Make Soundings voyages playable with ship operations and guided tips
This commit is contained in:
@@ -6,9 +6,11 @@ namespace Soundings
|
||||
public sealed partial class SoundingsApp
|
||||
{
|
||||
private Voyage underway;
|
||||
private OnboardSession livePassage;
|
||||
private float passageElapsed;
|
||||
private VisualElement passageFill;
|
||||
private Label passageDistance;
|
||||
private int passageSpeed = 1, passageDeck = -1, passageServiceArea = -1;
|
||||
private bool passageFreeLook, passageCursorLocked;
|
||||
private bool passageBridge, passageExploring;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
@@ -32,15 +34,7 @@ namespace Soundings
|
||||
if (underway != null)
|
||||
{
|
||||
if (!paused)
|
||||
{
|
||||
passageElapsed += Time.unscaledDeltaTime;
|
||||
float duration = PassageDuration(underway);
|
||||
float progress = Mathf.Clamp01(passageElapsed / duration);
|
||||
harbor.SetPassage(progress);
|
||||
UpdatePassageInstrument(progress);
|
||||
if (progress >= 1)
|
||||
FinishVoyage();
|
||||
}
|
||||
UpdateActivePassage();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -59,7 +53,84 @@ namespace Soundings
|
||||
harbor.ResetView();
|
||||
}
|
||||
|
||||
private static float PassageDuration(Voyage voyage) => Mathf.Clamp(4.8f + voyage.Days * .56f, 6, 10);
|
||||
private void UpdateActivePassage()
|
||||
{
|
||||
float delta = Time.unscaledDeltaTime;
|
||||
passageElapsed += delta * passageSpeed * livePassage.SpeedFactor;
|
||||
float progress = Mathf.Clamp01(passageElapsed / PassageDuration(underway));
|
||||
livePassage.AdvanceTo(progress);
|
||||
harbor.SetPassage(progress);
|
||||
harbor.UpdatePassengers(livePassage, delta);
|
||||
if (progress >= 1)
|
||||
{
|
||||
FinishVoyage();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Input.GetMouseButton(1) || !Application.isFocused)
|
||||
SetPassageFreeLook(false);
|
||||
if (passageFreeLook && passageCursorLocked)
|
||||
{
|
||||
Vector2 look = new Vector2(Input.GetAxisRaw("Mouse X"), -Input.GetAxisRaw("Mouse Y")) * 10;
|
||||
if (look.sqrMagnitude > .001f)
|
||||
harbor.Look(look);
|
||||
}
|
||||
if (passageFreeLook || passageExploring || passageBridge)
|
||||
{
|
||||
float lift = passageExploring || passageBridge ? 0 : MoveAxis(KeyCode.E, KeyCode.Q);
|
||||
Vector3 movement = new Vector3(MoveAxis(KeyCode.D, KeyCode.A), lift, MoveAxis(KeyCode.W, KeyCode.S));
|
||||
if (movement.sqrMagnitude > 0)
|
||||
harbor.Fly(Vector3.ClampMagnitude(movement, 1), delta, Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift));
|
||||
}
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.Home))
|
||||
{
|
||||
if (passageServiceArea >= 0)
|
||||
harbor.ExploreServiceArea(passageServiceArea);
|
||||
else if (passageBridge)
|
||||
harbor.ViewBridge();
|
||||
else if (passageExploring)
|
||||
harbor.ExploreDeck(passageDeck);
|
||||
else
|
||||
harbor.ResetView();
|
||||
}
|
||||
if (Input.GetKeyDown(KeyCode.B))
|
||||
ViewPassageBridge();
|
||||
if (Input.GetKeyDown(KeyCode.V))
|
||||
ExplorePassageDeck();
|
||||
for (int i = 0; i <= Ship.Decks.Count; i++)
|
||||
{
|
||||
if (Input.GetKeyDown((KeyCode)((int)KeyCode.Alpha0 + i)))
|
||||
{
|
||||
SelectPassageDeck(i - 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
UpdatePassageUi(progress);
|
||||
UpdateServiceNavigation();
|
||||
}
|
||||
|
||||
private void SetPassageFreeLook(bool active)
|
||||
{
|
||||
if (active == passageFreeLook)
|
||||
return;
|
||||
passageFreeLook = active;
|
||||
if (Application.platform == RuntimePlatform.WebGLPlayer)
|
||||
return;
|
||||
passageCursorLocked = active;
|
||||
UnityEngine.Cursor.lockState = active ? CursorLockMode.Locked : CursorLockMode.None;
|
||||
UnityEngine.Cursor.visible = !active;
|
||||
}
|
||||
|
||||
private static float MoveAxis(KeyCode forward, KeyCode reverse) =>
|
||||
(Input.GetKey(forward) ? 1 : 0) - (Input.GetKey(reverse) ? 1 : 0);
|
||||
|
||||
// Real seconds at 1×. Put enough real time between onboard service windows to act.
|
||||
private static float PassageDuration(Voyage voyage)
|
||||
{
|
||||
float weather = voyage.Weather switch { WeatherCondition.Swell => 1.14f, WeatherCondition.Storm => 1.32f, _ => 1 };
|
||||
return Mathf.Clamp((90f + voyage.Miles * .125f + voyage.Days * 6f) * weather, 115f, 360f);
|
||||
}
|
||||
|
||||
private bool EditingText()
|
||||
{
|
||||
@@ -71,9 +142,10 @@ namespace Soundings
|
||||
|
||||
private void BeginVoyage(Voyage quote)
|
||||
{
|
||||
if (underway != null || Ship == null)
|
||||
Ship ship = Ship;
|
||||
if (underway != null || ship == null)
|
||||
return;
|
||||
string failure = company.DepartureBlock(Ship, quote);
|
||||
string failure = company.DepartureBlock(ship, quote);
|
||||
if (failure != null)
|
||||
{
|
||||
Apply(failure, null);
|
||||
@@ -81,11 +153,78 @@ namespace Soundings
|
||||
}
|
||||
|
||||
underway = quote;
|
||||
livePassage = new OnboardSession(ship, quote) { Assisted = company.Voyages < 3 && ship.HullIndex == 0 };
|
||||
passageElapsed = 0;
|
||||
passageSpeed = 1;
|
||||
passageDeck = passageServiceArea = -1;
|
||||
passageBridge = passageExploring = false;
|
||||
passageBusinessOpen = true;
|
||||
SetPassageFreeLook(false);
|
||||
fleetOpen = shipActionsOpen = false;
|
||||
page = 0;
|
||||
Notify(null);
|
||||
harbor.BeginPassage();
|
||||
harbor.BeginPassage(quote.Weather);
|
||||
harbor.ShowDeck(passageDeck);
|
||||
harbor.UpdatePassengers(livePassage, 0);
|
||||
Render();
|
||||
}
|
||||
|
||||
private void SelectPassageDeck(int index)
|
||||
{
|
||||
if (underway == null || index < -1 || index >= Ship.Decks.Count ||
|
||||
(passageDeck == index && !passageBridge && !passageExploring && passageServiceArea < 0))
|
||||
return;
|
||||
passageDeck = index;
|
||||
passageServiceArea = -1;
|
||||
passageBridge = passageExploring = false;
|
||||
harbor.ShowDeck(index);
|
||||
harbor.ResetView();
|
||||
Render();
|
||||
}
|
||||
|
||||
private void ViewPassageBridge()
|
||||
{
|
||||
if (underway == null)
|
||||
return;
|
||||
passageBridge = true;
|
||||
passageExploring = false;
|
||||
passageDeck = passageServiceArea = -1;
|
||||
harbor.ViewBridge();
|
||||
Render();
|
||||
}
|
||||
|
||||
private void ExplorePassageDeck()
|
||||
{
|
||||
if (underway == null)
|
||||
return;
|
||||
if (passageDeck < 0)
|
||||
passageDeck = Ship.Decks.Count - 1;
|
||||
passageBridge = false;
|
||||
passageExploring = true;
|
||||
passageServiceArea = -1;
|
||||
harbor.ExploreDeck(passageDeck);
|
||||
Render();
|
||||
}
|
||||
|
||||
private void ExploreServiceArea(int index)
|
||||
{
|
||||
if (underway == null || index < 0 || index >= ServiceDeckModel.Areas.Length)
|
||||
return;
|
||||
if (passageServiceArea < 0)
|
||||
passageBusinessOpen = false;
|
||||
passageBridge = false;
|
||||
passageExploring = true;
|
||||
passageDeck = -1;
|
||||
passageServiceArea = index;
|
||||
harbor.ExploreServiceArea(index);
|
||||
Render();
|
||||
}
|
||||
|
||||
private void SetPassageSpeed(int speed)
|
||||
{
|
||||
if (underway == null || (speed != 1 && speed != 2 && speed != 4) || speed == passageSpeed)
|
||||
return;
|
||||
passageSpeed = speed;
|
||||
Render();
|
||||
}
|
||||
|
||||
@@ -94,13 +233,16 @@ namespace Soundings
|
||||
if (underway == null || paused)
|
||||
return;
|
||||
Voyage voyage = underway;
|
||||
livePassage.AdvanceTo(1);
|
||||
string failure = company.Sail(Ship, voyage.Destination, livePassage);
|
||||
|
||||
underway = null;
|
||||
passageFill = null;
|
||||
passageDistance = null;
|
||||
livePassage = null;
|
||||
passageServiceArea = -1;
|
||||
serviceReadout = null;
|
||||
SetPassageFreeLook(false);
|
||||
harbor.EndPassage();
|
||||
|
||||
Ship ship = Ship;
|
||||
string failure = company.Sail(ship, voyage.Destination);
|
||||
if (failure == null)
|
||||
{
|
||||
ResetItinerary();
|
||||
@@ -112,31 +254,5 @@ namespace Soundings
|
||||
}
|
||||
Apply(failure, $"Arrived in {Market.Ports[voyage.Destination].Name}.");
|
||||
}
|
||||
|
||||
private void DrawUnderway(VisualElement workspace)
|
||||
{
|
||||
var passage = Add(workspace, "underway-instrument");
|
||||
AddText(passage, "Underway", "eyebrow passage-kicker");
|
||||
string route = $"{Market.Ports[underway.Origin].Name} → {Market.Ports[underway.Destination].Name}";
|
||||
AddDisplay(passage, route, "passage-route");
|
||||
var trace = Add(passage, "passage-trace");
|
||||
passageFill = Add(trace, "passage-progress");
|
||||
var footer = Add(passage, "passage-footer");
|
||||
passageDistance = AddText(footer, "", "passage-distance");
|
||||
footer.Add(Action("Skip to arrival", FinishVoyage, "passage-skip", "dock-now"));
|
||||
float duration = PassageDuration(underway);
|
||||
UpdatePassageInstrument(Mathf.Clamp01(passageElapsed / duration));
|
||||
}
|
||||
|
||||
private void UpdatePassageInstrument(float progress)
|
||||
{
|
||||
if (passageFill == null || passageDistance == null)
|
||||
return;
|
||||
passageFill.style.width = Length.Percent(100 * progress);
|
||||
int miles = Mathf.RoundToInt(underway.Miles * (1 - progress));
|
||||
string label = $"{underway.ShipName} / {miles:N0} nm to port";
|
||||
if (passageDistance.text != label)
|
||||
passageDistance.text = label;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user