-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Improve the Pokédex AREA functionality
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:
FindWildLocationsOfMon:
ld hl, WildDataPointers
ld de, wBuffer
ld c, $0
.loop
inc hl
ld a, [hld]
inc a
jr z, .done
push hl
ld a, [hli]
ld h, [hl]
ld l, a
ld a, [hli]
and a
call nz, CheckMapForMon ; land
+ jr c, .passWaterCheck
ld a, [hli]
and a
call nz, CheckMapForMon ; water
+.passWaterCheck
pop hl
inc hl
inc hl
inc c
jr .loop
.done
ld a, $ff ; list terminator
ld [de], a
ret
CheckMapForMon:
inc hl
ld b, NUM_WILDMONS
.loop
ld a, [wPokedexNum]
cp [hl]
jr nz, .nextEntry
ld a, c
ld [de], a
inc de
+ scf ; set c flag if match found
+ ret
.nextEntry
inc hl
inc hl
dec b
jr nz, .loop
dec hl
+ and a ; clear flags if no match found
ret