From 5678a7bb3498f20123523f008df947a39eb44ccc Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Fri, 3 Apr 2015 00:33:39 +0200 Subject: Implement damage blobs. --- assets/gfx/2d/numbers_alt/0.tga | Bin 0 -> 1038 bytes assets/gfx/2d/numbers_alt/1.tga | Bin 0 -> 772 bytes assets/gfx/2d/numbers_alt/2.tga | Bin 0 -> 854 bytes assets/gfx/2d/numbers_alt/3.tga | Bin 0 -> 786 bytes assets/gfx/2d/numbers_alt/4.tga | Bin 0 -> 860 bytes assets/gfx/2d/numbers_alt/5.tga | Bin 0 -> 834 bytes assets/gfx/2d/numbers_alt/6.tga | Bin 0 -> 904 bytes assets/gfx/2d/numbers_alt/7.tga | Bin 0 -> 710 bytes assets/gfx/2d/numbers_alt/8.tga | Bin 0 -> 1102 bytes assets/gfx/2d/numbers_alt/9.tga | Bin 0 -> 904 bytes assets/gfx/2d/numbers_alt/minus.tga | Bin 0 -> 282 bytes src/cgame/cg_draw.c | 139 ++++++++++++++++++++++++++++++++++++ src/cgame/cg_local.h | 5 ++ src/cgame/cg_main.c | 25 ++++++- src/cgame/cg_servercmds.c | 20 ++++++ src/game/bg_public.h | 4 ++ src/game/g_active.c | 39 ++++++++++ src/game/g_combat.c | 37 ++++++++++ src/game/g_local.h | 11 +++ 19 files changed, 279 insertions(+), 1 deletion(-) create mode 100644 assets/gfx/2d/numbers_alt/0.tga create mode 100644 assets/gfx/2d/numbers_alt/1.tga create mode 100644 assets/gfx/2d/numbers_alt/2.tga create mode 100644 assets/gfx/2d/numbers_alt/3.tga create mode 100644 assets/gfx/2d/numbers_alt/4.tga create mode 100644 assets/gfx/2d/numbers_alt/5.tga create mode 100644 assets/gfx/2d/numbers_alt/6.tga create mode 100644 assets/gfx/2d/numbers_alt/7.tga create mode 100644 assets/gfx/2d/numbers_alt/8.tga create mode 100644 assets/gfx/2d/numbers_alt/9.tga create mode 100644 assets/gfx/2d/numbers_alt/minus.tga diff --git a/assets/gfx/2d/numbers_alt/0.tga b/assets/gfx/2d/numbers_alt/0.tga new file mode 100644 index 0000000..ed72ed5 Binary files /dev/null and b/assets/gfx/2d/numbers_alt/0.tga differ diff --git a/assets/gfx/2d/numbers_alt/1.tga b/assets/gfx/2d/numbers_alt/1.tga new file mode 100644 index 0000000..8267352 Binary files /dev/null and b/assets/gfx/2d/numbers_alt/1.tga differ diff --git a/assets/gfx/2d/numbers_alt/2.tga b/assets/gfx/2d/numbers_alt/2.tga new file mode 100644 index 0000000..92414db Binary files /dev/null and b/assets/gfx/2d/numbers_alt/2.tga differ diff --git a/assets/gfx/2d/numbers_alt/3.tga b/assets/gfx/2d/numbers_alt/3.tga new file mode 100644 index 0000000..862606a Binary files /dev/null and b/assets/gfx/2d/numbers_alt/3.tga differ diff --git a/assets/gfx/2d/numbers_alt/4.tga b/assets/gfx/2d/numbers_alt/4.tga new file mode 100644 index 0000000..bd7e6cc Binary files /dev/null and b/assets/gfx/2d/numbers_alt/4.tga differ diff --git a/assets/gfx/2d/numbers_alt/5.tga b/assets/gfx/2d/numbers_alt/5.tga new file mode 100644 index 0000000..0de619f Binary files /dev/null and b/assets/gfx/2d/numbers_alt/5.tga differ diff --git a/assets/gfx/2d/numbers_alt/6.tga b/assets/gfx/2d/numbers_alt/6.tga new file mode 100644 index 0000000..770ee54 Binary files /dev/null and b/assets/gfx/2d/numbers_alt/6.tga differ diff --git a/assets/gfx/2d/numbers_alt/7.tga b/assets/gfx/2d/numbers_alt/7.tga new file mode 100644 index 0000000..cf173e7 Binary files /dev/null and b/assets/gfx/2d/numbers_alt/7.tga differ diff --git a/assets/gfx/2d/numbers_alt/8.tga b/assets/gfx/2d/numbers_alt/8.tga new file mode 100644 index 0000000..21a0b54 Binary files /dev/null and b/assets/gfx/2d/numbers_alt/8.tga differ diff --git a/assets/gfx/2d/numbers_alt/9.tga b/assets/gfx/2d/numbers_alt/9.tga new file mode 100644 index 0000000..d548695 Binary files /dev/null and b/assets/gfx/2d/numbers_alt/9.tga differ diff --git a/assets/gfx/2d/numbers_alt/minus.tga b/assets/gfx/2d/numbers_alt/minus.tga new file mode 100644 index 0000000..2129858 Binary files /dev/null and b/assets/gfx/2d/numbers_alt/minus.tga differ diff --git a/src/cgame/cg_draw.c b/src/cgame/cg_draw.c index e3af715..30e6001 100644 --- a/src/cgame/cg_draw.c +++ b/src/cgame/cg_draw.c @@ -3834,6 +3834,143 @@ static void CG_DrawWarmup( void ) UI_Text_Paint( 320 - w / 2, 200 + 1.5f * h, size, colorWhite, text, 0, 0, ITEM_TEXTSTYLE_SHADOWED ); } +/* +================= +CG_DrawWarmup +================= +*/ + +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( ) * 50, crandom( ) * 50, 300 ); +} + +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 ); + + +#define Vector3Set( v, x, y, z ) ((v)[0]=(x),(v)[1]=(y),(v)[2]=(z)) + + if( blob->flags & DAMAGE_BLOB_FRIENDLY ) + Vector3Set( color, 1, 0, 0 ); + else + { + if( blob->flags & DAMAGE_BLOB_BUILDABLE ) + { + if( blob->flags & DAMAGE_BLOB_SPLASH ) + Vector3Set( color, 1, 0.5, 0 ); + else + Vector3Set( color, 0.7, 0.7, 0.7 ); + } + else + { + if( blob->flags & DAMAGE_BLOB_SPLASH ) + Vector3Set( color, 1, 1, 0 ); + else + Vector3Set( 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 ] -= 800 * dt; + } + + trap_R_SetColor( NULL ); +} + //================================================================================== /* @@ -3884,6 +4021,8 @@ static void CG_Draw2D( void ) CG_DrawBuildableStatus( ); } + CG_DrawDamageBlobs( ); + if( !menu ) { menu = Menus_FindByName( "default_hud" ); diff --git a/src/cgame/cg_local.h b/src/cgame/cg_local.h index 5816a9b..bb38c41 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,9 @@ 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; + // // cg_main.c // @@ -1703,6 +1707,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..714b0d8 100644 --- a/src/cgame/cg_main.c +++ b/src/cgame/cg_main.c @@ -232,6 +232,9 @@ vmCvar_t cg_viewQuake; vmCvar_t cg_viewQuakeLambda; vmCvar_t cg_viewQuakeLimit; +vmCvar_t cg_damageBlobSize; +vmCvar_t cg_damageBlobAlpha; + typedef struct { vmCvar_t *vmCvar; @@ -379,7 +382,10 @@ 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 } }; static int cvarTableSize = sizeof( cvarTable ) / sizeof( cvarTable[0] ); @@ -769,6 +775,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 +811,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..891c3e0 100644 --- a/src/cgame/cg_servercmds.c +++ b/src/cgame/cg_servercmds.c @@ -1336,6 +1336,25 @@ 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 ); + + i += 5; + } +} + static consoleCommand_t svcommands[ ] = { { "chat", CG_Chat_f }, @@ -1343,6 +1362,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 }, diff --git a/src/game/bg_public.h b/src/game/bg_public.h index f96fd66..fa93839 100644 --- a/src/game/bg_public.h +++ b/src/game/bg_public.h @@ -1244,3 +1244,7 @@ typedef struct } dummyCmd_t; int cmdcmp( const void *a, const void *b ); +// damage blob flags +#define DAMAGE_BLOB_FRIENDLY 1 +#define DAMAGE_BLOB_BUILDABLE 2 +#define DAMAGE_BLOB_SPLASH 4 diff --git a/src/game/g_active.c b/src/game/g_active.c index 6021a65..90c47c4 100644 --- a/src/game/g_active.c +++ b/src/game/g_active.c @@ -2236,6 +2236,45 @@ void ClientThink( int clientNum ) void G_RunClient( gentity_t *ent ) { + if( ent->client->bufferedBlobCount ) + { + int i; + g_damageBlob_t *blob; + char *p, buffer[ 1024 ]; + + strcpy( buffer, "dblob" ); + p = buffer + 5; + + for( i = 0; i < ent->client->bufferedBlobCount; i++ ) + { + char smallbuf[ 64 ]; + int len; + + blob = ent->client->blobBuffer + i; + + Com_sprintf( smallbuf, sizeof( smallbuf ), " %.0f %.0f %.0f %d %d", + blob->origin[ 0 ], blob->origin[ 1 ], blob->origin[ 2 ], + blob->value, blob->flags ); + + len = strlen( smallbuf ); + + if( p - buffer + len + 1 > sizeof( buffer ) ) + { + trap_SendServerCommand( ent - g_entities, buffer ); + strcpy( buffer, "dblob" ); + p = buffer + 5; + } + + strcpy( p, smallbuf ); + p += len; + } + + if( p > buffer + 6 ) + trap_SendServerCommand( ent - g_entities, buffer ); + + ent->client->bufferedBlobCount = 0; + } + // Run a client think when there are no commands for a time if( !g_synchronousClients.integer && ( g_friendlyFreeze.integer < 100 || diff --git a/src/game/g_combat.c b/src/game/g_combat.c index eb7f48e..9758dc0 100644 --- a/src/game/g_combat.c +++ b/src/game/g_combat.c @@ -1116,6 +1116,42 @@ void G_InitDamageLocations( void ) } +/* +============ +G_SpawnDamageBlob +============ +*/ + +void G_SpawnDamageBlob( + gentity_t *ent, gentity_t *target, int mod, + int damage, vec3_t point, qboolean indirect ) +{ + g_damageBlob_t *blob; + int flags = 0; + + if( !ent || !ent->client || !target || ent == target ) + return; + + if( ent->client->bufferedBlobCount == MAX_BUFFERED_BLOBS ) + return; + + if( OnSameTeam( ent, target ) || + ( target->s.eType == ET_BUILDABLE && + ent->client->pers.teamSelection == target->buildableTeam ) ) + flags |= DAMAGE_BLOB_FRIENDLY; + + if( target->s.eType == ET_BUILDABLE ) + flags |= DAMAGE_BLOB_BUILDABLE; + + if( indirect ) + flags |= DAMAGE_BLOB_SPLASH; + + blob = ent->client->blobBuffer + (ent->client->bufferedBlobCount++); + VectorCopy( point, blob->origin ); + blob->value = damage; + blob->flags = flags; +} + /* ============ T_Damage @@ -1446,6 +1482,7 @@ void G_Damage( gentity_t *targ, gentity_t *inflictor, gentity_t *attacker, } G_CombatStats_HitMOD( attacker, targ, mod, take ); + G_SpawnDamageBlob( attacker, targ, mod, take, point, ( dflags & DAMAGE_RADIUS ) ); if( targ->health <= 0 ) { diff --git a/src/game/g_local.h b/src/game/g_local.h index 30a61b0..cbf98bd 100644 --- a/src/game/g_local.h +++ b/src/game/g_local.h @@ -403,6 +403,14 @@ typedef struct unlagged_s { qboolean used; } unlagged_t; +#define MAX_BUFFERED_BLOBS 20 +typedef struct +{ + vec3_t origin; + int value; + int flags; +} g_damageBlob_t; + #define MAX_TRAMPLE_BUILDABLES_TRACKED 20 // this structure is cleared on each ClientSpawn(), // except for 'client->pers' and 'client->sess' @@ -511,6 +519,9 @@ struct gclient_s int notrackEndTime; // Time when the current no track period ends int blobs; + + g_damageBlob_t blobBuffer[ MAX_BUFFERED_BLOBS ]; + int bufferedBlobCount; }; -- cgit From fe532a0393166815f0cee89e46c917ad22ccb542 Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Fri, 3 Apr 2015 00:57:30 +0200 Subject: Fix damage blobs appearing in wrong places or not appearing at all. --- src/cgame/cg_draw.c | 13 +++---- src/cgame/cg_servercmds.c | 2 -- src/game/g_combat.c | 87 ++++++++++++++++++++++++++--------------------- 3 files changed, 54 insertions(+), 48 deletions(-) diff --git a/src/cgame/cg_draw.c b/src/cgame/cg_draw.c index 30e6001..7ca427f 100644 --- a/src/cgame/cg_draw.c +++ b/src/cgame/cg_draw.c @@ -3937,26 +3937,23 @@ static void CG_DrawDamageBlobs( void ) Com_sprintf( str, sizeof( str ), "%d", blob->value ); - -#define Vector3Set( v, x, y, z ) ((v)[0]=(x),(v)[1]=(y),(v)[2]=(z)) - if( blob->flags & DAMAGE_BLOB_FRIENDLY ) - Vector3Set( color, 1, 0, 0 ); + VectorSet( color, 1, 0, 0 ); else { if( blob->flags & DAMAGE_BLOB_BUILDABLE ) { if( blob->flags & DAMAGE_BLOB_SPLASH ) - Vector3Set( color, 1, 0.5, 0 ); + VectorSet( color, 1, 0.5, 0 ); else - Vector3Set( color, 0.7, 0.7, 0.7 ); + VectorSet( color, 0.7, 0.7, 0.7 ); } else { if( blob->flags & DAMAGE_BLOB_SPLASH ) - Vector3Set( color, 1, 1, 0 ); + VectorSet( color, 1, 1, 0 ); else - Vector3Set( color, 1, 1, 1 ); + VectorSet( color, 1, 1, 1 ); } } diff --git a/src/cgame/cg_servercmds.c b/src/cgame/cg_servercmds.c index 891c3e0..d8a9323 100644 --- a/src/cgame/cg_servercmds.c +++ b/src/cgame/cg_servercmds.c @@ -1350,8 +1350,6 @@ static void CG_DamageBlob_f( void ) flags = atoi( CG_Argv( i + 4 ) ); CG_SpawnDamageBlob( origin, value, flags ); - - i += 5; } } diff --git a/src/game/g_combat.c b/src/game/g_combat.c index 9758dc0..099b5e9 100644 --- a/src/game/g_combat.c +++ b/src/game/g_combat.c @@ -1115,43 +1115,6 @@ void G_InitDamageLocations( void ) } } - -/* -============ -G_SpawnDamageBlob -============ -*/ - -void G_SpawnDamageBlob( - gentity_t *ent, gentity_t *target, int mod, - int damage, vec3_t point, qboolean indirect ) -{ - g_damageBlob_t *blob; - int flags = 0; - - if( !ent || !ent->client || !target || ent == target ) - return; - - if( ent->client->bufferedBlobCount == MAX_BUFFERED_BLOBS ) - return; - - if( OnSameTeam( ent, target ) || - ( target->s.eType == ET_BUILDABLE && - ent->client->pers.teamSelection == target->buildableTeam ) ) - flags |= DAMAGE_BLOB_FRIENDLY; - - if( target->s.eType == ET_BUILDABLE ) - flags |= DAMAGE_BLOB_BUILDABLE; - - if( indirect ) - flags |= DAMAGE_BLOB_SPLASH; - - blob = ent->client->blobBuffer + (ent->client->bufferedBlobCount++); - VectorCopy( point, blob->origin ); - blob->value = damage; - blob->flags = flags; -} - /* ============ T_Damage @@ -1482,7 +1445,55 @@ void G_Damage( gentity_t *targ, gentity_t *inflictor, gentity_t *attacker, } G_CombatStats_HitMOD( attacker, targ, mod, take ); - G_SpawnDamageBlob( attacker, targ, mod, take, point, ( dflags & DAMAGE_RADIUS ) ); + + + if( attacker && attacker->client && take && attacker != targ ) + { + g_damageBlob_t *blob; + int flags = 0; + + if( attacker->client->bufferedBlobCount == MAX_BUFFERED_BLOBS ) + return; + + if( OnSameTeam( attacker, targ ) || + ( targ->s.eType == ET_BUILDABLE && + attacker->client->pers.teamSelection == targ->buildableTeam ) ) + flags |= DAMAGE_BLOB_FRIENDLY; + + if( targ->s.eType == ET_BUILDABLE ) + flags |= DAMAGE_BLOB_BUILDABLE; + + if( dflags & DAMAGE_RADIUS ) + { + vec3_t mins = {0}, maxs = {0}; + + flags |= DAMAGE_BLOB_SPLASH; + + switch( targ->s.eType ) + { + case ET_BUILDABLE: + BG_BuildableBoundingBox( targ->s.modelindex, mins, maxs ); + break; + + case ET_PLAYER: + BG_ClassBoundingBox( targ->client->ps.stats[ STAT_CLASS ], mins, maxs, NULL, NULL, NULL ); + break; + } + + VectorAdd( mins, maxs, point ); + VectorScale( point, 0.5f, point ); + VectorAdd( point, targ->s.origin, point ); + } + else if( inflictor->s.eType == ET_MISSILE ) + VectorCopy( inflictor->r.currentOrigin, point ); + + blob = attacker->client->blobBuffer + + ( attacker->client->bufferedBlobCount++ ); + + VectorCopy( point, blob->origin ); + blob->value = damage; + blob->flags = flags; + } if( targ->health <= 0 ) { -- cgit From 53a42080d6a4e34359b86b6604c48049bcbabfad Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Fri, 3 Apr 2015 01:28:19 +0200 Subject: Make damage blobs easier to read for Aliens. Fix a bug in zapping code. --- src/cgame/cg_draw.c | 4 ++-- src/game/g_weapon.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cgame/cg_draw.c b/src/cgame/cg_draw.c index 7ca427f..d8b411c 100644 --- a/src/cgame/cg_draw.c +++ b/src/cgame/cg_draw.c @@ -3878,7 +3878,7 @@ found_blob: blob->value = value; blob->flags = flags; VectorCopy( origin, blob->origin ); - VectorSet( blob->velocity, crandom( ) * 50, crandom( ) * 50, 300 ); + VectorSet( blob->velocity, crandom( ) * 20, crandom( ) * 20, 100 ); } static void CG_DrawNumber( float x, float y, float h, char *str ) @@ -3962,7 +3962,7 @@ static void CG_DrawDamageBlobs( void ) CG_DrawNumber( x, y, scale, str ); VectorMA( blob->origin, dt, blob->velocity, blob->origin ); - blob->velocity[ 2 ] -= 800 * dt; + blob->velocity[ 2 ] -= 300 * dt; } trap_R_SetColor( NULL ); diff --git a/src/game/g_weapon.c b/src/game/g_weapon.c index 3a8c8ac..95e0b11 100644 --- a/src/game/g_weapon.c +++ b/src/game/g_weapon.c @@ -1473,7 +1473,7 @@ static void G_CreateNewZap( gentity_t *creator, gentity_t *target ) { if( !zap->targets[ i ]->client || zap->targets[ i ]->client->ps.stats[ STAT_TEAM ] != TEAM_ALIENS ) - G_Damage( zap->targets[ i ], target, zap->creator, forward, target->s.origin, + G_Damage( zap->targets[ i ], target, zap->creator, forward, zap->targets[ i ]->s.origin, LEVEL2_AREAZAP_DMG * ( 1 - pow( (zap->distances[ i ] / LEVEL2_AREAZAP_CHAIN_RANGE ), LEVEL2_AREAZAP_CHAIN_FALLOFF ) ) + 1, DAMAGE_NO_KNOCKBACK | DAMAGE_NO_LOCDAMAGE, -- cgit From e6735d21e17ecbbe03607046ded443516b65c3a7 Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Fri, 3 Apr 2015 02:21:52 +0200 Subject: Make damage blobs show the actual damage dealt. --- src/game/g_combat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/game/g_combat.c b/src/game/g_combat.c index 099b5e9..1a54981 100644 --- a/src/game/g_combat.c +++ b/src/game/g_combat.c @@ -1491,7 +1491,7 @@ void G_Damage( gentity_t *targ, gentity_t *inflictor, gentity_t *attacker, ( attacker->client->bufferedBlobCount++ ); VectorCopy( point, blob->origin ); - blob->value = damage; + blob->value = take; blob->flags = flags; } -- cgit From 0d5460522ba3651da1ed5630f7f8a784c5eb6514 Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Fri, 3 Apr 2015 03:50:41 +0200 Subject: Initial implementation of health bars. --- src/cgame/cg_draw.c | 120 +++++++++++++++++++++++++++++++++++++++++++++++++++- src/game/g_active.c | 4 ++ 2 files changed, 123 insertions(+), 1 deletion(-) diff --git a/src/cgame/cg_draw.c b/src/cgame/cg_draw.c index d8b411c..340a207 100644 --- a/src/cgame/cg_draw.c +++ b/src/cgame/cg_draw.c @@ -3836,7 +3836,7 @@ static void CG_DrawWarmup( void ) /* ================= -CG_DrawWarmup +Damage blobs ================= */ @@ -3968,6 +3968,123 @@ static void CG_DrawDamageBlobs( void ) 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 = ¢->currentState; + + if( es->eFlags & EF_DEAD ) + continue; + + switch( es->eType ) + { + case ET_BUILDABLE: + bar->value = es->generic1; + bar->max = BG_Buildable( es->modelindex )->health; + BG_BuildableBoundingBox( es->modelindex, mins, maxs ); + break; + + case ET_PLAYER: + 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 = 20 * 100 / bar->dist; + w = 4 * h * cgDC.aspectScale; + + Com_sprintf( buffer, sizeof( buffer ), "%d", bar->value ); + + color[ 3 ] = 1.0f; + + 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 ); + } +} + + //================================================================================== /* @@ -4019,6 +4136,7 @@ static void CG_Draw2D( void ) } CG_DrawDamageBlobs( ); + CG_DrawHealthBars( ); if( !menu ) { diff --git a/src/game/g_active.c b/src/game/g_active.c index 90c47c4..2eede6b 100644 --- a/src/game/g_active.c +++ b/src/game/g_active.c @@ -2236,6 +2236,7 @@ void ClientThink( int clientNum ) void G_RunClient( gentity_t *ent ) { + // send all buffered damage blobs if( ent->client->bufferedBlobCount ) { int i; @@ -2275,6 +2276,9 @@ void G_RunClient( gentity_t *ent ) ent->client->bufferedBlobCount = 0; } + // update the public health field + ent->s.otherEntityNum2 = MAX( 0, ent->client->ps.stats[ STAT_HEALTH ] ); + // Run a client think when there are no commands for a time if( !g_synchronousClients.integer && ( g_friendlyFreeze.integer < 100 || -- cgit From f639515054b2122c7166793f7c0a0a751087209f Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Fri, 3 Apr 2015 13:51:24 +0200 Subject: Make health bars customizable with cvars. --- src/cgame/cg_draw.c | 4 ++-- src/cgame/cg_local.h | 3 +++ src/cgame/cg_main.c | 8 +++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/cgame/cg_draw.c b/src/cgame/cg_draw.c index 340a207..64e5ed7 100644 --- a/src/cgame/cg_draw.c +++ b/src/cgame/cg_draw.c @@ -4063,12 +4063,12 @@ static void CG_DrawHealthBars( void ) hf = (float)bar->value / bar->max; - h = 20 * 100 / bar->dist; + h = cg_healthBarSize.value / bar->dist; w = 4 * h * cgDC.aspectScale; Com_sprintf( buffer, sizeof( buffer ), "%d", bar->value ); - color[ 3 ] = 1.0f; + color[ 3 ] = cg_healthBarAlpha.value; VectorSet( color, 0.1, 0.7, 0.1 ); trap_R_SetColor( color ); diff --git a/src/cgame/cg_local.h b/src/cgame/cg_local.h index bb38c41..83cac63 100644 --- a/src/cgame/cg_local.h +++ b/src/cgame/cg_local.h @@ -1610,6 +1610,9 @@ 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 // diff --git a/src/cgame/cg_main.c b/src/cgame/cg_main.c index 714b0d8..0fdb028 100644 --- a/src/cgame/cg_main.c +++ b/src/cgame/cg_main.c @@ -235,6 +235,9 @@ 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; @@ -385,7 +388,10 @@ static cvarTable_t cvarTable[ ] = { &cg_viewQuakeLimit, "cg_viewQuakeLimit", "5", CVAR_ARCHIVE }, { &cg_damageBlobSize, "cg_damageBlobSize", "400", CVAR_ARCHIVE }, - { &cg_damageBlobAlpha, "cg_damageBlobAlpha", "0.8", 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] ); -- cgit From 9ab47e4be8337219585f59b1c28ec72bc25a5ae1 Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Fri, 3 Apr 2015 14:10:06 +0200 Subject: Make health bars invisible if build stats are visible. --- src/cgame/cg_draw.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/cgame/cg_draw.c b/src/cgame/cg_draw.c index 64e5ed7..e351b70 100644 --- a/src/cgame/cg_draw.c +++ b/src/cgame/cg_draw.c @@ -4009,6 +4009,9 @@ static void CG_DrawHealthBars( void ) 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 ); -- cgit From 7f984114f2e19b0579e1d55e3c1a8925a88c35d0 Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Fri, 3 Apr 2015 18:07:22 +0200 Subject: Do not display health bars on cloaked players. --- src/cgame/cg_draw.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cgame/cg_draw.c b/src/cgame/cg_draw.c index e351b70..2c6645f 100644 --- a/src/cgame/cg_draw.c +++ b/src/cgame/cg_draw.c @@ -4003,7 +4003,7 @@ static void CG_DrawHealthBars( void ) cent = cg_entities + cg.snap->entities[ i ].number; es = ¢->currentState; - if( es->eFlags & EF_DEAD ) + if( es->eFlags & ( EF_DEAD | EF_NODRAW ) ) continue; switch( es->eType ) @@ -4018,6 +4018,9 @@ static void CG_DrawHealthBars( void ) 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 ); -- cgit