// FILENAME:	DM_Volcano.cs
//
// AUTHORS:  	Gen. Powio™ [MIB]
//------------------------------------------------------------------------------

$missionName = "DM_Volcano";
$sinkSpeed = 0.35;
$minEruptTime = 120;
$maxEruptTime = 180;
$volcano = true;
$rocks = 6;
$rockFireRate = 0.25;

exec("multiplayerStdLib.cs");
exec("DMstdLib.cs");

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

   // what can the client choose for a team
	$server::AllowTeamRed = false;
	$server::AllowTeamBlue = false;
	$server::AllowTeamYellow = false;
	$server::AllowTeamPurple = false;

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

function onMissionStart()
{
	venusSounds();
}

function vehicle::onDestroyed(%d,%r)
{
   %p = playerManager::vehicleIdToPlayerNum(%d);
   vehicle::onDestroyedLog(%d,%r);
   %m = getFancyDeathMessage(getHUDName(%d),getHUDName(%r));
   if(%d.Damage == Burning)
   {
      %r = randomInt(0,2);
      if(%r == 0)
      {
         say(0,%p,getHUDName(%d)@"<F5> slipped into the volcano and was promptly devoured by the flames.","sfx_lava.wav");
      }
      else if(%r == 1)
      {
         say(0,%p,getHUDName(%d)@"<F5> took a step into the magma and never returned.","sfx_lava.wav");
      }
      else
      {
         say(0,%p,getHUDName(%d)@"<F5> took a nasty fall into the magma but couldn't make it out in time.","sfx_lava.wav");
      }
   }
   else if(%d.Damage == FireRock)
   {
      %r = randomInt(0,2);
      if(%r == 0)
      {
         say(0,%p,getHUDName(%d)@"<F5> was whacked over the head by a stray fire rock.","sfx_lava.wav");
      }
      else if(%r == 1)
      {
         say(0,%p,getHUDName(%d)@"<F5> couldn't make the play when the fire rock came crashing down.","sfx_lava.wav");
      }
      else
      {
         say(0,%p,getHUDName(%d)@"<F5> exploded just the fire rock that exploded on them.","sfx_lava.wav");
      }
   }
   else if(%m != "")
   {
      say( 0, 0, %m);
   }
   %v.Ready = "";
}

function vehicle::onAdd(%v)
{
   %v.Damage = "";
   %v.Ready = True;
}

function player::onAdd(%player)
{
   messageBox(%player, "This map requires that you download a new terrain to play. It is available for download in the \"MIB Terrain Pack\" on the MIB website at www.starsiegemeninblack.cjb.net");
   say(%player,0,"Welcome to DM_Volcano! You can download this & other terrain-based missions made by Gen. Powio™ [MIB] in the \"MIB Terrain Pack\" on the MIB Website at www.starsiegemeninblack.cjb.net");
}

function ZenHeal::trigger::onEnter(%this, %object)
{
   	Zen::onEnter(%this, %object, *IDMULT_CHAT_HEALPAD, true, true);  
}
function ZenHeal::trigger::onContact(%this, %object)
{
   	Zen::work(%this, %object, $healRate, 0, $padWaitTime, true); 
}

function ZenAmmo::trigger::onEnter(%this, %object)
{
   	Zen::onEnter(%this, %object, *IDMULT_CHAT_AMMOPAD, true, true);  
}

function ZenAmmo::trigger::onContact(%this, %object)
{
   	Zen::work(%this, %object, 0, $ammoRate, $padWaitTime, true); 
}

function ZenAll::trigger::onEnter(%this, %object)
{
   	Zen::onEnter(%this, %object, *IDMULT_CHAT_ALLPAD, true, true);  
}

function ZenAll::trigger::onContact(%this, %object)
{
   	Zen::work(%this, %object, $healRate, $ammoRate, $zenWaitTime, true); 
}

function EnergyBoost::Trigger::onEnter(%t,%v)
{
   %p = playerManager::vehicleIdToPlayerNum(%v);
   if($EnergyBoostReady == True)
   {
      setShapeVisibility($EnergyBoost,false);
      $EnergyBoostReady = "";
      healObject(%v,999999);
      healObject(%v,999999);
      healObject(%v,999999);
      healObject(%v,999999);
      healObject(%v,999999);
      say(%p,%p,"<F4>Your vehicle has been restored.","sfx_reactorcap.wav");
      schedule("readyEnergy();",180);
   }
}

function readyEnergy()
{
   setShapeVisibility($EnergyBoost,true);
   $EnergyBoostReady = True;
}

function Burner::Trigger::onContact(%t,%v)
{
   %p = playerManager::vehicleIdToPlayerNum(%v);
   playSound(%p,"sfx_fire.wav",IDPRF_2D);
   if(%v.Ready == True)
   {
      %v.Damage = Burning;
      %x = getPosition(%v,x);
      %y = getPosition(%v,y);
      %z = getPosition(%v,z);
      setPosition(%v,%x,%y,%z - $sinkSpeed);
      damageObject(%v,400);
   }
   else
   {
      %v.Damage = "";
   }
}

