public bool TrySpawnChildHive(bool ignoreRoofedRequirement, out Hive newHive)
        {
            bool result;

            if (!this.CanSpawnChildHive)
            {
                newHive = null;
                result  = false;
            }
            else
            {
                IntVec3 loc = CompSpawnerHives.FindChildHiveLocation(this.parent.Position, this.parent.Map, this.parent.def, this.Props, ignoreRoofedRequirement);
                if (!loc.IsValid)
                {
                    newHive = null;
                    result  = false;
                }
                else
                {
                    newHive = (Hive)GenSpawn.Spawn(this.parent.def, loc, this.parent.Map, WipeMode.FullRefund);
                    if (newHive.Faction != this.parent.Faction)
                    {
                        newHive.SetFaction(this.parent.Faction, null);
                    }
                    Hive hive = this.parent as Hive;
                    if (hive != null)
                    {
                        newHive.active = hive.active;
                    }
                    this.CalculateNextHiveSpawnTick();
                    result = true;
                }
            }
            return(result);
        }
        public bool TrySpawnChildHive(bool ignoreRoofedRequirement, out Hive newHive)
        {
            if (!this.CanSpawnChildHive)
            {
                newHive = null;
                return(false);
            }
            IntVec3 loc = CompSpawnerHives.FindChildHiveLocation(this.parent.Position, this.parent.Map, this.parent.def, this.Props, ignoreRoofedRequirement, false);

            if (!loc.IsValid)
            {
                newHive = null;
                return(false);
            }
            newHive = (Hive)ThingMaker.MakeThing(this.parent.def, null);
            if (newHive.Faction != this.parent.Faction)
            {
                newHive.SetFaction(this.parent.Faction, null);
            }
            Hive hive = this.parent as Hive;

            if (hive != null)
            {
                newHive.active = hive.active;
            }
            GenSpawn.Spawn(newHive, loc, this.parent.Map, WipeMode.FullRefund);
            this.CalculateNextHiveSpawnTick();
            return(true);
        }
Exemple #3
0
 private void TrySpawnHive(Map map)
 {
     if (TryFindHiveSpawnCell(map, out IntVec3 spawnCell))
     {
         possibleSpawnCells.Remove(spawnCell);
         Hive hive = (Hive)GenSpawn.Spawn(ThingMaker.MakeThing(ThingDefOf.Hive), spawnCell, map);
         hive.SetFaction(Faction.OfInsects);
         hive.caveColony = true;
         (from x in hive.GetComps <CompSpawner>()
          where x.PropsSpawner.thingToSpawn == ThingDefOf.GlowPod
          select x).First().TryDoSpawn();
         hive.SpawnPawnsUntilPoints(Rand.Range(200f, 500f));
         hive.canSpawnPawns = false;
         hive.GetComp <CompSpawnerHives>().canSpawnHives = false;
         spawnedHives.Add(hive);
     }
 }
        private void TrySpawnHive(Map map)
        {
            IntVec3 intVec = default(IntVec3);

            if (this.TryFindHiveSpawnCell(map, out intVec))
            {
                this.possibleSpawnCells.Remove(intVec);
                Hive hive = (Hive)GenSpawn.Spawn(ThingMaker.MakeThing(ThingDefOf.Hive, null), intVec, map);
                hive.SetFaction(Faction.OfInsects, null);
                (from x in hive.GetComps <CompSpawner>()
                 where x.PropsSpawner.thingToSpawn == ThingDefOf.GlowPod
                 select x).First().TryDoSpawn();
                hive.SpawnPawnsUntilPoints(Rand.Range(200f, 500f));
                hive.canSpawnPawns = false;
                hive.GetComp <CompSpawnerHives>().canSpawnHives = false;
                this.spawnedHives.Add(hive);
            }
        }
Exemple #5
0
        public bool TrySpawnChildHive(bool ignoreRoofedRequirement, out Hive newHive)
        {
            if (!this.CanSpawnChildHive)
            {
                newHive = null;
                return(false);
            }
            IntVec3 invalid = IntVec3.Invalid;
            int     num     = 0;

            while (num < 3)
            {
                float minDist = this.Props.HiveSpawnPreferredMinDist;
                switch (num)
                {
                case 1:
                    minDist = 0f;
                    break;

                case 2:
                    newHive = null;
                    return(false);
                }
                if (!CellFinder.TryFindRandomReachableCellNear(base.parent.Position, base.parent.Map, this.Props.HiveSpawnRadius, TraverseParms.For(TraverseMode.NoPassClosedDoors, Danger.Deadly, false), (Predicate <IntVec3>)((IntVec3 c) => this.CanSpawnHiveAt(c, minDist, ignoreRoofedRequirement)), (Predicate <Region>)null, out invalid, 999999))
                {
                    num++;
                    continue;
                }
                break;
            }
            newHive = (Hive)GenSpawn.Spawn(base.parent.def, invalid, base.parent.Map);
            if (newHive.Faction != base.parent.Faction)
            {
                newHive.SetFaction(base.parent.Faction, null);
            }
            Hive hive = base.parent as Hive;

            if (hive != null)
            {
                newHive.active = hive.active;
            }
            this.CalculateNextHiveSpawnTick();
            return(true);
        }
