From f40b90570c4cfb272aa1360c920928f2b378d634 Mon Sep 17 00:00:00 2001 From: Matei Date: Sat, 13 May 2006 04:07:42 +0000 Subject: [PATCH] # Fixed a bug with the run action. Also added a pass-through-allies attribute in CEntity as m_passThroughAllies (actions.move.pass_through_allies). This was SVN commit r3853. --- source/simulation/BaseEntity.cpp | 5 ++- source/simulation/BaseEntity.h | 2 + source/simulation/Entity.cpp | 43 ++++++++++++++++----- source/simulation/Entity.h | 3 ++ source/simulation/EntityStateProcessing.cpp | 22 +++++------ 5 files changed, 53 insertions(+), 22 deletions(-) diff --git a/source/simulation/BaseEntity.cpp b/source/simulation/BaseEntity.cpp index 51ec78302e..d82352f4b1 100644 --- a/source/simulation/BaseEntity.cpp +++ b/source/simulation/BaseEntity.cpp @@ -19,11 +19,12 @@ CBaseEntity::CBaseEntity() AddProperty( L"parent", &m_base, false ); AddProperty( L"actions.move.speed_curr", &m_speed ); AddProperty( L"actions.move.turningradius", &m_turningRadius ); - AddProperty( L"actions.move.run.speed.curr", &( m_run.m_Speed ) ); + AddProperty( L"actions.move.run.speed", &m_runSpeed ); AddProperty( L"actions.move.run.rangemin", &( m_run.m_MinRange ) ); AddProperty( L"actions.move.run.range", &( m_run.m_MaxRange ) ); AddProperty( L"actions.move.run.regen_rate", &m_runRegenRate ); AddProperty( L"actions.move.run.decay_rate", &m_runDecayRate ); + AddProperty( L"actions.move.pass_through_allies", &m_passThroughAllies ); AddProperty( L"actor", &m_actorName ); AddProperty( L"traits.extant", &m_extant ); AddProperty( L"traits.corpse", &m_corpse ); @@ -38,7 +39,6 @@ CBaseEntity::CBaseEntity() 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"traits.stamina.curr", &m_staminaCurr ); AddProperty( L"traits.stamina.max", &m_staminaMax ); AddProperty( L"traits.stamina.bar_height", &m_staminaBarHeight ); @@ -74,6 +74,7 @@ CBaseEntity::CBaseEntity() m_extant = true; m_corpse = CStrW(); m_foundation = CStrW(); + m_passThroughAllies = false; // Sentinel values for stamina and health (so scripts can check if an entity has no stamina or no HP). m_speed=0; diff --git a/source/simulation/BaseEntity.h b/source/simulation/BaseEntity.h index 9f6b07595b..d56925c24a 100644 --- a/source/simulation/BaseEntity.h +++ b/source/simulation/BaseEntity.h @@ -104,8 +104,10 @@ public: CStrW m_foundation; float m_speed; + float m_runSpeed; float m_runRegenRate; float m_runDecayRate; + bool m_passThroughAllies; SEntityAction m_run; SEntityAction m_generic; diff --git a/source/simulation/Entity.cpp b/source/simulation/Entity.cpp index f720ca7081..95f5b72120 100644 --- a/source/simulation/Entity.cpp +++ b/source/simulation/Entity.cpp @@ -49,11 +49,12 @@ CEntity::CEntity( CBaseEntity* base, CVector3D position, float orientation, cons also be added to BaseEntity.h */ AddProperty( L"actions.move.speed_curr", &m_speed ); - AddProperty( L"actions.move.run.speed.curr", &( m_run.m_Speed ) ); + AddProperty( L"actions.move.run.speed", &m_runSpeed ); AddProperty( L"actions.move.run.rangemin", &( m_run.m_MinRange ) ); AddProperty( L"actions.move.run.range", &( m_run.m_MaxRange ) ); AddProperty( L"actions.move.run.regen_rate", &m_runRegenRate ); AddProperty( L"actions.move.run.decay_rate", &m_runDecayRate ); + AddProperty( L"actions.move.pass_through_allies", &m_passThroughAllies ); AddProperty( L"selected", &m_selected, false, (NotifyFn)&CEntity::checkSelection ); AddProperty( L"group", &m_grouped, false, (NotifyFn)&CEntity::checkGroup ); AddProperty( L"traits.extant", &m_extant ); @@ -73,7 +74,6 @@ CEntity::CEntity( CBaseEntity* base, CVector3D position, float orientation, cons 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"traits.stamina.curr", &m_staminaCurr ); AddProperty( L"traits.stamina.max", &m_staminaMax ); AddProperty( L"traits.stamina.bar_height", &m_staminaBarHeight ); @@ -94,7 +94,6 @@ CEntity::CEntity( CBaseEntity* base, CVector3D position, float orientation, cons AddProperty( L"traits.anchor.type", &m_anchorType ); AddProperty( L"traits.anchor.conformx", &m_anchorConformX ); AddProperty( L"traits.anchor.conformz", &m_anchorConformZ ); - AddProperty( L"traits.vision.los", &m_los ); AddProperty( L"traits.vision.permanent", &m_permanent ); AddProperty( L"last_combat_time", &m_lastCombatTime ); @@ -512,6 +511,32 @@ void CEntity::update( size_t timestep ) } } + if( m_orderQueue.empty() ) + { + // If we have no orders, stop running + m_isRunning = false; + m_shouldRun = false; + } + else + { + // If the front order is not a movement order, stop running + switch(m_orderQueue.front().m_type) + { + case CEntityOrder::ORDER_GOTO_NOPATHING: + case CEntityOrder::ORDER_GOTO_COLLISION: + case CEntityOrder::ORDER_GOTO_SMOOTHED: + case CEntityOrder::ORDER_GOTO_WAYPOINT: + case CEntityOrder::ORDER_GOTO_WAYPOINT_CONTACT: + case CEntityOrder::ORDER_GOTO: + case CEntityOrder::ORDER_RUN: + break; + default: + m_isRunning = false; + //m_shouldRun = false; + break; + } + } + PROFILE_END( "state processing" ); if( m_actor ) @@ -1251,15 +1276,15 @@ void CEntity::renderStaminaBar() glBegin(GL_LINES); // blue part of bar - glColor3f( 0, 0, 1 ); + glColor3f( 0.1f, 0.1f, 1 ); glVertex3f( x1, y, 0 ); - glColor3f( 0, 0, 1 ); + glColor3f( 0.1f, 0.1f, 1 ); glVertex3f( x1 + m_staminaBarSize*fraction, y, 0 ); - // red part of bar - glColor3f( 1, 0, 0 ); + // purple part of bar + glColor3f( 0.3f, 0, 0.3f ); glVertex3f( x1 + m_staminaBarSize*fraction, y, 0 ); - glColor3f( 1, 0, 0 ); + glColor3f( 0.3f, 0, 0.3f ); glVertex3f( x2, y, 0 ); glEnd(); @@ -1990,7 +2015,7 @@ jsval CEntity::SetRun( JSContext* cx, uintN argc, jsval* argv ) } jsval CEntity::GetRunState( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) ) { - return m_isRunning; + return BOOLEAN_TO_JSVAL( m_shouldRun ); } jsval CEntity::GetFormationPenalty( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) ) { diff --git a/source/simulation/Entity.h b/source/simulation/Entity.h index d19ec5146d..39be057aec 100644 --- a/source/simulation/Entity.h +++ b/source/simulation/Entity.h @@ -74,10 +74,13 @@ public: // Production queue CProductionQueue* m_productionQueue; + // Movement properties float m_speed; float m_turningRadius; + float m_runSpeed; float m_runRegenRate; float m_runDecayRate; + bool m_passThroughAllies; float m_maxActorPitch; float m_minActorPitch; diff --git a/source/simulation/EntityStateProcessing.cpp b/source/simulation/EntityStateProcessing.cpp index 4865695495..27b5cca6d3 100644 --- a/source/simulation/EntityStateProcessing.cpp +++ b/source/simulation/EntityStateProcessing.cpp @@ -42,14 +42,14 @@ float CEntity::processChooseMovement( float distance ) if ( !m_actor->IsPlayingAnimation( "run" ) ) { m_actor->SetEntitySelection( L"run" ); - m_actor->SetRandomAnimation( "run", false, m_run.m_Speed ); + m_actor->SetRandomAnimation( "run", false, m_runSpeed ); // Animation desync m_actor->GetModel()->Update( rand( 0, 1000 ) / 1000.0f ); m_isRunning = true; } } - return m_run.m_Speed; + return m_runSpeed; } else { @@ -254,8 +254,8 @@ bool CEntity::processGotoNoPathing( CEntityOrder* current, size_t timestep_milli else { m_orderQueue.pop_front(); - m_isRunning = false; - m_shouldRun = false; + //m_isRunning = false; + //m_shouldRun = false; } return( false ); case COLLISION_OVERLAPPING_OBJECTS: @@ -263,8 +263,8 @@ bool CEntity::processGotoNoPathing( CEntityOrder* current, size_t timestep_milli case COLLISION_WITH_DESTINATION: // We're here... m_orderQueue.pop_front(); - m_isRunning = false; - m_shouldRun = false; + //m_isRunning = false; + //m_shouldRun = false; return( false ); case COLLISION_NEAR_DESTINATION: @@ -328,8 +328,8 @@ bool CEntity::processGotoNoPathing( CEntityOrder* current, size_t timestep_milli case WOULD_LEAVE_MAP: // Just stop here, repath if necessary. m_orderQueue.pop_front(); - m_isRunning = false; - m_shouldRun = false; + //m_isRunning = false; + //m_shouldRun = false; return( false ); default: @@ -592,8 +592,8 @@ bool CEntity::processGoto( CEntityOrder* current, size_t UNUSED(timestep_millis) // Let's just check we're going somewhere... if( Distance < 0.1f ) { - m_isRunning = false; - m_shouldRun = false; + //m_isRunning = false; + //m_shouldRun = false; return( false ); } @@ -617,7 +617,7 @@ bool CEntity::processGotoWaypoint( CEntityOrder* current, size_t UNUSED(timestep if( Distance < 0.1f ) { m_isRunning = false; - m_shouldRun = false; + //m_shouldRun = false; return( false ); }