Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Units::setAutomaticProfessions #4982

Merged
merged 2 commits into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Template for new versions:
## Documentation

## API
- ``Units::setAutomaticProfessions``: bay12-provided entry point to assign labors based on work details
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plz move down to Future section -- this is the template : )

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops :)


## Lua

Expand Down
4 changes: 4 additions & 0 deletions library/include/modules/Units.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
11 changes: 11 additions & 0 deletions library/modules/Units.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<void(df::unit*)>;
auto f = reinterpret_cast<FT*>(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)
{
Expand Down