// Omni-bot 0.7 script for Wolfsrudel2, by d00d
// Mon, 19 May 2008 15:50:08 GMT
// Waypoints by Blindman

global OnMapLoad = function()
{
  Util.SetGoalOffset( 0, -10, 0, "PLANT_Forwardbunkerdoor" );
  Util.SetGoalOffset( -10, 0, 0, "PLANT_Woodenbarrier" );
  SetGoalPriority( "PLANT_Forwardbunkerdoor", 1.0 );
  SetGoalPriority( "DEFEND_radarparts.*", 0.7 );
  SetGoalPriority( "PLANTMINE_radiomast1", 0.95 );
  SetGoalPriority( "PLANTMINE_radiomast2", 0.93 );
  SetGoalPriority( "PLANTMINE_radiomast3", 0.91 );
  SetAvailableMapGoals( TEAM.ALLIES, false, {
  	"PLANTMINE_.*",
  	"DEFEND_.*",
  	"MOUNTMG42_475",
  	"REPAIRMG42_475",
  	"SNIPE_.*",
  });
  SetAvailableMapGoals( TEAM.ALLIES, true, "SNIPE_compost" );

  SetAvailableMapGoals( TEAM.AXIS, false, {
  	"SNIPE_.*",
  	"MOUNTMG42_475",
  	"MOUNTMG42_136",
  	"REPAIRMG42_136",
  	"DEFEND.*",
  });
  SetAvailableMapGoals( TEAM.AXIS, true, {
  	"DEFEND_start.*",
  	"DEFEND_forwardbunker.*",
  });

  Util.SetMaxUsersInProgress( 1, "DEFEND_.*" );

  Map.bunker_secured = false;
  Map.radars_stolen = 0;
  Map.radars_secured = 0;
  Map.radars_left = 0;

  OnTrigger( "wr_axis_entrance1_destroyed", Map.onBunkerSecured );
  //OnTrigger( "^1The Allies breach the Forwardbunkerdoor!", Map.onMaindoorBreached );
  OnTrigger( "^1The Allies have breached the Sidewall!", Map.onSideWallBreached );
  OnTrigger( "^1The Allies have breached the Bunkersidewall!", Map.onSideWallBreached );
  OnTrigger( "^1Allies have destroyed the Main Radio Mast!", Map.onMastDestroyed );
  OnTrigger( "Allies have stolen the First Radarparts!", Map.onRadarStolen );
  OnTrigger( "Allies have stolen the Second Radarparts!", Map.onRadarStolen );
  OnTrigger( "Flag returned emitterbox1!", Map.onRadarReturned );
  OnTrigger( "Flag returned emitterbox2!", Map.onRadarReturned );
  OnTrigger( "^1Allies have secured the Second Radar Parts!", Map.onRadarSecured );
  OnTrigger( "^1Allies have secured the First Radar Parts!", Map.onRadarSecured );
  //print("OnMapLoad");
};

global OnBotJoin = function( bot )
{
  // half of the allies should spawn at the water tower
  if ( bot.GetTeam() == TEAM.ALLIES && !Map.bunker_secured )
  {
    if ( RandInt(0,1) == 1 )
    {
      bot.ChangeSpawnPoint(4);
    }
  }
};

