/*
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.
*/

#define OBJ_TYPE_SCOUT 0
#define OBJ_TYPE_FIGHTER 1
#define OBJ_TYPE_BOMBER 2
#define OBJ_TYPE_REPAIRSHIP 3
#define OBJ_TYPE_CAPITALSHIP 4
#define OBJ_TYPE_ADV_FIGHTER 5
#define OBJ_TYPE_IMMOBILE_TURRET 6
#define OBJ_TYPE_ADV_BOMBER 7
#define OBJ_TYPE_REPAIRTURRET 8

#define OBJ_TYPE_TURRET 100

class CObjectData
{
private:
public:
	int id;
	int type;
	int maxHealth;
	
	//collision box
	float width;
	float height;
	float radius;
	
	float acceleration;
	float maxSpeed;
	float strafeSpeed;
	float turnRate;
	
	CModel* model;

	CProjectileData* projectile;
	float attackRange;
	
	Vector turretOffset;	
	CObjectData* turret;
	CObjectData* prevData;
	CObjectData* nextData;
	
	CObjectData();
	~CObjectData();
};

CObjectData::CObjectData()
{
	model = NULL;
	projectile = NULL;
	turretOffset = CreateVector(0,0);
	turret = NULL;
	prevData = NULL;
	nextData = NULL;
}

CObjectData::~CObjectData()
{
	if (model)
		delete model;
	model = NULL;
}

CObjectData* g_firstObjectData = NULL;

//Just quickly places the object data at the beginning of the linked list
CObjectData* AddObjectData(int id)
{
	CObjectData* newData;
	newData = new CObjectData();
	if (!newData)
		return NULL;
	newData->nextData = g_firstObjectData;
	if (g_firstObjectData)
		g_firstObjectData->prevData = newData;
	g_firstObjectData = newData;
	newData->id = id;
	return newData;
}

void DeleteObjectData(CObjectData* data)
{
	if (!data)
		return;

	if (data->prevData)
		data->prevData->nextData = data->nextData;
	else
		g_firstObjectData = data->nextData;
	if (data->nextData)
		data->nextData->prevData = data->prevData;
	delete data;
}

CObjectData* FindObjectData(int id)
{
	CObjectData* data = g_firstObjectData;
	while (data)
	{
		if (data->id == id)
			return data;
		data = data->nextData;
	}
	return NULL;
}

void DeleteAllObjectData()
{
	CObjectData* curData;
	CObjectData* tmpData;
	curData = g_firstObjectData;
	while (curData)
	{
		tmpData = curData->nextData;
		delete curData;
		curData = tmpData;
	}
	g_firstObjectData = NULL;
}
