From: bones_was_here Date: Sun, 18 Oct 2020 03:53:09 +0000 (+1000) Subject: SPAWNFUNC macro cleanup X-Git-Tag: xonotic-v0.8.5~352^2~18 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=88fcde8f2df0954cb6daebd141a52070cf644ea7;p=xonotic%2Fxonotic-data.pk3dir.git SPAWNFUNC macro cleanup --- diff --git a/qcsrc/common/items/item.qh b/qcsrc/common/items/item.qh index 26f89cad5..10c1bbc99 100644 --- a/qcsrc/common/items/item.qh +++ b/qcsrc/common/items/item.qh @@ -64,27 +64,23 @@ const int ITS_GLOW = BIT(6); .float strength_finished; // NOTE: this field is used only by map entities, it does not directly apply the strength stat .float invincible_finished; // ditto -#define spawnfunc_body(item) \ - if (!(item) || !Item_IsDefinitionAllowed(item)) \ +#define SPAWNFUNC_BODY(item) \ + if (item && Item_IsDefinitionAllowed(item)) \ + StartItem(this, item); \ + else \ { \ startitem_failed = true; \ delete(this); \ - return; \ - } \ - StartItem(this, item) + } #define SPAWNFUNC_ITEM(name, item) \ spawnfunc(name) \ { \ - spawnfunc_body(item); \ + SPAWNFUNC_BODY(item) \ } #define SPAWNFUNC_ITEM_COND(name, cond, item1, item2) \ - spawnfunc(name) \ - { \ - entity item = (cond) ? item1 : item2; \ - spawnfunc_body(item); \ - } + SPAWNFUNC_ITEM(name, (cond ? item1 : item2)) #else diff --git a/qcsrc/common/weapons/weapon.qh b/qcsrc/common/weapons/weapon.qh index 916acdf9e..cf266b8d6 100644 --- a/qcsrc/common/weapons/weapon.qh +++ b/qcsrc/common/weapons/weapon.qh @@ -136,11 +136,7 @@ void weapon_defaultspawnfunc(entity this, Weapon e); spawnfunc(name) { weapon_defaultspawnfunc(this, weapon); } #define SPAWNFUNC_WEAPON_COND(name, cond, wep1, wep2) \ - spawnfunc(name) \ - { \ - entity wep = (cond) ? wep1 : wep2; \ - weapon_defaultspawnfunc(this, wep); \ - } + SPAWNFUNC_WEAPON(name, (cond ? wep1 : wep2)) #else diff --git a/qcsrc/server/compat/quake3.qc b/qcsrc/server/compat/quake3.qc index 9347077a4..fec250558 100644 --- a/qcsrc/server/compat/quake3.qc +++ b/qcsrc/server/compat/quake3.qc @@ -78,7 +78,7 @@ SPAWNFUNC_Q3(weapon_railgun, ammo_slugs, WEP_VORTEX) // BFG -> Crylink || Fireball SPAWNFUNC_Q3_COND(weapon_bfg, ammo_bfg, cvar_string("g_mod_balance") == "XDF", WEP_CRYLINK, WEP_FIREBALL) - // FIXME: WEP_FIREBALL has no ammo_type field so ammo_bfg is deleted by spawnfunc_body + // FIXME: WEP_FIREBALL has no ammo_type field so ammo_bfg is deleted by SPAWNFUNC_BODY // grappling hook -> hook SPAWNFUNC_WEAPON(weapon_grapplinghook, WEP_HOOK) diff --git a/qcsrc/server/compat/quake3.qh b/qcsrc/server/compat/quake3.qh index 55b2ede5c..321c6fb4f 100644 --- a/qcsrc/server/compat/quake3.qh +++ b/qcsrc/server/compat/quake3.qh @@ -8,27 +8,22 @@ bool DoesQ3ARemoveThisEntity(entity this); .int fragsfilter_cnt; -// The ammo spawnfunc knows which weapon will use the ammo so it can look up the type -// and calculate the amount required for the number of shots in the count field. -#define _SPAWNFUNC_Q3AMMO(ammo_classname, xonwep) \ - if(this.count && xonwep.ammo_type) \ - SetResource(this, xonwep.ammo_type, this.count * GetAmmoConsumptionPrimary(xonwep.netname)); \ - spawnfunc_body(GetAmmoItem(xonwep.ammo_type)); - +/* We tell the ammo spawnfunc which weapon will use the ammo so it can + * calculate the amount required for the number of shots in the count field, + * and so the type can be looked up rather than specified in quake3.qc + */ // Ammo only, unconditional #define SPAWNFUNC_Q3AMMO(ammo_classname, xonwep) \ spawnfunc(ammo_classname) \ { \ - _SPAWNFUNC_Q3AMMO(ammo_classname, xonwep) \ + if(this.count && xonwep.ammo_type) \ + SetResource(this, xonwep.ammo_type, this.count * GetAmmoConsumptionPrimary(xonwep.netname)); \ + SPAWNFUNC_BODY(GetAmmoItem(xonwep.ammo_type)) \ } // Ammo only, conditional #define SPAWNFUNC_Q3AMMO_COND(ammo_classname, cond, xonwep1, xonwep0) \ - spawnfunc(ammo_classname) \ - { \ - entity xonwep = (cond) ? xonwep1 : xonwep0; \ - _SPAWNFUNC_Q3AMMO(ammo_classname, xonwep) \ - } + SPAWNFUNC_Q3AMMO(ammo_classname, (cond ? xonwep1 : xonwep0)) // Weapon & ammo, unconditional #define SPAWNFUNC_Q3(weapon_classname, ammo_classname, xonwep) \