2010-07-26 10:52:32 +00:00
|
|
|
#ifndef GAME_MWMECHANICS_STAT_H
|
|
|
|
#define GAME_MWMECHANICS_STAT_H
|
|
|
|
|
2010-07-26 21:09:37 +00:00
|
|
|
#include <limits>
|
|
|
|
|
2010-07-26 10:52:32 +00:00
|
|
|
namespace MWMechanics
|
|
|
|
{
|
|
|
|
template<typename T>
|
|
|
|
class Stat
|
|
|
|
{
|
|
|
|
T mBase;
|
|
|
|
T mModified;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
Stat() : mBase (0), mModified (0) {}
|
|
|
|
|
|
|
|
const T& getBase() const
|
|
|
|
{
|
|
|
|
return mBase;
|
|
|
|
}
|
|
|
|
|
|
|
|
const T& getModified() const
|
|
|
|
{
|
|
|
|
return mModified;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Set base and modified to \a value.
|
|
|
|
void set (const T& value)
|
|
|
|
{
|
|
|
|
mBase = mModified = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Set base and adjust modified accordingly.
|
|
|
|
void setBase (const T& value)
|
|
|
|
{
|
|
|
|
T diff = value - mBase;
|
|
|
|
mBase = value;
|
|
|
|
mModified += diff;
|
|
|
|
}
|
|
|
|
|
2010-07-26 21:09:37 +00:00
|
|
|
/// 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;
|
|
|
|
|
|
|
|
if (mBase+diff<min)
|
|
|
|
{
|
|
|
|
value = min + (mModified - mBase);
|
|
|
|
diff = value - mModified;
|
|
|
|
}
|
|
|
|
else if (mBase>max-diff)
|
|
|
|
{
|
|
|
|
value = max + (mModified - mBase);
|
|
|
|
diff = value - mModified;
|
|
|
|
}
|
|
|
|
|
|
|
|
mModified = value;
|
|
|
|
mBase += diff;
|
|
|
|
}
|
|
|
|
|
2010-07-26 10:52:32 +00:00
|
|
|
/// Change modified relatively.
|
|
|
|
void modify (const T& diff)
|
|
|
|
{
|
|
|
|
mModified += diff;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|