Add Units::getKillCount() and expose it to Lua

develop
lethosor 2016-02-25 15:21:14 -05:00
parent 3e44aabf12
commit 25507a10f9
3 changed files with 32 additions and 16 deletions

@ -1521,6 +1521,7 @@ static const LuaWrapper::FunctionReg dfhack_units_module[] = {
WRAPM(Units, isDwarf), WRAPM(Units, isDwarf),
WRAPM(Units, isCitizen), WRAPM(Units, isCitizen),
WRAPM(Units, getAge), WRAPM(Units, getAge),
WRAPM(Units, getKillCount),
WRAPM(Units, getNominalSkill), WRAPM(Units, getNominalSkill),
WRAPM(Units, getEffectiveSkill), WRAPM(Units, getEffectiveSkill),
WRAPM(Units, getExperience), WRAPM(Units, getExperience),

@ -268,6 +268,7 @@ DFHACK_EXPORT bool isForest(df::unit* unit);
DFHACK_EXPORT bool isMarkedForSlaughter(df::unit* unit); DFHACK_EXPORT bool isMarkedForSlaughter(df::unit* unit);
DFHACK_EXPORT double getAge(df::unit *unit, bool true_age = false); DFHACK_EXPORT double getAge(df::unit *unit, bool true_age = false);
DFHACK_EXPORT int getKillCount(df::unit *unit);
DFHACK_EXPORT int getNominalSkill(df::unit *unit, df::job_skill skill_id, bool use_rust = false); DFHACK_EXPORT int getNominalSkill(df::unit *unit, df::job_skill skill_id, bool use_rust = false);
DFHACK_EXPORT int getEffectiveSkill(df::unit *unit, df::job_skill skill_id); DFHACK_EXPORT int getEffectiveSkill(df::unit *unit, df::job_skill skill_id);

@ -31,6 +31,7 @@ distribution.
#include <map> #include <map>
#include <cstring> #include <cstring>
#include <algorithm> #include <algorithm>
#include <numeric>
using namespace std; using namespace std;
#include "VersionInfo.h" #include "VersionInfo.h"
@ -47,29 +48,30 @@ using namespace std;
#include "Core.h" #include "Core.h"
#include "MiscUtils.h" #include "MiscUtils.h"
#include "df/world.h" #include "df/burrow.h"
#include "df/ui.h" #include "df/caste_raw.h"
#include "df/job.h" #include "df/creature_raw.h"
#include "df/unit_inventory_item.h" #include "df/curse_attr_change.h"
#include "df/unit_soul.h" #include "df/entity_position.h"
#include "df/nemesis_record.h" #include "df/entity_position_assignment.h"
#include "df/historical_entity.h"
#include "df/entity_raw.h" #include "df/entity_raw.h"
#include "df/entity_raw_flags.h" #include "df/entity_raw_flags.h"
#include "df/game_mode.h"
#include "df/histfig_entity_link_positionst.h"
#include "df/historical_entity.h"
#include "df/historical_figure.h" #include "df/historical_figure.h"
#include "df/historical_figure_info.h" #include "df/historical_figure_info.h"
#include "df/entity_position.h" #include "df/historical_kills.h"
#include "df/entity_position_assignment.h"
#include "df/histfig_entity_link_positionst.h"
#include "df/identity.h" #include "df/identity.h"
#include "df/burrow.h" #include "df/job.h"
#include "df/creature_raw.h" #include "df/nemesis_record.h"
#include "df/caste_raw.h" #include "df/squad.h"
#include "df/game_mode.h" #include "df/ui.h"
#include "df/unit_inventory_item.h"
#include "df/unit_misc_trait.h" #include "df/unit_misc_trait.h"
#include "df/unit_skill.h" #include "df/unit_skill.h"
#include "df/curse_attr_change.h" #include "df/unit_soul.h"
#include "df/squad.h" #include "df/world.h"
using namespace DFHack; using namespace DFHack;
using namespace df::enums; using namespace df::enums;
@ -1100,6 +1102,18 @@ double Units::getAge(df::unit *unit, bool true_age)
return cur_time - birth_time; return cur_time - birth_time;
} }
int Units::getKillCount(df::unit *unit)
{
CHECK_NULL_POINTER(unit);
auto histfig = df::historical_figure::find(unit->hist_figure_id);
if (histfig && histfig->info->kills)
return std::accumulate(histfig->info->kills->killed_count.begin(),
histfig->info->kills->killed_count.end(), 0);
else
return 0;
}
inline void adjust_skill_rating(int &rating, bool is_adventure, int value, int dwarf3_4, int dwarf1_2, int adv9_10, int adv3_4, int adv1_2) inline void adjust_skill_rating(int &rating, bool is_adventure, int value, int dwarf3_4, int dwarf1_2, int adv9_10, int adv3_4, int adv1_2)
{ {
if (is_adventure) if (is_adventure)