Preparing for Battle
It's been a very long time since I've last posted here, but that's mainly because the to-do list in the last post was so long. I finished everything I really wanted to finish, which was all of the Pokemon- and item-related stuff, so battling would only be battling and not worrying about stuff like leveling up. To be fair, I skipped the scripting commands I had planned because I realized they're not as necessary. I dumped the data for wild encounters and trainers (which was annoying, and I'll explain why in a bit), so now implementing encounters is what I'll be doing next.
Wild Encounters
Wild encounters are easy. Dumping the data was extremely simple, especially since I already had ClassicMap loading it. The pre-battle fading is really easy too - fade to black, from black, to white, from white; rinse and repeat a couple times - so those shouldn't give too many issues. I've also figured out (but have yet to dump) the battle transitions, so those should be fun.
Dealing with wild Pokemon encounters is actually quite interesting. Rather than check if you're "on" grass or "in" water, check if rand() % x == 0, and do battles that way, it's a bit more complicated than that. The way the game checks for wild Pokemon is as follows:
-Has it been 3 steps since the last battle? If yes, is the bottom right tile the tileset's grass tile? If yes, is RND < grass encounter rate? If yes, we have a wild battle.
-Has it been 3 steps since the last battle? If yes, is the bottom right tile the tileset's water tile? If yes, is RND < water encounter rate? If yes, we have a wild battle.
Now here is where things get interesting, and why the Missingno. glitch exists. Is the bottom left tile water? If yes, use the water Pokemon. If not, use the grass Pokemon. You can exploit this fact in a couple of places. In the area just south of palette down, surf along the west coast where there is a little bit of land. Even though you're surfing, you'll encounter the grass Pokemon. This is true for any place that has a water encounter rate and grass Pokemon.
So why does the Missingno. glitch occur? When you surf on the east coast of Cinnabar Island, you're in the next map over. This map has a water Pokemon encounter rate, but no grass (Nor does Cinnabar Island). Therefore, it skips loading grass Pokemon. But remember I said the corners it checks for rates and Pokemon sets is different. The game sees you're moving on water, so it uses the water encounter rate, but the grass Pokemon set for what you encounter. When you talk to the man in Viridian City, the game stores your name in the grass set list, which is why your name determines what you encounter. Flying from any map to Cinnabar island will cause its coast to use the last grass set that was loaded.
Long story short, the Missingno. glitch will work exactly the same in PMR, without much effort.
Trainer Battles
So I thought these were going to be a piece of cake originally, since each trainer contains a trainer ID and a Pokemon set. However, the game stores trainer viewing distances and their battle text in places only accessible through scripts. No pointer tables - they're loaded inside of the map's scripts. But fortunately, GameFreak was very consistent in how they loaded trainer headers. They would load HL with the address of the header, and then DE with something else. If they didn't load DE with anything, there would be no trainer headers. I just had to make the dumper detect this and bam, I had a map's trainer header pointers.
That's pretty much all I have to say for battle encounters. Hopefully you learned a thing or two.