From: TimePath Date: Tue, 12 May 2015 03:26:25 +0000 (+1000) Subject: Do something awesome with macros X-Git-Tag: xonotic-v0.8.1~53^2~15 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=316d7a2a6d09b95fa6607580c648b4ed36fa9b5c;p=xonotic%2Fxonotic-data.pk3dir.git Do something awesome with macros --- diff --git a/qcsrc/common/items/item/ammo.qc b/qcsrc/common/items/item/ammo.qc index a2381ab99..dc0909d1e 100644 --- a/qcsrc/common/items/item/ammo.qc +++ b/qcsrc/common/items/item/ammo.qc @@ -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 diff --git a/qcsrc/common/items/item/armor.qc b/qcsrc/common/items/item/armor.qc index 3dac22a59..563ece2f7 100644 --- a/qcsrc/common/items/item/armor.qc +++ b/qcsrc/common/items/item/armor.qc @@ -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 diff --git a/qcsrc/common/items/item/health.qc b/qcsrc/common/items/item/health.qc index 47df52ebe..33f6ccfb0 100644 --- a/qcsrc/common/items/item/health.qc +++ b/qcsrc/common/items/item/health.qc @@ -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 diff --git a/qcsrc/common/util-pre.qh b/qcsrc/common/util-pre.qh index a1ac7dc7a..91094e11f 100644 --- a/qcsrc/common/util-pre.qh +++ b/qcsrc/common/util-pre.qh @@ -51,6 +51,34 @@ [[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))