Skip to content

Commit

Permalink
Version 1.3.8 (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hazzer authored Apr 13, 2022
1 parent d57c111 commit c68fd99
Show file tree
Hide file tree
Showing 20 changed files with 150 additions and 46 deletions.
Binary file modified 1.3/Assemblies/PrisonLabor.dll
Binary file not shown.
2 changes: 2 additions & 0 deletions 1.3/Defs/MainButton.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
<li>MedicalCare</li>
<li>GapTiny</li>
<li>FoodRestriction</li>
<li>GapTiny</li>
<li>DrugPolicy</li>
<li>RemainingSpace</li>
</columns>
</PawnTableDef>
Expand Down
59 changes: 32 additions & 27 deletions 1.3/Defs/ThinkTreeDef.xml
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<Defs>
<ThinkTreeDef>
<defName>PrisonLabor_WorkThinkTree</defName>
<insertTag>Humanlike_PostDuty</insertTag>
<insertPriority>80</insertPriority>
<thinkRoot Class="PrisonLabor.Core.AI.ThinkNodes.ThinkNode_Labor">
<invert>false</invert>
<subNodes>
<li Class="PrisonLabor.Core.AI.ThinkNodes.ThinkNode_SeekSafeTemperature">
<ThinkTreeDef>
<defName>PrisonLabor_WorkThinkTree</defName>
<insertTag>Humanlike_PostDuty</insertTag>
<insertPriority>80</insertPriority>
<thinkRoot Class="PrisonLabor.Core.AI.ThinkNodes.ThinkNode_Labor">
<invert>false</invert>
<subNodes>
<li Class="JobGiver_SeekSafeTemperature"/>
<li Class="PrisonLabor.Core.AI.ThinkNodes.ThinkNode_SeekSafeTemperature">
<subNodes>
<li Class="JobGiver_SeekSafeTemperature"/>
</subNodes>
</li>
<li Class="PrisonLabor.Core.AI.ThinkNodes.ThinkNode_IsMotivated">
<subNodes>
<li Class="JobGiver_TakeDrugsForDrugPolicy"/>
</subNodes>
</li>
<li Class="ThinkNode_Tagger">
<tagToGive>ChangingApparel</tagToGive>
<subNodes>
<li Class="JobGiver_PrisonerGetDressed" />
</subNodes>
</li>
<li Class="ThinkNode_Priority">
<subNodes>
<li Class="PrisonLabor.Core.AI.JobGivers.JobGiver_BedTime" />
<li Class="PrisonLabor.Core.AI.JobGivers.JobGiver_PickupWeapon" />
<li Class="PrisonLabor.Core.AI.JobGivers.JobGiver_Diet" />
<li Class="PrisonLabor.Core.AI.JobGivers.JobGiver_Labor" />
</subNodes>
</li>
</subNodes>
</li>
<li Class="ThinkNode_Tagger">
<tagToGive>ChangingApparel</tagToGive>
<subNodes>
<li Class="JobGiver_PrisonerGetDressed" />
</subNodes>
</li>
<li Class="ThinkNode_Priority">
<subNodes>
<li Class="PrisonLabor.Core.AI.JobGivers.JobGiver_BedTime" />
<li Class="PrisonLabor.Core.AI.JobGivers.JobGiver_PickupWeapon" />
<li Class="PrisonLabor.Core.AI.JobGivers.JobGiver_Diet" />
<li Class="PrisonLabor.Core.AI.JobGivers.JobGiver_Labor" />
</subNodes>
</li>
</subNodes>
</thinkRoot>
</ThinkTreeDef>
</thinkRoot>
</ThinkTreeDef>
</Defs>
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.7
<description>Version 1.3.8

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
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.7-orange.svg?style=flat" alt="v1.3.7" />
<img src="https://img.shields.io/badge/version-1.3.8-orange.svg?style=flat" alt="v1.3.8" />
</a>
</p>

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

namespace PrisonLabor.Core.AI.ThinkNodes
{
class ThinkNode_IsMotivated : ThinkNode_Conditional
{
protected override bool Satisfied(Pawn pawn)
{
bool motivatedPrisoner = pawn.IsPrisonerOfColony && pawn.IsMotivated();
if (motivatedPrisoner && pawn.drugs == null)
{
//Migration from older version of PL
pawn.drugs = new Pawn_DrugPolicyTracker(pawn);
}
return motivatedPrisoner;
}
}
}
5 changes: 5 additions & 0 deletions Source/Core/GameSaves/SaveCleaner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ private static void UpdateData(XmlElement xmlNode)
{
removalBuffer.Add(component);
}

if (component.Attributes["Class"].Value == "PrisonLabor.Core.Trackers.CuffsTracker")
{
removalBuffer.Add(component);
}
}
foreach (var item in removalBuffer)
components.RemoveChild(item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public override void DoCell(Rect rect, Pawn pawn, PawnTable table)
if(Widgets.ButtonText(rect, "PrisonLabor_RecruitButtonLabel".Translate()))
{
ConvertPrisoner(pawn);
WindowNotifier.NotifyPLWindows();
}

}
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 @@ -75,6 +75,7 @@ public enum Version
v1_3_4,
v1_3_5,
v1_3_6,
v1_3_7
v1_3_7,
v1_3_8
}
}
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_7;
public const string versionString = "1.3.7";
public const Version versionNumber = Version.v1_3_8;
public const string versionString = "1.3.8";

