#pragma once

#include	"..\..\BasicWindow\Engine.h"
#include	"..\..\\Bitmap\Bitmap.h"
#include	"..\..\Button\Button.h"
#include	"The Forging Enumerations.h"
#include	"..\..\Map\IsoHexTile.h"
#include	"..\..\clientviews\NewPlayWindow.h"
#include	"..\..\clientviews\NewPlayWinVariables.h"
#include	"..\..\Avatars\Avatar.h"
#include	"MapLinks.h"
#include	"MapPath.h"
#include	"..\..\instruction\instruction.h"
#include	"StartLocation.h"
#include	"InScreenMsg.h"
#include	"..\..\Campaign\Campaign.h"

int myTestNum = 0;
//Engine Related - M. White 21 March, 2019
#define				_FPS				16
bool				_bPlayersTurn		= true;
int					_CmbtCnt			= 0;
Engine				*_pEngine			= NULL;
Instruction			*_TheWizard			= NULL;
InScreenMsg			*_MSG				= NULL;
DWORD				_Style				= WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_VISIBLE;
int					_EngineCommand		= SW_MAXIMIZE;
RECT				_cliRect;
int					_EngineWidth		= 100;			//Starting  Width of Client Rect - M. White 21 March, 2019 (temporary)
int					_EngineHeight		= 100;			//Starting Height of Client Rect - M. White 21 March, 2019 (temporary)
int					_MouseDelay			= 0;
int					_KBoardDelay		= 0;
int					_XMouse				= 0;
int					_YMouse				= 0;
int					_MonitorCat			= 0;
//This counter used to wait for the ShowWindow to activate, 
//and then get measurements in GameStart() - M. White 10 March, 2019
int					_GameStartCount		= int(_FPS / 2);
int					_SplashCount		= 100;
time_t				_timer;
//Thread Stuff
string				_FileNameMap		= "";
string				_FileNameLinks		= "";
string				_FileNameMobs		= "";
string				_FileNamePaths		= "";
string				_FileNameFOW		= "";
HANDLE				_myHandleOne		= NULL;
HANDLE				_myHandleTwo		= NULL;
HANDLE				_myHandleThr		= NULL;
HANDLE				_myHandleFou		= NULL;
HANDLE				_myHandleFiv		= NULL;
DWORD				_myThreadIDOne;
DWORD				_myThreadIDTwo;
DWORD				_myThreadIDThr;
DWORD				_myThreadIDFou;
DWORD				_myThreadIDFiv;
int					_PercentCounter		= 0;
int					_PercentTotal		= 0;
bool				_IsLoading			= false;
bool				_IsLoadingFOW		= false;
bool				_IsLoadingMobs		= false;
bool				_LoadCampaign		= false;
int					_GAMEPHASE			= phSplashScrn;
int					_GAMEsubPHASE		= 0;

bool				_ClickedSuperChicken = false;

bool				_ShowAnAvatar		= false;
RECT				_PlayScrnAvatar;

RECT				_RectMenu;
RECT				_RectSubMenu;
RECT				_MenuBackGrnd;
RECT				_ShadowRect;						//Shadow is area where User is hoving over an option - M. White 10 May, 2019
RECT				_RectHorSlidePer;
int					_intHorSlideLocation;

RECT				_RectName;
RECT				_RectRace;
bool				_OpenRaceScreen		= false;
RECT				_RectClass;
bool				_OpenClassScreen	= false;
RECT				_RectKit;
bool				_OpenKitScreen		= false;
RECT				_RectAlign;
bool				_OpenAlignScreen	= false;
RECT				_WeaponPros;
bool				_OpenWeapons		= false;	
RECT				_RectPort;
RECT				_RectStartTown;
bool				_OpenStartTown		= false;
int					_PortraitsW;		
int					_PortraitsH;		
int					_MaxPortraits;
string				*_SideBarMenuStr	= NULL;
RECT				_SideBarMenu;
RECT				_SideBarBackGrnd;
int					_SideBarMenuIndex;
int					_WhichSubMenu		= 0;			//Cancel, Continue, etc - M. White 10 May, 2019
RECT				_MiniWindow;
RECT				_MiniMap;
int					_ScrollIndex		= 0;
int					_NumBarMenuItems;
int					_EditingTarget1		= -1;			//This holds User's active choice to use as data input (editor) - M. White 10 May, 2019
int					_EditingTarget2		= -1;			//This holds User's active choice to use as data input (editor) - M. White 10 May, 2019
int					_edOpenMCNum		= 1;			//Editor's Open Map Category Number - Terrain, Coastal, etc - M. White 10 May, 2019
int					_EditorFocusIndex	= 0;			//Which edit box (rect) is the User focused on typing in - M. White 10 May, 2019
bool				_bHiddenMap			= true;
bool				_bMonstersMad		= true;

