public override Job JobOnThing(Pawn pawn, Thing thing, bool forced = false) { ISlotGroupParent slotGroupParent = thing as ISlotGroupParent; if (slotGroupParent == null) { return(null); } if (!pawn.CanReserve(thing.Position)) { return(null); } int num = 0; List <Thing> list = pawn.Map.thingGrid.ThingsListAt(thing.Position); for (int i = 0; i < list.Count; i++) { Thing thing2 = list[i]; if (Building_NutrientPasteDispenser.IsAcceptableFeedstock(thing2.def)) { num += thing2.stackCount; } } if (num > 25) { JobFailReason.Is("AlreadyFilledLower".Translate()); return(null); } return(HopperFillFoodJob(pawn, slotGroupParent)); }
public virtual Thing FindFeedInAnyHopper() { for (int i = 0; i < this.AdjCellsCardinalInBounds.Count; i++) { Thing thing = null; Thing thing2 = null; List <Thing> thingList = this.AdjCellsCardinalInBounds[i].GetThingList(base.Map); for (int j = 0; j < thingList.Count; j++) { Thing thing3 = thingList[j]; if (Building_NutrientPasteDispenser.IsAcceptableFeedstock(thing3.def)) { thing = thing3; } if (thing3.def == ThingDefOf.Hopper) { thing2 = thing3; } } if (thing != null && thing2 != null) { return(thing); } } return(null); }
public virtual bool HasEnoughFeedstockInHoppers() { float num = 0f; for (int i = 0; i < this.AdjCellsCardinalInBounds.Count; i++) { IntVec3 c = this.AdjCellsCardinalInBounds[i]; Thing thing = null; Thing thing2 = null; List <Thing> thingList = c.GetThingList(base.Map); for (int j = 0; j < thingList.Count; j++) { Thing thing3 = thingList[j]; if (Building_NutrientPasteDispenser.IsAcceptableFeedstock(thing3.def)) { thing = thing3; } if (thing3.def == ThingDefOf.Hopper) { thing2 = thing3; } } if (thing != null && thing2 != null) { num += (float)thing.stackCount * thing.def.ingestible.nutrition; } if (num >= base.def.building.nutritionCostPerDispense) { return(true); } } return(false); }
public static Job HopperFillFoodJob(Pawn pawn, ISlotGroupParent hopperSgp) { Building building = (Building)hopperSgp; if (!pawn.CanReserveAndReach(building.Position, PathEndMode.Touch, pawn.NormalMaxDanger())) { return(null); } ThingDef thingDef = null; Thing firstItem = building.Position.GetFirstItem(building.Map); if (firstItem != null) { if (!Building_NutrientPasteDispenser.IsAcceptableFeedstock(firstItem.def)) { if (firstItem.IsForbidden(pawn)) { return(null); } return(HaulAIUtility.HaulAsideJobFor(pawn, firstItem)); } thingDef = firstItem.def; } List <Thing> list = (thingDef != null) ? pawn.Map.listerThings.ThingsOfDef(thingDef) : pawn.Map.listerThings.ThingsInGroup(ThingRequestGroup.FoodSourceNotPlantOrTree); bool flag = false; for (int i = 0; i < list.Count; i++) { Thing thing = list[i]; if (thing.def.IsNutritionGivingIngestible && (thing.def.ingestible.preferability == FoodPreferability.RawBad || thing.def.ingestible.preferability == FoodPreferability.RawTasty) && HaulAIUtility.PawnCanAutomaticallyHaul(pawn, thing, forced: false) && pawn.Map.haulDestinationManager.SlotGroupAt(building.Position).Settings.AllowedToAccept(thing)) { StoragePriority storagePriority = StoreUtility.CurrentStoragePriorityOf(thing); if ((int)storagePriority >= (int)hopperSgp.GetSlotGroup().Settings.Priority) { flag = true; JobFailReason.Is(TheOnlyAvailableFoodIsInStorageOfHigherPriorityTrans); } else { Job job = HaulAIUtility.HaulToCellStorageJob(pawn, thing, building.Position, fitInStoreCell: true); if (job != null) { return(job); } } } } if (!flag) { JobFailReason.Is(NoFoodToFillHopperTrans); } return(null); }
public static Job HopperFillFoodJob(Pawn pawn, ISlotGroupParent hopperSgp) { Building building = hopperSgp as Building; if (!pawn.CanReserveAndReach(building.Position, PathEndMode.Touch, pawn.NormalMaxDanger(), 1, -1, null, false)) { return(null); } ThingDef thingDef = null; Thing firstItem = building.Position.GetFirstItem(building.Map); if (firstItem != null) { if (Building_NutrientPasteDispenser.IsAcceptableFeedstock(firstItem.def)) { thingDef = firstItem.def; } else { if (firstItem.IsForbidden(pawn)) { return(null); } return(HaulAIUtility.HaulAsideJobFor(pawn, firstItem)); } } List <Thing> list; if (thingDef == null) { list = pawn.Map.listerThings.ThingsInGroup(ThingRequestGroup.FoodSourceNotPlantOrTree); } else { list = pawn.Map.listerThings.ThingsOfDef(thingDef); } bool flag = false; for (int i = 0; i < list.Count; i++) { Thing thing = list[i]; if (thing.def.IsNutritionGivingIngestible) { if (thing.def.ingestible.preferability == FoodPreferability.RawBad || thing.def.ingestible.preferability == FoodPreferability.RawTasty) { if (HaulAIUtility.PawnCanAutomaticallyHaul(pawn, thing, false)) { if (pawn.Map.slotGroupManager.SlotGroupAt(building.Position).Settings.AllowedToAccept(thing)) { StoragePriority storagePriority = HaulAIUtility.StoragePriorityAtFor(thing.Position, thing); if (storagePriority >= hopperSgp.GetSlotGroup().Settings.Priority) { flag = true; JobFailReason.Is(WorkGiver_CookFillHopper.TheOnlyAvailableFoodIsInStorageOfHigherPriorityTrans); } else { Job job = HaulAIUtility.HaulMaxNumToCellJob(pawn, thing, building.Position, true); if (job != null) { return(job); } } } } } } } if (!flag) { JobFailReason.Is(WorkGiver_CookFillHopper.NoFoodToFillHopperTrans); } return(null); }