Skip to content

Commit

Permalink
Merge pull request #237 from Aviuz/1.3.1
Browse files Browse the repository at this point in the history
1.3.1
  • Loading branch information
Hazzer authored Aug 25, 2021
2 parents f5ddd44 + fdc7c1a commit 20402f0
Show file tree
Hide file tree
Showing 36 changed files with 287 additions and 153 deletions.
Binary file modified 1.3/Assemblies/PrisonLabor.dll
Binary file not shown.
1 change: 1 addition & 0 deletions 1.3/Defs/MainButton.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<label>Prisoners</label>
<description>Manage your faction prisoners</description>
<tabWindowClass>PrisonLabor.Core.MainButton_Window.PrisonerButtonWindow</tabWindowClass>
<iconPath>PL_TabIcon</iconPath>
<order>35</order>
<closesWorldView>true</closesWorldView>
</MainButtonDef>
Expand Down
5 changes: 0 additions & 5 deletions 1.3/Defs/PrisonerInteractionModeDef.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,4 @@
<label>Work and recruit</label>
<listOrder>6</listOrder>
</PrisonerInteractionModeDef>
<PrisonerInteractionModeDef>
<defName>PrisonLabor_workAndConvertOption</defName>
<label>Work and convert</label>
<listOrder>7</listOrder>
</PrisonerInteractionModeDef>
</Defs>
4 changes: 2 additions & 2 deletions 1.3/Defs/WorkGiverDef.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
<giverClass>PrisonLabor.Core.AI.WorkGivers.WorkGiver_HandleChains</giverClass>
<workType>PrisonLabor_Jailor</workType>
<priorityInType>5</priorityInType>
<verb>>handle prisoner's chainsr</verb>
<gerund>>handling prisoner's chains</gerund>
<verb>handle prisoner's chains</verb>
<gerund>handling prisoner's chains</gerund>
<requiredCapacities>
<li>Manipulation</li>
</requiredCapacities>
Expand Down
15 changes: 15 additions & 0 deletions Ideology/Defs/PrisonersInteractionMode.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<Defs>
<PrisonerInteractionModeDef>
<defName>PrisonLabor_workAndConvertOption</defName>
<label>Work and convert</label>
<listOrder>7</listOrder>
</PrisonerInteractionModeDef>

<PrisonerInteractionModeDef>
<defName>PrisonLabor_workAndEnslaveOption</defName>
<label>Work and enslave</label>
<listOrder>8</listOrder>
</PrisonerInteractionModeDef>

</Defs>
1 change: 1 addition & 0 deletions Languages/English/Keyed/Keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PrisonLabor_PrisonerWork>Force to work</PrisonLabor_PrisonerWork>
<PrisonLabor_WorkAndRecruit>Work and recruit</PrisonLabor_WorkAndRecruit>
<PrisonLabor_WorkAndConvert>Work and convert</PrisonLabor_WorkAndConvert>
<PrisonLabor_WorkAndEnslave>Work and enslave</PrisonLabor_WorkAndEnslave>
<PrisonLabor_LazyPrisonerMessage>Your prisoner stopped working!</PrisonLabor_LazyPrisonerMessage>
<PrisonLabor_WardenResponseThreshold>Warden response threshold</PrisonLabor_WardenResponseThreshold>
<PrisonLabor_StoppingWorkThreshold>Stopping work threshold</PrisonLabor_StoppingWorkThreshold>
Expand Down
1 change: 1 addition & 0 deletions LoadFolders.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
<v1.3>
<li>/</li>
<li>1.3</li>
<li IfModActive="Ludeon.Rimworld.Ideology">Ideology</li>
</v1.3>
</loadFolders>
4 changes: 3 additions & 1 deletion MakeRelease.bat
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ xcopy "1.1\*.*" "%target_directory%\1.1" /e
mkdir "%target_directory%\1.2"
xcopy "1.2\*.*" "%target_directory%\1.2" /e

:: 1.2
:: 1.3
mkdir "%target_directory%\1.3"
xcopy "1.3\*.*" "%target_directory%\1.3" /e

mkdir "%target_directory%\Ideology"
xcopy "Ideology\*.*" "%target_directory%\Ideology" /e

