/** 
 * \file Level.h
 * \brief Header file containing CLevel class and actual game level objects.
 * 
 * \author Petar Bajic, MPE (C) All Rights Reserved, Homepage: www.mystic-peanut.com
 * \date January, 16 2007.
 */

#include "d3dx9.h"
#include "Terrain.h"
#include "Media.h"
#include "Sound.h"
#include "XFileEntity.h"
#include "Turtle.h"
#include "Sheep.h"
#include "Dwarf.h"
#include "Particles.h"
#include "LevelUtils.h"
#include "Level2D.h"
#include "MagicFlower.h"

#include <vector>
using namespace std;

#define LEVEL_RETURN_MENU  1
#define LEVEL_RETURN_BONUS 2
#define LEVEL_RETURN_PAUSE 3

#define DWARFMOVESPEED 10

#define LEVEL_OUTCOME_SUCCESS 0
#define LEVEL_OUTCOME_SHEEPSTOLEN 1
#define LEVEL_OUTCOME_SHEEPSHOT 2

#define VK_W	0x57	//W key 
#define VK_S	0x53	//S Key
#define VK_A	0x41	//A Key
#define VK_D	0x44	//D Key
#define VK_Q	0x51	//Q Key
#define VK_E	0x45	//E Key

class CLanguage;

/**
 * \brief Level class handles gameplay level action, and draws everything on the screen.
 *
 * This class is responsible for handling all level action and drawing all level models.
 * All calculations are processed in function OnFrameMove(), and rendering is done in function OnRender().
 * \author Petar Bajic \date January, 16 2007.
 */
class CLevel {

public:

	CLevel();
	~CLevel();

	bool Init(HWND hWnd, LPDIRECT3DDEVICE9 pd3dDevice, int screenWidth, int screenHeight, IDirectSound8* pDS, CTerrain* pTerrain, CTurtle* pTurtle, CSheep* pSheep, CLanguage* language);
	bool OnEvent(LPDIRECT3DDEVICE9 pd3dDevice, IDirectSound8* pDS, HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, int* code);
	void SetupMatrices(LPDIRECT3DDEVICE9* ppd3dDevice, D3DXVECTOR3* eye, D3DXVECTOR3* lookAt, D3DXVECTOR3* upVec);
	void OnFrameMove(LPDIRECT3DDEVICE9 pd3dDevice, double fTime, float fElapsedTime);
	void OnRender(LPDIRECT3DDEVICE9 pd3dDevice, float fElapsedTime, int counter);
	void LevelStart(float hardness, bool details, CSheep* pSheep);
	void ReleaseSheeps();
	void LevelRestart();
	void WindowMove(HWND hWnd, int screenWidth, int screenHeight);
	void LevelShutDown();
	void OnLostDevice();
	void UnPause();
	void Pause();
	void OnResetDevice(HWND hWnd, LPDIRECT3DDEVICE9 pd3dDevice, int screenWidth, int screenHeight);

	void UpdateTurtlePosition(float fElapsedTime);
	void AI_MoveDwarf(CDwarf* dwarf);
	void AddDwarf();
	void ScheduleGameAction(float fElapsedTime);
	CSheep* FindClosestSheep(CDwarf *dwarf);
	void RedirectOtherDwarfs();
	void DistributeSheepsForStart();

	CTerrain*	m_pTerrain;
	CMedia*		m_plevelTheme; //Music
	CTurtle*	m_pTurtle;
	std::vector<CSheep*> m_Sheeps;
	std::vector<CDwarf*> m_Dwarfs;

	CSound*		m_shootingSound;
	CSound*		m_MFSoundDouble;
	CSound*		m_MFSoundHarmless;
	CGun*		m_gun;
	CLevel2D*	m_draw2D;
	CLanguage*	m_Language;

	CMagicFlower*	m_pMFDouble;
	CMagicFlower*	m_pMFHarmless;

	float	m_aspectRatio;
	float	m_AdjustMovement;
	bool	m_LevelFinished;
	int		m_LevelOutcome;
	bool	m_LevelPaused;
	bool	m_LevelDetails;
	float	m_LevelHard;
	bool	m_CAPSLOCK;
	double	m_Timer;
	int		m_LevelNumber;
	int		m_LivesNumber;
	int		m_MousePosX;
	int		m_MousePosY;
	float	m_EyeY;
	bool	m_GunDouble;
	bool	m_GunHarmless;
};