Home of Gravity Quake


News About Files Tutorials Screenshots


#1-Shadow/Haste Trail



Old Code
New Code

This tutorial will show how to change the dinky haste smoke trail into a shadow trail. First, open up cg_players.c and go down to CG_HasteTrail, around line 1012. Here's what it starts out as...

static void CG_HasteTrail( centity_t *cent ) {
	localEntity_t	*smoke;
	vec3_t			origin;
	int				anim;

	if ( cent->trailTime > cg.time ) {
		return;
	}
	anim = cent->pe.legs.animationNumber & ~ANIM_TOGGLEBIT;
	if ( anim != LEGS_RUN && anim != LEGS_BACK ) {
		return;
	}

	cent->trailTime += 100;
	if ( cent->trailTime < cg.time ) {
		cent->trailTime = cg.time;
	}

	VectorCopy( cent->lerpOrigin, origin );
	origin[2] -= 16;

	smoke = CG_SmokePuff( origin, vec3_origin, 
				  8, 
				  1, 1, 1, 1,
				  500, 
				  cg.time,
				  0, 
				  cgs.media.hastePuffShader );

	// use the optimized local entity add
	smoke->leType = LE_SCALE_FADE;
}

Here's what we change it to...

static void CG_HasteTrail( centity_t *cent, refEntity_t *re, int bodyPart ) {

	localEntity_t	*le;

	if ( cent->trailTime > cg.time ) {
		return;
	}
 
	if ( bodyPart == 3 ) {
		cent->trailTime += 100;
		if ( cent->trailTime < cg.time ) {
			cent->trailTime = cg.time;
		}
	}

	le = CG_AllocLocalEntity();
	le->leFlags = 0;
	le->leType = LE_FADE_RGB;
	le->startTime = cg.time;
	le->endTime = cg.time + 300;
	le->lifeRate = 1.0 / ( le->endTime - le->startTime );
	VectorCopy( re->origin, le->pos.trBase );

	le->refEntity = *re;
}

Changed everything there, so I'll try to explain everyting quick.
First we setup a local entity le, which will will use here to hold the info for each part of the shadow trail.
If the ent's trailTime is grater than the "current time" than get out of CG_HasteTrail. Used to regulate timing.
If the current body part we are hadling is the last(#3) then advance trailTime by .1 sec. And if TrailTime is still less than the current time then set trailTime to current time. You may want to change the 3 if you are shadowing more than the head/torso/legs.
The next group of commands are used to get a new local entity, and set the info for it, should be somewhat self-explanitory.
Last, set the reference entity for the new local entity to re.

Next we have to change the call to CG_HasteTrail to add in the ew parameters we set up. Still in cg_players.c, goto line 1109 in CG_PlayerPowerups, and get rid of these three lines.


	// haste leaves smoke trails
	if ( powerups & ( 1 << PW_HASTE ) ) {
		CG_HasteTrail( cent );
	}

Calling CG_HasteTrail here would be impractical due to the new information it needs, a much better place is down at the end of CG_Player, line 1492, right after...

	//
	// add the gun / barrel / flash
	//
	CG_AddPlayerWeapon( &torso, NULL, cent );

add in the new calls...

	// XS:2/17/00  if dashing, set shaders and draw shadow trail
	if ( cent->currentState.powerups & ( 1 << PW_HASTE )) {
		legs.customShader = cgs.media.battleSuitShader;
		torso.customShader = cgs.media.battleSuitShader;
		head.customShader = cgs.media.battleSuitShader;

		CG_HasteTrail( cent, &legs, 1);
		CG_HasteTrail( cent, &torso, 2);
		CG_HasteTrail( cent, &head, 3);
}

This sets the shader effect to the battle suit for each of the 3 body parts, and then calls CG_HasteTrail with each part as a reference entity.

At this point if you went ahead and compiled it should work ok, and just add the new trail in when you have haste. 1