Merge remote-tracking branch 'nornagon/unit-description' into develop

develop
lethosor 2020-01-13 23:31:23 -05:00
commit 5eca50476e
6 changed files with 35 additions and 0 deletions

@ -1611,6 +1611,7 @@ static const LuaWrapper::FunctionReg dfhack_units_module[] = {
WRAPM(Units, isOwnCiv),
WRAPM(Units, isOwnGroup),
WRAPM(Units, isOwnRace),
WRAPM(Units, getPhysicalDescription),
WRAPM(Units, getRaceName),
WRAPM(Units, getRaceNamePlural),
WRAPM(Units, getRaceBabyName),

@ -45,6 +45,17 @@ using std::endl;
#define DFHACK_FUNCTION_SIG __func__
#endif
#ifdef _WIN32
// On x86 MSVC, __thiscall passes |this| in ECX. On x86_64, __thiscall is the
// same as the standard calling convention.
// See https://docs.microsoft.com/en-us/cpp/cpp/thiscall for more info.
#define THISCALL __thiscall
#else
// On other platforms, there's no special calling convention for calling member
// functions.
#define THISCALL
#endif
namespace DFHack {
class color_ostream;
}

@ -120,6 +120,7 @@ DFHACK_EXPORT bool isVisible(df::unit* unit);
DFHACK_EXPORT std::string getRaceNameById(int32_t race_id);
DFHACK_EXPORT std::string getRaceName(df::unit* unit);
DFHACK_EXPORT std::string getPhysicalDescription(df::unit* unit);
DFHACK_EXPORT std::string getRaceNamePluralById(int32_t race_id);
DFHACK_EXPORT std::string getRaceNamePlural(df::unit* unit);
DFHACK_EXPORT std::string getRaceBabyNameById(int32_t race_id);

@ -541,6 +541,25 @@ string Units::getRaceName(df::unit* unit)
return getRaceNameById(unit->race);
}
void df_unit_get_physical_description(df::unit* unit, string* out_str)
{
static auto* const fn =
reinterpret_cast<void(THISCALL *)(df::unit*, string*)>(
Core::getInstance().vinfo->getAddress("unit_get_physical_description"));
if (fn)
fn(unit, out_str);
else
*out_str = "";
}
string Units::getPhysicalDescription(df::unit* unit)
{
CHECK_NULL_POINTER(unit);
string str;
df_unit_get_physical_description(unit, &str);
return str;
}
// get plural of race name (used for display in autobutcher UI and for sorting the watchlist)
string Units::getRaceNamePluralById(int32_t id)
{

@ -457,6 +457,7 @@ message UnitAppearance
optional Hair beard = 6;
optional Hair moustache = 7;
optional Hair sideburns = 8;
optional string physical_description = 9;
}
message InventoryItem

@ -1734,6 +1734,8 @@ static command_result GetUnitListInside(color_ostream &stream, const BlockReques
appearance->add_colors(unit->appearance.colors[j]);
appearance->set_size_modifier(unit->appearance.size_modifier);
appearance->set_physical_description(Units::getPhysicalDescription(unit));
send_unit->set_profession_id(unit->profession);
std::vector<Units::NoblePosition> pvec;