Quake DeveLS - Triple Blaster

Author: SumFuka
Difficulty: Easy

DON'T SAY I DIDNT WARN YOU !!!!

Bring on the weapons ! Open up p_weapon.c. I reckon we'll do a triple blaster... change your Weapon_Blaster_Fire function to look like this :

 
void Weapon_Blaster_Fire (edict_t *ent)
{
	int		damage;
	// STEVE
	vec3_t tempvec;

	if (deathmatch->value)
		damage = 15;
	else
		damage = 10;
	Blaster_Fire (ent, vec3_origin, damage, false, EF_BLASTER);

	// STEVE : add 2 new bolts below
	VectorSet(tempvec, 0, 8, 0);
	VectorAdd(tempvec, vec3_origin, tempvec);
	Blaster_Fire (ent, tempvec, damage, false, EF_BLASTER);

	VectorSet(tempvec, 0, -8, 0);
	VectorAdd(tempvec, vec3_origin, tempvec);
	Blaster_Fire (ent, tempvec, damage, false, EF_BLASTER);

	ent->client->ps.gunframe++;
}
What did we do there ? Well, we created a temporary vector of simply 8 units in the y direction (this is to your right in the quake2 world). We then use this offset to fire a second blaster bolt to the right of the center one. Ditto on the left hand side (offset is -8).

Notice how I have used the VectorSet and VectorAdd functions ? look in q_shared.h to see how these and other vector functions work.

More laser bolts, please !

Now lets do a triple hyperblaster !!! This thing will really chew up ammo, but anyone on the other side of your crosshaire is going to end up atomic-fried-chicken. Find the function Weapon_HyperBlaster_Fire and replace it with this one :

 
void Weapon_HyperBlaster_Fire (edict_t *ent)
{
	float	rotation;
	vec3_t	offset;
	int		effect;

	ent->client->weapon_sound = gi.soundindex("weapons/hyprbl1a.wav");

	if (!(ent->client->buttons & BUTTON_ATTACK))
	{
		ent->client->ps.gunframe++;
	}
	else
	{
		if (! ent->client->pers.inventory[ent->client->ammo_index] )
		{
			if (level.time >= ent->pain_debounce_time)
			{
				gi.sound(ent, CHAN_VOICE, gi.soundindex("weapons/noammo.wav"), 1, ATTN_NORM, 0);
				ent->pain_debounce_time = level.time + 1;
			}
			NoAmmoWeaponChange (ent);
		}
		else
		{
			// STEVE .... the lines below are new !
			// ...........TRIPLE HYPER BLASTER !!!

			if ((ent->client->ps.gunframe == 6) || (ent->client->ps.gunframe == 9))
				effect = EF_HYPERBLASTER;
			else
				effect = 0;

			// change the offset radius to 6 (from 4), spread the bolts out a little
			rotation = (ent->client->ps.gunframe - 5) * 2*M_PI/6;
			offset[0] = 0;
			offset[1] = -8 * sin(rotation);
			offset[2] = 8 * cos(rotation);
			Blaster_Fire (ent, offset, 20, true, effect);

			// fire a second blast at a different rotation
			rotation = (ent->client->ps.gunframe - 5) * 2*M_PI/6 + M_PI*2.0/3.0;
			offset[0] = 0;
			offset[1] = -8 * sin(rotation);
			offset[2] = 8 * cos(rotation);
			Blaster_Fire (ent, offset, 20, true, effect);

			// fire a third blast at a different rotation
			rotation = (ent->client->ps.gunframe - 5) * 2*M_PI/6 + M_PI*4.0/3.0;
			offset[0] = 0;
			offset[1] = -8 * sin(rotation);
			offset[2] = 8 * cos(rotation);
			Blaster_Fire (ent, offset, 20, true, effect);
			// deduct 3 times the amount of ammo as before (... the *3 on end)
			ent->client->pers.inventory[ent->client->ammo_index] -= ent->client->pers.weapon->quantity * 3;
		}

		ent->client->ps.gunframe++;
		if (ent->client->ps.gunframe == 12 && ent->client->pers.inventory[ent->client->ammo_index])
			ent->client->ps.gunframe = 6;
	}

	if (ent->client->ps.gunframe == 12)
	{
		gi.sound(ent, CHAN_AUTO, gi.soundindex("weapons/hyprbd1a.wav"), 1, ATTN_NORM, 0);
		ent->client->weapon_sound = 0;
	}

}
What does it do ? Well this line from the original code...
rotation = (ent->client->ps.gunframe - 5) * 2*M_PI/6;
... it rotates the blast in 60 degree increments around a full circle in time with the gun animation (which has 6 frames). We are simply adding two more blasts evenly spaced around the circle at 120 degrees and 240 degrees, or pi*2/3 and pi*4/3.

(Note that id got it wrong, and were rotating in the x/z axis, I changed it to rotate in the y/z axis, must've been Brian who wrote this bit eh John ?).

Well that's it ! Get the Hyperblaster and ROCK and ROLL ! I'll leave it up to you budding Q2 programmers to make a triple RL and triple GL.

Next week... bouncy bouncy.

Tutorial by SumFuka


This site, and all content and graphics displayed on it,
are ©opyrighted to the Quake DeveLS team. All rights received.
Got a suggestion? Comment? Question? Hate mail? Send it to us!
Oh yeah, this site is best viewed in 16 Bit or higher, with the resolution on 800*600.
Thanks to Planet Quake for there great help and support with hosting.
Best viewed with Netscape 4 or IE 3