internal void PrepareForPlanningPhase(PlayLayer pl)
        {
            // first check the aggro
            // i.e. if an enemy (i.e. a player aircraft) is close enough break formation
            // also if one of the aircrafts is damaged break formation too
            if (InFormation)
            {
                foreach (var aircraft in pl.PlayerAircrafts)
                {
                    if (CCPoint.Distance(aircraft.Position, Position) < AggroRange)
                    {
                        //Console.WriteLine("TRIGGERED - DISTANCE");
                        InFormation = false;
                        break;
                    }
                }
                foreach (var aircraft in AircraftsWithRelPositions.Keys)
                {
                    if (aircraft.Health < aircraft.MaxHealth)
                    {
                        //Console.WriteLine("TRIGGERED - HP");
                        InFormation = false;
                        break;
                    }
                }
            }

            foreach (var aircraft in AircraftsWithRelPositions.Keys)
            {
                aircraft.PrepareForPlanningPhase();
            }

            if (!InFormation)
            {
                return;                 // squadrons only control their units while in formation
            }
            //Console.WriteLine("FLYING IN FORMATION");

            const float dt = Constants.TURN_DURATION;
            // if you're too close to the current Waypoint roll a new one
            var   diff            = WayPoint - Leader.Position;
            float advanceDistance = Velocity * dt;

            if (diff.Length < advanceDistance)
            {
                GenerateWayPoint();
                diff = WayPoint - Leader.Position;
            }
            LeaderWayPoint = Leader.Position + CCPoint.Normalize(diff) * advanceDistance;
            // rotate all formation positions correctly around the leader and tell everyone to go to their positions
            float angle = Constants.DxDyToRadians(diff.X, diff.Y);

            foreach (var entry in AircraftsWithRelPositions)
            {
                var formationPoint = CCPoint.RotateByAngle(entry.Value, CCPoint.Zero, angle);
                var yourWaypoint   = LeaderWayPoint + formationPoint;
                entry.Key.TryToSetFlightPathHeadTo(yourWaypoint);
            }
        }
Beispiel #2
0
 internal override void Clear()
 {
     TouchCountSource         = null;
     PlayLayer                = null;
     this.ExecuteOrdersButton = null;
     this.FirstTouchListener  = null;
     this.Scroller            = null;
     this.StopAllActions();
     this.ResetCleanState();
 }
 internal bool IsActive(PlayLayer pl)
 {
     return(pl.PosIsActive(Position));
 }
Beispiel #4
0
 public GUILayer(PlayLayer playLayer) : base(CCColor4B.Transparent, countTouches: true)
 {
     PlayLayer = playLayer;
     AddChild(ExecuteOrdersButton);
 }