/*************************************************
 * Decompiled by Serious and Edited by SyndiShanX
 * Script: zm\zm_cosmodrome.csc
*************************************************/

#using scripts\codescripts\struct;
#using scripts\shared\array_shared;
#using scripts\shared\audio_shared;
#using scripts\shared\callbacks_shared;
#using scripts\shared\clientfield_shared;
#using scripts\shared\exploder_shared;
#using scripts\shared\scene_shared;
#using scripts\shared\util_shared;
#using scripts\shared\visionset_mgr_shared;
#using scripts\zm\_load;
#using scripts\zm\_zm;
#using scripts\zm\_zm_ai_monkey;
#using scripts\zm\_zm_audio;
#using scripts\zm\_zm_audio_zhd;
#using scripts\zm\_zm_pack_a_punch;
#using scripts\zm\_zm_perk_additionalprimaryweapon;
#using scripts\zm\_zm_perk_deadshot;
#using scripts\zm\_zm_perk_doubletap2;
#using scripts\zm\_zm_perk_juggernaut;
#using scripts\zm\_zm_perk_quick_revive;
#using scripts\zm\_zm_perk_random;
#using scripts\zm\_zm_perk_sleight_of_hand;
#using scripts\zm\_zm_perk_staminup;
#using scripts\zm\_zm_perk_widows_wine;
#using scripts\zm\_zm_powerup_carpenter;
#using scripts\zm\_zm_powerup_double_points;
#using scripts\zm\_zm_powerup_fire_sale;
#using scripts\zm\_zm_powerup_free_perk;
#using scripts\zm\_zm_powerup_full_ammo;
#using scripts\zm\_zm_powerup_insta_kill;
#using scripts\zm\_zm_powerup_nuke;
#using scripts\zm\_zm_powerup_weapon_minigun;
#using scripts\zm\_zm_trap_fire;
#using scripts\zm\_zm_utility;
#using scripts\zm\_zm_weap_black_hole_bomb;
#using scripts\zm\_zm_weap_bouncingbetty;
#using scripts\zm\_zm_weap_thundergun;
#using scripts\zm\_zm_weapons;
#using scripts\zm\zm_cosmodrome_amb;
#using scripts\zm\zm_cosmodrome_ffotd;
#using scripts\zm\zm_cosmodrome_fx;
#namespace zm_cosmodrome;

function autoexec opt_in() {
  level.aat_in_use = 1;
  level.bgb_in_use = 1;
}

function main() {
  zm_cosmodrome_ffotd::main_start();
  level.default_game_mode = "zclassic";
  level.default_start_location = "default";
  level._power_on = 0;
  level.rocket_num = 0;
  level.var_f2fba834 = 0;
  level.var_90e9447c = 0;
  level.intro_done = 0;
  include_weapons();
  callback::on_localclient_connect(&function_82a94b2c);
  register_client_fields();
  zm_cosmodrome_fx::main();
  level thread zm_cosmodrome_amb::main();
  level.setupcustomcharacterexerts = &setup_personality_character_exerts;
  visionset_mgr::register_visionset_info("zm_cosmodrome_no_power", 21000, 31, undefined, "zombie_cosmodrome_nopower");
  visionset_mgr::register_visionset_info("zm_cosmodrome_power_antic", 21000, 31, undefined, "zombie_cosmodrome_power_antic");
  visionset_mgr::register_visionset_info("zm_cosmodrome_power_flare", 21000, 31, undefined, "zombie_cosmodrome_power_flare");
  visionset_mgr::register_visionset_info("zm_cosmodrome_monkey_on", 21000, 31, undefined, "zombie_cosmodrome_monkey");
  visionset_mgr::register_visionset_info("zm_cosmodrome_monkey_off", 21000, 31, undefined, "zombie_cosmodrome_monkey");
  load::main();
  level thread setup_fog();
  level init_cosmodrome_box_screens();
  util::waitforclient(0);
  level thread radar_dish_init();
  level.nml_spark_pull = struct::get("nml_spark_pull", "targetname");
  function_6ac83719();
  level thread function_d87a7dcc();
  zm_cosmodrome_ffotd::main_end();
}

function function_82a94b2c(localclientnum) {
  setsaveddvar("phys_buoyancy", 1);
  level thread function_85c8e13c(localclientnum);
}

function function_85c8e13c(localclientnum) {
  self endon("disconnect");
  while(true) {
    var_f4570d42 = randomint(5);
    switch (var_f4570d42) {
      case 0: {
        exploder::exploder("fxexp_4100", localclientnum);
        setukkoscriptindex(localclientnum, 2, 1);
        wait(0.05);
        setukkoscriptindex(localclientnum, 3, 1);
        wait(0.1);
        setukkoscriptindex(localclientnum, 4, 1);
        wait(0.05);
        setukkoscriptindex(localclientnum, 5, 1);
        wait(0.1);
        setukkoscriptindex(localclientnum, 4, 1);
        wait(0.05);
        setukkoscriptindex(localclientnum, 3, 1);
        wait(0.05);
        setukkoscriptindex(localclientnum, 4, 1);
        wait(0.1);
        setukkoscriptindex(localclientnum, 3, 1);
        wait(0.05);
        setukkoscriptindex(localclientnum, 4, 1);
        wait(0.05);
        setukkoscriptindex(localclientnum, 6, 1);
        wait(0.05);
        setukkoscriptindex(localclientnum, 4, 1);
        wait(0.05);
        setukkoscriptindex(localclientnum, 5, 1);
        wait(0.1);
        setukkoscriptindex(localclientnum, 6, 1);
        wait(0.05);
        setukkoscriptindex(localclientnum, 7, 1);
        wait(0.05);
        break;
      }
      case 1: {
        exploder::exploder("fxexp_4200", localclientnum);
        setukkoscriptindex(localclientnum, 8, 1);
        wait(0.05);
        setukkoscriptindex(localclientnum, 9, 1);
        wait(0.1);
        setukkoscriptindex(localclientnum, 10, 1);
        wait(0.05);
        setukkoscriptindex(localclientnum, 11, 1);
        wait(0.1);
        setukkoscriptindex(localclientnum, 10, 1);
        wait(0.1);
        setukkoscriptindex(localclientnum, 11, 1);
        wait(0.05);
        setukkoscriptindex(localclientnum, 12, 1);
        wait(0.1);
        setukkoscriptindex(localclientnum, 13, 1);
        wait(0.05);
        setukkoscriptindex(localclientnum, 14, 1);
        wait(0.1);
        break;
      }
      case 2: {
        exploder::exploder("fxexp_4300", localclientnum);
        setukkoscriptindex(localclientnum, 15, 1);
        wait(0.1);
        setukkoscriptindex(localclientnum, 16, 1);
        wait(0.1);
        setukkoscriptindex(localclientnum, 17, 1);
        wait(0.1);
        setukkoscriptindex(localclientnum, 18, 1);
        wait(0.1);
        setukkoscriptindex(localclientnum, 19, 1);
        wait(0.1);
        setukkoscriptindex(localclientnum, 20, 1);
        wait(0.1);
        setukkoscriptindex(localclientnum, 21, 1);
        wait(0.1);
        break;
      }
      case 3: {
        exploder::exploder("fxexp_4400", localclientnum);
        setukkoscriptindex(localclientnum, 22, 1);
        wait(0.1);
        setukkoscriptindex(localclientnum, 23, 1);
        wait(0.1);
        setukkoscriptindex(localclientnum, 24, 1);
        wait(0.1);
        setukkoscriptindex(localclientnum, 25, 1);
        wait(0.1);
        setukkoscriptindex(localclientnum, 26, 1);
        wait(0.1);
        break;
      }
      case 4: {
        exploder::exploder("fxexp_4500", localclientnum);
        setukkoscriptindex(localclientnum, 29, 1);
        wait(0.15);
        setukkoscriptindex(localclientnum, 30, 1);
        wait(0.05);
        setukkoscriptindex(localclientnum, 29, 1);
        wait(0.05);
        setukkoscriptindex(localclientnum, 31, 1);
        wait(0.05);
        setukkoscriptindex(localclientnum, 30, 1);
        wait(0.15);
        setukkoscriptindex(localclientnum, 29, 1);
        wait(0.05);
        setukkoscriptindex(localclientnum, 30, 1);
        wait(0.1);
        setukkoscriptindex(localclientnum, 29, 1);
        wait(0.1);
        setukkoscriptindex(localclientnum, 31, 1);
        wait(0.05);
        setukkoscriptindex(localclientnum, 27, 1);
        wait(0.05);
        setukkoscriptindex(localclientnum, 28, 1);
        wait(0.1);
        setukkoscriptindex(localclientnum, 29, 1);
        wait(0.05);
        setukkoscriptindex(localclientnum, 30, 1);
        wait(0.05);
        setukkoscriptindex(localclientnum, 29, 1);
        wait(0.05);
        setukkoscriptindex(localclientnum, 31, 1);
        wait(0.05);
        setukkoscriptindex(localclientnum, 30, 1);
        wait(0.15);
        setukkoscriptindex(localclientnum, 29, 1);
        wait(0.05);
        setukkoscriptindex(localclientnum, 30, 1);
        wait(0.1);
        setukkoscriptindex(localclientnum, 29, 1);
        wait(0.1);
        setukkoscriptindex(localclientnum, 31, 1);
        wait(0.05);
        setukkoscriptindex(localclientnum, 32, 1);
        wait(0.05);
        break;
      }
      default: {
        break;
      }
    }
    setukkoscriptindex(localclientnum, 1, 1);
    n_wait_time = randomintrange(2, 4);
    wait(n_wait_time);
  }
}

