[Added] CanTouchItem Virtual

Moderator: GZDoom Developers

CanTouchItem Virtual

Postby Major Cooke » Thu Jan 03, 2019 7:21 pm

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 2:29 pm, edited 2 times in total.
User avatar
Major Cooke
The road to Hell is paved in the carrion she leaves behind.
 
Joined: 28 Jan 2007
Discord: Major Cooke#0846

Re: CanPickupItem Virtual

Postby Graf Zahl » Fri Jan 04, 2019 1:40 am

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
Graf Zahl
Lead GZDoom Developer
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: CanTouchItem Virtual

Postby Major Cooke » Fri Jan 04, 2019 11:27 am

Simplified and renamed it accordingly so it's delegated to Touch only.
User avatar
Major Cooke
The road to Hell is paved in the carrion she leaves behind.
 
Joined: 28 Jan 2007
Discord: Major Cooke#0846

Re: CanTouchItem Virtual

Postby Major Cooke » Sun Jan 06, 2019 3:44 pm

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 allExpand view
//===========================================================================
//
// ACustomInventory :: Use
//
//===========================================================================

override bool Use (bool pickup)
{
   if (!pickup && Owner && !Owner.CanUseItem(self))
      return false;
   return CallStateChain (Owner, FindState('Use'));
}
User avatar
Major Cooke
The road to Hell is paved in the carrion she leaves behind.
 
Joined: 28 Jan 2007
Discord: Major Cooke#0846

Re: CanTouchItem Virtual

Postby Graf Zahl » Sun Jan 06, 2019 4:13 pm

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
Graf Zahl
Lead GZDoom Developer
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: CanTouchItem Virtual

Postby Major Cooke » Fri Feb 01, 2019 12:42 pm

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
The road to Hell is paved in the carrion she leaves behind.
 
Joined: 28 Jan 2007
Discord: Major Cooke#0846

Re: CanTouchItem Virtual

Postby Major Cooke » Sun Mar 03, 2019 2:29 pm

New PR to fix merge conflict.
User avatar
Major Cooke
The road to Hell is paved in the carrion she leaves behind.
 
Joined: 28 Jan 2007
Discord: Major Cooke#0846

Re: CanTouchItem Virtual

Postby Rachael » Mon Mar 04, 2019 1:38 pm

User avatar
Rachael
Webmaster
 
Joined: 13 Jan 2004
Discord: Rachael#3767
Twitch ID: madamerachelle
Github ID: madame-rachelle


Return to Closed Feature Suggestions

Who is online

Users browsing this forum: No registered users and 0 guests