Skip to content

Commit

Permalink
v3.0.6 speeds up job handling and adds marker configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
pardeike committed Sep 1, 2020
1 parent 9477388 commit 1cd4309
Show file tree
Hide file tree
Showing 14 changed files with 112 additions and 68 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>3.0.5.0</version>
<version>3.0.6.0</version>
<targetVersions>
<li>1.0.0</li>
<li>1.1.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>3.0.5.0</Version>
<Version>3.0.6.0</Version>
<SaveBreaking>False</SaveBreaking>
<Host name="Github">
<Owner>pardeike</Owner>
Expand Down
Binary file modified Current/Assemblies/AchtungMod.dll
Binary file not shown.
6 changes: 6 additions & 0 deletions Languages/English/Keyed/Text.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ The formation can be rotated using Q and E</AchtungModifierExplained>
<IgnoreAssignmentsTitle>Ignore work type assignments</IgnoreAssignmentsTitle>
<IgnoreAssignmentsExplained>Ignores unset work priorities</IgnoreAssignmentsExplained>

<WorkMarkersTitle>Force work markers</WorkMarkersTitle>
<WorkMarkersExplained>Forced work is displayed with small markers</WorkMarkersExplained>
<WorkMarkersOptionAnimated>Animated</WorkMarkersOptionAnimated>
<WorkMarkersOptionStatic>Static</WorkMarkersOptionStatic>
<WorkMarkersOptionOff>Off</WorkMarkersOptionOff>

<JobInterruptedLabel>Cancelled: {0}</JobInterruptedLabel>
<JobInterruptedBreakdown>{0}: {1}</JobInterruptedBreakdown>
<JobInterruptedBadHealth>{0} is in bad shape</JobInterruptedBadHealth>
Expand Down
6 changes: 6 additions & 0 deletions Languages/German/Keyed/Text.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ Die Formation kann während der Bewegung mit Q und E rotiert werden</AchtungModi
<IgnoreAssignmentsTitle>Ignoriere Arbeitseinstellungen</IgnoreAssignmentsTitle>
<IgnoreAssignmentsExplained>Ignoriert leere, unzugewiesene Arbeitsprioriteten</IgnoreAssignmentsExplained>

<WorkMarkersTitle>Erzwungene Arbeitspositionen</WorkMarkersTitle>
<WorkMarkersExplained>Stellen mit erzwungener Arbeit werden mit Markierungen angezeigt</WorkMarkersExplained>
<WorkMarkersOptionAnimated>Animieren</WorkMarkersOptionAnimated>
<WorkMarkersOptionStatic>Statisch</WorkMarkersOptionStatic>
<WorkMarkersOptionOff>Aus</WorkMarkersOptionOff>

<JobInterruptedLabel>Abgebrochen: {0}</JobInterruptedLabel>
<JobInterruptedBreakdown>{0}: {1}</JobInterruptedBreakdown>
<JobInterruptedBadHealth>{0} ist in schlechter gesundheitlicher Verfassung</JobInterruptedBadHealth>
Expand Down
6 changes: 6 additions & 0 deletions Languages/Spanish/Keyed/Text.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ La formación puede rotar usando las teclas Q y E.</AchtungModifierExplained>
<IgnoreAssignmentsTitle>Ignorar asignaciones de tipo de trabajo</IgnoreAssignmentsTitle>
<IgnoreAssignmentsExplained>Ignora las prioridades de trabajo que no están establecidas</IgnoreAssignmentsExplained>

<WorkMarkersTitle>Posiciones de trabajo forzoso</WorkMarkersTitle>
<WorkMarkersExplained>Los puestos de trabajo forzoso se indican con marcadores.</WorkMarkersExplained>
<WorkMarkersOptionAnimated>Con animación</WorkMarkersOptionAnimated>
<WorkMarkersOptionStatic>Estático</WorkMarkersOptionStatic>
<WorkMarkersOptionOff>Apagado</WorkMarkersOptionOff>

<JobInterruptedLabel>Cancelado: {0}</JobInterruptedLabel>
<JobInterruptedBreakdown>{0}: {1}</JobInterruptedBreakdown>
<JobInterruptedBadHealth>{0} se encuentra mal</JobInterruptedBadHealth>
Expand Down
6 changes: 6 additions & 0 deletions Languages/SpanishLatin/Keyed/Text.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ La formación puede rotar usando las teclas Q y E.</AchtungModifierExplained>
<IgnoreAssignmentsTitle>Ignorar asignaciones de tipo de trabajo</IgnoreAssignmentsTitle>
<IgnoreAssignmentsExplained>Ignora las prioridades de trabajo que no están establecidas</IgnoreAssignmentsExplained>

