Skip to content

Improve the Pokédex AREA functionality

RainbowMetalPigeon edited this page Feb 21, 2024 · 3 revisions

The CheckMapForMon function, used by the Pokédex AREA functionality, can be easily improved. In its vanilla version, bugs will happen as soon as more than 30 individual encounter slots with one specific Pokémon are coded: e.g., Tentacool appears in 3 maps, 10 slots each, for a grand total of 30 individual encounter slots. If one tries to add even one more encounter slot in any map, the wBuffer variable won't be anymore big enough to host all of these, and will "leak" into other wram variables, generating a number of unintended effects. This is due to the fact that CheckMapForMon saves every single encounter, and keeps looping in a specific map even after has found a single match. This is wasteful in terms of memory and CPU, and can be easily improved as shown below. There is even a function fully dedicated to get rid of copies of the same entry, which can be skipped entirely in case all of your grass encounters are different from your water encounters in each given map.

In engine/items/item_effects.asm, just edit the following:

CheckMapForMon:
	inc hl
	ld b, NUM_WILDMONS
.loop
	ld a, [wd11e]
	cp [hl]
	jr nz, .nextEntry
	ld a, c
	ld [de], a
	inc de
+	inc hl
+	ret
.nextEntry
	inc hl
	inc hl
	dec b
	jr nz, .loop
	dec hl
	ret
Clone this wiki locally