using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; namespace GrassCutter { /// /// `-demotrailer -stills`: the store page's screenshots, `x_`. Each is a short take of a few frames to pick from, of /// what the game has now: the crew in a row, the machines abreast, the factory with belts and an unload bay, the house /// on stilts with its drone pad by day and by lamplight, the vending machines on the deck, the player's own eyes with /// a boost on, acid rain, a twister, a night shift and the saucer. /// public partial class Trailer { /// Set while the music video films the same scenes as moving takes, `y_` instead of `x_`. bool _clip; string X(string name) => _clip ? "y" + name.Substring(1) : name; /// A still is a few frames to pick from; in the video it is three seconds with the lens easing in. IEnumerator Still(string name, System.Func lens, float lead = 0.6f, System.Action every = null, bool hud = false) { if (!_clip) return Take(name, 0.3f, 30, lens, lead, every, hud); System.Func push = t => { var l = lens(t); l.at = Vector3.Lerp(l.at, l.look, 0.07f * t); return l; }; return Take(X(name), 3.2f, 60, push, lead, every, hud); } /// `-demotrailer`: the new things on the planet as moving takes for the music video. IEnumerator NewThings() { _clip = true; Cheats.Run("ship 60"); BuildRules.AnyGround = true; yield return StillFactory(); yield return StillHouse(); yield return StillVending(); yield return StillHands(); yield return StillWeather(); yield return StillUfo(); _clip = false; } IEnumerator Stills() { Cheats.Run("ship 60"); BuildRules.AnyGround = true; yield return new WaitForSeconds(0.5f); yield return StillKey(); yield return StillCrew(); yield return StillMachines(); yield return StillFactory(); yield return StillHouse(); yield return StillVending(); yield return StillHands(); yield return StillNight(); yield return StillWeather(); yield return StillUfo(); } static Quaternion Facing(Vector3 at, Vector3 dir) => Quaternion.LookRotation(Vector3.ProjectOnPlane(dir, Planet.Up(at)), Planet.Up(at)); /// A belt from a piece's port straight out for so many metres; returns its far end. Vector3 LayBelt(BuildPiece piece, int port, float metres) { var ports = new List(); piece.Ports(ports); if (port >= ports.Count) return piece.transform.position; var p = ports[port]; var end = Planet.Surface(p.at + p.dir * metres); end += Planet.Up(end); Ts.BuildRpc((byte)PieceId.Belt, p.at, BuildRules.RunRotation(p.at, end), end); return end; } // ───────────────────────── by day ───────────────────────── /// /// `x_key`: the key art, from the game itself. The crew mows across the meadow in a staggered line, each trailing a /// cut stripe, under the ringed giant. The camera looks the giant's way, so it hangs over the field; `-shotsize` /// picks the frame (wide for the capsules and hero, upright for the library and vertical capsules), and the /// lens widens on an upright frame so the giant and the crew both fit. /// IEnumerator StillKey() { if (!Wanted("x_key")) yield break; Sky(0.55f, false); bool tall = H > W; // the spot and the lens can be tried from the command line without a new build float x = Arg("-keyx", -80f), z = Arg("-keyz", 300f); float dist = Arg("-keydist", tall ? 11f : 10f), aimUp = Arg("-keyaim", tall ? 10f : 9f), fov = Arg("-keyfov", tall ? 66f : 58f); float spread = Arg("-keyspread", tall ? 2.4f : 3.6f); // the giant hangs at (-0.55, 0.42, 0.72) in the sky above the base: look past it to the right, so it hangs // over the left of the field and leaves the right for the logo var giant = new Vector2(-0.55f, 0.72f).normalized; var look = Rotate(giant, -Arg("-keyturn", tall ? 4f : 12f)); var right = new Vector2(look.y, -look.x); var walk = (right * 0.55f - look * 0.85f).normalized; // toward us and a little across, faces showing var abreast = new Vector2(walk.y, -walk.x); // across the frame Vector3 At(Vector2 p, float h = 0f) => On(p.x, p.y, h); var mid = new Vector2(x, z); var who = new[] { 4, 1, 6, 2 }; var tools = new[] { ToolId.WideScythe, ToolId.LongScythe, ToolId.WideScythe, ToolId.Scythe }; for (int i = 0; i < who.Length; i++) { // a shallow V: the middle two lead, the outer two a step behind var start = mid + abreast * ((i - 1.5f) * spread) - walk * (Mathf.Abs(i - 1.5f) * 1.4f); MowMap.Cut(At(start - walk * 45f), At(start), 2.4f); var s0 = start; Actor(who[i], At(start), new Vector3(walk.x, 0f, walk.y), tools[i], true, s => At(s0 + walk * (s * 1.1f))); } var cam = mid - look * dist; var aim = mid + look * 30f; yield return Still("x_key", t => new Lens(At(cam, tall ? 2.6f : 2.8f), At(aim, aimUp), fov), 2f); Strike(); } static float Arg(string flag, float fallback) => float.TryParse(CommandLine.Get(flag), System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out float v) ? v : fallback; static Vector2 Rotate(Vector2 v, float degrees) { float r = degrees * Mathf.Deg2Rad, c = Mathf.Cos(r), s = Mathf.Sin(r); return new Vector2(v.x * c - v.y * s, v.x * s + v.y * c); } IEnumerator StillCrew() { if (!Wanted(X("x_crew"))) yield break; Sky(0.5f, false); float x = -30f, z = 230f; var tools = new[] { ToolId.WideScythe, ToolId.LongScythe, ToolId.LawnMower, ToolId.WideScythe, ToolId.Scythe, ToolId.LongScythe }; for (int i = 0; i < 6; i++) { float side = (i - 2.5f) * 3.2f, back = Mathf.Abs(i - 2.5f) * 1.1f; MowMap.Cut(On(x + side, z - back - 30f), On(x + side, z - back), 2.2f); Actor(new[] { 1, 4, 2, 6, 0, 7 }[i], On(x + side, z - back), Vector3.forward, tools[i], true, s => On(x + side, z - back + s * 1.7f)); } yield return Still("x_crew", t => new Lens(On(x + 4.5f, z + 8.5f, 1.1f), On(x - 2f, z + 2.6f, 1.05f), 46f), 1.6f); yield return Still("x_crew_back", t => new Lens(On(x - 5f, z - 16f, 5f), On(x + 1f, z + 6f, 0.5f), 55f), 0.4f); Strike(); } IEnumerator StillMachines() { if (!Wanted(X("x_machines"))) yield break; Sky(0.4f, false); float x = 240f, z = -120f; var row = new (VehicleKind kind, float dx, float dz, int who)[] { (VehicleKind.Combine, 0f, 0f, 5), (VehicleKind.Tractor, 13f, -7f, 3), (VehicleKind.Rider, -10f, -5f, 1), (VehicleKind.Rider, -17f, -10f, 6) }; Vehicle lead = null; foreach (var m in row) { float ax = x + m.dx, az = z + m.dz; MowMap.Cut(On(ax, az - 30f), On(ax, az), m.kind == VehicleKind.Combine ? 6f : 3f); yield return Machine(m.kind, On(ax, az), Vector3.forward, s => On(ax, az + 3.2f * s), m.who, v => { if (!lead) lead = v; }); } yield return new WaitForSeconds(1.5f); var c = lead.transform; yield return Still("x_machines", t => new Lens(c.position + c.forward * 15f - c.right * 9f + c.up * 1.8f, c.position - c.right * 5f + c.up * 1.4f, 54f), 0.4f); yield return Still("x_machines_air", t => new Lens(c.position - c.forward * 14f - c.right * 14f + c.up * 15f, c.position + c.forward * 3f - c.right * 4f, 56f), 0.2f); Strike(); } // ───────────────────────── building ───────────────────────── IEnumerator StillFactory() { if (!Wanted(X("x_factory")) && !Wanted(X("x_belts"))) yield break; Sky(0.38f, false); // the music video has already built a factory on this spot in Works() float x = _clip ? 160f : 60f, z = _clip ? -300f : 480f; for (int i = -24; i <= 24; i += 6) MowMap.Cut(On(x - 40f, z + i * 2f), On(x + 40f, z + i * 2f), 13f); var at = On(x, z); Ts.BuildRpc((byte)PieceId.UnloadBay, at, Facing(at, Vector3.forward), Vector3.zero); void Put(PieceId id, float dx, float dz) { var p = On(x + dx, z + dz); Ts.BuildRpc((byte)id, p, Facing(p, Vector3.forward), Vector3.zero); } Put(PieceId.Press, -16f, -22f); Put(PieceId.Dryer, 18f, -20f); Put(PieceId.Binder, 22f, 4f); Put(PieceId.SolarL, -22f, 6f); Put(PieceId.SolarL, -22f, 18f); Put(PieceId.BatteryL, -12f, 16f); Put(PieceId.Pole, 10f, 18f); Put(PieceId.Garage, 28f, 22f); yield return new WaitForSeconds(1f); var bay = BuildPiece.All.LastOrDefault(p => p && p.piece == PieceId.UnloadBay); if (!bay) { Log("stills: no unload bay"); yield break; } var ends = new List { LayBelt(bay, 0, 22f), LayBelt(bay, 1, 22f) }; yield return null; var silo = bay.GetComponent(); if (silo) silo.TakeRpc(120f); var b = bay.transform; var up = Planet.Up(b.position); var pad = silo ? silo.PadSpot : b.position + b.forward * 2f; var from = pad + b.forward * 16f; yield return Machine(VehicleKind.Rider, Planet.Surface(from), -b.forward, s => Vector3.Lerp(Planet.Surface(from), Planet.Surface(pad), Mathf.Clamp01(s / 3.5f)), 2, v => { }); yield return new WaitForSeconds(2.5f); Log($"stills: {BuildPiece.All.Count(p => p && p.piece == PieceId.Belt)} belts, bay silo {(silo ? silo.Silo.Value : -1f):0}"); yield return Still("x_factory", t => new Lens(b.position - b.forward * 11f + b.right * 9f + up * 6f, b.position - b.forward * 2f + up * 0.6f, 54f), 1.5f); yield return Still("x_belts", t => { var a = ends[0]; var w = (a - b.position).normalized; var p = b.position + w * 9f; return new Lens(p + Planet.Up(p) * 1.1f + Vector3.Cross(Planet.Up(p), w) * 1.6f + w * 4f, p - w * 2f + Planet.Up(p) * 0.4f, 52f); }, 0.2f); Strike(); } IEnumerator StillHouse() { if (!Wanted(X("x_house")) && !Wanted(X("x_drones"))) yield break; Sky(0.14f, true); var c = On(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); } 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); } 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); Put(PieceId.Steps, Planet.Surface(c - north * 2.7f), face); 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); 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); 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); if (b) Put(PieceId.Stairs, Foundation.Grid(b.transform, b.transform.position + east * 0.5f), b.transform.rotation); 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); } 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.Lamppost, Planet.Surface(c - north * 5f + east * 11f), 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); // the drone pad beside it, four drones, and bundles lying about for them to fetch var padAt = Planet.Surface(c + east * 14f); var pad = Spawner.Instance.SpawnPiece(PieceId.DronePad, padAt, face, padAt, true); yield return new WaitForSeconds(1.2f); if (pad) pad.Tier.Value = 2; Log($"stills house: {built} built, {refused} refused"); for (int i = 0; i < 10; i++) { float ang = -0.6f + i * 0.17f, r = 14f + (i % 3) * 6f; var p = Planet.Surface(padAt - north * Mathf.Cos(ang) * r + east * Mathf.Sin(ang) * r); Spawner.Instance.SpawnCargo(CargoKind.Grass, p + Planet.Up(p) * 0.5f, Quaternion.Euler(0f, i * 37f, 0f), Vector3.zero); } var mid = c + east * 1.5f + up * 2f; var one = Actor(4, c - north * 4.2f + east * 1.2f, north + east * 0.6f, ToolId.Hammer); var two = Actor(0, c - north * 6.4f - east * 0.6f, north - east * 0.3f, ToolId.Scythe); yield return new WaitForSeconds(2.2f); yield return Still("x_house", t => new Lens(mid - north * 15f + east * 8f + up * 2.6f, mid + east * 3f + up * 0.6f, 52f), 0.5f); yield return Take(X("x_drones"), 3f, _clip ? 60 : 10, t => new Lens(padAt - north * 11f + east * 7f + up * 1.4f, padAt - north * 4f + up * 3.2f, 58f), 0.2f); yield return Still("x_house_wide", t => new Lens(mid - north * 22f - east * 6f + up * 9f, mid + east * 5f, 52f), 0.2f); Sky(-0.3f, true); yield return new WaitForSeconds(1.5f); yield return Still("x_house_night", t => new Lens(mid - north * 15f + east * 8f + up * 2.6f, mid + east * 3f + up * 0.6f, 52f), 0.5f); Strike(); } // ───────────────────────── the deck ───────────────────────── IEnumerator StillVending() { if (!Wanted(X("x_vending"))) yield break; var beer = VendingMachine.All.FirstOrDefault(m => m && m.kind == TreatId.Beer && m.transform.position.magnitude > 0f && (m.transform.position - On(0f, 0f)).magnitude < 40f); var cigar = VendingMachine.All.FirstOrDefault(m => m && m.kind == TreatId.Cigar && beer && (m.transform.position - beer.transform.position).magnitude < 6f); if (!beer || !cigar) { Log($"stills: vending machines {VendingMachine.All.Count}"); yield break; } Sky(0.04f, true); var bt = beer.transform; var up = Planet.Up(bt.position); var mid = (bt.position + cigar.transform.position) * 0.5f; var buyer = Actor(3, bt.position + bt.forward * 1.15f + bt.right * 0.25f, -bt.forward, ToolId.Scythe); var ct = cigar.transform; var smoker = Actor(6, ct.position + ct.forward * 1.5f - ct.right * 0.9f, bt.forward + bt.right * 0.4f, ToolId.Hammer); // Actor stands them on the soil: they belong on the deck the machines stand on buyer.transform.position = bt.position + bt.forward * 1.15f + bt.right * 0.25f; smoker.transform.position = ct.position + ct.forward * 1.5f - ct.right * 0.9f; yield return new WaitForSeconds(0.5f); var hand = buyer.transform.position + up * 1.1f + bt.forward * -0.3f; beer.Play(false, hand); cigar.Play(false, ct.position + ct.forward * 1.1f + up * 1.1f); float puff = 0f; yield return Take(X("x_vending"), _clip ? 2.6f : 1.8f, _clip ? 60 : 10, t => new Lens(mid + bt.forward * 4.6f + bt.right * 1.6f + up * 1.25f, mid + up * 1.05f + bt.forward * 0.4f, 50f), 0.4f, k => { if (k < puff) return; puff = k + 0.18f; var mouth = smoker.transform.position + up * 1.62f + smoker.transform.forward * 0.18f; Fx.Exhale(mouth, smoker.transform.forward + up * 0.3f, 1f); if (k > 0.4f) Fx.SmokeRing(mouth, smoker.transform.forward + up * 0.2f); }); yield return new WaitForSeconds(1.5f); yield return Still("x_vending_wide", t => new Lens(mid + bt.forward * 7.5f - bt.right * 3f + up * 2.4f, mid + up * 1f, 54f), 0.2f); Strike(); } /// Through the player's eyes: a can from the machine and down it goes, a cigar from the other, then mowing with both boosts on. IEnumerator StillHands() { if (!Wanted(X("x_fp"))) yield break; Sky(0.3f, true); Me.Character.Value = 0; Eyes(true); yield return new WaitForSeconds(0.5f); foreach (var m in VendingMachine.All.Where(v => v && (v.transform.position - On(0f, 0f)).magnitude < 40f).OrderBy(v => v.kind).ToList()) { string name = m.kind == TreatId.Beer ? "x_fp_beer" : "x_fp_cigar"; if (!Wanted(X(name))) continue; Me.Tools.Equip(ToolId.Scythe); yield return new WaitForSeconds(0.4f); Me.Tools.CheatFill(); var mt = m.transform; var spot = mt.position + mt.forward * 1.5f; Me.Teleport(spot + Planet.Up(spot) * 0.2f); yield return null; Me.LookAt(mt.position + Planet.Up(mt.position) * 1.25f); yield return new WaitForSeconds(0.5f); bool bought = false; yield return Take(X(name), 6.2f, _clip ? 60 : 20, null, 0.1f, k => { if (!bought) { bought = true; m.Interact(); } if (k < 0.3f) Me.LookAt(mt.position + Planet.Up(mt.position) * 1.25f); }, true); yield return new WaitForSeconds(0.5f); } Treats.Begin(TreatId.Beer); Treats.Begin(TreatId.Cigar); Sky(0.45f, false); yield return Mow(X("x_fp_mow"), ToolId.WideScythe, 44f, 8f, 1.5f, 1.4f, 0.5f, 2.8f, 4860); Eyes(false); Treats.Clear(); } // ───────────────────────── weather and night ───────────────────────── IEnumerator StillWeather() { if (Wanted(X("x_acid"))) { Sky(0.4f, false); Ts.ServerSetWeather(WeatherKind.AcidRain, 60f); float x = -200f, z = 120f; for (int i = 0; i < 4; i++) { float side = (i - 1.5f) * 3.4f, back = Mathf.Abs(i - 1.5f) * 1.2f; MowMap.Cut(On(x + side, z - back - 20f), On(x + side, z - back), 2.2f); Actor(new[] { 2, 5, 7, 1 }[i], On(x + side, z - back), Vector3.forward, ToolId.LongScythe, true, s => On(x + side, z - back + s * 1.5f)); } yield return new WaitForSeconds(3f); yield return Still("x_acid", t => new Lens(On(x + 6f, z + 11f, 1.2f), On(x - 1f, z + 1f, 1.3f), 50f), 1.2f); Strike(); } if (Wanted(X("x_twister"))) { Ts.ServerSetWeather(WeatherKind.Storm, 40f); Sky(0.3f, false); var cam = On(60f, 26f, 1.4f); var from = On(70f, 92f); for (int i = 0; i < 3; i++) { float sx = 56f + i * 3.5f, sz = 40f + i * 1.5f; Actor(new[] { 0, 3, 6 }[i], On(sx, sz), Vector3.back, ToolId.Scythe, false, s => On(sx - s * 0.6f, sz - s * 2.6f)); } Ts.ServerTwister(from); Ts.TwisterFrom.Value = from; Ts.TwisterDir.Value = Vector3.ProjectOnPlane(cam - from, Planet.Up(from)).normalized; yield return Take(X("x_twister"), _clip ? 4f : 1.5f, _clip ? 60 : 10, t => new Lens(cam, Vector3.Lerp(Ts.TwisterPos(Ts.Now), On(60f, 44f, 1f), 0.45f) + Planet.Up(cam) * 5f, 60f), 3.5f); Ts.TwisterAt.Value = 0d; Strike(); } Ts.ServerSetWeather(WeatherKind.Clear, 600f); yield return new WaitForSeconds(1f); } IEnumerator StillNight() { if (!Wanted(X("x_night"))) yield break; Ts.ServerSetWeather(WeatherKind.Clear, 600f); Sky(-0.3f, true); float x = -420f, z = 90f; for (int i = 0; i < 12; i++) { float side = (i - 5.5f) * 3.4f, back = Mathf.Abs(i - 5.5f) * 1f; MowMap.Cut(On(x + side, z - back - 25f), On(x + side, z - back), 2.2f); Actor(i % 8, On(x + side, z - back), Vector3.forward, ToolId.WideScythe, true, s => On(x + side, z - back + s * 1.7f), i); } Vehicle r = null; yield return Machine(VehicleKind.Tractor, On(x + 30f, z - 8f), Vector3.forward, s => On(x + 30f, z - 8f + s * 4f), 0, v => r = v); float go = Time.time; float Near() => z + (Time.time - go) * 1.7f; WorkLight(() => On(x, Near() + 8f, 10f), () => On(x, Near() - 2f, 0.5f)); yield return Still("x_night", t => new Lens(On(x + 3.5f, Near() + 7.5f, 1.2f), On(x - 1.5f, Near() + 0.8f, 0.95f), 52f), 1.2f); DayNight.Rig = null; DayNight.SetView(DayNight.Off); Strike(); } IEnumerator StillUfo() { if (!Wanted(X("x_ufo"))) yield break; Sky(0.12f, true); var spot = On(-60f, 70f); for (int i = 0; i < 3; i++) Actor(new[] { 4, 1, 7 }[i], On(-61f + i * 2.4f, 47f + (i % 2) * 1.2f), spot - On(-61f + i * 2.4f, 47f), i == 1 ? ToolId.Hammer : ToolId.Scythe); Ts.ServerUfo(spot); yield return new WaitForSeconds(TeamState.UfoArrive + 4f); yield return Still("x_ufo", t => new Lens(On(-57f, 40f, 1.0f), On(-60f, 70f, 9f), 56f), 0.2f); yield return Still("x_ufo_top", t => new Lens(On(-44f, 54f, 18f), On(-60f, 70f, 2f), 54f), 0.2f); Ts.UfoAt.Value = 0d; Strike(); } } }