Exemple #6
0
        public bool TrySpawnChildHive(bool ignoreRoofedRequirement, out Hive newHive)
        {
            if (!this.CanSpawnChildHive)
            {
                newHive = null;
                return(false);
            }
            IntVec3 invalid = IntVec3.Invalid;

            for (int i = 0; i < 3; i++)
            {
                float minDist = this.Props.HiveSpawnPreferredMinDist;
                if (i == 1)
                {
                    minDist = 0f;
                }
                else if (i == 2)
                {
                    newHive = null;
                    return(false);
                }
                if (CellFinder.TryFindRandomReachableCellNear(this.parent.Position, this.parent.Map, this.Props.HiveSpawnRadius, TraverseParms.For(TraverseMode.NoPassClosedDoors, Danger.Deadly, false), (IntVec3 c) => this.CanSpawnHiveAt(c, minDist, ignoreRoofedRequirement), null, out invalid, 999999))
                {
                    break;
                }
            }
            newHive = (Hive)GenSpawn.Spawn(this.parent.def, invalid, this.parent.Map);
            if (newHive.Faction != this.parent.Faction)
            {
                newHive.SetFaction(this.parent.Faction, null);
            }
            Hive hive = this.parent as Hive;

            if (hive != null)
            {
                newHive.active = hive.active;
            }
            this.CalculateNextHiveSpawnTick();
            return(true);
        }
Exemple #7
0
        private Hive SpawnHiveCluster(int hiveCount, Map map)
        {
            IntVec3 loc = default(IntVec3);

            if (!InfestationCellFinder.TryFindCell(out loc, map))
            {
                return(null);
            }
            Hive hive = (Hive)GenSpawn.Spawn(ThingMaker.MakeThing(ThingDefOf.Hive, null), loc, map);

            hive.SetFaction(Faction.OfInsects, null);
            IncidentWorker_Infestation.SpawnInsectJellyInstantly(hive);
            for (int i = 0; i < hiveCount - 1; i++)
            {
                Hive hive2 = default(Hive);
                if (hive.GetComp <CompSpawnerHives>().TrySpawnChildHive(false, out hive2))
                {
                    IncidentWorker_Infestation.SpawnInsectJellyInstantly(hive2);
                    hive = hive2;
                }
            }
            return(hive);
        }
Exemple #8
0
 public override void Tick()
 {
     if (base.Spawned)
     {
         sustainer.Maintain();
         Vector3 vector = base.Position.ToVector3Shifted();
         if (Rand.MTBEventOccurs(FilthSpawnMTB, 1f, 1.TicksToSeconds()) && CellFinder.TryFindRandomReachableCellNear(base.Position, base.Map, FilthSpawnRadius, TraverseParms.For(TraverseMode.NoPassClosedDoors), null, null, out IntVec3 result))
         {
             FilthMaker.MakeFilth(result, base.Map, filthTypes.RandomElement());
         }
         if (Rand.MTBEventOccurs(DustMoteSpawnMTB, 1f, 1.TicksToSeconds()))
         {
             Vector3 loc = new Vector3(vector.x, 0f, vector.z);
             loc.y = AltitudeLayer.MoteOverhead.AltitudeFor();
             MoteMaker.ThrowDustPuffThick(loc, base.Map, Rand.Range(1.5f, 3f), new Color(1f, 1f, 1f, 2.5f));
         }
         if (secondarySpawnTick <= Find.TickManager.TicksGame)
         {
             sustainer.End();
             Map     map      = base.Map;
             IntVec3 position = base.Position;
             Destroy();
             if (spawnHive)
             {
                 Hive hive = (Hive)GenSpawn.Spawn(ThingMaker.MakeThing(ThingDefOf.Hive), position, map);
                 hive.SetFaction(Faction.OfInsects);
                 foreach (CompSpawner comp in hive.GetComps <CompSpawner>())
                 {
                     if (comp.PropsSpawner.thingToSpawn == ThingDefOf.InsectJelly)
                     {
                         comp.TryDoSpawn();
                         break;
                     }
                 }
             }
             if (insectsPoints > 0f)
             {
                 insectsPoints = Mathf.Max(insectsPoints, Hive.spawnablePawnKinds.Min((PawnKindDef x) => x.combatPower));
                 float       pointsLeft = insectsPoints;
                 List <Pawn> list       = new List <Pawn>();
                 int         num        = 0;
                 while (pointsLeft > 0f)
                 {
                     num++;
                     if (num > 1000)
                     {
                         Log.Error("Too many iterations.");
                         break;
                     }
                     IEnumerable <PawnKindDef> source = from x in Hive.spawnablePawnKinds
                                                        where x.combatPower <= pointsLeft
                                                        select x;
                     if (!source.TryRandomElement(out PawnKindDef result2))
                     {
                         break;
                     }
                     Pawn pawn = PawnGenerator.GeneratePawn(result2, Faction.OfInsects);
                     GenSpawn.Spawn(pawn, CellFinder.RandomClosewalkCellNear(position, map, 2), map);
                     pawn.mindState.spawnedByInfestationThingComp = spawnedByInfestationThingComp;
                     list.Add(pawn);
                     pointsLeft -= result2.combatPower;
                 }
                 if (list.Any())
                 {
                     LordMaker.MakeNewLord(Faction.OfInsects, new LordJob_AssaultColony(Faction.OfInsects, canKidnap: true, canTimeoutOrFlee: false), map, list);
                 }
             }
         }
     }
 }
