184 lines
7.2 KiB
C#
184 lines
7.2 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
|
||
namespace BigShipTycoon
|
||
{
|
||
public enum CrewRole { Bridge, Engineering, Galley, Housekeeping, Laundry, Entertainment }
|
||
|
||
public sealed class CrewRoleSpec
|
||
{
|
||
public readonly CrewRole Role;
|
||
public readonly string Name, Description;
|
||
public readonly int DailyWage;
|
||
private readonly int[] complement;
|
||
|
||
internal CrewRoleSpec(CrewRole role, string name, string description, int dailyWage, int coastal, int regional, int ocean)
|
||
{
|
||
Role = role;
|
||
Name = name;
|
||
Description = description;
|
||
DailyWage = dailyWage;
|
||
complement = new[] { coastal, regional, ocean };
|
||
}
|
||
|
||
internal int StarterCount(int hull) => complement[hull];
|
||
}
|
||
|
||
public static class CrewMarket
|
||
{
|
||
private const int MaxPerRole = 240;
|
||
|
||
public static readonly IReadOnlyList<CrewRoleSpec> Roles = new[]
|
||
{
|
||
new CrewRoleSpec(CrewRole.Bridge, "Bridge officers", "Stand navigation watches and keep crossings on schedule.", 350, 4, 6, 10),
|
||
new CrewRoleSpec(CrewRole.Engineering, "Engineering", "Keep propulsion, water and treatment systems running.", 220, 8, 14, 24),
|
||
new CrewRoleSpec(CrewRole.Galley, "Galley crew", "Cook meals and staff the galley during busy seatings.", 155, 12, 21, 36),
|
||
new CrewRoleSpec(CrewRole.Housekeeping, "Hotel services", "Turn over cabins and serve guests at bars, shops and amenities.", 130, 14, 24, 44),
|
||
new CrewRoleSpec(CrewRole.Laundry, "Laundry crew", "Wash cabin linen and towels using the ship’s freshwater supply.", 115, 5, 9, 18),
|
||
new CrewRoleSpec(CrewRole.Entertainment, "Entertainment", "Run the ship’s shows and guest programming.", 140, 4, 7, 16)
|
||
};
|
||
|
||
internal static bool IsRole(CrewRole role) => (uint)role < (uint)Roles.Count;
|
||
|
||
public static int Minimum(Ship ship, CrewRole role) => role switch
|
||
{
|
||
CrewRole.Bridge => 2 + ship.HullIndex,
|
||
CrewRole.Engineering => 4 + 2 * ship.HullIndex,
|
||
_ => 0
|
||
};
|
||
|
||
internal static int Starter(Ship ship, CrewRole role) => Roles[(int)role].StarterCount(ship.HullIndex);
|
||
|
||
public static int Recommended(Ship ship, CrewRole role)
|
||
{
|
||
int extraDecks = Math.Max(0, ship.Decks.Count - ship.Hull.StarterDecks);
|
||
int additional = role switch
|
||
{
|
||
CrewRole.Bridge => (extraDecks + 1) / 2,
|
||
CrewRole.Engineering => extraDecks * 2 + ship.Count(Facility.Workshop),
|
||
CrewRole.Galley => extraDecks + ship.Count(Facility.Galley) * 2,
|
||
CrewRole.Housekeeping => extraDecks * 2 + ship.SuiteBerths / 60,
|
||
CrewRole.Laundry => extraDecks + ship.Beds / (100 + 75 * ship.HullIndex),
|
||
CrewRole.Entertainment => ship.Entertainment / 190,
|
||
_ => 0
|
||
};
|
||
// The baseline laundry complement already covers a normal starter fit-out.
|
||
if (role == CrewRole.Laundry)
|
||
additional = Math.Max(0, additional - 2);
|
||
return Starter(ship, role) + additional;
|
||
}
|
||
|
||
public static int HireFee(Ship ship, CrewRole role)
|
||
{
|
||
PortSpec port = Market.Ports[ship.Port];
|
||
double recruitmentRate = Math.Clamp(.85 + (port.Fee - 5600) / 27800.0, .85, 1.48);
|
||
return (int)Math.Round(Roles[(int)role].DailyWage * 3 * recruitmentRate / 10) * 10;
|
||
}
|
||
|
||
internal static bool ValidManifest(int[] manifest)
|
||
{
|
||
if (manifest == null || manifest.Length == 0)
|
||
return true;
|
||
if (manifest.Length != Roles.Count)
|
||
return false;
|
||
foreach (int count in manifest)
|
||
if (count < 0 || count > MaxPerRole)
|
||
return false;
|
||
return true;
|
||
}
|
||
|
||
internal static bool ValidPayroll(Voyage quote) => ValidManifest(quote.CrewAssigned)
|
||
&& (quote.CrewAssigned is not { Length: > 0 } || (long)Payroll(quote.CrewAssigned) * quote.Days == quote.Crew);
|
||
|
||
internal static int Payroll(int[] manifest)
|
||
{
|
||
int wage = 0;
|
||
for (int i = 0; i < Roles.Count; i++)
|
||
wage += manifest[i] * Roles[i].DailyWage;
|
||
return wage;
|
||
}
|
||
|
||
internal static int Maximum(Ship ship, CrewRole role) =>
|
||
Math.Min(MaxPerRole, Math.Max(16, Recommended(ship, role) * 3));
|
||
}
|
||
|
||
public sealed partial class Ship
|
||
{
|
||
[SerializeField] private int[] crew;
|
||
|
||
public int CrewCount(CrewRole role) => !CrewMarket.IsRole(role) ? 0
|
||
: crew is { Length: > 0 } ? crew[(int)role] : CrewMarket.Starter(this, role);
|
||
|
||
public int TotalCrew
|
||
{
|
||
get
|
||
{
|
||
int count = 0;
|
||
foreach (CrewRoleSpec department in CrewMarket.Roles)
|
||
count += CrewCount(department.Role);
|
||
return count;
|
||
}
|
||
}
|
||
|
||
public int DailyPayroll
|
||
{
|
||
get
|
||
{
|
||
int payroll = 0;
|
||
foreach (CrewRoleSpec department in CrewMarket.Roles)
|
||
payroll += CrewCount(department.Role) * department.DailyWage;
|
||
return payroll;
|
||
}
|
||
}
|
||
|
||
internal int[] CaptureCrew()
|
||
{
|
||
var manifest = new int[CrewMarket.Roles.Count];
|
||
for (int i = 0; i < manifest.Length; i++)
|
||
manifest[i] = CrewCount((CrewRole)i);
|
||
return manifest;
|
||
}
|
||
|
||
internal void SetCrewCount(CrewRole role, int count)
|
||
{
|
||
if (crew is not { Length: > 0 })
|
||
crew = CaptureCrew();
|
||
crew[(int)role] = count;
|
||
}
|
||
|
||
internal bool ValidCrew() => CrewMarket.ValidManifest(crew);
|
||
}
|
||
|
||
public sealed partial class Company
|
||
{
|
||
public string CrewChangeBlock(Ship ship, CrewRole role, int change, bool underway = false)
|
||
{
|
||
if (ship == null || !Fleet.Contains(ship) || !CrewMarket.IsRole(role) || change is not (-1 or 1))
|
||
return "Choose a department aboard a ship in your fleet.";
|
||
if (underway)
|
||
return "Crew assignments change at berth.";
|
||
|
||
int assigned = ship.CrewCount(role);
|
||
if (change < 0 && assigned <= CrewMarket.Minimum(ship, role))
|
||
return assigned == 0 ? "This department has no crew to release." : "Keep the watches needed to clear departure.";
|
||
if (change > 0 && assigned >= CrewMarket.Maximum(ship, role))
|
||
return "This department is at its crew accommodation limit.";
|
||
if (change > 0 && AvailableCash < CrewMarket.HireFee(ship, role))
|
||
return "The company needs more available cash to hire.";
|
||
return null;
|
||
}
|
||
|
||
public string ChangeCrew(Ship ship, CrewRole role, int change, bool underway = false)
|
||
{
|
||
string block = CrewChangeBlock(ship, role, change, underway);
|
||
if (block != null)
|
||
return block;
|
||
if (change > 0)
|
||
Cash -= CrewMarket.HireFee(ship, role);
|
||
ship.SetCrewCount(role, ship.CrewCount(role) + change);
|
||
return null;
|
||
}
|
||
}
|
||
}
|