bool				_ShowUserInput		= false;
bool				_ShowPickAvatar		= false;
RECT				_rctPickAvatar;
int					_pickAvScrollIndex	= 0;
bool				_edNewWorldTrue		= false;
bool				_edEditingWorld		= false;
bool				_edNewSceneTrue		= false;
bool				_edEditingScene		= false;

bool				_edLinkingMaps		= false;
bool				_edIntLinking		= false;
bool				_edAssignStartPnt	= false;
bool				_edPathAssignmens	= false;
bool				_edJustClickedIndex = false;
InternalMapLink		_tmpLS;
bool				_edLoadScrnDestMap	= false;
bool				_edDestMapWorld		= true;
bool				_StillEditing		= true;
bool				_edOpenTrue			= false;
bool				_edSaveTrue			= false;
bool				_edDeleteTrue		= false;
bool				_edOpenMapCategory	= false;		//This is the drop-down text to chose terrain categories - M. White 10 May, 2019
bool				_Dispersion			= false;		//_Dispersion is input of single- or multi-tile input - M. White 10 May, 2019
string				_EditorStr3letters	= "";
string				_Editor_W_S_Name	= "";
char				_SingleChar;
List<string>		_ListWorldScenes;
MapLinks			*_MapLink			= NULL;
List<StartLocation> _startPoints;
StartLocation		*_tmpStartLoc		= NULL;
Campaign			*_CampaignsAvail	= NULL;
Campaign			*_ActiveCampaign	= NULL;
int					_NumCampaigns		= 0;
int					_NumWSs				= -1;
int					_ListIndex			= 0;
int					_NumLinesToList		= 0;

RECT				_MapSliderVert;
RECT				_MapSliderHori;

int					_bmpY				= 0;			//used to know where to get Cursor from source BMP - M. White 21 March, 2019
int					_MAPVIEW			= 0;
int					_VisLightArray[64][64];
int					_MaxColsSQR_Map		= 0;			//Max viewable Columns for Play Window - M. White 21 March, 2019
int					_MaxRowsSQR_Map		= 0;			//Max viewable Rows    for Play Window - M. White 21 March, 2019
int					_MaxColsDIA_Map		= 0;			//Max viewable Columns for Play Window - M. White 21 March, 2019
int					_MaxRowsDIA_Map		= 0;			//Max viewable Rows    for Play Window - M. White 21 March, 2019
int					_MaxColsRHO_Map		= 0;			//Max viewable Columns for Play Window - M. White 21 March, 2019
int					_MaxRowsRHO_Map		= 0;			//Max viewable Rows    for Play Window - M. White 21 March, 2019
int					_MaxColsHEX_Map01	= 0;			//Max viewable Columns for Play Window - M. White 21 March, 2019
int					_MaxRowsHEX_Map01	= 0;			//Max viewable Rows    for Play Window - M. White 21 March, 2019
int					_MaxColsHEX_Map02	= 0;			//Max viewable Columns for Play Window - M. White 21 March, 2019
int					_MaxRowsHEX_Map02	= 0;			//Max viewable Rows    for Play Window - M. White 21 March, 2019

//these are to be used to test a file's data limits in case
//the User accepted a file from another person - M. White
int					_LoadedMapLimitL	= 0;
int					_LoadedMapLimitR	= 0;
int					_LoadedMapLimitT	= 0;
int					_LoadedMapLimitB	= 0;
/*
	_MapLimitL = _PlayWin[_MAPVIEW].GetCentCol();
	_MapLimitR = _TactMapW - _PlayWin[_MAPVIEW].GetCentCol();
	_MapLimitT = _PlayWin[_MAPVIEW].GetCentRow();
	_MapLimitB = _TactMapH - _PlayWin[_MAPVIEW].GetCentRow();
*/
myButton			*_Buttons			= NULL;
myButton			*_tmpSingleBtn		= NULL;
myButton			*_tmpSubBtn			= NULL;
myButton			*_MenuScrUpDwn		= NULL;			//The scroll buttons for side-bar menu screen - M. White 15 May, 2019
myButton			*_WorldSceneUpDwn	= NULL;
myButton			*_ResetMobs			= NULL;
int					_NumTmpSubBtn		= 0;
int					_NumTmpSingBtn		= 0;
int					_NumBtns			= 0;			//How many buttons assigned to *_Buttons - M. White 10 May, 2019

int					_tmpWizIndex		= 0;

int					_BckGrndIndex		= 0;
int					_ShipType			= 0;			//0 = Wedge Ship, 1 = Battlestar

