Skip to content

Commit

Permalink
almost release candidate (missing some tutors)
Browse files Browse the repository at this point in the history
  • Loading branch information
pardeike committed Aug 22, 2023
1 parent 2eb6a1c commit e4d9b45
Show file tree
Hide file tree
Showing 18 changed files with 203 additions and 41 deletions.
Binary file modified 1.4/Assemblies/AchtungMod.dll
Binary file not shown.
19 changes: 0 additions & 19 deletions Defs/WorkTypeDefs/WorkTypes.xml

This file was deleted.

9 changes: 9 additions & 0 deletions Languages/Dutch/DefInjected/WorkTypeDef/WorkTypes.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<LanguageData>

<Rescuing.labelShort>Redden</Rescuing.labelShort>
<Rescuing.pawnLabel>Redden</Rescuing.pawnLabel>
<Rescuing.gerundLabel>Reddend</Rescuing.gerundLabel>
<Rescuing.description>Kolonisten redden</Rescuing.description>

</LanguageData>
3 changes: 3 additions & 0 deletions Languages/Dutch/Keyed/Text.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
<ForceCommandMenuModeExplained>Auto = normaal gedrag (wapenstatus beslist)\nToon Menu = Toets ingedrukt houden voor contextmenu\nZet Positie = Toets ingedrukt houden om naar positie te bevelen</ForceCommandMenuModeExplained>
<ForceCommandMenuKeyTitle>Context Menu Toets</ForceCommandMenuKeyTitle>

<RescueEnabledTitle>'Redden' werkprioriteit kolom</RescueEnabledTitle>
<RescueEnabledExplained>Maakt het automatisch redden van pionnen mogelijk en voegt een kolom toe aan het werk-tabblad</RescueEnabledExplained>

<ForcedCommandState>Bevolen te werken tot het klaar is.</ForcedCommandState>

<ForceMenuButtonText>Dwingen</ForceMenuButtonText>
Expand Down
3 changes: 3 additions & 0 deletions Languages/English/Keyed/Text.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
<ForceCommandMenuModeExplained>Auto = normal behavior (draft status decides)\nShow Menu = Hold key for context menu\nSet Position = Hold key to order to position</ForceCommandMenuModeExplained>
<ForceCommandMenuKeyTitle>Context Menu Key</ForceCommandMenuKeyTitle>

<RescueEnabledTitle>'Rescue' work priority column</RescueEnabledTitle>
<RescueEnabledExplained>Enables the automatic rescue of pawns and adds a column on the work tab</RescueEnabledExplained>

<ForcedCommandState>Ordered to work until done.</ForcedCommandState>

<ForceMenuButtonText>Force</ForceMenuButtonText>
Expand Down
9 changes: 9 additions & 0 deletions Languages/German/DefInjected/WorkTypeDef/WorkTypes.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<LanguageData>

<Rescuing.labelShort>Rettung</Rescuing.labelShort>
<Rescuing.pawnLabel>Rettung</Rescuing.pawnLabel>
<Rescuing.gerundLabel>Am Retten von</Rescuing.gerundLabel>
<Rescuing.description>Rette Kolonisten</Rescuing.description>

</LanguageData>
3 changes: 3 additions & 0 deletions Languages/German/Keyed/Text.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
<ForceCommandMenuModeExplained>Auto = Normales Verhalten (Kampfmodus entscheidet)\nMenü anzeigen = Taste für Kontextmenüanzeige gedrückt halten\nPositionieren = Taste zum Positionieren gedrückt halten</ForceCommandMenuModeExplained>
<ForceCommandMenuKeyTitle>Kontextmenü-Taste</ForceCommandMenuKeyTitle>

<RescueEnabledTitle>'Rettung' Arbeitsprioritätsspalte</RescueEnabledTitle>
<RescueEnabledExplained>Aktiviert die automatische Rettung von Kolonisten und fügt eine Spalte in der Arbeitsansicht hinzu</RescueEnabledExplained>

