//==========================================================================================
//
//	etl_ice_v11.gm
//
//	Who          	When		What
//------------------------------------------------------------------------------------------
//	^1[UJE]^3Captain	3 May 2021	Initial Script
//
//==========================================================================================
//

global Map =
{
	Debug = 0, // please set to zero before distributing your script
	
	//set status' for conditionals
	AxisCP = false,
	AlliedCP = false,
	FlagStatus = false,
	DocTaken = false, 
	MainDoorStatus = true, //intact
	SideWallStatus = true, //intact
	SetSpawn1 = function(bot)
	{
		if (bot.GetTeam() == TEAM.AXIS) {
			if (RandInt(0,9) < 3) {
			bot.ChangeSpawnPoint(3);
			}
		}
	},
 
	SetSpawn2 = function(bot)
	{
		if (bot.GetTeam() == TEAM.ALLIES) {
			if (RandInt(0,6) < 3) {
			bot.ChangeSpawnPoint(2);
			}
		}
	},
 
	SetSpawn = function()
	{
		foreach(bot in BotTable)
		{
			Map.SetSpawn1(bot);
			Map.SetSpawn2(bot);
		}
	},
	// Rôles
	Roles =
	{
		AXIS =
		{
			AllBots = true, // each bot is considered for a role
			INFILTRATOR = // Plant Allies CP	
			{
				numbots = 1,
			},
	},	
		ALLIES =
		{
			AllBots = true, // each bot is considered for a role
			DEFENDER = // Defend Document 
			{ 
				numbots = 4,
				MinBotsForRole = 4,
				crucialClass = CLASS.MEDIC,
			},
			
			DEFENDER1 = // Defend flag
			{
				numbots = 2,
				MinBotsForRole = 4,
				crucialClass = CLASS.ENGINEER,
				
			},
		},
	},
	
	Navigation =
	{
		southladder =
		{
			navigate = function(_this)
			{
				_this.Bot.HoldButton(BTN.FORWARD, 3);
				sleep(3);
			},
		},
	},
	
	Axis_Taken_Doc =
      {
 	Name="Axis_Taken_Doc",
 	TriggerOnClass = CLASS.ANYPLAYER,
		TriggerOnClass = CLASS.ANYPLAYER,
		OnEnter = function(ent)
		{
			if( GetEntTeam(ent) == TEAM.AXIS )
			{ 
				if ( GetEntFlags( ent, ENTFLAG.CARRYINGGOAL ) )
				{
					SetAvailableMapGoals( TEAM.AXIS, true, "ATTACK_Flag.*" );
					SetAvailableMapGoals( TEAM.AXIS, false, "ATTACK_Doc.*" );
					
					SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_Flag.*" );
					SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_Doc.*" );
					
					Util.ClearRoleForGoals( ".*", { ROLE.DEFENDER, ROLE.DEFENDER1 } );
					Util.MapDebugPrint( "^5Axis Escape With Document" );
				}
			}
		},
	},
	
	Axis_Exit_Halls =
      {
 	Name="Axis_Exit_Halls",
 	TriggerOnClass = CLASS.ANYPLAYER,
		TriggerOnClass = CLASS.ANYPLAYER,
		OnEnter = function(ent)
		{
                  if( GetEntTeam(ent) == TEAM.AXIS )
			{ 
				if ( GetEntFlags( ent, ENTFLAG.CARRYINGGOAL ) )
				{
				      SetAvailableMapGoals( TEAM.AXIS, true, "ATTACK_Deliver.*" );
					SetAvailableMapGoals( TEAM.AXIS, false, "ATTACK_Flag.*" );
					
					SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_Deliver.*" );
					SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_Flag.*" );
					
					Map.SetSpawn();
					Util.MapDebugPrint( "^5Axis Exit Halls" );
				}
			}
		},
	},
	
	Allied_Command_Post_Built = function( trigger )
	{
	Map.AlliedCP = true;
	if ( !Map.DocTaken && Map.SideWallStatus or Map.MainDoorStatus )
	{
	SetAvailableMapGoals( TEAM.AXIS, true, "PLANT_Allied_Command_Post" );
	}
	SetAvailableMapGoals( TEAM.ALLIES, false, "BUILD_Allied_Command_Post" );
		
		Util.MapDebugPrint( "Allied_Command_Post_Built" );
	},
	
	Allied_Command_Post_Destroyed = function( trigger )
	{
	Map.AlliedCP = false;
	if ( !Map.DocTaken )
	{
	SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_Allied_Command_Post" );
	}
		
	SetAvailableMapGoals( TEAM.AXIS, false, "PLANT_Allied_Command_Post" );
	
		Util.MapDebugPrint( "Allied_Command_Post_Destroyed" );
	},
	
	Axis_Command_Post_Built = function( trigger )
	{
	Map.AxisCP = true;
	if ( !Map.DocTaken && !Map.FlagStatus )
	{
	SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Axis_Command_Post" );
	}
	SetAvailableMapGoals( TEAM.AXIS, false, "BUILD_Axis_Command_Post" );
	
		Util.MapDebugPrint( "Axis_Command_Post_Built" );
	},
	
	Axis_Command_Post_Destroyed = function( trigger )
	{
	Map.AxisCP = false;
	if ( !Map.DocTaken && Map.FlagStatus  )
	{
	SetAvailableMapGoals( TEAM.AXIS, true, "BUILD_Axis_Command_Post" );
	}
	SetAvailableMapGoals( TEAM.ALLIES, false, "PLANT_Axis_Command_Post" );
	
		Util.MapDebugPrint( "Axis_Command_Post_Destroyed" );
	},
	
	Guardtower_Built = function( trigger )
	{
		Util.MapDebugPrint( "Guardtower_Built" );
	},
	
	Guardtower_Destroyed = function( trigger )
	{
		Util.MapDebugPrint( "Guardtower_Destroyed" );
	},
	
	Main_Entrance_Destroyed = function( trigger )
	{
	Map.MainDoorStatus = false;
	if ( !Map.DocTaken )
	{
	SetAvailableMapGoals( TEAM.AXIS, true, {"ATTACK_Doc.*","FLAG_Documents"} );
	}
	if ( !Map.DocTaken && Map.AlliedCP )
	{
	SetAvailableMapGoals( TEAM.AXIS, true, "PLANT_Allied_Command_Post" );
	}
	SetAvailableMapGoals( TEAM.AXIS, false, "ATTACK_Flag.*" );	
	
	      Util.EnableGoal( "ROUTE_servicehalls" );
		Util.EnableGoal("ROUTE_hallpatrol");
		Util.MapDebugPrint( "Main_Entrance_Destroyed" );
	},
	
	Side_Wall_Destroyed = function( trigger )
	{
	Map.SideWallStatus = false;
	if ( !Map.DocTaken )
	{
	SetAvailableMapGoals( TEAM.AXIS, true, {"ATTACK_Doc.*","FLAG_Documents"} );
	}
	SetAvailableMapGoals( TEAM.AXIS, false, "ATTACK_Flag.*" );
	
		Util.EnableGoal( "ROUTE_sidewall" );
		Util.MapDebugPrint( "Side_Wall_Destroyed" );
	},

	documents_Taken = function( trigger )
	{
	Map.DocTaken = true;
	SetAvailableMapGoals( TEAM.AXIS, true, "CAPPOINT_Doc" );
	SetAvailableMapGoals( TEAM.AXIS, false, {
	"BUILD_Axis_Command_Post",
	"PLANT_Allied_Command_Post",
	"PLANT_Main_Entrance",
	"PLANT_Side_Wall",
	"FLAG_documents"
	});
	
	SetAvailableMapGoals( TEAM.ALLIES, false, {
	"BUILD_Allied_Command_Post",
	"PLANT_Axis_Command_Post",
	"PLANTMINE.*"
	});
	      Util.ClearRoleForGoals( ".*", { ROLE.DEFENDER, ROLE.DEFENDER1 } );
		Util.MapDebugPrint( "documents_Taken" );
	},

	documents_Returned = function( trigger )
	{
	Map.DocTaken = false;
	if ( !Map.MainDoorStatus )
	{
	SetAvailableMapGoals( TEAM.AXIS, false, "ATTACK_Flag.*" );
	SetAvailableMapGoals( TEAM.AXIS, true, {"ATTACK_Doc.*","FLAG_documents"} );
	}
	if ( !Map.AxisCP )
	{
	SetAvailableMapGoals( TEAM.AXIS, true, "BUILD_Axis_Command_Post");
	}
	else
	{
	SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Axis_Command_Post");
	}
	if ( !Map.AlliedCP )
	{
	SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_Allied_Command_Post");
	}
	else
	{
	SetAvailableMapGoals( TEAM.AXIS, true, "PLANT_Allied_Command_Post");
	}
	if ( Map.SideWallStatus )
	{
	SetAvailableMapGoals( TEAM.AXIS, true, "PLANT_Side_Wall");
	}
			
      SetAvailableMapGoals( TEAM.ALLIES, true, {
	"DEFEND_Flag.*",
	"DEFEND_Doc.*",
	"PLANTMINE.*"
	} );
	
	SetAvailableMapGoals( TEAM.AXIS, false, {
	"ATTACK_Deliver.*",
	"CAPPOINT_Doc"
	} );
	
      SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_Deliver.*");

	SetGoalRole("DEFEND_Doc.*", ROLE.DEFENDER);
	SetGoalRole("DEFEND_Flag.*", ROLE.DEFENDER1);
	
		Util.MapDebugPrint( "documents_Returned" );
	},

	documents_Secured = function( trigger )
	{
		Util.MapDebugPrint( "documents_Secured" );
	},

	forward_bunker_Axis_Captured = function( trigger )
	{
	Map.FlagStatus = true;
	SetAvailableMapGoals( TEAM.AXIS, false, "CHECKPOINT.*");
	
	if ( !Map.DocTaken or Map.SideWallStatus or Map.MainDoorStatus )
	{
	SetAvailableMapGoals( TEAM.AXIS, true, "ATTACK_Flag.*" );
	}

	if ( !Map.DocTaken )
	{
	SetAvailableMapGoals( TEAM.ALLIES, true, {
	"DEFEND_Doc.*",
	"CHECKPOINT.*"
	});
	SetGoalRole("DEFEND_Doc.*", ROLE.DEFENDER);
	SetGoalRole("DEFEND_Flag.*", ROLE.DEFENDER1);
	}	
		Util.MapDebugPrint( "forward_bunker_Axis_Captured" );
	},

	forward_bunker_Allies_Captured = function( trigger )
	{
	Map.FlagStatus = false;
	if ( !Map.DocTaken or !Map.SideWallStatus or !Map.MainDoorStatus )
	{
	SetAvailableMapGoals( TEAM.AXIS, true, "ATTACK_Flag.*" );
	}
	if ( !Map.DocTaken )
	{
	SetAvailableMapGoals( TEAM.AXIS, true, "CHECKPOINT.*");
	
	SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_Flag.*" );
	}
	if ( !Map.DocTaken && Map.AxisCP )
	{
	SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Axis_Command_Post" );
	}
	
	SetAvailableMapGoals( TEAM.ALLIES, false, "CHECKPOINT.*");
	
		Util.MapDebugPrint( "forward_bunker_Allies_Captured" );
	},

};

