Skip to content

Commit

Permalink
cgame: Encapsulate debris and spark particles explosions into functio…
Browse files Browse the repository at this point in the history
…ns and apply these correctly in some weapons
  • Loading branch information
LegendaryGuard committed Sep 24, 2024
1 parent b3dcf91 commit 10a0d88
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 60 deletions.
14 changes: 14 additions & 0 deletions source/cgame/cg_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -871,18 +871,28 @@ void CG_EntityEvent( centity_t *cent, vec3_t position ) {
DEBUGNAME("EV_MISSILE_HIT");
ByteToDir( es->eventParm, dir );
CG_MissileHitPlayer( es->weapon, position, dir, es->otherEntityNum );
// BFP - Spark particles explosion
CG_SparksExplosion( position, dir );
break;

case EV_MISSILE_MISS:
DEBUGNAME("EV_MISSILE_MISS");
ByteToDir( es->eventParm, dir );
CG_MissileHitWall( es->weapon, 0, position, dir, IMPACTSOUND_DEFAULT );
// BFP - Debris particles explosion
CG_DebrisExplosion( position, dir );
// BFP - Spark particles explosion
CG_SparksExplosion( position, dir );
break;

case EV_MISSILE_MISS_METAL:
DEBUGNAME("EV_MISSILE_MISS_METAL");
ByteToDir( es->eventParm, dir );
CG_MissileHitWall( es->weapon, 0, position, dir, IMPACTSOUND_METAL );
// BFP - Debris particles explosion
CG_DebrisExplosion( position, dir );
// BFP - Spark particles explosion
CG_SparksExplosion( position, dir );
break;

// BFP - TODO: Implement EV_MISSILE_DETONATE (it has been used on ki grenade bounces and ki disc, that happens when these explode after some time)
Expand All @@ -898,6 +908,10 @@ void CG_EntityEvent( centity_t *cent, vec3_t position ) {
if ( es->eventParm != 255 ) {
ByteToDir( es->eventParm, dir );
CG_MissileHitWall( es->weapon, es->clientNum, position, dir, IMPACTSOUND_DEFAULT );
// BFP - Debris particles explosion
CG_DebrisExplosion( position, dir );
// BFP - Spark particles explosion
CG_SparksExplosion( position, dir );
}
break;

Expand Down
4 changes: 4 additions & 0 deletions source/cgame/cg_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -1222,6 +1222,10 @@ void CG_MissileHitWall( int weapon, int clientNum, vec3_t origin, vec3_t dir, im
void CG_MissileHitPlayer( int weapon, vec3_t origin, vec3_t dir, int entityNum );
void CG_ShotgunFire( entityState_t *es );
void CG_Bullet( vec3_t origin, int sourceEntityNum, vec3_t normal, qboolean flesh, int fleshEntityNum );
// BFP - Debris particles explosion
void CG_DebrisExplosion( vec3_t origin, vec3_t dir );
// BFP - Spark particles explosion
void CG_SparksExplosion( vec3_t origin, vec3_t dir );

void CG_RailTrail( clientInfo_t *ci, vec3_t start, vec3_t end );
void CG_GrappleTrail( centity_t *ent, const weaponInfo_t *wi );
Expand Down
143 changes: 83 additions & 60 deletions source/cgame/cg_weapons.c
Original file line number Diff line number Diff line change
Expand Up @@ -1465,6 +1465,87 @@ void CG_FireWeapon( centity_t *cent ) {
}
}

/*
=================
CG_DebrisExplosion
=================
*/
void CG_DebrisExplosion( vec3_t origin, vec3_t dir ) { // BFP - Debris particles explosion
int i;
// spawn randomly the shaders with the particles
int shaderIndex;
vec3_t sprOrg, sprVel;

// BFP - NOTE: Debris particles shouldn't be used for bullet and disk weapon types

for ( i = 0; i < 26; ++i ) {
shaderIndex = rand() % 3;

// that would be the range for debris particles
VectorMA( origin, 24, dir, sprOrg );
sprOrg[0] += (rand() % 24);
sprOrg[1] += (rand() % 24);
sprOrg[2] += (rand() % 24);

VectorScale( dir, 1500 + (rand() % 1000), sprVel );
sprVel[0] += (rand() % 2800) - 1500;
sprVel[1] += (rand() % 2800) - 1500;
sprVel[2] += (rand() % 2200) - 1000;

switch ( shaderIndex ) {
case 0: {
CG_ParticleDebris( cgs.media.pebbleShader1, sprOrg, sprVel, qfalse );
break;
}
case 1: {
CG_ParticleDebris( cgs.media.pebbleShader2, sprOrg, sprVel, qfalse );
break;
}
default: {
CG_ParticleDebris( cgs.media.pebbleShader3, sprOrg, sprVel, qfalse );
}
}
}
}

/*
=================
CG_SparksExplosion
=================
*/
void CG_SparksExplosion( vec3_t origin, vec3_t dir ) { // BFP - Spark particles explosion
int i;
// spawn randomly the shaders with the particles
int shaderIndex;
vec3_t sparkOrg, sparkVel;

// BFP - NOTE: Spark particles shouldn't be used on bullet and disk weapon types

// BFP - TODO: Apply calling this function for finger blast and these rail gun weapon types when hitting a player

for ( i = 0; i < 26; ++i ) {
shaderIndex = (rand() % 100) < 50 ? 0 : 1; // if the random range was rand() % 2, it would repeat the pattern without randomize correctly

VectorMA( origin, 10, dir, sparkOrg );

// move faster
VectorScale( dir, 1500 + (rand() % 1000), sparkVel );
sparkVel[0] += 1.5 * (rand() % 3500) - 1500;
sparkVel[1] += 1.5 * (rand() % 3500) - 1500;
sparkVel[2] += 1.5 * (rand() % 2100) - 1000;

switch ( shaderIndex ) {
case 0: {
CG_ParticleSparks( cgs.media.sparkShader1, sparkOrg, sparkVel );
break;
}
default: {
CG_ParticleSparks( cgs.media.sparkShader2, sparkOrg, sparkVel );
}
}
}
}


/*
=================
Expand All @@ -1484,8 +1565,6 @@ void CG_MissileHitWall( int weapon, int clientNum, vec3_t origin, vec3_t dir, im
int r;
qboolean isSprite;
int duration;
vec3_t sprOrg;
vec3_t sprVel;

// BFP - NOTE: Crack mark shader replaces all other mark shaders, the radius is the same (64), there's no alpha fade

Expand Down Expand Up @@ -1533,64 +1612,7 @@ void CG_MissileHitWall( int weapon, int clientNum, vec3_t origin, vec3_t dir, im
lightColor[1] = 0.75;
lightColor[2] = 0.0;
// BFP - cg_oldRocket is unused on BFP, they forgot to remove
//if (cg_oldRocket.integer == 0)
{
int i, j;
// BFP - Spawn randomly the shaders with the particles
int shaderIndex;
vec3_t sparkOrg, sparkVel;

for ( i = 0; i < 26; ++i ) {
shaderIndex = (rand() % 100) < 50 ? 0 : 1; // if the random range was rand() % 2, it would repeat the pattern without randomize correctly

VectorMA( origin, 10, dir, sparkOrg );

// move faster
VectorScale( dir, 1500 + (rand() % 1000), sparkVel );
sparkVel[0] += 1.5 * (rand() % 3500) - 1500;
sparkVel[1] += 1.5 * (rand() % 3500) - 1500;
sparkVel[2] += 1.5 * (rand() % 2100) - 1000;

switch ( shaderIndex ) {
case 0: {
CG_ParticleSparks( cgs.media.sparkShader1, sparkOrg, sparkVel );
break;
}
default: {
CG_ParticleSparks( cgs.media.sparkShader2, sparkOrg, sparkVel );
}
}
}

for ( j = 0; j < 26; ++j ) {
shaderIndex = rand() % 3;

// BFP - That would be the range for debris particles
VectorMA( origin, 24, dir, sprOrg );
sprOrg[0] += (rand() % 24);
sprOrg[1] += (rand() % 24);
sprOrg[2] += (rand() % 24);

VectorScale( dir, 1500 + (rand() % 1000), sprVel );
sprVel[0] += (rand() % 2800) - 1500;
sprVel[1] += (rand() % 2800) - 1500;
sprVel[2] += (rand() % 2200) - 1000;

switch ( shaderIndex ) {
case 0: {
CG_ParticleDebris( cgs.media.pebbleShader1, sprOrg, sprVel, qfalse );
break;
}
case 1: {
CG_ParticleDebris( cgs.media.pebbleShader2, sprOrg, sprVel, qfalse );
break;
}
default: {
CG_ParticleDebris( cgs.media.pebbleShader3, sprOrg, sprVel, qfalse );
}
}
}
}
//if (cg_oldRocket.integer == 0) {}
break;
case WP_RAILGUN:
mod = cgs.media.ringFlashModel;
Expand Down Expand Up @@ -1651,6 +1673,7 @@ void CG_MissileHitWall( int weapon, int clientNum, vec3_t origin, vec3_t dir, im
//
// impact mark
//
// BFP - TODO: Disk type weapons don't leave a mark, apply it
CG_ImpactMark( cgs.media.crackMarkShader, origin, dir, random()*360, 1,1,1,1, 0, radius, qfalse );
}

Expand Down

0 comments on commit 10a0d88

Please sign in to comment.