« on: November 26, 2012, 09:28:39 am »
pokemon white 2 does some funny things in its breeding code. to create an egg, they:
-create a full wild pokemon for the sole purpose of creating a free 220 byte block and a pointer to it(they have a memory allocation system that could easily do this)
-create a 34-element u32 array where they arrange a bunch of features that the egg will have(inherited ivs, inherited moves species, et al)(there's a good amount of extraneous data in this)
-use the previous pointer as a start in creating a second full wild pokemon
-after making the second full pokemon, write all the values from the egg data array into the correct spots, the set some values for the egg, and finally set the marker that makes it an egg
in the end they generate 3 pids, 18 ivs, and loads of other extraneous values. it's really kind of a mess.
e: almost forgot the best part.
breeding in bw2 uses its own special inline rng. it uses a special seed they create when the game boots. however, due to a programming mistake, every time you restart the game the first egg you breed will be identical aside from the species and pid.
the way it works is when you start a new game, on loading into the world for the first time, the game creates a seed and saves it to your save file. each time you restart a new seed is made and copied into the right spot for breeding. after that, the old seed is read in front the save and written in. then the old seed is written in a second time when the entire daycare block is copied into place.