Exemplo n.º 1
0
        public virtual int CurrentResources()
        {
            int num = 0;

            foreach (TaskGroup taskGroup in this.m_TaskGroups)
            {
                num += CombatAI.AssessGroupStrength(taskGroup.GetShips());
            }
            return(num);
        }
Exemplo n.º 2
0
        public override int ResourceNeeds()
        {
            int num = 0;

            foreach (EnemyGroup enemyGroup in this.m_ThreatsInRange)
            {
                num += CombatAI.AssessGroupStrength(enemyGroup.m_Ships);
            }
            return(num);
        }
        protected override bool IsReadyToFire()
        {
            if (this.m_Ship.TaskGroup == null || this.m_Ship.TaskGroup.Objective.m_TargetEnemyGroup == null || (double)this.m_Ship.Maneuvering.Velocity.LengthSquared > 100.0)
            {
                return(false);
            }
            Vector3 desiredTargetPosition = this.GetDesiredTargetPosition(this.m_Ship.TaskGroup.Objective.m_TargetEnemyGroup);
            float   num = this.m_MaxRange * 0.75f;
            Vector3 v1  = desiredTargetPosition - this.m_Ship.Position;

            v1.Y = 0.0f;
            if ((double)v1.Normalize() > (double)num)
            {
                return(false);
            }
            bool flag = false;

            foreach (Ship friendlyShip in this.m_CommanderAI.GetFriendlyShips())
            {
                if (Ship.IsActiveShip(friendlyShip))
                {
                    Vector3 v0 = friendlyShip.Position - this.m_Ship.Position;
                    v0.Y = 0.0f;
                    if ((double)v0.Normalize() <= (double)this.m_MaxRange && (double)Vector3.Dot(v0, v1) > 0.899999976158142)
                    {
                        flag = true;
                        break;
                    }
                }
            }
            if (flag)
            {
                return(false);
            }
            if (CombatAI.AssessGroupStrength(this.m_Ship.TaskGroup.Objective.m_TargetEnemyGroup.m_Ships) < this.m_EnemyGroupStrngth)
            {
                return(true);
            }
            List <Ship> shipList = new List <Ship>();

            foreach (Ship ship in this.m_Ship.TaskGroup.Objective.m_TargetEnemyGroup.m_Ships)
            {
                Vector3 v0 = ship.Position - this.m_Ship.Position;
                v0.Y = 0.0f;
                if ((double)v0.Normalize() <= (double)this.m_MaxRange && (double)Vector3.Dot(v0, v1) > 0.899999976158142)
                {
                    shipList.Add(ship);
                }
            }
            return(CombatAI.AssessGroupStrength(this.m_Ship.TaskGroup.Objective.m_TargetEnemyGroup.m_Ships) >= this.m_EnemyGroupStrngth);
        }
Exemplo n.º 4
0
        public override void Update()
        {
            int num = 0;

            this.m_ThreatsInRange.Clear();
            foreach (EnemyGroup enemyGroup in this.m_CommandAI.GetEnemyGroups())
            {
                if (enemyGroup.GetClosestShip(this.GetObjectiveLocation(), this.m_ShipSensorRange) != null)
                {
                    this.m_ThreatsInRange.Add(enemyGroup);
                    num += CombatAI.AssessGroupStrength(enemyGroup.m_Ships);
                }
            }
            this.m_IsUnsafe = num > 50;
        }
Exemplo n.º 5
0
        public bool IsDesiredGroupTargetTaken(TaskGroupShipControl group, Ship desiredTarget)
        {
            int num = CombatAI.AssessGroupStrength(group.GetShips());

            foreach (TaskGroupShipControl shipControl in this.m_ShipControls)
            {
                if (shipControl != group && shipControl.GroupPriorityTarget == desiredTarget)
                {
                    if (CombatAI.AssessGroupStrength(shipControl.GetShips()) >= num)
                    {
                        return(true);
                    }
                    break;
                }
            }
            return(false);
        }
Exemplo n.º 6
0
 public override int ResourceNeeds()
 {
     return(CombatAI.AssessGroupStrength(this.m_TargetEnemyGroup.m_Ships));
 }
