Wagons on the rails, buildings on the slope, an autopilot nothing stops

- The train's loco and wagons stand on their front and back axles, so they pitch with the track up and down hills
  instead of standing level and hanging off one end; wheels sit on the rail tops, gauge matched to the models.
- A piece set down on the soil leans with the ground under its footprint (up to 22 degrees) and sinks until no
  corner hangs in the air; foundations stay level.
- On autopilot a machine touches nothing: it rides on the soil and the base deck and drives straight through
  buildings, rocks, rails, people and machines. Wedged anyway, it hops a few metres on; it no longer gives up on
  the way to unload.
- -demoauto puts a building in the way to the yard, sets one down on the steepest clear slope and reports any tip-over.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
NiemandKG
2026-11-10 19:54:01 +06:00
parent 6b2a9931b9
commit 0db89bf7cb
5 changed files with 186 additions and 31 deletions

View File

@ -10,6 +10,13 @@ namespace GrassCutter
/// and unload, then come back to mow), and a grass train laying its track to the next station and starting to run.
/// Time goes six times as fast. Logs both every ten seconds and takes pictures of them.
/// </summary>
static bool FindDock(out Vector3 at)
{
var dz = GameObject.Find("DockZone");
at = dz ? dz.transform.position : default;
return dz;
}
IEnumerator AutoDemo()
{
TeamState.DeleteSave();
@ -44,12 +51,65 @@ namespace GrassCutter
var train = piece ? piece.GetComponent<Train>() : null;
Log($"train built: {(train ? "ok" : "MISSING")}");
// something in the way to the yard: the autopilot should go straight through it
if (FindDock(out var dock))
{
var mid = Planet.Surface(Vector3.Lerp(tractor.transform.position, dock, 0.5f));
var block = Spawner.Instance.SpawnPiece(PieceId.Press, mid, Face(mid, dock - mid), mid, true);
Log($"obstacle: {(block ? "press" : "MISSING")} {Vector3.Distance(mid, tractor.transform.position):0} m on the way to the yard");
}
// a building on the steepest slope round here, sat on it the way the build tool now sets it down
Vector3 steep = default;
float worst = -1f;
for (int a = 0; a < 48; a++)
for (float r = 60f; r <= 300f; r += 15f)
{
var q = Soil17(Mathf.Cos(a * 7.5f * Mathf.Deg2Rad) * r, Mathf.Sin(a * 7.5f * Mathf.Deg2Rad) * r);
var u = Planet.Up(q);
var e = Vector3.ProjectOnPlane(Vector3.right, u).normalized;
var n2 = Vector3.Cross(u, e);
var nrm = Vector3.Cross(Planet.Surface(q + n2 * 2f) - Planet.Surface(q - n2 * 2f), Planet.Surface(q + e * 2f) - Planet.Surface(q - e * 2f));
float slope = Vector3.Angle(nrm.normalized * Mathf.Sign(Vector3.Dot(nrm, u)), u);
if (slope > worst && !Ts.OnDeck(q) && !(Ground.Instance && Ground.Instance.RockAt(q)) && !Physics.CheckSphere(q + u * 3f, 9f, 1 << Layers.Default, QueryTriggerInteraction.Ignore)) { worst = slope; steep = q; }
}
var dryerDef = GameDefs.Piece(PieceId.Dryer);
var dAt = steep;
var dRot = Face(steep, Vector3.forward);
PlayerBuild.Lean(dryerDef, ref dAt, ref dRot);
var dryer = Spawner.Instance.SpawnPiece(PieceId.Dryer, dAt, dRot, dAt, true);
Log($"slope {worst:0} deg: dryer leans {Vector3.Angle(dRot * Vector3.up, Planet.Up(steep)):0} deg, sunk {Vector3.Dot(dAt - steep, Planet.Up(steep)):0.00} m");
if (dryer)
{
var du = Planet.Up(dAt);
var side = Vector3.Cross(du, dRot * Vector3.forward).normalized;
yield return Look("auto00_slope_dryer", dAt + du * 3f + side * 13f, dAt + du * 1.5f, 1f);
yield return Look("auto00_slope_dryer2", dAt + du * 4f - (dRot * Vector3.forward) * 13f, dAt + du * 1.5f, 0.4f);
}
Time.timeScale = 6f;
var start = tractor.transform.position;
bool flipped = false;
double money = Ts.Money.Value;
for (int k = 1; k <= 18; k++)
{
yield return new WaitForSecondsRealtime(10f);
float until = Time.realtimeSinceStartup + 10f;
while (Time.realtimeSinceStartup < until)
{
yield return null;
var tp0 = tractor.transform.position;
float tilt = Vector3.Angle(tractor.transform.up, Planet.Up(tp0));
if (tilt > 40f && !flipped)
{
flipped = true;
Log($" TIPPED {tilt:0} deg: {tractor.Job}, alt {Planet.Altitude(tp0):0.00} m, {Vector3.Distance(tp0, Planet.FromBase(0f, 0f) * Planet.Radius):0} m from base, speed {tractor.Body.linearVelocity.magnitude:0.0}, on deck {Ts.OnDeck(tp0)}, exclude {tractor.Body.excludeLayers.value}");
Time.timeScale = 1f;
var u0 = Planet.Up(tp0);
yield return Look($"auto_tipped", tp0 + u0 * 8f + Vector3.ProjectOnPlane(Vector3.forward, u0).normalized * -10f, tp0, 0.1f);
Time.timeScale = 6f;
}
if (tilt < 20f) flipped = false;
}
Log($"t+{k * 60} game s: earned {Ts.Money.Value - money:0}, closed {Ts.Closed.Value}");
Log($" tractor: {tractor.Job}, {GameDefs.Kilos(tractor.Tank.Value)} of {GameDefs.Kilos(tractor.Capacity)}, {Vector3.Distance(start, tractor.transform.position):0} m from start, speed {tractor.Body.linearVelocity.magnitude:0.0}, tilt {Vector3.Angle(tractor.transform.up, Planet.Up(tractor.transform.position)):0} deg");
if (train) Log($" train: {train.Prompt}");