global OnMapLoad = function()
{
	// Register callback functions
	OnTrigger( "^5Allied Command Post constructed. Charge speed increased!", Map.Allied_Command_Post_Built );
	OnTrigger( "^1Axis team has destroyed the Allied Command Post!", Map.Allied_Command_Post_Destroyed );
	OnTrigger( "^1Axis Command Post constructed. Charge speed increased!", Map.Axis_Command_Post_Built );
	OnTrigger( "^5The Allies have destroyed the Axis Command Post!", Map.Axis_Command_Post_Destroyed );
	OnTrigger( "^5The Allies have constructed the Guardtower!", Map.Guardtower_Built );
	OnTrigger( "^1The Axis have destroyed the Guardtower!", Map.Guardtower_Destroyed );
	OnTrigger( "^1The Axis have destroyed the Main Entrance!", Map.Main_Entrance_Destroyed );
	OnTrigger( "^1The Axis have breached the Side Wall!", Map.Side_Wall_Destroyed );
	OnTrigger( "Axis have stolen Documents!", Map.documents_Taken );
	OnTrigger( "Flag returned documents!", Map.documents_Returned );
	OnTrigger( "^1The Axis have transmited the Secret War Documents!", Map.documents_Secured );
	OnTrigger( "^1The Axis have captured the Forward Bunker!", Map.forward_bunker_Axis_Captured );
	OnTrigger( "^5The Allies have reclaimed the Forward Bunker!", Map.forward_bunker_Allies_Captured );
	
	// Axis TriggerRegion
	Axis_Taken_Doc = OnTriggerRegion(AABB(-6556.691,793.322,326.215,-4964.178,2084.924,1139.752), Map.Axis_Taken_Doc);
	Axis_Exit_Halls = OnTriggerRegion(AABB(-3558.616,-1202.227,-0.874,-2211.025,736.094,122.281), Map.Axis_Exit_Halls);
	
	Util.DisableGoal( ".*", true ); // all but routes
	Util.DisableGoal("ROUTE_sidewall");
	Util.DisableGoal("ROUTE_hallpatrol");
	Util.DisableGoal("ROUTE_servicehalls");
	
	// activation ALLIES
	SetAvailableMapGoals( TEAM.ALLIES, true, {
	"DEFEND_Flag.*",
	"BUILD_Guardtower",
	"PLANTMINE.*",
	"BUILD_Allied_Command_Post"
	
	});
	
	// activation AXIS
	SetAvailableMapGoals( TEAM.AXIS, true, {
	"ATTACK_Flag.*",
	"PLANT_Main_Entrance",
	"PLANT_Side_Wall",
	"BUILD_Axis_Command_Post",
	"CHECKPOINT.*"
	});

	// Max users per goal
	Util.SetMaxUsers( 1, "MOUNTMG42.*" );
	Util.SetMaxUsers( 1, "ATTACK.*" );
	Util.SetMaxUsers( 1, "DEFEND.*" );
	Util.SetMaxUsers( 1, "PLANT.*" );
	Util.SetMaxUsers( 1, "BUILD.*" );
	Util.SetMaxUsers( 1, "CHECKPOINT.*" );
	Util.SetMaxUsers( 2, "PLANTMINE.*" );
	Util.SetMaxUsers( 1, "FLAG.*" );
	
      //SetPriority
	SetGoalPriority( "PLANT_Main_Entrance", 0.95 );
	SetGoalPriority( "PLANT_Side_Wall", 0.9 );
	SetGoalPriority( "BUILD_Allied_Command_Post", 1.0 );
	SetGoalPriority( "BUILD_Axis_Command_Post", 1.0 );
	SetGoalPriority( "CHECKPOINT_forward_bunker", 0.85 );
	
	// Camp times
	SetMapGoalProperties( "ATTACK_.*", {MinCampTime=15, MaxCampTime=30});
	SetMapGoalProperties( "DEFEND_.*", {MinCampTime=15, MaxCampTime=30});
	SetMapGoalProperties( "MOUNTMG42.*", {MinCampTime=15, MaxCampTime=90} );
      
	// CLEAR ROLES
	Util.ClearRoleForGoals( ".*", { ROLE.DEFENDER, ROLE.DEFENDER1 } );
	
      //Offset Plant Fix
	Util.SetGoalOffset( -50, -50, 0, "PLANT_Side_Wall" );
	
	Util.MapDebugPrint( "Omni-bot map script for " + GetMapName() + " executed." );
};

