Skip to content

Commit

Permalink
Merge pull request #247 from Aviuz/1.3.6
Browse files Browse the repository at this point in the history
release candidate
  • Loading branch information
Hazzer authored Dec 8, 2021
2 parents 787d152 + 6eda9a9 commit 12ba320
Show file tree
Hide file tree
Showing 38 changed files with 396 additions and 400 deletions.
Binary file modified 1.3/Assemblies/PrisonLabor.dll
Binary file not shown.
40 changes: 28 additions & 12 deletions 1.3/Defs/WorkGiverDef.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<Defs>
<WorkGiverDef>
<defName>PrisonLabor_SupervisePrisonLabor</defName>
<label>watch prisoner</label>
<giverClass>PrisonLabor.Core.AI.WorkGivers.WorkGiver_Supervise</giverClass>
<workType>PrisonLabor_Jailor</workType>
<priorityInType>5</priorityInType>
<verb>watch prisoner</verb>
<gerund>watching prisoner</gerund>
<requiredCapacities>
<li>Talking</li>
</requiredCapacities>
</WorkGiverDef>
<WorkGiverDef>
<defName>PrisonLabor_SupervisePrisonLabor</defName>
<label>watch prisoner</label>
<giverClass>PrisonLabor.Core.AI.WorkGivers.WorkGiver_Supervise</giverClass>
<workType>PrisonLabor_Jailor</workType>
<priorityInType>5</priorityInType>
<verb>watch prisoner</verb>
<gerund>watching prisoner</gerund>
<requiredCapacities>
<li>Manipulation</li>
</requiredCapacities>
<workTags>
<li>Violent</li>
</workTags>
</WorkGiverDef>

<WorkGiverDef>
<defName>PrisonLabor_ChatWithPrisoner</defName>
<label>chat with working prisoners</label>
<giverClass>PrisonLabor.Core.AI.WorkGivers.WorkGivers_ManipulatePrisoner</giverClass>
<workType>Warden</workType>
<verb>chat with</verb>
<gerund>chatting with</gerund>
<priorityInType>61</priorityInType>
<requiredCapacities>
<li>Talking</li>
</requiredCapacities>
</WorkGiverDef>

<WorkGiverDef>
<defName>PrisonLabor_HandleChains</defName>
Expand Down
5 changes: 1 addition & 4 deletions 1.3/Defs/WorkTypes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@
<verb>Supervise</verb>
<naturalPriority>1099</naturalPriority>
<requireCapableColonist>true</requireCapableColonist>
<relevantSkills>
<li>Social</li>
</relevantSkills>
<workTags>
<li>Social</li>
<li>Violent</li>
</workTags>
</WorkTypeDef>
</Defs>
2 changes: 1 addition & 1 deletion 1.3/Patches/Designators.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<Patch>
<Operation Class="PatchOperationSequence">
<success>Always</success>
<success>Normal</success>
<operations>
<li Class="PatchOperationSequence">
<success>Always</success>
Expand Down
33 changes: 33 additions & 0 deletions 1.3/Patches/SetJailorJobsPatch.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8" ?>
<Patch>
<Operation Class="PatchOperationSequence">
<success>Normal</success>
<operations>
<li Class="PatchOperationReplace">
<xpath>*/WorkGiverDef[defName="DoExecution"]/workType</xpath>
<value>
<workType>PrisonLabor_Jailor</workType>
</value>
</li>
<li Class="PatchOperationReplace">
<xpath>*/WorkGiverDef[defName="ExecuteGuiltyColonist"]/workType</xpath>
<value>
<workType>PrisonLabor_Jailor</workType>
</value>
</li>
<li Class="PatchOperationReplace">
<xpath>*/WorkGiverDef[defName="ReleasePrisoner"]/workType</xpath>
<value>
<workType>PrisonLabor_Jailor</workType>
</value>
</li>
<li Class="PatchOperationReplace">
<xpath>*/WorkGiverDef[defName="TakePrisonerToBed"]/workType</xpath>
<value>
<workType>PrisonLabor_Jailor</workType>
</value>
</li>
</operations>
</Operation>

</Patch>
2 changes: 1 addition & 1 deletion About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</li>
</modDependencies>

<description>Version 1.3.5
<description>Version 1.3.6

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
14 changes: 14 additions & 0 deletions Ideology/Patches/JailorForSlavesPatch.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?>
<Patch>
<Operation Class="PatchOperationSequence">
<success>Normal</success>
<operations>
<li Class="PatchOperationReplace">
<xpath>*/WorkGiverDef[defName="ExecuteSlave"]/workType</xpath>
<value>
<workType>PrisonLabor_Jailor</workType>
</value>
</li>
</operations>
</Operation>
</Patch>
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.3.5-orange.svg?style=flat" alt="v1.3.5" />
<img src="https://img.shields.io/badge/version-1.3.6-orange.svg?style=flat" alt="v1.3.6" />
</a>
</p>

Expand Down
68 changes: 68 additions & 0 deletions Source/CompatibilityPatches/CashRegister.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using CashRegister.Shifts;
using HarmonyLib;
using PrisonLabor.Core.Other;
using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Verse;

