#pragma once
#include "Jass.h"
#include "Game_structures.h"

//typedef int DWORD;

integer fGetPath();
integer fInitMap(integer vPathToW3);
unsigned short fCreateDataUnit(unit vUnit, unsigned short vFlagThread);
unsigned short fCreateDataUnit2(sDataUnit2 *pDataUnit2);
unsigned short fDelDataUnit2(unsigned short vIdDataUnit);
unsigned short fDelDataUnit2(DataUnit *pDataUnit);
integer fUnitGoToInt(unsigned short vIdDataUnit, integer vInt, unsigned short vAction, unsigned int vMaxR);//, integer vMaxTime);
integer fFindIToMap (integer vIntIn);
integer fCheckGoDataUnit(unsigned short vIdDataUnit);
integer fCreateGoToDataUnit(unsigned short vIdDataUnit, unsigned int vMaxRect);
integer fGoTo(unsigned short vIdDataUnit);
integer fCheckGoTo(unsigned short vIdDataUnit);
integer fStartCommands();
integer fStopCommands();
integer fCheckCreateIdDataUnit(unsigned short IdDataUnit);
unsigned short fGetIdDataUnit(integer vId, HPLAYERCOLOR vNPlayer);
unsigned int fGetIntUnit(unsigned short vIdDataUnit);
integer fCheckStartCommands();
unit fGetUnit(int vId, player vPlayer);
void fIssuePointOrderToXY(unit vUnit, string vStr, unsigned short vX, unsigned short vY);
real fConverterIY2RY (unsigned short vY);
real fConverterIX2RX (unsigned short vX);
unsigned short fConverterX (real X);
unsigned short fConverterY (real Y);
unsigned short fConvertIToX (unsigned int vIntIn);
unsigned short fConvertIToY (unsigned int vIntIn);
integer fModulo (integer a, integer b);
unsigned int fConvertXYToI (unsigned short vX, unsigned short vY);

unsigned int fGetDiffUnit (unit vUnit);
unsigned short fRadiusToDiff (real r);
integer fFillMap(integer vMap, unsigned short *pFillMap);

DataGoTo *fGetDataGoTo(HTRIGGER hTrigger);
void fDelDataGoTo(DataGoTo *pDataGoToBase, integer vFlag);
void fAddDataGoTo(DataGoTo *pDataGoToBase);
integer fActionGoTo(DataUnit* pDataUnit, real vTimerGetElapsed);
void fInitIdUnits();
integer fSetUnit(unsigned short vIdDataUnit, DataUnit *pDataUnit);
DataUnit * fGetDataUnit(unsigned short vIdDataUnit);
unsigned short fGetFreeIdDataUnit();
//integer fSetSpell(sDataSpell *pSpell, integer vId);
bool fInitMapGlobal();
integer fFillMToI(DataGoTo *pDataGoTo, unsigned int vIntIn);

integer fFillRectToFillMap (unsigned short *pFillMap, sRect2* vRect, unsigned short vIntInFill);
integer fSetCellInFillMap (unsigned short *pFillMap, sRect2* vRect, unsigned short vInt);
unsigned short fGetCellInFillMap (unsigned short *pFillMap, unsigned short x, unsigned short y);
integer fCheckRectToI (sRect2* vRect, unsigned int vIntIn);
integer fCheckRectToFillMap (unsigned short *pFillMap, sRect2* vRect);
integer fCheckPath (unsigned short vIntIn);
integer fCheckRectToIFillMap (unsigned short *pFillMap, sRect2* vRect, unsigned short vIntInFill);
integer fFillRectToFillMap2 (unsigned short *pFillMap, sRect2* vRect, unsigned short vIntInFill);

void fFreeDataUnit();

DWORD WINAPI ThreadGoTo(void *p);
void fActionUnitDeath();
DataUnit * fGetDataUnit(HUNIT whichUnit, unsigned short &vOutIdDataUnit);
void fActionUnitResurrected();

void fActionUnitEntersWorldBoundsRegion();

integer fFillUnitToMap(DataUnit *pDataUnit);

void fActionFillMapUnits(DataGoTo *pDataGoTo);
integer fFreeTrigger(HTRIGGER hTrigger);
integer fFillMapUnits(DataGoTo *pDataGoTo);

