]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Do something awesome with macros
authorTimePath <andrew.hardaker1995@gmail.com>
Tue, 12 May 2015 03:26:25 +0000 (13:26 +1000)
committerTimePath <andrew.hardaker1995@gmail.com>
Tue, 12 May 2015 03:33:48 +0000 (13:33 +1000)
qcsrc/common/items/item/ammo.qc
qcsrc/common/items/item/armor.qc
qcsrc/common/items/item/health.qc
qcsrc/common/util-pre.qh

index a2381ab99ff991f8def7a0e2b1131cfa82023b19..dc0909d1ee8404f6aca32cf13b692ee508b1a992 100644 (file)
@@ -1,49 +1,49 @@
 #include "ammo.qh"
 #include "../../../server/t_items.qh"
 
-#define REGISTER_AMMO(id, model, sound, name, itemid, botvalue) \
-REGISTER_ITEM(id, Ammo, LAMBDA({                                \
-    this.m_model = model;                                       \
-    this.m_sound = sound;                                       \
-    this.m_respawntime = SPAWNTIME_AMMO;                        \
-    this.m_respawntimejitter = SPAWNTIME_AMMO;                  \
-    this.m_name = name;                                         \
-    this.m_itemid = itemid;                                     \
-    this.m_botvalue = botvalue;                                 \
-}))
+#define WITH(it) this.m_##it;
+
+#define REGISTER_AMMO(id, ...)                      \
+    REGISTER_ITEM(id, Ammo, LAMBDA({                \
+        MAP(WITH, __VA_ARGS__)                      \
+        this.m_respawntime = SPAWNTIME_AMMO;        \
+        this.m_respawntimejitter = SPAWNTIME_AMMO;  \
+    }))
 
 REGISTER_AMMO(Bullets
-    , "models/items/a_bullets.mdl"
-    , "misc/itempickup.wav"
-    , "bullets"
-    , IT_NAILS
-    , 2000
+    , model     = "models/items/a_bullets.mdl"
+    , sound     = "misc/itempickup.wav"
+    , name      = "bullets"
+    , itemid    = IT_NAILS
+    , botvalue  = 2000
 )
 REGISTER_AMMO(Cells
-    , "models/items/a_cells.md3"
-    , "misc/itempickup.wav"
-    , "cells"
-    , IT_ROCKETS
-    , 2000
+    , model     = "models/items/a_cells.md3"
+    , sound     = "misc/itempickup.wav"
+    , name      = "cells"
+    , itemid    = IT_ROCKETS
+    , botvalue  = 2000
 )
 REGISTER_AMMO(Plasma
-    , "models/items/a_cells.md3"
-    , "misc/itempickup.wav"
-    , "plasma"
-    , IT_ROCKETS
-    , 2000
+    , model     = "models/items/a_cells.md3"
+    , sound     = "misc/itempickup.wav"
+    , name      = "plasma"
+    , itemid    = IT_ROCKETS
+    , botvalue  = 2000
 )
 REGISTER_AMMO(Rockets
-    , "models/items/a_rockets.md3"
-    , "misc/itempickup.wav"
-    , "rockets"
-    , IT_ROCKETS
-    , 3000
+    , model     = "models/items/a_rockets.md3"
+    , sound     = "misc/itempickup.wav"
+    , name      = "rockets"
+    , itemid    = IT_ROCKETS
+    , botvalue  = 3000
 )
 REGISTER_AMMO(Shells
-    , "models/items/a_shells.md3"
-    , "misc/itempickup.wav"
-    , "shells"
-    , IT_SHELLS
-    , 500
+    , model     = "models/items/a_shells.md3"
+    , sound     = "misc/itempickup.wav"
+    , name      = "shells"
+    , itemid    = IT_SHELLS
+    , botvalue  = 500
 )
+
+#undef WITH
index 3dac22a5966c49338c2a37afb8e66c5d5e7b3e76..563ece2f71c131922cc6e2d32b2fe3e5cee54e92 100644 (file)
@@ -1,49 +1,51 @@
 #include "armor.qh"
 #include "../../../server/t_items.qh"
 
