diff options
Diffstat (limited to 'engine/items/items.asm')
-rwxr-xr-x | engine/items/items.asm | 1235 |
1 files changed, 678 insertions, 557 deletions
diff --git a/engine/items/items.asm b/engine/items/items.asm index 21e6e924..f8873a6e 100755 --- a/engine/items/items.asm +++ b/engine/items/items.asm @@ -1,7 +1,7 @@ -UseItem_: ; d5c7 (3:55c7) +UseItem_: ld a,1 - ld [wcd6a],a - ld a,[wcf91] ;contains item_ID + ld [wActionResultOrTookBattleTurn],a ; initialise to success value + ld a,[wcf91] ;contains item_ID cp a,HM_01 jp nc,ItemUseTMHM ld hl,ItemUsePtrTable @@ -15,7 +15,7 @@ UseItem_: ; d5c7 (3:55c7) ld l,a jp [hl] -ItemUsePtrTable: ; d5e1 (3:55e1) +ItemUsePtrTable: dw ItemUseBall ; MASTER_BALL dw ItemUseBall ; ULTRA_BALL dw ItemUseBall ; GREAT_BALL @@ -70,7 +70,7 @@ ItemUsePtrTable: ; d5e1 (3:55e1) dw ItemUseMedicine ; FULL_HEAL dw ItemUseMedicine ; REVIVE dw ItemUseMedicine ; MAX_REVIVE - dw ItemUseGuardSpec ; GUARD_SPEC_ + dw ItemUseGuardSpec ; GUARD_SPEC dw ItemUseSuperRepel ; SUPER_REPL dw ItemUseMaxRepel ; MAX_REPEL dw ItemUseDireHit ; DIRE_HIT @@ -78,7 +78,7 @@ ItemUsePtrTable: ; d5e1 (3:55e1) dw ItemUseMedicine ; FRESH_WATER dw ItemUseMedicine ; SODA_POP dw ItemUseMedicine ; LEMONADE - dw UnusableItem ; S_S__TICKET + dw UnusableItem ; S_S_TICKET dw UnusableItem ; GOLD_TEETH dw ItemUseXStat ; X_ATTACK dw ItemUseXStat ; X_DEFEND @@ -90,108 +90,154 @@ ItemUsePtrTable: ; d5e1 (3:55e1) dw UnusableItem ; SILPH_SCOPE dw ItemUsePokeflute ; POKE_FLUTE dw UnusableItem ; LIFT_KEY - dw UnusableItem ; EXP__ALL - dw OldRodCode ; OLD_ROD - dw GoodRodCode ; GOOD_ROD - dw SuperRodCode ; SUPER_ROD + dw UnusableItem ; EXP_ALL + dw ItemUseOldRod ; OLD_ROD + dw ItemUseGoodRod ; GOOD_ROD + dw ItemUseSuperRod ; SUPER_ROD dw ItemUsePPUp ; PP_UP (real one) dw ItemUsePPRestore ; ETHER dw ItemUsePPRestore ; MAX_ETHER dw ItemUsePPRestore ; ELIXER dw ItemUsePPRestore ; MAX_ELIXER -ItemUseBall: ; d687 (3:5687) - ld a,[W_ISINBATTLE] +ItemUseBall: + +; Balls can't be used out of battle. + ld a,[wIsInBattle] and a - jp z,ItemUseNotTime ; not in battle + jp z,ItemUseNotTime + +; Balls can't catch trainers' Pokémon. dec a jp nz,ThrowBallAtTrainerMon - ld a,[W_BATTLETYPE] + +; If this is for the old man battle, skip checking if the party & box are full. + ld a,[wBattleType] dec a - jr z,.UseBall - ld a,[wPartyCount] ;is Party full? + jr z,.canUseBall + + ld a,[wPartyCount] ; is party full? cp a,PARTY_LENGTH - jr nz,.UseBall - ld a,[W_NUMINBOX] ;is Box full? + jr nz,.canUseBall + ld a,[wNumInBox] ; is box full? cp a,MONS_PER_BOX jp z,BoxFullCannotThrowBall -.UseBall ;$56a7 -;ok, you can use a ball + +.canUseBall xor a - ld [wd11c],a - ld a,[W_BATTLETYPE] - cp a,2 ;SafariBattle + ld [wCapturedMonSpecies],a + + ld a,[wBattleType] + cp a,BATTLE_TYPE_SAFARI jr nz,.skipSafariZoneCode + .safariZone - ; remove a Safari Ball from inventory - ld hl,W_NUMSAFARIBALLS - dec [hl] -.skipSafariZoneCode ;$56b6 - call GoPAL_SET_CF1C - ld a,$43 - ld [wd11e],a - call LoadScreenTilesFromBuffer1 ;restore screenBuffer from Backup + ld hl,wNumSafariBalls + dec [hl] ; remove a Safari Ball + +.skipSafariZoneCode + call RunDefaultPaletteCommand + + ld a,$43 ; successful capture value + ld [wPokeBallAnimData],a + + call LoadScreenTilesFromBuffer1 ld hl,ItemUseText00 call PrintText + +; If the player is fighting an unidentified ghost, set the value that indicates +; the Pokémon can't be caught and skip the capture calculations. callab IsGhostBattle - ld b,$10 - jp z,.next12 - ld a,[W_BATTLETYPE] + ld b,$10 ; can't be caught value + jp z,.setAnimData + + ld a,[wBattleType] dec a jr nz,.notOldManBattle + .oldManBattle - ld hl,W_GRASSRATE + ld hl,wGrassRate ld de,wPlayerName - ld bc,11 - call CopyData ; save the player's name in the Wild Monster data (part of the Cinnabar Island Missingno glitch) - jp .BallSuccess ;$578b -.notOldManBattle ;$56e9 - ld a,[W_CURMAP] + ld bc,NAME_LENGTH + call CopyData ; save the player's name in the Wild Monster data (part of the Cinnabar Island Missingno. glitch) + jp .captured + +.notOldManBattle +; If the player is fighting the ghost Marowak, set the value that indicates the +; Pokémon can't be caught and skip the capture calculations. + 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 ;$56fa + ld b,$10 ; can't be caught value + jp z,.setAnimData + +; Get the first random number. Let it be called Rand1. +; Rand1 must be within a certain range according the kind of ball being thrown. +; The ranges are as follows. +; Poké Ball: [0, 255] +; Great Ball: [0, 200] +; Ultra/Safari Ball: [0, 150] +; Loop until an acceptable number is found. + +.loop call Random ld b,a + +; Get the item ID. ld hl,wcf91 ld a,[hl] + +; The Master Ball always succeeds. cp a,MASTER_BALL - jp z,.BallSuccess ;$578b + jp z,.captured + +; Anything will do for the basic Poké Ball. cp a,POKE_BALL jr z,.checkForAilments + +; If it's a Great/Ultra/Safari Ball and Rand1 is greater than 200, try again. ld a,200 cp b - jr c,.loop ;get only numbers <= 200 for Great Ball + jr c,.loop + +; Less than or equal to 200 is good enough for a Great Ball. ld a,[hl] cp a,GREAT_BALL jr z,.checkForAilments - ld a,150 ;get only numbers <= 150 for Ultra Ball + +; If it's an Ultra/Safari Ball and Rand1 is greater than 150, try again. + ld a,150 cp b jr c,.loop -.checkForAilments ;$571a -; 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 + +.checkForAilments +; Pokémon can be caught more easily with a status ailment. +; Depending on the status ailment, a certain value will be subtracted from +; Rand1. Let this value be called Status. +; The larger Status is, the more easily the Pokémon can be caught. +; no status ailment: Status = 0 +; Burn/Paralysis/Poison: Status = 12 +; Freeze/Sleep: Status = 25 +; If Status is greater than Rand1, the Pokémon will be caught for sure. + ld a,[wEnemyMonStatus] and a - jr z,.noAilments - and a, 1 << FRZ | SLP ;is frozen and/or asleep? + jr z,.skipAilmentValueSubtraction ; no ailments + and a, 1 << FRZ | SLP ld c,12 jr z,.notFrozenOrAsleep ld c,25 -.notFrozenOrAsleep ;$5728 +.notFrozenOrAsleep ld a,b sub c - jp c,.BallSuccess ;$578b + jp c,.captured ld b,a -.noAilments ;$572e - push bc ;save RANDOM number + +.skipAilmentValueSubtraction + push bc ; save (Rand1 - Status) + +; Calculate MaxHP * 255. xor a ld [H_MULTIPLICAND],a ld hl,wEnemyMonMaxHP @@ -201,125 +247,182 @@ ItemUseBall: ; d687 (3:5687) ld [H_MULTIPLICAND + 2],a ld a,255 ld [H_MULTIPLIER],a - call Multiply ; MaxHP * 255 + call Multiply + +; Determine BallFactor. It's 8 for Great Balls and 12 for the others. ld a,[wcf91] cp a,GREAT_BALL - ld a,12 ;any other BallFactor - jr nz,.next7 + ld a,12 + jr nz,.skip1 ld a,8 -.next7 ;$574d + +.skip1 +; Note that the results of all division operations are floored. + +; Calculate (MaxHP * 255) / BallFactor. ld [H_DIVISOR],a - ld b,4 ; number of bytes in dividend + ld b,4 ; number of bytes in dividend call Divide + +; Divide the enemy's current HP by 4. HP is not supposed to exceed 999 so +; the result should fit in a. If the division results in a quotient of 0, +; change it to 1. 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). -; Always bigger than zero. srl b rr a srl b - rr a ; a = current HP / 4 + rr a and a - jr nz,.next8 + jr nz,.skip2 inc a -.next8 ;$5766 + +.skip2 +; Let W = ((MaxHP * 255) / BallFactor) / max(HP / 4, 1). Calculate W. ld [H_DIVISOR],a ld b,4 - call Divide ; ((MaxHP * 255) / BallFactor) / (CurHP / 4) + call Divide + +; If W > 255, store 255 in [H_QUOTIENT + 3]. +; Let X = min(W, 255) = [H_QUOTIENT + 3]. ld a,[H_QUOTIENT + 2] and a - jr z,.next9 + jr z,.skip3 ld a,255 ld [H_QUOTIENT + 3],a -.next9 ;$5776 - pop bc - ld a,[wEnemyMonCatchRate] ;enemy: Catch Rate + +.skip3 + pop bc ; b = Rand1 - Status + +; If Rand1 - Status > CatchRate, the ball fails to capture the Pokémon. + ld a,[wEnemyMonCatchRate] cp b - jr c,.next10 + jr c,.failedToCapture + +; If W > 255, the ball captures the Pokémon. ld a,[H_QUOTIENT + 2] and a - jr nz,.BallSuccess ; if ((MaxHP * 255) / BallFactor) / (CurHP / 4) > 0x255, automatic success - call Random + jr nz,.captured + + call Random ; Let this random number be called Rand2. + +; If Rand2 > X, the ball fails to capture the Pokémon. ld b,a ld a,[H_QUOTIENT + 3] cp b - jr c,.next10 -.BallSuccess ;$578b - jr .BallSuccess2 -.next10 ;$578d + jr c,.failedToCapture + +.captured + jr .skipShakeCalculations + +.failedToCapture ld a,[H_QUOTIENT + 3] - ld [wd11e],a + ld [wPokeBallCaptureCalcTemp],a ; Save X. + +; Calculate CatchRate * 100. xor a ld [H_MULTIPLICAND],a ld [H_MULTIPLICAND + 1],a - ld a,[wEnemyMonCatchRate] ;enemy: Catch Rate + ld a,[wEnemyMonCatchRate] ld [H_MULTIPLICAND + 2],a ld a,100 ld [H_MULTIPLIER],a - call Multiply ; CatchRate * 100 + call Multiply + +; Determine BallFactor2. +; Poké Ball: BallFactor2 = 255 +; Great Ball: BallFactor2 = 200 +; Ultra/Safari Ball: BallFactor2 = 150 ld a,[wcf91] ld b,255 cp a,POKE_BALL - jr z,.next11 + jr z,.skip4 ld b,200 cp a,GREAT_BALL - jr z,.next11 + jr z,.skip4 ld b,150 cp a,ULTRA_BALL - jr z,.next11 -.next11 ;$57b8 + jr z,.skip4 + +.skip4 +; Let Y = (CatchRate * 100) / BallFactor2. Calculate Y. ld a,b ld [H_DIVISOR],a ld b,4 call Divide + +; If Y > 255, there are 3 shakes. +; Note that this shouldn't be possible. +; The maximum value of Y is (255 * 100) / 150 = 170. ld a,[H_QUOTIENT + 2] and a - ld b,$63 - jr nz,.next12 - ld a,[wd11e] + ld b,$63 ; 3 shakes + jr nz,.setAnimData + +; Calculate X * Y. + ld a,[wPokeBallCaptureCalcTemp] ld [H_MULTIPLIER],a call Multiply + +; Calculate (X * Y) / 255. ld a,255 ld [H_DIVISOR],a ld b,4 call Divide - ld a,[wEnemyMonStatus] ;status ailments + +; Determine Status2. +; no status ailment: Status2 = 0 +; Burn/Paralysis/Poison: Status2 = 5 +; Freeze/Sleep: Status2 = 10 + ld a,[wEnemyMonStatus] and a - jr z,.next13 + jr z,.skip5 and a, 1 << FRZ | SLP ld b,5 - jr z,.next14 + jr z,.addAilmentValue ld b,10 -.next14 ;$57e6 + +.addAilmentValue +; If the Pokémon has a status ailment, add Status2. ld a,[H_QUOTIENT + 3] add b ld [H_QUOTIENT + 3],a -.next13 ;$57eb + +.skip5 +; Finally determine the number of shakes. +; Let Z = ((X * Y) / 255) + Status2 = [H_QUOTIENT + 3]. +; The number of shakes depend on the range Z is in. +; 0 ≤ Z < 10: 0 shakes (the ball misses) +; 10 ≤ Z < 30: 1 shake +; 30 ≤ Z < 70: 2 shakes +; 70 ≤ Z: 3 shakes ld a,[H_QUOTIENT + 3] cp a,10 ld b,$20 - jr c,.next12 + jr c,.setAnimData cp a,30 ld b,$61 - jr c,.next12 + jr c,.setAnimData cp a,70 ld b,$62 - jr c,.next12 + jr c,.setAnimData ld b,$63 -.next12 ;$5801 + +.setAnimData ld a,b - ld [wd11e],a -.BallSuccess2 ;$5805 + ld [wPokeBallAnimData],a + +.skipShakeCalculations ld c,20 call DelayFrames + +; Do the animation. ld a,TOSS_ANIM - ld [W_ANIMATIONID],a + ld [wAnimationID],a xor a - ld [$fff3],a + ld [H_WHOSETURN],a ld [wAnimationType],a ld [wDamageMultipliers],a ld a,[wWhichPokemon] @@ -331,51 +434,67 @@ ItemUseBall: ; d687 (3:5687) ld [wcf91],a pop af ld [wWhichPokemon],a - ld a,[wd11e] + +; Determine the message to display from the animation. + ld a,[wPokeBallAnimData] cp a,$10 ld hl,ItemUseBallText00 - jp z,.printText0 + jp z,.printMessage cp a,$20 ld hl,ItemUseBallText01 - jp z,.printText0 + jp z,.printMessage cp a,$61 ld hl,ItemUseBallText02 - jp z,.printText0 + jp z,.printMessage cp a,$62 ld hl,ItemUseBallText03 - jp z,.printText0 + jp z,.printMessage cp a,$63 ld hl,ItemUseBallText04 - jp z,.printText0 - ld hl,wEnemyMonHP ;current HP + jp z,.printMessage + +; Save current HP. + ld hl,wEnemyMonHP ld a,[hli] push af ld a,[hli] - push af ;backup currentHP... + push af + +; Save status ailment. inc hl ld a,[hl] - push af ;...and status ailments + push af + push hl - ld hl,W_ENEMYBATTSTATUS3 + +; If the Pokémon is transformed, the Pokémon is assumed to be a Ditto. +; This is a bug because a wild Pokémon could have used Transform via +; Mirror Move even though the only wild Pokémon that knows Transform is Ditto. + ld hl,wEnemyBattleStatus3 bit Transformed,[hl] - jr z,.next15 - ld a,$4c + jr z,.notTransformed + ld a,DITTO ld [wEnemyMonSpecies2],a - jr .next16 -.next15 ;$5871 + jr .skip6 + +.notTransformed +; If the Pokémon is not transformed, set the transformed bit and copy the +; DVs to wTransformedEnemyMonOriginalDVs so that LoadEnemyMonData won't generate +; new DVs. set Transformed,[hl] - ld hl,wcceb + ld hl,wTransformedEnemyMonOriginalDVs ld a,[wEnemyMonDVs] ld [hli],a ld a,[wEnemyMonDVs + 1] ld [hl],a -.next16 ;$587e + +.skip6 ld a,[wcf91] push af ld a,[wEnemyMonSpecies2] ld [wcf91],a ld a,[wEnemyMonLevel] - ld [W_CURENEMYLVL],a + ld [wCurEnemyLVL],a callab LoadEnemyMonData pop af ld [wcf91],a @@ -387,124 +506,136 @@ ItemUseBall: ; d687 (3:5687) ld [hld],a pop af ld [hl],a - ld a,[wEnemyMonSpecies] ;enemy - ld [wd11c],a + ld a,[wEnemyMonSpecies] + ld [wCapturedMonSpecies],a ld [wcf91],a ld [wd11e],a - ld a,[W_BATTLETYPE] - dec a - jr z,.printText1 + ld a,[wBattleType] + dec a ; is this the old man battle? + jr z,.oldManCaughtMon ; if so, don't give the player the caught Pokémon + ld hl,ItemUseBallText05 call PrintText + +; Add the caught Pokémon to the Pokédex. predef IndexToPokedex ld a,[wd11e] dec a ld c,a - ld b,2 - ld hl,wPokedexOwned ;Dex_own_flags (pokemon) + ld b,FLAG_TEST + ld hl,wPokedexOwned predef FlagActionPredef ld a,c push af ld a,[wd11e] dec a ld c,a - ld b,1 + ld b,FLAG_SET predef FlagActionPredef pop af - and a - jr nz,.checkParty + + and a ; was the Pokémon already in the Pokédex? + jr nz,.skipShowingPokedexData ; if so, don't show the Pokédex data + ld hl,ItemUseBallText06 call PrintText call ClearSprites - ld a,[wEnemyMonSpecies] ;caught mon_ID + ld a,[wEnemyMonSpecies] ld [wd11e],a predef ShowPokedexData -.checkParty ;$58f4 + +.skipShowingPokedexData ld a,[wPartyCount] - cp a,PARTY_LENGTH ;is party full? + cp a,PARTY_LENGTH ; is party full? jr z,.sendToBox - xor a - ld [wcc49],a + xor a ; PLAYER_PARTY_DATA + ld [wMonDataLocation],a call ClearSprites - call AddPartyMon ;add mon to Party - jr .End -.sendToBox ;$5907 + call AddPartyMon + jr .done + +.sendToBox call ClearSprites call SendNewMonToBox ld hl,ItemUseBallText07 - ld a,[wd7f1] - bit 0,a ;already met Bill? - jr nz,.sendToBox2 + CheckEvent EVENT_MET_BILL + jr nz,.printTransferredToPCText ld hl,ItemUseBallText08 -.sendToBox2 ;$591a +.printTransferredToPCText call PrintText - jr .End -.printText1 ;$591f + jr .done + +.oldManCaughtMon ld hl,ItemUseBallText05 -.printText0 ;$5922 + +.printMessage call PrintText call ClearSprites -.End ;$5928 - ld a,[W_BATTLETYPE] - and a - ret nz + +.done + ld a,[wBattleType] + and a ; is this the old man battle? + ret nz ; if so, don't remove a ball from the bag + +; Remove a ball from the bag. ld hl,wNumBagItems inc a - ld [wcf96],a - jp RemoveItemFromInventory ;remove ITEM (XXX) -ItemUseBallText00: ; d937 (3:5937) + ld [wItemQuantity],a + jp RemoveItemFromInventory + +ItemUseBallText00: ;"It dodged the thrown ball!" ;"This pokemon can't be caught" TX_FAR _ItemUseBallText00 db "@" -ItemUseBallText01: ; d93c (3:593c) +ItemUseBallText01: ;"You missed the pokemon!" TX_FAR _ItemUseBallText01 db "@" -ItemUseBallText02: ; d941 (3:5941) +ItemUseBallText02: ;"Darn! The pokemon broke free!" TX_FAR _ItemUseBallText02 db "@" -ItemUseBallText03: ; d946 (3:5946) +ItemUseBallText03: ;"Aww! It appeared to be caught!" TX_FAR _ItemUseBallText03 db "@" -ItemUseBallText04: ; d94b (3:594b) +ItemUseBallText04: ;"Shoot! It was so close too!" TX_FAR _ItemUseBallText04 db "@" -ItemUseBallText05: ; d950 (3:5950) +ItemUseBallText05: ;"All right! {MonName} was caught!" ;play sound TX_FAR _ItemUseBallText05 - db $12,$06 + TX_SFX_CAUGHT_MON + TX_BLINK db "@" -ItemUseBallText07: ; d957 (3:5957) +ItemUseBallText07: ;"X was transferred to Bill's PC" TX_FAR _ItemUseBallText07 db "@" -ItemUseBallText08: ; d95c (3:595c) +ItemUseBallText08: ;"X was transferred to someone's PC" TX_FAR _ItemUseBallText08 db "@" -ItemUseBallText06: ; d961 (3:5961) +ItemUseBallText06: ;"New DEX data will be added..." ;play sound TX_FAR _ItemUseBallText06 - db $13,$06 + TX_SFX_DEX_PAGE_ADDED + TX_BLINK db "@" -ItemUseTownMap: ; d968 (3:5968) - ld a,[W_ISINBATTLE] +ItemUseTownMap: + ld a,[wIsInBattle] and a jp nz,ItemUseNotTime - ld b, BANK(DisplayTownMap) - ld hl, DisplayTownMap - jp Bankswitch ; display Town Map + jpba DisplayTownMap -ItemUseBicycle: ; d977 (3:5977) - ld a,[W_ISINBATTLE] +ItemUseBicycle: + ld a,[wIsInBattle] and a jp nz,ItemUseNotTime ld a,[wWalkBikeSurfState] @@ -534,7 +665,7 @@ ItemUseBicycle: ; d977 (3:5977) jp PrintText ; used for Surf out-of-battle effect -ItemUseSurfboard: ; d9b4 (3:59b4) +ItemUseSurfboard: ld a,[wWalkBikeSurfState] ld [wWalkBikeSurfStateCopy],a cp a,2 ; is the player already surfing? @@ -556,17 +687,17 @@ ItemUseSurfboard: ; d9b4 (3:59b4) jp PrintText .tryToStopSurfing xor a - ld [$ff8c],a + ld [hSpriteIndexOrTextID],a ld d,16 ; talking range in pixels (normal range) call IsSpriteInFrontOfPlayer2 res 7,[hl] - ld a,[$ff8c] + ld a,[hSpriteIndexOrTextID] and a ; is there a sprite in the way? jr nz,.cannotStopSurfing ld hl,TilePairCollisionsWater call CheckForTilePairCollisions jr c,.cannotStopSurfing - ld hl,W_TILESETCOLLISIONPTR ; pointer to list of passable tiles + ld hl,wTilesetCollisionPtr ; pointer to list of passable tiles ld a,[hli] ld h,[hl] ld l,a ; hl now points to passable tiles @@ -593,14 +724,14 @@ ItemUseSurfboard: ; d9b4 (3:59b4) jp LoadWalkingPlayerSpriteGraphics ; uses a simulated button press to make the player move forward .makePlayerMoveForward - ld a,[wd52a] ; direction the player is going - bit 3,a + ld a,[wPlayerDirection] ; direction the player is going + bit PLAYER_DIR_BIT_UP,a ld b,D_UP jr nz,.storeSimulatedButtonPress - bit 2,a + bit PLAYER_DIR_BIT_DOWN,a ld b,D_DOWN jr nz,.storeSimulatedButtonPress - bit 1,a + bit PLAYER_DIR_BIT_LEFT,a ld b,D_LEFT jr nz,.storeSimulatedButtonPress ld b,D_RIGHT @@ -613,28 +744,28 @@ ItemUseSurfboard: ; d9b4 (3:59b4) ld [wSimulatedJoypadStatesIndex],a ret -SurfingGotOnText: ; da4c (3:5a4c) +SurfingGotOnText: TX_FAR _SurfingGotOnText db "@" -SurfingNoPlaceToGetOffText: ; da51 (3:5a51) +SurfingNoPlaceToGetOffText: TX_FAR _SurfingNoPlaceToGetOffText db "@" -ItemUsePokedex: ; da56 (3:5a56) +ItemUsePokedex: predef_jump ShowPokedexMenu -ItemUseEvoStone: ; da5b (3:5a5b) - ld a,[W_ISINBATTLE] +ItemUseEvoStone: + ld a,[wIsInBattle] and a jp nz,ItemUseNotTime ld a,[wWhichPokemon] push af ld a,[wcf91] - ld [wd156],a + ld [wEvoStoneItemID],a push af - ld a,$05 ; evolution stone party menu - ld [wd07d],a + ld a,EVO_STONE_PARTY_MENU + ld [wPartyMenuTypeOrMessageID],a ld a,$ff ld [wUpdateSpritesEnabled],a call DisplayPartyMenu @@ -643,34 +774,34 @@ ItemUseEvoStone: ; da5b (3:5a5b) ld a,b ld [wcf91],a ld a,$01 - ld [wccd4],a - ld a,(SFX_02_3e - SFX_Headers_02) / 3 - call PlaySoundWaitForCurrent ; play sound - call WaitForSoundToFinish ; wait for sound to end + ld [wForceEvolution],a + ld a,SFX_HEAL_AILMENT + call PlaySoundWaitForCurrent + call WaitForSoundToFinish callab TryEvolvingMon ; try to evolve pokemon - ld a,[wd121] + ld a,[wEvolutionOccurred] and a jr z,.noEffect pop af ld [wWhichPokemon],a ld hl,wNumBagItems ld a,1 ; remove 1 stone - ld [wcf96],a + ld [wItemQuantity],a jp RemoveItemFromInventory .noEffect call ItemUseNoEffect .canceledItemUse xor a - ld [wcd6a],a + ld [wActionResultOrTookBattleTurn],a ; item not used pop af ret -ItemUseVitamin: ; dab4 (3:5ab4) - ld a,[W_ISINBATTLE] +ItemUseVitamin: + ld a,[wIsInBattle] and a jp nz,ItemUseNotTime -ItemUseMedicine: ; dabb (3:5abb) +ItemUseMedicine: ld a,[wPartyCount] and a jp z,.emptyParty @@ -678,11 +809,11 @@ ItemUseMedicine: ; dabb (3:5abb) push af ld a,[wcf91] push af - ld a,$01 - ld [wd07d],a ; item use party menu + ld a,USE_ITEM_PARTY_MENU + ld [wPartyMenuTypeOrMessageID],a ld a,$ff ld [wUpdateSpritesEnabled],a - ld a,[wd152] + ld a,[wPseudoItemID] and a ; using Softboiled? jr z,.notUsingSoftboiled ; if using softboiled @@ -691,7 +822,7 @@ ItemUseMedicine: ; dabb (3:5abb) .emptyParty ld hl,.emptyPartyText xor a - ld [wcd6a],a ; item use failed + ld [wActionResultOrTookBattleTurn],a ; item use failed jp PrintText .emptyPartyText text "You don't have" @@ -706,7 +837,7 @@ ItemUseMedicine: ; dabb (3:5abb) ld a,[wWhichPokemon] call AddNTimes ld a,[wWhichPokemon] - ld [wcf06],a + ld [wUsedItemOnWhichPokemon],a ld d,a ld a,[wcf91] ld e,a @@ -715,7 +846,7 @@ ItemUseMedicine: ; dabb (3:5abb) ld [wcf91],a pop af ld [wWhichPokemon],a - ld a,[wd152] + ld a,[wPseudoItemID] and a ; using Softboiled? jr z,.checkItemType ; if using softboiled @@ -734,25 +865,25 @@ ItemUseMedicine: ; dabb (3:5abb) 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 + ld bc,wPartyMon1Status - wPartyMon1 add hl,bc ; hl now points to status ld a,[wcf91] - ld bc,$f008 + lb bc, ANTIDOTE_MSG, 1 << PSN cp a,ANTIDOTE jr z,.checkMonStatus - ld bc,$f110 + lb bc, BURN_HEAL_MSG, 1 << BRN cp a,BURN_HEAL jr z,.checkMonStatus - ld bc,$f220 + lb bc, ICE_HEAL_MSG, 1 << FRZ cp a,ICE_HEAL jr z,.checkMonStatus - ld bc,$f307 + lb bc, AWAKENING_MSG, SLP cp a,AWAKENING jr z,.checkMonStatus - ld bc,$f440 + lb bc, PARALYZ_HEAL_MSG, 1 << PAR cp a,PARLYZ_HEAL jr z,.checkMonStatus - ld bc,$f6ff ; Full Heal + lb bc, FULL_HEAL_MSG, $ff ; Full Heal .checkMonStatus ld a,[hl] ; pokemon's status and c ; does the pokemon have a status ailment the item can cure? @@ -761,7 +892,7 @@ ItemUseMedicine: ; dabb (3:5abb) xor a ld [hl],a ; remove the status ailment in the party data ld a,b - ld [wd07d],a ; the message to display for the item used + 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 @@ -769,13 +900,13 @@ ItemUseMedicine: ; dabb (3:5abb) xor a ld [wBattleMonStatus],a ; remove the status ailment in the in-battle pokemon data push hl - ld hl,W_PLAYERBATTSTATUS3 + ld hl,wPlayerBattleStatus3 res BadlyPoisoned,[hl] ; heal Toxic status pop hl - ld bc,30 + ld bc,wPartyMon1Stats - wPartyMon1Status add hl,bc ; hl now points to party stats - ld de,wBattleMonMaxHP - ld bc,10 + ld de,wBattleMonStats + ld bc,NUM_STATS * 2 call CopyData ; copy party stats to in-battle stat data predef DoubleOrHalveSelectedStats jp .doneHealing @@ -797,24 +928,24 @@ ItemUseMedicine: ; dabb (3:5abb) jr z,.updateInBattleFaintedData jp .healingItemNoEffect .updateInBattleFaintedData - ld a,[W_ISINBATTLE] + ld a,[wIsInBattle] and a jr z,.compareCurrentHPToMaxHP push hl push de push bc - ld a,[wcf06] + ld a,[wUsedItemOnWhichPokemon] ld c,a ld hl,wPartyFoughtCurrentEnemyFlags - ld b,$02 + ld b,FLAG_TEST predef FlagActionPredef ld a,c and a jr z,.next - ld a,[wcf06] + ld a,[wUsedItemOnWhichPokemon] ld c,a ld hl,wPartyGainExpFlags - ld b,$01 + ld b,FLAG_SET predef FlagActionPredef .next pop bc @@ -830,7 +961,7 @@ ItemUseMedicine: ; dabb (3:5abb) .compareCurrentHPToMaxHP push hl push bc - ld bc,32 + ld bc,wPartyMon1MaxHP - (wPartyMon1HP + 1) add hl,bc ; hl now points to max HP pop bc ld a,[hli] @@ -859,16 +990,16 @@ ItemUseMedicine: ; dabb (3:5abb) .notFullHP ; if the pokemon's current HP doesn't equal its max HP xor a ld [wLowHealthAlarm],a ;disable low health alarm - ld [wc02a],a + ld [wChannelSoundIDs + Ch4],a push hl push de - ld bc,32 + ld bc,wPartyMon1MaxHP - (wPartyMon1HP + 1) 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,[wd152] + ld a,[wPseudoItemID] and a ; using Softboiled? jp z,.notUsingSoftboiled2 ; if using softboiled @@ -895,7 +1026,7 @@ ItemUseMedicine: ; dabb (3:5abb) 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 + ld bc,(wPartyMon1HP + 1) - (wPartyMon1MaxHP + 1) 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] @@ -913,12 +1044,12 @@ ItemUseMedicine: ; dabb (3:5abb) sbc b ld [hl],a ld [wHPBarNewHP+1],a - hlCoord 4, 1 + coord hl, 4, 1 ld a,[wWhichPokemon] - ld bc,2 * 20 + ld bc,2 * SCREEN_WIDTH call AddNTimes ; calculate coordinates of HP bar of pokemon that used Softboiled - ld a,(SFX_02_3d - SFX_Headers_02) / 3 - call PlaySoundWaitForCurrent ; play sound + ld a,SFX_HEAL_HP + call PlaySoundWaitForCurrent ld a,[hFlags_0xFFF6] set 0,a ld [hFlags_0xFFF6],a @@ -974,7 +1105,7 @@ ItemUseMedicine: ; dabb (3:5abb) inc hl ld d,h ld e,l ; de now points to current HP - ld hl,33 + ld hl,(wPartyMon1MaxHP + 1) - (wPartyMon1HP + 1) add hl,de ; hl now points to max HP ld a,[wcf91] cp a,REVIVE @@ -1021,7 +1152,7 @@ ItemUseMedicine: ; dabb (3:5abb) ld a,[wcf91] cp a,FULL_RESTORE jr nz,.updateInBattleData - ld bc,-31 + ld bc,wPartyMon1Status - (wPartyMon1MaxHP + 1) add hl,bc xor a ld [hl],a ; remove the status ailment in the party data @@ -1044,7 +1175,7 @@ ItemUseMedicine: ; dabb (3:5abb) ld [wBattleMonStatus],a ; remove the status ailment in the in-battle pokemon data .calculateHPBarCoords ld hl,wOAMBuffer + $90 - ld bc,2 * 20 + ld bc,2 * SCREEN_WIDTH inc d .calculateHPBarCoordsLoop add hl,bc @@ -1055,7 +1186,7 @@ ItemUseMedicine: ; dabb (3:5abb) call ItemUseNoEffect jp .done .doneHealing - ld a,[wd152] + ld a,[wPseudoItemID] and a ; using Softboiled? jr nz,.skipRemovingItem ; no item to remove if using Softboiled push hl @@ -1067,8 +1198,8 @@ ItemUseMedicine: ; dabb (3:5abb) jr c,.playStatusAilmentCuringSound cp a,FULL_HEAL jr z,.playStatusAilmentCuringSound - ld a,(SFX_02_3d - SFX_Headers_02) / 3 ; HP healing sound - call PlaySoundWaitForCurrent ; play sound + ld a,SFX_HEAL_HP + call PlaySoundWaitForCurrent ld a,[hFlags_0xFFF6] set 0,a ld [hFlags_0xFFF6],a @@ -1078,18 +1209,18 @@ ItemUseMedicine: ; dabb (3:5abb) ld a,[hFlags_0xFFF6] res 0,a ld [hFlags_0xFFF6],a - ld a,$f7 ; revived message - ld [wd07d],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,$f5 ; standard HP healed message - ld [wd07d],a + ld a,POTION_MSG + ld [wPartyMenuTypeOrMessageID],a jr .showHealingItemMessage .playStatusAilmentCuringSound - ld a,(SFX_02_3e - SFX_Headers_02) / 3 ; status ailment curing sound + ld a,SFX_HEAL_AILMENT call PlaySoundWaitForCurrent .showHealingItemMessage xor a @@ -1106,16 +1237,16 @@ ItemUseMedicine: ; dabb (3:5abb) jr .done .canceledItemUse xor a - ld [wcd6a],a ; item use failed + ld [wActionResultOrTookBattleTurn],a ; item use failed pop af pop af .done - ld a,[wd152] + ld a,[wPseudoItemID] and a ; using Softboiled? ret nz ; if so, return call GBPalWhiteOut - call z,GoPAL_SET_CF1C - ld a,[W_ISINBATTLE] + call z,RunDefaultPaletteCommand + ld a,[wIsInBattle] and a ret nz jp ReloadMapData @@ -1124,10 +1255,10 @@ ItemUseMedicine: ; dabb (3:5abb) ld a,[hl] ld [wd0b5],a ld [wd11e],a - ld bc,33 + ld bc,wPartyMon1Level - wPartyMon1 add hl,bc ; hl now points to level ld a,[hl] ; a = level - ld [W_CURENEMYLVL],a ; store level + ld [wCurEnemyLVL],a ; store level call GetMonHeader push de ld a,d @@ -1141,7 +1272,7 @@ ItemUseMedicine: ; dabb (3:5abb) push hl sub a,HP_UP add a - ld bc,17 + ld bc,wPartyMon1HPExp - wPartyMon1 add hl,bc add l ld l,a @@ -1178,8 +1309,8 @@ ItemUseMedicine: ; dabb (3:5abb) ld de,wcf4b ld bc,10 call CopyData ; copy the stat's name to wcf4b - ld a,(SFX_02_3e - SFX_Headers_02) / 3 - call PlaySound ; play sound + ld a,SFX_HEAL_AILMENT + call PlaySound ld hl,VitaminStatRoseText call PrintText jp RemoveUsedItem @@ -1189,38 +1320,38 @@ ItemUseMedicine: ; dabb (3:5abb) call PrintText jp GBPalWhiteOut .recalculateStats - ld bc,34 + ld bc,wPartyMon1Stats - wPartyMon1 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 bc,(wPartyMon1Exp + 2) - wPartyMon1Stats + add hl,bc ; hl now points to LSB of experience ld b,1 jp CalcStats ; recalculate stats .useRareCandy push hl - ld bc,33 + ld bc,wPartyMon1Level - wPartyMon1 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 inc a ld [hl],a ; store incremented level - ld [W_CURENEMYLVL],a + ld [wCurEnemyLVL],a push hl push de 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,wPartyMon1Exp - wPartyMon1Level + add hl,bc ; hl now points to MSB of experience ; update experience to minimum for new level - ld a,[$ff96] + ld a,[hExperience] ld [hli],a - ld a,[$ff97] + ld a,[hExperience + 1] ld [hli],a - ld a,[$ff98] + ld a,[hExperience + 2] ld [hl],a pop hl ld a,[wWhichPokemon] @@ -1229,7 +1360,7 @@ ItemUseMedicine: ; dabb (3:5abb) push af push de push hl - ld bc,34 + ld bc,wPartyMon1MaxHP - wPartyMon1 add hl,bc ; hl now points to MSB of max HP ld a,[hli] ld b,a @@ -1239,8 +1370,8 @@ ItemUseMedicine: ; dabb (3:5abb) push hl call .recalculateStats pop hl - ld bc,35 ; hl now points to LSB of max HP - add hl,bc + ld bc,(wPartyMon1MaxHP + 1) - wPartyMon1 + add hl,bc ; hl now points to LSB of max HP pop bc ld a,[hld] sub c @@ -1249,33 +1380,33 @@ ItemUseMedicine: ; dabb (3:5abb) sbc b 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 de,(wPartyMon1HP + 1) - wPartyMon1MaxHP + add hl,de ; hl now points to LSB of current HP ld a,[hl] add c ld [hld],a ld a,[hl] adc b ld [hl],a - ld a,$f8 ; level up message - ld [wd07d],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 - xor a - ld [wcc49],a ; load from player's party + xor a ; PLAYER_PARTY_DATA + ld [wMonDataLocation],a call LoadMonData ld d,$01 callab PrintStatsBox ; display new stats text box call WaitForTextScrollButtonPress ; wait for button press - xor a - ld [wcc49],a + xor a ; PLAYER_PARTY_DATA + ld [wMonDataLocation],a predef LearnMoveFromLevelUp ; learn level up move, if any xor a - ld [wccd4],a + ld [wForceEvolution],a callab TryEvolvingMon ; evolve pokemon, if appropriate ld a,$01 ld [wUpdateSpritesEnabled],a @@ -1285,22 +1416,22 @@ ItemUseMedicine: ; dabb (3:5abb) ld [wWhichPokemon],a jp RemoveUsedItem -VitaminStatRoseText: ; df24 (3:5f24) +VitaminStatRoseText: TX_FAR _VitaminStatRoseText db "@" -VitaminNoEffectText: ; df29 (3:5f29) +VitaminNoEffectText: TX_FAR _VitaminNoEffectText db "@" -VitaminText: ; df2e (3:5f2e) +VitaminText: db "HEALTH@" db "ATTACK@" db "DEFENSE@" db "SPEED@" db "SPECIAL@" -ItemUseBait: ; df52 (3:5f52) +ItemUseBait: ld hl,ThrewBaitText call PrintText ld hl,wEnemyMonCatchRate ; catch rate @@ -1310,7 +1441,7 @@ ItemUseBait: ; df52 (3:5f52) ld de,wSafariEscapeFactor ; escape factor jr BaitRockCommon -ItemUseRock: ; df67 (3:5f67) +ItemUseRock: ld hl,ThrewRockText call PrintText ld hl,wEnemyMonCatchRate ; catch rate @@ -1324,10 +1455,10 @@ ItemUseRock: ; df67 (3:5f67) ld hl,wSafariEscapeFactor ; escape factor ld de,wSafariBaitFactor ; bait factor -BaitRockCommon: ; df7f (3:5f7f) - ld [W_ANIMATIONID],a +BaitRockCommon: + ld [wAnimationID],a xor a - ld [wcc5b],a + 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 @@ -1347,23 +1478,23 @@ BaitRockCommon: ; df7f (3:5f7f) ld c,70 jp DelayFrames -ThrewBaitText: ; dfa5 (3:5fa5) +ThrewBaitText: TX_FAR _ThrewBaitText db "@" -ThrewRockText: ; dfaa (3:5faa) +ThrewRockText: TX_FAR _ThrewRockText db "@" ; also used for Dig out-of-battle effect -ItemUseEscapeRope: ; dfaf (3:5faf) - ld a,[W_ISINBATTLE] +ItemUseEscapeRope: + ld a,[wIsInBattle] and a jr nz,.notUsable - ld a,[W_CURMAP] + ld a,[wCurMap] cp a,AGATHAS_ROOM jr z,.notUsable - ld a,[W_CURMAPTILESET] + ld a,[wCurMapTileset] ld b,a ld hl,EscapeRopeTilesets .loop @@ -1377,15 +1508,14 @@ ItemUseEscapeRope: ; dfaf (3:5faf) set 6,[hl] ld hl,wd72e res 4,[hl] - ld hl,wd790 - res 7,[hl] ; unset Safari Zone bit + ResetEvent EVENT_IN_SAFARI_ZONE xor a - ld [W_NUMSAFARIBALLS],a - ld [W_SAFARIZONEENTRANCECURSCRIPT],a + ld [wNumSafariBalls],a + ld [wSafariZoneEntranceCurScript],a inc a ld [wEscapedFromBattle],a - ld [wcd6a],a ; item used - ld a,[wd152] + ld [wActionResultOrTookBattleTurn],a ; item used + ld a,[wPseudoItemID] and a ; using Dig? ret nz ; if so, return call ItemUseReloadOverworldData @@ -1395,15 +1525,15 @@ ItemUseEscapeRope: ; dfaf (3:5faf) .notUsable jp ItemUseNotTime -EscapeRopeTilesets: ; dffd (3:5ffd) +EscapeRopeTilesets: db FOREST, CEMETERY, CAVERN, FACILITY, INTERIOR db $ff ; terminator -ItemUseRepel: ; e003 (3:6003) +ItemUseRepel: ld b,100 -ItemUseRepelCommon: ; e005 (3:6005) - ld a,[W_ISINBATTLE] +ItemUseRepelCommon: + ld a,[wIsInBattle] and a jp nz,ItemUseNotTime ld a,b @@ -1411,21 +1541,21 @@ ItemUseRepelCommon: ; e005 (3:6005) jp PrintItemUseTextAndRemoveItem ; handles X Accuracy item -ItemUseXAccuracy: ; e013 (3:6013) - ld a,[W_ISINBATTLE] +ItemUseXAccuracy: + ld a,[wIsInBattle] and a jp z,ItemUseNotTime - ld hl,W_PLAYERBATTSTATUS2 + ld hl,wPlayerBattleStatus2 set UsingXAccuracy,[hl] ; X Accuracy bit jp PrintItemUseTextAndRemoveItem ; This function is bugged and never works. It always jumps to ItemUseNotTime. ; The Card Key is handled in a different way. -ItemUseCardKey: ; e022 (3:6022) +ItemUseCardKey: xor a - ld [wd71f],a + ld [wUnusedD71F],a call GetTileAndCoordsInFrontOfPlayer - ld a,[GetTileAndCoordsInFrontOfPlayer] ; $4586 + ld a,[GetTileAndCoordsInFrontOfPlayer] cp a,$18 jr nz,.next0 ld hl,CardKeyTable1 @@ -1440,7 +1570,7 @@ ItemUseCardKey: ; e022 (3:6022) jp nz,ItemUseNotTime ld hl,CardKeyTable3 .next1 - ld a,[W_CURMAP] + ld a,[wCurMap] ld b,a .loop ld a,[hli] @@ -1455,7 +1585,7 @@ ItemUseCardKey: ; e022 (3:6022) cp e jr nz,.nextEntry3 ld a,[hl] - ld [wd71f],a + ld [wUnusedD71F],a jr .done .nextEntry1 inc hl @@ -1481,7 +1611,7 @@ ItemUseCardKey: ; e022 (3:6022) ; 02: X ; 03: ID? -CardKeyTable1: ; e072 (3:6072) +CardKeyTable1: db SILPH_CO_2F,$04,$04,$00 db SILPH_CO_2F,$04,$05,$01 db SILPH_CO_4F,$0C,$04,$02 @@ -1494,7 +1624,7 @@ CardKeyTable1: ; e072 (3:6072) db SILPH_CO_10F,$08,$0B,$09 db $ff -CardKeyTable2: ; e09b (3:609b) +CardKeyTable2: db SILPH_CO_3F,$08,$09,$0A db SILPH_CO_3F,$09,$09,$0B db SILPH_CO_5F,$04,$07,$0C @@ -1507,64 +1637,64 @@ CardKeyTable2: ; e09b (3:609b) db SILPH_CO_9F,$09,$03,$13 db $ff -CardKeyTable3: ; e0c4 (3:60c4) +CardKeyTable3: db SILPH_CO_11F,$08,$09,$14 db SILPH_CO_11F,$09,$09,$15 db $ff -ItemUsePokedoll: ; e0cd (3:60cd) - ld a,[W_ISINBATTLE] +ItemUsePokedoll: + ld a,[wIsInBattle] dec a jp nz,ItemUseNotTime ld a,$01 ld [wEscapedFromBattle],a jp PrintItemUseTextAndRemoveItem -ItemUseGuardSpec: ; e0dc (3:60dc) - ld a,[W_ISINBATTLE] +ItemUseGuardSpec: + ld a,[wIsInBattle] and a jp z,ItemUseNotTime - ld hl,W_PLAYERBATTSTATUS2 + ld hl,wPlayerBattleStatus2 set ProtectedByMist,[hl] ; Mist bit jp PrintItemUseTextAndRemoveItem -ItemUseSuperRepel: ; e0eb (3:60eb) +ItemUseSuperRepel: ld b,200 jp ItemUseRepelCommon -ItemUseMaxRepel: ; e0f0 (3:60f0) +ItemUseMaxRepel: ld b,250 jp ItemUseRepelCommon -ItemUseDireHit: ; e0f5 (3:60f5) - ld a,[W_ISINBATTLE] +ItemUseDireHit: + ld a,[wIsInBattle] and a jp z,ItemUseNotTime - ld hl,W_PLAYERBATTSTATUS2 + ld hl,wPlayerBattleStatus2 set GettingPumped,[hl] ; Focus Energy bit jp PrintItemUseTextAndRemoveItem -ItemUseXStat: ; e104 (3:6104) - ld a,[W_ISINBATTLE] +ItemUseXStat: + ld a,[wIsInBattle] and a jr nz,.inBattle call ItemUseNotTime ld a,2 - ld [wcd6a],a ; item not used + ld [wActionResultOrTookBattleTurn],a ; item not used ret .inBattle - ld hl,W_PLAYERMOVENUM + ld hl,wPlayerMoveNum ld a,[hli] - push af ; save [W_PLAYERMOVENUM] + push af ; save [wPlayerMoveNum] ld a,[hl] - push af ; save [W_PLAYERMOVEEFFECT] + push af ; save [wPlayerMoveEffect] push hl 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 [W_PLAYERMOVENUM],a + ld [wPlayerMoveNum],a call LoadScreenTilesFromBuffer1 ; restore saved screen call Delay3 xor a @@ -1572,22 +1702,21 @@ ItemUseXStat: ; e104 (3:6104) callba StatModifierUpEffect ; do stat increase move pop hl pop af - ld [hld],a ; restore [W_PLAYERMOVEEFFECT] + ld [hld],a ; restore [wPlayerMoveEffect] pop af - ld [hl],a ; restore [W_PLAYERMOVENUM] + ld [hl],a ; restore [wPlayerMoveNum] ret -ItemUsePokeflute: ; e140 (3:6140) - ld a,[W_ISINBATTLE] +ItemUsePokeflute: + ld a,[wIsInBattle] and a jr nz,.inBattle ; if not in battle call ItemUseReloadOverworldData - ld a,[W_CURMAP] + ld a,[wCurMap] cp a,ROUTE_12 jr nz,.notRoute12 - ld a,[wd7d8] - bit 7,a ; has the player beaten Route 12 Snorlax yet? + CheckEvent EVENT_BEAT_ROUTE12_SNORLAX jr nz,.noSnorlaxToWakeUp ; if the player hasn't beaten Route 12 Snorlax ld hl,Route12SnorlaxFluteCoords @@ -1595,14 +1724,12 @@ ItemUsePokeflute: ; e140 (3:6140) jr nc,.noSnorlaxToWakeUp ld hl,PlayedFluteHadEffectText call PrintText - ld hl,wd7d8 - set 6,[hl] ; trigger Snorlax fight (handled by map script) + SetEvent EVENT_FIGHT_ROUTE12_SNORLAX ret .notRoute12 cp a,ROUTE_16 jr nz,.noSnorlaxToWakeUp - ld a,[wd7e0] - bit 1,a ; has the player beaten Route 16 Snorlax yet? + CheckEvent EVENT_BEAT_ROUTE16_SNORLAX jr nz,.noSnorlaxToWakeUp ; if the player hasn't beaten Route 16 Snorlax ld hl,Route16SnorlaxFluteCoords @@ -1610,19 +1737,18 @@ ItemUsePokeflute: ; e140 (3:6140) jr nc,.noSnorlaxToWakeUp ld hl,PlayedFluteHadEffectText call PrintText - ld hl,wd7e0 - set 0,[hl] ; trigger Snorlax fight (handled by map script) + SetEvent EVENT_FIGHT_ROUTE16_SNORLAX ret .noSnorlaxToWakeUp ld hl,PlayedFluteNoEffectText jp PrintText .inBattle xor a - ld [wWhichTrade],a ; initialize variable that indicates if any pokemon were woken up to zero - ld b,~SLP & $FF + ld [wWereAnyMonsAsleep],a + ld b,~SLP & $ff ld hl,wPartyMon1Status call WakeUpEntireParty - ld a,[W_ISINBATTLE] + ld a,[wIsInBattle] dec a ; is it a trainer battle? jr z,.skipWakingUpEnemyParty ; if it's a trainer battle @@ -1638,7 +1764,7 @@ ItemUsePokeflute: ; e140 (3:6140) and b ; remove Sleep status ld [hl],a call LoadScreenTilesFromBuffer2 ; restore saved screen - ld a,[wWhichTrade] + ld a,[wWereAnyMonsAsleep] and a ; were any pokemon asleep before playing the flute? ld hl,PlayedFluteNoEffectText jp z,PrintText ; if no pokemon were asleep @@ -1651,7 +1777,7 @@ ItemUsePokeflute: ; e140 (3:6140) call WaitForSoundToFinish ; wait for sound to end callba Music_PokeFluteInBattle ; play in-battle pokeflute music .musicWaitLoop ; wait for music to finish playing - ld a,[wc02c] + ld a,[wChannelSoundIDs + Ch6] and a ; music off? jr nz,.musicWaitLoop .skipMusic @@ -1662,10 +1788,10 @@ ItemUsePokeflute: ; e140 (3:6140) ; INPUT: ; hl must point to status of first pokemon in party (player's or enemy's) ; b must equal ~SLP -; [wWhichTrade] should be initialized to 0 +; [wWereAnyMonsAsleep] should be initialized to 0 ; OUTPUT: -; [wWhichTrade]: set to 1 if any pokemon were asleep -WakeUpEntireParty: ; e1e5 (3:61e5) +; [wWereAnyMonsAsleep]: set to 1 if any pokemon were asleep +WakeUpEntireParty: ld de,44 ld c,6 .loop @@ -1674,7 +1800,7 @@ WakeUpEntireParty: ; e1e5 (3:61e5) and a,SLP ; is pokemon asleep? jr z,.notAsleep ld a,1 - ld [wWhichTrade],a ; indicate that a pokemon had to be woken up + ld [wWereAnyMonsAsleep],a ; indicate that a pokemon had to be woken up .notAsleep pop af and b ; remove Sleep status @@ -1687,7 +1813,7 @@ WakeUpEntireParty: ; e1e5 (3:61e5) ; Format: ; 00: Y ; 01: X -Route12SnorlaxFluteCoords: ; e1fd (3:61fd) +Route12SnorlaxFluteCoords: db 62,9 ; one space West of Snorlax db 61,10 ; one space North of Snorlax db 63,10 ; one space South of Snorlax @@ -1697,59 +1823,59 @@ Route12SnorlaxFluteCoords: ; e1fd (3:61fd) ; Format: ; 00: Y ; 01: X -Route16SnorlaxFluteCoords: ; e206 (3:6206) +Route16SnorlaxFluteCoords: db 10,27 ; one space East of Snorlax db 10,25 ; one space West of Snorlax db $ff ; terminator -PlayedFluteNoEffectText: ; e20b (3:620b) +PlayedFluteNoEffectText: TX_FAR _PlayedFluteNoEffectText db "@" -FluteWokeUpText: ; e210 (3:6210) +FluteWokeUpText: TX_FAR _FluteWokeUpText db "@" -PlayedFluteHadEffectText: ; e215 (3:6215) +PlayedFluteHadEffectText: TX_FAR _PlayedFluteHadEffectText - db $06 - db $08 - ld a,[W_ISINBATTLE] + TX_BLINK + TX_ASM + ld a,[wIsInBattle] and a jr nz,.done ; play out-of-battle pokeflute music ld a,$ff call PlaySound ; turn off music - ld a, (SFX_02_5e - SFX_Headers_02) / 3 - ld c, BANK(SFX_02_5e) - call PlayMusic ; play music + ld a, SFX_POKEFLUE + ld c, BANK(SFX_Pokeflute) + call PlayMusic .musicWaitLoop ; wait for music to finish playing - ld a,[wc028] - cp a,$b8 + ld a,[wChannelSoundIDs + Ch2] + cp a, SFX_POKEFLUE jr z,.musicWaitLoop call PlayDefaultMusic ; start playing normal music again .done jp TextScriptEnd ; end text -ItemUseCoinCase: ; e23a (3:623a) - ld a,[W_ISINBATTLE] +ItemUseCoinCase: + ld a,[wIsInBattle] and a jp nz,ItemUseNotTime ld hl,CoinCaseNumCoinsText jp PrintText -CoinCaseNumCoinsText: ; e247 (3:6247) +CoinCaseNumCoinsText: TX_FAR _CoinCaseNumCoinsText db "@" -OldRodCode: ; e24c (3:624c) +ItemUseOldRod: call FishingInit jp c, ItemUseNotTime - ld bc, (5 << 8) | MAGIKARP + lb bc, 5, MAGIKARP ld a, $1 ; set bite - jr RodResponse ; 0xe257 $34 + jr RodResponse -GoodRodCode: ; e259 (3:6259) +ItemUseGoodRod: call FishingInit jp c,ItemUseNotTime .RandomLoop @@ -1777,23 +1903,23 @@ GoodRodCode: ; e259 (3:6259) INCLUDE "data/good_rod.asm" -SuperRodCode: ; e283 (3:6283) +ItemUseSuperRod: call FishingInit jp c, ItemUseNotTime - call ReadSuperRodData ; 0xe8ea + call ReadSuperRodData ld a, e -RodResponse: ; e28d (3:628d) - ld [wWhichTrade], a +RodResponse: + ld [wRodResponse], a dec a ; is there a bite? jr nz, .next ; if yes, store level and species data ld a, 1 - ld [W_MOVEMISSED], a + ld [wMoveMissed], a ld a, b ; level - ld [W_CURENEMYLVL], a + ld [wCurEnemyLVL], a ld a, c ; species - ld [W_CUROPPONENT], a + ld [wCurOpponent], a .next ld hl, wWalkBikeSurfState @@ -1801,7 +1927,7 @@ RodResponse: ; e28d (3:628d) push af push hl ld [hl], 0 - callba Func_707b6 + callba FishingAnim pop hl pop af ld [hl], a @@ -1809,8 +1935,8 @@ RodResponse: ; e28d (3:628d) ; 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: ; e2b4 (3:62b4) - ld a,[W_ISINBATTLE] +FishingInit: + ld a,[wIsInBattle] and a jr z,.notInBattle scf ; can't fish during battle @@ -1824,8 +1950,8 @@ FishingInit: ; e2b4 (3:62b4) call ItemUseReloadOverworldData ld hl,ItemUseText00 call PrintText - ld a,(SFX_02_3e - SFX_Headers_02) / 3 - call PlaySound ; play sound + ld a,SFX_HEAL_AILMENT + call PlaySound ld c,80 call DelayFrames and a @@ -1834,11 +1960,11 @@ FishingInit: ; e2b4 (3:62b4) scf ; can't fish when surfing ret -ItemUseOaksParcel: ; e2de (3:62de) +ItemUseOaksParcel: jp ItemUseNotYoursToUse -ItemUseItemfinder: ; e2e1 (3:62e1) - ld a,[W_ISINBATTLE] +ItemUseItemfinder: + ld a,[wIsInBattle] and a jp nz,ItemUseNotTime call ItemUseReloadOverworldData @@ -1847,50 +1973,50 @@ ItemUseItemfinder: ; e2e1 (3:62e1) jr nc,.printText ; if no hidden items ld c,4 .loop - ld a,(SFX_02_4a - SFX_Headers_02) / 3 - call PlaySoundWaitForCurrent ; play sound - ld a,(SFX_02_5a - SFX_Headers_02) / 3 - call PlaySoundWaitForCurrent ; play sound + ld a,SFX_HEALING_MACHINE + call PlaySoundWaitForCurrent + ld a,SFX_PURCHASE + call PlaySoundWaitForCurrent dec c jr nz,.loop ld hl,ItemfinderFoundItemText .printText jp PrintText -ItemfinderFoundItemText: ; e30d (3:630d) +ItemfinderFoundItemText: TX_FAR _ItemfinderFoundItemText db "@" -ItemfinderFoundNothingText: ; e312 (3:6312) +ItemfinderFoundNothingText: TX_FAR _ItemfinderFoundNothingText db "@" -ItemUsePPUp: ; e317 (3:6317) - ld a,[W_ISINBATTLE] +ItemUsePPUp: + ld a,[wIsInBattle] and a jp nz,ItemUseNotTime -ItemUsePPRestore: ; e31e (3:631e) +ItemUsePPRestore: ld a,[wWhichPokemon] push af ld a,[wcf91] - ld [wWhichTrade],a + ld [wPPRestoreItem],a .chooseMon xor a ld [wUpdateSpritesEnabled],a - ld a,$01 ; item use party menu - ld [wd07d],a + ld a,USE_ITEM_PARTY_MENU + ld [wPartyMenuTypeOrMessageID],a call DisplayPartyMenu jr nc,.chooseMove jp .itemNotUsed .chooseMove - ld a,[wWhichTrade] + 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,[wWhichTrade] + 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 @@ -1903,7 +2029,7 @@ ItemUsePPRestore: ; e31e (3:631e) ld [wPlayerMoveListIndex],a jr nz,.chooseMon ld hl,wPartyMon1Moves - ld bc,44 + ld bc, wPartyMon2 - wPartyMon1 call GetSelectedMoveOffset push hl ld a,[hl] @@ -1911,11 +2037,11 @@ ItemUsePPRestore: ; e31e (3:631e) call GetMoveName call CopyStringToCF4B ; copy name to wcf4b pop hl - ld a,[wWhichTrade] + ld a,[wPPRestoreItem] cp a,ETHER jr nc,.useEther ; if Ether or Max Ether .usePPUp - ld bc,21 + ld bc,wPartyMon1PP - wPartyMon1Moves add hl,bc ld a,[hl] ; move PP cp a,3 << 6 ; have 3 PP Ups already been used? @@ -1936,7 +2062,7 @@ ItemUsePPRestore: ; e31e (3:631e) pop af ld [wWhichPokemon],a call GBPalWhiteOut - call GoPAL_SET_CF1C + call RunDefaultPaletteCommand jp RemoveUsedItem .afterRestoringPP ; after using a (Max) Ether/Elixir ld a,[wWhichPokemon] @@ -1945,13 +2071,13 @@ ItemUsePPRestore: ; e31e (3:631e) cp b ; is the pokemon whose PP was restored active in battle? jr nz,.skipUpdatingInBattleData ld hl,wPartyMon1PP - ld bc,44 + ld bc, wPartyMon2 - wPartyMon1 call AddNTimes ld de,wBattleMonPP ld bc,4 call CopyData ; copy party data to in-battle data .skipUpdatingInBattleData - ld a,(SFX_02_3e - SFX_Headers_02) / 3 + ld a,SFX_HEAL_AILMENT call PlaySound ld hl,PPRestoredText call PrintText @@ -1963,17 +2089,17 @@ ItemUsePPRestore: ; e31e (3:631e) ; 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 - ld [wcc49],a ; party pokemon + xor a ; PLAYER_PARTY_DATA + ld [wMonDataLocation],a call GetMaxPP ld hl,wPartyMon1Moves - ld bc,44 + ld bc, wPartyMon2 - wPartyMon1 call GetSelectedMoveOffset - ld bc,21 + ld bc, wPartyMon1PP - wPartyMon1Moves add hl,bc ; hl now points to move's PP - ld a,[wd11e] - ld b,a ; b = max PP - ld a,[wWhichTrade] + ld a,[wMaxPP] + ld b,a + ld a,[wPPRestoreItem] cp a,MAX_ETHER jr z,.fullyRestorePP ld a,[hl] ; move PP @@ -2005,7 +2131,7 @@ ItemUsePPRestore: ; e31e (3:631e) jr .storeNewAmount .useElixir ; decrement the item ID so that ELIXER becomes ETHER and MAX_ELIXER becomes MAX_ETHER - ld hl,wWhichTrade + ld hl,wPPRestoreItem dec [hl] dec [hl] xor a @@ -2017,7 +2143,7 @@ ItemUsePPRestore: ; e31e (3:631e) .elixirLoop push bc ld hl,wPartyMon1Moves - ld bc,44 + ld bc, wPartyMon2 - wPartyMon1 call GetSelectedMoveOffset ld a,[hl] and a ; does the current slot have a move? @@ -2040,38 +2166,38 @@ ItemUsePPRestore: ; e31e (3:631e) call ItemUseNoEffect .itemNotUsed call GBPalWhiteOut - call GoPAL_SET_CF1C + call RunDefaultPaletteCommand pop af xor a - ld [wcd6a],a ; item use failed + ld [wActionResultOrTookBattleTurn],a ; item use failed ret -RaisePPWhichTechniqueText: ; e45d (3:645d) +RaisePPWhichTechniqueText: TX_FAR _RaisePPWhichTechniqueText db "@" -RestorePPWhichTechniqueText: ; e462 (3:6462) +RestorePPWhichTechniqueText: TX_FAR _RestorePPWhichTechniqueText db "@" -PPMaxedOutText: ; e467 (3:6467) +PPMaxedOutText: TX_FAR _PPMaxedOutText db "@" -PPIncreasedText: ; e46c (3:646c) +PPIncreasedText: TX_FAR _PPIncreasedText db "@" -PPRestoredText: ; e471 (3:6471) +PPRestoredText: TX_FAR _PPRestoredText db "@" ; for items that can't be used from the Item menu -UnusableItem: ; e476 (3:6476) +UnusableItem: jp ItemUseNotTime -ItemUseTMHM: ; e479 (3:6479) - ld a,[W_ISINBATTLE] +ItemUseTMHM: + ld a,[wIsInBattle] and a jp nz,ItemUseNotTime ld a,[wcf91] @@ -2095,8 +2221,8 @@ ItemUseTMHM: ; e479 (3:6479) call PrintText ld hl,TeachMachineMoveText call PrintText - hlCoord 14, 7 - ld bc,$080f + coord hl, 14, 7 + lb bc, 8, 15 ld a,TWO_OPTION_MENU ld [wTextBoxID],a call DisplayTextBoxID ; yes/no menu @@ -2104,7 +2230,7 @@ ItemUseTMHM: ; e479 (3:6479) and a jr z,.useMachine ld a,2 - ld [wcd6a],a ; item not used + ld [wActionResultOrTookBattleTurn],a ; item not used ret .useMachine ld a,[wWhichPokemon] @@ -2113,16 +2239,16 @@ ItemUseTMHM: ; e479 (3:6479) push af .chooseMon ld hl,wcf4b - ld de,wd036 + ld de,wTempMoveNameBuffer ld bc,14 - call CopyData + call CopyData ; save the move name because DisplayPartyMenu will overwrite it ld a,$ff ld [wUpdateSpritesEnabled],a - ld a,$03 ; teach TM/HM party menu - ld [wd07d],a + ld a,TMHM_PARTY_MENU + ld [wPartyMenuTypeOrMessageID],a call DisplayPartyMenu push af - ld hl,wd036 + ld hl,wTempMoveNameBuffer ld de,wcf4b ld bc,14 call CopyData @@ -2133,7 +2259,7 @@ ItemUseTMHM: ; e479 (3:6479) pop af call GBPalWhiteOutWithDelay3 call ClearSprites - call GoPAL_SET_CF1C + call RunDefaultPaletteCommand jp LoadScreenTilesFromBuffer1 ; restore saved screen .checkIfAbleToLearnMove predef CanLearnTM ; check if the pokemon can learn the move @@ -2146,8 +2272,8 @@ ItemUseTMHM: ; e479 (3:6479) and a ; can the pokemon learn the move? jr nz,.checkIfAlreadyLearnedMove ; if the pokemon can't learn the move - ld a,(SFX_02_51 - SFX_Headers_02) / 3 - call PlaySoundWaitForCurrent ; play sound + ld a,SFX_DENIED + call PlaySoundWaitForCurrent ld hl,MonCannotLearnMachineMoveText call PrintText jr .chooseMon @@ -2167,53 +2293,53 @@ ItemUseTMHM: ; e479 (3:6479) ret c jp RemoveUsedItem -BootedUpTMText: ; e54f (3:654f) +BootedUpTMText: TX_FAR _BootedUpTMText db "@" -BootedUpHMText: ; e554 (3:6554) +BootedUpHMText: TX_FAR _BootedUpHMText db "@" -TeachMachineMoveText: ; e559 (3:6559) +TeachMachineMoveText: TX_FAR _TeachMachineMoveText db "@" -MonCannotLearnMachineMoveText: ; e55e (3:655e) +MonCannotLearnMachineMoveText: TX_FAR _MonCannotLearnMachineMoveText db "@" -PrintItemUseTextAndRemoveItem: ; e563 (3:6563) +PrintItemUseTextAndRemoveItem: ld hl,ItemUseText00 call PrintText - ld a,(SFX_02_3e - SFX_Headers_02) / 3 - call PlaySound ; play sound + ld a,SFX_HEAL_AILMENT + call PlaySound call WaitForTextScrollButtonPress ; wait for button press -RemoveUsedItem: ; e571 (3:6571) +RemoveUsedItem: ld hl,wNumBagItems ld a,1 ; one item - ld [wcf96],a ; store quantity + ld [wItemQuantity],a jp RemoveItemFromInventory -ItemUseNoEffect: ; e57c (3:657c) +ItemUseNoEffect: ld hl,ItemUseNoEffectText jr ItemUseFailed -ItemUseNotTime: ; e581 (3:6581) +ItemUseNotTime: ld hl,ItemUseNotTimeText jr ItemUseFailed -ItemUseNotYoursToUse: ; e586 (3:6586) +ItemUseNotYoursToUse: ld hl,ItemUseNotYoursToUseText jr ItemUseFailed -ThrowBallAtTrainerMon: ; e58b (3:658b) - call GoPAL_SET_CF1C +ThrowBallAtTrainerMon: + call RunDefaultPaletteCommand call LoadScreenTilesFromBuffer1 ; restore saved screen call Delay3 ld a,TOSS_ANIM - ld [W_ANIMATIONID],a + ld [wAnimationID],a predef MoveAnimation ; do animation ld hl,ThrowBallAtTrainerMonText1 call PrintText @@ -2221,69 +2347,69 @@ ThrowBallAtTrainerMon: ; e58b (3:658b) call PrintText jr RemoveUsedItem -NoCyclingAllowedHere: ; e5ac (3:65ac) +NoCyclingAllowedHere: ld hl,NoCyclingAllowedHereText jr ItemUseFailed -BoxFullCannotThrowBall: ; e5b1 (3:65b1) +BoxFullCannotThrowBall: ld hl,BoxFullCannotThrowBallText jr ItemUseFailed -SurfingAttemptFailed: ; e5b6 (3:65b6) +SurfingAttemptFailed: ld hl,NoSurfingHereText -ItemUseFailed: ; e5b9 (3:65b9) +ItemUseFailed: xor a - ld [wcd6a],a ; item use failed + ld [wActionResultOrTookBattleTurn],a ; item use failed jp PrintText -ItemUseNotTimeText: ; e5c0 (3:65c0) +ItemUseNotTimeText: TX_FAR _ItemUseNotTimeText db "@" -ItemUseNotYoursToUseText: ; e5c5 (3:65c5) +ItemUseNotYoursToUseText: TX_FAR _ItemUseNotYoursToUseText db "@" -ItemUseNoEffectText: ; e5ca (3:65ca) +ItemUseNoEffectText: TX_FAR _ItemUseNoEffectText db "@" -ThrowBallAtTrainerMonText1: ; e5cf (3:65cf) +ThrowBallAtTrainerMonText1: TX_FAR _ThrowBallAtTrainerMonText1 db "@" -ThrowBallAtTrainerMonText2: ; e5d4 (3:65d4) +ThrowBallAtTrainerMonText2: TX_FAR _ThrowBallAtTrainerMonText2 db "@" -NoCyclingAllowedHereText: ; e5d9 (3:65d9) +NoCyclingAllowedHereText: TX_FAR _NoCyclingAllowedHereText db "@" -NoSurfingHereText: ; e5de (3:65de) +NoSurfingHereText: TX_FAR _NoSurfingHereText db "@" -BoxFullCannotThrowBallText: ; e5e3 (3:65e3) +BoxFullCannotThrowBallText: TX_FAR _BoxFullCannotThrowBallText db "@" -ItemUseText00: ; e5e8 (3:65e8) +ItemUseText00: TX_FAR _ItemUseText001 - db $05 + TX_LINE TX_FAR _ItemUseText002 db "@" -GotOnBicycleText: ; e5f2 (3:65f2) +GotOnBicycleText: TX_FAR _GotOnBicycleText1 - db $05 + TX_LINE TX_FAR _GotOnBicycleText2 db "@" -GotOffBicycleText: ; e5fc (3:65fc) +GotOffBicycleText: TX_FAR _GotOffBicycleText1 - db $05 + TX_LINE TX_FAR _GotOffBicycleText2 db "@" @@ -2291,23 +2417,20 @@ GotOffBicycleText: ; e5fc (3:65fc) ; also, when a PP Up is used, it increases the current PP by one PP Up bonus ; INPUT: ; [wWhichPokemon] = index of pokemon in party -; [wd11e] = mode -; 0: Pokemon Center healing -; 1: using a PP Up ; [wCurrentMenuItem] = index of move (when using a PP Up) -RestoreBonusPP: ; e606 (3:6606) +RestoreBonusPP: ld hl,wPartyMon1Moves - ld bc,44 + ld bc, wPartyMon2 - wPartyMon1 ld a,[wWhichPokemon] call AddNTimes push hl - ld de,wcd78 - 1 - predef LoadMovePPs ; loads the normal max PP of each of the pokemon's moves to wcd78 + ld de,wNormalMaxPPList - 1 + predef LoadMovePPs ; loads the normal max PP of each of the pokemon's moves to wNormalMaxPPList pop hl - ld c,21 + ld c, wPartyMon1PP - wPartyMon1Moves ld b,0 add hl,bc ; hl now points to move 1 PP - ld de,wcd78 + ld de,wNormalMaxPPList ld b,0 ; initialize move counter to zero ; loop through the pokemon's moves .loop @@ -2315,7 +2438,7 @@ RestoreBonusPP: ; e606 (3:6606) ld a,b cp a,5 ; reached the end of the pokemon's moves? ret z ; if so, return - ld a,[wd11e] + ld a,[wUsingPPUp] dec a ; using a PP Up? jr nz,.skipMenuItemIDCheck ; if using a PP Up, check if this is the move it's being used on @@ -2337,9 +2460,7 @@ RestoreBonusPP: ; e606 (3:6606) ; INPUT: ; [de] = normal max PP ; [hl] = move PP -; [wd11e] = max number of times to add bonus -; set to 1 when using a PP Up, set to 255 otherwise -AddBonusPP: ; e642 (3:6642) +AddBonusPP: push bc ld a,[de] ; normal max PP of move ld [H_DIVIDEND + 3],a @@ -2366,9 +2487,9 @@ AddBonusPP: ; e642 (3:6642) .addAmount add b ld b,a - ld a,[wd11e] - dec a - jr z,.done + ld a,[wUsingPPUp] + dec a ; is the player using a PP Up right now? + jr z,.done ; if so, only add the bonus once dec c jr nz,.loop .done @@ -2379,7 +2500,7 @@ AddBonusPP: ; e642 (3:6642) ; gets max PP of a pokemon's move (including PP from PP Ups) ; INPUT: ; [wWhichPokemon] = index of pokemon within party/box -; [wcc49] = pokemon source +; [wMonDataLocation] = pokemon source ; 00: player's party ; 01: enemy's party ; 02: current box @@ -2387,9 +2508,9 @@ AddBonusPP: ; e642 (3:6642) ; 04: player's in-battle pokemon ; [wCurrentMenuItem] = move index ; OUTPUT: -; [wd11e] = max PP -GetMaxPP: ; e677 (3:6677) - ld a,[wcc49] +; [wMaxPP] = max PP +GetMaxPP: + ld a,[wMonDataLocation] and a ld hl,wPartyMon1Moves ld bc,wPartyMon2 - wPartyMon1 @@ -2415,21 +2536,21 @@ GetMaxPP: ; e677 (3:6677) dec a push hl ld hl,Moves - ld bc,6 + ld bc,MoveEnd - Moves call AddNTimes ld de,wcd6d ld a,BANK(Moves) call FarCopyData - ld de,wcd72 + 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,21 ; PP offset if not player's in-battle pokemon data - ld a,[wcc49] + 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,17 ; PP offset if player's in-battle pokemon data + ld bc,wBattleMonPP - wBattleMonMoves ; PP offset if player's in-battle pokemon data .addPPOffset add hl,bc ld a,[hl] ; a = current PP @@ -2440,19 +2561,19 @@ GetMaxPP: ; e677 (3:6677) ld l,e inc hl ; hl = wcd73 ld [hl],a - xor a - ld [wd11e],a ; no limit on PP Up amount + xor a ; add the bonus for the existing PP Up count + ld [wUsingPPUp],a call AddBonusPP ; add bonus PP from PP Ups ld a,[hl] and a,%00111111 ; mask out the PP Up count - ld [wd11e],a ; store max PP + ld [wMaxPP],a ; store max PP ret -GetSelectedMoveOffset: ; e6e3 (3:66e3) +GetSelectedMoveOffset: ld a,[wWhichPokemon] call AddNTimes -GetSelectedMoveOffset2: ; e6e9 (3:66e9) +GetSelectedMoveOffset2: ld a,[wCurrentMenuItem] ld c,a ld b,0 @@ -2464,10 +2585,10 @@ GetSelectedMoveOffset2: ; e6e9 (3:66e9) ; hl = address of inventory (either wNumBagItems or wNumBoxItems) ; [wcf91] = item ID ; [wWhichPokemon] = index of item within inventory -; [wcf96] = quantity to toss +; [wItemQuantity] = quantity to toss ; OUTPUT: ; clears carry flag if the item is tossed, sets carry flag if not -TossItem_: ; e6f1 (3:66f1) +TossItem_: push hl ld a,[wcf91] call IsItemHM @@ -2475,7 +2596,7 @@ TossItem_: ; e6f1 (3:66f1) jr c,.tooImportantToToss push hl call IsKeyItem_ - ld a,[wd124] + ld a,[wIsKeyItem] pop hl and a jr nz,.tooImportantToToss @@ -2486,16 +2607,16 @@ TossItem_: ; e6f1 (3:66f1) call CopyStringToCF4B ; copy name to wcf4b ld hl,IsItOKToTossItemText call PrintText - hlCoord 14, 7 - ld bc,$080f + coord hl, 14, 7 + lb bc, 8, 15 ld a,TWO_OPTION_MENU ld [wTextBoxID],a call DisplayTextBoxID ; yes/no menu - ld a,[wd12e] - cp a,2 + ld a,[wMenuExitMethod] + cp a,CHOSE_SECOND_ITEM pop hl scf - ret z + ret z ; return if the player chose No ; if the player chose Yes push hl ld a,[wWhichPokemon] @@ -2517,15 +2638,15 @@ TossItem_: ; e6f1 (3:66f1) scf ret -ThrewAwayItemText: ; e755 (3:6755) +ThrewAwayItemText: TX_FAR _ThrewAwayItemText db "@" -IsItOKToTossItemText: ; e75a (3:675a) +IsItOKToTossItemText: TX_FAR _IsItOKToTossItemText db "@" -TooImportantToTossText: ; e75f (3:675f) +TooImportantToTossText: TX_FAR _TooImportantToTossText db "@" @@ -2533,27 +2654,27 @@ TooImportantToTossText: ; e75f (3:675f) ; INPUT: ; [wcf91] = item ID ; OUTPUT: -; [wd124] = result +; [wIsKeyItem] = result ; 00: item is not key item ; 01: item is key item -IsKeyItem_: ; e764 (3:6764) +IsKeyItem_: ld a,$01 - ld [wd124],a + 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,wHPBarMaxHP + ld de,wBuffer ld bc,15 ; only 11 bytes are actually used call CopyData pop af dec a ld c,a - ld hl,wHPBarMaxHP - ld b,$02 ; test bit - predef FlagActionPredef ; bitfield operation function + ld hl,wBuffer + ld b,FLAG_TEST + predef FlagActionPredef ld a,c and a ret nz @@ -2562,13 +2683,13 @@ IsKeyItem_: ; e764 (3:6764) call IsItemHM ret c xor a - ld [wd124],a + ld [wIsKeyItem],a ret INCLUDE "data/key_items.asm" -SendNewMonToBox: ; e7a4 (3:67a4) - ld de, W_NUMINBOX ; wda80 +SendNewMonToBox: + ld de, wNumInBox ld a, [de] inc a ld [de], a @@ -2586,74 +2707,74 @@ SendNewMonToBox: ; e7a4 (3:67a4) jr nz, .asm_e7b1 call GetMonHeader ld hl, wBoxMonOT - ld bc, $b - ld a, [W_NUMINBOX] ; wda80 + ld bc, NAME_LENGTH + ld a, [wNumInBox] dec a jr z, .asm_e7ee dec a call AddNTimes push hl - ld bc, $b + ld bc, NAME_LENGTH add hl, bc ld d, h ld e, l pop hl - ld a, [W_NUMINBOX] ; wda80 + ld a, [wNumInBox] dec a ld b, a .asm_e7db push bc push hl - ld bc, $b + ld bc, NAME_LENGTH call CopyData pop hl ld d, h ld e, l - ld bc, $fff5 + ld bc, -NAME_LENGTH add hl, bc pop bc dec b jr nz, .asm_e7db .asm_e7ee - ld hl, wPlayerName ; wd158 + ld hl, wPlayerName ld de, wBoxMonOT - ld bc, $b + ld bc, NAME_LENGTH call CopyData - ld a, [W_NUMINBOX] ; wda80 + ld a, [wNumInBox] dec a jr z, .asm_e82a ld hl, wBoxMonNicks - ld bc, $b + ld bc, NAME_LENGTH dec a call AddNTimes push hl - ld bc, $b + ld bc, NAME_LENGTH add hl, bc ld d, h ld e, l pop hl - ld a, [W_NUMINBOX] ; wda80 + ld a, [wNumInBox] dec a ld b, a .asm_e817 push bc push hl - ld bc, $b + ld bc, NAME_LENGTH call CopyData pop hl ld d, h ld e, l - ld bc, $fff5 + ld bc, -NAME_LENGTH add hl, bc pop bc dec b jr nz, .asm_e817 .asm_e82a ld hl, wBoxMonNicks - ld a, $2 - ld [wd07d], a + ld a, NAME_MON_SCREEN + ld [wNamingScreenType], a predef AskName - ld a, [W_NUMINBOX] ; wda80 + ld a, [wNumInBox] dec a jr z, .asm_e867 ld hl, wBoxMons @@ -2666,7 +2787,7 @@ SendNewMonToBox: ; e7a4 (3:67a4) ld d, h ld e, l pop hl - ld a, [W_NUMINBOX] ; wda80 + ld a, [wNumInBox] dec a ld b, a .asm_e854 @@ -2677,19 +2798,19 @@ SendNewMonToBox: ; e7a4 (3:67a4) pop hl ld d, h ld e, l - ld bc, $ffdf + ld bc, wBoxMon1 - wBoxMon2 add hl, bc pop bc dec b jr nz, .asm_e854 .asm_e867 - ld a, [wEnemyMonLevel] ; wEnemyMonLevel + ld a, [wEnemyMonLevel] ld [wEnemyMonBoxLevel], a ld hl, wEnemyMon ld de, wBoxMon1 - ld bc, $c + ld bc, wEnemyMonDVs - wEnemyMon call CopyData - ld hl, wPlayerID ; wPlayerID + ld hl, wPlayerID ld a, [hli] ld [de], a inc de @@ -2697,21 +2818,21 @@ SendNewMonToBox: ; e7a4 (3:67a4) ld [de], a inc de push de - ld a, [W_CURENEMYLVL] ; W_CURENEMYLVL + ld a, [wCurEnemyLVL] ld d, a callab CalcExperience pop de - ld a, [H_NUMTOPRINT] ; $ff96 (aliases: H_MULTIPLICAND) + ld a, [hExperience] ld [de], a inc de - ld a, [$ff97] + ld a, [hExperience + 1] ld [de], a inc de - ld a, [$ff98] + ld a, [hExperience + 2] ld [de], a inc de xor a - ld b, $a + ld b, NUM_STATS * 2 .asm_e89f ld [de], a inc de @@ -2723,8 +2844,8 @@ SendNewMonToBox: ; e7a4 (3:67a4) inc de ld a, [hli] ld [de], a - ld hl, wEnemyMonPP ; wcffe - ld b, $4 + ld hl, wEnemyMonPP + ld b, NUM_MOVES .asm_e8b1 ld a, [hli] inc de @@ -2736,13 +2857,13 @@ SendNewMonToBox: ; e7a4 (3:67a4) ; checks if the tile in front of the player is a shore or water tile ; used for surfing and fishing ; unsets carry if it is, sets carry if not -IsNextTileShoreOrWater: ; e8b8 (3:68b8) - ld a, [W_CURMAPTILESET] +IsNextTileShoreOrWater: + ld a, [wCurMapTileset] ld hl, WaterTilesets ld de,1 call IsInArray jr nc, .notShoreOrWater - ld a, [W_CURMAPTILESET] + ld a, [wCurMapTileset] cp SHIP_PORT ; Vermilion Dock tileset ld a, [wTileInFrontOfPlayer] ; tile in front of player jr z, .skipShoreTiles ; if it's the Vermilion Dock tileset @@ -2761,15 +2882,15 @@ IsNextTileShoreOrWater: ; e8b8 (3:68b8) ret ; tilesets with water -WaterTilesets: ; e8e0 (3:68e0) +WaterTilesets: db OVERWORLD, FOREST, DOJO, GYM, SHIP, SHIP_PORT, CAVERN, FACILITY, PLATEAU db $ff ; terminator -ReadSuperRodData: ; e8ea (3:68ea) +ReadSuperRodData: ; return e = 2 if no fish on this map ; return e = 1 if a bite, bc = level,species ; return e = 0 if no bite - ld a, [W_CURMAP] + ld a, [wCurMap] ld de, 3 ; each fishing group is three bytes wide ld hl, SuperRodData call IsInArray @@ -2777,7 +2898,7 @@ ReadSuperRodData: ; e8ea (3:68ea) ld e, $2 ; $2 if no fishing groups found ret -.ReadFishingGroup ; 0xe8f6 +.ReadFishingGroup ; hl points to the fishing group entry in the index inc hl ; skip map id @@ -2790,7 +2911,7 @@ ReadSuperRodData: ; e8ea (3:68ea) inc hl ; point to data ld e, $0 ; no bite yet -.RandomLoop ; 0xe90c +.RandomLoop call Random srl a ret c ; 50% chance of no battle @@ -2814,13 +2935,13 @@ INCLUDE "data/super_rod.asm" ; reloads map view and processes sprite data ; for items that cause the overworld to be displayed -ItemUseReloadOverworldData: ; e9c5 (3:69c5) +ItemUseReloadOverworldData: call LoadCurrentMapView jp UpdateSprites ; creates a list at wBuffer of maps where the mon in [wd11e] can be found. ; this is used by the pokedex to display locations the mon can be found on the map. -FindWildLocationsOfMon: ; e9cb (3:69cb) +FindWildLocationsOfMon: ld hl, WildDataPointers ld de, wBuffer ld c, $0 @@ -2849,7 +2970,7 @@ FindWildLocationsOfMon: ; e9cb (3:69cb) ld [de], a ret -CheckMapForMon: ; e9f0 (3:69f0) +CheckMapForMon: inc hl ld b, $a .loop |