mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-31 18:06:41 +00:00
Move getArmorRating to MWWorld::Class.
This commit is contained in:
parent
c66675b599
commit
95e1cdc07d
10 changed files with 71 additions and 56 deletions
|
@ -83,9 +83,6 @@ namespace MWBase
|
||||||
virtual int getDerivedDisposition(const MWWorld::Ptr& ptr) = 0;
|
virtual int getDerivedDisposition(const MWWorld::Ptr& ptr) = 0;
|
||||||
///< Calculate the diposition of an NPC toward the player.
|
///< 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;
|
virtual int countDeaths (const std::string& id) const = 0;
|
||||||
///< Return the number of deaths for actors with the given ID.
|
///< Return the number of deaths for actors with the given ID.
|
||||||
|
|
||||||
|
|
|
@ -191,6 +191,12 @@ namespace MWClass
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float Creature::getArmorRating (const MWWorld::Ptr& ptr) const
|
||||||
|
{
|
||||||
|
/// \todo add Shield magic effect magnitude here, controlled by a GMST (Vanilla vs MCP behaviour)
|
||||||
|
return 0.f;
|
||||||
|
}
|
||||||
|
|
||||||
float Creature::getCapacity (const MWWorld::Ptr& ptr) const
|
float Creature::getCapacity (const MWWorld::Ptr& ptr) const
|
||||||
{
|
{
|
||||||
const MWMechanics::CreatureStats& stats = getCreatureStats (ptr);
|
const MWMechanics::CreatureStats& stats = getCreatureStats (ptr);
|
||||||
|
|
|
@ -54,6 +54,9 @@ namespace MWClass
|
||||||
///< Returns total weight of objects inside this object (including modifications from magic
|
///< Returns total weight of objects inside this object (including modifications from magic
|
||||||
/// effects). Throws an exception, if the object can't hold other objects.
|
/// effects). Throws an exception, if the object can't hold other objects.
|
||||||
|
|
||||||
|
virtual float getArmorRating (const MWWorld::Ptr& ptr) const;
|
||||||
|
///< @return combined armor rating of this actor
|
||||||
|
|
||||||
virtual bool isEssential (const MWWorld::Ptr& ptr) const;
|
virtual bool isEssential (const MWWorld::Ptr& ptr) const;
|
||||||
///< Is \a ptr essential? (i.e. may losing \a ptr make the game unwinnable)
|
///< Is \a ptr essential? (i.e. may losing \a ptr make the game unwinnable)
|
||||||
|
|
||||||
|
|
|
@ -505,6 +505,55 @@ namespace MWClass
|
||||||
stats.useSkill (skill, *class_, usageType);
|
stats.useSkill (skill, *class_, usageType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float Npc::getArmorRating (const MWWorld::Ptr& ptr) const
|
||||||
|
{
|
||||||
|
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(ESM::MagicEffect::Shield).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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Npc::adjustRotation(const MWWorld::Ptr& ptr,float& x,float& y,float& z) const
|
void Npc::adjustRotation(const MWWorld::Ptr& ptr,float& x,float& y,float& z) const
|
||||||
{
|
{
|
||||||
y = 0;
|
y = 0;
|
||||||
|
|
|
@ -104,6 +104,9 @@ namespace MWClass
|
||||||
///< Returns total weight of objects inside this object (including modifications from magic
|
///< Returns total weight of objects inside this object (including modifications from magic
|
||||||
/// effects). Throws an exception, if the object can't hold other objects.
|
/// effects). Throws an exception, if the object can't hold other objects.
|
||||||
|
|
||||||
|
virtual float getArmorRating (const MWWorld::Ptr& ptr) const;
|
||||||
|
///< @return combined armor rating of this actor
|
||||||
|
|
||||||
virtual bool apply (const MWWorld::Ptr& ptr, const std::string& id,
|
virtual bool apply (const MWWorld::Ptr& ptr, const std::string& id,
|
||||||
const MWWorld::Ptr& actor) const;
|
const MWWorld::Ptr& actor) const;
|
||||||
///< Apply \a id on \a ptr.
|
///< Apply \a id on \a ptr.
|
||||||
|
|
|
@ -292,7 +292,7 @@ namespace MWGui
|
||||||
mAvatarImage->setImageTexture("CharacterPreview");
|
mAvatarImage->setImageTexture("CharacterPreview");
|
||||||
|
|
||||||
mArmorRating->setCaptionWithReplacing ("#{sArmor}: "
|
mArmorRating->setCaptionWithReplacing ("#{sArmor}: "
|
||||||
+ boost::lexical_cast<std::string>(static_cast<int>(MWBase::Environment::get().getMechanicsManager()->getArmorRating(mPtr))));
|
+ boost::lexical_cast<std::string>(static_cast<int>(MWWorld::Class::get(mPtr).getArmorRating(mPtr))));
|
||||||
}
|
}
|
||||||
|
|
||||||
void InventoryWindow::pickUpObject (MWWorld::Ptr object)
|
void InventoryWindow::pickUpObject (MWWorld::Ptr object)
|
||||||
|
|
|
@ -669,52 +669,4 @@ namespace MWMechanics
|
||||||
mActors.skipAnimation(ptr);
|
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(ESM::MagicEffect::Shield).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,9 +88,6 @@ namespace MWMechanics
|
||||||
virtual int getDerivedDisposition(const MWWorld::Ptr& ptr);
|
virtual int getDerivedDisposition(const MWWorld::Ptr& ptr);
|
||||||
///< Calculate the diposition of an NPC toward the player.
|
///< 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;
|
virtual int countDeaths (const std::string& id) const;
|
||||||
///< Return the number of deaths for actors with the given ID.
|
///< Return the number of deaths for actors with the given ID.
|
||||||
|
|
||||||
|
|
|
@ -172,6 +172,11 @@ namespace MWWorld
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float Class::getArmorRating (const MWWorld::Ptr& ptr) const
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Class does not support armor rating");
|
||||||
|
}
|
||||||
|
|
||||||
const Class& Class::get (const std::string& key)
|
const Class& Class::get (const std::string& key)
|
||||||
{
|
{
|
||||||
std::map<std::string, boost::shared_ptr<Class> >::const_iterator iter = sClasses.find (key);
|
std::map<std::string, boost::shared_ptr<Class> >::const_iterator iter = sClasses.find (key);
|
||||||
|
|
|
@ -215,6 +215,9 @@ namespace MWWorld
|
||||||
///< Return the down sound ID of \a ptr or throw an exception, if class does not support ID retrieval
|
///< Return the down sound ID of \a ptr or throw an exception, if class does not support ID retrieval
|
||||||
/// (default implementation: throw an exception)
|
/// (default implementation: throw an exception)
|
||||||
|
|
||||||
|
virtual float getArmorRating (const MWWorld::Ptr& ptr) const;
|
||||||
|
///< @return combined armor rating of this actor
|
||||||
|
|
||||||
virtual std::string getInventoryIcon (const MWWorld::Ptr& ptr) const;
|
virtual std::string getInventoryIcon (const MWWorld::Ptr& ptr) const;
|
||||||
///< Return name of inventory icon.
|
///< Return name of inventory icon.
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue