#pragma once

#include "MW4.hpp"
#include "hudcomp.hpp"

namespace MechWarrior4
{
	class CBucket;
	class HUDComm;

    class CHudScoreInfo : public ReplicatorID
    {
    public:
        Replicator* m_pREP;
        bool m_bBOT;
        int m_nScore;
        int m_nKills;
        int m_nDeaths;
    public:
        CHudScoreInfo();
        int Compare(const CHudScoreInfo& that) const;
    };

	class HUDScore : public HUDComponent
	{
	protected:

		friend class MWApplication;

		typedef HUDComponent inherited;

		struct BucketData
		{
			CBucket *bucket;
			HUDText *text;
			HUDText *score;
			HUDText *kill,*death,*ping;
			BucketData (CBucket *p1,HUDText *p2,HUDText *p3,HUDText *p4,HUDText *p5,HUDText *p6)
			{
				bucket = p1;
				text = p2;
				score = p3;
				kill = p4;
				death = p5;
				ping = p6;
			}

			bool operator<(const BucketData& p) const;
		};

		stlport::vector<BucketData> m_Buckets;
		int m_AnimLoc;
		Stuff::Time m_AnimTime;
		HUDText *m_PlayerTitle,*m_ScoreTitle;
		HUDText *m_GameType;
		Stuff::Time m_TimeLeft;
		HUDText *m_TimeLeftText;
//		HUDText *m_KillText,*m_DeathText,*m_PingText;
		HUDText *m_KillHeader,*m_DeathHeader;
		HUDText *m_PingHeader;
//		HUDComm *comm;

		void DrawImplementation(void);
		void KillData (void);
        int Kills (const Adept::ReplicatorID& me, const Adept::ReplicatorID& whom);
        int Deaths (const Adept::ReplicatorID& me, const Adept::ReplicatorID& whom);
		int Kills (const Adept::ReplicatorID& who);
		int Deaths (const Adept::ReplicatorID& who);
		int Kills (int teamid);
		int Deaths (int teamid);

	public:
		HUDScore();
		~HUDScore();
		virtual void Reset (void);
		virtual void Update (Stuff::Time till);

		void AddBucket (CBucket *);
		void KillBucket (CBucket *);

		void GameType (const char *type)
		{
			Verify (m_GameType);
			m_GameType->UpdateText (type);
		}
		void TimeLeft (Stuff::Time value)
		{ m_TimeLeft = value; }

		void SortByTeam();
	public:
        int GetScore4Player(const ReplicatorID& who, int& nKills, int& nDeaths); // jcem
        int GetScoreArray(CHudScoreInfo aScores[16], const ReplicatorID& idRoExlcude, int nMode = 0);
        int GetTeamScore(int nTeam, int& nKills, int& nDeaths); // jcem
	};
}