function function_6ac83719() {
  visionset_mgr::init_fog_vol_to_visionset_monitor("zombie_cosmodrome", 0.01);
  visionset_mgr::fog_vol_to_visionset_set_suffix("");
  visionset_mgr::fog_vol_to_visionset_set_info(0, "zombie_cosmodrome");
}

function function_c07d3f2c(localclientnum, oldval, newval, bnewent, binitialsnap, fieldname, bwasdemojump) {
  if(newval) {
    player = getlocalplayers()[localclientnum];
    player set_fog("normal");
    visionset_mgr::fog_vol_to_visionset_set_suffix("_nopower");
    visionset_mgr::fog_vol_to_visionset_set_info(0, "zombie_cosmodrome", 8.5);
    level.intro_done = 1;
  }
}

function function_d0429093(localclientnum, oldval, newval, bnewent, binitialsnap, fieldname, bwasdemojump) {
  if(newval) {
    if(isDefined(level.intro_done) && !level.intro_done) {
      level.intro_done = 1;
      player = getlocalplayers()[localclientnum];
      player set_fog("normal");
      wait(0.01);
      visionset_mgr::fog_vol_to_visionset_set_suffix("_nopower");
      visionset_mgr::fog_vol_to_visionset_set_info(0, "zombie_cosmodrome", 0.01);
    }
  }
}

function function_e470dce(localclientnum, oldval, newval, bnewent, binitialsnap, fieldname, bwasdemojump) {
  if(newval) {
    level.var_f2fba834 = 1;
    if(isDefined(level._power_on) && !level._power_on) {
      level._power_on = 1;
      level thread setup_lander_screens(localclientnum);
    }
    player = getlocalplayers()[localclientnum];
    player earthquake(0.2, 5, player.origin, 20000);
    playSound(0, "zmb_ape_intro_sonicboom_fnt", (0, 0, 0));
    level._effect["eye_glow"] = level._effect["monkey_eye_glow"];
    e_player = getlocalplayers()[localclientnum];
    e_player set_fog("monkey");
  }
}

function function_87f08b47(localclientnum, oldval, newval, bnewent, binitialsnap, fieldname, bwasdemojump) {
  if(newval) {
    level.var_f2fba834 = 0;
    if(isDefined(level._power_on) && !level._power_on) {
      level._power_on = 1;
      level thread setup_lander_screens(localclientnum);
    }
    player = getlocalplayers()[localclientnum];
    player set_fog("normal");
    wait(0.01);
    visionset_mgr::fog_vol_to_visionset_set_suffix("_poweron");
    visionset_mgr::fog_vol_to_visionset_set_info(0, "zombie_cosmodrome", 0.01);
    level._effect["eye_glow"] = level._effect["zombie_eye_glow"];
  }
}

function function_2f143630(var_54168c72, var_f8308617, n_wait, var_2e141209, var_862916dc) {
  visionset_mgr::fog_vol_to_visionset_set_suffix(var_54168c72);
  visionset_mgr::fog_vol_to_visionset_set_info(0, "zombie_cosmodrome", var_f8308617);
  wait(n_wait);
  visionset_mgr::fog_vol_to_visionset_set_suffix(var_2e141209);
  visionset_mgr::fog_vol_to_visionset_set_info(0, "zombie_cosmodrome", var_862916dc);
}

function function_ea758913() {
  if(isDefined(level.var_f2fba834) && level.var_f2fba834 && isDefined(level.var_90e9447c) && !level.var_90e9447c) {
    level.var_90e9447c = 1;
    self function_2f143630("_monkey_flare", 0.5, 0.5, "_monkey", 3);
    level.var_90e9447c = 0;
  }
}

function register_client_fields() {
  clientfield::register("scriptmover", "zombie_has_eyes", 21000, 1, "int", &zm::zombie_eyes_clientfield_cb, 0, 0);
  clientfield::register("actor", "COSMO_SOULPULL", 21000, 1, "int", &actor_flag_soulpull_handler, 0, 0);
  clientfield::register("scriptmover", "COSMO_ROCKET_FX", 21000, 1, "int", &rocket_fx, 0, 0);
  clientfield::register("scriptmover", "COSMO_MONKEY_LANDER_FX", 21000, 1, "int", &monkey_lander_fx, 0, 0);
  clientfield::register("world", "COSMO_EGG_SAM_ANGRY", 21000, 1, "int", &samantha_is_angry, 0, 0);
  clientfield::register("scriptmover", "COSMO_LANDER_ENGINE_FX", 21000, 1, "int", &lander_engine_fx, 0, 0);
  clientfield::register("allplayers", "COSMO_PLAYER_LANDER_FOG", 21000, 1, "int", &player_lander_fog, 0, 0);
  clientfield::register("scriptmover", "COSMO_LANDER_MOVE_FX", 21000, 1, "int", &lander_move_fx, 0, 0);
  clientfield::register("scriptmover", "COSMO_LANDER_RUMBLE_AND_QUAKE", 21000, 1, "int", &lander_rumble_and_quake, 0, 0);
  clientfield::register("world", "COSMO_LANDER_STATUS_LIGHTS", 21000, 2, "int", &function_32db5393, 0, 0);
  clientfield::register("world", "COSMO_LANDER_STATION", 21000, 3, "int", &function_446c53e5, 0, 0);
  clientfield::register("world", "COSMO_LANDER_DEST", 21000, 3, "int", &function_f6ffc831, 0, 0);
  clientfield::register("world", "COSMO_LANDER_CATWALK_BAY", 21000, 3, "int", &function_89e03497, 0, 0);
  clientfield::register("world", "COSMO_LANDER_BASE_ENTRY_BAY", 21000, 3, "int", &function_429d7872, 0, 0);
  clientfield::register("world", "COSMO_LANDER_CENTRIFUGE_BAY", 21000, 3, "int", &function_7eaa1812, 0, 0);
  clientfield::register("world", "COSMO_LANDER_STORAGE_BAY", 21000, 3, "int", &function_686d40af, 0, 0);
  clientfield::register("scriptmover", "COSMO_LAUNCH_PANEL_CENTRIFUGE_STATUS", 21000, 1, "int", &launch_panel_centrifuge_status, 0, 0);
  clientfield::register("scriptmover", "COSMO_LAUNCH_PANEL_BASEENTRY_STATUS", 21000, 1, "int", &launch_panel_baseentry_status, 0, 0);
  clientfield::register("scriptmover", "COSMO_LAUNCH_PANEL_STORAGE_STATUS", 21000, 1, "int", &launch_panel_storage_status, 0, 0);
  clientfield::register("scriptmover", "COSMO_LAUNCH_PANEL_CATWALK_STATUS", 21000, 1, "int", &launch_panel_catwalk_status, 0, 0);
  clientfield::register("scriptmover", "COSMO_CENTRIFUGE_RUMBLE", 21000, 1, "int", &centrifuge_rumble_control, 0, 0);
  clientfield::register("scriptmover", "COSMO_CENTRIFUGE_LIGHTS", 21000, 1, "int", &centrifuge_warning_lights_init, 0, 0);
  clientfield::register("world", "COSMO_VISIONSET_BEGIN", 21000, 1, "int", &function_c07d3f2c, 0, 0);
  clientfield::register("world", "COSMO_VISIONSET_NOPOWER", 21000, 1, "int", &function_d0429093, 0, 0);
  clientfield::register("world", "COSMO_VISIONSET_POWERON", 21000, 1, "int", &function_87f08b47, 0, 0);
  clientfield::register("world", "COSMO_VISIONSET_MONKEY", 21000, 1, "int", &function_e470dce, 0, 0);
}

