//==========================================================================================
//
//	uje_battersea.gm
//
//	      Who       	When		        What
//------------------------------------------------------------------------------------------
//	^1[UJE]^3Niek	01 February 2023	Initial Script
//	///XP*Captain	06 February 2023	Attack,Defense, Route and More..., have fun.
//==========================================================================================
//

global Map =
{
	Debug = 0, // please set to zero before distributing your script
	
    // **** set status' for conditionals ***
    Gold2Secured = 0,
    
	// Rôles
	Roles =
	{
    	AXIS =
		{
		    AllBots = true, // each bot is considered for a role
			ATTACKER = // Attack Armory
			{
				numbots = 4,				
			},
			ATTACKER1 = // Attack Bomb
			{
				numbots = 6,			
			},
		},	
	    ALLIES =
		{
			AllBots = true, // each bot is considered for a role
			DEFENDER = // // Defend Armory
			{ 
				numbots = 4,
                crucialClass = CLASS.MEDIC,
			},
            DEFENDER1 = // // Defend Bomb
			{ 
				numbots = 6,
                crucialClass = CLASS.MEDIC,
			},
		},
	},
	
    Switches =
	{
		//	/bot waypoint_setproperty paththrough UseSwitch_PT:double_door_ins
		double_door_ins =
		{
            AimPosition = Vec3(923.789, 704.125, 706.984),	///bot aim_pos
			Enabled = true,
			LimitTeam = (1<<TEAM.AXIS) | (1<<TEAM.ALLIES),
			Priority = 0.0,
			WaypointName = "double_door_ins",
			LimitBots = 1,
			Timeout = 2500,
			Wait = function()
			{
				if ( Map.DoorStatus == 1 )
				{
					sleep(2.5);
					return true;
				}
				return false;
			}
		},
		
		//	/bot waypoint_setproperty paththrough UseSwitch_PT:double_door_out
		double_door_out =
		{
			AimPosition = Vec3(743.839, 687.875, 705.724),	///bot aim_pos
			Enabled = true,
			LimitTeam = (1<<TEAM.AXIS) | (1<<TEAM.ALLIES),
			Priority = 0.0,
			WaypointName = "double_door_out",
			LimitBots = 1,
			Timeout = 2500,
			Wait = function()
			{
				if ( Map.DoorStatus == 1 )
				{
					sleep(2.5);
					return true;
				}
				return false;
			},
		},
	},
    Double_door_moving = function( trigger )
	{
           vec = ToVector(trigger.Action);
           if ( vec.z < 0 )
			{
			Map.Switches.double_door_ins.Enabled = false;
            Map.Switches.double_door_out.Enabled = false;
		    Map.DoorStatus = 1; //opened
            Util.MapDebugPrint("Double_door_opening", true);
			}
            else if ( vec.z > 0 )
			{
			Map.Switches.double_door_ins.Enabled = true;
            Map.Switches.double_door_out.Enabled = true;
		    Util.MapDebugPrint("Double_door_closing", true);
            }
    },
    
	Allied_Command_Post_Built = function( trigger )
	{
	SetAvailableMapGoals( TEAM.AXIS, true, "PLANT_Command_Post" );
	SetAvailableMapGoals( TEAM.AXIS, false, "BUILD_Command_Post" );
	
	SetAvailableMapGoals( TEAM.ALLIES, false, {"PLANT_Command_Post","BUILD_Command_Post"} );
	
		Util.MapDebugPrint( "Allied_Command_Post_Built" );
	},
	
	Allied_Command_Post_Destroyed = function( trigger )
	{
	SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_Command_Post" );
    SetAvailableMapGoals( TEAM.ALLIES, false, "PLANT_Command_Post" );

	SetAvailableMapGoals( TEAM.AXIS, true, "BUILD_Command_Post" );
	SetAvailableMapGoals( TEAM.AXIS, false, "PLANT_Command_Post" );
	
		Util.MapDebugPrint( "Allied_Command_Post_Destroyed" );
	},
	
    Axis_Command_Post_Built = function( trigger )
	{
	SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Command_Post" );
	SetAvailableMapGoals( TEAM.ALLIES, false, "BUILD_Command_Post" );
    
	SetAvailableMapGoals( TEAM.AXIS, false, {"BUILD_Command_Post","PLANT_Command_Post"} );
	
		Util.MapDebugPrint( "Axis_Command_Post_Built" );
	},
	
	Axis_Command_Post_Destroyed = function( trigger )
	{
	SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_Command_Post" );
    SetAvailableMapGoals( TEAM.ALLIES, false, "PLANT_Command_Post" );

	SetAvailableMapGoals( TEAM.AXIS, true, "BUILD_Command_Post" );
	SetAvailableMapGoals( TEAM.AXIS, false, "PLANT_Command_Post" );
	
		Util.MapDebugPrint( "Axis_Command_Post_Destroyed" );
	},

	factory_side_door_Built = function( trigger )
	{
    SetAvailableMapGoals( TEAM.ALLIES, false, "BUILD_factory_side_door" );
    
    SetAvailableMapGoals( TEAM.AXIS, true, "PLANT_factory_side_door" );
    
		Util.MapDebugPrint( "factory_side_door_Built" );
	},

	factory_side_door_Destroyed = function( trigger )
	{
    if ( !Map.Gold2Secured )
    {
    SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_factory_side_door" );
    }
    SetAvailableMapGoals( TEAM.AXIS, false, "PLANT_factory_side_door" );

		Util.MapDebugPrint( "factory_side_door_Destroyed" );
	},
    
    train_door_Destroyed = function( trigger )
	{
    SetAvailableMapGoals( TEAM.AXIS, true, "FLAG_gold2" );
    
		Util.MapDebugPrint( "train_door_Destroyed" );
	},

	gold2_Taken = function( trigger )
	{
    SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_Armory.*" );
    SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_Key.*" );
    
    SetAvailableMapGoals( TEAM.AXIS, true, {
    "CAPPOINT_keycard",
    "ATTACK_Armory.*"
    } );
    
    SetAvailableMapGoals( TEAM.AXIS, false, {
    "ATTACK_Key.*",
    "FLAG_gold2"
    } );
    
		Util.MapDebugPrint( "gold2_Taken" );
	},

	gold2_Returned = function( trigger )
	{
    SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_Key.*" );
    SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_Armory.*" );

    SetAvailableMapGoals( TEAM.AXIS, true, {
    "FLAG_gold2",
    "ATTACK_Key.*"
    } );
    
    SetAvailableMapGoals( TEAM.AXIS, false, {
    "CAPPOINT_keycard",
    "ATTACK_Armory.*"
    } );

    SetAvailableMapGoals( TEAM.AXIS, false, "ATTACK_Armory.*" );

		Util.MapDebugPrint( "gold2_Returned" );
	},

	gold2_Secured = function( trigger )
	{
    SetAvailableMapGoals( TEAM.ALLIES, true, {
    "DEFEND_Bomb.*",
    "PLANTMINE_Bomb.*"
    } );
    
    SetAvailableMapGoals( TEAM.AXIS, true, {
    "FLAG_gold",
    "ATTACK_Bomb.*"
    } );
    SetAvailableMapGoals( TEAM.AXIS, false, "CAPPOINT_keycard" );
    
    Util.SetRoleForTable({ "DEFEND_Armory.*"}, ROLE.DEFENDER);
    Util.SetRoleForTable({ "DEFEND_Bomb.*"}, ROLE.DEFENDER1);
    Util.SetRoleForTable({ "ATTACK_Armory.*"}, ROLE.ATTACKER);
    Util.SetRoleForTable({ "ATTACK_Bomb.*"}, ROLE.ATTACKER1);
    
		Util.MapDebugPrint( "gold2_Secured" );
	},
    
    gold_Taken = function( trigger )
	{
    SetAvailableMapGoals( TEAM.AXIS, true, "CAPPOINT_dynamite.*" );
   
		Util.MapDebugPrint( "gold_Taken" );
	},
    
    last_gold_Taken = function( trigger )
	{
    SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_Armory.*" );
    
    SetAvailableMapGoals( TEAM.AXIS, false, {
    "ATTACK_Armory.*",
    "FLAG_gold"
    } );
    
		Util.MapDebugPrint( "last_gold_Taken" );
	},
    
    last_gold_Returned = function( trigger )
	{
    SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_Armory.*" );
    
    SetAvailableMapGoals( TEAM.AXIS, true, {
    "ATTACK_Armory.*",
    "FLAG_gold"
    } );
    
		Util.MapDebugPrint( "last_gold_Returned" );
	},

    last_gold_Placed = function( trigger )
	{
    SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_Armory.*" );
    
    SetAvailableMapGoals( TEAM.AXIS, false, {
    "ATTACK_Armory.*",
    "FLAG_gold"
    } );
    
		Util.MapDebugPrint( "last_gold_Placed" );
	},
    
	Bomb_Ready = function( trigger )
	{
    
    SetAvailableMapGoals( TEAM.AXIS, true, "SWITCH_Bomb" );

	ClearGoalRole( "DEFEND_Bomb.*", ROLE.DEFENDER1 );
	ClearGoalRole( "DEFEND_Armory.*", ROLE.DEFENDER );
	ClearGoalRole( "ATTACK_Armory.*", ROLE.ATTACKER );
	ClearGoalRole( "ATTACK_Bomb.*", ROLE.ATTACKER1 );
		Util.MapDebugPrint( "Bomb_Ready" );
	},
    
    countdown_Actived = function( trigger )
	{
    SetAvailableMapGoals( TEAM.ALLIES, true, "SWITCH_Bomb" );
    
    SetAvailableMapGoals( TEAM.AXIS, false, "SWITCH_Bomb" );
    
		Util.MapDebugPrint( "countdown_Actived" );
	},
    
    countdown_Interrupted = function( trigger )
	{
    SetAvailableMapGoals( TEAM.ALLIES, false, "SWITCH_Bomb" );
    
    SetAvailableMapGoals( TEAM.AXIS, true, "SWITCH_Bomb" );
    
		Util.MapDebugPrint( "countdown_Interrupted" );
	},
};

