Hitscan (original) (raw)
An SS shooting the player is an example of a Hitscan.
Hitscanning is a method of performing damage calculations for video games. In Wolfenstein 3D, it is used to calculate the damage dealt by the Pistol, Machine Gun, and Chain Gun.
Damage formula (enemy shooting)[]
Hitscanning is unique among damage in Wolfenstein 3D in that not one but two calculations are performed, one to determine if a hit actually occurred, and another for damage dealt.[1]
Variables[]
The following variables are used:
rand
Random integer between and including the numbers 0 and 255.[2] Every time this variable is mentioned is a different call to the function, and a different random number, even within formulas.
dist
The distance between the player and the enemy. Multiplied by two-thirds if the enemy shooting is Hans Grösse or an SS ("ss are better shots"[3]).
hitchance
Output of the first formula, used to determine if a hit occurred.
base damage
Output of the second formula and input of TakeDamage, will be divided by four if the player is on lowest difficulty level.[4]
Hit detection[]
h i t c h a n c e = { 256 − ( d i s t × 16 ) , if player is walking and can see enemy 256 − ( d i s t × 8 ) , if player is walking and cannot see enemy 160 − ( d i s t × 16 ) , if player is running and can see enemy 160 − ( d i s t × 8 ) , if player is running and cannot see enemy {\displaystyle hitchance = \begin{cases} 256-(dist \times 16), & \mbox{if player is walking and can see enemy} \\ 256-(dist \times 8), & \mbox{if player is walking and cannot see enemy} \\ 160-(dist \times 16), & \mbox{if player is running and can see enemy} \\ 160-(dist \times 8), & \mbox{if player is running and cannot see enemy} \end{cases} }
Damage calculation[]
base damage = { ⌊ r a n d ÷ 4 ⌋ , if r a n d l t ; h i t c h a n c e and d i s t l t ; 2 ⌊ r a n d ÷ 8 ⌋ , if r a n d l t ; h i t c h a n c e and 2 l t ; d i s t l t ; 4 ⌊ r a n d ÷ 16 ⌋ , if r a n d l t ; h i t c h a n c e and 4 l t ; d i s t 0 , if r a n d > h i t c h a n c e {\displaystyle {\mbox{base damage}}={\begin{cases}\lfloor rand\div 4\rfloor ,&{\mbox{if }}rand<hitchance{\mbox{ and }}dist<2\\\lfloor rand\div 8\rfloor ,&{\mbox{if }}rand<hitchance{\mbox{ and }}2<dist<4\\\lfloor rand\div 16\rfloor ,&{\mbox{if }}rand<hitchance{\mbox{ and }}4<dist\\0,&{\mbox{if }}rand>hitchance\end{cases}}}
Note the floor function around the division—due to the use of bit shift rather than true division, the output is rounded down. This allows the player's health to never stray from being a whole number. The maximum damage (255/4) is therefore 63 rather than 63.75. The minimum is zero, even with a successful hit.
As with all damage to the player, the actual damage received is one-fourth of the base damage if the player is playing at "Can I play, Daddy?" difficulty.[4] Save for godmode, the two are otherwise equal.
Graph[]
Damage formula (player shooting)[]
The formula for the player's shots also has a double calculation, though simpler. The same variables as the previous case are used.[5]
base damage = { r a n d ÷ 4 , if d i s t l t ; 2 r a n d ÷ 6 , if 2 l t ; d i s t l t ; 4 r a n d ÷ 6 , if 4 l t ; d i s t and ( r a n d ÷ 12 ) > d i s t 0 , if 4 l t ; d i s t and ( r a n d ÷ 12 ) l t ; d i s t {\displaystyle {\mbox{base damage}}={\begin{cases}rand\div 4,&{\mbox{if }}dist<2\\rand\div 6,&{\mbox{if }}2<dist<4\\rand\div 6,&{\mbox{if }}4<dist{\mbox{ and }}(rand\div 12)>dist\\0,&{\mbox{if }}4<dist{\mbox{ and }}(rand\div 12)<dist\end{cases}}}
References[]
- ↑ WOLFSRC/WL_ACT2.C from the Wolfenstein 3D source code on github.com, line 3444
- ↑ WOLFSRC/ID_US_A.ASM from the Wolfenstein 3D source code on github.com
- ↑ WOLFSRC/WL_ACT2.C from the Wolfenstein 3D source code on github.com, line 3461
- ↑ 4.0 4.1 WOLFSRC/WL_AGENT.C from the Wolfenstein 3D source code on github.com, line 392
- ↑ WOLFSRC/WL_AGENT.C from the Wolfenstein 3D source code on github.com, line 1168