namespace PrisonLabor.CompatibilityPatches
{
static class CashRegister
{
private static ModSearcher modSeeker;
internal static void Init()
{
ModSearcher modSeeker = new ModSearcher("Cash Register");
if (modSeeker.LookForMod())
{
Patch();
}
}

private static void Patch()
{
try
{
MethodBase methodBase = GetTargetMethod();
if (methodBase != null)
{
var harmony = new Harmony("Harmony_PrisonLabor_CashRegister");
harmony.Patch(methodBase, postfix: new HarmonyMethod(typeof(CashRegister).GetMethod("PostFixCandidates")));
Log.Message("Prison Labor: Cash Register mod patched");
}
}
catch (Exception e)
{
Log.Error($"PrisonLaborException: failed to proceed Cash Register mod patches: {e.ToString()}");
}

}

public static IEnumerable<Pawn> PostFixCandidates(IEnumerable<Pawn> __result, CompAssignableToPawn __instance)
{
foreach(Pawn pawn in __result)
{
yield return pawn;
}

if (__instance.parent.Spawned && __instance is CompAssignableToPawn_Shifts)
{
foreach(Pawn pawn in __instance.parent.Map.mapPawns.PrisonersOfColonySpawned)
{
yield return pawn;
}
}
}

private static MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(CompAssignableToPawn), "get_AssigningCandidates");
}
}

}
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()
//NoWaterNoLife.Init();
Quarry.Init();
Kajin2.Init();
CashRegister.Init();
}
}
}
6 changes: 0 additions & 6 deletions Source/Core/AI/WorkGivers/WorkGiver_Supervise.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)

if (!PrisonLaborUtility.LaborEnabled(prisoner) && prisonerComp != null && !prisonerComp.EscapeTracker.CanEscape)
return null;
if (PrisonLaborUtility.RecruitInLaborEnabled(prisoner))
return new Job(JobDefOf.PrisonerAttemptRecruit, t);
if (PrisonLaborUtility.ConvertInLaborEnabled(prisoner))
return new Job(JobDefOf.PrisonerConvert, t);
if (PrisonLaborUtility.EnslaveInLaborEnabled(prisoner))
return new Job(JobDefOf.PrisonerEnslave, t);
if ((!PrisonLaborUtility.WorkTime(prisoner) || !need.ShouldBeMotivated) && prisonerComp != null && !prisonerComp.EscapeTracker.CanEscape)
return null;

Expand Down
45 changes: 45 additions & 0 deletions Source/Core/AI/WorkGivers/WorkGivers_ManipulatePrisoner.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Verse;
using Verse.AI;

namespace PrisonLabor.Core.AI.WorkGivers
{
class WorkGivers_ManipulatePrisoner : WorkGiver_Warden
{
public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
{
var prisoner = t as Pawn;

if (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.RecruitInLaborEnabled(prisoner))
{
return new Job(JobDefOf.PrisonerAttemptRecruit, t);
}
if (PrisonLaborUtility.ConvertInLaborEnabled(prisoner))
{
return new Job(JobDefOf.PrisonerConvert, t);
}
if (PrisonLaborUtility.EnslaveInLaborEnabled(prisoner))
{
return new Job(JobDefOf.PrisonerEnslave, t);
}

return null;
}
}
}

3 changes: 2 additions & 1 deletion Source/Core/Meta/Version.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public enum Version
v1_3_2,
v1_3_3,
v1_3_4,
v1_3_5
v1_3_5,
v1_3_6
}
}
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_3_5;
public const string versionString = "1.3.5";
public const Version versionNumber = Version.v1_3_6;
public const string versionString = "1.3.6";

public static Version VersionOfSaveFile { get; set; }

Expand Down
9 changes: 7 additions & 2 deletions Source/Core/PrisonLaborUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace PrisonLabor.Core
{
internal static class PrisonLaborUtility
public static class PrisonLaborUtility
{
public static bool LaborEnabled(this Pawn pawn)
{
Expand Down Expand Up @@ -83,7 +83,7 @@ public static bool IsDisabledByLabor(IntVec3 pos, Pawn pawn, WorkTypeDef workTyp
return false;
}

public static bool canWorkHere(IntVec3 pos, Pawn pawn, WorkTypeDef workType)
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))
Expand All @@ -101,5 +101,10 @@ public static bool canWorkHere(IntVec3 pos, Pawn pawn, WorkTypeDef workType)
}
return true;
}

public static Faction GetPawnFaction(Pawn pawn)
{
return pawn.IsPrisonerOfColony ? Faction.OfPlayer : pawn.Faction;
}
}
}
1 change: 0 additions & 1 deletion Source/Core/Settings/CleanSaveDialog.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using PrisonLabor.Core.GameSaves;
using PrisonLabor.Tweaks;
using UnityEngine;
using Verse;

Expand Down
3 changes: 1 addition & 2 deletions Source/Core/Settings/SelectSaveForCleaningDialog.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using PrisonLabor.Tweaks;
using System.Collections.Generic;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEngine;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> inst
//Add If(pawn.IsPrisonerOfColony) {jump next condition}
yield return new CodeInstruction(OpCodes.Ldarg_2);
yield return new CodeInstruction(OpCodes.Ldarg_1);
yield return new CodeInstruction(OpCodes.Call, typeof(ConstructionUtils).GetMethod("isPrisonerWork"));
yield return new CodeInstruction(OpCodes.Call, typeof(ConstructionUtils).GetMethod(nameof(ConstructionUtils.IsPrisonerWork)));
yield return new CodeInstruction(OpCodes.Brtrue, label);

foreach (var instr in instructions)
Expand Down
Loading

0 comments on commit 12ba320

Please sign in to comment.