//==========================================================================================
//
//	blood.gm
//
//	Who                  	When		What
//------------------------------------------------------------------------------------------
//	maker@bigsighstudios.com	25 October 2017	Initial Script
//
//==========================================================================================
//

global Map =
{
	Debug = 1, // please set to zero before distributing your script
	ShowMovers = false,

	North_Tower_Dyno = 0,
	South_Tower_Dyno = 0,
	tunnel_gate_Dyno = 0,
	tunnel_wall_Dyno = 0,

	//Door status flags, 1 = intact
	Door1 = 1,
	Door2 = 1,
	Tunnel_Gate = 1,
	Tunnel_Wall = 1,

	//Tank status + location
	TankBuilt = 0,
	TruckBuilt = 1,

	//trigger pointers
	tr_TankAtDoor1    = 0,
	tr_TankAtDoor2    = 0,
	tr_TruckExitsBase = 0,


	//Main Base features =========================================================
	North_Tower_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_North_Tower" );
		Util.MapDebugPrint( "North_Tower_Built" );
	},
	North_Tower_Planted = function( trigger )
	{
		Map.North_Tower_Dyno += 1;
		Util.MapDebugPrint( "North_Tower_Planted" );
	},
	North_Tower_Defused = function( trigger )
	{
		Map.North_Tower_Dyno -= 1;
		Util.MapDebugPrint( "North_Tower_Defused" );
	},
	North_Tower_Destroyed = function( trigger )
	{
		Map.North_Tower_Dyno = 0;
		SetAvailableMapGoals( TEAM.ALLIES, false, "PLANT_North_Tower" );
		SetAvailableMapGoals( TEAM.AXIS, true, "BUILD_North_Tower" );
		Util.MapDebugPrint( "North_Tower_Destroyed" );
	},

	South_Tower_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_South_Tower" );
		SetAvailableMapGoals( TEAM.AXIS, false, "BUILD_South_Tower" );
		Util.MapDebugPrint( "South_Tower_Built" );
	},
	South_Tower_Planted = function( trigger )
	{
		Map.South_Tower_Dyno += 1;
		Util.MapDebugPrint( "South_Tower_Planted" );
	},
	South_Tower_Defused = function( trigger )
	{
		Map.South_Tower_Dyno -= 1;
		Util.MapDebugPrint( "South_Tower_Defused" );
	},
	South_Tower_Destroyed = function( trigger )
	{
		Map.South_Tower_Dyno = 0;
		SetAvailableMapGoals( TEAM.ALLIES, false, "PLANT_South_Tower" );
		SetAvailableMapGoals( TEAM.AXIS, true, "BUILD_South_Tower" );
		Util.MapDebugPrint( "South_Tower_Destroyed" );
	},

	//Vehicles ===================================================================
	vehicle_at_location = function( trigger )
	{
		switch(Map.VehicleLocation)
		{
			case 1:
			{
	      Map.Tank_At_Door_1();
			}
			case 2:
			{
				Map.Tank_At_Door_2();
			}
			case 3:
			{
				Map.Truck_Exits_Base();
			}
			case 4:
			{
				Map.Truck_Past_Forward_Spawn();
			}
			case 5:
			{
				Map.Truck_At_Escape();
			}
		}
		Util.MapDebugPrint("vehicle at location " + Map.VehicleLocation, true);
	},

	//Forward Spawn Base =========================================================
	Tank_At_Door_1 = function( trigger )
	{
		//Map.tr_TankAtDoor1 = 1; assigned by regiontrigger setup
		Util.MapDebugPrint( "Tank_At_Door_1 - Map.TankAtDoor1 = " + Map.tr_TankAtDoor1 );
	},

	Door1_Destroyed = function( trigger )
	{
		Map.Door1 = 0;

		SetAvailableMapGoals( TEAM.ALLIES, true, { "CHECKPOINT_.*",
																							 "PLANT_tunnel_gate",
																							 "PLANT_tunnel_wall" });

		Util.MapDebugPrint( "Door1_Destroyed" );
	},

	//Main Base ==================================================================
	Tank_At_Door_2 = function( trigger )
	{
		//Map.tr_TankAtDoor2 = 1;
		DeleteTriggerRegion( Map.TR_Tank_At_Door_2 );
		Util.MapDebugPrint( "Tank_At_Door_2 - Map.TankAtDoor2 = " + Map.tr_TankAtDoor2 );
	},

	Door2_Destroyed = function( trigger )
	{
		Map.Door2 = 0;

		SetAvailableMapGoals( TEAM.ALLIES, false, { "BUILD_Tank",
																								"ESCORT_Tank" } );

		SetAvailableMapGoals( TEAM.ALLIES, true,  { "FLAG_Book",
																								"CAPPOINT_Book",
																								"BUILD_Truck",
																								"ESCORT_Truck",
																								"CAMP_Allies_Truck_.*" } );
		Util.MapDebugPrint( "Door2_Destroyed" );
	},

	Tank_Built = function( trigger )
	{
		TankBuilt = 1;
		SetAvailableMapGoals( TEAM.ALLIES, false, "BUILD_Tank" );
		Util.MapDebugPrint( "Tank_Built" );
	},
	Tank_Damaged = function( trigger )
	{
		TankBuilt = 0;
		SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_Tank" );
		Util.MapDebugPrint( "Tank_Damaged" );
	},

	Truck_Built = function( trigger )
	{
		TruckBuilt = 1;
		SetAvailableMapGoals( TEAM.AXIS, true, "ATTACK_Truck.*" );
		Util.MapDebugPrint( "Truck_Built" );
	},
	Truck_Damaged = function( trigger )
	{
		TruckBuilt = 0;
		SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_Truck" );
		SetAvailableMapGoals( TEAM.AXIS, false, "ATTACK_Truck.*" );
		Util.MapDebugPrint( "Truck_Damaged" );
	},

	Truck_Exits_Base = function( trigger ) //Main Base
	{
		Util.MapDebugPrint( "Truck_Exits_Base" );
	},
	Truck_Past_Forward_Spawn = function( trigger ) //Forward Spawn
	{
		Util.MapDebugPrint( "Truck_Past_Forward_Spawn" );
	},
	Truck_At_Escape = function( trigger )
	{
		Util.MapDebugPrint( "Truck_At_Escape" );
	},


	//Underground ================================================================
	tunnel_gate_Built = function( trigger )
	{
		Map.Tunnel_Gate = 1;
		SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_tunnel_gate" );
		Util.MapDebugPrint( "tunnel_gate_Built" );
	},
	tunnel_gate_Planted = function( trigger )
	{
		Map.tunnel_gate_Dyno += 1;
		SetAvailableMapGoals( TEAM.ALLIES, false, "PLANT_tunnel_gate" );
		Util.MapDebugPrint( "tunnel_gate_Planted" );
	},
	tunnel_gate_Defused = function( trigger )
	{
		Map.tunnel_gate_Dyno -= 1;
		SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_tunnel_gate" );
		Util.MapDebugPrint( "tunnel_gate_Defused" );
	},
	tunnel_gate_Destroyed = function( trigger )
	{
		Map.Tunnel_Gate = 0;
		Map.tunnel_gate_Dyno = 0;
		SetAvailableMapGoals( TEAM.AXIS, true, "BUILD_tunnel_gate" );
		Util.MapDebugPrint( "tunnel_gate_Destroyed" );
	},

	tunnel_wall_Built = function( trigger )
	{
		Map.Tunnel_Wall = 1;
		SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_tunnel_wall" );
		Util.MapDebugPrint( "tunnel_wall_Built" );
	},
	tunnel_wall_Planted = function( trigger )
	{
		Map.tunnel_wall_Dyno += 1;
		Util.MapDebugPrint( "tunnel_wall_Planted" );
	},
	tunnel_wall_Defused = function( trigger )
	{
		Map.tunnel_wall_Dyno -= 1;
		Util.MapDebugPrint( "tunnel_wall_Defused" );
	},
	tunnel_wall_Destroyed = function( trigger )
	{
		Map.Tunnel_Wall = 0;
		Map.tunnel_wall_Dyno = 0;
		SetAvailableMapGoals( TEAM.ALLIES, false, "PLANT_tunnel_wall" );
		SetAvailableMapGoals( TEAM.AXIS, true, "BUILD_tunnel_wall" );
		Util.MapDebugPrint( "tunnel_wall_Destroyed" );
	},

	//Objectives =================================================================
	Book_Taken = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, true, "CAPPOINT_Book" );
		Util.MapDebugPrint( "Book_Taken" );
	},
	Book_Going = function( trigger )
	{
		Util.MapDebugPrint( "Book_Going" );
	},
	Book_Returned = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, false, "CAPPOINT_Book" );
		Util.MapDebugPrint( "Book_Returned" );
	},
	Book_Secured = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, false, "CAPPOINT_Book" );
		Util.MapDebugPrint( "Book_Secured" );
	},

	//Spawns =====================================================================
	forwardspawn1_flag_Axis_Captured = function( trigger )
	{
		Util.MapDebugPrint( "forwardspawn1_flag_Axis_Captured" );
	},
	forwardspawn1_flag_Allies_Captured = function( trigger )
	{
		Util.MapDebugPrint( "forwardspawn1_flag_Allies_Captured" );
	},


};

