From 2715520d6fba458d0e0549de51b5ddccd4e68a68 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sun, 19 May 2013 23:19:48 +0200 Subject: [PATCH] Cleanup Security class --- apps/openmw/mwmechanics/security.cpp | 41 ++++++++++++---------------- apps/openmw/mwmechanics/security.hpp | 10 +++++-- apps/openmw/mwworld/player.cpp | 4 +-- 3 files changed, 28 insertions(+), 27 deletions(-) diff --git a/apps/openmw/mwmechanics/security.cpp b/apps/openmw/mwmechanics/security.cpp index 11edc6450..090e8ced3 100644 --- a/apps/openmw/mwmechanics/security.cpp +++ b/apps/openmw/mwmechanics/security.cpp @@ -13,7 +13,17 @@ namespace MWMechanics { - void Security::pickLock(const MWWorld::Ptr &actor, const MWWorld::Ptr &lock, const MWWorld::Ptr &lockpick, + Security::Security(const MWWorld::Ptr &actor) + { + CreatureStats& creatureStats = MWWorld::Class::get(actor).getCreatureStats(actor); + NpcStats& npcStats = MWWorld::Class::get(actor).getNpcStats(actor); + mAgility = creatureStats.getAttribute(ESM::Attribute::Agility).getModified(); + mLuck = creatureStats.getAttribute(ESM::Attribute::Luck).getModified(); + mSecuritySkill = npcStats.getSkill(ESM::Skill::Security).getModified(); + mFatigueTerm = creatureStats.getFatigueTerm(); + } + + void Security::pickLock(const MWWorld::Ptr &lock, const MWWorld::Ptr &lockpick, std::string& resultMessage, std::string& resultSound) { if (lock.getCellRef().mLockLevel <= 0) @@ -23,17 +33,10 @@ namespace MWMechanics float pickQuality = lockpick.get()->mBase->mData.mQuality; - CreatureStats& creatureStats = MWWorld::Class::get(actor).getCreatureStats(actor); - NpcStats& npcStats = MWWorld::Class::get(actor).getNpcStats(actor); - float pcAgility = creatureStats.getAttribute(ESM::Attribute::Agility).getModified(); - float pcLuck = creatureStats.getAttribute(ESM::Attribute::Luck).getModified(); - float securitySkill = npcStats.getSkill(ESM::Skill::Security).getModified(); - float fatigueTerm = creatureStats.getFatigueTerm(); - float fPickLockMult = MWBase::Environment::get().getWorld()->getStore().get().find("fPickLockMult")->getFloat(); - float x = 0.2 * pcAgility + 0.1 * pcLuck + securitySkill; - x *= pickQuality * fatigueTerm; + float x = 0.2 * mAgility + 0.1 * mLuck + mSecuritySkill; + x *= pickQuality * mFatigueTerm; x += fPickLockMult * lockStrength; resultSound = "Open Lock Fail"; @@ -47,7 +50,7 @@ namespace MWMechanics MWWorld::Class::get(lock).unlock(lock); resultMessage = "#{sLockSuccess}"; resultSound = "Open Lock"; - MWWorld::Class::get(actor).skillUsageSucceeded(actor, ESM::Skill::Security, 1); + MWWorld::Class::get(mActor).skillUsageSucceeded(mActor, ESM::Skill::Security, 1); } else resultMessage = "#{sLockFail}"; @@ -60,30 +63,22 @@ namespace MWMechanics lockpick.getRefData().setCount(0); } - void Security::probeTrap(const MWWorld::Ptr &actor, const MWWorld::Ptr &trap, const MWWorld::Ptr &probe, + void Security::probeTrap(const MWWorld::Ptr &trap, const MWWorld::Ptr &probe, std::string& resultMessage, std::string& resultSound) { if (trap.getCellRef().mTrap == "") return; - CreatureStats& creatureStats = MWWorld::Class::get(actor).getCreatureStats(actor); - NpcStats& npcStats = MWWorld::Class::get(actor).getNpcStats(actor); - float probeQuality = probe.get()->mBase->mData.mQuality; const ESM::Spell* trapSpell = MWBase::Environment::get().getWorld()->getStore().get().find(trap.getCellRef().mTrap); float trapSpellPoints = trapSpell->mData.mCost; - float pcAgility = creatureStats.getAttribute(ESM::Attribute::Agility).getModified(); - float pcLuck = creatureStats.getAttribute(ESM::Attribute::Luck).getModified(); - float securitySkill = npcStats.getSkill(ESM::Skill::Security).getModified(); - float fatigueTerm = creatureStats.getFatigueTerm(); - float fTrapCostMult = MWBase::Environment::get().getWorld()->getStore().get().find("fTrapCostMult")->getFloat(); - float x = 0.2 * pcAgility + 0.1 * pcLuck + securitySkill; + float x = 0.2 * mAgility + 0.1 * mLuck + mSecuritySkill; x += fTrapCostMult * trapSpellPoints; - x *= probeQuality * fatigueTerm; + x *= probeQuality * mFatigueTerm; resultSound = "Disarm Trap Fail"; if (x <= 0) @@ -97,7 +92,7 @@ namespace MWMechanics resultSound = "Disarm Trap"; resultMessage = "#{sTrapSuccess}"; - MWWorld::Class::get(actor).skillUsageSucceeded(actor, ESM::Skill::Security, 0); + MWWorld::Class::get(mActor).skillUsageSucceeded(mActor, ESM::Skill::Security, 0); } else resultMessage = "#{sTrapFail}"; diff --git a/apps/openmw/mwmechanics/security.hpp b/apps/openmw/mwmechanics/security.hpp index 17a914459..f3efb04ed 100644 --- a/apps/openmw/mwmechanics/security.hpp +++ b/apps/openmw/mwmechanics/security.hpp @@ -10,10 +10,16 @@ namespace MWMechanics class Security { public: - static void pickLock (const MWWorld::Ptr& actor, const MWWorld::Ptr& lock, const MWWorld::Ptr& lockpick, + Security (const MWWorld::Ptr& actor); + + void pickLock (const MWWorld::Ptr& lock, const MWWorld::Ptr& lockpick, std::string& resultMessage, std::string& resultSound); - static void probeTrap (const MWWorld::Ptr& actor, const MWWorld::Ptr& trap, const MWWorld::Ptr& probe, + void probeTrap (const MWWorld::Ptr& trap, const MWWorld::Ptr& probe, std::string& resultMessage, std::string& resultSound); + + private: + float mAgility, mLuck, mSecuritySkill, mFatigueTerm; + MWWorld::Ptr mActor; }; } diff --git a/apps/openmw/mwworld/player.cpp b/apps/openmw/mwworld/player.cpp index b597dccf3..ebc9cd86d 100644 --- a/apps/openmw/mwworld/player.cpp +++ b/apps/openmw/mwworld/player.cpp @@ -162,13 +162,13 @@ namespace MWWorld if (item.getTypeName() == typeid(ESM::Lockpick).name()) { if (!target.isEmpty()) - MWMechanics::Security::pickLock(getPlayer(), target, item, resultMessage, resultSound); + MWMechanics::Security(getPlayer()).pickLock(target, item, resultMessage, resultSound); anim->play("pickprobe", MWMechanics::Priority_Weapon, MWRender::Animation::Group_UpperBody, true, "start", "stop", 0.0, 0); } else if (item.getTypeName() == typeid(ESM::Probe).name()) { if (!target.isEmpty()) - MWMechanics::Security::probeTrap(getPlayer(), target, item, resultMessage, resultSound); + MWMechanics::Security(getPlayer()).probeTrap(target, item, resultMessage, resultSound); anim->play("pickprobe", MWMechanics::Priority_Weapon, MWRender::Animation::Group_UpperBody, true, "start", "stop", 0.0, 0); }