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

#using scripts\codescripts\struct;
#using scripts\shared\aat_shared;
#using scripts\shared\ai\margwa;
#using scripts\shared\ai\systems\animation_state_machine_utility;
#using scripts\shared\ai\systems\behavior_tree_utility;
#using scripts\shared\ai\systems\blackboard;
#using scripts\shared\ai\zombie_utility;
#using scripts\shared\array_shared;
#using scripts\shared\callbacks_shared;
#using scripts\shared\clientfield_shared;
#using scripts\shared\flag_shared;
#using scripts\shared\flagsys_shared;
#using scripts\shared\laststand_shared;
#using scripts\shared\math_shared;
#using scripts\shared\scene_shared;
#using scripts\shared\scoreevents_shared;
#using scripts\shared\spawner_shared;
#using scripts\shared\util_shared;
#using scripts\zm\_zm;
#using scripts\zm\_zm_ai_margwa_no_idgun;
#using scripts\zm\_zm_behavior;
#using scripts\zm\_zm_devgui;
#using scripts\zm\_zm_elemental_zombies;
#using scripts\zm\_zm_laststand;
#using scripts\zm\_zm_light_zombie;
#using scripts\zm\_zm_powerups;
#using scripts\zm\_zm_score;
#using scripts\zm\_zm_shadow_zombie;
#using scripts\zm\_zm_spawner;
#using scripts\zm\_zm_utility;
#namespace zm_ai_margwa_elemental;

function autoexec init() {
  function_afef488b();
  spawner::add_archetype_spawn_function("margwa", &function_e1859566);
  clientfield::register("actor", "margwa_elemental_type", 15000, 3, "int");
  clientfield::register("actor", "margwa_defense_actor_appear_disappear_fx", 15000, 1, "int");
  clientfield::register("scriptmover", "play_margwa_fire_attack_fx", 15000, 1, "counter");
  clientfield::register("scriptmover", "margwa_defense_hovering_fx", 15000, 3, "int");
  clientfield::register("actor", "shadow_margwa_attack_portal_fx", 15000, 1, "int");
  clientfield::register("actor", "margwa_shock_fx", 15000, 1, "int");
  var_91a17b7d = getEntArray("zombie_wasp_elite_spawner", "script_noteworthy");
  if(isDefined(var_91a17b7d) && var_91a17b7d.size > 0) {
    level.var_39c0c115 = var_91a17b7d[0];
  }
  zm::register_actor_damage_callback(&function_5ff4198);
  level thread function_15492d9b();
}

function private function_afef488b() {
  behaviortreenetworkutility::registerbehaviortreescriptapi("zmMargwaFireAttackService", &brrebirth_triggerrespawnoverlay);
  behaviortreenetworkutility::registerbehaviortreescriptapi("zmMargwaFireDefendService", &function_c8dea044);
  behaviortreenetworkutility::registerbehaviortreescriptapi("zmMargwaElectricGroundAttackService", &function_744188c1);
  behaviortreenetworkutility::registerbehaviortreescriptapi("zmMargwaElectricShootAttackService", &function_7652cccb);
  behaviortreenetworkutility::registerbehaviortreescriptapi("zmMargwaElectricDefendService", &function_39eece3f);
  behaviortreenetworkutility::registerbehaviortreescriptapi("zmMargwaLightAttackService", &function_655b9672);
  behaviortreenetworkutility::registerbehaviortreescriptapi("zmMargwaLightDefendService", &function_64e5bb2);
  behaviortreenetworkutility::registerbehaviortreescriptapi("zmMargwaShadowAttackService", &function_43079630);
  behaviortreenetworkutility::registerbehaviortreescriptapi("zmMargwaShadowDefendService", &function_50654c28);
  behaviortreenetworkutility::registerbehaviortreescriptapi("zmMargwaShouldFireAttack", &function_78f83c26);
  behaviortreenetworkutility::registerbehaviortreescriptapi("zmMargwaShouldFireDefendOut", &function_782e86fb);
  behaviortreenetworkutility::registerbehaviortreescriptapi("zmMargwaShouldFireDefendIn", &function_836eeae4);
  behaviortreenetworkutility::registerbehaviortreescriptapi("zmMargwaShouldElectricGroundAttack", &function_eb0118e7);
  behaviortreenetworkutility::registerbehaviortreescriptapi("zmMargwaShouldElectricShootAttack", &function_2672a46d);
  behaviortreenetworkutility::registerbehaviortreescriptapi("zmMargwaShouldElectricDefendOut", &function_efc320f8);
  behaviortreenetworkutility::registerbehaviortreescriptapi("zmMargwaShouldElectricDefendIn", &function_bcd55721);
  behaviortreenetworkutility::registerbehaviortreescriptapi("zmMargwaShouldLightAttack", &function_fd4fb480);
  behaviortreenetworkutility::registerbehaviortreescriptapi("zmMargwaShouldLightDefendOut", &function_5bfc92ed);
  behaviortreenetworkutility::registerbehaviortreescriptapi("zmMargwaShouldLightDefendIn", &function_412d8b9a);
  behaviortreenetworkutility::registerbehaviortreescriptapi("zmMargwaShouldShadowAttack", &function_dfedf376);
  behaviortreenetworkutility::registerbehaviortreescriptapi("zmMargwaShouldShadowAttackLoop", &function_a5dc38a7);
  behaviortreenetworkutility::registerbehaviortreescriptapi("zmMargwaShouldShadowAttackOut", &function_f2802e4b);
  behaviortreenetworkutility::registerbehaviortreescriptapi("zmMargwaShouldShadowDefendOut", &function_87dfc76b);
  behaviortreenetworkutility::registerbehaviortreescriptapi("zmMargwaShouldShadowDefendIn", &function_6af3c534);
  behaviortreenetworkutility::registerbehaviortreescriptapi("zmMargwaFireAttack", &function_face7ad8);
  behaviortreenetworkutility::registerbehaviortreescriptapi("zmMargwaFireAttackTerminate", &function_68e3291c);
  behaviortreenetworkutility::registerbehaviortreescriptapi("zmMargwaFireDefendOut", &function_99ba2c25);
  behaviortreenetworkutility::registerbehaviortreescriptapi("zmMargwaFireDefendOutTerminate", &function_6a7ddf05);
  behaviortreenetworkutility::registerbehaviortreescriptapi("zmMargwaFireDefendIn", &function_75f40972);
  behaviortreenetworkutility::registerbehaviortreescriptapi("zmMargwaFireDefendInTerminate", &function_cd27e3fa);
  behaviortreenetworkutility::registerbehaviortreescriptapi("zmMargwaElectricGroundAttack", &function_b473ad25);
  behaviortreenetworkutility::registerbehaviortreescriptapi("zmMargwaElectricShootAttack", &function_6619b5ab);
  behaviortreenetworkutility::registerbehaviortreescriptapi("zmMargwaElectricDefendOut", &function_8382b576);
  behaviortreenetworkutility::registerbehaviortreescriptapi("zmMargwaElectricDefendOutTerminate", &function_3c8bea36);
  behaviortreenetworkutility::registerbehaviortreescriptapi("zmMargwaElectricDefendIn", &function_11d72a03);
  behaviortreenetworkutility::registerbehaviortreescriptapi("zmMargwaLightAttack", &function_226a6f4a);
  behaviortreenetworkutility::registerbehaviortreescriptapi("zmMargwaLightDefendOut", &function_9c7737ef);
  behaviortreenetworkutility::registerbehaviortreescriptapi("zmMargwaLightDefendOutTerminate", &function_5d88ac4b);
  behaviortreenetworkutility::registerbehaviortreescriptapi("zmMargwaLightDefendIn", &function_c2614d30);
  behaviortreenetworkutility::registerbehaviortreescriptapi("zmMargwaShadowAttack", &function_9a9f35ac);
  behaviortreenetworkutility::registerbehaviortreescriptapi("zmMargwaShadowAttackLoop", &function_ae1bcedd);
  behaviortreenetworkutility::registerbehaviortreescriptapi("zmMargwaShadowAttackLoopTerminate", &function_58c0f99d);
  behaviortreenetworkutility::registerbehaviortreescriptapi("zmMargwaShadowAttackOutTerminate", &function_d89cf919);
  behaviortreenetworkutility::registerbehaviortreescriptapi("zmMargwaShadowDefendOut", &function_d765e859);
  behaviortreenetworkutility::registerbehaviortreescriptapi("zmMargwaShadowDefendOutTerminate", &function_4600a191);
  behaviortreenetworkutility::registerbehaviortreescriptapi("zmMargwaShadowDefendIn", &function_d258371e);
  behaviortreenetworkutility::registerbehaviortreescriptapi("zmMargwaIsElectric", &function_3cfb8731);
  behaviortreenetworkutility::registerbehaviortreescriptapi("zmMargwaIsFire", &function_6bbd2a18);
  behaviortreenetworkutility::registerbehaviortreescriptapi("zmMargwaIsLight", &function_7db0458);
  behaviortreenetworkutility::registerbehaviortreescriptapi("zmMargwaIsShadow", &function_b9fad980);
}

