Jump to content

Focus Energy glitch: Difference between revisions

m
→‎Analysis: Use <syntaxhighlight> tags for assembly code.
>Sherkel
(New page: {{Misc R/B}} The '''Focus Energy Glitch''' is a glitch in Pokémon Red and Blue Versions involving the effect of the move Focus Energy. Focus Energy is a move that, ever since [[bp:Ge...)
 
m (→‎Analysis: Use <syntaxhighlight> tags for assembly code.)
 
(11 intermediate revisions by 7 users not shown)
Line 1:
{{Misc R/B}}
{{PRAMA|glitches-mineurs-rbj#Puissance}}
The '''Focus Energy Glitch''' is a [[glitch]] in Pokémon Red and Blue Versions involving the effect of the move Focus Energy.
The '''Focus Energy glitch''' is a glitch in {{RBY}} that causes the move [[bp:Focus Energy|Focus Energy]] to decrease (more precisely, quarter) the user's critical hit rate instead of increasing it, like the move does in all other versions of the game.
 
A remarkable side effect of this glitch is that it is difficult to tell which critical hit rate is the originally intended base critical hit rate in Generation I, because {{Stadium}} uses [[bp:Critical hit#In Pokémon Stadium|a different critical hit rate formula]], and since Generation II the base critical hit rate has become constant.
Focus Energy is a move that, ever since [[bp:Generation II|Generation II]], increased the user's critical hit rate. This glitch, causing it to sometimes do the opposite, was fixed in [[bp:Pokémon Stadium|Pokémon Stadium]].
==Focus Energy's original effect==
After Focus Energy is used, any move that does not have an increased critical hit rate (Razor Leaf, Slash, Crabhammer, Karate Chop) will have one quarter of the normal chance to land a critical hit.
 
==Analysis==
As for moves with increased critical hit rates, the reduction is dependent on the user's speed. If the user is faster than the opponent, no reduction occurs. If the user is somewhat slower than the opponent (exact numbers still need to be found,) then its critical hit rate will lower by 50%. If the user is significantly slower than the opponent, then it will become impossible for the user to land a critical hit.
The relevant block of code for Focus Energy's effect is this<ref>[https://github.com/pret/pokered/blob/bb76c06120bcd1fc0f86bd3cc96cbbde93c0c80c/engine/battle/core.asm#L4610-L4619 The same block of code in the pokered disassembly]</ref>, beginning at offset 3E055 in Pokémon Red and Blue (view 0F:6055 in a debugger). Thanks Wack0 for walking through this.
 
<syntaxhighlight lang="asm">
bit 2, a ; test for focus energy
jr nz, .focusEnergyUsed
sla b ; b=b*2
jr nc, .noFocusEnergyUsed ; if b was below 128, skip...
ld b, $ff ; a cap at 255/256
jr .noFocusEnergyUsed
.focusEnergyUsed
srl b ; whoops! b=b/2, and if you look, the jump to here is before the b=b*2, so b is effectively 1/4 of what it should be
.noFocusEnergyUsed ; no cap at 255/256 for focus energy. I wonder if, if done properly, this would have caused bugs related to integer wraparound...
; ... (check for high critical hit move here)
</syntaxhighlight>
 
The relative jump to '.focusEnergyUsed' that happens when Focus Energy is used makes the game skip a 'sla b' (double b), and then a 'srl b' (half b) at '.focusEnergyUsed' halves the value in register 'b'.
 
If Focus Energy is not used, the value in 'b' is doubled and if it was used, the value in 'b' is halved. 2.0/0.5=4.0, meaning critical hits land four times less likely.
 
==Ambiguity==
Due to this glitch, the critical hit rate of a Pokémon that has used Focus Energy is <code>BaseSpeed / 2048</code>, lower than the critical rate of a Pokémon that has not used Focus Energy, <code>BaseSpeed / 512</code>. However, it is unclear whether the intended critical hit rates are:
* <code>BaseSpeed / 512</code> without Focus Energy, and <code>BaseSpeed / 128</code> with Focus Energy; or
* <code>BaseSpeed / 2048</code> without Focus Energy, and <code>BaseSpeed / 512</code> with Focus Energy.
 
The first theory is more intuitive because it means that this glitch only affects Pokémon that has used Focus Energy, which means that it would be less likely to notice. Furthermore, the developers of the game may have written this piece of code first, then balanced the game around the perceived base critical hit rate later.
 
However, as alluded to by Wack0's comments above, there is no really easy way to fix the above code to fit the first theory: The value in 'b' would need to be shifted left ''three'' times so that it is multiplied by 8, compared to 2 in the normal case, and care must be taken to prevent overflow. On the other hand, in order to fit the second theory, the "jr nz, .focusEnergyUsed" simply needs to be changed to "jr z, .focusEnergyUsed" (notice that the names of labels are added by people documenting the assembly according to functionality, and do not reflect anything official).
 
{{Stadium}} changed the critical hit rate formula to a "flatter" formula affected less by the base speed: <code>(BaseSpeed + 76) / 1024</code> without Focus Energy and <code>(BaseSpeed + 236) / 512</code> with Focus Energy. While the resulting values are closer to what would be predicted by the first theory, the divisors seem closer to the second theory. Generation II changed the base critical hit rate again to a flat value of 1/16, which would be equivalent to a very slow (base speed 32, slightly faster than Snorlax) Pokémon in the first theory, and a very fast (base speed 128, slightly slower than Jolteon) in the second theory, so again, it could go either way.
 
== References ==
<references />
 
[[Category:Generation I glitches]]
Cookies help us deliver our services. By using our services, you agree to our use of cookies.