Open Idain opened 7 months ago
Nicely explained, thank you!
@Rangi42, done. Let me know if there's something else to address.
While we're at it, I'd add a ; BUG:
marker to this, replacing some redundant bits of explanation if possible.
https://github.com/pret/pokecrystal/wiki/Code-cleanup#refer-to-docsbugs_and_glitchesmd-instead-of-explaining-a-bug-inline
@mid-kid, how is it now?
This pull request tackles two documentation topics about Magikarp's length:
1. Wrong comment about maximum Magikarp's length in
CalcMagikarpLength
First of all, let's talk about
CalcMagikarpLength
. This function first calculates the length in millimeters by using the Magikarp's DVs and the Trainer ID, and then convert it to feet and inches. The maximum length a Magikarp can have (in millimeters) is 1625mm (bugged version)/1755mm (fixed version), but the comment inside the function says the maximum is 1786mm (the bug makes it so that onlyb
is used when calculating the length, instead ofbc
). To check this, I've run various calculations, both accounting for the bug inCalcMagikarpLength.BCLessThanDE
and with the fixed version.To prove this, let's assume
bc
has the maximum possible value ($ffff
). According toCalcMagikarpLength
, ifbc ≥ $ff00: [wMagikarpLength] = c + 1370
, whose code is located here, so let's start calculating:Q: "According to the comment inside
CalcMagikarpLength
, the formula is different ifbc < $ff00
, so maybe the result could be 1786mm?"A: I also accounted for this, and no, the max possible result is either 1590mm (with the bug) or 1755mm (fixed version). If you fix the function, the last threshold in the
MagikarpLength
table is used, which is 65510. Let's make two calculations, one for each version (the formula isz * 100 + (bc - x) / y
):Bugged version
Fixed version
2. Wrong fix in "Magikarp lengths can be miscalculated"
The bugfix doesn't account for cases where
b > d
, so instead of returning, it tries to compare the low bytesbc
andde
as if the high bytes were equal, which will give the wrong result. A simple fix is toret nz
to discard all cases whereb ≠ d
.