]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Proper handling of expiring items.
authorLyberta <lyberta@lyberta.net>
Tue, 10 Oct 2017 23:08:02 +0000 (02:08 +0300)
committerLyberta <lyberta@lyberta.net>
Tue, 10 Oct 2017 23:08:02 +0000 (02:08 +0300)
qcsrc/common/t_items.qc
qcsrc/server/items.qc
qcsrc/server/items.qh
qcsrc/server/weapons/throwing.qc

index 70c462288637bfa0af4f90f178afaf113626443a..da491b71871eb86ead9b45a522938d93191461fe 100644 (file)
@@ -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);
index 23124730fab631094b82938f07048d7d79d52886..8161e10c1e657fa30d950b72d5cb52a9c829bffb 100644 (file)
@@ -9,6 +9,9 @@
 #include <common/weapons/all.qh>
 
 .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
index 6544336d9137e0e9bc03fcc5b0e3a42196cb3736..a1e3a313108e93f217df8db885a9d06a1d021f68 100644 (file)
@@ -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);
index 52b7586b8e9cacf0e15170d701d06b4a4530f9a1..91602e750ad08c0e19b9b18995185fd115f8cc7f 100644 (file)
@@ -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;