Files
grass-cutters/Assets/Scripts/Gameplay/RobotDock.cs
NiemandKG df55b5e417 Smaller planets, 93% sectors, dearer late game, automation perks, autopilot, grass train
Not yet tried in the game: Unity could not get a licence (Unity Hub isn't
running), so this was only type-checked with Roslyn.

- Planets by area: the hard one half the old whole planet, normal a third of
  that, easy a sixth. Saves keep the size set they were made on (sizeGen 0).
- A sector closes at 93% mown.
- Mid and late prices go up (perks, machines, vehicles, tunes); the early
  game stays as it was.
- AUTOMATION perk tree: Long Leash (robot reach), Overdrive Motors, Bigger
  Hoppers, Long-Range Drones and Hive Mind.
- Autopilot, a garage tune for mowers: C hands the machine over. It mows the
  fields around in strokes, unloads at the nearest pad or the base yard and
  comes back. Getting in takes it back; it carries on after a load.
- Grass Train: lays its own track to a station next door, mowing under it,
  then runs back and forth cutting wider each run. Models in gc_train.py.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 11:39:02 +06:00

108 lines
4.1 KiB
C#

using System.Collections.Generic;
using Unity.Netcode;
using UnityEngine;
namespace GrassCutter
{
/// <summary>
/// A robot mower and its dock: it works the rings of sectors around the dock, and the dock ties what it brings into
/// bundles for the belt, or with no belt sends it straight to Earth. When everything in its rings is mown it takes the
/// next ring out, up to four times its first reach, so a dock keeps working for a long time without being moved.
/// </summary>
public class RobotDock : Mowbot, IPorts
{
const float SiloRoom = 100f, UnloadRate = 5f;
public Transform bot;
public readonly NetworkVariable<float> Silo = new NetworkVariable<float>();
bool _unloading;
int _turn, _area, _reach;
float _shipAt;
protected override Transform Body => bot;
protected override bool NoseOnBack => true;
protected override Vector3 Origin => transform.position;
protected override int Reach => Mathf.Min(MaxReach, Mathf.Max(_reach, StartReach));
/// <summary>Where it starts: its own reach, and Long Leash puts it further out.</summary>
int StartReach => Def.reach + (TeamState.Instance ? TeamState.Instance.BotReachRings : 0);
int MaxReach => Mathf.Max(StartReach, Mathf.RoundToInt(Def.reach * 4 * (TeamState.Instance ? TeamState.Instance.BotRoamMul : 1f)));
protected override Vector3 HomeDir => Planet.Up(transform.position);
public override string Prompt
{
get
{
if (_area == 0) _area = Area();
return Loc.F("{0}: {1}, {2} of {3}, {4} sectors, dock holds {5}", Def.name, MoodText, GameDefs.Kilos(Hopper.Value), GameDefs.Kilos(HopperCap), _area, GameDefs.Kilos(Silo.Value))
+ " · " + (BeltNet.Belted(GetComponent<BuildPiece>()) ? Loc.T("onto the belt") : Loc.T("straight to Earth"));
}
}
public override float[] State
{
get => new[] { Hopper.Value, Dir.x, Dir.y, Dir.z, Silo.Value, Reach };
set
{
base.State = value;
if (value != null && value.Length > 4) Silo.Value = value[4];
if (value != null && value.Length > 5) _reach = Mathf.Clamp((int)value[5], Def.reach, MaxReach);
}
}
public void Ports(List<Port> into)
{
into.Add(BeltNet.Front(transform));
}
protected override bool Stay(float dt)
{
var piece = GetComponent<BuildPiece>();
if (BeltNet.Belted(piece)) BeltNet.Drain(piece, Silo, ref _turn);
else BeltNet.Ship(Silo, transform.position, ref _shipAt);
if (_unloading)
{
float give = Mathf.Min(Hopper.Value, UnloadRate * dt, SiloRoom - Silo.Value);
if (give > 0f)
{
Hopper.Value -= give;
Silo.Value += give;
}
if (Hopper.Value >= 0.01f)
{
// with no belt the dock ships every few seconds: that is unloading, not waiting for a belt
Mood.Value = (byte)(give > 0f || !BeltNet.Belted(piece) ? RobotMood.Unloading : RobotMood.Waiting);
return true;
}
Hopper.Value = 0f;
_unloading = false;
}
if (!Homing && Hopper.Value >= HopperCap) GoHome();
return false;
}
protected override void Arrived() => _unloading = true;
protected override void NoWork()
{
// its rings are done: one more ring out, and look again
if (Reach < MaxReach)
{
_reach = Reach + 1;
_area = 0;
Mood.Value = (byte)RobotMood.Travelling;
return;
}
if (Vector3.Dot(Dir, HomeDir) < 0.9999999f || Hopper.Value > 0f) GoHome();
else Mood.Value = (byte)RobotMood.Finished;
}
public override void Moved(Vector3 at)
{
base.Moved(at);
_reach = 0;
_area = 0;
}
}
}