using System; namespace Soundings { public sealed partial class OnboardSession { private const double PortionPerMeal = .26; private static readonly double[] FuelRates = { .78, 1, 1.22 }; private static readonly float[] ShipSpeeds = { .82f, 1, 1.22f }; private double provisions, water, waste, fuelIntegrated, health = 99, hydration = 1; private int galleyUntil, pumpsUntil, treatmentUntil; public bool Assisted { get; set; } = true; public int EngineMode { get; private set; } = 1; public float SpeedFactor => ShipSpeeds[EngineMode]; public int Health => (int)Math.Round(health); public int WaterPercent => (int)Math.Round(100 * water / Ship.WaterCapacity); public int SewagePercent => (int)Math.Round(100 * waste / Ship.WasteCapacity); public int ProvisionsRemaining => (int)Math.Floor(provisions); public int RepairCredit { get; private set; } public bool StoresOpened { get; private set; } public int ProjectedFuelBurn => FuelForMode(EngineMode); public bool GalleyBoost => galleyUntil > tick; public bool PumpsBoost => pumpsUntil > tick; public bool TreatmentBoost => treatmentUntil > tick; public int GalleyCost => 420 + Quote.Guests * 2; public int StoreCost => 180 + Quote.Guests * 3; public int PumpCost => 410; public int TreatmentCost => 360; public int RepairCost => 780 + Ship.HullIndex * 490; public bool CanOpenStores => !StoresOpened && provisions < Ship.FoodCapacity * .85 && CanSpend(StoreCost); public bool CanSpend(int cost) => tick < ticks && Expenses + cost <= Quote.TicketSales / 4; public bool CanSetEngineMode(int mode) => mode >= 0 && mode < FuelRates.Length && (mode < 2 || FuelForMode(mode) + Quote.Reserve <= Ship.Fuel); public void SetEngineMode(int mode) { if (CanSetEngineMode(mode)) EngineMode = mode; } public void OpenStores() { if (!CanOpenStores) return; Expenses += StoreCost; StoresOpened = true; provisions = Math.Min(Ship.FoodCapacity, provisions + Math.Max(225, Quote.Guests * 1.6)); Measure(false); } public void ExtendGalley() { if (GalleyBoost || !CanSpend(GalleyCost)) return; Expenses += GalleyCost; galleyUntil = tick + 7; Measure(false); } public void RunBoostPumps() { if (PumpsBoost || !CanSpend(PumpCost)) return; Expenses += PumpCost; pumpsUntil = tick + 7; } public void BoostTreatment() { if (TreatmentBoost || !CanSpend(TreatmentCost)) return; Expenses += TreatmentCost; treatmentUntil = tick + 7; } public void ServiceMachinery() { if (RepairCredit > 0 || Ship.Condition >= 100 || !CanSpend(RepairCost)) return; Expenses += RepairCost; RepairCredit = Math.Min(6, 2 + Ship.Count(Facility.Workshop) * Market.Facilities[(int)Facility.Workshop].Capacity); } private void InitializeSystems() { provisions = Math.Min(Ship.FoodCapacity, Quote.Plan == null ? Quote.Guests * Quote.Days * 2.53 : Quote.Plan.FoodUnits); water = Ship.WaterCapacity; } private int FuelForMode(int mode) { double expected = Quote.FuelBurn * (fuelIntegrated + (ticks - tick) * FuelRates[mode]) / ticks; return Math.Max(1, (int)Math.Round(expected, MidpointRounding.AwayFromZero)); } private void AdvanceSystems() { if (Assisted && tick < ticks) { if (provisions < Math.Min(QuotaPerService() * 2, Ship.FoodCapacity * .28)) OpenStores(); if (WaterPercent < 24) RunBoostPumps(); if (SewagePercent > 76) BoostTreatment(); } fuelIntegrated += FuelRates[EngineMode]; double portionOfDay = (double)Quote.Days / ticks; water = Math.Min(Ship.WaterCapacity, water + Ship.WaterProduction * (PumpsBoost ? 1.9 : 1) * portionOfDay); double requested = (Quote.Guests * 54 + Get(OnboardService.Amenities).Served * 28) * portionOfDay; double delivered = Math.Min(water, requested); water -= delivered; hydration = requested <= 0 ? 1 : delivered / requested; waste = Math.Min(Ship.WasteCapacity * 1.3, Math.Max(0, waste + delivered * .74 - Ship.WasteTreatment * (TreatmentBoost ? 2.3 : 1) * portionOfDay)); } private double QuotaPerService() => Math.Min(Ship.GalleyCapacity, Quote.Guests) * PortionPerMeal; private int ServiceCapacity(int service, int venueCapacity) { if (service == (int)OnboardService.Meals) { int galley = Ship.GalleyCapacity + (GalleyBoost ? 85 : 0); int portions = (int)Math.Floor(provisions / PortionPerMeal); return Math.Min(venueCapacity, Math.Min(galley, portions)); } if (service == (int)OnboardService.Amenities && WaterPercent < 22) return venueCapacity / 3; return venueCapacity; } private void UpdateHealth(double mealFulfillment) { double sanitation = 1 - Math.Min(.67, Math.Max(0, waste / Ship.WasteCapacity - .68)); double target = 53 + mealFulfillment * 32 + hydration * 9 + sanitation * 6; health = health * .80 + target * .20; } } }