diff options
author | Tim Angus <tim@ngus.net> | 2002-08-08 21:40:19 +0000 |
---|---|---|
committer | Tim Angus <tim@ngus.net> | 2002-08-08 21:40:19 +0000 |
commit | b209c6138bfa97f8d427611f19a5e128d1a134e0 (patch) | |
tree | 86941a427e060b2b9b12b5386418f044c9ea223f /src/cgame | |
parent | f58a14bc26cd5356f7ddd97f6481ddf8fc079223 (diff) |
* Display of buildable health and power status
Diffstat (limited to 'src/cgame')
-rw-r--r-- | src/cgame/cg_buildable.c | 96 | ||||
-rw-r--r-- | src/cgame/cg_draw.c | 6 | ||||
-rw-r--r-- | src/cgame/cg_drawtools.c | 51 | ||||
-rw-r--r-- | src/cgame/cg_local.h | 2 | ||||
-rw-r--r-- | src/cgame/cg_main.c | 1 |
5 files changed, 154 insertions, 2 deletions
diff --git a/src/cgame/cg_buildable.c b/src/cgame/cg_buildable.c index bd337dcc..4c5e13ec 100644 --- a/src/cgame/cg_buildable.c +++ b/src/cgame/cg_buildable.c @@ -519,6 +519,87 @@ void CG_GhostBuildable( buildable_t buildable ) trap_R_AddRefEntityToScene( &ent ); } +#define HEALTH_BAR_WIDTH 50.0f +#define HEALTH_BAR_HEIGHT 15.0f + +/* +================== +CG_BuildableHealthBar +================== +*/ +void CG_BuildableHealthBar( centity_t *cent ) +{ + vec3_t origin, origin2, down, right, back, downLength, rightLength; + float rimWidth = HEALTH_BAR_HEIGHT / 15.0f; + float doneWidth, leftWidth, progress; + int health; + qhandle_t shader; + entityState_t *es; + vec3_t mins, maxs; + + es = ¢->currentState; + + health = es->generic1 & ~( B_POWERED_TOGGLEBIT | B_DCCED_TOGGLEBIT ); + progress = (float)health / 63.0f; + + if( progress < 0.0f ) + progress = 0.0f; + else if( progress > 1.0f ) + progress = 1.0f; + + if( progress < 0.33f ) + shader = cgs.media.redBuildShader; + else + shader = cgs.media.greenBuildShader; + + doneWidth = ( HEALTH_BAR_WIDTH - 2 * rimWidth ) * progress; + leftWidth = ( HEALTH_BAR_WIDTH - 2 * rimWidth ) - doneWidth; + + VectorCopy( cg.refdef.viewaxis[ 2 ], down ); + VectorInverse( down ); + VectorCopy( cg.refdef.viewaxis[ 1 ], right ); + VectorInverse( right ); + VectorSubtract( cg.refdef.vieworg, cent->lerpOrigin, back ); + VectorNormalize( back ); + VectorCopy( cent->lerpOrigin, origin ); + + BG_FindBBoxForBuildable( es->modelindex, mins, maxs ); + VectorMA( origin, 48.0f, es->origin2, origin ); + VectorMA( origin, -HEALTH_BAR_WIDTH / 2.0f, right, origin ); + VectorMA( origin, maxs[ 0 ] + 8.0f, back, origin ); + + VectorCopy( origin, origin2 ); + VectorScale( right, rimWidth + doneWidth, rightLength ); + VectorScale( down, HEALTH_BAR_HEIGHT, downLength ); + CG_DrawPlane( origin2, downLength, rightLength, shader ); + + VectorMA( origin, rimWidth + doneWidth, right, origin2 ); + VectorScale( right, leftWidth, rightLength ); + VectorScale( down, rimWidth, downLength ); + CG_DrawPlane( origin2, downLength, rightLength, shader ); + + VectorMA( origin, rimWidth + doneWidth, right, origin2 ); + VectorMA( origin2, HEALTH_BAR_HEIGHT - rimWidth, down, origin2 ); + VectorScale( right, leftWidth, rightLength ); + VectorScale( down, rimWidth, downLength ); + CG_DrawPlane( origin2, downLength, rightLength, shader ); + + VectorMA( origin, HEALTH_BAR_WIDTH - rimWidth, right, origin2 ); + VectorScale( right, rimWidth, rightLength ); + VectorScale( down, HEALTH_BAR_HEIGHT, downLength ); + CG_DrawPlane( origin2, downLength, rightLength, shader ); + + if( !( es->generic1 & B_POWERED_TOGGLEBIT ) && + BG_FindTeamForBuildable( es->modelindex ) == WUT_HUMANS ) + { + VectorMA( origin, 15.0f, right, origin2 ); + VectorMA( origin2, HEALTH_BAR_HEIGHT + 5.0f, down, origin2 ); + VectorScale( right, HEALTH_BAR_WIDTH / 2.0f - 5.0f, rightLength ); + VectorScale( down, HEALTH_BAR_WIDTH / 2.0f - 5.0f, downLength ); + CG_DrawPlane( origin2, downLength, rightLength, cgs.media.noPowerShader ); + } +} + /* ================== CG_Buildable @@ -648,4 +729,19 @@ void CG_Buildable( centity_t *cent ) trap_R_AddRefEntityToScene( &turretTop ); } + + switch( cg.predictedPlayerState.weapon ) + { + case WP_ABUILD: + case WP_ABUILD2: + case WP_HBUILD: + case WP_HBUILD2: + if( BG_FindTeamForBuildable( es->modelindex ) == + BG_FindTeamForWeapon( cg.predictedPlayerState.weapon ) ) + CG_BuildableHealthBar( cent ); + break; + + default: + break; + } } diff --git a/src/cgame/cg_draw.c b/src/cgame/cg_draw.c index 1aca9df4..25a62b85 100644 --- a/src/cgame/cg_draw.c +++ b/src/cgame/cg_draw.c @@ -535,8 +535,7 @@ static void CG_DrawProgressBar( rectDef_t *rect, vec4_t color, float scale, int align, int textStyle, float progress ) { int rimWidth = (int)( rect->h / 20.0f ); - float doneWidth = ( rect->w - 2 * rimWidth ) * progress; - float leftWidth = ( rect->w - 2 * rimWidth ) - doneWidth; + float doneWidth, leftWidth; float tx, ty, tw, th; char textBuffer[ 8 ]; @@ -545,6 +544,9 @@ static void CG_DrawProgressBar( rectDef_t *rect, vec4_t color, else if( progress > 1.0f ) progress = 1.0f; + doneWidth = ( rect->w - 2 * rimWidth ) * progress; + leftWidth = ( rect->w - 2 * rimWidth ) - doneWidth; + trap_R_SetColor( color ); //draw rim and bar diff --git a/src/cgame/cg_drawtools.c b/src/cgame/cg_drawtools.c index d5a144e6..391b287d 100644 --- a/src/cgame/cg_drawtools.c +++ b/src/cgame/cg_drawtools.c @@ -18,6 +18,57 @@ #include "cg_local.h" /* +=============== +CG_DrawPlane + +Draw a quad in 3 space - basically CG_DrawPic in 3 space +=============== +*/ +void CG_DrawPlane( vec3_t origin, vec3_t down, vec3_t right, qhandle_t shader ) +{ + polyVert_t verts[ 4 ]; + vec3_t temp; + + VectorCopy( origin, verts[ 0 ].xyz ); + verts[ 0 ].st[ 0 ] = 0; + verts[ 0 ].st[ 1 ] = 0; + verts[ 0 ].modulate[ 0 ] = 255; + verts[ 0 ].modulate[ 1 ] = 255; + verts[ 0 ].modulate[ 2 ] = 255; + verts[ 0 ].modulate[ 3 ] = 255; + + VectorAdd( origin, right, temp ); + VectorCopy( temp, verts[ 1 ].xyz ); + verts[ 1 ].st[ 0 ] = 1; + verts[ 1 ].st[ 1 ] = 0; + verts[ 1 ].modulate[ 0 ] = 255; + verts[ 1 ].modulate[ 1 ] = 255; + verts[ 1 ].modulate[ 2 ] = 255; + verts[ 1 ].modulate[ 3 ] = 255; + + VectorAdd( origin, right, temp ); + VectorAdd( temp, down, temp ); + VectorCopy( temp, verts[ 2 ].xyz ); + verts[ 2 ].st[ 0 ] = 1; + verts[ 2 ].st[ 1 ] = 1; + verts[ 2 ].modulate[ 0 ] = 255; + verts[ 2 ].modulate[ 1 ] = 255; + verts[ 2 ].modulate[ 2 ] = 255; + verts[ 2 ].modulate[ 3 ] = 255; + + VectorAdd( origin, down, temp ); + VectorCopy( temp, verts[ 3 ].xyz ); + verts[ 3 ].st[ 0 ] = 0; + verts[ 3 ].st[ 1 ] = 1; + verts[ 3 ].modulate[ 0 ] = 255; + verts[ 3 ].modulate[ 1 ] = 255; + verts[ 3 ].modulate[ 2 ] = 255; + verts[ 3 ].modulate[ 3 ] = 255; + + trap_R_AddPolyToScene( shader, 4, verts ); +} + +/* ================ CG_AdjustFrom640 diff --git a/src/cgame/cg_local.h b/src/cgame/cg_local.h index 371ea341..30e07080 100644 --- a/src/cgame/cg_local.h +++ b/src/cgame/cg_local.h @@ -884,6 +884,7 @@ typedef struct { //TA: buildable shaders qhandle_t greenBuildShader; qhandle_t redBuildShader; + qhandle_t noPowerShader; // weapon effect models qhandle_t bulletFlashModel; @@ -1311,6 +1312,7 @@ void CG_DrawActiveFrame( int serverTime, stereoFrame_t stereoView, qboolean demo // // cg_drawtools.c // +void CG_DrawPlane( vec3_t origin, vec3_t down, vec3_t right, qhandle_t shader ); void CG_AdjustFrom640( float *x, float *y, float *w, float *h ); void CG_FillRect( float x, float y, float width, float height, const float *color ); void CG_DrawPic( float x, float y, float width, float height, qhandle_t hShader ); diff --git a/src/cgame/cg_main.c b/src/cgame/cg_main.c index 8f0d1b04..b2a12e80 100644 --- a/src/cgame/cg_main.c +++ b/src/cgame/cg_main.c @@ -743,6 +743,7 @@ static void CG_RegisterGraphics( void ) { //TA: building shaders cgs.media.greenBuildShader = trap_R_RegisterShader("gfx/2d/greenbuild" ); cgs.media.redBuildShader = trap_R_RegisterShader("gfx/2d/redbuild" ); + cgs.media.noPowerShader = trap_R_RegisterShader("gfx/2d/nopower" ); // powerup shaders cgs.media.quadShader = trap_R_RegisterShader("powerups/quad" ); |