public static AIPawn CreateAIPawn(string pawnDefName, IntVec3 position, Map map, Faction faction, Gender gender) { AIPawn pawn = AIPawnGenerator.GenerateAIPawn(pawnDefName, faction, map, gender); //// Old: //IntVec3 spawnPos = position; // GenCellFinder.RandomStandableClosewalkCellNear(position, 1); // New: Find empty position in adjacent cell IntVec3 spawnPos = IntVec3.Invalid; if (map.thingGrid.ThingAt(position, ThingCategory.Building) != null || map.thingGrid.ThingAt(position, ThingCategory.Pawn) != null) { foreach (IntVec3 c in GenAdjFast.AdjacentCells8Way(position)) { if (map.thingGrid.ThingAt(c, ThingCategory.Building) == null && map.thingGrid.ThingAt(c, ThingCategory.Pawn) == null) { spawnPos = c; break; } } } if (spawnPos == IntVec3.Invalid) { spawnPos = position; } AIPawn newPawn = (AIPawn)Spawn(pawn, spawnPos, map); // Notify the Storyteller Find.StoryWatcher.watcherPopAdaptation.Notify_PawnEvent(newPawn, PopAdaptationEvent.GainedColonist); return(newPawn); }
public static AIPawn CreateAIPawn(string pawnDefName, IntVec3 position, Map map, Faction faction, Gender gender) { AIPawn pawn = AIPawnGenerator.GenerateAIPawn(pawnDefName, faction, map, gender); //// Old: //IntVec3 spawnPos = position; // GenCellFinder.RandomStandableClosewalkCellNear(position, 1); // New: Find empty position in adjacent cell IntVec3 spawnPos = IntVec3.Invalid; if (map.thingGrid.ThingAt(position, ThingCategory.Building) != null || map.thingGrid.ThingAt(position, ThingCategory.Pawn) != null) { foreach (IntVec3 c in GenAdjFast.AdjacentCells8Way(position)) { if (map.thingGrid.ThingAt(c, ThingCategory.Building) == null && map.thingGrid.ThingAt(c, ThingCategory.Pawn) == null) { spawnPos = c; break; } } } if (spawnPos == IntVec3.Invalid) { spawnPos = position; } return((AIPawn)Spawn(pawn, spawnPos, map)); }