示例#1
0
        /// <summary>
        /// Calculated from <see cref="SubmarineElement"/>. Can be used when the sub hasn't been loaded and we can't access <see cref="Submarine.RealWorldCrushDepth"/>.
        /// </summary>
        public float GetRealWorldCrushDepth()
        {
            if (SubmarineElement == null)
            {
                return(Level.DefaultRealWorldCrushDepth);
            }
            bool  structureCrushDepthsDefined = false;
            float realWorldCrushDepth         = float.PositiveInfinity;

            foreach (var structureElement in SubmarineElement.GetChildElements("structure"))
            {
                string name            = structureElement.Attribute("name")?.Value ?? "";
                string identifier      = structureElement.GetAttributeString("identifier", "");
                var    structurePrefab = Structure.FindPrefab(name, identifier);
                if (structurePrefab == null || !structurePrefab.Body)
                {
                    continue;
                }
                if (!structureCrushDepthsDefined && structureElement.Attribute("crushdepth") != null)
                {
                    structureCrushDepthsDefined = true;
                }
                float structureCrushDepth = structureElement.GetAttributeFloat("crushdepth", float.PositiveInfinity);
                realWorldCrushDepth = Math.Min(structureCrushDepth, realWorldCrushDepth);
            }
            if (!structureCrushDepthsDefined)
            {
                realWorldCrushDepth = Level.DefaultRealWorldCrushDepth;
            }
            realWorldCrushDepth *= GetRealWorldCrushDepthMultiplier();
            return(realWorldCrushDepth);
        }
示例#2
0
        private void GenerateWallVertices(XElement rootElement)
        {
            List <Vector2> points = new List <Vector2>();

            var wallPrefabs = StructurePrefab.Prefabs.Where(mp => mp.Body);

            foreach (XElement element in rootElement.Elements())
            {
                if (element.Name != "Structure")
                {
                    continue;
                }

                string name       = element.GetAttributeString("name", "");
                string identifier = element.GetAttributeString("identifier", "");

                StructurePrefab prefab = Structure.FindPrefab(name, identifier);
                if (prefab == null)
                {
                    continue;
                }

                var rect = element.GetAttributeVector4("rect", Vector4.Zero);

                points.Add(new Vector2(rect.X, rect.Y));
                points.Add(new Vector2(rect.X + rect.Z, rect.Y));
                points.Add(new Vector2(rect.X, rect.Y - rect.W));
                points.Add(new Vector2(rect.X + rect.Z, rect.Y - rect.W));
            }

            wallVertices = MathUtils.GiftWrap(points);
        }
示例#3
0
        public static List <MapEntity> LoadAll(Submarine submarine, XElement parentElement, string filePath, int idOffset)
        {
            IdRemap idRemap = new IdRemap(parentElement, idOffset);

            List <MapEntity> entities = new List <MapEntity>();

            foreach (XElement element in parentElement.Elements())
            {
                string typeName = element.Name.ToString();

                Type t;
                try
                {
                    t = Type.GetType("Barotrauma." + typeName, true, true);
                    if (t == null)
                    {
                        DebugConsole.ThrowError("Error in " + filePath + "! Could not find a entity of the type \"" + typeName + "\".");
                        continue;
                    }
                }
                catch (Exception e)
                {
                    DebugConsole.ThrowError("Error in " + filePath + "! Could not find a entity of the type \"" + typeName + "\".", e);
                    continue;
                }

                if (t == typeof(Structure))
                {
                    string          name            = element.Attribute("name").Value;
                    string          identifier      = element.GetAttributeString("identifier", "");
                    StructurePrefab structurePrefab = Structure.FindPrefab(name, identifier);
                    if (structurePrefab == null)
                    {
                        ItemPrefab itemPrefab = ItemPrefab.Find(name, identifier);
                        if (itemPrefab != null)
                        {
                            t = typeof(Item);
                        }
                    }
                }

                try
                {
                    MethodInfo loadMethod = t.GetMethod("Load", new[] { typeof(XElement), typeof(Submarine), typeof(IdRemap) });
                    if (loadMethod == null)
                    {
                        DebugConsole.ThrowError("Could not find the method \"Load\" in " + t + ".");
                    }
                    else if (!loadMethod.ReturnType.IsSubclassOf(typeof(MapEntity)))
                    {
                        DebugConsole.ThrowError("Error loading entity of the type \"" + t.ToString() + "\" - load method does not return a valid map entity.");
                    }
                    else
                    {
                        object newEntity = loadMethod.Invoke(t, new object[] { element, submarine, idRemap });
                        if (newEntity != null)
                        {
                            entities.Add((MapEntity)newEntity);
                        }
                    }
                }
                catch (TargetInvocationException e)
                {
                    DebugConsole.ThrowError("Error while loading entity of the type " + t + ".", e.InnerException);
                }
                catch (Exception e)
                {
                    DebugConsole.ThrowError("Error while loading entity of the type " + t + ".", e);
                }
            }
            return(entities);
        }