function function_d87a7dcc() {
  var_bd7ba30 = 0;
  while(true) {
    if(!level clientfield::get("zombie_power_on")) {
      if(var_bd7ba30) {
        level notify("power_controlled_light");
      }
      level util::waittill_any("power_on", "pwr", "ZPO");
    }
    level._power_on = 1;
    level notify("power_controlled_light");
    players = getlocalplayers();
    for(i = 0; i < players.size; i++) {
      level thread setup_lander_screens(i);
    }
    level function_2f143630("_powerup", 0.1, 1, "_poweron", 2.5);
    level util::waittill_any("pwo", "ZPOff");
    var_bd7ba30 = 1;
  }
}

function include_weapons() {
  zm_weapons::load_weapon_spec_from_table("gamedata/weapons/zm/zm_cosmodrome_weapons.csv", 1);
}

function radar_dish_init() {
  radar_dish = getEntArray(0, "zombie_cosmodrome_radar_dish", "targetname");
  if(isDefined(radar_dish)) {
    for(i = 0; i < radar_dish.size; i++) {
      radar_dish[i] thread radar_dish_rotate();
    }
  }
}

function radar_dish_rotate() {
  wait(0.1);
  while(true) {
    self rotateyaw(360, 10);
    self waittill("rotatedone");
  }
}

function perk_wire_fx_client(client_num, done_notify) {
  println("" + client_num);
  targ = struct::get(self.target, "targetname");
  if(!isDefined(targ)) {
    return;
  }
  mover = spawn(client_num, targ.origin, "script_model");
  mover setModel("tag_origin");
  fx = playFXOnTag(client_num, level._effect["wire_spark"], mover, "tag_origin");
  while(isDefined(targ)) {
    if(isDefined(targ.target)) {
      println((("" + client_num) + "") + targ.target);
      target = struct::get(targ.target, "targetname");
      mover moveto(target.origin, 0.5);
      wait(0.5);
      targ = target;
    } else {
      break;
    }
  }
  level notify("spark_done");
  mover delete();
  level notify(done_notify);
}

function tele_spark_audio_mover(fake_ent) {
  level endon("spark_done");
  while(true) {
    wait(0.05);
  }
}

function actor_flag_soulpull_handler(localclientnum, oldval, newval, bnewent, binitialsnap, fieldname, bwasdemojump) {
  if(newval) {
    self thread soul_pull(localclientnum);
  }
}

function soul_pull(client_num) {
  println((("" + self.origin) + "") + level.nml_spark_pull.origin);
  mover = spawn(client_num, self.origin, "script_model");
  mover setModel("tag_origin");
  fx = playFXOnTag(client_num, level._effect["soul_spark"], mover, "tag_origin");
  wait(1);
  mover moveto(level.nml_spark_pull.origin, 3);
  wait(3);
  mover delete();
}

function init_cosmodrome_box_screens() {
  level._cosmodrome_fire_sale = array("p7_zm_asc_cam_monitor_screen_fsale1", "p7_zm_asc_cam_monitor_screen_fsale2");
  level.magic_box_tv_off = array("p7_zm_asc_cam_monitor_screen_off");
  level.magic_box_tv_on = array("p7_zm_asc_cam_monitor_screen_on");
  level.magic_box_tv_start_1 = array("p7_zm_asc_cam_monitor_screen_obsdeck");
  level.magic_box_tv_roof_connector = array("p7_zm_asc_cam_monitor_screen_labs");
  level.magic_box_tv_centrifuge = array("p7_zm_asc_cam_monitor_screen_centrifuge");
  level.magic_box_tv_base_entry = array("p7_zm_asc_cam_monitor_screen_enter");
  level.magic_box_tv_storage = array("p7_zm_asc_cam_monitor_screen_storage");
  level.magic_box_tv_catwalks = array("p7_zm_asc_cam_monitor_screen_catwalk");
  level.magic_box_tv_north_pass = array("p7_zm_asc_cam_monitor_screen_topack");
  level.magic_box_tv_warehouse = array("p7_zm_asc_cam_monitor_screen_warehouse");
  level.magic_box_tv_random = array("p7_zm_asc_cam_monitor_screen_logo");
  level._box_locations = array(level.magic_box_tv_start_1, level.magic_box_tv_roof_connector, level.magic_box_tv_centrifuge, level.magic_box_tv_base_entry, level.magic_box_tv_storage, level.magic_box_tv_catwalks, level.magic_box_tv_north_pass, level.magic_box_tv_warehouse);
  level._custom_box_monitor = &cosmodrome_screen_switch;
}

function cosmodrome_screen_switch(client_num, state, oldstate) {
  cosmodrome_tv_init(client_num);
  if(state == "n") {
    if(level._power_on == 0) {
      screen_to_display = level.magic_box_tv_off;
    } else {
      screen_to_display = level.magic_box_tv_on;
    }
  } else {
    if(state == "f") {
      screen_to_display = level._cosmodrome_fire_sale;
    } else {
      array_number = int(state);
      screen_to_display = level._box_locations[array_number];
    }
  }
  stop_notify = "stop_tv_swap";
  for(i = 0; i < level.cosmodrome_tvs[client_num].size; i++) {
    tele = level.cosmodrome_tvs[client_num][i];
    tele notify(stop_notify);
    wait(0.2);
    tele thread magic_box_screen_swap(screen_to_display, "stop_tv_swap");
    tele thread play_magic_box_tv_audio(state);
  }
}

function cosmodrome_tv_init(client_num) {
  if(!isDefined(level.cosmodrome_tvs)) {
    level.cosmodrome_tvs = [];
  }
  if(isDefined(level.cosmodrome_tvs[client_num])) {
    return;
  }
  level.cosmodrome_tvs[client_num] = getEntArray(client_num, "model_cosmodrome_box_screens", "targetname");
  for(i = 0; i < level.cosmodrome_tvs[client_num].size; i++) {
    tele = level.cosmodrome_tvs[client_num][i];
    tele setModel(level.magic_box_tv_off[0]);
    wait(0.1);
  }
}

function magic_box_screen_swap(model_array, endon_notify) {
  self endon(endon_notify);
  while(true) {
    for(i = 0; i < model_array.size; i++) {
      self setModel(model_array[i]);
      wait(3);
    }
    if(3 > randomint(100) && isDefined(level.magic_box_tv_random)) {
      self setModel(level.magic_box_tv_random[randomint(level.magic_box_tv_random.size)]);
      wait(2);
    }
    wait(1);
  }
}

function play_magic_box_tv_audio(state) {
  self.alias = "amb_tv_static";
  if(state == "n") {
    if(level._power_on == 0) {
      self.alias = undefined;
    } else {
      self.alias = "amb_tv_static";
    }
  } else {
    if(state == "f") {} else {
      self.alias = "amb_tv_static";
    }
  }
  if(!isDefined(self.alias)) {} else {
    self playLoopSound(self.alias, 0.5);
  }
}

function function_89e03497(localclientnum, oldval, newval, bnewent, binitialsnap, fieldname, bwasdemojump) {
  level function_18769931(localclientnum, newval, "catwalk_zip_door");
}

function function_429d7872(localclientnum, oldval, newval, bnewent, binitialsnap, fieldname, bwasdemojump) {
  level function_18769931(localclientnum, newval, "base_entry_zip_door");
}

function function_7eaa1812(localclientnum, oldval, newval, bnewent, binitialsnap, fieldname, bwasdemojump) {
  level function_18769931(localclientnum, newval, "centrifuge_zip_door");
}

function function_686d40af(localclientnum, oldval, newval, bnewent, binitialsnap, fieldname, bwasdemojump) {
  level function_18769931(localclientnum, newval, "storage_zip_door");
}

function function_18769931(localclientnum, n_state, door_name) {
  sound_count = 0;
  doors = getEntArray(localclientnum, door_name, "targetname");
  for(i = 0; i < doors.size; i++) {
    var_1f9cab23 = doors[i] function_b2c64ce4(n_state);
    v_move_pos = doors[i] function_b27e98c0(var_1f9cab23);
    b_move = doors[i] function_53c16d30(v_move_pos);
    if(b_move) {
      doors[i] moveto(v_move_pos, 1);
      if(sound_count == 0) {
        playSound(0, "zmb_lander_door", doors[i].origin);
        sound_count++;
      }
    }
  }
}