<WorkMarkersTitle>Posiciones de trabajo forzoso</WorkMarkersTitle>
<WorkMarkersExplained>Los puestos de trabajo forzoso se indican con marcadores.</WorkMarkersExplained>
<WorkMarkersOptionAnimated>Con animación</WorkMarkersOptionAnimated>
<WorkMarkersOptionStatic>Estático</WorkMarkersOptionStatic>
<WorkMarkersOptionOff>Apagado</WorkMarkersOptionOff>

<JobInterruptedLabel>Cancelado: {0}</JobInterruptedLabel>
<JobInterruptedBreakdown>{0}: {1}</JobInterruptedBreakdown>
<JobInterruptedBadHealth>{0} se encuentra mal</JobInterruptedBadHealth>
Expand Down
6 changes: 6 additions & 0 deletions Languages/Swedish/Keyed/Text.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ Höll i för att flytta kolonister i deras formation. Formationen kan roteras me
<IgnoreAssignmentsTitle>Ignorera arbetstypsuppdrag</IgnoreAssignmentsTitle>
<IgnoreAssignmentsExplained>Ignorerar tomma arbetsprioriteringar</IgnoreAssignmentsExplained>

<WorkMarkersTitle>Tvingade arbetspositioner</WorkMarkersTitle>
<WorkMarkersExplained>Platser med tvångsarbete visas med små markörer</WorkMarkersExplained>
<WorkMarkersOptionAnimated>Animaterat</WorkMarkersOptionAnimated>
<WorkMarkersOptionStatic>Statiskt</WorkMarkersOptionStatic>
<WorkMarkersOptionOff>Av</WorkMarkersOptionOff>

<JobInterruptedLabel>Avbruten: {0}</JobInterruptedLabel>
<JobInterruptedBreakdown>{0}: {1}</JobInterruptedBreakdown>
<JobInterruptedBadHealth>{0} har låg hälsa</JobInterruptedBadHealth>
Expand Down
6 changes: 4 additions & 2 deletions Source/Controller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,12 @@ private static void DrawForcedJobs()
if (map == null || forcedWork == null)
return;

var currentViewRect = Find.CameraDriver.CurrentViewRect;
forcedWork.ForcedJobsForMap(map)
.DoIf(forcedJob => forcedJob.pawn.Spawned && forcedJob.pawn.Map == map && Find.Selector.IsSelected(forcedJob.pawn), forcedJob =>
{
forcedJob.AllCells(true).Distinct()
.Do(cell => Tools.DrawForceIcon(cell.ToVector3()));
.DoIf(cell => currentViewRect.Contains(cell), cell => Tools.DrawForceIcon(cell.x, cell.z));
});
}

Expand All @@ -325,7 +326,8 @@ private static void DrawForcedJobs()

public void HandleDrawing()
{
DrawForcedJobs();
if (Achtung.Settings.workMarkers != WorkMarkers.Off)
DrawForcedJobs();

// for debugging reservations
// DrawReservations();
Expand Down
38 changes: 38 additions & 0 deletions Source/ForcedWork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class ForcedWork : WorldComponent
Dictionary<Pawn, ForcedJobs> allForcedJobs = new Dictionary<Pawn, ForcedJobs>();
private List<Pawn> forcedJobsKeysWorkingList;
private List<ForcedJobs> forcedJobsValuesWorkingList;
private int counter;

readonly HashSet<Pawn> preparing = new HashSet<Pawn>();
readonly Dictionary<Pawn, HashSet<IntVec3>> forbiddenLocations = new Dictionary<Pawn, HashSet<IntVec3>>();
Expand Down Expand Up @@ -181,6 +182,43 @@ public bool IsForbiddenLocation(IntVec3 cell)
.Any(pair => pair.Value.Contains(cell));
}

