public static bool IsDisabledByLabor(IntVec3 pos, Pawn pawn, WorkTypeDef workType) { if (pos != null && pawn.Map.areaManager.Get <Area_Labor>() != null && !PrisonLaborUtility.WorkDisabled(workType)) { return(pawn.Map.areaManager.Get <Area_Labor>()[pos]); } return(false); }
protected override bool Satisfied(Pawn pawn) { if (pawn.IsPrisoner) { //show tutorials Tutorials.Introduction(); Tutorials.Management(); IntVec3 c; var need = pawn.needs.TryGetNeed <Need_Motivation>(); if (need == null) { if (!pawn.guest.PrisonerIsSecure || RCellFinder.TryFindBestExitSpot(pawn, out c, TraverseMode.ByPawn)) { return(false); } else if (PrisonLaborUtility.LaborEnabled(pawn)) { return(true); } else { return(false); } } // Prisoner will escape if get ready to run. // If he can run he will start ticking impatient, once complete he will get ready. if (!pawn.guest.PrisonerIsSecure || RCellFinder.TryFindBestExitSpot(pawn, out c, TraverseMode.ByPawn)) { need.CanEscape = true; if (need.ReadyToRun) { return(false); } } else { need.CanEscape = false; } if (PrisonLaborUtility.LaborEnabled(pawn)) { return(true); } need.Enabled = false; } return(false); }
private static void Apply(Dictionary <WorkTypeDef, bool> workTypes) { var list = new List <WorkTypeDef>(); foreach (var workDef in workTypes.Keys) { if (workTypes[workDef]) { list.Add(workDef); } } PrisonLaborUtility.SetAllowedWorkTypes(list); PrisonLaborPrefs.AllowedWorkTypes = PrisonLaborUtility.AllowedWorkTypesData; }
private static void CalculateDifficulty() { var value = 1000; if (!enableMotivationMechanics) { value -= 300; } if (advancedGrowing) { value -= 50; } value -= 500; if (!allowAllWorktypes) { var delta = 500 + 7 * 50 + (DefDatabase <WorkTypeDef> .DefCount - 20) * 25; foreach (var wtd in DefDatabase <WorkTypeDef> .AllDefs) { if (!PrisonLaborUtility.WorkDisabled(wtd)) { delta -= 50; } } if (delta > 0) { value += delta; } } if (value >= 1000) { difficulty = value / 10 + " (" + "PrisonLabor_DifficultyNormal".Translate() + ")"; } else if (value >= 800) { difficulty = value / 10 + " (" + "PrisonLabor_DifficultyCasual".Translate() + ")"; } else if (value >= 500) { difficulty = value / 10 + " (" + "PrisonLabor_DifficultyEasy".Translate() + ")"; } else if (value >= 300) { difficulty = value / 10 + " (" + "PrisonLabor_DifficultyPeaceful".Translate() + ")"; } else { difficulty = value / 10 + " (" + "PrisonLabor_DifficultyJoke".Translate() + ")"; } }
public SelectWorkTypesDialog() { absorbInputAroundWindow = true; closeOnEscapeKey = true; doCloseX = true; doCloseButton = true; workTypes = new Dictionary <WorkTypeDef, bool>(); foreach (var workType in DefDatabase <WorkTypeDef> .AllDefs) { if (!PrisonLaborUtility.WorkDisabled(workType)) { workTypes.Add(workType, true); } else { workTypes.Add(workType, false); } } }
public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false) { var prisoner = t as Pawn; var need = prisoner.needs.TryGetNeed <Need_Motivation>(); if (need == null || prisoner == null) { return(null); } if (!ShouldTakeCareOfPrisoner(pawn, prisoner)) { return(null); } if (prisoner.Downed || !pawn.CanReserve(t, 1, -1, null, false) || !prisoner.Awake()) { return(null); } if (pawn.IsPrisoner) { return(null); } if (!PrisonLaborUtility.LaborEnabled(prisoner) && !need.CanEscape) { return(null); } if (PrisonLaborUtility.RecruitInLaborEnabled(prisoner)) { return(new Job(JobDefOf.PrisonerAttemptRecruit, t)); } if ((!PrisonLaborUtility.WorkTime(prisoner) || !need.NeedToBeInspired) && !need.CanEscape) { return(null); } return(new Job(DefDatabase <JobDef> .GetNamed("PrisonLabor_PrisonerSupervise"), prisoner)); }
public override ThinkResult TryIssueJobPackage(Pawn pawn, JobIssueParams jobParams) { var need = pawn.needs.TryGetNeed <Need_Motivation>(); if (pawn.timetable == null) { PrisonLaborUtility.InitWorkSettings(pawn); } if (HealthAIUtility.ShouldHaveSurgeryDoneNow(pawn)) { return(ThinkResult.NoJob); } //Check medical assistance, fed, and rest if not override if (!PrisonLaborUtility.WorkTime(pawn)) { Tutorials.Timetable(); if (need != null) { need.Enabled = false; } return(ThinkResult.NoJob); } //Check motivation if (PrisonLaborPrefs.EnableMotivationMechanics && (need == null || need.IsLazy)) { return(ThinkResult.NoJob); } //Work prisoners will do PrisonLaborUtility.InitWorkSettings(pawn); var workList = pawn.workSettings.WorkGiversInOrderNormal; //TODO check this //workList.RemoveAll(workGiver => workGiver.def.defName == "GrowerSow"); if (need != null) { need.Enabled = false; } var num = -999; var targetInfo = TargetInfo.Invalid; WorkGiver_Scanner workGiver_Scanner = null; for (var j = 0; j < workList.Count; j++) { var workGiver = workList[j]; if (workGiver.def.priorityInType != num && targetInfo.IsValid) { break; } if (PawnCanUseWorkGiver(pawn, workGiver)) { try { var job2 = workGiver.NonScanJob(pawn); if (job2 != null) { if (need != null) { need.Enabled = true; } return(new ThinkResult(job2, this, workList[j].def.tagToGive)); } var scanner = workGiver as WorkGiver_Scanner; if (scanner != null) { if (workGiver.def.scanThings) { Predicate <Thing> predicate = t => !t.IsForbidden(pawn) && scanner.HasJobOnThing(pawn, t, false); var enumerable = scanner.PotentialWorkThingsGlobal(pawn); Thing thing; if (scanner.Prioritized) { var enumerable2 = enumerable; if (enumerable2 == null) { enumerable2 = pawn.Map.listerThings.ThingsMatching(scanner.PotentialWorkThingRequest); } var validator = predicate; thing = GenClosest.ClosestThing_Global_Reachable(pawn.Position, pawn.Map, enumerable2, scanner.PathEndMode, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), 9999f, validator, x => scanner.GetPriority(pawn, x)); } else { var validator = predicate; var forceGlobalSearch = enumerable != null; thing = GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, scanner.PotentialWorkThingRequest, scanner.PathEndMode, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), 9999f, validator, enumerable, 0, scanner.LocalRegionsToScanFirst, forceGlobalSearch, RegionType.Set_Passable, false); } if (thing != null) { targetInfo = thing; workGiver_Scanner = scanner; } } if (workGiver.def.scanCells) { var position = pawn.Position; var num2 = 99999f; var num3 = -3.40282347E+38f; var prioritized = scanner.Prioritized; foreach (var current in scanner.PotentialWorkCellsGlobal(pawn)) { var flag = false; float num4 = (current - position).LengthHorizontalSquared; if (prioritized) { if (!current.IsForbidden(pawn) && scanner.HasJobOnCell(pawn, current)) { var priority = scanner.GetPriority(pawn, current); if (priority > num3 || priority == num3 && num4 < num2) { flag = true; num3 = priority; } } } else if (num4 < num2 && !current.IsForbidden(pawn) && scanner.HasJobOnCell(pawn, current)) { flag = true; } if (flag) { targetInfo = new TargetInfo(current, pawn.Map, false); workGiver_Scanner = scanner; num2 = num4; } } } } } catch (Exception ex) { Log.Error(string.Concat(pawn, " threw exception in WorkGiver ", workGiver.def.defName, ": ", ex.ToString())); } finally { } if (targetInfo.IsValid) { pawn.mindState.lastGivenWorkType = workGiver.def.workType; Job job3; if (targetInfo.HasThing) { job3 = workGiver_Scanner.JobOnThing(pawn, targetInfo.Thing, false); } else { job3 = workGiver_Scanner.JobOnCell(pawn, targetInfo.Cell); } if (job3 != null) { if (need != null) { need.Enabled = true; } return(new ThinkResult(job3, this, workList[j].def.tagToGive)); } Log.ErrorOnce( string.Concat(workGiver_Scanner, " provided target ", targetInfo, " but yielded no actual job for pawn ", pawn, ". The CanGiveJob and JobOnX methods may not be synchronized."), 6112651); } num = workGiver.def.priorityInType; } } return(ThinkResult.NoJob); }