Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Chewyninja69

Question about the (super)shotgun and/or its pellets...

Recommended Posts

As the subject states, I am curious: how does the game determine which pellets from a shotgun "goes through" an enemy to kill another enemy? And what's the maximum number of enemies that can be penetrated by a single pellet?

Share this post


Link to post

That's an intersting question. I think if a pellet kills an enemy, it goes through him and hits another enemy, and if it kills him, it goes onto the third enemy.. Kinda like this, I guess.

That's why you can easily kill more than 10 zombiemen at once, but never more than 6 imps at once..

Share this post


Link to post

I think the game checks out one pellet by one, so if by the second one the enemy is dead, then the rest of them go "through" him etc.

I hope someone checks the code, though.

Share this post


Link to post
VGA said:

I think the game checks out one pellet by one, so if by the second one the enemy is dead, then the rest of them go "through" him etc.

Yes. A pellet either hits a monster if it has positive health (and that's where the pellet's journey stops, as the monster takes damage), or misses it and goes through if the monster is already dead (by pellets that previously hit it, even within the same game tic).

Share this post


Link to post

To put it simply, the order is what determines which pellets will go through an enemy - like VGA said, the game doesn't actually process them all simultaneously because that's needlessly complicated for something that doesn't really benefit DOOM.

Now, can you use this information to your advantage? Well, no, because it's not like the most accurate hitscans come first - all of them are given a random angle, so literally any one fired could be the first one processed. And while they don't process simultaneously, they are all processed in a single tic, so it's not like you base this off of how delayed the shot is.

Share this post


Link to post

Yeah, this is something that I didn't realize would be unclear: The engine processes the pellets one by one, but all of them within the same game tic. For example, when the player fires the SSG, the engine first processes its first pellet, calculates its flight path, determines which wall / floor / game object it hits, deals damage to the game object that was hit if it was shootable, and potentially kills the game object if its health dropped to 0 or lower value. Only then the engine proceeds to process the second pellet, calculate its flight path etc., then the third pellet and so on up to the 20th pellet. A monster that gets killed by pellets sometime during this process (say, by being hit by the first 5 pellets) simply becomes unhittable afterwards, so that next pellets will pass through the monster as if the monster didn't exist (no collision will be detected at all). And since this all happens within the same game tic, there is no delay during which the player or other game objects could move, observe or do anything - for them, it appears to be all done in the exact same moment.

Share this post


Link to post

It's worth noting that the monster's corpse not blocking projectiles and such due to this is not something innate with the method, mind - it's because a monster dies due to the damage function, instead of an alternative of having a monster die after all hitscan and projectile processing is done. If you instead keep track of every actor that takes damage in the tic, then iterate over them at the end of the tic and check if their health is 0 or less, everything that should hit a monster would. With an extra bonus of making it so that you would definitely be able to gib a gibbable monster with a point-blank SSG, since all the pellet hitting would deal enough damage to do that - although, amusingly, a point-blank single shotgun would definitely gib a zombieman would the same reason.

Share this post


Link to post

The shotgun firing code is literally just 7 consecutive calls to A_FirePistol, so it's literally like shooting the pistol 7 times. The SSG is a bit more complicated because of the spread, but it's also similar to firing a less accurate pistol 20 times. Each pellet is thus processed exactly the same way as a single pistol shot.

Share this post


Link to post
Maes said:

The shotgun firing code is literally just 7 consecutive calls to A_FirePistol, so it's literally like shooting the pistol 7 times. The SSG is a bit more complicated because of the spread, but it's also similar to firing a less accurate pistol 20 times. Each pellet is thus processed exactly the same way as a single pistol shot.

Out of curiosity, does this mean that the pistol has perfect vertical accuracy and its spread is only horizontal?

Share this post


Link to post
Cynical said:

Out of curiosity, does this mean that the pistol has perfect vertical accuracy and its spread is only horizontal?


Yup. This can be seen when firing the chaingun and shotgun on a wall and noticing the puffs -they all fall on a horizontal line, and both use the pistol firing code.

Share this post


Link to post

If the chaingun uses the pistol firing code, why are the first two shots always on-target?

Share this post


Link to post
Cynical said:

If the chaingun uses the pistol firing code, why are the first two shots always on-target?

Because the first shot of the pistol is always accurate.

Share this post


Link to post
Arctangent said:

Because the first shot of the pistol is always accurate.

!!!

Woah, I didn't know that! I always thought it was just the Chaingun!

Share this post


Link to post
scifista42 said:

Yeah, this is something that I didn't realize would be unclear: The engine processes the pellets one by one, but all of them within the same game tic. For example, when the player fires the SSG, the engine first processes its first pellet, calculates its flight path, determines which wall / floor / game object it hits, deals damage to the game object that was hit if it was shootable, and potentially kills the game object if its health dropped to 0 or lower value. Only then the engine proceeds to process the second pellet, calculate its flight path etc., then the third pellet and so on up to the 20th pellet. A monster that gets killed by pellets sometime during this process (say, by being hit by the first 5 pellets) simply becomes unhittable afterwards, so that next pellets will pass through the monster as if the monster didn't exist (no collision will be detected at all). And since this all happens within the same game tic, there is no delay during which the player or other game objects could move, observe or do anything - for them, it appears to be all done in the exact same moment.


Sorry, I don't get something.

You're saying that the engine calculates each pellet as a separate "event", which means that "one comes after the other", yet all of them on the same tic. Isn't the tic the "smallest ammount of time" in Doom? Like, can a monster be alive and then die in the same tic, so the engine can decide which of the pellets fired on the same tic will/won't hit it?

