jojobear13 / shinpokered

Mostly-vanilla hack of Pokémon Red/Blue focused on bugfixes and trainer ai
205 stars 40 forks source link

Bug: New Itemfinder bugs #324

Closed suloku closed 7 months ago

suloku commented 7 months ago

There are two problems witht he current itemfinder:

  1. When the map has more than one hidden items, wItemFinderAttributes will hold the previous set bits, so extra arrows can be displayed on the following entries.

Fix:

.popHLloop
    pop hl
+++xor a
+++ld [wItemFinderAttributes ], a
    jp .loop
  1. When the player is 8 or 9 tiles away from the hidden item, no arrows will be displayed. The reason: max distance to a hidden item on-screen is 9. The code increases the distance (stored in c) three times, so for distance 8 and 9 it will always be bigger than 10 in the first loop. Fix:
    
    ld a, c
    cp 13
    jr c, .loop2
    .return_carry
    scf
    ret


Tested the fixes and working correctly. I'll take the oportunity to give my thanks to this amazing project.
jojobear13 commented 7 months ago

Help me understand Point 2 a little more. Do you mean actual tiles (squares of 8 x 8 pixels), or do you mean discrete spaces that NPCs stand in (composed of four tiles). If you mean the latter, that being stand-able spaces, I believe the max distance for the itemfinder is 5 because the distance is measured from the player's coordinates.

Nevermind. I see now. But I confirm that this is working correctly. I think the issue here is a misunderstanding in how the function treats diagonal distance. It does not do the Pythagorean theorem (and I am not even going to try on the GBC's processor). Instead, a diagonal is abstracted by adding the X distance to the Y distance. This results in a max distance of 9 looking like the following. It will produce 1 chime. image

suloku commented 7 months ago

Oh, I see, so intended behavior is that being on a big distance won't show any arrows. I think that is a little missleading, so I'm gonna go with my version to show the arrows always if the item is on-screen, but thanks for the clarification. This was the setup were I found out: image

jojobear13 commented 7 months ago

No, the intended behavior of your given image is that 1 chime with arrows will sound for the space in purple. I went and replicated your setup with the master branch, and I confirmed that it works in said manner. So maybe there's a code discrepancy between the main repo and your own local repo.

Either way, I incorporated item 1. Glad your fix is working for you on item 2.

suloku commented 7 months ago

Thank you, I'll check against master, see if I hsve some unnoticed mistake. I did incorporate the code on another project, but I already tried to make sure the code was correct, will check again.