/**
 * Map library
 */

#Const Version		"2017-09-13"
#Const ScriptName	"Libs/Nadeo/ShootMania/Map.Script.txt"

// ---------------------------------- //
// 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 map type script version from the map metadata
 *
 *	@return		The version number of the maptype
 */
Integer GetMapTypeVersion() {
	declare metadata LibMapType_MapTypeVersion for Map = 0;
	return LibMapType_MapTypeVersion;
}

// ---------------------------------- //
/**	Get a landmark from its type, tag and order
 *
 *	@param	_Type		The type of landmark
 *	@param	_Tag		The tag of the spawn
 *	@param	_Order		The order of the spawn
 *
 *	@return		The landmark if found, Null otherwise
 */
CSmMapLandmark GetLandmark(Text Type, Text _Tag, Integer _Order) {
	foreach (MapLandmark in MapLandmarks) {
		if (MapLandmark.Tag != _Tag || MapLandmark.Order != _Order) continue;
		
		switch (Type) {
			case "Base"					: if (MapLandmark.Base != Null) return MapLandmark;
			case "Gate"					: if (MapLandmark.Gate != Null) return MapLandmark;
			case "Gauge"				: if (MapLandmark.Gauge != Null) return MapLandmark;
			case "Sector"				: if (MapLandmark.Sector != Null) return MapLandmark;
			case "PlayerSpawn"	: if (MapLandmark.PlayerSpawn != Null) return MapLandmark;
			case "BotPath"			: if (MapLandmark.BotPath != Null) return MapLandmark;
			case "ObjectAnchor"	: if (MapLandmark.ObjectAnchor != Null) return MapLandmark;
			case "Capturable"		: if (MapLandmark.Sector != Null && MapLandmark.Gauge != Null) return MapLandmark;
			default							: return MapLandmark;
		}
	}
	return Null;
}

// ---------------------------------- //
/**	Get a landmark from its tag and order
 *
 *	@param	_Tag		The tag of the landmark
 *	@param	_Order		The order of the landmark
 *
 *	@return		The landmark if found, Null otherwise
 */
CSmMapLandmark GetLandmark(Text _Tag, Integer _Order) {
	return GetLandmark("", _Tag, _Order);
}

// ---------------------------------- //
/**	Get a landmark with a base from its tag and order
 *
 *	@param	_Tag		The tag of the base
 *	@param	_Order		The order of the base
 *
 *	@return		The landmark if found, Null otherwise
 */
CSmMapLandmark GetLandmarkBase(Text _Tag, Integer _Order) {
	return GetLandmark("Base", _Tag, _Order);
}

// ---------------------------------- //
/**	Get a landmark with a gate from its tag and order
 *
 *	@param	_Tag		The tag of the gate
 *	@param	_Order		The order of the gate
 *
 *	@return		The landmark if found, Null otherwise
 */
CSmMapLandmark GetLandmarkGate(Text _Tag, Integer _Order) {
	return GetLandmark("Gate", _Tag, _Order);
}

// ---------------------------------- //
/**	Get a landmark with a gauge from its tag and order
 *
 *	@param	_Tag		The tag of the gauge
 *	@param	_Order		The order of the gauge
 *
 *	@return		The landmark if found, Null otherwise
 */
CSmMapLandmark GetLandmarkGauge(Text _Tag, Integer _Order) {
	return GetLandmark("Gauge", _Tag, _Order);
}

// ---------------------------------- //
/**	Get a landmark with a sector from its tag and order
 *
 *	@param	_Tag		The tag of the sector
 *	@param	_Order		The order of the sector
 *
 *	@return		The landmark if found, Null otherwise
 */
CSmMapLandmark GetLandmarkSector(Text _Tag, Integer _Order) {
	return GetLandmark("Sector", _Tag, _Order);
}

// ---------------------------------- //
/**	Get a landmark with a player spawn from its tag and order
 *
 *	@param	_Tag		The tag of the player spawn
 *	@param	_Order		The order of the player spawn
 *
 *	@return		The landmark if found, Null otherwise
 */
