/*
 * Entity.h
 *
 *  Created on: 2009-07-10
 *      Author: wasyl
 */

#ifndef ENTITY_H_
#define ENTITY_H_

#include <cstdio>
#include <string>
#include "../misc/Vector2D.h"
#include "../misc/SPrintF.h"

#define ID(str) (((str[3] * 256 + str[2]) * 256 + str[1]) * 256 + str[0])

class World;

/**
 * Represents entities in the game world.
 */
class Entity
{
protected:
	World *mWorld;
	Vec mPos;

	int loadByte(FILE *f);
	void saveByte(FILE *f, int b);
	virtual const char *code() { return "XX"; };

public:

	virtual ~Entity(){};
	virtual void discard();
	virtual int *indices()
	{
		static int t[1] = {0};
		return t;
	}

	virtual int order(int index) { return (int)this; }

	World *world() { return mWorld; }
	void setWorld(World *world) { mWorld = world; }

	virtual Vec pos() { return mPos; }
	virtual double x() { return mPos.x; }
	virtual double y() { return mPos.y; }
	virtual void setPos(Vec pos) { mPos = pos; }
	virtual void setX(double x) { mPos.x = x; }
	virtual void setY(double y) { mPos.y = y; }

	virtual void update(double dt) {}
	virtual void render() {}
	virtual Rect bbox() { return Rect(0,0,0,0); }

	virtual void save(FILE *f);
	virtual void load(FILE *f);
	virtual Entity *clone() { return NULL; };
	virtual std::string edString() { return ""; };
};

#endif /* ENTITY_H_ */
