Add an API function for reading the nominal skill level.

develop
Alexander Gavrilov 2012-09-29 15:18:04 +04:00
parent 6fd002382f
commit 48da06ec37
4 changed files with 25 additions and 3 deletions

@ -918,6 +918,11 @@ Units module
Returns the age of the unit in years as a floating-point value. Returns the age of the unit in years as a floating-point value.
If ``true_age`` is true, ignores false identities. If ``true_age`` is true, ignores false identities.
* ``dfhack.units.getNominalSkill(unit, skill[, use_rust])``
Retrieves the nominal skill level for the given unit. If ``use_rust``
is *true*, subtracts the rust penalty.
* ``dfhack.units.getEffectiveSkill(unit, skill)`` * ``dfhack.units.getEffectiveSkill(unit, skill)``
Computes the effective rating for the given skill, taking into account exhaustion, pain etc. Computes the effective rating for the given skill, taking into account exhaustion, pain etc.

@ -828,6 +828,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, getNominalSkill),
WRAPM(Units, getEffectiveSkill), WRAPM(Units, getEffectiveSkill),
WRAPM(Units, computeMovementSpeed), WRAPM(Units, computeMovementSpeed),
WRAPM(Units, getProfessionName), WRAPM(Units, getProfessionName),

@ -233,6 +233,7 @@ DFHACK_EXPORT bool isDwarf(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 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);
DFHACK_EXPORT int computeMovementSpeed(df::unit *unit); DFHACK_EXPORT int computeMovementSpeed(df::unit *unit);

@ -876,7 +876,7 @@ inline void adjust_skill_rating(int &rating, bool is_adventure, int value, int d
} }
} }
int Units::getEffectiveSkill(df::unit *unit, df::job_skill skill_id) int Units::getNominalSkill(df::unit *unit, df::job_skill skill_id, bool use_rust)
{ {
CHECK_NULL_POINTER(unit); CHECK_NULL_POINTER(unit);
@ -892,9 +892,24 @@ int Units::getEffectiveSkill(df::unit *unit, df::job_skill skill_id)
df::enum_field<df::job_skill,int16_t> key(skill_id); df::enum_field<df::job_skill,int16_t> key(skill_id);
auto skill = binsearch_in_vector(unit->status.current_soul->skills, &df::unit_skill::id, key); auto skill = binsearch_in_vector(unit->status.current_soul->skills, &df::unit_skill::id, key);
int rating = 0;
if (skill) if (skill)
rating = std::max(0, int(skill->rating) - skill->rusty); {
int rating = int(skill->rating);
if (use_rust)
rating -= skill->rusty;
return std::max(0, rating);
}
return 0;
}
int Units::getEffectiveSkill(df::unit *unit, df::job_skill skill_id)
{
/*
* This is 100% reverse-engineered from DF code.
*/
int rating = getNominalSkill(unit, skill_id, true);
// Apply special states // Apply special states