Thursday, April 24, 2014

Predicting Duplication

From Far Away

Although it may seem complicated, this trick is actually about as simple as a walljump.  Finding the values for it could be a bit tricky though, unless you equip yourself with a lua script to find them for you (as assumed for all other tricks in which you would need to go through a complex calculation for one result).

For a duplication to occur from far away, all you must do is find whether or not the oscillation of an item will allow it to reach a block's theoretical bottom - 6.  It needs to get here without reaching the theoretical position of the block (i.e. it could get to the theoretical bottom - 6 as long as it did not come to that value by being at the pixel position of the theoretical bottom the frame before (because it stops on that frame)).

The theoretical position of the block will be the cut out 16th part of the block's y position (to make its position a multiple of 16) + 13.  Using this value, all we have to do is predict the item's position at a given time, and make sure that that we stop its decreasing (because it is going to be thrown).
To find the item's total pixel position, we must add its low byte position (7e00d8 + slot) to its high byte position multiplied by 256 ((7e14d4 + slot) * 256).  Note that slot is the slot of the item being carried.  To find this in a lua script, just scroll through the sprite status table and see which slot has the carrying flag set.
To find the item's y subpixel position, we must reference just one RAM address (7e14ec + slot).

Now, all we need to do is convert that pixel position and subpixel position to total subpixels.  When we have all of this, we are able to predict the new positions that the item will reach.  As I mentioned before, you want to make sure that for each frame you scroll through, it needs to be checked if the item is passed the block.  Only initially check this at the start of a loop, as you will be increasing the item's position and searching for if it has the capability of reaching the block's theoretical position - 6 from the block's theoretical position + 1 within one frame.
The shell's y speed oscillation starts at -112 when released upwards and this delta increases by 3 every frame.

This picture has the theoretical attributes of the block, in case you were confused when I explained it earlier.  Note the position prediction at the top middle of the screen.

If the condition of reaching 6 pixels into the theoretical bottom from the theoretical bottom + 1 (or more) is true, we need a way to detect which way the duplication will occur.  The way an item is shoved out of a block actually depends on the frame counter of the game.  So, if we take a value f for the frame value before the duplication, and add 1 initial frame that it takes to release the shell, and n frames to when the block will be duplicated, this will be the final frame counter.  If this is an even number, it will duplicate right, and it will duplicate left otherwise.

If I were to release the item on this frame (which means that I would need to go a frame before this and release the shell), the shell would go into the block to 327.90, and 327 is 333 - 6, except it would reach this from 334 on one frame, which means that these are perfect conditions for a duplication.  Using the frame counter, it is figured that the shell will duplicate the block to the right.

Proof that an item oscillates just enough to duplicate the block at sub 20 from 3 tiles away.

Predicting Normal Duplication

While there is a specific pattern to duplication from afar, there are only a few sets of rules for duplication right at the block's position.

(Subpixels are ignored in the following rules.  For this example, I will be using a shell in slot 9.  Note its attributes in each given picture)
If you are duplicating to the right, the game frame counter (7e0013) + 1 must be even, the item you are duplicating with must be in between the theoretical bottom of the block and the theretical bottom - 7, and must have an x position within the range of the theoretical right of the block - 9 and the theoretical right - 3.  If those conditions are achieved, a duplication to the right can occur.

If you are duplicating to the left, the game frame counter must be odd, the item must be in the same y range as when duplicating right, but must be within the x positions of the theoretical left + 2 and the theoretical left + 7.

If you are duplicating upwards, the game frame counter does not matter.  However, the y position of the item must be  exactly 8 or 7 pixels from the theoretical bottom of the block, and in an area constrained by 1 on regular x axis rules for to the left and right.

If the conditions are fulfilled for both left/right and up, a block will be duplicated diagonally.

No comments:

Post a Comment