function function_eb5051f4(spawner, targetname, var_f9ebd43e, s_location) {
  if(isDefined(spawner)) {
    level.margwa_head_left_model_override = undefined;
    level.margwa_head_mid_model_override = undefined;
    level.margwa_head_right_model_override = undefined;
    level.margwa_gore_left_model_override = undefined;
    level.margwa_gore_mid_model_override = undefined;
    level.margwa_gore_right_model_override = undefined;
    switch (var_f9ebd43e) {
      case "fire": {
        level.margwa_head_left_model_override = "c_zom_dlc4_margwa_chunks_le_fire";
        level.margwa_head_mid_model_override = "c_zom_dlc4_margwa_chunks_mid_fire";
        level.margwa_head_right_model_override = "c_zom_dlc4_margwa_chunks_ri_fire";
        level.margwa_gore_left_model_override = "c_zom_dlc4_margwa_gore_le_fire";
        level.margwa_gore_mid_model_override = "c_zom_dlc4_margwa_gore_mid_fire";
        level.margwa_gore_right_model_override = "c_zom_dlc4_margwa_gore_ri_fire";
        break;
      }
      case "shadow": {
        level.margwa_head_left_model_override = "c_zom_dlc4_margwa_chunks_le_shadow";
        level.margwa_head_mid_model_override = "c_zom_dlc4_margwa_chunks_mid_shadow";
        level.margwa_head_right_model_override = "c_zom_dlc4_margwa_chunks_ri_shadow";
        level.margwa_gore_left_model_override = "c_zom_dlc4_margwa_gore_le_shadow";
        level.margwa_gore_mid_model_override = "c_zom_dlc4_margwa_gore_mid_shadow";
        level.margwa_gore_right_model_override = "c_zom_dlc4_margwa_gore_ri_shadow";
        break;
      }
    }
    spawner.script_forcespawn = 1;
    ai = zombie_utility::spawn_zombie(spawner, targetname, s_location);
    level.margwa_head_left_model_override = undefined;
    level.margwa_head_mid_model_override = undefined;
    level.margwa_head_right_model_override = undefined;
    level.margwa_gore_left_model_override = undefined;
    level.margwa_gore_mid_model_override = undefined;
    level.margwa_gore_right_model_override = undefined;
    if(isDefined(level.var_fd47363)) {
      level.margwa_head_left_model_override = level.var_fd47363["head_le"];
      level.margwa_head_mid_model_override = level.var_fd47363["head_mid"];
      level.margwa_head_right_model_override = level.var_fd47363["head_ri"];
      level.margwa_gore_left_model_override = level.var_fd47363["gore_le"];
      level.margwa_gore_mid_model_override = level.var_fd47363["gore_mid"];
      level.margwa_gore_right_model_override = level.var_fd47363["gore_ri"];
    }
    ai disableaimassist();
    ai.actor_damage_func = &margwaserverutils::margwadamage;
    ai.candamage = 0;
    ai.targetname = targetname;
    ai.holdfire = 1;
    ai function_c0ff1e9(var_f9ebd43e);
    switch (var_f9ebd43e) {
      case "fire": {
        ai clientfield::set("margwa_elemental_type", 1);
        break;
      }
      case "electric": {
        ai clientfield::set("margwa_elemental_type", 2);
        break;
      }
      case "light": {
        ai clientfield::set("margwa_elemental_type", 3);
        break;
      }
      case "shadow": {
        ai clientfield::set("margwa_elemental_type", 4);
        break;
      }
    }
    ai.n_start_health = self.health;
    ai.team = level.zombie_team;
    ai.canstun = 1;
    ai.thundergun_fling_func = &zm_ai_margwa::function_7292417a;
    ai.thundergun_knockdown_func = &zm_ai_margwa::function_94fd1710;
    ai.var_23340a5d = &zm_ai_margwa::function_7292417a;
    ai.var_e1dbd63 = &zm_ai_margwa::function_94fd1710;
    e_player = zm_utility::get_closest_player(s_location.origin);
    v_dir = e_player.origin - s_location.origin;
    v_dir = vectornormalize(v_dir);
    v_angles = vectortoangles(v_dir);
    ai forceteleport(s_location.origin, v_angles);
    ai function_551e32b4();
    ai thread function_8d578a58();
    ai.ignore_round_robbin_death = 1;
    ai.ignore_devgui_death = 1;
    ai thread zm_ai_margwa::function_618bf323();
    ai thread function_3d56f587();
    level thread zm_spawner::zombie_death_event(ai);
    return ai;
  }
  return undefined;
}

function function_75b161ab(spawner, s_location) {
  if(!isDefined(spawner)) {
    var_fda751f9 = getspawnerarray("zombie_margwa_fire_spawner", "script_noteworthy");
    if(var_fda751f9.size <= 0) {
      iprintln("");
      return;
    }
    spawner = var_fda751f9[0];
  }
  spawner_targetname = "margwa_fire";
  var_f9ebd43e = "fire";
  ai = function_eb5051f4(spawner, spawner_targetname, var_f9ebd43e, s_location);
  return ai;
}