global OnBotJoin = function( bot )
{
	// Uncomment for shootable breakables
	bot.TargetBreakableDist = 90.0;
	// Only set MaxViewDistance on maps with limited sight (e.g. fog)
	//~bot.MaxViewDistance = 2400;
	Map.SetSpawn1(bot);
	Map.SetSpawn2(bot);
};

global InitializeRoutes = function()
{
	MapRoutes =
	{
	      CHECKPOINT_forward_bunker =
		{
		  ROUTE_AxisSpawn1 =
			{
				ROUTE_southhalls =
				{
					ROUTE_southhalls2 = {},
					ROUTE_southhalls3 = {},
				},
				ROUTE_northhalls = {},
			},
			ROUTE_AxisSpawn2  = 
			{
				ROUTE_Radio  = 
				{
					ROUTE_southhalls  = 
					{
						ROUTE_southhalls2  = {},
						ROUTE_southhalls3  = {},
					},
					ROUTE_northhalls  = {},
				},
			},
		},
		FLAG_Documents =
		{
			ROUTE_AxisSpawn1  = 
			{
				ROUTE_southhalls  = 
				{
					ROUTE_southhalls2  = 
					{
						ROUTE_mainhall  = 
						{
							ROUTE_sidewall  = 
							{
								ROUTE_coveredladder  = {},
							},
							ROUTE_cornerwall  = 
							{
								ROUTE_longladder  = {},
							},
						},
						ROUTE_topbunker  = 
						{
							ROUTE_sidewall  = 
							{
								ROUTE_coveredladder  = 
								{
									ROUTE_docpatrol  = {},
								},
								ROUTE_farladder  = {},
								ROUTE_longladder  = {},
							},
						},
					},
					ROUTE_southhalls3  = 
					{
						ROUTE_mainhall  = 
						{
							ROUTE_sidewall  = {},
						},
						ROUTE_topbunker  = 
						{
							ROUTE_sidewall  = {},
						},
					},
				},
				ROUTE_northhalls  = 
				{
					ROUTE_servicehalls  = 
					{
						ROUTE_hallpatrol  = 
						{
							ROUTE_coveredladder  = 
							{
								ROUTE_docpatrol  = {},
							},
							ROUTE_longladder  = {},
							ROUTE_farladder  = {},
						},
					},
				},
			},
			ROUTE_AxisSpawn2  = 
			{
				ROUTE_southhalls  = 
				{
					ROUTE_southhalls2  = 
					{
						ROUTE_mainhall  = 
						{
							ROUTE_sidewall  = 
							{
								ROUTE_coveredladder  = {},
							},
							ROUTE_cornerwall  = 
							{
								ROUTE_longladder  = {},
							},
						},
						ROUTE_topbunker  = 
						{
							ROUTE_sidewall  = 
							{
								ROUTE_coveredladder  = 
								{
									ROUTE_docpatrol  = {},
								},
								ROUTE_farladder  = {},
								ROUTE_longladder  = {},
							},
						},
					},
					ROUTE_southhalls3  = 
					{
						ROUTE_mainhall  = 
						{
							ROUTE_sidewall  = {},
						},
						ROUTE_topbunker  = 
						{
							ROUTE_sidewall  = {},
						},
					},
				},
				ROUTE_northhalls  = 
				{
					ROUTE_servicehalls  = 
					{
						ROUTE_hallpatrol  = 
						{
							ROUTE_coveredladder  = 
							{
								ROUTE_docpatrol  = {},
							},
							ROUTE_longladder  = {},
							ROUTE_farladder  = {},
						},
					},
				},
			},
			ROUTE_FlagSpawn =
			{
				ROUTE_topbunker =
				{
					ROUTE_sidewall =
					{
						ROUTE_farladder = {},
						ROUTE_coveredladder = {},
					},
				},
				ROUTE_servicehalls =
				{
					Weight = 3,
					ROUTE_farladder = { Weight = 2, },
					ROUTE_coveredladder = {},
					ROUTE_longladder = {},
				},
				ROUTE_mainhall =
				{
					Weight = 2,
					ROUTE_sidewall =
					{
						ROUTE_farladder = { Weight = 2, },
						ROUTE_coveredladder = {},
						ROUTE_longladder = {},
					},
					ROUTE_cornerwall =
					{
						Weight = 2,
						ROUTE_gate =
						{
							ROUTE_farladder = { Weight = 2, },
							ROUTE_coveredladder = {},
							ROUTE_longladder = {},
						},
					},

				},
			},
		},
		CAPPOINT_Doc = 
		{
			ROUTE_docgrab  = 
			{
				ROUTE_docpatrol  = 
				{
					ROUTE_coveredladder  = 
					{
						ROUTE_hallpatrol  = 
						{
							ROUTE_servicehalls  = 
							{
								ROUTE_northhalls  = {},
								ROUTE_FlagSpawn  = 
								{
									ROUTE_southhalls2  = 
									{
										ROUTE_southhalls  = {},
									},
									ROUTE_southhalls3  = 
									{
										ROUTE_southhalls  = {},
									},
								},
							},
						},
						ROUTE_sidewall  = 
						{
							ROUTE_mainhall  = 
							{
								ROUTE_southhalls2  = 
								{
									ROUTE_southhalls  = {},
								},
								ROUTE_southhalls3  = 
								{
									ROUTE_southhalls  = {},
								},
							},
						},
					},
				},
				ROUTE_sidewall  = 
				{
					ROUTE_mainhall  = 
					{
						ROUTE_southhalls2  = 
						{
							ROUTE_southhalls  = {},
						},
						ROUTE_southhalls3  = 
						{
							ROUTE_southhalls  = {},
						},
					},
				},
			},
		},
		BUILD_Guardtower =
		{
		},
		PLANT_Guardtower =
		{
		},
		PLANT_Side_Wall =
		{
		},
		PLANT_Main_Entrance =
		{
		},
		BUILD_Allied_Command_Post =
		{
		},
		PLANT_Allied_Command_Post =
		{
		},
		BUILD_Axis_Command_Post =
		{
		},
		PLANT_Axis_Command_Post =
		{
		},
	};
	MapRoutes["ATTACK_Flag.*"] = MapRoutes.FLAG_Documents;
	Util.Routes(MapRoutes);
};
