From 86c50304dd3599d1229bad4612954001092810a4 Mon Sep 17 00:00:00 2001 From: Regalis Date: Wed, 28 Sep 2016 19:16:50 +0300 Subject: [PATCH] - saving after MainSub has been removed (i.e. saving after returning to map screen) doesn't break save files anymore - fixed subs getting left behind if the sub moves too far from the start/end position during the ending cinematic - map shows which LocationConnections have been passed through --- .../GameSession/GameModes/SinglePlayerMode.cs | 52 +++++++++---------- Subsurface/Source/Map/Map/Map.cs | 41 +++++++++++---- Subsurface/Source/Utils/SaveUtil.cs | 9 +--- 3 files changed, 57 insertions(+), 45 deletions(-) diff --git a/Subsurface/Source/GameSession/GameModes/SinglePlayerMode.cs b/Subsurface/Source/GameSession/GameModes/SinglePlayerMode.cs index 42a55be99..f76525739 100644 --- a/Subsurface/Source/GameSession/GameModes/SinglePlayerMode.cs +++ b/Subsurface/Source/GameSession/GameModes/SinglePlayerMode.cs @@ -26,6 +26,11 @@ namespace Barotrauma private bool savedOnStart; + private List subsToLeaveBehind; + + private Submarine leavingSub; + private bool atEndPosition; + public override Mission Mission { get @@ -208,12 +213,6 @@ namespace Barotrauma } endShiftButton.Draw(spriteBatch); - //chatBox.Draw(spriteBatch); - //textBox.Draw(spriteBatch); - - //timerBar.Draw(spriteBatch); - - //if (Game1.Client == null) endShiftButton.Draw(spriteBatch); } public override void Update(float deltaTime) @@ -240,10 +239,17 @@ namespace Barotrauma public override void End(string endMessage = "") { - isRunning = false; - //if (endMessage != "" || this.endMessage == null) this.endMessage = endMessage; + if (subsToLeaveBehind == null || leavingSub == null) + { + DebugConsole.ThrowError("Leaving submarine not selected -> selecting the closest one"); + + leavingSub = GetLeavingSub(); + + subsToLeaveBehind = GetSubsToLeaveBehind(leavingSub); + } + bool success = CrewManager.characters.Any(c => !c.IsDead); @@ -251,19 +257,13 @@ namespace Barotrauma if (success) { - var leavingSub = GetLeavingSub(); - - if (!Submarine.MainSub.AtEndPosition && !Submarine.MainSub.AtStartPosition) + if (leavingSub != Submarine.MainSub && !leavingSub.DockedTo.Contains(Submarine.MainSub)) { - System.Diagnostics.Debug.Assert(leavingSub != Submarine.MainSub); - Submarine oldMainSub = Submarine.MainSub; Submarine.MainSub = leavingSub; GameMain.GameSession.Submarine = leavingSub; - - List subsToLeaveBehind = GetSubsToLeaveBehind(leavingSub); - + foreach (Submarine sub in subsToLeaveBehind) { MapEntity.mapEntityList.RemoveAll(e => e.Submarine == sub && e is LinkedSubmarine); @@ -271,13 +271,11 @@ namespace Barotrauma } } - - if (Submarine.MainSub.AtEndPosition) + if (atEndPosition) { Map.MoveToNextLocation(); } - SaveUtil.SaveGame(GameMain.GameSession.SaveFile); } @@ -312,18 +310,18 @@ namespace Barotrauma private bool TryEndShift(GUIButton button, object obj) { - List subsNotDocked = new List(); - - var leavingSub = obj as Submarine; + leavingSub = obj as Submarine; if (leavingSub != null) { - subsNotDocked = GetSubsToLeaveBehind(leavingSub); + subsToLeaveBehind = GetSubsToLeaveBehind(leavingSub); } - if (subsNotDocked.Any()) + atEndPosition = leavingSub.AtEndPosition; + + if (subsToLeaveBehind.Any()) { string msg = ""; - if (subsNotDocked.Count==1) + if (subsToLeaveBehind.Count == 1) { msg = "One of your vessels isn't at the exit yet. Do you want to leave it behind?"; } @@ -335,7 +333,7 @@ namespace Barotrauma var msgBox = new GUIMessageBox("Warning", msg, new string[] {"Yes", "No"}); msgBox.Buttons[0].OnClicked += EndShift; msgBox.Buttons[0].OnClicked += msgBox.Close; - msgBox.Buttons[0].UserData = Submarine.Loaded.FindAll(s => !subsNotDocked.Contains(s)); + msgBox.Buttons[0].UserData = Submarine.Loaded.FindAll(s => !subsToLeaveBehind.Contains(s)); msgBox.Buttons[1].OnClicked += msgBox.Close; } @@ -353,7 +351,7 @@ namespace Barotrauma List leavingSubs = obj as List; if (leavingSubs == null) leavingSubs = new List() { GetLeavingSub() }; - + var cinematic = new TransitionCinematic(leavingSubs, GameMain.GameScreen.Cam, 5.0f); SoundPlayer.OverrideMusicType = CrewManager.characters.Any(c => !c.IsDead) ? "endshift" : "crewdead"; diff --git a/Subsurface/Source/Map/Map/Map.cs b/Subsurface/Source/Map/Map/Map.cs index bcbbab401..df8a5341d 100644 --- a/Subsurface/Source/Map/Map/Map.cs +++ b/Subsurface/Source/Map/Map/Map.cs @@ -72,7 +72,16 @@ namespace Barotrauma string[] discoveredStrs = discoveredStr.Split(','); for (int i = 0; i < discoveredStrs.Length; i++ ) { - map.locations[i].Discovered = discoveredStrs[i].ToLowerInvariant() == "true"; + int index = -1; + if (int.TryParse(discoveredStrs[i], out index)) map.locations[index].Discovered = true; + } + + string passedStr = ToolBox.GetAttributeString(element, "passed", ""); + string[] passedStrs = passedStr.Split(','); + for (int i = 0; i < passedStrs.Length; i++) + { + int index = -1; + if (int.TryParse(passedStrs[i], out index)) map.connections[index].Passed = true; } return map; @@ -226,6 +235,8 @@ namespace Barotrauma public void MoveToNextLocation() { + selectedConnection.Passed = true; + currentLocation = selectedLocation; currentLocation.Discovered = true; selectedLocation = null; @@ -291,7 +302,7 @@ namespace Barotrauma { crackColor = Color.Red; } - else if (!connection.Locations[0].Discovered || !connection.Locations[1].Discovered) + else if (!connection.Passed) { crackColor *= 0.2f; } @@ -407,9 +418,19 @@ namespace Barotrauma mapElement.Add(new XAttribute("seed", Seed)); mapElement.Add(new XAttribute("size", size)); - List discovered = locations.Select(l => l.Discovered).ToList(); + List discoveredLocations = new List(); + for (int i = 0; i < locations.Count; i++ ) + { + if (locations[i].Discovered) discoveredLocations.Add(i); + } + mapElement.Add(new XAttribute("discovered", string.Join(",", discoveredLocations))); - mapElement.Add(new XAttribute("discovered", string.Join(",", discovered))); + List passedConnections = new List(); + for (int i = 0; i < connections.Count; i++) + { + if (connections[i].Passed) passedConnections.Add(i); + } + mapElement.Add(new XAttribute("passed", string.Join(",", passedConnections))); element.Add(mapElement); } @@ -425,19 +446,21 @@ namespace Barotrauma public List CrackSegments; + public bool Passed; + private int missionsCompleted; private Mission mission; public Mission Mission { get - { - if (mission==null || mission.Completed) + { + if (mission == null || mission.Completed) { - if (mission !=null && mission.Completed) missionsCompleted++; + if (mission != null && mission.Completed) missionsCompleted++; long seed = (long)locations[0].MapPosition.X + (long)locations[0].MapPosition.Y * 100; - seed += (long)locations[1].MapPosition.X*10000 + (long)locations[1].MapPosition.Y * 1000000; + seed += (long)locations[1].MapPosition.X * 10000 + (long)locations[1].MapPosition.Y * 1000000; MTRandom rand = new MTRandom((int)((seed + missionsCompleted) % int.MaxValue)); @@ -450,8 +473,6 @@ namespace Barotrauma } } - - public Location[] Locations { get { return locations; } diff --git a/Subsurface/Source/Utils/SaveUtil.cs b/Subsurface/Source/Utils/SaveUtil.cs index 093e7dc35..3a4a3a5bb 100644 --- a/Subsurface/Source/Utils/SaveUtil.cs +++ b/Subsurface/Source/Utils/SaveUtil.cs @@ -23,21 +23,14 @@ namespace Barotrauma string tempPath = Path.Combine(SaveFolder, "temp"); - if (Directory.Exists(tempPath)) - { - Directory.Delete(tempPath, true); - } Directory.CreateDirectory(tempPath); try { - - - if (Submarine.MainSub != null) { Submarine.MainSub.FilePath = Path.Combine(tempPath, Submarine.MainSub.Name + ".sub"); - Submarine.MainSub.SaveAs(Submarine.MainSub.FilePath); + Submarine.MainSub.SaveAs(Submarine.MainSub.FilePath); } } catch (Exception e)