From 52f5ee02436488637e4368a602cb0d15d1b87bc1 Mon Sep 17 00:00:00 2001 From: drjaska Date: Thu, 29 Dec 2022 14:24:14 +0200 Subject: [PATCH] continue macrofication --- qcsrc/client/hud/panel/weapons.qc | 2 +- qcsrc/common/notifications/all.qh | 4 ++-- qcsrc/common/weapons/all.qc | 12 ++++++------ qcsrc/common/weapons/all.qh | 12 +++++++++++- qcsrc/common/weapons/weapon.qh | 6 +----- qcsrc/server/compat/quake3.qh | 2 +- qcsrc/server/items/items.qc | 32 ++++++++++++++++--------------- 7 files changed, 39 insertions(+), 31 deletions(-) diff --git a/qcsrc/client/hud/panel/weapons.qc b/qcsrc/client/hud/panel/weapons.qc index 720a73991..cb7c95482 100644 --- a/qcsrc/client/hud/panel/weapons.qc +++ b/qcsrc/client/hud/panel/weapons.qc @@ -171,7 +171,7 @@ void HUD_Weapons() { weapons_orderbyimpulse_old = autocvar_hud_panel_weapons_orderbyimpulse; strcpy(cl_weaponpriority_old, autocvar_cl_weaponpriority); - string weporder = W_FIXWEAPNORDER_FORCECOMPLETE(W_NUMBERWEAPONORDER(cl_weaponpriority_old)); + string weporder = W_FIXWEAPONORDER_FORCECOMPLETE(W_NUMBERWEAPONORDER(cl_weaponpriority_old)); if(autocvar_hud_panel_weapons_orderbyimpulse) { weporder = W_FixWeaponOrder_BuildImpulseList(weporder); diff --git a/qcsrc/common/notifications/all.qh b/qcsrc/common/notifications/all.qh index e9eb9895c..2df383ce2 100644 --- a/qcsrc/common/notifications/all.qh +++ b/qcsrc/common/notifications/all.qh @@ -632,8 +632,8 @@ string notif_arg_item_wepammo(float f1, float f2) { string ammoitems = ""; Weapon wep = REGISTRY_GET(Weapons, f1); - if (wep.ammo_type.m_name) - ammoitems = wep.ammo_type.m_name; + if (GETAMMONAME(wep.ammo_type)) + ammoitems = GETAMMONAME(wep.ammo_type); return sprintf(_(" with %d %s"), f2, ammoitems); } diff --git a/qcsrc/common/weapons/all.qc b/qcsrc/common/weapons/all.qc index 27ab16644..369cf7208 100644 --- a/qcsrc/common/weapons/all.qc +++ b/qcsrc/common/weapons/all.qc @@ -170,7 +170,7 @@ WepSet W_RandomWeapons(entity e, WepSet remaining, int n) // TODO: registry handles for below functions // drjaska: made these functions into macros in -// common/weapons/weapon.qh +// common/weapons/all.qh // instead of registry handles #if 0 string GetAmmoPicture(Resource ammotype) @@ -200,9 +200,8 @@ string GetAmmoName(Resource ammotype) default: return "batteries"; } } -#endif -entity GetAmmoItem(Resource ammotype) +entity GETAMMOITEM(Resource ammotype) { switch (ammotype) { @@ -218,6 +217,7 @@ entity GetAmmoItem(Resource ammotype) // WEAPONTODO: use this generic func to reduce duplication ? // GETAMMOPICTURE GETAMMONAME notif_arg_item_wepammo ammo_pickupevalfunc ? } +#endif string W_Sound(string w_snd) { @@ -770,9 +770,9 @@ NET_HANDLE(w_muzzleflash, bool isNew) #endif #ifdef SVQC -string W_FIXWEAPNORDER_FORCECOMPLETE_AndBuildImpulseList(entity this, string wo) +string W_FixWeaponOrder_ForceComplete_AndBuildImpulseList(entity this, string wo) { - string o = W_FIXWEAPNORDER_FORCECOMPLETE(wo); + string o = W_FIXWEAPONORDER_FORCECOMPLETE(wo); strcpy(CS_CVAR(this).weaponorder_byimpulse, W_FixWeaponOrder_BuildImpulseList(o)); return o; } @@ -788,7 +788,7 @@ REPLICATE(cvar_cl_gunalign, int, "cl_gunalign"); REPLICATE(cvar_cl_weapon_switch_reload, bool, "cl_weapon_switch_reload"); REPLICATE(cvar_cl_weapon_switch_fallback_to_impulse, bool, "cl_weapon_switch_fallback_to_impulse"); REPLICATE(cvar_cl_weaponimpulsemode, int, "cl_weaponimpulsemode"); -REPLICATE(cvar_cl_weaponpriority, string, "cl_weaponpriority", W_FIXWEAPNORDER_FORCECOMPLETE_AndBuildImpulseList); +REPLICATE(cvar_cl_weaponpriority, string, "cl_weaponpriority", W_FixWeaponOrder_ForceComplete_AndBuildImpulseList); REPLICATE(cvar_cl_weaponpriorities[0], string, "cl_weaponpriority0", W_FixWeaponOrder_AllowIncomplete); REPLICATE(cvar_cl_weaponpriorities[1], string, "cl_weaponpriority1", W_FixWeaponOrder_AllowIncomplete); REPLICATE(cvar_cl_weaponpriorities[2], string, "cl_weaponpriority2", W_FixWeaponOrder_AllowIncomplete); diff --git a/qcsrc/common/weapons/all.qh b/qcsrc/common/weapons/all.qh index 1618b1dc6..30e442eee 100644 --- a/qcsrc/common/weapons/all.qh +++ b/qcsrc/common/weapons/all.qh @@ -10,6 +10,16 @@ void WriteWepSet(float dest, WepSet w); #endif +#define GETAMMOPICTURE(ammotype) GETAMMOITEM(ammotype).m_icon +#define GETAMMONAME(ammotype) GETAMMOITEM(ammotype).m_name +#define GETAMMOITEM(ammotype) \ + (ammotype == RES_SHELLS ? ITEM_Shells : \ + ammotype == RES_BULLETS ? ITEM_Bullets : \ + ammotype == RES_ROCKETS ? ITEM_Rockets : \ + ammotype == RES_CELLS ? ITEM_Cells : \ + ammotype == RES_PLASMA ? ITEM_Plasma : \ + ammotype == RES_FUEL ? ITEM_JetpackFuel : NULL) + #ifdef CSQC WepSet WepSet_GetFromStat(); WepSet WepSet_GetFromStat_InMap(); @@ -409,7 +419,7 @@ void wframe_send(entity actor, entity weaponentity, int wepframe, float attackra void W_MuzzleFlash(Weapon thiswep, entity actor, .entity weaponentity, vector shotorg, vector shotdir); -string W_FIXWEAPNORDER_FORCECOMPLETE_AndBuildImpulseList(entity this, string wo); +string W_FixWeaponOrder_ForceComplete_AndBuildImpulseList(entity this, string wo); string W_FixWeaponOrder_AllowIncomplete(entity this, string order); #endif diff --git a/qcsrc/common/weapons/weapon.qh b/qcsrc/common/weapons/weapon.qh index b2cc8434b..717c1f616 100644 --- a/qcsrc/common/weapons/weapon.qh +++ b/qcsrc/common/weapons/weapon.qh @@ -233,13 +233,9 @@ string W_NumberWeaponOrder_MapFunc(string s); string W_FixWeaponOrder_BuildImpulseList(string o); string W_FixWeaponOrder_AllowIncomplete(entity this, string order); WepSet W_RandomWeapons(entity e, WepSet remaining, int n); -#define W_FIXWEAPNORDER_FORCECOMPLETE(order) \ +#define W_FIXWEAPONORDER_FORCECOMPLETE(order) \ W_FIXWEAPONORDER(((order == "") ? W_NUMBERWEAPONORDER(cvar_defstring("cl_weaponpriority")) : order), 1) -#define GETAMMOPICTURE(ammotype) GetAmmoItem(ammotype).m_icon -#define GETAMMONAME(ammotype) GetAmmoItem(ammotype).m_name -entity GetAmmoItem(Resource ammotype); - #ifdef CSQC #define GETAMMOTYPEFROMNUM(i) \ i == 0 ? RES_SHELLS : \ diff --git a/qcsrc/server/compat/quake3.qh b/qcsrc/server/compat/quake3.qh index d2c547b6f..165b79a70 100644 --- a/qcsrc/server/compat/quake3.qh +++ b/qcsrc/server/compat/quake3.qh @@ -21,7 +21,7 @@ int GetAmmoConsumptionQ3(string netname); { \ if(this.count && xonwep.ammo_type) \ SetResource(this, xonwep.ammo_type, this.count * GetAmmoConsumptionQ3(xonwep.netname)); \ - SPAWNFUNC_BODY(GetAmmoItem(xonwep.ammo_type)) \ + SPAWNFUNC_BODY(GETAMMOITEM(xonwep.ammo_type)) \ } // Ammo only, conditional diff --git a/qcsrc/server/items/items.qc b/qcsrc/server/items/items.qc index 5a973264b..7f3c7e8f6 100644 --- a/qcsrc/server/items/items.qc +++ b/qcsrc/server/items/items.qc @@ -1273,22 +1273,23 @@ spawnfunc(target_items) { for(int j = 0; j < n; ++j) { + string s = argv(j); // this is from a time when unlimited superweapons were handled together with ammo in some parts of the code - if (argv(j) == "unlimited_ammo") this.items |= IT_UNLIMITED_AMMO | IT_UNLIMITED_SUPERWEAPONS; - else if(argv(j) == "unlimited_weapon_ammo") this.items |= IT_UNLIMITED_AMMO; - else if(argv(j) == "unlimited_superweapons") this.items |= IT_UNLIMITED_SUPERWEAPONS; - else if(argv(j) == "strength") this.items |= ITEM_Strength.m_itemid; - else if(argv(j) == "invincible") this.items |= ITEM_Shield.m_itemid; - else if(argv(j) == "speed") this.items |= ITEM_Speed.m_itemid; - else if(argv(j) == "invisibility") this.items |= ITEM_Invisibility.m_itemid; - else if(argv(j) == "superweapons") this.items |= IT_SUPERWEAPON; - else if(argv(j) == "jetpack") this.items |= ITEM_Jetpack.m_itemid; - else if(argv(j) == "fuel_regen") this.items |= ITEM_JetpackRegen.m_itemid; + if (s == "unlimited_ammo") this.items |= IT_UNLIMITED_AMMO | IT_UNLIMITED_SUPERWEAPONS; + else if(s == "unlimited_weapon_ammo") this.items |= IT_UNLIMITED_AMMO; + else if(s == "unlimited_superweapons") this.items |= IT_UNLIMITED_SUPERWEAPONS; + else if(s == "strength") this.items |= ITEM_Strength.m_itemid; + else if(s == "invincible") this.items |= ITEM_Shield.m_itemid; + else if(s == "speed") this.items |= ITEM_Speed.m_itemid; + else if(s == "invisibility") this.items |= ITEM_Invisibility.m_itemid; + else if(s == "superweapons") this.items |= IT_SUPERWEAPON; + else if(s == "jetpack") this.items |= ITEM_Jetpack.m_itemid; + else if(s == "fuel_regen") this.items |= ITEM_JetpackRegen.m_itemid; else { FOREACH(StatusEffect, it.instanceOfBuff, { - string s = Buff_UndeprecateName(argv(j)); + s = Buff_UndeprecateName(s); if(s == it.netname) { this.buffdef = it; @@ -1298,7 +1299,7 @@ spawnfunc(target_items) } }); FOREACH(Weapons, it != WEP_Null, { - string s = W_UNDEPRECATENAME(argv(j)); + s = W_UNDEPRECATENAME(s); if(s == it.netname) { STAT(WEAPONS, this) |= (it.m_wepset); @@ -1364,7 +1365,8 @@ spawnfunc(target_items) n = tokenize_console(this.netname); for(int j = 0; j < n; ++j) { - FOREACH(Weapons, it != WEP_Null && W_UNDEPRECATENAME(argv(j)) == it.netname, { + string s = argv(j); + FOREACH(Weapons, it != WEP_Null && W_UNDEPRECATENAME(s) == it.netname, { it.wr_init(it); break; }); @@ -1669,8 +1671,8 @@ float GiveItems(entity e, float beginarg, float endarg) break; }); FOREACH(Weapons, it != WEP_Null && W_UNDEPRECATENAME(cmd) == it.netname, { - got += GiveWeapon(e, it.m_id, op, val); - break; + got += GiveWeapon(e, it.m_id, op, val); + break; }); break; } -- 2.39.2