public static bool TryFindGoodHiveLoc(Pawn pawn, Pawn victim, out IntVec3 c, bool AllowHiveShip = false) { Map map = pawn.Map; c = IntVec3.Invalid; bool selected = map != null?Find.Selector.SelectedObjects.Contains(pawn) && (Prefs.DevMode) : false; ThingDef named = victim.RaceProps.Humanlike ? XenomorphDefOf.RRY_Xenomorph_Humanoid_Cocoon : XenomorphDefOf.RRY_Xenomorph_Animal_Cocoon; if (AllowHiveShip) { hiveshippresent = XenomorphUtil.HiveShipPresent(map); hiveshipReachable = !XenomorphUtil.ClosestReachableHiveShip(pawn).DestroyedOrNull(); closestreachablehiveship = XenomorphUtil.ClosestReachableHiveShip(pawn); if (c == IntVec3.Invalid && hiveshippresent && hiveshipReachable) { if (Prefs.DevMode && DebugSettings.godMode) { Log.Message(string.Format("(c == IntVec3.Invalid && hiveshippresent && hiveshipReachable)")); } c = closestreachablehiveship.Position; if (Prefs.DevMode && DebugSettings.godMode) { Log.Message(string.Format("(c == {0})", c)); } return(true); } } hivelikesPresent = XenomorphUtil.HivelikesPresent(map); hivelikesReachable = !XenomorphUtil.ClosestReachableHivelike(pawn).DestroyedOrNull(); closestReachableHivelike = XenomorphUtil.ClosestReachableHivelike(pawn); if ((hivelikesPresent && hivelikesReachable)) { List <ThingDef_HiveLike> hivedefs = DefDatabase <ThingDef_HiveLike> .AllDefsListForReading.FindAll(x => x.Faction == pawn.Faction.def); if (XenomorphUtil.TotalSpawnedHivelikeCount(map) > 0) { if (XenomorphUtil.TotalSpawnedParentHivelikeCount(map) > 0) { hiveThing = XenomorphUtil.TotalSpawnedParentHivelikeCount(map) > 1 ? XenomorphUtil.SpawnedParentHivelikes(map).RandomElement() : XenomorphUtil.ClosestReachableHivelike(pawn, XenomorphUtil.SpawnedParentHivelikes(map)); c = hiveThing.Position; if (c != IntVec3.Invalid) { return(true); } } /* * if (XenomorphUtil.TotalSpawnedChildHivelikeCount(map) > 0) * { * hiveThing = XenomorphUtil.TotalSpawnedParentHivelikeCount(map) > 1 ? XenomorphUtil.SpawnedParentHivelikes(map).RandomElement() : XenomorphUtil.ClosestReachableHivelike(pawn, XenomorphUtil.SpawnedParentHivelikes(map)); * c = hiveThing.Position; * return true; * } */ } } hiveslimepresent = XenomorphUtil.HiveSlimePresent(map); hiveslimeReachable = !XenomorphUtil.ClosestReachableHiveSlime(pawn).DestroyedOrNull(); closestreachablehiveslime = XenomorphUtil.ClosestReachableHiveSlime(pawn); if (c == IntVec3.Invalid && hiveslimepresent && hiveslimeReachable) { c = closestreachablehiveslime.Position; if (c != IntVec3.Invalid) { return(true); } } eggsPresent = XenomorphUtil.EggsPresent(map); eggsReachable = !XenomorphUtil.ClosestReachableEgg(pawn).DestroyedOrNull(); closestReachableEgg = XenomorphUtil.ClosestReachableEgg(pawn); if (c == IntVec3.Invalid && (eggsPresent && eggsReachable && XenomorphUtil.SpawnedEggsNeedHosts(map).Count > 0)) { eggThing = XenomorphUtil.SpawnedEggsNeedHosts(map).Count > 1 ? XenomorphUtil.SpawnedEggsNeedHosts(map).RandomElement() : XenomorphUtil.ClosestReachableEggNeedsHost(pawn); c = eggThing.Position; if (c != IntVec3.Invalid) { return(true); } } cocoonsPresent = XenomorphUtil.CocoonsPresent(map, named); cocoonsReachable = !XenomorphUtil.ClosestReachableCocoon(pawn, named).DestroyedOrNull(); closestReachableCocoon = XenomorphUtil.ClosestReachableCocoon(pawn, named); if (c == IntVec3.Invalid && cocoonsPresent && cocoonsReachable) { c = closestReachableCocoon.Position; if (c != IntVec3.Invalid) { return(true); } } if (c == IntVec3.Invalid) { if (!InfestationLikeCellFinder.TryFindCell(out c, map, false)) { if (!RCellFinder.TryFindBestExitSpot(pawn, out c, TraverseMode.ByPawn)) { return(false); } if (c != IntVec3.Invalid) { return(true); } } else { if (pawn.GetLord() != null && pawn.GetLord() is Lord lord) { Log.Message(string.Format("TryFindGoodHiveLoc pawn.GetLord() != null")); } if (pawn.mindState.duty.def != OGHiveLikeDefOf.RRY_DefendAndExpandHiveLike && pawn.mindState.duty.def != OGHiveLikeDefOf.RRY_DefendHiveLikeAggressively) { pawn.mindState.duty = new PawnDuty(OGHiveLikeDefOf.RRY_DefendAndExpandHiveLike, c, 40f); c = RCellFinder.RandomWanderDestFor(pawn, c, 5f, null, Danger.Some); return(true); } else { c = RCellFinder.RandomWanderDestFor(pawn, c, 5f, null, Danger.Some); return(true); } } } return(false); }