QuakeZone
MOD Coding Tutorials
Quake II Coding Tutorials!

Introduction
Code
Notes
Exercises
Quake II Coding Tutorials

Status Bar Tutorial

Introduction Introduction

This tutorial demonstrates how to display currently selected rocket type (standard, nuclear, etc) and fire mode (standrad, homing, etc) on the status bar on the player's Head-Up Display, or HUD.

This tutorial supplements the tutorials on nuclear rockets and blister rockets, which show how to implement different rocket types and fire modes respectively.

Code Code


g_local.h

Make sure the folloiwng fields exist at the end of structure client_persistant_t:
	qboolean    nuke_state;	                // PJT - nuke rocket state
	qboolean    homing_state;		// PJT - homing missile state
	qboolean    blister_state;		// PJT - blister rocket state
	qboolean    multi_state;		// PJT - multiple rockets	

q_shared.h

Add the following defines at the indicated position file:
#define STAT_SPECTATOR	        17		// <-- insert after here
#define STAT_ROCKET_STRING      18		// PJT - rocket type string
#define STAT_FIREMODE_MULTI     19		// PJT - rocket fire mode - multiple
#define STAT_FIREMODE_HOMING    20		// PJT - rocket fire mode - homing
#define STAT_FIREMODE_BLISTER   21		// PJT - rocket fire mode - blister
Then a further define at the next indicated location:
#define MAX_CONFIGSTRINGS	(CS_GENERAL+MAX_GENERAL)	// <-- insert after here
#define CS_TR_STRINGS       	(CS_ITEMS+200)			// PJT - HUD strings

p_hud.c

Add the following statement at the end of procedure G_SetStats:
	// PJT - new Hud
	update_hud_rockets(ent);
Then add the folloing code at the end of the file:
// PJT - new HUD (TR 1.1.0)
void update_hud_rockets (edict_t *ent)
{

	//1. set rocket type
	if (ent->client->pers.nuke_state > 4)	// 4 is number of different rocket types
	   ent->client->pers.nuke_state = 0;
	ent->client->ps.stats[STAT_ROCKET_STRING] = CS_TR_STRINGS + ent->client->pers.nuke_state;

	//2. set fire mode

	//   : homing missiles
	if (ent->client->pers.homing_state == 1)
		ent->client->ps.stats[STAT_FIREMODE_HOMING] 	= CS_TR_STRINGS + 21;
	else
		ent->client->ps.stats[STAT_FIREMODE_HOMING] 	= CS_TR_STRINGS + 20;

	//   : multi rockets
	if (ent->client->pers.multi_state == 1)
		ent->client->ps.stats[STAT_FIREMODE_MULTI] 	= CS_TR_STRINGS + 22;
	else
		ent->client->ps.stats[STAT_FIREMODE_MULTI] 	= CS_TR_STRINGS + 20;

	//    : blister rockets
	if (ent->client->pers.blister_state == 1)
		ent->client->ps.stats[STAT_FIREMODE_BLISTER] 	= CS_TR_STRINGS + 23;
	else
		ent->client->ps.stats[STAT_FIREMODE_BLISTER] 	= CS_TR_STRINGS + 20;

	//    : new fire modes can be inserted here 

}

// PJT - new HUD - define HUD strings
void init_hud_rocket_strings(void)
{
	// rocket type names
	gi.configstring (CS_TR_STRINGS +0, "Standard   ");
	gi.configstring (CS_TR_STRINGS +1, "Nuke       ");
	gi.configstring (CS_TR_STRINGS +2, "Gas        ");
	gi.configstring (CS_TR_STRINGS +3, "Positron   ");
	gi.configstring (CS_TR_STRINGS +4, "Earthquake ");
	// add configstring statements for new rocket types here

	// rocket fire modes
	gi.configstring (CS_TR_STRINGS +20, "    ");
	gi.configstring (CS_TR_STRINGS +21, "Hom ");
	gi.configstring (CS_TR_STRINGS +22, "Mul ");
	gi.configstring (CS_TR_STRINGS +23, "Bli ");
	// add configstring statements for new fire modes here
}
// PJT

g_spawn.c

Add the following lines to the end of the definitions of both single_statusbar and dm_statusbar:
// PJT - rocket type(18)

  "xv 0 "
  "yb -68 "
  "string \"Rocket\" "
  "xv 64 "
  "stat_string 18 "

// PJT - fire modes multi(19) homing(20) blister(21)
  "xv 250 "
  "string \"Mode  \" "
  "xv 314 "
  "stat_string 19 "
  "xv 346 "
  "stat_string 20 "
  "xv 378 "
  "stat_string 21 "

// PJT
Then, in procedure SP_worldspawn, add the following code at indicated position:
	// set configstrings for items
	SetItemNames ();

	// PJT - set configstrings for team rocket HUD (see p_hud.c)
	init_hud_rocket_strings();


Notes Notes to code


g_local.h
  • in structure client_persistant_t, nuke_state indicates the currently selected rocket type
  • the other fields indicate the status of the different fire modes

q_shared.h
  • explanation of the first group of defines:
    • each client has a stats array (called ent->client->ps.stats[]) that is an array of statistics used by the HUD (for example health and frags are stored on this array)
    • this array currently has 32 'slots'
    • these slots can either be counters (eg frags or health) or pointers into a string array (see below)
    • these defines reserve 1 'slot' to show rocket type and 3 'slots' for the different fire modes
  • explanation of the second define:
    • within the game structure (gi) there is an array of strings which can be displayed on the status bar (although Quake does use it for other purposes as well)
    • these strings are pointed to by the p.stats[] array - see above
    • the array of strings is divided into ranges (sounds, images, lights, etc)
    • the second define reserves a sub-range of the item strings for our purposes (200 through 256 to be exact). So long as the number of different items in the game does not exceed 200 (items are defined in g_items.c) we should be alright.

p_hud.c
  • procedure G_SetStats is called every Quake frame to update the stats on a player's HUD:
    • the call to update_hud_rockets makes sure the rocket type and firemode are always displayed
  • procedure update_hud_rockets displays rocket type and fore modes:
    • pre-defined strings set up in procedure init_hud_rocket_strings below are pointed to for rocket type and fire modes
    • inactive fire modes are hidden by pointing to emptry string
    • insert code in this procedure to indicate more rocket types and fire modes
  • procedure init_hud_rocket_strings sets up the pre-defined strings for our HUD display:
    • it is called by procedure SP_worldspawn once per game in g_spawn.c
    • restricted to range we defined in q_shared.c
    • "slots" 0 to 19 are reserved for rocket types
    • "slots" 20 to 39 are reserved for fire modes (20 is blank string)
    • remaining slots 40 to 56 are reserved for future use

q_spawn.c
  • the 2 status_bar character strings are used by the internal Quake interface for dislaying icons, strings and numbers on the player's status bar:
    • a more detailed explanation of this interface can be found in the QDevels tutorials (go to the Tutorials Links page)
    • the numbers refer to the "slots" we've reserved in the client's ps.stats[] array
    • 18 is for the rocket type, and 19 to 21 are the fire modes
  • procedure SP_worldspawn is called at the start of every game:
    • procedure init_hud_rocket_strings, in p_hud.c, is called to initialise the pre-defined strings for our HUD
Exercises Exercises

  • add your own rocket types and fire modes to the status bar


Page last updated 26th October 2000