//==========================================================================================
//
//	blackwood_b2.gm
//
//	Who                  	When		What
//------------------------------------------------------------------------------------------
//	maker@bigsighstudios.com	11 September 2018	Initial Script
//
//==========================================================================================
//

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

	BeamExploded = 0,

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

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

	Tank_Barrier_1_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "MOBILEMORTAR_747" );
		SetAvailableMapGoals( TEAM.AXIS, 1, "PLANT_Tank_Barrier_1" );
		Util.MapDebugPrint( "Tank_Barrier_1_Built" );
	},
	Tank_Barrier_1_Planted = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, 0, "PLANT_Tank_Barrier_1" );
		Util.MapDebugPrint( "Tank_Barrier_1_Planted" );
	},
	Tank_Barrier_1_Defused = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, 1, "PLANT_Tank_Barrier_1" );
		Util.MapDebugPrint( "Tank_Barrier_1_Defused" );
	},
	Tank_Barrier_1_Destroyed = function( trigger )
	{
		Util.MapDebugPrint( "Tank_Barrier_1_Destroyed" );
	},

	//added region trigger
	Tank_Barrier_1_Passed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, {
			"BUILD_Tank_Barrier_1",
			"MOBILEMORTAR_747",
			"CAMP_Def_S1_.*",
		});
		SetAvailableMapGoals( TEAM.ALLIES, 1, {
			"BUILD_Tank_Barrier_2",
			"CAMP_Def_S2_.*",
		});
		SetAvailableMapGoals( TEAM.AXIS, 0, {
			"PLANT_Tank_Barrier_1",
			"MOBILEMORTAR_756",
		});
		Util.MapDebugPrint( "Tank_Barrier_1_Passed" );
	},

	Tank_Barrier_2_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, 1, "PLANT_Tank_Barrier_2" );
		Util.MapDebugPrint( "Tank_Barrier_2_Built" );
	},
	Tank_Barrier_2_Planted = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, 0, "PLANT_Tank_Barrier_2" );
		Util.MapDebugPrint( "Tank_Barrier_2_Planted" );
	},
	Tank_Barrier_2_Defused = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, 1, "PLANT_Tank_Barrier_2" );
		Util.MapDebugPrint( "Tank_Barrier_2_Defused" );
	},
	Tank_Barrier_2_Destroyed = function( trigger )
	{
		Util.MapDebugPrint( "Tank_Barrier_2_Destroyed" );
	},

	Tank_Barrier_2_Passed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, {
			"CAMP_Def_S2_.*",
			"BUILD_Tank_Barrier_2",
		});
		SetAvailableMapGoals( TEAM.ALLIES, 1, {
			"CAMP_Def_S3_.*",
			"MOUNTMG42_481",
			"MOUNTMG42_482",
		});
		Util.MapDebugPrint( "Tank_Barrier_2_Passed" );
	},

	Loo_Blown = function( trigger )
	{
		sleep(3);
		SetAvailableMapGoals( TEAM.AXIS, 1, "BUILD_fuel_drums" );
		Util.MapDebugPrint( "Loo_Blown" );
	},

	fuel_drums_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, 1, {
			"BUILD_assault_ramp",
			"FLAG_d",
		});
		Util.MapDebugPrint( "fuel_drums_Built" );
	},
	fuel_drums_Destroyed = function( trigger )
	{
		Util.MapDebugPrint( "fuel_drums_Destroyed" );
	},

	Castle_Gate_Breached = function( trigger)
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, {
			"FLAG_d",
			"PLANT_assault_ramp",
		});
		SetAvailableMapGoals( TEAM.AXIS, 1, "FLAG_d" );
		Util.MapDebugPrint( "Castle_Gate_Breached" );
	},

	assault_ramp_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "CAMP_Def_S3_AR_1" );
		SetAvailableMapGoals( TEAM.AXIS, 1, "BUILD_Command_Post" );
		Util.MapDebugPrint( "assault_ramp_Built" );
	},
	assault_ramp_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "CAMP_Def_S3_AR_1" );
		Util.MapDebugPrint( "assault_ramp_Destroyed" );
	},

	d_Taken = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, 1, "CAPPOINT_Docs" );
		Util.MapDebugPrint( "d_Taken" );
	},
	d_Returned = function( trigger )
	{
		Util.MapDebugPrint( "d_Returned" );
	},
	d_Secured = function( trigger )
	{
		Util.MapDebugPrint( "d_Secured" );
	},


	//CP Template -----------------------------------------------------------------------------------//
	// Neutral Command Post
	CP_Owner = 0,
	CP_Dyno = 0,

	Set_CP = function(_p) // p = TEAM.ALLIES or TEAM.AXIS or 0 (unbuilt)
	{
		switch(_p)
		{
			case 0:
			{
				Map.CP_Owner = 0;
				SetAvailableMapGoals( TEAM.ALLIES, 1, "BUILD_Command_Post" );
				SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Command_Post" );
				SetAvailableMapGoals( TEAM.AXIS,   1, "BUILD_Command_Post" );
				SetAvailableMapGoals( TEAM.AXIS,   0, "PLANT_Command_Post" );
			}
			case TEAM.ALLIES:
			{
				Map.CP_Owner = TEAM.ALLIES;
				SetAvailableMapGoals( TEAM.ALLIES, 0, "BUILD_Command_Post" );
				SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Command_Post" );
				SetAvailableMapGoals( TEAM.AXIS,   1, "PLANT_Command_Post" );
				SetAvailableMapGoals( TEAM.AXIS,   0, "BUILD_Command_Post" );
			}
			case TEAM.AXIS:
			{
				Map.CP_Owner = TEAM.AXIS;
				SetAvailableMapGoals( TEAM.ALLIES, 0, "BUILD_Command_Post" );
				SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Command_Post" );
				SetAvailableMapGoals( TEAM.AXIS,   0, "PLANT_Command_Post" );
				SetAvailableMapGoals( TEAM.AXIS,   0, "BUILD_Command_Post" );
			}
		}
		//Util.MapDebugPrint("CP Owner: " + Map.CP_Owner );
	},
	Allied_CP_Built = function( trigger )
	{
		Map.Set_CP(TEAM.ALLIES);
		Util.MapDebugPrint( "Allied_CP_Built" );
	},
	Allied_CP_Destroyed = function( trigger )
	{
		Map.CP_Dyno = 0;
		Map.Set_CP(0);
		Util.MapDebugPrint( "Allied_CP_Destroyed" );
	},
	Axis_CP_Built = function( trigger )
	{
		Map.Set_CP(TEAM.AXIS);
		Util.MapDebugPrint( "Axis_CP_Built" );
	},
	Axis_CP_Destroyed = function( trigger )
	{
		Map.CP_Dyno = 0;
		Map.Set_CP(0);
		Util.MapDebugPrint( "Axis_CP_Destroyed" );
	},
	CP_Planted = function( trigger )
	{
		Map.CP_Dyno += 1;
		Util.MapDebugPrint( "CP_Planted" );
	},
	CP_Defused = function( trigger )
	{
		Map.CP_Dyno -= 1;
		Util.MapDebugPrint( "CP_Defused" );
	},
	//CP Template -----------------------------------------------------------------------------------//

	//misc
	GRENADE_Beam_Exploded = function( trigger )
	{
		Map.BeamExploded = 1;
	},

  vehicle_at_location = function( trigger )
	{
		switch(Map.VehicleLocation)
		{
			case 1:
			{
				Map.Tank_Barrier_2_Passed();
			}
		}
		Util.MapDebugPrint("vehicle at location " + Map.VehicleLocation, true);
  },

};

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

	OnTriggerRegion(AABB(2443.708,-1697.019,33.125,2720.307,-1550.893,108.037), RegionTrigger.VehicleTrigger );
	OnTrigger( "tank at location", Map.vehicle_at_location );

	OnTrigger( "GRENADE_beam Exploded.", Map.GRENADE_Beam_Exploded );

	OnTrigger( "^7The tank has been repaired", Map.Tank_Built );
	OnTrigger( "^7The tank is damaged", Map.Tank_Damaged );

	OnTrigger( "blackwood_axis_gate_dest", Map.Axis_Gate_Dest ); //tank approaching bar1

	OnTrigger( "blackwood_axis_bar1_consted", Map.Tank_Barrier_1_Built );
	OnTrigger( "Planted at Tank Barrier #1.", Map.Tank_Barrier_1_Planted );
	OnTrigger( "Defused at Tank Barrier #1.", Map.Tank_Barrier_1_Defused );
	OnTrigger( "blackwood_axis_bar_dested", Map.Tank_Barrier_1_Destroyed );

	OnTrigger( "The tank passed the first barrier!", Map.Tank_Barrier_1_Passed ); //"Setting Allied autospawn to Hut"

	OnTrigger( "blackwood_axis_bar2_consted", Map.Tank_Barrier_2_Built );
	OnTrigger( "Planted at Tank Barrier #2.", Map.Tank_Barrier_2_Planted );
	OnTrigger( "Defused at Tank Barrier #2.", Map.Tank_Barrier_2_Defused );
	OnTrigger( "blackwood_axis_bar2_dested", Map.Tank_Barrier_2_Destroyed );

	OnTrigger( "The loo was obliterated by the tank,", Map.Loo_Blown ); //"the axis can now construct a bridge from the cliff!"

	OnTrigger( "MISSING_STRING", Map.assault_ramp_Built );
	OnTrigger( "MISSING_STRING", Map.assault_ramp_Destroyed );

	OnTrigger( "^7The castle gate has been breached", Map.Castle_Gate_Breached );

	//diesel fuel barrel
	//"^7The axis can now siphon diesel into the barrel"
	OnTrigger( "^7The the diesel barrel is now filled", Map.fuel_drums_Built );
	OnTrigger( "Allies have destroyed the fuel drums!", Map.fuel_drums_Destroyed );

	OnTrigger( "^7The axis has taken the diesel barrel", Map.d_Taken );
	//"^7The diesel barrel was dropped"
	OnTrigger( "^7The diesel barrel was returned", Map.d_Returned );

	//end round
	OnTrigger( "^7The diesel has been spilled on the documents", Map.d_Secured );

	//CP Template -----------------------------------------------------------------------------------//
	OnTrigger( "Allied Command Post constructed. Charge speed increased!",  Map.Allied_CP_Built );
	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( "Allied team has destroyed the Axis Command Post!",          Map.Axis_CP_Destroyed );
	OnTrigger( "Planted at the Command Post.",                              Map.CP_Planted  );
	OnTrigger( "Defused at the Command Post.",                              Map.CP_Defused  );
	//CP Template -----------------------------------------------------------------------------------//

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

	//Util.AddUsePoint( "BUILD_assault_ramp", Vec3(4794,-5602,101) );
	//Util.AddUsePoint( "BUILD_fuel_drums", Vec3(5352,-3926,-128) );
	Util.AddUsePoint( "PLANT_Command_Post", Vec3(4121,-4533,128) );

	Util.LimitToClass( "PLANT_Command_Post", 0, 5 );

	//Allies
	SetAvailableMapGoals( TEAM.ALLIES, 1, {
		"CAMP_Def_S1_.*",
		"BUILD_Command_Post",
		"MOUNTMG42_466",
		"BUILD_Tank_Barrier_1",
	});

	//Axis
	SetAvailableMapGoals( TEAM.AXIS, 1, {
		"CAMP_Att_S1_.*",
		"MOBILEMORTAR_756",
		"BUILD_tank",
		"ESCORT_tank",
		"MOUNT_tank",
	});

	SetGoalPriority( "BUILD_Command_Post", 0.92 );
	SetGoalPriority( "PLANT_Tank_Barrier_.*", 0.93 );

	Util.ExcludeClass( "FLAG_d", 0, 3 );
	Util.LimitToClass( "PLANT_Command_Post", 0, 5 );

	// Max users per goal
	Util.SetMaxUsers( 1, "MOUNTMG42_.*" );
	Util.SetMaxUsers( 1, "CAMP_.*" );

	// Camp times
	SetMapGoalProperties( "CAMP_.*", {MinCampTime=60, MaxCampTime=300} );


	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 =
	{
		BUILD_tank =
		{
		},
		BUILD_Tank_Barrier_1 =
		{
		},
		PLANT_Tank_Barrier_1 =
		{
		},
		BUILD_Tank_Barrier_2 =
		{
		},
		PLANT_Tank_Barrier_2 =
		{
		},
		BUILD_assault_ramp =
		{
		},
		PLANT_assault_ramp =
		{
		},
		BUILD_fuel_drums =
		{
		},
		PLANT_fuel_drums =
		{
		},
		BUILD_Command_Post =
		{
		},
		PLANT_Command_Post =
		{
		},
		FLAG_d =
		{
		},
		CAPPOINT_Docs = {},

	};
	Util.Routes(MapRoutes);
};
