protected override Job TryGiveJob(Pawn pawn)
        {
            if (HiveUtility.JobGivenRecentTick(pawn, "Mine"))
            {
                return(null);
            }
            if (BetterInfestationsMod.settings == null)
            {
                return(null);
            }
            if (!BetterInfestationsMod.settings.allowSapperJob)
            {
                return(null);
            }
            if (pawn.GetRoom() != null && pawn.GetRoom().Fogged)
            {
                return(null);
            }
            Queen queen = HiveUtility.FindQueen(pawn);

            if (queen == null)
            {
                return(null);
            }
            Insect insect = pawn as Insect;

            if (insect == null && queen != null && queen.spawnedInsects != null && queen.spawnedInsects.Count > 1)
            {
                return(null);
            }
            int foodAmount = HiveUtility.HiveFoodCount(queen);

            if (foodAmount >= BetterInfestationsMod.settings.foodStorage && insect != null && !insect.stealFood)
            {
                return(null);
            }
            Region region = pawn.GetRegion(RegionType.Set_Passable);

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

            if (target != null && target != queen as Thing)
            {
                Thing gatherTarget = JobGiver_InsectGather.FindTarget(pawn, false);
                if (gatherTarget != null)
                {
                    if (JobGiver_InsectGather.FindCloserTarget(pawn, target, gatherTarget))
                    {
                        return(JobGiver_InsectGather.ForceJob(pawn, gatherTarget));
                    }
                }
                if (JobGiver_InsectHunt.CanHunt(pawn) && BetterInfestationsMod.settings.allowHuntingJob)
                {
                    Thing huntTarget = JobGiver_InsectHunt.FindTarget(pawn);
                    if (huntTarget != null)
                    {
                        if (JobGiver_InsectGather.FindCloserTarget(pawn, target, huntTarget))
                        {
                            return(JobGiver_InsectHunt.ForceJob(pawn, huntTarget));
                        }
                    }
                }
                if (JobGiver_InsectHarvest.CanHarvest(pawn) && BetterInfestationsMod.settings.allowHarvestJob)
                {
                    Thing harvestTarget = JobGiver_InsectHarvest.FindTarget(pawn);
                    if (harvestTarget != null)
                    {
                        if (JobGiver_InsectGather.FindCloserTarget(pawn, target, harvestTarget))
                        {
                            return(JobGiver_InsectHarvest.ForceJob(pawn, harvestTarget));
                        }
                    }
                }
            }
            if (target == null)
            {
                return(null);
            }
            if (!pawn.CanReach(target, PathEndMode.OnCell, Danger.Deadly, false, TraverseMode.PassAllDestroyableThings))
            {
                return(null);
            }
            using (PawnPath pawnPath = pawn.Map.pathFinder.FindPath(pawn.Position, target, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.PassAllDestroyableThings, false), PathEndMode.OnCell))
            {
                List <IntVec3> cells = pawnPath.NodesReversed;
                if (cells != null && cells.Any())
                {
                    foreach (IntVec3 cell in cells)
                    {
                        Building b = cell.GetEdifice(pawn.Map);
                        if (b != null && b.def != null)
                        {
                            if (b.def.passability != Traversability.Impassable)
                            {
                                return(null);
                            }
                            if (b.def.size != IntVec2.One)
                            {
                                return(null);
                            }
                            if (b.Faction == null || (b.Faction != null && !b.Faction.IsPlayer))
                            {
                                return(null);
                            }
                        }
                    }
                }
                IntVec3 cellBeforeBlocker;
                Thing   thing = pawnPath.FirstBlockingBuilding(out cellBeforeBlocker, pawn);
                if (thing != null && pawn.CanReserve(thing) && pawn.CanReach(thing, PathEndMode.Touch, Danger.Deadly, true, TraverseMode.PassDoors))
                {
                    return(new Job(JobDefOf.Mine, thing)
                    {
                        ignoreDesignations = true,
                        expiryInterval = 6000
                    });
                }
            }
            return(null);
        }
        protected override Job TryGiveJob(Pawn pawn)
        {
            if (HiveUtility.JobGivenRecentTick(pawn, "BI_HaulToCell"))
            {
                return(null);
            }
            if (BetterInfestationsMod.settings == null)
            {
                return(null);
            }
            if (pawn.GetRoom() != null && pawn.GetRoom().Fogged)
            {
                return(null);
            }
            Queen queen = HiveUtility.FindQueen(pawn);

            if (queen == null)
            {
                return(null);
            }
            Insect insect = pawn as Insect;

            if (insect == null && queen != null && queen.spawnedInsects != null && queen.spawnedInsects.Count > 1)
            {
                return(null);
            }
            int foodAmount = HiveUtility.HiveFoodCount(queen);

            if (foodAmount >= BetterInfestationsMod.settings.foodStorage && insect != null && !insect.stealFood)
            {
                return(null);
            }
            Region region = pawn.GetRegion(RegionType.Set_Passable);

            if (region == null)
            {
                return(null);
            }
            Thing target = FindTarget(pawn, false);

            if (target != null)
            {
                if (JobGiver_InsectHunt.CanHunt(pawn) && BetterInfestationsMod.settings.allowHuntingJob)
                {
                    Thing huntTarget = JobGiver_InsectHunt.FindTarget(pawn);
                    if (huntTarget != null)
                    {
                        if (FindCloserTarget(pawn, target, huntTarget))
                        {
                            return(JobGiver_InsectHunt.ForceJob(pawn, huntTarget));
                        }
                    }
                }
                if (JobGiver_InsectHarvest.CanHarvest(pawn) && BetterInfestationsMod.settings.allowHarvestJob)
                {
                    Thing harvestTarget = JobGiver_InsectHarvest.FindTarget(pawn);
                    if (harvestTarget != null)
                    {
                        if (FindCloserTarget(pawn, target, harvestTarget))
                        {
                            return(JobGiver_InsectHarvest.ForceJob(pawn, harvestTarget));
                        }
                    }
                }
                if (Rand.Range(1, 25) == 1 && BetterInfestationsMod.settings.allowSapperJob)
                {
                    Thing sapperTarget = JobGiver_InsectSapper.FindTarget(pawn);
                    if (sapperTarget != null && sapperTarget != queen as Thing)
                    {
                        if (FindCloserTarget(pawn, target, sapperTarget))
                        {
                            return(JobGiver_InsectSapper.ForceJob(pawn, sapperTarget));
                        }
                    }
                }
            }
            if (target == null)
            {
                return(null);
            }
            IntVec3 cell = FindCell(pawn);

            if (cell == IntVec3.Invalid)
            {
                return(null);
            }
            return(new Job(DefDatabase <JobDef> .GetNamed("BI_HaulToCell"), target, cell)
            {
                canBash = true,
                haulOpportunisticDuplicates = false,
                haulMode = HaulMode.ToCellNonStorage,
                expiryInterval = 480,
                ignoreForbidden = true,
                count = 99999
            });
        }
