Skip to content

Commit

Permalink
Version 0.7
Browse files Browse the repository at this point in the history
- fixed "failing to reserve food" bug (that one with circling warden around food)
- prisoners now stop working (while "anything" time) while starving instead of hungry. They will still get minor debuff
- wardens will no longer watch over not working prisoners
- prisoners will no longer work if waiting for operation
- fixed bug preventing prisoners from cleaning
- added "starving prisoners" alert
- added settings
- changed "Your prisoner stopped working" message to "Prisoners aren't working" alert
  • Loading branch information
Aviuz committed Jul 25, 2017
1 parent 50588ec commit 6f170d3
Show file tree
Hide file tree
Showing 23 changed files with 603 additions and 139 deletions.
Binary file modified Assemblies/PrisonLabor.dll
Binary file not shown.
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
9 changes: 8 additions & 1 deletion Source/Alert_LazyPrisoners.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,14 @@ public override string GetExplanation()

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

}
Expand Down
11 changes: 9 additions & 2 deletions Source/Alert_StarvingPrisoners.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private IEnumerable<Pawn> StarvingPrisoners
{
foreach (Pawn pawn in maps[i].mapPawns.AllPawns)
{
if (PrisonLaborUtility.LaborEnabled(pawn) && PrisonLaborUtility.WorkTime(pawn) && !pawn.needs.TryGetNeed<Need_Motivation>().IsLazy && pawn.timetable != null && pawn.timetable.CurrentAssignment == TimeAssignmentDefOf.Anything && pawn.needs.food.Starving)
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;
}
}
Expand All @@ -43,7 +43,14 @@ public override string GetExplanation()

