Started refactoring the submarine class in order to make it possible to add multiple submarines (or other movable structures)
This commit is contained in:
@@ -83,7 +83,7 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
public Gap(MapEntityPrefab prefab, Rectangle rectangle)
|
||||
: this (rectangle, Submarine.Loaded)
|
||||
: this (rectangle, Submarine.MainSub)
|
||||
{ }
|
||||
|
||||
public Gap(Rectangle newRect, Submarine submarine)
|
||||
@@ -253,7 +253,7 @@ namespace Barotrauma
|
||||
|
||||
var particle = GameMain.ParticleManager.CreateParticle(
|
||||
"watersplash",
|
||||
(Submarine.Loaded == null ? pos : pos + Submarine.Loaded.Position) - Vector2.UnitY * Rand.Range(0.0f, 10.0f),
|
||||
(Submarine == null ? pos : pos + Submarine.Position) - Vector2.UnitY * Rand.Range(0.0f, 10.0f),
|
||||
velocity);
|
||||
|
||||
if (particle != null)
|
||||
@@ -269,7 +269,7 @@ namespace Barotrauma
|
||||
|
||||
GameMain.ParticleManager.CreateParticle(
|
||||
"bubbles",
|
||||
Submarine.Loaded == null ? pos : pos + Submarine.Loaded.Position,
|
||||
Submarine == null ? pos : pos + Submarine.Position,
|
||||
flowForce / 10.0f);
|
||||
}
|
||||
}
|
||||
@@ -288,14 +288,14 @@ namespace Barotrauma
|
||||
|
||||
var splash = GameMain.ParticleManager.CreateParticle(
|
||||
"watersplash",
|
||||
Submarine.Loaded == null ? pos : pos + Submarine.Loaded.Position,
|
||||
Submarine == null ? pos : pos + Submarine.Position,
|
||||
-velocity, 0, FlowTargetHull);
|
||||
|
||||
if (splash != null) splash.Size = splash.Size * MathHelper.Clamp(rect.Width / 50.0f, 0.8f, 4.0f);
|
||||
|
||||
GameMain.ParticleManager.CreateParticle(
|
||||
"bubbles",
|
||||
Submarine.Loaded == null ? pos : pos + Submarine.Loaded.Position,
|
||||
Submarine == null ? pos : pos + Submarine.Position,
|
||||
flowForce / 2.0f, 0, FlowTargetHull);
|
||||
}
|
||||
}
|
||||
@@ -552,7 +552,7 @@ namespace Barotrauma
|
||||
}
|
||||
else
|
||||
{
|
||||
hull1.LethalPressure += (Submarine.Loaded != null && Submarine.Loaded.AtDamageDepth) ? 100.0f * deltaTime : 10.0f * deltaTime;
|
||||
hull1.LethalPressure += (Submarine != null && Submarine.AtDamageDepth) ? 100.0f * deltaTime : 10.0f * deltaTime;
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -567,7 +567,7 @@ namespace Barotrauma
|
||||
}
|
||||
if (hull1.Volume >= hull1.FullVolume - Hull.MaxCompress)
|
||||
{
|
||||
hull1.LethalPressure += (Submarine.Loaded != null && Submarine.Loaded.AtDamageDepth) ? 100.0f * deltaTime : 10.0f * deltaTime;
|
||||
hull1.LethalPressure += (Submarine != null && Submarine.AtDamageDepth) ? 100.0f * deltaTime : 10.0f * deltaTime;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -178,7 +178,7 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
public Hull(MapEntityPrefab prefab, Rectangle rectangle)
|
||||
: this (prefab, rectangle, Submarine.Loaded)
|
||||
: this (prefab, rectangle, Submarine.MainSub)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -821,7 +821,7 @@ namespace Barotrauma
|
||||
}
|
||||
else
|
||||
{
|
||||
var newFire = new FireSource(pos + Submarine.Loaded.Position, this, true);
|
||||
var newFire = new FireSource(pos + Submarine.Position, this, true);
|
||||
newFire.Size = new Vector2(
|
||||
newFire.Hull == null ? size : size * newFire.Hull.rect.Width,
|
||||
newFire.Size.Y);
|
||||
|
||||
@@ -30,7 +30,8 @@ namespace Barotrauma
|
||||
|
||||
public static readonly Vector2 GridSize = new Vector2(16.0f, 16.0f);
|
||||
|
||||
private static Submarine loaded;
|
||||
public static Submarine MainSub;
|
||||
private static List<Submarine> loaded;
|
||||
|
||||
private SubmarineBody subBody;
|
||||
|
||||
@@ -96,16 +97,16 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
public static Submarine Loaded
|
||||
{
|
||||
get { return loaded; }
|
||||
}
|
||||
//public static List<Submarine> Loaded
|
||||
//{
|
||||
// get { return loaded; }
|
||||
//}
|
||||
|
||||
public static Rectangle Borders
|
||||
public Rectangle Borders
|
||||
{
|
||||
get
|
||||
{
|
||||
return (loaded==null) ? Rectangle.Empty : Loaded.subBody.Borders;
|
||||
return subBody.Borders;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -255,17 +256,17 @@ namespace Barotrauma
|
||||
|
||||
//math/physics stuff ----------------------------------------------------
|
||||
|
||||
public static Vector2 MouseToWorldGrid(Camera cam)
|
||||
public static Vector2 MouseToWorldGrid(Camera cam, Submarine sub)
|
||||
{
|
||||
Vector2 position = PlayerInput.MousePosition;
|
||||
position = cam.ScreenToWorld(position);
|
||||
|
||||
Vector2 worldGridPos = VectorToWorldGrid(position);
|
||||
|
||||
if (loaded != null)
|
||||
if (sub != null)
|
||||
{
|
||||
worldGridPos.X += loaded.Position.X % GridSize.X;
|
||||
worldGridPos.Y += loaded.Position.Y % GridSize.Y;
|
||||
worldGridPos.X += sub.Position.X % GridSize.X;
|
||||
worldGridPos.Y += sub.Position.Y % GridSize.Y;
|
||||
}
|
||||
|
||||
return worldGridPos;
|
||||
@@ -435,6 +436,23 @@ namespace Barotrauma
|
||||
//Level.Loaded.Move(-amount);
|
||||
}
|
||||
|
||||
public static Submarine GetClosest(Vector2 worldPosition)
|
||||
{
|
||||
Submarine closest = null;
|
||||
float closestDist = 0.0f;
|
||||
foreach (Submarine sub in Submarine.loaded)
|
||||
{
|
||||
float dist = Vector2.Distance(worldPosition, sub.WorldPosition);
|
||||
if (closest == null || dist < closestDist)
|
||||
{
|
||||
closest = sub;
|
||||
closestDist = dist;
|
||||
}
|
||||
}
|
||||
|
||||
return closest;
|
||||
}
|
||||
|
||||
public override bool FillNetworkData(Networking.NetworkEventType type, NetBuffer message, object data)
|
||||
{
|
||||
if (subBody == null) return false;
|
||||
@@ -519,15 +537,17 @@ namespace Barotrauma
|
||||
|
||||
public static bool SaveCurrent(string filePath)
|
||||
{
|
||||
if (loaded==null)
|
||||
if (!loaded.Any())
|
||||
{
|
||||
loaded = new Submarine(filePath);
|
||||
loaded.Add(new Submarine(filePath));
|
||||
// return;
|
||||
}
|
||||
|
||||
loaded.filePath = filePath;
|
||||
System.Diagnostics.Debug.Assert(loaded.Count==1);
|
||||
|
||||
return loaded.SaveAs(filePath);
|
||||
loaded.First().filePath = filePath;
|
||||
|
||||
return loaded.First().SaveAs(filePath);
|
||||
}
|
||||
|
||||
public void CheckForErrors()
|
||||
@@ -766,8 +786,8 @@ namespace Barotrauma
|
||||
|
||||
subBody = new SubmarineBody(this);
|
||||
subBody.SetPosition(HiddenSubPosition);
|
||||
|
||||
loaded = this;
|
||||
|
||||
loaded.Add(this);
|
||||
|
||||
Hull.GenerateEntityGrid();
|
||||
|
||||
@@ -809,16 +829,19 @@ namespace Barotrauma
|
||||
|
||||
public static void Unload()
|
||||
{
|
||||
if (loaded == null) return;
|
||||
|
||||
Sound.OnGameEnd();
|
||||
|
||||
if (GameMain.LightManager != null) GameMain.LightManager.ClearLights();
|
||||
|
||||
loaded.Remove();
|
||||
|
||||
|
||||
foreach (Submarine sub in loaded)
|
||||
{
|
||||
sub.Remove();
|
||||
sub.Clear();
|
||||
}
|
||||
|
||||
loaded.Clear();
|
||||
loaded = null;
|
||||
}
|
||||
|
||||
private void Clear()
|
||||
|
||||
Reference in New Issue
Block a user