Oak Tutorial

Back to Tutorials

Next Lesson

 

Oak Toturial 2: Spawning continued

Lesson Requirements
A C compiler, and the Quake2 Source code

Instructions on using the LCCWin32 Compiler.

Lesson Summary
More on spawning a bot in Quake2. This builds on th first tutorial.

Lesson

Ok this tutorial is based on how I`ve been writing my bot. We`ll fill in the pain and death functions first and then look at animation. NOTE you can not cut and paste this code from HTML!

Ok do you remember these lines from the spawn function?

	// think functions
	newOak->pain = oak_pain;
	newOak->die = oak_die;
They set what functions the engine will run if the entity suffers pain and dies. So firstly lets have a pain function:
void oak_pain (edict_t *self, edict_t *other, float kick, int damage)
{
	OakAI_RunFrames(self, FRAME_pain101, FRAME_pain104);
}

Ok the parameters this takes are dicated by the existing code layout. The engine is execting to call a function with the specified parameters. I have as yet not coded my pain function beyond running the pain frames. Hence the above code simply calls my function OakAI_RunFrames which plays a set animation. The first paramter is a pointer to the entity to animate the second and third being the start and end of the animation sequence, these are simply integers defined in m_player.h.

Next we need a death function:

void oak_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
{
	gi.sound (self, CHAN_BODY, gi.soundindex ("misc/udeath.wav"), 1, ATTN_NORM, 0);
	for (i= 0; i < 4; i++)
		ThrowGib (self, "models/objects/gibs/sm_meat/tris.md2", damage, GIB_ORGANIC);
	self->takedamage = DAMAGE_NO;

	// respawn the bot
	OAK_Respawn(self);
}

This function is not complete as yet, so far the bots will only gib, not run the actual death sequences. The death function also calls a respawn fuction which is essentially a cut down version of the SP_Oak function.

void OAK_Respawn(edict_t *self)
{
	vec3_t	spawn_origin, spawn_angles;

	// spawn the bot on a spawn spot
	SelectSpawnPoint(spawn_origin, spawn_angles);
	VectorCopy (spawn_origin, self->s.origin);
	self->s.origin[2] += 1;	// make sure off ground

	self->deadflag = DEAD_NO;

	self->s.frame = 0;
	self->waterlevel = 0;
	self->watertype = 0;
	self->health = 100;

	self->pain = oak_pain;
	self->die = oak_die;

	VectorSet(self->mins, -16, -16, -24);
	VectorSet(self->maxs, 16, 16, 32);
	VectorClear(self->velocity);

	gi.linkentity(self);
}
Finally you`ll need the function to run the animation frames:
void OakAI_RunFrames(edict_t *self, int start, int end)
{
	if (self->s.frame < end)
	{
		self->s.frame++;
	}
	else 
	{
		self->s.frame = start;
	}

}

Ok if you compile that code in with the id and earlier oak code you can then spawn a bot by typing cmd oak in the console. Remember you must run quake with the command line:

quake2 +set game oak

Assuming you put the new gamex86.dll in the dir called oak.

 

Back to Tutorials

Next Lesson


Copyright © 1997, John Crickett.
Legal Information