//==========================================================================================
//
//	stock_snipertram.gm_editing
//
//	Who                  	When		What
//------------------------------------------------------------------------------------------
//	maker@bigsighstudios.com	31 January 2018	Initial Script
//
//==========================================================================================
//

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

	Axis_Engy_Count = 0,
	Allies_Engy_Count = 0,

//	//SnipeMap = 1, //hmm, we need an engy.
//
//	Roles =
//	{
//		AXIS =
//		{
//			AllBots = true, // each bot is considered for a role
//			DEFENDER =
//			{
//				spawnpt = 1,
//				numbots = 5,
//				crucialClass = CLASS.ENGINEER,
//			},
//			DEFENDER1 =
//			{
//				spawnpt = 1,
//				numbots = 5,
//				crucialClass = CLASS.COVERTOPS,
//			},
//			DEFENDER2 =
//			{
//				spawnpt = 1,
//				numbots = 5,
//				crucialClass = CLASS.COVERTOPS,
//			},
//			DEFENDER3 =
//			{
//				spawnpt = 1,
//				numbots = 5,
//				crucialClass = CLASS.COVERTOPS,
//			},
//		},
//
//		ALLIES =
//		{
//			AllBots = true, // each bot is considered for a role
//			ATTACKER =
//			{
//				numbots = 5,
//				crucialClass = CLASS.ENGINEER,
//			},
//			ATTACKER1 =
//			{
//				numbots = 5,
//				crucialClass = CLASS.COVERTOPS,
//			},
//			ATTACKER2 =
//			{
//				numbots = 5,
//				crucialClass = CLASS.COVERTOPS,
//			},
//			ATTACKER3 =
//			{
//				numbots = 5,
//				crucialClass = CLASS.COVERTOPS,
//			},
//		},
//	},

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

	Axis_Wall_and_MG42_Built = function( trigger )
	{
		SetAvailableMapGoals( TEAM.AXIS, 0, "BUILD_Axis_Wall_and_MG42" );
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Axis_Wall_and_MG42" );

		Util.MapDebugPrint( "Axis_Wall_and_MG42_Built" );
	},
	Axis_Wall_and_MG42_Destroyed = function( trigger )
	{
                SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Generator" );
		SetAvailableMapGoals( TEAM.AXIS, 1, "BUILD_Axis_Wall_and_MG42" );
		Util.MapDebugPrint( "Axis_Wall_and_MG42_Destroyed" );
	},

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

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

	Bank_Door_Planted = function( trigger ) //"axis_hq_objective_destroyed" incorrect
	{
    SetAvailableMapGoals( TEAM.ALLIES, true, "CAMP_ATTACK_B" ); 
    SetAvailableMapGoals( TEAM.ALLIES, true, "CAMP_ATTACK_A" );
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Bank_Door" );
    SetAvailableMapGoals( TEAM.ALLIES, true, "FLAG_loffy_gold_crateinbank" );
		Util.MapDebugPrint( "Bank_Door_Planted" );
	},
	Bank_Door_Defused = function( trigger ) //"axis_hq_objective_destroyed"
	{
		SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Bank_Door" );;
		Util.MapDebugPrint( "Bank_Door_Defused" );
	},
	Bank_Door_Destroyed = function( trigger ) //"axis_hq_objective_destroyed"
	{
                SetAvailableMapGoals( TEAM.ALLIES, false, "CAMP_ATTACK_B" ); 
                SetAvailableMapGoals( TEAM.ALLIES, false, "CAMP_ATTACK_A" );                
                SetAvailableMapGoals( TEAM.ALLIES, true, "FLAG_loffy_gold_crateinbank" );
		SetAvailableMapGoals( TEAM.ALLIES, false, "PLANT_Bank_Door" );
                SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Generator" );
                SetAvailableMapGoals( TEAM.AXIS, false, "CHECKPOINT_the_flag" );
                SetAvailableMapGoals( TEAM.ALLIES, false, "CHECKPOINT_the_flag" );
                SetAvailableMapGoals( TEAM.ALLIES, true, "PLANT_Axis_Wall_and_MG42" );
	Util.LimitToClass( "PLANT_Axis_Wall_and_MG42", 1, CLASS.COVERTOPS, CLASS.ENGINEER );
                SetGoalPriority( "PLANT_Axis_Wall_and_MG42", 0.99, TEAM.ALLIES );
	        SetGoalPriority( "FLAG_loffy_gold_crateinbank", 0.99, TEAM.ALLIES );
          	Util.DisableGoal( "CAMP_ATTACK_A", true ); // all but routes
            	Util.DisableGoal( "CAMP_ATTACK_B", true ); // all but routes
		Util.MapDebugPrint( "Bank_Door_Destroyed" );
	},

	Generator_Planted = function( trigger ) //"axis_hq_objective_destroyed"
	{
		SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Generator" );

		Util.MapDebugPrint( "Generator_Planted" );
	},
	Generator_Defused = function( trigger ) //"axis_hq_objective_destroyed"
	{
		SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Generator" );

		Util.MapDebugPrint( "Generator_Planted" );
	},
	Generator_Destroyed = function( trigger )
	{
                SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Generator" );
		Util.MapDebugPrint( "Generator_Destroyed" );
	},

	loffy_gold_crateinbank_Taken = function( trigger )
	{
                SetAvailableMapGoals( TEAM.ALLIES, true, "CAPPOINT_.*" );
                SetAvailableMapGoals( TEAM.ALLIES, true, "CAMP_ATTACK_E" ); 
                SetAvailableMapGoals( TEAM.ALLIES, true, "CAMP_ATTACK_C" ); 
                SetAvailableMapGoals( TEAM.ALLIES, true, "CAMP_ATTACK_D" );
                SetAvailableMapGoals( TEAM.ALLIES, false, "CAMP_ATTACK_B" ); 
                SetAvailableMapGoals( TEAM.ALLIES, false, "CAMP_ATTACK_A" );
		Util.MapDebugPrint( "loffy_gold_crateinbank_Taken" );
	},
	loffy_gold_crateinbank_Returned = function( trigger )
	{
                SetAvailableMapGoals( TEAM.ALLIES, true, "FLAG_loffy_gold_crateinbank" );
		Util.MapDebugPrint( "loffy_gold_crateinbank_Returned" );
	},
	loffy_gold_crateinbank_Secured = function( trigger )
	{
		Util.MapDebugPrint( "loffy_gold_crateinbank_Secured" );
	},

	the_flag_Axis_Captured = function( trigger )
	{
                SetAvailableMapGoals( TEAM.AXIS, false, "CHECKPOINT_the_flag" );
                SetAvailableMapGoals( TEAM.ALLIES, true, "CHECKPOINT_the_flag" );
		Util.MapDebugPrint( "the_flag_Axis_Captured" );
	},
	the_flag_Allies_Captured = function( trigger )
	{
                SetAvailableMapGoals( TEAM.AXIS, true, "CHECKPOINT_the_flag" );
                SetAvailableMapGoals( TEAM.ALLIES, false, "CHECKPOINT_the_flag" );
		Util.MapDebugPrint( "the_flag_Allies_Captured" );
	},

	// 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_Command_Post" );
				SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Command_Post" );
				SetAvailableMapGoals( TEAM.AXIS,   1, "BUILD_Command_Post" );
				SetAvailableMapGoals( TEAM.AXIS,   0, "PLANT_Command_Post" );
			}
			case TEAM.ALLIES:
			{
				Map.CP_Owner = TEAM.ALLIES;
				SetAvailableMapGoals( TEAM.ALLIES, 0, "BUILD_Command_Post" );
				SetAvailableMapGoals( TEAM.ALLIES, 0, "PLANT_Command_Post" );
				SetAvailableMapGoals( TEAM.AXIS,   1, "PLANT_Command_Post" );
			}
			case TEAM.AXIS:
			{
				Map.CP_Owner = TEAM.AXIS;
				SetAvailableMapGoals( TEAM.ALLIES, 0, "BUILD_Command_Post" );
				SetAvailableMapGoals( TEAM.ALLIES, 1, "PLANT_Command_Post" );
				SetAvailableMapGoals( TEAM.AXIS,   0, "PLANT_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( "Allied Command Post constructed. Charge speed increased!",  Map.Allied_CP_Built );
	OnTrigger( "Axis team has destroyed the Allied Command Post!",          Map.Allied_CP_Destroyed );
	OnTrigger( "Axis Command Post constructed. Charge speed increased!",    Map.Axis_CP_Built );
	OnTrigger( "Allied 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  );
        OnTrigger( "Planted at the Bank Door.",                              Map.Bank_Door_Planted  );

	OnTrigger( "MISSING_STRING", Map.Allied_constructible_Built );
	OnTrigger( "MISSING_STRING", Map.Allied_constructible_Destroyed );

	//"The Axis are constructing their Wall, and MG42!"
	OnTrigger( "Axis Wall (and MG42) constructed!", Map.Axis_Wall_and_MG42_Built );
	OnTrigger( "Allied Wall and MG42 destroyed!", Map.Axis_Wall_and_MG42_Destroyed );

	OnTrigger( "MISSING_STRING", Map.Neutral_Constructible_Built );
	OnTrigger( "MISSING_STRING", Map.Neutral_Constructible_Destroyed );

	//"The Allies have started to build the lower Tram system!"
	//"The Allied Forces have constructed the lower Tram system!"
	//"The lower Tram system is destroyed!"

	//"The Allies have started to build an ammo and health dispenser!"
	//"The Allied Forces have constructed an ammo and health dispenser!"
	//"The ammo and health dispenser is destroyed!"

	//"The Allies have started to build the upper Tram system!"

	//"The Axis have started to build the upper Tram system!"
	OnTrigger( "The Axis Forces have constructed the upper Tram system!", Map.Tram_1_Built );

	OnTrigger( "MISSING_STRING", Map.Tram_1_Destroyed );

	OnTrigger( "Setting Axis autospwan to Axis Second Spawn Setting Allied autospawn to Axis First Spawn", Map.Bank_Door_Destroyed );

	OnTrigger( "Allies have destroyed the Generator!", Map.Generator_Destroyed );

	OnTrigger( "Allies have stolen The Gold!", Map.loffy_gold_crateinbank_Taken );
	OnTrigger( "Axis have returned the Gold!", Map.loffy_gold_crateinbank_Returned );
	OnTrigger( "MISSING_STRING", Map.loffy_gold_crateinbank_Secured );

	OnTrigger( "Axis reclaim the Flag!", Map.the_flag_Axis_Captured );
	OnTrigger( "Allies capture the Flag!", Map.the_flag_Allies_Captured );

	//---------------------------------------------------------------------------

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

	Util.LimitToClass( "BUILD_Command_Post", 0, CLASS.ENGINEER);
	Util.LimitToClass( "BUILD_Neutral_.*", 0, CLASS.ENGINEER);
	Util.LimitToClass( "PLANT_Command_Post", 0, CLASS.COVERTOPS);
  	Util.LimitToClass( "PLANT_Bank_Door", 1, CLASS.ENGINEER);
	Util.LimitToClass( "Generator", 1, CLASS.ENGINEER);
	Util.LimitToClass( "CHECKPOINT_the_flag", 1, CLASS.MEDIC);
	Util.LimitToClass( "MOUNTMG42.*", TEAM.AXIS, CLASS.SOLDIER, CLASS.FIELDOPS );
	Util.LimitToClass( "MOUNTMG42.*", TEAM.ALLIES, CLASS.SOLDIER, CLASS.FIELDOPS );

	Util.LimitToClass( "CAMP_ATTACK_B", TEAM.ALLIES, CLASS.SOLDIER, CLASS.FIELDOPS, CLASS.MEDIC );
	Util.LimitToClass( "CAMP_ATTACK_A", TEAM.ALLIES, CLASS.SOLDIER, CLASS.FIELDOPS, CLASS.MEDIC );
  Util.LimitToClass( "CAMP_ATTACK_C", TEAM.ALLIES, CLASS.SOLDIER, CLASS.FIELDOPS, CLASS.MEDIC );
	Util.LimitToClass( "CAMP_ATTACK_D", TEAM.ALLIES, CLASS.SOLDIER, CLASS.FIELDOPS, CLASS.MEDIC );
	Util.LimitToClass( "CAMP_ATTACK_E", TEAM.ALLIES, CLASS.SOLDIER, CLASS.FIELDOPS, CLASS.MEDIC );

	//Allies
	Util.LimitToClass( "PLANT_Axis_Wall_and_MG42", 1, CLASS.COVERTOPS);
	Util.AddUsePoint( "PLANT_Axis_Wall_and_MG42", Vec3( -6742, -2498, 456 ) );
	Util.AddUsePoint( "PLANT_Generator", Vec3( -5940, -3926, 724 ) );
        SetGoalPriority( "PLANT_Generator", 1.0, TEAM.ALLIES );
        SetGoalPriority( "PLANT_Bank_Door", 1.0, TEAM.ALLIES );
        SetGoalPriority( "CAPPOINT_goldcrate_capture_point", 1.0, TEAM.ALLIES );
        SetAvailableMapGoals( TEAM.ALLIES, false, "FLAG_loffy_gold_crateinbank" );
        SetAvailableMapGoals( TEAM.ALLIES, false, "CAMP_ATTACK_A" );
        SetAvailableMapGoals( TEAM.ALLIES, false, "CAMP_ATTACK_C" ); 
        SetAvailableMapGoals( TEAM.ALLIES, false, "CAMP_ATTACK_D" );
        SetAvailableMapGoals( TEAM.ALLIES, false, "CAMP_ATTACK_E" );
      SetAvailableMapGoals( TEAM.ALLIES, false, "CAMP_ATTACK_B" ); 
	SetAvailableMapGoals( TEAM.ALLIES, 1, {
		".*CAB.*",
		//"ATTACK_.*",
		//"SNIPE_Al_.*",
		"BUILD_ALlied_.*",
		"BUILD_Command_Post",
		"BUILD_Neutral_.*",
		"BUILD_Tram_.*",
		"PLANT_Bank_Door",
    "PLANT_Generator",
    "CHECKPOINT_the_flag",
    "CAPPOINT_goldcrate_capture_point",
	});

	//Axis
	SetAvailableMapGoals( TEAM.AXIS, 1, {
		".*CAB.*",
		//"DEFEND_.*",
		//"SNIPE_Ax_.*",
		"BUILD_Command_Post",
		"BUILD_Axis_.*",
		"BUILD_Neutral_.*",
               // "CHECKPOINT_the_flag",
                "BUILD_Axis_Wall_and_MG42",

	});

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

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

	SetMapGoalProperties( "CAMP_ATTACK_A", {MinCampTime=90, MaxCampTime=999} );
	SetGoalPriority("CAMP_ATTACK_A", 0.97);
	SetMapGoalProperties( "CAMP_ATTACK_B", {MinCampTime=90, MaxCampTime=999} );
	SetGoalPriority("CAMP_ATTACK_B", 0.97);
	SetMapGoalProperties( "CAMP_ATTACK_C", {MinCampTime=90, MaxCampTime=999} );
	SetGoalPriority("CAMP_ATTACK_C", 0.97);
	SetMapGoalProperties( "CAMP_ATTACK_D", {MinCampTime=90, MaxCampTime=999} );
	SetGoalPriority("CAMP_ATTACK_D", 0.97);
	SetMapGoalProperties( "CAMP_ATTACK_E", {MinCampTime=90, MaxCampTime=999} );
	SetGoalPriority("CAMP_ATTACK_E", 0.98);


	//Server.MinClassCount[teamId][Util.SniperClass] = 99;
        Util.LimitToTeam( TEAM.ALLIES, "CAMP_ATTACK_A" );
        Util.LimitToTeam( TEAM.ALLIES, "CAMP_ATTACK_B" );
        Util.LimitToTeam( TEAM.ALLIES, "CAMP_ATTACK_C" );
        Util.LimitToTeam( TEAM.ALLIES, "CAMP_ATTACK_D" );
        Util.LimitToTeam( TEAM.ALLIES, "CAMP_ATTACK_E" );
	//Util.LimitToTeam( TEAM.AXIS, "SNIPE_Ax.*" );
	//Util.LimitToTeam( TEAM.ALLIES, "SNIPE_Al.*" );

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

};

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;
//
//	if ( bot.GetTeam() == TEAM.AXIS )
//	{
//		if ( Map.Axis_Engy_Count < 1 ) {
//			Map.Axis_Engy_Count += 1;
//			bot.ChangeClass(CLASS.ENGINEER);
//		} else {
//			bot.ChangeClass(CLASS.COVERTOPS);
//			Util.ChangeToSniperWeapons(bot);
//		}
//	}
//	else
//	if ( bot.GetTeam() == TEAM.ALLIES )
//	{
//		if ( Map.Allies_Engy_Count < 1 ) {
//			Map.Allies_Engy_Count += 1;
//			bot.ChangeClass(CLASS.ENGINEER);
//		} else {
//			bot.ChangeClass(CLASS.COVERTOPS);
//			Util.ChangeToSniperWeapons(bot);
//		}
//	}
};

global InitializeRoutes = function()
{
	MapRoutes =
	{
		BUILD_Allied_constructible =
		{
		},
		PLANT_Allied_constructible =
		{
		},
		BUILD_Tram_1 =
		{
		},
		PLANT_Tram_1 =
		{
		},
		CHECKPOINT_the_flag =
		{
		},
		PLANT_Generator =
		{
		},
		BUILD_Command_Post =
		{
		},
		PLANT_Command_Post =
		{
		},
		PLANT_Bank_Door =
		{
		},
		BUILD_Neutral_Constructible =
		{
		},
		PLANT_Neutral_Constructible =
		{
		},
		BUILD_Axis_Wall_and_MG42 =
		{
		},
		PLANT_Axis_Wall_and_MG42 =
		{
		},
		FLAG_loffy_gold_crateinbank =
		{
		},
	};
	Util.Routes(MapRoutes);
};
