Skip to content

Commit

Permalink
Merge pull request #228 from Aviuz/1.2.4
Browse files Browse the repository at this point in the history
1.2.4
  • Loading branch information
Hazzer authored May 31, 2021
2 parents 916cfca + a0b52de commit 860d416
Show file tree
Hide file tree
Showing 13 changed files with 182 additions and 17 deletions.
Binary file modified 1.2/Assemblies/PrisonLabor.dll
Binary file not shown.
38 changes: 38 additions & 0 deletions 1.2/Patches/Designators.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8" ?>
<Patch>
<Operation Class="PatchOperationSequence">
<success>Always</success>
<operations>
<li Class="PatchOperationSequence">
<success>Always</success>
<operations>
<li Class="PatchOperationTest">
<xpath>/Defs/DesignationCategoryDef[defName = "Zone"]/specialDesignatorClasses[li = "PrisonLabor.Core.LaborArea.Designator_AreaLaborExpand"]</xpath>
<success>Invert</success>
</li>
<li Class="PatchOperationAdd">
<xpath>/Defs/DesignationCategoryDef[defName = "Zone"]/specialDesignatorClasses</xpath>
<value>
<li>PrisonLabor.Core.LaborArea.Designator_AreaLaborExpand</li>
</value>
</li>
</operations>
</li>
<li Class="PatchOperationSequence">
<success>Always</success>
<operations>
<li Class="PatchOperationTest">
<xpath>/Defs/DesignationCategoryDef[defName = "Zone"]/specialDesignatorClasses[li = "PrisonLabor.Core.LaborArea.Designator_AreaLaborClear"]</xpath>
<success>Invert</success>
</li>
<li Class="PatchOperationAdd">
<xpath>/Defs/DesignationCategoryDef[defName = "Zone"]/specialDesignatorClasses</xpath>
<value>
<li>PrisonLabor.Core.LaborArea.Designator_AreaLaborClear</li>
</value>
</li>
</operations>
</li>
</operations>
</Operation>
</Patch>
4 changes: 2 additions & 2 deletions About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<supportedVersions>
<li>1.0</li>
<li>1.1</li>
<li>1.2</li>
<li>1.2</li>
</supportedVersions>
<packageId>avius.prisonlabor</packageId>
<incompatibleWith>
Expand All @@ -23,7 +23,7 @@
</li>
</modDependencies>

<description>Version 1.2.3
<description>Version 1.2.4

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

Expand Down
8 changes: 0 additions & 8 deletions Source/Core/LaborArea/Designator_AreaLabor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,5 @@ public override void SelectedUpdate()
Map.areaManager.AllAreas.Add(new Area_Labor(Map.areaManager));
Map.areaManager.Get<Area_Labor>().MarkForDraw();
}

public static void Initialization()
{
DefDatabase<DesignationCategoryDef>.GetNamed("Zone").AllResolvedDesignators
.Add(new Designator_AreaLaborExpand());
DefDatabase<DesignationCategoryDef>.GetNamed("Zone").AllResolvedDesignators
.Add(new Designator_AreaLaborClear());
}
}
}
3 changes: 2 additions & 1 deletion Source/Core/Meta/Version.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public enum Version
v1_2_0,
v1_2_1,
v1_2_2,
v1_2_3
v1_2_3,
v1_2_4
}
}
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_2_3;
public const string versionString = "1.2.3";
public const Version versionNumber = Version.v1_2_4;
public const string versionString = "1.2.4";

public static Version VersionOfSaveFile { get; set; }

Expand Down
14 changes: 12 additions & 2 deletions Source/Core/PrisonLaborUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,25 @@ public static bool WorkTime(Pawn pawn)
{
if (HealthAIUtility.ShouldSeekMedicalRest(pawn) ||
pawn.health.hediffSet.HasTemperatureInjury(TemperatureInjuryStage.Serious) ||
pawn.needs.food.CurCategory > HungerCategory.Hungry ||
pawn.needs.rest.CurCategory != RestCategory.Rested)
CheckFoodNeed(pawn) ||
CheckRestNeed(pawn))
return false;
else
return true;
}
return false;
}

private static bool CheckFoodNeed(Pawn pawn)
{
return pawn.needs != null && pawn.needs.food != null && pawn.needs.food.CurCategory > HungerCategory.Hungry;
}

private static bool CheckRestNeed(Pawn pawn)
{
return pawn.needs != null && pawn.needs.rest != null && pawn.needs.rest.CurCategory != RestCategory.Rested;
}

