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

View File

@@ -36,6 +36,7 @@ namespace Barotrauma
private string filePath;
private bool loadSub;
private Submarine sub;
private XElement saveElement;
@@ -56,6 +57,14 @@ namespace Barotrauma
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)
{
@@ -280,15 +289,32 @@ namespace Barotrauma
}
else
{
if (!sub.DockedTo.Contains(Submarine.MainSub)) return null;
saveElement = new XElement("LinkedSubmarine");
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();
saveElement.Add(new XAttribute("pos", ToolBox.Vector2ToString(Position - Submarine.HiddenSubPosition)));
if (saveElement.Attribute("pos") != null) saveElement.Attribute("pos").Remove();
saveElement.Add(new XAttribute("pos", ToolBox.Vector2ToString(Position - Submarine.HiddenSubPosition)));
}
parentElement.Add(saveElement);
@@ -313,6 +339,15 @@ namespace Barotrauma
linkedSub = new LinkedSubmarine(submarine);
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();
}
@@ -332,11 +367,22 @@ namespace Barotrauma
public override void OnMapLoaded()
{
if (Screen.Selected == GameMain.EditMapScreen) return;
if (!loadSub) return;
sub = Submarine.Load(saveElement, false);
sub.SetPosition(WorldPosition - Submarine.WorldPosition);
sub.Submarine = Submarine;
sub = Submarine.Load(saveElement, false);
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);

View File

@@ -191,6 +191,7 @@ namespace Barotrauma
public string FilePath
{
get { return filePath; }
set { filePath = value; }
}
public bool AtDamageDepth

View File

@@ -390,7 +390,10 @@ namespace Barotrauma
damagePos += submarine.Position + submarine.HiddenSubPosition;
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);
//SoundPlayer.PlayDamageSound(DamageSoundType.StructureBlunt, Rand.Range(0.0f, 100.0f), damagePos, 5000.0f);