Quake Style - Quake 3 Tutorials
Code Helpers - FindRadius for Quake 3
A useful function which will find entities around a certain object!

If you are an experienced programmer, you may remember this function from Quake 2. Since it wasn't in Quake 3, and there is use for it, I decided to write a tutorial to put it in.

Open up g_utils.c, and go down to the bottom of the file. Pop this function right in there:

// (NOBODY): Code helper function
gentity_t *findradius (gentity_t *from, vec3_t org, float rad)
	vec3_t	eorg;
	int		j;

	if (!from)
		from = g_entities;

	for (; from < &g_entities[level.num_entities]; from++)
		if (!from->inuse)
		for (j=0; j<3; j++)
			eorg[j] = org[j] - (from->r.currentOrigin[j] + (from->r.mins[j] + from->r.maxs[j])*0.5);
		if (VectorLength(eorg) > rad)
		return from;

	return NULL;

That's almost it. Next, open up g_local.h and put this line down the end of the file:

gentity_t *findradius (gentity_t *from, vec3_t org, float rad);

That's there simply so that every file (well, atleast ones which include g_local.h :) will be able to call this function.

Enjoy. Expect a homing missile tutorial any day now :)

-- Credits:
   Tutorial by (nobody)
   Return to QS Tutorials

-- Important:
   If you do use something from QuakeStyle in your mod, please give us credit.
   Our code is copyrighted, but we give permission to everyone to use it in any way they see fit, as long as we are recognized.