// Returns attack postion of target in world public static Vector2?ChooseTargetVector(TeamType teamType, float range, Rectangle bb, Guid interiorId) { foreach (var otherTeam in BoundingBoxLocations.BoundingBoxLocationMap.Keys) { if (AttackMapping.AttackMappings[teamType][otherTeam]) { Vector2?shotCords = null; if (BoundingBoxLocations.BoundingBoxLocationMap[otherTeam].Any()) { float minVMag = float.MaxValue; foreach (var target in BoundingBoxLocations.BoundingBoxLocationMap[otherTeam]) { float vmag = PhysicsUtility.VectorMagnitude(target.targetLoc.X, bb.X, target.targetLoc.Y, bb.Y); if (vmag < minVMag && interiorId == target.interiorId) { minVMag = vmag; shotCords = target.targetLoc; } } if (minVMag <= range) { return(shotCords); } } else { return(null); } } } return(null); }
// Returns tile point of target (pass the pathType on which you desire to find a target - i.e. ships don't build paths to land tiles) and the distance between target and this bb public static Tuple <Point?, float> ChooseTargetPoint(TeamType teamType, float range, Rectangle bb, Guid interiorId, PathType pathType) { foreach (var otherTeam in BoundingBoxLocations.BoundingBoxLocationMap.Keys) { if (AttackMapping.AttackMappings[teamType][otherTeam]) { Point?targetTilePoint = null; if (BoundingBoxLocations.BoundingBoxLocationMap[otherTeam].Any()) { float minVMag = float.MaxValue; foreach (var target in BoundingBoxLocations.BoundingBoxLocationMap[otherTeam]) { if (target.pathType != pathType) { continue; } float vmag = PhysicsUtility.VectorMagnitude(target.targetLoc.X, bb.X, target.targetLoc.Y, bb.Y); if (vmag < minVMag && interiorId == target.interiorId) { minVMag = vmag; targetTilePoint = target.mapCordPoint; } } if (minVMag <= range) { return(new Tuple <Point?, float>(targetTilePoint, minVMag)); } } else { return(null); } } } return(null); }