/**
 *	Spectators library
 */
#Const	Version			"2016-05-19"
#Const	ScriptName	"Libs/Nadeo/Spectators.Script.txt"

// ---------------------------------- //
// Constants
// ---------------------------------- //
#Const C_Camera_All -1
#Const C_Camera_ThirdPerson 0
#Const C_Camera_FirstPerson 1

// ---------------------------------- //
// Globales
// ---------------------------------- //
declare Boolean G_ForceClan; ///< Force spectators to watch players from their clan

// ---------------------------------- //
// Functions
// ---------------------------------- //
// ---------------------------------- //
// Public
// ---------------------------------- //
// ---------------------------------- //
/**	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;
}

// ---------------------------------- //
/// Get the camera constants
Integer Camera_All() { return C_Camera_All; }
Integer Camera_ThirdPerson() { return C_Camera_ThirdPerson; }
Integer Camera_FirstPerson() { return C_Camera_FirstPerson; }

// ---------------------------------- //
/** Force spectators to watch players from their clan
 *
 *	@param	_Forced										True to force
 */
Void ForceClan(Boolean _Forced) {
	G_ForceClan = _Forced;
	
	foreach (Score in Scores) {
		declare UI <=> UIManager.GetUI(Score.User);
		if (UI == Null) continue;
		if (G_ForceClan) UI.SpectatorForcedClan = Score.TeamNum;
		else UI.SpectatorForcedClan = -1;
	}
}

Void ForceCamera(Integer _Camera) {
	UIManager.UIAll.SpectatorForceCameraType = _Camera;
}

// ---------------------------------- //
/// Update the library
Void Yield() {
	if (G_ForceClan) {
		foreach (Player in AllPlayers) {
			if (Player.Score == Null) continue;
			declare UI <=> UIManager.GetUI(Player);
			if (UI == Null) continue;
			if (UI.SpectatorForcedClan != Player.Score.TeamNum) {
				UI.SpectatorForcedClan = Player.Score.TeamNum;
			}
		}
	}
}

// ---------------------------------- //
/// Unload the library
Void Unload() {
	G_ForceClan = False;
}

// ---------------------------------- //
/// Load the library
Void Load() {
	Unload();
}