mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-10-31 10:56:38 +00:00 
			
		
		
		
	
							parent
							
								
									61b34124e2
								
							
						
					
					
						commit
						2cc1b52baf
					
				
					 5 changed files with 103 additions and 20 deletions
				
			
		|  | @ -546,7 +546,7 @@ namespace MWMechanics | ||||||
|         float diff = (static_cast<int>(magickaFactor*intelligence)) - magicka.getBase(); |         float diff = (static_cast<int>(magickaFactor*intelligence)) - magicka.getBase(); | ||||||
|         float currentToBaseRatio = (magicka.getCurrent() / magicka.getBase()); |         float currentToBaseRatio = (magicka.getCurrent() / magicka.getBase()); | ||||||
|         magicka.setModified(magicka.getModified() + diff, 0); |         magicka.setModified(magicka.getModified() + diff, 0); | ||||||
|         magicka.setCurrent(magicka.getBase() * currentToBaseRatio); |         magicka.setCurrent(magicka.getBase() * currentToBaseRatio, false, true); | ||||||
|         creatureStats.setMagicka(magicka); |         creatureStats.setMagicka(magicka); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -578,7 +578,13 @@ namespace MWMechanics | ||||||
|         if (normalizedEncumbrance > 1) |         if (normalizedEncumbrance > 1) | ||||||
|             normalizedEncumbrance = 1; |             normalizedEncumbrance = 1; | ||||||
|   |   | ||||||
|         // restore fatigue
 |         // Current fatigue can be above base value due to a fortify effect.
 | ||||||
|  |         // In that case stop here and don't try to restore.
 | ||||||
|  |         DynamicStat<float> fatigue = stats.getFatigue(); | ||||||
|  |         if (fatigue.getCurrent() >= fatigue.getBase()) | ||||||
|  |             return; | ||||||
|  | 
 | ||||||
|  |         // Restore fatigue
 | ||||||
|         float fFatigueReturnBase = settings.find("fFatigueReturnBase")->getFloat (); |         float fFatigueReturnBase = settings.find("fFatigueReturnBase")->getFloat (); | ||||||
|         float fFatigueReturnMult = settings.find("fFatigueReturnMult")->getFloat (); |         float fFatigueReturnMult = settings.find("fFatigueReturnMult")->getFloat (); | ||||||
|         float fEndFatigueMult = settings.find("fEndFatigueMult")->getFloat (); |         float fEndFatigueMult = settings.find("fEndFatigueMult")->getFloat (); | ||||||
|  | @ -586,7 +592,6 @@ namespace MWMechanics | ||||||
|         float x = fFatigueReturnBase + fFatigueReturnMult * (1 - normalizedEncumbrance); |         float x = fFatigueReturnBase + fFatigueReturnMult * (1 - normalizedEncumbrance); | ||||||
|         x *= fEndFatigueMult * endurance; |         x *= fEndFatigueMult * endurance; | ||||||
| 
 | 
 | ||||||
|         DynamicStat<float> fatigue = stats.getFatigue(); |  | ||||||
|         fatigue.setCurrent (fatigue.getCurrent() + 3600 * x); |         fatigue.setCurrent (fatigue.getCurrent() + 3600 * x); | ||||||
|         stats.setFatigue (fatigue); |         stats.setFatigue (fatigue); | ||||||
|     } |     } | ||||||
|  | @ -598,16 +603,20 @@ namespace MWMechanics | ||||||
| 
 | 
 | ||||||
|         MWMechanics::CreatureStats& stats = ptr.getClass().getCreatureStats (ptr); |         MWMechanics::CreatureStats& stats = ptr.getClass().getCreatureStats (ptr); | ||||||
| 
 | 
 | ||||||
|         int endurance = stats.getAttribute (ESM::Attribute::Endurance).getModified (); |         // Current fatigue can be above base value due to a fortify effect.
 | ||||||
|  |         // In that case stop here and don't try to restore.
 | ||||||
|  |         DynamicStat<float> fatigue = stats.getFatigue(); | ||||||
|  |         if (fatigue.getCurrent() >= fatigue.getBase()) | ||||||
|  |             return; | ||||||
| 
 | 
 | ||||||