I'm so confused.

Share this post


Link to post

A tic is the smallest amount of time calculable, however the engine still has to process things in some kind of order. It can't process everything all at the same time (I can't imagine how you'd design an engine to do that), so while each hitscan will fire in the same frame, one logically has to occur before the other.

Share this post


Link to post

The engine can reduce a monster's health. The tic doesn't have to end for this to take place. Then in the next pellet calculation, if that monster's health is zero or less, then it isn't blocking the shot.

Realistically, the corpse should block the shots until it is gibbed or something. But this would make gameplay worse I feel.

Share this post


Link to post

Note that the same logic works at to why the rocket doesn't always gib zombiemen, despite a direct hit dealing a minimum of 148 damage against non-cybers or spiders - as they have 20 health and the rocket deals at least 20 damage on impact, a zombieman will die before the explosion can be processed.

The same reason works for imps, too, though amusingly it's the mid-range damage that won't gib - a 20 or 40 roll will allow the explosion damage to hit it and overkill it, while a 120, 140, or 160 roll will just gib it via impact alone.

Share this post


Link to post

Also you will be gibbed on the first hit by a mere zombieman if you have negative armor. I'm not helpful to any practical situation that can reasonably happen, ha ha!

Share this post


Link to post
dew said:

Also you will be gibbed on the first hit by a mere zombieman if you have negative armor. I'm not helpful to any practical situation that can reasonably happen, ha ha!


Dammit, careful what you post, dew! You probably gave some troll a new "idea" for some UACMN-style map.

Share this post


Link to post
Maes said:

Dammit, careful what you post, dew! You probably gave some troll a new "idea" for some UACMN-style map.

I'm pretty sure it's literally impossible to make a player have negative armor in a ZDoom-based port, not to mention the fact that it might not even work that way in one of them.

Share this post


Link to post
Cynical said:

If the chaingun uses the pistol firing code, why are the first two shots always on-target?

The engine keeps info about weapon hitscan accuracy in a single bitflag, where one value means "perfect accuracy", and the other value means "imperfect accuracy".

While a weapon is not being fired, it keeps calling "WeaponReady" function every tic. This function detects when a fire button is pressed, and begins the weapon's firing animation, as well as it sets the accuracy bit to "perfect accuracy". As a result, all subsequent hitscan shots will be perfectly accurate.

What happens next depends on how the weapon's animation is defined, particularly its ending part. It may end by returning directly to the idle state with "WeaponReady" function on it - then, if the fire button was still pressed, the weapon would fire again - still perfectly accurately. But alternatively (and I think all Doom's weapons do this), the animation may contain a "Refire" function, that will automatically and immediately repeat the weapon's firing animation if the fire button is pressed at the moment, or return to idle state if it's not pressed. This "Refire" function also sets the accuracy bit to "imperfect accuracy", and causes non-first pistol and chaingun shots to be inaccurate.

It is possible to exploit this behavior via DEHACKED to create always accurate pistols/chainguns, as well as always inaccurate pistols/chainguns.

Share this post


Link to post
scifista42 said:

But alternatively (and I think all Doom's weapons do this), the animation may contain a "Refire" function, that will automatically and immediately repeat the weapon's firing animation if the fire button is pressed at the moment, or return to idle state if it's not pressed.

This is a bit incorrect - Refire only does the first part of what you're saying, and does absolutely nothing in regards to returning the weapon to its idle state. Instead, the weapon's fire animation continues, and it's this that returns a weapon to its idle state - and it's worth noting, the only weapons that call Refire without having some frames afterwards ( iirc ) are the chainsaw and chaingun, and maaaaybe the BFG. This is how the plasma rifle does its recoil animation - it's a single, extremely long frame that calls Refire at the start, meaning it will restart the firing animation before actually showing the recoil frame if the player's holding the fire button.

You can also see this effect with the pistol and the shotguns, however - if you hold the fire button instead of pressing it whenever the weapon's idle, you'll actually get a faster fire rate as this skips some frames at the end of their firing animation. This is notable with the pistol, given that it can have perfect accuracy, unlike the shotguns, and thus has a reason to not hold down the fire button. Once you start exploiting the way inaccuracy works in the Doom engine, you can really start to feel how much slower those extra frames make you fire.

Share this post


Link to post

You're right about the animation continuing after Refire when fire button is not pressed. For curiosity, BFG's Refire frame has duration 20, exactly like the plasmagun's one does, but if you press fire during this frame, the BFG won't start firing when it reaches WeaponReady because of its hardcoded safe trigger. Also the rocket launcher ends with a zero duration Refire frame just like chainsaw and chaingun.

Share this post


Link to post
VGA said:

The engine can reduce a monster's health. The tic doesn't have to end for this to take place. Then in the next pellet calculation, if that monster's health is zero or less, then it isn't blocking the shot.

Realistically, the corpse should block the shots until it is gibbed or something. But this would make gameplay worse I feel.


Sometimes, what's realistic isn't what's fun. Realistically speaking, you'd also have to reload every few shots on your bullet weapons and they probably could have rigged something up since Duke 3D has a reload for the pistol but that wouldn't have been fun to have to do.

Share this post


Link to post

OTOH, dying monsters do clip regular projectiles at least in some of their death frames, or at least that's what I heard.

Share this post


Link to post
Maes said:

OTOH, dying monsters do clip regular projectiles at least in some of their death frames, or at least that's what I heard.

They do not. You might be thinking of the fact that they're still solid to other solid actors, like the player or other monsters, because that does actually take a couple frames for most monsters to undo. However, they become unshootable as soon as they die, likely before their state is even changed to their death state.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×