function function_26efbc37(spawner, s_location) {
  if(!isDefined(spawner)) {
    var_5e8312fd = getspawnerarray("zombie_margwa_shadow_spawner", "script_noteworthy");
    if(var_5e8312fd.size <= 0) {
      iprintln("");
      return;
    }
    spawner = var_5e8312fd[0];
  }
  spawner_targetname = "margwa_shadow";
  var_f9ebd43e = "shadow";
  ai = function_eb5051f4(spawner, spawner_targetname, var_f9ebd43e, s_location);
  return ai;
}

function function_12301fd1(spawner, s_location) {
  if(!isDefined(spawner)) {
    var_1977e3bb = getspawnerarray("zombie_margwa_light_spawner", "script_noteworthy");
    if(var_1977e3bb.size <= 0) {
      iprintln("");
      return;
    }
    spawner = var_1977e3bb[0];
  }
  spawner_targetname = "margwa_light";
  var_f9ebd43e = "light";
  ai = function_eb5051f4(spawner, spawner_targetname, var_f9ebd43e, s_location);
  return ai;
}

function function_5b1c9e5c(spawner, s_location) {
  if(!isDefined(spawner)) {
    var_9ceb03c8 = getspawnerarray("zombie_margwa_electricity_spawner", "script_noteworthy");
    if(var_9ceb03c8.size <= 0) {
      iprintln("");
      return;
    }
    spawner = var_9ceb03c8[0];
  }
  spawner_targetname = "margwa_electric";
  var_f9ebd43e = "electric";
  ai = function_eb5051f4(spawner, spawner_targetname, var_f9ebd43e, s_location);
  return ai;
}

function private function_3d56f587() {
  util::wait_network_frame();
  self clientfield::increment("margwa_fx_spawn");
  wait(3);
  self function_26c35525();
  self.candamage = 1;
  self.needspawn = 1;
}

function private function_551e32b4() {
  self.isfrozen = 1;
  self.dontshow = 1;
  self ghost();
  self notsolid();
  self pathmode("dont move");
}

function private function_26c35525() {
  self.isfrozen = 0;
  self show();
  self solid();
  self pathmode("move allowed");
}

function private function_8d578a58() {
  self waittill("death", attacker, mod, weapon);
  foreach(player in level.players) {
    if(player.am_i_valid && (!(isDefined(level.var_1f6ca9c8) && level.var_1f6ca9c8)) && (!(isDefined(self.var_2d5d7413) && self.var_2d5d7413))) {
      scoreevents::processscoreevent("kill_margwa", player, undefined, undefined);
    }
  }
  level notify("hash_1a2d33d7");
  if(isDefined(function_6bbd2a18(self)) && function_6bbd2a18(self)) {
    function_396590c8(self.origin, 128);
  }
  if(isDefined(function_b9fad980(self)) && function_b9fad980(self)) {
    self clientfield::set("shadow_margwa_attack_portal_fx", 0);
    function_3572faf3(self.origin, 128);
  }
  if(isDefined(level.var_7cef68dc)) {
    [[level.var_7cef68dc]]();
  }
}

function private function_396590c8(pos, range) {
  a_zombies = function_181f65f7(pos, range);
  foreach(zombie in a_zombies) {
    zombie zm_elemental_zombie::function_f4defbc2();
  }
}

function private function_3572faf3(pos, range) {
  a_zombies = function_181f65f7(pos, range);
  foreach(zombie in a_zombies) {
    zombie zm_shadow_zombie::function_1b2b62b();
  }
}

function function_181f65f7(pos, range) {
  var_7843fa64 = zm_elemental_zombie::function_d41418b8();
  a_zombies = array::get_all_closest(pos, var_7843fa64, undefined, undefined, range);
  return a_zombies;
}

function private function_c0ff1e9(var_f9ebd43e) {
  self.var_f9ebd43e = var_f9ebd43e;
}

function function_6bbd2a18(entity) {
  if(isDefined(entity) && isDefined(entity.var_f9ebd43e) && entity.var_f9ebd43e == "fire") {
    return true;
  }
  return false;
}

function function_3cfb8731(entity) {
  if(isDefined(entity) && isDefined(entity.var_f9ebd43e) && entity.var_f9ebd43e == "electric") {
    return true;
  }
  return false;
}

function function_7db0458(entity) {
  if(isDefined(entity) && isDefined(entity.var_f9ebd43e) && entity.var_f9ebd43e == "light") {
    return true;
  }
  return false;
}

function function_b9fad980(entity) {
  if(isDefined(entity) && isDefined(entity.var_f9ebd43e) && entity.var_f9ebd43e == "shadow") {
    return true;
  }
  return false;
}

function private function_e1859566() {
  self.zombie_lift_override = &function_2ab5f647;
  self function_68ff73f4();
  self function_1d2f460c();
  self function_3c6c3309();
  self function_36cf9d7();
  self function_4e78142b();
  self function_1da8deb6();
  self function_6ae4a816();
  self function_e268d040();
  self function_246f9ba8();
}

function private function_68ff73f4() {
  self.var_16ee8ac0 = gettime() + 20000;
}

function private function_1d2f460c() {
  self.var_5ef5dff8 = gettime() + 20000;
}

function private function_3c6c3309() {
  self.var_57ad950f = gettime() + 6000;
}

function private function_36cf9d7() {
  self.var_a5ab6e8d = gettime() + 6000;
}

function private function_4e78142b() {
  self.var_7294169 = gettime() + 7500;
}

function private function_1da8deb6() {
  self.var_44d78ba2 = gettime() + 3000;
}

function private function_6ae4a816() {
  self.var_c0e54902 = gettime() + 20000;
}

function private function_e268d040() {
  self.var_70f89c94 = gettime() + 20000;
}

function private function_246f9ba8() {
  self.var_3a9ed1bc = gettime() + 20000;
}

function private function_4f4a272(right_offset) {
  origin = self.origin;
  if(isDefined(right_offset)) {
    right_angle = anglestoright(self.angles);
    origin = origin + (right_angle * right_offset);
  }
  facing_vec = anglesToForward(self.angles);
  enemy_vec = self.favoriteenemy.origin - origin;
  enemy_yaw_vec = (enemy_vec[0], enemy_vec[1], 0);
  facing_yaw_vec = (facing_vec[0], facing_vec[1], 0);
  enemy_yaw_vec = vectornormalize(enemy_yaw_vec);
  facing_yaw_vec = vectornormalize(facing_yaw_vec);
  enemy_dot = vectordot(facing_yaw_vec, enemy_yaw_vec);
  if(enemy_dot < 0.5) {
    return false;
  }
  enemy_angles = vectortoangles(enemy_vec);
  if(abs(angleclamp180(enemy_angles[0])) > 60) {
    return false;
  }
  return true;
}

