]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Clear out .health and .armorvalue from the client side
authorMario <mario@smbclan.net>
Sat, 16 Jun 2018 17:25:07 +0000 (03:25 +1000)
committerMario <mario@smbclan.net>
Sat, 16 Jun 2018 17:25:07 +0000 (03:25 +1000)
21 files changed:
qcsrc/client/_mod.inc
qcsrc/client/_mod.qh
qcsrc/client/hud/panel/radar.qc
qcsrc/client/miscfunctions.qh
qcsrc/client/resources.qc [new file with mode: 0644]
qcsrc/client/resources.qh [new file with mode: 0644]
qcsrc/client/shownames.qc
qcsrc/common/debug.qh
qcsrc/common/ent_cs.qc
qcsrc/common/gamemodes/gamemode/onslaught/cl_controlpoint.qc
qcsrc/common/gamemodes/gamemode/onslaught/cl_generator.qc
qcsrc/common/gamemodes/gamemode/onslaught/onslaught.qc
qcsrc/common/mapobjects/func/door.qc
qcsrc/common/mapobjects/func/door_rotating.qc
qcsrc/common/mapobjects/trigger/swamp.qc
qcsrc/common/mutators/mutator/nades/net.qc
qcsrc/common/mutators/mutator/waypoints/waypointsprites.qc
qcsrc/common/turrets/cl_turrets.qc
qcsrc/common/turrets/turret/ewheel.qc
qcsrc/common/turrets/turret/walker.qc
qcsrc/server/client.qc

index aa20961a2b1a60d8037567f340518922df69ebac..ab9184b9b9efccf44caaaa393a6bace1bf0f6e8e 100644 (file)
@@ -6,6 +6,7 @@
 #include <client/mapvoting.qc>
 #include <client/miscfunctions.qc>
 #include <client/player_skeleton.qc>
+#include <client/resources.qc>
 #include <client/shownames.qc>
 #include <client/teamradar.qc>
 #include <client/view.qc>
index ecfa4ee1a6751d0d97c68e4b8f646befab9d2bba..971cc01de6afaf6e3a002942cfac832a15b9d165 100644 (file)
@@ -6,6 +6,7 @@
 #include <client/mapvoting.qh>
 #include <client/miscfunctions.qh>
 #include <client/player_skeleton.qh>
+#include <client/resources.qh>
 #include <client/shownames.qh>
 #include <client/teamradar.qh>
 #include <client/view.qh>