//Tile Sizes for assignment...
int					_TileW_Sqr			= 0;
int					_TileH_Sqr			= 0;
int					_TileW_SqI			= 0;
int					_TileH_SqI			= 0;
int					_TileW_Iso			= 0;
int					_TileH_Iso			= 0;
int					_TileW_Hex01		= 0;
int					_TileH_Hex01		= 0;
int					_TileW_Hex02		= 0;
int					_TileH_Hex02		= 0;
double				_PercentToUseWidth	= 0.0;
double				_PercentToUseHeigh	= 0.0;

//Location Coordinates for tracking where the screen will print
//These would be based upon some Avatar that the player is controlling at the time
int					_TileWalkFacing		= 0;
int					_TileWalkerX		= 0;
int					_TileWalkerY		= 0;

//Define a Tactical Map 
#define				_TactMapW			512
#define				_TactMapH			512
IsoHexTile			_TactMap			[_TactMapW][_TactMapH]; //Can double as "World Map" for large scale movement - M. White 25 April, 2019
IsoHexTile			_TactMapBack		[_TactMapW][_TactMapH]; //Used to flip speedily between maps - M. White 16 June, 2019
bool				_edShowMapOfInt		= true;

//These four maps are used to show local ground movement as Avatars walk. There are four
//for when a User's view approaches the edges of a map section and the view has to know 
//what the data is for the next map over is. There is a maximum potential of four visible
//maps at one time if the user is at the corners. It is recommended that each of these 
//maps is larger than the Play Window to help reduce how often new maps are loaded - M. White 25 April, 2019
//IsoHexTile		_LocalMapA			[_TactMapW][_TactMapW];
//IsoHexTile		_LocalMapB			[_TactMapW][_TactMapW];
//IsoHexTile		_LocalMapC			[_TactMapW][_TactMapW];
//IsoHexTile		_LocalMapD			[_TactMapW][_TactMapW];

int					_EditHexTileNum		= 0;//Going to be used for a map editor later...

bool				_ShowTestData		= false;
bool				_WasMinimized		= true;
bool				_paintSomething		= true;
bool				_paintWholeScrn		= true;
bool				_paintMainMap		= false;
bool				_paintButtons		= false;//gets set to true in paintWholeScrn
bool				_PaintSideBar		= false;
bool				_PaintTheWizard		= false;

HDC					_OffScrnDC;
HBITMAP				_OffScrnBmp;

#define				NUM_BGs				5
int					_bgHeigh			= 0;
int					_bgWidth			= 0;
Bitmap				*_bmpBG				= NULL;
Bitmap				*_bmpCursors		= NULL;
Bitmap				*_bmpTiles			= NULL;
Bitmap				*_bmpTrim			= NULL;
Bitmap				*_bmpSpcEff			= NULL;
Bitmap				*_bmpCompFace		= NULL;
Bitmap				*_bmpRedShip		= NULL; 
Bitmap				*_bmpButtons		= NULL;
Bitmap				*_bmpMultiUse		= NULL;
Bitmap				*_bmpJunk			= NULL;
Bitmap				*_bmpSQR			= NULL;
Bitmap				*_bmpTrimmed		= NULL;
Bitmap				*_bmpPortraits		= NULL;
Bitmap				*_bmpBGParch 		= NULL;
Bitmap				*_bmpCoastalImgs	= NULL;
Bitmap				*_bmpRiverRoads		= NULL;
Bitmap				*_walls002			= NULL;
Bitmap				*_bmpMobImages		= NULL;
Bitmap				*_bmpMobImagesMap	= NULL;
Bitmap				*_bmpPathLinks		= NULL;
Bitmap				*_bmpFOW			= NULL;
Bitmap				*_bmpAlienSpeak		= NULL;
Bitmap				*_bmpMiniMap		= NULL;
int					_numWallTypes002	= 0;
//This integer -
// Number of Rivers and Roads, horizontally measured
// - takes the bitmap and divides it width by the 
//width of the Tiles to calculate - M. White 31 May, 2019
int					_numRiverRoadsHori	= 0;
Bitmap				*_bmpDispersionImg	= NULL;

//Path Stuff...
MapPath				*_EditPath			= NULL;
MapPath				*_MapPaths			= NULL;
MapPath				*_SwapPath			= NULL;
PathNode			*_WorkingNodeLead	= NULL;	//User's target location...
PathNode			*_WorkingNodeFoll	= NULL; //Following the location...
int					_NumNodesWorking	= 0;
int					_NumPathsOnMap		= 0;
bool				_bLoadPath			= false;
bool				_bLoadMobs			= false;

