Page 1 of 1

[2.1.2] ::HandlePickup()

Posted: Mon Jul 17, 2006 3:39 am
by Carnevil
When trying to get some of Skulltag's new items to work under ZDoom 2.1.0, I noticed a bug that's preventing some of them from working properly. It's still present in 2.1.2, so here goes.

Basically, whenever you pick up an item, ZDoom goes through each object in the player's inventory, and asks it whether or not it's okay to pick up the item, via the function ::HandlePickup(). Each item subclass (AWeapon, AAmmo, APowerup, etc.) has its own handling of this function. They all start off by checking to see if the item being picked up is of the same class as the item in the inventory.

The problem is that even if you pick up an item of the same class as something in your inventory, this check fails. For example, just now I gave myself the InvulnerabilitySphere. Then, when I give myself another one, APowerup::HandlePickup() is called, and when it compares the class of the item I'm giving to myself ("InvulnerabilitySphere") and the same thing that I just gave to myself that's now in my inventory ("PowerInvulnerable"). The classes don't match, and the function returns false when really it should return true.

I'm not sure what other classes this happens with, but it definitely seems to happen with powerups.

Posted: Mon Jul 17, 2006 4:02 am
by Graf Zahl
This is not a bug. The InvulnerabilitySphere item never goes into the inventory. All it does is to create a PowerInvulnerable item, set up its properties and give that to the player.

The second InvulnerabilitySphere you are giving the player gives another PowerInvulnerable item which in turn is handled by the already active one in the inventory.

The base class isn't called Powerupgiver for nothing. ;)

Posted: Mon Jul 17, 2006 4:45 am
by Carnevil
Ah, alright. I see it now. The powerup giver spawns the powerup, runs TryPickup(), and THEN it the check works out properly.

My bad :) It works fine. Thanks Graf.