Werewolf

From ZAMN Hacking
Monster data
HP 11
Points 300
Entity data
Entity pointer $81:ABF5

The werewolf is a respawning monster. Werewolves will only spawn if the level has palette fade that has completed, though this condition can be bypassed by using $81:ABFB as the entity pointer instead.

Behavior[edit]

Werewolves can be in one of three states:

  • Walking: Move towards the nearest targetable sprite at an average rate of 1.5 px/frame. Werewolves start in this state.
    • If the werewolf is exactly 360 pixels away from the target, then despawn.
    • If the werewolf's health has changed, jump in a random diagonal direction a distance of 20-51 pixels on the X axis and 15-46 pixels on the Y axis.
    • If the werewolf is between 70 and 344 pixels of the target, then there is a 15/255 (5.88%) chance to jump at the target.
      • If the target is a victim, jump 28 pixels past the target on the X axis.
      • Otherwise, jump 124 pixels past the target on the X axis.
    • If the werewolf is less than 4 pixels from the target on the Y axis and less than 29 pixels on the X axis, then attack.
  • Jumping: Jumping is implemented as three separate states:
    • Pre-jump: Do a 17 frame pre-jump animation.
    • Main jump: Move at a constant speed towards the destination point. The total duration of the jump (in frames) is the distance on the larger of the two axes divided by 4. The werewolf has no collision during this phase. After the jump is complete, the game attempts to adjust the werewolf's position if it lands too close to the target, but this is bugged.
    • Post-jump: Do a 15 frame landing animation. Then attack if the werewolf is less than 4 pixels from the target on the Y axis and less than 29 pixels on the X axis. If not attacking, wait a random amount of time from 1 to 16 frames, then go back to the walking state.
  • Attacking: Perform a 27 frame attack animation. During the last 12 frames of this, there is an additional sprite hitbox created 25 pixels to the left or right of the werewolf. Once complete, go back to the walking state.

Weapon damage[edit]

Werewolves take normal damage from all weapons except silverware, which kills them in one hit.

Bugs[edit]

  • Werewolves attempt to adjust their position upon landing if they are within 9 pixels of the target on the X axis. It is intended to move an additional 15 pixels on the X axis and 8 pixels on the Y axis, but there are several bugs in the implementation.
    • The position offset table has the wrong values for the down-left entry (uses values for up-left instead).
    • The table is indexed incorrectly and reads the wrong values for each direction.
    • The function that determines the direction of the jump is bugged to only return left, right, or none. This bug actually prevents reading past the end of the table due to the incorrect indexing.
    • The end result of these bugs is that the werewolf will move down 15 pixels if the jump was to the right, and up 15 pixels if it was to the left.
  • Werewolves only despawn if they are exactly 360 pixels away from the nearest targetable sprite. Since players move at 2 px/frame orthogonally, the distance can go directly from 359 to 361, causing the werewolf not to despawn.
  • It's not clear if this is a bug or intended behavior, but werewolves will never jump straight up or down. This is because their target position would be exactly on top of the sprite they are trying to jump at, and since all target sprites are solid to monsters, the jump is not allowed.

RAM map[edit]

Entity arguments[edit]

Address Length Type Description
$00 2 int16 X position
$02 2 int16 Y position

Entity memory[edit]

Address Length Type Description
$08 2 pointer16 Pointer to sprite
$0A 2 pointer16 Current state subroutine pointer
$0C 2 uint16 Current animation frame (x2 during attack animation)
$0E 2 int16 0-based Number of frames until next animation frame
$10 2 boolean Dead
$12 2 int16 X position
$14 2 int16 Y position
$16 2 int16 New X position
$18 2 int16 New Y position
$1A 2 direction Current direction
$1C 2 unused Unused
$1E 2 optional pointer16 Pointer to sprite that is being jumped at (0xFFFF if empty)
$20 2 int16 Jump target X position
$22 2 int16 Jump target Y position
$24 2 int16 x4 Z velocity during jump
$26 2 uint16 Duration of jump in frames
$28 2 uint16 Fractional portion of X position during jump (full X position = $12 + ($28/$26))
$2A 2 uint16 Fractional portion of Y position during jump (full Y position = $14 + ($2A/$26))
$2C 2 uint16 Jump distance X magnitude
$2E 2 uint16 Jump distance Y magnitude
$30 2 int16 Jump distance X sign (1 if jump is right, -1 if left)
$32 2 int16 Jump distance Y sign (1 if jump is down, -1 if up)
$34 2 direction Jump direction (only left or right due to a bug)
$36 2 uint16 Temporary storage
$38 2 optional pointer16 Extra attack hitbox sprite (0xFFFF if empty)
$3A 2 int16 0-based Previous health
$3C 2 int16 0-based Health
$3E 2 sprite type Type of weapon shot sprite collided with
$40 2 unused Unused
$42 2 pointer16 Pointer to target sprite
$44 2 uint16 Distance to target sprite
$7E 2 unused Value is set but not used