-#define REGISTER_ARMOR(id, model, sound, resp, name, itemid, botvalue)  \
-REGISTER_ITEM(id, Armor, LAMBDA({                                       \
-    this.m_model = model;                                               \
-    this.m_sound = sound;                                               \
-    this.m_respawntime = resp;                                          \
-    this.m_respawntimejitter = resp;                                    \
-    this.m_name = name;                                                 \
-    this.m_itemid = itemid;                                             \
-    this.m_botvalue = botvalue;                                         \
-}))
+#define WITH(it) this.m_##it;
+
+#define REGISTER_ARMOR(id, ...)         \
+    REGISTER_ITEM(id, Armor, LAMBDA({   \
+        MAP(WITH, __VA_ARGS__)          \
+    }))
 
 REGISTER_ARMOR(ArmorSmall
-    , "models/items/item_armor_small.md3"
-    , "misc/armor1.wav"
-    , SPAWNTIME_SHORT
-    , "5 Armor"
-    , IT_ARMOR_SHARD
-    , BOT_PICKUP_RATING_LOW
+    , model             = "models/items/item_armor_small.md3"
+    , sound             = "misc/armor1.wav"
+    , respawntime       = SPAWNTIME_SHORT
+    , respawntimejitter = SPAWNTIME_SHORT
+    , name              = "5 Armor"
+    , itemid            = IT_ARMOR_SHARD
+    , botvalue          = BOT_PICKUP_RATING_LOW
 )
 
 REGISTER_ARMOR(ArmorMedium
-    , "models/items/item_armor_medium.md3"
-    , "misc/armor10.wav"
-    , SPAWNTIME_MEDIUM
-    , "25 Armor"
-    , IT_ARMOR
-    , BOT_PICKUP_RATING_MID
+    , model             = "models/items/item_armor_medium.md3"
+    , sound             = "misc/armor10.wav"
+    , respawntime       = SPAWNTIME_MEDIUM
+    , respawntimejitter = SPAWNTIME_MEDIUM
+    , name              = "25 Armor"
+    , itemid            = IT_ARMOR
+    , botvalue          = BOT_PICKUP_RATING_MID
 )
 
 REGISTER_ARMOR(ArmorBig
-    , "models/items/item_armor_big.md3"
-    , "misc/armor17_5.wav"
-    , SPAWNTIME_LONG
-    , "50 Armor"
-    , IT_ARMOR
-    , 20000 // FIXME: higher than BOT_PICKUP_RATING_HIGH?
+    , model             = "models/items/item_armor_big.md3"
+    , sound             = "misc/armor17_5.wav"
+    , respawntime       = SPAWNTIME_LONG
+    , respawntimejitter = SPAWNTIME_LONG
+    , name              = "50 Armor"
+    , itemid            = IT_ARMOR
+    , botvalue          = 20000 // FIXME: higher than BOT_PICKUP_RATING_HIGH?
 )
 
 REGISTER_ARMOR(ArmorLarge
-    , "models/items/item_armor_large.md3"
-    , "misc/armor25.wav"
-    , SPAWNTIME_LONG
-    , "100 Armor"
-    , IT_ARMOR
-    , BOT_PICKUP_RATING_HIGH
+    , model             = "models/items/item_armor_large.md3"
+    , sound             = "misc/armor25.wav"
+    , respawntime       = SPAWNTIME_LONG
+    , respawntimejitter = SPAWNTIME_LONG
+    , name              = "100 Armor"
+    , itemid            = IT_ARMOR
+    , botvalue          = BOT_PICKUP_RATING_HIGH
 )
+
+#undef WITH
index 47df52ebeb72afb2a67c2880ed421b648194c59b..33f6ccfb0ad881ec7cd94238afc7a79d511ec7bb 100644 (file)
@@ -1,49 +1,51 @@
 #include "health.qh"
 #include "../../../server/t_items.qh"
 