function function_b2c64ce4(n_state) {
  switch (n_state) {
    case 1: {
      return true;
    }
    case 2: {
      if(!isDefined(self.script_noteworthy)) {
        return false;
      } else {
        return true;
      }
    }
    case 3: {
      return false;
    }
    case 0: {
      if(!isDefined(self.script_noteworthy)) {
        return true;
      } else {
        return false;
      }
    }
  }
}

function function_b27e98c0(var_2291984a) {
  open_pos = struct::get(self.target, "targetname");
  start_pos = struct::get(open_pos.target, "targetname");
  if(!isDefined(self.script_noteworthy)) {
    if(var_2291984a) {
      return start_pos.origin;
    }
    return open_pos.origin;
  }
  if(var_2291984a) {
    return open_pos.origin;
  }
  return start_pos.origin;
}

function function_53c16d30(v_pos) {
  if(self.origin != v_pos) {
    return true;
  }
  return false;
}

function rocket_fx(localclientnum, oldval, newval, bnewent, binitialsnap, fieldname, bwasdemojump) {
  if(newval) {
    self.var_a13e8509 = playFXOnTag(localclientnum, level._effect["rocket_blast_trail"], self, "tag_engine");
  } else if(isDefined(self.var_a13e8509)) {
    killfx(localclientnum, self.var_a13e8509);
  }
}

function lander_engine_fx(localclientnum, oldval, newval, bnewent, binitialsnap, fieldname, bwasdemojump) {
  player = getlocalplayers()[localclientnum];
  if(newval) {
    if(isDefined(player.lander_fx)) {
      stopfx(localclientnum, player.lander_fx);
      stopfx(localclientnum, player.lander_fx1);
      stopfx(localclientnum, player.lander_fx2);
      stopfx(localclientnum, player.lander_fx3);
      stopfx(localclientnum, player.lander_fx4);
    }
    player.lander_fx = playFXOnTag(localclientnum, level._effect["lunar_lander_thruster_leg"], self, "tag_engine01");
    setfxignorepause(localclientnum, player.lander_fx, 1);
    player.lander_fx1 = playFXOnTag(localclientnum, level._effect["lunar_lander_thruster_leg"], self, "tag_engine02");
    setfxignorepause(localclientnum, player.lander_fx1, 1);
    player.lander_fx2 = playFXOnTag(localclientnum, level._effect["lunar_lander_thruster_leg"], self, "tag_engine03");
    setfxignorepause(localclientnum, player.lander_fx2, 1);
    player.lander_fx3 = playFXOnTag(localclientnum, level._effect["lunar_lander_thruster_leg"], self, "tag_engine04");
    setfxignorepause(localclientnum, player.lander_fx3, 1);
    player.lander_fx4 = playFXOnTag(localclientnum, level._effect["lunar_lander_thruster_bellow"], self, "tag_bellow");
    setfxignorepause(localclientnum, player.lander_fx4, 1);
    self thread start_ground_sounds();
  } else if(isDefined(player.lander_fx)) {
    stopfx(localclientnum, player.lander_fx);
    stopfx(localclientnum, player.lander_fx1);
    stopfx(localclientnum, player.lander_fx2);
    stopfx(localclientnum, player.lander_fx3);
    stopfx(localclientnum, player.lander_fx4);
  }
}

function start_ground_sounds() {
  self endon("entityshutdown");
  level endon("save_restore");
  self notify("start_ground_sounds");
  self.stop_ground_sounds = 0;
  trace = undefined;
  self.ground_sound_ent = spawn(0, (0, 0, 0), "script_origin");
  self.ground_sound_ent thread function_fb377b79();
  pre_origin = vectorscale((1, 1, 1), 100000);
  while(isDefined(self)) {
    wait(0.15);
    if(isDefined(self.stop_ground_sounds) && self.stop_ground_sounds) {
      if(isDefined(self.ground_sound_ent)) {
        self.ground_sound_ent stoploopsound(2);
      }
      return;
    }
    if(distancesquared(pre_origin, self gettagorigin("tag_bellow")) < 144) {
      continue;
    }
    pre_origin = self gettagorigin("tag_bellow");
    trace = bulletTrace(self gettagorigin("tag_bellow"), self gettagorigin("tag_bellow") - vectorscale((0, 0, 1), 100000), 0, undefined);
    if(!isDefined(trace)) {
      continue;
    }
    if(!isDefined(trace["position"])) {
      self.ground_sound_ent stoploopsound(2);
      continue;
    }
    self.ground_sound_ent.origin = trace["position"] + vectorscale((0, 0, 1), 30);
    self.ground_sound_ent playLoopSound("zmb_lander_ground_sounds", 3);
  }
}

function function_fb377b79() {
  self endon("entityshutdown");
  level waittill("demo_jump");
  self delete();
}

function end_ground_sounds() {
  self endon("start_ground_sounds");
  self.stop_ground_sounds = 1;
  wait(3);
  if(isDefined(self) && isDefined(self.ground_sound_ent)) {
    self.ground_sound_ent delete();
  }
}

function get_random_spot_in_player_view(fwd_min, fwd_max, side_min, side_max) {
  fwd = anglesToForward(self.angles);
  scale = randomintrange(fwd_min, fwd_max);
  fwd = (fwd[0] * scale, fwd[1] * scale, fwd[2] * scale);
  if(randomint(100) > 50) {
    side = anglestoright(self.angles);
  } else {
    side = anglestoright(self.angles) * -1;
  }
  scale = randomintrange(side_min, side_max);
  side = (side[0] * scale, side[1] * scale, side[2] * scale);
  point = (self.origin + fwd) + side;
  trace = bulletTrace(point, point + (vectorscale((0, 0, -1), 10000)), 0, undefined);
  return trace["position"];
}

function debris_crash_and_burn(spot, client, player) {
  playFXOnTag(client, level._effect["debris_trail"], self, "tag_origin");
  self moveto(spot, 3.1);
  for(i = 0; i < 10; i++) {
    self rotateto((randomint(360), randomint(360), randomint(360)), 0.3);
    wait(0.3);
  }
  wait(3.1);
  player earthquake(0.4, 0.5, self.origin, 1200);
  playFX(client, level._effect["debris_hit"], self.origin);
  wait(1);
  self delete();
}

function setup_lander_screens(clientnum) {
  screens = getEntArray(clientnum, "lander_screens", "targetname");
  for(i = 0; i < screens.size; i++) {
    if(isDefined(screens[i].model)) {
      screens[i] setModel("p7_zm_asc_control_panel_lunar");
    }
  }
}

function lander_at_station(station, clientnum) {
  self util::waittill_dobj(clientnum);
  if(isDefined(self.panel_fx)) {
    stopfx(clientnum, self.panel_fx);
  }
  if(isDefined(self.lander_fx)) {
    stopfx(clientnum, self.lander_fx);
  }
  switch (station) {
    case 3: {
      self.panel_fx = playFXOnTag(clientnum, level._effect["panel_green"], self, "tag_location_3");
      self.lander_location = self gettagorigin("tag_location_3");
      self.lander_location_angles = self gettagangles("tag_location_3");
      setfxignorepause(clientnum, self.panel_fx, 1);
      break;
    }
    case 1: {
      self.panel_fx = playFXOnTag(clientnum, level._effect["panel_green"], self, "tag_location_1");
      self.lander_location = self gettagorigin("tag_location_1");
      self.lander_location_angles = self gettagangles("tag_location_1");
      setfxignorepause(clientnum, self.panel_fx, 1);
      break;
    }
    case 2: {
      self.panel_fx = playFXOnTag(clientnum, level._effect["panel_green"], self, "tag_location_2");
      self.lander_location = self gettagorigin("tag_location_2");
      self.lander_location_angles = self gettagangles("tag_location_2");
      setfxignorepause(clientnum, self.panel_fx, 1);
      break;
    }
    case 4: {
      self.panel_fx = playFXOnTag(clientnum, level._effect["panel_green"], self, "tag_home");
      self.lander_location = self gettagorigin("tag_home");
      self.lander_location_angles = self gettagangles("tag_home");
      setfxignorepause(clientnum, self.panel_fx, 1);
      break;
    }
  }
}

function lander_move_fx(localclientnum, oldval, newval, bnewent, binitialsnap, fieldname, bwasdemojump) {
  if(newval) {
    player = getlocalplayers()[localclientnum];
    player thread lander_station_move_lander_marker(localclientnum);
  }
}