public override AlertReport GetReport()
{
return AlertReport.CulpritIs(StarvingPrisoners.FirstOrDefault());
if (!PrisonLaborPrefs.DisableMod)
{
return AlertReport.CulpritIs(StarvingPrisoners.FirstOrDefault());
}
else
{
return false;
}
}
}
}
32 changes: 31 additions & 1 deletion 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 @@ -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;
}
}
}
}
11 changes: 8 additions & 3 deletions Source/Initialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace PrisonLabor
[StaticConstructorOnStartup]
class Initialization
{
public static int version = 6;
public static int version = PrisonLaborMod.versionNumber;

static Initialization()
{
Expand Down Expand Up @@ -47,12 +47,17 @@ private static void checkVersion()
if (PrisonLaborPrefs.LastVersion < 5)
{
Log.Message("Detected older version of PrisonLabor than 0.5");
Tutorials.msgShowVersion0_5 = true;
NewsDialog.news_0_5 = true;
}
if (PrisonLaborPrefs.LastVersion < 6)
{
Log.Message("Detected older version of PrisonLabor than 0.6");
Tutorials.msgShowVersion0_6 = true;
NewsDialog.news_0_6 = true;
}
if (PrisonLaborPrefs.LastVersion < 7)
{
Log.Message("Detected older version of PrisonLabor than 0.7");
NewsDialog.news_0_7 = true;
}

Log.Message("Loaded PrisonLabor v" + PrisonLaborPrefs.Version);
Expand Down
3 changes: 2 additions & 1 deletion Source/JobGiver_Diet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ protected override Job TryGiveJob(Pawn pawn)
{
return null;
}
pawn.needs.TryGetNeed<Need_Motivation>().Enabled = false;
if(pawn.needs.TryGetNeed<Need_Motivation>() != null)
pawn.needs.TryGetNeed<Need_Motivation>().Enabled = false;
bool flag;
if (pawn.RaceProps.Animal)
{
Expand Down
20 changes: 12 additions & 8 deletions Source/JobGiver_Labor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,32 @@ public override float GetPriority(Pawn pawn)

public override ThinkResult TryIssueJobPackage(Pawn pawn, JobIssueParams jobParams)
{
if(pawn.timetable == null)
if (pawn.timetable == null)
{
PrisonLaborUtility.InitWorkSettings(pawn);
}
if(HealthAIUtility.ShouldHaveSurgeryDoneNow(pawn))
if (HealthAIUtility.ShouldHaveSurgeryDoneNow(pawn))
{
return ThinkResult.NoJob;
}
//Check medical assistance, fed, and rest if not override
if(!PrisonLaborUtility.WorkTime(pawn))
if (!PrisonLaborUtility.WorkTime(pawn))
{
pawn.needs.TryGetNeed<Need_Motivation>().Enabled = false;
if (pawn.needs.TryGetNeed<Need_Motivation>() != null)
pawn.needs.TryGetNeed<Need_Motivation>().Enabled = false;
return ThinkResult.NoJob;
}
//Check laziness
if (pawn.needs.TryGetNeed<Need_Motivation>().IsLazy)
if (PrisonLaborPrefs.EnableMotivationMechanics && pawn.needs.TryGetNeed<Need_Motivation>().IsLazy)
{
return ThinkResult.NoJob;
}
//Work prisoners will do
PrisonLaborUtility.InitWorkSettings(pawn);
List<WorkGiver> workList = pawn.workSettings.WorkGiversInOrderNormal;
workList.RemoveAll(workGiver => workGiver.def.defName == "GrowerSow");
pawn.needs.TryGetNeed<Need_Motivation>().Enabled = false;
if (pawn.needs.TryGetNeed<Need_Motivation>() != null)
pawn.needs.TryGetNeed<Need_Motivation>().Enabled = false;

int num = -999;
TargetInfo targetInfo = TargetInfo.Invalid;
Expand All @@ -71,7 +73,8 @@ public override ThinkResult TryIssueJobPackage(Pawn pawn, JobIssueParams jobPara
Job job2 = workGiver.NonScanJob(pawn);
if (job2 != null)
{
pawn.needs.TryGetNeed<Need_Motivation>().Enabled = true;
if (pawn.needs.TryGetNeed<Need_Motivation>() != null)
pawn.needs.TryGetNeed<Need_Motivation>().Enabled = true;
return new ThinkResult(job2, this, new JobTag?(workList[j].def.tagToGive));
}
WorkGiver_Scanner scanner = workGiver as WorkGiver_Scanner;
Expand Down Expand Up @@ -168,7 +171,8 @@ public override ThinkResult TryIssueJobPackage(Pawn pawn, JobIssueParams jobPara
}
if (job3 != null)
{
pawn.needs.TryGetNeed<Need_Motivation>().Enabled = true;
if (pawn.needs.TryGetNeed<Need_Motivation>() != null)
pawn.needs.TryGetNeed<Need_Motivation>().Enabled = true;
return new ThinkResult(job3, this, new JobTag?(workList[j].def.tagToGive));
}
Log.ErrorOnce(string.Concat(new object[]
Expand Down
112 changes: 112 additions & 0 deletions Source/NewsDialog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using Verse;

namespace PrisonLabor
{
class NewsDialog : Window
{
private static bool autoShow = true;

public static bool showAll = false;

public static bool news_0_5 = false;
public static bool news_0_6 = false;
public static bool news_0_7 = false;

private Vector2 position;
private Rect cRect;

public NewsDialog()
{
this.doCloseButton = true;
this.doCloseX = true;
}

public static void TryShow()
{
if (autoShow && PrisonLaborPrefs.ShowNews)
{
Find.WindowStack.Add(new NewsDialog());
PrisonLaborPrefs.LastVersion = PrisonLaborPrefs.Version;
PrisonLaborPrefs.Save();
autoShow = false;
}
}

public static void ForceShow()
{
Find.WindowStack.Add(new NewsDialog());
PrisonLaborPrefs.LastVersion = PrisonLaborPrefs.Version;
PrisonLaborPrefs.Save();
autoShow = false;
}

public override void DoWindowContents(Rect inRect)
{
if(cRect == null)
cRect = inRect;

Rect viewRect = new Rect(inRect.x, inRect.y, inRect.width, inRect.height - 50);

Widgets.BeginScrollView(viewRect, ref this.position, cRect, true);

float CurHeight = 0;

Listing_Standard ls_title = new Listing_Standard(GameFont.Medium);
Listing_Standard ls_desc = new Listing_Standard(GameFont.Small);
if(news_0_7 || showAll)
{
ls_title.Begin(new Rect(cRect.x, cRect.y + CurHeight, cRect.width, cRect.height - CurHeight));
ls_title.Label("Prison Labor Alpha v0.7");
ls_title.GapLine();
ls_title.End();
CurHeight += ls_title.CurHeight;
ls_desc.Begin(new Rect(cRect.x, cRect.y + CurHeight, cRect.width, cRect.height - CurHeight));
ls_desc.Label(" - Added settings! You can now change almost any aspect of this mod, including:\n * work types\n * motivation mechanics\n * prevention of planting advanced plants.");
ls_desc.Label(" - Added \"uninstaller\" (\"disable\" option in settings), which will allow to disable this mod from existing saves.");
ls_desc.Label(" - \"No more beeping!\". Changed way of informing player what's going on with prisoners. It should be less annoying and more insightful.");
ls_desc.Label(" - Fixed bugs, including bug that prevents prisoners from cleaning and bug that causes warden to stuck in loop of delivering food to prisoner.");
ls_desc.Label(" - \"No more watching while prisoner is sleeping.\"Wardens will no longer watch over not working prisoners.");
ls_desc.Label(" - Prisoners will now stay in bed while waiting for operation");
ls_desc.Label(" - Prisoners will now stop work when starving for default (\"Anything\" time), instead of hungry. They will still get minor debuff.");
ls_desc.Gap();
ls_desc.End();
CurHeight += ls_desc.CurHeight;
}
if(news_0_6 || showAll)
{
ls_title.Begin(new Rect(cRect.x, cRect.y + CurHeight, cRect.width, cRect.height - CurHeight));
ls_title.Label("Prison Labor Alpha v0.6");
ls_title.GapLine();
ls_title.End();
CurHeight += ls_title.CurHeight;
ls_desc.Begin(new Rect(cRect.x, cRect.y + CurHeight, cRect.width, cRect.height - CurHeight));
ls_desc.Label("Changes in PrisonLabor v0.6:\n\n 1. Time restrictions - now you can manage your prisoners time for sleep, work and joy. You can now even force them to work when they're hungry!\n 2. Getting food by prisoners - Now prisoners will look for food in much better way, and now (when they desperate enough) they will eat corpses!\n 3. \"Laziness\" changed to \"Motivation\" and inverted.\n\n ATTENTION: After PrisonLabor reaches beta all saves with PrisonLabor v0.5a or lower will be corrupted and unplayable. This version (0.6) is safe and converts all older saves.");
ls_desc.Gap();
ls_desc.End();
CurHeight += ls_desc.CurHeight;
}
if(news_0_5 || showAll)
{
ls_title.Begin(new Rect(cRect.x, cRect.y + CurHeight, cRect.width, cRect.height - CurHeight));
ls_title.Label("Prison Labor Alpha v0.5");
ls_title.GapLine();
ls_title.End();
CurHeight += ls_title.CurHeight;
ls_desc.Begin(new Rect(cRect.x, cRect.y + CurHeight, cRect.width, cRect.height - CurHeight));
ls_desc.Label("Major changes to PrisonLabor:\n\n 1. Prisoners can now grow, but only plants that not require any skills.\n 2. You can now manage prisoners work types. Just check \"Work\" tab!\n 3. Laziness now appear on \"Needs\" tab. Above 50% wardens will watch prisoners. Above 80% prisoners won't work unless supervised.\n 4. Wardens will now bring food to prisoners that went too far from his bed.\n 5. Prisoners won't gain laziness when not working anymore.\n 6. Fixed many bugs");
ls_desc.Gap();
ls_desc.End();
CurHeight += ls_desc.CurHeight;
}

Widgets.EndScrollView();

cRect = new Rect(inRect.x, inRect.y, inRect.width - 50f, CurHeight + 50f);
}
}
}
Loading

0 comments on commit 6f170d3

Please sign in to comment.