Skip to content

Commit

Permalink
Merge pull request #225 from Aviuz/1.2.3
Browse files Browse the repository at this point in the history
1.2.3
  • Loading branch information
Hazzer authored Mar 6, 2021
2 parents 9a06581 + 8473664 commit 916cfca
Show file tree
Hide file tree
Showing 33 changed files with 547 additions and 177 deletions.
Binary file modified 1.2/Assemblies/PrisonLabor.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</li>
</modDependencies>

<description>Version 1.2.2
<description>Version 1.2.3

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
8 changes: 7 additions & 1 deletion Defs/ThinkTreeDef.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@
<li Class="JobGiver_SeekSafeTemperature"/>
</subNodes>
</li>
<li Class="ThinkNode_Priority">
<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" />
Expand Down
3 changes: 3 additions & 0 deletions Languages/English/Keyed/Keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,7 @@

<PrisonLabor_ToggleHandscuffs>Remove/put handcuffs</PrisonLabor_ToggleHandscuffs>
<PrisonLabor_ToggleLegscuffs>Remove/put legscuffs</PrisonLabor_ToggleLegscuffs>

<PrisonLabor_EnableDebugLogs>Enable Debug Logs</PrisonLabor_EnableDebugLogs>
<PrisonLabor_EnableDebugLogsDesc>Turning on this option may spam log</PrisonLabor_EnableDebugLogsDesc>
</LanguageData>
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.2-orange.svg?style=flat" alt="v1.2.2" />
<img src="https://img.shields.io/badge/version-1.2.3-orange.svg?style=flat" alt="v1.2.3" />
</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()
//NoWaterNoLife.Init();
WorkTab.Init();
Quarry.Init();
Kajin2.Init();
}
}
}
64 changes: 64 additions & 0 deletions Source/CompatibilityPatches/Kajin2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
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 Kajin2
{
private static ModSearcher modSeeker;
internal static void Init()
{
ModSearcher modSeeker = new ModSearcher("Kijin Race 2.0");
if (modSeeker.LookForMod())
{
Patch();
}
}

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

}

public static Pawn postfix_Job( Pawn __result, IntVec3 c, Map map)
{
if (__result == null)
{
foreach(Thing thing in GridsUtility.GetThingList(c, map) )
{
Pawn val = thing as Pawn;
if (val != null && !val.Dead && !val.Downed && val.IsPrisonerOfColony)
{
return val;
}
}
}
return __result;
}
private static MethodBase getTargetMethod()
{
return AccessTools.Method("Kijin2.Kijin2PlantCollectedPatch:GetFirstPawnNotDeadOrDowned");
}
}
}
8 changes: 8 additions & 0 deletions Source/Core/AI/JobGivers/JobGiver_BedTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ public override ThinkNode DeepCopy(bool resolve = true)

