User:Furey/Sandbox, Attack Type
In NetHack, a monster may have up to 6 attacks. Each attack has a defined attack type and damage type. The attack type determines how the attack makes contact with the defender, and the damage type determines how the attack affects the defender if it hits.
Each attack type has an internal ID used in the source code.[1]. For precision, we also use this symbol when describing the attack types.
An attack type can be melee, where the attacker must be next to the defender, or ranged, where the attacker may attack the defender from a distance. An attacker may attack a defender with a ranged attack type even if they are next to the defender. A few attack types are both melee and ranged.
Most attack types consider the defender's armor class, but some attack types do not. TODO: which ones?
TODO: i'm confusing "melee" and "range <= 2", gotta get that straight.
List of attack types
ID | Name | Melee or ranged | Must overcome | Dispatch function (internal) |
---|---|---|---|---|
AT_NONE | Passive | melee | passive | passive (dispatched through hitum, not hitmu) |
AT_CLAW | Claw | melee | armor class | hitmu |
AT_BITE | Bite | melee | armor class | hitmu |
AT_KICK | Kick | melee | armor class | hitmu |
AT_BUTT | Head butt | melee | armor class | hitmu |
AT_TUCH | Touch | melee | armor class | hitmu |
AT_STNG | Sting | melee | armor class | hitmu |
AT_HUGS | Bear hug | melee | previous two attacks must have hit or hero is stuck to attacker | hitmu |
AT_SPIT | Spit | ranged | spitmu | |
AT_ENGL | Engulf | melee | armor class to swallow you, then automatic hit | gulpmu |
AT_BREA | Breath | ranged | breamu | |
AT_EXPL | Explodes | melee | always succeeds | explmu |
AT_BOOM | Explodes when killed | melee | corpse_chance | |
AT_GAZE | Gaze | ranged | defender must see attacker but fails 3⁄4 time if defender is hallucinating. | gazemu |
AT_TENT | Tentacle | melee | armor class | hitmu |
AT_WEAP | Weapon attack | melee or ranged | hitmu (melee), thrwmu (ranged) | |
AT_MAGC | Magic attack | melee or ranged | castmu (melee), (range) |
Passive attacks
AT_NONE indicates a special attack type known as a passive attack. A passive attack is something that the defender does back to the attacker during combat. Common examples are the paralysis attack of a floating eye and the cold attack of a blue jelly.
Effect of displacement
If the defender has the displacement property, then the attacker may perceive the defender to be on a different square from the defender's actual location. If another creature is on that square, the attacker will attack the unfortunate other creature instead! A melee attack affected by displacement will always miss, but a ranged attack will proceed as usual. TODO: check each attack type.
Displacement does not help against a gaze attack.
Displacement does not help against an engulfing attack after you have been swallowed.
Effect of magic cancellation
Magic cancellation is a property that the character may have which prevents certain attacks. Magic cancellation requires that the attack have both an eligible attack type and an eligibile damage type. And even then, there is only a probability of preventing the attack.
These attack types are eligible to be cancelled: claw, bite, kick, head butt, touch, sting, bear hug, tentacle, and weapon attack at melee distance. All other attack types are immune to magic cancellation: passive, spit, engulf, breath, explodes, explodes when killed, gaze, weapon attack at ranged distance, magic attack at melee distance, magic attack at ranged distance.
Internals
TODO: move this into my user space.
Both source-diving players and documentation-maintaining editors may be interested in these internals.
mattacku takes care of a bunch of features and then switches on the attack type.
Besides the specific functions mentioned, these source files contain useful auxiliary functions.
Source File | Function | Notes |
---|---|---|
include/monattk.h in NetHack 3.6.7, line 8 | - | defines the AT_* values |
src/mhitu.c in NetHack 3.6.7, line 260 | getmattk | select a monster attack, with subs, such as !SEDUCE, vortex after engulf, rider stun on second attack}} |
src/mhitu.c in NetHack 3.6.7, line 354 | mattacku | monster (m) attacks you (u) |
History
NetHack 3.4.3
The attack types and their AT_* symbols are the same in NetHack 3.4.3 as they are in NetHack 3.6.7.
TODO: read mattacku in 3.4.3, verify that the dispatch functions are the same (or similar). Check where AC gets checked. Important to see which AT_* dispatch to mhitu, and that mhitu is the only thing that checks magic cancellation.
NetHack 3.7-dev
TODO