From: TimePath Date: Sun, 10 May 2015 12:15:27 +0000 (+1000) Subject: Use the new item system for health and armor X-Git-Tag: xonotic-v0.8.1~53^2~16 X-Git-Url: https://git.xonotic.org/?a=commitdiff_plain;h=b800544899fb0c516022ab01b21b94ef6db84ab1;p=xonotic%2Fxonotic-data.pk3dir.git Use the new item system for health and armor --- diff --git a/qcsrc/common/items/all.inc b/qcsrc/common/items/all.inc index 24f795572..aeee8d3e6 100644 --- a/qcsrc/common/items/all.inc +++ b/qcsrc/common/items/all.inc @@ -1,4 +1,6 @@ #include "item.qc" #include "item/ammo.qc" +#include "item/armor.qc" #include "item/buff.qc" +#include "item/health.qc" diff --git a/qcsrc/common/items/item/ammo.qc b/qcsrc/common/items/item/ammo.qc index 9bce0839a..a2381ab99 100644 --- a/qcsrc/common/items/item/ammo.qc +++ b/qcsrc/common/items/item/ammo.qc @@ -1,57 +1,49 @@ #include "ammo.qh" #include "../../../server/t_items.qh" -#define REGISTER_AMMO(id, model, sound, name, itemid, basevalue) \ -REGISTER_ITEM(id, Ammo, LAMBDA({ \ - this.ammoModel = model; \ - this.ammoSound = sound; \ - this.ammoName = name; \ - this.ammoId = itemid; \ - this.ammoQuantity = basevalue; \ +#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; \ })) -REGISTER_AMMO(Bullets, - "models/items/a_bullets.mdl", - "misc/itempickup.wav", - "bullets", - IT_NAILS, - 2000 +REGISTER_AMMO(Bullets + , "models/items/a_bullets.mdl" + , "misc/itempickup.wav" + , "bullets" + , IT_NAILS + , 2000 ) -REGISTER_AMMO(Cells, - "models/items/a_cells.md3", - "misc/itempickup.wav", - "cells", - IT_ROCKETS, - 2000 +REGISTER_AMMO(Cells + , "models/items/a_cells.md3" + , "misc/itempickup.wav" + , "cells" + , IT_ROCKETS + , 2000 ) -REGISTER_AMMO(Plasma, - "models/items/a_cells.md3", - "misc/itempickup.wav", - "plasma", - IT_ROCKETS, - 2000 +REGISTER_AMMO(Plasma + , "models/items/a_cells.md3" + , "misc/itempickup.wav" + , "plasma" + , IT_ROCKETS + , 2000 ) -REGISTER_AMMO(Rockets, - "models/items/a_rockets.md3", - "misc/itempickup.wav", - "rockets", - IT_ROCKETS, - 3000 +REGISTER_AMMO(Rockets + , "models/items/a_rockets.md3" + , "misc/itempickup.wav" + , "rockets" + , IT_ROCKETS + , 3000 ) -REGISTER_AMMO(Shells, - "models/items/a_shells.md3", - "misc/itempickup.wav", - "shells", - IT_SHELLS, - 500 +REGISTER_AMMO(Shells + , "models/items/a_shells.md3" + , "misc/itempickup.wav" + , "shells" + , IT_SHELLS + , 500 ) - -bool Ammo_respondTo(entity this, int request) -{ - switch (request) { - default: return false; - case ITEM_SIGNAL(Default): - print(strcat(this.ammoName, " responding\n")); - return true; - } -} diff --git a/qcsrc/common/items/item/ammo.qh b/qcsrc/common/items/item/ammo.qh index 4ff7babfb..b7fcd13b2 100644 --- a/qcsrc/common/items/item/ammo.qh +++ b/qcsrc/common/items/item/ammo.qh @@ -1,12 +1,6 @@ #ifndef AMMO_H #define AMMO_H -#include "../item.qh" -CLASS(Ammo, GameItem) - METHOD(Ammo, respondTo, bool(entity, int)) - ATTRIB(Ammo, ammoModel, string, string_null) - ATTRIB(Ammo, ammoSound, string, string_null) - ATTRIB(Ammo, ammoName, string, string_null) - ATTRIB(Ammo, ammoId, int, 0) - ATTRIB(Ammo, ammoQuantity, int, 0) +#include "pickup.qh" +CLASS(Ammo, Pickup) ENDCLASS(Ammo) #endif diff --git a/qcsrc/common/items/item/armor.qc b/qcsrc/common/items/item/armor.qc new file mode 100644 index 000000000..3dac22a59 --- /dev/null +++ b/qcsrc/common/items/item/armor.qc @@ -0,0 +1,49 @@ +#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; \ +})) + +REGISTER_ARMOR(ArmorSmall + , "models/items/item_armor_small.md3" + , "misc/armor1.wav" + , SPAWNTIME_SHORT + , "5 Armor" + , IT_ARMOR_SHARD + , 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 +) + +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? +) + +REGISTER_ARMOR(ArmorLarge + , "models/items/item_armor_large.md3" + , "misc/armor25.wav" + , SPAWNTIME_LONG + , "100 Armor" + , IT_ARMOR + , BOT_PICKUP_RATING_HIGH +) diff --git a/qcsrc/common/items/item/armor.qh b/qcsrc/common/items/item/armor.qh new file mode 100644 index 000000000..3ce853c0a --- /dev/null +++ b/qcsrc/common/items/item/armor.qh @@ -0,0 +1,6 @@ +#ifndef ARMOR_H +#define ARMOR_H +#include "pickup.qh" +CLASS(Armor, Pickup) +ENDCLASS(Armor) +#endif diff --git a/qcsrc/common/items/item/health.qc b/qcsrc/common/items/item/health.qc new file mode 100644 index 000000000..47df52ebe --- /dev/null +++ b/qcsrc/common/items/item/health.qc @@ -0,0 +1,49 @@ +#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; \ +})) + +REGISTER_HEALTH(HealthSmall + , "models/items/g_h1.md3" + , "misc/minihealth.wav" + , SPAWNTIME_SHORT + , "5 Health" + , IT_5HP + , 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 +) + +REGISTER_HEALTH(HealthLarge + , "models/items/g_h50.md3" + , "misc/mediumhealth.wav" + , SPAWNTIME_MEDIUM + , "50 Health" + , IT_25HP + , 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 +) diff --git a/qcsrc/common/items/item/health.qh b/qcsrc/common/items/item/health.qh new file mode 100644 index 000000000..26d926ac3 --- /dev/null +++ b/qcsrc/common/items/item/health.qh @@ -0,0 +1,6 @@ +#ifndef HEALTH_H +#define HEALTH_H +#include "pickup.qh" +CLASS(Health, Pickup) +ENDCLASS(Health) +#endif diff --git a/qcsrc/common/items/item/pickup.qh b/qcsrc/common/items/item/pickup.qh new file mode 100644 index 000000000..7e814e0b7 --- /dev/null +++ b/qcsrc/common/items/item/pickup.qh @@ -0,0 +1,49 @@ +#ifndef PICKUP_H +#define PICKUP_H +#include "../item.qh" +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) + ATTRIB(Pickup, m_botvalue, int, 0) +ENDCLASS(Pickup) + +#define SPAWNTIMES(_) \ + _(WEAPON, weapon) \ + _(AMMO, ammo) \ + _(SHORT, short) \ + _(MEDIUM, medium) \ + _(LONG, long) \ + /**/ + +#define SPAWNTIMES_ENUM(id, idlc) SPAWNTIME_##id , +enum { SPAWNTIMES(SPAWNTIMES_ENUM) }; +#undef SPAWNTIMES_ENUM + +#ifdef SVQC +#include "../../../server/defs.qh" + +#define SPAWNTIMES_MAP(id, idlc) i == SPAWNTIME_##id ? g_pickup_respawntime_##idlc : +[[inline]] int spawntime(int i) { return SPAWNTIMES(SPAWNTIMES_MAP) 0; } +#undef SPAWNTIMES_MAP + +#define SPAWNTIMES_MAP(id, idlc) i == SPAWNTIME_##id ? g_pickup_respawntimejitter_##idlc : +[[inline]] int spawntimejitter(int i) { return SPAWNTIMES(SPAWNTIMES_MAP) 0; } +#undef SPAWNTIMES_MAP +#endif + +bool Pickup_respondTo(entity this, int request) +{ + switch (request) { + default: return false; + case ITEM_SIGNAL(Default): + print(strcat(this.m_name, " responding\n")); + return true; + } +} + +#endif diff --git a/qcsrc/common/oo.qh b/qcsrc/common/oo.qh index 02f992a34..63b17089e 100644 --- a/qcsrc/common/oo.qh +++ b/qcsrc/common/oo.qh @@ -35,35 +35,35 @@ entity spawnObject(entity this, entity) // Macro to hide this implementation detail #define NEW(cname) (spawn##cname(NULL, NULL)) -#define CLASS(cname, base) \ -entity spawn##cname(entity this, entity basevtbl) { \ - this = NEW(base); basevtbl = base##_vtbl; \ +#define CLASS(cname, base) \ +entity spawn##cname(entity this, entity basevtbl) { \ + this = NEW(base); basevtbl = base##_vtbl; \ } -#define METHOD(cname, name, prototype) \ -prototype cname##_##name; \ -.prototype name; \ -[[accumulate]] entity spawn##cname(entity this, entity basevtbl) { \ - this.name = cname##_##name; \ +#define METHOD(cname, name, prototype) \ +prototype cname##_##name; \ +.prototype name; \ +[[accumulate]] entity spawn##cname(entity this, entity basevtbl) { \ + this.name = cname##_##name; \ } -#define ATTRIB(cname, name, type, val) \ -.type name; \ -[[accumulate]] entity spawn##cname(entity this, entity basevtbl) { \ - this.name = val; \ +#define ATTRIB(cname, name, type, val) \ +.type name; \ +[[accumulate]] entity spawn##cname(entity this, entity basevtbl) { \ + this.name = val; \ } -#define ATTRIBARRAY(cname, name, type, cnt) \ +#define ATTRIBARRAY(cname, name, type, cnt) \ .type name[cnt]; -#define ENDCLASS(cname) \ -.bool instanceOf##cname; \ -entity cname##_vtbl; \ -[[last]] entity spawn##cname(entity this, entity basevtbl) { \ - this.instanceOf##cname = true; \ - this.classname = #cname; \ - if (!cname##_vtbl) cname##_vtbl = spawnVtbl(this, basevtbl); \ - return this; \ +#define ENDCLASS(cname) \ +.bool instanceOf##cname; \ +entity cname##_vtbl; \ +[[accumulate]] [[last]] entity spawn##cname(entity this, entity basevtbl) { \ + this.instanceOf##cname = true; \ + this.classname = #cname; \ + if (!cname##_vtbl) cname##_vtbl = spawnVtbl(this, basevtbl); \ + return this; \ } #define SUPER(cname) (cname##_vtbl.vtblbase) diff --git a/qcsrc/server/t_items.qc b/qcsrc/server/t_items.qc index cb507fc20..be2d5352e 100644 --- a/qcsrc/server/t_items.qc +++ b/qcsrc/server/t_items.qc @@ -1156,7 +1156,7 @@ void StartItem (string itemmodel, string pickupsound, float defaultrespawntime, void StartItemA (entity a) { - StartItem(a.ammoModel, a.ammoSound, g_pickup_respawntime_ammo, g_pickup_respawntimejitter_ammo, a.ammoName, a.ammoId, 0, 0, commodity_pickupevalfunc, a.ammoQuantity); + StartItem(a.m_model, a.m_sound, spawntime(a.m_respawntime), spawntimejitter(a.m_respawntimejitter), a.m_name, a.m_itemid, 0, 0, commodity_pickupevalfunc, a.m_botvalue); } void spawnfunc_item_rockets (void) { @@ -1227,7 +1227,7 @@ void spawnfunc_item_armor_small (void) { self.max_armorvalue = g_pickup_armorsmall_max; if(!self.pickup_anyway) self.pickup_anyway = g_pickup_armorsmall_anyway; - StartItem ("models/items/item_armor_small.md3", "misc/armor1.wav", g_pickup_respawntime_short, g_pickup_respawntimejitter_short, "5 Armor", IT_ARMOR_SHARD, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_LOW); + StartItemA (ITEM_ArmorSmall); } void spawnfunc_item_armor_medium (void) { @@ -1237,7 +1237,7 @@ void spawnfunc_item_armor_medium (void) { self.max_armorvalue = g_pickup_armormedium_max; if(!self.pickup_anyway) self.pickup_anyway = g_pickup_armormedium_anyway; - StartItem ("models/items/item_armor_medium.md3", "misc/armor10.wav", g_pickup_respawntime_medium, g_pickup_respawntimejitter_medium, "25 Armor", IT_ARMOR, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_MID); + StartItemA (ITEM_ArmorMedium); } void spawnfunc_item_armor_big (void) { @@ -1247,7 +1247,7 @@ void spawnfunc_item_armor_big (void) { self.max_armorvalue = g_pickup_armorbig_max; if(!self.pickup_anyway) self.pickup_anyway = g_pickup_armorbig_anyway; - StartItem ("models/items/item_armor_big.md3", "misc/armor17_5.wav", g_pickup_respawntime_long, g_pickup_respawntimejitter_long, "50 Armor", IT_ARMOR, 0, 0, commodity_pickupevalfunc, 20000); + StartItemA (ITEM_ArmorBig); } void spawnfunc_item_armor_large (void) { @@ -1257,7 +1257,7 @@ void spawnfunc_item_armor_large (void) { self.max_armorvalue = g_pickup_armorlarge_max; if(!self.pickup_anyway) self.pickup_anyway = g_pickup_armorlarge_anyway; - StartItem ("models/items/item_armor_large.md3", "misc/armor25.wav", g_pickup_respawntime_long, g_pickup_respawntimejitter_long, "100 Armor", IT_ARMOR, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_HIGH); + StartItemA (ITEM_ArmorLarge); } void spawnfunc_item_health_small (void) { @@ -1267,7 +1267,7 @@ void spawnfunc_item_health_small (void) { self.health = g_pickup_healthsmall; if(!self.pickup_anyway) self.pickup_anyway = g_pickup_healthsmall_anyway; - StartItem ("models/items/g_h1.md3", "misc/minihealth.wav", g_pickup_respawntime_short, g_pickup_respawntimejitter_short, "5 Health", IT_5HP, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_LOW); + StartItemA (ITEM_HealthSmall); } void spawnfunc_item_health_medium (void) { @@ -1277,7 +1277,7 @@ void spawnfunc_item_health_medium (void) { self.health = g_pickup_healthmedium; if(!self.pickup_anyway) self.pickup_anyway = g_pickup_healthmedium_anyway; - StartItem ("models/items/g_h25.md3", "misc/mediumhealth.wav", g_pickup_respawntime_short, g_pickup_respawntimejitter_short, "25 Health", IT_25HP, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_MID); + StartItemA (ITEM_HealthMedium); } void spawnfunc_item_health_large (void) { @@ -1287,17 +1287,17 @@ void spawnfunc_item_health_large (void) { self.health = g_pickup_healthlarge; if(!self.pickup_anyway) self.pickup_anyway = g_pickup_healthlarge_anyway; - StartItem ("models/items/g_h50.md3", "misc/mediumhealth.wav", g_pickup_respawntime_medium, g_pickup_respawntimejitter_medium, "50 Health", IT_25HP, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_MID); + StartItemA (ITEM_HealthLarge); } void spawnfunc_item_health_mega (void) { - if(!self.max_health) - self.max_health = g_pickup_healthmega_max; - if(!self.health) - self.health = g_pickup_healthmega; - if(!self.pickup_anyway) - self.pickup_anyway = g_pickup_healthmega_anyway; - StartItem ("models/items/g_h100.md3", "misc/megahealth.wav", g_pickup_respawntime_long, g_pickup_respawntimejitter_long, "100 Health", IT_HEALTH, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_HIGH); + if(!self.max_health) + self.max_health = g_pickup_healthmega_max; + if(!self.health) + self.health = g_pickup_healthmega; + if(!self.pickup_anyway) + self.pickup_anyway = g_pickup_healthmega_anyway; + StartItemA (ITEM_HealthMega); } // support old misnamed entities