/* All the entity type stuff goes in here! */
#include "gameinc.h"

/* Strat include */
#include "strats.h"

static br_fmt_results *modelresults;
static br_fmt_results *modelresults2;
static br_fmt_results *modelresults3;
static br_model *bulletmodel;

void CreateBoom(p_E_Entity thisparent)
{
	p_E_Entity this;
	br_actor *scaleit;

	this = Entity_Create();
	this->identifier = 1;
	this->transform_type = ENTITY_TRANSFORM_FLAT;
	this->rootactor = BrActorAllocate(BR_ACTOR_NONE, NULL);

	scaleit = BrActorAllocate(BR_ACTOR_MODEL, NULL);
	scaleit->model = modelresults2->models[0];
	BrMatrix34Scale(&scaleit->t.t.mat, BR_SCALAR(0.4),BR_SCALAR(0.4),BR_SCALAR(0.4));
	BrActorAdd(this->rootactor,scaleit);

	scaleit = BrActorAllocate(BR_ACTOR_MODEL, NULL);
	scaleit->model = modelresults2->models[0];
	BrMatrix34Scale(&scaleit->t.t.mat, BR_SCALAR(0.2),BR_SCALAR(0.2),BR_SCALAR(0.2));
	BrMatrix34PreRotateY(&scaleit->t.t.mat, BR_ANGLE_DEG(-90.0));
	BrMatrix34PreRotateX(&scaleit->t.t.mat, BR_ANGLE_DEG(90.0));
	BrActorAdd(this->rootactor,scaleit);

	this->rootactor->t.type=BR_TRANSFORM_MATRIX34;
	BrMatrix34Copy(&this->worldpos,&thisparent->worldpos);
	BrMatrix34PreTranslate(&this->worldpos, BR_SCALAR(0.0), BR_SCALAR(40.0), BR_SCALAR(90.0));
	BrActorAdd(game_worldactor,this->rootactor);

	BrMatrix34Copy(&this->rootactor->t.t.mat,&this->worldpos);
	this->anim_callback = STRAT_BoomEntity;

	Entity_SendMessageToOne(ENTITY_MESSAGE_INSTANCE_STARTUP,this);
	this->linklist = LinkList_Add(entity_level_list,this);
}


void CreateBullet(p_E_Entity thisparent)
{
	p_E_Entity this;
	br_actor *scaleit;

	this = Entity_Create();
	this->identifier = 1;
	this->transform_type = ENTITY_TRANSFORM_FLAT;
	this->rootactor = BrActorAllocate(BR_ACTOR_NONE, NULL);
	scaleit = BrActorAllocate(BR_ACTOR_MODEL, NULL);
	scaleit->model = modelresults->models[0];
	BrMatrix34Scale(&scaleit->t.t.mat, BR_SCALAR(0.4),BR_SCALAR(0.4),BR_SCALAR(0.4));
	BrActorAdd(this->rootactor,scaleit);
	this->rootactor->t.type=BR_TRANSFORM_MATRIX34;
	BrMatrix34Copy(&this->worldpos,&thisparent->worldpos);
	BrMatrix34PreTranslate(&this->worldpos, BR_SCALAR(10.0), BR_SCALAR(70.0), BR_SCALAR(20.0));
	BrActorAdd(game_worldactor,this->rootactor);

	BrMatrix34Copy(&this->rootactor->t.t.mat,&this->worldpos);
	this->anim_callback = STRAT_NathanBulletEntity;

	Entity_SendMessageToOne(ENTITY_MESSAGE_INSTANCE_STARTUP,this);
	this->linklist = LinkList_Add(entity_level_list,this);
}


