From: TimePath Date: Sun, 10 May 2015 11:12:47 +0000 (+1000) Subject: Use the new item system for ammo X-Git-Tag: xonotic-v0.8.1~53^2~17 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=ee91ec05fdfba024c9b3221045baa786190dd9b6;p=xonotic%2Fxonotic-data.pk3dir.git Use the new item system for ammo --- diff --git a/qcsrc/common/items/all.qc b/qcsrc/common/items/all.qc index 1700ae9fb..460f77fcb 100644 --- a/qcsrc/common/items/all.qc +++ b/qcsrc/common/items/all.qc @@ -1,3 +1,5 @@ +#ifndef ALL_C +#define ALL_C #include "all.qh" #include "all.inc" @@ -9,3 +11,5 @@ void ItemTest() ITEM_SEND(Default, it); })); } + +#endif diff --git a/qcsrc/common/items/item.qh b/qcsrc/common/items/item.qh index cf2779aa0..1c8939beb 100644 --- a/qcsrc/common/items/item.qh +++ b/qcsrc/common/items/item.qh @@ -28,8 +28,10 @@ ITEM_SIGNALS(ITEM_SEND) int ITEM_COUNT; #define REGISTER_ITEM(id, class, body) \ + entity ITEM_##id; \ void RegisterItems_##id() { \ const noref entity this = NEW(class); \ + ITEM_##id = this; \ ITEMS[ITEM_COUNT++] = this; \ body \ } \ diff --git a/qcsrc/common/items/item/ammo.qc b/qcsrc/common/items/item/ammo.qc index 5868eeb84..9bce0839a 100644 --- a/qcsrc/common/items/item/ammo.qc +++ b/qcsrc/common/items/item/ammo.qc @@ -1,11 +1,50 @@ #include "ammo.qh" +#include "../../../server/t_items.qh" -#define REGISTER_AMMO(id) REGISTER_ITEM(id, Ammo, LAMBDA(this.ammoName = #id)) -REGISTER_AMMO(nails) -REGISTER_AMMO(rockets) -REGISTER_AMMO(cells) -REGISTER_AMMO(plasma) -REGISTER_AMMO(fuel) +#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; \ +})) + +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(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(Shells, + "models/items/a_shells.md3", + "misc/itempickup.wav", + "shells", + IT_SHELLS, + 500 +) bool Ammo_respondTo(entity this, int request) { diff --git a/qcsrc/common/items/item/ammo.qh b/qcsrc/common/items/item/ammo.qh index 412ccc2d2..4ff7babfb 100644 --- a/qcsrc/common/items/item/ammo.qh +++ b/qcsrc/common/items/item/ammo.qh @@ -3,6 +3,10 @@ #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) ENDCLASS(Ammo) #endif diff --git a/qcsrc/server/t_items.qc b/qcsrc/server/t_items.qc index 6839091f4..cb507fc20 100644 --- a/qcsrc/server/t_items.qc +++ b/qcsrc/server/t_items.qc @@ -1,5 +1,7 @@ #include "t_items.qh" +#include "../common/items/all.qc" + #if defined(SVQC) #include "_all.qh" @@ -1151,12 +1153,18 @@ void StartItem (string itemmodel, string pickupsound, float defaultrespawntime, return; } } + +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); +} + void spawnfunc_item_rockets (void) { if(!self.ammo_rockets) self.ammo_rockets = g_pickup_rockets; if(!self.pickup_anyway) self.pickup_anyway = g_pickup_ammo_anyway; - StartItem ("models/items/a_rockets.md3", "misc/itempickup.wav", g_pickup_respawntime_ammo, g_pickup_respawntimejitter_ammo, "rockets", IT_ROCKETS, 0, 0, commodity_pickupevalfunc, 3000); + StartItemA (ITEM_Rockets); } void spawnfunc_item_bullets (void) { @@ -1174,7 +1182,7 @@ void spawnfunc_item_bullets (void) { self.ammo_nails = g_pickup_nails; if(!self.pickup_anyway) self.pickup_anyway = g_pickup_ammo_anyway; - StartItem ("models/items/a_bullets.mdl", "misc/itempickup.wav", g_pickup_respawntime_ammo, g_pickup_respawntimejitter_ammo, "bullets", IT_NAILS, 0, 0, commodity_pickupevalfunc, 2000); + StartItemA (ITEM_Bullets); } void spawnfunc_item_cells (void) { @@ -1182,7 +1190,7 @@ void spawnfunc_item_cells (void) { self.ammo_cells = g_pickup_cells; if(!self.pickup_anyway) self.pickup_anyway = g_pickup_ammo_anyway; - StartItem ("models/items/a_cells.md3", "misc/itempickup.wav", g_pickup_respawntime_ammo, g_pickup_respawntimejitter_ammo, "cells", IT_CELLS, 0, 0, commodity_pickupevalfunc, 2000); + StartItemA (ITEM_Cells); } void spawnfunc_item_plasma() @@ -1191,7 +1199,7 @@ void spawnfunc_item_plasma() self.ammo_plasma = g_pickup_plasma; if(!self.pickup_anyway) self.pickup_anyway = g_pickup_ammo_anyway; - StartItem ("models/items/a_cells.md3", "misc/itempickup.wav", g_pickup_respawntime_ammo, g_pickup_respawntimejitter_ammo, "plasma", IT_PLASMA, 0, 0, commodity_pickupevalfunc, 2000); + StartItemA (ITEM_Plasma); } void spawnfunc_item_shells (void) { @@ -1209,7 +1217,7 @@ void spawnfunc_item_shells (void) { self.ammo_shells = g_pickup_shells; if(!self.pickup_anyway) self.pickup_anyway = g_pickup_ammo_anyway; - StartItem ("models/items/a_shells.md3", "misc/itempickup.wav", g_pickup_respawntime_ammo, g_pickup_respawntimejitter_ammo, "shells", IT_SHELLS, 0, 0, commodity_pickupevalfunc, 500); + StartItemA (ITEM_Shells); } void spawnfunc_item_armor_small (void) { diff --git a/qcsrc/server/t_items.qh b/qcsrc/server/t_items.qh index 7470d2f05..a33e45a82 100644 --- a/qcsrc/server/t_items.qh +++ b/qcsrc/server/t_items.qh @@ -11,13 +11,13 @@ const int IT_FUEL_REGEN = 32; // fuel regeneration trigger // where is 64... ? const int IT_FUEL = 128; // -Wdouble-declaration -// const int IT_SHELLS = 256; +#define IT_SHELLS 256 // -Wdouble-declaration -// const int IT_NAILS = 512; +#define IT_NAILS 512 // -Wdouble-declaration -// const int IT_ROCKETS = 1024; +#define IT_ROCKETS 1024 // -Wdouble-declaration -// const int IT_CELLS = 2048; +#define IT_CELLS 2048 const int IT_SUPERWEAPON = 4096; const int IT_STRENGTH = 8192; const int IT_INVINCIBLE = 16384;