Exemple #9
0
 public override void Tick()
 {
     if (base.Spawned)
     {
         this.sustainer.Maintain();
         Vector3 vector = base.Position.ToVector3Shifted();
         IntVec3 c;
         if (Rand.MTBEventOccurs(TunnelHiveSpawner.FilthSpawnMTB, 1f, 1.TicksToSeconds()) && CellFinder.TryFindRandomReachableCellNear(base.Position, base.Map, TunnelHiveSpawner.FilthSpawnRadius, TraverseParms.For(TraverseMode.NoPassClosedDoors, Danger.Deadly, false), null, null, out c, 999999))
         {
             FilthMaker.MakeFilth(c, base.Map, TunnelHiveSpawner.filthTypes.RandomElement <ThingDef>(), 1);
         }
         if (Rand.MTBEventOccurs(TunnelHiveSpawner.DustMoteSpawnMTB, 1f, 1.TicksToSeconds()))
         {
             MoteMaker.ThrowDustPuffThick(new Vector3(vector.x, 0f, vector.z)
             {
                 y = AltitudeLayer.MoteOverhead.AltitudeFor()
             }, base.Map, Rand.Range(1.5f, 3f), new Color(1f, 1f, 1f, 2.5f));
         }
         if (this.secondarySpawnTick <= Find.TickManager.TicksGame)
         {
             this.sustainer.End();
             Map     map      = base.Map;
             IntVec3 position = base.Position;
             this.Destroy(DestroyMode.Vanish);
             if (this.spawnHive)
             {
                 Hive hive = (Hive)GenSpawn.Spawn(ThingMaker.MakeThing(ThingDefOf.Hive, null), position, map, WipeMode.Vanish);
                 hive.SetFaction(Faction.OfInsects, null);
                 foreach (CompSpawner compSpawner in hive.GetComps <CompSpawner>())
                 {
                     if (compSpawner.PropsSpawner.thingToSpawn == ThingDefOf.InsectJelly)
                     {
                         compSpawner.TryDoSpawn();
                         break;
                     }
                 }
             }
             if (this.insectsPoints > 0f)
             {
                 this.insectsPoints = Mathf.Max(this.insectsPoints, Hive.spawnablePawnKinds.Min((PawnKindDef x) => x.combatPower));
                 float       pointsLeft = this.insectsPoints;
                 List <Pawn> list       = new List <Pawn>();
                 int         num        = 0;
                 while (pointsLeft > 0f)
                 {
                     num++;
                     if (num > 1000)
                     {
                         Log.Error("Too many iterations.", false);
                         break;
                     }
                     IEnumerable <PawnKindDef> source = from x in Hive.spawnablePawnKinds
                                                        where x.combatPower <= pointsLeft
                                                        select x;
                     PawnKindDef pawnKindDef;
                     if (!source.TryRandomElement(out pawnKindDef))
                     {
                         break;
                     }
                     Pawn pawn = PawnGenerator.GeneratePawn(pawnKindDef, Faction.OfInsects);
                     GenSpawn.Spawn(pawn, CellFinder.RandomClosewalkCellNear(position, map, 2, null), map, WipeMode.Vanish);
                     pawn.mindState.spawnedByInfestationThingComp = this.spawnedByInfestationThingComp;
                     list.Add(pawn);
                     pointsLeft -= pawnKindDef.combatPower;
                 }
                 if (list.Any <Pawn>())
                 {
                     LordMaker.MakeNewLord(Faction.OfInsects, new LordJob_AssaultColony(Faction.OfInsects, true, false, false, false, true), map, list);
                 }
             }
         }
     }
 }