#include "WorldManager.h"void InitWorld(VWorld * world) {	world->StartPos.x = 0.0;	world->StartPos.y = 0.0;	world->StartPos.z = 0.0;		InitCamera(&world->Camera);	world->Camera.Position = world->StartPos;	InitPlayer(&world->Player);		AllocateWObject(&world->Objects);	AllocateObject(world->Objects);	if (world->Objects->o != NULL) {		Vector targetPos;				InitObject(world->Objects->o);		BuildTargetModel(&world->Objects->o->Model);		targetPos.x = 2.0;		targetPos.y = 1.0;		targetPos.z = -7.0;		MoveObjectToPoint(world->Objects->o, &targetPos);		CalculateRadius(world->Objects->o);	}		InitObject(&world->CrossHair);	world->CrossHair.Position.x = 0.0;	world->CrossHair.Position.y = 0.0;	world->CrossHair.Position.z = -1.7;	BuildCrossHairModel(&world->CrossHair.Model);		InitObject(&world->Environment);	BuildGrassModel(&world->Environment.Model);	world->Environment.Position.x = 0.0;	world->Environment.Position.y = -2.0;	world->Environment.Position.z = 0.0;		InitObject(&world->Walls);	BuildWallsModel(&world->Walls.Model);	world->Walls.Position.x = 0.0;	world->Walls.Position.y = -2.0;	world->Walls.Position.z = 0.0;		AllocateWObject(&world->Objects->next);	AllocateEnemy(world->Objects->next);	InitEnemy(world->Objects->next->e, SmartShooterAI, world);	world->Objects->next->e->Object.Position.y = 1;	world->Objects->next->previous = world->Objects;		AllocateWObject(&world->Objects->next->next);	AllocateEnemy(world->Objects->next->next);	InitEnemy(world->Objects->next->next->e, DumbShooterAI, world);	world->Objects->next->next->e->Object.Position.y = 5;	world->Objects->next->next->previous = world->Objects->next;		AllocateWObject(&world->Objects->next->next->next);	AllocateEnemy(world->Objects->next->next->next);	InitEnemy(world->Objects->next->next->next->e, KamikazeAI, world);	world->Objects->next->next->next->e->Object.Position.x = 7;	world->Objects->next->next->next->e->Object.Position.y = 1;	world->Objects->next->next->next->previous = world->Objects->next->next;		InitPhysics(&world->Physics);}void InitPlayer(VPlayer * p){	p->NumRockets = INITIALROCKETS;	p->Shields = INITIALSHIELDS;}void AddWeapon(VWorld * world, int Type){	VWeapon * theWeapon;	Vector front;	VObjectWrapper * theWObject;		if((Type == WEAPONTYPEROCKET && world->Player.NumRockets > 0) || Type == WEAPONTYPEBULLET)	{		if(Type == WEAPONTYPEROCKET)			world->Player.NumRockets--;		theWeapon = (VWeapon *) NewPtr(sizeof(VWeapon));		if (theWeapon != NULL) {			InitWeapon(theWeapon, Type);			AllocateWObject(&theWObject);			theWObject->w = theWeapon;			theWObject->Type = VWEAPON;			theWObject->next = world->Objects;			if (world->Objects != NULL)				world->Objects->previous = theWObject;			world->Objects = theWObject;						ForwardsVector(&world->Camera, 1, &front);			StartWeapon(theWeapon, &world->Camera.Position, ((front.x * world->Physics.Momentum.x) + (front.y * world->Physics.Momentum.y) + (front.z * world->Physics.Momentum.z)), &front, &world->Camera.Up);		}	}}void CleanUpWorld(VWorld * world) {	VObjectWrapper * theWObject;	CleanUpObject(&world->CrossHair);		while(world->Objects != NULL)	{		theWObject = world->Objects;		world->Objects = theWObject->next;		CleanUpWObject(theWObject);		DisposePtr((Ptr) theWObject);	}}void DrawCrossHair(VWorld * world){	glPushMatrix();		glLoadIdentity();		glDisable(GL_DEPTH_TEST);		DrawObject(&world->CrossHair);		glEnable(GL_DEPTH_TEST);	glPopMatrix();}void DrawWorld(VWorld * world, float interval){	VObjectWrapper * theWObject;		/* Fill with semi transparent background */	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);	glDepthMask(GL_FALSE);	glColor4f(0.0, 0.0, 0.0, ALPHAFILL / interval);	glBegin(GL_QUADS);		glVertex3f(-10.0, 10.0, -2.0);		glVertex3f(10.0, 10.0, -2.0);		glVertex3f(10.0, -10.0, -2.0);		glVertex3f(-10.0, -10.0, -2.0);	glEnd();	glDepthMask(GL_TRUE);	glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);		ApplyCamera(&world->Camera);		DrawObject(&world->Environment);	DrawObject(&world->Walls);		for(theWObject = world->Objects; theWObject != NULL; theWObject = theWObject->next)	{		DrawWObject(theWObject);	}		DrawCrossHair(world);	DrawConsole(&world->Console);}/* Radius is NOT squared */Boolean InBounds(VWorld * world, Vector Pos, float Radius){	#pragma unused (world)		if(Pos.x < (-24.0 + Radius) || Pos.x > (24.0 - Radius) || 		Pos.z < (-24.0 + Radius) || Pos.z > (24.0 - Radius) || 		Pos.y < (-2 + Radius) || Pos.y > (46.0 - Radius))		return false;	return true;}void RunWorld(VWorld * world, float interval) {	VObjectWrapper * theWObject;	VObjectWrapper * obj;	VObjectWrapper * next;	VObjectWrapper * powerup;	Vector front;	Vector right;	Boolean exploded;		if((!InBounds(world, world->Camera.Position, sqrt(PLAYERSHIPRADIUS))) && world->Player.Shields > 0) {		DamagePlayer(world, world->Player.Shields);	}		powerup = NULL;	theWObject = world->Objects;	while(theWObject != NULL)	{		next = theWObject->next;		if(theWObject == NULL)			break;		RunWObject(theWObject, interval, world);				exploded = false;		if(theWObject->exploded == 1)		{			AllocateWObject(&obj);			AllocateExplosion(obj);			switch(theWObject->Type)			{				case VOBJECT:					InitExplosion(obj->ex, theWObject->o, 7);					AllocateWObject(&powerup);					AllocatePowerup(powerup);					InitPowerup(powerup->p);					SetupPowerup(powerup->p, POWERUPTYPEROCKETS, 5);					powerup->p->Object.Position = theWObject->o->Position;										CleanUpObject(theWObject->o);					DisposePtr((Ptr)theWObject->o);					break;				case VENEMY:					InitExplosion(obj->ex, &theWObject->e->Object, 7);					AllocateWObject(&powerup);					AllocatePowerup(powerup);					InitPowerup(powerup->p);					SetupPowerup(powerup->p, POWERUPTYPEHEALTH, 10);					powerup->p->Object.Position = theWObject->e->Object.Position;										CleanUpEnemy(theWObject->e);					DisposePtr((Ptr)theWObject->e);					break;				case VWEAPON:					InitExplosion(obj->ex, &theWObject->w->Object, theWObject->explosionLevel);					CleanUpWeapon(theWObject->w);					DisposePtr((Ptr)theWObject->w);					break;			}			exploded = true;		}				if(theWObject->exploded == 2)		{			AllocateWObject(&obj);			AllocateExplosion(obj);			switch(theWObject->Type)			{				case VOBJECT:					InitExplosion(obj->ex, theWObject->o, 1);					break;				case VENEMY:					InitExplosion(obj->ex, &theWObject->e->Object, 1);					break;			}						world->Objects->previous = obj;			obj->next = world->Objects;			world->Objects = obj;			theWObject->exploded = 0;		}				if(theWObject->taggedForRemoval)		{			if(theWObject->next)				theWObject->next->previous = theWObject->previous;			if(theWObject->previous)				theWObject->previous->next = theWObject->next;			else				world->Objects = world->Objects->next;			DisposePtr((Ptr)theWObject);		}				if(exploded)		{			if(world->Objects)				world->Objects->previous = obj;			obj->next = world->Objects;			world->Objects = obj;						if(powerup)			{				if(world->Objects)					world->Objects->previous = powerup;				powerup->next = world->Objects;				world->Objects = powerup;			}		}				theWObject = next;	}		ForwardsVector(&world->Camera, 1.0, &front);	CrossProduct(&world->Camera.Up, &front, &right);	RunPhysics(&world->Physics, &world->Camera.Position, &front, &right, &world->Camera.Up, interval);	AddVector(&world->Camera.Position, &front, &world->Camera.Look);}void DamagePlayer(VWorld * world, int amount) {  world->Player.Shields -= amount;  if (world->Player.Shields <= 0) {    InitCamera(&world->Camera);    InitPhysics(&world->Physics);    InitPlayer(&world->Player);  }}