/*
Solar Conquest
Copyright (C) 2006 Greg Beaman

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

class CFactory
{
public:
	int team;
	int obj;
	int aiType;
	CFactory* aiParent;

	float spawnTime;
	
	Vector position;
	
	CFactory* nextObj;
	CFactory* prevObj;
	
	CObject* parent;
	
	CFactory();
	~CFactory();
	
	void Update(float elapsedTime);
	void Render(float cameraX, float cameraY);
};

CFactory::CFactory()
{
	spawnTime = 0;
	
	nextObj = NULL;
	prevObj = NULL;
	parent = NULL;

	aiParent = NULL;
	aiType = AI_TYPE_NORMAL;
	obj = -1;
}

CFactory::~CFactory()
{
}

void CFactory::Update(float elapsedTime)
{
	if (spawnTime > 0)
		spawnTime -= elapsedTime;
}

void CFactory::Render(float cameraX, float cameraY)
{
	//Render
	if (team == 1)
		glColor4f(0,0,1,0.4);
	else if (team == 2)
		glColor4f(1,0,0,0.4);
	else
		glColor4f(1,1,1,0.4);
	
	if (Distance(cameraX+(g_screenWidth/2),cameraY+(g_screenHeight/2),position.x,position.y) <= ((g_screenWidth)+30))
	{
		glBegin(GL_TRIANGLE_FAN);
			glVertex2f(position.x-cameraX,position.y-cameraY);
			{
			for (int i=0; i <= 8; i++)
				glVertex2f((GetSin(ToRadians(360/8)*i)*30)+(position.x-cameraX),(GetCos(ToRadians(360/8)*i)*30)+(position.y-cameraY));
			}
		glEnd();
	
		glBegin(GL_LINE_STRIP);
			{
			for (int i=0; i <= 8; i++)
				glVertex2f((GetSin(ToRadians(360/8)*i)*30)+(position.x-cameraX),(GetCos(ToRadians(360/8)*i)*30)+(position.y-cameraY));
			}
		glEnd();
	}
}

CFactory* g_firstFactory = NULL;

CFactory* AddFactory()
{
	CFactory* newObj;
	newObj = new CFactory();
	if (!newObj)
		return NULL;
	newObj->nextObj = g_firstFactory;
	if (g_firstFactory)
		g_firstFactory->prevObj = newObj;
	g_firstFactory = newObj;
	
	return newObj;
}

void DeleteFactory(CFactory* node)
{
	if (!node)
		return;

	if (node->prevObj)
		node->prevObj->nextObj = node->nextObj;
	else
		g_firstFactory = node->nextObj;
	if (node->nextObj)
		node->nextObj->prevObj = node->prevObj;
	delete node;
}

void DeleteAllFactories()
{
	CFactory* curObj;
	CFactory* tmpObj;
	curObj = g_firstFactory;
	while (curObj)
	{
		tmpObj = curObj->nextObj;
		delete curObj;
		curObj = tmpObj;
	}
	g_firstFactory = NULL;
}