integer fUnitsMagazine();
DataUnit * fGetDataUnit(DataGoTo *pDataGoTo, unsigned int vInt3);

//integer vTest1(void *p);

void fExpiredTimerGoTo(DataGoTo* pDataGoTo, real vTimerGetElapsed);
DataGoTo *fGetDataGoToBaseTimer(HTIMER vTimer);
//DataGoTo *fGetDataGoToBase(HTRIGGER hTrigger);
//DataGoTo *fGetDataGoToBase(HTIMER hTimer);

integer fFillBlinkToI(DataGoTo *pDataGoTo, unsigned int vIntIn);

double round(double d);

unsigned int fGetINext (unsigned short *pFillMap, unsigned short vNextIntFill, unsigned short vDiff);

real fGetMinIX2RX (unsigned short vX);
real fGetMaxIX2RX (unsigned short vX);
real fGetMinIY2RY (unsigned short vY);
real fGetMaxIY2RY (unsigned short vY);

void fActionUnitAllEvents();
void fActionUnitMove();
void fTimerForMoveUnit();
//DataUnit * fGetDataUnit(HTIMER vTimer);

integer fSetHost(HPLAYER vPlayer);
integer fCheckSetHost();

void fInitPlayer();
integer fCheñkGoTo(unsigned short vIdDataUnit);
integer fClearMapUnits(unsigned short vStorona);

integer fActionUnitFinished(unsigned short vIdDataUnit);
integer fGetActionUnitFinish(unsigned short vIdDataUnit);
integer fGetActionUnit(unsigned short vIdDataUnit);
integer fFreeActionUnit(unsigned short vIdDataUnit);

//integer fGetObstacle(unsigned short vIdDataUnit);
//integer fSetObstacle(unsigned short vIdDataUnit, unsigned short vObstacle);

void fAddToActionStackForUnits(DataUnit *pDataUnit);
void fDelToActionStackForUnits(DataUnit *pDataUnit);

void fSettingUnit(HEVENTID vEventId);

void fActionUnitAttacked();
void fTimerForAttackedUnit();

integer fBuild(unsigned short vIdDataUnit, integer vInt, integer vIdBuild, real *vX, real *vY, real *vRadius);

integer fFinishActionUnit(unsigned short vIdDataUnit);

void fFreeDataGoTo();

integer fGetCurrentIntFill(unsigned short *pFillMap, sRect2* vRect);

bool fIssuePointOrderToRect(unit vUnit, string vStr, sRect2 *vRect, real vRadius_Unit);

bool fIsPointToRect(real vX, real vY, sRect2 *vRect);

bool fGetINext (unsigned short *pFillMap, sRect2 *vRect1, sRect2 *vRect2, unsigned short vNextIntFill, unsigned int vR, unsigned short vDiff);

bool fIsPlayerAI(HPLAYERCOLOR vNPlayer);

bool fIsSlayer(integer vId);
bool fIsVampire(integer vId);
bool fIsMainHuman(integer vId);

unsigned short fGetLastUnit(unsigned short vLastUnit);

void fCast(HEVENTID vEventId);

void fChat();
void fSendAllPlayer(String vMessage);

void fWinPlayer();
void fWin(int vStorona);
void fCheckWin();
bool fUTF8ToANSI_UNICODE(char *vUTF8, char *vANSI, wchar_t *vUNICODE);
bool fUTF8(char *vUTF8, char *vANSI);
bool fRemoveDeadToNickName(char *vNickName);

void fItem();

void fFreePlayer();

void fFogOfWar();

bool fIsRectToRect(sRect2 *vRect1, sRect2 *vRect2);

HPLAYER fGetHost2();

integer fUnitsMainHuman();

//void fThreadGoTo2(DataGoTo *pDataGoTo);
//void fThreadGoTo3();

DataUnit * fGetDataUnit(HUNIT whichUnit);

bool fFindIToMapCenter (integer vIntIn, real *vX, real *vY);
unsigned short fMaxBase ();

void fDelToActionStackForUnitsForEnemy(DataUnit *pDataUnit);

bool fGlobalGoToInt(integer vInt, DataGoTo *pDataGoTo, DataUnit *pDataUnit);

bool fFreeHost();

unsigned short fFindBaseByDataUnit (DataUnit *pDataUnit);

