Util method (in the Units class) to get a unit squad name (the translated name, or alias if set)

develop
Pierre-David Bélanger 2014-06-09 21:51:52 -04:00
parent 23acf276b4
commit bdcc00f6f7
2 changed files with 13 additions and 0 deletions

@ -256,6 +256,8 @@ DFHACK_EXPORT std::string getCasteProfessionName(int race, int caste, df::profes
DFHACK_EXPORT int8_t getProfessionColor(df::unit *unit, bool ignore_noble = false);
DFHACK_EXPORT int8_t getCasteProfessionColor(int race, int caste, df::profession pid);
DFHACK_EXPORT std::string getSquadName(df::unit *unit);
}
}
#endif

@ -69,6 +69,7 @@ using namespace std;
#include "df/unit_misc_trait.h"
#include "df/unit_skill.h"
#include "df/curse_attr_change.h"
#include "df/squad.h"
using namespace DFHack;
using namespace df::enums;
@ -1552,3 +1553,13 @@ int8_t DFHack::Units::getCasteProfessionColor(int race, int casteid, df::profess
// default to dwarven peasant color
return 3;
}
std::string DFHack::Units::getSquadName(df::unit *unit)
{
if (unit->military.squad_id == -1)
return "";
df::squad *squad = world->squads.all[unit->military.squad_id];
if (squad->alias.size() > 0)
return squad->alias;
return Translation::TranslateName(&squad->name, true);
}