Implement getNormalizedEnchantmentCharge() method and use it

pull/541/head
Capostrophic 6 years ago
parent 54bd7b2dcf
commit c3e8d536cd

@ -86,66 +86,24 @@ namespace
if (!leftName.empty())
{
const ESM::Enchantment* ench = MWBase::Environment::get().getWorld()->getStore().get<ESM::Enchantment>().search(leftName);
if (ench)
{
if (ench->mData.mType == ESM::Enchantment::ConstantEffect)
{
leftChargePercent = 101;
}
else
{
int maxEnchCharge = ench->mData.mCharge;
if (maxEnchCharge == 0)
{
leftChargePercent = 0;
}
else
{
float enchCharge = left.mBase.getCellRef().getEnchantmentCharge();
if (enchCharge == -1)
{
leftChargePercent = 100;
}
else
{
leftChargePercent = static_cast<int>(enchCharge / static_cast<float>(maxEnchCharge) * 100);
}
}
}
leftChargePercent = static_cast<int>(left.mBase.getCellRef().getNormalizedEnchantmentCharge(ench->mData.mCharge) * 100);
}
}
if (!rightName.empty())
{
const ESM::Enchantment* ench = MWBase::Environment::get().getWorld()->getStore().get<ESM::Enchantment>().search(rightName);
if (ench)
{
if (ench->mData.mType == ESM::Enchantment::ConstantEffect)
{
rightChargePercent = 101;
}
else
{
int maxEnchCharge = ench->mData.mCharge;
if (maxEnchCharge == 0)
{
rightChargePercent = 0;
}
else
{
float enchCharge = right.mBase.getCellRef().getEnchantmentCharge();
if (enchCharge == -1)
{
rightChargePercent = 100;
}
else
{
rightChargePercent = static_cast<int>(enchCharge / static_cast<float>(maxEnchCharge) * 100);
}
}
}
rightChargePercent = static_cast<int>(right.mBase.getCellRef().getNormalizedEnchantmentCharge(ench->mData.mCharge) * 100);
}
}

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

@ -1369,22 +1369,7 @@ namespace MWGui
const ESM::Enchantment* ench = mStore->get<ESM::Enchantment>()
.find(item.getClass().getEnchantment(item));
int chargePercent = 100;
int maxEnchCharge = ench->mData.mCharge;
if (maxEnchCharge == 0)
{
chargePercent = 0;
}
else
{
float enchCharge = item.getCellRef().getEnchantmentCharge();
if (enchCharge != -1)
{
chargePercent = static_cast<int>(enchCharge / static_cast<float>(maxEnchCharge) * 100);
}
}
int chargePercent = static_cast<int>(item.getCellRef().getNormalizedEnchantmentCharge(ench->mData.mCharge) * 100);
mHud->setSelectedEnchantItem(item, chargePercent);
mSpellWindow->setTitle(item.getClass().getName(item));
}
@ -1402,7 +1387,6 @@ namespace MWGui
{
durabilityPercent = static_cast<int>(item.getClass().getItemNormalizedHealth(item));
}
mHud->setSelectedWeapon(item, durabilityPercent);
mInventoryWindow->setTitle(item.getClass().getName(item));
}

@ -70,6 +70,22 @@ namespace MWWorld
return mCellRef.mEnchantmentCharge;
}
float CellRef::getNormalizedEnchantmentCharge(int maxCharge) const
{
if (maxCharge == 0)
{
return 0;
}
else if (mCellRef.mEnchantmentCharge == -1)
{
return 1;
}
else
{
return mCellRef.mEnchantmentCharge / static_cast<float>(maxCharge);
}
}
void CellRef::setEnchantmentCharge(float charge)
{
if (charge != mCellRef.mEnchantmentCharge)

@ -56,6 +56,9 @@ namespace MWWorld
// Remaining enchantment charge. This could be -1 if the charge was not touched yet (i.e. full).
float getEnchantmentCharge() const;
// Remaining enchantment charge rescaled to the supplied maximum charge (such as one of the enchantment).
float getNormalizedEnchantmentCharge(int maxCharge) const;
void setEnchantmentCharge(float charge);
// For weapon or armor, this is the remaining item health.

Loading…
Cancel
Save