Parts of the submarine that are left behind in the level will stay there, it's possible to leave the level without the main sub (e.g. in an escape shuttle)

This commit is contained in:
Regalis
2016-07-16 16:14:51 +03:00
parent 8357532fc1
commit f8fec79785
7 changed files with 87 additions and 14 deletions
@@ -145,12 +145,12 @@ namespace Barotrauma
if (Submarine.MainSub == null) return; if (Submarine.MainSub == null) return;
if (Submarine.MainSub.AtEndPosition) if (Submarine.Loaded.Any(s=> s.AtEndPosition))
{ {
endShiftButton.Text = "Enter " + Map.SelectedLocation.Name; endShiftButton.Text = "Enter " + Map.SelectedLocation.Name;
endShiftButton.Draw(spriteBatch); endShiftButton.Draw(spriteBatch);
} }
else if (Submarine.MainSub.AtStartPosition) else if (Submarine.Loaded.Any(s => s.AtStartPosition))
{ {
endShiftButton.Text = "Enter " + Map.CurrentLocation.Name; endShiftButton.Text = "Enter " + Map.CurrentLocation.Name;
endShiftButton.Draw(spriteBatch); endShiftButton.Draw(spriteBatch);
@@ -204,6 +204,24 @@ namespace Barotrauma
Map.MoveToNextLocation(); Map.MoveToNextLocation();
} }
if (!Submarine.MainSub.AtEndPosition && !Submarine.MainSub.AtStartPosition)
{
Submarine newMainSub = Submarine.Loaded.Find(s => s.AtEndPosition || s.AtStartPosition);
Submarine oldMainSub = Submarine.MainSub;
Submarine.MainSub = newMainSub;
GameMain.GameSession.Submarine = newMainSub;
List<Submarine> subsToLeaveBehind = Submarine.Loaded.FindAll(s => s != Submarine.MainSub && !Submarine.MainSub.DockedTo.Contains(s));
foreach (Submarine sub in subsToLeaveBehind)
{
MapEntity.mapEntityList.RemoveAll(e => e.Submarine == sub && e is LinkedSubmarine);
LinkedSubmarine.CreateDummy(newMainSub, sub);
}
}
SaveUtil.SaveGame(GameMain.GameSession.SaveFile); SaveUtil.SaveGame(GameMain.GameSession.SaveFile);
} }
+2 -1
View File
@@ -54,6 +54,7 @@ namespace Barotrauma
public Submarine Submarine public Submarine Submarine
{ {
get { return submarine; } get { return submarine; }
set { submarine = value; }
} }
public string SaveFile public string SaveFile
@@ -124,7 +125,7 @@ namespace Barotrauma
DebugConsole.ThrowError("Couldn't start game session, submarine not selected"); DebugConsole.ThrowError("Couldn't start game session, submarine not selected");
return; return;
} }
if (reloadSub || Submarine.MainSub != submarine) submarine.Load(true); if (reloadSub || Submarine.MainSub != submarine) submarine.Load(true);
Submarine.MainSub = submarine; Submarine.MainSub = submarine;
+54 -8
View File
@@ -36,6 +36,7 @@ namespace Barotrauma
private string filePath; private string filePath;
private bool loadSub;
private Submarine sub; private Submarine sub;
private XElement saveElement; private XElement saveElement;
@@ -56,6 +57,14 @@ namespace Barotrauma
InsertToList(); InsertToList();
} }
public static LinkedSubmarine CreateDummy(Submarine mainSub, Submarine linkedSub)
{
LinkedSubmarine sl = new LinkedSubmarine(mainSub);
sl.sub = linkedSub;
return sl;
}
public static LinkedSubmarine CreateDummy(Submarine mainSub, string filePath, Vector2 position) public static LinkedSubmarine CreateDummy(Submarine mainSub, string filePath, Vector2 position)
{ {
@@ -280,15 +289,32 @@ namespace Barotrauma
} }
else else
{ {
if (!sub.DockedTo.Contains(Submarine.MainSub)) return null;
saveElement = new XElement("LinkedSubmarine"); saveElement = new XElement("LinkedSubmarine");
sub.SaveToXElement(saveElement); sub.SaveToXElement(saveElement);
} }
if (sub != null)
{
if (!sub.DockedTo.Contains(Submarine.MainSub))
{
saveElement.Add(new XAttribute("location", Level.Loaded.Seed));
saveElement.Add(new XAttribute("worldpos", ToolBox.Vector2ToString(sub.SubBody.Position)));
}
else
{
if (saveElement.Attribute("location") != null) saveElement.Attribute("location").Remove();
if (saveElement.Attribute("worldpos") != null) saveElement.Attribute("worldpos").Remove();
}
if (saveElement.Attribute("pos") != null) saveElement.Attribute("pos").Remove(); if (saveElement.Attribute("pos") != null) saveElement.Attribute("pos").Remove();
saveElement.Add(new XAttribute("pos", ToolBox.Vector2ToString(Position - Submarine.HiddenSubPosition))); saveElement.Add(new XAttribute("pos", ToolBox.Vector2ToString(Position - Submarine.HiddenSubPosition)));
}
parentElement.Add(saveElement); parentElement.Add(saveElement);
@@ -313,6 +339,15 @@ namespace Barotrauma
linkedSub = new LinkedSubmarine(submarine); linkedSub = new LinkedSubmarine(submarine);
linkedSub.saveElement = element; linkedSub.saveElement = element;
string levelSeed = ToolBox.GetAttributeString(element, "location", "");
if (!string.IsNullOrWhiteSpace(levelSeed) && GameMain.GameSession.Level != null && GameMain.GameSession.Level.Seed != levelSeed)
{
linkedSub.loadSub = false;
return;
}
linkedSub.loadSub = true;
linkedSub.rect.Location = pos.ToPoint(); linkedSub.rect.Location = pos.ToPoint();
} }
@@ -332,11 +367,22 @@ namespace Barotrauma
public override void OnMapLoaded() public override void OnMapLoaded()
{ {
if (Screen.Selected == GameMain.EditMapScreen) return; if (!loadSub) return;
sub = Submarine.Load(saveElement, false); sub = Submarine.Load(saveElement, false);
sub.SetPosition(WorldPosition - Submarine.WorldPosition);
sub.Submarine = Submarine; Vector2 worldPos = ToolBox.GetAttributeVector2(saveElement, "worldpos", Vector2.Zero);
if (worldPos != Vector2.Zero)
{
sub.SetPosition(worldPos);
}
else
{
sub.SetPosition(WorldPosition - Submarine.WorldPosition);
sub.Submarine = Submarine;
}
var linkedItem = linkedTo.FirstOrDefault(lt => (lt is Item) && ((Item)lt).GetComponent<DockingPort>() != null); var linkedItem = linkedTo.FirstOrDefault(lt => (lt is Item) && ((Item)lt).GetComponent<DockingPort>() != null);
+1
View File
@@ -191,6 +191,7 @@ namespace Barotrauma
public string FilePath public string FilePath
{ {
get { return filePath; } get { return filePath; }
set { filePath = value; }
} }
public bool AtDamageDepth public bool AtDamageDepth
+4 -1
View File
@@ -390,7 +390,10 @@ namespace Barotrauma
damagePos += submarine.Position + submarine.HiddenSubPosition; damagePos += submarine.Position + submarine.HiddenSubPosition;
SoundPlayer.PlayDamageSound(DamageSoundType.Pressure, 50.0f, damagePos, 10000.0f); SoundPlayer.PlayDamageSound(DamageSoundType.Pressure, 50.0f, damagePos, 10000.0f);
GameMain.GameScreen.Cam.Shake = depth * PressureDamageMultiplier * 0.1f; if (Character.Controlled != null && Character.Controlled.Submarine == submarine)
{
GameMain.GameScreen.Cam.Shake = depth * PressureDamageMultiplier * 0.1f;
}
Explosion.RangedStructureDamage(damagePos, depth * PressureDamageMultiplier * 50.0f, depth * PressureDamageMultiplier); Explosion.RangedStructureDamage(damagePos, depth * PressureDamageMultiplier * 50.0f, depth * PressureDamageMultiplier);
//SoundPlayer.PlayDamageSound(DamageSoundType.StructureBlunt, Rand.Range(0.0f, 100.0f), damagePos, 5000.0f); //SoundPlayer.PlayDamageSound(DamageSoundType.StructureBlunt, Rand.Range(0.0f, 100.0f), damagePos, 5000.0f);
+1 -1
View File
@@ -346,7 +346,7 @@ namespace Barotrauma
{ {
Vector2 bodyPosition = body.DrawPosition; Vector2 bodyPosition = body.DrawPosition;
PlayDamageSound(damageType, damage, bodyPosition); PlayDamageSound(damageType, damage, bodyPosition, 800.0f);
} }
public static void PlayDamageSound(DamageSoundType damageType, float damage, Vector2 position, float range = 2000.0f) public static void PlayDamageSound(DamageSoundType damageType, float damage, Vector2 position, float range = 2000.0f)
+5 -1
View File
@@ -31,9 +31,13 @@ namespace Barotrauma
try try
{ {
if (Submarine.MainSub != null) if (Submarine.MainSub != null)
{ {
Submarine.MainSub.SaveAs(Path.Combine(tempPath, Submarine.MainSub.Name+".sub")); Submarine.MainSub.FilePath = Path.Combine(tempPath, Submarine.MainSub.Name + ".sub");
Submarine.MainSub.SaveAs(Submarine.MainSub.FilePath);
} }
} }
catch (Exception e) catch (Exception e)