summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--LUA_API.rst5
-rw-r--r--library/LuaApi.cpp1
-rw-r--r--library/include/modules/Units.h1
-rw-r--r--library/modules/Units.cpp21
4 files changed, 25 insertions, 3 deletions
diff --git a/LUA_API.rst b/LUA_API.rst
index f532d221..bf7ee45a 100644
--- a/LUA_API.rst
+++ b/LUA_API.rst
@@ -918,6 +918,11 @@ Units module
Returns the age of the unit in years as a floating-point value.
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)``
Computes the effective rating for the given skill, taking into account exhaustion, pain etc.
diff --git a/library/LuaApi.cpp b/library/LuaApi.cpp
index b2d41dc1..dab99f48 100644
--- a/library/LuaApi.cpp
+++ b/library/LuaApi.cpp
@@ -828,6 +828,7 @@ static const LuaWrapper::FunctionReg dfhack_units_module[] = {
WRAPM(Units, isDwarf),
WRAPM(Units, isCitizen),
WRAPM(Units, getAge),
+ WRAPM(Units, getNominalSkill),
WRAPM(Units, getEffectiveSkill),
WRAPM(Units, computeMovementSpeed),
WRAPM(Units, getProfessionName),
diff --git a/library/include/modules/Units.h b/library/include/modules/Units.h
index 65f0b58a..2019eb65 100644
--- a/library/include/modules/Units.h
+++ b/library/include/modules/Units.h
@@ -233,6 +233,7 @@ DFHACK_EXPORT bool isDwarf(df::unit *unit);
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 computeMovementSpeed(df::unit *unit);
diff --git a/library/modules/Units.cpp b/library/modules/Units.cpp
index 01b7b50f..2644f4ab 100644
--- a/library/modules/Units.cpp
+++ b/library/modules/Units.cpp
@@ -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);
@@ -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);
auto skill = binsearch_in_vector(unit->status.current_soul->skills, &df::unit_skill::id, key);
- int rating = 0;
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