- 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
This commit is contained in:
Regalis
2016-09-28 19:16:50 +03:00
parent c5ce3a75a2
commit 86c50304dd
3 changed files with 57 additions and 45 deletions
@@ -26,6 +26,11 @@ namespace Barotrauma
private bool savedOnStart;
private List<Submarine> 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<Submarine> 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<Submarine> subsNotDocked = new List<Submarine>();
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<Submarine> leavingSubs = obj as List<Submarine>;
if (leavingSubs == null) leavingSubs = new List<Submarine>() { GetLeavingSub() };
var cinematic = new TransitionCinematic(leavingSubs, GameMain.GameScreen.Cam, 5.0f);
SoundPlayer.OverrideMusicType = CrewManager.characters.Any(c => !c.IsDead) ? "endshift" : "crewdead";
+31 -10
View File
@@ -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<bool> discovered = locations.Select(l => l.Discovered).ToList();
List<int> discoveredLocations = new List<int>();
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<int> passedConnections = new List<int>();
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<Vector2[]> 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; }
+1 -8
View File
@@ -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)