Example #1
0
        private protected void InitiateChunk(CCPointI chunkPoint)
        {
            // add some squadrons randomly
            var       rng        = new Random();
            const int squadCount = 5;
            // choose random positions inside of this chunk
            CCPoint chunkMiddle = ChunkToWorldPos(chunkPoint);

            for (int i = 0; i < squadCount; i++)
            {
                var randomPos = Constants.RandomPointBoxnear(chunkMiddle, CHUNK_SIZE / 2, rng);
                int zone      = RadiusToZoneNum(randomPos.Length);
                // place more squads in zone 1 and less in zone 3 (statistically)
                switch (zone)
                {
                case 1:
                    if (rng.Next(3) == 0)
                    {
                        i--;
                    }
                    break;

                case 3:
                    if (rng.Next(3) == 0)
                    {
                        i++;
                    }
                    break;

                default:
                    break;
                }
                var newSquadron = GenerateSquadron(zone, rng);
                if (newSquadron != null)
                {
                    // choose a random orientation
                    var CCdirection = (float)rng.NextDouble() * 360f;
                    AddSquadron(newSquadron, randomPos, CCdirection);
                }
            }

            KnownChunks.Add(chunkPoint);
        }
Example #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() )));
            }
        }
Example #3
0
 internal static CCPoint ChunkToWorldPos(CCPointI chunkPos)
 {
     return(new CCPoint(chunkPos.X * (int)CHUNK_SIZE, chunkPos.Y * (int)CHUNK_SIZE));
 }