]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/turrets/turret/walker.qc
s/world/NULL/
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / turrets / turret / walker.qc
index eac40d22094eea782c12fdde95eced356a505469..1a5c3f09ab03aa5f51ec97d3b98ff386861781b9 100644 (file)
@@ -3,15 +3,15 @@
 
 //#define WALKER_FANCYPATHING
 
-#include "walker_weapon.qc"
+#include "walker_weapon.qh"
 
 CLASS(WalkerTurret, Turret)
 /* spawnflags */ ATTRIB(WalkerTurret, spawnflags, int, TUR_FLAG_PLAYER | TUR_FLAG_MOVE);
 /* mins       */ ATTRIB(WalkerTurret, mins, vector, '-70 -70 0');
 /* maxs       */ ATTRIB(WalkerTurret, maxs, vector, '70 70 95');
 /* modelname  */ ATTRIB(WalkerTurret, mdl, string, "walker_body.md3");
-/* model      */ ATTRIB(WalkerTurret, model, string, strzone(strcat("models/turrets/", this.mdl)));
-/* head_model */ ATTRIB(WalkerTurret, head_model, string, strzone(strcat("models/turrets/", "walker_head_minigun.md3")));
+/* model      */ ATTRIB_STRZONE(WalkerTurret, model, string, strcat("models/turrets/", this.mdl));
+/* head_model */ ATTRIB_STRZONE(WalkerTurret, head_model, string, strcat("models/turrets/", "walker_head_minigun.md3"));
 /* netname    */ ATTRIB(WalkerTurret, netname, string, "walker");
 /* fullname   */ ATTRIB(WalkerTurret, turret_name, string, _("Walker Turret"));
     ATTRIB(WalkerTurret, m_weapon, Weapon, WEP_WALKER);
@@ -22,8 +22,6 @@ REGISTER_TURRET(WALKER, NEW(WalkerTurret));
 
 #ifdef IMPLEMENTATION
 
-#include "walker_weapon.qc"
-
 #ifdef SVQC
 
 float autocvar_g_turrets_unit_walker_melee_damage;
@@ -65,181 +63,176 @@ const int ANIM_ROAM       = 11;
 .float animflag;
 .float idletime;
 
-#define WALKER_PATH(s,e) pathlib_astar(s,e)
+#define WALKER_PATH(this, s, e) pathlib_astar(this, s, e)
 
