Add port-specific shore excursions and deck stack

This commit is contained in:
josh
2026-11-28 17:19:25 -05:00
parent c570a64840
commit a54f66cec9
28 changed files with 1270 additions and 31 deletions

View File

@@ -108,7 +108,7 @@ namespace Soundings
}
[Serializable]
public sealed class Ship
public sealed partial class Ship
{
public string Name;
public int HullIndex, Port, Condition, Fare, Fuel;
@@ -165,17 +165,23 @@ namespace Soundings
public int ItineraryStartDay, ItineraryLeg, ItineraryLegs;
public OnboardReport Onboard;
public DeparturePlan Plan;
public ShoreOffer[] ShoreOffers;
public int ShoreCallId;
[SerializeReference] public ShoreReport ShoreReport;
public WeatherCondition Weather;
public int OperatingCash => Crew + Catering + PortFees + (Plan == null ? 0 : Plan.FoodCost + Plan.ProgramCost)
+ (Onboard?.Expenses ?? 0);
public int NetIncome => TicketSales + OnboardSales - OperatingCash - FuelExpense - LoanInterest;
public int CashChange => TicketSales + OnboardSales - OperatingCash - LoanInterest - Principal;
public int NetIncome => TicketSales + OnboardSales - OperatingCash - FuelExpense - LoanInterest + (ShoreReport?.NetIncome ?? 0);
public int CashChange => TicketSales + OnboardSales - OperatingCash - LoanInterest - Principal + (ShoreReport?.NetIncome ?? 0);
public int RequiredFuel => FuelBurn + Reserve;
internal Voyage CopyForPassage(bool hasDeparturePlan)
{
var copy = (Voyage)MemberwiseClone();
copy.Onboard = null;
copy.ShoreOffers = ShorePortPlan.Copy(ShoreOffers);
copy.ShoreCallId = 0;
copy.ShoreReport = null;
copy.Plan = hasDeparturePlan && Plan != null ? new DeparturePlan
{
FoodUnits = Plan.FoodUnits, FoodCost = Plan.FoodCost, Program = Plan.Program, ProgramCost = Plan.ProgramCost
@@ -226,6 +232,7 @@ namespace Soundings
|| (Fleet.Count == 0 ? SelectedShip != -1 : SelectedShip < 0 || SelectedShip >= Fleet.Count))
return false;
var callIds = new HashSet<int>();
foreach (Ship ship in Fleet)
{
if (ship == null || string.IsNullOrWhiteSpace(ship.Name) || ship.HullIndex < 0 || ship.HullIndex >= Market.Hulls.Count
@@ -242,13 +249,20 @@ namespace Soundings
return false;
}
if (ship.Fuel > ship.Tank || !ValidSavedItinerary(ship))
if (ship.Fuel > ship.Tank || !ValidSavedItinerary(ship) || !ship.ValidShorePlans()
|| ship.ShoreCall is ShoreCall call && (call.CallId < 1 || call.CallId > Voyages
|| !callIds.Add(call.CallId) || !call.CanLoad(ship.Port)))
return false;
}
var recordedCalls = new HashSet<int>();
foreach (Voyage voyage in History)
if (voyage == null || voyage.Origin < 0 || voyage.Origin >= Permits.Length
|| voyage.Destination < 0 || voyage.Destination >= Permits.Length)
|| voyage.Destination < 0 || voyage.Destination >= Permits.Length
|| voyage.ShoreCallId < 0 || voyage.ShoreCallId > Voyages
|| voyage.ShoreCallId > 0 && !recordedCalls.Add(voyage.ShoreCallId)
|| voyage.ShoreReport is ShoreReport report && (callIds.Contains(voyage.ShoreCallId)
|| !report.CanLoad(voyage.Destination, voyage.ShoreCallId)))
return false;
return true;
}
@@ -507,6 +521,7 @@ namespace Soundings
{
Origin = ship.Port,
Destination = destination,
ShoreOffers = ship.ExcursionsFor(destination),
ShipName = ship.Name,
Day = Day + days,
Days = days,
@@ -536,6 +551,8 @@ namespace Soundings
{
if (ship == null || quote == null || quote.Origin != ship.Port || !Market.TryDistance(ship.Port, quote.Destination, out _))
return "Select a connected port from your itinerary.";
if (ship.ShoreCall != null)
return "Clear the shore excursion groups before departure.";
if (ship.Itinerary is { HasNext: true } itinerary && quote.Destination != itinerary.NextPort)
return $"This itinerary's next stop is {Market.Ports[itinerary.NextPort].Name}.";
if (!Permits[quote.Destination])
@@ -587,6 +604,7 @@ namespace Soundings
ship.Condition = Market.Clamp(ship.Condition - Math.Max(1, quote.Days / 2) + (quote.Onboard?.Repair ?? 0), 24, 100);
RecordItineraryArrival(ship, quote);
ship.Port = quote.Destination;
BookShoreCall(ship, quote);
Day = quote.Day;
Cash += quote.CashChange;
Debt -= quote.Principal;
@@ -597,7 +615,11 @@ namespace Soundings
&& quote.Origin == Market.Bermuda && quote.Destination == Market.Lisbon;
History.Insert(0, quote);
if (History.Count > MaxHistory)
History.RemoveAt(MaxHistory);
{
int archivalRecord = History.FindLastIndex(voyage => voyage.ShoreCallId == 0
|| !Fleet.Exists(vessel => vessel.ShoreCall?.CallId == voyage.ShoreCallId));
History.RemoveAt(archivalRecord >= 0 ? archivalRecord : MaxHistory);
}
return null;
}
}