Add a few functions to retrieve unit social activities

develop
lethosor 2017-04-28 17:25:58 -04:00
parent 318cf92f0b
commit 71b553b305
3 changed files with 29 additions and 0 deletions

@ -62,6 +62,8 @@ distribution.
#include "MiscUtils.h"
#include "df/activity_entry.h"
#include "df/activity_event.h"
#include "df/job.h"
#include "df/job_item.h"
#include "df/building.h"
@ -1580,6 +1582,8 @@ static const LuaWrapper::FunctionReg dfhack_units_module[] = {
WRAPM(Units, isUndead),
WRAPM(Units, isGelded),
WRAPM(Units, isDomesticated),
WRAPM(Units, getMainSocialActivity),
WRAPM(Units, getMainSocialEvent),
{ NULL, NULL }
};

@ -41,6 +41,8 @@ distribution.
namespace df
{
struct activity_entry;
struct activity_event;
struct nemesis_record;
struct burrow;
struct identity;
@ -301,6 +303,10 @@ DFHACK_EXPORT int8_t getProfessionColor(df::unit *unit, bool ignore_noble = fals
DFHACK_EXPORT int8_t getCasteProfessionColor(int race, int caste, df::profession pid);
DFHACK_EXPORT std::string getSquadName(df::unit *unit);
DFHACK_EXPORT df::activity_entry *getMainSocialActivity(df::unit *unit);
DFHACK_EXPORT df::activity_event *getMainSocialEvent(df::unit *unit);
}
}
#endif

@ -48,6 +48,7 @@ using namespace std;
#include "Core.h"
#include "MiscUtils.h"
#include "df/activity_entry.h"
#include "df/burrow.h"
#include "df/caste_raw.h"
#include "df/creature_raw.h"
@ -1831,6 +1832,24 @@ std::string Units::getSquadName(df::unit *unit)
return Translation::TranslateName(&squad->name, true);
}
df::activity_entry *Units::getMainSocialActivity(df::unit *unit)
{
CHECK_NULL_POINTER(unit);
if (unit->social_activities.empty())
return nullptr;
return df::activity_entry::find(unit->social_activities[unit->social_activities.size() - 1]);
}
df::activity_event *Units::getMainSocialEvent(df::unit *unit)
{
CHECK_NULL_POINTER(unit);
df::activity_entry *entry = getMainSocialActivity(unit);
if (!entry || entry->events.empty())
return nullptr;
return entry->events[entry->events.size() - 1];
}
bool Units::isMerchant(df::unit* unit)
{
CHECK_NULL_POINTER(unit);