function private brrebirth_triggerrespawnoverlay(entity) {
  if(!function_6bbd2a18(entity)) {
    return false;
  }
  if(isDefined(entity.var_322364e8) && entity.var_322364e8) {
    entity.var_4ad63d98 = 1;
    return true;
  }
  time = gettime();
  entity.var_4ad63d98 = 0;
  if(time < entity.var_16ee8ac0) {
    return false;
  }
  if(isDefined(entity.var_b696faa3) && entity.var_b696faa3) {
    return false;
  }
  if(isDefined(entity.var_dd350502) && entity.var_dd350502) {
    return false;
  }
  if(!isDefined(entity.favoriteenemy)) {
    return false;
  }
  if(!entity function_4f4a272()) {
    return false;
  }
  if(!entity cansee(entity.favoriteenemy)) {
    return false;
  }
  dist_sq = distancesquared(entity.origin, entity.favoriteenemy.origin);
  if(dist_sq < 62500 || dist_sq > 1440000) {
    return false;
  }
  entity.var_4ad63d98 = 1;
  return true;
}

function private function_c8dea044(entity) {
  if(!function_6bbd2a18(entity)) {
    return false;
  }
  if(entity.headattached > 2) {
    return false;
  }
  if(isDefined(entity.favoriteenemy) && (isDefined(entity.favoriteenemy.is_flung) && entity.favoriteenemy.is_flung)) {
    return false;
  }
  if(gettime() > entity.var_5ef5dff8) {
    entity.var_501a54e5 = 1;
    return true;
  }
  return false;
}

function private function_744188c1(entity) {
  entity.var_6d87f4e5 = 0;
  if(!function_3cfb8731(entity)) {
    return false;
  }
  if(gettime() > entity.var_57ad950f) {
    entity.var_6d87f4e5 = 1;
    return true;
  }
  if(!isDefined(entity.favoriteenemy)) {
    return false;
  }
  if(!entity function_4f4a272()) {
    return false;
  }
  if(!entity cansee(entity.favoriteenemy)) {
    return false;
  }
  dist_sq = distancesquared(entity.origin, entity.favoriteenemy.origin);
  if(dist_sq < 62500 || dist_sq > 1440000) {
    return false;
  }
  entity.var_6d87f4e5 = 1;
  return true;
}

function private function_7652cccb(entity) {
  if(!function_3cfb8731(entity)) {
    return false;
  }
  entity.var_c521ba6b = 0;
  if(gettime() > entity.var_a5ab6e8d) {
    entity.var_c521ba6b = 1;
    return true;
  }
  if(!isDefined(entity.favoriteenemy)) {
    return false;
  }
  if(!entity function_4f4a272()) {
    return false;
  }
  if(!entity cansee(entity.favoriteenemy)) {
    return false;
  }
  dist_sq = distancesquared(entity.origin, entity.favoriteenemy.origin);
  if(dist_sq < 62500 || dist_sq > 1440000) {
    return false;
  }
  entity.var_c521ba6b = 1;
  return true;
}

function private function_39eece3f(entity) {
  entity.var_a48cbe36 = 0;
  if(!function_3cfb8731(entity)) {
    return false;
  }
  if(gettime() < entity.var_7294169) {
    return false;
  }
  dist_sq = distancesquared(entity.origin, entity.favoriteenemy.origin);
  if(dist_sq < 129600 || dist_sq > 921600) {
    return false;
  }
  entity.var_a48cbe36 = 1;
  return true;
}

function private function_655b9672(entity) {
  if(!function_7db0458(entity)) {
    return false;
  }
  entity.var_d3c45f0a = 0;
  if(gettime() > entity.var_44d78ba2) {
    entity.var_d3c45f0a = 1;
    return true;
  }
  if(!isDefined(entity.favoriteenemy)) {
    return false;
  }
  if(!entity cansee(entity.favoriteenemy)) {
    return false;
  }
  dist_sq = distancesquared(entity.origin, entity.favoriteenemy.origin);
  if(dist_sq < 62500 || dist_sq > 1440000) {
    return false;
  }
  entity.var_d3c45f0a = 1;
  return true;
}

function private function_64e5bb2(entity) {
  if(!function_7db0458(entity)) {
    return false;
  }
  if(gettime() > entity.var_c0e54902) {
    entity.var_623927af = 1;
    return true;
  }
  return false;
}

function private function_43079630(entity) {
  if(!function_b9fad980(entity)) {
    return false;
  }
  if(isDefined(entity.var_3c58b79c) && entity.var_3c58b79c) {
    entity.var_321306c = 1;
    return true;
  }
  entity.var_321306c = 0;
  if(isDefined(entity.var_187c138e) && entity.var_187c138e) {
    return false;
  }
  if(isDefined(entity.isteleporting) && entity.isteleporting) {
    return false;
  }
  if(gettime() < entity.var_70f89c94) {
    return false;
  }
  if(!isDefined(entity.favoriteenemy)) {
    return false;
  }
  if(!entity cansee(entity.favoriteenemy)) {
    return false;
  }
  if(!entity function_4f4a272()) {
    return false;
  }
  dist_sq = distancesquared(entity.origin, entity.favoriteenemy.origin);
  if(dist_sq < 16384 || dist_sq > 589824) {
    return false;
  }
  entity.var_321306c = 1;
  return true;
}

function private function_50654c28(entity) {
  if(!function_b9fad980(entity)) {
    return false;
  }
  if(entity.headattached > 2) {
    return false;
  }
  if(isDefined(entity.favoriteenemy) && (isDefined(entity.favoriteenemy.is_flung) && entity.favoriteenemy.is_flung)) {
    return false;
  }
  if(isDefined(entity.var_187c138e) && entity.var_187c138e) {
    return false;
  }
  if(gettime() > entity.var_3a9ed1bc) {
    entity.var_e9353b19 = 1;
    return true;
  }
  return false;
}

function private function_78f83c26(entity) {
  if(isDefined(entity.var_4ad63d98) && entity.var_4ad63d98) {
    return true;
  }
  return false;
}

function private function_782e86fb(entity) {
  return false;
}

function private function_836eeae4(entity) {
  return false;
}

function private function_eb0118e7(entity) {
  if(isDefined(entity.var_6d87f4e5) && entity.var_6d87f4e5) {
    return true;
  }
  return false;
}

function private function_2672a46d(entity) {
  if(isDefined(entity.var_c521ba6b) && entity.var_c521ba6b) {
    return true;
  }
  return false;
}

function private function_efc320f8(entity) {
  if(isDefined(entity.var_a48cbe36) && entity.var_a48cbe36) {
    return true;
  }
  return false;
}

function private function_bcd55721(entity) {
  if(isDefined(entity.var_523cacc3) && entity.var_523cacc3) {
    return true;
  }
  return false;
}

function private function_fd4fb480(entity) {
  if(isDefined(entity.var_d3c45f0a) && entity.var_d3c45f0a) {
    return true;
  }
  return false;
}