<ForcedCommandState>Gezwungen zu arbeiten, bis alles erledigt ist.</ForcedCommandState>

<ForceMenuButtonText>Erzw.</ForceMenuButtonText>
Expand Down
9 changes: 9 additions & 0 deletions Languages/Spanish/DefInjected/WorkTypeDef/WorkTypes.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<LanguageData>

<Rescuing.labelShort>Rescate</Rescuing.labelShort>
<Rescuing.pawnLabel>Rescate</Rescuing.pawnLabel>
<Rescuing.gerundLabel>Rescatando</Rescuing.gerundLabel>
<Rescuing.description>Rescatar colonos</Rescuing.description>

</LanguageData>
3 changes: 3 additions & 0 deletions Languages/Spanish/Keyed/Text.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
<ForceCommandMenuModeExplained>Auto = comportamiento normal (el estado de reclutamiento decide)\nMostrar menú = Mantenga presionada la tecla para el menú\nEstablecer posición = Mantenga presionada la tecla para posicionamiento</ForceCommandMenuModeExplained>
<ForceCommandMenuKeyTitle>Tecla del menú contextual</ForceCommandMenuKeyTitle>

<RescueEnabledTitle>Columna de prioridad de trabajo 'Rescate'</RescueEnabledTitle>
<RescueEnabledExplained>Habilita el rescate automático de peones y añade una columna en la pestaña de trabajo</RescueEnabledExplained>

<ForcedCommandState>Tiene la orden de trabajar hasta terminar la tarea.</ForcedCommandState>

<ForceMenuButtonText>Forzar</ForceMenuButtonText>
Expand Down
9 changes: 9 additions & 0 deletions Languages/Swedish/DefInjected/WorkTypeDef/WorkTypes.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<LanguageData>

<Rescuing.labelShort>Rädda</Rescuing.labelShort>
<Rescuing.pawnLabel>Rädda</Rescuing.pawnLabel>
<Rescuing.gerundLabel>Räddande</Rescuing.gerundLabel>
<Rescuing.description>Rädda kolonister</Rescuing.description>

</LanguageData>
3 changes: 3 additions & 0 deletions Languages/Swedish/Keyed/Text.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
<ForceCommandMenuModeExplained>Auto = Vanlig beteende (kampmodus bestämmer)\nVisa meny = Håll knappen för kontextmenyn\nPositionera = Håll knappen för att beordra till position</ForceCommandMenuModeExplained>
<ForceCommandMenuKeyTitle>Kontextmenyknapp</ForceCommandMenuKeyTitle>

<RescueEnabledTitle>'Rädda' arbetsprioritetskolumn</RescueEnabledTitle>
<RescueEnabledExplained>Aktiverar automatisk räddning av kolonister och lägger till en kolumn på arbetsfliken</RescueEnabledExplained>

<ForcedCommandState>Kommenderad att slutföra sitt arbete.</ForcedCommandState>

<ForceMenuButtonText>Tvinga</ForceMenuButtonText>
Expand Down
6 changes: 0 additions & 6 deletions Patches/DoctorRescue.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@
<Operation Class="PatchOperationSequence">
<success>Always</success>
<operations>
<li Class="PatchOperationReplace">
<xpath>/Defs/WorkGiverDef[defName="DoctorRescue"]/workType</xpath>
<value>
<workType>Rescuing</workType>
</value>
</li>
<li Class="PatchOperationReplace">
<xpath>/Defs/WorkGiverDef[defName="DoctorRescue"]/directOrderable</xpath>
<value>
Expand Down
9 changes: 3 additions & 6 deletions Source/Achtung.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@
</PropertyGroup>

