From 5ad35ed58c9eb8f52afd13db42f712d308d807df Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 18 Jan 2022 18:02:17 +0000 Subject: [PATCH] Migrating resources (ammo, health etc) to a registry for ease of maintenance and a cleaner codebase. --- qcsrc/client/_mod.inc | 1 - qcsrc/client/_mod.qh | 1 - qcsrc/client/hud/panel/ammo.qc | 10 ++- qcsrc/client/hud/panel/radar.qc | 2 +- qcsrc/client/hud/panel/strafehud.qc | 2 +- qcsrc/client/hud/panel/weapons.qc | 1 + qcsrc/client/resources.qc | 85 ------------------- qcsrc/client/shownames.qc | 2 +- qcsrc/common/_all.inc | 2 + qcsrc/common/_mod.inc | 1 + qcsrc/common/debug.qh | 2 +- qcsrc/common/ent_cs.qc | 6 +- .../gamemode/freezetag/sv_freezetag.qc | 2 +- qcsrc/common/items/item/ammo.qh | 19 +---- qcsrc/common/mutators/mutator/nix/sv_nix.qc | 1 + .../common/mutators/mutator/overkill/okhmg.qh | 2 +- .../mutators/mutator/overkill/okmachinegun.qh | 2 +- .../common/mutators/mutator/overkill/oknex.qh | 2 +- .../common/mutators/mutator/overkill/okrpc.qh | 2 +- .../mutators/mutator/overkill/okshotgun.qh | 2 +- qcsrc/common/notifications/all.qh | 1 + qcsrc/common/resources.qh | 24 ------ qcsrc/common/resources/_mod.inc | 8 ++ qcsrc/common/resources/_mod.qh | 8 ++ qcsrc/common/resources/all.inc | 61 +++++++++++++ qcsrc/common/resources/cl_resources.qc | 52 ++++++++++++ .../resources/cl_resources.qh} | 28 ++---- qcsrc/common/resources/resources.qc | 15 ++++ qcsrc/common/resources/resources.qh | 65 ++++++++++++++ .../resources/sv_resources.qc} | 65 ++++---------- .../resources/sv_resources.qh} | 30 ++----- qcsrc/common/vehicles/sv_vehicles.qc | 2 +- qcsrc/common/weapons/all.qc | 13 +-- qcsrc/common/weapons/weapon.qh | 15 ++-- qcsrc/common/weapons/weapon/arc.qh | 2 +- qcsrc/common/weapons/weapon/blaster.qh | 2 +- qcsrc/common/weapons/weapon/crylink.qh | 2 +- qcsrc/common/weapons/weapon/devastator.qh | 2 +- qcsrc/common/weapons/weapon/electro.qh | 2 +- qcsrc/common/weapons/weapon/fireball.qh | 2 +- qcsrc/common/weapons/weapon/hagar.qh | 2 +- qcsrc/common/weapons/weapon/hlac.qh | 2 +- qcsrc/common/weapons/weapon/hook.qh | 2 +- qcsrc/common/weapons/weapon/machinegun.qh | 2 +- qcsrc/common/weapons/weapon/minelayer.qh | 2 +- qcsrc/common/weapons/weapon/mortar.qh | 2 +- qcsrc/common/weapons/weapon/porto.qh | 2 +- qcsrc/common/weapons/weapon/rifle.qh | 2 +- qcsrc/common/weapons/weapon/seeker.qh | 2 +- qcsrc/common/weapons/weapon/shockwave.qh | 2 +- qcsrc/common/weapons/weapon/shotgun.qh | 2 +- qcsrc/common/weapons/weapon/vaporizer.qh | 2 +- qcsrc/common/weapons/weapon/vortex.qh | 2 +- qcsrc/server/_mod.inc | 1 - qcsrc/server/_mod.qh | 1 - qcsrc/server/bot/default/havocbot/roles.qc | 2 +- qcsrc/server/cheats.qc | 2 +- qcsrc/server/client.qc | 4 +- qcsrc/server/client.qh | 4 +- qcsrc/server/compat/quake3.qc | 2 +- qcsrc/server/damage.qc | 2 +- qcsrc/server/items/items.qc | 5 +- qcsrc/server/items/items.qh | 3 +- qcsrc/server/mutators/events.qh | 26 +++--- qcsrc/server/weapons/spawning.qc | 3 +- qcsrc/server/weapons/throwing.qc | 4 +- qcsrc/server/weapons/weaponsystem.qc | 2 +- 67 files changed, 335 insertions(+), 298 deletions(-) delete mode 100644 qcsrc/client/resources.qc delete mode 100644 qcsrc/common/resources.qh create mode 100644 qcsrc/common/resources/_mod.inc create mode 100644 qcsrc/common/resources/_mod.qh create mode 100644 qcsrc/common/resources/all.inc create mode 100644 qcsrc/common/resources/cl_resources.qc rename qcsrc/{client/resources.qh => common/resources/cl_resources.qh} (62%) create mode 100644 qcsrc/common/resources/resources.qc create mode 100644 qcsrc/common/resources/resources.qh rename qcsrc/{server/resources.qc => common/resources/sv_resources.qc} (71%) rename qcsrc/{server/resources.qh => common/resources/sv_resources.qh} (77%) diff --git a/qcsrc/client/_mod.inc b/qcsrc/client/_mod.inc index 8f56739df..8a25226ab 100644 --- a/qcsrc/client/_mod.inc +++ b/qcsrc/client/_mod.inc @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include diff --git a/qcsrc/client/_mod.qh b/qcsrc/client/_mod.qh index 5f82413c4..d17165d3d 100644 --- a/qcsrc/client/_mod.qh +++ b/qcsrc/client/_mod.qh @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include diff --git a/qcsrc/client/hud/panel/ammo.qc b/qcsrc/client/hud/panel/ammo.qc index b4a7b6040..0cc1f2395 100644 --- a/qcsrc/client/hud/panel/ammo.qc +++ b/qcsrc/client/hud/panel/ammo.qc @@ -4,6 +4,7 @@ #include #include #include +#include #include // 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, diff --git a/qcsrc/client/hud/panel/radar.qc b/qcsrc/client/hud/panel/radar.qc index f4bae2024..ef209633b 100644 --- a/qcsrc/client/hud/panel/radar.qc +++ b/qcsrc/client/hud/panel/radar.qc @@ -2,10 +2,10 @@ #include #include -#include #include #include #include +#include // Radar (#6) diff --git a/qcsrc/client/hud/panel/strafehud.qc b/qcsrc/client/hud/panel/strafehud.qc index 5ddc30d23..e4e339c44 100644 --- a/qcsrc/client/hud/panel/strafehud.qc +++ b/qcsrc/client/hud/panel/strafehud.qc @@ -4,13 +4,13 @@ #include #include -#include #include #include #include #include #include #include +#include #include // StrafeHUD (#25) diff --git a/qcsrc/client/hud/panel/weapons.qc b/qcsrc/client/hud/panel/weapons.qc index a79b64c40..b51c5761d 100644 --- a/qcsrc/client/hud/panel/weapons.qc +++ b/qcsrc/client/hud/panel/weapons.qc @@ -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 index 5408872b4..000000000 --- a/qcsrc/client/resources.qc +++ /dev/null @@ -1,85 +0,0 @@ -#include "resources.qh" - -#include - -/// \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/shownames.qc b/qcsrc/client/shownames.qc index 27157a5a1..3f0688d61 100644 --- a/qcsrc/client/shownames.qc +++ b/qcsrc/client/shownames.qc @@ -2,11 +2,11 @@ #include #include -#include #include #include #include #include +#include #include #include diff --git a/qcsrc/common/_all.inc b/qcsrc/common/_all.inc index fa80064c9..0a2cca157 100644 --- a/qcsrc/common/_all.inc +++ b/qcsrc/common/_all.inc @@ -49,3 +49,5 @@ noref float autocvar_net_connecttimeout = 30; #include "mutators/_mod.inc" #include "gamemodes/_mod.inc" + +#include "resources/_mod.inc" diff --git a/qcsrc/common/_mod.inc b/qcsrc/common/_mod.inc index 4a45c1edb..84d6789c7 100644 --- a/qcsrc/common/_mod.inc +++ b/qcsrc/common/_mod.inc @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include diff --git a/qcsrc/common/debug.qh b/qcsrc/common/debug.qh index e63a7f04f..ca0e28f04 100644 --- a/qcsrc/common/debug.qh +++ b/qcsrc/common/debug.qh @@ -2,8 +2,8 @@ #ifdef CSQC #include -#include #include +#include #endif diff --git a/qcsrc/common/ent_cs.qc b/qcsrc/common/ent_cs.qc index fb2f9d5d3..536637145 100644 --- a/qcsrc/common/ent_cs.qc +++ b/qcsrc/common/ent_cs.qc @@ -2,12 +2,12 @@ #if defined(CSQC) #include - #include + #include #elif defined(MENUQC) #elif defined(SVQC) #include - #include - #include + #include + #include #endif REGISTRY(EntCSProps, BITS(16) - 1) diff --git a/qcsrc/common/gamemodes/gamemode/freezetag/sv_freezetag.qc b/qcsrc/common/gamemodes/gamemode/freezetag/sv_freezetag.qc index 58fd90c89..4c50abb46 100644 --- a/qcsrc/common/gamemodes/gamemode/freezetag/sv_freezetag.qc +++ b/qcsrc/common/gamemodes/gamemode/freezetag/sv_freezetag.qc @@ -1,7 +1,7 @@ #include "sv_freezetag.qh" +#include #include -#include float autocvar_g_freezetag_frozen_maxtime; float autocvar_g_freezetag_revive_clearspeed; diff --git a/qcsrc/common/items/item/ammo.qh b/qcsrc/common/items/item/ammo.qh index 02857d8ae..bf22a7e81 100644 --- a/qcsrc/common/items/item/ammo.qh +++ b/qcsrc/common/items/item/ammo.qh @@ -2,25 +2,10 @@ #include "pickup.qh" #include +#include #ifdef SVQC - #include + #include #include - #include -#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 diff --git a/qcsrc/common/mutators/mutator/nix/sv_nix.qc b/qcsrc/common/mutators/mutator/nix/sv_nix.qc index e23d533ed..c53c76eb7 100644 --- a/qcsrc/common/mutators/mutator/nix/sv_nix.qc +++ b/qcsrc/common/mutators/mutator/nix/sv_nix.qc @@ -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); diff --git a/qcsrc/common/mutators/mutator/overkill/okhmg.qh b/qcsrc/common/mutators/mutator/overkill/okhmg.qh index 8a00b4d77..8f597e01b 100644 --- a/qcsrc/common/mutators/mutator/overkill/okhmg.qh +++ b/qcsrc/common/mutators/mutator/overkill/okhmg.qh @@ -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); diff --git a/qcsrc/common/mutators/mutator/overkill/okmachinegun.qh b/qcsrc/common/mutators/mutator/overkill/okmachinegun.qh index 10f3b9c09..7cf072b33 100644 --- a/qcsrc/common/mutators/mutator/overkill/okmachinegun.qh +++ b/qcsrc/common/mutators/mutator/overkill/okmachinegun.qh @@ -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); diff --git a/qcsrc/common/mutators/mutator/overkill/oknex.qh b/qcsrc/common/mutators/mutator/overkill/oknex.qh index 1ffaf78b8..21bbfaa2f 100644 --- a/qcsrc/common/mutators/mutator/overkill/oknex.qh +++ b/qcsrc/common/mutators/mutator/overkill/oknex.qh @@ -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); diff --git a/qcsrc/common/mutators/mutator/overkill/okrpc.qh b/qcsrc/common/mutators/mutator/overkill/okrpc.qh index 6b6763ce7..60c0c9a2d 100644 --- a/qcsrc/common/mutators/mutator/overkill/okrpc.qh +++ b/qcsrc/common/mutators/mutator/overkill/okrpc.qh @@ -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); diff --git a/qcsrc/common/mutators/mutator/overkill/okshotgun.qh b/qcsrc/common/mutators/mutator/overkill/okshotgun.qh index 2c75681d9..e70fc4326 100644 --- a/qcsrc/common/mutators/mutator/overkill/okshotgun.qh +++ b/qcsrc/common/mutators/mutator/overkill/okshotgun.qh @@ -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); diff --git a/qcsrc/common/notifications/all.qh b/qcsrc/common/notifications/all.qh index babadf8c8..17d2047dc 100644 --- a/qcsrc/common/notifications/all.qh +++ b/qcsrc/common/notifications/all.qh @@ -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 index 81f4eb54a..000000000 --- a/qcsrc/common/resources.qh +++ /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 index 000000000..27e682319 --- /dev/null +++ b/qcsrc/common/resources/_mod.inc @@ -0,0 +1,8 @@ +// generated file; do not modify +#include +#ifdef CSQC + #include +#endif +#ifdef SVQC + #include +#endif diff --git a/qcsrc/common/resources/_mod.qh b/qcsrc/common/resources/_mod.qh new file mode 100644 index 000000000..d1ef95f4e --- /dev/null +++ b/qcsrc/common/resources/_mod.qh @@ -0,0 +1,8 @@ +// generated file; do not modify +#include +#ifdef CSQC + #include +#endif +#ifdef SVQC + #include +#endif diff --git a/qcsrc/common/resources/all.inc b/qcsrc/common/resources/all.inc new file mode 100644 index 000000000..51e0bccad --- /dev/null +++ b/qcsrc/common/resources/all.inc @@ -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 index 000000000..fc259005d --- /dev/null +++ b/qcsrc/common/resources/cl_resources.qc @@ -0,0 +1,52 @@ +#include "cl_resources.qh" + +#include +#include + +/// \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/client/resources.qh b/qcsrc/common/resources/cl_resources.qh similarity index 62% rename from qcsrc/client/resources.qh rename to qcsrc/common/resources/cl_resources.qh index 4b0eaa8e7..f03c1dc3d 100644 --- a/qcsrc/client/resources.qh +++ b/qcsrc/common/resources/cl_resources.qh @@ -4,7 +4,7 @@ /// \brief Header file that describes the resource system. /// \copyright GNU GPLv2 or any later version. -#include +#include // ============================ Public API ==================================== @@ -12,28 +12,28 @@ /// \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); +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, int res_type, float amount); +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, int res_type, float amount); +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, int res_type, float amount); +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. @@ -41,20 +41,4 @@ void TakeResource(entity receiver, int res_type, float amount); /// \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; +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 index 000000000..84bb25ab4 --- /dev/null +++ b/qcsrc/common/resources/resources.qc @@ -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 index 000000000..0ecd29da2 --- /dev/null +++ b/qcsrc/common/resources/resources.qh @@ -0,0 +1,65 @@ +#pragma once + +#ifdef SVQC + #include +#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/server/resources.qc b/qcsrc/common/resources/sv_resources.qc similarity index 71% rename from qcsrc/server/resources.qc rename to qcsrc/common/resources/sv_resources.qc index e0b8995f1..9984e9111 100644 --- a/qcsrc/server/resources.qc +++ b/qcsrc/common/resources/sv_resources.qc @@ -1,19 +1,21 @@ -#include "resources.qh" +#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 #include #include -float GetResourceLimit(entity e, int res_type) +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: @@ -71,12 +73,12 @@ float GetResourceLimit(entity e, int res_type) return limit; } -float GetResource(entity e, int res_type) +float GetResource(entity e, Resource res_type) { return e.(GetResourceField(res_type)); } -bool SetResourceExplicit(entity e, int res_type, float amount) +bool SetResourceExplicit(entity e, Resource res_type, float amount) { .float res_field = GetResourceField(res_type); if (e.(res_field) != amount) @@ -87,14 +89,14 @@ bool SetResourceExplicit(entity e, int res_type, float amount) return false; } -void SetResource(entity e, int res_type, float amount) +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, int); + 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; @@ -115,7 +117,7 @@ void SetResource(entity e, int res_type, float amount) MUTATOR_CALLHOOK(ResourceWasted, e, res_type, amount_wasted); } -void GiveResource(entity receiver, int res_type, float amount) +void GiveResource(entity receiver, Resource res_type, float amount) { if (amount <= 0) { @@ -126,13 +128,14 @@ void GiveResource(entity receiver, int res_type, float amount) { return; } - res_type = M_ARGV(1, int); + 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: @@ -158,7 +161,7 @@ void GiveResource(entity receiver, int res_type, float amount) } } -void GiveResourceWithLimit(entity receiver, int res_type, float amount, float limit) +void GiveResourceWithLimit(entity receiver, Resource res_type, float amount, float limit) { if (amount <= 0) { @@ -169,7 +172,7 @@ void GiveResourceWithLimit(entity receiver, int res_type, float amount, float li { return; } - res_type = M_ARGV(1, int); + res_type = M_ARGV(1, entity); amount = M_ARGV(2, float); limit = M_ARGV(3, float); if (amount <= 0) @@ -184,7 +187,7 @@ void GiveResourceWithLimit(entity receiver, int res_type, float amount, float li GiveResource(receiver, res_type, amount); } -void TakeResource(entity receiver, int res_type, float amount) +void TakeResource(entity receiver, Resource res_type, float amount) { if (amount <= 0) { @@ -195,7 +198,7 @@ void TakeResource(entity receiver, int res_type, float amount) { return; } - res_type = M_ARGV(1, int); + res_type = M_ARGV(1, entity); amount = M_ARGV(2, float); if (amount <= 0) { @@ -204,7 +207,7 @@ void TakeResource(entity receiver, int res_type, float amount) SetResource(receiver, res_type, GetResource(receiver, res_type) - amount); } -void TakeResourceWithLimit(entity receiver, int res_type, float amount, float limit) +void TakeResourceWithLimit(entity receiver, Resource res_type, float amount, float limit) { if (amount <= 0) { @@ -215,7 +218,7 @@ void TakeResourceWithLimit(entity receiver, int res_type, float amount, float li { return; } - res_type = M_ARGV(1, int); + res_type = M_ARGV(1, entity); amount = M_ARGV(2, float); limit = M_ARGV(3, float); if (amount <= 0) @@ -229,37 +232,3 @@ void TakeResourceWithLimit(entity receiver, int res_type, float amount, float li } 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/common/resources/sv_resources.qh similarity index 77% rename from qcsrc/server/resources.qh rename to qcsrc/common/resources/sv_resources.qh index 05cb602c3..738501433 100644 --- a/qcsrc/server/resources.qh +++ b/qcsrc/common/resources/sv_resources.qh @@ -5,7 +5,7 @@ /// \author Lyberta /// \copyright GNU GPLv2 or any later version. -#include +#include // TODO: split resources into their own files, registry based float autocvar_g_balance_health_limit; @@ -41,20 +41,20 @@ float autocvar_g_balance_pause_health_rot; /// \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); +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, int res_type); +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, int res_type, float amount); +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. @@ -62,14 +62,14 @@ bool SetResourceExplicit(entity e, int res_type, float amount); /// \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); +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, int res_type, float amount); +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. @@ -77,14 +77,14 @@ void GiveResource(entity receiver, int res_type, float amount); /// \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); +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, int res_type, float amount); +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. @@ -92,16 +92,4 @@ void TakeResource(entity receiver, int res_type, float amount); /// \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); +void TakeResourceWithLimit(entity receiver, Resource res_type, float amount, float limit); diff --git a/qcsrc/common/vehicles/sv_vehicles.qc b/qcsrc/common/vehicles/sv_vehicles.qc index bbecb83da..302b39a0d 100644 --- a/qcsrc/common/vehicles/sv_vehicles.qc +++ b/qcsrc/common/vehicles/sv_vehicles.qc @@ -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); diff --git a/qcsrc/common/weapons/all.qc b/qcsrc/common/weapons/all.qc index 7ef3cc1e8..e1efeb02e 100644 --- a/qcsrc/common/weapons/all.qc +++ b/qcsrc/common/weapons/all.qc @@ -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) { diff --git a/qcsrc/common/weapons/weapon.qh b/qcsrc/common/weapons/weapon.qh index 83f3f4a0f..ec6e14eb6 100644 --- a/qcsrc/common/weapons/weapon.qh +++ b/qcsrc/common/weapons/weapon.qh @@ -1,7 +1,7 @@ #pragma once -#include #include +#include #include #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); diff --git a/qcsrc/common/weapons/weapon/arc.qh b/qcsrc/common/weapons/weapon/arc.qh index 6db349889..15a2cb772 100644 --- a/qcsrc/common/weapons/weapon/arc.qh +++ b/qcsrc/common/weapons/weapon/arc.qh @@ -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); diff --git a/qcsrc/common/weapons/weapon/blaster.qh b/qcsrc/common/weapons/weapon/blaster.qh index ed966cf2f..d768abfaf 100644 --- a/qcsrc/common/weapons/weapon/blaster.qh +++ b/qcsrc/common/weapons/weapon/blaster.qh @@ -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); diff --git a/qcsrc/common/weapons/weapon/crylink.qh b/qcsrc/common/weapons/weapon/crylink.qh index 501b87822..2329c364e 100644 --- a/qcsrc/common/weapons/weapon/crylink.qh +++ b/qcsrc/common/weapons/weapon/crylink.qh @@ -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); diff --git a/qcsrc/common/weapons/weapon/devastator.qh b/qcsrc/common/weapons/weapon/devastator.qh index 11481c6f9..70c72f52c 100644 --- a/qcsrc/common/weapons/weapon/devastator.qh +++ b/qcsrc/common/weapons/weapon/devastator.qh @@ -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); diff --git a/qcsrc/common/weapons/weapon/electro.qh b/qcsrc/common/weapons/weapon/electro.qh index 6417243b2..e4263403b 100644 --- a/qcsrc/common/weapons/weapon/electro.qh +++ b/qcsrc/common/weapons/weapon/electro.qh @@ -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); diff --git a/qcsrc/common/weapons/weapon/fireball.qh b/qcsrc/common/weapons/weapon/fireball.qh index dc59a109c..c3dd73a2e 100644 --- a/qcsrc/common/weapons/weapon/fireball.qh +++ b/qcsrc/common/weapons/weapon/fireball.qh @@ -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); diff --git a/qcsrc/common/weapons/weapon/hagar.qh b/qcsrc/common/weapons/weapon/hagar.qh index d9df8485f..5a43d84ef 100644 --- a/qcsrc/common/weapons/weapon/hagar.qh +++ b/qcsrc/common/weapons/weapon/hagar.qh @@ -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); diff --git a/qcsrc/common/weapons/weapon/hlac.qh b/qcsrc/common/weapons/weapon/hlac.qh index 5ff0e2b30..ec07fa35a 100644 --- a/qcsrc/common/weapons/weapon/hlac.qh +++ b/qcsrc/common/weapons/weapon/hlac.qh @@ -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); diff --git a/qcsrc/common/weapons/weapon/hook.qh b/qcsrc/common/weapons/weapon/hook.qh index 385fab4d6..25b1be507 100644 --- a/qcsrc/common/weapons/weapon/hook.qh +++ b/qcsrc/common/weapons/weapon/hook.qh @@ -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); diff --git a/qcsrc/common/weapons/weapon/machinegun.qh b/qcsrc/common/weapons/weapon/machinegun.qh index acf1668d7..9a2adf46c 100644 --- a/qcsrc/common/weapons/weapon/machinegun.qh +++ b/qcsrc/common/weapons/weapon/machinegun.qh @@ -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); diff --git a/qcsrc/common/weapons/weapon/minelayer.qh b/qcsrc/common/weapons/weapon/minelayer.qh index b34ef9dd4..a574510f5 100644 --- a/qcsrc/common/weapons/weapon/minelayer.qh +++ b/qcsrc/common/weapons/weapon/minelayer.qh @@ -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); diff --git a/qcsrc/common/weapons/weapon/mortar.qh b/qcsrc/common/weapons/weapon/mortar.qh index 97ee20791..118e5c5f0 100644 --- a/qcsrc/common/weapons/weapon/mortar.qh +++ b/qcsrc/common/weapons/weapon/mortar.qh @@ -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); diff --git a/qcsrc/common/weapons/weapon/porto.qh b/qcsrc/common/weapons/weapon/porto.qh index 6c1a6e7f2..757386b5c 100644 --- a/qcsrc/common/weapons/weapon/porto.qh +++ b/qcsrc/common/weapons/weapon/porto.qh @@ -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); diff --git a/qcsrc/common/weapons/weapon/rifle.qh b/qcsrc/common/weapons/weapon/rifle.qh index 7a2348af7..e5a2cde2b 100644 --- a/qcsrc/common/weapons/weapon/rifle.qh +++ b/qcsrc/common/weapons/weapon/rifle.qh @@ -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); diff --git a/qcsrc/common/weapons/weapon/seeker.qh b/qcsrc/common/weapons/weapon/seeker.qh index 3e79ce252..d3024a436 100644 --- a/qcsrc/common/weapons/weapon/seeker.qh +++ b/qcsrc/common/weapons/weapon/seeker.qh @@ -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); diff --git a/qcsrc/common/weapons/weapon/shockwave.qh b/qcsrc/common/weapons/weapon/shockwave.qh index 8b1cd48ef..9fa484b6a 100644 --- a/qcsrc/common/weapons/weapon/shockwave.qh +++ b/qcsrc/common/weapons/weapon/shockwave.qh @@ -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); diff --git a/qcsrc/common/weapons/weapon/shotgun.qh b/qcsrc/common/weapons/weapon/shotgun.qh index d99a371f3..5b200ed58 100644 --- a/qcsrc/common/weapons/weapon/shotgun.qh +++ b/qcsrc/common/weapons/weapon/shotgun.qh @@ -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); diff --git a/qcsrc/common/weapons/weapon/vaporizer.qh b/qcsrc/common/weapons/weapon/vaporizer.qh index 00dbf78ec..c34062a6b 100644 --- a/qcsrc/common/weapons/weapon/vaporizer.qh +++ b/qcsrc/common/weapons/weapon/vaporizer.qh @@ -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); diff --git a/qcsrc/common/weapons/weapon/vortex.qh b/qcsrc/common/weapons/weapon/vortex.qh index 040374f4c..babbfe51b 100644 --- a/qcsrc/common/weapons/weapon/vortex.qh +++ b/qcsrc/common/weapons/weapon/vortex.qh @@ -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); diff --git a/qcsrc/server/_mod.inc b/qcsrc/server/_mod.inc index 34ca1e2c8..c82e892f7 100644 --- a/qcsrc/server/_mod.inc +++ b/qcsrc/server/_mod.inc @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include diff --git a/qcsrc/server/_mod.qh b/qcsrc/server/_mod.qh index c99753826..52574efec 100644 --- a/qcsrc/server/_mod.qh +++ b/qcsrc/server/_mod.qh @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include diff --git a/qcsrc/server/bot/default/havocbot/roles.qc b/qcsrc/server/bot/default/havocbot/roles.qc index 87f7bc0d0..52aff186a 100644 --- a/qcsrc/server/bot/default/havocbot/roles.qc +++ b/qcsrc/server/bot/default/havocbot/roles.qc @@ -1,5 +1,6 @@ #include "roles.qh" +#include #include #include #include @@ -11,7 +12,6 @@ #include #include #include -#include void havocbot_goalrating_waypoints(entity this, float ratingscale, vector org, float sradius) { diff --git a/qcsrc/server/cheats.qc b/qcsrc/server/cheats.qc index 6091c5344..9ec7cc69a 100644 --- a/qcsrc/server/cheats.qc +++ b/qcsrc/server/cheats.qc @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -26,7 +27,6 @@ #include #include #include -#include #include #ifdef NOCHEATS diff --git a/qcsrc/server/client.qc b/qcsrc/server/client.qc index edefc0d28..421a1eb55 100644 --- a/qcsrc/server/client.qc +++ b/qcsrc/server/client.qc @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -65,7 +66,6 @@ #include #include #include -#include #include #include #include @@ -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) { diff --git a/qcsrc/server/client.qh b/qcsrc/server/client.qh index b3ba22abd..b2cf8edb7 100644 --- a/qcsrc/server/client.qh +++ b/qcsrc/server/client.qh @@ -2,6 +2,7 @@ #include "utils.qh" #include +//#include #include #include @@ -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); diff --git a/qcsrc/server/compat/quake3.qc b/qcsrc/server/compat/quake3.qc index ac2409cc0..911ab0f81 100644 --- a/qcsrc/server/compat/quake3.qc +++ b/qcsrc/server/compat/quake3.qc @@ -9,13 +9,13 @@ #include #include #include +#include #include #include #include #include #include #include -#include #include /*********************** diff --git a/qcsrc/server/damage.qc b/qcsrc/server/damage.qc index 7a614bc87..969423bfb 100644 --- a/qcsrc/server/damage.qc +++ b/qcsrc/server/damage.qc @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -31,7 +32,6 @@ #include #include #include -#include #include #include #include diff --git a/qcsrc/server/items/items.qc b/qcsrc/server/items/items.qc index ade4795c5..0ea10da5e 100644 --- a/qcsrc/server/items/items.qc +++ b/qcsrc/server/items/items.qc @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -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; diff --git a/qcsrc/server/items/items.qh b/qcsrc/server/items/items.qh index dc3898323..dff9ccda2 100644 --- a/qcsrc/server/items/items.qh +++ b/qcsrc/server/items/items.qh @@ -1,5 +1,6 @@ #pragma once +#include #include 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); diff --git a/qcsrc/server/mutators/events.qh b/qcsrc/server/mutators/events.qh index ee5d18a69..abda2bda3 100644 --- a/qcsrc/server/mutators/events.qh +++ b/qcsrc/server/mutators/events.qh @@ -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/weapons/spawning.qc b/qcsrc/server/weapons/spawning.qc index 810cc2638..30a2869f3 100644 --- a/qcsrc/server/weapons/spawning.qc +++ b/qcsrc/server/weapons/spawning.qc @@ -1,10 +1,10 @@ #include "spawning.qh" +#include #include #include #include #include -#include #include #include @@ -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; diff --git a/qcsrc/server/weapons/throwing.qc b/qcsrc/server/weapons/throwing.qc index 66b62c6e2..719b59935 100644 --- a/qcsrc/server/weapons/throwing.qc +++ b/qcsrc/server/weapons/throwing.qc @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -13,7 +14,6 @@ #include #include #include -#include #include #include #include @@ -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); diff --git a/qcsrc/server/weapons/weaponsystem.qc b/qcsrc/server/weapons/weaponsystem.qc index 200e6a3bd..fcce2a23d 100644 --- a/qcsrc/server/weapons/weaponsystem.qc +++ b/qcsrc/server/weapons/weaponsystem.qc @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -21,7 +22,6 @@ #include #include #include -#include #include #include #include -- 2.39.2