コード例 #1
0
        private void AssignShipsToDefendObjective()
        {
            DefendPlanetObjective objective = this.m_Objective as DefendPlanetObjective;

            if (objective.DefendPatrolObjective != null)
            {
                int index = 0;
                foreach (Ship ship in this.m_Ships)
                {
                    if (index < this.m_ShipControls.Count)
                    {
                        this.m_ShipControls[index].AddShip(ship, false);
                    }
                    else
                    {
                        Vector3           patrolDirection   = objective.GetPatrolDirection(index);
                        PatrolShipControl patrolShipControl = new PatrolShipControl(this.m_Game, (TacticalObjective)objective.DefendPatrolObjective, this.m_CommanderAI, this.m_PatrolType, patrolDirection, 10000f, this.m_CommanderAI.AIRandom.CoinToss(0.5));
                        patrolShipControl.AddShip(ship, false);
                        this.m_ShipControls.Add((TaskGroupShipControl)patrolShipControl);
                    }
                    index = (index + 1) % 6;
                }
            }
            else
            {
                this.m_RequestedObjectiveType = ObjectiveType.PATROL;
            }
        }
コード例 #2
0
 private void AssignShipsToObjective()
 {
     if (this.m_Ships.Count == 0)
     {
         return;
     }
     if (this.m_Objective is ScoutObjective)
     {
         Ship bestScout = CombatAI.FindBestScout(this.m_Ships);
         if (bestScout == null)
         {
             this.m_RequestedObjectiveType = ObjectiveType.PATROL;
         }
         else
         {
             ScoutShipControl scoutShip = new ScoutShipControl(this.m_Game, this.m_Objective, this.m_CommanderAI, bestScout.SensorRange * 0.75f);
             scoutShip.AddShip(bestScout, false);
             if (this.m_Type == TaskGroupType.Civilian)
             {
                 foreach (Ship ship in this.m_Ships)
                 {
                     if (ship != bestScout)
                     {
                         scoutShip.AddShip(ship, false);
                     }
                 }
                 this.m_ShipControls.Add((TaskGroupShipControl)scoutShip);
             }
             else
             {
                 ScoutTrailShipControl trailShipControl = new ScoutTrailShipControl(this.m_Game, this.m_Objective, this.m_CommanderAI, scoutShip);
                 foreach (Ship ship in this.m_Ships)
                 {
                     if (ship != bestScout)
                     {
                         trailShipControl.AddShip(ship, false);
                     }
                 }
                 this.m_ShipControls.Add((TaskGroupShipControl)scoutShip);
                 this.m_ShipControls.Add((TaskGroupShipControl)trailShipControl);
             }
         }
     }
     else if (this.m_Objective is PatrolObjective)
     {
         PatrolShipControl patrolShipControl;
         if (this.m_Type == TaskGroupType.Police)
         {
             patrolShipControl = new PatrolShipControl(this.m_Game, this.m_Objective, this.m_CommanderAI, this.m_PatrolType, Vector3.UnitZ, this.m_Game.AssetDatabase.PolicePatrolRadius, this.m_CommanderAI.AIRandom.CoinToss(0.5));
         }
         else
         {
             Vector3 dir = -this.m_Objective.GetObjectiveLocation();
             if ((double)dir.LengthSquared > 0.0)
             {
                 double num = (double)dir.Normalize();
             }
             else
             {
                 dir = -Vector3.UnitZ;
             }
             bool clockwise = this.m_Type != TaskGroupType.Freighter && this.m_CommanderAI.AIRandom.CoinToss(0.5);
             patrolShipControl = new PatrolShipControl(this.m_Game, this.m_Objective, this.m_CommanderAI, this.m_PatrolType, dir, 10000f, clockwise);
         }
         foreach (Ship ship in this.m_Ships)
         {
             patrolShipControl.AddShip(ship, false);
         }
         this.m_ShipControls.Add((TaskGroupShipControl)patrolShipControl);
     }
     else if (this.m_Objective is AttackGroupObjective)
     {
         this.AssignShipsToAttackObjective();
     }
     else if (this.m_Objective is AttackPlanetObjective)
     {
         AttackPlanetShipControl planetShipControl = new AttackPlanetShipControl(this.m_Game, this.m_Objective, this.m_CommanderAI);
         foreach (Ship ship in this.m_Ships)
         {
             planetShipControl.AddShip(ship, false);
         }
         this.m_ShipControls.Add((TaskGroupShipControl)planetShipControl);
     }
     else if (this.m_Objective is DefendPlanetObjective)
     {
         this.AssignShipsToDefendObjective();
     }
     else if (this.m_Objective is EvadeEnemyObjective)
     {
         EvadeEnemyObjective objective = this.m_Objective as EvadeEnemyObjective;
         if (objective.EvadePatrolObjective != null)
         {
             Vector3           safePatrolDirection = objective.GetSafePatrolDirection(this.GetBaseGroupPosition());
             PatrolShipControl patrolShipControl   = new PatrolShipControl(this.m_Game, (TacticalObjective)objective.EvadePatrolObjective, this.m_CommanderAI, PatrolType.Circular, safePatrolDirection, 10000f, this.m_CommanderAI.AIRandom.CoinToss(0.5));
             foreach (Ship ship in this.m_Ships)
             {
                 patrolShipControl.AddShip(ship, false);
             }
             this.m_ShipControls.Add((TaskGroupShipControl)patrolShipControl);
         }
         else
         {
             this.m_RequestedObjectiveType = ObjectiveType.PATROL;
         }
     }
     else if (this.m_Objective is RetreatObjective)
     {
         RetreatShipControl retreatShipControl = new RetreatShipControl(this.m_Game, this.m_Objective, this.m_CommanderAI, this.m_Type != TaskGroupType.Freighter);
         foreach (Ship ship in this.m_Ships)
         {
             retreatShipControl.AddShip(ship, false);
         }
         this.m_ShipControls.Add((TaskGroupShipControl)retreatShipControl);
     }
     else if (this.m_Objective is BoardTargetObjective)
     {
         float val1 = float.MaxValue;
         foreach (Ship ship in this.m_Ships)
         {
             val1 = Math.Min(val1, CombatAI.GetAveEffectiveWeaponRange(ship, false));
         }
         PursueShipControl pursueShipControl = new PursueShipControl(this.m_Game, this.m_Objective, this.m_CommanderAI, val1 * 0.75f);
         foreach (Ship ship in this.m_Ships)
         {
             pursueShipControl.AddShip(ship, false);
         }
         this.m_ShipControls.Add((TaskGroupShipControl)pursueShipControl);
     }
     else
     {
         if (!(this.m_Objective is FollowTaskGroupObjective))
         {
             return;
         }
         SupportGroupShipControl groupShipControl = new SupportGroupShipControl(this.m_Game, this.m_Objective, this.m_CommanderAI, (TaskGroupShipControl)null);
         foreach (Ship ship in this.m_Ships)
         {
             groupShipControl.AddShip(ship, false);
         }
         this.m_ShipControls.Add((TaskGroupShipControl)groupShipControl);
     }
 }
