Skip to content

Commit

Permalink
Merge pull request #196 from Aviuz/fixes-tweakses
Browse files Browse the repository at this point in the history
Version 1.1.10
  • Loading branch information
Hazzer authored Jul 6, 2020
2 parents 7fde629 + 7808786 commit 35db4b4
Show file tree
Hide file tree
Showing 19 changed files with 347 additions and 36 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.9
<description>Version 1.1.10

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.
3 changes: 3 additions & 0 deletions Languages/English/Keyed/Keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,7 @@

<PrisonLabor_EnableSuicide>Enable prisoner suicide</PrisonLabor_EnableSuicide>
<PrisonLabor_EnableSuicideDesc>Enables suicide of prisoners when they aren't very happy</PrisonLabor_EnableSuicideDesc>

<PrisonLabor_EnableFullHealRest>Enable prisoner full heal rest</PrisonLabor_EnableFullHealRest>
<PrisonLabor_EnableFullHealRestDesc>Prisoner will stay in bed until fully healed</PrisonLabor_EnableFullHealRestDesc>
</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.1.9-orange.svg?style=flat" alt="v1.1.9" />
<img src="https://img.shields.io/badge/version-1.1.10-orange.svg?style=flat" alt="v1.1.10" />
</a>
</p>

Expand Down
7 changes: 6 additions & 1 deletion Source/Core/AI/JobGivers/JobGiver_Labor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,13 @@ public override ThinkResult TryIssueJobPackage(Pawn pawn, JobIssueParams jobPara

if (pawn.timetable == null)
WorkSettings.InitWorkSettings(pawn);
if (HealthAIUtility.ShouldHaveSurgeryDoneNow(pawn) || HealthAIUtility.ShouldBeTendedNowByPlayer(pawn) || HealthAIUtility.ShouldSeekMedicalRest(pawn))
if (HealthAIUtility.ShouldHaveSurgeryDoneNow(pawn))
return ThinkResult.NoJob;

if(PrisonLaborPrefs.EnableFullHealRest && (HealthAIUtility.ShouldBeTendedNowByPlayer(pawn) || HealthAIUtility.ShouldSeekMedicalRest(pawn)))
{
return ThinkResult.NoJob;
}
//Check medical assistance, fed, and rest if not override
if (!PrisonLaborUtility.WorkTime(pawn))
{
Expand Down
11 changes: 11 additions & 0 deletions Source/Core/Meta/Prefs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,17 @@ public static string AllowedWorkTypes
}
}

public static bool EnableFullHealRest
{
get { return data.enable_full_heal_rest; }

set
{
data.enable_full_heal_rest = value;
Apply();
}
}

public static void Init()
{
var flag = !new FileInfo(prefsFilePath).Exists;
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 @@ -14,6 +14,7 @@ public class PrisonLaborPrefsData
public bool enable_revolts = true;
public bool show_treatment_happiness = false;
public bool enable_suicide = true;
public bool enable_full_heal_rest = true;

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 @@ -59,6 +59,7 @@ public enum Version
v1_1_6,
v1_1_7,
v1_1_8,
v1_1_9
v1_1_9,
v1_1_10
}
}
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_9;
public const string versionString = "1.1.9";
public const Version versionNumber = Version.v1_1_10;
public const string versionString = "1.1.10";

public static Version VersionOfSaveFile { get; set; }

Expand Down
7 changes: 7 additions & 0 deletions Source/Core/Settings/SettingsMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ internal class SettingsMenu : Mod
private static bool enableRevolts;
private static bool showTreatmentHappiness;
private static bool enableSuicide;
private static bool enableFullHealRest;
private static bool advancedGrowing;
private static int defaultInteractionMode;

Expand All @@ -38,6 +39,7 @@ public static void Init()
enableRevolts = PrisonLaborPrefs.EnableRevolts;
enableSuicide = PrisonLaborPrefs.EnableSuicide;
showTreatmentHappiness = PrisonLaborPrefs.ShowTreatmentHappiness;
enableFullHealRest = PrisonLaborPrefs.EnableFullHealRest;

interactionModeList = new List<PrisonerInteractionModeDef>(DefDatabase<PrisonerInteractionModeDef>.AllDefs);
defaultInteractionMode = interactionModeList.IndexOf(DefDatabase<PrisonerInteractionModeDef>.GetNamed(PrisonLaborPrefs.DefaultInteractionMode));
Expand Down Expand Up @@ -102,6 +104,10 @@ public override void DoSettingsWindowContents(Rect inRect)
listing_options.CheckboxLabeled("PrisonLabor_EnableSuicide".Translate(), ref enableSuicide,
"PrisonLabor_EnableSuicideDesc".Translate());

listing_options.CheckboxLabeled("PrisonLabor_EnableFullHealRest".Translate(), ref enableFullHealRest,
"PrisonLabor_EnableFullHealRestDesc".Translate());


listing_options.GapLine();

