]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/turrets/turret/ewheel.qc
Clear out .health and .armorvalue from the client side
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / turrets / turret / ewheel.qc
index 113431003c93053903b04ae4768616314e6c6ff6..c0a0b177ee2d179afb99aeb774203521daf5eeeb 100644 (file)
@@ -1,26 +1,4 @@
-#ifndef TURRET_EWHEEL_H
-#define TURRET_EWHEEL_H
-
-//#define EWHEEL_FANCYPATH
-
-#include "ewheel_weapon.qh"
-
-CLASS(EWheel, Turret)
-/* spawnflags */ ATTRIB(EWheel, spawnflags, int, TUR_FLAG_PLAYER | TUR_FLAG_MOVE | TUR_FLAG_ROAM);
-/* mins       */ ATTRIB(EWheel, mins, vector, '-32 -32 0');
-/* maxs       */ ATTRIB(EWheel, maxs, vector, '32 32 48');
-/* modelname  */ ATTRIB(EWheel, mdl, string, "ewheel-base2.md3");
-/* model      */ ATTRIB_STRZONE(EWheel, model, string, strcat("models/turrets/", this.mdl));
-/* head_model */ ATTRIB_STRZONE(EWheel, head_model, string, strcat("models/turrets/", "ewheel-gun1.md3"));
-/* netname    */ ATTRIB(EWheel, netname, string, "ewheel");
-/* fullname   */ ATTRIB(EWheel, turret_name, string, _("eWheel Turret"));
-    ATTRIB(EWheel, m_weapon, Weapon, WEP_EWHEEL);
-ENDCLASS(EWheel)
-REGISTER_TURRET(EWHEEL, NEW(EWheel));
-
-#endif
-
-#ifdef IMPLEMENTATION
+#include "ewheel.qh"
 
 #ifdef SVQC
 
@@ -30,144 +8,164 @@ float autocvar_g_turrets_unit_ewheel_speed_slower;
 float autocvar_g_turrets_unit_ewheel_speed_stop;
 float autocvar_g_turrets_unit_ewheel_turnrate;
 
-const float ewheel_anim_stop = 0;
-const float ewheel_anim_fwd_slow = 1;
-const float ewheel_anim_fwd_fast = 2;
-const float ewheel_anim_bck_slow = 3;
-const float ewheel_anim_bck_fast = 4;
+const int ewheel_anim_stop     = 0;
+const int ewheel_anim_fwd_slow = 1;
+const int ewheel_anim_fwd_fast = 2;
+const int ewheel_anim_bck_slow = 3;
+const int ewheel_anim_bck_fast = 4;
 