function private function_5bfc92ed(entity) {
  if(isDefined(entity.var_623927af) && entity.var_623927af) {
    return true;
  }
  return false;
}

function private function_412d8b9a(entity) {
  if(isDefined(entity.var_5df615f0) && entity.var_5df615f0) {
    return true;
  }
  return false;
}

function private function_dfedf376(entity) {
  if(isDefined(entity.var_321306c) && entity.var_321306c) {
    return true;
  }
  return false;
}

function private function_a5dc38a7(entity) {
  if(isDefined(entity.var_1ab20b9b)) {
    if(gettime() > entity.var_1ab20b9b) {
      return false;
    }
  }
  return true;
}

function private function_f2802e4b(entity) {
  if(isDefined(entity.var_6a2ba141) && entity.var_6a2ba141) {
    return true;
  }
  return false;
}

function private function_87dfc76b(entity) {
  return false;
}

function private function_6af3c534(entity) {
  return false;
}

function private function_face7ad8(entity) {
  entity endon("death");
  entity.var_322364e8 = 0;
  entity thread function_90ec324d();
}

function private function_90ec324d() {
  self.var_dd350502 = 1;
  foreach(head in self.head) {
    if(!(isDefined(head.candamage) && head.candamage)) {
      head.var_13ac78ab = 0;
      head.candamage = 1;
      continue;
    }
    head.var_13ac78ab = 1;
  }
  self waittill("hash_b55b6f2b");
  foreach(head in self.head) {
    if(!(isDefined(head.var_13ac78ab) && head.var_13ac78ab)) {
      head.candamage = 0;
    }
  }
  if(isDefined(self.favoriteenemy)) {
    var_70b6278d = self.favoriteenemy.origin - self.origin;
    var_68149ff9 = vectornormalize(var_70b6278d);
    target_entity = self.favoriteenemy;
  } else {
    var_68149ff9 = anglesToForward(self.angles);
  }
  var_1642db30 = var_68149ff9;
  var_74475c34 = int(13.33333);
  position = self.origin;
  var_898f5d33 = spawn("script_model", position);
  var_898f5d33 setModel("tag_origin");
  level thread function_396590c8(position, 48);
  torpedo_yaw_per_interval = 13.5;
  torpedo_max_yaw_cos = cos(torpedo_yaw_per_interval);
  for(i = 0; i <= var_74475c34; i++) {
    self function_68ff73f4();
    position = position + vectorscale((0, 0, 1), 32);
    if(isDefined(target_entity)) {
      torpedo_target_point = target_entity.origin;
      vector_to_target = torpedo_target_point - position;
      normal_vector = vectornormalize(vector_to_target);
      flat_mapped_normal_vector = vectornormalize((normal_vector[0], normal_vector[1], 0));
      flat_mapped_old_normal_vector = vectornormalize((var_1642db30[0], var_1642db30[1], 0));
      dot = vectordot(flat_mapped_normal_vector, flat_mapped_old_normal_vector);
      if(dot >= 1) {
        dot = 1;
      } else if(dot <= -1) {
        dot = -1;
      }
      if(dot < torpedo_max_yaw_cos) {
        new_vector = normal_vector - var_1642db30;
        angle_between_vectors = acos(dot);
        if(!isDefined(angle_between_vectors)) {
          angle_between_vectors = 180;
        }
        if(angle_between_vectors == 0) {
          angle_between_vectors = 0.0001;
        }
        max_angle_per_interval = 13.5;
        ratio = max_angle_per_interval / angle_between_vectors;
        if(ratio > 1) {
          ratio = 1;
        }
        new_vector = new_vector * ratio;
        new_vector = new_vector + var_1642db30;
        normal_vector = vectornormalize(new_vector);
      } else {
        normal_vector = var_1642db30;
      }
    }
    if(!isDefined(normal_vector)) {
      normal_vector = var_1642db30;
    }
    var_98258f16 = normal_vector * 48;
    var_1642db30 = normal_vector;
    target_pos = position + var_98258f16;
    if(bullettracepassed(position, target_pos, 0, self)) {
      trace = bulletTrace(target_pos, target_pos - vectorscale((0, 0, 1), 64), 0, self);
      if(!isDefined(trace["position"])) {
        continue;
      }
      position = trace["position"];
      var_898f5d33 moveto(position, 0.15);
      var_898f5d33 waittill("movedone");
      var_898f5d33 clientfield::increment("play_margwa_fire_attack_fx");
      var_898f5d33 thread function_396590c8(position, 48);
      self thread function_308ca6aa(position, 48, 30, "MOD_BURNED");
      if(isDefined(target_entity) && distancesquared(target_entity.origin, position) <= 2304) {
        break;
      }
      continue;
    }
    break;
  }
  self.var_dd350502 = 0;
}

function private function_68e3291c(entity) {
  entity function_68ff73f4();
}

function private function_99ba2c25(entity) {
  entity function_1d2f460c();
  entity.isteleporting = 1;
  entity.var_501a54e5 = 0;
  entity.var_b696faa3 = 1;
}

function private function_6a7ddf05(entity) {
  entity clientfield::set("margwa_defense_actor_appear_disappear_fx", 1);
  entity ghost();
  entity pathmode("dont move");
  entity thread function_ced695a8();
}

function private function_ced695a8() {
  self.waiting = 1;
  var_c37d9885 = vectorscale((0, 0, 1), 64);
  self function_258d1434(var_c37d9885, 240, 480);
  if(isDefined(self.var_937645c5)) {
    self.var_937645c5 clientfield::set("margwa_defense_hovering_fx", 1);
  }
  if(isDefined(self.var_b978c02e)) {
    self.var_b978c02e clientfield::set("margwa_defense_hovering_fx", 1);
  }
  if(isDefined(self.var_df7b3a97)) {
    self.var_df7b3a97 clientfield::set("margwa_defense_hovering_fx", 1);
  }
  self forceteleport(self.var_58b84a32);
  wait(1);
  self.waiting = 0;
  self.var_847ae832 = 1;
}

function private function_794b06f(point) {
  return zm_utility::check_point_in_playable_area(point.origin) && zm_utility::check_point_in_enabled_zone(point.origin);
}

function private function_75f40972(entity) {
  entity show();
  entity pathmode("move allowed");
  entity.isteleporting = 0;
  entity.var_847ae832 = 0;
  if(isDefined(self.var_937645c5)) {
    self.var_937645c5 clientfield::set("margwa_defense_hovering_fx", 0);
  }
  if(isDefined(self.var_b978c02e)) {
    self.var_b978c02e clientfield::set("margwa_defense_hovering_fx", 0);
  }
  if(isDefined(self.var_df7b3a97)) {
    self.var_df7b3a97 clientfield::set("margwa_defense_hovering_fx", 0);
  }
  wait(0.05);
  if(isDefined(self.var_937645c5)) {
    self.var_937645c5 delete();
  }
  if(isDefined(self.var_b978c02e)) {
    self.var_b978c02e delete();
  }
  if(isDefined(self.var_df7b3a97)) {
    self.var_df7b3a97 delete();
  }
}

