From 7bcbefe938eb29a89c00b08b375c40ec6be2c989 Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Fri, 4 Oct 2024 21:58:37 -0500 Subject: [PATCH 1/2] add `Units::setAutomaticProfessions` uses bay12-provided export --- docs/changelog.txt | 1 + library/include/modules/Units.h | 4 ++++ library/modules/Units.cpp | 11 +++++++++++ 3 files changed, 16 insertions(+) diff --git a/docs/changelog.txt b/docs/changelog.txt index 88b97403e4..17624f3df3 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -35,6 +35,7 @@ Template for new versions: ## Documentation ## API +- ``Units::setAutomaticProfessions``: bay12-provided entry point to assign labors based on work details ## Lua diff --git a/library/include/modules/Units.h b/library/include/modules/Units.h index 9b356de105..f398d135f8 100644 --- a/library/include/modules/Units.h +++ b/library/include/modules/Units.h @@ -239,6 +239,10 @@ DFHACK_EXPORT bool unassignTrainer(df::unit *unit); /// to determine if the makeown operation was successful. DFHACK_EXPORT void makeown(df::unit *unit); +/// set appropriate labors on a unit based on current work detail settings +/// (uses Bay12-provided algorithm) +DFHACK_EXPORT void setAutomaticProfessions(df::unit* unit); + // Set the units target location and goal, clearing any existing goal or path DFHACK_EXPORT void setPathGoal(df::unit *unit, df::coord pos, df::unit_path_goal goal); diff --git a/library/modules/Units.cpp b/library/modules/Units.cpp index 8db7c9d525..2c78f0bb4b 100644 --- a/library/modules/Units.cpp +++ b/library/modules/Units.cpp @@ -934,6 +934,17 @@ void Units::makeown(df::unit *unit) { (*f)(unit); } +void Units::setAutomaticProfessions(df::unit* unit) { + CHECK_NULL_POINTER(unit); + auto fp = df::global::unitst_set_automatic_professions; + CHECK_NULL_POINTER(fp); + + using FT = std::function; + auto f = reinterpret_cast(fp); + (*f)(unit); +} + + // functionality reverse-engineered from DF's unitst::set_goal void Units::setPathGoal(df::unit *unit, df::coord pos, df::unit_path_goal goal) { From b70012321a6097b827655e485eecc100dc407ec5 Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Sat, 5 Oct 2024 19:07:16 -0500 Subject: [PATCH 2/2] undo brain damage --- docs/changelog.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index 17624f3df3..8fc230423a 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -35,7 +35,6 @@ Template for new versions: ## Documentation ## API -- ``Units::setAutomaticProfessions``: bay12-provided entry point to assign labors based on work details ## Lua @@ -76,6 +75,7 @@ Template for new versions: ## API - ``DFHack::Units``: new function ``setPathGoal`` +- ``Units::setAutomaticProfessions``: bay12-provided entry point to assign labors based on work details ## Lua