|         // restore fatigue
 |         // Restore fatigue
 | ||||||
|  |         int endurance = stats.getAttribute(ESM::Attribute::Endurance).getModified(); | ||||||
|         const MWWorld::Store<ESM::GameSetting>& settings = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>(); |         const MWWorld::Store<ESM::GameSetting>& settings = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>(); | ||||||
|         static const float fFatigueReturnBase = settings.find("fFatigueReturnBase")->getFloat (); |         static const float fFatigueReturnBase = settings.find("fFatigueReturnBase")->getFloat (); | ||||||
|         static const float fFatigueReturnMult = settings.find("fFatigueReturnMult")->getFloat (); |         static const float fFatigueReturnMult = settings.find("fFatigueReturnMult")->getFloat (); | ||||||
| 
 | 
 | ||||||
|         float x = fFatigueReturnBase + fFatigueReturnMult * endurance; |         float x = fFatigueReturnBase + fFatigueReturnMult * endurance; | ||||||
| 
 | 
 | ||||||
|         DynamicStat<float> fatigue = stats.getFatigue(); |  | ||||||
|         fatigue.setCurrent (fatigue.getCurrent() + duration * x); |         fatigue.setCurrent (fatigue.getCurrent() + duration * x); | ||||||
|         stats.setFatigue (fatigue); |         stats.setFatigue (fatigue); | ||||||
|     } |     } | ||||||
|  | @ -723,7 +732,7 @@ namespace MWMechanics | ||||||
|         for(int i = 0;i < 3;++i) |         for(int i = 0;i < 3;++i) | ||||||
|         { |         { | ||||||
|             DynamicStat<float> stat = creatureStats.getDynamic(i); |             DynamicStat<float> stat = creatureStats.getDynamic(i); | ||||||
|             stat.setModifier(effects.get(ESM::MagicEffect::FortifyHealth+i).getMagnitude() - |             stat.setCurrentModifier(effects.get(ESM::MagicEffect::FortifyHealth+i).getMagnitude() - | ||||||
|                              effects.get(ESM::MagicEffect::DrainHealth+i).getMagnitude(), |                              effects.get(ESM::MagicEffect::DrainHealth+i).getMagnitude(), | ||||||
|                              // Magicka can be decreased below zero due to a fortify effect wearing off
 |                              // Magicka can be decreased below zero due to a fortify effect wearing off
 | ||||||
|                              // Fatigue can be decreased below zero meaning the actor will be knocked out
 |                              // Fatigue can be decreased below zero meaning the actor will be knocked out
 | ||||||
|  |  | ||||||
|  | @ -195,6 +195,7 @@ namespace MWMechanics | ||||||
|             mDead = true; |             mDead = true; | ||||||
| 
 | 
 | ||||||
|             mDynamic[index].setModifier(0); |             mDynamic[index].setModifier(0); | ||||||
|  |             mDynamic[index].setCurrentModifier(0); | ||||||
|             mDynamic[index].setCurrent(0); |             mDynamic[index].setCurrent(0); | ||||||
| 
 | 
 | ||||||
|             if (MWBase::Environment::get().getWorld()->getGodModeState()) |             if (MWBase::Environment::get().getWorld()->getGodModeState()) | ||||||
|  |  | ||||||
|  | @ -5,11 +5,11 @@ | ||||||
| namespace MWMechanics | namespace MWMechanics | ||||||
| { | { | ||||||
|     template<typename T> |     template<typename T> | ||||||
|     Stat<T>::Stat() : mBase (0), mModified (0) {} |     Stat<T>::Stat() : mBase (0), mModified (0), mCurrentModified (0) {} | ||||||
|     template<typename T> |     template<typename T> | ||||||
|     Stat<T>::Stat(T base) : mBase (base), mModified (base) {} |     Stat<T>::Stat(T base) : mBase (base), mModified (base), mCurrentModified (base) {} | ||||||
|     template<typename T> |     template<typename T> | ||||||
|     Stat<T>::Stat(T base, T modified) : mBase (base), mModified (modified) {} |     Stat<T>::Stat(T base, T modified) : mBase (base), mModified (modified), mCurrentModified (modified) {} | ||||||
| 
 | 
 | ||||||
|     template<typename T> |     template<typename T> | ||||||
|     const T& Stat<T>::getBase() const |     const T& Stat<T>::getBase() const | ||||||
|  | @ -22,23 +22,42 @@ namespace MWMechanics | ||||||
|     { |     { | ||||||
|         return std::max(static_cast<T>(0), mModified); |         return std::max(static_cast<T>(0), mModified); | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     template<typename T> | ||||||
|  |     T Stat<T>::getCurrentModified() const | ||||||
|  |     { | ||||||
|  |         return mCurrentModified; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     template<typename T> |     template<typename T> | ||||||
|     T Stat<T>::getModifier() const |     T Stat<T>::getModifier() const | ||||||
|     { |     { | ||||||
|         return mModified-mBase; |         return mModified-mBase; | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     template<typename T> | ||||||
|  |     T Stat<T>::getCurrentModifier() const | ||||||
|  |     { | ||||||
|  |         return mCurrentModified - mModified; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     template<typename T> |     template<typename T> | ||||||
|     void Stat<T>::set (const T& value) |     void Stat<T>::set (const T& value) | ||||||
|     { |     { | ||||||
|  |         T diff = value - mBase; | ||||||
|         mBase = mModified = value; |         mBase = mModified = value; | ||||||
|  |         mCurrentModified += diff; | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|     template<typename T> |     template<typename T> | ||||||
|     void Stat<T>::setBase (const T& value) |     void Stat<T>::setBase (const T& value) | ||||||
|     { |     { | ||||||
|         T diff = value - mBase; |         T diff = value - mBase; | ||||||
|         mBase = value; |         mBase = value; | ||||||
|         mModified += diff; |         mModified += diff; | ||||||
|  |         mCurrentModified += diff; | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|     template<typename T> |     template<typename T> | ||||||
|     void Stat<T>::setModified (T value, const T& min, const T& max) |     void Stat<T>::setModified (T value, const T& min, const T& max) | ||||||
|     { |     { | ||||||
|  | @ -57,24 +76,39 @@ namespace MWMechanics | ||||||
| 
 | 
 | ||||||
|         mModified = value; |         mModified = value; | ||||||
|         mBase += diff; |         mBase += diff; | ||||||
|  |         mCurrentModified += diff; | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     template<typename T> | ||||||
|  |     void Stat<T>::setCurrentModified(T value) | ||||||
|  |     { | ||||||
|  |         mCurrentModified = value; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     template<typename T> |     template<typename T> | ||||||
|     void Stat<T>::setModifier (const T& modifier) |     void Stat<T>::setModifier (const T& modifier) | ||||||
|     { |     { | ||||||
|         mModified = mBase + modifier; |         mModified = mBase + modifier; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     template<typename T> | ||||||
|  |     void Stat<T>::setCurrentModifier(const T& modifier) | ||||||
|  |     { | ||||||
|  |         mCurrentModified = mModified + modifier; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     template<typename T> |     template<typename T> | ||||||
|     void Stat<T>::writeState (ESM::StatState<T>& state) const |     void Stat<T>::writeState (ESM::StatState<T>& state) const | ||||||
|     { |     { | ||||||
|         state.mBase = mBase; |         state.mBase = mBase; | ||||||
|         state.mMod = mModified; |         state.mMod = mCurrentModified; | ||||||
|     } |     } | ||||||
|     template<typename T> |     template<typename T> | ||||||
|     void Stat<T>::readState (const ESM::StatState<T>& state) |     void Stat<T>::readState (const ESM::StatState<T>& state) | ||||||
|     { |     { | ||||||
|         mBase = state.mBase; |         mBase = state.mBase; | ||||||
|         mModified = state.mMod; |         mModified = state.mBase; | ||||||
|  |         mCurrentModified = state.mMod; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @ -98,6 +132,12 @@ namespace MWMechanics | ||||||
|     { |     { | ||||||
|         return mStatic.getModified(); |         return mStatic.getModified(); | ||||||
|     } |     } | ||||||
|  |     template<typename T> | ||||||
|  |     T DynamicStat<T>::getCurrentModified() const | ||||||
|  |     { | ||||||
|  |         return mStatic.getCurrentModified(); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     template<typename T> |     template<typename T> | ||||||
|     const T& DynamicStat<T>::getCurrent() const |     const T& DynamicStat<T>::getCurrent() const | ||||||
|     { |     { | ||||||
|  | @ -127,14 +167,21 @@ namespace MWMechanics | ||||||
|             mCurrent = getModified(); |             mCurrent = getModified(); | ||||||
|     } |     } | ||||||
|     template<typename T> |     template<typename T> | ||||||
|     void DynamicStat<T>::setCurrent (const T& value, bool allowDecreaseBelowZero) |     void DynamicStat<T>::setCurrentModified(T value) | ||||||
|  |     { | ||||||
|  |         mStatic.setCurrentModified(value); | ||||||
|  |     } | ||||||
|  |     template<typename T> | ||||||
|  |     void DynamicStat<T>::setCurrent (const T& value, bool allowDecreaseBelowZero, bool allowIncreaseAboveModified) | ||||||
|     { |     { | ||||||
|         if (value > mCurrent) |         if (value > mCurrent) | ||||||
|         { |         { | ||||||
|             // increase
 |             // increase
 | ||||||
|  |             if (value <= getModified() || allowIncreaseAboveModified) | ||||||
|                 mCurrent = value; |                 mCurrent = value; | ||||||
| 
 |             else if (mCurrent > getModified()) | ||||||
|             if (mCurrent > getModified()) |                 return; | ||||||
|  |             else | ||||||
|                 mCurrent = getModified(); |                 mCurrent = getModified(); | ||||||
|         } |         } | ||||||
|         else if (value > 0 || allowDecreaseBelowZero) |         else if (value > 0 || allowDecreaseBelowZero) | ||||||
|  | @ -156,6 +203,16 @@ namespace MWMechanics | ||||||
|         setCurrent (getCurrent()+diff, allowCurrentDecreaseBelowZero); |         setCurrent (getCurrent()+diff, allowCurrentDecreaseBelowZero); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     template<typename T> | ||||||
|  |     void DynamicStat<T>::setCurrentModifier(const T& modifier, bool allowCurrentDecreaseBelowZero) | ||||||
|  |     { | ||||||
|  |         T diff = modifier - mStatic.getCurrentModifier(); | ||||||
|  |         mStatic.setCurrentModifier(modifier); | ||||||
|  | 
 | ||||||
|  |         // The (modifier > 0) check here allows increase over modified only if the modifier is positive (a fortify effect is active).
 | ||||||
|  |         setCurrent (getCurrent() + diff, allowCurrentDecreaseBelowZero, (modifier > 0)); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     template<typename T> |     template<typename T> | ||||||
|     void DynamicStat<T>::writeState (ESM::StatState<T>& state) const |     void DynamicStat<T>::writeState (ESM::StatState<T>& state) const | ||||||
|     { |     { | ||||||
|  |  | ||||||
|  | @ -17,6 +17,7 @@ namespace MWMechanics | ||||||
|     { |     { | ||||||
|             T mBase; |             T mBase; | ||||||
|             T mModified; |             T mModified; | ||||||
|  |             T mCurrentModified; | ||||||
| 
 | 
 | ||||||
|         public: |         public: | ||||||
|             typedef T Type; |             typedef T Type; | ||||||
|  | @ -28,7 +29,9 @@ namespace MWMechanics | ||||||
|             const T& getBase() const; |             const T& getBase() const; | ||||||
| 
 | 
 | ||||||
|             T getModified() const; |             T getModified() const; | ||||||
|  |             T getCurrentModified() const; | ||||||
|             T getModifier() const; |             T getModifier() const; | ||||||
|  |             T getCurrentModifier() const; | ||||||
| 
 | 
 | ||||||
|             /// Set base and modified to \a value.
 |             /// Set base and modified to \a value.
 | ||||||
|             void set (const T& value); |             void set (const T& value); | ||||||
|  | @ -36,9 +39,15 @@ namespace MWMechanics | ||||||
|             /// Set base and adjust modified accordingly.
 |             /// Set base and adjust modified accordingly.
 | ||||||
|             void setBase (const T& value); |             void setBase (const T& value); | ||||||
| 
 | 
 | ||||||
|             /// Set modified value an adjust base accordingly.
 |             /// Set modified value and adjust base accordingly.
 | ||||||
|             void setModified (T value, const T& min, const T& max = std::numeric_limits<T>::max()); |             void setModified (T value, const T& min, const T& max = std::numeric_limits<T>::max()); | ||||||
|  | 
 | ||||||
|  |             /// Set "current modified," used for drain and fortify. Unlike the regular modifier
 | ||||||
|  |             /// this just adds and subtracts from the current value without changing the maximum.
 | ||||||
|  |             void setCurrentModified(T value); | ||||||
|  | 
 | ||||||
|             void setModifier (const T& modifier); |             void setModifier (const T& modifier); | ||||||
|  |             void setCurrentModifier (const T& modifier); | ||||||
| 
 | 
 | ||||||
|             void writeState (ESM::StatState<T>& state) const; |             void writeState (ESM::StatState<T>& state) const; | ||||||
|             void readState (const ESM::StatState<T>& state); |             void readState (const ESM::StatState<T>& state); | ||||||
|  | @ -73,6 +82,7 @@ namespace MWMechanics | ||||||
| 
 | 
 | ||||||
|             const T& getBase() const; |             const T& getBase() const; | ||||||
|             T getModified() const; |             T getModified() const; | ||||||
|  |             T getCurrentModified() const; | ||||||
|             const T& getCurrent() const; |             const T& getCurrent() const; | ||||||
| 
 | 
 | ||||||
|             /// Set base, modified and current to \a value.
 |             /// Set base, modified and current to \a value.
 | ||||||
|  | @ -81,11 +91,16 @@ namespace MWMechanics | ||||||
|             /// Set base and adjust modified accordingly.
 |             /// Set base and adjust modified accordingly.
 | ||||||
|             void setBase (const T& value); |             void setBase (const T& value); | ||||||
| 
 | 
 | ||||||
|             /// Set modified value an adjust base accordingly.
 |             /// Set modified value and adjust base accordingly.
 | ||||||
|             void setModified (T value, const T& min, const T& max = std::numeric_limits<T>::max()); |             void setModified (T value, const T& min, const T& max = std::numeric_limits<T>::max()); | ||||||
| 
 | 
 | ||||||
|             void setCurrent (const T& value, bool allowDecreaseBelowZero = false); |             /// Set "current modified," used for drain and fortify. Unlike the regular modifier
 | ||||||
|             void setModifier (const T& modifier, bool allowCurrentDecreaseBelowZero=false); |             /// this just adds and subtracts from the current value without changing the maximum.
 | ||||||
|  |             void setCurrentModified(T value); | ||||||
|  | 
 | ||||||
|  |             void setCurrent (const T& value, bool allowDecreaseBelowZero = false, bool allowIncreaseAboveModified = false); | ||||||
|  |             void setModifier (const T& modifier, bool allowCurrentToDecreaseBelowZero=false); | ||||||
|  |             void setCurrentModifier (const T& modifier, bool allowCurrentToDecreaseBelowZero = false); | ||||||
| 
 | 
 | ||||||
|             void writeState (ESM::StatState<T>& state) const; |             void writeState (ESM::StatState<T>& state) const; | ||||||
|             void readState (const ESM::StatState<T>& state); |             void readState (const ESM::StatState<T>& state); | ||||||
|  |  | ||||||
|  | @ -261,6 +261,7 @@ namespace MWScript | ||||||
|                         .getDynamic (mIndex)); |                         .getDynamic (mIndex)); | ||||||
| 
 | 
 | ||||||
|                     stat.setModified (diff + stat.getModified(), 0); |                     stat.setModified (diff + stat.getModified(), 0); | ||||||
|  |                     stat.setCurrentModified (diff + stat.getCurrentModified()); | ||||||
| 
 | 
 | ||||||
|                     stat.setCurrent (diff + current); |                     stat.setCurrent (diff + current); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue