protected override Job TryGiveJob(Pawn pawn) { if (HiveUtility.JobGivenRecentTick(pawn, "BI_Maintain")) { return(null); } Queen queen = HiveUtility.FindQueen(pawn); if (queen != null && JobGiver_InsectGather.WithinHive(pawn, pawn, true)) { List <Egg> eggs = queen.spawnedEggs; if (eggs != null && eggs.Any()) { foreach (Egg egg in eggs) { if (egg != null && pawn.CanReserve(egg)) { CompMaintainable compMaintainable = egg.TryGetComp <CompMaintainable>(); if (compMaintainable != null && compMaintainable.CurStage != MaintainableStage.Healthy) { return(new Job(DefDatabase <JobDef> .GetNamed("BI_Maintain"), egg)); } } } } } return(null); }
public static Thing FindTarget(Pawn pawn) { List <Pawn> allPawns = pawn.Map.mapPawns.AllPawnsSpawned; if (allPawns == null || !allPawns.Any()) { return(null); } if (BetterInfestationsMod.settings == null) { return(null); } List <Thing> targets = new List <Thing>(); foreach (Pawn target in allPawns) { if (!target.DestroyedOrNull() && !target.Downed) { if (target.Faction == null || (target.Faction != null && target.Faction != pawn.Faction)) { bool recentAttack = target.mindState != null && target.mindState.lastAttackedTarget == pawn && target.mindState.lastAttackTargetTick <= Find.TickManager.TicksGame && target.mindState.lastAttackTargetTick > Find.TickManager.TicksGame - ticksInAttackMode; bool withinHiveAndInVisual = JobGiver_InsectGather.WithinHive(pawn, target as Thing, false) && GenSight.LineOfSight(pawn.Position, target.Position, pawn.Map, true, null, 0, 0); if (recentAttack || withinHiveAndInVisual) { if (!BetterInfestationsMod.settings.disabledDefList.Contains(target.def.defName)) { targets.Add(target as Thing); } } } } } return(JobGiver_InsectGather.GetClosest(pawn, targets)); }
public static Thing FindTarget(Pawn pawn) { List<Pawn> allPawns = pawn.Map.mapPawns.AllPawnsSpawned; if (allPawns == null || !allPawns.Any()) { return null; } if (BetterInfestationsMod.settings == null) { return null; } List<Thing> targetList = new List<Thing>(); foreach (Pawn target in allPawns) { if (target.DestroyedOrNull()) { continue; } if (target.Faction != null && target.Faction == pawn.Faction) { continue; } if (target.Downed && JobGiver_InsectGather.WithinHive(pawn, target, true)) { continue; } if (!BetterInfestationsMod.settings.disabledDefList.Contains(target.def.defName)) { targetList.Add(target as Thing); } } return JobGiver_InsectGather.GetClosest(pawn, targetList); }
public static Thing GetAttacker(Pawn pawn, Thing target, bool attackingHive) { Pawn pawnTarget = target as Pawn; Insect enemyBug = target as Insect; Building_Turret turretTarget = target as Building_Turret; bool recentAttack = false; if (pawnTarget != null) { recentAttack = pawnTarget.mindState.lastAttackTargetTick <= Find.TickManager.TicksGame && pawnTarget.mindState.lastAttackTargetTick > Find.TickManager.TicksGame - ticksInAttackMode; } else if (turretTarget != null) { recentAttack = turretTarget.LastAttackTargetTick <= Find.TickManager.TicksGame && turretTarget.LastAttackTargetTick > Find.TickManager.TicksGame - ticksInAttackMode; } int dist = IntVec3Utility.ManhattanDistanceFlat(pawn.PositionHeld, target.PositionHeld); bool withinHiveAndInVisual = JobGiver_InsectGather.WithinHive(pawn, target, false) && GenSight.LineOfSight(pawn.Position, target.Position, pawn.Map, true, null, 0, 0); bool enemyPawnThreat = (withinHiveAndInVisual || (attackingHive && recentAttack)) && dist < maxAttackDistance; bool enemyInsectThreat = enemyBug != null && enemyBug.Faction != pawn.Faction && GenSight.LineOfSight(pawn.Position, enemyBug.Position, pawn.Map, true, null, 0, 0) && dist < 30; if (enemyPawnThreat || enemyInsectThreat) { if (pawn.CanReach(target, PathEndMode.Touch, Danger.Deadly, true, TraverseMode.PassDoors)) { return(target); } } return(null); }
public static Thing FindTarget(Pawn pawn) { List <Thing> allThings = pawn.Map.listerThings.ThingsOfDef(ThingDefOf.InsectJelly); if (allThings == null || !allThings.Any()) { return(null); } List <Thing> targetList = new List <Thing>(); foreach (Thing thing in allThings) { if (JobGiver_InsectGather.WithinHive(pawn, thing, false)) { targetList.Add(thing); } } return(JobGiver_InsectGather.GetClosest(pawn, targetList)); }
protected override Job TryGiveJob(Pawn pawn) { if (HiveUtility.JobGivenRecentTick(pawn, "BI_InsectButcher")) { return(null); } if (!ButcherCheck(pawn)) { return(null); } Thing thing = JobGiver_InsectGather.FindTarget(pawn, true); if (thing == null || !JobGiver_InsectGather.WithinHive(pawn, pawn, false)) { return(null); } Job job = new Job(DefDatabase <JobDef> .GetNamed("BI_InsectButcher"), thing) { ignoreForbidden = true, count = 1 }; return(job); }
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, "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); }
public static Thing FindTarget(Pawn pawn) { List <Thing> allThings = pawn.Map.listerThings.AllThings; if (allThings == null || !allThings.Any()) { return(null); } List <Thing> targetList = new List <Thing>(); foreach (Thing thing in allThings) { if (thing != null) { Corpse corpse = thing as Corpse; Pawn p = thing as Pawn; Queen q = thing as Queen; if (thing.def.category == ThingCategory.Item && !thing.def.IsCorpse && (thing.IngestibleNow || thing.def.defName == "WoodLog") && !JobGiver_InsectGather.WithinHive(pawn, thing, true)) { targetList.Add(thing); } else if (corpse != null && corpse.InnerPawn != null && corpse.InnerPawn.RaceProps.IsFlesh && corpse.GetRotStage() != RotStage.Dessicated && !JobGiver_InsectGather.WithinHive(pawn, thing, true)) { targetList.Add(thing); } else if (p != null && p.RaceProps.IsFlesh && (p.Faction == null || (p.Faction != null && p.Faction != pawn.Faction)) && !JobGiver_InsectGather.WithinHive(pawn, thing, true)) { targetList.Add(thing); } else if (q != null && HiveUtility.FindQueen(pawn) == q) { targetList.Add(thing); } } } return(GetClosest(pawn, targetList)); }
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); }