Train and autopilot tried in the game: prefab, wagons upright, no circling

The train piece is in the scene's prefab list, its icon is made, and the
wagons keep the axis turn their FBX root brings. The autopilot gives up on a
point it has circled for seven seconds without getting closer, and takes sharp
turns close by slowly. -demoauto: on the easy planet the tractor unloads and
goes back to mowing, and the train lays 826 m of track to Timothy, closes 532
sectors and earns about 13.7k by the time its reach is mown.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
NiemandKG
2026-11-10 12:17:41 +06:00
parent df55b5e417
commit 29485df9e1
19 changed files with 6111 additions and 4879 deletions

View File

@ -0,0 +1,77 @@
using System.Collections;
using UnityEngine;
namespace GrassCutter
{
public partial class DemoBot
{
/// <summary>
/// -demoauto [-difficulty 2]: a fresh planet; a mowing tractor on autopilot with its hopper nearly full (it should go
/// 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>
IEnumerator AutoDemo()
{
TeamState.DeleteSave();
yield return new WaitForSeconds(2f);
NetSession.Instance.HostLocal();
while (!Me || !Ts) yield return null;
yield return new WaitForSeconds(3f);
Clock(11f);
Log($"{Difficulties.Name(Difficulties.Current)} gen {Difficulties.Gen}: radius {Planet.Radius:0} m, sector {GameDefs.SectorArea:0.0} m², planet {GameDefs.PlanetArea / 1e6:0.00} km², wire {Ts.Size.Value}");
Log($"perks {Ts.Perks.Count} of {(int)PerkId.Count}, installs {TeamState.TotalInstalls}");
Ts.ServerSetMoney(200000d);
double before = Ts.Money.Value;
Ts.BuyPerkRpc((int)PerkId.BotReach);
yield return new WaitForSeconds(0.5f);
Log($"Long Leash bought: {before - Ts.Money.Value:0} paid, level {Ts.Level(PerkId.BotReach)}");
Quaternion Face(Vector3 p, Vector3 way) => Quaternion.LookRotation(Vector3.ProjectOnPlane(way, Planet.Up(p)), Planet.Up(p));
var tAt = Soil17(70f, 60f);
var tractor = Spawner.Instance.SpawnVehicle(VehicleKind.Tractor, Me.SaveId, tAt + Planet.Up(tAt) * 1.2f, Face(tAt, Vector3.right));
yield return new WaitForSeconds(1f);
if (!tractor) { Log("tractor NOT spawned"); yield break; }
before = Ts.Money.Value;
Ts.TuneVehicleRpc(tractor.NetworkObjectId, (byte)TuneId.Autopilot);
yield return new WaitForSeconds(0.5f);
Log($"autopilot bought for {before - Ts.Money.Value:0}: CanAuto {tractor.CanAuto}");
tractor.Tank.Value = tractor.Capacity - 25f;
tractor.ServerStartAuto(tractor.transform.position, tractor.transform.forward);
var sAt = Soil17(-40f, -70f);
var piece = Spawner.Instance.SpawnPiece(PieceId.Train, sAt, Face(sAt, Vector3.ProjectOnPlane(sAt - Planet.FromBase(0f, 0f) * Planet.Radius, Planet.Up(sAt))), sAt, true);
yield return new WaitForSeconds(1f);
var train = piece ? piece.GetComponent<Train>() : null;
Log($"train built: {(train ? "ok" : "MISSING")}");
Time.timeScale = 6f;
var start = tractor.transform.position;
double money = Ts.Money.Value;
for (int k = 1; k <= 18; k++)
{
yield return new WaitForSecondsRealtime(10f);
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}");
if (k == 3 || k == 12)
{
Time.timeScale = 1f;
var tp = tractor.transform.position;
var up = Planet.Up(tp);
yield return Look($"auto{k:00}_tractor", tp + up * 9f + Vector3.ProjectOnPlane(Vector3.forward, up).normalized * -14f, tp, 0.3f);
if (train && train.loco)
{
var lp = train.loco.position;
var lu = Planet.Up(lp);
yield return Look($"auto{k:00}_train", lp + lu * 6f + Vector3.ProjectOnPlane(Vector3.right, lu).normalized * 12f, lp, 0.3f);
}
if (piece) yield return Look($"auto{k:00}_station", sAt + Planet.Up(sAt) * 10f - piece.transform.forward * 14f, sAt + piece.transform.forward * 10f, 0.3f);
Time.timeScale = 6f;
}
}
Time.timeScale = 1f;
Log("auto done");
Application.Quit();
}
}
}