Skip to content

Commit

Permalink
game, cgame: add cg_damagePlum(size,colorstyle)
Browse files Browse the repository at this point in the history
  • Loading branch information
yumirak committed Mar 5, 2024
1 parent 7eff10b commit 6e85764
Show file tree
Hide file tree
Showing 11 changed files with 337 additions and 10 deletions.
47 changes: 47 additions & 0 deletions code/cgame/cg_effects.c
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,54 @@ void CG_ScorePlum( int client, vec3_t org, int score ) {
VectorClear(angles);
AnglesToAxis( angles, re->axis );
}
/*
==================
CG_DamagePlum
==================
*/

void CG_DamagePlum( int client, vec3_t org, int damage ) {
localEntity_t *le;
refEntity_t *re;
vec3_t angles;
static vec3_t lastPos;

if (client != cg.predictedPlayerState.clientNum || cg_damagePlum.integer == 0) {
return;
}

le = CG_AllocLocalEntity();
le->leFlags = 0;
le->leType = LE_DAMAGEPLUM;
le->startTime = cg.time;
le->endTime = cg.time + 1000;
le->lifeRate = 1.0 / ( le->endTime - le->startTime );


le->color[0] = le->color[1] = le->color[2] = le->color[3] = 1.0;
le->radius = damage;

VectorCopy( org, le->pos.trBase );
if (org[2] >= lastPos[2] - 20 && org[2] <= lastPos[2] + 20) {
le->pos.trBase[2] -= 20;
}

//CG_Printf( "Plum origin %i %i %i -- %i\n", (int)org[0], (int)org[1], (int)org[2], (int)Distance(org, lastPos));
VectorCopy(org, lastPos);

le->pos.trDelta[0] = 2.0 * crandom();
le->pos.trDelta[1] = 2.0 * crandom();
le->pos.trDelta[2] = 6.0;

re = &le->refEntity;

re->reType = RT_SPRITE;
re->renderfx = RF_FIRST_PERSON;
re->radius = 11;

VectorClear(angles);
AnglesToAxis( angles, re->axis );
}

/*
====================
Expand Down
5 changes: 4 additions & 1 deletion code/cgame/cg_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,10 @@ void CG_EntityEvent( centity_t *cent, vec3_t position ) {
DEBUGNAME("EV_SCOREPLUM");
CG_ScorePlum( cent->currentState.otherEntityNum, cent->lerpOrigin, cent->currentState.time );
break;

case EV_DAMAGEPLUM:
DEBUGNAME("EV_DAMAGEPLUM");
CG_DamagePlum( cent->currentState.otherEntityNum, cent->lerpOrigin, cent->currentState.time );
break;
//
// missile impacts
//
Expand Down
10 changes: 8 additions & 2 deletions code/cgame/cg_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,9 @@ typedef enum {
LE_KAMIKAZE,
LE_INVULIMPACT,
LE_INVULJUICED,
LE_SHOWREFENTITY
LE_SHOWREFENTITY,
#endif
LE_DAMAGEPLUM
} leType_t;

typedef enum {
Expand Down Expand Up @@ -1300,6 +1301,11 @@ extern vmCvar_t cg_teamModel;
extern vmCvar_t cg_teamColors;
extern vmCvar_t cg_deadBodyDarken;
//
extern vmCvar_t cg_damagePlum;
extern vmCvar_t cg_damagePlumStyle;
extern vmCvar_t cg_damagePlumSize;
//


//
// cg_main.c
Expand Down Expand Up @@ -1562,7 +1568,7 @@ void CG_InvulnerabilityJuiced( vec3_t org );
void CG_LightningBoltBeam( vec3_t start, vec3_t end );
#endif
void CG_ScorePlum( int client, vec3_t org, int score );

void CG_DamagePlum( int client, vec3_t org, int score );
void CG_GibPlayer(const centity_t *cent);
void CG_BigExplode( vec3_t playerOrigin );

Expand Down
174 changes: 172 additions & 2 deletions code/cgame/cg_localents.c
Original file line number Diff line number Diff line change
Expand Up @@ -728,12 +728,13 @@ CG_AddScorePlum
===================
*/
#define NUMBER_SIZE 8
#define MAX_PLUM_DIGITS 10

