//////////////////////////////////////////
//   Scoring
//////////////////////////////////////////
#Const Version		"2012-10-31"
#Const ScriptName	"Score.Script.txt"

#Include "MathLib" as MathLib
#Include "TextLib" as TextLib
#Include "Libs/Nadeo/Mode.Script.txt" as Mode

declare Boolean G_LibScore_UseLadder;

/* ------------------------------------- */
/** Return the version number of the script
 *
 *	@return		The version number of the script
 */
Text GetScriptVersion() {
	return Version;
}

/* ------------------------------------- */
/** Return the name of the script
 *
 *	@return		The name of the script
 */
Text GetScriptName() {
	return ScriptName;
}

Void MatchBegin(Boolean _G_LibScore_UseLadder) {
	G_LibScore_UseLadder = _G_LibScore_UseLadder;
	if(G_LibScore_UseLadder)
		Mode::Ladder_OpenMatch_All();
	This.ClearScores();
}

Void MatchBegin() {	
	MatchBegin(True);
}

Void MatchEnd(Boolean UpdateLadder) { 
	if(G_LibScore_UseLadder) {	
		if (UpdateLadder) {
			foreach (Score in Scores) {
				Score.LadderRankSortValue = - 1 - Score.Points;
			}	
			Mode::Ladder_CloseMatch();
		} 
		else {
			Mode::Ladder_CancelMatch();
		}
	}
}

Void MatchEnd() { MatchEnd(True); }

Void ClearScores() { This.ClearScores(); }

Void RoundBegin() {	
	foreach(Score in Scores) {
		Score.RoundPoints = 0;
	}
}

Void RoundEnd() {
	foreach(Score in Scores) {
		Score.Points += Score.RoundPoints;
		Score.RoundPoints = 0;
	}
}

Void AddPoints(CSmPlayer _Player, Integer _Points) {	
	if (_Player != Null && _Player.Score != Null) {
		if(_Player.Score.RoundPoints + _Points > 0) {
			_Player.Score.RoundPoints += _Points;
		} else {
			_Player.Score.RoundPoints = 0;
		}
	}
}

Void RemovePoints(CSmPlayer _Player, Integer _Points) {	
	AddPoints(_Player, -_Points);
}

