//==========================================================================================
//
//	secrets.gm
//
//	Who                  	When		What
//------------------------------------------------------------------------------------------
//	maker@bigsighstudios.com	04 December 2017	Initial Script
//
//==========================================================================================
//

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

	Allied_Front_Gate_Dyno = 0,
	Axis_Forward_Bunker_Dyno = 0,
	Forward_Gate_Dyno = 0,
	Radio_Tower_Raft_Dyno = 0,
	side_entrance_of_the_mine_Dyno = 0,
	Sneek_Ramp_Dyno = 0,
	Tower_Entrance_Dyno = 0,
	Tower_Gate_Dyno = 0,
	Underground_Defense_Dyno = 0,

	//Obj states 1 = intact/built
	Allied_Front_Gate = 1,
	Axis_Forward_Bunker = 0,
	Forward_Gate = 1,
	Radio_Tower_Raft = 0,
	side_entrance_of_the_mine = 1,
	Sneek_Ramp = 0,
	Tower_Entrance = 1,
	Tower_Gate = 0,
	Underground_Defense = 0,


	Axis_Forward_Bunker_Built = function( trigger )
	{
		Map.Axis_Forward_Bunker = 1;
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Axis_Forward_Bunker" );
		Util.MapDebugPrint( "Axis_Forward_Bunker_Built" );
	},
	Axis_Forward_Bunker_Planted = function( trigger )
	{
		Map.Axis_Forward_Bunker_Dyno += 1;

		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Axis_Forward_Bunker" );
		Util.MapDebugPrint( "Axis_Forward_Bunker_Planted" );
	},
	Axis_Forward_Bunker_Defused = function( trigger )
	{
		Map.Axis_Forward_Bunker_Dyno -= 1;
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Axis_Forward_Bunker" );
		Util.MapDebugPrint( "Axis_Forward_Bunker_Planted" );
	},
	Axis_Forward_Bunker_Destroyed = function( trigger )
	{
		Map.Axis_Forward_Bunker = 0;
		Map.Axis_Forward_Bunker_Dyno = 0;
		SetAvailableMapGoals( TEAM.AXIS, 1, "BUILD_Axis_Forward_Bunker" );
		Util.MapDebugPrint( "Axis_Forward_Bunker_Destroyed" );
	},

	Allied_Front_Gate_Planted = function( trigger )
	{
		Map.Allied_Front_Gate_Dyno += 1;
		SetAvailableMapGoals( TEAM.AXIS, 0, "PLANT_Allied_Front_Gate" );
		Util.MapDebugPrint( "Allied_Front_Gate_Planted" );
	},
	Allied_Front_Gate_Defused = function( trigger )
	{
		Map.Allied_Front_Gate_Dyno -= 1;
		SetAvailableMapGoals( TEAM.AXIS, 1, "PLANT_Allied_Front_Gate" );
		Util.MapDebugPrint( "Allied_Front_Gate_Defused" );
	},
	Allied_Front_Gate_Destroyed = function( trigger )
	{
		Map.Allied_Front_Gate = 0;
		Map.Allied_Front_Gate_Dyno = 0;
		Util.MapDebugPrint( "Allied_Front_Gate_Destroyed" );
	},

	Forward_Gate_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, 1, "PLANT_Forward_Gate" );
		Util.MapDebugPrint( "Forward_Gate_Built" );
	},
	Forward_Gate_Planted = function( trigger )
	{
		Map.Forward_Gate_Dyno += 1;
		SetAvailableMapGoals( TEAM.AXIS, 0, "PLANT_Forward_Gate" );
		Util.MapDebugPrint( "Forward_Gate_Planted" );
	},
	Forward_Gate_Defused = function( trigger )
	{
		Map.Forward_Gate_Dyno -= 1;
		SetAvailableMapGoals( TEAM.AXIS, 1, "PLANT_Forward_Gate" );
		Util.MapDebugPrint( "Forward_Gate_Defused" );
	},
	Forward_Gate_Destroyed = function( trigger )
	{
		Map.Forward_Gate = 0;
		Map.Forward_Gate_Dyno = 0;
		SetAvailableMapGoals( TEAM.ALLIES, 1, "BUILD_Forward_Gate" );
		Util.MapDebugPrint( "Forward_Gate_Destroyed" );
	},

	Radio_Tower_Raft_Built = function( trigger )
	{
		Map.Radio_Tower_Raft = 1;
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Radio_Tower_Raft" );
		Util.MapDebugPrint( "Radio_Tower_Raft_Built" );
	},
	Radio_Tower_Raft_Planted = function( trigger )
	{
		Map.Radio_Tower_Raft_Dyno += 1;
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Radio_Tower_Raft" );
		Util.MapDebugPrint( "Radio_Tower_Raft_Planted" );
	},
	Radio_Tower_Raft_Defused = function( trigger )
	{
		Map.Radio_Tower_Raft_Dyno -= 1;
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Radio_Tower_Raft" );
		Util.MapDebugPrint( "Radio_Tower_Raft_Defused" );
	},
	Radio_Tower_Raft_Destroyed = function( trigger )
	{
		Map.Radio_Tower_Raft = 0;
		Map.Radio_Tower_Raft_Dyno = 0;
		SetAvailableMapGoals( TEAM.AXIS, 1, "BUILD_Radio_Tower_Raft" );
		Util.MapDebugPrint( "Radio_Tower_Raft_Destroyed" );
	},

	//Sneek Ramp is required for end game
	Sneek_Ramp_Built = function( trigger )
	{
		Map.Sneek_Ramp = 1;
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Sneek_Ramp" );
		SetAvailableMapGoals( TEAM.AXIS, 0, "BUILD_Sneek_Ramp" );
		SetAvailableMapGoals( TEAM.AXIS, 1, "BUILD_Radio_Tower_Raft" );
		Util.MapDebugPrint( "Sneek_Ramp_Built" );
	},
	Sneek_Ramp_Planted = function( trigger )
	{
		Map.Sneek_Ramp_Dyno += 1;
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Sneek_Ramp" );
		Util.MapDebugPrint( "Sneek_Ramp_Planted" );
	},
	Sneek_Ramp_Defused = function( trigger )
	{
		Map.Sneek_Ramp_Dyno -= 1;
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Sneek_Ramp" );
		Util.MapDebugPrint( "Sneek_Ramp_Defused" );
	},
	Sneek_Ramp_Destroyed = function( trigger )
	{
		Map.Sneek_Ramp = 0;
		Map.Sneek_Ramp_Dyno = 0;
		SetAvailableMapGoals( TEAM.AXIS, 1, "BUILD_Sneek_Ramp" );
		Util.MapDebugPrint( "Sneek_Ramp_Destroyed" );
	},

	//Axis access door to Allies tower. Not rebuildable.
	Tower_Entrance_Planted = function( trigger )
	{
		Map.Tower_Entrance_Dyno += 1;
		SetAvailableMapGoals( TEAM.AXIS, 0, "PLANT_Tower_Entrance" );
		Util.MapDebugPrint( "Tower_Entrance_Planted" );
	},
	Tower_Entrance_Defused = function( trigger )
	{
		Map.Tower_Entrance_Dyno -= 1;
		SetAvailableMapGoals( TEAM.AXIS, 1, "PLANT_Tower_Entrance" );
		Util.MapDebugPrint( "Tower_Entrance_Defused" );
	},
	Tower_Entrance_Destroyed = function( trigger )
	{
		Map.Tower_Entrance = 0;
		Map.Tower_Entrance_Dyno = 0;
		SetAvailableMapGoals( TEAM.AXIS, 1, "FLAG_documents" );
		Util.MapDebugPrint( "Tower_Entrance_Destroyed" );
	},

	Tower_Gate_Built = function( trigger )
	{
		Map.Tower_Gate = 1;
		SetAvailableMapGoals( TEAM.AXIS, 1, "PLANT_Tower_Gate" );
		Util.MapDebugPrint( "Tower_Gate_Built" );
	},
	Tower_Gate_Planted = function( trigger )
	{
		Map.Tower_Gate_Dyno += 1;
		SetAvailableMapGoals( TEAM.AXIS, 0, "PLANT_Tower_Gate" );
		Util.MapDebugPrint( "Tower_Gate_Planted" );
	},
	Tower_Gate_Defused = function( trigger )
	{
		Map.Tower_Gate_Dyno -= 1;
		SetAvailableMapGoals( TEAM.AXIS, 1, "PLANT_Tower_Gate" );
		Util.MapDebugPrint( "Tower_Gate_Defused" );
	},
	Tower_Gate_Destroyed = function( trigger )
	{
		Map.Tower_Gate = 0;
		Map.Tower_Gate_Dyno = 0;
		SetAvailableMapGoals( TEAM.ALLIES, 1, "BUILD_Tower_Gate" );
		Util.MapDebugPrint( "Tower_Gate_Destroyed" );
	},

	Underground_Defense_Built = function( trigger )
	{
		Map.Underground_Defense = 1;
		SetAvailableMapGoals( TEAM.AXIS, 1, "PLANT_Underground_Defense" );
		Util.MapDebugPrint( "Underground_Defense_Built" );
	},
	Underground_Defense_Planted = function( trigger )
	{
		Map.Underground_Defense_Dyno += 1;
		SetAvailableMapGoals( TEAM.AXIS, 0, "PLANT_Underground_Defense" );
		Util.MapDebugPrint( "Underground_Defense_Planted" );
	},
	Underground_Defense_Defused = function( trigger )
	{
		Map.Underground_Defense_Dyno -= 1;
		SetAvailableMapGoals( TEAM.AXIS, 1, "PLANT_Underground_Defense" );
		Util.MapDebugPrint( "Underground_Defense_Defused" );
	},
	Underground_Defense_Destroyed = function( trigger )
	{
		Map.Underground_Defense = 0;
		Map.Underground_Defense_Dyno = 0;
		Util.MapDebugPrint( "Underground_Defense_Destroyed" );
	},

	side_entrance_of_the_mine_Planted = function( trigger )
	{
		Map.side_entrance_of_the_mine_Dyno += 1;
		SetAvailableMapGoals( TEAM.AXIS, 0, "PLANT_side_entrance_of_the_mine" );
		Util.MapDebugPrint( "side_entrance_of_the_mine_Planted" );
	},
	side_entrance_of_the_mine_Defused = function( trigger )
	{
		Map.side_entrance_of_the_mine_Dyno -= 1;
		SetAvailableMapGoals( TEAM.AXIS, 1, "PLANT_side_entrance_of_the_mine" );
		Util.MapDebugPrint( "side_entrance_of_the_mine_Defused" );
	},
	side_entrance_of_the_mine_Destroyed = function( trigger )
	{
		Map.side_entrance_of_the_mine = 0;
		Map.side_entrance_of_the_mine_Dyno = 0;
		SetAvailableMapGoals( TEAM.ALLIES, 1, "BUILD_side_entrance_of_the_mine" );
		SetAvailableMapGoals( TEAM.AXIS, 0, "PLANT_side_entrance_of_the_mine" );
		Util.MapDebugPrint( "side_entrance_of_the_mine_Destroyed" );
	},

	Set_Rope = function ( _p )
	{
		if ( _p == "Main" )
		{
			Wp.SetWaypointFlag("Rope_Main_Top", "closed", 0);
			Wp.SetWaypointFlag("Rope_Main_Bottom", "closed", 0);
			Wp.SetWaypointFlag("Rope_Aux_Top", "closed", 1);
			Wp.SetWaypointFlag("Rope_Aux_Bottom", "closed", 1);
			Util.MapDebugPrint( "Main Rope opened" );
		}
		else if ( _p == "Aux" )
		{
			Wp.SetWaypointFlag("Rope_Main_Top", "closed", 1);
			Wp.SetWaypointFlag("Rope_Main_Bottom", "closed", 1);
			Wp.SetWaypointFlag("Rope_Aux_Top", "closed", 0);
			Wp.SetWaypointFlag("Rope_Aux_Bottom", "closed", 0);
			Util.MapDebugPrint( "Aux Rope opened" );
		}
	},

	//Main obj needs wp paths opened/closed
	documents_Taken = function( trigger )
	{
		Map.Set_Rope( "Main" );
		SetAvailableMapGoals( TEAM.AXIS, 1, "BUILD_Sneek_Ramp" );
		Util.MapDebugPrint( "documents_Taken" );
	},
	documents_Returned = function( trigger )
	{
		Map.Set_Rope( "Aux" );
		Util.MapDebugPrint( "documents_Returned" );
	},
	documents_Secured = function( trigger )
	{
		//endgame
		Util.MapDebugPrint( "documents_Secured" );
	},

	forward_spawn_Axis_Captured = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, 1, "PLANT_Tower_Entrance" );
		Util.MapDebugPrint( "forward_spawn_Axis_Captured" );
	},

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

};

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

	OnTrigger( "Planted at the Allied Front Gate.", Map.Allied_Front_Gate_Planted );
	OnTrigger( "Defused at the Allied Front Gate.", Map.Allied_Front_Gate_Defused );
	OnTrigger( "Axis have blown up the Allied Front Gate", Map.Allied_Front_Gate_Destroyed );

	OnTrigger( "Axis team has built a Forward Bunker!", Map.Axis_Forward_Bunker_Built );
	OnTrigger( "Planted at the Axis Forward Bunker.", Map.Axis_Forward_Bunker_Planted );
	OnTrigger( "Allied team has destroyed the Axis Forward Bunker!", Map.Axis_Forward_Bunker_Destroyed );

	OnTrigger( "Allied team has built the Forward Gate!", Map.Forward_Gate_Built );
	OnTrigger( "Planted at the Forward Gate.", Map.Forward_Gate_Planted );
	OnTrigger( "Defused at the Forward Gate.", Map.Forward_Gate_Defused );
	OnTrigger( "Axis team has destroyed the Forward Gate!", Map.Forward_Gate_Destroyed );

	OnTrigger( "Axis team has built the Radio Tower Ramp!", Map.Radio_Tower_Raft_Built );
	OnTrigger( "Allied team has destroyed the Radio Tower Ramp!", Map.Radio_Tower_Raft_Destroyed );

	OnTrigger( "Axis team has built the Sneek Ramp!", Map.Sneek_Ramp_Built );
	OnTrigger( "Planted at the Sneek Ramp.", Map.Sneek_Ramp_Planted );
	OnTrigger( "Allied team has destroyed the Sneek Ramp!", Map.Sneek_Ramp_Destroyed );

	OnTrigger( "Allied team has built the Tower Security Gate!", Map.Tower_Gate_Built );
	OnTrigger( "Planted at the Tower Gate.", Map.Tower_Gate_Planted );
	OnTrigger( "Axis team has destroyed the Tower Security Gate!", Map.Tower_Gate_Destroyed );

	OnTrigger( "Allied team has built an Underground Defense!", Map.Underground_Defense_Built );
	OnTrigger( "Planted at the Underground Defense.", Map.Underground_Defense_Planted );
	OnTrigger( "Defused at the Underground Defense.", Map.Underground_Defense_Defused );
	OnTrigger( "Axis team has destroyed the Allies Underground Defense!", Map.Underground_Defense_Destroyed );

	OnTrigger( "Planted at Tower Entrance.", Map.Tower_Entrance_Planted );
	OnTrigger( "Defused at Tower Entrance.", Map.Tower_Entrance_Defused );
	OnTrigger( "Axis have destroyed the Tower Door!", Map.Tower_Entrance_Destroyed );

	OnTrigger( "Planted at the side mine gate.", Map.side_entrance_of_the_mine_Planted );
	OnTrigger( "Defused at the side mine gate.", Map.side_entrance_of_the_mine_Defused );
	OnTrigger( "Axis have blown up the side mine gate", Map.side_entrance_of_the_mine_Destroyed );

	OnTrigger( "Axis have stolen the precious documents!!", Map.documents_Taken );
	OnTrigger( "MISSING_STRING", Map.documents_Returned );
	OnTrigger( "Axis have transmitted the precious documents at the Radio Room!", Map.documents_Secured );

	OnTrigger( "Axis capture the forward bunker!", Map.forward_spawn_Axis_Captured );
	OnTrigger( "Allies capture the forward bunker!", Map.forward_spawn_Allies_Captured );

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

	//Allies
	SetAvailableMapGoals( TEAM.ALLIES, 1, "DEFEND_.*" );
	SetAvailableMapGoals( TEAM.ALLIES, 1, "BUILD_Tower_Gate" );
	SetAvailableMapGoals( TEAM.ALLIES, 1, "BUILD_Underground_Defense" );
	SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANTMINE_.*" );

	//Axis
	SetAvailableMapGoals( TEAM.AXIS, 1, "ATTACK_.*" );
	SetAvailableMapGoals( TEAM.AXIS, 1, "CHECKPOINT_.*" );
	// wait until docs taken === SetAvailableMapGoals( TEAM.AXIS, 1, "BUILD_Sneek_Ramp" );

	//wrong gate, should be Allied_Front Gate   ~-Util.AddUsePoint( "PLANT_Forward_Gate", Vec3( 5045, -942, -3347 ) );


	//test
	//Util.LimitToClass( "BUILD_.*", 0, CLASS.ENGINEER );
	//Util.LimitToClass( "PLANT_.*", 0, CLASS.ENGINEER );

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

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

	//Pathing
	Wp.SetWaypointFlag("Rope_Main_Top", "closed", 1);
	Wp.SetWaypointFlag("Rope_Main_Bottom", "closed", 1);
	Wp.SetWaypointFlag("Rope_Aux_Top", "closed", 0);
	Wp.SetWaypointFlag("Rope_Aux_Bottom", "closed", 0);


	Util.MapDebugPrint( "Omni-bot map script for " + GetMapName() + " by maker@bigsighstudios.com." );
};

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;

  foreach ( id and weap in
  {
    WEAPON.THOMPSON, WEAPON.MP40, WEAPON.SHOTGUN,
    WEAPON.STEN, WEAPON.MP34, WEAPON.M97, WEAPON.M7,
    WEAPON.STG44, WEAPON.FG42, WEAPON.GARAND,
    WEAPON.K43, WEAPON.BAR
  } )
  {
		bot.GetWeapon( weap ).PrimaryFire.SetTargetBias( CLASS.BREAKABLE, 1.2 );
  }
  bot.GetWeapon( WEAPON.KNIFE ).PrimaryFire.SetDesirabilityRange( 0, 48, 0.6 );
};

global InitializeRoutes = function()
{
	MapRoutes =
	{
		FLAG_documents =
		{
		},
		PLANT_Allied_Front_Gate =
		{
		},
		PLANT_side_entrance_of_the_mine =
		{
		},
		BUILD_Tower_Gate =
		{
		},
		PLANT_Tower_Gate =
		{
		},
		BUILD_Underground_Defense =
		{
		},
		PLANT_Underground_Defense =
		{
		},
		BUILD_Forward_Gate =
		{
		},
		PLANT_Forward_Gate =
		{
		},
		CHECKPOINT_forward_spawn =
		{
		},
		BUILD_Axis_Forward_Bunker =
		{
		},
		PLANT_Axis_Forward_Bunker =
		{
		},
		BUILD_Sneek_Ramp =
		{
		},
		PLANT_Sneek_Ramp =
		{
		},
		BUILD_Radio_Tower_Raft =
		{
		},
		PLANT_Radio_Tower_Raft =
		{
		},
		PLANT_Tower_Entrance =
		{
		},
	};
	Util.Routes(MapRoutes);
};
