summaryrefslogtreecommitdiff
path: root/library/modules
diff options
context:
space:
mode:
authorAlexander Gavrilov2012-09-09 12:51:08 +0400
committerAlexander Gavrilov2012-09-09 12:51:08 +0400
commitec3d489bda19f8ab2a45fbb19d7259ea3f4ad75b (patch)
treec2acb9e8fe785785f3bdb2cfc88a7e0c7400ae20 /library/modules
parenta36fe25e7249c60094a6347726f961779cf3b98a (diff)
downloaddfhack-ec3d489bda19f8ab2a45fbb19d7259ea3f4ad75b.tar.gz
dfhack-ec3d489bda19f8ab2a45fbb19d7259ea3f4ad75b.tar.bz2
dfhack-ec3d489bda19f8ab2a45fbb19d7259ea3f4ad75b.tar.xz
Move curse-affected attribute value getters to the core.
Diffstat (limited to 'library/modules')
-rw-r--r--library/modules/Units.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/library/modules/Units.cpp b/library/modules/Units.cpp
index 6a672b58..1565dbbd 100644
--- a/library/modules/Units.cpp
+++ b/library/modules/Units.cpp
@@ -617,6 +617,58 @@ df::nemesis_record *Units::getNemesis(df::unit *unit)
return NULL;
}
+
+bool Units::isHidingCurse(df::unit *unit)
+{
+ if (!unit->job.hunt_target)
+ {
+ auto identity = Units::getIdentity(unit);
+ if (identity && identity->unk_4c == 0)
+ return true;
+ }
+
+ return false;
+}
+
+int Units::getPhysicalAttrValue(df::unit *unit, df::physical_attribute_type attr)
+{
+ auto &aobj = unit->body.physical_attrs[attr];
+ int value = std::max(0, aobj.value - aobj.soft_demotion);
+
+ if (auto mod = unit->curse.attr_change)
+ {
+ int mvalue = (value * mod->phys_att_perc[attr]) + mod->phys_att_add[attr];
+
+ if (isHidingCurse(unit))
+ value = std::min(value, mvalue);
+ else
+ value = mvalue;
+ }
+
+ return value;
+}
+
+int Units::getMentalAttrValue(df::unit *unit, df::mental_attribute_type attr)
+{
+ auto soul = unit->status.current_soul;
+ if (!soul) return 0;
+
+ auto &aobj = soul->mental_attrs[attr];
+ int value = std::max(0, aobj.value - aobj.soft_demotion);
+
+ if (auto mod = unit->curse.attr_change)
+ {
+ int mvalue = (value * mod->ment_att_perc[attr]) + mod->ment_att_add[attr];
+
+ if (isHidingCurse(unit))
+ value = std::min(value, mvalue);
+ else
+ value = mvalue;
+ }
+
+ return value;
+}
+
static bool casteFlagSet(int race, int caste, df::caste_raw_flags flag)
{
auto creature = df::creature_raw::find(race);