function lander_station_move_lander_marker(localclientnum) {
  dest = undefined;
  x = localclientnum;
  screens = getEntArray(x, "lander_screens", "targetname");
  for(i = 0; i < screens.size; i++) {
    screen = screens[i];
    if(isDefined(screen.lander_fx)) {
      stopfx(x, screen.lander_fx);
    }
    if(isDefined(screen.panel_fx)) {
      stopfx(x, screen.panel_fx);
    }
    if(!isDefined(screen.lander_fx_ent)) {
      screen.lander_fx_ent = spawn(x, screen.lander_location, "script_origin");
      screen.lander_fx_ent setModel("tag_origin");
      screen.lander_fx_ent.angles = screen.lander_location_angles;
    }
    screen.lander_fx = playFXOnTag(x, level._effect["panel_green"], screen.lander_fx_ent, "tag_origin");
    setfxignorepause(x, screen.lander_fx, 1);
    switch (level.lander_dest_station) {
      case "base": {
        dest = screen gettagorigin("tag_location_3");
        break;
      }
      case "storage": {
        dest = screen gettagorigin("tag_location_1");
        break;
      }
      case "centrifuge": {
        dest = screen gettagorigin("tag_home");
        break;
      }
      case "catwalk": {
        dest = screen gettagorigin("tag_location_2");
        break;
      }
    }
    screen.lander_fx_ent moveto(dest, 10);
  }
}

function function_446c53e5(localclientnum, oldval, newval, bnewent, binitialsnap, fieldname, bwasdemojump) {
  screens = getEntArray(localclientnum, "lander_screens", "targetname");
  for(i = 0; i < screens.size; i++) {
    screens[i] thread lander_at_station(newval, localclientnum);
  }
}

function function_32db5393(localclientnum, oldval, newval, bnewent, binitialsnap, fieldname, bwasdemojump) {
  if(newval == 1) {
    level zm_cosmodrome_fx::toggle_lander_lights("red", localclientnum);
  } else if(newval == 2) {
    level zm_cosmodrome_fx::toggle_lander_lights("green", localclientnum);
  }
}

function function_f6ffc831(localclientnum, oldval, newval, bnewent, binitialsnap, fieldname, bwasdemojump) {
  switch (newval) {
    case 2: {
      level.lander_dest_station = "catwalk";
      break;
    }
    case 3: {
      level.lander_dest_station = "base";
      break;
    }
    case 4: {
      level.lander_dest_station = "centrifuge";
      break;
    }
    case 1: {
      level.lander_dest_station = "storage";
      break;
    }
  }
}

function launch_panel_centrifuge_status(localclientnum, oldval, newval, bnewent, binitialsnap, fieldname, bwasdemojump) {
  if(newval) {
    if(isDefined(self.centrifuge_status)) {
      stopfx(localclientnum, self.centrifuge_status);
    }
    self.centrifuge_status = playFXOnTag(localclientnum, level._effect["panel_red"], self, "tag_home");
    setfxignorepause(localclientnum, self.centrifuge_status, 1);
  } else {
    if(isDefined(self.centrifuge_status)) {
      stopfx(localclientnum, self.centrifuge_status);
    }
    self.centrifuge_status = playFXOnTag(localclientnum, level._effect["panel_green"], self, "tag_home");
    setfxignorepause(localclientnum, self.centrifuge_status, 1);
  }
}

function launch_panel_storage_status(localclientnum, oldval, newval, bnewent, binitialsnap, fieldname, bwasdemojump) {
  if(newval) {
    if(localclientnum == 0) {
      level.rocket_num++;
    }
    level thread rocket_launch_display(localclientnum);
  }
}

function launch_panel_baseentry_status(localclientnum, oldval, newval, bnewent, binitialsnap, fieldname, bwasdemojump) {
  if(newval) {
    if(localclientnum == 0) {
      level.rocket_num++;
    }
    level thread rocket_launch_display(localclientnum);
  }
}

function launch_panel_catwalk_status(localclientnum, oldval, newval, bnewent, binitialsnap, fieldname, bwasdemojump) {
  if(newval) {
    if(localclientnum == 0) {
      level.rocket_num++;
    }
    level thread rocket_launch_display(localclientnum);
  }
}

function rocket_launch_display(localclientnum) {
  wait(1);
  rocket_screens = getEntArray(localclientnum, "rocket_launch_sign", "targetname");
  model = rocket_screens[0].model;
  switch (level.rocket_num) {
    case 1: {
      model = "p7_zm_asc_sign_rocket_02";
      break;
    }
    case 2: {
      model = "p7_zm_asc_sign_rocket_03";
      break;
    }
    case 3: {
      model = "p7_zm_asc_sign_rocket_04";
      break;
    }
  }
  array::thread_all(rocket_screens, &update_rocket_display, model);
}

function update_rocket_display(on_model) {
  old_model = self.model;
  for(i = 0; i < 3; i++) {
    self setModel(on_model);
    wait(0.35);
    self setModel(old_model);
    wait(0.35);
  }
  self setModel(on_model);
}

function lander_rumble_and_quake(localclientnum, oldval, newval, bnewent, binitialsnap, fieldname, bwasdemojump) {
  player = getlocalplayers()[localclientnum];
  player endon("death");
  player endon("disconnect");
  if(isspectating(localclientnum, 0)) {
    return;
  }
  if(newval) {
    player earthquake(randomfloatrange(0.2, 0.3), randomfloatrange(2, 2.5), player.origin, 150);
    player playrumbleonentity(localclientnum, "artillery_rumble");
    self thread do_lander_rumble_quake(localclientnum);
  } else {
    self thread end_ground_sounds();
    player earthquake(randomfloatrange(0.3, 0.4), randomfloatrange(0.5, 0.6), self.origin, 150);
    wait(0.6);
    if(isDefined(player) && isDefined(self)) {
      player earthquake(randomfloatrange(0.1, 0.2), randomfloatrange(0.2, 0.3), self.origin, 150);
    }
    level notify("stop_lander_rumble");
  }
}

function do_lander_rumble_quake(localclientnum) {
  level endon("stop_lander_rumble");
  player = getlocalplayers()[localclientnum];
  player endon("entityshutdown");
  player endon("disconnect");
  while(true) {
    if(!isDefined(self.origin) || !isDefined(player.origin)) {
      wait(0.05);
      continue;
    }
    if(distancesquared(player.origin, self.origin) > 2250000) {
      wait(0.1);
      continue;
    }
    dist = distancesquared(player.origin, self.origin);
    if(dist > 562500) {
      player earthquake(randomfloatrange(0.1, 0.15), randomfloatrange(0.15, 0.16), self.origin, 1000);
      rumble = "slide_rumble";
    } else {
      player earthquake(randomfloatrange(0.15, 0.2), randomfloatrange(0.15, 0.16), self.origin, 750);
      rumble = "damage_light";
    }
    player playrumbleonentity(localclientnum, rumble);
    wait(0.1);
  }
}

function centrifuge_rumble_control(local_client_num, oldval, newval, bnewent, binitialsnap, fieldname, bwasdemojump) {
  if(local_client_num != 0) {
    return;
  }
  if(newval) {
    players = getlocalplayers();
    for(i = 0; i < players.size; i++) {
      players[i] thread centrifuge_rumble_when_close(self, i);
    }
  } else {
    level notify("centrifuge_rumble_done");
  }
}

function centrifuge_rumble_when_close(ent_centrifuge, int_client_num) {
  self endon("death");
  self endon("disconnect");
  level endon("centrifuge_rumble_done");
  rumble_range = 360000;
  centrifuge_rumble = "damage_heavy";
  client_num = undefined;
  while(isDefined(self)) {
    distance_to_centrifuge = distancesquared(self.origin, ent_centrifuge.origin);
    if(distance_to_centrifuge < rumble_range && isDefined(self)) {
      if(isDefined(int_client_num)) {
        self playrumbleonentity(int_client_num, centrifuge_rumble);
      }
    }
    if(distance_to_centrifuge > rumble_range) {
      if(isDefined(int_client_num) && isDefined(self)) {
        self stoprumble(int_client_num, centrifuge_rumble);
      }
    }
    wait(0.1);
  }
}

function centrifuge_clean_rumble(int_client_num) {
  self endon("death");
  self endon("disconnect");
  self stoprumble(int_client_num, "damage_heavy");
}

