]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
SPAWNFUNC macro cleanup
authorbones_was_here <bones_was_here@xa.org.au>
Sun, 18 Oct 2020 03:53:09 +0000 (13:53 +1000)
committerbones_was_here <bones_was_here@xa.org.au>
Sun, 18 Oct 2020 03:53:09 +0000 (13:53 +1000)
qcsrc/common/items/item.qh
qcsrc/common/weapons/weapon.qh
qcsrc/server/compat/quake3.qc
qcsrc/server/compat/quake3.qh

index 26f89cad5f45f598e7f13ae119db9eadab882ae5..10c1bbc99d2e64358f493d82f6c8a7f55ecfaede 100644 (file)
@@ -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
 
index 916acdf9ed97c0cc316685a6bab8eadeb8c3cbf5..cf266b8d69964b0c9cc7c9dc9420381d83b53dac 100644 (file)
@@ -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
 
index 9347077a46f0ea94e4be687848df2dff054d337d..fec250558784a5ff3f42bf02e7f0b88cac029191 100644 (file)
@@ -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)
index 55b2ede5cb7044b38e622ff51365e71c00d36781..321c6fb4feb5ace4bb736d766a48892afdfefe54 100644 (file)
@@ -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) \