Files
cruiseSimulator/Assets/Soundings/Runtime/OnboardRounds.cs

175 lines
9.3 KiB
C#

using System;
namespace Soundings
{
public sealed partial class OnboardSession
{
private static readonly float[] CrewCallSchedule = { .12f, .43f, .71f };
private readonly int[] stationReadyAt = new int[(int)StationKind.Retail + 1];
private readonly int[] stationBoostUntil = new int[ServiceKinds];
private int nextCrewCall, crewCallDeadline;
internal StationKind? CrewCall { get; private set; }
internal int CrewRequestsCompleted { get; private set; }
internal int CrewRoundsLeft => CrewCall == null ? 0 : crewCallDeadline - tick;
private double CrewSurveyBonus => CrewRequestsCompleted * 1.6;
internal static string StationName(StationKind station) => station switch
{
StationKind.Helm => "Bridge helm",
StationKind.Engine => "Engine control",
StationKind.Galley => "Galley pass",
StationKind.Stores => "Provision stores",
StationKind.Maintenance => "Maintenance bench",
StationKind.Water => "Freshwater pumps",
StationKind.Waste => "Treatment plant",
StationKind.Cabins => "Cabin service",
StationKind.Dining => "Dining host",
StationKind.Bar => "Bar counter",
StationKind.Stage => "Show lounge",
StationKind.Retail => "Shop checkout",
_ => "Pool terrace"
};
internal string StationAction(StationKind station) => station switch
{
StationKind.Engine => $"Set {EngineOrderName(NextEngineOrder())} power",
StationKind.Galley => $"Staff an extra shift · ${GalleyCost:N0}",
StationKind.Stores => $"Release the reserve · ${StoreCost:N0}",
StationKind.Maintenance => $"Service machinery · ${RepairCost:N0}",
StationKind.Water => $"Boost pumps · ${PumpCost:N0}",
StationKind.Waste => $"Start extra treatment · ${TreatmentCost:N0}",
StationKind.Cabins => "Check in with guests",
StationKind.Dining => $"Call an extra seating · ${GalleyCost:N0}",
StationKind.Bar => "Start happy hour · 25% off",
StationKind.Stage => CanAdvancePerformance ? "Call the booked act" : "Open overflow seating",
StationKind.Pool => "Host a poolside game",
StationKind.Retail => "Start a shop sale · 25% off",
_ => "Take the helm"
};
internal string StationBlock(StationKind station)
{
if (tick >= ticks)
return "Service has ended for this crossing";
if (stationReadyAt[(int)station] > tick)
return "The crew is handling this station";
return station switch
{
StationKind.Galley or StationKind.Dining when GalleyBoost => "The extra shift is already running",
StationKind.Galley or StationKind.Dining when !CanSpend(GalleyCost) => "No room in the operating budget",
StationKind.Dining when ProvisionsRemaining < 12 => "Too little food in stores for another seating",
StationKind.Stores when StoresOpened => "The reserve has already been released",
StationKind.Stores when !CanOpenStores => "Reserve stock is unavailable at this level or budget",
StationKind.Maintenance when Ship.Condition == 100 || RepairCredit > 0 => "Machinery is already serviced",
StationKind.Maintenance when !CanSpend(RepairCost) => "No room in the operating budget",
StationKind.Water when PumpsBoost => "The boost pumps are running",
StationKind.Water when !CanSpend(PumpCost) => "No room in the operating budget",
StationKind.Waste when TreatmentBoost => "Extra treatment is already running",
StationKind.Waste when !CanSpend(TreatmentCost) => "No room in the operating budget",
StationKind.Bar when DiscountTicks(OnboardService.Drinks) > 0 => "Happy hour is already underway",
StationKind.Bar when GetPrice(OnboardService.Drinks) == 0 || capacity[(int)OnboardService.Drinks] == 0 => "There is no paid bar service to promote",
StationKind.Retail when DiscountTicks(OnboardService.Retail) > 0 => "A shop sale is already underway",
StationKind.Retail when GetPrice(OnboardService.Retail) == 0 || capacity[(int)OnboardService.Retail] == 0 => "Set a shopping price to run a sale",
StationKind.Stage when capacity[(int)OnboardService.Shows] == 0 => "No show lounge is fitted",
StationKind.Pool when Quote.Weather == WeatherCondition.Storm => "The terrace is closed in this weather",
StationKind.Pool when WaterPercent < 22 => "Freshwater is too low for pool operation",
_ => null
};
}
internal bool TryWorkStation(StationKind station, out string result)
{
result = StationBlock(station);
if (result != null || station == StationKind.Helm)
return false;
switch (station)
{
case StationKind.Engine: SetEngineMode(NextEngineOrder()); break;
case StationKind.Galley:
case StationKind.Dining: ExtendGalley(); break;
case StationKind.Stores: OpenStores(); break;
case StationKind.Maintenance: ServiceMachinery(); break;
case StationKind.Water: RunBoostPumps(); break;
case StationKind.Waste: BoostTreatment(); break;
case StationKind.Bar: StartSpecial(OnboardService.Drinks); break;
case StationKind.Stage:
if (!TryAdvancePerformance())
stationBoostUntil[(int)OnboardService.Shows] = tick + 6;
break;
case StationKind.Pool: stationBoostUntil[(int)OnboardService.Amenities] = tick + 6; break;
case StationKind.Retail: StartSpecial(OnboardService.Retail); break;
}
stationReadyAt[(int)station] = tick + (station == StationKind.Engine ? 1 : 8);
bool answered = station == CrewCall;
if (answered)
{
CrewRequestsCompleted++;
CrewCall = null;
}
if (answered || station is StationKind.Cabins or StationKind.Pool or StationKind.Stage)
satisfaction = Math.Min(100, satisfaction + (answered ? 4 : 2));
Measure(false);
result = answered ? "Crew call answered · Guest survey improved" : StationResult(station);
return true;
}
private string StationResult(StationKind station) => station switch
{
StationKind.Engine => $"Engine order acknowledged · {EngineOrderName(EngineMode)}",
StationKind.Galley or StationKind.Dining => "Extra service is running",
StationKind.Stores => $"Reserve delivered · {ProvisionsRemaining:N0} portions aboard",
StationKind.Maintenance => "Service logged · Less wear on arrival",
StationKind.Water => "Freshwater boost is running",
StationKind.Waste => "Treatment boost is running",
StationKind.Cabins => "Guest services checked in · Survey improved",
StationKind.Bar => "Happy hour started · Drinks are 25% off",
StationKind.Stage => "Show lounge ready for guests",
StationKind.Retail => "Shop sale started · Merchandise is 25% off",
_ => "Poolside game started · More terrace capacity"
};
private int NextEngineOrder() => EngineMode == 2 || !CanSetEngineMode(EngineMode + 1) ? 0 : EngineMode + 1;
private static string EngineOrderName(int mode) => mode == 0 ? "Economy" : mode == 1 ? "Cruise" : "Power";
private int CrewServiceBoost(int service) => stationBoostUntil[service] <= tick ? 0
: service == (int)OnboardService.Shows ? 42 : 24;
private void AdvanceCrewRequest()
{
if (CrewCall != null && tick >= crewCallDeadline)
CrewCall = null;
if (CrewCall != null || nextCrewCall >= CrewCallSchedule.Length || tick < ticks * CrewCallSchedule[nextCrewCall])
return;
StationKind station;
switch (nextCrewCall++)
{
case 0:
station = ProvisionsRemaining < Quote.Guests && StationBlock(StationKind.Stores) == null
? StationKind.Stores : StationKind.Galley;
break;
case 1:
station = capacity[(int)OnboardService.Shows] > 0 ? StationKind.Stage : StationKind.Cabins;
break;
default:
if (WaterPercent < 33)
station = StationKind.Water;
else if (SewagePercent > 68)
station = StationKind.Waste;
else
station = capacity[(int)OnboardService.Drinks] > 0 ? StationKind.Bar : StationKind.Maintenance;
break;
}
if (StationBlock(station) != null)
station = StationKind.Cabins;
if (StationBlock(station) != null)
return;
CrewCall = station;
crewCallDeadline = Math.Min(ticks, tick + Math.Max(6, ticks / 6));
}
}
}