public static Thing FindNearbyDamagedThing(Pawn pawn, int radius) { List <Pawn> mapPawns = pawn.Map.mapPawns.AllPawnsSpawned; List <Thing> pawnList = new List <Thing>(); Pawn targetPawn = null; pawnList.Clear(); for (int i = 0; i < mapPawns.Count; i++) { targetPawn = mapPawns[i]; if (targetPawn != null && targetPawn.Spawned && !targetPawn.Dead && !targetPawn.Destroyed) { //Log.Message("evaluating targetpawn " + targetPawn.LabelShort); //Log.Message("pawn faction is " + targetPawn.Faction); //Log.Message("pawn position is " + targetPawn.Position); //Log.Message("pawn is robot: " + TM_Calc.IsRobotPawn(targetPawn)); if (targetPawn.Faction != null && targetPawn.Faction == pawn.Faction && (pawn.Position - targetPawn.Position).LengthHorizontal <= radius && TM_Calc.IsRobotPawn(targetPawn)) { float injurySeverity = 0; using (IEnumerator <BodyPartRecord> enumerator = targetPawn.health.hediffSet.GetInjuredParts().GetEnumerator()) { while (enumerator.MoveNext()) { BodyPartRecord rec = enumerator.Current; IEnumerable <Hediff_Injury> arg_BB_0 = targetPawn.health.hediffSet.GetHediffs <Hediff_Injury>(); Func <Hediff_Injury, bool> arg_BB_1; arg_BB_1 = ((Hediff_Injury injury) => injury.Part == rec); foreach (Hediff_Injury current in arg_BB_0.Where(arg_BB_1)) { bool flag5 = !current.IsPermanent(); if (flag5) { injurySeverity += current.Severity; } } } } if (injurySeverity != 0) { pawnList.Add(targetPawn as Thing); } } targetPawn = null; } } List <Thing> buildingList = TM_Calc.FindNearbyDamagedBuilding(pawn, radius); if (buildingList != null) { for (int i = 0; i < buildingList.Count; i++) { pawnList.Add(buildingList[i]); } } if (pawnList.Count > 0) { return(pawnList.RandomElement()); } else { return(null); } }