void CreateBulletSuper(p_E_Entity thisparent)
{
	p_E_Entity this;
	br_actor *scaleit;

	this = Entity_Create();
	this->identifier = 1;
	this->transform_type = ENTITY_TRANSFORM_FLAT;
	this->rootactor = BrActorAllocate(BR_ACTOR_NONE, NULL);
	scaleit = BrActorAllocate(BR_ACTOR_MODEL, NULL);
	scaleit->model = modelresults->models[0];
	BrMatrix34Scale(&scaleit->t.t.mat, BR_SCALAR(0.4),BR_SCALAR(0.4),BR_SCALAR(0.4));
	BrActorAdd(this->rootactor,scaleit);
	this->rootactor->t.type=BR_TRANSFORM_MATRIX34;
	this->rootactor->model = modelresults->models[0];
	BrMatrix34Copy(&this->worldpos,&thisparent->worldpos);
	BrMatrix34PreTranslate(&this->worldpos, BR_SCALAR(10.0), BR_SCALAR(70.0), BR_SCALAR(20.0));
	BrMatrix34PreRotateY(&this->worldpos, BR_ANGLE_DEG(-3.0));
	BrActorAdd(game_worldactor,this->rootactor);

	BrMatrix34Copy(&this->rootactor->t.t.mat,&this->worldpos);
	this->anim_callback = STRAT_NathanBulletEntity;

	Entity_SendMessageToOne(ENTITY_MESSAGE_INSTANCE_STARTUP,this);
	this->linklist = LinkList_Add(entity_level_list,this);



	this = Entity_Create();
	this->identifier = 1;
	this->transform_type = ENTITY_TRANSFORM_FLAT;
	this->rootactor = BrActorAllocate(BR_ACTOR_NONE, NULL);
	scaleit = BrActorAllocate(BR_ACTOR_MODEL, NULL);
	scaleit->model = modelresults->models[0];
	BrMatrix34Scale(&scaleit->t.t.mat, BR_SCALAR(0.4),BR_SCALAR(0.4),BR_SCALAR(0.4));
	BrActorAdd(this->rootactor,scaleit);
	this->rootactor->t.type=BR_TRANSFORM_MATRIX34;
	this->rootactor->model = modelresults->models[0];
	BrMatrix34Copy(&this->worldpos,&thisparent->worldpos);
	BrMatrix34PreTranslate(&this->worldpos, BR_SCALAR(10.0), BR_SCALAR(70.0), BR_SCALAR(20.0));
	BrMatrix34PreRotateY(&this->worldpos, BR_ANGLE_DEG(3.0));
	BrActorAdd(game_worldactor,this->rootactor);

	BrMatrix34Copy(&this->rootactor->t.t.mat,&this->worldpos);
	this->anim_callback = STRAT_NathanBulletEntity;

	Entity_SendMessageToOne(ENTITY_MESSAGE_INSTANCE_STARTUP,this);
	this->linklist = LinkList_Add(entity_level_list,this);


	this = Entity_Create();
	this->identifier = 1;
	this->transform_type = ENTITY_TRANSFORM_FLAT;
	this->rootactor = BrActorAllocate(BR_ACTOR_NONE, NULL);
	scaleit = BrActorAllocate(BR_ACTOR_MODEL, NULL);
	scaleit->model = modelresults->models[0];
	BrMatrix34Scale(&scaleit->t.t.mat, BR_SCALAR(0.4),BR_SCALAR(0.4),BR_SCALAR(0.4));
	BrActorAdd(this->rootactor,scaleit);
	this->rootactor->t.type=BR_TRANSFORM_MATRIX34;
	this->rootactor->model = modelresults->models[0];
	BrMatrix34Copy(&this->worldpos,&thisparent->worldpos);
	BrMatrix34PreTranslate(&this->worldpos, BR_SCALAR(10.0), BR_SCALAR(70.0), BR_SCALAR(20.0));
	BrMatrix34PreRotateX(&this->worldpos, BR_ANGLE_DEG(-3.0));
	BrActorAdd(game_worldactor,this->rootactor);

	BrMatrix34Copy(&this->rootactor->t.t.mat,&this->worldpos);
	this->anim_callback = STRAT_NathanBulletEntity;

	Entity_SendMessageToOne(ENTITY_MESSAGE_INSTANCE_STARTUP,this);
	this->linklist = LinkList_Add(entity_level_list,this);


	this = Entity_Create();
	this->identifier = 1;
	this->transform_type = ENTITY_TRANSFORM_FLAT;
	this->rootactor = BrActorAllocate(BR_ACTOR_NONE, NULL);
	scaleit = BrActorAllocate(BR_ACTOR_MODEL, NULL);
	scaleit->model = modelresults->models[0];
	BrMatrix34Scale(&scaleit->t.t.mat, BR_SCALAR(0.4),BR_SCALAR(0.4),BR_SCALAR(0.4));
	BrActorAdd(this->rootactor,scaleit);
	this->rootactor->t.type=BR_TRANSFORM_MATRIX34;
	this->rootactor->model = modelresults->models[0];
	BrMatrix34Copy(&this->worldpos,&thisparent->worldpos);
	BrMatrix34PreTranslate(&this->worldpos, BR_SCALAR(10.0), BR_SCALAR(70.0), BR_SCALAR(20.0));
	BrMatrix34PreRotateX(&this->worldpos, BR_ANGLE_DEG(3.0));
	BrActorAdd(game_worldactor,this->rootactor);

	BrMatrix34Copy(&this->rootactor->t.t.mat,&this->worldpos);
	this->anim_callback = STRAT_NathanBulletEntity;

	Entity_SendMessageToOne(ENTITY_MESSAGE_INSTANCE_STARTUP,this);
	this->linklist = LinkList_Add(entity_level_list,this);
}


void CreateBulletSuperBig(p_E_Entity thisparent)
{
	p_E_Entity this;
	int i;
	br_actor *scaleit;

	for (i=0;i<12;i++)
	{
		this = Entity_Create();
		this->identifier = 1;
		this->transform_type = ENTITY_TRANSFORM_FLAT;
		this->rootactor = BrActorAllocate(BR_ACTOR_NONE, NULL);
		scaleit = BrActorAllocate(BR_ACTOR_MODEL, NULL);
		scaleit->model = modelresults->models[0];
		BrMatrix34Scale(&scaleit->t.t.mat, BR_SCALAR(0.4),BR_SCALAR(0.4),BR_SCALAR(0.4));
		BrActorAdd(this->rootactor,scaleit);
		this->rootactor->t.type=BR_TRANSFORM_MATRIX34;
		this->rootactor->model = modelresults->models[0];
		BrMatrix34Copy(&this->worldpos,&thisparent->worldpos);
		BrMatrix34PreTranslate(&this->worldpos, BR_SCALAR(10.0), BR_SCALAR(70.0), BR_SCALAR(20.0));
		BrMatrix34PreRotateY(&this->worldpos, BR_ANGLE_DEG(((float)i-5.5F) * 9.0F));
		BrActorAdd(game_worldactor,this->rootactor);

		BrMatrix34Copy(&this->rootactor->t.t.mat,&this->worldpos);
		this->anim_callback = STRAT_NathanBulletEntity;

		Entity_SendMessageToOne(ENTITY_MESSAGE_INSTANCE_STARTUP,this);
		this->linklist = LinkList_Add(entity_level_list,this);
	}
}


/* "Morph" one matrix to another
 */
void c_ZoomToMatrix34(br_matrix34 *a, br_matrix34 *b, float speed)
{
	int i, j;
	br_matrix34 temp;

	for(i = 0; i < 4; i++)
	{
		for(j = 0; j < 3; j++)
		{
			a->m[i][j] = BR_ADD(BR_MUL(a->m[i][j], BR_SCALAR(1-speed)),
			 BR_MUL(b->m[i][j], BR_SCALAR(speed)));
		}
	}

	BrMatrix34LPNormalise(&temp, a);
	BrMatrix34Copy(a, &temp);
}

static int footsampleid = -1;
static int gun1sampleid = -1;

static int gun1sampleids[9];

