mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-25 15:35:23 +00:00
Explicity instantiate MWMechanics::Stat
This commit is contained in:
parent
3655ef16af
commit
b1cc74dd9a
@ -16,6 +16,8 @@
|
||||
|
||||
#include <components/settings/settings.hpp>
|
||||
|
||||
#include <components/misc/stringops.hpp>
|
||||
|
||||
#include "../mwbase/world.hpp"
|
||||
#include "../mwbase/environment.hpp"
|
||||
#include "../mwbase/soundmanager.hpp"
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <components/esm/esmreader.hpp>
|
||||
#include <components/esm/esmwriter.hpp>
|
||||
#include <components/esm/loadnpc.hpp>
|
||||
#include <components/esm/esmreader.hpp>
|
||||
|
||||
#include "../mwworld/esmstore.hpp"
|
||||
#include "../mwworld/class.hpp"
|
||||
|
@ -1,28 +1,276 @@
|
||||
|
||||
#include "stat.hpp"
|
||||
|
||||
void MWMechanics::AttributeValue::writeState (ESM::StatState<int>& state) const
|
||||
#include <components/esm/statstate.hpp>
|
||||
|
||||
namespace MWMechanics
|
||||
{
|
||||
state.mBase = mBase;
|
||||
state.mMod = mModifier;
|
||||
state.mDamage = mDamage;
|
||||
template<typename T>
|
||||
Stat<T>::Stat() : mBase (0), mModified (0) {}
|
||||
template<typename T>
|
||||
Stat<T>::Stat(T base) : mBase (base), mModified (base) {}
|
||||
template<typename T>
|
||||
Stat<T>::Stat(T base, T modified) : mBase (base), mModified (modified) {}
|
||||
|
||||
template<typename T>
|
||||
const T& Stat<T>::getBase() const
|
||||
{
|
||||
return mBase;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T Stat<T>::getModified() const
|
||||
{
|
||||
return std::max(static_cast<T>(0), mModified);
|
||||
}
|
||||
template<typename T>
|
||||
T Stat<T>::getModifier() const
|
||||
{
|
||||
return mModified-mBase;
|
||||
}
|
||||
template<typename T>
|
||||
void Stat<T>::set (const T& value)
|
||||
{
|
||||
mBase = mModified = value;
|
||||
}
|
||||
template<typename T>
|
||||
void Stat<T>::modify(const T& diff)
|
||||
{
|
||||
mBase += diff;
|
||||
if(mBase >= static_cast<T>(0))
|
||||
mModified += diff;
|
||||
else
|
||||
{
|
||||
mModified += diff - mBase;
|
||||
mBase = static_cast<T>(0);
|
||||
}
|
||||
}
|
||||
template<typename T>
|
||||
void Stat<T>::setBase (const T& value)
|
||||
{
|
||||
T diff = value - mBase;
|
||||
mBase = value;
|
||||
mModified += diff;
|
||||
}
|
||||
template<typename T>
|
||||
void Stat<T>::setModified (T value, const T& min, const T& max)
|
||||
{
|
||||
T diff = value - mModified;
|
||||
|
||||
if (mBase+diff<min)
|
||||
{
|
||||
value = min + (mModified - mBase);
|
||||
diff = value - mModified;
|
||||
}
|
||||
else if (mBase+diff>max)
|
||||
{
|
||||
value = max + (mModified - mBase);
|
||||
diff = value - mModified;
|
||||
}
|
||||
|
||||
mModified = value;
|
||||
mBase += diff;
|
||||
}
|
||||
template<typename T>
|
||||
void Stat<T>::setModifier (const T& modifier)
|
||||
{
|
||||
mModified = mBase + modifier;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void Stat<T>::writeState (ESM::StatState<T>& state) const
|
||||
{
|
||||
state.mBase = mBase;
|
||||
state.mMod = mModified;
|
||||
}
|
||||
template<typename T>
|
||||
void Stat<T>::readState (const ESM::StatState<T>& state)
|
||||
{
|
||||
mBase = state.mBase;
|
||||
mModified = state.mMod;
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
DynamicStat<T>::DynamicStat() : mStatic (0), mCurrent (0) {}
|
||||
template<typename T>
|
||||
DynamicStat<T>::DynamicStat(T base) : mStatic (base), mCurrent (base) {}
|
||||
template<typename T>
|
||||
DynamicStat<T>::DynamicStat(T base, T modified, T current) : mStatic(base, modified), mCurrent (current) {}
|
||||
template<typename T>
|
||||
DynamicStat<T>::DynamicStat(const Stat<T> &stat, T current) : mStatic(stat), mCurrent (current) {}
|
||||
|
||||
|
||||
template<typename T>
|
||||
const T& DynamicStat<T>::getBase() const
|
||||
{
|
||||
return mStatic.getBase();
|
||||
}
|
||||
template<typename T>
|
||||
T DynamicStat<T>::getModified() const
|
||||
{
|
||||
return mStatic.getModified();
|
||||
}
|
||||
template<typename T>
|
||||
const T& DynamicStat<T>::getCurrent() const
|
||||
{
|
||||
return mCurrent;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void DynamicStat<T>::set (const T& value)
|
||||
{
|
||||
mStatic.set (value);
|
||||
mCurrent = value;
|
||||
}
|
||||
template<typename T>
|
||||
void DynamicStat<T>::setBase (const T& value)
|
||||
{
|
||||
mStatic.setBase (value);
|
||||
|
||||
if (mCurrent>getModified())
|
||||
mCurrent = getModified();
|
||||
}
|
||||
template<typename T>
|
||||
void DynamicStat<T>::setModified (T value, const T& min, const T& max)
|
||||
{
|
||||
mStatic.setModified (value, min, max);
|
||||
|
||||
if (mCurrent>getModified())
|
||||
mCurrent = getModified();
|
||||
}
|
||||
template<typename T>
|
||||
void DynamicStat<T>::modify (const T& diff, bool allowCurrentDecreaseBelowZero)
|
||||
{
|
||||
mStatic.modify (diff);
|
||||
setCurrent (getCurrent()+diff, allowCurrentDecreaseBelowZero);
|
||||
}
|
||||
template<typename T>
|
||||
void DynamicStat<T>::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<typename T>
|
||||
void DynamicStat<T>::setModifier (const T& modifier, bool allowCurrentDecreaseBelowZero)
|
||||
{
|
||||
T diff = modifier - mStatic.getModifier();
|
||||
mStatic.setModifier (modifier);
|
||||
setCurrent (getCurrent()+diff, allowCurrentDecreaseBelowZero);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void DynamicStat<T>::writeState (ESM::StatState<T>& state) const
|
||||
{
|
||||
mStatic.writeState (state);
|
||||
state.mCurrent = mCurrent;
|
||||
}
|
||||
template<typename T>
|
||||
void DynamicStat<T>::readState (const ESM::StatState<T>& 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 = std::max(0, 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<int>& state) const
|
||||
{
|
||||
state.mBase = mBase;
|
||||
state.mMod = mModifier;
|
||||
state.mDamage = mDamage;
|
||||
}
|
||||
|
||||
void AttributeValue::readState (const ESM::StatState<int>& 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<int>& state) const
|
||||
{
|
||||
AttributeValue::writeState (state);
|
||||
state.mProgress = mProgress;
|
||||
}
|
||||
|
||||
void SkillValue::readState (const ESM::StatState<int>& state)
|
||||
{
|
||||
AttributeValue::readState (state);
|
||||
mProgress = state.mProgress;
|
||||
}
|
||||
}
|
||||
|
||||
void MWMechanics::AttributeValue::readState (const ESM::StatState<int>& state)
|
||||
{
|
||||
mBase = state.mBase;
|
||||
mModifier = state.mMod;
|
||||
mDamage = state.mDamage;
|
||||
}
|
||||
|
||||
void MWMechanics::SkillValue::writeState (ESM::StatState<int>& state) const
|
||||
{
|
||||
AttributeValue::writeState (state);
|
||||
state.mProgress = mProgress;
|
||||
}
|
||||
|
||||
void MWMechanics::SkillValue::readState (const ESM::StatState<int>& state)
|
||||
{
|
||||
AttributeValue::readState (state);
|
||||
mProgress = state.mProgress;
|
||||
}
|
||||
template class MWMechanics::Stat<int>;
|
||||
template class MWMechanics::Stat<float>;
|
||||
template class MWMechanics::DynamicStat<int>;
|
||||
template class MWMechanics::DynamicStat<float>;
|
||||
|
@ -4,7 +4,11 @@
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
|
||||
#include <components/esm/statstate.hpp>
|
||||
namespace ESM
|
||||
{
|
||||
template<typename T>
|
||||
struct StatState;
|
||||
}
|
||||
|
||||
namespace MWMechanics
|
||||
{
|
||||
@ -17,87 +21,28 @@ namespace MWMechanics
|
||||
public:
|
||||
typedef T Type;
|
||||
|
||||
Stat() : mBase (0), mModified (0) {}
|
||||
Stat(T base) : mBase (base), mModified (base) {}
|
||||
Stat(T base, T modified) : mBase (base), mModified (modified) {}
|
||||
Stat();
|
||||
Stat(T base);
|
||||
Stat(T base, T modified);
|
||||
|
||||
const T& getBase() const
|
||||
{
|
||||
return mBase;
|
||||
}
|
||||
const T& getBase() const;
|
||||
|
||||
T getModified() const
|
||||
{
|
||||
return std::max(static_cast<T>(0), mModified);
|
||||
}
|
||||
|
||||
T getModifier() const
|
||||
{
|
||||
return mModified-mBase;
|
||||
}
|
||||
T getModified() const;
|
||||
T getModifier() const;
|
||||
|
||||
/// Set base and modified to \a value.
|
||||
void set (const T& value)
|
||||
{
|
||||
mBase = mModified = value;
|
||||
}
|
||||
|
||||
void modify(const T& diff)
|
||||
{
|
||||
mBase += diff;
|
||||
if(mBase >= static_cast<T>(0))
|
||||
mModified += diff;
|
||||
else
|
||||
{
|
||||
mModified += diff - mBase;
|
||||
mBase = static_cast<T>(0);
|
||||
}
|
||||
}
|
||||
void set (const T& value);
|
||||
void modify(const T& diff);
|
||||
|
||||
/// Set base and adjust modified accordingly.
|
||||
void setBase (const T& value)
|
||||
{
|
||||
T diff = value - mBase;
|
||||
mBase = value;
|
||||
mModified += diff;
|
||||
}
|
||||
void setBase (const T& value);
|
||||
|
||||
/// Set modified value an adjust base accordingly.
|
||||
void setModified (T value, const T& min, const T& max = std::numeric_limits<T>::max())
|
||||
{
|
||||
T diff = value - mModified;
|
||||
void setModified (T value, const T& min, const T& max = std::numeric_limits<T>::max());
|
||||
void setModifier (const T& modifier);
|
||||
|
||||
if (mBase+diff<min)
|
||||
{
|
||||
value = min + (mModified - mBase);
|
||||
diff = value - mModified;
|
||||
}
|
||||
else if (mBase+diff>max)
|
||||
{
|
||||
value = max + (mModified - mBase);
|
||||
diff = value - mModified;
|
||||
}
|
||||
|
||||
mModified = value;
|
||||
mBase += diff;
|
||||
}
|
||||
|
||||
void setModifier (const T& modifier)
|
||||
{
|
||||
mModified = mBase + modifier;
|
||||
}
|
||||
|
||||
void writeState (ESM::StatState<T>& state) const
|
||||
{
|
||||
state.mBase = mBase;
|
||||
state.mMod = mModified;
|
||||
}
|
||||
|
||||
void readState (const ESM::StatState<T>& state)
|
||||
{
|
||||
mBase = state.mBase;
|
||||
mModified = state.mMod;
|
||||
}
|
||||
void writeState (ESM::StatState<T>& state) const;
|
||||
void readState (const ESM::StatState<T>& state);
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
@ -122,98 +67,32 @@ namespace MWMechanics
|
||||
public:
|
||||
typedef T Type;
|
||||
|
||||
DynamicStat() : mStatic (0), mCurrent (0) {}
|
||||
DynamicStat(T base) : mStatic (base), mCurrent (base) {}
|
||||
DynamicStat(T base, T modified, T current) : mStatic(base, modified), mCurrent (current) {}
|
||||
DynamicStat(const Stat<T> &stat, T current) : mStatic(stat), mCurrent (current) {}
|
||||
DynamicStat();
|
||||
DynamicStat(T base);
|
||||
DynamicStat(T base, T modified, T current);
|
||||
DynamicStat(const Stat<T> &stat, T current);
|
||||
|
||||
const T& getBase() const
|
||||
{
|
||||
return mStatic.getBase();
|
||||
}
|
||||
|
||||
T getModified() const
|
||||
{
|
||||
return mStatic.getModified();
|
||||
}
|
||||
|
||||
const T& getCurrent() const
|
||||
{
|
||||
return mCurrent;
|
||||
}
|
||||
const T& getBase() const;
|
||||
T getModified() const;
|
||||
const T& getCurrent() const;
|
||||
|
||||
/// Set base, modified and current to \a value.
|
||||
void set (const T& value)
|
||||
{
|
||||
mStatic.set (value);
|
||||
mCurrent = value;
|
||||
}
|
||||
void set (const T& value);
|
||||
|
||||
/// Set base and adjust modified accordingly.
|
||||
void setBase (const T& value)
|
||||
{
|
||||
mStatic.setBase (value);
|
||||
|
||||
if (mCurrent>getModified())
|
||||
mCurrent = getModified();
|
||||
}
|
||||
void setBase (const T& value);
|
||||
|
||||
/// Set modified value an adjust base accordingly.
|
||||
void setModified (T value, const T& min, const T& max = std::numeric_limits<T>::max())
|
||||
{
|
||||
mStatic.setModified (value, min, max);
|
||||
|
||||
if (mCurrent>getModified())
|
||||
mCurrent = getModified();
|
||||
}
|
||||
void setModified (T value, const T& min, const T& max = std::numeric_limits<T>::max());
|
||||
|
||||
/// Change modified relatively.
|
||||
void modify (const T& diff, bool allowCurrentDecreaseBelowZero=false)
|
||||
{
|
||||
mStatic.modify (diff);
|
||||
setCurrent (getCurrent()+diff, allowCurrentDecreaseBelowZero);
|
||||
}
|
||||
void modify (const T& diff, bool allowCurrentDecreaseBelowZero=false);
|
||||
|
||||
void setCurrent (const T& value, bool allowDecreaseBelowZero = false)
|
||||
{
|
||||
if (value > mCurrent)
|
||||
{
|
||||
// increase
|
||||
mCurrent = value;
|
||||
void setCurrent (const T& value, bool allowDecreaseBelowZero = false);
|
||||
void setModifier (const T& modifier, bool allowCurrentDecreaseBelowZero=false);
|
||||
|
||||
if (mCurrent > getModified())
|
||||
mCurrent = getModified();
|
||||
}
|
||||
else if (value > 0 || allowDecreaseBelowZero)
|
||||
{
|
||||
// allowed decrease
|
||||
mCurrent = value;
|
||||
}
|
||||
else if (mCurrent > 0)
|
||||
{
|
||||
// capped decrease
|
||||
mCurrent = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void setModifier (const T& modifier, bool allowCurrentDecreaseBelowZero=false)
|
||||
{
|
||||
T diff = modifier - mStatic.getModifier();
|
||||
mStatic.setModifier (modifier);
|
||||
setCurrent (getCurrent()+diff, allowCurrentDecreaseBelowZero);
|
||||
}
|
||||
|
||||
void writeState (ESM::StatState<T>& state) const
|
||||
{
|
||||
mStatic.writeState (state);
|
||||
state.mCurrent = mCurrent;
|
||||
}
|
||||
|
||||
void readState (const ESM::StatState<T>& state)
|
||||
{
|
||||
mStatic.readState (state);
|
||||
mCurrent = state.mCurrent;
|
||||
}
|
||||
void writeState (ESM::StatState<T>& state) const;
|
||||
void readState (const ESM::StatState<T>& state);
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
@ -237,26 +116,25 @@ namespace MWMechanics
|
||||
float mDamage; // needs to be float to allow continuous damage
|
||||
|
||||
public:
|
||||
AttributeValue() : mBase(0), mModifier(0), mDamage(0) {}
|
||||
AttributeValue();
|
||||
|
||||
int getModified() const { return std::max(0, mBase - (int) mDamage + mModifier); }
|
||||
int getBase() const { return mBase; }
|
||||
int getModifier() const { return mModifier; }
|
||||
int getModified() const;
|
||||
int getBase() const;
|
||||
int getModifier() const;
|
||||
|
||||
void setBase(int base) { mBase = std::max(0, base); }
|
||||
void setBase(int base);
|
||||
|
||||
void setModifier(int mod) { mModifier = mod; }
|
||||
void setModifier(int mod);
|
||||
|
||||
// Maximum attribute damage is limited to the modified value.
|
||||
// Note: I think MW applies damage directly to mModified, since you can also
|
||||
// "restore" drained attributes. We need to rewrite the magic effect system to support this.
|
||||
void damage(float damage) { mDamage += std::min(damage, (float)getModified()); }
|
||||
void restore(float amount) { mDamage -= std::min(mDamage, amount); }
|
||||
void damage(float damage);
|
||||
void restore(float amount);
|
||||
|
||||
float getDamage() const { return mDamage; }
|
||||
float getDamage() const;
|
||||
|
||||
void writeState (ESM::StatState<int>& state) const;
|
||||
|
||||
void readState (const ESM::StatState<int>& state);
|
||||
};
|
||||
|
||||
@ -264,12 +142,11 @@ namespace MWMechanics
|
||||
{
|
||||
float mProgress;
|
||||
public:
|
||||
SkillValue() : mProgress(0) {}
|
||||
float getProgress() const { return mProgress; }
|
||||
void setProgress(float progress) { mProgress = progress; }
|
||||
SkillValue();
|
||||
float getProgress() const;
|
||||
void setProgress(float progress);
|
||||
|
||||
void writeState (ESM::StatState<int>& state) const;
|
||||
|
||||
void readState (const ESM::StatState<int>& state);
|
||||
};
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include <components/files/collections.hpp>
|
||||
#include <components/compiler/locals.hpp>
|
||||
#include <components/esm/cellid.hpp>
|
||||
#include <components/esm/esmreader.hpp>
|
||||
#include <components/misc/resourcehelpers.hpp>
|
||||
#include <components/resource/resourcesystem.hpp>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user