global OnMapLoad = function()
{
	// Register callback functions
    OnTrigger( "^4Allied Command Post constructed", Map.Allied_Command_Post_Built );
	OnTrigger( "^4Allied team has destroyed the Axis Command Post", Map.Allied_Command_Post_Destroyed );
	OnTrigger( "^1Axis Command Post constructed", Map.Axis_Command_Post_Built );
	OnTrigger( "^1Axis team has destroyed the Allied Command Post", Map.Axis_Command_Post_Destroyed );
    
	OnTrigger( "the side door has been contructed", Map.factory_side_door_Built );
	OnTrigger( "the side door has been destroyed", Map.factory_side_door_Destroyed );
    OnTrigger( "Axis have breached the sidedoor!!!!", Map.train_door_Destroyed );

	OnTrigger( "^6Axis have stolen the keycard!!!", Map.gold2_Taken );
	OnTrigger( "^6The keycard have been returned!!!!", Map.gold2_Returned );
	OnTrigger( "^6The armory has been opened!!!!", Map.gold2_Secured );
    
    OnTrigger( "Axis have stolen The explosive charge!", Map.gold_Taken );
    OnTrigger( "^6Axis have stolen the 5th explosive charge!!!!", Map.last_gold_Taken );
    OnTrigger( "^6The 5th explosive charge has been returned!!!!", Map.last_gold_Returned );
    OnTrigger( "^6The last explosive charge has been placed!!!!", Map.last_gold_Placed );
    
    OnTrigger( "^6The bomb is ready to be armed!!!!", Map.Bomb_Ready );
    OnTrigger( "^6Countdown activated", Map.countdown_Actived );
    OnTrigger( "^6Countdown interrupted", Map.countdown_Interrupted );
    
    // Double_door_moving
    OnTrigger( "portedouble_droite_goto", Map.Double_door_moving );
    
    // Disable Combat Movement triggers
	Beam = OnTriggerRegion(AABB(-196.190,1018.230,569.910,-117.970,1119.134,726.336), RegionTrigger.DisableCombatMovement );
    Wagon = OnTriggerRegion(AABB(-11.125,874.878,265.125,175.815,1216.875,339.130), RegionTrigger.DisableCombatMovement );
    
    //^6Axis have stolen the 5th explosive charge!!!!
    //^6Countdown interrupted
    //^6The last explosive charge has been placed!!!!
	Util.DisableGoal( ".*", true ); // all but routes
	
	//activation ALLIES
	SetAvailableMapGoals( TEAM.ALLIES, true, {
	"BUILD_Command_Post",
	"BUILD_factory_side_door",
	"DEFEND_Key.*",
	".*CAB.*"
	});
	
	//activation AXIS
	SetAvailableMapGoals( TEAM.AXIS, true, {
    "BUILD_Command_Post",
	"PLANT_train_door",
    "ATTACK_Key.*",
    ".*CAB.*"
	});

	// Max users per goal
	Util.SetMaxUsers( 1, "ATTACK.*" );
	Util.SetMaxUsers( 1, "DEFEND.*" );
	Util.SetMaxUsers( 1, "BUILD.*" );
	Util.SetMaxUsers( 1, "PLANT.*" );
    //Util.SetMaxUsers( 4, "SWITCH_Bomb" );
    Util.SetMaxUsers( 3, "FLAG.*" );

	// Camp times
    SetMapGoalProperties( "ATTACK.*", {MinCampTime=40, MaxCampTime=80} );
	SetMapGoalProperties( "DEFEND.*", {MinCampTime=40, MaxCampTime=80} );
    
	//SetPriority
	SetGoalPriority( "PLANT_Command_Post", 0.92, TEAM.AXIS, CLASS.COVERTOPS );
    SetGoalPriority( "PLANT_factory_side_door", 0.96, TEAM.AXIS, CLASS.COVERTOPS );
	SetGoalPriority( "BUILD_Command_Post", 0.92, TEAM.AXIS );
    SetGoalPriority( "PLANT_train_door", 0.96, TEAM.AXIS );
    SetGoalPriority( "SWITCH_Bomb", 0.98, TEAM.AXIS );
    SetGoalPriority( "PLANT_Command_Post", 0.92, TEAM.ALLIES, CLASS.COVERTOPS );
	SetGoalPriority( "BUILD_factory_side_door", 0.91, TEAM.ALLIES );
    SetGoalPriority( "SWITCH_Bomb", 0.98, TEAM.ALLIES );
    SetGoalPriority( "DEFEND_Armory.*", 0.96, TEAM.ALLIES );
    SetGoalPriority( "PLANTMINE_Bomb.*", 0.96, TEAM.ALLIES, CLASS.ENGINEER );
	SetGoalPriority( "BUILD_Command_Post", 0.96, TEAM.ALLIES );

	OnTrigger( "portedouble_lever1_goto", Map.Double_door_moving );
    
    //SwitchData
	Util.UpdateSwitchData();
    
    // Clear Roles on Start Map
	ClearGoalRole( "DEFEND_Bomb.*", ROLE.DEFENDER1 );
	ClearGoalRole( "DEFEND_Armory.*", ROLE.DEFENDER );
	ClearGoalRole( "ATTACK_Armory.*", ROLE.ATTACKER );
	ClearGoalRole( "ATTACK_Bomb.*", ROLE.ATTACKER1 );
    
    //Offset Plant Fix
	Util.SetGoalOffset( 0, 50, 0, "PLANT_factory_side_door" );
    
	//Util.MapDebugPrint( "Omni-bot map script for " + GetMapName() + " executed." );
    print( "^3Omni-bot map script by ^1[UJE]^3Niek ^3and ^U/^5/^D/^TXP^D*Captain ^3for " + GetMapName() + " executed & " + "Have Fun..");
};

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;
};

