Started refactoring the submarine class in order to make it possible to add multiple submarines (or other movable structures)
This commit is contained in:
Binary file not shown.
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using System.Linq;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
@@ -178,9 +179,11 @@ namespace Barotrauma
|
||||
if (GameMain.Config.KeyBind(InputType.Up).IsDown()) moveCam.Y += moveSpeed;
|
||||
}
|
||||
|
||||
if (Submarine.Loaded!=null && Screen.Selected == GameMain.GameScreen)
|
||||
if (Submarine.MainSub != null && Screen.Selected == GameMain.GameScreen)
|
||||
{
|
||||
moveCam += FarseerPhysics.ConvertUnits.ToDisplayUnits(Submarine.Loaded.Velocity*deltaTime);
|
||||
|
||||
|
||||
moveCam += FarseerPhysics.ConvertUnits.ToDisplayUnits(Submarine.MainSub.Velocity*deltaTime);
|
||||
}
|
||||
|
||||
moveCam = moveCam * deltaTime * 60.0f;
|
||||
|
||||
@@ -164,15 +164,15 @@ namespace Barotrauma
|
||||
|
||||
GUI.DrawLine(spriteBatch,
|
||||
new Vector2(Character.WorldPosition.X, -Character.WorldPosition.Y),
|
||||
new Vector2(pathSteering.CurrentPath.CurrentNode.Position.X+Submarine.Loaded.Position.X, -(pathSteering.CurrentPath.CurrentNode.Position.Y+Submarine.Loaded.Position.Y)),
|
||||
new Vector2(pathSteering.CurrentPath.CurrentNode.WorldPosition.X, -pathSteering.CurrentPath.CurrentNode.WorldPosition.Y),
|
||||
Color.LightGreen);
|
||||
|
||||
|
||||
for (int i = 1; i < pathSteering.CurrentPath.Nodes.Count; i++)
|
||||
{
|
||||
GUI.DrawLine(spriteBatch,
|
||||
new Vector2(pathSteering.CurrentPath.Nodes[i].Position.X + Submarine.Loaded.Position.X, -(pathSteering.CurrentPath.Nodes[i].Position.Y + Submarine.Loaded.Position.Y)),
|
||||
new Vector2(pathSteering.CurrentPath.Nodes[i - 1].Position.X + Submarine.Loaded.Position.X, -(pathSteering.CurrentPath.Nodes[i-1].Position.Y + Submarine.Loaded.Position.Y)),
|
||||
new Vector2(pathSteering.CurrentPath.Nodes[i].WorldPosition.X, -pathSteering.CurrentPath.Nodes[i].WorldPosition.Y),
|
||||
new Vector2(pathSteering.CurrentPath.Nodes[i - 1].WorldPosition.Y, -pathSteering.CurrentPath.Nodes[i-1].WorldPosition.Y),
|
||||
Color.LightGreen);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ namespace Barotrauma
|
||||
Vector2 pos = host.SimPosition;
|
||||
if (character!=null && character.Submarine==null)
|
||||
{
|
||||
pos -= Submarine.Loaded.SimPosition;
|
||||
pos -= Submarine.MainSub.SimPosition;
|
||||
}
|
||||
|
||||
currentPath = pathFinder.FindPath(pos, target);
|
||||
@@ -107,7 +107,7 @@ namespace Barotrauma
|
||||
Vector2 pos2 = host.SimPosition;
|
||||
if (character != null && character.Submarine == null)
|
||||
{
|
||||
pos2 -= Submarine.Loaded.SimPosition;
|
||||
pos2 -= Submarine.MainSub.SimPosition;
|
||||
}
|
||||
return currentTarget-pos2;
|
||||
}
|
||||
@@ -120,7 +120,7 @@ namespace Barotrauma
|
||||
Vector2 pos = host.SimPosition;
|
||||
if (character != null && character.Submarine == null)
|
||||
{
|
||||
pos -= Submarine.Loaded.SimPosition;
|
||||
pos -= Submarine.MainSub.SimPosition;
|
||||
}
|
||||
|
||||
if (currentPath.CurrentNode!= null && currentPath.CurrentNode.Ladders!=null)
|
||||
|
||||
@@ -89,7 +89,7 @@ namespace Barotrauma
|
||||
}
|
||||
else if (target.Submarine == null)
|
||||
{
|
||||
currTargetPos -= Submarine.Loaded.SimPosition;
|
||||
currTargetPos -= character.Submarine.SimPosition;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace Barotrauma
|
||||
if (currentTarget != null)
|
||||
{
|
||||
Vector2 pos = character.SimPosition;
|
||||
if (character != null && character.Submarine == null) pos -= Submarine.Loaded.SimPosition;
|
||||
if (character != null && character.Submarine == null) pos -= Submarine.MainSub.SimPosition;
|
||||
|
||||
var path = pathSteering.PathFinder.FindPath(pos, currentTarget.SimPosition);
|
||||
if (path.Cost > 200.0f && character.AnimController.CurrentHull!=null) return;
|
||||
|
||||
@@ -594,7 +594,7 @@ namespace Barotrauma
|
||||
|
||||
CurrentHull = newHull;
|
||||
|
||||
character.Submarine = CurrentHull == null ? null : Submarine.Loaded;
|
||||
character.Submarine = currentHull == null ? null : currentHull.Submarine;
|
||||
|
||||
UpdateCollisionCategories();
|
||||
}
|
||||
|
||||
@@ -855,7 +855,10 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
cursorPosition = cam.ScreenToWorld(PlayerInput.MousePosition);
|
||||
if (AnimController.CurrentHull != null) cursorPosition -= Submarine.Loaded.Position;
|
||||
if (AnimController.CurrentHull != null && AnimController.CurrentHull.Submarine != null)
|
||||
{
|
||||
cursorPosition -= AnimController.CurrentHull.Submarine.Position;
|
||||
}
|
||||
|
||||
Vector2 mouseSimPos = ConvertUnits.ToSimUnits(cursorPosition);
|
||||
|
||||
@@ -1006,12 +1009,9 @@ namespace Barotrauma
|
||||
if (needsAir)
|
||||
{
|
||||
bool protectedFromPressure = PressureProtection > 0.0f;
|
||||
|
||||
if (Submarine.Loaded != null && Level.Loaded != null)
|
||||
{
|
||||
protectedFromPressure = protectedFromPressure && WorldPosition.Y > SubmarineBody.DamageDepth;
|
||||
}
|
||||
|
||||
protectedFromPressure = protectedFromPressure && WorldPosition.Y > SubmarineBody.DamageDepth;
|
||||
|
||||
if (!protectedFromPressure &&
|
||||
(AnimController.CurrentHull == null || AnimController.CurrentHull.LethalPressure >= 80.0f))
|
||||
{
|
||||
|
||||
@@ -213,8 +213,6 @@ namespace Barotrauma
|
||||
break;
|
||||
case "near":
|
||||
case "close":
|
||||
if (Submarine.Loaded == null) break;
|
||||
|
||||
float closestDist = 0.0f;
|
||||
foreach (WayPoint wp in WayPoint.WayPointList)
|
||||
{
|
||||
@@ -223,7 +221,7 @@ namespace Barotrauma
|
||||
//don't spawn inside hulls
|
||||
if (Hull.FindHull(wp.WorldPosition, null) != null) continue;
|
||||
|
||||
float dist = Vector2.Distance(wp.WorldPosition, Submarine.Loaded.WorldPosition);
|
||||
float dist = Vector2.Distance(wp.WorldPosition, GameMain.GameScreen.Cam.WorldViewCenter);
|
||||
|
||||
if (spawnPoint == null || dist < closestDist)
|
||||
{
|
||||
@@ -319,7 +317,9 @@ namespace Barotrauma
|
||||
Character.Controlled = Character.CharacterList.Find(c => !c.IsNetworkPlayer && c.Name.ToLowerInvariant() == commands[1]);
|
||||
break;
|
||||
case "godmode":
|
||||
Submarine.Loaded.GodMode = !Submarine.Loaded.GodMode;
|
||||
if (Submarine.MainSub == null) return;
|
||||
|
||||
Submarine.MainSub.GodMode = !Submarine.MainSub.GodMode;
|
||||
break;
|
||||
case "dumpids":
|
||||
int count = commands.Length < 2 ? 10 : int.Parse(commands[1]);
|
||||
@@ -438,8 +438,11 @@ namespace Barotrauma
|
||||
return;
|
||||
}
|
||||
|
||||
if (Submarine.SaveCurrent(System.IO.Path.Combine(Submarine.SavePath, fileName +".sub"))) NewMessage("map saved", Color.Green);
|
||||
Submarine.Loaded.CheckForErrors();
|
||||
if (Submarine.SaveCurrent(System.IO.Path.Combine(Submarine.SavePath, fileName + ".sub")))
|
||||
{
|
||||
NewMessage("Sub saved", Color.Green);
|
||||
//Submarine.Loaded.First().CheckForErrors();
|
||||
}
|
||||
|
||||
break;
|
||||
case "loadmap":
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace Barotrauma
|
||||
state = 2;
|
||||
break;
|
||||
case 2:
|
||||
if (!Submarine.Loaded.AtEndPosition && !Submarine.Loaded.AtStartPosition) return;
|
||||
if (!Submarine.MainSub.AtEndPosition && !Submarine.MainSub.AtStartPosition) return;
|
||||
|
||||
Finished();
|
||||
state = 3;
|
||||
|
||||
@@ -96,7 +96,7 @@ namespace Barotrauma
|
||||
|
||||
public override void End()
|
||||
{
|
||||
if (Submarine.Loaded != null && Submarine.Loaded.AtEndPosition)
|
||||
if (Submarine.MainSub != null && Submarine.MainSub.AtEndPosition)
|
||||
{
|
||||
int deliveredItemCount = items.Count(i => i.CurrentHull != null && i.Condition > 0.0f);
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace Barotrauma
|
||||
radarPosition = monster.Position;
|
||||
}
|
||||
else if (GameMain.Client == null)
|
||||
{ Vector2 diff = monster.WorldPosition-Submarine.Loaded.WorldPosition;
|
||||
{ Vector2 diff = monster.WorldPosition - Submarine.MainSub.WorldPosition;
|
||||
monster.Enabled = FarseerPhysics.ConvertUnits.ToSimUnits(diff.Length()) < NetConfig.CharacterIgnoreDistance;
|
||||
}
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ namespace Barotrauma
|
||||
state = 1;
|
||||
break;
|
||||
case 1:
|
||||
if (!Submarine.Loaded.AtEndPosition && !Submarine.Loaded.AtStartPosition) return;
|
||||
if (!Submarine.MainSub.AtEndPosition && !Submarine.MainSub.AtStartPosition) return;
|
||||
ShowMessage(state);
|
||||
state = 2;
|
||||
break;
|
||||
|
||||
@@ -83,7 +83,7 @@ namespace Barotrauma
|
||||
{
|
||||
if (monster.IsDead) continue;
|
||||
|
||||
if (!isStarted && Vector2.Distance(monster.WorldPosition, Submarine.Loaded.WorldPosition) < 5000.0f) isStarted = true;
|
||||
if (!isStarted && Vector2.Distance(monster.WorldPosition, Submarine.MainSub.WorldPosition) < 5000.0f) isStarted = true;
|
||||
|
||||
monstersDead = false;
|
||||
break;
|
||||
|
||||
@@ -414,10 +414,10 @@ namespace Barotrauma
|
||||
"Camera pos: " + GameMain.GameScreen.Cam.Position,
|
||||
new Vector2(10, 70), Color.White);
|
||||
|
||||
if (Submarine.Loaded!=null)
|
||||
if (Submarine.MainSub != null)
|
||||
{
|
||||
spriteBatch.DrawString(Font,
|
||||
"Sub pos: " + Submarine.Loaded.Position,
|
||||
"Sub pos: " + Submarine.MainSub.Position,
|
||||
new Vector2(10, 90), Color.White);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,14 +143,14 @@ namespace Barotrauma
|
||||
|
||||
CrewManager.Draw(spriteBatch);
|
||||
|
||||
if (Submarine.Loaded == null) return;
|
||||
if (Submarine.MainSub == null) return;
|
||||
|
||||
if (Submarine.Loaded.AtEndPosition)
|
||||
if (Submarine.MainSub.AtEndPosition)
|
||||
{
|
||||
endShiftButton.Text = "Enter " + Map.SelectedLocation.Name;
|
||||
endShiftButton.Draw(spriteBatch);
|
||||
}
|
||||
else if (Submarine.Loaded.AtStartPosition)
|
||||
else if (Submarine.MainSub.AtStartPosition)
|
||||
{
|
||||
endShiftButton.Text = "Enter " + Map.CurrentLocation.Name;
|
||||
endShiftButton.Draw(spriteBatch);
|
||||
@@ -199,7 +199,7 @@ namespace Barotrauma
|
||||
|
||||
if (success)
|
||||
{
|
||||
if (Submarine.Loaded.AtEndPosition)
|
||||
if (Submarine.MainSub.AtEndPosition)
|
||||
{
|
||||
Map.MoveToNextLocation();
|
||||
}
|
||||
@@ -240,7 +240,7 @@ namespace Barotrauma
|
||||
{
|
||||
isRunning = false;
|
||||
|
||||
var cinematic = new TransitionCinematic(Submarine.Loaded, GameMain.GameScreen.Cam, 5.0f);
|
||||
var cinematic = new TransitionCinematic(Submarine.MainSub, GameMain.GameScreen.Cam, 5.0f);
|
||||
|
||||
SoundPlayer.OverrideMusicType = CrewManager.characters.Any(c => !c.IsDead) ? "endshift" : "crewdead";
|
||||
|
||||
@@ -253,12 +253,12 @@ namespace Barotrauma
|
||||
{
|
||||
while (cinematic.Running)
|
||||
{
|
||||
if (Submarine.Loaded == null) yield return CoroutineStatus.Success;
|
||||
if (Submarine.MainSub == null) yield return CoroutineStatus.Success;
|
||||
|
||||
yield return CoroutineStatus.Running;
|
||||
}
|
||||
|
||||
if (Submarine.Loaded == null) yield return CoroutineStatus.Success;
|
||||
if (Submarine.MainSub == null) yield return CoroutineStatus.Success;
|
||||
|
||||
End("");
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ namespace Barotrauma
|
||||
endMessage = traitorCharacter.Name + " was a traitor! ";
|
||||
endMessage += (traitorCharacter.Info.Gender == Gender.Male) ? "His" : "Her";
|
||||
endMessage += " task was to assassinate " + targetCharacter.Name + ". ";
|
||||
endMessage += (Submarine.Loaded.AtEndPosition) ?
|
||||
endMessage += (Submarine.MainSub.AtEndPosition) ?
|
||||
"The task was unsuccessful - the has submarine reached its destination." :
|
||||
"The task was unsuccessful.";
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace Barotrauma.Tutorials
|
||||
|
||||
//spawn some fish next to the player
|
||||
GameMain.GameScreen.BackgroundCreatureManager.SpawnSprites(2,
|
||||
Submarine.Loaded.Position + Character.Controlled.Position);
|
||||
Submarine.MainSub.Position + Character.Controlled.Position);
|
||||
|
||||
yield return new WaitForSeconds(4.0f);
|
||||
|
||||
@@ -276,7 +276,7 @@ namespace Barotrauma.Tutorials
|
||||
|
||||
infoBox = CreateInfoFrame("Steer the submarine downwards, heading further into the cavern.");
|
||||
|
||||
while (Submarine.Loaded.WorldPosition.Y > 24600.0f)
|
||||
while (Submarine.MainSub.WorldPosition.Y > 24600.0f)
|
||||
{
|
||||
yield return CoroutineStatus.Running;
|
||||
}
|
||||
@@ -300,7 +300,7 @@ namespace Barotrauma.Tutorials
|
||||
bool broken = false;
|
||||
do
|
||||
{
|
||||
Submarine.Loaded.Velocity = Vector2.Zero;
|
||||
Submarine.MainSub.Velocity = Vector2.Zero;
|
||||
|
||||
moloch.AIController.SelectTarget(steering.Item.CurrentHull.AiTarget);
|
||||
Vector2 steeringDir = windows[0].WorldPosition - moloch.WorldPosition;
|
||||
@@ -349,7 +349,7 @@ namespace Barotrauma.Tutorials
|
||||
}
|
||||
}
|
||||
|
||||
Submarine.Loaded.GodMode = true;
|
||||
Submarine.MainSub.GodMode = true;
|
||||
|
||||
var capacitor1 = Item.ItemList.Find(i => i.HasTag("capacitor1")).GetComponent<PowerContainer>();
|
||||
var capacitor2 = Item.ItemList.Find(i => i.HasTag("capacitor1")).GetComponent<PowerContainer>();
|
||||
@@ -462,7 +462,7 @@ namespace Barotrauma.Tutorials
|
||||
yield return CoroutineStatus.Running;
|
||||
}
|
||||
|
||||
Submarine.Loaded.GodMode = false;
|
||||
Submarine.MainSub.GodMode = false;
|
||||
|
||||
infoBox = CreateInfoFrame("The creature has died. Now you should fix the damages in the control room: " +
|
||||
"Grab a welding tool from the closet in the railgun room.");
|
||||
@@ -588,7 +588,7 @@ namespace Barotrauma.Tutorials
|
||||
GameMain.GameScreen.Cam.TargetPos = Vector2.Zero;
|
||||
GameMain.LightManager.LosEnabled = false;
|
||||
|
||||
var cinematic = new TransitionCinematic(Submarine.Loaded, GameMain.GameScreen.Cam, 5.0f);
|
||||
var cinematic = new TransitionCinematic(Submarine.MainSub, GameMain.GameScreen.Cam, 5.0f);
|
||||
|
||||
while (cinematic.Running)
|
||||
{
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace Barotrauma.Tutorials
|
||||
public virtual void Initialize()
|
||||
{
|
||||
|
||||
GameMain.GameSession = new GameSession(Submarine.Loaded, "", GameModePreset.list.Find(gm => gm.Name.ToLowerInvariant() == "tutorial"));
|
||||
GameMain.GameSession = new GameSession(Submarine.MainSub, "", GameModePreset.list.Find(gm => gm.Name.ToLowerInvariant() == "tutorial"));
|
||||
(GameMain.GameSession.gameMode as TutorialMode).tutorialType = this;
|
||||
|
||||
GameMain.GameSession.StartShift("tuto1");
|
||||
|
||||
@@ -121,7 +121,7 @@ namespace Barotrauma
|
||||
return;
|
||||
}
|
||||
|
||||
if (reloadSub || Submarine.Loaded != submarine) submarine.Load();
|
||||
if (reloadSub || Submarine.MainSub != submarine) submarine.Load();
|
||||
|
||||
if (level != null)
|
||||
{
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace Barotrauma
|
||||
|
||||
string text = infoList[Rand.Int(infoList.Count)];
|
||||
|
||||
if (Submarine.Loaded!=null) text = text.Replace("[sub]", Submarine.Loaded.Name);
|
||||
if (Submarine.MainSub != null) text = text.Replace("[sub]", Submarine.MainSub.Name);
|
||||
if (GameMain.GameSession != null && GameMain.GameSession.Map != null)
|
||||
{
|
||||
if (GameMain.GameSession.Map.CurrentLocation!=null)
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace Barotrauma
|
||||
bool singleplayer = GameMain.NetworkMember == null;
|
||||
|
||||
bool gameOver = gameSession.CrewManager.characters.All(c => c.IsDead);
|
||||
bool progress = Submarine.Loaded.AtEndPosition;
|
||||
bool progress = Submarine.MainSub.AtEndPosition;
|
||||
|
||||
GUIFrame frame = new GUIFrame(new Rectangle(0, 0, GameMain.GraphicsWidth, GameMain.GraphicsHeight), Color.Black * 0.8f);
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ namespace Barotrauma.Items.Components
|
||||
Msg = "";
|
||||
}
|
||||
|
||||
if (attachedByDefault || (Screen.Selected == GameMain.EditMapScreen && Submarine.Loaded != null)) Use(1.0f);
|
||||
if (attachedByDefault || (Screen.Selected == GameMain.EditMapScreen)) Use(1.0f);
|
||||
|
||||
|
||||
//holdAngle = ToolBox.GetAttributeFloat(element, "holdangle", 0.0f);
|
||||
|
||||
@@ -86,7 +86,7 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
Vector2 currForce = new Vector2((force / 100.0f) * maxForce * (voltage / minVoltage), 0.0f);
|
||||
|
||||
Submarine.Loaded.ApplyForce(currForce);
|
||||
item.Submarine.ApplyForce(currForce);
|
||||
|
||||
if (item.CurrentHull != null)
|
||||
{
|
||||
|
||||
@@ -36,6 +36,8 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
public override void DrawHUD(SpriteBatch spriteBatch, Character character)
|
||||
{
|
||||
if (item.Submarine == null) return;
|
||||
|
||||
int width = GuiFrame.Rect.Width, height = GuiFrame.Rect.Height;
|
||||
int x = GuiFrame.Rect.X;
|
||||
int y = GuiFrame.Rect.Y;
|
||||
@@ -48,12 +50,12 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
Rectangle miniMap = new Rectangle(x + 20, y + 40, width - 40, height - 60);
|
||||
|
||||
float size = Math.Min((float)miniMap.Width / (float)Submarine.Borders.Width, (float)miniMap.Height / (float)Submarine.Borders.Height);
|
||||
float size = Math.Min((float)miniMap.Width / (float)item.Submarine.Borders.Width, (float)miniMap.Height / (float)item.Submarine.Borders.Height);
|
||||
foreach (Hull hull in Hull.hullList)
|
||||
{
|
||||
Rectangle hullRect = new Rectangle(
|
||||
miniMap.X + (int)((hull.Rect.X - Submarine.HiddenSubPosition.X - Submarine.Borders.X) * size),
|
||||
miniMap.Y - (int)((hull.Rect.Y - Submarine.HiddenSubPosition.Y - Submarine.Borders.Y) * size),
|
||||
miniMap.X + (int)((hull.Rect.X - Submarine.HiddenSubPosition.X - item.Submarine.Borders.X) * size),
|
||||
miniMap.Y - (int)((hull.Rect.Y - Submarine.HiddenSubPosition.Y - item.Submarine.Borders.Y) * size),
|
||||
(int)(hull.Rect.Width * size),
|
||||
(int)(hull.Rect.Height * size));
|
||||
|
||||
|
||||
@@ -124,38 +124,41 @@ namespace Barotrauma.Items.Components
|
||||
float radius = rect.Width / 2.0f;
|
||||
|
||||
float displayScale = radius / range;
|
||||
|
||||
if (DetectSubmarineWalls)
|
||||
|
||||
foreach (Submarine submarine in Submarine.Loaded)
|
||||
{
|
||||
for (int i = 0; i < Submarine.Loaded.HullVertices.Count; i++)
|
||||
{
|
||||
Vector2 start = ConvertUnits.ToDisplayUnits(Submarine.Loaded.HullVertices[i]);
|
||||
Vector2 end = ConvertUnits.ToDisplayUnits(Submarine.Loaded.HullVertices[(i + 1) % Submarine.Loaded.HullVertices.Count]);
|
||||
if (item.Submarine == submarine && !DetectSubmarineWalls) continue;
|
||||
|
||||
if (item.CurrentHull!=null)
|
||||
for (int i = 0; i < submarine.HullVertices.Count; i++)
|
||||
{
|
||||
Vector2 start = ConvertUnits.ToDisplayUnits(submarine.HullVertices[i]);
|
||||
Vector2 end = ConvertUnits.ToDisplayUnits(submarine.HullVertices[(i + 1) % submarine.HullVertices.Count]);
|
||||
|
||||
if (item.Submarine == submarine)
|
||||
{
|
||||
start += Rand.Vector(500.0f);
|
||||
end += Rand.Vector(500.0f);
|
||||
}
|
||||
|
||||
CreateBlipsForLine(
|
||||
start + Submarine.Loaded.WorldPosition,
|
||||
end + Submarine.Loaded.WorldPosition,
|
||||
start + submarine.WorldPosition,
|
||||
end + submarine.WorldPosition,
|
||||
radius, displayScale, 200.0f, 2.0f);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
|
||||
|
||||
if (item.Submarine != null && !DetectSubmarineWalls)
|
||||
{
|
||||
float simScale = displayScale * Physics.DisplayToSimRation;
|
||||
|
||||
Vector2 offset = ConvertUnits.ToSimUnits(Submarine.Loaded.WorldPosition - item.WorldPosition);
|
||||
Vector2 offset = ConvertUnits.ToSimUnits(item.Submarine.WorldPosition - item.WorldPosition);
|
||||
|
||||
for (int i = 0; i < Submarine.Loaded.HullVertices.Count; i++)
|
||||
for (int i = 0; i < item.Submarine.HullVertices.Count; i++)
|
||||
{
|
||||
Vector2 start = (Submarine.Loaded.HullVertices[i] + offset) * simScale;
|
||||
Vector2 start = (item.Submarine.HullVertices[i] + offset) * simScale;
|
||||
start.Y = -start.Y;
|
||||
Vector2 end = (Submarine.Loaded.HullVertices[(i + 1) % Submarine.Loaded.HullVertices.Count] + offset) * simScale;
|
||||
Vector2 end = (item.Submarine.HullVertices[(i + 1) % item.Submarine.HullVertices.Count] + offset) * simScale;
|
||||
end.Y = -end.Y;
|
||||
|
||||
GUI.DrawLine(spriteBatch, center + start, center + end, Color.Green);
|
||||
|
||||
@@ -163,10 +163,10 @@ namespace Barotrauma.Items.Components
|
||||
Rectangle velRect = new Rectangle(x + 20, y + 20, width - 40, height - 40);
|
||||
//GUI.DrawRectangle(spriteBatch, velRect, Color.White, false);
|
||||
|
||||
if (Submarine.Loaded != null && Level.Loaded != null)
|
||||
if (item.Submarine != null && Level.Loaded != null)
|
||||
{
|
||||
Vector2 realWorldVelocity = ConvertUnits.ToDisplayUnits(Submarine.Loaded.Velocity * Physics.DisplayToRealWorldRatio) * 3.6f;
|
||||
float realWorldDepth = Math.Abs(Submarine.Loaded.Position.Y - Level.Loaded.Size.Y) * Physics.DisplayToRealWorldRatio;
|
||||
Vector2 realWorldVelocity = ConvertUnits.ToDisplayUnits(item.Submarine.Velocity * Physics.DisplayToRealWorldRatio) * 3.6f;
|
||||
float realWorldDepth = Math.Abs(item.Submarine.Position.Y - Level.Loaded.Size.Y) * Physics.DisplayToRealWorldRatio;
|
||||
GUI.DrawString(spriteBatch, new Vector2(x + 20, y + height - 65),
|
||||
"Velocity: " + (int)realWorldVelocity.X + " km/h", Color.LightGreen, null, 0, GUI.SmallFont);
|
||||
GUI.DrawString(spriteBatch, new Vector2(x + 20, y + height - 50),
|
||||
@@ -220,7 +220,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
if (autopilotRayCastTimer <= 0.0f && steeringPath.NextNode != null)
|
||||
{
|
||||
Vector2 diff = Vector2.Normalize(ConvertUnits.ToSimUnits(steeringPath.NextNode.Position - Submarine.Loaded.WorldPosition));
|
||||
Vector2 diff = Vector2.Normalize(ConvertUnits.ToSimUnits(steeringPath.NextNode.Position - item.Submarine.WorldPosition));
|
||||
|
||||
bool nextVisible = true;
|
||||
for (int x = -1; x < 2; x += 2)
|
||||
@@ -228,9 +228,9 @@ namespace Barotrauma.Items.Components
|
||||
for (int y = -1; y < 2; y += 2)
|
||||
{
|
||||
Vector2 cornerPos =
|
||||
new Vector2(Submarine.Borders.Width * x, Submarine.Borders.Height * y) / 2.0f;
|
||||
new Vector2(item.Submarine.Borders.Width * x, item.Submarine.Borders.Height * y) / 2.0f;
|
||||
|
||||
cornerPos = ConvertUnits.ToSimUnits(cornerPos * 1.2f + Submarine.Loaded.WorldPosition);
|
||||
cornerPos = ConvertUnits.ToSimUnits(cornerPos * 1.2f + item.Submarine.WorldPosition);
|
||||
|
||||
float dist = Vector2.Distance(cornerPos, steeringPath.NextNode.SimPosition);
|
||||
|
||||
|
||||
@@ -366,7 +366,7 @@ namespace Barotrauma.Items.Components
|
||||
for (int i = 0; i < Nodes.Count; i++)
|
||||
{
|
||||
Vector2 worldPos = Nodes[i];
|
||||
if (Submarine.Loaded != null) worldPos += Submarine.Loaded.Position + Submarine.HiddenSubPosition;
|
||||
if (item.Submarine != null) worldPos += item.Submarine.Position + Submarine.HiddenSubPosition;
|
||||
worldPos.Y = -worldPos.Y;
|
||||
|
||||
GUI.DrawRectangle(spriteBatch, worldPos + new Vector2(-3, -3), new Vector2(6, 6), item.Color, true, 0.0f);
|
||||
@@ -407,7 +407,7 @@ namespace Barotrauma.Items.Components
|
||||
MapEntity.DisableSelect = true;
|
||||
//Nodes[(int)selectedNodeIndex] = GameMain.EditMapScreen.Cam.ScreenToWorld(PlayerInput.MousePosition)-Submarine.HiddenSubPosition+Submarine.Loaded.Position;
|
||||
|
||||
Vector2 nodeWorldPos = GameMain.EditMapScreen.Cam.ScreenToWorld(PlayerInput.MousePosition) - Submarine.HiddenSubPosition - Submarine.Loaded.Position;// Nodes[(int)selectedNodeIndex];
|
||||
Vector2 nodeWorldPos = GameMain.EditMapScreen.Cam.ScreenToWorld(PlayerInput.MousePosition) - Submarine.HiddenSubPosition - item.Submarine.Position;// Nodes[(int)selectedNodeIndex];
|
||||
|
||||
nodeWorldPos.X = MathUtils.Round(nodeWorldPos.X, Submarine.GridSize.X / 2.0f);
|
||||
nodeWorldPos.Y = MathUtils.Round(nodeWorldPos.Y, Submarine.GridSize.Y / 2.0f);
|
||||
@@ -428,10 +428,10 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
private void DrawSection(SpriteBatch spriteBatch, Vector2 start, Vector2 end, Color color, float width = 0.3f)
|
||||
{
|
||||
if (Submarine.Loaded!=null)
|
||||
if (item.Submarine != null)
|
||||
{
|
||||
start += Submarine.Loaded.DrawPosition + Submarine.HiddenSubPosition;
|
||||
end += Submarine.Loaded.DrawPosition + Submarine.HiddenSubPosition;
|
||||
start += item.Submarine.DrawPosition + Submarine.HiddenSubPosition;
|
||||
end += item.Submarine.DrawPosition + Submarine.HiddenSubPosition;
|
||||
}
|
||||
|
||||
start.Y = -start.Y;
|
||||
|
||||
@@ -525,7 +525,7 @@ namespace Barotrauma
|
||||
CurrentHull = Hull.FindHull(WorldPosition, CurrentHull);
|
||||
if (body != null)
|
||||
{
|
||||
Submarine = CurrentHull == null ? null : Submarine.Loaded;
|
||||
Submarine = CurrentHull == null ? null : CurrentHull.Submarine;
|
||||
body.Submarine = Submarine;
|
||||
}
|
||||
|
||||
|
||||
@@ -109,7 +109,7 @@ namespace Barotrauma
|
||||
|
||||
public override void UpdatePlacing(SpriteBatch spriteBatch, Camera cam)
|
||||
{
|
||||
Vector2 position = Submarine.MouseToWorldGrid(cam);
|
||||
Vector2 position = Submarine.MouseToWorldGrid(cam, Submarine.MainSub);
|
||||
|
||||
if (PlayerInput.RightButtonClicked())
|
||||
{
|
||||
@@ -121,10 +121,10 @@ namespace Barotrauma
|
||||
{
|
||||
if (PlayerInput.LeftButtonClicked())
|
||||
{
|
||||
var item = new Item(new Rectangle((int)position.X, (int)position.Y, (int)sprite.size.X, (int)sprite.size.Y), this, Submarine.Loaded);
|
||||
var item = new Item(new Rectangle((int)position.X, (int)position.Y, (int)sprite.size.X, (int)sprite.size.Y), this, Submarine.MainSub);
|
||||
//constructor.Invoke(lobject);
|
||||
item.Submarine = Submarine.Loaded;
|
||||
item.SetTransform(ConvertUnits.ToSimUnits(Submarine.Loaded==null ? item.Position : item.Position - Submarine.Loaded.Position), 0.0f);
|
||||
item.Submarine = Submarine.MainSub;
|
||||
item.SetTransform(ConvertUnits.ToSimUnits(Submarine.MainSub==null ? item.Position : item.Position - Submarine.MainSub.Position), 0.0f);
|
||||
item.FindHull();
|
||||
|
||||
placePosition = Vector2.Zero;
|
||||
@@ -152,11 +152,11 @@ namespace Barotrauma
|
||||
|
||||
if (PlayerInput.LeftButtonReleased())
|
||||
{
|
||||
var item = new Item(new Rectangle((int)placePosition.X, (int)placePosition.Y, (int)placeSize.X, (int)placeSize.Y), this, Submarine.Loaded);
|
||||
var item = new Item(new Rectangle((int)placePosition.X, (int)placePosition.Y, (int)placeSize.X, (int)placeSize.Y), this, Submarine.MainSub);
|
||||
placePosition = Vector2.Zero;
|
||||
|
||||
item.Submarine = Submarine.Loaded;
|
||||
item.SetTransform(ConvertUnits.ToSimUnits(Submarine.Loaded == null ? item.Position : item.Position - Submarine.Loaded.Position), 0.0f);
|
||||
item.Submarine = Submarine.MainSub;
|
||||
item.SetTransform(ConvertUnits.ToSimUnits(Submarine.MainSub == null ? item.Position : item.Position - Submarine.MainSub.Position), 0.0f);
|
||||
item.FindHull();
|
||||
|
||||
//selected = null;
|
||||
|
||||
@@ -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