listing_options.CheckboxLabeled("PrisonLabor_ShowTreatmentHappiness".Translate(), ref showTreatmentHappiness,
Expand Down Expand Up @@ -169,6 +175,7 @@ public override void WriteSettings()
PrisonLaborPrefs.ShowTreatmentHappiness = showTreatmentHappiness;
PrisonLaborPrefs.AdvancedGrowing = advancedGrowing;
PrisonLaborPrefs.EnableSuicide = enableSuicide;
PrisonLaborPrefs.EnableFullHealRest = enableFullHealRest;
PrisonLaborPrefs.DefaultInteractionMode = interactionModeList[defaultInteractionMode].defName;
PrisonLaborPrefs.Save();
Log.Message("Prison Labor settings saved");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using HarmonyLib;
using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Instrumentation;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Verse;

namespace PrisonLabor.HarmonyPatches.Patches_Construction
{
[HarmonyPatch(typeof(Blueprint), "TryReplaceWithSolidThing")]
class Patch_BlueprintsForPlayerFaction
{

public static void Postfix(Pawn workerPawn, Thing createdThing, bool __result)
{

if (__result && createdThing != null && createdThing.def.CanHaveFaction && workerPawn.IsPrisonerOfColony)
{
#if DEBUG
Log.Message($"Setting faction for: {createdThing}");
#endif
createdThing.SetFactionDirect(Faction.OfPlayer);
}

}

}
}
33 changes: 33 additions & 0 deletions Source/HarmonyPatches/Patches_Construction/Patch_Smoothing.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using HarmonyLib;
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.HarmonyPatches.Patches_Construction
{
[HarmonyPatch()]
class Patch_Smoothing
{
static IEnumerable<MethodBase> TargetMethods()
{
yield return (MethodBase)typeof(WorkGiver_ConstructSmoothWall).GetMethod("HasJobOnCell");
yield return (MethodBase)typeof(WorkGiver_ConstructAffectFloor).GetMethod("HasJobOnCell");
}

public static bool Postfix(bool __result, Pawn pawn, IntVec3 c)
{
if(__result && pawn.IsPrisonerOfColony)
{
return pawn.CanReach(c, PathEndMode.Touch, pawn.NormalMaxDanger());
}

return __result;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using HarmonyLib;
using PrisonLabor.WorkUtils;
using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;
using Verse;
using Verse.AI;

namespace PrisonLabor.HarmonyPatches.Patches_Construction
{
[HarmonyPatch(typeof(WorkGiver_ConstructDeliverResourcesToFrames))]
[HarmonyPatch("JobOnThing")]
[HarmonyPatch(new[] { typeof(Pawn), typeof(Thing), typeof(bool) })]
class Patch_WorkGiver_ConstructDeliverResourcesToFrames
{
static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{

OpCode[] opCodes1 =
{
OpCodes.Ldarg_2,
OpCodes.Callvirt,
OpCodes.Ldarg_1,
OpCodes.Callvirt,
OpCodes.Beq_S,
};
string[] operands1 =
{
"",
"RimWorld.Faction get_Faction()",
"",
"RimWorld.Faction get_Faction()",
"System.Reflection.Emit.Label",
};


var label = HPatcher.FindOperandAfter(opCodes1, operands1, instructions, true);

//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.Brtrue, label);

foreach (var instr in instructions)
{
yield return instr;
}

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using HarmonyLib;
using PrisonLabor.WorkUtils;
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_Construction
{
[HarmonyPatch(typeof(WorkGiver_Repair))]
class Patch_WorkGiver_Repair
{
[HarmonyPrefix]
[HarmonyPatch("ShouldSkip")]
[HarmonyPatch(new[] { typeof(Pawn), typeof(bool) })]
static bool ShouldSKipPrefix(ref bool __result, Pawn pawn, bool forced)
{
if(pawn.IsPrisonerOfColony)
{
__result = pawn.Map.listerBuildingsRepairable.RepairableBuildings(Faction.OfPlayer).Count == 0;
return false;
}
return true;

}

[HarmonyPrefix]
[HarmonyPatch("PotentialWorkThingsGlobal")]
[HarmonyPatch(new[] { typeof(Pawn) })]
static bool PotentialWorkThingsGlobalPrefix(ref IEnumerable<Thing> __result, Pawn pawn)
{
if (pawn.IsPrisonerOfColony)
{
__result = pawn.Map.listerBuildingsRepairable.RepairableBuildings(Faction.OfPlayer);
return false;
}
return true;

}


[HarmonyPrefix]
[HarmonyPatch("HasJobOnThing")]
[HarmonyPatch(new[] { typeof(Pawn), typeof(Thing), typeof(bool) })]
static bool HasJobOnThingPrefix(ref bool __result, Pawn pawn,Thing t, bool forced)
{
if (pawn.IsPrisonerOfColony)
{
__result = ConstructionUtils.HasJobOnThingFixed(pawn, t, forced);
return false;
}
return true;

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using HarmonyLib;
using PrisonLabor.WorkUtils;
using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;
using Verse;
using Verse.AI;

namespace PrisonLabor.HarmonyPatches.Patches_Construction
{
[HarmonyPatch(typeof(WorkGiver_ConstructDeliverResourcesToBlueprints))]
[HarmonyPatch("JobOnThing")]
[HarmonyPatch(new[] { typeof(Pawn), typeof(Thing), typeof(bool) })]
class Patch_WorkGiver_ConstructDeliverResourcesToBlueprints
{
static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{

OpCode[] opCodes1 =
{
OpCodes.Ldarg_2,
OpCodes.Callvirt,
OpCodes.Ldarg_1,
OpCodes.Callvirt,
OpCodes.Beq_S,
};
string[] operands1 =
{
"",
"RimWorld.Faction get_Faction()",
"",
"RimWorld.Faction get_Faction()",
"System.Reflection.Emit.Label",
};


var label = HPatcher.FindOperandAfter(opCodes1, operands1, instructions, true);

//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.Brtrue, label);

foreach (var instr in instructions)
{
yield return instr;
}

}
}
}

This file was deleted.

Loading

0 comments on commit 35db4b4

Please sign in to comment.