Exemplo n.º 1
0
        internal void RemoveAircraft(Aircraft aircraft)
        {
            var squadron = aircraft.Squadron;

            if (squadron != null)
            {
                squadron.RemoveAircraft(aircraft);
                if (squadron.Leader == null)
                {
                    RemoveSquadron(squadron);
                }
            }
            Aircrafts.Remove(aircraft);
            ActiveAircrafts.Remove(aircraft);
            aircraft.VertexZ = 0f;  // reset vertexZ
            if (PlayerAircrafts.Contains(aircraft))
            {
                PlayerAircrafts.Remove(aircraft);
                // check if the player now has lost all his aircrafts
                if (!PlayerAircrafts.Any())
                {
                    // and if true stop the PlayLayer and enter the WreckageLayer
                    EnterWreckageLayer();
                }
            }
            RemoveChild(aircraft);
        }
Exemplo n.º 2
0
        internal void StartPlanningPhase(bool suppressZoomPopup = false)
        {
            State = GameState.PLANNING;
            if (!PopUp.TriggeredZoom && !suppressZoomPopup)
            {
                PopUp.ShowPopUp(GUILayer, PopUp.Enum.TRIGGERED_ZOOM);
            }
            // find all active chunks
            // for that first find the player chunks and then grow around them
            // also calculate the new camera boundaries based on the plane positions
            float minX = float.PositiveInfinity;
            float minY = float.PositiveInfinity;
            float maxX = float.NegativeInfinity;
            float maxY = float.NegativeInfinity;
            var   activeChunksBefore = new CCPointI[ActiveChunks.Count];

            ActiveChunks.CopyTo(activeChunksBefore);
            ActiveChunks.Clear();
            foreach (var aircraft in PlayerAircrafts)
            {
                if (aircraft.Position.X < minX)
                {
                    minX = aircraft.Position.X;
                }
                if (aircraft.Position.X > maxX)
                {
                    maxX = aircraft.Position.X;
                }
                if (aircraft.Position.Y < minY)
                {
                    minY = aircraft.Position.Y;
                }
                if (aircraft.Position.Y > maxY)
                {
                    maxY = aircraft.Position.Y;
                }
                var aircraftChunk = PosToWorldChunk(aircraft.Position);
                for (int dx = -1; dx <= 1; dx++)
                {
                    for (int dy = -1; dy <= 1; dy++)
                    {
                        var activeChunk = aircraftChunk + new CCPointI(dx, dy);
                        if (!ActiveChunks.Contains(activeChunk))
                        {
                            ActiveChunks.Add(activeChunk);
                        }
                    }
                }
            }

            var noLongerActiveChunks = new List <CCPointI>();

            foreach (CCPointI chunkPoint in activeChunksBefore)
            {
                if (!ActiveChunks.Contains(chunkPoint))
                {
                    noLongerActiveChunks.Add(chunkPoint);
                }
            }

            const float BORDER = 5500f;

            CameraSpace = new CCRect(minX - BORDER, minY - BORDER, maxX - minX + BORDER * 2, maxY - minY + BORDER * 2);
            // check if there are any new chunks
            // if there are generate their contents (i.e. the enemies that are supposed to be there)
            foreach (var chunkPoint in ActiveChunks)
            {
                if (!KnownChunks.Contains(chunkPoint))
                {
                    InitiateChunk(chunkPoint);
                }
            }
            // prepare the squadrons
            // also find all currently active squadrons and aircrafts
            ActiveAircrafts.Clear();
            ActiveSquadrons.Clear();
            foreach (var squadron in Squadrons)
            {
                var chunkPoint = PosToWorldChunk(squadron.Position);
                if (ActiveChunks.Contains(chunkPoint))
                {
                    squadron.PrepareForPlanningPhase(this);
                    // add the squadron and the aircrafts to the active lists
                    ActiveSquadrons.Add(squadron);
                    foreach (var aircraft in squadron.AircraftsWithRelPositions.Keys)
                    {
                        ActiveAircrafts.Add(aircraft);
                    }
                }
                else if (noLongerActiveChunks.Contains(chunkPoint))
                {
                    foreach (var aircraft in squadron.AircraftsWithRelPositions.Keys)
                    {
                        aircraft.PrepareForStandby();
                    }
                }
            }
            // prepare the player-aircrafts
            foreach (var aircraft in PlayerAircrafts)
            {
                aircraft.PrepareForPlanningPhase();
            }
            // only go back to normal if the player is still alive
            if (PlayerIsAlive)
            {
                // make the ExecuteOrderButton visible again
                GUILayer.ExecuteOrdersButton.Visible = true;
            }
            else
            {
                ExecuteOrders();
                //AddAction(new CCSequence(new CCDelayTime(0.25f), new CCCallFunc( () => ExecuteOrders() )));
            }
        }