Skip to content

Commit a842c42

Browse files
authored
Merge pull request #4982 from ab9rf/setAutomaticProfession
add `Units::setAutomaticProfessions`
2 parents 3b59f47 + b700123 commit a842c42

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

docs/changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ Template for new versions:
7878
## API
7979

8080
- ``DFHack::Units``: new function ``setPathGoal``
81+
- ``Units::setAutomaticProfessions``: bay12-provided entry point to assign labors based on work details
8182

8283
## Lua
8384

library/include/modules/Units.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,10 @@ DFHACK_EXPORT bool unassignTrainer(df::unit *unit);
239239
/// to determine if the makeown operation was successful.
240240
DFHACK_EXPORT void makeown(df::unit *unit);
241241

242+
/// set appropriate labors on a unit based on current work detail settings
243+
/// (uses Bay12-provided algorithm)
244+
DFHACK_EXPORT void setAutomaticProfessions(df::unit* unit);
245+
242246
// Set the units target location and goal, clearing any existing goal or path
243247
DFHACK_EXPORT void setPathGoal(df::unit *unit, df::coord pos, df::unit_path_goal goal);
244248

library/modules/Units.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,17 @@ void Units::makeown(df::unit *unit) {
934934
(*f)(unit);
935935
}
936936

937+
void Units::setAutomaticProfessions(df::unit* unit) {
938+
CHECK_NULL_POINTER(unit);
939+
auto fp = df::global::unitst_set_automatic_professions;
940+
CHECK_NULL_POINTER(fp);
941+
942+
using FT = std::function<void(df::unit*)>;
943+
auto f = reinterpret_cast<FT*>(fp);
944+
(*f)(unit);
945+
}
946+
947+
937948
// functionality reverse-engineered from DF's unitst::set_goal
938949
void Units::setPathGoal(df::unit *unit, df::coord pos, df::unit_path_goal goal)
939950
{

0 commit comments

Comments
 (0)