protected override bool CanFireNowSub(IncidentParms parms) { if (!base.CanFireNowSub(parms)) { return(false); } if (BetterInfestationsMod.settings == null) { return(false); } Map map = (Map)parms.target; if (HiveUtility.TotalSpawnedInsectCount(map) >= BetterInfestationsMod.settings.maxInsectsMap) { return(false); } IntVec3 loc; if (!InfestationCellFinder.TryFindCell(out loc, map)) { return(false); } Faction faction = HiveUtility.GetRandomInsectFaction(); if (faction == null) { return(false); } return(true); }
public override void SpawnSetup(Map map, bool respawningAfterLoad) { base.SpawnSetup(map, respawningAfterLoad); if (!respawningAfterLoad) { CalculateNextEggSpawnTick(); gender = Gender.Female; if (Faction == null) { SetFaction(HiveUtility.GetInsectFaction(this)); } if (!hiveLocation.IsValid) { hiveLocation = Position; IntVec3 loc; if (InfestationCellFinder.TryFindCell(out loc, map)) { hiveLocation = loc; } } spawnedInsects.Add(this); Lord lord = Lord; if (lord == null) { lord = CreateNewLord(); } lord.AddPawn(this); } }
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); }
protected override bool CanFireNowSub(IncidentParms parms) { if (!base.CanFireNowSub(parms)) { return(false); } 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); } 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)) { return(true); } } } return(false); }
public void SpawnBug(Faction faction) { Egg egg = parent as Egg; Queen queen = egg.eggLayer; PawnKindDef kindDef = null; int random = Rand.Range(1, 50); int random2 = Rand.Range(1, 3); switch (random) { case int n when n <= 26: kindDef = HiveUtility.GetFactionKindDef(PawnKindDef.Named("BI_Megascarab_Brown"), faction); break; case int n when n >= 27 && n <= 40: kindDef = HiveUtility.GetFactionKindDef(PawnKindDef.Named("BI_Spelopede_Brown"), faction); break; case int n when n >= 41 && n <= 48: kindDef = HiveUtility.GetFactionKindDef(PawnKindDef.Named("BI_Megaspider_Brown"), faction); break; case int n when n >= 49 && n <= 50: kindDef = HiveUtility.GetFactionKindDef(PawnKindDef.Named("BI_Queen_Brown"), faction); break; } if (kindDef != null) { PawnGenerationRequest request = new PawnGenerationRequest(kindDef, faction, PawnGenerationContext.NonPlayer, -1, true, true, false, false, false, false, 1f, false, false, true, false, false, false, false, null, null, null, null, null, null, null, null); Pawn pawn = PawnGenerator.GeneratePawn(request); if (kindDef.defName.Contains("BI_Queen")) { IntVec3 loc; if (InfestationCellFinder.TryFindCell(out loc, egg.Map)) { Queen queen2 = pawn as Queen; if (queen2 != null) { queen2.hiveLocation = loc; } } } GenSpawn.Spawn(pawn, CellFinder.RandomClosewalkCellNear(egg.Position, egg.Map, 2, null), egg.Map); Lord lord = null; if (queen != null && !queen.Dead) { lord = queen.Lord; queen.spawnedEggs.Remove(egg); if (!kindDef.defName.Contains("BI_Queen")) { queen.spawnedInsects.Add(pawn); } } if (queen == null || queen.Dead || lord == null) { lord = CreateNewLord(faction); } if (!kindDef.defName.Contains("BI_Queen")) { lord.AddPawn(pawn); } FilthMaker.MakeFilth(egg.Position, egg.Map, ThingDefOf.Filth_Slime, 12); SoundDefOf.Hive_Spawn.PlayOneShot(egg); egg.Destroy(DestroyMode.Vanish); } }