From bf0c12ce5260eca289d3e0a02aa492a1443619ee Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Tue, 24 Jul 2018 14:34:27 +0300 Subject: [PATCH] The number of completed missions in a level connection is saved (-> reloading doesn't reset the mission in the connection to the initial one). Fixes #517 --- .../BarotraumaShared/Source/Map/Map/Map.cs | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/Barotrauma/BarotraumaShared/Source/Map/Map/Map.cs b/Barotrauma/BarotraumaShared/Source/Map/Map/Map.cs index eb7eb91af..607f06e6d 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Map/Map.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Map/Map.cs @@ -418,12 +418,13 @@ namespace Barotrauma if (int.TryParse(discoveredStrs[i], out index)) locations[index].Discovered = true; } - string passedStr = element.GetAttributeString("passed", ""); - string[] passedStrs = passedStr.Split(','); - for (int i = 0; i < passedStrs.Length; i++) + foreach (XElement subElement in element.Elements()) { - int index = -1; - if (int.TryParse(passedStrs[i], out index)) connections[index].Passed = true; + if (subElement.Name.ToString() != "connection") continue; + int connectionIndex = subElement.GetAttributeInt("i", -1); + if (connectionIndex < 0 || connectionIndex >= connections.Count) continue; + connections[connectionIndex].Passed = true; + connections[connectionIndex].MissionsCompleted = subElement.GetAttributeInt("m", 0); } } @@ -442,12 +443,15 @@ namespace Barotrauma } mapElement.Add(new XAttribute("discovered", string.Join(",", discoveredLocations))); - List passedConnections = new List(); for (int i = 0; i < connections.Count; i++) { - if (connections[i].Passed) passedConnections.Add(i); + if (!connections[i].Passed) continue; + + var connectionElement = new XElement("connection", new XAttribute("i", i)); + if (connections[i].MissionsCompleted > 0) connectionElement.Add(new XAttribute("m", connections[i].MissionsCompleted)); + mapElement.Add(connectionElement); + } - mapElement.Add(new XAttribute("passed", string.Join(",", passedConnections))); element.Add(mapElement); } @@ -467,7 +471,7 @@ namespace Barotrauma public bool Passed; - private int missionsCompleted; + public int MissionsCompleted; private Mission mission; public Mission Mission @@ -476,12 +480,12 @@ namespace Barotrauma { 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; - MTRandom rand = new MTRandom((int)((seed + missionsCompleted) % int.MaxValue)); + MTRandom rand = new MTRandom((int)((seed + MissionsCompleted) % int.MaxValue)); if (rand.NextDouble() < 0.3f) return null; @@ -518,8 +522,7 @@ namespace Barotrauma public LocationConnection(Location location1, Location location2) { locations = new Location[] { location1, location2 }; - - missionsCompleted = 0; + MissionsCompleted = 0; } public Location OtherLocation(Location location)