#ifndef XRPG_IFACE_H
#define XRPG_IFACE_H

#include "../core/ge_iface.h"
#include "../core/ie_iface.h"
#include "../core/se_iface.h"

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>

using namespace ge;
using namespace ie;
using namespace se;
using namespace std;

namespace xrpg
{
	enum ZTextures
	{
		TEXTURE_FONT		= 4,
		TEXTURE_SYSTEM		= 5,
		TEXTURE_ICONS		= 6,
		TEXTURE_CHARS		= 7,

		TEXTURE_TITLE		= 9,

		TEXTURE_GRASS		= 10,
		TEXTURE_FOREST		= 11,
		TEXTURE_SNOW		= 12,
		TEXTURE_SWAMP		= 13,
		TEXTURE_DESERT		= 14,
		TEXTURE_WASTELAND	= 15,
		TEXTURE_GALAXY		= 16
	};

	enum ZGameState
	{
		STATE_BEGIN			= 0,
		STATE_WORLD			= 1,
		STATE_GOTO_NEXT		= 2,
		STATE_INCREASE		= 3,
		STATE_CUR_EVENT		= 4,
		STATE_DECREASE		= 5,
		STATE_GAME_OVER		= 6
	};

	enum ZGameEvent
	{
		EVENT_UNKNOWN		= 0,

		EVENT_SHOP			= 1,
		EVENT_FORGE			= 2,
		EVENT_ROGUES		= 3,
		EVENT_WITCH			= 4,

		EVENT_SLIME			= 5,
		EVENT_SKELETON		= 6,
		EVENT_ZOMBIE		= 7,
		EVENT_WEREWOLF		= 8,
		EVENT_MINOTAUR		= 9,
		EVENT_GOLEM			= 10,
		EVENT_ANGEL			= 11,
		EVENT_TANATOS		= 12,
		EVENT_DRAGON		= 13
	};

	struct ZEvent
	{
		ZGameEvent type;
		int hp, atk, ex, gld;
		int tex_x, tex_y;
		string title, desc;
	};

	struct ZDelta
	{
		int x, y;
		int delta;
		int cntd;
		ZDelta( int _x, int _y, int _d )
		{
			x = _x;
			y = _y;
			delta = _d;
			cntd = 100;
		}
	};

	class ZXRPG
	{
		int _cntd;
		ZGameState _state;
		int _frame;

		int _world, _cur_e;
		int _exp, _lvl, _hp, _gld, _pot;
		int _atk, _def;

		ZEvent _evs[10];

		vector< ZDelta > delta_vec;
		queue< string > _messages;

		void d_hp( int d ) { _hp += d; if (_hp<0) _hp = 0; if (_hp>100) _hp=100;
			delta_vec.push_back( ZDelta(50, 35, d) ); }
		void d_atk( int d ) { _atk += d; delta_vec.push_back( ZDelta(110, 35, d) ); }
		void d_def( int d ) { _def += d; delta_vec.push_back( ZDelta(170, 35, d) ); }
		void d_gld( int d ) { _gld += d; delta_vec.push_back( ZDelta(230, 35, d) ); }
		void d_pot( int d ) { _pot += d; delta_vec.push_back( ZDelta(290, 35, d) ); }

		void d_e_hp( int d ) { _evs[_cur_e].hp += d; if (_evs[_cur_e].hp<0) _evs[_cur_e].hp = 0;
			delta_vec.push_back( ZDelta(160, 105, d) ); }

		int get_atk() { return _lvl*6+_atk; }
		int get_def() { return _lvl*2+_def; }

		void reset();
		void gen();

	public:
		ZXRPG();

		bool do_frame( XInputEngine * IE, XSoundEngine * SE );
		void draw_frame( XInputEngine * IE, XGraphicEngine * GE );
	};
};

#endif