#include "global.h"
#include "Piece.h"
#include "TextureLoader.h"

using namespace std;

extern GLuint g_fighterList;
extern GLuint g_knightList;
extern GLuint g_propellerList;
extern GLuint g_pickList;
extern GLuint g_carList;
extern GLuint g_killnerList;
extern glTexture g_fighterTexture;
extern glTexture g_knightTexture;
extern glTexture g_propellerTexture;
extern glTexture g_pickTexture;
extern glTexture g_carTexture;
extern glTexture g_killnerTexture;
extern struct obj_model_t objfile;

CPiece::CPiece(int r, int c)
{
	m_row = r;
	m_col = c;
	m_size = 0.05;
	chooseType();
}

CPiece::~CPiece(void)
{
}

void CPiece::draw()
{
	glColor3f(1.0, 1.0, 1.0);
	glLoadIdentity();
	
	GLfloat translateX = (((GLfloat) m_col - ((GLfloat) k_numCols/2.0)) * m_size * k_spacing) + 0.125;
	GLfloat translateY = (((GLfloat) m_row - ((GLfloat) k_numRows/2.0)) * m_size * k_spacing) + 0.125;
	glTranslatef(translateX, translateY, 0.0);
	//glutSolidTeapot(m_size); 

	switch (m_type)
	{
	case k_PIECE_FIGHTER:
		glBindTexture(GL_TEXTURE_2D, g_fighterTexture.TextureID);
		glCallList(g_fighterList);
		break;
	case k_PIECE_KNIGHT:
		glBindTexture(GL_TEXTURE_2D, g_knightTexture.TextureID);
		glCallList(g_knightList);
		break;
	case k_PIECE_PROPELLER:
		glBindTexture(GL_TEXTURE_2D, g_propellerTexture.TextureID);
		glCallList(g_propellerList);
		break;
	case k_PIECE_PICK:
		glBindTexture(GL_TEXTURE_2D, g_pickTexture.TextureID);
		glCallList(g_pickList);
		break;
	case k_PIECE_CAR:
		glBindTexture(GL_TEXTURE_2D, g_carTexture.TextureID);
		glCallList(g_carList);
		break;
	case k_PIECE_KILLNER:
		glBindTexture(GL_TEXTURE_2D, g_killnerTexture.TextureID);
		glCallList(g_killnerList);
		break;
	default:
		break;
	}
}

void CPiece::chooseType()
{
	m_type = (pieceType)(rand() % k_numPieces);
}
