Jump to content

Heracross size formula


Metropolis

Recommended Posts

I took a quick look at it and here's what I've come up with.

Some breakpoints from FireRed US 1.1:

0x080A0840: check_new_height(poke_id, record_ptr)

0x080A06B0: calc_hval(pkm_ptr)

0x080A0784: calc_height(poke_id, hval)

0x08088E4C: get_dex_height(dex_id)

0x080A0754: get_hval_class(hval)

The height of the Pokémon is calculated based on the Pokémon's PID and IVs and normalized, then multiplied by the Pokémon species' average height as listed in the Pokédex. The formulas are below.

Calculating the hval (^ meaning exclusive OR):

a = ((iv_atk ^ iv_def) & 0xF) * (iv_hp & 0xF)

b = ((iv_spatk ^ iv_spdef) & 0xF) * (iv_spe & 0xF)

hval = (pid & 0xFFFF) ^ (a | (b << 8))

A lookup table is used for normalization:

[table]

[tr][td]class[/td][td]min[/td][td]base[/td][td]size[/td][/tr]

[tr][td]0[/td][td]0[/td][td]290[/td][td]1[/td][/tr]

[tr][td]1[/td][td]10[/td][td]300[/td][td]1[/td][/tr]

[tr][td]2[/td][td]110[/td][td]400[/td][td]2[/td][/tr]

[tr][td]3[/td][td]310[/td][td]500[/td][td]4[/td][/tr]

[tr][td]4[/td][td]710[/td][td]600[/td][td]20[/td][/tr]

[tr][td]5[/td][td]2710[/td][td]700[/td][td]50[/td][/tr]

[tr][td]6[/td][td]7710[/td][td]800[/td][td]100[/td][/tr]

[tr][td]7[/td][td]17710[/td][td]900[/td][td]150[/td][/tr]

[tr][td]8[/td][td]32710[/td][td]1000[/td][td]150[/td][/tr]

[tr][td]9[/td][td]47710[/td][td]1100[/td][td]100[/td][/tr]

[tr][td]10[/td][td]57710[/td][td]1200[/td][td]50[/td][/tr]

[tr][td]11[/td][td]62710[/td][td]1300[/td][td]20[/td][/tr]

[tr][td]12[/td][td]64710[/td][td]1400[/td][td]5[/td][/tr]

[tr][td]13[/td][td]65210[/td][td]1500[/td][td]2[/td][/tr]

[tr][td]14[/td][td]65410[/td][td]1600[/td][td]1[/td][/tr]

[tr][td]15[/td][td]65510[/td][td]1700[/td][td]1[/td][/tr]

[/table]

Height class is determined from the largest minimum that's less than the hval.

Normalized hval calculation:

hnorm = base + (hval - min) / size

The Pokémon's average height in meters is pulled from the Pokédex data to calculate the individual Pokémon size in meters. In the ROM the height is stored multiplied by 10, hence the division below.

hmeter = hdex * hnorm / 10

Finally, the height is converted to inches as such:

hinch = hmeter * 100 / 254

Link to comment
Share on other sites

Wow great work! Cool that they used a normal distribution :-)

Are you sure you mean metres, not millimetres? I'm playing an EU ROM, where the pokedex is displayed as feet and inches. Is the result of a conversion calculation too?

The reading the woman gave my Heracross is 44.0 inches. The values I get just before the *100/254 conversion range from 1677 to 2586. After that, they range from 640 to 1018, so not sure exactly how to get the 44 figure out.

Here's the Java code I used to iterate through all the values:

public static void main(String[] args) {

for (int heracrossValue = 0; heracrossValue < 0xFFFF; heracrossValue++) {

int size = calculateHeracrossSize(heracrossValue);

System.out.println(size);

}

}

private static int calculateHeracrossSize(int heracrossValue) {

int index = 0;

while (index < 15 && HERACROSS_MIN[index + 1] < heracrossValue) {

index++;

}

int ret = heracrossValue;

ret -= HERACROSS_MIN[index];

ret /= HERACROSS_SIZE[index];

ret += HERACROSS_BASE[index];

ret *= 15;

ret /= 10;

ret *= 100;

ret /= 254;

return ret;

}

This verifies that the result increases with hvalue. There's no dips and the highest value is when hval is 0xFFFF. This allows for generation of the (unique) lower half of the PID that will give the max height for any given IVs.

These are PIDs for max-IV Heracross of each nature, in order from Hardy (0) to Quirky (24) that will give maximum height when shown to the Six Island woman:

1048575

458751

1507327

917503

327679

1376255

786431

196607

1245183

655359

65535

1114111

524287

1572863

983039

393215

1441791

851967

262143

1310719

720895

131071

1179647

589823

1638399

Link to comment
Share on other sites

Incidentally, the formula appears to be the same for the Magikarp checker just south of Lavender Tower.

My Editor now has an action to maximise size for Gen 3 Magikarp and Heracross.

I've also implemented this formula for the gen 2 Lake of Rage Magikarp checker. The action adjusts IVs to the (unique) combination for that Magikarp's trainer ID. ie it computes the best Magikarp for your trainer ID.

There is a unique Magikarp with max size and max IVs - the ID must be 0. Conversely the ID must be 65535 to get max size with minimum IVs.

Another corollary of the formula is that only eight trainer IDs allow for a shiny and largest-possible magikarp. Where defense, speed and special DVs are each 10, these combinations are:

ID: 60074, attack IV: 2

ID: 58026, attack IV: 3

ID: 51882, attack IV: 6

ID: 49834, attack IV: 7

ID: 43690, attack IV: 10

ID: 41642, attack IV: 11

ID: 35498, attack IV: 14

ID: 33450, attack IV: 15

Edited by Metropolis
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...