//==========================================================================================
//
//	battlefield_of_nightmare_noon.gm
//
//	Who                  	When		What
//------------------------------------------------------------------------------------------
//	maker@bigsighstudios.com	04 May 2018	Initial Script
//
//==========================================================================================
//

global Map =
{
	Debug = 0, // please set to zero before distributing your script
	DefendingTeam = TEAM.AXIS,

	Generator_Built = 1,
	Cave_Entrance_Intact = 1,
	Secret_Cave_Entrance_Intact = 1,
	Side_Entrance_Intact = 1,
	Main_Entrance_Intact = 1,

	Ramp_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "BUILD_Allied_assualt_ramp" );
		SetAvailableMapGoals( TEAM.ALLIES, 1, {
			"CHECKPOINT_forwardspawn",
			"PLANT_Axis_generator",
		});

		SetAvailableMapGoals( TEAM.AXIS, 1, "PLANT_Allied_assualt_ramp" );

		Wp.SetWaypointFlag("ramp1", "closed", 1);
		Wp.SetWaypointFlag("ramp2", "closed", 1);

		Util.MapDebugPrint( "Ramp_Built" );
	},
	Ramp_Destroyed = function( trigger )
	{
		if (Map.Generator_Built) {
			SetAvailableMapGoals( TEAM.ALLIES, 1, "BUILD_Allied_assualt_ramp" );
		}
		Wp.SetWaypointFlag("ramp1", "closed", 0);
		Wp.SetWaypointFlag("ramp2", "closed", 0);

		Util.MapDebugPrint( "Ramp_Destroyed" );
	},

	Axis_generator_Planted = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Axis_generator" );
		Util.MapDebugPrint( "Axis_generator_Planted" );
	},
	Axis_generator_Defused = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Axis_generator" );
		Util.MapDebugPrint( "Axis_generator_Defused" );
	},
	Axis_generator_Destroyed = function( trigger )
	{
		Map.Generator_Built = 0;
		SetAvailableMapGoals( TEAM.ALLIES, 0, {
			"PLANT_Axis_generator",
			"CAMP_b1_.*",
		});
		SetAvailableMapGoals( TEAM.ALLIES, 1, {
			"BUILD_Allied_Command_Post",
			"PLANT_Secret_cave_entrance",
			"PLANT_Cave_entrance",
		});

		SetAvailableMapGoals( TEAM.AXIS, 0, {
			"CAMP_r1_.*",
			"PLANTMINE_r1_.*,"
			"TRIPMINE_r1_.*",
			"PLANT_Allied_Command_Post",
		});
		SetAvailableMapGoals( TEAM.AXIS, 1, {
			"BUILD_Axis_Command_Post",
		});

		SetAvailableMapGoals( 0, 1, "CAMP_r2_.*" );

		Util.MapDebugPrint( "Axis_generator_Destroyed" );
	},

	Cave_entrance_Planted = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Cave_entrance" );
		SetAvailableMapGoals( TEAM.AXIS, 0, {
			"CAMP_r2_.*",
		});
		Util.MapDebugPrint( "Cave_entrance_Planted" );
	},
	Cave_entrance_Defused = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Cave_entrance" );
		Util.MapDebugPrint( "Cave_entrance_Defused" );
	},
	Cave_entrance_Destroyed = function( trigger )
	{
		Map.Cave_Entrance_Intact = 0;
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Cave_entrance" );
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Axis_depot_underground_entrance" );

		SetAvailableMapGoals( TEAM.AXIS, 0, "CAMP_r2_.*" );
		SetAvailableMapGoals( TEAM.AXIS, 1, "CAMP_r3_.*" );

		Util.MapDebugPrint( "Cave_entrance_Destroyed" );
	},

	Secret_cave_entrance_Destroyed = function( trigger )
	{
		Map.Secret_Cave_Entrance_Intact = 0;
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Secret_cave_entrance" );
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Axis_depot_underground_entrance" );
		Util.MapDebugPrint( "Secret_cave_entrance_Destroyed" );
	},

	Underground_Entrance_Planted = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Axis_depot_underground_entrance" );
		SetAvailableMapGoals( 0, 1, "CAMP_UG_.*" );
		Util.MapDebugPrint( "Underground_Entrance_Planted" );
	},
	Underground_Entrance_Defused = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Axis_depot_underground_entrance" );
		SetAvailableMapGoals( 0, 0, "CAMP_UG_.*" );
		SetAvailableMapGoals( 0, 1, "CAMP_Comp_.*" );

		Util.MapDebugPrint( "Underground_Entrance_Defused" );
	},
	Underground_Entrance_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Axis_depot_underground_entrance" );
		SetAvailableMapGoals( TEAM.ALLIES, 1, {
			"PLANT_Axis_depot_side_entrance",
		});
		Util.MapDebugPrint( "Underground_Entrance_Destroyed" );
	},

	Axis_depot_side_entrance_Planted = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Axis_depot_side_entrance" );
		Util.MapDebugPrint( "Axis_depot_side_entrance_Planted" );
	},
	Axis_depot_side_entrance_Defused = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Axis_depot_side_entrance" );
		Util.MapDebugPrint( "Axis_depot_side_entrance_Defused" );
	},
	Axis_depot_side_entrance_Destroyed = function( trigger )
	{
		Map.Side_Entrance_Intact = 0;
		SetAvailableMapGoals( TEAM.ALLIES, 0, {
			"PLANT_Axis_depot_side_entrance",
			"CAMP_b3_.*",
		});
		SetAvailableMapGoals( TEAM.ALLIES, 1, {
			"PLANT_Axis_depot_main_entrance",
			"PLANT_Axis_Computer",
		});
		SetAvailableMapGoals( TEAM.AXIS, 0, {
			"CAMP_r3_.*",
			"PLANT_Allied_Command_Post",
		});
		SetAvailableMapGoals( 0, 1, "CAMP_Comp_.*" );
		Util.MapDebugPrint( "Axis_depot_side_entrance_Destroyed" );
	},

	Main_Entrance_Planted = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Axis_depot_main_entrance" );
		Util.MapDebugPrint( "Main_Entrance_Planted" );
	},
	Main_Entrance_Defused = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Axis_depot_main_entrance" );
		Util.MapDebugPrint( "Main_Entrance_Defused" );
	},
	Main_Entrance_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Axis_depot_main_entrance" );
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Axis_computer" );
		Util.MapDebugPrint( "Main_Entrance_Destroyed" );
	},

	Axis_computer_Planted = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Axis_computer" );
		Util.MapDebugPrint( "Axis_computer_Planted" );
	},
	Axis_computer_Defused = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Axis_computer" );
		Util.MapDebugPrint( "Axis_computer_Defused" );
	},
	Axis_computer_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Axis_computer" );
		Util.MapDebugPrint( "Axis_computer_Destroyed" );
	},

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

	// Dual Command Post
	Allied_CP_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, 1, "PLANT_Allied_Command_Post" );
		Util.MapDebugPrint( "Allied_CP_Built" );
	},
	Allied_CP_Planted = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, 0, "PLANT_Allied_Command_Post" );
		Util.MapDebugPrint( "Allied_CP_Planted" );
	},
	Allied_CP_Defused = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Axis_Command_Post" );
		Util.MapDebugPrint( "Allied_CP_Defused" );
	},
	Allied_CP_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, 0, "PLANT_Allied_Command_Post" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_Allied_Command_Post" );
		Util.MapDebugPrint( "Allied_CP_Destroyed" );
	},
	Axis_CP_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Allied_Command_Post" );
		Util.MapDebugPrint( "Axis_CP_Built" );
	},
	Axis_CP_Planted = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Axis_Command_Post" );
		Util.MapDebugPrint( "Axis_CP_Planted" );
	},
	Axis_CP_Defused = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Axis_Command_Post" );
		Util.MapDebugPrint( "Axis_CP_Defused" );
	},
	Axis_CP_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Axis_Command_Post" );
		SetAvailableMapGoals( TEAM.AXIS, 1, "BUILD_Axis_Command_Post" );
		Util.MapDebugPrint( "Axis_CP_Destroyed" );
	},


};

