diff --git a/Subsurface/Source/Items/Item.cs b/Subsurface/Source/Items/Item.cs index 7172dd548..1b26fcc33 100644 --- a/Subsurface/Source/Items/Item.cs +++ b/Subsurface/Source/Items/Item.cs @@ -1983,6 +1983,25 @@ namespace Barotrauma return true; } + public override void ShallowRemove() + { + base.ShallowRemove(); + + Removed = true; + + foreach (ItemComponent ic in components) + { + ic.Remove(); + } + ItemList.Remove(this); + + if (body != null) + { + body.Remove(); + body = null; + } + } + public override void Remove() { base.Remove(); diff --git a/Subsurface/Source/Map/MapEntity.cs b/Subsurface/Source/Map/MapEntity.cs index 2b0a27b98..a8739c223 100644 --- a/Subsurface/Source/Map/MapEntity.cs +++ b/Subsurface/Source/Map/MapEntity.cs @@ -240,6 +240,17 @@ namespace Barotrauma Debug.Assert(clones.Count == entitiesToClone.Count); + //clone links between the entities + for (int i = 0; i < clones.Count; i++) + { + foreach (MapEntity linked in entitiesToClone[i].linkedTo) + { + if (!entitiesToClone.Contains(linked)) continue; + + clones[i].linkedTo.Add(clones[entitiesToClone.IndexOf(linked)]); + } + } + //connect clone wires to the clone items for (int i = 0; i < clones.Count; i++) { @@ -300,6 +311,18 @@ namespace Barotrauma public virtual void DrawDamage(SpriteBatch spriteBatch, Effect damageEffect) {} + /// + /// Remove the entity from the entity list without removing links to other entities + /// + public virtual void ShallowRemove() + { + base.Remove(); + + mapEntityList.Remove(this); + + if (aiTarget != null) aiTarget.Remove(); + } + public override void Remove() { base.Remove(); @@ -388,12 +411,13 @@ namespace Barotrauma if (PlayerInput.GetKeyboardState.IsKeyDown(Keys.C) && PlayerInput.GetOldKeyboardState.IsKeyUp(Keys.C)) { - copiedList = new List(selectedList); + CopyEntities(selectedList); } else if (PlayerInput.GetKeyboardState.IsKeyDown(Keys.X) && PlayerInput.GetOldKeyboardState.IsKeyUp(Keys.X)) { - copiedList = new List(selectedList); + CopyEntities(selectedList); + selectedList.ForEach(e => e.Remove()); selectedList.Clear(); } @@ -636,6 +660,24 @@ namespace Barotrauma selectedList.Add(entity); } + + /// + /// copies a list of entities to the "clipboard" (copiedList) + /// + private static void CopyEntities(List entities) + { + List prevEntities = new List(mapEntityList); + + copiedList = Clone(entities); + + //find all new entities created during cloning + var newEntities = mapEntityList.Except(prevEntities).ToList(); + + //do a "shallow remove" (removes the entities from the game without removing links between them) + // -> items will stay in their containers + newEntities.ForEach(e => e.ShallowRemove()); + } + public virtual void FlipX() { if (Submarine == null) @@ -752,26 +794,7 @@ namespace Barotrauma } } } - - public static List FindMapEntities(Vector2 pos) - { - List foundEntities = new List(); - foreach (MapEntity e in mapEntityList) - { - if (Submarine.RectContains(e.rect, pos)) foundEntities.Add(e); - } - return foundEntities; - } - - public static MapEntity FindMapEntity(Vector2 pos) - { - foreach (MapEntity e in mapEntityList) - { - if (Submarine.RectContains(e.rect, pos)) return e; - } - return null; - } - + /// /// Find entities whose rect intersects with the "selection rect" ///