Files
grass-cutters/Assets/Scripts/Core/Achievements.cs
Bonchellon 3ee5956694 Ending: the Director's call, flyovers into orbit, Earth turning green, credits
When the planet is mown the ending plays by itself: G.R.A.S.S.A. calls, the
camera skims the stubble into the base, circles it and rises without a cut
into orbit over the bald planet (title, the crew's results). Then a jump
across space to a scorched, dried-out Earth: a rocket from Herbaria-7 passes
the lens and lands in Africa, and the green spreads from there over the whole
globe (seed pods, a glowing front, clouds and blue air coming back). The
credits roll over the green Earth (PlayWay credited as publisher), then THE
END and a card to keep mowing, leave a review or go to the menu. Space, Enter
or Esc skips to the green Earth and the card.

- EndingCinematic, EndingEarth (globe, air shell, rocket, seeds), SpaceSky
  (split out of the intro), EarthGlobe/EarthAir shaders and Earth maps in
  Resources/Ending
- the far meadow shows as stubble once the planet is mown
- "all of it" mown now means no sector with grass left (MowMap.Left); mown
  area summed in double
- the crew's total pay and play time are counted and saved for the results
- the "ending" cheat; -ending previews it in a test world; the -ending bot
  shoots every stage
- loc for the new lines in all 11 languages

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-28 01:52:24 +03:00

120 lines
5.9 KiB
C#

using System;
using System.Collections.Generic;
using Steamworks;
using UnityEngine;
namespace GrassCutter
{
public class Award
{
/// <summary>English patterns; <c>{0}</c> in them is <see cref="value"/> (as money when <see cref="money"/>).</summary>
public string id, nameEn, descEn;
public double value;
public bool money;
public Func<TeamState, PlayerAgent, bool> done;
object Arg => money ? UIK.Money(value) : (object)value;
public string name => Loc.F(nameEn, Arg);
public string desc => Loc.F(descEn, Arg);
}
/// <summary>
/// The 33 awards: grass shipped, money, sectors, the planet, what was found and what was built. Each player earns them on
/// their own computer, and on Steam as well once the game has an AppID of its own: on the test AppID the calls go nowhere.
/// </summary>
public static class Achievements
{
const float Every = 2f;
public static readonly List<Award> All = new List<Award>();
static readonly HashSet<string> s_got = new HashSet<string>();
static float s_next;
static bool s_read;
static bool Dev => CommandLine.Has("-autodemo") || CommandLine.Has("-mpdemo") || EndingCinematic.Preview;
static string Key => Dev ? "gc_awards_dev" : "gc_awards";
static Achievements()
{
foreach (double kg in new[] { 1d, 100d, 1000d, 10000d, 100000d })
Add($"SHIP_{kg:0}", kg < 2d ? Loc.N("First Delivery") : Loc.N("{0:N0} kg for Earth"), Loc.N("Ship {0:N0} kg of grass"), (t, p) => t.Shipped.Value >= kg, kg);
foreach (double cash in new[] { 1000d, 10000d, 100000d, 1000000d })
Add($"CASH_{cash:0}", Loc.N("{0} in the Bank"), Loc.N("Have {0} in the crew wallet"), (t, p) => t.Money.Value >= cash, cash, true);
foreach (int n in new[] { 1, 10, 100, 1000, 10000 })
Add($"SECTOR_{n}", n == 1 ? Loc.N("Clean Sweep") : Loc.N("{0:N0} Sectors"), Loc.N("Mow {0:N0} sectors clean"), (t, p) => t.Closed.Value >= n, n);
foreach (double pc in new[] { 0.01d, 0.1d, 1d, 10d, 50d, 100d })
Add($"PLANET_{pc * 100d:0}", pc >= 100d ? Loc.N("Herbaria Mown") : Loc.N("{0:0.##}% of Herbaria-7"), Loc.N("Mow {0:0.##}% of the planet"), (t, p) => t.Mown01 * 100d >= pc, pc);
Add("STAKE_1", Loc.N("Untangled"), Loc.N("Sort out a survey stake"), (t, p) => t.FoundCount(false) >= 1);
Add("STAKE_50", Loc.N("Fifty Stakes"), Loc.N("Sort out 50 survey stakes"), (t, p) => t.FoundCount(false) >= 50);
Add("STAKE_ALL", Loc.N("Every Last Stake"), Loc.N("Sort out all {0} survey stakes"), (t, p) => t.FoundCount(false) >= Landmarks.Stakes, Landmarks.Stakes);
Add("POINT_1", Loc.N("Surveyor"), Loc.N("Read a survey point"), (t, p) => t.FoundCount(true) >= 1);
Add("POINT_ALL", Loc.N("The Whole Map"), Loc.N("Read all {0} survey points"), (t, p) => t.FoundCount(true) >= Landmarks.Points, Landmarks.Points);
Add("STATION_1", Loc.N("Not Alone Out Here"), Loc.N("Find a far station"), (t, p) => t.Opened.Count >= 1);
Add("STATION_5", Loc.N("Well Travelled"), Loc.N("Find 5 far stations"), (t, p) => t.Opened.Count >= 5);
Add("STATION_ALL", Loc.N("All Twelve"), Loc.N("Find every station"), (t, p) => t.Opened.Count >= Stations.Count - 1);
Add("TOOL_SCYTHE", Loc.N("A Proper Scythe"), Loc.N("Own the Scythe"), (t, p) => p.Owns(ToolId.Scythe));
Add("TOOL_ALL", Loc.N("Full Tool Belt"), Loc.N("Own every blade on the wall"), (t, p) => p.Owns(ToolId.WideScythe) && p.Owns(ToolId.LongScythe) && p.Owns(ToolId.Scythe));
Add("ROBOT_1", Loc.N("Let the Robot Do It"), Loc.N("Build a robot dock"), (t, p) => Mowbot.All.Count >= 1);
Add("ROBOT_10", Loc.N("Robot Crew"), Loc.N("Have 10 robots at work"), (t, p) => Mowbot.All.Count >= 10);
Add("REAPER", Loc.N("Fear the Reaper"), Loc.N("Set a Reaper loose"), (t, p) => Mowbot.All.Exists(m => m is Reaper));
}
static void Add(string id, string name, string desc, Func<TeamState, PlayerAgent, bool> done, double value = 0d, bool money = false) => All.Add(new Award { id = id, nameEn = name, descEn = desc, done = done, value = value, money = money });
static void Read()
{
if (s_read) return;
s_read = true;
foreach (var id in PlayerPrefs.GetString(Key, "").Split(',')) if (id.Length > 0) s_got.Add(id);
}
public static bool Has(Award a)
{
Read();
return s_got.Contains(a.id);
}
public static int Earned
{
get
{
Read();
return s_got.Count;
}
}
/// <summary>The demo starts with a clean slate.</summary>
public static void Forget()
{
s_got.Clear();
s_read = true;
PlayerPrefs.DeleteKey(Key);
}
public static void Tick()
{
if (Time.time < s_next) return;
s_next = Time.time + Every;
var ts = TeamState.Instance;
var me = PlayerAgent.Local;
if (!ts || !me || Demo.On) return;
Read();
foreach (var a in All)
{
if (s_got.Contains(a.id) || !a.done(ts, me)) continue;
s_got.Add(a.id);
PlayerPrefs.SetString(Key, string.Join(",", s_got));
PlayerPrefs.Save();
Hud.Toast(Loc.F("Achievement: {0}", a.name), Hud.ToastKind.Info);
Sfx.Play("milestone", 0.7f);
// test runs earn them on this computer only, never on the player's Steam account
if (SteamManager.Initialized && !Dev)
{
SteamUserStats.SetAchievement(a.id);
SteamUserStats.StoreStats();
}
}
}
}
}