<ItemGroup>
<Content Include="..\Defs\**\*.xml">
<Link>Defs\%(RecursiveDir)%(FileName)%(Extension)</Link>
</Content>
<Content Include="..\Languages\**\Keyed\*.xml">
<Content Include="..\Languages\**\*.xml">
<Link>Languages\%(RecursiveDir)%(FileName)%(Extension)</Link>
</Content>
<Content Include="..\Patches\**\*.xml">
Expand Down Expand Up @@ -94,7 +91,7 @@
<!--<PostBuildEvent>
mkdir -p /Users/ap/Library/Application\ Support/Steam/steamapps/common/RimWorld/RimWorldMac.app/Mods/Achtung
pushd ../..
cp -rf 1.1 1.2 1.3 1.4 About Assemblies Defs Languages Patches Resources Textures LoadFolders.xml /Users/ap/Library/Application\ Support/Steam/steamapps/common/RimWorld/RimWorldMac.app/Mods/Achtung/
cp -rf 1.1 1.2 1.3 1.4 About Assemblies Languages Patches Resources Textures LoadFolders.xml /Users/ap/Library/Application\ Support/Steam/steamapps/common/RimWorld/RimWorldMac.app/Mods/Achtung/
popd
pushd /Users/ap/Library/Application\ Support/Steam/steamapps/common/RimWorld/RimWorldMac.app/Mods
rm -f Achtung.zip
Expand All @@ -109,7 +106,7 @@
ModBuilder XMLPut -file "$(SolutionDir)About\Manifest.xml" -xpath /Manifest/version -value "{{$(MSBuildProjectName)-version}}"
)
if defined INSTALL_MOD (
"%INSTALL_MOD%" "$(Configuration)" "$(SolutionDir)" "$(MSBuildProjectName)" "1.1 1.2 1.3 1.4 About Assemblies Defs Languages Patches Resources Textures" "LoadFolders.xml"
"%INSTALL_MOD%" "$(Configuration)" "$(SolutionDir)" "$(MSBuildProjectName)" "1.1 1.2 1.3 1.4 About Assemblies Languages Patches Resources Textures" "LoadFolders.xml"
)
</PostBuildEvent>
<Company>Brrainz</Company>
Expand Down
102 changes: 102 additions & 0 deletions Source/DynamicWorkTypes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
using HarmonyLib;
using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using Verse;

