#include "stat.hpp" #include namespace MWMechanics { template Stat::Stat() : mBase (0), mModified (0) {} template Stat::Stat(T base) : mBase (base), mModified (base) {} template Stat::Stat(T base, T modified) : mBase (base), mModified (modified) {} template const T& Stat::getBase() const { return mBase; } template T Stat::getModified() const { return std::max(static_cast(0), mModified); } template T Stat::getModifier() const { return mModified-mBase; } template void Stat::set (const T& value) { mBase = mModified = value; } template void Stat::setBase (const T& value) { T diff = value - mBase; mBase = value; mModified += diff; } template void Stat::setModified (T value, const T& min, const T& max) { T diff = value - mModified; if (mBase+diffmax) { value = max + (mModified - mBase); diff = value - mModified; } mModified = value; mBase += diff; } template void Stat::setModifier (const T& modifier) { mModified = mBase + modifier; } template void Stat::writeState (ESM::StatState& state) const { state.mBase = mBase; state.mMod = mModified; } template void Stat::readState (const ESM::StatState& state) { mBase = state.mBase; mModified = state.mMod; } template DynamicStat::DynamicStat() : mStatic (0), mCurrent (0) {} template DynamicStat::DynamicStat(T base) : mStatic (base), mCurrent (base) {} template DynamicStat::DynamicStat(T base, T modified, T current) : mStatic(base, modified), mCurrent (current) {} template DynamicStat::DynamicStat(const Stat &stat, T current) : mStatic(stat), mCurrent (current) {} template const T& DynamicStat::getBase() const { return mStatic.getBase(); } template T DynamicStat::getModified() const { return mStatic.getModified(); } template const T& DynamicStat::getCurrent() const { return mCurrent; } template void DynamicStat::set (const T& value) { mStatic.set (value); mCurrent = value; } template void DynamicStat::setBase (const T& value) { mStatic.setBase (value); if (mCurrent>getModified()) mCurrent = getModified(); } template void DynamicStat::setModified (T value, const T& min, const T& max) { mStatic.setModified (value, min, max); if (mCurrent>getModified()) mCurrent = getModified(); } template void DynamicStat::setCurrent (const T& value, bool allowDecreaseBelowZero) { if (value > mCurrent) { // increase mCurrent = value; if (mCurrent > getModified()) mCurrent = getModified(); } else if (value > 0 || allowDecreaseBelowZero) { // allowed decrease mCurrent = value; } else if (mCurrent > 0) { // capped decrease mCurrent = 0; } } template void DynamicStat::setModifier (const T& modifier, bool allowCurrentDecreaseBelowZero) { T diff = modifier - mStatic.getModifier(); mStatic.setModifier (modifier); setCurrent (getCurrent()+diff, allowCurrentDecreaseBelowZero); } template void DynamicStat::writeState (ESM::StatState& state) const { mStatic.writeState (state); state.mCurrent = mCurrent; } template void DynamicStat::readState (const ESM::StatState& state) { mStatic.readState (state); mCurrent = state.mCurrent; } AttributeValue::AttributeValue() : mBase(0), mModifier(0), mDamage(0) { } int AttributeValue::getModified() const { return std::max(0, mBase - (int) mDamage + mModifier); } int AttributeValue::getBase() const { return mBase; } int AttributeValue::getModifier() const { return mModifier; } void AttributeValue::setBase(int base) { mBase = base; } void AttributeValue::setModifier(int mod) { mModifier = mod; } void AttributeValue::damage(float damage) { mDamage += std::min(damage, (float)getModified()); } void AttributeValue::restore(float amount) { mDamage -= std::min(mDamage, amount); } float AttributeValue::getDamage() const { return mDamage; } void AttributeValue::writeState (ESM::StatState& state) const { state.mBase = mBase; state.mMod = mModifier; state.mDamage = mDamage; } void AttributeValue::readState (const ESM::StatState& state) { mBase = state.mBase; mModifier = state.mMod; mDamage = state.mDamage; } SkillValue::SkillValue() : mProgress(0) { } float SkillValue::getProgress() const { return mProgress; } void SkillValue::setProgress(float progress) { mProgress = progress; } void SkillValue::writeState (ESM::StatState& state) const { AttributeValue::writeState (state); state.mProgress = mProgress; } void SkillValue::readState (const ESM::StatState& state) { AttributeValue::readState (state); mProgress = state.mProgress; } } template class MWMechanics::Stat; template class MWMechanics::Stat; template class MWMechanics::DynamicStat; template class MWMechanics::DynamicStat;