function private function_cd27e3fa(entity) {
  entity.var_b696faa3 = 0;
}

function private function_b473ad25(entity) {
  entity function_3c6c3309();
}

function private function_6619b5ab(entity) {
  entity function_36cf9d7();
}

function private function_8382b576(entity) {
  entity function_4e78142b();
  entity.isteleporting = 1;
  entity.var_a48cbe36 = 0;
}

function private function_3c8bea36(entity) {
  if(isDefined(entity.traveler)) {
    entity.traveler.origin = entity gettagorigin("j_spine_1");
    entity.traveler clientfield::set("margwa_fx_travel", 1);
  }
  entity ghost();
  entity pathmode("dont move");
  if(isDefined(entity.traveler)) {
    entity linkto(entity.traveler);
  }
  entity thread function_aa4e7619();
}

function private function_aa4e7619() {
  self.waiting = 1;
  goal_pos = self.enemy.origin;
  if(isDefined(self.enemy.last_valid_position)) {
    goal_pos = self.enemy.last_valid_position;
  }
  path = self calcapproximatepathtoposition(goal_pos, 0);
  var_2fd16fa4 = randomintrange(96, 192);
  segment_length = 0;
  teleport_point = [];
  var_f2593821 = 0;
  for(index = 1; index < path.size; index++) {
    var_cabd9641 = distance(path[index - 1], path[index]);
    if((segment_length + var_cabd9641) > var_2fd16fa4) {
      var_bee1a4a2 = var_2fd16fa4 - segment_length;
      var_5a78f4fc = (path[index - 1]) + ((vectornormalize(path[index] - (path[index - 1]))) * var_bee1a4a2);
      query_result = positionquery_source_navigation(var_5a78f4fc, 64, 128, 36, 16, self, 16);
      if(query_result.data.size > 0) {
        point = query_result.data[randomint(query_result.data.size)];
        teleport_point[var_f2593821] = point.origin;
        var_f2593821++;
        if(var_f2593821 == 3) {
          break;
        }
      }
    }
  }
  foreach(point in teleport_point) {
    var_bd23de7b = point + vectorscale((0, 0, 1), 60);
    dist = distance(self.traveler.origin, var_bd23de7b);
    time = dist / 1200;
    if(time < 0.1) {
      time = 0.1;
    }
    if(isDefined(self.traveler)) {
      self.traveler moveto(var_bd23de7b, time);
      self.traveler util::waittill_any_timeout(time, "movedone");
    }
  }
  self.teleportpos = point;
  self.waiting = 0;
  self.var_523cacc3 = 1;
}

function private function_11d72a03(entity) {
  entity unlink();
  if(isDefined(entity.teleportpos)) {
    entity forceteleport(entity.teleportpos);
  }
  entity show();
  entity pathmode("move allowed");
  entity.isteleporting = 0;
  entity.var_523cacc3 = 0;
  entity.traveler clientfield::set("margwa_fx_travel", 0);
}

function private function_226a6f4a(entity) {
  entity function_1da8deb6();
  printtoprightln("");
}

function private function_9c7737ef(entity) {
  entity function_6ae4a816();
  entity.isteleporting = 1;
  entity.var_623927af = 0;
  printtoprightln("");
}

function private function_5d88ac4b(entity) {
  entity ghost();
  entity pathmode("dont move");
  entity thread function_f10db74e();
}

function private function_f10db74e() {
  self.waiting = 1;
  queryresult = positionquery_source_navigation(self.origin, 120, 360, 128, 32, self);
  pointlist = array::randomize(queryresult.data);
  self.var_58b84a32 = pointlist[0].origin;
  self forceteleport(self.var_58b84a32);
  wait(0.5);
  self.waiting = 0;
  self.var_5df615f0 = 1;
}

function private function_c2614d30(entity) {
  entity show();
  entity pathmode("move allowed");
  entity.isteleporting = 0;
  entity.var_5df615f0 = 0;
}

function private function_9a9f35ac(entity) {
  entity endon("death");
  var_3e944f2d = 0;
  entity.var_3c58b79c = 0;
  entity.var_187c138e = 1;
  entity.var_1ab20b9b = undefined;
  var_5ba5953 = anglesToForward(entity.angles);
  var_bc39bd09 = (entity.origin + vectorscale((0, 0, 1), 72)) + (var_5ba5953 * 96);
  var_1be3af57 = entity.angles;
  entity waittill("hash_64a0057e");
  entity clientfield::set("shadow_margwa_attack_portal_fx", 1);
  wait(0.5);
  target = undefined;
  if(isDefined(entity.favoriteenemy)) {
    position = var_bc39bd09 + (var_5ba5953 * 96);
    target = spawn("script_model", position);
    target setModel("tag_origin");
    target.var_8002cc8a = entity.favoriteenemy;
    target.owner = entity;
    target thread function_9a821f95();
  }
  while(var_3e944f2d < 4) {
    entity function_8969ba81(var_bc39bd09, var_1be3af57, target);
    var_3e944f2d = var_3e944f2d + 1;
    wait(0.25);
  }
  entity clientfield::set("shadow_margwa_attack_portal_fx", 0);
}

function private function_ae1bcedd(entity) {
  entity.var_1ab20b9b = gettime() + 1000;
}

function private function_58c0f99d(entity) {
  entity.var_6a2ba141 = 1;
}

function private function_d89cf919(entity) {
  entity.var_187c138e = 0;
  entity.var_6a2ba141 = 0;
  entity.var_70f89c94 = gettime() + 100000;
}

function private function_9a821f95() {
  self.owner util::waittill_any("shadow_margwa_skull_launched", "death");
  self.owner.var_ed0c0558 = array::remove_undefined(self.owner.var_ed0c0558, 0);
  margwa = self.owner;
  while(isDefined(self) && isDefined(self.var_8002cc8a) && isalive(self.var_8002cc8a) && isDefined(self.owner) && isDefined(self.owner.var_ed0c0558) && self.owner.var_ed0c0558.size > 0) {
    eye_position = self.var_8002cc8a gettagorigin("tag_eye");
    self.owner.var_ed0c0558 = array::remove_undefined(self.owner.var_ed0c0558, 0);
    if(distancesquared(self.origin, eye_position) <= 10000) {
      if(!(isDefined(self.var_d7c0356e) && self.var_d7c0356e)) {
        self.origin = eye_position;
        self linkto(self.var_8002cc8a, "tag_eye");
        self.var_d7c0356e = 1;
      }
    } else {
      var_2dca088d = eye_position - self.origin;
      var_6c4cc94d = vectornormalize(var_2dca088d);
      var_4037a81b = var_6c4cc94d * 50;
      var_5ae4b928 = self.origin + var_4037a81b;
      var_81e4178f = eye_position[2] - self.origin[2];
      bullet_trace = bulletTrace(var_5ae4b928 + (0, 0, var_81e4178f), var_5ae4b928 - (0, 0, var_81e4178f), 0, self.var_8002cc8a);
      if(isDefined(bullet_trace["position"])) {
        var_5ae4b928 = bullet_trace["position"] + (0, 0, var_81e4178f);
      }
      self moveto(var_5ae4b928, 0.2);
    }
    wait(0.2);
  }
  margwa function_e268d040();
  if(isDefined(self)) {
    if(isDefined(self.var_d7c0356e) && self.var_d7c0356e) {
      self unlink();
    }
    self delete();
  }
}