int STRAT_NathanEntity(int event,void *extradata)
{
	static br_scalar speed=BR_SCALAR(0);
	static br_scalar maxspeed=BR_SCALAR(1.0);
	float runningscale;
	static int waitcycle=0,waitnum=0;
	static int jumping=0;
	static int jumping2=0;
	static int camchange=0;
	static int cammode=0;
	static int weapchange=0;
	static int weapmode=0;
	static int movenfire=0;
	static br_actor *headmodel=NULL;
	static int sidestepping = 0;
	br_matrix34 tempmat;
	br_vector3 solve,startpos,endpos;
	float befypos,aftypos;
	p_E_Entity this = extradata;
	static float gravity;
	float mtime = 1.0F;
	int thisframeset = 0;
	int i;
	char buff[256];

	// Shuts up the compiler
	solve.v[0] = BR_SCALAR(0.0);
	endpos.v[0] = BR_SCALAR(0.0);

	if (event == ENTITY_MESSAGE_SYSTEM_STARTUP && footsampleid == -1)
	{
		footsampleid = LoadSample("d:\\cult\\data\\sound\\stpwood.wav");
		gun1sampleid = LoadSample("d:\\cult\\data\\sound\\magic.wav");

		for (i=0;i<7;i++)
		{
			sprintf(buff,"d:\\cult\\data\\sound\\jiz\\\\laser%d.wav",i+1);
			gun1sampleids[i] = LoadSample(buff);
		}

		modelresults = Entity_LoadAModelCollection(this,"p:\\cult\\veryt\\bullet.3ds");
		modelresults2 = Entity_LoadAModelCollection(this,"p:\\cult\\martinp\\tstcomp\\nebula.3ds");
	}

	if (event == ENTITY_MESSAGE_INSTANCE_STARTUP)
	{
	   BrMatrix34Identity(&this->worldpos);
		BrMatrix34PreTranslate(&this->worldpos, BR_SCALAR(0), BR_SCALAR(10.0), BR_SCALAR(0.0));
		BrMatrix34Copy(&this->rootactor->t.t.mat,&this->worldpos);
		/* Bodge up blokecam to look down at bloke */
		BrMatrix34Copy(&blokecam->t.t.mat,&this->rootactor->t.t.mat);
		BrMatrix34PreTranslate(&blokecam->t.t.mat, BR_SCALAR(0), BR_SCALAR(180.0), BR_SCALAR(-1.0));
		BrMatrix34PreRotateY(&blokecam->t.t.mat, BR_ANGLE_DEG(180.0));
		BrMatrix34PreRotateX(&blokecam->t.t.mat, BR_ANGLE_DEG(-90.0));

		headmodel = Editor_SearchTreeNew(this->rootactor, "MHEAD");
		gravity = 1.0F;
		this->tweentime = 0.1F;
	}


	if (event == ENTITY_MESSAGE_PREFRAME)
	{
		BrMatrix34Copy(&this->rootactor->t.t.mat,&this->worldpos);
//		Entity_SetAnimFrame(this,this->anim_identifier,this->anim_frame);
	}


	if (event == ENTITY_MESSAGE_MIDFRAME)
	{
		if (camchange > 0)
		{
			BrPixelmapTextF(back_screen,32-320,4-180+8,BR_COLOUR_RGB(255,255,255),BrFontProp7x9,
							"Camera mode %d",cammode+1);
		}

		if (weapchange > 0)
		{
			BrPixelmapTextF(back_screen,32-320,4-180+8+9,BR_COLOUR_RGB(255,255,255),BrFontProp7x9,
							"Weapon mode %d",weapmode);
		}
	}


	if (event == ENTITY_MESSAGE_TICKER)
	{
//		BrMatrix34Copy(&this->worldpos,&this->rootactor->t.t.mat);

		if (DOSKeyTest(SC_G, 0, REPT_FIRST_DOWN))
		{
		   BrMatrix34Identity(&this->worldpos);
			BrMatrix34PreTranslate(&this->worldpos, BR_SCALAR(0), BR_SCALAR(10.0), BR_SCALAR(0.0));
		}

		startpos.v[0] = this->worldpos.m[3][0];
		startpos.v[1] = this->worldpos.m[3][1];
		startpos.v[2] = this->worldpos.m[3][2];

		waitcycle++;
		runningscale = 1.0F;

		if (DOSKeyTest(SC_J, 0, REPT_FIRST_DOWN))
		{
			gravity -= 11.0F;
		}

		if (jumping == 0)
		{
			if (DOSKeyTest(SC_C, 0, REPT_FIRST_DOWN))
			{
				camchange=1;
				cammode++;
				if (cammode>2)
					cammode = 0;
			}

			if (camchange > 0)
			{
				camchange++;
				if (camchange > 50)
					camchange = 0;
			}	


			if (DOSKeyTest(SC_1, 0, REPT_FIRST_DOWN))
			{
				weapchange=1;
				weapmode = 1;
			}

			if (DOSKeyTest(SC_2, 0, REPT_FIRST_DOWN))
			{
				weapchange=1;
				weapmode = 2;
			}

			if (DOSKeyTest(SC_3, 0, REPT_FIRST_DOWN))
			{
				weapchange=1;
				weapmode = 3;
			}

			if (DOSKeyTest(SC_4, 0, REPT_FIRST_DOWN))
			{
				weapchange=1;
				weapmode = 4;
			}

			if (DOSKeyTest(SC_5, 0, REPT_FIRST_DOWN))
			{
				weapchange=1;
				weapmode = 5;
			}

			if (DOSKeyTest(SC_6, 0, REPT_FIRST_DOWN))
			{
				weapchange=1;
				weapmode = 6;
			}

			if (DOSKeyTest(SC_7, 0, REPT_FIRST_DOWN))
			{
				weapchange=1;
				weapmode = 7;
			}

			if (weapchange > 0)
			{
				weapchange++;
				if (weapchange > 50)
					weapchange = 0;
			}	


			if (DOSKeyTest(SC_L, 0, 0))
			{
				sidestepping++;
			}
			else
			{
				sidestepping = 0;
			}

			if (DOSKeyTest(SC_C_UP, 0, REPT_FIRST_DOWN))
			{
				this->morphtime = mtime;
			}

			if (DOSKeyTest(SC_C_DOWN, 0, REPT_FIRST_DOWN))
			{
				this->morphtime = mtime;
			}

			if (DOSKeyTest(SC_ENTER, 0, REPT_FIRST_DOWN))
			{
				this->morphtime = mtime;
			}

			movenfire = 0;
			if (DOSKeyTest(SC_C_UP, 0, 0))
			{
				movenfire = 1;
				this->anim_frame++;
				if (this->anim_identifier == 2 && !DOSKeyTest(SC_ENTER, 0, 0))
				{
					this->morphtime = mtime;
				}
				this->anim_identifier = 1;
				if (DOSKeyTest(SC_ENTER, 0, 0))
				{
					runningscale = 2.0F;
					this->anim_identifier = 2;
				}
				BrMatrix34PreTranslate(&this->worldpos, BR_SCALAR(0), BR_SCALAR(0.0), BR_SCALAR(3.0 * runningscale));
				thisframeset = 1;

/*******/
		if (DOSKeyTest(SC_SPACE, 0, 0) && jumping2 == 0)
		{
			jumping2++;
			PlaySample(gun1sampleids[weapmode-1],200);
			waitcycle = 0;
			switch (weapmode)
			{
				case 0:
				case 1:
				case 5:
				case 6:
				case 7:
					CreateBullet(this);
					break;
				case 2:
					CreateBulletSuper(this);
					break;
				case 3:
					CreateBulletSuperBig(this);
					break;
				case 4:
					CreateBoom(this);
					break;
			}
		}

		if (jumping2 > 0)
		{
			waitcycle = 0;
			this->anim_identifier += 10;
		}
/*******/


				Entity_SetAnimFrame(this,this->anim_identifier,this->anim_frame);

/*******/
		if (jumping2 > 0)
		{
			jumping2++;
			if (jumping2 >= 11)
			{
				jumping2 = 0;
				this->morphtime = mtime;
			}
		}
/*******/
				if (this->anim_identifier == 1 && (this->anim_frame == 10 || this->anim_frame == 25) )
				{
					PlaySample(footsampleid,255);
				}
				if (this->anim_identifier == 2 && (this->anim_frame == 5 || this->anim_frame == 15) )
				{
					PlaySample(footsampleid,255);
				}
				waitcycle = 0;
			}

			if (DOSKeyTest(SC_C_DOWN, 0, 0))
			{
				movenfire = 1;
				this->anim_frame--;
				if (this->anim_identifier == 2 && !DOSKeyTest(SC_ENTER, 0, 0))
				{
					this->morphtime = mtime;
				}
				this->anim_identifier = 1;
				if (DOSKeyTest(SC_ENTER, 0, 0))
				{
					runningscale = 2.0F;
					this->anim_identifier = 2;
				}
				BrMatrix34PreTranslate(&this->worldpos, BR_SCALAR(0), BR_SCALAR(0.0), BR_SCALAR(-2.0 * runningscale));
				if (this->anim_identifier == 0 && (this->anim_frame == 10 || this->anim_frame == 25) )
				{
					PlaySample(footsampleid,255);
				}
				thisframeset = 1;

/*******/
		if (DOSKeyTest(SC_SPACE, 0, 0) && jumping2 == 0)
		{
			jumping2++;
			PlaySample(gun1sampleids[weapmode-1],200);
			waitcycle = 0;
			switch (weapmode)
			{
				case 0:
				case 1:
				case 5:
				case 6:
				case 7:
					CreateBullet(this);
					break;
				case 2:
					CreateBulletSuper(this);
					break;
				case 3:
					CreateBulletSuperBig(this);
					break;
				case 4:
					CreateBoom(this);
					break;
			}
		}

		if (jumping2 > 0)
		{
			waitcycle = 0;
			this->anim_identifier += 10;
		}
/*******/

				Entity_SetAnimFrame(this,this->anim_identifier,this->anim_frame);

/*******/
		if (jumping2 > 0)
		{
			jumping2++;
			if (jumping2 >= 11)
			{
				jumping2 = 0;
				this->morphtime = mtime;
			}
		}
/*******/

				if (this->anim_identifier == 1 && (this->anim_frame == 5 || this->anim_frame == 15) )
				{
					PlaySample(footsampleid,255);
				}
				waitcycle = 0;
			}
		}

		if (DOSKeyTest(SC_C_LEFT, 0, 0) && sidestepping == 0)
		{
			BrMatrix34PreRotateY(&this->worldpos, BR_ANGLE_DEG(6.0));
			waitcycle = 0;
		}

		if (DOSKeyTest(SC_C_RIGHT, 0, 0) && sidestepping == 0)
		{
			BrMatrix34PreRotateY(&this->worldpos, BR_ANGLE_DEG(-6.0));
			waitcycle = 0;
		}

		if (DOSKeyTest(SC_C_LEFT, 0, 0) && sidestepping > 0)
		{
			waitcycle = 0;
			if (sidestepping == 1)
				this->anim_frame = 0;
			else
				this->anim_frame++;

			if (this->anim_frame >= 28)
			{
				this->anim_frame = 0;
			}

			this->anim_identifier = 10;
			thisframeset = 1;
			Entity_SetAnimFrame(this,this->anim_identifier,this->anim_frame);
			if (this->anim_frame == 18)
			{
				this->anim_frame = 0;
			}
			BrMatrix34PreTranslate(&this->worldpos, BR_SCALAR(3.0), BR_SCALAR(0.0), BR_SCALAR(0.0));
		}

		if (DOSKeyTest(SC_C_RIGHT, 0, 0) && sidestepping > 0)
		{
			waitcycle = 0;
			if (sidestepping == 1)
				this->anim_frame = 28;
			else
				this->anim_frame++;

			if (this->anim_frame <28)
			{
				this->anim_frame = 28;
			}

			this->anim_identifier = 10;
			thisframeset = 1;
			Entity_SetAnimFrame(this,this->anim_identifier,this->anim_frame);
			if (this->anim_frame == 0)
			{
				this->anim_frame = 28;
			}
			BrMatrix34PreTranslate(&this->worldpos, BR_SCALAR(-3.0), BR_SCALAR(0.0), BR_SCALAR(0.0));
		}

		if (DOSKeyTest(SC_SPACE, 0, 0) && jumping == 0 && movenfire==0)
		{
			jumping++;
			this->morphtime = 0.0F;
			this->anim_frame = 0;
			waitcycle = 0;
			PlaySample(gun1sampleids[weapmode-1],200);
			switch (weapmode)
			{
				case 0:
				case 1:
				case 5:
				case 6:
				case 7:
					CreateBullet(this);
					break;
				case 2:
					CreateBulletSuper(this);
					break;
				case 3:
					CreateBulletSuperBig(this);
					break;
				case 4:
					CreateBoom(this);
					break;
			}
		}

		if (jumping > 0)
		{
			waitcycle = 0;
			this->anim_frame++;
			this->anim_identifier = 7;
			if (weapmode == 4)
			{
				this->anim_identifier = 8;
			}
			thisframeset = 1;
			Entity_SetAnimFrame(this,this->anim_identifier,this->anim_frame);
			if (this->anim_frame == 0)
			{
				jumping = 0;
				this->morphtime = mtime;
			}
		}

		if (waitcycle == 50)
		{
			this->anim_frame=0;
			this->morphtime = mtime;
			jumping2=0;
		}

		if (waitcycle >= 50)
		{
			this->anim_frame++;
			this->anim_identifier = 3 + waitnum;
			thisframeset = 1;
			Entity_SetAnimFrame(this,this->anim_identifier,this->anim_frame);
			if (this->anim_frame == 0)
			{
				this->anim_identifier = 0;
				waitcycle = 0;
				this->morphtime = mtime;
				waitnum++;
				if (waitnum>3)		/* Maximum number of idle anims */
				{
					waitnum=0;
				}
			}
		}

		/* Gravity!! */
		gravity +=1.0F;
		this->worldpos.m[3][1] = BR_SUB(this->worldpos.m[3][1] , BR_SCALAR(gravity));
		if (gravity > 40.0F)
			gravity = 40.0F;
		befypos = 0.0F;
		aftypos = 0.0F;
#if 0

		BrMatrix34Copy(&tempmat,&this->worldpos);
		befypos = BrScalarToFloat(tempmat.m[3][1]);
		tempmat.m[3][1] = Collision_SolveForYHeight(tempmat.m[3][0],tempmat.m[3][1],tempmat.m[3][2],BR_SCALAR(50.0));

		aftypos = BrScalarToFloat(tempmat.m[3][1]);

		if (aftypos > befypos)
		{
			BrMatrix34Copy(&this->worldpos,&tempmat);
			gravity = 1.0F;
		}

#else

// Try out new collision hack.
		endpos.v[0] = this->worldpos.m[3][0];
		endpos.v[1] = this->worldpos.m[3][1];
		endpos.v[2] = this->worldpos.m[3][2];

		Collision_SolveForVector(&solve,&startpos,&endpos, BR_SCALAR(1.0));

		this->worldpos.m[3][0] = solve.v[0];
		this->worldpos.m[3][1] = solve.v[1];
		this->worldpos.m[3][2] = solve.v[2];
		befypos = BrScalarToFloat(startpos.v[1]);
		aftypos = BrScalarToFloat(solve.v[1]);
		gravity = befypos - aftypos;

#endif

		BrMatrix34Copy(&tempmat,&this->worldpos);
		if (cammode == 0)
		{
			BrMatrix34PreTranslate(&tempmat, BR_SCALAR(0), BR_SCALAR(80.0), BR_SCALAR(-60.0));
			BrMatrix34PreRotateY(&tempmat, BR_ANGLE_DEG(180.0));
			BrMatrix34PreRotateX(&tempmat, BR_ANGLE_DEG(-10.0));
			c_ZoomToMatrix34(&blokecam->t.t.mat, &tempmat, 0.2F);
		}

		if (cammode == 1)
		{
			BrMatrix34PreTranslate(&tempmat, BR_SCALAR(0), BR_SCALAR(120.0), BR_SCALAR(-130.0));
			BrMatrix34PreRotateY(&tempmat, BR_ANGLE_DEG(180.0));
			BrMatrix34PreRotateX(&tempmat, BR_ANGLE_DEG(-20.0));
			c_ZoomToMatrix34(&blokecam->t.t.mat, &tempmat, 0.2F);
		}

		if (cammode == 2)
		{
		}

		if ( thisframeset == 0)
		{
			Entity_SetAnimFrame(this,this->anim_identifier,this->anim_frame);
		}

	}

	return 0;
}


