private void Spawn() { Lord lord = CompSpawnerPawn.FindLordToJoin(parent, Props.lordJob, Props.shouldJoinParentLord, (Thing spawner) => spawner.TryGetComp <CompPawnSpawnOnWakeup>()?.spawnedPawns); if (lord == null) { lord = CompSpawnerPawn.CreateNewLord(parent, Props.aggressive, Props.defendRadius, Props.lordJob); } IntVec3 spawnPosition = GetSpawnPosition(); if (!spawnPosition.IsValid) { return; } List <Thing> list = GeneratePawns(); if (Props.dropInPods) { DropPodUtility.DropThingsNear(spawnPosition, parent.MapHeld, list); } List <IntVec3> occupiedCells = new List <IntVec3>(); foreach (Thing item in list) { if (!Props.dropInPods) { IntVec3 intVec = CellFinder.RandomClosewalkCellNear(spawnPosition, parent.Map, Props.pawnSpawnRadius.RandomInRange, (IntVec3 c) => !occupiedCells.Contains(c)); if (!intVec.IsValid) { intVec = CellFinder.RandomClosewalkCellNear(spawnPosition, parent.Map, Props.pawnSpawnRadius.RandomInRange); } GenSpawn.Spawn(item, intVec, parent.Map); occupiedCells.Add(intVec); } lord.AddPawn((Pawn)item); spawnedPawns.Add((Pawn)item); item.TryGetComp <CompCanBeDormant>()?.WakeUp(); } if (Props.spawnEffecter != null) { Effecter effecter = new Effecter(Props.spawnEffecter); effecter.Trigger(parent, TargetInfo.Invalid); effecter.Cleanup(); } if (Props.spawnSound != null) { Props.spawnSound.PlayOneShot(parent); } if (Props.activatedMessageKey != null) { Messages.Message(Props.activatedMessageKey.Translate(), spawnedPawns, MessageTypeDefOf.ThreatBig); } }
private static bool IsBuildingThreat(Thing b) { CompPawnSpawnOnWakeup compPawnSpawnOnWakeup = b.TryGetComp <CompPawnSpawnOnWakeup>(); if (compPawnSpawnOnWakeup != null && compPawnSpawnOnWakeup.CanSpawn) { return(true); } CompSpawnerPawn compSpawnerPawn = b.TryGetComp <CompSpawnerPawn>(); if (compSpawnerPawn != null && compSpawnerPawn.pawnsLeftToSpawn != 0) { return(true); } if (!b.def.building.IsTurret) { return(b.TryGetComp <CompCauseGameCondition>() != null); } return(true); }