void				InitPlayScrn		(int X, int Y);
void				LMouse				(int X, int Y);
void				RMouse				(int X, int Y);
void				PaintMiniMap		(HDC hDC);
void				CreateButtons		(int Scrn);
void				GetTacticalMapData	(int Screen);
void				GetSqrIsoMapData	();
void				GetSqrMapData		();
void				GetIsoMapData		();
void				GetHex01MapData		();
void				GetHex02MapData		();
void				RandomTactMap		();
void				PaintAShadow		(HDC hDC, int Red, int Grn, int Blu, RECT &rect);
void				PaintBorderTrim		(HDC hDC);
void				InvertedTrimRect	(HDC hDC, RECT rect);
void				TextBoxTrim			(HDC hDC, RECT rect, int NumRows);
void				ThinTrimBox			(HDC hDC, RECT rect, int Red, int Green, int Blue);
RECT				_rctFake;
int					_intFake;
bool				_bFakeLoad			= false;
void				FakeProgressBar		(HDC hDC, int Red, int Green, int Blue);
void				PaintSplashScrn		(HDC hDC);
void				PaintPlayScrn		(HDC hDC);
void				PaintEditor			(HDC hDC);
void				PaintMainMenu		(HDC hDC);
void				PaintNewGame		(HDC hDC);
void				TabFlipMapType		(int index);
void				ResetIntLinkStruct	();
int					Roll4D6				();
int					RollSomeDice		(int Num, int Side);
int					VRD					(int StartingY, int MouseY, int Divisor = _bmpTrimmed->GetHeight());//Verticle Rectangle Divisor
bool				LoadData			(int WorldORScene);
DWORD WINAPI		LoadWorldScene		(LPVOID lpParameter);
DWORD WINAPI		SaveWorldScene		(LPVOID lpParameter);
DWORD WINAPI		LoadLinks			(LPVOID lpParameter);
DWORD WINAPI		SaveLinks			(LPVOID lpParameter);

DWORD WINAPI		LoadMobsEditor		(LPVOID lpParameter);
DWORD WINAPI		SaveMobsEditor		(LPVOID lpParameter);

DWORD WINAPI		LoadMobList			(LPVOID lpParameter);
DWORD WINAPI		SaveMobList			(LPVOID lpParameter);
DWORD WINAPI		LoadStartPoints		(LPVOID lpParameter);
DWORD WINAPI		SaveStartPoints		(LPVOID lpParameter);
DWORD WINAPI		LoadSavePaths		(LPVOID lpParameter);
DWORD WINAPI		LoadSaveAvatars		(LPVOID lpParameter);
DWORD WINAPI		LoadFOW				(LPVOID lpParameter);
DWORD WINAPI		SaveFOW				(LPVOID lpParameter);
void				MobAI				();
void				DeleteCharacter		(string txtFileName);
void				SaveBasicAvatar		(int AvatarUI);
void				LoadBasicAvatar		(int AvatarUI);
void				SaveBaseAvatarList	();
void				LoadBaseAvatarList	();
void				SaveGame			(int index);
void				LoadGame			(int index);
void				LoadCampaignToDelete(int index);
void				LoadCampaignList	();
void				SaveCampaignList	();
bool				LoadCampaignVisitedMaps(int i);
void				ShowLinkData		(int Stage);

//TEMPORARY - M. White 6 April, 2019
#define				_MAXStats			7
Avatar				*_TempAvatar		= NULL;
struct AvFileRef
{
	string	AvDisplayName;
	int		UniqueID;
};
AvFileRef			*_AvatarRef			= NULL;
AvFileRef			*_AvRefSwap			= NULL;
int					_numAvatarRef		= 0;
const int			_showNumAvatars		= 24;
const int			_showNumCampaigns	= 17;
bool				_loadAvatarRefs		= false;
List<Avatar>		_ListMobAssigns;
Avatar				*_MobArray			= NULL;
int					_intNumMobsAssigned = 0;
int					_intTotalXP_Assigned= 0;
int					_TempStats[7];
int					_intStatReserve		= 0;
AvClassBasics		*_ClassBasics;	
int					_MonsterTHACOs[MAX_MonThaco];
MonsterDataStruct	*_MonData;
RECT				_AvSpeachBubble;

int					_STRData[StrMAX][25];
int					_ESRData[StrMAX][5];//Only 5 categories here...
int					_DEXData[DexMAX][25];
int					_CONData[ConMAX][25];
int					_INTData[IntMAX][25];
int					_WISData[WisMAX][25];
int					_CHAData[ChaMAX][25];
int					_COMData[ComMAX][25];
int					_CampaignIndexed	= -1;


int	XPCharts[cMAX_CLASSES][11];//11 levels to account for a 0-level Fighter...
int NegativeToHit = 0;
//----------------------------------------------//
//												//
//----------------------------------------------//