/*************************************************
 * Decompiled by Serious and Edited by SyndiShanX
 * Script: zm\zm_genesis_radios.gsc
*************************************************/

#using scripts\codescripts\struct;
#using scripts\shared\ai\systems\gib;
#using scripts\shared\ai\zombie_utility;
#using scripts\shared\animation_shared;
#using scripts\shared\array_shared;
#using scripts\shared\callbacks_shared;
#using scripts\shared\challenges_shared;
#using scripts\shared\clientfield_shared;
#using scripts\shared\exploder_shared;
#using scripts\shared\flag_shared;
#using scripts\shared\laststand_shared;
#using scripts\shared\math_shared;
#using scripts\shared\scoreevents_shared;
#using scripts\shared\system_shared;
#using scripts\shared\util_shared;
#using scripts\zm\_zm_devgui;
#using scripts\zm\_zm_equipment;
#using scripts\zm\_zm_score;
#using scripts\zm\_zm_stats;
#using scripts\zm\_zm_unitrigger;
#using scripts\zm\_zm_utility;
#using scripts\zm\_zm_weapons;
#using scripts\zm\_zm_zonemgr;
#using scripts\zm\zm_genesis_util;
#using scripts\zm\zm_genesis_vo;
#namespace zm_genesis_radios;

function autoexec __init__sytem__() {
  system::register("zm_genesis_radios", &__init__, &__main__, undefined);
}

function __init__() {
  callback::on_disconnect(&on_player_disconnect);
}

function __main__() {
  level thread function_9ef4291();
  level waittill("start_zombie_round_logic");
  level thread function_a999a42a();
}

function on_player_disconnect() {}

function function_a999a42a() {
  level.var_66b7ed7e = [];
  level.var_22e09be4 = [];
  level.var_22e09be4["divine_comedy"] = array("vox_abcd_excerpt_divine_0");
  level.var_22e09be4["theatre"] = array("vox_abcd_excerpt_tempest_0");
  level.var_22e09be4["asylum"] = array("vox_sfx_radio_stem_verruckt_0");
  level.var_22e09be4["mob"] = array("vox_sfx_radio_stem_mob_log_1_0", "vox_sfx_radio_stem_mob_log_2_0", "vox_sfx_radio_stem_mob_log_3_0");
  level.var_22e09be4["trenches"] = array("vox_sfx_radio_stem_origins_log_0");
  level.var_22e09be4["romeros_assistant"] = array("vox_sall_shangri_log_1_0", "vox_sall_shangri_log_2_0", "vox_sall_shangri_log_3_0", "vox_sfx_radio_stem_shangri_log_4_0");
  level.var_22e09be4["island"] = array("vox_sfx_radio_stem_shinonuma_log_0");
  level.var_22e09be4["mcnamara"] = array("vox_nama_namara_log_0");
  a_s_radios = struct::get_array("s_radio", "targetname");
  level.a_s_radios = array::sort_by_script_int(a_s_radios, 1);
  var_64dfb3ba = getEntArray("clip_radio", "targetname");
  var_a399b51e = array::sort_by_script_int(var_64dfb3ba, 1);
  var_ff34523e = array(5, 8, 10, 11, 12, 13);
  for(i = 0; i < level.a_s_radios.size; i++) {
    level.a_s_radios[i].clip = arraygetclosest(level.a_s_radios[i].origin, var_64dfb3ba);
    s_unitrigger = level.a_s_radios[i] zm_unitrigger::create_unitrigger(&"", 64, &function_2c776a2a);
    s_unitrigger.require_look_at = 1;
    s_unitrigger.b_on = 1;
    level.a_s_radios[i] thread function_795f4e6();
    var_32be5a3 = i + 1;
    if(isinarray(var_ff34523e, var_32be5a3)) {
      level.a_s_radios[i] thread function_35f4f25f();
    }
  }
}

function function_2c776a2a(e_player) {
  if(isDefined(self.stub.b_on) && self.stub.b_on) {
    self sethintstring("");
    return true;
  }
  self sethintstring("");
  return false;
}

function function_795f4e6() {
  self endon("hash_e37d497d");
  while(true) {
    self waittill("trigger_activated", e_user);
    if(isPlayer(e_user) && !level flag::get("abcd_speaking") && !level flag::get("sophia_speaking") && !level flag::get("shadowman_speaking") && !self function_94b3b616()) {
      self thread function_66d50897("trigger");
      return;
    }
  }
}

function function_35f4f25f() {
  self endon("hash_e37d497d");
  self endon("hash_27f23694");
  self.clip setCanDamage(1);
  var_b1c8a081 = 0;
  while(!var_b1c8a081) {
    self.clip waittill("damage", n_amount, e_attacker, v_org, v_dir, str_mod);
    if(isPlayer(e_attacker) && !level flag::get("abcd_speaking") && !level flag::get("sophia_speaking") && !level flag::get("shadowman_speaking") && !self function_94b3b616()) {
      var_b1c8a081 = 1;
      self thread function_66d50897("damage");
    } else {
      self.clip.health = 100000;
    }
  }
}

