Unlock expanded venues and manage concurrent fleet voyages
This commit is contained in:
@@ -8,6 +8,34 @@ namespace Soundings
|
||||
{
|
||||
public Facility[] Cells;
|
||||
public Deck(int size) => Cells = new Facility[size];
|
||||
|
||||
public int AnchorAt(int cell, int columns)
|
||||
{
|
||||
int rowStart = cell - cell % columns;
|
||||
while (cell > rowStart && Cells[cell] == Facility.Extension)
|
||||
cell--;
|
||||
return cell;
|
||||
}
|
||||
|
||||
public Facility FacilityAt(int cell, int columns) => Cells[AnchorAt(cell, columns)];
|
||||
|
||||
internal bool HasValidFootprints(int columns, int hull)
|
||||
{
|
||||
for (int anchor = 0; anchor < Cells.Length;)
|
||||
{
|
||||
Facility facility = Cells[anchor];
|
||||
if ((uint)facility >= (uint)Facility.Extension)
|
||||
return false;
|
||||
FacilitySpec spec = Market.Facilities[(int)facility];
|
||||
if (columns - anchor % columns < spec.Length || hull < spec.MinimumHull)
|
||||
return false;
|
||||
for (int offset = 1; offset < spec.Length; offset++)
|
||||
if (Cells[anchor + offset] != Facility.Extension)
|
||||
return false;
|
||||
anchor += spec.Length;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
@@ -21,24 +49,32 @@ namespace Soundings
|
||||
public CruiseItinerary Itinerary;
|
||||
|
||||
public HullSpec Hull => Market.Hulls[HullIndex];
|
||||
public int Beds => Count(Facility.Cabin) * Market.Facilities[(int)Facility.Cabin].Capacity;
|
||||
public int Meals => Count(Facility.Dining) * Market.Facilities[(int)Facility.Dining].Capacity * 3;
|
||||
public int Entertainment => Count(Facility.Entertainment) * Market.Facilities[(int)Facility.Entertainment].Capacity;
|
||||
public int Beds => FacilityCapacity(Facility.Cabin) + SuiteBerths;
|
||||
public int SuiteBerths => FacilityCapacity(Facility.Suite) + FacilityCapacity(Facility.GrandSuite);
|
||||
internal int GrandSuiteBerths => FacilityCapacity(Facility.GrandSuite);
|
||||
public int Meals => (FacilityCapacity(Facility.Dining) + FacilityCapacity(Facility.Restaurant)) * 3;
|
||||
public int Entertainment => FacilityCapacity(Facility.Entertainment) + FacilityCapacity(Facility.GrandTheater);
|
||||
public int PoolCapacity => FacilityCapacity(Facility.Amenity) + FacilityCapacity(Facility.ResortPool);
|
||||
public int BarCapacity => FacilityCapacity(Facility.Bar) + FacilityCapacity(Facility.CocktailLounge);
|
||||
public int Capacity => Math.Min(Beds, Meals);
|
||||
public int GalleyCapacity => 168 + HullIndex * 72 + Count(Facility.Galley) * Market.Facilities[(int)Facility.Galley].Capacity;
|
||||
public int FoodCapacity => 1500 + HullIndex * 640 + Count(Facility.Stores) * Market.Facilities[(int)Facility.Stores].Capacity;
|
||||
public int WaterCapacity => 16000 + HullIndex * 7600 + Count(Facility.Water) * Market.Facilities[(int)Facility.Water].Capacity;
|
||||
public int GalleyCapacity => 168 + HullIndex * 72 + FacilityCapacity(Facility.Galley);
|
||||
public int FoodCapacity => 1500 + HullIndex * 640 + FacilityCapacity(Facility.Stores);
|
||||
public int WaterCapacity => 16000 + HullIndex * 7600 + FacilityCapacity(Facility.Water);
|
||||
public int WaterProduction => 9000 + HullIndex * 3900 + Count(Facility.Water) * 6000;
|
||||
public int WasteCapacity => 12000 + HullIndex * 6800 + Count(Facility.Waste) * Market.Facilities[(int)Facility.Waste].Capacity;
|
||||
public int WasteCapacity => 12000 + HullIndex * 6800 + FacilityCapacity(Facility.Waste);
|
||||
public int WasteTreatment => 5500 + HullIndex * 3400 + Count(Facility.Waste) * 7000;
|
||||
public int Tank => Hull.Tank + Count(Facility.Tank) * Market.Facilities[(int)Facility.Tank].Capacity;
|
||||
public int Tank => Hull.Tank + FacilityCapacity(Facility.Tank);
|
||||
public double BurnPerMile => Hull.TonsPerMile * (1 + (100 - Condition) * .003);
|
||||
public int SafeRange => Math.Max(0, (int)Math.Floor(Math.Min(Fuel - 6, Fuel * 100 / 112) / BurnPerMile));
|
||||
|
||||
internal void AddEmptyDeck() => Decks.Add(new Deck(Hull.Columns * Hull.Rows));
|
||||
|
||||
private int FacilityCapacity(Facility facility) => Count(facility) * Market.Facilities[(int)facility].Capacity;
|
||||
|
||||
public int Count(Facility facility)
|
||||
{
|
||||
if (facility == Facility.Extension)
|
||||
return 0;
|
||||
int count = 0;
|
||||
foreach (Deck deck in Decks)
|
||||
foreach (Facility cell in deck.Cells)
|
||||
@@ -53,6 +89,7 @@ namespace Soundings
|
||||
{
|
||||
public int Origin, Destination, Miles, Days, Day, Fare, Guests, RoomDemand, Capacity, FuelBurn, Reserve,
|
||||
TicketSales, OnboardSales, Crew, Catering, PortFees, FuelExpense, LoanInterest, Principal, ReputationChange;
|
||||
public int SuiteGuests, SuitePremium;
|
||||
public string ShipName;
|
||||
public int ItineraryStartDay, ItineraryLeg, ItineraryLegs;
|
||||
public OnboardReport Onboard;
|
||||
@@ -72,6 +109,7 @@ namespace Soundings
|
||||
public const int MaxHistory = 30;
|
||||
public int Version = SaveVersion;
|
||||
public int Day = 1, Cash, Debt, Reputation, Voyages;
|
||||
[NonSerialized] internal int ReservedCash;
|
||||
public long LifetimeProfit;
|
||||
public bool Flagship, Bridge;
|
||||
public int SelectedShip, TutorialStep;
|
||||
@@ -80,6 +118,7 @@ namespace Soundings
|
||||
public List<Voyage> History = new List<Voyage>();
|
||||
|
||||
public Ship ActiveShip => SelectedShip >= 0 && SelectedShip < Fleet.Count ? Fleet[SelectedShip] : null;
|
||||
public int AvailableCash => Math.Max(0, Cash - ReservedCash);
|
||||
|
||||
public static Company Start(bool financed)
|
||||
{
|
||||
@@ -116,11 +155,9 @@ namespace Soundings
|
||||
|
||||
foreach (Deck deck in ship.Decks)
|
||||
{
|
||||
if (deck?.Cells == null || deck.Cells.Length != ship.Hull.Columns * ship.Hull.Rows)
|
||||
if (deck?.Cells == null || deck.Cells.Length != ship.Hull.Columns * ship.Hull.Rows
|
||||
|| !deck.HasValidFootprints(ship.Hull.Columns, ship.HullIndex))
|
||||
return false;
|
||||
foreach (Facility cell in deck.Cells)
|
||||
if ((int)cell < 0 || (int)cell >= Market.Facilities.Count)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ship.Fuel > ship.Tank || !ValidSavedItinerary(ship))
|
||||
@@ -150,7 +187,7 @@ namespace Soundings
|
||||
return "The fleet has reached its eight-ship limit.";
|
||||
if (Voyages < hull.Voyages || Reputation < hull.Reputation)
|
||||
return $"Requires {hull.Voyages} voyages and {hull.Reputation} reputation.";
|
||||
if (Cash < (used ? Market.UsedPrice(hullIndex) : hull.Price))
|
||||
if (AvailableCash < (used ? Market.UsedPrice(hullIndex) : hull.Price))
|
||||
return "The company needs more cash.";
|
||||
return null;
|
||||
}
|
||||
@@ -214,28 +251,60 @@ namespace Soundings
|
||||
int price = DeckPrice(ship);
|
||||
if (ship.Decks.Count >= ship.Hull.MaxDecks)
|
||||
return "The hull has reached its deck limit.";
|
||||
if (Cash < price)
|
||||
if (AvailableCash < price)
|
||||
return "The company needs more cash.";
|
||||
Cash -= price;
|
||||
ship.AddEmptyDeck();
|
||||
return null;
|
||||
}
|
||||
|
||||
public string Build(Ship ship, int deckIndex, int cell, Facility plan)
|
||||
public string BuildBlock(Ship ship, int deckIndex, int cell, Facility plan)
|
||||
{
|
||||
if (ship == null || (uint)deckIndex >= (uint)ship.Decks.Count || (uint)cell >= (uint)ship.Decks[deckIndex].Cells.Length)
|
||||
return "Select a berth on this ship.";
|
||||
if ((uint)plan >= (uint)Facility.Extension)
|
||||
return "Select a facility to build.";
|
||||
Deck deck = ship.Decks[deckIndex];
|
||||
Facility previous = deck.Cells[cell];
|
||||
int columns = ship.Hull.Columns;
|
||||
Facility previous = deck.FacilityAt(cell, columns);
|
||||
if (previous == plan)
|
||||
return null;
|
||||
if (previous != Facility.Empty && plan != Facility.Empty)
|
||||
return "Clear this berth before building another facility.";
|
||||
if (previous == Facility.Tank && ship.Fuel > ship.Tank - Market.Facilities[(int)Facility.Tank].Capacity)
|
||||
return "Burn more fuel before removing this tank.";
|
||||
int price = Market.Facilities[(int)plan].Price;
|
||||
if (Cash < price)
|
||||
if (plan == Facility.Empty)
|
||||
return previous == Facility.Tank && ship.Fuel > ship.Tank - Market.Facilities[(int)Facility.Tank].Capacity
|
||||
? "Burn more fuel before removing this tank." : null;
|
||||
|
||||
FacilitySpec spec = Market.Facilities[(int)plan];
|
||||
if (ship.HullIndex < spec.MinimumHull)
|
||||
return $"Requires a {Market.Hulls[spec.MinimumHull].Name} hull or larger.";
|
||||
if (spec.Length > columns - cell % columns)
|
||||
return $"This facility needs {spec.Length} consecutive berths in one row.";
|
||||
for (int offset = 0; offset < spec.Length; offset++)
|
||||
if (deck.Cells[cell + offset] != Facility.Empty)
|
||||
return spec.Length == 1 ? "Clear this berth before building another facility."
|
||||
: "Clear every berth in the footprint before fitting this facility.";
|
||||
if (AvailableCash < spec.Price)
|
||||
return "The company needs more cash.";
|
||||
Cash += Market.Facilities[(int)previous].Price / 4 - price;
|
||||
deck.Cells[cell] = plan;
|
||||
return null;
|
||||
}
|
||||
|
||||
public string Build(Ship ship, int deckIndex, int cell, Facility plan)
|
||||
{
|
||||
string block = BuildBlock(ship, deckIndex, cell, plan);
|
||||
if (block != null)
|
||||
return block;
|
||||
|
||||
Deck deck = ship.Decks[deckIndex];
|
||||
int anchor = deck.AnchorAt(cell, ship.Hull.Columns);
|
||||
Facility previous = deck.Cells[anchor];
|
||||
if (previous == plan)
|
||||
return null;
|
||||
FacilitySpec fitted = Market.Facilities[(int)previous];
|
||||
FacilitySpec selected = Market.Facilities[(int)plan];
|
||||
Cash += fitted.Price / 4 - selected.Price;
|
||||
int length = plan == Facility.Empty ? fitted.Length : selected.Length;
|
||||
deck.Cells[anchor] = plan;
|
||||
for (int offset = 1; offset < length; offset++)
|
||||
deck.Cells[anchor + offset] = plan == Facility.Empty ? Facility.Empty : Facility.Extension;
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -246,7 +315,7 @@ namespace Soundings
|
||||
return "Permit held.";
|
||||
if (Reputation < port.Reputation)
|
||||
return $"Requires {port.Reputation} reputation.";
|
||||
if (Cash < port.Permit)
|
||||
if (AvailableCash < port.Permit)
|
||||
return "The company needs more cash.";
|
||||
return null;
|
||||
}
|
||||
@@ -268,7 +337,7 @@ namespace Soundings
|
||||
if (tons <= 0 || tons > ship.Tank - ship.Fuel)
|
||||
return "Select a fuel quantity that fits in the tank.";
|
||||
int cost = BunkerCost(ship, tons);
|
||||
if (Cash < cost)
|
||||
if (AvailableCash < cost)
|
||||
return "The company needs more cash.";
|
||||
Cash -= cost;
|
||||
ship.Fuel += tons;
|
||||
@@ -281,7 +350,7 @@ namespace Soundings
|
||||
public string Service(Ship ship)
|
||||
{
|
||||
int cost = ServiceCost(ship);
|
||||
if (Cash < cost)
|
||||
if (AvailableCash < cost)
|
||||
return "The company needs more cash.";
|
||||
Cash -= cost;
|
||||
ship.Condition = 100;
|
||||
@@ -293,19 +362,19 @@ namespace Soundings
|
||||
int payment = Math.Min(25000, Debt);
|
||||
if (payment <= 0)
|
||||
return "The company has no outstanding loan.";
|
||||
if (Cash < payment)
|
||||
if (AvailableCash < payment)
|
||||
return "The company needs more cash.";
|
||||
Cash -= payment;
|
||||
Debt -= payment;
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool CanDrawBridge => Bridge && Cash < 100000;
|
||||
public bool CanDrawBridge => Bridge && AvailableCash < 100000;
|
||||
|
||||
public string DrawBridge()
|
||||
{
|
||||
if (!CanDrawBridge)
|
||||
return "Bridge credit is available once when cash falls below $100,000.";
|
||||
return "Bridge credit is available once when spendable cash falls below $100,000.";
|
||||
Cash += 125000;
|
||||
Debt += 125000;
|
||||
Bridge = false;
|
||||
@@ -339,6 +408,12 @@ namespace Soundings
|
||||
double product = (.66 + Reputation * .006 + entertainment * .20) * (.8 + ship.Condition * .002);
|
||||
int roomDemand = Math.Max(0, (int)Math.Round(marketDemand * fareFactor * product));
|
||||
int guests = Math.Min(roomDemand, ship.Capacity);
|
||||
int suiteBerths = ship.SuiteBerths;
|
||||
int suiteGuests = suiteBerths == 0 ? 0 : (int)Math.Round(guests * (double)suiteBerths / ship.Beds);
|
||||
int grandSuiteGuests = suiteGuests == 0 ? 0 : (int)Math.Round(suiteGuests * (double)ship.GrandSuiteBerths / suiteBerths);
|
||||
int suitePremium = (int)Math.Round(ship.Fare / 100.0 * (
|
||||
(suiteGuests - grandSuiteGuests) * Market.Facilities[(int)Facility.Suite].FarePremiumPercent
|
||||
+ grandSuiteGuests * Market.Facilities[(int)Facility.GrandSuite].FarePremiumPercent));
|
||||
double unitCost = ship.Fuel > 0 ? ship.FuelValue / ship.Fuel : Market.FuelPrice(ship.Port, Day);
|
||||
|
||||
return new Voyage
|
||||
@@ -355,7 +430,9 @@ namespace Soundings
|
||||
Capacity = ship.Capacity,
|
||||
FuelBurn = fuel,
|
||||
Reserve = reserve,
|
||||
TicketSales = guests * ship.Fare,
|
||||
SuiteGuests = suiteGuests,
|
||||
SuitePremium = suitePremium,
|
||||
TicketSales = guests * ship.Fare + suitePremium,
|
||||
OnboardSales = (int)Math.Round(guests * days * (13 + entertainment * 18)),
|
||||
Crew = ship.Hull.CrewPerDay * days + ship.Decks.Count * 500 * days,
|
||||
Catering = guests * days * 27,
|
||||
@@ -388,7 +465,7 @@ namespace Soundings
|
||||
return $"Buy {quote.RequiredFuel - ship.Fuel} t more fuel to cover the crossing and reserve.";
|
||||
if (quote.Guests <= 0)
|
||||
return "Raise demand or lower the fare to attract passengers.";
|
||||
if (Cash < quote.OperatingCash + quote.LoanInterest + quote.Principal)
|
||||
if (AvailableCash < quote.OperatingCash + quote.LoanInterest + Math.Min(Debt, quote.Principal))
|
||||
return quote.Plan == null ? "Cash must cover the voyage expenses and loan payment."
|
||||
: "Cash must cover port orders, voyage expenses and the loan payment.";
|
||||
return null;
|
||||
@@ -399,7 +476,7 @@ namespace Soundings
|
||||
if (ship == null || !Fleet.Contains(ship))
|
||||
return "Choose a ship in this fleet.";
|
||||
Voyage quote = live?.Quote ?? Forecast(ship, destination);
|
||||
if (live != null && (live.Ship != ship || quote.Origin != ship.Port || quote.Destination != destination || quote.Day <= Day))
|
||||
if (live != null && (live.Ship != ship || quote.Origin != ship.Port || quote.Destination != destination || quote.Onboard != null))
|
||||
return "This sailing has already been settled or belongs to another ship.";
|
||||
string block = DepartureBlock(ship, quote);
|
||||
if (block != null)
|
||||
@@ -416,6 +493,8 @@ namespace Soundings
|
||||
live.SavePrices();
|
||||
}
|
||||
|
||||
quote.Principal = Math.Min(Debt, quote.Principal);
|
||||
quote.Day = Math.Max(Day, quote.Day);
|
||||
ship.FuelValue *= (double)(ship.Fuel - quote.FuelBurn) / ship.Fuel;
|
||||
ship.Fuel -= quote.FuelBurn;
|
||||
ship.Condition = Market.Clamp(ship.Condition - Math.Max(1, quote.Days / 2) + (quote.Onboard?.Repair ?? 0), 24, 100);
|
||||
|
||||
Reference in New Issue
Block a user