Skip to content

Commit

Permalink
Next updates (#181)
Browse files Browse the repository at this point in the history
* Compatibility with quarry

* v1.1.5 release canditate

* Fixes for prisoner patient

* remove logging

* add dll

Co-authored-by: Hazzer <[email protected]>
  • Loading branch information
Hazzer and Hazzer authored Jun 3, 2020
1 parent 1ad003e commit 00a4956
Show file tree
Hide file tree
Showing 16 changed files with 141 additions and 45 deletions.
2 changes: 1 addition & 1 deletion About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</li>
</modDependencies>

<description>Version 1.1.4
<description>Version 1.1.5

This mod force prisoners to work. To enable this feature prisoners must have "Force to work" option checked ("Prisoner" tab). Prison labor needs management that consist:
- Motivation - prisoners need to be motivated by presence of colonists. Wardens have new job - supervising prisoners. Low motivation can lead to revolts.
Expand Down
Binary file modified Assemblies/PrisonLabor.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
</p>
<p align="center">
<a href="https://github.com/Aviuz/PrisonLabor/releases">
<img src="https://img.shields.io/badge/version-1.1.4-orange.svg?style=flat" alt="v1.1.4" />
<img src="https://img.shields.io/badge/version-1.1.5-orange.svg?style=flat" alt="v1.1.5" />
</a>
</p>

Expand Down
1 change: 1 addition & 0 deletions Source/CompatibilityPatches/Initialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ internal static void Run()
SeedsPlease.Init();
//NoWaterNoLife.Init();
WorkTab.Init();
Quarry.Init();
}
}
}
75 changes: 75 additions & 0 deletions Source/CompatibilityPatches/Quarry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using HarmonyLib;
using PrisonLabor.Core;
using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Verse;
using Verse.AI;

namespace PrisonLabor.CompatibilityPatches
{
internal static class Quarry
{
private static bool foundType;
internal static void Init()
{
if (Check())
{
Patch();
}
}

private static void Patch()
{
try
{
MethodBase methodBase = getTargetMethod();
if (methodBase != null)
{
var harmony = new Harmony("Harmony_PrisonLabor_Quarry");
harmony.Patch(methodBase, postfix: new HarmonyMethod(typeof(Quarry).GetMethod("postfix_Job")));
}
}
catch (Exception e)
{
Log.Error($"PrisonLaborException: failed to proceed Query mod patches: {e.ToString()}");
}

}

public static Job postfix_Job(Job __result, Pawn pawn, Thing t, bool forced)
{
WorkTypeDef workDef = DefDatabase<WorkTypeDef>.GetNamed("QuarryMining");

if (__result != null && pawn.Faction.IsPlayer && !pawn.IsPrisonerOfColony && PrisonLaborUtility.IsDisabledByLabor(__result.targetA.Cell, pawn, workDef))
{
return null;
}
return __result;
}
private static MethodBase getTargetMethod()
{
WorkGiverDef workDef = DefDatabase<WorkGiverDef>.GetNamed("QRY_MineQuarry");
return workDef.giverClass.GetMethod("JobOnThing");
}

private static bool Check()
{
try
{
var mod = LoadedModManager.RunningMods.First(m => m.Name == "Quarry 1.1");
foundType = mod != null;
Verse.Log.Message($"[PL] Trying to find: {mod}, Result: {foundType}");
}
catch
{
foundType = false;
}
return foundType;
}
}
}
6 changes: 2 additions & 4 deletions Source/CompatibilityPatches/SeedsPlease_WorkDriver_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ public static void Run()
var harvestDriverClass = JobDefOf.Harvest.driverClass.BaseType;
harmony.Patch(
harvestDriverClass.GetMethod("HarvestSeedsToil", BindingFlags.NonPublic | BindingFlags.Instance),
new HarmonyMethod(null), new HarmonyMethod(null), new HarmonyMethod(typeof(SeedsPlease_WorkDriver_Patch).GetMethod("MethodFinder")));
harmony.Patch(
method,
new HarmonyMethod(null), new HarmonyMethod(null), new HarmonyMethod(typeof(SeedsPlease_WorkDriver_Patch).GetMethod("DelegateTranspiler")));
transpiler: new HarmonyMethod(typeof(SeedsPlease_WorkDriver_Patch).GetMethod("MethodFinder")));
harmony.Patch(method, transpiler: new HarmonyMethod(typeof(SeedsPlease_WorkDriver_Patch).GetMethod("DelegateTranspiler")));
}

