A_CheckFlag

Moderator: GZDoom Developers

User avatar
FDARI
Posts: 1097
Joined: Tue Nov 03, 2009 9:19 am

A_CheckFlag

Post by FDARI »

Preferred patch: http://forum.zdoom.org/viewtopic.php?f=34&t=29364

Definition: A_CheckFlag(string flagname, state label, int check_actor = AAPTR_DEFAULT);
Optional rename: A_JumpIfFlag

Effect: Check the selected actor's flag. Default selection is the caller, but TARGET|MASTER|TRACER can also be used. Will not jump if the flag is missing. Counterpart to A_ChangeFlag, and a more flexible alternative to features otherwise considered for A_JumpInTargetLOS.

Current backward compatibility requirements: None, as this is a new feature.
Future backward compatibility: Flags that are valid in the revision where this is introduced, need to be supported for backward compatibility.

Implemented handling of deprecated flags:

Currently deprecated flags are supported for read in the same way they were already supported for write; with a dedicated function. "bool CheckDeprecatedFlags(AActor *actor, FActorInfo *info, int index)" is inserted immediately after "HandleDeprecatedFlags". The function checks that the data matches that which HandleDeprecatedFlags would have set if the flag was to be enabled. (The code may speak more clearly than I do on that matter.)

Drawback: Whenever a change is made to HandleDeprecatedFlags (this is not frequent, is it?), a corresponding change should be made to CheckDeprecatedFlags.

Merit: Both I and other modders have encountered situations where it would be nice to toggle or verify a flag value somehow; both of which require the engine to measure the current value of that flag. It has most recently come up during the discussion of another feature suggestion I have made. We already have ways to make jumps and judgements based on many other properties and conditions, so the code pointer seems to fit well in its context.

Testing: Jumps have been tested and verified with FRIENDLY, LOWGRAVITY, ISMONSTER, FRIGHTENED.


Example use: A weapon checking properties of the actor under crosshair. Particularly, if I wanted the backstab dagger from my other suggestion to be useful only against human-typed enemies, the fire state would include:

Code: Select all

Fire:
  SPRT A 0 A_CheckFlag("ISMONSTER", "FireAtMonster", AAPTR_TARGET)
InvalidTarget:
  SPRT 4
  goto Ready
FireAtMonster:
  SPRT A 2 A_CheckFlag("NOBLOOD", "InvalidTarget", AAPTR_TARGET)
 // More fire-state
EDIT: Added a version which uses my recently submitted player-target code. (From Final inventory actor pointer)

You can now OR (|) your target selection with AAPTR_PLAYER_GETTARGET. If executed with a player caller, the function will then use the player's current linetarget instead of any stored pointer. Players usually have null pointers. This would be especially relevant in weapon definitions where properties of the current target need to be tested. To have it work only for the player, specify AAPTR_PLAYER_GETTARGET|AAPTR_NULL. To have it get any of the other pointers (DEFAULT - which means self, MASTER, TRACER, TARGET), just combine it with that particular pointer instead. AAPTR_DEFAULT is 0, so if you specify AAPTR_PLAYER_GETTARGET alone, DEFAULT is automatically implied for non-players.

EDIT: Attachments removed; they have served their purpose.
Last edited by FDARI on Thu Oct 27, 2011 10:01 am, edited 5 times in total.
User avatar
Major Cooke
Posts: 8209
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: GZBoomer Town
Contact:

Re: A_CheckFlag

Post by Major Cooke »

Can you do me a favor? Please upload a combined patch that has everything so far -- TargetLOS, final inventory actor and this, because I'm apparently doing something wrong and this A_CheckFlag is doing nothing.
User avatar
Major Cooke
Posts: 8209
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: GZBoomer Town
Contact:

Re: A_CheckFlag

Post by Major Cooke »

http://www.sendspace.com/file/rlgbtj

Code: Select all

Ready:
		M00K A 0 A_JumpIfInventory("OpenAnimation",1,1)
		Goto Unfold
		M00K A 0 A_CheckFlag("ISMONSTER",1,AAPTR_TARGET)
		Goto ReadyNormal
		M00K A 0 A_JumpIfTargetInLOS(1,50,0,128) //Check distance.
		Goto ReadyNormal
		M00K A 0 A_JumpIfTargetInLOS(1,200,JLOSF_TARGETLOS) //Check if behind.
		Goto RaiseForBackstab
Now, this should be working just fine but no matter what I do, A_CheckFlag is just not working so it is always going back to the ReadyNormal state. However, if you comment that and the Goto ReadyNormal just below it, it works just fine (including non-monsters).

I'm using the latest patch here and from the final inventory actor/jumpiftargetinLOS patches.

Edit: I just noticed now that your A_CheckFlag is not using the updated code from your final inventory actor patch... Not sure if that has anything to do with it or not...
User avatar
FDARI
Posts: 1097
Joined: Tue Nov 03, 2009 9:19 am

Re: A_CheckFlag

Post by FDARI »

What actor is calling A_CheckFlag? If that is a weapon/player, use AAPTR_TARGET|AAPTR_PLAYER_GETTARGET; I believe I added that to the latest patch. Not having the indicated type of target will give the same result as a flag not being set, and players normally don't have a stored target.

