CanTouchItem Virtual

Moderator: GZDoom Developers

Post Reply
User avatar
Major Cooke
Posts: 8170
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

CanTouchItem Virtual

Post by Major Cooke »

EDIT: Reworked and renamed.
Pull Request

Items could pick and choose whom they can enter, but never the other way around.
This PR adds functionality to fix this issue, allowing those with the +PICKUP flag the ability to filter what items they can pick up.
Simply override the CanTouchItem(Inventory item) function. Return true to signify the actor can attempt to pick up the item, false if they cannot.
Last edited by Major Cooke on Sun Mar 03, 2019 1:29 pm, edited 2 times in total.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49056
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: CanPickupItem Virtual

Post by Graf Zahl »

Why did you add this in two places and added a special handling to CallTryPickup? Such things need commenting because it is not apparent why it is necessary.
User avatar
Major Cooke
Posts: 8170
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: CanTouchItem Virtual

Post by Major Cooke »

Simplified and renamed it accordingly so it's delegated to Touch only.
User avatar
Major Cooke
Posts: 8170
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: CanTouchItem Virtual

Post by Major Cooke »

I'm going to introduce CanUseItem as well. I just found myself wishing that I could block certain inventory items from being usable while under a certain condition. I.e. activating powerups while morphed (at least some of them).

The only problem is, this area is a bit more sticky and I'm not entirely sure where I should place the check... Would it be best to just put this in CustomInventory's Use override?

Code: Select all

//===========================================================================
//
// ACustomInventory :: Use
//
//===========================================================================

override bool Use (bool pickup)
{
	if (!pickup && Owner && !Owner.CanUseItem(self))
		return false;
	return CallStateChain (Owner, FindState('Use'));
}
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49056
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: CanTouchItem Virtual

Post by Graf Zahl »

No, that won't help much. To pull this off you'd have to wrap the virtual Use call into another function, similar to CallTryPickup and do the check there.

Of course you have to do this for all Use calls everywhere and that's going to be a bit tricky.
User avatar
Major Cooke
Posts: 8170
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: CanTouchItem Virtual

Post by Major Cooke »

Understood. That'll be something for me to think about as a separate PR, but not until after this one has been merged.

I also opened a completely new PR when I reworked it to ensure this is clean.
User avatar
Major Cooke
Posts: 8170
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: CanTouchItem Virtual

Post by Major Cooke »

New PR to fix merge conflict.
User avatar
Rachael
Posts: 13531
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her
Contact:

Re: CanTouchItem Virtual

Post by Rachael »

Post Reply

Return to “Closed Feature Suggestions [GZDoom]”