# Hitscan

*809*pages on

this wiki

**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)Edit

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]}

### VariablesEdit

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 detectionEdit

### Damage calculationEdit

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.

### GraphEdit

## Damage formula (player shooting)Edit

The formula for the player's shots also has a double calculation, though simpler. The same variables as the previous case are used.^{[5]}

## ReferencesEdit

- ↑ 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