Exemplo n.º 1
0
        public static Egg FindEgg(Pawn pawn)
        {
            Queen queen = HiveUtility.FindQueen(pawn);

            if (queen != null)
            {
                List <Egg> eggs = queen.spawnedEggs;
                if (eggs != null && eggs.Any())
                {
                    foreach (Egg egg in eggs)
                    {
                        CompInsectSpawner comp = egg.TryGetComp <CompInsectSpawner>();
                        if (comp != null)
                        {
                            if (comp.jellyMax > comp.jellyStores)
                            {
                                if (pawn.CanReserve(egg.Position) && pawn.CanReach(egg.Position, PathEndMode.Touch, Danger.Deadly, true, TraverseMode.PassDoors))
                                {
                                    return(egg);
                                }
                            }
                        }
                    }
                }
            }
            return(null);
        }
Exemplo n.º 2
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            if (HiveUtility.JobGivenRecentTick(pawn, "BI_HaulToCell"))
            {
                return(null);
            }
            Egg egg = FindEgg(pawn);

            if (egg == null)
            {
                return(null);
            }
            Thing target = FindTarget(pawn);

            if (target == null)
            {
                return(null);
            }
            CompInsectSpawner comp = egg.TryGetComp <CompInsectSpawner>();
            int jellyCount         = comp.jellyMax - comp.jellyStores;

            return(new Job(DefDatabase <JobDef> .GetNamed("BI_HaulToCell"), target, egg.Position)
            {
                canBash = true,
                haulOpportunisticDuplicates = false,
                haulMode = HaulMode.ToCellNonStorage,
                expiryInterval = 240,
                ignoreForbidden = true,
                count = jellyCount
            });
        }
Exemplo n.º 3
0
 public override void Tick()
 {
     base.Tick();
     if (Spawned)
     {
         CompInsectSpawner comp = this.TryGetComp <CompInsectSpawner>();
         if (comp != null)
         {
             if (Find.TickManager.TicksGame >= insectSpawnTick && insectSpawnTick != 0)
             {
                 comp.SpawnBug(Faction);
             }
             if (comp.jellyStores >= comp.jellyMax && insectSpawnTick == 0)
             {
                 eggSpawnTick = Find.TickManager.TicksGame;
                 CalculateInsectSpawnTick();
             }
             else if (comp.jellyStores < comp.jellyMax)
             {
                 if (Map.thingGrid != null)
                 {
                     Thing thing = Map.thingGrid.ThingAt(Position, ThingDefOf.InsectJelly);
                     if (thing != null)
                     {
                         int jellyNeeded = comp.jellyMax - comp.jellyStores;
                         int stackCount  = thing.stackCount;
                         if (jellyNeeded >= stackCount)
                         {
                             comp.jellyStores = comp.jellyStores + stackCount;
                             thing.Destroy(DestroyMode.Vanish);
                         }
                         else if (jellyNeeded < stackCount)
                         {
                             int stackAdj = stackCount - jellyNeeded;
                             thing.stackCount = stackAdj;
                             comp.jellyStores = comp.jellyMax;
                         }
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 4
0
        private void TrySpawnHive(Map map)
        {
            IntVec3 intVec;

            if (!TryFindQueenSpawnCell(map, out intVec))
            {
                return;
            }
            possibleSpawnCells.Remove(intVec);

            Faction     faction = HiveUtility.GetRandomInsectFaction();
            PawnKindDef kindDef = HiveUtility.GetFactionKindDef(PawnKindDef.Named("BI_Queen_Brown"), faction);
            Queen       queen   = PawnGenerator.GeneratePawn(kindDef, faction) as Queen;

            queen.hiveLocation = intVec;
            GenSpawn.Spawn(queen, CellFinder.RandomClosewalkCellNear(intVec, map, 4, null), map);
            spawnedQueens.Add(queen);
            Lord lord = queen.Lord;

            if (lord == null)
            {
                lord = queen.CreateNewLord();
            }
            int count = Rand.Range(4, 5);

            for (int i = 0; i < count; i++)
            {
                kindDef = HiveUtility.GetFactionKindDef(PawnKindDef.Named("BI_Megascarab_Brown"), faction);
                Pawn pawn = PawnGenerator.GeneratePawn(kindDef, faction);
                GenSpawn.Spawn(pawn, CellFinder.RandomClosewalkCellNear(intVec, map, 4, null), map);
                queen.spawnedInsects.Add(pawn);
                lord.AddPawn(pawn);
            }
            IntVec3 c;
            int     foodAmt = 0;

            for (int i = 0; i < Rand.Range(4, 7); i++)
            {
                if (CellFinder.TryFindRandomReachableCellNear(intVec, map, 8, TraverseParms.For(TraverseMode.NoPassClosedDoors, Danger.Deadly, false), (IntVec3 x) => x.Walkable(map), (Region x) => true, out c, 999999))
                {
                    Egg egg = ThingMaker.MakeThing(HiveUtility.ThingDefOfEgg, null) as Egg;
                    egg.SetFaction(queen.Faction, null);
                    egg.eggLayer = queen;
                    GenPlace.TryPlaceThing(egg, c, map, ThingPlaceMode.Direct, out Thing t, null, null);
                    queen.spawnedEggs.Add(egg);
                    CompInsectSpawner comp = egg.TryGetComp <CompInsectSpawner>();
                    if (comp != null)
                    {
                        comp.jellyStores = Rand.Range(50, comp.jellyMax);
                    }
                    if (Rand.Range(1, 4) < 4)
                    {
                        CompSpawner comp2 = egg.TryGetComp <CompSpawner>();
                        if (comp2 != null)
                        {
                            comp2.TryDoSpawn();
                        }
                    }
                    if (foodAmt < (BetterInfestationsMod.settings.foodStorage + 100))
                    {
                        IntVec3 c2;
                        if (CellFinder.TryFindRandomReachableCellNear(intVec, map, 2, TraverseParms.For(TraverseMode.NoPassClosedDoors, Danger.Deadly, false), (IntVec3 x) => x.Walkable(map), (Region x) => true, out c2, 999999))
                        {
                            Thing thing2 = ThingMaker.MakeThing(ThingDefOf.InsectJelly, null);
                            thing2.stackCount = Rand.Range(15, 75);
                            GenPlace.TryPlaceThing(thing2, c2, map, ThingPlaceMode.Direct, out Thing food, null);
                            if (food != null)
                            {
                                food.SetForbidden(true);
                            }
                        }
                    }
                }
            }
        }