]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Migrating resources (ammo, health etc) to a registry for ease of maintenance and...
authorMario <mario.mario@y7mail.com>
Tue, 18 Jan 2022 18:02:17 +0000 (18:02 +0000)
committerterencehill <piuntn@gmail.com>
Tue, 18 Jan 2022 18:02:17 +0000 (18:02 +0000)
70 files changed:
qcsrc/client/_mod.inc
qcsrc/client/_mod.qh
qcsrc/client/hud/panel/ammo.qc
qcsrc/client/hud/panel/radar.qc
qcsrc/client/hud/panel/strafehud.qc
qcsrc/client/hud/panel/weapons.qc
qcsrc/client/resources.qc [deleted file]
qcsrc/client/resources.qh [deleted file]
qcsrc/client/shownames.qc
qcsrc/common/_all.inc
qcsrc/common/_mod.inc
qcsrc/common/debug.qh
qcsrc/common/ent_cs.qc
qcsrc/common/gamemodes/gamemode/freezetag/sv_freezetag.qc
qcsrc/common/items/item/ammo.qh
qcsrc/common/mutators/mutator/nix/sv_nix.qc
qcsrc/common/mutators/mutator/overkill/okhmg.qh
qcsrc/common/mutators/mutator/overkill/okmachinegun.qh
qcsrc/common/mutators/mutator/overkill/oknex.qh
qcsrc/common/mutators/mutator/overkill/okrpc.qh
qcsrc/common/mutators/mutator/overkill/okshotgun.qh
qcsrc/common/notifications/all.qh
qcsrc/common/resources.qh [deleted file]
qcsrc/common/resources/_mod.inc [new file with mode: 0644]
qcsrc/common/resources/_mod.qh [new file with mode: 0644]
qcsrc/common/resources/all.inc [new file with mode: 0644]
qcsrc/common/resources/cl_resources.qc [new file with mode: 0644]
qcsrc/common/resources/cl_resources.qh [new file with mode: 0644]
qcsrc/common/resources/resources.qc [new file with mode: 0644]
qcsrc/common/resources/resources.qh [new file with mode: 0644]
qcsrc/common/resources/sv_resources.qc [new file with mode: 0644]
qcsrc/common/resources/sv_resources.qh [new file with mode: 0644]
qcsrc/common/vehicles/sv_vehicles.qc
qcsrc/common/weapons/all.qc
qcsrc/common/weapons/weapon.qh
qcsrc/common/weapons/weapon/arc.qh
qcsrc/common/weapons/weapon/blaster.qh
qcsrc/common/weapons/weapon/crylink.qh
qcsrc/common/weapons/weapon/devastator.qh
qcsrc/common/weapons/weapon/electro.qh
qcsrc/common/weapons/weapon/fireball.qh
qcsrc/common/weapons/weapon/hagar.qh
qcsrc/common/weapons/weapon/hlac.qh
qcsrc/common/weapons/weapon/hook.qh
qcsrc/common/weapons/weapon/machinegun.qh
qcsrc/common/weapons/weapon/minelayer.qh
qcsrc/common/weapons/weapon/mortar.qh
qcsrc/common/weapons/weapon/porto.qh
qcsrc/common/weapons/weapon/rifle.qh
qcsrc/common/weapons/weapon/seeker.qh
qcsrc/common/weapons/weapon/shockwave.qh
qcsrc/common/weapons/weapon/shotgun.qh
qcsrc/common/weapons/weapon/vaporizer.qh
qcsrc/common/weapons/weapon/vortex.qh
qcsrc/server/_mod.inc
qcsrc/server/_mod.qh
qcsrc/server/bot/default/havocbot/roles.qc
qcsrc/server/cheats.qc
qcsrc/server/client.qc
qcsrc/server/client.qh
qcsrc/server/compat/quake3.qc
qcsrc/server/damage.qc
qcsrc/server/items/items.qc
qcsrc/server/items/items.qh
qcsrc/server/mutators/events.qh
qcsrc/server/resources.qc [deleted file]
qcsrc/server/resources.qh [deleted file]
qcsrc/server/weapons/spawning.qc
qcsrc/server/weapons/throwing.qc
qcsrc/server/weapons/weaponsystem.qc

index 8f56739df0f66ea1458555cb83643b9df60e5bf1..8a25226ab2f29994faa8bd97dedcda663728d78f 100644 (file)
@@ -6,7 +6,6 @@
 #include <client/main.qc>
 #include <client/mapvoting.qc>
 #include <client/player_skeleton.qc>
-#include <client/resources.qc>
 #include <client/shownames.qc>
 #include <client/teamradar.qc>
 #include <client/view.qc>
index 5f82413c4633f25f2b2b14d528c2d52b46283e68..d17165d3d3ed80444a48d66c1347f2f8a96c8e6e 100644 (file)
@@ -6,7 +6,6 @@
 #include <client/main.qh>
 #include <client/mapvoting.qh>
 #include <client/player_skeleton.qh>
-#include <client/resources.qh>
 #include <client/shownames.qh>
 #include <client/teamradar.qh>
 #include <client/view.qh>
index b4a7b6040a92cd5f980253d8a4f51858c5df2662..0cc1f23956aa417f554c186183ff2f0438d6f53d 100644 (file)
@@ -4,6 +4,7 @@
 #include <client/items/items.qh>
 #include <client/view.qh>
 #include <common/mutators/mutator/nades/nades.qh>
+#include <common/resources/resources.qh>
 #include <common/wepent.qh>
 
 // Ammo (#1)
@@ -31,7 +32,7 @@ void DrawNadeProgressBar(vector myPos, vector mySize, float progress, vector col
                autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
 }
 
