//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// ACCM Randomized Events - Made by Blnukem.
//------------------------------------------------------------------------------
// NOTICE:
// • This script is public, just like the "Natural Weather" script. (Weather.cs)
// • If this script is used in any way, please give credit to it's creator.
// • More information is at the bottom of this script.
// • This script is predicted to update and grow over time.
//------------------------------------------------------------------------------
// Primary Event Function:
//------------------------------------------------------------------------------

function Events(%args) {

   if(($CurrentMission $= "Affliction") && ($Host::PureBuild == 1)) { // This check is not really needed, it's just a precaution.
      Error("Error: The Random event script attempted to initiate with Purebuild enabled.");
      Cancel($Event);
      Cancel($Reset);
      return;
   } else if(($CurrentMission !$= "Affliction") || (Game.class !$= "InfectionGame")) { // Just a precaution.
      return;
   } else if(!isFile("Scripts/ModScripts/EventTypes.cs") && ($CurrentMission $= "Affliction")) { // Missing the EventTypes file? If so, change the mission.
      cycleMissions();
      messageAll("", "\c2The mission was changed because the Event Types file is missing. ~wvoice/Announcer/ANN.gameover.wav");
      Error("Major Error: The event types file is missing.");
      return;
   }

   if(%args $= "Cancel") { // Lets kill the looping.
      Warn("Random Events have been cancelled");
      Cancel($Event);
      Cancel($Reset);
      return;
   } else if(%args $= "Reset") { // Disable the event-based zombie points when the event is finished.
      KillEvents();
      return;
   }

   if(%args $= "RandomEvents" && $CurrentMission $= "Affliction") {
      $Event = Schedule(60000*9, 0, "Events", "RandomEvents");
      %cycle = getRandom(1, 10); // Time to make significant events fairly rare.
   if(%cycle == 2) {
      Schedule(60000*5, 0, "Events", "Reset");
      $Reset = Schedule(60000*6, 0, "Events", "Reset");
      AfflictionMediumAttack();
      Schedule(0, 0, "MessageAll", "", "\c2INCOMING TRANSMISSION :: \c0Transmitting data from Central Command... ~wvoice/Training/Any/ANY.incoming_msg.wav");
      Schedule(3000, 0, "MessageAll", "", "\c2CENTRAL COMMAND :: \c0A moderate number of zombies have been detected nearing the Caldera Outpost. ~wvoice/Training/Mission4/T4_07.wav");
   } else if(%cycle == 3) {
      $Reset = Schedule(60000*8, 0, "Events", "Reset");
      AfflictionHeavyAttack();
      Schedule(0, 0, "MessageAll", "", "\c2INCOMING TRANSMISSION :: \c0Transmitting data from Central Command... ~wvoice/Training/Any/ANY.incoming_msg.wav");
      Schedule(3000, 0, "MessageAll", "", "\c2CENTRAL COMMAND :: \c0A large number of zombies have been detected nearing the Caldera Outpost. ~wvoice/Training/Mission4/T4_07.wav");
   } else if(%cycle == 4) {
      $Reset = Schedule(60000*4, 0, "Events", "Reset");
      AfflictionRapierAttack();
      Schedule(0, 0, "MessageAll", "", "\c2INCOMING TRANSMISSION :: \c0Transmitting data from Central Command... ~wvoice/Training/Any/ANY.incoming_msg.wav");
      Schedule(3000, 0, "MessageAll", "", "\c2CENTRAL COMMAND :: \c0A group of Rapier zombies have been detected nearing the Caldera Outpost. ~wvoice/Training/Mission4/T4_07.wav");
   } else if(%cycle == 5) {
      $Reset = Schedule(60000*1, 0, "Events", "Reset");
      AfflictionDemonMotherSpawn();
      Schedule(0, 0, "MessageAll", "", "\c2INCOMING TRANSMISSION :: \c0Transmitting data from Central Command... ~wvoice/Training/Any/ANY.incoming_msg.wav");
      Schedule(3000, 0, "MessageAll", "", "\c2CENTRAL COMMAND :: \c0Warning... A demon mother has been sighted somewhere in the vicinity of the Caldera Outpost. ~wvoice/Training/Any/ANY.careful.wav");
   } else if(%cycle == 6) {
      $Reset = Schedule(60000*1, 0, "Events", "Reset");
      AfflictionDemonSpawns();
      Schedule(0, 0, "MessageAll", "", "\c2INCOMING TRANSMISSION :: \c0Transmitting data from Central Command... ~wvoice/Training/Any/ANY.incoming_msg.wav");
      Schedule(3000, 0, "MessageAll", "", "\c2CENTRAL COMMAND :: \c0A group of Demon zombies have been detected nearing the Caldera Outpost. ~wvoice/Training/Mission4/T4_07.wav");
   } else {
      Nothing();
      return;
   }
   }
}

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Event Sub-Functions
//------------------------------------------------------------------------------
// Basic "Kill" function to disable event spawns:
//------------------------------------------------------------------------------