:: LoadFolders.xml
copy "LoadFolders.xml" "%target_directory%\LoadFolders.xml"
Expand Down
5 changes: 5 additions & 0 deletions Source/Constants/PL_DefOf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ public static class PL_DefOf
{
public static PrisonerInteractionModeDef PrisonLabor_workOption;
public static PrisonerInteractionModeDef PrisonLabor_workAndRecruitOption;

[MayRequireIdeology]
public static PrisonerInteractionModeDef PrisonLabor_workAndConvertOption;

[MayRequireIdeology]
public static PrisonerInteractionModeDef PrisonLabor_workAndEnslaveOption;

public static WorkTypeDef PrisonLabor_Jailor;

public static NeedDef PrisonLabor_Motivation;
Expand Down
10 changes: 6 additions & 4 deletions Source/Core/AI/ThinkNodes/ThinkNode_Labor.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using PrisonLabor.Core.Components;
using PrisonLabor.Core.Needs;
using PrisonLabor.Core.Other;
using PrisonLabor.Core.Trackers;
Expand Down Expand Up @@ -32,17 +33,18 @@ protected override bool Satisfied(Pawn pawn)

// Prisoner will escape if get ready to run.
// If he can run he will start ticking impatient, once complete he will get ready.
var escapeTracker = EscapeTracker.Of(pawn, true);

var prisonerComp = pawn.TryGetComp<PrisonerComp>();
if (pawn.guest.PrisonerIsSecure && RCellFinder.TryFindBestExitSpot(pawn, out c, TraverseMode.ByPawn))
{
if (escapeTracker.ReadyToEscape)
if (prisonerComp.escapeTracker.ReadyToEscape)
return false;
else
escapeTracker.CanEscape = true;
prisonerComp.escapeTracker.CanEscape = true;
}
else
{
escapeTracker.CanEscape = false;
prisonerComp.escapeTracker.CanEscape = false;
}


Expand Down
10 changes: 7 additions & 3 deletions Source/Core/AI/WorkGivers/WorkGiver_Supervise.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using PrisonLabor.Core.Components;
using PrisonLabor.Core.Needs;
using PrisonLabor.Core.Trackers;
using RimWorld;
Expand All @@ -20,14 +21,17 @@ public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
return null;
if (pawn.IsPrisoner)
return null;
var escapeTracker = EscapeTracker.Of(prisoner, true);
if (!PrisonLaborUtility.LaborEnabled(prisoner) && !escapeTracker.CanEscape)
var prisonerComp = prisoner.TryGetComp<PrisonerComp>(); ;

if (!PrisonLaborUtility.LaborEnabled(prisoner) && prisonerComp != null && !prisonerComp.escapeTracker.CanEscape)
return null;
if (PrisonLaborUtility.RecruitInLaborEnabled(prisoner))
return new Job(JobDefOf.PrisonerAttemptRecruit, t);
if (PrisonLaborUtility.ConvertInLaborEnabled(prisoner))
return new Job(JobDefOf.PrisonerConvert, t);
if ((!PrisonLaborUtility.WorkTime(prisoner) || !need.ShouldBeMotivated) && !escapeTracker.CanEscape)
if (PrisonLaborUtility.EnslaveInLaborEnabled(prisoner))
return new Job(JobDefOf.PrisonerEnslave, t);
if ((!PrisonLaborUtility.WorkTime(prisoner) || !need.ShouldBeMotivated) && prisonerComp != null && !prisonerComp.escapeTracker.CanEscape)
return null;

return new Job(DefDatabase<JobDef>.GetNamed("PrisonLabor_PrisonerSupervise"), prisoner);
Expand Down
5 changes: 1 addition & 4 deletions Source/Core/Alerts/Alert_EscapingPrisoners.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ private IEnumerable<Pawn> PotentialEscapingPrisoners
{
get
{
var maps = Find.Maps;
for (var i = 0; i < maps.Count; i++)
foreach (var pawn in maps[i].mapPawns.AllPawns.Where(p=>p.IsPrisoner && EscapeTracker.Of(p, true).CanEscape))
yield return pawn;
return EscapeTracker.PrisonersReadyToEscape;
}
}

Expand Down
2 changes: 1 addition & 1 deletion Source/Core/BaseClasses/SimpleTimer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void Tick()
{
if (_IsActive)
{
Ticks++;
Ticks += 250;
}
}

Expand Down
28 changes: 26 additions & 2 deletions Source/Core/Components/PrisonerComp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
namespace PrisonLabor.Core.Components
{

public class PrisonerComp : ThingComp
public class PrisonerComp : ThingComp
{
public EscapeTracker escapeTracker;

private bool Active
{
get
Expand All @@ -24,6 +26,14 @@ private bool Active
}
}

public override void Initialize(CompProperties props)
{
base.Initialize(props);
if (escapeTracker == null)
{
escapeTracker = new EscapeTracker(this.parent as Pawn);
}
}
public override void PostDraw()
{
if (Active && PrisonLaborPrefs.EnableMotivationIcons)
Expand All @@ -43,10 +53,11 @@ public override void PostDraw()
DrawIcon(TexturePool.lazyTexture);
}
}

}



