//==========================================================================================
//
//	powcamp_b5.gm
//
//	Who                  	When		What
//------------------------------------------------------------------------------------------
//	maker@bigsighstudios.com	03 March 2018	Initial Script
//
//==========================================================================================
//

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

	Use_MG42 = 1, //set to 0 to disable use of MG42's

	Garrison_Door_Intact = 1,

	Tank_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "BUILD_Tank" );
		SetAvailableMapGoals( TEAM.ALLIES, 1, "ESCORT_Tank" );
		SetAvailableMapGoals( TEAM.ALLIES, 1, "MOUNT_Tank" );
		SetAvailableMapGoals( TEAM.AXIS, 1, "MOUNT_Tank" );
		Util.MapDebugPrint( "Tank_Built" );
	},
	Tank_Damaged = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "BUILD_Tank" );
		SetAvailableMapGoals( TEAM.ALLIES, 0, "ESCORT_Tank" );
		SetAvailableMapGoals( TEAM.ALLIES, 0, "MOUNT_Tank" );
		SetAvailableMapGoals( TEAM.AXIS, 0, "MOUNT_Tank" );
		Util.MapDebugPrint( "Tank_Damaged" );
	},

	Sola_River_Bridge_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "BUILD_Sola_River_Bridge" );
		if ( Map.Garrison_Door_Intact )
		{
			SetAvailableMapGoals( TEAM.AXIS, 1, "PLANT_Sola_River_Bridge" );
		}
		Util.MapDebugPrint( "Sola_River_Bridge_Built" );
	},
	Sola_River_Bridge_Planted = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, 0, "PLANT_Sola_River_Bridge" );
		Util.MapDebugPrint( "Sola_River_Bridge_Planted" );
	},
	Sola_River_Bridge_Destroyed = function( trigger )
	{
		if ( Map.Garrison_Door_Intact )
		{
			SetAvailableMapGoals( TEAM.ALLIES, 1, "BUILD_Sola_River_Bridge" );
		}
		SetAvailableMapGoals( TEAM.AXIS, 0, "PLANT_Sola_River_Bridge" );
		Util.MapDebugPrint( "Sola_River_Bridge_Destroyed" );
	},

	//Tank blows garrison door
	Garrison_Door_Destroyed  = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, {
			"BUILD_Neutral_Command_Post",
			"FLAG_allied_gold",
		});
		SetAvailableMapGoals( TEAM.ALLIES, 0, {
			"SNIPE_ATTACK_.*",
			"ESCORT_Tank",
			"BUILD_Tank",
			"BUILD_Sola_River_Bridge",
		});

		SetAvailableMapGoals( TEAM.AXIS, 1, {
			"BUILD_Gas_Control",
			"BUILD_Invasion_Barrier",
		});

		Util.MapDebugPrint( "Garrison_Door_Destroyed" );
	},

	// *** Major Event: Phase 2

	Main_Gate_Open = function( trigger )
	{
		Map.Garrison_Door_Intact = 0;
		SetAvailableMapGoals( TEAM.ALLIES, 1, {
			"CHECKPOINT_superflag",
			"BUILD_Assault_Ramp",
			"PLANT_execution_wall",
			"PLANT_Neutral_Command_Post",
		});
		SetAvailableMapGoals( TEAM.ALLIES, 0, {
		});

		SetAvailableMapGoals( TEAM.AXIS, 1, {
			"BUILD_Gas_Control",
		});
		SetAvailableMapGoals( TEAM.AXIS, 0, {
			"SNIPE_DEFEND_.*",
			"BUILD_Tank_Barrier",
		});

		Util.MapDebugPrint( "Main_Gate_Open" );
	},

	Assault_Ramp_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "BUILD_Assault_Ramp" );
		SetAvailableMapGoals( TEAM.AXIS, 1, "PLANT_Assault_Ramp" );
		Util.MapDebugPrint( "Assault_Ramp_Built" );
	},
	Assault_Ramp_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "BUILD_Assault_Ramp" );
		Util.MapDebugPrint( "Assault_Ramp_Destroyed" );
	},

	Gas_Control_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, 0, "BUILD_Gas_Control" );
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Gas_Control" );
		SetAvailableMapGoals( TEAM.ALLIES, 0, "FLAG_zyklon" );
		Util.MapDebugPrint( "Gas_Control_Built" );
	},
	Gas_Control_Planted = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Gas_Control" );
		SetAvailableMapGoals( TEAM.AXIS, 0, "BUILD_Gas_Control" );
		Util.MapDebugPrint( "Gas_Control_Planted" );
	},
	Gas_Control_Defused = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Gas_Control" );
		Util.MapDebugPrint( "Gas_Control_Defused" );
	},
	Gas_Control_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, 1, "BUILD_Gas_Control" );
		SetAvailableMapGoals( TEAM.ALLIES, 1, "FLAG_zyklon" );
		Util.MapDebugPrint( "Gas_Control_Destroyed" );
	},

	execution_wall_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Invasion_Barrier" );

		Util.MapDebugPrint( "execution_wall_Destroyed" );
	},

	Invasion_Barrier_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Invasion_Barrier" );
		Util.MapDebugPrint( "Invasion_Barrier_Built" );
	},
	Invasion_Barrier_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Invasion_Barrier" );
		SetAvailableMapGoals( TEAM.ALLIES, 1, "FLAG_zyklon" );
		Util.MapDebugPrint( "Invasion_Barrier_Destroyed" );
	},

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

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

	Tank_Barrier_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Tank_Barrier" );
		Util.MapDebugPrint( "Tank_Barrier_Built" );
	},
	Tank_Barrier_Planted = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Tank_Barrier" );
		Util.MapDebugPrint( "Tank_Barrier_Planted" );
	},
	Tank_Barrier_Defused = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Tank_Barrier" );
		Util.MapDebugPrint( "Tank_Barrier_Defused" );
	},
	Tank_Barrier_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Tank_Barrier" );
		Util.MapDebugPrint( "Tank_Barrier_Destroyed" );
	},

	scaffolding_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "BUILD_scaffolding" );
		SetAvailableMapGoals( TEAM.AXIS, 1, "PLANT_scaffolding" );
		Util.MapDebugPrint( "scaffolding_Built" );
	},
	scaffolding_Destroyed = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "BUILD_scaffolding" );
		Util.MapDebugPrint( "scaffolding_Destroyed" );
	},

	// main gate key
	allied_gold_Taken = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "CAPPOINT_GateControls" );
		Util.MapDebugPrint( "allied_gold_Taken" );
	},
	allied_gold_Returned = function( trigger )
	{
		Util.MapDebugPrint( "allied_gold_Returned" );
	},

	zyklon_Taken = function( trigger )
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "CAPPOINT_zyklon" );
		Util.MapDebugPrint( "zyklon_Taken" );
	},
	zyklon_Returned = function( trigger )
	{
		Util.MapDebugPrint( "zyklon_Returned" );
	},
	zyklon_Secured = function( trigger )
	{
		Util.MapDebugPrint( "zyklon_Secured" );
	},

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


	// 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_Neutral_Command_Post" );
				SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Neutral_Command_Post" );
				SetAvailableMapGoals( TEAM.AXIS,   1, "BUILD_Neutral_Command_Post" );
				SetAvailableMapGoals( TEAM.AXIS,   0, "PLANT_Neutral_Command_Post" );
			}
			case TEAM.ALLIES:
			{
				Map.CP_Owner = TEAM.ALLIES;
				SetAvailableMapGoals( TEAM.ALLIES, 0, "BUILD_Neutral_Command_Post" );
				SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Neutral_Command_Post" );
				SetAvailableMapGoals( TEAM.AXIS,   1, "PLANT_Neutral_Command_Post" );
				SetAvailableMapGoals( TEAM.AXIS,   0, "BUILD_Neutral_Command_Post" );
			}
			case TEAM.AXIS:
			{
				Map.CP_Owner = TEAM.AXIS;
				SetAvailableMapGoals( TEAM.ALLIES, 0, "BUILD_Neutral_Command_Post" );
				if ( !Map.Garrison_Door_Intact )
				{
					SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Neutral_Command_Post" );
				}
				SetAvailableMapGoals( TEAM.AXIS,   0, "PLANT_Neutral_Command_Post" );
				SetAvailableMapGoals( TEAM.AXIS,   0, "BUILD_Neutral_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" );
	},

