//
// AVP_Multiplayer_GameMessageSystem.h
//
// Created by JG - 17 September 2008
//
// Copyright (C) 2008 Rebellion, All Rights Reserved.
//

#ifdef ASURA_USE_PRAGMA_ONCE
#pragma once
#endif

#ifndef __AVP_MULTIPLAYER_GAMEMESSAGESYSTEM_H__
#define __AVP_MULTIPLAYER_GAMEMESSAGESYSTEM_H__

#include "Core/AVP_Settings.h"

// Gobal constants
static const u_int s_uAVP_MULTIPLAYER_SPAM_MESSAGES_MAX_NUMBER = 8; 
static const u_int s_uAVP_MULTIPLAYER_SPAM_MESSAGES_MAX_LENGTH = 128; 
static const u_int s_uAVP_MULTIPLAYER_CAPTURE_POINT_NAME_MAX_LENGTH = 32;

// Forwards declarations
template <typename T> class Asura_LinkList;
template <typename T> class Asura_List;

class AVP_Multiplayer_GameMessageSystem
{
public:
	static void Initialise(); 
	static void Update(); 
	static void Render(); 
	static void Shutdown(); 
	
	// Events
	static void OnActorGetsKilled( Asura_Guid uExecutorGuid, Asura_Guid uVictimGuid, Asura_Hash_ID uDamageType, bool bStealth ); 

	static void AddConsoleCmdsAndVars(); 

	// Respawn timer
	static void ShowRespawnTimer(); 
	static void UpdateRespawnTimer( float fRemainingTime ); 
	static void HideRespawnTimer();

	// Special message
	static void ShowPriorityMessage(); 
	static void HidePriorityMessage();

	// On-screen indicator for capture in progress
	static void ShowCaptureInProgress(); 
	static void HideCaptureInProgress();

	// Current rank in the scoreboard
	static void UpdateRankPlayers( int iNumberOfPlayers ); 
	static void UpdateRankPlace( int iPlace ); 

	// Currrent team score
	static void UpdateTeamScore( AVP_Settings::Team eTeam, int iScore ); 

	// Current state of capture points
	static void UpdateCapturePointsState();

	// Capture Point list
	static void ShowCapturePointList(); 
	static void HideCapturePointList(); 

	// Population / Visibility functions for the Capture Point list
	static bool VisibilityCPEnemy( u_int uElementIndex, bool bInterrogate, bool bHelp );
	static bool VisibilityCPFriendly( u_int uElementIndex, bool bInterrogate, bool bHelp );
	static bool VisibilityCPContested( u_int uElementIndex, bool bInterrogate, bool bHelp );
	static bool VisibilityCPNeutral( u_int uElementIndex, bool bInterrogate, bool bHelp );
	static bool PopulateCPName( u_int uElementIndex, bool bInterrogate, bool bHelp );

	// Some game rules exposed to the GUI system 
	static bool GetNumberOfTeams( bool bHelp ); 
	static bool IsTeamBasedGame( bool bHelp ); 

	static void AddSpamMessage( Asura_UnicodeChar* swzMessage, float fDisplayTime ); 

	static void AddCapturePoint( Asura_Guid uCapturePointGuid ); 

	// Message entry 
	struct SpamMessageEntry
	{
		Asura_UnicodeChar	m_aswzSpamMessageBuffer[s_uAVP_MULTIPLAYER_SPAM_MESSAGES_MAX_LENGTH]; 
		float				m_fTimeRemainingOnScreen; 
	};  

	// Capture point state
	struct CapturePointState
	{ 
		Asura_Guid			m_uGuid; 
		Asura_UnicodeChar	m_aswzCapturePointName[s_uAVP_MULTIPLAYER_CAPTURE_POINT_NAME_MAX_LENGTH]; 
		AVP_Settings::Team	m_eControlledByTeam;
		bool				m_bContested;

		Asura_Guid			GetGuid()				{ return m_uGuid; }
	};

protected:
	static bool GetSpamMessageByIndex( u_int uMessageIndex, bool bInterrogate, bool bHelp );
	static int	SortMessagesByTimeRemaining( const SpamMessageEntry& xMessageA, const SpamMessageEntry& xMessageB ); 

	static int	SortCapturePointsByGuid( const CapturePointState& xCapturePointA, const CapturePointState& xCapturePointB ); 

	// Spam messages
	static SpamMessageEntry		s_xSpamMessages[s_uAVP_MULTIPLAYER_SPAM_MESSAGES_MAX_NUMBER]; 

	// Flag for rendering the respawn counter message
	static bool s_bShowRespawnTimer;

	// Flag for rendering the high priority messages 
	static bool s_bShowPriorityMessage; 

	// Flag for rendering an on-screen indicator when capturing a command post
	static bool s_bShowCaptureInProgress; 

	// Flag for rendering the capture point list
	static bool s_bShowCapturePointList; 

	static Asura_List<SpamMessageEntry>			s_xSortedMesagesList; 
	static Asura_LinkList<CapturePointState>	s_xSortedCapturePointState; 

private:
};

#endif//__AVP_MULTIPLAYER_GAMEMESSAGESYSTEM_H__