real fG(real vX1, real vY1, real vX2, real vY2);
real fG(unsigned int vInt3_1, unsigned int vInt3_2);

bool fCenterToRect(Coordinates * vCoordinates, sRect2 *vRect);

bool fIsWall(integer vId);
bool fIsBuildFirst(integer vId);
bool fIsHouse(integer vId);

//void fActionUnitLeaveWorldBoundsRegion();

bool fIsFirstTower(integer vId);
bool fIsInfernal(integer vId);

bool fIsBigHPTower(integer vId);
void fStopMove();

integer fUnitAttack(unsigned short vIdDataUnit, unsigned short vIdDataUnit2);

integer fInitMapFromResources();

void fUnitConstructFinish();

DataUnit * fGetLastConstruct();

void fTrainFinish();

void fAddDataUnit(int vId, player vPlayer);

void fAddAllDataUnit();

unsigned short fFindBaseByDataUnitNoEnemy (DataUnit *pDataUnit);

void fAddAllDataUnitOfPlayer(HPLAYER vPlayer);

void fUnitResearchFinish();

void fUnitResearchStart();

void fFreeAllStacksActions(sStackActions *vFirst);

void fTrainStart();

//unsigned short fFindFreeNInSteckDataUnit2(integer vId, HPLAYERCOLOR vNPlayer);
void fDataUnit2();
unsigned short fDelDataUnit(unsigned short vIdDataUnit);
bool fIsGoTo(integer vId);
bool fIsResearch(integer vId);

bool fHarvestingNearestTree(DataUnit *pDataUnit);
void fFlagAction();

void fLog(int vFlag, char *vText);

bool fCheckLeftToNickName(char *vNickName);

bool fPreDelDataUnit2(DataUnit *pDataUnit);

void fDestAction();

unsigned short fRemoteness(unsigned int vInt3);
unsigned short fRemoteness(DataUnit* pDataUnit);
unsigned short fRemotenessBase(DataUnit* pDataUnit);
unsigned short fRemotenessBase(unsigned int vInt3);

bool fIsBuild(unsigned short vIdDataUnit, integer vInt, integer vIdBuild);

unsigned short fMaxRemotenessBase(DataUnit* pDataUnit);

real fConvertIToRX(unsigned int vIntIn);
real fConvertIToRY(unsigned int vIntIn);

bool fCheckPos(DataUnit* pDataUnit, unsigned int vInt3);

unsigned int fJumpBack (DataUnit *pDataUnit);

bool fFreePosRepair(DataUnit *pDataUnit);

unsigned short fQPosRepairMainHuman(sBase *vBase);

bool fMiddleRect(sRect2 *vRect1, sRect2 *vRect2, sRect2 *vRectMiddle);

bool fCheckMapUnitsRect(sRect2 *vRect2, unsigned short vStorona);

bool fIsTwoVampires();

bool fIsPosUnit(unsigned short vIdDataUnit, unsigned int vInt3);

unsigned int fInt3DataUnit(DataUnit *pDataUnit);


DataUnit * fDataUnitInt3(unsigned int vInt3, unsigned short vStorona);

unsigned int fConverterI(real vX, real vY);

bool fIsHealTower(integer vId);

bool fNullUnit(unit WhichUnit);

integer fFindRectToFillMap (unsigned short* pFillMap, sRect2* vRect2, unsigned short vIntInFill);
integer fCheckRectToIFillMap3 (unsigned short* pFillMap, sRect2* vRect, unsigned short vIntInFill);

bool fWriteMap(integer vPathToW3);

bool fNull2(unsigned int vUI);

bool fDevelopmentPriority(HumanPlayer *pHumanPlayer, DataUnit *pDataUnit);

bool fIssuePointOrderByIdToRect(unit vUnit, integer vOrderId, sRect2 *vRect, real vRadius_Unit);

void fDelToPlaceWork(DataUnit *pDataUnit);

DataUnit * fGetDataUnit2(HUNIT whichUnit);

int fCheckFile2();

integer fGetNumWall(integer vId);

unsigned short fRemoteness2(DataUnit* pDataUnit1, DataUnit* pDataUnit2);
unsigned short fRemoteness2(unsigned int vInt3_1, unsigned int vInt3_2);

DataUnit * fGetDataUnit2(unsigned short vIdDataUnit);