A_Explode returning iterator or array

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
User avatar
MartinHowe
Posts: 2078
Joined: Mon Aug 11, 2003 1:50 pm
Preferred Pronouns: He/Him
Location: East Suffolk (UK)

A_Explode returning iterator or array

Post by MartinHowe »

One of the problems coding new weapons or monster attacks, is that so few of the standard codepointers return an actor pointer, array or iterator to the actors actually hit, in order to perform special effects; most return void or at best int (for number of actors hit). At least things like A_CustomBulletAttack tend to have source code in c++ that can be simply translated into ZScript, so one can use an FLineTarget to capture a reference to each actor actually hit. However, A_Explode seems an absolute nightmare, seemingly referencing loads of internal functions that are likely not exposed to ZScript; some are, just without the "P_" prefix, but it uses lots of internal data structures as well.

So before I attempt this myself, has anybody tried even to just replicate A_Explode as it is out of the box and what sort of compromises did you have to make?
User avatar
Player701
 
 
Posts: 1710
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

Re: A_Explode returning iterator or array

Post by Player701 »

The source code of A_Explode is available in ZScript. It is essentially a wrapper for the native RadiusAttack function, which uses a BlockThingsIterator internally and tries to do damage to everything it finds provided that there is a line of sight to the target. Here is the source code.

I bet that RadiusAttack can be reproduced in ZScript if necessary, although perhaps not with a 100% accuracy. However, I don't think that would be a good idea considering the amount of code and the possibility that it may change in future releases. Instead, I suggest you override DoSpecialDamage for your projectile. This method is called each time someone's about to get damaged, and in addition to special effects, you can also apply custom logic to modify the damage or cancel it out entirely (by setting it to -1). Return value is the resulting damage, which you can leave unchanged.
User avatar
MartinHowe
Posts: 2078
Joined: Mon Aug 11, 2003 1:50 pm
Preferred Pronouns: He/Him
Location: East Suffolk (UK)

Re: A_Explode returning iterator or array

Post by MartinHowe »

Thanks, @Player701. I've been looking at the source code of RadiusAttack, seeing what converts easily and what doesn't; however, my concerns are the same as yours - things can change in the future. Thanks especially for the pointer to DoSpecialDamage, I'll have a look at that, cheers :thumb:

Indeed, this works perfectly :D
User avatar
MartinHowe
Posts: 2078
Joined: Mon Aug 11, 2003 1:50 pm
Preferred Pronouns: He/Him
Location: East Suffolk (UK)

Re: A_Explode returning iterator or array

Post by MartinHowe »

Just wanted to say a big THANKS to @Player701 for their help. I guess with so much new functionality being added to ZDoom in the wake of ZScript, it will take a while to get used to knowing where everything is.

In other words, with the actor virtuals, most functions now effectively do have iterators; however, the problem is knowing where to look when you want to do something new; just looking at the list of action functions isn't enough nowadays. If Doom were new and designed today with ZScript, maybe all attack functions would return an iterator anyway, who knows?
Post Reply

Return to “Scripting”