protected override ThoughtState CurrentStateInternal(Pawn p) { if (p.story.traits.allTraits.Find(x => x.def is TraitDef_ReligionTrait) == null || !p.IsColonist) { return(ThoughtState.Inactive); } var pawnReligion = p.story.traits.allTraits.Find(x => x.def is TraitDef_ReligionTrait).def; var altars = p.Map.listerThings.ThingsMatching(ThingRequest.ForDef(ReligionDefOf.Altar)); if (altars.NullOrEmpty()) { return(true); } foreach (var thing in altars) { var a = (Building_Altar)thing; if (a.religion.Contains(pawnReligion) && a.relic != null /* && a.lectern != null*/) { return(ThoughtState.Inactive); } } return(true); }
protected override Job TryGiveJob(Pawn pawn) { // Log.Message("Scratching the itch."); // try finding scratching poles. Thing target = GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForDef(ThingDef.Named("Fluffy_ScratchingPole")), PathEndMode.Touch, TraverseParms.For(pawn), 20); if (target != null) { // Log.Message("Scratching pole found."); return(new Job(DefDatabase <JobDef> .GetNamed("Fluffy_Scratch", true), target)); } // potential other targets. IEnumerable <Building> targets = from t in pawn.Map.listerBuildings.AllBuildingsColonistOfClass <Building>() where t.def.useHitPoints && pawn.CanReach(t, PathEndMode.Touch, Danger.Some) select t; if (!targets.Any()) { return(null); } target = targets.RandomElement(); return(new Job(DefDatabase <JobDef> .GetNamed("Fluffy_Scratch", true), target)); }
private static Thing FindNextFuelItem(Pawn pawn, Thing refuelable) { List <IngredientAndCostClass> ingredients = refuelable.def.GetModExtension <NPDModExtension>().ingredientList; int i = 0; bool found = false; for (i = 0; i < refuelable.TryGetComp <CompRefillable>().items.Count; i++) { if (refuelable.TryGetComp <CompRefillable>().items[i] < refuelable.def.GetCompProperties <CompProperties_Refillable>().itemCapacity) { found = true; break; } } ThingDef item = null; int quantity = 0; if (found) { item = ingredients[i].thingDef; quantity = refuelable.TryGetComp <CompRefillable>().CountToRefill(i); } Predicate <Thing> validator = (Thing x) => !x.IsForbidden(pawn) && pawn.CanReserve(x, 1, -1, null, false) && x.def == item; IntVec3 position = pawn.Position; Map map = pawn.Map; ThingRequest itemThingRequest = ThingRequest.ForDef(item); PathEndMode peMode = PathEndMode.ClosestTouch; TraverseParms traverseParams = TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false); return(GenClosest.ClosestThingReachable(position, map, itemThingRequest, peMode, traverseParams, 9999f, validator, null, 0, -1, false, RegionType.Set_Passable, false)); }
// Token: 0x0600001E RID: 30 RVA: 0x00002C2C File Offset: 0x00001C2C private Thing Findmech_oil(Pawn pawn, Building_sd_luciprod_distillery barrel) { Predicate <Thing> predicate = (Thing x) => !x.IsForbidden(pawn) && pawn.CanReserve(x, 1, -1, null, false); Predicate <Thing> validator = predicate; return(GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForDef(ThingDefOf.sd_luciprod_mechanite_oil), PathEndMode.ClosestTouch, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), 9999f, validator, null, 0, -1, false, RegionType.Set_Passable, false)); }
public Thing ClosestFuelAvailable(Pawn pawn) { Predicate <Thing> validator = (Thing x) => !x.IsForbidden(pawn) && pawn.CanReserve(x, 1, -1, null, false) && x.def == Props.fuelType; return(GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForDef(Props.fuelType), PathEndMode.ClosestTouch, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), 9999f, validator, null, 0, -1, false, RegionType.Set_Passable, false)); }
protected override Job TryGiveJob(Pawn pawn) { //Log.Message("JobGiver_RunningWheelPrisoner.TryGiveJob"); Map map = pawn.Map; //죄수일때만 if (pawn.IsPrisoner) { if (pawn.Map.listerThings.ThingsOfDef(RK_ThingDefOf.RK_HamsterWheelGenerator).Any()) { foreach (Building wheel in pawn.Map.listerThings.ThingsMatching(ThingRequest.ForDef(RK_ThingDefOf.RK_HamsterWheelGenerator))) { if (wheel.Position.IsInPrisonCell(map)) { if (pawn.CanReserve(wheel) && wheel.GetComp <CompPowerPlantHamsterWheel>().user == null) { return(new Job(RK_JobDefOf.RK_Job_HamsterWheel, wheel)); } } } } } return(null); }
public override void CompTickRare() { if (GenClosest.ClosestThingReachable(parent.Position, parent.Map, ThingRequest.ForDef(Props.target), PathEndMode.OnCell, TraverseParms.For(TraverseMode.NoPassClosedDoors), Props.radius) != null) { parent.GetComp <CompExplosive>().StartWick(); } }
private ThingWithComps GetNearestTrainingWeaponOfType(ThingDef weaponType) { ThingRequest request = ThingRequest.ForDef(weaponType); ThingWithComps nearestTrainingWeapon = (ThingWithComps)GenClosest.RegionwiseBFSWorker(this.TargetA.Thing.Position, pawn.Map, request, PathEndMode.OnCell, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), (Thing x) => pawn.CanReserve(x, 1, -1, null, false), null, 0, 12, 50f, out int regionsSearched, RegionType.Set_Passable, true); return(nearestTrainingWeapon); }
public ThingWithComps GetNearestTrainingWeaponOfType(ThingDef weaponType) { ThingRequest req = ThingRequest.ForDef(weaponType); int regionsSeen; return((ThingWithComps)GenClosest.RegionwiseBFSWorker(base.TargetA.Thing.Position, pawn.Map, req, PathEndMode.OnCell, TraverseParms.For(pawn), (Thing x) => pawn.CanReserve(x), null, 0, 12, 50f, out regionsSeen, RegionType.Set_Passable, ignoreEntirelyForbiddenRegions: true)); }
private Building_CryptosleepCasket FindCasket(Pawn p, Corpse corpse) { IEnumerable <ThingDef> enumerable = from def in DefDatabase <ThingDef> .AllDefs where typeof(OsirisCasket).IsAssignableFrom(def.thingClass) select def; foreach (ThingDef singleDef in enumerable) { Predicate <Thing> predicate = (Thing x) => !((Building_CryptosleepCasket)x).HasAnyContents && ReservationUtility.CanReserve(p, x, 1, -1, null, false); Building_CryptosleepCasket building_CryptosleepCasket = (Building_CryptosleepCasket)GenClosest.ClosestThingReachable(p.Position, p.Map, ThingRequest.ForDef(singleDef), PathEndMode.InteractionCell, TraverseParms.For(p, Danger.Deadly, TraverseMode.ByPawn, false), 9999f, predicate, null, 0, -1, false, RegionType.Set_Passable, false); if (building_CryptosleepCasket != null) { return(building_CryptosleepCasket); } } enumerable = from def in DefDatabase <ThingDef> .AllDefs where typeof(Building_CryptosleepCasket).IsAssignableFrom(def.thingClass) select def; foreach (ThingDef singleDef2 in enumerable) { Predicate <Thing> predicate2 = (Thing x) => !((Building_CryptosleepCasket)x).HasAnyContents && ReservationUtility.CanReserve(p, x, 1, -1, null, false); Building_CryptosleepCasket building_CryptosleepCasket2 = (Building_CryptosleepCasket)GenClosest.ClosestThingReachable (p.Position, p.Map, ThingRequest.ForDef(singleDef2), PathEndMode.InteractionCell, TraverseParms.For(p, Danger.Deadly, TraverseMode.ByPawn, false), 9999f, predicate2, null, 0, -1, false, RegionType.Set_Passable, false); if (building_CryptosleepCasket2 != null) { return(building_CryptosleepCasket2); } } return(null); }
private Thing FindIngredient(Pawn pawn, string thirdItem, Building_ItemProcessor building_processor) { if (building_processor.compItemProcessor.Props.isCategoryBuilding) { Predicate <Thing> predicate = (Thing x) => !x.IsForbidden(pawn) && pawn.CanReserve(x, 1, 1, null, false); IntVec3 position = pawn.Position; Map map = pawn.Map; List <Thing> searchSet = new List <Thing>(); foreach (ThingDef thingDef in ThingCategoryDef.Named(thirdItem).childThingDefs) { if (!(DefDatabase <CombinationDef> .GetNamed(building_processor.thisRecipe).disallowedThingDefs != null && DefDatabase <CombinationDef> .GetNamed(building_processor.thisRecipe).disallowedThingDefs.Contains(thingDef.defName))) { searchSet.AddRange(pawn.Map.listerThings.ThingsOfDef(thingDef)); } } TraverseParms traverseParams = TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false); Predicate <Thing> validator = predicate; PathEndMode peMode = PathEndMode.ClosestTouch; return(GenClosest.ClosestThing_Global_Reachable(pawn.Position, pawn.Map, searchSet, peMode, traverseParams, 9999f, validator, null)); } else { Predicate <Thing> predicate = (Thing x) => !x.IsForbidden(pawn) && pawn.CanReserve(x, 1, 1, null, false); IntVec3 position = pawn.Position; Map map = pawn.Map; ThingRequest thingReq = ThingRequest.ForDef(ThingDef.Named(thirdItem)); PathEndMode peMode = PathEndMode.ClosestTouch; TraverseParms traverseParams = TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false); Predicate <Thing> validator = predicate; return(GenClosest.ClosestThingReachable(position, map, thingReq, peMode, traverseParams, 9999f, validator, null, 0, -1, false, RegionType.Set_Passable, false)); } }
public override Job JobOnThing(Pawn pawn, Thing t) { Building_TurretGunCR turret = t as Building_TurretGunCR; if (turret == null) { return(null); } Thing ammo = GenClosest.ClosestThingReachable(pawn.Position, ThingRequest.ForDef(turret.compAmmo.selectedAmmo), PathEndMode.ClosestTouch, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn), 80, x => !x.IsForbidden(pawn) && pawn.CanReserve(x)); if (ammo == null) { return(null); } int amountNeeded = turret.compAmmo.Props.magazineSize; if (turret.compAmmo.currentAmmo == turret.compAmmo.selectedAmmo) { amountNeeded -= turret.compAmmo.curMagCount; } return(new Job(DefDatabase <JobDef> .GetNamed("ReloadTurret"), t, ammo) { maxNumToCarry = Mathf.Min(amountNeeded, ammo.stackCount) }); }
private Thing FindIngredient(Pawn pawn, Building_Processing building) { ThingDef ingredientDef = building.CompProcessing.IngredientDef; ThingFilter ingredientFilter = building.CompProcessing.IngredientFilter; ThingDef contentsDef = building.CompProcessing.contentsDef; Predicate <Thing> ingredientValidator; ThingRequest ingredientRequest; // Contents for when stuff matters. if (building.CompProcessing.ProductDef.MadeFromStuff && contentsDef != null) { ingredientValidator = (Thing thing) => !thing.IsForbidden(pawn) && pawn.CanReserve(thing); ingredientRequest = ThingRequest.ForDef(contentsDef); } // Use category if no ingredient def. else if (ingredientDef == null) { if (ingredientFilter == null) { // Complete failure. return(null); } ingredientValidator = (Thing thing) => !thing.IsForbidden(pawn) && pawn.CanReserve(thing) && ingredientFilter.Allows(thing); ingredientRequest = ingredientFilter.BestThingRequest; } // Single ingredient def if possible. else { ingredientValidator = (Thing thing) => !thing.IsForbidden(pawn) && pawn.CanReserve(thing); ingredientRequest = ThingRequest.ForDef(ingredientDef); } return(GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ingredientRequest, PathEndMode.ClosestTouch, TraverseParms.For(pawn), 9999f, ingredientValidator)); }
static void Postfix(Thing __result, Pawn pawn) { bool found = false; if (pawn != null && __result == null) { foreach (Building_InfiniteStorage storage in WorldComp.GetInfiniteStorages(pawn.Map)) { if (storage.TryRemove(ThingDefOf.ComponentIndustrial, 1, out List <Thing> list)) { found = true; foreach (Thing t in list) { BuildingUtil.DropThing(t, 1, storage, storage.Map, null); } } } if (found) { __result = GenClosest.ClosestThingReachable( pawn.Position, pawn.Map, ThingRequest.ForDef(ThingDefOf.ComponentIndustrial), PathEndMode.InteractionCell, TraverseParms.For(pawn, pawn.NormalMaxDanger(), TraverseMode.ByPawn, false), 9999f, (Thing x) => !x.IsForbidden(pawn) && pawn.CanReserve(x, 1, -1, null, false), null, 0, -1, false, RegionType.Set_Passable, false); } } }
// Token: 0x060032A0 RID: 12960 RVA: 0x001196A0 File Offset: 0x001178A0 private Hive FindClosestHive(Pawn pawn) { ThingDef hiveDef = RimWorld.ThingDefOf.Hive; Hive hive = null; bool pawnFaction = pawn.Faction != null; bool pawnDefaultFaction = pawn.kindDef.defaultFactionType != null; FactionDef factionDef = pawnFaction ? pawn.Faction.def : (pawnDefaultFaction ? pawn.kindDef.defaultFactionType : null); if (factionDef == null) { return(null); } List <ThingDef> defs = factionDef.HivedefsFor(); if (pawn.Faction != null && !defs.NullOrEmpty()) { foreach (ThingDef td in defs) { hiveDef = td; hive = GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForDef(hiveDef), PathEndMode.Touch, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), 30f, (Thing x) => x.Faction == pawn.Faction, null, 0, 30, false, RegionType.Set_Passable, false) as Hive; if (hive != null) { return(hive); } } } return(GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForDef(hiveDef), PathEndMode.Touch, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), 30f, (Thing x) => x.Faction == pawn.Faction, null, 0, 30, false, RegionType.Set_Passable, false) as Hive); }
private static UnfinishedThing ClosestUnfinishedThingForBill(Pawn pawn, Bill_ProductionWithUft bill) { if (ModCheck.Validate.NoJobAuthors.IsInitialized()) { Predicate <Thing> predicate = (Thing t) => !t.IsForbidden(pawn) && ((UnfinishedThing)t).Recipe == bill.recipe && ((UnfinishedThing)t).ingredients.TrueForAll((Thing x) => bill.IsFixedOrAllowedIngredient(x.def)); IntVec3 position = pawn.Position; Map map = pawn.Map; ThingRequest thingReq = ThingRequest.ForDef(bill.recipe.unfinishedThingDef); PathEndMode peMode = PathEndMode.InteractionCell; TraverseParms traverseParams = TraverseParms.For(pawn, pawn.NormalMaxDanger()); Predicate <Thing> validator = predicate; return((UnfinishedThing)GenClosest.ClosestThingReachable(position, map, thingReq, peMode, traverseParams, 9999f, validator)); } else { Predicate <Thing> predicate = (Thing t) => !t.IsForbidden(pawn) && ((UnfinishedThing)t).Recipe == bill.recipe && ((UnfinishedThing)t).Creator == pawn && ((UnfinishedThing)t).ingredients.TrueForAll((Thing x) => bill.IsFixedOrAllowedIngredient(x.def)) && pawn.CanReserve(t); IntVec3 position = pawn.Position; Map map = pawn.Map; ThingRequest thingReq = ThingRequest.ForDef(bill.recipe.unfinishedThingDef); PathEndMode peMode = PathEndMode.InteractionCell; TraverseParms traverseParams = TraverseParms.For(pawn, pawn.NormalMaxDanger()); Predicate <Thing> validator = predicate; return((UnfinishedThing)GenClosest.ClosestThingReachable(position, map, thingReq, peMode, traverseParams, 9999f, validator)); } }
public static void Postfix(Pawn pawn, Building_Turret tube, ref Thing __result) { if (__result != null) { return; } var turret = tube as Building_ShipTurret; StorageSettings allowedShellsSettings = ThingCompUtility.TryGetComp <CompChangeableProjectilePlural>(turret.gun).allowedShellsSettings; Predicate <Thing> pred = (Thing x) => { if (ForbidUtility.IsForbidden(x, pawn) || !ReservationUtility.CanReserve(pawn, x, 1, -1, (ReservationLayerDef)null, false)) { return(false); } else { return(allowedShellsSettings?.AllowedToAccept(x) ?? true); } }; foreach (String defName in shellDefNames) { var val = ThingDef.Named(defName); __result = GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForDef(val), PathEndMode.ClosestTouch, TraverseParms.For(pawn), 9999f, pred); if (__result != null) { return; } } }
public override Job JobOnCell(Pawn pawn, IntVec3 cell) { Job job = base.JobOnCell(pawn, cell); if (job != null && job.plantDefToSow != null && job.plantDefToSow.blueprintDef != null) { Predicate <Thing> predicate = (Thing tempThing) => !ForbidUtility.IsForbidden(tempThing, pawn.Faction) && PawnLocalAwareness.AnimalAwareOf(pawn, tempThing) && ReservationUtility.CanReserve(pawn, tempThing, 1); Thing bestSeedThingForSowing = GenClosest.ClosestThingReachable( cell, pawn.Map, ThingRequest.ForDef(job.plantDefToSow.blueprintDef), PathEndMode.ClosestTouch, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), 9999, predicate, null, -1, false); if (bestSeedThingForSowing != null) { return(new Job(LocalJobDefOf.SowWithSeeds, cell, bestSeedThingForSowing) { plantDefToSow = job.plantDefToSow, count = 25 }); } return(null); } return(job); }
public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false) { Building_TurretGunCE turret = t as Building_TurretGunCE; if (turret == null || (!forced && !turret.AllowAutomaticReload)) { return(false); } if (!turret.NeedsReload || !pawn.CanReserveAndReach(turret, PathEndMode.ClosestTouch, Danger.Deadly) || turret.IsForbidden(pawn.Faction)) { return(false); } if (!turret.CompAmmo.UseAmmo) { return(true); } Thing ammo = GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForDef(turret.CompAmmo.SelectedAmmo), PathEndMode.ClosestTouch, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn), 80, x => !x.IsForbidden(pawn) && pawn.CanReserve(x)); return(ammo != null); }
// Used to automatically re-arm turrets static void Postfix(WorkGiver_ReloadTurret __instance, ref Job __result, Pawn pawn, Thing t, bool forced) { if (__result == null) { if (t is Building_TurretGunCE turret) { if (WorldComp.HasStorages(turret.Map) && CombatExtendedUtil.HasAmmo(turret.CompAmmo.SelectedAmmo)) { var storage = GenClosest.ClosestThingReachable( turret.Position, turret.Map, ThingRequest.ForDef(WorldComp.WeaponStorageDef), Verse.AI.PathEndMode.ClosestTouch, TraverseParms.For(pawn, pawn.NormalMaxDanger(), TraverseMode.ByPawn, false), 100); if (storage != null) { // TODO - Add setting where ammo should be dropped //CombatExtendedUtil.TryDropAmmo(turret.CompAmmo.SelectedAmmo, turret.CompAmmo.Props.magazineSize, storage.Position, storage.Map); __result = new Job( DefDatabase <JobDef> .GetNamed("ReloadTurret", true), t, new StoredAmmo( Patch_WorkGiver_ReloadTurret_HasJobOnThing.WS, turret.CompAmmo.SelectedAmmo, turret.CompAmmo.Props.magazineSize, forced)); } } } } }
public override Job JobOnCell(Pawn pawn, IntVec3 c, bool forced = false) { var job = base.JobOnCell(pawn, c, forced); // plant has seeds, if there is a seed return a job, otherwise prevent it. Seeds with no category are forbidden. var seed = job?.plantDefToSow?.blueprintDef; if (seed != null && !seed.thingCategories.NullOrEmpty()) { // Clear the area some... var zone = c.GetZone(pawn.Map); if (zone != null) { foreach (var corner in GenAdj.AdjacentCells8WayRandomized()) { var cell = c + corner; if (zone.ContainsCell(cell)) { foreach (var thing in pawn.Map.thingGrid.ThingsAt(cell)) { if (thing.def != job.plantDefToSow && thing.def.BlocksPlanting(true) && pawn.CanReserve(thing) && !thing.IsForbidden(pawn)) { if (thing.def.category == ThingCategory.Plant) { return(new Job(JobDefOf.CutPlant, thing)); } if (thing.def.EverHaulable) { return(HaulAIUtility.HaulAsideJobFor(pawn, thing)); } } } } } } Predicate <Thing> predicate = (Thing tempThing) => !ForbidUtility.IsForbidden(tempThing, pawn.Faction) && ForbidUtility.InAllowedArea(tempThing.Position, pawn) && PawnLocalAwareness.AnimalAwareOf(pawn, tempThing) && ReservationUtility.CanReserve(pawn, tempThing, 1); Thing bestSeedThingForSowing = GenClosest.ClosestThingReachable( c, pawn.Map, ThingRequest.ForDef(job.plantDefToSow.blueprintDef), PathEndMode.ClosestTouch, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), 9999, predicate); if (bestSeedThingForSowing != null) { return(new Job(ResourceBank.JobDefOf.SowWithSeeds, c, bestSeedThingForSowing) { plantDefToSow = job.plantDefToSow, count = SEEDS_TO_CARRY }); } return(null); } return(job); }
public static List <Thing> GetAllOfThingsOnMap(string defName) { List <Thing> result = null; if (!(from t in DefDatabase <ThingDef> .AllDefs where t.defName == defName select t).TryRandomElement(out ThingDef finalDef)) { Log.Error("Unable to locate " + defName + " in DefDatabase.", false); } else { var def = finalDef; var req = ThingRequest.ForDef(def); var thingList = new List <Thing>(); thingList = Find.CurrentMap.listerThings.ThingsMatching(req); if (thingList.Count == 0) { //Log.Error("No things found in colony."); return(null); } result = thingList; // Log.Error("Num of found things in colony: " + thingList.Count); } return(result); }
public static Blueprint_Install ExistingBlueprintFor(Thing th) { ThingDef installBlueprintDef = th.GetInnerIfMinified().def.installBlueprintDef; Blueprint_Install result; if (installBlueprintDef == null) { result = null; } else { List <Map> maps = Find.Maps; for (int i = 0; i < maps.Count; i++) { List <Thing> list = maps[i].listerThings.ThingsMatching(ThingRequest.ForDef(installBlueprintDef)); for (int j = 0; j < list.Count; j++) { Blueprint_Install blueprint_Install = list[j] as Blueprint_Install; if (blueprint_Install != null && blueprint_Install.MiniToInstallOrBuildingToReinstall == th) { return(blueprint_Install); } } } result = null; } return(result); }
protected override ThoughtState CurrentStateInternal(Pawn p) { if (!p.needs.AllNeeds.Any(x => x.def == ReligionDefOf.Religion_Need)) { return(ThoughtState.Inactive); } var pawnReligion = p.story.traits.allTraits.Find(x => x.def is TraitDef_ReligionTrait).def; var altars = p.Map.listerThings.ThingsMatching(ThingRequest.ForDef(ReligionDefOf.Altar)); if (altars.NullOrEmpty()) { return(ThoughtState.Inactive); } foreach (var thing in altars) { var a = (Building_Altar)thing; if (a.religion.Contains(pawnReligion) && a.relic != null && a.lectern != null && !a.lectern.CompAssignableToPawn.AssignedPawnsForReading.NullOrEmpty()) { return(ThoughtState.Inactive); } } return(true); return(ThoughtState.Inactive); }
public Thing getAmmo(Pawn pawn, List <AmmoDef> ammoTypes, int index) { return(GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForDef(ammoTypes[index]), PathEndMode.ClosestTouch, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn), 80, x => !x.IsForbidden(pawn) && pawn.CanReserve(x))); }
public static Thing ClosestReachableCocoonThatEggNeedsHost(Pawn pawn, ThingDef t) { Thing thing; List <Thing> list = SpawnedEggsNeedHosts(pawn.Map); thing = GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForDef(XenomorphDefOf.RRY_EggXenomorphFertilized), PathEndMode.OnCell, TraverseParms.For(TraverseMode.NoPassClosedDoors, Danger.Deadly, false), 9999f, (x => list.Contains(x)), null, 0, -1, false, RegionType.Set_Passable, false); thing = GenClosest.ClosestThingReachable(thing.Position, thing.Map, ThingRequest.ForDef(XenomorphDefOf.RRY_Xenomorph_Humanoid_Cocoon), PathEndMode.OnCell, TraverseParms.For(TraverseMode.NoPassClosedDoors, Danger.Deadly, false), 10f, (x => (x is Building_XenomorphCocoon XC)), null, 0, -1, false, RegionType.Set_Passable, false); return(thing); }
public static bool ThingsOfDef(ListerThings __instance, ref List <Thing> __result, ThingDef def) { __result = EmptyList; if (def != null) { __result = __instance.ThingsMatching(ThingRequest.ForDef(def)); } return(false); }
private Thing ThingToDo(Pawn pawn) { var singleDef = WhatDef(); var thingRequest = ThingRequest.ForDef(singleDef); var closestPosition = ClosestPosition(pawn, thingRequest); return(closestPosition); }
public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false) { Building_TurretGunCE turret = t as Building_TurretGunCE; if (turret == null || turret.CompAmmo == null) { return(null); } if (!turret.CompAmmo.UseAmmo) { return(new Job(CE_JobDefOf.ReloadTurret, t, null)); } // Iterate through all possible ammo types for NPC's to find whichever is available, starting with currently selected Thing ammo = null; var ammoTypes = turret.CompAmmo.Props.ammoSet.ammoTypes.Select(l => l.ammo).ToList(); var index = ammoTypes.IndexOf(turret.CompAmmo.SelectedAmmo); for (int i = 0; i < ammoTypes.Count; i++) { index = (index + i) % ammoTypes.Count; ammo = GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForDef(ammoTypes[index]), PathEndMode.ClosestTouch, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn), 80, x => !x.IsForbidden(pawn) && pawn.CanReserve(x)); if (ammo != null || pawn.Faction == Faction.OfPlayer) { break; } } if (ammo == null) { return(null); } // Update selected ammo if necessary if (ammo.def != turret.CompAmmo.SelectedAmmo) { turret.CompAmmo.SelectedAmmo = ammo.def as AmmoDef; } // Create the actual job int amountNeeded = turret.CompAmmo.Props.magazineSize; if (turret.CompAmmo.CurrentAmmo == turret.CompAmmo.SelectedAmmo) { amountNeeded -= turret.CompAmmo.CurMagCount; } return(new Job(DefDatabase <JobDef> .GetNamed("ReloadTurret"), t, ammo) { count = Mathf.Min(amountNeeded, ammo.stackCount) }); }
private IEnumerable <Toil> PrepareToIngestToils_ToolUser(Toil chewToil) { if (eatingFromInventory) { yield return(Toils_Misc.TakeItemFromInventoryToCarrier(pawn, TargetIndex.A)); } else { yield return(ReserveFoodIfWillIngestWholeStack()); Toil gotoToPickup = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch).FailOnDespawnedNullOrForbidden(TargetIndex.A); yield return(Toils_Jump.JumpIf(gotoToPickup, () => pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation))); yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch).FailOnDespawnedNullOrForbidden(TargetIndex.A)); yield return(Toils_Jump.Jump(chewToil)); yield return(gotoToPickup); yield return(Toils_Ingest.PickupIngestible(TargetIndex.A, pawn)); Toil reserveExtraFoodToCollect = Toils_Reserve.Reserve(TargetIndex.C); Toil findExtraFoodToCollect = new Toil(); findExtraFoodToCollect.initAction = delegate { if (pawn.inventory.innerContainer.TotalStackCountOfDef(IngestibleSource.def) < job.takeExtraIngestibles) { Predicate <Thing> validator = (Thing x) => pawn.CanReserve(x) && !x.IsForbidden(pawn) && x.IsSociallyProper(pawn); Thing thing = GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForDef(IngestibleSource.def), PathEndMode.Touch, TraverseParms.For(pawn), 12f, validator); if (thing != null) { pawn.CurJob.SetTarget(TargetIndex.C, thing); JumpToToil(reserveExtraFoodToCollect); } } }; findExtraFoodToCollect.defaultCompleteMode = ToilCompleteMode.Instant; yield return(Toils_Jump.Jump(findExtraFoodToCollect)); yield return(reserveExtraFoodToCollect); yield return(Toils_Goto.GotoThing(TargetIndex.C, PathEndMode.Touch)); yield return(Toils_Haul.TakeToInventory(TargetIndex.C, () => job.takeExtraIngestibles - pawn.inventory.innerContainer.TotalStackCountOfDef(IngestibleSource.def))); yield return(findExtraFoodToCollect); } yield return(Toils_Ingest.CarryIngestibleToChewSpot(pawn, TargetIndex.A).FailOnDestroyedOrNull(TargetIndex.A)); yield return(Toils_Ingest.FindAdjacentEatSurface(TargetIndex.B, TargetIndex.A)); }