//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $Workfile:     $
// $Date:         $
//
//-----------------------------------------------------------------------------
// $Log: $
//
// $NoKeywords: $
//=============================================================================//

#ifndef HL2WMP_GAMERULES_H
#define HL2WMP_GAMERULES_H
#pragma once

#include "gamerules.h"
#include "teamplay_gamerules.h"
#include "gamevars_shared.h"

#ifndef CLIENT_DLL
#include "hl2wars/hl2wars_player.h"
#endif


#ifdef CLIENT_DLL
	#define CHL2WMPRules C_HL2WMPRules
	#define CHL2WMPGameRulesProxy C_HL2WMPGameRulesProxy
#endif

enum gamemodes
{
	GAMEMODE_SANDBOX = 0,	// just start a random map
	GAMEMODE_CLASSIC,		// create a game in the gamelobby, then start it.
};

class CHL2WMPGameRulesProxy : public CGameRulesProxy
{
public:
	DECLARE_CLASS( CHL2WMPGameRulesProxy, CGameRulesProxy );
	DECLARE_NETWORKCLASS();
};

class CHL2WMPRules : public CMultiplayRules
{
public:
	DECLARE_CLASS( CHL2WMPRules, CMultiplayRules );

#ifdef CLIENT_DLL

	DECLARE_CLIENTCLASS_NOBASE(); // This makes datatables able to access our private vars.

#else

	DECLARE_SERVERCLASS_NOBASE(); // This makes datatables able to access our private vars.
#endif
	
	CHL2WMPRules();
	virtual ~CHL2WMPRules();

	virtual void Precache( void );
	virtual bool ShouldCollide( int collisionGroup0, int collisionGroup1 );
	virtual bool ClientCommand( CBaseEntity *pEdict, const CCommand &args );

	virtual float FlWeaponRespawnTime( CBaseCombatWeapon *pWeapon );
	virtual float FlWeaponTryRespawn( CBaseCombatWeapon *pWeapon );
	//virtual Vector VecWeaponRespawnSpot( CBaseCombatWeapon *pWeapon );
	virtual int WeaponShouldRespawn( CBaseCombatWeapon *pWeapon );
	virtual void Think( void );
	virtual void CreateStandardEntities( void );
	virtual void ClientSettingsChanged( CBasePlayer *pPlayer );
	virtual int PlayerRelationship( CBaseEntity *pPlayer, CBaseEntity *pTarget );
	virtual void GoToIntermission( void );
	virtual void DeathNotice( CBasePlayer *pVictim, const CTakeDamageInfo &info );
	virtual const char *GetGameDescription( void );
	// derive this function if you mod uses encrypted weapon info files
	virtual const unsigned char *GetEncryptionKey( void ) { return (unsigned char *)"x9Ke0BY7"; }


	float GetMapRemainingTime();
	void CleanUpMap();
	void CheckRestartGame();
	void RestartGame();
	
#ifndef CLIENT_DLL
	virtual float	FlItemRespawnTime( CItem *pItem );
	virtual bool FShouldSwitchWeapon( CBasePlayer *pPlayer, CBaseCombatWeapon *pWeapon );

	void	AddLevelDesignerPlacedObject( CBaseEntity *pEntity );
	void	RemoveLevelDesignerPlacedObject( CBaseEntity *pEntity );
	void    CheckChatForReadySignal( CHL2Wars_Player *pPlayer, const char *chatmsg );

#endif
	virtual void ClientDisconnected( edict_t *pClient );

	bool CheckGameOver( void );
	bool IsIntermission( void );

	void PlayerKilled( CBasePlayer *pVictim, const CTakeDamageInfo &info );

	int		GetGameMode() { return m_iGameMode; }
	void	SetGameMode( int gamemode ) { m_iGameMode = gamemode; }

	void	CheckAllPlayersReady( void );

	bool	CheckAllPlayersPresent();

// we need the default relationship tables for the ai in mp
#ifndef CLIENT_DLL 
	void InitDefaultAIRelationships( void );
#endif

	// hl2wars game related rules
	bool	IsGameRoom( void ) { return m_bGameRoom; }
	void	SetGameRoom( bool state ) { m_bGameRoom = state; }
	
private:
	
	//CNetworkVar( bool, m_bTeamPlayEnabled );
	CNetworkVar( int, m_iGameMode );
	CNetworkVar( float, m_flGameStartTime );
	CUtlVector<EHANDLE> m_hRespawnableItemsAndWeapons;
	float m_tmNextPeriodicThink;
	float m_flRestartGameTime;
	bool m_bCompleteReset;
	bool m_bAwaitingReadyRestart;
	bool m_bHeardAllPlayersReady;

	bool m_bAllPlayersPresent;

	// hl2wmp vars
	CNetworkVar( bool, m_bGameRoom );
};

inline CHL2WMPRules* HL2WMPRules()
{
	return static_cast<CHL2WMPRules*>(g_pGameRules);
}

#endif //HL2WMP_GAMERULES_H
