protected override bool TryExecuteWorker(IncidentParms parms) { if (BetterInfestationsMod.settings == null) { return(false); } Map map = (Map)parms.target; if (HiveUtility.TotalSpawnedInsectCount(map) >= BetterInfestationsMod.settings.maxInsectsMap) { return(false); } IntVec3 hiveLoc; if (!InfestationCellFinder.TryFindCell(out hiveLoc, map)) { return(false); } Faction faction = HiveUtility.GetRandomInsectFaction(); if (faction == null) { return(false); } Thing deepDrill = null; List <Thing> drills = new List <Thing>(); tmpDrills.Clear(); DeepDrillInfestationIncidentUtility.GetUsableDeepDrills(map, tmpDrills); if (tmpDrills != null && tmpDrills.Any()) { foreach (Thing t in tmpDrills) { if (map.reachability.CanReach(t.Position, hiveLoc, PathEndMode.OnCell, TraverseMode.PassDoors, Danger.Deadly)) { drills.Add(t); } } } if (drills == null || !drills.Any()) { return(false); } deepDrill = drills.RandomElement(); TunnelQueenSpawner tunnelQueenSpawner = (TunnelQueenSpawner)ThingMaker.MakeThing(HiveUtility.ThingDefOfTunnelQueenSpawner, null); tunnelQueenSpawner.insectsPoints = Mathf.Clamp(parms.points * Rand.Range(0.3f, 0.6f), 200f, BetterInfestationsMod.settings.maxParamPointsDeep); tunnelQueenSpawner.hiveLocation = hiveLoc; tunnelQueenSpawner.queenFaction = faction; GenSpawn.Spawn(tunnelQueenSpawner, deepDrill.Position, map, WipeMode.FullRefund); deepDrill.TryGetComp <CompCreatesInfestations>().Notify_CreatedInfestation(); if (BetterInfestationsMod.settings.showNotifications) { Find.LetterStack.ReceiveLetter("letterlabeldeepdrillinfestation".Translate(), "lettertextdeepdrillinfestation".Translate(), LetterDefOf.ThreatBig, tunnelQueenSpawner); Find.TickManager.slower.SignalForceNormalSpeedShort(); } return(true); }
private Thing SpawnTunnels(int hiveCount, Map map, IncidentParms parms) { if (BetterInfestationsMod.settings == null) { return(null); } if (HiveUtility.TotalSpawnedInsectCount(map) >= BetterInfestationsMod.settings.maxInsectsMap) { return(null); } IntVec3 loc; if (!InfestationCellFinder.TryFindCell(out loc, map)) { return(null); } Faction faction = HiveUtility.GetRandomInsectFaction(); if (faction == null) { return(null); } TunnelQueenSpawner tunnelQueenSpawner = ThingMaker.MakeThing(HiveUtility.ThingDefOfTunnelQueenSpawner, null) as TunnelQueenSpawner; tunnelQueenSpawner.queenFaction = faction; if (BetterInfestationsMod.settings.spawnAdditionalInsects) { tunnelQueenSpawner.insectsPoints = Mathf.Clamp(parms.points * Rand.Range(0.3f, 0.6f), 200f, BetterInfestationsMod.settings.maxParamPointsInf); } GenSpawn.Spawn(tunnelQueenSpawner, loc, map, WipeMode.FullRefund); for (int i = 0; i < hiveCount - 1; i++) { IntVec3 c; if (CellFinder.TryFindRandomReachableCellNear(loc, map, 12, TraverseParms.For(TraverseMode.NoPassClosedDoors, Danger.Deadly, false), (IntVec3 x) => x.Walkable(map), (Region x) => true, out c, 999999)) { if (c.IsValid) { TunnelQueenSpawner tunnelQueenSpawner2 = ThingMaker.MakeThing(HiveUtility.ThingDefOfTunnelQueenSpawner, null) as TunnelQueenSpawner; tunnelQueenSpawner2.queenFaction = faction; if (BetterInfestationsMod.settings.spawnAdditionalInsects) { tunnelQueenSpawner2.insectsPoints = Mathf.Clamp(parms.points * Rand.Range(0.3f, 0.6f), 200f, BetterInfestationsMod.settings.maxParamPointsInf); } GenSpawn.Spawn(tunnelQueenSpawner2, c, map, WipeMode.FullRefund); } } } return(tunnelQueenSpawner); }