summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Angus <tim@ngus.net>2002-08-08 21:40:19 +0000
committerTim Angus <tim@ngus.net>2002-08-08 21:40:19 +0000
commitb209c6138bfa97f8d427611f19a5e128d1a134e0 (patch)
tree86941a427e060b2b9b12b5386418f044c9ea223f
parentf58a14bc26cd5356f7ddd97f6481ddf8fc079223 (diff)
* Display of buildable health and power status
-rw-r--r--src/cgame/cg_buildable.c96
-rw-r--r--src/cgame/cg_draw.c6
-rw-r--r--src/cgame/cg_drawtools.c51
-rw-r--r--src/cgame/cg_local.h2
-rw-r--r--src/cgame/cg_main.c1
-rw-r--r--src/game/bg_public.h4
-rw-r--r--src/game/g_buildable.c12
7 files changed, 170 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 = &cent->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" );
diff --git a/src/game/bg_public.h b/src/game/bg_public.h
index c4517a57..95ec9feb 100644
--- a/src/game/bg_public.h
+++ b/src/game/bg_public.h
@@ -444,6 +444,10 @@ typedef enum
BIT_NUM_TEAMS
} buildableTeam_t;
+#define B_POWERED_TOGGLEBIT 0x00000040
+#define B_DCCED_TOGGLEBIT 0x00000080
+
+
// reward sounds (stored in ps->persistant[PERS_PLAYEREVENTS])
#define PLAYEREVENT_DENIEDREWARD 0x0001
#define PLAYEREVENT_GAUNTLETREWARD 0x0002
diff --git a/src/game/g_buildable.c b/src/game/g_buildable.c
index a6cf9492..b636c650 100644
--- a/src/game/g_buildable.c
+++ b/src/game/g_buildable.c
@@ -2175,6 +2175,18 @@ gentity_t *G_buildItem( gentity_t *builder, buildable_t buildable, vec3_t origin
else
VectorSet( normal, 0.0f, 0.0f, 1.0f );
+ built->s.generic1 = (int)( ( (float)built->health /
+ (float)BG_FindHealthForBuildable( buildable ) ) * 63.0f );
+
+ if( built->s.generic1 < 0 )
+ built->s.generic1 = 0;
+
+ if( built->powered )
+ built->s.generic1 |= B_POWERED_TOGGLEBIT;
+
+ if( built->dcced )
+ built->s.generic1 |= B_DCCED_TOGGLEBIT;
+
VectorCopy( normal, built->s.origin2 );
G_AddEvent( built, EV_BUILD_CONSTRUCT, BANIM_CONSTRUCT1 );