public void RequestTargetFromParent(LocustFighterControl lfc) { if (this.m_TargetList.Count == 0 && !(this.m_Target is StellarBody)) { lfc.SetTarget((IGameObject)this.m_LocustNest); } else { LocustTarget locustTarget = (LocustTarget)null; float num1 = float.MaxValue; foreach (LocustTarget target in this.m_TargetList) { int num2 = LocustFighterControl.NumFightersPerShip(target.Target.ShipClass); if (target.FightersOnTarget < num2) { float lengthSquared = (target.Target.Position - lfc.GetShip().Position).LengthSquared; if ((double)lengthSquared < (double)num1) { num1 = lengthSquared; locustTarget = target; } } } if (locustTarget != null) { locustTarget.IncFightersOnTarget(); lfc.SetTarget((IGameObject)locustTarget.Target); } else if (this.m_NumLocustsReachedPlanet > 0 && this.m_Target is StellarBody) { lfc.SetTarget(this.m_Target); } else { lfc.SetTarget((IGameObject)this.m_LocustNest); } } }
public override void FindNewTarget(IEnumerable <IGameObject> objs) { this.m_Planets.Clear(); List <LocustTarget> locustTargetList = new List <LocustTarget>(); List <LocustTarget> source = new List <LocustTarget>(); foreach (LocustTarget target in this.m_TargetList) { target.ClearNumTargets(); } source.AddRange((IEnumerable <LocustTarget>) this.m_TargetList); foreach (IGameObject gameObject in objs) { if (gameObject is Ship) { Ship ship = gameObject as Ship; if (Ship.IsActiveShip(ship) && ship.Player != this.m_LocustNest.Player) { bool flag = ship.IsDetected(this.m_LocustNest.Player); foreach (LocustFighterControl spawnedFighter in this.m_SpawnedFighters) { if (ship == spawnedFighter.GetTarget()) { if (!flag) { spawnedFighter.SetTarget((IGameObject)null); break; } break; } } if (flag) { locustTargetList.Add(new LocustTarget() { Target = ship }); LocustTarget locustTarget = source.FirstOrDefault <LocustTarget>((Func <LocustTarget, bool>)(x => x.Target == ship)); if (locustTarget != null) { source.Remove(locustTarget); } } } } if (gameObject is StellarBody) { StellarBody stellarBody = gameObject as StellarBody; if (this.m_Game.GameDatabase.GetColonyInfoForPlanet(stellarBody.Parameters.OrbitalID) != null) { this.m_Planets.Add(stellarBody); } } } if (source.Count > 0) { foreach (LocustFighterControl spawnedFighter in this.m_SpawnedFighters) { LocustFighterControl fighter = spawnedFighter; if (source.Any <LocustTarget>((Func <LocustTarget, bool>)(x => x.Target == fighter.GetTarget()))) { fighter.SetTarget((IGameObject)null); } } } if (locustTargetList.Count > this.m_TargetList.Count) { foreach (LocustTarget target in this.m_TargetList) { ShipClass shipClass = target.Target.ShipClass; target.ClearNumTargets(); int num = LocustFighterControl.NumFightersPerShip(shipClass); foreach (LocustFighterControl spawnedFighter in this.m_SpawnedFighters) { if (spawnedFighter.GetTarget() == target.Target) { if (num > 0) { --num; target.IncFightersOnTarget(); } else { spawnedFighter.SetTarget((IGameObject)null); } } } } } else { foreach (LocustFighterControl spawnedFighter in this.m_SpawnedFighters) { LocustFighterControl fighter = spawnedFighter; if (fighter.GetTarget() != null) { this.m_TargetList.FirstOrDefault <LocustTarget>((Func <LocustTarget, bool>)(x => x.Target == fighter.GetTarget()))?.IncFightersOnTarget(); } } } foreach (LocustTarget locustTarget in locustTargetList) { LocustTarget target = locustTarget; if (!this.m_TargetList.Any <LocustTarget>((Func <LocustTarget, bool>)(x => x.Target == target.Target))) { target.ClearNumTargets(); this.m_TargetList.Add(target); } } this.m_UpdateTargetList = false; }