Skip to content

Commit

Permalink
v2.3.1 adds more options and fixes some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
pardeike committed Nov 12, 2018
1 parent 1035364 commit b315a94
Show file tree
Hide file tree
Showing 13 changed files with 119 additions and 29 deletions.
2 changes: 1 addition & 1 deletion About/Manifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Manifest>
<identifier>net.pardeike.rimworld.mod.achtung</identifier>
<version>2.3.0.0</version>
<version>2.3.1.0</version>
<targetVersions>
<li>0.19.0</li>
<li>1.0.0</li>
Expand Down
2 changes: 1 addition & 1 deletion About/ModSync.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<ModSyncNinjaData>
<ID>be673269-db56-463b-8c36-e074881e0d77</ID>
<ModName>Achtung!</ModName>
<Version>2.3.0.0</Version>
<Version>2.3.1.0</Version>
<SaveBreaking>False</SaveBreaking>
<Host name="Github">
<Owner>pardeike</Owner>
Expand Down
Binary file modified Assemblies/AchtungMod.dll
Binary file not shown.
7 changes: 7 additions & 0 deletions Languages/English/Keyed/Text.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ The formation can be rotated using Q and E</AchtungModifierExplained>
<HealthLevelOptionNeedsMedicalRest>Needs medical rest</HealthLevelOptionNeedsMedicalRest>
<HealthLevelOptionInPainShock>In pain shock</HealthLevelOptionInPainShock>

<IgnoreForbiddenTitle>Ignore forbidden things</IgnoreForbiddenTitle>
<IgnoreForbiddenExplained>Ignores forbidden (red crossed) items when doing forced work</IgnoreForbiddenExplained>
<IgnoreRestrictionsTitle>Ignore restricted areas</IgnoreRestrictionsTitle>
<IgnoreRestrictionsExplained>Ignore zone restrictions when doing forced work</IgnoreRestrictionsExplained>
<IgnoreAssignmentsTitle>Ignore work type assignments</IgnoreAssignmentsTitle>
<IgnoreAssignmentsExplained>Ignores unset work priorities</IgnoreAssignmentsExplained>

<JobInterruptedLabel>Cancelled: {0}</JobInterruptedLabel>
<JobInterruptedBreakdown>{0}: {1}</JobInterruptedBreakdown>
<JobInterruptedBadHealth>{0} is in bad shape</JobInterruptedBadHealth>
Expand Down
7 changes: 7 additions & 0 deletions Languages/German/Keyed/Text.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ Die Formation kann während der Bewegung mit Q und E rotiert werden</AchtungModi
<HealthLevelOptionNeedsMedicalRest>Notwendige Bettruhe</HealthLevelOptionNeedsMedicalRest>
<HealthLevelOptionInPainShock>Schockzustand</HealthLevelOptionInPainShock>

<IgnoreForbiddenTitle>Ignoriere verbotene Dinge</IgnoreForbiddenTitle>
<IgnoreForbiddenExplained>Ignoriert verbotene (rotes Kreuz) Dinge während erzwungener Arbeit</IgnoreForbiddenExplained>
<IgnoreRestrictionsTitle>Ignoriere Zonenbegrenzungen</IgnoreRestrictionsTitle>
<IgnoreRestrictionsExplained>Ignoriert Zonen während erzwungener Arbeit</IgnoreRestrictionsExplained>
<IgnoreAssignmentsTitle>Ignoriere Arbeitseinstellungen</IgnoreAssignmentsTitle>
<IgnoreAssignmentsExplained>Ignoriert leere, unzugewiesene Arbeitsprioriteten</IgnoreAssignmentsExplained>

<JobInterruptedLabel>Abgebrochen: {0}</JobInterruptedLabel>
<JobInterruptedBreakdown>{0}: {1}</JobInterruptedBreakdown>
<JobInterruptedBadHealth>{0} ist in schlechter gesundheitlicher Verfassung</JobInterruptedBadHealth>
Expand Down
7 changes: 7 additions & 0 deletions Languages/Spanish/Keyed/Text.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ La formación puede rotar usando las teclas Q y E.</AchtungModifierExplained>
<HealthLevelOptionNeedsMedicalRest>Necesita descanso médico</HealthLevelOptionNeedsMedicalRest>
<HealthLevelOptionInPainShock>En estado de shock</HealthLevelOptionInPainShock>

