global Map =
{
	Holy_Documents = "FLAG_cross_docs",
	Holy_Documents_cappoint = "CAPPOINT_Holy_Documents",

	Generator_Flag = "CHECKPOINT_generator_spawn_flag",

	Destroy_Generator_Controls = "PLANT_Generator_controls",
	Destroy_Castle_Wall = "PLANT_Castle_wall",
	Destroy_Dracula_Chest = "PLANT_Dracula_chest",

	Build_Castle_Wall = "BUILD_Castle_wall",

	Holy_Docs_Status = 0,
	Generator_Status = 0,
	Generator_Flag_status = 0,
	Castle_Wall_Status = 0,

	Dracula_Chest_Dynamites = 0,

	Allies_Capture_Flag = function()
	{
		Map.Generator_Flag_status = 1;
		SetAvailableMapGoals( TEAM.ALLIES, false, Map.Generator_Flag );
		SetAvailableMapGoals( TEAM.AXIS, true, Map.Generator_Flag );

		Util.MapDebugPrint( "Allies_Capture_Flag" );
	},
	Axis_Capture_Flag = function()
	{
		Map.Generator_Flag_status = 0;
		SetAvailableMapGoals( TEAM.ALLIES, true, Map.Generator_Flag );
		SetAvailableMapGoals( TEAM.AXIS, false, Map.Generator_Flag );

		Util.MapDebugPrint( "Axis_Capture_Flag" );
	},

	Generator_Controls_Destroyed = function()
	{
		Map.Generator_Status = 1;
		SetAvailableMapGoals( TEAM.ALLIES, false, Map.Destroy_Generator_Controls );
		if( Map.Holy_Docs_Status == 1 )
		{
			SetAvailableMapGoals( TEAM.ALLIES, true, Map.Generator_Flag );
			SetAvailableMapGoals( TEAM.AXIS, true, Map.Generator_Flag );
		}
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			Map.Destroy_Castle_Wall,
			Map.Destroy_Dracula_Chest,
		});

		SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_Generator_.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_Castle_Defend.*" );
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_Generator_.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"DEFEND_Castle_Defend.*",
			"PLANTMINE_Castle_Wall_.*",
		});

		Util.MapDebugPrint( "Generator_Controls_Destroyed" );
	},

	Documents_Stolen = function()
	{
		Map.Holy_Docs_Status = 0;
		SetAvailableMapGoals( TEAM.ALLIES, false, "FLAG_cross_docs" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "CAPPOINT_Holy_Documents" );
		SetAvailableMapGoals( TEAM.AXIS, false, {
			"DEFEND_Generator_.*",
			"DEFEND_Holy_Documents_.*",
		});
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_Holy_Documents_cappoint_.*" );
		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"DEFEND_Generator_.*",
			"DEFEND_Holy_Documents_.*",
		});
		SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_Holy_Documents_cappoint_.*" );

		Util.MapDebugPrint( "Documents_Stolen" );
	},
	Documents_Returned = function()
	{
		Map.Holy_Docs_Status = -1;
		SetAvailableMapGoals( TEAM.ALLIES, true, "FLAG_cross_docs" );
		SetAvailableMapGoals( TEAM.ALLIES, false, Map.Holy_Documents_cappoint );
		SetAvailableMapGoals( TEAM.AXIS, true, {
			"DEFEND_Generator_.*",
			"DEFEND_Holy_Documents_.*",
		});
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_Holy_Documents_cappoint_.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"DEFEND_Generator_.*",
			"DEFEND_Holy_Documents_.*",
		});
		SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_Holy_Documents_cappoint_.*" );

		Util.MapDebugPrint( "Documents_Returned" );
	},
	Documents_Delivered = function()
	{
		Map.Holy_Docs_Status = 1;
		SetAvailableMapGoals( TEAM.ALLIES, false, {
			"FLAG_cross_docs",
			"CAPPOINT_Holy_Documents",
		});
		if( Map.Generator_Status == 1 )
		{
			SetAvailableMapGoals( TEAM.ALLIES, true, Map.Generator_Flag );
			SetAvailableMapGoals( TEAM.AXIS, true, Map.Generator_Flag );
		}
		SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_Holy_Documents_.*" );
		SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_Holy_Documents_.*" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "DEFEND_Generator_.*" );
		SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_Generator_.*" );

		Util.MapDebugPrint( "Documents_Delivered" );
	},

	Castle_Wall_Built = function()
	{
		Map.Castle_Wall_Status = 0;
		SetAvailableMapGoals( TEAM.ALLIES, true, Map.Destroy_Castle_Wall );
		SetAvailableMapGoals( TEAM.AXIS, false, Map.Build_Castle_Wall );
		Util.MapDebugPrint( "Castle_Wall_Built" );
	},
	Castle_Wall_Destroyed = function()
	{
		Map.Castle_Wall_Status = 1;
		SetAvailableMapGoals( TEAM.ALLIES, false, Map.Destroy_Castle_Wall );
		SetAvailableMapGoals( TEAM.AXIS, true, Map.Build_Castle_Wall );

		Util.MapDebugPrint( "Castle_Wall_Destroyed" );
	},

	Dracula_Chest_Planted = function()
	{
		Map.Dracula_Chest_Dynamites += 1;
		SetAvailableMapGoals( TEAM.ALLIES, false, Map.Generator_Flag );
		SetAvailableMapGoals( TEAM.AXIS, false, Map.Generator_Flag );

		Util.MapDebugPrint( "Castle_Wall_Built" );
	},
	Dracula_Chest_Defused = function()
	{
		Map.Dracula_Chest_Dynamites -= 1;
		if(Dracula_Chest_Dynamites == 0)
		{
			SetAvailableMapGoals( TEAM.ALLIES, true, Map.Generator_Flag );
			SetAvailableMapGoals( TEAM.AXIS, true, Map.Generator_Flag );

		}
		Util.MapDebugPrint( "Castle_Wall_Destroyed" );
	},

};

