Skip to content

Commit

Permalink
return original unit name instead of hf name
Browse files Browse the repository at this point in the history
when there is no impersonated identity
  • Loading branch information
myk002 committed Dec 30, 2024
1 parent 67bc599 commit 1e21fbf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Template for new versions:

## API
- ``Units::isUnitInBox``, ``Units::getUnitsInBox``: add versions accepting pos arguments
- ``Units::getVisibleName``: when acting on a unit without an impersonated identity, returns the unit's name structure instead of the associated histfig's name structure

## Lua
- ``dfhack.units.isUnitInBox``, ``dfhack.units.getUnitsInBox``: add versions accepting pos arguments
Expand Down
8 changes: 6 additions & 2 deletions library/modules/Units.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -897,8 +897,12 @@ df::language_name *Units::getVisibleName(df::historical_figure *hf) {

df::language_name *Units::getVisibleName(df::unit *unit) {
CHECK_NULL_POINTER(unit);
auto hf = df::historical_figure::find(unit->hist_figure_id);
return hf ? getVisibleName(hf) : &unit->name;
if (auto identity = getIdentity(unit))
{
auto imp_hf = df::historical_figure::find(identity->impersonated_hf);
return (imp_hf && imp_hf->name.has_name) ? &imp_hf->name : &identity->name;
}
return &unit->name;
}

bool Units::assignTrainer(df::unit *unit, int32_t trainer_id) {
Expand Down

0 comments on commit 1e21fbf

Please sign in to comment.