A patch containing absolutely everything I have done so far will also include the adjustments I'd make if I knew that all my submissions would be accepted. JLOSF_NOMONSTERNOJUMP will not be part of it, but JLOSF_COMBATANTONLY will be. Feel free to improve naming ideas. JLOSF_COMBATANTONLY will check that the target is either a monster or a player.

I hope I'm not giving anybody a headache.
User avatar
Major Cooke
Posts: 8209
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: GZBoomer Town
Contact:

Re: A_CheckFlag

Post by Major Cooke »

Tried it that way too, didn't work. And yeah it's a weapon.

If you want me to, I can upload a diff file showing everything combined into one.
User avatar
FDARI
Posts: 1097
Joined: Tue Nov 03, 2009 9:19 am

Re: A_CheckFlag

Post by FDARI »

What I'm most interested in at this point, is your decorate; any code relevant to this weapon. I'll test that code in my build and see if it does what it's supposed to, and examine the minutiae if there is something odd.

One thing to be aware of: A player only has a (line)target if it is looking directly at one. This is so certain a fact that standard A_JumpIfTargetInLOS skips fov-checks when called by players. (However, my reverse fov/los versions check fov when testing the other actor.) It means your aim must be nearly perfect for A_CheckFlag to get a valid linetarget.

I'll run your decorate on my build, that's what's next.
User avatar
Major Cooke
Posts: 8209
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: GZBoomer Town
Contact:

Re: A_CheckFlag

Post by Major Cooke »

Okay. So even if aiming at the target, you have to be aiming directly at the center of their radius and height?

Also, here's my current changes in case if you can't reproduce it: http://www.sendspace.com/file/chrfuh
User avatar
FDARI
Posts: 1097
Joined: Tue Nov 03, 2009 9:19 am

Re: A_CheckFlag

Post by FDARI »

I don't think it needs to be dead center. Even if it does, I found the bug. I missed a spot when converting duplicated code from A_ChangeFlag. New diff uploaded; should be fine now.
User avatar
NeuralStunner
 
 
Posts: 12328
Joined: Tue Jul 21, 2009 12:04 pm
Preferred Pronouns: No Preference
Operating System Version (Optional): Windows 11
Graphics Processor: nVidia with Vulkan support
Location: capital N, capital S, no space
Contact:

Re: A_CheckFlag

Post by NeuralStunner »

Nice! I hope it works. :P

Though I think this should have a boolean parameter to check against, so you can also code a jump if a particular flag is off.
User avatar
FDARI
Posts: 1097
Joined: Tue Nov 03, 2009 9:19 am

Re: A_CheckFlag

Post by FDARI »

Most decorate jumps have jump as either true or false, and not jump as the other, and offer no other way of distinction. If adding a boolean to invert the jump condition is a popular idea, I can do it, but it is neither necessary nor precedented. I'm quite used to weaving a path of jumps and non-jumps to reach a state that is only attainable under a specific set of circumstances.

Inverting the jump condition would be roughly the same as inverting the jump condition for A_JumpIfTargetInLOS ("not" in LOS). The change is easier for A_ChangeFlag, because there are fewer branches in the code, but logically it is similar. The two functions also share the same problem with that particular idea: What if the actor you're checking against does not exist? Both functions can check your target, tracer or master. No jump is executed if the chosen actor does not exist. Should this also be inverted? (A_CheckFlag can also check against "self", the default actor which always exists, no issues there.)

Thoughts?
User avatar
NeuralStunner
 
 
Posts: 12328
Joined: Tue Jul 21, 2009 12:04 pm
Preferred Pronouns: No Preference
Operating System Version (Optional): Windows 11
Graphics Processor: nVidia with Vulkan support
Location: capital N, capital S, no space
Contact:

Re: A_CheckFlag

Post by NeuralStunner »

The check would simply invert the value it checks for, nothing else. The jump should always fail if another actor is referenced that does not exist, as there's no way to check the flag at all.

The idea was for simplicity of use and more similarity to A_ChangeFlag. (A_JumpIfInventory also lets you check certain values, it just happens that flags only have 2. :P ) If it would only add messy complexity to the code, it's not a big deal to have.

I see you made sure it can accept a state offset instead of a label, as well.

For the record, I like the name "A_JumpIfFlag" better. It more clearly conveys the usage of the function. (Though one could argue that "A_CheckFlag" is grammatically nicer. :P )
User avatar
Major Cooke
Posts: 8209
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: GZBoomer Town
Contact:

Re: A_CheckFlag

Post by Major Cooke »

It appears to be working now. Thanks mate!

I don't like A_JumpIfFlag as much as A_CheckFlag, because "check" is straight to the point and says to me, "Is this flag on them? If so, jump."
User avatar
FDARI
Posts: 1097
Joined: Tue Nov 03, 2009 9:19 am

Re: A_CheckFlag

Post by FDARI »

There is a bug in this code presently. (Yes, another one.)
For once, I found it during my own testing. I'll get you a fixed patch shortly.
User avatar
FDARI
Posts: 1097
Joined: Tue Nov 03, 2009 9:19 am

Re: A_CheckFlag

Post by FDARI »

Patch in first post is updated with fix.
User avatar
Major Cooke
Posts: 8209
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: GZBoomer Town
Contact:

Re: A_CheckFlag

Post by Major Cooke »

Oh. Uh, what was the bug?
Post Reply

Return to “Closed Feature Suggestions [GZDoom]”