global Map =
{
  onBunkerSecured = function()
  {
    Map.bunker_secured = true;
    SetAvailableMapGoals( TEAM.ALLIES, true, "SNIPE_allies.*" );
    SetAvailableMapGoals( TEAM.AXIS, true, "SNIPE_fort.*" );
    SetAvailableMapGoals( TEAM.ALLIES, false, {
    	"MOUNTMG42_136",
    	"REPAIRMG42_136",
    });
    SetAvailableMapGoals( TEAM.AXIS, false, {
    	"DEFEND_forwardbunker.*",
    	"HEALTH_154",
    	"AMMO_153",
    	"HEALTH_CABINET_t10.*",
    	"AMMO_CABINET_t10.*",
    });
    foreach ( bot in BotTable )
    {
      if ( bot.GetTeam() == TEAM.ALLIES )
      {
        bot.ChangeSpawnPoint(0);
      }
    }
    //print("onBunkerSecured");
  },

  onMaindoorBreached = function()
  {
    Map.enableInsideDefense();
    //print("onMaindoorBreached");
  },

  onSideWallBreached = function()
  {
    Map.enableInsideDefense();
    //print("onSideWallBreached");
  },

  onMastDestroyed = function()
  {
    SetAvailableMapGoals( TEAM.AXIS, false, {
    	"SNIPE_fort4",
    	"SNIPE_fort5",
    	"SNIPE_fort6",
    });
    SetAvailableMapGoals(TEAM.AXIS, false, {
    	"DEFEND_radiomast.*",
    	"PLANTMINE_radiomast.*",
    	"BUILD_defense",
    });
    SetAvailableMapGoals(TEAM.ALLIES, false, "PLANT_defense");
    //print("onMastDestroyed");
  },

  onRadarStolen = function()
  {
    Map.radars_stolen = Map.radars_stolen + 1;
    Map.radars_left = Map.radars_left - 1;
    if (Map.radars_stolen > 0)
    {
      SetAvailableMapGoals(TEAM.AXIS, true, "DEFEND_cappoint.*");
      SetAvailableMapGoals(TEAM.ALLIES, true, "DEFEND_cappoint.*");
      SetGoalPriority( "DEFEND_cappoint.*", 0.8 );
      Util.ResetGoals();
    }
    if (Map.radars_left == 0)
    {
      SetAvailableMapGoals(TEAM.AXIS, false, "DEFEND_radarpart.*");
      Util.ResetGoals();
    }
    //print("onRadarStolen; Map.radars_stolen = ",Map.radars_stolen);
  },

  onRadarSecured = function()
  {
    Map.radars_stolen = Map.radars_stolen - 1;
    Map.radars_secured = Map.radars_secured + 1;
    if (Map.radars_stolen < 1)
    {
      SetAvailableMapGoals(TEAM.AXIS, false, "DEFEND_cappoint.*");
      SetAvailableMapGoals(TEAM.ALLIES, false, "DEFEND_cappoint.*");
    }
    if (Map.radars_secured == 2)
    {
      SetAvailableMapGoals( TEAM.ALLIES, false, "SNIPE_compost" );
      SetAvailableMapGoals(TEAM.AXIS, false, {
      	"DEFEND_radarpart.*",
      	"DEFEND_cappoint.*",
      });
      SetAvailableMapGoals(TEAM.ALLIES, false, {
      	"DEFEND_cappoint.*",
      	"PLANT_woodenbarrier",
      });
      Util.ResetGoals();
    }
    //print("onRadarSecured; Map.radars_stolen = ",Map.radars_stolen);
  },

  onRadarReturned = function()
  {
    Map.radars_stolen = Map.radars_stolen - 1;
    Map.radars_left = Map.radars_left + 1;
    if (Map.radars_stolen < 1)
    {
      SetAvailableMapGoals(TEAM.AXIS, false, "DEFEND_cappoint.*");
      SetAvailableMapGoals(TEAM.ALLIES, false, "DEFEND_cappoint.*");
    }

    if (Map.radars_left > 0)
    {
      SetAvailableMapGoals(TEAM.AXIS, true, "DEFEND_radarpart.*");
    }
    //print("onRadarReturned; Map.radars_stolen = ",Map.radars_stolen);
  },

  enableInsideDefense = function()
  {
    SetAvailableMapGoals(TEAM.AXIS, true, {
    	"DEFEND_fort.*",
    	"DEFEND_radiomast.*",
    	"DEFEND_radarparts.*",
    	"MOUNTMG42_475",
    });
  },

};