static br_token_value e_blend_tokens[] = {
	BRT_BLEND_B,BR_TRUE,
	BRT_OPACITY_X, 0xa00000,	/* i.e. 160 in fixed point - this is hideous */
	0
	};

struct s_EntityNathanBullet {		br_actor *actor;
											br_model *model;
											br_material *material;
											float distancez;
											float prevailx;
											float prevaily;
											float current_px;
											float current_py;
											int collided;
										 };
static br_actor *muzzlelight=NULL;

#define TRAIL_SEGMENTS 5

int STRAT_NathanBulletEntity(int event,void *extradata)
{
	p_E_Entity this = extradata;
	struct s_EntityNathanBullet *p_localdata = (struct s_EntityNathanBullet *) this->p_localdata;
	br_material *material;
	br_model *thismodel;
	br_actor *actor;
	int i,j;
	float trailpos,blueness;
//	br_vector3 solve;
	br_vector3 startpos,endpos;

	if (event == ENTITY_MESSAGE_SYSTEM_STARTUP)
	{
	}

	if (event == ENTITY_MESSAGE_SYSTEM_CLOSEDOWN)
	{
		if (muzzlelight != NULL)
		{
//			fatal("A light is already enabled for the muzzle flash!!");
			Editor_OverlayDebug("Disabling muzzleflash on ENTITY_MESSAGE_SYSTEM_CLOSEDOWN");
			BrLightDisable(muzzlelight);
			BrLightDisable(muzzlelight);
			BrLightDisable(muzzlelight);
			BrActorRemove(muzzlelight);
			BrActorFree(muzzlelight);
			muzzlelight = NULL;
		}

		Editor_OverlayDebug("Removing bullet entity on ENTITY_MESSAGE_SYSTEM_CLOSEDOWN");
		BrActorRemove(this->rootactor);
		LinkList_Remove(this->linklist);
//		Entity_SendMessageToOne(ENTITY_MESSAGE_INSTANCE_CLOSEDOWN,this);
		BrActorFree(this->rootactor);
		free(this);
		return 0;

	}

	if (event == ENTITY_MESSAGE_INSTANCE_STARTUP)
	{
		p_localdata = calloc(1,sizeof (struct s_EntityNathanBullet));
		if (p_localdata == NULL)
		{
			fatal("Failed to allocate p_localdata workspace!!");
		}

		this->p_localdata = p_localdata;

		p_localdata->prevailx = ((rand()%200)-100.0F)/200.0F;
		p_localdata->prevaily = ((rand()%200)-100.0F)/200.0F;
		p_localdata->current_px = 0.0F;
		p_localdata->current_py = 0.0F;

		material = BrMaterialAllocate("ooverlaymat");
		material->flags = BR_MATF_PRELIT | BR_MATF_ALWAYS_VISIBLE | BR_MATF_SMOOTH;
		material->colour = BR_COLOUR_RGB(255,255,255);
		material->extra_prim = e_blend_tokens;
		BrMaterialAdd(material);

		/* Create a model with two faces, two texture mapped triangles */
		thismodel = BrModelAllocate("oentnatbul",TRAIL_SEGMENTS*2+2,TRAIL_SEGMENTS*2);

		for (i=0;i<TRAIL_SEGMENTS+1;i++)
		{

			blueness = (255.0F * ((float)i/(float)TRAIL_SEGMENTS));

			thismodel->vertices[i*2].p.v[0]=BR_SCALAR(-2.0);
			thismodel->vertices[i*2].p.v[1]=BR_SCALAR(0.0);
			thismodel->vertices[i*2].p.v[2]=BR_SCALAR(0.0);
			thismodel->vertices[i*2].red = (int) 255;
			thismodel->vertices[i*2].grn = (int) blueness;
			thismodel->vertices[i*2].blu = (int) 0;

			thismodel->vertices[i*2+1].p.v[0]=BR_SCALAR(2.0);
			thismodel->vertices[i*2+1].p.v[1]=BR_SCALAR(0.0);
			thismodel->vertices[i*2+1].p.v[2]=BR_SCALAR(0.0);
			thismodel->vertices[i*2+1].red = (int) 255;
			thismodel->vertices[i*2+1].grn = (int) blueness;
			thismodel->vertices[i*2+1].blu = (int) 0;
		}

		for (i=0;i<TRAIL_SEGMENTS;i++)
		{
			thismodel->faces[i*2].vertices[0]=(i*2)+0;
			thismodel->faces[i*2].vertices[1]=(i*2)+2;
			thismodel->faces[i*2].vertices[2]=(i*2)+3;
			thismodel->faces[i*2].material=material;

			thismodel->faces[i*2+1].vertices[0]=(i*2)+0;
			thismodel->faces[i*2+1].vertices[1]=(i*2)+3;
			thismodel->faces[i*2+1].vertices[2]=(i*2)+1;
			thismodel->faces[i*2+1].material=material;
		}

		thismodel->flags=BR_MODF_KEEP_ORIGINAL;

		/* Add model to registry */
		BrModelAdd(thismodel);
		BrModelUpdate(thismodel,BR_MODU_ALL);

		actor = BrActorAllocate(BR_ACTOR_MODEL, NULL);
		actor->t.type = BR_TRANSFORM_MATRIX34;
		BrMatrix34Copy(&actor->t.t.mat,&this->worldpos);
		actor->model = thismodel;
		BrMatrix34Copy(&actor->t.t.mat,&this->worldpos);
		BrActorAdd(game_worldactor,actor);

		p_localdata->actor = actor;
		p_localdata->model = thismodel;
		p_localdata->material = material;
		p_localdata->distancez = 0.0F;

#if 1
		if (muzzlelight != NULL)
		{
//			fatal("A light is already enabled for the muzzle flash!!");
//			Editor_OverlayDebug("A light is already enabled for the muzzle flash!!");
			BrLightDisable(muzzlelight);
			BrLightDisable(muzzlelight);
			BrLightDisable(muzzlelight);
			BrActorRemove(muzzlelight);
			BrActorFree(muzzlelight);
			muzzlelight = NULL;
		}
		muzzlelight = BrActorAllocate(BR_ACTOR_LIGHT, NULL);
		((br_light *) muzzlelight->type_data)->type = BR_LIGHT_POINT;
		((br_light *) muzzlelight->type_data)->attenuation_c = BR_SCALAR(1.0);
		((br_light *) muzzlelight->type_data)->attenuation_q = BR_SCALAR(0.0001);
		((br_light *) muzzlelight->type_data)->colour = BR_COLOUR_RGB(255, 255, 255);
		muzzlelight->t.type=BR_TRANSFORM_MATRIX34;
		BrActorAdd(game_worldactor,muzzlelight);
		BrLightDisable(muzzlelight);
		BrLightDisable(muzzlelight);
		BrLightEnable(muzzlelight);
		BrMatrix34Copy(&muzzlelight->t.t.mat,&this->worldpos);
#endif
	}

	if (event == ENTITY_MESSAGE_INSTANCE_CLOSEDOWN)
	{
		if (p_localdata != NULL)
		{
			BrActorRemove(p_localdata->actor);
			BrModelRemove(p_localdata->model);
			BrModelFree(p_localdata->model);
			BrMaterialRemove(p_localdata->material);
			BrMaterialFree(p_localdata->material);
			free(this->p_localdata);
			p_localdata = NULL;
			this->p_localdata = NULL;
		}
	}

	if (event == ENTITY_MESSAGE_PREFRAME)
	{
		e_blend_tokens[1].v.u32 = (int) ((200-((float)this->localdata * (180.0F/20.0F))) * 65536);
		BrMaterialUpdate(p_localdata->material,BR_MATU_ALL);
		thismodel = p_localdata->model;

		for (i=1;i<=TRAIL_SEGMENTS;i++)
		{
			trailpos = p_localdata->distancez * ((float)i/(float)TRAIL_SEGMENTS);
			thismodel->vertices[i*2].p.v[2] =		BR_SCALAR( trailpos );
			thismodel->vertices[i*2+1].p.v[2] =		BR_SCALAR( trailpos );
		}

		i=0;
		for (j=0;j<(TRAIL_SEGMENTS*2+2);j+=2)
		{
			blueness = (float) i/(float)TRAIL_SEGMENTS;
			blueness = (float) sin( blueness * PI ) * 3.0F;
			blueness += 1.0F;

			trailpos = BrScalarToFloat(thismodel->vertices[j].p.v[0]);
			trailpos += (float) p_localdata->current_px * (blueness/5.0F);
			thismodel->vertices[j].p.v[0] = BR_SCALAR(trailpos);

			trailpos = BrScalarToFloat(thismodel->vertices[j+1].p.v[0]);
			trailpos += (float) p_localdata->current_px * (blueness/5.0F);
			thismodel->vertices[j+1].p.v[0] = BR_SCALAR(trailpos);

			trailpos = BrScalarToFloat(thismodel->vertices[j].p.v[1]);
			trailpos += (float) p_localdata->current_py * (blueness/5.0F);
			thismodel->vertices[j].p.v[1] = BR_SCALAR(trailpos);

			trailpos = BrScalarToFloat(thismodel->vertices[j+1].p.v[1]);
			trailpos += (float) p_localdata->current_py * (blueness/5.0F);
			thismodel->vertices[j+1].p.v[1] = BR_SCALAR(trailpos);

			i++;
		}

		BrModelUpdate(thismodel,BR_MODU_VERTICES);
		BrMatrix34Copy(&this->rootactor->t.t.mat,&this->worldpos);
		if (muzzlelight != NULL)
		{
			BrMatrix34Copy(&muzzlelight->t.t.mat,&this->worldpos);
		}
	}

	if (event == ENTITY_MESSAGE_TICKER)
	{
		startpos.v[0] = this->worldpos.m[3][0];
		startpos.v[1] = this->worldpos.m[3][1];
		startpos.v[2] = this->worldpos.m[3][2];

//		BrMatrix34Copy(&this->worldpos,&this->rootactor->t.t.mat);
		if (p_localdata->collided == 0)
		{
			p_localdata->current_px += p_localdata->prevailx;
			p_localdata->current_py += p_localdata->prevaily;
			p_localdata->distancez += 50.0F;
			BrMatrix34PreTranslate(&this->worldpos, BR_SCALAR(0.0), BR_SCALAR(0.0), BR_SCALAR(50.0));
		}

		endpos.v[0] = this->worldpos.m[3][0];
		endpos.v[1] = this->worldpos.m[3][1];
		endpos.v[2] = this->worldpos.m[3][2];

#if 0
		if (Collision_SolveForVector(&solve,&startpos,&endpos, BR_SCALAR(1.0)))
		{
//			p_localdata->collided = 1;
			this->worldpos.m[3][0] = solve.v[0];
			this->worldpos.m[3][1] = solve.v[1];
			this->worldpos.m[3][2] = solve.v[2];
		}
#endif

#if 1

		if (this->localdata < 5)
		{
			if (muzzlelight == NULL)
			{
//				Editor_OverlayDebug("The muzzle flash light isn't on can't change its brightness (obviously)!!");
			}
			else
			{
				((br_light *) muzzlelight->type_data)->attenuation_c = BR_SCALAR((this->localdata+1)/10.0F);
			}
		}

		if (this->localdata == 5)
		{
			if (muzzlelight == NULL)
			{
//				Editor_OverlayDebug("The muzzle flash light isn't on can't turn it off (obviously)!!");
			}
			else
			{
				BrLightDisable(muzzlelight);
				BrLightDisable(muzzlelight);
				BrLightDisable(muzzlelight);
				BrActorRemove(muzzlelight);
				BrActorFree(muzzlelight);
				muzzlelight = NULL;
			}
		}
#endif

		if (this->localdata > 20)
		{
			BrActorRemove(this->rootactor);
			LinkList_Remove(this->linklist);
			Entity_SendMessageToOne(ENTITY_MESSAGE_INSTANCE_CLOSEDOWN,this);
			BrActorFree(this->rootactor);
			free(this);
			return 0;
		}

		this->localdata++;
	}

	return 0;
}


