private TaskGroupShipControl CreatePursueAttackGroup(List <Ship> ships) { float val1_1 = float.MaxValue; float val1_2 = float.MaxValue; foreach (Ship ship in ships) { val1_1 = Math.Min(val1_1, CombatAI.GetAveEffectiveWeaponRange(ship, false)); val1_2 = Math.Min(val1_2, ship.SensorRange); } PursueShipControl pursueShipControl = new PursueShipControl(this.m_Game, this.m_Objective, this.m_CommanderAI, Math.Min(val1_1 * 0.75f, val1_2 * 0.75f)); foreach (Ship ship in ships) { pursueShipControl.AddShip(ship, (this.m_Type == TaskGroupType.Aggressive || this.m_Type == TaskGroupType.Passive) && TaskGroup.GetTaskTypeFromShip(ship) == TaskGroupType.Civilian); } return((TaskGroupShipControl)pursueShipControl); }
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); } }