function private function_8969ba81(var_bc39bd09, var_1be3af57, target = undefined) {
  entity = self;
  weapon = getweapon("launcher_shadow_margwa");
  if(!isDefined(entity.var_ed0c0558)) {
    entity.var_ed0c0558 = [];
  }
  vector = anglesToForward(var_1be3af57);
  vector = vector * 250;
  vector = vector + vectorscale((0, 0, 1), 250);
  var_c4d58545 = randomint(100) - 50;
  var_36db14ca = randomint(100) - 50;
  var_71c4e537 = randomint(50) - 25;
  var_4126099a = vector + (var_c4d58545, var_36db14ca, var_71c4e537);
  if(!isDefined(target)) {
    skull = entity magicmissile(weapon, var_bc39bd09, var_4126099a);
    skull thread function_16cddcb6();
    entity.var_ed0c0558[entity.var_ed0c0558.size] = skull;
    entity notify("shadow_margwa_skull_launched");
  } else {
    skull = entity magicmissile(weapon, var_bc39bd09, var_4126099a, target);
    skull thread function_16cddcb6();
    entity.var_ed0c0558[entity.var_ed0c0558.size] = skull;
    entity notify("shadow_margwa_skull_launched");
  }
}

function function_16cddcb6() {
  self.takedamage = 1;
  var_b5f846f3 = 0;
  var_b52ddb1c = 100;
  if(isDefined(level.var_928e29b4)) {
    var_b52ddb1c = level.var_928e29b4;
  }
  while(isDefined(self)) {
    self waittill("damage", n_damage, e_attacker);
    if(isPlayer(e_attacker)) {
      var_b5f846f3 = var_b5f846f3 + n_damage;
      if(var_b5f846f3 >= var_b52ddb1c) {
        self detonate();
      }
    }
  }
}

function private function_d765e859(entity) {
  entity function_246f9ba8();
  entity.isteleporting = 1;
  entity.var_e9353b19 = 0;
}

function private function_4600a191(entity) {
  entity ghost();
  entity pathmode("dont move");
  entity thread function_2f67316c();
}

function private function_2f67316c() {
  self.waiting = 1;
  var_c37d9885 = vectorscale((0, 0, 1), 64);
  self function_258d1434(var_c37d9885, 240, 480);
  if(isDefined(self.var_937645c5)) {
    self.var_937645c5 clientfield::set("margwa_defense_hovering_fx", 4);
  }
  if(isDefined(self.var_b978c02e)) {
    self.var_b978c02e clientfield::set("margwa_defense_hovering_fx", 4);
  }
  if(isDefined(self.var_df7b3a97)) {
    self.var_df7b3a97 clientfield::set("margwa_defense_hovering_fx", 4);
  }
  self forceteleport(self.var_58b84a32);
  wait(1);
  self.waiting = 0;
  self.var_5760b1de = 1;
}

function private function_d258371e(entity) {
  entity show();
  entity pathmode("move allowed");
  entity.isteleporting = 0;
  entity.var_5760b1de = 0;
  entity thread function_34067c01();
}

function private function_34067c01() {
  if(isDefined(self.var_937645c5)) {
    self.var_937645c5 clientfield::set("margwa_defense_hovering_fx", 0);
  }
  if(isDefined(self.var_b978c02e)) {
    self.var_b978c02e clientfield::set("margwa_defense_hovering_fx", 0);
  }
  if(isDefined(self.var_df7b3a97)) {
    self.var_df7b3a97 clientfield::set("margwa_defense_hovering_fx", 0);
  }
  wait(0.05);
  if(isDefined(self.var_937645c5)) {
    self.var_937645c5 delete();
  }
  if(isDefined(self.var_b978c02e)) {
    self.var_b978c02e delete();
  }
  if(isDefined(self.var_df7b3a97)) {
    self.var_df7b3a97 delete();
  }
}

function private function_308ca6aa(position, range, damage, damage_mod) {
  margwa = self;
  players = getplayers();
  range_sq = range * range;
  foreach(player in players) {
    if(player laststand::player_is_in_laststand()) {
      continue;
    }
    dist_sq = distancesquared(position, player.origin);
    if(dist_sq <= range_sq) {
      player dodamage(damage, position, margwa, undefined, undefined, damage_mod);
    }
  }
}

function function_5ff4198(inflictor, attacker, damage, flags, meansofdeath, weapon, vpoint, vdir, shitloc, psoffsettime, boneindex, surfacetype) {
  if(isDefined(weapon) && weapon == getweapon("launcher_shadow_margwa")) {
    if(isDefined(attacker) && (self == attacker || self.team == attacker.team)) {
      if(self.archetype === "zombie" && zm_elemental_zombie::function_b804eb62(self)) {
        self zm_shadow_zombie::function_1b2b62b();
      }
      return 0;
    }
  }
  return -1;
}

function function_258d1434(var_c37d9885, var_6cd7eac7, var_19d406c9) {
  var_58b84a32 = self.origin;
  if(isDefined(self.favoriteenemy)) {
    var_58b84a32 = self.favoriteenemy.origin;
  }
  queryresult = positionquery_source_navigation(var_58b84a32, var_6cd7eac7, var_19d406c9, 256, 96, self);
  pointlist = array::randomize(queryresult.data);
  pointlist = array::filter(pointlist, 0, &function_794b06f);
  if(pointlist.size > 0) {
    self.var_58b84a32 = pointlist[0].origin;
    self.var_937645c5 = spawn("script_model", self.var_58b84a32 + var_c37d9885);
    self.var_937645c5 setModel("tag_origin");
    var_d1122efb = 1;
    if(isDefined(pointlist[1])) {
      self.var_b978c02e = spawn("script_model", pointlist[1].origin + var_c37d9885);
      self.var_b978c02e setModel("tag_origin");
      var_d1122efb = var_d1122efb + 1;
      if(isDefined(pointlist[2])) {
        self.var_df7b3a97 = spawn("script_model", pointlist[2].origin + var_c37d9885);
        self.var_df7b3a97 setModel("tag_origin");
        var_d1122efb = var_d1122efb + 1;
      }
    }
  } else {
    self.var_58b84a32 = self.origin;
    self.var_937645c5 = spawn("script_model", self.var_58b84a32 + var_c37d9885);
    self.var_937645c5 setModel("tag_origin");
    var_d1122efb = 1;
  }
  var_ce0ccfb0 = randomint(var_d1122efb);
  if(var_ce0ccfb0 === 1) {
    self.var_58b84a32 = pointlist[1].origin;
  }
  if(var_ce0ccfb0 === 2) {
    self.var_58b84a32 = pointlist[2].origin;
  }
}

