public static Thing SpawnTunnels(ThingDef hiveDef, int hiveCount, Map map, IntVec3 cell, bool spawnAnywhereIfNoGoodCell = false, bool ignoreRoofedRequirement = false, string questTag = null, Faction faction = null) { ThingDef HiveDef = hiveDef ?? RimWorld.ThingDefOf.Hive; HiveDefExtension HiveExt = HiveDef.GetModExtension <HiveDefExtension>(); ThingDef TunnelDef = HiveExt?.TunnelDef ?? RimWorld.ThingDefOf.TunnelHiveSpawner; HiveDefExtension extension = HiveDef.GetModExtension <HiveDefExtension>(); if (extension != null && extension.TunnelDef != null) { TunnelDef = extension.TunnelDef; } Thing thing = GenSpawn.Spawn(ThingMaker.MakeThing(TunnelDef), cell, map, WipeMode.FullRefund); TunnelHiveSpawner hiveSpawner = thing as TunnelHiveSpawner; if (hiveSpawner != null) { if (hiveSpawner.faction == null && faction != null) { hiveSpawner.faction = faction; } } if (hiveSpawner.SpawnedFaction != null) { // Log.Message(hiveSpawner.Faction.def.defName + ": " + hiveSpawner.faction); } QuestUtility.AddQuestTag(thing, questTag); CompSpawnerHives spawnerHives = thing.TryGetComp <CompSpawnerHives>(); if (spawnerHives?.Props.tunnelDef != null) { TunnelDef = spawnerHives.Props.tunnelDef; } for (int i = 0; i < hiveCount - 1; i++) { cell = CompSpawnerHives.FindChildHiveLocation(thing.Position, map, HiveDef, HiveDef.GetCompProperties <CompProperties_SpawnerHives>(), ignoreRoofedRequirement, allowUnreachable: true); if (cell.IsValid) { thing = GenSpawn.Spawn(ThingMaker.MakeThing(TunnelDef), cell, map, WipeMode.FullRefund); hiveSpawner = thing as TunnelHiveSpawner; if (hiveSpawner != null) { if (hiveSpawner.faction == null && faction != null) { hiveSpawner.faction = faction; } } if (hiveSpawner.SpawnedFaction != null) { // Log.Message(hiveSpawner.Faction.def.defName + ": " + hiveSpawner.faction); } QuestUtility.AddQuestTag(thing, questTag); } } return(thing); }
// Token: 0x06005333 RID: 21299 RVA: 0x001BD108 File Offset: 0x001BB308 public bool TrySpawnChildHive(bool ignoreRoofedRequirement, out Hive newHive) { if (!this.CanSpawnChildHive) { newHive = null; return(false); } HiveDefExtension ext = null; if (this.parent.def.HasModExtension <HiveDefExtension>()) { ext = this.parent.def.GetModExtension <HiveDefExtension>(); } ThingDef thingDef = Props.hiveDef ?? this.parent.def; IntVec3 loc = CompSpawnerHives.FindChildHiveLocation(this.parent.OccupiedRect().AdjacentCells.RandomElement(), this.parent.Map, thingDef, this.Props, ignoreRoofedRequirement, false, CurrentRadius); if (!loc.IsValid) { newHive = null; Log.Warning("this !loc.IsValid"); return(false); } newHive = (Hive)ThingMaker.MakeThing(thingDef, null); if (newHive.Faction != this.parent.Faction) { newHive.SetFaction(this.parent.Faction, null); } Hive hive = this.parent as Hive; if (hive != null) { if (hive.CompDormant.Awake) { newHive.CompDormant.WakeUp(); } newHive.questTags = hive.questTags; } if (newHive.Ext?.TunnelDef != null) { TunnelHiveSpawner tunnel = (TunnelHiveSpawner)ThingMaker.MakeThing(newHive.Ext.TunnelDef, null); tunnel.hive = newHive; GenSpawn.Spawn(tunnel, loc, this.parent.Map, WipeMode.FullRefund); this.CalculateNextHiveSpawnTick(); } else { GenSpawn.Spawn(newHive, loc, this.parent.Map, WipeMode.FullRefund); this.CalculateNextHiveSpawnTick(); } return(true); }
public static Thing SpawnTunnels(ThingDef hiveDef, int hiveCount, Map map, bool spawnAnywhereIfNoGoodCell = false, bool ignoreRoofedRequirement = false, string questTag = null, Faction faction = null) { ThingDef HiveDef = hiveDef ?? RimWorld.ThingDefOf.Hive; HiveDefExtension HiveExt = HiveDef.GetModExtension <HiveDefExtension>(); ThingDef TunnelDef = HiveExt?.TunnelDef ?? RimWorld.ThingDefOf.TunnelHiveSpawner; if (!InfestationCellFinder.TryFindCell(out IntVec3 cell, map, HiveExt)) { if (!spawnAnywhereIfNoGoodCell) { return(null); } if (!RCellFinder.TryFindRandomCellNearTheCenterOfTheMapWith(delegate(IntVec3 x) { if (!x.Standable(map) || x.Fogged(map)) { return(false); } bool flag = false; int num = GenRadial.NumCellsInRadius(3f); for (int j = 0; j < num; j++) { IntVec3 c = x + GenRadial.RadialPattern[j]; if (c.InBounds(map)) { RoofDef roof = c.GetRoof(map); if (roof != null && roof.isThickRoof) { flag = true; break; } } } return(flag ? true : false); }, map, out cell)) { return(null); } } HiveDefExtension extension = HiveDef.GetModExtension <HiveDefExtension>(); if (extension != null && extension.TunnelDef != null) { TunnelDef = extension.TunnelDef; } Thing thing = GenSpawn.Spawn(ThingMaker.MakeThing(TunnelDef), cell, map, WipeMode.FullRefund); TunnelHiveSpawner hiveSpawner = thing as TunnelHiveSpawner; if (hiveSpawner != null) { if (hiveSpawner.faction == null && faction != null) { hiveSpawner.faction = faction; } } if (hiveSpawner.SpawnedFaction != null) { // Log.Message(hiveSpawner.Faction.def.defName + ": " + hiveSpawner.faction); } QuestUtility.AddQuestTag(thing, questTag); for (int i = 0; i < hiveCount - 1; i++) { cell = CompSpawnerHives.FindChildHiveLocation(thing.Position, map, HiveDef, HiveDef.GetCompProperties <CompProperties_SpawnerHives>(), ignoreRoofedRequirement, allowUnreachable: true); if (cell.IsValid) { thing = GenSpawn.Spawn(ThingMaker.MakeThing(TunnelDef), cell, map, WipeMode.FullRefund); hiveSpawner = thing as TunnelHiveSpawner; if (hiveSpawner != null) { if (hiveSpawner.faction == null && faction != null) { hiveSpawner.faction = faction; } } if (hiveSpawner.SpawnedFaction != null) { // Log.Message(hiveSpawner.Faction.def.defName+": "+ hiveSpawner.faction); } QuestUtility.AddQuestTag(thing, questTag); } } return(thing); }