protected override Job TryGiveJob(Pawn pawn)
 {
     if (HiveUtility.JobGivenRecentTick(pawn, "AttackMelee"))
     {
         return null;
     }
     if (BetterInfestationsMod.settings == null)
     {
         return null;
     }
     if (!BetterInfestationsMod.settings.allowHuntingJob)
     {
         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)
     {
         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_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 (Rand.Range(1, 25) == 1 && BetterInfestationsMod.settings.allowSapperJob)
         {
             Thing sapperTarget = JobGiver_InsectSapper.FindTarget(pawn);
             if (sapperTarget != null && sapperTarget != queen as Thing)
             {
                 if (JobGiver_InsectGather.FindCloserTarget(pawn, target, sapperTarget))
                 {
                     return JobGiver_InsectSapper.ForceJob(pawn, sapperTarget);
                 }
             }
         }
     }
     if (target == null)
     {
         return null;
     }
     return MeleeAttackJob(pawn, target);
 }
        protected override Job TryGiveJob(Pawn pawn)
        {
            if (HiveUtility.JobGivenRecentTick(pawn, "BI_InsectHarvest"))
            {
                return(null);
            }
            if (BetterInfestationsMod.settings == null)
            {
                return(null);
            }
            if (!BetterInfestationsMod.settings.allowHarvestJob)
            {
                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)
            {
                return(null);
            }
            int foodAmount = HiveUtility.HiveFoodCount(queen);

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

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

            if (target != null)
            {
                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 (Rand.Range(1, 25) == 1 && BetterInfestationsMod.settings.allowSapperJob)
                {
                    Thing sapperTarget = JobGiver_InsectSapper.FindTarget(pawn);
                    if (sapperTarget != null && sapperTarget != queen as Thing)
                    {
                        if (JobGiver_InsectGather.FindCloserTarget(pawn, target, sapperTarget))
                        {
                            return(JobGiver_InsectSapper.ForceJob(pawn, sapperTarget));
                        }
                    }
                }
            }
            if (target == null)
            {
                return(null);
            }
            Job job = new Job(DefDatabase <JobDef> .GetNamed("BI_InsectHarvest"), target)
            {
                canBash        = true,
                expiryInterval = 480,
                count          = 1
            };

            return(job);
        }
        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
            });
        }