//==========================================================================================
//
//	nemo.gm
//
//	Who                  	When		What
//------------------------------------------------------------------------------------------
//	maker@bigsighstudios.com	05 November 2017	Initial Script
//
//==========================================================================================
//

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

	Allied_Construction_Dyno = 0,
	Arhive_Barricade_Dyno = 0,
	Axis_Checkpoint_Dyno = 0,
	Axis_Harbor_Barricade_Dyno = 0,
	Command_Post_Dyno = 0,
	Sewer_Entreance_Dyno = 0,
	Window_Grate_Dyno = 0,

	Allied_Construction_Built = function( trigger )
	{
		if ( TestMap ) 	{ return; }

		Util.MapDebugPrint( "Allied_Construction_Built" );
	},
	Allied_Construction_Planted = function( trigger )
	{
		if ( TestMap ) 	{ return; }

		Map.Allied_Construction_Dyno += 1;
		Util.MapDebugPrint( "Allied_Construction_Planted" );
	},
	Allied_Construction_Defused = function( trigger )
	{
		if ( TestMap ) 	{ return; }

		Map.Allied_Construction_Dyno -= 1;
		Util.MapDebugPrint( "Allied_Construction_Defused" );
	},
	Allied_Construction_Destroyed = function( trigger )
	{
		if ( TestMap ) 	{ return; }

		Map.Allied_Construction_Dyno = 0;

		Util.MapDebugPrint( "Allied_Construction_Destroyed" );
	},

	Arhive_Barricade_Built = function( trigger )
	{
		if ( TestMap ) 	{ return; }

		Util.MapDebugPrint( "Arhive_Barricade_Built" );
	},
	Arhive_Barricade_Planted = function( trigger )
	{
		if ( TestMap ) 	{ return; }

		Map.Arhive_Barricade_Dyno += 1;
		Util.MapDebugPrint( "Arhive_Barricade_Planted" );
	},
	Arhive_Barricade_Defused = function( trigger )
	{
		if ( TestMap ) 	{ return; }

		Map.Arhive_Barricade_Dyno -= 1;
		Util.MapDebugPrint( "Arhive_Barricade_Defused" );
	},
	Arhive_Barricade_Destroyed = function( trigger )
	{
		if ( TestMap ) 	{ return; }

		Map.Arhive_Barricade_Dyno = 0;

		Util.MapDebugPrint( "Arhive_Barricade_Destroyed" );
	},

	Axis_Checkpoint_Built = function( trigger )
	{
		if ( TestMap ) 	{ return; }

		Util.MapDebugPrint( "Axis_Checkpoint_Built" );
	},
	Axis_Checkpoint_Planted = function( trigger )
	{
		if ( TestMap ) 	{ return; }

		Map.Axis_Checkpoint_Dyno += 1;
		Util.MapDebugPrint( "Axis_Checkpoint_Planted" );
	},
	Axis_Checkpoint_Defused = function( trigger )
	{
		if ( TestMap ) 	{ return; }

		Map.Axis_Checkpoint_Dyno -= 1;
		Util.MapDebugPrint( "Axis_Checkpoint_Defused" );
	},
	Axis_Checkpoint_Destroyed = function( trigger )
	{
		if ( TestMap ) 	{ return; }

		Map.Axis_Checkpoint_Dyno = 0;

		Util.MapDebugPrint( "Axis_Checkpoint_Destroyed" );
	},

	Axis_Harbor_Barricade_Built = function( trigger )
	{
		if ( TestMap ) 	{ return; }

		Util.MapDebugPrint( "Axis_Harbor_Barricade_Built" );
	},
	Axis_Harbor_Barricade_Planted = function( trigger )
	{
		if ( TestMap ) 	{ return; }

		Map.Axis_Harbor_Barricade_Dyno += 1;
		Util.MapDebugPrint( "Axis_Harbor_Barricade_Planted" );
	},
	Axis_Harbor_Barricade_Defused = function( trigger )
	{
		if ( TestMap ) 	{ return; }

		Map.Axis_Harbor_Barricade_Dyno -= 1;
		Util.MapDebugPrint( "Axis_Harbor_Barricade_Defused" );
	},
	Axis_Harbor_Barricade_Destroyed = function( trigger )
	{
		if ( TestMap ) 	{ return; }

		Map.Axis_Harbor_Barricade_Dyno = 0;

		Util.MapDebugPrint( "Axis_Harbor_Barricade_Destroyed" );
	},

	Command_Post_Built = function( trigger )
	{
		if ( TestMap ) 	{ return; }

		Util.MapDebugPrint( "Command_Post_Built" );
	},
	Command_Post_Planted = function( trigger )
	{
		if ( TestMap ) 	{ return; }

		Map.Command_Post_Dyno += 1;
		Util.MapDebugPrint( "Command_Post_Planted" );
	},
	Command_Post_Defused = function( trigger )
	{
		if ( TestMap ) 	{ return; }

		Map.Command_Post_Dyno -= 1;
		Util.MapDebugPrint( "Command_Post_Defused" );
	},
	Command_Post_Destroyed = function( trigger )
	{
		if ( TestMap ) 	{ return; }

		Map.Command_Post_Dyno = 0;

		Util.MapDebugPrint( "Command_Post_Destroyed" );
	},

	Window_Grate_Built = function( trigger )
	{
		if ( TestMap ) 	{ return; }

		Util.MapDebugPrint( "Window_Grate_Built" );
	},
	Window_Grate_Planted = function( trigger )
	{
		if ( TestMap ) 	{ return; }

		Map.Window_Grate_Dyno += 1;
		Util.MapDebugPrint( "Window_Grate_Planted" );
	},
	Window_Grate_Defused = function( trigger )
	{
		if ( TestMap ) 	{ return; }

		Map.Window_Grate_Dyno -= 1;
		Util.MapDebugPrint( "Window_Grate_Defused" );
	},
	Window_Grate_Destroyed = function( trigger )
	{
		if ( TestMap ) 	{ return; }

		Map.Window_Grate_Dyno = 0;

		Util.MapDebugPrint( "Window_Grate_Destroyed" );
	},


	Sewer_Entreance_Planted = function( trigger )
	{
		if ( TestMap ) 	{ return; }

		Map.Sewer_Entreance_Dyno += 1;
		Util.MapDebugPrint( "Sewer_Entreance_Planted" );
	},
	Sewer_Entreance_Defused = function( trigger )
	{
		if ( TestMap ) 	{ return; }

		Map.Sewer_Entreance_Dyno -= 1;
		Util.MapDebugPrint( "Sewer_Entreance_Defused" );
	},
	Sewer_Entreance_Destroyed = function( trigger )
	{
		if ( TestMap ) 	{ return; }

		Map.Sewer_Entreance_Dyno = 0;

		Util.MapDebugPrint( "Sewer_Entreance_Destroyed" );
	},


	flag3_Axis_Captured = function( trigger )
	{
		if ( TestMap ) 	{ return; }

		Util.MapDebugPrint( "flag3_Axis_Captured" );
	},

	flag3_Allies_Captured = function( trigger )
	{
		if ( TestMap ) 	{ return; }

		Util.MapDebugPrint( "flag3_Allies_Captured" );
	},

	flag4_Axis_Captured = function( trigger )
	{
		if ( TestMap ) 	{ return; }

		Util.MapDebugPrint( "flag4_Axis_Captured" );
	},

	flag4_Allies_Captured = function( trigger )
	{
		if ( TestMap ) 	{ return; }

		Util.MapDebugPrint( "flag4_Allies_Captured" );
	},

	flag5_Axis_Captured = function( trigger )
	{
		if ( TestMap ) 	{ return; }

		Util.MapDebugPrint( "flag5_Axis_Captured" );
	},

	flag5_Allies_Captured = function( trigger )
	{
		if ( TestMap ) 	{ return; }

		Util.MapDebugPrint( "flag5_Allies_Captured" );
	},

	Tr_Axis_Spawn_Barrier = 
	{
		Name = "Tr_Axis_Spawn_Barrier",
		TriggerOnClass = CLASS.ANYPLAYER,
		OnEnter = function(ent)
		{
			SetAvailableMapGoals( TEAM.AXIS, false, "GRENADE_.*" );
		},
	},
		
};

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

	// Register callback functions
	OnTriggerRegion(AABB(1495.413,7737.093,179.125,1685.353,7968.659,253.125), Map.Tr_Axis_Spawn_Barrier );

	OnTrigger( "MISSING_STRING", Map.Allied_Construction_Built );
	OnTrigger( "Planted at the MISSING_STRING.", Map.Allied_Construction_Planted );
	OnTrigger( "Defused at the MISSING_STRING.", Map.Allied_Construction_Defused );
	OnTrigger( "MISSING_STRING", Map.Allied_Construction_Destroyed );

	OnTrigger( "MISSING_STRING", Map.Arhive_Barricade_Built );
	OnTrigger( "Planted at the MISSING_STRING.", Map.Arhive_Barricade_Planted );
	OnTrigger( "Defused at the MISSING_STRING.", Map.Arhive_Barricade_Defused );
	OnTrigger( "MISSING_STRING", Map.Arhive_Barricade_Destroyed );

	OnTrigger( "The Axis have built the Checkpoint!", Map.Axis_Checkpoint_Built );
	OnTrigger( "Planted at Axis Checkpoint.", Map.Axis_Checkpoint_Planted );
	OnTrigger( "Defused at Axis Checkpoint.", Map.Axis_Checkpoint_Defused );
	OnTrigger( "The Allies have destroyed the checkpoint!", Map.Axis_Checkpoint_Destroyed );

	OnTrigger( "MISSING_STRING", Map.Axis_Harbor_Barricade_Built );
	OnTrigger( "Planted at the MISSING_STRING.", Map.Axis_Harbor_Barricade_Planted );
	OnTrigger( "Defused at the MISSING_STRING.", Map.Axis_Harbor_Barricade_Defused );
	OnTrigger( "MISSING_STRING", Map.Axis_Harbor_Barricade_Destroyed );

	OnTrigger( "MISSING_STRING", Map.Command_Post_Built );
	OnTrigger( "Planted at the MISSING_STRING.", Map.Command_Post_Planted );
	OnTrigger( "Defused at the MISSING_STRING.", Map.Command_Post_Defused );
	OnTrigger( "MISSING_STRING", Map.Command_Post_Destroyed );

	OnTrigger( "MISSING_STRING", Map.Window_Grate_Built );
	OnTrigger( "Planted at the MISSING_STRING.", Map.Window_Grate_Planted );
	OnTrigger( "Defused at the MISSING_STRING.", Map.Window_Grate_Defused );
	OnTrigger( "MISSING_STRING", Map.Window_Grate_Destroyed );

	OnTrigger( "Planted at the MISSING_STRING.", Map.Sewer_Entreance_Planted );
	OnTrigger( "Defused at the MISSING_STRING.", Map.Sewer_Entreance_Defused );
	OnTrigger( "MISSING_STRING", Map.Sewer_Entreance_Destroyed );

	OnTrigger( "MISSING_STRING", Map.flag3_Axis_Captured );
	OnTrigger( "MISSING_STRING", Map.flag3_Allies_Captured );
	OnTrigger( "MISSING_STRING", Map.flag4_Axis_Captured );
	OnTrigger( "MISSING_STRING", Map.flag4_Allies_Captured );
	OnTrigger( "MISSING_STRING", Map.flag5_Axis_Captured );
	OnTrigger( "MISSING_STRING", Map.flag5_Allies_Captured );

	//Util.DisableGoal( ".*", true ); // all but routes
	
	//~SetAvailableMapGoals( TEAM.AXIS, true, "ATTACK_.*" );
	//~SetAvailableMapGoals( TEAM.ALLIES, true, "ATTACK_.*" );

	SetAvailableMapGoals( TEAM.AXIS, true, "GRENADE_.*" );
	SetGoalPriority("GRENADE_.*", 1.2);

	//PLANT_Window_Grate
	Util.AddUsePoint( "PLANT_Window_Grate", Vec3( 4969, 6270, 208 ) );
	
	//STILL NOT WORKING (UNDERWATER) PLANT_Sewer_Entreance (sic)
	Util.AddUsePoint( "PLANT_Sewer_Entreance", Vec3( 6655, 6150, 120 ) );
	//Util.AddUsePoint( "PLANT_Allied_Construction", Vec3( 4590, 5958, 188 ) );
	Util.AddUsePoint( "PLANT_Axis_Checkpoint", Vec3( 4086, 7592, 184 ) );

	// Max users per goal
	Util.SetMaxUsers( 1, "ATTACK_.*" );
	Util.SetMaxUsers( 1, "DEFEND_.*" );
	Util.SetMaxUsers( 10, "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_.*" );

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


	Util.MapDebugPrint( "Omni-bot map script for " + GetMapName() + " executed." );
};

