Add fleet save slots and rotatable onboard venues

This commit is contained in:
josh
2026-11-28 16:04:48 -05:00
parent a9472edc35
commit c570a64840
37 changed files with 1970 additions and 310 deletions

View File

@@ -0,0 +1,305 @@
using System;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.UIElements;
namespace Soundings
{
public sealed partial class SoundingsApp
{
private enum CareerMenu { Closed, Load, SaveAs }
private CareerMenu careerMenu;
private CareerStore careers;
private string careerId, careerName, careerNameDraft, careerError;
private CareerSave legacyCareer;
private float nextCareerAutosave;
private void InitializeCareers()
{
string path = autoSmoke ? Path.Combine(Path.GetTempPath(), "soundings-careers-" + Guid.NewGuid().ToString("N"))
: Path.Combine(Application.persistentDataPath, "Careers");
careers = new CareerStore(path);
if (autoSmoke || AdoptCareer(careers.Read(careers.RecentId), false))
return;
foreach (CareerSave candidate in careers.List())
if (AdoptCareer(candidate, false))
return;
if (!PlayerPrefs.HasKey(SaveKey))
return;
try
{
var imported = new CareerSave
{
Id = Guid.NewGuid().ToString("N"),
Name = "Imported career",
SavedUtc = DateTime.UtcNow.Ticks,
Company = JsonUtility.FromJson<Company>(PlayerPrefs.GetString(SaveKey))
};
if (AdoptCareer(imported, false))
{
if (!careers.Write(imported))
legacyCareer = imported;
return;
}
}
catch (ArgumentException error)
{
Debug.LogWarning("Could not import the previous career. " + error.Message);
}
Notify("The previous career could not be read.", true);
}
private bool AdoptCareer(CareerSave saved, bool play)
{
if (saved?.Company == null || !saved.Company.CanLoad())
return false;
saved.Company.RestoreHullDecks();
if (!CanRestoreFleetPassages(saved.Company, saved.Passages))
return false;
if (harbor.PortCinematicActive)
harbor.EndPortCinematic();
if (underway != null)
harbor.EndPassage();
passageAudio.End();
ResetFleetPassages();
company = saved.Company;
RestoreFleetPassages(saved.Passages);
careerId = saved.Id;
careerName = saved.Name;
paused = fleetOpen = shipActionsOpen = false;
pendingStart = null;
careerMenu = CareerMenu.Closed;
title = !play;
page = Ship == null ? 2 : Mathf.Clamp(saved.Page, 0, 4);
deckIndex = Ship == null ? 0 : Mathf.Clamp(saved.DeckIndex, 0, Ship.Decks.Count - 1);
inspectedPort = Ship?.Port ?? 0;
yardSelection = 1;
selectedVoyage = 0;
ledgerRecordOffset = 0;
ledgerAccounts = worldChart = false;
tool = Facility.Cabin;
deckTools = DeckTools.GuestFacilities;
ResetWeatherSelection();
ResetItinerary();
nextCareerAutosave = Time.unscaledTime + 15;
if (play)
{
harbor.ResetView(true);
ResumeSelectedSavedPassage();
careers.Select(saved.Id);
Notify(null);
Render();
}
return true;
}
private void LoadCareer(string id)
{
CareerSave saved = careers.Read(id) ?? (legacyCareer?.Id == id ? legacyCareer : null);
if (AdoptCareer(saved, true))
return;
careerError = "This save could not be loaded.";
if (careerMenu == CareerMenu.Closed)
Notify(careerError, true);
Render();
}
private bool WriteCareer(string newName = null)
{
if (company == null)
return false;
var entry = new CareerSave
{
Id = newName != null || careerId == null ? Guid.NewGuid().ToString("N") : careerId,
Name = newName ?? careerName ?? "Soundings career",
SavedUtc = DateTime.UtcNow.Ticks,
Page = page,
DeckIndex = deckIndex,
Company = company,
Passages = CaptureFleetPassages()
};
nextCareerAutosave = Time.unscaledTime + 15;
if (!careers.Write(entry))
{
careerError = "The game could not write this save.";
return false;
}
careerId = entry.Id;
careerName = entry.Name;
careerError = null;
return true;
}
private void Save()
{
if (!autoSmoke && !WriteCareer())
Notify(careerError, true);
}
private void AutosaveCareer()
{
if (!title && !paused && fleetPassages.Count > 0 && Time.unscaledTime >= nextCareerAutosave)
Save();
}
private void SaveFromPause()
{
if (WriteCareer())
Notify($"Saved {careerName}.");
else
Notify(careerError, true);
Render();
}
private void SaveAndLeave(bool quit)
{
if (!WriteCareer())
{
Notify(careerError, true);
Render();
return;
}
if (quit)
{
title = true;
Application.Quit();
return;
}
if (underway != null)
harbor.EndPassage();
passageAudio.End();
ClearActivePassage();
paused = fleetOpen = shipActionsOpen = false;
title = true;
Notify(null);
Render();
}
private void OnApplicationQuit()
{
if (!autoSmoke && !title && company != null)
Save();
}
private void OpenCareerMenu(CareerMenu menu)
{
careerError = null;
careerMenu = menu;
careerNameDraft = menu == CareerMenu.SaveAs ? AvailableCareerName(careerName + " copy") : "";
Render();
}
private void CloseCareerMenu()
{
careerError = null;
careerMenu = CareerMenu.Closed;
Render();
}
private string AvailableCareerName(string preferred)
{
var saves = careers.List();
string stem = preferred.Length <= 35 ? preferred : preferred.Substring(0, 35).TrimEnd();
string name = stem;
for (int copy = 2; HasCareerName(saves, name); copy++)
name = $"{stem} {copy}";
return name;
}
private static bool HasCareerName(List<CareerSave> saves, string name) =>
saves.Exists(save => string.Equals(save.Name, name, StringComparison.OrdinalIgnoreCase));
private bool CheckCareerName(out string name)
{
name = careerNameDraft?.Trim() ?? "";
if (name.Length == 0)
careerError = "Give the save a name.";
else if (HasCareerName(careers.List(), name))
careerError = "A save with that name already exists.";
else
return true;
Render();
return false;
}
private void StartNamedCareer()
{
if (pendingStart.HasValue && CheckCareerName(out string name))
StartCompany(pendingStart.Value, name);
}
private void SaveCareerCopy()
{
if (!CheckCareerName(out string name))
return;
if (WriteCareer(name))
{
careerMenu = CareerMenu.Closed;
Notify($"Created {careerName}.");
}
Render();
}
private TextField CareerNameField(VisualElement parent)
{
var name = new TextField("Save name") { name = "career-save-name", value = careerNameDraft, maxLength = 40 };
name.AddToClassList("career-save-name");
name.RegisterValueChangedCallback(change => careerNameDraft = change.newValue);
parent.Add(name);
return name;
}
private void DrawCareerMenu()
{
for (int i = 0; i < root.childCount; i++)
root[i].SetEnabled(false);
var overlay = Add(root, "career-save-overlay");
var menu = Add(overlay, "career-save-sheet");
menu.name = "career-save-sheet";
var header = Add(menu, "career-save-header");
AddDisplay(header, careerMenu == CareerMenu.Load ? "Load game" : "Save as", "career-save-title");
Button close = Action("Close Esc", CloseCareerMenu, "career-save-close", "career-save-close");
header.Add(close);
if (!string.IsNullOrEmpty(careerError))
AddText(menu, careerError, "career-save-error");
if (careerMenu == CareerMenu.SaveAs)
{
TextField name = CareerNameField(menu);
menu.Add(Action("Create save", SaveCareerCopy, "primary career-save-confirm", "career-save-confirm"));
name.schedule.Execute(() => name.Focus());
return;
}
List<CareerSave> saves = careers.List();
if (legacyCareer != null && !saves.Exists(saved => saved.Id == legacyCareer.Id))
saves.Add(legacyCareer);
if (saves.Count == 0)
{
AddText(menu, "No saved careers yet.", "career-save-detail");
close.schedule.Execute(() => close.Focus());
return;
}
var list = new ScrollView(ScrollViewMode.Vertical) { name = "career-save-list" };
list.AddToClassList("career-save-list");
menu.Add(list);
for (int i = 0; i < saves.Count; i++)
{
CareerSave save = saves[i];
int sailing = save.Passages?.Length ?? 0;
Button row = Action("", () => LoadCareer(save.Id), "career-save-row", $"career-load-{i}");
row.EnableInClassList("career-save-current", save.Id == careerId);
AddText(row, save.Name, "career-save-label");
AddText(row, $"Day {save.Company.Day} · {save.Company.Fleet?.Count ?? 0} ships · {sailing} underway", "career-save-detail");
list.Add(row);
if (i == 0)
row.schedule.Execute(() => row.Focus());
}
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: ddc7e3938e8c062669e679eac3d7d696

View File

@@ -0,0 +1,128 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using UnityEngine;
namespace Soundings
{
[Serializable]
internal sealed class CareerSave
{
public int Version = 1;
public string Id, Name;
public long SavedUtc;
public int Page, DeckIndex;
public Company Company;
public FleetPassageSnapshot[] Passages;
}
internal sealed class CareerStore
{
private readonly string directory;
internal CareerStore(string directory) => this.directory = directory;
internal string RecentId
{
get
{
string path = Path.Combine(directory, "recent");
try { return File.Exists(path) ? File.ReadAllText(path) : null; }
catch (Exception error) when (IsFileError(error)) { return null; }
}
}
internal List<CareerSave> List()
{
var result = new List<CareerSave>();
if (!Directory.Exists(directory))
return result;
try
{
foreach (string file in Directory.GetFiles(directory, "*.json"))
{
CareerSave saved = Read(Path.GetFileNameWithoutExtension(file));
if (saved != null)
result.Add(saved);
}
}
catch (Exception error) when (IsFileError(error))
{
Debug.LogWarning("Could not list careers. " + error.Message);
}
result.Sort((a, b) => b.SavedUtc.CompareTo(a.SavedUtc));
return result;
}
internal CareerSave Read(string id)
{
if (!Guid.TryParseExact(id, "N", out _))
return null;
try
{
string path = Path.Combine(directory, id + ".json");
if (!File.Exists(path))
return null;
CareerSave saved = JsonUtility.FromJson<CareerSave>(File.ReadAllText(path));
return saved is { Version: 1, Company: not null } && saved.Id == id && !string.IsNullOrWhiteSpace(saved.Name)
? saved : null;
}
catch (Exception error) when (IsFileError(error) || error is ArgumentException)
{
Debug.LogWarning("Could not read a career. " + error.Message);
return null;
}
}
internal bool Write(CareerSave saved)
{
try
{
Directory.CreateDirectory(directory);
ReplaceFile(Path.Combine(directory, saved.Id + ".json"), JsonUtility.ToJson(saved));
}
catch (Exception error) when (IsFileError(error))
{
Debug.LogWarning("Could not write a career. " + error.Message);
return false;
}
Select(saved.Id);
return true;
}
internal void Select(string id)
{
try { ReplaceFile(Path.Combine(directory, "recent"), id); }
catch (Exception error) when (IsFileError(error))
{
Debug.LogWarning("Could not set the most recent career. " + error.Message);
}
}
private static void ReplaceFile(string path, string contents)
{
string temporary = path + "." + Guid.NewGuid().ToString("N") + ".tmp";
try
{
using (var file = new FileStream(temporary, FileMode.Create, FileAccess.Write, FileShare.None))
{
byte[] bytes = Encoding.UTF8.GetBytes(contents);
file.Write(bytes, 0, bytes.Length);
file.Flush(true);
}
if (File.Exists(path))
File.Replace(temporary, path, null);
else
File.Move(temporary, path);
}
finally
{
if (File.Exists(temporary))
File.Delete(temporary);
}
}
private static bool IsFileError(Exception error) => error is IOException or UnauthorizedAccessException;
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 85c3f73a7578c37c8b6aec2d085a840d

View File

@@ -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;
}

View File

@@ -1,3 +1,5 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
@@ -8,8 +10,18 @@ namespace Soundings
private static readonly (int HullIndex, bool Used)[] Offers =
{ (0, true), (0, false), (1, true), (1, false), (2, false) };
private enum DeckTools { GuestFacilities, LargerVenues, ShipSystems }
private enum DeckTools { GuestFacilities, LargerVenues, LeisureAndRetail, ShipSystems }
private DeckTools deckTools;
private int toolRotation;
private Action refreshDeckPlacement;
private static readonly Facility[] GuestTools = { Facility.Cabin, Facility.Dining, Facility.Entertainment,
Facility.Tank, Facility.Bar, Facility.Amenity, Facility.Empty };
private static readonly Facility[] ExpandedTools = { Facility.Suite, Facility.GrandSuite, Facility.Restaurant,
Facility.GrandTheater, Facility.ResortPool, Facility.CocktailLounge, Facility.Empty };
private static readonly Facility[] LeisureTools = { Facility.Shop, Facility.ShoppingArcade, Facility.Spa, Facility.WaterPark, Facility.Empty };
private static readonly Facility[] SystemsTools = { Facility.Galley, Facility.Stores, Facility.Water,
Facility.Waste, Facility.Workshop, Facility.Empty };
private static readonly Color DraftGrid = new Color(.37f, .62f, .65f, .19f);
private static readonly Color DraftFine = new Color(.47f, .75f, .74f, .42f);
@@ -72,9 +84,9 @@ namespace Soundings
var layout = Add(board, "work-berth-grid");
var placement = Add(board, "work-placement");
var placementLabel = AddText(placement, PlacementInstruction(ship, tool), "work-placement-text");
var placementLabel = AddText(placement, PlacementInstruction(ship, tool, toolRotation), "work-placement-text");
placementLabel.name = "berth-placement";
DrawBerthGrid(layout, placementLabel, ship);
refreshDeckPlacement = DrawBerthGrid(layout, placementLabel, ship);
var fittings = Add(work, "work-fittings");
var gauges = Add(fittings, "work-capacity-strip");
@@ -91,10 +103,13 @@ namespace Soundings
AddText(gauges, rooms, "work-capacity");
AddText(gauges, $"{ship.Meals:N0} meal covers", "work-capacity");
AddText(gauges, $"{ship.Entertainment:N0} show seats", "work-capacity");
if (deckTools == DeckTools.LargerVenues)
if (deckTools == DeckTools.LargerVenues || deckTools == DeckTools.LeisureAndRetail)
{
AddText(gauges, $"{ship.PoolCapacity:N0} pool admissions", "work-capacity");
AddText(gauges, $"{ship.BarCapacity:N0} drink orders", "work-capacity");
AddText(gauges, $"{ship.PoolCapacity:N0} amenity admissions", "work-capacity");
if (deckTools == DeckTools.LeisureAndRetail)
AddText(gauges, $"{ship.RetailCapacity:N0} retail orders", "work-capacity");
else
AddText(gauges, $"{ship.BarCapacity:N0} drink orders", "work-capacity");
}
else
AddText(gauges, $"{ship.Tank:N0} t bunker capacity", "work-capacity");
@@ -104,21 +119,32 @@ namespace Soundings
var toolMode = Add(fittings, "work-fit-modes");
AddBuildToolTab(toolMode, "Guest facilities", "facility-guests", DeckTools.GuestFacilities, Facility.Cabin);
AddBuildToolTab(toolMode, "Larger venues", "facility-larger", DeckTools.LargerVenues, Facility.Suite);
AddBuildToolTab(toolMode, "Leisure & retail", "facility-leisure", DeckTools.LeisureAndRetail, Facility.Shop);
AddBuildToolTab(toolMode, "Ship systems", "facility-systems", DeckTools.ShipSystems, Facility.Galley);
FacilitySpec selectedSpec = Market.Facilities[(int)tool];
if (selectedSpec.BayCount > 1)
{
Button rotate = Action("Rotate R", RotateDeckTool, "work-tool-rotate", "facility-rotate");
rotate.tooltip = "Turn the selected fitting clockwise by 90°";
toolMode.Add(rotate);
AddText(toolMode, RotationLabel(selectedSpec), "work-tool-orientation").name = "facility-orientation";
}
var tools = Add(fittings, "work-tool-tray");
var (start, end) = deckTools switch
Facility[] options = deckTools switch
{
DeckTools.LargerVenues => (Facility.Suite, Facility.Extension),
DeckTools.ShipSystems => (Facility.Galley, Facility.Suite),
_ => (Facility.Cabin, Facility.Galley)
DeckTools.LargerVenues => ExpandedTools,
DeckTools.LeisureAndRetail => LeisureTools,
DeckTools.ShipSystems => SystemsTools,
_ => GuestTools
};
for (int i = (int)start; i <= (int)end; i++)
foreach (Facility option in options)
{
Facility option = i == (int)end ? Facility.Empty : (Facility)i;
FacilitySpec spec = Market.Facilities[(int)option];
bool locked = ship.HullIndex < spec.MinimumHull;
Button button = Action("", () =>
{
if (tool != option)
toolRotation = 0;
tool = option;
Notify(null);
Render();
@@ -131,9 +157,9 @@ namespace Soundings
copy.pickingMode = PickingMode.Ignore;
AddText(copy, spec.Name, "work-tool-name");
string price = option == Facility.Empty ? "25% refund" : Money(spec.Price);
if (spec.Length > 1)
if (spec.BayCount > 1)
{
price = $"{spec.Length} bays · {price}";
price = $"{FootprintLabel(spec, 0)} · {price}";
button.AddToClassList("work-tool-larger");
}
AddText(copy, price, "work-tool-cost");
@@ -143,11 +169,12 @@ namespace Soundings
}
}
private void DrawBerthGrid(VisualElement layout, Label instruction, Ship ship)
private Action DrawBerthGrid(VisualElement layout, Label instruction, Ship ship)
{
Deck deck = ship.Decks[deckIndex];
int columns = ship.Hull.Columns;
var berths = new Button[deck.Cells.Length];
var strips = new VisualElement[ship.Hull.Rows];
int hovered = -1, focused = -1;
void UpdatePreview()
@@ -160,24 +187,26 @@ namespace Soundings
}
if (selected < 0)
{
instruction.text = PlacementInstruction(ship, tool);
instruction.text = PlacementInstruction(ship, tool, toolRotation);
return;
}
Facility room = deck.FacilityAt(selected, columns);
int anchor = room == Facility.Empty ? selected : deck.AnchorAt(selected, columns);
Facility sizeOf = room == Facility.Empty ? tool : room;
int span = Market.Facilities[(int)sizeOf].Length;
string blocked = PlacementBlock(ship, selected, room);
instruction.text = BerthDescription(deck, columns, selected, room, tool, blocked);
int rowEnd = (anchor / columns + 1) * columns;
for (int i = anchor; i < Mathf.Min(rowEnd, anchor + span); i++)
berths[i].AddToClassList(blocked == null ? "work-berth-preview" : "work-berth-blocked");
bool planning = room == Facility.Empty || room == tool;
FacilitySpec spec = Market.Facilities[(int)(planning ? tool : room)];
int rotation = planning ? toolRotation : deck.RotationAt(anchor);
string blocked = PlacementBlock(ship, selected);
instruction.text = BerthDescription(deck, columns, selected, room, tool, toolRotation, blocked);
foreach (Vector2Int offset in spec.Footprint(rotation))
if (deck.TryCellAt(anchor, columns, offset, out int bay))
berths[bay].AddToClassList(blocked == null ? "work-berth-preview" : "work-berth-blocked");
}
for (int row = 0; row < ship.Hull.Rows; row++)
{
var strip = Add(layout, "work-berth-row");
strips[row] = strip;
for (int column = 0; column < columns; column++)
{
int cell = row * columns + column;
@@ -188,8 +217,6 @@ namespace Soundings
Button berth = Action("", () => BuildAtBerth(ship, deck, cell), "work-berth work-room-" + (int)existing, "berth-" + cell);
berths[cell] = berth;
slot.Add(berth);
string blocked = PlacementBlock(ship, cell, existing);
berth.tooltip = BerthDescription(deck, columns, cell, existing, tool, blocked);
berth.RegisterCallback<PointerEnterEvent>(_ => { hovered = cell; UpdatePreview(); });
berth.RegisterCallback<PointerLeaveEvent>(_ => { hovered = -1; UpdatePreview(); });
berth.RegisterCallback<FocusInEvent>(_ => { focused = cell; UpdatePreview(); });
@@ -197,36 +224,67 @@ namespace Soundings
AddText(berth, BerthName(cell, columns), "work-berth-index");
if (existing == Facility.Empty)
AddText(berth, "+", "work-berth-open");
else if (room.Length == 1)
else if (room.BayCount == 1)
AddVenueLabel(berth, existing);
else
{
berth.EnableInClassList("work-berth-join-left", anchor < cell);
berth.EnableInClassList("work-berth-join-right", anchor + room.Length - 1 > cell);
berth.EnableInClassList("work-berth-join-left", column > 0 && SameVenue(cell - 1));
berth.EnableInClassList("work-berth-join-right", column + 1 < columns && SameVenue(cell + 1));
berth.EnableInClassList("work-berth-join-top", row > 0 && SameVenue(cell - columns));
berth.EnableInClassList("work-berth-join-bottom", row + 1 < ship.Hull.Rows && SameVenue(cell + columns));
}
bool SameVenue(int other) => deck.AnchorAt(other, columns) == anchor;
}
}
for (int column = 0; column < columns; column++)
for (int anchor = 0; anchor < deck.Cells.Length; anchor++)
{
Facility room = deck.Cells[anchor];
FacilitySpec spec = Market.Facilities[(int)room];
if (spec.BayCount <= 1)
continue;
var (row, start, span) = CaptionRow(spec.Footprint(deck.RotationAt(anchor)));
var label = Add(strips[anchor / columns + row], "work-span-caption");
label.pickingMode = PickingMode.Ignore;
label.style.left = Length.Percent(100f * (anchor % columns + start) / columns);
label.style.width = Length.Percent(100f * span / columns);
AddVenueLabel(label, room);
}
Refresh();
return Refresh;
void Refresh()
{
for (int cell = 0; cell < berths.Length; cell++)
{
Facility room = deck.Cells[row * columns + column];
int span = Market.Facilities[(int)room].Length;
if (span <= 1)
continue;
var label = Add(strip, "work-span-caption");
label.pickingMode = PickingMode.Ignore;
label.style.left = Length.Percent(100f * column / columns);
label.style.width = Length.Percent(100f * span / columns);
AddVenueLabel(label, room);
Facility room = deck.FacilityAt(cell, columns);
berths[cell].tooltip = BerthDescription(deck, columns, cell, room, tool, toolRotation,
PlacementBlock(ship, cell));
}
UpdatePreview();
}
}
private string PlacementBlock(Ship ship, int cell, Facility existing)
private static (int Row, int First, int Span) CaptionRow(IReadOnlyList<Vector2Int> footprint)
{
(int row, int start, int span) = (0, 0, 1);
for (int first = 0; first < footprint.Count;)
{
int end = first + 1;
while (end < footprint.Count && footprint[end].y == footprint[first].y)
end++;
if (end - first > span)
(row, start, span) = (footprint[first].y, footprint[first].x, end - first);
first = end;
}
return (row, start, span);
}
private string PlacementBlock(Ship ship, int cell)
{
if (existing != Facility.Empty && tool != Facility.Empty)
return null;
FacilitySpec spec = Market.Facilities[(int)tool];
return ship.HullIndex < spec.MinimumHull ? VenueRequirement(spec) : company.BuildBlock(ship, deckIndex, cell, tool);
return ship.HullIndex < spec.MinimumHull ? VenueRequirement(spec) : company.BuildBlock(ship, deckIndex, cell, tool, toolRotation);
}
private void BuildAtBerth(Ship ship, Deck deck, int cell)
@@ -234,15 +292,18 @@ namespace Soundings
int columns = ship.Hull.Columns;
int anchor = deck.AnchorAt(cell, columns);
Facility previous = deck.FacilityAt(cell, columns);
string failure = company.Build(ship, deckIndex, cell, tool);
if (failure == null && previous != tool)
SetRecommendedFuel();
int oldRotation = deck.RotationAt(anchor);
FacilitySpec room = Market.Facilities[(int)(tool == Facility.Empty ? previous : tool)];
string area = BerthRange(tool == Facility.Empty ? anchor : cell, room.Length, columns);
int footprintRotation = tool == Facility.Empty ? oldRotation : toolRotation;
string area = BerthNames(deck, columns, previous == Facility.Empty ? cell : anchor, room.Footprint(footprintRotation));
string failure = company.Build(ship, deckIndex, cell, tool, toolRotation);
bool turned = previous == tool && previous != Facility.Empty && oldRotation != deck.RotationAt(anchor);
if (failure == null && (previous != tool || turned))
SetRecommendedFuel();
string confirmation = tool == Facility.Empty
? $"Removed {room.Name.ToLowerInvariant()} from {area}."
: $"Built {room.Name.ToLowerInvariant()} at {area}.";
Apply(failure, previous == tool ? null : confirmation);
: $"{(turned ? "Rotated" : "Built")} {room.Name.ToLowerInvariant()} at {area}.";
Apply(failure, previous == tool && !turned ? null : confirmation);
}
private void AddBuildToolTab(VisualElement parent, string label, string id, DeckTools group, Facility initial)
@@ -253,6 +314,7 @@ namespace Soundings
return;
deckTools = group;
tool = initial;
toolRotation = 0;
Notify(null);
Render();
}, deckTools == group ? "work-selected" : "", id);
@@ -273,39 +335,74 @@ namespace Soundings
return $"Requires a {hull.Name} hull. Unlock the hull with {hull.Voyages} completed voyages and {hull.Reputation} reputation.";
}
private static string PlacementInstruction(Ship ship, Facility selected)
private string RotationLabel(FacilitySpec spec) => $"{FootprintLabel(spec, toolRotation)} · {toolRotation * 90}°";
private void RotateDeckTool()
{
FacilitySpec spec = Market.Facilities[(int)tool];
if (spec.BayCount <= 1 || root.Q<Label>("facility-orientation") is not Label orientation)
return;
toolRotation = (toolRotation + 1) & 3;
orientation.text = RotationLabel(spec);
refreshDeckPlacement?.Invoke();
}
private static string PlacementInstruction(Ship ship, Facility selected, int rotation)
{
FacilitySpec spec = Market.Facilities[(int)selected];
if (selected == Facility.Empty)
return "Select any bay in a fitted room to remove it and recover 25%.";
if (ship.HullIndex < spec.MinimumHull)
return VenueRequirement(spec);
string plan = spec.Length == 1 ? "Select an open bay" : $"Select the sternmost of {spec.Length} open bays in a row";
return $"{plan} to build {spec.Name.ToLowerInvariant()}. {spec.Details} · {Money(spec.Price)}";
string plan = spec.BayCount == 1 ? "Select an open bay" : $"Point at a bay to preview the {FootprintLabel(spec, rotation)} fitting";
return $"{plan}. {spec.Name} · {spec.Details} · {Money(spec.Price)}";
}
private static string BerthName(int cell, int columns) => $"{(char)('A' + cell / columns)}{cell % columns + 1}";
private static string BerthRange(int start, int span, int columns)
private static string FootprintLabel(FacilitySpec spec, int rotation)
{
int end = Mathf.Min(start + span - 1, (start / columns + 1) * columns - 1);
return end == start ? BerthName(start, columns) : $"{BerthName(start, columns)}–{BerthName(end, columns)}";
int left = 0, right = 0, depth = 1;
foreach (Vector2Int offset in spec.Footprint(rotation))
{
left = Mathf.Min(left, offset.x);
right = Mathf.Max(right, offset.x);
depth = Mathf.Max(depth, offset.y + 1);
}
int width = right - left + 1;
return spec.BayCount == width * depth ? $"{width}×{depth} bays" : $"L-shaped · {spec.BayCount} bays";
}
private static string BerthDescription(Deck deck, int columns, int cell, Facility room, Facility selected, string blocked)
private static string BerthNames(Deck deck, int columns, int anchor, IReadOnlyList<Vector2Int> footprint)
{
var names = new List<string>(footprint.Count);
foreach (Vector2Int offset in footprint)
if (deck.TryCellAt(anchor, columns, offset, out int bay))
names.Add(BerthName(bay, columns));
return string.Join(", ", names);
}
private static string BerthDescription(Deck deck, int columns, int cell, Facility room, Facility selected, int rotation, string blocked)
{
if (blocked != null)
return $"{BerthName(cell, columns)} · {blocked}";
FacilitySpec existing = Market.Facilities[(int)room];
if (blocked != null)
return room == Facility.Empty ? $"{BerthName(cell, columns)} · {blocked}"
: $"{BerthName(cell, columns)} · {existing.Name} · {blocked}";
if (room == Facility.Empty)
{
FacilitySpec fitting = Market.Facilities[(int)selected];
string location = BerthRange(cell, fitting.Length, columns);
string location = BerthNames(deck, columns, cell, fitting.Footprint(rotation));
return selected == Facility.Empty
? $"{location} is already clear."
: $"{location} · {fitting.Name} · {fitting.Details} · {Money(fitting.Price)}";
}
string area = BerthRange(deck.AnchorAt(cell, columns), existing.Length, columns);
int anchor = deck.AnchorAt(cell, columns);
if (selected == room && rotation != deck.RotationAt(anchor))
{
string newArea = BerthNames(deck, columns, anchor, existing.Footprint(rotation));
return $"{existing.Name} · Rotate to {rotation * 90}° across {newArea}";
}
string area = BerthNames(deck, columns, anchor, existing.Footprint(deck.RotationAt(anchor)));
return selected == Facility.Empty
? $"{area} · Remove {existing.Name.ToLowerInvariant()} and recover {Money(existing.Price / 4)}"
: $"{area} · {existing.Name} · {existing.Details}";
@@ -375,10 +472,23 @@ namespace Soundings
break;
case Facility.Amenity:
case Facility.ResortPool:
case Facility.WaterPark:
Segment(4,11,6,7,10,5,14,5,18,7,20,11,4,11);
Line(12,11,12,17);
Segment(3,19,6,17,9,19,12,17,15,19,18,17,21,19);
break;
case Facility.Spa:
Segment(4,13,20,13,18,18,6,18,4,13);
Segment(8,10,7,8,9,5,8,3);
Segment(12,10,11,8,13,5,12,3);
Segment(16,10,15,8,17,5,16,3);
break;
case Facility.Shop:
case Facility.ShoppingArcade:
Segment(5,8,19,8,21,20,3,20,5,8);
Segment(9,9,9,6,10,4,14,4,15,6,15,9);
Line(8,15,16,15);
break;
case Facility.Galley:
Segment(3,13,17,13,15,18,5,18,3,13);
Line(17,13,22,11);

View File

@@ -0,0 +1,251 @@
using UnityEngine;
namespace Soundings
{
internal sealed partial class DeckPassengers
{
private readonly struct DeckGrid
{
public readonly int Columns, Rows;
public readonly float Start, CellWidth, RowDepth, HalfWidth;
public DeckGrid(int columns, int rows, float start, float cellWidth, float rowDepth, float halfWidth)
{
Columns = columns;
Rows = rows;
Start = start;
CellWidth = cellWidth;
RowDepth = rowDepth;
HalfWidth = halfWidth;
}
public int Slot(int col, int row) => row * Columns + col;
public float Edge(int col) => Start + col * CellWidth;
public float Center(int col) => Edge(col) + CellWidth * .5f;
public float Row(int row) => -HalfWidth + (row + .5f) * RowDepth + row * AisleWidth;
public float Aisle(int row) => Row(row) + (RowDepth + AisleWidth) * .5f;
}
private void BuildDeckPlan(int index, Layout layout, Geometry structure, Geometry interior, Geometry cutaway,
DeckGrid grid, float aft, float fore, float floor)
{
Deck plan = ship.Decks[index];
var owners = new int[plan.Cells.Length];
for (int slot = 0; slot < owners.Length; slot++)
owners[slot] = plan.AnchorAt(slot, grid.Columns);
int Owner(int col, int row) => owners[grid.Slot(col, row)];
bool Linked(int col, int aisle) => col >= 0 && col < grid.Columns
&& aisle >= 0 && aisle < grid.Rows - 1 && Owner(col, aisle) == Owner(col, aisle + 1);
// Furnish only the anchor. The plan below supplies the floor and bulkheads for its whole footprint.
for (int anchor = 0; anchor < owners.Length; anchor++)
{
if (owners[anchor] != anchor)
continue;
Facility facility = plan.Cells[anchor];
var footprint = Market.Facilities[(int)facility].Footprint(plan.RotationAt(anchor));
int row = anchor / grid.Columns, column = anchor % grid.Columns;
if (footprint.Count == 1 && facility != Facility.Shop)
{
Vector3 center = new(grid.Center(column), floor + .055f, grid.Row(row));
Room(structure, layout, facility, center, grid.CellWidth - .19f, grid.RowDepth - .18f,
index * 70 + anchor, row == 0 ? -1 : 1, index == programDeck && anchor == programRoom);
continue;
}
foreach (Vector2Int bay in footprint)
structure.Box(FacilityFloor(facility), new Vector3(grid.Center(column + bay.x), floor + .037f, grid.Row(row + bay.y)),
new Vector3(grid.CellWidth, .045f, grid.RowDepth));
FurnishFootprint(index, anchor, plan.RotationAt(anchor), footprint, facility, layout, structure, grid, floor);
}
for (int row = 0; row < grid.Rows; row++)
{
float z = grid.Row(row);
for (int col = 0; col <= grid.Columns; col++)
{
if (col == 0 || col == grid.Columns || Owner(col - 1, row) != Owner(col, row))
SolidDeckWall(layout, interior, cutaway, new Vector3(grid.Edge(col), floor, z), .15f, grid.RowDepth);
}
for (int side = -1; side <= 1; side += 2)
{
float wallZ = z + side * grid.RowDepth * .5f;
if (side < 0 && row == 0 || side > 0 && row == grid.Rows - 1)
{
for (int col = 0; col < grid.Columns; col++)
RoomWindow(interior, cutaway, grid.Center(col), floor, wallZ, grid.CellWidth, side,
IsGlazed(plan.Cells[Owner(col, row)]));
continue;
}
int aisle = side < 0 ? row - 1 : row;
for (int start = 0; start < grid.Columns;)
{
int owner = Owner(start, row);
int end = start + 1;
bool joined = Linked(start, aisle);
while (end < grid.Columns && Owner(end, row) == owner && Linked(end, aisle) == joined)
end++;
if (!joined)
{
Facility facility = plan.Cells[owner];
float width = (end - start) * grid.CellWidth;
float door = facility switch
{
Facility.Empty => 2.4f,
Facility.Cabin => 1.18f,
Facility.Suite or Facility.GrandSuite => 1.56f,
_ => end - start > 1 ? 2.20f : 1.48f
};
RoomEntrance(layout, interior, cutaway, (grid.Edge(start) + grid.Edge(end)) * .5f, floor,
wallZ, width, Mathf.Min(door, width - .42f), side, index, owner, facility);
}
start = end;
}
}
}
for (int aisle = 0; aisle < grid.Rows - 1; aisle++)
{
float z = grid.Aisle(aisle);
float publicStart = aft;
for (int col = 0; col <= grid.Columns; col++)
{
bool openLeft = Linked(col - 1, aisle), openRight = Linked(col, aisle);
if (openLeft != openRight || openLeft && Owner(col - 1, aisle) != Owner(col, aisle))
CrossAisleBoundary(layout, interior, cutaway, grid.Edge(col), floor, z,
openLeft ? plan.Cells[Owner(col - 1, aisle)] : Facility.Empty,
openRight ? plan.Cells[Owner(col, aisle)] : Facility.Empty);
if (!openLeft && openRight)
PublicAisle(index, aisle, publicStart, grid.Edge(col), floor, z, grid.CellWidth, layout, structure, interior);
if (openLeft && !openRight)
publicStart = grid.Edge(col);
if (openRight)
structure.Box(FacilityFloor(plan.Cells[Owner(col, aisle)]), new Vector3(grid.Center(col), floor + .037f, z),
new Vector3(grid.CellWidth, .045f, AisleWidth));
}
PublicAisle(index, aisle, publicStart, fore, floor, z, grid.CellWidth, layout, structure, interior);
}
}
private void FurnishFootprint(int index, int anchor, int rotation, System.Collections.Generic.IReadOnlyList<Vector2Int> footprint,
Facility facility, Layout layout, Geometry structure, DeckGrid grid, float floor)
{
int col = anchor % grid.Columns, row = anchor / grid.Columns;
Vector2Int min = footprint[0], max = min;
foreach (Vector2Int offset in footprint)
{
min = Vector2Int.Min(min, offset);
max = Vector2Int.Max(max, offset);
}
int seed = index * 70 + anchor;
if (facility == Facility.ShoppingArcade)
{
FitRetailArcade(structure, layout, grid, footprint, col, row, floor, rotation, seed);
return;
}
Vector3 center = new((grid.Center(col + min.x) + grid.Center(col + max.x)) * .5f, floor + .06f,
(grid.Row(row + min.y) + grid.Row(row + max.y)) * .5f);
float width = (max.x - min.x + 1) * grid.CellWidth - .19f;
float depth = (max.y - min.y + 1) * grid.RowDepth + (max.y - min.y) * AisleWidth - .18f;
if ((rotation & 1) != 0)
(width, depth) = (depth, width);
var room = new Venue(structure, layout, center, row == 0 ? -1 : 1, seed, rotation);
if (facility is Facility.Shop or Facility.Spa or Facility.WaterPark)
FitNewVenue(room, facility, width, depth);
else
{
StationKind? station = FacilityStation(facility);
if (station.HasValue)
room.Station(station.Value, 0, -depth * .33f);
FitVenue(room, facility, width, depth, index == programDeck && anchor == programRoom);
}
}
private static void CrossAisleBoundary(Layout layout, Geometry interior, Geometry cutaway, float x, float floor, float z,
Facility left, Facility right)
{
const float opening = 1.28f;
float panel = (AisleWidth - opening) * .5f;
for (int side = -1; side <= 1; side += 2)
{
SolidDeckWall(layout, interior, cutaway, new Vector3(x, floor, z + side * (opening + panel) * .5f), .14f, panel);
interior.Box(Joinery, new Vector3(x, floor + 1.02f, z + side * opening * .5f), new Vector3(.165f, 2.04f, .05f));
}
interior.Box(Joinery, new Vector3(x, floor + 2.07f, z), new Vector3(.17f, .08f, opening));
interior.Box(Bulkhead, new Vector3(x, floor + 2.25f, z), new Vector3(.14f, .36f, opening));
interior.Box(Alloy, new Vector3(x, floor + .058f, z), new Vector3(.22f, .020f, opening));
if (left != Facility.Empty)
DirectionSign(left, 1);
if (right != Facility.Empty)
DirectionSign(right, -1);
void DirectionSign(Facility facility, int side)
{
interior.Box(DeckTrim, new Vector3(x + side * .09f, floor + 2.21f, z), new Vector3(.035f, .132f, .97f));
PlaceSign(layout.Interior.transform, Market.Facilities[(int)facility].Name.ToUpperInvariant(),
new Vector3(x + side * .112f, floor + 2.21f, z), -side * 90, .047f);
}
}
private static void PublicAisle(int index, int aisle, float start, float end, float floor, float z, float bay,
Layout layout, Geometry structure, Geometry interior)
{
float length = end - start;
float mid = (end + start) * .5f;
structure.Box(DeckTrim, new Vector3(mid, floor + .037f, z), new Vector3(length, .018f, AisleWidth - .21f));
for (int side = -1; side <= 1; side += 2)
{
structure.Box(Joinery, new Vector3(mid, floor + .049f, z + side * .615f), new Vector3(length, .008f, .025f));
interior.Box(DeckTrim, new Vector3(mid, floor + DeckCeiling - .083f, z + side * .60f), new Vector3(length, .12f, .028f));
}
int lights = Mathf.Max(1, Mathf.RoundToInt(length / bay));
for (int i = 0; i < lights; i++)
{
float x = Mathf.Lerp(start, end, (i + .5f) / lights);
interior.Box(Gasket, new Vector3(x, floor + DeckCeiling - .009f, z), new Vector3(Mathf.Min(2.22f, length), .045f, .43f));
interior.Box(LightStrip, new Vector3(x, floor + DeckCeiling - .031f, z), new Vector3(Mathf.Min(2.04f, length), .018f, .28f));
structure.Box(Joinery, new Vector3(x, floor + .048f, z), new Vector3(.035f, .009f, 1.23f));
}
if (length < 5f)
return;
int walkers = Mathf.Max(1, lights / 2);
for (int i = 0; i < walkers; i++)
{
var route = new Vector3(start + 1.35f, floor + .055f, z);
layout.People.Add(new DeckGuest(route, end - 1.2f, .37f, (i + .29f * aisle) / walkers,
index * 53 + aisle * 17 + i * 11, .19f + i * .14f));
}
}
private static bool IsGlazed(Facility facility) => facility is Facility.Cabin or Facility.Dining or Facility.Bar or Facility.Amenity
or Facility.Suite or Facility.GrandSuite or Facility.Restaurant or Facility.ResortPool or Facility.CocktailLounge
or Facility.Shop or Facility.ShoppingArcade or Facility.Spa or Facility.WaterPark;
private static int FacilityFloor(Facility facility) => facility switch
{
Facility.Cabin => Carpet, Facility.Dining or Facility.Restaurant => Joinery,
Facility.Entertainment or Facility.GrandTheater => 11, Facility.Bar or Facility.CocktailLounge => 7,
Facility.Suite or Facility.GrandSuite => SuiteCarpet, Facility.ResortPool or Facility.Spa or Facility.WaterPark => PoolDeck,
Facility.Shop or Facility.ShoppingArcade => Marble,
Facility.Amenity => Alloy, Facility.Galley or Facility.Workshop => BridgeFloor, _ => DeckTrim
};
private static StationKind? FacilityStation(Facility facility) => facility switch
{
Facility.Cabin or Facility.Suite or Facility.GrandSuite => StationKind.Cabins,
Facility.Dining or Facility.Restaurant => StationKind.Dining,
Facility.Bar or Facility.CocktailLounge => StationKind.Bar,
Facility.Entertainment or Facility.GrandTheater => StationKind.Stage,
Facility.Amenity or Facility.ResortPool or Facility.Spa or Facility.WaterPark => StationKind.Pool,
Facility.Galley => StationKind.Galley, Facility.Stores => StationKind.Stores,
Facility.Water => StationKind.Water, Facility.Waste => StationKind.Waste,
Facility.Workshop => StationKind.Maintenance,
Facility.Shop or Facility.ShoppingArcade => StationKind.Retail,
_ => null
};
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: eec517e457aa4b3ab4d7a536d546bc5d

View File

@@ -343,8 +343,6 @@ namespace Soundings
float roomStart = aft + endCrossing;
int columns = ship.Hull.Columns, rows = ship.Hull.Rows;
float rowDepth = (halfWidth * 2 - (rows - 1) * AisleWidth) / rows;
float RowCenter(int row) => -halfWidth + (row + .5f) * rowDepth + row * AisleWidth;
float AisleCenter(int aisle) => RowCenter(aisle) + (rowDepth + AisleWidth) * .5f;
float cellWidth = (usableLength - endCrossing * 2) / columns;
float mid = (fore + aft) * .5f;
structure.Box(Carpet, new Vector3(mid, y + .020f, 0), new Vector3(usableLength, .028f, halfWidth * 2));
@@ -357,82 +355,8 @@ namespace Soundings
DeckWall(interior, cutaway, new Vector3(side < 0 ? aft : fore, y, 0), .14f, halfWidth * 2);
}
for (int aisle = 0; aisle < rows - 1; aisle++)
{
float z = AisleCenter(aisle);
structure.Box(DeckTrim, new Vector3(mid, y + .037f, z), new Vector3(usableLength, .018f, AisleWidth - .21f));
for (int side = -1; side <= 1; side += 2)
{
structure.Box(Joinery, new Vector3(mid, y + .049f, z + side * .615f), new Vector3(usableLength, .008f, .025f));
interior.Box(DeckTrim, new Vector3(mid, y + DeckCeiling - .083f, z + side * .60f), new Vector3(usableLength, .12f, .028f));
}
for (int col = 0; col < columns; col++)
{
float x = roomStart + (col + .5f) * cellWidth;
interior.Box(Gasket, new Vector3(x, y + DeckCeiling - .009f, z), new Vector3(2.22f, .045f, .43f));
interior.Box(LightStrip, new Vector3(x, y + DeckCeiling - .031f, z), new Vector3(2.04f, .018f, .28f));
structure.Box(Joinery, new Vector3(x, y + .048f, z), new Vector3(.035f, .009f, 1.23f));
}
}
Deck plan = ship.Decks[index];
for (int col = 0; col < columns; col++)
{
for (int row = 0; row < rows; row++)
{
int slot = row * columns + col;
Facility facility = plan.Cells[slot];
if (facility == Facility.Extension)
continue;
int span = Market.Facilities[(int)facility].Length;
float roomWidth = span * cellWidth;
float x = roomStart + (col + span * .5f) * cellWidth;
var center = new Vector3(x, y + .055f, RowCenter(row));
float halfRow = rowDepth * .5f;
float door = facility switch
{
Facility.Empty => Mathf.Min(2.4f, cellWidth - .6f),
Facility.Cabin => 1.18f,
Facility.Suite or Facility.GrandSuite => 1.56f,
_ => span > 1 ? 2.20f : 1.48f
};
if (col == 0)
SolidDeckWall(layout, interior, cutaway, new Vector3(x - roomWidth * .5f, y, center.z), .15f, rowDepth);
SolidDeckWall(layout, interior, cutaway, new Vector3(x + roomWidth * .5f, y, center.z), .15f, rowDepth);
if (row > 0)
RoomEntrance(layout, interior, cutaway, x, y, center.z - halfRow, roomWidth, door, -1, index, slot, facility);
if (row < rows - 1)
{
if (span == 1 || row == 0)
RoomEntrance(layout, interior, cutaway, x, y, center.z + halfRow, roomWidth, door, 1, index, slot, facility);
else
SolidDeckWall(layout, interior, cutaway, new Vector3(x, y, center.z + halfRow), roomWidth, .15f);
}
Room(structure, layout, facility, center, roomWidth - .19f, rowDepth - .18f, index * 70 + slot,
row == 0 ? -1 : 1, index == programDeck && slot == programRoom);
if (row == 0 || row == rows - 1)
{
int side = row == 0 ? -1 : 1;
bool glazed = facility is Facility.Cabin or Facility.Dining or Facility.Bar or Facility.Amenity
or Facility.Suite or Facility.GrandSuite or Facility.Restaurant or Facility.ResortPool or Facility.CocktailLounge;
for (int bay = 0; bay < span; bay++)
RoomWindow(interior, cutaway, x - roomWidth * .5f + (bay + .5f) * cellWidth, y, halfWidth * side, cellWidth, side, glazed);
}
}
}
for (int aisle = 0; aisle < rows - 1; aisle++)
{
int walkers = columns / 2;
for (int walker = 0; walker < walkers; walker++)
{
float start = (walker + .29f * aisle) / walkers;
var route = new Vector3(aft + 1.35f, y + .055f, AisleCenter(aisle));
layout.People.Add(new DeckGuest(route, fore - 1.2f, .37f, start,
index * 53 + aisle * 17 + walker * 11, .19f + walker * .14f));
}
}
var grid = new DeckGrid(columns, rows, roomStart, cellWidth, rowDepth, halfWidth);
BuildDeckPlan(index, layout, structure, interior, cutaway, grid, aft, fore, y);
structure.Finish();
interior.Finish();
cutaway.Finish();
@@ -524,13 +448,7 @@ namespace Soundings
private void Room(Geometry shape, Layout layout, Facility facility, Vector3 pos, float width, float depth,
int seed, int facing, bool programVenue)
{
int floor = facility switch
{
Facility.Cabin => Carpet, Facility.Dining or Facility.Restaurant => Joinery,
Facility.Entertainment or Facility.GrandTheater => 11, Facility.Bar or Facility.CocktailLounge => 7,
Facility.Suite or Facility.GrandSuite => SuiteCarpet, Facility.ResortPool => PoolDeck,
Facility.Amenity => Alloy, Facility.Galley or Facility.Workshop => BridgeFloor, _ => DeckTrim
};
int floor = FacilityFloor(facility);
void Box(int color, float x, float y, float z, float w, float height, float d)
=> shape.Box(color, pos + new Vector3(x, y, z * facing), new Vector3(w, height, d));
void Solid(int color, float x, float y, float z, float w, float h, float d)
@@ -556,29 +474,10 @@ namespace Soundings
if (facility == Facility.Empty)
return;
StationKind? station = facility switch
{
Facility.Cabin or Facility.Suite or Facility.GrandSuite => StationKind.Cabins,
Facility.Dining or Facility.Restaurant => StationKind.Dining,
Facility.Bar or Facility.CocktailLounge => StationKind.Bar,
Facility.Entertainment or Facility.GrandTheater => StationKind.Stage,
Facility.Amenity or Facility.ResortPool => StationKind.Pool,
Facility.Galley => StationKind.Galley,
Facility.Stores => StationKind.Stores,
Facility.Water => StationKind.Water,
Facility.Waste => StationKind.Waste,
Facility.Workshop => StationKind.Maintenance,
_ => null
};
StationKind? station = FacilityStation(facility);
if (station.HasValue)
layout.Stations.Add(new ShipStation(station.Value, pos + new Vector3(0, 1.45f, -.33f * depth * facing)));
if (Market.Facilities[(int)facility].Length > 1)
{
FitVenue(new Venue(shape, layout, pos, facing, seed), facility, width, depth, programVenue);
return;
}
switch (facility)
{
case Facility.Cabin:

View File

@@ -226,30 +226,188 @@ namespace Soundings
}
}
private static void FitRetailArcade(Geometry shape, Layout layout, DeckGrid grid,
System.Collections.Generic.IReadOnlyList<Vector2Int> footprint, int col, int row, float floor, int rotation, int seed)
{
for (int i = 0; i < footprint.Count; i++)
{
Vector2Int offset = footprint[i];
int bayRow = row + offset.y;
var center = new Vector3(grid.Center(col + offset.x), floor + .06f, grid.Row(bayRow));
float width = grid.CellWidth - .19f, depth = grid.RowDepth - .18f;
if ((rotation & 1) != 0)
(width, depth) = (depth, width);
var wing = new Venue(shape, layout, center, bayRow == 0 ? -1 : 1, seed + i * 13, rotation);
FitRetail(wing, width, depth, offset == Vector2Int.zero, i);
}
}
private static void FitNewVenue(Venue room, Facility facility, float width, float depth)
{
if (facility == Facility.Shop)
FitRetail(room, width, depth, true, 0);
else
FitWellness(room, width, depth, facility == Facility.WaterPark);
}
private static void FitRetail(Venue room, float width, float depth, bool checkout, int selection)
{
float displayX = width * .235f;
float displayZ = depth * .30f;
float shelfWidth = Mathf.Min(width * .29f, 2.36f);
float shelfDepth = Mathf.Min(.40f, depth * .115f);
room.Box(Carpet, 0, .012f, -depth * .08f, width * .89f, .023f, depth * .50f);
room.Box(Brass, 0, .024f, -depth * .335f, width * .89f, .015f, .034f);
room.Solid(Joinery, displayX, .21f, displayZ, shelfWidth, .42f, shelfDepth);
room.Solid(Joinery, displayX, 1.11f, displayZ + shelfDepth * .41f, shelfWidth, 1.42f, .079f);
room.Box(Brass, displayX, 1.846f, displayZ, shelfWidth + .07f, .055f, shelfDepth + .047f);
room.Box(LightStrip, displayX, 1.791f, displayZ - shelfDepth * .41f, shelfWidth * .96f, .024f, .06f);
for (int level = 0; level < 3; level++)
{
float y = .49f + level * .42f;
room.Solid(Ivory, displayX, y, displayZ, shelfWidth + .07f, .055f, shelfDepth + .035f);
for (int item = 0; item < 4; item++)
{
float x = displayX + (item - 1.5f) * shelfWidth * .227f;
int color = ((item + level + selection) % 4) switch
{
0 => ShowVelvet, 1 => LoungeLeather, 2 => PoolTile, _ => Ivory
};
float packWidth = Mathf.Min(.27f, shelfWidth * .182f);
float height = level == 2 ? .15f + item % 2 * .055f : .095f + item % 3 * .064f;
room.Box(color, x, y + .027f + height * .5f, displayZ - .045f, packWidth, height, shelfDepth * .67f);
room.Box(Brass, x, y + .045f + height * .63f, displayZ - shelfDepth * .37f - .045f, packWidth * .52f, .025f, .014f);
}
}
room.Guest(GuestActivity.Shopper, displayX, displayZ - .62f, 17, OnboardService.Retail, .24f);
float counterX = -width * .232f;
float counterZ = checkout ? depth * .035f : depth * .25f;
float counterWidth = Mathf.Min(width * .28f, 2.02f);
float counterDepth = Mathf.Min(depth * .17f, .66f);
room.Solid(Joinery, counterX, .462f, counterZ, counterWidth, .924f, counterDepth);
room.Box(Marble, counterX, .945f, counterZ, counterWidth + .072f, .055f, counterDepth + .087f);
room.Box(Brass, counterX, .774f, counterZ - counterDepth * .50f, counterWidth, .027f, .029f);
if (!checkout)
{
room.Box(WindowGlass, counterX, 1.118f, counterZ, counterWidth * .91f, .29f, counterDepth * .82f);
for (int item = -1; item <= 1; item++)
room.Box(item == 0 ? ShowVelvet : LoungeLeather, counterX + item * counterWidth * .24f,
1.029f, counterZ, .124f, .095f, .092f);
room.Guest(GuestActivity.Shopper, counterX, counterZ - counterDepth * .5f - .42f, 31, OnboardService.Retail, .48f);
return;
}
room.Box(DeckTrim, counterX, 1.027f, counterZ + counterDepth * .29f, .297f, .111f, .193f);
room.Box(PoolTile, counterX, 1.101f, counterZ + counterDepth * .33f, .246f, .106f, .049f);
room.Box(LightStrip, counterX, 1.108f, counterZ + counterDepth * .302f, .165f, .049f, .013f);
room.Guest(GuestActivity.ShopClerk, counterX, counterZ + counterDepth * .5f + .40f, 27,
OnboardService.Retail, .04f, direction: -1);
room.Guest(GuestActivity.Shopper, counterX - .11f, counterZ - counterDepth * .5f - .50f, 34, OnboardService.Retail, .39f);
room.Station(StationKind.Retail, counterX, counterZ - counterDepth * .5f - .10f);
}
private static void FitWellness(Venue room, float width, float depth, bool park)
{
float poolZ = depth * .093f;
var basin = new Vector2(width * (park ? .313f : .253f), depth * .213f);
float surface = park ? .50f : .44f;
room.Box(Marble, 0, .014f, poolZ, basin.x * 2 + 1.06f, .025f, basin.y * 2 + .99f);
room.Pool(poolZ, basin, surface + .103f, surface);
if (park)
{
for (int lane = -1; lane <= 1; lane++)
room.Swimmer(lane * .34f, surface, poolZ + lane * basin.y * .54f, basin.x * .69f,
74 + lane * 7, .24f + lane * .11f);
for (int side = -1; side <= 1; side += 2)
{
room.Guest(GuestActivity.Wade, side * basin.x * .82f, poolZ + basin.y * .68f,
89 + side, OnboardService.Amenities, .31f + side * .11f, lift: surface);
room.Box(SafetyGreen, side * (basin.x + .09f), .617f, poolZ - basin.y * .51f, .13f, .041f, .46f);
}
float splashX = basin.x * .79f;
for (int spray = -1; spray <= 1; spray++)
{
float x = splashX + spray * basin.x * .053f;
float z = poolZ - basin.y * .72f;
room.Cylinder(Brass, x, surface, z, .091f, .088f);
Vector3 last = new(x, surface + .081f, z);
for (int segment = 1; segment <= 8; segment++)
{
float t = segment / 8f;
Vector3 stream = new(x + spray * t * basin.x * .018f,
surface + Mathf.Lerp(.081f, .014f, t) + Mathf.Sin(t * Mathf.PI) * (.57f + spray * .14f),
z + t * basin.y * .76f);
room.Rod(PoolWater, last, stream, .020f);
last = stream;
}
}
}
else
{
for (int seat = -1; seat <= 1; seat += 2)
{
float x = seat * basin.x * .69f;
room.Guest(GuestActivity.Wade, x, poolZ, 128 + seat, OnboardService.Amenities, .26f + seat * .09f, lift: surface);
float sconce = poolZ + basin.y + .32f;
room.Cylinder(Brass, x, .012f, sconce, .25f, .136f);
room.Cylinder(LightStrip, x, .262f, sconce, .053f, .102f);
}
}
// Keep the entrance sightline and cross-ship walkway clear past the basin.
for (int side = -1; side <= 1; side += 2)
{
float x = side * width * .317f;
float z = -depth * .379f;
room.Solid(Joinery, x, .228f, z, width * .235f, .444f, .57f);
room.Box(LoungeLeather, x, .48f, z, width * .238f, .083f, .586f);
room.Box(Brass, x, .51f, z + .27f, width * .233f, .028f, .039f);
for (int towel = -1; towel <= 1; towel++)
room.Box(towel == 0 ? PoolTile : Ivory, x + towel * width * .051f + width * .029f,
.554f, z, .192f, .093f, .23f);
room.Guest(GuestActivity.Rest, x - width * .077f, z, 145 + side, OnboardService.Amenities, .45f, .514f);
}
room.Station(StationKind.Pool, 0, poolZ - basin.y - .36f);
}
private readonly struct Venue
{
private readonly Geometry shape;
private readonly Layout layout;
private readonly Vector3 center;
private readonly int facing, seed;
private readonly int facing, seed, rotation;
public Venue(Geometry shape, Layout layout, Vector3 center, int facing, int seed)
public Venue(Geometry shape, Layout layout, Vector3 center, int facing, int seed, int rotation)
{
this.shape = shape;
this.layout = layout;
this.center = center;
this.facing = facing;
this.seed = seed;
this.rotation = rotation;
}
private Vector3 Point(float x, float y, float z) => center + new Vector3(x, y, z * facing);
private Vector3 Point(float x, float y, float z) => center + (rotation switch
{
1 => new Vector3(-z * facing, y, x),
2 => new Vector3(-x, y, -z * facing),
3 => new Vector3(z * facing, y, -x),
_ => new Vector3(x, y, z * facing)
});
private Vector3 Size(float width, float height, float depth) =>
(rotation & 1) == 0 ? new Vector3(width, height, depth) : new Vector3(depth, height, width);
public void Station(StationKind kind, float x, float z) =>
layout.Stations.Add(new ShipStation(kind, Point(x, 1.4f, z)));
public void Box(int color, float x, float y, float z, float width, float height, float depth) =>
shape.Box(color, Point(x, y, z), new Vector3(width, height, depth));
shape.Box(color, Point(x, y, z), Size(width, height, depth));
public void Solid(int color, float x, float y, float z, float width, float height, float depth)
{
var size = new Vector3(width, height, depth);
var size = Size(width, height, depth);
Vector3 point = Point(x, y, z);
shape.Box(color, point, size);
layout.WalkSpace.Block(point, size);
@@ -261,29 +419,49 @@ namespace Soundings
shape.Mesh(color).Rod(point, point + Vector3.up * height, radius, 12, true);
}
public void Rod(int color, Vector3 start, Vector3 end, float radius) =>
shape.Mesh(color).Rod(Point(start.x, start.y, start.z), Point(end.x, end.y, end.z), radius, 8);
public void Seat(float x, float z, int color, int direction = 1)
{
Vector3 point = Point(x, 0, z);
Chair(shape, point, color, facing * direction);
layout.WalkSpace.Block(point, new Vector3(.50f, .91f, .54f));
Box(color, x, .45f, z, .44f, .089f, .41f);
Box(color, x, .69f, z - .185f * direction, .43f, .41f, .085f);
for (int side = -1; side <= 1; side += 2)
for (int fore = -1; fore <= 1; fore += 2)
Box(Joinery, x + side * .167f, .208f, z + fore * .158f, .044f, .414f, .044f);
layout.WalkSpace.Block(Point(x, 0, z), Size(.50f, .91f, .54f));
}
public void Guest(GuestActivity activity, float x, float z, int variant, OnboardService service, float occupancy,
float seatHeight = 0, int direction = 1, float lift = 0, EntertainmentProgram? program = null) =>
AddGuest(layout, activity, Point(x, lift, z), seed * 11 + variant, facing * direction > 0 ? 0 : 180,
AddGuest(layout, activity, Point(x, lift, z), seed * 11 + variant, (facing * direction > 0 ? 0 : 180) - rotation * 90,
(int)service, occupancy, seatHeight, program);
public void Pool(float z, Vector2 basin, float rim, float surface)
{
Vector3 foot = Point(0, 0, z);
VesselExterior.PoolBasin(shape.Mesh(Ivory), shape.Mesh(PoolTile), shape.Mesh(PoolWater), foot, basin, rim, surface);
Vector3 ladder = Point(basin.x * .68f, .20f, z + basin.y - .07f);
VesselExterior.PoolRails(shape.Mesh(Alloy), ladder, facing);
layout.WalkSpace.Block(foot, new Vector3((basin.x + .23f) * 2f, rim, (basin.y + .23f) * 2f));
Vector2 worldBasin = (rotation & 1) == 0 ? basin : new Vector2(basin.y, basin.x);
VesselExterior.PoolBasin(shape.Mesh(Ivory), shape.Mesh(PoolTile), shape.Mesh(PoolWater), foot, worldBasin, rim, surface);
float ladderX = basin.x * .68f, ladderZ = z + basin.y - .07f;
var rails = shape.Mesh(Alloy);
for (int rail = -1; rail <= 1; rail += 2)
{
float x = ladderX + rail * .23f;
Vector3 post = Point(x, .23f, ladderZ + .36f);
Vector3 elbow = Point(x, .95f, ladderZ + .23f);
rails.Rod(post, elbow, .028f, 8, true);
rails.Rod(elbow, Point(x, .54f, ladderZ - .19f), .028f, 8, true);
}
for (int rung = 0; rung < 2; rung++)
{
float y = .34f + rung * .18f;
rails.Rod(Point(ladderX - .23f, y, ladderZ - .15f), Point(ladderX + .23f, y, ladderZ - .15f), .024f, 8, true);
}
layout.WalkSpace.Block(foot, Size((basin.x + .23f) * 2f, rim, (basin.y + .23f) * 2f));
}
public void Swimmer(float x, float y, float z, float halfLength, int variant, float occupancy) =>
AddGuest(layout, GuestActivity.Swim, Point(x, y, z), seed * 11 + variant, facing * 90,
AddGuest(layout, GuestActivity.Swim, Point(x, y, z), seed * 11 + variant, facing * 90 - rotation * 90,
(int)OnboardService.Amenities, occupancy, swimHalfLength: halfLength);
}
}

View File

@@ -0,0 +1,187 @@
using System;
using System.Collections.Generic;
namespace Soundings
{
[Serializable]
internal sealed class FleetPassageSnapshot
{
public int ShipIndex, Speed;
public bool ApproachAnnounced, HasDeparturePlan, HasView;
public Voyage Voyage;
public HelmSnapshot Helm;
public OnboardSessionSnapshot Session;
public PassageViewSnapshot View;
}
[Serializable]
internal sealed class PassageViewSnapshot
{
public int Deck, ServiceArea;
public bool Bridge, Exploring, BusinessOpen, MapOpen;
}
public sealed partial class SoundingsApp
{
private FleetPassageSnapshot[] CaptureFleetPassages()
{
if (company == null || fleetPassages.Count == 0)
return Array.Empty<FleetPassageSnapshot>();
var snapshots = new List<FleetPassageSnapshot>(fleetPassages.Count);
for (int i = 0; i < company.Fleet.Count; i++)
{
Ship ship = company.Fleet[i];
if (!fleetPassages.TryGetValue(ship, out FleetPassage passage))
continue;
bool foreground = ship == Ship && underway == passage.Voyage;
bool hasDeparturePlan = passage.Voyage.Plan != null;
PassageViewSnapshot view = foreground ? CapturePassageView() : passage.RestoredView;
snapshots.Add(new FleetPassageSnapshot
{
ShipIndex = i, Speed = passage.Speed, Voyage = passage.Voyage.CopyForPassage(hasDeparturePlan),
HasDeparturePlan = hasDeparturePlan,
ApproachAnnounced = foreground ? passageAudio.ApproachSent : passage.ApproachAnnounced,
Helm = passage.Helm.CaptureState(), Session = passage.Session.CaptureState(),
HasView = view != null, View = view
});
}
return snapshots.ToArray();
}
private static bool CanRestoreFleetPassages(Company savedCompany, FleetPassageSnapshot[] snapshots) =>
TryRestoreFleet(savedCompany, snapshots, out _);
private bool RestoreFleetPassages(FleetPassageSnapshot[] snapshots, bool focus = false)
{
if (!TryRestoreFleet(company, snapshots, out Dictionary<Ship, FleetPassage> restored))
return false;
ResetFleetPassages();
foreach (var entry in restored)
fleetPassages.Add(entry.Key, entry.Value);
UpdateVoyageReserves();
if (focus)
ResumeSelectedSavedPassage();
return true;
}
private void ResumeSelectedSavedPassage()
{
Ship selected = Ship;
if (selected == null || underway != null || !fleetPassages.TryGetValue(selected, out FleetPassage passage))
return;
page = 0;
FocusPassage(passage, false);
PassageViewSnapshot view = passage.RestoredView;
passage.RestoredView = null;
if (view != null)
RestorePassageView(view);
else if (passage.Helm.Manual)
{
passageBridge = true;
harbor.ViewBridge();
}
}
private PassageViewSnapshot CapturePassageView() => new PassageViewSnapshot
{
Deck = passageDeck, ServiceArea = passageServiceArea, Bridge = passageBridge, Exploring = passageExploring,
BusinessOpen = passageBusinessOpen, MapOpen = voyageMapOpen
};
private void RestorePassageView(PassageViewSnapshot view)
{
if (view.Bridge || passageHelm.Manual)
{
passageBridge = true;
harbor.ViewBridge();
}
else if (view.ServiceArea >= 0)
{
passageServiceArea = view.ServiceArea;
passageExploring = true;
harbor.ExploreServiceArea(passageServiceArea);
}
else if (view.Deck >= 0)
{
passageDeck = view.Deck;
passageExploring = view.Exploring;
if (passageExploring)
harbor.ExploreDeck(passageDeck);
else
harbor.ShowDeck(passageDeck);
}
passageBusinessOpen = view.BusinessOpen;
voyageMapOpen = view.MapOpen;
}
private static bool TryRestoreFleet(Company savedCompany, FleetPassageSnapshot[] snapshots,
out Dictionary<Ship, FleetPassage> restored)
{
restored = new Dictionary<Ship, FleetPassage>();
if (savedCompany?.Fleet == null)
return false;
if (snapshots == null || snapshots.Length == 0)
return true;
if (snapshots.Length > savedCompany.Fleet.Count)
return false;
long reserved = 0;
foreach (FleetPassageSnapshot snapshot in snapshots)
{
if (snapshot == null || snapshot.ShipIndex < 0 || snapshot.ShipIndex >= savedCompany.Fleet.Count
|| (snapshot.Speed != 1 && snapshot.Speed != 2 && snapshot.Speed != 4))
return false;
Ship ship = savedCompany.Fleet[snapshot.ShipIndex];
Voyage voyage = snapshot.Voyage;
if (ship == null || restored.ContainsKey(ship) || !ValidSavedVoyage(ship, voyage, snapshot.HasDeparturePlan))
return false;
Voyage quote = voyage.CopyForPassage(snapshot.HasDeparturePlan);
reserved += (long)quote.Crew + quote.Catering + quote.PortFees + (quote.Plan?.FoodCost ?? 0)
+ (quote.Plan?.ProgramCost ?? 0) + quote.LoanInterest + quote.Principal;
if (reserved > int.MaxValue)
return false;
var passage = new FleetPassage(ship, quote, snapshot.Session?.Assisted ?? false);
if (!passage.Helm.RestoreState(snapshot.Helm) || !passage.Session.RestoreState(snapshot.Session))
return false;
passage.Speed = snapshot.Speed;
passage.ApproachAnnounced = snapshot.ApproachAnnounced;
PassageViewSnapshot view = snapshot.View;
if (snapshot.HasView && view != null && view.Deck >= -1 && view.Deck < ship.Decks.Count
&& view.ServiceArea >= -1 && view.ServiceArea < ServiceDeckModel.Areas.Length)
passage.RestoredView = view;
if (snapshot.ShipIndex != savedCompany.SelectedShip && passage.Helm.Manual)
{
passage.Helm.Manual = false;
passage.Helm.PropulsionStopped = false;
}
restored.Add(ship, passage);
}
return true;
}
private static bool ValidSavedVoyage(Ship ship, Voyage voyage, bool hasDeparturePlan)
{
if (voyage == null || voyage.Origin != ship.Port || voyage.Destination < 0
|| voyage.Destination >= Market.Ports.Count || !Market.TryDistance(voyage.Origin, voyage.Destination, out int miles)
|| voyage.Miles != miles || voyage.Days < 1 || voyage.Days > 1000 || voyage.Day < 1
|| (uint)voyage.Weather > (uint)WeatherCondition.Storm || voyage.Guests < 1 || voyage.Guests > voyage.Capacity
|| voyage.RoomDemand < voyage.Guests || voyage.Fare < Market.MinFare || voyage.Fare > Market.MaxFare
|| voyage.TicketSales < 0 || voyage.FuelBurn < 1 || voyage.Reserve < 0 || voyage.Crew < 0 || voyage.Catering < 0
|| voyage.PortFees < 0 || voyage.LoanInterest < 0 || voyage.Principal < 0)
return false;
DeparturePlan plan = voyage.Plan;
return !hasDeparturePlan || (plan != null && plan.FoodUnits >= 0 && plan.FoodUnits <= ship.FoodCapacity && plan.FoodCost >= 0
&& plan.ProgramCost >= 0 && (uint)plan.Program <= (uint)EntertainmentProgram.Headline);
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 3dd78688ec48422297b2a2233debd901

View File

@@ -15,6 +15,7 @@ namespace Soundings
public readonly HelmNavigation Helm;
public int Speed = 1;
public bool ApproachAnnounced;
public PassageViewSnapshot RestoredView;
public FleetPassage(Ship ship, Voyage voyage, bool assisted)
{

View File

@@ -598,8 +598,8 @@ namespace Soundings
int deckCount = ship.Decks.Count;
ulong layout = 0;
foreach (Deck deck in ship.Decks)
foreach (Facility cell in deck.Cells)
layout = unchecked(layout * 31 + (uint)cell + 1);
for (int cell = 0; cell < deck.Cells.Length; cell++)
layout = unchecked(layout * 109 + (uint)deck.Cells[cell] * 4 + (uint)deck.RotationAt(cell) + 1);
if (ReferenceEquals(displayedShip, ship) && hullIndex == lastHull && deckCount == lastDecks && layout == lastLayout)
return;

View File

@@ -4,7 +4,7 @@ using UnityEngine;
namespace Soundings
{
internal enum StationKind { Helm, Engine, Galley, Stores, Maintenance, Water, Waste, Cabins, Dining, Bar, Stage, Pool }
internal enum StationKind { Helm, Engine, Galley, Stores, Maintenance, Water, Waste, Cabins, Dining, Bar, Stage, Pool, Retail }
internal readonly struct ShipStation
{

View File

@@ -1,7 +1,16 @@
using System;
using UnityEngine;
namespace Soundings
{
[Serializable]
internal sealed class HelmSnapshot
{
public Vector2 Position, ApproachWaypoint;
public float RouteDuration, Heading, Rudder, Speed, Progress, TurnRate;
public bool Manual, PropulsionStopped, Arrived, ExtendingApproach;
}
internal sealed class HelmNavigation
{
private const float RudderLimit = 35f;
@@ -102,5 +111,46 @@ namespace Soundings
extendingApproach = false;
Arrived = Progress >= 1;
}
internal HelmSnapshot CaptureState() => new HelmSnapshot
{
Position = Position, ApproachWaypoint = approachWaypoint, RouteDuration = duration, Heading = Heading,
Rudder = Rudder, Speed = Speed, Progress = Progress, TurnRate = turnRate, Manual = Manual,
PropulsionStopped = PropulsionStopped, Arrived = Arrived, ExtendingApproach = extendingApproach
};
internal bool RestoreState(HelmSnapshot state)
{
if (state == null || !Finite(state.RouteDuration) || state.RouteDuration < 1
|| !Finite(state.Position.x) || !Finite(state.Position.y)
|| !Finite(state.ApproachWaypoint.x) || !Finite(state.ApproachWaypoint.y)
|| !Finite(state.Heading) || Mathf.Abs(state.Heading) > 180
|| !Finite(state.Rudder) || Mathf.Abs(state.Rudder) > RudderLimit
|| !Finite(state.Speed) || state.Speed < 0 || state.Speed > 120
|| !Finite(state.Progress) || state.Progress < 0 || state.Progress > 1 || (state.Arrived && state.Progress != 1)
|| !Finite(state.TurnRate) || Mathf.Abs(state.TurnRate) > 40)
return false;
float scale = duration / state.RouteDuration;
Vector2 position = state.Position * scale;
Vector2 waypoint = state.ApproachWaypoint * scale;
if (!Finite(position.sqrMagnitude) || !Finite(waypoint.sqrMagnitude))
return false;
Position = position;
approachWaypoint = waypoint;
Heading = state.Heading;
Rudder = state.Rudder;
Speed = state.Speed;
Progress = state.Progress;
turnRate = state.TurnRate;
Manual = state.Manual;
PropulsionStopped = state.PropulsionStopped;
Arrived = state.Arrived;
extendingApproach = state.ExtendingApproach;
return true;
}
private static bool Finite(float value) => !float.IsNaN(value) && !float.IsInfinity(value);
}
}

View File

@@ -153,6 +153,9 @@ namespace Soundings
if (trip.SuiteGuests > 0)
LogLine(statement, $"Suite premium · {trip.SuiteGuests:N0} guests", Money(trip.SuitePremium));
LogLine(statement, "Onboard revenue", Money(trip.OnboardSales));
if (trip.Onboard?.ServiceSales is int[] sales && sales.Length > (int)OnboardService.Retail
&& sales[(int)OnboardService.Retail] > 0)
AddText(statement, $"Includes {Money(sales[(int)OnboardService.Retail])} in shop sales", "log-secondary");
if (trip.Onboard?.Expenses > 0)
LogLine(statement, "Onboard operating costs", Money(-trip.Onboard.Expenses));
LogLine(statement, "Crew and catering", Money(-trip.Crew - trip.Catering));

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace Soundings
{
@@ -8,25 +9,52 @@ namespace Soundings
public enum Facility
{
Empty, Cabin, Dining, Entertainment, Tank, Bar, Amenity, Galley, Stores, Water, Waste, Workshop,
Suite, GrandSuite, Restaurant, GrandTheater, ResortPool, CocktailLounge, Extension
Suite, GrandSuite, Restaurant, GrandTheater, ResortPool, CocktailLounge, Extension,
Shop, ShoppingArcade, Spa, WaterPark
}
public sealed class FacilitySpec
{
public readonly string Name, Mark, Details;
public readonly int Price, Capacity, Length, MinimumHull, FarePremiumPercent;
public readonly int Price, Capacity, MinimumHull, FarePremiumPercent;
private readonly Vector2Int[][] footprints = new Vector2Int[4][];
public FacilitySpec(string name, string mark, string details, int price, int capacity,
int length = 1, int minimumHull = Market.Coastal, int farePremiumPercent = 0)
int length = 1, int minimumHull = Market.Coastal, int farePremiumPercent = 0,
int depth = 1, bool corner = false)
{
Name = name;
Mark = mark;
Details = details;
Price = price;
Capacity = capacity;
Length = length;
MinimumHull = minimumHull;
FarePremiumPercent = farePremiumPercent;
var bays = new List<Vector2Int>(length * depth);
for (int row = 0; row < depth; row++)
for (int column = 0; column < length; column++)
if (!corner || row == 0 || column == 0)
bays.Add(new Vector2Int(column, row));
footprints[0] = bays.ToArray();
for (int rotation = 1; rotation < footprints.Length; rotation++)
footprints[rotation] = Turn(footprints[rotation - 1]);
}
public int BayCount => footprints[0].Length;
public IReadOnlyList<Vector2Int> Footprint(int rotation) => footprints[rotation & 3];
private static Vector2Int[] Turn(Vector2Int[] bays)
{
var rotated = new Vector2Int[bays.Length];
for (int i = 0; i < bays.Length; i++)
rotated[i] = new Vector2Int(-bays[i].y, bays[i].x);
Array.Sort(rotated, (left, right) => left.y != right.y ? left.y.CompareTo(right.y) : left.x.CompareTo(right.x));
// Keep the first occupied bay as the anchor, even when a lower row reaches farther left.
Vector2Int anchor = rotated[0];
for (int i = 0; i < rotated.Length; i++)
rotated[i] -= anchor;
return rotated;
}
}
@@ -132,7 +160,11 @@ namespace Soundings
new FacilitySpec("Grand theater", "GT", "256 show seats", 52300, 256, 3, Ocean),
new FacilitySpec("Resort pool", "RP", "216 amenity admissions per service", 57200, 216, 3, Regional),
new FacilitySpec("Cocktail lounge", "CL", "156 drink orders per service", 32100, 156, 2, Regional),
new FacilitySpec("Continued berth", "", "", 0, 0)
new FacilitySpec("Continued berth", "", "", 0, 0),
new FacilitySpec("Gift shop", "SH", "64 retail orders per service", 12600, 64),
new FacilitySpec("Shopping arcade", "SA", "190 retail orders per service", 41500, 190, 2, Regional, depth: 2, corner: true),
new FacilitySpec("Spa retreat", "SP", "144 amenity admissions per service", 48300, 144, 2, Regional, depth: 2),
new FacilitySpec("Water park", "WP", "460 amenity admissions per service", 107000, 460, 3, Ocean, depth: 2)
};
public static readonly IReadOnlyList<HullSpec> Hulls = new[]

View File

@@ -2,7 +2,7 @@ using System;
namespace Soundings
{
public enum OnboardService { Rooms, Meals, Drinks, Shows, Amenities }
public enum OnboardService { Rooms, Meals, Drinks, Shows, Amenities, Retail }
[Serializable]
public sealed class OnboardReport
@@ -42,10 +42,11 @@ namespace Soundings
public sealed partial class OnboardSession
{
private const int ServiceKinds = 5;
private const int ServiceKinds = (int)OnboardService.Retail + 1;
private const int PromotionTicks = 5;
private static readonly int[] Defaults = { 0, 12, 7, 18, 10 };
private static readonly double[] BaseDemand = { 0, .71, .59, .43, .51 };
private const int WholesalePrice = 5;
private static readonly int[] Defaults = { 0, 12, 7, 18, 10, 22 };
private static readonly double[] BaseDemand = { 0, .71, .59, .43, .51, .29 };
private static readonly VoyageEvent[] Events =
{
new VoyageEvent("Dinner rush", "An early seating is filling up. Open overflow tables to expand meal capacity and lift the survey.",
@@ -95,8 +96,11 @@ namespace Soundings
capacity[3] = ship.Entertainment;
int outdoor = ship.PoolCapacity;
capacity[4] = quote.Weather switch { WeatherCondition.Storm => 0, WeatherCondition.Swell => outdoor * 2 / 3, _ => outdoor };
capacity[(int)OnboardService.Retail] = ship.RetailCapacity;
prices = (int[])(ship.ServicePrices?.Length == ServiceKinds ? ship.ServicePrices : Defaults).Clone();
prices = (int[])Defaults.Clone();
if (ship.ServicePrices != null)
Array.Copy(ship.ServicePrices, prices, Math.Min(ship.ServicePrices.Length, prices.Length));
for (int i = 0; i < ServiceKinds; i++)
prices[i] = Market.Clamp(prices[i], 0, Defaults[i] * 4);
InitializeSystems();
@@ -109,6 +113,7 @@ namespace Soundings
OnboardService.Meals => "Meals",
OnboardService.Drinks => "Drinks",
OnboardService.Shows => "Entertainment",
OnboardService.Retail => "Shopping",
_ => "Amenities"
};
@@ -210,8 +215,10 @@ namespace Soundings
sample[0] = new OnboardSample(Math.Max(Quote.Guests, Quote.RoomDemand), Quote.Guests, capacity[0], 0);
double fulfillment = 1;
double mealFulfillment = 1;
for (int i = 1; i < ServiceKinds; i++)
int serviceCount = capacity[(int)OnboardService.Retail] > 0 ? ServiceKinds : ServiceKinds - 1;
for (int i = 1; i < serviceCount; i++)
{
bool retail = i == (int)OnboardService.Retail;
int price = EffectivePrice((OnboardService)i);
double wave = .76 + .48 * (.5 + .5 * Math.Sin((tick + i * 2.1) * .66));
double appeal = Math.Max(.23, Math.Min(1.6, (Defaults[i] + 5.0) / (price + 5.0)));
@@ -221,7 +228,7 @@ namespace Soundings
bool performance = i == (int)OnboardService.Shows && PerformanceActive;
if (performance)
rush += PortPlanning.ShowDemand(BookedProgram);
double indoorShift = Quote.Weather == WeatherCondition.Storm && (i == 2 || i == 3) ? 1.28 : 1;
double indoorShift = Quote.Weather == WeatherCondition.Storm && (i == 2 || i == 3 || retail) ? 1.28 : 1;
int requested = Math.Min(Quote.Guests, rush + (int)Math.Round(Quote.Guests * BaseDemand[i] * appeal * wave * indoorShift));
int extraSeats = performance ? PortPlanning.ShowSeats(BookedProgram) : 0;
int possible = ServiceCapacity(i, capacity[i] + extraSeats + (featured ? additionalCapacity : 0) + CrewServiceBoost(i));
@@ -229,7 +236,15 @@ namespace Soundings
if (collect)
{
int takings = (int)Math.Round(served * price * (i == 1 ? .17 : .13));
int takings;
if (retail)
{
int orders = price == 0 ? 0 : (int)Math.Round(served * .13);
takings = orders * price;
Expenses += orders * WholesalePrice;
}
else
takings = (int)Math.Round(served * price * (i == 1 ? .17 : .13));
revenue[i] += takings;
Revenue += takings;
}
@@ -246,7 +261,7 @@ namespace Soundings
if (collect)
{
UpdateHealth(mealFulfillment);
double target = Math.Min(100, 40 + 55 * fulfillment / ServiceKinds - (100 - health) * .28 + CrewSurveyBonus);
double target = Math.Min(100, 40 + 55 * fulfillment / serviceCount - (100 - health) * .28 + CrewSurveyBonus);
satisfaction = satisfaction * .77 + target * .23;
}
}

View File

@@ -5,7 +5,7 @@ namespace Soundings
public sealed partial class OnboardSession
{
private static readonly float[] CrewCallSchedule = { .12f, .43f, .71f };
private readonly int[] stationReadyAt = new int[(int)StationKind.Pool + 1];
private readonly int[] stationReadyAt = new int[(int)StationKind.Retail + 1];
private readonly int[] stationBoostUntil = new int[ServiceKinds];
private int nextCrewCall, crewCallDeadline;
@@ -27,6 +27,7 @@ namespace Soundings
StationKind.Dining => "Dining host",
StationKind.Bar => "Bar counter",
StationKind.Stage => "Show lounge",
StationKind.Retail => "Shop checkout",
_ => "Pool terrace"
};
@@ -43,6 +44,7 @@ namespace Soundings
StationKind.Bar => "Start happy hour · 25% off",
StationKind.Stage => CanAdvancePerformance ? "Call the booked act" : "Open overflow seating",
StationKind.Pool => "Host a poolside game",
StationKind.Retail => "Start a shop sale · 25% off",
_ => "Take the helm"
};
@@ -67,6 +69,8 @@ namespace Soundings
StationKind.Waste when !CanSpend(TreatmentCost) => "No room in the operating budget",
StationKind.Bar when DiscountTicks(OnboardService.Drinks) > 0 => "Happy hour is already underway",
StationKind.Bar when GetPrice(OnboardService.Drinks) == 0 || capacity[(int)OnboardService.Drinks] == 0 => "There is no paid bar service to promote",
StationKind.Retail when DiscountTicks(OnboardService.Retail) > 0 => "A shop sale is already underway",
StationKind.Retail when GetPrice(OnboardService.Retail) == 0 || capacity[(int)OnboardService.Retail] == 0 => "Set a shopping price to run a sale",
StationKind.Stage when capacity[(int)OnboardService.Shows] == 0 => "No show lounge is fitted",
StationKind.Pool when Quote.Weather == WeatherCondition.Storm => "The terrace is closed in this weather",
StationKind.Pool when WaterPercent < 22 => "Freshwater is too low for pool operation",
@@ -95,6 +99,7 @@ namespace Soundings
stationBoostUntil[(int)OnboardService.Shows] = tick + 6;
break;
case StationKind.Pool: stationBoostUntil[(int)OnboardService.Amenities] = tick + 6; break;
case StationKind.Retail: StartSpecial(OnboardService.Retail); break;
}
stationReadyAt[(int)station] = tick + (station == StationKind.Engine ? 1 : 8);
@@ -122,6 +127,7 @@ namespace Soundings
StationKind.Cabins => "Guest services checked in · Survey improved",
StationKind.Bar => "Happy hour started · Drinks are 25% off",
StationKind.Stage => "Show lounge ready for guests",
StationKind.Retail => "Shop sale started · Merchandise is 25% off",
_ => "Poolside game started · More terrace capacity"
};

View File

@@ -0,0 +1,150 @@
using System;
namespace Soundings
{
[Serializable]
internal sealed class OnboardSessionSnapshot
{
public int Tick, NextEvent, OpenedAt, EventBenefitUntil, FeaturedService, AdditionalCapacity, Decisions;
public int Revenue, Expenses;
public int[] Prices, ServiceRevenue, SaleUntil, StationReadyAt, StationBoostUntil;
public ServiceSampleSnapshot[] Samples;
public double Satisfaction, Provisions, Water, Waste, FuelIntegrated, Health, Hydration;
public int GalleyUntil, PumpsUntil, TreatmentUntil, EngineMode, RepairCredit;
public bool Assisted, StoresOpened;
public int NextCrewCall, CrewCallDeadline, CrewCall, CrewRequestsCompleted, PerformanceStarted;
public string EventResult;
}
[Serializable]
internal struct ServiceSampleSnapshot
{
public int Requested, Served, Capacity, Revenue;
}
public sealed partial class OnboardSession
{
internal OnboardSessionSnapshot CaptureState()
{
var samples = new ServiceSampleSnapshot[sample.Length];
for (int i = 0; i < sample.Length; i++)
samples[i] = new ServiceSampleSnapshot
{
Requested = sample[i].Requested, Served = sample[i].Served,
Capacity = sample[i].Capacity, Revenue = sample[i].Revenue
};
return new OnboardSessionSnapshot
{
Tick = tick, NextEvent = nextEvent, OpenedAt = openedAt, EventBenefitUntil = eventBenefitUntil,
FeaturedService = featuredService, AdditionalCapacity = additionalCapacity, Decisions = decisions,
Satisfaction = satisfaction, Revenue = Revenue, Expenses = Expenses, EventResult = EventResult,
Prices = (int[])prices.Clone(), ServiceRevenue = (int[])revenue.Clone(), SaleUntil = (int[])saleUntil.Clone(),
Samples = samples, Provisions = provisions, Water = water, Waste = waste, FuelIntegrated = fuelIntegrated,
Health = health, Hydration = hydration, GalleyUntil = galleyUntil, PumpsUntil = pumpsUntil,
TreatmentUntil = treatmentUntil, Assisted = Assisted, EngineMode = EngineMode, RepairCredit = RepairCredit,
StoresOpened = StoresOpened, StationReadyAt = (int[])stationReadyAt.Clone(), StationBoostUntil = (int[])stationBoostUntil.Clone(),
NextCrewCall = nextCrewCall, CrewCallDeadline = crewCallDeadline,
CrewCall = CrewCall is StationKind station ? (int)station : -1,
CrewRequestsCompleted = CrewRequestsCompleted, PerformanceStarted = performanceStarted
};
}
internal bool RestoreState(OnboardSessionSnapshot state)
{
if (!IsValidSnapshot(state))
return false;
tick = state.Tick;
nextEvent = state.NextEvent;
openedAt = state.OpenedAt;
eventBenefitUntil = state.EventBenefitUntil;
featuredService = state.FeaturedService;
additionalCapacity = state.AdditionalCapacity;
decisions = state.Decisions;
satisfaction = state.Satisfaction;
Revenue = state.Revenue;
Expenses = state.Expenses;
EventResult = state.EventResult;
Array.Copy(state.Prices, prices, state.Prices.Length);
Array.Copy(state.ServiceRevenue, revenue, state.ServiceRevenue.Length);
Array.Copy(state.SaleUntil, saleUntil, state.SaleUntil.Length);
provisions = state.Provisions;
water = state.Water;
waste = state.Waste;
fuelIntegrated = state.FuelIntegrated;
health = state.Health;
hydration = state.Hydration;
galleyUntil = state.GalleyUntil;
pumpsUntil = state.PumpsUntil;
treatmentUntil = state.TreatmentUntil;
Assisted = state.Assisted;
EngineMode = state.EngineMode;
RepairCredit = state.RepairCredit;
StoresOpened = state.StoresOpened;
Array.Copy(state.StationReadyAt, stationReadyAt, state.StationReadyAt.Length);
Array.Copy(state.StationBoostUntil, stationBoostUntil, state.StationBoostUntil.Length);
nextCrewCall = state.NextCrewCall;
crewCallDeadline = state.CrewCallDeadline;
CrewCall = state.CrewCall < 0 ? null : (StationKind)state.CrewCall;
CrewRequestsCompleted = state.CrewRequestsCompleted;
performanceStarted = state.PerformanceStarted;
// Evaluate newly introduced services before restoring the exact saved readouts for existing ones.
Measure(false);
for (int i = 0; i < state.Samples.Length; i++)
{
ServiceSampleSnapshot saved = state.Samples[i];
sample[i] = new OnboardSample(saved.Requested, saved.Served, saved.Capacity, saved.Revenue);
}
return true;
}
private bool IsValidSnapshot(OnboardSessionSnapshot state)
{
const int OriginalServiceCount = 5;
const int OriginalStationCount = (int)StationKind.Pool + 1;
if (state?.Prices == null || state.Prices.Length < OriginalServiceCount || state.Prices.Length > ServiceKinds
|| state.ServiceRevenue?.Length != state.Prices.Length || state.SaleUntil?.Length != state.Prices.Length
|| state.Samples?.Length != state.Prices.Length || state.StationBoostUntil?.Length != state.Prices.Length
|| state.StationReadyAt == null || state.StationReadyAt.Length < OriginalStationCount
|| state.StationReadyAt.Length > stationReadyAt.Length)
return false;
int offerCount = (Quote.Weather == WeatherCondition.Storm ? StormEvents : Events).Length;
if (state.Tick < 0 || state.Tick > ticks || state.NextEvent < 0 || state.NextEvent > offerCount
|| state.OpenedAt < -1 || state.OpenedAt > state.Tick || (state.OpenedAt >= 0 && state.NextEvent >= offerCount)
|| state.FeaturedService < -1 || state.FeaturedService >= state.Prices.Length || state.AdditionalCapacity < 0
|| state.EventBenefitUntil < 0 || state.Decisions < 0 || state.Decisions > offerCount
|| state.Revenue < 0 || state.Expenses < 0 || state.EngineMode < 0 || state.EngineMode >= FuelRates.Length
|| state.RepairCredit < 0 || state.RepairCredit > 6 || state.GalleyUntil < 0 || state.PumpsUntil < 0
|| state.TreatmentUntil < 0 || state.NextCrewCall < 0 || state.NextCrewCall > CrewCallSchedule.Length
|| state.CrewCall < -1 || state.CrewCall >= state.StationReadyAt.Length || state.CrewCallDeadline < 0
|| state.CrewCallDeadline > ticks || state.CrewRequestsCompleted < 0
|| state.CrewRequestsCompleted > CrewCallSchedule.Length || state.PerformanceStarted < -1
|| state.PerformanceStarted > state.Tick)
return false;
if (!AmountInRange(state.Satisfaction, 100) || !AmountInRange(state.Health, 100) || !AmountInRange(state.Hydration, 1)
|| !AmountInRange(state.Provisions, Ship.FoodCapacity) || !AmountInRange(state.Water, Ship.WaterCapacity)
|| !AmountInRange(state.Waste, Ship.WasteCapacity * 1.3) || !AmountInRange(state.FuelIntegrated, ticks * 1.23))
return false;
for (int i = 0; i < state.Prices.Length; i++)
{
ServiceSampleSnapshot saved = state.Samples[i];
if (state.Prices[i] < 0 || state.Prices[i] > Defaults[i] * 4 || state.ServiceRevenue[i] < 0
|| state.SaleUntil[i] < 0 || state.StationBoostUntil[i] < 0 || saved.Requested < 0 || saved.Served < 0
|| saved.Capacity < 0 || saved.Revenue < 0)
return false;
}
foreach (int ready in state.StationReadyAt)
if (ready < 0)
return false;
return true;
}
private static bool AmountInRange(double value, double maximum) => value >= 0 && value <= maximum + .0001;
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: b24d886813ee4e248010bee51cfd1095

View File

@@ -5,12 +5,12 @@ namespace Soundings
{
public sealed partial class SoundingsApp
{
private static readonly string[] PassageServices = { "rooms", "meals", "drinks", "shows", "amenities" };
private readonly Label[] passageDemand = new Label[5];
private readonly Label[] passagePrices = new Label[5];
private readonly Button[] passageSpecials = new Button[5];
private readonly Button[] passageMinus = new Button[5];
private readonly Button[] passagePlus = new Button[5];
private static readonly string[] PassageServices = { "rooms", "meals", "drinks", "shows", "amenities", "retail" };
private readonly Label[] passageDemand = new Label[PassageServices.Length];
private readonly Label[] passagePrices = new Label[PassageServices.Length];
private readonly Button[] passageSpecials = new Button[PassageServices.Length];
private readonly Button[] passageMinus = new Button[PassageServices.Length];
private readonly Button[] passagePlus = new Button[PassageServices.Length];
private bool passageBusinessOpen = true;
private VisualElement passageProgress, passageEventHost;
private Label passageRemaining, passageHappiness, passageHealth, passageSupplies, passageSales, passageEventClock, passageEventResult, passagePerformance;
@@ -147,6 +147,11 @@ namespace Soundings
for (int i = 0; i < PassageServices.Length; i++)
{
OnboardService service = (OnboardService)i;
if (service == OnboardService.Retail && Ship.RetailCapacity == 0)
{
passageDemand[i] = null;
continue;
}
string slug = PassageServices[i];
var entry = Add(book, "voyage-service");
var line = Add(entry, "voyage-service-line");
@@ -233,6 +238,8 @@ namespace Soundings
SetPassageText(passagePerformance, livePassage.PerformanceLabel);
for (int i = 0; i < PassageServices.Length; i++)
{
if (passageDemand[i] == null)
continue;
OnboardService service = (OnboardService)i;
OnboardSample demand = livePassage.Get(service);
SetPassageText(passageDemand[i], $"{demand.Served:N0} / {demand.Requested:N0} guests");

View File

@@ -4,7 +4,10 @@ using UnityEngine.Rendering;
namespace Soundings
{
internal enum GuestActivity { Walk, Rail, Talk, Photograph, Read, Dine, Drink, Watch, Perform, Rest, Guitar, Revue, Swim, Wade, TendBar, Lounge }
internal enum GuestActivity
{
Walk, Rail, Talk, Photograph, Read, Dine, Drink, Watch, Perform, Rest, Guitar, Revue, Swim, Wade, TendBar, Lounge, Shopper, ShopClerk
}
internal sealed class DeckGuest
{
@@ -118,7 +121,7 @@ namespace Soundings
if (guest.Service >= 0)
{
OnboardSample service = session.Get((OnboardService)guest.Service);
occupancy = guest.Activity == GuestActivity.TendBar && service.Capacity > 0
occupancy = guest.Activity is (GuestActivity.TendBar or GuestActivity.ShopClerk) && service.Capacity > 0
? 1 : service.Served / (float)Mathf.Max(1, service.Capacity);
}
if (guest.Program.HasValue)

View File

@@ -75,7 +75,7 @@ namespace Soundings
bool walking = activity == GuestActivity.Walk;
bool swimming = activity == GuestActivity.Swim;
bool inWater = swimming || activity == GuestActivity.Wade;
bool staff = activity == GuestActivity.TendBar;
bool staff = activity is GuestActivity.TendBar or GuestActivity.ShopClerk;
bool lounging = activity == GuestActivity.Lounge;
bool seated = guest.SeatHeight > 0;
float heading = guest.Heading;
@@ -138,6 +138,7 @@ namespace Soundings
{
GuestActivity.Read => 23f, GuestActivity.Dine => 9f, GuestActivity.Drink => 5f,
GuestActivity.TendBar => 12f, GuestActivity.Photograph => -2f, GuestActivity.Lounge => -11f,
GuestActivity.Shopper => 16f, GuestActivity.ShopClerk => 15f,
_ => seated ? -3f : 0
};
float spot = Mathf.Sin(time * .67f) * (walking ? 12 : 23);
@@ -187,7 +188,7 @@ namespace Soundings
new Vector3(.015f, .035f, .014f), handRotation * Quaternion.Euler(0, 0, side * -22), skin, Surface.Skin);
if (side > 0)
HeldObject(activity, palm, yaw: chestTurn, lift: focusPhase);
else if (staff)
else if (activity == GuestActivity.TendBar)
Shell(SmallOrb, palm + new Vector3(.022f, .034f, .015f), new Vector3(.034f, .048f, .035f),
Quaternion.identity, Glass, Surface.Accessory);
}
@@ -298,6 +299,12 @@ namespace Soundings
case GuestActivity.TendBar:
return side > 0 ? new Vector3(.19f + .12f * Mathf.Sin(time * 1.35f) * (1 - beat), hip + .14f + .22f * beat, .50f - .069f * beat)
: new Vector3(-.119f + .072f * Mathf.Sin(time * 1.55f) * (1 - beat), hip + .158f, .49f);
case GuestActivity.Shopper:
return side > 0 ? new Vector3(.15f, hip + .15f + .19f * beat, .27f + .12f * beat)
: new Vector3(-.20f + .10f * beat, hip - .11f + .31f * beat, .10f + .26f * beat);
case GuestActivity.ShopClerk:
return side > 0 ? new Vector3(.22f - beat * .15f, hip + .133f + .10f * beat, .43f)
: new Vector3(-.118f, hip + .14f, .40f + .072f * beat);
case GuestActivity.Watch:
float clap = beat * (.66f + .34f * Mathf.Sin(time * 17f));
return new Vector3(side * Mathf.Lerp(.155f, .031f, clap), hip + .108f + beat * .25f, .295f + beat * .055f);
@@ -446,6 +453,16 @@ namespace Soundings
case GuestActivity.Perform:
Span(palm + new Vector3(-.009f, -.029f, .023f), palm + new Vector3(-.035f, .105f, .030f), .019f, Dark, Surface.Accessory);
break;
case GuestActivity.Shopper:
Vector3 bag = palm + new Vector3(-.014f, -.134f, .012f);
Span(bag + new Vector3(-.057f, .074f, 0), palm, .007f, Strap, Surface.Accessory);
Span(palm, bag + new Vector3(.057f, .074f, 0), .007f, Strap, Surface.Accessory);
ShoppingBag(bag);
break;
case GuestActivity.ShopClerk:
Span(palm + new Vector3(.006f, -.036f, 0), palm + new Vector3(.006f, .068f, .029f), .026f, Dark, Surface.Accessory);
Span(palm + new Vector3(.006f, .068f, .029f), palm + new Vector3(.006f, .083f, .081f), .027f, Dark, Surface.Accessory);
break;
case GuestActivity.TendBar:
float phase = Mathf.Repeat(passengerClock * .19f, 1);
Quaternion bottle = Quaternion.Euler(-28 - 48 * lift, yaw + phase * 5, -11 + lift * 87);
@@ -459,6 +476,32 @@ namespace Soundings
}
}
private void ShoppingBag(Vector3 center)
{
Vector3 half = new(.090f, .081f, .043f);
Vector3 a = center + new Vector3(-half.x, -half.y, -half.z);
Vector3 b = center + new Vector3(half.x, -half.y, -half.z);
Vector3 c = center + new Vector3(half.x, -half.y, half.z);
Vector3 d = center + new Vector3(-half.x, -half.y, half.z);
Vector3 up = Vector3.up * (half.y * 2);
Panel(b, a, a + up, b + up, Vector3.back, Paper);
Panel(c, b, b + up, c + up, Vector3.right, Paper);
Panel(d, c, c + up, d + up, Vector3.forward, Paper);
Panel(a, d, d + up, a + up, Vector3.left, Paper);
Panel(a + up, d + up, c + up, b + up, Vector3.up, Dark);
Panel(a, b, c, d, Vector3.down, Paper);
void Panel(Vector3 first, Vector3 second, Vector3 third, Vector3 fourth, Vector3 normal, Color32 color)
{
int start = vertices.Count;
Emit(first, normal, color, Surface.Accessory, coverage);
Emit(second, normal, color, Surface.Accessory, coverage);
Emit(third, normal, color, Surface.Accessory, coverage);
Emit(fourth, normal, color, Surface.Accessory, coverage);
TrianglePair(start, start + 1, start + 2, start + 3);
}
}
private void Guitar(Vector3 pelvis)
{
Quaternion angle = Quaternion.Euler(-11, -5, 20);

View File

@@ -61,13 +61,13 @@ namespace Soundings
root = document.rootVisualElement;
root.style.flexGrow = 1;
root.style.unityFontDefinition = interfaceFont;
foreach (string sheet in new[] { "Soundings", "Shipwork", "Ledger", "FirstVoyageGuide", "Passage", "ServiceControls", "FleetOverview" })
foreach (string sheet in new[] { "Soundings", "Shipwork", "Ledger", "FirstVoyageGuide", "Passage", "ServiceControls", "FleetOverview", "Careers" })
{
StyleSheet stylesheet = Resources.Load<StyleSheet>(sheet);
if (stylesheet != null)
root.styleSheets.Add(stylesheet);
}
company = autoSmoke ? null : Load();
InitializeCareers();
Render();
if (exportClips)
StartCoroutine(ExportPortClips(arguments[clipArgument + 1]));
@@ -75,39 +75,14 @@ namespace Soundings
StartCoroutine(VisualSmoke());
}
private Company Load()
{
if (!PlayerPrefs.HasKey(SaveKey))
return null;
try
{
Company loaded = JsonUtility.FromJson<Company>(PlayerPrefs.GetString(SaveKey));
if (loaded != null && loaded.CanLoad())
{
loaded.RestoreHullDecks();
return loaded;
}
}
catch (ArgumentException exception)
{
Debug.LogWarning("Could not read the company save. " + exception.Message);
}
Notify("The company save could not be read.", true);
return null;
}
private void Save()
{
if (autoSmoke)
return;
PlayerPrefs.SetString(SaveKey, JsonUtility.ToJson(company));
PlayerPrefs.Save();
}
private void StartCompany(bool financed)
private void StartCompany(bool financed, string name = null)
{
ResetFleetPassages();
company = Company.Start(financed);
careerId = Guid.NewGuid().ToString("N");
careerName = name ?? AvailableCareerName(financed ? "Shipyard career" : "Meridian Line");
careerMenu = CareerMenu.Closed;
careerError = null;
title = paused = fleetOpen = shipActionsOpen = false;
page = financed ? 2 : 0;
yardSelection = 1;
@@ -212,7 +187,9 @@ namespace Soundings
DrawPause();
}
if (!string.IsNullOrEmpty(focus) && root.Q<VisualElement>(focus) != null)
if (careerMenu != CareerMenu.Closed)
DrawCareerMenu();
else if (!string.IsNullOrEmpty(focus) && root.Q<VisualElement>(focus) != null)
root.schedule.Execute(() => root.Q<VisualElement>(focus)?.Focus());
}
@@ -241,22 +218,22 @@ namespace Soundings
if (pendingStart.HasValue)
{
AddDisplay(intro, "Replace this company?", "title-question");
AddText(intro, "A new career replaces your saved fleet and voyages.", "title-confirm-copy");
intro.Add(Action("Start a new career", () => StartCompany(pendingStart.Value), "primary title-command", "replace"));
intro.Add(Action("Keep my company", () => { pendingStart = null; Render(); }, "title-command", "keep"));
AddDisplay(intro, "Name your new career", "title-question");
CareerNameField(intro);
if (!string.IsNullOrEmpty(careerError))
AddText(intro, careerError, "career-save-error");
intro.Add(Action("Start a new career", StartNamedCareer, "primary title-command", "replace"));
intro.Add(Action("Back", () => { pendingStart = null; careerError = null; Render(); }, "title-command", "keep"));
}
else
{
if (company != null)
intro.Add(Action("Continue career", () =>
{
title = false;
page = Ship == null ? 2 : 0;
ResetItinerary();
Notify(null);
Render();
}, "primary title-command", "resume"));
{
Button resume = Action("Continue career", () => LoadCareer(careerId), "primary title-command", "resume");
resume.tooltip = careerName;
intro.Add(resume);
intro.Add(Action("Load game", () => OpenCareerMenu(CareerMenu.Load), "title-command", "career-load-open"));
}
StartOption(intro, "Take the helm", "Used coastal ship / $135,000 cash / No debt", false);
StartOption(intro, "Start from the shipyard", "Empty fleet / $580,000 cash / $500,000 loan", true);
@@ -276,13 +253,11 @@ namespace Soundings
{
Button option = Action("", () =>
{
if (company == null)
StartCompany(financed);
else
{
pendingStart = financed;
Render();
}
pendingStart = financed;
careerNameDraft = AvailableCareerName(financed ? "Shipyard career" : "Meridian Line");
careerError = null;
Notify(null);
Render();
}, "career-option", financed ? "start-financed" : "start-used");
AddText(option, titleText, "career-option-name");
AddText(option, description, "career-option-balance");
@@ -431,19 +406,15 @@ namespace Soundings
GameIcon(menu, "anchor");
AddDisplay(menu, "Paused", "pause-title");
menu.Add(Action("Resume", () => { paused = false; Render(); }, "primary pause-command", "resume-game"));
menu.Add(Action("Restart first voyage guide", RestartGuide, "pause-command", "restart-guide"));
if (fleetPassages.Count == 0 && underway == null)
{
menu.Add(Action("Title screen", () =>
{
paused = fleetOpen = shipActionsOpen = false;
title = true;
Notify(null);
Render();
}, "pause-command", "return-title"));
}
var saving = Add(menu, "career-pause-actions");
saving.Add(Action("Save game", SaveFromPause, "pause-command", "career-save"));
saving.Add(Action("Save as…", () => OpenCareerMenu(CareerMenu.SaveAs), "pause-command", "career-save-as"));
menu.Add(Action("Load game", () => OpenCareerMenu(CareerMenu.Load), "pause-command", "career-load-open"));
menu.Add(Action("Save and return to title", () => SaveAndLeave(false), "pause-command", "return-title"));
if (!Application.isEditor && Application.platform != RuntimePlatform.WebGLPlayer)
menu.Add(Action("Quit to desktop", () => Application.Quit(), "pause-command", "quit-game"));
menu.Add(Action("Save and quit", () => SaveAndLeave(true), "pause-command", "quit-game"));
menu.Add(Action("Restart first voyage guide", RestartGuide, "pause-command", "restart-guide"));
AddNotice(menu);
}
private void AttachCamera(VisualElement world)

View File

@@ -118,11 +118,13 @@ namespace Soundings
StationKind.Dining => (Facility.Dining, Facility.Restaurant, Facility.Restaurant),
StationKind.Bar => (Facility.Bar, Facility.CocktailLounge, Facility.CocktailLounge),
StationKind.Stage => (Facility.Entertainment, Facility.GrandTheater, Facility.GrandTheater),
StationKind.Retail => (Facility.Shop, Facility.ShoppingArcade, Facility.ShoppingArcade),
_ => (Facility.Amenity, Facility.ResortPool, Facility.ResortPool)
};
for (int i = 0; i < Ship.Decks.Count; i++)
foreach (Facility cell in Ship.Decks[i].Cells)
if (cell == room || cell == expansion || cell == premium)
if (cell == room || cell == expansion || cell == premium
|| station == StationKind.Pool && cell is Facility.Spa or Facility.WaterPark)
return $"Deck {i + 1}";
return "Guest decks";
}

View File

@@ -171,6 +171,10 @@ namespace Soundings
case Facility.CocktailLounge:
case Facility.GrandTheater:
case Facility.ResortPool:
case Facility.Shop:
case Facility.ShoppingArcade:
case Facility.Spa:
case Facility.WaterPark:
BuildWindow(floor, along, outward, side, width * .88f, 1.35f, 1.23f, 3,
(i + deck * 2) % 6 == 0 ? Paint.Lounge : Paint.Glass);
break;
@@ -445,12 +449,15 @@ namespace Soundings
Offset = DeckOffset(ship.Hull.Length, deck);
HalfBeam = DeckHalfBeam(ship.Hull.Beam * .5f, deck);
Facility[] cells = ship.Decks[deck].Cells;
Resort = System.Array.IndexOf(cells, Facility.ResortPool) >= 0;
bool waterPark = System.Array.IndexOf(cells, Facility.WaterPark) >= 0;
Resort = waterPark || System.Array.IndexOf(cells, Facility.ResortPool) >= 0;
Theater = System.Array.IndexOf(cells, Facility.GrandTheater) >= 0;
HasPool = Resort || ship.Count(Facility.Amenity) > 0;
PoolCenter = Offset + Length * (Resort ? .033f : .01f);
PoolHalfSize = Resort ? new Vector2(Mathf.Min(7.15f, Length * .089f), Mathf.Min(2.77f, HalfBeam * .39f))
: new Vector2(PoolHalfLength, PoolHalfWidth);
PoolHalfSize = waterPark
? new Vector2(Mathf.Min(8.95f, Length * .105f), Mathf.Min(3f, HalfBeam * .40f))
: Resort ? new Vector2(Mathf.Min(7.15f, Length * .089f), Mathf.Min(2.77f, HalfBeam * .39f))
: new Vector2(PoolHalfLength, PoolHalfWidth);
StageCenter = Offset - Length * .376f;
StageHalfWidth = Mathf.Min(2.85f, HalfBeam * .39f);
}

View File

@@ -35,7 +35,7 @@ namespace Soundings
if (!CheckSmoke(guidedCareer, "The guide is on by default")
|| !SubmitSmoke("guide-toggle") || !CheckSmoke(!guidedCareer, "Guide can be turned off at title")
|| !SubmitSmoke("guide-toggle") || !SubmitSmoke("start-used")
|| !SubmitSmoke("guide-toggle") || !SubmitSmoke("start-used") || !SubmitSmoke("replace")
|| !CheckSmoke(Ship?.Name == "MV Meridian" && guideContext == GuideStep.SetCourse, "Guided used start"))
yield break;
yield return CaptureSmoke(directory, "02-harbor");
@@ -378,7 +378,7 @@ namespace Soundings
|| !SubmitSmoke("guide-skip") || !CheckSmoke(company.TutorialStep == 0, "Guide can be skipped"))
yield break;
company.Cash = 2_000_000;
company.Cash = 3_000_000;
if (!SubmitSmoke("nav-1") || !SubmitSmoke("facility-larger")
|| !CheckSmoke(root.Q<Button>("facility-12")?.ClassListContains("work-tool-locked") == true,
"Larger venues show the lock on a Coastal hull")
@@ -434,9 +434,20 @@ namespace Soundings
for (int bay = 0; bay < 7; bay++)
if (!CheckSmoke(company.Build(Ship, 0, bay, Facility.Cabin) == null, "Fit flagship passenger berths"))
yield break;
if (!SubmitSmoke("nav-1") || !SubmitSmoke("deck-5") || !SubmitSmoke("facility-leisure")
|| !SubmitSmoke("facility-20") || !SubmitSmoke("facility-rotate") || !SubmitSmoke("berth-4")
|| !SubmitSmoke("facility-21") || !SubmitSmoke("berth-7")
|| !CheckSmoke(Ship.Decks[5].RotationAt(4) == 1 && Ship.Decks[5].AnchorAt(18, Ship.Hull.Columns) == 7,
"Rotate an L-shaped shopping arcade and fit an adjacent 2×2 spa")
|| !SubmitSmoke("deck-6") || !SubmitSmoke("facility-22") || !SubmitSmoke("facility-rotate") || !SubmitSmoke("berth-3")
|| !CheckSmoke(Ship.Decks[6].RotationAt(3) == 1 && Ship.Decks[6].AnchorAt(24, Ship.Hull.Columns) == 3,
"Rotate a 3×2 water park to span three rows"))
yield break;
yield return CaptureSmoke(directory, "15b-rotated-water-park-plan");
if (!CheckSmoke(company.Build(Ship, 7, 10, Facility.Restaurant) == null && company.Build(Ship, 7, 21, Facility.CocktailLounge) == null
&& company.Build(Ship, 7, 0, Facility.ResortPool) == null && company.Build(Ship, 7, 3, Facility.GrandTheater) == null
&& company.Build(Ship, 7, 14, Facility.GrandSuite) == null && VesselExterior.SunDeck(Ship).Theater
&& company.Build(Ship, 7, 14, Facility.GrandSuite) == null && company.Build(Ship, 7, 28, Facility.Shop) == null
&& VesselExterior.SunDeck(Ship).Theater
&& company.Refuel(Ship, 100) == null, "Fit and fuel the largest hull") || !SubmitSmoke("nav-0"))
yield break;
Ship flagship = Ship;
@@ -447,6 +458,18 @@ namespace Soundings
yield break;
holdCinematicClock = true;
yield return CapturePortAndSkipSmoke(directory, "16b-ocean-class-departure", 1.4f);
int retailPrice = livePassage.GetPrice(OnboardService.Retail) + 1;
if (!SubmitSmoke("passage-price-retail-plus") || !livePassage.TryWorkStation(StationKind.Retail, out _)
|| !CheckSmoke(livePassage.Get(OnboardService.Retail).Served > 0
&& livePassage.GetPrice(OnboardService.Retail) == retailPrice && livePassage.DiscountTicks(OnboardService.Retail) > 0,
"Shops serve passengers and support checkout promotions and onboard pricing"))
yield break;
MovePassageToSmoke(.18f);
if (!CheckSmoke(livePassage.Get(OnboardService.Retail).Revenue > 0 && livePassage.Expenses > 0,
"Shop orders record retail takings and wholesale expense")
|| !SubmitSmoke("passage-deck-6"))
yield break;
yield return CaptureSmoke(directory, "16c-water-park-cutaway");
if (!SubmitSmoke("passage-deck-7")
|| !CheckSmoke(passageDeck == 7, "Select the eighth deck during the voyage"))
yield break;
@@ -475,7 +498,10 @@ namespace Soundings
float flagshipPosition = flagshipHelm.Position.x;
if (!CheckSmoke(company.Refuel(regional, 60) == null, "Prepare the second fleet departure")
|| !SubmitSmoke("plan-voyage") || !SubmitSmoke("port-1") || !SubmitSmoke("dispatch")
|| !SubmitSmoke("plan-voyage") || !SubmitSmoke("port-1")
|| !CheckSmoke(root.Q<Button>("dispatch")?.enabledInHierarchy == true,
"The second departure is ready: " + company.DepartureBlock(Ship, company.Forecast(Ship, destination)))
|| !SubmitSmoke("dispatch")
|| !CheckSmoke(FleetStatus(regional).Session == livePassage && company.Cash - company.AvailableCash > firstReserve,
"Dispatch a second ship with an independent session and cash reservation"))
yield break;
@@ -495,6 +521,41 @@ namespace Soundings
"Returning to a ship restores its exact voyage, prices, and track"))
yield break;
MovePassageToSmoke(.30f);
if (!SubmitSmoke("passage-deck-7") || !SubmitSmoke("passage-special-retail") || !SubmitSmoke("company-menu"))
yield break;
int savedReserve = company.ReservedCash;
Company departingCompany = company;
if (!SubmitSmoke("career-save") || !SubmitSmoke("career-save-as"))
yield break;
TextField saveName = root.Q<TextField>("career-save-name");
if (!CheckSmoke(saveName != null, "Name the separate save slot"))
yield break;
saveName.value = "Fleet Crossing";
if (!SubmitSmoke("career-save-confirm") || !SubmitSmoke("career-load-open")
|| !CheckSmoke(careers.List().Count >= 3 && careerName == "Fleet Crossing", "Save as preserves existing careers"))
yield break;
FleetPassageSnapshot[] before = careers.Read(careerId)?.Passages;
if (!CheckSmoke(before?.Length == 2, "The named save contains both crossings"))
yield break;
yield return CaptureSmoke(directory, "19-saved-careers");
if (!SubmitSmoke("career-load-0"))
yield break;
FleetPassageSnapshot[] after = CaptureFleetPassages();
if (!CheckSmoke(company != departingCompany && careerMenu == CareerMenu.Closed && careerName == "Fleet Crossing",
"The load browser activates the selected save")
|| !CheckSmoke(after.Length == 2 && company.ReservedCash == savedReserve, "Both crossings retain their cash reserves")
|| !CheckSmoke(SameSavedCrossing(before[0], after[0]), "The background crossing retains its navigation and operation state")
|| !CheckSmoke(SameSavedCrossing(before[1], after[1]), "The foreground crossing retains its navigation and operation state")
|| !CheckSmoke(Ship.Decks[6].RotationAt(3) == 1 && Ship.Decks[5].RotationAt(4) == 1, "Both rotated layouts load intact")
|| !CheckSmoke(passageDeck == 7 && livePassage.GetPrice(OnboardService.Retail) == retailPrice
&& livePassage.DiscountTicks(OnboardService.Retail) > 0, "The selected deck and active shop sale resume"))
yield break;
flagship = Ship;
flagshipSession = livePassage;
flagshipHelm = passageHelm;
regional = company.Fleet[1];
regionalHelm = FleetStatus(regional).Helm;
int sailed = company.Voyages;
regionalHelm.SetProgress(1);
yield return null;
@@ -516,6 +577,11 @@ namespace Soundings
Application.Quit(0);
}
private static bool SameSavedCrossing(FleetPassageSnapshot before, FleetPassageSnapshot after) =>
before.ShipIndex == after.ShipIndex && before.Voyage.Destination == after.Voyage.Destination
&& JsonUtility.ToJson(before.Helm) == JsonUtility.ToJson(after.Helm)
&& JsonUtility.ToJson(before.Session) == JsonUtility.ToJson(after.Session);
private void MovePassageToSmoke(float progress)
{
passageHelm.SetProgress(progress);

View File

@@ -17,6 +17,14 @@ namespace Soundings
if (root == null)
return;
if (careerMenu != CareerMenu.Closed)
{
if (Input.GetKeyDown(KeyCode.Escape))
CloseCareerMenu();
return;
}
AutosaveCareer();
float delta = Time.unscaledDeltaTime;
if (harbor.PortCinematicActive)
{
@@ -40,6 +48,7 @@ namespace Soundings
else if (title && pendingStart.HasValue)
{
pendingStart = null;
careerError = null;
Render();
}
else if (!title)
@@ -70,6 +79,9 @@ namespace Soundings
if (title || paused || fleetOpen || EditingText())
return;
if (page == 1 && Input.GetKeyDown(KeyCode.R))
RotateDeckTool();
for (int i = 0; i < HotbarPages.Length; i++)
{
if (Input.GetKeyDown((KeyCode)((int)KeyCode.Alpha1 + i)))
@@ -259,6 +271,7 @@ namespace Soundings
page = 0;
Notify(null);
FocusPassage(passage, true);
Save();
if (!StartPortCinematic(quote.Origin, false))
Render();
}