コード例 #3
0
 public bool UpdateEnemyContact()
 {
     this.m_bIsInContactWithEnemy = false;
     if (this.m_Objective is DefendPlanetObjective)
     {
         this.m_EnemyGroupInContact   = (this.m_Objective as DefendPlanetObjective).GetClosestThreat();
         this.m_bIsInContactWithEnemy = this.m_EnemyGroupInContact != null;
     }
     if (!this.m_bIsInContactWithEnemy)
     {
         foreach (EnemyGroup enemyGroup in this.m_CommanderAI.GetEnemyGroups())
         {
             foreach (Ship ship in enemyGroup.m_Ships)
             {
                 foreach (TaskGroupShipControl shipControl in this.m_ShipControls)
                 {
                     if ((double)(ship.Maneuvering.Position - shipControl.GetCurrentPosition()).LengthSquared < (double)shipControl.SensorRange * (double)shipControl.SensorRange && (this.m_EnemyGroupInContact == null || this.m_EnemyGroupInContact == enemyGroup || enemyGroup.IsHigherPriorityThan(this.m_EnemyGroupInContact, this.m_CommanderAI, false)))
                     {
                         if (shipControl is ScoutShipControl)
                         {
                             (shipControl as ScoutShipControl).NotifyEnemyGroupDetected(enemyGroup);
                             if (this.m_ShipControls.Any <TaskGroupShipControl>((Func <TaskGroupShipControl, bool>)(x => x is ScoutTrailShipControl)))
                             {
                                 continue;
                             }
                         }
                         this.m_bIsInContactWithEnemy = true;
                         this.m_EnemyGroupInContact   = enemyGroup;
                     }
                 }
             }
         }
     }
     if (this.m_bIsInContactWithEnemy && !(this.m_Objective is RetreatObjective) && (!(this.m_Objective is BoardTargetObjective) && this.m_Type != TaskGroupType.Freighter) && this.m_Type != TaskGroupType.BoardingGroup)
     {
         if (this.m_Objective is AttackGroupObjective || this.m_Objective is AttackPlanetObjective)
         {
             float num = this.m_EnemyGroupInContact.m_Ships.Count > 0 ? this.m_EnemyGroupInContact.m_Ships.Average <Ship>((Func <Ship, float>)(x => x.Maneuvering.MaxShipSpeed)) : 0.0f;
             if ((!(this.m_Objective is AttackPlanetObjective) || this.m_Type != TaskGroupType.PlanetAssault && (double)num <= (double)this.m_GroupSpeed + 5.0) && (this.m_Objective.m_TargetEnemyGroup == null || this.m_Objective.m_TargetEnemyGroup != this.m_EnemyGroupInContact && !this.m_Objective.m_TargetEnemyGroup.IsFreighterEnemyGroup()) && (this.m_Objective.m_TargetEnemyGroup == null || this.m_EnemyGroupInContact.IsHigherPriorityThan(this.m_Objective.m_TargetEnemyGroup, this.m_CommanderAI, false)))
             {
                 this.Objective = (TacticalObjective)null;
             }
         }
         else if (this.m_Objective is EvadeEnemyObjective && this.m_CommanderAI.GetTaskGroups().Count <TaskGroup>() > 1)
         {
             Vector3 safePatrolDirection = (this.m_Objective as EvadeEnemyObjective).GetSafePatrolDirection(this.GetBaseGroupPosition());
             foreach (TaskGroupShipControl shipControl in this.m_ShipControls)
             {
                 if (shipControl is PatrolShipControl)
                 {
                     PatrolShipControl patrolShipControl = shipControl as PatrolShipControl;
                     if ((double)Vector3.Dot(safePatrolDirection, patrolShipControl.PreviousDir) < 0.800000011920929)
                     {
                         patrolShipControl.ResetPatrolWaypoints(PatrolType.Circular, safePatrolDirection, 10000f);
                     }
                 }
             }
         }
         else
         {
             this.m_RequestedObjectiveType = ObjectiveType.ATTACK_TARGET;
         }
     }
     return(this.m_bIsInContactWithEnemy);
 }