-#define REGISTER_HEALTH(id, model, sound, resp, name, itemid, botvalue) \
-REGISTER_ITEM(id, Health, LAMBDA({                                      \
-    this.m_model = model;                                               \
-    this.m_sound = sound;                                               \
-    this.m_respawntime = resp;                                          \
-    this.m_respawntimejitter = resp;                                    \
-    this.m_name = name;                                                 \
-    this.m_itemid = itemid;                                             \
-    this.m_botvalue = botvalue;                                         \
-}))
+#define WITH(it) this.m_##it;
+
+#define REGISTER_HEALTH(id, ...)        \
+    REGISTER_ITEM(id, Health, LAMBDA({  \
+        MAP(WITH, __VA_ARGS__)          \
+    }))
 
 REGISTER_HEALTH(HealthSmall
-    , "models/items/g_h1.md3"
-    , "misc/minihealth.wav"
-    , SPAWNTIME_SHORT
-    , "5 Health"
-    , IT_5HP
-    , BOT_PICKUP_RATING_LOW
+    , model             =   "models/items/g_h1.md3"
+    , sound             =   "misc/minihealth.wav"
+    , respawntime       =   SPAWNTIME_SHORT
+    , respawntimejitter =   SPAWNTIME_SHORT
+    , name              =   "5 Health"
+    , itemid            =   IT_5HP
+    , botvalue          =   BOT_PICKUP_RATING_LOW
 )
 
 REGISTER_HEALTH(HealthMedium
-    , "models/items/g_h25.md3"
-    , "misc/mediumhealth.wav"
-    , SPAWNTIME_SHORT
-    , "25 Health"
-    , IT_25HP
-    , BOT_PICKUP_RATING_MID
+    , model             =   "models/items/g_h25.md3"
+    , sound             =   "misc/mediumhealth.wav"
+    , respawntime       =   SPAWNTIME_SHORT
+    , respawntimejitter =   SPAWNTIME_SHORT
+    , name              =   "25 Health"
+    , itemid            =   IT_25HP
+    , botvalue          =   BOT_PICKUP_RATING_MID
 )
 
 REGISTER_HEALTH(HealthLarge
-    , "models/items/g_h50.md3"
-    , "misc/mediumhealth.wav"
-    , SPAWNTIME_MEDIUM
-    , "50 Health"
-    , IT_25HP
-    , BOT_PICKUP_RATING_MID
+    , model             =   "models/items/g_h50.md3"
+    , sound             =   "misc/mediumhealth.wav"
+    , respawntime       =   SPAWNTIME_MEDIUM
+    , respawntimejitter =   SPAWNTIME_MEDIUM
+    , name              =   "50 Health"
+    , itemid            =   IT_25HP
+    , botvalue          =   BOT_PICKUP_RATING_MID
 )
 
 REGISTER_HEALTH(HealthMega
-    , "models/items/g_h100.md3"
-    , "misc/megahealth.wav"
-    , SPAWNTIME_LONG
-    , "100 Health"
-    , IT_HEALTH
-    , BOT_PICKUP_RATING_HIGH
+    , model             =   "models/items/g_h100.md3"
+    , sound             =   "misc/megahealth.wav"
+    , respawntime       =   SPAWNTIME_LONG
+    , respawntimejitter =   SPAWNTIME_LONG
+    , name              =   "100 Health"
+    , itemid            =   IT_HEALTH
+    , botvalue          =   BOT_PICKUP_RATING_HIGH
 )
+
+#undef WITH
index a1ac7dc7adeabd5793fd129a19e19a366431d67e..91094e11f5dcb39ecdb6b1798b5812e04f962795 100644 (file)
 [[deprecated("use true")]] [[alias("true")]] const bool TRUE;
 [[deprecated("use false")]] [[alias("false")]] const bool FALSE;
 
+#ifdef GMQCC
+    #define OVERLOAD(F, ...) F##_##__VA_COUNT__(__VA_ARGS__)
+#else
+    #define OVERLOAD_(F,_9,_8,_7,_6,_5,_4,_3,_2,_1,n,...) F##_##n
+    #define OVERLOAD(F, ...) OVERLOAD_(F,__VA_ARGS__,9,8,7,6,5,4,3,2,1)(__VA_ARGS__)
+#endif
+
+#define MAP(f, ...) OVERLOAD(MAP, f, __VA_ARGS__)
+#define MAP_2(f, it) f(it)
+#define MAP_3(f, it, ...) f(it)MAP_2(f, __VA_ARGS__)
+#define MAP_4(f, it, ...) f(it)MAP_3(f, __VA_ARGS__)
+#define MAP_5(f, it, ...) f(it)MAP_4(f, __VA_ARGS__)
+#define MAP_6(f, it, ...) f(it)MAP_5(f, __VA_ARGS__)
+#define MAP_7(f, it, ...) f(it)MAP_6(f, __VA_ARGS__)
+#define MAP_8(f, it, ...) f(it)MAP_7(f, __VA_ARGS__)
+#define MAP_9(f, it, ...) f(it)MAP_8(f, __VA_ARGS__)
+#define MAP_10(f, it, ...) f(it)MAP_9(f, __VA_ARGS__)
+#define MAP_11(f, it, ...) f(it)MAP_10(f, __VA_ARGS__)
+#define MAP_12(f, it, ...) f(it)MAP_11(f, __VA_ARGS__)
+#define MAP_13(f, it, ...) f(it)MAP_12(f, __VA_ARGS__)
+#define MAP_14(f, it, ...) f(it)MAP_13(f, __VA_ARGS__)
+#define MAP_15(f, it, ...) f(it)MAP_14(f, __VA_ARGS__)
+#define MAP_16(f, it, ...) f(it)MAP_15(f, __VA_ARGS__)
+#define MAP_17(f, it, ...) f(it)MAP_16(f, __VA_ARGS__)
+#define MAP_18(f, it, ...) f(it)MAP_17(f, __VA_ARGS__)
+#define MAP_19(f, it, ...) f(it)MAP_18(f, __VA_ARGS__)
+#define MAP_20(f, it, ...) f(it)MAP_19(f, __VA_ARGS__)
+
 #define BIT(n) (1 << (n))
 #define BITSET(var, mask, flag) (flag ? (var) | (mask) : (var) &~ (mask))