// Command Post END


};

global OnMapLoad = function()
{
	// Register callback functions
	OnTrigger( "^dThe tank has been repaired!", Map.Tank_Built );
	OnTrigger( "^1The tank has been damaged!", Map.Tank_Damaged );

	OnTrigger( "^dAllies ^3have built the Sola River Bridge!", Map.Sola_River_Bridge_Built );
	OnTrigger( "^1Axis ^3has destroyed the Sola River Bridge!", Map.Sola_River_Bridge_Destroyed );

	OnTrigger( "^dAllies ^3have destroyed the Garrison Door!", Map.Garrison_Door_Destroyed );
	//spawn forward: "^dAllies ^3have breached the Garrison!"

	OnTrigger( "^dAllies ^3have built the assault ramp!", Map.Assault_Ramp_Built );
	OnTrigger( "^1Axis ^3has damaged the assault ramp!", Map.Assault_Ramp_Destroyed );

	OnTrigger( "^1Axis ^3has repaired the gas control!", Map.Gas_Control_Built );
	OnTrigger( "Planted at the gas control.", Map.Gas_Control_Planted );
	OnTrigger( "Defused at the gas control.", Map.Gas_Control_Defused );
	OnTrigger( "MISSING_STRING", Map.Gas_Control_Destroyed );

	// *** Major Event: Phase 2
	OnTrigger( "^dAllied team ^3has opened the camp's main gate!", Map.Main_Gate_Open );

	OnTrigger( "^1Axis ^3has built the infantry barrier!", Map.Invasion_Barrier_Built );
	OnTrigger( "^dAllies ^3have destroyed the infantry barrier!", Map.Invasion_Barrier_Destroyed );

	OnTrigger( "^1The Tank Barrier has been constructed.", Map.Tank_Barrier_Built );
	OnTrigger( "^dThe Tank Barrier has been destroyed.", Map.Tank_Barrier_Destroyed );

	OnTrigger( "^dAllies ^3have built the scaffold!", Map.scaffolding_Built );
	OnTrigger( "^1Axis ^3has damaged the scaffold!", Map.scaffolding_Destroyed );

	OnTrigger( "^dAllies ^3have destroyed the execution wall!", Map.execution_wall_Destroyed );

	OnTrigger( "^dAllies ^3have taken the Main Gate key!", Map.allied_gold_Taken );
	OnTrigger( "^1Axis ^3has returned the Main Gate key!", Map.allied_gold_Returned );
	OnTrigger( "^dAllied team ^3has opened the camp's main gate!", Map.allied_gold_Secured );

	OnTrigger( "^dAllies ^3have taken the Artillery Shell!", Map.zyklon_Taken );
	OnTrigger( "^1Axis ^3have returned the Artillery Shell!", Map.zyklon_Returned );
	OnTrigger( "^dAllies ^3have delivered the Artillery Shell", Map.zyklon_Secured );

	OnTrigger( "^1Axis ^3have captured the Main Camp!", Map.superflag_Axis_Captured );
	OnTrigger( "^dAllies ^3have captured the Main Camp!", Map.superflag_Allies_Captured );

	OnTrigger( "^dAllied Command Post constructed. Charge speed increased!",  Map.Allied_CP_Built );
	OnTrigger( "^1Axis team has destroyed the Allied Command Post!",          Map.Allied_CP_Destroyed );
	OnTrigger( "^1Axis Command Post constructed. Charge speed increased!",    Map.Axis_CP_Built );
	OnTrigger( "^dAllied 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  );

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

	if ( !Map.Use_MG42 ) { Util.DisableGoal("MOUNTMG42_.*"); }

	Util.LimitToClass( "PLANT_scaffolding", 1, 5 );
	Util.LimitToClass( "PLANT_Assault_Ramp", 1, 5 );
	Util.LimitToClass( "PLANT_scaffolding", 1, 5 );
	Util.LimitToClass( "PLANT_Neutral_Command_Post", 0, 5 );


	Util.AddUsePoint( "PLANT_Invasion_Barrier", Vec3( 8787, 5752, 672 ) );

	//Allies
	SetAvailableMapGoals( TEAM.ALLIES, 1, {
		"ATTACK_.*",
		"BUILD_Tank",
		"BUILD_Sola_River_Bridge",
		"SNIPE_ATTACK_.*",
	});
	//SetGoalPriority( "BUILD_Tank", 0.95 );
	SetGoalPriority( "BUILD_Sola_River_Bridge", 0.95 );
	SetGoalPriority( "PLANT_Tank_Barrier", 0.96 );
	Util.ExcludeClass( "ATTACK_.*", 2, 3 );

	//Axis
	SetAvailableMapGoals( TEAM.AXIS, 1, {
		"BUILD_Tank_Barrier",
		"BUILD_Neutral_Command_Post",
		"DEFEND_.*",
		"SNIPE_DEFEND_.*",
	});
	SetGoalPriority( "BUILD_Tank_Barrier", 0.95 );
	Util.ExcludeClass( "DEFEND_.*", 1, 3 );

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

	// Camp times
	SetMapGoalProperties( "MOUNTMG42_.*", {MinCampTime=15, MaxCampTime=90} );
	SetMapGoalProperties( "SNIPE_.*", {MinCampTime=300, MaxCampTime=999} );
	SetGoalPriority( "SNIPE_.*", 0.95 );

	//unreachables
	Util.DisableGoal( {
		"MOUNTMG42_211",
		"MOUNTMG42_488",
		"MOUNTMG42_569",
		"MOUNTMG42_812",
	});

	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;

	team = bot.GetTeam();
	class = bot.GetClass();
	if ( class == CLASS.COVERTOPS )
	{
		if ( team == TEAM.ALLIES )
		{ bot.ChangePrimaryWeapon( WEAPON.GARAND_SCOPE ); }
		else if ( team == TEAM.AXIS )
		{ bot.ChangePrimaryWeapon( WEAPON.K43 ); }
	}
};

global InitializeRoutes = function()
{
	MapRoutes =
	{
		BUILD_Tank = {},
		BUILD_Tank_Barrier = {},
		PLANT_Tank_Barrier = {},
		BUILD_Neutral_Command_Post = {},
		PLANT_Neutral_Command_Post = {},
		BUILD_Sola_River_Bridge = {},
		PLANT_Sola_River_Bridge = {},
		BUILD_Assault_Ramp = {},
		PLANT_Assault_Ramp = {},
		PLANT_execution_wall = {},
		BUILD_Invasion_Barrier = {},
		PLANT_Invasion_Barrier = {},
		BUILD_Gas_Control = {},
		PLANT_Gas_Control = {},
		BUILD_scaffolding = {},
		PLANT_scaffolding = {},
		CHECKPOINT_superflag = {},

		FLAG_allied_gold = {}, // = main gate key
		CAPPOINT_GateControls = {}, // ...

		FLAG_zyklon = {},
		CAPPOINT_zyklon = {}, //wins the round

	};
	Util.Routes(MapRoutes);
};
