Build Soundings cruise management simulator
This commit is contained in:
117
Assets/Soundings/Editor/EconomyVerification.cs
Normal file
117
Assets/Soundings/Editor/EconomyVerification.cs
Normal file
@@ -0,0 +1,117 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Soundings.Editor
|
||||
{
|
||||
public static class EconomyVerification
|
||||
{
|
||||
public static void Run()
|
||||
{
|
||||
VerifyUsedStartAndProfit();
|
||||
VerifyFinancedStartAndConstruction();
|
||||
VerifyFlagshipCampaign();
|
||||
Debug.Log("Soundings economy verification passed: both starts, pricing, fuel, accounting, saves and flagship progression.");
|
||||
}
|
||||
|
||||
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 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 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user