function function_66d50897(var_ffc8395e) {
  if(self.s_unitrigger.b_on) {
    self notify("hash_e37d497d");
    self.clip setCanDamage(0);
    self.s_unitrigger.b_on = 0;
    zm_unitrigger::unregister_unitrigger(self);
    var_3c13e11b = self.script_noteworthy;
    if(level.var_22e09be4[var_3c13e11b].size) {
      str_vo = level.var_22e09be4[var_3c13e11b][0];
      if(isDefined(str_vo)) {
        if(var_ffc8395e == "damage") {
          var_c46d7830 = self.clip.origin;
        } else {
          var_c46d7830 = self.origin;
        }
        array::add(level.var_66b7ed7e, self, 0);
        arrayremoveindex(level.var_22e09be4[var_3c13e11b], 0);
        var_5cd02106 = soundgetplaybacktime(str_vo);
        if(var_5cd02106 > 0) {
          var_269117b2 = var_5cd02106 / 1000;
          playsoundatposition(str_vo, var_c46d7830);
          wait(var_269117b2);
        }
        arrayremovevalue(level.var_66b7ed7e, self);
      }
    }
  }
}

function function_94b3b616(n_range = 800) {
  if(level.var_66b7ed7e.size == 0) {
    return 0;
  }
  var_f39e4895 = arraygetclosest(self.origin, level.var_66b7ed7e);
  if(isDefined(var_f39e4895)) {
    n_dist = distance(self.origin, var_f39e4895.origin);
    return n_dist <= n_range;
  }
  return 0;
}

function function_9ef4291() {
  level thread zm_genesis_util::setup_devgui_func("", "", 1, &function_418d5e87);
  level thread zm_genesis_util::setup_devgui_func("", "", 1, &function_dda18b8e);
  level thread zm_genesis_util::setup_devgui_func("", "", 2, &function_418d5e87);
  level thread zm_genesis_util::setup_devgui_func("", "", 2, &function_dda18b8e);
  level thread zm_genesis_util::setup_devgui_func("", "", 3, &function_418d5e87);
  level thread zm_genesis_util::setup_devgui_func("", "", 3, &function_dda18b8e);
  level thread zm_genesis_util::setup_devgui_func("", "", 4, &function_418d5e87);
  level thread zm_genesis_util::setup_devgui_func("", "", 4, &function_dda18b8e);
  level thread zm_genesis_util::setup_devgui_func("", "", 5, &function_418d5e87);
  level thread zm_genesis_util::setup_devgui_func("", "", 5, &function_dda18b8e);
  level thread zm_genesis_util::setup_devgui_func("", "", 6, &function_418d5e87);
  level thread zm_genesis_util::setup_devgui_func("", "", 6, &function_dda18b8e);
  level thread zm_genesis_util::setup_devgui_func("", "", 7, &function_418d5e87);
  level thread zm_genesis_util::setup_devgui_func("", "", 7, &function_dda18b8e);
  level thread zm_genesis_util::setup_devgui_func("", "", 8, &function_418d5e87);
  level thread zm_genesis_util::setup_devgui_func("", "", 8, &function_dda18b8e);
  level thread zm_genesis_util::setup_devgui_func("", "", 9, &function_418d5e87);
  level thread zm_genesis_util::setup_devgui_func("", "", 9, &function_dda18b8e);
  level thread zm_genesis_util::setup_devgui_func("", "", 10, &function_418d5e87);
  level thread zm_genesis_util::setup_devgui_func("", "", 10, &function_dda18b8e);
  level thread zm_genesis_util::setup_devgui_func("", "", 11, &function_418d5e87);
  level thread zm_genesis_util::setup_devgui_func("", "", 11, &function_dda18b8e);
  level thread zm_genesis_util::setup_devgui_func("", "", 12, &function_418d5e87);
  level thread zm_genesis_util::setup_devgui_func("", "", 12, &function_dda18b8e);
  level thread zm_genesis_util::setup_devgui_func("", "", 13, &function_418d5e87);
  level thread zm_genesis_util::setup_devgui_func("", "", 13, &function_dda18b8e);
}

function function_dda18b8e(n_val) {
  level.a_s_radios[n_val - 1] thread function_66d50897();
}

function function_418d5e87(n_val) {
  str_dest = "" + n_val;
  s_dest = struct::get(str_dest);
  if(isDefined(s_dest)) {
    player = level.activeplayers[0];
    var_5d8a4d6d = util::spawn_model("", player.origin, player.angles);
    player linkto(var_5d8a4d6d);
    var_5d8a4d6d.origin = s_dest.origin;
    wait(0.5);
    player unlink();
    var_5d8a4d6d delete();
  }
}