function centrifuge_warning_lights_init(local_client_num, oldval, newval, bnewent, binitialsnap, fieldname, bwasdemojump) {
  while(!self hasdobj(local_client_num)) {
    wait(0.1);
  }
  if(local_client_num != 0) {
    return;
  }
  players = getlocalplayers();
  for(i = 0; i < players.size; i++) {
    self centrifuge_warning_lights_off(i);
  }
  if(newval) {
    players = getlocalplayers();
    for(i = 0; i < players.size; i++) {
      self centrifuge_fx_spot_init(i);
      self centrifuge_warning_lights_on(i);
    }
  }
}

function monkey_lander_fx_on() {
  self endon("switch_off_monkey_lander_fx");
  playSound(0, "zmb_ape_intro_whoosh", self.origin);
  wait(2.5);
  if(isDefined(self)) {
    self.fx = [];
    players = getlocalplayers();
    ent_num = self getentitynumber();
    for(i = 0; i < players.size; i++) {
      player = players[i];
      if(!isDefined(player._monkey_lander_fx)) {
        player._monkey_lander_fx = [];
      }
      if(isDefined(player._monkey_lander_fx[ent_num])) {
        deletefx(i, player._monkey_lander_fx[ent_num]);
        player._monkey_lander_fx[ent_num] = undefined;
      }
      player._monkey_lander_fx[ent_num] = playFXOnTag(i, level._effect["monkey_trail"], self, "tag_origin");
      setfxignorepause(i, player._monkey_lander_fx[ent_num], 1);
    }
  }
}

function monkey_lander_fx_off() {
  players = getlocalplayers();
  ent_num = self getentitynumber();
  for(i = 0; i < players.size; i++) {
    player = players[i];
    playFX(i, level._effect["monkey_spawn"], self.origin);
    playrumbleonposition(i, "explosion_generic", self.origin);
    player earthquake(0.5, 0.5, player.origin, 1000);
  }
  playSound(0, "zmb_ape_intro_land", self.origin);
}

function monkey_lander_fx(local_client_num, oldval, newval, bnewent, binitialsnap, fieldname, bwasdemojump) {
  if(local_client_num != 0) {
    return;
  }
  while(!self hasdobj(local_client_num)) {
    wait(0.1);
  }
  if(newval) {
    self thread monkey_lander_fx_on();
    level thread function_ea758913();
  } else {
    self thread monkey_lander_fx_off();
  }
}

function samantha_is_angry(localclientnum, oldval, newval, bnewent, binitialsnap, fieldname, bwasdemojump) {
  if(newval) {
    zm_cosmodrome_amb::samantha_is_angry_earthquake_and_rumbles(localclientnum);
  }
}

function centrifuge_fx_spot_init(int_client_num) {
  self._centrifuge_lights_[int_client_num] = [];
  self._centrifuge_lights_[int_client_num] = array::add(self._centrifuge_lights_[int_client_num], "tag_light_bk_top", 0);
  self._centrifuge_lights_[int_client_num] = array::add(self._centrifuge_lights_[int_client_num], "tag_light_fnt_top", 0);
  self._centrifuge_lights_[int_client_num] = array::add(self._centrifuge_lights_[int_client_num], "tag_light_fnt_bttm", 0);
  self._centrifuge_lights_[int_client_num] = array::add(self._centrifuge_lights_[int_client_num], "tag_light_bk_bttm", 0);
  self._centrifuge_sparks_[int_client_num] = [];
  self._centrifuge_sparks_[int_client_num] = array::add(self._centrifuge_sparks_[int_client_num], "tag_light_bk_bttm", 0);
  self._centrifuge_sparks_[int_client_num] = array::add(self._centrifuge_sparks_[int_client_num], "tag_light_fnt_bttm", 0);
  self._centrifuge_steams_[int_client_num] = [];
  self._centrifuge_steams_[int_client_num] = array::add(self._centrifuge_steams_[int_client_num], "tag_vent_bk_btm", 0);
  self._centrifuge_steams_[int_client_num] = array::add(self._centrifuge_steams_[int_client_num], "tag_vent_top_btm", 0);
  self._centrifuge_light_mdls_[int_client_num] = [];
  self._centrifuge_fx_setup = 1;
}

function centrifuge_warning_lights_on(client_num) {
  for(i = 0; i < self._centrifuge_lights_[client_num].size; i++) {
    temp_mdl = spawn(client_num, self gettagorigin(self._centrifuge_lights_[client_num][i]), "script_model");
    temp_mdl.angles = self gettagangles(self._centrifuge_lights_[client_num][i]);
    if(issubstr(self._centrifuge_lights_[client_num][i], "_bttm")) {
      temp_mdl.angles = temp_mdl.angles + vectorscale((1, 0, 0), 180);
    }
    temp_mdl setModel("tag_origin");
    temp_mdl linkto(self, self._centrifuge_lights_[client_num][i]);
    playFXOnTag(client_num, level._effect["centrifuge_warning_light"], temp_mdl, "tag_origin");
    self._centrifuge_light_mdls_[client_num] = array::add(self._centrifuge_light_mdls_[client_num], temp_mdl, 0);
  }
  for(i = 0; i < self._centrifuge_sparks_[client_num].size; i++) {
    temp_mdl = spawn(client_num, self gettagorigin(self._centrifuge_sparks_[client_num][i]), "script_model");
    temp_mdl.angles = self gettagangles(self._centrifuge_sparks_[client_num][i]);
    temp_mdl setModel("tag_origin");
    temp_mdl linkto(self, self._centrifuge_sparks_[client_num][i]);
    playFXOnTag(client_num, level._effect["centrifuge_light_spark"], temp_mdl, "tag_origin");
    self._centrifuge_light_mdls_[client_num] = array::add(self._centrifuge_light_mdls_[client_num], temp_mdl, 0);
  }
  self thread centrifuge_steam_warning(client_num);
}

function centrifuge_steam_warning(client_num) {
  self endon("entityshutdown");
  wait(1);
  for(i = 0; i < self._centrifuge_steams_[client_num].size; i++) {
    playFXOnTag(client_num, level._effect["centrifuge_start_steam"], self, self._centrifuge_steams_[client_num][i]);
  }
}

function centrifuge_warning_lights_off(client_num) {
  if(!isDefined(self._centrifuge_fx_setup)) {
    return;
  }
  wait(0.2);
  for(i = 0; i < self._centrifuge_light_mdls_[client_num].size; i++) {
    if(isDefined(self._centrifuge_light_mdls_[client_num][i])) {
      self._centrifuge_light_mdls_[client_num][i] unlink();
    }
  }
  array::delete_all(self._centrifuge_light_mdls_[client_num]);
  self._centrifuge_light_mdls_[client_num] = [];
}

function fog_apply(str_fog, int_priority) {
  self endon("death");
  self endon("disconnect");
  if(!isDefined(self._zombie_fog_list)) {
    self._zombie_fog_list = [];
  }
  if(!isDefined(str_fog) || !isDefined(int_priority)) {
    return;
  }
  already_in_array = 0;
  if(self._zombie_fog_list.size != 0) {
    for(i = 0; i < self._zombie_fog_list.size; i++) {
      if(isDefined(self._zombie_fog_list[i].fog_setting) && self._zombie_fog_list[i].fog_setting == str_fog) {
        already_in_array = 1;
        if(self._zombie_fog_list[i].priority != int_priority) {
          self._zombie_fog_list[i].priority = int_priority;
        }
        break;
      }
    }
  }
  if(!already_in_array) {
    temp_struct = spawnStruct();
    temp_struct.fog_setting = str_fog;
    temp_struct.priority = int_priority;
    self._zombie_fog_list = array::add(self._zombie_fog_list, temp_struct, 0);
  }
  fog_to_set = get_fog_by_priority();
  set_fog(fog_to_set);
}

function fog_remove(str_fog) {
  self endon("death");
  self endon("disconnect");
  if(!isDefined(str_fog)) {
    return;
  }
  if(!isDefined(self._zombie_fog_list)) {
    self._zombie_fog_list = [];
  }
  temp_struct = undefined;
  for(i = 0; i < self._zombie_fog_list.size; i++) {
    if(isDefined(self._zombie_fog_list[i].fog_setting) && self._zombie_fog_list[i].fog_setting == str_fog) {
      temp_struct = self._zombie_fog_list[i];
    }
  }
  if(isDefined(temp_struct)) {
    for(i = 0; i < self._zombie_fog_list.size; i++) {
      if(self._zombie_fog_list[i] == temp_struct) {
        self._zombie_fog_list[i] = undefined;
      }
    }
    array::remove_undefined(self._zombie_fog_list);
  }
  fog_to_set = get_fog_by_priority();
  set_fog(fog_to_set);
}

