using System; namespace BigShipTycoon { public sealed partial class OnboardSession { private const double PortionPerMeal = .26; private const int WaterPerLaundryLoad = 10; 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 double laundryBacklog, laundryCleaned; private int galleyUntil, pumpsUntil, treatmentUntil, laundryUntil; private int[] crewComplement; private readonly double[] crewCoverage = new double[CrewMarket.Roles.Count]; public bool Assisted { get; set; } = true; public int EngineMode { get; private set; } = 1; public float SpeedFactor => ShipSpeeds[EngineMode] * (float)(.86 + .14 * Coverage(CrewRole.Bridge)); 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 bool LaundryBoost => laundryUntil > tick; public int LaundryDemand { get; private set; } public int LaundryCapacity => Math.Min(138 + Ship.HullIndex * 140 + Ship.FittedLaundryCapacity, AssignedCrew(CrewRole.Laundry) * 22) + (LaundryBoost ? Math.Min(58, AssignedCrew(CrewRole.Laundry) * 9) : 0); public int LaundryBacklog => (int)Math.Ceiling(laundryBacklog); public int LaundryCleaned => (int)Math.Floor(laundryCleaned); public int GalleyCost => 420 + Quote.Guests * 2; public int LaundryShiftCost => 180 + AssignedCrew(CrewRole.Laundry) * 18; 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 CanExtendLaundry => !LaundryBoost && AssignedCrew(CrewRole.Laundry) > 0 && CanSpend(LaundryShiftCost); public int AssignedCrew(CrewRole role) => CrewMarket.IsRole(role) ? crewComplement[(int)role] : 0; public bool CanSpend(int cost) => tick < ticks && Expenses + cost <= Quote.TicketSales / 4; public bool CanSetEngineMode(int mode) => mode >= 0 && mode < FuelRates.Length && (mode < 2 || (Coverage(CrewRole.Engineering) >= .85 && 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 || AssignedCrew(CrewRole.Galley) == 0 || !CanSpend(GalleyCost)) return; Expenses += GalleyCost; galleyUntil = tick + 7; Measure(false); } public void ExtendLaundry() { if (!CanExtendLaundry) return; Expenses += LaundryShiftCost; laundryUntil = tick + 7; } 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; int maximum = Ship.HullIndex == Market.Mega ? 12 : 6; RepairCredit = Math.Min(maximum, 2 + Ship.FittedRepairCapacity); } private void InitializeSystems() { crewComplement = Quote.CrewAssigned is { Length: > 0 } ? (int[])Quote.CrewAssigned.Clone() : Ship.CaptureCrew(); int totalCrew = 0; foreach (CrewRoleSpec department in CrewMarket.Roles) { CrewRole role = department.Role; int assigned = AssignedCrew(role); totalCrew += assigned; crewCoverage[(int)role] = Math.Min(1.35, (double)assigned / CrewMarket.Recommended(Ship, role)); } LaundryDemand = (Quote.Guests + 2) / 3 + (totalCrew + 13) / 14; provisions = Math.Min(Ship.FoodCapacity, Quote.Plan == null ? Quote.Guests * Quote.Days * 2.53 : Quote.Plan.FoodUnits); water = Ship.WaterCapacity; } private double Coverage(CrewRole role) => crewCoverage[(int)role]; private double LaundryServiceLoss => Math.Min(1, laundryBacklog / Math.Max(1, LaundryDemand * .80)); 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; double engineering = .35 + .65 * Coverage(CrewRole.Engineering); water = Math.Min(Ship.WaterCapacity, water + Ship.WaterProduction * engineering * (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; laundryBacklog += LaundryDemand * portionOfDay; double cleaned = Math.Min(laundryBacklog, Math.Min(LaundryCapacity * portionOfDay, water / WaterPerLaundryLoad)); double washingWater = cleaned * WaterPerLaundryLoad; laundryBacklog = Math.Max(0, laundryBacklog - cleaned); laundryCleaned += cleaned; water = Math.Max(0, water - washingWater); waste = Math.Min(Ship.WasteCapacity * 1.3, Math.Max(0, waste + delivered * .74 + washingWater * .76 - Ship.WasteTreatment * engineering * (TreatmentBoost ? 2.3 : 1) * portionOfDay)); } private int StaffedGalleyCapacity => (int)Math.Round(Ship.GalleyCapacity * Coverage(CrewRole.Galley)); private double QuotaPerService() => Math.Min(StaffedGalleyCapacity, Quote.Guests) * PortionPerMeal; private int ServiceCapacity(int service, int venueCapacity) { if (service == (int)OnboardService.Meals) { int galley = StaffedGalleyCapacity + (GalleyBoost ? 85 : 0); int portions = (int)Math.Floor(provisions / PortionPerMeal); return Math.Min(venueCapacity, Math.Min(galley, portions)); } if (service is (int)OnboardService.Shows or (int)OnboardService.Casino) return (int)Math.Round(venueCapacity * Math.Min(1, Coverage(CrewRole.Entertainment))); int staffed = (int)Math.Round(venueCapacity * Math.Min(1, Coverage(CrewRole.Housekeeping))); return service == (int)OnboardService.Amenities && WaterPercent < 22 ? staffed / 3 : staffed; } 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 - LaundryServiceLoss * 3; health = health * .80 + target * .20; } } }