int STRAT_CycleEntity(int event,void *extradata)
{
	p_E_Entity this = extradata;

	if (event == ENTITY_MESSAGE_PREFRAME)
	{
		BrMatrix34Copy(&this->rootactor->t.t.mat,&this->worldpos);
		Entity_SetAnimFrame(this,this->anim_identifier,this->anim_frame);
	}

	if (event == ENTITY_MESSAGE_TICKER)
	{
		this->anim_frame++;
		Entity_SetAnimFrame(this,this->anim_identifier,this->anim_frame);

		if (this->anim_frame == 0)
		{
			this->anim_identifier++;
			if (this->anim_identifier >= this->anim_total_identifiers)
			{
				this->anim_identifier=0;
			}
		}
//		BrMatrix34PreRotateY(&this->worldpos, BR_ANGLE_DEG(-3.0));
	}

	return 0;
}


int STRAT_CycleEntityMove(int event,void *extradata)
{
	p_E_Entity this = extradata;

	if (event == ENTITY_MESSAGE_PREFRAME)
	{
		BrMatrix34Copy(&this->rootactor->t.t.mat,&this->worldpos);
		Entity_SetAnimFrame(this,this->anim_identifier,this->anim_frame);
	}

	if (event == ENTITY_MESSAGE_TICKER)
	{
		this->anim_frame++;
		Entity_SetAnimFrame(this,this->anim_identifier,this->anim_frame);

		if (this->anim_frame == 0)
		{
			this->anim_identifier++;
			if (this->anim_identifier >= this->anim_total_identifiers)
			{
				this->anim_identifier=0;
			}
		}
		BrMatrix34PreTranslate(&this->worldpos, BR_SCALAR(0.0), BR_SCALAR(0.0), BR_SCALAR(3.0));
		BrMatrix34PreRotateY(&this->worldpos, BR_ANGLE_DEG(-3.0));
	}

	return 0;
}