global OnMapLoad = function()
{
	if ( TestMapOn ) { Util.AutoTestMap(); }

	// Register callback functions
	OnTrigger( "Allied team has destroyed the  Main Gate!", Map.Door1_Destroyed );
	OnTrigger( "Allied team has destroyed the Second Main Gate!", Map.Door2_Destroyed );

	OnTrigger( "The North Tower has been constructed!", Map.North_Tower_Built );
	OnTrigger( "Planted at the North Tower.", Map.North_Tower_Planted );
	OnTrigger( "Defused at the North Tower.", Map.North_Tower_Defused );
	OnTrigger( "Allies have destroyed the North Tower!", Map.North_Tower_Destroyed );

	OnTrigger( "The South Tower has been constructed!", Map.South_Tower_Built );
	OnTrigger( "Planted at the South Tower.", Map.South_Tower_Planted );
	OnTrigger( "Defused at the South Tower.", Map.South_Tower_Defused );
	OnTrigger( "Allies have destroyed the South Tower!", Map.South_Tower_Destroyed );

	OnTrigger( "The Tank has been repaired!", Map.Tank_Built );
	OnTrigger( "The Tank has been damaged!", Map.Tank_Damaged );

	OnTrigger( "Allies have repaired the Truck!", Map.Truck_Built );
	OnTrigger( "The Truck has been damaged!", Map.Truck_Damaged );

	OnTrigger( "Axis have built the Tunnel Gate!", Map.tunnel_gate_Built );
	OnTrigger( "Planted at tunnel_gate.", Map.tunnel_gate_Planted );
	OnTrigger( "Defused at the Tunnel Gate.", Map.tunnel_gate_Defused );
	OnTrigger( "The Tunnel gate has been destroyed!", Map.tunnel_gate_Destroyed );

	OnTrigger( "Axis have built the Tunnel Wall!", Map.tunnel_wall_Built );
	OnTrigger( "Planted at tunnel_wall.", Map.tunnel_wall_Planted );
	OnTrigger( "Defused at the Tunnel Wall.", Map.tunnel_wall_Defused );
	OnTrigger( "The Tunnel wall has been destroyed!", Map.tunnel_wall_Destroyed );

	OnTrigger( "Allies have stolen the Book!", Map.Book_Taken );
	OnTrigger( "Allied team is escaping with the Book!", Map.Book_Going );
	OnTrigger( "Axis have returned the Book!", Map.Book_Returned );
	OnTrigger( "Book", Map.Book_Secured );

	OnTrigger( "Allies capture the Forward Spawn!", Map.forwardspawn1_flag_Axis_Captured );
	OnTrigger( "Axis capture the Forward Spawn!", Map.forwardspawn1_flag_Allies_Captured );

	OnTrigger( "tank at location", Map.vehicle_at_location );

	Map.tr_TankAtDoor1    = OnTriggerRegion(AABB(5409.249,1490.096,-382.875,5658.929,1660.420,-308.875), RegionTrigger.VehicleTrigger);

	//Map.tr_TankAtDoor2    = OnTriggerRegion(AABB(4879.336,1484.107,-382.875,5161.230,1805.693,-308.875), RegionTrigger.VehicleTrigger);
	Map.tr_TankAtDoor2    = OnTriggerRegion(AABB(978.428,1659.374,-382.875,1283.954,2040.766,-308.875 ), RegionTrigger.VehicleTrigger);
	Map.tr_TruckExitsBase = OnTriggerRegion(AABB(864.916,876.604,-382.875,1069.756,1109.506,-308.875  ), RegionTrigger.VehicleTrigger);

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

	Util.EnableGoal( "HEALTHCAB_.*", true );
	Util.EnableGoal( "AMMOCAB_.*", true );

	//Axis
	SetAvailableMapGoals( TEAM.AXIS, true, "CHECKPOINT_forwardspawn1_flag" );
	SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_.*" );

	//Allies
	SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_.*" );
	SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_Tank" );
	SetAvailableMapGoals( TEAM.ALLIES, true, "ESCORT_Tank" );
	SetAvailableMapGoals( TEAM.ALLIES, true, "MOUNT_Tank" );

	SetGoalPriority( "BUILD_Tank", 0.91, TEAM.ALLIES, CLASS.ENGINEER );
	SetGoalPriority( "ESCORT_tank", 0.90, TEAM.ALLIES );

	ETUtil.SetStartIndex("ESCORT_Tank", 1);
	ETUtil.SetStartIndex("MOUNT_Tank", 1);
	//ETUtil.SetStartIndex("BUILD_Truck", 0);

/*
	// Max users per goal
	Util.SetMaxUsers( 3, "ATTACK_.*" );
	Util.SetMaxUsers( 3, "DEFEND_.*" );
	Util.SetMaxUsers( 1, "GRENADE_.*" );
	Util.SetMaxUsers( 1, "SNIPE_.*" );
	Util.SetMaxUsers( 1, "MOUNTMG42_.*" );
	Util.SetMaxUsers( 1, "MOBILEMG42_.*" );
	Util.SetMaxUsers( 1, "MOBILEMORTAR_.*" );
	Util.SetMaxUsers( 1, "AIRSTRIKE_.*" );
	Util.SetMaxUsers( 1, "CALLARTILLERY_.*" );
	Util.SetMaxUsers( 2, "ESCORT_.*" );
*/

	// Camp times
	SetMapGoalProperties( "MOUNTMG42_.*", {MinCampTime=15, MaxCampTime=90} );
	SetMapGoalProperties( "MOBILEMG42_.*", {MinCampTime=10, MaxCampTime=60} );

	Util.AddUsePoint("PLANT_South_Tower", Vec3( 574, 217, 0 ) );

	ETUtil.SetCabinets();

	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_forwardspawn1_flag =
		{
			ROUTE_Allied_Spawn =
			{
				ROUTE_Tank_At_FS = {},
			},
		},

		BUILD_Tank =
		{
			ROUTE_Allied_Spawn = {},
		},

		FLAG_Book =
		{
		},

		BUILD_Truck =
		{
		},

		BUILD_tunnel_wall =
		{
		},
		PLANT_tunnel_wall =
		{
		},

		BUILD_tunnel_gate =
		{
		},
		PLANT_tunnel_gate =
		{
		},

		BUILD_South_Tower =
		{
		},
		PLANT_South_Tower =
		{
		},

		BUILD_North_Tower =
		{
		},
		PLANT_North_Tower =
		{
		},

	};
	Util.Routes(MapRoutes);

/*
	ROUTE_Allied_Spawn =
	ROUTE_Tank_At_Door_1 =
	ROUTE_Tank_At_Door_2 =
	ROUTE_Tank_Start =

*/

};
