Removed the Entity.MoveWithLevel property, fixed artifacts and other items from ruins not being saved. Closes #694

This commit is contained in:
Joonas Rikkonen
2018-08-20 16:23:40 +03:00
parent 2f6cb84b5e
commit 3747852c13
10 changed files with 41 additions and 47 deletions
@@ -355,9 +355,9 @@ namespace Barotrauma
NewMessage("Removed " + me.Name + " (simposition " + me.SimPosition + ")", Color.Orange); NewMessage("Removed " + me.Name + " (simposition " + me.SimPosition + ")", Color.Orange);
MapEntity.mapEntityList.RemoveAt(i); MapEntity.mapEntityList.RemoveAt(i);
} }
else if (me.MoveWithLevel) else if (!me.ShouldBeSaved)
{ {
NewMessage("Removed " + me.Name + " (MoveWithLevel==true)", Color.Orange); NewMessage("Removed " + me.Name + " (!ShouldBeSaved)", Color.Orange);
MapEntity.mapEntityList.RemoveAt(i); MapEntity.mapEntityList.RemoveAt(i);
} }
else if (me is Item) else if (me is Item)
@@ -180,7 +180,7 @@ namespace Barotrauma
} }
} }
if (WayPoint.WayPointList.Find(wp => !wp.MoveWithLevel && wp.SpawnType == SpawnType.Path) == null) if (!WayPoint.WayPointList.Any(wp => wp.ShouldBeSaved && wp.SpawnType == SpawnType.Path))
{ {
errorMsgs.Add(TextManager.Get("NoWaypointsWarning")); errorMsgs.Add(TextManager.Get("NoWaypointsWarning"));
} }
@@ -92,7 +92,7 @@ namespace Barotrauma
public PathFinder(List<WayPoint> wayPoints, bool insideSubmarine = false) public PathFinder(List<WayPoint> wayPoints, bool insideSubmarine = false)
{ {
nodes = PathNode.GenerateNodes(wayPoints.FindAll(w => w.MoveWithLevel != insideSubmarine)); nodes = PathNode.GenerateNodes(wayPoints.FindAll(w => (w.Submarine != null) == insideSubmarine));
foreach (WayPoint wp in wayPoints) foreach (WayPoint wp in wayPoints)
{ {
@@ -37,7 +37,6 @@ namespace Barotrauma
Level.PositionType.Cave | Level.PositionType.MainPath | Level.PositionType.Ruin, 500.0f, 10000.0f, 30.0f); Level.PositionType.Cave | Level.PositionType.MainPath | Level.PositionType.Ruin, 500.0f, 10000.0f, 30.0f);
item = new Item(itemPrefab, position, null); item = new Item(itemPrefab, position, null);
item.MoveWithLevel = true;
item.body.FarseerBody.IsKinematic = true; item.body.FarseerBody.IsKinematic = true;
//try to find a nearby artifact holder (or any alien itemcontainer) and place the artifact inside it //try to find a nearby artifact holder (or any alien itemcontainer) and place the artifact inside it
@@ -66,7 +65,7 @@ namespace Barotrauma
switch (state) switch (state)
{ {
case 0: case 0:
if (item.ParentInventory!=null) item.body.FarseerBody.IsKinematic = false; if (item.ParentInventory != null) item.body.FarseerBody.IsKinematic = false;
if (item.CurrentHull == null) return; if (item.CurrentHull == null) return;
state = 1; state = 1;
@@ -50,7 +50,6 @@ namespace Barotrauma
Vector2 position = Level.Loaded.GetRandomItemPos(spawnPositionType, 100.0f, minDistance, 30.0f); Vector2 position = Level.Loaded.GetRandomItemPos(spawnPositionType, 100.0f, minDistance, 30.0f);
item = new Item(itemPrefab, position, null); item = new Item(itemPrefab, position, null);
item.MoveWithLevel = true;
item.body.FarseerBody.IsKinematic = true; item.body.FarseerBody.IsKinematic = true;
if (item.HasTag("alien")) if (item.HasTag("alien"))
@@ -358,10 +358,7 @@ namespace Barotrauma
WayPoint wayPoint = new WayPoint( WayPoint wayPoint = new WayPoint(
mirror ? new Vector2(borders.X - positionOfInterest.Position.X, positionOfInterest.Position.Y) : positionOfInterest.Position, mirror ? new Vector2(borders.X - positionOfInterest.Position.X, positionOfInterest.Position.Y) : positionOfInterest.Position,
SpawnType.Enemy, SpawnType.Enemy,
submarine: null) submarine: null);
{
MoveWithLevel = true
};
} }
startPosition.X = pathCells[0].Center.X; startPosition.X = pathCells[0].Center.X;
@@ -611,7 +608,6 @@ namespace Barotrauma
List<WayPoint> wayPoints = new List<WayPoint>(); List<WayPoint> wayPoints = new List<WayPoint>();
var newWaypoint = new WayPoint(new Rectangle((int)pathCells[0].Center.X, borders.Height, 10, 10), null); var newWaypoint = new WayPoint(new Rectangle((int)pathCells[0].Center.X, borders.Height, 10, 10), null);
newWaypoint.MoveWithLevel = true;
wayPoints.Add(newWaypoint); wayPoints.Add(newWaypoint);
for (int i = 0; i < pathCells.Count; i++) for (int i = 0; i < pathCells.Count; i++)
@@ -619,7 +615,6 @@ namespace Barotrauma
pathCells[i].CellType = CellType.Path; pathCells[i].CellType = CellType.Path;
newWaypoint = new WayPoint(new Rectangle((int)pathCells[i].Center.X, (int)pathCells[i].Center.Y, 10, 10), null); newWaypoint = new WayPoint(new Rectangle((int)pathCells[i].Center.X, (int)pathCells[i].Center.Y, 10, 10), null);
newWaypoint.MoveWithLevel = true;
wayPoints.Add(newWaypoint); wayPoints.Add(newWaypoint);
wayPoints[wayPoints.Count-2].linkedTo.Add(newWaypoint); wayPoints[wayPoints.Count-2].linkedTo.Add(newWaypoint);
@@ -637,7 +632,6 @@ namespace Barotrauma
} }
newWaypoint = new WayPoint(new Rectangle((int)pathCells[pathCells.Count - 1].Center.X, borders.Height, 10, 10), null); newWaypoint = new WayPoint(new Rectangle((int)pathCells[pathCells.Count - 1].Center.X, borders.Height, 10, 10), null);
newWaypoint.MoveWithLevel = true;
wayPoints.Add(newWaypoint); wayPoints.Add(newWaypoint);
wayPoints[wayPoints.Count - 2].linkedTo.Add(newWaypoint); wayPoints[wayPoints.Count - 2].linkedTo.Add(newWaypoint);
@@ -348,15 +348,15 @@ namespace Barotrauma.RuinGeneration
var structurePrefab = RuinStructure.GetRandom(wallType, leaf.GetLineAlignment(wall)); var structurePrefab = RuinStructure.GetRandom(wallType, leaf.GetLineAlignment(wall));
if (structurePrefab == null) continue; if (structurePrefab == null) continue;
float radius = (wall.A.X == wall.B.X) ? float radius = (wall.A.X == wall.B.X) ?
(structurePrefab.Prefab as StructurePrefab).Size.X * 0.5f : (structurePrefab.Prefab as StructurePrefab).Size.X * 0.5f :
(structurePrefab.Prefab as StructurePrefab).Size.Y * 0.5f; (structurePrefab.Prefab as StructurePrefab).Size.Y * 0.5f;
Rectangle rect = new Rectangle( Rectangle rect = new Rectangle(
(int)(wall.A.X - radius), (int)(wall.A.X - radius),
(int)(wall.B.Y + radius), (int)(wall.B.Y + radius),
(int)((wall.B.X - wall.A.X) + radius*2.0f), (int)((wall.B.X - wall.A.X) + radius * 2.0f),
(int)((wall.B.Y - wall.A.Y) + radius*2.0f)); (int)((wall.B.Y - wall.A.Y) + radius * 2.0f));
//cut a section off from both ends of a horizontal wall to get nicer looking corners //cut a section off from both ends of a horizontal wall to get nicer looking corners
if (wall.A.Y == wall.B.Y) if (wall.A.Y == wall.B.Y)
@@ -365,8 +365,10 @@ namespace Barotrauma.RuinGeneration
if (rect.Width < Submarine.GridSize.X) continue; if (rect.Width < Submarine.GridSize.X) continue;
} }
var structure = new Structure(rect, structurePrefab.Prefab as StructurePrefab, null); var structure = new Structure(rect, structurePrefab.Prefab as StructurePrefab, null)
structure.MoveWithLevel = true; {
ShouldBeSaved = false
};
structure.SetCollisionCategory(Physics.CollisionLevel); structure.SetCollisionCategory(Physics.CollisionLevel);
} }
@@ -376,11 +378,14 @@ namespace Barotrauma.RuinGeneration
Rectangle backgroundRect = new Rectangle(leaf.Rect.X, leaf.Rect.Y + leaf.Rect.Height, leaf.Rect.Width, leaf.Rect.Height); Rectangle backgroundRect = new Rectangle(leaf.Rect.X, leaf.Rect.Y + leaf.Rect.Height, leaf.Rect.Width, leaf.Rect.Height);
new Structure(backgroundRect, (background.Prefab as StructurePrefab), null).MoveWithLevel = true; new Structure(backgroundRect, (background.Prefab as StructurePrefab), null)
{
ShouldBeSaved = false
};
var submarineBlocker = BodyFactory.CreateRectangle(GameMain.World, var submarineBlocker = BodyFactory.CreateRectangle(GameMain.World,
ConvertUnits.ToSimUnits(leaf.Rect.Width), ConvertUnits.ToSimUnits(leaf.Rect.Width),
ConvertUnits.ToSimUnits(leaf.Rect.Height), ConvertUnits.ToSimUnits(leaf.Rect.Height),
1, ConvertUnits.ToSimUnits(leaf.Center)); 1, ConvertUnits.ToSimUnits(leaf.Center));
submarineBlocker.IsStatic = true; submarineBlocker.IsStatic = true;
@@ -420,8 +425,10 @@ namespace Barotrauma.RuinGeneration
doorPos.Y = (wall.A.Y + wall.B.Y) / 2.0f; doorPos.Y = (wall.A.Y + wall.B.Y) / 2.0f;
} }
var door = new Item(doorPrefab.Prefab as ItemPrefab, doorPos, null); var door = new Item(doorPrefab.Prefab as ItemPrefab, doorPos, null)
door.MoveWithLevel = true; {
ShouldBeSaved = false
};
door.GetComponent<Items.Components.Door>().IsOpen = Rand.Range(0.0f, 1.0f, Rand.RandSync.Server) < 0.8f; door.GetComponent<Items.Components.Door>().IsOpen = Rand.Range(0.0f, 1.0f, Rand.RandSync.Server) < 0.8f;
@@ -432,11 +439,13 @@ namespace Barotrauma.RuinGeneration
var sensor = new Item(sensorPrefab, new Vector2( var sensor = new Item(sensorPrefab, new Vector2(
Rand.Range(sensorRoom.Rect.X, sensorRoom.Rect.Right, Rand.RandSync.Server), Rand.Range(sensorRoom.Rect.X, sensorRoom.Rect.Right, Rand.RandSync.Server),
Rand.Range(sensorRoom.Rect.Y, sensorRoom.Rect.Bottom, Rand.RandSync.Server)), null); Rand.Range(sensorRoom.Rect.Y, sensorRoom.Rect.Bottom, Rand.RandSync.Server)), null)
sensor.MoveWithLevel = true; {
ShouldBeSaved = false
};
var wire = new Item(wirePrefab, sensorRoom.Center, null).GetComponent<Items.Components.Wire>(); var wire = new Item(wirePrefab, sensorRoom.Center, null).GetComponent<Items.Components.Wire>();
wire.Item.MoveWithLevel = false; wire.Item.ShouldBeSaved = false;
var conn1 = door.Connections.Find(c => c.Name == "set_state"); var conn1 = door.Connections.Find(c => c.Name == "set_state");
conn1.AddLink(0, wire); conn1.AddLink(0, wire);
@@ -483,15 +492,17 @@ namespace Barotrauma.RuinGeneration
if (prop.Prefab is ItemPrefab) if (prop.Prefab is ItemPrefab)
{ {
var item = new Item((ItemPrefab)prop.Prefab, position, null); new Item((ItemPrefab)prop.Prefab, position, null);
item.MoveWithLevel = true;
} }
else else
{ {
new Structure(new Rectangle( new Structure(new Rectangle(
(int)(position.X - size.X/2.0f), (int)(position.Y + size.Y/2.0f), (int)(position.X - size.X / 2.0f), (int)(position.Y + size.Y / 2.0f),
(int)size.X, (int)size.Y), (int)size.X, (int)size.Y),
prop.Prefab as StructurePrefab, null).MoveWithLevel = true; prop.Prefab as StructurePrefab, null)
{
ShouldBeSaved = false
};
} }
} }
@@ -20,16 +20,7 @@ namespace Barotrauma
//observable collection because some entities may need to be notified when the collection is modified //observable collection because some entities may need to be notified when the collection is modified
public ObservableCollection<MapEntity> linkedTo; public ObservableCollection<MapEntity> linkedTo;
//protected float soundRange;
//protected float sightRange;
public bool MoveWithLevel
{
get;
set;
}
public bool ShouldBeSaved = true; public bool ShouldBeSaved = true;
//the position and dimensions of the entity //the position and dimensions of the entity
@@ -719,7 +719,7 @@ namespace Barotrauma
foreach (MapEntity e in subEntities) foreach (MapEntity e in subEntities)
{ {
if (e.MoveWithLevel || e is Item) continue; if (e is Item) continue;
if (e is LinkedSubmarine) if (e is LinkedSubmarine)
{ {
@@ -1262,7 +1262,7 @@ namespace Barotrauma
foreach (MapEntity e in MapEntity.mapEntityList) foreach (MapEntity e in MapEntity.mapEntityList)
{ {
if (e.MoveWithLevel || e.Submarine != this || !e.ShouldBeSaved) continue; if (e.Submarine != this || !e.ShouldBeSaved) continue;
e.Save(element); e.Save(element);
} }
} }
@@ -609,7 +609,7 @@ namespace Barotrauma
public override XElement Save(XElement parentElement) public override XElement Save(XElement parentElement)
{ {
if (MoveWithLevel) return null; if (!ShouldBeSaved) return null;
XElement element = new XElement("WayPoint"); XElement element = new XElement("WayPoint");
element.Add(new XAttribute("ID", ID), element.Add(new XAttribute("ID", ID),