public override void WorldComponentTick()
{
if (Find.TickManager.TicksGame % 139 != 0) return;
var pawns = allForcedJobs.Keys.ToArray();
var n = pawns.Length;
if (n == 0) return;
var pawn = pawns[++counter % n];
var map = pawn.Map;
if (map == null) return;

void ShowNote(string txt)
{
map.pawnDestinationReservationManager.ReleaseAllClaimedBy(pawn);
var jobName = pawn.jobs?.curJob.GetReport(pawn).CapitalizeFirst() ?? "-";
var label = "JobInterruptedLabel".Translate(jobName);
Find.LetterStack.ReceiveLetter(LetterMaker.MakeLetter(label, txt, LetterDefOf.NegativeEvent, pawn));
}

var breakNote = Tools.PawnOverBreakLevel(pawn);
if (breakNote != null)
{
if (breakNote.Length > 0)
ShowNote("JobInterruptedBreakdown".Translate(pawn.Name.ToStringShort, breakNote));
Remove(pawn);
pawn.jobs?.EndCurrentJob(JobCondition.InterruptForced, true);
return;
}

if (Tools.PawnOverHealthLevel(pawn))
{
ShowNote("JobInterruptedBadHealth".Translate(pawn.Name.ToStringShort));
Remove(pawn);
pawn.jobs?.EndCurrentJob(JobCondition.InterruptForced, true);
return;
}
}

public override void ExposeData()
{
if (Scribe.mode == LoadSaveMode.Saving)
Expand Down
48 changes: 0 additions & 48 deletions Source/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -553,54 +553,6 @@ public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructio
}
}

// check mental levels
//
[HarmonyPatch(typeof(MentalBreaker))]
[HarmonyPatch(nameof(MentalBreaker.MentalBreakerTick))]
static class MentalBreaker_MentalBreakerTick_Patch
{
public static void Postfix(Pawn ___pawn)
{
if (___pawn?.Map == null)
return;

if (___pawn.IsColonist == false || ___pawn.IsHashIntervalTick(120) == false)
return;

var forcedWork = Find.World.GetComponent<ForcedWork>();
if (forcedWork.HasForcedJob(___pawn) == false)
return;

var breakNote = Tools.PawnOverBreakLevel(___pawn);
if (breakNote != null)
{
if (breakNote.Length > 0)
{
___pawn.Map.pawnDestinationReservationManager.ReleaseAllClaimedBy(___pawn);
var jobName = ___pawn.jobs?.curJob.GetReport(___pawn).CapitalizeFirst() ?? "-";
var label = "JobInterruptedLabel".Translate(jobName);
Find.LetterStack.ReceiveLetter(LetterMaker.MakeLetter(label, "JobInterruptedBreakdown".Translate(___pawn.Name.ToStringShort, breakNote), LetterDefOf.NegativeEvent, ___pawn));
}

forcedWork.Remove(___pawn);
___pawn.jobs?.EndCurrentJob(JobCondition.InterruptForced, true);
return;
}

if (Tools.PawnOverHealthLevel(___pawn))
{
___pawn.Map.pawnDestinationReservationManager.ReleaseAllClaimedBy(___pawn);
var jobName = ___pawn.jobs?.curJob.GetReport(___pawn).CapitalizeFirst() ?? "-";
var label = "JobInterruptedLabel".Translate(jobName);
Find.LetterStack.ReceiveLetter(LetterMaker.MakeLetter(label, "JobInterruptedBadHealth".Translate(___pawn.Name.ToStringShort), LetterDefOf.NegativeEvent, ___pawn));

forcedWork.Remove(___pawn);
___pawn.jobs?.EndCurrentJob(JobCondition.InterruptForced, true);
return;
}
}
}

// release forced work when pawn disappears
//
[HarmonyPatch(typeof(Pawn))]
Expand Down
4 changes: 2 additions & 2 deletions Source/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@

[assembly: Guid("8bd5a28f-96c4-43b4-907f-600aa0162f84")]

[assembly: AssemblyVersion("3.0.5.0")]
[assembly: AssemblyFileVersion("3.0.5.0")]
[assembly: AssemblyVersion("3.0.6.0")]
[assembly: AssemblyFileVersion("3.0.6.0")]
34 changes: 24 additions & 10 deletions Source/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ public enum HealthLevel
InPainShock
}

public enum WorkMarkers
{
Animated,
Static,
Off
}

