#ifndef __GAME_SCENE_H__
#define __GAME_SCENE_H__

#include "cocos2d.h"
#include "HUDScene.h"
#include "Unit.h"
#include "Player.h"
#include "PRect.h"
#include "Item.h"

class GameScene : public cocos2d::Layer
{
protected:
	std::vector<Player*> _players;
	cocos2d::Follow* _camera;
	HUDScene* _hud; 
	std::vector<Unit*> _units;
	std::vector<Item*> _items;
	std::vector<PRect*> _rects;
	
	cocos2d::EventListenerKeyboard* _listener;
	cocos2d::Vector<Node*> _actions;
	
	std::vector<Item*> _meduses;

	bool _endless;
	int _count;
	int _deadCount;
	int _limit;
	int _limitStep;
	int _generationIndex;

	bool _endGame;
	bool _goodEnd;
	int _score;
public:
    // Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
	virtual bool init();  
    // there's no 'id' in cpp, so we recommend returning the class instance pointer
    static cocos2d::Scene* scene();
	static cocos2d::Scene* scene(int players, int mod, bool friendlyfire);
	static void initAdditionalViews(cocos2d::Scene* scene, GameScene* game);

	void setHUD(HUDScene* hud);

	virtual void removeUnit(Unit* remUnit);
	virtual void removeUnit(unsigned index);
	virtual Unit* createUnit(int type, cocos2d::Vec2 position, unsigned team);

	virtual void removeItem(unsigned index);
	virtual Item* createItem(
		int id,
		cocos2d::Vec2 position,
		unsigned team = BOT_TEAM,
		cocos2d::Vec2 direction =cocos2d::Vec2(0,0),
		float speed=0);

	void endButtonPressed(cocos2d::Ref* pSender);

    virtual void updateFunc(float dt);
	void UpdateDead();
	void UpdateRectsAndZOrder();
	void UpdateMovement();
	void UpdateAttacks(float dt);
	void UpdateHUD();
	void UpdateGeneration();

	
	void dispathAttacksFromString(std::string& data,std::vector<int>* vec);
	//void dispathBuildDataFromString(std::string& data,std::vector<BuildNeeds>* vec);

	void loadDB();
	
	virtual void goodEndGame();
	virtual void badEndGame();
	virtual int countScore();

	virtual void onExit();

	void OnKeyPressed(cocos2d::EventKeyboard::KeyCode keyCode, cocos2d::Event* event);
	void OnKeyReleased(cocos2d::EventKeyboard::KeyCode keyCode, cocos2d::Event* event);

	void additionalInit(int players, int mod, bool friendlyfire);

	void generateMeduse();

    // implement the "static node()" method manually
    CREATE_FUNC(GameScene);
};

#endif // __GAME_SCENE_H__
