/***************************************************************************
 *   Copyright (C) 2004-2005 by                                            *
 *     Paolo Sacconier   <axa1981@tin.it>                                  *
 *     Francesco Tamagni <minchiahead@hacari.org>                          *
 *                                                                         *
 *   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.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#ifndef GILLOENTITY_H
#define GILLOENTITY_H

#include "main.h"
#include "context.h"

namespace gillo {

/**
Entity base class

@author ,,,
*/
class Entity{

public:
	enum Type {
		DEFAULT,
		BALL,
		FIELD,
		CAR,
		CUBE,
		GOAL,
		GOALKEEPER,
		PWRUP
	};
	
	enum Move {
		GO_FWRD,
		GO_BWRD,
		GO_STOP,
		TURN_LEFT,
		TURN_RIGHT,
		TURN_STOP,
		FIRE,
		JUMP,
		JUMP_STOP
	};
	
	virtual ~Entity();

	static const float defaultCharge = 10;
	float charge;
	float timeOfRemoval;
	
	virtual void update(float dt);
	virtual void move(Move m);
	virtual void getPos(sgVec3 out);
	virtual void setPos(double x, double y, double z);
	void setVel(double x, double y, double z);
	virtual void getMagnetPos(sgVec3 out);
	virtual void getMagnetDir(sgVec3 out);
	virtual void addForce(sgVec3 force);
	virtual void getUpVector(sgVec3 out);
	
	inline Type getType() { return type; }
	
	inline dBodyID getBid(dGeomID g = 0) { if (g) return dGeomGetBody(g); else return bid; }
	inline dGeomID getGid() { return gid; }
	
	inline ssgTransform*	getTransPtr()	{ return &trans; }
	
	char* toString();
	inline bool isA(Type t) { return (this->type == t); }
	inline bool hasBall() { return this->stickyBall; }
	
	static inline bool isPair(Entity* e1, Entity* e2, Type t1, Type t2) { return ((e1->isA(t1) && e2->isA(t2)) || (e2->isA(t1) && e1->isA(t2))); }
	static void odeTrans2ssgTrans(const dBodyID bid, ssgTransform& sgt);
	static void ssgRot2odeRot(const dGeomID gid, ssgTransform& sgt);
	static void transform(ssgTransform* t, float angle, float scale);
	
protected:
	Context& context;
	ssgTransform& trans; // don't worry it's refcounted :)
	ssgTransform& alphaTrans;
	dGeomID gid;
	dBodyID bid;
	Type type;
	bool stickyBall;
	bool shifting;
	double shiftForce[3];
	char string[256]; //@fixme
	
	Entity(Context& c);
	void Init();
	void startShifting(double x, double y, double z);
	void stopShifting();
};

};

#endif
