The action hitbox, like all abstract mechanical concepts, is a name given to us by MathOnNapkins in his US disassembly. This hitbox describes the current size and location of Link's sword and hammer attacks. Its routine begins at
$06F5E6, and is surprisingly simple.
Hitboxes are very simple shapes. In fact, they're rectangles defined by 4 parameters:
x- The x-position of the top-left corner of the rectangle
y- The y-position of the top-left corner of the rectangle
w- The length in pixels that the rectangle extends towards the right; i.e. its width
h- The length in pixels that the rectangle extends downwards; i.e. its height
For the action hitbox specifically,
y will be relative offsets, rather than absolute. That is, all values of
y will need to be added to Link's x- and y-coordinates to get the actual position of the hitbox.
Hitboxes are simple shapes because this cuts down on calculation time. Even modern 3D games still use basic shapes (spheres or rectangular prisms), because they are much more efficient. These games tend to use a whole lot of them to approximate more complex shapes, but the calculations are so fast and easy that this turns out to be better than a single complicated calculation.
Within the action hitbox routine, there are several branches to determine which hitbox is used, checked in the following order:
The dashing hitbox is used whenever the dashing flag at
$0372 is nonzero. The direction Link is facing is used to index tables just before the routine to determine the relative offsets of the top-left corner. Regardless of Link's direction, the dash hitbox always extends 16 pixels right and 16 pixels down.
The spin hitbox is next, because it's dead simple, and because the next two sets need to be discussed together. This hitbox is used when bit7 of
$3C, an address for sword control, is set.
Link's direction is completely irrelevant for the spin hitbox. This hitbox will always be 14 pixels up, 10 pixels left, and extend 44 pixels right and 44 pixels down.
The hammer and net hitboxes point to the same branch, which is taken when the hammer is flagged (bit 1 or unused bit 3 of
$0301) or the net is flagged (bit 4 of
$037A). This routine shares code with slashing and poking, but there's a key difference. Believe it or not, the direction Link is facing is not taken into account.
The sword control address
$3C handles spin attacks, but it also handles whether or not a hitbox should even be calculated for other sword attacks. In this case, when the value is non-negative, it indexes a table (shown to the right), for this decision. For the hammer and net, the value here is irrelevant.
The parameters of the hitbox are indexed from various tables using the
X register. For the hammer and net, this index is always 0, but for sword attacks, it is a function of Link's direction and the current animation step of the attack, which is held in
$3C. Once this index is calculated, both branches merge, and the rest of the routine is the same.
If direction is irrelevant for the hammer and net, how are their hitboxes actually different?
This is where two more variables come into play. They're pretty much an additional offset to
y, so we'll call them
These offsets are constantly being recalculated, and they depend mostly on Link's current action and the direction he's facing. So I kinda lied. Direction does matter for the hammer and net, but it's done indepedently in an entirely separate part of the code. Furthermore, this means direction matters twice for slash and poke attacks.
As for why the sword can extend the hammer hitbox, that's just because a hitbox calculation is requested after the sword has placed its values, but before the offsets are reset again.
With just that much information, the calculations are super simple:
xhitbox = xLink + xi + Ox
yhitbox = yLink + yi + Oy
whitbox = wi
hhitbox = hi
vi just indicates the variable came from our tables indexed by the
X register, which we will call
I to avoid confusion. The table is documented below, but keep reading afterwards.
Interestingly, I didn't make any mention of how exactly a hitbox is cancelled. That's because, they kind of aren't. In the case where everything else fails the scratch space values are mostly left alone. The only one that isn't is the high byte of the x-coordinate, which will take on the value
0x80. This means the existing values will be used for the size and vertical position of the hitbox, but the horizontal position will be anywhere from −32513 to −32768 pixels away.
What about the offsets for the hammer? Most of the time, these extra offsets are
0x80. They are only set to proper values for a single frame. But, nothing actually prevents the hitbox from being created. Instead, it will just use that default value. Unfortunately, everything that requests an action hitbox also checks
Oy beforehand, skipping the request and subsequent hitbox code if the value is exactly
And as one last thing: ya know that thing where you hit King Helma and then he clinks you and you see the clink at the bottom. What's that about?
At first, I thought it had to do with those offsets, since there's a routine for placing what's known as a repulse spark, and they're used in the calculation.
It turns out to be even dumber.
When you hit King Helma with the hammer while outmaneuvering him, the game uses a routine to calculate the velocity of Link's recoil. In doing so, it leaves some leftovers in scratch space. And for some got dang reason, right after doing that, those same leftovers are used for the coordinates of the repulse spark.
I think what they were going for is using the leftovers of the action hitbox routine for these coordinates, but, yeah…