global OnMapLoad = function()
{
	// Register callback functions

	OnTrigger( "^dThe Allies' assualt ramp has been constructed!", Map.Ramp_Built );
	OnTrigger( "^dThe Allies' assualt ramp has been destroyed!", Map.Ramp_Destroyed );

	OnTrigger( "Planted at the Axis' generator..", Map.Axis_generator_Planted );
	OnTrigger( "Defused at the Axis' generator..", Map.Axis_generator_Defused );
	OnTrigger( "^dThe Axis' generator has been destroyed!", Map.Axis_generator_Destroyed );

	OnTrigger( "Planted at Cave entrance.", Map.Cave_entrance_Planted );
	OnTrigger( "Defused at Cave entrance.", Map.Cave_entrance_Defused );
	OnTrigger( "^dThe cave entrance has been destroyed!", Map.Cave_entrance_Destroyed );

	OnTrigger( "^dThe Secret cave entrance has been destroyed!", Map.Secret_cave_entrance_Destroyed );

	OnTrigger( "^dThe Axis' depot side entrance has been destroyed!", Map.Axis_depot_side_entrance_Destroyed );

	OnTrigger( "Planted at Axis' depot main entrance.", Map.Main_Entrance_Planted );
	OnTrigger( "Defused at Axis' depot main entrance.", Map.Main_Entrance_Defused );
	OnTrigger( "^dThe Axis' depot main entrance has been destroyed!", Map.Main_Entrance_Destroyed );

	OnTrigger( "Planted at Axis' depot underground entrance.", Map.Underground_Entrance_Planted );
	OnTrigger( "^dThe Axis' depot underground entrance has been destroyed!", Map.Underground_Entrance_Destroyed );

	OnTrigger( "^dThe Axis' computer has been destroyed!", Map.Axis_computer_Destroyed );

	OnTrigger( "^dAllies capture the inspection place flag!", Map.Allies_Forward_Spawn_Captured );
	OnTrigger( "^dAxis reclaim the inspection place flag!", Map.Axis_Forward_Spawn_Captured );

	OnTrigger( "^dAllied Command Post constructed. Charge speed increased!",  Map.Allied_CP_Built );
	OnTrigger( "Planted at the Allied Command Post.",                       Map.Allied_CP_Planted );
	OnTrigger( "Defused at the Allied Command Post.",                       Map.Allied_CP_Defused );
	OnTrigger( "Axis team has destroyed the Allied Command Post!",          Map.Allied_CP_Destroyed );

	OnTrigger( "Axis Command Post constructed. Charge speed increased!",    Map.Axis_CP_Built );
	OnTrigger( "Planted at the Axis Command Post.",                         Map.Axis_CP_Planted );
	OnTrigger( "Defused at the Axis Command Post.",                         Map.Axis_CP_Defused );
	OnTrigger( "Allied team has destroyed the Axis Command Post!",          Map.Axis_CP_Destroyed );

	OnTriggerRegion(AABB(3880.274,4487.239,9.125,4332.569,4857.297,83.125), RegionTrigger.DisableBotPush);

	//maybe later OnTriggerRegion(AABB(7291.639,3759.388,2.444,7487.726,3841.560,107.125), Map.TRIGGERNAME);

	Util.DisableGoal( ".*", true ); // all but routes

	//Allies
	SetAvailableMapGoals( TEAM.ALLIES, 1, {
		"CAMP_b1_.*",
		"BUILD_Allied_assualt_ramp",
		"CHECKPOINT_forwardspawn",
	});
	Util.LimitToClass( "PLANT_Secret_cave_entrance", 2, 5 );

	//Axis
	SetAvailableMapGoals( TEAM.AXIS, 1, {
		"CAMP_r1_.*",
		"PLANTMINE_r1_.*",
		//"BUILD_Axis_Command_Post",
		"CHECKPOINT_forwardspawn",
	});

	if(GetModName() == "silent")
	{
		SetAvailableMapGoals( TEAM.AXIS, 1, "TRIPMINE_r1_.*" );
	}

	Util.LimitToClass( "PLANT_Allied_assualt_ramp", 1, 5 );

	SetGoalPriority("PLANTMINE_.*", 1.2, TEAM.AXIS, CLASS.ENGINEER);
	SetGoalPriority("PLANT_Allied_assualt_ramp", 1.2, TEAM.AXIS, CLASS.COVERTOPS);
	SetGoalPriority("CAMP_r1_8", 1.2, TEAM.AXIS, CLASS.SOLDIER);

	Util.AddUsePoint( "PLANT_Allied_assualt_ramp", Vec3(4292,4501,142) );
	Util.AddUsePoint( "PLANT_Allied_assualt_ramp", Vec3(4145,4525,32) );
	Util.AddUsePoint( "PLANT_Secret_cave_entrance", Vec3(5737,3482,36) );
	Util.AddUsePoint( "PLANT_Axis_depot_side_entrance", Vec3(11910,2999,122) );

	Wp.SetWaypointFlag("ramp1", "closed", 0);
	Wp.SetWaypointFlag("ramp2", "closed", 0);


	// Max users per goal
	Util.SetMaxUsers( 1, "MOUNTMG42_.*" );
	Util.SetMaxUsers( 2, "CHECKPOINT_forwardspawn" );
	Util.SetMaxUsers( 1, "PLANTMINE_.*" );
	Util.SetMaxUsers( 1, "TRIPMINE_.*" );

	// Camp times
	SetMapGoalProperties( "MOUNTMG42_.*", {MinCampTime=15, MaxCampTime=90} );
	SetMapGoalProperties( "CAMP_.*", {MinCampTime=90, MaxCampTime=900} );

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

global InitializeRoutes = function()
{
	MapRoutes =
	{
		CHECKPOINT_forwardspawn = {},

		PLANT_Axis_generator = {},

		BUILD_Allied_assualt_ramp =
		{
		},
		PLANT_Allied_assualt_ramp =
		{
		},
		BUILD_Allied_Command_Post =
		{
		},
		PLANT_Allied_Command_Post =
		{
		},
		PLANT_Axis_computer =
		{
		},
		PLANT_Axis_depot_side_entrance =
		{
		},

		PLANT_Axis_depot_main_entrance = {},

		BUILD_Axis_Command_Post =
		{
		},
		PLANT_Axis_Command_Post =
		{
		},
		PLANT_Axis_depot_underground_entrance =
		{
		},
		BUILD_Secret_cave_entrance =
		{
		},
		PLANT_Secret_cave_entrance =
		{
		},
		PLANT_Cave_entrance = {},

	};
	Util.Routes(MapRoutes);
};