void CG_AddScorePlum( localEntity_t *le ) {
refEntity_t *re;
vec3_t origin, delta, dir, vec, up = {0, 0, 1};
float c, len;
int i, score, digits[10], numdigits, negative;
int i, score, digits[MAX_PLUM_DIGITS], numdigits, negative;

re = &le->refEntity;

Expand Down Expand Up @@ -791,7 +792,7 @@ void CG_AddScorePlum( localEntity_t *le ) {
score = -score;
}

for (numdigits = 0; !(numdigits && !score); numdigits++) {
for (numdigits = 0; !(numdigits && !score) && numdigits < MAX_PLUM_DIGITS - 1; numdigits++) {
digits[numdigits] = score % 10;
score = score / 10;
}
Expand All @@ -807,7 +808,173 @@ void CG_AddScorePlum( localEntity_t *le ) {
trap_R_AddRefEntityToScene( re );
}
}
/*
===================
CG_AddDamagePlum
===================
*/
void CG_AddDamagePlum( localEntity_t *le ) {
refEntity_t *re;
vec3_t origin, dir, vec, up = {0, 0, 1};
float c;
int i, damage, digits[MAX_PLUM_DIGITS], numdigits, negative;
float deltaTime;
float size;
int weapon;

re = &le->refEntity;

c = ( le->endTime - cg.time ) * le->lifeRate;
weapon = cg_entities[cg.snap->ps.clientNum].currentState.weapon;;
damage = le->radius;
if (!weapon) {
//CG_Printf("^3WARNING CG_AddDamagePlum() invalid weapon number '%d'\n", weapon);
return;
}
switch(cg_damagePlumStyle.integer)
{
default:
// white
VectorSet(re->shaderRGBA, 0xff, 0xff, 0xff);
break;
case 1:
switch((damage + 1) / 20) {
case 0:
// light blue
VectorSet(re->shaderRGBA, 0x38, 0xb0, 0xde);
break;
case 1:
// yellow
VectorSet(re->shaderRGBA, 0xff, 0xff, 0x00);
break;
case 2:
// orange
VectorSet(re->shaderRGBA, 0xff, 0x7f, 0x00);
break;
default:
// red
VectorSet(re->shaderRGBA, 0xff, 0x00, 0x00);
break;
}
break;
case 2:
switch (weapon) {
case WP_GAUNTLET:
// light blue
VectorSet(re->shaderRGBA, 0x38, 0xb0, 0xde);
break;
case WP_MACHINEGUN:
// yellow
VectorSet(re->shaderRGBA, 0xff, 0xff, 0x00);
break;
case WP_SHOTGUN:
// orange
VectorSet(re->shaderRGBA, 0xff, 0x7f, 0x00);
break;
case WP_GRENADE_LAUNCHER:
// dark green
VectorSet(re->shaderRGBA, 0x00, 0x7f, 0x00);
break;
case WP_ROCKET_LAUNCHER:
// red
VectorSet(re->shaderRGBA, 0xff, 0x00, 0x00);
break;
case WP_LIGHTNING:
// yellowish white
VectorSet(re->shaderRGBA, 0xff, 0xff, 0xaf);
break;
case WP_RAILGUN:
// green
VectorSet(re->shaderRGBA, 0x00, 0xff, 0x00);
break;
case WP_PLASMAGUN:
// magenta
VectorSet(re->shaderRGBA, 0xaf, 0x00, 0xaf);
break;
case WP_BFG:
// dark blue
VectorSet(re->shaderRGBA, 0x00, 0x3f, 0xaf);
break;
case WP_GRAPPLING_HOOK:
//FIXME ql doesn't show hook damage plum
// purple
VectorSet(re->shaderRGBA, 0x55, 0xa8, 0x8b);
break;
#ifdef MISSIONPACK
case WP_NAILGUN:
// turquoise
VectorSet(re->shaderRGBA, 0x00, 0xaf, 0x7f);
break;
case WP_PROX_LAUNCHER:
// rose
VectorSet(re->shaderRGBA, 0xff, 0x00, 0x7f);
break;
case WP_CHAINGUN:
// light grey
VectorSet(re->shaderRGBA, 0xaf, 0xaf, 0xaf);
break;
#endif
case WP_HMG:
// dark yellowish orange
VectorSet(re->shaderRGBA, 0xaf, 0xaf, 0x00);
break;
default:
// light blue
VectorSet(re->shaderRGBA, 0x38, 0xb0, 0xde);
break;
}
break;
}


if (c < 0.25)
re->shaderRGBA[3] = 0xff * 4 * c;
else
re->shaderRGBA[3] = 0xff;


deltaTime = (cg.time - le->startTime) * 0.001;
VectorCopy(le->pos.trBase, origin);

VectorSubtract(cg.refdef.vieworg, origin, dir);
CrossProduct(dir, up, vec);
VectorNormalize(vec);
VectorNormalize(dir);
VectorMA(cg.refdef.vieworg, -8, dir, origin);

VectorMA(origin, deltaTime, le->pos.trDelta, origin);
// like TR_GRAVITY, but with different gravity
origin[2] -= 0.5 * 12 * deltaTime * deltaTime;


size = cg_damagePlumSize.value * 0.03;
re->radius = size / 2;

negative = qfalse;
if (damage < 0) {
negative = qtrue;
damage = -damage;
}

for (numdigits = 0; !(numdigits && !damage) && numdigits < MAX_PLUM_DIGITS-1; numdigits++) {
digits[numdigits] = damage % 10;
damage = damage / 10;
}

if (negative) {
digits[numdigits] = 10;
numdigits++;
}

for (i = 0; i < numdigits; i++) {
VectorMA(origin, ((float)numdigits / 2.0 - 0.5 - (float) i) * size, vec, re->origin);
// damage plums still using old quake3 font
re->customShader = cgs.media.numberShaders[digits[numdigits-1-i]];
trap_R_AddRefEntityToScene( re );

}

}



Expand Down Expand Up @@ -873,6 +1040,9 @@ void CG_AddLocalEntities( void ) {
case LE_SCOREPLUM:
CG_AddScorePlum( le );
break;
case LE_DAMAGEPLUM:
CG_AddDamagePlum( le );
break;

#ifdef MISSIONPACK
case LE_KAMIKAZE:
Expand Down
8 changes: 8 additions & 0 deletions code/cgame/cg_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ vmCvar_t cg_teamModel;
vmCvar_t cg_teamColors;
vmCvar_t cg_deadBodyDarken;
//
vmCvar_t cg_damagePlum;
vmCvar_t cg_damagePlumStyle;
vmCvar_t cg_damagePlumSize;
//
typedef struct {
vmCvar_t *vmCvar;
char *cvarName;
Expand Down Expand Up @@ -396,6 +400,10 @@ static cvarTable_t cvarTable[] = {
{ &cg_teamModel, "cg_teamModel", "", CVAR_ARCHIVE},
{ &cg_teamColors, "cg_teamColors", "", CVAR_ARCHIVE},
{ &cg_deadBodyDarken, "cg_deadBodyDarken", "0", CVAR_ARCHIVE},
//
{ &cg_damagePlum, "cg_damagePlum", "1", CVAR_USERINFO | CVAR_ARCHIVE},
{ &cg_damagePlumStyle, "cg_damagePlumColorStyle", "1", CVAR_USERINFO | CVAR_ARCHIVE},
{ &cg_damagePlumSize, "cg_damagePlumSize", "8", CVAR_USERINFO | CVAR_ARCHIVE},
// { &cg_pmove_fixed, "cg_pmove_fixed", "0", CVAR_USERINFO | CVAR_ARCHIVE }
};

Expand Down
3 changes: 2 additions & 1 deletion code/game/bg_public.h
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,8 @@ typedef enum {
EV_TAUNT_FOLLOWME,
EV_TAUNT_GETFLAG,
EV_TAUNT_GUARDBASE,
EV_TAUNT_PATROL
EV_TAUNT_PATROL,
EV_DAMAGEPLUM

} entity_event_t;

Expand Down
8 changes: 8 additions & 0 deletions code/game/g_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,14 @@ void ClientUserinfoChanged( int clientNum ) {
} else {
client->pers.predictItemPickup = qtrue;
}
// client damageplums

s = Info_ValueForKey( userinfo, "cg_damagePlum" );
if ( !atoi( s ) ) {
client->pers.damagePlums = 0;
} else {
client->pers.damagePlums = atoi( s );
}

// set name
Q_strncpyz ( oldname, client->pers.netname, sizeof( oldname ) );
Expand Down
Loading

0 comments on commit 6e85764

Please sign in to comment.