// FILENAME:	DD_Fort_Brid.cs
//
// AUTHOR:	ACrisp [oAo]
//------------------------------------------------------------------------------

$missionName = "DD_Fort_Brid";

$criticalPoints = 2;
$capturablePoints = 1;
$killPoints     = 1;
$deathPoints    = 1;
$buildingLostPoints = 20;
$fortBridBuildings = 13;
$totalCriticals = 3;

$yellowCriticalsLost = 0;
$redCriticalsLost = 0;

$noFactions = FALSE;

$objective1 = "Dropship.";
$objective2 = "Turrets.";
$capturable1 = "Fort Brid";

$briefingTxt = "During the Fire, Fort Brid was a refuge for Martian colonists from the Cybrid assault.  Now Imperial and Rebel forces battle for control of this fortified town.  Each side has set up a small landing zone from which to launch their attack.  The first side to destroy the other's dropship and turrets will be the victor!";

$yellowtech = "Imperial";
$redtech = "Rebel";
$bluetech = "none";
$purpletech = "none";

$base1Owner = "";

exec("multiplayerStdLib.cs");
exec("teamSetupStdlib.cs");
exec("DDStdlib.cs");

$server::HudMapViewOffsetX = -7168;
$server::HudMapViewOffsetY = 2048;


function setDefaultMissionOptions()
{
	$server::TeamPlay = true;
	$server::AllowDeathmatch = false;
	$server::AllowTeamPlay = true;	

	$server::AllowTeamRed = true;
	$server::AllowTeamBlue = false;
	$server::AllowTeamYellow = true;
	$server::AllowTeamPurple = false;

   // what can the server admin choose for available teams
   $server::disableTeamRed = false;
   $server::disableTeamBlue = true;
   $server::disableTeamYellow = false;
   $server::disableTeamPurple = true;

   $server::TeamDamage = true;
}

function onMissionLoad()
{
   cdAudioCycle("Purge", "Terror", "Watching");
   
   setRules();
  
}

function onMissionStart()
{
        createDropships();
   
	marsSounds();
}



function createDropships()
{
   // this function will create the Imperial and Rebel transports

   %x = getPosition(getObjectId("MissionGroup\\yellowBase\\navYellow"), x);
   %y = getPosition(getObjectId("MissionGroup\\yellowBase\\navYellow"), y);

   %herc = NewObject("KnDropship", Flyer, 111);
   setTeam(%herc, *IDSTR_TEAM_YELLOW);
   addToSet("MissionGroup/yellowBase", %herc);
   placeObject(%herc, %x, %y, 180);
   order(%herc, shutdown, true); // can't leave the engines idling...
   $yellowDrop = %herc;

   %x = getPosition(getObjectId("MissionGroup\\redBase\\navRed"), x);
   %y = getPosition(getObjectId("MissionGroup\\redBase\\navRed"), y);

   %herc = NewObject("RbConveyor", Flyer, 132);
   setTeam(%herc, *IDSTR_TEAM_RED);
   addToSet("MissionGroup/redBase", %herc);
   placeObject(%herc, %x, %y, 0);
   order(%herc, shutdown, true); // can't leave the engines idling...
   $redDrop = %herc;


}




