]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Support #ifdef in item declarations
authorTimePath <andrew.hardaker1995@gmail.com>
Tue, 12 May 2015 06:42:36 +0000 (16:42 +1000)
committerTimePath <andrew.hardaker1995@gmail.com>
Tue, 12 May 2015 06:42:36 +0000 (16:42 +1000)
qcsrc/common/items/item/ammo.qc
qcsrc/common/items/item/armor.qc
qcsrc/common/items/item/health.qc
qcsrc/common/items/item/pickup.qh
qcsrc/common/util-pre.qh

index dc0909d1ee8404f6aca32cf13b692ee508b1a992..0e389c9872e5b134a9a3c2f5755be1b644d36471 100644 (file)
@@ -2,48 +2,72 @@
 #include "../../../server/t_items.qh"
 
 #define WITH(it) this.m_##it;
+#define CONFIGURE(...) MAP(WITH, __VA_ARGS__)
+#define DEFINE(id, ...)                             \
+    REGISTER_ITEM(id, Ammo, LAMBDA(                 \
+        IF(SV, CONFIGURE                            \
+        ,   respawntime         = SPAWNTIME_AMMO    \
+        ,   respawntimejitter   = SPAWNTIME_AMMO    \
+        )                                           \
+        MAP(IDENTITY, __VA_ARGS__)                  \
+    ))
 
-#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
-    , model     = "models/items/a_bullets.mdl"
-    , sound     = "misc/itempickup.wav"
-    , name      = "bullets"
-    , itemid    = IT_NAILS
-    , botvalue  = 2000
+DEFINE(Bullets
+    ,IF(ALL, CONFIGURE
+    ,   model               =   "models/items/a_bullets.mdl"
+    ,   sound               =   "misc/itempickup.wav"
+    ,   name                =   "bullets"
+    ,   itemid              =   IT_NAILS
+    )
+    ,IF(SV, CONFIGURE
+    ,   botvalue            =   2000
+    )
 )