function function_2ab5f647(e_player, v_attack_source, n_push_away, n_lift_height, v_lift_offset, n_lift_speed) {
  self endon("death");
  if(isDefined(self.in_gravity_trap) && self.in_gravity_trap && e_player.gravityspikes_state === 3) {
    if(isDefined(self.var_1f5fe943) && self.var_1f5fe943) {
      return;
    }
    self.var_bcecff1d = 1;
    self.var_1f5fe943 = 1;
    self dodamage(10, self.origin);
    self.var_3abf1eec = self.origin;
    scene = "cin_zm_dlc4_margwa_dth_deathray_01";
    if(self.var_f9ebd43e === "fire") {
      scene = "cin_zm_dlc4_margwa_fire_dth_deathray_01";
    }
    if(self.var_f9ebd43e === "shadow") {
      scene = "cin_zm_dlc4_margwa_shadow_dth_deathray_01";
    }
    self thread scene::play(scene, self);
    self clientfield::set("sparky_beam_fx", 1);
    self clientfield::set("margwa_shock_fx", 1);
    self playSound("zmb_talon_electrocute");
    n_start_time = gettime();
    n_total_time = 0;
    while(10 > n_total_time && e_player.gravityspikes_state === 3) {
      util::wait_network_frame();
      n_total_time = (gettime() - n_start_time) / 1000;
    }
    self scene::stop(scene);
    self thread function_3f3b0b14(self);
    self clientfield::set("sparky_beam_fx", 0);
    self clientfield::set("margwa_shock_fx", 0);
    self.var_bcecff1d = undefined;
    while(e_player.gravityspikes_state === 3) {
      util::wait_network_frame();
    }
    self.var_1f5fe943 = undefined;
    self.in_gravity_trap = undefined;
  } else {
    if(!(isDefined(self.reactstun) && self.reactstun)) {
      self.reactstun = 1;
    }
    self.in_gravity_trap = undefined;
  }
}

function function_3f3b0b14(margwa) {
  margwa endon("death");
  if(isDefined(margwa)) {
    self.var_3abf1eec = self.origin;
    scene = "cin_zm_dlc4_margwa_dth_deathray_02";
    if(self.var_f9ebd43e === "fire") {
      scene = "cin_zm_dlc4_margwa_fire_dth_deathray_02";
    }
    if(self.var_f9ebd43e === "shadow") {
      scene = "cin_zm_dlc4_margwa_shadow_dth_deathray_02";
    }
    margwa scene::play(scene, margwa);
  }
  if(isDefined(margwa) && isalive(margwa) && isDefined(margwa.var_3abf1eec)) {
    v_eye_pos = margwa gettagorigin("tag_eye");
    recordline(margwa.origin, v_eye_pos, vectorscale((0, 1, 0), 255), "", margwa);
    trace = bulletTrace(v_eye_pos, margwa.origin, 0, margwa);
    if(trace["position"] !== margwa.origin) {
      point = getclosestpointonnavmesh(trace["position"], 64, 30);
      if(!isDefined(point)) {
        point = margwa.var_3abf1eec;
      }
      margwa forceteleport(point);
    }
  }
}

function function_15492d9b() {
  wait(0.05);
  level waittill("start_zombie_round_logic");
  wait(0.05);
  str_cmd = "";
  adddebugcommand(str_cmd);
  str_cmd = "";
  adddebugcommand(str_cmd);
  str_cmd = "";
  adddebugcommand(str_cmd);
  str_cmd = "";
  adddebugcommand(str_cmd);
  while(true) {
    string = getdvarstring("");
    if(string === "") {
      level thread function_a06aa49e();
      setDvar("", "");
    }
    string = getdvarstring("");
    if(string === "") {
      level thread function_50a5b7b6();
      setDvar("", "");
    }
    string = getdvarstring("");
    if(string === "") {
      level thread function_d11bf3e();
      setDvar("", "");
    }
    string = getdvarstring("");
    if(string === "") {
      level thread function_156bbea2();
      setDvar("", "");
    }
    wait(0.05);
  }
}

function function_a06aa49e() {
  players = getplayers();
  var_fda751f9 = getspawnerarray("", "");
  if(var_fda751f9.size <= 0) {
    iprintln("");
    return;
  }
  margwa_spawner = var_fda751f9[0];
  queryresult = positionquery_source_navigation(players[0].origin, 128, 256, 128, 20);
  spot = spawnStruct();
  spot.origin = players[0].origin;
  if(isDefined(queryresult) && queryresult.data.size > 0) {
    spot.origin = queryresult.data[0].origin;
  }
  level function_75b161ab(margwa_spawner, spot);
}

function function_156bbea2() {
  players = getplayers();
  var_5e8312fd = getspawnerarray("", "");
  if(var_5e8312fd.size <= 0) {
    iprintln("");
    return;
  }
  margwa_spawner = var_5e8312fd[0];
  queryresult = positionquery_source_navigation(players[0].origin, 128, 256, 128, 20);
  spot = spawnStruct();
  spot.origin = players[0].origin;
  if(isDefined(queryresult) && queryresult.data.size > 0) {
    spot.origin = queryresult.data[0].origin;
  }
  level function_26efbc37(margwa_spawner, spot);
}

function function_f6720b6e() {
  players = getplayers();
  var_1977e3bb = getspawnerarray("", "");
  if(var_1977e3bb.size <= 0) {
    iprintln("");
    return;
  }
  margwa_spawner = var_1977e3bb[0];
  queryresult = positionquery_source_navigation(players[0].origin, 128, 256, 128, 20);
  spot = spawnStruct();
  spot.origin = players[0].origin;
  if(isDefined(queryresult) && queryresult.data.size > 0) {
    spot.origin = queryresult.data[0].origin;
  }
  level function_12301fd1(margwa_spawner, spot);
}

function function_812b0245() {
  players = getplayers();
  var_9ceb03c8 = getspawnerarray("", "");
  if(var_9ceb03c8.size <= 0) {
    iprintln("");
    return;
  }
  margwa_spawner = var_9ceb03c8[0];
  queryresult = positionquery_source_navigation(players[0].origin, 128, 256, 128, 20);
  spot = spawnStruct();
  spot.origin = players[0].origin;
  if(isDefined(queryresult) && queryresult.data.size > 0) {
    spot.origin = queryresult.data[0].origin;
  }
  level function_5b1c9e5c(margwa_spawner, spot);
}

function function_50a5b7b6() {
  var_9ca661a2 = getaiarchetypearray("");
  foreach(margwa in var_9ca661a2) {
    margwa kill();
  }
}

function function_d11bf3e() {
  var_9ca661a2 = getaiarchetypearray("");
  foreach(margwa in var_9ca661a2) {
    if(!isDefined(margwa.debughealth)) {
      margwa.debughealth = 1;
      continue;
    }
    margwa.debughealth = !margwa.debughealth;
  }
}