Exemple #1
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);
 }