#ifndef __CRIOMAIN_H__
#define __CRIOMAIN_H__

#define ASSERT() {}
#define TRACE() {}
#include "c232comm.h"
#include "c232comm.cpp"

#define _BIGINNER_MODE	0
#define _VETERAN_MODE	1
#define _EXPERT_MODE	2

int	 g_nOldInputMode;
int	 g_nInputMode;
int	 g_nProgramMode;
int	 g_nFiringMode;
// MSL 5.03 Dump Ammo
int  g_nAmmoDump1;
int  g_nAmmoDump2;
int  g_nAssignGroup1;
int  g_nAssignGroup2;
int  g_nAssignGroup3;
int  g_nPrevWeapon;
int  g_nNextWeapon;

#define LAMPBLANK {-1, SYSKEY_NULL, LAMP_OFF}
enum { SYSKEY_NULL, SYSKEY_SHFT = 16, SYSKEY_CTRL = 17, SYSKEY_ALT = 18 };
enum { LAMP_NONE, LAMP_OFF, LAMP_DIM, LAMP_BRIGHT, LAMP_FLASH, LAMP_DEFAULT = (BYTE)-1, LAMP_NOTEXIST = (BYTE)-2 };
struct RIOBUTTON
{
    int norm_key;
    BYTE mod_key;
    BYTE lamp;
};

HWND g_hWnd;
int _stdcall VehGetShutdownState();

///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
//{
#define ESC		27

class CPlasma : public C232Comm
{
public:
	DWORD m_dwStart;
	int m_nOldRank;
	int m_nOldScore;
	enum {
		ATTR_NORMAL		= 0,
		ATTR_HALF		= 1,
		ATTR_LINE		= 2,
		ATTR_REVERSE	= 4,
		ATTR_FLASH		= 8,
		ATTR_PROTECTED	= 128
	};
	enum { PLASMA_OFF, PLASMA_ON, PLASMA_FLASH };

    int m_nGlobalState;
    Time m_timeLastPlasma2;
public:
	CPlasma () {
		Open (2);
		m_dwStart = GetTickCount ();
		PlasmaClear ();
		PlasmaCursor (CPlasma::PLASMA_OFF);
		m_nOldRank = INT_MIN;
		m_nOldScore = INT_MIN;

        m_nGlobalState = -1;
	}
	virtual ~CPlasma () { 
		PlasmaCursor (CPlasma::PLASMA_OFF);
		PlasmaClear ();
		Close (); 
	}
public:
	void SendPacket (const BYTE* pbPacket, char nLen);
	void PlasmaClear ();

	void PlasmaCursor (char n = PLASMA_OFF);
	void PlasmaCursorHome ();
	void PlasmaCursorX (char n);
	void PlasmaCursorY (char n);

	void PlasmaFontAttr (char n);
	void PlasmaFont (char n);
	
	void PlasmaText (const char *szText);	
	POINT GetFontSize (int Font);

	void PlasmaBoxDraw (RECT tag);
	void PlasmaBoxFill (RECT tag);
	void PlasmaPosText (const char *szText, char x = 0, char y = 0, char Attr = 0, char Font = 5);
	void PlasmaScoreDraw (const char *Rank, const char *Score, BOOL bFlag);

    void DoPlasma(char nMode);
private:
	void PlasmaDisplay (int Gamestate, const char *szName, const char *Rank, const char *Score);
};
//}
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////

class CBUTTON_GROUP
{
public:	
	static RIOBUTTON s_aButtonTable[];
	static BYTE s_aSaveLamp[];
	static BYTE s_aCtrlLamp[];

	// Aux#1
	BOOL m_bFreeForAll;
	BOOL m_bOneFlagShutDown;

public:
	CBUTTON_GROUP ();
	virtual ~CBUTTON_GROUP ();

	void SetTable(BOOL bFlag = true);
	void ResetTable(BOOL bFlag = true);
    int GetLampState(BYTE b) const;
	void SetLampState(BYTE b, int State);	
	int m_HeatMode;
};


class CRIOMAIN : public CBUTTON_GROUP, public CPlasma
{
public:
	BOOL	m_bGamePlaying;	
public:
	CRIOMAIN (HWND hWnd);
	virtual ~CRIOMAIN ();
    int IsLampOFF(int n) const;

	void RunMain ();
	BOOL LampEvent (BYTE b);
    void ButtonEvent(BYTE state, BYTE index);
    void AnalogButton(const BYTE state, const BYTE index);
	void UpdateAnalog (DIJOYSTATE &js);
	void UpdateHat (DIJOYSTATE &js);
	void UpdatePadal (DIJOYSTATE &js);
	void UpdateThrottle (DIJOYSTATE &js);
	void UpdateJoystickX (DIJOYSTATE &js);
	void UpdateJoystickY (DIJOYSTATE &js);
	void UpdateJoystick (DIJOYSTATE &js);
	void DoSafeAnalog (LONG &lResult) {
		if (lResult < -1000L) {
			lResult = -1000L;
		} else if (lResult > 1000L) {
			lResult = 1000L;
		}
	}

	enum {
			LeaveTorsoAlone,
			CenterTorsoToLegs,
			CenterLegsToTorso,
		};

	void Redf_ThrottleMessageHandler (VehicleInterface& vh, BYTE btnIndex, int data);
    void DoTeamOrderButton(VehicleInterface& vh, int button);
    void SetTeamOrderButtons(bool bForce = false);
};


#endif