public void SpawnEgg() { Queen queen = pawn as Queen; if (queen != null) { Egg egg = (Egg)ThingMaker.MakeThing(HiveUtility.ThingDefOfEgg, null); egg.SetFaction(pawn.Faction, null); egg.eggLayer = queen; GenSpawn.Spawn(egg, pawn.Position, Map, WipeMode.Vanish); SoundDef.Named("BI_Laying_Egg").PlayOneShot(egg); queen.eggReady = false; queen.spawnedEggs.Add(egg); } }
public override IEnumerable <Gizmo> CompGetGizmosExtra() { if (Prefs.DevMode) { yield return(new Command_Action { defaultLabel = "egg_debug_desc".Translate(), icon = TexCommand.ReleaseAnimals, action = delegate { Egg egg = parent as Egg; if (egg != null) { SpawnBug(egg.Faction); } } }); } }
public override string CompInspectStringExtra() { string txt = null; Egg egg = parent as Egg; if (egg != null) { if (jellyStores < jellyMax) { txt = "egg_foodneeded_desc".Translate() + jellyStores + "/" + jellyMax; } else { float curTick = Find.TickManager.TicksGame - egg.eggSpawnTick; float endTick = egg.insectSpawnTick - egg.eggSpawnTick; int perc = (int)(curTick / endTick * 100f); txt = "egg_foodneeded_desc".Translate() + jellyStores + "/" + jellyMax + "\r\n" + "egg_spawning_desc".Translate() + perc + "%"; } } return(txt); }
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); } }
public static Thing FindTarget(Pawn pawn) { List <Thing> allThings = pawn.Map.listerThings.AllThings; if (allThings == null || !allThings.Any()) { return(null); } if (BetterInfestationsMod.settings == null) { return(null); } List <Thing> targets = new List <Thing>(); foreach (Thing target in allThings) { Pawn pawnTarget = target as Pawn; Building_Turret turretTarget = target as Building_Turret; Egg eggTarget = target as Egg; if (!pawnTarget.DestroyedOrNull() && !pawnTarget.Downed) { if ((pawnTarget.Faction != null && pawnTarget.Faction != pawn.Faction) || pawnTarget.Faction == null) { if (!BetterInfestationsMod.settings.disabledDefList.Contains(pawnTarget.def.defName)) { targets.Add(target); } } } else if (!turretTarget.DestroyedOrNull()) { if ((turretTarget.Faction != null && turretTarget.Faction != pawn.Faction) || turretTarget.Faction == null) { targets.Add(target); } } else if (!eggTarget.DestroyedOrNull()) { if ((eggTarget.Faction != null && eggTarget.Faction != pawn.Faction) || eggTarget.Faction == null) { targets.Add(target); } } } Thing result = null; if (pawn.mindState.enemyTarget == null) { if (targets.Any()) { foreach (Thing target in targets) { Pawn pawnTarget = target as Pawn; Building_Turret turretTarget = target as Building_Turret; Egg eggTarget = target as Egg; bool attackingHive; if (pawnTarget != null) { attackingHive = pawnTarget.mindState.lastAttackedTarget == pawn; result = GetAttacker(pawn, target, attackingHive); } else if (turretTarget != null) { attackingHive = turretTarget.LastAttackedTarget == pawn; result = GetAttacker(pawn, target, attackingHive); } else if (eggTarget != null && GenSight.LineOfSight(pawn.Position, eggTarget.Position, pawn.Map, true, null, 0, 0) && IntVec3Utility.ManhattanDistanceFlat(pawn.PositionHeld, eggTarget.PositionHeld) < 30) { result = target; } if (result != null) { break; } } } } else { Thing target = pawn.mindState.enemyTarget; Pawn pawnTarget = target as Pawn; Building_Turret turretTarget = target as Building_Turret; Egg eggTarget = target as Egg; Thing attackedTarget = null; if (pawnTarget != null && pawnTarget.mindState != null) { attackedTarget = pawnTarget.mindState.lastAttackedTarget.Thing; } else if (turretTarget != null) { attackedTarget = turretTarget.LastAttackedTarget.Thing; } else if (eggTarget != null && GenSight.LineOfSight(pawn.Position, eggTarget.Position, pawn.Map, true, null, 0, 0) && IntVec3Utility.ManhattanDistanceFlat(pawn.PositionHeld, eggTarget.PositionHeld) < 30) { result = target; } if (attackedTarget != null) { bool attackingHive = attackedTarget.Faction != null && attackedTarget.Faction == pawn.Faction; result = GetAttacker(pawn, target, attackingHive); } if (result == null) { pawn.mindState.enemyTarget = null; } } if (result != null) { if (result.def != HiveUtility.ThingDefOfEgg) { pawn.mindState.enemyTarget = result; } List <Pawn> insectPawns = new List <Pawn>(); foreach (Thing thing in allThings) { Pawn insect = thing as Pawn; if (!insect.DestroyedOrNull() && !insect.Downed && insect.Faction != null && insect.Faction == pawn.Faction && insect != pawn && insect.mindState.enemyTarget == null) { insectPawns.Add(insect); } } foreach (Pawn insect in insectPawns) { int dist = IntVec3Utility.ManhattanDistanceFlat(insect.PositionHeld, result.PositionHeld); if (insect.CanReach(result, PathEndMode.Touch, Danger.Deadly, true, TraverseMode.PassDoors) && dist < maxAttackDistance) { if (result.def != HiveUtility.ThingDefOfEgg) { insect.mindState.enemyTarget = result; } } } } return(result); }
private void TrySpawnHive(Map map) { IntVec3 intVec; if (!TryFindQueenSpawnCell(map, out intVec)) { return; } possibleSpawnCells.Remove(intVec); Faction faction = HiveUtility.GetRandomInsectFaction(); PawnKindDef kindDef = HiveUtility.GetFactionKindDef(PawnKindDef.Named("BI_Queen_Brown"), faction); Queen queen = PawnGenerator.GeneratePawn(kindDef, faction) as Queen; queen.hiveLocation = intVec; GenSpawn.Spawn(queen, CellFinder.RandomClosewalkCellNear(intVec, map, 4, null), map); spawnedQueens.Add(queen); Lord lord = queen.Lord; if (lord == null) { lord = queen.CreateNewLord(); } int count = Rand.Range(4, 5); for (int i = 0; i < count; i++) { kindDef = HiveUtility.GetFactionKindDef(PawnKindDef.Named("BI_Megascarab_Brown"), faction); Pawn pawn = PawnGenerator.GeneratePawn(kindDef, faction); GenSpawn.Spawn(pawn, CellFinder.RandomClosewalkCellNear(intVec, map, 4, null), map); queen.spawnedInsects.Add(pawn); lord.AddPawn(pawn); } IntVec3 c; int foodAmt = 0; for (int i = 0; i < Rand.Range(4, 7); i++) { if (CellFinder.TryFindRandomReachableCellNear(intVec, map, 8, TraverseParms.For(TraverseMode.NoPassClosedDoors, Danger.Deadly, false), (IntVec3 x) => x.Walkable(map), (Region x) => true, out c, 999999)) { Egg egg = ThingMaker.MakeThing(HiveUtility.ThingDefOfEgg, null) as Egg; egg.SetFaction(queen.Faction, null); egg.eggLayer = queen; GenPlace.TryPlaceThing(egg, c, map, ThingPlaceMode.Direct, out Thing t, null, null); queen.spawnedEggs.Add(egg); CompInsectSpawner comp = egg.TryGetComp <CompInsectSpawner>(); if (comp != null) { comp.jellyStores = Rand.Range(50, comp.jellyMax); } if (Rand.Range(1, 4) < 4) { CompSpawner comp2 = egg.TryGetComp <CompSpawner>(); if (comp2 != null) { comp2.TryDoSpawn(); } } if (foodAmt < (BetterInfestationsMod.settings.foodStorage + 100)) { IntVec3 c2; if (CellFinder.TryFindRandomReachableCellNear(intVec, map, 2, TraverseParms.For(TraverseMode.NoPassClosedDoors, Danger.Deadly, false), (IntVec3 x) => x.Walkable(map), (Region x) => true, out c2, 999999)) { Thing thing2 = ThingMaker.MakeThing(ThingDefOf.InsectJelly, null); thing2.stackCount = Rand.Range(15, 75); GenPlace.TryPlaceThing(thing2, c2, map, ThingPlaceMode.Direct, out Thing food, null); if (food != null) { food.SetForbidden(true); } } } } } }