#if !defined(__CTCL_H__)
#define __CTCL_H__

// The following ifdef block is the standard way of creating macros which make exporting 
// from a DLL simpler. All files within this DLL are compiled with the CTCL_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see 
// CTCL_API functions as being imported from a DLL, wheras this DLL sees symbols
// defined with this macro as being exported.

#define CTCL_API _stdcall

#if !defined(BOOL)
#define BOOL int
#if !defined(TRUE)
#define TRUE 1
#define FALSE 0
#endif // !defined(TRUE)
#endif // !defined(BOOL)

#pragma pack(push, 1)
#if !defined(CTCLS_EXPORTS)
class CInviteCOOP
{
public:
    void* m_pParent;

    int m_nTimeInvite;
    int m_nResult; // 0: not inited, 1: requesting, 2: no, 3: yes...
    int m_nResultAccepted;
    GUID m_guidGameData;
public:
    CInviteCOOP();
    void Clear();
};
#endif // !defined(CTCLS_EXPORTS)
struct STeslaInfo
{
public:
    BOOL m_bCameraShip;
    unsigned long m_ulAddr;
    const char* m_pcsz;

    int m_nLauncherConnection; // 0: no connection, +1: connection, -1: connecting
    int m_nConnection2; // Connection to game or camera ship per m_bCameraShip, 0: no connection, +1: connected, -1: connecting
    int m_nApplType;
    int m_nApplState;
    int m_nGameState;
    int m_nGameTime;
    int m_nGameIsServer;
public:
};

#define MAX_PLYR_NAME  20
struct SPlayerInfo
{
public:
    BYTE m_bBot;
	BYTE m_bTeam;
    int m_nLevelOrTesla;
    char m_szName[MAX_PLYR_NAME];
    UINT m_uPlayerID;
    int m_nMechIndex;
	short m_fileID;
	WORD m_recordID;
    char m_szMech[64];
    int m_nTeamOrSkin;
    int m_nDecal;
    DWORD m_dwAddr;
};
#pragma pack(pop)

#define C_GameInfo          1 // Console 2 Launcher
#define S_GameInfo          1 // Launcher 2 Console

#define C_OrderAppl         10 // Console 2 Launcher

#define C_ErrorStartGame    19 // to server & client - error occurred, to mainmenu
#define C_ReadyStartGame    20 // to server - Game Server Start w/ HostSetup & Mission Params...
#define C_BOTS              21 // to server - Bot Infos
#define C_SetMechs          22 // to server & client - 
#define C_GetReady          23 // to server & client - 
#define C_DoLaunch          24 // to server

#define S_GameReturn        30 // game to console

#define C_SendFile          40
#define S_SendFile          40

#define C_InviteCOOP        50 // to server & client - invite clients
#define S_InviteCOOP        50 // to server & client - reply to server for invitation

class CTeslaInfo;
typedef CTeslaInfo* TESLA_HANDLE;

BOOL CTCL_API CTCL_Start(int nCTCLType);
void CTCL_API CTCL_Stop();
void CTCL_API CTCL_Run();
// Used by All
int CTCL_API CTCL_API CTCL_GetType();
BOOL CTCL_API CTCL_IsNone(); // no -ctcltype...
BOOL CTCL_API CTCL_IsConsole(); // Console Only
bool CTCL_API CTCL_IsCOOP(); // is COOP?
BOOL CTCL_API CTCL_IsConsoleOrCOOP(); // Console or COOP(COin OPerational)
BOOL CTCL_API CTCL_IsConsoleX(); // Game & Cameraship
// Used by Console(+ COOP)
int CTCL_API CTCL_GetTeslaCountAll();
int CTCL_API CTCL_GetTeslaCount();
TESLA_HANDLE CTCL_API CTCL_GetTeslaInfo(int nIndex, STeslaInfo& TI);
int CTCL_API CTCL_InviteCOOP(int nTimeInvite, int& nYes, int& nNo, int& nProcessings);
const char* CTCL_API CTCL_GetTeslaName(int nIndex);
int CTCL_API CTCL_OrderAppl(int nIndex, int nOrder, int nParam);
// Used by Launcher
// Used by Game
// Used by CameraShip

void CTCL_API CTCL_DoTerminateAppl();
void CTCL_API CTCL_DoEndMission();
void CTCL_API CTCL_DoMainShell();
void CTCL_API CTCL_DoCreateGame();
void CTCL_API CTCL_DoJoinGame();
void CTCL_API CTCL_StartGame(BOOL bRealLaunch);
void CTCL_API CTCL_InitMechDatas();
void CTCL_API CTCL_CheckJoinGame();
void CTCL_API CTCL_CheckNetConnectedToServer();
void CTCL_API CTCL_SetMissionParams();
void CTCL_API CTCL_CheckMissionParams();
void CTCL_API CTCL_SetMechs();
void CTCL_API CTCL_CheckClientReady();
void CTCL_API CTCL_CheckServerReady();
void CTCL_API CTCL_DefaultHostSetup(int nMode);
// from here - Mech4 only
void CTCL_API CTCL_DoSendGameReturn(int nValue);
void CTCL_API CTCL_SaveNMP(const void* p, int nSize);
void* CTCL_API CTCL_LoadNMP(int& nSize);
void CTCL_API CTCL_SendFile(const SYSTEMTIME& SysTime, const GUID& guid, int nType);
bool CTCL_API CTCL_DoReprintOrCheck(bool bRealPrint);
void CTCL_API CTCL_SetGameStateAsIdle();
// to here - Mech4 only

extern "C" {
extern int g_nCTCLType;

extern int g_nCTCL_DoLaunchGame;
#if !defined(CTCLS_EXPORTS)
extern CInviteCOOP g_InviteCOOP;
// console only...
// Mech4 only
extern int g_nMech4Comm;
// server & client only
extern BOOL g_bIsServer;
// console(All), server & client only(g_aPlayerInfos[0]), server only(g_aPlayerInfos[1..g_nBOTs]
extern SPlayerInfo g_aPlayerInfos[20];
extern int g_nPlayerInfos;
extern int g_nServer;
extern int g_nTeslas;
extern int g_nPrintOut;
extern int g_nMissionReview;
extern SYSTEMTIME g_SysTime;
extern GUID g_guidGameDatas;
// Tesla Server & Clients only
extern char g_szGameName[128];
extern int g_nBOTs;

extern DWORD g_dwJoinStartTicks;
#endif // !defined(CTCLS_EXPORTS)

extern const char PROF_INI[];
extern const char SECT_TESLAS[];
extern const char SECT_GAMES[];
extern const char SECT_CONFIG[];
} // end of extern "C"

#endif // !defined(__CTCL_H__)
