protected Job RemoveExistingFloorJob(Pawn pawn, Blueprint blue) { Job result; if (!WorkGiver_ConstructDeliverResources.ShouldRemoveExistingFloorFirst(pawn, blue)) { result = null; } else { LocalTargetInfo target = blue.Position; ReservationLayerDef floor = ReservationLayerDefOf.Floor; if (!pawn.CanReserve(target, 1, -1, floor, false)) { result = null; } else { result = new Job(JobDefOf.RemoveFloor, blue.Position) { ignoreDesignations = true }; } } return(result); }
private HashSet <Thing> FindNearbyNeeders(Pawn pawn, ThingCountClass 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, true)) { if (neededTotal < resTotalAvailable) { if (this.IsNewValidNearbyNeeder(item, hashSet, c, pawn)) { Blueprint blueprint = item as Blueprint; if (blueprint == null || !WorkGiver_ConstructDeliverResources.ShouldRemoveExistingFloorFirst(pawn, blueprint)) { int num = GenConstruct.AmountNeededByOf((IConstructible)item, need.thingDef); if (num > 0) { hashSet.Add(item); neededTotal += num; } } } continue; } break; } 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, false)) { if (this.IsNewValidNearbyNeeder(item2, hashSet, c, pawn)) { Blueprint blueprint3 = item2 as Blueprint; if (blueprint3 != null) { Job job = this.RemoveExistingFloorJob(pawn, blueprint3); if (job != null) { jobToMakeNeederAvailable = job; return(hashSet); } } } } } jobToMakeNeederAvailable = null; return(hashSet); }
public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false) { if (t.Faction != pawn.Faction) { return(null); } Blueprint blueprint = t as Blueprint; if (blueprint == null) { return(null); } if (GenConstruct.FirstBlockingThing(blueprint, pawn) != null) { return(GenConstruct.HandleBlockingThingJob(blueprint, pawn, forced)); } bool flag = def.workType == WorkTypeDefOf.Construction; if (!GenConstruct.CanConstruct(blueprint, pawn, flag, forced)) { return(null); } if (!flag && WorkGiver_ConstructDeliverResources.ShouldRemoveExistingFloorFirst(pawn, blueprint)) { return(null); } Job job = RemoveExistingFloorJob(pawn, blueprint); if (job != null) { return(job); } Job job2 = ResourceDeliverJobFor(pawn, blueprint); if (job2 != null) { return(job2); } if (def.workType != WorkTypeDefOf.Hauling) { Job job3 = NoCostFrameMakeJobFor(pawn, blueprint); if (job3 != null) { return(job3); } } return(null); }
protected Job RemoveExistingFloorJob(Pawn pawn, Blueprint blue) { if (!WorkGiver_ConstructDeliverResources.ShouldRemoveExistingFloorFirst(pawn, blue)) { return(null); } LocalTargetInfo target = blue.Position; ReservationLayerDef floor = ReservationLayerDefOf.Floor; if (!pawn.CanReserve(target, 1, -1, floor, false)) { return(null); } Job job = new Job(JobDefOf.RemoveFloor, blue.Position); job.ignoreDesignations = true; return(job); }
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); }
public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false) { Job result; if (t.Faction != pawn.Faction) { result = null; } else { Blueprint blueprint = t as Blueprint; if (blueprint == null) { result = null; } else if (GenConstruct.FirstBlockingThing(blueprint, pawn) != null) { result = GenConstruct.HandleBlockingThingJob(blueprint, pawn, forced); } else { bool flag = this.def.workType == WorkTypeDefOf.Construction; if (!GenConstruct.CanConstruct(blueprint, pawn, flag, forced)) { result = null; } else if (!flag && WorkGiver_ConstructDeliverResources.ShouldRemoveExistingFloorFirst(pawn, blueprint)) { result = null; } else { Job job = base.RemoveExistingFloorJob(pawn, blueprint); if (job != null) { result = job; } else { Job job2 = base.ResourceDeliverJobFor(pawn, blueprint, true); if (job2 != null) { result = job2; } else { Job job3 = this.NoCostFrameMakeJobFor(pawn, blueprint); if (job3 != null) { result = job3; } else { result = null; } } } } } } return(result); }