Beispiel #1
0
 private static void SpawnInsectJellyInstantly(Hive hive)
 {
     foreach (CompSpawner comp in hive.GetComps <CompSpawner>())
     {
         if (comp.PropsSpawner.thingToSpawn == ThingDefOf.InsectJelly)
         {
             comp.TryDoSpawn();
             break;
         }
     }
 }
Beispiel #2
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);
            }
        }
Beispiel #4
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);
                 }
             }
         }
     }
 }
Beispiel #5
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);
                 }
             }
         }
     }
 }