public class AchtungSettings : ModSettings
{
public bool positioningEnabled = true;
Expand All @@ -48,6 +55,7 @@ public class AchtungSettings : ModSettings
public bool ignoreForbidden = false;
public bool ignoreRestrictions = false;
public bool ignoreAssignments = false;
public WorkMarkers workMarkers = WorkMarkers.Animated;

public override void ExposeData()
{
Expand All @@ -65,11 +73,11 @@ public override void ExposeData()

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

list.Gap(4);
list.CheckboxEnhanced("PositioningEnabled", ref Achtung.Settings.positioningEnabled);
list.Gap(10);
list.ValueLabeled("AchtungModifier", ref Achtung.Settings.achtungKey);
Expand All @@ -80,25 +88,31 @@ public static void DoWindowContents(Rect canvas)
list.Gap(-2);
list.ValueLabeled("ForceCommandMenuKey", ref Achtung.Settings.forceCommandMenuKey);
}
list.Gap(10);

list.NewColumn();
list.Indent(30 - Listing.ColumnSpacing);

list.Gap(4);
list.ValueLabeled("BreakLevel", ref Achtung.Settings.breakLevel);
list.Gap(10);
list.ValueLabeled("HealthLevel", ref Achtung.Settings.healthLevel);
list.Gap(10);
list.CheckboxEnhanced("IgnoreForbidden", ref Achtung.Settings.ignoreForbidden);
list.CheckboxEnhanced("IgnoreRestrictions", ref Achtung.Settings.ignoreRestrictions);
list.CheckboxEnhanced("IgnoreAssignments", ref Achtung.Settings.ignoreAssignments);
list.Gap(10);
list.ValueLabeled("WorkMarkers", ref Achtung.Settings.workMarkers);

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

list.Gap(10);
list.Note("Notes");
list.Gap(2);
list = new Listing_Standard { ColumnWidth = canvas.width };
canvas.yMin = canvas.yMax - 100;
list.Begin(canvas);
list.Note("Notes", GameFont.Medium);
list.Gap(4);
list.Note("Note1");
list.Gap(2);
list.Gap(4);
list.Note("Note2");

list.End();
}
}
Expand Down
16 changes: 12 additions & 4 deletions Source/Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -503,12 +503,17 @@ public static void DrawMarker(Vector3 pos)
DrawScaledMesh(MeshPool.plane10, markerMaterial, pos, Quaternion.identity, 1.25f, 1.25f);
}

public static void DrawForceIcon(Vector3 pos)
public static void DrawForceIcon(int x, int z)
{
// for strong visual debugging
// DebugPosition(pos, new Color(1f, 1f, 0f, 0.3f));

pos += new Vector3(0.75f, Altitudes.AltitudeFor(AltitudeLayer.MoteOverhead), 0.75f);
var pos = new Vector3(x + 0.75f, Altitudes.AltitudeFor(AltitudeLayer.MoteOverhead), z + 0.75f);
if (Achtung.Settings.workMarkers == WorkMarkers.Static)
{
DrawScaledMesh(MeshPool.plane10, forceIconMaterial, pos, Quaternion.identity, 0.5f, 0.5f);
return;
}
var a = 0.08f * (GenTicks.TicksAbs + 13 * pos.x + 7 * pos.z);
var rot = Quaternion.Euler(0f, Mathf.Sin(a) * 10f, 0f);
DrawScaledMesh(MeshPool.plane10, forceIconMaterial, pos, rot, 0.5f, 0.5f);
Expand Down Expand Up @@ -560,15 +565,16 @@ public static IEnumerable<Colonist> OrderColonistsAlongLine(IEnumerable<Colonist
});
}

public static void Note(this Listing_Standard listing, string name)
public static void Note(this Listing_Standard listing, string name, GameFont font = GameFont.Small)
{
if (name.CanTranslate())
{
Text.Font = GameFont.Small;
Text.Font = font;
listing.ColumnWidth -= 34;
GUI.color = Color.white;
_ = listing.Label(name.Translate());
listing.ColumnWidth += 34;
Text.Font = GameFont.Small;
}
}

Expand All @@ -593,6 +599,7 @@ public static void CheckboxEnhanced(this Listing_Standard listing, string name,
GUI.color = Color.gray;
_ = listing.Label((name + "Explained").Translate());
listing.ColumnWidth += 34;
Text.Font = GameFont.Small;

var rect = listing.GetRect(0);
rect.height = listing.CurHeight - startHeight;
Expand Down Expand Up @@ -636,6 +643,7 @@ public static void ValueLabeled<T>(this Listing_Standard listing, string name, r
GUI.color = Color.gray;
_ = listing.Label(key.Translate());
listing.ColumnWidth += 34;
Text.Font = GameFont.Small;
}

rect = listing.GetRect(0);
Expand Down

0 comments on commit 1cd4309

Please sign in to comment.