mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-09 21:44:54 +00:00
Implement getItemNormalizedHealth() method and use it
This commit is contained in:
parent
67de61e1fb
commit
54bd7b2dcf
@ -1148,16 +1148,7 @@ namespace MWClass
|
|||||||
const bool hasHealth = it->getClass().hasItemHealth(*it);
|
const bool hasHealth = it->getClass().hasItemHealth(*it);
|
||||||
if (hasHealth)
|
if (hasHealth)
|
||||||
{
|
{
|
||||||
int armorMaxHealth = it->getClass().getItemMaxHealth(*it);
|
ratings[i] *= it->getClass().getItemNormalizedHealth(*it);
|
||||||
if (armorMaxHealth == 0)
|
|
||||||
{
|
|
||||||
ratings[i] = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
int armorHealth = it->getClass().getItemHealth(*it);
|
|
||||||
ratings[i] *= (float(armorHealth) / armorMaxHealth);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,17 +34,8 @@ namespace
|
|||||||
{
|
{
|
||||||
float price = static_cast<float>(item.getClass().getValue(item));
|
float price = static_cast<float>(item.getClass().getValue(item));
|
||||||
if (item.getClass().hasItemHealth(item))
|
if (item.getClass().hasItemHealth(item))
|
||||||
{
|
price *= item.getClass().getItemNormalizedHealth(item);
|
||||||
if (item.getClass().getItemMaxHealth(item) == 0)
|
|
||||||
{
|
|
||||||
price = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
price *= item.getClass().getItemHealth(item);
|
|
||||||
price /= item.getClass().getItemMaxHealth(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return static_cast<int>(price * count);
|
return static_cast<int>(price * count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1400,17 +1400,9 @@ namespace MWGui
|
|||||||
int durabilityPercent = 100;
|
int durabilityPercent = 100;
|
||||||
if (item.getClass().hasItemHealth(item))
|
if (item.getClass().hasItemHealth(item))
|
||||||
{
|
{
|
||||||
int weapmaxhealth = item.getClass().getItemMaxHealth(item);
|
durabilityPercent = static_cast<int>(item.getClass().getItemNormalizedHealth(item));
|
||||||
if (weapmaxhealth == 0)
|
|
||||||
{
|
|
||||||
durabilityPercent = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
int weaphealth = item.getClass().getItemHealth(item);
|
|
||||||
durabilityPercent = static_cast<int>(weaphealth / static_cast<float>(weapmaxhealth) * 100);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mHud->setSelectedWeapon(item, durabilityPercent);
|
mHud->setSelectedWeapon(item, durabilityPercent);
|
||||||
mInventoryWindow->setTitle(item.getClass().getName(item));
|
mInventoryWindow->setTitle(item.getClass().getName(item));
|
||||||
}
|
}
|
||||||
|
@ -373,16 +373,7 @@ namespace MWMechanics
|
|||||||
const bool weaphashealth = weapon.getClass().hasItemHealth(weapon);
|
const bool weaphashealth = weapon.getClass().hasItemHealth(weapon);
|
||||||
if (weaphashealth)
|
if (weaphashealth)
|
||||||
{
|
{
|
||||||
int weapmaxhealth = weapon.getClass().getItemMaxHealth(weapon);
|
damage *= weapon.getClass().getItemNormalizedHealth(weapon);
|
||||||
|
|
||||||
if (weapmaxhealth == 0)
|
|
||||||
{
|
|
||||||
damage = 0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int weaphealth = weapon.getClass().getItemHealth(weapon);
|
|
||||||
damage *= (float(weaphealth) / weapmaxhealth);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const float fDamageStrengthBase = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>()
|
static const float fDamageStrengthBase = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>()
|
||||||
|
@ -83,6 +83,18 @@ namespace MWWorld
|
|||||||
return ptr.getCellRef().getCharge();
|
return ptr.getCellRef().getCharge();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float Class::getItemNormalizedHealth (const ConstPtr& ptr) const
|
||||||
|
{
|
||||||
|
if (getItemMaxHealth(ptr) == 0)
|
||||||
|
{
|
||||||
|
return 0.f;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return getItemHealth(ptr) / static_cast<float>(getItemMaxHealth(ptr));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int Class::getItemMaxHealth (const ConstPtr& ptr) const
|
int Class::getItemMaxHealth (const ConstPtr& ptr) const
|
||||||
{
|
{
|
||||||
throw std::runtime_error ("class does not have item health");
|
throw std::runtime_error ("class does not have item health");
|
||||||
|
@ -112,6 +112,9 @@ namespace MWWorld
|
|||||||
virtual int getItemHealth (const ConstPtr& ptr) const;
|
virtual int getItemHealth (const ConstPtr& ptr) const;
|
||||||
///< Return current item health or throw an exception if class does not have item health
|
///< Return current item health or throw an exception if class does not have item health
|
||||||
|
|
||||||
|
virtual float getItemNormalizedHealth (const ConstPtr& ptr) const;
|
||||||
|
///< Return current item health re-scaled to maximum health
|
||||||
|
|
||||||
virtual int getItemMaxHealth (const ConstPtr& ptr) const;
|
virtual int getItemMaxHealth (const ConstPtr& ptr) const;
|
||||||
///< Return item max health or throw an exception, if class does not have item health
|
///< Return item max health or throw an exception, if class does not have item health
|
||||||
/// (default implementation: throw an exception)
|
/// (default implementation: throw an exception)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user