static bool Prefix(WorkGiver_GrowerHarvest __instance, Pawn pawn, IntVec3 c, ref bool __result) { Plant plant = c.GetPlant(pawn.Map); // If this plant has a secondary resource and is in an orchard zone, don't chop it down unless it's designated if ((plant is PlantWithSecondary) && pawn.Map.zoneManager.ZoneAt(c) is Zone_Orchard) { if (pawn.Map.designationManager.DesignationAt(c, DesignationDefOf.CutPlant) == null) { __result = false; } } else { __result = ( plant != null && !plant.IsForbidden(pawn) && plant.def.plant.Harvestable && plant.LifeStage == PlantLifeStage.Mature && pawn.CanReserve(plant, 1, -1, null, false) ); } return(__result); }
// Do not automatically harvest Party Trees. Player can still designate it explicitly if they wish. public static void HasJobOnCell_PostFix(WorkGiver_GrowerHarvest __instance, Pawn pawn, IntVec3 c, bool forced, ref bool __result) { if (__result == false) { return; } if (c.GetPlant(pawn.Map) is Plant_PartyTree) { __result = false; } }
internal static IntVec3 ClosestLocationReachable(WorkGiver_GrowerHarvest workGiver_GrowerHarvest, Pawn pawn) { Danger maxDanger = pawn.NormalMaxDanger(); //bool forced = false; Map map = pawn.Map; ZoneManager zoneManager = pawn.Map.zoneManager; foreach (IntVec3 actionableLocation in PlantHarvest_Cache.GetClosestActionableLocations(pawn, map, PlantHarvest_Cache.awaitingHarvestCellsMapDict)) { List <Thing> thingsAtLocation = GridsUtility.GetThingList(actionableLocation, map); foreach (Thing thingAtLocation in thingsAtLocation) { if (thingAtLocation is Building_PlantGrower building_PlantGrower) { if (building_PlantGrower == null || !workGiver_GrowerHarvest.ExtraRequirements(building_PlantGrower, pawn) || building_PlantGrower.IsForbidden(pawn) || !pawn.CanReach(building_PlantGrower, PathEndMode.OnCell, maxDanger) ) { continue; } return(actionableLocation); } } if (!(zoneManager.ZoneAt(actionableLocation) is Zone_Growing growZone)) { continue; } if (!workGiver_GrowerHarvest.ExtraRequirements(growZone, pawn)) { continue; } //if (!JobOnCellTest(workGiver_GrowerHarvest, pawn, actionableLocation, forced)) //{ // continue; //} if (!workGiver_GrowerHarvest.HasJobOnCell(pawn, actionableLocation)) { PlantHarvest_Cache.ReregisterObject(pawn.Map, actionableLocation, PlantHarvest_Cache.awaitingHarvestCellsMapDict); continue; } if (!pawn.CanReach(actionableLocation, PathEndMode.OnCell, maxDanger)) { continue; } return(actionableLocation); } return(IntVec3.Invalid); }
protected override Job TryGiveTerminalJob(Pawn pawn) { WorkGiver_Scanner scanner = new WorkGiver_GrowerHarvest(); IntVec3 position = pawn.Position; float num2 = 99999f; TargetInfo targetInfo = TargetInfo.Invalid; foreach (IntVec3 current in scanner.PotentialWorkCellsGlobal(pawn)) { float lengthHorizontalSquared = (current - position).LengthHorizontalSquared; if (lengthHorizontalSquared < num2 && !current.IsForbidden(pawn) && scanner.HasJobOnCell(pawn, current)) { targetInfo = current; //workGiver_Scanner = scanner; num2 = lengthHorizontalSquared; } } if (targetInfo.Cell != TargetInfo.Invalid) { WorkGiver_GrowerHarvest grower = new WorkGiver_GrowerHarvest(); return(grower.JobOnCell(pawn, targetInfo.Cell)); } return(null); }