|
QuakeZone MOD Coding Tutorials
|
|
|
Introduction Code Notes Exercises |
|
| Introduction |
|
|
This tutorial describes how to add blister rockets to your mod. First of all, the player toggles the bister state on with a button. He/she then fires a rocket, and when he/she presses another key, the 'blister' key, the rocket divides up into 4 that fly off in the 4 compass points. This tutorial also describes how to generically add different rocket firing modes, and to cater for the different number of rockets that might be required. For this purpose, the code from the tutorial on Rocket Types must already have been implemented. |
| Code |
|
|
g_local.h Add the following line to the end of the client_persistant_t struct: qboolean blister_state; // PJT - blister rocket stateAdd the following line to the end of the gclient_s struct: qboolean blister; // PJT blister command made: 1=YES, 0=NOAdd the following line to the end of the edict_s struct: qboolean can_blister; // PJT - blister rockets g_weapon.c Add the following variables to start of procedure rocket_think: vec3_t forward, backward, right, left, up; // PJT - vectors for blister qboolean tmp; // PJT - blister - store client stateThen add the following code to the end of procedure rocket_think:
// PJT - blister rocket
if (!self->owner) return;
if (!self->owner->client) return;
if ((self->owner->client->blister) && (self->can_blister))
{
// define vectors for 4 compass points
VectorSet(forward,0,1,0);
VectorSet(right,1,0,0);
VectorSet(backward,0,-1,0);
VectorSet(left,-1,0,0);
self->can_blister = false;
// create 4 new missiles in other 4 compass points
// future change - add small random variation for more realism
tmp = self->owner->client->pers.blister_state;
self->owner->client->pers.blister_state = false; // stop child rockets from blistering
fire_rocket(self->owner, self->s.origin, forward, 100, 30, 120, 120);
fire_rocket(self->owner, self->s.origin, right, 100, 30, 120, 120);
fire_rocket(self->owner, self->s.origin, left, 100, 30, 120, 120);
fire_rocket(self->owner, self->s.origin, backward, 100, 30, 120, 120);
self->owner->client->pers.blister_state = tmp;
// dont forget to turn blister command off!
self->owner->client->blister = false;
// destroy original rocket
G_FreeEdict (self);
}
// PJT
Then, in procedure fire_rocket, add the following code at the indicated location:
rocket->s.modelindex = gi.modelindex ("models/objects/rocket/tris.md2");
// PJT blister rockets - for clients only
rocket->can_blister = 0;
if (self->client)
rocket->can_blister = self->client->pers.blister_state; // PJT - only 'parent' rockets can blister
// PJT
p_weapon.c In procedure Rocket_Count (which was created in the Nuclear Rockets/Rocket Types tutorial), add the following code at the indicated location:
// rockets for particular type
count = 1;
switch (ent->client->pers.nuke_state)
{
case 0: // standard
count = 1;
break;
case 1: // nukes
count = 20;
break;
// any other rocket types added here
}
// rockets for each fire mode
if (ent->client->pers.blister_state) count *= 4; // PJT - blister rockets
// add rocket multipliers for other rocket fire modes here, to determine
// whether player has enough rockets
Add the following code at the start of procedure Weapon_RocketLauncher_Fire as indicated:
ent->client->blister = 0; // PJT blister rockets damage = 100 + (int)(random() * 20.0); g_cmds.c In procedure ClientCommand add the following lines near the end of the procedure at the indicated location: // PJT - blister rockets: 1. set blister status else if (Q_stricmp (cmd, "blister_on") == 0) Cmd_Blister_on_f (ent); // 2. issue blister command else if (Q_stricmp (cmd, "blister") == 0) Cmd_Blister_f (ent); // PJT else if (Q_stricmp (cmd, "gameversion") == 0) gi.cprintf (ent, PRINT_HIGH, "%s : %s\n", GAMEVERSION, __DATE__);Then, at the end of the file, add the following code:
//PJT blister missiles
/*
=================
Cmd_Blister_on_f
PJT: whole new function for adjusting blister missile state
=================
*/
void Cmd_Blister_on_f (edict_t *ent)
{
int i;
i = ent->client->pers.blister_state;
switch (i)
{
case 1:
ent->client->pers.blister_state = 0;
break;
case 0:
default:
ent->client->pers.blister_state = 1;
break;
}
}
// PJT
/*
=================
Cmd_Blister_on_f
PJT: whole new function for adjusting blister missile state
=================
*/
void Cmd_Blister_f (edict_t *ent)
{
int i;
i = ent->client->pers.blister_state;
switch (i)
{
case 0:
gi.cprintf (ent, PRINT_HIGH, "Blister missiles are not enabled\n");
break;
case 1:
default:
ent->client->blister = 1;
break;
}
}
// PJT
Finally bind keys to "blister_on" and "blister" while playing, or add the binds to your .cfg file.
To activate blister status, press the key bound to "blister_on". To blister a rocket in flight,
press the key bound to "blister".
|
| Notes |
|
|
g_local.h
g_weapon.c
p_weapon.c
g_cmds.c
Different Fire Modes
|
| Exercises |
|
|