<IgnoreForbiddenTitle>Ignorar las cosas prohibidas</IgnoreForbiddenTitle>
<IgnoreForbiddenExplained>Ignora los artículos prohibidos (cruzados en rojo) al realizar trabajos forzados</IgnoreForbiddenExplained>
<IgnoreRestrictionsTitle>Ignorar las áreas restringidas</IgnoreRestrictionsTitle>
<IgnoreRestrictionsExplained>Ignorar las restricciones de zona al hacer trabajos forzados</IgnoreRestrictionsExplained>
<IgnoreAssignmentsTitle>Ignorar asignaciones de tipo de trabajo</IgnoreAssignmentsTitle>
<IgnoreAssignmentsExplained>Ignora las prioridades de trabajo que no están establecidas</IgnoreAssignmentsExplained>

<JobInterruptedLabel>Cancelado: {0}</JobInterruptedLabel>
<JobInterruptedBreakdown>{0}: {1}</JobInterruptedBreakdown>
<JobInterruptedBadHealth>{0} se encuentra mal</JobInterruptedBadHealth>
Expand Down
7 changes: 7 additions & 0 deletions Languages/SpanishLatin/Keyed/Text.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ La formación puede rotar usando las teclas Q y E.</AchtungModifierExplained>
<HealthLevelOptionNeedsMedicalRest>Necesita descanso médico</HealthLevelOptionNeedsMedicalRest>
<HealthLevelOptionInPainShock>En estado de shock</HealthLevelOptionInPainShock>

<IgnoreForbiddenTitle>Ignorar las cosas prohibidas</IgnoreForbiddenTitle>
<IgnoreForbiddenExplained>Ignora los artículos prohibidos (cruzados en rojo) al realizar trabajos forzados</IgnoreForbiddenExplained>
<IgnoreRestrictionsTitle>Ignorar las áreas restringidas</IgnoreRestrictionsTitle>
<IgnoreRestrictionsExplained>Ignorar las restricciones de zona al hacer trabajos forzados</IgnoreRestrictionsExplained>
<IgnoreAssignmentsTitle>Ignorar asignaciones de tipo de trabajo</IgnoreAssignmentsTitle>
<IgnoreAssignmentsExplained>Ignora las prioridades de trabajo que no están establecidas</IgnoreAssignmentsExplained>

<JobInterruptedLabel>Cancelado: {0}</JobInterruptedLabel>
<JobInterruptedBreakdown>{0}: {1}</JobInterruptedBreakdown>
<JobInterruptedBadHealth>{0} se encuentra mal</JobInterruptedBadHealth>
Expand Down
7 changes: 7 additions & 0 deletions Languages/Swedish/Keyed/Text.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ Höll i för att flytta kolonister i deras formation. Formationen kan roteras me
<HealthLevelOptionNeedsMedicalRest>Sängbunden</HealthLevelOptionNeedsMedicalRest>
<HealthLevelOptionInPainShock>I shock</HealthLevelOptionInPainShock>

<IgnoreForbiddenTitle>Ignorera förbjudna saker</IgnoreForbiddenTitle>
<IgnoreForbiddenExplained>Ignorerar förbjudna (röd kors) föremål vid tvångsarbete</IgnoreForbiddenExplained>
<IgnoreRestrictionsTitle>Ignorera begränsade områden</IgnoreRestrictionsTitle>
<IgnoreRestrictionsExplained>Ignorera zonbegränsningar vid tvångsarbete</IgnoreRestrictionsExplained>
<IgnoreAssignmentsTitle>Ignorera arbetstypsuppdrag</IgnoreAssignmentsTitle>
<IgnoreAssignmentsExplained>Ignorerar tomma arbetsprioriteringar</IgnoreAssignmentsExplained>