public override float GetPriority(Pawn pawn)
{
if (pawn.needs.rest == null)
{
return 0f;
}
if (HealthAIUtility.ShouldHaveSurgeryDoneNow(pawn))
return 15f;
if (pawn.timetable != null && pawn.timetable.CurrentAssignment == TimeAssignmentDefOf.Sleep)
Expand All @@ -28,6 +32,10 @@ public override float GetPriority(Pawn pawn)

protected override Job TryGiveJob(Pawn pawn)
{
if(pawn.needs.rest == null)
{
return null;
}
if (pawn.timetable == null || pawn.timetable.CurrentAssignment != TimeAssignmentDefOf.Sleep)
return null;
if (RestUtility.DisturbancePreventsLyingDown(pawn))
Expand Down
14 changes: 10 additions & 4 deletions Source/Core/Incidents/IncidentWorker_ResocializationOffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected override bool CanFireNowSub(IncidentParms parms)

foreach (var pawn in map.mapPawns.PrisonersOfColony)
{
if (pawn.IsColonist)
if (pawn.IsColonist || !pawn.Spawned)
continue;

var treatment = pawn.needs.TryGetNeed<Need_Treatment>();
Expand All @@ -39,7 +39,7 @@ protected override bool TryExecuteWorker(IncidentParms parms)
var affectedPawns = new List<Pawn>(map.mapPawns.PrisonersOfColony);
foreach (var pawn in map.mapPawns.PrisonersOfColony)
{
if (pawn.IsColonist)
if (pawn.IsColonist || !pawn.Spawned)
continue;

var treatment = pawn.needs.TryGetNeed<Need_Treatment>();
Expand All @@ -58,8 +58,14 @@ protected override bool TryExecuteWorker(IncidentParms parms)
return false;

Tutorials.Treatment();

SendStandardLetter(parms, prisoner, prisoner.Name.ToStringShort, prisoner.Faction.Name);
if (prisoner.Faction == null)
{
SendStandardLetter(parms, prisoner, prisoner.Name.ToStringShort);
}
else
{
SendStandardLetter(parms, prisoner, prisoner.Name.ToStringShort, prisoner.Faction.Name);
}
return true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/Incidents/IncidentWorker_Suicide.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected override bool CanFireNowSub(IncidentParms parms)

foreach (var pawn in map.mapPawns.PrisonersOfColony)
{
if (pawn.IsColonist || pawn.health.capacities.GetLevel(PawnCapacityDefOf.Manipulation) == 0f || pawn.health.capacities.GetLevel(PawnCapacityDefOf.Consciousness) == 0f)
if (pawn.IsColonist || !pawn.Spawned || pawn.health.capacities.GetLevel(PawnCapacityDefOf.Manipulation) == 0f || pawn.health.capacities.GetLevel(PawnCapacityDefOf.Consciousness) == 0f)
{
continue;
}
Expand All @@ -42,7 +42,7 @@ protected override bool TryExecuteWorker(IncidentParms parms)
var affectedPawns = new List<Pawn>(map.mapPawns.PrisonersOfColony);
foreach (var pawn in map.mapPawns.PrisonersOfColony)
{
if (pawn.IsColonist)
if (pawn.IsColonist || !pawn.Spawned || pawn.health.capacities.GetLevel(PawnCapacityDefOf.Manipulation) == 0f || pawn.health.capacities.GetLevel(PawnCapacityDefOf.Consciousness) == 0f)
continue;

var need = pawn.needs.TryGetNeed<Need_Treatment>();
Expand Down
13 changes: 13 additions & 0 deletions Source/Core/Meta/Prefs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ public static class PrisonLaborPrefs
private static readonly string prefsFilePath =
Path.Combine(GenFilePaths.ConfigFolderPath, "PrisonLabor_Prefs.xml");

public static bool DebugLogs
{
get
{
return data.enable_debug_logging;
}
set
{
data.enable_debug_logging = value;
Apply();
}
}
public static Version Version
{
get { return data.version; }
Expand Down Expand Up @@ -209,6 +221,7 @@ public static void RestoreToDefault()
data.version = version;
data.last_version = last_version;
data.tutorials_flags = tutorials;
data.enable_debug_logging = false;

Apply();
}
Expand Down
1 change: 1 addition & 0 deletions Source/Core/Meta/PrefsData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class PrisonLaborPrefsData
public bool show_treatment_happiness = false;
public bool enable_suicide = true;
public bool enable_full_heal_rest = true;
public bool enable_debug_logging = false;

public Version last_version = Version.v0_0;
public bool show_news = true;
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 @@ -64,6 +64,7 @@ public enum Version
v1_1_11,
v1_2_0,
v1_2_1,
v1_2_2
v1_2_2,
v1_2_3
}
}
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_2;
public const string versionString = "1.2.2";
public const Version versionNumber = Version.v1_2_3;
public const string versionString = "1.2.3";

public static Version VersionOfSaveFile { get; set; }

Expand Down
6 changes: 5 additions & 1 deletion Source/Core/Needs/Need_Motivation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ private float GetChangePoints()
value -= BGP.Laziness_LazyRate;
if (HealthAIUtility.ShouldSeekMedicalRest(pawn))
value -= BGP.Laziness_HealthRate;
value -= (int)pawn.needs.food.CurCategory * BGP.Laziness_HungryRate;
if (pawn.needs.food != null)
{
//warforged
value -= (int)pawn.needs.food.CurCategory * BGP.Laziness_HungryRate;
}
// Some pawns have no rest need (e.g. Pawns with Circadian Half Cycler or androids from other mods)
if (pawn.needs.rest != null)
{
Expand Down
27 changes: 15 additions & 12 deletions Source/Core/Needs/Need_Treatment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,21 @@ public override void NeedInterval()
CurLevel += BGP.JoyRate;

// Status
var hunger = pawn.needs.TryGetNeed<Need_Food>();

int statusScore = 0;
if (hunger.CurCategory < HungerCategory.UrgentlyHungry)
statusScore += 5;
if (hunger.CurCategory < HungerCategory.Hungry)
statusScore += 5;
statusScore -= (int)pawn.health.hediffSet.PainTotal / 10;
if (pawn.health.HasHediffsNeedingTend())
statusScore -= 7;

CurLevel += statusScore * BGP.StatusMultiplier;
if (pawn.needs.food != null)
{
var hunger = pawn.needs.TryGetNeed<Need_Food>();

int statusScore = 0;
if (hunger.CurCategory < HungerCategory.UrgentlyHungry)
statusScore += 5;
if (hunger.CurCategory < HungerCategory.Hungry)
statusScore += 5;
statusScore -= (int)pawn.health.hediffSet.PainTotal / 10;
if (pawn.health.HasHediffsNeedingTend())
statusScore -= 7;

CurLevel += statusScore * BGP.StatusMultiplier;
}


// Labor
Expand Down
31 changes: 31 additions & 0 deletions Source/Core/Other/CleanPrisonersStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using PrisonLabor.Constants;
using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Verse;

namespace PrisonLabor.Core.Other
{
public static class CleanPrisonersStatus
{

static public void Clean(Pawn prisoner)
{
prisoner.workSettings = new Pawn_WorkSettings(prisoner);
Hediff legs = prisoner.health.hediffSet.GetFirstHediffOfDef(PL_DefOf.PrisonLabor_RemovedLegscuffs, false);
if (legs != null)
{
prisoner.health.hediffSet.hediffs.Remove(legs);
}
Hediff hands = prisoner.health.hediffSet.GetFirstHediffOfDef(PL_DefOf.PrisonLabor_RemovedHandscuffs, false);
if (hands != null)
{
prisoner.health.hediffSet.hediffs.Remove(hands);
}
prisoner.playerSettings.AreaRestriction = null;
}
}
}
Loading

0 comments on commit 916cfca

Please sign in to comment.