// GTW Game files. GTWFunction.cs
// Require to be run before Package GTWGame

function GTWGame::awardFlipFlopDestroy(%game, %cl)
{
   //messageAll("Switch has been destroyed. Attackers WIN!");
   //%game.attackersWin(%game);
   return %game.SCORE_FLIPFLOP_DESTROY;
}

function GTWGame::attackersWin(%game)
{
    $victory = 1;
    logEcho("game over (AtkObjective)");
    $TeamScore[1] = $TeamScore[2] + 1;
    %game.misSaveGame();
    DefaultGame::gameOver(%game);
    %winner = %game.getTeamName(1);
    cycleMissions();
    messageAll('MsgGameOver',"Attackers Secure territory.~wvoice/announcer/ann.stowins.wav");
    messageAll('MsgClearObjHud', "");
   for(%i = 0; %i < ClientGroup.getCount(); %i ++)
   {
      %client = ClientGroup.getObject(%i);
      %game.resetScore(%client);
   }
   for(%j = 1; %j <= %game.numTeams; %j++)
      $TeamScore[%j] = 0;
}

function GTWGame::awardMpbDestroy(%game)
{
   messageAll("MPB has been destroyed. Defenders WIN!");
   %game.defendersWin(%game);
   return %game.SCORE_FLIPFLOP_DESTROY;
}

function GTWGame::defendersWin(%game)
{
    $victory = 2;
    logEcho("game over (DefObjective)");
    $TeamScore[2] = $TeamScore[1] + 1;
    DefaultGame::gameOver(%game);
    %winner = %game.getTeamName(2);
    cycleMissions();
    messageAll('MsgGameOver',"Defenders repel attack.~wvoice/announcer/ann.infwins.wav");
    messageAll('MsgClearObjHud', "");
    for(%i = 0; %i < ClientGroup.getCount(); %i ++)
    {
        %client = ClientGroup.getObject(%i);
        %game.resetScore(%client);
    }
     for(%j = 1; %j <= %game.numTeams; %j++)
     $TeamScore[%j] = 0;
}

function GTWGame::noneWin(%game)
{
    $victory = 3;
    logEcho("game over");
    //$TeamScore[2] = $TeamScore[1] + 1;
    DefaultGame::gameOver(%game);
    %winner = 0;
    cycleMissions();
    messageAll('MsgGameOver',"Both teams found enternal peace.~wvoice/announcer/ann.infwins.wav");
    messageAll('MsgClearObjHud', "");
    for(%i = 0; %i < ClientGroup.getCount(); %i ++)
    {
        %client = ClientGroup.getObject(%i);
        %game.resetScore(%client);
    }
     for(%j = 1; %j <= %game.numTeams; %j++)
     $TeamScore[%j] = 0;
}

function showSpawnsLeft(%team)
{
    if ($casualties[%team] == 750)
    {
    messageAll('MsgSpawnsLeft','Team 1 has %1 soldiers left',$casualties[1]);
    messageAll('MsgSpawnsLeft','Team 2 has %1 soldiers left',$casualties[2]);
    }

    if ($casualties[%team] == 500)
    {
    messageAll('MsgSpawnsLeft','Team 1 has %1 soldiers left',$casualties[1]);
    messageAll('MsgSpawnsLeft','Team 2 has %1 soldiers left',$casualties[2]);
    }

    if ($casualties[%team] == 250)
    {
    messageAll('MsgSpawnsLeft','Team 1 has %1 soldiers left',$casualties[1]);
    messageAll('MsgSpawnsLeft','Team 2 has %1 soldiers left',$casualties[2]);
    }

    if ($casualties[%team] == 100)
    {
    messageAll('MsgSpawnsLeft','Team 1 has %1 soldiers left',$casualties[1]);
    messageAll('MsgSpawnsLeft','Team 2 has %1 soldiers left',$casualties[2]);
    }

    if ($casualties[%team] < 50)
    {
    messageAll('MsgSpawnsLeft','Team 1 has %1 soldiers left',$casualties[1]);
    messageAll('MsgSpawnsLeft','Team 2 has %1 soldiers left',$casualties[2]);
    }
}

function GTWGame::misSaveGame()
{
   //%file = "gtw/missions/grid13.mis";
   //missionGroup.save("missions/grid13.mis");
   //$MissionName = "grid13.mis";
}

