summaryrefslogtreecommitdiff
path: root/src/cgame
diff options
context:
space:
mode:
Diffstat (limited to 'src/cgame')
-rw-r--r--src/cgame/cg_draw.c260
-rw-r--r--src/cgame/cg_local.h8
-rw-r--r--src/cgame/cg_main.c31
-rw-r--r--src/cgame/cg_servercmds.c18
4 files changed, 316 insertions, 1 deletions
diff --git a/src/cgame/cg_draw.c b/src/cgame/cg_draw.c
index e3af715..2c6645f 100644
--- a/src/cgame/cg_draw.c
+++ b/src/cgame/cg_draw.c
@@ -3834,6 +3834,263 @@ static void CG_DrawWarmup( void )
UI_Text_Paint( 320 - w / 2, 200 + 1.5f * h, size, colorWhite, text, 0, 0, ITEM_TEXTSTYLE_SHADOWED );
}
+/*
+=================
+Damage blobs
+=================
+*/
+
+typedef struct
+{
+ qboolean inuse;
+ int spawnTime;
+ int value;
+ int flags;
+ vec3_t origin;
+ vec3_t velocity;
+} cg_damageBlob_t;
+
+#define MAX_DAMAGE_BLOBS 50
+cg_damageBlob_t cg_damageBlobs[ MAX_DAMAGE_BLOBS ];
+
+void CG_SpawnDamageBlob( vec3_t origin, int value, int flags )
+{
+ centity_t *cent;
+ cg_damageBlob_t *blob, *oldest = NULL;
+
+ for( blob = cg_damageBlobs; blob < cg_damageBlobs + MAX_DAMAGE_BLOBS; blob++ )
+ {
+ if( !oldest || blob->spawnTime < oldest->spawnTime )
+ oldest = blob;
+
+ if( blob->inuse )
+ continue;
+
+ goto found_blob;
+ }
+
+ oldest = blob;
+
+found_blob:
+
+ blob->inuse = qtrue;
+ blob->spawnTime = cg.time;
+ blob->value = value;
+ blob->flags = flags;
+ VectorCopy( origin, blob->origin );
+ VectorSet( blob->velocity, crandom( ) * 20, crandom( ) * 20, 100 );
+}
+
+static void CG_DrawNumber( float x, float y, float h, char *str )
+{
+ int index, len;
+ float w;
+ char *p;
+
+ len = strlen( str );
+ w = h * cgDC.aspectScale * 0.5f;
+
+ y -= h / 2;
+ x -= len * w / 2;
+
+ for( p = str; *p; p++ )
+ {
+ if( *p >= '0' && *p <= '9' )
+ index = *p - '0';
+ else
+ index = 10;
+
+ CG_DrawPic( x, y, w, h, cgs.media.numberShadersAlt[ index ] );
+ x += w;
+ }
+}
+
+#define DAMAGE_BLOB_TIME 700
+
+static void CG_DrawDamageBlobs( void )
+{
+ cg_damageBlob_t *blob;
+ float dt, x, y, fade, scale;
+ vec4_t color;
+ char str[ 32 ];
+
+ dt = 0.001 * cg.frametime;
+
+ for( blob = cg_damageBlobs; blob < cg_damageBlobs + MAX_DAMAGE_BLOBS; blob++ )
+ {
+ if( !blob->inuse )
+ continue;
+
+ if( blob->spawnTime + DAMAGE_BLOB_TIME < cg.time )
+ {
+ blob->inuse = qfalse;
+ continue;
+ }
+
+ if( !CG_WorldToScreen( blob->origin, &x, &y ) )
+ continue;
+
+ fade = 1.0f - (float)( cg.time - blob->spawnTime ) / DAMAGE_BLOB_TIME;
+
+ scale = cg_damageBlobSize.value /
+ pow( Distance( blob->origin, cg.refdef.vieworg ), 0.5f );
+
+ Com_sprintf( str, sizeof( str ), "%d", blob->value );
+
+ if( blob->flags & DAMAGE_BLOB_FRIENDLY )
+ VectorSet( color, 1, 0, 0 );
+ else
+ {
+ if( blob->flags & DAMAGE_BLOB_BUILDABLE )
+ {
+ if( blob->flags & DAMAGE_BLOB_SPLASH )
+ VectorSet( color, 1, 0.5, 0 );
+ else
+ VectorSet( color, 0.7, 0.7, 0.7 );
+ }
+ else
+ {
+ if( blob->flags & DAMAGE_BLOB_SPLASH )
+ VectorSet( color, 1, 1, 0 );
+ else
+ VectorSet( color, 1, 1, 1 );
+ }
+ }
+
+ color[ 3 ] = cg_damageBlobAlpha.value * fade;
+ trap_R_SetColor( color );
+ CG_DrawNumber( x, y, scale, str );
+
+ VectorMA( blob->origin, dt, blob->velocity, blob->origin );
+ blob->velocity[ 2 ] -= 300 * dt;
+ }
+
+ trap_R_SetColor( NULL );
+}
+
+/*
+=================
+Health bars
+=================
+*/
+typedef struct
+{
+ vec3_t origin;
+ float dist;
+
+ int value;
+ int max;
+} healthBar_t;
+
+static int CompareHealthBars( const healthBar_t *a, const healthBar_t *b )
+{
+ return a->dist < b->dist;
+}
+
+static void CG_DrawHealthBars( void )
+{
+ int i;
+ healthBar_t *bar, *bare, bars[ MAX_ENTITIES_IN_SNAPSHOT ];
+
+ for( bar = bars, i = 0; i < cg.snap->numEntities; i++ )
+ {
+ int j;
+ centity_t *cent;
+ entityState_t *es;
+ trace_t tr;
+ vec3_t mins, maxs;
+
+ cent = cg_entities + cg.snap->entities[ i ].number;
+ es = &cent->currentState;
+
+ if( es->eFlags & ( EF_DEAD | EF_NODRAW ) )
+ continue;
+
+ switch( es->eType )
+ {
+ case ET_BUILDABLE:
+ if( CG_PlayerIsBuilder( es->modelindex ) )
+ continue;
+
+ bar->value = es->generic1;
+ bar->max = BG_Buildable( es->modelindex )->health;
+ BG_BuildableBoundingBox( es->modelindex, mins, maxs );
+ break;
+
+ case ET_PLAYER:
+ if( es->eFlags & EF_MOVER_STOP ) // cloak
+ continue;
+
+ bar->value = es->otherEntityNum2;
+ bar->max = BG_Class( ( es->misc >> 8 ) & 0xFF )->health;
+ BG_ClassBoundingBox( ( es->misc >> 8 ) & 0xFF, mins, maxs, NULL, NULL, NULL );
+ break;
+
+ default:
+ continue;
+ }
+
+ for( j = 0; j < 3; j++ )
+ bar->origin[ j ] = cent->lerpOrigin[ j ] + ( maxs[ j ] + mins[ j ] ) / 2.0f;
+
+ CG_Trace( &tr, cg.refdef.vieworg, NULL, NULL, bar->origin, ENTITYNUM_NONE, MASK_SOLID );
+
+ if( tr.fraction < 1.0f )
+ continue;
+
+ bar->dist = Distance( bar->origin, cg.refdef.vieworg );
+
+ bar++;
+ }
+
+ bare = bar;
+ qsort( bars, bare - bars, sizeof( healthBar_t ),
+ (int(*)(const void*,const void*))CompareHealthBars );
+
+/*
+ TODO: figure out why qsort fails for more than 5 bars
+
+ for( i = 0; i < bare - bars - 1; i++ )
+ if( CompareHealthBars( bars + i, bars + i + 1 ) )
+ {
+ Com_Printf( "qsort is retarded\n" );
+ break;
+ }
+*/
+
+ for( bar = bars; bar < bare; bar++ )
+ {
+ float x, y, w, h, hf;
+ char buffer[ 64 ];
+ vec4_t color;
+
+ if( !CG_WorldToScreen( bar->origin, &x, &y ) )
+ continue;
+
+ hf = (float)bar->value / bar->max;
+
+ h = cg_healthBarSize.value / bar->dist;
+ w = 4 * h * cgDC.aspectScale;
+
+ Com_sprintf( buffer, sizeof( buffer ), "%d", bar->value );
+
+ color[ 3 ] = cg_healthBarAlpha.value;
+
+ VectorSet( color, 0.1, 0.7, 0.1 );
+ trap_R_SetColor( color );
+ CG_DrawPic( x - w/2, y - h/2, w * hf, h, cgs.media.whiteShader );
+
+ VectorSet( color, 0.7, 0.1, 0.1 );
+ trap_R_SetColor( color );
+ CG_DrawPic( x - w/2 + w * hf, y - h/2, w * ( 1 - hf ), h, cgs.media.whiteShader );
+
+ VectorSet( color, 0, 0, 0 );
+ trap_R_SetColor( color );
+ CG_DrawNumber( x, y, h, buffer );
+ }
+}
+
+
//==================================================================================
/*
@@ -3884,6 +4141,9 @@ static void CG_Draw2D( void )
CG_DrawBuildableStatus( );
}
+ CG_DrawDamageBlobs( );
+ CG_DrawHealthBars( );
+
if( !menu )
{
menu = Menus_FindByName( "default_hud" );
diff --git a/src/cgame/cg_local.h b/src/cgame/cg_local.h
index 5816a9b..83cac63 100644
--- a/src/cgame/cg_local.h
+++ b/src/cgame/cg_local.h
@@ -1198,6 +1198,7 @@ typedef struct
qhandle_t teamOverlayShader;
qhandle_t numberShaders[ 11 ];
+ qhandle_t numberShadersAlt[ 11 ];
qhandle_t shadowMarkShader;
qhandle_t wakeMarkShader;
@@ -1606,6 +1607,12 @@ extern vmCvar_t cg_viewQuake;
extern vmCvar_t cg_viewQuakeLambda;
extern vmCvar_t cg_viewQuakeLimit;
+extern vmCvar_t cg_damageBlobSize;
+extern vmCvar_t cg_damageBlobAlpha;
+
+extern vmCvar_t cg_healthBarSize;
+extern vmCvar_t cg_healthBarAlpha;
+
//
// cg_main.c
//
@@ -1703,6 +1710,7 @@ void CG_UpdateMediaFraction( float newFract );
void CG_ResetPainBlend( void );
void CG_DrawField( float x, float y, int width, float cw, float ch, int value );
+void CG_SpawnDamageBlob( vec3_t origin, int value, int flags );
//
// cg_players.c
//
diff --git a/src/cgame/cg_main.c b/src/cgame/cg_main.c
index 7ed3bfc..0fdb028 100644
--- a/src/cgame/cg_main.c
+++ b/src/cgame/cg_main.c
@@ -232,6 +232,12 @@ vmCvar_t cg_viewQuake;
vmCvar_t cg_viewQuakeLambda;
vmCvar_t cg_viewQuakeLimit;
+vmCvar_t cg_damageBlobSize;
+vmCvar_t cg_damageBlobAlpha;
+
+vmCvar_t cg_healthBarSize;
+vmCvar_t cg_healthBarAlpha;
+
typedef struct
{
vmCvar_t *vmCvar;
@@ -379,7 +385,13 @@ static cvarTable_t cvarTable[ ] =
{ &cg_viewQuake, "cg_viewQuake", "1", CVAR_ARCHIVE },
{ &cg_viewQuakeLambda, "cg_viewQuakeLambda", "-10", CVAR_ARCHIVE },
- { &cg_viewQuakeLimit, "cg_viewQuakeLimit", "5", CVAR_ARCHIVE }
+ { &cg_viewQuakeLimit, "cg_viewQuakeLimit", "5", CVAR_ARCHIVE },
+
+ { &cg_damageBlobSize, "cg_damageBlobSize", "400", CVAR_ARCHIVE },
+ { &cg_damageBlobAlpha, "cg_damageBlobAlpha", "0.8", CVAR_ARCHIVE },
+
+ { &cg_healthBarSize, "cg_healthBarSize", "2000", CVAR_ARCHIVE },
+ { &cg_healthBarAlpha, "cg_healthBarAlpha", "0.5", CVAR_ARCHIVE }
};
static int cvarTableSize = sizeof( cvarTable ) / sizeof( cvarTable[0] );
@@ -769,6 +781,20 @@ static void CG_RegisterGraphics( void )
"gfx/2d/numbers/nine_32b",
"gfx/2d/numbers/minus_32b",
};
+ static char *sb_nums_alt[ 11 ] =
+ {
+ "gfx/2d/numbers_alt/0",
+ "gfx/2d/numbers_alt/1",
+ "gfx/2d/numbers_alt/2",
+ "gfx/2d/numbers_alt/3",
+ "gfx/2d/numbers_alt/4",
+ "gfx/2d/numbers_alt/5",
+ "gfx/2d/numbers_alt/6",
+ "gfx/2d/numbers_alt/7",
+ "gfx/2d/numbers_alt/8",
+ "gfx/2d/numbers_alt/9",
+ "gfx/2d/numbers_alt/minus",
+ };
static char *buildWeaponTimerPieShaders[ 8 ] =
{
"ui/assets/neutral/1_5pie",
@@ -791,6 +817,9 @@ static void CG_RegisterGraphics( void )
for( i = 0; i < 11; i++ )
cgs.media.numberShaders[ i ] = trap_R_RegisterShader( sb_nums[ i ] );
+ for( i = 0; i < 11; i++ )
+ cgs.media.numberShadersAlt[ i ] = trap_R_RegisterShader( sb_nums_alt[ i ] );
+
cgs.media.viewBloodShader = trap_R_RegisterShader( "gfx/damage/fullscreen_painblend" );
cgs.media.connectionShader = trap_R_RegisterShader( "gfx/2d/net" );
diff --git a/src/cgame/cg_servercmds.c b/src/cgame/cg_servercmds.c
index 084e3f1..d8a9323 100644
--- a/src/cgame/cg_servercmds.c
+++ b/src/cgame/cg_servercmds.c
@@ -1336,6 +1336,23 @@ static void CG_GameCmds_f( void )
trap_AddCommand( CG_Argv( i ) );
}
+static void CG_DamageBlob_f( void )
+{
+ int i, count = trap_Argc( ), value, flags;
+ vec3_t origin;
+
+ for( i = 1; i + 4 < count; i += 5 )
+ {
+ origin[ 0 ] = atof( CG_Argv( i ) );
+ origin[ 1 ] = atof( CG_Argv( i + 1 ) );
+ origin[ 2 ] = atof( CG_Argv( i + 2 ) );
+ value = atoi( CG_Argv( i + 3 ) );
+ flags = atoi( CG_Argv( i + 4 ) );
+
+ CG_SpawnDamageBlob( origin, value, flags );
+ }
+}
+
static consoleCommand_t svcommands[ ] =
{
{ "chat", CG_Chat_f },
@@ -1343,6 +1360,7 @@ static consoleCommand_t svcommands[ ] =
{ "cmds", CG_GameCmds_f },
{ "cp", CG_CenterPrint_f },
{ "cs", CG_ConfigStringModified },
+ { "dblob", CG_DamageBlob_f },
{ "map_restart", CG_MapRestart },
{ "poisoncloud", CG_PoisonCloud_f },
{ "print", CG_Print_f },