Exemplo n.º 1
0
        public override IEnumerable <Gizmo> CompGetGizmosExtra()
        {
            if (!Prefs.DevMode)
            {
                yield break;
            }
            yield return((Gizmo) new Command_Action
            {
                defaultLabel = "DEBUG: Reproduce",
                icon = TexCommand.GatherSpotActive,
                action = delegate
                {
                    Hive hive = default(Hive);
                    ((_003CCompGetGizmosExtra_003Ec__Iterator0) /*Error near IL_005c: stateMachine*/)._0024this.TrySpawnChildHive(false, out hive);
                }
            });

            /*Error: Unable to find new state assignment for yield return*/;
        }
        private void TrySpawnHive(Map map)
        {
            IntVec3 intVec;

            if (this.TryFindHiveSpawnCell(map, out intVec))
            {
                this.possibleSpawnCells.Remove(intVec);
                Hive hive = (Hive)GenSpawn.Spawn(ThingMaker.MakeThing(ThingDefOf.Hive, null), intVec, map, WipeMode.Vanish);
                hive.SetFaction(Faction.OfInsects, null);
                hive.caveColony = true;
                (from x in hive.GetComps <CompSpawner>()
                 where x.PropsSpawner.thingToSpawn == ThingDefOf.GlowPod
                 select x).First <CompSpawner>().TryDoSpawn();
                hive.SpawnPawnsUntilPoints(Rand.Range(200f, 500f));
                hive.canSpawnPawns = false;
                hive.GetComp <CompSpawnerHives>().canSpawnHives = false;
                this.spawnedHives.Add(hive);
            }
        }
Exemplo n.º 3
0
        public static void Notify_HiveDespawned(Hive hive, Map map)
        {
            int num = GenRadial.NumCellsInRadius(2f);

            for (int i = 0; i < num; i++)
            {
                IntVec3 c = hive.Position + GenRadial.RadialPattern[i];
                if (c.InBounds(map))
                {
                    List <Thing> thingList = c.GetThingList(map);
                    for (int j = 0; j < thingList.Count; j++)
                    {
                        if (thingList[j].Faction == Faction.OfInsects && !HiveUtility.AnyHivePreventsClaiming(thingList[j]))
                        {
                            thingList[j].SetFaction(null, null);
                        }
                    }
                }
            }
        }
        public override void CompTick()
        {
            base.CompTick();
            Hive hive = this.parent as Hive;

            if (hive == null || hive.active)
            {
                if (Find.TickManager.TicksGame >= this.nextHiveSpawnTick)
                {
                    Hive t;
                    if (this.TrySpawnChildHive(false, out t))
                    {
                        Messages.Message("MessageHiveReproduced".Translate(), t, MessageTypeDefOf.NegativeEvent, true);
                    }
                    else
                    {
                        this.CalculateNextHiveSpawnTick();
                    }
                }
            }
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            Room room = pawn.GetRoom();

            for (int i = 0; (float)i < CellsInScanRadius; i++)
            {
                IntVec3 intVec = pawn.Position + GenRadial.RadialPattern[i];
                if (intVec.InBounds(pawn.Map) && intVec.GetRoom(pawn.Map) == room)
                {
                    Hive hive = (Hive)pawn.Map.thingGrid.ThingAt(intVec, ThingDefOf.Hive);
                    if (hive != null && pawn.CanReserve(hive))
                    {
                        CompMaintainable compMaintainable = hive.TryGetComp <CompMaintainable>();
                        if (compMaintainable.CurStage != 0 && (!onlyIfDamagingState || compMaintainable.CurStage == MaintainableStage.Damaging))
                        {
                            return(new Job(JobDefOf.Maintain, hive));
                        }
                    }
                }
            }
            return(null);
        }
Exemplo n.º 7
0
        public override void CompTickRare()
        {
            Hive hive = base.parent as Hive;

            if (hive != null && !hive.active)
            {
                return;
            }
            if (Find.TickManager.TicksGame >= this.nextHiveSpawnTick)
            {
                Hive hive2 = default(Hive);
                if (this.TrySpawnChildHive(false, out hive2))
                {
                    hive2.nextPawnSpawnTick = Find.TickManager.TicksGame + Rand.Range(150, 350);
                    Messages.Message("MessageHiveReproduced".Translate(), hive2, MessageTypeDefOf.NegativeEvent);
                }
                else
                {
                    this.CalculateNextHiveSpawnTick();
                }
            }
        }
Exemplo n.º 8
0
 private void TickInterval(int interval)
 {
     if (parent.Spawned)
     {
         Hive hive = parent as Hive;
         if (hive != null)
         {
             if (!hive.active)
             {
                 return;
             }
         }
         else if (parent.Position.Fogged(parent.Map))
         {
             return;
         }
         if (!PropsSpawner.requiresPower || PowerOn)
         {
             ticksUntilSpawn -= interval;
             CheckShouldSpawn();
         }
     }
 }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
0
 private void TickInterval(int interval)
 {
     if (base.parent.Spawned)
     {
         Hive hive = base.parent as Hive;
         if (hive != null)
         {
             if (!hive.active)
             {
                 return;
             }
         }
         else if (base.parent.Position.Fogged(base.parent.Map))
         {
             return;
         }
         if (this.PropsSpawner.requiresPower && !this.PowerOn)
         {
             return;
         }
         this.ticksUntilSpawn -= interval;
         this.CheckShouldSpawn();
     }
 }
        protected override Job TryGiveJob(Pawn pawn)
        {
            Room room = pawn.GetRoom(RegionType.Set_Passable);
            int  num  = 0;

            while ((float)num < JobGiver_MaintainHives.CellsInScanRadius)
            {
                IntVec3 intVec = pawn.Position + GenRadial.RadialPattern[num];
                if (intVec.InBounds(pawn.Map) && intVec.GetRoom(pawn.Map, RegionType.Set_Passable) == room)
                {
                    Hive hive = (Hive)pawn.Map.thingGrid.ThingAt(intVec, ThingDefOf.Hive);
                    if (hive != null && pawn.CanReserve(hive, 1, -1, null, false))
                    {
                        CompMaintainable compMaintainable = hive.TryGetComp <CompMaintainable>();
                        if (compMaintainable.CurStage != 0)
                        {
                            return(new Job(JobDefOf.Maintain, hive));
                        }
                    }
                }
                num++;
            }
            return(null);
        }
Exemplo n.º 12
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);
                 }
             }
         }
     }
 }
        protected override bool Satisfied(Pawn pawn)
        {
            Hive hive = pawn.mindState.duty.focus.Thing as Hive;

            return(hive != null && hive.GetComp <CompSpawnerHives>().canSpawnHives);
        }
Exemplo n.º 14
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);
                 }
             }
         }
     }
 }