Train lines that grow, station yards, a cab to ride, a wagon per upgrade; autopilot unloads where it can
- The grass train lays on to the next station by itself once its newest stretch is mown as far as the cutters reach, rounding each station at the edge of its yard, until no station is left within reach; it runs three times as fast over the stretches already mown. - Every station on a line has a yard at the end of the rails: machines (the autopilot too) unload there, the train picks it up as it passes and it is paid when the train gets home. With nothing left to cut it carries for the yards. - E on the locomotive puts you in the cab: W on up the line, S back home, E to get off; it carries on by itself after. - Three wagons, one more per upgrade (six at Mk IV), 2 t each; the heaps grow as they fill. The upgrade text says so. - The autopilot only drives to places a machine can unload (garage pads, unload bays, the yard, train yards), not to drone pads, binders or catchers, where it used to stop and stand; at a spot that won't take it, it tries the next. The HUD unload markers skip those too. - -demotrain checks the line growing, a yard filling and emptying, the cab ride and six wagons. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@ -35,6 +35,9 @@ namespace GrassCutter
|
||||
float _bestDist, _bestAt;
|
||||
int _goalKey = -1;
|
||||
Vector3 _unloadAt;
|
||||
/// <summary>Pads it got to and couldn't unload on this trip (walled in, say): it tries the next place.</summary>
|
||||
readonly HashSet<SiloPiece> _badPads = new HashSet<SiloPiece>();
|
||||
float _thereSince = -1f;
|
||||
|
||||
/// <summary>
|
||||
/// An autopilot touches nothing, so nothing can wedge it, climb it or tip it: it rides on the soil and on the base
|
||||
@ -121,6 +124,7 @@ namespace GrassCutter
|
||||
}
|
||||
|
||||
static readonly List<Vector2Int> s_fields = new List<Vector2Int>();
|
||||
static readonly List<(Vector3 at, string name)> s_yards = new List<(Vector3, string)>();
|
||||
static readonly Collider[] s_block = new Collider[4];
|
||||
|
||||
/// <summary>The driver hands over: they step off, it carries on.</summary>
|
||||
@ -282,12 +286,18 @@ namespace GrassCutter
|
||||
var p = transform.position;
|
||||
foreach (var s in SiloPiece.Pads)
|
||||
{
|
||||
if (!s || !s.IsSpawned) continue;
|
||||
// only what a machine can drive onto (a garage, an unload bay): a drone pad or a binder holds grass too
|
||||
if (!s || !s.IsSpawned || !s.OnPad(s.PadSpot) || _badPads.Contains(s)) continue;
|
||||
float d = (s.PadSpot - p).sqrMagnitude;
|
||||
if (d < best) { best = d; at = s.PadSpot; }
|
||||
}
|
||||
if (!s_dock) { var dz = GameObject.Find("DockZone"); s_dock = dz ? dz.transform : null; }
|
||||
if (s_dock && (s_dock.position - p).sqrMagnitude < best) { best = (s_dock.position - p).sqrMagnitude; at = s_dock.position; }
|
||||
// a yard at a station on a train's line: the train takes it home
|
||||
s_yards.Clear();
|
||||
Train.Yards(s_yards);
|
||||
foreach (var y in s_yards)
|
||||
if ((y.at - p).sqrMagnitude < best) { best = (y.at - p).sqrMagnitude; at = y.at; }
|
||||
return best < float.MaxValue;
|
||||
}
|
||||
|
||||
@ -309,8 +319,22 @@ namespace GrassCutter
|
||||
if (job == AutoJob.Unloading)
|
||||
{
|
||||
// on the pad: stand still until it's empty, then back to work
|
||||
if (Unloading) return Vector2.zero;
|
||||
if (Tank.Value <= 0.1f) { Auto.Value = (byte)AutoJob.Mowing; _stuckTimes = 0; return Vector2.zero; }
|
||||
if (Unloading) { _thereSince = -1f; return Vector2.zero; }
|
||||
if (Tank.Value <= 0.1f) { Auto.Value = (byte)AutoJob.Mowing; _stuckTimes = 0; _badPads.Clear(); return Vector2.zero; }
|
||||
// at the spot and still not unloading: that place won't take it, so the next one
|
||||
if (Vector3.ProjectOnPlane(_unloadAt - p, up).sqrMagnitude < 25f)
|
||||
{
|
||||
if (_thereSince < 0f) _thereSince = Time.time;
|
||||
else if (Time.time - _thereSince > 4f)
|
||||
{
|
||||
_thereSince = -1f;
|
||||
var bad = SiloPiece.Pads.Find(s => s && (s.PadSpot - _unloadAt).sqrMagnitude < 1f);
|
||||
if (bad) _badPads.Add(bad);
|
||||
if (!bad) Hop(_unloadAt, 5f); // the yard: right onto the spot
|
||||
else if (!FindUnload(out _unloadAt)) { Auto.Value = (byte)AutoJob.Done; return Vector2.zero; }
|
||||
}
|
||||
}
|
||||
else _thereSince = -1f;
|
||||
}
|
||||
|
||||
Vector3 goal;
|
||||
|
||||
Reference in New Issue
Block a user