<JobInterruptedLabel>Avbruten: {0}</JobInterruptedLabel>
<JobInterruptedBreakdown>{0}: {1}</JobInterruptedBreakdown>
<JobInterruptedBadHealth>{0} har låg hälsa</JobInterruptedBadHealth>
Expand Down
4 changes: 2 additions & 2 deletions Source/ForcedJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,8 @@ public static Job GetThingJob(this Thing thing, Pawn pawn, WorkGiver_Scanner wor
var job = workgiver.JobOnThing(pawn, thing, true);
if (job != null)
{
if (ignoreRestrictions || thing.IsForbidden(pawn) == false)
if (ignoreRestrictions || thing.Position.InAllowedArea(pawn))
if ((Achtung.Settings.ignoreForbidden && ignoreRestrictions) || thing.IsForbidden(pawn) == false)
if ((Achtung.Settings.ignoreRestrictions && ignoreRestrictions) || thing.Position.InAllowedArea(pawn))
{
var ok1 = (ignoreReserve == false && pawn.CanReserveAndReach(thing, workgiver.PathEndMode, Danger.Deadly));
var ok2 = (ignoreReserve && pawn.CanReach(thing, workgiver.PathEndMode, Danger.Deadly));
Expand Down
77 changes: 57 additions & 20 deletions Source/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,14 @@ static class HaulAIUtility_PawnCanAutomaticallyHaulFast_Patch
{
static bool Prefix(Pawn p, Thing t, bool forced, ref bool __result)
{
var forcedWork = Find.World.GetComponent<ForcedWork>();
if (forced || forcedWork.HasForcedJob(p))
if (Achtung.Settings.ignoreRestrictions)
{
__result = true;
return false;
var forcedWork = Find.World.GetComponent<ForcedWork>();
if (forced || forcedWork.HasForcedJob(p))
{
__result = true;
return false;
}
}
return true;
}
Expand All @@ -104,15 +107,21 @@ static class ForbidUtility_InAllowedArea_Patch
{
static void Postfix(IntVec3 c, Pawn forPawn, ref bool __result)
{
if (__result == false)
return;
var forcedWork = Find.World.GetComponent<ForcedWork>();
if (forcedWork.HasForcedJob(forPawn))
__result = true;
else
__result = forcedWork
.AllForcedCellsForMap(forPawn.Map)
.Contains(c) == false;
{
if (Achtung.Settings.ignoreRestrictions)
{
__result = true;
return;
}
}
else if (__result == true)
{
// ignore forced work cells if colonist is not forced
if (forcedWork.AllForcedCellsForMap(forPawn.Map).Contains(c))
__result = false;
}
}
}

Expand Down Expand Up @@ -247,7 +256,6 @@ static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> inst
}

// ignore forbidden for forced jobs
// TODO: make this optional
//
[HarmonyPatch(typeof(ForbidUtility))]
[HarmonyPatch(nameof(ForbidUtility.IsForbidden))]
Expand All @@ -256,11 +264,14 @@ static class ForbidUtility_IsForbidden_Patch
{
static bool Prefix(Thing t, Pawn pawn, ref bool __result)
{
var forcedWork = Find.World.GetComponent<ForcedWork>();
if (forcedWork.HasForcedJob(pawn))
if (Achtung.Settings.ignoreForbidden)
{
__result = false;
return false;
var forcedWork = Find.World.GetComponent<ForcedWork>();
if (forcedWork.HasForcedJob(pawn))
{
__result = false;
return false;
}
}
return true;
}
Expand Down Expand Up @@ -364,14 +375,37 @@ static void Postfix(Pawn pawn, ForcedWork __state)
__state.Unprepare(pawn);
}

static int GetPriority(Pawn pawn, WorkTypeDef w)
{
if (Achtung.Settings.ignoreAssignments)
return pawn.story.WorkTypeIsDisabled(w) ? 0 : 1;
return pawn.workSettings.GetPriority(w);
}

static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
var m_GetPriority = AccessTools.Method(typeof(Pawn_WorkSettings), nameof(Pawn_WorkSettings.GetPriority));
var c_FloatMenuOption = AccessTools.FirstConstructor(typeof(FloatMenuOption), c => c.GetParameters().Count() > 1);
var m_ForcedFloatMenuOption = AccessTools.Method(typeof(ForcedFloatMenuOption), nameof(ForcedFloatMenuOption.CreateForcedMenuItem));

var list = instructions.ToList();

var foundCount = 0;
while (true)
{
var idx = list.FirstIndexOf(instr => instr.operand == m_GetPriority);
if (idx < 2 || idx >= list.Count)
break;
foundCount++;
list[idx - 2].opcode = OpCodes.Nop;
list[idx].opcode = OpCodes.Call;
list[idx].operand = SymbolExtensions.GetMethodInfo(() => GetPriority(null, WorkTypeDefOf.Doctor));
}

if (foundCount != 2)
Log.Error("Cannot find 2x Pawn_WorkSettings.GetPriority in RimWorld.FloatMenuMakerMap::AddJobGiverWorkOrders");

foundCount = 0;
Enumerable.Range(0, list.Count)
.DoIf(i => list[i].opcode == OpCodes.Isinst && list[i].operand == typeof(WorkGiver_Scanner), i =>
{
Expand Down Expand Up @@ -470,10 +504,13 @@ static void Postfix(Pawn ___pawn)
var breakNote = Tools.PawnOverBreakLevel(___pawn);
if (breakNote != null)
{
___pawn.Map.pawnDestinationReservationManager.ReleaseAllClaimedBy(___pawn);
var jobName = ___pawn.jobs?.curJob.GetReport(___pawn).CapitalizeFirst() ?? "-";
var label = "JobInterruptedLabel".Translate(new object[] { jobName });
Find.LetterStack.ReceiveLetter(LetterMaker.MakeLetter(label, "JobInterruptedBreakdown".Translate(new object[] { ___pawn.Name.ToStringShort, breakNote }), LetterDefOf.NegativeEvent, ___pawn));
if (breakNote != "")
{
___pawn.Map.pawnDestinationReservationManager.ReleaseAllClaimedBy(___pawn);
var jobName = ___pawn.jobs?.curJob.GetReport(___pawn).CapitalizeFirst() ?? "-";
var label = "JobInterruptedLabel".Translate(new object[] { jobName });
Find.LetterStack.ReceiveLetter(LetterMaker.MakeLetter(label, "JobInterruptedBreakdown".Translate(new object[] { ___pawn.Name.ToStringShort, breakNote }), LetterDefOf.NegativeEvent, ___pawn));
}

forcedWork.Remove(___pawn);
___pawn.jobs?.EndCurrentJob(JobCondition.InterruptForced, true);
Expand Down
4 changes: 2 additions & 2 deletions Source/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.3.0.0")]
[assembly: AssemblyFileVersion("2.3.0.0")]
[assembly: AssemblyVersion("2.3.1.0")]
[assembly: AssemblyFileVersion("2.3.1.0")]
19 changes: 17 additions & 2 deletions Source/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public class AchtungSettings : ModSettings
public AchtungModKey forceCommandMenuKey = AchtungModKey.Ctrl;
public BreakLevel breakLevel = BreakLevel.AlmostExtreme;
public HealthLevel healthLevel = HealthLevel.InPainShock;
public bool ignoreForbidden = false;
public bool ignoreRestrictions = false;
public bool ignoreAssignments = false;

public override void ExposeData()
{
Expand All @@ -46,11 +49,16 @@ public override void ExposeData()
Scribe_Values.Look(ref forceCommandMenuKey, "forceCommandMenuKey", AchtungModKey.Ctrl, true);
Scribe_Values.Look(ref breakLevel, "BreakLevel", BreakLevel.AlmostExtreme, true);
Scribe_Values.Look(ref healthLevel, "HealthLevel", HealthLevel.InPainShock, true);
Scribe_Values.Look(ref ignoreForbidden, "ignoreForbidden", false, true);
Scribe_Values.Look(ref ignoreRestrictions, "ignoreRestrictions", false, true);
Scribe_Values.Look(ref ignoreAssignments, "ignoreAssignments", false, true);
}

static Vector2 scrollPosition = Vector2.zero;
public void DoWindowContents(Rect canvas)
{
var list = new Listing_Standard { ColumnWidth = canvas.width / 2 };
var columnWidth = canvas.width * 0.6f;
var list = new Listing_Standard { ColumnWidth = columnWidth };
list.Begin(canvas);
list.Gap();

Expand All @@ -63,8 +71,15 @@ public void DoWindowContents(Rect canvas)
list.ValueLabeled("BreakLevel", ref Achtung.Settings.breakLevel);
list.Gap();
list.ValueLabeled("HealthLevel", ref Achtung.Settings.healthLevel);
list.Gap();
list.CheckboxEnhanced("IgnoreForbidden", ref Achtung.Settings.ignoreForbidden);
list.CheckboxEnhanced("IgnoreRestrictions", ref Achtung.Settings.ignoreRestrictions);
list.CheckboxEnhanced("IgnoreAssignments", ref Achtung.Settings.ignoreAssignments);

list.NewColumn();
list.ColumnWidth = canvas.width - columnWidth;

list.Gap(18f);
list.Gap();
list.Note("Notes");
list.Gap(6f);
list.Note("Note1");
Expand Down
5 changes: 4 additions & 1 deletion Source/Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public static void Debug(Thing thing, string text) { }

public static string PawnOverBreakLevel(Pawn pawn)
{
if (pawn.InMentalState)
return "";

var mb = pawn.mindState.mentalBreaker;
switch (Achtung.Settings.breakLevel)
{
Expand Down Expand Up @@ -540,7 +543,7 @@ public static void Note(this Listing_Standard listing, string name)
{
if (name.CanTranslate())
{
Text.Font = GameFont.Tiny;
Text.Font = GameFont.Small;
listing.ColumnWidth -= 34;
GUI.color = Color.white;
listing.Label(name.Translate());
Expand Down

0 comments on commit b315a94

Please sign in to comment.