1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-02-20 19:39:41 +00:00

Implement getItemNormalizedHealth() method and use it

This commit is contained in:
Capostrophic 2018-10-25 15:45:31 +03:00
parent 67de61e1fb
commit 54bd7b2dcf
6 changed files with 21 additions and 41 deletions

View file

@ -1148,16 +1148,7 @@ namespace MWClass
const bool hasHealth = it->getClass().hasItemHealth(*it);
if (hasHealth)
{
int armorMaxHealth = it->getClass().getItemMaxHealth(*it);
if (armorMaxHealth == 0)
{
ratings[i] = 0;
}
else
{
int armorHealth = it->getClass().getItemHealth(*it);
ratings[i] *= (float(armorHealth) / armorMaxHealth);
}
ratings[i] *= it->getClass().getItemNormalizedHealth(*it);
}
}
}

View file

@ -34,17 +34,8 @@ namespace
{
float price = static_cast<float>(item.getClass().getValue(item));
if (item.getClass().hasItemHealth(item))
{
if (item.getClass().getItemMaxHealth(item) == 0)
{
price = 0;
}
else
{
price *= item.getClass().getItemHealth(item);
price /= item.getClass().getItemMaxHealth(item);
}
}
price *= item.getClass().getItemNormalizedHealth(item);
return static_cast<int>(price * count);
}

View file

@ -1400,17 +1400,9 @@ namespace MWGui
int durabilityPercent = 100;
if (item.getClass().hasItemHealth(item))
{
int weapmaxhealth = item.getClass().getItemMaxHealth(item);
if (weapmaxhealth == 0)
{
durabilityPercent = 0;
}
else
{
int weaphealth = item.getClass().getItemHealth(item);
durabilityPercent = static_cast<int>(weaphealth / static_cast<float>(weapmaxhealth) * 100);
}
durabilityPercent = static_cast<int>(item.getClass().getItemNormalizedHealth(item));
}
mHud->setSelectedWeapon(item, durabilityPercent);
mInventoryWindow->setTitle(item.getClass().getName(item));
}

View file

@ -373,16 +373,7 @@ namespace MWMechanics
const bool weaphashealth = weapon.getClass().hasItemHealth(weapon);
if (weaphashealth)
{
int weapmaxhealth = weapon.getClass().getItemMaxHealth(weapon);
if (weapmaxhealth == 0)
{
damage = 0;
return;
}
int weaphealth = weapon.getClass().getItemHealth(weapon);
damage *= (float(weaphealth) / weapmaxhealth);
damage *= weapon.getClass().getItemNormalizedHealth(weapon);
}
static const float fDamageStrengthBase = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>()

View file

@ -83,6 +83,18 @@ namespace MWWorld
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
{
throw std::runtime_error ("class does not have item health");

View file

@ -112,6 +112,9 @@ namespace MWWorld
virtual int getItemHealth (const ConstPtr& ptr) const;
///< 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;
///< Return item max health or throw an exception, if class does not have item health
/// (default implementation: throw an exception)