Beispiel #3
0
        public void ManageHive()
        {
            if (BetterInfestationsMod.settings == null)
            {
                return;
            }
            if (!spawnedInsects.Any())
            {
                return;
            }
            int[] workerCount = new int[3];
            List <List <Pawn> > insectList = new List <List <Pawn> >();

            for (int i = 0; i < 3; i++)
            {
                insectList.Add(new List <Pawn>());
            }
            for (int i = 0; i < spawnedInsects.Count; i++)
            {
                if (HiveUtility.megascarabKindDef.Contains(spawnedInsects[i].kindDef))
                {
                    insectList[0].Add(spawnedInsects[i]);
                }
                else if (HiveUtility.spelopedeKindDef.Contains(spawnedInsects[i].kindDef))
                {
                    insectList[1].Add(spawnedInsects[i]);
                }
                else if (HiveUtility.megaspiderKindDef.Contains(spawnedInsects[i].kindDef))
                {
                    insectList[2].Add(spawnedInsects[i]);
                }
            }
            for (int i = 0; i < 3; i++)
            {
                if (!insectList[i].Any())
                {
                    continue;
                }
                workerCount[i] = (int)Math.Round(insectList[i].Count * BetterInfestationsMod.settings.hiveAggression, MidpointRounding.AwayFromZero);
                for (int j = 0; j < insectList[i].Count; j++)
                {
                    Insect insect = insectList[i][j] as Insect;
                    if (insect == null)
                    {
                        continue;
                    }
                    if (insect.worker)
                    {
                        if (workerCount[i] > 0)
                        {
                            if (colonyFoodFound && HiveUtility.TotalHiveInsectCount(this) >= BetterInfestationsMod.settings.maxInsectsHive)
                            {
                                insect.targetColonyFood = true;
                                insect.stealFood        = true;
                            }
                            workerCount[i]--;
                        }
                        else
                        {
                            insect.worker           = false;
                            insect.targetColonyFood = false;
                            insect.stealFood        = false;
                        }
                    }
                    else
                    {
                        if (workerCount[i] > 0)
                        {
                            insect.worker = true;
                            workerCount[i]--;
                        }
                    }
                }
            }
        }
Beispiel #4
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            if (HiveUtility.JobGivenRecentTick(pawn, "BI_LayEgg"))
            {
                return(null);
            }
            if (BetterInfestationsMod.settings == null)
            {
                return(null);
            }
            Queen queen = pawn as Queen;

            if (queen == null)
            {
                return(null);
            }
            if (!queen.eggReady)
            {
                return(null);
            }
            if (queen.hiveLocation == IntVec3.Invalid || HiveUtility.TotalHiveInsectCount(queen) >= BetterInfestationsMod.settings.maxInsectsHive || HiveUtility.TotalSpawnedInsectCount(queen.Map) >= BetterInfestationsMod.settings.maxInsectsMap)
            {
                return(null);
            }
            Map map = pawn.Map;
            Predicate <IntVec3> baseValidator = delegate(IntVec3 cell)
            {
                if (!cell.Standable(map) || !cell.Walkable(map) || cell.GetFirstItem(map) != null || cell.GetFirstBuilding(map) != null || cell.GetFirstPawn(map) != null || !pawn.CanReach(cell, PathEndMode.OnCell, Danger.Deadly, false, TraverseMode.NoPassClosedDoors))
                {
                    return(false);
                }
                return(true);
            };
            IntVec3 loc;

            if (CellFinder.TryFindRandomCellNear(queen.hiveLocation, map, 12, (IntVec3 cell) => baseValidator(cell) && cell.Roofed(map), out loc, -1))
            {
                return(new Job(DefDatabase <JobDef> .GetNamed("BI_LayEgg"), loc));
            }
            if (CellFinder.TryFindRandomCellNear(queen.hiveLocation, map, 12, (IntVec3 cell) => baseValidator(cell), out loc, 3))
            {
                return(new Job(DefDatabase <JobDef> .GetNamed("BI_LayEgg"), loc));
            }
            return(null);
        }