private void DrawIcon(Material drawIcon)
{
var drawPos = parent.DrawPos;
Expand All @@ -62,5 +73,18 @@ private void DrawIcon(Material drawIcon)
var material = FadedMaterialPool.FadedVersionOf(drawIcon, num2);
Graphics.DrawMesh(MeshPool.plane05, drawPos, Quaternion.identity, material, 0);
}

public override void PostExposeData()
{
Scribe_Deep.Look(ref escapeTracker, "EscapeTracker", new object[] { this.parent as Pawn });
}

public override void CompTickRare()
{
if (Active)
{
escapeTracker?.Tick();
}
}
}
}
2 changes: 1 addition & 1 deletion Source/Core/GameSaves/SaveCleaner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ private static void UpdateData(XmlElement xmlNode)
// TODO bills

// Interaction Mode
string[] interactions = { PL_DefOf.PrisonLabor_workOption.defName, PL_DefOf.PrisonLabor_workAndRecruitOption.defName, PL_DefOf.PrisonLabor_workAndConvertOption.defName };
string[] interactions = { PL_DefOf.PrisonLabor_workOption.defName, PL_DefOf.PrisonLabor_workAndRecruitOption.defName, PL_DefOf.PrisonLabor_workAndConvertOption.defName, PL_DefOf.PrisonLabor_workAndEnslaveOption.defName };

foreach (var guestTracker in gameNode.GetEveryNode("guest"))
{
Expand Down
20 changes: 10 additions & 10 deletions Source/Core/MainButton_Window/ColumnWorker_EscapeTracker.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using PrisonLabor.Core.Trackers;
using PrisonLabor.Core.Components;
using PrisonLabor.Core.Trackers;
using RimWorld;
using System;
using System.Collections.Generic;
Expand All @@ -13,24 +14,23 @@ public class ColumnWorker_EscapeTracker : PawnColumnWorker_Text
{
protected override string GetTextFor(Pawn pawn)
{

var escapeTracker = EscapeTracker.Of(pawn);
if(escapeTracker != null)
var prisonerComp = pawn.TryGetComp<PrisonerComp>();
if(prisonerComp != null)
{
return (escapeTracker.ReadyToEscape ? "ready" : escapeTracker.ReadyToRunPercentage + " %");
return (prisonerComp.escapeTracker.ReadyToEscape ? "ready" : prisonerComp.escapeTracker.ReadyToRunPercentage + " %");
}

return "0 %";
return null;
}

protected override string GetTip(Pawn pawn)
{
var escapeTracker = EscapeTracker.Of(pawn);
if (escapeTracker != null)
var prisonerComp = pawn.TryGetComp<PrisonerComp>();
if (prisonerComp != null)
{
return $"(Cap:{ escapeTracker.EscapeLevel})";
return $"(Cap:{ prisonerComp.escapeTracker.EscapeLevel})";
}
return "";
return null;
}
}
}
5 changes: 5 additions & 0 deletions Source/Core/MainButton_Window/ColumnWorker_HasHandscuffs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,10 @@ protected override void SetValue(Pawn pawn, bool value, PawnTable table)
}
table.SetDirty();
}

protected override bool HasCheckbox(Pawn pawn)
{
return pawn != null && pawn.health != null;
}
}
}
5 changes: 5 additions & 0 deletions Source/Core/MainButton_Window/ColumnWorker_HasLegcuffs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,10 @@ protected override void SetValue(Pawn pawn, bool value, PawnTable table)
}
table.SetDirty();
}