public static bool IsDisabledByLabor(IntVec3 pos, Pawn pawn, WorkTypeDef workType)
{
if (pos != null && pawn.Map.areaManager.Get<Area_Labor>() != null &&
Expand Down
31 changes: 31 additions & 0 deletions Source/HarmonyPatches/Patches_Food/GetFoodRestrictionPatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using HarmonyLib;
using PrisonLabor.Core.Needs;
using PrisonLabor.Core.Trackers;
using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Verse;

namespace PrisonLabor.HarmonyPatches.Patches_Food
{
[HarmonyPatch(typeof(Pawn_FoodRestrictionTracker))]
[HarmonyPatch(nameof(Pawn_FoodRestrictionTracker.GetCurrentRespectedRestriction))]
class GetFoodRestrictionPatch
{
static FoodRestriction Postfix(FoodRestriction __result, Pawn_FoodRestrictionTracker __instance, Pawn getter)
{
if(__result == null && __instance.pawn.IsPrisonerOfColony && !__instance.pawn.InMentalState)
{
Need_Motivation motivation = __instance.pawn.needs.TryGetNeed<Need_Motivation>();
if(motivation != null && (motivation.CurLevel > 0.7 || __instance.pawn.IsWatched() ))
{
return __instance.CurrentFoodRestriction;
}
}
return __result;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using HarmonyLib;
using PrisonLabor.Core.Other;
using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;
using Verse;
using Verse.AI;

namespace PrisonLabor.HarmonyPatches.Patches_Work
{
[HarmonyPatch(typeof(WorkGiver_OperateScanner))]
class Patch_WorkGiver_OperateScanner
{
[HarmonyPatch("ShouldSkip")]
[HarmonyPostfix]
static bool ShouldSkipPostfix(bool __result, WorkGiver_OperateScanner __instance, Pawn pawn, bool forced)
{
if (__result && pawn.IsPrisonerOfColony)
{
return CanOperate(pawn, __instance);
}
return __result;
}

private static bool CanOperate(Pawn pawn, WorkGiver_OperateScanner __instance)
{
List<Thing> list = pawn.Map.listerThings.ThingsOfDef(__instance.ScannerDef);
for (int i = 0; i < list.Count; i++)
{
if (list[i].Faction == Faction.OfPlayer)
{
CompScanner compScanner = list[i].TryGetComp<CompScanner>();
if (compScanner != null && compScanner.CanUseNow)
{
return false;
}
}
}
return true;
}

[HarmonyPatch("HasJobOnThing")]
[HarmonyPostfix]
static bool HasJobOnThingPostfix(bool __result, Pawn pawn, Thing t, bool forced)
{
if(!__result && pawn.IsPrisonerOfColony)
{
if(t.Faction != Faction.OfPlayer)
{
return false;
}
Building building = t as Building;
if (building == null)
{
return false;
}
if (building.IsForbidden(pawn))
{
return false;
}
if (!pawn.CanReserve(building, 1, -1, null, forced))
{
return false;
}
if (!building.TryGetComp<CompScanner>().CanUseNow)
{
return false;
}
if (building.IsBurning())
{
return false;
}
return true;
}
return __result;
}
}
}
1 change: 0 additions & 1 deletion Source/Initialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ static Initialization()
ClassInjector.Init();
SettingsMenu.Init();
VersionUtility.CheckVersion();
Designator_AreaLabor.Initialization();
CompatibilityPatches.Initialization.Run();
HediffManager.Init();

Expand Down
8 changes: 8 additions & 0 deletions Source/Organizer/NewsFeed.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
<!-- [img] ... [/img] for image (inside name of file) -->
<!-- [gap] for gap -->
<patches>
<patch version="1.2.4">
<title>Prison Labor v 1.2.4</title>
<items>
<item>[-]Changed adding designer for prisoner labor zone to more "common" way. It may fix missing designators as mod incompatibility</item>
<item>[-]Prisoners should respect their food restriction when motivation is more than 75%, or they are watched</item>
<item>[-]Prisoners should use ground penetration and long scanners</item>
</items>
</patch>
<patch version="1.0.3" silent="true"/>
<patch version="1.0.2" silent="true"/>
<patch version="1.0.1" silent="true"/>
Expand Down
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
Changelog:
1.2.4
- Changed adding designer for prisoner labor zone to more "common" way. It may fix missing designators as mod incompatibility
- Prisoners should respects their food restriction when motivation is more than 75% or they are watched
- Prisoners should use ground penetration and long scanners
1.2.3
- Fixing issue with faction set (animal and recruiting) from 1.2.1 and 1.2.2
- Prisoners without food and/or sleep needs should work normally
Expand Down

0 comments on commit 860d416

Please sign in to comment.