# Pokemon Emerald

## byCrosspeice

### Part 45: How Overhauled Pokemon Tick (Part 2 - PID)

Side Notes #04: How Overhauled Pokemon Tick (Part 2 - PID) So the PID is a 32-bit integer that determines a lot of thing. Gender is determined by the last eight digits and ranges from Genderless (11111111) to always Female (1111110), to always Male (0000000). If the Pokemon has a chance of being either gender, the number generated is compared against the gender threshold, a number generated between 1 and 253. If the PID number is greater than or equal to the threshold, the Pokemon is male, otherwise it is female. Because of this, ratios are still slightly skewed until Gen 6.

Ability is determined by the lowest bit, in the gender string, but only if it can have more than one ability, since the game forces that value to be 0 for single Ability Pokemon. If it's odd, the Pokemon has their first slot Ability and then even for the second slot. Because of this, Pokemon that gained an ability in Gen 4 will switch abilities as 0 is even, so the first ability will always become the second, as the PID is rechecked.

Nature is determined by PID mod 25 (so what whole remainder is left over when dividing by 25), from 0 to 24. Each nature has a corresponding number which I don't fancy listing.

Now shininess is the big one. This depends on the Trainer ID, the Secret ID (which you'll never know about unless you cheat) and on both halves of the PID, split down the middle as P1 and P2. This is determined by the formula S = IDTrainer ⊕ IDSecret ⊕ p1 ⊕ p2. If you have no idea what the ⊕ is, I didn't until this very sentence. Basically, A ⊕ B = C, outputs C such that, if Ai (bit i of A) and Bi are different, then Ci is 1; otherwise it is 0. Mathematics, man. After that is worked out, if the resulting number at the end if less than 8 then it is shiny. Obviously with so many variations in numbers, this makes it a very rare occurance, though having your Trainer ID and Secret ID match more helps for this.

Unown's letter is determined by the collection of the last two bits in each four bytes and then calculated by Pletter mod 28, with 0 being A, to ? and ! being 26 and 27. Wurmple's evolution, meanwhile, is determined by the upper half of its personality value, so if that value is divided by 10 and the remainder is less than or equal to 4, Wurmple will evolve into Silcoon, if it's greater than 4, Cascoon. So since it's 0-4, or 5-9... then it's 50/50.

Spinda has four spots on its body, two on its face, two on its ears. Where the x and y co-ordinates cross is where the top left corner of the spot is placed. Each of the four bytes in the PID correspond to a spot and the x coordinate is determined by the lower four bits of that byte, with the y coordinate determined by the upper four bits. So does this mean Spinda actually has 4,294,967,296 different combinations, sine it draws from the whole PID? Well, no, some values will have Spinda's spots either overlapping each other, or not on Spinda's body at all, so ones that we actually notice as being different are in fact fewer.

Finally, there are some NPCs who wish to see a Pokemon of a large size. Yep, this is determined by the PID and not simply either, cause why wouldn't it? Overall height is determined by the lowest two bytes of the PID, split into P1 and P2, again, as well as IVs (only the four least significant bits of each stat, so one bit is usused), as well as the Pokemon's height, though those numbers are predetermined. So, the calculation starts off easy with s = ( ( (Atk' ⊕ Def') * HP' ) ⊕ p1 ) * 256 + ( ( (SpAtk' ⊕ SpDef') * Spd' ) ⊕ p2 ). Don't worry if you didn't get that, this is only for nerdy weirdos who think they understand it.

From there, height is the species height in tenths of a metre and three more values, x, y and z are determined by what s results to, using this table: FROM THERE, h, x, y, z and s are put into this formula: ( (s-z) / y + x ) * h / 10, which is then rounded down, then converted to inches, THEN rounded down to the nearest tenth of an inch. Simple, right? All for two bumfucks in each game to measure it.

Last, but not least, the PID determines when Mirage Island appears, if the lower half of a Pokemon's PID in the party matches a random number generated at the start of each day. If it matches, the island appears.