]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/turrets/turret/walker.qc
Clear out .health and .armorvalue from the client side
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / turrets / turret / walker.qc
index 727da27f945aa4ef67a3a58a44504a4380b2e92a..02b5067470087a8e4a3d24f8a1e5414c3cdc6b79 100644 (file)
@@ -1,26 +1,4 @@
-#ifndef TURRET_WALKER_H
-#define TURRET_WALKER_H
-
-//#define WALKER_FANCYPATHING
-
-#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_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);
-ENDCLASS(WalkerTurret)
-REGISTER_TURRET(WALKER, NEW(WalkerTurret));
-
-#endif
-
-#ifdef IMPLEMENTATION
+#include "walker.qh"
 
 #ifdef SVQC
 
@@ -63,8 +41,6 @@ const int ANIM_ROAM       = 11;
 .float animflag;
 .float idletime;
 
-#define WALKER_PATH(this, s, e) pathlib_astar(this, s, e)
-
 bool walker_firecheck(entity this)
 {
     if (this.animflag == ANIM_MELEE)
@@ -86,7 +62,7 @@ void walker_melee_do_dmg(entity this)
     {
         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));
+                Damage(e, this, this, (autocvar_g_turrets_unit_walker_melee_damage), DEATH_TURRET_WALK_MELEE.m_id, DMG_NOWEP, '0 0 0', v_forward * (autocvar_g_turrets_unit_walker_melee_force));
 
         e = e.chain;
     }
@@ -99,8 +75,8 @@ void walker_setnoanim(entity this)
 }
 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);
-    delete (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, DMG_NOWEP, NULL);
+    delete(this);
 }
 
 void walker_rocket_touch(entity this, entity toucher)
@@ -108,12 +84,12 @@ void walker_rocket_touch(entity this, entity toucher)
     walker_rocket_explode(this);
 }
 
-void walker_rocket_damage(entity this, entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector vforce)
+void walker_rocket_damage(entity this, entity inflictor, entity attacker, float damage, float deathtype, .entity weaponentity, vector hitloc, vector vforce)
 {
-    this.health = this.health - damage;
+    SetResourceAmountExplicit(this, RESOURCE_HEALTH, GetResourceAmount(this, RESOURCE_HEALTH) - damage);
     this.velocity = this.velocity + vforce;
 
-    if (this.health <= 0)
+    if (GetResourceAmount(this, RESOURCE_HEALTH) <= 0)
         W_PrepareExplosionByDamage(this, this.owner, walker_rocket_explode);
 }
 
@@ -242,7 +218,7 @@ void walker_fire_rocket(entity this, vector org)
     rocket.bot_dodgerating     = 50;
     rocket.takedamage           = DAMAGE_YES;
     rocket.damageforcescale   = 2;
-    rocket.health                       = 25;
+    SetResourceAmountExplicit(rocket, RESOURCE_HEALTH, 25);
     rocket.tur_shotorg         = randomvec() * 512;
     rocket.cnt                         = time + 1;
     rocket.enemy                         = this.enemy;
@@ -261,6 +237,7 @@ void walker_fire_rocket(entity this, vector org)
     settouch(rocket, walker_rocket_touch);
     rocket.flags = FL_PROJECTILE;
     IL_PUSH(g_projectiles, rocket);
+    IL_PUSH(g_bot_dodge, rocket);
     rocket.solid                         = SOLID_BBOX;
     rocket.max_health           = time + 9;
     rocket.missile_flags = MIF_SPLASH | MIF_PROXY | MIF_GUIDED_HEAT;
@@ -304,7 +281,8 @@ void walker_move_path(entity this)
 {
 #ifdef WALKER_FANCYPATHING
     // Are we close enougth to a path node to switch to the next?
-    if(vdist(this.origin - this.pathcurrent.origin, <, 64))
+    if(turret_closetotarget(this, this.pathcurrent.origin))
+    {
         if (this.pathcurrent.path_next == NULL)
         {
             // Path endpoint reached
@@ -318,7 +296,7 @@ void walker_move_path(entity this)
 
                 if (this.pathgoal.enemy)
                 {
-                    this.pathcurrent = WALKER_PATH(this, this.pathgoal.origin, this.pathgoal.enemy.origin);
+                    this.pathcurrent = pathlib_astar(this, this.pathgoal.origin, this.pathgoal.enemy.origin);
                     this.pathgoal = this.pathgoal.enemy;
                 }
             }
@@ -327,13 +305,14 @@ void walker_move_path(entity this)
         }
         else
             this.pathcurrent = this.pathcurrent.path_next;
+    }
 
     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(vdist(this.origin - this.pathcurrent.origin, <, 64))
