public AttackGroupObjective(EnemyGroup eGroup) { this.m_ObjectiveType = ObjectiveType.ATTACK_TARGET; this.m_TargetEnemyGroup = eGroup; this.m_TaskGroups = new List <TaskGroup>(); this.m_RequestTaskGroup = false; }
public TaskGroup(App game, CombatAI commandAI) { this.m_Game = game; this.m_CommanderAI = commandAI; this.m_Objective = (TacticalObjective)null; this.m_Orders = TaskGroupOrders.None; this.m_Type = TaskGroupType.Aggressive; this.m_bIsPlayerOrder = false; this.m_bIsInContactWithEnemy = false; this.m_EnemyGroupInContact = (EnemyGroup)null; this.m_Ships = new List <Ship>(); this.m_Targets = new List <Ship>(); this.m_ShipControls = new List <TaskGroupShipControl>(); this.m_TargetGroup = (EnemyGroup)null; this.m_TargetTaskGroup = (TaskGroup)null; this.m_PatrolType = PatrolType.Circular; this.m_RequestedObjectiveType = ObjectiveType.NO_OBJECTIVE; this.m_NumShipTypes = new int[14]; for (int index = 0; index < 14; ++index) { this.m_NumShipTypes[index] = 0; } this.m_GroupSpeed = 0.0f; this.m_RequestRefreshShipControls = false; this.m_ChangeAttackTime = 4800; this.m_CurrentChangeAttackDelay = this.m_ChangeAttackTime; }
public virtual void Shutdown() { this.m_TargetTaskGroup = (TaskGroup)null; this.m_TargetEnemyGroup = (EnemyGroup)null; this.m_PoliceOwner = (Ship)null; this.m_Planet = (StellarBody)null; this.m_TaskGroups.Clear(); }
protected override Vector3 GetDesiredTargetPosition(EnemyGroup enemy) { Vector3 vector3 = enemy.m_LastKnownPosition; if ((double)(enemy.m_LastKnownDestination - enemy.m_LastKnownPosition).LengthSquared < (double)(enemy.m_LastKnownPosition - vector3).LengthSquared) { vector3 = enemy.m_LastKnownDestination; } return(this.m_Ship.Maneuvering.Position + Vector3.Normalize(this.m_Ship.Maneuvering.Position - vector3) * this.m_MaxRange); }
public ScoutObjective(EnemyGroup eGroup, Player player) { this.m_ObjectiveType = ObjectiveType.SCOUT; this.m_TargetEnemyGroup = eGroup; this.m_Destination = eGroup.m_LastKnownPosition; this.m_TaskGroups = new List <TaskGroup>(); this.m_Player = player; this.m_RequestTaskGroup = false; this.m_Planet = (StellarBody)null; }
public EnemyGroup GetClosestThreat() { EnemyGroup eg = (EnemyGroup)null; foreach (EnemyGroup enemyGroup in this.m_ThreatsInRange) { if (eg == null || enemyGroup.IsHigherPriorityThan(eg, this.m_CommandAI, true)) { eg = enemyGroup; } } return(eg); }
protected virtual Vector3 GetDesiredTargetPosition(EnemyGroup enemy) { Vector3 vector3 = enemy.m_LastKnownPosition; if ((double)this.m_WeaponSpeed > 0.0) { float num = (this.m_Ship.Maneuvering.Position - vector3).Length / this.m_WeaponSpeed; vector3 += enemy.m_LastKnownHeading * num; if ((double)(enemy.m_LastKnownDestination - enemy.m_LastKnownPosition).LengthSquared < (double)(enemy.m_LastKnownPosition - vector3).LengthSquared) { vector3 = enemy.m_LastKnownDestination; } } return(vector3); }
public EnemyGroup GetClosestThreat() { EnemyGroup enemyGroup1 = (EnemyGroup)null; float num = float.MaxValue; foreach (EnemyGroup enemyGroup2 in this.m_ThreatsInRange) { float lengthSquared = (enemyGroup2.m_LastKnownPosition - this.m_Planet.Parameters.Position).LengthSquared; if ((double)lengthSquared < (double)num) { num = lengthSquared; enemyGroup1 = enemyGroup2; } } return(enemyGroup1); }
protected override Vector3 GetDesiredTargetPosition(EnemyGroup enemy) { Vector3 vector3_1 = enemy.m_LastKnownPosition; if ((double)(enemy.m_LastKnownDestination - enemy.m_LastKnownPosition).LengthSquared < (double)(enemy.m_LastKnownPosition - vector3_1).LengthSquared) { vector3_1 = enemy.m_LastKnownDestination; } Vector3 vector3_2 = this.m_Ship.Maneuvering.Position - vector3_1; float num1 = vector3_2.Normalize(); float num2 = (float)((double)this.m_EffectRange + (double)this.m_Ship.ShipSphere.radius + 500.0); if ((double)num1 < (double)num2) { vector3_1 = this.m_Ship.Maneuvering.Position + vector3_2 * num2; } return(vector3_1); }
public void NotifyEnemyGroupDetected(EnemyGroup eGroup) { this.m_EnemyGroup = eGroup; this.m_EncounteredEnemy = this.m_EnemyGroup != null; }
public void ClearEnemyGroupInContact() { this.m_EnemyGroupInContact = (EnemyGroup)null; this.m_bIsInContactWithEnemy = false; }
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); }
public virtual void FindNewTarget(EnemyGroup targetEnemyGroup) { this.m_RequestNewTarget = false; }
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)); }