QuakeZone
MOD Coding Tutorials
Quake II Coding Tutorials!

Introduction
Code
Notes
Exercises
Quake II Coding Tutorials

Turbo Armour

Introduction Introduction

This tutorial shows you how to add Lox-style regenerative organic armour to your mod. When you pick up an armour item, you have a small chance of it being turbo armour. When it is, your armour quickly ramps up to 500, and when you take damage this value is quickly restored.

Code Code


g_local.h

At the end of the client_persistant_t struct, add the following line:

	qboolean	turbo_armour;		// PJT - turbo armour

g_items.c

Add the following lines the top of this file as indicated:
	
#define HEALTH_TIMED		2
#define TURBO_ARMOUR_HIT    	0.1		// PJT - turbo armour 0.5 for testing 0.1 is default
Add the following lines to procedure Pickup_Armor as indicated in the following places:
	
	float			salvage;
	int			salvagecount;

	// PJT - turbo armour
	if (other->client->pers.turbo_armour)
		return false;
	// PJT

	....

	// if player has no armor, just use it
	else if (!old_armor_index)
	{
		// PJT - turbo armour
		if (random() < TURBO_ARMOUR_HIT)
		{
			gi.cprintf (other, PRINT_HIGH, "Regeneration turbo-armour picked up\n");
			other->client->pers.turbo_armour = true;
			if (!(ent->spawnflags & DROPPED_ITEM) && (deathmatch->value))
				SetRespawn (ent, 20);
			return true;
		}
		// PJT
		other->client->pers.inventory[ITEM_INDEX(ent->item)] = newinfo->base_count;

	....

			// PJT - turbo armour
			if (random() < TURBO_ARMOUR_HIT)
			{
				gi.cprintf (other, PRINT_HIGH, "Regeneration turbo-armour picked up\n");
				other->client->pers.turbo_armour = true;
				if (!(ent->spawnflags & DROPPED_ITEM) && (deathmatch->value))
					SetRespawn (ent, 20);
				return true;
			}
			// PJT

	....

			// if we're already maxed out then we don't need the new armor
			if (other->client->pers.inventory[old_armor_index] >= newcount)
				return false;

			// PJT - turbo armour
			if (random() < TURBO_ARMOUR_HIT)
			{
				gi.cprintf (other, PRINT_HIGH, "Regeneration turbo-armour picked up\n");
				other->client->pers.turbo_armour = true;
				if (!(ent->spawnflags & DROPPED_ITEM) && (deathmatch->value))
					SetRespawn (ent, 20);
				return true;
			}
			// PJT


p_client.c

Add the following code as indicated into function ClientThink:

	level.current_entity = ent;
	client = ent->client;

	// PJT - turbo armour
	if ((!ent->deadflag) && (client->pers.turbo_armour) && (client->pers.inventory[jacket_armor_index] < 500))
		client->pers.inventory[jacket_armor_index] += 1;
	// PJT
Notes Notes to code


g_local.h
  • a flag in the client structure to indicate ownership of the turbo armour.
  • note that this is in the persistant part of the client structure, and turbo armour will be retained across game loads

g_items.c
  • this code gives the player turbo armour at random when picking up armour (0.1 chance)
  • if player already has turbo armour, he cannot pick up any more armour
  • when turbo armour is picked up, following happens:
    • a message is sent to player
    • turbo armour flag is set
    • item re-spawn is set if necessary, and return true to incidate successful pick up of an armour item
  • note that the turbo armour pick up code is in 3 places in this procedure. This is because of the more complex structure of armour (i.e. different types) compared to health pick-up.

p_client.c
  • the ClientThink routine processes a client every Quake frame
  • if a player is not dead, has turbo armour and jacket armour (the most powerful type) is less than 500, increments player armour - this quickly restores player armour to 500 when damage taken
Exercises Exercises

  • replace the turbo armour switch in the client structure as an item that is given to the player, so turbo armour can be seen in the inventory


Page last updated 25th October 2000