-float walker_firecheck()
-{SELFPARAM();
-    if (self.animflag == ANIM_MELEE)
-        return 0;
+bool walker_firecheck(entity this)
+{
+    if (this.animflag == ANIM_MELEE)
+        return false;
 
-    return turret_firecheck();
+    return turret_firecheck(this);
 }
 
-void walker_melee_do_dmg()
-{SELFPARAM();
+void walker_melee_do_dmg(entity this)
+{
     vector where;
     entity e;
 
-    makevectors(self.angles);
-    where = self.origin + v_forward * 128;
+    makevectors(this.angles);
+    where = this.origin + v_forward * 128;
 
     e = findradius(where,32);
     while (e)
     {
-        if (turret_validate_target(self, e, self.target_validate_flags))
-            if (e != self && e.owner != self)
-                Damage(e, self, self, (autocvar_g_turrets_unit_walker_melee_damage), DEATH_TURRET_WALK_MELEE.m_id, '0 0 0', v_forward * (autocvar_g_turrets_unit_walker_melee_force));
+        if (turret_validate_target(this, e, this.target_validate_flags))
+            if (e != this && e.owner != this)
+                Damage(e, this, this, (autocvar_g_turrets_unit_walker_melee_damage), DEATH_TURRET_WALK_MELEE.m_id, '0 0 0', v_forward * (autocvar_g_turrets_unit_walker_melee_force));
 
         e = e.chain;
     }
 }
 
-void walker_setnoanim()
-{SELFPARAM();
-    turrets_setframe(ANIM_NO, false);
-    self.animflag = self.frame;
+void walker_setnoanim(entity this)
+{
+    turrets_setframe(this, ANIM_NO, false);
+    this.animflag = this.frame;
 }
-void walker_rocket_explode()
-{SELFPARAM();
-    RadiusDamage (self, self.owner, (autocvar_g_turrets_unit_walker_rocket_damage), 0, (autocvar_g_turrets_unit_walker_rocket_radius), self, world, (autocvar_g_turrets_unit_walker_rocket_force), DEATH_TURRET_WALK_ROCKET.m_id, world);
-    remove (self);
+void walker_rocket_explode(entity this)
+{
+    RadiusDamage (this, this.owner, (autocvar_g_turrets_unit_walker_rocket_damage), 0, (autocvar_g_turrets_unit_walker_rocket_radius), this, NULL, (autocvar_g_turrets_unit_walker_rocket_force), DEATH_TURRET_WALK_ROCKET.m_id, NULL);
+    remove (this);
 }
 
-void walker_rocket_damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector vforce)
-{SELFPARAM();
-    self.health = self.health - damage;
-    self.velocity = self.velocity + vforce;
+void walker_rocket_damage(entity this, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector vforce)
+{
+    this.health = this.health - damage;
+    this.velocity = this.velocity + vforce;
 
-    if (self.health <= 0)
-        W_PrepareExplosionByDamage(self.owner, walker_rocket_explode);
+    if (this.health <= 0)
+        W_PrepareExplosionByDamage(this, this.owner, walker_rocket_explode);
 }
 
-#define WALKER_ROCKET_MOVE movelib_move_simple(newdir, (autocvar_g_turrets_unit_walker_rocket_speed), (autocvar_g_turrets_unit_walker_rocket_turnrate)); UpdateCSQCProjectile(self)
-void walker_rocket_loop();
-void walker_rocket_think()
-{SELFPARAM();
+#define WALKER_ROCKET_MOVE(s) movelib_move_simple((s), newdir, (autocvar_g_turrets_unit_walker_rocket_speed), (autocvar_g_turrets_unit_walker_rocket_turnrate)); UpdateCSQCProjectile(s)
+void walker_rocket_loop(entity this);
+void walker_rocket_think(entity this)
+{
     vector newdir;
     float edist;
     float itime;
     float m_speed;
 
-    self.nextthink = time;
+    this.nextthink = time;
 
-    edist = vlen(self.enemy.origin - self.origin);
+    edist = vlen(this.enemy.origin - this.origin);
 
     // Simulate crude guidance
-    if (self.cnt < time)
+    if (this.cnt < time)
     {
         if (edist < 1000)
-            self.tur_shotorg = randomvec() * min(edist, 64);
+            this.tur_shotorg = randomvec() * min(edist, 64);
         else
-            self.tur_shotorg = randomvec() * min(edist, 256);
+            this.tur_shotorg = randomvec() * min(edist, 256);
 
-        self.cnt = time + 0.5;
+        this.cnt = time + 0.5;
     }
 
     if (edist < 128)
-        self.tur_shotorg = '0 0 0';
+        this.tur_shotorg = '0 0 0';
 
-    if (self.max_health < time)
+    if (this.max_health < time)
     {
-        self.think       = walker_rocket_explode;
-        self.nextthink  = time;
+        setthink(this, walker_rocket_explode);
+        this.nextthink  = time;
         return;
     }
 
-    if (self.shot_dmg != 1337 && random() < 0.01)
+    if (this.shot_dmg != 1337 && random() < 0.01)
     {
-        walker_rocket_loop();
+        walker_rocket_loop(this);
         return;
     }
 
-    m_speed = vlen(self.velocity);
+    m_speed = vlen(this.velocity);
 
     // Enemy dead? just keep on the current heading then.
-    if (self.enemy == world || self.enemy.deadflag != DEAD_NO)
-        self.enemy = world;
+    if (this.enemy == NULL || IS_DEAD(this.enemy))
+        this.enemy = NULL;
 
-    if (self.enemy)
+    if (this.enemy)
     {
         itime = max(edist / m_speed, 1);
-        newdir = steerlib_pull(self.enemy.origin + self.tur_shotorg);
+        newdir = steerlib_pull(this, this.enemy.origin + this.tur_shotorg);
     }
     else
-        newdir  = normalize(self.velocity);
+        newdir  = normalize(this.velocity);
 
-    WALKER_ROCKET_MOVE;
+    WALKER_ROCKET_MOVE(this);
 }
 
-void walker_rocket_loop3()
-{SELFPARAM();
-    vector newdir;
-    self.nextthink = time;
+void walker_rocket_loop3(entity this)
+{
+    this.nextthink = time;
 
-    if (self.max_health < time)
+    if (this.max_health < time)
     {
-        self.think = walker_rocket_explode;
+        setthink(this, walker_rocket_explode);
         return;
     }
 
-    if (vlen(self.origin - self.tur_shotorg) < 100 )
+    if(vdist(this.origin - this.tur_shotorg, <, 100))
     {
-        self.think = walker_rocket_think;
+        setthink(this, walker_rocket_think);
         return;
     }
 
-    newdir = steerlib_pull(self.tur_shotorg);
-    WALKER_ROCKET_MOVE;
+    vector newdir = steerlib_pull(this, this.tur_shotorg);
+    WALKER_ROCKET_MOVE(this);
 
-    self.angles = vectoangles(self.velocity);
+    this.angles = vectoangles(this.velocity);
 }
 
-void walker_rocket_loop2()
-{SELFPARAM();
-    vector newdir;
-
-    self.nextthink = time;
+void walker_rocket_loop2(entity this)
+{
+    this.nextthink = time;
 
-    if (self.max_health < time)
+    if (this.max_health < time)
     {
-        self.think = walker_rocket_explode;
+        setthink(this, walker_rocket_explode);
         return;
     }
 
-    if (vlen(self.origin - self.tur_shotorg) < 100 )
+    if(vdist(this.origin - this.tur_shotorg, <, 100))
     {
-        self.tur_shotorg = self.origin - '0 0 200';
-        self.think = walker_rocket_loop3;
+        this.tur_shotorg = this.origin - '0 0 200';
+        setthink(this, walker_rocket_loop3);
         return;
     }
 
-    newdir = steerlib_pull(self.tur_shotorg);
-    WALKER_ROCKET_MOVE;
+    vector newdir = steerlib_pull(this, this.tur_shotorg);
+    WALKER_ROCKET_MOVE(this);
 }
 
-void walker_rocket_loop()
-{SELFPARAM();
-    self.nextthink = time;
-    self.tur_shotorg = self.origin + '0 0 300';
-    self.think = walker_rocket_loop2;
-    self.shot_dmg = 1337;
+void walker_rocket_loop(entity this)
+{
+    this.nextthink = time;
+    this.tur_shotorg = this.origin + '0 0 300';
+    setthink(this, walker_rocket_loop2);
+    this.shot_dmg = 1337;
 }
 
-void walker_fire_rocket(vector org)
-{SELFPARAM();
-    entity rocket;
-
-    fixedmakevectors(self.angles);
+void walker_fire_rocket(entity this, vector org)
+{
+    fixedmakevectors(this.angles);
 
     te_explosion (org);
 
-    rocket = new(walker_rocket);
+    entity rocket = new(walker_rocket);
     setorigin(rocket, org);
 
-    sound (self, CH_WEAPON_A, SND_HAGAR_FIRE, VOL_BASE, ATTEN_NORM);
+    sound (this, CH_WEAPON_A, SND_HAGAR_FIRE, VOL_BASE, ATTEN_NORM);
     setsize (rocket, '-3 -3 -3', '3 3 3'); // give it some size so it can be shot
 
-    rocket.owner                         = self;
+    rocket.owner                         = this;
     rocket.bot_dodge             = true;
     rocket.bot_dodgerating     = 50;
     rocket.takedamage           = DAMAGE_YES;
@@ -247,12 +240,12 @@ void walker_fire_rocket(vector org)
     rocket.health                       = 25;
     rocket.tur_shotorg         = randomvec() * 512;
     rocket.cnt                         = time + 1;
-    rocket.enemy                         = self.enemy;
+    rocket.enemy                         = this.enemy;
 
     if (random() < 0.01)
-        rocket.think             = walker_rocket_loop;
+        setthink(rocket, walker_rocket_loop);
     else
-        rocket.think             = walker_rocket_think;
+        setthink(rocket, walker_rocket_think);
 
     rocket.event_damage           = walker_rocket_damage;
 
@@ -260,7 +253,7 @@ void walker_fire_rocket(vector org)
     rocket.movetype               = MOVETYPE_FLY;
     rocket.velocity               = normalize((v_forward + v_up * 0.5) + (randomvec() * 0.2)) * (autocvar_g_turrets_unit_walker_rocket_speed);
     rocket.angles                       = vectoangles(rocket.velocity);
-    rocket.touch                         = walker_rocket_explode;
+    settouch(rocket, walker_rocket_explode);
     rocket.flags                         = FL_PROJECTILE;
     rocket.solid                         = SOLID_BBOX;
     rocket.max_health           = time + 9;
@@ -271,385 +264,385 @@ void walker_fire_rocket(vector org)
 
 .vector enemy_last_loc;
 .float enemy_last_time;
-void walker_move_to(vector _target, float _dist)
-{SELFPARAM();
-    switch (self.waterlevel)
+void walker_move_to(entity this, vector _target, float _dist)
+{
+    switch (this.waterlevel)
     {
         case WATERLEVEL_NONE:
             if (_dist > 500)
-                self.animflag = ANIM_RUN;
+                this.animflag = ANIM_RUN;
             else
-                self.animflag = ANIM_WALK;
+                this.animflag = ANIM_WALK;
         case WATERLEVEL_WETFEET:
         case WATERLEVEL_SWIMMING:
-            if (self.animflag != ANIM_SWIM)
-                self.animflag = ANIM_WALK;
+            if (this.animflag != ANIM_SWIM)
+                this.animflag = ANIM_WALK;
             else
-                self.animflag = ANIM_SWIM;
+                this.animflag = ANIM_SWIM;
             break;
         case WATERLEVEL_SUBMERGED:
-            self.animflag = ANIM_SWIM;
+            this.animflag = ANIM_SWIM;
     }
 
-    self.moveto = _target;
-    self.steerto = steerlib_attract2(self.moveto, 0.5, 500, 0.95);
+    this.moveto = _target;
+    this.steerto = steerlib_attract2(this, this.moveto, 0.5, 500, 0.95);
 
-    if(self.enemy)
+    if(this.enemy)
     {
-        self.enemy_last_loc = _target;
-        self.enemy_last_time = time;
+        this.enemy_last_loc = _target;
+        this.enemy_last_time = time;
     }
 }
 
-void walker_move_path()
-{SELFPARAM();
+void walker_move_path(entity this)
+{
 #ifdef WALKER_FANCYPATHING
     // Are we close enougth to a path node to switch to the next?
-    if (vlen(self.origin  - self.pathcurrent.origin) < 64)
-        if (self.pathcurrent.path_next == world)
+    if(vdist(this.origin - this.pathcurrent.origin, <, 64))
+        if (this.pathcurrent.path_next == NULL)
         {
             // Path endpoint reached
-            pathlib_deletepath(self.pathcurrent.owner);
-            self.pathcurrent = world;
+            pathlib_deletepath(this.pathcurrent.owner);
+            this.pathcurrent = NULL;
 
-            if (self.pathgoal)
+            if (this.pathgoal)
             {
-                if (self.pathgoal.use)
-                    self.pathgoal.use();
+                if (this.pathgoal.use)
+                    this.pathgoal.use(this, NULL, NULL);
 
-                if (self.pathgoal.enemy)
+                if (this.pathgoal.enemy)
                 {
-                    self.pathcurrent = WALKER_PATH(self.pathgoal.origin,self.pathgoal.enemy.origin);
-                    self.pathgoal = self.pathgoal.enemy;
+                    this.pathcurrent = WALKER_PATH(this, this.pathgoal.origin, this.pathgoal.enemy.origin);
+                    this.pathgoal = this.pathgoal.enemy;
                 }
             }
             else
-                self.pathgoal = world;
+                this.pathgoal = NULL;
         }
         else
-            self.pathcurrent = self.pathcurrent.path_next;
+            this.pathcurrent = this.pathcurrent.path_next;
 
-    self.moveto = self.pathcurrent.origin;
-    self.steerto = steerlib_attract2(self.moveto,0.5,500,0.95);
-    walker_move_to(self.moveto, 0);
+    this.moveto = this.pathcurrent.origin;
+    this.steerto = steerlib_attract2(this, this.moveto,0.5,500,0.95);
+    walker_move_to(this, this.moveto, 0);
 
 #else
-    if (vlen(self.origin - self.pathcurrent.origin) < 64)
-        self.pathcurrent = self.pathcurrent.enemy;
+    if(vdist(this.origin - this.pathcurrent.origin, <, 64))
+        this.pathcurrent = this.pathcurrent.enemy;
 
-    if(!self.pathcurrent)
+    if(!this.pathcurrent)
         return;
 
-    self.moveto = self.pathcurrent.origin;
-    self.steerto = steerlib_attract2(self.moveto, 0.5, 500, 0.95);
-    walker_move_to(self.moveto, 0);
+    this.moveto = this.pathcurrent.origin;
+    this.steerto = steerlib_attract2(this, this.moveto, 0.5, 500, 0.95);
+    walker_move_to(this, this.moveto, 0);
 #endif
 }
 
-spawnfunc(turret_walker) { if(!turret_initialize(TUR_WALKER)) remove(self); }
+spawnfunc(turret_walker) { if(!turret_initialize(this, TUR_WALKER)) remove(this); }
 
-        METHOD(WalkerTurret, tr_think, void(WalkerTurret thistur))
-        {
-            fixedmakevectors(self.angles);
+METHOD(WalkerTurret, tr_think, void(WalkerTurret thistur, entity it))
+{
+    fixedmakevectors(it.angles);
 
-            if (self.spawnflags & TSF_NO_PATHBREAK && self.pathcurrent)
-                walker_move_path();
-            else if (self.enemy == world)
+    if (it.spawnflags & TSF_NO_PATHBREAK && it.pathcurrent)
+        walker_move_path(it);
+    else if (it.enemy == NULL)
+    {
+        if(it.pathcurrent)
+            walker_move_path(it);
+        else
+        {
+            if(it.enemy_last_time != 0)
             {
-                if(self.pathcurrent)
-                    walker_move_path();
+                if(vdist(it.origin - it.enemy_last_loc, <, 128) || time - it.enemy_last_time > 10)
+                    it.enemy_last_time = 0;
                 else
-                {
-                    if(self.enemy_last_time != 0)
-                    {
-                        if(vlen(self.origin - self.enemy_last_loc) < 128 || time - self.enemy_last_time > 10)
-                            self.enemy_last_time = 0;
-                        else
-                            walker_move_to(self.enemy_last_loc, 0);
-                    }
-                    else
-                    {
-                        if(self.animflag != ANIM_NO)
-                        {
-                            traceline(self.origin + '0 0 64', self.origin + '0 0 64' + v_forward * 128, MOVE_NORMAL, self);
-
-                            if(trace_fraction != 1.0)
-                                self.tur_head.idletime = -1337;
-                            else
-                            {
-                                traceline(trace_endpos, trace_endpos - '0 0 256', MOVE_NORMAL, self);
-                                if(trace_fraction == 1.0)
-                                    self.tur_head.idletime = -1337;
-                            }
-
-                            if(self.tur_head.idletime == -1337)
-                            {
-                                self.moveto = self.origin + randomvec() * 256;
-                                self.tur_head.idletime = 0;
-                            }
-
-                            self.moveto = self.moveto * 0.9 + ((self.origin + v_forward * 500) + randomvec() * 400) * 0.1;
-                            self.moveto_z = self.origin_z + 64;
-                            walker_move_to(self.moveto, 0);
-                        }
-
-                        if(self.idletime < time)
-                        {
-                            if(random() < 0.5 || !(self.spawnflags & TSL_ROAM))
-                            {
-                                self.idletime = time + 1 + random() * 5;
-                                self.moveto = self.origin;
-                                self.animflag = ANIM_NO;
-                            }
-                            else
-                            {
-                                self.animflag = ANIM_WALK;
-                                self.idletime = time + 4 + random() * 2;
-                                self.moveto = self.origin + randomvec() * 256;
-                                self.tur_head.moveto = self.moveto;
-                                self.tur_head.idletime = 0;
-                            }
-                        }
-                    }
-                }
+                    walker_move_to(it, it.enemy_last_loc, 0);
             }
             else
             {
-                if (self.tur_dist_enemy < (autocvar_g_turrets_unit_walker_melee_range) && self.animflag != ANIM_MELEE)
+                if(it.animflag != ANIM_NO)
                 {
-                    vector wish_angle;
+                    traceline(it.origin + '0 0 64', it.origin + '0 0 64' + v_forward * 128, MOVE_NORMAL, it);
 
-                    wish_angle = angleofs(self, self.enemy);
-                    if (self.animflag != ANIM_SWIM)
-                    if (fabs(wish_angle_y) < 15)
+                    if(trace_fraction != 1.0)
+                        it.tur_head.idletime = -1337;
+                    else
                     {
-                        self.moveto   = self.enemy.origin;
-                        self.steerto  = steerlib_attract2(self.moveto, 0.5, 500, 0.95);
-                        self.animflag = ANIM_MELEE;
+                        traceline(trace_endpos, trace_endpos - '0 0 256', MOVE_NORMAL, it);
+                        if(trace_fraction == 1.0)
+                            it.tur_head.idletime = -1337;
                     }
+
+                    if(it.tur_head.idletime == -1337)
+                    {
+                        it.moveto = it.origin + randomvec() * 256;
+                        it.tur_head.idletime = 0;
+                    }
+
+                    it.moveto = it.moveto * 0.9 + ((it.origin + v_forward * 500) + randomvec() * 400) * 0.1;
+                    it.moveto_z = it.origin_z + 64;
+                    walker_move_to(it, it.moveto, 0);
                 }
-                else if (self.tur_head.attack_finished_single[0] < time)
+
+                if(it.idletime < time)
                 {
-                    if(self.tur_head.shot_volly)
+                    if(random() < 0.5 || !(it.spawnflags & TSL_ROAM))
                     {
-                        self.animflag = ANIM_NO;
-
-                        self.tur_head.shot_volly = self.tur_head.shot_volly -1;
-                        if(self.tur_head.shot_volly == 0)
-                            self.tur_head.attack_finished_single[0] = time + (autocvar_g_turrets_unit_walker_rocket_refire);
-                        else
-                            self.tur_head.attack_finished_single[0] = time + 0.2;
-
-                        if(self.tur_head.shot_volly > 1)
-                            walker_fire_rocket(gettaginfo(self, gettagindex(self, "tag_rocket01")));
-                        else
-                            walker_fire_rocket(gettaginfo(self, gettagindex(self, "tag_rocket02")));
+                        it.idletime = time + 1 + random() * 5;
+                        it.moveto = it.origin;
+                        it.animflag = ANIM_NO;
                     }
                     else
                     {
-                        if (self.tur_dist_enemy > (autocvar_g_turrets_unit_walker_rocket_range_min))
-                        if (self.tur_dist_enemy < (autocvar_g_turrets_unit_walker_rocket_range))
-                            self.tur_head.shot_volly = 4;
+                        it.animflag = ANIM_WALK;
+                        it.idletime = time + 4 + random() * 2;
+                        it.moveto = it.origin + randomvec() * 256;
+                        it.tur_head.moveto = it.moveto;
+                        it.tur_head.idletime = 0;
                     }
                 }
-                else
-                {
-                    if (self.animflag != ANIM_MELEE)
-                        walker_move_to(self.enemy.origin, self.tur_dist_enemy);
-                }
             }
+        }
+    }
+    else
+    {
+        if (it.tur_dist_enemy < (autocvar_g_turrets_unit_walker_melee_range) && it.animflag != ANIM_MELEE)
+        {
+            vector wish_angle;
 
+            wish_angle = angleofs(it, it.enemy);
+            if (it.animflag != ANIM_SWIM)
+            if (fabs(wish_angle_y) < 15)
+            {
+                it.moveto   = it.enemy.origin;
+                it.steerto  = steerlib_attract2(it, it.moveto, 0.5, 500, 0.95);
+                it.animflag = ANIM_MELEE;
+            }
+        }
+        else if (it.tur_head.attack_finished_single[0] < time)
+        {
+            if(it.tur_head.shot_volly)
             {
-                vector real_angle;
-                float turny = 0, turnx = 0;
-                float vz;
+                it.animflag = ANIM_NO;
 
-                real_angle = vectoangles(self.steerto) - self.angles;
-                vz = self.velocity_z;
+                it.tur_head.shot_volly = it.tur_head.shot_volly -1;
+                if(it.tur_head.shot_volly == 0)
+                    it.tur_head.attack_finished_single[0] = time + (autocvar_g_turrets_unit_walker_rocket_refire);
+                else
+                    it.tur_head.attack_finished_single[0] = time + 0.2;
 
-                switch (self.animflag)
-                {
-                    case ANIM_NO:
-                        movelib_beak_simple((autocvar_g_turrets_unit_walker_speed_stop));
-                        break;
-
-                    case ANIM_TURN:
-                        turny = (autocvar_g_turrets_unit_walker_turn);
-                        movelib_beak_simple((autocvar_g_turrets_unit_walker_speed_stop));
-                        break;
-
-                    case ANIM_WALK:
-                        turny = (autocvar_g_turrets_unit_walker_turn_walk);
-                        movelib_move_simple(v_forward, (autocvar_g_turrets_unit_walker_speed_walk), 0.6);
-                        break;
-
-                    case ANIM_RUN:
-                        turny = (autocvar_g_turrets_unit_walker_turn_run);
-                        movelib_move_simple(v_forward, (autocvar_g_turrets_unit_walker_speed_run), 0.6);
-                        break;
-
-                    case ANIM_STRAFE_L:
-                        turny = (autocvar_g_turrets_unit_walker_turn_strafe);
-                        movelib_move_simple(v_right * -1, (autocvar_g_turrets_unit_walker_speed_walk), 0.8);
-                        break;
-
-                    case ANIM_STRAFE_R:
-                        turny = (autocvar_g_turrets_unit_walker_turn_strafe);
-                        movelib_move_simple(v_right, (autocvar_g_turrets_unit_walker_speed_walk), 0.8);
-                        break;
-
-                    case ANIM_JUMP:
-                        self.velocity += '0 0 1' * (autocvar_g_turrets_unit_walker_speed_jump);
-                        break;
-
-                    case ANIM_LAND:
-                        break;
-
-                    case ANIM_PAIN:
-                        if(self.frame != ANIM_PAIN)
-                            defer(0.25, walker_setnoanim);
-
-                        break;
-
-                    case ANIM_MELEE:
-                        if(self.frame != ANIM_MELEE)
-                        {
-                            defer(0.41, walker_setnoanim);
-                            defer(0.21, walker_melee_do_dmg);
-                        }
-
-                        movelib_beak_simple((autocvar_g_turrets_unit_walker_speed_stop));
-                        break;
-
-                    case ANIM_SWIM:
-                        turny = (autocvar_g_turrets_unit_walker_turn_swim);
-                        turnx = (autocvar_g_turrets_unit_walker_turn_swim);
-
-                        self.angles_x += bound(-10, shortangle_f(real_angle_x, self.angles_x), 10);
-                        movelib_move_simple(v_forward, (autocvar_g_turrets_unit_walker_speed_swim), 0.3);
-                        vz = self.velocity_z + sin(time * 4) * 8;
-                        break;
-
-                    case ANIM_ROAM:
-                        turny = (autocvar_g_turrets_unit_walker_turn_walk);
-                        movelib_move_simple(v_forward ,(autocvar_g_turrets_unit_walker_speed_roam), 0.5);
-                        break;
-                }
+                if(it.tur_head.shot_volly > 1)
+                    walker_fire_rocket(it, gettaginfo(it, gettagindex(it, "tag_rocket01")));
+                else
+                    walker_fire_rocket(it, gettaginfo(it, gettagindex(it, "tag_rocket02")));
+            }
+            else
+            {
+                if (it.tur_dist_enemy > (autocvar_g_turrets_unit_walker_rocket_range_min))
+                if (it.tur_dist_enemy < (autocvar_g_turrets_unit_walker_rocket_range))
+                    it.tur_head.shot_volly = 4;
+            }
+        }
+        else
+        {
+            if (it.animflag != ANIM_MELEE)
+                walker_move_to(it, it.enemy.origin, it.tur_dist_enemy);
+        }
+    }
 
-                if(turny)
-                {
-                    turny = bound( turny * -1, shortangle_f(real_angle_y, self.angles_y), turny );
-                    self.angles_y += turny;
-                }
+    {
+        vector real_angle;
+        float turny = 0, turnx = 0;
+        float vz;
+
+        real_angle = vectoangles(it.steerto) - it.angles;
+        vz = it.velocity_z;
 
-                if(turnx)
+        switch (it.animflag)
+        {
+            case ANIM_NO:
+                movelib_brake_simple(it, (autocvar_g_turrets_unit_walker_speed_stop));
+                break;
+
+            case ANIM_TURN:
+                turny = (autocvar_g_turrets_unit_walker_turn);
+                movelib_brake_simple(it, (autocvar_g_turrets_unit_walker_speed_stop));
+                break;
+
+            case ANIM_WALK:
+                turny = (autocvar_g_turrets_unit_walker_turn_walk);
+                movelib_move_simple(it, v_forward, (autocvar_g_turrets_unit_walker_speed_walk), 0.6);
+                break;
+
+            case ANIM_RUN:
+                turny = (autocvar_g_turrets_unit_walker_turn_run);
+                movelib_move_simple(it, v_forward, (autocvar_g_turrets_unit_walker_speed_run), 0.6);
+                break;
+
+            case ANIM_STRAFE_L:
+                turny = (autocvar_g_turrets_unit_walker_turn_strafe);
+                movelib_move_simple(it, v_right * -1, (autocvar_g_turrets_unit_walker_speed_walk), 0.8);
+                break;
+
+            case ANIM_STRAFE_R:
+                turny = (autocvar_g_turrets_unit_walker_turn_strafe);
+                movelib_move_simple(it, v_right, (autocvar_g_turrets_unit_walker_speed_walk), 0.8);
+                break;
+
+            case ANIM_JUMP:
+                it.velocity += '0 0 1' * (autocvar_g_turrets_unit_walker_speed_jump);
+                break;
+
+            case ANIM_LAND:
+                break;
+
+            case ANIM_PAIN:
+                if(it.frame != ANIM_PAIN)
+                    defer(it, 0.25, walker_setnoanim);
+
+                break;
+
+            case ANIM_MELEE:
+                if(it.frame != ANIM_MELEE)
                 {
-                    turnx = bound( turnx * -1, shortangle_f(real_angle_x, self.angles_x), turnx );
-                    self.angles_x += turnx;
+                    defer(it, 0.41, walker_setnoanim);
+                    defer(it, 0.21, walker_melee_do_dmg);
                 }
 
-                self.velocity_z = vz;
-            }
+                movelib_brake_simple(it, (autocvar_g_turrets_unit_walker_speed_stop));
+                break;
 
+            case ANIM_SWIM:
+                turny = (autocvar_g_turrets_unit_walker_turn_swim);
+                turnx = (autocvar_g_turrets_unit_walker_turn_swim);
 
-            if(self.origin != self.oldorigin)
-                self.SendFlags |= TNSF_MOVE;
+                it.angles_x += bound(-10, shortangle_f(real_angle_x, it.angles_x), 10);
+                movelib_move_simple(it, v_forward, (autocvar_g_turrets_unit_walker_speed_swim), 0.3);
+                vz = it.velocity_z + sin(time * 4) * 8;
+                break;
 
-            self.oldorigin = self.origin;
-            turrets_setframe(self.animflag, false);
+            case ANIM_ROAM:
+                turny = (autocvar_g_turrets_unit_walker_turn_walk);
+                movelib_move_simple(it, v_forward ,(autocvar_g_turrets_unit_walker_speed_roam), 0.5);
+                break;
         }
-        METHOD(WalkerTurret, tr_death, void(WalkerTurret this, entity it))
+
+        if(turny)
         {
-#ifdef WALKER_FANCYPATHING
-            if (it.pathcurrent)
-                pathlib_deletepath(it.pathcurrent.owner);
-#endif
-            it.pathcurrent = NULL;
+            turny = bound( turny * -1, shortangle_f(real_angle_y, it.angles_y), turny );
+            it.angles_y += turny;
         }
-        METHOD(WalkerTurret, tr_setup, void(WalkerTurret this, entity it))
+
+        if(turnx)
         {
-            it.ticrate = 0.05;
+            turnx = bound( turnx * -1, shortangle_f(real_angle_x, it.angles_x), turnx );
+            it.angles_x += turnx;
+        }
 
-            entity e;
+        it.velocity_z = vz;
+    }
 
-            // Respawn is called & first spawn to, to set team. need to make sure we do not move the initial spawn.
-            if(it.movetype == MOVETYPE_WALK)
-            {
-                if(it.pos1)
-                    setorigin(it, it.pos1);
-                if(it.pos2)
-                    it.angles = it.pos2;
-            }
 
-            it.ammo_flags = TFL_AMMO_BULLETS | TFL_AMMO_RECHARGE | TFL_AMMO_RECIEVE;
-            it.aim_flags = TFL_AIM_LEAD;
-            it.turret_flags |= TUR_FLAG_HITSCAN;
-
-            it.target_select_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK | TFL_TARGETSELECT_LOS;
-            it.target_validate_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK | TFL_TARGETSELECT_LOS;
-            it.iscreature = true;
-            it.teleportable = TELEPORT_NORMAL;
-            it.damagedbycontents = true;
-            it.solid = SOLID_SLIDEBOX;
-            it.takedamage = DAMAGE_AIM;
-            if(it.movetype != MOVETYPE_WALK)
-            {
-                setorigin(it, it.origin);
-                tracebox(it.origin + '0 0 128', it.mins, it.maxs, it.origin - '0 0 10000', MOVE_NORMAL, it);
-                setorigin(it, trace_endpos + '0 0 4');
-                it.pos1 = it.origin;
-                it.pos2 = it.angles;
-            }
-            it.movetype = MOVETYPE_WALK;
-            it.idle_aim = '0 0 0';
-            it.turret_firecheckfunc = walker_firecheck;
+    if(it.origin != it.oldorigin)
+        it.SendFlags |= TNSF_MOVE;
 
-            if (it.target != "")
-            {
-                e = find(world, targetname, it.target);
-                if (!e)
-                {
-                    LOG_TRACE("Initital waypoint for walker does NOT exsist, fix your map!\n");
-                    it.target = "";
-                }
+    it.oldorigin = it.origin;
+    turrets_setframe(it, it.animflag, false);
+}
+METHOD(WalkerTurret, tr_death, void(WalkerTurret this, entity it))
+{
+#ifdef WALKER_FANCYPATHING
+    if (it.pathcurrent)
+        pathlib_deletepath(it.pathcurrent.owner);
+#endif
+    it.pathcurrent = NULL;
+}
+METHOD(WalkerTurret, tr_setup, void(WalkerTurret this, entity it))
+{
+    it.ticrate = 0.05;
 
-                if (e.classname != "turret_checkpoint")
-                    LOG_TRACE("Warning: not a turrret path\n");
-                else
-                {
+    entity e;
+
+    // Respawn is called & first spawn to, to set team. need to make sure we do not move the initial spawn.
+    if(it.movetype == MOVETYPE_WALK)
+    {
+        if(it.pos1)
+            setorigin(it, it.pos1);
+        if(it.pos2)
+            it.angles = it.pos2;
+    }
+
+    it.ammo_flags = TFL_AMMO_BULLETS | TFL_AMMO_RECHARGE | TFL_AMMO_RECIEVE;
+    it.aim_flags = TFL_AIM_LEAD;
+    it.turret_flags |= TUR_FLAG_HITSCAN;
+
+    it.target_select_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK | TFL_TARGETSELECT_LOS;
+    it.target_validate_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK | TFL_TARGETSELECT_LOS;
+    it.iscreature = true;
+    it.teleportable = TELEPORT_NORMAL;
+    it.damagedbycontents = true;
+    it.solid = SOLID_SLIDEBOX;
+    it.takedamage = DAMAGE_AIM;
+    if(it.movetype != MOVETYPE_WALK)
+    {
+        setorigin(it, it.origin);
+        tracebox(it.origin + '0 0 128', it.mins, it.maxs, it.origin - '0 0 10000', MOVE_NORMAL, it);
+        setorigin(it, trace_endpos + '0 0 4');
+        it.pos1 = it.origin;
+        it.pos2 = it.angles;
+    }
+    it.movetype = MOVETYPE_WALK;
+    it.idle_aim = '0 0 0';
+    it.turret_firecheckfunc = walker_firecheck;
+
+    if (it.target != "")
+    {
+        e = find(NULL, targetname, it.target);
+        if (!e)
+        {
+            LOG_TRACE("Initital waypoint for walker does NOT exsist, fix your map!\n");
+            it.target = "";
+        }
+
+        if (e.classname != "turret_checkpoint")
+            LOG_TRACE("Warning: not a turrret path\n");
+        else
+        {
 #ifdef WALKER_FANCYPATHING
-                    it.pathcurrent = WALKER_PATH(it.origin, e.origin);
-                    it.pathgoal = e;
+            it.pathcurrent = WALKER_PATH(it, it.origin, e.origin);
+            it.pathgoal = e;
 #else
-                    it.pathcurrent = e;
+            it.pathcurrent = e;
 #endif
-                }
-            }
         }
+    }
+}
 
 #endif // SVQC
 #ifdef CSQC
 
-#include "../../../client/movelib.qh"
+#include <common/physics/movelib.qh>
 
 void walker_draw(entity this)
 {
     float dt;
 
-    dt = time - self.move_time;
-    self.move_time = time;
+    dt = time - this.move_time;
+    this.move_time = time;
     if(dt <= 0)
         return;
 
-    fixedmakevectors(self.angles);
-    movelib_groundalign4point(300, 100, 0.25, 45);
-    setorigin(self, self.origin + self.velocity * dt);
-    self.tur_head.angles += dt * self.tur_head.move_avelocity;
-    self.angles_y = self.move_angles_y;
+    fixedmakevectors(this.angles);
+    movelib_groundalign4point(this, 300, 100, 0.25, 45);
+    setorigin(this, this.origin + this.velocity * dt);
+    this.tur_head.angles += dt * this.tur_head.move_avelocity;
+    this.angles_y = this.move_angles_y;
 
-    if (self.health < 127)
+    if (this.health < 127)
     if(random() < 0.15)
-        te_spark(self.origin + '0 0 40', randomvec() * 256 + '0 0 256', 16);
+        te_spark(this.origin + '0 0 40', randomvec() * 256 + '0 0 256', 16);
 }
 
         METHOD(WalkerTurret, tr_setup, void(WalkerTurret this, entity it))