using System; using UnityEngine; namespace Soundings.Editor { public static class EconomyVerification { public static void Run() { VerifyUsedStartAndProfit(); VerifyFinancedStartAndConstruction(); VerifyHullDeckProgression(); VerifyFlagshipCampaign(); VerifyLiveCrossingSettlement(); VerifyStormAndShipSystems(); Debug.Log("Soundings economy verification passed: both starts, pricing, fuel, accounting, saves, flagship progression, live settlement, weather and ship systems."); } private static void VerifyUsedStartAndProfit() { Company company = Company.Start(false); Ship ship = company.ActiveShip; Require(company.Cash == 135000 && company.Debt == 0 && ship.Capacity == 256, "used start"); Require(company.Forecast(ship, -1) == null, "disconnected route"); Voyage standard = company.Forecast(ship, 1); ship.Fare = 900; Require(company.Forecast(ship, 1).Guests < standard.Guests, "price elasticity"); ship.Fare = standard.Fare; Require(company.Sail(ship, 3) != null && ship.Port == 0 && company.Day == 1, "permit gate"); Require(company.Sail(ship, 1) == null, "first Caribbean sailing"); Require(ship.Port == 1 && company.Day == standard.Day && company.Cash == 135000 + standard.CashChange, "voyage settlement"); Require(ship.Fuel == 48 - standard.FuelBurn && company.LifetimeProfit == standard.NetIncome, "consumed fuel accounting"); Require(Market.FuelPrice(1, company.Day) > Market.FuelPrice(0, company.Day), "foreign fuel market"); int price = Market.FuelPrice(1, company.Day); int priorCash = company.Cash; double priorValue = ship.FuelValue; Require(company.Refuel(ship, 10) == null && company.Cash == priorCash - price * 10, "local fuel purchase cash"); Require(Math.Abs(ship.FuelValue - priorValue - price * 10) < .01, "fuel inventory average cost"); Company loaded = JsonUtility.FromJson(JsonUtility.ToJson(company)); Require(loaded.CanLoad() && loaded.History[0].CashChange == standard.CashChange && loaded.ActiveShip.Port == 1, "save round-trip"); Require(company.Permit(2) == null && company.Permits[2], "permit purchase"); Require(company.Acquire(0, true, null) == null && company.Fleet.Count == 2 && ship.Port == 1, "used fleet expansion"); } private static void VerifyFinancedStartAndConstruction() { Company company = Company.Start(true); Require(company.Cash == 580000 && company.Debt == 500000 && company.ActiveShip == null, "financed start"); Require(company.ShipyardBlock(1, false) != null && company.ShipyardBlock(2, false) != null, "shipyard progression gates"); Require(company.Acquire(0, false, "Peregrine") == null, "commission hull"); Ship ship = company.ActiveShip; Require(company.AddDeck(ship) == null && company.AddDeck(ship) != null, "deck limits"); Require(company.Sail(ship, 1) != null, "empty ship cannot sail"); for (int i = 0; i < 8; i++) Require(company.Build(ship, 0, i, Facility.Cabin) == null, "cabin construction"); Require(company.Build(ship, 0, 0, Facility.Dining) != null, "occupied berth rejection"); Require(company.Build(ship, 1, 0, Facility.Dining) == null && company.Build(ship, 1, 1, Facility.Dining) == null, "dining construction"); Require(company.Build(ship, 1, 2, Facility.Tank) == null, "tank construction"); Voyage quote = company.Forecast(ship, 1); int cash = company.Cash; Require(company.Sail(ship, 1) != null && company.Cash == cash && company.Day == 1, "under-fueled voyage is atomic"); Require(company.Refuel(ship, quote.RequiredFuel - 1) == null && company.Sail(ship, 1) != null, "reserve enforced"); Require(company.Refuel(ship, 1) == null && ship.SafeRange >= quote.Miles, "range matches reserve"); Require(company.Sail(ship, 1) == null && company.Debt == 500000 - quote.Principal && quote.LoanInterest > 0, "debt amortization"); Require(company.Refuel(ship, ship.Tank - ship.Fuel) == null && company.Build(ship, 1, 2, Facility.Empty) != null, "cannot discard loaded tank"); Require(company.PayDownDebt() == null, "voluntary debt payment"); } private static void VerifyFlagshipCampaign() { Company company = Company.Start(false); Ship starter = company.ActiveShip; for (int i = 0; i < 18; i++) Complete(company, starter, 1 - starter.Port); Require(company.ShipyardBlock(2, false) == null, "flagship affordable after a run of profitable voyages"); Require(company.Acquire(2, false, "Blue Meridian") == null, "commission flagship"); Ship ship = company.ActiveShip; for (int i = 0; i < 20; i++) Require(company.Build(ship, 0, i, Facility.Cabin) == null, "flagship berths"); for (int i = 0; i < 5; i++) Require(company.Build(ship, 1, i, Facility.Dining) == null, "flagship dining"); for (int i = 5; i < 9; i++) Require(company.Build(ship, 1, i, Facility.Entertainment) == null, "flagship show capacity"); Require(company.Build(ship, 1, 9, Facility.Tank) == null, "flagship range upgrade"); Require(company.Permit(Market.Bermuda) == null && company.Permit(Market.Lisbon) == null, "Atlantic access"); ship.Fare = 1050; Complete(company, ship, Market.Bermuda); ship.Fare = 1750; Complete(company, ship, Market.Lisbon); Require(company.Flagship && company.History[0].NetIncome > 0 && company.CanLoad(), "end-to-end flagship milestone"); Debug.Log($"Flagship reference run reached Lisbon on day {company.Day} with ${company.Cash:N0} cash."); for (int port = Market.StarterPortCount; port < Market.Ports.Count; port++) { Require(company.Permit(port) == null, "global port permit"); ship.Fare = 400 + 170 * company.Forecast(ship, port).Days; Complete(company, ship, port); } ship.Fare = 1100; Complete(company, ship, 0); Require(ship.Port == 0 && company.Cash > 0 && company.CanLoad(), "completed a global circuit"); Debug.Log($"Global circuit returned to Miami on day {company.Day} with ${company.Cash:N0} cash."); } private static void VerifyHullDeckProgression() { Company company = Company.Start(false); company.Cash = 2_000_000; company.Reputation = 70; company.Voyages = 12; Ship coastal = company.ActiveShip; Require(company.AddDeck(coastal) == null, "expand Coastal to its deck limit"); Require(company.Acquire(1, true, null) == null, "buy a taller Regional hull"); Ship regional = company.ActiveShip; Require(regional.Decks.Count == 4 && regional.Decks.Count > coastal.Decks.Count && regional.Hull.Length > coastal.Hull.Length, "new Regional is bigger than a fully expanded Coastal"); Require(company.AddDeck(regional) == null, "expand Regional to its deck limit"); Require(company.Acquire(Market.Ocean, false, "Crownhaven") == null, "commission a taller Ocean Class hull"); Ship ocean = company.ActiveShip; Require(ocean.Decks.Count == 6 && ocean.Decks.Count > regional.Decks.Count && ocean.Hull.Length > regional.Hull.Length, "new Ocean Class is bigger than a fully expanded Regional"); Require(company.Build(regional, 2, 0, Facility.Stores) == null, "fit an existing Regional deck"); regional.Decks.RemoveRange(3, regional.Decks.Count - 3); ocean.Decks.RemoveRange(2, ocean.Decks.Count - 2); Require(company.CanLoad(), "legacy hulls remain loadable"); company.RestoreHullDecks(); company.RestoreHullDecks(); Require(regional.Decks.Count == 4 && regional.Decks[2].Cells[0] == Facility.Stores && ocean.Decks.Count == 6, "older saves gain missing decks without losing their fit-out"); } private static void VerifyLiveCrossingSettlement() { Company company = Company.Start(false); Ship ship = company.ActiveShip; Voyage booking = company.Forecast(ship, 1); int startingCash = company.Cash; int startingFuel = ship.Fuel; var live = new OnboardSession(ship, booking); int initialDemand = live.Get(OnboardService.Meals).Requested; int initialPrice = live.GetPrice(OnboardService.Meals); live.ChangePrice(OnboardService.Meals, 10); Require(live.Get(OnboardService.Meals).Requested < initialDemand, "meal requests respond to live prices"); Require(live.StartSpecial(OnboardService.Meals) && live.EffectivePrice(OnboardService.Meals) < live.GetPrice(OnboardService.Meals), "specials reduce the effective price immediately"); live.AdvanceTo(.30f); Require(live.CurrentEvent.HasValue && live.CanAcceptEvent, "an event opens with a meaningful budget"); int eventCost = live.CurrentEvent.Value.Cost; int beforeDecision = live.Happiness; live.ResolveEvent(true); Require(live.Expenses == eventCost && live.Happiness > beforeDecision, "event decision affects the crossing"); live.AdvanceTo(.46f); Require(company.Voyages == 0 && ship.Port == 0 && company.Cash == startingCash && ship.Fuel == startingFuel, "onboard simulation does not move the company before arrival"); live.AdvanceTo(1); Require(company.Sail(ship, 1, live) == null, "complete live crossing"); Voyage arrival = company.History[0]; Require(arrival.Guests == booking.Guests && arrival.TicketSales == booking.TicketSales, "departed manifest stays fixed"); Require(arrival.Day == booking.Day && ship.Fuel == startingFuel - booking.FuelBurn, "live arrival settles time and fuel"); Require(company.Cash == startingCash + arrival.CashChange && company.LifetimeProfit == arrival.NetIncome, "live voyage accounting balances"); var reloaded = JsonUtility.FromJson(JsonUtility.ToJson(company)); Require(reloaded.CanLoad() && reloaded.History[0].OnboardSales == arrival.OnboardSales && reloaded.History[0].Onboard.Happiness == arrival.Onboard.Happiness && reloaded.ActiveShip.ServicePrices[(int)OnboardService.Meals] == initialPrice + 10, "live earnings, survey and future prices survive a save round-trip"); Require(company.Sail(ship, 1, live) != null && company.Voyages == 1, "the live crossing cannot settle twice"); } private static void VerifyStormAndShipSystems() { Company company = Company.Start(false); Ship ship = company.ActiveShip; Voyage booking = company.Forecast(ship, 1); ship.Fuel = booking.RequiredFuel; var speed = new OnboardSession(ship, booking); Require(!speed.CanSetEngineMode(2), "full power cannot consume the arrival reserve"); speed.SetEngineMode(0); Require(speed.SpeedFactor < 1 && speed.ProjectedFuelBurn < booking.FuelBurn, "economy power trades time for fuel"); ship.Fuel = ship.Tank; speed.SetEngineMode(2); Require(speed.SpeedFactor > 1 && speed.ProjectedFuelBurn > booking.FuelBurn && speed.ProjectedFuelBurn + booking.Reserve <= ship.Fuel, "full power uses spare fuel without consuming reserve"); var calm = new OnboardSession(ship, booking); Voyage stormBooking = company.Forecast(ship, 1); stormBooking.Weather = WeatherCondition.Storm; var storm = new OnboardSession(ship, stormBooking); Require(calm.Get(OnboardService.Amenities).Capacity > 0 && storm.Get(OnboardService.Amenities).Capacity == 0 && storm.Get(OnboardService.Amenities).Served == 0, "storm closes outdoor amenities"); Require(storm.Get(OnboardService.Drinks).Requested > calm.Get(OnboardService.Drinks).Requested, "storm sends more guests to indoor venues"); storm.AdvanceTo(.30f); Require(storm.CurrentEvent.HasValue && storm.CurrentEvent.Value.Title == "Outdoor decks closed", "storm presents a weather-specific decision"); // Keep the same manifest on a longer crossing to stress the ship's service and utility capacity. booking.Days = 7; var baseline = new OnboardSession(ship, booking) { Assisted = false }; baseline.AdvanceTo(1); OnboardReport baselineReport = baseline.Report(); Require(company.Build(ship, 0, 8, Facility.Galley) == null && company.Build(ship, 0, 9, Facility.Stores) == null && company.Build(ship, 0, 10, Facility.Water) == null && company.Build(ship, 0, 11, Facility.Waste) == null && company.Build(ship, 1, 0, Facility.Stores) == null, "service and utility modules fit spare berths"); var upgraded = new OnboardSession(ship, booking) { Assisted = false }; upgraded.AdvanceTo(1); Require(baselineReport.Provisions == 0 && upgraded.ProvisionsRemaining > 0 && upgraded.WaterPercent > baselineReport.WaterPercent && upgraded.SewagePercent < baselineReport.SewagePercent && upgraded.Health > baselineReport.Health && upgraded.Happiness > baselineReport.Happiness, "upgraded resources sustain guest health and happiness on a long crossing"); } private static void Complete(Company company, Ship ship, int destination) { Voyage quote = company.Forecast(ship, destination); int missing = quote.RequiredFuel - ship.Fuel; if (missing > 0) Require(company.Refuel(ship, missing) == null, "bunker for campaign voyage"); Require(company.Sail(ship, destination) == null, "complete campaign voyage"); } private static void Require(bool condition, string description) { if (!condition) throw new InvalidOperationException("Economy verification failed: " + description); } } }