From 274359abdba7e814a0b404e9bc2e230869e7ffe8 Mon Sep 17 00:00:00 2001 From: Mario Date: Sat, 16 Jun 2018 23:44:51 +1000 Subject: [PATCH] Clear out most references to the .ammo_* fields --- qcsrc/common/items/item/ammo.qh | 23 ++-- qcsrc/common/items/item/jetpack.qh | 8 +- .../common/mutators/mutator/instagib/items.qh | 4 +- qcsrc/common/physics/player.qc | 2 +- qcsrc/common/t_items.qc | 121 +++++++++++------- qcsrc/common/t_items.qh | 3 + qcsrc/common/weapons/weapon/hook.qc | 8 +- qcsrc/common/weapons/weapon/vaporizer.qc | 4 +- qcsrc/server/bot/default/havocbot/havocbot.qc | 2 +- qcsrc/server/bot/default/havocbot/roles.qc | 10 +- qcsrc/server/bot/default/navigation.qc | 4 +- qcsrc/server/client.qc | 18 +-- qcsrc/server/compat/quake3.qc | 12 +- qcsrc/server/resources.qc | 16 ++- qcsrc/server/resources.qh | 7 + 15 files changed, 146 insertions(+), 96 deletions(-) diff --git a/qcsrc/common/items/item/ammo.qh b/qcsrc/common/items/item/ammo.qh index 7c5c12af7..c7b3e0a6c 100644 --- a/qcsrc/common/items/item/ammo.qh +++ b/qcsrc/common/items/item/ammo.qh @@ -3,8 +3,10 @@ #include "pickup.qh" #ifdef SVQC #include + #include #endif +#if 1 .int ammo_none; .int ammo_shells; .int ammo_nails; @@ -17,6 +19,7 @@ .int ammo_plasma; .int ammo_fuel; #endif +#endif #ifdef SVQC PROPERTY(float, g_pickup_ammo_anyway); @@ -40,8 +43,8 @@ MODEL(Bullets_ITEM, Item_Model("a_bullets.mdl")); PROPERTY(int, g_pickup_nails); void ammo_bullets_init(Pickup this, entity item) { - if(!item.ammo_nails) - item.ammo_nails = g_pickup_nails; + if(!GetResourceAmount(item, RESOURCE_BULLETS)) + SetResourceAmountExplicit(item, RESOURCE_BULLETS, g_pickup_nails); } #endif @@ -74,8 +77,8 @@ MODEL(Cells_ITEM, Item_Model("a_cells.md3")); PROPERTY(int, g_pickup_cells); void ammo_cells_init(Pickup this, entity item) { - if(!item.ammo_cells) - item.ammo_cells = g_pickup_cells; + if(!GetResourceAmount(item, RESOURCE_CELLS)) + SetResourceAmountExplicit(item, RESOURCE_CELLS, g_pickup_cells); } #endif REGISTER_ITEM(Cells, Ammo) { @@ -104,8 +107,8 @@ MODEL(Plasma_ITEM, Item_Model("a_cells.md3")); PROPERTY(int, g_pickup_plasma); void ammo_plasma_init(Pickup this, entity item) { - if(!item.ammo_plasma) - item.ammo_plasma = g_pickup_plasma; + if(!GetResourceAmount(item, RESOURCE_PLASMA)) + SetResourceAmountExplicit(item, RESOURCE_PLASMA, g_pickup_plasma); } #endif REGISTER_ITEM(Plasma, Ammo) { @@ -134,8 +137,8 @@ MODEL(Rockets_ITEM, Item_Model("a_rockets.md3")); PROPERTY(int, g_pickup_rockets); void ammo_rockets_init(Pickup this, entity item) { - if(!item.ammo_rockets) - item.ammo_rockets = g_pickup_rockets; + if(!GetResourceAmount(item, RESOURCE_ROCKETS)) + SetResourceAmountExplicit(item, RESOURCE_ROCKETS, g_pickup_rockets); } #endif REGISTER_ITEM(Rockets, Ammo) { @@ -164,8 +167,8 @@ MODEL(Shells_ITEM, Item_Model("a_shells.md3")); PROPERTY(int, g_pickup_shells); void ammo_shells_init(Pickup this, entity item) { - if(!item.ammo_shells) - item.ammo_shells = g_pickup_shells; + if(!GetResourceAmount(item, RESOURCE_SHELLS)) + SetResourceAmountExplicit(item, RESOURCE_SHELLS, g_pickup_shells); } #endif diff --git a/qcsrc/common/items/item/jetpack.qh b/qcsrc/common/items/item/jetpack.qh index c56d682fe..e03c1ae6d 100644 --- a/qcsrc/common/items/item/jetpack.qh +++ b/qcsrc/common/items/item/jetpack.qh @@ -19,8 +19,8 @@ MODEL(Jetpack_ITEM, Item_Model("g_jetpack.md3")); PROPERTY(int, g_pickup_fuel_jetpack); void powerup_jetpack_init(Pickup this, entity item) { - if(!item.ammo_fuel) - item.ammo_fuel = g_pickup_fuel_jetpack; + if(!GetResourceAmount(item, RESOURCE_FUEL)) + SetResourceAmountExplicit(item, RESOURCE_FUEL, g_pickup_fuel_jetpack); } #endif @@ -57,8 +57,8 @@ MODEL(JetpackFuel_ITEM, Item_Model("g_fuel.md3")); PROPERTY(int, g_pickup_fuel); void ammo_fuel_init(Pickup this, entity item) { - if(!item.ammo_fuel) - item.ammo_fuel = g_pickup_fuel; + if(!GetResourceAmount(item, RESOURCE_FUEL)) + SetResourceAmountExplicit(item, RESOURCE_FUEL, g_pickup_fuel); } #endif REGISTER_ITEM(JetpackFuel, Ammo) { diff --git a/qcsrc/common/mutators/mutator/instagib/items.qh b/qcsrc/common/mutators/mutator/instagib/items.qh index 95f4f3210..3f8d08716 100644 --- a/qcsrc/common/mutators/mutator/instagib/items.qh +++ b/qcsrc/common/mutators/mutator/instagib/items.qh @@ -18,8 +18,8 @@ SOUND(VaporizerCells, Item_Sound("itempickup")); int autocvar_g_instagib_ammo_drop; void ammo_vaporizercells_init(Pickup this, entity item) { - if(!item.ammo_cells) - item.ammo_cells = autocvar_g_instagib_ammo_drop; + if(!GetResourceAmount(item, RESOURCE_CELLS)) + SetResourceAmountExplicit(item, RESOURCE_CELLS, autocvar_g_instagib_ammo_drop); } #endif REGISTER_ITEM(VaporizerCells, Ammo) { diff --git a/qcsrc/common/physics/player.qc b/qcsrc/common/physics/player.qc index 2b9808a55..2bfc80bd0 100644 --- a/qcsrc/common/physics/player.qc +++ b/qcsrc/common/physics/player.qc @@ -792,7 +792,7 @@ void PM_jetpack(entity this, float maxspd_mod, float dt) #ifdef SVQC if (!(ITEMS_STAT(this) & IT_UNLIMITED_WEAPON_AMMO)) - this.ammo_fuel -= PHYS_JETPACK_FUEL(this) * dt * fvel * f; + SetResourceAmountExplicit(this, RESOURCE_FUEL, GetResourceAmount(this, RESOURCE_FUEL) - PHYS_JETPACK_FUEL(this) * dt * fvel * f); ITEMS_STAT(this) |= IT_USING_JETPACK; diff --git a/qcsrc/common/t_items.qc b/qcsrc/common/t_items.qc index a518348a2..2e0eb0e90 100644 --- a/qcsrc/common/t_items.qc +++ b/qcsrc/common/t_items.qc @@ -1071,12 +1071,12 @@ float ammo_pickupevalfunc(entity player, entity item) if(item.itemdef.instanceOfWeaponPickup) { entity ammo = NULL; - if(item.ammo_shells) { need_shells = true; ammo = ITEM_Shells; } - else if(item.ammo_nails) { need_nails = true; ammo = ITEM_Bullets; } - else if(item.ammo_rockets) { need_rockets = true; ammo = ITEM_Rockets; } - else if(item.ammo_cells) { need_cells = true; ammo = ITEM_Cells; } - else if(item.ammo_plasma) { need_plasma = true; ammo = ITEM_Plasma; } - else if(item.ammo_fuel) { need_fuel = true; ammo = ITEM_JetpackFuel; } + if(GetResourceAmount(item, RESOURCE_SHELLS)) { need_shells = true; ammo = ITEM_Shells; } + else if(GetResourceAmount(item, RESOURCE_BULLETS)) { need_nails = true; ammo = ITEM_Bullets; } + else if(GetResourceAmount(item, RESOURCE_ROCKETS)) { need_rockets = true; ammo = ITEM_Rockets; } + else if(GetResourceAmount(item, RESOURCE_CELLS)) { need_cells = true; ammo = ITEM_Cells; } + else if(GetResourceAmount(item, RESOURCE_PLASMA)) { need_plasma = true; ammo = ITEM_Plasma; } + else if(GetResourceAmount(item, RESOURCE_FUEL)) { need_fuel = true; ammo = ITEM_JetpackFuel; } if(!ammo) return 0; @@ -1104,23 +1104,23 @@ float ammo_pickupevalfunc(entity player, entity item) float noammorating = 0.5; - if ((need_shells) && (item.ammo_shells) && (GetResourceAmount(player, RESOURCE_SHELLS) < g_pickup_shells_max)) - c = item.ammo_shells / max(noammorating, GetResourceAmount(player, RESOURCE_SHELLS)); + if ((need_shells) && GetResourceAmount(item, RESOURCE_SHELLS) && (GetResourceAmount(player, RESOURCE_SHELLS) < g_pickup_shells_max)) + c = GetResourceAmount(item, RESOURCE_SHELLS) / max(noammorating, GetResourceAmount(player, RESOURCE_SHELLS)); - if ((need_nails) && (item.ammo_nails) && (GetResourceAmount(player, RESOURCE_BULLETS) < g_pickup_nails_max)) - c = item.ammo_nails / max(noammorating, GetResourceAmount(player, RESOURCE_BULLETS)); + if ((need_nails) && GetResourceAmount(item, RESOURCE_BULLETS) && (GetResourceAmount(player, RESOURCE_BULLETS) < g_pickup_nails_max)) + c = GetResourceAmount(item, RESOURCE_BULLETS) / max(noammorating, GetResourceAmount(player, RESOURCE_BULLETS)); - if ((need_rockets) && (item.ammo_rockets) && (GetResourceAmount(player, RESOURCE_ROCKETS) < g_pickup_rockets_max)) - c = item.ammo_rockets / max(noammorating, GetResourceAmount(player, RESOURCE_ROCKETS)); + if ((need_rockets) && GetResourceAmount(item, RESOURCE_ROCKETS) && (GetResourceAmount(player, RESOURCE_ROCKETS) < g_pickup_rockets_max)) + c = GetResourceAmount(item, RESOURCE_ROCKETS) / max(noammorating, GetResourceAmount(player, RESOURCE_ROCKETS)); - if ((need_cells) && (item.ammo_cells) && (GetResourceAmount(player, RESOURCE_CELLS) < g_pickup_cells_max)) - c = item.ammo_cells / max(noammorating, GetResourceAmount(player, RESOURCE_CELLS)); + if ((need_cells) && GetResourceAmount(item, RESOURCE_CELLS) && (GetResourceAmount(player, RESOURCE_CELLS) < g_pickup_cells_max)) + c = GetResourceAmount(item, RESOURCE_CELLS) / max(noammorating, GetResourceAmount(player, RESOURCE_CELLS)); - if ((need_plasma) && (item.ammo_plasma) && (GetResourceAmount(player, RESOURCE_PLASMA) < g_pickup_plasma_max)) - c = item.ammo_plasma / max(noammorating, GetResourceAmount(player, RESOURCE_PLASMA)); + if ((need_plasma) && GetResourceAmount(item, RESOURCE_PLASMA) && (GetResourceAmount(player, RESOURCE_PLASMA) < g_pickup_plasma_max)) + c = GetResourceAmount(item, RESOURCE_PLASMA) / max(noammorating, GetResourceAmount(player, RESOURCE_PLASMA)); - if ((need_fuel) && (item.ammo_fuel) && (GetResourceAmount(player, RESOURCE_FUEL) < g_pickup_fuel_max)) - c = item.ammo_fuel / max(noammorating, GetResourceAmount(player, RESOURCE_FUEL)); + if ((need_fuel) && GetResourceAmount(item, RESOURCE_FUEL) && (GetResourceAmount(player, RESOURCE_FUEL) < g_pickup_fuel_max)) + c = GetResourceAmount(item, RESOURCE_FUEL) / max(noammorating, GetResourceAmount(player, RESOURCE_FUEL)); rating *= min(c, 2); if(wpn) @@ -1555,12 +1555,12 @@ spawnfunc(target_items) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, this.superweapons_finished * boolean(this.items & IT_SUPERWEAPON), "superweapons"); this.netname = sprintf("%s %s%d %s", this.netname, itemprefix, boolean(this.items & ITEM_Jetpack.m_itemid), "jetpack"); this.netname = sprintf("%s %s%d %s", this.netname, itemprefix, boolean(this.items & ITEM_JetpackRegen.m_itemid), "fuel_regen"); - if(this.ammo_shells != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, this.ammo_shells), "shells"); - if(this.ammo_nails != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, this.ammo_nails), "nails"); - if(this.ammo_rockets != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, this.ammo_rockets), "rockets"); - if(this.ammo_cells != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, this.ammo_cells), "cells"); - if(this.ammo_plasma != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, this.ammo_plasma), "plasma"); - if(this.ammo_fuel != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, this.ammo_fuel), "fuel"); + if(GetResourceAmount(this, RESOURCE_SHELLS) != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, GetResourceAmount(this, RESOURCE_SHELLS)), "shells"); + if(GetResourceAmount(this, RESOURCE_BULLETS) != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, GetResourceAmount(this, RESOURCE_BULLETS)), "nails"); + if(GetResourceAmount(this, RESOURCE_ROCKETS) != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, GetResourceAmount(this, RESOURCE_ROCKETS)), "rockets"); + if(GetResourceAmount(this, RESOURCE_CELLS) != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, GetResourceAmount(this, RESOURCE_CELLS)), "cells"); + if(GetResourceAmount(this, RESOURCE_PLASMA) != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, GetResourceAmount(this, RESOURCE_PLASMA)), "plasma"); + if(GetResourceAmount(this, RESOURCE_FUEL) != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, GetResourceAmount(this, RESOURCE_FUEL)), "fuel"); if(this.health != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, this.health), "health"); if(this.armorvalue != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, this.armorvalue), "armor"); FOREACH(Buffs, it != BUFF_Null, this.netname = sprintf("%s %s%d %s", this.netname, itemprefix, !!(STAT(BUFFS, this) & (it.m_itemid)), it.m_name)); @@ -1662,6 +1662,31 @@ 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 resource_type, int op, int val) +{ + int v0 = GetResourceAmount(e, resource_type); + switch (op) + { + case OP_SET: + SetResourceAmount(e, resource_type, val); + break; + case OP_MIN: + SetResourceAmount(e, resource_type, max(v0, val)); // min 100 cells = at least 100 cells + break; + case OP_MAX: + SetResourceAmount(e, resource_type, min(v0, val)); + break; + case OP_PLUS: + SetResourceAmount(e, resource_type, v0 + val); + break; + case OP_MINUS: + SetResourceAmount(e, resource_type, v0 - val); + break; + } + int v1 = GetResourceAmount(e, resource_type); + return v0 != v1; +} + float GiveItems(entity e, float beginarg, float endarg) { float got, i, val, op; @@ -1694,12 +1719,12 @@ float GiveItems(entity e, float beginarg, float endarg) PREGIVE(e, strength_finished); PREGIVE(e, invincible_finished); PREGIVE(e, superweapons_finished); - PREGIVE(e, ammo_nails); - PREGIVE(e, ammo_cells); - PREGIVE(e, ammo_plasma); - PREGIVE(e, ammo_shells); - PREGIVE(e, ammo_rockets); - PREGIVE(e, ammo_fuel); + PREGIVE_RESOURCE(e, RESOURCE_BULLETS); + PREGIVE_RESOURCE(e, RESOURCE_CELLS); + PREGIVE_RESOURCE(e, RESOURCE_PLASMA); + PREGIVE_RESOURCE(e, RESOURCE_SHELLS); + PREGIVE_RESOURCE(e, RESOURCE_ROCKETS); + PREGIVE_RESOURCE(e, RESOURCE_FUEL); PREGIVE(e, armorvalue); PREGIVE(e, health); @@ -1745,12 +1770,12 @@ float GiveItems(entity e, float beginarg, float endarg) //case "allbuffs": // all buffs makes a player god, do not want! //FOREACH(Buffs, it != BUFF_Null, got += GiveBuff(e, it.m_itemid, op, val)); case "allammo": - got += GiveValue(e, ammo_cells, op, val); - got += GiveValue(e, ammo_plasma, op, val); - got += GiveValue(e, ammo_shells, op, val); - got += GiveValue(e, ammo_nails, op, val); - got += GiveValue(e, ammo_rockets, op, val); - got += GiveValue(e, ammo_fuel, op, val); + got += GiveResourceValue(e, RESOURCE_CELLS, op, val); + got += GiveResourceValue(e, RESOURCE_PLASMA, op, val); + got += GiveResourceValue(e, RESOURCE_SHELLS, op, val); + got += GiveResourceValue(e, RESOURCE_BULLETS, op, val); + got += GiveResourceValue(e, RESOURCE_ROCKETS, op, val); + got += GiveResourceValue(e, RESOURCE_FUEL, op, val); break; case "unlimited_ammo": got += GiveBit(e, items, IT_UNLIMITED_AMMO, op, val); @@ -1777,20 +1802,20 @@ float GiveItems(entity e, float beginarg, float endarg) got += GiveValue(e, superweapons_finished, op, val); break; case "cells": - got += GiveValue(e, ammo_cells, op, val); + got += GiveResourceValue(e, RESOURCE_CELLS, op, val); break; case "plasma": - got += GiveValue(e, ammo_plasma, op, val); + got += GiveResourceValue(e, RESOURCE_PLASMA, op, val); break; case "shells": - got += GiveValue(e, ammo_shells, op, val); + got += GiveResourceValue(e, RESOURCE_SHELLS, op, val); break; case "nails": case "bullets": - got += GiveValue(e, ammo_nails, op, val); + got += GiveResourceValue(e, RESOURCE_BULLETS, op, val); break; case "rockets": - got += GiveValue(e, ammo_rockets, op, val); + got += GiveResourceValue(e, RESOURCE_ROCKETS, op, val); break; case "health": got += GiveValue(e, health, op, val); @@ -1799,7 +1824,7 @@ float GiveItems(entity e, float beginarg, float endarg) got += GiveValue(e, armorvalue, op, val); break; case "fuel": - got += GiveValue(e, ammo_fuel, op, val); + got += GiveResourceValue(e, RESOURCE_FUEL, op, val); break; default: FOREACH(Buffs, it != BUFF_Null && Buff_UndeprecateName(cmd) == it.m_name, @@ -1830,12 +1855,12 @@ float GiveItems(entity e, float beginarg, float endarg) POSTGIVE_VALUE(e, strength_finished, 1, SND_POWERUP, SND_POWEROFF); POSTGIVE_VALUE(e, invincible_finished, 1, SND_Shield, SND_POWEROFF); //POSTGIVE_VALUE(e, superweapons_finished, 1, SND_Null, SND_Null); - POSTGIVE_VALUE(e, ammo_nails, 0, SND_ITEMPICKUP, SND_Null); - POSTGIVE_VALUE(e, ammo_cells, 0, SND_ITEMPICKUP, SND_Null); - POSTGIVE_VALUE(e, ammo_plasma, 0, SND_ITEMPICKUP, SND_Null); - POSTGIVE_VALUE(e, ammo_shells, 0, SND_ITEMPICKUP, SND_Null); - POSTGIVE_VALUE(e, ammo_rockets, 0, SND_ITEMPICKUP, SND_Null); - POSTGIVE_VALUE_ROT(e, ammo_fuel, 1, pauserotfuel_finished, autocvar_g_balance_pause_fuel_rot, pauseregen_finished, autocvar_g_balance_pause_fuel_regen, SND_ITEMPICKUP, SND_Null); + POSTGIVE_RESOURCE(e, RESOURCE_BULLETS, 0, SND_ITEMPICKUP, SND_Null); + POSTGIVE_RESOURCE(e, RESOURCE_CELLS, 0, SND_ITEMPICKUP, SND_Null); + POSTGIVE_RESOURCE(e, RESOURCE_PLASMA, 0, SND_ITEMPICKUP, SND_Null); + POSTGIVE_RESOURCE(e, RESOURCE_SHELLS, 0, SND_ITEMPICKUP, SND_Null); + POSTGIVE_RESOURCE(e, RESOURCE_ROCKETS, 0, SND_ITEMPICKUP, SND_Null); + POSTGIVE_RESOURCE_ROT(e, RESOURCE_FUEL, 1, pauserotfuel_finished, autocvar_g_balance_pause_fuel_rot, pauseregen_finished, autocvar_g_balance_pause_fuel_regen, SND_ITEMPICKUP, SND_Null); POSTGIVE_VALUE_ROT(e, armorvalue, 1, pauserotarmor_finished, autocvar_g_balance_pause_armor_rot, pauseregen_finished, autocvar_g_balance_pause_health_regen, SND_ARMOR25, SND_Null); POSTGIVE_VALUE_ROT(e, health, 1, pauserothealth_finished, autocvar_g_balance_pause_health_rot, pauseregen_finished, autocvar_g_balance_pause_health_regen, SND_MEGAHEALTH, SND_Null); diff --git a/qcsrc/common/t_items.qh b/qcsrc/common/t_items.qh index 50228a0a8..9fdb0b092 100644 --- a/qcsrc/common/t_items.qh +++ b/qcsrc/common/t_items.qh @@ -128,8 +128,11 @@ spawnfunc(target_items); #define PREGIVE_WEAPONS(e) WepSet save_weapons; save_weapons = STAT(WEAPONS, e) #define PREGIVE(e,f) float save_##f; save_##f = (e).f +#define PREGIVE_RESOURCE(e,f) float save_##f = GetResourceAmount((e), (f)) #define POSTGIVE_WEAPON(e,b,snd_incr,snd_decr) GiveSound((e), !!(save_weapons & WepSet_FromWeapon(b)), !!(STAT(WEAPONS, e) & WepSet_FromWeapon(b)), 0, snd_incr, snd_decr) #define POSTGIVE_BIT(e,f,b,snd_incr,snd_decr) GiveSound((e), save_##f & (b), (e).f & (b), 0, snd_incr, snd_decr) +#define POSTGIVE_RESOURCE(e,f,t,snd_incr,snd_decr) GiveSound((e), save_##f, GetResourceAmount((e), (f)), t, snd_incr, snd_decr) +#define POSTGIVE_RESOURCE_ROT(e,f,t,rotfield,rottime,regenfield,regentime,snd_incr,snd_decr) GiveRot((e),save_##f,GetResourceAmount((e),(f)),rotfield,rottime,regenfield,regentime);GiveSound((e),save_##f,GetResourceAmount((e),(f)),t,snd_incr,snd_decr) #define POSTGIVE_VALUE(e,f,t,snd_incr,snd_decr) GiveSound((e), save_##f, (e).f, t, snd_incr, snd_decr) #define POSTGIVE_VALUE_ROT(e,f,t,rotfield,rottime,regenfield,regentime,snd_incr,snd_decr) GiveRot((e), save_##f, (e).f, rotfield, rottime, regenfield, regentime); GiveSound((e), save_##f, (e).f, t, snd_incr, snd_decr) diff --git a/qcsrc/common/weapons/weapon/hook.qc b/qcsrc/common/weapons/weapon/hook.qc index 985d2ae59..255b30afb 100644 --- a/qcsrc/common/weapons/weapon/hook.qc +++ b/qcsrc/common/weapons/weapon/hook.qc @@ -165,7 +165,7 @@ METHOD(Hook, wr_think, void(entity thiswep, entity actor, .entity weaponentity, { if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO)) { - if( actor.ammo_fuel >= (time - actor.(weaponentity).hook_time_fueldecrease) * hooked_fuel ) + if( GetResourceAmount(actor, RESOURCE_FUEL) >= (time - actor.(weaponentity).hook_time_fueldecrease) * hooked_fuel ) { W_DecreaseAmmo(thiswep, actor, (time - actor.(weaponentity).hook_time_fueldecrease) * hooked_fuel, weaponentity); actor.(weaponentity).hook_time_fueldecrease = time; @@ -173,7 +173,7 @@ METHOD(Hook, wr_think, void(entity thiswep, entity actor, .entity weaponentity, } else { - actor.ammo_fuel = 0; + SetResourceAmount(actor, RESOURCE_FUEL, 0); actor.(weaponentity).hook_state |= HOOK_REMOVING; if(actor.(weaponentity).m_weapon != WEP_Null) // offhand W_SwitchWeapon_Force(actor, w_getbestweapon(actor, weaponentity), weaponentity); @@ -214,9 +214,9 @@ METHOD(Hook, wr_checkammo1, bool(Hook thiswep, entity actor, .entity weaponentit if (!thiswep.ammo_factor) return true; if(actor.(weaponentity).hook) - return actor.ammo_fuel > 0; + return GetResourceAmount(actor, RESOURCE_FUEL) > 0; - return actor.ammo_fuel >= WEP_CVAR_PRI(hook, ammo); + return GetResourceAmount(actor, RESOURCE_FUEL) >= WEP_CVAR_PRI(hook, ammo); } METHOD(Hook, wr_checkammo2, bool(Hook thiswep, entity actor, .entity weaponentity)) { diff --git a/qcsrc/common/weapons/weapon/vaporizer.qc b/qcsrc/common/weapons/weapon/vaporizer.qc index c3baa1212..2dd5cae15 100644 --- a/qcsrc/common/weapons/weapon/vaporizer.qc +++ b/qcsrc/common/weapons/weapon/vaporizer.qc @@ -295,7 +295,7 @@ METHOD(Vaporizer, wr_think, void(entity thiswep, entity actor, .entity weaponent } else if(WEP_CVAR(vaporizer, reload_ammo) && actor.(weaponentity).clip_load < vaporizer_ammo) { // forced reload thiswep.wr_reload(thiswep, actor, weaponentity); } - if((fire & 1) && (actor.ammo_cells || !autocvar_g_rm) && !forbidWeaponUse(actor)) + if((fire & 1) && (GetResourceAmount(actor, RESOURCE_CELLS) || !autocvar_g_rm) && !forbidWeaponUse(actor)) { if(weapon_prepareattack(thiswep, actor, weaponentity, false, WEP_CVAR_PRI(vaporizer, refire))) { @@ -303,7 +303,7 @@ METHOD(Vaporizer, wr_think, void(entity thiswep, entity actor, .entity weaponent weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, WEP_CVAR_PRI(vaporizer, animtime), w_ready); } } - if((fire & 2) || ((fire & 1) && !actor.ammo_cells && autocvar_g_rm)) + if((fire & 2) || ((fire & 1) && !GetResourceAmount(actor, RESOURCE_CELLS) && autocvar_g_rm)) { if((autocvar_g_rm && autocvar_g_rm_laser) || autocvar_g_rm_laser == 2) { diff --git a/qcsrc/server/bot/default/havocbot/havocbot.qc b/qcsrc/server/bot/default/havocbot/havocbot.qc index 91b5c463d..4fc810b74 100644 --- a/qcsrc/server/bot/default/havocbot/havocbot.qc +++ b/qcsrc/server/bot/default/havocbot/havocbot.qc @@ -500,7 +500,7 @@ void havocbot_movetogoal(entity this) // Jetpack navigation if(this.navigation_jetpack_goal) if(this.goalcurrent==this.navigation_jetpack_goal) - if(this.ammo_fuel) + if(GetResourceAmount(this, RESOURCE_FUEL)) { if(autocvar_bot_debug_goalstack) { diff --git a/qcsrc/server/bot/default/havocbot/roles.qc b/qcsrc/server/bot/default/havocbot/roles.qc index 2aa11b52c..d557be654 100644 --- a/qcsrc/server/bot/default/havocbot/roles.qc +++ b/qcsrc/server/bot/default/havocbot/roles.qc @@ -53,11 +53,11 @@ bool havocbot_goalrating_item_can_be_left_to_teammate(entity this, entity player if (item.health && player.health <= this.health) {return true;} if (item.armorvalue && player.armorvalue <= this.armorvalue) {return true;} if (STAT(WEAPONS, item) && !(STAT(WEAPONS, player) & STAT(WEAPONS, item))) {return true;} - if (item.ammo_shells && GetResourceAmount(player, RESOURCE_SHELLS) <= GetResourceAmount(this, RESOURCE_SHELLS)) {return true;} - if (item.ammo_nails && GetResourceAmount(player, RESOURCE_BULLETS) <= GetResourceAmount(this, RESOURCE_BULLETS)) {return true;} - if (item.ammo_rockets && GetResourceAmount(player, RESOURCE_ROCKETS) <= GetResourceAmount(this, RESOURCE_ROCKETS)) {return true;} - if (item.ammo_cells && GetResourceAmount(player, RESOURCE_CELLS) <= GetResourceAmount(this, RESOURCE_CELLS)) {return true;} - if (item.ammo_plasma && GetResourceAmount(player, RESOURCE_PLASMA) <= GetResourceAmount(this, RESOURCE_PLASMA)) {return true;} + if (GetResourceAmount(item, RESOURCE_SHELLS) && GetResourceAmount(player, RESOURCE_SHELLS) <= GetResourceAmount(this, RESOURCE_SHELLS)) {return true;} + if (GetResourceAmount(item, RESOURCE_BULLETS) && GetResourceAmount(player, RESOURCE_BULLETS) <= GetResourceAmount(this, RESOURCE_BULLETS)) {return true;} + if (GetResourceAmount(item, RESOURCE_ROCKETS) && GetResourceAmount(player, RESOURCE_ROCKETS) <= GetResourceAmount(this, RESOURCE_ROCKETS)) {return true;} + if (GetResourceAmount(item, RESOURCE_CELLS) && GetResourceAmount(player, RESOURCE_CELLS) <= GetResourceAmount(this, RESOURCE_CELLS)) {return true;} + if (GetResourceAmount(item, RESOURCE_PLASMA) && GetResourceAmount(player, RESOURCE_PLASMA) <= GetResourceAmount(this, RESOURCE_PLASMA)) {return true;} if (item.itemdef.instanceOfPowerup) {return true;} return false; diff --git a/qcsrc/server/bot/default/navigation.qc b/qcsrc/server/bot/default/navigation.qc index 9c3bae8e7..512d3a206 100644 --- a/qcsrc/server/bot/default/navigation.qc +++ b/qcsrc/server/bot/default/navigation.qc @@ -1315,10 +1315,10 @@ void navigation_routerating(entity this, entity e, float f, float rangebias) t += xydistance / autocvar_g_jetpack_maxspeed_side; fuel = t * autocvar_g_jetpack_fuel * 0.8; - LOG_DEBUG("jetpack ai: required fuel ", ftos(fuel), " this.ammo_fuel ", ftos(this.ammo_fuel)); + LOG_DEBUG("jetpack ai: required fuel ", ftos(fuel), ", have ", ftos(GetResourceAmount(this, RESOURCE_FUEL))); // enough fuel ? - if(this.ammo_fuel>fuel || (this.items & IT_UNLIMITED_WEAPON_AMMO)) + if(GetResourceAmount(this, RESOURCE_FUEL) > fuel || (this.items & IT_UNLIMITED_WEAPON_AMMO)) { // Estimate cost // (as onground costs calculation is mostly based on distances, here we do the same establishing some relationship diff --git a/qcsrc/server/client.qc b/qcsrc/server/client.qc index 93d037aad..22287db9b 100644 --- a/qcsrc/server/client.qc +++ b/qcsrc/server/client.qc @@ -1746,7 +1746,9 @@ void player_regen(entity this) minf = autocvar_g_balance_fuel_regenstable; limitf = GetResourceLimit(this, RESOURCE_FUEL); - this.ammo_fuel = CalcRotRegen(this.ammo_fuel, minf, autocvar_g_balance_fuel_regen, autocvar_g_balance_fuel_regenlinear, frametime * (time > this.pauseregen_finished) * ((this.items & ITEM_JetpackRegen.m_itemid) != 0), maxf, autocvar_g_balance_fuel_rot, autocvar_g_balance_fuel_rotlinear, frametime * (time > this.pauserotfuel_finished), limitf); + SetResourceAmount(this, RESOURCE_FUEL, CalcRotRegen(GetResourceAmount(this, RESOURCE_FUEL), minf, autocvar_g_balance_fuel_regen, autocvar_g_balance_fuel_regenlinear, + frametime * (time > this.pauseregen_finished) * ((this.items & ITEM_JetpackRegen.m_itemid) != 0), + maxf, autocvar_g_balance_fuel_rot, autocvar_g_balance_fuel_rotlinear, frametime * (time > this.pauserotfuel_finished), limitf)); } // Ugly hack to make sure the health and armor don't go beyond hard limit. // TODO: Remove this hack when all code uses GivePlayerHealth and @@ -1805,12 +1807,12 @@ void SpectateCopy(entity this, entity spectatee) PS(this) = PS(spectatee); this.armortype = spectatee.armortype; this.armorvalue = spectatee.armorvalue; - this.ammo_cells = spectatee.ammo_cells; // TODO: these will be a part of inventory, so no need to worry about setting them later! - this.ammo_plasma = spectatee.ammo_plasma; - this.ammo_shells = spectatee.ammo_shells; - this.ammo_nails = spectatee.ammo_nails; - this.ammo_rockets = spectatee.ammo_rockets; - this.ammo_fuel = spectatee.ammo_fuel; + SetResourceAmountExplicit(this, RESOURCE_CELLS, GetResourceAmount(spectatee, RESOURCE_CELLS)); + SetResourceAmountExplicit(this, RESOURCE_PLASMA, GetResourceAmount(spectatee, RESOURCE_PLASMA)); + SetResourceAmountExplicit(this, RESOURCE_SHELLS, GetResourceAmount(spectatee, RESOURCE_SHELLS)); + SetResourceAmountExplicit(this, RESOURCE_BULLETS, GetResourceAmount(spectatee, RESOURCE_BULLETS)); + SetResourceAmountExplicit(this, RESOURCE_ROCKETS, GetResourceAmount(spectatee, RESOURCE_ROCKETS)); + SetResourceAmountExplicit(this, RESOURCE_FUEL, GetResourceAmount(spectatee, RESOURCE_FUEL)); this.effects = spectatee.effects & EFMASK_CHEAP; // eat performance this.health = spectatee.health; CS(this).impulse = 0; @@ -2309,7 +2311,7 @@ bool PlayerThink(entity this) } this.items_added = 0; - if ((this.items & ITEM_Jetpack.m_itemid) && ((this.items & ITEM_JetpackRegen.m_itemid) || this.ammo_fuel >= 0.01)) + if ((this.items & ITEM_Jetpack.m_itemid) && ((this.items & ITEM_JetpackRegen.m_itemid) || GetResourceAmount(this, RESOURCE_FUEL) >= 0.01)) this.items_added |= IT_FUEL; this.items |= this.items_added; diff --git a/qcsrc/server/compat/quake3.qc b/qcsrc/server/compat/quake3.qc index 85b063a68..93f59a515 100644 --- a/qcsrc/server/compat/quake3.qc +++ b/qcsrc/server/compat/quake3.qc @@ -141,27 +141,27 @@ void target_give_init(entity this) IL_EACH(g_items, it.targetname == this.target, { if (it.classname == "weapon_devastator") { - this.ammo_rockets += it.count * WEP_CVAR(devastator, ammo); + SetResourceAmountExplicit(this, RESOURCE_ROCKETS, GetResourceAmount(this, RESOURCE_ROCKETS) + it.count * WEP_CVAR_PRI(devastator, ammo)); // WEAPONTODO this.netname = cons(this.netname, "devastator"); } else if (it.classname == "weapon_vortex") { - this.ammo_cells += it.count * WEP_CVAR_PRI(vortex, ammo); // WEAPONTODO + SetResourceAmountExplicit(this, RESOURCE_CELLS, GetResourceAmount(this, RESOURCE_CELLS) + it.count * WEP_CVAR_PRI(vortex, ammo)); // WEAPONTODO this.netname = cons(this.netname, "vortex"); } else if (it.classname == "weapon_electro") { - this.ammo_cells += it.count * WEP_CVAR_PRI(electro, ammo); // WEAPONTODO + SetResourceAmountExplicit(this, RESOURCE_CELLS, GetResourceAmount(this, RESOURCE_CELLS) + it.count * WEP_CVAR_PRI(electro, ammo)); // WEAPONTODO this.netname = cons(this.netname, "electro"); } else if (it.classname == "weapon_hagar") { - this.ammo_rockets += it.count * WEP_CVAR_PRI(hagar, ammo); // WEAPONTODO + SetResourceAmountExplicit(this, RESOURCE_ROCKETS, GetResourceAmount(this, RESOURCE_ROCKETS) + it.count * WEP_CVAR_PRI(hagar, ammo)); // WEAPONTODO this.netname = cons(this.netname, "hagar"); } else if (it.classname == "weapon_crylink") { - this.ammo_cells += it.count * WEP_CVAR_PRI(crylink, ammo); + SetResourceAmountExplicit(this, RESOURCE_CELLS, GetResourceAmount(this, RESOURCE_CELLS) + it.count * WEP_CVAR_PRI(crylink, ammo)); // WEAPONTODO this.netname = cons(this.netname, "crylink"); } else if (it.classname == "weapon_mortar") { - this.ammo_rockets += it.count * WEP_CVAR_PRI(mortar, ammo); // WEAPONTODO + SetResourceAmountExplicit(this, RESOURCE_ROCKETS, GetResourceAmount(this, RESOURCE_ROCKETS) + it.count * WEP_CVAR_PRI(mortar, ammo)); // WEAPONTODO this.netname = cons(this.netname, "mortar"); } else if (it.classname == "item_armor_mega") diff --git a/qcsrc/server/resources.qc b/qcsrc/server/resources.qc index 4ad66bb98..b63ba7874 100644 --- a/qcsrc/server/resources.qc +++ b/qcsrc/server/resources.qc @@ -74,6 +74,17 @@ float GetResourceAmount(entity e, int resource_type) return e.(resource_field); } +bool SetResourceAmountExplicit(entity e, int resource_type, float amount) +{ + .float resource_field = GetResourceField(resource_type); + if (e.(resource_field) != amount) + { + e.(resource_field) = amount; + return true; + } + return false; +} + void SetResourceAmount(entity e, int resource_type, float amount) { bool forbid = MUTATOR_CALLHOOK(SetResourceAmount, e, resource_type, amount); @@ -90,10 +101,9 @@ void SetResourceAmount(entity e, int resource_type, float amount) amount_wasted = amount - max_amount; amount = max_amount; } - .float resource_field = GetResourceField(resource_type); - if (e.(resource_field) != amount) + bool changed = SetResourceAmountExplicit(e, resource_type, amount); + if (changed) { - e.(resource_field) = amount; MUTATOR_CALLHOOK(ResourceAmountChanged, e, resource_type, amount); } if (amount_wasted == 0) diff --git a/qcsrc/server/resources.qh b/qcsrc/server/resources.qh index 6ff3cea67..47ed972d2 100644 --- a/qcsrc/server/resources.qh +++ b/qcsrc/server/resources.qh @@ -24,6 +24,13 @@ float GetResourceLimit(entity e, int resource_type); /// \return Current amount of resource the given entity has. float GetResourceAmount(entity e, int resource_type); +/// \brief Sets the resource amount of an entity without calling any hooks. +/// \param[in,out] e Entity to adjust. +/// \param[in] resource_type Type of the resource (a RESOURCE_* constant). +/// \param[in] amount Amount of resource to set. +/// \return Boolean for whether the ammo amount was changed +bool SetResourceAmountExplicit(entity e, int resource_type, float amount); + /// \brief Sets the current amount of resource the given entity will have. /// \param[in,out] e Entity to adjust. /// \param[in] resource_type Type of the resource (a RESOURCE_* constant). -- 2.39.2