📄 stamina.cpp
字号:
#include "Stamina.h"
#include "CppConst.h"
/*****************************************************************************/
/********************* CLASS STAMINA *****************************************/
/*****************************************************************************/
/*! This is the constructor for this class. It sets the stamina, effort and
recovery on the supplied values.
\param dSta new stamina value (default 4000.0)
\param dEff new effort value (default 1.0)
\param dRec new recovery value (default 1.0)*/
Stamina::Stamina( double dSta, double dEff, double dRec )
{
setStamina ( dSta );
setEffort ( dEff );
setRecovery( dRec );
}
/*! This method returns the current stamina value.
\return current stamina value (>0) */
double Stamina::getStamina() const
{
return m_dStamina;
}
/*! This method sets the stamina value. This value should be positive,
otherwise the value is set to 0 and false is returned.
\param d new stamina value
\return bool indicating whether value was set. */
bool Stamina::setStamina( double d )
{
if( d < 0.0 )
{
m_dStamina = 0.0;
return false;
}
else
m_dStamina = d;
return true;
}
/*! This method returns the effort. The effort denotes the percentage of
the power in a dash that is actually used. Normally this is 1.0
(100%), but when it comes below a threshold, it decreases. It will again
rise when stamina becomes higher than a certain threshold defined in
ServerSettings.
\return effort value between 0 and 1 */
double Stamina::getEffort() const
{
return m_dEffort;
}
/*! This method sets the effort value. This value should be between 0 and 1,
otherwise the value is set to the closest value in this interval
(0 for negative values, 1 for higher values) and false is returned.
\param d new effort value (0..1)
\return bool indicating whether value was set. */
bool Stamina::setEffort( double d )
{
if( d < 0.0 )
{
m_dEffort = 0.0;
return false;
}
else if( d > 1.0 )
{
m_dEffort = 1.0;
return false;
}
else
m_dEffort = d;
return true;
}
/*! This method returns the recovery. Recovery denotes the percentage of
the stamina increase that is added to the stamina every cycle. If recovery
is 1.0 all of the increase of stamina is added to the current stamina.
When stamina becomes below a certain threshold defined in ServerSettings,
the recovery is decreased. It can never increase!
\return recovery value between 0 and 1 */
double Stamina::getRecovery() const
{
return m_dRecovery;
}
/*! This method sets the recovery value. This value should be between 0 and 1,
otherwise the value is set to the closest value in this interval (0 for
negative values, 1 for higher values) and false is returned.
\param d new recovery value (0..1)
\return bool indicating whether value was set. */
bool Stamina::setRecovery( double d )
{
if( d < 0.0 )
{
m_dRecovery = 0.0;
return false;
}
else if( d > 1.0 )
{
m_dRecovery = 1.0;
return false;
}
else
m_dRecovery = d;
return true;
}
void Stamina::calStaminaAfterDash( double dPower)
{
// double negative value when dashed backwards
m_dStamina -= ( dPower > 0.0 ) ? dPower : -2 * dPower ;
if( m_dStamina < 0 ) m_dStamina = 0;
// stamina below recovery threshold, lower recovery
if( m_dStamina <= CRECOVERDECTHR*CSTAMINAMAX &&
m_dRecovery > CRECOVERMIN)
m_dRecovery -= CRECOVERDEC;
// stamina below effort decrease threshold, lower effort
if( m_dStamina <= CRECOVERDECTHR*CSTAMINAMAX &&
m_dEffort > CEFFORTMIN )
m_dEffort -= CEFFORTDEC;
// stamina higher than effort incr threshold, raise effort and check maximum
if( m_dStamina >= CEFFORTINCTHR * CSTAMINAMAX &&
m_dEffort < 1.0)
{
m_dEffort += CEFFORTINC;
if ( m_dEffort > 1.0 )
m_dEffort = 1.0;
}
// increase stamina with (new) recovery value and check for maximum
m_dStamina += m_dRecovery*CSTAMINAINCMAX;
if ( m_dStamina > CSTAMINAMAX )
m_dStamina = CSTAMINAMAX;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -