Armor rating

actorid
scrawl 12 years ago
parent e8b08326dc
commit 1666bc7740

@ -82,7 +82,10 @@ namespace MWBase
virtual int getDerivedDisposition(const MWWorld::Ptr& ptr) = 0;
///< Calculate the diposition of an NPC toward the player.
virtual float getArmorRating (const MWWorld::Ptr& ptr) = 0;
///< Calculate the combined armor rating of an NPC.
virtual int countDeaths (const std::string& id) const = 0;
///< Return the number of deaths for actors with the given ID.

@ -13,6 +13,7 @@
#include "../mwbase/environment.hpp"
#include "../mwbase/soundmanager.hpp"
#include "../mwbase/windowmanager.hpp"
#include "../mwbase/mechanicsmanager.hpp"
#include "../mwworld/containerstore.hpp"
#include "../mwworld/class.hpp"
@ -50,6 +51,7 @@ namespace MWGui
getWidget(mFilterMisc, "MiscButton");
getWidget(mLeftPane, "LeftPane");
getWidget(mRightPane, "RightPane");
getWidget(mArmorRating, "ArmorRating");
mAvatar->eventMouseButtonClick += MyGUI::newDelegate(this, &InventoryWindow::onAvatarClicked);
@ -288,6 +290,9 @@ namespace MWGui
mPreview.update (size.width, size.height);
mAvatarImage->setSize(MyGUI::IntSize(std::max(mAvatar->getSize().width, 512), std::max(mAvatar->getSize().height, 1024)));
mAvatarImage->setImageTexture("CharacterPreview");
mArmorRating->setCaptionWithReplacing ("#{sArmor}: "
+ boost::lexical_cast<std::string>(static_cast<int>(MWBase::Environment::get().getMechanicsManager()->getArmorRating(mPtr))));
}
void InventoryWindow::pickUpObject (MWWorld::Ptr object)

@ -2,6 +2,7 @@
#include "mechanicsmanagerimp.hpp"
#include "../mwworld/esmstore.hpp"
#include "../mwworld/inventorystore.hpp"
#include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp"
@ -668,4 +669,52 @@ namespace MWMechanics
mActors.skipAnimation(ptr);
}
float MechanicsManager::getArmorRating(const MWWorld::Ptr &ptr)
{
MWWorld::InventoryStore& invStore = MWWorld::Class::get(ptr).getInventoryStore(ptr);
const MWWorld::Store<ESM::GameSetting> &gmst =
MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>();
int ratings[MWWorld::InventoryStore::Slots];
int iBaseArmorSkill = gmst.find("iBaseArmorSkill")->getInt();
float fUnarmoredBase1 = gmst.find("fUnarmoredBase1")->getFloat();
float fUnarmoredBase2 = gmst.find("fUnarmoredBase2")->getFloat();
int unarmoredSkill = MWWorld::Class::get(ptr).getNpcStats(ptr).getSkill(ESM::Skill::Unarmored).getModified();
for (int i = 0; i < MWWorld::InventoryStore::Slots; ++i)
{
MWWorld::ContainerStoreIterator it = invStore.getSlot(i);
if (it == invStore.end() || it->getTypeName() != typeid(ESM::Armor).name())
{
// unarmored
ratings[i] = (fUnarmoredBase1 * unarmoredSkill) * (fUnarmoredBase2 * unarmoredSkill);
}
else
{
MWWorld::LiveCellRef<ESM::Armor> *ref =
it->get<ESM::Armor>();
int armorSkillType = MWWorld::Class::get(*it).getEquipmentSkill(*it);
int armorSkill = MWWorld::Class::get(ptr).getNpcStats(ptr).getSkill(armorSkillType).getModified();
if (ref->mBase->mData.mWeight == 0)
ratings[i] = ref->mBase->mData.mArmor;
else
ratings[i] = ref->mBase->mData.mArmor * armorSkill / iBaseArmorSkill;
}
}
float shield = MWWorld::Class::get(ptr).getCreatureStats(ptr).getMagicEffects().get(3).mMagnitude;
return ratings[MWWorld::InventoryStore::Slot_Cuirass] * 0.3
+ (ratings[MWWorld::InventoryStore::Slot_CarriedLeft] + ratings[MWWorld::InventoryStore::Slot_Helmet]
+ ratings[MWWorld::InventoryStore::Slot_Greaves] + ratings[MWWorld::InventoryStore::Slot_Boots]
+ ratings[MWWorld::InventoryStore::Slot_LeftPauldron] + ratings[MWWorld::InventoryStore::Slot_RightPauldron]
) * 0.1
+ (ratings[MWWorld::InventoryStore::Slot_LeftGauntlet] + MWWorld::InventoryStore::Slot_RightGauntlet)
* 0.05
+ shield;
}
}

@ -88,6 +88,9 @@ namespace MWMechanics
virtual int getDerivedDisposition(const MWWorld::Ptr& ptr);
///< Calculate the diposition of an NPC toward the player.
virtual float getArmorRating (const MWWorld::Ptr& ptr);
///< Calculate the combined armor rating of an NPC.
virtual int countDeaths (const std::string& id) const;
///< Return the number of deaths for actors with the given ID.

@ -17,7 +17,6 @@
<Property key="NeedMouse" value="false"/>
</Widget>
<Widget type="TextBox" skin="ProgressText" position="0 150 212 24" align="HCenter Bottom" name="ArmorRating">
<Property key="Caption" value="Armor Rating"/>
<Property key="NeedMouse" value="false"/>
</Widget>
</Widget>

Loading…
Cancel
Save