public static Version VersionOfSaveFile { get; set; }

Expand Down
19 changes: 19 additions & 0 deletions Source/Core/Needs/NeedsUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using PrisonLabor.Core.Meta;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Verse;

namespace PrisonLabor.Core.Needs
{
public static class NeedsUtils
{
public static bool IsMotivated(this Pawn pawn)
{
var need = pawn.needs.TryGetNeed<Need_Motivation>();
return !PrisonLaborPrefs.EnableMotivationMechanics || ( need != null && !need.IsLazy);
}
}
}
1 change: 1 addition & 0 deletions Source/Core/Other/CleanPrisonersStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ static public void Clean(Pawn prisoner)
prisoner.workSettings = new Pawn_WorkSettings(prisoner);
CleanHediffs(prisoner);
prisoner.playerSettings.AreaRestriction = null;
prisoner.drugs.CurrentPolicy = Current.Game.drugPolicyDatabase.DefaultDrugPolicy();
}

static public void CleanHediffs(Pawn prisoner)
Expand Down
5 changes: 3 additions & 2 deletions Source/Core/PrisonLaborUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using PrisonLabor.Core.LaborArea;
using PrisonLabor.Core.LaborWorkSettings;
using PrisonLabor.Core.Meta;
using PrisonLabor.Core.Other;
using RimWorld;
using Verse;