function KillEvents() { // Lets disable any event spawns. Sloppy, but affective.
   Call("DisableSpawn", "EventSpawn01");
   Call("DisableSpawn", "EventSpawn02");
   Call("DisableSpawn", "EventSpawn03");
   Call("DisableSpawn", "EventSpawn04");
   Call("DisableSpawn", "EventSpawn05");
   Call("DisableSpawn", "EventSpawn06");
   Call("DisableSpawn", "EventSpawn07");
   Call("DisableSpawn", "EventSpawn08");
   Call("DisableSpawn", "EventSpawn09");
   Call("DisableSpawn", "EventSpawn10");
   Call("DisableSpawn", "EventSpawn11");
   Call("DisableSpawn", "EventSpawn12");
   Call("DisableSpawn", "EventSpawn13");
   Call("DisableSpawn", "EventSpawn14");
   Call("DisableSpawn", "EventSpawn15");
   Call("DisableSpawn", "EventSpawn16");
   Call("DisableSpawn", "EventSpawn17");
   Call("DisableSpawn", "EventSpawn18");
   Call("DisableSpawn", "EventSpawn19");
   Call("DisableSpawn", "EventSpawn20");
   Call("DisableSpawn", "EventRSpawn01");
   Call("DisableSpawn", "EventRSpawn02");
   Call("DisableSpawn", "EventRSpawn03");
   Call("DisableSpawn", "EventRSpawn04");
   Call("DisableSpawn", "EventRSpawn05");
   Call("DisableSpawn", "EventRSpawn06");
   Call("DisableSpawn", "EventRSpawn07");
   Call("DisableSpawn", "EventRSpawn08");
   Call("DisableSpawn", "EventRSpawn09");
   Call("DisableSpawn", "EventRSpawn10");
   Call("DisableSpawn", "EventSpecialSpawn01");
   Call("DisableSpawn", "EventSpecialSpawn02");
   Call("DisableSpawn", "EventSpecialSpawn03");
   Call("DisableSpawn", "EventSpecialSpawn04");
   Call("DisableSpawn", "EventSpecialSpawn05");
      return;
}

//------------------------------------------------------------------------------
// Begins the mission scenario: (This is activated in defaultGame.cs)
//------------------------------------------------------------------------------

function BeginScenario() {

   Call("Events", "Reset");
   %grp = nameToID("MissionCleanup/ZombieGroup");
   %count = %grp.getCount();
   for(%i = 0; %i < %count; %i++) {
      %obj = %grp.getObject(%i);
   if(isObject(%obj)) {
      if(%obj.infected || strstr(%obj.getDatablock().getName(), "Zombie") != -1) {
      %obj.infected = 0;
      %obj.scriptkill($DamageType::Idiocy);
   }

   cls();
   Error("Cleaning mission of improperly spawned zombies.");
   Warn("Zombies are spawned and the mission scenario is ready.");
   Call("WeatherCycle", "Initiate");
   Schedule(200000, 0, "Events", "RandomEvents");
   return;

   }
}

//------------------------------------------------------------------------------
// Lets the server control the Zombie spawn points:
//------------------------------------------------------------------------------

function EnableSpawn(%args) {

   if(Game.class $= "ConstructionGame") {
      return;
   }

   if(Game.class $= "ZombieGame") {
      return;
   }

   if(%args $= "") {
      return;
   }

   %obj = zombieSpawnByName(%args);
   if(%obj == 0) {
      return;
   }

   %obj.disabled = 0;
   %obj.spawnedZombies = 0;
   %obj.StartSpawnLoop();
}

function DisableSpawn(%args) {

   if(Game.class $= "ConstructionGame") {
      return;
   }

   if(Game.class $= "ZombieGame") {
      return;
   }

   if(%args $= "") {
      return;
   }

   %obj = zombieSpawnByName(%args);
   if(%obj == 0) {
      return;
   }

   %obj.disabled = 1;
   if(isEventPending(%obj.zombieLoop))
      cancel(%obj.zombieLoop);

   %obj.zombieLoop = "";
}

function DisableAllSpawns() {

   if(Game.class $= "ConstructionGame") {
      return;
   }

   if(Game.class $= "ZombieGame" && !%sender.isMapAdmin) {
      return;
   }

   %grp = nameToId("MissionCleanup/ZombiePoints");
   for(%i = 0; %i < %grp.getCount(); %i++) {
      %obj = %grp.getObject(%i);
      if(isEventPending(%obj.zombieLoop))
         cancel(%obj.zombieLoop);
      %obj.disabled = 1;
   }
}
