Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Aviuz committed Jul 25, 2017
2 parents 6e66659 + 6f170d3 commit aff9e7d
Show file tree
Hide file tree
Showing 33 changed files with 1,025 additions and 408 deletions.
2 changes: 1 addition & 1 deletion About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<name>Prison Labor (Alpha)</name>
<author>Avius</author>
<targetVersion>0.17.0</targetVersion>
<description>Version 0.6
<description>Version 0.7

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. Revolts are not available yet.
Expand Down
Binary file modified Assemblies/PrisonLabor.dll
Binary file not shown.
12 changes: 12 additions & 0 deletions Defs/WorkGiverDef.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,16 @@
<li>Manipulation</li>
</requiredCapacities>
</WorkGiverDef>
<WorkGiverDef>
<defName>PrisonLabor_CleanFilth_Tweak</defName>
<label>clean filth</label>
<giverClass>PrisonLabor.WorkGiver_CleanFilth_Tweak</giverClass>
<workType>Cleaning</workType>
<priorityInType>6</priorityInType>
<verb>clean</verb>
<gerund>cleaning</gerund>
<requiredCapacities>
<li>Manipulation</li>
</requiredCapacities>
</WorkGiverDef>
</WorkGivers>
19 changes: 5 additions & 14 deletions 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-0.6-orange.svg?style=flat" alt="v0.6" />
<img src="https://img.shields.io/badge/version-0.7-orange.svg?style=flat" alt="v0.7" />
</a>
</p>

Expand All @@ -24,22 +24,13 @@ This is early alpha version! Some features can be changed, and there are many th