namespace AchtungMod
{
public class DynamicWorkTypes
{
static void Reload<T>() where T : Def
{
DefDatabase<T>.ClearCachedData();
DefDatabase<T>.ResolveAllReferences(false, true);
}

static void UpdatePawns()
{
Find.Maps.Do(map => map.mapPawns.AllPawnsSpawned.DoIf(p => p.workSettings != null, p =>
{
p.workSettings.priorities = null;
p.workSettings.workGiversDirty = true;
p.workSettings.EnableAndInitialize();
p.workSettings.CacheWorkGiversInOrder();
p.Notify_DisabledWorkTypesChanged();
}));
}

static void Update(PawnTableDef workTable)
{
var moveWorkTypeLabelDown = false;
for (var i = 0; i < workTable.columns.Count; i++)
{
moveWorkTypeLabelDown = !moveWorkTypeLabelDown;
workTable.columns[i].moveWorkTypeLabelDown = moveWorkTypeLabelDown;
}

var controller = AccessTools.TypeByName("WorkTab.Controller");
if (controller != null)
{
var columns = new List<PawnColumnDef>(workTable.columns);
Traverse.Create(controller).Field("allColumns").SetValue(columns);
}
}

public static WorkTypeDef AddWorkTypeDef(WorkTypeDef def, WorkGiverDef workgiver)
{
DefDatabase<WorkTypeDef>.Add(def);

var saved = workgiver.workType;
workgiver.workType = def;

Reload<WorkTypeDef>();
Reload<WorkGiverDef>();

var workerClass = AccessTools.TypeByName("WorkTab.PawnColumnWorker_WorkType") ?? typeof(PawnColumnWorker_WorkPriority);
var pawnColumnDefType = AccessTools.TypeByName("WorkTab.PawnColumnDef_WorkGiver") ?? typeof(PawnColumnDef);

var columnDef = (PawnColumnDef)Activator.CreateInstance(pawnColumnDefType);
Traverse.Create(columnDef).Field("workgiver").SetValue(workgiver);
columnDef.defName = $"WorkPriority_{def.defName}";
columnDef.workType = def;
columnDef.workerClass = workerClass;
columnDef.sortable = true;
columnDef.generated = true;
columnDef.modContentPack = def.modContentPack;
columnDef.PostLoad();
DefDatabase<PawnColumnDef>.Add(columnDef);

var workTable = PawnTableDefOf.Work;
var prio = columnDef.workType.naturalPriority;
var idx = workTable.columns.FirstIndexOf(col => col.workType != null && col.workType.naturalPriority < prio);
workTable.columns.Insert(idx, columnDef);
Update(workTable);

Reload<PawnColumnDef>();
Reload<PawnTableDef>();
UpdatePawns();

return saved;
}

public static void RemoveWorkTypeDef(WorkTypeDef def, WorkTypeDef savedDef, WorkGiverDef workGiver)
{
workGiver.workType = savedDef;
DefDatabase<WorkTypeDef>.Remove(def);
var columnDef = DefDatabase<PawnColumnDef>.AllDefsListForReading.First(d => d.workType == def);
DefDatabase<PawnColumnDef>.Remove(columnDef);

PawnTableDef workTable = PawnTableDefOf.Work;
workTable.columns.RemoveAll(col => col.workType == def);
Update(workTable);

Reload<WorkTypeDef>();
Reload<WorkGiverDef>();
Reload<PawnColumnDef>();
Reload<PawnTableDef>();
UpdatePawns();
}
}
}
13 changes: 10 additions & 3 deletions Source/ForcedJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -667,10 +667,17 @@ public static Job GetThingJob(this Thing thing, Pawn pawn, WorkGiver_Scanner sca
{
if (thing == null || thing.Spawned == false)
return null;
var potentialWork = scanner.PotentialWorkThingRequest.Accepts(thing) || scanner.PotentialWorkThingsGlobal(pawn) != null && scanner.PotentialWorkThingsGlobal(pawn).Contains(thing);
if ((scanner as WorkGiver_Haul) != null && potentialWork == false)
var potentialWork = scanner.PotentialWorkThingRequest.Accepts(thing);
if (potentialWork == false)
{
var workThingsGlobal = scanner.PotentialWorkThingsGlobal(pawn);
workThingsGlobal ??= pawn.Map.listerThings.ThingsMatching(scanner.PotentialWorkThingRequest);
if (workThingsGlobal != null && workThingsGlobal.Contains(thing))
potentialWork = true;
}
if (potentialWork == false && scanner is WorkGiver_Haul)
potentialWork = ShouldBeHaulable(thing);
else if ((scanner as WorkGiver_Merge) != null && potentialWork == false)
else if (potentialWork == false && scanner is WorkGiver_Merge)
potentialWork = ShouldBeMergeable(thing);

if (potentialWork)
Expand Down
8 changes: 7 additions & 1 deletion Source/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ static class World_FinalizeInit_Patch
public static void Prefix()
{
ForcedWork.Instance = null;

var rescuing = DefDatabase<WorkTypeDef>.GetNamedSilentFail(Tools.rescuingWorkTypeDef.defName);
var doctorRescueWorkGiver = DefDatabase<WorkGiverDef>.GetNamed("DoctorRescue");
if (rescuing == null && Achtung.Settings.rescueEnabled)
Tools.savedWorkTypeDef = DynamicWorkTypes.AddWorkTypeDef(Tools.rescuingWorkTypeDef, doctorRescueWorkGiver);

Log.Message($"Achtung v{Performance.GetModVersionString()} Info: To make Achtung log some performance info, create an empty 'AchtungPerformance.txt' file in same directory as Player.log");
}
}
Expand Down Expand Up @@ -759,7 +765,7 @@ static bool IgnoreForbiddenHauling(WorkGiver_Scanner workgiver, Thing thing)
return workgiver.Ignorable();
}