struct s_EntityBounce {		float yvel; };

int STRAT_EntityBounce(int event,void *extradata)
{
	p_E_Entity this = extradata;
	struct s_EntityBounce *p_localdata = (struct s_EntityBounce *) this->p_localdata;
	br_matrix34 *thismat = &this->worldpos;
	float oldheight,newheight,collheight;

	if (event == ENTITY_MESSAGE_INSTANCE_STARTUP)
	{
		p_localdata = calloc(1,sizeof(struct s_EntityBounce));
		p_localdata->yvel = 0.0F;
		this->p_localdata = p_localdata;
		thismat->m[3][1] = BR_SCALAR(150.F + BrScalarToFloat(Collision_SolveForYHeight(thismat->m[3][0],thismat->m[3][1],thismat->m[3][2],BR_SCALAR(0.0))));
	}

	if (event == ENTITY_MESSAGE_INSTANCE_CLOSEDOWN)
	{
		free(p_localdata);
	}

	if (event == ENTITY_MESSAGE_PREFRAME)
	{
		BrMatrix34Copy(&this->rootactor->t.t.mat,&this->worldpos);
		Entity_SetAnimFrame(this,this->anim_identifier,this->anim_frame);
	}

	if (event == ENTITY_MESSAGE_TICKER)
	{
		/* Add on gravity */
		p_localdata->yvel -= (0.98F);

		oldheight = BrScalarToFloat(thismat->m[3][1]);
		newheight = oldheight + p_localdata->yvel;
		collheight = BrScalarToFloat(Collision_SolveForYHeight(thismat->m[3][0],thismat->m[3][1],thismat->m[3][2],BR_SCALAR(0.0)));

		if ( newheight >= collheight )
		{
			thismat->m[3][1] = BR_SCALAR(newheight);
		}
		else
		{
			p_localdata->yvel = -p_localdata->yvel;
			thismat->m[3][1] = BR_SCALAR(collheight);
		}
	}

	return 0;
}