global OnMapLoad = function()
{
	OnTrigger( "Allies have stolen Allies Holy Documents!", Map.Documents_Stolen );
	OnTrigger( "Axis have returned Allies Holy Documents!", Map.Documents_Returned );
	OnTrigger( "Holy Documents delivered!", Map.Documents_Delivered );
	OnTrigger( "Generator has been destroyed!", Map.Generator_Controls_Destroyed );
	OnTrigger( "Allied captured generator spawn!", Map.Allies_Capture_Flag );
	OnTrigger( "Axis captured generator spawn!", Map.Axis_Capture_Flag );
	OnTrigger( "Axis team has built Castle wall.", Map.Castle_Wall_Built );
	OnTrigger( "Allies team has destroyed the Castle wall!", Map.Castle_Wall_Destroyed );
	OnTrigger( "Planted at Dracula chest.", Map.Dracula_Chest_Planted );
	OnTrigger( "Defused at Dracula chest.", Map.Dracula_Chest_Defused );

	// Max users per goal
	Util.SetMaxUsers( 2, Map.Holy_Documents );
	Util.SetMaxUsers( 1, Map.Generator_Flag );
	Util.SetMaxUsers( 1, "DEFEND_.*" );
	Util.SetMaxUsers( 1, "PLANT_.*" );

	// Allied goals
	SetAvailableMapGoals( TEAM.ALLIES, false, ".*" );

	SetAvailableMapGoals( TEAM.ALLIES, true, {
		Map.Holy_Documents,
		Map.Destroy_Generator_Controls,
		"DEFEND_Holy_Documents.*",
	});
	SetAvailableMapGoals( TEAM.ALLIES, false, "DEFEND_Holy_Documents_cappoint_.*" );
	SetAvailableMapGoals( TEAM.ALLIES, true, {
		"SNIPE_Snipe_.*",
		"HEALTHCAB_.*",
		"AMMOCAB_.*",
		"ROUTE_.*",
	});

	// Axis goals
	SetAvailableMapGoals( TEAM.AXIS, false, ".*" );

	SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_Holy_Documents_.*" );
	SetAvailableMapGoals( TEAM.AXIS, false, "DEFEND_Holy_Documents_cappoint_.*" );
	SetAvailableMapGoals( TEAM.AXIS, true, {
		"DEFEND_Generator_.*",
		"HEALTHCAB_.*",
		"AMMOCAB_.*",
		"ROUTE_.*",
	});

	MapRoutes =
	{
		FLAG_cross_docs =
		{
			ROUTE_Allied_Spawn_1 =
			{
				ROUTE_Left =
				{
					ROUTE_Well =
					{
					},
				},
				ROUTE_Center =
				{
				},
				ROUTE_Right =
				{
				},
				ROUTE_Roof =
				{
					ROUTE_Roof_Right =
					{
					},
				},
			},
			ROUTE_Allied_Spawn_2 =
			{
				ROUTE_Left =
				{
					ROUTE_Well =
					{
					},
				},
				ROUTE_Center =
				{
				},
				ROUTE_Right =
				{
				},
				ROUTE_Roof =
				{
					ROUTE_Roof_Right =
					{
					},
				},
			},
		},
		CAPPOINT_Holy_Documents =
		{
			ROUTE_objective =
			{
				ROUTE_Right =
				{
					ROUTE_Center =
					{
						ROUTE_Church_Back =
						{
						},
					},
					ROUTE_Roof =
					{
						ROUTE_Roof_Left =
						{
							ROUTE_Roof_Church =
							{
							},
						},
					},
				},
				ROUTE_Near_Well =
				{
				},
				ROUTE_Between_Houses =
				{
				},
			}
		},
		PLANT_Generator_controls =
		{
			ROUTE_Church_Spawn_1 =
			{
				ROUTE_Church_Left =
				{
				},
				ROUTE_Church_Front =
				{
				},
				ROUTE_Church_Right =
				{
					Weight = 10,
				},
			},
			ROUTE_Church_Spawn_2 =
			{
				ROUTE_Church_Left =
				{
				},
				ROUTE_Church_Front =
				{
				},
				ROUTE_Church_Right =
				{
					Weight = 10,
				},
			},
		},
		PLANT_Dracula_chest =
		{
			ROUTE_Church_Spawn_1 =
			{
				ROUTE_Castle_2nd_Floor_Left =
				{
				},
				ROUTE_Castle_2nd_Floor_Right =
				{
				},
			},
			ROUTE_Church_Spawn_2 =
			{
				ROUTE_Castle_2nd_Floor_Left =
				{
				},
				ROUTE_Castle_2nd_Floor_Right =
				{
				},
			}
		},
	};
	MapRoutes.DEFEND_Holy_Documents_1 = MapRoutes.FLAG_cross_docs;
	MapRoutes.DEFEND_Holy_Documents_2 = MapRoutes.FLAG_cross_docs;
	MapRoutes.DEFEND_Holy_Documents_3 = MapRoutes.FLAG_cross_docs;
	MapRoutes.DEFEND_Holy_Documents_cappoint_1 = MapRoutes.CAPPOINT_Holy_Documents;
	MapRoutes.DEFEND_Holy_Documents_cappoint_2 = MapRoutes.CAPPOINT_Holy_Documents;
	Util.Routes(MapRoutes);

	Util.MapDebugPrint( "All done! xD" );
};

global OnBotJoin = function( bot )
{
	bot.TargetBreakableDist = 100.0;
};