public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, MethodBase original)
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
var m_GetPriority = AccessTools.Method(typeof(Pawn_WorkSettings), nameof(Pawn_WorkSettings.GetPriority));
var floatMenuOptionConstructorArgs = new[] { typeof(string), typeof(Action), typeof(MenuOptionPriority), typeof(Action<Rect>), typeof(Thing), typeof(float), typeof(Func<Rect, bool>), typeof(WorldObject), typeof(bool), typeof(int) };
Expand Down
22 changes: 16 additions & 6 deletions Source/Settings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using UnityEngine;
using RimWorld;
using UnityEngine;
using Verse;

namespace AchtungMod
Expand Down Expand Up @@ -47,6 +48,7 @@ public enum WorkMarkers
public class AchtungSettings : ModSettings
{
public bool positioningEnabled = true;
public bool rescueEnabled = true;
public AchtungModKey achtungKey = AchtungModKey.Alt;
public CommandMenuMode forceCommandMenuMode = CommandMenuMode.PressForMenu;
public AchtungModKey forceCommandMenuKey = AchtungModKey.Ctrl;
Expand Down Expand Up @@ -101,11 +103,19 @@ public static void DoWindowContents(Rect canvas)
list.Gap(-2);
list.ValueLabeled("ForceCommandMenuKey", ref Achtung.Settings.forceCommandMenuKey);
}
list.Gap(20);
var r = list.GetRect(Tools.menuExampleTexture.height);
r.width = r.height * Tools.menuExampleTexture.width / Tools.menuExampleTexture.height;
GUI.color = Color.white;
GenUI.DrawTextureWithMaterial(r, Tools.menuExampleTexture, null, new Rect(0f, 0f, 1f, 1f));
list.Gap(18);
list.CheckboxEnhanced("RescueEnabled", ref Achtung.Settings.rescueEnabled);
var rescuing = DefDatabase<WorkTypeDef>.GetNamedSilentFail(Tools.rescuingWorkTypeDef.defName);
var doctorRescueWorkGiver = DefDatabase<WorkGiverDef>.GetNamed("DoctorRescue");
if (rescuing == null && Achtung.Settings.rescueEnabled)
Tools.savedWorkTypeDef = DynamicWorkTypes.AddWorkTypeDef(Tools.rescuingWorkTypeDef, doctorRescueWorkGiver);
else if (rescuing != null && Achtung.Settings.rescueEnabled == false)
DynamicWorkTypes.RemoveWorkTypeDef(Tools.rescuingWorkTypeDef, Tools.savedWorkTypeDef, doctorRescueWorkGiver);

// var r = list.GetRect(Tools.menuExampleTexture.height);
// r.width = r.height * Tools.menuExampleTexture.width / Tools.menuExampleTexture.height;
// GUI.color = Color.white;
// GenUI.DrawTextureWithMaterial(r, Tools.menuExampleTexture, null, new Rect(0f, 0f, 1f, 1f));

list.NewColumn();
list.curX += 30 - Listing.ColumnSpacing;
Expand Down
14 changes: 14 additions & 0 deletions Source/Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ static class Tools
public static Material lineMaterial;
public static Material forceRadiusMaterial = SolidColorMaterials.SimpleSolidColorMaterial(Color.white.ToTransparent(0.5f));
public static string goHereLabel;
public static WorkTypeDef savedWorkTypeDef = null;

public static WorkTypeDef rescuingWorkTypeDef = new WorkTypeDef()
{
defName = "Rescuing",
labelShort = "rescue",
pawnLabel = "Rescue",
gerundLabel = "Rescuing",
description = "Rescue colonists",
verb = "Rescue",
naturalPriority = 1310,
alwaysStartActive = true,
workTags = WorkTags.Caring | WorkTags.Commoner | WorkTags.AllWork
};

private static string _version;
public static string Version
Expand Down

0 comments on commit e4d9b45

Please sign in to comment.