Пример #1
0
        /// <summary>
        /// Update the linkedTo-lists of the entities based on the linkedToID-lists
        /// Has to be done after all the entities have been loaded (an entity can't
        /// be linked to some other entity that hasn't been loaded yet)
        /// </summary>
        public static void MapLoaded(Submarine sub)
        {
            foreach (MapEntity e in mapEntityList)
            {
                if (e.Submarine != sub)
                {
                    continue;
                }
                if (e.linkedToID == null)
                {
                    continue;
                }
                if (e.linkedToID.Count == 0)
                {
                    continue;
                }

                e.linkedTo.Clear();

                foreach (ushort i in e.linkedToID)
                {
                    if (FindEntityByID(i) is MapEntity linked)
                    {
                        e.linkedTo.Add(linked);
                    }
                }
            }

            List <LinkedSubmarine> linkedSubs = new List <LinkedSubmarine>();

            for (int i = 0; i < mapEntityList.Count; i++)
            {
                if (mapEntityList[i].Submarine != sub)
                {
                    continue;
                }

                if (mapEntityList[i] is LinkedSubmarine)
                {
                    linkedSubs.Add((LinkedSubmarine)mapEntityList[i]);
                    continue;
                }

                mapEntityList[i].OnMapLoaded();
            }

            Item.UpdateHulls();
            Gap.UpdateHulls();

            foreach (LinkedSubmarine linkedSub in linkedSubs)
            {
                linkedSub.OnMapLoaded();
            }
        }
Пример #2
0
        public override void Move(Vector2 amount)
        {
            rect.X += (int)amount.X;
            rect.Y += (int)amount.Y;

            if (Submarine == null || !Submarine.Loading)
            {
                Item.UpdateHulls();
                Gap.UpdateHulls();
            }

            surface  = rect.Y - rect.Height + WaterVolume / rect.Width;
            Pressure = surface;
        }
Пример #3
0
        public Hull(MapEntityPrefab prefab, Rectangle rectangle, Submarine submarine)
            : base(prefab, submarine)
        {
            rect = rectangle;

            OxygenPercentage = 100.0f;

            FireSources = new List <FireSource>();

            properties = SerializableProperty.GetProperties(this);

            int arraySize = (int)Math.Ceiling((float)rectangle.Width / WaveWidth + 1);

            waveY   = new float[arraySize];
            waveVel = new float[arraySize];

            leftDelta  = new float[arraySize];
            rightDelta = new float[arraySize];

            surface = rect.Y - rect.Height;

            if (submarine != null)
            {
                aiTarget = new AITarget(this)
                {
                    MinSightRange = 2000,
                    MaxSightRange = 5000,
                    MaxSoundRange = 5000,
                    SoundRange    = 0
                };
            }

            hullList.Add(this);

            if (submarine == null || !submarine.Loading)
            {
                Item.UpdateHulls();
                Gap.UpdateHulls();
            }

            WaterVolume = 0.0f;

            InsertToList();

            DebugConsole.Log("Created hull (" + ID + ")");
        }
Пример #4
0
        public Hull(MapEntityPrefab prefab, Rectangle rectangle, Submarine submarine)
            : base(prefab, submarine)
        {
            rect = rectangle;

            OxygenPercentage = 100.0f;

            FireSources = new List <FireSource>();
            linkedTo    = new System.Collections.ObjectModel.ObservableCollection <MapEntity>();



            properties = SerializableProperty.GetProperties(this);

            int arraySize = (int)Math.Ceiling((float)rectangle.Width / WaveWidth + 1);

            waveY   = new float[arraySize];
            waveVel = new float[arraySize];

            leftDelta  = new float[arraySize];
            rightDelta = new float[arraySize];

            surface = rect.Y - rect.Height;

            aiTarget = new AITarget(this);

            hullList.Add(this);

            ConnectedGaps = new List <Gap>();

            if (submarine == null || !submarine.Loading)
            {
                Item.UpdateHulls();
                Gap.UpdateHulls();
            }

            WaterVolume = 0.0f;

            InsertToList();
        }
Пример #5
0
        public Hull(MapEntityPrefab prefab, Rectangle rectangle, Submarine submarine)
            : base(prefab, submarine)
        {
            rect = rectangle;

            OxygenPercentage = 100.0f;

            fireSources = new List <FireSource>();

            properties = ObjectProperty.GetProperties(this);

            int arraySize = (rectangle.Width / WaveWidth + 1);

            waveY   = new float[arraySize];
            waveVel = new float[arraySize];

            leftDelta  = new float[arraySize];
            rightDelta = new float[arraySize];

            surface = rect.Y - rect.Height;

            aiTarget = new AITarget(this);

            hullList.Add(this);

            ConnectedGaps = new List <Gap>();

            if (submarine == null || !submarine.Loading)
            {
                Item.UpdateHulls();
                Gap.UpdateHulls();
            }

            WaterVolume = 0.0f;

            InsertToList();
        }
Пример #6
0
        public void FlipX(List <Submarine> parents = null)
        {
            if (parents == null)
            {
                parents = new List <Submarine>();
            }
            parents.Add(this);

            flippedX = !flippedX;

            Item.UpdateHulls();

            List <Item> bodyItems = Item.ItemList.FindAll(it => it.Submarine == this && it.body != null);

            List <MapEntity> subEntities = MapEntity.mapEntityList.FindAll(me => me.Submarine == this);

            foreach (MapEntity e in subEntities)
            {
                if (e.MoveWithLevel || e is Item)
                {
                    continue;
                }

                if (e is LinkedSubmarine)
                {
                    Submarine sub = ((LinkedSubmarine)e).Sub;
                    if (!parents.Contains(sub))
                    {
                        Vector2 relative1 = sub.SubBody.Position - SubBody.Position;
                        relative1.X = -relative1.X;
                        sub.SetPosition(relative1 + SubBody.Position);
                        sub.FlipX(parents);
                    }
                }
                else
                {
                    e.FlipX();
                }
            }

            foreach (MapEntity mapEntity in subEntities)
            {
                mapEntity.Move(-HiddenSubPosition);
            }

            Vector2 pos = new Vector2(subBody.Position.X, subBody.Position.Y);

            subBody.Body.Remove();
            subBody = new SubmarineBody(this);
            SetPosition(pos);

            if (entityGrid != null)
            {
                Hull.EntityGrids.Remove(entityGrid);
                entityGrid = null;
            }
            entityGrid = Hull.GenerateEntityGrid(this);

            foreach (MapEntity mapEntity in subEntities)
            {
                mapEntity.Move(HiddenSubPosition);
            }

            foreach (Item item in Item.ItemList)
            {
                if (bodyItems.Contains(item))
                {
                    item.Submarine = this;
                    if (Position == Vector2.Zero)
                    {
                        item.Move(-HiddenSubPosition);
                    }
                }
                else if (item.Submarine != this)
                {
                    continue;
                }

                item.FlipX();
            }

            Item.UpdateHulls();
            Gap.UpdateHulls();
        }