public static EnemyGroupData GetEnemyGroupData( CombatAI ai, EnemyGroup eg, List <StellarBody> planets) { EnemyGroupData enemyGroupData = new EnemyGroupData(); enemyGroupData.DistanceFromColony = 0.0f; enemyGroupData.NumAggressive = 0; enemyGroupData.NumCivilian = 0; enemyGroupData.NumPassive = 0; enemyGroupData.NumUnarmed = 0; enemyGroupData.IsAttackingPlanetOrStation = false; enemyGroupData.IsEncounter = false; enemyGroupData.IsFreighter = false; enemyGroupData.IsStation = false; foreach (Ship ship in eg.m_Ships) { if (ship.ShipRole == ShipRole.FREIGHTER) { enemyGroupData.IsFreighter = true; } if (TaskGroup.IsValidTaskGroupShip(ship)) { switch (TaskGroup.GetTaskTypeFromShip(ship)) { case TaskGroupType.Aggressive: case TaskGroupType.Police: case TaskGroupType.BoardingGroup: case TaskGroupType.FollowGroup: case TaskGroupType.PlanetAssault: ++enemyGroupData.NumAggressive; break; case TaskGroupType.Passive: ++enemyGroupData.NumPassive; break; case TaskGroupType.Civilian: ++enemyGroupData.NumCivilian; break; case TaskGroupType.UnArmed: ++enemyGroupData.NumUnarmed; break; } } else if (ship.ShipClass == ShipClass.Station) { enemyGroupData.IsStation = true; } if (ship.Target != null && !enemyGroupData.IsAttackingPlanetOrStation) { if (ship.Target is Ship) { Ship target = ship.Target as Ship; enemyGroupData.IsAttackingPlanetOrStation = target.Player == ai.m_Player && target.ShipClass == ShipClass.Station; } else if (ship.Target is StellarBody && (ship.Target as StellarBody).Parameters.ColonyPlayerID == ai.m_Player.ID) { enemyGroupData.IsAttackingPlanetOrStation = true; } } enemyGroupData.IsEncounter = enemyGroupData.IsEncounter || ai.IsEncounterPlayer(ship.Player.ID); foreach (StellarBody planet in planets) { if (planet.Parameters.ColonyPlayerID == ai.m_Player.ID) { float lengthSquared = (planet.Parameters.Position - ship.Position).LengthSquared; if ((double)enemyGroupData.DistanceFromColony == 0.0 || (double)lengthSquared < (double)enemyGroupData.DistanceFromColony) { enemyGroupData.DistanceFromColony = lengthSquared; } } } } if ((double)enemyGroupData.DistanceFromColony > 0.0) { enemyGroupData.DistanceFromColony = (float)Math.Sqrt((double)enemyGroupData.DistanceFromColony); } return(enemyGroupData); }
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)); }