Exemplo n.º 7
0
 private void AssignShipsToAttackObjective()
 {
     if (this.m_Objective != null && this.m_Objective.m_TargetEnemyGroup == null)
     {
         this.m_RequestedObjectiveType = ObjectiveType.PATROL;
     }
     else if (this.m_Type == TaskGroupType.Police || this.m_CommanderAI.GetAIType() == OverallAIType.PIRATE)
     {
         this.m_ShipControls.Add(this.CreatePursueAttackGroup(this.m_Ships));
     }
     else
     {
         Vector3     objectiveLocation = this.m_Objective.GetObjectiveLocation();
         float       groupRadius       = this.m_Objective.m_TargetEnemyGroup.GetGroupRadius();
         List <Ship> shipList1         = new List <Ship>();
         List <Ship> shipList2         = new List <Ship>();
         int[]       numArray          = new int[14];
         foreach (Ship ship in this.m_Ships)
         {
             float num = groupRadius + TaskGroup.ATTACK_GROUP_RANGE + ship.SensorRange;
             if ((double)(objectiveLocation - ship.Maneuvering.Position).LengthSquared < (double)num * (double)num)
             {
                 shipList1.Add(ship);
                 ++numArray[(int)ship.RealShipClass];
             }
             else
             {
                 shipList2.Add(ship);
             }
         }
         int num1 = CombatAI.AssessGroupStrength(this.m_Objective.m_TargetEnemyGroup.m_Ships);
         int num2 = CombatAI.AssessGroupStrength(shipList1);
         if (num2 > num1 && this.m_Type != TaskGroupType.Civilian)
         {
             List <Ship> list = shipList1.Where <Ship>((Func <Ship, bool>)(x =>
             {
                 if (x.RealShipClass != RealShipClasses.Leviathan)
                 {
                     return(x.RealShipClass == RealShipClasses.Dreadnought);
                 }
                 return(true);
             })).ToList <Ship>();
             foreach (Ship ship in list)
             {
                 shipList1.Remove(ship);
             }
             if (list.Count > 0)
             {
                 this.m_ShipControls.Add(this.CreateStandOffAttackGroup(list));
             }
             if (shipList1.Count > 0)
             {
                 float num3 = 5f;
                 float num4 = Math.Min(Math.Max((float)((double)shipList1.Count / 5.0 - 1.0), 0.0f), 1f) * 5f;
                 float num5 = 0.0f;
                 if ((double)this.m_CommanderAI.AIRandom.NextInclusive(0.0f, num3 + num4 + num5) <= (double)num3)
                 {
                     List <Ship> ships    = new List <Ship>();
                     int         maxValue = Math.Max(shipList1.Count - 5, 0);
                     if (maxValue > 0 && this.m_Type != TaskGroupType.Civilian)
                     {
                         for (int index1 = 1; index1 > 0 && maxValue > 0; maxValue = Math.Max(shipList1.Count - 5, 0))
                         {
                             index1 = this.m_CommanderAI.AIRandom.NextInclusive(0, maxValue);
                             for (int index2 = 0; index2 < index1; ++index2)
                             {
                                 ships.Add(shipList1[index2]);
                             }
                             if (ships.Count != 0)
                             {
                                 foreach (Ship ship in ships)
                                 {
                                     shipList1.Remove(ship);
                                 }
                                 this.m_ShipControls.Add(this.CreateStandOffAttackGroup(ships));
                             }
                             else
                             {
                                 break;
                             }
                         }
                     }
                     this.m_ShipControls.Add(this.CreateFlyByAttackGroup(shipList1));
                 }
                 else if (shipList1.Count > 0)
                 {
                     bool    flag              = false;
                     int     num6              = Math.Min(shipList1.Count, 6);
                     int     val1              = (int)Math.Ceiling((double)shipList1.Count / (double)num6);
                     float   radians           = MathHelper.DegreesToRadians(360f / (float)num6);
                     float   num7              = (float)-((double)radians * 0.5);
                     Vector3 baseGroupPosition = this.GetBaseGroupPosition();
                     Vector3 forward           = objectiveLocation - baseGroupPosition;
                     forward.Y = 0.0f;
                     double num8  = (double)forward.Normalize();
                     Matrix world = Matrix.CreateWorld(baseGroupPosition, forward, Vector3.UnitY);
                     for (int index1 = 0; index1 < num6; ++index1)
                     {
                         float       num9   = index1 % 2 == 0 ? -1f : 1f;
                         float       num10  = (float)Math.Floor((double)(index1 % num6 + 1) * 0.5);
                         Matrix      matrix = Matrix.CreateRotationYPR(num9 * radians * num10 + num7, 0.0f, 0.0f) * world;
                         List <Ship> ships  = new List <Ship>();
                         int         num11  = shipList1.Count <= num6 - index1 ? 1 : Math.Min(val1, shipList1.Count - 1);
                         for (int index2 = 0; index2 < num11; ++index2)
                         {
                             ships.Add(shipList1[index2]);
                         }
                         foreach (Ship ship in ships)
                         {
                             shipList1.Remove(ship);
                         }
                         if (flag)
                         {
                             this.m_ShipControls.Add(this.CreateFlankAttackGroups(ships, matrix.Forward));
                         }
                         else
                         {
                             this.m_ShipControls.Add(this.CreateSurroundAttackGroups(ships, matrix.Forward));
                         }
                         if (shipList1.Count == 0)
                         {
                             break;
                         }
                     }
                 }
             }
         }
         else if (num2 * 2 < num1)
         {
             this.m_ShipControls.Add(this.CreateStandOffAttackGroup(shipList1));
         }
         else
         {
             this.m_ShipControls.Add(this.CreatePursueAttackGroup(shipList1));
         }
         TaskGroupShipControl shipControl1 = this.m_ShipControls[0];
         foreach (Ship ship1 in shipList2)
         {
             bool flag = false;
             foreach (TaskGroupShipControl shipControl2 in this.m_ShipControls)
             {
                 if (shipControl2 != shipControl1)
                 {
                     foreach (Ship ship2 in shipControl2.GetShips())
                     {
                         if ((double)(ship2.Maneuvering.Position - ship1.Maneuvering.Position).LengthSquared < (double)TaskGroup.ATTACK_GROUP_RANGE * (double)TaskGroup.ATTACK_GROUP_RANGE)
                         {
                             shipControl2.AddShip(ship1, false);
                             flag = true;
                             break;
                         }
                     }
                     if (flag)
                     {
                         break;
                     }
                 }
             }
             if (!flag)
             {
                 this.m_ShipControls.Add(this.CreateSupportGroup(new List <Ship>()
                 {
                     ship1
                 }, this.m_ShipControls[0]));
             }
         }
     }
 }