-void DrawAmmoItem(vector myPos, vector mySize, int ammoType, bool isCurrent, bool isInfinite)
+void DrawAmmoItem(vector myPos, vector mySize, Resource ammoType, bool isCurrent, bool isInfinite)
 {
        TC(bool, isCurrent); TC(bool, isInfinite);
        if(ammoType == RES_NONE)
@@ -216,11 +217,12 @@ void HUD_Ammo()
        }
        else
        {
-               int ammotype;
                row = column = 0;
-               for(i = 0; i < AMMO_COUNT; ++i)
+               // disabling new-style loop for now to restore original order of ammo types
+               //FOREACH(Resources, it.instanceOfAmmoResource && !it.m_hidden,
+               for(int j = 0; j < AMMO_COUNT; ++j)
                {
-                       ammotype = GetAmmoTypeFromNum(i);
+                       Resource ammotype = GetAmmoTypeFromNum(j);
                        DrawAmmoItem(
                                pos + vec2(column * (ammo_size.x + offset.x), row * (ammo_size.y + offset.y)),
                                ammo_size,
index f4bae2024cca45fc9b95fe7b14c8ae09fd127408..ef209633b76c08f61dec511b18d430cc5a72f44c 100644 (file)
@@ -2,10 +2,10 @@
 
 #include <client/draw.qh>
 #include <client/mapvoting.qh>
-#include <client/resources.qh>
 #include <client/teamradar.qh>
 #include <common/ent_cs.qh>
 #include <common/mutators/mutator/waypoints/all.qh>
+#include <common/resources/cl_resources.qh>
 
 // Radar (#6)
 
index 5ddc30d2365bfd3a51bda133adcee303c7b27bda..e4e339c44a53497c54e60485d00ce88b23468134 100644 (file)
@@ -4,13 +4,13 @@
 
 #include <client/draw.qh>
 #include <client/hud/panel/racetimer.qh>
-#include <client/resources.qh>
 #include <client/view.qh>
 #include <common/animdecide.qh>
 #include <common/ent_cs.qh>
 #include <common/mapinfo.qh>
 #include <common/physics/movetypes/movetypes.qh>
 #include <common/physics/player.qh>
+#include <common/resources/cl_resources.qh>
 #include <lib/csqcmodel/cl_player.qh>
 
 // StrafeHUD (#25)
index a79b64c4073cee7816c8f74f8adde3bcea9a4145..b51c5761d77819902787d194525dd2301093b751 100644 (file)
@@ -581,6 +581,7 @@ void HUD_Weapons()
 
                                if(a > 0)
                                {
+                                       // TODO: registry handles
                                        switch (it.ammo_type)
                                        {
                                                case RES_SHELLS:  ammo_full = autocvar_hud_panel_weapons_ammo_full_shells;  break;
diff --git a/qcsrc/client/resources.qc b/qcsrc/client/resources.qc
deleted file mode 100644 (file)
index 5408872..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-#include "resources.qh"
-
-#include <common/items/item/ammo.qh>
-
-/// \file
-/// \brief Source file that contains implementation of the resource system.
-/// \copyright GNU GPLv2 or any later version.
-
-float GetResource(entity e, int res_type)
-{
-       return e.(GetResourceField(res_type));
-}
-
-bool SetResourceExplicit(entity e, int res_type, float amount)
-{
-       .float res_field = GetResourceField(res_type);
-       if (e.(res_field) != amount)
-       {
-               e.(res_field) = amount;
-               return true;
-       }
-       return false;
-}
-
-void SetResource(entity e, int res_type, float amount)
-{
-       SetResourceExplicit(e, res_type, amount);
-}
-
-void TakeResource(entity receiver, int res_type, float amount)
-{
-       if (amount == 0)
-       {
-               return;
-       }
-       SetResource(receiver, res_type, GetResource(receiver, res_type) - amount);
-}
-
-void TakeResourceWithLimit(entity receiver, int res_type, float amount, float limit)
-{
-       if (amount == 0)
-       {
-               return;
-       }
-       float current_amount = GetResource(receiver, res_type);
-       if (current_amount - amount < limit)
-       {
-               amount = limit + current_amount;
-       }
-       TakeResource(receiver, res_type, amount);
-}
-
-int GetResourceType(.float res_field)
-{
-       switch (res_field)
-       {
-               case health: { return RES_HEALTH; }
-               case armorvalue: { return RES_ARMOR; }
-               case ammo_shells: { return RES_SHELLS; }
-               case ammo_nails: { return RES_BULLETS; }
-               case ammo_rockets: { return RES_ROCKETS; }
-               case ammo_cells: { return RES_CELLS; }
-               case ammo_plasma: { return RES_PLASMA; }
-               case ammo_fuel: { return RES_FUEL; }
-       }
-       error("GetResourceType: Invalid field.");
-       return 0;
-}
-
-.float GetResourceField(int res_type)
-{
-       switch (res_type)
-       {
-               case RES_HEALTH: { return health; }
-               case RES_ARMOR: { return armorvalue; }
-               case RES_SHELLS: { return ammo_shells; }
-               case RES_BULLETS: { return ammo_nails; }
-               case RES_ROCKETS: { return ammo_rockets; }
-               case RES_CELLS: { return ammo_cells; }
-               case RES_PLASMA: { return ammo_plasma; }
-               case RES_FUEL: { return ammo_fuel; }
-       }
-       error("GetResourceField: Invalid resource type.");
-       return health;
-}
diff --git a/qcsrc/client/resources.qh b/qcsrc/client/resources.qh
deleted file mode 100644 (file)
index 4b0eaa8..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-#pragma once
-
-/// \file
-/// \brief Header file that describes the resource system.
-/// \copyright GNU GPLv2 or any later version.
-
-#include <common/resources.qh>
-
-// ============================ Public API ====================================
-
-/// \brief Returns the current amount of resource the given entity has.
-/// \param[in] e Entity to check.
-/// \param[in] res_type Type of the resource (a RES_* constant).
-/// \return Current amount of resource the given entity has.
-float GetResource(entity e, int res_type);
-
-/// \brief Sets the resource amount of an entity without calling any hooks.
-/// \param[in,out] e Entity to adjust.
-/// \param[in] res_type Type of the resource (a RES_* constant).
-/// \param[in] amount Amount of resource to set.
-/// \return Boolean for whether the ammo amount was changed
-bool SetResourceExplicit(entity e, int res_type, float amount);
-
-/// \brief Sets the current amount of resource the given entity will have.
-/// \param[in,out] e Entity to adjust.
-/// \param[in] res_type Type of the resource (a RES_* constant).
-/// \param[in] amount Amount of resource to set.
-/// \return No return.
-void SetResource(entity e, int res_type, float amount);
-
-/// \brief Takes an entity some resource.
-/// \param[in,out] receiver Entity to take resource from.
-/// \param[in] res_type Type of the resource (a RES_* constant).
-/// \param[in] amount Amount of resource to take.
-/// \return No return.
-void TakeResource(entity receiver, int res_type, float amount);
-
-/// \brief Takes an entity some resource but not less than a limit.
-/// \param[in,out] receiver Entity to take resource from.
-/// \param[in] res_type Type of the resource (a RES_* constant).
-/// \param[in] amount Amount of resource to take.
-/// \param[in] limit Limit of resources to take.
-/// \return No return.
-void TakeResourceWithLimit(entity receiver, int res_type, float amount, float limit);
-
-// ===================== Legacy and/or internal API ===========================
-
-/// \brief Converts an entity field to resource type.
-/// \param[in] res_field Entity field to convert.
-/// \return Resource type (a RES_* constant).
-int GetResourceType(.float res_field);
-
-/// \brief Converts resource type (a RES_* constant) to entity field.
-/// \param[in] res_type Type of the resource.
-/// \return Entity field for that resource.
-.float GetResourceField(int res_type);
-
-/// \brief Legacy fields for the resources. To be removed.
-.float health;
-.float armorvalue;
index 27157a5a165fa1c9dc904cf2e0e36e4aec1c9893..3f0688d61d0e4a2c577ae2ae10660197ccd18380 100644 (file)
@@ -2,11 +2,11 @@
 
 #include <client/draw.qh>
 #include <client/hud/_mod.qh>
-#include <client/resources.qh>
 #include <client/view.qh>
 #include <common/constants.qh>
 #include <common/ent_cs.qh>
 #include <common/net_linked.qh>
+#include <common/resources/cl_resources.qh>
 #include <common/teams.qh>
 #include <lib/csqcmodel/cl_model.qh>
 
index fa80064c9aeeaf86ca9227c377e8b0be0980b82a..0a2cca157e65e54bd9bd3d9fb45b64a2dfdc4eba 100644 (file)
@@ -49,3 +49,5 @@ noref float autocvar_net_connecttimeout = 30;
 
 #include "mutators/_mod.inc"
     #include "gamemodes/_mod.inc"
+
+#include "resources/_mod.inc"
index 4a45c1edb0123b87fa606dbf2d1d916a62df9717..84d6789c71de598db6e228bab699f9dc02093d6a 100644 (file)
@@ -7,6 +7,7 @@
 #include <common/mapinfo.qc>
 #include <common/net_notice.qc>
 #include <common/playerstats.qc>
+#include <common/resources.qc>
 #include <common/replicate.qc>
 #include <common/state.qc>
 #include <common/util.qc>
index e63a7f04f63e7e86f69f04dd3befb13af5868a0a..ca0e28f04680e24b4585ebf41f88b0b9bed2d0b5 100644 (file)
@@ -2,8 +2,8 @@
 
 #ifdef CSQC
 #include <client/draw.qh>
-#include <client/resources.qh>
 #include <client/view.qh>
+#include <common/resources/cl_resources.qh>
 #endif
 
 
index fb2f9d5d3e3576225538b04df23d264738816d1d..5366371458fe52fadb86e3c2d7fc3dd8b2ca44db 100644 (file)
@@ -2,12 +2,12 @@
 
 #if defined(CSQC)
        #include <common/gamemodes/_mod.qh>
-       #include <common/resources.qh>
+       #include <common/resources/resources.qh>
 #elif defined(MENUQC)
 #elif defined(SVQC)
        #include <common/gamemodes/_mod.qh>
-       #include <common/resources.qh>
-       #include <server/resources.qh>
+       #include <common/resources/resources.qh>
+       #include <common/resources/sv_resources.qh>
 #endif
 
 REGISTRY(EntCSProps, BITS(16) - 1)
index 58fd90c897f15213ce6b686e9a5b402df00c19d6..4c50abb464e3737b0284849e98c69671580e5aa2 100644 (file)
@@ -1,7 +1,7 @@
 #include "sv_freezetag.qh"
 
+#include <common/resources/sv_resources.qh>
 #include <server/elimination.qh>
-#include <server/resources.qh>
 
 float autocvar_g_freezetag_frozen_maxtime;
 float autocvar_g_freezetag_revive_clearspeed;
index 02857d8ae23cd9f0f7c1cf04a372c2f20f516bf2..bf22a7e81d8b0dd6ca93fcf074c05e5c6ae59e63 100644 (file)
@@ -2,25 +2,10 @@
 
 #include "pickup.qh"
 #include <common/items/all.qh>
+#include <common/resources/resources.qh>
 #ifdef SVQC
-    #include <common/stats.qh>
+    #include <common/resources/sv_resources.qh>
     #include <server/items/items.qh>
-    #include <server/resources.qh>
-#endif
-
-#if 1
-.int ammo_none;
-.int ammo_shells;
-.int ammo_nails;
-.int ammo_rockets;
-.int ammo_cells;
-#ifdef SVQC
-const .int ammo_plasma = _STAT(PLASMA);
-const .int ammo_fuel = _STAT(FUEL);
-#else
-.int ammo_plasma;
-.int ammo_fuel;
-#endif
 #endif
 
 #ifdef GAMEQC
index e23d533edffde69b72bf4ec98a8267c23770e558..c53c76eb777e1773700264ca807ae9b6e4a55f3d 100644 (file)
@@ -135,6 +135,7 @@ void NIX_GiveCurrentWeapon(entity this)
        // get weapon info
        entity wpn = REGISTRY_GET(Weapons, nix_weapon);
 
+       // TODO: registry handles
        if(nix_nextchange != this.nix_lastchange_id) // this shall only be called once per round!
        {
                SetResource(this, RES_SHELLS, 0);
index 8a00b4d77adfb92e40d3aafb6cf3c36827206243..8f597e01b2924b182338d8705522a1a9dc116e19 100644 (file)
@@ -4,7 +4,7 @@
 
 CLASS(OverkillHeavyMachineGun, Weapon)
 /* spawnfunc */ ATTRIB(OverkillHeavyMachineGun, m_canonical_spawnfunc, string, "weapon_okhmg");
-/* ammotype  */ ATTRIB(OverkillHeavyMachineGun, ammo_type, int, RES_BULLETS);
+/* ammotype  */ ATTRIB(OverkillHeavyMachineGun, ammo_type, Resource, RES_BULLETS);
 /* impulse   */ ATTRIB(OverkillHeavyMachineGun, impulse, int, 3);
 /* flags     */ ATTRIB(OverkillHeavyMachineGun, spawnflags, int, WEP_FLAG_MUTATORBLOCKED | WEP_FLAG_HIDDEN | WEP_FLAG_RELOADABLE | WEP_TYPE_HITSCAN | WEP_FLAG_SUPERWEAPON | WEP_FLAG_PENETRATEWALLS);
 /* rating    */ ATTRIB(OverkillHeavyMachineGun, bot_pickupbasevalue, float, 10000);
index 10f3b9c09fb66192f604e3beacba25ca279601ba..7cf072b33a5c5bf41e92baa3f3b41c2e982580b5 100644 (file)
@@ -2,7 +2,7 @@
 
 CLASS(OverkillMachineGun, Weapon)
 /* spawnfunc */ ATTRIB(OverkillMachineGun, m_canonical_spawnfunc, string, "weapon_okmachinegun");
-/* ammotype  */ ATTRIB(OverkillMachineGun, ammo_type, int, RES_BULLETS);
+/* ammotype  */ ATTRIB(OverkillMachineGun, ammo_type, Resource, RES_BULLETS);
 /* impulse   */ ATTRIB(OverkillMachineGun, impulse, int, 3);
 /* flags        */ ATTRIB(OverkillMachineGun, spawnflags, int, WEP_FLAG_HIDDEN | WEP_FLAG_RELOADABLE | WEP_TYPE_HITSCAN | WEP_FLAG_PENETRATEWALLS | WEP_FLAG_MUTATORBLOCKED);
 /* rating      */ ATTRIB(OverkillMachineGun, bot_pickupbasevalue, float, 7000);
index 1ffaf78b8ceeeea57116569d86cb70a1761769a6..21bbfaa2f9f069d46554cd196b574b1eb884651a 100644 (file)
@@ -2,7 +2,7 @@
 
 CLASS(OverkillNex, Weapon)
 /* spawnfunc */ ATTRIB(OverkillNex, m_canonical_spawnfunc, string, "weapon_oknex");
-/* ammotype  */ ATTRIB(OverkillNex, ammo_type, int, RES_CELLS);
+/* ammotype  */ ATTRIB(OverkillNex, ammo_type, Resource, RES_CELLS);
 /* impulse   */ ATTRIB(OverkillNex, impulse, int, 7);
 /* flags     */ ATTRIB(OverkillNex, spawnflags, int, WEP_FLAG_HIDDEN | WEP_FLAG_RELOADABLE | WEP_TYPE_HITSCAN | WEP_FLAG_MUTATORBLOCKED);
 /* rating    */ ATTRIB(OverkillNex, bot_pickupbasevalue, float, 8000);
index 6b6763ce702fc5523dde5891bdeb89b93a331af0..60c0c9a2df1d55790da28557a884fe9015c3e85c 100644 (file)
@@ -4,7 +4,7 @@
 
 CLASS(OverkillRocketPropelledChainsaw, Weapon)
 /* spawnfunc */ ATTRIB(OverkillRocketPropelledChainsaw, m_canonical_spawnfunc, string, "weapon_okrpc");
-/* ammotype  */ ATTRIB(OverkillRocketPropelledChainsaw, ammo_type, int, RES_ROCKETS);
+/* ammotype  */ ATTRIB(OverkillRocketPropelledChainsaw, ammo_type, Resource, RES_ROCKETS);
 /* impulse   */ ATTRIB(OverkillRocketPropelledChainsaw, impulse, int, 9);
 /* flags     */ ATTRIB(OverkillRocketPropelledChainsaw, spawnflags, int, WEP_FLAG_MUTATORBLOCKED | WEP_FLAG_HIDDEN | WEP_FLAG_CANCLIMB | WEP_FLAG_RELOADABLE | WEP_TYPE_SPLASH | WEP_FLAG_SUPERWEAPON);
 /* rating    */ ATTRIB(OverkillRocketPropelledChainsaw, bot_pickupbasevalue, float, 10000);
index 2c75681d970cca83305a0dea2e6363b6c1e04065..e70fc43269f1eb329f2c9d6f9458ac29da5dd010 100644 (file)
@@ -2,7 +2,7 @@
 
 CLASS(OverkillShotgun, Weapon)
 /* spawnfunc */ ATTRIB(OverkillShotgun, m_canonical_spawnfunc, string, "weapon_okshotgun");
-/* ammotype  */ ATTRIB(OverkillShotgun, ammo_type, int, RES_SHELLS);
+/* ammotype  */ ATTRIB(OverkillShotgun, ammo_type, Resource, RES_SHELLS);
 /* impulse   */ ATTRIB(OverkillShotgun, impulse, int, 2);
 /* flags     */ ATTRIB(OverkillShotgun, spawnflags, int, WEP_FLAG_HIDDEN | WEP_FLAG_RELOADABLE | WEP_TYPE_HITSCAN | WEP_FLAG_MUTATORBLOCKED);
 /* rating    */ ATTRIB(OverkillShotgun, bot_pickupbasevalue, float, 6000);
index babadf8c873272fb7a7e847e31cf2cf41a438fc1..17d2047dcb767523f932ed258da2976ededd1946 100644 (file)
@@ -634,6 +634,7 @@ string notif_arg_item_wepammo(float f1, float f2)
 {
        string ammoitems = "";
        Weapon wep = REGISTRY_GET(Weapons, f1);
+       // TODO: registry handles
        switch (wep.ammo_type)
        {
                case RES_SHELLS:  ammoitems = ITEM_Shells.m_name;      break;
diff --git a/qcsrc/common/resources.qh b/qcsrc/common/resources.qh
deleted file mode 100644 (file)
index 81f4eb5..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-#pragma once
-
-/// \file
-/// \brief Header file that describes resource types.
-/// \author Lyberta
-/// \copyright GNU GPLv2 or any later version.
-
-/// \brief Unconditional maximum amount of resources the entity can have.
-const int RES_AMOUNT_HARD_LIMIT = 999;
-const int RES_LIMIT_NONE = -1;
-
-/// \brief Describes the available resource types.
-enum
-{
-       RES_NONE, ///< Indicates the lack of resource. Use with caution.
-       RES_HEALTH, ///< Health.
-       RES_ARMOR, ///< Armor.
-       RES_SHELLS, ///< Shells (used by shotgun).
-       RES_BULLETS, ///< Bullets (used by machinegun, rifle, HMG)
-       RES_ROCKETS, ///< Rockets (used by mortar, hagar, devastator, etc).
-       RES_CELLS, ///< Cells (used by electro, crylink, vortex, etc)
-       RES_PLASMA, ///< Plasma (unused).
-       RES_FUEL ///< Fuel (used by jetpack).
-};
diff --git a/qcsrc/common/resources/_mod.inc b/qcsrc/common/resources/_mod.inc
new file mode 100644 (file)
index 0000000..27e6823
--- /dev/null
@@ -0,0 +1,8 @@
+// generated file; do not modify
+#include <common/resources/resources.qc>
+#ifdef CSQC
+    #include <common/resources/cl_resources.qc>
+#endif
+#ifdef SVQC
+    #include <common/resources/sv_resources.qc>
+#endif
diff --git a/qcsrc/common/resources/_mod.qh b/qcsrc/common/resources/_mod.qh
new file mode 100644 (file)
index 0000000..d1ef95f
--- /dev/null
@@ -0,0 +1,8 @@
+// generated file; do not modify
+#include <common/resources/resources.qh>
+#ifdef CSQC
+    #include <common/resources/cl_resources.qh>
+#endif
+#ifdef SVQC
+    #include <common/resources/sv_resources.qh>
+#endif
diff --git a/qcsrc/common/resources/all.inc b/qcsrc/common/resources/all.inc
new file mode 100644 (file)
index 0000000..51e0bcc
--- /dev/null
@@ -0,0 +1,61 @@
+REGISTER_RESOURCE(HEALTH, NEW(Resource)) {
+       this.netname = "health";
+#ifdef GAMEQC
+       this.m_field = health;
+#endif
+}
+REGISTER_RESOURCE(ARMOR, NEW(Resource)) {
+       this.netname = "armor";
+#ifdef GAMEQC
+       this.m_field = armorvalue;
+#endif
+}
+
+CLASS(AmmoResource, Resource)
+#ifdef CSQC
+       ATTRIB(AmmoResource, m_hidden, bool, false);
+#endif
+ENDCLASS(AmmoResource)
+
+REGISTER_RESOURCE(SHELLS, NEW(AmmoResource)) {
+       this.netname = "shells";
+#ifdef GAMEQC
+       this.m_field = ammo_shells;
+#endif
+}
+REGISTER_RESOURCE(BULLETS, NEW(AmmoResource)) {
+       this.netname = "bullets";
+#ifdef GAMEQC
+       this.m_field = ammo_nails;
+#endif
+}
+REGISTER_RESOURCE(ROCKETS, NEW(AmmoResource)) {
+       this.netname = "rockets";
+#ifdef GAMEQC
+       this.m_field = ammo_rockets;
+#endif
+}
+REGISTER_RESOURCE(CELLS, NEW(AmmoResource)) {
+       this.netname = "cells";
+#ifdef GAMEQC
+       this.m_field = ammo_cells;
+#endif
+}
+REGISTER_RESOURCE(PLASMA, NEW(AmmoResource)) {
+       this.netname = "plasma";
+#ifdef GAMEQC
+       this.m_field = ammo_plasma;
+#endif
+#ifdef CSQC
+       this.m_hidden = true; // WIP ammo type
+#endif
+}
+REGISTER_RESOURCE(FUEL, NEW(AmmoResource)) {
+       this.netname = "fuel";
+#ifdef GAMEQC
+       this.m_field = ammo_fuel;
+#endif
+#ifdef CSQC
+       this.m_hidden = true; // displayed in a separate panel
+#endif
+}
diff --git a/qcsrc/common/resources/cl_resources.qc b/qcsrc/common/resources/cl_resources.qc
new file mode 100644 (file)
index 0000000..fc25900
--- /dev/null
@@ -0,0 +1,52 @@
+#include "cl_resources.qh"
+
+#include <common/items/item/ammo.qh>
+#include <common/resources/resources.qh>
+
+/// \file
+/// \brief Source file that contains implementation of the resource system.
+/// \copyright GNU GPLv2 or any later version.
+
+float GetResource(entity e, Resource res_type)
+{
+       return e.(GetResourceField(res_type));
+}
+
+bool SetResourceExplicit(entity e, Resource res_type, float amount)
+{
+       .float res_field = GetResourceField(res_type);
+       if (e.(res_field) != amount)
+       {
+               e.(res_field) = amount;
+               return true;
+       }
+       return false;
+}
+
+void SetResource(entity e, Resource res_type, float amount)
+{
+       SetResourceExplicit(e, res_type, amount);
+}
+
+void TakeResource(entity receiver, Resource res_type, float amount)
+{
+       if (amount == 0)
+       {
+               return;
+       }
+       SetResource(receiver, res_type, GetResource(receiver, res_type) - amount);
+}
+
+void TakeResourceWithLimit(entity receiver, Resource res_type, float amount, float limit)
+{
+       if (amount == 0)
+       {
+               return;
+       }
+       float current_amount = GetResource(receiver, res_type);
+       if (current_amount - amount < limit)
+       {
+               amount = limit + current_amount;
+       }
+       TakeResource(receiver, res_type, amount);
+}
diff --git a/qcsrc/common/resources/cl_resources.qh b/qcsrc/common/resources/cl_resources.qh
new file mode 100644 (file)
index 0000000..f03c1dc
--- /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/resources.qh>
+
+// ============================ Public API ====================================
+
+/// \brief Returns the current amount of resource the given entity has.
+/// \param[in] e Entity to check.
+/// \param[in] res_type Type of the resource (a RES_* constant).
+/// \return Current amount of resource the given entity has.
+float GetResource(entity e, Resource res_type);
+
+/// \brief Sets the resource amount of an entity without calling any hooks.
+/// \param[in,out] e Entity to adjust.
+/// \param[in] res_type Type of the resource (a RES_* constant).
+/// \param[in] amount Amount of resource to set.
+/// \return Boolean for whether the ammo amount was changed
+bool SetResourceExplicit(entity e, Resource res_type, float amount);
+
+/// \brief Sets the current amount of resource the given entity will have.
+/// \param[in,out] e Entity to adjust.
+/// \param[in] res_type Type of the resource (a RES_* constant).
+/// \param[in] amount Amount of resource to set.
+/// \return No return.
+void SetResource(entity e, Resource res_type, float amount);
+
+/// \brief Takes an entity some resource.
+/// \param[in,out] receiver Entity to take resource from.
+/// \param[in] res_type Type of the resource (a RES_* constant).
+/// \param[in] amount Amount of resource to take.
+/// \return No return.
+void TakeResource(entity receiver, Resource res_type, float amount);
+
+/// \brief Takes an entity some resource but not less than a limit.
+/// \param[in,out] receiver Entity to take resource from.
+/// \param[in] res_type Type of the resource (a RES_* constant).
+/// \param[in] amount Amount of resource to take.
+/// \param[in] limit Limit of resources to take.
+/// \return No return.
+void TakeResourceWithLimit(entity receiver, Resource res_type, float amount, float limit);
diff --git a/qcsrc/common/resources/resources.qc b/qcsrc/common/resources/resources.qc
new file mode 100644 (file)
index 0000000..84bb25a
--- /dev/null
@@ -0,0 +1,15 @@
+#include "resources.qh"
+
+#ifdef GAMEQC
+Resource GetResourceType(.float res_field)
+{
+       FOREACH(Resources, it.m_field == res_field, return it);
+       error("GetResourceType: Invalid field.");
+       return RES_NONE;
+}
+
+.float GetResourceField(Resource res_type)
+{
+       return res_type.m_field;
+}
+#endif
diff --git a/qcsrc/common/resources/resources.qh b/qcsrc/common/resources/resources.qh
new file mode 100644 (file)
index 0000000..0ecd29d
--- /dev/null
@@ -0,0 +1,65 @@
+#pragma once
+
+#ifdef SVQC
+       #include <common/stats.qh>
+#endif
+
+#ifdef CSQC
+/// \brief Legacy fields for the resources. To be removed.
+.float health;
+.float armorvalue;
+#endif
+
+#if 1
+.int ammo_none;
+.int ammo_shells;
+.int ammo_nails;
+.int ammo_rockets;
+.int ammo_cells;
+#ifdef SVQC
+const .int ammo_plasma = _STAT(PLASMA);
+const .int ammo_fuel = _STAT(FUEL);
+#else
+.int ammo_plasma;
+.int ammo_fuel;
+#endif
+#endif
+
+CLASS(Resource, Object)
+       ATTRIB(Resource, netname, string, "");
+#ifdef GAMEQC
+       ATTRIB(Resource, m_field, .float, health);
+#endif
+ENDCLASS(Resource)
+
+#define REGISTER_RESOURCE(id, inst) REGISTER(Resources, RES, id, m_id, inst)
+REGISTRY(Resources, BITS(4));
+REGISTER_REGISTRY(Resources)
+REGISTRY_SORT(Resources);
+REGISTRY_CHECK(Resources);
+
+REGISTRY_DEFINE_GET(Resources, NULL)
+STATIC_INIT(Resources_renumber) { FOREACH(Resources, true, it.m_id = i); }
+
+/// \brief Unconditional maximum amount of resources the entity can have.
+const int RES_AMOUNT_HARD_LIMIT = 999;
+const int RES_LIMIT_NONE = -1;
+
+/// \brief Describes the available resource types.
+REGISTER_RESOURCE(NONE, NEW(Resource)); ///< Indicates the lack of resource. Use with caution.
+
+#include "all.inc"
+
+#ifdef GAMEQC
+// ===================== Legacy and/or internal API ===========================
+
+/// \brief Converts an entity field to resource type.
+/// \param[in] res_field Entity field to convert.
+/// \return Resource type (a RES_* constant).
+Resource GetResourceType(.float res_field);
+
+/// \brief Converts resource type (a RES_* constant) to entity field.
+/// \param[in] res_type Type of the resource.
+/// \return Entity field for that resource.
+.float GetResourceField(Resource res_type);
+#endif
diff --git a/qcsrc/common/resources/sv_resources.qc b/qcsrc/common/resources/sv_resources.qc
new file mode 100644 (file)
index 0000000..9984e91
--- /dev/null
@@ -0,0 +1,234 @@
+#include "sv_resources.qh"
+
+/// \file
+/// \brief Source file that contains implementation of the resource system.
+/// \author Lyberta
+/// \copyright GNU GPLv2 or any later version.
+
+#include <common/resources/resources.qh>
+#include <server/mutators/_mod.qh>
+#include <server/world.qh>
+
+float GetResourceLimit(entity e, Resource res_type)
+{
+       if(!IS_PLAYER(e))
+               return RES_LIMIT_NONE; // no limits on non-players
+
+       float limit;
+       // TODO: registry handles
+       switch (res_type)
+       {
+               case RES_HEALTH:
+               {
+                       limit = autocvar_g_balance_health_limit;
+                       break;
+               }
+               case RES_ARMOR:
+               {
+                       limit = autocvar_g_balance_armor_limit;
+                       break;
+               }
+               case RES_SHELLS:
+               {
+                       limit = g_pickup_shells_max;
+                       break;
+               }
+               case RES_BULLETS:
+               {
+                       limit = g_pickup_nails_max;
+                       break;
+               }
+               case RES_ROCKETS:
+               {
+                       limit = g_pickup_rockets_max;
+                       break;
+               }
+               case RES_CELLS:
+               {
+                       limit = g_pickup_cells_max;
+                       break;
+               }
+               case RES_PLASMA:
+               {
+                       limit = g_pickup_plasma_max;
+                       break;
+               }
+               case RES_FUEL:
+               {
+                       limit = autocvar_g_balance_fuel_limit;
+                       break;
+               }
+               default:
+               {
+                       error("GetResourceLimit: Invalid resource type.");
+                       return 0;
+               }
+       }
+       MUTATOR_CALLHOOK(GetResourceLimit, e, res_type, limit);
+       limit = M_ARGV(2, float);
+       if (limit > RES_AMOUNT_HARD_LIMIT)
+       {
+               limit = RES_AMOUNT_HARD_LIMIT;
+       }
+       return limit;
+}
+
+float GetResource(entity e, Resource res_type)
+{
+       return e.(GetResourceField(res_type));
+}
+
+bool SetResourceExplicit(entity e, Resource res_type, float amount)
+{
+       .float res_field = GetResourceField(res_type);
+       if (e.(res_field) != amount)
+       {
+               e.(res_field) = amount;
+               return true;
+       }
+       return false;
+}
+
+void SetResource(entity e, Resource res_type, float amount)
+{
+       bool forbid = MUTATOR_CALLHOOK(SetResource, e, res_type, amount);
+       if (forbid)
+       {
+               return;
+       }
+       res_type = M_ARGV(1, entity);
+       amount = M_ARGV(2, float);
+       float max_amount = GetResourceLimit(e, res_type); // TODO: should allow overriding these limits if cheats are enabled!
+       float amount_wasted = 0;
+       if (amount > max_amount && max_amount != RES_LIMIT_NONE)
+       {
+               amount_wasted = amount - max_amount;
+               amount = max_amount;
+       }
+       bool changed = SetResourceExplicit(e, res_type, amount);
+       if (changed)
+       {
+               MUTATOR_CALLHOOK(ResourceAmountChanged, e, res_type, amount);
+       }
+       if (amount_wasted == 0)
+       {
+               return;
+       }
+       MUTATOR_CALLHOOK(ResourceWasted, e, res_type, amount_wasted);
+}
+
+void GiveResource(entity receiver, Resource res_type, float amount)
+{
+       if (amount <= 0)
+       {
+               return;
+       }
+       bool forbid = MUTATOR_CALLHOOK(GiveResource, receiver, res_type, amount);
+       if (forbid)
+       {
+               return;
+       }
+       res_type = M_ARGV(1, entity);
+       amount = M_ARGV(2, float);
+       if (amount <= 0)
+       {
+               return;
+       }
+       SetResource(receiver, res_type, GetResource(receiver, res_type) + amount);
+       // TODO: registry handles
+       switch (res_type)
+       {
+               case RES_HEALTH:
+               {
+                       receiver.pauserothealth_finished =
+                               max(receiver.pauserothealth_finished, time +
+                               autocvar_g_balance_pause_health_rot);
+                       return;
+               }
+               case RES_ARMOR:
+               {
+                       receiver.pauserotarmor_finished =
+                               max(receiver.pauserotarmor_finished, time +
+                               autocvar_g_balance_pause_armor_rot);
+                       return;
+               }
+               case RES_FUEL:
+               {
+                       receiver.pauserotfuel_finished = max(receiver.pauserotfuel_finished,
+                               time + autocvar_g_balance_pause_fuel_rot);
+                       return;
+               }
+       }
+}
+
+void GiveResourceWithLimit(entity receiver, Resource res_type, float amount, float limit)
+{
+       if (amount <= 0)
+       {
+               return;
+       }
+       bool forbid = MUTATOR_CALLHOOK(GiveResourceWithLimit, receiver, res_type, amount, limit);
+       if (forbid)
+       {
+               return;
+       }
+       res_type = M_ARGV(1, entity);
+       amount = M_ARGV(2, float);
+       limit = M_ARGV(3, float);
+       if (amount <= 0)
+       {
+               return;
+       }
+       float current_amount = GetResource(receiver, res_type);
+       if (current_amount + amount > limit && limit != RES_LIMIT_NONE)
+       {
+               amount = limit - current_amount;
+       }
+       GiveResource(receiver, res_type, amount);
+}
+
+void TakeResource(entity receiver, Resource res_type, float amount)
+{
+       if (amount <= 0)
+       {
+               return;
+       }
+       bool forbid = MUTATOR_CALLHOOK(TakeResource, receiver, res_type, amount);
+       if (forbid)
+       {
+               return;
+       }
+       res_type = M_ARGV(1, entity);
+       amount = M_ARGV(2, float);
+       if (amount <= 0)
+       {
+               return;
+       }
+       SetResource(receiver, res_type, GetResource(receiver, res_type) - amount);
+}
+
+void TakeResourceWithLimit(entity receiver, Resource res_type, float amount, float limit)
+{
+       if (amount <= 0)
+       {
+               return;
+       }
+       bool forbid = MUTATOR_CALLHOOK(TakeResourceWithLimit, receiver, res_type, amount, limit);
+       if (forbid)
+       {
+               return;
+       }
+       res_type = M_ARGV(1, entity);
+       amount = M_ARGV(2, float);
+       limit = M_ARGV(3, float);
+       if (amount <= 0)
+       {
+               return;
+       }
+       float current_amount = GetResource(receiver, res_type);
+       if (current_amount - amount < -limit)
+       {
+               amount = -limit + current_amount;
+       }
+       TakeResource(receiver, res_type, amount);
+}
diff --git a/qcsrc/common/resources/sv_resources.qh b/qcsrc/common/resources/sv_resources.qh
new file mode 100644 (file)
index 0000000..7385014
--- /dev/null
@@ -0,0 +1,95 @@
+#pragma once
+
+/// \file
+/// \brief Header file that describes the resource system.
+/// \author Lyberta
+/// \copyright GNU GPLv2 or any later version.
+
+#include <common/resources/resources.qh>
+
+// TODO: split resources into their own files, registry based
+float autocvar_g_balance_health_limit;
+int autocvar_g_balance_armor_limit;
+float autocvar_g_balance_fuel_limit;
+float autocvar_g_balance_armor_regen;
+float autocvar_g_balance_armor_regenlinear;
+int autocvar_g_balance_armor_regenstable;
+float autocvar_g_balance_armor_rot;
+float autocvar_g_balance_armor_rotlinear;
+int autocvar_g_balance_armor_rotstable;
+float autocvar_g_balance_fuel_regen;
+float autocvar_g_balance_fuel_regenlinear;
+int autocvar_g_balance_fuel_regenstable;
+float autocvar_g_balance_fuel_rot;
+float autocvar_g_balance_fuel_rotlinear;
+int autocvar_g_balance_fuel_rotstable;
+float autocvar_g_balance_health_regen;
+float autocvar_g_balance_health_regenlinear;
+float autocvar_g_balance_health_regenstable;
+float autocvar_g_balance_health_rot;
+float autocvar_g_balance_health_rotlinear;
+float autocvar_g_balance_health_rotstable;
+float autocvar_g_balance_pause_armor_rot;
+float autocvar_g_balance_pause_fuel_regen;
+float autocvar_g_balance_pause_fuel_rot;
+float autocvar_g_balance_pause_health_regen;
+float autocvar_g_balance_pause_health_rot;
+
+// ============================ Public API ====================================
+
+/// \brief Returns the maximum amount of the given resource.
+/// \param[in] e Entity to check.
+/// \param[in] res_type Type of the resource (a RES_* constant).
+/// \return Maximum amount of the given resource.
+float GetResourceLimit(entity e, Resource res_type);
+
+/// \brief Returns the current amount of resource the given entity has.
+/// \param[in] e Entity to check.
+/// \param[in] res_type Type of the resource (a RES_* constant).
+/// \return Current amount of resource the given entity has.
+float GetResource(entity e, Resource res_type);
+
+/// \brief Sets the resource amount of an entity without calling any hooks.
+/// \param[in,out] e Entity to adjust.
+/// \param[in] res_type Type of the resource (a RES_* constant).
+/// \param[in] amount Amount of resource to set.
+/// \return Boolean for whether the ammo amount was changed
+bool SetResourceExplicit(entity e, Resource res_type, float amount);
+
+/// \brief Sets the current amount of resource the given entity will have
+/// but limited to the max amount allowed for the resource type.
+/// \param[in,out] e Entity to adjust.
+/// \param[in] res_type Type of the resource (a RES_* constant).
+/// \param[in] amount Amount of resource to set.
+/// \return No return.
+void SetResource(entity e, Resource res_type, float amount);
+
+/// \brief Gives an entity some resource.
+/// \param[in,out] receiver Entity to give resource to.
+/// \param[in] res_type Type of the resource (a RES_* constant).
+/// \param[in] amount Amount of resource to give.
+/// \return No return.
+void GiveResource(entity receiver, Resource res_type, float amount);
+
+/// \brief Gives an entity some resource but not more than a limit.
+/// \param[in,out] receiver Entity to give resource to.
+/// \param[in] res_type Type of the resource (a RES_* constant).
+/// \param[in] amount Amount of resource to give.
+/// \param[in] limit Limit of resources to give.
+/// \return No return.
+void GiveResourceWithLimit(entity receiver, Resource res_type, float amount, float limit);
+
+/// \brief Takes an entity some resource.
+/// \param[in,out] receiver Entity to take resource from.
+/// \param[in] res_type Type of the resource (a RES_* constant).
+/// \param[in] amount Amount of resource to take.
+/// \return No return.
+void TakeResource(entity receiver, Resource res_type, float amount);
+
+/// \brief Takes an entity some resource but not less than a limit.
+/// \param[in,out] receiver Entity to take resource from.
+/// \param[in] res_type Type of the resource (a RES_* constant).
+/// \param[in] amount Amount of resource to take.
+/// \param[in] limit Limit of resources to take.
+/// \return No return.
+void TakeResourceWithLimit(entity receiver, Resource res_type, float amount, float limit);
index bbecb83da6efe8b9cb65641dc66e6f38977e3cab..302b39a0d16d66c12b6c328d992a710cd2d0c373 100644 (file)
@@ -569,7 +569,7 @@ void vehicles_regen(entity this, float timer, .float regen_field, float field_ma
        }
 }
 
-void vehicles_regen_resource(entity this, float timer, .float regen_field, float field_max, float rpause, float regen, float delta_time, float _healthscale, int resource)
+void vehicles_regen_resource(entity this, float timer, .float regen_field, float field_max, float rpause, float regen, float delta_time, float _healthscale, Resource resource)
 {
        float resource_amount = GetResource(this, resource);
 
index 7ef3cc1e8d7a5ee18ff37591f899d635d8e0ee6d..e1efeb02e933c4559f5455d8e1691fd1a42f7ecc 100644 (file)
@@ -202,7 +202,8 @@ WepSet W_RandomWeapons(entity e, WepSet remaining, int n)
        return result;
 }
 
-string GetAmmoPicture(int ammotype)
+// TODO: registry handles for below functions
+string GetAmmoPicture(Resource ammotype)
 {
        switch (ammotype)
        {
@@ -216,7 +217,7 @@ string GetAmmoPicture(int ammotype)
        }
 }
 
-string GetAmmoName(int ammotype)
+string GetAmmoName(Resource ammotype)
 {
        switch (ammotype)
        {
@@ -230,7 +231,7 @@ string GetAmmoName(int ammotype)
        }
 }
 
-entity GetAmmoItem(int ammotype)
+entity GetAmmoItem(Resource ammotype)
 {
        switch (ammotype)
        {
@@ -241,14 +242,14 @@ entity GetAmmoItem(int ammotype)
                case RES_PLASMA:  return ITEM_Plasma;
                case RES_FUEL:    return ITEM_JetpackFuel;
        }
-       LOG_WARNF("Invalid ammo type %d ", ammotype);
+       LOG_WARNF("Invalid ammo type %d ", ammotype.m_id);
        return NULL;
        // WEAPONTODO: use this generic func to reduce duplication ?
        // GetAmmoPicture  GetAmmoName  notif_arg_item_wepammo  ammo_pickupevalfunc ?
 }
 
 #ifdef CSQC
-int GetAmmoTypeFromNum(int i)
+Resource GetAmmoTypeFromNum(int i)
 {
        switch (i)
        {
@@ -262,7 +263,7 @@ int GetAmmoTypeFromNum(int i)
        }
 }
 
-int GetAmmoStat(int ammotype)
+int GetAmmoStat(Resource ammotype)
 {
        switch (ammotype)
        {
index 83f3f4a0febd438e9f817f3ba9010bd747f78992..ec6e14eb668d8ef63e33cb6aaf2577fc464033cb 100644 (file)
@@ -1,7 +1,7 @@
 #pragma once
 
-#include <common/resources.qh>
 #include <common/items/item/pickup.qh>
+#include <common/resources/resources.qh>
 #include <common/stats.qh>
 
 #ifdef SVQC
@@ -45,7 +45,7 @@ CLASS(Weapon, Object)
     /** control what happens when this weapon is spawned */
     METHOD(Weapon, m_spawnfunc_hookreplace, Weapon(Weapon this, entity e)) { return this; }
     /** M: ammotype  : main ammo type */
-    ATTRIB(Weapon, ammo_type, int, RES_NONE);
+    ATTRIB(Weapon, ammo_type, Resource, RES_NONE);
     /** M: impulse   : weapon impulse */
     ATTRIB(Weapon, impulse, int, -1);
     /** M: flags     : WEPSPAWNFLAG_... combined */
@@ -223,15 +223,16 @@ string W_FixWeaponOrder_AllowIncomplete(entity this, string order);
 string W_FixWeaponOrder_ForceComplete(string order);
 WepSet W_RandomWeapons(entity e, WepSet remaining, int n);
 
-string GetAmmoPicture(int ammotype);
+string GetAmmoPicture(Resource ammotype);
 
-string GetAmmoName(int ammotype);
+string GetAmmoName(Resource ammotype);
 
-entity GetAmmoItem(int ammotype);
+entity GetAmmoItem(Resource ammotype);
 
 #ifdef CSQC
-int GetAmmoTypeFromNum(int i);
-int GetAmmoStat(int ammotype);
+Resource GetAmmoTypeFromNum(int i);
+
+int GetAmmoStat(Resource ammotype);
 #endif
 
 string W_Sound(string w_snd);
index 6db349889b80599587eb7a0b0e59333ba2de6668..15a2cb772f15b8dde905e6cd6c5d65197d566576 100644 (file)
@@ -2,7 +2,7 @@
 
 CLASS(Arc, Weapon)
 /* spawnfunc */ ATTRIB(Arc, m_canonical_spawnfunc, string, "weapon_arc");
-/* ammotype  */ ATTRIB(Arc, ammo_type, int, RES_CELLS);
+/* ammotype  */ ATTRIB(Arc, ammo_type, Resource, RES_CELLS);
 /* impulse   */ ATTRIB(Arc, impulse, int, 3);
 /* flags     */ ATTRIB(Arc, spawnflags, int, WEP_TYPE_HITSCAN);
 /* rating    */ ATTRIB(Arc, bot_pickupbasevalue, float, 8000);
index ed966cf2fac76bff9a2b304a070782564bd337ad..d768abfafe46ada390d6f4dfea6c4b3558c3c961 100644 (file)
@@ -2,7 +2,7 @@
 
 CLASS(Blaster, Weapon)
 /* spawnfunc */ ATTRIB(Blaster, m_canonical_spawnfunc, string, "weapon_blaster");
-/* ammotype  */ //ATTRIB(Blaster, ammo_type, int, RES_NONE);
+/* ammotype  */ //ATTRIB(Blaster, ammo_type, Resource, RES_NONE);
 /* impulse   */ ATTRIB(Blaster, impulse, int, 1);
 /* flags     */ ATTRIB(Blaster, spawnflags, int, WEP_FLAG_NORMAL | WEP_FLAG_CANCLIMB | WEP_TYPE_SPLASH);
 /* rating    */ ATTRIB(Blaster, bot_pickupbasevalue, float, 0);
index 501b8782273b70fd95c474546feae4c58220bca0..2329c364e2998f16d425856292da6c6431b181e3 100644 (file)
@@ -2,7 +2,7 @@
 
 CLASS(Crylink, Weapon)
 /* spawnfunc */ ATTRIB(Crylink, m_canonical_spawnfunc, string, "weapon_crylink");
-/* ammotype  */ ATTRIB(Crylink, ammo_type, int, RES_CELLS);
+/* ammotype  */ ATTRIB(Crylink, ammo_type, Resource, RES_CELLS);
 /* impulse   */ ATTRIB(Crylink, impulse, int, 6);
 /* flags     */ ATTRIB(Crylink, spawnflags, int, WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_TYPE_SPLASH | WEP_FLAG_CANCLIMB);
 /* rating    */ ATTRIB(Crylink, bot_pickupbasevalue, float, 6000);
index 11481c6f95167acf56acb927595a5056b52c04a0..70c72f52cba160dbcad5ab19e82e476f102f090c 100644 (file)
@@ -2,7 +2,7 @@
 
 CLASS(Devastator, Weapon)
 /* spawnfunc */ ATTRIB(Devastator, m_canonical_spawnfunc, string, "weapon_devastator");
-/* ammotype  */ ATTRIB(Devastator, ammo_type, int, RES_ROCKETS);
+/* ammotype  */ ATTRIB(Devastator, ammo_type, Resource, RES_ROCKETS);
 /* impulse   */ ATTRIB(Devastator, impulse, int, 9);
 /* flags     */ ATTRIB(Devastator, spawnflags, int, WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_FLAG_CANCLIMB | WEP_TYPE_SPLASH);
 /* rating    */ ATTRIB(Devastator, bot_pickupbasevalue, float, 8000);
index 6417243b2efbbd85c0276cf59a0a0c979c486ed2..e4263403bf82161b52cf66eac3a1507e9f4b3748 100644 (file)
@@ -2,7 +2,7 @@
 
 CLASS(Electro, Weapon)
 /* spawnfunc */ ATTRIB(Electro, m_canonical_spawnfunc, string, "weapon_electro");
-/* ammotype  */ ATTRIB(Electro, ammo_type, int, RES_CELLS);
+/* ammotype  */ ATTRIB(Electro, ammo_type, Resource, RES_CELLS);
 /* impulse   */ ATTRIB(Electro, impulse, int, 5);
 /* flags     */ ATTRIB(Electro, spawnflags, int, WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_FLAG_CANCLIMB | WEP_TYPE_SPLASH);
 /* rating    */ ATTRIB(Electro, bot_pickupbasevalue, float, 5000);
index dc59a109ce47a5a029b7f5a190c75fe188e86d58..c3dd73a2eb8bab5eea5d70b2288896533bdf9650 100644 (file)
@@ -2,7 +2,7 @@
 
 CLASS(Fireball, Weapon)
 /* spawnfunc */ ATTRIB(Fireball, m_canonical_spawnfunc, string, "weapon_fireball");
-/* ammotype  */ //ATTRIB(Fireball, ammo_type, int, RES_NONE);
+/* ammotype  */ //ATTRIB(Fireball, ammo_type, Resource, RES_NONE);
 /* impulse   */ ATTRIB(Fireball, impulse, int, 9);
 /* flags     */ ATTRIB(Fireball, spawnflags, int, WEP_FLAG_SUPERWEAPON | WEP_TYPE_SPLASH | WEP_FLAG_NODUAL);
 /* rating    */ ATTRIB(Fireball, bot_pickupbasevalue, float, 5000);
index d9df8485f4c8cc65e8cf1d2bb386029a4a7b85f0..5a43d84eff1fc5113e56058bc4a687d7fd95d54b 100644 (file)
@@ -2,7 +2,7 @@
 
 CLASS(Hagar, Weapon)
 /* spawnfunc */ ATTRIB(Hagar, m_canonical_spawnfunc, string, "weapon_hagar");
-/* ammotype  */ ATTRIB(Hagar, ammo_type, int, RES_ROCKETS);
+/* ammotype  */ ATTRIB(Hagar, ammo_type, Resource, RES_ROCKETS);
 /* impulse   */ ATTRIB(Hagar, impulse, int, 8);
 /* flags     */ ATTRIB(Hagar, spawnflags, int, WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_FLAG_CANCLIMB | WEP_TYPE_SPLASH);
 /* rating    */ ATTRIB(Hagar, bot_pickupbasevalue, float, 6000);
index 5ff0e2b30ea82a9c2d1444e0c05b2a6042e08be9..ec07fa35a4ba76184f9afe38416e5a35cea28301 100644 (file)
@@ -2,7 +2,7 @@
 
 CLASS(HLAC, Weapon)
 /* spawnfunc */ ATTRIB(HLAC, m_canonical_spawnfunc, string, "weapon_hlac");
-/* ammotype  */ ATTRIB(HLAC, ammo_type, int, RES_CELLS);
+/* ammotype  */ ATTRIB(HLAC, ammo_type, Resource, RES_CELLS);
 /* impulse   */ ATTRIB(HLAC, impulse, int, 6);
 /* flags     */ ATTRIB(HLAC, spawnflags, int, WEP_FLAG_MUTATORBLOCKED | WEP_FLAG_RELOADABLE | WEP_TYPE_SPLASH);
 /* rating    */ ATTRIB(HLAC, bot_pickupbasevalue, float, 4000);
index 385fab4d6a1488544d131be653fc269a80c77e2d..25b1be5073aa14542acc2e85802320597615c259 100644 (file)
@@ -2,7 +2,7 @@
 
 CLASS(Hook, Weapon)
 /* spawnfunc */ ATTRIB(Hook, m_canonical_spawnfunc, string, "weapon_hook");
-/* ammotype  */ ATTRIB(Hook, ammo_type, int, RES_FUEL);
+/* ammotype  */ ATTRIB(Hook, ammo_type, Resource, RES_FUEL);
 /* impulse   */ ATTRIB(Hook, impulse, int, 0);
 /* flags     */ ATTRIB(Hook, spawnflags, int, WEP_FLAG_CANCLIMB | WEP_TYPE_SPLASH | WEP_FLAG_NOTRUEAIM);
 /* rating    */ ATTRIB(Hook, bot_pickupbasevalue, float, 0);
index acf1668d79f75f7a38431bc72bf7cbf9104f2677..9a2adf46c94d42d17dfda956578c249857e09181 100644 (file)
@@ -2,7 +2,7 @@
 
 CLASS(MachineGun, Weapon)
 /* spawnfunc */ ATTRIB(MachineGun, m_canonical_spawnfunc, string, "weapon_machinegun");
-/* ammotype  */ ATTRIB(MachineGun, ammo_type, int, RES_BULLETS);
+/* ammotype  */ ATTRIB(MachineGun, ammo_type, Resource, RES_BULLETS);
 /* impulse   */ ATTRIB(MachineGun, impulse, int, 3);
 /* flags     */ ATTRIB(MachineGun, spawnflags, int, WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_TYPE_HITSCAN | WEP_FLAG_PENETRATEWALLS | WEP_FLAG_BLEED);
 /* rating    */ ATTRIB(MachineGun, bot_pickupbasevalue, float, 7000);
index b34ef9dd4171f9e88eed0bb9da3449730a074961..a574510f57736e373e0107ea59202d102ca09fca 100644 (file)
@@ -2,7 +2,7 @@
 
 CLASS(MineLayer, Weapon)
 /* spawnfunc */ ATTRIB(MineLayer, m_canonical_spawnfunc, string, "weapon_minelayer");
-/* ammotype  */ ATTRIB(MineLayer, ammo_type, int, RES_ROCKETS);
+/* ammotype  */ ATTRIB(MineLayer, ammo_type, Resource, RES_ROCKETS);
 /* impulse   */ ATTRIB(MineLayer, impulse, int, 4);
 /* flags     */ ATTRIB(MineLayer, spawnflags, int, WEP_FLAG_MUTATORBLOCKED | WEP_FLAG_RELOADABLE | WEP_TYPE_SPLASH);
 /* rating    */ ATTRIB(MineLayer, bot_pickupbasevalue, float, 7000);
index 97ee20791965e32f36c9ed2fc4bde13c4dc97859..118e5c5f0010ee03ce619f2f4b915d8895db3db0 100644 (file)
@@ -2,7 +2,7 @@
 
 CLASS(Mortar, Weapon)
 /* spawnfunc */ ATTRIB(Mortar, m_canonical_spawnfunc, string, "weapon_mortar");
-/* ammotype  */ ATTRIB(Mortar, ammo_type, int, RES_ROCKETS);
+/* ammotype  */ ATTRIB(Mortar, ammo_type, Resource, RES_ROCKETS);
 /* impulse   */ ATTRIB(Mortar, impulse, int, 4);
 /* flags     */ ATTRIB(Mortar, spawnflags, int, WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_FLAG_CANCLIMB | WEP_TYPE_SPLASH | WEP_FLAG_NOTRUEAIM);
 /* rating    */ ATTRIB(Mortar, bot_pickupbasevalue, float, 7000);
index 6c1a6e7f2957a9ba08e14539df9ff66e9225a5dc..757386b5c3f9dd65db332d5ed948619f3cc74b12 100644 (file)
@@ -2,7 +2,7 @@
 
 CLASS(PortoLaunch, Weapon)
 /* spawnfunc */ ATTRIB(PortoLaunch, m_canonical_spawnfunc, string, "weapon_porto");
-/* ammotype  */ ATTRIB(PortoLaunch, ammo_type, int, RES_NONE);
+/* ammotype  */ ATTRIB(PortoLaunch, ammo_type, Resource, RES_NONE);
 /* impulse   */ ATTRIB(PortoLaunch, impulse, int, 0);
 /* flags     */ ATTRIB(PortoLaunch, spawnflags, int, WEP_TYPE_OTHER | WEP_FLAG_SUPERWEAPON | WEP_FLAG_NODUAL | WEP_FLAG_NOTRUEAIM);
 /* rating    */ ATTRIB(PortoLaunch, bot_pickupbasevalue, float, 0);
index 7a2348af740d78954bd6ae86e09af5f1ef1ae4a3..e5a2cde2b0b3956f3081c0889e5aa98d11b56390 100644 (file)
@@ -2,7 +2,7 @@
 
 CLASS(Rifle, Weapon)
 /* spawnfunc */ ATTRIB(Rifle, m_canonical_spawnfunc, string, "weapon_rifle");
-/* ammotype  */ ATTRIB(Rifle, ammo_type, int, RES_BULLETS);
+/* ammotype  */ ATTRIB(Rifle, ammo_type, Resource, RES_BULLETS);
 /* impulse   */ ATTRIB(Rifle, impulse, int, 7);
 /* flags     */ ATTRIB(Rifle, spawnflags, int, WEP_FLAG_MUTATORBLOCKED | WEP_FLAG_RELOADABLE | WEP_TYPE_HITSCAN | WEP_FLAG_PENETRATEWALLS);
 /* rating    */ ATTRIB(Rifle, bot_pickupbasevalue, float, 7000);
index 3e79ce252bdd7bb7461c306ce2e8f20664876845..d3024a436e485fa5a0bda7557d1489a4ebaca4a8 100644 (file)
@@ -2,7 +2,7 @@
 
 CLASS(Seeker, Weapon)
 /* spawnfunc */ ATTRIB(Seeker, m_canonical_spawnfunc, string, "weapon_seeker");
-/* ammotype  */ ATTRIB(Seeker, ammo_type, int, RES_ROCKETS);
+/* ammotype  */ ATTRIB(Seeker, ammo_type, Resource, RES_ROCKETS);
 /* impulse   */ ATTRIB(Seeker, impulse, int, 8);
 /* flags     */ ATTRIB(Seeker, spawnflags, int, WEP_FLAG_MUTATORBLOCKED | WEP_FLAG_RELOADABLE | WEP_TYPE_SPLASH);
 /* rating    */ ATTRIB(Seeker, bot_pickupbasevalue, float, 5000);
index 8b1cd48efd260701993a907826b50cfe0872e677..9fa484b6a49ea75f22970ed610f7b711b34c2878 100644 (file)
@@ -2,7 +2,7 @@
 
 CLASS(Shockwave, Weapon)
 /* spawnfunc */ ATTRIB(Shockwave, m_canonical_spawnfunc, string, "weapon_shockwave");
-/* ammotype  */ //ATTRIB(Shockwave, ammo_type, int, RES_NONE);
+/* ammotype  */ //ATTRIB(Shockwave, ammo_type, Resource, RES_NONE);
 /* impulse   */ ATTRIB(Shockwave, impulse, int, 2);
 /* flags     */ ATTRIB(Shockwave, spawnflags, int, WEP_FLAG_HIDDEN | WEP_TYPE_HITSCAN | WEP_FLAG_CANCLIMB | WEP_TYPE_MELEE_SEC);
 /* rating    */ ATTRIB(Shockwave, bot_pickupbasevalue, float, 3000);
index d99a371f34cbcd593aabb50cd789d136ab320e2e..5b200ed588e0df64bcfb951ab16e6e2ffcfb49e3 100644 (file)
@@ -2,7 +2,7 @@
 
 CLASS(Shotgun, Weapon)
 /* spawnfunc */ ATTRIB(Shotgun, m_canonical_spawnfunc, string, "weapon_shotgun");
-/* ammotype  */ ATTRIB(Shotgun, ammo_type, int, RES_SHELLS);
+/* ammotype  */ ATTRIB(Shotgun, ammo_type, Resource, RES_SHELLS);
 /* impulse   */ ATTRIB(Shotgun, impulse, int, 2);
 /* flags     */ ATTRIB(Shotgun, spawnflags, int, WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_TYPE_HITSCAN | WEP_TYPE_MELEE_SEC | WEP_FLAG_BLEED);
 /* rating    */ ATTRIB(Shotgun, bot_pickupbasevalue, float, 6000);
index 00dbf78ec48662679a72fc58d9e85ce5b5d9d3fa..c34062a6bad024c9eac08c15d4e8ce93b3de78d6 100644 (file)
@@ -2,7 +2,7 @@
 
 CLASS(Vaporizer, Weapon)
 /* spawnfunc */ ATTRIB(Vaporizer, m_canonical_spawnfunc, string, "weapon_vaporizer");
-/* ammotype  */ ATTRIB(Vaporizer, ammo_type, int, RES_CELLS);
+/* ammotype  */ ATTRIB(Vaporizer, ammo_type, Resource, RES_CELLS);
 /* impulse   */ ATTRIB(Vaporizer, impulse, int, 7);
 /* flags     */ ATTRIB(Vaporizer, spawnflags, int, WEP_FLAG_RELOADABLE | WEP_FLAG_CANCLIMB | WEP_FLAG_SUPERWEAPON | WEP_TYPE_HITSCAN | WEP_FLAG_NODUAL);
 /* rating    */ ATTRIB(Vaporizer, bot_pickupbasevalue, float, 10000);
index 040374f4cef0b3c5bb610dc0e0068764d6eb00e6..babbfe51bb0f25a8a0777ce78cbfc3da08470ce7 100644 (file)
@@ -2,7 +2,7 @@
 
 CLASS(Vortex, Weapon)
 /* spawnfunc */ ATTRIB(Vortex, m_canonical_spawnfunc, string, "weapon_vortex");
-/* ammotype  */ ATTRIB(Vortex, ammo_type, int, RES_CELLS);
+/* ammotype  */ ATTRIB(Vortex, ammo_type, Resource, RES_CELLS);
 /* impulse   */ ATTRIB(Vortex, impulse, int, 7);
 /* flags     */ ATTRIB(Vortex, spawnflags, int, WEP_FLAG_NORMAL | WEP_FLAG_RELOADABLE | WEP_TYPE_HITSCAN);
 /* rating    */ ATTRIB(Vortex, bot_pickupbasevalue, float, 8000);
index 34ca1e2c85d664ee07c2ce53177c03945a39f22e..c82e892f721815fdeff9c6b46d0260eee26fe86d 100644 (file)
@@ -20,7 +20,6 @@
 #include <server/player.qc>
 #include <server/portals.qc>
 #include <server/race.qc>
-#include <server/resources.qc>
 #include <server/round_handler.qc>
 #include <server/scores.qc>
 #include <server/scores_rules.qc>
index c997538266a8c1be093b43556118d63baa601311..52574efecc1ac689a2d9a341cc9a10a7d40c6943 100644 (file)
@@ -20,7 +20,6 @@
 #include <server/player.qh>
 #include <server/portals.qh>
 #include <server/race.qh>
-#include <server/resources.qh>
 #include <server/round_handler.qh>
 #include <server/scores.qh>
 #include <server/scores_rules.qh>
index 87f7bc0d00f0584b2c70f356fb18eea830b6a926..52aff186aef70e133f390c1851f93dc5c613e6f6 100644 (file)
@@ -1,5 +1,6 @@
 #include "roles.qh"
 
+#include <common/resources/sv_resources.qh>
 #include <common/stats.qh>
 #include <common/mutators/mutator/powerups/_mod.qh>
 #include <common/mutators/mutator/status_effects/_mod.qh>
@@ -11,7 +12,6 @@
 #include <server/items/items.qh>
 #include <server/items/spawning.qh>
 #include <server/mutators/_mod.qh>
-#include <server/resources.qh>
 
 void havocbot_goalrating_waypoints(entity this, float ratingscale, vector org, float sradius)
 {
index 6091c5344077b4b147ef0d09e0e44eba4d715e53..9ec7cc69a637466cfc9759ac3fe398cc5a02558c 100644 (file)
@@ -12,6 +12,7 @@
 #include <common/monsters/_mod.qh>
 #include <common/mutators/mutator/status_effects/_mod.qh>
 #include <common/physics/player.qh>
+#include <common/resources/sv_resources.qh>
 #include <common/stats.qh>
 #include <common/util.qh>
 #include <common/weapons/_all.qh>
@@ -26,7 +27,6 @@
 #include <server/mutators/_mod.qh>
 #include <server/player.qh>
 #include <server/race.qh>
-#include <server/resources.qh>
 #include <server/world.qh>
 
 #ifdef NOCHEATS
index edefc0d28b0f72086d11ba12ff75224460716d5d..421a1eb5503163a1333d8d1ee9b38395105bf4a2 100644 (file)
@@ -30,6 +30,7 @@
 #include <common/notifications/all.qh>
 #include <common/physics/player.qh>
 #include <common/playerstats.qh>
+#include <common/resources/sv_resources.qh>
 #include <common/state.qh>
 #include <common/stats.qh>
 #include <common/vehicles/all.qh>
@@ -65,7 +66,6 @@
 #include <server/player.qh>
 #include <server/portals.qh>
 #include <server/race.qh>
-#include <server/resources.qh>
 #include <server/scores.qh>
 #include <server/scores_rules.qh>
 #include <server/spawnpoints.qh>
@@ -1554,7 +1554,7 @@ float CalcRot(float current, float stable, float rotfactor, float rotframetime)
                return max(stable, current + (stable - current) * rotfactor * rotframetime);
 }
 
-void RotRegen(entity this, int res, float limit_mod,
+void RotRegen(entity this, Resource res, float limit_mod,
        float regenstable, float regenfactor, float regenlinear, float regenframetime,
        float rotstable, float rotfactor, float rotlinear, float rotframetime)
 {
index b3ba22abd8738371809ab3b5e1f9b4e927dca192..b2cf8edb743d342f0c3037d7eab89a2a7fc6043f 100644 (file)
@@ -2,6 +2,7 @@
 
 #include "utils.qh"
 #include <server/intermission.qh>
+//#include <common/resources/resources.qh>
 #include <common/replicate.qh>
 #include <common/sounds/all.qh>
 
@@ -376,7 +377,8 @@ STATIC_INIT(g_initforplayer) { g_initforplayer = IL_NEW(); }
 void play_countdown(entity this, float finished, Sound samp);
 void player_powerups_remove_all(entity this);
 
-void RotRegen(entity this, float current, float limit_mod,
+// NOTE: current type is Resource (avoiding circular includes!)
+void RotRegen(entity this, entity current, float limit_mod,
        float regenstable, float regenfactor, float regenlinear, float regenframetime,
        float rotstable, float rotfactor, float rotlinear, float rotframetime);
 
index ac2409cc0dc4b0718e5105dd1cacd2593957ad87..911ab0f815534dfcebd5e10c35ab7ed658be0d72 100644 (file)
@@ -9,13 +9,13 @@
 #include <common/mutators/mutator/powerups/_mod.qh>
 #include <common/mutators/mutator/status_effects/_mod.qh>
 #include <common/notifications/all.qh>
+#include <common/resources/sv_resources.qh>
 #include <common/stats.qh>
 #include <common/weapons/_all.qh>
 #include <common/weapons/_all.qh>
 #include <server/client.qh>
 #include <server/items/items.qh>
 #include <server/items/spawning.qh>
-#include <server/resources.qh>
 #include <server/world.qh>
 
 /***********************
index 7a614bc87cf0d4503f59fb108e5e28a23854d23e..969423bfb83f8b0e55ae1e6add6f25b5bdebefcc 100644 (file)
@@ -17,6 +17,7 @@
 #include <common/physics/movetypes/movetypes.qh>
 #include <common/physics/player.qh>
 #include <common/playerstats.qh>
+#include <common/resources/sv_resources.qh>
 #include <common/state.qh>
 #include <common/teams.qh>
 #include <common/util.qh>
@@ -31,7 +32,6 @@
 #include <server/items/items.qh>
 #include <server/main.qh>
 #include <server/mutators/_mod.qh>
-#include <server/resources.qh>
 #include <server/scores.qh>
 #include <server/spawnpoints.qh>
 #include <server/teamplay.qh>
index ade4795c523e420e56c77f4f5b5164cbc8250179..0ea10da5e389ef37a23402584390aa671470fa16 100644 (file)
@@ -12,6 +12,7 @@
 #include <common/mutators/mutator/powerups/_mod.qh>
 #include <common/mutators/mutator/status_effects/_mod.qh>
 #include <common/notifications/all.qh>
+#include <common/resources/resources.qh>
 #include <common/util.qh>
 #include <common/weapons/_all.qh>
 #include <common/wepent.qh>
@@ -447,7 +448,7 @@ void GiveRandomWeapons(entity receiver, int num_weapons, string weapon_names,
        }
 }
 
-bool Item_GiveAmmoTo(entity item, entity player, int res_type, float ammomax)
+bool Item_GiveAmmoTo(entity item, entity player, Resource res_type, float ammomax)
 {
        float amount = GetResource(item, res_type);
        if (amount == 0)
@@ -1450,7 +1451,7 @@ void GiveRot(entity e, float v0, float v1, .float rotfield, float rottime, .floa
        else if(v0 > v1)
                e.(regenfield) = max(e.(regenfield), time + regentime);
 }
-bool GiveResourceValue(entity e, int res_type, int op, int val)
+bool GiveResourceValue(entity e, Resource res_type, int op, int val)
 {
        int v0 = GetResource(e, res_type);
        float new_val = 0;
index dc3898323aea38a43daddcf99624c3b9b02e7e7a..dff9ccda2356075db87ccae66208428d0f58f00d 100644 (file)
@@ -1,5 +1,6 @@
 #pragma once
 
+#include <common/resources/resources.qh>
 #include <common/sounds/sound.qh>
 
 float autocvar_g_balance_superweapons_time;
@@ -64,7 +65,7 @@ void Item_ScheduleInitialRespawn(entity e);
 /// \return No return.
 void GiveRandomWeapons(entity receiver, int num_weapons, string weapon_names, entity ammo_entity);
 
-bool Item_GiveAmmoTo(entity item, entity player, int res_type, float ammomax);
+bool Item_GiveAmmoTo(entity item, entity player, Resource res_type, float ammomax);
 
 bool Item_GiveTo(entity item, entity player);
 
index ee5d18a69157a9d6210bc211ed0f813748578442..abda2bda31545d8238601007c15547a0026a7ee0 100644 (file)
@@ -709,7 +709,7 @@ MUTATOR_HOOKABLE(ItemTouched, EV_ItemTouched);
 resource limit. */
 #define EV_GetResourceLimit(i, o) \
        /** checked entity */ i(entity, MUTATOR_ARGV_0_entity) \
-       /** resource type */  i(int, MUTATOR_ARGV_1_int) \
+       /** resource type */  i(entity, MUTATOR_ARGV_1_entity) \
        /** limit */          i(float, MUTATOR_ARGV_2_float) \
        /**/                  o(float, MUTATOR_ARGV_2_float) \
        /**/
@@ -719,8 +719,8 @@ MUTATOR_HOOKABLE(GetResourceLimit, EV_GetResourceLimit);
 constants for resource types. Return true to forbid the change. */
 #define EV_SetResource(i, o) \
        /** checked entity */ i(entity, MUTATOR_ARGV_0_entity) \
-       /** resource type */  i(int, MUTATOR_ARGV_1_int) \
-       /**/                  o(int, MUTATOR_ARGV_1_int) \
+       /** resource type */  i(entity, MUTATOR_ARGV_1_entity) \
+       /**/                  o(entity, MUTATOR_ARGV_1_entity) \
        /** amount */         i(float, MUTATOR_ARGV_2_float) \
        /**/                  o(float, MUTATOR_ARGV_2_float) \
        /**/
@@ -731,7 +731,7 @@ constants for resource types. Amount wasted is the amount of resource that is
 above resource limit so it was not given. */
 #define EV_ResourceAmountChanged(i, o) \
        /** checked entity */ i(entity, MUTATOR_ARGV_0_entity) \
-       /** resource type */  i(int, MUTATOR_ARGV_1_int) \
+       /** resource type */  i(entity, MUTATOR_ARGV_1_entity) \
        /** amount */         i(float, MUTATOR_ARGV_2_float) \
        /**/
 MUTATOR_HOOKABLE(ResourceAmountChanged, EV_ResourceAmountChanged);
@@ -741,7 +741,7 @@ limit. See RES_* constants for resource types. Amount wasted is the amount
 of resource that is above resource limit so it was not given. */
 #define EV_ResourceWasted(i, o) \
        /** checked entity */ i(entity, MUTATOR_ARGV_0_entity) \
-       /** resource type */  i(int, MUTATOR_ARGV_1_int) \
+       /** resource type */  i(entity, MUTATOR_ARGV_1_entity) \
        /** amount wasted */  i(float, MUTATOR_ARGV_2_float) \
        /**/
 MUTATOR_HOOKABLE(ResourceWasted, EV_ResourceWasted);
@@ -751,8 +751,8 @@ for resource types. Return true to forbid giving.
 NOTE: This hook is also called by GiveResourceWithLimit */
 #define EV_GiveResource(i, o) \
        /** receiver */      i(entity, MUTATOR_ARGV_0_entity) \
-       /** resource type */ i(int, MUTATOR_ARGV_1_int) \
-       /**/                 o(int, MUTATOR_ARGV_1_int) \
+       /** resource type */ i(entity, MUTATOR_ARGV_1_entity) \
+       /**/                 o(entity, MUTATOR_ARGV_1_entity) \
        /** amount */        i(float, MUTATOR_ARGV_2_float) \
        /**/                 o(float, MUTATOR_ARGV_2_float) \
        /**/
@@ -762,8 +762,8 @@ MUTATOR_HOOKABLE(GiveResource, EV_GiveResource);
 RES_* constants for resource types. Return true to forbid giving. */
 #define EV_GiveResourceWithLimit(i, o) \
        /** receiver */      i(entity, MUTATOR_ARGV_0_entity) \
-       /** resource type */ i(int, MUTATOR_ARGV_1_int) \
-       /**/                 o(int, MUTATOR_ARGV_1_int) \
+       /** resource type */ i(entity, MUTATOR_ARGV_1_entity) \
+       /**/                 o(entity, MUTATOR_ARGV_1_entity) \
        /** amount */        i(float, MUTATOR_ARGV_2_float) \
        /**/                 o(float, MUTATOR_ARGV_2_float) \
        /** limit */         i(float, MUTATOR_ARGV_3_float) \
@@ -776,8 +776,8 @@ for resource types. Return true to forbid giving.
 NOTE: This hook is also called by TakeResourceWithLimit */
 #define EV_TakeResource(i, o) \
     /** receiver */      i(entity, MUTATOR_ARGV_0_entity) \
-    /** resource type */ i(int, MUTATOR_ARGV_1_int) \
-    /**/                 o(int, MUTATOR_ARGV_1_int) \
+    /** resource type */ i(entity, MUTATOR_ARGV_1_entity) \
+    /**/                 o(entity, MUTATOR_ARGV_1_entity) \
     /** amount */        i(float, MUTATOR_ARGV_2_float) \
     /**/                 o(float, MUTATOR_ARGV_2_float) \
     /**/
@@ -787,8 +787,8 @@ MUTATOR_HOOKABLE(TakeResource, EV_TakeResource);
 RES_* constants for resource types. Return true to forbid giving. */
 #define EV_TakeResourceWithLimit(i, o) \
     /** receiver */      i(entity, MUTATOR_ARGV_0_entity) \
-    /** resource type */ i(int, MUTATOR_ARGV_1_int) \
-    /**/                 o(int, MUTATOR_ARGV_1_int) \
+    /** resource type */ i(entity, MUTATOR_ARGV_1_entity) \
+    /**/                 o(entity, MUTATOR_ARGV_1_entity) \
     /** amount */        i(float, MUTATOR_ARGV_2_float) \
     /**/                 o(float, MUTATOR_ARGV_2_float) \
     /** limit */         i(float, MUTATOR_ARGV_3_float) \
diff --git a/qcsrc/server/resources.qc b/qcsrc/server/resources.qc
deleted file mode 100644 (file)
index e0b8995..0000000
+++ /dev/null
@@ -1,265 +0,0 @@
-#include "resources.qh"
-
-/// \file
-/// \brief Source file that contains implementation of the resource system.
-/// \author Lyberta
-/// \copyright GNU GPLv2 or any later version.
-
-#include <server/mutators/_mod.qh>
-#include <server/world.qh>
-
-float GetResourceLimit(entity e, int res_type)
-{
-       if(!IS_PLAYER(e))
-               return RES_LIMIT_NONE; // no limits on non-players
-
-       float limit;
-       switch (res_type)
-       {
-               case RES_HEALTH:
-               {
-                       limit = autocvar_g_balance_health_limit;
-                       break;
-               }
-               case RES_ARMOR:
-               {
-                       limit = autocvar_g_balance_armor_limit;
-                       break;
-               }
-               case RES_SHELLS:
-               {
-                       limit = g_pickup_shells_max;
-                       break;
-               }
-               case RES_BULLETS:
-               {
-                       limit = g_pickup_nails_max;
-                       break;
-               }
-               case RES_ROCKETS:
-               {
-                       limit = g_pickup_rockets_max;
-                       break;
-               }
-               case RES_CELLS:
-               {
-                       limit = g_pickup_cells_max;
-                       break;
-               }
-               case RES_PLASMA:
-               {
-                       limit = g_pickup_plasma_max;
-                       break;
-               }
-               case RES_FUEL:
-               {
-                       limit = autocvar_g_balance_fuel_limit;
-                       break;
-               }
-               default:
-               {
-                       error("GetResourceLimit: Invalid resource type.");
-                       return 0;
-               }
-       }
-       MUTATOR_CALLHOOK(GetResourceLimit, e, res_type, limit);
-       limit = M_ARGV(2, float);
-       if (limit > RES_AMOUNT_HARD_LIMIT)
-       {
-               limit = RES_AMOUNT_HARD_LIMIT;
-       }
-       return limit;
-}
-
-float GetResource(entity e, int res_type)
-{
-       return e.(GetResourceField(res_type));
-}
-
-bool SetResourceExplicit(entity e, int res_type, float amount)
-{
-       .float res_field = GetResourceField(res_type);
-       if (e.(res_field) != amount)
-       {
-               e.(res_field) = amount;
-               return true;
-       }
-       return false;
-}
-
-void SetResource(entity e, int res_type, float amount)
-{
-       bool forbid = MUTATOR_CALLHOOK(SetResource, e, res_type, amount);
-       if (forbid)
-       {
-               return;
-       }
-       res_type = M_ARGV(1, int);
-       amount = M_ARGV(2, float);
-       float max_amount = GetResourceLimit(e, res_type); // TODO: should allow overriding these limits if cheats are enabled!
-       float amount_wasted = 0;
-       if (amount > max_amount && max_amount != RES_LIMIT_NONE)
-       {
-               amount_wasted = amount - max_amount;
-               amount = max_amount;
-       }
-       bool changed = SetResourceExplicit(e, res_type, amount);
-       if (changed)
-       {
-               MUTATOR_CALLHOOK(ResourceAmountChanged, e, res_type, amount);
-       }
-       if (amount_wasted == 0)
-       {
-               return;
-       }
-       MUTATOR_CALLHOOK(ResourceWasted, e, res_type, amount_wasted);
-}
-
-void GiveResource(entity receiver, int res_type, float amount)
-{
-       if (amount <= 0)
-       {
-               return;
-       }
-       bool forbid = MUTATOR_CALLHOOK(GiveResource, receiver, res_type, amount);
-       if (forbid)
-       {
-               return;
-       }
-       res_type = M_ARGV(1, int);
-       amount = M_ARGV(2, float);
-       if (amount <= 0)
-       {
-               return;
-       }
-       SetResource(receiver, res_type, GetResource(receiver, res_type) + amount);
-       switch (res_type)
-       {
-               case RES_HEALTH:
-               {
-                       receiver.pauserothealth_finished =
-                               max(receiver.pauserothealth_finished, time +
-                               autocvar_g_balance_pause_health_rot);
-                       return;
-               }
-               case RES_ARMOR:
-               {
-                       receiver.pauserotarmor_finished =
-                               max(receiver.pauserotarmor_finished, time +
-                               autocvar_g_balance_pause_armor_rot);
-                       return;
-               }
-               case RES_FUEL:
-               {
-                       receiver.pauserotfuel_finished = max(receiver.pauserotfuel_finished,
-                               time + autocvar_g_balance_pause_fuel_rot);
-                       return;
-               }
-       }
-}
-
-void GiveResourceWithLimit(entity receiver, int res_type, float amount, float limit)
-{
-       if (amount <= 0)
-       {
-               return;
-       }
-       bool forbid = MUTATOR_CALLHOOK(GiveResourceWithLimit, receiver, res_type, amount, limit);
-       if (forbid)
-       {
-               return;
-       }
-       res_type = M_ARGV(1, int);
-       amount = M_ARGV(2, float);
-       limit = M_ARGV(3, float);
-       if (amount <= 0)
-       {
-               return;
-       }
-       float current_amount = GetResource(receiver, res_type);
-       if (current_amount + amount > limit && limit != RES_LIMIT_NONE)
-       {
-               amount = limit - current_amount;
-       }
-       GiveResource(receiver, res_type, amount);
-}
-
-void TakeResource(entity receiver, int res_type, float amount)
-{
-       if (amount <= 0)
-       {
-               return;
-       }
-       bool forbid = MUTATOR_CALLHOOK(TakeResource, receiver, res_type, amount);
-       if (forbid)
-       {
-               return;
-       }
-       res_type = M_ARGV(1, int);
-       amount = M_ARGV(2, float);
-       if (amount <= 0)
-       {
-               return;
-       }
-       SetResource(receiver, res_type, GetResource(receiver, res_type) - amount);
-}
-
-void TakeResourceWithLimit(entity receiver, int res_type, float amount, float limit)
-{
-       if (amount <= 0)
-       {
-               return;
-       }
-       bool forbid = MUTATOR_CALLHOOK(TakeResourceWithLimit, receiver, res_type, amount, limit);
-       if (forbid)
-       {
-               return;
-       }
-       res_type = M_ARGV(1, int);
-       amount = M_ARGV(2, float);
-       limit = M_ARGV(3, float);
-       if (amount <= 0)
-       {
-               return;
-       }
-       float current_amount = GetResource(receiver, res_type);
-       if (current_amount - amount < -limit)
-       {
-               amount = -limit + current_amount;
-       }
-       TakeResource(receiver, res_type, amount);
-}
-
-int GetResourceType(.float res_field)
-{
-       switch (res_field)
-       {
-               case health: { return RES_HEALTH; }
-               case armorvalue: { return RES_ARMOR; }
-               case ammo_shells: { return RES_SHELLS; }
-               case ammo_nails: { return RES_BULLETS; }
-               case ammo_rockets: { return RES_ROCKETS; }
-               case ammo_cells: { return RES_CELLS; }
-               case ammo_plasma: { return RES_PLASMA; }
-               case ammo_fuel: { return RES_FUEL; }
-       }
-       error("GetResourceType: Invalid field.");
-       return 0;
-}
-
-.float GetResourceField(int res_type)
-{
-       switch (res_type)
-       {
-               case RES_HEALTH: { return health; }
-               case RES_ARMOR: { return armorvalue; }
-               case RES_SHELLS: { return ammo_shells; }
-               case RES_BULLETS: { return ammo_nails; }
-               case RES_ROCKETS: { return ammo_rockets; }
-               case RES_CELLS: { return ammo_cells; }
-               case RES_PLASMA: { return ammo_plasma; }
-               case RES_FUEL: { return ammo_fuel; }
-       }
-       error("GetResourceField: Invalid resource type.");
-       return health;
-}
diff --git a/qcsrc/server/resources.qh b/qcsrc/server/resources.qh
deleted file mode 100644 (file)
index 05cb602..0000000
+++ /dev/null
@@ -1,107 +0,0 @@
-#pragma once
-
-/// \file
-/// \brief Header file that describes the resource system.
-/// \author Lyberta
-/// \copyright GNU GPLv2 or any later version.
-
-#include <common/resources.qh>
-
-// TODO: split resources into their own files, registry based
-float autocvar_g_balance_health_limit;
-int autocvar_g_balance_armor_limit;
-float autocvar_g_balance_fuel_limit;
-float autocvar_g_balance_armor_regen;
-float autocvar_g_balance_armor_regenlinear;
-int autocvar_g_balance_armor_regenstable;
-float autocvar_g_balance_armor_rot;
-float autocvar_g_balance_armor_rotlinear;
-int autocvar_g_balance_armor_rotstable;
-float autocvar_g_balance_fuel_regen;
-float autocvar_g_balance_fuel_regenlinear;
-int autocvar_g_balance_fuel_regenstable;
-float autocvar_g_balance_fuel_rot;
-float autocvar_g_balance_fuel_rotlinear;
-int autocvar_g_balance_fuel_rotstable;
-float autocvar_g_balance_health_regen;
-float autocvar_g_balance_health_regenlinear;
-float autocvar_g_balance_health_regenstable;
-float autocvar_g_balance_health_rot;
-float autocvar_g_balance_health_rotlinear;
-float autocvar_g_balance_health_rotstable;
-float autocvar_g_balance_pause_armor_rot;
-float autocvar_g_balance_pause_fuel_regen;
-float autocvar_g_balance_pause_fuel_rot;
-float autocvar_g_balance_pause_health_regen;
-float autocvar_g_balance_pause_health_rot;
-
-// ============================ Public API ====================================
-
-/// \brief Returns the maximum amount of the given resource.
-/// \param[in] e Entity to check.
-/// \param[in] res_type Type of the resource (a RES_* constant).
-/// \return Maximum amount of the given resource.
-float GetResourceLimit(entity e, int res_type);
-
-/// \brief Returns the current amount of resource the given entity has.
-/// \param[in] e Entity to check.
-/// \param[in] res_type Type of the resource (a RES_* constant).
-/// \return Current amount of resource the given entity has.
-float GetResource(entity e, int res_type);
-
-/// \brief Sets the resource amount of an entity without calling any hooks.
-/// \param[in,out] e Entity to adjust.
-/// \param[in] res_type Type of the resource (a RES_* constant).
-/// \param[in] amount Amount of resource to set.
-/// \return Boolean for whether the ammo amount was changed
-bool SetResourceExplicit(entity e, int res_type, float amount);
-
-/// \brief Sets the current amount of resource the given entity will have
-/// but limited to the max amount allowed for the resource type.
-/// \param[in,out] e Entity to adjust.
-/// \param[in] res_type Type of the resource (a RES_* constant).
-/// \param[in] amount Amount of resource to set.
-/// \return No return.
-void SetResource(entity e, int res_type, float amount);
-
-/// \brief Gives an entity some resource.
-/// \param[in,out] receiver Entity to give resource to.
-/// \param[in] res_type Type of the resource (a RES_* constant).
-/// \param[in] amount Amount of resource to give.
-/// \return No return.
-void GiveResource(entity receiver, int res_type, float amount);
-
-/// \brief Gives an entity some resource but not more than a limit.
-/// \param[in,out] receiver Entity to give resource to.
-/// \param[in] res_type Type of the resource (a RES_* constant).
-/// \param[in] amount Amount of resource to give.
-/// \param[in] limit Limit of resources to give.
-/// \return No return.
-void GiveResourceWithLimit(entity receiver, int res_type, float amount, float limit);
-
-/// \brief Takes an entity some resource.
-/// \param[in,out] receiver Entity to take resource from.
-/// \param[in] res_type Type of the resource (a RES_* constant).
-/// \param[in] amount Amount of resource to take.
-/// \return No return.
-void TakeResource(entity receiver, int res_type, float amount);
-
-/// \brief Takes an entity some resource but not less than a limit.
-/// \param[in,out] receiver Entity to take resource from.
-/// \param[in] res_type Type of the resource (a RES_* constant).
-/// \param[in] amount Amount of resource to take.
-/// \param[in] limit Limit of resources to take.
-/// \return No return.
-void TakeResourceWithLimit(entity receiver, int res_type, float amount, float limit);
-
-// ===================== Legacy and/or internal API ===========================
-
-/// \brief Converts an entity field to resource type.
-/// \param[in] res_field Entity field to convert.
-/// \return Resource type (a RES_* constant).
-int GetResourceType(.float res_field);
-
-/// \brief Converts resource type (a RES_* constant) to entity field.
-/// \param[in] res_type Type of the resource.
-/// \return Entity field for that resource.
-.float GetResourceField(int res_type);
index 810cc2638453561cbf11ab56f2ecfd591310db5c..30a2869f399f42b1887a4d7e626364a3f7b81b4e 100644 (file)
@@ -1,10 +1,10 @@
 #include "spawning.qh"
 
+#include <common/resources/sv_resources.qh>
 #include <common/weapons/_all.qh>
 #include <server/items/items.qh>
 #include <server/items/spawning.qh>
 #include <server/mutators/_mod.qh>
-#include <server/resources.qh>
 #include <server/weapons/weaponsystem.qh>
 #include <server/world.qh>
 
@@ -108,6 +108,7 @@ void weapon_defaultspawnfunc(entity this, Weapon wpn)
                        this.superweapons_finished = autocvar_g_balance_superweapons_time;
 
        // if we don't already have ammo, give us some ammo
+       // TODO: registry handles
        if ((wpn.ammo_type != RES_NONE) && !GetResource(this, wpn.ammo_type))
        {
                int ammo = 0;
index 66b62c6e2f502fb61db9ea4a364d4539752a480d..719b5993590891173a572c25584398b7882de4f5 100644 (file)
@@ -5,6 +5,7 @@
 #include <common/mapobjects/subs.qh>
 #include <common/mutators/mutator/status_effects/_mod.qh>
 #include <common/notifications/all.qh>
+#include <common/resources/sv_resources.qh>
 #include <common/state.qh>
 #include <common/util.qh>
 #include <common/weapons/_all.qh>
@@ -13,7 +14,6 @@
 #include <server/items/items.qh>
 #include <server/items/spawning.qh>
 #include <server/mutators/_mod.qh>
-#include <server/resources.qh>
 #include <server/weapons/selection.qh>
 #include <server/weapons/weaponsystem.qh>
 #include <server/world.qh>
@@ -40,7 +40,7 @@ void thrown_wep_think(entity this)
 float W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vector velo, .entity weaponentity)
 {
        Weapon info = REGISTRY_GET(Weapons, wpn);
-       int ammotype = info.ammo_type;
+       Resource ammotype = info.ammo_type;
 
        entity wep = spawn();
        Item_SetLoot(wep, true);
index 200e6a3bd24c5ca66efbf05141750cebc5c1796e..fcce2a23d7a3c2427ae03a31c0b15efcfe57ce0b 100644 (file)
@@ -8,6 +8,7 @@
 #include <common/mutators/mutator/status_effects/_mod.qh>
 #include <common/net_linked.qh>
 #include <common/notifications/all.qh>
+#include <common/resources/sv_resources.qh>
 #include <common/state.qh>
 #include <common/util.qh>
 #include <common/vehicles/all.qh>
@@ -21,7 +22,6 @@
 #include <server/items/items.qh>
 #include <server/hook.qh>
 #include <server/mutators/_mod.qh>
-#include <server/resources.qh>
 #include <server/round_handler.qh>
 #include <server/weapons/selection.qh>
 #include <server/world.qh>