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);
        }
        // Token: 0x06006854 RID: 26708 RVA: 0x002441A0 File Offset: 0x002423A0
        public override void DrawGhost(ThingDef def, IntVec3 center, Rot4 rot, Color ghostCol, Thing thing = null)
        {
            if (thing == null)
            {
                return;
            }
            CompSpawnerHives compPlantHarmRadius = thing.TryGetComp <CompSpawnerHives>();

            if (compPlantHarmRadius == null)
            {
                return;
            }
            if (compPlantHarmRadius.Props.radiusPerDayCurve.EnumerableNullOrEmpty())
            {
                return;
            }
            float currentRadius = compPlantHarmRadius.CurrentRadius;

            if (currentRadius < 50f)
            {
                GenDraw.DrawRadiusRing(center, currentRadius);
            }
        }
        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);
        }
        // Token: 0x06005334 RID: 21300 RVA: 0x001BD1F0 File Offset: 0x001BB3F0
        public static IntVec3 FindChildHiveLocation(IntVec3 pos, Map map, ThingDef parentDef, CompProperties_SpawnerHives props, bool ignoreRoofedRequirement, bool allowUnreachable, float radius = 0f)
        {
            IntVec3 intVec = IntVec3.Invalid;
            float   Radius = radius > 0 ? radius : props.HiveSpawnRadius;

            for (int i = 0; i < 3; i++)
            {
                float minDist = props.HiveSpawnPreferredMinDist;
                bool  flag;
                if (i < 2)
                {
                    if (i == 1)
                    {
                        minDist = 0f;
                    }
                    flag = CellFinder.TryFindRandomReachableCellNear(pos, map, Radius, TraverseParms.For(TraverseMode.NoPassClosedDoors, Danger.Deadly, false), (IntVec3 c) => CompSpawnerHives.CanSpawnHiveAt(c, map, pos, parentDef, minDist, ignoreRoofedRequirement), null, out intVec, 999999);
                }
                else
                {
                    flag = (allowUnreachable && CellFinder.TryFindRandomCellNear(pos, map, (int)Radius, (IntVec3 c) => CompSpawnerHives.CanSpawnHiveAt(c, map, pos, parentDef, minDist, ignoreRoofedRequirement), out intVec, -1));
                }
                if (flag)
                {
                    intVec = CellFinder.FindNoWipeSpawnLocNear(intVec, map, parentDef, Rot4.North, 2, (IntVec3 c) => CompSpawnerHives.CanSpawnHiveAt(c, map, pos, parentDef, minDist, ignoreRoofedRequirement));
                    break;
                }
            }
            return(intVec);
        }