-void ewheel_move_path()
-{SELFPARAM();
+void ewheel_move_path(entity this)
+{
+    // Are we close enough to a path node to switch to the next?
+    if(turret_closetotarget(this, this.pathcurrent.origin))
+    {
 #ifdef EWHEEL_FANCYPATH
-    // Are we close enougth to a path node to switch to the next?
-    if(vdist(self.origin - self.pathcurrent.origin, <, 64))
-        if (self.pathcurrent.path_next == world)
+        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(self.pathgoal, NULL, NULL);
+                if (this.pathgoal.use)
+                    this.pathgoal.use(this.pathgoal, NULL, NULL);
 
-                if (self.pathgoal.enemy)
+                if (this.pathgoal.enemy)
                 {
-                    self.pathcurrent = pathlib_astar(self, self.pathgoal.origin,self.pathgoal.enemy.origin);
-                    self.pathgoal = self.pathgoal.enemy;
+                    this.pathcurrent = pathlib_astar(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;
 #else
-    if(vdist(self.origin - self.pathcurrent.origin, <, 64))
-        self.pathcurrent = self.pathcurrent.enemy;
+        this.pathcurrent = this.pathcurrent.enemy;
 #endif
+    }
 
-    if (self.pathcurrent)
+    if (this.pathcurrent)
     {
+        this.moveto = this.pathcurrent.origin;
+        this.steerto = steerlib_attract2(this, this.moveto, 0.5, 500, 0.95);
 
-        self.moveto = self.pathcurrent.origin;
-        self.steerto = steerlib_attract2(self, self.moveto, 0.5, 500, 0.95);
-
-        movelib_move_simple(self, v_forward, (autocvar_g_turrets_unit_ewheel_speed_fast), 0.4);
+        movelib_move_simple(this, v_forward, (autocvar_g_turrets_unit_ewheel_speed_fast), 0.4);
     }
 }
 
-void ewheel_move_enemy()
-{SELFPARAM();
-    float newframe;
+void ewheel_move_enemy(entity this)
+{
+    int newframe;
 
-    self.steerto = steerlib_arrive(self, self.enemy.origin,self.target_range_optimal);
+    this.steerto = steerlib_arrive(this, this.enemy.origin,this.target_range_optimal);
 
-    self.moveto  = self.origin + self.steerto * 128;
+    this.moveto = this.origin + this.steerto * 128;
 
-    if (self.tur_dist_enemy > self.target_range_optimal)
+    if (this.tur_dist_enemy > this.target_range_optimal)
     {
-        if ( self.tur_head.spawnshieldtime < 1 )
+        if ( this.tur_head.spawnshieldtime < 1 )
         {
             newframe = ewheel_anim_fwd_fast;
-            movelib_move_simple(self, v_forward, (autocvar_g_turrets_unit_ewheel_speed_fast), 0.4);
+            movelib_move_simple(this, v_forward, (autocvar_g_turrets_unit_ewheel_speed_fast), 0.4);
         }
-        else if (self.tur_head.spawnshieldtime < 2)
+        else if (this.tur_head.spawnshieldtime < 2)
         {
 
             newframe = ewheel_anim_fwd_slow;
-            movelib_move_simple(self, v_forward, (autocvar_g_turrets_unit_ewheel_speed_slow), 0.4);
+            movelib_move_simple(this, v_forward, (autocvar_g_turrets_unit_ewheel_speed_slow), 0.4);
        }
         else
         {
             newframe = ewheel_anim_fwd_slow;
-            movelib_move_simple(self, v_forward, (autocvar_g_turrets_unit_ewheel_speed_slower), 0.4);
+            movelib_move_simple(this, v_forward, (autocvar_g_turrets_unit_ewheel_speed_slower), 0.4);
         }
     }
-    else if (self.tur_dist_enemy < self.target_range_optimal * 0.5)
+    else if (this.tur_dist_enemy < this.target_range_optimal * 0.5)
     {
         newframe = ewheel_anim_bck_slow;
-        movelib_move_simple(self, v_forward * -1, (autocvar_g_turrets_unit_ewheel_speed_slow), 0.4);
+        movelib_move_simple(this, v_forward * -1, (autocvar_g_turrets_unit_ewheel_speed_slow), 0.4);
     }
     else
     {
         newframe = ewheel_anim_stop;
-        movelib_brake_simple(self, (autocvar_g_turrets_unit_ewheel_speed_stop));
+        movelib_brake_simple(this, (autocvar_g_turrets_unit_ewheel_speed_stop));
     }
 
-    turrets_setframe(newframe, false);
+    turrets_setframe(this, newframe, false);
 }
 
-void ewheel_move_idle()
-{SELFPARAM();
-    if(self.frame != 0)
+void ewheel_move_idle(entity this)
+{
+    if(this.frame != 0)
     {
-        self.SendFlags |= TNSF_ANIM;
-        self.anim_start_time = time;
+        this.SendFlags |= TNSF_ANIM;
+        this.anim_start_time = time;
     }
 
-    self.frame = 0;
-    if(self.velocity)
-        movelib_brake_simple(self, (autocvar_g_turrets_unit_ewheel_speed_stop));
+    this.frame = 0;
+    if(this.velocity)
+        movelib_brake_simple(this, (autocvar_g_turrets_unit_ewheel_speed_stop));
+}
+
+void ewheel_findtarget(entity this)
+{
+    entity e = find(NULL, targetname, this.target);
+    if (!e)
+    {
+        LOG_TRACE("Initital waypoint for ewheel does NOT exist, fix your map!");
+        this.target = "";
+    }
+
+    if (e.classname != "turret_checkpoint")
+        LOG_TRACE("Warning: not a turret path");
+    else
+    {
+
+#ifdef EWHEEL_FANCYPATH
+        this.pathcurrent = pathlib_astar(this, this.origin, e.origin);
+        this.pathgoal = e;
+#else
+        this.pathcurrent  = e;
+#endif
+    }
 }
 
-spawnfunc(turret_ewheel) { if(!turret_initialize(TUR_EWHEEL)) remove(this); }
+spawnfunc(turret_ewheel) { if(!turret_initialize(this, TUR_EWHEEL)) delete(this); }
 
 METHOD(EWheel, tr_think, void(EWheel thistur, entity it))
 {
-    SELFPARAM();
-    float vz;
     vector wish_angle, real_angle;
 
-    vz = self.velocity_z;
+    float vz = it.velocity_z;
 
-    self.angles_x = anglemods(self.angles_x);
-    self.angles_y = anglemods(self.angles_y);
+    it.angles_x = anglemods(it.angles_x);
+    it.angles_y = anglemods(it.angles_y);
 
-    fixedmakevectors(self.angles);
+    fixedmakevectors(it.angles);
 
-    wish_angle = normalize(self.steerto);
+    wish_angle = normalize(it.steerto);
     wish_angle = vectoangles(wish_angle);
-    real_angle = wish_angle - self.angles;
-    real_angle = shortangle_vxy(real_angle, self.tur_head.angles);
+    real_angle = wish_angle - it.angles;
+    real_angle = shortangle_vxy(real_angle, it.tur_head.angles);
 
-    self.tur_head.spawnshieldtime = fabs(real_angle_y);
-    real_angle_y  = bound(-self.tur_head.aim_speed, real_angle_y, self.tur_head.aim_speed);
-    self.angles_y = (self.angles_y + real_angle_y);
+    it.tur_head.spawnshieldtime = fabs(real_angle_y);
+    real_angle_y  = bound(-it.tur_head.aim_speed, real_angle_y, it.tur_head.aim_speed);
+    it.angles_y = (it.angles_y + real_angle_y);
 
-    if(self.enemy)
-        ewheel_move_enemy();
-    else if(self.pathcurrent)
-        ewheel_move_path();
+    if(it.enemy)
+        ewheel_move_enemy(it);
+    else if(it.pathcurrent)
+        ewheel_move_path(it);
     else
-        ewheel_move_idle();
+        ewheel_move_idle(it);
 
-    self.velocity_z = vz;
+    it.velocity_z = vz;
 
-    if(self.velocity)
-        self.SendFlags |= TNSF_MOVE;
+    if(it.velocity)
+        it.SendFlags |= TNSF_MOVE;
 }
 
 METHOD(EWheel, tr_death, void(EWheel this, entity it))
@@ -175,7 +173,7 @@ METHOD(EWheel, tr_death, void(EWheel this, entity it))
     it.velocity = '0 0 0';
 
 #ifdef EWHEEL_FANCYPATH
-    if (self.pathcurrent)
+    if (it.pathcurrent)
         pathlib_deletepath(it.pathcurrent.owner);
 #endif
     it.pathcurrent = NULL;
@@ -183,43 +181,23 @@ METHOD(EWheel, tr_death, void(EWheel this, entity it))
 
 METHOD(EWheel, tr_setup, void(EWheel this, entity it))
 {
-    entity e;
-
-    if(it.movetype == MOVETYPE_WALK)
+    if(it.move_movetype == MOVETYPE_WALK)
     {
         it.velocity = '0 0 0';
-        it.enemy = world;
+        it.enemy = NULL;
 
         setorigin(it, it.pos1);
 
         if (it.target != "")
-        {
-            e = find(world, targetname, it.target);
-            if (!e)
-            {
-                LOG_TRACE("Initital waypoint for ewheel does NOT exsist, fix your map!\n");
-                it.target = "";
-            }
-
-            if (e.classname != "turret_checkpoint")
-                LOG_TRACE("Warning: not a turrret path\n");
-            else
-            {
-
-#ifdef EWHEEL_FANCYPATH
-                it.pathcurrent = WALKER_PATH(it, it.origin, e.origin);
-                it.pathgoal = e;
-#else
-                it.pathcurrent  = e;
-#endif
-            }
-        }
+            InitializeEntity(it, ewheel_findtarget, INITPRIO_FINDTARGET);
     }
 
     it.iscreature                              = true;
     it.teleportable                    = TELEPORT_NORMAL;
-    it.damagedbycontents               = true;
-    it.movetype                                = MOVETYPE_WALK;
+    if(!it.damagedbycontents)
+        IL_PUSH(g_damagedbycontents, it);
+    it.damagedbycontents        = true;
+    set_movetype(it, MOVETYPE_WALK);
     it.solid                                   = SOLID_SLIDEBOX;
     it.takedamage                              = DAMAGE_AIM;
     it.idle_aim                                = '0 0 0';
@@ -248,23 +226,19 @@ void ewheel_draw(entity this)
 
     fixedmakevectors(this.angles);
     setorigin(this, this.origin + this.velocity * dt);
-    this.tur_head.angles += dt * this.tur_head.move_avelocity;
-    this.angles_y = this.move_angles_y;
+    this.tur_head.angles += dt * this.tur_head.avelocity;
 
-    if (this.health < 127)
+    if(GetResourceAmount(this, RESOURCE_HEALTH) < 127)
     if(random() < 0.05)
         te_spark(this.origin + '0 0 40', randomvec() * 256 + '0 0 256', 16);
 }
 
-        METHOD(EWheel, tr_setup, void(EWheel this, entity it))
-        {
-            it.gravity         = 1;
-            it.movetype                = MOVETYPE_BOUNCE;
-            it.move_movetype   = MOVETYPE_BOUNCE;
-            it.move_origin     = it.origin;
-            it.move_time               = time;
-            it.draw                    = ewheel_draw;
-        }
+METHOD(EWheel, tr_setup, void(EWheel this, entity it))
+{
+    it.gravity         = 1;
+    set_movetype(it, MOVETYPE_BOUNCE);
+    it.move_time               = time;
+    it.draw                    = ewheel_draw;
+}
 
 #endif // CSQC
-#endif