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:
parent
67de61e1fb
commit
54bd7b2dcf
6 changed files with 21 additions and 41 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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>()
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue