Files
grass-cutters/Assets/Scripts/Core/DemoBot.Ending.cs
Bonchellon d4dff6ea99 Ending: rail camera, stable far planet, green bursts from a US landing
Flights run on rails at even speed along the spline with eased ends and
smooth zoom pushes, no hand-held shake. Grass fur, sector lines and
shadows fade out as the camera climbs, and above 250 m the ground swaps
to an even cube-sphere skin so the relief no longer pops while orbiting.
Per-shot FOV, motion blur, slamming titles and a warp to Earth; the
rocket now lands in Kansas and the green bursts straight out of it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 16:38:46 +03:00

127 lines
6.6 KiB
C#

using System.Collections;
using System.Linq;
using UnityEngine;
namespace GrassCutter
{
public partial class DemoBot
{
/// <summary>
/// -ending: a new world mown bald sector by sector until the planet goes past the line, and the ending that follows by
/// itself: the call, the climb, the planet, the results, the credits, THE END and the card; then back into the game,
/// and the film again from the cheat, skipped.
/// </summary>
IEnumerator EndingDemo()
{
TeamState.DeleteSave();
yield return new WaitForSeconds(2f);
NetSession.Instance.HostLocal();
while (!Me || !Ts) yield return null;
Clock(9.5f);
yield return new WaitForSeconds(9f);
Ts.ServerDeposit(48000f, CargoKind.Grass, Me.transform.position);
yield return Shot("end_00_before");
// every sector down, a slice a frame
float t0 = Time.realtimeSinceStartup;
for (int id = 0; id < HexGrid.Cells; id++)
{
MowMap.Close(id);
if (id % 4000 == 0) yield return null;
}
Log($"closed {HexGrid.Cells} sectors in {Time.realtimeSinceStartup - t0:0.0} s");
{
float fsum = 0f; double total = 0d; int empty = 0, done = 0;
foreach (var m in MowMap.All) { fsum += m.mown; total += m.total; if (m.total <= 0f) empty++; if (m.done) done++; }
Log($"mown {MowMap.MownArea():0} m² (float sum {fsum:0}), grass {total:0} m², planet {GameDefs.PlanetArea:0} m², sector {GameDefs.SectorArea:0.0} m², masks {MowMap.All.Count()} done {done} empty {empty}, finished {MowMap.Finished}");
}
float wait = Time.time;
while (!EndingCinematic.Running && Time.time - wait < 60f) yield return null;
Log($"ending started by itself: {EndingCinematic.Running}, planet {Ts.Mown01 * 100d:0.00000}%, seen before {EndingCinematic.Seen}");
if (!EndingCinematic.Running) { EndingCinematic.Force = true; while (!EndingCinematic.Running) yield return null; }
float s = Time.time;
yield return Until(s, 9f, "Call"); yield return Shot("end_01_call");
// the flights: skim, arc round the base, (a machine), the rise; times from the start of each stage
yield return AtStage("Climb", 2.0f, "end_02_skim");
yield return AtStage("Climb", 4.4f, "end_02b_skim_late");
yield return AtStage("Climb", 6.5f, "end_03_arc");
yield return AtStage("Climb", 10.2f, "end_03b_arc_late");
yield return AtStage("Space", 1.5f, "end_04a_rise_low");
yield return AtStage("Space", 3.5f, "end_04a2_rise_fade");
yield return AtStage("Space", 5.5f, "end_04b_rise_mid");
yield return AtStage("Space", 8.5f, "end_04c_rise_high");
yield return AtStage("Space", 10.8f, "end_04d_rise_top");
yield return AtStage("Space", 14.0f, "end_05_title");
yield return AtStage("Space", 21.5f, "end_06_line");
yield return StageShot("Results", 5.5f, "end_07_results");
yield return AtStage("Earth", 0.5f, "end_08a_warp");
yield return AtStage("Earth", 5.0f, "end_08b_earth_title");
yield return AtStage("Earth", 8.7f, "end_08c_rocket_pass");
yield return AtStage("Earth", 9.7f, "end_08c2_rocket_away");
yield return AtStage("Earth", 12.5f, "end_08d_rocket_down");
yield return AtStage("Earth", 15.6f, "end_08e_landing");
yield return AtStage("Earth", 20f, "end_08f_greening");
yield return AtStage("Earth", 26f, "end_08g_line");
yield return AtStage("Earth", 33.5f, "end_08h_green");
yield return StageShot("Credits", 12f, "end_09_credits");
while (EndingCinematic.Stage != "End" && EndingCinematic.Running) yield return null;
yield return new WaitForSeconds(2.2f);
yield return Shot("end_10_theend");
yield return new WaitForSeconds(4.5f);
yield return Shot("end_10_card");
Log($"at the card: seen {EndingCinematic.Seen}, cinematic {Ctl.Cinematic}, modal {UIRoot.I.AnyModal}, {Time.time - s:0} s in");
UIRoot.I.CloseTopModal();
yield return new WaitForSeconds(1.5f);
Log($"keep mowing: running {EndingCinematic.Running}, cinematic {Ctl.Cinematic}, camera local {CameraFx.Cam.transform.localPosition}");
yield return Shot("end_11_back");
// again from the cheat, skipped a few seconds in
Cheats.Run("ending");
while (!EndingCinematic.Running) yield return null;
yield return new WaitForSeconds(4f);
EndingCinematic.SkipNow();
yield return new WaitForSeconds(7.5f);
yield return Shot("end_12_skipped");
Log($"skipped: stage {EndingCinematic.Stage}, modal {UIRoot.I.AnyModal}");
UIRoot.I.CloseTopModal();
yield return new WaitForSeconds(1f);
Log($"ending done: running {EndingCinematic.Running}, cinematic {Ctl.Cinematic}");
Application.Quit();
}
static IEnumerator Until(float since, float maxWait, string stage)
{
while (EndingCinematic.Stage != stage && Time.time - since < maxWait + 60f && EndingCinematic.Running) yield return null;
}
string _endStage;
float _endStageAt;
/// <summary>A picture this long after the film reached a stage (skipped when the film has moved past the stage).</summary>
IEnumerator AtStage(string stage, float at, string name)
{
while (EndingCinematic.Running)
{
var now = EndingCinematic.Stage;
if (now != _endStage) { _endStage = now; _endStageAt = Time.time; }
if (now == stage && Time.time - _endStageAt >= at) break;
if (now != stage && _seenStages.Contains(stage)) yield break;
if (now == stage) _seenStages.Add(stage);
yield return null;
}
if (!EndingCinematic.Running) yield break;
yield return Shot(name);
}
readonly System.Collections.Generic.HashSet<string> _seenStages = new System.Collections.Generic.HashSet<string>();
IEnumerator StageShot(string stage, float after, string name)
{
while (EndingCinematic.Stage != stage && EndingCinematic.Running) yield return null;
yield return new WaitForSeconds(after);
yield return Shot(name);
}
}
}