function captureTrigger::Trigger::onEnter(%this, %object)
{
   %team  = getTeam(%object);
   %player = playerManager::vehicleIdToPlayerNum(%object);
   if ((%team == *IDSTR_TEAM_YELLOW) && ($base1Owner != %team))
    {
      $base1Owner = %team;
      %player.baseCaptures++;
      say(IDSTR_TEAM_YELLOW, 1, "Your team has captured Fort Brid!");
      say(IDSTR_TEAM_RED, 1, "The Imperials have captured Fort Brid!");
      setShapeVisibility(getObjectId("MissionGroup\\FortBrid\\neutralFlag"), false);
      setShapeVisibility(getObjectId("MissionGroup\\FortBrid\\redFlag"), false);
      setShapeVisibility(getObjectId("MissionGroup\\FortBrid\\yellowFlag"), true);

      setTeam(getObjectId("MissionGroup/FortBrid/defenses/turret1"), *IDSTR_TEAM_YELLOW);
      setTeam(getObjectId("MissionGroup/FortBrid/defenses/turret2"), *IDSTR_TEAM_YELLOW);
      setTeam(getObjectId("MissionGroup/FortBrid/defenses/turret3"), *IDSTR_TEAM_YELLOW);
      setTeam(getObjectId("MissionGroup/FortBrid/defenses/turret4"), *IDSTR_TEAM_YELLOW);
      setTeam(getObjectId("MissionGroup/FortBrid/defenses/turret5"), *IDSTR_TEAM_YELLOW);
      setTeam(getObjectId("MissionGroup/FortBrid/defenses/turret6"), *IDSTR_TEAM_YELLOW);
    }
   if ((%team == *IDSTR_TEAM_RED) && ($base1Owner != %team))
    {
      $base1Owner = %team;
      %player.baseCaptures++;
      say(IDSTR_TEAM_YELLOW, 1, "The Rebels have captured Fort Brid!");
      say(IDSTR_TEAM_RED, 1, "Your team has captured Fort Brid!");
      setShapeVisibility(getObjectId("MissionGroup\\FortBrid\\neutralFlag"), false);
      setShapeVisibility(getObjectId("MissionGroup\\FortBrid\\redFlag"), true);
      setShapeVisibility(getObjectId("MissionGroup\\FortBrid\\yellowFlag"), false);

      setTeam(getObjectId("MissionGroup/FortBrid/defenses/turret1"), *IDSTR_TEAM_RED);
      setTeam(getObjectId("MissionGroup/FortBrid/defenses/turret2"), *IDSTR_TEAM_RED);
      setTeam(getObjectId("MissionGroup/FortBrid/defenses/turret3"), *IDSTR_TEAM_RED);
      setTeam(getObjectId("MissionGroup/FortBrid/defenses/turret4"), *IDSTR_TEAM_RED);
      setTeam(getObjectId("MissionGroup/FortBrid/defenses/turret5"), *IDSTR_TEAM_RED);
      setTeam(getObjectId("MissionGroup/FortBrid/defenses/turret6"), *IDSTR_TEAM_RED);
    }
}



function vehicle::onDestroyed(%this, %destroyerID)
{
   %message = getFancyDeathMessage(getHUDName(%this), getHUDName(%destroyerID));
   if(%message != "")
   {
      say( 0, 0, %message);
   }


   if (%this == $yellowDrop)
    {
        %txt = "<f5>" @ getHUDname(%destroyerID) @ " has destroyed the Imperial dropship!";
         say(IDSTR_TEAM_RED, 1, %txt, "");

         say(IDSTR_TEAM_YELLOW, 1, "<f5>Your dropship has been destroyed!", "");


         $yellowCriticalsLost++;
         if ($yellowCriticalsLost == $totalCriticals)
          {
            winCondition();
          }
    }
   if (%this == $redDrop)
    {
        %txt = "<f5>" @ getHUDname(%destroyerID) @ " has destroyed the Rebel conveyor!";
         say(IDSTR_TEAM_YELLOW, 1, %txt, "");

         say(IDSTR_TEAM_RED, 1, "<f5>Your dropship has been destroyed!", "");


         $redCriticalsLost++;
         if ($redCriticalsLost == $totalCriticals)
          {
            winCondition();
          }
    }

 
}


// Water splashing functionality
//------------------------------------------------------------------------------
function fortBrid::structure::onDestroyed(%this, %attackerId)
 {

        $fortBridBuildings = $fortBridBuildings - 1;
	// Which water tower was just destroyed?
	if(%this == getObjectId("MissionGroup\\FortBrid\\WaterTower"))
         {
		setShapeVisibility(getObjectId("MissionGroup\\FortBrid\\Splash"), true);
		playAnimSequence(getObjectId("MissionGroup\\FortBrid\\Splash"), 0, true);
	 }

        if (%this == getObjectId("MissionGroup\\FortBrid\\Fusion"))
         {
                damageArea(getObjectId("MissionGroup\\FortBrid\\Fusion"), 0, 0, 0, 100, 5000);
                order("MissionGroup/FortBrid/defenses", shutdown, true);

         }
 }
