diff options
Diffstat (limited to 'engine/items')
-rwxr-xr-x | engine/items/items.asm | 2437 |
1 files changed, 1247 insertions, 1190 deletions
diff --git a/engine/items/items.asm b/engine/items/items.asm index f37f9f47..e147f5a5 100755 --- a/engine/items/items.asm +++ b/engine/items/items.asm @@ -1,18 +1,18 @@ UseItem_: ; d2ed (3:52ed) - ld a,1 - ld [wActionResultOrTookBattleTurn],a ; initialise to success value - ld a,[wcf91] ;contains item_ID - cp a,HM_01 - jp nc,ItemUseTMHM - ld hl,ItemUsePtrTable + ld a, 1 + ld [wActionResultOrTookBattleTurn], a ; initialise to success value + ld a, [wcf91] ;contains item_ID + cp a, HM_01 + jp nc, ItemUseTMHM + ld hl, ItemUsePtrTable dec a add a - ld c,a - ld b,0 - add hl,bc - ld a,[hli] - ld h,[hl] - ld l,a + ld c, a + ld b, 0 + add hl, bc + ld a, [hli] + ld h, [hl] + ld l, a jp [hl] ItemUsePtrTable: ; d307 (3:5307) @@ -101,135 +101,137 @@ ItemUsePtrTable: ; d307 (3:5307) dw ItemUsePPRestore ; MAX_ELIXER ItemUseBall: ; d3ad (3:53ad) - ld a,[wIsInBattle] + ld a, [wIsInBattle] and a - jp z,ItemUseNotTime ; not in battle + jp z, ItemUseNotTime ; not in battle dec a - jp nz,ThrowBallAtTrainerMon - ld a,[wBattleType] + jp nz, ThrowBallAtTrainerMon + ld a, [wBattleType] cp $1 - jr z,.UseBall + jr z, .UseBall cp $4 ; pikachu battle? - jr z,.UseBall - ld a,[wPartyCount] ;is Party full? - cp a,PARTY_LENGTH - jr nz,.UseBall - ld a,[wNumInBox] ;is Box full? - cp a,MONS_PER_BOX - jp z,BoxFullCannotThrowBall + jr z, .UseBall + ld a, [wPartyCount] ;is Party full? + cp a, PARTY_LENGTH + jr nz, .UseBall + ld a, [wNumInBox] ;is Box full? + cp a, MONS_PER_BOX + jp z, BoxFullCannotThrowBall .UseBall ;ok, you can use a ball xor a - ld [wCapturedMonSpecies],a - ld a,[wBattleType] - cp a,2 ;SafariBattle - jr nz,.skipSafariZoneCode + ld [wCapturedMonSpecies], a + ld a, [wBattleType] + cp a, 2 ;SafariBattle + jr nz, .skipSafariZoneCode .safariZone ; remove a Safari Ball from inventory - ld hl,wNumSafariBalls + ld hl, wNumSafariBalls dec [hl] .skipSafariZoneCode call RunDefaultPaletteCommand - ld a,$43 - ld [wd11e],a + ld a, $43 + ld [wd11e], a call LoadScreenTilesFromBuffer1 ;restore screenBuffer from Backup - ld hl,ItemUseText00 + ld hl, ItemUseText00 call PrintText callab IsGhostBattle - ld b,$10 - jp z,.next12 - ld a,[wBattleType] + ld b, $10 + jp z, .next12 + ld a, [wBattleType] cp $1 - jr z,.oldManBattle + jr z, .oldManBattle cp $4 - jr z,.oldManBattle ; pikachu battle technically old man battle + jr z, .oldManBattle ; pikachu battle technically old man battle jr .notOldManBattle + .oldManBattle - ld hl,wGrassRate - ld de,wPlayerName - ld bc,NAME_LENGTH + ld hl, wGrassRate + ld de, wPlayerName + ld bc, NAME_LENGTH call CopyData ; save the player's name in the Wild Monster data ld a, [wBattleType] cp $1 - jp nz,.BallSuccess - ld a,$1 + jp nz, .BallSuccess + ld a, $1 ld [wCapturedMonSpecies], a ld a, [wd74c] bit 7, a ld b, $63 - jp nz,.next12 + jp nz, .next12 jp .BallSuccess + .notOldManBattle - ld a,[wCurMap] - cp a,POKEMONTOWER_6 - jr nz,.loop - ld a,[wEnemyMonSpecies2] - cp a,MAROWAK - ld b,$10 - jp z,.next12 + ld a, [wCurMap] + cp a, POKEMONTOWER_6 + jr nz, .loop + ld a, [wEnemyMonSpecies2] + cp a, MAROWAK + ld b, $10 + jp z, .next12 ; if not fighting ghost Marowak, loop until a random number in the current ; pokeball's allowed range is found .loop call Random - ld b,a - ld hl,wcf91 + ld b, a + ld hl, wcf91 .asm_d54a - ld a,[hl] - cp a,MASTER_BALL - jp z,.BallSuccess - cp a,POKE_BALL - jr z,.checkForAilments - ld a,200 + ld a, [hl] + cp a, MASTER_BALL + jp z, .BallSuccess + cp a, POKE_BALL + jr z, .checkForAilments + ld a, 200 cp b - jr c,.loop ;get only numbers <= 200 for Great Ball - ld a,[hl] - cp a,GREAT_BALL - jr z,.checkForAilments - ld a,150 ;get only numbers <= 150 for Ultra Ball + jr c, .loop ;get only numbers <= 200 for Great Ball + ld a, [hl] + cp a, GREAT_BALL + jr z, .checkForAilments + ld a, 150 ;get only numbers <= 150 for Ultra Ball cp b - jr c,.loop + jr c, .loop .checkForAilments ; pokemon can be caught more easily with any (primary) status ailment ; Frozen/Asleep pokemon are relatively even easier to catch ; for Frozen/Asleep pokemon, any random number from 0-24 ensures a catch. ; for the others, a random number from 0-11 ensures a catch. - ld a,[wEnemyMonStatus] ;status ailments + ld a, [wEnemyMonStatus] ;status ailments and a - jr z,.noAilments + jr z, .noAilments and a, 1 << FRZ | SLP ;is frozen and/or asleep? - ld c,12 - jr z,.notFrozenOrAsleep - ld c,25 + ld c, 12 + jr z, .notFrozenOrAsleep + ld c, 25 .notFrozenOrAsleep - ld a,b + ld a, b sub c - jp c,.BallSuccess - ld b,a + jp c, .BallSuccess + ld b, a .noAilments push bc ;save RANDOM number xor a - ld [H_MULTIPLICAND],a - ld hl,wEnemyMonMaxHP - ld a,[hli] - ld [H_MULTIPLICAND + 1],a - ld a,[hl] - ld [H_MULTIPLICAND + 2],a - ld a,255 - ld [H_MULTIPLIER],a + ld [H_MULTIPLICAND], a + ld hl, wEnemyMonMaxHP + ld a, [hli] + ld [H_MULTIPLICAND + 1], a + ld a, [hl] + ld [H_MULTIPLICAND + 2], a + ld a, 255 + ld [H_MULTIPLIER], a call Multiply ; MaxHP * 255 - ld a,[wcf91] + ld a, [wcf91] cp GREAT_BALL - ld a,12 ;any other BallFactor - jr nz,.next7 - ld a,8 + ld a, 12 ;any other BallFactor + jr nz, .next7 + ld a, 8 .next7 - ld [H_DIVISOR],a - ld b,4 ; number of bytes in dividend + ld [H_DIVISOR], a + ld b, 4 ; number of bytes in dividend call Divide - ld hl,wEnemyMonHP - ld a,[hli] - ld b,a - ld a,[hl] + ld hl, wEnemyMonHP + ld a, [hli] + ld b, a + ld a, [hl] ; explanation: we have a 16-bit value equal to [b << 8 | a]. ; This number is divided by 4. The result is 8 bit (reg. a). @@ -239,242 +241,247 @@ ItemUseBall: ; d3ad (3:53ad) srl b rr a ; a = current HP / 4 and a - jr nz,.next8 + jr nz, .next8 inc a .next8 - ld [H_DIVISOR],a - ld b,4 + ld [H_DIVISOR], a + ld b, 4 call Divide ; ((MaxHP * 255) / BallFactor) / (CurHP / 4) - ld a,[H_QUOTIENT + 2] + ld a, [H_QUOTIENT + 2] and a - jr z,.next9 - ld a,255 - ld [H_QUOTIENT + 3],a + jr z, .next9 + ld a, 255 + ld [H_QUOTIENT + 3], a .next9 pop bc - ld a,[wEnemyMonCatchRate] ;enemy: Catch Rate + ld a, [wEnemyMonCatchRate] ;enemy: Catch Rate cp b - jr c,.next10 - ld a,[H_QUOTIENT + 2] + jr c, .next10 + ld a, [H_QUOTIENT + 2] and a - jr nz,.BallSuccess ; if ((MaxHP * 255) / BallFactor) / (CurHP / 4) > 0x255, automatic success + jr nz, .BallSuccess ; if ((MaxHP * 255) / BallFactor) / (CurHP / 4) > 0x255, automatic success call Random - ld b,a - ld a,[H_QUOTIENT + 3] + ld b, a + ld a, [H_QUOTIENT + 3] cp b - jr c,.next10 + jr c, .next10 .BallSuccess jr .BallSuccess2 + .next10 - ld a,[H_QUOTIENT + 3] - ld [wd11e],a + ld a, [H_QUOTIENT + 3] + ld [wd11e], a xor a - ld [H_MULTIPLICAND],a - ld [H_MULTIPLICAND + 1],a - ld a,[wEnemyMonCatchRate] ;enemy: Catch Rate - ld [H_MULTIPLICAND + 2],a - ld a,100 - ld [H_MULTIPLIER],a + ld [H_MULTIPLICAND], a + ld [H_MULTIPLICAND + 1], a + ld a, [wEnemyMonCatchRate] ;enemy: Catch Rate + ld [H_MULTIPLICAND + 2], a + ld a, 100 + ld [H_MULTIPLIER], a call Multiply ; CatchRate * 100 - ld a,[wcf91] - ld b,255 + ld a, [wcf91] + ld b, 255 cp POKE_BALL - jr z,.next11 - ld b,200 + jr z, .next11 + ld b, 200 cp GREAT_BALL - jr z,.next11 - ld b,150 + jr z, .next11 + ld b, 150 cp ULTRA_BALL - jr z,.next11 + jr z, .next11 .next11 - ld a,b - ld [H_DIVISOR],a - ld b,4 + ld a, b + ld [H_DIVISOR], a + ld b, 4 call Divide - ld a,[H_QUOTIENT + 2] + ld a, [H_QUOTIENT + 2] and a - ld b,$63 - jr nz,.next12 - ld a,[wd11e] - ld [H_MULTIPLIER],a + ld b, $63 + jr nz, .next12 + ld a, [wd11e] + ld [H_MULTIPLIER], a call Multiply - ld a,255 - ld [H_DIVISOR],a - ld b,4 + ld a, 255 + ld [H_DIVISOR], a + ld b, 4 call Divide - ld a,[wEnemyMonStatus] ;status ailments + ld a, [wEnemyMonStatus] ;status ailments and a - jr z,.next13 + jr z, .next13 and 1 << FRZ | SLP - ld b,5 - jr z,.next14 - ld b,10 + ld b, 5 + jr z, .next14 + ld b, 10 .next14 - ld a,[H_QUOTIENT + 3] + ld a, [H_QUOTIENT + 3] add b - ld [H_QUOTIENT + 3],a + ld [H_QUOTIENT + 3], a .next13 - ld a,[H_QUOTIENT + 3] - cp a,10 - ld b,$20 - jr c,.next12 - cp a,30 - ld b,$61 - jr c,.next12 - cp a,70 - ld b,$62 - jr c,.next12 - ld b,$63 + ld a, [H_QUOTIENT + 3] + cp a, 10 + ld b, $20 + jr c, .next12 + cp a, 30 + ld b, $61 + jr c, .next12 + cp a, 70 + ld b, $62 + jr c, .next12 + ld b, $63 .next12 - ld a,b - ld [wPokeBallAnimData],a + ld a, b + ld [wPokeBallAnimData], a .BallSuccess2 - ld c,20 + ld c, 20 call DelayFrames - ld a,TOSS_ANIM - ld [wAnimationID],a + ld a, TOSS_ANIM + ld [wAnimationID], a xor a - ld [H_WHOSETURN],a - ld [wAnimationType],a - ld [wDamageMultipliers],a - ld a,[wWhichPokemon] + ld [H_WHOSETURN], a + ld [wAnimationType], a + ld [wDamageMultipliers], a + ld a, [wWhichPokemon] push af - ld a,[wcf91] + ld a, [wcf91] push af predef MoveAnimation pop af - ld [wcf91],a + ld [wcf91], a pop af - ld [wWhichPokemon],a - ld a,[wPokeBallAnimData] - cp a,$10 - ld hl,ItemUseBallText00 - jp z,.printText0 - cp a,$20 - ld hl,ItemUseBallText01 - jp z,.printText0 - cp a,$61 - ld hl,ItemUseBallText02 - jp z,.printText0 - cp a,$62 - ld hl,ItemUseBallText03 - jp z,.printText0 - cp a,$63 - ld hl,ItemUseBallText04 - jp z,.printText0 - ld hl,wEnemyMonHP ;current HP - ld a,[hli] + ld [wWhichPokemon], a + ld a, [wPokeBallAnimData] + cp a, $10 + ld hl, ItemUseBallText00 + jp z, .printText0 + cp a, $20 + ld hl, ItemUseBallText01 + jp z, .printText0 + cp a, $61 + ld hl, ItemUseBallText02 + jp z, .printText0 + cp a, $62 + ld hl, ItemUseBallText03 + jp z, .printText0 + cp a, $63 + ld hl, ItemUseBallText04 + jp z, .printText0 + ld hl, wEnemyMonHP ;current HP + ld a, [hli] push af - ld a,[hli] + ld a, [hli] push af ;backup currentHP... inc hl - ld a,[hl] + ld a, [hl] push af ;...and status ailments push hl - ld hl,wEnemyBattleStatus3 - bit Transformed,[hl] - jr z,.next15 - ld a,$4c - ld [wEnemyMonSpecies2],a + ld hl, wEnemyBattleStatus3 + bit Transformed, [hl] + jr z, .next15 + ld a, $4c + ld [wEnemyMonSpecies2], a jr .next16 + .next15 - set Transformed,[hl] - ld hl,wTransformedEnemyMonOriginalDVs - ld a,[wEnemyMonDVs] - ld [hli],a - ld a,[wEnemyMonDVs + 1] - ld [hl],a + set Transformed, [hl] + ld hl, wTransformedEnemyMonOriginalDVs + ld a, [wEnemyMonDVs] + ld [hli], a + ld a, [wEnemyMonDVs + 1] + ld [hl], a .next16 - ld a,[wcf91] + ld a, [wcf91] push af - ld a,[wEnemyMonSpecies2] - ld [wcf91],a - ld a,[wEnemyMonLevel] - ld [wCurEnemyLVL],a + ld a, [wEnemyMonSpecies2] + ld [wcf91], a + ld a, [wEnemyMonLevel] + ld [wCurEnemyLVL], a callab LoadEnemyMonData pop af - ld [wcf91],a + ld [wcf91], a pop hl pop af - ld [hld],a + ld [hld], a dec hl pop af - ld [hld],a + ld [hld], a pop af - ld [hl],a - ld a,[wEnemyMonSpecies] ;enemy - ld [wCapturedMonSpecies],a - ld [wcf91],a - ld [wd11e],a - ld a,[wBattleType] + ld [hl], a + ld a, [wEnemyMonSpecies] ;enemy + ld [wCapturedMonSpecies], a + ld [wcf91], a + ld [wd11e], a + ld a, [wBattleType] cp $1 - jp z,.printText1 ; just barely out of reach for a relative jump + jp z, .printText1 ; just barely out of reach for a relative jump cp $4 - jr z,.printText1 - ld hl,ItemUseBallText05 + jr z, .printText1 + ld hl, ItemUseBallText05 call PrintText predef IndexToPokedex - ld a,[wd11e] + ld a, [wd11e] dec a - ld c,a - ld b,FLAG_TEST - ld hl,wPokedexOwned + ld c, a + ld b, FLAG_TEST + ld hl, wPokedexOwned predef FlagActionPredef - ld a,c + ld a, c push af - ld a,[wd11e] + ld a, [wd11e] dec a - ld c,a - ld b,FLAG_SET + ld c, a + ld b, FLAG_SET predef FlagActionPredef pop af and a - jr nz,.checkParty - ld hl,ItemUseBallText06 + jr nz, .checkParty + ld hl, ItemUseBallText06 call PrintText call ClearSprites - ld a,[wEnemyMonSpecies] ;caught mon_ID - ld [wd11e],a + ld a, [wEnemyMonSpecies] ;caught mon_ID + ld [wd11e], a predef ShowPokedexData .checkParty ld a, $1 ld [wd49c], a ld a, $85 ld [wPikachuMood], a - ld a,[wPartyCount] + ld a, [wPartyCount] cp PARTY_LENGTH ;is party full? - jr z,.sendToBox + jr z, .sendToBox xor a ; PLAYER_PARTY_DATA - ld [wMonDataLocation],a + ld [wMonDataLocation], a call ClearSprites ld hl, .emptyString call PrintText call AddPartyMon ;add mon to Party jr .End + .sendToBox call ClearSprites call SendNewMonToBox - ld hl,ItemUseBallText07 + ld hl, ItemUseBallText07 ld a, [wd7f1] bit 0, a - jr nz,.sendToBox2 - ld hl,ItemUseBallText08 + jr nz, .sendToBox2 + ld hl, ItemUseBallText08 .sendToBox2 call PrintText jr .End + .printText1 - ld hl,ItemUseBallText05 + ld hl, ItemUseBallText05 .printText0 call PrintText call ClearSprites .End - ld a,[wBattleType] + ld a, [wBattleType] and a ret nz - ld hl,wNumBagItems + ld hl, wNumBagItems inc a - ld [wItemQuantity],a + ld [wItemQuantity], a jp RemoveItemFromInventory + .emptyString db "@" @@ -503,7 +510,7 @@ ItemUseBallText05: ; d6b0 (3:56b0) ;"All right! {MonName} was caught!" ;play sound TX_FAR _ItemUseBallText05 - db $12,$06 + db $12, $06 db "@" ItemUseBallText07: ; d6b7 (3:59b7) ;"X was transferred to Bill's PC" @@ -518,46 +525,47 @@ ItemUseBallText06: ; d6c1 (3:56c1) ;"New DEX data will be added..." ;play sound TX_FAR _ItemUseBallText06 - db $13,$06 + db $13, $06 db "@" ItemUseTownMap: ; d6c8 (3:56c8) - ld a,[wIsInBattle] + ld a, [wIsInBattle] and a - jp nz,ItemUseNotTime + jp nz, ItemUseNotTime jpba DisplayTownMap ItemUseBicycle: ; d6d7 (3:56d7) - ld a,[wIsInBattle] + ld a, [wIsInBattle] and a - jp nz,ItemUseNotTime - ld a,[wWalkBikeSurfState] - ld [wWalkBikeSurfStateCopy],a - cp a,2 ; is the player surfing? - jp z,ItemUseNotTime + jp nz, ItemUseNotTime + ld a, [wWalkBikeSurfState] + ld [wWalkBikeSurfStateCopy], a + cp a, 2 ; is the player surfing? + jp z, ItemUseNotTime dec a ; is player already bicycling? - jr nz,.tryToGetOnBike + jr nz, .tryToGetOnBike .getOffBike call ItemUseReloadOverworldData xor a - ld [wWalkBikeSurfState],a ; change player state to walking + ld [wWalkBikeSurfState], a ; change player state to walking ld a, $00 - ld [wd431], a + ld [wPikachuSpawnState], a call PlayDefaultMusic ; play walking music - ld hl,GotOffBicycleText + ld hl, GotOffBicycleText jp PrintText + .tryToGetOnBike call IsBikeRidingAllowed - jp nc,NoCyclingAllowedHere + jp nc, NoCyclingAllowedHere call ItemUseReloadOverworldData xor a ; no keys pressed - ld [hJoyHeld],a ; current joypad state + ld [hJoyHeld], a ; current joypad state ld a, $1 - ld [wWalkBikeSurfState],a ; change player state to bicycling + ld [wWalkBikeSurfState], a ; change player state to bicycling call PlayDefaultMusic ; play bike riding music xor a - ld [wWalkBikeSurfState],a - ld hl,GotOnBicycleText + ld [wWalkBikeSurfState], a + ld hl, GotOnBicycleText call PrintText ld a, $1 ld [wWalkBikeSurfState], a @@ -565,79 +573,82 @@ ItemUseBicycle: ; d6d7 (3:56d7) ; used for Surf out-of-battle effect ItemUseSurfboard: ; d725 (3:5725) - ld a,[wWalkBikeSurfState] - ld [wWalkBikeSurfStateCopy],a - cp a,2 ; is the player already surfing? - jr z,.tryToStopSurfing + ld a, [wWalkBikeSurfState] + ld [wWalkBikeSurfStateCopy], a + cp a, 2 ; is the player already surfing? + jr z, .tryToStopSurfing .tryToSurf call IsNextTileShoreOrWater - jp nc,SurfingAttemptFailed - ld hl,TilePairCollisionsWater + jp nc, SurfingAttemptFailed + ld hl, TilePairCollisionsWater call CheckForTilePairCollisions - jp c,SurfingAttemptFailed + jp c, SurfingAttemptFailed .surf call .makePlayerMoveForward - ld hl,wd730 - set 7,[hl] - ld a,2 - ld [wWalkBikeSurfState],a ; change player state to surfing + ld hl, wd730 + set 7, [hl] + ld a, 2 + ld [wWalkBikeSurfState], a ; change player state to surfing call PlayDefaultMusic ; play surfing music - ld hl,SurfingGotOnText + ld hl, SurfingGotOnText jp PrintText + .tryToStopSurfing xor a - ld [hSpriteIndexOrTextID],a - ld d,16 ; talking range in pixels (normal range) + ld [hSpriteIndexOrTextID], a + ld d, 16 ; talking range in pixels (normal range) call IsSpriteInFrontOfPlayer2 - res 7,[hl] - ld a,[hSpriteIndexOrTextID] + res 7, [hl] + ld a, [hSpriteIndexOrTextID] and a ; is there a sprite in the way? - jr nz,.cannotStopSurfing - ld hl,TilePairCollisionsWater + jr nz, .cannotStopSurfing + ld hl, TilePairCollisionsWater call CheckForTilePairCollisions - jr c,.cannotStopSurfing - ld a,[wTileInFrontOfPlayer] - ld c,a + jr c, .cannotStopSurfing + ld a, [wTileInFrontOfPlayer] + ld c, a call IsTilePassable - jr nc,.stopSurfing + jr nc, .stopSurfing .cannotStopSurfing - ld hl,SurfingNoPlaceToGetOffText + ld hl, SurfingNoPlaceToGetOffText jp PrintText + .stopSurfing call .makePlayerMoveForward - ld a,$3 - ld [wd431], a - ld hl,wPikachuOverworldStateFlags - set 5,[hl] - ld hl,wd730 - set 7,[hl] + ld a, $3 + ld [wPikachuSpawnState], a + ld hl, wPikachuOverworldStateFlags + set 5, [hl] + ld hl, wd730 + set 7, [hl] xor a - ld [wWalkBikeSurfState],a ; change player state to walking + ld [wWalkBikeSurfState], a ; change player state to walking dec a - ld [wJoyIgnore],a + ld [wJoyIgnore], a call PlayDefaultMusic ; play walking music call GBPalWhiteOutWithDelay3 jp LoadWalkingPlayerSpriteGraphics + ; uses a simulated button press to make the player move forward .makePlayerMoveForward - ld a,[wPlayerDirection] ; direction the player is going - bit PLAYER_DIR_BIT_UP,a - ld b,D_UP - jr nz,.storeSimulatedButtonPress - bit PLAYER_DIR_BIT_DOWN,a - ld b,D_DOWN - jr nz,.storeSimulatedButtonPress - bit PLAYER_DIR_BIT_LEFT,a - ld b,D_LEFT - jr nz,.storeSimulatedButtonPress - ld b,D_RIGHT + ld a, [wPlayerDirection] ; direction the player is going + bit PLAYER_DIR_BIT_UP, a + ld b, D_UP + jr nz, .storeSimulatedButtonPress + bit PLAYER_DIR_BIT_DOWN, a + ld b, D_DOWN + jr nz, .storeSimulatedButtonPress + bit PLAYER_DIR_BIT_LEFT, a + ld b, D_LEFT + jr nz, .storeSimulatedButtonPress + ld b, D_RIGHT .storeSimulatedButtonPress - ld a,b - ld [wSimulatedJoypadStatesEnd],a + ld a, b + ld [wSimulatedJoypadStatesEnd], a xor a - ld [wWastedByteCD39],a + ld [wWastedByteCD39], a inc a - ld [wSimulatedJoypadStatesIndex],a + ld [wSimulatedJoypadStatesIndex], a ret SurfingGotOnText: ; d7c1 (3:57c1) @@ -652,25 +663,25 @@ ItemUsePokedex: ; d7cb (3:57cb) predef_jump ShowPokedexMenu ItemUseEvoStone: ; d7d0 (3:57d0) - ld a,[wIsInBattle] + ld a, [wIsInBattle] and a - jp nz,ItemUseNotTime - ld a,[wWhichPokemon] + jp nz, ItemUseNotTime + ld a, [wWhichPokemon] push af - ld a,[wcf91] - ld [wEvoStoneItemID],a + ld a, [wcf91] + ld [wEvoStoneItemID], a push af - ld a,EVO_STONE_PARTY_MENU - ld [wPartyMenuTypeOrMessageID],a - ld a,$ff - ld [wUpdateSpritesEnabled],a + ld a, EVO_STONE_PARTY_MENU + ld [wPartyMenuTypeOrMessageID], a + ld a, $ff + ld [wUpdateSpritesEnabled], a call DisplayPartyMenu ld a, [wcf91] ld [wLoadedMon], a pop bc - jr c,.canceledItemUse - ld a,b - ld [wcf91],a + jr c, .canceledItemUse + ld a, b + ld [wcf91], a call Func_d85d jr nc, .noEffect callab IsThisPartymonStarterPikachu_Party @@ -687,24 +698,26 @@ ItemUseEvoStone: ; d7d0 (3:57d0) ld a, $82 ld [wPikachuMood], a jr .canceledItemUse + .notPlayerPikachu - ld a,SFX_HEAL_AILMENT + ld a, SFX_HEAL_AILMENT call PlaySoundWaitForCurrent call WaitForSoundToFinish - ld a,$01 - ld [wForceEvolution],a + ld a, $01 + ld [wForceEvolution], a callab TryEvolvingMon ; try to evolve pokemon pop af - ld [wWhichPokemon],a - ld hl,wNumBagItems - ld a,1 ; remove 1 stone - ld [wItemQuantity],a + ld [wWhichPokemon], a + ld hl, wNumBagItems + ld a, 1 ; remove 1 stone + ld [wItemQuantity], a jp RemoveItemFromInventory + .noEffect call ItemUseNoEffect .canceledItemUse xor a - ld [wActionResultOrTookBattleTurn],a ; item not used + ld [wActionResultOrTookBattleTurn], a ; item not used pop af ret @@ -748,6 +761,7 @@ Func_d85d: ; d85d (3:585d) jr nz, .loop scf ret + .cannotEvolveWithUsedStone and a ret @@ -757,42 +771,43 @@ RefusingText: ; d8a2 (3:58a2) db "@" ItemUseVitamin: ; d8a7 (3:58a7) - ld a,[wIsInBattle] + ld a, [wIsInBattle] and a - jp nz,ItemUseNotTime + jp nz, ItemUseNotTime ItemUseMedicine: ; d8ae (3:58ae) - ld a,[wPartyCount] + ld a, [wPartyCount] and a - jp z,Func_e4bf - ld a,[wWhichPokemon] + jp z, Func_e4bf + ld a, [wWhichPokemon] push af - ld a,[wcf91] + ld a, [wcf91] push af - ld a,USE_ITEM_PARTY_MENU - ld [wPartyMenuTypeOrMessageID],a - ld a,$ff - ld [wUpdateSpritesEnabled],a - ld a,[wPseudoItemID] + ld a, USE_ITEM_PARTY_MENU + ld [wPartyMenuTypeOrMessageID], a + ld a, $ff + ld [wUpdateSpritesEnabled], a + ld a, [wPseudoItemID] and a ; using Softboiled? - jr z,.notUsingSoftboiled + jr z, .notUsingSoftboiled ; if using softboiled call GoBackToPartyMenu jr .getPartyMonDataAddress + .notUsingSoftboiled call DisplayPartyMenu .getPartyMonDataAddress - jp c,.canceledItemUse - ld hl,wPartyMons - ld bc,wPartyMon2 - wPartyMon1 - ld a,[wWhichPokemon] + jp c, .canceledItemUse + ld hl, wPartyMons + ld bc, wPartyMon2 - wPartyMon1 + ld a, [wWhichPokemon] call AddNTimes - ld a,[wWhichPokemon] - ld [wUsedItemOnWhichPokemon],a - ld d,a - ld a,[wcf91] - ld e,a - ld [wd0b5],a + ld a, [wWhichPokemon] + ld [wUsedItemOnWhichPokemon], a + ld d, a + ld a, [wcf91] + ld e, a + ld [wd0b5], a pop af push af cp $28 @@ -804,90 +819,92 @@ ItemUseMedicine: ; d8ae (3:58ae) pop hl .asm_d906 pop af - ld [wcf91],a + ld [wcf91], a pop af - ld [wWhichPokemon],a - ld a,[wPseudoItemID] + ld [wWhichPokemon], a + ld a, [wPseudoItemID] and a ; using Softboiled? - jr z,.checkItemType + jr z, .checkItemType ; if using softboiled - ld a,[wWhichPokemon] + ld a, [wWhichPokemon] cp d ; is the pokemon trying to use softboiled on itself? - jr z,ItemUseMedicine ; if so, force another choice + jr z, ItemUseMedicine ; if so, force another choice .checkItemType - ld a,[wcf91] - cp a,REVIVE - jr nc,.healHP ; if it's a Revive or Max Revive - cp a,FULL_HEAL - jr z,.cureStatusAilment ; if it's a Full Heal - cp a,HP_UP - jp nc,.useVitamin ; if it's a vitamin or Rare Candy - cp a,FULL_RESTORE - jr nc,.healHP ; if it's a Full Restore or one of the potions + ld a, [wcf91] + cp a, REVIVE + jr nc, .healHP ; if it's a Revive or Max Revive + cp a, FULL_HEAL + jr z, .cureStatusAilment ; if it's a Full Heal + cp a, HP_UP + jp nc, .useVitamin ; if it's a vitamin or Rare Candy + cp a, FULL_RESTORE + jr nc, .healHP ; if it's a Full Restore or one of the potions ; fall through if it's one of the status-specifc healing items .cureStatusAilment - ld bc,4 - add hl,bc ; hl now points to status - ld a,[wcf91] + ld bc, 4 + add hl, bc ; hl now points to status + ld a, [wcf91] lb bc, ANTIDOTE_MSG, 1 << PSN - cp a,ANTIDOTE - jr z,.checkMonStatus + cp a, ANTIDOTE + jr z, .checkMonStatus lb bc, BURN_HEAL_MSG, 1 << BRN - cp a,BURN_HEAL - jr z,.checkMonStatus + cp a, BURN_HEAL + jr z, .checkMonStatus lb bc, ICE_HEAL_MSG, 1 << FRZ - cp a,ICE_HEAL - jr z,.checkMonStatus + cp a, ICE_HEAL + jr z, .checkMonStatus lb bc, AWAKENING_MSG, SLP - cp a,AWAKENING - jr z,.checkMonStatus + cp a, AWAKENING + jr z, .checkMonStatus lb bc, PARALYZ_HEAL_MSG, 1 << PAR - cp a,PARLYZ_HEAL - jr z,.checkMonStatus + cp a, PARLYZ_HEAL + jr z, .checkMonStatus lb bc, FULL_HEAL_MSG, $ff ; Full Heal .checkMonStatus - ld a,[hl] ; pokemon's status + ld a, [hl] ; pokemon's status and c ; does the pokemon have a status ailment the item can cure? - jp z,.healingItemNoEffect + jp z, .healingItemNoEffect ; if the pokemon has a status the item can heal xor a - ld [hl],a ; remove the status ailment in the party data - ld a,b - ld [wPartyMenuTypeOrMessageID],a ; the message to display for the item used - ld a,[wPlayerMonNumber] + ld [hl], a ; remove the status ailment in the party data + ld a, b + ld [wPartyMenuTypeOrMessageID], a ; the message to display for the item used + ld a, [wPlayerMonNumber] cp d ; is pokemon the item was used on active in battle? - jp nz,.doneHealing + jp nz, .doneHealing ; if it is active in battle xor a - ld [wBattleMonStatus],a ; remove the status ailment in the in-battle pokemon data + ld [wBattleMonStatus], a ; remove the status ailment in the in-battle pokemon data push hl - ld hl,wPlayerBattleStatus3 - res BadlyPoisoned,[hl] ; heal Toxic status + ld hl, wPlayerBattleStatus3 + res BadlyPoisoned, [hl] ; heal Toxic status pop hl - ld bc,30 - add hl,bc ; hl now points to party stats - ld de,wBattleMonMaxHP - ld bc,10 + ld bc, 30 + add hl, bc ; hl now points to party stats + ld de, wBattleMonMaxHP + ld bc, 10 call CopyData ; copy party stats to in-battle stat data predef DoubleOrHalveSelectedStats jp .doneHealing + .healHP inc hl ; hl = address of current HP - ld a,[hli] - ld b,a - ld [wHPBarOldHP+1],a - ld a,[hl] - ld c,a - ld [wHPBarOldHP],a ; current HP stored at wHPBarOldHP (2 bytes, big-endian) + ld a, [hli] + ld b, a + ld [wHPBarOldHP+1], a + ld a, [hl] + ld c, a + ld [wHPBarOldHP], a ; current HP stored at wHPBarOldHP (2 bytes, big-endian) or b - jr nz,.notFainted + jr nz, .notFainted .fainted - ld a,[wcf91] - cp a,REVIVE - jr z,.updateInBattleFaintedData - cp a,MAX_REVIVE - jr z,.updateInBattleFaintedData + ld a, [wcf91] + cp a, REVIVE + jr z, .updateInBattleFaintedData + cp a, MAX_REVIVE + jr z, .updateInBattleFaintedData jp .healingItemNoEffect + .updateInBattleFaintedData ld a, [wWhichPokemon] push af @@ -903,486 +920,499 @@ ItemUseMedicine: ; d8ae (3:58ae) pop af ld [wWhichPokemon], a - ld a,[wIsInBattle] + ld a, [wIsInBattle] and a - jr z,.compareCurrentHPToMaxHP + jr z, .compareCurrentHPToMaxHP push hl push de push bc - ld a,[wUsedItemOnWhichPokemon] - ld c,a - ld hl,wPartyFoughtCurrentEnemyFlags - ld b,FLAG_TEST + ld a, [wUsedItemOnWhichPokemon] + ld c, a + ld hl, wPartyFoughtCurrentEnemyFlags + ld b, FLAG_TEST predef FlagActionPredef - ld a,c + ld a, c and a - jr z,.next - ld a,[wUsedItemOnWhichPokemon] - ld c,a - ld hl,wPartyGainExpFlags - ld b,FLAG_SET + jr z, .next + ld a, [wUsedItemOnWhichPokemon] + ld c, a + ld hl, wPartyGainExpFlags + ld b, FLAG_SET predef FlagActionPredef .next pop bc pop de pop hl jr .compareCurrentHPToMaxHP + .notFainted - ld a,[wcf91] - cp a,REVIVE - jp z,.healingItemNoEffect - cp a,MAX_REVIVE - jp z,.healingItemNoEffect + ld a, [wcf91] + cp a, REVIVE + jp z, .healingItemNoEffect + cp a, MAX_REVIVE + jp z, .healingItemNoEffect .compareCurrentHPToMaxHP push hl push bc - ld bc,32 - add hl,bc ; hl now points to max HP + ld bc, 32 + add hl, bc ; hl now points to max HP pop bc - ld a,[hli] + ld a, [hli] cp b - jr nz,.skipComparingLSB ; no need to compare the LSB's if the MSB's don't match - ld a,[hl] + jr nz, .skipComparingLSB ; no need to compare the LSB's if the MSB's don't match + ld a, [hl] cp c .skipComparingLSB pop hl - jr nz,.notFullHP + jr nz, .notFullHP .fullHP ; if the pokemon's current HP equals its max HP - ld a,[wcf91] - cp a,FULL_RESTORE - jp nz,.healingItemNoEffect + ld a, [wcf91] + cp a, FULL_RESTORE + jp nz, .healingItemNoEffect inc hl inc hl - ld a,[hld] ; status ailment + ld a, [hld] ; status ailment and a ; does the pokemon have a status ailment? - jp z,.healingItemNoEffect - ld a,FULL_HEAL - ld [wcf91],a + jp z, .healingItemNoEffect + ld a, FULL_HEAL + ld [wcf91], a dec hl dec hl dec hl jp .cureStatusAilment + .notFullHP ; if the pokemon's current HP doesn't equal its max HP xor a - ld [wLowHealthAlarm],a ;disable low health alarm - ld [wChannelSoundIDs + CH4],a + ld [wLowHealthAlarm], a ;disable low health alarm + ld [wChannelSoundIDs + CH4], a push hl push de - ld bc,32 - add hl,bc ; hl now points to max HP - ld a,[hli] - ld [wHPBarMaxHP+1],a - ld a,[hl] - ld [wHPBarMaxHP],a ; max HP stored at wHPBarMaxHP (2 bytes, big-endian) - ld a,[wPseudoItemID] + ld bc, 32 + add hl, bc ; hl now points to max HP + ld a, [hli] + ld [wHPBarMaxHP+1], a + ld a, [hl] + ld [wHPBarMaxHP], a ; max HP stored at wHPBarMaxHP (2 bytes, big-endian) + ld a, [wPseudoItemID] and a ; using Softboiled? - jp z,.notUsingSoftboiled2 + jp z, .notUsingSoftboiled2 ; if using softboiled - ld hl,wHPBarMaxHP - ld a,[hli] + ld hl, wHPBarMaxHP + ld a, [hli] push af - ld a,[hli] + ld a, [hli] push af - ld a,[hli] + ld a, [hli] push af - ld a,[hl] + ld a, [hl] push af - ld hl,wPartyMon1MaxHP - ld a,[wWhichPokemon] - ld bc,wPartyMon2 - wPartyMon1 + ld hl, wPartyMon1MaxHP + ld a, [wWhichPokemon] + ld bc, wPartyMon2 - wPartyMon1 call AddNTimes - ld a,[hli] - ld [wHPBarMaxHP + 1],a - ld [H_DIVIDEND],a - ld a,[hl] - ld [wHPBarMaxHP],a - ld [H_DIVIDEND + 1],a - ld a,5 - ld [H_DIVISOR],a - ld b,2 ; number of bytes + ld a, [hli] + ld [wHPBarMaxHP + 1], a + ld [H_DIVIDEND], a + ld a, [hl] + ld [wHPBarMaxHP], a + ld [H_DIVIDEND + 1], a + ld a, 5 + ld [H_DIVISOR], a + ld b, 2 ; number of bytes call Divide ; get 1/5 of max HP of pokemon that used Softboiled - ld bc,wPartyMon1HP - wPartyMon1MaxHP - add hl,bc ; hl now points to LSB of current HP of pokemon that used Softboiled + ld bc, wPartyMon1HP - wPartyMon1MaxHP + add hl, bc ; hl now points to LSB of current HP of pokemon that used Softboiled ; subtract 1/5 of max HP from current HP of pokemon that used Softboiled - ld a,[H_QUOTIENT + 3] + ld a, [H_QUOTIENT + 3] push af - ld b,a - ld a,[hl] - ld [wHPBarOldHP],a + ld b, a + ld a, [hl] + ld [wHPBarOldHP], a sub b - ld [hld],a - ld [wHPBarNewHP],a - ld a,[H_QUOTIENT + 2] - ld b,a - ld a,[hl] - ld [wHPBarOldHP+1],a + ld [hld], a + ld [wHPBarNewHP], a + ld a, [H_QUOTIENT + 2] + ld b, a + ld a, [hl] + ld [wHPBarOldHP+1], a sbc b - ld [hl],a - ld [wHPBarNewHP+1],a + ld [hl], a + ld [wHPBarNewHP+1], a coord hl, 4, 1 - ld a,[wWhichPokemon] - ld bc,2 * SCREEN_WIDTH + ld a, [wWhichPokemon] + ld bc, 2 * SCREEN_WIDTH call AddNTimes ; calculate coordinates of HP bar of pokemon that used Softboiled - ld a,SFX_HEAL_HP + ld a, SFX_HEAL_HP call PlaySoundWaitForCurrent - ld a,[hFlags_0xFFFA] - set 0,a - ld [hFlags_0xFFFA],a - ld a,$02 - ld [wHPBarType],a + ld a, [hFlags_0xFFFA] + set 0, a + ld [hFlags_0xFFFA], a + ld a, $02 + ld [wHPBarType], a predef UpdateHPBar2 ; animate HP bar decrease of pokemon that used Softboiled - ld a,[hFlags_0xFFFA] - res 0,a - ld [hFlags_0xFFFA],a + ld a, [hFlags_0xFFFA] + res 0, a + ld [hFlags_0xFFFA], a pop af - ld b,a ; store heal amount (1/5 of max HP) - ld hl,wHPBarOldHP + 1 + ld b, a ; store heal amount (1/5 of max HP) + ld hl, wHPBarOldHP + 1 pop af - ld [hld],a + ld [hld], a pop af - ld [hld],a + ld [hld], a pop af - ld [hld],a + ld [hld], a pop af - ld [hl],a + ld [hl], a jr .addHealAmount + .notUsingSoftboiled2 - ld a,[wcf91] - cp a,SODA_POP - ld b,60 ; Soda Pop heal amount - jr z,.addHealAmount - ld b,80 ; Lemonade heal amount - jr nc,.addHealAmount - cp a,FRESH_WATER - ld b,50 ; Fresh Water heal amount - jr z,.addHealAmount - cp a,SUPER_POTION - ld b,200 ; Hyper Potion heal amount - jr c,.addHealAmount - ld b,50 ; Super Potion heal amount - jr z,.addHealAmount - ld b,20 ; Potion heal amount + ld a, [wcf91] + cp a, SODA_POP + ld b, 60 ; Soda Pop heal amount + jr z, .addHealAmount + ld b, 80 ; Lemonade heal amount + jr nc, .addHealAmount + cp a, FRESH_WATER + ld b, 50 ; Fresh Water heal amount + jr z, .addHealAmount + cp a, SUPER_POTION + ld b, 200 ; Hyper Potion heal amount + jr c, .addHealAmount + ld b, 50 ; Super Potion heal amount + jr z, .addHealAmount + ld b, 20 ; Potion heal amount .addHealAmount pop de pop hl - ld a,[hl] + ld a, [hl] add b - ld [hld],a - ld [wHPBarNewHP],a - ld a,[hl] - ld [wHPBarNewHP+1],a - jr nc,.noCarry + ld [hld], a + ld [wHPBarNewHP], a + ld a, [hl] + ld [wHPBarNewHP+1], a + jr nc, .noCarry inc [hl] - ld a,[hl] - ld [wHPBarNewHP + 1],a + ld a, [hl] + ld [wHPBarNewHP + 1], a .noCarry push de inc hl - ld d,h - ld e,l ; de now points to current HP - ld hl,33 - add hl,de ; hl now points to max HP - ld a,[wcf91] - cp a,REVIVE - jr z,.setCurrentHPToHalfMaxHP - ld a,[hld] - ld b,a - ld a,[de] + ld d, h + ld e, l ; de now points to current HP + ld hl, 33 + add hl, de ; hl now points to max HP + ld a, [wcf91] + cp a, REVIVE + jr z, .setCurrentHPToHalfMaxHP + ld a, [hld] + ld b, a + ld a, [de] sub b dec de - ld b,[hl] - ld a,[de] + ld b, [hl] + ld a, [de] sbc b - jr nc,.setCurrentHPToMaxHp ; if current HP exceeds max HP after healing - ld a,[wcf91] - cp a,HYPER_POTION - jr c,.setCurrentHPToMaxHp ; if using a Full Restore or Max Potion - cp a,MAX_REVIVE - jr z,.setCurrentHPToMaxHp ; if using a Max Revive + jr nc, .setCurrentHPToMaxHp ; if current HP exceeds max HP after healing + ld a, [wcf91] + cp a, HYPER_POTION + jr c, .setCurrentHPToMaxHp ; if using a Full Restore or Max Potion + cp a, MAX_REVIVE + jr z, .setCurrentHPToMaxHp ; if using a Max Revive jr .updateInBattleData + .setCurrentHPToHalfMaxHP dec hl dec de - ld a,[hli] + ld a, [hli] srl a - ld [de],a - ld [wHPBarNewHP+1],a - ld a,[hl] + ld [de], a + ld [wHPBarNewHP+1], a + ld a, [hl] rr a inc de - ld [de],a - ld [wHPBarNewHP],a + ld [de], a + ld [wHPBarNewHP], a dec de jr .doneHealingPartyHP + .setCurrentHPToMaxHp - ld a,[hli] - ld [de],a - ld [wHPBarNewHP+1],a + ld a, [hli] + ld [de], a + ld [wHPBarNewHP+1], a inc de - ld a,[hl] - ld [de],a - ld [wHPBarNewHP],a + ld a, [hl] + ld [de], a + ld [wHPBarNewHP], a dec de .doneHealingPartyHP ; done updating the pokemon's current HP in the party data structure - ld a,[wcf91] - cp a,FULL_RESTORE - jr nz,.updateInBattleData - ld bc,-31 - add hl,bc + ld a, [wcf91] + cp a, FULL_RESTORE + jr nz, .updateInBattleData + ld bc, -31 + add hl, bc xor a - ld [hl],a ; remove the status ailment in the party data + ld [hl], a ; remove the status ailment in the party data .updateInBattleData - ld h,d - ld l,e + ld h, d + ld l, e pop de - ld a,[wPlayerMonNumber] + ld a, [wPlayerMonNumber] cp d ; is pokemon the item was used on active in battle? - jr nz,.calculateHPBarCoords + jr nz, .calculateHPBarCoords ; copy party HP to in-battle HP - ld a,[hli] - ld [wBattleMonHP],a - ld a,[hld] - ld [wBattleMonHP + 1],a - ld a,[wcf91] - cp a,FULL_RESTORE - jr nz,.calculateHPBarCoords + ld a, [hli] + ld [wBattleMonHP], a + ld a, [hld] + ld [wBattleMonHP + 1], a + ld a, [wcf91] + cp a, FULL_RESTORE + jr nz, .calculateHPBarCoords xor a - ld [wBattleMonStatus],a ; remove the status ailment in the in-battle pokemon data + ld [wBattleMonStatus], a ; remove the status ailment in the in-battle pokemon data .calculateHPBarCoords - ld hl,wOAMBuffer + $90 - ld bc,2 * 20 + ld hl, wOAMBuffer + $90 + ld bc, 2 * 20 inc d .calculateHPBarCoordsLoop - add hl,bc + add hl, bc dec d - jr nz,.calculateHPBarCoordsLoop + jr nz, .calculateHPBarCoordsLoop jr .doneHealing + .healingItemNoEffect call ItemUseNoEffect jp .done + .doneHealing - ld a,[wPseudoItemID] + ld a, [wPseudoItemID] and a ; using Softboiled? - jr nz,.skipRemovingItem ; no item to remove if using Softboiled + jr nz, .skipRemovingItem ; no item to remove if using Softboiled push hl call RemoveUsedItem pop hl .skipRemovingItem - ld a,[wcf91] - cp a,FULL_RESTORE - jr c,.playStatusAilmentCuringSound - cp a,FULL_HEAL - jr z,.playStatusAilmentCuringSound - ld a,SFX_HEAL_HP + ld a, [wcf91] + cp a, FULL_RESTORE + jr c, .playStatusAilmentCuringSound + cp a, FULL_HEAL + jr z, .playStatusAilmentCuringSound + ld a, SFX_HEAL_HP call PlaySoundWaitForCurrent - ld a,[hFlags_0xFFFA] - set 0,a - ld [hFlags_0xFFFA],a - ld a,$02 - ld [wHPBarType],a + ld a, [hFlags_0xFFFA] + set 0, a + ld [hFlags_0xFFFA], a + ld a, $02 + ld [wHPBarType], a predef UpdateHPBar2 ; animate the HP bar lengthening - ld a,[hFlags_0xFFFA] - res 0,a - ld [hFlags_0xFFFA],a - ld a,REVIVE_MSG - ld [wPartyMenuTypeOrMessageID],a - ld a,[wcf91] - cp a,REVIVE - jr z,.showHealingItemMessage - cp a,MAX_REVIVE - jr z,.showHealingItemMessage - ld a,POTION_MSG - ld [wPartyMenuTypeOrMessageID],a + ld a, [hFlags_0xFFFA] + res 0, a + ld [hFlags_0xFFFA], a + ld a, REVIVE_MSG + ld [wPartyMenuTypeOrMessageID], a + ld a, [wcf91] + cp a, REVIVE + jr z, .showHealingItemMessage + cp a, MAX_REVIVE + jr z, .showHealingItemMessage + ld a, POTION_MSG + ld [wPartyMenuTypeOrMessageID], a jr .showHealingItemMessage + .playStatusAilmentCuringSound - ld a,SFX_HEAL_AILMENT + ld a, SFX_HEAL_AILMENT call PlaySoundWaitForCurrent .showHealingItemMessage xor a - ld [H_AUTOBGTRANSFERENABLED],a + ld [H_AUTOBGTRANSFERENABLED], a call ClearScreen dec a - ld [wUpdateSpritesEnabled],a + ld [wUpdateSpritesEnabled], a call RedrawPartyMenu ; redraws the party menu and displays the message - ld a,1 - ld [H_AUTOBGTRANSFERENABLED],a - ld c,50 + ld a, 1 + ld [H_AUTOBGTRANSFERENABLED], a + ld c, 50 call DelayFrames call WaitForTextScrollButtonPress jr .done + .canceledItemUse xor a - ld [wActionResultOrTookBattleTurn],a ; item use failed + ld [wActionResultOrTookBattleTurn], a ; item use failed pop af pop af .done - ld a,[wPseudoItemID] + ld a, [wPseudoItemID] and a ; using Softboiled? ret nz ; if so, return call GBPalWhiteOut - call z,RunDefaultPaletteCommand - ld a,[wIsInBattle] + call z, RunDefaultPaletteCommand + ld a, [wIsInBattle] and a ret nz jp ReloadMapData + .useVitamin push hl - ld a,[hl] - ld [wd0b5],a - ld [wd11e],a - ld bc,33 - add hl,bc ; hl now points to level - ld a,[hl] ; a = level - ld [wCurEnemyLVL],a ; store level + ld a, [hl] + ld [wd0b5], a + ld [wd11e], a + ld bc, 33 + add hl, bc ; hl now points to level + ld a, [hl] ; a = level + ld [wCurEnemyLVL], a ; store level call GetMonHeader push de - ld a,d - ld hl,wPartyMonNicks + ld a, d + ld hl, wPartyMonNicks call GetPartyMonName pop de pop hl - ld a,[wcf91] - cp a,RARE_CANDY - jp z,.useRareCandy + ld a, [wcf91] + cp a, RARE_CANDY + jp z, .useRareCandy push hl - sub a,HP_UP + sub a, HP_UP add a - ld bc,17 - add hl,bc + ld bc, 17 + add hl, bc add l - ld l,a - jr nc,.noCarry2 + ld l, a + jr nc, .noCarry2 inc h .noCarry2 - ld a,10 - ld b,a - ld a,[hl] ; a = MSB of stat experience of the appropriate stat - cp a,100 ; is there already at least 25600 (256 * 100) stat experience? - jr nc,.vitaminNoEffect ; if so, vitamins can't add any more + ld a, 10 + ld b, a + ld a, [hl] ; a = MSB of stat experience of the appropriate stat + cp a, 100 ; is there already at least 25600 (256 * 100) stat experience? + jr nc, .vitaminNoEffect ; if so, vitamins can't add any more add b ; add 2560 (256 * 10) stat experience - jr nc,.noCarry3 ; a carry should be impossible here, so this will always jump - ld a,255 + jr nc, .noCarry3 ; a carry should be impossible here, so this will always jump + ld a, 255 .noCarry3 - ld [hl],a + ld [hl], a pop hl call .recalculateStats - ld hl,VitaminText - ld a,[wcf91] - sub a,HP_UP - 1 - ld c,a + ld hl, VitaminText + ld a, [wcf91] + sub a, HP_UP - 1 + ld c, a .statNameLoop ; loop to get the address of the name of the stat the vitamin increases dec c - jr z,.gotStatName + jr z, .gotStatName .statNameInnerLoop - ld a,[hli] - ld b,a - ld a,$50 + ld a, [hli] + ld b, a + ld a, $50 cp b - jr nz,.statNameInnerLoop + jr nz, .statNameInnerLoop jr .statNameLoop + .gotStatName - ld de,wcf4b - ld bc,10 + ld de, wcf4b + ld bc, 10 call CopyData ; copy the stat's name to wcf4b - ld a,SFX_HEAL_AILMENT + ld a, SFX_HEAL_AILMENT call PlaySound - ld hl,VitaminStatRoseText + ld hl, VitaminStatRoseText call PrintText jp RemoveUsedItem + .vitaminNoEffect pop hl - ld hl,VitaminNoEffectText + ld hl, VitaminNoEffectText call PrintText jp GBPalWhiteOut + .recalculateStats - ld bc,34 - add hl,bc - ld d,h - ld e,l ; de now points to stats - ld bc,-18 - add hl,bc ; hl now points to byte 3 of experience - ld b,1 + ld bc, 34 + add hl, bc + ld d, h + ld e, l ; de now points to stats + ld bc, -18 + add hl, bc ; hl now points to byte 3 of experience + ld b, 1 jp CalcStats ; recalculate stats .useRareCandy push hl - ld bc,33 - add hl,bc ; hl now points to level - ld a,[hl] ; a = level + ld bc, 33 + add hl, bc ; hl now points to level + ld a, [hl] ; a = level cp a, MAX_LEVEL - jr z,.vitaminNoEffect ; can't raise level above 100 + jr z, .vitaminNoEffect ; can't raise level above 100 inc a - ld [hl],a ; store incremented level - ld [wCurEnemyLVL],a + ld [hl], a ; store incremented level + ld [wCurEnemyLVL], a push hl push de - ld d,a + ld d, a callab CalcExperience ; calculate experience for next level and store it at $ff96 pop de pop hl - ld bc,-19 - add hl,bc ; hl now points to experience + ld bc, -19 + add hl, bc ; hl now points to experience ; update experience to minimum for new level - ld a,[hExperience] - ld [hli],a - ld a,[hExperience + 1] - ld [hli],a - ld a,[hExperience + 2] - ld [hl],a + ld a, [hExperience] + ld [hli], a + ld a, [hExperience + 1] + ld [hli], a + ld a, [hExperience + 2] + ld [hl], a pop hl - ld a,[wWhichPokemon] + ld a, [wWhichPokemon] push af - ld a,[wcf91] + ld a, [wcf91] push af push de push hl - ld bc,34 - add hl,bc ; hl now points to MSB of max HP - ld a,[hli] - ld b,a - ld c,[hl] + ld bc, 34 + add hl, bc ; hl now points to MSB of max HP + ld a, [hli] + ld b, a + ld c, [hl] pop hl push bc push hl call .recalculateStats pop hl - ld bc,35 ; hl now points to LSB of max HP - add hl,bc + ld bc, 35 ; hl now points to LSB of max HP + add hl, bc pop bc - ld a,[hld] + ld a, [hld] sub c - ld c,a - ld a,[hl] + ld c, a + ld a, [hl] sbc b - ld b,a ; bc = the amount of max HP gained from leveling up + ld b, a ; bc = the amount of max HP gained from leveling up ; add the amount gained to the current HP - ld de,-32 - add hl,de ; hl now points to MSB of current HP - ld a,[hl] + ld de, -32 + add hl, de ; hl now points to MSB of current HP + ld a, [hl] add c - ld [hld],a - ld a,[hl] + ld [hld], a + ld a, [hl] adc b - ld [hl],a - ld a,RARE_CANDY_MSG - ld [wPartyMenuTypeOrMessageID],a + ld [hl], a + ld a, RARE_CANDY_MSG + ld [wPartyMenuTypeOrMessageID], a call RedrawPartyMenu pop de - ld a,d - ld [wWhichPokemon],a - ld a,e - ld [wd11e],a + ld a, d + ld [wWhichPokemon], a + ld a, e + ld [wd11e], a xor a ; PLAYER_PARTY_DATA - ld [wMonDataLocation],a + ld [wMonDataLocation], a call LoadMonData - ld d,$01 + ld d, $01 callab PrintStatsBox ; display new stats text box call WaitForTextScrollButtonPress ; wait for button press xor a ; PLAYER_PARTY_DATA - ld [wMonDataLocation],a + ld [wMonDataLocation], a predef LearnMoveFromLevelUp ; learn level up move, if any xor a - ld [wForceEvolution],a + ld [wForceEvolution], a callabd_ModifyPikachuHappiness PIKAHAPPY_LEVELUP ld a, [wWhichPokemon] push af @@ -1390,15 +1420,15 @@ ItemUseMedicine: ; d8ae (3:58ae) ld [wWhichPokemon], a callab Func_2fd6a ; evolve pokemon, if appropriate pop af - ld [wWhichPokemon],a + ld [wWhichPokemon], a callab TryEvolvingMon - ld a,$01 - ld [wUpdateSpritesEnabled],a + ld a, $01 + ld [wUpdateSpritesEnabled], a pop af - ld [wcf91],a + ld [wcf91], a pop af - ld [wWhichPokemon],a + ld [wWhichPokemon], a jp RemoveUsedItem VitaminStatRoseText: ; dd44 (3:5d44) @@ -1417,50 +1447,50 @@ VitaminText: ; dd4e (3:5d4e) db "SPECIAL@" ItemUseBait: ; dd72 (3:5d72) - ld hl,ThrewBaitText + ld hl, ThrewBaitText call PrintText - ld hl,wEnemyMonCatchRate ; catch rate + ld hl, wEnemyMonCatchRate ; catch rate srl [hl] ; halve catch rate - ld a,BAIT_ANIM - ld hl,wSafariBaitFactor ; bait factor - ld de,wSafariEscapeFactor ; escape factor + ld a, BAIT_ANIM + ld hl, wSafariBaitFactor ; bait factor + ld de, wSafariEscapeFactor ; escape factor jr BaitRockCommon ItemUseRock: ; dd87 (3:5d87) - ld hl,ThrewRockText + ld hl, ThrewRockText call PrintText - ld hl,wEnemyMonCatchRate ; catch rate - ld a,[hl] + ld hl, wEnemyMonCatchRate ; catch rate + ld a, [hl] add a ; double catch rate - jr nc,.noCarry - ld a,$ff + jr nc, .noCarry + ld a, $ff .noCarry - ld [hl],a - ld a,ROCK_ANIM - ld hl,wSafariEscapeFactor ; escape factor - ld de,wSafariBaitFactor ; bait factor + ld [hl], a + ld a, ROCK_ANIM + ld hl, wSafariEscapeFactor ; escape factor + ld de, wSafariBaitFactor ; bait factor BaitRockCommon: ; dd9f (3:5d9f) - ld [wAnimationID],a + ld [wAnimationID], a xor a - ld [wAnimationType],a - ld [H_WHOSETURN],a - ld [de],a ; zero escape factor (for bait), zero bait factor (for rock) + ld [wAnimationType], a + ld [H_WHOSETURN], a + ld [de], a ; zero escape factor (for bait), zero bait factor (for rock) .randomLoop ; loop until a random number less than 5 is generated call Random - and a,7 - cp a,5 - jr nc,.randomLoop + and a, 7 + cp a, 5 + jr nc, .randomLoop inc a ; increment the random number, giving a range from 1 to 5 inclusive - ld b,a - ld a,[hl] + ld b, a + ld a, [hl] add b ; increase bait factor (for bait), increase escape factor (for rock) - jr nc,.noCarry - ld a,$ff + jr nc, .noCarry + ld a, $ff .noCarry - ld [hl],a + ld [hl], a predef MoveAnimation ; do animation - ld c,70 + ld c, 70 jp DelayFrames ThrewBaitText: ; ddc6 (3:5dc6) @@ -1473,46 +1503,47 @@ ThrewRockText: ; ddca (3:5dca) ; also used for Dig out-of-battle effect ItemUseEscapeRope: ; ddcf (3:5dcf) - ld a,[wIsInBattle] + ld a, [wIsInBattle] and a - jr nz,.notUsable - ld a,[wCurMap] - cp a,AGATHAS_ROOM - jr z,.notUsable - cp a,BILLS_HOUSE - jr z,.notUsable - cp a,POKEMON_FAN_CLUB - jr z,.notUsable - ld a,[wCurMapTileset] - ld b,a - ld hl,EscapeRopeTilesets + jr nz, .notUsable + ld a, [wCurMap] + cp a, AGATHAS_ROOM + jr z, .notUsable + cp a, BILLS_HOUSE + jr z, .notUsable + cp a, POKEMON_FAN_CLUB + jr z, .notUsable + ld a, [wCurMapTileset] + ld b, a + ld hl, EscapeRopeTilesets .loop - ld a,[hli] - cp a,$ff - jr z,.notUsable + ld a, [hli] + cp a, $ff + jr z, .notUsable cp b - jr nz,.loop - ld hl,wd732 - set 3,[hl] - set 6,[hl] + jr nz, .loop + ld hl, wd732 + set 3, [hl] + set 6, [hl] call Func_1510 - ld hl,wd72e - res 4,[hl] - ld hl,wd790 - res 7,[hl] + ld hl, wd72e + res 4, [hl] + ld hl, wd790 + res 7, [hl] xor a - ld [wNumSafariBalls],a - ld [wSafariZoneEntranceCurScript],a + ld [wNumSafariBalls], a + ld [wSafariZoneEntranceCurScript], a inc a - ld [wEscapedFromBattle],a - ld [wActionResultOrTookBattleTurn],a ; item used - ld a,[wPseudoItemID] + ld [wEscapedFromBattle], a + ld [wActionResultOrTookBattleTurn], a ; item used + ld a, [wPseudoItemID] and a ; using Dig? ret nz ; if so, return call ItemUseReloadOverworldData - ld c,30 + ld c, 30 call DelayFrames jp RemoveUsedItem + .notUsable jp ItemUseNotTime @@ -1521,23 +1552,23 @@ EscapeRopeTilesets: ; de28 (3:5e28) db $ff ; terminator ItemUseRepel: ; de2e (3:5e2e) - ld b,100 + ld b, 100 ItemUseRepelCommon: ; e005 (3:6005) - ld a,[wIsInBattle] + ld a, [wIsInBattle] and a - jp nz,ItemUseNotTime - ld a,b - ld [wRepelRemainingSteps],a + jp nz, ItemUseNotTime + ld a, b + ld [wRepelRemainingSteps], a jp PrintItemUseTextAndRemoveItem ; handles X Accuracy item ItemUseXAccuracy: ; de3e (3:5e3e) - ld a,[wIsInBattle] + ld a, [wIsInBattle] and a - jp z,ItemUseNotTime - ld hl,wPlayerBattleStatus2 - set UsingXAccuracy,[hl] ; X Accuracy bit + jp z, ItemUseNotTime + ld hl, wPlayerBattleStatus2 + set UsingXAccuracy, [hl] ; X Accuracy bit callabd_ModifyPikachuHappiness PIKAHAPPY_USEDXITEM jp PrintItemUseTextAndRemoveItem @@ -1545,40 +1576,43 @@ ItemUseXAccuracy: ; de3e (3:5e3e) ; The Card Key is handled in a different way. ItemUseCardKey: ; de57 (3:de57) xor a - ld [wUnusedD71F],a + ld [wUnusedD71F], a call GetTileAndCoordsInFrontOfPlayer - ld a,[GetTileAndCoordsInFrontOfPlayer] ; $4586 - cp a,$18 - jr nz,.next0 - ld hl,CardKeyTable1 + ld a, [GetTileAndCoordsInFrontOfPlayer] ; $4586 + cp a, $18 + jr nz, .next0 + ld hl, CardKeyTable1 jr .next1 + .next0 - cp a,$24 - jr nz,.next2 - ld hl,CardKeyTable2 + cp a, $24 + jr nz, .next2 + ld hl, CardKeyTable2 jr .next1 + .next2 - cp a,$5e - jp nz,ItemUseNotTime - ld hl,CardKeyTable3 + cp a, $5e + jp nz, ItemUseNotTime + ld hl, CardKeyTable3 .next1 - ld a,[wCurMap] - ld b,a + ld a, [wCurMap] + ld b, a .loop - ld a,[hli] - cp a,$ff - jp z,ItemUseNotTime + ld a, [hli] + cp a, $ff + jp z, ItemUseNotTime cp b - jr nz,.nextEntry1 - ld a,[hli] + jr nz, .nextEntry1 + ld a, [hli] cp d - jr nz,.nextEntry2 - ld a,[hli] + jr nz, .nextEntry2 + ld a, [hli] cp e - jr nz,.nextEntry3 - ld a,[hl] - ld [wUnusedD71F],a + jr nz, .nextEntry3 + ld a, [hl] + ld [wUnusedD71F], a jr .done + .nextEntry1 inc hl .nextEntry2 @@ -1586,14 +1620,15 @@ ItemUseCardKey: ; de57 (3:de57) .nextEntry3 inc hl jr .loop + .done - ld hl,ItemUseText00 + ld hl, ItemUseText00 call PrintText - ld hl,wd728 - set 7,[hl] + ld hl, wd728 + set 7, [hl] ret -; These tables are probably supposed to be door locations in Silph Co., +; These tables are probably supposed to be door locations in Silph Co., ; but they are unused. ; The reason there are 3 tables is unknown. @@ -1604,48 +1639,48 @@ ItemUseCardKey: ; de57 (3:de57) ; 03: ID? CardKeyTable1: ; dea7 (3:5ea7) - db SILPH_CO_2F,$04,$04,$00 - db SILPH_CO_2F,$04,$05,$01 - db SILPH_CO_4F,$0C,$04,$02 - db SILPH_CO_4F,$0C,$05,$03 - db SILPH_CO_7F,$06,$0A,$04 - db SILPH_CO_7F,$06,$0B,$05 - db SILPH_CO_9F,$04,$12,$06 - db SILPH_CO_9F,$04,$13,$07 - db SILPH_CO_10F,$08,$0A,$08 - db SILPH_CO_10F,$08,$0B,$09 + db SILPH_CO_2F, $04, $04, $00 + db SILPH_CO_2F, $04, $05, $01 + db SILPH_CO_4F, $0C, $04, $02 + db SILPH_CO_4F, $0C, $05, $03 + db SILPH_CO_7F, $06, $0A, $04 + db SILPH_CO_7F, $06, $0B, $05 + db SILPH_CO_9F, $04, $12, $06 + db SILPH_CO_9F, $04, $13, $07 + db SILPH_CO_10F, $08, $0A, $08 + db SILPH_CO_10F, $08, $0B, $09 db $ff CardKeyTable2: ; ded0 (3:5ed0) - db SILPH_CO_3F,$08,$09,$0A - db SILPH_CO_3F,$09,$09,$0B - db SILPH_CO_5F,$04,$07,$0C - db SILPH_CO_5F,$05,$07,$0D - db SILPH_CO_6F,$0C,$05,$0E - db SILPH_CO_6F,$0D,$05,$0F - db SILPH_CO_8F,$08,$07,$10 - db SILPH_CO_8F,$09,$07,$11 - db SILPH_CO_9F,$08,$03,$12 - db SILPH_CO_9F,$09,$03,$13 + db SILPH_CO_3F, $08, $09, $0A + db SILPH_CO_3F, $09, $09, $0B + db SILPH_CO_5F, $04, $07, $0C + db SILPH_CO_5F, $05, $07, $0D + db SILPH_CO_6F, $0C, $05, $0E + db SILPH_CO_6F, $0D, $05, $0F + db SILPH_CO_8F, $08, $07, $10 + db SILPH_CO_8F, $09, $07, $11 + db SILPH_CO_9F, $08, $03, $12 + db SILPH_CO_9F, $09, $03, $13 db $ff CardKeyTable3: ; def9 (3:5ef9) - db SILPH_CO_11F,$08,$09,$14 - db SILPH_CO_11F,$09,$09,$15 + db SILPH_CO_11F, $08, $09, $14 + db SILPH_CO_11F, $09, $09, $15 db $ff ItemUsePokedoll: ; df02 (3:5f02) - ld a,[wIsInBattle] + ld a, [wIsInBattle] dec a - jp nz,ItemUseNotTime - ld a,$01 - ld [wEscapedFromBattle],a + jp nz, ItemUseNotTime + ld a, $01 + ld [wEscapedFromBattle], a jp PrintItemUseTextAndRemoveItem ItemUseGuardSpec: ; df11 (3:5f11) - ld a,[wIsInBattle] + ld a, [wIsInBattle] and a - jp z,ItemUseNotTime + jp z, ItemUseNotTime ld a, [wWhichPokemon] push af @@ -1655,22 +1690,22 @@ ItemUseGuardSpec: ; df11 (3:5f11) pop af ld [wWhichPokemon], a - ld hl,wPlayerBattleStatus2 - set ProtectedByMist,[hl] ; Mist bit + ld hl, wPlayerBattleStatus2 + set ProtectedByMist, [hl] ; Mist bit jp PrintItemUseTextAndRemoveItem ItemUseSuperRepel: ; df38 (3:5f38) - ld b,200 + ld b, 200 jp ItemUseRepelCommon ItemUseMaxRepel: ; df3d (3:5f3d) - ld b,250 + ld b, 250 jp ItemUseRepelCommon ItemUseDireHit: ; df42 (3:5f42) - ld a,[wIsInBattle] + ld a, [wIsInBattle] and a - jp z,ItemUseNotTime + jp z, ItemUseNotTime ld a, [wWhichPokemon] push af @@ -1680,35 +1715,36 @@ ItemUseDireHit: ; df42 (3:5f42) pop af ld [wWhichPokemon], a - ld hl,wPlayerBattleStatus2 - set GettingPumped,[hl] ; Focus Energy bit + ld hl, wPlayerBattleStatus2 + set GettingPumped, [hl] ; Focus Energy bit jp PrintItemUseTextAndRemoveItem ItemUseXStat: ; df69 (3:df69) - ld a,[wIsInBattle] + ld a, [wIsInBattle] and a - jr nz,.inBattle + jr nz, .inBattle call ItemUseNotTime - ld a,2 - ld [wActionResultOrTookBattleTurn],a ; item not used + ld a, 2 + ld [wActionResultOrTookBattleTurn], a ; item not used ret + .inBattle - ld hl,wPlayerMoveNum - ld a,[hli] + ld hl, wPlayerMoveNum + ld a, [hli] push af ; save [wPlayerMoveNum] - ld a,[hl] + ld a, [hl] push af ; save [wPlayerMoveEffect] push hl - ld a,[wcf91] - sub a,X_ATTACK - ATTACK_UP1_EFFECT - ld [hl],a ; store player move effect + ld a, [wcf91] + sub a, X_ATTACK - ATTACK_UP1_EFFECT + ld [hl], a ; store player move effect call PrintItemUseTextAndRemoveItem - ld a,XSTATITEM_ANIM ; X stat item animation ID - ld [wPlayerMoveNum],a + ld a, XSTATITEM_ANIM ; X stat item animation ID + ld [wPlayerMoveNum], a call LoadScreenTilesFromBuffer1 ; restore saved screen call Delay3 xor a - ld [H_WHOSETURN],a ; set turn to player's turn + ld [H_WHOSETURN], a ; set turn to player's turn callba StatModifierUpEffect ; do stat increase move ld a, [wWhichPokemon] @@ -1721,110 +1757,114 @@ ItemUseXStat: ; df69 (3:df69) pop hl pop af - ld [hld],a ; restore [wPlayerMoveEffect] + ld [hld], a ; restore [wPlayerMoveEffect] pop af - ld [hl],a ; restore [wPlayerMoveNum] + ld [hl], a ; restore [wPlayerMoveNum] ret ItemUsePokeflute: ; dfbd (3:5fbd) - ld a,[wIsInBattle] + ld a, [wIsInBattle] and a - jr nz,.inBattle + jr nz, .inBattle ; if not in battle call ItemUseReloadOverworldData - ld a,[wCurMap] - cp a,ROUTE_12 - jr nz,.notRoute12 + ld a, [wCurMap] + cp a, ROUTE_12 + jr nz, .notRoute12 ld a, [wd7d8] bit 7, a - jr nz,.noSnorlaxOrPikachuToWakeUp + jr nz, .noSnorlaxOrPikachuToWakeUp ; if the player hasn't beaten Route 12 Snorlax - ld hl,Route12SnorlaxFluteCoords + ld hl, Route12SnorlaxFluteCoords call ArePlayerCoordsInArray - jr nc,.noSnorlaxOrPikachuToWakeUp - ld hl,PlayedFluteHadEffectText + jr nc, .noSnorlaxOrPikachuToWakeUp + ld hl, PlayedFluteHadEffectText call PrintText ld hl, wd7d8 set 6, [hl] ret + .notRoute12 - cp a,ROUTE_16 - jr nz,.notRoute16 + cp a, ROUTE_16 + jr nz, .notRoute16 ld a, [wd7e0] bit 1, a - jr nz,.noSnorlaxOrPikachuToWakeUp + jr nz, .noSnorlaxOrPikachuToWakeUp ; if the player hasn't beaten Route 16 Snorlax - ld hl,Route16SnorlaxFluteCoords + ld hl, Route16SnorlaxFluteCoords call ArePlayerCoordsInArray - jr nc,.noSnorlaxOrPikachuToWakeUp - ld hl,PlayedFluteHadEffectText + jr nc, .noSnorlaxOrPikachuToWakeUp + ld hl, PlayedFluteHadEffectText call PrintText ld hl, wd7e0 set 0, [hl] ret + .notRoute16 - cp a,PEWTER_POKECENTER - jr nz,.noSnorlaxOrPikachuToWakeUp + cp a, PEWTER_POKECENTER + jr nz, .noSnorlaxOrPikachuToWakeUp call CheckPikachuFollowingPlayer - jr z,.noSnorlaxOrPikachuToWakeUp - callab Func_fcb01 - jr nc,.noSnorlaxOrPikachuToWakeUp + jr z, .noSnorlaxOrPikachuToWakeUp + callab IsPikachuRightNextToPlayer + jr nc, .noSnorlaxOrPikachuToWakeUp ld hl, PlayedFluteHadEffectText call PrintText call ItemUseReloadOverworldData ld e, $1a callab Func_fd001 ret + .noSnorlaxOrPikachuToWakeUp - ld hl,PlayedFluteNoEffectText + ld hl, PlayedFluteNoEffectText jp PrintText + .inBattle xor a - ld [wWereAnyMonsAsleep],a - ld b,~SLP & $ff - ld hl,wPartyMon1Status + ld [wWereAnyMonsAsleep], a + ld b, $ff ^ SLP + ld hl, wPartyMon1Status call WakeUpEntireParty - ld a,[wIsInBattle] + ld a, [wIsInBattle] dec a ; is it a trainer battle? - jr z,.skipWakingUpEnemyParty + jr z, .skipWakingUpEnemyParty ; if it's a trainer battle - ld hl,wEnemyMon1Status + ld hl, wEnemyMon1Status call WakeUpEntireParty .skipWakingUpEnemyParty - ld hl,wBattleMonStatus - ld a,[hl] + ld hl, wBattleMonStatus + ld a, [hl] and b ; remove Sleep status - ld [hl],a - ld hl,wEnemyMonStatus - ld a,[hl] - ld c,a + ld [hl], a + ld hl, wEnemyMonStatus + ld a, [hl] + ld c, a and b ; remove Sleep status - ld [hl],a - ld a,c - and a,SLP - jr z,.asm_e063 - ld a,$1 - ld [wWereAnyMonsAsleep],a + ld [hl], a + ld a, c + and a, SLP + jr z, .asm_e063 + ld a, $1 + ld [wWereAnyMonsAsleep], a .asm_e063 call LoadScreenTilesFromBuffer2 ; restore saved screen - ld a,[wWereAnyMonsAsleep] + ld a, [wWereAnyMonsAsleep] and a ; were any pokemon asleep before playing the flute? - ld hl,PlayedFluteNoEffectText - jp z,PrintText ; if no pokemon were asleep + ld hl, PlayedFluteNoEffectText + jp z, PrintText ; if no pokemon were asleep ; if some pokemon were asleep - ld hl,PlayedFluteHadEffectText + ld hl, PlayedFluteHadEffectText call PrintText - ld a,[wLowHealthAlarm] - and a,$80 - jr nz,.skipMusic + ld a, [wLowHealthAlarm] + and a, $80 + jr nz, .skipMusic call WaitForSoundToFinish ; wait for sound to end callba Music_PokeFluteInBattle ; play in-battle pokeflute music .musicWaitLoop ; wait for music to finish playing - ld a,[wChannelSoundIDs + CH6] + ld a, [wChannelSoundIDs + CH6] and a ; music off? - jr nz,.musicWaitLoop + jr nz, .musicWaitLoop .skipMusic - ld hl,FluteWokeUpText + ld hl, FluteWokeUpText jp PrintText ; wakes up all party pokemon @@ -1835,40 +1875,40 @@ ItemUsePokeflute: ; dfbd (3:5fbd) ; OUTPUT: ; [wWereAnyMonsAsleep]: set to 1 if any pokemon were asleep WakeUpEntireParty: ; e094 (3:6094) - ld de,44 - ld c,6 + ld de, 44 + ld c, 6 .loop - ld a,[hl] + ld a, [hl] push af - and a,SLP ; is pokemon asleep? - jr z,.notAsleep - ld a,1 - ld [wWereAnyMonsAsleep],a ; indicate that a pokemon had to be woken up + and a, SLP ; is pokemon asleep? + jr z, .notAsleep + ld a, 1 + ld [wWereAnyMonsAsleep], a ; indicate that a pokemon had to be woken up .notAsleep pop af and b ; remove Sleep status - ld [hl],a - add hl,de + ld [hl], a + add hl, de dec c - jr nz,.loop + jr nz, .loop ret ; Format: ; 00: Y ; 01: X Route12SnorlaxFluteCoords: ; e0ac (3:60ac) - db 62,9 ; one space West of Snorlax - db 61,10 ; one space North of Snorlax - db 63,10 ; one space South of Snorlax - db 62,11 ; one space East of Snorlax + db 62, 9 ; one space West of Snorlax + db 61, 10 ; one space North of Snorlax + db 63, 10 ; one space South of Snorlax + db 62, 11 ; one space East of Snorlax db $ff ; terminator ; Format: ; 00: Y ; 01: X Route16SnorlaxFluteCoords: ; e0b5 (3:60b5) - db 10,27 ; one space East of Snorlax - db 10,25 ; one space West of Snorlax + db 10, 27 ; one space East of Snorlax + db 10, 25 ; one space West of Snorlax db $ff ; terminator PlayedFluteNoEffectText: ; e0ba (3:60ba) @@ -1883,27 +1923,27 @@ PlayedFluteHadEffectText: ; e0c4 (3:60c4) TX_FAR _PlayedFluteHadEffectText db $06 TX_ASM - ld a,[wIsInBattle] + ld a, [wIsInBattle] and a - jr nz,.done + jr nz, .done ; play out-of-battle pokeflute music call StopAllMusic ; turn off music ld a, SFX_POKEFLUTE ld c, BANK(SFX_Pokeflute) call PlayMusic .musicWaitLoop ; wait for music to finish playing - ld a,[wChannelSoundIDs + CH2] + ld a, [wChannelSoundIDs + CH2] cp a, SFX_POKEFLUTE - jr z,.musicWaitLoop + jr z, .musicWaitLoop call PlayDefaultMusic ; start playing normal music again .done jp TextScriptEnd ; end text ItemUseCoinCase: ; e0e7 (3:60e7) - ld a,[wIsInBattle] + ld a, [wIsInBattle] and a - jp nz,ItemUseNotTime - ld hl,CoinCaseNumCoinsText + jp nz, ItemUseNotTime + ld hl, CoinCaseNumCoinsText jp PrintText CoinCaseNumCoinsText: ; e0f1 (3:60f1) @@ -1919,7 +1959,7 @@ ItemUseOldRod: ; e0f9 (3:60f9) ItemUseGoodRod: ; e106 (3:6106) call FishingInit - jp c,ItemUseNotTime + jp c, ItemUseNotTime .RandomLoop call Random srl a @@ -1928,17 +1968,17 @@ ItemUseGoodRod: ; e106 (3:6106) cp 2 jr nc, .RandomLoop ; choose which monster appears - ld hl,GoodRodMons + ld hl, GoodRodMons add a - ld c,a - ld b,0 - add hl,bc - ld b,[hl] + ld c, a + ld b, 0 + add hl, bc + ld b, [hl] inc hl - ld c,[hl] + ld c, [hl] and a .SetBite - ld a,0 + ld a, 0 rla xor 1 jr RodResponse @@ -1964,6 +2004,7 @@ ItemUseSuperRod: ; e130 (3:6130) xor a ld [wRodResponse], a jr DoNotGenerateFishingEncounter + RodResponse: ; e15b (3:615b) ld [wRodResponse], a @@ -1993,30 +2034,32 @@ DoNotGenerateFishingEncounter: ; e16e (3:616e) ; checks if fishing is possible and if so, runs initialization code common to all rods ; unsets carry if fishing is possible, sets carry if not FishingInit: ; e182 (3:6182) - ld a,[wIsInBattle] + ld a, [wIsInBattle] and a - jr z,.notInBattle + jr z, .notInBattle scf ; can't fish during battle ret + .notInBattle call IsNextTileShoreOrWater - jr nc,.cannotFish - ld a,[wWalkBikeSurfState] - cp a,2 ; Surfing? - jr z,.cannotFish + jr nc, .cannotFish + ld a, [wWalkBikeSurfState] + cp a, 2 ; Surfing? + jr z, .cannotFish call ItemUseReloadOverworldData - ld hl,ItemUseText00 + ld hl, ItemUseText00 call PrintText - ld a,SFX_HEAL_AILMENT + ld a, SFX_HEAL_AILMENT call PlaySound ld a, $2 ld [wd49c], a ld a, $81 ld [wPikachuMood], a - ld c,80 + ld c, 80 call DelayFrames and a ret + .cannotFish scf ; can't fish when surfing ret @@ -2025,22 +2068,22 @@ ItemUseOaksParcel: ; e1b7 (3:61b7) jp ItemUseNotYoursToUse ItemUseItemfinder: ; e1ba (3:61ba) - ld a,[wIsInBattle] + ld a, [wIsInBattle] and a - jp nz,ItemUseNotTime + jp nz, ItemUseNotTime call ItemUseReloadOverworldData callba HiddenItemNear ; check for hidden items - ld hl,ItemfinderFoundNothingText - jr nc,.printText ; if no hidden items - ld c,4 + ld hl, ItemfinderFoundNothingText + jr nc, .printText ; if no hidden items + ld c, 4 .loop - ld a,SFX_HEALING_MACHINE + ld a, SFX_HEALING_MACHINE call PlaySoundWaitForCurrent - ld a,SFX_PURCHASE + ld a, SFX_PURCHASE call PlaySoundWaitForCurrent dec c - jr nz,.loop - ld hl,ItemfinderFoundItemText + jr nz, .loop + ld hl, ItemfinderFoundItemText .printText jp PrintText @@ -2053,23 +2096,24 @@ ItemfinderFoundNothingText: ; e1eb (3:61eb) db "@" ItemUsePPUp: ; e1f0 (3:61f0) - ld a,[wIsInBattle] + ld a, [wIsInBattle] and a - jp nz,ItemUseNotTime + jp nz, ItemUseNotTime ItemUsePPRestore: ; e1f7 (3:61f7) - ld a,[wWhichPokemon] + ld a, [wWhichPokemon] push af - ld a,[wcf91] - ld [wPPRestoreItem],a + ld a, [wcf91] + ld [wPPRestoreItem], a .chooseMon xor a - ld [wUpdateSpritesEnabled],a - ld a,USE_ITEM_PARTY_MENU - ld [wPartyMenuTypeOrMessageID],a + ld [wUpdateSpritesEnabled], a + ld a, USE_ITEM_PARTY_MENU + ld [wPartyMenuTypeOrMessageID], a call DisplayPartyMenu - jr nc,.chooseMove + jr nc, .chooseMove jp .itemNotUsed + .chooseMove ld a, [wIsInBattle] and a @@ -2084,121 +2128,127 @@ ItemUsePPRestore: ; e1f7 (3:61f7) jr z, .usePPItem call ItemUseNotTime jp .itemNotUsed + .usePPItem - ld a,[wPPRestoreItem] - cp a,ELIXER - jp nc,.useElixir ; if Elixir or Max Elixir - ld a,$02 - ld [wMoveMenuType],a - ld hl,RaisePPWhichTechniqueText - ld a,[wPPRestoreItem] - cp a,ETHER ; is it a PP Up? - jr c,.printWhichTechniqueMessage ; if so, print the raise PP message - ld hl,RestorePPWhichTechniqueText ; otherwise, print the restore PP message + ld a, [wPPRestoreItem] + cp a, ELIXER + jp nc, .useElixir ; if Elixir or Max Elixir + ld a, $02 + ld [wMoveMenuType], a + ld hl, RaisePPWhichTechniqueText + ld a, [wPPRestoreItem] + cp a, ETHER ; is it a PP Up? + jr c, .printWhichTechniqueMessage ; if so, print the raise PP message + ld hl, RestorePPWhichTechniqueText ; otherwise, print the restore PP message .printWhichTechniqueMessage call PrintText xor a - ld [wPlayerMoveListIndex],a + ld [wPlayerMoveListIndex], a callab MoveSelectionMenu ; move selection menu - ld a,0 - ld [wPlayerMoveListIndex],a - jr nz,.chooseMon - ld hl,wPartyMon1Moves + ld a, 0 + ld [wPlayerMoveListIndex], a + jr nz, .chooseMon + ld hl, wPartyMon1Moves ld bc, wPartyMon2 - wPartyMon1 call GetSelectedMoveOffset push hl - ld a,[hl] - ld [wd11e],a + ld a, [hl] + ld [wd11e], a call GetMoveName call CopyStringToCF4B ; copy name to wcf4b pop hl - ld a,[wPPRestoreItem] - cp a,ETHER - jr nc,.useEther ; if Ether or Max Ether + ld a, [wPPRestoreItem] + cp a, ETHER + jr nc, .useEther ; if Ether or Max Ether .usePPUp - ld bc,21 - add hl,bc - ld a,[hl] ; move PP - cp a,3 << 6 ; have 3 PP Ups already been used? - jr c,.PPNotMaxedOut - ld hl,PPMaxedOutText + ld bc, 21 + add hl, bc + ld a, [hl] ; move PP + cp a, 3 << 6 ; have 3 PP Ups already been used? + jr c, .PPNotMaxedOut + ld hl, PPMaxedOutText call PrintText jr .chooseMove + .PPNotMaxedOut - ld a,[hl] - add a,1 << 6 ; increase PP Up count by 1 - ld [hl],a - ld a,1 ; 1 PP Up used - ld [wd11e],a + ld a, [hl] + add a, 1 << 6 ; increase PP Up count by 1 + ld [hl], a + ld a, 1 ; 1 PP Up used + ld [wd11e], a call RestoreBonusPP ; add the bonus PP to current PP ld a, SFX_HEAL_AILMENT call PlaySound - ld hl,PPIncreasedText + ld hl, PPIncreasedText call PrintText .done pop af - ld [wWhichPokemon],a + ld [wWhichPokemon], a call GBPalWhiteOut call RunDefaultPaletteCommand jp RemoveUsedItem + .afterRestoringPP ; after using a (Max) Ether/Elixir - ld a,[wWhichPokemon] - ld b,a - ld a,[wPlayerMonNumber] + ld a, [wWhichPokemon] + ld b, a + ld a, [wPlayerMonNumber] cp b ; is the pokemon whose PP was restored active in battle? - jr nz,.skipUpdatingInBattleData - ld hl,wPartyMon1PP + jr nz, .skipUpdatingInBattleData + ld hl, wPartyMon1PP ld bc, wPartyMon2 - wPartyMon1 call AddNTimes - ld de,wBattleMonPP - ld bc,4 + ld de, wBattleMonPP + ld bc, 4 call CopyData ; copy party data to in-battle data .skipUpdatingInBattleData - ld a,SFX_HEAL_AILMENT + ld a, SFX_HEAL_AILMENT call PlaySound - ld hl,PPRestoredText + ld hl, PPRestoredText call PrintText jr .done + .useEther call .restorePP - jr nz,.afterRestoringPP + jr nz, .afterRestoringPP jp .noEffect + ; unsets zero flag if PP was restored, sets zero flag if not ; however, this is bugged for Max Ethers and Max Elixirs (see below) .restorePP xor a ; PLAYER_PARTY_DATA - ld [wMonDataLocation],a + ld [wMonDataLocation], a call GetMaxPP - ld hl,wPartyMon1Moves + ld hl, wPartyMon1Moves ld bc, wPartyMon2 - wPartyMon1 call GetSelectedMoveOffset ld bc, wPartyMon1PP - wPartyMon1Moves - add hl,bc ; hl now points to move's PP - ld a,[wMaxPP] - ld b,a - ld a,[wPPRestoreItem] - cp a,MAX_ETHER - jr z,.fullyRestorePP - ld a,[hl] ; move PP - and a,%00111111 ; lower 6 bit bits store current PP + add hl, bc ; hl now points to move's PP + ld a, [wMaxPP] + ld b, a + ld a, [wPPRestoreItem] + cp a, MAX_ETHER + jr z, .fullyRestorePP + ld a, [hl] ; move PP + and a, %00111111 ; lower 6 bit bits store current PP cp b ; does current PP equal max PP? ret z ; if so, return - add a,10 ; increase current PP by 10 + add a, 10 ; increase current PP by 10 ; b holds the max PP amount and b will hold the new PP amount. -; So, if the new amount meets or exceeds the max amount, +; So, if the new amount meets or exceeds the max amount, ; cap the amount to the max amount by leaving b unchanged. ; Otherwise, store the new amount in b. cp b ; does the new amount meet or exceed the maximum? - jr nc,.storeNewAmount - ld b,a + jr nc, .storeNewAmount + ld b, a .storeNewAmount - ld a,[hl] ; move PP - and a,%11000000 ; PP Up counter bits + ld a, [hl] ; move PP + and a, %11000000 ; PP Up counter bits add b - ld [hl],a + ld [hl], a ret + .fullyRestorePP - ld a,[hl] ; move PP + ld a, [hl] ; move PP ; Note that this code has a bug. It doesn't mask out the upper two bits, which ; are used to count how many PP Ups have been used on the move. So, Max Ethers ; and Max Elixirs will not be detected as having no effect on a move with full @@ -2206,39 +2256,40 @@ ItemUsePPRestore: ; e1f7 (3:61f7) cp b ; does current PP equal max PP? ret z jr .storeNewAmount + .useElixir ; decrement the item ID so that ELIXER becomes ETHER and MAX_ELIXER becomes MAX_ETHER - ld hl,wPPRestoreItem + ld hl, wPPRestoreItem dec [hl] dec [hl] xor a - ld hl,wCurrentMenuItem - ld [hli],a - ld [hl],a ; zero the counter for number of moves that had their PP restored - ld b,4 + ld hl, wCurrentMenuItem + ld [hli], a + ld [hl], a ; zero the counter for number of moves that had their PP restored + ld b, 4 ; loop through each move and restore PP .elixirLoop push bc - ld hl,wPartyMon1Moves + ld hl, wPartyMon1Moves ld bc, wPartyMon2 - wPartyMon1 call GetSelectedMoveOffset - ld a,[hl] + ld a, [hl] and a ; does the current slot have a move? - jr z,.nextMove + jr z, .nextMove call .restorePP - jr z,.nextMove + jr z, .nextMove ; if some PP was restored - ld hl,wTileBehindCursor ; counter for number of moves that had their PP restored + ld hl, wTileBehindCursor ; counter for number of moves that had their PP restored inc [hl] .nextMove - ld hl,wCurrentMenuItem + ld hl, wCurrentMenuItem inc [hl] pop bc dec b - jr nz,.elixirLoop - ld a,[wTileBehindCursor] + jr nz, .elixirLoop + ld a, [wTileBehindCursor] and a ; did any moves have their PP restored? - jp nz,.afterRestoringPP + jp nz, .afterRestoringPP .noEffect call ItemUseNoEffect .itemNotUsed @@ -2246,7 +2297,7 @@ ItemUsePPRestore: ; e1f7 (3:61f7) call RunDefaultPaletteCommand pop af xor a - ld [wActionResultOrTookBattleTurn],a ; item use failed + ld [wActionResultOrTookBattleTurn], a ; item use failed ret RaisePPWhichTechniqueText: ; e358 (3:6358) @@ -2274,63 +2325,64 @@ UnusableItem: ; e371 (3:6371) jp ItemUseNotTime ItemUseTMHM: ; e374 (3:6374) - ld a,[wIsInBattle] + ld a, [wIsInBattle] and a - jp nz,ItemUseNotTime - ld a,[wcf91] - sub a,TM_01 + jp nz, ItemUseNotTime + ld a, [wcf91] + sub a, TM_01 push af - jr nc,.skipAdding - add a,55 ; if item is an HM, add 55 + jr nc, .skipAdding + add a, 55 ; if item is an HM, add 55 .skipAdding inc a - ld [wd11e],a + ld [wd11e], a predef TMToMove ; get move ID from TM/HM ID - ld a,[wd11e] - ld [wMoveNum],a + ld a, [wd11e] + ld [wMoveNum], a call GetMoveName call CopyStringToCF4B ; copy name to wcf4b pop af - ld hl,BootedUpTMText - jr nc,.printBootedUpMachineText - ld hl,BootedUpHMText + ld hl, BootedUpTMText + jr nc, .printBootedUpMachineText + ld hl, BootedUpHMText .printBootedUpMachineText call PrintText - ld hl,TeachMachineMoveText + ld hl, TeachMachineMoveText call PrintText coord hl, 14, 7 lb bc, 8, 15 - ld a,TWO_OPTION_MENU - ld [wTextBoxID],a + ld a, TWO_OPTION_MENU + ld [wTextBoxID], a call DisplayTextBoxID ; yes/no menu - ld a,[wCurrentMenuItem] + ld a, [wCurrentMenuItem] and a - jr z,.useMachine - ld a,2 - ld [wActionResultOrTookBattleTurn],a ; item not used + jr z, .useMachine + ld a, 2 + ld [wActionResultOrTookBattleTurn], a ; item not used ret + .useMachine - ld a,[wWhichPokemon] + ld a, [wWhichPokemon] push af - ld a,[wcf91] + ld a, [wcf91] push af .chooseMon - ld hl,wcf4b - ld de,wTempMoveNameBuffer - ld bc,14 + ld hl, wcf4b + ld de, wTempMoveNameBuffer + ld bc, 14 call CopyData ; save the move name because DisplayPartyMenu will overwrite it - ld a,$ff - ld [wUpdateSpritesEnabled],a - ld a,TMHM_PARTY_MENU - ld [wPartyMenuTypeOrMessageID],a + ld a, $ff + ld [wUpdateSpritesEnabled], a + ld a, TMHM_PARTY_MENU + ld [wPartyMenuTypeOrMessageID], a call DisplayPartyMenu push af - ld hl,wTempMoveNameBuffer - ld de,wcf4b - ld bc,14 + ld hl, wTempMoveNameBuffer + ld de, wcf4b + ld bc, 14 call CopyData pop af - jr nc,.checkIfAbleToLearnMove + jr nc, .checkIfAbleToLearnMove ; if the player canceled teaching the move pop af pop af @@ -2341,45 +2393,46 @@ ItemUseTMHM: ; e374 (3:6374) .checkIfAbleToLearnMove predef CanLearnTM ; check if the pokemon can learn the move push bc - ld a,[wWhichPokemon] - ld hl,wPartyMonNicks + ld a, [wWhichPokemon] + ld hl, wPartyMonNicks call GetPartyMonName pop bc - ld a,c + ld a, c and a ; can the pokemon learn the move? - jr nz,.checkIfAlreadyLearnedMove + jr nz, .checkIfAlreadyLearnedMove ; if the pokemon can't learn the move - ld a,SFX_DENIED + ld a, SFX_DENIED call PlaySoundWaitForCurrent - ld hl,MonCannotLearnMachineMoveText + ld hl, MonCannotLearnMachineMoveText call PrintText jr .chooseMon + .checkIfAlreadyLearnedMove callab CheckIfMoveIsKnown ; check if the pokemon already knows the move - jr c,.chooseMon + jr c, .chooseMon predef LearnMove ; teach move ld a, [wWhichPokemon] ld d, a pop af - ld [wcf91],a + ld [wcf91], a pop af - ld [wWhichPokemon],a - ld a,b + ld [wWhichPokemon], a + ld a, b and a ret z - ld a,[wWhichPokemon] + ld a, [wWhichPokemon] push af - ld a,d - ld [wWhichPokemon],a + ld a, d + ld [wWhichPokemon], a callabd_ModifyPikachuHappiness PIKAHAPPY_USEDTMHM callab IsThisPartymonStarterPikachu_Party - jr nc,.notTeachingThunderboltOrThunderToPikachu - ld a,[wcf91] - cp a,TM_24 ; are we teaching thunderbolt to the player pikachu? - jr z,.teachingThunderboltOrThunderToPlayerPikachu - cp a,TM_25 ; are we teaching thunder then? - jr nz,.notTeachingThunderboltOrThunderToPikachu + jr nc, .notTeachingThunderboltOrThunderToPikachu + ld a, [wcf91] + cp a, TM_24 ; are we teaching thunderbolt to the player pikachu? + jr z, .teachingThunderboltOrThunderToPlayerPikachu + cp a, TM_25 ; are we teaching thunder then? + jr nz, .notTeachingThunderboltOrThunderToPikachu .teachingThunderboltOrThunderToPlayerPikachu ld a, $5 ld [wd49c], a @@ -2389,7 +2442,7 @@ ItemUseTMHM: ; e374 (3:6374) pop af ld [wWhichPokemon], a - ld a,[wcf91] + ld a, [wcf91] call IsItemHM ret c jp RemoveUsedItem @@ -2411,28 +2464,28 @@ MonCannotLearnMachineMoveText: ; e492 (3:6492) db "@" PrintItemUseTextAndRemoveItem: ; e497 (3:6497) - ld hl,ItemUseText00 + ld hl, ItemUseText00 call PrintText - ld a,SFX_HEAL_AILMENT + ld a, SFX_HEAL_AILMENT call PlaySound call WaitForTextScrollButtonPress ; wait for button press RemoveUsedItem: ; e4a5 (3:64a5) - ld hl,wNumBagItems - ld a,1 ; one item - ld [wItemQuantity],a + ld hl, wNumBagItems + ld a, 1 ; one item + ld [wItemQuantity], a jp RemoveItemFromInventory ItemUseNoEffect: ; e4b0 (3:64b0) - ld hl,ItemUseNoEffectText + ld hl, ItemUseNoEffectText jr ItemUseFailed ItemUseNotTime: ; e4b5 (3:64b5) - ld hl,ItemUseNotTimeText + ld hl, ItemUseNotTimeText jr ItemUseFailed ItemUseNotYoursToUse: ; e4ba (3:64ba) - ld hl,ItemUseNotYoursToUseText + ld hl, ItemUseNotYoursToUseText jr ItemUseFailed Func_e4bf: ; e4bf (3:64bf) @@ -2440,34 +2493,35 @@ Func_e4bf: ; e4bf (3:64bf) ld [wActionResultOrTookBattleTurn], a ld hl, DontHavePokemonText jp PrintText + ThrowBallAtTrainerMon: ; e4ca (3:64ca) call RunDefaultPaletteCommand call LoadScreenTilesFromBuffer1 ; restore saved screen call Delay3 - ld a,TOSS_ANIM - ld [wAnimationID],a + ld a, TOSS_ANIM + ld [wAnimationID], a predef MoveAnimation ; do animation - ld hl,ThrowBallAtTrainerMonText1 + ld hl, ThrowBallAtTrainerMonText1 call PrintText - ld hl,ThrowBallAtTrainerMonText2 + ld hl, ThrowBallAtTrainerMonText2 call PrintText jr RemoveUsedItem NoCyclingAllowedHere: ; e4eb (3:64eb) - ld hl,NoCyclingAllowedHereText + ld hl, NoCyclingAllowedHereText jr ItemUseFailed BoxFullCannotThrowBall: ; e4f0 (3:64f0) - ld hl,BoxFullCannotThrowBallText + ld hl, BoxFullCannotThrowBallText jr ItemUseFailed SurfingAttemptFailed: ; e4f5 (3:64f5) - ld hl,NoSurfingHereText + ld hl, NoSurfingHereText ItemUseFailed: ; e4f8 (3:64f8) xor a - ld [wActionResultOrTookBattleTurn],a ; item use failed + ld [wActionResultOrTookBattleTurn], a ; item use failed jp PrintText ItemUseNotTimeText: ; e4ff (3:64ff) @@ -2530,37 +2584,37 @@ GotOffBicycleText: ; e540 (3:6540) ; [wWhichPokemon] = index of pokemon in party ; [wCurrentMenuItem] = index of move (when using a PP Up) RestoreBonusPP: ; e54a (3:654a) - ld hl,wPartyMon1Moves + ld hl, wPartyMon1Moves ld bc, wPartyMon2 - wPartyMon1 - ld a,[wWhichPokemon] + ld a, [wWhichPokemon] call AddNTimes push hl - ld de,wNormalMaxPPList - 1 + ld de, wNormalMaxPPList - 1 predef LoadMovePPs ; loads the normal max PP of each of the pokemon's moves to wNormalMaxPPList pop hl ld c, wPartyMon1PP - wPartyMon1Moves - ld b,0 - add hl,bc ; hl now points to move 1 PP - ld de,wNormalMaxPPList - ld b,0 ; initialize move counter to zero + ld b, 0 + add hl, bc ; hl now points to move 1 PP + ld de, wNormalMaxPPList + ld b, 0 ; initialize move counter to zero ; loop through the pokemon's moves .loop inc b - ld a,b - cp a,5 ; reached the end of the pokemon's moves? + ld a, b + cp a, 5 ; reached the end of the pokemon's moves? ret z ; if so, return - ld a,[wUsingPPUp] + ld a, [wUsingPPUp] dec a ; using a PP Up? - jr nz,.skipMenuItemIDCheck + jr nz, .skipMenuItemIDCheck ; if using a PP Up, check if this is the move it's being used on - ld a,[wCurrentMenuItem] + ld a, [wCurrentMenuItem] inc a cp b - jr nz,.nextMove + jr nz, .nextMove .skipMenuItemIDCheck - ld a,[hl] - and a,%11000000 ; have any PP Ups been used? - call nz,AddBonusPP ; if so, add bonus PP + ld a, [hl] + and a, %11000000 ; have any PP Ups been used? + call nz, AddBonusPP ; if so, add bonus PP .nextMove inc hl inc de @@ -2573,38 +2627,38 @@ RestoreBonusPP: ; e54a (3:654a) ; [hl] = move PP AddBonusPP: ; e586 (3:6586) push bc - ld a,[de] ; normal max PP of move - ld [H_DIVIDEND + 3],a + ld a, [de] ; normal max PP of move + ld [H_DIVIDEND + 3], a xor a - ld [H_DIVIDEND],a - ld [H_DIVIDEND + 1],a - ld [H_DIVIDEND + 2],a - ld a,5 - ld [H_DIVISOR],a - ld b,4 + ld [H_DIVIDEND], a + ld [H_DIVIDEND + 1], a + ld [H_DIVIDEND + 2], a + ld a, 5 + ld [H_DIVISOR], a + ld b, 4 call Divide - ld a,[hl] ; move PP - ld b,a + ld a, [hl] ; move PP + ld b, a swap a - and a,%1111 + and a, %1111 srl a srl a - ld c,a ; c = number of PP Ups used + ld c, a ; c = number of PP Ups used .loop - ld a,[H_QUOTIENT + 3] - cp a,8 ; is the amount greater than or equal to 8? - jr c,.addAmount - ld a,7 ; cap the amount at 7 + ld a, [H_QUOTIENT + 3] + cp a, 8 ; is the amount greater than or equal to 8? + jr c, .addAmount + ld a, 7 ; cap the amount at 7 .addAmount add b - ld b,a - ld a,[wUsingPPUp] + ld b, a + ld a, [wUsingPPUp] dec a ; is the player using a PP Up right now? - jr z,.done ; if so, only add the bonus once + jr z, .done ; if so, only add the bonus once dec c - jr nz,.loop + jr nz, .loop .done - ld [hl],b + ld [hl], b pop bc ret @@ -2621,74 +2675,75 @@ AddBonusPP: ; e586 (3:6586) ; OUTPUT: ; [wMaxPP] = max PP GetMaxPP: ; e5bb (3:65bb) - ld a,[wMonDataLocation] + ld a, [wMonDataLocation] and a - ld hl,wPartyMon1Moves - ld bc,wPartyMon2 - wPartyMon1 - jr z,.sourceWithMultipleMon - ld hl,wEnemyMon1Moves + ld hl, wPartyMon1Moves + ld bc, wPartyMon2 - wPartyMon1 + jr z, .sourceWithMultipleMon + ld hl, wEnemyMon1Moves dec a - jr z,.sourceWithMultipleMon - ld hl,wBoxMon1Moves - ld bc,wBoxMon2 - wBoxMon1 + jr z, .sourceWithMultipleMon + ld hl, wBoxMon1Moves + ld bc, wBoxMon2 - wBoxMon1 dec a - jr z,.sourceWithMultipleMon - ld hl,wDayCareMonMoves + jr z, .sourceWithMultipleMon + ld hl, wDayCareMonMoves dec a - jr z,.sourceWithOneMon - ld hl,wBattleMonMoves ; player's in-battle pokemon + jr z, .sourceWithOneMon + ld hl, wBattleMonMoves ; player's in-battle pokemon .sourceWithOneMon call GetSelectedMoveOffset2 jr .next + .sourceWithMultipleMon call GetSelectedMoveOffset .next - ld a,[hl] + ld a, [hl] dec a push hl - ld hl,Moves - ld bc,MoveEnd - Moves + ld hl, Moves + ld bc, MoveEnd - Moves call AddNTimes - ld de,wcd6d - ld a,BANK(Moves) + ld de, wcd6d + ld a, BANK(Moves) call FarCopyData - ld de,wcd6d + 5 ; PP is byte 5 of move data - ld a,[de] - ld b,a ; b = normal max PP + ld de, wcd6d + 5 ; PP is byte 5 of move data + ld a, [de] + ld b, a ; b = normal max PP pop hl push bc - ld bc,wPartyMon1PP - wPartyMon1Moves ; PP offset if not player's in-battle pokemon data - ld a,[wMonDataLocation] - cp a,4 ; player's in-battle pokemon? - jr nz,.addPPOffset - ld bc,wBattleMonPP - wBattleMonMoves ; PP offset if player's in-battle pokemon data + ld bc, wPartyMon1PP - wPartyMon1Moves ; PP offset if not player's in-battle pokemon data + ld a, [wMonDataLocation] + cp a, 4 ; player's in-battle pokemon? + jr nz, .addPPOffset + ld bc, wBattleMonPP - wBattleMonMoves ; PP offset if player's in-battle pokemon data .addPPOffset - add hl,bc - ld a,[hl] ; a = current PP - and a,%11000000 ; get PP Up count + add hl, bc + ld a, [hl] ; a = current PP + and a, %11000000 ; get PP Up count pop bc or b ; place normal max PP in 6 lower bits of a - ld h,d - ld l,e + ld h, d + ld l, e inc hl ; hl = wcd73 - ld [hl],a + ld [hl], a xor a ; add the bonus for the existing PP Up count - ld [wUsingPPUp],a + ld [wUsingPPUp], a call AddBonusPP ; add bonus PP from PP Ups - ld a,[hl] - and a,%00111111 ; mask out the PP Up count - ld [wMaxPP],a ; store max PP + ld a, [hl] + and a, %00111111 ; mask out the PP Up count + ld [wMaxPP], a ; store max PP ret GetSelectedMoveOffset: ; e627 (3:6627) - ld a,[wWhichPokemon] + ld a, [wWhichPokemon] call AddNTimes GetSelectedMoveOffset2: ; e62d (3:662d) - ld a,[wCurrentMenuItem] - ld c,a - ld b,0 - add hl,bc + ld a, [wCurrentMenuItem] + ld c, a + ld b, 0 + add hl, bc ret ; confirms the item toss and then tosses the item @@ -2701,49 +2756,50 @@ GetSelectedMoveOffset2: ; e62d (3:662d) ; clears carry flag if the item is tossed, sets carry flag if not TossItem_: ; e635 (3:6635) push hl - ld a,[wcf91] + ld a, [wcf91] call IsItemHM pop hl - jr c,.tooImportantToToss + jr c, .tooImportantToToss push hl call IsKeyItem_ - ld a,[wIsKeyItem] + ld a, [wIsKeyItem] pop hl and a - jr nz,.tooImportantToToss + jr nz, .tooImportantToToss push hl - ld a,[wcf91] - ld [wd11e],a + ld a, [wcf91] + ld [wd11e], a call GetItemName call CopyStringToCF4B ; copy name to wcf4b - ld hl,IsItOKToTossItemText + ld hl, IsItOKToTossItemText call PrintText coord hl, 14, 7 lb bc, 8, 15 - ld a,TWO_OPTION_MENU - ld [wTextBoxID],a + ld a, TWO_OPTION_MENU + ld [wTextBoxID], a call DisplayTextBoxID ; yes/no menu - ld a,[wMenuExitMethod] - cp a,CHOSE_SECOND_ITEM + ld a, [wMenuExitMethod] + cp a, CHOSE_SECOND_ITEM pop hl scf ret z ; return if the player chose No ; if the player chose Yes push hl - ld a,[wWhichPokemon] + ld a, [wWhichPokemon] call RemoveItemFromInventory - ld a,[wcf91] - ld [wd11e],a + ld a, [wcf91] + ld [wd11e], a call GetItemName call CopyStringToCF4B ; copy name to wcf4b - ld hl,ThrewAwayItemText + ld hl, ThrewAwayItemText call PrintText pop hl and a ret + .tooImportantToToss push hl - ld hl,TooImportantToTossText + ld hl, TooImportantToTossText call PrintText pop hl scf @@ -2769,32 +2825,32 @@ TooImportantToTossText: ; e6a3 (3:66a3) ; 00: item is not key item ; 01: item is key item IsKeyItem_: ; e6a8 (3:66a8) - ld a,$01 - ld [wIsKeyItem],a - ld a,[wcf91] - cp a,HM_01 ; is the item an HM or TM? - jr nc,.checkIfItemIsHM + ld a, $01 + ld [wIsKeyItem], a + ld a, [wcf91] + cp a, HM_01 ; is the item an HM or TM? + jr nc, .checkIfItemIsHM ; if the item is not an HM or TM push af - ld hl,KeyItemBitfield - ld de,wBuffer - ld bc,15 ; only 11 bytes are actually used + ld hl, KeyItemBitfield + ld de, wBuffer + ld bc, 15 ; only 11 bytes are actually used call CopyData pop af dec a - ld c,a - ld hl,wBuffer - ld b,FLAG_TEST + ld c, a + ld hl, wBuffer + ld b, FLAG_TEST predef FlagActionPredef - ld a,c + ld a, c and a ret nz .checkIfItemIsHM - ld a,[wcf91] + ld a, [wcf91] call IsItemHM ret c xor a - ld [wIsKeyItem],a + ld [wIsKeyItem], a ret INCLUDE "data/key_items.asm" @@ -2977,10 +3033,10 @@ SendNewMonToBox: ; e6e8 (3:66e8) IsNextTileShoreOrWater: ; e808 (3:6808) ld a, [wCurMapTileset] ld hl, WaterTilesets - ld de,1 + ld de, 1 call IsInArray ; does the current map allow surfing? ret nc ; if not, return - ld hl,WaterTile + ld hl, WaterTile ld a, [wCurMapTileset] cp SHIP_PORT ; Vermilion Dock tileset jr z, .skipShoreTiles ; if it's the Vermilion Dock tileset @@ -2988,10 +3044,10 @@ IsNextTileShoreOrWater: ; e808 (3:6808) jr z, .skipShoreTiles cp DOJO ; usual eastern shore tile jr z, .skipShoreTiles - ld hl,ShoreTiles + ld hl, ShoreTiles .skipShoreTiles - ld a,[wTileInFrontOfPlayer] - ld de,$1 + ld a, [wTileInFrontOfPlayer] + ld de, $1 call IsInArray ret @@ -3039,6 +3095,7 @@ FindWildLocationsOfMon: ; e848 (3:6848) inc hl inc c jr .loop + .done ld a, $ff ; list terminator ld [de], a |