Exemplo n.º 8
0
        public bool IsHigherPriorityThan(EnemyGroup eg, CombatAI ai, bool defendObjAsking = false)
        {
            if (eg == null)
            {
                return(true);
            }
            EnemyGroupData enemyGroupData1 = EnemyGroup.GetEnemyGroupData(ai, this, ai.PlanetsInSystem);
            EnemyGroupData enemyGroupData2 = EnemyGroup.GetEnemyGroupData(ai, eg, ai.PlanetsInSystem);

            if (ai.GetAIType() == OverallAIType.PIRATE)
            {
                if (enemyGroupData1.IsFreighter || enemyGroupData2.IsFreighter)
                {
                    if (enemyGroupData1.IsFreighter && !enemyGroupData2.IsFreighter)
                    {
                        return(true);
                    }
                    if (!enemyGroupData1.IsFreighter && enemyGroupData2.IsFreighter)
                    {
                        return(false);
                    }
                    float val2_1 = float.MaxValue;
                    float val2_2 = float.MaxValue;
                    bool  flag   = false;
                    foreach (TaskGroup taskGroup in ai.GetTaskGroups())
                    {
                        Vector3 baseGroupPosition = taskGroup.GetBaseGroupPosition();
                        Ship    closestShip1      = this.GetClosestShip(baseGroupPosition, 100000f);
                        Ship    closestShip2      = eg.GetClosestShip(baseGroupPosition, 100000f);
                        if (closestShip1 != null && closestShip2 != null)
                        {
                            val2_1 = Math.Min((closestShip1.Position - baseGroupPosition).LengthSquared, val2_1);
                            val2_2 = Math.Min((closestShip2.Position - baseGroupPosition).LengthSquared, val2_2);
                            flag   = true;
                        }
                    }
                    if (flag)
                    {
                        return((double)val2_1 < (double)val2_2);
                    }
                }
                return(CombatAI.AssessGroupStrength(this.m_Ships) > CombatAI.AssessGroupStrength(eg.m_Ships));
            }
            if (enemyGroupData1.IsEncounter || enemyGroupData2.IsEncounter)
            {
                if (enemyGroupData1.IsEncounter && !enemyGroupData2.IsEncounter)
                {
                    return(true);
                }
                if (enemyGroupData1.IsEncounter)
                {
                    return(!enemyGroupData1.IsStation);
                }
                return(false);
            }
            if (ai.OwnsSystem)
            {
                if (enemyGroupData1.IsAttackingPlanetOrStation || enemyGroupData2.IsAttackingPlanetOrStation || defendObjAsking)
                {
                    if (enemyGroupData1.IsAttackingPlanetOrStation && !enemyGroupData2.IsAttackingPlanetOrStation)
                    {
                        return(true);
                    }
                    if (!enemyGroupData1.IsAttackingPlanetOrStation && enemyGroupData2.IsAttackingPlanetOrStation)
                    {
                        return(false);
                    }
                    if ((double)enemyGroupData1.DistanceFromColony > 0.0 && (double)enemyGroupData2.DistanceFromColony > 0.0)
                    {
                        return((double)enemyGroupData1.DistanceFromColony < (double)enemyGroupData2.DistanceFromColony);
                    }
                }
                if (enemyGroupData1.NumAggressive > 0 || enemyGroupData2.NumAggressive > 0)
                {
                    return(enemyGroupData1.NumAggressive > enemyGroupData2.NumAggressive);
                }
                if (enemyGroupData1.NumPassive > 0 || enemyGroupData2.NumPassive > 0)
                {
                    return(enemyGroupData1.NumPassive > enemyGroupData2.NumPassive);
                }
                if (enemyGroupData1.NumCivilian > 0 || enemyGroupData2.NumCivilian > 0)
                {
                    return(enemyGroupData1.NumCivilian > enemyGroupData2.NumCivilian);
                }
                if (enemyGroupData1.NumUnarmed > 0 || enemyGroupData2.NumUnarmed > 0)
                {
                    return(enemyGroupData1.NumUnarmed > enemyGroupData2.NumUnarmed);
                }
            }
            else
            {
                if (enemyGroupData1.IsStation || enemyGroupData2.IsStation)
                {
                    if (enemyGroupData1.IsAttackingPlanetOrStation && !enemyGroupData2.IsAttackingPlanetOrStation)
                    {
                        return(true);
                    }
                    if (!enemyGroupData1.IsAttackingPlanetOrStation && enemyGroupData2.IsAttackingPlanetOrStation)
                    {
                        return(false);
                    }
                    if ((double)enemyGroupData1.DistanceFromColony > 0.0 && (double)enemyGroupData2.DistanceFromColony > 0.0)
                    {
                        return((double)enemyGroupData1.DistanceFromColony < (double)enemyGroupData2.DistanceFromColony);
                    }
                }
                if (enemyGroupData1.NumAggressive > 0 || enemyGroupData2.NumAggressive > 0)
                {
                    return(enemyGroupData1.NumAggressive > enemyGroupData2.NumAggressive);
                }
                if (enemyGroupData1.NumPassive > 0 || enemyGroupData2.NumPassive > 0)
                {
                    return(enemyGroupData1.NumPassive > enemyGroupData2.NumPassive);
                }
                if (enemyGroupData1.NumCivilian > 0 || enemyGroupData2.NumCivilian > 0)
                {
                    return(enemyGroupData1.NumCivilian > enemyGroupData2.NumCivilian);
                }
                if (enemyGroupData1.NumUnarmed > 0 || enemyGroupData2.NumUnarmed > 0)
                {
                    return(enemyGroupData1.NumUnarmed > enemyGroupData2.NumUnarmed);
                }
            }
            return(CombatAI.AssessGroupStrength(this.m_Ships) > CombatAI.AssessGroupStrength(eg.m_Ships));
        }