CSmMapLandmark GetLandmarkPlayerSpawn(Text _Tag, Integer _Order) {
	return GetLandmark("PlayerSpawn", _Tag, _Order);
}

// ---------------------------------- //
/**	Get a landmark with a bot path from its tag and order
 *
 *	@param	_Tag		The tag of the bot path
 *	@param	_Order		The order of the bot path
 *
 *	@return		The landmark if found, Null otherwise
 */
CSmMapLandmark GetLandmarkBotPath(Text _Tag, Integer _Order) {
	return GetLandmark("BotPath", _Tag, _Order);
}

// ---------------------------------- //
/**	Get a landmark with an object anchor from its tag and order
 *
 *	@param	_Tag		The tag of the object anchor
 *	@param	_Order		The order of the object anchor
 *
 *	@return		The landmark if found, Null otherwise
 */
CSmMapLandmark GetLandmarkObjectAnchor(Text _Tag, Integer _Order) {
	return GetLandmark("ObjectAnchor", _Tag, _Order);
}

// ---------------------------------- //
/**	Get a capturable landmark from its tag and order
 *
 *	@param	_Tag		The tag of the capturable
 *	@param	_Order		The order of the capturable
 *
 *	@return		The landmark if found, Null otherwise
 */
CSmMapLandmark GetLandmarkCapturable(Text _Tag, Integer _Order) {
	return GetLandmark("Capturable", _Tag, _Order);
}

// ---------------------------------- //
/**	Get the base of a landmark from its tag and order
 *
 *	@param	_Tag		The tag of the base
 *	@param	_Order		The order of the base
 *
 *	@return		The base if found, Null otherwise
 */
CSmMapBase GetBase(Text _Tag, Integer _Order) {
	declare Landmark <=> GetLandmark("Base", _Tag, _Order);
	if (Landmark != Null) return Landmark.Base;
	return Null;
}

// ---------------------------------- //
/**	Get the gate of landmark from its tag and order
 *
 *	@param	_Tag		The tag of the gate
 *	@param	_Order		The order of the gate
 *
 *	@return		The gate if found, Null otherwise
 */
CSmMapGate GetGate(Text _Tag, Integer _Order) {
	declare Landmark <=> GetLandmark("Gate", _Tag, _Order);
	if (Landmark != Null) return Landmark.Gate;
	return Null;
}

// ---------------------------------- //
/**	Get the gauge of a landmark from its tag and order
 *
 *	@param	_Tag		The tag of the gauge
 *	@param	_Order		The order of the gauge
 *
 *	@return		The gauge if found, Null otherwise
 */
CSmMapGauge GetGauge(Text _Tag, Integer _Order) {
	declare Landmark <=> GetLandmark("Gauge", _Tag, _Order);
	if (Landmark != Null) return Landmark.Gauge;
	return Null;
}

// ---------------------------------- //
/**	Get the sector of a landmark from its tag and order
 *
 *	@param	_Tag		The tag of the sector
 *	@param	_Order		The order of the sector
 *
 *	@return		The sector if found, Null otherwise
 */
CMapSector GetSector(Text _Tag, Integer _Order) {
	declare Landmark <=> GetLandmark("Sector", _Tag, _Order);
	if (Landmark != Null) return Landmark.Sector;
	return Null;
}

// ---------------------------------- //
/**	Get the player spawn of a landmark from its tag and order
 *
 *	@param	_Tag		The tag of the player spawn
 *	@param	_Order		The order of the player spawn
 *
 *	@return		The player spawn if found, Null otherwise
 */
CMapSpawn GetPlayerSpawn(Text _Tag, Integer _Order) {
	declare Landmark <=> GetLandmark("PlayerSpawn", _Tag, _Order);
	if (Landmark != Null) return Landmark.PlayerSpawn;
	return Null;
}

// ---------------------------------- //
/**	Get the bot path of a landmark from its tag and order
 *
 *	@param	_Tag		The tag of the bot path
 *	@param	_Order		The order of the bot path
 *
 *	@return		The bot path if found, Null otherwise
 */