function get_fog_by_priority() {
  if(!isDefined(self._zombie_fog_list)) {
    return;
  }
  highest_score = 0;
  highest_score_fog = undefined;
  for(i = 0; i < self._zombie_fog_list.size; i++) {
    if(isDefined(self._zombie_fog_list[i].priority) && self._zombie_fog_list[i].priority > highest_score) {
      highest_score = self._zombie_fog_list[i].priority;
      highest_score_fog = self._zombie_fog_list[i].fog_setting;
    }
  }
  return highest_score_fog;
}

function setup_fog() {
  util::waitforclient(0);
  wait(1);
  players = getlocalplayers();
  for(i = 0; i < players.size; i++) {
    players[i] fog_apply("normal", level._fog_settings_default_priority);
  }
}

function set_fog(fog_type) {
  util::waitforclient(0);
  if(!isDefined(fog_type)) {
    return;
  }
  switch (fog_type) {
    case "normal": {
      setworldfogactivebank(self getlocalclientnumber(), 1);
      break;
    }
    case "monkey": {
      setworldfogactivebank(self getlocalclientnumber(), 2);
      break;
    }
    case "lander": {
      break;
    }
  }
}

function player_lander_fog(local_client_num, oldval, newval, bnewent, binitialsnap, fieldname, bwasdemojump) {
  player = getlocalplayers()[local_client_num];
  if(newval) {
    player thread fog_apply("lander", level._fog_settings_lander_priority);
  } else {
    player thread fog_remove("lander");
  }
}