## Compatibility
* Works with mods that add Jobs of type cook/mine/craft/haul/clean like Quarry, or Haulers Can Haul To Blueprints
Works with saves.
* You can enable, re-enable, disable this mod to all saves. (However disabling mod can throw errors, but they just saying they can't find tutorials, no harm)
* No collisions with other mods detected yet. Only mods that changes thinking of humanlike should be considered (Humanlike_PostDuty handle).
* Works with old saves.
* Disabling this mod to saves causes prisoners to disappear. In 0.7 I've planned tool to safely disable this mod.
* Now works with WorkTab (by Fluffy)
* There are some collisions that causes prisoners to fail to reserve target of their jobs. They will work on same thing or stealing resources from benches. If you experiencing this issue please le me know what mods are you using. I need to identify which mod causes that.

## [To-do list](https://github.com/Aviuz/PrisonLabor/projects/1)

## Currently to make prisoners work you must meet these conditions
* Prisoner is safe, and don't need medical assistance.
* Prisoner don't need to recover from injury/sickness in bed.
* Prisoner can't escape.
* Prisoner can reach work (best way to do that is leaving open doors to work area).
* Prisoner is fed, and rested.
* Prisoner interaction is set to "Force to work" (no "Chat and Recruit", or "Friendly Chat").
* Laziness bar in "Needs" tab is below 80%.
* Work type is enabled in "Work" tab.

## Translations
Please contact me if you want help me writing translations. It will take you a few minutes to translate few sentences, and you will help making the mod even better. Thank you in advance!
Also I would gladly hear about misspellings or grammar mistakes in English version.
Expand Down
57 changes: 57 additions & 0 deletions Source/Alert_LazyPrisoners.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Verse;

namespace PrisonLabor
{
class Alert_LazyPrisoners : Alert
{
public Alert_LazyPrisoners()
{
this.defaultLabel = "Prisoners aren't working";
this.defaultExplanation = "Work in progress";
}

private IEnumerable<Pawn> LazyPrisoners
{
get
{
List<Map> maps = Find.Maps;
for (int i = 0; i < maps.Count; i++)
{
foreach (Pawn pawn in maps[i].mapPawns.AllPawns)
{
if (PrisonLaborUtility.LaborEnabled(pawn) && PrisonLaborUtility.WorkTime(pawn) && pawn.needs.TryGetNeed<Need_Motivation>().IsLazy)
yield return pawn;
}
}
}
}

public override string GetExplanation()
{
StringBuilder stringBuilder = new StringBuilder();
foreach (Pawn current in LazyPrisoners)
{
stringBuilder.AppendLine(" " + current.NameStringShort);
}
return string.Format("Those prisoners are lazy:\n\n{0}\nTry to motivate them.", stringBuilder.ToString());
}

public override AlertReport GetReport()
{
if (PrisonLaborPrefs.EnableMotivationMechanics)
{
return AlertReport.CulpritIs(LazyPrisoners.FirstOrDefault());
}
else
{
return false;
}
}

}
}
56 changes: 56 additions & 0 deletions Source/Alert_StarvingPrisoners.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Verse;

namespace PrisonLabor
{
class Alert_StarvingPrisoners : Alert
{
public Alert_StarvingPrisoners()
{
this.defaultLabel = "Prisoners are starving";
this.defaultExplanation = "Work in progress";
}

private IEnumerable<Pawn> StarvingPrisoners
{
get
{
List<Map> maps = Find.Maps;
for (int i = 0; i < maps.Count; i++)
{
foreach (Pawn pawn in maps[i].mapPawns.AllPawns)
{
if (PrisonLaborUtility.LaborEnabled(pawn) && PrisonLaborUtility.WorkTime(pawn) && (!PrisonLaborPrefs.EnableMotivationMechanics || !pawn.needs.TryGetNeed<Need_Motivation>().IsLazy) && pawn.timetable != null && pawn.timetable.CurrentAssignment == TimeAssignmentDefOf.Anything && pawn.needs.food.Starving)
yield return pawn;
}
}
}
}

public override string GetExplanation()
{
StringBuilder stringBuilder = new StringBuilder();
foreach (Pawn current in StarvingPrisoners)
{
stringBuilder.AppendLine(" " + current.NameStringShort);
}
return string.Format("Those prisoners are starving and won't work:\n\n{0}", stringBuilder.ToString());
}

public override AlertReport GetReport()
{
if (!PrisonLaborPrefs.DisableMod)
{
return AlertReport.CulpritIs(StarvingPrisoners.FirstOrDefault());
}
else
{
return false;
}
}
}
}
40 changes: 35 additions & 5 deletions Source/HarmonyPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public static bool ShouldHaveNeedPrisoner(NeedDef nd, Pawn pawn)
//delete later
if (nd.defName == "PrisonLabor_Laziness" || nd is Need_Laziness)
return false;
if (nd.defName == "PrisonLabor_Motivation" && !pawn.IsPrisoner)
if (nd.defName == "PrisonLabor_Motivation" && !(pawn.IsPrisoner && PrisonLaborPrefs.EnableMotivationMechanics))
{
return false;
}
Expand Down Expand Up @@ -210,9 +210,9 @@ public static IEnumerable<Pawn> Pawns(MainTabWindow mainTabWindow)
if (mainTabWindow is MainTabWindow_Work || mainTabWindow is MainTabWindow_Restrict || mainTabWindow.GetType().ToString().Contains("MainTabWindow_WorkTab"))
{
foreach (Pawn pawn in Find.VisibleMap.mapPawns.PrisonersOfColony)
if (pawn.guest.interactionMode == DefDatabase<PrisonerInteractionModeDef>.GetNamed("PrisonLabor_workOption"))
if (PrisonLaborUtility.LaborEnabled(pawn))
{
WorkAssignmentsUtility.initWorkSettings(pawn);
PrisonLaborUtility.InitWorkSettings(pawn);
yield return pawn;
}
}
Expand All @@ -230,7 +230,7 @@ static IEnumerable<CodeInstruction> Transpiler(ILGenerator gen, MethodBase mBase
Label jumpTo = gen.DefineLabel();
yield return new CodeInstruction(OpCodes.Ldarg_2);
yield return new CodeInstruction(OpCodes.Ldarg_3);
yield return new CodeInstruction(OpCodes.Call, typeof(WorkAssignmentsUtility).GetMethod("Disabled", new Type[] { typeof(Pawn), typeof(WorkTypeDef) }));
yield return new CodeInstruction(OpCodes.Call, typeof(PrisonLaborUtility).GetMethod("WorkDisabled", new Type[] { typeof(Pawn), typeof(WorkTypeDef) }));
//If false continue
yield return new CodeInstruction(OpCodes.Brfalse, jumpTo);
//Return
Expand Down Expand Up @@ -260,7 +260,7 @@ static IEnumerable<CodeInstruction> Transpiler(ILGenerator gen, MethodBase mBase
Label jumpTo = gen.DefineLabel();
yield return new CodeInstruction(OpCodes.Ldarg_0);
yield return new CodeInstruction(OpCodes.Ldarg_1);
yield return new CodeInstruction(OpCodes.Call, typeof(WorkAssignmentsUtility).GetMethod("Disabled", new Type[] { typeof(Pawn), typeof(WorkTypeDef) }));
yield return new CodeInstruction(OpCodes.Call, typeof(PrisonLaborUtility).GetMethod("WorkDisabled", new Type[] { typeof(Pawn), typeof(WorkTypeDef) }));
//If false continue
yield return new CodeInstruction(OpCodes.Brfalse, jumpTo);
//Load string TODO translate
Expand Down Expand Up @@ -330,4 +330,34 @@ public static bool isPrisoner(Pawn pawn)
return false;
}
}

[HarmonyPatch(typeof(ForbidUtility))]
[HarmonyPatch("IsForbidden")]
[HarmonyPatch(new Type[] { typeof(Thing), typeof(Pawn) })]
class FoodReservingPatch
{
private static IEnumerable<CodeInstruction> Transpiler(ILGenerator gen, MethodBase mBase, IEnumerable<CodeInstruction> instr)
{
Label jumpTo = gen.DefineLabel();
yield return new CodeInstruction(OpCodes.Ldarg_0);
yield return new CodeInstruction(OpCodes.Call, typeof(PrisonerFoodReservation).GetMethod("isReserved"));
yield return new CodeInstruction(OpCodes.Brfalse, jumpTo);
yield return new CodeInstruction(OpCodes.Ldarg_1);
yield return new CodeInstruction(OpCodes.Call, typeof(Pawn).GetMethod("get_IsPrisoner"));
yield return new CodeInstruction(OpCodes.Brtrue, jumpTo);
yield return new CodeInstruction(OpCodes.Ldc_I4_1);
yield return new CodeInstruction(OpCodes.Ret);

bool first = true;
foreach (CodeInstruction ci in instr)
{
if (first)
{
first = false;
ci.labels.Add(jumpTo);
}
yield return ci;
}
}
}
}
104 changes: 0 additions & 104 deletions Source/InfoDialog.cs

This file was deleted.

Loading

0 comments on commit aff9e7d

Please sign in to comment.