index f0ec01c9e7b1847e68734896348da82b7658ad0f..9959ad977e1a3cd2b5b97691dbdd2a6c514c56f8 100644 (file)
@@ -352,7 +352,7 @@ void HUD_Radar()
 
        IL_EACH(g_radaricons, it.teamradar_icon, {
                if ( hud_panel_radar_mouse )
-               if ( it.health >= 0 )
+               if ( GetResourceAmount(it, RESOURCE_HEALTH) >= 0 )
                if ( it.team == myteam + 1 || gametype == MAPINFO_TYPE_RACE || !teamplay )
                {
                        vector coord = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(it.origin));
index f23a3976b55c6fcaba36a0ec2d5301f80ab0ba8f..0143d1a0134ac1720a49273a0bb87b408156ab54 100644 (file)
@@ -34,7 +34,7 @@ float PreviewExists(string name);
 vector Rotate(vector v, float a);
 
 
-#define IS_DEAD(s) (((s).classname == "csqcmodel") ? (s).csqcmodel_isdead : ((s).health <= 0))
+#define IS_DEAD(s) (((s).classname == "csqcmodel") ? (s).csqcmodel_isdead : (GetResourceAmount((s), RESOURCE_HEALTH) <= 0))
 
 
 // decolorizes and team colors the player name when needed
diff --git a/qcsrc/client/resources.qc b/qcsrc/client/resources.qc
new file mode 100644 (file)
index 0000000..1dbbe66
--- /dev/null
@@ -0,0 +1,61 @@
+#include "resources.qh"
+
+/// \file
+/// \brief Source file that contains implementation of the resource system.
+/// \copyright GNU GPLv2 or any later version.
+
+float GetResourceAmount(entity e, int resource_type)
+{
+       .float resource_field = GetResourceField(resource_type);
+       return e.(resource_field);
+}
+
+bool SetResourceAmountExplicit(entity e, int resource_type, float amount)
+{
+       .float resource_field = GetResourceField(resource_type);
+       if (e.(resource_field) != amount)
+       {
+               e.(resource_field) = amount;
+               return true;
+       }
+       return false;
+}
+
+void SetResourceAmount(entity e, int resource_type, float amount)
+{
+       SetResourceAmountExplicit(e, resource_type, amount);
+}
+
+int GetResourceType(.float resource_field)
+{
+       switch (resource_field)
+       {
+               case health: { return RESOURCE_HEALTH; }
+               case armorvalue: { return RESOURCE_ARMOR; }
+               case ammo_shells: { return RESOURCE_SHELLS; }
+               case ammo_nails: { return RESOURCE_BULLETS; }
+               case ammo_rockets: { return RESOURCE_ROCKETS; }
+               case ammo_cells: { return RESOURCE_CELLS; }
+               case ammo_plasma: { return RESOURCE_PLASMA; }
+               case ammo_fuel: { return RESOURCE_FUEL; }
+       }
+       error("GetResourceType: Invalid field.");
+       return 0;
+}
+
+.float GetResourceField(int resource_type)
+{
+       switch (resource_type)
+       {
+               case RESOURCE_HEALTH: { return health; }
+               case RESOURCE_ARMOR: { return armorvalue; }
+               case RESOURCE_SHELLS: { return ammo_shells; }
+               case RESOURCE_BULLETS: { return ammo_nails; }
+               case RESOURCE_ROCKETS: { return ammo_rockets; }
+               case RESOURCE_CELLS: { return ammo_cells; }
+               case RESOURCE_PLASMA: { return ammo_plasma; }
+               case RESOURCE_FUEL: { return ammo_fuel; }
+       }
+       error("GetResourceField: Invalid resource type.");
+       return health;
+}
diff --git a/qcsrc/client/resources.qh b/qcsrc/client/resources.qh
new file mode 100644 (file)
index 0000000..d1079e7
--- /dev/null
@@ -0,0 +1,44 @@
+#pragma once
+
+/// \file
+/// \brief Header file that describes the resource system.
+/// \copyright GNU GPLv2 or any later version.
+
+#include <common/resources.qh>
+
+/// \brief Unconditional maximum amount of resources the entity can have.
+const int RESOURCE_AMOUNT_HARD_LIMIT = 999;
+
+// ============================ Public API ====================================
+
+/// \brief Returns the current amount of resource the given entity has.
+/// \param[in] e Entity to check.
+/// \param[in] resource_type Type of the resource (a RESOURCE_* constant).
+/// \return Current amount of resource the given entity has.
+float GetResourceAmount(entity e, int resource_type);
+
+/// \brief Sets the resource amount of an entity without calling any hooks.
+/// \param[in,out] e Entity to adjust.
+/// \param[in] resource_type Type of the resource (a RESOURCE_* constant).
+/// \param[in] amount Amount of resource to set.
+/// \return Boolean for whether the ammo amount was changed
+bool SetResourceAmountExplicit(entity e, int resource_type, float amount);
+
+/// \brief Sets the current amount of resource the given entity will have.
+/// \param[in,out] e Entity to adjust.
+/// \param[in] resource_type Type of the resource (a RESOURCE_* constant).
+/// \param[in] amount Amount of resource to set.
+/// \return No return.
+void SetResourceAmount(entity e, int resource_type, float amount);
+
+// ===================== Legacy and/or internal API ===========================
+
+/// \brief Converts an entity field to resource type.
+/// \param[in] resource_field Entity field to convert.
+/// \return Resource type (a RESOURCE_* constant).
+int GetResourceType(.float resource_field);
+
+/// \brief Converts resource type (a RESOURCE_* constant) to entity field.
+/// \param[in] resource_type Type of the resource.
+/// \return Entity field for that resource.
+.float GetResourceField(int resource_type);
index 8a7d225bff7bdc319260e5e0648a2aaff9b7aa08..2dbd8efa2760a437cd58bef57b9f7273a8a7b576 100644 (file)
@@ -157,10 +157,10 @@ void Draw_ShowNames(entity this)
                                        this.healthvalue / autocvar_hud_panel_healtharmor_maxhealth, false, 1, '1 0 0', a,
                                        DRAWFLAG_NORMAL);
                        }
