From 6a4d5ecf143def35b95fecf9ef448164f78caffc Mon Sep 17 00:00:00 2001 From: Lyberta Date: Wed, 11 Oct 2017 02:08:02 +0300 Subject: [PATCH] Proper handling of expiring items. --- qcsrc/common/t_items.qc | 36 +++++++++++++------------------- qcsrc/server/items.qc | 13 ++++++++++++ qcsrc/server/items.qh | 13 ++++++++++++ qcsrc/server/weapons/throwing.qc | 1 + 4 files changed, 41 insertions(+), 22 deletions(-) diff --git a/qcsrc/common/t_items.qc b/qcsrc/common/t_items.qc index 70c462288..da491b718 100644 --- a/qcsrc/common/t_items.qc +++ b/qcsrc/common/t_items.qc @@ -905,26 +905,22 @@ void Item_Touch(entity this, entity toucher) toucher = M_ARGV(1, entity); - // TODO: Proper way to handle expiring and not expiring loot. - // Expiring loot will have strength "ticking" will it's dropped. - // Not expiring will not tick. - // OTOH, do we really need expiring loot? - //if (this.classname == "droppedweapon") - //{ - // 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); - //} + if (Item_IsExpiring(this)) + { + 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); + } bool gave = ITEM_HANDLE(Pickup, this.itemdef, this, toucher); if (!gave) { - //if (this.classname == "droppedweapon") - //{ - // // undo what we did above - // this.strength_finished += time; - // this.invincible_finished += time; - // this.superweapons_finished += time; - //} + if (Item_IsExpiring(this)) + { + // undo what we did above + this.strength_finished += time; + this.invincible_finished += time; + this.superweapons_finished += time; + } return; } @@ -1232,11 +1228,7 @@ void _StartItem(entity this, entity def, float defaultrespawntime, float default this.takedamage = DAMAGE_YES; this.event_damage = Item_Damage; - // TODO: Proper way to handle expiring and not expiring loot. - // Expiring loot will have strength "ticking" will it's dropped. - // Not expiring will not tick. - // OTOH, do we really need expiring loot? - if (this.strength_finished || this.invincible_finished || this.superweapons_finished) + if (Item_IsExpiring(this)) { // if item is worthless after a timer, have it expire then this.nextthink = max(this.strength_finished, this.invincible_finished, this.superweapons_finished); diff --git a/qcsrc/server/items.qc b/qcsrc/server/items.qc index 23124730f..8161e10c1 100644 --- a/qcsrc/server/items.qc +++ b/qcsrc/server/items.qc @@ -9,6 +9,9 @@ #include .bool m_isloot; ///< Holds whether item is loot. +/// \brief Holds whether strength, shield or superweapon timers expire while +/// this item is on the ground. +.bool m_isexpiring; entity Item_Create(string class_name, vector position) { @@ -80,6 +83,16 @@ void Item_SetLoot(entity item, bool loot) item.m_isloot = loot; } +bool Item_IsExpiring(entity item) +{ + return item.m_isexpiring; +} + +void Item_SetExpiring(entity item, bool expiring) +{ + item.m_isexpiring = expiring; +} + // Compatibility spawn functions // FIXME: in Quake this is green armor, in Xonotic maps it is an armor shard diff --git a/qcsrc/server/items.qh b/qcsrc/server/items.qh index 6544336d9..a1e3a3131 100644 --- a/qcsrc/server/items.qh +++ b/qcsrc/server/items.qh @@ -1,4 +1,5 @@ #pragma once + /// \file /// \brief Header file that describes the functions related to game items. /// \copyright GNU GPLv2 or any later version. @@ -48,3 +49,15 @@ bool Item_IsLoot(entity item); /// \return No return. void Item_SetLoot(entity item, bool loot); +/// \brief Returns whether the item is expiring (i.e. its strength, shield and +/// superweapon timers expire while it is on the ground). +/// \param[in] item Item to check. +/// \return True if the item is expiring, false otherwise. +bool Item_IsExpiring(entity item); + +/// \brief Sets the item expiring status (i.e. whether its strength, shield +/// and superweapon timers expire while it is on the ground). +/// \param[in,out] item Item to adjust. +/// \param[in] expiring Whether item is expiring. +/// \return No return. +void Item_SetExpiring(entity item, bool expiring); diff --git a/qcsrc/server/weapons/throwing.qc b/qcsrc/server/weapons/throwing.qc index 52b7586b8..91602e750 100644 --- a/qcsrc/server/weapons/throwing.qc +++ b/qcsrc/server/weapons/throwing.qc @@ -55,6 +55,7 @@ string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vecto if(WepSet_FromWeapon(Weapons_from(wpn)) & WEPSET_SUPERWEAPONS) { + Item_SetExpiring(wep, true); if(own.items & IT_UNLIMITED_SUPERWEAPONS) { wep.superweapons_finished = time + autocvar_g_balance_superweapons_time; -- 2.39.2