function setup_personality_character_exerts() {
  level.exert_sounds[1]["playerbreathinsound"][0] = "vox_plr_0_exert_inhale_0";
  level.exert_sounds[1]["playerbreathinsound"][1] = "vox_plr_0_exert_inhale_1";
  level.exert_sounds[1]["playerbreathinsound"][2] = "vox_plr_0_exert_inhale_2";
  level.exert_sounds[2]["playerbreathinsound"][0] = "vox_plr_1_exert_inhale_0";
  level.exert_sounds[2]["playerbreathinsound"][1] = "vox_plr_1_exert_inhale_1";
  level.exert_sounds[2]["playerbreathinsound"][2] = "vox_plr_1_exert_inhale_2";
  level.exert_sounds[3]["playerbreathinsound"][0] = "vox_plr_2_exert_inhale_0";
  level.exert_sounds[3]["playerbreathinsound"][1] = "vox_plr_2_exert_inhale_1";
  level.exert_sounds[3]["playerbreathinsound"][2] = "vox_plr_2_exert_inhale_2";
  level.exert_sounds[4]["playerbreathinsound"][0] = "vox_plr_3_exert_inhale_0";
  level.exert_sounds[4]["playerbreathinsound"][1] = "vox_plr_3_exert_inhale_1";
  level.exert_sounds[4]["playerbreathinsound"][2] = "vox_plr_3_exert_inhale_2";
  level.exert_sounds[1]["playerbreathoutsound"][0] = "vox_plr_0_exert_exhale_0";
  level.exert_sounds[1]["playerbreathoutsound"][1] = "vox_plr_0_exert_exhale_1";
  level.exert_sounds[1]["playerbreathoutsound"][2] = "vox_plr_0_exert_exhale_2";
  level.exert_sounds[2]["playerbreathoutsound"][0] = "vox_plr_1_exert_exhale_0";
  level.exert_sounds[2]["playerbreathoutsound"][1] = "vox_plr_1_exert_exhale_1";
  level.exert_sounds[2]["playerbreathoutsound"][2] = "vox_plr_1_exert_exhale_2";
  level.exert_sounds[3]["playerbreathoutsound"][0] = "vox_plr_2_exert_exhale_0";
  level.exert_sounds[3]["playerbreathoutsound"][1] = "vox_plr_2_exert_exhale_1";
  level.exert_sounds[3]["playerbreathoutsound"][2] = "vox_plr_2_exert_exhale_2";
  level.exert_sounds[4]["playerbreathoutsound"][0] = "vox_plr_3_exert_exhale_0";
  level.exert_sounds[4]["playerbreathoutsound"][1] = "vox_plr_3_exert_exhale_1";
  level.exert_sounds[4]["playerbreathoutsound"][2] = "vox_plr_3_exert_exhale_2";
  level.exert_sounds[1]["playerbreathgaspsound"][0] = "vox_plr_0_exert_exhale_0";
  level.exert_sounds[1]["playerbreathgaspsound"][1] = "vox_plr_0_exert_exhale_1";
  level.exert_sounds[1]["playerbreathgaspsound"][2] = "vox_plr_0_exert_exhale_2";
  level.exert_sounds[2]["playerbreathgaspsound"][0] = "vox_plr_1_exert_exhale_0";
  level.exert_sounds[2]["playerbreathgaspsound"][1] = "vox_plr_1_exert_exhale_1";
  level.exert_sounds[2]["playerbreathgaspsound"][2] = "vox_plr_1_exert_exhale_2";
  level.exert_sounds[3]["playerbreathgaspsound"][0] = "vox_plr_2_exert_exhale_0";
  level.exert_sounds[3]["playerbreathgaspsound"][1] = "vox_plr_2_exert_exhale_1";
  level.exert_sounds[3]["playerbreathgaspsound"][2] = "vox_plr_2_exert_exhale_2";
  level.exert_sounds[4]["playerbreathgaspsound"][0] = "vox_plr_3_exert_exhale_0";
  level.exert_sounds[4]["playerbreathgaspsound"][1] = "vox_plr_3_exert_exhale_1";
  level.exert_sounds[4]["playerbreathgaspsound"][2] = "vox_plr_3_exert_exhale_2";
  level.exert_sounds[1]["falldamage"][0] = "vox_plr_0_exert_pain_low_0";
  level.exert_sounds[1]["falldamage"][1] = "vox_plr_0_exert_pain_low_1";
  level.exert_sounds[1]["falldamage"][2] = "vox_plr_0_exert_pain_low_2";
  level.exert_sounds[1]["falldamage"][3] = "vox_plr_0_exert_pain_low_3";
  level.exert_sounds[1]["falldamage"][4] = "vox_plr_0_exert_pain_low_4";
  level.exert_sounds[1]["falldamage"][5] = "vox_plr_0_exert_pain_low_5";
  level.exert_sounds[1]["falldamage"][6] = "vox_plr_0_exert_pain_low_6";
  level.exert_sounds[1]["falldamage"][7] = "vox_plr_0_exert_pain_low_7";
  level.exert_sounds[2]["falldamage"][0] = "vox_plr_1_exert_pain_low_0";
  level.exert_sounds[2]["falldamage"][1] = "vox_plr_1_exert_pain_low_1";
  level.exert_sounds[2]["falldamage"][2] = "vox_plr_1_exert_pain_low_2";
  level.exert_sounds[2]["falldamage"][3] = "vox_plr_1_exert_pain_low_3";
  level.exert_sounds[2]["falldamage"][4] = "vox_plr_1_exert_pain_low_4";
  level.exert_sounds[2]["falldamage"][5] = "vox_plr_1_exert_pain_low_5";
  level.exert_sounds[2]["falldamage"][6] = "vox_plr_1_exert_pain_low_6";
  level.exert_sounds[2]["falldamage"][7] = "vox_plr_1_exert_pain_low_7";
  level.exert_sounds[3]["falldamage"][0] = "vox_plr_2_exert_pain_low_0";
  level.exert_sounds[3]["falldamage"][1] = "vox_plr_2_exert_pain_low_1";
  level.exert_sounds[3]["falldamage"][2] = "vox_plr_2_exert_pain_low_2";
  level.exert_sounds[3]["falldamage"][3] = "vox_plr_2_exert_pain_low_3";
  level.exert_sounds[3]["falldamage"][4] = "vox_plr_2_exert_pain_low_4";
  level.exert_sounds[3]["falldamage"][5] = "vox_plr_2_exert_pain_low_5";
  level.exert_sounds[3]["falldamage"][6] = "vox_plr_2_exert_pain_low_6";
  level.exert_sounds[3]["falldamage"][7] = "vox_plr_2_exert_pain_low_7";
  level.exert_sounds[4]["falldamage"][0] = "vox_plr_3_exert_pain_low_0";
  level.exert_sounds[4]["falldamage"][1] = "vox_plr_3_exert_pain_low_1";
  level.exert_sounds[4]["falldamage"][2] = "vox_plr_3_exert_pain_low_2";
  level.exert_sounds[4]["falldamage"][3] = "vox_plr_3_exert_pain_low_3";
  level.exert_sounds[4]["falldamage"][4] = "vox_plr_3_exert_pain_low_4";
  level.exert_sounds[4]["falldamage"][5] = "vox_plr_3_exert_pain_low_5";
  level.exert_sounds[4]["falldamage"][6] = "vox_plr_3_exert_pain_low_6";
  level.exert_sounds[4]["falldamage"][7] = "vox_plr_3_exert_pain_low_7";
  level.exert_sounds[1]["mantlesoundplayer"][0] = "vox_plr_0_exert_grunt_0";
  level.exert_sounds[1]["mantlesoundplayer"][1] = "vox_plr_0_exert_grunt_1";
  level.exert_sounds[1]["mantlesoundplayer"][2] = "vox_plr_0_exert_grunt_2";
  level.exert_sounds[1]["mantlesoundplayer"][3] = "vox_plr_0_exert_grunt_3";
  level.exert_sounds[1]["mantlesoundplayer"][4] = "vox_plr_0_exert_grunt_4";
  level.exert_sounds[1]["mantlesoundplayer"][5] = "vox_plr_0_exert_grunt_5";
  level.exert_sounds[1]["mantlesoundplayer"][6] = "vox_plr_0_exert_grunt_6";
  level.exert_sounds[2]["mantlesoundplayer"][0] = "vox_plr_1_exert_grunt_0";
  level.exert_sounds[2]["mantlesoundplayer"][1] = "vox_plr_1_exert_grunt_1";
  level.exert_sounds[2]["mantlesoundplayer"][2] = "vox_plr_1_exert_grunt_2";
  level.exert_sounds[2]["mantlesoundplayer"][3] = "vox_plr_1_exert_grunt_3";
  level.exert_sounds[2]["mantlesoundplayer"][4] = "vox_plr_1_exert_grunt_4";
  level.exert_sounds[2]["mantlesoundplayer"][5] = "vox_plr_1_exert_grunt_5";
  level.exert_sounds[3]["mantlesoundplayer"][0] = "vox_plr_2_exert_grunt_0";
  level.exert_sounds[3]["mantlesoundplayer"][1] = "vox_plr_2_exert_grunt_1";
  level.exert_sounds[3]["mantlesoundplayer"][2] = "vox_plr_2_exert_grunt_2";
  level.exert_sounds[3]["mantlesoundplayer"][3] = "vox_plr_2_exert_grunt_3";
  level.exert_sounds[3]["mantlesoundplayer"][4] = "vox_plr_2_exert_grunt_4";
  level.exert_sounds[3]["mantlesoundplayer"][5] = "vox_plr_2_exert_grunt_5";
  level.exert_sounds[3]["mantlesoundplayer"][6] = "vox_plr_2_exert_grunt_6";
  level.exert_sounds[4]["mantlesoundplayer"][0] = "vox_plr_3_exert_grunt_0";
  level.exert_sounds[4]["mantlesoundplayer"][1] = "vox_plr_3_exert_grunt_1";
  level.exert_sounds[4]["mantlesoundplayer"][2] = "vox_plr_3_exert_grunt_2";
  level.exert_sounds[4]["mantlesoundplayer"][3] = "vox_plr_3_exert_grunt_4";
  level.exert_sounds[4]["mantlesoundplayer"][4] = "vox_plr_3_exert_grunt_5";
  level.exert_sounds[4]["mantlesoundplayer"][5] = "vox_plr_3_exert_grunt_6";
  level.exert_sounds[1]["meleeswipesoundplayer"][0] = "vox_plr_0_exert_knife_swipe_0";
  level.exert_sounds[1]["meleeswipesoundplayer"][1] = "vox_plr_0_exert_knife_swipe_1";
  level.exert_sounds[1]["meleeswipesoundplayer"][2] = "vox_plr_0_exert_knife_swipe_2";
  level.exert_sounds[1]["meleeswipesoundplayer"][3] = "vox_plr_0_exert_knife_swipe_3";
  level.exert_sounds[1]["meleeswipesoundplayer"][4] = "vox_plr_0_exert_knife_swipe_4";
  level.exert_sounds[1]["meleeswipesoundplayer"][5] = "vox_plr_0_exert_knife_swipe_5";
  level.exert_sounds[2]["meleeswipesoundplayer"][0] = "vox_plr_1_exert_knife_swipe_0";
  level.exert_sounds[2]["meleeswipesoundplayer"][1] = "vox_plr_1_exert_knife_swipe_1";
  level.exert_sounds[2]["meleeswipesoundplayer"][2] = "vox_plr_1_exert_knife_swipe_2";
  level.exert_sounds[2]["meleeswipesoundplayer"][3] = "vox_plr_1_exert_knife_swipe_3";
  level.exert_sounds[2]["meleeswipesoundplayer"][4] = "vox_plr_1_exert_knife_swipe_4";
  level.exert_sounds[2]["meleeswipesoundplayer"][5] = "vox_plr_1_exert_knife_swipe_5";
  level.exert_sounds[3]["meleeswipesoundplayer"][0] = "vox_plr_2_exert_knife_swipe_0";
  level.exert_sounds[3]["meleeswipesoundplayer"][1] = "vox_plr_2_exert_knife_swipe_1";
  level.exert_sounds[3]["meleeswipesoundplayer"][2] = "vox_plr_2_exert_knife_swipe_2";
  level.exert_sounds[3]["meleeswipesoundplayer"][3] = "vox_plr_2_exert_knife_swipe_3";
  level.exert_sounds[3]["meleeswipesoundplayer"][4] = "vox_plr_2_exert_knife_swipe_4";
  level.exert_sounds[3]["meleeswipesoundplayer"][5] = "vox_plr_2_exert_knife_swipe_5";
  level.exert_sounds[4]["meleeswipesoundplayer"][0] = "vox_plr_3_exert_knife_swipe_0";
  level.exert_sounds[4]["meleeswipesoundplayer"][1] = "vox_plr_3_exert_knife_swipe_1";
  level.exert_sounds[4]["meleeswipesoundplayer"][2] = "vox_plr_3_exert_knife_swipe_2";
  level.exert_sounds[4]["meleeswipesoundplayer"][3] = "vox_plr_3_exert_knife_swipe_3";
  level.exert_sounds[4]["meleeswipesoundplayer"][4] = "vox_plr_3_exert_knife_swipe_4";
  level.exert_sounds[4]["meleeswipesoundplayer"][5] = "vox_plr_3_exert_knife_swipe_5";
  level.exert_sounds[1]["dtplandsoundplayer"][0] = "vox_plr_0_exert_pain_medium_0";
  level.exert_sounds[1]["dtplandsoundplayer"][1] = "vox_plr_0_exert_pain_medium_1";
  level.exert_sounds[1]["dtplandsoundplayer"][2] = "vox_plr_0_exert_pain_medium_2";
  level.exert_sounds[1]["dtplandsoundplayer"][3] = "vox_plr_0_exert_pain_medium_3";
  level.exert_sounds[2]["dtplandsoundplayer"][0] = "vox_plr_1_exert_pain_medium_0";
  level.exert_sounds[2]["dtplandsoundplayer"][1] = "vox_plr_1_exert_pain_medium_1";
  level.exert_sounds[2]["dtplandsoundplayer"][2] = "vox_plr_1_exert_pain_medium_2";
  level.exert_sounds[2]["dtplandsoundplayer"][3] = "vox_plr_1_exert_pain_medium_3";
  level.exert_sounds[3]["dtplandsoundplayer"][0] = "vox_plr_2_exert_pain_medium_0";
  level.exert_sounds[3]["dtplandsoundplayer"][1] = "vox_plr_2_exert_pain_medium_1";
  level.exert_sounds[3]["dtplandsoundplayer"][2] = "vox_plr_2_exert_pain_medium_2";
  level.exert_sounds[3]["dtplandsoundplayer"][3] = "vox_plr_2_exert_pain_medium_3";
  level.exert_sounds[4]["dtplandsoundplayer"][0] = "vox_plr_3_exert_pain_medium_0";
  level.exert_sounds[4]["dtplandsoundplayer"][1] = "vox_plr_3_exert_pain_medium_1";
  level.exert_sounds[4]["dtplandsoundplayer"][2] = "vox_plr_3_exert_pain_medium_2";
  level.exert_sounds[4]["dtplandsoundplayer"][3] = "vox_plr_3_exert_pain_medium_3";
}