struct s_EntityBoom {
								float opacity;
								br_material *material;
							 };

int STRAT_BoomEntity(int event,void *extradata)
{
	p_E_Entity this = extradata;
	struct s_EntityBoom *p_localdata = (struct s_EntityBoom *) this->p_localdata;
	br_actor *edit;

	if (event == ENTITY_MESSAGE_INSTANCE_STARTUP)
	{
		p_localdata = calloc(1,sizeof (struct s_EntityNathanBullet));
		if (p_localdata == NULL)
		{
			fatal("Failed to allocate p_localdata workspace!!");
		}

		this->p_localdata = p_localdata;
		p_localdata->opacity = 200.0F;
		p_localdata->material = modelresults2->materials[0];
		p_localdata->material->extra_prim = e_blend_tokens;
	}

	if (event == ENTITY_MESSAGE_INSTANCE_CLOSEDOWN)
	{
		if (p_localdata != NULL)
		{
			free(this->p_localdata);
			p_localdata = NULL;
			this->p_localdata = NULL;
		}
	}


	if (event == ENTITY_MESSAGE_PREFRAME)
	{
		float basescale;

		e_blend_tokens[1].v.u32 = (int) (p_localdata->opacity * 65536.0F);
		BrMaterialUpdate(p_localdata->material,BR_MATU_ALL);

		basescale = (float) (cos((p_localdata->opacity/200.0F)*(3.141F/2.0F))/2.5F) + 0.05F;

		edit = this->rootactor->children;
		BrMatrix34Scale(&edit->t.t.mat, BR_SCALAR(basescale),BR_SCALAR(basescale),BR_SCALAR(basescale));
		BrMatrix34PreRotateY(&edit->t.t.mat, BR_ANGLE_DEG(-p_localdata->opacity/2));
		BrMatrix34PreRotateX(&edit->t.t.mat, BR_ANGLE_DEG(p_localdata->opacity/2));

		basescale = basescale*2.0F;
		edit = edit->next;
		BrMatrix34Scale(&edit->t.t.mat, BR_SCALAR(basescale),BR_SCALAR(basescale),BR_SCALAR(basescale));
		BrMatrix34PreRotateY(&edit->t.t.mat, BR_ANGLE_DEG(-p_localdata->opacity));
		BrMatrix34PreRotateX(&edit->t.t.mat, BR_ANGLE_DEG(p_localdata->opacity));
	}

	if (event == ENTITY_MESSAGE_TICKER)
	{

		p_localdata->opacity -=3.0F;

		if ( p_localdata->opacity<=0.0F )
		{
			BrActorRemove(this->rootactor);
			LinkList_Remove(this->linklist);
			Entity_SendMessageToOne(ENTITY_MESSAGE_INSTANCE_CLOSEDOWN,this);
			BrActorFree(this->rootactor);
			free(this);
			return 0;
		}
	}

	return 0;
}


