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

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

	Roof_Gun_Dyno = 0,
	Roof_Gun_Active = true,
	CP_Dyno = 0,
	CP_Owner = 0, //TEAM.ALLIES || TEAM.AXIS
	Garden_Gun_Dyno = 0,
	Garden_Gun_Active = true,
	Side_Warehouse_Entrance_Dyno = 0,
	Villa_Gate_Dyno = 0,
	Villa_Gate_Active = true,
	Villa_Ladder_Dyno = 0,

	Allied_CP_Built = function( trigger )
	{ if ( TestMap ) { return; }
		CP_Owner = TEAM.ALLIES;
		SetAvailableMapGoals( TEAM.ALLIES, false, "BUILD_Command_Post" );
		Util.MapDebugPrint( "Allied_CP_Built" );
	},
	Axis_CP_Built = function( trigger )
	{ if ( TestMap ) { return; }
		CP_Owner = TEAM.AXIS;
		SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Command_Post" );
		Util.MapDebugPrint( "Axis_CP_Built" );
	},
	CP_Planted = function( trigger )
	{ if ( TestMap ) { return; }
		Map.CP_Dyno += 1;
		Util.MapDebugPrint( "CP_Planted" );
	},
	CP_Defused = function( trigger )
	{ if ( TestMap ) { return; }
		Map.CP_Dyno -= 1;
		Util.MapDebugPrint( "Axis_CP_Defused" );
	},
	Allied_CP_Destroyed = function( trigger )
	{ if ( TestMap ) { return; }
		Map.CP_Dyno = 0;
		CP_Owner = 0;
		SetAvailableMapGoals( TEAM.AXIS, true, "BUILD_Command_Post" );
		Util.MapDebugPrint( "Allied_CP_Destroyed" );
	},
	Axis_CP_Destroyed = function( trigger )
	{ if ( TestMap ) { return; }
		Map.CP_Dyno = 0;
		CP_Owner = 0;
		SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_Command_Post" );
		Util.MapDebugPrint( "Axis_CP_Destroyed" );
	},


	Villa_Gate_Built = function( trigger )
	{ if ( TestMap ) { return; }
		Map.Villa_Gate_Active = true;
		if ( Map.Garden_Gun_Active == true ) {
			SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Villa_Gate" );
		}
		Util.MapDebugPrint( "Villa_Gate_Built" );
	},
	Villa_Gate_Planted = function( trigger )
	{ if ( TestMap ) { return; }
		Map.Villa_Gate_Dyno += 1;
		Util.MapDebugPrint( "Villa_Gate_Planted" );
	},
	Villa_Gate_Defused = function( trigger )
	{ if ( TestMap ) { return; }
		Map.Villa_Gate_Dyno -= 1;
		Util.MapDebugPrint( "Villa_Gate_Defused" );
	},
	Villa_Gate_Destroyed = function( trigger )
	{ if ( TestMap ) { return; }
		Map.Villa_Gate_Dyno = 0;
		Map.Villa_Gate_Active = false;
		SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Anti_Aircraft_Roof_Gun" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "PLANT_Villa_Gate" );
		if ( Map.Garden_Gun_Active == false ) {
			//allow engy to focus on roof gun
			SetAvailableMapGoals( TEAM.AXIS, true, "DEFEND_Axis_Gun_2" );
			SetAvailableMapGoals( TEAM.AXIS, false, "BUILD_Villa_Gate" );
		}
		Util.MapDebugPrint( "Villa_Gate_Destroyed" );
	},

	Villa_Ladder_Built = function( trigger )
	{ if ( TestMap ) { return; }
		SetAvailableMapGoals( TEAM.ALLIES, false, "BUILD_Villa_Ladder" );
		SetAvailableMapGoals( TEAM.AXIS, true, "PLANT_Villa_Ladder" );
		Util.MapDebugPrint( "Villa_Ladder_Built" );
	},
	Villa_Ladder_Planted = function( trigger )
	{ if ( TestMap ) { return; }
		Map.Villa_Ladder_Dyno += 1;
		Util.MapDebugPrint( "Villa_Ladder_Planted" );
	},
	Villa_Ladder_Defused = function( trigger )
	{ if ( TestMap ) { return; }
		Map.Villa_Ladder_Dyno -= 1;
		Util.MapDebugPrint( "Villa_Ladder_Defused" );
	},
	Villa_Ladder_Destroyed = function( trigger )
	{ if ( TestMap ) { return; }
		Map.Villa_Ladder_Dyno = 0;
		SetAvailableMapGoals( TEAM.ALLIES, true, "BUILD_Villa_Ladder" );
		SetAvailableMapGoals( TEAM.AXIS, false, "PLANT_Villa_Ladder" );
		Util.MapDebugPrint( "Villa_Ladder_Destroyed" );
	},


	Garden_Gun_Planted = function( trigger )
	{ if ( TestMap ) { return; }
		Map.Garden_Gun_Dyno += 1;
		Util.MapDebugPrint( "Garden_Gun_Planted" );
	},
	Garden_Gun_Defused = function( trigger )
	{ if ( TestMap ) { return; }
		Map.Garden_Gun_Dyno -= 1;
		Util.MapDebugPrint( "Garden_Gun_Defused" );
	},
	Garden_Gun_Destroyed = function( trigger )
	{ if ( TestMap ) { return; }
		Map.Garden_Gun_Dyno = 0;
		Map.Garden_Gun_Active = false;
		SetAvailableMapGoals( TEAM.ALLIES, false, "PLANT_Garden_Anti_Aircraft_Gun" );
		SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Anti_Aircraft_Roof_Gun" );
		Util.DisableGroup( "Axis_Garden", TEAM.AXIS );
		Util.EnableGroup( "Axis_Roof", TEAM.AXIS );
		Util.MapDebugPrint( "Garden_Gun_Destroyed" );
	},


	Roof_Gun_Planted = function( trigger )
	{ if ( TestMap ) { return; }
		Map.Roof_Gun_Dyno += 1;
		Util.MapDebugPrint( "Roof_Gun_Planted" );
	},
	Roof_Gun_Defused = function( trigger )
	{ if ( TestMap ) { return; }
		Map.Roof_Gun_Dyno -= 1;
		Util.MapDebugPrint( "Roof_Gun_Defused" );
	},
	Roof_Gun_Destroyed = function( trigger )
	{ if ( TestMap ) { return; }
		Map.Roof_Gun_Dyno = 0;
		Map.Roof_Gun_Active = false;
		Util.DisableGroup( "Axis_Roof", TEAM.AXIS );
		if ( Map.Garden_Gun_Active == true ) {
			Util.EnableGroup( "Axis_Garden", TEAM.AXIS );
		}
		Util.MapDebugPrint( "Roof_Gun_Destroyed" );
	},


	Side_Warehouse_Entrance_Planted = function( trigger )
	{ if ( TestMap ) { return; }
		Map.Side_Warehouse_Entrance_Dyno += 1;
		SetAvailableMapGoals( TEAM.ALLIES, true, {
			"BUILD_Command.*",
			"PLANT_Garden.*",
			"PLANT_Villa_Gate.*",
		});
		Util.MapDebugPrint( "Side_Warehouse_Entrance_Planted" );
	},
	Side_Warehouse_Entrance_Defused = function( trigger )
	{ if ( TestMap ) { return; }
		Map.Side_Warehouse_Entrance_Dyno -= 1;
		Util.MapDebugPrint( "Side_Warehouse_Entrance_Defused" );
	},
	Side_Warehouse_Entrance_Destroyed = function( trigger )
	{ if ( TestMap ) { return; }
		Map.Side_Warehouse_Entrance_Dyno = 0;
		SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Villa_Gate" );
		Util.MapDebugPrint( "Side_Warehouse_Entrance_Destroyed" );
	},


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

};

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

	//Command Post
	OnTrigger( "Allied Command Post constructed. Charge speed increased!", Map.Allied_CP_Built );
	OnTrigger( "Axis Command Post constructed. Charge speed increased!", Map.Axis_CP_Built );
	OnTrigger( "Planted at the Command Post.", Map.CP_Planted );
	OnTrigger( "Defused at the Command Post.", Map.CP_Defused );
	OnTrigger( "Axis have destroyed the Allied Command Post!", Map.Allied_CP_Destroyed );
	OnTrigger( "Allied team has destroyed the Axis Command Post!", Map.Axis_CP_Destroyed );

	//Villa Gate
	OnTrigger( "Axis Team have built the Villa Gate!", Map.Villa_Gate_Built );
	OnTrigger( "Planted at the Villa Gate.", Map.Villa_Gate_Planted );
	OnTrigger( "Defused at the Villa Gate.", Map.Villa_Gate_Defused );
	OnTrigger( "The Allies have destroyed the Villa Gate!", Map.Villa_Gate_Destroyed );

	//Ladder
	OnTrigger( "Allied Team have built the Ladder!", Map.Villa_Ladder_Built );
	OnTrigger( "Planted at the Ladder.", Map.Villa_Ladder_Planted );
	OnTrigger( "Defused at the Villa Ladder.", Map.Villa_Ladder_Defused );
	OnTrigger( "Axis Team have destroyed the Ladder!", Map.Villa_Ladder_Destroyed );

	//Gun1 garden
	OnTrigger( "Planted at the Garden Anti-Aircraft Gun.", Map.Garden_Gun_Planted );
	OnTrigger( "Defused at the Garden Anti-Aircraft Gun.", Map.Garden_Gun_Defused );
	OnTrigger( "Allies have destroyed the Garden Anti-Aircraft Gun!", Map.Garden_Gun_Destroyed );

	//Gun2 roof
	OnTrigger( "Planted at Anti-Aircraft Roof Gun.", Map.Roof_Gun_Planted );
	OnTrigger( "Defused at Anti-Aircraft Roof Gun.", Map.Roof_Gun_Defused );
	OnTrigger( "Allies have destroyed the Roof Anti-Aircraft Gun!", Map.Roof_Gun_Destroyed );

	//Warehouse
	OnTrigger( "Planted at the Side Warehouse Entrance.", Map.Side_Warehouse_Entrance_Planted );
	OnTrigger( "Defused at the Side Warehouse Entrance.", Map.Side_Warehouse_Entrance_Defused );
	OnTrigger( "Allies have destroyed the Side Warehouse Entrance!", Map.Side_Warehouse_Entrance_Destroyed );

	//Desert area
	OnTrigger( "Allies lost the desert spawn!", Map.desertspawn_Axis_Captured );
	OnTrigger( "Allies captured the Desert!", Map.desertspawn_Allies_Captured );

	//===Setup Goals ===//
	Util.DisableGoal( ".*", true ); // all but routes
	Util.EnableGoal( "HEALTHCAB.*", true );
	Util.EnableGoal( "AMMOCAB.*", true );
	
	//Allies
	SetAvailableMapGoals( TEAM.ALLIES, true, {
		"ATTACK.*",
		"PLANT_Side.*",
	});

	//Axis
	SetAvailableMapGoals( TEAM.AXIS, true, {
		"SNIPE_.*",
		"ATTACK_.*",
		"DEFEND_Axis_Gun_1",
	});

	//Adjustments
	Util.SetGoalPosition( -594, 1850, 72, "PLANT_Garden_Anti_Aircraft_Gun" );
	Util.SetGoalPosition( -1290, 2654, 560, "PLANT_Anti_Aircraft_Roof_Gun" );
	Util.AddUsePoint( "PLANT_Side_Warehouse_Entrance", Vec3( -1966, -443, 68 ) );
	Util.AddUsePoint( "PLANT_Villa_Gate", Vec3( -286, 1448, 58 ) );

	// Defend + Camp times
	Util.EnableGroup( "Axis_Garden", TEAM.AXIS );
	Util.DisableGroup( "Axis_Roof", TEAM.AXIS );


	// 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( 3, "MOBILEMG42_.*" );
	Util.SetMaxUsers( 1, "MOBILEMORTAR_.*" );
	Util.SetMaxUsers( 1, "AIRSTRIKE_.*" );
	Util.SetMaxUsers( 1, "CALLARTILLERY_.*" );

	SetMapGoalProperties( "MOUNTMG42_.*", {MinCampTime=25, MaxCampTime=90} );
	SetMapGoalProperties( "MOBILEMG42_.*", {MinCampTime=30, MaxCampTime=90} );


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

global OnBotJoin = function( bot )
{
	// Uncomment for shootable breakables
	bot.TargetBreakableDist = 200.0;
	// Only set MaxViewDistance on maps with limited sight (e.g. fog)
	//~bot.MaxViewDistance = 2400;
};

global InitializeRoutes = function()
{
	MapRoutes =
	{
		DEFEND_Axis_Gun_2 = 
		{
		},
		BUILD_Villa_Gate =
		{
		},
		PLANT_Villa_Gate =
		{
		},
		PLANT_Garden_Anti_Aircraft_Gun =
		{
		},
		PLANT_Side_Warehouse_Entrance =
		{
		},
		BUILD_Command_Post =
		{
		},
		PLANT_Command_Post =
		{
		},
		CHECKPOINT_desertspawn =
		{
		},
		BUILD_Villa_Ladder =
		{
		},
		PLANT_Villa_Ladder =
		{
		},
		PLANT_Anti_Aircraft_Roof_Gun =
		{
		},
	};
	Util.Routes(MapRoutes);
};