CMapBotPath GetBotPath(Text _Tag, Integer _Order) {
	declare Landmark <=> GetLandmark("BotPath", _Tag, _Order);
	if (Landmark != Null) return Landmark.BotPath;
	return Null;
}

// ---------------------------------- //
/**	Get the object anchor of a landmark from its tag and order
 *
 *	@param	_Tag		The tag of the object anchor
 *	@param	_Order		The order of the object anchor
 *
 *	@return		The object anchor if found, Null otherwise
 */
CMapObjectAnchor GetObjectAnchor(Text _Tag, Integer _Order) {
	declare Landmark <=> GetLandmark("ObjectAnchor", _Tag, _Order);
	if (Landmark != Null) return Landmark.ObjectAnchor;
	return Null;
}

// ---------------------------------- //
/**	Count the number of landmark of a specific type
 *
 *	@param	_Type		The type of landmark
 *
 *	@return		The number of landmark of this type
 */
Integer GetLandmarksCount(Text Type) {
	switch (Type) {
		case "Base"			: {
			declare Count = 0;
			foreach (MapLandmark in MapLandmarks) {
				if (MapLandmark.Base != Null) Count += 1;
			}
			return Count;
		}
		case "Gate"			: return MapLandmarks_Gate.count;
		case "Gauge"		: return MapLandmarks_Gauge.count;
		case "Sector"		: {
			declare Count = 0;
			foreach (MapLandmark in MapLandmarks) {
				if (MapLandmark.Sector != Null) Count += 1;
			}
			return Count;
		}
		case "PlayerSpawn"	: return MapLandmarks_PlayerSpawn.count;
		case "Capturable"	: {
			declare Count = 0;
			foreach (MapLandmark in MapLandmarks) {
				if (MapLandmark.Sector != Null && MapLandmark.Gauge != Null) Count += 1;
			}
			return Count;
		}
		case "BotPath"		: {
			declare Count = 0;
			foreach (MapLandmark in MapLandmarks) {
				if (MapLandmark.BotPath != Null) Count += 1;
			}
			return Count;
		}
		case "ObjectAnchor"		: {
			declare Count = 0;
			foreach (MapLandmark in MapLandmarks) {
				if (MapLandmark.ObjectAnchor != Null) Count += 1;
			}
			return Count;
		}
		default				: return MapLandmarks.count;
	}
	
	return 0;
}

// ---------------------------------- //
/**	Count the number of landmarks
 *
 *	@return		The number of landmarks
 */
Integer GetLandmarksCount() {
	return GetLandmarksCount("");
}

// ---------------------------------- //
/**	Count the number of bases
 *
 *	@return		The number of bases
 */
Integer GetBasesCount() {
	return GetLandmarksCount("Base");
}

// ---------------------------------- //
/**	Count the number of gates
 *
 *	@return		The number of gates
 */
Integer GetGatesCount() {
	return GetLandmarksCount("Gate");
}

// ---------------------------------- //
/**	Count the number of gauges
 *
 *	@return		The number of gauges
 */
Integer GetGaugesCount() {
	return GetLandmarksCount("Gauge");
}

// ---------------------------------- //
/**	Count the number of sectors
 *
 *	@return		The number of sectors
 */
Integer GetSectorsCount() {
	return GetLandmarksCount("Sector");
}

// ---------------------------------- //
/**	Count the number of player spawns
 *
 *	@return		The number of player spawns
 */
Integer GetPlayerSpawnsCount() {
	return GetLandmarksCount("PlayerSpawn");
}

// ---------------------------------- //
/**	Count the number of bot paths
 *
 *	@return		The number of bot paths
 */
Integer GetBotPathsCount() {
	return GetLandmarksCount("BotPath");
}

// ---------------------------------- //
/**	Count the number of object anchors
 *
 *	@return		The number of object anchors
 */
Integer GetObjectAnchorsCount() {
	return GetLandmarksCount("ObjectAnchor");
}

// ---------------------------------- //
/**	Count the number of capturable
 *
 *	@return		The number of capturable
 */
Integer GetCapturablesCount() {
	return GetLandmarksCount("Capturable");
}