Expand Down Expand Up @@ -85,7 +86,7 @@ public static bool IsDisabledByLabor(IntVec3 pos, Pawn pawn, WorkTypeDef workTyp

public static bool CanWorkHere(IntVec3 pos, Pawn pawn, WorkTypeDef workType)
{
if (!pawn.IsPrisonerOfColony && pos != null && pawn.Map.areaManager.Get<Area_Labor>() != null &&
if ((!pawn.IsPrisonerOfColony || !pawn.IsSlaveOfColony) && pos != null && pawn.Map.areaManager.Get<Area_Labor>() != null &&
!WorkSettings.WorkDisabled(workType))
{
bool result = true;
Expand All @@ -95,7 +96,7 @@ public static bool CanWorkHere(IntVec3 pos, Pawn pawn, WorkTypeDef workType)
}
catch (IndexOutOfRangeException e)
{
Log.Message($"IndexOutOfRangeException for {workType.label} calling pos {pos}");
DebugLogger.debug($"{pawn.NameShortColored} cause IndexOutOfRangeException for {workType.label} calling pos {pos}");
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ private static void Postfix(Pawn_GuestTracker __instance, Faction newHost, Guest
Pawn pawn = Traverse.Create(__instance).Field("pawn").GetValue<Pawn>();
CleanPrisonersStatus.CleanHediffs(pawn);
}

if (guestStatus == GuestStatus.Prisoner)
{
Pawn pawn = Traverse.Create(__instance).Field("pawn").GetValue<Pawn>();
if (pawn.drugs == null)
{
pawn.drugs = new Pawn_DrugPolicyTracker(pawn);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,8 @@ static MethodBase TargetMethod()
}
static bool Postfix(bool __result, Pawn pawn, Thing t, bool forced)
{
if (!__result)
if (pawn.IsPrisonerOfColony)
{
if (pawn.Faction != Faction.OfPlayer && !pawn.IsPrisonerOfColony)
{
return __result;
}

WorkGiverDef workGiverDef = DefDatabase<WorkGiverDef>.GetNamed("CleanFilth");
return t is Filth filth && filth.Map.areaManager.Home[filth.Position]
&& pawn.CanReserveAndReach(t, PathEndMode.ClosestTouch, pawn.NormalMaxDanger(), 1, -1, null, forced)
Expand Down
32 changes: 32 additions & 0 deletions Source/HarmonyPatches/Patches_Work/Patch_WorkGiver_CleanSnow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using HarmonyLib;
using PrisonLabor.Core;
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.HarmonyPatches.Patches_Work
{
[HarmonyPatch(typeof(WorkGiver_ClearSnow), "HasJobOnCell")]
class Patch_WorkGiver_CleanSnow
{
static bool Postfix(bool __result, Pawn pawn, IntVec3 c, bool forced)
{
if(pawn.IsPrisonerOfColony)
{
WorkGiverDef workGiverDef = DefDatabase<WorkGiverDef>.GetNamed("CleanClearSnow");
return pawn.Map.snowGrid.GetDepth(c) >= 0.200000002980232 &&
!c.IsForbidden(pawn) &&
pawn.CanReserveAndReach(c, PathEndMode.ClosestTouch, pawn.NormalMaxDanger(), 1, -1, null, forced) &&
PrisonLaborUtility.CanWorkHere(c, pawn, workGiverDef.workType);


}
return __result;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ class Patch_RespectAllowedArea
{
static bool Postfix(bool __result, Pawn_PlayerSettings __instance)
{
Pawn pawn = Traverse.Create(__instance).Field("pawn").GetValue<Pawn>();
if (!__result && pawn != null && pawn.IsPrisonerOfColony )
if (!__result)
{
return true;
Pawn pawn = Traverse.Create(__instance).Field("pawn").GetValue<Pawn>();
if (pawn != null && pawn.IsPrisonerOfColony)
{
return true;
}
}
return __result;
}
Expand Down
1 change: 1 addition & 0 deletions Source/Organizer/NewsFeed.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<!-- [img] ... [/img] for image (inside name of file) -->
<!-- [gap] for gap -->
<patches>
<patch version="1.3.8" silent="true"/>
<patch version="1.3.7" silent="true"/>
<patch version="1.3.6" silent="true"/>
<patch version="1.3.5" silent="true"/>
Expand Down
6 changes: 3 additions & 3 deletions Source/PrisonLabor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
<Compile Include="Core\AI\JobDrivers\JobDriver_Unchain.cs" />
<Compile Include="Core\AI\JobDrivers\JobDriver_UnchainLegs.cs" />
<Compile Include="Core\AI\JobDrivers\JobDriver_UnchainHands.cs" />
<Compile Include="Core\AI\ThinkNodes\ThinkNode_IsMotivated.cs" />
<Compile Include="Core\AI\WorkGivers\WorkGivers_ManipulatePrisoner.cs" />
<Compile Include="Core\AI\WorkGivers\WorkGiver_HandleChains.cs" />
<Compile Include="Core\Alerts\Alert_EscapingPrisoners.cs" />
Expand Down Expand Up @@ -123,6 +124,7 @@
<Compile Include="Core\MainButton_Window\UIDefsOf.cs" />
<Compile Include="Core\MainButton_Window\WindowNotifier.cs" />
<Compile Include="Core\Meta\Version.cs" />
<Compile Include="Core\Needs\NeedsUtils.cs" />
<Compile Include="Core\Other\CleanPrisonersStatus.cs" />
<Compile Include="Core\Other\CustomForbidenUtil.cs" />
<Compile Include="Core\Other\DebugLogger.cs" />
Expand Down Expand Up @@ -194,6 +196,7 @@
<Compile Include="HarmonyPatches\Patches_Work\Patch_JobDriver_Mine.cs" />
<Compile Include="HarmonyPatches\Patches_Work\Patch_PlantWork.cs" />
<Compile Include="HarmonyPatches\Patches_Work\Patch_WorkGiver_CleanFilth.cs" />
<Compile Include="HarmonyPatches\Patches_Work\Patch_WorkGiver_CleanSnow.cs" />
<Compile Include="HarmonyPatches\Patches_Work\Patch_WorkGiver_Refuel.cs" />
<Compile Include="HarmonyPatches\Patches_Work\Patch_WorkGiver_RescueDowned.cs" />
<Compile Include="HarmonyPatches\Patches_Work\Patch_WorkGiver_PrisonerFaction.cs" />
Expand Down Expand Up @@ -245,9 +248,6 @@
<Compile Include="WorkUtils\ConstructionUtils.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="..\..\..\Gry\Steam\steamapps\workshop\content\294100\2506046833\1.3\Assemblies\CashRegister.dll">
<Link>CashRegister.dll</Link>
</Content>
<Content Include="..\1.3\Defs\ConceptDef.xml">
<Link>Defs\ConceptDef.xml</Link>
</Content>
Expand Down
3 changes: 3 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
Changelog:
1.3.8
- Harmony patches for clean and remove snow
- Drugs policy tracker enabled for prisoners
1.3.7
- More NPR checks in prisoners tab GUI
1.3.6
Expand Down

0 comments on commit c68fd99

Please sign in to comment.