using System; using UnityEngine; namespace BigShipTycoon.Editor { public static class EconomyVerification { public static void Run() { VerifyUsedStartAndProfit(); VerifyFinancedStartAndConstruction(); VerifyCaptainCareer(); VerifyHullDeckProgression(); VerifyMultiBerthFacilities(); VerifyRotatableFacilities(); VerifySunDeckRefit(); VerifyPlacedSunDeckFittings(); VerifyFlagshipCampaign(); VerifyMegaLiner(); VerifyLiveCrossingSettlement(); VerifyConcurrentSettlement(); VerifyStormAndShipSystems(); VerifyCrewAndLaundry(); VerifyPortOrders(); VerifyMultiStopItinerary(); VerifyShoreExcursions(); Debug.Log("Big Ship Tycoon economy verification passed for all starts, Captain Career, pricing, fuel, venue and sun deck refits, MEGA commissions and facilities, fleet settlements, saves, weather, ship systems, crew payroll, laundry, port orders, multi-stop itineraries and shore excursions."); } private static void VerifyCaptainCareer() { var previous = Company.Start(false); Array.Resize(ref previous.Permits, Market.Brickell); Require(previous.CanLoad() && previous.Permits.Length == Market.Ports.Count && !previous.IsCaptainCareer && previous.Forecast(previous.ActiveShip, Market.Brickell) == null, "earlier careers keep their permits and ocean routes"); var company = Company.StartCaptain(); Ship river = company.ActiveShip; Require(company.CanLoad() && river.HullIndex == Market.River && river.Hull.Length == 32 && river.Decks.Count == 1 && company.Forecast(river, 1) == null && company.Forecast(river, Market.Brickell).NetIncome > 0 && company.ShipyardBlock(Market.Coastal, true) != null, "the river start sails profitable local routes and must earn Coastal command"); Require(company.Build(river, 0, 5, Facility.Suite) != null, "the riverboat cannot install Regional facilities"); Complete(company, river, Market.Brickell); Complete(company, river, Market.Mangrove); var resumed = JsonUtility.FromJson(JsonUtility.ToJson(company)); Require(resumed.CanLoad() && resumed.IsCaptainCareer && resumed.CommandVoyages(Market.River) == 2 && resumed.HelmQualifications(Market.River) == 0 && resumed.ShipyardBlock(Market.Coastal, true) != null, "ordinary river crossings persist without satisfying the practical helm requirement"); } private static void VerifyMegaLiner() { HullSpec hull = Market.Hulls[Market.Mega]; Company company = Company.Start(false); company.Cash = 9_000_000; company.Voyages = hull.Voyages; company.Reputation = hull.Reputation; int available = company.AvailableCash; Require(company.Acquire(Market.Mega, false, "Horizon Crown") != null && company.AvailableCash == available, "a liner commission needs the completed flagship charter even with the required voyage count, reputation, and cash"); company.Flagship = true; company.Voyages--; Require(company.ShipyardBlock(Market.Mega, false) != null, "the liner checks completed voyages after the charter"); company.Voyages++; company.Reputation--; Require(company.ShipyardBlock(Market.Mega, false) != null, "the liner also checks reputation after the charter"); company.Reputation++; Require(company.ShipyardBlock(Market.Mega, true) != null, "the liner can only be commissioned new"); Require(company.Acquire(Market.Ocean, false, "North Star") == null, "prepare an Ocean Class hull for the exclusive fitting checks"); Ship ocean = company.ActiveShip; Require(company.Build(ocean, 0, 0, Facility.SkyResidence) != null && company.Build(ocean, 0, 0, Facility.ProductionGalley) != null, "Ocean Class cannot fit either a MEGA guest venue or utility"); int beforeCommission = company.Cash; Require(company.Acquire(Market.Mega, false, "Horizon Crown") == null && company.Cash == beforeCommission - hull.Price, "unlocked liner commission charges the advertised price once"); Ship ship = company.ActiveShip; Require(ship.Decks.Count == 12 && hull.MaxDecks == 15 && hull.Length >= 300 && hull.Beam >= 48 && ship.Decks[0].Cells.Length == 64 && ship.DailyPayroll > ocean.DailyPayroll && ship.Tank > ocean.Tank, "the liner is longer, wider and taller with an appropriately larger tank and crew complement"); Require(company.AddDeck(ship) == null && company.AddDeck(ship) == null && company.AddDeck(ship) == null && ship.Decks.Count == 15 && company.AddDeck(ship) != null, "the liner expands to its own deck limit"); int tank = ship.Tank, galley = ship.GalleyCapacity, stores = ship.FoodCapacity; int water = ship.WaterCapacity, waterOutput = ship.WaterProduction, waste = ship.WasteCapacity, wasteOutput = ship.WasteTreatment; var fittings = new[] { Facility.SkyResidence, Facility.MarketHall, Facility.OceanArena, Facility.BunkerFarm, Facility.PanoramaClub, Facility.ThermalSpa, Facility.ProductionGalley, Facility.ColdChain, Facility.MembranePlant, Facility.ReclamationPlant, Facility.EngineeringCenter, Facility.Galleria, Facility.RoyalCasino, Facility.LaundryPlant }; for (int i = 0; i < fittings.Length; i++) Require(company.Build(ship, i / 2, i % 2 * 6, fittings[i]) == null, $"fit {fittings[i]} on the liner"); Require(ship.Beds == 128 && ship.Meals == 840 && ship.Entertainment == 720 && ship.BarCapacity == 340 && ship.PoolCapacity == 480 && ship.RetailCapacity == 590 && ship.CasinoCapacity == 640, "each new guest facility adds its own service capacity"); Require(ship.Tank == tank + 320 && ship.GalleyCapacity == galley + 360 && ship.FoodCapacity == stores + 5400 && ship.WaterCapacity == water + 60000 && ship.WaterProduction == waterOutput + 36000 && ship.WasteCapacity == waste + 44000 && ship.WasteTreatment == wasteOutput + 40000, "the enlarged utilities add fuel, provisions, cooking, water, and treatment headroom"); int afterFit = company.Cash; Require(company.Build(ship, 0, 0, Facility.SkyResidence, 1) == null && company.Cash == afterFit && ship.Decks[0].FacilityAt(3 * hull.Columns + 1, hull.Columns) == Facility.SkyResidence, "turn the residence through four rows without paying for it again"); Require(company.Refuel(ship, ship.Tank) == null && company.Build(ship, 1, 6, Facility.Empty) != null, "a full bunker farm cannot be removed while the remaining tanks would overflow"); ship.Fare = 600; ship.Condition = 94; Voyage quote = company.Forecast(ship, 1); var voyage = new OnboardSession(ship, quote); voyage.ServiceMachinery(); Require(quote.Guests > 0 && quote.SuiteGuests == quote.Guests && quote.SuitePremium == quote.Guests * 840 && quote.Crew == ship.DailyPayroll * quote.Days && voyage.RepairCredit == 7 && voyage.LaundryCapacity > 558, "a liner quote and live session use residence fares, crew payroll, laundry and engineering capacity"); Require(company.Sail(ship, 1, voyage) == null && ship.Port == 1, "settle a liner voyage through the ordinary ledger"); Company restored = JsonUtility.FromJson(JsonUtility.ToJson(company)); Require(restored.CanLoad() && restored.ActiveShip.HullIndex == Market.Mega && restored.ActiveShip.Decks.Count == 15 && restored.ActiveShip.Decks[0].RotationAt(0) == 1 && restored.ActiveShip.CasinoCapacity == 640 && restored.History[0].SuitePremium == quote.SuitePremium, "liner fittings, rotation and voyage accounts survive save and reload"); } private static void VerifySunDeckRefit() { Company company = Company.Start(false); Ship ship = company.ActiveShip; int cash = company.Cash, originalCapacity = ship.PoolCapacity; var plan = new SunDeckPlan { Pool = SunPoolStyle.Compact, Shape = SunPoolShape.Oval, Position = SunPoolPosition.Aft, Attraction = SunAttraction.MiniGolf, ExtraLoungers = true }; Require(company.ChangeSunDeck(ship, plan) == null && company.Cash < cash && ship.PoolCapacity > originalCapacity, "a pool and miniature golf course cost cash and add amenity places"); int remaining = company.Cash; Require(company.ChangeSunDeck(ship, plan) == null && company.Cash == remaining, "unchanged sun deck refits do not charge again"); Company restored = JsonUtility.FromJson(JsonUtility.ToJson(company)); Require(restored.CanLoad() && restored.ActiveShip.SunDeckPlan.Pool == plan.Pool && restored.ActiveShip.SunDeckPlan.Shape == plan.Shape && restored.ActiveShip.SunDeckPlan.Position == plan.Position && restored.ActiveShip.SunDeckPlan.Attraction == plan.Attraction && restored.ActiveShip.SunDeckPlan.ExtraLoungers, "sun deck fittings and placement survive a career save"); plan.Attraction = SunAttraction.RollerCoaster; Require(company.ChangeSunDeck(ship, plan) != null && company.Cash == remaining && ship.SunDeckPlan.Attraction == SunAttraction.MiniGolf, "a small hull cannot install a roller coaster or spend money attempting it"); } private static void VerifyPlacedSunDeckFittings() { Company company = Company.Start(false); Ship coastal = company.ActiveShip; int startingCash = company.Cash; Require(company.PlaceSunDeck(coastal, new SunDeckPlacement(SunAttraction.RollerCoaster, 1, 1)) != null && company.Cash == startingCash && !coastal.SunDeckPlan.CustomLayout, "the coaster stays locked on a Coastal ship"); company.Cash = 2_000_000; company.Reputation = 70; company.Voyages = 12; Require(company.Acquire(Market.Ocean, false, "Seabreeze") == null, "commission a ship for a multi-attraction sun deck"); Ship ship = company.ActiveShip; Require(company.AddDeck(ship) == null && company.AddDeck(ship) == null, "test the final sun deck on the expanded hull"); int beforeFit = company.Cash; SunDeckPlacement coaster = FindFreeSunFitting(company, ship, SunAttraction.RollerCoaster); company.Cash = 0; Require(company.PlaceSunDeck(ship, coaster) != null && company.Cash == 0 && !ship.SunDeckPlan.CustomLayout, "an otherwise valid coaster needs funds before changing the layout"); company.Cash = beforeFit; Require(company.PlaceSunDeck(ship, coaster) == null, "fit the coaster on the sun deck"); SunDeckPlacement pool = FindFreeSunFitting(company, ship, SunAttraction.Pool, rotation: 1, startFromBow: true); Require(company.PlaceSunDeck(ship, pool) == null, "fit a rotated pool alongside the coaster"); SunDeckPlacement golf = FindFreeSunFitting(company, ship, SunAttraction.MiniGolf, mustTurn: true); Require(company.PlaceSunDeck(ship, golf) == null, "fit mini golf alongside the coaster and pool"); Require(ship.SunDeckPlan.CustomLayout && ship.SunDeckPlan.Placements is { Length: 3 } && ship.PoolCapacity == 124 + 42 + 52 && company.Cash == beforeFit - 145000 - 9500 - 16000, "three outdoor venues add their own capacities and each charge once"); int afterFit = company.Cash; var overlap = new SunDeckPlacement(SunAttraction.MiniGolf, coaster.Column, coaster.Row); Require(company.PlaceSunDeck(ship, overlap) != null && company.Cash == afterFit && ship.SunDeckPlan.Placements.Length == 3, "overlapping footprints leave the balance and layout alone"); int golfIndex = Array.FindIndex(ship.SunDeckPlan.Placements, item => item.Kind == SunAttraction.MiniGolf); golf.Rotation = 1; Require(company.PlaceSunDeck(ship, golf, golfIndex) == null && company.Cash == afterFit && ship.PoolCapacity == 124 + 42 + 52, "turn an existing mini golf course without buying it again"); Company restored = JsonUtility.FromJson(JsonUtility.ToJson(company)); SunDeckPlacement[] fittings = restored.ActiveShip.SunDeckPlan.Placements; Require(restored.CanLoad() && fittings is { Length: 3 } && Array.Exists(fittings, fitting => fitting.Equals(coaster)) && Array.Exists(fittings, fitting => fitting.Equals(pool)) && Array.Exists(fittings, fitting => fitting.Equals(golf)), "all three placements and rotations survive serialization"); Require(restored.RemoveSunDeck(restored.ActiveShip, Array.FindIndex(fittings, fitting => fitting.Equals(golf))) == null && restored.ActiveShip.PoolCapacity == 124 + 42 && restored.Cash == afterFit + 16000 / 4, "removing mini golf refunds once and leaves the pool and coaster in service"); } private static SunDeckPlacement FindFreeSunFitting(Company company, Ship ship, SunAttraction kind, int rotation = 0, bool startFromBow = false, bool mustTurn = false) { int columns = Mathf.CeilToInt(ship.Hull.Length / 3f); int rows = Mathf.CeilToInt(ship.Hull.Beam / 3f); for (int step = 0; step < columns; step++) { int column = startFromBow ? columns - step - 1 : step; for (int row = 0; row < rows; row++) { var placement = new SunDeckPlacement(kind, column, row, rotation); if (company.SunDeckPlacementBlock(ship, placement) == null && (!mustTurn || company.SunDeckPlacementBlock(ship, new SunDeckPlacement(kind, column, row, rotation + 1)) == null)) return placement; } } throw new InvalidOperationException($"Economy verification could not fit {kind} on {ship.Name}."); } private static void VerifyCrewAndLaundry() { Company company = Company.Start(false); Ship ship = company.ActiveShip; Voyage baseQuote = company.Forecast(ship, 1); int galley = ship.CrewCount(CrewRole.Galley); int laundry = ship.CrewCount(CrewRole.Laundry); int dailyWage = CrewMarket.Roles[(int)CrewRole.Laundry].DailyWage; int hireFee = CrewMarket.HireFee(ship, CrewRole.Laundry); int initialCash = company.Cash; Require(galley > 0 && laundry > 0 && baseQuote.Crew == ship.DailyPayroll * baseQuote.Days && company.DepartureBlock(ship, baseQuote) == null, "the starter vessel has a fully payable sailing crew"); Require(company.ChangeCrew(ship, CrewRole.Laundry, 1, true) != null && company.Cash == initialCash, "an underway crew role cannot be changed"); Require(company.ChangeCrew(ship, CrewRole.Laundry, 1) == null && company.Cash == initialCash - hireFee, "a dockside hire charges a single recruitment fee"); Voyage upgradedQuote = company.Forecast(ship, 1); Require(ship.CrewCount(CrewRole.Laundry) == laundry + 1 && baseQuote.CrewAssigned[(int)CrewRole.Laundry] == laundry && upgradedQuote.Crew == baseQuote.Crew + dailyWage * upgradedQuote.Days, "a changed roster adds daily payroll to a new quote and preserves prior voyage assignments"); var upgraded = new OnboardSession(ship, upgradedQuote) { Assisted = false }; int expandedLaundry = upgraded.LaundryCapacity; int staffedMeals = upgraded.Get(OnboardService.Meals).Capacity; upgraded.AdvanceTo(.50f); Require(company.Cash == initialCash - hireFee && upgraded.LaundryCleaned > 0, "operations use the booked roster and withhold payroll until settlement"); int beforeSail = company.Cash; Require(company.Sail(ship, 1, upgraded) == null && company.History[0].Crew == upgradedQuote.Crew && company.Cash == beforeSail + upgradedQuote.CashChange && company.History[0].Onboard.LaundryCleaned > 0, "arrival records payroll and laundry results and posts the exact cash change"); Require(company.Sail(ship, 1, upgraded) != null && company.Cash == beforeSail + upgradedQuote.CashChange, "a completed voyage cannot debit payroll twice"); Require(CrewMarket.HireFee(ship, CrewRole.Laundry) != hireFee, "the same role costs a different recruitment fee at another port"); company = JsonUtility.FromJson(JsonUtility.ToJson(company)); Require(company.CanLoad() && company.ActiveShip.CrewCount(CrewRole.Laundry) == laundry + 1 && company.History[0].CrewAssigned[(int)CrewRole.Laundry] == laundry + 1 && company.History[0].Onboard.LaundryCleaned > 0, "staff contracts, booked manifests and laundry statistics survive a career save"); company = Company.Start(false); ship = company.ActiveShip; for (int release = 0; release < 3; release++) { Require(company.ChangeCrew(ship, CrewRole.Galley, -1) == null && company.ChangeCrew(ship, CrewRole.Laundry, -1) == null, "release service staff at port"); } Voyage leanQuote = company.Forecast(ship, 1); var lean = new OnboardSession(ship, leanQuote) { Assisted = false }; Require(lean.LaundryCapacity < expandedLaundry && lean.LaundryCapacity < lean.LaundryDemand && lean.Get(OnboardService.Meals).Capacity < staffedMeals, "smaller Galley and Laundry teams limit actual onboard service"); lean.AdvanceTo(.50f); Require(lean.LaundryBacklog > 0 && lean.CanExtendLaundry, "an undersized laundry roster builds up a linen backlog"); int regularCapacity = lean.LaundryCapacity; int beforeShift = lean.Expenses; lean.ExtendLaundry(); Require(lean.LaundryBoost && lean.LaundryCapacity > regularCapacity && lean.Expenses == beforeShift + lean.LaundryShiftCost, "the player can authorize a paid extra laundry shift during the voyage"); } private static void VerifyShoreExcursions() { var names = new System.Collections.Generic.HashSet(); for (int i = 0; i < Market.Ports.Count; i++) { var tours = ShoreExcursions.Catalog(i); Require(tours.Count == 3, "three distinct local shore tours at " + Market.Ports[i].Name); foreach (ShoreTour tour in tours) Require(names.Add(tour.Name) && tour.MinPrice < tour.StandardPrice && tour.StandardPrice < tour.MaxPrice, "unique and priced shore tour " + tour.Name); var route = new Voyage { Destination = i, Guests = 32, Weather = WeatherCondition.Calm }; ShoreBooking[] local = ShoreExcursions.Forecast(route, new[] { new ShoreOffer { Tour = 2, Price = tours[2].StandardPrice, Capacity = tours[2].MaxCapacity } }); Require(local.Length == 1 && local[0].Tour == 2 && local[0].Guests > 0 && local[0].Revenue > local[0].OperatorCost, "the third local excursion can be booked at " + Market.Ports[i].Name); } Company company = Company.Start(false); Voyage quote = company.Forecast(company.ActiveShip, 1); var catalog = ShoreExcursions.Catalog(1); var offer = new ShoreOffer { Tour = 1, Price = catalog[1].StandardPrice, Capacity = catalog[1].MaxCapacity }; ShoreOffer[] offers = { offer }; Require(ShoreExcursions.Create(quote, null) == null, "shore excursions are optional"); Require(!ShoreExcursions.ValidOffers(1, new[] { offer, offer }), "shore plans reject duplicate tours"); ShoreBooking calm = ShoreExcursions.Forecast(quote, offers)[0]; quote.Weather = WeatherCondition.Storm; ShoreBooking storm = ShoreExcursions.Forecast(quote, offers)[0]; Require(storm.Demand < calm.Demand && storm.DelayRisk > calm.DelayRisk, "rough weather shifts shore demand and return risk"); offer.Price = catalog[1].MaxPrice; Require(ShoreExcursions.Forecast(quote, offers)[0].Demand < storm.Demand, "higher shore prices reduce projected demand"); offer.Price = catalog[1].MinPrice; offer.Capacity = 4; ShoreBooking limited = ShoreExcursions.Forecast(quote, offers)[0]; Require(limited.Demand > limited.Guests && limited.Guests == 4 && limited.Revenue > limited.OperatorCost, "excursion seats limit sales and the price floor covers contracted operators"); offer.Capacity = catalog[1].MaxCapacity; var indoor = new ShoreOffer { Tour = 0, Price = catalog[0].MinPrice, Capacity = catalog[0].MaxCapacity }; var studio = new ShoreOffer { Tour = 2, Price = catalog[2].MinPrice, Capacity = catalog[2].MaxCapacity }; quote.Weather = WeatherCondition.Calm; int actualGuests = quote.Guests; quote.Guests = 75; ShoreBooking[] shared = ShoreExcursions.Forecast(quote, new[] { offer, indoor, studio }); Require(shared.Length == 3 && shared[0].Guests > 0 && shared[1].Guests > 0 && shared[2].Guests > 0 && shared[0].Guests + shared[1].Guests + shared[2].Guests <= quote.Guests, "all three shore tours share a finite passenger pool"); quote.Guests = actualGuests; ShoreCall delayed = null, onTime = null; for (int tries = 0; tries < 150 && (delayed == null || onTime == null); tries++, quote.Day++) { ShoreCall call = ShoreExcursions.Create(quote, offers); if (call.LateGuests > 0) delayed = call; else onTime = call; } Require(delayed != null && onTime != null, "scheduled shore tours can arrive on time or run late"); onTime.CallId = 1; Require(onTime.Advance(60) && onTime.Report().CanLoad(1, 1) && onTime.Report().Resolution == ShoreLateResolution.None, "an on-time tour settles without a departure decision"); delayed.CallId = 2; float fullDwell = delayed.RemainingSeconds; Require(!delayed.Advance(4) && delayed.RemainingSeconds < fullDwell, "tour group departure runs on the gameplay clock"); delayed = JsonUtility.FromJson(JsonUtility.ToJson(delayed)); Require(delayed.CanLoad(1) && delayed.Phase == ShorePhase.Touring && delayed.RemainingSeconds == fullDwell - 4, "shore groups and docking timer survive a save"); Require(delayed.Advance(60) && delayed.Phase == ShorePhase.AwaitingDecision && delayed.LateGuests > 0 && !delayed.Advance(60) && delayed.Report() == null, "the departure decision waits for the player"); var alternate = JsonUtility.FromJson(JsonUtility.ToJson(delayed)); Require(delayed.ResolveLate(true) && delayed.CanLoad(1) && delayed.Phase == ShorePhase.Holding && !delayed.ResolveLate(true), "holding persists and cannot be charged twice"); Require(delayed.Advance(60) && delayed.Report().CanLoad(1, 2) && delayed.Report().Resolution == ShoreLateResolution.Held && delayed.Report().NetIncome >= 0, "settle after holding the ship"); Require(alternate.ResolveLate(false) && alternate.Report().CanLoad(1, 2) && alternate.Report().Resolution == ShoreLateResolution.AlternateTransport && alternate.Report().NetIncome >= 0 && alternate.GuestImpact < delayed.GuestImpact && alternate.ReputationImpact < delayed.ReputationImpact, "alternate transport releases the berth immediately with worse guest feedback"); Ship ship = company.ActiveShip; quote = company.Forecast(ship, 1); quote.ShoreOffers = offers; Require(company.Sail(ship, 1, new OnboardSession(ship, quote)) == null && ship.ShoreCall?.CallId == 1 && company.History[0].ShoreCallId == ship.ShoreCall.CallId && company.History[0].ShoreReport == null, "an arrival books the excursion without settling it before guests return"); Company resumed = JsonUtility.FromJson(JsonUtility.ToJson(company)); Require(resumed.CanLoad() && resumed.ActiveShip.ShoreCall?.CallId == 1 && resumed.ActiveShip.ShoreCall.Phase == ShorePhase.Touring && resumed.ActiveShip.ShoreCall.RemainingSeconds == ship.ShoreCall.RemainingSeconds && resumed.History[0].ShoreReport == null, "the career save restores an active shore call and its pending ledger entry"); ShoreCall resumedCall = resumed.ActiveShip.ShoreCall; resumedCall.Advance(60); if (resumedCall.Phase == ShorePhase.AwaitingDecision) resumedCall.ResolveLate(false); resumed.ActiveShip.ShoreCall = null; resumed.History[0].ShoreReport = resumedCall.Report(); resumed = JsonUtility.FromJson(JsonUtility.ToJson(resumed)); Require(resumed.CanLoad() && resumed.ActiveShip.ShoreCall == null && resumed.History[0].ShoreReport?.CanLoad(1, 1) == true, "the career save restores the shore report after berth release"); } 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 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(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(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++) { if (Market.IsRiverPort(port)) continue; 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 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"); Voyage economy = company.Forecast(ship, 1); Voyage express = company.Forecast(ship, 1); PortPlanning.Apply(ship, economy, company.Day, null, EntertainmentProgram.Shipboard, PassageOrder.Economy); PortPlanning.Apply(ship, express, company.Day, null, EntertainmentProgram.Shipboard, PassageOrder.Express); var economical = new OnboardSession(ship, economy); var faster = new OnboardSession(ship, express); Require(economy.RequiredFuel < light.RequiredFuel && express.RequiredFuel > light.RequiredFuel && economy.FuelExpense < light.FuelExpense && express.FuelExpense > light.FuelExpense && economical.EngineMode == 0 && faster.EngineMode == 2 && economical.SpeedFactor < faster.SpeedFactor, "departure sailing orders change fuel requirements, costs and sailing speed"); economical.AdvanceTo(1); faster.AdvanceTo(1); Require(economical.Report().FuelBurn == economy.DepartureFuelBurn && faster.Report().FuelBurn == express.DepartureFuelBurn, "steady sailing orders consume the planned fuel quantity"); 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(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(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); } } }