private static HashSet <Thing> FindNearbyNeeders(Pawn pawn, ThingDefCountClass need, IConstructible c, int resTotalAvailable, bool canRemoveExistingFloorUnderNearbyNeeders, out int neededTotal, out Job jobToMakeNeederAvailable) { neededTotal = need.count; HashSet <Thing> hashSet = new HashSet <Thing>(); Thing thing = (Thing)c; foreach (Thing item in GenRadial.RadialDistinctThingsAround(thing.Position, thing.Map, 8f, useCenter: true)) { if (neededTotal >= resTotalAvailable) { break; } if (IsNewValidNearbyNeeder(item, hashSet, c, pawn)) { Blueprint blueprint = item as Blueprint; if (blueprint == null || !ShouldRemoveExistingFloorFirst(pawn, blueprint)) { int num = GenConstruct.AmountNeededByOf((IConstructible)item, need.thingDef); if (num > 0) { hashSet.Add(item); neededTotal += num; } } } } Blueprint blueprint2 = c as Blueprint; if (((blueprint2 != null && blueprint2.def.entityDefToBuild is TerrainDef) & canRemoveExistingFloorUnderNearbyNeeders) && neededTotal < resTotalAvailable) { foreach (Thing item2 in GenRadial.RadialDistinctThingsAround(thing.Position, thing.Map, 3f, useCenter: false)) { if (IsNewValidNearbyNeeder(item2, hashSet, c, pawn)) { Blueprint blueprint3 = item2 as Blueprint; if (blueprint3 != null) { Job job = RemoveExistingFloorJob(pawn, blueprint3); if (job != null) { jobToMakeNeederAvailable = job; return(hashSet); } } } } } jobToMakeNeederAvailable = null; return(hashSet); }
public static Toil DepositHauledThingInContainer(TargetIndex containerInd, TargetIndex reserveForContainerInd) { Toil toil = new Toil(); toil.initAction = delegate { Pawn actor = toil.actor; Job curJob = actor.jobs.curJob; if (actor.carryTracker.CarriedThing == null) { Log.Error(actor + " tried to place hauled thing in container but is not hauling anything.", false); return; } Thing thing = curJob.GetTarget(containerInd).Thing; ThingOwner thingOwner = thing.TryGetInnerInteractableThingOwner(); if (thingOwner != null) { int num = actor.carryTracker.CarriedThing.stackCount; if (thing is IConstructible) { int a = GenConstruct.AmountNeededByOf((IConstructible)thing, actor.carryTracker.CarriedThing.def); num = Mathf.Min(a, num); if (reserveForContainerInd != TargetIndex.None) { Thing thing2 = curJob.GetTarget(reserveForContainerInd).Thing; if (thing2 != null && thing2 != thing) { int num2 = GenConstruct.AmountNeededByOf((IConstructible)thing2, actor.carryTracker.CarriedThing.def); num = Mathf.Min(num, actor.carryTracker.CarriedThing.stackCount - num2); } } } if (actor.carryTracker.innerContainer.TryTransferToContainer(actor.carryTracker.CarriedThing, thingOwner, num, true) != 0) { Building_Grave building_Grave = thing as Building_Grave; if (building_Grave != null) { building_Grave.Notify_CorpseBuried(actor); } } } else if (curJob.GetTarget(containerInd).Thing.def.Minifiable) { actor.carryTracker.innerContainer.ClearAndDestroyContents(DestroyMode.Vanish); } else { Log.Error("Could not deposit hauled thing in container: " + curJob.GetTarget(containerInd).Thing, false); } }; return(toil); }
public static void JumpToCarryToNextContainerIfPossible_Prefix(ref Toil __result, Toil carryToContainerToil, TargetIndex primaryTargetInd) { Toil toil = new Toil(); toil.initAction = delegate() { Pawn actor = toil.actor; Job curJob = actor.jobs.curJob; if (actor.carryTracker.CarriedThing != null) { LocalTargetInfo target; if (curJob.targetQueueB != null && curJob.targetQueueB.Count > 0 && actor.RaceProps.Animal) { target = curJob.GetTarget(primaryTargetInd); Thing primaryTarget2 = target.Thing; bool hasSpareItems2 = actor.carryTracker.CarriedThing.stackCount > GenConstruct.AmountNeededByOf((IConstructible)(object)(IConstructible)primaryTarget2, actor.carryTracker.CarriedThing.def); Predicate <Thing> predicate = (Thing th) => ReservationUtility.CanReserve(actor, primaryTarget2, 1, -1, (ReservationLayerDef)null, false) && GenCollection.Any <ThingDefCountClass>(((IConstructible)th).MaterialsNeeded(), (Predicate <ThingDefCountClass>)((ThingDefCountClass need) => need.thingDef == actor.carryTracker.CarriedThing.def)) && ((th == primaryTarget2) | hasSpareItems2); Thing nextTarget2 = GenClosest.ClosestThing_Global_Reachable(actor.Position, actor.Map, curJob.targetQueueB.Select(delegate(LocalTargetInfo targ) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) LocalTargetInfo val2 = targ; return(val2.Thing); }), (PathEndMode)2, TraverseParms.For(actor, (Danger)3, (TraverseMode)0, false), 99999f, predicate, (Func <Thing, float>)null); if (nextTarget2 != null) { curJob.targetQueueB.RemoveAll((LocalTargetInfo targ) => targ.Thing == nextTarget2); curJob.targetB = nextTarget2; actor.jobs.curDriver.JumpToToil(carryToContainerToil); } } if (curJob.targetQueueB != null && curJob.targetQueueB.Count > 0 && !actor.RaceProps.Animal) { target = curJob.GetTarget(primaryTargetInd); Thing primaryTarget = target.Thing; bool hasSpareItems = actor.carryTracker.CarriedThing.stackCount > GenConstruct.AmountNeededByOf((IConstructible)(object)(IConstructible)primaryTarget, actor.carryTracker.CarriedThing.def); Predicate <Thing> predicate2 = (Thing th) => GenConstruct.CanConstruct(th, actor, false, false) && GenCollection.Any <ThingDefCountClass>(((IConstructible)th).MaterialsNeeded(), (Predicate <ThingDefCountClass>)((ThingDefCountClass need) => need.thingDef == actor.carryTracker.CarriedThing.def)) && ((th == primaryTarget) | hasSpareItems); Thing nextTarget = GenClosest.ClosestThing_Global_Reachable(actor.Position, actor.Map, curJob.targetQueueB.Select(delegate(LocalTargetInfo targ) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) LocalTargetInfo val = targ; return(val.Thing); }), (PathEndMode)2, TraverseParms.For(actor, (Danger)3, (TraverseMode)0, false), 99999f, predicate2, (Func <Thing, float>)null); if (nextTarget != null) { curJob.targetQueueB.RemoveAll((LocalTargetInfo targ) => targ.Thing == nextTarget); curJob.targetB = nextTarget; actor.jobs.curDriver.JumpToToil(carryToContainerToil); } } } }; __result = toil; }
public static Toil JumpToCarryToNextContainerIfPossible(Toil carryToContainerToil, TargetIndex primaryTargetInd) { Toil toil = new Toil(); toil.initAction = delegate { Pawn actor = toil.actor; Job curJob = actor.jobs.curJob; if (actor.carryTracker.CarriedThing != null && curJob.targetQueueB != null && curJob.targetQueueB.Count > 0) { Thing primaryTarget = curJob.GetTarget(primaryTargetInd).Thing; bool hasSpareItems = actor.carryTracker.CarriedThing.stackCount > GenConstruct.AmountNeededByOf((IConstructible)primaryTarget, actor.carryTracker.CarriedThing.def); Predicate <Thing> validator = delegate(Thing th) { if (!GenConstruct.CanConstruct(th, actor, false)) { return(false); } if (!((IConstructible)th).MaterialsNeeded().Any((ThingCountClass need) => need.thingDef == actor.carryTracker.CarriedThing.def)) { return(false); } if (th != primaryTarget && !hasSpareItems) { return(false); } return(true); }; Thing nextTarget = GenClosest.ClosestThing_Global_Reachable(actor.Position, actor.Map, from targ in curJob.targetQueueB select targ.Thing, PathEndMode.Touch, TraverseParms.For(actor, Danger.Deadly, TraverseMode.ByPawn, false), 99999f, validator, null); if (nextTarget != null) { curJob.targetQueueB.RemoveAll((LocalTargetInfo targ) => targ.Thing == nextTarget); curJob.targetB = nextTarget; actor.jobs.curDriver.JumpToToil(carryToContainerToil); } } }; return(toil); }