-                       if (this.armorvalue > 0)
+                       if (GetResourceAmount(this, RESOURCE_ARMOR) > 0)
                        {
                                HUD_Panel_DrawProgressBar(pos + eX * 0.5 * mySize.x, sz, "nametag_statusbar",
-                                       this.armorvalue / autocvar_hud_panel_healtharmor_maxarmor, false, 0, '0 1 0', a,
+                                       GetResourceAmount(this, RESOURCE_ARMOR) / autocvar_hud_panel_healtharmor_maxarmor, false, 0, '0 1 0', a,
                                        DRAWFLAG_NORMAL);
                        }
                }
@@ -193,13 +193,13 @@ void Draw_ShowNames_All()
                if (entcs.m_entcs_private)
                {
                        it.healthvalue = entcs.healthvalue;
-                       it.armorvalue = entcs.armorvalue;
+                       SetResourceAmountExplicit(it, RESOURCE_ARMOR, GetResourceAmount(entcs, RESOURCE_ARMOR));
                        it.sameteam = true;
                }
                else
                {
                        it.healthvalue = 0;
-                       it.armorvalue = 0;
+                       SetResourceAmountExplicit(it, RESOURCE_ARMOR, 0);
                        it.sameteam = false;
                }
                bool dead = entcs_IsDead(i) || entcs_IsSpectating(i);
index 983b073b406c8cfb93de92a31002d5dd1359fa56..ab4e6f2e950fffc5e5ce489d27e26acf004f61c1 100644 (file)
@@ -403,7 +403,7 @@ CLASS(DebugText3d, Object)
                CONSTRUCT(DebugText3d);
                this.origin = pos;
                this.message = strzone(msg);
-               this.health = align;
+               SetResourceAmount(this, RESOURCE_HEALTH, align);
                this.hit_time = time;
                this.fade_rate = fade_rate_;
                this.velocity = vel;
@@ -425,7 +425,7 @@ CLASS(DebugText3d, Object)
 
                int size = 8;
                vector screen_pos = project_3d_to_2d(this.origin) + since_created * this.velocity;
-               float align = this.health;
+               float align = GetResourceAmount(this, RESOURCE_HEALTH);
                if (align > 0)
                        screen_pos.x -= stringwidth(this.message, true, size * '1 1 0') * min(1, align);
                if (screen_pos.z < 0) return; // behind camera
