From 5f4bf48449539bf71b713ca693480377b12d4235 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Tue, 14 Nov 2017 21:40:43 +0200 Subject: [PATCH] Replaced instances where MapEntityPrefabs are searched for based on the name with a static Find method that takes the aliases of the prefabs into account. --- .../Source/Screens/EditMapScreen.cs | 12 +- .../Source/Characters/Jobs/Job.cs | 4 +- .../BarotraumaShared/Source/DebugConsole.cs | 2 +- .../Source/Events/ArtifactEvent.cs | 9 +- .../Source/Events/Missions/CargoMission.cs | 8 +- .../Source/Events/Missions/SalvageMission.cs | 14 +-- .../Source/Items/Components/DockingPort.cs | 4 +- .../Components/Machines/Deconstructor.cs | 2 +- .../Items/Components/Machines/Fabricator.cs | 11 +- .../BarotraumaShared/Source/Items/Item.cs | 103 ++++++++---------- Barotrauma/BarotraumaShared/Source/Map/Gap.cs | 2 +- .../BarotraumaShared/Source/Map/Hull.cs | 4 +- .../Source/Map/Levels/Ruins/RuinGenerator.cs | 7 +- .../Source/Map/Levels/Ruins/RuinStructure.cs | 18 +-- .../Source/Map/MapEntityPrefab.cs | 38 +++++++ .../BarotraumaShared/Source/Map/Structure.cs | 25 ++--- .../Source/Networking/RespawnManager.cs | 8 +- 17 files changed, 141 insertions(+), 130 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/Screens/EditMapScreen.cs b/Barotrauma/BarotraumaClient/Source/Screens/EditMapScreen.cs index cad76e059..e30e85880 100644 --- a/Barotrauma/BarotraumaClient/Source/Screens/EditMapScreen.cs +++ b/Barotrauma/BarotraumaClient/Source/Screens/EditMapScreen.cs @@ -718,13 +718,8 @@ namespace Barotrauma if (wiringMode) { CreateDummyCharacter(); - - var screwdriverPrefab = ItemPrefab.list.Find(ip => ip.Name == "Screwdriver") as ItemPrefab; - - var item = new Item(screwdriverPrefab, Vector2.Zero, null); - + var item = new Item(MapEntityPrefab.Find("Screwdriver") as ItemPrefab, Vector2.Zero, null); dummyCharacter.Inventory.TryPutItem(item, null, new List() { InvSlotType.RightHand }); - wiringToolPanel = CreateWiringPanel(); } else @@ -760,11 +755,12 @@ namespace Barotrauma GUIListBox listBox = new GUIListBox(Rectangle.Empty, "", frame); listBox.OnSelected = SelectWire; - + foreach (MapEntityPrefab ep in MapEntityPrefab.list) { var itemPrefab = ep as ItemPrefab; - if (itemPrefab == null || itemPrefab.Name == null || !itemPrefab.Name.Contains("Wire")) continue; + if (itemPrefab == null || itemPrefab.Name == null) continue; + if (!itemPrefab.Name.Contains("Wire") && (itemPrefab.Aliases == null || !itemPrefab.Aliases.Any(a => a.Contains("Wire")))) continue; GUIFrame imgFrame = new GUIFrame(new Rectangle(0, 0, (int)itemPrefab.sprite.size.X, (int)itemPrefab.sprite.size.Y), null, listBox); imgFrame.UserData = itemPrefab; diff --git a/Barotrauma/BarotraumaShared/Source/Characters/Jobs/Job.cs b/Barotrauma/BarotraumaShared/Source/Characters/Jobs/Job.cs index 2e8f8e9f6..2d207ec02 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/Jobs/Job.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/Jobs/Job.cs @@ -98,7 +98,7 @@ namespace Barotrauma { string itemName = itemElement.GetAttributeString("name", ""); - ItemPrefab itemPrefab = ItemPrefab.list.Find(ip => ip.Name == itemName) as ItemPrefab; + ItemPrefab itemPrefab = MapEntityPrefab.Find(itemName) as ItemPrefab; if (itemPrefab == null) { DebugConsole.ThrowError("Tried to spawn \"" + Name + "\" with the item \"" + itemName + "\". Matching item prefab not found."); @@ -124,7 +124,7 @@ namespace Barotrauma character.Inventory.TryPutItem(item, null, item.AllowedSlots); } - if (item.Prefab.Name == "ID Card" && spawnPoint != null) + if (item.Prefab.NameMatches("ID Card") && spawnPoint != null) { foreach (string s in spawnPoint.IdCardTags) { diff --git a/Barotrauma/BarotraumaShared/Source/DebugConsole.cs b/Barotrauma/BarotraumaShared/Source/DebugConsole.cs index 9bac11a4e..39c546de3 100644 --- a/Barotrauma/BarotraumaShared/Source/DebugConsole.cs +++ b/Barotrauma/BarotraumaShared/Source/DebugConsole.cs @@ -213,7 +213,7 @@ namespace Barotrauma string itemName = string.Join(" ", args.Take(args.Length - extraParams)).ToLowerInvariant(); - var itemPrefab = MapEntityPrefab.list.Find(ip => ip.Name.ToLowerInvariant() == itemName) as ItemPrefab; + var itemPrefab = MapEntityPrefab.Find(itemName) as ItemPrefab; if (itemPrefab == null) { ThrowError("Item \"" + itemName + "\" not found!"); diff --git a/Barotrauma/BarotraumaShared/Source/Events/ArtifactEvent.cs b/Barotrauma/BarotraumaShared/Source/Events/ArtifactEvent.cs index 3bcba0f18..41b8577c4 100644 --- a/Barotrauma/BarotraumaShared/Source/Events/ArtifactEvent.cs +++ b/Barotrauma/BarotraumaShared/Source/Events/ArtifactEvent.cs @@ -14,19 +14,18 @@ namespace Barotrauma public override string ToString() { - return "ScriptedEvent (" + (itemPrefab==null ? "null" : itemPrefab.Name) + ")"; + return "ScriptedEvent (" + (itemPrefab == null ? "null" : itemPrefab.Name) + ")"; } - + public ArtifactEvent(XElement element) : base(element) { string itemName = element.GetAttributeString("itemname", ""); - - itemPrefab = ItemPrefab.list.Find(ip => ip.Name == itemName) as ItemPrefab; + itemPrefab = MapEntityPrefab.Find(itemName) as ItemPrefab; if (itemPrefab == null) { - DebugConsole.ThrowError("Error in SalvageMission: couldn't find an item prefab with the name "+itemName); + DebugConsole.ThrowError("Error in SalvageMission: couldn't find an item prefab with the name " + itemName); } } diff --git a/Barotrauma/BarotraumaShared/Source/Events/Missions/CargoMission.cs b/Barotrauma/BarotraumaShared/Source/Events/Missions/CargoMission.cs index c9813384f..77039b48b 100644 --- a/Barotrauma/BarotraumaShared/Source/Events/Missions/CargoMission.cs +++ b/Barotrauma/BarotraumaShared/Source/Events/Missions/CargoMission.cs @@ -43,15 +43,15 @@ namespace Barotrauma { string itemName = element.GetAttributeString("name", ""); - ItemPrefab itemPrefab = ItemPrefab.list.Find(ip => ip.Name == itemName) as ItemPrefab; - if (itemPrefab==null) + ItemPrefab itemPrefab = MapEntityPrefab.Find(itemName) as ItemPrefab; + if (itemPrefab == null) { - DebugConsole.ThrowError("Couldn't spawn item for cargo mission: item prefab \""+element.Name.ToString()+"\" not found"); + DebugConsole.ThrowError("Couldn't spawn item for cargo mission: item prefab \"" + element.Name.ToString() + "\" not found"); return; } WayPoint cargoSpawnPos = WayPoint.GetRandom(SpawnType.Cargo, null, Submarine.MainSub, true); - if (cargoSpawnPos==null) + if (cargoSpawnPos == null) { DebugConsole.ThrowError("Couldn't spawn items for cargo mission, cargo spawnpoint not found"); return; diff --git a/Barotrauma/BarotraumaShared/Source/Events/Missions/SalvageMission.cs b/Barotrauma/BarotraumaShared/Source/Events/Missions/SalvageMission.cs index 84eb0613f..b5c4fc7b1 100644 --- a/Barotrauma/BarotraumaShared/Source/Events/Missions/SalvageMission.cs +++ b/Barotrauma/BarotraumaShared/Source/Events/Missions/SalvageMission.cs @@ -28,8 +28,13 @@ namespace Barotrauma { string itemName = element.GetAttributeString("itemname", ""); - itemPrefab = ItemPrefab.list.Find(ip => ip.Name == itemName) as ItemPrefab; - + itemPrefab = MapEntityPrefab.Find(itemName) as ItemPrefab; + if (itemPrefab == null) + { + DebugConsole.ThrowError("Error in SalvageMission: couldn't find an item prefab with the name " + itemName); + return; + } + string spawnPositionTypeStr = element.GetAttributeString("spawntype", ""); if (string.IsNullOrWhiteSpace(spawnPositionTypeStr) || @@ -37,11 +42,6 @@ namespace Barotrauma { spawnPositionType = Level.PositionType.Cave | Level.PositionType.Ruin; } - - if (itemPrefab == null) - { - DebugConsole.ThrowError("Error in SalvageMission: couldn't find an item prefab with the name "+itemName); - } } public override void Start(Level level) diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/DockingPort.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/DockingPort.cs index 8d9bafec1..1b33e369a 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/DockingPort.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/DockingPort.cs @@ -390,7 +390,7 @@ namespace Barotrauma.Items.Components for (int i = 0; i < 2; i++) { hullRects[i].Location -= MathUtils.ToPoint((subs[i].WorldPosition - subs[i].HiddenSubPosition)); - hulls[i] = new Hull(MapEntityPrefab.list.Find(m => m.Name == "Hull"), hullRects[i], subs[i]); + hulls[i] = new Hull(MapEntityPrefab.Find("Hull"), hullRects[i], subs[i]); hulls[i].AddToGrid(subs[i]); for (int j = 0; j < 2; j++) @@ -420,7 +420,7 @@ namespace Barotrauma.Items.Components for (int i = 0; i < 2; i++) { hullRects[i].Location -= MathUtils.ToPoint((subs[i].WorldPosition - subs[i].HiddenSubPosition)); - hulls[i] = new Hull(MapEntityPrefab.list.Find(m => m.Name == "Hull"), hullRects[i], subs[i]); + hulls[i] = new Hull(MapEntityPrefab.Find("Hull"), hullRects[i], subs[i]); hulls[i].AddToGrid(subs[i]); if (hullIds[i] != null) hulls[i].ID = (ushort)hullIds[i]; diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Deconstructor.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Deconstructor.cs index 2c187067a..d9f127d14 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Deconstructor.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Deconstructor.cs @@ -59,7 +59,7 @@ namespace Barotrauma.Items.Components { if (deconstructProduct.RequireFullCondition && targetItem.Condition < targetItem.Prefab.Health) continue; - var itemPrefab = MapEntityPrefab.list.FirstOrDefault(ip => ip.Name.ToLowerInvariant() == deconstructProduct.ItemPrefabName.ToLowerInvariant()) as ItemPrefab; + var itemPrefab = MapEntityPrefab.Find(deconstructProduct.ItemPrefabName) as ItemPrefab; if (itemPrefab == null) { DebugConsole.ThrowError("Tried to deconstruct item \"" + targetItem.Name + "\" but couldn't find item prefab \"" + deconstructProduct + "\"!"); diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Fabricator.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Fabricator.cs index b5f556c9a..299bdf083 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Fabricator.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Fabricator.cs @@ -22,7 +22,7 @@ namespace Barotrauma.Items.Components { string name = element.GetAttributeString("name", ""); - TargetItem = MapEntityPrefab.list.Find(ip => ip.Name.ToLowerInvariant() == name.ToLowerInvariant()) as ItemPrefab; + TargetItem = MapEntityPrefab.Find(name) as ItemPrefab; if (TargetItem == null) { @@ -30,9 +30,7 @@ namespace Barotrauma.Items.Components } RequiredSkills = new List(); - RequiredTime = element.GetAttributeFloat("requiredtime", 1.0f); - RequiredItems = new List>(); string[] requiredItemNames = element.GetAttributeString("requireditems", "").Split(','); @@ -40,25 +38,22 @@ namespace Barotrauma.Items.Components { if (string.IsNullOrWhiteSpace(requiredItemName)) continue; - ItemPrefab requiredItem = ItemPrefab.list.Find(ip => ip.Name.ToLowerInvariant() == requiredItemName.Trim().ToLowerInvariant()) as ItemPrefab; + ItemPrefab requiredItem = MapEntityPrefab.Find(requiredItemName.Trim()) as ItemPrefab; if (requiredItem == null) { DebugConsole.ThrowError("Error in fabricable item " + name + "! Required item \"" + requiredItemName + "\" not found."); - continue; } var existing = RequiredItems.Find(r => r.Item1 == requiredItem); - if (existing == null) { - RequiredItems.Add(new Tuple(requiredItem, 1)); } else { RequiredItems.Remove(existing); - RequiredItems.Add(new Tuple(requiredItem, existing.Item2+1)); + RequiredItems.Add(new Tuple(requiredItem, existing.Item2 + 1)); } } diff --git a/Barotrauma/BarotraumaShared/Source/Items/Item.cs b/Barotrauma/BarotraumaShared/Source/Items/Item.cs index 1229b2aff..25e40e07f 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Item.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Item.cs @@ -1488,11 +1488,8 @@ namespace Barotrauma if (!spawn) return null; //---------------------------------------- - - var prefab = MapEntityPrefab.list.Find(me => me.Name == itemName); - if (prefab == null) return null; - - var itemPrefab = prefab as ItemPrefab; + + var itemPrefab = MapEntityPrefab.Find(itemName) as ItemPrefab; if (itemPrefab == null) return null; Inventory inventory = null; @@ -1592,68 +1589,64 @@ namespace Barotrauma public static void Load(XElement element, Submarine submarine) { - Rectangle rect = element.GetAttributeRect("rect", Rectangle.Empty); - string name = element.Attribute("name").Value; - foreach (MapEntityPrefab ep in MapEntityPrefab.list) + ItemPrefab prefab = MapEntityPrefab.Find(name) as ItemPrefab; + if (prefab == null) { - ItemPrefab ip = ep as ItemPrefab; - if (ip == null) continue; + DebugConsole.ThrowError("Error loading item - item prefab \"" + name + "\" not found."); + return; + } - if (ip.Name != name && (ip.Aliases == null || !ip.Aliases.Contains(name))) continue; + Rectangle rect = element.GetAttributeRect("rect", Rectangle.Empty); + if (rect.Width == 0 && rect.Height == 0) + { + rect.Width = (int)prefab.Size.X; + rect.Height = (int)prefab.Size.Y; + } - if (rect.Width == 0 && rect.Height == 0) + Item item = new Item(rect, prefab, submarine); + item.Submarine = submarine; + item.ID = (ushort)int.Parse(element.Attribute("ID").Value); + + item.linkedToID = new List(); + + foreach (XAttribute attribute in element.Attributes()) + { + SerializableProperty property = null; + if (!item.properties.TryGetValue(attribute.Name.ToString(), out property)) continue; + + bool shouldBeLoaded = false; + + foreach (var propertyAttribute in property.Attributes.OfType()) { - rect.Width = (int)ip.Size.X; - rect.Height = (int)ip.Size.Y; - } - - Item item = new Item(rect, ip, submarine); - item.Submarine = submarine; - item.ID = (ushort)int.Parse(element.Attribute("ID").Value); - - item.linkedToID = new List(); - - foreach (XAttribute attribute in element.Attributes()) - { - SerializableProperty property = null; - if (!item.properties.TryGetValue(attribute.Name.ToString(), out property)) continue; - - bool shouldBeLoaded = false; - - foreach (var propertyAttribute in property.Attributes.OfType()) + if (propertyAttribute.isSaveable) { - if (propertyAttribute.isSaveable) - { - shouldBeLoaded = true; - break; - } - } - - if (shouldBeLoaded) property.TrySetValue(attribute.Value); - } - - string linkedToString = element.GetAttributeString("linked", ""); - if (linkedToString!="") - { - string[] linkedToIds = linkedToString.Split(','); - for (int i = 0; i x.Name == subElement.Name.ToString()); - - if (component == null) continue; - - component.Load(subElement); + item.linkedToID.Add((ushort)int.Parse(linkedToIds[i])); } - - break; + } + + foreach (XElement subElement in element.Elements()) + { + ItemComponent component = item.components.Find(x => x.Name == subElement.Name.ToString()); + + if (component == null) continue; + + component.Load(subElement); } } diff --git a/Barotrauma/BarotraumaShared/Source/Map/Gap.cs b/Barotrauma/BarotraumaShared/Source/Map/Gap.cs index c46522a86..cf1969028 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Gap.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Gap.cs @@ -101,7 +101,7 @@ namespace Barotrauma { } public Gap(Rectangle newRect, bool isHorizontal, Submarine submarine) - : base (MapEntityPrefab.list.Find(m=> m.Name == "Gap"), submarine) + : base (MapEntityPrefab.Find("Gap"), submarine) { rect = newRect; linkedTo = new ObservableCollection(); diff --git a/Barotrauma/BarotraumaShared/Source/Map/Hull.cs b/Barotrauma/BarotraumaShared/Source/Map/Hull.cs index 564861196..cde34d175 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Hull.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Hull.cs @@ -255,7 +255,7 @@ namespace Barotrauma public override MapEntity Clone() { - return new Hull(MapEntityPrefab.list.Find(m => m.Name == "Hull"), rect, Submarine); + return new Hull(MapEntityPrefab.Find("Hull"), rect, Submarine); } public static EntityGrid GenerateEntityGrid(Submarine submarine) @@ -722,7 +722,7 @@ namespace Barotrauma int.Parse(element.Attribute("height").Value)); } - Hull h = new Hull(MapEntityPrefab.list.Find(m => m.Name == "Hull"), rect, submarine); + Hull h = new Hull(MapEntityPrefab.Find("Hull"), rect, submarine); h.waterVolume = element.GetAttributeFloat("pressure", 0.0f); diff --git a/Barotrauma/BarotraumaShared/Source/Map/Levels/Ruins/RuinGenerator.cs b/Barotrauma/BarotraumaShared/Source/Map/Levels/Ruins/RuinGenerator.cs index bd4f5118e..26c6bc01f 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Levels/Ruins/RuinGenerator.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Levels/Ruins/RuinGenerator.cs @@ -389,12 +389,11 @@ namespace Barotrauma.RuinGeneration prop.Prefab as StructurePrefab, null).MoveWithLevel = true; } } - - + //generate doors & sensors that close them ------------------------------------------------------------- - var sensorPrefab = ItemPrefab.list.Find(ip => ip.Name == "Alien Motion Sensor") as ItemPrefab; - var wirePrefab = ItemPrefab.list.Find(ip => ip.Name == "Wire") as ItemPrefab; + var sensorPrefab = MapEntityPrefab.Find("Alien Motion Sensor") as ItemPrefab; + var wirePrefab = MapEntityPrefab.Find("Wire") as ItemPrefab; foreach (Corridor corridor in corridors) { diff --git a/Barotrauma/BarotraumaShared/Source/Map/Levels/Ruins/RuinStructure.cs b/Barotrauma/BarotraumaShared/Source/Map/Levels/Ruins/RuinStructure.cs index 2b547969d..8be78eaf3 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Levels/Ruins/RuinStructure.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Levels/Ruins/RuinStructure.cs @@ -27,26 +27,26 @@ namespace Barotrauma.RuinGeneration private RuinStructure(XElement element) { - string prefab = element.GetAttributeString("prefab", "").ToLowerInvariant(); - Prefab = MapEntityPrefab.list.Find(s => s.Name.ToLowerInvariant() == prefab); + string name = element.GetAttributeString("prefab", ""); + Prefab = MapEntityPrefab.Find(name); if (Prefab == null) { - DebugConsole.ThrowError("Loading ruin structure failed - structure prefab \""+prefab+" not found"); + DebugConsole.ThrowError("Loading ruin structure failed - structure prefab \"" + name + " not found"); return; } - string alignmentStr = element.GetAttributeString("alignment","Bottom"); + string alignmentStr = element.GetAttributeString("alignment", "Bottom"); if (!Enum.TryParse(alignmentStr, true, out Alignment)) { - DebugConsole.ThrowError("Error in ruin structure \""+prefab+"\" - "+alignmentStr+" is not a valid alignment"); + DebugConsole.ThrowError("Error in ruin structure \"" + name + "\" - " + alignmentStr + " is not a valid alignment"); } - - string typeStr = element.GetAttributeString("type",""); - if (!Enum.TryParse(typeStr,true, out Type)) + + string typeStr = element.GetAttributeString("type", ""); + if (!Enum.TryParse(typeStr, true, out Type)) { - DebugConsole.ThrowError("Error in ruin structure \"" + prefab + "\" - " + typeStr + " is not a valid type"); + DebugConsole.ThrowError("Error in ruin structure \"" + name + "\" - " + typeStr + " is not a valid type"); return; } diff --git a/Barotrauma/BarotraumaShared/Source/Map/MapEntityPrefab.cs b/Barotrauma/BarotraumaShared/Source/Map/MapEntityPrefab.cs index fded3dcf0..1180e6f32 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/MapEntityPrefab.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/MapEntityPrefab.cs @@ -1,6 +1,7 @@ using Microsoft.Xna.Framework; using System; using System.Collections.Generic; +using System.Linq; using System.Reflection; namespace Barotrauma @@ -191,6 +192,43 @@ namespace Barotrauma } } + public static MapEntityPrefab Find(string name, bool caseSensitive = false) + { + if (caseSensitive) + { + foreach (MapEntityPrefab prefab in list) + { + if (prefab.name == name || (prefab.Aliases != null && prefab.Aliases.Contains(name))) return prefab; + } + } + else + { + name = name.ToLowerInvariant(); + foreach (MapEntityPrefab prefab in list) + { + if (prefab.name.ToLowerInvariant() == name || (prefab.Aliases != null && prefab.Aliases.Any(a => a.ToLowerInvariant() == name))) return prefab; + } + } + + return null; + } + + /// + /// Check if the name or any of the aliases of this prefab match the given name. + /// + public bool NameMatches(string name, bool caseSensitive = false) + { + if (caseSensitive) + { + return this.name == name || (Aliases != null && Aliases.Any(a => a == name)); + } + else + { + name = name.ToLowerInvariant(); + return this.name.ToLowerInvariant() == name || (Aliases != null && Aliases.Any(a => a.ToLowerInvariant() == name)); + } + } + //a method that allows the GUIListBoxes to check through a delegate if the entityprefab is still selected public static object GetSelected() { diff --git a/Barotrauma/BarotraumaShared/Source/Map/Structure.cs b/Barotrauma/BarotraumaShared/Source/Map/Structure.cs index 409cb70b6..7b2f2e258 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Structure.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Structure.cs @@ -824,28 +824,19 @@ namespace Barotrauma public static void Load(XElement element, Submarine submarine) { - Rectangle rect = element.GetAttributeRect("rect", Rectangle.Empty); - string name = element.Attribute("name").Value; - - Structure s = null; - foreach (MapEntityPrefab ep in MapEntityPrefab.list) + StructurePrefab prefab = MapEntityPrefab.Find(name) as StructurePrefab; + if (prefab == null) { - if (ep.Name == name || (ep.Aliases != null && ep.Aliases.Contains(name))) - { - s = new Structure(rect, (StructurePrefab)ep, submarine); - s.Submarine = submarine; - s.ID = (ushort)int.Parse(element.Attribute("ID").Value); - break; - } - } - - if (s == null) - { - DebugConsole.ThrowError("Structure prefab " + name + " not found."); + DebugConsole.ThrowError("Error loading structure - structure prefab " + name + " not found."); return; } + + Rectangle rect = element.GetAttributeRect("rect", Rectangle.Empty); + Structure s = new Structure(rect, prefab, submarine); + s.Submarine = submarine; + s.ID = (ushort)int.Parse(element.Attribute("ID").Value); foreach (XElement subElement in element.Elements()) { diff --git a/Barotrauma/BarotraumaShared/Source/Networking/RespawnManager.cs b/Barotrauma/BarotraumaShared/Source/Networking/RespawnManager.cs index 78eedd456..0fe95edf1 100644 --- a/Barotrauma/BarotraumaShared/Source/Networking/RespawnManager.cs +++ b/Barotrauma/BarotraumaShared/Source/Networking/RespawnManager.cs @@ -429,10 +429,10 @@ namespace Barotrauma.Networking //(in order to give them appropriate ID card tags) var mainSubSpawnPoints = WayPoint.SelectCrewSpawnPoints(characterInfos, Submarine.MainSub); - ItemPrefab divingSuitPrefab = ItemPrefab.list.Find(ip => ip.Name == "Diving Suit") as ItemPrefab; - ItemPrefab oxyPrefab = ItemPrefab.list.Find(ip => ip.Name == "Oxygen Tank") as ItemPrefab; - ItemPrefab scooterPrefab = ItemPrefab.list.Find(ip => ip.Name == "Underwater Scooter") as ItemPrefab; - ItemPrefab batteryPrefab = ItemPrefab.list.Find(ip => ip.Name == "Battery Cell") as ItemPrefab; + ItemPrefab divingSuitPrefab = MapEntityPrefab.Find("Diving Suit") as ItemPrefab; + ItemPrefab oxyPrefab = MapEntityPrefab.Find("Oxygen Tank") as ItemPrefab; + ItemPrefab scooterPrefab = MapEntityPrefab.Find("Underwater Scooter") as ItemPrefab; + ItemPrefab batteryPrefab = MapEntityPrefab.Find("Battery Cell") as ItemPrefab; var cargoSp = WayPoint.WayPointList.Find(wp => wp.Submarine == respawnShuttle && wp.SpawnType == SpawnType.Cargo);