Add fleet save slots and rotatable onboard venues
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Soundings
|
||||
{
|
||||
@@ -7,10 +8,19 @@ namespace Soundings
|
||||
public sealed class Deck
|
||||
{
|
||||
public Facility[] Cells;
|
||||
[SerializeField] private int[] owners;
|
||||
[SerializeField] private int[] rotations;
|
||||
|
||||
public Deck(int size) => Cells = new Facility[size];
|
||||
|
||||
public int AnchorAt(int cell, int columns)
|
||||
{
|
||||
if (Cells[cell] != Facility.Extension)
|
||||
return cell;
|
||||
if (owners != null && owners.Length != 0)
|
||||
return owners[cell] - 1;
|
||||
|
||||
// Older saves store runs of extension bays immediately after their room.
|
||||
int rowStart = cell - cell % columns;
|
||||
while (cell > rowStart && Cells[cell] == Facility.Extension)
|
||||
cell--;
|
||||
@@ -19,21 +29,80 @@ namespace Soundings
|
||||
|
||||
public Facility FacilityAt(int cell, int columns) => Cells[AnchorAt(cell, columns)];
|
||||
|
||||
public int RotationAt(int anchor) => rotations == null || rotations.Length == 0 ? 0 : rotations[anchor];
|
||||
|
||||
internal bool TryCellAt(int anchor, int columns, Vector2Int offset, out int bay)
|
||||
{
|
||||
int column = anchor % columns + offset.x;
|
||||
bay = (anchor / columns + offset.y) * columns + column;
|
||||
return (uint)column < (uint)columns && (uint)bay < (uint)Cells.Length;
|
||||
}
|
||||
|
||||
internal void SetFacility(int anchor, int columns, Facility facility, int rotation)
|
||||
{
|
||||
if (owners == null || owners.Length == 0)
|
||||
{
|
||||
var legacyOwners = new int[Cells.Length];
|
||||
for (int i = 0; i < Cells.Length; i++)
|
||||
if (Cells[i] == Facility.Extension)
|
||||
legacyOwners[i] = AnchorAt(i, columns) + 1;
|
||||
owners = legacyOwners;
|
||||
rotations = new int[Cells.Length];
|
||||
}
|
||||
|
||||
foreach (Vector2Int offset in Market.Facilities[(int)Cells[anchor]].Footprint(RotationAt(anchor)))
|
||||
{
|
||||
TryCellAt(anchor, columns, offset, out int bay);
|
||||
Cells[bay] = Facility.Empty;
|
||||
owners[bay] = 0;
|
||||
}
|
||||
|
||||
foreach (Vector2Int offset in Market.Facilities[(int)facility].Footprint(rotation))
|
||||
{
|
||||
TryCellAt(anchor, columns, offset, out int bay);
|
||||
Cells[bay] = bay == anchor ? facility : Facility.Extension;
|
||||
owners[bay] = bay == anchor ? 0 : anchor + 1;
|
||||
}
|
||||
rotations[anchor] = rotation;
|
||||
}
|
||||
|
||||
internal bool HasValidFootprints(int columns, int hull)
|
||||
{
|
||||
for (int anchor = 0; anchor < Cells.Length;)
|
||||
bool legacy = (owners == null || owners.Length == 0) && (rotations == null || rotations.Length == 0);
|
||||
if (!legacy && (owners?.Length != Cells.Length || rotations?.Length != Cells.Length))
|
||||
return false;
|
||||
|
||||
var occupied = new bool[Cells.Length];
|
||||
for (int anchor = 0; anchor < Cells.Length; anchor++)
|
||||
{
|
||||
Facility facility = Cells[anchor];
|
||||
if ((uint)facility >= (uint)Facility.Extension)
|
||||
int rotation = RotationAt(anchor);
|
||||
if ((uint)facility >= (uint)Market.Facilities.Count || (uint)rotation > 3)
|
||||
return false;
|
||||
if (facility == Facility.Extension)
|
||||
{
|
||||
if (rotation != 0)
|
||||
return false;
|
||||
continue;
|
||||
}
|
||||
if (!legacy && owners[anchor] != 0)
|
||||
return false;
|
||||
FacilitySpec spec = Market.Facilities[(int)facility];
|
||||
if (columns - anchor % columns < spec.Length || hull < spec.MinimumHull)
|
||||
if (hull < spec.MinimumHull || (spec.BayCount == 1 && rotation != 0))
|
||||
return false;
|
||||
for (int offset = 1; offset < spec.Length; offset++)
|
||||
if (Cells[anchor + offset] != Facility.Extension)
|
||||
foreach (Vector2Int offset in spec.Footprint(rotation))
|
||||
{
|
||||
if (offset == Vector2Int.zero)
|
||||
continue;
|
||||
if (!TryCellAt(anchor, columns, offset, out int bay) || occupied[bay]
|
||||
|| Cells[bay] != Facility.Extension || AnchorAt(bay, columns) != anchor)
|
||||
return false;
|
||||
anchor += spec.Length;
|
||||
occupied[bay] = true;
|
||||
}
|
||||
}
|
||||
for (int bay = 0; bay < Cells.Length; bay++)
|
||||
if (Cells[bay] == Facility.Extension && !occupied[bay])
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -54,8 +123,10 @@ namespace Soundings
|
||||
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 PoolCapacity => FacilityCapacity(Facility.Amenity) + FacilityCapacity(Facility.ResortPool)
|
||||
+ FacilityCapacity(Facility.Spa) + FacilityCapacity(Facility.WaterPark);
|
||||
public int BarCapacity => FacilityCapacity(Facility.Bar) + FacilityCapacity(Facility.CocktailLounge);
|
||||
public int RetailCapacity => FacilityCapacity(Facility.Shop) + FacilityCapacity(Facility.ShoppingArcade);
|
||||
public int Capacity => Math.Min(Beds, Meals);
|
||||
public int GalleyCapacity => 168 + HullIndex * 72 + FacilityCapacity(Facility.Galley);
|
||||
public int FoodCapacity => 1500 + HullIndex * 640 + FacilityCapacity(Facility.Stores);
|
||||
@@ -100,6 +171,17 @@ namespace Soundings
|
||||
public int NetIncome => TicketSales + OnboardSales - OperatingCash - FuelExpense - LoanInterest;
|
||||
public int CashChange => TicketSales + OnboardSales - OperatingCash - LoanInterest - Principal;
|
||||
public int RequiredFuel => FuelBurn + Reserve;
|
||||
|
||||
internal Voyage CopyForPassage(bool hasDeparturePlan)
|
||||
{
|
||||
var copy = (Voyage)MemberwiseClone();
|
||||
copy.Onboard = null;
|
||||
copy.Plan = hasDeparturePlan && Plan != null ? new DeparturePlan
|
||||
{
|
||||
FoodUnits = Plan.FoodUnits, FoodCost = Plan.FoodCost, Program = Plan.Program, ProgramCost = Plan.ProgramCost
|
||||
} : null;
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
@@ -258,53 +340,58 @@ namespace Soundings
|
||||
return null;
|
||||
}
|
||||
|
||||
public string BuildBlock(Ship ship, int deckIndex, int cell, Facility plan)
|
||||
public string BuildBlock(Ship ship, int deckIndex, int cell, Facility plan, int rotation = 0)
|
||||
{
|
||||
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)
|
||||
if (plan == Facility.Extension || (uint)plan >= (uint)Market.Facilities.Count)
|
||||
return "Select a facility to build.";
|
||||
Deck deck = ship.Decks[deckIndex];
|
||||
int columns = ship.Hull.Columns;
|
||||
Facility previous = deck.FacilityAt(cell, columns);
|
||||
if (previous == plan)
|
||||
return null;
|
||||
int anchor = deck.AnchorAt(cell, columns);
|
||||
Facility previous = deck.Cells[anchor];
|
||||
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];
|
||||
rotation = spec.BayCount > 1 ? rotation & 3 : 0;
|
||||
bool turning = previous == plan;
|
||||
if (turning && rotation == deck.RotationAt(anchor))
|
||||
return null;
|
||||
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."
|
||||
if (!turning && previous != Facility.Empty)
|
||||
return "Clear this berth before building another facility.";
|
||||
foreach (Vector2Int offset in spec.Footprint(rotation))
|
||||
{
|
||||
if (!deck.TryCellAt(anchor, columns, offset, out int bay))
|
||||
return "The footprint extends beyond this deck. Try another bay or turn it.";
|
||||
if (deck.Cells[bay] != Facility.Empty && !(turning && deck.AnchorAt(bay, columns) == anchor))
|
||||
return spec.BayCount == 1 ? "Clear this berth before building another facility."
|
||||
: "Clear every berth in the footprint before fitting this facility.";
|
||||
if (AvailableCash < spec.Price)
|
||||
}
|
||||
if (!turning && AvailableCash < spec.Price)
|
||||
return "The company needs more cash.";
|
||||
return null;
|
||||
}
|
||||
|
||||
public string Build(Ship ship, int deckIndex, int cell, Facility plan)
|
||||
public string Build(Ship ship, int deckIndex, int cell, Facility plan, int rotation = 0)
|
||||
{
|
||||
string block = BuildBlock(ship, deckIndex, cell, plan);
|
||||
string block = BuildBlock(ship, deckIndex, cell, plan, rotation);
|
||||
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;
|
||||
rotation = selected.BayCount > 1 ? rotation & 3 : 0;
|
||||
if (previous == plan && deck.RotationAt(anchor) == rotation)
|
||||
return null;
|
||||
if (previous != plan)
|
||||
Cash += Market.Facilities[(int)previous].Price / 4 - selected.Price;
|
||||
deck.SetFacility(anchor, ship.Hull.Columns, plan, rotation);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user