Files
cruiseSimulator/Assets/Soundings/Editor/EconomyVerification.cs

476 lines
31 KiB
C#

using System;
using UnityEngine;
namespace Soundings.Editor
{
public static class EconomyVerification
{
public static void Run()
{
VerifyUsedStartAndProfit();
VerifyFinancedStartAndConstruction();
VerifyHullDeckProgression();
VerifyMultiBerthFacilities();
VerifyRotatableFacilities();
VerifyFlagshipCampaign();
VerifyLiveCrossingSettlement();
VerifyConcurrentSettlement();
VerifyStormAndShipSystems();
VerifyPortOrders();
VerifyMultiStopItinerary();
Debug.Log("Soundings economy verification passed for both starts, pricing, fuel, enlarged venues, fleet settlements, saves, weather, ship systems, port orders and multi-stop itineraries.");
}
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<Company>(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 VerifyMultiBerthFacilities()
{
Company company = Company.Start(false);
Ship coastal = company.ActiveShip;
Require(company.Build(coastal, 0, 8, Facility.Suite) != null, "Coastal hull cannot fit suites");
Require(company.Build(coastal, 1, 9, Facility.ResortPool) != null, "Coastal hull cannot fit resort pools");
Require(company.Build(coastal, 1, 9, Facility.Extension) != null, "only fitting a complete facility can create a continuation");
company.Cash = 2400000;
company.Voyages = 2;
company.Reputation = 24;
Require(company.ShipyardBlock(Market.Regional, false) != null, "Regional facilities require the Regional voyage milestone");
company.Voyages = 3;
company.Reputation = 23;
Require(company.ShipyardBlock(Market.Regional, false) != null, "Regional acquisition checks reputation");
company.Reputation = 24;
Require(company.Acquire(Market.Regional, false, "Silver Current") == null, "commission a Regional layout");
Ship regional = company.ActiveShip;
company.Reputation = 0;
int cash = company.Cash;
FacilitySpec suite = Market.Facilities[(int)Facility.Suite];
Require(company.Build(regional, 0, 1, Facility.Suite) == null && company.Cash == cash - suite.Price
&& regional.Decks[0].Cells[2] == Facility.Extension && regional.Decks[0].AnchorAt(2, regional.Hull.Columns) == 1
&& regional.Decks[0].FacilityAt(2, regional.Hull.Columns) == Facility.Suite
&& regional.Beds == suite.Capacity && regional.Count(Facility.Suite) == 1,
"an owned Regional hull can still fit a suite after reputation falls");
cash = company.Cash;
Require(company.Build(regional, 0, 2, Facility.Suite) == null && company.Cash == cash, "placing an existing suite is a no-op");
Require(company.Build(regional, 0, 0, Facility.Restaurant) != null && regional.Decks[0].Cells[0] == Facility.Empty
&& company.Cash == cash, "a footprint cannot overlap an existing room");
int rowEnd = regional.Hull.Columns - 1;
Require(company.Build(regional, 0, rowEnd, Facility.Suite) != null && regional.Decks[0].Cells[rowEnd + 1] == Facility.Empty
&& company.Cash == cash, "a footprint cannot wrap into the next row");
Require(company.Build(regional, 1, 0, Facility.GrandTheater) != null, "a Regional hull cannot fit a grand theater");
Require(company.Build(regional, 0, 4, Facility.Cabin) == null
&& company.Build(regional, 1, 0, Facility.Restaurant) == null
&& company.Build(regional, 1, 2, Facility.ResortPool) == null
&& company.Build(regional, 1, 5, Facility.CocktailLounge) == null,
"fit adjacent facilities on a Regional deck");
Require(regional.Meals == 3 * Market.Facilities[(int)Facility.Restaurant].Capacity
&& regional.PoolCapacity == Market.Facilities[(int)Facility.ResortPool].Capacity
&& regional.BarCapacity == Market.Facilities[(int)Facility.CocktailLounge].Capacity,
"each expanded facility contributes capacity once");
Voyage quote = company.Forecast(regional, 1);
var crossing = new OnboardSession(regional, quote);
Require(quote.SuiteGuests > 0 && quote.SuitePremium == (int)Math.Round(quote.SuiteGuests * quote.Fare * (suite.FarePremiumPercent / 100.0))
&& quote.TicketSales == quote.Guests * quote.Fare + quote.SuitePremium
&& crossing.Get(OnboardService.Amenities).Capacity == regional.PoolCapacity
&& crossing.Get(OnboardService.Drinks).Capacity == regional.BarCapacity,
"premium bookings and expanded venues contribute to the live economy");
Require(company.Refuel(regional, quote.RequiredFuel) == null && company.Sail(regional, 1, crossing) == null,
"settle a sailing with suite bookings");
Company loaded = JsonUtility.FromJson<Company>(JsonUtility.ToJson(company));
Require(loaded.CanLoad() && loaded.ActiveShip.Beds == regional.Beds && loaded.History[0].SuitePremium == quote.SuitePremium,
"authored footprints and suite premiums survive reload");
regional = loaded.ActiveShip;
cash = loaded.Cash;
Require(loaded.Build(regional, 0, 2, Facility.Empty) == null && regional.Decks[0].Cells[1] == Facility.Empty
&& regional.Decks[0].Cells[2] == Facility.Empty && loaded.Cash == cash + suite.Price / 4
&& loaded.Build(regional, 0, 2, Facility.Empty) == null && loaded.Cash == cash + suite.Price / 4,
"clearing the continuation removes the whole suite and refunds it once");
regional.Decks[0].Cells[2] = Facility.Extension;
Require(!loaded.CanLoad(), "reject an orphaned continuation in a saved layout");
company.Voyages = 8;
company.Reputation = 42;
Require(company.ShipyardBlock(Market.Ocean, false) != null, "grand facilities require the Ocean Class voyage milestone");
company.Voyages = 9;
company.Reputation = 41;
Require(company.ShipyardBlock(Market.Ocean, false) != null, "Ocean Class acquisition checks reputation");
company.Reputation = 42;
Require(company.Acquire(Market.Ocean, false, "Blue Horizon") == null, "commission an Ocean Class layout");
Ship ocean = company.ActiveShip;
Require(company.Build(ocean, 0, 0, Facility.GrandSuite) == null && ocean.SuiteBerths > suite.Capacity
&& company.Build(ocean, 1, 0, Facility.GrandTheater) == null
&& ocean.Entertainment == Market.Facilities[(int)Facility.GrandTheater].Capacity,
"Ocean Class fits grand suites and a grand theater");
}
private static void VerifyRotatableFacilities()
{
Company company = Company.Start(false);
company.Cash = 2400000;
company.Voyages = 9;
company.Reputation = 42;
Require(company.Build(company.ActiveShip, 1, 9, Facility.ShoppingArcade) != null,
"Coastal hull cannot fit a shopping arcade");
Require(company.Acquire(Market.Regional, false, "Silver Current") == null, "commission a Regional hull for footprint checks");
Ship ship = company.ActiveShip;
Deck deck = ship.Decks[0];
int columns = ship.Hull.Columns;
deck.Cells[0] = Facility.Suite;
deck.Cells[1] = Facility.Extension;
Require(company.CanLoad() && deck.AnchorAt(1, columns) == 0, "legacy row layouts load without footprint metadata");
const int arcade = 4;
int lowerLeft = arcade + columns - 1;
int cash = company.Cash;
Require(company.Build(ship, 0, columns, Facility.ShoppingArcade, 2) != null && company.Cash == cash,
"a turned arcade cannot cross the portside boundary");
Require(company.Build(ship, 0, arcade, Facility.ShoppingArcade, 2) == null
&& deck.AnchorAt(lowerLeft, columns) == arcade && deck.AnchorAt(lowerLeft + 1, columns) == arcade
&& deck.Cells[arcade - 1] == Facility.Empty && deck.AnchorAt(1, columns) == 0,
"an L-shaped installation spans two rows while preserving the open bay and the legacy suite");
Require(ship.RetailCapacity == Market.Facilities[(int)Facility.ShoppingArcade].Capacity,
"arcade capacity is counted once");
cash = company.Cash;
Require(company.Build(ship, 0, arcade - 2, Facility.Spa) != null && deck.Cells[arcade - 2] == Facility.Empty
&& company.Cash == cash, "a square venue cannot overlap another venue's lower row");
Require(company.Build(ship, 0, lowerLeft, Facility.ShoppingArcade, 1) == null
&& deck.RotationAt(arcade) == 1 && deck.Cells[lowerLeft] == Facility.Empty && deck.Cells[lowerLeft + 1] == Facility.Empty
&& deck.AnchorAt(lowerLeft + 2, columns) == arcade && company.Cash == cash,
"rotating an arcade through a continuation reuses its anchor without charging again");
Require(company.Build(ship, 1, 2, Facility.Spa, 3) == null && company.Build(ship, 1, 4, Facility.WaterPark) != null,
"Regional hull fits a spa and keeps the water park locked");
company = JsonUtility.FromJson<Company>(JsonUtility.ToJson(company));
Require(company.CanLoad() && company.ActiveShip.Decks[0].AnchorAt(lowerLeft + 2, columns) == arcade
&& company.ActiveShip.Decks[1].RotationAt(2) == 3
&& company.ActiveShip.Decks[1].FacilityAt(columns + 3, columns) == Facility.Spa,
"saved footprints retain their anchors and rotations, including square venues");
Require(company.Acquire(Market.Ocean, false, "Blue Horizon") == null, "commission an Ocean Class hull for footprint checks");
ship = company.ActiveShip;
deck = ship.Decks[1];
columns = ship.Hull.Columns;
int farCorner = 2 + columns * 2 + 1;
FacilitySpec waterPark = Market.Facilities[(int)Facility.WaterPark];
Require(company.Build(ship, 1, 2, Facility.WaterPark, 1) == null
&& deck.AnchorAt(farCorner, columns) == 2 && ship.PoolCapacity == waterPark.Capacity,
"turning a three-by-two water park spans three rows and counts its capacity once");
cash = company.Cash;
Require(company.Build(ship, 1, farCorner, Facility.Empty) == null
&& Array.TrueForAll(deck.Cells, cell => cell == Facility.Empty) && company.Cash == cash + waterPark.Price / 4,
"clearing the far corner removes the water park and refunds it once");
}
private static void VerifyConcurrentSettlement()
{
Company company = Company.Start(false);
company.Cash = 520000;
company.Debt = 1700;
company.Reputation = 25;
Ship first = company.ActiveShip;
Require(company.Permit(3) == null && company.Acquire(Market.Coastal, true, null) == null,
"prepare two ships for concurrent departures");
Ship second = company.ActiveShip;
Voyage shortQuote = company.Forecast(first, 1);
Voyage longQuote = company.Forecast(second, 3);
Require(shortQuote.Day < longQuote.Day && company.Refuel(second, longQuote.RequiredFuel - second.Fuel) == null,
"schedule passages with different arrival dates");
var shortVoyage = new OnboardSession(first, shortQuote);
var longVoyage = new OnboardSession(second, longQuote);
shortVoyage.AdvanceTo(.2f);
longVoyage.AdvanceTo(.7f);
Require(company.Sail(second, 3, longVoyage) == null && company.Day == longQuote.Day && company.Debt == 0,
"the longer fleet passage can settle first and repay the remaining debt");
int cash = company.Cash;
Require(company.Sail(first, 1, shortVoyage) == null && shortQuote.Day == longQuote.Day
&& company.Cash == cash + shortQuote.CashChange && shortQuote.Principal == 0
&& company.Debt == 0 && company.Day == longQuote.Day && company.Voyages == 2,
"an earlier booking can settle afterward without moving the clock backward or repaying debt twice");
Complete(company, first, 0);
cash = company.Cash;
Require(company.Sail(first, 1, shortVoyage) != null && company.Cash == cash && company.Voyages == 3,
"a settled booking cannot be reused after a return to its origin");
}
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<Company>(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 VerifyPortOrders()
{
Company company = Company.Start(false);
Ship ship = company.ActiveShip;
Voyage light = company.Forecast(ship, 1);
Voyage stocked = company.Forecast(ship, 1);
PortPlanning.Apply(ship, light, company.Day, 125, EntertainmentProgram.Shipboard);
PortPlanning.Apply(ship, stocked, company.Day, ship.FoodCapacity + 100, EntertainmentProgram.LiveMusic);
Require(light.Plan.FoodUnits == 125 && stocked.Plan.FoodUnits == ship.FoodCapacity
&& stocked.Plan.FoodCost > light.Plan.FoodCost && stocked.Plan.ProgramCost > 0, "port food orders respect capacity and itemized costs");
Require(PortPlanning.FoodPriceCents(0, company.Day) != PortPlanning.FoodPriceCents(1, company.Day), "ports have different food prices");
var understocked = new OnboardSession(ship, light) { Assisted = false };
var provisioned = new OnboardSession(ship, stocked) { Assisted = false };
understocked.AdvanceTo(.5f);
provisioned.AdvanceTo(.5f);
Require(provisioned.Get(OnboardService.Shows).Capacity > understocked.Get(OnboardService.Shows).Capacity,
"booked local act opens more show places in its scheduled service window");
understocked.AdvanceTo(1);
provisioned.AdvanceTo(1);
Require(understocked.ProvisionsRemaining == 0 && provisioned.Health > understocked.Health
&& provisioned.Happiness > understocked.Happiness, "underbuying food affects health and guest happiness");
int cash = company.Cash;
company.Cash = stocked.OperatingCash + stocked.LoanInterest + stocked.Principal - 1;
Require(company.DepartureBlock(ship, stocked) != null, "departure needs enough cash for dockside invoices");
company.Cash = cash;
Require(company.Sail(ship, 1, provisioned) == null && company.Cash == cash + stocked.CashChange,
"port invoices settle in the voyage ledger");
var loaded = JsonUtility.FromJson<Company>(JsonUtility.ToJson(company));
Require(loaded.CanLoad() && loaded.History[0].Plan.FoodUnits == stocked.Plan.FoodUnits
&& loaded.History[0].Plan.Program == EntertainmentProgram.LiveMusic, "dockside orders survive a saved arrival");
}
private static void VerifyMultiStopItinerary()
{
Company company = Company.Start(false);
Ship ship = company.ActiveShip;
Require(company.AppendItineraryStop(ship, 0) != null, "an itinerary cannot repeat the current berth in consecutive calls");
Require(company.AppendItineraryStop(ship, 1) == null, "add Nassau to a Miami itinerary");
Require(company.AppendItineraryStop(ship, 2) != null, "a later call also needs its permit");
Require(company.Permit(2) == null && company.AppendItineraryStop(ship, 2) == null, "add Key West after licensing it");
Require(company.AppendItineraryStop(ship, Market.Lisbon) != null, "reject a disconnected leg");
Require(company.Sail(ship, 2) != null && ship.Port == 0, "an active itinerary enforces its next call");
Voyage first = company.Forecast(ship, 1);
var session = new OnboardSession(ship, first);
Require(company.Sail(ship, 1, session) == null && ship.Itinerary.NextPort == 2 && ship.Port == 1,
"settling one leg leaves the ship at its intermediate port");
int start = company.History[0].ItineraryStartDay;
Require(company.History[0].ItineraryLeg == 1 && company.History[0].ItineraryLegs == 2, "record first leg in the voyage ledger");
Company resumed = JsonUtility.FromJson<Company>(JsonUtility.ToJson(company));
Require(resumed.CanLoad() && resumed.ActiveShip.Itinerary.NextPort == 2, "persist the next leg at an intermediate call");
ship = resumed.ActiveShip;
Voyage second = resumed.Forecast(ship, 2);
int needed = Math.Max(0, second.RequiredFuel - ship.Fuel);
if (needed > 0)
Require(resumed.Refuel(ship, needed) == null, "bunker from the intermediate port");
Require(resumed.Sail(ship, 2) == null && ship.Itinerary.CompletedStops == 2 && !ship.Itinerary.HasNext,
"arriving at the last call completes the itinerary");
Require(resumed.History[0].ItineraryStartDay == start && resumed.History[0].ItineraryLeg == 2
&& resumed.History[1].Destination == 1 && resumed.History[0].Destination == 2, "group settled legs in order");
}
private static void Require(bool condition, string description)
{
if (!condition)
throw new InvalidOperationException("Economy verification failed: " + description);
}
}
}