protected override bool HasCheckbox(Pawn pawn)
{
return pawn != null && pawn.health != null;
}
}
}
7 changes: 6 additions & 1 deletion Source/Core/MainButton_Window/ColumnWorker_Interaction.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using RimWorld;
using PrisonLabor.Constants;
using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -30,6 +31,10 @@ public override void DoCell(Rect rect, Pawn pawn, PawnTable table)
option = new FloatMenuOption(intertaction.LabelCap, delegate
{
pawn.guest.interactionMode = intertaction;
if(intertaction == PrisonerInteractionModeDefOf.Convert || intertaction == PL_DefOf.PrisonLabor_workAndConvertOption)
{
pawn.guest.ideoForConversion = Faction.OfPlayer.ideos.PrimaryIdeo;
}
}),
payload = intertaction
};
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/MainButton_Window/CustomTabWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public override Vector2 InitialSize
return requestedTabSize;
}
}
protected virtual IEnumerable<Pawn> Pawns => Find.CurrentMap.mapPawns.FreeColonists_NoHusks;
protected virtual IEnumerable<Pawn> Pawns => Find.CurrentMap.mapPawns.FreeColonists;

public override void PostOpen()
{
Expand Down
10 changes: 6 additions & 4 deletions Source/Core/MainButton_Window/PrisonerButtonWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public PrisonerButtonWindow() : base()
{
foreach(var def in DefDatabase<PrisonersTabDef>.AllDefs)
{
Log.Message($"Def: {def.defName}, def.dev: {def.dev}, dev: {Prefs.DevMode}");
if(def.dev == false)
{
tabsView.Add(def, CreateWindow(def));
Expand All @@ -94,9 +95,9 @@ public PrisonerButtonWindow() : base()
}

}
DebugLogger.debug("Prisoners main windows constructed");

DebugLogger.debug("Prisoners main windows constructed");
}

public override void DoWindowContents(Rect inRect)
{

Expand All @@ -113,15 +114,16 @@ public override void PostOpen()
{
base.PostOpen();
tabs.Clear();
foreach (PrisonersTabDef tabDef in DefDatabase<PrisonersTabDef>.AllDefs.OrderBy(def => def.order))
foreach (PrisonersTabDef tabDef in DefDatabase<PrisonersTabDef>.AllDefs.Where(def => !def.dev || def.dev == Prefs.DevMode).OrderBy(def => def.order))
{
tabs.Add(new PrisonerWindowTab(tabDef, tabDef.LabelCap, delegate
{
CurTab = tabDef;
}, () => CurTab == tabDef));
GetTable(tabDef);

}
CurTab = tabs[0].def;
CurTab = tabs[1].def;
foreach(var tab in tabsView.Values)
{
tab.PostOpen();
Expand Down
1 change: 1 addition & 0 deletions Source/Core/Needs/Need_Treatment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public override void NeedInterval()
var motivation = pawn.needs.TryGetNeed<Need_Motivation>();
if (motivation != null && motivation.IsPrisonerWorking)
CurLevel += BGP.LaborRate;

}

public override string GetTipString()
Expand Down
14 changes: 11 additions & 3 deletions Source/Core/PrisonLaborUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ internal static class PrisonLaborUtility
public static bool LaborEnabled(this Pawn pawn)
{
if (pawn.IsPrisoner)
if (pawn.guest.interactionMode == PL_DefOf.PrisonLabor_workOption || pawn.guest.interactionMode == PL_DefOf.PrisonLabor_workAndRecruitOption || pawn.guest.interactionMode == PL_DefOf.PrisonLabor_workAndConvertOption)
if (pawn.guest.interactionMode == PL_DefOf.PrisonLabor_workOption || pawn.guest.interactionMode == PL_DefOf.PrisonLabor_workAndRecruitOption
|| pawn.guest.interactionMode == PL_DefOf.PrisonLabor_workAndConvertOption || pawn.guest.interactionMode == PL_DefOf.PrisonLabor_workAndEnslaveOption)
{
return true;
}

return false;
}
Expand All @@ -36,10 +39,15 @@ public static bool ConvertInLaborEnabled(Pawn pawn)
return false;
}

public static bool EnslaveInLaborEnabled(Pawn pawn)
{
if (pawn.guest.interactionMode == PL_DefOf.PrisonLabor_workAndEnslaveOption && pawn.guest.ScheduledForInteraction && pawn.health.capacities.CapableOf(PawnCapacityDefOf.Talking))
return true;

return false;
}
public static bool WorkTime(Pawn pawn)
{
/* if (pawn.needs == null || pawn.needs.food == null || pawn.needs.rest == null)
return false;*/
if (pawn.timetable == null)
return true;
if (pawn.timetable.CurrentAssignment == TimeAssignmentDefOf.Work)
Expand Down
Loading

0 comments on commit 20402f0

Please sign in to comment.