int STRAT_WraithEntity(int event,void *extradata)
{
	p_E_Entity this = extradata;
	static void *fd_startframe;
	static void *fd_0to1;
	static void *fd_1to2;
	static void *fd_1to3;
	static void *fd_1to4;

	static float onebitstart=0.0F;
	static int bounce=0;
	static float onebitstart2=0.0F;
	static int bounce2=0;
	static float onebitstart3=0.0F;
	static int bounce3=0;
	float temp;

	if (event == ENTITY_MESSAGE_SYSTEM_STARTUP && modelresults3 == NULL)
	{
		modelresults3 = Entity_LoadAModelCollection(this,"p:\\cult\\martinp\\tstcomp\\nwraith.3ds");
		fd_startframe = Anim_FiniteDifferenceCalculateStart(modelresults3->models[0]);
		fd_0to1 = Anim_FiniteDifferenceCalculate(modelresults3->models[0],modelresults3->models[1]);
		fd_1to2 = Anim_FiniteDifferenceCalculate(modelresults3->models[1],modelresults3->models[2]);
		fd_1to3 = Anim_FiniteDifferenceCalculate(modelresults3->models[1],modelresults3->models[3]);
		fd_1to4 = Anim_FiniteDifferenceCalculate(modelresults3->models[1],modelresults3->models[4]);
	}

	if (event == ENTITY_MESSAGE_INSTANCE_STARTUP)
	{
		this->rootactor->children->model = modelresults3->models[0];
	}

	if (event == ENTITY_MESSAGE_TICKER)
	{
		if (bounce == 0)
		{
			onebitstart +=0.02F;
			if (onebitstart > 6.0F)
			{
				onebitstart = 6.0F;
				bounce = 1;
			}
		}
		if (bounce == 1)
		{
			onebitstart -=0.02F;
			if (onebitstart < -6.0F)
			{
				onebitstart = -6.0F;
				bounce = 0;
			}
		}


		if (bounce2 == 0)
		{
			onebitstart2 +=0.05F;
			if (onebitstart2 > 1.0F)
			{
				bounce2 = 1;
			}
		}
		if (bounce2 == 1)
		{
			onebitstart2 -=0.05F;
			if (onebitstart2 < 0.0F)
			{
				onebitstart2 = 0.0F;
				bounce2 = 0;
			}
		}

		if (bounce3 == 0)
		{
			onebitstart3 +=0.07F;
			if (onebitstart3 > 1.0F)
			{
				bounce3 = 1;
			}
		}
		if (bounce3 == 1)
		{
			onebitstart3 -=0.07F;
			if (onebitstart3 < 0.0F)
			{
				onebitstart3 = 0.0F;
				bounce3 = 0;
			}
		}

		if ( !(onebitstart >= 1.0F && onebitstart <=6.0F))
		{
			onebitstart2 = 0.0F;
			onebitstart3 = 0.0F;
		}
	}

	if (event == ENTITY_MESSAGE_PREFRAME)
	{
		temp = onebitstart;
		if (temp>1.0F)
		{
			temp = 1.0F;
		}

		if (temp<0.0F)
		{
			temp = 0.0F;
		}

		Anim_FiniteDifferenceStart(modelresults3->models[0],fd_startframe);
		Anim_FiniteDifferenceMorphTo(modelresults3->models[0], fd_0to1, temp);
		Anim_FiniteDifferenceMorphTo(modelresults3->models[0], fd_1to2, onebitstart2/2.0F);
		Anim_FiniteDifferenceMorphTo(modelresults3->models[0], fd_1to3, onebitstart3/2.0F);
		Anim_FiniteDifferenceMorphTo(modelresults3->models[0], fd_1to3, (onebitstart3+onebitstart2)/2.0F);
		BrModelUpdate(modelresults3->models[0],BR_MODU_VERTICES);
	}

	return 0;
}
