Comments (4)
I'm testing with Blue, who has two Full Restores and he's able to use both items perfectly. I also checked the code and didn't see any irregularity.
from pokecrystal.
Just looking at the code I found a potential issue... Althought i'd need to test to make sure.
AI_TryItem:
; items are not allowed in the Battle Tower
ld a, [wInBattleTowerBattle]
and a
ret nz
ld a, [wEnemyTrainerItem1]
ld b, a
ld a, [wEnemyTrainerItem2]
or b
ret z
call .IsHighestLevel
ret nc
ld a, [wTrainerClass]
dec a
ld hl, TrainerClassAttributes + TRNATTR_AI_ITEM_SWITCH
ld bc, NUM_TRAINER_ATTRIBUTES
call AddNTimes
ld b, h
ld c, l
+ ; hl = AI_Items item script pointer table
ld hl, AI_Items
+ ; de = the first item of two that the enemy trainer is using.
ld de, wEnemyTrainerItem1
.loop
ld a, [hl]
and a
inc a
+ ; if [hl] = -1 then return (end of table)
ret z
ld a, [de]
cp [hl]
+ ; if current [hl] is equal to [wEnemyTrainerItem1] then we found our item, execute item script
jr z, .has_item
+ ; increment de to point to wEnemyTrainerItem2
inc de
ld a, [de]
cp [hl]
+ ; if current [hl] is equal to [wEnemyTrainerItem2] then we found our item, execute itme script
jr z, .has_item
+ ; we did not found either items on current hl row, decrement de back to wEnemyTrainerItem1
dec de
+ ; increment hl to the next row in AI_Items table
inc hl
inc hl
inc hl
+ ; re-rerun the above on the next row.
jr .loop
.has_item
+ ; we found a matching item, increment hl to the first byte of the script pointer.
inc hl
+ ; we push hl & de onto the stack.. Note that if we jumped from a matching wEnemyTrainerItem2,
+ ; then de is still pointing to wEnemyTrainerItem2 and not wEnemyTrainerItem1.
push hl
push de
+ ; load the address of .callback into de
ld de, .callback
+ ; push the address of .callback onto the stack, when we return after the jump, we will return
+ ; to this address!
push de
+ ; jump to the script for this AI_Items row.
ld a, [hli]
ld h, [hl]
ld l, a
jp hl
.callback
+ ; We have returned from executing the script. Restore hl & de, remember,
+ ; that de will be either wEnemyTrainerItem1 or wEnemyTrainerItem2 depending on where we jumped from
+ ; before.
pop de
pop hl
+ ; increment past the pointer to the start of the next AI_Items row.
inc hl
inc hl
+ ; if the item script DID NOT use the item, for example if the item cures a status condition, and the pokemon
+ ; is not under any status conditions, then we loop again... This is a problem if we jumped from wEnemyTrainerItem2 as de
+ ; will still be set to the address of wEnemyTrainerItem2.. Which means that when it tries to increment de again to grab
+ ; what it thinks is wEnemytrainerItem2, It will be in fact wEnemyTrainerRewards address, ect.
jr c, .loop
; used item
+ ; if the item was used.. then we set either wEnemyTrainerItem1 or wEnemyTrainerItem2 to 0.
xor a
ld [de], a
from pokecrystal.
I think I would personally fix this by doing:
...
ld hl, AI_Items
- ld de, wEnemyTrainerItem1
.loop
+ ld de, wEnemyTrainerItem1
ld a, [hl]
and a
inc a
ret z
...
Hopefully the above makes sense; if not I can try to explain it better.. I haven't test any of this at all.. or traced it in bgb yet.. Just what I guessed from looking at the code.
from pokecrystal.
Oh yes, you're right! There's a chance it might not use the item it finds which I didn't account for.
from pokecrystal.
Related Issues (20)
- Add dupeframes.py tool to find duplicate Pokemon frames
- Bug: Mind Reader and Lock-On don't prevent the AI from failing status moves that have a 25% chance to fail (when used by AI) HOT 1
- Make types easier to edit with rept HOT 4
- [Bug] ["no-maps" Branch] Whiting out while set to the default spawnpoint causes a crash HOT 1
- Inaccurate function names HOT 5
- Use grayscale PNGs plus normal.pal files for Pokemon and trainer sprites HOT 3
- Refactor tools/dupeframes.py HOT 2
- Incorrect Mystery Gift decorations HOT 5
- Support `-` for stdin and stdout in bpp2png and other tools HOT 1
- The `list_start` macro should take a max string length for `li` to check HOT 3
- Move charmap.asm to constants/
- Lowercase "pret" in Discord link HOT 2
- Sweet scent can still be used after being overwritten by a newly learned move HOT 2
- Bug: CheckObjectCoveredByTextbox doesn't account for the background scroll (SCX/SCY)
- Bug: Map cursor on New Bark Town when on S.S. Aqua HOT 1
- Use named constants for warp IDs? HOT 16
- Bug: Closing textboxes overlapping tiles $80+ glitches out for a frame HOT 3
- TextCommand_WAIT_BUTTON naming HOT 2
- Bug: Mania uses wrong dialogue for trying to return Shuckie with no other Pokémon
- .editorconfig support HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pokecrystal.