summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaweł Redman <pawel.redman@gmail.com>2015-04-07 13:34:17 +0200
committerPaweł Redman <pawel.redman@gmail.com>2015-04-07 13:34:17 +0200
commit84788917d2deb14f07c5710f2f9eaaae3f0b50a2 (patch)
tree0eca2e499cd6d744c6be2f55db5c91d1aa906781 /src
parent7bf6dbfed060ded89da8c53ae8b712e62bd19da2 (diff)
Rename damage blobs to damage indicators.
Diffstat (limited to 'src')
-rw-r--r--src/cgame/cg_draw.c121
-rw-r--r--src/cgame/cg_local.h4
-rw-r--r--src/cgame/cg_main.c8
-rw-r--r--src/cgame/cg_servercmds.c6
-rw-r--r--src/game/bg_public.h9
-rw-r--r--src/game/g_active.c22
-rw-r--r--src/game/g_combat.c95
-rw-r--r--src/game/g_local.h8
8 files changed, 168 insertions, 105 deletions
diff --git a/src/cgame/cg_draw.c b/src/cgame/cg_draw.c
index 35c53cc..0af9839 100644
--- a/src/cgame/cg_draw.c
+++ b/src/cgame/cg_draw.c
@@ -3836,7 +3836,7 @@ static void CG_DrawWarmup( void )
/*
=================
-Damage blobs
+Damage indicators
=================
*/
@@ -3848,54 +3848,71 @@ typedef struct
int flags;
vec3_t origin;
vec3_t velocity;
-} cg_damageBlob_t;
+} cg_damageIndicator_t;
-#define MAX_DAMAGE_BLOBS 50
-cg_damageBlob_t cg_damageBlobs[ MAX_DAMAGE_BLOBS ];
+#define MAX_DAMAGE_INDICATORS 50
+cg_damageIndicator_t cg_damageIndicators[ MAX_DAMAGE_INDICATORS ];
-void CG_SpawnDamageBlob( vec3_t origin, int value, int flags )
+/*
+=================
+CG_SpawnDamageIndicator
+
+Creates a new local damage indicator
+=================
+*/
+void CG_SpawnDamageIndicator( vec3_t origin, int value, int flags )
{
- centity_t *cent;
- cg_damageBlob_t *blob, *oldest = NULL;
+ int i;
+ cg_damageIndicator_t *di, *oldest = NULL;
- for( blob = cg_damageBlobs; blob < cg_damageBlobs + MAX_DAMAGE_BLOBS; blob++ )
+ for( i = 0; i < MAX_DAMAGE_INDICATORS; i++ )
{
- if( !oldest || blob->spawnTime < oldest->spawnTime )
- oldest = blob;
+ di = cg_damageIndicators + i;
+
+ if( !oldest || di->spawnTime < oldest->spawnTime )
+ oldest = di;
- if( blob->inuse )
+ if( di->inuse )
continue;
- goto found_blob;
+ goto found;
}
- oldest = blob;
+ oldest = di;
-found_blob:
+found:
- 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 );
+ di->inuse = qtrue;
+ di->spawnTime = cg.time;
+ di->value = value;
+ di->flags = flags;
+ VectorCopy( origin, di->origin );
+ VectorSet( di->velocity, crandom( ) * 20, crandom( ) * 20, 100 );
if( cg_hitSounds.integer > 1 ||
( cg_hitSounds.integer == 1 &&
- ( flags & DAMAGE_BLOB_FRIENDLY ) ) )
+ ( flags & DIF_FRIENDLY ) ) )
{
int index;
- if( flags & DAMAGE_BLOB_FRIENDLY )
+ if( flags & DIF_FRIENDLY )
index = 4;
else
- index = ( flags & ( DAMAGE_BLOB_SPLASH | DAMAGE_BLOB_BUILDABLE ) );
+ index = ( flags & ( DIF_INDIRECT | DIF_BUILDABLE ) );
trap_S_StartLocalSound( cgs.media.hitSounds[ index ], CHAN_LOCAL_SOUND );
}
}
-static void CG_DrawNumber( float x, float y, float h, char *str )
+/*
+=================
+CG_DrawAltNumber
+
+Draws a centered (horizontally and vertically) number using the
+cgs.media.numbersAlt charset. Used by damage indicators and health bars.
+=================
+*/
+static void CG_DrawAltNumber( float x, float y, float h, char *str )
{
int index, len;
float w;
@@ -3923,64 +3940,76 @@ static void CG_DrawNumber( float x, float y, float h, char *str )
}
}
-#define DAMAGE_BLOB_TIME 700
+#define DIF_TIME 700
+
+/*
+=================
+CG_DrawDamageIndicators
-static void CG_DrawDamageBlobs( void )
+Handle damage indicators' dynamics, timing out and drawing.
+=================
+*/
+static void CG_DrawDamageIndicators( void )
{
- cg_damageBlob_t *blob;
+ int i;
+ cg_damageIndicator_t *di;
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++ )
+ for( i = 0; i < MAX_DAMAGE_INDICATORS; i++ )
{
- if( !blob->inuse )
+ di = cg_damageIndicators + i;
+
+ if( !di->inuse )
continue;
- if( blob->spawnTime + DAMAGE_BLOB_TIME < cg.time )
+ if( di->spawnTime + DIF_TIME < cg.time )
{
- blob->inuse = qfalse;
+ di->inuse = qfalse;
continue;
}
- if( !CG_WorldToScreen( blob->origin, &x, &y ) )
+ if( !CG_WorldToScreen( di->origin, &x, &y ) )
continue;
- fade = 1.0f - (float)( cg.time - blob->spawnTime ) / DAMAGE_BLOB_TIME;
+ fade = 1.0f - (float)( cg.time - di->spawnTime ) / DIF_TIME;
- scale = 0.75f * cg_damageBlobSize.value /
- pow( Distance( blob->origin, cg.refdef.vieworg ), 0.5f );
+ scale = 0.75f * cg_damageIndicatorSize.value /
+ pow( Distance( di->origin, cg.refdef.vieworg ), 0.5f );
- Com_sprintf( str, sizeof( str ), "%d", blob->value );
+ Com_sprintf( str, sizeof( str ), "%d", di->value );
- if( blob->flags & DAMAGE_BLOB_FRIENDLY )
+ if( di->flags & DIF_FRIENDLY )
VectorSet( color, 1, 0, 0 );
+ else if( di->flags & DIF_PERSISTENT )
+ VectorSet( color, 0, 1, 0 );
else
{
- if( blob->flags & DAMAGE_BLOB_BUILDABLE )
+ if( di->flags & DIF_BUILDABLE )
{
- if( blob->flags & DAMAGE_BLOB_SPLASH )
+ if( di->flags & DIF_INDIRECT )
VectorSet( color, 1, 0.5, 0 );
else
VectorSet( color, 0.7, 0.7, 0.7 );
}
else
{
- if( blob->flags & DAMAGE_BLOB_SPLASH )
+ if( di->flags & DIF_INDIRECT )
VectorSet( color, 1, 1, 0 );
else
VectorSet( color, 1, 1, 1 );
}
}
- color[ 3 ] = cg_damageBlobAlpha.value * fade;
+ color[ 3 ] = cg_damageIndicatorAlpha.value * fade;
trap_R_SetColor( color );
- CG_DrawNumber( x, y, scale, str );
+ CG_DrawAltNumber( x, y, scale, str );
- VectorMA( blob->origin, dt, blob->velocity, blob->origin );
- blob->velocity[ 2 ] -= 300 * dt;
+ VectorMA( di->origin, dt, di->velocity, di->origin );
+ di->velocity[ 2 ] -= 300 * dt;
}
trap_R_SetColor( NULL );
@@ -4110,7 +4139,7 @@ static void CG_DrawHealthBars( void )
VectorSet( color, 1, 1, 1 );
trap_R_SetColor( color );
- CG_DrawNumber( x, y, h, buffer );
+ CG_DrawAltNumber( x, y, h, buffer );
}
}
@@ -4165,8 +4194,8 @@ static void CG_Draw2D( void )
CG_DrawBuildableStatus( );
}
- CG_DrawDamageBlobs( );
CG_DrawHealthBars( );
+ CG_DrawDamageIndicators( );
if( !menu )
{
diff --git a/src/cgame/cg_local.h b/src/cgame/cg_local.h
index 6c3325a..dc40f22 100644
--- a/src/cgame/cg_local.h
+++ b/src/cgame/cg_local.h
@@ -1609,8 +1609,8 @@ 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_damageIndicatorSize;
+extern vmCvar_t cg_damageIndicatorAlpha;
extern vmCvar_t cg_healthBarSize;
extern vmCvar_t cg_healthBarAlpha;
diff --git a/src/cgame/cg_main.c b/src/cgame/cg_main.c
index 06fd2a3..f562728 100644
--- a/src/cgame/cg_main.c
+++ b/src/cgame/cg_main.c
@@ -232,8 +232,8 @@ vmCvar_t cg_viewQuake;
vmCvar_t cg_viewQuakeLambda;
vmCvar_t cg_viewQuakeLimit;
-vmCvar_t cg_damageBlobSize;
-vmCvar_t cg_damageBlobAlpha;
+vmCvar_t cg_damageIndicatorSize;
+vmCvar_t cg_damageIndicatorAlpha;
vmCvar_t cg_healthBarSize;
vmCvar_t cg_healthBarAlpha;
@@ -389,8 +389,8 @@ static cvarTable_t cvarTable[ ] =
{ &cg_viewQuakeLambda, "cg_viewQuakeLambda", "-10", 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_damageIndicatorSize, "cg_damageIndicatorSize", "400", CVAR_ARCHIVE },
+ { &cg_damageIndicatorAlpha, "cg_damageIndicatorAlpha", "0.8", CVAR_ARCHIVE },
{ &cg_healthBarSize, "cg_healthBarSize", "2000", CVAR_ARCHIVE },
{ &cg_healthBarAlpha, "cg_healthBarAlpha", "0.5", CVAR_ARCHIVE },
diff --git a/src/cgame/cg_servercmds.c b/src/cgame/cg_servercmds.c
index d8a9323..a373e5a 100644
--- a/src/cgame/cg_servercmds.c
+++ b/src/cgame/cg_servercmds.c
@@ -1336,7 +1336,7 @@ static void CG_GameCmds_f( void )
trap_AddCommand( CG_Argv( i ) );
}
-static void CG_DamageBlob_f( void )
+static void CG_DamageIndicator_f( void )
{
int i, count = trap_Argc( ), value, flags;
vec3_t origin;
@@ -1349,7 +1349,7 @@ static void CG_DamageBlob_f( void )
value = atoi( CG_Argv( i + 3 ) );
flags = atoi( CG_Argv( i + 4 ) );
- CG_SpawnDamageBlob( origin, value, flags );
+ CG_SpawnDamageIndicator( origin, value, flags );
}
}
@@ -1360,7 +1360,7 @@ static consoleCommand_t svcommands[ ] =
{ "cmds", CG_GameCmds_f },
{ "cp", CG_CenterPrint_f },
{ "cs", CG_ConfigStringModified },
- { "dblob", CG_DamageBlob_f },
+ { "di", CG_DamageIndicator_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 a04d053..1e9d23c 100644
--- a/src/game/bg_public.h
+++ b/src/game/bg_public.h
@@ -1244,7 +1244,8 @@ typedef struct
} dummyCmd_t;
int cmdcmp( const void *a, const void *b );
-// damage blob flags
-#define DAMAGE_BLOB_SPLASH 1 // has to be 1
-#define DAMAGE_BLOB_BUILDABLE 2 // has to be 2
-#define DAMAGE_BLOB_FRIENDLY 4
+// damage indicator flags
+#define DIF_INDIRECT 0x0001 // has to be 1
+#define DIF_BUILDABLE 0x0002 // has to be 2
+#define DIF_FRIENDLY 0x0004
+#define DIF_PERSISTENT 0x0008 // poison and infection
diff --git a/src/game/g_active.c b/src/game/g_active.c
index 02cb6e9..0c84f57 100644
--- a/src/game/g_active.c
+++ b/src/game/g_active.c
@@ -2270,33 +2270,33 @@ void ClientThink( int clientNum )
void G_RunClient( gentity_t *ent )
{
// send all buffered damage blobs
- if( ent->client->bufferedBlobCount )
+ if( ent->client->diBufferCounter )
{
int i;
- g_damageBlob_t *blob;
+ g_damageIndicator_t *di;
char *p, buffer[ 1024 ];
- strcpy( buffer, "dblob" );
- p = buffer + 5;
+ strcpy( buffer, "di" );
+ p = buffer + 2;
- for( i = 0; i < ent->client->bufferedBlobCount; i++ )
+ for( i = 0; i < ent->client->diBufferCounter; i++ )
{
char smallbuf[ 64 ];
int len;
- blob = ent->client->blobBuffer + i;
+ di = ent->client->diBuffer + i;
Com_sprintf( smallbuf, sizeof( smallbuf ), " %.0f %.0f %.0f %d %d",
- blob->origin[ 0 ], blob->origin[ 1 ], blob->origin[ 2 ],
- blob->value, blob->flags );
+ di->origin[ 0 ], di->origin[ 1 ], di->origin[ 2 ],
+ di->value, di->flags );
len = strlen( smallbuf );
if( p - buffer + len + 1 > sizeof( buffer ) )
{
G_SendPublicServerCommand( ent - g_entities, buffer );
- strcpy( buffer, "dblob" );
- p = buffer + 5;
+ strcpy( buffer, "di" );
+ p = buffer + 2;
}
strcpy( p, smallbuf );
@@ -2306,7 +2306,7 @@ void G_RunClient( gentity_t *ent )
if( p > buffer + 6 )
G_SendPublicServerCommand( ent - g_entities, buffer );
- ent->client->bufferedBlobCount = 0;
+ ent->client->diBufferCounter = 0;
}
// update the public health field
diff --git a/src/game/g_combat.c b/src/game/g_combat.c
index 423b517..b0d435b 100644
--- a/src/game/g_combat.c
+++ b/src/game/g_combat.c
@@ -1117,6 +1117,69 @@ void G_InitDamageLocations( void )
/*
============
+G_SpawnDamageIndicator
+
+Computes a damage indicator for a given hit and stores it in the
+player's damage indicator buffer.
+============
+*/
+void G_SpawnDamageIndicator( gentity_t *ent, gentity_t *inflictor,
+ gentity_t *targ, const vec3_t point, int mod, int take, int dflags )
+{
+ g_damageIndicator_t *di;
+
+ if( !ent || !ent->client )
+ return;
+
+ if( ent == targ )
+ return;
+
+ if( !take )
+ return;
+
+ if( ent->client->diBufferCounter >= MAX_BUFFERED_DAMAGE_INDICATORS )
+ return;
+
+ di = ent->client->diBuffer + ent->client->diBufferCounter++;
+ di->value = take;
+
+ di->flags = 0;
+
+ if( targ->s.eType == ET_BUILDABLE )
+ di->flags |= DIF_BUILDABLE;
+
+ if( OnSameTeam( ent, targ ) ||
+ ( targ->s.eType == ET_BUILDABLE &&
+ ent->client->pers.teamSelection == targ->buildableTeam ) )
+ di->flags |= DIF_FRIENDLY;
+
+ if( dflags & DAMAGE_RADIUS )
+ di->flags |= DIF_INDIRECT;
+
+ switch( mod )
+ {
+ case MOD_POISON:
+ case MOD_INFECTION:
+ di->flags |= DIF_INDIRECT | DIF_PERSISTENT;
+ break;
+
+ case MOD_DECONSTRUCT:
+ return;
+ }
+
+ if( di->flags & DIF_INDIRECT )
+ {
+ VectorAdd( targ->r.absmin, targ->r.absmax, di->origin );
+ VectorScale( di->origin, 0.5f, di->origin );
+ }
+ else if( inflictor->s.eType == ET_MISSILE )
+ VectorCopy( inflictor->r.currentOrigin, di->origin );
+ else
+ VectorCopy( point, di->origin );
+}
+
+/*
+============
T_Damage
targ entity that is being damaged
@@ -1446,37 +1509,7 @@ void G_Damage( gentity_t *targ, gentity_t *inflictor, gentity_t *attacker,
G_CombatStats_HitMOD( attacker, targ, mod, take );
-
- if( attacker && attacker->client && take && attacker != targ &&
- attacker->client->bufferedBlobCount < MAX_BUFFERED_BLOBS )
- {
- g_damageBlob_t *blob;
-
- blob = attacker->client->blobBuffer +
- ( attacker->client->bufferedBlobCount++ );
-
- blob->flags = 0;
- blob->value = take;
-
- if( OnSameTeam( attacker, targ ) ||
- ( targ->s.eType == ET_BUILDABLE &&
- attacker->client->pers.teamSelection == targ->buildableTeam ) )
- blob->flags |= DAMAGE_BLOB_FRIENDLY;
-
- if( targ->s.eType == ET_BUILDABLE )
- blob->flags |= DAMAGE_BLOB_BUILDABLE;
-
- if( ( dflags & DAMAGE_RADIUS ) || mod == MOD_POISON )
- {
- blob->flags |= DAMAGE_BLOB_SPLASH;
- VectorAdd( targ->r.absmin, targ->r.absmax, blob->origin );
- VectorScale( blob->origin, 0.5f, blob->origin );
- }
- else if( inflictor->s.eType == ET_MISSILE )
- VectorCopy( inflictor->r.currentOrigin, blob->origin );
- else
- VectorCopy( point, blob->origin );
- }
+ G_SpawnDamageIndicator( attacker, inflictor, targ, point, mod, take, dflags );
if( targ->health <= 0 )
{
diff --git a/src/game/g_local.h b/src/game/g_local.h
index cbf98bd..b4f6d81 100644
--- a/src/game/g_local.h
+++ b/src/game/g_local.h
@@ -403,13 +403,13 @@ typedef struct unlagged_s {
qboolean used;
} unlagged_t;
-#define MAX_BUFFERED_BLOBS 20
+#define MAX_BUFFERED_DAMAGE_INDICATORS 20
typedef struct
{
vec3_t origin;
int value;
int flags;
-} g_damageBlob_t;
+} g_damageIndicator_t;
#define MAX_TRAMPLE_BUILDABLES_TRACKED 20
// this structure is cleared on each ClientSpawn(),
@@ -520,8 +520,8 @@ struct gclient_s
int notrackEndTime; // Time when the current no track period ends
int blobs;
- g_damageBlob_t blobBuffer[ MAX_BUFFERED_BLOBS ];
- int bufferedBlobCount;
+ g_damageIndicator_t diBuffer[ MAX_BUFFERED_DAMAGE_INDICATORS ];
+ int diBufferCounter;
};