+    if(turret_closetotarget(this, this.pathcurrent.origin))
         this.pathcurrent = this.pathcurrent.enemy;
 
     if(!this.pathcurrent)
@@ -345,13 +324,37 @@ void walker_move_path(entity this)
 #endif
 }
 
+void walker_findtarget(entity this)
+{
+    entity e = find(NULL, targetname, this.target);
+    if (!e)
+    {
+        LOG_TRACE("Initital waypoint for walker does NOT exist, fix your map!");
+        this.target = "";
+    }
+
+    if (e.classname != "turret_checkpoint")
+        LOG_TRACE("Warning: not a turrret path");
+    else
+    {
+#ifdef WALKER_FANCYPATHING
+        this.pathcurrent = pathlib_astar(this, this.origin, e.origin);
+        this.pathgoal = e;
+#else
+        this.pathcurrent = e;
+#endif
+    }
+
+    // TODO: this doesn't reset target, so tur_defend will be the checkpoint too!
+}
+
 spawnfunc(turret_walker) { if(!turret_initialize(this, TUR_WALKER)) delete(this); }
 
 METHOD(WalkerTurret, tr_think, void(WalkerTurret thistur, entity it))
 {
     fixedmakevectors(it.angles);
 
-    if (it.spawnflags & TSF_NO_PATHBREAK && it.pathcurrent)
+    if ((it.spawnflags & TSF_NO_PATHBREAK) && it.pathcurrent)
         walker_move_path(it);
     else if (it.enemy == NULL)
     {
@@ -569,8 +572,6 @@ METHOD(WalkerTurret, tr_setup, void(WalkerTurret this, entity it))
 {
     it.ticrate = 0.05;
 
-    entity e;
-
     // Respawn is called & first spawn to, to set team. need to make sure we do not move the initial spawn.
     if(it.move_movetype == MOVETYPE_WALK)
     {
@@ -588,6 +589,8 @@ METHOD(WalkerTurret, tr_setup, void(WalkerTurret this, entity it))
     it.target_validate_flags = TFL_TARGETSELECT_PLAYERS | TFL_TARGETSELECT_RANGELIMITS | TFL_TARGETSELECT_TEAMCHECK | TFL_TARGETSELECT_LOS;
     it.iscreature = true;
     it.teleportable = TELEPORT_NORMAL;
+    if(!it.damagedbycontents)
+        IL_PUSH(g_damagedbycontents, it);
     it.damagedbycontents = true;
     it.solid = SOLID_SLIDEBOX;
     it.takedamage = DAMAGE_AIM;
@@ -604,26 +607,7 @@ METHOD(WalkerTurret, tr_setup, void(WalkerTurret this, entity it))
     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!");
-            it.target = "";
-        }
-
-        if (e.classname != "turret_checkpoint")
-            LOG_TRACE("Warning: not a turrret path");
-        else
-        {
-#ifdef WALKER_FANCYPATHING
-            it.pathcurrent = WALKER_PATH(it, it.origin, e.origin);
-            it.pathgoal = e;
-#else
-            it.pathcurrent = e;
-#endif
-        }
-    }
+        InitializeEntity(it, walker_findtarget, INITPRIO_FINDTARGET);
 }
 
 #endif // SVQC
@@ -645,18 +629,17 @@ void walker_draw(entity this)
     setorigin(this, this.origin + this.velocity * dt);
     this.tur_head.angles += dt * this.tur_head.avelocity;
 
-    if (this.health < 127)
+    if(GetResourceAmount(this, RESOURCE_HEALTH) < 127)
     if(random() < 0.15)
         te_spark(this.origin + '0 0 40', randomvec() * 256 + '0 0 256', 16);
 }
 
-        METHOD(WalkerTurret, tr_setup, void(WalkerTurret this, entity it))
-        {
-            it.gravity         = 1;
-            set_movetype(it, MOVETYPE_BOUNCE);
-            it.move_time               = time;
-            it.draw                    = walker_draw;
-        }
+METHOD(WalkerTurret, tr_setup, void(WalkerTurret this, entity it))
+{
+    it.gravity         = 1;
+    set_movetype(it, MOVETYPE_BOUNCE);
+    it.move_time               = time;
+    it.draw                    = walker_draw;
+}
 
 #endif // CSQC
-#endif