From 3747852c13a2320f0a2d265332b4a5b25b4a465e Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Mon, 20 Aug 2018 16:23:40 +0300 Subject: [PATCH] Removed the Entity.MoveWithLevel property, fixed artifacts and other items from ruins not being saved. Closes #694 --- .../BarotraumaClient/Source/DebugConsole.cs | 4 +- .../BarotraumaClient/Source/Map/Submarine.cs | 2 +- .../Source/Characters/AI/PathFinder.cs | 2 +- .../Source/Events/ArtifactEvent.cs | 3 +- .../Source/Events/Missions/SalvageMission.cs | 1 - .../Source/Map/Levels/Level.cs | 8 +-- .../Source/Map/Levels/Ruins/RuinGenerator.cs | 51 +++++++++++-------- .../BarotraumaShared/Source/Map/MapEntity.cs | 11 +--- .../BarotraumaShared/Source/Map/Submarine.cs | 4 +- .../BarotraumaShared/Source/Map/WayPoint.cs | 2 +- 10 files changed, 41 insertions(+), 47 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/DebugConsole.cs b/Barotrauma/BarotraumaClient/Source/DebugConsole.cs index 0a3a91434..3b878f699 100644 --- a/Barotrauma/BarotraumaClient/Source/DebugConsole.cs +++ b/Barotrauma/BarotraumaClient/Source/DebugConsole.cs @@ -355,9 +355,9 @@ namespace Barotrauma NewMessage("Removed " + me.Name + " (simposition " + me.SimPosition + ")", Color.Orange); 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); } else if (me is Item) diff --git a/Barotrauma/BarotraumaClient/Source/Map/Submarine.cs b/Barotrauma/BarotraumaClient/Source/Map/Submarine.cs index 8202dd7e8..e275bceff 100644 --- a/Barotrauma/BarotraumaClient/Source/Map/Submarine.cs +++ b/Barotrauma/BarotraumaClient/Source/Map/Submarine.cs @@ -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")); } diff --git a/Barotrauma/BarotraumaShared/Source/Characters/AI/PathFinder.cs b/Barotrauma/BarotraumaShared/Source/Characters/AI/PathFinder.cs index cc4bcbd0a..a2c4b7168 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/AI/PathFinder.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/AI/PathFinder.cs @@ -92,7 +92,7 @@ namespace Barotrauma public PathFinder(List 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) { diff --git a/Barotrauma/BarotraumaShared/Source/Events/ArtifactEvent.cs b/Barotrauma/BarotraumaShared/Source/Events/ArtifactEvent.cs index be7ca10b1..19fd37154 100644 --- a/Barotrauma/BarotraumaShared/Source/Events/ArtifactEvent.cs +++ b/Barotrauma/BarotraumaShared/Source/Events/ArtifactEvent.cs @@ -37,7 +37,6 @@ namespace Barotrauma Level.PositionType.Cave | Level.PositionType.MainPath | Level.PositionType.Ruin, 500.0f, 10000.0f, 30.0f); item = new Item(itemPrefab, position, null); - item.MoveWithLevel = true; item.body.FarseerBody.IsKinematic = true; //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) { 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; state = 1; diff --git a/Barotrauma/BarotraumaShared/Source/Events/Missions/SalvageMission.cs b/Barotrauma/BarotraumaShared/Source/Events/Missions/SalvageMission.cs index b9fc7bb10..11c305eb3 100644 --- a/Barotrauma/BarotraumaShared/Source/Events/Missions/SalvageMission.cs +++ b/Barotrauma/BarotraumaShared/Source/Events/Missions/SalvageMission.cs @@ -50,7 +50,6 @@ namespace Barotrauma Vector2 position = Level.Loaded.GetRandomItemPos(spawnPositionType, 100.0f, minDistance, 30.0f); item = new Item(itemPrefab, position, null); - item.MoveWithLevel = true; item.body.FarseerBody.IsKinematic = true; if (item.HasTag("alien")) diff --git a/Barotrauma/BarotraumaShared/Source/Map/Levels/Level.cs b/Barotrauma/BarotraumaShared/Source/Map/Levels/Level.cs index b52a2f9b6..35ac625d3 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Levels/Level.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Levels/Level.cs @@ -358,10 +358,7 @@ namespace Barotrauma WayPoint wayPoint = new WayPoint( mirror ? new Vector2(borders.X - positionOfInterest.Position.X, positionOfInterest.Position.Y) : positionOfInterest.Position, SpawnType.Enemy, - submarine: null) - { - MoveWithLevel = true - }; + submarine: null); } startPosition.X = pathCells[0].Center.X; @@ -611,7 +608,6 @@ namespace Barotrauma List wayPoints = new List(); var newWaypoint = new WayPoint(new Rectangle((int)pathCells[0].Center.X, borders.Height, 10, 10), null); - newWaypoint.MoveWithLevel = true; wayPoints.Add(newWaypoint); for (int i = 0; i < pathCells.Count; i++) @@ -619,7 +615,6 @@ namespace Barotrauma pathCells[i].CellType = CellType.Path; 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[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.MoveWithLevel = true; wayPoints.Add(newWaypoint); wayPoints[wayPoints.Count - 2].linkedTo.Add(newWaypoint); diff --git a/Barotrauma/BarotraumaShared/Source/Map/Levels/Ruins/RuinGenerator.cs b/Barotrauma/BarotraumaShared/Source/Map/Levels/Ruins/RuinGenerator.cs index f4126af3e..cb5d15e0e 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Levels/Ruins/RuinGenerator.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Levels/Ruins/RuinGenerator.cs @@ -348,15 +348,15 @@ namespace Barotrauma.RuinGeneration var structurePrefab = RuinStructure.GetRandom(wallType, leaf.GetLineAlignment(wall)); if (structurePrefab == null) continue; - float radius = (wall.A.X == wall.B.X) ? - (structurePrefab.Prefab as StructurePrefab).Size.X * 0.5f : + float radius = (wall.A.X == wall.B.X) ? + (structurePrefab.Prefab as StructurePrefab).Size.X * 0.5f : (structurePrefab.Prefab as StructurePrefab).Size.Y * 0.5f; Rectangle rect = new Rectangle( - (int)(wall.A.X - radius), - (int)(wall.B.Y + radius), - (int)((wall.B.X - wall.A.X) + radius*2.0f), - (int)((wall.B.Y - wall.A.Y) + radius*2.0f)); + (int)(wall.A.X - radius), + (int)(wall.B.Y + radius), + (int)((wall.B.X - wall.A.X) + 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 if (wall.A.Y == wall.B.Y) @@ -365,8 +365,10 @@ namespace Barotrauma.RuinGeneration if (rect.Width < Submarine.GridSize.X) continue; } - var structure = new Structure(rect, structurePrefab.Prefab as StructurePrefab, null); - structure.MoveWithLevel = true; + var structure = new Structure(rect, structurePrefab.Prefab as StructurePrefab, null) + { + ShouldBeSaved = false + }; 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); - 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.Height), + ConvertUnits.ToSimUnits(leaf.Rect.Height), 1, ConvertUnits.ToSimUnits(leaf.Center)); submarineBlocker.IsStatic = true; @@ -420,8 +425,10 @@ namespace Barotrauma.RuinGeneration doorPos.Y = (wall.A.Y + wall.B.Y) / 2.0f; } - var door = new Item(doorPrefab.Prefab as ItemPrefab, doorPos, null); - door.MoveWithLevel = true; + var door = new Item(doorPrefab.Prefab as ItemPrefab, doorPos, null) + { + ShouldBeSaved = false + }; door.GetComponent().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( Rand.Range(sensorRoom.Rect.X, sensorRoom.Rect.Right, Rand.RandSync.Server), - Rand.Range(sensorRoom.Rect.Y, sensorRoom.Rect.Bottom, Rand.RandSync.Server)), null); - sensor.MoveWithLevel = true; + Rand.Range(sensorRoom.Rect.Y, sensorRoom.Rect.Bottom, Rand.RandSync.Server)), null) + { + ShouldBeSaved = false + }; var wire = new Item(wirePrefab, sensorRoom.Center, null).GetComponent(); - wire.Item.MoveWithLevel = false; + wire.Item.ShouldBeSaved = false; var conn1 = door.Connections.Find(c => c.Name == "set_state"); conn1.AddLink(0, wire); @@ -483,15 +492,17 @@ namespace Barotrauma.RuinGeneration if (prop.Prefab is ItemPrefab) { - var item = new Item((ItemPrefab)prop.Prefab, position, null); - item.MoveWithLevel = true; + new Item((ItemPrefab)prop.Prefab, position, null); } else { 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), - prop.Prefab as StructurePrefab, null).MoveWithLevel = true; + prop.Prefab as StructurePrefab, null) + { + ShouldBeSaved = false + }; } } diff --git a/Barotrauma/BarotraumaShared/Source/Map/MapEntity.cs b/Barotrauma/BarotraumaShared/Source/Map/MapEntity.cs index 7b5a55a5a..200454f55 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/MapEntity.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/MapEntity.cs @@ -20,16 +20,7 @@ namespace Barotrauma //observable collection because some entities may need to be notified when the collection is modified public ObservableCollection linkedTo; - - //protected float soundRange; - //protected float sightRange; - - public bool MoveWithLevel - { - get; - set; - } - + public bool ShouldBeSaved = true; //the position and dimensions of the entity diff --git a/Barotrauma/BarotraumaShared/Source/Map/Submarine.cs b/Barotrauma/BarotraumaShared/Source/Map/Submarine.cs index a38edae39..49612ca16 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Submarine.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Submarine.cs @@ -719,7 +719,7 @@ namespace Barotrauma foreach (MapEntity e in subEntities) { - if (e.MoveWithLevel || e is Item) continue; + if (e is Item) continue; if (e is LinkedSubmarine) { @@ -1262,7 +1262,7 @@ namespace Barotrauma 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); } } diff --git a/Barotrauma/BarotraumaShared/Source/Map/WayPoint.cs b/Barotrauma/BarotraumaShared/Source/Map/WayPoint.cs index 13fbcd339..533219f87 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/WayPoint.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/WayPoint.cs @@ -609,7 +609,7 @@ namespace Barotrauma public override XElement Save(XElement parentElement) { - if (MoveWithLevel) return null; + if (!ShouldBeSaved) return null; XElement element = new XElement("WayPoint"); element.Add(new XAttribute("ID", ID),