using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEngine;
namespace GrassCutter
{
///
/// Dev bot: `-autodemo <folder>` hosts a local game and plays the first minutes the way a new player would (empty
/// hands, the supply wall, cutting, a bundle, the depot, the matrix, belts, the garage), saving a screenshot of each
/// moment and writing what actually happened to results.txt.
///
public partial class DemoBot : MonoBehaviour
{
public string folder = "demo";
IEnumerator Shot(string name)
{
Directory.CreateDirectory(folder);
yield return BotCapture.Shot(Path.Combine(folder, name + ".png"));
Debug.Log("[DemoBot] shot " + name);
}
/// The real cost of a frame here, appended to fps.txt beside the screenshots.
/// What each studio booth is filming right now, saved as it is.
IEnumerator Booths(string prefix)
{
yield return new WaitForEndOfFrame();
foreach (var cam in Object.FindObjectsByType(FindObjectsInactive.Include))
{
var rt = cam.targetTexture;
if (!rt || cam.gameObject.layer != Studio.Layer) continue;
var was = RenderTexture.active;
cam.Render();
RenderTexture.active = rt;
var tex = new Texture2D(rt.width, rt.height, TextureFormat.RGB24, false);
tex.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0);
tex.Apply();
RenderTexture.active = was;
Directory.CreateDirectory(folder);
File.WriteAllBytes(Path.Combine(folder, $"{prefix}_{rt.name.Replace(' ', '_')}.png"), tex.EncodeToPNG());
Object.Destroy(tex);
}
}
IEnumerator Fps(string label)
{
float ms = 0f;
yield return BotCapture.FrameCost(40, v => ms = v);
File.AppendAllText(Path.Combine(folder, "fps.txt"), $"{label}: {ms:0.0} ms a frame ({1000f / Mathf.Max(0.1f, ms):0} fps), {Screen.width}x{Screen.height}\n");
}
void Log(string line)
{
File.AppendAllText(Path.Combine(folder, "results.txt"), line + "\n");
Debug.Log("[DemoBot] " + line);
}
static PlayerAgent Me => PlayerAgent.Local;
static TeamState Ts => TeamState.Instance;
const float Soil = GameDefs.WaterY;
/// Hold LMB while the aim swings over the grass in front of the player.
IEnumerator Sweep(Vector3 center, Vector3 span, float seconds, string shotHalfway = null)
{
Ctl.BotUseHeld = true;
float t = 0f;
bool shot = shotHalfway == null;
while (t < seconds)
{
t += Time.deltaTime;
Me.LookAt(center + span * Mathf.Sin(t * 1.6f));
if (!shot && t > seconds * 0.5f) { shot = true; yield return Shot(shotHalfway); }
yield return null;
}
Ctl.BotUseHeld = false;
}
// where the far strip lies, so the second run can look for it
static readonly Vector3 FarSpot = Planet.FromLatLon(-61f, 133f);
/// Cut on the far side: a strip, the same strip again, across a border, a whole sector, then a save.
IEnumerator FarCut()
{
Me.Tools.Equip(ToolId.WideScythe);
yield return new WaitForSeconds(0.3f);
Cheats.Run("tank");
Me.Tools.CheatEmpty();
var ground = Planet.OnSurface(FarSpot);
var up = FarSpot;
var east = Vector3.Cross(up, Vector3.up).normalized;
var north = Vector3.Cross(east, up);
Me.Teleport(ground + up * 0.2f);
yield return new WaitForSeconds(0.8f);
var target = ground + north * 1.8f;
yield return Sweep(target, east * 1.6f, 5f);
float one = Me.Tank.Value;
yield return new WaitForSeconds(0.2f);
Log($"far strip: {one:0.###} kg, grass left at the middle {MowMap.Yield(target):0.00}, sector {HexGrid.SectorAt(up) + 1} at {MowMap.Cleared(HexGrid.SectorAt(up)) * 100f:0.0}%");
yield return Sweep(target, east * 1.6f, 5f);
Log($"same strip again: {Me.Tank.Value - one:0.###} kg more");
Me.LookAt(target);
yield return new WaitForSeconds(0.3f);
yield return Shot("26_far_strip");
// a stroke across a border must cost nothing and leave no seam
var near = HexGrid.Get(HexGrid.SectorAt(up));
var other = HexGrid.Get(near.neighbours[0]);
var edge = ((near.c + other.c) * 0.5f).normalized;
var along = Vector3.Cross(edge, (other.c - near.c).normalized);
Me.Teleport(Planet.OnSurface((edge + (near.c - other.c).normalized * 2.6f / Planet.Radius).normalized) + edge * 0.2f);
yield return new WaitForSeconds(0.8f);
float before = Me.Tank.Value;
var aim = Planet.OnSurface(edge);
yield return Sweep(aim, (other.c - near.c).normalized * 1.8f, 5f);
Log($"across a border: {Me.Tank.Value - before:0.###} kg, both sides {MowMap.Cleared(near.id) * 100f:0.0}% and {MowMap.Cleared(other.id) * 100f:0.0}%, seam {MowMap.Yield(aim):0.00}");
Me.LookAt(aim);
yield return new WaitForSeconds(0.3f);
yield return Shot("27_across_border");
// a whole sector: the area it reports must match what comes out of it
int id = other.neighbours[2];
float total = MowMap.Total(id);
float gone = MowMap.CutSector(id);
var c = HexGrid.Get(id).c;
Me.SetFlying(true);
Me.Teleport(Planet.OnSurface(c) + c * 34f);
Me.LookAt(Planet.OnSurface(c));
yield return new WaitForSeconds(1f);
yield return Shot("28_sector_done");
yield return Fps("above a finished sector");
Me.SetFlying(false);
MowMap.Count();
Log($"sector {id + 1}: {total:0} m² of grass, {gone:0} m² cut, {MowMap.Cleared(id) * 100f:0.0}%, left under it {MowMap.Yield(Planet.OnSurface(c)):0.00}; {MowMap.Started} started, {MowMap.Finished} finished");
yield return SectorRows(other.neighbours[3]);
// the ground as it looks from up close at the mower's old strip
Me.Tools.Select(ToolId.None);
}
/// A real sector, cut row by row with a blade a metre wide: can the last scraps be reached, and does it pay once?
IEnumerator SectorRows(int id)
{
var s = HexGrid.Get(id);
double money = Ts.Money.Value;
int closed = Ts.Closed.Value;
float cut = 0f;
for (float v = -s.half; v <= s.half; v += 0.9f)
{
var from = (s.c * Planet.Radius + s.e1 * -s.half + s.e2 * v).normalized;
var to = (s.c * Planet.Radius + s.e1 * s.half + s.e2 * v).normalized;
cut += MowMap.Cut(Planet.OnSurface(from), Planet.OnSurface(to), 1f);
yield return null;
}
yield return new WaitForSeconds(0.5f);
Log($"sector {id + 1} cut in rows: {cut:0} m², {MowMap.Cleared(id) * 100f:0.0}%, paid {Ts.Money.Value - money:0.##}, {Ts.Closed.Value - closed} closed");
MowMap.Cut(Planet.OnSurface(s.c), Planet.OnSurface(s.c), 1f, 1f);
MowMap.CutSector(id);
yield return new WaitForSeconds(0.5f);
Log($"and again: paid {Ts.Money.Value - money:0.##}, {Ts.Closed.Value - closed} closed, {Ts.Mown01 * 100.0:0.00000}% of the planet");
}
/// Walk up to the nearest stake or survey point and hold E.
IEnumerator Mark(bool point, string shot)
{
int id = Landmarks.Instance.Nearest(Me.transform.position, point);
var spot = Landmarks.Spot(id);
float far = (spot - Vector3.zero).magnitude;
Me.Tools.Select(ToolId.None);
Me.Teleport(spot + Vector3.ProjectOnPlane(Vector3.right, Planet.Up(spot)).normalized * 2f + Planet.Up(spot) * 0.2f);
yield return new WaitForSeconds(0.8f);
Me.LookAt(spot + Planet.Up(spot) * 1.3f);
yield return new WaitForSeconds(0.5f);
string prompt = Me.AimInteractable?.Prompt;
yield return Shot(shot);
double money = Ts.Money.Value;
Ctl.BotInteractPressed = Ctl.BotInteractHeld = true;
yield return null;
Ctl.BotInteractPressed = false;
yield return new WaitForSeconds(point ? 3.3f : 1.9f);
Ctl.BotInteractHeld = false;
yield return new WaitForSeconds(0.4f);
double paid = Ts.Money.Value - money;
yield return Shot(shot + "_done");
Ctl.BotInteractPressed = Ctl.BotInteractHeld = true;
yield return null;
Ctl.BotInteractPressed = false;
yield return new WaitForSeconds(point ? 3.3f : 1.9f);
Ctl.BotInteractHeld = false;
yield return new WaitForSeconds(0.3f);
Log($"{(point ? "survey point" : "stake")} {id}, {far:0} m from the base: '{prompt}', paid {paid:0.##}, a second try {Ts.Money.Value - money - paid:0.##}, found {Ts.FoundCount(point)}");
}
static string Bundles()
{
float kg = 0f;
foreach (var c in Cargo.All) kg += c.Kg.Value;
return $"{Cargo.All.Count} ({kg:0.##} kg)";
}
IEnumerator Click(System.Action press)
{
press(true);
yield return null;
press(false);
yield return new WaitForSeconds(0.35f);
}
IEnumerator LeftClick() => Click(v => Ctl.BotUsePressed = v);
IEnumerator RightClick() => Click(v => Ctl.BotAltPressed = v);
/// Stage 7: a line with a splitter and a merger on the far side of the ball, then the hammer driven like a player.
IEnumerator Building()
{
var b = PlayerBuild.Local;
var up = Planet.FromLatLon(-40f, 200f);
var north = Vector3.ProjectOnPlane(Vector3.up, up).normalized;
var east = Vector3.Cross(up, north);
Vector3 At(float x, float z, float h = 0f)
{
var d = (up * Planet.Radius + east * x + north * z).normalized;
return Planet.OnSurface(d) + d * h;
}
void Lay(Vector3 from, Vector3 to)
{
if (!BuildRules.CanRun(from, to, out var why)) Log($"can't lay a belt: {why}");
Ts.BuildRpc((byte)PieceId.Belt, from, BuildRules.RunRotation(from, to), to);
}
Me.SetFlying(false);
Me.Teleport(At(8f, 2f, 3f));
yield return new WaitForSeconds(0.6f);
var turn = Quaternion.LookRotation(north, up);
double cash = Ts.Money.Value;
Ts.BuildRpc((byte)PieceId.Splitter, At(0f, 0f), turn, Vector3.zero);
Ts.BuildRpc((byte)PieceId.Merger, At(0f, 12f), turn, Vector3.zero);
yield return new WaitForSeconds(0.5f);
var sp = BuildPiece.All.Find(p => p.piece == PieceId.Splitter);
var mg = BuildPiece.All.Find(p => p.piece == PieceId.Merger);
var sPorts = new List();
var mPorts = new List();
if (sp && mg)
{
sp.Ports(sPorts);
mg.Ports(mPorts);
Lay(At(0f, -9f, 0.6f), sPorts[0].at);
Lay(sPorts[1].at, At(3f, 0f, 1.4f));
Lay(At(3f, 0f, 1.4f), At(3f, 12f, 1.4f));
Lay(At(3f, 12f, 1.4f), mPorts[1].at);
Lay(sPorts[2].at, At(-3f, 0f, 1.4f));
Lay(At(-3f, 0f, 1.4f), At(-3f, 12f, 1.4f));
Lay(At(-3f, 12f, 1.4f), mPorts[0].at);
Lay(mPorts[3].at, At(0f, 20f, 0.6f));
}
yield return new WaitForSeconds(0.6f);
Log($"far line: {BuildPiece.All.Count(p => p.Run)} belts, {Ts.Money.Value - cash:0.##} paid, longest {BuildPiece.All.Where(p => p.Run).Max(p => p.Run.Metres):0.0} m");
var left = new HashSet();
var right = new HashSet();
var waist = At(0f, 6f);
Me.LookAt(waist);
var mine = new List();
for (float t = 0f, next = 0f; t < 28f; t += Time.deltaTime)
{
if (t >= next && mine.Count < 6)
{
next = t + 0.9f;
mine.Add(Spawner.Instance.SpawnCargo(CargoKind.Grass, At(0f, -8f, 1.2f), Quaternion.identity, Vector3.zero));
}
foreach (var c in mine)
{
if (!c) continue;
float x = Vector3.Dot(c.transform.position - waist, east);
if (x > 2f) right.Add(c); else if (x < -2f) left.Add(c);
}
if (Mathf.Abs(t - 7f) < Time.deltaTime) yield return Shot("33_far_line");
yield return null;
}
int landed = mine.Count(c => c && Vector3.Distance(c.transform.position, At(0f, 21f)) < 5f);
Log($"six bundles down the line: {right.Count} went right, {left.Count} left, {landed} came off the end, {Conveyor.All.Sum(c => c.Count)} still riding");
// the hammer, as a player holds it
Me.Tools.Equip(ToolId.Hammer);
yield return new WaitForSeconds(0.5f);
Log($"hammer: build mode {b.Active}, {b.Current?.name}");
// daylight on this side of the ball, and from here on the real rule
float pinned = Sun.Pinned;
Sun.Pinned = Mathf.Repeat(pinned + 0.5f, 1f);
BuildRules.AnyGround = false;
var slab = At(-12f, -6f);
b.Select(PieceId.Square);
Me.Teleport(At(-12f, -13f, 0.2f));
Me.LookAt(slab);
yield return new WaitForSeconds(0.5f);
yield return Shot("34a_on_standing_grass");
Log($"on standing grass: valid {b.Valid}, {b.Reason}");
int slabs = BuildPiece.All.Count(p => p.piece == PieceId.Square);
yield return LeftClick();
yield return new WaitForSeconds(0.3f);
Log($"click on standing grass: {BuildPiece.All.Count(p => p.piece == PieceId.Square) - slabs} built, {Ts.Money.Value - cash:0.##} spent since the line");
// half the plot cut: still no
MowMap.Cut(At(-14f, -6f), At(-10f, -6f), 1.4f);
yield return new WaitForSeconds(0.2f);
Log($"one stroke through it: valid {b.Valid}, {b.Reason}");
for (float z = -15f; z <= 3f; z += 1.2f) MowMap.Cut(At(-23f, z), At(-1f, z), 1.8f);
yield return new WaitForSeconds(0.4f);
Log($"mown: valid {b.Valid}, {b.Reason}");
yield return Shot("34_foundation_ghost");
cash = Ts.Money.Value;
yield return LeftClick();
var first = BuildPiece.All.Find(p => p.piece == PieceId.Square);
Log($"foundation: {(first ? "built" : "NOT built, " + b.Reason)} for {cash - Ts.Money.Value:0.##}, {(first ? Vector3.Distance(first.transform.position, slab) : -1f):0.00} m from the aim");
Me.LookAt(At(-12f, -2.5f));
yield return new WaitForSeconds(0.4f);
yield return LeftClick();
var second = BuildPiece.All.Find(p => p.piece == PieceId.Square && p != first);
if (first && second) Log($"second foundation: {Vector3.Distance(first.transform.position, second.transform.position):0.00} m from the first");
if (first)
{
Me.Teleport(first.transform.position + first.transform.right * 7f + first.transform.up * 2.5f);
Me.LookAt(first.transform.position);
yield return new WaitForSeconds(0.5f);
yield return Shot("34b_foundation_built");
Me.Teleport(At(-12f, -13f, 0.2f));
yield return new WaitForSeconds(0.3f);
}
if (first)
{
b.Select(PieceId.Merger);
Me.LookAt(first.transform.position + first.transform.up * Foundation.Top + first.transform.right * 0.7f);
yield return new WaitForSeconds(0.5f);
yield return Shot("35_on_foundation");
yield return LeftClick();
var rider = BuildPiece.All.Find(p => p.piece == PieceId.Merger && p != mg);
Log($"on the foundation: {(rider ? "built" : "NOT built, " + b.Reason)}, {BuildRules.Riders(first).Count} riders, height over the slab {(rider ? first.transform.InverseTransformPoint(rider.transform.position).y : 0f):0.00}, x {(rider ? first.transform.InverseTransformPoint(rider.transform.position).x : 0f):0.00}");
float gap = rider ? Vector3.Distance(first.transform.position, rider.transform.position) : 0f;
Me.LookAt(first.transform.position + first.transform.up * Foundation.Top - first.transform.right);
yield return new WaitForSeconds(0.4f);
yield return Click(v => Ctl.BotMovePressed = v);
Log($"carrying: {b.Moving?.Def.name}");
Me.LookAt(At(-5f, -11f));
yield return new WaitForSeconds(0.5f);
yield return Shot("36_moving");
var goal = At(-5f, -11f);
yield return LeftClick();
yield return new WaitForSeconds(0.3f);
Log($"moved: foundation {Vector3.Distance(first.transform.position, goal):0.00} m from the aim, rider still {(rider ? Vector3.Distance(first.transform.position, rider.transform.position) : 0f):0.00} m from it (was {gap:0.00})");
b.Select(PieceId.Square);
Me.LookAt(first.transform.position + first.transform.up * Foundation.Top - first.transform.right);
yield return new WaitForSeconds(0.4f);
cash = Ts.Money.Value;
yield return RightClick();
Log($"removing a foundation with a rider: {(first ? "refused" : "REMOVED")}, money {Ts.Money.Value - cash:0.##}");
}
// two clicks lay a belt, the ghost shows it on the way
b.Select(PieceId.Belt);
b.Height = 2f;
Me.Teleport(At(-16f, -8f, 0.2f));
Me.LookAt(At(-20f, -2f));
yield return new WaitForSeconds(0.5f);
int belts = BuildPiece.All.Count(p => p.Run);
cash = Ts.Money.Value;
yield return LeftClick();
Me.LookAt(At(-13f, -2f));
yield return new WaitForSeconds(0.5f);
yield return Shot("37_belt_ghost");
Log($"belt ghost: {b.Note}, valid {b.Valid}, {b.Reason}");
yield return LeftClick();
yield return new WaitForSeconds(0.3f);
var run = BuildPiece.All.Where(p => p.Run).LastOrDefault();
yield return RightClick();
Log($"belt by hand: {BuildPiece.All.Count(p => p.Run) - belts} laid, {run?.Run.Metres:0.0} m, cost {cash - Ts.Money.Value:0.##}, height {(run ? Planet.Altitude(run.transform.position) : 0f):0.00} m, still laying {b.Laying}");
if (run)
{
cash = Ts.Money.Value;
Me.LookAt(run.transform.position + (run.Run.End - run.transform.position) * 0.5f);
yield return new WaitForSeconds(0.4f);
Log($"aiming at it: {b.Target?.Def.name}, {b.Reason}");
yield return RightClick();
Log($"belt taken down: {BuildPiece.All.Count(p => p.Run) - belts} left of it, refund {Ts.Money.Value - cash:0.##}");
}
// past the mown plot a belt can't even start
Me.Teleport(At(-30f, 2f, 0.2f));
Me.LookAt(At(-30f, 8f));
b.Select(PieceId.Belt);
yield return new WaitForSeconds(0.4f);
Log($"a belt started on standing grass: valid {b.Valid}, {b.Reason}");
BuildRules.AnyGround = true;
Sun.Pinned = pinned;
Me.Tools.Equip(ToolId.Scythe);
yield return new WaitForSeconds(0.3f);
}
string Tries()
{
int had = Vehicle.All.Count;
Ts.BuyVehicleRpc((byte)VehicleKind.Rider, 0UL);
return Vehicle.All.Count == had ? "yes" : "NO";
}
/// Stage 9: upgrades on your own machine, a garage of your own, the pickup's bed.
IEnumerator Fleet()
{
Vector3 At(float x, float z, float h = 0f)
{
var d = Planet.FromBase(x, z);
return Planet.OnSurface(d) + d * h;
}
var rider = Vehicle.All.Find(v => v.kind == VehicleKind.Rider);
var push = Vehicle.All.Find(v => v.kind == VehicleKind.Push);
var combine = Vehicle.All.Find(v => v.kind == VehicleKind.Combine);
if (!rider || !push || !combine) { Log("machines missing"); yield break; }
UIRoot.I.OpenGarage(null);
yield return new WaitForSeconds(0.8f);
yield return Shot("17b_garage_owned");
UIRoot.I.CloseTopModal();
float speed = rider.TopSpeed, width = rider.CutWidth, room = rider.Capacity;
double cash = Ts.Money.Value;
Ts.TuneVehicleRpc(rider.NetworkObjectId, (byte)TuneId.Motors);
Ts.TuneVehicleRpc(rider.NetworkObjectId, (byte)TuneId.Hopper);
yield return new WaitForSeconds(0.3f);
Log($"tuned rider: {cash - Ts.Money.Value:0.##} paid, speed {speed:0.##} to {rider.TopSpeed:0.##}, hopper {room:0} to {rider.Capacity:0}");
cash = Ts.Money.Value;
Ts.TuneVehicleRpc(push.NetworkObjectId, (byte)TuneId.Motors);
Ts.TuneVehicleRpc(combine.NetworkObjectId, (byte)TuneId.Motors);
yield return new WaitForSeconds(0.3f);
Log($"the same upgrade on the push mower and the combine: {cash - Ts.Money.Value:0.##} together");
Ts.TuneVehicleRpc(rider.NetworkObjectId, (byte)TuneId.Cutter);
yield return new WaitForSeconds(0.3f);
Log($"cutter control: strip {width:0.##} to {rider.CutWidth:0.##}, top speed {rider.TopSpeed:0.##}");
// a garage out in the meadow: the rider unloads into its silo and the silo goes out on a belt
Me.Teleport(At(-60f, 40f, 1.5f));
yield return new WaitForSeconds(0.5f);
var spot = At(-60f, 50f);
var turn = Quaternion.LookRotation(Vector3.ProjectOnPlane(Vector3.forward, Planet.Up(spot)), Planet.Up(spot));
Ts.BuildRpc((byte)PieceId.Garage, spot, turn, Vector3.zero);
yield return new WaitForSeconds(0.5f);
var garage = Garage.All.Count > 0 ? Garage.All[0] : null;
if (!garage) { Log("garage NOT built"); yield break; }
var ports = new List();
garage.Ports(ports);
var end = ports[0].at + ports[0].dir * 8f;
if (!BuildRules.CanRun(ports[0].at, end, out var why)) Log($"can't lay a belt: {why}");
Ts.BuildRpc((byte)PieceId.Belt, ports[0].at, BuildRules.RunRotation(ports[0].at, end), end);
Ts.CallVehicleRpc(rider.NetworkObjectId, garage.NetworkObjectId);
yield return new WaitForSeconds(0.8f);
Log($"called: rider {Vector3.Distance(rider.transform.position, garage.PadSpot):0.0} m from the pad's middle");
Me.Teleport(At(-52f, 50f, 2f));
Me.LookAt(At(-60f, 54f, 1f));
yield return new WaitForSeconds(0.5f);
yield return Shot("24_own_garage");
rider.Interact();
yield return new WaitForSeconds(1f);
Ctl.BotMove = Vector2.up;
yield return new WaitForSeconds(5f);
Ctl.BotMove = Vector2.zero;
yield return new WaitForSeconds(0.8f);
float hopper = rider.Tank.Value;
Ctl.BotMove = Vector2.down;
float t0 = Time.time;
while (Time.time - t0 < 14f && rider.Tank.Value > 0.2f) yield return null;
Ctl.BotMove = Vector2.zero;
yield return new WaitForSeconds(1f);
rider.RequestExit();
yield return new WaitForSeconds(0.8f);
Log($"own garage: {hopper:0.##} kg went in, hopper {rider.Tank.Value:0.##}, silo {garage.Silo.Value:0.##}, bundles on the belt or past it {Cargo.All.Count(c => c.Kg.Value >= 0.99f && Vector3.Distance(c.transform.position, end) < 10f)}");
// the pickup takes a bundle from your arms
var pickup = Vehicle.All.Find(v => v.kind == VehicleKind.Pickup);
if (pickup)
{
var bundle = Spawner.Instance.SpawnCargo(CargoKind.Grass, Me.transform.position + Me.transform.forward + Planet.Up(Me.transform.position), Quaternion.identity, Vector3.zero);
yield return new WaitForSeconds(0.3f);
Me.Grab.TryGrab(bundle.Grab);
yield return new WaitForSeconds(0.4f);
pickup.LoadRpc(bundle.NetworkObjectId);
yield return new WaitForSeconds(0.4f);
int onBed = pickup.Bed.Count;
pickup.TipRpc();
yield return new WaitForSeconds(0.5f);
Log($"pickup: {onBed} on the bed, {pickup.Bed.Count} after tipping, hands holding {Me.Grab.Holding}");
}
Me.SetFlying(true);
}
/// Stage 11: a far station found by walking up to it, its depot, travel, the save screen.
IEnumerator Travel()
{
const int far = 3, unfound = 5;
var dir = Stations.Dir(far);
var side = Vector3.Cross(dir, Vector3.right).normalized;
float bump = 0f;
for (int k = 0; k < 12; k++)
{
var d = (dir + Quaternion.AngleAxis(k * 30f, dir) * side * (40f / Planet.Radius)).normalized;
bump = Mathf.Max(bump, Mathf.Abs(Planet.HeightAt(d) - Planet.HeightAt(dir)));
}
Log($"stations: {Depot.All.Count} depots, {Stations.Names[far]} found {Ts.StationOpen(far)}, soil within 40 m of it differs by {bump:0.00} m");
Me.Teleport(Stations.Arrival(far));
yield return new WaitForSeconds(2f);
Log($"{Stations.Names[far]}: found {Ts.StationOpen(far)}, altitude {Planet.Altitude(Me.transform.position):0.00}");
Me.LookAt(Stations.Spot(far) + Planet.Up(Stations.Spot(far)));
yield return new WaitForSeconds(0.5f);
yield return Shot("47_station");
var depot = Depot.All.Find(d => (d.transform.position - Stations.Spot(far)).sqrMagnitude < 25f);
var bundle = Spawner.Instance.SpawnCargo(CargoKind.Grass, Me.transform.position + Planet.Up(Me.transform.position), Quaternion.identity, Vector3.zero);
double cash = Ts.Money.Value;
yield return new WaitForSeconds(0.3f);
if (depot) depot.ServerAccept(bundle, bundle.transform.position, Vector3.zero);
yield return new WaitForSeconds(0.5f);
Log($"its depot paid {Ts.Money.Value - cash:0.##} for a bundle");
UIRoot.I.OpenStations();
yield return new WaitForSeconds(0.6f);
yield return Shot("48_stations");
UIRoot.I.CloseTopModal();
cash = Ts.Money.Value;
Ts.TravelRpc(far);
Ts.TravelRpc(unfound);
yield return new WaitForSeconds(0.5f);
Log($"travel refused to here and to the unfound: {cash - Ts.Money.Value:0.##} paid");
Ts.TravelRpc(0);
yield return new WaitForSeconds(1f);
Log($"travel home: {cash - Ts.Money.Value:0.##} paid, {Vector3.Distance(Me.transform.position, Stations.Arrival(0)):0.0} m from where you step out");
UIRoot.I.OpenSlots();
yield return new WaitForSeconds(0.6f);
yield return Shot("49_slots");
UIRoot.I.CloseTopModal();
Me.SetFlying(true);
}
/// Stage 12: what forty robots cost, the new models, the awards.
IEnumerator Loaded()
{
Vector3 At(float x, float z, float h = 0f)
{
var d = Planet.FromBase(x, z);
return Planet.OnSurface(d) + d * h;
}
Ts.ServerSetMoney(Ts.Money.Value + 30000d);
Me.Teleport(At(0f, 500f, 40f));
Me.SetFlying(true);
yield return Fps("over the meadow before the robots");
var mine = new List();
for (int i = 0; i < 40; i++)
{
float a = i * Mathf.PI / 20f;
var spot = At(Mathf.Cos(a) * 110f, 500f + Mathf.Sin(a) * 110f);
Ts.BuildRpc((byte)PieceId.RobotI, spot, Quaternion.LookRotation(Vector3.ProjectOnPlane(Vector3.forward, Planet.Up(spot)), Planet.Up(spot)), Vector3.zero);
if (i % 8 == 7) yield return null;
}
yield return new WaitForSeconds(1f);
int bots = Mowbot.All.Count;
Mowbot.Haste = 4f;
yield return new WaitForSeconds(6f);
yield return Fps($"{bots} robots at work below");
Me.LookAt(At(90f, 500f));
yield return new WaitForSeconds(0.5f);
yield return Shot("50_robots");
Mowbot.Haste = 1f;
foreach (var p in BuildPiece.All.ToList())
if (p.piece == PieceId.RobotI && Vector3.Distance(p.transform.position, At(0f, 500f)) < 140f) Ts.RemovePieceRpc(p.NetworkObjectId);
yield return new WaitForSeconds(1f);
Log($"robots: {bots} built, {Mowbot.All.Count} left after clearing them away");
// each new model side by side, on the ground and in the build panel's icons
var view = At(-12f, -40f, 1.5f);
Me.SetFlying(false);
Me.Teleport(view);
float x = -20f;
foreach (var id in new[] { PieceId.SolarS, PieceId.SolarM, PieceId.SolarL, PieceId.Binder, PieceId.Catcher, PieceId.RobotII })
{
var spot = At(x, -30f);
Ts.BuildRpc((byte)id, spot, Quaternion.LookRotation(Vector3.ProjectOnPlane(Vector3.back, Planet.Up(spot)), Planet.Up(spot)), Vector3.zero);
x += 4.5f;
}
yield return new WaitForSeconds(1f);
Me.LookAt(At(-9f, -30f, 1f));
yield return new WaitForSeconds(0.6f);
yield return Shot("51_models");
yield return new WaitForSeconds(2.5f);
Log($"awards: {Achievements.Earned} of {Achievements.All.Count}: {string.Join(", ", Achievements.All.Where(Achievements.Has).Select(a => a.id))}");
UIRoot.I.OpenAwards();
yield return new WaitForSeconds(0.6f);
yield return Shot("52_awards");
UIRoot.I.CloseTopModal();
Me.SetFlying(true);
}
/// `-demoteam host` and four `-demoteam join`: a crew mowing one field side by side, for the store page.
IEnumerator Team(bool host)
{
const int Crew = 4;
const float Gap = 3.4f;
var field = Planet.FromBase(70f, 46f);
var ahead = -Vector3.ProjectOnPlane(Vector3.forward, field).normalized;
var side = Vector3.Cross(field, ahead);
Vector3 Spot(float across, float along) => Planet.OnSurface((field * Planet.Radius + side * across + ahead * along).normalized);
yield return new WaitForSeconds(2f);
if (host) { TeamState.DeleteSave(); NetSession.Instance.HostLocal(); }
else
{
Application.targetFrameRate = 15;
foreach (var cam in FindObjectsByType(FindObjectsSortMode.None)) cam.enabled = false;
yield return new WaitForSeconds(10f);
NetSession.Instance.JoinLocal("127.0.0.1");
}
while (!Me || !Ts) yield return null;
float t0 = Time.time;
if (!host)
{
int k = (int)Me.OwnerClientId - 1;
var tool = new[] { ToolId.Scythe, ToolId.LongScythe, ToolId.Sickle, ToolId.WideScythe }[k % Crew];
yield return new WaitForSeconds(6f);
Ts.BuyToolRpc((byte)ToolId.NailScissors);
yield return new WaitForSeconds(0.5f);
Ts.BuyToolRpc((byte)tool);
yield return new WaitForSeconds(1f);
Me.Tools.Equip(tool);
float across = (k - (Crew - 1) * 0.5f) * Gap, along = k % 2 * 1.3f;
Me.Teleport(Spot(across, along) + field * 0.1f);
yield return new WaitForSeconds(1f);
Ctl.BotUseHeld = true;
while (Me && Time.time - t0 < 110f)
{
Me.LookAt(Spot(across + Mathf.Sin(Time.time * 1.4f) * 1.2f, along + 2f));
yield return null;
}
Application.Quit();
yield break;
}
Cheats.Run("money 50000");
Cheats.Run("tool all");
while (PlayerAgent.All.Count < Crew + 1 && Time.time - t0 < 50f) yield return null;
Log($"crew: {PlayerAgent.All.Count} players");
yield return new WaitForSeconds(11f);
// the stripes they have already mown behind them
for (int k = 0; k < Crew; k++)
{
float across = (k - (Crew - 1) * 0.5f) * Gap;
MowMap.Cut(Spot(across, -26f), Spot(across, k % 2 * 1.3f), 2.3f);
}
Me.SetFlying(true);
Me.Tools.Equip(ToolId.WideScythe);
ViewModel.Hidden = true;
var views = new[] { (0f, 8.5f, 1.5f, 0f, 0.7f), (-7f, 7f, 2.2f, 0f, 0.7f), (8f, 6f, 1.3f, 0f, 0.7f), (0f, 11f, 5f, -4f, 0.7f), (-1.7f, 3.4f, 0.7f, 0f, 1.5f), (1.7f, 4.2f, 0.5f, 0f, 2f), (-4f, 5.5f, 0.6f, -1f, 2.4f), (0f, 7f, 0.9f, 0f, 3f) };
for (int i = 0; i < views.Length; i++)
{
var v = views[i];
var at = Spot(v.Item1, v.Item2) + field * v.Item3;
Me.Teleport(at);
Me.LookAt(Spot(0f, v.Item4) + field * v.Item5);
yield return new WaitForSeconds(1.2f);
yield return Shot("team_" + i);
}
Log($"crew tools: {string.Join(", ", PlayerAgent.All.Select(p => (ToolId)p.ToolNet.Value))}");
Application.Quit();
}
/// `-democrowd host` and a crowd of `-democrowd join`: a full game, and one too many.
IEnumerator Crowd(bool host)
{
NetSession.Instance.Failed += reason => Log($"refused: {reason}");
yield return new WaitForSeconds(2f);
if (host) { TeamState.DeleteSave(); NetSession.Instance.HostLocal(); }
else
{
// sixteen of these on one computer: nobody draws anything
Application.targetFrameRate = 15;
foreach (var cam in FindObjectsByType(FindObjectsSortMode.None)) cam.enabled = false;
yield return new WaitForSeconds(10f);
NetSession.Instance.JoinLocal("127.0.0.1");
}
float t0 = Time.time;
int most = 0;
while (Time.time - t0 < 100f)
{
most = Mathf.Max(most, PlayerAgent.All.Count);
yield return new WaitForSeconds(1f);
}
Log($"crowd: {most} players at the most, {PlayerAgent.All.Count} now, {1f / Mathf.Max(0.0001f, Time.smoothDeltaTime):0} fps, state {NetSession.Instance.Current}");
Application.Quit();
}
/// Stage 10: the binder, a robot on its dock, the Reaper and its catcher.
IEnumerator Robots()
{
Vector3 At(float x, float z, float h = 0f)
{
var d = Planet.FromBase(x, z);
return Planet.OnSurface(d) + d * h;
}
Quaternion Turn(Vector3 p) => Quaternion.LookRotation(Vector3.ProjectOnPlane(Vector3.forward, Planet.Up(p)), Planet.Up(p));
Vector3 Lay(BuildPiece piece, float metres)
{
var ports = new List();
piece.Ports(ports);
var end = Planet.Surface(ports[0].at + ports[0].dir * metres);
end += Planet.Up(end);
if (!BuildRules.CanRun(ports[0].at, end, out var why)) Log($"can't lay a belt: {why}");
Ts.BuildRpc((byte)PieceId.Belt, ports[0].at, BuildRules.RunRotation(ports[0].at, end), end);
return end;
}
Ts.ServerSetMoney(Ts.Money.Value + 40000d);
Me.Teleport(At(210f, 40f, 1.5f));
yield return new WaitForSeconds(0.5f);
var spot = At(200f, 40f);
Ts.BuildRpc((byte)PieceId.Binder, spot, Turn(spot), Vector3.zero);
yield return new WaitForSeconds(0.5f);
var binder = BuildPiece.All.Find(p => p.piece == PieceId.Binder);
if (!binder) { Log("binder NOT built"); yield break; }
var end = Lay(binder, 7f);
yield return new WaitForSeconds(0.5f);
binder.GetComponent().TakeRpc(3.4f);
yield return new WaitForSeconds(2f);
Log($"binder: {binder.GetComponent().Silo.Value:0.##} kg left, {Cargo.All.Count(c => Vector3.Distance(c.transform.position, end) < 9f)} bundles along the belt");
Mowbot.Haste = 12f;
spot = At(230f, -60f);
Ts.BuildRpc((byte)PieceId.RobotI, spot, Turn(spot), Vector3.zero);
yield return new WaitForSeconds(0.5f);
var dock = Mowbot.All.OfType().FirstOrDefault();
if (!dock) { Log("dock NOT built"); yield break; }
Lay(dock.GetComponent(), 6f);
int closed = Ts.Closed.Value;
float t0 = Time.time;
while (Ts.Closed.Value == closed && Time.time - t0 < 95f) yield return null;
Log($"robot: {dock.Area()} sectors in reach, {Ts.Closed.Value - closed} closed after {Time.time - t0:0} s at {Mowbot.Haste:0}x, {dock.Prompt}");
Me.Teleport(dock.At.Value + Planet.Up(dock.At.Value) * 2.5f + Vector3.right * 3f);
yield return new WaitForSeconds(0.4f);
Me.LookAt(dock.At.Value);
yield return new WaitForSeconds(0.5f);
yield return Shot("44_robot_dock");
// the Reaper with no way out for its bundles stops, a belt on the catcher lets it go on
Me.Teleport(At(-230f, 60f, 1.5f));
yield return new WaitForSeconds(0.5f);
spot = At(-240f, 60f);
Ts.BuildRpc((byte)PieceId.Catcher, spot, Turn(spot), Vector3.zero);
yield return new WaitForSeconds(0.3f);
spot = At(-260f, 90f);
Ts.BuildRpc((byte)PieceId.Reaper, spot, Turn(spot), Vector3.zero);
yield return new WaitForSeconds(0.5f);
var reaper = Mowbot.All.OfType().FirstOrDefault();
var catcher = BuildPiece.All.Find(p => p.piece == PieceId.Catcher);
if (!reaper || !catcher) { Log("reaper or catcher NOT built"); yield break; }
t0 = Time.time;
while (reaper.Doing != RobotMood.NoCatcher && Time.time - t0 < 25f) yield return null;
Log($"catcher with no belt: {catcher.GetComponent().Prompt}, {reaper.Prompt}, after {Time.time - t0:0} s");
Me.LookAt(catcher.transform.position);
yield return new WaitForSeconds(0.5f);
yield return Shot("45_catcher");
Lay(catcher, 9f);
closed = Ts.Closed.Value;
var was = reaper.At.Value;
t0 = Time.time;
yield return new WaitForSeconds(2f);
Me.Teleport(reaper.At.Value + Planet.Up(reaper.At.Value) * 6f + Vector3.right * 6f);
yield return new WaitForSeconds(0.3f);
Me.LookAt(reaper.At.Value);
yield return new WaitForSeconds(0.5f);
yield return Shot("46_reaper");
while (Ts.Closed.Value == closed && Time.time - t0 < 60f) yield return null;
Log($"reaper: {Ts.Closed.Value - closed} closed after {Time.time - t0:0} s, {Vector3.Distance(was, reaper.At.Value):0} m on, {reaper.Prompt}");
Mowbot.Haste = 1f;
Me.SetFlying(true);
}
/// Stage 8: a dryer and a press on solar power by the base, then the night.
IEnumerator Production()
{
Vector3 At(float x, float z, float h = 0f)
{
var d = Planet.FromBase(x, z);
return Planet.OnSurface(d) + d * h;
}
void Lay(Vector3 from, Vector3 to)
{
if (!BuildRules.CanRun(from, to, out var why)) Log($"can't lay a belt: {why}");
Ts.BuildRpc((byte)PieceId.Belt, from, BuildRules.RunRotation(from, to), to);
}
Quaternion Facing(Vector3 at) => Quaternion.LookRotation(Vector3.ProjectOnPlane(Vector3.forward, Planet.Up(at)), Planet.Up(at));
void Put(PieceId id, Vector3 at) => Ts.BuildRpc((byte)id, at, Facing(at), Vector3.zero);
Sun.Pinned = 0.97f;
Ts.ServerSetMoney(Ts.Money.Value + 6000d);
Me.SetFlying(false);
Me.Teleport(At(47f, 24f, 2f));
Me.LookAt(At(40f, 34f, 1f));
yield return new WaitForSeconds(0.8f);
Put(PieceId.Dryer, At(40f, 30f));
Put(PieceId.Press, At(40f, 40f));
yield return new WaitForSeconds(0.5f);
var dryer = Machine.All.Find(m => m.GetComponent().piece == PieceId.Dryer);
var press = Machine.All.Find(m => m.GetComponent().piece == PieceId.Press);
if (!dryer || !press) { Log("machines NOT built"); yield break; }
var dp = new List();
var pp = new List();
dryer.Ports(dp);
press.Ports(pp);
Log($"machines: dryer {dp.Count} ports, press {pp.Count} ports, {dryer.Kw:0}+{press.Kw:0} kW");
Lay(At(40f, 21f, 0.6f), dp[0].at);
Lay(dp[1].at, pp[0].at);
Lay(At(44f, 30f, 0.6f), pp[1].at);
Lay(pp[2].at, At(40f, 48f, 0.6f));
yield return new WaitForSeconds(0.5f);
void Feed(float x, float z) => Spawner.Instance.SpawnCargo(CargoKind.Grass, At(x, z, 1.3f), Quaternion.identity, Vector3.zero);
for (int i = 0; i < 5; i++)
{
Feed(40f, 22f);
yield return new WaitForSeconds(0.7f);
}
yield return new WaitForSeconds(6f);
Log($"no panel: {dryer.Prompt}");
yield return Shot("38_machines");
// the speed follows the power: a post gives 3 of the 10 kW, so it should run at 30%
Put(PieceId.SolarS, At(34f, 30f));
yield return new WaitForSeconds(1.5f);
float had = dryer.Grass.Value;
float t0 = Time.time;
yield return new WaitForSeconds(6f);
Log($"one post: {dryer.Prompt}, {(had - dryer.Grass.Value) / (Time.time - t0) * 60f:0.0} kg of grass a minute, full speed is 25");
Put(PieceId.SolarM, At(34f, 36f));
Put(PieceId.SolarL, At(47f, 36f));
yield return new WaitForSeconds(1f);
had = dryer.Grass.Value;
t0 = Time.time;
yield return new WaitForSeconds(4f);
Log($"three panels: {dryer.Prompt}, {(had - dryer.Grass.Value) / (Time.time - t0) * 60f:0.0} kg of grass a minute");
foreach (var p in PowerNode.All) Log(p.Prompt);
for (int i = 0; i < 3; i++)
{
Feed(44f, 31f);
yield return new WaitForSeconds(0.7f);
}
t0 = Time.time;
while (Cargo.All.Count(c => c.kind == CargoKind.Brick) < 2 && Time.time - t0 < 30f) yield return null;
Log($"press: {press.Prompt}, {Cargo.All.Count(c => c.kind == CargoKind.Brick)} bricks after {Time.time - t0:0.0} s");
Me.Teleport(At(36f, 44f, 2f));
Me.LookAt(At(40f, 40f, 1f));
yield return new WaitForSeconds(5f);
yield return Shot("39_production");
Log($"line after a while: {Cargo.All.Count(c => c.kind == CargoKind.Hay)} hay and {Cargo.All.Count(c => c.kind == CargoKind.Brick)} bricks out, press holds {press.Hay.Value:0} hay, {press.Grass.Value:0} grass");
// what each pays at the depot
var dep = Depot.All[0];
foreach (var kind in new[] { CargoKind.Hay, CargoKind.Brick })
{
double before = Ts.Money.Value;
var c = Spawner.Instance.SpawnCargo(kind, dep.Mouth, Quaternion.identity, Vector3.zero);
dep.ServerAccept(c, dep.Mouth, Vector3.down);
Log($"{kind} at the depot: {Ts.Money.Value - before:0.##} a kilo");
yield return new WaitForSeconds(0.2f);
}
// dusk and night
Sun.Pinned = 0.27f;
yield return new WaitForSeconds(0.5f);
yield return Shot("40_dusk");
Sun.Pinned = 0.5f;
yield return new WaitForSeconds(1f);
for (int i = 0; i < 5; i++)
{
Feed(40f, 22f);
yield return new WaitForSeconds(0.7f);
}
yield return new WaitForSeconds(4f);
Log($"night: sun {Sun.Height(Vector3.up):0.00} here, panels give {PowerNode.All.OfType().Sum(p => p.Output.Value):0.0} kW, {dryer.Prompt}");
Me.Teleport(At(32f, 30f, 2f));
Me.LookAt(At(40f, 30f, 1f));
yield return new WaitForSeconds(0.5f);
yield return Shot("41_night_lamp");
Ts.BuyGearRpc((byte)GearId.NightVision);
yield return new WaitForSeconds(0.4f);
DayNight.SetView(DayNight.NightVision);
yield return new WaitForSeconds(0.4f);
yield return Shot("42_night_vision");
DayNight.SetView(DayNight.Off);
yield return new WaitForSeconds(0.4f);
yield return Shot("43_night_dark");
DayNight.SetView(DayNight.Lamp);
Sun.Pinned = 0.93f;
Log($"gear: night vision {Me.HasGear(GearId.NightVision)}");
yield return new WaitForSeconds(0.4f);
}
/// Stage 13: a battery through the night, poles carrying the network, and what junctions do with their ways.
IEnumerator Network()
{
var up = Planet.FromLatLon(-30f, 120f);
var north = Vector3.ProjectOnPlane(Vector3.up, up).normalized;
var east = Vector3.Cross(up, north);
var turn = Quaternion.LookRotation(north, up);
Vector3 At(float x, float z, float h = 0f)
{
var d = (up * Planet.Radius + east * x + north * z).normalized;
return Planet.OnSurface(d) + d * h;
}
void Lay(Vector3 from, Vector3 to)
{
if (!BuildRules.CanRun(from, to, out var why)) Log($"can't lay a belt {Vector3.Distance(from, to):0.0} m long, {Vector3.Distance(from, At(-30f, 40f)):0.0} m from the merger: {why}");
Ts.BuildRpc((byte)PieceId.Belt, from, BuildRules.RunRotation(from, to), to);
}
void Put(PieceId id, Vector3 at) => Ts.BuildRpc((byte)id, at, turn, Vector3.zero);
BuildPiece Newest(PieceId id) => BuildPiece.All.FindLast(p => p.piece == id);
void Feed(CargoKind kind, Vector3 at) => Spawner.Instance.SpawnCargo(kind, at, Quaternion.identity, Vector3.zero);
string Where(BuildPiece j, float reach)
{
int left = 0, right = 0, front = 0;
foreach (var c in Cargo.All)
{
var l = j.transform.InverseTransformPoint(c.transform.position);
if (Mathf.Abs(l.x) > reach || l.z < -1f || l.z > reach) continue;
if (l.x < -0.7f) left++;
else if (l.x > 0.7f) right++;
else if (l.z > 0.7f) front++;
}
return $"{left} left, {right} right, {front} straight on";
}
// noon and midnight here
float noon = 0f, midnight = 0f, high = -2f, low = 2f;
for (int k = 0; k < 20; k++)
{
Sun.Pinned = k / 20f;
yield return null;
float h = Sun.Height(up);
if (h > high) { high = h; noon = Sun.Pinned; }
if (h < low) { low = h; midnight = Sun.Pinned; }
}
Sun.Pinned = midnight;
Ts.ServerSetMoney(Ts.Money.Value + 30000d);
Me.SetFlying(false);
Me.Teleport(At(-6f, -6f, 2f));
Me.LookAt(At(3f, 2f, 1f));
yield return new WaitForSeconds(0.8f);
Put(PieceId.Dryer, At(0f, 0f));
Put(PieceId.BatteryS, At(5f, 0f));
Put(PieceId.Press, At(0f, 5f));
yield return new WaitForSeconds(0.8f);
var dryer = Newest(PieceId.Dryer).GetComponent();
var press = Newest(PieceId.Press).GetComponent();
var rack = Newest(PieceId.BatteryS).GetComponent();
dryer.Grass.Value = 10f;
yield return new WaitForSeconds(1.5f);
Log($"night, empty battery: {dryer.Prompt}");
rack.State = new[] { 2f };
yield return new WaitForSeconds(1.5f);
float had = dryer.Grass.Value, t0 = Time.time;
yield return new WaitForSeconds(5f);
Log($"night on a battery: {dryer.Prompt}, {(had - dryer.Grass.Value) / (Time.time - t0) * 60f:0.0} kg of grass a minute");
Log(rack.Prompt);
press.Grass.Value = 10f;
press.Hay.Value = 10f;
yield return new WaitForSeconds(1.5f);
Log($"more than it can give: {dryer.Prompt} / {press.Prompt}");
yield return Shot("53_battery_night");
rack.State = new[] { 0.002f };
yield return new WaitForSeconds(1.5f);
Log($"battery run down: {dryer.Prompt}, {rack.Prompt}");
Sun.Pinned = noon;
dryer.Grass.Value = 0f;
press.Grass.Value = 0f;
press.Hay.Value = 0f;
Put(PieceId.Pole, At(25f, 0f));
Put(PieceId.Pole, At(50f, 0f));
Put(PieceId.SolarS, At(68f, 0f));
yield return new WaitForSeconds(1.5f);
float before = rack.Stored.Value;
yield return new WaitForSeconds(3f);
Log($"sun through two poles: {Newest(PieceId.Pole).GetComponent().Prompt} / {rack.Prompt}, {rack.Stored.Value - before:0.0000} kWh in 3 s");
Me.Teleport(At(14f, -8f, 2.4f));
Me.LookAt(At(40f, 0f, 3f));
yield return new WaitForSeconds(0.6f);
yield return Shot("54_poles");
// only the left way joined: nothing falls off the other two
Me.Teleport(At(-7f, 32f, 3f));
Me.LookAt(At(0f, 40f, 0.5f));
Put(PieceId.Splitter, At(0f, 40f, 0.6f));
yield return new WaitForSeconds(0.5f);
var sp = Newest(PieceId.Splitter);
var ports = new List();
sp.Ports(ports);
Lay(At(0f, 30f, 0.6f), ports[0].at);
Lay(ports[2].at, At(-5f, 40f, 0.6f));
yield return new WaitForSeconds(0.6f);
for (int i = 0; i < 4; i++)
{
Feed(CargoKind.Grass, At(0f, 31f, 1.5f));
yield return new WaitForSeconds(0.9f);
}
yield return new WaitForSeconds(9f);
Log($"one way joined: {Where(sp, 9f)}");
// the other two joined as well, and the left way blocked by a full machine: the rest carry on
Lay(ports[1].at, At(5f, 40f, 0.6f));
Lay(ports[3].at, At(0f, 46f, 0.6f));
yield return new WaitForSeconds(0.6f);
foreach (var c in Cargo.All.ToArray()) if (c.Grab.Body && (c.transform.position - At(0f, 40f)).sqrMagnitude < 150f) c.NetworkObject.Despawn(true);
for (int i = 0; i < 6; i++)
{
Feed(CargoKind.Grass, At(0f, 31f, 1.5f));
yield return new WaitForSeconds(0.9f);
}
yield return new WaitForSeconds(9f);
Log($"three ways in turn: {Where(sp, 9f)}");
yield return Shot("55_splitter");
// a sorter: hay left, the rest the other ways
foreach (var c in Cargo.All.ToArray()) if (c.Grab.Body && (c.transform.position - At(0f, 40f)).sqrMagnitude < 150f) c.NetworkObject.Despawn(true);
sp.Mode.Value = 2;
yield return new WaitForSeconds(0.3f);
Log(sp.GetComponent().Prompt);
for (int i = 0; i < 6; i++)
{
Feed(i % 2 == 0 ? CargoKind.Hay : CargoKind.Grass, At(0f, 31f, 1.5f));
yield return new WaitForSeconds(0.9f);
}
yield return new WaitForSeconds(9f);
int hayLeft = Cargo.All.Count(c => c.kind == CargoKind.Hay && sp.transform.InverseTransformPoint(c.transform.position).x < -0.7f);
Log($"sorter: {Where(sp, 9f)}, {hayLeft} of 3 hay on the left");
// a blocked way: the left belt runs into a dryer that's full
Put(PieceId.Dryer, At(30f, 40f));
yield return new WaitForSeconds(0.5f);
var full = Newest(PieceId.Dryer).GetComponent();
full.Grass.Value = 10f;
var fp = new List();
full.Ports(fp);
Put(PieceId.Splitter, At(30f, 30f, 0.6f));
yield return new WaitForSeconds(0.5f);
var sp2 = Newest(PieceId.Splitter);
var p2 = new List();
sp2.Ports(p2);
Lay(At(30f, 22f, 0.6f), p2[0].at);
Lay(p2[3].at, fp[0].at);
Lay(p2[1].at, At(36f, 30f, 0.6f));
yield return new WaitForSeconds(0.6f);
for (int i = 0; i < 28; i++)
{
Feed(CargoKind.Grass, At(30f, 23f, 1.5f));
yield return new WaitForSeconds(0.7f);
}
yield return new WaitForSeconds(7f);
int past = Cargo.All.Count(c => sp2.transform.InverseTransformPoint(c.transform.position).x > 0.7f);
Log($"one way blocked: {past} went right past the full belt");
// a merger with all three ways in
Me.Teleport(At(-30f, 32f, 3f));
Me.LookAt(At(-30f, 40f, 0.5f));
Put(PieceId.Merger, At(-30f, 40f, 0.6f));
yield return new WaitForSeconds(0.5f);
var mg = Newest(PieceId.Merger);
var mp = new List();
mg.Ports(mp);
Lay(At(-36f, 40f, 0.6f), mp[0].at);
Lay(At(-24f, 40f, 0.6f), mp[1].at);
Lay(At(-30f, 34f, 0.6f), mp[2].at);
Lay(mp[3].at, At(-30f, 50f, 0.6f));
yield return new WaitForSeconds(0.6f);
for (int i = 0; i < 3; i++)
{
Feed(CargoKind.Grass, At(-35f, 40f, 1.5f));
Feed(CargoKind.Hay, At(-25f, 40f, 1.5f));
Feed(CargoKind.Brick, At(-30f, 35f, 1.5f));
yield return new WaitForSeconds(1.2f);
}
yield return new WaitForSeconds(8f);
int outThere = Cargo.All.Count(c => { var l = mg.transform.InverseTransformPoint(c.transform.position); return l.z > 1f && Mathf.Abs(l.x) < 3f && l.z < 14f; });
Log($"merger: {outThere} of 9 came out of the front, it stands {Vector3.Distance(mg.transform.position, At(-30f, 40f)):0.0} m from where it was put");
yield return Shot("56_merger");
}
/// Stage 14: the fields, the old farm, which way the machines point, and the moon.
IEnumerator Scenery()
{
float pinned = Sun.Pinned, noon = 0f, midnight = 0f, high = -2f, low = 2f;
var up = Planet.FromBase(0f, 0f);
for (int k = 0; k < 20; k++)
{
Sun.Pinned = k / 20f;
yield return null;
float h = Sun.Height(up);
if (h > high) { high = h; noon = Sun.Pinned; }
if (h < low) { low = h; midnight = Sun.Pinned; }
}
Sun.Pinned = noon;
Me.SetFlying(true);
foreach (var crop in new[] { Crop.Wheat, Crop.Oats, Crop.Corn, Crop.Sunflowers })
{
var d = Crops.FirstField(crop);
var side = Vector3.Cross(d, Vector3.right).normalized;
var id = HexGrid.SectorAt(d);
Log($"{crop}: sector {id + 1} grows {Crops.At(id)}, {Vector3.Distance(Planet.OnSurface(d), Planet.OnSurface(up)):0} m from the base");
Me.Teleport(Planet.OnSurface((d + side * (58f / Planet.Radius)).normalized) + d * 2.2f);
Me.LookAt(Planet.OnSurface(d) + d);
yield return new WaitForSeconds(0.8f);
yield return Shot("60_field_" + crop);
Me.Teleport(Planet.OnSurface(d) + d * 1.3f);
Me.LookAt(Planet.OnSurface((d + side * (30f / Planet.Radius)).normalized) + d * 1.3f);
yield return new WaitForSeconds(0.8f);
yield return Shot("61_inside_" + crop);
}
Me.Teleport(Planet.OnSurface(Planet.FromBase(-30f, 66f)) + up * 4f);
Me.LookAt(Planet.OnSurface(Planet.FromBase(-66f, 36f)) + up * 2f);
yield return new WaitForSeconds(0.8f);
yield return Shot("62_clearing");
Me.Teleport(Planet.OnSurface(Planet.FromBase(95f, 20f)) + up * 3f);
Me.LookAt(Planet.OnSurface(Planet.FromBase(165f, 40f)) + up * 2f);
yield return new WaitForSeconds(0.8f);
yield return Shot("63_field_from_afar");
Me.Teleport(Planet.OnSurface(Planet.FromBase(60f, 50f)) + up * 2f);
Me.LookAt(Planet.OnSurface(Planet.FromBase(88f, 72f)) + up);
yield return new WaitForSeconds(0.8f);
yield return Shot("64_flowers");
foreach (var v in Vehicle.All.ToArray())
{
var t = v.transform;
Me.Teleport(t.position + t.forward * (v.length * 0.5f + 4f) + t.right * 2.5f + t.up * 2.2f);
Me.LookAt(t.position + t.up);
yield return new WaitForSeconds(0.6f);
yield return Shot("65_front_" + v.kind);
float front = v.wheels.Where(w => w.name.ToUpperInvariant().Contains("WHEEL_F")).DefaultIfEmpty(t).Average(w => t.InverseTransformPoint(w.position).z);
float rear = v.wheels.Where(w => w.name.ToUpperInvariant().Contains("WHEEL_R")).DefaultIfEmpty(t).Average(w => t.InverseTransformPoint(w.position).z);
Log($"{v.Def.name}: front wheels at {front:0.00}, rear at {rear:0.00}, seat at {t.InverseTransformPoint(v.seat.position).z:0.00}");
}
Sun.Pinned = midnight;
Me.Teleport(Planet.OnSurface(Planet.FromBase(-30f, 66f)) + up * 4f);
Me.LookAt(Planet.OnSurface(Planet.FromBase(-66f, 36f)) + up * 2f);
yield return new WaitForSeconds(1f);
yield return Shot("66_moonlight");
Sun.Pinned = pinned;
Me.SetFlying(false);
}
IEnumerator JumpPeak(System.Action done)
{
Me.SetFlying(false);
Me.Teleport(new Vector3(14f, Soil + 0.1f, 12f));
yield return new WaitForSeconds(0.6f);
float from = Planet.Altitude(Me.transform.position), peak = 0f;
Ctl.BotJumpPressed = true;
yield return null;
Ctl.BotJumpPressed = false;
for (float t = 0f; t < 2.2f; t += Time.deltaTime)
{
peak = Mathf.Max(peak, Planet.Altitude(Me.transform.position) - from);
yield return null;
}
done(peak);
}
///
/// `-demopace`: the opening played for real at six times the speed: cut rows along the meadow, walk back (the trip
/// takes as long as it would at a sprint), hand in at the depot, buy in the order the guides recommend. Writes the
/// clock at each purchase.
///
IEnumerator Pace()
{
File.Delete(Path.Combine(folder, "pace.txt"));
void Note(string line) => File.AppendAllText(Path.Combine(folder, "pace.txt"), line + "\n");
TeamState.DeleteSave();
yield return new WaitForSeconds(2f);
NetSession.Instance.HostLocal();
while (!Me || !Ts) yield return null;
yield return new WaitForSeconds(2f);
Ts.BuyToolRpc((byte)ToolId.NailScissors);
yield return new WaitForSeconds(0.6f);
var depot = Depot.All[0];
var home = depot.transform.position + new Vector3(0f, 0.1f, -2.6f);
var shop = new (string name, double price, System.Action buy)[]
{
("Scythe", 25, () => Ts.BuyToolRpc((byte)ToolId.Scythe)),
("Scythe basket", 30, () => Ts.BuyPerkRpc((int)PerkId.BinScythe)),
("Second belt slot", 15, () => Ts.BuyBeltSlotRpc()),
("Hammer", 50, () => Ts.BuyToolRpc((byte)ToolId.Hammer)),
("Wider Blades", 40, () => Ts.BuyPerkRpc((int)PerkId.WiderBlades)),
("Long Scythe", 75, () => Ts.BuyToolRpc((byte)ToolId.LongScythe)),
("Servo Boots", 50, () => Ts.BuyPerkRpc((int)PerkId.ServoBoots)),
("Two-Handed Scythe", 150, () => Ts.BuyToolRpc((byte)ToolId.WideScythe)),
};
const float Scale = 6f, Limit = 1800f;
Time.timeScale = Scale;
float t0 = Time.time, z = -36f, x0 = 13f;
int next = 0, trips = 0;
var blade = ToolId.NailScissors;
string Clock() { int s = (int)(Time.time - t0); return $"{s / 60}:{s % 60:00}"; }
while (next < shop.Length && Time.time - t0 < Limit)
{
float width = Ts.ToolWidth(blade);
var start = new Vector3(x0, Soil + 0.1f, z);
z += 1.8f + width;
if (z > 36f) { z = -36f; x0 += 28f; }
yield return new WaitForSeconds((start - home).magnitude / Me.sprintSpeed);
Me.Tools.Select(blade);
Me.Teleport(start);
yield return null;
float cap = Ts.ToolCap(blade), t = 0f;
Ctl.BotUseHeld = true;
Ctl.BotMove = Vector2.up;
while (Me.Tools.Bin(blade) < cap - 0.01f && t < 70f)
{
t += Time.deltaTime;
var at = Me.transform.position;
Me.LookAt(Planet.Surface(at + Vector3.right * 1.5f + Vector3.forward * Mathf.Sin(t * 3f) * 0.9f));
yield return null;
}
Ctl.BotUseHeld = false;
Ctl.BotMove = Vector2.zero;
yield return new WaitForSeconds((Me.transform.position - home).magnitude / Me.sprintSpeed);
Me.Teleport(home);
yield return null;
Me.Tools.Deposit(depot);
trips++;
yield return new WaitForSeconds(1f);
while (next < shop.Length && Ts.Money.Value >= shop[next].price)
{
shop[next].buy();
Note($"{Clock()} {shop[next].name} ${shop[next].price} after {trips} trips, {Ts.Shipped.Value:0.0} kg shipped, ${Ts.Money.Value:0.00} left");
if (shop[next].name == "Scythe") blade = ToolId.Scythe;
else if (shop[next].name == "Long Scythe") blade = ToolId.LongScythe;
else if (shop[next].name == "Two-Handed Scythe") blade = ToolId.WideScythe;
next++;
yield return new WaitForSeconds(1f);
}
}
Time.timeScale = 1f;
Note($"{Clock()} stopped: {next} of {shop.Length} bought, {trips} trips, {Ts.Shipped.Value:0.0} kg shipped, {MowMap.MownArea():0} m² mown");
Application.Quit();
}
/// `-demohands`: every tool at rest, then one whole stroke of it frame by frame, slowed right down.
///
/// `-demolook N`: a saved game from the slot (counted from 1) as it stands, round the base at eye height and over
/// the sectors from above, then the crew's own arms in first person, and a grove coming down as its sector is finished.
///
IEnumerator LookAround(int slot)
{
SaveSlots.Current = slot - 1;
yield return new WaitForSeconds(2f);
NetSession.Instance.HostLocal();
while (!Me || !Ts) yield return null;
yield return new WaitForSeconds(4f);
Log($"loaded: ${Ts.Money.Value:0}, {MowMap.Started} sectors started, {MowMap.Finished} finished, {BuildPiece.All.Count} pieces");
foreach (var spot in new[] { new Vector2(-2f, -8f), new Vector2(10f, -30f), new Vector2(30f, -10f), new Vector2(-30f, -20f), new Vector2(0f, 20f) })
{
var at = Planet.FromBase(spot.x, spot.y);
Me.Teleport(Planet.OnSurface(at) + at * 0.2f);
yield return new WaitForSeconds(1.2f);
for (int k = 0; k < 6; k++)
{
float a = k * 60f * Mathf.Deg2Rad;
var e1 = Vector3.Cross(at, Vector3.forward).normalized;
var e2 = Vector3.Cross(e1, at);
Me.LookAt(Planet.OnSurface((at + (e1 * Mathf.Cos(a) + e2 * Mathf.Sin(a)) * 9f / Planet.Radius).normalized));
yield return new WaitForSeconds(0.5f);
yield return Shot($"look_{spot.x:0}_{spot.y:0}_{k}");
}
}
// every sector that has been started, from above, the busiest first
Me.SetFlying(true);
int n = 0;
foreach (var m in MowMap.All.Where(m => !m.done && m.mown > 0f).OrderByDescending(m => m.mown).Take(6))
{
Me.Teleport(Planet.OnSurface(m.s.c) + m.s.c * 30f);
Me.LookAt(Planet.OnSurface(m.s.c));
yield return new WaitForSeconds(1.5f);
yield return Shot($"above_{n++}_{m.s.id}");
Log($"sector {m.s.id}: {m.mown:0}/{m.total:0} m², done {m.done}, {MowMap.Leftover(m.s.id, out _)} cells with grass left");
}
Me.SetFlying(false);
// what is left of the nearly finished sectors near the base, at eye height from three metres off
n = 0;
var home = Planet.FromBase(0f, 0f);
foreach (var m in MowMap.All.Where(m => !m.done && m.total > 0f && m.mown > m.total * 0.9f && (m.s.c - home).magnitude * Planet.Radius < 200f).OrderBy(m => (m.s.c - home).sqrMagnitude).Take(5).ToList())
{
int cells = MowMap.Leftover(m.s.id, out var left);
if (cells == 0) continue;
var side = Vector3.Cross(left, Vector3.forward).normalized;
var stand = (left + side * 3f / Planet.Radius).normalized;
Me.Teleport(Planet.OnSurface(stand) + stand * 0.2f);
yield return new WaitForSeconds(1f);
Me.LookAt(Planet.OnSurface(left));
yield return new WaitForSeconds(0.5f);
yield return Shot($"left_{n++}_{m.s.id}");
Log($"leftover in sector {m.s.id}: {cells} cells, {m.mown:0}/{m.total:0} m²");
}
// every machine and robot in the save, from a few metres off
n = 0;
foreach (var v in Vehicle.All.ToList()) if (v) yield return LookAt(v.transform.position, $"machine_{n++}_{v.kind}");
foreach (var m in Mowbot.All.ToList())
{
var b = m.ShownBody;
if (b)
{
var parts = string.Join(" ", b.GetComponentsInChildren().Select(c => $"{c.name}:{c.localRotation.eulerAngles.ToString("F0")}"));
Log($"robot {n} {m.GetType().Name}: tilt {Vector3.Angle(b.up, Planet.Up(b.position)):0}°, {parts}");
}
yield return LookAt(m.Shown, $"robot_{n++}");
}
// the arms of everyone on the roster, each tool at rest
for (int who = 0; who < Roster.All.Length; who++)
{
Me.Character.Value = (byte)who;
Me.Teleport(Planet.OnSurface(Planet.FromBase(20f, 30f)) + Planet.FromBase(20f, 30f) * 0.2f);
yield return new WaitForSeconds(0.5f);
foreach (var tool in new[] { ToolId.NailScissors, ToolId.Sickle, ToolId.Scythe, ToolId.Hammer })
{
if (!Me.Tools.Owns(tool)) Cheats.Run("tool all");
Me.Tools.Equip(tool);
Me.LookAt(Planet.OnSurface(Planet.FromBase(14f, 40f)));
yield return new WaitForSeconds(0.9f);
yield return Shot($"arms_{Roster.Of(who).name}_{tool}");
if (who > 0) break;
}
}
// the phone in the hand, upright and on its side
Me.Character.Value = 0;
yield return new WaitForSeconds(0.3f);
var phone = FindAnyObjectByType();
phone.Show(PhoneMode.Side);
yield return new WaitForSeconds(1.2f);
yield return Shot("phone_side");
phone.Screen.Turn();
yield return new WaitForSeconds(1.2f);
yield return Shot("phone_side_wide");
phone.Screen.Turn();
phone.Show(PhoneMode.Away);
yield return new WaitForSeconds(0.8f);
// a grove nearby, its sector finished while we watch
var grove = Ground.Instance.NearestPlant(Me.transform.position, out int sector);
if (grove != Vector3.zero)
{
var up = Planet.Up(grove);
var back = Vector3.Cross(up, Vector3.Cross(Vector3.forward, up)).normalized;
var stand = (up + back * 22f / Planet.Radius).normalized;
Me.Teleport(Planet.OnSurface(stand) + stand * 0.2f);
yield return new WaitForSeconds(1.2f);
Me.LookAt(grove + up * 3f);
yield return new WaitForSeconds(0.6f);
yield return Shot("fell_0_before");
MowMap.CutSector(sector);
for (int k = 1; k <= 6; k++)
{
yield return new WaitForSeconds(0.35f);
yield return Shot($"fell_{k}");
}
yield return new WaitForSeconds(1f);
yield return Shot("fell_9_after");
}
Application.Quit();
}
/// Stand off a thing at an angle, look at it, take a picture.
IEnumerator LookAt(Vector3 thing, string name)
{
var up = Planet.Up(thing);
var side = (Vector3.Cross(up, Vector3.forward).normalized * 0.8f + Vector3.Cross(up, Vector3.right).normalized * 0.6f).normalized;
var stand = (up + side * 5f / Planet.Radius).normalized;
Me.Teleport(Planet.OnSurface(stand) + stand * 0.2f);
yield return new WaitForSeconds(0.8f);
Me.LookAt(thing + up * 0.5f);
yield return new WaitForSeconds(0.6f);
yield return Shot(name);
}
static Vector3 Soil17(float x, float z) => Planet.Surface(new Vector3(x, Soil, z));
/// The clock at the base, 0..24.
static void Clock(float hour) => Sun.Pinned = Mathf.Repeat(hour / 24f + 0.5f, 1f);
IEnumerator Look(string name, Vector3 eye, Vector3 at, float wait = 0.6f)
{
BotCapture.From = (eye, at);
yield return new WaitForSeconds(wait);
yield return Shot(name);
}
///
/// `-demotreats`: the two vending machines on the deck. A look at both, then in first person: a kilo of grass into the
/// beer machine, the can into the hand, cracked, drunk, the boost, crushed and thrown; then the cigar machine, the
/// drawer, the light, the draw, the smoke and rings, the stub flicked away; the boost chips; the machines at night.
///
IEnumerator TreatsDemo()
{
TeamState.DeleteSave();
yield return new WaitForSeconds(2f);
NetSession.Instance.HostLocal();
while (!Me || !Ts) yield return null;
yield return new WaitForSeconds(3f);
Clock(16.5f);
Ts.ServerSetMoney(1000000);
yield return new WaitForSeconds(0.3f);
Ts.BuyToolRpc((byte)ToolId.NailScissors);
yield return new WaitForSeconds(0.5f);
Ts.BuyToolRpc((byte)ToolId.Scythe);
yield return new WaitForSeconds(0.8f);
Me.Tools.Equip(ToolId.Scythe);
yield return new WaitForSeconds(0.5f);
Me.Tools.CheatFill();
var beer = VendingMachine.All.Find(m => m && m.kind == TreatId.Beer);
var cigar = VendingMachine.All.Find(m => m && m.kind == TreatId.Cigar);
if (!beer || !cigar) { Log("treats: machines missing"); Application.Quit(); yield break; }
var up = beer.transform.up;
var mid = (beer.transform.position + cigar.transform.position) * 0.5f;
var fwd = beer.transform.forward;
var side = beer.transform.right;
yield return Look("t01_machines", mid + fwd * 4.2f + side * 1.6f + up * 1.6f, mid + up * 1.05f, 1.2f);
yield return Look("t02_machines_close", beer.transform.position + fwd * 2.1f - side * 0.9f + up * 1.5f, beer.transform.position + up * 1.2f);
IEnumerator Use(VendingMachine m, string tag, float[] at, string[] names)
{
BotCapture.From = null;
Me.Teleport(m.transform.position + m.transform.forward * 1.35f + up * 0.1f);
yield return new WaitForSeconds(0.4f);
Me.LookAt(m.transform.position + up * 1.15f);
yield return new WaitForSeconds(0.6f);
yield return Shot(tag + "_00_aim");
float kg = Me.Tools.Carried;
m.Interact();
Log($"treats: {tag} paid {kg - Me.Tools.Carried:0.00} kg");
float t0 = Time.time;
for (int i = 0; i < at.Length; i++)
{
while (Time.time - t0 < at[i]) yield return null;
yield return Shot(tag + "_" + names[i]);
}
}
yield return Use(beer, "t1beer", new[] { 0.3f, 1.25f, 1.75f, 2.75f, 3.4f, 4.15f, 4.65f, 5.1f, 5.45f },
new[] { "01_hopper", "02_whirr", "03_drop", "04_hand", "05_crack", "06_drink", "07_boost", "08_crush", "09_toss" });
yield return new WaitForSeconds(1.5f);
Me.Tools.CheatFill();
yield return Use(cigar, "t2cigar", new[] { 0.3f, 0.95f, 1.35f, 2.75f, 3.0f, 3.6f, 4.45f, 4.95f, 5.85f },
new[] { "01_hopper", "02_drawer", "03_cigar", "04_hand", "05_light", "06_draw", "07_exhale", "08_rings", "09_flick" });
yield return new WaitForSeconds(1.2f);
yield return Shot("t3_boosts");
Log($"treats: beer {Treats.Left(TreatId.Beer):0} s, cigar {Treats.Left(TreatId.Cigar):0} s, mow x{Treats.MowMul:0.0}, move x{Treats.MoveMul:0.0}");
Clock(21.5f);
yield return new WaitForSeconds(1f);
yield return Look("t4_night", mid + fwd * 4.2f - side * 1.2f + up * 1.7f, mid + up * 1.1f, 1f);
Application.Quit();
}
///
/// `-demohouse`: what the structures make. Two foundations lifted 1.5 m onto stilts with steps up, walls with a door and
/// windows, a floor on the walls with stairs up to it, railings round the top, a pitched roof over half and a flat roof
/// over the other; a fence, a lamp, a bench, a flower box, crates and a flag round it. Every piece goes through the
/// same snapping the hammer uses (Snap.Edge, Snap.OnTop, Foundation.Beside) and the real placement rule.
///
IEnumerator House()
{
TeamState.DeleteSave();
yield return new WaitForSeconds(2f);
NetSession.Instance.HostLocal();
while (!Me || !Ts) yield return null;
yield return new WaitForSeconds(3f);
Clock(10.5f);
var c = Soil17(60f, -40f);
var up = Planet.Up(c);
var east = Vector3.ProjectOnPlane(Vector3.right, up).normalized;
var north = Vector3.Cross(east, up);
var face = Quaternion.LookRotation(north, up);
int built = 0, refused = 0;
BuildPiece Put(PieceId id, Vector3 at, Quaternion rot)
{
var d = GameDefs.Piece(id);
if (!BuildRules.CanPlace(d, at, rot, null, out var why)) { refused++; Log($"house: {d.name} refused: {why}"); return null; }
built++;
return Spawner.Instance.SpawnPiece(id, at, rot, at, true);
}
// two slabs on stilts, side by side
var a = Put(PieceId.Square, c + up * 1.5f, face);
yield return new WaitForSeconds(0.6f);
Foundation.Beside(c + east * 3f + up * 1.8f, PieceId.Square, out var bAt, out var bRot);
var b = Put(PieceId.Square, bAt, bRot);
yield return new WaitForSeconds(0.8f);
// steps up to the front of the first
Put(PieceId.Steps, Planet.Surface(c - north * 2.7f), face);
// walls round both: the door in front of the first, windows at the sides, plain at the back
void Edge(PieceId id, BuildPiece on, Vector3 toward)
{
if (!on) return;
var top = on.transform.position + on.transform.up * Foundation.Top;
if (Snap.Edge(top + toward * 1.4f, on, 0f, out var at, out var rot)) Put(id, at, rot);
}
Edge(PieceId.DoorWall, a, -north);
Edge(PieceId.WindowWall, a, -east);
Edge(PieceId.Wall, a, north);
Edge(PieceId.WindowWall, b, -north);
Edge(PieceId.WindowWall, b, east);
Edge(PieceId.Wall, b, north);
yield return new WaitForSeconds(0.8f);
// a floor over the second, aimed at its back wall from inside
var wallB = BuildPiece.All.FirstOrDefault(p => p && p.piece == PieceId.Wall && b && (p.transform.position - (b.transform.position + north * 1.5f)).magnitude < 1.5f);
BuildPiece floor = null;
if (wallB && Snap.OnTop(PieceId.Floor, wallB.transform.position + up * 2.9f - north * 0.5f, wallB, null, 0f, out var fAt, out var fRot)) floor = Put(PieceId.Floor, fAt, fRot);
// and a pitched roof over the first, its eave on the side wall
var wallA = BuildPiece.All.FirstOrDefault(p => p && p.piece == PieceId.WindowWall && a && (p.transform.position - (a.transform.position - east * 1.5f)).magnitude < 1.5f);
if (wallA && Snap.OnTop(PieceId.Roof, wallA.transform.position + up * 2.9f + east * 0.5f, wallA, null, 0f, out var rAt, out var rRot)) Put(PieceId.Roof, rAt, rRot);
yield return new WaitForSeconds(0.8f);
// stairs inside the second, up to the floor
if (b) Put(PieceId.Stairs, Foundation.Grid(b.transform, b.transform.position + east * 0.5f - north * 0f), b.transform.rotation * Quaternion.Euler(0f, 0f, 0f));
// railings round the floor and a lamp on it
if (floor)
{
var ftop = floor.transform.position;
Edge(PieceId.Railing, floor, east);
Edge(PieceId.Railing, floor, -north);
Edge(PieceId.Railing, floor, north);
Put(PieceId.Lamppost, Foundation.Grid(floor.transform, ftop + east * 1f + north * 1f), face);
}
// round the house
Put(PieceId.Fence, Planet.Surface(c - north * 5f + east * 6f), face);
Put(PieceId.Fence, Planet.Surface(c - north * 5f + east * 9f), face);
Put(PieceId.Lamppost, Planet.Surface(c - north * 4f - east * 2.5f), face);
Put(PieceId.Bench, Planet.Surface(c - north * 4.5f + east * 2f), face);
Put(PieceId.Planter, Planet.Surface(c - north * 2.2f + east * 4.2f), face);
Put(PieceId.Crates, Planet.Surface(c + east * 6.5f), face);
Put(PieceId.Flagpole, Planet.Surface(c - east * 4f + north * 3f), face);
Put(PieceId.Pillar, Planet.Surface(c + east * 7f + north * 4f), face);
yield return new WaitForSeconds(2f);
Log($"house: {built} pieces built, {refused} refused, raised {(a ? Planet.Altitude(a.transform.position) : -1f):0.00} m, riders on the first {(a ? BuildRules.Riders(a).Count : -1)}");
var mid = c + east * 1.5f + up * 2f;
yield return Look("h01_front", mid - north * 13f + east * 4f + up * 3f, mid, 1.5f);
yield return Look("h02_corner", mid - north * 9f - east * 9f + up * 6f, mid);
yield return Look("h03_back", mid + north * 12f + east * 6f + up * 4f, mid);
yield return Look("h04_stilts", c - north * 6f - east * 3f + up * 0.6f, c + up * 1f);
yield return Look("h05_door", c - north * 4.5f + up * 2.4f, c + up * 2.8f);
yield return Look("h06_inside", (b ? b.transform.position : c) - north * 0.8f - east * 0.8f + up * 2f, (b ? b.transform.position : c) + north * 1.2f + up * 2.5f);
yield return Look("h07_top", mid + up * 16f - north * 6f, mid);
// the new drone pad and unload bay beside it
var padAt = Planet.Surface(c + east * 14f);
Spawner.Instance.SpawnPiece(PieceId.DronePad, padAt, face, padAt, true);
var bayAt = Planet.Surface(c + east * 14f - north * 9f);
Spawner.Instance.SpawnPiece(PieceId.UnloadBay, bayAt, face, bayAt, true);
yield return new WaitForSeconds(2f);
yield return Look("h09_dronepad", padAt - north * 5f + east * 3f + up * 3f, padAt + up * 0.8f);
yield return Look("h10_dronepad_close", padAt - north * 2.5f + east * 1.5f + up * 1.8f, padAt + up * 0.7f);
yield return Look("h11_unloadbay", bayAt + north * 8f + east * 5f + up * 4f, bayAt + up * 1.2f);
yield return Look("h12_unloadbay_front", bayAt - north * 6f - east * 4f + up * 2.5f, bayAt + up * 1f);
Clock(21.5f);
yield return new WaitForSeconds(1f);
yield return Look("h08_night", mid - north * 13f + east * 4f + up * 3f, mid, 1f);
Application.Quit();
}
/// `-demosize` (with `-difficulty 0..2`): the ball the new save is built on, from the deck, from the air and from space.
IEnumerator Sizes()
{
TeamState.DeleteSave();
yield return new WaitForSeconds(2f);
NetSession.Instance.HostLocal();
while (!Me || !Ts) yield return null;
yield return new WaitForSeconds(4f);
Clock(11f);
string tag = Difficulties.Tag(Difficulties.Current).Replace(' ', '_');
int here = HexGrid.SectorAt(Planet.FromBase(60f, 20f));
Log($"{Difficulties.Name(Difficulties.Current)}: radius {Planet.Radius:0} m, sector {GameDefs.SectorArea:0} m² (#{here + 1} is {HexGrid.Get(here).radius:0.0} m to its corner), planet {GameDefs.PlanetArea / 1e6:0.0} km², {GameDefs.PlanetKg / 1000:0} t of grass, size on the wire {Ts.Size.Value}, stations at {Mathf.Acos(Stations.Dir(1).y) * Planet.Radius:0} m");
var up = Vector3.up;
// the loading ramp and the unloading yard stay bare on every size of ball (a far spot for contrast)
Log("bare: ramp " + string.Join(" ", new[] { -10.5f, -12.2f, -14.5f }.Select(z => MowMap.Clear(Planet.Surface(new Vector3(0f, 0f, z))) ? "y" : "n"))
+ ", yard " + string.Join(" ", new[] { -16f, -20f, -26f }.Select(z => MowMap.Clear(Planet.Surface(new Vector3(5f, 0f, z))) ? "y" : "n"))
+ ", meadow " + (MowMap.Clear(Planet.Surface(new Vector3(40f, 0f, -60f))) ? "y" : "n"));
yield return Look($"z_{tag}_0_ramp", Planet.Surface(new Vector3(11f, 0f, -30f)) + up * 4f, Planet.Surface(new Vector3(0f, 0f, -14f)), 1.5f);
yield return Look($"z_{tag}_1_yard", Soil17(40f, -30f) + up * 1.8f, Soil17(90f, 10f) + up * 1f, 1.5f);
yield return Look($"z_{tag}_2_air", Soil17(0f, -80f) + up * 90f, Soil17(0f, 120f), 1.5f);
yield return Look($"z_{tag}_3_high", Planet.Center + new Vector3(0f, 0.6f, -0.8f).normalized * Planet.Radius * 1.35f, Planet.Center, 2f);
yield return Look($"z_{tag}_4_space", Planet.Center + new Vector3(0.3f, 0.5f, -0.8f).normalized * Planet.Radius * 3.2f, Planet.Center, 2f);
Application.Quit();
}
///
/// `-demobelts`: belts up a ramp and over the crest, round a corner on top and down again, a corner that climbs as it
/// turns, a sharp turn; cargo riding all of it. Close-ups of every joint, the hollows and the crests.
///
IEnumerator Belts()
{
TeamState.DeleteSave();
yield return new WaitForSeconds(2f);
NetSession.Instance.HostLocal();
while (!Me || !Ts) yield return null;
yield return new WaitForSeconds(3f);
Clock(11f);
var c = Soil17(70f, 40f);
var up = Planet.Up(c);
var east = Vector3.ProjectOnPlane(Vector3.right, up).normalized;
var north = Vector3.Cross(east, up);
Vector3 P(float x, float z, float h)
{
var g = Planet.Surface(c + east * x + north * z);
return g + Planet.Up(g) * h;
}
void Run(Vector3 from, Vector3 to) => Spawner.Instance.SpawnPiece(PieceId.Belt, from, BuildRules.RunRotation(from, to), to, true);
Vector3[] ramp = { P(0f, 0f, 0.6f), P(0f, 8f, 0.6f), P(0f, 16f, 4f), P(0f, 24f, 4f), P(8f, 24f, 4f), P(16f, 24f, 0.8f), P(16f, 32f, 0.8f) };
for (int i = 0; i + 1 < ramp.Length; i++) Run(ramp[i], ramp[i + 1]);
Vector3[] twist = { P(-14f, 0f, 0.6f), P(-14f, 8f, 0.6f), P(-22f, 14f, 3.2f), P(-22f, 22f, 3.2f), P(-16f, 23f, 3.2f) };
for (int i = 0; i + 1 < twist.Length; i++) Run(twist[i], twist[i + 1]);
yield return new WaitForSeconds(1.5f);
yield return Look("b01_overview", c + up * 26f - north * 14f + east * 2f, P(0f, 14f, 1f), 1.2f);
yield return Look("b02_ramp_side", P(-9f, 12f, 4f), P(0f, 12f, 2f));
yield return Look("b03_hollow", P(-3.5f, 6f, 2.2f), ramp[1]);
yield return Look("b04_crest", P(-3.5f, 18f, 5.6f), ramp[2]);
yield return Look("b05_top_corner", P(-3f, 27f, 6.4f), ramp[3]);
yield return Look("b06_down_side", P(10f, 18f, 4.5f), P(12f, 24f, 2.5f));
yield return Look("b07_down_crest", P(5f, 20f, 6.4f), ramp[4]);
yield return Look("b08_down_hollow_corner", P(19f, 21f, 2.8f), ramp[5]);
yield return Look("b09_twist", P(-10f, 12f, 5f), twist[2]);
yield return Look("b10_twist_top", P(-18f, 18f, 6f), twist[3]);
yield return Look("b11_under", P(3f, 12f, 0.4f), P(0f, 12f, 2f));
for (int k = 0; k < 14; k++)
{
Spawner.Instance.SpawnCargo(CargoKind.Grass, ramp[0] + Planet.Up(ramp[0]) * 0.8f, Quaternion.identity, Vector3.zero);
Spawner.Instance.SpawnCargo(CargoKind.Grass, twist[0] + Planet.Up(twist[0]) * 0.8f, Quaternion.identity, Vector3.zero);
yield return new WaitForSeconds(1.2f);
}
yield return Look("b12_cargo_ramp", P(-6f, 10f, 4f), P(0f, 14f, 2f), 0.2f);
yield return new WaitForSeconds(6f);
yield return Look("b13_cargo_top", P(-4f, 22f, 7f), P(4f, 24f, 4f), 0.2f);
yield return new WaitForSeconds(6f);
yield return Look("b14_cargo_down", P(10f, 18f, 4.5f), P(13f, 24f, 2.5f), 0.2f);
int riding = Conveyor.All.Sum(cv => cv ? cv.Count : 0);
int fell = Cargo.All.Count(g => g && !g.Belt && (g.transform.position - c).magnitude < 40f);
Log($"belts: {riding} bundles riding, {fell} off the belts");
Application.Quit();
}
/// `-democalls`: the Director's call and the assistant, up close, and what their booths film.
IEnumerator Calls()
{
TeamState.DeleteSave();
yield return new WaitForSeconds(2f);
NetSession.Instance.HostLocal();
while (!Me || !Ts) yield return null;
Clock(11f);
yield return new WaitForSeconds(4f);
DirectorCall.Call("dir_intro");
float wait = Time.time;
while (Time.time - wait < 8f && !(Phone.I && Phone.I.Mode != PhoneMode.Away)) yield return null;
if (Phone.I) Phone.I.Show(PhoneMode.Up);
(float at, string name)[] marks = { (1.5f, "c01"), (3f, "c02"), (6f, "c03"), (9f, "c04"), (13f, "c05"), (20f, "c06") };
float t0 = Time.time;
foreach (var (at, name) in marks)
{
while (Time.time - t0 < at) yield return null;
yield return Shot(name + "_call");
yield return Booths(name);
}
if (Phone.I) Phone.I.Show(PhoneMode.Away);
yield return new WaitForSeconds(1.5f);
foreach (var line in new[] { "asst_twister", "asst_meteors" })
{
Assistant.Say(line);
yield return new WaitForSeconds(1.4f);
yield return Shot("c10_" + line);
yield return Booths("c10_" + line);
yield return new WaitForSeconds(0.9f);
yield return Booths("c11_" + line);
while (Assistant.Busy) yield return null;
yield return new WaitForSeconds(0.5f);
}
UIRoot.I.OpenSettings();
yield return new WaitForSeconds(0.6f);
yield return Shot("c20_settings");
UIRoot.I.CloseTopModal();
Log("calls done");
Application.Quit();
}
///
/// `-demostage19`: the opening film from black to space and back, the Director's call on the phone, the seam by the
/// base's pentagon, mown ground with no stubble, the low intakes against the deck, the hotbar after buying, the mower
/// back from the chase view, compact unload markers, a trailer swinging on a turn with dust and smoke, critters
/// running from a cut, a milestone call, and the new saucer arriving, beaming and leaving.
///
IEnumerator Stage19()
{
TeamState.DeleteSave();
yield return new WaitForSeconds(2f);
IntroCinematic.Force = true;
NetSession.Instance.HostLocal();
while (!Me || !Ts) yield return null;
// the very first frames of a new game must already be black
yield return Shot("00_first_frame");
Clock(10.5f);
float wait = Time.time;
while (!IntroCinematic.Running && Time.time - wait < 15f) yield return null;
Log($"intro started: {IntroCinematic.Running}");
float t0 = Time.time;
(float at, string name)[] marks =
{
(1.0f, "01_intro_black"), (4.6f, "02_intro_floor"), (7.4f, "03_intro_phone_up"), (13f, "04_intro_call"),
(24f, "05_intro_call_loud"), (41.1f, "06_intro_look"), (42.1f, "07_intro_up9"), (42.6f, "08_intro_up45"),
(43.1f, "09_intro_up220"), (43.6f, "10_intro_up950"), (46.5f, "11_intro_space"),
};
foreach (var (at, name) in marks)
{
while (Time.time - t0 < at && IntroCinematic.Running) yield return null;
if (!IntroCinematic.Running) break;
yield return Shot(name);
}
while (IntroCinematic.Running && Time.time - t0 < 70f) yield return null;
Log($"intro over after {Time.time - t0:0.0} s: cinematic lock {Ctl.Cinematic}, phone {(Phone.I ? Phone.I.Mode.ToString() : "-")}");
yield return new WaitForSeconds(1.2f);
yield return Shot("12_after_intro");
Log($"base shed gone: {VehicleShed.Base == null}");
Cheats.Run("money 5m");
Clock(11f);
var up0 = Vector3.up;
// the base intakes: low, against the deck
int intakes = BuildPiece.All.Count(p => p && p.piece == PieceId.Intake);
int tall = BuildPiece.All.Count(p => p && p.piece == PieceId.Depot && Planet.Altitude(p.transform.position) < 0.6f);
Log($"base intakes: {intakes}, tall depots left on the ground: {tall}");
var intake = BuildPiece.All.FirstOrDefault(p => p && p.piece == PieceId.Intake);
if (intake)
{
var ip = intake.transform.position;
var top = intake.GetComponentsInChildren().Select(r => Planet.Altitude(r.bounds.max)).DefaultIfEmpty(0f).Max();
Log($"intake top {top:0.00} m over the ground (deck 1.2), at {ip}");
foreach (var ik in BuildPiece.All.Where(p => p && p.piece == PieceId.Intake))
{
var f = ik.transform.forward;
var back = ik.transform.position - f * 0.75f;
Log($"intake at {ik.transform.position.x:0.0},{ik.transform.position.z:0.0} faces {f.x:0.00},{f.z:0.00}, back face {Mathf.Max(Mathf.Abs(back.x), Mathf.Abs(back.z)):0.00} m from the middle (deck edge 9)");
}
yield return Look("13_intake", ip + intake.transform.forward * 5f + intake.transform.right * 3f + up0 * 2.2f, ip + up0 * 0.5f);
}
// the seam by the pentagon and the mown ground: cut a ring round the deck
for (float a = 0f; a < 360f; a += 12f)
{
float r0 = 10.5f, r1 = 15f;
var d = new Vector3(Mathf.Sin(a * Mathf.Deg2Rad), 0f, Mathf.Cos(a * Mathf.Deg2Rad));
MowMap.Cut(Soil17(d.x * r0, d.z * r0), Soil17(d.x * r1, d.z * r1), 3.2f);
}
yield return new WaitForSeconds(1f);
yield return Look("14_seam_by_stilts", Soil17(-14f, -1f) + up0 * 1.7f, Soil17(-10.5f, -4f));
yield return Look("15_seam_south", Soil17(1f, -15f) + up0 * 1.7f, Soil17(0f, -11.5f));
yield return Look("16_mown_close", Soil17(-13f, 6f) + up0 * 1.2f, Soil17(-11f, 3f));
BotCapture.From = null;
// the hotbar after buying a tool, and the mower after the chase view
Ts.BuyToolRpc((byte)ToolId.LawnMower);
yield return new WaitForSeconds(1.5f);
Me.Tools.Equip(ToolId.LawnMower);
yield return new WaitForSeconds(1f);
yield return Shot("17_hotbar_bought");
var avatar = Me.GetComponentInChildren();
avatar.ShowBody(true);
yield return new WaitForSeconds(0.3f);
avatar.ShowBody(false);
yield return new WaitForSeconds(0.5f);
Me.Teleport(Soil17(16f, 16f) + up0 * 0.2f);
yield return new WaitForSeconds(1f);
yield return Shot("18_mower_after_chase");
// critters out of a cut, near the camera
var eye = Me.transform.position;
var fwd = Vector3.ProjectOnPlane(Me.transform.forward, Planet.Up(eye)).normalized;
for (int k = 0; k < 8; k++)
MowMap.Cut(eye + fwd * 2.5f + Me.transform.right * (k - 4) * 0.6f, eye + fwd * 6f + Me.transform.right * (k - 4) * 0.6f, 1.2f);
yield return new WaitForSeconds(0.25f);
Log($"critters out: {Critters.Alive} after {Critters.Families} families");
// and one sure family right in front, for the picture
for (int k = 0; k < 6 && Critters.Alive == 0; k++) Critters.Disturb(eye + fwd * 3f, 1f, 12f);
yield return new WaitForSeconds(0.15f);
Log($"critters out after a sure stir: {Critters.Alive}");
yield return Look("19_critters", eye + up0 * 0.9f, eye + fwd * 4f);
BotCapture.From = null;
// a milestone: the Director rings
Ts.Mown.Value = GameDefs.PlanetArea * 0.000011d;
yield return new WaitForSeconds(2.2f);
yield return Shot("20_call_ringing");
wait = Time.time;
while (Time.time - wait < 8f && !(Phone.I && Phone.I.Mode != PhoneMode.Away)) yield return null;
yield return new WaitForSeconds(3f);
Log($"milestone call: busy {DirectorCall.Busy}, phone {(Phone.I ? Phone.I.Mode.ToString() : "-")}");
yield return Shot("21_call_on_phone");
if (Phone.I) Phone.I.Show(PhoneMode.Up);
yield return new WaitForSeconds(1.2f);
yield return Shot("22_call_up_close");
if (Phone.I) Phone.I.Show(PhoneMode.Away);
yield return new WaitForSeconds(1f);
Log($"call hung up by putting the phone away: busy {DirectorCall.Busy}");
// the assistant at the side of the view, and both booths' own pictures
Assistant.Say("asst_storm");
yield return new WaitForSeconds(1.6f);
yield return Shot("22g_assistant");
yield return Booths("22h");
yield return new WaitForSeconds(1.3f);
yield return Shot("22i_assistant_later");
while (Assistant.Busy) yield return null;
Log("assistant said her line");
// a moved Director: tears, and then the shouting
DirectorCall.Call("dir_m50");
wait = Time.time;
while (Time.time - wait < 8f && !(Phone.I && Phone.I.Mode != PhoneMode.Away)) yield return null;
if (Phone.I) Phone.I.Show(PhoneMode.Up);
yield return new WaitForSeconds(2.6f);
yield return Shot("22b_call_sad");
yield return Booths("22b");
for (int k = 0; k < 6; k++)
{
yield return new WaitForSeconds(0.11f);
yield return Shot($"22f_flap_{k}");
}
yield return new WaitForSeconds(5.5f);
yield return Shot("22c_call_shouting");
if (Phone.I) Phone.I.Show(PhoneMode.Away);
yield return new WaitForSeconds(1f);
// the hauler: unload markers, and the trailer swinging on a turn
Ts.BuyVehicleRpc((byte)VehicleKind.Hauler, 0UL);
yield return new WaitForSeconds(4f);
var haul = Vehicle.Mine(VehicleKind.Hauler, Me.SaveId);
if (haul)
{
var spot = Soil17(40f, 40f);
haul.ServerPut(spot + Planet.Up(spot) * 0.05f, Quaternion.LookRotation(Vector3.forward, Planet.Up(spot)));
yield return new WaitForSeconds(0.6f);
Me.Teleport(haul.transform.position + haul.transform.right * 3f);
yield return new WaitForSeconds(0.5f);
haul.Interact();
yield return new WaitForSeconds(1.5f);
if (haul.IsOwner) haul.Tank.Value = haul.Capacity * 0.8f;
yield return new WaitForSeconds(0.6f);
yield return Shot("23_unload_markers");
Ctl.BotMove = new Vector2(0f, 1f);
yield return new WaitForSeconds(2.5f);
Ctl.BotMove = new Vector2(1f, 1f);
yield return new WaitForSeconds(2.2f);
var hitch = haul.hitch;
Log($"hauler hitch {(hitch ? "found" : "MISSING")}, trailer swing {(hitch ? Quaternion.Angle(hitch.localRotation, Quaternion.identity) : 0f):0.0} deg while turning");
yield return Shot("24_trailer_chase_turn");
var hp = haul.transform.position;
yield return Look("25_trailer_from_above", hp + Planet.Up(hp) * 14f - haul.transform.forward * 6f, hp - haul.transform.forward * 2f, 0.2f);
yield return Look("26_trailer_side", hp + haul.transform.right * 9f + Planet.Up(hp) * 2.5f, hp - haul.transform.forward * 2f, 0.2f);
Ctl.BotMove = Vector2.zero;
BotCapture.From = null;
yield return new WaitForSeconds(1f);
haul.RequestExit();
yield return new WaitForSeconds(1f);
}
// the saucer: in, beaming, out
Clock(20.5f);
Me.Teleport(Soil17(-40f, 40f) + up0 * 0.2f);
yield return new WaitForSeconds(1f);
var ufoAt = Me.transform.position + Me.transform.forward * 30f;
Ts.ServerUfo(ufoAt);
float u0 = Time.time;
var look = ufoAt + Planet.Up(ufoAt) * 12f;
var cam = Me.transform.position - Me.transform.forward * 12f + Planet.Up(Me.transform.position) * 3f;
(float at, string name)[] ufoShots = { (3.5f, "27_ufo_arriving"), (6.8f, "28_ufo_settling"), (12f, "29_ufo_beam"), (24f, "30_ufo_beam_late"), (30.4f, "31_ufo_leaving") };
foreach (var (at, name) in ufoShots)
{
while (Time.time - u0 < at) yield return null;
BotCapture.From = (cam, look);
yield return Shot(name);
}
BotCapture.From = null;
Log("stage 19 done");
Application.Quit();
}
///
/// `-demostage18`: the depots round the foot of the base, the meadow floor by the base, belts bending round corners and
/// out of and into ports with bundles riding the curves, a drone pad fetching loose bundles, walking into the base shed,
/// driving a machine up to it to tune it, the wide mulcher from behind with its driver, where each machine cuts, faces.
///
IEnumerator Stage18()
{
TeamState.DeleteSave();
yield return new WaitForSeconds(2f);
NetSession.Instance.HostLocal();
while (!Me || !Ts) yield return null;
yield return new WaitForSeconds(3f);
Cheats.Run("money 5m");
Clock(11f);
var up0 = Vector3.up;
// the base: eight depots on the ground round its foot
int footDepots = BuildPiece.All.Count(p => p && p.piece == PieceId.Depot && Planet.Altitude(p.transform.position) < 0.6f && new Vector2(p.transform.position.x, p.transform.position.z).magnitude < 20f);
Log($"base depots on the ground: {footDepots}");
yield return Look("40_base_intakes", new Vector3(-24f, 10f, 20f), new Vector3(0f, -1.5f, 0f), 1.2f);
yield return Look("41_intake_close", Soil17(15f, -10f) + up0 * 1.8f, Soil17(11f, -6f) + up0 * 0.8f);
yield return Look("41_intake_south", Soil17(9f, -16f) + up0 * 2.2f, Soil17(6f, -11f) + up0 * 0.6f);
// the meadow floor by the base, where a triangle of bare soil used to show through
foreach (var (n, x, z) in new[] { ("a", 0f, 15f), ("b", 15f, 2f), ("c", -15f, 4f), ("d", 5f, -14f), ("e", -12f, -12f) })
yield return Look($"42_floor_{n}", Soil17(x, z) + up0 * 1.7f, Soil17(x * 0.72f, z * 0.72f));
BotCapture.From = null;
// belts: out of an unload bay's hatch at an angle, round two corners, into a depot's side at an angle
var bAt = Soil17(40f, 10f);
var bay = Spawner.Instance.SpawnPiece(PieceId.UnloadBay, bAt, Quaternion.identity, bAt, true);
var dAt = Soil17(52f, -6f);
var depot = Spawner.Instance.SpawnPiece(PieceId.Depot, dAt, Quaternion.identity, dAt, true);
yield return new WaitForSeconds(1f);
var bp = new List();
bay.Ports(bp);
var dp = new List();
depot.Ports(dp);
Vector3 Lo(Vector3 v) => Planet.Surface(v) + Planet.Up(v) * GameDefs.BeltLowest;
var hatch = bp.First(p => !p.input);
var r0 = hatch.at;
var r1 = Lo(r0 + Quaternion.AngleAxis(55f, Vector3.up) * hatch.dir * 6f);
var d1 = (r1 - r0).normalized;
var r2 = Lo(r1 + Quaternion.AngleAxis(90f, Vector3.up) * d1 * 7f);
var into = dp.Where(p => p.input).OrderBy(p => (p.at - r2).sqrMagnitude).First();
var r3 = into.at;
void Run(Vector3 a, Vector3 b) => Spawner.Instance.SpawnPiece(PieceId.Belt, a, BuildRules.RunRotation(a, b), b, true);
Run(r0, r1);
Run(r1, r2);
Run(r2, r3);
// the other hatch: back a little, then a hard turn and a gentle one, ending free
var other = bp.Last(p => !p.input);
var s0 = other.at;
var s1 = Lo(s0 + other.dir * 4f);
var s2 = Lo(s1 + Quaternion.AngleAxis(-90f, Vector3.up) * other.dir * 5f);
var s3 = Lo(s2 + Quaternion.AngleAxis(-135f, Vector3.up) * other.dir * 6f);
Run(s0, s1);
Run(s1, s2);
Run(s2, s3);
yield return new WaitForSeconds(1.5f);
var silo = bay.GetComponent();
if (silo) silo.Silo.Value = 40f;
double paid = Ts.Money.Value;
yield return Look("43_belts_top", bAt + new Vector3(4f, 22f, -6f), bAt + new Vector3(4f, 0f, -6f), 1.5f);
yield return Look("44_port_bend", r0 + new Vector3(-3f, 2.6f, -2f), r0 + (r1 - r0) * 0.25f);
yield return Look("45_corner_close", r1 + new Vector3(2.5f, 2.4f, 2.5f), r1);
yield return Look("46_into_depot", r3 + new Vector3(-4f, 2.6f, 1.5f), r3);
yield return Look("47_tight_turns", s1 + new Vector3(-2f, 3.5f, -4f), (s1 + s2) * 0.5f);
yield return new WaitForSeconds(8f);
yield return Look("48_cargo_on_curves", r1 + new Vector3(3f, 3f, -3f), r1, 0.2f);
yield return Look("49_cargo_tight", s1 + new Vector3(-2.5f, 3f, -3f), (s1 + s2) * 0.5f, 0.2f);
yield return new WaitForSeconds(10f);
int riding = Conveyor.All.Sum(c => c ? c.Count : 0);
int fell = Cargo.All.Count(c => c && !c.Belt && (c.transform.position - bAt).magnitude < 30f && (c.transform.position - s3).magnitude > 2.5f);
Log($"belts: {riding} bundles riding, {fell} off a belt away from the free end, depot paid {Ts.Money.Value - paid:0.##}, bay silo {(silo ? silo.Silo.Value : -1f):0.#}");
BotCapture.From = null;
// a drone pad and loose bundles round it
var padAt = Soil17(-40f, 20f);
var pad = Spawner.Instance.SpawnPiece(PieceId.DronePad, padAt, Quaternion.identity, padAt, true);
yield return new WaitForSeconds(1f);
var pp = new List();
pad.Ports(pp);
var t0 = pp[0].at;
var t1 = Lo(t0 + pad.transform.forward * 7f);
Run(t0, t1);
for (int i = 0; i < 7; i++)
{
var a = Quaternion.AngleAxis(i * 51f, Vector3.up) * Vector3.forward * (9f + i * 3.5f);
Spawner.Instance.SpawnCargo(CargoKind.Grass, Planet.Surface(padAt + a) + Planet.Up(padAt + a) * 0.6f, Quaternion.identity, Vector3.zero);
}
yield return new WaitForSeconds(1.5f);
yield return Look("50_dronepad", padAt + new Vector3(5f, 3.5f, 6f), padAt + Vector3.up * 0.8f);
yield return new WaitForSeconds(4f);
yield return Look("51_drones_out", padAt + new Vector3(-6f, 10f, -12f), padAt + new Vector3(0f, 3f, 12f), 0.2f);
var dpad = pad.GetComponent();
for (int i = 0; i < 3; i++)
{
yield return new WaitForSeconds(4f);
var d = dpad ? dpad.GetComponentsInChildren().Where(t => t.name.StartsWith("SM_Drone")).OrderByDescending(t => Planet.Altitude(t.position)).FirstOrDefault() : null;
if (d) yield return Look($"52_drone_{i}", d.position + d.right * 4f + d.forward * -3f + Vector3.up * 1.5f, d.position + Vector3.down * 0.6f, 0.05f);
}
yield return new WaitForSeconds(30f);
int loose = Cargo.All.Count(c => c && !c.Belt && (c.transform.position - padAt).magnitude < DronePad.Range && (c.transform.position - padAt).magnitude > 3f);
Log($"drone pad: {dpad?.Prompt}, brought in {(dpad ? dpad.Delivered : -1)}, loose bundles left in reach {loose}, on its belt {Conveyor.All.Sum(c => c && (c.transform.position - padAt).magnitude < 10f ? c.Count : 0)}");
yield return Look("53_dronepad_after", padAt + new Vector3(5f, 4f, 9f), padAt + new Vector3(0f, 0.5f, 3f));
BotCapture.From = null;
// the base shed: walk in through an open bay, look round inside
var shed = VehicleShed.Base;
if (shed)
{
var st = shed.transform;
var openBay = st.TransformPoint(new Vector3(-shed.inside.x, 0f, shed.doorLine + 4f));
Me.Teleport(openBay + st.up * 0.2f);
yield return new WaitForSeconds(0.8f);
Me.LookAt(st.TransformPoint(new Vector3(-shed.inside.x, 1f, 0f)));
yield return new WaitForSeconds(0.4f);
yield return Shot("54_shed_open_bay");
Ctl.BotMove = new Vector2(0f, 1f);
yield return new WaitForSeconds(3.5f);
Ctl.BotMove = Vector2.zero;
var inShed = st.InverseTransformPoint(Me.transform.position);
Log($"walked into the shed: local {inShed}, inside {(inShed.z < shed.doorLine && Mathf.Abs(inShed.x) < shed.halfWide)}");
yield return Shot("55_shed_inside_fp");
yield return Look("56_shed_inside_door", st.TransformPoint(new Vector3(shed.inside.x - 1.5f, 2f, shed.backWall + 1f)), st.TransformPoint(new Vector3(shed.inside.x, 1.4f, shed.doorLine)));
yield return Look("57_shed_inside_wide", st.TransformPoint(new Vector3(-shed.inside.x, 2.2f, shed.backWall + 0.8f)), st.TransformPoint(new Vector3(shed.inside.x * 0.5f, 1f, shed.doorLine)));
BotCapture.From = null;
}
// the wide mulcher: out of the shed, driven, seen from behind with its driver
Ts.BuyVehicleRpc((byte)VehicleKind.Mulcher, 0UL);
if (shed)
{
// low and from the side: does it roll on the ground, folded narrower than the door?
var st = shed.transform;
yield return Look("57_mulcher_door", st.TransformPoint(new Vector3(shed.inside.x + 7f, 0.9f, shed.doorLine + 4f)), st.TransformPoint(new Vector3(shed.inside.x, 1.2f, shed.doorLine)), 2.4f);
yield return Look("57_mulcher_rolling", st.TransformPoint(new Vector3(shed.inside.x + 6f, 0.5f, shed.doorLine + 3f)), st.TransformPoint(new Vector3(shed.inside.x, 0.6f, shed.doorLine + 2f)), 1.2f);
var rolling = Vehicle.Mine(VehicleKind.Mulcher, Me.SaveId);
if (rolling)
{
rolling.Extent(out _, out _, out float under);
Log($"mulcher rolling out: {Planet.Altitude(rolling.transform.position):0.00} m over the ground, lowest point {under:0.00}");
}
BotCapture.From = null;
}
yield return new WaitForSeconds(6f);
var mul = Vehicle.Mine(VehicleKind.Mulcher, Me.SaveId);
if (mul)
{
Me.Teleport(mul.transform.position + mul.transform.right * 3f);
yield return new WaitForSeconds(0.5f);
mul.Interact();
yield return new WaitForSeconds(1.5f);
yield return Shot("58_mulcher_chase");
// drive it up to the shed's door: G opens the garage on it
if (shed)
{
var front = shed.Outside + shed.transform.forward * 3f;
mul.ServerPut(front, Quaternion.LookRotation(-shed.transform.forward, shed.transform.up));
yield return new WaitForSeconds(1f);
Log($"mulcher by the shed: near {(VehicleShed.Near(mul.transform.position) ? "yes" : "no")}");
Ctl.BotBootsPressed = true;
yield return null;
yield return null;
Ctl.BotBootsPressed = false;
yield return new WaitForSeconds(0.8f);
Log($"G by the shed opened the garage: {UIRoot.I.AnyModal}");
yield return Shot("59_garage_from_seat");
if (UIRoot.I.AnyModal) UIRoot.I.CloseTopModal();
}
}
// where each machine cuts: the trail starts under the cutter
foreach (var k in new[] { VehicleKind.Hauler, VehicleKind.Baler })
{
Ts.BuyVehicleRpc((byte)k, 0UL);
yield return new WaitForSeconds(9f);
}
float zx = 60f;
foreach (var v in Vehicle.All.Where(v => v).ToList())
{
if (Me.Vehicle) { Me.Vehicle.RequestExit(); yield return new WaitForSeconds(1f); }
var grass = Soil17(zx, 60f);
zx += 25f;
v.ServerPut(grass + Planet.Up(grass) * 0.05f, Quaternion.LookRotation(Vector3.forward, Planet.Up(grass)));
yield return new WaitForSeconds(0.6f);
Me.Teleport(v.transform.position + v.transform.right * 3f);
yield return new WaitForSeconds(0.5f);
v.Interact();
yield return new WaitForSeconds(1.2f);
Ctl.BotMove = new Vector2(0f, 0.6f);
yield return new WaitForSeconds(2.5f);
Ctl.BotMove = Vector2.zero;
yield return new WaitForSeconds(1.5f);
var t = v.transform;
var il = v.intake ? t.InverseTransformPoint(v.intake.position) : Vector3.zero;
v.Extent(out float back, out float top, out float bottom);
Log($"{v.Def.name}: intake local {il}, cut width {v.CutWidth:0.00} (bar {v.barWidth:0.00}), tail {back:0.00}, top {top:0.00}");
yield return Look($"60_cut_{v.Def.name.Replace(' ', '_')}", t.position + t.up * 9f - t.forward * 2f + t.right * 0.5f, t.position - t.forward * 1f, 0.3f);
yield return Look($"61_side_{v.Def.name.Replace(' ', '_')}", t.position + t.right * 6f + t.up * 2.2f - t.forward * 1f, t.position + t.up * 1f, 0.3f);
BotCapture.From = null;
}
if (Me.Vehicle) { Me.Vehicle.RequestExit(); yield return new WaitForSeconds(1f); }
// faces up close
Me.GetComponentInChildren().ShowBody();
ViewModel.Hidden = true;
for (int i = 0; i < 3; i++)
{
var face = Me.transform.position + Me.transform.forward * 1.1f + Me.transform.up * 1.15f;
BotCapture.From = (face, Me.transform.position + Me.transform.up * 1.0f);
yield return new WaitForSeconds(0.9f);
yield return Shot($"62_face_{i}");
}
BotCapture.From = null;
Application.Quit();
}
///
/// `-demostage17`: the base shed and machines driving out of it, the new machines, the chase camera, a built garage with
/// its door and outlet, the unload bay, belt corners and hoods, the piece screen, the lawn mower, the crew face up close,
/// the weather and its events, dusk, dawn and a meteor night.
///
IEnumerator Stage17()
{
TeamState.DeleteSave();
yield return new WaitForSeconds(2f);
NetSession.Instance.HostLocal();
while (!Me || !Ts) yield return null;
yield return new WaitForSeconds(3f);
Cheats.Run("money 5m");
Cheats.Run("tool all");
Clock(11f);
// the base shed: a machine waits inside, the door goes up, it drives out onto the yard
var shed = VehicleShed.Base;
Log($"base shed {(shed ? "found" : "MISSING")}, door {(shed && shed.door ? shed.door.name : "none")}, inside {(shed ? shed.Inside : Vector3.zero)}, out {(shed ? shed.Outside : Vector3.zero)}");
Me.Teleport(Soil17(-2f, -16f) + Vector3.up * 0.2f);
yield return new WaitForSeconds(1f);
if (shed)
{
var front = shed.Outside + shed.transform.forward * 5f + shed.transform.right * 7f + shed.transform.up * 3.5f;
yield return Look("01_shed", front, shed.transform.position + shed.transform.up * 1.2f);
Ts.BuyVehicleRpc((byte)VehicleKind.Hauler, 0UL);
yield return new WaitForSeconds(1.2f);
yield return Shot("02_shed_door_up");
yield return new WaitForSeconds(1.8f);
yield return Shot("03_rolling_out");
yield return new WaitForSeconds(3.5f);
yield return Shot("04_out_door_down");
Ts.BuyVehicleRpc((byte)VehicleKind.Mulcher, 0UL);
yield return new WaitForSeconds(2.6f);
yield return Shot("05_mulcher_rolling");
yield return new WaitForSeconds(4f);
Ts.BuyVehicleRpc((byte)VehicleKind.Baler, 0UL);
yield return new WaitForSeconds(7f);
yield return Look("06_three_machines", shed.Outside + shed.transform.forward * 10f + shed.transform.up * 5f, shed.Outside);
}
foreach (var k in new[] { VehicleKind.Hauler, VehicleKind.Mulcher, VehicleKind.Baler })
{
var m = Vehicle.Mine(k, Me.SaveId);
Log(m ? $"{k}: at {m.transform.position}, rolling {m.RollingOut}, kinematic {m.Body.isKinematic}" : $"{k}: NOT BOUGHT");
}
BotCapture.From = null;
// the chase camera behind the hauler
var hauler = Vehicle.Mine(VehicleKind.Hauler, Me.SaveId);
if (hauler)
{
Me.Teleport(hauler.transform.position + hauler.transform.right * 2.5f);
yield return new WaitForSeconds(0.5f);
hauler.Interact();
yield return new WaitForSeconds(1.5f);
Log($"driving the hauler: {Me.Vehicle == hauler}, chase view {Me.InChaseView}");
yield return Shot("07_chase_view");
Ctl.BotMove = new Vector2(0.3f, 1f);
yield return new WaitForSeconds(2.5f);
yield return Shot("08_chase_driving");
Ctl.BotMove = Vector2.zero;
yield return new WaitForSeconds(1.5f);
hauler.RequestExit();
yield return new WaitForSeconds(1f);
}
// built pieces: a garage with its door and outlet, an unload bay, belts turning corners and running into ports
var gAt = Soil17(26f, -30f);
var garage = Spawner.Instance.SpawnPiece(PieceId.Garage, gAt, Quaternion.identity, gAt, true);
var bAt = Soil17(40f, -26f);
var bay = Spawner.Instance.SpawnPiece(PieceId.UnloadBay, bAt, Quaternion.identity, bAt, true);
var lo = Vector3.up * GameDefs.BeltLowest;
var p0 = gAt + new Vector3(-0.8f, 0f, -2.8f) + lo;
var p1 = p0 + new Vector3(0f, 0f, -5f);
var p2 = p1 + new Vector3(-6f, 0f, 0f);
Spawner.Instance.SpawnPiece(PieceId.Belt, p0, Quaternion.LookRotation(p1 - p0), p1, true);
Spawner.Instance.SpawnPiece(PieceId.Belt, p1, Quaternion.LookRotation(p2 - p1), p2, true);
var q0 = bAt + new Vector3(0.8f, 0f, -3.7f) + lo;
var q1 = q0 + new Vector3(0f, 0f, -4f);
var q2 = q1 + new Vector3(4f, 0f, -2f);
var q3 = q2 + new Vector3(0f, 0f, -5f);
Spawner.Instance.SpawnPiece(PieceId.Belt, q0, Quaternion.LookRotation(q1 - q0), q1, true);
Spawner.Instance.SpawnPiece(PieceId.Belt, q1, Quaternion.LookRotation(q2 - q1), q2, true);
Spawner.Instance.SpawnPiece(PieceId.Belt, q2, Quaternion.LookRotation(q3 - q2), q3, true);
yield return new WaitForSeconds(2f);
Log($"garage {(garage ? "built" : "FAILED")}, shed {(garage && garage.GetComponent() ? "yes" : "no")}, bay {(bay ? "built" : "FAILED")}");
yield return Look("09_garage_front", gAt + new Vector3(7f, 3.5f, 12f), gAt + Vector3.up * 1.2f);
yield return Look("10_garage_back", gAt + new Vector3(-6f, 4f, -12f), gAt + new Vector3(-1f, 0.5f, -5f));
yield return Look("11_belt_corner_close", p1 + new Vector3(2.5f, 2.2f, -2.5f), p1);
yield return Look("12_bay_and_belts", bAt + new Vector3(-7f, 6f, -10f), bAt + new Vector3(1f, 0f, -6f));
yield return Look("13_bay_hatch_close", q0 + new Vector3(-2.5f, 1.8f, -2.5f), q0 + new Vector3(0f, 0.2f, 1f));
// a machine called to the new garage comes out of it
if (garage && hauler)
{
Ts.CallVehicleRpc(hauler.NetworkObjectId, garage.NetworkObjectId);
yield return Look("14_garage_door_up", gAt + new Vector3(9f, 3f, 13f), gAt + new Vector3(2.9f, 1f, 3f), 1.4f);
yield return new WaitForSeconds(1.6f);
yield return Shot("15_garage_rolling_out");
yield return new WaitForSeconds(3.5f);
yield return Shot("16_garage_out");
Log($"hauler called to the garage: at {hauler.transform.position}, garage pad {garage.GetComponent().PadSpot}");
}
BotCapture.From = null;
// the piece screen and upgrades
var belt = BuildPiece.All.FirstOrDefault(b => b && b.Run);
if (belt)
{
UIRoot.I.OpenPiece(belt);
yield return new WaitForSeconds(0.8f);
yield return Shot("17_piece_screen_belt");
belt.UpgradeRpc();
belt.SwitchRpc();
yield return new WaitForSeconds(0.8f);
yield return Shot("18_piece_screen_upgraded");
UIRoot.I.CloseTopModal();
Log($"belt after upgrade: tier {belt.Tier.Value}, switched {belt.Switched}, speed x{belt.TierMul}");
}
if (garage)
{
UIRoot.I.OpenPiece(garage);
yield return new WaitForSeconds(0.8f);
yield return Shot("19_piece_screen_garage");
UIRoot.I.CloseTopModal();
}
// the lawn mower, first person and as the others see it
var lawn = Soil17(30f, -8f);
Me.Teleport(lawn + Vector3.up * 0.2f);
yield return new WaitForSeconds(0.8f);
Me.Tools.Equip(ToolId.LawnMower);
Me.LookAt(lawn + new Vector3(0f, 0f, 8f));
yield return new WaitForSeconds(1f);
yield return Shot("20_mower_fp");
Ctl.BotUseHeld = true;
Ctl.BotMove = new Vector2(0f, 1f);
yield return new WaitForSeconds(2.5f);
yield return Shot("21_mower_fp_mowing");
Me.GetComponentInChildren().ShowBody();
ViewModel.Hidden = true;
var side = Me.transform.right * 2.2f + Me.transform.forward * 1.6f + Me.transform.up * 1.4f;
BotCapture.From = (Me.transform.position + side, Me.transform.position + Me.transform.forward * 0.6f + Me.transform.up * 0.5f);
yield return new WaitForSeconds(0.3f);
yield return Shot("22_mower_3p");
Ctl.BotMove = Vector2.zero;
Ctl.BotUseHeld = false;
Log($"mower: bin {Me.Tools.Bin(ToolId.LawnMower):0.00}, cutting {Me.Tools.IsCutting}");
// the face up close
for (int i = 0; i < 4; i++)
{
var face = Me.transform.position + Me.transform.forward * 1.1f + Me.transform.up * 1.15f;
BotCapture.From = (face, Me.transform.position + Me.transform.up * 1.0f);
yield return new WaitForSeconds(0.9f);
yield return Shot($"23_face_{i}");
}
BotCapture.From = null;
ViewModel.Hidden = false;
Me.GetComponentInChildren().ShowBody(false);
// weather: each kind eased in, then a wide look over the meadow
var view = Soil17(10f, -40f);
Me.Teleport(view + Vector3.up * 0.2f);
yield return new WaitForSeconds(0.5f);
Me.LookAt(view + new Vector3(30f, 4f, -30f));
foreach (var w in new[] { "clouds", "rain", "acidrain", "wind", "storm" })
{
Cheats.Run($"weather {w} 10");
yield return new WaitForSeconds(11f);
yield return Shot($"30_weather_{w}");
Log($"weather {w}: rain {WeatherFx.Rain:0.00} acid {WeatherFx.Acid:0.00} wind {WeatherFx.Wind:0.00} storm {WeatherFx.Storm:0.00} murk {WeatherFx.Murk:0.00} sun x{WeatherFx.SunMul:0.00}");
}
// a twister crossing in front of us
Cheats.Run("weather wind 10");
double cashBefore = Ts.Money.Value;
Ts.ServerTwister(Me.transform.position + Me.transform.forward * 22f);
for (int i = 0; i < 4; i++)
{
yield return new WaitForSeconds(3f);
yield return Shot($"31_twister_{i}");
}
var tw = Ts.TwisterPos(Ts.Now);
yield return Look("32_twister_path", tw + Planet.Up(tw) * 30f - Me.transform.forward * 10f, tw);
BotCapture.From = null;
Log($"twister: on {Ts.TwisterOn}, at {tw}, money change {Ts.Money.Value - cashBefore:0}");
// walk into it
Me.Teleport(Ts.TwisterPos(Ts.Now) + Vector3.up * 0.3f);
yield return new WaitForSeconds(0.6f);
Log($"in the twister: grounded {Me.Grounded}, height {Vector3.Dot(Me.transform.position - Planet.Surface(Me.transform.position), Planet.Up(Me.transform.position)):0.0} m");
yield return Shot("33_thrown");
yield return new WaitForSeconds(3f);
// the saucer
Cheats.Run("weather clear 10");
double cash = Ts.Money.Value;
var spot = Me.transform.position + Me.transform.forward * 30f;
Ts.ServerUfo(spot);
Me.LookAt(spot + Planet.Up(spot) * 8f);
foreach (float t in new[] { 4f, 6f, 6f, 8f, 8f, 6f })
{
yield return new WaitForSeconds(t);
yield return Shot($"34_ufo_{(int)(Ts.Now - Ts.UfoAt.Value)}s");
}
yield return Look("35_crop_circle", Ts.UfoSpot.Value + Planet.Up(Ts.UfoSpot.Value) * 45f + Vector3.forward * 8f, Ts.UfoSpot.Value);
BotCapture.From = null;
Log($"saucer: tip {Ts.Money.Value - cash:0}");
// dusk, dawn, then a meteor night
foreach (float h in new[] { 18.2f, 18.6f, 19f, 5f, 5.5f })
{
Clock(h);
Me.LookAt(view + new Vector3(-30f, 6f, 30f));
yield return new WaitForSeconds(1.2f);
yield return Shot($"36_sky_{h:00.0}h");
Me.LookAt(view + new Vector3(30f, 6f, -30f));
yield return new WaitForSeconds(0.5f);
yield return Shot($"36_sky_{h:00.0}h_other_way");
}
Clock(0f);
Cheats.Run("weather meteors 10");
Me.LookAt(Me.transform.position + Me.transform.forward * 10f + Planet.Up(Me.transform.position) * 14f);
yield return new WaitForSeconds(3f);
for (int i = 0; i < 3; i++) { yield return Shot($"37_meteors_{i}"); yield return new WaitForSeconds(0.4f); }
Log("done");
Application.Quit();
}
IEnumerator Hands()
{
const int Frames = 8;
TeamState.DeleteSave();
yield return new WaitForSeconds(2f);
NetSession.Instance.HostLocal();
while (!Me || !Ts) yield return null;
yield return new WaitForSeconds(2f);
Cheats.Run("tool all");
yield return new WaitForSeconds(0.8f);
var at = new Vector3(-16f, Soil + 0.1f, 14f);
Me.Teleport(at);
yield return new WaitForSeconds(0.6f);
var ground = Planet.Surface(at + new Vector3(-1.2f, 0f, 1.8f));
for (int i = 0; i <= (int)ToolId.Hammer; i++)
{
var tool = (ToolId)i;
Me.Tools.Equip(tool);
Me.LookAt(at + new Vector3(-6f, 1.4f, 9f));
yield return new WaitForSeconds(1f);
yield return Shot($"{i}_{tool}_rest");
Me.LookAt(ground);
yield return new WaitForSeconds(0.6f);
yield return Shot($"{i}_{tool}_rest_down");
float period = 1f / PlayerTools.StrokesPerSecond(tool);
if (tool == ToolId.Hammer) period = 0.5f;
else Ctl.BotUseHeld = true;
yield return new WaitForSeconds(0.5f);
Time.timeScale = 0.1f;
if (tool == ToolId.Hammer) Me.Tools.Struck();
for (int k = 0; k < Frames; k++)
{
yield return Shot($"{i}_{tool}_{k}");
yield return new WaitForSeconds(period / Frames);
}
// and as the others see it
Time.timeScale = 1f;
Me.GetComponentInChildren().ShowBody();
ViewModel.Hidden = true;
yield return new WaitForSeconds(0.4f);
var side = Me.transform.right * 1.5f + Me.transform.forward * 1.9f + Me.transform.up * 1.5f;
BotCapture.From = (Me.transform.position + side, Me.transform.position + Me.transform.up * 0.7f);
Time.timeScale = 0.1f;
for (int k = 0; k < 4; k++)
{
yield return Shot($"{i}_{tool}_out{k}");
yield return new WaitForSeconds(period / 4f);
}
Time.timeScale = 1f;
Ctl.BotUseHeld = false;
yield return new WaitForSeconds(0.6f);
yield return Shot($"{i}_{tool}_outrest");
BotCapture.From = null;
ViewModel.Hidden = false;
Me.GetComponentInChildren().ShowBody(false);
Log($"{tool}: bin {Me.Tools.Bin(tool):0.00}, cutting {Me.Tools.IsCutting}");
yield return new WaitForSeconds(0.6f);
}
Application.Quit();
}
/// `-democrew`: everyone on the roster from outside, standing, walking, mowing, on the phone and in the seat.
IEnumerator CrewFilm()
{
TeamState.DeleteSave();
yield return new WaitForSeconds(2f);
NetSession.Instance.HostLocal();
while (!Me || !Ts) yield return null;
yield return new WaitForSeconds(2f);
Cheats.Run("tool all");
Cheats.Run("money set 900000");
var at = new Vector3(-16f, Soil + 0.1f, 14f);
Me.Teleport(at);
yield return new WaitForSeconds(0.6f);
Ts.BuyVehicleRpc((byte)VehicleKind.Rider, 0UL);
yield return new WaitForSeconds(1f);
var rider = Vehicle.All.Find(v => v.kind == VehicleKind.Rider);
Me.GetComponentInChildren().ShowBody();
ViewModel.Hidden = true;
var ground = Planet.Surface(at + new Vector3(-1.2f, 0f, 1.8f));
for (int i = 0; i < Roster.All.Length; i++)
{
string who = i + "_" + Roster.All[i].name;
Me.Character.Value = (byte)i;
Me.Teleport(at);
Me.Tools.Equip(ToolId.Scythe);
Me.LookAt(at + new Vector3(-6f, 1.4f, 9f));
yield return new WaitForSeconds(0.5f);
Log($"{who}: wearing {Roster.Of(Me.Character.Value).model}");
yield return Around(who + "_a_front", 0f, 2.1f, 0.9f);
yield return Around(who + "_b_back", 180f, 2.1f, 1.1f);
Ctl.BotMove = Vector2.up;
yield return new WaitForSeconds(0.9f);
Time.timeScale = 0.1f;
// WaitForSeconds runs on game time, so this is a true tenth of a second of walking
for (int k = 0; k < 6; k++)
{
yield return Around(who + "_c_walk" + k, 75f, 2.4f, 0.8f);
yield return new WaitForSeconds(0.1f);
}
Time.timeScale = 1f;
Ctl.BotMove = Vector2.zero;
Me.Teleport(at);
Me.LookAt(ground);
Ctl.BotUseHeld = true;
yield return new WaitForSeconds(0.7f);
Time.timeScale = 0.1f;
float period = 1f / PlayerTools.StrokesPerSecond(ToolId.Scythe);
for (int k = 0; k < 4; k++)
{
yield return Around(who + "_d_mow" + k, 45f, 2.2f, 1f);
yield return new WaitForSeconds(period / 4f);
}
Time.timeScale = 1f;
Ctl.BotUseHeld = false;
Me.Tools.Equip(ToolId.Hammer);
Me.LookAt(at + new Vector3(-6f, 1.4f, 9f));
Phone.I.Show(PhoneMode.Side);
yield return new WaitForSeconds(0.8f);
yield return Around(who + "_e_phone", 20f, 1.9f, 1.1f);
Phone.I.Show(PhoneMode.Away);
yield return new WaitForSeconds(0.3f);
if (rider)
{
rider.Interact();
float t0 = Time.time;
while (!Me.Driving.Value && Time.time - t0 < 3f) yield return null;
yield return new WaitForSeconds(0.5f);
Log($"{who}: seated {Me.Driving.Value}");
yield return Around(who + "_f_seat", 55f, 2.8f, 1.1f);
rider.RequestExit();
while (Me.Driving.Value && Time.time - t0 < 6f) yield return null;
yield return new WaitForSeconds(0.3f);
}
}
BotCapture.From = null;
ViewModel.Hidden = false;
UIRoot.I.OpenCharacter();
yield return new WaitForSeconds(0.8f);
yield return Shot("z_picker");
Application.Quit();
}
IEnumerator Around(string name, float round, float far, float high)
{
var p = Me.transform;
BotCapture.From = (p.position + Quaternion.AngleAxis(round, p.up) * p.forward * far + p.up * high, p.position + p.up * 0.75f);
yield return Shot(name);
}
string _said;
IEnumerator Ask(PhoneWeb web, string js)
{
var t = web.Ask(js);
for (float w = 0f; w < 6f && !t.IsCompleted; w += Time.unscaledDeltaTime) yield return null;
_said = t.IsCompleted ? t.Result : "(no answer)";
}
IEnumerator Until(System.Func ok, float seconds)
{
for (float w = 0f; w < seconds && !ok(); w += Time.unscaledDeltaTime) yield return null;
}
/// `-demophone`: a page of our own with every trick on it, then real sites, then the browser killed under the phone.
IEnumerator PhoneTest()
{
TeamState.DeleteSave();
yield return new WaitForSeconds(2f);
NetSession.Instance.HostLocal();
while (!Me || !Ts) yield return null;
yield return new WaitForSeconds(2f);
var at = new Vector3(-16f, Soil + 0.1f, 14f);
Me.Teleport(at);
Me.LookAt(at + new Vector3(-6f, 1.4f, 9f));
yield return new WaitForSeconds(0.8f);
var phone = Phone.I;
Log($"engine on this PC: {PhoneWeb.Available}");
phone.Show(PhoneMode.Side);
yield return new WaitForSeconds(1f);
yield return Shot("1_side_home");
phone.Show(PhoneMode.Up);
yield return new WaitForSeconds(1f);
yield return Shot("2_up_home");
var scr = phone.Screen;
var web = scr.Web;
const string page = "data:text/html," +
"
tap here
" +
"" +
"" +
"" +
"";
scr.Open(page);
yield return Until(() => web.Url != null, 20f);
yield return new WaitForSeconds(1.5f);
Log($"page up: {web.Url != null}, {web.Stats}, viewport css {web.CssW}x{web.CssH}");
yield return Shot("3_up_page");
var tap = scr.PageAt(0.5f, 0.2f);
scr.Pointer(tap, true, true, false);
yield return null;
scr.Pointer(tap, false, false, true);
yield return new WaitForSeconds(0.4f);
yield return Ask(web, "a.dataset.x+','+a.dataset.y+' of '+innerWidth+'x'+innerHeight");
Log($"tap at 50%,20% of the page landed at {_said}");
var field = scr.PageAt(0.2f, 0.615f);
scr.Pointer(field, true, true, false);
yield return null;
scr.Pointer(field, false, false, true);
yield return new WaitForSeconds(0.6f);
bool typing = Ctl.Typing;
foreach (char c in "gras") scr.Char(c);
scr.Char('\b');
foreach (char c in "ss") scr.Char(c);
yield return new WaitForSeconds(0.3f);
yield return Ask(web, "i.value");
Log($"typing: took the keyboard {typing}, field says '{_said}'");
Phone.Back();
Log($"Esc: keyboard free {!Ctl.Typing}, phone still up {Phone.Focused}");
scr.Wheel(1);
yield return new WaitForSeconds(0.5f);
yield return Ask(web, "String(scrollY|0)");
Log($"one notch of the wheel: scrolled to {_said}");
yield return Ask(web, "String(v.paused)+' vol '+v.volume");
Log($"video before: paused {_said}");
phone.Show(PhoneMode.Away);
yield return new WaitForSeconds(1.4f);
yield return Ask(web, "String(v.paused)+', frame '+f.contentWindow.__gc.hold");
Log($"phone away: video paused, frame told to hold: {_said}");
phone.Show(PhoneMode.Side);
yield return new WaitForSeconds(1.4f);
yield return Ask(web, "String(v.paused)");
Log($"phone out again: video paused {_said}");
phone.Show(PhoneMode.Up);
scr.Turn();
yield return new WaitForSeconds(1.2f);
yield return Ask(web, "innerWidth+'x'+innerHeight+' '+screen.orientation.type");
Log($"on its side: {_said}");
yield return Shot("4_wide_up");
tap = scr.PageAt(0.25f, 0.25f);
scr.Pointer(tap, true, true, false);
yield return null;
scr.Pointer(tap, false, false, true);
yield return new WaitForSeconds(0.4f);
yield return Ask(web, "a.dataset.x+','+a.dataset.y");
Log($"on its side, tap at 25%,25% landed at {_said} (css {web.CssW}x{web.CssH})");
phone.Show(PhoneMode.Side);
yield return new WaitForSeconds(1f);
yield return Shot("5_wide_side");
scr.Turn();
scr.Open("https://m.youtube.com/");
yield return Until(() => web.Url != null && web.Url.Contains("youtube"), 25f);
yield return new WaitForSeconds(5f);
Log($"real site: {web.Url}, {web.Stats}");
yield return Shot("6_youtube_side");
phone.Show(PhoneMode.Up);
yield return new WaitForSeconds(1f);
yield return Shot("7_youtube_up");
web.Kill();
yield return Until(() => !web.Ready, 5f);
yield return Until(() => web.Ready && web.Url != null && web.Url.Contains("youtube"), 25f);
Log($"browser killed: back with {web.Url}, running {web.Running}");
// and as the others see it
phone.Show(PhoneMode.Side);
Me.GetComponentInChildren().ShowBody();
ViewModel.Hidden = true;
yield return new WaitForSeconds(0.8f);
var front = Me.transform.forward * 1.9f + Me.transform.right * -0.6f + Me.transform.up * 1.2f;
BotCapture.From = (Me.transform.position + front, Me.transform.position + Me.transform.up * 0.8f);
yield return Shot("8_outside_front");
var behind = Me.transform.forward * -1.7f + Me.transform.right * -0.9f + Me.transform.up * 1.7f;
BotCapture.From = (Me.transform.position + behind, Me.transform.position + Me.transform.up * 0.8f);
yield return Shot("9_outside_behind");
BotCapture.From = null;
ViewModel.Hidden = false;
Log($"others see the phone: {Me.PhoneOut.Value}");
phone.Unbind();
yield return new WaitForSeconds(0.5f);
Log($"match over: browser running {web.Running}");
Application.Quit();
}
/// Stand on a spot of the ball, walk, jump, and write down whether the ground held.
IEnumerator Stop(string name, float lat, float lon)
{
var dir = Planet.FromLatLon(lat, lon);
Me.Teleport(Planet.OnSurface(dir) + dir * 1.5f);
yield return new WaitForSeconds(1.2f);
var a = Me.transform.position;
var up = Planet.Up(a);
float lean = Vector3.Angle(Me.transform.up, up);
bool landed = Me.Grounded;
Me.LookAt(a + Vector3.ProjectOnPlane(Vector3.forward + Vector3.right * 0.3f, up).normalized * 40f + up * 1.2f);
yield return new WaitForSeconds(0.6f);
yield return Shot("22_" + name);
float low = 9f, high = -9f;
Ctl.BotMove = Vector2.up;
for (float t = 0f; t < 5f; t += Time.deltaTime)
{
float alt = Planet.Altitude(Me.transform.position);
low = Mathf.Min(low, alt); high = Mathf.Max(high, alt);
yield return null;
}
Ctl.BotMove = Vector2.zero;
float walked = (Me.transform.position - a).magnitude;
Ctl.BotJumpPressed = true;
yield return null;
Ctl.BotJumpPressed = false;
yield return new WaitForSeconds(0.25f);
float jump = Planet.Altitude(Me.transform.position);
yield return new WaitForSeconds(1.2f);
Log($"{name}: sector {HexGrid.SectorAt(Planet.Up(Me.transform.position)) + 1}, landed {landed}, lean {lean:0.0}°, walked {walked:0.0} m in 5 s at altitude {low:0.00}..{high:0.00}, jump {jump:0.00} m, back at {Planet.Altitude(Me.transform.position):0.00}, grounded {Me.Grounded}");
}
/// Round the planet: on foot in every region, a machine and a bundle on the far side, then from orbit.
IEnumerator PlanetTour()
{
Log(HexGrid.SelfTest());
Me.Tools.Select(ToolId.None);
// off the base and over the rim of the clearing, on foot
Me.Teleport(new Vector3(14f, Soil + 0.1f, -2f));
Me.LookAt(new Vector3(120f, Soil, 30f));
yield return new WaitForSeconds(0.5f);
Me.CheatSpeed = 8f;
float low = 9f, high = -9f;
Ctl.BotMove = Vector2.up;
for (float t = 0f; t < 25f; t += Time.deltaTime)
{
float alt = Planet.Altitude(Me.transform.position);
low = Mathf.Min(low, alt); high = Mathf.Max(high, alt);
yield return null;
}
Ctl.BotMove = Vector2.zero;
Me.CheatSpeed = 1f;
var ran = Me.transform.position;
Log($"ran out from the base: {(ran - Planet.Center).normalized.y:0.000} of the way up, {Mathf.Acos((ran - Planet.Center).normalized.y) * Planet.Radius:0} m from the pole, altitude {low:0.00}..{high:0.00}");
yield return Shot("22_past_the_clearing");
yield return Stop("north", 62f, 40f);
yield return Stop("equator", 0f, 120f);
yield return Stop("south", -48f, 250f);
yield return Stop("antipode", -89.6f, 10f);
yield return Fps("on foot at the far side");
// a bundle dropped here lands in the grass and stays
var pos = Me.transform.position;
var pup = Planet.Up(pos);
Spawner.Instance.SpawnCargo(CargoKind.Grass, pos + Me.transform.forward * 2f + pup * 3f, Quaternion.identity, Vector3.zero);
yield return new WaitForSeconds(3f);
var box = Cargo.All.Count > 0 ? Cargo.All[Cargo.All.Count - 1] : null;
if (box) Log($"bundle at the far side: altitude {Planet.Altitude(box.transform.position):0.00} m after 3 s, speed {box.Grab.Body.linearVelocity.magnitude:0.00}");
if (box) { Me.LookAt(box.transform.position); yield return new WaitForSeconds(0.3f); yield return Shot("23_far_bundle"); }
// bring the mower around and drive it here
var rider = Vehicle.All.Find(v => v.kind == VehicleKind.Rider);
if (rider)
{
var spot = Planet.OnSurface(Planet.FromLatLon(-30f, 200f));
var up = Planet.Up(spot);
rider.Body.position = spot + up * 1.2f;
rider.Body.rotation = Quaternion.LookRotation(Vector3.ProjectOnPlane(Vector3.right, up), up);
rider.transform.SetPositionAndRotation(rider.Body.position, rider.Body.rotation);
rider.Body.linearVelocity = Vector3.zero;
yield return new WaitForSeconds(1.5f);
rider.Interact();
yield return new WaitForSeconds(1f);
var from = rider.transform.position;
Ctl.BotMove = new Vector2(0.2f, 1f);
float lowV = 9f, highV = -9f;
for (float t = 0f; t < 10f; t += Time.deltaTime)
{
float alt = Planet.Altitude(rider.transform.position);
lowV = Mathf.Min(lowV, alt); highV = Mathf.Max(highV, alt);
yield return null;
}
yield return Shot("24_far_mower");
Ctl.BotMove = Vector2.zero;
Log($"mower at 30 S: drove {(rider.transform.position - from).magnitude:0.0} m in 10 s, ride height {lowV:0.00}..{highV:0.00}, tilt {Vector3.Angle(rider.transform.up, Planet.Up(rider.transform.position)):0.0}°");
rider.RequestExit();
yield return new WaitForSeconds(0.8f);
Log($"hopped off: grounded {Me.Grounded}, altitude {Planet.Altitude(Me.transform.position):0.00}");
}
yield return FarCut();
Me.Teleport(new Vector3(14f, Soil + 0.1f, 12f));
yield return new WaitForSeconds(0.8f);
yield return Mark(false, "30_stake");
yield return Mark(true, "31_survey_point");
// the whole ball
Me.SetFlying(true);
var high2 = Planet.FromLatLon(35f, 60f);
Me.Teleport(Planet.Center + high2 * (Planet.Radius + 2600f));
Me.LookAt(Planet.Center);
yield return new WaitForSeconds(2f);
yield return Shot("25_from_orbit");
Me.SetFlying(false);
}
///
/// `-demolan host` opens a LAN game; `-demolan join` must hear it on the network, join it and see two crew;
/// `-demolan solo`, started while the host holds port 7777, must still get a game of its own on another port.
///
IEnumerator LanTest(string role)
{
yield return new WaitForSeconds(2f);
var ns = NetSession.Instance;
if (role == "host")
{
TeamState.DeleteSave();
ns.Host(NetSession.LobbyKind.Lan);
while (!Me || !Ts) yield return null;
Log($"lan host: port {ns.LanPort}, announcing {LanBeacon.Hosting}, addresses {LanBeacon.MyAddresses()}");
float t0 = Time.time;
while (PlayerAgent.All.Count < 2 && Time.time - t0 < 60f) yield return null;
Log($"lan host: {PlayerAgent.All.Count} players after {Time.time - t0:0.0} s");
yield return new WaitForSeconds(20f);
Log($"lan host: {PlayerAgent.All.Count} players at the end");
yield break;
}
if (role == "solo")
{
yield return new WaitForSeconds(6f);
ns.Host(NetSession.LobbyKind.Solo);
float t1 = Time.time;
while ((!Me || !Ts) && Time.time - t1 < 20f) yield return null;
Log($"solo: started {Me != null}, kind {ns.Kind}, in lobby {ns.InLobby}, state {ns.Current}");
LanBeacon.Listen();
yield return new WaitForSeconds(3f);
Log($"solo: hears {LanBeacon.Found().Count} LAN game(s) while playing alone");
LanBeacon.StopListening();
yield break;
}
LanBeacon.Listen();
float t = Time.time;
List found;
while ((found = LanBeacon.Found()).Count == 0 && Time.time - t < 30f) yield return null;
Log($"lan join: heard {found.Count} game(s) after {Time.time - t:0.0} s" + (found.Count > 0 ? $": {found[0].name} at {found[0].ip}:{found[0].port}, {found[0].members}/{found[0].max}" : ""));
if (found.Count == 0) yield break;
LanBeacon.StopListening();
ns.JoinLocal(found[0].ip, found[0].port);
t = Time.time;
while ((!Me || PlayerAgent.All.Count < 2) && Time.time - t < 30f) yield return null;
Log($"lan join: in game {Me != null}, {PlayerAgent.All.Count} players, kind {ns.Kind}");
bool bad = NetSession.ParseAddress("192.168.1.300", out _, out _) || NetSession.ParseAddress("abc:7777", out _, out _);
bool good = NetSession.ParseAddress(" 10.0.0.5:7778 ", out var ip, out var port) && ip == "10.0.0.5" && port == 7778;
Log($"addresses: good {good}, bad rejected {!bad}");
}
///
/// `-demomp host` and `-demomp join` in two processes: do two crew members see each other standing on the far side,
/// and does a strip one of them cuts show up for the other?
///
static readonly Vector3 LateSpot = new Vector3(-16f, Soil, 9f);
IEnumerator TwoPlayers(bool host)
{
File.Delete(Path.Combine(folder, "results.txt"));
yield return new WaitForSeconds(2f);
if (host) { TeamState.DeleteSave(); NetSession.Instance.HostLocal(); }
else { yield return new WaitForSeconds(8f); NetSession.Instance.JoinLocal("127.0.0.1"); }
while (!Me || !Ts) yield return null;
float t0 = Time.time;
if (host)
{
// cut first: whoever joins later must find it already gone
Ts.BuyToolRpc((byte)ToolId.NailScissors);
Cheats.Run("tool all");
Cheats.Run("money 2000");
yield return new WaitForSeconds(0.3f);
Ts.BuyVehicleRpc((byte)VehicleKind.Rider, 0UL);
yield return new WaitForSeconds(1.5f);
Me.Tools.Equip(ToolId.WideScythe);
Me.Teleport(new Vector3(-14f, Soil + 0.1f, 8f));
yield return new WaitForSeconds(0.8f);
yield return Sweep(LateSpot, new Vector3(0f, 0f, 1.6f), 3f);
}
while (PlayerAgent.All.Count < 2 && Time.time - t0 < 40f) yield return null;
Log($"{(host ? "host" : "client")}: {PlayerAgent.All.Count} players");
if (PlayerAgent.All.Count < 2) { Application.Quit(); yield break; }
Me.Character.Value = (byte)(host ? 2 : 6);
yield return new WaitForSeconds(2f);
foreach (var p in PlayerAgent.All) Log($"{(host ? "host" : "client")} sees {(p.IsOwner ? "itself" : "the other")} as {Roster.Of(p.Character.Value).name}");
yield return new WaitForSeconds(3f);
var other = PlayerAgent.All.Find(p => p != Me);
Log($"cut before the client joined: grass left {MowMap.Yield(LateSpot):0.00}");
// side by side on the far side of the planet
var dir = Planet.FromLatLon(-52f, 140f);
var east = Vector3.Cross(dir, Vector3.up).normalized;
Me.Teleport(Planet.OnSurface((dir + east * ((host ? 0f : 5f) / Planet.Radius)).normalized) + dir * 0.2f);
yield return new WaitForSeconds(3f);
Me.LookAt(other.transform.position + Planet.Up(other.transform.position));
yield return new WaitForSeconds(1f);
var o = other.transform.position;
Log($"far side: me altitude {Planet.Altitude(Me.transform.position):0.00}, the other altitude {Planet.Altitude(o):0.00}, lean {Vector3.Angle(other.transform.up, Planet.Up(o)):0.0}°, apart {(o - Me.transform.position).magnitude:0.0} m");
yield return Shot(host ? "mp_host_sees" : "mp_client_sees");
if (!host)
{
Ctl.BotMove = Vector2.up;
yield return new WaitForSeconds(3f);
Ctl.BotMove = Vector2.zero;
}
else yield return new WaitForSeconds(5f);
yield return new WaitForSeconds(2f);
Log($"after the client's walk: the other altitude {Planet.Altitude(other.transform.position):0.00}, lean {Vector3.Angle(other.transform.up, Planet.Up(other.transform.position)):0.0}°, apart {(other.transform.position - Me.transform.position).magnitude:0.0} m");
// back at the base the client cuts, the host watches the grass go
var spot = new Vector3(14.6f, Soil, -2f);
Me.Teleport(new Vector3(host ? 16f : 13f, Soil + 0.1f, -2f));
yield return new WaitForSeconds(1.5f);
if (!host)
{
Ts.BuyToolRpc((byte)ToolId.NailScissors);
yield return new WaitForSeconds(1f);
yield return Sweep(spot, new Vector3(0f, 0f, 1.3f), 6f);
Log($"client cut {Me.Tank.Value:0.###} kg");
}
else yield return new WaitForSeconds(7.5f);
yield return new WaitForSeconds(1.5f);
Log($"grass left on the strip: {MowMap.Yield(spot):0.00}, tool of the other {(ToolId)other.ToolNet.Value}");
Me.LookAt(spot);
yield return new WaitForSeconds(0.5f);
yield return Shot(host ? "mp_host_strip" : "mp_client_strip");
// a sector the client finishes pays once, on the host, and closes for everyone
int far = HexGrid.SectorAt(Planet.FromLatLon(20f, 50f));
double cash = Ts.Money.Value;
if (!host) MowMap.CutSector(far);
yield return new WaitForSeconds(1.5f);
Log($"sector closed by the client: paid {Ts.Money.Value - cash:0.##}, {Ts.Closed.Value} closed, here {MowMap.Cleared(far) * 100f:0}%");
// the client takes the mower out: its strip must land on the host too
var rider = Vehicle.All.Find(v => v.kind == VehicleKind.Rider);
float mownBefore = MowMap.MownArea();
if (!host && rider)
{
rider.Interact();
yield return new WaitForSeconds(1f);
Ctl.BotMove = Vector2.up;
yield return new WaitForSeconds(6f);
Ctl.BotMove = Vector2.zero;
yield return new WaitForSeconds(0.5f);
Log($"client's mower: {rider.Tank.Value:0.##} kg in the hopper");
rider.RequestExit();
yield return new WaitForSeconds(1f);
}
else yield return new WaitForSeconds(8.5f);
yield return new WaitForSeconds(2f);
MowMap.Count();
Log($"after the mower: {MowMap.MownArea() - mownBefore:0.0} m² more, {MowMap.MownArea():0.0} m² mown here, {MowMap.Started} started");
// the client lays a belt, both see it with its ends
var beltUp = Planet.Up(Me.transform.position);
var fwd = Vector3.ProjectOnPlane(Vector3.up, beltUp).normalized;
var from = Planet.OnSurface(beltUp) + beltUp;
var to = Planet.OnSurface((beltUp * Planet.Radius + fwd * 9f).normalized) + beltUp;
if (host) Cheats.Run("money 200");
yield return new WaitForSeconds(1f);
if (!host)
{
Ts.BuyToolRpc((byte)ToolId.Hammer);
yield return new WaitForSeconds(1f);
if (!BuildRules.CanRun(from, to, out var why)) Log($"can't lay a belt: {why}");
Ts.BuildRpc((byte)PieceId.Belt, from, BuildRules.RunRotation(from, to), to);
}
else yield return new WaitForSeconds(1f);
yield return new WaitForSeconds(2f);
var laid = BuildPiece.All.Find(p => p.Run && p.Run.Metres > 8f);
Log($"client's belt: {BuildPiece.All.Count(p => p.Run)} belts here, {(laid ? laid.Run.Metres : 0f):0.0} m");
// a robot works on the host, its grass goes on the client too
var robotDir = Planet.FromBase(150f, 150f);
var robotAt = Planet.OnSurface(robotDir);
if (host)
{
Cheats.Run("money 1000");
yield return new WaitForSeconds(0.5f);
Mowbot.Haste = 20f;
Ts.BuildRpc((byte)PieceId.RobotI, robotAt, Quaternion.LookRotation(Vector3.ProjectOnPlane(Vector3.forward, robotDir), robotDir), Vector3.zero);
}
else yield return new WaitForSeconds(0.5f);
yield return new WaitForSeconds(9f);
Mowbot.Haste = 0f;
yield return new WaitForSeconds(5f);
var robot = Mowbot.All.FirstOrDefault();
MowMap.Count();
Log($"robot: {Mowbot.All.Count} here, {(robot ? Vector3.Distance(robot.At.Value, robotAt) : 0f):0} m from its dock, its sector {MowMap.Cleared(HexGrid.SectorAt(robotDir)) * 100f:0}% mown, {MowMap.MownArea():0.0} m² in all");
// the host shows the client the door: banned, and it stays with the save
if (host)
{
yield return new WaitForSeconds(2f);
string key = other.SaveId ?? "local";
ulong client = other.OwnerClientId;
Ts.ServerKick(client, true);
float gone = Time.time;
while (PlayerAgent.All.Count > 1 && Time.time - gone < 8f) yield return null;
Log($"after the ban: {PlayerAgent.All.Count} here after {Time.time - gone:0.0} s, banned {Ts.Banned(key)}");
}
else
{
float gone = Time.time;
while (NetSession.Instance.Current == NetSession.State.InGame && Time.time - gone < 8f) yield return null;
Log($"client after the ban: {NetSession.Instance.Current}");
}
yield return new WaitForSeconds(host ? 5f : 1f);
Application.Quit();
}
IEnumerator Start()
{
Directory.CreateDirectory(folder);
Sun.Pinned = 0.93f;
BuildRules.AnyGround = true; // the tests build where they stand, only Building() goes by the rule
if (CommandLine.Get("-demomp") is string role)
{
yield return TwoPlayers(role == "host");
yield break;
}
if (CommandLine.Get("-democrowd") is string crowd)
{
yield return Crowd(crowd == "host");
yield break;
}
if (CommandLine.Get("-demolan") is string lan)
{
yield return LanTest(lan);
Application.Quit();
yield break;
}
if (CommandLine.Get("-demoteam") is string team)
{
yield return Team(team == "host");
yield break;
}
if (CommandLine.Get("-demolang") is string langs)
{
yield return Languages(langs);
yield break;
}
if (CommandLine.Has("-demostage17"))
{
yield return Stage17();
yield break;
}
if (CommandLine.Has("-demostage18"))
{
yield return Stage18();
yield break;
}
if (CommandLine.Has("-demotreats"))
{
yield return TreatsDemo();
yield break;
}
if (CommandLine.Has("-demohouse"))
{
yield return House();
yield break;
}
if (CommandLine.Has("-demosize"))
{
yield return Sizes();
yield break;
}
if (CommandLine.Get("-demoperf") is string perfSlot)
{
yield return Perf(int.Parse(perfSlot));
yield break;
}
if (CommandLine.Has("-demobots"))
{
yield return Bots();
yield break;
}
if (CommandLine.Has("-demobelts"))
{
yield return Belts();
yield break;
}
if (CommandLine.Has("-democalls"))
{
yield return Calls();
yield break;
}
if (CommandLine.Has("-demostage19"))
{
yield return Stage19();
yield break;
}
if (CommandLine.Has("-demohands"))
{
yield return Hands();
yield break;
}
if (CommandLine.Get("-demolook") is string slot)
{
yield return LookAround(int.Parse(slot));
yield break;
}
if (CommandLine.Has("-democrew"))
{
yield return CrewFilm();
yield break;
}
if (CommandLine.Has("-demotrailer"))
{
yield return gameObject.AddComponent().Shoot(folder);
yield break;
}
if (CommandLine.Has("-demophone"))
{
yield return PhoneTest();
yield break;
}
if (CommandLine.Has("-demopace"))
{
yield return Pace();
yield break;
}
if (CommandLine.Has("-demoresume"))
{
// second run: does the save bring everything back?
yield return new WaitForSeconds(2f);
NetSession.Instance.HostLocal();
while (!Me || !Ts) yield return null;
yield return new WaitForSeconds(3f);
int pieces = BuildPiece.All.Count;
Log($"far strip after a restart: grass left {MowMap.Yield(Planet.OnSurface(FarSpot) + Vector3.Cross(Vector3.Cross(FarSpot, Vector3.up).normalized, FarSpot) * 1.8f):0.00}, sector at {MowMap.Cleared(HexGrid.SectorAt(FarSpot)) * 100f:0.0}%, {MowMap.Started} started, {MowMap.Finished} finished");
Me.Teleport(Planet.OnSurface(FarSpot) + FarSpot * 0.2f);
yield return new WaitForSeconds(1.5f);
Me.LookAt(Planet.OnSurface(FarSpot) + Vector3.Cross(Vector3.Cross(FarSpot, Vector3.up).normalized, FarSpot) * 1.8f);
yield return new WaitForSeconds(0.5f);
yield return Shot("29_far_strip_after_restart");
Log($"resumed: {Ts.Closed.Value} sectors closed, {Ts.FoundCount(false)} stakes, {Ts.FoundCount(true)} points, mown {Ts.Mown.Value:0} m²");
Log($"resumed: {BuildPiece.All.Count(p => p.Run)} belts, {BuildPiece.All.Where(p => p.Run).Sum(p => p.Run.Metres):0.0} m, {BuildPiece.All.Count(p => GameDefs.IsFoundation(p.piece))} foundations, {BuildPiece.All.Count(p => p.piece == PieceId.Merger)} mergers");
foreach (var m in Mowbot.All) Log($"resumed: {m.Prompt}");
Log($"resumed: {Depot.All.Count} depots, {Ts.Opened.Count} far stations found, compass and map see {Stations.Names[3]}: {Ts.StationOpen(3)}");
// a ruined save comes back from its backup, and the other slots know nothing of it
Ts.Save();
SaveSlots.Backup();
var good = SaveSlots.Info(0);
File.WriteAllText(SaveSlots.GamePath, "{ this is not a save");
var bad = SaveSlots.Info(0);
string back = SaveSlots.Read();
var fixedUp = SaveSlots.Info(0);
Log($"slots: {good.money:0.##} saved, ruined reads {bad.money:0.##}, repaired {back != null} to {fixedUp.money:0.##}, second slot used {SaveSlots.Info(1).used}");
foreach (var v in Vehicle.All) Log($"resumed: {v.Def.name}, {v.Tank.Value:0.##} kg, top speed {v.TopSpeed:0.##}, {Planet.Altitude(v.transform.position):0.0} m up");
foreach (var m in Machine.All) Log($"resumed: {m.Prompt}");
foreach (var p in PowerNode.All) Log($"resumed: {p.Prompt}");
Log($"resumed: money {Ts.Money.Value:0.##}, shipped {Ts.Shipped.Value:0.##}, installs {Ts.Installs}, owned mask {Me.Owned.Value}, slots {Me.BeltSlots.Value}, belt {string.Join(", ", Me.Tools.Belt)}, in hand {Me.Tools.Current} with {Me.Tools.Bin(Me.Tools.Current):0.##} kg, bundles {Bundles()}, pieces {pieces}, machines {Vehicle.All.Count}");
yield return Shot("21_resumed");
Application.Quit();
yield break;
}
File.Delete(Path.Combine(folder, "fps.txt"));
Achievements.Forget();
File.Delete(Path.Combine(folder, "results.txt"));
// every demo starts from a fresh base (the dev save is separate from players' saves)
TeamState.DeleteSave();
yield return new WaitForSeconds(3f);
yield return Shot("01_menu");
NetSession.Instance.HostLocal();
while (!Me || !Ts) yield return null;
yield return new WaitForSeconds(4f);
yield return Shot("02_first_day");
Log($"start: money {Ts.Money.Value}, owned mask {Me.Owned.Value}, belt slots {Me.BeltSlots.Value}, tool {Me.Tools.Current}");
// the supply wall: empty hands, take the nail scissors
Me.Teleport(new Vector3(-6.4f, 0.1f, -1.5f));
Me.LookAt(new Vector3(-8.5f, 1.2f, -1.5f));
yield return new WaitForSeconds(1f);
yield return Shot("03_supply_wall");
Log($"aim at wall: {Me.AimInteractable?.Prompt}");
Me.AimInteractable?.Interact();
yield return new WaitForSeconds(1f);
yield return Shot("04_supply_screen");
Ts.BuyToolRpc((byte)ToolId.NailScissors);
yield return new WaitForSeconds(0.8f);
yield return Shot("05_supply_taken");
UIRoot.I.CloseTopModal();
yield return new WaitForSeconds(0.4f);
Log($"took scissors: tool {Me.Tools.Current}, money {Ts.Money.Value}");
// down on the meadow: cut until the 0.5 kg container is full
Me.Teleport(new Vector3(13f, Soil + 0.1f, -2f));
yield return new WaitForSeconds(0.8f);
yield return Sweep(new Vector3(14.6f, Soil, -2f), new Vector3(0f, 0f, 1.3f), 12f, "06_cutting");
yield return new WaitForSeconds(0.2f);
float cut = Me.Tank.Value;
Log($"after 12 s of sweeping: {cut:0.###} kg of {Me.Tools.CurrentCap} kg");
yield return Shot("07_cut_strip");
Me.LookAt(new Vector3(14.4f, Soil, -2f));
yield return new WaitForSeconds(0.4f);
yield return Shot("07b_strip_from_above");
Log($"blade on the grass: {Me.Tools.BladeOn}, {Me.Tools.BladeAt}");
yield return Fps("standing in the meadow");
// Q ties what's there into a bundle
Ctl.BotPackHeld = true;
yield return new WaitForSeconds(0.1f);
Ctl.BotPackHeld = false;
yield return new WaitForSeconds(0.8f);
Log($"bundle tied: {Cargo.All.Count} loose, container {Me.Tank.Value:0.###} kg, bundle {(Cargo.All.Count > 0 ? Cargo.All[0].Kg.Value : 0f):0.###} kg");
yield return Shot("08_bundle");
// E at the depot: instant, paid at once
Cheats.Run("tank");
float kg = Me.Tank.Value;
double before = Ts.Money.Value;
var depot = Depot.All[0];
Me.Teleport(depot.transform.position + new Vector3(0f, 0.1f, -2.6f));
Me.LookAt(depot.Mouth);
yield return new WaitForSeconds(0.8f);
yield return Shot("09_depot");
Log($"aim at depot: {Me.AimInteractable?.Prompt}");
Me.AimInteractable?.Interact();
yield return new WaitForSeconds(0.3f);
yield return Shot("10_deposit");
Log($"deposit {kg:0.###} kg: paid {Ts.Money.Value - before:0.##}, shipped {Ts.Shipped.Value:0.###} kg");
// a bundle in your arms goes in with E
before = Ts.Money.Value;
var carried = Spawner.Instance.SpawnCargo(CargoKind.Grass, Me.transform.position + Me.transform.forward * 0.6f + Vector3.up * 1f, Quaternion.identity, Vector3.zero, 0.8f);
yield return new WaitForSeconds(0.2f);
Me.Grab.TryGrab(carried.Grab);
yield return new WaitForSeconds(0.5f);
Me.LookAt(depot.Mouth);
yield return new WaitForSeconds(0.2f);
bool carrying = Me.Grab.Holding;
string held = Me.AimInteractable?.Prompt;
Ctl.BotInteractPressed = true;
yield return null;
Ctl.BotInteractPressed = false;
yield return new WaitForSeconds(0.4f);
Log($"E with a bundle in hand: carrying {carrying}, aimed at '{held}', paid {Ts.Money.Value - before:0.##}, still holding {Me.Grab.Holding}");
yield return new WaitForSeconds(4.5f);
// a bundle dropped in pays on arrival
before = Ts.Money.Value;
Spawner.Instance.SpawnCargo(CargoKind.Grass, depot.Mouth + Vector3.up * 1.4f, Quaternion.identity, Vector3.zero);
yield return new WaitForSeconds(1.5f);
Log($"bundle dropped in: paid {Ts.Money.Value - before:0.##}, loose left {Cargo.All.Count}");
// the matrix
Cheats.Run("money 5000");
yield return new WaitForSeconds(0.6f);
UIRoot.I.OpenShop();
yield return new WaitForSeconds(1f);
yield return Shot("11_matrix");
Log($"matrix: {Ts.Installs} / {TeamState.TotalInstalls} installs");
before = Ts.Money.Value;
Ts.BuyPerkRpc((int)PerkId.BinScissors);
Ts.BuyPerkRpc((int)PerkId.WiderBlades);
yield return new WaitForSeconds(0.6f);
yield return Shot("12_matrix_bought");
UIRoot.I.CloseTopModal();
yield return new WaitForSeconds(0.4f);
Log($"bought 2 installs for {before - Ts.Money.Value:0.##}: scissors hold {Ts.ToolCap(ToolId.NailScissors)} kg, width {Ts.ToolWidth(ToolId.NailScissors):0.###} m");
// every tool in hand, out on the meadow
Ts.BuyBeltSlotRpc();
Cheats.Run("tool all");
yield return new WaitForSeconds(0.8f);
Log($"tools on belt: {string.Join(", ", Me.Tools.Belt)}, slots {Me.BeltSlots.Value}");
Me.Teleport(new Vector3(-14f, Soil + 0.1f, 8f));
yield return new WaitForSeconds(0.6f);
Me.LookAt(new Vector3(-16f, Soil, 9f));
for (int i = 0; i <= (int)ToolId.Hammer; i++)
{
Me.Tools.Equip((ToolId)i);
yield return new WaitForSeconds(0.7f);
yield return Shot("13_hold_" + (ToolId)i);
}
// the widest scythe across a long strip
Me.Tools.Equip(ToolId.WideScythe);
yield return new WaitForSeconds(0.3f);
Me.Teleport(new Vector3(16f, Soil + 0.1f, 8f));
yield return new WaitForSeconds(0.5f);
yield return Sweep(new Vector3(18f, Soil, 8f), new Vector3(0f, 0f, 2f), 6f, "14_scythe");
Log($"6 s with the two-handed scythe: {Me.Tank.Value:0.###} kg of {Me.Tools.CurrentCap} kg");
Me.SetFlying(true);
Me.Teleport(new Vector3(15.5f, Soil + 2f, 5f));
Me.LookAt(new Vector3(18f, Soil, 8f));
yield return new WaitForSeconds(0.6f);
yield return Shot("14b_scythe_strip");
Me.Teleport(new Vector3(15.5f, Soil + 4f, 2f));
Me.LookAt(new Vector3(15.5f, Soil, 5.5f));
yield return new WaitForSeconds(0.6f);
yield return Shot("15_strips_from_above");
yield return Fps("over the meadow, looking down");
Me.SetFlying(false);
Me.Teleport(new Vector3(14f, Soil + 0.1f, 12f));
yield return new WaitForSeconds(1f);
// the crew floats until the boots go on
float low2 = 0f;
yield return JumpPeak(v => low2 = v);
Cheats.Run("money 500");
yield return new WaitForSeconds(0.3f);
Ts.BuyGearRpc((byte)GearId.Boots);
yield return new WaitForSeconds(0.5f);
Me.BootsOn = true;
float high3 = 0f;
yield return JumpPeak(v => high3 = v);
Me.BootsOn = false;
Log($"jump: {low2:0.00} m on Herbaria, {high3:0.00} m in the boots, owned {Me.HasGear(GearId.Boots)}");
Me.SetFlying(true);
// a belt runs bundles into the depot
var ports = new List();
depot.GetComponent().Ports(ports);
var gate = ports.Find(p => Vector3.Dot(p.dir, Vector3.forward) > 0.9f && Mathf.Abs(p.at.x - depot.transform.position.x) < 0.1f);
var feed = gate.at - gate.dir * 5f;
before = Ts.Money.Value;
Ts.BuildRpc((byte)PieceId.Belt, feed, Quaternion.identity, gate.at);
yield return new WaitForSeconds(0.6f);
double paidFrom = Ts.Money.Value;
Log($"belt to the depot: {BuildPiece.All.Count(p => p.Run)} laid for {before - paidFrom:0.##}, {ports.Count} ports");
Spawner.Instance.SpawnCargo(CargoKind.Grass, feed + Vector3.up * 0.6f + gate.dir, Quaternion.identity, Vector3.zero);
Me.Teleport(feed + new Vector3(3f, 2f, -1f));
Me.LookAt(gate.at);
yield return new WaitForSeconds(0.9f);
yield return Shot("16_belt");
yield return new WaitForSeconds(5f);
Log($"bundle on a belt: paid {Ts.Money.Value - paidFrom:0.##}, loose left {Cargo.All.Count}");
yield return Building();
yield return Production();
yield return Network();
Me.SetFlying(true);
// the garage
Ts.ServerSetMoney(Ts.Money.Value + 20000d);
yield return new WaitForSeconds(0.3f);
double fleetFrom = Ts.Money.Value;
foreach (var kind in new[] { VehicleKind.Rider, VehicleKind.Push, VehicleKind.Pickup, VehicleKind.Tractor, VehicleKind.Combine })
{
Ts.BuyVehicleRpc((byte)kind, 0UL);
yield return new WaitForSeconds(0.2f);
}
yield return new WaitForSeconds(1f);
Log($"machines bought: {Vehicle.All.Count} for {fleetFrom - Ts.Money.Value:0.##}, a second rider refused: {Tries()}");
UIRoot.I.OpenGarage(null);
yield return new WaitForSeconds(1f);
yield return Shot("17_garage");
UIRoot.I.CloseTopModal();
Me.Teleport(new Vector3(9f, 4f, -24f));
Me.LookAt(new Vector3(0f, Soil, -15f));
yield return new WaitForSeconds(1f);
yield return Shot("18_pad");
Log($"fleet: {Vehicle.All.Count} machines");
// ride the mower out over the pad edge, cut a swath, back up and it unloads at the pad
Me.SetFlying(false);
var rider = Vehicle.All.Find(v => v.kind == VehicleKind.Rider);
if (rider)
{
rider.Interact();
yield return new WaitForSeconds(1f);
Ctl.BotMove = Vector2.up;
yield return new WaitForSeconds(5f);
yield return Shot("18b_mowing");
yield return new WaitForSeconds(1f);
Ctl.BotMove = Vector2.zero;
yield return new WaitForSeconds(0.5f);
float hopper = rider.Tank.Value;
Log($"rider: driving {Me.Driving.Value}, hopper {hopper:0.##} kg of {rider.Capacity} kg");
before = Ts.Money.Value;
Ctl.BotMove = Vector2.down;
float t0 = Time.time;
while (Time.time - t0 < 24f && rider.Tank.Value > 0.2f) yield return null;
Ctl.BotMove = Vector2.zero;
yield return new WaitForSeconds(0.5f);
Log($"rider unloaded at the pad: hopper {rider.Tank.Value:0.##} kg, paid {Ts.Money.Value - before:0.##}");
rider.RequestExit();
yield return new WaitForSeconds(0.8f);
}
yield return Fleet();
yield return Robots();
yield return Travel();
yield return Loaded();
yield return PlanetTour();
Me.SetFlying(true);
// the base from above
Me.Teleport(new Vector3(14f, 11f, -16f));
Me.LookAt(new Vector3(0f, 0f, 1f));
yield return new WaitForSeconds(1.2f);
yield return Shot("19_base");
UIRoot.I.OpenMap();
yield return new WaitForSeconds(0.8f);
yield return Shot("20_map");
UIRoot.I.CloseTopModal();
yield return new WaitForSeconds(0.3f);
Me.SetFlying(false);
var seen = Planet.OnSurface(FarSpot) + FarSpot * 0.2f;
Me.Teleport(seen);
yield return new WaitForSeconds(0.8f);
UIRoot.I.OpenMap(30f);
yield return new WaitForSeconds(0.8f);
yield return Shot("20b_map_close");
UIRoot.I.CloseTopModal();
yield return new WaitForSeconds(0.3f);
UIRoot.I.OpenNotebook();
yield return new WaitForSeconds(0.8f);
yield return Shot("20c_notebook");
UIRoot.I.CloseTopModal();
yield return new WaitForSeconds(0.3f);
Me.LookAt(Me.transform.position + Vector3.ProjectOnPlane(Vector3.up, FarSpot).normalized * 20f);
yield return new WaitForSeconds(0.4f);
yield return Shot("20d_compass");
Log($"compass: base {Compass.Distance(Mathf.Acos(FarSpot.y) * Planet.Radius)} away, bearing {Compass.Bearing(FarSpot, Me.transform.forward):0}°, sector {HexGrid.SectorAt(FarSpot) + 1}");
// the grass in the tools and on the ground has to survive too
Me.Tools.Equip(ToolId.Scythe);
yield return new WaitForSeconds(0.2f);
Cheats.Run("tank");
yield return Scenery();
Me.Tools.ReportNow();
yield return new WaitForSeconds(0.5f);
Log($"saved: {Ts.Closed.Value} sectors closed, {Ts.FoundCount(false)} stakes, {Ts.FoundCount(true)} points, mown {Ts.Mown.Value:0} m²");
Log($"saved: {BuildPiece.All.Count(p => p.Run)} belts, {BuildPiece.All.Where(p => p.Run).Sum(p => p.Run.Metres):0.0} m, {BuildPiece.All.Count(p => GameDefs.IsFoundation(p.piece))} foundations, {BuildPiece.All.Count(p => p.piece == PieceId.Merger)} mergers");
foreach (var m in Mowbot.All) Log($"saved: {m.Prompt}");
foreach (var v in Vehicle.All) Log($"saved: {v.Def.name}, {v.Tank.Value:0.##} kg, top speed {v.TopSpeed:0.##}, {Planet.Altitude(v.transform.position):0.0} m up");
foreach (var m in Machine.All) Log($"saved: {m.Prompt}");
foreach (var p in PowerNode.All) Log($"saved: {p.Prompt}");
Log($"saved: money {Ts.Money.Value:0.##}, installs {Ts.Installs}, owned mask {Me.Owned.Value}, slots {Me.BeltSlots.Value}, belt {string.Join(", ", Me.Tools.Belt)}, in hand {Me.Tools.Current} with {Me.Tools.Bin(ToolId.Scythe):0.##} kg, bundles {Bundles()}, pieces {BuildPiece.All.Count}, machines {Vehicle.All.Count}");
Ts.Save();
Application.Quit();
}
}
}