// Token: 0x06000081 RID: 129 RVA: 0x000051D4 File Offset: 0x000033D4 private Job NoCostFrameMakeJobFor(Pawn pawn, IConstructible c) { bool flag = c is Blueprint_Install; Job result; if (flag) { result = null; } else { bool flag2 = c is Blueprint && c.MaterialsNeeded().Count == 0; if (flag2) { Job job = JobMaker.MakeJob(JobDefOf.PlaceNoCostFrame); job.targetA = (Thing)c; result = job; } else { result = null; } } return(result); }
public static int AmountNeededByOf(IConstructible c, ThingDef resDef) { foreach (ThingDefCountClass thingDefCountClass in c.MaterialsNeeded()) { if (thingDefCountClass.thingDef == resDef) { return(thingDefCountClass.count); } } return(0); }
// Get materials considering that IConstructible may be a Blueprint_Install public static List <ThingDefCountClass> GetMaterialsNeededSafely(this IConstructible constructible) { if (constructible is Blueprint_Install bInstall) { return(new List <ThingDefCountClass>() { new ThingDefCountClass(bInstall.GetInnerIfMinified().def, 1) }); } return(constructible.MaterialsNeeded()); }
public static List <ThingDefCount> MaterialsNeededSafe(this IConstructible constructible) { if (constructible is Blueprint_Install blueprintInstall) { return new List <ThingDefCount> { new ThingDefCount(blueprintInstall.GetInnerIfMinified().def, 1) } } ; return(new List <ThingDefCount>(constructible.MaterialsNeeded().Select(x => (ThingDefCount)x))); }
private Job NoCostFrameMakeJobFor(Pawn pawn, IConstructible c) { if (c is Blueprint_Install) { return(null); } if (c is Blueprint && c.MaterialsNeeded().Count == 0) { Job job = new Job(JobDefOf.PlaceNoCostFrame); job.targetA = (Thing)c; return(job); } return(null); }
private Job NoCostFrameMakeJobFor(Pawn pawn, IConstructible c) { Job result; if (c is Blueprint_Install) { result = null; } else if (c is Blueprint && c.MaterialsNeeded().Count == 0) { result = new Job(JobDefOf.PlaceNoCostFrame) { targetA = (Thing)c }; } else { result = null; } return(result); }
public Job NoCostFrameMakeJobFor(Pawn pawn, IConstructible c) { if (c is Blueprint_Install) { return null; } if (c is RimWorld.Blueprint && c.MaterialsNeeded().Count == 0) { return new Job(JobDefOf.PlaceNoCostFrame) { targetA = (Thing)c }; } return null; }
protected Job ResourceDeliverJobFor(Pawn pawn, IConstructible c, bool canRemoveExistingFloorUnderNearbyNeeders = true) { Blueprint_Install blueprint_Install = c as Blueprint_Install; if (blueprint_Install != null) { return(this.InstallJob(pawn, blueprint_Install)); } bool flag = false; ThingDefCountClass thingDefCountClass = null; List <ThingDefCountClass> list = c.MaterialsNeeded(); int count = list.Count; int i = 0; while (i < count) { ThingDefCountClass need = list[i]; if (!pawn.Map.itemAvailability.ThingsAvailableAnywhere(need, pawn)) { flag = true; thingDefCountClass = need; break; } Thing foundRes = GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForDef(need.thingDef), PathEndMode.ClosestTouch, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), 9999f, (Thing r) => WorkGiver_ConstructDeliverResources.ResourceValidator(pawn, need, r), null, 0, -1, false, RegionType.Set_Passable, false); if (foundRes != null) { int resTotalAvailable; this.FindAvailableNearbyResources(foundRes, pawn, out resTotalAvailable); int num; Job job; HashSet <Thing> hashSet = this.FindNearbyNeeders(pawn, need, c, resTotalAvailable, canRemoveExistingFloorUnderNearbyNeeders, out num, out job); if (job != null) { return(job); } hashSet.Add((Thing)c); Thing thing = hashSet.MinBy((Thing nee) => IntVec3Utility.ManhattanDistanceFlat(foundRes.Position, nee.Position)); hashSet.Remove(thing); int num2 = 0; int j = 0; do { num2 += WorkGiver_ConstructDeliverResources.resourcesAvailable[j].stackCount; j++; }while (num2 < num && j < WorkGiver_ConstructDeliverResources.resourcesAvailable.Count); WorkGiver_ConstructDeliverResources.resourcesAvailable.RemoveRange(j, WorkGiver_ConstructDeliverResources.resourcesAvailable.Count - j); WorkGiver_ConstructDeliverResources.resourcesAvailable.Remove(foundRes); Job job2 = new Job(JobDefOf.HaulToContainer); job2.targetA = foundRes; job2.targetQueueA = new List <LocalTargetInfo>(); for (j = 0; j < WorkGiver_ConstructDeliverResources.resourcesAvailable.Count; j++) { job2.targetQueueA.Add(WorkGiver_ConstructDeliverResources.resourcesAvailable[j]); } job2.targetB = thing; if (hashSet.Count > 0) { job2.targetQueueB = new List <LocalTargetInfo>(); foreach (Thing current in hashSet) { job2.targetQueueB.Add(current); } } job2.targetC = (Thing)c; job2.count = num; job2.haulMode = HaulMode.ToContainer; return(job2); } else { flag = true; thingDefCountClass = need; i++; } } if (flag) { JobFailReason.Is(string.Format("{0}: {1}", WorkGiver_ConstructDeliverResources.MissingMaterialsTranslated, thingDefCountClass.thingDef.label), null); } return(null); }
protected Job ResourceDeliverJobFor(Pawn pawn, IConstructible c, bool canRemoveExistingFloorUnderNearbyNeeders = true) { Blueprint_Install blueprint_Install = c as Blueprint_Install; if (blueprint_Install != null) { return(InstallJob(pawn, blueprint_Install)); } bool flag = false; ThingDefCountClass thingDefCountClass = null; List <ThingDefCountClass> list = c.MaterialsNeeded(); int count = list.Count; for (int i = 0; i < count; i++) { ThingDefCountClass need = list[i]; if (!pawn.Map.itemAvailability.ThingsAvailableAnywhere(need, pawn)) { flag = true; thingDefCountClass = need; break; } Thing foundRes = GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForDef(need.thingDef), PathEndMode.ClosestTouch, TraverseParms.For(pawn), 9999f, (Thing r) => ResourceValidator(pawn, need, r)); if (foundRes != null) { FindAvailableNearbyResources(foundRes, pawn, out int resTotalAvailable); int neededTotal; Job jobToMakeNeederAvailable; HashSet <Thing> hashSet = FindNearbyNeeders(pawn, need, c, resTotalAvailable, canRemoveExistingFloorUnderNearbyNeeders, out neededTotal, out jobToMakeNeederAvailable); if (jobToMakeNeederAvailable != null) { return(jobToMakeNeederAvailable); } hashSet.Add((Thing)c); Thing thing = hashSet.MinBy((Thing nee) => IntVec3Utility.ManhattanDistanceFlat(foundRes.Position, nee.Position)); hashSet.Remove(thing); int num = 0; int num2 = 0; do { num += resourcesAvailable[num2].stackCount; num2++; }while (num < neededTotal && num2 < resourcesAvailable.Count); resourcesAvailable.RemoveRange(num2, resourcesAvailable.Count - num2); resourcesAvailable.Remove(foundRes); Job job = new Job(JobDefOf.HaulToContainer); job.targetA = foundRes; job.targetQueueA = new List <LocalTargetInfo>(); for (num2 = 0; num2 < resourcesAvailable.Count; num2++) { job.targetQueueA.Add(resourcesAvailable[num2]); } job.targetB = thing; if (hashSet.Count > 0) { job.targetQueueB = new List <LocalTargetInfo>(); foreach (Thing item in hashSet) { job.targetQueueB.Add(item); } } job.targetC = (Thing)c; job.count = neededTotal; job.haulMode = HaulMode.ToContainer; return(job); } flag = true; thingDefCountClass = need; } if (flag) { JobFailReason.Is($"{MissingMaterialsTranslated}: {thingDefCountClass.thingDef.label}"); } return(null); }
public static bool ResourceDeliverJobFor(WorkGiver_ConstructDeliverResources __instance, ref Job __result, Pawn pawn, IConstructible c, bool canRemoveExistingFloorUnderNearbyNeeders = true) { Blueprint_Install blueprint_Install = c as Blueprint_Install; if (blueprint_Install != null) { __result = InstallJob(pawn, blueprint_Install); return(false); } List <Thing> resourcesAvailable = new List <Thing>(); bool flag = false; ThingDefCountClass thingDefCountClass = null; List <ThingDefCountClass> list = c.MaterialsNeeded(); int count = list.Count; for (int i = 0; i < count; i++) { ThingDefCountClass need = list[i]; if (!pawn.Map.itemAvailability.ThingsAvailableAnywhere(need, pawn)) { flag = true; thingDefCountClass = need; break; } Thing foundRes = GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForDef(need.thingDef), PathEndMode.ClosestTouch, TraverseParms.For(pawn), 9999f, (Thing r) => ResourceValidator(pawn, need, r)); if (foundRes != null) { resourcesAvailable.Clear(); //FindAvailableNearbyResources2(foundRes, pawn, out int resTotalAvailable, resourcesAvailable); int resTotalAvailable; int num0 = Mathf.Min(foundRes.def.stackLimit, pawn.carryTracker.MaxStackSpaceEver(foundRes.def)); resTotalAvailable = 0; resourcesAvailable.Add(foundRes); resTotalAvailable += foundRes.stackCount; if (resTotalAvailable < num0) { foreach (Thing item in GenRadial.RadialDistinctThingsAround(foundRes.Position, foundRes.Map, 5f, useCenter: false)) { if (resTotalAvailable >= num0) { break; } if (item.def == foundRes.def && GenAI.CanUseItemForWork(pawn, item)) { resourcesAvailable.Add(item); resTotalAvailable += item.stackCount; } } } int neededTotal; Job jobToMakeNeederAvailable; HashSet <Thing> hashSet = FindNearbyNeeders(pawn, need, c, resTotalAvailable, canRemoveExistingFloorUnderNearbyNeeders, out neededTotal, out jobToMakeNeederAvailable); if (jobToMakeNeederAvailable != null) { __result = jobToMakeNeederAvailable; return(false); } hashSet.Add((Thing)c); Thing thing = hashSet.MinBy((Thing nee) => IntVec3Utility.ManhattanDistanceFlat(foundRes.Position, nee.Position)); hashSet.Remove(thing); int num = 0; int num2 = 0; do { num += resourcesAvailable[num2].stackCount; num2++; }while (num < neededTotal && num2 < resourcesAvailable.Count); resourcesAvailable.RemoveRange(num2, resourcesAvailable.Count - num2); resourcesAvailable.Remove(foundRes); Job job = JobMaker.MakeJob(JobDefOf.HaulToContainer); job.targetA = foundRes; job.targetQueueA = new List <LocalTargetInfo>(); for (num2 = 0; num2 < resourcesAvailable.Count; num2++) { job.targetQueueA.Add(resourcesAvailable[num2]); } job.targetB = thing; if (hashSet.Count > 0) { job.targetQueueB = new List <LocalTargetInfo>(); foreach (Thing item in hashSet) { job.targetQueueB.Add(item); } } job.targetC = (Thing)c; job.count = neededTotal; job.haulMode = HaulMode.ToContainer; __result = job; return(false); } flag = true; thingDefCountClass = need; } if (flag) { JobFailReason.Is($"{MissingMaterialsTranslated}: {thingDefCountClass.thingDef.label}"); } __result = null; return(false); }