function Burner::Trigger::onLeave(%t,%v)
{
   %p = playerManager::vehicleIdToPlayerNum(%v);
   %x = getPosition(%v,x);
   %y = getPosition(%v,y);
   %z = getPosition(%v,z);
   if((%v.Ready == True)&&((%x < -354)&&(%x > -574)&&(%y < -194)&&(%y > -414)&&(%z < 101)))
   {
      %v.Damage = Burning;
      damageObject(%v,999999);
      echo(getHUDname(%v)@" has sunk.");
   }
   else
   {
      setPosition(%v,%x,%y,getTerrainHeight(%x,%y));
      %v.Damage = "";
      echo(%x@" "@%y@" "@%z);
   }
}

function eruption()
{
   if($volcano == True)
   {
      playSound(0,"sfx_quake.wav",IDPRF_2D);
      schedule("playSound(0,\"sfx_quake.wav\",IDPRF_2D);",1);
      schedule("playSound(0,\"sfx_quake.wav\",IDPRF_2D);",2);
      schedule("playSound(0,\"sfx_quake.wav\",IDPRF_2D);",3);
      schedule("playSound(0,\"sfx_quake.wav\",IDPRF_2D);",4);
      schedule("playSound(0,\"sfx_quake.wav\",IDPRF_2D);",5);
      schedule("playSound(0,\"sfx_quake.wav\",IDPRF_2D);",6);
      schedule("playSound(0,\"sfx_quake.wav\",IDPRF_2D);",7);
      schedule("calRocks();",7);
   }
   %t = randomInt($minEruptTime,$maxEruptTime);
   echo("Next Eruption - "@%t@"s");
   schedule("eruption();",%t);
}

function calRocks()
{
   %w = 0;
   
   for(%i=0;%i<$Rocks;%i++)
   {
      schedule("fireRock();",%w);
      %w = %w + $rockFireRate;
   }
}


function fireRock()
{
   playSound(0,"sfx_fog.wav",IDPRF_2D);
   playSound(0,"sfx_prob.wav",IDPRF_2D);
   %x1 = randomInt(-554,-384);
   %y1 = randomInt(-384,-224);
   %x2 = randomInt(-928,0);
   %y2 = randomInt(-832,224);
   if(%x1 < %x2)
   {
      %distX = %x2 - %x1;
   }
   else if(%x2 < %x1)
   {
      %distX = %x1 - %x2;
   }
   if(%y1 < %y2)
   {
      %distY = %y2 - %y1;
   }
   else if(%y2 < %y1)
   {
      %distY = %y1 - %y2;
   }
   dropPod(%x1,%y1,100,%x2,%y2,2000);
   %hyp = sqrt((%distX * distX) + (%distY * %distY));
   %NewHyp = sqrt((%hyp * %hyp) + (1900 * 1900));
   %t = %NewHyp / 400;
   schedule("dropRock("@%x2@","@%y2@");",%t);
}

function dropRock(%x1,%y1)
{
   playSound(0,"sfx_quake.wav",IDPRF_2D);
   %a = newObject("Nothing",staticShape,"Nothing.dts");
   %x2 = randomInt(-928,0);
   %y2 = randomInt(-832,224);
   %z = getTerrainHeight(%x2,%y2);
   setPosition(%a,%x2,%y2,%z);
   if(%x1 < %x2)
   {
      %distX = %x2 - %x1;
   }
   else if(%x2 < %x1)
   {
      %distX = %x1 - %x2;
   }
   if(%y1 < %y2)
   {
      %distY = %y2 - %y1;
   }
   else if(%y2 < %y1)
   {
      %distY = %y1 - %y2;
   }
   %zdist = 2000 - %z;
   %hyp = sqrt((%distX * distX) + (%distY * %distY));
   %NewHyp = sqrt((%hyp * %hyp) + (%zdist * %zdist));
   %t = %NewHyp / 400;
   dropPod(%x1,%y1,2000,%x2,%y2,%z);

   schedule("%c = playerManager::getPlayerCount(); for(%i=0;%i<%c;%i++){%p = playerManager::getPlayerNum(%i); %v = playerManager::playerNumToVehicleId(%p); %dist = getDistance(%v,"@%a@"); if(%dist <= 120){ %v.Damage = FireRock; }}",%t);

   schedule("damageArea("@%a@",0,0,0,120,5000);",%t);
   schedule("setPosition("@%a@",0,0,0);",%t + 1);
   schedule("deleteObject("@%a@");",%t + 2);
}

function onMissionLoad()
{
   cdAudioCycle("Purge", "Terror", "Watching");
   $healRate = 200;
   $reloadRate = 1;
   $padWaitTime = 45;
   $zenWaitTime = 60;
   $EnergyBoostReady = True;
   $EnergyBoost = getObjectId("MissionGroup/special/EnergyBoost");
   %t = randomInt($minEruptTime,$maxEruptTime);
   echo("Next Eruption - "@%t@"s");
   schedule("eruption();",%t);
}