1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-02-21 08:09:39 +00:00

Cleanup some redundancy

This commit is contained in:
Chris Robinson 2013-08-27 17:56:47 -07:00
parent 33c173a23a
commit 281fdbd81b
2 changed files with 35 additions and 41 deletions

View file

@ -215,79 +215,74 @@ namespace MWMechanics
void MechanicsManager::update(float duration, bool paused) void MechanicsManager::update(float duration, bool paused)
{ {
if (!mWatched.isEmpty()) if(!mWatched.isEmpty())
{ {
MWMechanics::CreatureStats& stats = static const char attributeNames[8][12] =
MWWorld::Class::get (mWatched).getCreatureStats (mWatched);
MWMechanics::NpcStats& npcStats =
MWWorld::Class::get (mWatched).getNpcStats (mWatched);
static const char *attributeNames[8] =
{ {
"AttribVal1", "AttribVal2", "AttribVal3", "AttribVal4", "AttribVal5", "AttribVal1", "AttribVal2", "AttribVal3", "AttribVal4", "AttribVal5",
"AttribVal6", "AttribVal7", "AttribVal8" "AttribVal6", "AttribVal7", "AttribVal8"
}; };
static const char dynamicNames[3][5] =
static const char *dynamicNames[3] =
{ {
"HBar", "MBar", "FBar" "HBar", "MBar", "FBar"
}; };
for (int i=0; i<8; ++i) MWBase::WindowManager *winMgr = MWBase::Environment::get().getWindowManager();
const MWMechanics::NpcStats &stats = mWatched.getClass().getNpcStats(mWatched);
for(int i = 0;i < ESM::Attribute::Length;++i)
{ {
if (stats.getAttribute(i)!=mWatchedCreature.getAttribute(i)) if(stats.getAttribute(i) != mWatchedStats.getAttribute(i))
{ {
mWatchedCreature.setAttribute(i, stats.getAttribute(i)); mWatchedStats.setAttribute(i, stats.getAttribute(i));
winMgr->setValue(attributeNames[i], stats.getAttribute(i));
MWBase::Environment::get().getWindowManager()->setValue (attributeNames[i], stats.getAttribute(i));
} }
} }
if (stats.getHealth() != mWatchedCreature.getHealth()) { if(stats.getHealth() != mWatchedStats.getHealth())
mWatchedCreature.setHealth(stats.getHealth()); {
MWBase::Environment::get().getWindowManager()->setValue(dynamicNames[0], stats.getHealth()); mWatchedStats.setHealth(stats.getHealth());
winMgr->setValue(dynamicNames[0], stats.getHealth());
} }
if (stats.getMagicka() != mWatchedCreature.getMagicka()) { if(stats.getMagicka() != mWatchedStats.getMagicka())
mWatchedCreature.setMagicka(stats.getMagicka()); {
MWBase::Environment::get().getWindowManager()->setValue(dynamicNames[1], stats.getMagicka()); mWatchedStats.setMagicka(stats.getMagicka());
winMgr->setValue(dynamicNames[1], stats.getMagicka());
} }
if (stats.getFatigue() != mWatchedCreature.getFatigue()) { if(stats.getFatigue() != mWatchedStats.getFatigue())
mWatchedCreature.setFatigue(stats.getFatigue()); {
MWBase::Environment::get().getWindowManager()->setValue(dynamicNames[2], stats.getFatigue()); mWatchedStats.setFatigue(stats.getFatigue());
winMgr->setValue(dynamicNames[2], stats.getFatigue());
} }
if(npcStats.getTimeToStartDrowning() != mWatchedNpc.getTimeToStartDrowning()) if(stats.getTimeToStartDrowning() != mWatchedStats.getTimeToStartDrowning())
{ {
mWatchedNpc.setTimeToStartDrowning(npcStats.getTimeToStartDrowning()); mWatchedStats.setTimeToStartDrowning(stats.getTimeToStartDrowning());
if(npcStats.getTimeToStartDrowning()>=20.0) if(stats.getTimeToStartDrowning() >= 20.0f)
{ winMgr->setDrowningBarVisibility(false);
MWBase::Environment::get().getWindowManager()->setDrowningBarVisibility(false);
}
else else
{ {
MWBase::Environment::get().getWindowManager()->setDrowningBarVisibility(true); winMgr->setDrowningBarVisibility(true);
MWBase::Environment::get().getWindowManager()->setDrowningTimeLeft(npcStats.getTimeToStartDrowning()); winMgr->setDrowningTimeLeft(stats.getTimeToStartDrowning());
} }
} }
bool update = false; bool update = false;
//Loop over ESM::Skill::SkillEnum //Loop over ESM::Skill::SkillEnum
for(int i = 0; i < 27; ++i) for(int i = 0; i < ESM::Skill::Length; ++i)
{ {
if(npcStats.getSkill (i) != mWatchedNpc.getSkill (i)) if(stats.getSkill(i) != mWatchedStats.getSkill(i))
{ {
update = true; update = true;
mWatchedNpc.getSkill (i) = npcStats.getSkill (i); mWatchedStats.getSkill(i) = stats.getSkill(i);
MWBase::Environment::get().getWindowManager()->setValue((ESM::Skill::SkillEnum)i, npcStats.getSkill (i)); winMgr->setValue((ESM::Skill::SkillEnum)i, stats.getSkill(i));
} }
} }
if (update) if(update)
MWBase::Environment::get().getWindowManager()->updateSkillArea(); winMgr->updateSkillArea();
MWBase::Environment::get().getWindowManager()->setValue ("level", stats.getLevel()); winMgr->setValue("level", stats.getLevel());
} }
if (mUpdatePlayer) if (mUpdatePlayer)

View file

@ -25,8 +25,7 @@ namespace MWMechanics
class MechanicsManager : public MWBase::MechanicsManager class MechanicsManager : public MWBase::MechanicsManager
{ {
MWWorld::Ptr mWatched; MWWorld::Ptr mWatched;
CreatureStats mWatchedCreature; NpcStats mWatchedStats;
NpcStats mWatchedNpc;
bool mUpdatePlayer; bool mUpdatePlayer;
bool mClassSelected; bool mClassSelected;
bool mRaceSelected; bool mRaceSelected;