1
0
forked from 0ad/0ad

Health regen fix for ranged attack.

This was SVN commit r3411.
This commit is contained in:
Matei 2006-01-23 03:56:48 +00:00
parent 1c541db46b
commit c4aea4eb62
5 changed files with 52 additions and 25 deletions

View File

@ -33,7 +33,8 @@ CGame::CGame():
m_GameView(this),
m_pLocalPlayer(NULL),
m_GameStarted(false),
m_Paused(false)
m_Paused(false),
m_Time(0)
{
debug_printf("CGame::CGame(): Game object CREATED; initializing..\n");
}
@ -131,6 +132,8 @@ void CGame::Update(double deltaTime)
return;
}
m_Time += deltaTime;
m_Simulation.Update(deltaTime);
// TODO Detect game over and bring up the summary screen or something

View File

@ -31,6 +31,8 @@ class CGame
bool m_GameStarted;
float m_Time;
enum EOG
{
EOG_NEUTRAL,
@ -89,6 +91,9 @@ public:
{ return &m_GameView; }
inline CSimulation *GetSimulation()
{ return &m_Simulation; }
inline float GetTime()
{ return m_Time; }
private:
PSRETURN RegisterInit(CGameAttributes* pAttribs);

View File

@ -918,14 +918,28 @@ JSBool setWaterAlphaOffset( JSContext* cx, JSObject* UNUSED(globalObject), uint
JSBool isPaused( JSContext* cx, JSObject* UNUSED(globalObject), uint argc, jsval* argv, jsval* rval )
{
REQUIRE_NO_PARAMS( isPaused );
if( !g_Game )
{
JS_ReportError( cx, "Game is not started" );
return JS_FALSE;
}
*rval = g_Game->m_Paused ? JSVAL_TRUE : JSVAL_FALSE;
return( JS_TRUE );
return JS_TRUE ;
}
// Pause/unpause the game
JSBool setPaused( JSContext* cx, JSObject* UNUSED(globalObject), uint argc, jsval* argv, jsval* UNUSED(rval) )
{
REQUIRE_PARAMS( 1, setPaused );
if( !g_Game )
{
JS_ReportError( cx, "Game is not started" );
return JS_FALSE;
}
try
{
g_Game->m_Paused = ToPrimitive<bool>( argv[0] );
@ -934,7 +948,23 @@ JSBool setPaused( JSContext* cx, JSObject* UNUSED(globalObject), uint argc, jsva
{
JS_ReportError( cx, "Invalid parameter to setPaused" );
}
return( JS_TRUE );
return JS_TRUE;
}
// Get game time
JSBool getGameTime( JSContext* cx, JSObject* UNUSED(globalObject), uint argc, jsval* argv, jsval* rval )
{
REQUIRE_NO_PARAMS( getGameTime );
if( !g_Game )
{
JS_ReportError( cx, "Game is not started" );
return JS_FALSE;
}
*rval = ToJSVal(g_Game->GetTime());
return JS_TRUE;
}
// Reveal map
@ -1042,6 +1072,7 @@ JSFunctionSpec ScriptFunctionTable[] =
JS_FUNC(exit, exitProgram, 0)
JS_FUNC(isPaused, isPaused, 0)
JS_FUNC(setPaused, setPaused, 1)
JS_FUNC(getGameTime, getGameTime, 0)
JS_FUNC(vmem, vmem, 0)
JS_FUNC(_rewriteMaps, _rewriteMaps, 0)
JS_FUNC(_lodbias, _lodbias, 0)

View File

@ -72,6 +72,7 @@ CEntity::CEntity( CBaseEntity* base, CVector3D position, float orientation )
AddProperty( L"traits.health.regen_rate", &m_healthRegenRate );
AddProperty( L"traits.health.regen_start", &m_healthRegenStart );
AddProperty( L"traits.health.decay_rate", &m_healthDecayRate );
AddProperty( L"last_combat_time", &m_lastCombatTime );
for( int t = 0; t < EVENT_LAST; t++ )
{
@ -113,7 +114,7 @@ CEntity::CEntity( CBaseEntity* base, CVector3D position, float orientation )
m_healthDecay = false;
m_frameCheck = 0;
m_lastAttackTime = 0;
m_lastCombatTime = 0;
m_grouped = -1;
@ -318,9 +319,6 @@ void CEntity::update( size_t timestep )
m_position_previous = m_position;
m_orientation_previous = m_orientation;
if ( IsAttacking() )
m_lastAttackTime = get_time();
CalculateRun( timestep );
CalculateHealth( timestep );
@ -1021,10 +1019,14 @@ void CEntity::renderStaminaBar()
void CEntity::CalculateRun(float timestep)
{
if ( m_isRunning )
if ( m_isRunning && m_runDecayRate > 0 )
{
m_staminaCurr = max( 0.0f, m_staminaCurr - timestep / 1000.0f / m_runDecayRate * m_staminaMax );
else if ( m_orderQueue.empty() )
}
else if ( m_orderQueue.empty() && m_runRegenRate > 0 )
{
m_staminaCurr = min( m_staminaMax, m_staminaCurr + timestep / 1000.0f / m_runRegenRate * m_staminaMax );
}
}
void CEntity::CalculateHealth(float timestep)
@ -1033,24 +1035,11 @@ void CEntity::CalculateHealth(float timestep)
{
m_healthCurr = max( 0.0f, m_healthCurr - timestep / 1000.0f / m_healthDecayRate * m_healthMax );
}
else if ( m_healthRegenRate > 0 && get_time() - m_lastAttackTime > m_healthRegenStart && !IsAttacking() )
else if ( m_healthRegenRate > 0 && g_Game->GetTime() - m_lastCombatTime > m_healthRegenStart )
{
m_healthCurr = min( m_healthMax, m_healthCurr + timestep / 1000.0f / m_healthRegenRate * m_healthMax );
}
}
bool CEntity::IsAttacking()
{
if ( !m_orderQueue.empty() )
{
if ( ( m_orderQueue.front().m_type == CEntityOrder::ORDER_GENERIC ||
m_orderQueue.front().m_type == CEntityOrder::ORDER_GENERIC_NOPATHING ) &&
m_orderQueue.front().m_data[1].data == 1 )
{
return true;
}
}
return false;
}
/*

View File

@ -98,7 +98,7 @@ public:
bool m_triggerRun; //used in SetRun, corrects 1 frame stamina imbalance
int m_frameCheck; //counts the frame
float m_lastAttackTime;
float m_lastCombatTime;
//SP properties
float m_staminaCurr;
@ -249,7 +249,6 @@ public:
//Calculate stamina points
void CalculateRun(float timestep);
void CalculateHealth(float timestep);
bool IsAttacking();
// Reset properties after the entity-template we use changes.
void loadBase();