static Exception Finalizer(Exception __exception, Vector3 clickPos, Pawn pawn) { // Time to clean up our mess if (pawn != null) { CompMeeseeksMemory compMeeseeksMemory = pawn.GetComp <CompMeeseeksMemory>(); if (compMeeseeksMemory != null) { IntVec3 cell = IntVec3.FromVector3(clickPos); DesignatorUtility.RestoreDesignationsOnCell(cell, pawn.MapHeld); } } return(__exception); }
public static void Prefix(Vector3 clickPos, Pawn pawn) { // Ok this is a bit ridiculous but lets try it anyway... // We save all existing designations at this cell and remove them // Then for every thing here, we create all designations for them // So they should get flagged as a viable target for every possible job // Wish me luck. if (pawn != null) { CompMeeseeksMemory compMeeseeksMemory = pawn.GetComp <CompMeeseeksMemory>(); if (compMeeseeksMemory != null && compMeeseeksMemory.CanTakeOrders()) { IntVec3 cell = IntVec3.FromVector3(clickPos); DesignatorUtility.ForceAllDesignationsOnCell(cell, pawn.MapHeld); } } }
private bool PrepareDesignations(SavedJob savedJob, IntVec3 cell) { bool result = false; // Holy shit the things I do for plants - checking for plant cutting jobs that match normal designations - chop wood, harvest plants, cut plants if (savedJob.def.driverClass.IsSubclassOf(typeof(JobDriver_PlantWork))) { if (Memory.jobTargets.Count > 0 && Memory.jobTargets[0].HasThing) { Plant plant = Memory.jobTargets[0].Thing as Plant; if (plant != null) { if (plant.HarvestableNow) { if (plant.def.plant.IsTree) { DesignatorUtility.ForceDesignationOnThingsInCell(cell, base.Map, DesignationDefOf.HarvestPlant, ((Func <Thing, bool>)((Thing thing) => thing.def.plant?.IsTree ?? false))); //Logger.MessageFormat(this, "It's a tree harvest job..."); } else { DesignatorUtility.ForceDesignationOnThingsInCell(cell, base.Map, DesignationDefOf.HarvestPlant, ((Func <Thing, bool>)((Thing thing) => !thing.def.plant?.IsTree ?? false))); //Logger.MessageFormat(this, "It's a plant harvest job..."); } result = true; } else { DesignatorUtility.ForceDesignationOnThingsInCell(cell, base.Map, DesignationDefOf.CutPlant, ((Func <Thing, bool>)((Thing thing) => thing.def.plant != null))); //Logger.MessageFormat(this, "It's a plant cut job..."); result = true; } } } } else { DesignatorUtility.ForceAllDesignationsOnCell(cell, base.Map); result = true; } return(result); }
private void RestoreDesignations(IntVec3 cell) { DesignatorUtility.RestoreDesignationsOnCell(cell, base.Map); }
protected Job GetJobOnTarget(Pawn meeseeks, SavedTargetInfo targetInfo, WorkGiver_Scanner workGiverScanner, bool scanAllThingsOnCell = false) { Job job = null; try { DesignatorUtility.ForceAllDesignationsOnCell(targetInfo.Cell, meeseeks.MapHeld); if (targetInfo.HasThing && !targetInfo.ThingDestroyed) { // Special case for uninstall, the workgiver doesn't check to see if its already uninstalled if (workGiverScanner as WorkGiver_Uninstall != null && !targetInfo.Thing.Spawned) { Logger.WarningFormat(this, "Target is inside {0}", targetInfo.Thing.ParentHolder); DesignatorUtility.RestoreDesignationsOnCell(targetInfo.Cell, meeseeks.MapHeld); return(null); } // Have to try-catch all these damn things because other mods arent't doing null checks :( try { //Logger.MessageFormat(this, "Checking {0} for job on {1}", workGiverScanner, targetInfo.Thing); if (workGiverScanner.HasJobOnThing(meeseeks, targetInfo.Thing, true)) { //Logger.MessageFormat(this, "Getting {0} for job on {1}", workGiverScanner, targetInfo.Thing); job = workGiverScanner.JobOnThing(meeseeks, targetInfo.Thing, true); } } catch (Exception e) { } finally { } } else { // Have to try-catch all these damn things because other mods arent't doing null checks :( try { //Logger.MessageFormat(this, "Checking {0} for job on {1}", workGiverScanner, targetInfo.Cell); if (job == null && workGiverScanner.HasJobOnCell(meeseeks, targetInfo.Cell, true)) { job = workGiverScanner.JobOnCell(meeseeks, targetInfo.Cell, true); } } catch (Exception e) { } finally { } } if (job == null && scanAllThingsOnCell) { var thingsAtCell = meeseeks.MapHeld.thingGrid.ThingsAt(targetInfo.Cell); foreach (Thing thing in thingsAtCell) { //Logger.MessageFormat(this, "Checking {0} for {1}.", thing, workGiverScanner.def.defName); // Have to try-catch all these damn things because other mods arent't doing null checks :( try { Logger.MessageFormat(this, "Checking {0} for job on {1}", workGiverScanner, thing); if (workGiverScanner.HasJobOnThing(meeseeks, thing, true)) { job = workGiverScanner.JobOnThing(meeseeks, thing, true); } } catch (Exception e) { } finally { } if (job != null) { break; } } } } finally { DesignatorUtility.RestoreDesignationsOnCell(targetInfo.Cell, meeseeks.MapHeld); } return(job); }