-REGISTER_AMMO(Cells
-    , model     = "models/items/a_cells.md3"
-    , sound     = "misc/itempickup.wav"
-    , name      = "cells"
-    , itemid    = IT_ROCKETS
-    , botvalue  = 2000
+DEFINE(Cells
+    ,IF(ALL, CONFIGURE
+    ,   model               =   "models/items/a_cells.md3"
+    ,   sound               =   "misc/itempickup.wav"
+    ,   name                =   "cells"
+    ,   itemid              =   IT_ROCKETS
+    )
+    ,IF(SV, CONFIGURE
+    ,   botvalue            =   2000
+    )
 )
-REGISTER_AMMO(Plasma
-    , model     = "models/items/a_cells.md3"
-    , sound     = "misc/itempickup.wav"
-    , name      = "plasma"
-    , itemid    = IT_ROCKETS
-    , botvalue  = 2000
+DEFINE(Plasma
+    ,IF(ALL, CONFIGURE
+    ,   model               =   "models/items/a_cells.md3"
+    ,   sound               =   "misc/itempickup.wav"
+    ,   name                =   "plasma"
+    ,   itemid              =   IT_ROCKETS
+    )
+    ,IF(SV, CONFIGURE
+    ,   botvalue            =   2000
+    )
 )
-REGISTER_AMMO(Rockets
-    , model     = "models/items/a_rockets.md3"
-    , sound     = "misc/itempickup.wav"
-    , name      = "rockets"
-    , itemid    = IT_ROCKETS
-    , botvalue  = 3000
+DEFINE(Rockets
+    ,IF(ALL, CONFIGURE
+    ,   model               =   "models/items/a_rockets.md3"
+    ,   sound               =   "misc/itempickup.wav"
+    ,   name                =   "rockets"
+    ,   itemid              =   IT_ROCKETS
+    )
+    ,IF(SV, CONFIGURE
+    ,   botvalue            =   3000
+    )
 )
-REGISTER_AMMO(Shells
-    , model     = "models/items/a_shells.md3"
-    , sound     = "misc/itempickup.wav"
-    , name      = "shells"
-    , itemid    = IT_SHELLS
-    , botvalue  = 500
+DEFINE(Shells
+    ,IF(ALL, CONFIGURE
+    ,   model               =   "models/items/a_shells.md3"
+    ,   sound               =   "misc/itempickup.wav"
+    ,   name                =   "shells"
+    ,   itemid              =   IT_SHELLS
+    )
+    ,IF(SV, CONFIGURE
+    ,   botvalue            =   500
+    )
 )
 
 #undef WITH
+#undef CONFIGURE
+#undef DEFINE
index 563ece2f71c131922cc6e2d32b2fe3e5cee54e92..15947704643ba22f278a93355846473a27ebc209 100644 (file)
@@ -2,50 +2,65 @@
 #include "../../../server/t_items.qh"
 
 #define WITH(it) this.m_##it;
+#define CONFIGURE(...) MAP(WITH, __VA_ARGS__)
+#define DEFINE(id, ...) REGISTER_ITEM(id, Armor, MAP(IDENTITY, __VA_ARGS__))
 
-#define REGISTER_ARMOR(id, ...)         \
-    REGISTER_ITEM(id, Armor, LAMBDA({   \
-        MAP(WITH, __VA_ARGS__)          \
-    }))
-
-REGISTER_ARMOR(ArmorSmall
-    , 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
+DEFINE(ArmorSmall
+    ,IF(ALL, CONFIGURE
+    ,   model               =   "models/items/item_armor_small.md3"
+    ,   sound               =   "misc/armor1.wav"
+    ,   name                =   "5 Armor"
+    ,   itemid              =   IT_ARMOR_SHARD
+    )
+    ,IF(SV, CONFIGURE
+    ,   botvalue            =   BOT_PICKUP_RATING_LOW
+    ,   respawntime         =   SPAWNTIME_SHORT
+    ,   respawntimejitter   =   SPAWNTIME_SHORT
+    )
 )
 
-REGISTER_ARMOR(ArmorMedium
-    , 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
+DEFINE(ArmorMedium
+    ,IF(ALL, CONFIGURE
+    ,   model               =   "models/items/item_armor_medium.md3"
+    ,   sound               =   "misc/armor10.wav"
+    ,   name                =   "25 Armor"
+    ,   itemid              =   IT_ARMOR
+    )
+    ,IF(SV, CONFIGURE
+    ,   botvalue            =   BOT_PICKUP_RATING_MID
+    ,   respawntime         =   SPAWNTIME_MEDIUM
+    ,   respawntimejitter   =   SPAWNTIME_MEDIUM
+    )
 )
 
-REGISTER_ARMOR(ArmorBig
-    , 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?
+DEFINE(ArmorBig
+    ,IF(ALL, CONFIGURE
+    ,   model               =   "models/items/item_armor_big.md3"
+    ,   sound               =   "misc/armor17_5.wav"
+    ,   name                =   "50 Armor"
+    ,   itemid              =   IT_ARMOR
+    )
+    ,IF(SV, CONFIGURE
+    ,   botvalue            =   20000 // FIXME: higher than BOT_PICKUP_RATING_HIGH?
+    ,   respawntime         =   SPAWNTIME_LONG
+    ,   respawntimejitter   =   SPAWNTIME_LONG
+    )
 )
 
-REGISTER_ARMOR(ArmorLarge
-    , 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
+DEFINE(ArmorLarge
+    ,IF(ALL, CONFIGURE
+    ,   model               =   "models/items/item_armor_large.md3"
+    ,   sound               =   "misc/armor25.wav"
+    ,   name                =   "100 Armor"
+    ,   itemid              =   IT_ARMOR
+    )
+    ,IF(SV, CONFIGURE
+    ,   botvalue            =   BOT_PICKUP_RATING_HIGH
+    ,   respawntime         =   SPAWNTIME_LONG
+    ,   respawntimejitter   =   SPAWNTIME_LONG
+    )
 )
 
 #undef WITH
+#undef CONFIGURE
+#undef DEFINE
index 33f6ccfb0ad881ec7cd94238afc7a79d511ec7bb..fb2f23f8c3601a382e6085a7fe051935d0fd9a4c 100644 (file)
@@ -2,50 +2,65 @@
 #include "../../../server/t_items.qh"
 
 #define WITH(it) this.m_##it;
+#define CONFIGURE(...) MAP(WITH, __VA_ARGS__)
+#define DEFINE(id, ...) REGISTER_ITEM(id, Health, MAP(IDENTITY, __VA_ARGS__))
 
-#define REGISTER_HEALTH(id, ...)        \
-    REGISTER_ITEM(id, Health, LAMBDA({  \
-        MAP(WITH, __VA_ARGS__)          \
-    }))
-
-REGISTER_HEALTH(HealthSmall
-    , 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
+DEFINE(HealthSmall
+    ,IF(ALL, CONFIGURE
+    ,   model               =   "models/items/g_h1.md3"
+    ,   sound               =   "misc/minihealth.wav"
+    ,   name                =   "5 Health"
+    ,   itemid              =   IT_5HP
+    )
+    ,IF(SV, CONFIGURE
+    ,   botvalue            =   BOT_PICKUP_RATING_LOW
+    ,   respawntime         =   SPAWNTIME_SHORT
+    ,   respawntimejitter   =   SPAWNTIME_SHORT
+    )
 )
 
-REGISTER_HEALTH(HealthMedium
-    , 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
+DEFINE(HealthMedium
+    ,IF(ALL, CONFIGURE
+    ,   model               =   "models/items/g_h25.md3"
+    ,   sound               =   "misc/mediumhealth.wav"
+    ,   name                =   "25 Health"
+    ,   itemid              =   IT_25HP
+    )
+    ,IF(SV, CONFIGURE
+    ,   botvalue            =   BOT_PICKUP_RATING_MID
+    ,   respawntime         =   SPAWNTIME_SHORT
+    ,   respawntimejitter   =   SPAWNTIME_SHORT
+    )
 )
 
-REGISTER_HEALTH(HealthLarge
-    , 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
+DEFINE(HealthLarge
+    ,IF(ALL, CONFIGURE
+    ,   model               =   "models/items/g_h50.md3"
+    ,   sound               =   "misc/mediumhealth.wav"
+    ,   name                =   "50 Health"
+    ,   itemid              =   IT_25HP
+    )
+    ,IF(SV, CONFIGURE
+    ,   botvalue            =   BOT_PICKUP_RATING_MID
+    ,   respawntime         =   SPAWNTIME_MEDIUM
+    ,   respawntimejitter   =   SPAWNTIME_MEDIUM
+    )
 )
 
-REGISTER_HEALTH(HealthMega
-    , 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
+DEFINE(HealthMega
+    ,IF(ALL, CONFIGURE
+    ,   model               =   "models/items/g_h100.md3"
+    ,   sound               =   "misc/megahealth.wav"
+    ,   name                =   "100 Health"
+    ,   itemid              =   IT_HEALTH
+    )
+    ,IF(SV, CONFIGURE
+    ,   botvalue            =   BOT_PICKUP_RATING_HIGH
+    ,   respawntime         =   SPAWNTIME_LONG
+    ,   respawntimejitter   =   SPAWNTIME_LONG
+    )
 )
 
 #undef WITH
+#undef CONFIGURE
+#undef DEFINE
index 7e814e0b75c5273f76612df674279e7e7b6a5c3f..5e0d610fccde091117a9c4154ee96cedcf3d27bc 100644 (file)
@@ -5,11 +5,13 @@ CLASS(Pickup, GameItem)
     METHOD(Pickup, respondTo, bool(entity, int))
     ATTRIB(Pickup, m_model, string, string_null)
     ATTRIB(Pickup, m_sound, string, string_null)
-    ATTRIB(Pickup, m_respawntime, int, 0)
-    ATTRIB(Pickup, m_respawntimejitter, int, 0)
     ATTRIB(Pickup, m_name, string, string_null)
     ATTRIB(Pickup, m_itemid, int, 0)
+#ifdef SVQC
     ATTRIB(Pickup, m_botvalue, int, 0)
+    ATTRIB(Pickup, m_respawntime, int, 0)
+    ATTRIB(Pickup, m_respawntimejitter, int, 0)
+#endif
 ENDCLASS(Pickup)
 
 #define SPAWNTIMES(_) \
index fbc43bdc5c8fb34c58391d9b0b7fba4eebf1bd20..45a37302274e7ebffbef036f49f16e8119c22581 100644 (file)
 #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 IDENTITY(it) it
+
+#ifdef SVQC
+    #define SV(f, ...) f(__VA_ARGS__)
+#else
+    #define SV(f, ...)
+#endif
+
+#ifdef CSQC
+    #define CL(f, ...) f(__VA_ARGS__)
+#else
+    #define CL(f, ...)
+#endif
+
+#define ALL(f, ...) f(__VA_ARGS__)
+
+#define IF(pred, f, ...) pred(f, __VA_ARGS__)
+
 #define BIT(n) (1 << (n))
 #ifndef BRANCHLESS_BITSET
     #define BITSET(var, mask, flag) (flag ? (var) | (mask) : (var) &~ (mask))