diff options
Diffstat (limited to 'engine/battle')
-rwxr-xr-x | engine/battle/animations.asm | 794 | ||||
-rw-r--r-- | engine/battle/bank3d_battle.asm | 111 | ||||
-rw-r--r-- | engine/battle/battle_transitions.asm | 263 | ||||
-rw-r--r-- | engine/battle/common_text.asm | 110 | ||||
-rwxr-xr-x | engine/battle/core.asm | 2840 | ||||
-rw-r--r-- | engine/battle/decrement_pp.asm | 2 | ||||
-rw-r--r-- | engine/battle/display_effectiveness.asm | 8 | ||||
-rw-r--r-- | engine/battle/draw_hud_pokeball_gfx.asm | 8 | ||||
-rw-r--r-- | engine/battle/effects.asm | 1551 | ||||
-rwxr-xr-x | engine/battle/end_of_battle.asm | 10 | ||||
-rw-r--r-- | engine/battle/experience.asm | 64 | ||||
-rw-r--r-- | engine/battle/get_trainer_name.asm | 8 | ||||
-rw-r--r-- | engine/battle/ghost_marowak_anim.asm | 20 | ||||
-rw-r--r-- | engine/battle/init_battle_variables.asm | 4 | ||||
-rw-r--r-- | engine/battle/link_battle_versus_text.asm | 10 | ||||
-rwxr-xr-x | engine/battle/misc.asm (renamed from engine/battle/bank_e_misc.asm) | 0 | ||||
-rw-r--r-- | engine/battle/move_effects/conversion.asm (renamed from engine/battle/moveEffects/conversion_effect.asm) | 6 | ||||
-rw-r--r-- | engine/battle/move_effects/drain_hp.asm (renamed from engine/battle/moveEffects/drain_hp_effect.asm) | 20 | ||||
-rw-r--r-- | engine/battle/move_effects/focus_energy.asm (renamed from engine/battle/moveEffects/focus_energy_effect.asm) | 12 | ||||
-rw-r--r-- | engine/battle/move_effects/haze.asm (renamed from engine/battle/moveEffects/haze_effect.asm) | 6 | ||||
-rw-r--r-- | engine/battle/move_effects/heal.asm (renamed from engine/battle/moveEffects/heal_effect.asm) | 22 | ||||
-rw-r--r-- | engine/battle/move_effects/leech_seed.asm (renamed from engine/battle/moveEffects/leech_seed_effect.asm) | 14 | ||||
-rw-r--r-- | engine/battle/move_effects/mist.asm (renamed from engine/battle/moveEffects/mist_effect.asm) | 10 | ||||
-rw-r--r-- | engine/battle/move_effects/one_hit_ko.asm (renamed from engine/battle/moveEffects/one_hit_ko_effect.asm) | 2 | ||||
-rw-r--r-- | engine/battle/move_effects/paralyze.asm (renamed from engine/battle/moveEffects/paralyze_effect.asm) | 14 | ||||
-rw-r--r-- | engine/battle/move_effects/pay_day.asm (renamed from engine/battle/moveEffects/pay_day_effect.asm) | 28 | ||||
-rw-r--r-- | engine/battle/move_effects/recoil.asm (renamed from engine/battle/moveEffects/recoil_effect.asm) | 12 | ||||
-rw-r--r-- | engine/battle/move_effects/reflect_light_screen.asm (renamed from engine/battle/moveEffects/reflect_light_screen_effect.asm) | 10 | ||||
-rw-r--r-- | engine/battle/move_effects/substitute.asm (renamed from engine/battle/moveEffects/substitute_effect.asm) | 18 | ||||
-rw-r--r-- | engine/battle/move_effects/transform.asm (renamed from engine/battle/moveEffects/transform_effect.asm) | 12 | ||||
-rw-r--r-- | engine/battle/print_type.asm | 2 | ||||
-rwxr-xr-x | engine/battle/read_trainer_party.asm | 2 | ||||
-rwxr-xr-x | engine/battle/safari_zone.asm | 8 | ||||
-rw-r--r-- | engine/battle/save_trainer_name.asm | 95 | ||||
-rw-r--r-- | engine/battle/scale_sprites.asm | 30 | ||||
-rw-r--r-- | engine/battle/scroll_draw_trainer_pic.asm | 4 | ||||
-rw-r--r-- | engine/battle/trainer_ai.asm | 157 | ||||
-rwxr-xr-x | engine/battle/trainer_pic_money_pointers.asm | 143 | ||||
-rw-r--r-- | engine/battle/unused_stats_functions.asm | 4 | ||||
-rw-r--r-- | engine/battle/wild_encounters.asm | 32 |
40 files changed, 2713 insertions, 3753 deletions
diff --git a/engine/battle/animations.asm b/engine/battle/animations.asm index de1e67b9..4508dbaa 100755 --- a/engine/battle/animations.asm +++ b/engine/battle/animations.asm @@ -19,11 +19,11 @@ DrawFrameBlock: ld [wdef5], a ld a, [wSubAnimTransform] dec a - jr z, .flipHorizontalAndVertical ; 1 + jr z, .flipHorizontalAndVertical ; SUBANIMTYPE_HVFLIP dec a - jp z, .flipHorizontalTranslateDown ; 2 + jp z, .flipHorizontalTranslateDown ; SUBANIMTYPE_HFLIP dec a - jr z, .flipBaseCoords ; 3 + jr z, .flipBaseCoords ; SUBANIMTYPE_COORDFLIP .noTransformation ld a, [wBaseCoordY] add [hl] @@ -45,7 +45,7 @@ DrawFrameBlock: ld b, a ld a, 168 sub b ; flip X base coordinate -.finishCopying ; finish copying values to OAM (when [wSubAnimTransform] not 1 or 2) +.finishCopying ; finish copying values to OAM (when subanimation not transformed) add [hl] ; X offset ld [de], a ; store X cp 88 @@ -159,15 +159,15 @@ DrawFrameBlock: jp nz, .loop ; go back up if there are more tiles to draw .afterDrawingTiles ld a, [wFBMode] - cp 2 + cp FRAMEBLOCKMODE_02 jr z, .advanceFrameBlockDestAddr; skip delay and don't clean OAM buffer ld a, [wSubAnimFrameDelay] ld c, a call DelayFrames ld a, [wFBMode] - cp 3 + cp FRAMEBLOCKMODE_03 jr z, .advanceFrameBlockDestAddr ; skip cleaning OAM buffer - cp 4 + cp FRAMEBLOCKMODE_04 jr z, .done ; skip cleaning OAM buffer and don't advance the frame block destination address ld a, [wAnimationID] cp GROWL @@ -190,7 +190,7 @@ DrawFrameBlock: PlayAnimation: xor a - ld [$FF8B], a ; it looks like nothing reads this + ldh [hROMBankTemp], a ; it looks like nothing reads this ld [wSubAnimTransform], a ld a, [wAnimationID] ; get animation number dec a @@ -204,9 +204,9 @@ PlayAnimation: ld l, a .animationLoop ld a, [hli] - cp $FF + cp -1 jr z, .AnimationOver - cp $C0 ; is this subanimation or a special effect? + cp FIRST_SE_ID ; is this subanimation or a special effect? jr c, .playSubanimation .doSpecialEffect ld c, a @@ -221,7 +221,7 @@ PlayAnimation: jr .searchSpecialEffectTableLoop .foundMatch ld a, [hli] - cp $FF ; is there a sound to play? + cp NO_MOVE - 1 ; is there a sound to play? jr z, .skipPlayingSound ld [wAnimSoundID], a ; store sound push hl @@ -268,16 +268,16 @@ PlayAnimation: ld l, c ld h, b push hl - ld a, [rOBP0] + ldh a, [rOBP0] push af ld a, [wAnimPalette] - ld [rOBP0], a + ldh [rOBP0], a call UpdateGBCPal_OBP0 call LoadAnimationTileset call LoadSubanimation call PlaySubanimation pop af - ld [rOBP0], a + ldh [rOBP0], a call UpdateGBCPal_OBP0 .nextAnimationCommand pop hl @@ -296,11 +296,11 @@ LoadSubanimation: ld d, a ; de = address of subanimation ld a, [de] ld b, a - and 31 + and %00011111 ld [wSubAnimCounter], a ; number of frame blocks ld a, b and %11100000 - cp 5 << 5 ; is subanimation type 5? + cp SUBANIMTYPE_ENEMY << 5 jr nz, .isNotType5 .isType5 call GetSubanimationTransform2 @@ -312,7 +312,7 @@ LoadSubanimation: srl a swap a ld [wSubAnimTransform], a - cp 4 ; is the animation reversed? + cp SUBANIMTYPE_REVERSE ld hl, 0 jr nz, .storeSubentryAddr ; if the animation is reversed, then place the initial subentry address at the end of the list of subentries @@ -332,27 +332,27 @@ LoadSubanimation: ld [wSubAnimSubEntryAddr + 1], a ret -; called if the subanimation type is not 5 -; sets the transform to 0 (i.e. no transform) if it's the player's turn +; called if the subanimation type is not SUBANIMTYPE_ENEMY +; sets the transform to SUBANIMTYPE_NORMAL if it's the player's turn ; sets the transform to the subanimation type if it's the enemy's turn GetSubanimationTransform1: ld b, a - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a ld a, b ret nz - xor a + xor a ; SUBANIMTYPE_NORMAL << 5 ret -; called if the subanimation type is 5 -; sets the transform to 2 (i.e. horizontal and vertical flip) if it's the player's turn -; sets the transform to 0 (i.e. no transform) if it's the enemy's turn +; called if the subanimation type is SUBANIMTYPE_ENEMY +; sets the transform to SUBANIMTYPE_HFLIP if it's the player's turn +; sets the transform to SUBANIMTYPE_NORMAL if it's the enemy's turn GetSubanimationTransform2: - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a - ld a, 2 << 5 + ld a, SUBANIMTYPE_HFLIP << 5 ret z - xor a + xor a ; SUBANIMTYPE_NORMAL << 5 ret ; loads tile patterns for battle animations @@ -370,33 +370,33 @@ LoadAnimationTileset: ld e, a ld a, [hl] ld d, a ; de = address of tileset - ld hl, vSprites + $310 + ld hl, vSprites tile $31 ld b, BANK(AnimationTileset1) ; ROM bank ld a, [wTempTilesetNumTiles] ld c, a ; number of tiles jp CopyVideoData ; load tileset -AnimationTilesetPointers: - db 79 ; number of tiles - dw AnimationTileset1 - db $FF - - db 79 ; number of tiles - dw AnimationTileset2 - db $FF +anim_tileset: MACRO + db \1 + dw \2 + db -1 ; padding +ENDM - db 64 ; number of tiles - dw AnimationTileset1 - db $FF +AnimationTilesetPointers: + ; number of tiles, gfx pointer + anim_tileset 79, AnimationTileset1 + anim_tileset 79, AnimationTileset2 + anim_tileset 64, AnimationTileset1 AnimationTileset1: - INCBIN "gfx/attack_anim_1.2bpp" + INCBIN "gfx/battle/attack_anim_1.2bpp" AnimationTileset2: - INCBIN "gfx/attack_anim_2.2bpp" + INCBIN "gfx/battle/attack_anim_2.2bpp" SlotMachineTiles2: - INCBIN "gfx/slotmachine2.2bpp" + INCBIN "gfx/slots/slots_2.2bpp" +SlotMachineTiles2End: MoveAnimation: push hl @@ -435,7 +435,7 @@ MoveAnimation: ld [wSubAnimSubEntryAddr], a ld [wUnusedD09B], a ld [wSubAnimTransform], a - dec a + dec a ; NO_MOVE - 1 ld [wAnimSoundID], a pop af pop bc @@ -445,11 +445,11 @@ MoveAnimation: ShareMoveAnimations: ; some moves just reuse animations from status conditions - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a ret z - ; opponent’s turn + ; opponent's turn ld a, [wAnimationID] @@ -484,10 +484,10 @@ PlayApplyingAttackAnimation: jp hl AnimationTypePointerTable: - dw ShakeScreenVertically ; enemy mon has used a damaging move without a side effect + dw ShakeScreenVertically ; enemy mon has used a damaging move without a side effect dw ShakeScreenHorizontallyHeavy ; enemy mon has used a damaging move with a side effect - dw ShakeScreenHorizontallySlow ; enemy mon has used a non-damaging move - dw BlinkEnemyMonSprite ; player mon has used a damaging move without a side effect + dw ShakeScreenHorizontallySlow ; enemy mon has used a non-damaging move + dw BlinkEnemyMonSprite ; player mon has used a damaging move without a side effect dw ShakeScreenHorizontallyLight ; player mon has used a damaging move with a side effect dw ShakeScreenHorizontallySlow2 ; player mon has used a non-damaging move @@ -521,18 +521,18 @@ AnimationShakeScreenHorizontallySlow: push bc push bc .loop1 - ld a, [rWX] + ldh a, [rWX] inc a - ld [rWX], a + ldh [rWX], a ld c, 2 call DelayFrames dec b jr nz, .loop1 pop bc .loop2 - ld a, [rWX] + ldh a, [rWX] dec a - ld [rWX], a + ldh [rWX], a ld c, 2 call DelayFrames dec b @@ -558,18 +558,18 @@ SetAnimationPalette: ld b, $f0 .next ld a, b - ld [rOBP0], a + ldh [rOBP0], a ld a, $6c - ld [rOBP1], a + ldh [rOBP1], a call UpdateGBCPal_OBP0 call UpdateGBCPal_OBP1 ret .notSGB ld a, $e4 ld [wAnimPalette], a - ld [rOBP0], a + ldh [rOBP0], a ld a, $6c - ld [rOBP1], a + ldh [rOBP1], a call UpdateGBCPal_OBP0 call UpdateGBCPal_OBP1 ret @@ -577,13 +577,13 @@ SetAnimationPalette: Func_78e98: call SaveScreenTilesToBuffer2 xor a - ld [H_AUTOBGTRANSFERENABLED], a + ldh [hAutoBGTransferEnabled], a call ClearScreen ld h, vBGMap0 / $100 call WriteLowerByteOfBGMapAndEnableBGTransfer call Delay3 xor a - ld [H_AUTOBGTRANSFERENABLED], a + ldh [hAutoBGTransferEnabled], a call LoadScreenTilesFromBuffer2 ld h, vBGMap1 / $100 @@ -591,12 +591,12 @@ WriteLowerByteOfBGMapAndEnableBGTransfer: ld l, vBGMap0 & $ff call BattleAnimCopyTileMapToVRAM ld a, $1 - ld [H_AUTOBGTRANSFERENABLED], a + ldh [hAutoBGTransferEnabled], a ret PlaySubanimation: ld a, [wAnimSoundID] - cp $FF + cp NO_MOVE - 1 jr z, .skipPlayingSound call GetMoveSound call PlaySound @@ -648,7 +648,7 @@ PlaySubanimation: ld a, [wSubAnimSubEntryAddr] ld l, a ld a, [wSubAnimTransform] - cp 4 ; is the animation reversed? + cp SUBANIMTYPE_REVERSE ld bc, 3 jr nz, .nextSubanimationSubentry ld bc, -3 @@ -697,90 +697,16 @@ DoSpecialEffectByAnimationId: pop hl ret -; Format: Animation ID (1 byte), Address (2 bytes) -AnimationIdSpecialEffects: - db MEGA_PUNCH - dw AnimationFlashScreen - - db GUILLOTINE - dw AnimationFlashScreen - - db MEGA_KICK - dw AnimationFlashScreen - - db HEADBUTT - dw AnimationFlashScreen - - db TAIL_WHIP - dw TailWhipAnimationUnused - - db GROWL - dw DoGrowlSpecialEffects - - db DISABLE - dw AnimationFlashScreen - - db BLIZZARD - dw DoBlizzardSpecialEffects - - db BUBBLEBEAM - dw AnimationFlashScreen - - db HYPER_BEAM - dw FlashScreenEveryFourFrameBlocks - - db THUNDERBOLT - dw FlashScreenEveryEightFrameBlocks - - db REFLECT - dw AnimationFlashScreen - - db SELFDESTRUCT - dw DoExplodeSpecialEffects - - db SPORE - dw FlashScreenEveryFourFrameBlocks - - db EXPLOSION - dw DoExplodeSpecialEffects - - db ROCK_SLIDE - dw DoRockSlideSpecialEffects - - db TRADE_BALL_DROP_ANIM - dw TradeHidePokemon - - db TRADE_BALL_SHAKE_ANIM - dw TradeShakePokeball - - db TRADE_BALL_TILT_ANIM - dw TradeJumpPokeball - - db TOSS_ANIM - dw DoBallTossSpecialEffects - - db SHAKE_ANIM - dw DoBallShakeSpecialEffects - - db POOF_ANIM - dw DoPoofSpecialEffects - - db GREATTOSS_ANIM - dw DoBallTossSpecialEffects - - db ULTRATOSS_ANIM - dw DoBallTossSpecialEffects - - db $FF ; terminator +INCLUDE "data/battle_anims/special_effects.asm" DoBallTossSpecialEffects: ld a, [wcf91] cp 3 ; is it a Master Ball or Ultra Ball? jr nc, .skipFlashingEffect .flashingEffect ; do a flashing effect if it's Master Ball or Ultra Ball - ld a, [rOBP0] + ldh a, [rOBP0] xor %00111100 ; complement colors 1 and 2 - ld [rOBP0], a + ldh [rOBP0], a call UpdateGBCPal_OBP0 .skipFlashingEffect ld a, [wSubAnimCounter] @@ -805,7 +731,7 @@ DoBallTossSpecialEffects: cp 1 ret nz .moveGhostMarowakLeft - coord hl, 17, 0 + hlcoord 17, 0 ld de, 20 lb bc, 7, 7 .loop @@ -818,7 +744,7 @@ DoBallTossSpecialEffects: dec b jr nz, .loop ld a, %00001000 - ld [rNR10], a ; Channel 1 sweep register + ldh [rNR10], a ; Channel 1 sweep register ret .isTrainerBattle ; if it's a trainer battle, shorten the animation by one frame ld a, [wSubAnimCounter] @@ -904,7 +830,7 @@ DoExplodeSpecialEffects: cp 1 ; is it the end of the subanimation? jr nz, FlashScreenEveryFourFrameBlocks ; if it's the end of the subanimation, make the attacking pokemon disappear - coord hl, 1, 5 + hlcoord 1, 5 jp AnimationHideMonPic ; make pokemon disappear ; flashes the screen when subanimation counter is 1 modulo 4 @@ -972,7 +898,7 @@ TradeShakePokeball: BallMoveDistances1: db -12, -12, -8 - db $ff ; terminator + db -1 ; end ; function to make the pokeball jump up TradeJumpPokeball: @@ -1005,15 +931,15 @@ TradeJumpPokeball: ld c, 5 call DelayFrames pop bc - ld a, [hSCX] ; background scroll X + ldh a, [hSCX] ; background scroll X sub 8 ; scroll to the left - ld [hSCX], a + ldh [hSCX], a pop de jr .loop BallMoveDistances2: db 11, 12, -12, -7, 7, 12, -8, 8 - db $ff ; terminator + db -1 ; end ; this function copies the current musical note graphic ; so that there are two musical notes flying towards the defending pokemon @@ -1034,87 +960,7 @@ TailWhipAnimationUnused: ld c, 20 jp DelayFrames -; Format: Special Effect ID (1 byte), Address (2 bytes) -SpecialEffectPointers: - db SE_DARK_SCREEN_FLASH ; $FE - dw AnimationFlashScreen - db SE_DARK_SCREEN_PALETTE ; $FD - dw AnimationDarkScreenPalette - db SE_RESET_SCREEN_PALETTE ; $FC - dw AnimationResetScreenPalette - db SE_SHAKE_SCREEN ; $FB - dw AnimationShakeScreen - db SE_WATER_DROPLETS_EVERYWHERE ; $FA - dw AnimationWaterDropletsEverywhere - db SE_DARKEN_MON_PALETTE ; $F9 - dw AnimationDarkenMonPalette - db SE_FLASH_SCREEN_LONG ; $F8 - dw AnimationFlashScreenLong - db SE_SLIDE_MON_UP ; $F7 - dw AnimationSlideMonUp - db SE_SLIDE_MON_DOWN ; $F6 - dw AnimationSlideMonDown - db SE_FLASH_MON_PIC ; $F5 - dw AnimationFlashMonPic - db SE_SLIDE_MON_OFF ; $F4 - dw AnimationSlideMonOff - db SE_BLINK_MON ; $F3 - dw AnimationBlinkMon - db SE_MOVE_MON_HORIZONTALLY ; $F2 - dw AnimationMoveMonHorizontally - db SE_RESET_MON_POSITION ; $F1 - dw AnimationResetMonPosition - db SE_LIGHT_SCREEN_PALETTE ; $F0 - dw AnimationLightScreenPalette - db SE_HIDE_MON_PIC ; $EF - dw AnimationHideMonPic - db SE_SQUISH_MON_PIC ; $EE - dw AnimationSquishMonPic - db SE_SHOOT_BALLS_UPWARD ; $ED - dw AnimationShootBallsUpward - db SE_SHOOT_MANY_BALLS_UPWARD ; $EC - dw AnimationShootManyBallsUpward - db SE_BOUNCE_UP_AND_DOWN ; $EB - dw AnimationBoundUpAndDown - db SE_MINIMIZE_MON ; $EA - dw AnimationMinimizeMon - db SE_SLIDE_MON_DOWN_AND_HIDE ; $E9 - dw AnimationSlideMonDownAndHide - db SE_TRANSFORM_MON ; $E8 - dw AnimationTransformMon - db SE_LEAVES_FALLING ; $E7 - dw AnimationLeavesFalling - db SE_PETALS_FALLING ; $E6 - dw AnimationPetalsFalling - db SE_SLIDE_MON_HALF_OFF ; $E5 - dw AnimationSlideMonHalfOff - db SE_SHAKE_ENEMY_HUD ; $E4 - dw AnimationShakeEnemyHUD - db SE_SHAKE_ENEMY_HUD_2 ; unused--same pointer as SE_SHAKE_ENEMY_HUD ($E4) - dw AnimationShakeEnemyHUD - db SE_SPIRAL_BALLS_INWARD ; $E2 - dw AnimationSpiralBallsInward - db SE_DELAY_ANIMATION_10 ; $E1 - dw AnimationDelay10 - db SE_FLASH_ENEMY_MON_PIC ; unused--same as SE_FLASH_MON_PIC ($F5), but for the enemy mon - dw AnimationFlashEnemyMonPic - db SE_HIDE_ENEMY_MON_PIC ; $DF - dw AnimationHideEnemyMonPic - db SE_BLINK_ENEMY_MON ; $DE - dw AnimationBlinkEnemyMon - db SE_SHOW_MON_PIC ; $DD - dw AnimationShowMonPic - db SE_SHOW_ENEMY_MON_PIC ; $DC - dw AnimationShowEnemyMonPic - db SE_SLIDE_ENEMY_MON_OFF ; $DB - dw AnimationSlideEnemyMonOff - db SE_SHAKE_BACK_AND_FORTH ; $DA - dw AnimationShakeBackAndForth - db SE_SUBSTITUTE_MON ; $D9 - dw AnimationSubstitute - db SE_WAVY_SCREEN ; $D8 - dw AnimationWavyScreen - db $FF +INCLUDE "data/battle_anims/special_effect_pointers.asm" AnimationDelay10: ld c, 10 @@ -1123,16 +969,16 @@ AnimationDelay10: ; calls a function with the turn flipped from player to enemy or vice versa ; input - hl - address of function to call CallWithTurnFlipped: - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] push af xor 1 - ld [H_WHOSETURN], a + ldh [hWhoseTurn], a ld de, .returnAddress push de jp hl .returnAddress pop af - ld [H_WHOSETURN], a + ldh [hWhoseTurn], a ret ; flashes the screen for an extended period (48 frames) @@ -1150,7 +996,7 @@ AnimationFlashScreenLong: ld a, [hli] cp $01 ; is it the end of the palettes? jr z, .endOfPalettes - ld [rBGP], a + ldh [rBGP], a call UpdateGBCPal_BGP call FlashScreenLongDelay jr .innerLoop @@ -1210,20 +1056,20 @@ FlashScreenLongDelay: jp DelayFrames AnimationFlashScreen: - ld a, [rBGP] + ldh a, [rBGP] push af ; save initial palette ld a, %00011011 ; 0, 1, 2, 3 (inverted colors) - ld [rBGP], a + ldh [rBGP], a call UpdateGBCPal_BGP ld c, 2 call DelayFrames xor a ; white out background - ld [rBGP], a + ldh [rBGP], a call UpdateGBCPal_BGP ld c, 2 call DelayFrames pop af - ld [rBGP], a ; restore initial palette + ldh [rBGP], a ; restore initial palette call UpdateGBCPal_BGP ret @@ -1269,7 +1115,7 @@ SetAnimationBGPalette: jr z, .next ld a, c .next - ld [rBGP], a + ldh [rBGP], a call UpdateGBCPal_BGP ret @@ -1356,14 +1202,14 @@ _AnimationWaterDroplets: AnimationSlideMonUp: ; Slides the mon's sprite upwards. ld c, 7 - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a - coord hl, 1, 6 - coord de, 1, 5 + hlcoord 1, 6 + decoord 1, 5 ld a, $30 jr z, .next - coord hl, 12, 1 - coord de, 12, 0 + hlcoord 12, 1 + decoord 12, 0 ld a, $ff .next ld [wSlideMonUpBottomRowLeftTile], a @@ -1371,7 +1217,7 @@ AnimationSlideMonUp: AnimationSlideMonDown: ; Slides the mon's sprite down out of the screen. - xor a + xor a ; TILEMAP_MON_PIC call GetTileIDList .loop call GetMonSpriteTileMapPointerFromRowCount @@ -1424,11 +1270,11 @@ _AnimationSlideMonUp: jr nz, .slideLoop ; Fill in the bottom row of the mon pic with the next row's tile IDs. - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a - coord hl, 1, 11 + hlcoord 1, 11 jr z, .next - coord hl, 12, 6 + hlcoord 12, 6 .next ld a, [wSlideMonUpBottomRowLeftTile] inc a @@ -1592,7 +1438,7 @@ AnimationFlashEnemyMonPic: jp CallWithTurnFlipped AnimationShowMonPic: - xor a + xor a ; TILEMAP_MON_PIC call GetTileIDList call GetMonSpriteTileMapPointerFromRowCount call CopyPicTiles @@ -1607,16 +1453,16 @@ AnimationShowEnemyMonPic: AnimationShakeBackAndForth: ; Shakes the mon's sprite back and forth rapidly. This is used in Double Team. ; The mon's sprite disappears after this animation. - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a - coord hl, 0, 5 - coord de, 2, 5 + hlcoord 0, 5 + decoord 2, 5 jr z, .next - coord hl, 11, 0 - coord de, 13, 0 + hlcoord 11, 0 + decoord 13, 0 .next - xor a + xor a ; TILEMAP_MON_PIC ld c, $10 .loop push af @@ -1655,13 +1501,13 @@ AnimationMoveMonHorizontally: ; Shifts the mon's sprite horizontally to a fixed location. Used by lots of ; animations like Tackle/Body Slam. call AnimationHideMonPic - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a - coord hl, 2, 5 + hlcoord 2, 5 jr z, .next - coord hl, 11, 0 + hlcoord 11, 0 .next - xor a + xor a ; TILEMAP_MON_PIC push hl call GetTileIDList pop hl @@ -1671,7 +1517,7 @@ AnimationMoveMonHorizontally: AnimationResetMonPosition: ; Resets the mon's sprites to be located at the normal coordinates. - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a ld a, 5 * SCREEN_WIDTH + 2 jr z, .next @@ -1683,7 +1529,7 @@ AnimationResetMonPosition: AnimationSpiralBallsInward: ; Creates an effect that looks like energy balls spiralling into the ; player mon's sprite. Used in Focus Energy, for example. - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a jr z, .playerTurn ld a, -40 @@ -1772,7 +1618,7 @@ SpiralBallAnimationCoordinates: db $58, $28 db $50, $30 db $50, $28 - db $FF ; list terminator + db -1 ; end AnimationSquishMonPic: ; Squishes the mon's sprite horizontally making it @@ -1780,15 +1626,15 @@ AnimationSquishMonPic: ld c, 4 .loop push bc - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a jr z, .playerTurn - coord hl, 16, 0 - coord de, 14, 0 + hlcoord 16, 0 + decoord 14, 0 jr .next .playerTurn - coord hl, 5, 5 - coord de, 3, 5 + hlcoord 5, 5 + decoord 3, 5 .next push de xor a ; left @@ -1833,7 +1679,7 @@ _AnimationSquishMonPic: AnimationShootBallsUpward: ; Shoots one pillar of "energy" balls upwards. Used in Teleport/Sky Attack ; animations. - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a jr z, .playerTurn lb bc, 0, 16 * 8 @@ -1901,7 +1747,7 @@ _AnimationShootBallsUpward: AnimationShootManyBallsUpward: ; Shoots several pillars of "energy" balls upward. - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a ld hl, UpwardBallsAnimXCoordinatesPlayerTurn ld a, $50 ; y coordinate for "energy" ball pillar @@ -1927,13 +1773,13 @@ UpwardBallsAnimXCoordinatesPlayerTurn: ; List of x coordinates for each pillar of "energy" balls in the ; AnimationShootManyBallsUpward animation. It's unused in the game. db $10, $40, $28, $18, $38, $30 - db $FF ; list terminator + db -1 ; end UpwardBallsAnimXCoordinatesEnemyTurn: ; List of x coordinates for each pillar of "energy" balls in the ; AnimationShootManyBallsUpward animation. It's unused in the game. db $60, $90, $78, $68, $88, $80 - db $FF ; list terminator + db -1 ; end AnimationMinimizeMon: ; Changes the mon's sprite to a mini black sprite. Used by the @@ -1960,13 +1806,13 @@ AnimationMinimizeMon: jp AnimationShowMonPic MinimizedMonSprite: - INCBIN "gfx/minimized_mon_sprite.1bpp" + INCBIN "gfx/battle/minimize.1bpp" MinimizedMonSpriteEnd: AnimationSlideMonDownAndHide: ; Slides the mon's sprite down and disappears. Used in Acid Armor. - ld a, $1 - ld c, $2 + ld a, TILEMAP_SLIDE_DOWN_MON_PIC_7X5 + ld c, 2 .loop push bc push af @@ -1985,7 +1831,7 @@ AnimationSlideMonDownAndHide: jr nz, .loop call AnimationHideMonPic ld hl, wTempPic - ld bc, $0310 + ld bc, 7 * 7 tiles xor a call FillMemory jp CopyTempPicToMonPic @@ -1993,13 +1839,13 @@ AnimationSlideMonDownAndHide: _AnimationSlideMonOff: ; Slides the mon's sprite off the screen horizontally by e tiles and waits ; [wSlideMonDelay] V-blanks each time the pic is slid by one tile. - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a jr z, .playerTurn - coord hl, 12, 0 + hlcoord 12, 0 jr .next .playerTurn - coord hl, 0, 5 + hlcoord 0, 5 .next ld d, 8 ; d's value is unused .slideLoop ; iterates once for each time the pic slides by one tile @@ -2008,7 +1854,7 @@ _AnimationSlideMonOff: .rowLoop ; iterates once for each row ld c, 8 .tileLoop ; iterates once for each tile in the row - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a jr z, .playerTurn2 call .EnemyNextTile @@ -2069,7 +1915,7 @@ AnimationSlideMonHalfOff: jp Delay3 CopyTempPicToMonPic: - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a ld hl, vBackPic ; player turn jr z, .next @@ -2085,18 +1931,18 @@ AnimationWavyScreen: call BattleAnimCopyTileMapToVRAM call Delay3 xor a - ld [H_AUTOBGTRANSFERENABLED], a - ld a, SCREEN_HEIGHT_PIXELS - ld [hWY], a + ldh [hAutoBGTransferEnabled], a + ld a, SCREEN_HEIGHT_PX + ldh [hWY], a ld d, $80 ; terminator - ld e, SCREEN_HEIGHT_PIXELS - 1 + ld e, SCREEN_HEIGHT_PX - 1 ld c, $ff ld hl, WavyScreenLineOffsets .loop push hl .innerLoop call WavyScreen_SetSCX - ld a, [rLY] + ldh a, [rLY] cp e ; is it the last visible line in the frame? jr nz, .innerLoop ; keep going if not pop hl @@ -2109,11 +1955,11 @@ AnimationWavyScreen: dec c jr nz, .loop xor a - ld [hWY], a + ldh [hWY], a call SaveScreenTilesToBuffer2 call ClearScreen ld a, 1 - ld [H_AUTOBGTRANSFERENABLED], a + ldh [hAutoBGTransferEnabled], a call Delay3 call LoadScreenTilesFromBuffer2 ld hl, vBGMap1 @@ -2121,11 +1967,11 @@ AnimationWavyScreen: ret WavyScreen_SetSCX: - ld a, [rSTAT] + ldh a, [rSTAT] and $3 ; is it H-blank? jr nz, WavyScreen_SetSCX ; wait until it's H-blank ld a, [hl] - ld [rSCX], a + ldh [rSCX], a inc hl ld a, [hl] cp d ; have we reached the end? @@ -2144,48 +1990,48 @@ AnimationSubstitute: ; Changes the pokemon's sprite to the mini sprite ld hl, wTempPic xor a - ld bc, $0310 + ld bc, $310 call FillMemory - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a jr z, .playerTurn - ld hl, SlowbroSprite ; facing down sprite + ld hl, MonsterSprite tile 0 ; facing down sprite ld de, wTempPic + $120 - call CopySlowbroSpriteData - ld hl, SlowbroSprite + $10 + call CopyMonsterSpriteData + ld hl, MonsterSprite tile 1 ld de, wTempPic + $120 + $70 - call CopySlowbroSpriteData - ld hl, SlowbroSprite + $20 + call CopyMonsterSpriteData + ld hl, MonsterSprite tile 2 ld de, wTempPic + $120 + $10 - call CopySlowbroSpriteData - ld hl, SlowbroSprite + $30 + call CopyMonsterSpriteData + ld hl, MonsterSprite tile 3 ld de, wTempPic + $120 + $10 + $70 - call CopySlowbroSpriteData + call CopyMonsterSpriteData jr .next .playerTurn - ld hl, SlowbroSprite + $40 ; facing up sprite + ld hl, MonsterSprite tile 4 ; facing up sprite ld de, wTempPic + $120 + $70 - call CopySlowbroSpriteData - ld hl, SlowbroSprite + $50 + call CopyMonsterSpriteData + ld hl, MonsterSprite tile 5 ld de, wTempPic + $120 + $e0 - call CopySlowbroSpriteData - ld hl, SlowbroSprite + $60 + call CopyMonsterSpriteData + ld hl, MonsterSprite tile 6 ld de, wTempPic + $120 + $80 - call CopySlowbroSpriteData - ld hl, SlowbroSprite + $70 + call CopyMonsterSpriteData + ld hl, MonsterSprite tile 7 ld de, wTempPic + $120 + $f0 - call CopySlowbroSpriteData + call CopyMonsterSpriteData .next call CopyTempPicToMonPic jp AnimationShowMonPic -CopySlowbroSpriteData: - ld bc, $0010 - ld a, BANK(SlowbroSprite) +CopyMonsterSpriteData: + ld bc, 1 tiles + ld a, BANK(MonsterSprite) jp FarCopyData HideSubstituteShowMonAnim: - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a ld hl, wPlayerMonMinimized ld de, wPlayerBattleStatus1 @@ -2226,7 +2072,7 @@ HideSubstituteShowMonAnim: call AnimationFlashMonPic jp AnimationShowMonPic .flyOrDig - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a jr nz, .enemy ld a, [wPlayerMonMinimized] @@ -2294,7 +2140,7 @@ AnimationTransformMon: ld [wChangeMonPicEnemyTurnSpecies], a ChangeMonPic: - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a jr z, .playerTurn ld a, [wChangeMonPicEnemyTurnSpecies] @@ -2303,7 +2149,7 @@ ChangeMonPic: xor a ld [wSpriteFlipped], a call GetMonHeader - coord hl, 12, 0 + hlcoord 12, 0 call LoadFrontSpriteByMonIndex jr .done .playerTurn @@ -2314,7 +2160,7 @@ ChangeMonPic: ld [wd0b5], a call GetMonHeader predef LoadMonBackPic - xor a + xor a ; TILEMAP_MON_PIC call GetTileIDList call GetMonSpriteTileMapPointerFromRowCount call CopyPicTiles @@ -2327,16 +2173,16 @@ ChangeMonPic: AnimationHideEnemyMonPic: ; Hides the enemy mon's sprite xor a - ld [H_AUTOBGTRANSFERENABLED], a + ldh [hAutoBGTransferEnabled], a ld hl, AnimationHideMonPic call CallWithTurnFlipped ld a, $1 - ld [H_AUTOBGTRANSFERENABLED], a + ldh [hAutoBGTransferEnabled], a jp Delay3 Func_79929: ld hl, wPlayerMonMinimized - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a jr z, .playerTurn ld hl, wEnemyMonMinimized @@ -2376,7 +2222,7 @@ InitMultipleObjectsOAM: AnimationHideMonPic: ; Hides the mon's sprite. - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a jr z, .playerTurn ld a, 12 @@ -2390,7 +2236,7 @@ ClearMonPicFromTileMap: push bc ld e, a ld d, 0 - coord hl, 0, 0 + hlcoord 0, 0 add hl, de lb bc, 7, 7 call ClearScreenArea @@ -2404,7 +2250,7 @@ ClearMonPicFromTileMap: ; in order to show only a portion of the mon sprite. GetMonSpriteTileMapPointerFromRowCount: push de - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a jr nz, .enemyTurn ld a, 20 * 5 + 1 @@ -2412,7 +2258,7 @@ GetMonSpriteTileMapPointerFromRowCount: .enemyTurn ld a, 12 .next - coord hl, 0, 0 + hlcoord 0, 0 ld e, a ld d, 0 add hl, de @@ -2492,7 +2338,7 @@ GetMoveSound: ld b, a call IsCryMove jr nc, .NotCryMove - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a jr nz, .next ld a, [wBattleMonSpecies] ; get number of current monster @@ -2534,184 +2380,17 @@ IsCryMove: scf ret -MoveSoundTable: - ; ID, pitch mod, tempo mod - db SFX_POUND, $00, $80 ; POUND - db SFX_BATTLE_0C, $10, $80 ; KARATE_CHOP - db SFX_DOUBLESLAP, $00, $80 ; DOUBLESLAP - db SFX_BATTLE_0B, $01, $80 ; COMET_PUNCH - db SFX_BATTLE_0D, $00, $40 ; MEGA_PUNCH - db SFX_SILPH_SCOPE, $00, $ff ; PAY_DAY - db SFX_BATTLE_0D, $10, $60 ; FIRE_PUNCH - db SFX_BATTLE_0D, $20, $80 ; ICE_PUNCH - db SFX_BATTLE_0D, $00, $a0 ; THUNDERPUNCH - db SFX_DAMAGE, $00, $80 ; SCRATCH - db SFX_BATTLE_0F, $20, $40 ; VICEGRIP - db SFX_BATTLE_0F, $00, $80 ; GUILLOTINE - db SFX_BATTLE_0E, $00, $a0 ; RAZOR_WIND - db SFX_NOT_VERY_EFFECTIVE, $10, $c0 ; SWORDS_DANCE - db SFX_NOT_VERY_EFFECTIVE, $00, $a0 ; CUT - db SFX_BATTLE_12, $00, $c0 ; GUST - db SFX_BATTLE_12, $10, $a0 ; WING_ATTACK - db SFX_BATTLE_13, $00, $e0 ; WHIRLWIND - db SFX_NOT_VERY_EFFECTIVE, $20, $c0 ; FLY - db SFX_BATTLE_14, $00, $80 ; BIND - db SFX_BATTLE_22, $00, $80 ; SLAM - db SFX_VINE_WHIP, $01, $80 ; VINE_WHIP - db SFX_BATTLE_20, $00, $80 ; STOMP - db SFX_BATTLE_17, $f0, $40 ; DOUBLE_KICK - db SFX_SUPER_EFFECTIVE, $00, $80 ; MEGA_KICK - db SFX_BATTLE_17, $00, $80 ; JUMP_KICK - db SFX_BATTLE_21, $10, $80 ; ROLLING_KICK - db SFX_BATTLE_1B, $01, $a0 ; SAND_ATTACK - db SFX_BATTLE_18, $00, $80 ; HEADBUTT - db SFX_BATTLE_1E, $00, $60 ; HORN_ATTACK - db SFX_BATTLE_1E, $01, $40 ; FURY_ATTACK - db SFX_HORN_DRILL, $00, $a0 ; HORN_DRILL - db SFX_SUPER_EFFECTIVE, $10, $a0 ; TACKLE - db SFX_BATTLE_20, $00, $c0 ; BODY_SLAM - db SFX_BATTLE_14, $10, $60 ; WRAP - db SFX_SUPER_EFFECTIVE, $00, $a0 ; TAKE_DOWN - db SFX_BATTLE_22, $11, $c0 ; THRASH - db SFX_SUPER_EFFECTIVE, $20, $c0 ; DOUBLE_EDGE - db SFX_BATTLE_21, $00, $80 ; TAIL_WHIP - db SFX_BATTLE_1B, $00, $80 ; POISON_STING - db SFX_BATTLE_1B, $20, $c0 ; TWINEEDLE - db SFX_BATTLE_19, $00, $80 ; PIN_MISSILE - db SFX_BATTLE_31, $ff, $40 ; LEER - db SFX_BATTLE_1E, $00, $80 ; BITE - db SFX_BATTLE_0B, $00, $c0 ; GROWL - db SFX_BATTLE_0B, $00, $40 ; ROAR - db SFX_BATTLE_35, $00, $80 ; SING - db SFX_BATTLE_27, $40, $60 ; SUPERSONIC - db SFX_BATTLE_27, $00, $80 ; SONICBOOM - db SFX_BATTLE_27, $ff, $40 ; DISABLE - db SFX_BATTLE_2A, $80, $c0 ; ACID - db SFX_BATTLE_19, $10, $a0 ; EMBER - db SFX_BATTLE_19, $21, $e0 ; FLAMETHROWER - db SFX_BATTLE_29, $00, $80 ; MIST - db SFX_BATTLE_24, $20, $60 ; WATER_GUN - db SFX_BATTLE_2A, $00, $80 ; HYDRO_PUMP - db SFX_BATTLE_2C, $00, $80 ; SURF - db SFX_BATTLE_28, $40, $80 ; ICE_BEAM - db SFX_BATTLE_29, $f0, $e0 ; BLIZZARD - db SFX_PSYBEAM, $00, $80 ; PSYBEAM - db SFX_BATTLE_2A, $f0, $60 ; BUBBLEBEAM - db SFX_BATTLE_28, $00, $80 ; AURORA_BEAM - db SFX_BATTLE_36, $00, $80 ; HYPER_BEAM - db SFX_PECK, $01, $a0 ; PECK - db SFX_BATTLE_13, $f0, $20 ; DRILL_PECK - db SFX_BATTLE_23, $01, $c0 ; SUBMISSION - db SFX_BATTLE_23, $00, $80 ; LOW_KICK - db SFX_SUPER_EFFECTIVE, $00, $e0 ; COUNTER - db SFX_BATTLE_26, $01, $60 ; SEISMIC_TOSS - db SFX_BATTLE_26, $20, $40 ; STRENGTH - db SFX_BATTLE_24, $00, $80 ; ABSORB - db SFX_BATTLE_24, $40, $c0 ; MEGA_DRAIN - db SFX_BATTLE_1B, $03, $60 ; LEECH_SEED - db SFX_BATTLE_25, $11, $e0 ; GROWTH - db SFX_BATTLE_12, $20, $e0 ; RAZOR_LEAF - db SFX_BATTLE_2E, $00, $80 ; SOLARBEAM - db SFX_BATTLE_1C, $00, $80 ; POISONPOWDER - db SFX_BATTLE_1C, $11, $a0 ; STUN_SPORE - db SFX_BATTLE_1C, $01, $c0 ; SLEEP_POWDER - db SFX_BATTLE_13, $14, $c0 ; PETAL_DANCE - db SFX_BATTLE_1B, $02, $a0 ; STRING_SHOT - db SFX_BATTLE_29, $f0, $80 ; DRAGON_RAGE - db SFX_BATTLE_29, $20, $c0 ; FIRE_SPIN - db SFX_BATTLE_2F, $00, $20 ; THUNDERSHOCK - db SFX_BATTLE_2F, $20, $80 ; THUNDERBOLT - db SFX_BATTLE_2E, $12, $60 ; THUNDER_WAVE - db SFX_BATTLE_26, $00, $80 ; THUNDER - db SFX_BATTLE_14, $01, $e0 ; ROCK_THROW - db SFX_BATTLE_29, $0f, $e0 ; EARTHQUAKE - db SFX_BATTLE_29, $11, $20 ; FISSURE - db SFX_DAMAGE, $10, $40 ; DIG - db SFX_BATTLE_0F, $10, $c0 ; TOXIC - db SFX_BATTLE_14, $00, $20 ; CONFUSION - db SFX_PSYCHIC_M, $00, $80 ; PSYCHIC_M - db SFX_BATTLE_35, $11, $18 ; HYPNOSIS - db SFX_BATTLE_09, $20, $c0 ; MEDITATE - db SFX_FAINT_FALL, $20, $c0 ; AGILITY - db SFX_BATTLE_25, $00, $10 ; QUICK_ATTACK - db SFX_BATTLE_26, $f0, $20 ; RAGE - db SFX_BATTLE_33, $f0, $c0 ; TELEPORT - db SFX_NOT_VERY_EFFECTIVE, $f0, $e0 ; NIGHT_SHADE - db SFX_BATTLE_09, $f0, $40 ; MIMIC - db SFX_BATTLE_31, $00, $80 ; SCREECH - db SFX_BATTLE_33, $80, $40 ; DOUBLE_TEAM - db SFX_BATTLE_33, $00, $80 ; RECOVER - db SFX_BATTLE_14, $11, $20 ; HARDEN - db SFX_BATTLE_14, $22, $10 ; MINIMIZE - db SFX_BATTLE_1B, $f1, $ff ; SMOKESCREEN - db SFX_BATTLE_13, $f1, $ff ; CONFUSE_RAY - db SFX_BATTLE_14, $33, $30 ; WITHDRAW - db SFX_BATTLE_32, $40, $c0 ; DEFENSE_CURL - db SFX_BATTLE_0E, $20, $20 ; BARRIER - db SFX_BATTLE_0E, $f0, $10 ; LIGHT_SCREEN - db SFX_BATTLE_0F, $f8, $10 ; HAZE - db SFX_NOT_VERY_EFFECTIVE, $f0, $10 ; REFLECT - db SFX_BATTLE_25, $00, $80 ; FOCUS_ENERGY - db SFX_BATTLE_18, $00, $c0 ; BIDE - db SFX_BATTLE_32, $c0, $ff ; METRONOME - db SFX_BATTLE_09, $f2, $20 ; MIRROR_MOVE - db SFX_BATTLE_34, $00, $80 ; SELFDESTRUCT - db SFX_BATTLE_34, $00, $40 ; EGG_BOMB - db SFX_BATTLE_09, $00, $40 ; LICK - db SFX_NOT_VERY_EFFECTIVE, $10, $ff ; SMOG - db SFX_BATTLE_2A, $20, $20 ; SLUDGE - db SFX_BATTLE_32, $00, $80 ; BONE_CLUB - db SFX_BATTLE_29, $1f, $20 ; FIRE_BLAST - db SFX_BATTLE_25, $2f, $80 ; WATERFALL - db SFX_BATTLE_0F, $1f, $ff ; CLAMP - db SFX_BATTLE_2B, $1f, $60 ; SWIFT - db SFX_BATTLE_26, $1e, $20 ; SKULL_BASH - db SFX_BATTLE_26, $1f, $18 ; SPIKE_CANNON - db SFX_BATTLE_14, $0f, $80 ; CONSTRICT - db SFX_BATTLE_09, $f8, $10 ; AMNESIA - db SFX_FAINT_FALL, $18, $20 ; KINESIS - db SFX_BATTLE_32, $08, $40 ; SOFTBOILED - db SFX_BATTLE_17, $01, $e0 ; HI_JUMP_KICK - db SFX_NOT_VERY_EFFECTIVE, $09, $ff ; GLARE - db SFX_BATTLE_35, $42, $01 ; DREAM_EATER - db SFX_BATTLE_1C, $00, $ff ; POISON_GAS - db SFX_BATTLE_32, $08, $e0 ; BARRAGE - db SFX_BATTLE_24, $00, $80 ; LEECH_LIFE - db SFX_BATTLE_09, $88, $10 ; LOVELY_KISS - db SFX_BATTLE_25, $48, $ff ; SKY_ATTACK - db SFX_FAINT_FALL, $ff, $ff ; TRANSFORM - db SFX_BATTLE_24, $ff, $10 ; BUBBLE - db SFX_FAINT_FALL, $ff, $04 ; DIZZY_PUNCH - db SFX_BATTLE_1C, $01, $ff ; SPORE - db SFX_BATTLE_13, $f8, $ff ; FLASH - db SFX_BATTLE_0C, $f0, $f0 ; PSYWAVE - db SFX_BATTLE_0F, $08, $10 ; SPLASH - db SFX_BATTLE_0D, $f0, $ff ; ACID_ARMOR - db SFX_SUPER_EFFECTIVE, $f0, $ff ; CRABHAMMER - db SFX_BATTLE_34, $10, $ff ; EXPLOSION - db SFX_BATTLE_0E, $f0, $20 ; FURY_SWIPES - db SFX_BATTLE_2B, $f0, $60 ; BONEMERANG - db SFX_BATTLE_21, $12, $10 ; REST - db SFX_BATTLE_36, $f0, $20 ; ROCK_SLIDE - db SFX_BATTLE_1E, $12, $ff ; HYPER_FANG - db SFX_BATTLE_31, $80, $04 ; SHARPEN - db SFX_BATTLE_33, $f0, $10 ; CONVERSION - db SFX_BATTLE_29, $f8, $ff ; TRI_ATTACK - db SFX_BATTLE_26, $f0, $ff ; SUPER_FANG - db SFX_NOT_VERY_EFFECTIVE, $01, $ff ; SLASH - db SFX_BATTLE_2C, $d8, $04 ; SUBSTITUTE - db SFX_BATTLE_0B, $00, $80 ; STRUGGLE - db SFX_BATTLE_0B, $00, $80 +INCLUDE "data/moves/sfx.asm" CopyPicTiles: - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a ld a, $31 ; base tile ID of player mon sprite jr z, .next ; enemy turn xor a ; base tile ID of enemy mon sprite .next - ld [hBaseTileID], a + ldh [hBaseTileID], a jr CopyTileIDs_NoBGTransfer ; copy the tiles used when a mon is being sent out of or into a pokeball @@ -2728,7 +2407,7 @@ CopyDownscaledMonTiles: CopyTileIDs_NoBGTransfer: xor a - ld [H_AUTOBGTRANSFERENABLED], a + ldh [hAutoBGTransferEnabled], a ; fall through ; b = number of rows @@ -2738,7 +2417,7 @@ CopyTileIDs: .rowLoop push bc push hl - ld a, [hBaseTileID] + ldh a, [hBaseTileID] ld b, a .columnLoop ld a, [de] @@ -2754,108 +2433,17 @@ CopyTileIDs: dec b jr nz, .rowLoop ld a, $1 - ld [H_AUTOBGTRANSFERENABLED], a + ldh [hAutoBGTransferEnabled], a pop hl ret -TileIDListPointerTable: - dw DownscaledMonTiles_7x7 - dn 7, 7 - dw DownscaledMonTiles_5x7 - dn 5, 7 - dw DownscaledMonTiles_3x7 - dn 3, 7 - dw GengarIntroTiles1 - dn 7, 7 - dw GengarIntroTiles2 - dn 7, 7 - dw GengarIntroTiles3 - dn 7, 7 - dw DownscaledMonTiles_79d7c - dn 8, 6 - dw DownscaledMonTiles_79dac - dn 3, 12 - -DownscaledMonTiles_5x5: - db $31, $38, $46, $54, $5B - db $32, $39, $47, $55, $5C - db $34, $3B, $49, $57, $5E - db $36, $3D, $4B, $59, $60 - db $37, $3E, $4C, $5A, $61 - -DownscaledMonTiles_3x3: - db $31, $46, $5B - db $34, $49, $5E - db $37, $4C, $61 - -DownscaledMonTiles_7x7: - db $00, $07, $0E, $15, $1C, $23, $2A - db $01, $08, $0F, $16, $1D, $24, $2B - db $02, $09, $10, $17, $1E, $25, $2C - db $03, $0A, $11, $18, $1F, $26, $2D - db $04, $0B, $12, $19, $20, $27, $2E - db $05, $0C, $13, $1A, $21, $28, $2F - db $06, $0D, $14, $1B, $22, $29, $30 - -DownscaledMonTiles_5x7: - db $00, $07, $0E, $15, $1C, $23, $2A - db $01, $08, $0F, $16, $1D, $24, $2B - db $03, $0A, $11, $18, $1F, $26, $2D - db $04, $0B, $12, $19, $20, $27, $2E - db $05, $0C, $13, $1A, $21, $28, $2F - -DownscaledMonTiles_3x7: - db $00, $07, $0E, $15, $1C, $23, $2A - db $02, $09, $10, $17, $1E, $25, $2C - db $04, $0B, $12, $19, $20, $27, $2E - -GengarIntroTiles1: - db $00, $00, $00, $00, $00, $00, $00 - db $00, $00, $00, $00, $00, $19, $00 - db $02, $06, $0B, $10, $14, $1A, $00 - db $00, $07, $0C, $11, $15, $1B, $00 - db $03, $08, $0D, $12, $16, $1C, $00 - db $04, $09, $0E, $13, $17, $1D, $1F - db $05, $0A, $0F, $01, $18, $1E, $20 - -GengarIntroTiles2: - db $00, $00, $00, $30, $00, $37, $00 - db $00, $00, $2B, $31, $34, $38, $3D - db $21, $26, $2C, $01, $35, $39, $3E - db $22, $27, $2D, $32, $36, $01, $00 - db $23, $28, $2E, $33, $01, $3A, $00 - db $24, $29, $2F, $01, $01, $3B, $00 - db $25, $2A, $01, $01, $01, $3C, $00 - -GengarIntroTiles3: - db $00, $00, $00, $00, $00, $00, $00 - db $00, $00, $47, $4D, $00, $00, $00 - db $00, $00, $48, $4E, $52, $56, $5B - db $3F, $43, $49, $4F, $53, $57, $5C - db $40, $44, $4A, $50, $54, $58, $00 - db $41, $45, $4B, $51, $4C, $59, $5D - db $42, $46, $4C, $4C, $55, $5A, $5E - -DownscaledMonTiles_79d7c: - db $31, $32, $32, $32, $32, $33 - db $34, $35, $36, $36, $37, $38 - db $34, $39, $3A, $3A, $3B, $38 - db $3C, $3D, $3E, $3E, $3F, $40 - db $41, $42, $43, $43, $44, $45 - db $46, $47, $43, $48, $49, $4A - db $41, $43, $4B, $4C, $4D, $4E - db $4F, $50, $50, $50, $51, $52 - -DownscaledMonTiles_79dac: - db $43, $55, $56, $53, $53, $53, $53, $53, $53, $53, $53, $53 - db $43, $57, $58, $54, $54, $54, $54, $54, $54, $54, $54, $54 - db $43, $59, $5A, $43, $43, $43, $43, $43, $43, $43, $43, $43 +INCLUDE "data/tilemaps.asm" AnimationLeavesFalling: ; Makes leaves float down from the top of the screen. This is used ; in Razor Leaf's animation. ld a, [wAnimPalette] - ld [rOBP0], a + ldh [rOBP0], a call UpdateGBCPal_OBP0 ld d, $37 ; leaf tile ld a, 3 ; number of leaves @@ -3043,7 +2631,7 @@ AnimationShakeEnemyHUD: call CopyVideoData xor a - ld [hSCX], a + ldh [hSCX], a ; Copy wTileMap to BG map 0. The regular BG (not the window) is set to use ; map 0 and can be scrolled with SCX, which allows a shaking effect. @@ -3052,8 +2640,8 @@ AnimationShakeEnemyHUD: ; Now that the regular BG is showing the same thing the window was, move the ; window off the screen so that we can modify its contents below. - ld a, SCREEN_HEIGHT_PIXELS - ld [hWY], a + ld a, SCREEN_HEIGHT_PX + ldh [hWY], a ; Copy wTileMap to VRAM such that the row below the enemy HUD (in wTileMap) is ; lined up with row 0 of the window. @@ -3061,11 +2649,11 @@ AnimationShakeEnemyHUD: call BattleAnimCopyTileMapToVRAM ; update BGMap attributes - ld a, [hGBC] + ldh a, [hGBC] and a jr z, .notGBC ld c, 13 - callba LoadBGMapAttributes + farcall LoadBGMapAttributes .notGBC ; Move the window so that the row below the enemy HUD (in BG map 0) lines up @@ -3073,7 +2661,7 @@ AnimationShakeEnemyHUD: ; covers everything below the enemy HD with a copy that looks just like what ; was there before. ld a, 7 * 8 - ld [hWY], a + ldh [hWY], a ; Write OAM entries so that the copy of the back pic from the top of this ; function shows up on screen. We need this because the back pic's Y coordinates @@ -3097,19 +2685,19 @@ AnimationShakeEnemyHUD: ; Restore the original graphics. call AnimationShowMonPic call ClearSprites - ld a, SCREEN_HEIGHT_PIXELS - ld [hWY], a + ld a, SCREEN_HEIGHT_PX + ldh [hWY], a ld hl, vBGMap1 call BattleAnimCopyTileMapToVRAM ; update BGMap attributes - ld a, [hGBC] + ldh a, [hGBC] and a jr z, .notGBC2 ld c, 11 - callba LoadBGMapAttributes + farcall LoadBGMapAttributes .notGBC2 xor a - ld [hWY], a + ldh [hWY], a call SaveScreenTilesToBuffer1 ld hl, vBGMap0 call BattleAnimCopyTileMapToVRAM @@ -3122,7 +2710,7 @@ AnimationShakeEnemyHUD: CopyTileIDsFromList: call GetPredefRegisters ld a, c - ld [hBaseTileID], a + ldh [hBaseTileID], a ld a, b push hl call GetTileIDList @@ -3130,30 +2718,30 @@ CopyTileIDsFromList: jp CopyTileIDs ShakeEnemyHUD_ShakeBG: - ld a, [hSCX] + ldh a, [hSCX] ld [wTempSCX], a .loop ld a, [wTempSCX] add d - ld [hSCX], a + ldh [hSCX], a ld c, 2 call DelayFrames ld a, [wTempSCX] sub d - ld [hSCX], a + ldh [hSCX], a ld c, 2 call DelayFrames dec e jr nz, .loop ld a, [wTempSCX] - ld [hSCX], a + ldh [hSCX], a ret BattleAnimCopyTileMapToVRAM: ld a, h - ld [H_AUTOBGTRANSFERDEST + 1], a + ldh [hAutoBGTransferDest + 1], a ld a, l - ld [H_AUTOBGTRANSFERDEST], a + ldh [hAutoBGTransferDest], a jp Delay3 TossBallAnimation: diff --git a/engine/battle/bank3d_battle.asm b/engine/battle/bank3d_battle.asm index 5edc4571..48c3cde3 100644 --- a/engine/battle/bank3d_battle.asm +++ b/engine/battle/bank3d_battle.asm @@ -1,27 +1,28 @@ -InitBattle: +InitBattle:: ld a, [wCurOpponent] and a - jr z, asm_f6003 + jr z, DetermineWildOpponent InitOpponent: ld a, [wCurOpponent] ld [wcf91], a ld [wEnemyMonSpecies2], a - jr asm_f601d -asm_f6003: + jr InitBattleCommon + +DetermineWildOpponent: ld a, [wd732] bit 1, a - jr z, .asm_f600f - ld a, [hJoyHeld] + jr z, .asm_3ef2f + ldh a, [hJoyHeld] bit 1, a ; B button pressed? ret nz -.asm_f600f +.asm_3ef2f ld a, [wNumberOfNoRandomBattleStepsLeft] and a ret nz - callab TryDoWildEncounter + callfar TryDoWildEncounter ret nz -asm_f601d: +InitBattleCommon: ld a, [wMapPalOffset] push af ld hl, wLetterPrintingDelayFlags @@ -34,37 +35,37 @@ asm_f601d: jp c, InitWildBattle ld [wTrainerClass], a call GetTrainerInformation - callab ReadTrainer - callab DoBattleTransitionAndInitBattleVariables + callfar ReadTrainer + callfar DoBattleTransitionAndInitBattleVariables call _LoadTrainerPic xor a ld [wEnemyMonSpecies2], a - ld [$ffe1], a + ldh [hStartTileID], a dec a ld [wAICount], a - coord hl, 12, 0 + hlcoord 12, 0 predef CopyUncompressedPicToTilemap ld a, $ff ld [wEnemyMonPartyPos], a ld a, $2 ld [wIsInBattle], a - ; Is this a major story battle? - ld a,[wLoneAttackNo] +; Is this a major story battle? + ld a, [wLoneAttackNo] and a - jp z,InitBattle_Common + jp z, _InitBattleCommon callabd_ModifyPikachuHappiness PIKAHAPPY_GYMLEADER ; useless since already in bank3d - jp InitBattle_Common + jp _InitBattleCommon InitWildBattle: ld a, $1 ld [wIsInBattle], a - callab LoadEnemyMonData - callab DoBattleTransitionAndInitBattleVariables + callfar LoadEnemyMonData + callfar DoBattleTransitionAndInitBattleVariables ld a, [wCurOpponent] cp RESTLESS_SOUL jr z, .isGhost - callab IsGhostBattle + callfar IsGhostBattle jr nz, .isNoGhost .isGhost ld hl, wMonHSpriteDim @@ -101,49 +102,49 @@ InitWildBattle: .spriteLoaded xor a ld [wTrainerClass], a - ld [$ffe1], a - coord hl, 12, 0 + ldh [hStartTileID], a + hlcoord 12, 0 predef CopyUncompressedPicToTilemap ; common code that executes after init battle code specific to trainer or wild battles -InitBattle_Common: - ld b, $0 +_InitBattleCommon: + ld b, SET_PAL_BATTLE_BLACK call RunPaletteCommand - callab SlidePlayerAndEnemySilhouettesOnScreen + callfar SlidePlayerAndEnemySilhouettesOnScreen xor a - ld [H_AUTOBGTRANSFERENABLED], a + ldh [hAutoBGTransferEnabled], a ld hl, .emptyString call PrintText call SaveScreenTilesToBuffer1 call ClearScreen ld a, $98 - ld [$ffbd], a + ldh [hAutoBGTransferDest + 1], a ld a, $1 - ld [H_AUTOBGTRANSFERENABLED], a + ldh [hAutoBGTransferEnabled], a call Delay3 ld a, $9c - ld [$ffbd], a + ldh [hAutoBGTransferDest + 1], a call LoadScreenTilesFromBuffer1 - coord hl, 9, 7 - ld bc, $50a + hlcoord 9, 7 + lb bc, 5, 10 call ClearScreenArea - coord hl, 1, 0 - ld bc, $40a + hlcoord 1, 0 + lb bc, 4, 10 call ClearScreenArea call ClearSprites ld a, [wIsInBattle] dec a ; is it a wild battle? ld hl, DrawEnemyHUDAndHPBar - ld b,BANK(DrawEnemyHUDAndHPBar) + ld b, BANK(DrawEnemyHUDAndHPBar) call z, Bankswitch ; draw enemy HUD and HP bar if it's a wild battle - callab StartBattle - callab EndOfBattle + callfar StartBattle + callfar EndOfBattle pop af ld [wLetterPrintingDelayFlags], a pop af ld [wMapPalOffset], a ld a, [wSavedTilesetType] - ld [hTilesetType], a + ldh [hTilesetType], a scf ret .emptyString @@ -157,9 +158,9 @@ _LoadTrainerPic: ld d, a ; de contains pointer to trainer pic ld a, [wLinkState] and a - ld a, Bank(TrainerPics) ; this is where all the trainer pics are (not counting Red's) + ld a, BANK(TrainerPics) ; this is where all the trainer pics are (not counting Red's) jr z, .loadSprite - ld a, Bank(RedPicFront) + ld a, BANK(RedPicFront) .loadSprite call UncompressSpriteFromDE ld de, vFrontPic @@ -172,8 +173,8 @@ LoadMonBackPic: ; been loaded with GetMonHeader. ld a, [wBattleMonSpecies2] ld [wcf91], a - coord hl, 1, 5 - ld bc,$708 + hlcoord 1, 5 + lb bc, 7, 8 call ClearScreenArea ld hl, wMonHBackSprite - wMonHeader call UncompressMonSprite @@ -183,7 +184,7 @@ LoadMonBackPic: ld hl, vSprites ld de, vBackPic ld c, (2*SPRITEBUFFERSIZE)/16 ; count of 16-byte chunks to be copied - ld a, [H_LOADEDROMBANK] + ldh a, [hLoadedROMBank] ld b, a jp CopyVideoData @@ -192,8 +193,8 @@ AnimateSendingOutMon: ld h, a ld a, [wPredefRegisters + 1] ld l, a - ld a, [$ffe1] - ld [H_DOWNARROWBLINKCNT1], a + ldh a, [hStartTileID] + ldh [hDownArrowBlinkCount1], a ld b, $4c ld a, [wIsInBattle] and a @@ -223,7 +224,7 @@ AnimateSendingOutMon: ld bc, -123 .asm_f61f2 add hl, bc - ld a, [H_DOWNARROWBLINKCNT1] + ldh a, [hDownArrowBlinkCount1] add $31 jr CopyUncompressedPicToHL @@ -232,8 +233,8 @@ CopyUncompressedPicToTilemap: ld h, a ld a, [wPredefRegisters + 1] ld l, a - ld a, [$ffe1] -CopyUncompressedPicToHL: + ldh a, [hStartTileID] +CopyUncompressedPicToHL:: ld bc, $707 ld de, $14 push af @@ -281,11 +282,11 @@ CopyUncompressedPicToHL: ret INCLUDE "engine/battle/init_battle_variables.asm" -INCLUDE "engine/battle/moveEffects/focus_energy_effect.asm" -INCLUDE "engine/battle/moveEffects/heal_effect.asm" -INCLUDE "engine/battle/moveEffects/transform_effect.asm" -INCLUDE "engine/battle/moveEffects/reflect_light_screen_effect.asm" -INCLUDE "engine/battle/moveEffects/mist_effect.asm" -INCLUDE "engine/battle/moveEffects/one_hit_ko_effect.asm" -INCLUDE "engine/battle/moveEffects/pay_day_effect.asm" -INCLUDE "engine/battle/moveEffects/paralyze_effect.asm" +INCLUDE "engine/battle/move_effects/focus_energy.asm" +INCLUDE "engine/battle/move_effects/heal.asm" +INCLUDE "engine/battle/move_effects/transform.asm" +INCLUDE "engine/battle/move_effects/reflect_light_screen.asm" +INCLUDE "engine/battle/move_effects/mist.asm" +INCLUDE "engine/battle/move_effects/one_hit_ko.asm" +INCLUDE "engine/battle/move_effects/pay_day.asm" +INCLUDE "engine/battle/move_effects/paralyze.asm" diff --git a/engine/battle/battle_transitions.asm b/engine/battle/battle_transitions.asm index e4392a01..82c3318c 100644 --- a/engine/battle/battle_transitions.asm +++ b/engine/battle/battle_transitions.asm @@ -1,17 +1,17 @@ BattleTransition: ld a, 1 - ld [H_AUTOBGTRANSFERENABLED], a + ldh [hAutoBGTransferEnabled], a call Delay3 xor a - ld [hWY], a + ldh [hWY], a dec a ld [wUpdateSpritesEnabled], a call DelayFrame ; Determine which OAM block is being used by the enemy trainer sprite (if there ; is one). - ld hl, wSpriteStateData1 + 2 - ld a, [hSpriteIndexOrTextID] ; enemy trainer sprite index (0 if wild battle) + ld hl, wSpritePlayerStateData1ImageIndex + ldh a, [hSpriteIndexOrTextID] ; enemy trainer sprite index (0 if wild battle) ld c, a ld b, 0 ld de, $10 @@ -118,9 +118,6 @@ GetBattleTransitionID_CompareLevels: ld [wBattleTransitionSpiralDirection], a ret -; fails to recognize VICTORY_ROAD_2F, VICTORY_ROAD_3F, all ROCKET_HIDEOUT maps, -; POKEMON_MANSION_1F, SEAFOAM_ISLANDS_[B1F-B4F], POWER_PLANT, DIGLETTS_CAVE -; and SILPH_CO_[9-11]F as dungeon maps GetBattleTransitionID_IsDungeonMap: ld a, [wCurMap] ld e, a @@ -151,51 +148,21 @@ GetBattleTransitionID_IsDungeonMap: res 2, c ret -; GetBattleTransitionID_IsDungeonMap checks if wCurMap -; is equal to one of these maps -DungeonMaps1: - db VIRIDIAN_FOREST - db ROCK_TUNNEL_1F - db SEAFOAM_ISLANDS_1F - db ROCK_TUNNEL_B1F - db $FF - -; GetBattleTransitionID_IsDungeonMap checks if wCurMap -; is in between or equal to each pair of maps -DungeonMaps2: - ; all MT_MOON maps - db MT_MOON_1F - db MT_MOON_B2F - - ; all SS_ANNE maps, VICTORY_ROAD_1F, LANCES_ROOM, and HALL_OF_FAME - db SS_ANNE_1F - db HALL_OF_FAME - - ; all POKEMON_TOWER maps and Lavender Town buildings - db LAVENDER_POKECENTER - db LAVENDER_CUBONE_HOUSE - - ; SILPH_CO_[2-8]F, POKEMON_MANSION[2F-B1F], SAFARI_ZONE, and - ; CERULEAN_CAVE maps, except for SILPH_CO_1F - db SILPH_CO_2F - db CERULEAN_CAVE_1F - db $FF +INCLUDE "data/maps/dungeon_maps.asm" LoadBattleTransitionTile: - ld hl, vChars1 + $7f0 + ld hl, vChars1 tile $7f ld de, BattleTransitionTile - lb bc, BANK(BattleTransitionTile), (BattleTransitionTileEnd - BattleTransitionTile) / $10 + lb bc, BANK(BattleTransitionTile), 1 jp CopyVideoData -BattleTransitionTile: - INCBIN "gfx/battle_transition.2bpp" -BattleTransitionTileEnd: +BattleTransitionTile: INCBIN "gfx/overworld/battle_transition.2bpp" BattleTransition_BlackScreen: ld a, $ff - ld [rBGP], a - ld [rOBP0], a - ld [rOBP1], a + ldh [rBGP], a + ldh [rOBP0], a + ldh [rOBP1], a call UpdateGBCPal_BGP call UpdateGBCPal_OBP0 call UpdateGBCPal_OBP1 @@ -212,7 +179,7 @@ BattleTransition_Spiral: call BattleTransition_InwardSpiral jr .done .outwardSpiral - coord hl, 10, 10 + hlcoord 10, 10 ld a, $3 ld [wOutwardSpiralCurrentDirection], a ld a, l @@ -241,7 +208,7 @@ BattleTransition_Spiral: BattleTransition_InwardSpiral: ld a, 7 ld [wInwardSpiralUpdateScreenCounter], a - coord hl, 0, 0 + hlcoord 0, 0 ld c, SCREEN_HEIGHT - 1 ld de, SCREEN_WIDTH call BattleTransition_InwardSpiral_ @@ -359,9 +326,9 @@ BattleTransition_FlashScreen_: ld hl, BattleTransition_FlashScreenPalettes .loop ld a, [hli] - cp $1 + cp 1 jr z, .done - ld [rBGP], a + ldh [rBGP], a call UpdateGBCPal_BGP ld c, 2 call DelayFrames @@ -372,8 +339,19 @@ BattleTransition_FlashScreen_: ret BattleTransition_FlashScreenPalettes: - db $F9,$FE,$FF,$FE,$F9,$E4,$90,$40,$00,$40,$90,$E4 - db $01 ; terminator + db %11111001 + db %11111110 + db %11111111 + db %11111110 + db %11111001 + db %11100100 + db %10010000 + db %01000000 + db %00000000 + db %01000000 + db %10010000 + db %11100100 + db 1 ; end ; used for low level trainer dungeon battles BattleTransition_Shrink: @@ -381,25 +359,25 @@ BattleTransition_Shrink: .loop push bc xor a - ld [H_AUTOBGTRANSFERENABLED], a - coord hl, 0, 7 - coord de, 0, 8 + ldh [hAutoBGTransferEnabled], a + hlcoord 0, 7 + decoord 0, 8 ld bc, -SCREEN_WIDTH * 2 call BattleTransition_CopyTiles1 - coord hl, 0, 10 - coord de, 0, 9 + hlcoord 0, 10 + decoord 0, 9 ld bc, SCREEN_WIDTH * 2 call BattleTransition_CopyTiles1 - coord hl, 8, 0 - coord de, 9, 0 + hlcoord 8, 0 + decoord 9, 0 ld bc, -2 call BattleTransition_CopyTiles2 - coord hl, 11, 0 - coord de, 10, 0 + hlcoord 11, 0 + decoord 10, 0 ld bc, 2 call BattleTransition_CopyTiles2 ld a, $1 - ld [H_AUTOBGTRANSFERENABLED], a + ldh [hAutoBGTransferEnabled], a ld c, 6 call DelayFrames pop bc @@ -413,23 +391,23 @@ BattleTransition_Shrink: BattleTransition_Split: ld c, 9 xor a - ld [H_AUTOBGTRANSFERENABLED], a + ldh [hAutoBGTransferEnabled], a .loop push bc - coord hl, 0, 16 - coord de, 0, 17 + hlcoord 0, 16 + decoord 0, 17 ld bc, -SCREEN_WIDTH * 2 call BattleTransition_CopyTiles1 - coord hl, 0, 1 - coord de, 0, 0 + hlcoord 0, 1 + decoord 0, 0 ld bc, SCREEN_WIDTH * 2 call BattleTransition_CopyTiles1 - coord hl, 18, 0 - coord de, 19, 0 + hlcoord 18, 0 + decoord 19, 0 ld bc, -2 call BattleTransition_CopyTiles2 - coord hl, 1, 0 - coord de, 0, 0 + hlcoord 1, 0 + decoord 0, 0 ld bc, 2 call BattleTransition_CopyTiles2 call BattleTransition_TransferDelay3 @@ -525,10 +503,10 @@ BattleTransition_CopyTiles2: ; used for high level wild dungeon battles BattleTransition_VerticalStripes: ld c, SCREEN_HEIGHT - coord hl, 0, 0 - coord de, 1, 17 + hlcoord 0, 0 + decoord 1, 17 xor a - ld [H_AUTOBGTRANSFERENABLED], a + ldh [hAutoBGTransferEnabled], a .loop push bc push hl @@ -564,10 +542,10 @@ BattleTransition_VerticalStripes_: ; used for low level wild dungeon battles BattleTransition_HorizontalStripes: ld c, SCREEN_WIDTH - coord hl, 0, 0 - coord de, 19, 1 + hlcoord 0, 0 + decoord 19, 1 xor a - ld [H_AUTOBGTRANSFERENABLED], a + ldh [hAutoBGTransferEnabled], a .loop push bc push hl @@ -614,7 +592,7 @@ BattleTransition_FlashScreen: ld b, $3 call BattleTransition_FlashScreen_ xor a - ld [H_AUTOBGTRANSFERENABLED], a + ldh [hAutoBGTransferEnabled], a ret BattleTransition_Circle_Sub1: @@ -633,10 +611,10 @@ BattleTransition_Circle_Sub1: BattleTransition_TransferDelay3: ld a, 1 - ld [H_AUTOBGTRANSFERENABLED], a + ldh [hAutoBGTransferEnabled], a call Delay3 xor a - ld [H_AUTOBGTRANSFERENABLED], a + ldh [hAutoBGTransferEnabled], a ret ; used for low level wild non-dungeon battles @@ -683,87 +661,41 @@ BattleTransition_Circle_Sub2: ld l, a jp BattleTransition_Circle_Sub3 -BattleTransition_HalfCircle1: - db $01 - dw BattleTransition_CircleData1 - dwCoord 18, 6 - - db $01 - dw BattleTransition_CircleData2 - dwCoord 19, 3 - - db $01 - dw BattleTransition_CircleData3 - dwCoord 18, 0 - - db $01 - dw BattleTransition_CircleData4 - dwCoord 14, 0 - - db $01 - dw BattleTransition_CircleData5 - dwCoord 10, 0 +; halves + const_def + const CIRCLE_LEFT + const CIRCLE_RIGHT - db $00 - dw BattleTransition_CircleData5 - dwCoord 9, 0 +half_circle: MACRO + ; quadrant x, circle data, target coord + db \1 + dw \2 + dwcoord \3, \4 +ENDM - db $00 - dw BattleTransition_CircleData4 - dwCoord 5, 0 - - db $00 - dw BattleTransition_CircleData3 - dwCoord 1, 0 - - db $00 - dw BattleTransition_CircleData2 - dwCoord 0, 3 - - db $00 - dw BattleTransition_CircleData1 - dwCoord 1, 6 +BattleTransition_HalfCircle1: + half_circle CIRCLE_RIGHT, BattleTransition_CircleData1, 18, 6 + half_circle CIRCLE_RIGHT, BattleTransition_CircleData2, 19, 3 + half_circle CIRCLE_RIGHT, BattleTransition_CircleData3, 18, 0 + half_circle CIRCLE_RIGHT, BattleTransition_CircleData4, 14, 0 + half_circle CIRCLE_RIGHT, BattleTransition_CircleData5, 10, 0 + half_circle CIRCLE_LEFT, BattleTransition_CircleData5, 9, 0 + half_circle CIRCLE_LEFT, BattleTransition_CircleData4, 5, 0 + half_circle CIRCLE_LEFT, BattleTransition_CircleData3, 1, 0 + half_circle CIRCLE_LEFT, BattleTransition_CircleData2, 0, 3 + half_circle CIRCLE_LEFT, BattleTransition_CircleData1, 1, 6 BattleTransition_HalfCircle2: - db $00 - dw BattleTransition_CircleData1 - dwCoord 1, 11 - - db $00 - dw BattleTransition_CircleData2 - dwCoord 0, 14 - - db $00 - dw BattleTransition_CircleData3 - dwCoord 1, 17 - - db $00 - dw BattleTransition_CircleData4 - dwCoord 5, 17 - - db $00 - dw BattleTransition_CircleData5 - dwCoord 9, 17 - - db $01 - dw BattleTransition_CircleData5 - dwCoord 10, 17 - - db $01 - dw BattleTransition_CircleData4 - dwCoord 14, 17 - - db $01 - dw BattleTransition_CircleData3 - dwCoord 18, 17 - - db $01 - dw BattleTransition_CircleData2 - dwCoord 19, 14 - - db $01 - dw BattleTransition_CircleData1 - dwCoord 18, 11 + half_circle CIRCLE_LEFT, BattleTransition_CircleData1, 1, 11 + half_circle CIRCLE_LEFT, BattleTransition_CircleData2, 0, 14 + half_circle CIRCLE_LEFT, BattleTransition_CircleData3, 1, 17 + half_circle CIRCLE_LEFT, BattleTransition_CircleData4, 5, 17 + half_circle CIRCLE_LEFT, BattleTransition_CircleData5, 9, 17 + half_circle CIRCLE_RIGHT, BattleTransition_CircleData5, 10, 17 + half_circle CIRCLE_RIGHT, BattleTransition_CircleData4, 14, 17 + half_circle CIRCLE_RIGHT, BattleTransition_CircleData3, 18, 17 + half_circle CIRCLE_RIGHT, BattleTransition_CircleData2, 19, 14 + half_circle CIRCLE_RIGHT, BattleTransition_CircleData1, 18, 11 BattleTransition_Circle_Sub3: push hl @@ -792,7 +724,7 @@ BattleTransition_Circle_Sub3: add hl, bc ld a, [de] inc de - cp $ff + cp -1 ret z and a jr z, BattleTransition_Circle_Sub3 @@ -810,17 +742,8 @@ BattleTransition_Circle_Sub3: jr nz, .loop2 jr BattleTransition_Circle_Sub3 -BattleTransition_CircleData1: - db $02,$03,$05,$04,$09,$FF - -BattleTransition_CircleData2: - db $01,$01,$02,$02,$04,$02,$04,$02,$03,$FF - -BattleTransition_CircleData3: - db $02,$01,$03,$01,$04,$01,$04,$01,$04,$01,$03,$01,$02,$01,$01,$01,$01,$FF - -BattleTransition_CircleData4: - db $04,$01,$04,$00,$03,$01,$03,$00,$02,$01,$02,$00,$01,$FF - -BattleTransition_CircleData5: - db $04,$00,$03,$00,$03,$00,$02,$00,$02,$00,$01,$00,$01,$00,$01,$FF +BattleTransition_CircleData1: db 2, 3, 5, 4, 9, -1 +BattleTransition_CircleData2: db 1, 1, 2, 2, 4, 2, 4, 2, 3, -1 +BattleTransition_CircleData3: db 2, 1, 3, 1, 4, 1, 4, 1, 4, 1, 3, 1, 2, 1, 1, 1, 1, -1 +BattleTransition_CircleData4: db 4, 1, 4, 0, 3, 1, 3, 0, 2, 1, 2, 0, 1, -1 +BattleTransition_CircleData5: db 4, 0, 3, 0, 3, 0, 2, 0, 2, 0, 1, 0, 1, 0, 1, -1 diff --git a/engine/battle/common_text.asm b/engine/battle/common_text.asm index 1c85efe9..95c06bf5 100644 --- a/engine/battle/common_text.asm +++ b/engine/battle/common_text.asm @@ -5,18 +5,18 @@ PrintBeginningBattleText: ld a, [wCurMap] cp POKEMON_TOWER_3F jr c, .notPokemonTower - cp MR_FUJIS_HOUSE + cp POKEMON_TOWER_7F + 1 jr c, .pokemonTower .notPokemonTower - ld a,[wBattleType] + ld a, [wBattleType] cp BATTLE_TYPE_PIKACHU - jr nz,.notPikachuBattle - callab IsPlayerPikachuAsleepInParty - ld e,$24 - jr c,.asm_f4026 - ld e,$a + jr nz, .notPikachuBattle + callfar IsPlayerPikachuAsleepInParty + ld e, $24 + jr c, .asm_f4026 + ld e, $a .asm_f4026 - callab PlayPikachuSoundClip + callfar PlayPikachuSoundClip jr .continue .notPikachuBattle ld a, [wEnemyMonSpecies2] @@ -39,7 +39,7 @@ PrintBeginningBattleText: and a jr nz, .doNotDrawPokeballs push hl - callab DrawAllPokeballs + callfar DrawAllPokeballs pop hl .doNotDrawPokeballs call PrintText @@ -54,7 +54,7 @@ PrintBeginningBattleText: ld a, b and a jr z, .noSilphScope - callab LoadEnemyMonData + callfar LoadEnemyMonData jr .notPokemonTower .noSilphScope ld hl, EnemyAppearedText @@ -70,8 +70,8 @@ PrintBeginningBattleText: call PrintText ld hl, UnveiledGhostText call PrintText - callab LoadEnemyMonData - callab MarowakAnim + callfar LoadEnemyMonData + callfar MarowakAnim ld hl, WildMonAppearedText call PrintText @@ -87,28 +87,28 @@ PrintBeginningBattleText: ret WildMonAppearedText: - TX_FAR _WildMonAppearedText - db "@" + text_far _WildMonAppearedText + text_end HookedMonAttackedText: - TX_FAR _HookedMonAttackedText - db "@" + text_far _HookedMonAttackedText + text_end EnemyAppearedText: - TX_FAR _EnemyAppearedText - db "@" + text_far _EnemyAppearedText + text_end TrainerWantsToFightText: - TX_FAR _TrainerWantsToFightText - db "@" + text_far _TrainerWantsToFightText + text_end UnveiledGhostText: - TX_FAR _UnveiledGhostText - db "@" + text_far _UnveiledGhostText + text_end GhostCantBeIDdText: - TX_FAR _GhostCantBeIDdText - db "@" + text_far _GhostCantBeIDdText + text_end PrintSendOutMonMessage: ld hl, wEnemyMonHP @@ -117,16 +117,16 @@ PrintSendOutMonMessage: ld hl, GoText jr z, .printText xor a - ld [H_MULTIPLICAND], a + ldh [hMultiplicand], a ld hl, wEnemyMonHP ld a, [hli] ld [wLastSwitchInEnemyMonHP], a - ld [H_MULTIPLICAND + 1], a + ldh [hMultiplicand + 1], a ld a, [hl] ld [wLastSwitchInEnemyMonHP + 1], a - ld [H_MULTIPLICAND + 2], a + ldh [hMultiplicand + 2], a ld a, 25 - ld [H_MULTIPLIER], a + ldh [hMultiplier], a call Multiply ld hl, wEnemyMonMaxHP ld a, [hli] @@ -137,9 +137,9 @@ PrintSendOutMonMessage: rr b ld a, b ld b, 4 - ld [H_DIVISOR], a ; enemy mon max HP divided by 4 + ldh [hDivisor], a ; enemy mon max HP divided by 4 call Divide - ld a, [H_QUOTIENT + 3] ; a = (enemy mon current HP * 25) / (enemy max HP / 4); this approximates the current percentage of max HP + ldh a, [hQuotient + 3] ; a = (enemy mon current HP * 25) / (enemy max HP / 4); this approximates the current percentage of max HP ld hl, GoText ; 70% or greater cp 70 jr nc, .printText @@ -154,39 +154,39 @@ PrintSendOutMonMessage: jp PrintText GoText: - TX_FAR _GoText - TX_ASM + text_far _GoText + text_asm jr PrintPlayerMon1Text DoItText: - TX_FAR _DoItText - TX_ASM + text_far _DoItText + text_asm jr PrintPlayerMon1Text GetmText: - TX_FAR _GetmText - TX_ASM + text_far _GetmText + text_asm jr PrintPlayerMon1Text EnemysWeakText: - TX_FAR _EnemysWeakText - TX_ASM + text_far _EnemysWeakText + text_asm PrintPlayerMon1Text: ld hl, PlayerMon1Text ret PlayerMon1Text: - TX_FAR _PlayerMon1Text - db "@" + text_far _PlayerMon1Text + text_end RetreatMon: ld hl, PlayerMon2Text jp PrintText PlayerMon2Text: - TX_FAR _PlayerMon2Text - TX_ASM + text_far _PlayerMon2Text + text_asm push de push bc ld hl, wEnemyMonHP + 1 @@ -195,14 +195,14 @@ PlayerMon2Text: dec hl ld a, [de] sub b - ld [H_MULTIPLICAND + 2], a + ldh [hMultiplicand + 2], a dec de ld b, [hl] ld a, [de] sbc b - ld [H_MULTIPLICAND + 1], a + ldh [hMultiplicand + 1], a ld a, 25 - ld [H_MULTIPLIER], a + ldh [hMultiplier], a call Multiply ld hl, wEnemyMonMaxHP ld a, [hli] @@ -213,11 +213,11 @@ PlayerMon2Text: rr b ld a, b ld b, 4 - ld [H_DIVISOR], a + ldh [hDivisor], a call Divide pop bc pop de - ld a, [H_QUOTIENT + 3] ; a = ((LastSwitchInEnemyMonHP - CurrentEnemyMonHP) / 25) / (EnemyMonMaxHP / 4) + ldh a, [hQuotient + 3] ; a = ((LastSwitchInEnemyMonHP - CurrentEnemyMonHP) / 25) / (EnemyMonMaxHP / 4) ; Assuming that the enemy mon hasn't gained HP since the last switch in, ; a approximates the percentage that the enemy mon's total HP has decreased ; since the last switch in. @@ -236,18 +236,18 @@ PlayerMon2Text: ret EnoughText: - TX_FAR _EnoughText - TX_ASM + text_far _EnoughText + text_asm jr PrintComeBackText OKExclamationText: - TX_FAR _OKExclamationText - TX_ASM + text_far _OKExclamationText + text_asm jr PrintComeBackText GoodText: - TX_FAR _GoodText - TX_ASM + text_far _GoodText + text_asm jr PrintComeBackText PrintComeBackText: @@ -255,5 +255,5 @@ PrintComeBackText: ret ComeBackText: - TX_FAR _ComeBackText - db "@" + text_far _ComeBackText + text_end diff --git a/engine/battle/core.asm b/engine/battle/core.asm index 60146902..f66f509f 100755 --- a/engine/battle/core.asm +++ b/engine/battle/core.asm @@ -1,107 +1,17 @@ BattleCore: -; These are move effects (second value from the Moves table in bank $E). -ResidualEffects1: -; most non-side effects - db CONVERSION_EFFECT - db HAZE_EFFECT - db SWITCH_AND_TELEPORT_EFFECT - db MIST_EFFECT - db FOCUS_ENERGY_EFFECT - db CONFUSION_EFFECT - db HEAL_EFFECT - db TRANSFORM_EFFECT - db LIGHT_SCREEN_EFFECT - db REFLECT_EFFECT - db POISON_EFFECT - db PARALYZE_EFFECT - db SUBSTITUTE_EFFECT - db MIMIC_EFFECT - db LEECH_SEED_EFFECT - db SPLASH_EFFECT - db -1 -SetDamageEffects: -; moves that do damage but not through normal calculations -; e.g., Super Fang, Psywave - db SUPER_FANG_EFFECT - db SPECIAL_DAMAGE_EFFECT - db -1 -ResidualEffects2: -; non-side effects not included in ResidualEffects1 -; stat-affecting moves, sleep-inflicting moves, and Bide -; e.g., Meditate, Bide, Hypnosis - db $01 - db ATTACK_UP1_EFFECT - db DEFENSE_UP1_EFFECT - db SPEED_UP1_EFFECT - db SPECIAL_UP1_EFFECT - db ACCURACY_UP1_EFFECT - db EVASION_UP1_EFFECT - db ATTACK_DOWN1_EFFECT - db DEFENSE_DOWN1_EFFECT - db SPEED_DOWN1_EFFECT - db SPECIAL_DOWN1_EFFECT - db ACCURACY_DOWN1_EFFECT - db EVASION_DOWN1_EFFECT - db BIDE_EFFECT - db SLEEP_EFFECT - db ATTACK_UP2_EFFECT - db DEFENSE_UP2_EFFECT - db SPEED_UP2_EFFECT - db SPECIAL_UP2_EFFECT - db ACCURACY_UP2_EFFECT - db EVASION_UP2_EFFECT - db ATTACK_DOWN2_EFFECT - db DEFENSE_DOWN2_EFFECT - db SPEED_DOWN2_EFFECT - db SPECIAL_DOWN2_EFFECT - db ACCURACY_DOWN2_EFFECT - db EVASION_DOWN2_EFFECT - db -1 -AlwaysHappenSideEffects: -; Attacks that aren't finished after they faint the opponent. - db DRAIN_HP_EFFECT - db EXPLODE_EFFECT - db DREAM_EATER_EFFECT - db PAY_DAY_EFFECT - db TWO_TO_FIVE_ATTACKS_EFFECT - db $1E - db ATTACK_TWICE_EFFECT - db RECOIL_EFFECT - db TWINEEDLE_EFFECT - db RAGE_EFFECT - db -1 -SpecialEffects: -; Effects from arrays 2, 4, and 5B, minus Twineedle and Rage. -; Includes all effects that do not need to be called at the end of -; ExecutePlayerMove (or ExecuteEnemyMove), because they have already been handled - db DRAIN_HP_EFFECT - db EXPLODE_EFFECT - db DREAM_EATER_EFFECT - db PAY_DAY_EFFECT - db SWIFT_EFFECT - db TWO_TO_FIVE_ATTACKS_EFFECT - db $1E - db CHARGE_EFFECT - db SUPER_FANG_EFFECT - db SPECIAL_DAMAGE_EFFECT - db FLY_EFFECT - db ATTACK_TWICE_EFFECT - db JUMP_KICK_EFFECT - db RECOIL_EFFECT - ; fallthrough to Next EffectsArray -SpecialEffectsCont: -; damaging moves whose effect is executed prior to damage calculation - db THRASH_PETAL_DANCE_EFFECT - db TRAPPING_EFFECT - db -1 +INCLUDE "data/battle/residual_effects_1.asm" +INCLUDE "data/battle/set_damage_effects.asm" +INCLUDE "data/battle/residual_effects_2.asm" +INCLUDE "data/battle/always_happen_effects.asm" +INCLUDE "data/battle/special_effects.asm" SlidePlayerAndEnemySilhouettesOnScreen: call LoadPlayerBackPic ld a, MESSAGE_BOX ; the usual text box at the bottom of the screen ld [wTextBoxID], a call DisplayTextBoxID - coord hl, 1, 5 + hlcoord 1, 5 lb bc, 3, 7 call ClearScreenArea call DisableLCD @@ -117,7 +27,7 @@ SlidePlayerAndEnemySilhouettesOnScreen: or c jr nz, .clearBackgroundLoop ; copy the work RAM tile map to VRAM - coord hl, 0, 0 + hlcoord 0, 0 ld de, vBGMap0 ld b, 18 ; number of rows .copyRowLoop @@ -138,25 +48,25 @@ SlidePlayerAndEnemySilhouettesOnScreen: jr nz, .copyRowLoop call EnableLCD ld a, $90 - ld [hWY], a - ld [rWY], a + ldh [hWY], a + ldh [rWY], a xor a - ld [hTilesetType], a - ld [hSCY], a + ldh [hTilesetType], a + ldh [hSCY], a dec a ld [wUpdateSpritesEnabled], a call Delay3 xor a - ld [H_AUTOBGTRANSFERENABLED], a + ldh [hAutoBGTransferEnabled], a ld b, $70 ld c, $90 ld a, c - ld [hSCX], a + ldh [hSCX], a call DelayFrame ld a, %11100100 ; inverted palette for silhouette effect - ld [rBGP], a - ld [rOBP0], a - ld [rOBP1], a + ldh [rBGP], a + ldh [rOBP0], a + ldh [rOBP1], a call UpdateGBCPal_BGP call UpdateGBCPal_OBP0 call UpdateGBCPal_OBP1 @@ -171,26 +81,26 @@ SlidePlayerAndEnemySilhouettesOnScreen: call SetScrollXForSlidingPlayerBodyLeft ; end background scrolling on line $60 call SlidePlayerHeadLeft ld a, c - ld [hSCX], a + ldh [hSCX], a dec c dec c jr nz, .slideSilhouettesLoop ld a, $1 - ld [H_AUTOBGTRANSFERENABLED], a + ldh [hAutoBGTransferEnabled], a ld a, $31 - ld [hStartTileID], a - coord hl, 1, 5 + ldh [hStartTileID], a + hlcoord 1, 5 predef CopyUncompressedPicToTilemap xor a - ld [hWY], a - ld [rWY], a + ldh [hWY], a + ldh [rWY], a inc a - ld [H_AUTOBGTRANSFERENABLED], a + ldh [hAutoBGTransferEnabled], a call Delay3 ld b, SET_PAL_BATTLE call RunPaletteCommand call HideSprites - jpab PrintBeginningBattleText + jpfar PrintBeginningBattleText ; when a battle is starting, silhouettes of the player's pic and the enemy's pic are slid onto the screen ; the lower of the player's pic (his body) is part of the background, but his head is a sprite @@ -211,13 +121,13 @@ SlidePlayerHeadLeft: ret SetScrollXForSlidingPlayerBodyLeft: - ld a, [rLY] + ldh a, [rLY] cp l jr nz, SetScrollXForSlidingPlayerBodyLeft ld a, h - ld [rSCX], a + ldh [rSCX], a .loop - ld a, [rLY] + ldh a, [rLY] cp h jr z, .loop ret @@ -277,7 +187,7 @@ StartBattle: ld hl, .outOfSafariBallsText jp PrintText .notOutOfSafariBalls - callab PrintSafariZoneBattleText + callfar PrintSafariZoneBattleText ld a, [wEnemyMonSpeed + 1] add a ld b, a ; init b (which is later compared with random value) to (enemy speed % 256) * 2 @@ -306,8 +216,8 @@ StartBattle: jr EnemyRan ; if b was greater than the random value, the enemy runs .outOfSafariBallsText - TX_FAR _OutOfSafariBallsText - db "@" + text_far _OutOfSafariBallsText + text_end .playerSendOutFirstMon xor a @@ -331,7 +241,7 @@ StartBattle: ld [wcf91], a ld [wBattleMonSpecies2], a call LoadScreenTilesFromBuffer1 - coord hl, 1, 5 + hlcoord 1, 5 ld a, $9 call SlideTrainerPicOffScreen call SaveScreenTilesToBuffer1 @@ -365,16 +275,16 @@ EnemyRan: ld a, SFX_RUN call PlaySoundWaitForCurrent xor a - ld [H_WHOSETURN], a - jpab AnimationSlideEnemyMonOff + ldh [hWhoseTurn], a + jpfar AnimationSlideEnemyMonOff WildRanText: - TX_FAR _WildRanText - db "@" + text_far _WildRanText + text_end EnemyRanText: - TX_FAR _EnemyRanText - db "@" + text_far _EnemyRanText + text_end MainInBattleLoop: call ReadPlayerMonCurHPAndStatus @@ -464,7 +374,7 @@ MainInBattleLoop: jr nz, .specialMoveNotUsed ld [wPlayerSelectedMove], a .specialMoveNotUsed - callab SwitchEnemyMon + callfar SwitchEnemyMon .noLinkBattle ld a, [wPlayerSelectedMove] cp QUICK_ATTACK @@ -497,7 +407,7 @@ MainInBattleLoop: jr nc, .playerMovesFirst ; if player is faster jr .enemyMovesFirst ; if enemy is faster .speedEqual ; 50/50 chance for both players - ld a, [hSerialConnectionStatus] + ldh a, [hSerialConnectionStatus] cp USING_INTERNAL_CLOCK jr z, .invertOutcome call BattleRandom @@ -511,8 +421,8 @@ MainInBattleLoop: jr .playerMovesFirst .enemyMovesFirst ld a, $1 - ld [H_WHOSETURN], a - callab TrainerAI + ldh [hWhoseTurn], a + callfar TrainerAI jr c, .AIActionUsedEnemyFirst call ExecuteEnemyMove ld a, [wEscapedFromBattle] @@ -549,8 +459,8 @@ MainInBattleLoop: jp z, HandlePlayerMonFainted call DrawHUDsAndHPBars ld a, $1 - ld [H_WHOSETURN], a - callab TrainerAI + ldh [hWhoseTurn], a + callfar TrainerAI jr c, .AIActionUsedPlayerFirst call ExecuteEnemyMove ld a, [wEscapedFromBattle] @@ -569,7 +479,7 @@ MainInBattleLoop: HandlePoisonBurnLeechSeed: ld hl, wBattleMonHP ld de, wBattleMonStatus - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a jr z, .playersTurn ld hl, wEnemyMonHP @@ -594,7 +504,7 @@ HandlePoisonBurnLeechSeed: call HandlePoisonBurnLeechSeed_DecreaseOwnHP .notBurnedOrPoisoned ld de, wPlayerBattleStatus2 - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a jr z, .playersTurn2 ld de, wEnemyBattleStatus2 @@ -603,16 +513,16 @@ HandlePoisonBurnLeechSeed: add a jr nc, .notLeechSeeded push hl - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] push af xor $1 - ld [H_WHOSETURN], a + ldh [hWhoseTurn], a xor a ld [wAnimationType], a ld a, ABSORB call PlayMoveAnimation ; play leech seed animation (from opposing mon) pop af - ld [H_WHOSETURN], a + ldh [hWhoseTurn], a pop hl call HandlePoisonBurnLeechSeed_DecreaseOwnHP call HandlePoisonBurnLeechSeed_IncreaseEnemyHP @@ -631,16 +541,16 @@ HandlePoisonBurnLeechSeed: ret HurtByPoisonText: - TX_FAR _HurtByPoisonText - db "@" + text_far _HurtByPoisonText + text_end HurtByBurnText: - TX_FAR _HurtByBurnText - db "@" + text_far _HurtByBurnText + text_end HurtByLeechSeedText: - TX_FAR _HurtByLeechSeedText - db "@" + text_far _HurtByLeechSeedText + text_end ; decreases the mon's current HP by 1/16 of the Max HP (multiplied by number of toxic ticks if active) ; note that the toxic ticks are considered even if the damage is not poison (hence the Leech Seed glitch) @@ -670,7 +580,7 @@ HandlePoisonBurnLeechSeed_DecreaseOwnHP: .nonZeroDamage ld hl, wPlayerBattleStatus3 ld de, wPlayerToxicCounter - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a jr z, .playersTurn ld hl, wEnemyBattleStatus3 @@ -681,7 +591,7 @@ HandlePoisonBurnLeechSeed_DecreaseOwnHP: ld a, [de] ; increment toxic counter inc a ld [de], a - ld hl, $0000 + ld hl, 0 .toxicTicksLoop add hl, bc dec a @@ -717,7 +627,7 @@ HandlePoisonBurnLeechSeed_DecreaseOwnHP: HandlePoisonBurnLeechSeed_IncreaseEnemyHP: push hl ld hl, wEnemyMonMaxHP - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a jr z, .playersTurn ld hl, wBattleMonMaxHP @@ -754,23 +664,23 @@ HandlePoisonBurnLeechSeed_IncreaseEnemyHP: ld [hl], a ld [wHPBarNewHP], a .noOverfullHeal - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] xor $1 - ld [H_WHOSETURN], a + ldh [hWhoseTurn], a call UpdateCurMonHPBar - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] xor $1 - ld [H_WHOSETURN], a + ldh [hWhoseTurn], a pop hl ret UpdateCurMonHPBar: - coord hl, 10, 9 ; tile pointer to player HP bar - ld a, [H_WHOSETURN] + hlcoord 10, 9 ; tile pointer to player HP bar + ldh a, [hWhoseTurn] and a ld a, $1 jr z, .playersTurn - coord hl, 2, 2 ; tile pointer to enemy HP bar + hlcoord 2, 2 ; tile pointer to enemy HP bar xor a .playersTurn push bc @@ -866,10 +776,10 @@ FaintEnemyPokemon: ld hl, wPlayerUsedMove ld [hli], a ld [hl], a - coord hl, 12, 5 - coord de, 12, 6 + hlcoord 12, 5 + decoord 12, 6 call SlideDownFaintedMonPic - coord hl, 0, 0 + hlcoord 0, 0 lb bc, 4, 11 call ClearScreenArea ld a, [wIsInBattle] @@ -936,7 +846,7 @@ FaintEnemyPokemon: .giveExpToMonsThatFought xor a ld [wBoostExpByExpAll], a - callab GainExperience + callfar GainExperience pop af ret z ; return if no exp all @@ -954,11 +864,11 @@ FaintEnemyPokemon: jr nz, .gainExpFlagsLoop ld a, b ld [wPartyGainExpFlags], a - jpab GainExperience + jpfar GainExperience EnemyMonFaintedText: - TX_FAR _EnemyMonFaintedText - db "@" + text_far _EnemyMonFaintedText + text_end EndLowHealthAlarm: ; This function is called when the player has the won the battle. It turns off @@ -993,11 +903,11 @@ ReplaceFaintedEnemyMon: ld e, $30 call GetBattleHealthBarColor setpal SHADE_BLACK, SHADE_DARK, SHADE_LIGHT, SHADE_WHITE - ld [rOBP0], a - ld [rOBP1], a + ldh [rOBP0], a + ldh [rOBP1], a call UpdateGBCPal_OBP0 call UpdateGBCPal_OBP1 - callab DrawEnemyPokeballs + callfar DrawEnemyPokeballs ld a, [wLinkState] cp LINK_STATE_BATTLING jr nz, .notLinkBattle @@ -1025,7 +935,7 @@ TrainerBattleVictory: ld b, MUSIC_DEFEATED_TRAINER .gymleader ld a, [wTrainerClass] - cp SONY3 ; final battle against rival + cp RIVAL3 ; final battle against rival jr nz, .notrival ld b, MUSIC_DEFEATED_GYM_LEADER ld hl, wFlags_D733 @@ -1053,12 +963,12 @@ TrainerBattleVictory: predef_jump AddBCDPredef MoneyForWinningText: - TX_FAR _MoneyForWinningText - db "@" + text_far _MoneyForWinningText + text_end TrainerDefeatedText: - TX_FAR _TrainerDefeatedText - db "@" + text_far _TrainerDefeatedText + text_end PlayBattleVictoryMusic: push af @@ -1124,11 +1034,11 @@ RemoveFaintedPlayerMon: ld [hl], a ld [wBattleMonStatus], a call ReadPlayerMonCurHPAndStatus - coord hl, 9, 7 + hlcoord 9, 7 lb bc, 5, 11 call ClearScreenArea - coord hl, 1, 10 - coord de, 1, 11 + hlcoord 1, 10 + decoord 1, 11 call SlideDownFaintedMonPic ld a, $1 ld [wBattleResult], a @@ -1143,10 +1053,10 @@ RemoveFaintedPlayerMon: ld a, [wPlayerMonNumber] ld [wWhichPokemon], a - callab IsThisPartymonStarterPikachu_Party + callfar IsThisPartymonStarterPikachu_Party jr nc, .notPlayerPikachu ld e, $3 - callab PlayPikachuSoundClip + callfar PlayPikachuSoundClip jr .printText .notPlayerPikachu ld a, [wBattleMonSpecies] @@ -1173,8 +1083,8 @@ RemoveFaintedPlayerMon: ret PlayerMonFaintedText: - TX_FAR _PlayerMonFaintedText - db "@" + text_far _PlayerMonFaintedText + text_end ; asks if you want to use next mon ; stores whether you ran in C flag @@ -1188,7 +1098,7 @@ DoUseNextMonDialogue: ld hl, UseNextMonText call PrintText .displayYesNoBox - coord hl, 13, 9 + hlcoord 13, 9 lb bc, 10, 14 ld a, TWO_OPTION_MENU ld [wTextBoxID], a @@ -1207,8 +1117,8 @@ DoUseNextMonDialogue: jp TryRunningFromBattle UseNextMonText: - TX_FAR _UseNextMonText - db "@" + text_far _UseNextMonText + text_end ; choose next player mon to send out ; stores whether enemy mon has no HP left in Z flag @@ -1263,9 +1173,9 @@ HandlePlayerBlackOut: cp LINK_STATE_BATTLING jr z, .notSony1Battle ld a, [wCurOpponent] - cp OPP_SONY1 + cp OPP_RIVAL1 jr nz, .notSony1Battle - coord hl, 0, 0 ; sony 1 battle + hlcoord 0, 0 ; sony 1 battle lb bc, 8, 21 call ClearScreenArea call ScrollTrainerPicAfterBattle @@ -1294,19 +1204,19 @@ HandlePlayerBlackOut: ret Sony1WinText: - TX_FAR _Sony1WinText - db "@" + text_far _Sony1WinText + text_end PlayerBlackedOutText2: - TX_FAR _PlayerBlackedOutText2 - db "@" + text_far _PlayerBlackedOutText2 + text_end LinkBattleLostText: - TX_FAR _LinkBattleLostText - db "@" + text_far _LinkBattleLostText + text_end ; slides pic of fainted mon downwards until it disappears -; bug: when this is called, [H_AUTOBGTRANSFERENABLED] is non-zero, so there is screen tearing +; bug: when this is called, [hAutoBGTransferEnabled] is non-zero, so there is screen tearing SlideDownFaintedMonPic: ld a, [wd730] push af @@ -1359,9 +1269,9 @@ SevenSpacesText: ; slides the player or enemy trainer off screen ; a is the number of tiles to slide it horizontally (always 9 for the player trainer or 8 for the enemy trainer) ; if a is 8, the slide is to the right, else it is to the left -; bug: when this is called, [H_AUTOBGTRANSFERENABLED] is non-zero, so there is screen tearing +; bug: when this is called, [hAutoBGTransferEnabled] is non-zero, so there is screen tearing SlideTrainerPicOffScreen: - ld [hSlideAmount], a + ldh [hSlideAmount], a ld c, a .slideStepLoop ; each iteration, the trainer pic is slid one tile left/right push bc @@ -1369,10 +1279,10 @@ SlideTrainerPicOffScreen: ld b, 7 ; number of rows .rowLoop push hl - ld a, [hSlideAmount] + ldh a, [hSlideAmount] ld c, a .columnLoop - ld a, [hSlideAmount] + ldh a, [hSlideAmount] cp 8 jr z, .slideRight .slideLeft ; slide player sprite off screen @@ -1435,7 +1345,7 @@ EnemySendOutFirstMon: ld [wAICount], a ld hl, wPlayerBattleStatus1 res 5, [hl] - coord hl, 18, 0 + hlcoord 18, 0 ld a, 8 call SlideTrainerPicOffScreen call PrintEmptyString @@ -1505,7 +1415,7 @@ EnemySendOutFirstMon: jr nz, .next4 ld hl, TrainerAboutToUseText call PrintText - coord hl, 0, 7 + hlcoord 0, 7 lb bc, 8, 1 ld a, TWO_OPTION_MENU ld [wTextBoxID], a @@ -1540,7 +1450,7 @@ EnemySendOutFirstMon: call LoadScreenTilesFromBuffer1 .next4 call ClearSprites - coord hl, 0, 0 + hlcoord 0, 0 lb bc, 4, 11 call ClearScreenArea ld b, SET_PAL_BATTLE @@ -1555,8 +1465,8 @@ EnemySendOutFirstMon: ld de, vFrontPic call LoadMonFrontSprite ld a, -$31 - ld [hStartTileID], a - coord hl, 15, 6 + ldh [hStartTileID], a + hlcoord 15, 6 predef AnimateSendingOutMon ld a, [wEnemyMonSpecies2] call PlayCry @@ -1571,16 +1481,16 @@ EnemySendOutFirstMon: jp SwitchPlayerMon TrainerAboutToUseText: - TX_FAR _TrainerAboutToUseText - db "@" + text_far _TrainerAboutToUseText + text_end TrainerSentOutText: - TX_FAR _TrainerSentOutText - db "@" + text_far _TrainerSentOutText + text_end ; tests if the player has any pokemon that are not fainted ; sets d = 0 if all fainted, d != 0 if some mons are still alive -AnyPartyAlive: +AnyPartyAlive:: ld a, [wPartyCount] ld e, a xor a @@ -1616,8 +1526,8 @@ HasMonFainted: ret NoWillText: - TX_FAR _NoWillText - db "@" + text_far _NoWillText + text_end ; try to run from battle (hl = player speed, de = enemy speed) ; stores whether the attempt was successful in carry flag @@ -1639,32 +1549,32 @@ TryRunningFromBattle: inc a ld [wNumRunAttempts], a ld a, [hli] - ld [H_MULTIPLICAND + 1], a + ldh [hMultiplicand + 1], a ld a, [hl] - ld [H_MULTIPLICAND + 2], a + ldh [hMultiplicand + 2], a ld a, [de] - ld [hEnemySpeed], a + ldh [hEnemySpeed], a inc de ld a, [de] - ld [hEnemySpeed + 1], a + ldh [hEnemySpeed + 1], a call LoadScreenTilesFromBuffer1 - ld de, H_MULTIPLICAND + 1 + ld de, hMultiplicand + 1 ld hl, hEnemySpeed ld c, 2 call StringCmp jr nc, .canEscape ; jump if player speed greater than enemy speed xor a - ld [H_MULTIPLICAND], a + ldh [hMultiplicand], a ld a, 32 - ld [H_MULTIPLIER], a + ldh [hMultiplier], a call Multiply ; multiply player speed by 32 - ld a, [H_PRODUCT + 2] - ld [H_DIVIDEND], a - ld a, [H_PRODUCT + 3] - ld [H_DIVIDEND + 1], a - ld a, [hEnemySpeed] + ldh a, [hProduct + 2] + ldh [hDividend], a + ldh a, [hProduct + 3] + ldh [hDividend + 1], a + ldh a, [hEnemySpeed] ld b, a - ld a, [hEnemySpeed + 1] + ldh a, [hEnemySpeed + 1] ; divide enemy speed by 4 srl b rr a @@ -1672,10 +1582,10 @@ TryRunningFromBattle: rr a and a jr z, .canEscape ; jump if enemy speed divided by 4, mod 256 is 0 - ld [H_DIVISOR], a ; ((enemy speed / 4) % 256) + ldh [hDivisor], a ; ((enemy speed / 4) % 256) ld b, $2 call Divide ; divide (player speed * 32) by ((enemy speed / 4) % 256) - ld a, [H_QUOTIENT + 2] + ldh a, [hQuotient + 2] and a ; is the quotient greater than 256? jr nz, .canEscape ; if so, the player can escape ld a, [wNumRunAttempts] @@ -1685,15 +1595,15 @@ TryRunningFromBattle: dec c jr z, .compareWithRandomValue ld b, 30 - ld a, [H_QUOTIENT + 3] + ldh a, [hQuotient + 3] add b - ld [H_QUOTIENT + 3], a + ldh [hQuotient + 3], a jr c, .canEscape jr .loop .compareWithRandomValue call BattleRandom ld b, a - ld a, [H_QUOTIENT + 3] + ldh a, [hQuotient + 3] cp b jr nc, .canEscape ; if the random value was less than or equal to the quotient ; plus 30 times the number of attempts, the player can escape @@ -1741,16 +1651,16 @@ TryRunningFromBattle: ret CantEscapeText: - TX_FAR _CantEscapeText - db "@" + text_far _CantEscapeText + text_end NoRunningText: - TX_FAR _NoRunningText - db "@" + text_far _NoRunningText + text_end GotAwayText: - TX_FAR _GotAwayText - db "@" + text_far _GotAwayText + text_end ; copies from party data to battle mon data when sending out a new player mon LoadBattleMonFromParty: @@ -1851,7 +1761,7 @@ LoadEnemyMonFromParty: ret SendOutMon: - callab PrintSendOutMonMessage + callfar PrintSendOutMonMessage ld hl, wEnemyMonHP ld a, [hli] or [hl] ; is enemy mon HP zero? @@ -1861,7 +1771,7 @@ SendOutMon: call DrawPlayerHUDAndHPBar predef LoadMonBackPic xor a - ld [hStartTileID], a + ldh [hStartTileID], a ld hl, wBattleAndStartSavedMenuItem ld [hli], a ld [hl], a @@ -1884,27 +1794,27 @@ SendOutMon: call RunPaletteCommand ld hl, wEnemyBattleStatus1 res USING_TRAPPING_MOVE, [hl] - callab IsThisPartymonStarterPikachu + callfar IsThisPartymonStarterPikachu jr c, .starterPikachu ld a, $1 - ld [H_WHOSETURN], a + ldh [hWhoseTurn], a ld a, POOF_ANIM call PlayMoveAnimation - coord hl, 4, 11 + hlcoord 4, 11 predef AnimateSendingOutMon jr .playRegularCry .starterPikachu xor a - ld [H_WHOSETURN], a + ldh [hWhoseTurn], a ld a, $1 - ld [H_AUTOBGTRANSFERENABLED], a - callab StarterPikachuBattleEntranceAnimation - callab IsPlayerPikachuAsleepInParty + ldh [hAutoBGTransferEnabled], a + callfar StarterPikachuBattleEntranceAnimation + callfar IsPlayerPikachuAsleepInParty ld e, $24 jr c, .asm_3cd81 ld e, $a .asm_3cd81 - callab PlayPikachuSoundClip + callfar PlayPikachuSoundClip jr .done .playRegularCry ld a, [wcf91] @@ -1919,42 +1829,42 @@ AnimateRetreatingPlayerMon: push af ld a, [wPlayerMonNumber] ld [wWhichPokemon], a - callab IsThisPartymonStarterPikachu + callfar IsThisPartymonStarterPikachu pop bc ld a, b ld [wWhichPokemon], a jr c, .starterPikachu - coord hl, 1, 5 + hlcoord 1, 5 lb bc, 7, 7 call ClearScreenArea - coord hl, 3, 7 + hlcoord 3, 7 lb bc, 5, 5 xor a ld [wDownscaledMonSize], a - ld [hBaseTileID], a + ldh [hBaseTileID], a predef CopyDownscaledMonTiles ld c, 4 call DelayFrames call .clearScreenArea - coord hl, 4, 9 + hlcoord 4, 9 lb bc, 3, 3 ld a, 1 ld [wDownscaledMonSize], a xor a - ld [hBaseTileID], a + ldh [hBaseTileID], a predef CopyDownscaledMonTiles call Delay3 call .clearScreenArea ld a, $4c - Coorda 5, 11 + ldcoord_a 5, 11 jr .clearScreenArea .starterPikachu xor a - ld [H_WHOSETURN], a - callab AnimationSlideMonOff + ldh [hWhoseTurn], a + callfar AnimationSlideMonOff ret .clearScreenArea - coord hl, 1, 5 + hlcoord 1, 5 lb bc, 7, 7 call ClearScreenArea ret @@ -1977,15 +1887,15 @@ DrawHUDsAndHPBars: DrawPlayerHUDAndHPBar: xor a - ld [H_AUTOBGTRANSFERENABLED], a - coord hl, 9, 7 + ldh [hAutoBGTransferEnabled], a + hlcoord 9, 7 lb bc, 5, 11 call ClearScreenArea - callab PlacePlayerHUDTiles - coord hl, 18, 9 + callfar PlacePlayerHUDTiles + hlcoord 18, 9 ld [hl], $73 ld de, wBattleMonNick - coord hl, 10, 7 + hlcoord 10, 7 call CenterMonName call PlaceString ld hl, wBattleMonSpecies @@ -1996,7 +1906,7 @@ DrawPlayerHUDAndHPBar: ld de, wLoadedMonLevel ld bc, wBattleMonPP - wBattleMonLevel call CopyData - coord hl, 14, 8 + hlcoord 14, 8 push hl inc hl ld de, wLoadedMonStatus @@ -2007,10 +1917,10 @@ DrawPlayerHUDAndHPBar: .doNotPrintLevel ld a, [wLoadedMonSpecies] ld [wcf91], a - coord hl, 10, 9 + hlcoord 10, 9 predef DrawHP ld a, $1 - ld [H_AUTOBGTRANSFERENABLED], a + ldh [hAutoBGTransferEnabled], a ld hl, wPlayerHPBarColor call GetBattleHealthBarColor ld hl, wBattleMonHP @@ -2038,16 +1948,16 @@ DrawPlayerHUDAndHPBar: DrawEnemyHUDAndHPBar: xor a - ld [H_AUTOBGTRANSFERENABLED], a - coord hl, 0, 0 + ldh [hAutoBGTransferEnabled], a + hlcoord 0, 0 lb bc, 4, 12 call ClearScreenArea - callab PlaceEnemyHUDTiles + callfar PlaceEnemyHUDTiles ld de, wEnemyMonNick - coord hl, 1, 0 + hlcoord 1, 0 call CenterMonName call PlaceString - coord hl, 4, 1 + hlcoord 4, 1 push hl inc hl ld de, wEnemyMonStatus @@ -2060,9 +1970,9 @@ DrawEnemyHUDAndHPBar: .skipPrintLevel ld hl, wEnemyMonHP ld a, [hli] - ld [H_MULTIPLICAND + 1], a + ldh [hMultiplicand + 1], a ld a, [hld] - ld [H_MULTIPLICAND + 2], a + ldh [hMultiplicand + 2], a or [hl] ; is current HP zero? jr nz, .hpNonzero ; current HP is 0 @@ -2073,45 +1983,45 @@ DrawEnemyHUDAndHPBar: jp .drawHPBar .hpNonzero xor a - ld [H_MULTIPLICAND], a + ldh [hMultiplicand], a ld a, 48 - ld [H_MULTIPLIER], a + ldh [hMultiplier], a call Multiply ; multiply current HP by 48 ld hl, wEnemyMonMaxHP ld a, [hli] ld b, a ld a, [hl] - ld [H_DIVISOR], a + ldh [hDivisor], a ld a, b and a ; is max HP > 255? jr z, .doDivide ; if max HP > 255, scale both (current HP * 48) and max HP by dividing by 4 so that max HP fits in one byte ; (it needs to be one byte so it can be used as the divisor for the Divide function) - ld a, [H_DIVISOR] + ldh a, [hDivisor] srl b rr a srl b rr a - ld [H_DIVISOR], a - ld a, [H_PRODUCT + 2] + ldh [hDivisor], a + ldh a, [hProduct + 2] ld b, a srl b - ld a, [H_PRODUCT + 3] + ldh a, [hProduct + 3] rr a srl b rr a - ld [H_PRODUCT + 3], a + ldh [hProduct + 3], a ld a, b - ld [H_PRODUCT + 2], a + ldh [hProduct + 2], a .doDivide - ld a, [H_PRODUCT + 2] - ld [H_DIVIDEND], a - ld a, [H_PRODUCT + 3] - ld [H_DIVIDEND + 1], a + ldh a, [hProduct + 2] + ldh [hDividend], a + ldh a, [hProduct + 3] + ldh [hDividend + 1], a ld a, $2 ld b, a call Divide ; divide (current HP * 48) by max HP - ld a, [H_QUOTIENT + 3] + ldh a, [hQuotient + 3] ; set variables for DrawHPBar ld e, a ld a, $6 @@ -2120,10 +2030,10 @@ DrawEnemyHUDAndHPBar: .drawHPBar xor a ld [wHPBarType], a - coord hl, 2, 2 + hlcoord 2, 2 call DrawHPBar ld a, $1 - ld [H_AUTOBGTRANSFERENABLED], a + ldh [hAutoBGTransferEnabled], a ld hl, wEnemyHPBarColor GetBattleHealthBarColor: @@ -2161,7 +2071,7 @@ CenterMonName: pop de ret -DisplayBattleMenu: +DisplayBattleMenu:: call LoadScreenTilesFromBuffer1 ; restore saved screen ld a, [wBattleType] and a @@ -2206,12 +2116,12 @@ DisplayBattleMenu: ld bc, NAME_LENGTH call CopyData ; the following simulates the keystrokes by drawing menus on screen - coord hl, 9, 14 + hlcoord 9, 14 ld [hl], "▶" ld c, 20 call DelayFrames ld [hl], " " - coord hl, 9, 16 + hlcoord 9, 16 ld [hl], "▶" ld c, 20 call DelayFrames @@ -2238,14 +2148,14 @@ DisplayBattleMenu: ld a, " " jr z, .safariLeftColumn ; put cursor in left column for normal battle menu (i.e. when it's not a Safari battle) - Coorda 15, 14 ; clear upper cursor position in right column - Coorda 15, 16 ; clear lower cursor position in right column + ldcoord_a 15, 14 ; clear upper cursor position in right column + ldcoord_a 15, 16 ; clear lower cursor position in right column ld b, $9 ; top menu item X jr .leftColumn_WaitForInput .safariLeftColumn - Coorda 13, 14 - Coorda 13, 16 - coord hl, 7, 14 + ldcoord_a 13, 14 + ldcoord_a 13, 16 + hlcoord 7, 14 ld de, wNumSafariBalls lb bc, 1, 2 call PrintNumber @@ -2271,14 +2181,14 @@ DisplayBattleMenu: ld a, " " jr z, .safariRightColumn ; put cursor in right column for normal battle menu (i.e. when it's not a Safari battle) - Coorda 9, 14 ; clear upper cursor position in left column - Coorda 9, 16 ; clear lower cursor position in left column + ldcoord_a 9, 14 ; clear upper cursor position in left column + ldcoord_a 9, 16 ; clear lower cursor position in left column ld b, $f ; top menu item X jr .rightColumn_WaitForInput .safariRightColumn - Coorda 1, 14 ; clear upper cursor position in left column - Coorda 1, 16 ; clear lower cursor position in left column - coord hl, 7, 14 + ldcoord_a 1, 14 ; clear upper cursor position in left column + ldcoord_a 1, 16 ; clear lower cursor position in left column + hlcoord 7, 14 ld de, wNumSafariBalls lb bc, 1, 2 call PrintNumber @@ -2348,8 +2258,8 @@ DisplayBattleMenu: jp DisplayBattleMenu .RunAwayText - TX_FAR _RunAwayText - db "@" + text_far _RunAwayText + text_end .upperLeftMenuItemWasNotSelected ; a menu item other than the upper left item was selected cp $2 @@ -2485,8 +2395,8 @@ UseBagItem: ret ItemsCantBeUsedHereText: - TX_FAR _ItemsCantBeUsedHereText - db "@" + text_far _ItemsCantBeUsedHereText + text_end PartyMenuOrRockOrRun: dec a ; was Run selected? @@ -2517,7 +2427,7 @@ PartyMenuOrRockOrRun: call GBPalNormal jp DisplayBattleMenu .partyMonDeselected - coord hl, 11, 11 + hlcoord 11, 11 ld bc, 6 * SCREEN_WIDTH + 9 ld a, " " call FillMemory @@ -2562,7 +2472,7 @@ PartyMenuOrRockOrRun: predef StatusScreen2 ; now we need to reload the enemy mon pic ld a, 1 - ld [H_WHOSETURN], a + ldh [hWhoseTurn], a ld a, [wEnemyBattleStatus2] bit HAS_SUBSTITUTE_UP, a ; does the enemy mon have a substitute? ld hl, AnimationSubstitute @@ -2609,7 +2519,7 @@ PartyMenuOrRockOrRun: ; fall through to SwitchPlayerMon SwitchPlayerMon: - callab RetreatMon + callfar RetreatMon ld c, 50 call DelayFrames call AnimateRetreatingPlayerMon @@ -2632,8 +2542,8 @@ SwitchPlayerMon: ret AlreadyOutText: - TX_FAR _AlreadyOutText - db "@" + text_far _AlreadyOutText + text_end BattleMenu_RunWasSelected: call LoadScreenTilesFromBuffer1 @@ -2662,18 +2572,18 @@ MoveSelectionMenu: ld de, wMoves ld bc, NUM_MOVES call CopyData - callab FormatMovesString + callfar FormatMovesString ret .writemoves ld de, wMovesString - ld a, [hFlags_0xFFFA] + ldh a, [hFlagsFFFA] set 2, a - ld [hFlags_0xFFFA], a + ldh [hFlagsFFFA], a call PlaceString - ld a, [hFlags_0xFFFA] + ldh a, [hFlagsFFFA] res 2, a - ld [hFlags_0xFFFA], a + ldh [hFlagsFFFA], a ret .regularmenu @@ -2681,17 +2591,17 @@ MoveSelectionMenu: ret z ld hl, wBattleMonMoves call .loadmoves - coord hl, 4, 12 + hlcoord 4, 12 lb bc, 4, 14 di ; out of pure coincidence, it is possible for vblank to occur between the di and ei ; so it is necessary to put the di ei block to not cause tearing call TextBoxBorder - coord hl, 4, 12 + hlcoord 4, 12 ld [hl], $7a - coord hl, 10, 12 + hlcoord 10, 12 ld [hl], $7e ei - coord hl, 6, 13 + hlcoord 6, 13 call .writemoves ld b, $5 ld a, $c @@ -2699,10 +2609,10 @@ MoveSelectionMenu: .mimicmenu ld hl, wEnemyMonMoves call .loadmoves - coord hl, 0, 7 + hlcoord 0, 7 lb bc, 4, 14 call TextBoxBorder - coord hl, 2, 8 + hlcoord 2, 8 call .writemoves ld b, $1 ld a, $7 @@ -2713,10 +2623,10 @@ MoveSelectionMenu: ld bc, wPartyMon2 - wPartyMon1 call AddNTimes call .loadmoves - coord hl, 4, 7 + hlcoord 4, 7 lb bc, 4, 14 call TextBoxBorder - coord hl, 6, 8 + hlcoord 6, 8 call .writemoves ld b, $5 ld a, $7 @@ -2770,7 +2680,7 @@ SelectMenuItem: jr z, .battleselect dec a jr nz, .select - coord hl, 1, 14 + hlcoord 1, 14 ld de, WhichTechniqueString call PlaceString jr .select @@ -2782,16 +2692,16 @@ SelectMenuItem: ld a, [wMenuItemToSwap] and a jr z, .select - coord hl, 5, 13 + hlcoord 5, 13 dec a ld bc, SCREEN_WIDTH call AddNTimes ld [hl], "▷" .select - ld hl, hFlags_0xFFFA + ld hl, hFlagsFFFA set 1, [hl] call HandleMenuInput - ld hl, hFlags_0xFFFA + ld hl, hFlagsFFFA res 1, [hl] bit 6, a jp nz, SelectMenuItem_CursorUp ; up @@ -2860,12 +2770,12 @@ SelectMenuItem: jp MoveSelectionMenu MoveNoPPText: - TX_FAR _MoveNoPPText - db "@" + text_far _MoveNoPPText + text_end MoveDisabledText: - TX_FAR _MoveDisabledText - db "@" + text_far _MoveDisabledText + text_end WhichTechniqueString: db "WHICH TECHNIQUE?@" @@ -2899,7 +2809,7 @@ Func_3d4f5: jr nz, .asm_3d4fd ld a, $1 .asm_3d4fd - ld [H_WHOSETURN], a + ldh [hWhoseTurn], a call LoadScreenTilesFromBuffer1 call Func_3d536 ld a, [wTestBattlePlayerSelectedMove] @@ -2909,7 +2819,7 @@ Func_3d4f5: xor a ld [wAnimationType], a predef MoveAnimation - callab Func_78e98 + callfar Func_78e98 jp MoveSelectionMenu Func_3d523: @@ -2925,10 +2835,10 @@ asm_3d52d: jp MoveSelectionMenu Func_3d536: - coord hl, 10, 16 + hlcoord 10, 16 lb bc, 2, 10 call ClearScreenArea - coord hl, 10, 17 + hlcoord 10, 17 ld de, wTestBattlePlayerSelectedMove lb bc, LEADING_ZEROES | 1, 3 call PrintNumber @@ -2939,7 +2849,7 @@ Func_3d536: ret nc ld [wd11e], a call GetMoveName - coord hl, 13, 17 + hlcoord 13, 17 jp PlaceString AnyMoveToSelect: @@ -2989,8 +2899,8 @@ AnyMoveToSelect: ret NoMovesLeftText: - TX_FAR _NoMovesLeftText - db "@" + text_far _NoMovesLeftText + text_end SwapMovesInMenu: ld a, [wPlayerBattleStatus3] @@ -3073,8 +2983,8 @@ SwapMovesInMenu: PrintMenuItem: xor a - ld [H_AUTOBGTRANSFERENABLED], a - coord hl, 0, 8 + ldh [hAutoBGTransferEnabled], a + hlcoord 0, 8 lb bc, 3, 9 call TextBoxBorder ld a, [wPlayerDisabledMove] @@ -3086,7 +2996,7 @@ PrintMenuItem: ld a, [wCurrentMenuItem] cp b jr nz, .notDisabled - coord hl, 1, 10 + hlcoord 1, 10 ld de, DisabledText call PlaceString jr .moveDisabled @@ -3094,7 +3004,7 @@ PrintMenuItem: ld hl, wCurrentMenuItem dec [hl] xor a - ld [H_WHOSETURN], a + ldh [hWhoseTurn], a ld hl, wBattleMonMoves ld a, [wCurrentMenuItem] ld c, a @@ -3107,7 +3017,7 @@ PrintMenuItem: ld [wWhichPokemon], a ld a, BATTLE_MON_DATA ld [wMonDataLocation], a - callab GetMaxPP + callfar GetMaxPP ld hl, wCurrentMenuItem ld c, [hl] inc [hl] @@ -3118,27 +3028,27 @@ PrintMenuItem: and $3f ld [wcd6d], a ; print TYPE/<type> and <curPP>/<maxPP> - coord hl, 1, 9 + hlcoord 1, 9 ld de, TypeText call PlaceString - coord hl, 7, 11 + hlcoord 7, 11 ld [hl], "/" - coord hl, 5, 9 + hlcoord 5, 9 ld [hl], "/" - coord hl, 5, 11 + hlcoord 5, 11 ld de, wcd6d lb bc, 1, 2 call PrintNumber - coord hl, 8, 11 + hlcoord 8, 11 ld de, wMaxPP lb bc, 1, 2 call PrintNumber call GetCurrentMove - coord hl, 2, 10 + hlcoord 2, 10 predef PrintMoveType .moveDisabled ld a, $1 - ld [H_AUTOBGTRANSFERENABLED], a + ldh [hAutoBGTransferEnabled], a jp Delay3 DisabledText: @@ -3202,7 +3112,7 @@ SelectEnemyMove: ld a, [wIsInBattle] dec a jr z, .chooseRandomMove ; wild encounter - callab AIEnemyTrainerChooseMoves + callfar AIEnemyTrainerChooseMoves .chooseRandomMove push hl call BattleRandom @@ -3267,7 +3177,7 @@ LinkBattleExchangeData: ld a, b .doExchange ld [wSerialExchangeNybbleSendData], a - callab PrintWaitingText + callfar PrintWaitingText .syncLoop1 call Serial_ExchangeNybble call DelayFrame @@ -3290,7 +3200,7 @@ LinkBattleExchangeData: ExecutePlayerMove: xor a - ld [H_WHOSETURN], a ; set player's turn + ldh [hWhoseTurn], a ; set player's turn ld a, [wPlayerSelectedMove] inc a jp z, ExecutePlayerMoveDone ; for selected move = FF, skip most of player's turn @@ -3443,7 +3353,7 @@ MirrorMoveCheck: .moveDidNotMiss call ApplyAttackToEnemyPokemon call PrintCriticalOHKOText - callab DisplayEffectiveness + callfar DisplayEffectiveness ld a, 1 ld [wMoveDidntMiss], a .notDone @@ -3486,8 +3396,8 @@ MirrorMoveCheck: jp ExecutePlayerMoveDone MultiHitText: - TX_FAR _MultiHitText - db "@" + text_far _MultiHitText + text_end ExecutePlayerMoveDone: xor a @@ -3499,29 +3409,29 @@ PrintGhostText: ; print the ghost battle messages call IsGhostBattle ret nz - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a jr nz, .Ghost - ld a, [wBattleMonStatus] ; player’s turn + ld a, [wBattleMonStatus] ; player's turn and SLP | (1 << FRZ) ret nz ld hl, ScaredText call PrintText xor a ret -.Ghost ; ghost’s turn +.Ghost ; ghost's turn ld hl, GetOutText call PrintText xor a ret ScaredText: - TX_FAR _ScaredText - db "@" + text_far _ScaredText + text_end GetOutText: - TX_FAR _GetOutText - db "@" + text_far _GetOutText + text_end IsGhostBattle: ld a, [wIsInBattle] @@ -3804,69 +3714,69 @@ CheckPlayerStatusConditions: ret FastAsleepText: - TX_FAR _FastAsleepText - db "@" + text_far _FastAsleepText + text_end WokeUpText: - TX_FAR _WokeUpText - db "@" + text_far _WokeUpText + text_end IsFrozenText: - TX_FAR _IsFrozenText - db "@" + text_far _IsFrozenText + text_end FullyParalyzedText: - TX_FAR _FullyParalyzedText - db "@" + text_far _FullyParalyzedText + text_end FlinchedText: - TX_FAR _FlinchedText - db "@" + text_far _FlinchedText + text_end MustRechargeText: - TX_FAR _MustRechargeText - db "@" + text_far _MustRechargeText + text_end DisabledNoMoreText: - TX_FAR _DisabledNoMoreText - db "@" + text_far _DisabledNoMoreText + text_end IsConfusedText: - TX_FAR _IsConfusedText - db "@" + text_far _IsConfusedText + text_end HurtItselfText: - TX_FAR _HurtItselfText - db "@" + text_far _HurtItselfText + text_end ConfusedNoMoreText: - TX_FAR _ConfusedNoMoreText - db "@" + text_far _ConfusedNoMoreText + text_end SavingEnergyText: - TX_FAR _SavingEnergyText - db "@" + text_far _SavingEnergyText + text_end UnleashedEnergyText: - TX_FAR _UnleashedEnergyText - db "@" + text_far _UnleashedEnergyText + text_end ThrashingAboutText: - TX_FAR _ThrashingAboutText - db "@" + text_far _ThrashingAboutText + text_end AttackContinuesText: - TX_FAR _AttackContinuesText - db "@" + text_far _AttackContinuesText + text_end CantMoveText: - TX_FAR _CantMoveText - db "@" + text_far _CantMoveText + text_end PrintMoveIsDisabledText: ld hl, wPlayerSelectedMove ld de, wPlayerBattleStatus1 - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a jr z, .removeChargingUp inc hl @@ -3882,8 +3792,8 @@ PrintMoveIsDisabledText: jp PrintText MoveIsDisabledText: - TX_FAR _MoveIsDisabledText - db "@" + text_far _MoveIsDisabledText + text_end HandleSelfConfusionDamage: ld hl, HurtItselfText @@ -3922,11 +3832,11 @@ HandleSelfConfusionDamage: xor a ld [wAnimationType], a inc a - ld [H_WHOSETURN], a + ldh [hWhoseTurn], a call PlayMoveAnimation call DrawPlayerHUDAndHPBar xor a - ld [H_WHOSETURN], a + ldh [hWhoseTurn], a jp ApplyDamageToPlayerPokemon PrintMonName1Text: @@ -3939,9 +3849,9 @@ PrintMonName1Text: ; this likely had to do with Japanese grammar that got translated, ; but the functionality didn't get removed MonName1Text: - TX_FAR _MonName1Text - TX_ASM - ld a, [H_WHOSETURN] + text_far _MonName1Text + text_asm + ldh a, [hWhoseTurn] and a ld a, [wPlayerMoveNum] ld hl, wPlayerUsedMove @@ -3964,13 +3874,13 @@ MonName1Text: ret Used1Text: - TX_FAR _Used1Text - TX_ASM + text_far _Used1Text + text_asm jr PrintInsteadText Used2Text: - TX_FAR _Used2Text - TX_ASM + text_far _Used2Text + text_asm ; fall through PrintInsteadText: @@ -3981,8 +3891,8 @@ PrintInsteadText: ret InsteadText: - TX_FAR _InsteadText - TX_ASM + text_far _InsteadText + text_asm ; fall through PrintMoveName: @@ -3990,8 +3900,8 @@ PrintMoveName: ret _PrintMoveName: - TX_FAR _CF4BText - TX_ASM + text_far _CF4BText + text_asm ld hl, ExclamationPointPointerTable ld a, [wd11e] ; exclamation point num add a @@ -4013,24 +3923,24 @@ ExclamationPointPointerTable: dw ExclamationPoint5Text ExclamationPoint1Text: - TX_FAR _ExclamationPoint1Text - db "@" + text_far _ExclamationPoint1Text + text_end ExclamationPoint2Text: - TX_FAR _ExclamationPoint2Text - db "@" + text_far _ExclamationPoint2Text + text_end ExclamationPoint3Text: - TX_FAR _ExclamationPoint3Text - db "@" + text_far _ExclamationPoint3Text + text_end ExclamationPoint4Text: - TX_FAR _ExclamationPoint4Text - db "@" + text_far _ExclamationPoint4Text + text_end ExclamationPoint5Text: - TX_FAR _ExclamationPoint5Text - db "@" + text_far _ExclamationPoint5Text + text_end ; this function does nothing useful ; if the move being used is in set [1-4] from ExclamationPointMoveSets, @@ -4061,26 +3971,11 @@ DetermineExclamationPointTextNum: pop bc ret -ExclamationPointMoveSets: -; a grammar mistake was fixed (only concerning japanese) -; BIDE is in category 3, moved from category 2 - db SWORDS_DANCE, GROWTH - db $00 - db RECOVER, SELFDESTRUCT, AMNESIA - db $00 - db MEDITATE, AGILITY, TELEPORT, MIMIC, DOUBLE_TEAM, BIDE, BARRAGE - db $00 - db POUND, SCRATCH, VICEGRIP, WING_ATTACK, FLY, BIND, SLAM, HORN_ATTACK, BODY_SLAM - db WRAP, THRASH, TAIL_WHIP, LEER, BITE, GROWL, ROAR, SING, PECK, COUNTER - db STRENGTH, ABSORB, STRING_SHOT, EARTHQUAKE, FISSURE, DIG, TOXIC, SCREECH, HARDEN - db MINIMIZE, WITHDRAW, DEFENSE_CURL, METRONOME, LICK, CLAMP, CONSTRICT, POISON_GAS - db LEECH_LIFE, BUBBLE, FLASH, SPLASH, ACID_ARMOR, FURY_SWIPES, REST, SHARPEN, SLASH, SUBSTITUTE - db $00 - db $FF ; terminator +INCLUDE "data/moves/grammar.asm" PrintMoveFailureText: ld de, wPlayerMoveEffect - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a jr z, .playersTurn ld de, wEnemyMoveEffect @@ -4128,7 +4023,7 @@ PrintMoveFailureText: call PrintText ld b, $4 predef PredefShakeScreenHorizontally - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a jr nz, .enemyTurn jp ApplyDamageToPlayerPokemon @@ -4136,24 +4031,24 @@ PrintMoveFailureText: jp ApplyDamageToEnemyPokemon AttackMissedText: - TX_FAR _AttackMissedText - db "@" + text_far _AttackMissedText + text_end KeptGoingAndCrashedText: - TX_FAR _KeptGoingAndCrashedText - db "@" + text_far _KeptGoingAndCrashedText + text_end UnaffectedText: - TX_FAR _UnaffectedText - db "@" + text_far _UnaffectedText + text_end PrintDoesntAffectText: ld hl, DoesntAffectMonText jp PrintText DoesntAffectMonText: - TX_FAR _DoesntAffectMonText - db "@" + text_far _DoesntAffectMonText + text_end ; if there was a critical hit or an OHKO was successful, print the corresponding text PrintCriticalOHKOText: @@ -4181,12 +4076,12 @@ CriticalOHKOTextPointers: dw OHKOText CriticalHitText: - TX_FAR _CriticalHitText - db "@" + text_far _CriticalHitText + text_end OHKOText: - TX_FAR _OHKOText - db "@" + text_far _OHKOText + text_end ; checks if a traded mon will disobey due to lack of badges ; stores whether the mon will use a move in Z flag @@ -4216,16 +4111,16 @@ CheckForDisobedience: .monIsTraded ; what level might disobey? ld hl, wObtainedBadges - bit 7, [hl] + bit BIT_EARTHBADGE, [hl] ld a, 101 jr nz, .next - bit 5, [hl] + bit BIT_MARSHBADGE, [hl] ld a, 70 jr nz, .next - bit 3, [hl] + bit BIT_RAINBOWBADGE, [hl] ld a, 50 jr nz, .next - bit 1, [hl] + bit BIT_CASCADEBADGE, [hl] ld a, 30 jr nz, .next ld a, 10 @@ -4370,24 +4265,24 @@ CheckForDisobedience: ret LoafingAroundText: - TX_FAR _LoafingAroundText - db "@" + text_far _LoafingAroundText + text_end BeganToNapText: - TX_FAR _BeganToNapText - db "@" + text_far _BeganToNapText + text_end WontObeyText: - TX_FAR _WontObeyText - db "@" + text_far _WontObeyText + text_end TurnedAwayText: - TX_FAR _TurnedAwayText - db "@" + text_far _TurnedAwayText + text_end IgnoredOrdersText: - TX_FAR _IgnoredOrdersText - db "@" + text_far _IgnoredOrdersText + text_end ; sets b, c, d, and e for the CalculateDamage routine in the case of an attack by the player mon GetDamageVarsForPlayerAttack: @@ -4401,7 +4296,7 @@ GetDamageVarsForPlayerAttack: ld d, a ; d = move power ret z ; return if move power is zero ld a, [hl] ; a = [wPlayerMoveType] - cp FIRE ; types >= FIRE are all special + cp SPECIAL ; types >= SPECIAL are all special jr nc, .specialAttack .physicalAttack ld hl, wEnemyMonDefense @@ -4422,9 +4317,9 @@ GetDamageVarsForPlayerAttack: ; in the case of a critical hit, reset the player's attack and the enemy's defense to their base values ld c, 3 ; defense stat call GetEnemyMonStat - ld a, [H_PRODUCT + 2] + ldh a, [hProduct + 2] ld b, a - ld a, [H_PRODUCT + 3] + ldh a, [hProduct + 3] ld c, a push bc ld hl, wPartyMon1Attack @@ -4444,8 +4339,8 @@ GetDamageVarsForPlayerAttack: ; if the enemy has used Light Screen, double the enemy's special sla c rl b -; reflect and light screen boosts do not cap the stat at 999, so weird things will happen during stats scaling if -; a Pokemon with 512 or more Defense has used Reflect, or if a Pokemon with 512 or more Special has used Light Screen +; reflect and light screen boosts do not cap the stat at MAX_STAT_VALUE, so weird things will happen during stats scaling +; if a Pokemon with 512 or more Defense has used Reflect, or if a Pokemon with 512 or more Special has used Light Screen .specialAttackCritCheck ld hl, wBattleMonSpecial ld a, [wCriticalHitOrOHKO] @@ -4454,9 +4349,9 @@ GetDamageVarsForPlayerAttack: ; in the case of a critical hit, reset the player's and enemy's specials to their base values ld c, 5 ; special stat call GetEnemyMonStat - ld a, [H_PRODUCT + 2] + ldh a, [hProduct + 2] ld b, a - ld a, [H_PRODUCT + 3] + ldh a, [hProduct + 3] ld c, a push bc ld hl, wPartyMon1Special @@ -4514,7 +4409,7 @@ GetDamageVarsForEnemyAttack: and a ret z ; return if move power is zero ld a, [hl] ; a = [wEnemyMoveType] - cp FIRE ; types >= FIRE are all special + cp SPECIAL ; types >= SPECIAL are all special jr nc, .specialAttack .physicalAttack ld hl, wBattleMonDefense @@ -4543,7 +4438,7 @@ GetDamageVarsForEnemyAttack: push bc ld c, 2 ; attack stat call GetEnemyMonStat - ld hl, H_PRODUCT + 2 + ld hl, hProduct + 2 pop bc jr .scaleStats .specialAttack @@ -4557,8 +4452,8 @@ GetDamageVarsForEnemyAttack: ; if the player has used Light Screen, double the player's special sla c rl b -; reflect and light screen boosts do not cap the stat at 999, so weird things will happen during stats scaling if -; a Pokemon with 512 or more Defense has used Reflect, or if a Pokemon with 512 or more Special has used Light Screen +; reflect and light screen boosts do not cap the stat at MAX_STAT_VALUE, so weird things will happen during stats scaling +; if a Pokemon with 512 or more Defense has used Reflect, or if a Pokemon with 512 or more Special has used Light Screen .specialAttackCritCheck ld hl, wEnemyMonSpecial ld a, [wCriticalHitOrOHKO] @@ -4575,7 +4470,7 @@ GetDamageVarsForEnemyAttack: push bc ld c, 5 ; special stat call GetEnemyMonStat - ld hl, H_PRODUCT + 2 + ld hl, hProduct + 2 pop bc ; if either the offensive or defensive stat is too large to store in a byte, scale both stats by dividing them by 4 ; this allows values with up to 10 bits (values up to 1023) to be handled @@ -4633,9 +4528,9 @@ GetEnemyMonStat: ld bc, wEnemyMon2 - wEnemyMon1 call AddNTimes ld a, [hli] - ld [H_MULTIPLICAND + 1], a + ldh [hMultiplicand + 1], a ld a, [hl] - ld [H_MULTIPLICAND + 2], a + ldh [hMultiplicand + 2], a pop bc pop de ret @@ -4666,7 +4561,7 @@ CalculateDamage: ; d: base power ; e: level - ld a, [H_WHOSETURN] ; whose turn? + ldh a, [hWhoseTurn] ; whose turn? and a ld a, [wPlayerMoveEffect] jr z, .effect @@ -4698,7 +4593,7 @@ CalculateDamage: .skipbp xor a - ld hl, H_DIVIDEND + ld hl, hDividend ldi [hl], a ldi [hl], a ld [hl], a @@ -4747,76 +4642,82 @@ CalculateDamage: ld b, 4 call Divide +; Update wCurDamage. +; Capped at MAX_NEUTRAL_DAMAGE - MIN_NEUTRAL_DAMAGE: 999 - 2 = 997. ld hl, wDamage ld b, [hl] - ld a, [H_QUOTIENT + 3] + ldh a, [hQuotient + 3] add b - ld [H_QUOTIENT + 3], a - jr nc, .asm_3e142 + ldh [hQuotient + 3], a + jr nc, .dont_cap_1 - ld a, [H_QUOTIENT + 2] + ldh a, [hQuotient + 2] inc a - ld [H_QUOTIENT + 2], a + ldh [hQuotient + 2], a and a - jr z, .asm_3e176 + jr z, .cap -.asm_3e142 - ld a, [H_QUOTIENT] +.dont_cap_1 + ldh a, [hQuotient] ld b, a - ld a, [H_QUOTIENT + 1] + ldh a, [hQuotient + 1] or a - jr nz, .asm_3e176 - - ld a, [H_QUOTIENT + 2] - cp 998 / $100 - jr c, .asm_3e15a - cp 998 / $100 + 1 - jr nc, .asm_3e176 - ld a, [H_QUOTIENT + 3] - cp 998 % $100 - jr nc, .asm_3e176 - -.asm_3e15a + jr nz, .cap + + ldh a, [hQuotient + 2] + cp HIGH(MAX_NEUTRAL_DAMAGE - MIN_NEUTRAL_DAMAGE + 1) + jr c, .dont_cap_2 + + cp HIGH(MAX_NEUTRAL_DAMAGE - MIN_NEUTRAL_DAMAGE + 1) + 1 + jr nc, .cap + + ldh a, [hQuotient + 3] + cp LOW(MAX_NEUTRAL_DAMAGE - MIN_NEUTRAL_DAMAGE + 1) + jr nc, .cap + +.dont_cap_2 inc hl - ld a, [H_QUOTIENT + 3] + + ldh a, [hQuotient + 3] ld b, [hl] add b ld [hld], a - ld a, [H_QUOTIENT + 2] + ldh a, [hQuotient + 2] ld b, [hl] adc b ld [hl], a - jr c, .asm_3e176 + jr c, .cap ld a, [hl] - cp 998 / $100 - jr c, .asm_3e17c - cp 998 / $100 + 1 - jr nc, .asm_3e176 + cp HIGH(MAX_NEUTRAL_DAMAGE - MIN_NEUTRAL_DAMAGE + 1) + jr c, .dont_cap_3 + + cp HIGH(MAX_NEUTRAL_DAMAGE - MIN_NEUTRAL_DAMAGE + 1) + 1 + jr nc, .cap + inc hl ld a, [hld] - cp 998 % $100 - jr c, .asm_3e17c + cp LOW(MAX_NEUTRAL_DAMAGE - MIN_NEUTRAL_DAMAGE + 1) + jr c, .dont_cap_3 -.asm_3e176 -; cap at 997 - ld a, 997 / $100 +.cap + ld a, HIGH(MAX_NEUTRAL_DAMAGE - MIN_NEUTRAL_DAMAGE) ld [hli], a - ld a, 997 % $100 + ld a, LOW(MAX_NEUTRAL_DAMAGE - MIN_NEUTRAL_DAMAGE) ld [hld], a -.asm_3e17c -; add 2 +.dont_cap_3 +; Add back MIN_NEUTRAL_DAMAGE (capping at 999). inc hl ld a, [hl] - add 2 + add MIN_NEUTRAL_DAMAGE ld [hld], a - jr nc, .done + jr nc, .dont_floor inc [hl] +.dont_floor -.done -; minimum damage is 1 +; Returns nz and nc. ld a, 1 and a ret @@ -4827,13 +4728,7 @@ JumpToOHKOMoveEffect: dec a ret - -UnusedHighCriticalMoves: - db KARATE_CHOP - db RAZOR_LEAF - db CRABHAMMER - db SLASH - db $FF +INCLUDE "data/battle/unused_critical_hit_moves.asm" ; determines if attack is a critical hit ; azure heights claims "the fastest pokémon (who are, not coincidentally, @@ -4841,7 +4736,7 @@ UnusedHighCriticalMoves: CriticalHitTest: xor a ld [wCriticalHitOrOHKO], a - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a ld a, [wEnemyMonSpecies] jr nz, .handleEnemy @@ -4852,7 +4747,7 @@ CriticalHitTest: ld a, [wMonHBaseSpeed] ld b, a srl b ; (effective (base speed/2)) - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a ld hl, wPlayerMovePower ld de, wPlayerBattleStatus2 @@ -4904,14 +4799,7 @@ CriticalHitTest: ld [wCriticalHitOrOHKO], a ; set critical hit flag ret -; high critical hit moves -HighCriticalMoves: - db KARATE_CHOP - db RAZOR_LEAF - db CRABHAMMER - db SLASH - db $FF - +INCLUDE "data/battle/critical_hit_moves.asm" ; function to determine if Counter hits and if so, how much damage it does HandleCounterMove: @@ -4921,7 +4809,7 @@ HandleCounterMove: ; the outcome may be affected by the player's actions in the move selection menu prior to switching the Pokemon. ; This might also lead to desync glitches in link battles. - ld a, [H_WHOSETURN] ; whose turn + ldh a, [hWhoseTurn] ; whose turn and a ; player's turn ld hl, wEnemySelectedMove @@ -5091,7 +4979,7 @@ ApplyDamageToEnemyPokemon: ld [wHPBarNewHP+1], a ld a, [hl] ld [wHPBarNewHP], a - coord hl, 2, 2 + hlcoord 2, 2 xor a ld [wHPBarType], a predef UpdateHPBar2 ; animate the HP bar shortening @@ -5209,7 +5097,7 @@ ApplyDamageToPlayerPokemon: ld [wHPBarMaxHP+1], a ld a, [hl] ld [wHPBarMaxHP], a - coord hl, 10, 9 + hlcoord 10, 9 ld a, $01 ld [wHPBarType], a predef UpdateHPBar2 ; animate the HP bar shortening @@ -5229,7 +5117,7 @@ AttackSubstitute: ; values for player turn ld de, wEnemySubstituteHP ld bc, wEnemyBattleStatus2 - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a jr z, .applyDamageToSubstitute ; values for enemy turn @@ -5254,14 +5142,14 @@ AttackSubstitute: ld hl, SubstituteBrokeText call PrintText ; flip whose turn it is for the next function call - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] xor $01 - ld [H_WHOSETURN], a - callab Func_79929 ; animate the substitute breaking + ldh [hWhoseTurn], a + callfar Func_79929 ; animate the substitute breaking ; flip the turn back to the way it was - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] xor $01 - ld [H_WHOSETURN], a + ldh [hWhoseTurn], a ld hl, wPlayerMoveEffect ; value for player's turn and a jr z, .nullifyEffect @@ -5272,12 +5160,12 @@ AttackSubstitute: jp DrawHUDsAndHPBars SubstituteTookDamageText: - TX_FAR _SubstituteTookDamageText - db "@" + text_far _SubstituteTookDamageText + text_end SubstituteBrokeText: - TX_FAR _SubstituteBrokeText - db "@" + text_far _SubstituteBrokeText + text_end ; this function raises the attack modifier of a pokemon using Rage when that pokemon is attacked HandleBuildingRage: @@ -5285,7 +5173,7 @@ HandleBuildingRage: ld hl, wEnemyBattleStatus2 ld de, wEnemyMonStatMods ld bc, wEnemyMoveNum - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a jr z, .next ; values for the enemy turn @@ -5298,9 +5186,9 @@ HandleBuildingRage: ld a, [de] cp $0d ; maximum stat modifier value ret z ; return if attack modifier is already maxed - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] xor $01 ; flip turn for the stat modifier raising function - ld [H_WHOSETURN], a + ldh [hWhoseTurn], a ; temporarily change the target pokemon's move to $00 and the effect to the one ; that causes the attack modifier to go up one stage ld h, b @@ -5317,25 +5205,25 @@ HandleBuildingRage: ldd [hl], a ; null move effect ld a, RAGE ld [hl], a ; restore the target pokemon's move number to Rage - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] xor $01 ; flip turn back to the way it was - ld [H_WHOSETURN], a + ldh [hWhoseTurn], a ret BuildingRageText: - TX_FAR _BuildingRageText - db "@" + text_far _BuildingRageText + text_end ; copy last move for Mirror Move ; sets zero flag on failure and unsets zero flag on success MirrorMoveCopyMove: -; Mirror Move makes use of ccf1 (wPlayerUsedMove) and ccf2 (wEnemyUsedMove) addresses, +; Mirror Move makes use of wPlayerUsedMove and wEnemyUsedMove, ; which are mainly used to print the "[Pokemon] used [Move]" text. ; Both are set to 0 whenever a new Pokemon is sent out -; ccf1 is also set to 0 whenever the player is fast asleep or frozen solid. -; ccf2 is also set to 0 whenever the enemy is fast asleep or frozen solid. +; wPlayerUsedMove is also set to 0 whenever the player is fast asleep or frozen solid. +; wEnemyUsedMove is also set to 0 whenever the enemy is fast asleep or frozen solid. - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a ; values for player turn ld a, [wEnemyUsedMove] @@ -5359,8 +5247,8 @@ MirrorMoveCopyMove: ret MirrorMoveFailedText: - TX_FAR _MirrorMoveFailedText - db "@" + text_far _MirrorMoveFailedText + text_end ; function used to reload move data for moves like Mirror Move and Metronome ReloadMoveData: @@ -5388,7 +5276,7 @@ MetronomePickMove: ; values for player turn ld de, wPlayerMoveNum ld hl, wPlayerSelectedMove - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a jr z, .pickMoveLoop ; values for enemy turn @@ -5410,7 +5298,7 @@ MetronomePickMove: ; it's used to prevent moves that run another move within the same turn ; (like Mirror Move and Metronome) from losing 2 PP IncrementMovePP: - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a ; values for player turn ld hl, wBattleMonPP @@ -5429,7 +5317,7 @@ IncrementMovePP: ld h, d ld l, e add hl, bc - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a ld a, [wPlayerMonNumber] ; value for player turn jr z, .updatePP @@ -5453,7 +5341,7 @@ AdjustDamageForMoveType: ld e, [hl] ; e = type 2 of defender ld a, [wPlayerMoveType] ld [wMoveType], a - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a jr z, .next ; values for enemy turn @@ -5517,25 +5405,25 @@ AdjustDamageForMoveType: and $80 ld b, a ld a, [hl] ; a = damage multiplier - ld [H_MULTIPLIER], a + ldh [hMultiplier], a add b ld [wDamageMultipliers], a xor a - ld [H_MULTIPLICAND], a + ldh [hMultiplicand], a ld hl, wDamage ld a, [hli] - ld [H_MULTIPLICAND + 1], a + ldh [hMultiplicand + 1], a ld a, [hld] - ld [H_MULTIPLICAND + 2], a + ldh [hMultiplicand + 2], a call Multiply ld a, 10 - ld [H_DIVISOR], a + ldh [hDivisor], a ld b, $04 call Divide - ld a, [H_QUOTIENT + 2] + ldh a, [hQuotient + 2] ld [hli], a ld b, a - ld a, [H_QUOTIENT + 3] + ldh a, [hQuotient + 3] ld [hl], a or b ; is damage 0? jr nz, .skipTypeImmunity @@ -5598,7 +5486,7 @@ AIGetTypeEffectiveness: ld [wd11e], a ; store damage multiplier ret -INCLUDE "data/type_effects.asm" +INCLUDE "data/types/type_matchups.asm" ; some tests that need to pass for a move to hit MoveHitTest: @@ -5606,7 +5494,7 @@ MoveHitTest: ld hl, wEnemyBattleStatus1 ld de, wPlayerMoveEffect ld bc, wEnemyMonStatus - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a jr z, .dreamEaterCheck ; enemy's turn @@ -5626,8 +5514,8 @@ MoveHitTest: ret z ; Swift never misses (interestingly, Azure Heights lists this is a myth, but it appears to be true) call CheckTargetSubstitute ; substitute check (note that this overwrites a) jr z, .checkForDigOrFlyStatus -; this code is buggy. it's supposed to prevent HP draining moves from working on substitutes. -; since $7b79 overwrites a with either $00 or $01, it never works. +; This code is buggy. It's supposed to prevent HP draining moves from working on substitutes. +; Since CheckTargetSubstitute overwrites a with either $00 or $01, it never works. cp DRAIN_HP_EFFECT jp z, .moveMissed cp DREAM_EATER_EFFECT @@ -5635,7 +5523,7 @@ MoveHitTest: .checkForDigOrFlyStatus bit INVULNERABLE, [hl] jp nz, .moveMissed - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a jr nz, .enemyTurn .playerTurn @@ -5689,7 +5577,7 @@ MoveHitTest: call CalcHitChance ; scale the move accuracy according to attacker's accuracy and target's evasion ld a, [wPlayerMoveAccuracy] ld b, a - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a jr z, .doAccuracyCheck ld a, [wEnemyMoveAccuracy] @@ -5708,7 +5596,7 @@ MoveHitTest: ld [hl], a inc a ld [wMoveMissed], a - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a jr z, .playerTurn2 .enemyTurn2 @@ -5723,7 +5611,7 @@ MoveHitTest: ; values for player turn CalcHitChance: ld hl, wPlayerMoveAccuracy - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a ld a, [wPlayerMonAccuracyMod] ld b, a @@ -5743,10 +5631,10 @@ CalcHitChance: ; decreases the hit chance instead of increasing the hit chance) ; zero the high bytes of the multiplicand xor a - ld [H_MULTIPLICAND], a - ld [H_MULTIPLICAND + 1], a + ldh [hMultiplicand], a + ldh [hMultiplicand + 1], a ld a, [hl] - ld [H_MULTIPLICAND + 2], a ; set multiplicand to move accuracy + ldh [hMultiplicand + 2], a ; set multiplicand to move accuracy push hl ld d, $02 ; loop has two iterations ; loop to do the calculations, the first iteration multiplies by the accuracy ratio and @@ -5761,29 +5649,29 @@ CalcHitChance: add hl, bc ; hl = address of stat modifier ratio pop bc ld a, [hli] - ld [H_MULTIPLIER], a ; set multiplier to the numerator of the ratio + ldh [hMultiplier], a ; set multiplier to the numerator of the ratio call Multiply ld a, [hl] - ld [H_DIVISOR], a ; set divisor to the the denominator of the ratio + ldh [hDivisor], a ; set divisor to the the denominator of the ratio ; (the dividend is the product of the previous multiplication) ld b, $04 ; number of bytes in the dividend call Divide - ld a, [H_QUOTIENT + 3] + ldh a, [hQuotient + 3] ld b, a - ld a, [H_QUOTIENT + 2] + ldh a, [hQuotient + 2] or b jp nz, .nextCalculation ; make sure the result is always at least one - ld [H_QUOTIENT + 2], a + ldh [hQuotient + 2], a ld a, $01 - ld [H_QUOTIENT + 3], a + ldh [hQuotient + 3], a .nextCalculation ld b, c dec d jr nz, .loop - ld a, [H_QUOTIENT + 2] + ldh a, [hQuotient + 2] and a ; is the calculated hit chance over 0xFF? - ld a, [H_QUOTIENT + 3] + ldh a, [hQuotient + 3] jr z, .storeAccuracy ; if calculated hit chance over 0xFF ld a, $ff ; set the hit chance to 0xFF @@ -5803,29 +5691,29 @@ RandomizeDamage: ret c ; return if damage is equal to 0 or 1 .DamageGreaterThanOne xor a - ld [H_MULTIPLICAND], a + ldh [hMultiplicand], a dec hl ld a, [hli] - ld [H_MULTIPLICAND + 1], a + ldh [hMultiplicand + 1], a ld a, [hl] - ld [H_MULTIPLICAND + 2], a + ldh [hMultiplicand + 2], a ; loop until a random number greater than or equal to 217 is generated .loop call BattleRandom rrca cp 217 jr c, .loop - ld [H_MULTIPLIER], a + ldh [hMultiplier], a call Multiply ; multiply damage by the random number, which is in the range [217, 255] ld a, 255 - ld [H_DIVISOR], a + ldh [hDivisor], a ld b, $4 call Divide ; divide the result by 255 ; store the modified damage - ld a, [H_QUOTIENT + 2] + ldh a, [hQuotient + 2] ld hl, wDamage ld [hli], a - ld a, [H_QUOTIENT + 3] + ldh a, [hQuotient + 3] ld [hl], a ret @@ -6001,7 +5889,7 @@ EnemyCheckIfMirrorMoveEffect: .moveDidNotMiss call ApplyAttackToPlayerPokemon call PrintCriticalOHKOText - callab DisplayEffectiveness + callfar DisplayEffectiveness ld a, 1 ld [wMoveDidntMiss], a .handleExplosionMiss @@ -6040,8 +5928,8 @@ EnemyCheckIfMirrorMoveEffect: jr ExecuteEnemyMoveDone HitXTimesText: - TX_FAR _HitXTimesText - db "@" + text_far _HitXTimesText + text_end ExecuteEnemyMoveDone: ld b, $1 @@ -6181,11 +6069,11 @@ CheckEnemyStatusConditions: ld [hl], a xor a ld [wAnimationType], a - ld [H_WHOSETURN], a + ldh [hWhoseTurn], a ld a, POUND call PlayMoveAnimation ld a, $1 - ld [H_WHOSETURN], a + ldh [hWhoseTurn], a call ApplyDamageToEnemyPokemon jr .monHurtItselfOrFullyParalysed .checkIfTriedToUseDisabledMove @@ -6332,7 +6220,7 @@ CheckEnemyStatusConditions: ret GetCurrentMove: - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a jp z, .player ld de, wEnemyMoveNum @@ -6379,8 +6267,8 @@ LoadEnemyMonData: ld a, [wIsInBattle] cp $2 ; is it a trainer battle? ; fixed DVs for trainer mon - ld a, $98 - ld b, $88 + ld a, ATKDEFDV_TRAINER + ld b, SPDSPCDV_TRAINER jr z, .storeDVs ; random DVs for wild mon call BattleRandom @@ -6529,25 +6417,25 @@ DoBattleTransitionAndInitBattleVariables: ; link battle xor a ld [wMenuJoypadPollCount], a - callab DisplayLinkBattleVersusTextBox + callfar DisplayLinkBattleVersusTextBox ld a, $1 ld [wUpdateSpritesEnabled], a call ClearScreen .next call DelayFrame predef BattleTransition - callab LoadHudAndHpBarAndStatusTilePatterns + callfar LoadHudAndHpBarAndStatusTilePatterns ld a, $1 - ld [H_AUTOBGTRANSFERENABLED], a + ldh [hAutoBGTransferEnabled], a ld a, $ff ld [wUpdateSpritesEnabled], a call ClearSprites call ClearScreen xor a - ld [H_AUTOBGTRANSFERENABLED], a - ld [hWY], a - ld [rWY], a - ld [hTilesetType], a + ldh [hAutoBGTransferEnabled], a + ldh [hWY], a + ldh [rWY], a + ldh [hTilesetType], a ld hl, wPlayerStatsToDouble ld [hli], a ld [hli], a @@ -6587,7 +6475,7 @@ LoadPlayerBackPic: predef ScaleSpriteByTwo ld hl, wOAMBuffer xor a - ld [hOAMTile], a ; initial tile number + ldh [hOAMTile], a ; initial tile number ld b, $7 ; 7 columns ld e, $a0 ; X for the left-most column .loop ; each loop iteration writes 3 OAM entries in a vertical column @@ -6601,18 +6489,18 @@ LoadPlayerBackPic: add d ; increase Y by height of tile ld d, a inc hl - ld a, [hOAMTile] + ldh a, [hOAMTile] ld [hli], a ; OAM tile number inc a ; increment tile number - ld [hOAMTile], a + ldh [hOAMTile], a ld a, $2 ld [hl], a inc hl dec c jr nz, .innerLoop - ld a, [hOAMTile] + ldh a, [hOAMTile] add $4 ; increase tile number by 4 - ld [hOAMTile], a + ldh [hOAMTile], a ld a, $8 ; width of tile add e ; increase X by width of tile ld e, a @@ -6624,23 +6512,23 @@ LoadPlayerBackPic: call SwitchSRAMBankAndLatchClockData ld hl, vSprites ld de, sSpriteBuffer1 - ld a, [H_LOADEDROMBANK] + ldh a, [hLoadedROMBank] ld b, a ld c, 7 * 7 call CopyVideoData call PrepareRTCDataAndDisableSRAM ld a, $31 - ld [hStartTileID], a - coord hl, 1, 5 + ldh [hStartTileID], a + hlcoord 1, 5 predef_jump CopyUncompressedPicToTilemap ; does nothing since no stats are ever selected (barring glitches) DoubleOrHalveSelectedStats: - callab DoubleSelectedStats - jpab HalveSelectedStats + callfar DoubleSelectedStats + jpfar HalveSelectedStats ScrollTrainerPicAfterBattle: - jpab _ScrollTrainerPicAfterBattle + jpfar _ScrollTrainerPicAfterBattle ApplyBurnAndParalysisPenaltiesToPlayer: ld a, $1 @@ -6650,12 +6538,12 @@ ApplyBurnAndParalysisPenaltiesToEnemy: xor a ApplyBurnAndParalysisPenalties: - ld [H_WHOSETURN], a + ldh [hWhoseTurn], a call QuarterSpeedDueToParalysis jp HalveAttackDueToBurn QuarterSpeedDueToParalysis: - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a jr z, .playerTurn .enemyTurn ; quarter the player's speed @@ -6698,7 +6586,7 @@ QuarterSpeedDueToParalysis: ret HalveAttackDueToBurn: - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a jr z, .playerTurn .enemyTurn ; halve the player's attack @@ -6788,35 +6676,35 @@ CalculateModifiedStat: ld b, 0 add hl, bc xor a - ld [H_MULTIPLICAND], a + ldh [hMultiplicand], a ld a, [de] - ld [H_MULTIPLICAND + 1], a + ldh [hMultiplicand + 1], a inc de ld a, [de] - ld [H_MULTIPLICAND + 2], a + ldh [hMultiplicand + 2], a ld a, [hli] - ld [H_MULTIPLIER], a + ldh [hMultiplier], a call Multiply ld a, [hl] - ld [H_DIVISOR], a + ldh [hDivisor], a ld b, $4 call Divide pop hl - ld a, [H_DIVIDEND + 3] - sub 999 % $100 - ld a, [H_DIVIDEND + 2] - sbc 999 / $100 + ldh a, [hDividend + 3] + sub LOW(MAX_STAT_VALUE) + ldh a, [hDividend + 2] + sbc HIGH(MAX_STAT_VALUE) jp c, .storeNewStatValue -; cap the stat at 999 - ld a, 999 / $100 - ld [H_DIVIDEND + 2], a - ld a, 999 % $100 - ld [H_DIVIDEND + 3], a +; cap the stat at MAX_STAT_VALUE (999) + ld a, HIGH(MAX_STAT_VALUE) + ldh [hDividend + 2], a + ld a, LOW(MAX_STAT_VALUE) + ldh [hDividend + 3], a .storeNewStatValue - ld a, [H_DIVIDEND + 2] + ldh a, [hDividend + 2] ld [hli], a ld b, a - ld a, [H_DIVIDEND + 3] + ldh a, [hDividend + 3] ld [hl], a or b jr nz, .done @@ -6850,7 +6738,7 @@ ApplyBadgeStatBoosts: ret ; multiply stat at hl by 1.125 -; cap stat at 999 +; cap stat at MAX_STAT_VALUE .applyBoostToStat ld a, [hli] ld d, a @@ -6868,13 +6756,13 @@ ApplyBadgeStatBoosts: adc d ld [hli], a ld a, [hld] - sub 999 % $100 + sub LOW(MAX_STAT_VALUE) ld a, [hl] - sbc 999 / $100 + sbc HIGH(MAX_STAT_VALUE) ret c - ld a, 999 / $100 + ld a, HIGH(MAX_STAT_VALUE) ld [hli], a - ld a, 999 % $100 + ld a, LOW(MAX_STAT_VALUE) ld [hld], a ret @@ -6882,33 +6770,34 @@ LoadHudAndHpBarAndStatusTilePatterns: call LoadHpBarAndStatusTilePatterns LoadHudTilePatterns: - ld a, [rLCDC] + ldh a, [rLCDC] add a ; is LCD disabled? jr c, .lcdEnabled .lcdDisabled ld hl, BattleHudTiles1 - ld de, vChars2 + $6d0 + ld de, vChars2 tile $6d ld bc, BattleHudTiles1End - BattleHudTiles1 ld a, BANK(BattleHudTiles1) call FarCopyDataDouble ld hl, BattleHudTiles2 - ld de, vChars2 + $730 + ld de, vChars2 tile $73 ld bc, BattleHudTiles3End - BattleHudTiles2 ld a, BANK(BattleHudTiles2) jp FarCopyDataDouble .lcdEnabled ld de, BattleHudTiles1 - ld hl, vChars2 + $6d0 + ld hl, vChars2 tile $6d lb bc, BANK(BattleHudTiles1), (BattleHudTiles1End - BattleHudTiles1) / $8 call CopyVideoDataDouble ld de, BattleHudTiles2 - ld hl, vChars2 + $730 + ld hl, vChars2 tile $73 lb bc, BANK(BattleHudTiles2), (BattleHudTiles3End - BattleHudTiles2) / $8 jp CopyVideoDataDouble PrintEmptyString: ld hl, .emptyString jp PrintText + .emptyString db "@" @@ -6966,7 +6855,7 @@ BattleRandom: HandleExplodingAnimation: - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a ld hl, wEnemyMonType1 ld de, wEnemyBattleStatus1 @@ -7000,1662 +6889,5 @@ PlayMoveAnimation: ld [wAnimationID], a call Delay3 predef MoveAnimation - callab Func_78e98 - ret - -JumpMoveEffect: - call _JumpMoveEffect - ld b, $1 - ret - -_JumpMoveEffect: - ld a, [H_WHOSETURN] - and a - ld a, [wPlayerMoveEffect] - jr z, .next1 - ld a, [wEnemyMoveEffect] -.next1 - dec a ; subtract 1, there is no special effect for 00 - add a ; x2, 16bit pointers - ld hl, MoveEffectPointerTable - ld b, 0 - ld c, a - add hl, bc - ld a, [hli] - ld h, [hl] - ld l, a - jp hl ; jump to special effect handler - -MoveEffectPointerTable: - dw SleepEffect ; unused effect - dw PoisonEffect ; POISON_SIDE_EFFECT1 - dw DrainHPEffect ; DRAIN_HP_EFFECT - dw FreezeBurnParalyzeEffect ; BURN_SIDE_EFFECT1 - dw FreezeBurnParalyzeEffect ; FREEZE_SIDE_EFFECT - dw FreezeBurnParalyzeEffect ; PARALYZE_SIDE_EFFECT1 - dw ExplodeEffect ; EXPLODE_EFFECT - dw DrainHPEffect ; DREAM_EATER_EFFECT - dw $0000 ; MIRROR_MOVE_EFFECT - dw StatModifierUpEffect ; ATTACK_UP1_EFFECT - dw StatModifierUpEffect ; DEFENSE_UP1_EFFECT - dw StatModifierUpEffect ; SPEED_UP1_EFFECT - dw StatModifierUpEffect ; SPECIAL_UP1_EFFECT - dw StatModifierUpEffect ; ACCURACY_UP1_EFFECT - dw StatModifierUpEffect ; EVASION_UP1_EFFECT - dw PayDayEffect ; PAY_DAY_EFFECT - dw $0000 ; SWIFT_EFFECT - dw StatModifierDownEffect ; ATTACK_DOWN1_EFFECT - dw StatModifierDownEffect ; DEFENSE_DOWN1_EFFECT - dw StatModifierDownEffect ; SPEED_DOWN1_EFFECT - dw StatModifierDownEffect ; SPECIAL_DOWN1_EFFECT - dw StatModifierDownEffect ; ACCURACY_DOWN1_EFFECT - dw StatModifierDownEffect ; EVASION_DOWN1_EFFECT - dw ConversionEffect ; CONVERSION_EFFECT - dw HazeEffect ; HAZE_EFFECT - dw BideEffect ; BIDE_EFFECT - dw ThrashPetalDanceEffect ; THRASH_PETAL_DANCE_EFFECT - dw SwitchAndTeleportEffect ; SWITCH_AND_TELEPORT_EFFECT - dw TwoToFiveAttacksEffect ; TWO_TO_FIVE_ATTACKS_EFFECT - dw TwoToFiveAttacksEffect ; unused effect - dw FlinchSideEffect ; FLINCH_SIDE_EFFECT1 - dw SleepEffect ; SLEEP_EFFECT - dw PoisonEffect ; POISON_SIDE_EFFECT2 - dw FreezeBurnParalyzeEffect ; BURN_SIDE_EFFECT2 - dw FreezeBurnParalyzeEffect ; unused effect - dw FreezeBurnParalyzeEffect ; PARALYZE_SIDE_EFFECT2 - dw FlinchSideEffect ; FLINCH_SIDE_EFFECT2 - dw OneHitKOEffect ; OHKO_EFFECT - dw ChargeEffect ; CHARGE_EFFECT - dw $0000 ; SUPER_FANG_EFFECT - dw $0000 ; SPECIAL_DAMAGE_EFFECT - dw TrappingEffect ; TRAPPING_EFFECT - dw ChargeEffect ; FLY_EFFECT - dw TwoToFiveAttacksEffect ; ATTACK_TWICE_EFFECT - dw $0000 ; JUMP_KICK_EFFECT - dw MistEffect ; MIST_EFFECT - dw FocusEnergyEffect ; FOCUS_ENERGY_EFFECT - dw RecoilEffect ; RECOIL_EFFECT - dw ConfusionEffect ; CONFUSION_EFFECT - dw StatModifierUpEffect ; ATTACK_UP2_EFFECT - dw StatModifierUpEffect ; DEFENSE_UP2_EFFECT - dw StatModifierUpEffect ; SPEED_UP2_EFFECT - dw StatModifierUpEffect ; SPECIAL_UP2_EFFECT - dw StatModifierUpEffect ; ACCURACY_UP2_EFFECT - dw StatModifierUpEffect ; EVASION_UP2_EFFECT - dw HealEffect ; HEAL_EFFECT - dw TransformEffect ; TRANSFORM_EFFECT - dw StatModifierDownEffect ; ATTACK_DOWN2_EFFECT - dw StatModifierDownEffect ; DEFENSE_DOWN2_EFFECT - dw StatModifierDownEffect ; SPEED_DOWN2_EFFECT - dw StatModifierDownEffect ; SPECIAL_DOWN2_EFFECT - dw StatModifierDownEffect ; ACCURACY_DOWN2_EFFECT - dw StatModifierDownEffect ; EVASION_DOWN2_EFFECT - dw ReflectLightScreenEffect ; LIGHT_SCREEN_EFFECT - dw ReflectLightScreenEffect ; REFLECT_EFFECT - dw PoisonEffect ; POISON_EFFECT - dw ParalyzeEffect ; PARALYZE_EFFECT - dw StatModifierDownEffect ; ATTACK_DOWN_SIDE_EFFECT - dw StatModifierDownEffect ; DEFENSE_DOWN_SIDE_EFFECT - dw StatModifierDownEffect ; SPEED_DOWN_SIDE_EFFECT - dw StatModifierDownEffect ; SPECIAL_DOWN_SIDE_EFFECT - dw StatModifierDownEffect ; unused effect - dw StatModifierDownEffect ; unused effect - dw StatModifierDownEffect ; unused effect - dw StatModifierDownEffect ; unused effect - dw ConfusionSideEffect ; CONFUSION_SIDE_EFFECT - dw TwoToFiveAttacksEffect ; TWINEEDLE_EFFECT - dw $0000 ; unused effect - dw SubstituteEffect ; SUBSTITUTE_EFFECT - dw HyperBeamEffect ; HYPER_BEAM_EFFECT - dw RageEffect ; RAGE_EFFECT - dw MimicEffect ; MIMIC_EFFECT - dw $0000 ; METRONOME_EFFECT - dw LeechSeedEffect ; LEECH_SEED_EFFECT - dw SplashEffect ; SPLASH_EFFECT - dw DisableEffect ; DISABLE_EFFECT - -SleepEffect: - ld de, wEnemyMonStatus - ld bc, wEnemyBattleStatus2 - ld a, [H_WHOSETURN] - and a - jp z, .sleepEffect - ld de, wBattleMonStatus - ld bc, wPlayerBattleStatus2 - -.sleepEffect - ld a, [bc] - bit NEEDS_TO_RECHARGE, a ; does the target need to recharge? (hyper beam) - res NEEDS_TO_RECHARGE, a ; target no longer needs to recharge - ld [bc], a - jr nz, .setSleepCounter ; if the target had to recharge, all hit tests will be skipped - ; including the event where the target already has another status - ld a, [de] - ld b, a - and $7 - jr z, .notAlreadySleeping ; can't affect a mon that is already asleep - ld hl, AlreadyAsleepText - jp PrintText -.notAlreadySleeping - ld a, b - and a - jr nz, .didntAffect ; can't affect a mon that is already statused - push de - call MoveHitTest ; apply accuracy tests - pop de - ld a, [wMoveMissed] - and a - jr nz, .didntAffect -.setSleepCounter -; set target's sleep counter to a random number between 1 and 7 - call BattleRandom - and $7 - jr z, .setSleepCounter - ld b, a - ld a, [wUnknownSerialFlag_d499] - and a - jr z, .asm_3f1ba ; XXX stadium stuff? - ld a, b - and $3 - jr z, .setSleepCounter - ld b, a -.asm_3f1ba - ld a, b - ld [de], a - call PlayCurrentMoveAnimation2 - ld hl, FellAsleepText - jp PrintText -.didntAffect - jp PrintDidntAffectText - -FellAsleepText: - TX_FAR _FellAsleepText - db "@" - -AlreadyAsleepText: - TX_FAR _AlreadyAsleepText - db "@" - -PoisonEffect: - ld hl, wEnemyMonStatus - ld de, wPlayerMoveEffect - ld a, [H_WHOSETURN] - and a - jr z, .poisonEffect - ld hl, wBattleMonStatus - ld de, wEnemyMoveEffect -.poisonEffect - call CheckTargetSubstitute - jr nz, .noEffect ; can't poison a substitute target - ld a, [hli] - ld b, a - and a - jr nz, .noEffect ; miss if target is already statused - ld a, [hli] - cp POISON ; can't poison a poison-type target - jr z, .noEffect - ld a, [hld] - cp POISON ; can't poison a poison-type target - jr z, .noEffect - ld a, [de] - cp POISON_SIDE_EFFECT1 - ld b, $34 ; ~20% chance of poisoning - jr z, .sideEffectTest - cp POISON_SIDE_EFFECT2 - ld b, $67 ; ~40% chance of poisoning - jr z, .sideEffectTest - push hl - push de - call MoveHitTest ; apply accuracy tests - pop de - pop hl - ld a, [wMoveMissed] - and a - jr nz, .didntAffect - jr .inflictPoison -.sideEffectTest - call BattleRandom - cp b ; was side effect successful? - ret nc -.inflictPoison - dec hl - set 3, [hl] ; mon is now poisoned - push de - dec de - ld a, [H_WHOSETURN] - and a - ld b, ANIM_C7 - ld hl, wPlayerBattleStatus3 - ld a, [de] - ld de, wPlayerToxicCounter - jr nz, .ok - ld b, ANIM_A9 - ld hl, wEnemyBattleStatus3 - ld de, wEnemyToxicCounter -.ok - cp TOXIC - jr nz, .normalPoison ; done if move is not Toxic - set BADLY_POISONED, [hl] ; else set Toxic battstatus - xor a - ld [de], a - ld hl, BadlyPoisonedText - jr .continue -.normalPoison - ld hl, PoisonedText -.continue - pop de - ld a, [de] - cp POISON_EFFECT - jr z, .regularPoisonEffect - ld a, b - call PlayBattleAnimation2 - jp PrintText -.regularPoisonEffect - call PlayCurrentMoveAnimation2 - jp PrintText -.noEffect - ld a, [de] - cp POISON_EFFECT - ret nz -.didntAffect - ld c, 50 - call DelayFrames - jp PrintDidntAffectText - -PoisonedText: - TX_FAR _PoisonedText - db "@" - -BadlyPoisonedText: - TX_FAR _BadlyPoisonedText - db "@" - -DrainHPEffect: - jpab DrainHPEffect_ - -ExplodeEffect: - ld hl, wBattleMonHP - ld de, wPlayerBattleStatus2 - ld a, [H_WHOSETURN] - and a - jr z, .faintUser - ld hl, wEnemyMonHP - ld de, wEnemyBattleStatus2 -.faintUser - xor a - ld [hli], a ; set the mon's HP to 0 - ld [hli], a - inc hl - ld [hl], a ; set mon's status to 0 - ld a, [de] - res SEEDED, a ; clear mon's leech seed status - ld [de], a - ret - -FreezeBurnParalyzeEffect: - xor a - ld [wAnimationType], a - call CheckTargetSubstitute ; test bit 4 of d063/d068 flags [target has substitute flag] - ret nz ; return if they have a substitute, can't effect them - ld a, [H_WHOSETURN] - and a - jp nz, .opponentAttacker - ld a, [wEnemyMonStatus] - and a - jp nz, CheckDefrost ; can't inflict status if opponent is already statused - ld a, [wPlayerMoveType] - ld b, a - ld a, [wEnemyMonType1] - cp b ; do target type 1 and move type match? - ret z ; return if they match (an ice move can't freeze an ice-type, body slam can't paralyze a normal-type, etc.) - ld a, [wEnemyMonType2] - cp b ; do target type 2 and move type match? - ret z ; return if they match - ld a, [wPlayerMoveEffect] - cp UNUSED_EFFECT_23 ; more stadium stuff - jr nz, .asm_3f2c7 - ld a, [wUnknownSerialFlag_d499] - and a - ld a, FREEZE_SIDE_EFFECT - ld b, $4d ; else use 0x4D/0x100 or 77/256 = 30.1%~ chance - jr z, .next1 - ld b, $1a ; 0x1A/0x100 or 26/256 = 10.2%~ chance - jr .next1 -.asm_3f2c7 - cp a, PARALYZE_SIDE_EFFECT1 + 1 ; 10% status effects are 04, 05, 06 so 07 will set carry for those - ld b, $1a ; 0x1A/0x100 or 26/256 = 10.2%~ chance - jr c, .next1 ; branch ahead if this is a 10% chance effect.. - ld b, $4d ; else use 0x4D/0x100 or 77/256 = 30.1%~ chance - sub $1e ; subtract $1E to map to equivalent 10% chance effects -.next1 - push af - call BattleRandom ; get random 8bit value for probability test - cp b - pop bc - ret nc ; do nothing if random value is >= 1A or 4D [no status applied] - ld a, b ; what type of effect is this? - cp BURN_SIDE_EFFECT1 - jr z, .burn1 - cp FREEZE_SIDE_EFFECT - jr z, .freeze1 -; .paralyze - ld a, 1 << PAR - ld [wEnemyMonStatus], a - call QuarterSpeedDueToParalysis ; quarter speed of affected mon - ld a, ANIM_A9 - call PlayBattleAnimation - jp PrintMayNotAttackText ; print paralysis text -.burn1 - ld a, 1 << BRN - ld [wEnemyMonStatus], a - call HalveAttackDueToBurn ; halve attack of affected mon - ld a, ANIM_A9 - call PlayBattleAnimation - ld hl, BurnedText - jp PrintText -.freeze1 - call ClearHyperBeam ; resets hyper beam (recharge) condition from target - ld a, 1 << FRZ - ld [wEnemyMonStatus], a - ld a, ANIM_A9 - call PlayBattleAnimation - ld hl, FrozenText - jp PrintText -.opponentAttacker - ld a, [wBattleMonStatus] ; mostly same as above with addresses swapped for opponent - and a - jp nz, CheckDefrost - ld a, [wEnemyMoveType] - ld b, a - ld a, [wBattleMonType1] - cp b - ret z - ld a, [wBattleMonType2] - cp b - ret z - ld a, [wEnemyMoveEffect] - cp UNUSED_EFFECT_23 ; more stadium stuff - jr nz, .asm_3f341 - ld a, [wUnknownSerialFlag_d499] - and a - ld a, FREEZE_SIDE_EFFECT - ld b, $4d ; else use 0x4D/0x100 or 77/256 = 30.1%~ chance - jr z, .next2 - ld b, $1a ; 0x1A/0x100 or 26/256 = 10.2%~ chance - jr .next2 -.asm_3f341 - cp a, PARALYZE_SIDE_EFFECT1 + 1 - ld b, $1a - jr c, .next2 - ld b, $4d - sub $1e -.next2 - push af - call BattleRandom - cp b - pop bc - ret nc - ld a, b - cp BURN_SIDE_EFFECT1 - jr z, .burn2 - cp FREEZE_SIDE_EFFECT - jr z, .freeze2 - ld a, 1 << PAR - ld [wBattleMonStatus], a - call QuarterSpeedDueToParalysis - ld a, ANIM_C7 - call PlayBattleAnimation2 - jp PrintMayNotAttackText -.burn2 - ld a, 1 << BRN - ld [wBattleMonStatus], a - call HalveAttackDueToBurn - ld a, ANIM_C7 - call PlayBattleAnimation2 - ld hl, BurnedText - jp PrintText -.freeze2 -; hyper beam bits aren't reseted for opponent's side - ld a, 1 << FRZ - ld [wBattleMonStatus], a - ld a, ANIM_C7 - call PlayBattleAnimation2 - ld hl, FrozenText - jp PrintText - -BurnedText: - TX_FAR _BurnedText - db "@" - -FrozenText: - TX_FAR _FrozenText - db "@" - -CheckDefrost: -; any fire-type move that has a chance inflict burn (all but Fire Spin) will defrost a frozen target - and 1 << FRZ ; are they frozen? - ret z ; return if so - ld a, [H_WHOSETURN] - and a - jr nz, .opponent - ;player [attacker] - ld a, [wPlayerMoveType] - sub FIRE - ret nz ; return if type of move used isn't fire - ld [wEnemyMonStatus], a ; set opponent status to 00 ["defrost" a frozen monster] - ld hl, wEnemyMon1Status - ld a, [wEnemyMonPartyPos] - ld bc, wEnemyMon2 - wEnemyMon1 - call AddNTimes - xor a - ld [hl], a ; clear status in roster - ld hl, FireDefrostedText - jr .common -.opponent - ld a, [wEnemyMoveType] ; same as above with addresses swapped - sub FIRE - ret nz - ld [wBattleMonStatus], a - ld hl, wPartyMon1Status - ld a, [wPlayerMonNumber] - ld bc, wPartyMon2 - wPartyMon1 - call AddNTimes - xor a - ld [hl], a - ld hl, FireDefrostedText -.common - jp PrintText - -FireDefrostedText: - TX_FAR _FireDefrostedText - db "@" - -StatModifierUpEffect: - ld hl, wPlayerMonStatMods - ld de, wPlayerMoveEffect - ld a, [H_WHOSETURN] - and a - jr z, .statModifierUpEffect - ld hl, wEnemyMonStatMods - ld de, wEnemyMoveEffect -.statModifierUpEffect - ld a, [de] - sub ATTACK_UP1_EFFECT - cp EVASION_UP1_EFFECT + $3 - ATTACK_UP1_EFFECT ; covers all +1 effects - jr c, .incrementStatMod - sub ATTACK_UP2_EFFECT - ATTACK_UP1_EFFECT ; map +2 effects to equivalent +1 effect -.incrementStatMod - ld c, a - ld b, $0 - add hl, bc - ld b, [hl] - inc b ; increment corresponding stat mod - ld a, $d - cp b ; can't raise stat past +6 ($d or 13) - jp c, PrintNothingHappenedText - ld a, [de] - cp ATTACK_UP1_EFFECT + $8 ; is it a +2 effect? - jr c, .ok - inc b ; if so, increment stat mod again - ld a, $d - cp b ; unless it's already +6 - jr nc, .ok - ld b, a -.ok - ld [hl], b - ld a, c - cp $4 - jr nc, UpdateStatDone ; jump if mod affected is evasion/accuracy - push hl - ld hl, wBattleMonAttack + 1 - ld de, wPlayerMonUnmodifiedAttack - ld a, [H_WHOSETURN] - and a - jr z, .pointToStats - ld hl, wEnemyMonAttack + 1 - ld de, wEnemyMonUnmodifiedAttack -.pointToStats - push bc - sla c - ld b, $0 - add hl, bc ; hl = modified stat - ld a, c - add e - ld e, a - jr nc, .checkIf999 - inc d ; de = unmodified (original) stat -.checkIf999 - pop bc - ld a, [hld] - sub 999 % $100 ; check if stat is already 999 - jr nz, .recalculateStat - ld a, [hl] - sbc 999 / $100 - jp z, RestoreOriginalStatModifier -.recalculateStat ; recalculate affected stat - ; paralysis and burn penalties, as well as badge boosts are ignored - push hl - push bc - ld hl, StatModifierRatios - dec b - sla b - ld c, b - ld b, $0 - add hl, bc - pop bc - xor a - ld [H_MULTIPLICAND], a - ld a, [de] - ld [H_MULTIPLICAND + 1], a - inc de - ld a, [de] - ld [H_MULTIPLICAND + 2], a - ld a, [hli] - ld [H_MULTIPLIER], a - call Multiply - ld a, [hl] - ld [H_DIVISOR], a - ld b, $4 - call Divide - pop hl -; cap at 999 - ld a, [H_PRODUCT + 3] - sub 999 % $100 - ld a, [H_PRODUCT + 2] - sbc 999 / $100 - jp c, UpdateStat - ld a, 999 / $100 - ld [H_MULTIPLICAND + 1], a - ld a, 999 % $100 - ld [H_MULTIPLICAND + 2], a - -UpdateStat: - ld a, [H_PRODUCT + 2] - ld [hli], a - ld a, [H_PRODUCT + 3] - ld [hl], a - pop hl -UpdateStatDone: - ld b, c - inc b - call PrintStatText - ld hl, wPlayerBattleStatus2 - ld de, wPlayerMoveNum - ld bc, wPlayerMonMinimized - ld a, [H_WHOSETURN] - and a - jr z, .playerTurn - ld hl, wEnemyBattleStatus2 - ld de, wEnemyMoveNum - ld bc, wEnemyMonMinimized -.playerTurn - ld a, [de] - cp MINIMIZE - jr nz, .notMinimize - ; if a substitute is up, slide off the substitute and show the mon pic before - ; playing the minimize animation - bit HAS_SUBSTITUTE_UP, [hl] - push af - push bc - push de - ld hl, HideSubstituteShowMonAnim - ld b, BANK(HideSubstituteShowMonAnim) - call nz, Bankswitch - pop de -.notMinimize - call PlayCurrentMoveAnimation - ld a, [de] - cp MINIMIZE - jr nz, .applyBadgeBoostsAndStatusPenalties - pop bc - ld a, $1 - ld [bc], a - ld hl, ReshowSubstituteAnim - ld b, BANK(ReshowSubstituteAnim) - pop af - call nz, Bankswitch -.applyBadgeBoostsAndStatusPenalties - ld a, [H_WHOSETURN] - and a - call z, ApplyBadgeStatBoosts ; whenever the player uses a stat-up move, badge boosts get reapplied again to every stat, - ; even to those not affected by the stat-up move (will be boosted further) - ld hl, MonsStatsRoseText - call PrintText - -; these shouldn't be here - call QuarterSpeedDueToParalysis ; apply speed penalty to the player whose turn is not, if it's paralyzed - jp HalveAttackDueToBurn ; apply attack penalty to the player whose turn is not, if it's burned - -RestoreOriginalStatModifier: - pop hl - dec [hl] - -PrintNothingHappenedText: - ld hl, NothingHappenedText - jp PrintText - -MonsStatsRoseText: - TX_FAR _MonsStatsRoseText - TX_ASM - ld hl, GreatlyRoseText - ld a, [H_WHOSETURN] - and a - ld a, [wPlayerMoveEffect] - jr z, .playerTurn - ld a, [wEnemyMoveEffect] -.playerTurn - cp ATTACK_DOWN1_EFFECT - ret nc - ld hl, RoseText - ret - -GreatlyRoseText: - TX_DELAY - TX_FAR _GreatlyRoseText -; fallthrough -RoseText: - TX_FAR _RoseText - db "@" - -StatModifierDownEffect: - ld hl, wEnemyMonStatMods - ld de, wPlayerMoveEffect - ld bc, wEnemyBattleStatus1 - ld a, [H_WHOSETURN] - and a - jr z, .statModifierDownEffect - ld hl, wPlayerMonStatMods - ld de, wEnemyMoveEffect - ld bc, wPlayerBattleStatus1 - ld a, [wLinkState] - cp LINK_STATE_BATTLING - jr z, .statModifierDownEffect - call BattleRandom - cp $40 ; 1/4 chance to miss by in regular battle - jp c, MoveMissed -.statModifierDownEffect - call CheckTargetSubstitute ; can't hit through substitute - jp nz, MoveMissed - ld a, [de] - cp ATTACK_DOWN_SIDE_EFFECT - jr c, .nonSideEffect - call BattleRandom - cp $55 ; 85/256 chance for side effects - jp nc, CantLowerAnymore - ld a, [de] - sub ATTACK_DOWN_SIDE_EFFECT ; map each stat to 0-3 - jr .decrementStatMod -.nonSideEffect ; non-side effects only - push hl - push de - push bc - call MoveHitTest ; apply accuracy tests - pop bc - pop de - pop hl - ld a, [wMoveMissed] - and a - jp nz, MoveMissed - ld a, [bc] - bit INVULNERABLE, a ; fly/dig - jp nz, MoveMissed - ld a, [de] - sub ATTACK_DOWN1_EFFECT - cp EVASION_DOWN1_EFFECT + $3 - ATTACK_DOWN1_EFFECT ; covers all -1 effects - jr c, .decrementStatMod - sub ATTACK_DOWN2_EFFECT - ATTACK_DOWN1_EFFECT ; map -2 effects to corresponding -1 effect -.decrementStatMod - ld c, a - ld b, $0 - add hl, bc - ld b, [hl] - dec b ; dec corresponding stat mod - jp z, CantLowerAnymore ; if stat mod is 1 (-6), can't lower anymore - ld a, [de] - cp ATTACK_DOWN2_EFFECT - $16 ; $24 - jr c, .ok - cp EVASION_DOWN2_EFFECT + $5 ; $44 - jr nc, .ok - dec b ; stat down 2 effects only (dec mod again) - jr nz, .ok - inc b ; increment mod to 1 (-6) if it would become 0 (-7) -.ok - ld [hl], b ; save modified mod - ld a, c - cp $4 - jr nc, UpdateLoweredStatDone ; jump for evasion/accuracy - push hl - push de - ld hl, wEnemyMonAttack + 1 - ld de, wEnemyMonUnmodifiedAttack - ld a, [H_WHOSETURN] - and a - jr z, .pointToStat - ld hl, wBattleMonAttack + 1 - ld de, wPlayerMonUnmodifiedAttack -.pointToStat - push bc - sla c - ld b, $0 - add hl, bc ; hl = modified stat - ld a, c - add e - ld e, a - jr nc, .noCarry - inc d ; de = unmodified stat -.noCarry - pop bc - ld a, [hld] - sub $1 ; can't lower stat below 1 (-6) - jr nz, .recalculateStat - ld a, [hl] - and a - jp z, CantLowerAnymore_Pop -.recalculateStat -; recalculate affected stat -; paralysis and burn penalties, as well as badge boosts are ignored - push hl - push bc - ld hl, StatModifierRatios - dec b - sla b - ld c, b - ld b, $0 - add hl, bc - pop bc - xor a - ld [H_MULTIPLICAND], a - ld a, [de] - ld [H_MULTIPLICAND + 1], a - inc de - ld a, [de] - ld [H_MULTIPLICAND + 2], a - ld a, [hli] - ld [H_MULTIPLIER], a - call Multiply - ld a, [hl] - ld [H_DIVISOR], a - ld b, $4 - call Divide - pop hl - ld a, [H_PRODUCT + 3] - ld b, a - ld a, [H_PRODUCT + 2] - or b - jp nz, UpdateLoweredStat - ld [H_MULTIPLICAND + 1], a - ld a, $1 - ld [H_MULTIPLICAND + 2], a - -UpdateLoweredStat: - ld a, [H_PRODUCT + 2] - ld [hli], a - ld a, [H_PRODUCT + 3] - ld [hl], a - pop de - pop hl -UpdateLoweredStatDone: - ld b, c - inc b - push de - call PrintStatText - pop de - ld a, [de] - cp $44 - jr nc, .ApplyBadgeBoostsAndStatusPenalties - call PlayCurrentMoveAnimation2 -.ApplyBadgeBoostsAndStatusPenalties - ld a, [H_WHOSETURN] - and a - call nz, ApplyBadgeStatBoosts ; whenever the player uses a stat-down move, badge boosts get reapplied again to every stat, - ; even to those not affected by the stat-up move (will be boosted further) - ld hl, MonsStatsFellText - call PrintText - -; These where probably added given that a stat-down move affecting speed or attack will override -; the stat penalties from paralysis and burn respectively. -; But they are always called regardless of the stat affected by the stat-down move. - call QuarterSpeedDueToParalysis - jp HalveAttackDueToBurn - -CantLowerAnymore_Pop: - pop de - pop hl - inc [hl] - -CantLowerAnymore: - ld a, [de] - cp ATTACK_DOWN_SIDE_EFFECT - ret nc - ld hl, NothingHappenedText - jp PrintText - -MoveMissed: - ld a, [de] - cp $44 - ret nc - jp ConditionalPrintButItFailed - -MonsStatsFellText: - TX_FAR _MonsStatsFellText - TX_ASM - ld hl, FellText - ld a, [H_WHOSETURN] - and a - ld a, [wPlayerMoveEffect] - jr z, .playerTurn - ld a, [wEnemyMoveEffect] -.playerTurn -; check if the move's effect decreases a stat by 2 - cp BIDE_EFFECT - ret c - cp ATTACK_DOWN_SIDE_EFFECT - ret nc - ld hl, GreatlyFellText - ret - -GreatlyFellText: - TX_DELAY - TX_FAR _GreatlyFellText -; fallthrough -FellText: - TX_FAR _FellText - db "@" - -PrintStatText: - ld hl, StatsTextStrings - ld c, "@" -.findStatName_outer - dec b - jr z, .foundStatName -.findStatName_inner - ld a, [hli] - cp c - jr z, .findStatName_outer - jr .findStatName_inner -.foundStatName - ld de, wcf4b - ld bc, $a - jp CopyData - -StatsTextStrings: - db "ATTACK@" - db "DEFENSE@" - db "SPEED@" - db "SPECIAL@" - db "ACCURACY@" - db "EVADE@" - -StatModifierRatios: -; first byte is numerator, second byte is denominator - db 25, 100 ; 0.25 - db 28, 100 ; 0.28 - db 33, 100 ; 0.33 - db 40, 100 ; 0.40 - db 50, 100 ; 0.50 - db 66, 100 ; 0.66 - db 1, 1 ; 1.00 - db 15, 10 ; 1.50 - db 2, 1 ; 2.00 - db 25, 10 ; 2.50 - db 3, 1 ; 3.00 - db 35, 10 ; 3.50 - db 4, 1 ; 4.00 - -BideEffect: - ld hl, wPlayerBattleStatus1 - ld de, wPlayerBideAccumulatedDamage - ld bc, wPlayerNumAttacksLeft - ld a, [H_WHOSETURN] - and a - jr z, .bideEffect - ld hl, wEnemyBattleStatus1 - ld de, wEnemyBideAccumulatedDamage - ld bc, wEnemyNumAttacksLeft -.bideEffect - set STORING_ENERGY, [hl] ; mon is now using bide - xor a - ld [de], a - inc de - ld [de], a - ld [wPlayerMoveEffect], a - ld [wEnemyMoveEffect], a - call BattleRandom - and $1 - inc a - inc a - ld [bc], a ; set Bide counter to 2 or 3 at random - ld a, [H_WHOSETURN] - add XSTATITEM_ANIM - jp PlayBattleAnimation2 - -ThrashPetalDanceEffect: - ld hl, wPlayerBattleStatus1 - ld de, wPlayerNumAttacksLeft - ld a, [H_WHOSETURN] - and a - jr z, .thrashPetalDanceEffect - ld hl, wEnemyBattleStatus1 - ld de, wEnemyNumAttacksLeft -.thrashPetalDanceEffect - set THRASHING_ABOUT, [hl] ; mon is now using thrash/petal dance - call BattleRandom - and $1 - inc a - inc a - ld [de], a ; set thrash/petal dance counter to 2 or 3 at random - ld a, [H_WHOSETURN] - add ANIM_B0 - jp PlayBattleAnimation2 - -SwitchAndTeleportEffect: - ld a, [H_WHOSETURN] - and a - jr nz, .handleEnemy - ld a, [wIsInBattle] - dec a - jr nz, .notWildBattle1 - ld a, [wCurEnemyLVL] - ld b, a - ld a, [wBattleMonLevel] - cp b ; is the player's level greater than the enemy's level? - jr nc, .playerMoveWasSuccessful ; if so, teleport will always succeed - add b - ld c, a - inc c ; c = sum of player level and enemy level -.rejectionSampleLoop1 - call BattleRandom - cp c ; get a random number between 0 and c - jr nc, .rejectionSampleLoop1 - srl b - srl b ; b = enemyLevel / 4 - cp b ; is rand[0, playerLevel + enemyLevel) >= (enemyLevel / 4)? - jr nc, .playerMoveWasSuccessful ; if so, allow teleporting - ld c, 50 - call DelayFrames - ld a, [wPlayerMoveNum] - cp TELEPORT - jp nz, PrintDidntAffectText - jp PrintButItFailedText_ -.playerMoveWasSuccessful - call ReadPlayerMonCurHPAndStatus - xor a - ld [wAnimationType], a - inc a - ld [wEscapedFromBattle], a - ld a, [wPlayerMoveNum] - jr .playAnimAndPrintText -.notWildBattle1 - ld c, 50 - call DelayFrames - ld hl, IsUnaffectedText - ld a, [wPlayerMoveNum] - cp TELEPORT - jp nz, PrintText - jp PrintButItFailedText_ -.handleEnemy - ld a, [wIsInBattle] - dec a - jr nz, .notWildBattle2 - ld a, [wBattleMonLevel] - ld b, a - ld a, [wCurEnemyLVL] - cp b - jr nc, .enemyMoveWasSuccessful - add b - ld c, a - inc c -.rejectionSampleLoop2 - call BattleRandom - cp c - jr nc, .rejectionSampleLoop2 - srl b - srl b - cp b - jr nc, .enemyMoveWasSuccessful - ld c, 50 - call DelayFrames - ld a, [wEnemyMoveNum] - cp TELEPORT - jp nz, PrintDidntAffectText - jp PrintButItFailedText_ -.enemyMoveWasSuccessful - call ReadPlayerMonCurHPAndStatus - xor a - ld [wAnimationType], a - inc a - ld [wEscapedFromBattle], a - ld a, [wEnemyMoveNum] - jr .playAnimAndPrintText -.notWildBattle2 - ld c, 50 - call DelayFrames - ld hl, IsUnaffectedText - ld a, [wEnemyMoveNum] - cp TELEPORT - jp nz, PrintText - jp ConditionalPrintButItFailed -.playAnimAndPrintText - push af - call PlayBattleAnimation - ld c, 20 - call DelayFrames - pop af - ld hl, RanFromBattleText - cp TELEPORT - jr z, .printText - ld hl, RanAwayScaredText - cp ROAR - jr z, .printText - ld hl, WasBlownAwayText -.printText - jp PrintText - -RanFromBattleText: - TX_FAR _RanFromBattleText - db "@" - -RanAwayScaredText: - TX_FAR _RanAwayScaredText - db "@" - -WasBlownAwayText: - TX_FAR _WasBlownAwayText - db "@" - -TwoToFiveAttacksEffect: - ld hl, wPlayerBattleStatus1 - ld de, wPlayerNumAttacksLeft - ld bc, wPlayerNumHits - ld a, [H_WHOSETURN] - and a - jr z, .twoToFiveAttacksEffect - ld hl, wEnemyBattleStatus1 - ld de, wEnemyNumAttacksLeft - ld bc, wEnemyNumHits -.twoToFiveAttacksEffect - bit ATTACKING_MULTIPLE_TIMES, [hl] ; is mon attacking multiple times? - ret nz - set ATTACKING_MULTIPLE_TIMES, [hl] ; mon is now attacking multiple times - ld hl, wPlayerMoveEffect - ld a, [H_WHOSETURN] - and a - jr z, .setNumberOfHits - ld hl, wEnemyMoveEffect -.setNumberOfHits - ld a, [hl] - cp TWINEEDLE_EFFECT - jr z, .twineedle - cp ATTACK_TWICE_EFFECT - ld a, $2 ; number of hits it's always 2 for ATTACK_TWICE_EFFECT - jr z, .saveNumberOfHits -; for TWO_TO_FIVE_ATTACKS_EFFECT 3/8 chance for 2 and 3 hits, and 1/8 chance for 4 and 5 hits - call BattleRandom - and $3 - cp $2 - jr c, .gotNumHits -; if the number of hits was greater than 2, re-roll again for a lower chance - call BattleRandom - and $3 -.gotNumHits - inc a - inc a -.saveNumberOfHits - ld [de], a - ld [bc], a - ret -.twineedle - ld a, POISON_SIDE_EFFECT1 - ld [hl], a ; set Twineedle's effect to poison effect - jr .saveNumberOfHits - -FlinchSideEffect: - call CheckTargetSubstitute - ret nz - ld hl, wEnemyBattleStatus1 - ld de, wPlayerMoveEffect - ld a, [H_WHOSETURN] - and a - jr z, .flinchSideEffect - ld hl, wPlayerBattleStatus1 - ld de, wEnemyMoveEffect -.flinchSideEffect - ld a, [wLinkState] - cp LINK_STATE_BATTLING - call z, ClearHyperBeam - ld a, [de] - cp FLINCH_SIDE_EFFECT1 - ld b, $1a ; ~10% chance of flinch - jr z, .gotEffectChance - ld b, $4d ; ~30% chance of flinch -.gotEffectChance - call BattleRandom - cp b - ret nc - set FLINCHED, [hl] ; set mon's status to flinching - call ClearHyperBeam - ret - -OneHitKOEffect: - jpab OneHitKOEffect_ - -ChargeEffect: - ld hl, wPlayerBattleStatus1 - ld de, wPlayerMoveEffect - ld a, [H_WHOSETURN] - and a - ld b, XSTATITEM_ANIM - jr z, .chargeEffect - ld hl, wEnemyBattleStatus1 - ld de, wEnemyMoveEffect - ld b, ANIM_AF -.chargeEffect - set CHARGING_UP, [hl] - ld a, [de] - dec de ; de contains enemy or player MOVENUM - cp FLY_EFFECT - jr nz, .notFly - set INVULNERABLE, [hl] ; mon is now invulnerable to typical attacks (fly/dig) - ld b, TELEPORT ; load Teleport's animation -.notFly - ld a, [de] - cp DIG - jr nz, .notDigOrFly - set INVULNERABLE, [hl] ; mon is now invulnerable to typical attacks (fly/dig) - ld b, ANIM_C0 -.notDigOrFly - push de - push bc - inc hl ; battle status 2 - push hl - ld a, [hl] - bit HAS_SUBSTITUTE_UP, a - ld hl, HideSubstituteShowMonAnim - ld b, BANK(HideSubstituteShowMonAnim) - call nz, Bankswitch - pop hl - pop bc - xor a - ld [wAnimationType], a - ld a, b - call PlayBattleAnimation - ld a, [hl] - bit HAS_SUBSTITUTE_UP, a - ld hl, ReshowSubstituteAnim - ld b, BANK(ReshowSubstituteAnim) - call nz, Bankswitch - pop de - ld a, [de] - ld [wChargeMoveNum], a - ld hl, ChargeMoveEffectText - jp PrintText - -ChargeMoveEffectText: - TX_FAR _ChargeMoveEffectText - TX_ASM - ld a, [wChargeMoveNum] - cp RAZOR_WIND - ld hl, MadeWhirlwindText - jr z, .gotText - cp SOLARBEAM - ld hl, TookInSunlightText - jr z, .gotText - cp SKULL_BASH - ld hl, LoweredItsHeadText - jr z, .gotText - cp SKY_ATTACK - ld hl, SkyAttackGlowingText - jr z, .gotText - cp FLY - ld hl, FlewUpHighText - jr z, .gotText - cp DIG - ld hl, DugAHoleText -.gotText - ret - -MadeWhirlwindText: - TX_FAR _MadeWhirlwindText - db "@" - -TookInSunlightText: - TX_FAR _TookInSunlightText - db "@" - -LoweredItsHeadText: - TX_FAR _LoweredItsHeadText - db "@" - -SkyAttackGlowingText: - TX_FAR _SkyAttackGlowingText - db "@" - -FlewUpHighText: - TX_FAR _FlewUpHighText - db "@" - -DugAHoleText: - TX_FAR _DugAHoleText - db "@" - -TrappingEffect: - ld hl, wPlayerBattleStatus1 - ld de, wPlayerNumAttacksLeft - ld a, [H_WHOSETURN] - and a - jr z, .trappingEffect - ld hl, wEnemyBattleStatus1 - ld de, wEnemyNumAttacksLeft -.trappingEffect - bit USING_TRAPPING_MOVE, [hl] - ret nz - call ClearHyperBeam ; since this effect is called before testing whether the move will hit, - ; the target won't need to recharge even if the trapping move missed - set USING_TRAPPING_MOVE, [hl] ; mon is now using a trapping move - call BattleRandom ; 3/8 chance for 2 and 3 attacks, and 1/8 chance for 4 and 5 attacks - and $3 - cp $2 - jr c, .setTrappingCounter - call BattleRandom - and $3 -.setTrappingCounter - inc a - ld [de], a - ret - -MistEffect: - jpab MistEffect_ - -FocusEnergyEffect: - jpab FocusEnergyEffect_ - -RecoilEffect: - jpab RecoilEffect_ - -ConfusionSideEffect: - call BattleRandom - cp $19 ; ~10% chance - ret nc - jr ConfusionSideEffectSuccess - -ConfusionEffect: - call CheckTargetSubstitute - jr nz, ConfusionEffectFailed - call MoveHitTest - ld a, [wMoveMissed] - and a - jr nz, ConfusionEffectFailed - -ConfusionSideEffectSuccess: - ld a, [H_WHOSETURN] - and a - ld hl, wEnemyBattleStatus1 - ld bc, wEnemyConfusedCounter - ld a, [wPlayerMoveEffect] - jr z, .confuseTarget - ld hl, wPlayerBattleStatus1 - ld bc, wPlayerConfusedCounter - ld a, [wEnemyMoveEffect] -.confuseTarget - bit CONFUSED, [hl] ; is mon confused? - jr nz, ConfusionEffectFailed - set CONFUSED, [hl] ; mon is now confused - push af - call BattleRandom - and $3 - inc a - inc a - ld [bc], a ; confusion status will last 2-5 turns - pop af - cp CONFUSION_SIDE_EFFECT - call nz, PlayCurrentMoveAnimation2 - ld hl, BecameConfusedText - jp PrintText - -BecameConfusedText: - TX_FAR _BecameConfusedText - db "@" - -ConfusionEffectFailed: - cp CONFUSION_SIDE_EFFECT - ret z - ld c, 50 - call DelayFrames - jp ConditionalPrintButItFailed - -ParalyzeEffect: - jpab ParalyzeEffect_ - -SubstituteEffect: - jpab SubstituteEffect_ - -HyperBeamEffect: - ld hl, wPlayerBattleStatus2 - ld a, [H_WHOSETURN] - and a - jr z, .hyperBeamEffect - ld hl, wEnemyBattleStatus2 -.hyperBeamEffect - set NEEDS_TO_RECHARGE, [hl] ; mon now needs to recharge - ret - -ClearHyperBeam: - push hl - ld hl, wEnemyBattleStatus2 - ld a, [H_WHOSETURN] - and a - jr z, .playerTurn - ld hl, wPlayerBattleStatus2 -.playerTurn - res NEEDS_TO_RECHARGE, [hl] ; mon no longer needs to recharge - pop hl - ret - -RageEffect: - ld hl, wPlayerBattleStatus2 - ld a, [H_WHOSETURN] - and a - jr z, .player - ld hl, wEnemyBattleStatus2 -.player - set USING_RAGE, [hl] ; mon is now in "rage" mode - ret - -MimicEffect: - ld c, 50 - call DelayFrames - call MoveHitTest - ld a, [wMoveMissed] - and a - jr nz, .mimicMissed - ld a, [H_WHOSETURN] - and a - ld hl, wBattleMonMoves - ld a, [wPlayerBattleStatus1] - jr nz, .enemyTurn - ld a, [wLinkState] - cp LINK_STATE_BATTLING - jr nz, .letPlayerChooseMove - ld hl, wEnemyMonMoves - ld a, [wEnemyBattleStatus1] -.enemyTurn - bit INVULNERABLE, a - jr nz, .mimicMissed -.getRandomMove - push hl - call BattleRandom - and $3 - ld c, a - ld b, $0 - add hl, bc - ld a, [hl] - pop hl - and a - jr z, .getRandomMove - ld d, a - ld a, [H_WHOSETURN] - and a - ld hl, wBattleMonMoves - ld a, [wPlayerMoveListIndex] - jr z, .playerTurn - ld hl, wEnemyMonMoves - ld a, [wEnemyMoveListIndex] - jr .playerTurn -.letPlayerChooseMove - ld a, [wEnemyBattleStatus1] - bit INVULNERABLE, a - jr nz, .mimicMissed - ld a, [wCurrentMenuItem] - push af - ld a, $1 - ld [wMoveMenuType], a - call MoveSelectionMenu - call LoadScreenTilesFromBuffer1 - ld hl, wEnemyMonMoves - ld a, [wCurrentMenuItem] - ld c, a - ld b, $0 - add hl, bc - ld d, [hl] - pop af - ld hl, wBattleMonMoves -.playerTurn - ld c, a - ld b, $0 - add hl, bc - ld a, d - ld [hl], a - ld [wd11e], a - call GetMoveName - call PlayCurrentMoveAnimation - ld hl, MimicLearnedMoveText - jp PrintText -.mimicMissed - jp PrintButItFailedText_ - -MimicLearnedMoveText: - TX_FAR _MimicLearnedMoveText - db "@" - -LeechSeedEffect: - jpab LeechSeedEffect_ - -SplashEffect: - call PlayCurrentMoveAnimation - jp PrintNoEffectText - -DisableEffect: - call MoveHitTest - ld a, [wMoveMissed] - and a - jr nz, .moveMissed - ld de, wEnemyDisabledMove - ld hl, wEnemyMonMoves - ld a, [H_WHOSETURN] - and a - jr z, .disableEffect - ld de, wPlayerDisabledMove - ld hl, wBattleMonMoves -.disableEffect -; no effect if target already has a move disabled - ld a, [de] - and a - jr nz, .moveMissed -.pickMoveToDisable - push hl - call BattleRandom - and $3 - ld c, a - ld b, $0 - add hl, bc - ld a, [hl] - pop hl - and a - jr z, .pickMoveToDisable ; loop until a non-00 move slot is found - ld [wd11e], a ; store move number - push hl - ld a, [H_WHOSETURN] - and a - ld hl, wBattleMonPP - jr nz, .enemyTurn - ld a, [wLinkState] - cp LINK_STATE_BATTLING - pop hl ; wEnemyMonMoves - jr nz, .playerTurnNotLinkBattle -; .playerTurnLinkBattle - push hl - ld hl, wEnemyMonPP -.enemyTurn - push hl - ld a, [hli] - or [hl] - inc hl - or [hl] - inc hl - or [hl] - and $3f - pop hl ; wBattleMonPP or wEnemyMonPP - jr z, .moveMissedPopHL ; nothing to do if all moves have no PP left - add hl, bc - ld a, [hl] - pop hl - and a - jr z, .pickMoveToDisable ; pick another move if this one had 0 PP -.playerTurnNotLinkBattle -; non-link battle enemies have unlimited PP so the previous checks aren't needed - call BattleRandom - and $7 - inc a ; 1-8 turns disabled - inc c ; move 1-4 will be disabled - swap c - add c ; map disabled move to high nibble of wEnemyDisabledMove / wPlayerDisabledMove - ld [de], a - call PlayCurrentMoveAnimation2 - ld hl, wPlayerDisabledMoveNumber - ld a, [H_WHOSETURN] - and a - jr nz, .printDisableText - inc hl ; wEnemyDisabledMoveNumber -.printDisableText - ld a, [wd11e] ; move number - ld [hl], a - call GetMoveName - ld hl, MoveWasDisabledText - jp PrintText -.moveMissedPopHL - pop hl -.moveMissed - jp PrintButItFailedText_ - -MoveWasDisabledText: - TX_FAR _MoveWasDisabledText - db "@" - -PayDayEffect: - jpab PayDayEffect_ - -ConversionEffect: - jpab ConversionEffect_ - -HazeEffect: - jpab HazeEffect_ - -HealEffect: - jpab HealEffect_ - -TransformEffect: - jpab TransformEffect_ - -ReflectLightScreenEffect: - jpab ReflectLightScreenEffect_ - -NothingHappenedText: - TX_FAR _NothingHappenedText - db "@" - -PrintNoEffectText: - ld hl, NoEffectText - jp PrintText - -NoEffectText: - TX_FAR _NoEffectText - db "@" - -ConditionalPrintButItFailed: - ld a, [wMoveDidntMiss] - and a - ret nz ; return if the side effect failed, yet the attack was successful - -PrintButItFailedText_: - ld hl, ButItFailedText - jp PrintText - -ButItFailedText: - TX_FAR _ButItFailedText - db "@" - -PrintDidntAffectText: - ld hl, DidntAffectText - jp PrintText - -DidntAffectText: - TX_FAR _DidntAffectText - db "@" - -IsUnaffectedText: - TX_FAR _IsUnaffectedText - db "@" - -PrintMayNotAttackText: - ld hl, ParalyzedMayNotAttackText - jp PrintText - -ParalyzedMayNotAttackText: - TX_FAR _ParalyzedMayNotAttackText - db "@" - -CheckTargetSubstitute: - push hl - ld hl, wEnemyBattleStatus2 - ld a, [H_WHOSETURN] - and a - jr z, .next1 - ld hl, wPlayerBattleStatus2 -.next1 - bit HAS_SUBSTITUTE_UP, [hl] - pop hl - ret - -PlayCurrentMoveAnimation2: -; animation at MOVENUM will be played unless MOVENUM is 0 -; plays wAnimationType 3 or 6 - ld a, [H_WHOSETURN] - and a - ld a, [wPlayerMoveNum] - jr z, .notEnemyTurn - ld a, [wEnemyMoveNum] -.notEnemyTurn - and a - ret z - -PlayBattleAnimation2: -; play animation ID at a and animation type 6 or 3 - ld [wAnimationID], a - ld a, [H_WHOSETURN] - and a - ld a, $6 - jr z, .storeAnimationType - ld a, $3 -.storeAnimationType - ld [wAnimationType], a - jp PlayBattleAnimationGotID - -PlayCurrentMoveAnimation: -; animation at MOVENUM will be played unless MOVENUM is 0 -; resets wAnimationType - xor a - ld [wAnimationType], a - ld a, [H_WHOSETURN] - and a - ld a, [wPlayerMoveNum] - jr z, .notEnemyTurn - ld a, [wEnemyMoveNum] -.notEnemyTurn - and a - ret z - -PlayBattleAnimation: -; play animation ID at a and predefined animation type - ld [wAnimationID], a - -PlayBattleAnimationGotID: -; play animation at wAnimationID - push hl - push de - push bc - predef MoveAnimation - callab Func_78e98 - pop bc - pop de - pop hl + callfar Func_78e98 ret diff --git a/engine/battle/decrement_pp.asm b/engine/battle/decrement_pp.asm index b7c428f7..441bbb81 100644 --- a/engine/battle/decrement_pp.asm +++ b/engine/battle/decrement_pp.asm @@ -37,7 +37,7 @@ DecrementPP: ld a, [wPlayerMoveListIndex] ; which move (0, 1, 2, 3) did we use? ld c, a ld b, 0 - add hl ,bc ; calculate the address in memory of the PP we need to decrement + add hl, bc ; calculate the address in memory of the PP we need to decrement ; based on the move chosen. dec [hl] ; Decrement PP ret diff --git a/engine/battle/display_effectiveness.asm b/engine/battle/display_effectiveness.asm index 1bf14460..b23695cf 100644 --- a/engine/battle/display_effectiveness.asm +++ b/engine/battle/display_effectiveness.asm @@ -10,9 +10,9 @@ DisplayEffectiveness: jp PrintText SuperEffectiveText: - TX_FAR _SuperEffectiveText - db "@" + text_far _SuperEffectiveText + text_end NotVeryEffectiveText: - TX_FAR _NotVeryEffectiveText - db "@" + text_far _NotVeryEffectiveText + text_end diff --git a/engine/battle/draw_hud_pokeball_gfx.asm b/engine/battle/draw_hud_pokeball_gfx.asm index 96294774..6aed1d0a 100644 --- a/engine/battle/draw_hud_pokeball_gfx.asm +++ b/engine/battle/draw_hud_pokeball_gfx.asm @@ -12,7 +12,7 @@ DrawEnemyPokeballs: LoadPartyPokeballGfx: ld de, PokeballTileGraphics - ld hl, vSprites + $310 + ld hl, vSprites tile $31 lb bc, BANK(PokeballTileGraphics), (PokeballTileGraphicsEnd - PokeballTileGraphics) / $10 jp CopyVideoData @@ -125,7 +125,7 @@ PlacePlayerHUDTiles: ld de, wHUDGraphicsTiles ld bc, $3 call CopyData - coord hl, 18, 10 + hlcoord 18, 10 ld de, -1 jr PlaceHUDTiles @@ -140,7 +140,7 @@ PlaceEnemyHUDTiles: ld de, wHUDGraphicsTiles ld bc, $3 call CopyData - coord hl, 1, 2 + hlcoord 1, 2 ld de, $1 jr PlaceHUDTiles @@ -196,5 +196,5 @@ SetupPlayerAndEnemyPokeballs: ; four tiles: pokeball, black pokeball (status ailment), crossed out pokeball (fainted) and pokeball slot (no mon) PokeballTileGraphics:: - INCBIN "gfx/pokeball.2bpp" + INCBIN "gfx/battle/balls.2bpp" PokeballTileGraphicsEnd: diff --git a/engine/battle/effects.asm b/engine/battle/effects.asm new file mode 100644 index 00000000..c4e81816 --- /dev/null +++ b/engine/battle/effects.asm @@ -0,0 +1,1551 @@ +JumpMoveEffect: + call _JumpMoveEffect + ld b, $1 + ret + +_JumpMoveEffect: + ldh a, [hWhoseTurn] + and a + ld a, [wPlayerMoveEffect] + jr z, .next1 + ld a, [wEnemyMoveEffect] +.next1 + dec a ; subtract 1, there is no special effect for 00 + add a ; x2, 16bit pointers + ld hl, MoveEffectPointerTable + ld b, 0 + ld c, a + add hl, bc + ld a, [hli] + ld h, [hl] + ld l, a + jp hl ; jump to special effect handler + +INCLUDE "data/moves/effects_pointers.asm" + +SleepEffect: + ld de, wEnemyMonStatus + ld bc, wEnemyBattleStatus2 + ldh a, [hWhoseTurn] + and a + jp z, .sleepEffect + ld de, wBattleMonStatus + ld bc, wPlayerBattleStatus2 + +.sleepEffect + ld a, [bc] + bit NEEDS_TO_RECHARGE, a ; does the target need to recharge? (hyper beam) + res NEEDS_TO_RECHARGE, a ; target no longer needs to recharge + ld [bc], a + jr nz, .setSleepCounter ; if the target had to recharge, all hit tests will be skipped + ; including the event where the target already has another status + ld a, [de] + ld b, a + and $7 + jr z, .notAlreadySleeping ; can't affect a mon that is already asleep + ld hl, AlreadyAsleepText + jp PrintText +.notAlreadySleeping + ld a, b + and a + jr nz, .didntAffect ; can't affect a mon that is already statused + push de + call MoveHitTest ; apply accuracy tests + pop de + ld a, [wMoveMissed] + and a + jr nz, .didntAffect +.setSleepCounter +; set target's sleep counter to a random number between 1 and 7 + call BattleRandom + and $7 + jr z, .setSleepCounter + ld b, a + ld a, [wUnknownSerialFlag_d499] + and a + jr z, .asm_3f1ba ; XXX stadium stuff? + ld a, b + and $3 + jr z, .setSleepCounter + ld b, a +.asm_3f1ba + ld a, b + ld [de], a + call PlayCurrentMoveAnimation2 + ld hl, FellAsleepText + jp PrintText +.didntAffect + jp PrintDidntAffectText + +FellAsleepText: + text_far _FellAsleepText + text_end + +AlreadyAsleepText: + text_far _AlreadyAsleepText + text_end + +PoisonEffect: + ld hl, wEnemyMonStatus + ld de, wPlayerMoveEffect + ldh a, [hWhoseTurn] + and a + jr z, .poisonEffect + ld hl, wBattleMonStatus + ld de, wEnemyMoveEffect +.poisonEffect + call CheckTargetSubstitute + jr nz, .noEffect ; can't poison a substitute target + ld a, [hli] + ld b, a + and a + jr nz, .noEffect ; miss if target is already statused + ld a, [hli] + cp POISON ; can't poison a poison-type target + jr z, .noEffect + ld a, [hld] + cp POISON ; can't poison a poison-type target + jr z, .noEffect + ld a, [de] + cp POISON_SIDE_EFFECT1 + ld b, $34 ; ~20% chance of poisoning + jr z, .sideEffectTest + cp POISON_SIDE_EFFECT2 + ld b, $67 ; ~40% chance of poisoning + jr z, .sideEffectTest + push hl + push de + call MoveHitTest ; apply accuracy tests + pop de + pop hl + ld a, [wMoveMissed] + and a + jr nz, .didntAffect + jr .inflictPoison +.sideEffectTest + call BattleRandom + cp b ; was side effect successful? + ret nc +.inflictPoison + dec hl + set 3, [hl] ; mon is now poisoned + push de + dec de + ldh a, [hWhoseTurn] + and a + ld b, ANIM_C7 + ld hl, wPlayerBattleStatus3 + ld a, [de] + ld de, wPlayerToxicCounter + jr nz, .ok + ld b, ANIM_A9 + ld hl, wEnemyBattleStatus3 + ld de, wEnemyToxicCounter +.ok + cp TOXIC + jr nz, .normalPoison ; done if move is not Toxic + set BADLY_POISONED, [hl] ; else set Toxic battstatus + xor a + ld [de], a + ld hl, BadlyPoisonedText + jr .continue +.normalPoison + ld hl, PoisonedText +.continue + pop de + ld a, [de] + cp POISON_EFFECT + jr z, .regularPoisonEffect + ld a, b + call PlayBattleAnimation2 + jp PrintText +.regularPoisonEffect + call PlayCurrentMoveAnimation2 + jp PrintText +.noEffect + ld a, [de] + cp POISON_EFFECT + ret nz +.didntAffect + ld c, 50 + call DelayFrames + jp PrintDidntAffectText + +PoisonedText: + text_far _PoisonedText + text_end + +BadlyPoisonedText: + text_far _BadlyPoisonedText + text_end + +DrainHPEffect: + jpfar DrainHPEffect_ + +ExplodeEffect: + ld hl, wBattleMonHP + ld de, wPlayerBattleStatus2 + ldh a, [hWhoseTurn] + and a + jr z, .faintUser + ld hl, wEnemyMonHP + ld de, wEnemyBattleStatus2 +.faintUser + xor a + ld [hli], a ; set the mon's HP to 0 + ld [hli], a + inc hl + ld [hl], a ; set mon's status to 0 + ld a, [de] + res SEEDED, a ; clear mon's leech seed status + ld [de], a + ret + +FreezeBurnParalyzeEffect: + xor a + ld [wAnimationType], a + call CheckTargetSubstitute ; test bit 4 of d063/d068 flags [target has substitute flag] + ret nz ; return if they have a substitute, can't effect them + ldh a, [hWhoseTurn] + and a + jp nz, .opponentAttacker + ld a, [wEnemyMonStatus] + and a + jp nz, CheckDefrost ; can't inflict status if opponent is already statused + ld a, [wPlayerMoveType] + ld b, a + ld a, [wEnemyMonType1] + cp b ; do target type 1 and move type match? + ret z ; return if they match (an ice move can't freeze an ice-type, body slam can't paralyze a normal-type, etc.) + ld a, [wEnemyMonType2] + cp b ; do target type 2 and move type match? + ret z ; return if they match + ld a, [wPlayerMoveEffect] + cp UNUSED_EFFECT_23 ; more stadium stuff + jr nz, .asm_3f2c7 + ld a, [wUnknownSerialFlag_d499] + and a + ld a, FREEZE_SIDE_EFFECT + ld b, $4d ; else use 0x4D/0x100 or 77/256 = 30.1%~ chance + jr z, .next1 + ld b, $1a ; 0x1A/0x100 or 26/256 = 10.2%~ chance + jr .next1 +.asm_3f2c7 + cp a, PARALYZE_SIDE_EFFECT1 + 1 ; 10% status effects are 04, 05, 06 so 07 will set carry for those + ld b, $1a ; 0x1A/0x100 or 26/256 = 10.2%~ chance + jr c, .next1 ; branch ahead if this is a 10% chance effect.. + ld b, $4d ; else use 0x4D/0x100 or 77/256 = 30.1%~ chance + sub $1e ; subtract $1E to map to equivalent 10% chance effects +.next1 + push af + call BattleRandom ; get random 8bit value for probability test + cp b + pop bc + ret nc ; do nothing if random value is >= 1A or 4D [no status applied] + ld a, b ; what type of effect is this? + cp BURN_SIDE_EFFECT1 + jr z, .burn1 + cp FREEZE_SIDE_EFFECT + jr z, .freeze1 +; .paralyze + ld a, 1 << PAR + ld [wEnemyMonStatus], a + call QuarterSpeedDueToParalysis ; quarter speed of affected mon + ld a, ANIM_A9 + call PlayBattleAnimation + jp PrintMayNotAttackText ; print paralysis text +.burn1 + ld a, 1 << BRN + ld [wEnemyMonStatus], a + call HalveAttackDueToBurn ; halve attack of affected mon + ld a, ANIM_A9 + call PlayBattleAnimation + ld hl, BurnedText + jp PrintText +.freeze1 + call ClearHyperBeam ; resets hyper beam (recharge) condition from target + ld a, 1 << FRZ + ld [wEnemyMonStatus], a + ld a, ANIM_A9 + call PlayBattleAnimation + ld hl, FrozenText + jp PrintText +.opponentAttacker + ld a, [wBattleMonStatus] ; mostly same as above with addresses swapped for opponent + and a + jp nz, CheckDefrost + ld a, [wEnemyMoveType] + ld b, a + ld a, [wBattleMonType1] + cp b + ret z + ld a, [wBattleMonType2] + cp b + ret z + ld a, [wEnemyMoveEffect] + cp UNUSED_EFFECT_23 ; more stadium stuff + jr nz, .asm_3f341 + ld a, [wUnknownSerialFlag_d499] + and a + ld a, FREEZE_SIDE_EFFECT + ld b, $4d ; else use 0x4D/0x100 or 77/256 = 30.1%~ chance + jr z, .next2 + ld b, $1a ; 0x1A/0x100 or 26/256 = 10.2%~ chance + jr .next2 +.asm_3f341 + cp a, PARALYZE_SIDE_EFFECT1 + 1 + ld b, $1a + jr c, .next2 + ld b, $4d + sub $1e +.next2 + push af + call BattleRandom + cp b + pop bc + ret nc + ld a, b + cp BURN_SIDE_EFFECT1 + jr z, .burn2 + cp FREEZE_SIDE_EFFECT + jr z, .freeze2 + ld a, 1 << PAR + ld [wBattleMonStatus], a + call QuarterSpeedDueToParalysis + ld a, ANIM_C7 + call PlayBattleAnimation2 + jp PrintMayNotAttackText +.burn2 + ld a, 1 << BRN + ld [wBattleMonStatus], a + call HalveAttackDueToBurn + ld a, ANIM_C7 + call PlayBattleAnimation2 + ld hl, BurnedText + jp PrintText +.freeze2 +; hyper beam bits aren't reseted for opponent's side + ld a, 1 << FRZ + ld [wBattleMonStatus], a + ld a, ANIM_C7 + call PlayBattleAnimation2 + ld hl, FrozenText + jp PrintText + +BurnedText: + text_far _BurnedText + text_end + +FrozenText: + text_far _FrozenText + text_end + +CheckDefrost: +; any fire-type move that has a chance inflict burn (all but Fire Spin) will defrost a frozen target + and 1 << FRZ ; are they frozen? + ret z ; return if so + ldh a, [hWhoseTurn] + and a + jr nz, .opponent + ;player [attacker] + ld a, [wPlayerMoveType] + sub FIRE + ret nz ; return if type of move used isn't fire + ld [wEnemyMonStatus], a ; set opponent status to 00 ["defrost" a frozen monster] + ld hl, wEnemyMon1Status + ld a, [wEnemyMonPartyPos] + ld bc, wEnemyMon2 - wEnemyMon1 + call AddNTimes + xor a + ld [hl], a ; clear status in roster + ld hl, FireDefrostedText + jr .common +.opponent + ld a, [wEnemyMoveType] ; same as above with addresses swapped + sub FIRE + ret nz + ld [wBattleMonStatus], a + ld hl, wPartyMon1Status + ld a, [wPlayerMonNumber] + ld bc, wPartyMon2 - wPartyMon1 + call AddNTimes + xor a + ld [hl], a + ld hl, FireDefrostedText +.common + jp PrintText + +FireDefrostedText: + text_far _FireDefrostedText + text_end + +StatModifierUpEffect: + ld hl, wPlayerMonStatMods + ld de, wPlayerMoveEffect + ldh a, [hWhoseTurn] + and a + jr z, .statModifierUpEffect + ld hl, wEnemyMonStatMods + ld de, wEnemyMoveEffect +.statModifierUpEffect + ld a, [de] + sub ATTACK_UP1_EFFECT + cp EVASION_UP1_EFFECT + $3 - ATTACK_UP1_EFFECT ; covers all +1 effects + jr c, .incrementStatMod + sub ATTACK_UP2_EFFECT - ATTACK_UP1_EFFECT ; map +2 effects to equivalent +1 effect +.incrementStatMod + ld c, a + ld b, $0 + add hl, bc + ld b, [hl] + inc b ; increment corresponding stat mod + ld a, $d + cp b ; can't raise stat past +6 ($d or 13) + jp c, PrintNothingHappenedText + ld a, [de] + cp ATTACK_UP1_EFFECT + $8 ; is it a +2 effect? + jr c, .ok + inc b ; if so, increment stat mod again + ld a, $d + cp b ; unless it's already +6 + jr nc, .ok + ld b, a +.ok + ld [hl], b + ld a, c + cp $4 + jr nc, UpdateStatDone ; jump if mod affected is evasion/accuracy + push hl + ld hl, wBattleMonAttack + 1 + ld de, wPlayerMonUnmodifiedAttack + ldh a, [hWhoseTurn] + and a + jr z, .pointToStats + ld hl, wEnemyMonAttack + 1 + ld de, wEnemyMonUnmodifiedAttack +.pointToStats + push bc + sla c + ld b, $0 + add hl, bc ; hl = modified stat + ld a, c + add e + ld e, a + jr nc, .checkIf999 + inc d ; de = unmodified (original) stat +.checkIf999 + pop bc + ; check if stat is already 999 + ld a, [hld] + sub LOW(MAX_STAT_VALUE) + jr nz, .recalculateStat + ld a, [hl] + sbc HIGH(MAX_STAT_VALUE) + jp z, RestoreOriginalStatModifier +.recalculateStat ; recalculate affected stat + ; paralysis and burn penalties, as well as badge boosts are ignored + push hl + push bc + ld hl, StatModifierRatios + dec b + sla b + ld c, b + ld b, $0 + add hl, bc + pop bc + xor a + ldh [hMultiplicand], a + ld a, [de] + ldh [hMultiplicand + 1], a + inc de + ld a, [de] + ldh [hMultiplicand + 2], a + ld a, [hli] + ldh [hMultiplier], a + call Multiply + ld a, [hl] + ldh [hDivisor], a + ld b, $4 + call Divide + pop hl +; cap at MAX_STAT_VALUE (999) + ldh a, [hProduct + 3] + sub LOW(MAX_STAT_VALUE) + ldh a, [hProduct + 2] + sbc HIGH(MAX_STAT_VALUE) + jp c, UpdateStat + ld a, HIGH(MAX_STAT_VALUE) + ldh [hMultiplicand + 1], a + ld a, LOW(MAX_STAT_VALUE) + ldh [hMultiplicand + 2], a + +UpdateStat: + ldh a, [hProduct + 2] + ld [hli], a + ldh a, [hProduct + 3] + ld [hl], a + pop hl +UpdateStatDone: + ld b, c + inc b + call PrintStatText + ld hl, wPlayerBattleStatus2 + ld de, wPlayerMoveNum + ld bc, wPlayerMonMinimized + ldh a, [hWhoseTurn] + and a + jr z, .playerTurn + ld hl, wEnemyBattleStatus2 + ld de, wEnemyMoveNum + ld bc, wEnemyMonMinimized +.playerTurn + ld a, [de] + cp MINIMIZE + jr nz, .notMinimize + ; if a substitute is up, slide off the substitute and show the mon pic before + ; playing the minimize animation + bit HAS_SUBSTITUTE_UP, [hl] + push af + push bc + push de + ld hl, HideSubstituteShowMonAnim + ld b, BANK(HideSubstituteShowMonAnim) + call nz, Bankswitch + pop de +.notMinimize + call PlayCurrentMoveAnimation + ld a, [de] + cp MINIMIZE + jr nz, .applyBadgeBoostsAndStatusPenalties + pop bc + ld a, $1 + ld [bc], a + ld hl, ReshowSubstituteAnim + ld b, BANK(ReshowSubstituteAnim) + pop af + call nz, Bankswitch +.applyBadgeBoostsAndStatusPenalties + ldh a, [hWhoseTurn] + and a + call z, ApplyBadgeStatBoosts ; whenever the player uses a stat-up move, badge boosts get reapplied again to every stat, + ; even to those not affected by the stat-up move (will be boosted further) + ld hl, MonsStatsRoseText + call PrintText + +; these shouldn't be here + call QuarterSpeedDueToParalysis ; apply speed penalty to the player whose turn is not, if it's paralyzed + jp HalveAttackDueToBurn ; apply attack penalty to the player whose turn is not, if it's burned + +RestoreOriginalStatModifier: + pop hl + dec [hl] + +PrintNothingHappenedText: + ld hl, NothingHappenedText + jp PrintText + +MonsStatsRoseText: + text_far _MonsStatsRoseText + text_asm + ld hl, GreatlyRoseText + ldh a, [hWhoseTurn] + and a + ld a, [wPlayerMoveEffect] + jr z, .playerTurn + ld a, [wEnemyMoveEffect] +.playerTurn + cp ATTACK_DOWN1_EFFECT + ret nc + ld hl, RoseText + ret + +GreatlyRoseText: + text_pause + text_far _GreatlyRoseText +; fallthrough +RoseText: + text_far _RoseText + text_end + +StatModifierDownEffect: + ld hl, wEnemyMonStatMods + ld de, wPlayerMoveEffect + ld bc, wEnemyBattleStatus1 + ldh a, [hWhoseTurn] + and a + jr z, .statModifierDownEffect + ld hl, wPlayerMonStatMods + ld de, wEnemyMoveEffect + ld bc, wPlayerBattleStatus1 + ld a, [wLinkState] + cp LINK_STATE_BATTLING + jr z, .statModifierDownEffect + call BattleRandom + cp $40 ; 1/4 chance to miss by in regular battle + jp c, MoveMissed +.statModifierDownEffect + call CheckTargetSubstitute ; can't hit through substitute + jp nz, MoveMissed + ld a, [de] + cp ATTACK_DOWN_SIDE_EFFECT + jr c, .nonSideEffect + call BattleRandom + cp $55 ; 85/256 chance for side effects + jp nc, CantLowerAnymore + ld a, [de] + sub ATTACK_DOWN_SIDE_EFFECT ; map each stat to 0-3 + jr .decrementStatMod +.nonSideEffect ; non-side effects only + push hl + push de + push bc + call MoveHitTest ; apply accuracy tests + pop bc + pop de + pop hl + ld a, [wMoveMissed] + and a + jp nz, MoveMissed + ld a, [bc] + bit INVULNERABLE, a ; fly/dig + jp nz, MoveMissed + ld a, [de] + sub ATTACK_DOWN1_EFFECT + cp EVASION_DOWN1_EFFECT + $3 - ATTACK_DOWN1_EFFECT ; covers all -1 effects + jr c, .decrementStatMod + sub ATTACK_DOWN2_EFFECT - ATTACK_DOWN1_EFFECT ; map -2 effects to corresponding -1 effect +.decrementStatMod + ld c, a + ld b, $0 + add hl, bc + ld b, [hl] + dec b ; dec corresponding stat mod + jp z, CantLowerAnymore ; if stat mod is 1 (-6), can't lower anymore + ld a, [de] + cp ATTACK_DOWN2_EFFECT - $16 ; $24 + jr c, .ok + cp EVASION_DOWN2_EFFECT + $5 ; $44 + jr nc, .ok + dec b ; stat down 2 effects only (dec mod again) + jr nz, .ok + inc b ; increment mod to 1 (-6) if it would become 0 (-7) +.ok + ld [hl], b ; save modified mod + ld a, c + cp $4 + jr nc, UpdateLoweredStatDone ; jump for evasion/accuracy + push hl + push de + ld hl, wEnemyMonAttack + 1 + ld de, wEnemyMonUnmodifiedAttack + ldh a, [hWhoseTurn] + and a + jr z, .pointToStat + ld hl, wBattleMonAttack + 1 + ld de, wPlayerMonUnmodifiedAttack +.pointToStat + push bc + sla c + ld b, $0 + add hl, bc ; hl = modified stat + ld a, c + add e + ld e, a + jr nc, .noCarry + inc d ; de = unmodified stat +.noCarry + pop bc + ld a, [hld] + sub $1 ; can't lower stat below 1 (-6) + jr nz, .recalculateStat + ld a, [hl] + and a + jp z, CantLowerAnymore_Pop +.recalculateStat +; recalculate affected stat +; paralysis and burn penalties, as well as badge boosts are ignored + push hl + push bc + ld hl, StatModifierRatios + dec b + sla b + ld c, b + ld b, $0 + add hl, bc + pop bc + xor a + ldh [hMultiplicand], a + ld a, [de] + ldh [hMultiplicand + 1], a + inc de + ld a, [de] + ldh [hMultiplicand + 2], a + ld a, [hli] + ldh [hMultiplier], a + call Multiply + ld a, [hl] + ldh [hDivisor], a + ld b, $4 + call Divide + pop hl + ldh a, [hProduct + 3] + ld b, a + ldh a, [hProduct + 2] + or b + jp nz, UpdateLoweredStat + ldh [hMultiplicand + 1], a + ld a, $1 + ldh [hMultiplicand + 2], a + +UpdateLoweredStat: + ldh a, [hProduct + 2] + ld [hli], a + ldh a, [hProduct + 3] + ld [hl], a + pop de + pop hl +UpdateLoweredStatDone: + ld b, c + inc b + push de + call PrintStatText + pop de + ld a, [de] + cp $44 + jr nc, .ApplyBadgeBoostsAndStatusPenalties + call PlayCurrentMoveAnimation2 +.ApplyBadgeBoostsAndStatusPenalties + ldh a, [hWhoseTurn] + and a + call nz, ApplyBadgeStatBoosts ; whenever the player uses a stat-down move, badge boosts get reapplied again to every stat, + ; even to those not affected by the stat-up move (will be boosted further) + ld hl, MonsStatsFellText + call PrintText + +; These where probably added given that a stat-down move affecting speed or attack will override +; the stat penalties from paralysis and burn respectively. +; But they are always called regardless of the stat affected by the stat-down move. + call QuarterSpeedDueToParalysis + jp HalveAttackDueToBurn + +CantLowerAnymore_Pop: + pop de + pop hl + inc [hl] + +CantLowerAnymore: + ld a, [de] + cp ATTACK_DOWN_SIDE_EFFECT + ret nc + ld hl, NothingHappenedText + jp PrintText + +MoveMissed: + ld a, [de] + cp $44 + ret nc + jp ConditionalPrintButItFailed + +MonsStatsFellText: + text_far _MonsStatsFellText + text_asm + ld hl, FellText + ldh a, [hWhoseTurn] + and a + ld a, [wPlayerMoveEffect] + jr z, .playerTurn + ld a, [wEnemyMoveEffect] +.playerTurn +; check if the move's effect decreases a stat by 2 + cp BIDE_EFFECT + ret c + cp ATTACK_DOWN_SIDE_EFFECT + ret nc + ld hl, GreatlyFellText + ret + +GreatlyFellText: + text_pause + text_far _GreatlyFellText +; fallthrough +FellText: + text_far _FellText + text_end + +PrintStatText: + ld hl, StatsTextStrings + ld c, "@" +.findStatName_outer + dec b + jr z, .foundStatName +.findStatName_inner + ld a, [hli] + cp c + jr z, .findStatName_outer + jr .findStatName_inner +.foundStatName + ld de, wcf4b + ld bc, $a + jp CopyData + +INCLUDE "data/battle/stat_names.asm" + +INCLUDE "data/battle/stat_modifiers.asm" + +BideEffect: + ld hl, wPlayerBattleStatus1 + ld de, wPlayerBideAccumulatedDamage + ld bc, wPlayerNumAttacksLeft + ldh a, [hWhoseTurn] + and a + jr z, .bideEffect + ld hl, wEnemyBattleStatus1 + ld de, wEnemyBideAccumulatedDamage + ld bc, wEnemyNumAttacksLeft +.bideEffect + set STORING_ENERGY, [hl] ; mon is now using bide + xor a + ld [de], a + inc de + ld [de], a + ld [wPlayerMoveEffect], a + ld [wEnemyMoveEffect], a + call BattleRandom + and $1 + inc a + inc a + ld [bc], a ; set Bide counter to 2 or 3 at random + ldh a, [hWhoseTurn] + add XSTATITEM_ANIM + jp PlayBattleAnimation2 + +ThrashPetalDanceEffect: + ld hl, wPlayerBattleStatus1 + ld de, wPlayerNumAttacksLeft + ldh a, [hWhoseTurn] + and a + jr z, .thrashPetalDanceEffect + ld hl, wEnemyBattleStatus1 + ld de, wEnemyNumAttacksLeft +.thrashPetalDanceEffect + set THRASHING_ABOUT, [hl] ; mon is now using thrash/petal dance + call BattleRandom + and $1 + inc a + inc a + ld [de], a ; set thrash/petal dance counter to 2 or 3 at random + ldh a, [hWhoseTurn] + add ANIM_B0 + jp PlayBattleAnimation2 + +SwitchAndTeleportEffect: + ldh a, [hWhoseTurn] + and a + jr nz, .handleEnemy + ld a, [wIsInBattle] + dec a + jr nz, .notWildBattle1 + ld a, [wCurEnemyLVL] + ld b, a + ld a, [wBattleMonLevel] + cp b ; is the player's level greater than the enemy's level? + jr nc, .playerMoveWasSuccessful ; if so, teleport will always succeed + add b + ld c, a + inc c ; c = sum of player level and enemy level +.rejectionSampleLoop1 + call BattleRandom + cp c ; get a random number between 0 and c + jr nc, .rejectionSampleLoop1 + srl b + srl b ; b = enemyLevel / 4 + cp b ; is rand[0, playerLevel + enemyLevel) >= (enemyLevel / 4)? + jr nc, .playerMoveWasSuccessful ; if so, allow teleporting + ld c, 50 + call DelayFrames + ld a, [wPlayerMoveNum] + cp TELEPORT + jp nz, PrintDidntAffectText + jp PrintButItFailedText_ +.playerMoveWasSuccessful + call ReadPlayerMonCurHPAndStatus + xor a + ld [wAnimationType], a + inc a + ld [wEscapedFromBattle], a + ld a, [wPlayerMoveNum] + jr .playAnimAndPrintText +.notWildBattle1 + ld c, 50 + call DelayFrames + ld hl, IsUnaffectedText + ld a, [wPlayerMoveNum] + cp TELEPORT + jp nz, PrintText + jp PrintButItFailedText_ +.handleEnemy + ld a, [wIsInBattle] + dec a + jr nz, .notWildBattle2 + ld a, [wBattleMonLevel] + ld b, a + ld a, [wCurEnemyLVL] + cp b + jr nc, .enemyMoveWasSuccessful + add b + ld c, a + inc c +.rejectionSampleLoop2 + call BattleRandom + cp c + jr nc, .rejectionSampleLoop2 + srl b + srl b + cp b + jr nc, .enemyMoveWasSuccessful + ld c, 50 + call DelayFrames + ld a, [wEnemyMoveNum] + cp TELEPORT + jp nz, PrintDidntAffectText + jp PrintButItFailedText_ +.enemyMoveWasSuccessful + call ReadPlayerMonCurHPAndStatus + xor a + ld [wAnimationType], a + inc a + ld [wEscapedFromBattle], a + ld a, [wEnemyMoveNum] + jr .playAnimAndPrintText +.notWildBattle2 + ld c, 50 + call DelayFrames + ld hl, IsUnaffectedText + ld a, [wEnemyMoveNum] + cp TELEPORT + jp nz, PrintText + jp ConditionalPrintButItFailed +.playAnimAndPrintText + push af + call PlayBattleAnimation + ld c, 20 + call DelayFrames + pop af + ld hl, RanFromBattleText + cp TELEPORT + jr z, .printText + ld hl, RanAwayScaredText + cp ROAR + jr z, .printText + ld hl, WasBlownAwayText +.printText + jp PrintText + +RanFromBattleText: + text_far _RanFromBattleText + text_end + +RanAwayScaredText: + text_far _RanAwayScaredText + text_end + +WasBlownAwayText: + text_far _WasBlownAwayText + text_end + +TwoToFiveAttacksEffect: + ld hl, wPlayerBattleStatus1 + ld de, wPlayerNumAttacksLeft + ld bc, wPlayerNumHits + ldh a, [hWhoseTurn] + and a + jr z, .twoToFiveAttacksEffect + ld hl, wEnemyBattleStatus1 + ld de, wEnemyNumAttacksLeft + ld bc, wEnemyNumHits +.twoToFiveAttacksEffect + bit ATTACKING_MULTIPLE_TIMES, [hl] ; is mon attacking multiple times? + ret nz + set ATTACKING_MULTIPLE_TIMES, [hl] ; mon is now attacking multiple times + ld hl, wPlayerMoveEffect + ldh a, [hWhoseTurn] + and a + jr z, .setNumberOfHits + ld hl, wEnemyMoveEffect +.setNumberOfHits + ld a, [hl] + cp TWINEEDLE_EFFECT + jr z, .twineedle + cp ATTACK_TWICE_EFFECT + ld a, $2 ; number of hits it's always 2 for ATTACK_TWICE_EFFECT + jr z, .saveNumberOfHits +; for TWO_TO_FIVE_ATTACKS_EFFECT 3/8 chance for 2 and 3 hits, and 1/8 chance for 4 and 5 hits + call BattleRandom + and $3 + cp $2 + jr c, .gotNumHits +; if the number of hits was greater than 2, re-roll again for a lower chance + call BattleRandom + and $3 +.gotNumHits + inc a + inc a +.saveNumberOfHits + ld [de], a + ld [bc], a + ret +.twineedle + ld a, POISON_SIDE_EFFECT1 + ld [hl], a ; set Twineedle's effect to poison effect + jr .saveNumberOfHits + +FlinchSideEffect: + call CheckTargetSubstitute + ret nz + ld hl, wEnemyBattleStatus1 + ld de, wPlayerMoveEffect + ldh a, [hWhoseTurn] + and a + jr z, .flinchSideEffect + ld hl, wPlayerBattleStatus1 + ld de, wEnemyMoveEffect +.flinchSideEffect + ld a, [wLinkState] + cp LINK_STATE_BATTLING + call z, ClearHyperBeam + ld a, [de] + cp FLINCH_SIDE_EFFECT1 + ld b, $1a ; ~10% chance of flinch + jr z, .gotEffectChance + ld b, $4d ; ~30% chance of flinch +.gotEffectChance + call BattleRandom + cp b + ret nc + set FLINCHED, [hl] ; set mon's status to flinching + call ClearHyperBeam + ret + +OneHitKOEffect: + jpfar OneHitKOEffect_ + +ChargeEffect: + ld hl, wPlayerBattleStatus1 + ld de, wPlayerMoveEffect + ldh a, [hWhoseTurn] + and a + ld b, XSTATITEM_ANIM + jr z, .chargeEffect + ld hl, wEnemyBattleStatus1 + ld de, wEnemyMoveEffect + ld b, ANIM_AF +.chargeEffect + set CHARGING_UP, [hl] + ld a, [de] + dec de ; de contains enemy or player MOVENUM + cp FLY_EFFECT + jr nz, .notFly + set INVULNERABLE, [hl] ; mon is now invulnerable to typical attacks (fly/dig) + ld b, TELEPORT ; load Teleport's animation +.notFly + ld a, [de] + cp DIG + jr nz, .notDigOrFly + set INVULNERABLE, [hl] ; mon is now invulnerable to typical attacks (fly/dig) + ld b, ANIM_C0 +.notDigOrFly + push de + push bc + inc hl ; battle status 2 + push hl + ld a, [hl] + bit HAS_SUBSTITUTE_UP, a + ld hl, HideSubstituteShowMonAnim + ld b, BANK(HideSubstituteShowMonAnim) + call nz, Bankswitch + pop hl + pop bc + xor a + ld [wAnimationType], a + ld a, b + call PlayBattleAnimation + ld a, [hl] + bit HAS_SUBSTITUTE_UP, a + ld hl, ReshowSubstituteAnim + ld b, BANK(ReshowSubstituteAnim) + call nz, Bankswitch + pop de + ld a, [de] + ld [wChargeMoveNum], a + ld hl, ChargeMoveEffectText + jp PrintText + +ChargeMoveEffectText: + text_far _ChargeMoveEffectText + text_asm + ld a, [wChargeMoveNum] + cp RAZOR_WIND + ld hl, MadeWhirlwindText + jr z, .gotText + cp SOLARBEAM + ld hl, TookInSunlightText + jr z, .gotText + cp SKULL_BASH + ld hl, LoweredItsHeadText + jr z, .gotText + cp SKY_ATTACK + ld hl, SkyAttackGlowingText + jr z, .gotText + cp FLY + ld hl, FlewUpHighText + jr z, .gotText + cp DIG + ld hl, DugAHoleText +.gotText + ret + +MadeWhirlwindText: + text_far _MadeWhirlwindText + text_end + +TookInSunlightText: + text_far _TookInSunlightText + text_end + +LoweredItsHeadText: + text_far _LoweredItsHeadText + text_end + +SkyAttackGlowingText: + text_far _SkyAttackGlowingText + text_end + +FlewUpHighText: + text_far _FlewUpHighText + text_end + +DugAHoleText: + text_far _DugAHoleText + text_end + +TrappingEffect: + ld hl, wPlayerBattleStatus1 + ld de, wPlayerNumAttacksLeft + ldh a, [hWhoseTurn] + and a + jr z, .trappingEffect + ld hl, wEnemyBattleStatus1 + ld de, wEnemyNumAttacksLeft +.trappingEffect + bit USING_TRAPPING_MOVE, [hl] + ret nz + call ClearHyperBeam ; since this effect is called before testing whether the move will hit, + ; the target won't need to recharge even if the trapping move missed + set USING_TRAPPING_MOVE, [hl] ; mon is now using a trapping move + call BattleRandom ; 3/8 chance for 2 and 3 attacks, and 1/8 chance for 4 and 5 attacks + and $3 + cp $2 + jr c, .setTrappingCounter + call BattleRandom + and $3 +.setTrappingCounter + inc a + ld [de], a + ret + +MistEffect: + jpfar MistEffect_ + +FocusEnergyEffect: + jpfar FocusEnergyEffect_ + +RecoilEffect: + jpfar RecoilEffect_ + +ConfusionSideEffect: + call BattleRandom + cp $19 ; ~10% chance + ret nc + jr ConfusionSideEffectSuccess + +ConfusionEffect: + call CheckTargetSubstitute + jr nz, ConfusionEffectFailed + call MoveHitTest + ld a, [wMoveMissed] + and a + jr nz, ConfusionEffectFailed + +ConfusionSideEffectSuccess: + ldh a, [hWhoseTurn] + and a + ld hl, wEnemyBattleStatus1 + ld bc, wEnemyConfusedCounter + ld a, [wPlayerMoveEffect] + jr z, .confuseTarget + ld hl, wPlayerBattleStatus1 + ld bc, wPlayerConfusedCounter + ld a, [wEnemyMoveEffect] +.confuseTarget + bit CONFUSED, [hl] ; is mon confused? + jr nz, ConfusionEffectFailed + set CONFUSED, [hl] ; mon is now confused + push af + call BattleRandom + and $3 + inc a + inc a + ld [bc], a ; confusion status will last 2-5 turns + pop af + cp CONFUSION_SIDE_EFFECT + call nz, PlayCurrentMoveAnimation2 + ld hl, BecameConfusedText + jp PrintText + +BecameConfusedText: + text_far _BecameConfusedText + text_end + +ConfusionEffectFailed: + cp CONFUSION_SIDE_EFFECT + ret z + ld c, 50 + call DelayFrames + jp ConditionalPrintButItFailed + +ParalyzeEffect: + jpfar ParalyzeEffect_ + +SubstituteEffect: + jpfar SubstituteEffect_ + +HyperBeamEffect: + ld hl, wPlayerBattleStatus2 + ldh a, [hWhoseTurn] + and a + jr z, .hyperBeamEffect + ld hl, wEnemyBattleStatus2 +.hyperBeamEffect + set NEEDS_TO_RECHARGE, [hl] ; mon now needs to recharge + ret + +ClearHyperBeam: + push hl + ld hl, wEnemyBattleStatus2 + ldh a, [hWhoseTurn] + and a + jr z, .playerTurn + ld hl, wPlayerBattleStatus2 +.playerTurn + res NEEDS_TO_RECHARGE, [hl] ; mon no longer needs to recharge + pop hl + ret + +RageEffect: + ld hl, wPlayerBattleStatus2 + ldh a, [hWhoseTurn] + and a + jr z, .player + ld hl, wEnemyBattleStatus2 +.player + set USING_RAGE, [hl] ; mon is now in "rage" mode + ret + +MimicEffect: + ld c, 50 + call DelayFrames + call MoveHitTest + ld a, [wMoveMissed] + and a + jr nz, .mimicMissed + ldh a, [hWhoseTurn] + and a + ld hl, wBattleMonMoves + ld a, [wPlayerBattleStatus1] + jr nz, .enemyTurn + ld a, [wLinkState] + cp LINK_STATE_BATTLING + jr nz, .letPlayerChooseMove + ld hl, wEnemyMonMoves + ld a, [wEnemyBattleStatus1] +.enemyTurn + bit INVULNERABLE, a + jr nz, .mimicMissed +.getRandomMove + push hl + call BattleRandom + and $3 + ld c, a + ld b, $0 + add hl, bc + ld a, [hl] + pop hl + and a + jr z, .getRandomMove + ld d, a + ldh a, [hWhoseTurn] + and a + ld hl, wBattleMonMoves + ld a, [wPlayerMoveListIndex] + jr z, .playerTurn + ld hl, wEnemyMonMoves + ld a, [wEnemyMoveListIndex] + jr .playerTurn +.letPlayerChooseMove + ld a, [wEnemyBattleStatus1] + bit INVULNERABLE, a + jr nz, .mimicMissed + ld a, [wCurrentMenuItem] + push af + ld a, $1 + ld [wMoveMenuType], a + call MoveSelectionMenu + call LoadScreenTilesFromBuffer1 + ld hl, wEnemyMonMoves + ld a, [wCurrentMenuItem] + ld c, a + ld b, $0 + add hl, bc + ld d, [hl] + pop af + ld hl, wBattleMonMoves +.playerTurn + ld c, a + ld b, $0 + add hl, bc + ld a, d + ld [hl], a + ld [wd11e], a + call GetMoveName + call PlayCurrentMoveAnimation + ld hl, MimicLearnedMoveText + jp PrintText +.mimicMissed + jp PrintButItFailedText_ + +MimicLearnedMoveText: + text_far _MimicLearnedMoveText + text_end + +LeechSeedEffect: + jpfar LeechSeedEffect_ + +SplashEffect: + call PlayCurrentMoveAnimation + jp PrintNoEffectText + +DisableEffect: + call MoveHitTest + ld a, [wMoveMissed] + and a + jr nz, .moveMissed + ld de, wEnemyDisabledMove + ld hl, wEnemyMonMoves + ldh a, [hWhoseTurn] + and a + jr z, .disableEffect + ld de, wPlayerDisabledMove + ld hl, wBattleMonMoves +.disableEffect +; no effect if target already has a move disabled + ld a, [de] + and a + jr nz, .moveMissed +.pickMoveToDisable + push hl + call BattleRandom + and $3 + ld c, a + ld b, $0 + add hl, bc + ld a, [hl] + pop hl + and a + jr z, .pickMoveToDisable ; loop until a non-00 move slot is found + ld [wd11e], a ; store move number + push hl + ldh a, [hWhoseTurn] + and a + ld hl, wBattleMonPP + jr nz, .enemyTurn + ld a, [wLinkState] + cp LINK_STATE_BATTLING + pop hl ; wEnemyMonMoves + jr nz, .playerTurnNotLinkBattle +; .playerTurnLinkBattle + push hl + ld hl, wEnemyMonPP +.enemyTurn + push hl + ld a, [hli] + or [hl] + inc hl + or [hl] + inc hl + or [hl] + and $3f + pop hl ; wBattleMonPP or wEnemyMonPP + jr z, .moveMissedPopHL ; nothing to do if all moves have no PP left + add hl, bc + ld a, [hl] + pop hl + and a + jr z, .pickMoveToDisable ; pick another move if this one had 0 PP +.playerTurnNotLinkBattle +; non-link battle enemies have unlimited PP so the previous checks aren't needed + call BattleRandom + and $7 + inc a ; 1-8 turns disabled + inc c ; move 1-4 will be disabled + swap c + add c ; map disabled move to high nibble of wEnemyDisabledMove / wPlayerDisabledMove + ld [de], a + call PlayCurrentMoveAnimation2 + ld hl, wPlayerDisabledMoveNumber + ldh a, [hWhoseTurn] + and a + jr nz, .printDisableText + inc hl ; wEnemyDisabledMoveNumber +.printDisableText + ld a, [wd11e] ; move number + ld [hl], a + call GetMoveName + ld hl, MoveWasDisabledText + jp PrintText +.moveMissedPopHL + pop hl +.moveMissed + jp PrintButItFailedText_ + +MoveWasDisabledText: + text_far _MoveWasDisabledText + text_end + +PayDayEffect: + jpfar PayDayEffect_ + +ConversionEffect: + jpfar ConversionEffect_ + +HazeEffect: + jpfar HazeEffect_ + +HealEffect: + jpfar HealEffect_ + +TransformEffect: + jpfar TransformEffect_ + +ReflectLightScreenEffect: + jpfar ReflectLightScreenEffect_ + +NothingHappenedText: + text_far _NothingHappenedText + text_end + +PrintNoEffectText: + ld hl, NoEffectText + jp PrintText + +NoEffectText: + text_far _NoEffectText + text_end + +ConditionalPrintButItFailed: + ld a, [wMoveDidntMiss] + and a + ret nz ; return if the side effect failed, yet the attack was successful + +PrintButItFailedText_: + ld hl, ButItFailedText + jp PrintText + +ButItFailedText: + text_far _ButItFailedText + text_end + +PrintDidntAffectText: + ld hl, DidntAffectText + jp PrintText + +DidntAffectText: + text_far _DidntAffectText + text_end + +IsUnaffectedText: + text_far _IsUnaffectedText + text_end + +PrintMayNotAttackText: + ld hl, ParalyzedMayNotAttackText + jp PrintText + +ParalyzedMayNotAttackText: + text_far _ParalyzedMayNotAttackText + text_end + +CheckTargetSubstitute: + push hl + ld hl, wEnemyBattleStatus2 + ldh a, [hWhoseTurn] + and a + jr z, .next1 + ld hl, wPlayerBattleStatus2 +.next1 + bit HAS_SUBSTITUTE_UP, [hl] + pop hl + ret + +PlayCurrentMoveAnimation2: +; animation at MOVENUM will be played unless MOVENUM is 0 +; plays wAnimationType 3 or 6 + ldh a, [hWhoseTurn] + and a + ld a, [wPlayerMoveNum] + jr z, .notEnemyTurn + ld a, [wEnemyMoveNum] +.notEnemyTurn + and a + ret z + +PlayBattleAnimation2: +; play animation ID at a and animation type 6 or 3 + ld [wAnimationID], a + ldh a, [hWhoseTurn] + and a + ld a, $6 + jr z, .storeAnimationType + ld a, $3 +.storeAnimationType + ld [wAnimationType], a + jp PlayBattleAnimationGotID + +PlayCurrentMoveAnimation: +; animation at MOVENUM will be played unless MOVENUM is 0 +; resets wAnimationType + xor a + ld [wAnimationType], a + ldh a, [hWhoseTurn] + and a + ld a, [wPlayerMoveNum] + jr z, .notEnemyTurn + ld a, [wEnemyMoveNum] +.notEnemyTurn + and a + ret z + +PlayBattleAnimation: +; play animation ID at a and predefined animation type + ld [wAnimationID], a + +PlayBattleAnimationGotID: +; play animation at wAnimationID + push hl + push de + push bc + predef MoveAnimation + callfar Func_78e98 + pop bc + pop de + pop hl + ret diff --git a/engine/battle/end_of_battle.asm b/engine/battle/end_of_battle.asm index 5c0c3991..e64f54e7 100755 --- a/engine/battle/end_of_battle.asm +++ b/engine/battle/end_of_battle.asm @@ -12,7 +12,7 @@ EndOfBattle: call ClearScreen ld b, SET_PAL_OVERWORLD call RunPaletteCommand - callab DisplayLinkBattleVersusTextBox + callfar DisplayLinkBattleVersusTextBox ld a, [wBattleResult] cp $1 ld de, YouWinText @@ -21,7 +21,7 @@ EndOfBattle: jr z, .placeWinOrLoseString ld de, DrawText .placeWinOrLoseString - coord hl, 6, 8 + hlcoord 6, 8 call PlaceString ld c, 200 call DelayFrames @@ -46,7 +46,7 @@ EndOfBattle: ld [wForceEvolution], a predef EvolutionAfterBattle ld d, $82 - callab UpdatePikachuMoodAfterBattle + callfar UpdatePikachuMoodAfterBattle .resetVariables xor a ld [wLowHealthAlarm], a ;disable low health alarm @@ -88,5 +88,5 @@ DrawText: db " DRAW@" PickUpPayDayMoneyText: - TX_FAR _PickUpPayDayMoneyText - db "@" + text_far _PickUpPayDayMoneyText + text_end diff --git a/engine/battle/experience.asm b/engine/battle/experience.asm index 722685c2..bab804bb 100644 --- a/engine/battle/experience.asm +++ b/engine/battle/experience.asm @@ -55,15 +55,15 @@ GainExperience: jr .gainStatExpLoop .statExpDone xor a - ld [H_MULTIPLICAND], a - ld [H_MULTIPLICAND + 1], a + ldh [hMultiplicand], a + ldh [hMultiplicand + 1], a ld a, [wEnemyMonBaseExp] - ld [H_MULTIPLICAND + 2], a + ldh [hMultiplicand + 2], a ld a, [wEnemyMonLevel] - ld [H_MULTIPLIER], a + ldh [hMultiplier], a call Multiply ld a, 7 - ld [H_DIVISOR], a + ldh [hDivisor], a ld b, 4 call Divide ld hl, wPartyMon1OTID - (wPartyMon1DVs - 1) @@ -91,12 +91,12 @@ GainExperience: inc hl ; add the gained exp to the party mon's exp ld b, [hl] - ld a, [H_QUOTIENT + 3] + ldh a, [hQuotient + 3] ld [wExpAmountGained + 1], a add b ld [hld], a ld b, [hl] - ld a, [H_QUOTIENT + 2] + ldh a, [hQuotient + 2] ld [wExpAmountGained], a adc b ld [hl], a @@ -117,13 +117,13 @@ GainExperience: ld [wd0b5], a call GetMonHeader ld d, MAX_LEVEL - callab CalcExperience ; get max exp + callfar CalcExperience ; get max exp ; compare max exp with current exp - ld a, [hExperience] + ldh a, [hExperience] ld b, a - ld a, [hExperience + 1] + ldh a, [hExperience + 1] ld c, a - ld a, [hExperience + 2] + ldh a, [hExperience + 2] ld d, a pop hl ld a, [hld] @@ -155,7 +155,7 @@ GainExperience: ld bc, wPartyMon1Level - wPartyMon1Exp add hl, bc push hl - callba CalcLevelFromExperience + farcall CalcLevelFromExperience pop hl ld a, [hl] ; current level cp d @@ -252,7 +252,7 @@ GainExperience: ld [wMonDataLocation], a call LoadMonData ld d, $1 - callab PrintStatsBox + callfar PrintStatsBox call WaitForTextScrollButtonPress call LoadScreenTilesFromBuffer1 xor a ; PLAYER_PARTY_DATA @@ -317,14 +317,14 @@ DivideExpDataByNumMonsGainingExp: ld c, wEnemyMonBaseExp + 1 - wEnemyMonBaseStats .divideLoop xor a - ld [H_DIVIDEND], a + ldh [hDividend], a ld a, [hl] - ld [H_DIVIDEND + 1], a + ldh [hDividend + 1], a ld a, [wd11e] - ld [H_DIVISOR], a + ldh [hDivisor], a ld b, $2 call Divide ; divide value by number of mons gaining exp - ld a, [H_QUOTIENT + 3] + ldh a, [hQuotient + 3] ld [hli], a dec c jr nz, .divideLoop @@ -332,17 +332,17 @@ DivideExpDataByNumMonsGainingExp: ; multiplies exp by 1.5 BoostExp: - ld a, [H_QUOTIENT + 2] + ldh a, [hQuotient + 2] ld b, a - ld a, [H_QUOTIENT + 3] + ldh a, [hQuotient + 3] ld c, a srl b rr c add c - ld [H_QUOTIENT + 3], a - ld a, [H_QUOTIENT + 2] + ldh [hQuotient + 3], a + ldh a, [hQuotient + 2] adc b - ld [H_QUOTIENT + 2], a + ldh [hQuotient + 2], a ret Bankswitch15ToF: @@ -350,8 +350,8 @@ Bankswitch15ToF: jp Bankswitch GainedText: - TX_FAR _GainedText - TX_ASM + text_far _GainedText + text_asm ld a, [wBoostExpByExpAll] ld hl, WithExpAllText and a @@ -364,19 +364,19 @@ GainedText: ret WithExpAllText: - TX_FAR _WithExpAllText - TX_ASM + text_far _WithExpAllText + text_asm ld hl, ExpPointsText ret BoostedText: - TX_FAR _BoostedText + text_far _BoostedText ExpPointsText: - TX_FAR _ExpPointsText - db "@" + text_far _ExpPointsText + text_end GrewLevelText: - TX_FAR _GrewLevelText - TX_SFX_LEVEL_UP - db "@" + text_far _GrewLevelText + sound_level_up + text_end diff --git a/engine/battle/get_trainer_name.asm b/engine/battle/get_trainer_name.asm index 36ca019e..b2daebfe 100644 --- a/engine/battle/get_trainer_name.asm +++ b/engine/battle/get_trainer_name.asm @@ -1,15 +1,15 @@ -GetTrainerName_: +GetTrainerName_:: ld hl, wGrassRate ld a, [wLinkState] and a jr nz, .foundName ld hl, wRivalName ld a, [wTrainerClass] - cp SONY1 + cp RIVAL1 jr z, .foundName - cp SONY2 + cp RIVAL2 jr z, .foundName - cp SONY3 + cp RIVAL3 jr z, .foundName ld [wd0b5], a ld a, TRAINER_NAME diff --git a/engine/battle/ghost_marowak_anim.asm b/engine/battle/ghost_marowak_anim.asm index 972d5bf5..03059022 100644 --- a/engine/battle/ghost_marowak_anim.asm +++ b/engine/battle/ghost_marowak_anim.asm @@ -1,22 +1,22 @@ MarowakAnim: ; animate the ghost being unveiled as a Marowak ld a, $e4 - ld [rOBP1], a + ldh [rOBP1], a call UpdateGBCPal_OBP1 call CopyMonPicFromBGToSpriteVRAM ; cover the BG ghost pic with a sprite ghost pic that looks the same ; now that the ghost pic is being displayed using sprites, clear the ghost pic from the BG tilemap - coord hl, 12, 0 + hlcoord 12, 0 lb bc, 7, 7 call ClearScreenArea call Delay3 xor a - ld [H_AUTOBGTRANSFERENABLED], a ; disable BG transfer so we don't see the Marowak too soon + ldh [hAutoBGTransferEnabled], a ; disable BG transfer so we don't see the Marowak too soon ; replace ghost pic with Marowak in BG ld a, RESTLESS_SOUL ld [wChangeMonPicEnemyTurnSpecies], a ld a, $1 - ld [H_WHOSETURN], a - callab ChangeMonPic + ldh [hWhoseTurn], a + callfar ChangeMonPic ; alternate between black and light grey 8 times. ; this makes the ghost's body appear to flash ld d, $80 @@ -24,10 +24,10 @@ MarowakAnim: .fadeOutGhostLoop ld c, 10 call DelayFrames - ld a, [rOBP1] + ldh a, [rOBP1] sla a sla a - ld [rOBP1], a + ldh [rOBP1], a call UpdateGBCPal_OBP1 jr nz, .fadeOutGhostLoop call ClearSprites @@ -36,18 +36,18 @@ MarowakAnim: .fadeInMarowakLoop ld c, 10 call DelayFrames - ld a, [rOBP1] + ldh a, [rOBP1] srl b rra srl b rra - ld [rOBP1], a + ldh [rOBP1], a call UpdateGBCPal_OBP1 ld a, b and a jr nz, .fadeInMarowakLoop ld a, $1 - ld [H_AUTOBGTRANSFERENABLED], a ; enable BG transfer so the BG Marowak pic will be visible after the sprite one is cleared + ldh [hAutoBGTransferEnabled], a ; enable BG transfer so the BG Marowak pic will be visible after the sprite one is cleared call Delay3 jp ClearSprites diff --git a/engine/battle/init_battle_variables.asm b/engine/battle/init_battle_variables.asm index 7bc912d2..0d403b55 100644 --- a/engine/battle/init_battle_variables.asm +++ b/engine/battle/init_battle_variables.asm @@ -1,5 +1,5 @@ InitBattleVariables: - ld a, [hTilesetType] + ldh a, [hTilesetType] ld [wSavedTilesetType], a xor a ld [wActionResultOrTookBattleTurn], a @@ -35,4 +35,4 @@ InitBattleVariables: ld a, BATTLE_TYPE_SAFARI ld [wBattleType], a .notSafariBattle - jpab PlayBattleMusic + jpfar PlayBattleMusic diff --git a/engine/battle/link_battle_versus_text.asm b/engine/battle/link_battle_versus_text.asm index 63142ba6..e55a0672 100644 --- a/engine/battle/link_battle_versus_text.asm +++ b/engine/battle/link_battle_versus_text.asm @@ -1,22 +1,22 @@ ; display "[player] VS [enemy]" text box with pokeballs representing their parties next to the names DisplayLinkBattleVersusTextBox: call LoadTextBoxTilePatterns - coord hl, 3, 4 + hlcoord 3, 4 lb bc, 7, 12 call TextBoxBorder - coord hl, 4, 5 + hlcoord 4, 5 ld de, wPlayerName call PlaceString - coord hl, 4, 10 + hlcoord 4, 10 ld de, wLinkEnemyTrainerName call PlaceString ; place bold "VS" tiles between the names - coord hl, 9, 8 + hlcoord 9, 8 ld a, $69 ld [hli], a ld [hl], $6a xor a ld [wUpdateSpritesEnabled], a - callab SetupPlayerAndEnemyPokeballs + callfar SetupPlayerAndEnemyPokeballs ld c, 150 jp DelayFrames diff --git a/engine/battle/bank_e_misc.asm b/engine/battle/misc.asm index df9145f2..df9145f2 100755 --- a/engine/battle/bank_e_misc.asm +++ b/engine/battle/misc.asm diff --git a/engine/battle/moveEffects/conversion_effect.asm b/engine/battle/move_effects/conversion.asm index f23c3d70..1f64ec5b 100644 --- a/engine/battle/moveEffects/conversion_effect.asm +++ b/engine/battle/move_effects/conversion.asm @@ -1,7 +1,7 @@ ConversionEffect_: ld hl, wEnemyMonType1 ld de, wBattleMonType1 - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a ld a, [wEnemyBattleStatus1] jr z, .conversionEffect @@ -25,8 +25,8 @@ ConversionEffect_: jp PrintText ConvertedTypeText: - TX_FAR _ConvertedTypeText - db "@" + text_far _ConvertedTypeText + text_end PrintButItFailedText: ld hl, PrintButItFailedText_ diff --git a/engine/battle/moveEffects/drain_hp_effect.asm b/engine/battle/move_effects/drain_hp.asm index e5f4681a..04a585cc 100644 --- a/engine/battle/moveEffects/drain_hp_effect.asm +++ b/engine/battle/move_effects/drain_hp.asm @@ -14,7 +14,7 @@ DrainHPEffect_: .getAttackerHP ld hl, wBattleMonHP ld de, wBattleMonMaxHP - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a jp z, .addDamageToAttackerHP ld hl, wEnemyMonHP @@ -69,21 +69,21 @@ DrainHPEffect_: ld [wHPBarNewHP+1], a inc de .next - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a - coord hl, 10, 9 + hlcoord 10, 9 ld a, $1 jr z, .next2 - coord hl, 2, 2 + hlcoord 2, 2 xor a .next2 ld [wHPBarType], a predef UpdateHPBar2 predef DrawPlayerHUDAndHPBar predef DrawEnemyHUDAndHPBar - callab ReadPlayerMonCurHPAndStatus + callfar ReadPlayerMonCurHPAndStatus ld hl, SuckedHealthText - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a ld a, [wPlayerMoveEffect] jr z, .next3 @@ -96,9 +96,9 @@ DrainHPEffect_: jp PrintText SuckedHealthText: - TX_FAR _SuckedHealthText - db "@" + text_far _SuckedHealthText + text_end DreamWasEatenText: - TX_FAR _DreamWasEatenText - db "@" + text_far _DreamWasEatenText + text_end diff --git a/engine/battle/moveEffects/focus_energy_effect.asm b/engine/battle/move_effects/focus_energy.asm index 16dad7bb..1fafe920 100644 --- a/engine/battle/moveEffects/focus_energy_effect.asm +++ b/engine/battle/move_effects/focus_energy.asm @@ -1,6 +1,6 @@ FocusEnergyEffect_: ld hl, wPlayerBattleStatus2 - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a jr z, .notEnemy ld hl, wEnemyBattleStatus2 @@ -8,15 +8,15 @@ FocusEnergyEffect_: bit GETTING_PUMPED, [hl] ; is mon already using focus energy? jr nz, .alreadyUsing set GETTING_PUMPED, [hl] ; mon is now using focus energy - callab PlayCurrentMoveAnimation + callfar PlayCurrentMoveAnimation ld hl, GettingPumpedText jp PrintText .alreadyUsing ld c, 50 call DelayFrames - jpab PrintButItFailedText_ + jpfar PrintButItFailedText_ GettingPumpedText: - TX_DELAY - TX_FAR _GettingPumpedText - db "@" + text_pause + text_far _GettingPumpedText + text_end diff --git a/engine/battle/moveEffects/haze_effect.asm b/engine/battle/move_effects/haze.asm index 47723ba2..915eeed8 100644 --- a/engine/battle/moveEffects/haze_effect.asm +++ b/engine/battle/move_effects/haze.asm @@ -15,7 +15,7 @@ HazeEffect_: ; cure non-volatile status, but only for the target ld hl, wEnemyMonStatus ld de, wEnemySelectedMove - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a jr z, .cureStatuses ld hl, wBattleMonStatus @@ -77,5 +77,5 @@ ResetStats: ret StatusChangesEliminatedText: - TX_FAR _StatusChangesEliminatedText - db "@" + text_far _StatusChangesEliminatedText + text_end diff --git a/engine/battle/moveEffects/heal_effect.asm b/engine/battle/move_effects/heal.asm index 97afa394..80923a29 100644 --- a/engine/battle/moveEffects/heal_effect.asm +++ b/engine/battle/move_effects/heal.asm @@ -1,5 +1,5 @@ HealEffect_: - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a ld de, wBattleMonHP ld hl, wBattleMonMaxHP @@ -27,7 +27,7 @@ HealEffect_: ld c, 50 call DelayFrames ld hl, wBattleMonStatus - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a jr z, .restEffect ld hl, wEnemyMonStatus @@ -87,12 +87,12 @@ HealEffect_: .playAnim ld hl, PlayCurrentMoveAnimation call Bankswitch3DtoF - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a - coord hl, 10, 9 + hlcoord 10, 9 ld a, $1 jr z, .updateHPBar - coord hl, 2, 2 + hlcoord 2, 2 xor a .updateHPBar ld [wHPBarType], a @@ -108,13 +108,13 @@ HealEffect_: jp Bankswitch3DtoF StartedSleepingEffect: - TX_FAR _StartedSleepingEffect - db "@" + text_far _StartedSleepingEffect + text_end FellAsleepBecameHealthyText: - TX_FAR _FellAsleepBecameHealthyText - db "@" + text_far _FellAsleepBecameHealthyText + text_end RegainedHealthText: - TX_FAR _RegainedHealthText - db "@" + text_far _RegainedHealthText + text_end diff --git a/engine/battle/moveEffects/leech_seed_effect.asm b/engine/battle/move_effects/leech_seed.asm index f4d3ee9c..61bd982a 100644 --- a/engine/battle/moveEffects/leech_seed_effect.asm +++ b/engine/battle/move_effects/leech_seed.asm @@ -1,11 +1,11 @@ LeechSeedEffect_: - callab MoveHitTest + callfar MoveHitTest ld a, [wMoveMissed] and a jr nz, .moveMissed ld hl, wEnemyBattleStatus2 ld de, wEnemyMonType1 - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a jr z, .leechSeedEffect ld hl, wPlayerBattleStatus2 @@ -22,7 +22,7 @@ LeechSeedEffect_: bit SEEDED, [hl] jr nz, .moveMissed set SEEDED, [hl] - callab PlayCurrentMoveAnimation + callfar PlayCurrentMoveAnimation ld hl, WasSeededText jp PrintText .moveMissed @@ -32,9 +32,9 @@ LeechSeedEffect_: jp PrintText WasSeededText: - TX_FAR _WasSeededText - db "@" + text_far _WasSeededText + text_end EvadedAttackText: - TX_FAR _EvadedAttackText - db "@" + text_far _EvadedAttackText + text_end diff --git a/engine/battle/moveEffects/mist_effect.asm b/engine/battle/move_effects/mist.asm index 65070a3e..163d386f 100644 --- a/engine/battle/moveEffects/mist_effect.asm +++ b/engine/battle/move_effects/mist.asm @@ -1,6 +1,6 @@ MistEffect_: ld hl, wPlayerBattleStatus2 - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a jr z, .mistEffect ld hl, wEnemyBattleStatus2 @@ -8,12 +8,12 @@ MistEffect_: bit PROTECTED_BY_MIST, [hl] ; is mon protected by mist? jr nz, .mistAlreadyInUse set PROTECTED_BY_MIST, [hl] ; mon is now protected by mist - callab PlayCurrentMoveAnimation + callfar PlayCurrentMoveAnimation ld hl, ShroudedInMistText jp PrintText .mistAlreadyInUse - jpab PrintButItFailedText_ + jpfar PrintButItFailedText_ ShroudedInMistText: - TX_FAR _ShroudedInMistText - db "@" + text_far _ShroudedInMistText + text_end diff --git a/engine/battle/moveEffects/one_hit_ko_effect.asm b/engine/battle/move_effects/one_hit_ko.asm index 827e2197..7e5db0f7 100644 --- a/engine/battle/moveEffects/one_hit_ko_effect.asm +++ b/engine/battle/move_effects/one_hit_ko.asm @@ -7,7 +7,7 @@ OneHitKOEffect_: ld [wCriticalHitOrOHKO], a ld hl, wBattleMonSpeed + 1 ld de, wEnemyMonSpeed + 1 - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a jr z, .compareSpeed ld hl, wEnemyMonSpeed + 1 diff --git a/engine/battle/moveEffects/paralyze_effect.asm b/engine/battle/move_effects/paralyze.asm index 95979ae6..dbaa0fb8 100644 --- a/engine/battle/moveEffects/paralyze_effect.asm +++ b/engine/battle/move_effects/paralyze.asm @@ -1,7 +1,7 @@ ParalyzeEffect_: ld hl, wEnemyMonStatus ld de, wPlayerMoveType - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a jp z, .next ld hl, wBattleMonStatus @@ -26,22 +26,22 @@ ParalyzeEffect_: jr z, .doesntAffect .hitTest push hl - callab MoveHitTest + callfar MoveHitTest pop hl ld a, [wMoveMissed] and a jr nz, .didntAffect set PAR, [hl] - callab QuarterSpeedDueToParalysis + callfar QuarterSpeedDueToParalysis ld c, 30 call DelayFrames - callab PlayCurrentMoveAnimation - jpab PrintMayNotAttackText + callfar PlayCurrentMoveAnimation + jpfar PrintMayNotAttackText .didntAffect ld c, 50 call DelayFrames - jpab PrintDidntAffectText + jpfar PrintDidntAffectText .doesntAffect ld c, 50 call DelayFrames - jpab PrintDoesntAffectText + jpfar PrintDoesntAffectText diff --git a/engine/battle/moveEffects/pay_day_effect.asm b/engine/battle/move_effects/pay_day.asm index e5daf014..fa373038 100644 --- a/engine/battle/moveEffects/pay_day_effect.asm +++ b/engine/battle/move_effects/pay_day.asm @@ -2,7 +2,7 @@ PayDayEffect_: xor a ld hl, wcd6d ld [hli], a - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a ld a, [wBattleMonLevel] jr z, .payDayEffect @@ -10,28 +10,28 @@ PayDayEffect_: .payDayEffect ; level * 2 add a - ld [H_DIVIDEND + 3], a + ldh [hDividend + 3], a xor a - ld [H_DIVIDEND], a - ld [H_DIVIDEND + 1], a - ld [H_DIVIDEND + 2], a + ldh [hDividend], a + ldh [hDividend + 1], a + ldh [hDividend + 2], a ; convert to BCD ld a, 100 - ld [H_DIVISOR], a + ldh [hDivisor], a ld b, $4 call Divide - ld a, [H_QUOTIENT + 3] + ldh a, [hQuotient + 3] ld [hli], a - ld a, [H_REMAINDER] - ld [H_DIVIDEND + 3], a + ldh a, [hRemainder] + ldh [hDividend + 3], a ld a, 10 - ld [H_DIVISOR], a + ldh [hDivisor], a ld b, $4 call Divide - ld a, [H_QUOTIENT + 3] + ldh a, [hQuotient + 3] swap a ld b, a - ld a, [H_REMAINDER] + ldh a, [hRemainder] add b ld [hl], a ld de, wTotalPayDayMoney + 2 @@ -41,5 +41,5 @@ PayDayEffect_: jp PrintText CoinsScatteredText: - TX_FAR _CoinsScatteredText - db "@" + text_far _CoinsScatteredText + text_end diff --git a/engine/battle/moveEffects/recoil_effect.asm b/engine/battle/move_effects/recoil.asm index 0f2f087b..85110d50 100644 --- a/engine/battle/moveEffects/recoil_effect.asm +++ b/engine/battle/move_effects/recoil.asm @@ -1,5 +1,5 @@ RecoilEffect_: - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a ld a, [wPlayerMoveNum] ld hl, wBattleMonMaxHP @@ -53,12 +53,12 @@ RecoilEffect_: ld [hli], a ld [hl], a .getHPBarCoords - coord hl, 10, 9 - ld a, [H_WHOSETURN] + hlcoord 10, 9 + ldh a, [hWhoseTurn] and a ld a, $1 jr z, .updateHPBar - coord hl, 2, 2 + hlcoord 2, 2 xor a .updateHPBar ld [wHPBarType], a @@ -66,5 +66,5 @@ RecoilEffect_: ld hl, HitWithRecoilText jp PrintText HitWithRecoilText: - TX_FAR _HitWithRecoilText - db "@" + text_far _HitWithRecoilText + text_end diff --git a/engine/battle/moveEffects/reflect_light_screen_effect.asm b/engine/battle/move_effects/reflect_light_screen.asm index e5748b19..c05055fa 100644 --- a/engine/battle/moveEffects/reflect_light_screen_effect.asm +++ b/engine/battle/move_effects/reflect_light_screen.asm @@ -1,7 +1,7 @@ ReflectLightScreenEffect_: ld hl, wPlayerBattleStatus3 ld de, wPlayerMoveEffect - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a jr z, .reflectLightScreenEffect ld hl, wEnemyBattleStatus3 @@ -33,12 +33,12 @@ ReflectLightScreenEffect_: jp Bankswitch3DtoF LightScreenProtectedText: - TX_FAR _LightScreenProtectedText - db "@" + text_far _LightScreenProtectedText + text_end ReflectGainedArmorText: - TX_FAR _ReflectGainedArmorText - db "@" + text_far _ReflectGainedArmorText + text_end Bankswitch3DtoF: ld b, BANK(BattleCore) diff --git a/engine/battle/moveEffects/substitute_effect.asm b/engine/battle/move_effects/substitute.asm index b5d006fc..860b76b6 100644 --- a/engine/battle/moveEffects/substitute_effect.asm +++ b/engine/battle/move_effects/substitute.asm @@ -4,7 +4,7 @@ SubstituteEffect_: ld hl, wBattleMonMaxHP ld de, wPlayerSubstituteHP ld bc, wPlayerBattleStatus2 - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a jr z, .notEnemy ld hl, wEnemyMonMaxHP @@ -28,7 +28,7 @@ SubstituteEffect_: add hl, de ; point hl to current HP low byte pop de ld a, b - ld [de], a ; save copy of HP to subtract in ccd7/ccd8 [how much HP substitute has] + ld [de], a ; save copy of HP to subtract in wPlayerSubstituteHP/wEnemySubstituteHP ld a, [hld] ; subtract [max hp / 4] to current HP sub b @@ -55,7 +55,7 @@ SubstituteEffect_: call Bankswitch ; jump to routine depending on animation setting ld hl, SubstituteText call PrintText - jpab DrawHUDsAndHPBars + jpfar DrawHUDsAndHPBars .alreadyHasSubstitute ld hl, HasSubstituteText jr .printText @@ -65,13 +65,13 @@ SubstituteEffect_: jp PrintText SubstituteText: - TX_FAR _SubstituteText - db "@" + text_far _SubstituteText + text_end HasSubstituteText: - TX_FAR _HasSubstituteText - db "@" + text_far _HasSubstituteText + text_end TooWeakSubstituteText: - TX_FAR _TooWeakSubstituteText - db "@" + text_far _TooWeakSubstituteText + text_end diff --git a/engine/battle/moveEffects/transform_effect.asm b/engine/battle/move_effects/transform.asm index ec07b303..d37bd94d 100644 --- a/engine/battle/moveEffects/transform_effect.asm +++ b/engine/battle/move_effects/transform.asm @@ -3,7 +3,7 @@ TransformEffect_: ld de, wEnemyMonSpecies ld bc, wEnemyBattleStatus3 ld a, [wEnemyBattleStatus1] - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a jr nz, .hitTest ld hl, wEnemyMonSpecies @@ -18,7 +18,7 @@ TransformEffect_: push de push bc ld hl, wPlayerBattleStatus2 - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a jr z, .transformEffect ld hl, wEnemyBattleStatus2 @@ -64,7 +64,7 @@ TransformEffect_: inc bc inc bc call CopyData - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a jr z, .next ; save enemy mon DVs at wTransformedEnemyMonOriginalDVs @@ -121,7 +121,7 @@ TransformEffect_: jp PrintText .copyBasedOnTurn - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a jr z, .gotStatsOrModsToCopy push hl @@ -137,5 +137,5 @@ TransformEffect_: jp Bankswitch3DtoF TransformedText: - TX_FAR _TransformedText - db "@" + text_far _TransformedText + text_end diff --git a/engine/battle/print_type.asm b/engine/battle/print_type.asm index f717f871..7da0dc8c 100644 --- a/engine/battle/print_type.asm +++ b/engine/battle/print_type.asm @@ -49,4 +49,4 @@ PrintType_: pop hl jp PlaceString -INCLUDE "text/type_names.asm" +INCLUDE "data/types/names.asm" diff --git a/engine/battle/read_trainer_party.asm b/engine/battle/read_trainer_party.asm index b4ee46a0..02fbfeda 100755 --- a/engine/battle/read_trainer_party.asm +++ b/engine/battle/read_trainer_party.asm @@ -110,7 +110,7 @@ ReadTrainer: dec a ld c, a ld b, 0 - add hl,bc + add hl, bc ld a, [de] inc de ld [hl], a diff --git a/engine/battle/safari_zone.asm b/engine/battle/safari_zone.asm index 88064f9a..9362cc3a 100755 --- a/engine/battle/safari_zone.asm +++ b/engine/battle/safari_zone.asm @@ -28,9 +28,9 @@ PrintSafariZoneBattleText: jp PrintText SafariZoneEatingText: - TX_FAR _SafariZoneEatingText - db "@" + text_far _SafariZoneEatingText + text_end SafariZoneAngryText: - TX_FAR _SafariZoneAngryText - db "@" + text_far _SafariZoneAngryText + text_end diff --git a/engine/battle/save_trainer_name.asm b/engine/battle/save_trainer_name.asm index 49d0429f..4d40fd82 100644 --- a/engine/battle/save_trainer_name.asm +++ b/engine/battle/save_trainer_name.asm @@ -1,4 +1,4 @@ -SaveTrainerName: +SaveTrainerName:: ld hl, TrainerNamePointers ld a, [wTrainerClass] dec a @@ -18,95 +18,4 @@ SaveTrainerName: jr nz, .CopyCharacter ret -TrainerNamePointers: -; what is the point of these? - dw YoungsterName - dw BugCatcherName - dw LassName - dw wTrainerName - dw JrTrainerMName - dw JrTrainerFName - dw PokemaniacName - dw SuperNerdName - dw wTrainerName - dw wTrainerName - dw BurglarName - dw EngineerName - dw JugglerXName - dw wTrainerName - dw SwimmerName - dw wTrainerName - dw wTrainerName - dw BeautyName - dw wTrainerName - dw RockerName - dw JugglerName - dw wTrainerName - dw wTrainerName - dw BlackbeltName - dw wTrainerName - dw ProfOakName - dw ChiefName - dw ScientistName - dw wTrainerName - dw RocketName - dw CooltrainerMName - dw CooltrainerFName - dw wTrainerName - dw wTrainerName - dw wTrainerName - dw wTrainerName - dw wTrainerName - dw wTrainerName - dw wTrainerName - dw wTrainerName - dw wTrainerName - dw wTrainerName - dw wTrainerName - dw wTrainerName - dw wTrainerName - dw wTrainerName - dw wTrainerName - -YoungsterName: - db "YOUNGSTER@" -BugCatcherName: - db "BUG CATCHER@" -LassName: - db "LASS@" -JrTrainerMName: - db "JR.TRAINER♂@" -JrTrainerFName: - db "JR.TRAINER♀@" -PokemaniacName: - db "POKéMANIAC@" -SuperNerdName: - db "SUPER NERD@" -BurglarName: - db "BURGLAR@" -EngineerName: - db "ENGINEER@" -JugglerXName: - db "JUGGLER@" -SwimmerName: - db "SWIMMER@" -BeautyName: - db "BEAUTY@" -RockerName: - db "ROCKER@" -JugglerName: - db "JUGGLER@" -BlackbeltName: - db "BLACKBELT@" -ProfOakName: - db "PROF.OAK@" -ChiefName: - db "CHIEF@" -ScientistName: - db "SCIENTIST@" -RocketName: - db "ROCKET@" -CooltrainerMName: - db "COOLTRAINER♂@" -CooltrainerFName: - db "COOLTRAINER♀@" +INCLUDE "data/trainers/name_pointers.asm" diff --git a/engine/battle/scale_sprites.asm b/engine/battle/scale_sprites.asm index c614d638..794a65ab 100644 --- a/engine/battle/scale_sprites.asm +++ b/engine/battle/scale_sprites.asm @@ -24,7 +24,7 @@ ScaleFirstThreeSpriteColumnsByTwo: .columnInnerLoop push bc ld a, [de] - ld bc, -(7*8)+1 ; $ffc9, scale lower nybble and seek to previous output column + ld bc, -(7*8)+1 ; -$37, scale lower nybble and seek to previous output column call ScalePixelsByTwo ld a, [de] dec de @@ -39,7 +39,7 @@ ScaleFirstThreeSpriteColumnsByTwo: dec de dec de ld a, b - ld bc, -7*8 ; $ffc8, skip one output column (which has already been written along with the current one) + ld bc, -7*8 ; -$38, skip one output column (which has already been written along with the current one) add hl, bc ld b, a dec b @@ -48,16 +48,16 @@ ScaleFirstThreeSpriteColumnsByTwo: ScaleLastSpriteColumnByTwo: ld a, 4*8 - 4 ; $1c, 4 tiles minus 4 unused rows - ld [H_SPRITEINTERLACECOUNTER], a + ldh [hSpriteInterlaceCounter], a ld bc, -1 .columnInnerLoop ld a, [de] dec de swap a ; only high nybble contains information call ScalePixelsByTwo - ld a, [H_SPRITEINTERLACECOUNTER] + ldh a, [hSpriteInterlaceCounter] dec a - ld [H_SPRITEINTERLACECOUNTER], a + ldh [hSpriteInterlaceCounter], a jr nz, .columnInnerLoop dec de ; skip last 4 rows of new column dec de @@ -86,7 +86,19 @@ ScalePixelsByTwo: ; repeats each input bit twice DuplicateBitsTable: - db $00, $03, $0c, $0f - db $30, $33, $3c, $3f - db $c0, $c3, $cc, $cf - db $f0, $f3, $fc, $ff + db %00000000 + db %00000011 + db %00001100 + db %00001111 + db %00110000 + db %00110011 + db %00111100 + db %00111111 + db %11000000 + db %11000011 + db %11001100 + db %11001111 + db %11110000 + db %11110011 + db %11111100 + db %11111111 diff --git a/engine/battle/scroll_draw_trainer_pic.asm b/engine/battle/scroll_draw_trainer_pic.asm index 98893dcf..e19d681a 100644 --- a/engine/battle/scroll_draw_trainer_pic.asm +++ b/engine/battle/scroll_draw_trainer_pic.asm @@ -5,8 +5,8 @@ _ScrollTrainerPicAfterBattle: ld [wEnemyMonSpecies2], a ld b, SET_PAL_BATTLE call RunPaletteCommand - callab _LoadTrainerPic - coord hl, 19, 0 + callfar _LoadTrainerPic + hlcoord 19, 0 ld c, $0 .scrollLoop inc c diff --git a/engine/battle/trainer_ai.asm b/engine/battle/trainer_ai.asm index c8fdfb29..17e68e75 100644 --- a/engine/battle/trainer_ai.asm +++ b/engine/battle/trainer_ai.asm @@ -134,7 +134,7 @@ AIMoveChoiceModification1: push de push bc ld hl, StatusAilmentMoveEffects - ld de, $0001 + ld de, 1 call IsInArray pop bc pop de @@ -146,11 +146,11 @@ AIMoveChoiceModification1: jr .nextMove StatusAilmentMoveEffects: - db $01 ; unused sleep effect + db EFFECT_01 ; unused sleep effect db SLEEP_EFFECT db POISON_EFFECT db PARALYZE_EFFECT - db $FF + db -1 ; end ; slightly encourage moves with specific effects. ; in particular, stat-modifying moves and other move effects @@ -204,7 +204,7 @@ AIMoveChoiceModification3: push hl push bc push de - callab AIGetTypeEffectiveness + callfar AIGetTypeEffectiveness pop de pop bc pop hl @@ -273,68 +273,19 @@ ReadMove: pop hl ret -; move choice modification methods that are applied for each trainer class -; 0 is sentinel value -TrainerClassMoveChoiceModifications: - db 0 ; YOUNGSTER - db 1,0 ; BUG CATCHER - db 1,0 ; LASS - db 1,3,0 ; SAILOR - db 1,0 ; JR_TRAINER_M - db 1,0 ; JR_TRAINER_F - db 1,2,3,0; POKEMANIAC - db 1,2,0 ; SUPER_NERD - db 1,0 ; HIKER - db 1,0 ; BIKER - db 1,3,0 ; BURGLAR - db 1,0 ; ENGINEER - db 1,2,0 ; JUGGLER_X - db 1,3,0 ; FISHER - db 1,3,0 ; SWIMMER - db 0 ; CUE_BALL - db 1,0 ; GAMBLER - db 1,3,0 ; BEAUTY - db 1,2,0 ; PSYCHIC_TR - db 1,0 ; ROCKER - db 1,0 ; JUGGLER - db 1,0 ; TAMER - db 1,0 ; BIRD_KEEPER - db 1,0 ; BLACKBELT - db 1,0 ; SONY1 - db 1,3,0 ; PROF_OAK - db 1,2,0 ; CHIEF - db 1,2,0 ; SCIENTIST - db 1,3,0 ; GIOVANNI - db 1,0 ; ROCKET - db 1,3,0 ; COOLTRAINER_M - db 1,3,0 ; COOLTRAINER_F - db 1,0 ; BRUNO - db 1,0 ; BROCK - db 1,3,0 ; MISTY - db 1,0 ; LT_SURGE - db 1,3,0 ; ERIKA - db 1,3,0 ; KOGA - db 1,0 ; BLAINE - db 1,0 ; SABRINA - db 1,2,0 ; GENTLEMAN - db 1,3,0 ; SONY2 - db 1,3,0 ; SONY3 - db 1,2,3,0; LORELEI - db 1,0 ; CHANNELER - db 1,0 ; AGATHA - db 1,3,0 ; LANCE - -INCLUDE "engine/battle/trainer_pic_money_pointers.asm" - -INCLUDE "text/trainer_names.asm" - -INCLUDE "engine/battle/bank_e_misc.asm" +INCLUDE "data/trainers/move_choices.asm" + +INCLUDE "data/trainers/pic_pointers_money.asm" + +INCLUDE "data/trainers/names.asm" + +INCLUDE "engine/battle/misc.asm" INCLUDE "engine/battle/read_trainer_party.asm" -INCLUDE "data/trainer_moves.asm" +INCLUDE "data/trainers/special_moves.asm" -INCLUDE "data/trainer_parties.asm" +INCLUDE "data/trainers/parties.asm" TrainerAI: ld a, [wIsInBattle] @@ -350,7 +301,7 @@ TrainerAI: and 1 << USING_RAGE ; %1000000 jr nz, .done ; don't follow trainer ai if opponent is locked in rage ; note that this doesn't check for hyper beam recharge which can cause problems - ld a,[wTrainerClass] ; what trainer class is this? + ld a, [wTrainerClass] ; what trainer class is this? dec a ld c, a ld b, 0 @@ -377,57 +328,7 @@ TrainerAI: and a ret -TrainerAIPointers: -; one entry per trainer class -; first byte, number of times (per Pokémon) it can occur -; next two bytes, pointer to AI subroutine for trainer class - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,JugglerAI ; juggler_x - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,GenericAI - dbw 3,JugglerAI ; juggler - dbw 3,GenericAI - dbw 3,GenericAI - dbw 2,BlackbeltAI ; blackbelt - dbw 3,GenericAI - dbw 3,GenericAI - dbw 1,GenericAI ; chief - dbw 3,GenericAI - dbw 1,GiovanniAI ; giovanni - dbw 3,GenericAI - dbw 2,CooltrainerMAI ; cooltrainerm - dbw 1,CooltrainerFAI ; cooltrainerf - dbw 2,BrunoAI ; bruno - dbw 5,BrockAI ; brock - dbw 1,MistyAI ; misty - dbw 1,LtSurgeAI ; surge - dbw 1,ErikaAI ; erika - dbw 2,KogaAI ; koga - dbw 2,BlaineAI ; blaine - dbw 1,SabrinaAI ; sabrina - dbw 3,GenericAI - dbw 1,Sony2AI ; sony2 - dbw 1,Sony3AI ; sony3 - dbw 2,LoreleiAI ; lorelei - dbw 3,GenericAI - dbw 2,AgathaAI ; agatha - dbw 1,LanceAI ; lance +INCLUDE "data/trainers/ai_pointers.asm" JugglerAI: cp 25 percent + 1 @@ -650,14 +551,14 @@ AIRecoverHP: AIPrintItemUseAndUpdateHPBar: call AIPrintItemUse_ - coord hl, 2, 2 + hlcoord 2, 2 xor a ld [wHPBarType], a predef UpdateHPBar2 jp DecrementAICount AISwitchIfEnoughMons: -; enemy trainer switches if there are 3 or more unfainted mons in party +; enemy trainer switches if there are 2 or more unfainted mons in party ld a, [wEnemyPartyCount] ld c, a ld hl, wEnemyMon1HP @@ -681,7 +582,7 @@ AISwitchIfEnoughMons: jr nz, .loop ld a, d ; how many available monsters are there? - cp 2 ; don't bother if only 1 or 2 + cp 2 ; don't bother if only 1 jp nc, SwitchEnemyMon and a ret @@ -707,7 +608,7 @@ SwitchEnemyMon: ; switching in a new mon in response to this switch. ld a, 1 ld [wFirstMonsNotOutYet], a - callab EnemySendOut + callfar EnemySendOut xor a ld [wFirstMonsNotOutYet], a @@ -718,8 +619,8 @@ SwitchEnemyMon: ret AIBattleWithdrawText: - TX_FAR _AIBattleWithdrawText - db "@" + text_far _AIBattleWithdrawText + text_end AIUseFullHeal: call AIPlayRestoringSFX @@ -763,17 +664,17 @@ AIUseDireHit: ; unused AICheckIfHPBelowFraction: ; return carry if enemy trainer's current HP is below 1 / a of the maximum - ld [H_DIVISOR], a + ldh [hDivisor], a ld hl, wEnemyMonMaxHP ld a, [hli] - ld [H_DIVIDEND], a + ldh [hDividend], a ld a, [hl] - ld [H_DIVIDEND + 1], a + ldh [hDividend + 1], a ld b, 2 call Divide - ld a, [H_QUOTIENT + 3] + ldh a, [hQuotient + 3] ld c, a - ld a, [H_QUOTIENT + 2] + ldh a, [hQuotient + 2] ld b, a ld hl, wEnemyMonHP + 1 ld a, [hld] @@ -821,7 +722,7 @@ AIIncreaseStat: ld a, ANIM_AF ld [hli], a ld [hl], b - callab StatModifierUpEffect + callfar StatModifierUpEffect pop hl pop af ld [hli], a @@ -843,5 +744,5 @@ AIPrintItemUse_: jp PrintText AIBattleUseItemText: - TX_FAR _AIBattleUseItemText - db "@" + text_far _AIBattleUseItemText + text_end diff --git a/engine/battle/trainer_pic_money_pointers.asm b/engine/battle/trainer_pic_money_pointers.asm deleted file mode 100755 index 37678e74..00000000 --- a/engine/battle/trainer_pic_money_pointers.asm +++ /dev/null @@ -1,143 +0,0 @@ -TrainerPicAndMoneyPointers: -; trainer pic pointers and base money. -; money received after battle = base money × level of highest-level enemy mon - dw YoungsterPic - money 1500 - - dw BugCatcherPic - money 1000 - - dw LassPic - money 1500 - - dw SailorPic - money 3000 - - dw JrTrainerMPic - money 2000 - - dw JrTrainerFPic - money 2000 - - dw PokemaniacPic - money 5000 - - dw SuperNerdPic - money 2500 - - dw HikerPic - money 3500 - - dw BikerPic - money 2000 - - dw BurglarPic - money 9000 - - dw EngineerPic - money 5000 - - dw JugglerPic - money 3500 - - dw FisherPic - money 3500 - - dw SwimmerPic - money 500 - - dw CueBallPic - money 2500 - - dw GamblerPic - money 7000 - - dw BeautyPic - money 7000 - - dw PsychicPic - money 1000 - - dw RockerPic - money 2500 - - dw JugglerPic - money 3500 - - dw TamerPic - money 4000 - - dw BirdKeeperPic - money 2500 - - dw BlackbeltPic - money 2500 - - dw Rival1Pic - money 3500 - - dw ProfOakPic - money 9900 - - dw ChiefPic - money 3000 - - dw ScientistPic - money 5000 - - dw GiovanniPic - money 9900 - - dw RocketPic - money 3000 - - dw CooltrainerMPic - money 3500 - - dw CooltrainerFPic - money 3500 - - dw BrunoPic - money 9900 - - dw BrockPic - money 9900 - - dw MistyPic - money 9900 - - dw LtSurgePic - money 9900 - - dw ErikaPic - money 9900 - - dw KogaPic - money 9900 - - dw BlainePic - money 9900 - - dw SabrinaPic - money 9900 - - dw GentlemanPic - money 7000 - - dw Rival2Pic - money 6500 - - dw Rival3Pic - money 9900 - - dw LoreleiPic - money 9900 - - dw ChannelerPic - money 3000 - - dw AgathaPic - money 9900 - - dw LancePic - money 9900 diff --git a/engine/battle/unused_stats_functions.asm b/engine/battle/unused_stats_functions.asm index 55f78fd3..5174adf5 100644 --- a/engine/battle/unused_stats_functions.asm +++ b/engine/battle/unused_stats_functions.asm @@ -1,6 +1,6 @@ ; does nothing since no stats are ever selected (barring glitches) DoubleSelectedStats: - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a ld a, [wPlayerStatsToDouble] ld hl, wBattleMonAttack + 1 @@ -30,7 +30,7 @@ DoubleSelectedStats: ; does nothing since no stats are ever selected (barring glitches) HalveSelectedStats: - ld a, [H_WHOSETURN] + ldh a, [hWhoseTurn] and a ld a, [wPlayerStatsToHalve] ld hl, wBattleMonAttack diff --git a/engine/battle/wild_encounters.asm b/engine/battle/wild_encounters.asm index 0285346e..d16c6515 100644 --- a/engine/battle/wild_encounters.asm +++ b/engine/battle/wild_encounters.asm @@ -7,14 +7,14 @@ TryDoWildEncounter: ld a, [wd736] and a ret nz - callab IsPlayerStandingOnDoorTileOrWarpTile + callfar IsPlayerStandingOnDoorTileOrWarpTile jr nc, .notStandingOnDoorOrWarpTile .CantEncounter ld a, $1 and a ret .notStandingOnDoorOrWarpTile - callab IsPlayerJustOutsideMap + callfar IsPlayerJustOutsideMap jr z, .CantEncounter ld a, [wRepelRemainingSteps] and a @@ -26,7 +26,7 @@ TryDoWildEncounter: ; determine if wild pokemon can appear in the half-block we're standing in ; is the bottom left tile (8,9) of the half-block we're standing in a grass/water tile? ; note that by using the bottom left tile, this prevents the "left-shore" tiles from generating grass encounters - coord hl, 8, 9 + hlcoord 8, 9 ld c, [hl] ld a, [wGrassTile] cp c @@ -40,7 +40,7 @@ TryDoWildEncounter: ; so long as the map is "indoor" and has wild pokemon defined. ; ...as long as it's not Viridian Forest or Safari Zone. ld a, [wCurMap] - cp REDS_HOUSE_1F ; is this an indoor map? + cp FIRST_INDOOR_MAP ; is this an indoor map? jr c, .CantEncounter2 ld a, [wCurMapTileset] cp FOREST ; Viridian Forest/Safari Zone @@ -49,10 +49,10 @@ TryDoWildEncounter: .CanEncounter ; compare encounter chance with a random number to determine if there will be an encounter ld b, a - ld a, [hRandomAdd] + ldh a, [hRandomAdd] cp b jr nc, .CantEncounter2 - ld a, [hRandomSub] + ldh a, [hRandomSub] ld b, a ld hl, WildMonEncounterSlotChances .determineEncounterSlot @@ -65,7 +65,7 @@ TryDoWildEncounter: ; determine which wild pokemon (grass or water) can appear in the half-block we're standing in ld c, [hl] ld hl, wGrassMons - aCoord 8, 9 + lda_coord 8, 9 cp $14 ; is the bottom left tile (8,9) of the half-block we're standing in a water tile? jr nz, .gotWildEncounterType ; else, it's treated as a grass tile by default ld hl, wWaterMons @@ -89,7 +89,7 @@ TryDoWildEncounter: .lastRepelStep ld [wRepelRemainingSteps], a ld a, TEXT_REPEL_WORE_OFF - ld [hSpriteIndexOrTextID], a + ldh [hSpriteIndexOrTextID], a call EnableAutoTextBoxDrawing call DisplayTextID .CantEncounter2 @@ -100,18 +100,4 @@ TryDoWildEncounter: xor a ret -WildMonEncounterSlotChances: -; There are 10 slots for wild pokemon, and this is the table that defines how common each of -; those 10 slots is. A random number is generated and then the first byte of each pair in this -; table is compared against that random number. If the random number is less than or equal -; to the first byte, then that slot is chosen. The second byte is double the slot number. - db $32, $00 ; 51/256 = 19.9% chance of slot 0 - db $65, $02 ; 51/256 = 19.9% chance of slot 1 - db $8C, $04 ; 39/256 = 15.2% chance of slot 2 - db $A5, $06 ; 25/256 = 9.8% chance of slot 3 - db $BE, $08 ; 25/256 = 9.8% chance of slot 4 - db $D7, $0A ; 25/256 = 9.8% chance of slot 5 - db $E4, $0C ; 13/256 = 5.1% chance of slot 6 - db $F1, $0E ; 13/256 = 5.1% chance of slot 7 - db $FC, $10 ; 11/256 = 4.3% chance of slot 8 - db $FF, $12 ; 3/256 = 1.2% chance of slot 9 +INCLUDE "data/wild/probabilities.asm" |