From 101e31b5eb1dbfb7dc526ba23b29a706201a67aa Mon Sep 17 00:00:00 2001 From: TimePath Date: Tue, 13 Oct 2015 21:01:09 +1100 Subject: [PATCH] Items: shift picking up weapons into WeaponPickup --- qcsrc/common/items/all.qh | 2 -- qcsrc/common/items/item/pickup.qc | 8 +---- qcsrc/common/items/item/pickup.qh | 11 +++++- qcsrc/common/weapons/weapon.qh | 11 ++++++ qcsrc/server/t_items.qc | 57 ++++++++++++++++--------------- qcsrc/server/t_items.qh | 2 +- 6 files changed, 52 insertions(+), 39 deletions(-) diff --git a/qcsrc/common/items/all.qh b/qcsrc/common/items/all.qh index a825b4ed1..37e417a63 100644 --- a/qcsrc/common/items/all.qh +++ b/qcsrc/common/items/all.qh @@ -34,5 +34,3 @@ string Item_Model(string item_mdl); #endif #endif - -#include "inventory.qh" diff --git a/qcsrc/common/items/item/pickup.qc b/qcsrc/common/items/item/pickup.qc index ade99c543..fc958709e 100644 --- a/qcsrc/common/items/item/pickup.qc +++ b/qcsrc/common/items/item/pickup.qc @@ -2,12 +2,6 @@ #ifdef SVQC bool ITEM_HANDLE(Pickup, entity this, entity item, entity player) { - bool b = this.giveTo(this, item, player); - if (b) { - LOG_TRACEF("entity %i picked up %s\n", player, this.m_name); - player.inventory.inv_items[this.m_id]++; - Inventory_update(player); - } - return b; + return this.giveTo(this, item, player); } #endif diff --git a/qcsrc/common/items/item/pickup.qh b/qcsrc/common/items/item/pickup.qh index 9a25ebe9a..199632788 100644 --- a/qcsrc/common/items/item/pickup.qh +++ b/qcsrc/common/items/item/pickup.qh @@ -1,5 +1,6 @@ #ifndef PICKUP_H #define PICKUP_H +#include "../inventory.qh" #include "../item.qh" CLASS(Pickup, GameItem) #ifndef MENUQC @@ -21,7 +22,15 @@ CLASS(Pickup, GameItem) ATTRIB(Pickup, m_respawntimejitter, float(), func_null) float Item_GiveTo(entity item, entity player); METHOD(Pickup, giveTo, bool(entity this, entity item, entity player)) - { return Item_GiveTo(item, player); } + { + bool b = Item_GiveTo(item, player); + if (b) { + LOG_TRACEF("entity %i picked up %s\n", player, this.m_name); + player.inventory.inv_items[this.m_id]++; + Inventory_update(player); + } + return b; + } bool ITEM_HANDLE(Pickup, entity this, entity item, entity player); #endif ENDCLASS(Pickup) diff --git a/qcsrc/common/weapons/weapon.qh b/qcsrc/common/weapons/weapon.qh index 39702051b..624cb83f5 100644 --- a/qcsrc/common/weapons/weapon.qh +++ b/qcsrc/common/weapons/weapon.qh @@ -1,5 +1,6 @@ #ifndef WEAPON_H #define WEAPON_H +#include "../items/item/pickup.qh" .int ammo_shells; .int ammo_nails; @@ -112,6 +113,16 @@ CLASS(WeaponPickup, Pickup) this.m_botvalue = w.bot_pickupbasevalue; #endif } +#ifdef SVQC + METHOD(WeaponPickup, giveTo, bool(entity this, entity item, entity player)) + { + bool b = Item_GiveTo(item, player); + if (b) { + LOG_TRACEF("entity %i picked up %s\n", player, this.m_name); + } + return b; + } +#endif ENDCLASS(WeaponPickup) CLASS(OffhandWeapon, Object) diff --git a/qcsrc/server/t_items.qc b/qcsrc/server/t_items.qc index 15a8ec9b6..595f3c84e 100644 --- a/qcsrc/server/t_items.qc +++ b/qcsrc/server/t_items.qc @@ -711,16 +711,16 @@ float Item_GiveTo(entity item, entity player) return 1; } -void Item_Touch (void) -{SELFPARAM(); - entity e, head; +void Item_Touch() +{ + SELFPARAM(); // remove the item if it's currnetly in a NODROP brush or hits a NOIMPACT surface (such as sky) - if(self.classname == "droppedweapon") + if (this.classname == "droppedweapon") { if (ITEM_TOUCH_NEEDKILL()) { - remove(self); + remove(this); return; } } @@ -728,33 +728,33 @@ void Item_Touch (void) if(!(other.flags & FL_PICKUPITEMS) || other.frozen || other.deadflag - || (self.solid != SOLID_TRIGGER) - || (self.owner == other) - || (time < self.item_spawnshieldtime) - ) { return;} + || (this.solid != SOLID_TRIGGER) + || (this.owner == other) + || (time < this.item_spawnshieldtime) + ) { return; } - switch(MUTATOR_CALLHOOK(ItemTouch, self, other)) + switch (MUTATOR_CALLHOOK(ItemTouch, this, other)) { case MUT_ITEMTOUCH_RETURN: { return; } case MUT_ITEMTOUCH_PICKUP: { goto pickup; } } - if (self.classname == "droppedweapon") + if (this.classname == "droppedweapon") { - self.strength_finished = max(0, self.strength_finished - time); - self.invincible_finished = max(0, self.invincible_finished - time); - self.superweapons_finished = max(0, self.superweapons_finished - time); + this.strength_finished = max(0, this.strength_finished - time); + this.invincible_finished = max(0, this.invincible_finished - time); + this.superweapons_finished = max(0, this.superweapons_finished - time); } - entity it = self.itemdef; - bool gave = (it && it.instanceOfPickup) ? ITEM_HANDLE(Pickup, it, self, other) : Item_GiveTo(self, other); + entity it = this.itemdef; + bool gave = ITEM_HANDLE(Pickup, it, this, other); if (!gave) { - if (self.classname == "droppedweapon") + if (this.classname == "droppedweapon") { // undo what we did above - self.strength_finished += time; - self.invincible_finished += time; - self.superweapons_finished += time; + this.strength_finished += time; + this.invincible_finished += time; + this.superweapons_finished += time; } return; } @@ -763,17 +763,18 @@ void Item_Touch (void) other.last_pickup = time; - Send_Effect(EFFECT_ITEM_PICKUP, CENTER_OR_VIEWOFS(self), '0 0 0', 1); - _sound (other, CH_TRIGGER, (self.item_pickupsound ? self.item_pickupsound : self.item_pickupsound_ent.sound_str()), VOL_BASE, ATTEN_NORM); + Send_Effect(EFFECT_ITEM_PICKUP, CENTER_OR_VIEWOFS(this), '0 0 0', 1); + _sound (other, CH_TRIGGER, (this.item_pickupsound ? this.item_pickupsound : this.item_pickupsound_ent.sound_str()), VOL_BASE, ATTEN_NORM); - if (self.classname == "droppedweapon") - remove (self); - else if (self.spawnshieldtime) + if (this.classname == "droppedweapon") + remove (this); + else if (this.spawnshieldtime) { - if(self.team) + entity e; + if(this.team) { RandomSelection_Init(); - for(head = world; (head = findfloat(head, team, self.team)); ) + for(entity head = world; (head = findfloat(head, team, this.team)); ) { if(head.flags & FL_ITEM) if(head.classname != "item_flag_team" && head.classname != "item_key_team") @@ -786,7 +787,7 @@ void Item_Touch (void) } else - e = self; + e = this; Item_ScheduleRespawn(e); } } diff --git a/qcsrc/server/t_items.qh b/qcsrc/server/t_items.qh index 0e4da21ed..21fb5eb71 100644 --- a/qcsrc/server/t_items.qh +++ b/qcsrc/server/t_items.qh @@ -90,7 +90,7 @@ float Item_GiveAmmoTo(entity item, entity player, .float ammotype, float ammomax float Item_GiveTo(entity item, entity player); -void Item_Touch (void); +void Item_Touch(); void Item_Reset(entity this); -- 2.39.2