From cc795f09aace41eb64e988c37af78fa5f8af17fc Mon Sep 17 00:00:00 2001 From: TimePath Date: Tue, 11 Aug 2015 12:28:51 +1000 Subject: [PATCH] Simplify item definitions --- qcsrc/common/items/item.qh | 4 +- qcsrc/common/items/item/ammo.qc | 94 +++++++----------- qcsrc/common/items/item/ammo.qh | 2 + qcsrc/common/items/item/armor.qc | 96 ++++++++----------- qcsrc/common/items/item/buff.qc | 2 +- qcsrc/common/items/item/health.qc | 96 ++++++++----------- qcsrc/common/items/item/jetpack.qc | 78 +++++++-------- qcsrc/common/items/item/powerup.qc | 48 +++------- qcsrc/common/items/item/powerup.qh | 14 ++- .../server/mutators/mutator_instagib_items.qc | 43 ++++----- 10 files changed, 194 insertions(+), 283 deletions(-) diff --git a/qcsrc/common/items/item.qh b/qcsrc/common/items/item.qh index 43231cc1f..507ca93e0 100644 --- a/qcsrc/common/items/item.qh +++ b/qcsrc/common/items/item.qh @@ -12,9 +12,9 @@ ENDCLASS(GameItem) int ITEM_COUNT; /** If you register a new item, make sure to add it to all.inc */ -#define REGISTER_ITEM(id, class, body) \ +#define REGISTER_ITEM(id, class) \ entity ITEM_##id; \ - void RegisterItems_init_##id(entity this) { body } \ + void RegisterItems_init_##id(entity this) {} \ void RegisterItems_##id() { \ entity this = NEW(class); \ ITEM_##id = this; \ diff --git a/qcsrc/common/items/item/ammo.qc b/qcsrc/common/items/item/ammo.qc index 276e6bbe6..58f30fb84 100644 --- a/qcsrc/common/items/item/ammo.qc +++ b/qcsrc/common/items/item/ammo.qc @@ -3,67 +3,43 @@ #include "../../../server/t_items.qh" #endif -#define WITH(it) this.m_##it; -#define CONFIGURE(...) MAP(WITH, __VA_ARGS__) -#define DEFINE(id) \ - REGISTER_ITEM(id, Ammo, LAMBDA( \ - IF(SV, CONFIGURE \ - , respawntime = GET(g_pickup_respawntime_ammo) \ - , respawntimejitter = GET(g_pickup_respawntimejitter_ammo) \ - ) \ - )) - -DEFINE(Bullets) { - APPLY(CONFIGURE - , model = "models/items/a_bullets.mdl" - , name = "bullets" - ) - IF(SV, CONFIGURE - , botvalue = 2000 - , itemid = IT_NAILS - ) +REGISTER_ITEM(Bullets, Ammo) { + this.m_model = "models/items/a_bullets.mdl"; + this.m_name = "bullets"; +#ifdef SVQC + this.m_botvalue = 2000; + this.m_itemid = IT_NAILS; +#endif } -DEFINE(Cells) { - APPLY(CONFIGURE - , model = "models/items/a_cells.md3" - , name = "cells" - ) - IF(SV, CONFIGURE - , botvalue = 2000 - , itemid = IT_CELLS - ) +REGISTER_ITEM(Cells, Ammo) { + this.m_model = "models/items/a_cells.md3"; + this.m_name = "cells"; +#ifdef SVQC + this.m_botvalue = 2000; + this.m_itemid = IT_CELLS; +#endif } -DEFINE(Plasma) { - APPLY(CONFIGURE - , model = "models/items/a_cells.md3" - , name = "plasma" - ) - IF(SV, CONFIGURE - , botvalue = 2000 - , itemid = IT_PLASMA - ) +REGISTER_ITEM(Plasma, Ammo) { + this.m_model = "models/items/a_cells.md3"; + this.m_name = "plasma"; +#ifdef SVQC + this.m_botvalue = 2000; + this.m_itemid = IT_PLASMA; +#endif } -DEFINE(Rockets) { - APPLY(CONFIGURE - , model = "models/items/a_rockets.md3" - , name = "rockets" - ) - IF(SV, CONFIGURE - , botvalue = 3000 - , itemid = IT_ROCKETS - ) +REGISTER_ITEM(Rockets, Ammo) { + this.m_model = "models/items/a_rockets.md3"; + this.m_name = "rockets"; +#ifdef SVQC + this.m_botvalue = 3000; + this.m_itemid = IT_ROCKETS; +#endif } -DEFINE(Shells) { - APPLY(CONFIGURE - , model = "models/items/a_shells.md3" - , name = "shells" - ) - IF(SV, CONFIGURE - , botvalue = 500 - , itemid = IT_SHELLS - ) +REGISTER_ITEM(Shells, Ammo) { + this.m_model = "models/items/a_shells.md3"; + this.m_name = "shells"; +#ifdef SVQC + this.m_botvalue = 500; + this.m_itemid = IT_SHELLS; +#endif } - -#undef WITH -#undef CONFIGURE -#undef DEFINE diff --git a/qcsrc/common/items/item/ammo.qh b/qcsrc/common/items/item/ammo.qh index 41e2ac831..84f20483e 100644 --- a/qcsrc/common/items/item/ammo.qh +++ b/qcsrc/common/items/item/ammo.qh @@ -4,6 +4,8 @@ CLASS(Ammo, Pickup) #ifdef SVQC ATTRIB(Ammo, m_pickupevalfunc, float(entity player, entity item), commodity_pickupevalfunc) + ATTRIB(Ammo, m_respawntime, float(), GET(g_pickup_respawntime_ammo)) + ATTRIB(Ammo, m_respawntimejitter, float(), GET(g_pickup_respawntimejitter_ammo)) #endif ENDCLASS(Ammo) #endif diff --git a/qcsrc/common/items/item/armor.qc b/qcsrc/common/items/item/armor.qc index 295ff117e..0db9d1f70 100644 --- a/qcsrc/common/items/item/armor.qc +++ b/qcsrc/common/items/item/armor.qc @@ -3,66 +3,50 @@ #include "../../../server/t_items.qh" #endif -#define WITH(it) this.m_##it; -#define CONFIGURE(...) MAP(WITH, __VA_ARGS__) -#define DEFINE(id) REGISTER_ITEM(id, Armor, ) - -DEFINE(ArmorSmall) { - APPLY(CONFIGURE - , model = "models/items/item_armor_small.md3" - , sound = "misc/armor1.wav" - , name = "5 Armor" - ) - IF(SV, CONFIGURE - , botvalue = BOT_PICKUP_RATING_LOW - , itemid = IT_ARMOR_SHARD - , respawntime = GET(g_pickup_respawntime_short) - , respawntimejitter = GET(g_pickup_respawntimejitter_short) - ) +REGISTER_ITEM(ArmorSmall, Armor) { + this.m_model = "models/items/item_armor_small.md3"; + this.m_sound = "misc/armor1.wav"; + this.m_name = "5 Armor"; +#ifdef SVQC + this.m_botvalue = BOT_PICKUP_RATING_LOW; + this.m_itemid = IT_ARMOR_SHARD; + this.m_respawntime = GET(g_pickup_respawntime_short); + this.m_respawntimejitter = GET(g_pickup_respawntimejitter_short); +#endif } -DEFINE(ArmorMedium) { - APPLY(CONFIGURE - , model = "models/items/item_armor_medium.md3" - , sound = "misc/armor10.wav" - , name = "25 Armor" - ) - IF(SV, CONFIGURE - , botvalue = BOT_PICKUP_RATING_MID - , itemid = IT_ARMOR - , respawntime = GET(g_pickup_respawntime_medium) - , respawntimejitter = GET(g_pickup_respawntimejitter_medium) - ) +REGISTER_ITEM(ArmorMedium, Armor) { + this.m_model = "models/items/item_armor_medium.md3"; + this.m_sound = "misc/armor10.wav"; + this.m_name = "25 Armor"; +#ifdef SVQC + this.m_botvalue = BOT_PICKUP_RATING_MID; + this.m_itemid = IT_ARMOR; + this.m_respawntime = GET(g_pickup_respawntime_medium); + this.m_respawntimejitter = GET(g_pickup_respawntimejitter_medium); +#endif } -DEFINE(ArmorBig) { - APPLY(CONFIGURE - , model = "models/items/item_armor_big.md3" - , sound = "misc/armor17_5.wav" - , name = "50 Armor" - ) - IF(SV, CONFIGURE - , botvalue = 20000 // FIXME: higher than BOT_PICKUP_RATING_HIGH? - , itemid = IT_ARMOR - , respawntime = GET(g_pickup_respawntime_long) - , respawntimejitter = GET(g_pickup_respawntimejitter_long) - ) +REGISTER_ITEM(ArmorBig, Armor) { + this.m_model = "models/items/item_armor_big.md3"; + this.m_sound = "misc/armor17_5.wav"; + this.m_name = "50 Armor"; +#ifdef SVQC + this.m_botvalue = 20000; // FIXME: higher than BOT_PICKUP_RATING_HIGH? + this.m_itemid = IT_ARMOR; + this.m_respawntime = GET(g_pickup_respawntime_long); + this.m_respawntimejitter = GET(g_pickup_respawntimejitter_long); +#endif } -DEFINE(ArmorLarge) { - APPLY(CONFIGURE - , model = "models/items/item_armor_large.md3" - , sound = "misc/armor25.wav" - , name = "100 Armor" - ) - IF(SV, CONFIGURE - , botvalue = BOT_PICKUP_RATING_HIGH - , itemid = IT_ARMOR - , respawntime = GET(g_pickup_respawntime_long) - , respawntimejitter = GET(g_pickup_respawntimejitter_long) - ) +REGISTER_ITEM(ArmorLarge, Armor) { + this.m_model = "models/items/item_armor_large.md3"; + this.m_sound = "misc/armor25.wav"; + this.m_name = "100 Armor"; +#ifdef SVQC + this.m_botvalue = BOT_PICKUP_RATING_HIGH; + this.m_itemid = IT_ARMOR; + this.m_respawntime = GET(g_pickup_respawntime_long); + this.m_respawntimejitter = GET(g_pickup_respawntimejitter_long); +#endif } - -#undef WITH -#undef CONFIGURE -#undef DEFINE diff --git a/qcsrc/common/items/item/buff.qc b/qcsrc/common/items/item/buff.qc index 27a9b9ecd..1cad2f2a9 100644 --- a/qcsrc/common/items/item/buff.qc +++ b/qcsrc/common/items/item/buff.qc @@ -1,3 +1,3 @@ #include "buff.qh" -REGISTER_ITEM(DefaultBuff, Buff, ); +REGISTER_ITEM(DefaultBuff, Buff); diff --git a/qcsrc/common/items/item/health.qc b/qcsrc/common/items/item/health.qc index bd0558690..4867273a6 100644 --- a/qcsrc/common/items/item/health.qc +++ b/qcsrc/common/items/item/health.qc @@ -3,66 +3,50 @@ #include "../../../server/t_items.qh" #endif -#define WITH(it) this.m_##it; -#define CONFIGURE(...) MAP(WITH, __VA_ARGS__) -#define DEFINE(id) REGISTER_ITEM(id, Health, ) - -DEFINE(HealthSmall) { - APPLY(CONFIGURE - , model = "models/items/g_h1.md3" - , sound = "misc/minihealth.wav" - , name = "5 Health" - ) - IF(SV, CONFIGURE - , botvalue = BOT_PICKUP_RATING_LOW - , itemid = IT_5HP - , respawntime = GET(g_pickup_respawntime_short) - , respawntimejitter = GET(g_pickup_respawntimejitter_short) - ) +REGISTER_ITEM(HealthSmall, Health) { + this.m_model = "models/items/g_h1.md3"; + this.m_sound = "misc/minihealth.wav"; + this.m_name = "5 Health"; +#ifdef SVQC + this.m_botvalue = BOT_PICKUP_RATING_LOW; + this.m_itemid = IT_5HP; + this.m_respawntime = GET(g_pickup_respawntime_short); + this.m_respawntimejitter = GET(g_pickup_respawntimejitter_short); +#endif } -DEFINE(HealthMedium) { - APPLY(CONFIGURE - , model = "models/items/g_h25.md3" - , sound = "misc/mediumhealth.wav" - , name = "25 Health" - ) - IF(SV, CONFIGURE - , botvalue = BOT_PICKUP_RATING_MID - , itemid = IT_25HP - , respawntime = GET(g_pickup_respawntime_short) - , respawntimejitter = GET(g_pickup_respawntimejitter_short) - ) +REGISTER_ITEM(HealthMedium, Health) { + this.m_model = "models/items/g_h25.md3"; + this.m_sound = "misc/mediumhealth.wav"; + this.m_name = "25 Health"; +#ifdef SVQC + this.m_botvalue = BOT_PICKUP_RATING_MID; + this.m_itemid = IT_25HP; + this.m_respawntime = GET(g_pickup_respawntime_short); + this.m_respawntimejitter = GET(g_pickup_respawntimejitter_short); +#endif } -DEFINE(HealthLarge) { - APPLY(CONFIGURE - , model = "models/items/g_h50.md3" - , sound = "misc/mediumhealth.wav" - , name = "50 Health" - ) - IF(SV, CONFIGURE - , botvalue = BOT_PICKUP_RATING_MID - , itemid = IT_25HP - , respawntime = GET(g_pickup_respawntime_medium) - , respawntimejitter = GET(g_pickup_respawntimejitter_medium) - ) +REGISTER_ITEM(HealthLarge, Health) { + this.m_model = "models/items/g_h50.md3"; + this.m_sound = "misc/mediumhealth.wav"; + this.m_name = "50 Health"; +#ifdef SVQC + this.m_botvalue = BOT_PICKUP_RATING_MID; + this.m_itemid = IT_25HP; + this.m_respawntime = GET(g_pickup_respawntime_medium); + this.m_respawntimejitter = GET(g_pickup_respawntimejitter_medium); +#endif } -DEFINE(HealthMega) { - APPLY(CONFIGURE - , model = "models/items/g_h100.md3" - , sound = "misc/megahealth.wav" - , name = "100 Health" - ) - IF(SV, CONFIGURE - , botvalue = BOT_PICKUP_RATING_HIGH - , itemid = IT_HEALTH - , respawntime = GET(g_pickup_respawntime_long) - , respawntimejitter = GET(g_pickup_respawntimejitter_long) - ) +REGISTER_ITEM(HealthMega, Health) { + this.m_model = "models/items/g_h100.md3"; + this.m_sound = "misc/megahealth.wav"; + this.m_name = "100 Health"; +#ifdef SVQC + this.m_botvalue = BOT_PICKUP_RATING_HIGH; + this.m_itemid = IT_HEALTH; + this.m_respawntime = GET(g_pickup_respawntime_long); + this.m_respawntimejitter = GET(g_pickup_respawntimejitter_long); +#endif } - -#undef WITH -#undef CONFIGURE -#undef DEFINE diff --git a/qcsrc/common/items/item/jetpack.qc b/qcsrc/common/items/item/jetpack.qc index 45a256b1b..ad4ab2d0d 100644 --- a/qcsrc/common/items/item/jetpack.qc +++ b/qcsrc/common/items/item/jetpack.qc @@ -3,54 +3,40 @@ #include "../../../server/constants.qh" #endif -#define WITH(it) this.m_##it; -#define CONFIGURE(...) MAP(WITH, __VA_ARGS__) -#define DEFINE(id) REGISTER_ITEM(id, Pickup, ) - -DEFINE(Jetpack) { - APPLY(CONFIGURE - , model = "models/items/g_jetpack.md3" - , name = "Jet pack" - ) - IF(SV, CONFIGURE - , botvalue = BOT_PICKUP_RATING_LOW - , itemflags = FL_POWERUP - , itemid = IT_JETPACK - , pickupevalfunc = commodity_pickupevalfunc - , respawntime = GET(g_pickup_respawntime_powerup) - , respawntimejitter = GET(g_pickup_respawntimejitter_powerup) - ) +REGISTER_ITEM(Jetpack, Pickup) { + this.m_model = "models/items/g_jetpack.md3"; + this.m_name = "Jet pack"; +#ifdef SVQC + this.m_botvalue = BOT_PICKUP_RATING_LOW; + this.m_itemflags = FL_POWERUP; + this.m_itemid = IT_JETPACK; + this.m_pickupevalfunc = commodity_pickupevalfunc; + this.m_respawntime = GET(g_pickup_respawntime_powerup); + this.m_respawntimejitter = GET(g_pickup_respawntimejitter_powerup); +#endif } -DEFINE(JetpackFuel) { - APPLY(CONFIGURE - , model = "models/items/g_fuel.md3" - , name = "Fuel" - ) - IF(SV, CONFIGURE - , botvalue = BOT_PICKUP_RATING_LOW - , itemid = IT_FUEL - , pickupevalfunc = commodity_pickupevalfunc - , respawntime = GET(g_pickup_respawntime_ammo) - , respawntimejitter = GET(g_pickup_respawntimejitter_ammo) - ) +REGISTER_ITEM(JetpackFuel, Pickup) { + this.m_model = "models/items/g_fuel.md3"; + this.m_name = "Fuel"; +#ifdef SVQC + this.m_botvalue = BOT_PICKUP_RATING_LOW; + this.m_itemid = IT_FUEL; + this.m_pickupevalfunc = commodity_pickupevalfunc; + this.m_respawntime = GET(g_pickup_respawntime_ammo); + this.m_respawntimejitter = GET(g_pickup_respawntimejitter_ammo); +#endif } -DEFINE(JetpackRegen) { - APPLY(CONFIGURE - , model = "models/items/g_fuelregen.md3" - , name = "Fuel regenerator" - ) - IF(SV, CONFIGURE - , botvalue = BOT_PICKUP_RATING_LOW - , itemflags = FL_POWERUP - , itemid = IT_FUEL_REGEN - , pickupevalfunc = commodity_pickupevalfunc - , respawntime = GET(g_pickup_respawntime_powerup) - , respawntimejitter = GET(g_pickup_respawntimejitter_powerup) - ) +REGISTER_ITEM(JetpackRegen, Pickup) { + this.m_model = "models/items/g_fuelregen.md3"; + this.m_name = "Fuel regenerator"; +#ifdef SVQC + this.m_botvalue = BOT_PICKUP_RATING_LOW; + this.m_itemflags = FL_POWERUP; + this.m_itemid = IT_FUEL_REGEN; + this.m_pickupevalfunc = commodity_pickupevalfunc; + this.m_respawntime = GET(g_pickup_respawntime_powerup); + this.m_respawntimejitter = GET(g_pickup_respawntimejitter_powerup); +#endif } - -#undef WITH -#undef CONFIGURE -#undef DEFINE diff --git a/qcsrc/common/items/item/powerup.qc b/qcsrc/common/items/item/powerup.qc index 86e3a7d66..0f025aed8 100644 --- a/qcsrc/common/items/item/powerup.qc +++ b/qcsrc/common/items/item/powerup.qc @@ -1,39 +1,19 @@ #include "powerup.qh" #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 \ - , botvalue = 100000 \ - , itemflags = FL_POWERUP \ - , respawntime = GET(g_pickup_respawntime_powerup) \ - , respawntimejitter = GET(g_pickup_respawntimejitter_powerup) \ - ) \ - )) - -DEFINE(Strength) { - APPLY(CONFIGURE - , model = "models/items/g_strength.md3" - , sound = "misc/powerup.wav" - , name = "Strength Powerup" - ) - IF(SV, CONFIGURE - , itemid = IT_STRENGTH - ) +REGISTER_ITEM(Strength, Powerup) { + this.m_model = "models/items/g_strength.md3"; + this.m_sound = "misc/powerup.wav"; + this.m_name = "Strength Powerup"; +#ifdef SVQC + this.m_itemid = IT_STRENGTH; +#endif } -DEFINE(Shield) { - APPLY(CONFIGURE - , model = "models/items/g_invincible.md3" - , sound = "misc/powerup_shield.wav" - , name = "Shield" - ) - IF(SV, CONFIGURE - , itemid = IT_INVINCIBLE - ) +REGISTER_ITEM(Shield, Powerup) { + this.m_model = "models/items/g_invincible.md3"; + this.m_sound = "misc/powerup_shield.wav"; + this.m_name = "Shield"; +#ifdef SVQC + this.m_itemid = IT_INVINCIBLE; +#endif } - -#undef WITH -#undef CONFIGURE -#undef DEFINE diff --git a/qcsrc/common/items/item/powerup.qh b/qcsrc/common/items/item/powerup.qh index d27c1e60f..d78bd5563 100644 --- a/qcsrc/common/items/item/powerup.qh +++ b/qcsrc/common/items/item/powerup.qh @@ -1,12 +1,18 @@ +#ifdef SVQC + // For FL_POWERUP + #include "../../../server/constants.qh" +#endif + #ifndef POWERUP_H #define POWERUP_H #include "pickup.qh" CLASS(Powerup, Pickup) -ENDCLASS(Powerup) - #ifdef SVQC -// For FL_POWERUP -#include "../../../server/constants.qh" + ATTRIB(Powerup, m_botvalue, int, 100000) + ATTRIB(Powerup, m_itemflags, int, FL_POWERUP) + ATTRIB(Powerup, m_respawntime, float(), GET(g_pickup_respawntime_powerup)) + ATTRIB(Powerup, m_respawntimejitter, float(), GET(g_pickup_respawntimejitter_powerup)) #endif +ENDCLASS(Powerup) #endif diff --git a/qcsrc/server/mutators/mutator_instagib_items.qc b/qcsrc/server/mutators/mutator_instagib_items.qc index f2a0050e0..cd72aee3b 100644 --- a/qcsrc/server/mutators/mutator_instagib_items.qc +++ b/qcsrc/server/mutators/mutator_instagib_items.qc @@ -8,33 +8,26 @@ float instagib_respawntimejitter_ammo = 0; GETTER(float, instagib_respawntime_ammo) GETTER(float, instagib_respawntimejitter_ammo) -REGISTER_ITEM(VaporizerCells, Pickup, ) { - APPLY(CONFIGURE - , model = "models/items/a_cells.md3" - , sound = "misc/itempickup.wav" - , name = "Vaporizer Ammo" - ) - IF(SV, CONFIGURE - , botvalue = 100 - , itemid = IT_CELLS - , respawntime = GET(instagib_respawntime_ammo) - , respawntimejitter = GET(instagib_respawntimejitter_ammo) - ) +REGISTER_ITEM(VaporizerCells, Ammo) { + this.m_model = "models/items/a_cells.md3"; + this.m_sound = "misc/itempickup.wav"; + this.m_name = "Vaporizer Ammo"; +#ifdef SVQC + this.m_botvalue = 100; + this.m_itemid = IT_CELLS; + this.m_respawntime = GET(instagib_respawntime_ammo); + this.m_respawntimejitter = GET(instagib_respawntimejitter_ammo); +#endif } -REGISTER_ITEM(ExtraLife, Pickup, ) { - APPLY(CONFIGURE - , model = "models/items/g_h100.md3" - , sound = "misc/megahealth.wav" - , name = "Extralife" - ) - IF(SV, CONFIGURE - , botvalue = BOT_PICKUP_RATING_HIGH - , itemflags = FL_POWERUP - , itemid = IT_NAILS - , respawntime = GET(g_pickup_respawntime_powerup) - , respawntimejitter = GET(g_pickup_respawntimejitter_powerup) - ) +REGISTER_ITEM(ExtraLife, Powerup) { + this.m_model = "models/items/g_h100.md3"; + this.m_sound = "misc/megahealth.wav"; + this.m_name = "Extralife"; +#ifdef SVQC + this.m_itemid = IT_NAILS; + this.m_botvalue = BOT_PICKUP_RATING_HIGH; +#endif } #undef WITH -- 2.39.2