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

78 lines
2.8 KiB
C#

namespace Soundings
{
public sealed partial class SoundingsApp
{
private ShoreOffer[] CurrentShoreOffers(Voyage quote) => ShorePortPlan.Copy(quote?.ShoreOffers);
private bool ApplyShoreOffers(Voyage quote, ShoreOffer[] offers)
{
Ship ship = Ship;
if (ship == null || quote == null || quote.Origin != ship.Port || paused || harbor.PortCinematicActive
|| (underway != null ? quote != underway : page != 3 || inspectedPort != quote.Destination)
|| !ShoreExcursions.ValidOffers(quote.Destination, offers))
return false;
quote.ShoreOffers = ShorePortPlan.Copy(offers);
ship.SetExcursions(quote.Destination, quote.ShoreOffers);
Save();
return true;
}
private void AdvanceShoreCalls(float delta)
{
bool redraw = false;
foreach (Ship ship in company.Fleet)
{
if (ship.ShoreCall is not ShoreCall call || (ship == Ship && harbor.PortCinematicActive))
continue;
ShorePhase previous = call.Phase;
call.Advance(delta);
bool completed = call.Phase == ShorePhase.Complete;
if (completed)
SettleShoreCall(ship);
if (!completed && call.Phase == previous)
continue;
Save();
if (call.Phase == ShorePhase.AwaitingDecision && ship != Ship)
ShowFleetArrivalNotice($"{ship.Name} needs a departure decision in {Market.Ports[ship.Port].Name}.", false);
redraw |= ship == Ship || completed && underway == null && !ShorePlanningOpen;
}
if (redraw && !fleetOpen && !harbor.PortCinematicActive)
Render();
else
RefreshBerthExcursions();
}
private void DecideShoreDeparture(bool hold)
{
Ship ship = Ship;
if (paused || underway != null || ship?.ShoreCall is not ShoreCall call || !call.ResolveLate(hold))
return;
if (call.Phase == ShorePhase.Complete)
SettleShoreCall(ship);
else
Notify("Departure held for the returning group.");
Save();
Render();
}
private void SettleShoreCall(Ship ship)
{
ShoreReport report = company.CompleteShoreCall(ship);
if (report == null)
return;
RefreshFleetMetrics();
string message = $"{ship.Name} cleared for departure · {Money(report.NetIncome)} net from shore excursions.";
if (ship == Ship)
Notify(message);
else
ShowFleetArrivalNotice(message, false);
}
}
}