Skip to content

Commit

Permalink
add unassignTrainer to balance assignTrainer
Browse files Browse the repository at this point in the history
  • Loading branch information
myk002 committed Jan 27, 2024
1 parent 5476185 commit 75b0a99
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 3 deletions.
2 changes: 2 additions & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@ Template for new versions:

## API
- ``Units::assignTrainer``: assign a trainer to a trainable animal
- ``Units::unassignTrainer``: unassign a trainer from an animal

## Lua
- ``dfhack.units.isTamable``: return false for invaders to match vanilla logic
- ``dfhack.units.assignTrainer``: expose new API to Lua
- ``dfhack.units.unassignTrainer``: expose new API to Lua

## Removed
- ``nopause``: functionality has moved to `spectate`
Expand Down
7 changes: 4 additions & 3 deletions docs/dev/Lua API.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1486,10 +1486,11 @@ Units module
tile occupancy flags appropriately. Returns true if successful.

* ``dfhack.units.assignTrainer(unit[, trainer_id])``
* ``dfhack.units.unassignTrainer(unit)``

Assignes a trainer to the specified trainable unit. The trainer ID can be
omitted if "any trainer" is desired. Returns a boolean indicating whether the
operation was successful.
Assignes (or unassigns) a trainer for the specified trainable unit. The
trainer ID can be omitted if "any trainer" is desired. Returns a boolean
indicating whether the operation was successful.

* ``dfhack.units.getGeneralRef(unit, type)``

Expand Down
1 change: 1 addition & 0 deletions library/LuaApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1823,6 +1823,7 @@ static const LuaWrapper::FunctionReg dfhack_units_module[] = {
WRAPM(Units, setActionTimers),
WRAPM(Units, setGroupActionTimers),
WRAPM(Units, getUnitByNobleRole),
WRAPM(Units, unassignTrainer),
{ NULL, NULL }
};

Expand Down
1 change: 1 addition & 0 deletions library/include/modules/Units.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ DFHACK_EXPORT void setNickname(df::unit *unit, std::string nick);
DFHACK_EXPORT df::language_name *getVisibleName(df::unit *unit);

DFHACK_EXPORT bool assignTrainer(df::unit *unit, int32_t trainer_id = -1);
DFHACK_EXPORT bool unassignTrainer(df::unit *unit);

DFHACK_EXPORT df::identity *getIdentity(df::unit *unit);
DFHACK_EXPORT df::nemesis_record *getNemesis(df::unit *unit);
Expand Down
6 changes: 6 additions & 0 deletions library/modules/Units.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,12 @@ bool Units::assignTrainer(df::unit* unit, int32_t trainer_id) {
return true;
}

bool Units::unassignTrainer(df::unit* unit) {
CHECK_NULL_POINTER(unit);
return erase_from_vector(plotinfo->equipment.training_assignments,
&df::training_assignment::animal_id, unit->id);
}

// check if creature is domesticated
// seems to be the only way to really tell if it's completely safe to autonestbox it (training can revert)
bool Units::isDomesticated(df::unit* unit)
Expand Down

0 comments on commit 75b0a99

Please sign in to comment.