index f07add5eeb81799efc770328da71f0eca7e32b30..86acdc154064ac6d0bc80258e7fca234d369740c 100644 (file)
@@ -83,7 +83,7 @@ ENTCS_PROP_RESOURCE(HEALTH, false, RESOURCE_HEALTH, ENTCS_SET_NORMAL,
 
 ENTCS_PROP_RESOURCE(ARMOR, false, RESOURCE_ARMOR, ENTCS_SET_NORMAL,
        { WriteByte(chan, bound(0, GetResourceAmount(ent, RESOURCE_ARMOR) / 10, 255));  /* FIXME: use a better scale? */ },
-       { ent.armorvalue = ReadByte() * 10; })
+       { SetResourceAmountExplicit(ent, RESOURCE_ARMOR, ReadByte() * 10); })
 
 ENTCS_PROP(NAME, true, netname, ENTCS_SET_MUTABLE_STRING,
        { WriteString(chan, ent.netname); },
index a03e5b3353f8b6156eac2d8012ff5e0af9d2c96a..b8d49b10f2edce3580b517f2556a95f35fd092f7 100644 (file)
@@ -30,7 +30,7 @@ void cpicon_draw(entity this)
        this.cp_bob_spd = this.cp_bob_spd + 1.875 * frametime;
        this.colormod = '1 1 1' * (2 - bound(0, (this.pain_finished - time) / 10, 1));
 
-       if(!this.iscaptured) this.alpha = this.health / this.max_health;
+       if(!this.iscaptured) this.alpha = GetResourceAmount(this, RESOURCE_HEALTH) / this.max_health;
 
        if(this.iscaptured)
        {
@@ -165,14 +165,14 @@ NET_HANDLE(ENT_CLIENT_CONTROLPOINT_ICON, bool isnew)
                this.origin = ReadVector();
                setorigin(this, this.origin);
 
-               this.health = ReadByte();
+               SetResourceAmountExplicit(this, RESOURCE_HEALTH, ReadByte());
                this.max_health = ReadByte();
                this.count = ReadByte();
                this.team = ReadByte();
                this.iscaptured = ReadByte();
 
                if(!this.count)
-                       this.count = (this.health - this.max_health) * frametime;
+                       this.count = (GetResourceAmount(this, RESOURCE_HEALTH) - this.max_health) * frametime;
 
                cpicon_changeteam(this);
                cpicon_construct(this, isnew);
@@ -189,9 +189,9 @@ NET_HANDLE(ENT_CLIENT_CONTROLPOINT_ICON, bool isnew)
 
                _tmp = ReadByte();
 
-               if(_tmp != this.health)
+               if(_tmp != GetResourceAmount(this, RESOURCE_HEALTH))
                        cpicon_damage(this, _tmp);
 
-               this.health = _tmp;
+               SetResourceAmountExplicit(this, RESOURCE_HEALTH, _tmp);
        }
 }
index a3374bf91e804f4db0ae4993eb107349d3c72411..9d12c5548e6d4eafd4abdb336b6aa7208274bda3 100644 (file)
@@ -48,10 +48,10 @@ void generator_draw(entity this)
        if(time < this.move_time)
                return;
 
-       if(this.health > 0)
+       if(GetResourceAmount(this, RESOURCE_HEALTH) > 0)
        {
                // damaged fx (less probable the more damaged is the generator)
-               if(random() < 0.9 - this.health / this.max_health)
+               if(random() < 0.9 - GetResourceAmount(this, RESOURCE_HEALTH) / this.max_health)
                if(random() < 0.01)
                {
                        pointparticles(EFFECT_ELECTRO_BALLEXPLODE, this.origin + randompos('-50 -50 -20', '50 50 50'), '0 0 0', 1);
@@ -195,7 +195,7 @@ NET_HANDLE(ENT_CLIENT_GENERATOR, bool isnew)
                this.origin = ReadVector();
                setorigin(this, this.origin);
 
-               this.health = ReadByte();
+               SetResourceAmountExplicit(this, RESOURCE_HEALTH, ReadByte());
                this.max_health = ReadByte();
                this.count = ReadByte();
                this.team = ReadByte();
@@ -219,9 +219,9 @@ NET_HANDLE(ENT_CLIENT_GENERATOR, bool isnew)
 
                _tmp = ReadByte();
 
-               if(_tmp != this.health)
+               if(_tmp != GetResourceAmount(this, RESOURCE_HEALTH))
                        generator_damage(this, _tmp);
 
-               this.health = _tmp;
+               SetResourceAmountExplicit(this, RESOURCE_HEALTH, _tmp);
        }
 }