global OnBotJoin = function( bot )
{
	bot.TargetBreakableDist = 180.0;

	weaps = { WEAPON.THOMPSON, WEAPON.MP40, WEAPON.SHOTGUN, WEAPON.M97, WEAPON.M7, WEAPON.GARAND, WEAPON.K43, WEAPON.BAR, WEAPON.STEN, WEAPON.MP34, WEAPON.BAR, WEAPON.STG44, WEAPON.FG42, WEAPON.FLAMETHROWER, WEAPON.PANZERFAUST };

	foreach( id and weap in weaps )
	{
		w = bot.GetWeapon(weap);
		w.PrimaryFire.SetTargetBias(CLASS.BREAKABLE, 1.2);
	}

	// crapshoot: lower priority of knife at close range so they keep shooting breakables with primary
	w = bot.GetWeapon(WEAPON.KNIFE);
	w.PrimaryFire.SetDesirabilityRange(0, 48, 0.6);
};

global InitializeRoutes = function()
{
	MapRoutes =
	{
		CHECKPOINT_flag3 =
		{
		},
		CHECKPOINT_flag4 =
		{
		},
		BUILD_Command_Post =
		{
		},
		PLANT_Command_Post =
		{
		},
		BUILD_Allied_Construction =
		{
		},
		PLANT_Allied_Construction =
		{
		},
		CHECKPOINT_flag5 =
		{
		},
		BUILD_Axis_Harbor_Barricade =
		{
		},
		PLANT_Axis_Harbor_Barricade =
		{
		},
		BUILD_Arhive_Barricade =
		{
		},
		PLANT_Arhive_Barricade =
		{
		},
		BUILD_Axis_Checkpoint =
		{
		},
		PLANT_Axis_Checkpoint =
		{
		},
		BUILD_Window_Grate =
		{
		},
		PLANT_Window_Grate =
		{
		},
		PLANT_Sewer_Entreance =
		{
		},
	};
	Util.Routes(MapRoutes);
};
