295 lines
13 KiB
C#
295 lines
13 KiB
C#
using System;
|
|
|
|
namespace BigShipTycoon
|
|
{
|
|
public enum OnboardService { Rooms, Meals, Drinks, Shows, Amenities, Retail, Casino }
|
|
|
|
[Serializable]
|
|
public sealed class OnboardReport
|
|
{
|
|
public int Happiness, Health, Revenue, Expenses, Decisions, FuelBurn, Repair, Provisions, WaterPercent, SewagePercent, CrewCalls;
|
|
public int LaundryCleaned, LaundryBacklog;
|
|
public int CasinoPayouts;
|
|
public int[] ServiceSales;
|
|
}
|
|
|
|
public readonly struct OnboardSample
|
|
{
|
|
public readonly int Requested, Served, Capacity, Revenue;
|
|
public OnboardSample(int requested, int served, int capacity, int revenue)
|
|
{
|
|
Requested = requested;
|
|
Served = served;
|
|
Capacity = capacity;
|
|
Revenue = revenue;
|
|
}
|
|
}
|
|
|
|
public readonly struct VoyageEvent
|
|
{
|
|
public readonly string Title, Detail, Action, Alternative;
|
|
public readonly int Cost;
|
|
internal readonly int Service, Surge;
|
|
public VoyageEvent(string title, string detail, string action, string alternative, int cost, int service, int surge)
|
|
{
|
|
Title = title;
|
|
Detail = detail;
|
|
Action = action;
|
|
Alternative = alternative;
|
|
Cost = cost;
|
|
Service = service;
|
|
Surge = surge;
|
|
}
|
|
}
|
|
|
|
public sealed partial class OnboardSession
|
|
{
|
|
private const int ServiceKinds = (int)OnboardService.Casino + 1;
|
|
private const int PromotionTicks = 5;
|
|
private const int WholesalePrice = 5;
|
|
private static readonly int[] Defaults = { 0, 12, 7, 18, 10, 22, 18 };
|
|
private static readonly double[] BaseDemand = { 0, .71, .59, .43, .51, .29, .36 };
|
|
private static readonly VoyageEvent[] Events =
|
|
{
|
|
new VoyageEvent("Dinner rush", "An early seating is filling up. Open overflow tables to expand meal capacity and lift the survey.",
|
|
"Open overflow service", "Keep the schedule", 650, 1, 40),
|
|
new VoyageEvent("Sunset crowd", "Guests want a sunset program. Run an extra set on deck to provide more show places.",
|
|
"Book an encore", "Use the regular program", 950, 3, 65)
|
|
};
|
|
|
|
private static readonly VoyageEvent[] StormEvents =
|
|
{
|
|
new VoyageEvent("Outdoor decks closed", "Passengers have moved indoors. Add an indoor set to open extra show places.",
|
|
"Book an indoor set", "Keep the schedule", 1050, 3, 84),
|
|
new VoyageEvent("Lounge queues", "The lounges are still busy. Set up a temporary drinks station to ease the queues.",
|
|
"Open another station", "Use the regular bars", 760, 2, 54)
|
|
};
|
|
|
|
public readonly Ship Ship;
|
|
public readonly Voyage Quote;
|
|
private readonly int ticks;
|
|
private readonly int[] revenue = new int[ServiceKinds];
|
|
private readonly int[] saleUntil = new int[ServiceKinds];
|
|
private readonly int[] capacity = new int[ServiceKinds];
|
|
private readonly OnboardSample[] sample = new OnboardSample[ServiceKinds];
|
|
private readonly int[] prices;
|
|
|
|
private int tick, nextEvent, openedAt = -1, eventBenefitUntil, featuredService = -1, additionalCapacity, decisions;
|
|
private double satisfaction = 82;
|
|
public int Happiness => (int)Math.Round(satisfaction);
|
|
public int Revenue { get; private set; }
|
|
public int Expenses { get; private set; }
|
|
public int CasinoPayouts { get; private set; }
|
|
public float Progress => (float)tick / ticks;
|
|
public VoyageEvent? CurrentEvent => openedAt < 0 ? null :
|
|
(Quote.Weather == WeatherCondition.Storm ? StormEvents : Events)[nextEvent];
|
|
public string EventResult { get; private set; }
|
|
public int RemainingEventTicks => openedAt < 0 ? 0 : Math.Max(0, openedAt + 6 - tick);
|
|
public bool CanAcceptEvent => CurrentEvent.HasValue && CanBuyEvent(CurrentEvent.Value);
|
|
private bool CanBuyEvent(VoyageEvent offer) => Expenses + offer.Cost <= Quote.TicketSales / 4;
|
|
|
|
public OnboardSession(Ship ship, Voyage quote)
|
|
{
|
|
Ship = ship;
|
|
Quote = quote;
|
|
ticks = Math.Max(24, quote.Days * 8);
|
|
capacity[0] = ship.Beds;
|
|
capacity[1] = ship.Meals;
|
|
capacity[2] = ship.BarCapacity;
|
|
capacity[3] = ship.Entertainment - (quote.Weather == WeatherCondition.Storm ? ship.OutdoorShowCapacity : 0);
|
|
int indoor = ship.Count(Facility.ThermalSpa) * Market.Facilities[(int)Facility.ThermalSpa].Capacity;
|
|
int outdoor = ship.PoolCapacity - indoor;
|
|
capacity[4] = indoor + (quote.Weather switch { WeatherCondition.Storm => 0, WeatherCondition.Swell => outdoor * 2 / 3, _ => outdoor });
|
|
capacity[(int)OnboardService.Retail] = ship.RetailCapacity;
|
|
capacity[(int)OnboardService.Casino] = ship.CasinoCapacity;
|
|
|
|
prices = (int[])Defaults.Clone();
|
|
if (ship.ServicePrices != null)
|
|
Array.Copy(ship.ServicePrices, prices, Math.Min(ship.ServicePrices.Length, prices.Length));
|
|
for (int i = 0; i < ServiceKinds; i++)
|
|
prices[i] = Market.Clamp(prices[i], 0, Defaults[i] * 4);
|
|
InitializeSystems();
|
|
Measure(false);
|
|
}
|
|
|
|
public static string ServiceLabel(OnboardService service) => service switch
|
|
{
|
|
OnboardService.Rooms => "Rooms",
|
|
OnboardService.Meals => "Meals",
|
|
OnboardService.Drinks => "Drinks",
|
|
OnboardService.Shows => "Entertainment",
|
|
OnboardService.Retail => "Shopping",
|
|
OnboardService.Casino => "Casino",
|
|
_ => "Amenities"
|
|
};
|
|
|
|
public OnboardSample Get(OnboardService service) => sample[(int)service];
|
|
|
|
public int GetPrice(OnboardService service) => prices[(int)service];
|
|
|
|
internal void SavePrices() => Ship.ServicePrices = (int[])prices.Clone();
|
|
|
|
public int EffectivePrice(OnboardService service)
|
|
{
|
|
int price = GetPrice(service);
|
|
return price > 0 && DiscountTicks(service) > 0 ? Math.Max(1, price * 3 / 4) : price;
|
|
}
|
|
|
|
public int DiscountTicks(OnboardService service) => Math.Max(0, saleUntil[(int)service] - tick);
|
|
|
|
public void ChangePrice(OnboardService service, int amount)
|
|
{
|
|
int index = (int)service;
|
|
if (index == 0 || Progress >= 1)
|
|
return;
|
|
prices[index] = Market.Clamp(prices[index] + amount, 0, Defaults[index] * 4);
|
|
Measure(false);
|
|
}
|
|
|
|
public bool StartSpecial(OnboardService service)
|
|
{
|
|
int index = (int)service;
|
|
if (index == 0 || GetPrice(service) <= 0 || capacity[index] <= 0 || DiscountTicks(service) > 0 || tick >= ticks)
|
|
return false;
|
|
saleUntil[index] = tick + PromotionTicks;
|
|
Measure(false);
|
|
return true;
|
|
}
|
|
|
|
public void ResolveEvent(bool accept)
|
|
{
|
|
if (!CurrentEvent.HasValue || (accept && !CanAcceptEvent))
|
|
return;
|
|
VoyageEvent offer = CurrentEvent.Value;
|
|
if (accept)
|
|
{
|
|
Expenses += offer.Cost;
|
|
featuredService = offer.Service;
|
|
additionalCapacity = offer.Surge;
|
|
eventBenefitUntil = tick + 8;
|
|
satisfaction = Math.Min(100, satisfaction + 5);
|
|
EventResult = offer.Action + " booked.";
|
|
}
|
|
else
|
|
{
|
|
satisfaction = Math.Max(0, satisfaction - 2);
|
|
EventResult = offer.Alternative + ".";
|
|
}
|
|
decisions++;
|
|
openedAt = -1;
|
|
nextEvent++;
|
|
Measure(false);
|
|
}
|
|
|
|
public void AdvanceTo(float progress)
|
|
{
|
|
int goal = Market.Clamp((int)Math.Floor(progress * ticks + .0001), tick, ticks);
|
|
while (tick < goal)
|
|
{
|
|
tick++;
|
|
AdvanceSystems();
|
|
AdvancePerformance();
|
|
if (openedAt >= 0 && tick >= openedAt + 6)
|
|
ResolveEvent(false);
|
|
if (openedAt < 0 && nextEvent < Events.Length && tick >= ticks * (nextEvent == 0 ? .23 : .59))
|
|
openedAt = tick;
|
|
Measure(true);
|
|
AdvanceCrewRequest();
|
|
}
|
|
if (tick >= ticks && openedAt >= 0)
|
|
ResolveEvent(false);
|
|
}
|
|
|
|
public OnboardReport Report() => new OnboardReport
|
|
{
|
|
Happiness = Happiness,
|
|
Health = Health,
|
|
CrewCalls = CrewRequestsCompleted,
|
|
FuelBurn = ProjectedFuelBurn,
|
|
Repair = RepairCredit,
|
|
Provisions = ProvisionsRemaining,
|
|
WaterPercent = WaterPercent,
|
|
SewagePercent = SewagePercent,
|
|
LaundryCleaned = LaundryCleaned,
|
|
LaundryBacklog = LaundryBacklog,
|
|
CasinoPayouts = CasinoPayouts,
|
|
Revenue = Revenue,
|
|
Expenses = Expenses,
|
|
Decisions = decisions,
|
|
ServiceSales = (int[])revenue.Clone()
|
|
};
|
|
|
|
private void Measure(bool collect)
|
|
{
|
|
sample[0] = new OnboardSample(Math.Max(Quote.Guests, Quote.RoomDemand), Quote.Guests, capacity[0], 0);
|
|
double fulfillment = 1;
|
|
double mealFulfillment = 1;
|
|
int serviceCount = 1;
|
|
for (int i = 1; i < ServiceKinds; i++)
|
|
{
|
|
bool retail = i == (int)OnboardService.Retail;
|
|
bool gaming = i == (int)OnboardService.Casino;
|
|
if ((retail || gaming) && capacity[i] == 0)
|
|
continue;
|
|
serviceCount++;
|
|
int price = EffectivePrice((OnboardService)i);
|
|
double wave = .76 + .48 * (.5 + .5 * Math.Sin((tick + i * 2.1) * .66));
|
|
double appeal = Math.Max(.23, Math.Min(1.6, (Defaults[i] + 5.0) / (price + 5.0)));
|
|
bool featured = featuredService == i && tick <= eventBenefitUntil;
|
|
VoyageEvent? notice = CurrentEvent;
|
|
int rush = notice.HasValue && notice.Value.Service == i ? notice.Value.Surge : featured ? additionalCapacity / 2 : 0;
|
|
bool performance = i == (int)OnboardService.Shows && PerformanceActive;
|
|
if (performance)
|
|
rush += PortPlanning.ShowDemand(BookedProgram);
|
|
double indoorShift = Quote.Weather == WeatherCondition.Storm && (i == 2 || i == 3 || retail || gaming) ? 1.28 : 1;
|
|
int requested = Math.Min(Quote.Guests, rush + (int)Math.Round(Quote.Guests * BaseDemand[i] * appeal * wave * indoorShift));
|
|
int extraSeats = performance ? PortPlanning.ShowSeats(BookedProgram) : 0;
|
|
int possible = ServiceCapacity(i, capacity[i] + (featured ? additionalCapacity : 0) + CrewServiceBoost(i)) + extraSeats;
|
|
int served = Math.Min(requested, possible);
|
|
|
|
if (collect)
|
|
{
|
|
int takings;
|
|
if (retail)
|
|
{
|
|
int orders = price == 0 ? 0 : (int)Math.Round(served * .13);
|
|
takings = orders * price;
|
|
Expenses += orders * WholesalePrice;
|
|
}
|
|
else if (gaming)
|
|
{
|
|
takings = (int)Math.Round(served * .24) * price;
|
|
// Deterministic payouts make shifts vary while keeping saved voyages reproducible.
|
|
double returnRate = .82 + .16 * Math.Sin(tick * 1.37 + Quote.Origin * .71 + Quote.Destination);
|
|
int paidOut = (int)Math.Round(takings * returnRate);
|
|
CasinoPayouts += paidOut;
|
|
Expenses += paidOut;
|
|
}
|
|
else
|
|
takings = (int)Math.Round(served * price * (i == 1 ? .17 : .13));
|
|
revenue[i] += takings;
|
|
Revenue += takings;
|
|
}
|
|
if (i == (int)OnboardService.Meals)
|
|
{
|
|
mealFulfillment = requested == 0 ? 1 : (double)served / requested;
|
|
if (collect)
|
|
provisions = Math.Max(0, provisions - served * PortionPerMeal);
|
|
}
|
|
sample[i] = new OnboardSample(requested, served, possible, revenue[i]);
|
|
double affordability = price <= Defaults[i] ? 1 : .43 + .57 * Defaults[i] / price;
|
|
fulfillment += (requested == 0 ? 1 : (double)served / requested) * affordability;
|
|
}
|
|
if (collect)
|
|
{
|
|
UpdateHealth(mealFulfillment);
|
|
double cabinService = (Coverage(CrewRole.Housekeeping) - 1) * 8;
|
|
double showService = capacity[(int)OnboardService.Shows] > 0 ? Math.Max(0, Coverage(CrewRole.Entertainment) - 1) * 6 : 0;
|
|
double target = Math.Clamp(40 + 55 * fulfillment / serviceCount - (100 - health) * .28
|
|
+ CrewSurveyBonus + cabinService + showService - LaundryServiceLoss * 8, 0, 100);
|
|
satisfaction = satisfaction * .77 + target * .23;
|
|
}
|
|
}
|
|
}
|
|
}
|