global InitializeRoutes = function()
{
	MapRoutes =
	{
		FLAG_gold2 =
		{
			ROUTE_S1_Axis  = 
			{
				ROUTE_Train_Left  = 
				{Weight = 4,
				},
				ROUTE_Train_Right  = 
				{Weight = 2,
				},
				ROUTE_Factory_Door  = 
				{Weight = 3,
				},
            },
        },     
		CAPPOINT_keycard = 
		{
			ROUTE_Key  = 
			{
				ROUTE_Big_Stair_Left  = 
				{
					ROUTE_Stair2_Level_1  = 
					{
						ROUTE_Stair2_Level_2  = 
						{
							ROUTE_Cappoint_Key  = 
							{
							},
						},
					},
					ROUTE_Stair1_Level_1  = 
					{
						ROUTE_Stair1_Level_2  = 
						{
							ROUTE_Cappoint_Key  = 
							{
							},
						},
					},
				},
			},
			ROUTE_Big_Stair_Right  = 
			{
				ROUTE_Stair1_Level_1  = 
				{
					ROUTE_Stair1_Level_2  = 
					{
						ROUTE_Cappoint_Key  = 
						{
						},
					},
				},
				ROUTE_Stair2_Level_1  = 
				{
					ROUTE_Stair2_Level_2  = 
					{
						ROUTE_Cappoint_Key  = 
						{
						},
					},
				},
			},
			ROUTE_Stair1  = 
			{
				ROUTE_Stair1_Level_1  = 
				{
					ROUTE_Stair1_Level_2  = 
					{
						ROUTE_Cappoint_Key  = 
						{
						},
					},
				},
			},
			ROUTE_Stair2  = 
			{
				ROUTE_Stair2_Level_1  = 
				{
					ROUTE_Stair2_Level_2  = 
					{
						ROUTE_Cappoint_Key  = 
						{
						},
					},
				},
			},
		},
		FLAG_gold = 
		{
			ROUTE_S1_Axis  = 
			{
				ROUTE_Factory_Door  = 
				{
					ROUTE_Big_Stair_Right  = 
					{
						ROUTE_Stair1_Level_1  = 
						{
							ROUTE_Stair1_Level_2  = 
							{
								ROUTE_Armory_Explosive  = 
								{
								},
							},
						},
						ROUTE_Stair2_Level_1  = 
						{
							ROUTE_Stair2_Level_2  = 
							{
								ROUTE_Armory_Explosive  = 
								{
								},
							},
						},
					},
					ROUTE_Stair1  = 
					{
						ROUTE_Stair1_Level_1  = 
						{
							ROUTE_Stair1_Level_2  = 
							{
								ROUTE_Armory_Explosive  = 
								{
								},
							},
						},
					},
					ROUTE_Stair2  = 
					{
						ROUTE_Stair2_Level_1  = 
						{
							ROUTE_Stair2_Level_2  = 
							{
								ROUTE_Armory_Explosive  = 
								{
								},
							},
						},
					},
				},
				ROUTE_Train_Left  = 
				{
					ROUTE_Big_Stair_Left  = 
					{
						ROUTE_Stair1_Level_1  = 
						{
							ROUTE_Stair1_Level_2  = 
							{
								ROUTE_Armory_Explosive  = 
								{
								},
							},
						},
					},
					ROUTE_Stair2_Level_1  = 
					{
						ROUTE_Stair2_Level_2  = 
						{
							ROUTE_Armory_Explosive  = 
							{
							},
						},
					},
				},
			},
            ROUTE_S2_Axis  = 
			{
				ROUTE_Factory_Door  = 
				{
					ROUTE_Big_Stair_Right  = 
					{
						ROUTE_Stair1_Level_1  = 
						{
							ROUTE_Stair1_Level_2  = 
							{
								ROUTE_Armory_Explosive  = 
								{
								},
							},
						},
						ROUTE_Stair2_Level_1  = 
						{
							ROUTE_Stair2_Level_2  = 
							{
								ROUTE_Armory_Explosive  = 
								{
								},
							},
						},
					},
					ROUTE_Stair1  = 
					{
						ROUTE_Stair1_Level_1  = 
						{
							ROUTE_Stair1_Level_2  = 
							{
								ROUTE_Armory_Explosive  = 
								{
								},
							},
						},
					},
					ROUTE_Stair2  = 
					{
						ROUTE_Stair2_Level_1  = 
						{
							ROUTE_Stair2_Level_2  = 
							{
								ROUTE_Armory_Explosive  = 
								{
								},
							},
						},
					},
				},
				ROUTE_Train_Left  = 
				{
					ROUTE_Big_Stair_Left  = 
					{
						ROUTE_Stair1_Level_1  = 
						{
							ROUTE_Stair1_Level_2  = 
							{
								ROUTE_Armory_Explosive  = 
								{
								},
							},
						},
					},
					ROUTE_Stair2_Level_1  = 
					{
						ROUTE_Stair2_Level_2  = 
						{
							ROUTE_Armory_Explosive  = 
							{
							},
						},
					},
				},
			},
		},
		BUILD_Command_Post =
		{
		},
		PLANT_Command_Post =
		{
		},
		BUILD_factory_side_door =
		{
		},
		PLANT_factory_side_door =
		{
		},
        CAPPOINT_dynamite = 
		{
			ROUTE_Armory_Explosive  = 
			{
				ROUTE_Door_Roof  = 
				{
					ROUTE_2Tanks  = 
					{
						ROUTE_Back_Crane  = 
						{
							ROUTE_Bomb  = 
							{
                            },
						},
                    },   
					ROUTE_Rocket  = 
					{
						ROUTE_Bomb  = 
						{
						},
					},
				},
			},
			ROUTE_Stair2_Level_2  = 
			{
				ROUTE_Stair2_Level_1  = 
				{
					ROUTE_Window2  = 
					{
						ROUTE_Bomb  = 
						{
						},
					},
                    ROUTE_Window3  = 
					{
						ROUTE_Bomb  = 
						{
						},
					},
					ROUTE_Bomb  = 
					{
					},
				},
			},
            ROUTE_Stair1_Level_2  = 
			{
				ROUTE_Window_Roof_Stair1  = 
				{
					ROUTE_Bomb  = 
					{
					},
				},
             },  
			ROUTE_Stair1_Level_2  = 
			{
				ROUTE_Stair1_Level_1  = 
				{
					ROUTE_Window2  = 
					{
					},
					ROUTE_Bomb  = 
					{
					},
				},
			},
		},
        PLANT_Train_door = 
		{
			ROUTE_S1_Axis  = 
			{
				ROUTE_Train_Left  = 
				{Weight = 4,
				},
				ROUTE_Train_Right  = 
				{Weight = 2,
				},
				ROUTE_Factory_Door  = 
				{Weight = 3,
				},
			},
		},
	};
	Util.Routes(MapRoutes);
    MapRoutes["ATTACK_Key.*"] = MapRoutes.PLANT_Train_door;
    MapRoutes["ATTACK_Armory.*"] = MapRoutes.CAPPOINT_keycard;
};
