From 7884a927c96bafa1158a0d19772e0c45a35ca86c Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Fri, 19 Oct 2012 18:56:22 +0200 Subject: [PATCH] Issue #68: added dead flag to CreatureStats --- apps/openmw/mwmechanics/creaturestats.cpp | 28 +++++++++++++++++++---- apps/openmw/mwmechanics/creaturestats.hpp | 6 ++++- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwmechanics/creaturestats.cpp b/apps/openmw/mwmechanics/creaturestats.cpp index 4f699bba0..1ce7bdb93 100644 --- a/apps/openmw/mwmechanics/creaturestats.cpp +++ b/apps/openmw/mwmechanics/creaturestats.cpp @@ -10,7 +10,7 @@ namespace MWMechanics { CreatureStats::CreatureStats() - : mLevelHealthBonus(0.f) + : mLevel (0), mHello (0), mFight (0), mFlee (0), mAlarm (0), mLevelHealthBonus(0.f), mDead (false) { } @@ -156,17 +156,17 @@ namespace MWMechanics void CreatureStats::setHealth(const DynamicStat &value) { - mDynamic[0] = value; + setDynamic (0, value); } void CreatureStats::setMagicka(const DynamicStat &value) { - mDynamic[1] = value; + setDynamic (1, value); } void CreatureStats::setFatigue(const DynamicStat &value) { - mDynamic[2] = value; + setDynamic (2, value); } void CreatureStats::setDynamic (int index, const DynamicStat &value) @@ -175,6 +175,9 @@ namespace MWMechanics throw std::runtime_error("dynamic stat index is out of range"); mDynamic[index] = value; + + if (index==2 && mDynamic[index].getCurrent()<1) + mDead = true; } void CreatureStats::setLevel(int level) @@ -211,4 +214,21 @@ namespace MWMechanics { mAlarm = value; } + + bool CreatureStats::isDead() const + { + return mDead; + } + + void CreatureStats::resurrect() + { + if (mDead) + { + if (mDynamic[0].getCurrent()<1) + mDynamic[0].setCurrent (1); + + if (mDynamic[0].getCurrent()>=1) + mDead = false; + } + } } diff --git a/apps/openmw/mwmechanics/creaturestats.hpp b/apps/openmw/mwmechanics/creaturestats.hpp index 82988ce8b..671dcd439 100644 --- a/apps/openmw/mwmechanics/creaturestats.hpp +++ b/apps/openmw/mwmechanics/creaturestats.hpp @@ -29,8 +29,8 @@ namespace MWMechanics int mFlee; int mAlarm; AiSequence mAiSequence; - float mLevelHealthBonus; + bool mDead; public: CreatureStats(); @@ -105,6 +105,10 @@ namespace MWMechanics // small hack to allow the fact that Health permanently increases by 10% of endurance on each level up void increaseLevelHealthBonus(float value); float getLevelHealthBonus() const; + + bool isDead() const; + + void resurrect(); }; }