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

331 lines
20 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Collections;
using System.IO;
using UnityEngine;
using UnityEngine.UIElements;
namespace Soundings
{
public sealed partial class SoundingsApp
{
private IEnumerator VisualSmoke()
{
string[] args = Environment.GetCommandLineArgs();
int index = Array.IndexOf(args, "-soundings-smoke");
if (index + 1 >= args.Length)
{
Application.Quit(1);
yield break;
}
string directory = args[index + 1];
Directory.CreateDirectory(directory);
yield return CaptureSmoke(directory, "01-title");
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")
|| !CheckSmoke(Ship?.Name == "MV Meridian" && guideContext == GuideStep.SetCourse, "Guided used start"))
yield break;
yield return CaptureSmoke(directory, "02-harbor");
if (!SubmitSmoke("plan-voyage") || !CheckSmoke(page == 3 && destination == 1 && guideContext == GuideStep.Fare, "Set course and fare guide"))
yield break;
yield return CaptureSmoke(directory, "03-passage-chart");
int fare = Ship.Fare;
if (!SubmitSmoke("fare-plus") || !CheckSmoke(Ship.Fare == fare + 50 && guideContext == GuideStep.CastOff, "Fare control and departure guide"))
yield break;
if (!SubmitSmoke("port-plan-open"))
yield break;
IntegerField provisioning = root.Q<IntegerField>("port-food-units");
if (!CheckSmoke(provisioning != null && provisioning.value > 0, "Dockside orders show recommended provisions"))
yield break;
provisioning.value = 1120;
if (!SubmitSmoke("port-program-1") || !CheckSmoke(portFoodOrder == 1120 && portProgram == EntertainmentProgram.LiveMusic,
"Order an exact food quantity and book local musicians"))
yield break;
yield return CaptureSmoke(directory, "03a-dockside-orders");
if (!SubmitSmoke("port-plan-close"))
yield break;
if (!SubmitSmoke("weather-swell") || !CheckSmoke(PassageWeatherFor(0, 1) == WeatherCondition.Swell, "Select forecast conditions")
|| !SubmitSmoke("weather-calm"))
yield break;
if (!SubmitSmoke("dispatch") || !CheckSmoke(underway != null && livePassage != null && Ship.Port == 0
&& company.Voyages == 0 && PassageDuration(underway) >= 120 && livePassage.Assisted && underway.Weather == WeatherCondition.Calm
&& guideContext == GuideStep.AtSea && root.Q<Button>("guide-skip") != null
&& underway.Plan?.FoodUnits == 1120 && underway.Plan.Program == EntertainmentProgram.LiveMusic,
"Cast off into an assisted live crossing"))
yield break;
if (!CheckSmoke(passageAudio.CurrentAnnouncement == PassageAnnouncement.Departure && passageAudio.Caption.StartsWith("Welcome aboard"),
"Cast off starts the spoken welcome and its caption"))
yield break;
int mealPrice = livePassage.GetPrice(OnboardService.Meals);
int provisions = livePassage.ProvisionsRemaining;
if (!SubmitSmoke("passage-price-meals-plus") || !SubmitSmoke("passage-special-meals")
|| !CheckSmoke(provisions == 1120 && livePassage.GetPrice(OnboardService.Meals) == mealPrice + 1 && livePassage.DiscountTicks(OnboardService.Meals) > 0,
"Change live prices and start a meal special"))
yield break;
if (!CheckSmoke(passageAudio.CurrentAnnouncement == PassageAnnouncement.Departure,
"An on-demand special queues behind the ship's welcome"))
yield break;
Vector3 castingOff = harbor.PassageWorldPosition;
MovePassageToSmoke(.17f);
if (!CheckSmoke(harbor.PassageUsesPerspective && Vector3.Distance(castingOff, harbor.PassageWorldPosition) > 70f,
"Ship travels through the world in the exterior perspective view")
|| !CheckSmoke(livePassage.CrewCall == StationKind.Galley, "First crew call sends you to the galley")
|| !SubmitSmoke("passage-service") || !SubmitSmoke("service-area-1"))
yield break;
if (!CheckSmoke(!harbor.TryGetFacingStation(out _), "Station cannot be used from across the passage"))
yield break;
WalkSmoke(Vector2.up, 6);
if (!CheckSmoke(harbor.TryGetFacingStation(out StationKind galley) && galley == StationKind.Galley,
"Galley control becomes available as you approach the equipment"))
yield break;
yield return CaptureSmoke(directory, "03b-galley-crew-call");
if (!CheckSmoke(UseFacingStation() && livePassage.CrewRequestsCompleted == 1 && livePassage.GalleyBoost,
"Physical galley interaction answers the crew call and starts a paid extra shift")
|| !SubmitSmoke("passage-deck-all") || !SubmitSmoke("passage-business"))
yield break;
MovePassageToSmoke(.30f);
if (!CheckSmoke(livePassage.CurrentEvent.HasValue && livePassage.ProvisionsRemaining < provisions,
"Service uses inventory and opens a timed event"))
yield break;
for (int i = 0; i < 100; i++)
{
passageHelm.Advance(.1f, 0, livePassage.SpeedFactor, underway.Weather);
PresentVessel(.1f);
}
yield return CaptureSmoke(directory, "04-underway");
harbor.RotateView(112f);
yield return new WaitForSecondsRealtime(.38f);
yield return CaptureSmoke(directory, "04a-underway-wake");
if (!SubmitSmoke("passage-event-0") || !CheckSmoke(livePassage.Expenses > 0 && !livePassage.CurrentEvent.HasValue, "Resolve the event"))
yield break;
if (!SubmitSmoke("passage-deck-0") || !CheckSmoke(passageDeck == 0, "Inspect the cabin deck"))
yield break;
yield return CaptureSmoke(directory, "05-cabin-deck");
if (!SubmitSmoke("passage-deck-1") || !CheckSmoke(passageDeck == 1, "Inspect the second guest deck"))
yield break;
yield return CaptureSmoke(directory, "06-guest-deck");
if (!SubmitSmoke("passage-bridge") || !CheckSmoke(passageBridge && harbor.FirstPersonPositionIsClear, "Enter the first-person bridge"))
yield break;
yield return CaptureSmoke(directory, "06a-bridge");
Vector3 bridgeEntry = harbor.FirstPersonPosition;
WalkSmoke(Vector2.up, 35);
float bridgeWalk = Vector3.Distance(bridgeEntry, harbor.FirstPersonPosition);
if (!CheckSmoke(bridgeWalk > 1 && bridgeWalk < 3 && harbor.FirstPersonPositionIsClear, "Bridge console blocks grounded movement")
|| !SubmitSmoke("passage-camera-reset") || !CheckSmoke(UseFacingStation(), "Engage physical helm from its console")
|| !CheckSmoke(passageHelm.Manual, "Take physical control on the bridge"))
yield break;
passageHelm.Advance(8, 0, livePassage.SpeedFactor, underway.Weather);
float originalHeading = passageHelm.Heading;
for (int i = 0; i < 100; i++)
passageHelm.Advance(.1f, 1, livePassage.SpeedFactor, underway.Weather);
PresentVessel(.1f);
if (!CheckSmoke(passageHelm.Heading > originalHeading + 5 && passageHelm.Position.y > .3f, "Rudder changes the ship heading and track"))
yield break;
yield return CaptureSmoke(directory, "06a-manual-helm");
if (!SubmitSmoke("helm-order-0") || !CheckSmoke(passageHelm.PropulsionStopped, "Stop order at the helm"))
yield break;
float coastingSpeed = passageHelm.Speed;
passageHelm.Advance(.55f, 0, livePassage.SpeedFactor, underway.Weather);
if (!CheckSmoke(passageHelm.Speed > 0 && passageHelm.Speed < coastingSpeed, "Ship coasts when propulsion is stopped")
|| !SubmitSmoke("helm-toggle") || !CheckSmoke(!passageHelm.Manual && !passageHelm.PropulsionStopped, "Autopilot resumes propulsion"))
yield break;
if (!SubmitSmoke("passage-deck-0") || !SubmitSmoke("passage-explore")
|| !CheckSmoke(passageExploring && passageDeck == 0 && harbor.FirstPersonPositionIsClear, "Explore inside the cabin deck"))
yield break;
yield return CaptureSmoke(directory, "06a-cabin-corridor");
Vector3 corridorEntry = harbor.FirstPersonPosition;
WalkSmoke(Vector2.up, 9);
WalkSmoke(Vector2.right, 12);
Vector3 nearBulkhead = harbor.FirstPersonPosition;
if (!CheckSmoke(nearBulkhead.x > corridorEntry.x + 2 && Mathf.Abs(nearBulkhead.z - corridorEntry.z) < .8f,
"Cabin corridor is clear and bulkheads block sideways movement"))
yield break;
WalkSmoke(Vector2.up, 8);
WalkSmoke(Vector2.right, 6);
if (!CheckSmoke(Mathf.Abs(harbor.FirstPersonPosition.z - corridorEntry.z) > 1 && harbor.FirstPersonPositionIsClear,
"Walk into a cabin through its open doorway"))
yield break;
if (!SubmitSmoke("passage-service") || !CheckSmoke(passageServiceArea == 0 && harbor.FirstPersonPositionIsClear, "Enter engineering"))
yield break;
Vector3 serviceEntry = harbor.FirstPersonPosition;
WalkSmoke(Vector2.up, 38);
float serviceWalk = Vector3.Distance(serviceEntry, harbor.FirstPersonPosition);
if (!CheckSmoke(serviceWalk > 1.6f && serviceWalk < 5 && harbor.FirstPersonPositionIsClear, "Walk through an engineering doorway and stop at the machinery")
|| !SubmitSmoke("passage-camera-reset"))
yield break;
int cruiseBurn = livePassage.ProjectedFuelBurn;
if (!SubmitSmoke("service-engine-0") || !CheckSmoke(livePassage.ProjectedFuelBurn < cruiseBurn, "Economy throttle saves fuel")
|| !SubmitSmoke("service-assist") || !CheckSmoke(!livePassage.Assisted, "Switch to manual operations"))
yield break;
yield return CaptureSmoke(directory, "06b-engine-room");
if (!SubmitSmoke("service-area-1") || (!livePassage.GalleyBoost && !SubmitSmoke("service-operate"))
|| !CheckSmoke(livePassage.GalleyBoost, "Extend galley service"))
yield break;
yield return CaptureSmoke(directory, "06c-galley");
if (!SubmitSmoke("service-area-2") || !CheckSmoke(passageServiceArea == 2, "Inspect stores")
|| !SubmitSmoke("service-area-3") || !SubmitSmoke("service-operate") || !CheckSmoke(livePassage.RepairCredit > 0, "Service machinery")
|| !SubmitSmoke("service-area-4") || !SubmitSmoke("service-operate") || !CheckSmoke(livePassage.PumpsBoost, "Boost freshwater pumps")
|| !SubmitSmoke("service-area-5") || !SubmitSmoke("service-operate") || !CheckSmoke(livePassage.TreatmentBoost, "Boost sewage treatment"))
yield break;
if (!SubmitSmoke("company-menu") || !CheckSmoke(paused, "Pause voyage"))
yield break;
Vector2 pausedPosition = passageHelm.Position;
yield return new WaitForSecondsRealtime(.15f);
if (!CheckSmoke(passageHelm.Position == pausedPosition, "Paused passage clock") || !SubmitSmoke("resume-game"))
yield break;
if (!SubmitSmoke("dock-now") || !CheckSmoke(Ship.Port == 1 && company.Voyages == 1 && page == 4 && guideContext == GuideStep.Review
&& company.History[0].Plan.FoodUnits == 1120 && company.History[0].Onboard.CrewCalls == 1, "Arrival settles once and records the orders and crew call"))
yield break;
yield return CaptureSmoke(directory, "07-logbook");
if (!SubmitSmoke("voyage-0") || !SubmitSmoke("log-accounts") || !SubmitSmoke("log-voyages")
|| !SubmitSmoke("guide-finish") || !CheckSmoke(company.TutorialStep == 0, "Finish first voyage guide"))
yield break;
if (!SubmitSmoke("nav-1"))
yield break;
yield return CaptureSmoke(directory, "08-deck-plans");
if (!SubmitSmoke("deck-1") || !SubmitSmoke("facility-4") || !SubmitSmoke("berth-0")
|| !CheckSmoke(Ship.Decks[1].Cells[0] == Facility.Tank, "Deck placement")
|| !SubmitSmoke("add-deck") || !CheckSmoke(Ship.Decks.Count == 3 && deckIndex == 2, "Build a third deck")
|| !SubmitSmoke("facility-5") || !SubmitSmoke("berth-3") || !SubmitSmoke("facility-6") || !SubmitSmoke("berth-4")
|| !CheckSmoke(Ship.Decks[2].Cells[3] == Facility.Bar && Ship.Decks[2].Cells[4] == Facility.Amenity, "Fit a bar and amenity on a new deck")
|| !SubmitSmoke("facility-systems") || !SubmitSmoke("facility-7") || !SubmitSmoke("berth-0")
|| !CheckSmoke(Ship.Decks[2].Cells[0] == Facility.Galley, "Fit a service expansion on the new deck"))
yield break;
if (!SubmitSmoke("nav-3") || !SubmitSmoke("port-2") || !SubmitSmoke("permit")
|| !CheckSmoke(company.Permits[2], "Ports control"))
yield break;
yield return CaptureSmoke(directory, "09-ports");
if (!SubmitSmoke("chart-world") || !SubmitSmoke("port-12") || !CheckSmoke(inspectedPort == 12, "Global port chart"))
yield break;
yield return CaptureSmoke(directory, "10-world");
if (!SubmitSmoke("nav-0") || !SubmitSmoke("plan-voyage") || !SubmitSmoke("port-0") || !SubmitSmoke("weather-storm")
|| !SubmitSmoke("dispatch") || !CheckSmoke(underway.Weather == WeatherCondition.Storm
&& livePassage.Get(OnboardService.Amenities).Capacity == 0, "Rough sea closes outdoor amenities"))
yield break;
SelectPassageDeck(2);
if (!CheckSmoke(passageDeck == 2, "Visit the newly fitted third deck during the next crossing"))
yield break;
MovePassageToSmoke(.42f);
yield return CaptureSmoke(directory, "11-new-service-deck");
SetPassageSpeed(4);
if (!CheckSmoke(passageSpeed == 4, "Fast-forward setting"))
yield break;
MovePassageToSmoke(.95f);
float timeout = Time.realtimeSinceStartup + 15;
while (underway != null && Time.realtimeSinceStartup < timeout)
yield return null;
if (!CheckSmoke(underway == null && Ship.Port == 0 && company.Voyages == 2, "Timed passage and second settlement"))
yield break;
if (!SubmitSmoke("company-menu") || !SubmitSmoke("return-title") || !SubmitSmoke("start-financed") || !SubmitSmoke("replace")
|| !CheckSmoke(company.Debt == 500000 && company.Fleet.Count == 0 && guideContext == GuideStep.GetShip, "Guided financed start"))
yield break;
yield return CaptureSmoke(directory, "12-shipyard");
if (!SubmitSmoke("buy-ship") || !CheckSmoke(Ship != null && Ship.Beds == 0 && page == 1 && guideContext == GuideStep.Cabins, "Ship commissioning and cabin guide"))
yield break;
yield return CaptureSmoke(directory, "13-new-hull");
if (!SubmitSmoke("facility-1"))
yield break;
for (int i = 0; i < StarterCabinModules; i++)
if (!SubmitSmoke($"berth-{i}"))
yield break;
if (!CheckSmoke(guideContext == GuideStep.Dining, "Starter cabin block advances to dining")
|| !SubmitSmoke("facility-2") || !SubmitSmoke($"berth-{StarterCabinModules}")
|| !CheckSmoke(guideContext == GuideStep.SetCourse, "Dining advances to course planning")
|| !SubmitSmoke("nav-0") || !SubmitSmoke("plan-voyage")
|| !CheckSmoke(guideContext == GuideStep.Bunker && company.Forecast(Ship, destination).NetIncome > 0,
"Unfueled hull shows bunker lesson for a profitable first sailing"))
yield break;
yield return CaptureSmoke(directory, "14-bunker-lesson");
if (!SubmitSmoke("buy-fuel") || !CheckSmoke(Ship.Fuel > 0 && guideContext == GuideStep.Fare, "Bunkering and guide progress")
|| !SubmitSmoke("guide-skip") || !CheckSmoke(company.TutorialStep == 0, "Guide can be skipped"))
yield break;
company.Cash = 2_000_000;
company.Voyages = 10;
company.Reputation = 70;
if (!SubmitSmoke("nav-2") || !SubmitSmoke("yard-2") || !SubmitSmoke("buy-ship")
|| !CheckSmoke(Ship.HullIndex == 1 && Ship.Decks.Count == 4, "Regional hull is delivered with four decks")
|| !SubmitSmoke("nav-0"))
yield break;
yield return CaptureSmoke(directory, "15-regional-hull");
if (!SubmitSmoke("nav-2") || !SubmitSmoke("yard-4"))
yield break;
TextField vesselName = root.Q<TextField>("vessel-name");
if (!CheckSmoke(vesselName != null, "Name the Ocean Class commission"))
yield break;
vesselName.value = "Crownhaven";
if (!SubmitSmoke("buy-ship")
|| !CheckSmoke(Ship.HullIndex == Market.Ocean && Ship.Decks.Count == 6, "Ocean Class is delivered with six decks")
|| !SubmitSmoke("add-deck") || !SubmitSmoke("add-deck")
|| !CheckSmoke(Ship.Decks.Count == 8, "Ocean Class can add two more decks"))
yield break;
if (!CheckSmoke(company.Build(Ship, 0, 0, Facility.Cabin) == null
&& company.Build(Ship, 1, 0, Facility.Dining) == null && company.Build(Ship, 7, 0, Facility.Bar) == null
&& company.Refuel(Ship, 100) == null, "Fit and fuel the largest hull") || !SubmitSmoke("nav-0"))
yield break;
yield return CaptureSmoke(directory, "16-ocean-class-hull");
if (!SubmitSmoke("plan-voyage") || !SubmitSmoke("port-1") || !SubmitSmoke("dispatch")
|| !SubmitSmoke("passage-deck-7") || !CheckSmoke(passageDeck == 7, "Select the eighth deck during the voyage"))
yield break;
yield return CaptureSmoke(directory, "17-ocean-class-cutaway");
if (!SubmitSmoke("passage-explore") || !CheckSmoke(harbor.FirstPersonPositionIsClear, "Walk safely on the eighth deck"))
yield break;
Debug.Log($"Soundings player smoke passed at {Screen.width} × {Screen.height}.");
Application.Quit(0);
}
private void MovePassageToSmoke(float progress)
{
passageHelm.SetProgress(progress);
livePassage.AdvanceTo(progress);
PresentVessel(0);
UpdatePassageUi(progress);
}
private void WalkSmoke(Vector2 movement, int steps)
{
for (int i = 0; i < steps; i++)
harbor.Walk(movement, .1f, true);
}
private bool SubmitSmoke(string element)
{
Button button = root.Q<Button>(element);
if (!CheckSmoke(button != null && button.enabledInHierarchy, "Available control: " + element))
return false;
using NavigationSubmitEvent navigation = NavigationSubmitEvent.GetPooled();
navigation.target = button;
button.SendEvent(navigation);
return true;
}
private static bool CheckSmoke(bool condition, string label)
{
if (!condition)
{
Debug.LogError("Soundings player smoke failed: " + label);
Application.Quit(1);
}
return condition;
}
private static IEnumerator CaptureSmoke(string directory, string name)
{
yield return null;
yield return null;
yield return new WaitForEndOfFrame();
Texture2D image = ScreenCapture.CaptureScreenshotAsTexture();
File.WriteAllBytes(Path.Combine(directory, name + ".png"), image.EncodeToPNG());
Destroy(image);
}
}
}