////////////////////////////////////////////////////////////////////////////////
//
// Copyright 2016 RWS Inc, All Rights Reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of version 2 of the GNU General Public License as published by
// the Free Software Foundation
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// Score.h
// Project: Postal
// 
// History:
//
//		06/11/97 BRH	Started this module
//
//		06/16/97 BRH	Added a scoreboard reset function to reset the scores
//							and display time.
//
//		06/17/97 BRH	Increased max number of players to make sure there are
//							enough entries for 16 or more players.
//
//		07/04/97 BRH	Added two more scoring modes.
//
//		07/07/97	JMI	Now ScoreUpdateDisplay() returns true if it drew into
//							the passed in buffer and false otherwise.
//
//		07/22/97 BRH	Added ScoreDisplayHighScores.
//
//		07/26/97 BRH	Added ScoreGetName to get the name of the player when 
//							they better one of the high scores.
//
//		08/10/97	JRD	Added a hood to the score status to allow graphical
//							backdrops behind the scoring status.
//
//		09/07/97	JMI	Now requires a pclient for MP scores.
//
//////////////////////////////////////////////////////////////////////////////

#ifndef SCORE_H
#define SCORE_H

#include "RSPiX.h"
#include "game.h"
#include "realm.h"

// todo:
#define	MaxNumIDs 16

class CScoreboard
{
	//---------------------------------------------------------------------------
	// typedefs
	//---------------------------------------------------------------------------
	public:
		
		typedef enum
		{
			SinglePlayer,
			MultiPlayer,
			Timed,
			Goal,
			CaptureFlag,
			TimeBonus,
			Coop
		} ScoringMode;


		typedef enum
		{
			Kills,
			Deaths,
			Revives
		} ScoreType;
	//---------------------------------------------------------------------------
	// Variables
	//---------------------------------------------------------------------------
	public:
		// todo: magic numbers & local coop
		int16_t	m_asScores[MaxNumIDs][3];		// Score for each player
		int32_t	m_lLastScoreDrawTime;						// Time since last update
		int32_t	m_lLastStatusDrawTime;						// Time since last update

	protected:
		ScoringMode m_ScoringMode;						// Mode of scoring

	//---------------------------------------------------------------------------
	// Constructor(s) / destructor
	//---------------------------------------------------------------------------
	public:

		CScoreboard()
		{
			int16_t i;
			for (i = 0; i <= MaxNumIDs; i++)
			{
				m_asScores[i][Kills] = 0;
				m_asScores[i][Deaths] = 0;
				m_asScores[i][Revives] = 0;
			}
		}

		~CScoreboard()
		{

		}

	//---------------------------------------------------------------------------
	// Functions
	//---------------------------------------------------------------------------
	public:

		void Reset(void)
		{
			int16_t i;
			for (i = 0; i < MaxNumIDs; i++)
			{
				m_asScores[i][Kills] = 0;
				m_asScores[i][Deaths] = 0;
				m_asScores[i][Revives] = 0;
			}

			m_lLastStatusDrawTime = 0;
			m_lLastScoreDrawTime = 0;
		}
		
		// Subtract one from the score of the indicated guy
		void SubtractOne(int16_t sPlayerIndex, int8_t cScoreType = Kills)
		{
			// If it is beyond the number of players, set it to the
			// overflow bin.
			if (sPlayerIndex > MaxNumIDs)
				sPlayerIndex = MaxNumIDs;

			if (m_asScores[sPlayerIndex][cScoreType] < 0)
			{
				m_asScores[sPlayerIndex][cScoreType] = 0;
			}

			m_asScores[sPlayerIndex][cScoreType]--;
		}		


		// Add one to the score of the indicated guy
		void AddOne(int16_t sPlayerIndex, int8_t cScoreType = Kills)
		{
			// If it is beyond the number of players, set it to the
			// overflow bin.
			if (sPlayerIndex > MaxNumIDs)
				sPlayerIndex = MaxNumIDs;

			m_asScores[sPlayerIndex][cScoreType]++;
		}		

		void SetScoringMode(ScoringMode Mode)
			{m_ScoringMode = Mode;};

		int16_t GetScoringMode(void)
			{return m_ScoringMode;};
	
};

// Set up the RPrint for the score
void ScoreInit(void);

// Reset the display time and the multiplayer scores
void ScoreReset(void);

// Reset the display time - required before each realm
void ScoreResetDisplay(void);

// Function called by Characters when they die
void ScoreRegisterKill(CRealm* pRealm, U16 u16DeadGuy, U16 u16Killer);
void ScoreRegisterDeath(CRealm* pRealm, U16 u16Corpse);
void ScoreRegisterRevive(CRealm* pRealm, U16 u16Reviver);

// Function called by play to update the score display
// Returns true, if pImage was updated; false otherwise.
bool ScoreUpdateDisplayPVR(RRect* pRect, CRealm* pRealm, int16_t sDstX, int16_t sDstY, CHood* pHood);

// Function to set the scoring mode (ie multiplayer, single, timed etc)
void ScoreSetMode(CScoreboard::ScoringMode Mode);

// Call this function to show the status line or mission goal for a few
// seconds.  This can be called when the "show mission" key is pressed.
void ScoreDisplayStatus(CRealm* pRealm);

// Call this function at the end of the level and if it is a challenge level,
// it will display the high scores for that level and give the user a chance
//	to enter their name if they beat one of the top scores.
void ScoreDisplayHighScores(			// Returns nothing.
	CRealm* pRealm,						// In:  Realm won.	
	int16_t sRealmNum);
// Get the name for a new high score
int16_t ScoreGetName(char* pszName);

// Returns the highest multiplayer score.
int16_t ScoreHighestKills(CRealm* pRealm);

#endif //SCORE_H

//////////////////////////////////////////////////////////////////////////////
// EOF
//////////////////////////////////////////////////////////////////////////////
