]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
powerups: use Item_Think() for dropped powerups
authorbones_was_here <bones_was_here@xonotic.au>
Wed, 14 Jun 2023 13:53:57 +0000 (23:53 +1000)
committerbones_was_here <bones_was_here@xonotic.au>
Thu, 15 Jun 2023 20:36:27 +0000 (06:36 +1000)
Fixes lack of updates sent to CSQC ItemDraw() for position, velocity, etc.

qcsrc/common/mutators/mutator/powerups/sv_powerups.qc
qcsrc/common/mutators/mutator/powerups/sv_powerups.qh
qcsrc/server/items/items.qc

index d655ae19a29458e83bd7b52ab75becd9eb6ff7fe..7b15d34a09f8a4d4f30533d0f304dcfec6d89099 100644 (file)
@@ -79,18 +79,15 @@ MUTATOR_HOOKFUNCTION(powerups, MonsterValidTarget)
 
 void powerups_DropItem_Think(entity this)
 {
-       TakeResource(this, RES_HEALTH, 1);
-
-       if(GetResource(this, RES_HEALTH) < 1) {
-               RemoveItem(this);
-               return;
-       }
-
        // Only needed to update if the timer of the powerup is running
        if(!GetResource(this, RES_ARMOR))
-               WaypointSprite_UpdateHealth(this.waypointsprite_attached, GetResource(this, RES_HEALTH));
-
-       this.nextthink = time + 1;
+       {
+               float timeleft = floor(this.wait - time);
+               if (timeleft)
+                       WaypointSprite_UpdateHealth(this.waypointsprite_attached, timeleft);
+               else
+                       WaypointSprite_Kill(this.waypointsprite_attached);
+       }
 }
 
 void powerups_DropItem(entity this, StatusEffects effect, bool freezeTimer)
@@ -130,9 +127,6 @@ void powerups_DropItem(entity this, StatusEffects effect, bool freezeTimer)
        if(!freezeTimer)
                Item_SetExpiring(e, true);
 
-       // Use health as time left to live
-       SetResourceExplicit(e, RES_HEALTH, time_to_live);
-
        // Use armor as timer freezer
        if(freezeTimer)
                SetResourceExplicit(e, RES_ARMOR, 1);
@@ -142,10 +136,7 @@ void powerups_DropItem(entity this, StatusEffects effect, bool freezeTimer)
        wp.wp_extra = item.m_id;
        WaypointSprite_UpdateMaxHealth(e.waypointsprite_attached, maxtime);
        WaypointSprite_UpdateHealth(e.waypointsprite_attached, timeleft);
-
-       // Start dropping its time to live
-       setthink(e, powerups_DropItem_Think);
-       e.nextthink = time + 1;
+       // Item_Think() will call powerups_DropItem_Think() to update the waypoint
 }
 
 MUTATOR_HOOKFUNCTION(powerups, ItemTouched)
index 06098c95ebf1095c3297ab23f57d32608948b652..005cbcba42da09be81afa3cbb37e4765892b1166 100644 (file)
@@ -14,5 +14,7 @@ REGISTER_MUTATOR(powerups, true);
 .float prevstrengthsound;
 .float prevstrengthsoundattempt;
 
+void powerups_DropItem_Think(entity this);
+
 // q3compat
 .float count;
index 0f764c8627fca5aa90d8867f9937e508d353ba3e..7c3fd969b5f7f6929a814bdb52500eccb4cdf2e1 100644 (file)
@@ -202,6 +202,9 @@ void Item_Think(entity this)
                        }
                }
 
+               if (this.itemdef.instanceOfPowerup)
+                       powerups_DropItem_Think(this);
+
                // enable pickup by the player who threw it
                this.owner = NULL;