public static Thing GetClosest(Pawn pawn, List <Thing> list) { Thing result = null; int best = int.MaxValue; if (list != null && list.Any()) { Queen queen = HiveUtility.FindQueen(pawn); if (queen == null) { return(null); } if (list.Contains(queen as Thing) && !pawn.CanReach(queen, PathEndMode.OnCell, Danger.Deadly, true, TraverseMode.PassDoors)) { return(queen); } else { IntVec3 pos = pawn.Position; Insect insect = pawn as Insect; if (insect != null && insect.targetColonyFood) { pos = queen.colonyFoodLoc; } foreach (Thing thing in list) { int dist = IntVec3Utility.ManhattanDistanceFlat(pos, thing.Position); if (dist < best && dist <= JobGiver_InsectHunt.MaxDistance(pawn)) { if (!pawn.CanReach(thing, PathEndMode.OnCell, Danger.Deadly, true, TraverseMode.PassDoors)) { best = dist; result = thing; } } } } } return(result); }
public static Thing GetClosest(Pawn pawn, List <Thing> things) { if (things == null || !things.Any()) { return(null); } Thing result = null; int best = int.MaxValue; IntVec3 pos = pawn.Position; Insect insect = pawn as Insect; if (insect != null && insect.targetColonyFood) { Queen queen = HiveUtility.FindQueen(pawn); if (queen != null) { pos = queen.colonyFoodLoc; } } foreach (Thing thing in things) { int dist = IntVec3Utility.ManhattanDistanceFlat(pos, thing.Position); if (dist < best && dist <= JobGiver_InsectHunt.MaxDistance(pawn)) { if (pawn.CanReserve(thing) && pawn.CanReach(thing, PathEndMode.Touch, Danger.Deadly, true, TraverseMode.PassDoors)) { best = dist; result = thing; } } } return(result); }