public bool IsInSightRange(Attackable a, int faction) { foreach (Attackable att in attackables) { if (att.Faction == faction && AttackableHelper.Distance(att, a) <= att.VisionRange) { return(true); } } return(false); }
public List <Attackable> GetAllFriendlyUnitsInRange(Unit u, float range) { List <Attackable> friendly = new List <Attackable>(); foreach (Attackable a in attackables) { if (a != u && a.Faction == u.Faction && AttackableHelper.Distance(u, a) <= range) { friendly.Add(a); } } return(friendly); }
public Attackable GetNearestTarget(Attackable u, float range = float.MaxValue) { float distance = float.MaxValue; Attackable closest = null; foreach (Attackable a in attackables) { if (a == u || a.Faction == u.Faction) { continue; } float d = AttackableHelper.Distance(u, a); if (d < range && d < distance) { closest = a; distance = d; } } return(closest); }