index 80d6a6be29fa146940ccf242cfddb9c90413e2ea..5deef7ec22e01351ebf2f8b3796cd4c47b39f3d6 100644 (file)
@@ -36,7 +36,7 @@ MUTATOR_HOOKFUNCTION(cl_ons, WantEventchase)
        entity gen = NULL;
        if(ons_roundlost)
        {
-               IL_EACH(g_onsgenerators, it.health <= 0,
+               IL_EACH(g_onsgenerators, GetResourceAmount(it, RESOURCE_HEALTH) <= 0,
                {
                        gen = it;
                        break;
index 757b848955fc7820e956c0a5da4e00c364d197ec..4cb924bd6ab9db9fc417f91702b3cb13ccf4605b 100644 (file)
@@ -113,11 +113,7 @@ void door_go_down(entity this)
        if (this.max_health)
        {
                this.takedamage = DAMAGE_YES;
-       #ifdef SVQC
                SetResourceAmountExplicit(this, RESOURCE_HEALTH, this.max_health);
-       #elif defined(CSQC)
-               this.health = this.max_health;
-       #endif
        }
 
        this.state = STATE_DOWN;
@@ -269,11 +265,7 @@ void door_damage(entity this, entity inflictor, entity attacker, float damage, i
        if(this.spawnflags & NOSPLASH)
                if(!(DEATH_ISSPECIAL(deathtype)) && (deathtype & HITTYPE_SPLASH))
                        return;
-#ifdef SVQC
        SetResourceAmountExplicit(this, RESOURCE_HEALTH, GetResourceAmount(this, RESOURCE_HEALTH) - damage);
-#elif defined(CSQC)
-       this.health -= damage;
-#endif
 
        if (this.itemkeys)
        {
@@ -281,21 +273,12 @@ void door_damage(entity this, entity inflictor, entity attacker, float damage, i
                return;
        }
 
-#ifdef SVQC
        if (GetResourceAmount(this, RESOURCE_HEALTH) <= 0)
        {
                SetResourceAmountExplicit(this.owner, RESOURCE_HEALTH, this.owner.max_health);
                this.owner.takedamage = DAMAGE_NO;      // will be reset upon return
                door_use(this.owner, NULL, NULL);
        }
-#elif defined(CSQC)
-       if(this.health <= 0)
-       {
-               this.owner.health = this.owner.max_health;
-               this.owner.takedamage = DAMAGE_NO;
-               door_use(this.owner, NULL, NULL);
-       }
-#endif
 }
 
 .float door_finished;
@@ -374,11 +357,10 @@ Spawned if a door lacks a real activator
 
 void door_trigger_touch(entity this, entity toucher)
 {
-#ifdef SVQC
        if (GetResourceAmount(toucher, RESOURCE_HEALTH) < 1)
+#ifdef SVQC
                if (!((toucher.iscreature || (toucher.flags & FL_PROJECTILE)) && !IS_DEAD(toucher)))
 #elif defined(CSQC)
-       if (toucher.health < 1)
                if(!((IS_CLIENT(toucher) || toucher.classname == "csqcprojectile") && !IS_DEAD(toucher)))
 #endif
                        return;
@@ -459,11 +441,7 @@ void LinkDoors(entity this)
        {
                this.owner = this.enemy = this;
 
-#ifdef SVQC
                if (GetResourceAmount(this, RESOURCE_HEALTH))
-#elif defined(CSQC)
-               if(this.health)
-#endif
                        return;
                IFTARGETED
                        return;
@@ -496,13 +474,8 @@ void LinkDoors(entity this)
        cmaxs = this.absmax;
        for(t = this; ; t = t.enemy)
        {
-       #ifdef SVQC
                if(GetResourceAmount(t, RESOURCE_HEALTH) && !GetResourceAmount(this, RESOURCE_HEALTH))
                        SetResourceAmountExplicit(this, RESOURCE_HEALTH, GetResourceAmount(t, RESOURCE_HEALTH));
-       #elif defined(CSQC)
-               if(t.health && !this.health)
-                       this.health = t.health;
-       #endif
                if((t.targetname != "") && (this.targetname == ""))
                        this.targetname = t.targetname;
                if((t.message != "") && (this.message == ""))
@@ -526,11 +499,7 @@ void LinkDoors(entity this)
        // distribute health, targetname, message
        for(t = this; t; t = t.enemy)
        {
-       #ifdef SVQC
                SetResourceAmountExplicit(t, RESOURCE_HEALTH, GetResourceAmount(this, RESOURCE_HEALTH));
-       #elif defined(CSQC)
-               t.health = this.health;
-       #endif
                t.targetname = this.targetname;
                t.message = this.message;
                if(t.enemy == this)
@@ -540,11 +509,7 @@ void LinkDoors(entity this)
        // shootable, or triggered doors just needed the owner/enemy links,
        // they don't spawn a field
 
-#ifdef SVQC
        if (GetResourceAmount(this, RESOURCE_HEALTH))
-#elif defined(CSQC)
-       if(this.health)
-#endif
                return;
        IFTARGETED
                return;
index ebe7b2a9800134bb88eac4a1c2688b4697787cc4..39c02a8669881528f5a57d792c921fe03530c890 100644 (file)
@@ -58,11 +58,7 @@ void door_rotating_go_down(entity this)
        if (this.max_health)
        {
                this.takedamage = DAMAGE_YES;
-       #ifdef SVQC
                SetResourceAmountExplicit(this, RESOURCE_HEALTH, this.max_health);
-       #elif defined(CSQC)
-               this.health = this.max_health;
-       #endif
        }
 
        this.state = STATE_DOWN;
index 1acd8e0ab0cc65acafb5f2a6187b6d7a435af8be..fd40e2f34db29d4a04e88dd69074742da043cfd8 100644 (file)
@@ -40,18 +40,10 @@ void swampslug_think(entity this);
 void swampslug_think(entity this)
 {
        //Slowly kill the slug
-#ifdef SVQC
        SetResourceAmountExplicit(this, RESOURCE_HEALTH, GetResourceAmount(this, RESOURCE_HEALTH) - 1);
-#elif defined(CSQC)
-       this.health -= 1;
-#endif
 
        //Slug dead? then remove curses.
-#ifdef SVQC
        if(GetResourceAmount(this, RESOURCE_HEALTH) <= 0)
-#elif defined(CSQC)
-       if(this.health <= 0)
-#endif
        {
                this.owner.in_swamp = 0;
                delete(this);
@@ -84,11 +76,7 @@ void swamp_touch(entity this, entity toucher)
                // If not attach one.
                //centerprint(toucher,"Entering swamp!\n");
                toucher.swampslug = spawn();
-       #ifdef SVQC
                SetResourceAmountExplicit(toucher.swampslug, RESOURCE_HEALTH, 2);
-       #elif defined(CSQC)
-               toucher.swampslug.health = 2;
-       #endif
                setthink(toucher.swampslug, swampslug_think);
                toucher.swampslug.nextthink = time;
                toucher.swampslug.owner = toucher;
@@ -102,11 +90,7 @@ void swamp_touch(entity this, entity toucher)
        //toucher.in_swamp = 1;
 
        //Revitalize players swampslug
-#ifdef SVQC
        SetResourceAmountExplicit(toucher.swampslug, RESOURCE_HEALTH, 2);
-#elif defined(CSQC)
-       toucher.swampslug.health = 2;
-#endif
 }
 
 REGISTER_NET_LINKED(ENT_CLIENT_SWAMP)
index a691b866f789b448c8cfdf0d699cb2de892e9f85..1fdf5fd7aad1a5e2ef0e85c68d326da0fb6845bc 100644 (file)
@@ -32,7 +32,7 @@ void orb_setup(entity e)
 
        e.draw = orb_draw;
        IL_PUSH(g_drawables, e);
-       e.health = 255;
+       SetResourceAmountExplicit(e, RESOURCE_HEALTH, 255);
        set_movetype(e, MOVETYPE_NONE);
        e.solid = SOLID_NOT;
        e.drawmask = MASK_NORMAL;
index 530965e49077f386685c39b2c94d64a8e75f0db1..dcbb65f65cd29472659141b93617b7a8182c2075 100644 (file)
@@ -134,7 +134,7 @@ void Ent_WaypointSprite(entity this, bool isnew)
         int t = ReadByte();
         if (t < 192)
         {
-            this.health = t / 191.0;
+            SetResourceAmountExplicit(this, RESOURCE_HEALTH, t / 191.0);
             this.build_finished = 0;
         }
         else
@@ -142,7 +142,7 @@ void Ent_WaypointSprite(entity this, bool isnew)
             t = (t - 192) * 256 + ReadByte();
             this.build_started = servertime;
             if (this.build_finished)
-                this.build_starthealth = bound(0, this.health, 1);
+                this.build_starthealth = bound(0, GetResourceAmount(this, RESOURCE_HEALTH), 1);
             else
                 this.build_starthealth = 0;
             this.build_finished = servertime + t / 32;
@@ -150,7 +150,7 @@ void Ent_WaypointSprite(entity this, bool isnew)
     }
     else
     {
-        this.health = -1;
+        SetResourceAmountExplicit(this, RESOURCE_HEALTH, -1);
         this.build_finished = 0;
     }
 
@@ -654,14 +654,14 @@ void Draw_WaypointSprite(entity this)
         if (time < this.build_finished + 0.25)
         {
             if (time < this.build_started)
-                this.health = this.build_starthealth;
+                SetResourceAmountExplicit(this, RESOURCE_HEALTH, this.build_starthealth);
             else if (time < this.build_finished)
-                this.health = (time - this.build_started) / (this.build_finished - this.build_started) * (1 - this.build_starthealth) + this.build_starthealth;
+                SetResourceAmountExplicit(this, RESOURCE_HEALTH, (time - this.build_started) / (this.build_finished - this.build_started) * (1 - this.build_starthealth) + this.build_starthealth);
             else
-                this.health = 1;
+                SetResourceAmountExplicit(this, RESOURCE_HEALTH, 1);
         }
         else
-            this.health = -1;
+            SetResourceAmountExplicit(this, RESOURCE_HEALTH, -1);
     }
 
     o = drawspritearrow(o, ang, rgb, a, SPRITE_ARROW_SCALE * t);
@@ -709,7 +709,7 @@ void Draw_WaypointSprite(entity this)
     }
 
     draw_beginBoldFont();
-    if (this.health >= 0)
+    if (GetResourceAmount(this, RESOURCE_HEALTH) >= 0)
     {
         float align = 0, marg;
         if (this.build_finished)
@@ -726,7 +726,7 @@ void Draw_WaypointSprite(entity this)
         drawhealthbar(
                 o,
                 0,
-                this.health,
+                GetResourceAmount(this, RESOURCE_HEALTH),
                 '0 0 0',
                 '0 0 0',
                 SPRITE_HEALTHBAR_WIDTH * t,
index ba7b5d01bb5ba25c87ce00d1ad83b55b1f81923e..fb27cd12137fef8e36cd30dfb09f133077c3cf6c 100644 (file)
@@ -37,7 +37,7 @@ void turret_draw(entity this)
 
        this.tur_head.angles += dt * this.tur_head.avelocity;
 
-       if (this.health < 127)
+       if (GetResourceAmount(this, RESOURCE_HEALTH) < 127)
        {
                dt = random();
 
@@ -45,11 +45,11 @@ void turret_draw(entity this)
                        te_spark(this.origin + '0 0 40', randomvec() * 256 + '0 0 256', 16);
        }
 
-       if(this.health < 85)
+       if(GetResourceAmount(this, RESOURCE_HEALTH) < 85)
        if(dt < 0.01)
                pointparticles(EFFECT_SMOKE_LARGE, (this.origin + (randomvec() * 80)), '0 0 0', 1);
 
-       if(this.health < 32)
+       if(GetResourceAmount(this, RESOURCE_HEALTH) < 32)
        if(dt < 0.015)
                pointparticles(EFFECT_SMOKE_SMALL, (this.origin + (randomvec() * 80)), '0 0 0', 1);
 
@@ -180,7 +180,7 @@ void turret_draw2d(entity this)
        drawhealthbar(
                        o,
                        0,
-                       this.health / 255,
+                       GetResourceAmount(this, RESOURCE_HEALTH) / 255,
                        '0 0 0',
                        '0 0 0',
                        0.5 * SPRITE_HEALTHBAR_WIDTH * t,
@@ -221,7 +221,7 @@ void turret_construct(entity this, bool isnew)
        set_movetype(this.tur_head, MOVETYPE_NOCLIP);
        set_movetype(this, MOVETYPE_NOCLIP);
        this.tur_head.angles                    = this.angles;
-       this.health                                             = 255;
+       SetResourceAmountExplicit(this, RESOURCE_HEALTH, 255);
        this.solid                                              = SOLID_BBOX;
        this.tur_head.solid                             = SOLID_NOT;
        set_movetype(this, MOVETYPE_NOCLIP);
@@ -422,13 +422,13 @@ NET_HANDLE(ENT_CLIENT_TURRET, bool isnew)
                }
 
                _tmp = ReadByte();
-               if(_tmp == 0 && this.health != 0)
+               float myhp = GetResourceAmount(this, RESOURCE_HEALTH);
+               if(_tmp == 0 && myhp != 0)
                        turret_die(this);
-               else if(this.health && this.health != _tmp)
+               else if(myhp && myhp != _tmp)
                        this.helpme = servertime + 10;
 
-               this.health = _tmp;
+               SetResourceAmountExplicit(this, RESOURCE_HEALTH, _tmp);
        }
-       //this.enemy.health = this.health / 255;
        return true;
 }
index 3b237ea99fd3080edcb2a9214d3f56a192ce039f..c0a0b177ee2d179afb99aeb774203521daf5eeeb 100644 (file)
@@ -228,7 +228,7 @@ void ewheel_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.05)
         te_spark(this.origin + '0 0 40', randomvec() * 256 + '0 0 256', 16);
 }
index 549d6f5f321a599fe798c06f39df3691fa389840..02b5067470087a8e4a3d24f8a1e5414c3cdc6b79 100644 (file)
@@ -629,17 +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
index 24a0e0e1aab630da7ba311515a7aeb5a778482d1..d0e2074856e55dbeac63782faaf9811f0ac16cd8 100644 (file)
@@ -1756,13 +1756,13 @@ void player_regen(entity this)
        // Ugly hack to make sure the health and armor don't go beyond hard limit.
        // TODO: Remove this hack when all code uses GivePlayerHealth and
        // GivePlayerArmor.
-       if (this.health > RESOURCE_AMOUNT_HARD_LIMIT)
+       if (GetResourceAmount(this, RESOURCE_HEALTH) > RESOURCE_AMOUNT_HARD_LIMIT)
        {
-               this.health = RESOURCE_AMOUNT_HARD_LIMIT;
+               SetResourceAmountExplicit(this, RESOURCE_HEALTH, RESOURCE_AMOUNT_HARD_LIMIT);
        }
-       if (this.armorvalue > RESOURCE_AMOUNT_HARD_LIMIT)
+       if (GetResourceAmount(this, RESOURCE_ARMOR) > RESOURCE_AMOUNT_HARD_LIMIT)
        {
-               this.armorvalue = RESOURCE_AMOUNT_HARD_LIMIT;
+               SetResourceAmountExplicit(this, RESOURCE_ARMOR, RESOURCE_AMOUNT_HARD_LIMIT);
        }
        // End hack.
 }