public static IEnumerable<CodeInstruction> MethodFinder(ILGenerator gen, MethodBase mBase, IEnumerable<CodeInstruction> instr)
Expand Down
9 changes: 9 additions & 0 deletions Source/Core/AI/JobGivers/JobGiver_Diet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@ public override float GetPriority(Pawn pawn)
if (food.CurCategory < minCategory)
return 0f;
if (food.CurCategory <= stopWorkingCat)
{
return 11f;
}
if (food.CurLevelPercentage < pawn.RaceProps.FoodLevelPercentageWantEat)
{
return 7f;
}
return 0f;
}

Expand All @@ -39,6 +43,11 @@ protected override Job TryGiveJob(Pawn pawn)
if (food == null || food.CurCategory < minCategory)
return null;

if (HealthAIUtility.ShouldHaveSurgeryDoneNow(pawn))
{
return null;
}

var need = pawn.needs.TryGetNeed<Need_Motivation>();
if (need != null)
need.IsPrisonerWorking = false;
Expand Down
6 changes: 3 additions & 3 deletions Source/Core/AI/JobGivers/JobGiver_Labor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public override ThinkResult TryIssueJobPackage(Pawn pawn, JobIssueParams jobPara

if (pawn.timetable == null)
WorkSettings.InitWorkSettings(pawn);
if (HealthAIUtility.ShouldHaveSurgeryDoneNow(pawn))
if (HealthAIUtility.ShouldHaveSurgeryDoneNow(pawn) || HealthAIUtility.ShouldBeTendedNowByPlayer(pawn) || HealthAIUtility.ShouldSeekMedicalRest(pawn))
return ThinkResult.NoJob;
//Check medical assistance, fed, and rest if not override
if (!PrisonLaborUtility.WorkTime(pawn))
Expand Down Expand Up @@ -184,8 +184,8 @@ public override ThinkResult TryIssueJobPackage(Pawn pawn, JobIssueParams jobPara

private bool PawnCanUseWorkGiver(Pawn pawn, WorkGiver giver)
{
return !giver.ShouldSkip(pawn) && (giver.def.nonColonistsCanDo || pawn.IsPrisoner) &&
(pawn.story == null || !pawn.WorkTagIsDisabled(giver.def.workTags)) &&
return (pawn.story == null || !pawn.WorkTagIsDisabled(giver.def.workTags)) &&
!giver.ShouldSkip(pawn) && (giver.def.nonColonistsCanDo || pawn.IsPrisoner) &&
giver.MissingRequiredCapacity(pawn) == null;
}

Expand Down
3 changes: 2 additions & 1 deletion Source/Core/Meta/Version.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public enum Version
v1_1_0,
v1_1_2,
v1_1_3,
v1_1_4
v1_1_4,
v1_1_5
}
}
4 changes: 2 additions & 2 deletions Source/Core/Meta/VersionUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ namespace PrisonLabor.Core.Meta
{
class VersionUtility
{
public const Version versionNumber = Version.v1_1_4;
public const string versionString = "1.1.4";
public const Version versionNumber = Version.v1_1_5;
public const string versionString = "1.1.5";

public static Version VersionOfSaveFile { get; set; }

Expand Down
12 changes: 11 additions & 1 deletion Source/Core/PrisonLaborUtility.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using PrisonLabor.Constants;
using PrisonLabor.Core.LaborArea;
Expand Down Expand Up @@ -61,7 +62,16 @@ public static bool canWorkHere(IntVec3 pos, Pawn pawn, WorkTypeDef workType)
if (!pawn.IsPrisonerOfColony && pos != null && pawn.Map.areaManager.Get<Area_Labor>() != null &&
!WorkSettings.WorkDisabled(workType))
{
return !pawn.Map.areaManager.Get<Area_Labor>()[pos];
bool result = true;
try
{
result = !pawn.Map.areaManager.Get<Area_Labor>()[pos];
}
catch (IndexOutOfRangeException e)
{
Log.Message($"IndexOutOfRangeException for {workType.label} calling pos {pos}");
}
return result;
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ static bool HasJobOnThingPostfix(bool __result, WorkGiver_DeepDrill __instance,
{
if (pawn.IsPrisonerOfColony)
{
return true;
return pawn.CanReserve(building, 1, -1, null, forced);
}
else if (pawn.Faction.IsPlayer)
{
return !PrisonLaborUtility.IsDisabledByLabor(building.Position, pawn, __instance.def.workType);
return __result && !PrisonLaborUtility.IsDisabledByLabor(building.Position, pawn, __instance.def.workType);
}
}
return __result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private static IEnumerable<Thing> checkFields(IEnumerable<Thing> __result, WorkG
{
foreach (Thing thing in __result)
{
//Log.Message($"Work type: { __instance.def.workType}, thing is {thing}");
//Log.Message($"Work type: { __instance.def.workType}, thing is {thing}, value: {PrisonLaborUtility.canWorkHere(thing.Position, pawn, __instance.def.workType)}");
if (thing != null && PrisonLaborUtility.canWorkHere(thing.Position, pawn, __instance.def.workType))
{
// Log.Message($"Work type { __instance.def.workType}, value: {PrisonLaborUtility.canWorkHere(thing.Position, pawn, __instance.def.workType)}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,32 @@ static bool Prefix(MentalStateHandler __instance, ref bool __result, MentalState
if (pawn.IsPrisonerOfColony)
{
var need = pawn.needs.TryGetNeed<Need_Treatment>();
TreatmentCategory treatmentCat = need.CurCategory;
bool suspended = false;
float chance = 0f;
if (need != null)
{
TreatmentCategory treatmentCat = need.CurCategory;
bool suspended = false;
float chance = 0f;

switch (treatmentCat)
{
case TreatmentCategory.Normal:
chance = 0.1f;
break;
case TreatmentCategory.Bad:
chance = 0.5f;
break;
case TreatmentCategory.VeryBad:
chance = 1f;
break;
}
switch (treatmentCat)
{
case TreatmentCategory.Normal:
chance = 0.1f;
break;
case TreatmentCategory.Bad:
chance = 0.5f;
break;
case TreatmentCategory.VeryBad:
chance = 1f;
break;
}

suspended = UnityEngine.Random.value < chance;
suspended = UnityEngine.Random.value < chance;

if (suspended)
{
__result = false;
return false;
if (suspended)
{
__result = false;
return false;
}
}
}
return true;
Expand Down
9 changes: 0 additions & 9 deletions Source/HarmonyPatches/Patches_Work/Patch_JobDriver_Mine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,6 @@ static private Action createDelegate(JobDriver_Mine __instance)
{
thingList[i].SetForbidden(value: false, warnOnFail: false);
}

if (MineStrikeManager.MineableIsVeryValuable(mineTarget.def))
{
TaleRecorder.RecordTale(TaleDefOf.MinedValuable, pawn, mineTarget.def.building.mineableThing);
}
if (MineStrikeManager.MineableIsValuable(mineTarget.def) && !pawn.Map.IsPlayerHome)
{
TaleRecorder.RecordTale(TaleDefOf.CaravanRemoteMining, pawn, mineTarget.def.building.mineableThing);
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
Changelog:
1.1.5
- remove wealth tracker from prisioners mining
- updated part releated with seed please (no tested)
- added some checks to remove npr errors
- added more checks if prisioners should stay in bed
- Quarry from Quarry mod should works with labor area
- Added french translation (https://github.com/cprodhomme)
- fixed deep drills reservation by colonist and prisioners
1.1.4
- Fixed forbidden resources extracted by prisoners
- Fixed labor arena being not respected by colonist
Expand Down

0 comments on commit 00a4956

Please sign in to comment.