Added health properties to BaseEntity so they work properly for Entity as well (on units that don't directly specify them).
This was SVN commit r2677.
This commit is contained in:
parent
5f2857b6b8
commit
9dc8a71b15
@ -260,7 +260,7 @@ void Render()
|
||||
PROFILE_END( "render building placement cursor" );
|
||||
|
||||
|
||||
PROFILE_START( "render hitpoint bars" );
|
||||
PROFILE_START( "render health bars" );
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
@ -268,13 +268,13 @@ void Render()
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
g_Mouseover.renderHitpointBars();
|
||||
g_Selection.renderHitpointBars();
|
||||
g_Mouseover.renderHealthBars();
|
||||
g_Selection.renderHealthBars();
|
||||
glPopMatrix();
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glPopMatrix();
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
PROFILE_END( "render hitpoint bars" );
|
||||
PROFILE_END( "render health bars" );
|
||||
|
||||
glPopAttrib();
|
||||
}
|
||||
|
@ -74,11 +74,11 @@ void CSelectedEntities::renderSelectionOutlines()
|
||||
}
|
||||
}
|
||||
|
||||
void CSelectedEntities::renderHitpointBars()
|
||||
void CSelectedEntities::renderHealthBars()
|
||||
{
|
||||
std::vector<HEntity>::iterator it;
|
||||
for( it = m_selected.begin(); it < m_selected.end(); it++ )
|
||||
(*it)->renderHitpointBar();
|
||||
(*it)->renderHealthBar();
|
||||
|
||||
if( m_group_highlight != -1 )
|
||||
{
|
||||
@ -87,7 +87,7 @@ void CSelectedEntities::renderHitpointBars()
|
||||
|
||||
std::vector<HEntity>::iterator it;
|
||||
for( it = m_groups[m_group_highlight].begin(); it < m_groups[m_group_highlight].end(); it++ )
|
||||
(*it)->renderHitpointBar( 0.5f );
|
||||
(*it)->renderHealthBar();
|
||||
|
||||
glDisable( GL_BLEND );
|
||||
}
|
||||
@ -691,14 +691,14 @@ void CMouseoverEntities::renderSelectionOutlines()
|
||||
glDisable( GL_BLEND );
|
||||
}
|
||||
|
||||
void CMouseoverEntities::renderHitpointBars()
|
||||
void CMouseoverEntities::renderHealthBars()
|
||||
{
|
||||
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
|
||||
glEnable( GL_BLEND );
|
||||
|
||||
std::vector<SMouseoverFader>::iterator it;
|
||||
for( it = m_mouseover.begin(); it < m_mouseover.end(); it++ )
|
||||
it->entity->renderHitpointBar( it->fade );
|
||||
it->entity->renderHealthBar();
|
||||
|
||||
glDisable( GL_BLEND );
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ struct CSelectedEntities : public Singleton<CSelectedEntities>
|
||||
|
||||
void renderSelectionOutlines();
|
||||
void renderOverlays();
|
||||
void renderHitpointBars();
|
||||
void renderHealthBars();
|
||||
};
|
||||
|
||||
// CMouseoverEntities: the singleton containing entities the mouse is currently hovering over or bandboxing
|
||||
@ -110,7 +110,7 @@ struct CMouseoverEntities : public Singleton<CMouseoverEntities>
|
||||
|
||||
void renderSelectionOutlines();
|
||||
void renderOverlays();
|
||||
void renderHitpointBars();
|
||||
void renderHealthBars();
|
||||
|
||||
bool isBandbox() { return( m_bandbox ); }
|
||||
void startBandbox( u16 x, u16 y );
|
||||
|
@ -26,6 +26,9 @@ CBaseEntity::CBaseEntity()
|
||||
AddProperty( L"actor", &m_actorName );
|
||||
AddProperty( L"traits.extant", &m_extant );
|
||||
AddProperty( L"traits.corpse", &m_corpse );
|
||||
AddProperty( L"traits.health.curr", &m_healthCurr );
|
||||
AddProperty( L"traits.health.max", &m_healthMax );
|
||||
AddProperty( L"traits.health.bar_height", &m_healthBarHeight );
|
||||
|
||||
for( int t = 0; t < EVENT_LAST; t++ )
|
||||
{
|
||||
|
@ -69,6 +69,10 @@ public:
|
||||
void setClassSet( jsval value );
|
||||
void rebuildClassSet();
|
||||
|
||||
float m_healthCurr;
|
||||
float m_healthMax;
|
||||
float m_healthBarHeight;
|
||||
|
||||
// Script-bound functions
|
||||
|
||||
// Get script execution contexts - always run in the context of the entity that fired it.
|
||||
|
@ -37,8 +37,6 @@ CEntity::CEntity( CBaseEntity* base, CVector3D position, float orientation )
|
||||
AddProperty( L"group", &m_grouped, false, (NotifyFn)&CEntity::checkGroup );
|
||||
AddProperty( L"traits.extant", &m_extant );
|
||||
AddProperty( L"traits.corpse", &m_corpse );
|
||||
AddProperty( L"traits.health.curr", &m_healthCurr );
|
||||
AddProperty( L"traits.health.max", &m_healthMax );
|
||||
AddProperty( L"actions.move.turningradius", &m_turningRadius );
|
||||
AddProperty( L"actions.attack.range", &( m_melee.m_MaxRange ) );
|
||||
AddProperty( L"actions.attack.rangemin", &( m_melee.m_MinRange ) );
|
||||
@ -49,6 +47,9 @@ CEntity::CEntity( CBaseEntity* base, CVector3D position, float orientation )
|
||||
AddProperty( L"position", &m_graphics_position, false, (NotifyFn)&CEntity::teleport );
|
||||
AddProperty( L"orientation", &m_graphics_orientation, false, (NotifyFn)&CEntity::reorient );
|
||||
AddProperty( L"player", &m_player );
|
||||
AddProperty( L"traits.health.curr", &m_healthCurr );
|
||||
AddProperty( L"traits.health.max", &m_healthMax );
|
||||
AddProperty( L"traits.health.bar_height", &m_healthBarHeight );
|
||||
|
||||
for( int t = 0; t < EVENT_LAST; t++ )
|
||||
{
|
||||
@ -752,19 +753,19 @@ void CEntity::renderSelectionOutline( float alpha )
|
||||
glEnd();
|
||||
}
|
||||
|
||||
void CEntity::renderHitpointBar( float alpha )
|
||||
void CEntity::renderHealthBar()
|
||||
{
|
||||
if( !m_bounds ) return;
|
||||
if( m_healthBarHeight < 0 ) return; // negative bar height means don't display health bar
|
||||
|
||||
CCamera &g_Camera=*g_Game->GetView()->GetCamera();
|
||||
|
||||
float sx, sy;
|
||||
float height = 5; // TODO: change this to m_bounds->m_height when that is working properly for most units
|
||||
CVector3D pos = m_graphics_position;
|
||||
CVector3D above = pos;
|
||||
above.Y += height;
|
||||
above.Y += m_healthBarHeight;
|
||||
g_Camera.GetScreenCoordinates(above, sx, sy);
|
||||
float fraction = this->m_healthCurr / this->m_healthMax;
|
||||
float fraction = clamp(m_healthCurr / m_healthMax, 0.0f, 1.0f);
|
||||
|
||||
const float SIZE = 20;
|
||||
float x1 = sx - SIZE/2;
|
||||
|
@ -81,6 +81,7 @@ public:
|
||||
// HP properties
|
||||
float m_healthCurr;
|
||||
float m_healthMax;
|
||||
float m_healthBarHeight;
|
||||
|
||||
//-- Interpolated property
|
||||
CVector3D m_position;
|
||||
@ -178,7 +179,7 @@ public:
|
||||
// Things like selection circles and debug info - possibly move to gui if/when it becomes responsible for (and capable of) it.
|
||||
void render();
|
||||
void renderSelectionOutline( float alpha = 1.0f );
|
||||
void renderHitpointBar( float alpha = 1.0f );
|
||||
void renderHealthBar();
|
||||
|
||||
// After a collision, recalc the path to the next fixed waypoint.
|
||||
void repath();
|
||||
|
Loading…
Reference in New Issue
Block a user