diff options
Diffstat (limited to 'engine/battle')
38 files changed, 3553 insertions, 3442 deletions
diff --git a/engine/battle/animations.asm b/engine/battle/animations.asm index dc08e0e1..373136a8 100755 --- a/engine/battle/animations.asm +++ b/engine/battle/animations.asm @@ -1,21 +1,21 @@ ; Draws a "frame block". Frame blocks are blocks of tiles that are put ; together to form frames in battle animations. -DrawFrameBlock: ; 78000 (1e:4000) +DrawFrameBlock: ld l,c ld h,b ld a,[hli] - ld [W_NUMFBTILES],a - ld a,[W_FBDESTADDR + 1] + ld [wNumFBTiles],a + ld a,[wFBDestAddr + 1] ld e,a - ld a,[W_FBDESTADDR] + ld a,[wFBDestAddr] ld d,a xor a - ld [W_FBTILECOUNTER],a ; loop counter + ld [wFBTileCounter],a ; loop counter .loop - ld a,[W_FBTILECOUNTER] + ld a,[wFBTileCounter] inc a - ld [W_FBTILECOUNTER],a - ld a,[W_SUBANIMTRANSFORM] + ld [wFBTileCounter],a + ld a,[wSubAnimTransform] dec a jr z,.flipHorizontalAndVertical ; 1 dec a @@ -23,15 +23,15 @@ DrawFrameBlock: ; 78000 (1e:4000) dec a jr z,.flipBaseCoords ; 3 .noTransformation - ld a,[W_BASECOORDY] + ld a,[wBaseCoordY] add [hl] ld [de],a ; store Y inc hl inc de - ld a,[W_BASECOORDX] + ld a,[wBaseCoordX] jr .finishCopying .flipBaseCoords - ld a,[W_BASECOORDY] + ld a,[wBaseCoordY] ld b,a ld a,136 sub b ; flip Y base coordinate @@ -39,11 +39,11 @@ DrawFrameBlock: ; 78000 (1e:4000) ld [de],a ; store Y inc hl inc de - ld a,[W_BASECOORDX] + ld a,[wBaseCoordX] ld b,a ld a,168 sub b ; flip X base coordinate -.finishCopying ; finish copying values to OAM (when [W_SUBANIMTRANSFORM] not 1 or 2) +.finishCopying ; finish copying values to OAM (when [wSubAnimTransform] not 1 or 2) add [hl] ; X offset ld [de],a ; store X inc hl @@ -57,7 +57,7 @@ DrawFrameBlock: ; 78000 (1e:4000) inc de jp .nextTile .flipHorizontalAndVertical - ld a,[W_BASECOORDY] + ld a,[wBaseCoordY] add [hl] ; Y offset ld b,a ld a,136 @@ -65,7 +65,7 @@ DrawFrameBlock: ; 78000 (1e:4000) ld [de],a ; store Y inc hl inc de - ld a,[W_BASECOORDX] + ld a,[wBaseCoordX] add [hl] ; X offset ld b,a ld a,168 @@ -95,13 +95,13 @@ DrawFrameBlock: ; 78000 (1e:4000) inc de jp .nextTile .flipHorizontalTranslateDown - ld a,[W_BASECOORDY] + ld a,[wBaseCoordY] add [hl] add a,40 ; translate Y coordinate downwards ld [de],a ; store Y inc hl inc de - ld a,[W_BASECOORDX] + ld a,[wBaseCoordX] add [hl] ld b,a ld a,168 @@ -125,52 +125,52 @@ DrawFrameBlock: ; 78000 (1e:4000) ld [de],a inc de .nextTile - ld a,[W_FBTILECOUNTER] + ld a,[wFBTileCounter] ld c,a - ld a,[W_NUMFBTILES] + ld a,[wNumFBTiles] cp c jp nz,.loop ; go back up if there are more tiles to draw .afterDrawingTiles - ld a,[W_FBMODE] + ld a,[wFBMode] cp a,2 jr z,.advanceFrameBlockDestAddr; skip delay and don't clean OAM buffer - ld a,[W_SUBANIMFRAMEDELAY] + ld a,[wSubAnimFrameDelay] ld c,a call DelayFrames - ld a,[W_FBMODE] + ld a,[wFBMode] cp a,3 jr z,.advanceFrameBlockDestAddr ; skip cleaning OAM buffer cp a,4 jr z,.done ; skip cleaning OAM buffer and don't advance the frame block destination address - ld a,[W_ANIMATIONID] + ld a,[wAnimationID] cp a,GROWL jr z,.resetFrameBlockDestAddr call AnimationCleanOAM .resetFrameBlockDestAddr ld hl,wOAMBuffer ; OAM buffer ld a,l - ld [W_FBDESTADDR + 1],a + ld [wFBDestAddr + 1],a ld a,h - ld [W_FBDESTADDR],a ; set destination address to beginning of OAM buffer + ld [wFBDestAddr],a ; set destination address to beginning of OAM buffer ret .advanceFrameBlockDestAddr ld a,e - ld [W_FBDESTADDR + 1],a + ld [wFBDestAddr + 1],a ld a,d - ld [W_FBDESTADDR],a + ld [wFBDestAddr],a .done ret -PlayAnimation: ; 780f1 (1e:40f1) +PlayAnimation: xor a - ld [$FF8B],a - ld [W_SUBANIMTRANSFORM],a - ld a,[W_ANIMATIONID] ; get animation number + ld [$FF8B],a ; it looks like nothing reads this + ld [wSubAnimTransform],a + ld a,[wAnimationID] ; get animation number dec a ld l,a ld h,0 add hl,hl - ld de,AttackAnimationPointers ; $607d ; animation command stream pointers + ld de,AttackAnimationPointers ; animation command stream pointers add hl,de ld a,[hli] ld h,[hl] @@ -199,7 +199,7 @@ PlayAnimation: ; 780f1 (1e:40f1) ld [wAnimSoundID],a ; store sound push hl push de - call Func_7986f + call GetMoveSound call PlaySound pop de pop hl @@ -217,13 +217,13 @@ PlayAnimation: ; 780f1 (1e:40f1) .playSubanimation ld c,a and a,%00111111 - ld [W_SUBANIMFRAMEDELAY],a + ld [wSubAnimFrameDelay],a xor a sla c rla sla c rla - ld [wd09f],a ; tile select + ld [wWhichBattleAnimTileset],a ld a,[hli] ; sound ld [wAnimSoundID],a ; store sound ld a,[hli] ; subanimation ID @@ -235,15 +235,15 @@ PlayAnimation: ; 780f1 (1e:40f1) ld de,SubanimationPointers add hl,de ld a,l - ld [W_SUBANIMADDRPTR],a + ld [wSubAnimAddrPtr],a ld a,h - ld [W_SUBANIMADDRPTR + 1],a + ld [wSubAnimAddrPtr + 1],a ld l,c ld h,b push hl ld a,[rOBP0] push af - ld a,[wcc79] + ld a,[wAnimPalette] ld [rOBP0],a call LoadAnimationTileset call LoadSubanimation @@ -253,13 +253,13 @@ PlayAnimation: ; 780f1 (1e:40f1) .nextAnimationCommand pop hl jr .animationLoop -.AnimationOver ; 417B +.AnimationOver ret -LoadSubanimation: ; 7817c (1e:417c) - ld a,[W_SUBANIMADDRPTR + 1] +LoadSubanimation: + ld a,[wSubAnimAddrPtr + 1] ld h,a - ld a,[W_SUBANIMADDRPTR] + ld a,[wSubAnimAddrPtr] ld l,a ld a,[hli] ld e,a @@ -268,7 +268,7 @@ LoadSubanimation: ; 7817c (1e:417c) ld a,[de] ld b,a and a,31 - ld [W_SUBANIMCOUNTER],a ; number of frame blocks + ld [wSubAnimCounter],a ; number of frame blocks ld a,b and a,%11100000 cp a,5 << 5 ; is subanimation type 5? @@ -282,12 +282,12 @@ LoadSubanimation: ; 7817c (1e:417c) ; place the upper 3 bits of a into bits 0-2 of a before storing srl a swap a - ld [W_SUBANIMTRANSFORM],a + ld [wSubAnimTransform],a cp a,4 ; is the animation reversed? 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 - ld a,[W_SUBANIMCOUNTER] + ld a,[wSubAnimCounter] dec a ld bc,3 .loop @@ -298,15 +298,15 @@ LoadSubanimation: ; 7817c (1e:417c) inc de add hl,de ld a,l - ld [W_SUBANIMSUBENTRYADDR],a + ld [wSubAnimSubEntryAddr],a ld a,h - ld [W_SUBANIMSUBENTRYADDR + 1],a + 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 ; sets the transform to the subanimation type if it's the enemy's turn -GetSubanimationTransform1: ; 781c2 (1e:41c2) +GetSubanimationTransform1: ld b,a ld a,[H_WHOSETURN] and a @@ -318,7 +318,7 @@ GetSubanimationTransform1: ; 781c2 (1e:41c2) ; 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 -GetSubanimationTransform2: ; 781ca (1e:41ca) +GetSubanimationTransform2: ld a,[H_WHOSETURN] and a ld a,2 << 5 @@ -327,8 +327,8 @@ GetSubanimationTransform2: ; 781ca (1e:41ca) ret ; loads tile patterns for battle animations -LoadAnimationTileset: ; 781d2 (1e:41d2) - ld a,[wd09f] ; tileset select +LoadAnimationTileset: + ld a,[wWhichBattleAnimTileset] add a add a ld hl,AnimationTilesetPointers @@ -336,18 +336,18 @@ LoadAnimationTileset: ; 781d2 (1e:41d2) ld d,0 add hl,de ld a,[hli] - ld [wd07d],a ; number of tiles + ld [wTempTilesetNumTiles],a ; number of tiles ld a,[hli] ld e,a ld a,[hl] ld d,a ; de = address of tileset ld hl,vSprites + $310 ld b, BANK(AnimationTileset1) ; ROM bank - ld a,[wd07d] + ld a,[wTempTilesetNumTiles] ld c,a ; number of tiles jp CopyVideoData ; load tileset -AnimationTilesetPointers: ; 781f2 (1e:41f2) +AnimationTilesetPointers: db 79 ; number of tiles dw AnimationTileset1 db $FF @@ -360,60 +360,57 @@ AnimationTilesetPointers: ; 781f2 (1e:41f2) dw AnimationTileset1 db $FF -AnimationTileset1: ; 781fe (1e:41fe) +AnimationTileset1: INCBIN "gfx/attack_anim_1.2bpp" -AnimationTileset2: ; 786ee (1e:46ee) +AnimationTileset2: INCBIN "gfx/attack_anim_2.2bpp" -SlotMachineTiles2: ; 78bde (1e:4bde) +SlotMachineTiles2: IF DEF(_RED) INCBIN "gfx/red/slotmachine2.2bpp" ENDC IF DEF(_BLUE) INCBIN "gfx/blue/slotmachine2.2bpp" ENDC -IF DEF(_YELLOW) - INCBIN "gfx/yellow/slotmachine2.2bpp" -ENDC -MoveAnimation: ; 78d5e (1e:4d5e) +MoveAnimation: push hl push de push bc push af call WaitForSoundToFinish - call Func_78e23 - ld a,[W_ANIMATIONID] + call SetAnimationPalette + ld a,[wAnimationID] and a - jr z,.AnimationFinished + jr z, .animationFinished ; if throwing a Poké Ball, skip the regular animation code cp a,TOSS_ANIM - jr nz,.MoveAnimation - ld de,.AnimationFinished + jr nz, .moveAnimation + ld de, .animationFinished push de jp TossBallAnimation -.MoveAnimation +.moveAnimation ; check if battle animations are disabled in the options - ld a,[W_OPTIONS] + ld a,[wOptions] bit 7,a - jr nz,.AnimationsDisabled + jr nz, .animationsDisabled call ShareMoveAnimations call PlayAnimation jr .next4 -.AnimationsDisabled +.animationsDisabled ld c,30 call DelayFrames .next4 call PlayApplyingAttackAnimation ; shake the screen or flash the pic in and out (to show damage) -.AnimationFinished +.animationFinished call WaitForSoundToFinish xor a - ld [W_SUBANIMSUBENTRYADDR],a - ld [wd09b],a - ld [W_SUBANIMTRANSFORM],a + ld [wSubAnimSubEntryAddr],a + ld [wUnusedD09B],a + ld [wSubAnimTransform],a dec a ld [wAnimSoundID],a pop af @@ -422,7 +419,7 @@ MoveAnimation: ; 78d5e (1e:4d5e) pop hl ret -ShareMoveAnimations: ; 78da6 (1e:4da6) +ShareMoveAnimations: ; some moves just reuse animations from status conditions ld a,[H_WHOSETURN] and a @@ -430,22 +427,22 @@ ShareMoveAnimations: ; 78da6 (1e:4da6) ; opponent’s turn - ld a,[W_ANIMATIONID] + ld a,[wAnimationID] cp a,AMNESIA ld b,CONF_ANIM - jr z,.Replace + jr z, .replaceAnim cp a,REST ld b,SLP_ANIM ret nz -.Replace +.replaceAnim ld a,b - ld [W_ANIMATIONID],a + ld [wAnimationID],a ret -PlayApplyingAttackAnimation: ; 78dbd (1e:4dbd) +PlayApplyingAttackAnimation: ; Generic animation that shows after the move's individual animation ; Different animation depending on whether the move has an additional effect and on whose turn it is ld a,[wAnimationType] @@ -462,7 +459,7 @@ PlayApplyingAttackAnimation: ; 78dbd (1e:4dbd) ld l,a jp [hl] -AnimationTypePointerTable: ; 78dcf (1e:4dcf) +AnimationTypePointerTable: 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 @@ -470,100 +467,100 @@ AnimationTypePointerTable: ; 78dcf (1e:4dcf) dw ShakeScreenHorizontallyLight ; player mon has used a damaging move with a side effect dw ShakeScreenHorizontallySlow2 ; player mon has used a non-damaging move -ShakeScreenVertically: ; 78ddb (1e:4ddb) +ShakeScreenVertically: call PlayApplyingAttackSound - ld b, $8 + ld b, 8 jp AnimationShakeScreenVertically -ShakeScreenHorizontallyHeavy: ; 78de3 (1e:4de3) +ShakeScreenHorizontallyHeavy: call PlayApplyingAttackSound - ld b, $8 + ld b, 8 jp AnimationShakeScreenHorizontallyFast -ShakeScreenHorizontallySlow: ; 78deb (1e:4deb) - ld bc, $602 +ShakeScreenHorizontallySlow: + lb bc, 6, 2 jr AnimationShakeScreenHorizontallySlow -BlinkEnemyMonSprite: ; 78df0 (1e:4df0) +BlinkEnemyMonSprite: call PlayApplyingAttackSound jp AnimationBlinkEnemyMon -ShakeScreenHorizontallyLight: ; 78df6 (1e:4df6) +ShakeScreenHorizontallyLight: call PlayApplyingAttackSound - ld b, $2 + ld b, 2 jp AnimationShakeScreenHorizontallyFast -ShakeScreenHorizontallySlow2: ; 78dfe (1e:4dfe) - ld bc, $302 +ShakeScreenHorizontallySlow2: + lb bc, 3, 2 -AnimationShakeScreenHorizontallySlow: ; 78e01 (1e:4e01) +AnimationShakeScreenHorizontallySlow: push bc push bc -.asm_78e03 - ld a, [rWX] ; $ff4b +.loop1 + ld a, [rWX] inc a - ld [rWX], a ; $ff4b - ld c, $2 + ld [rWX], a + ld c, 2 call DelayFrames dec b - jr nz, .asm_78e03 + jr nz, .loop1 pop bc -.asm_78e11 - ld a, [rWX] ; $ff4b +.loop2 + ld a, [rWX] dec a - ld [rWX], a ; $ff4b - ld c, $2 + ld [rWX], a + ld c, 2 call DelayFrames dec b - jr nz, .asm_78e11 + jr nz, .loop2 pop bc dec c jr nz, AnimationShakeScreenHorizontallySlow ret -Func_78e23: ; 78e23 (1e:4e23) +SetAnimationPalette: ld a, [wOnSGB] and a ld a, $e4 - jr z, .asm_78e47 + jr z, .notSGB ld a, $f0 - ld [wcc79], a + ld [wAnimPalette], a ld b, $e4 - ld a, [W_ANIMATIONID] ; W_ANIMATIONID + ld a, [wAnimationID] cp TRADE_BALL_DROP_ANIM - jr c, .asm_78e3f + jr c, .next cp TRADE_BALL_POOF_ANIM + 1 - jr nc, .asm_78e3f + jr nc, .next ld b, $f0 -.asm_78e3f +.next ld a, b - ld [rOBP0], a ; $ff48 + ld [rOBP0], a ld a, $6c - ld [rOBP1], a ; $ff49 + ld [rOBP1], a ret -.asm_78e47 +.notSGB ld a, $e4 - ld [wcc79], a - ld [rOBP0], a ; $ff48 + ld [wAnimPalette], a + ld [rOBP0], a ld a, $6c - ld [rOBP1], a ; $ff49 + ld [rOBP1], a ret -PlaySubanimation: ; 78e53 (1e:4e53) +PlaySubanimation: ld a,[wAnimSoundID] cp a,$FF jr z,.skipPlayingSound - call Func_7986f - call PlaySound ; play sound effect + call GetMoveSound + call PlaySound .skipPlayingSound ld hl,wOAMBuffer ; base address of OAM buffer ld a,l - ld [W_FBDESTADDR + 1],a + ld [wFBDestAddr + 1],a ld a,h - ld [W_FBDESTADDR],a - ld a,[W_SUBANIMSUBENTRYADDR + 1] + ld [wFBDestAddr],a + ld a,[wSubAnimSubEntryAddr + 1] ld h,a - ld a,[W_SUBANIMSUBENTRYADDR] + ld a,[wSubAnimSubEntryAddr] ld l,a .loop push hl @@ -581,28 +578,28 @@ PlaySubanimation: ; 78e53 (1e:4e53) push hl ld e,[hl] ; base coordinate ID ld d,0 - ld hl,FrameBlockBaseCoords ; $7c85 ; base coordinate table + ld hl,FrameBlockBaseCoords ; base coordinate table add hl,de add hl,de ld a,[hli] - ld [W_BASECOORDY],a + ld [wBaseCoordY],a ld a,[hl] - ld [W_BASECOORDX],a + ld [wBaseCoordX],a pop hl inc hl ld a,[hl] ; frame block mode - ld [W_FBMODE],a + ld [wFBMode],a call DrawFrameBlock call DoSpecialEffectByAnimationId ; run animation-specific function (if there is one) - ld a,[W_SUBANIMCOUNTER] + ld a,[wSubAnimCounter] dec a - ld [W_SUBANIMCOUNTER],a + ld [wSubAnimCounter],a ret z - ld a,[W_SUBANIMSUBENTRYADDR + 1] + ld a,[wSubAnimSubEntryAddr + 1] ld h,a - ld a,[W_SUBANIMSUBENTRYADDR] + ld a,[wSubAnimSubEntryAddr] ld l,a - ld a,[W_SUBANIMTRANSFORM] + ld a,[wSubAnimTransform] cp a,4 ; is the animation reversed? ld bc,3 jr nz,.nextSubanimationSubentry @@ -610,12 +607,12 @@ PlaySubanimation: ; 78e53 (1e:4e53) .nextSubanimationSubentry add hl,bc ld a,h - ld [W_SUBANIMSUBENTRYADDR + 1],a + ld [wSubAnimSubEntryAddr + 1],a ld a,l - ld [W_SUBANIMSUBENTRYADDR],a + ld [wSubAnimSubEntryAddr],a jp .loop -AnimationCleanOAM: ; 78ec8 (1e:4ec8) +AnimationCleanOAM: push hl push de push bc @@ -630,11 +627,11 @@ AnimationCleanOAM: ; 78ec8 (1e:4ec8) ; this runs after each frame block is drawn in a subanimation ; it runs a particular special effect based on the animation ID -DoSpecialEffectByAnimationId: ; 78ed7 (1e:4ed7) +DoSpecialEffectByAnimationId: push hl push de push bc - ld a,[W_ANIMATIONID] + ld a,[wAnimationID] ld hl,AnimationIdSpecialEffects ld de,3 call IsInArray @@ -653,7 +650,7 @@ DoSpecialEffectByAnimationId: ; 78ed7 (1e:4ed7) ret ; Format: Animation ID (1 byte), Address (2 bytes) -AnimationIdSpecialEffects: ; 78ef5 (1e:4ef5) +AnimationIdSpecialEffects: db MEGA_PUNCH dw AnimationFlashScreen @@ -667,7 +664,7 @@ AnimationIdSpecialEffects: ; 78ef5 (1e:4ef5) dw AnimationFlashScreen db TAIL_WHIP - dw Func_790d0 + dw TailWhipAnimationUnused db GROWL dw DoGrowlSpecialEffects @@ -703,13 +700,13 @@ AnimationIdSpecialEffects: ; 78ef5 (1e:4ef5) dw DoRockSlideSpecialEffects db TRADE_BALL_DROP_ANIM - dw Func_79041 + dw TradeHidePokemon db TRADE_BALL_SHAKE_ANIM - dw Func_7904c + dw TradeShakePokeball db TRADE_BALL_TILT_ANIM - dw Func_7907c + dw TradeJumpPokeball db TOSS_ANIM dw DoBallTossSpecialEffects @@ -728,7 +725,7 @@ AnimationIdSpecialEffects: ; 78ef5 (1e:4ef5) db $FF ; terminator -DoBallTossSpecialEffects: ; 78f3e (1e:4f3e) +DoBallTossSpecialEffects: ld a,[wcf91] cp a,3 ; is it a Master Ball or Ultra Ball? jr nc,.skipFlashingEffect @@ -737,21 +734,21 @@ DoBallTossSpecialEffects: ; 78f3e (1e:4f3e) xor a,%00111100 ; complement colors 1 and 2 ld [rOBP0],a .skipFlashingEffect - ld a,[W_SUBANIMCOUNTER] + ld a,[wSubAnimCounter] cp a,11 ; is it the beginning of the subanimation? jr nz,.skipPlayingSound ; if it is the beginning of the subanimation, play a sound - ld a,(SFX_08_41 - SFX_Headers_08) / 3 - call PlaySound ; play sound + ld a,SFX_BALL_TOSS + call PlaySound .skipPlayingSound - ld a,[W_ISINBATTLE] + ld a,[wIsInBattle] cp a,02 ; is it a trainer battle? jr z,.isTrainerBattle ld a,[wd11e] cp a,$10 ; is the enemy pokemon the Ghost Marowak? ret nz ; if the enemy pokemon is the Ghost Marowak, make it dodge during the last 3 frames - ld a,[W_SUBANIMCOUNTER] + ld a,[wSubAnimCounter] cp a,3 jr z,.moveGhostMarowakLeft cp a,2 @@ -759,72 +756,72 @@ DoBallTossSpecialEffects: ; 78f3e (1e:4f3e) cp a,1 ret nz .moveGhostMarowakLeft - hlCoord 17, 0 + coord hl, 17, 0 ld de,20 - ld bc,$0707 ; 7 rows and 7 columns + lb bc, 7, 7 .loop push hl push bc - call Func_79862 ; move row of tiles left + call AnimCopyRowRight ; move row of tiles left pop bc pop hl add hl,de dec b jr nz,.loop ld a,%00001000 - ld [$ff10],a ; Channel 1 sweep register + ld [rNR10],a ; Channel 1 sweep register ret .isTrainerBattle ; if it's a trainer battle, shorten the animation by one frame - ld a,[W_SUBANIMCOUNTER] + ld a,[wSubAnimCounter] cp a,3 ret nz dec a - ld [W_SUBANIMCOUNTER],a + ld [wSubAnimCounter],a ret -DoBallShakeSpecialEffects: ; 78f96 (1e:4f96) - ld a,[W_SUBANIMCOUNTER] +DoBallShakeSpecialEffects: + ld a,[wSubAnimCounter] cp a,4 ; is it the beginning of a shake? jr nz,.skipPlayingSound ; if it is the beginning of a shake, play a sound and wait 2/3 of a second - ld a,(SFX_08_3c - SFX_Headers_08) / 3 - call PlaySound ; play sound + ld a,SFX_TINK + call PlaySound ld c,40 call DelayFrames .skipPlayingSound - ld a,[W_SUBANIMCOUNTER] + ld a,[wSubAnimCounter] dec a ret nz ; if it's the end of the ball shaking subanimation, check if more shakes are left and restart the subanimation - ld a,[wWhichTrade] ; number of shakes + ld a,[wNumShakes] ; number of shakes dec a ; decrement number of shakes - ld [wWhichTrade],a + ld [wNumShakes],a ret z ; if there are shakes left, restart the subanimation - ld a,[W_SUBANIMSUBENTRYADDR] + ld a,[wSubAnimSubEntryAddr] ld l,a - ld a,[W_SUBANIMSUBENTRYADDR + 1] + ld a,[wSubAnimSubEntryAddr + 1] ld h,a ld de,-(4 * 3) ; 4 subentries and 3 bytes per subentry add hl,de ld a,l - ld [W_SUBANIMSUBENTRYADDR],a + ld [wSubAnimSubEntryAddr],a ld a,h - ld [W_SUBANIMSUBENTRYADDR + 1],a + ld [wSubAnimSubEntryAddr + 1],a ld a,5 ; number of subentries in the ball shaking subanimation plus one - ld [W_SUBANIMCOUNTER],a + ld [wSubAnimCounter],a ret ; plays a sound after the second frame of the poof animation -DoPoofSpecialEffects: ; 78fce (1e:4fce) - ld a,[W_SUBANIMCOUNTER] +DoPoofSpecialEffects: + ld a,[wSubAnimCounter] cp a,5 ret nz - ld a,(SFX_08_42 - SFX_Headers_08) / 3 + ld a,SFX_BALL_POOF jp PlaySound -DoRockSlideSpecialEffects: ; 78fd9 (1e:4fd9) - ld a,[W_SUBANIMCOUNTER] +DoRockSlideSpecialEffects: + ld a,[wSubAnimCounter] cp a,12 ret nc cp a,8 @@ -835,35 +832,35 @@ DoRockSlideSpecialEffects: ; 78fd9 (1e:4fd9) ; if the subaninmation counter is between 8 and 11, shake the screen horizontally and vertically .shakeScreen ld b,1 - predef Func_48125 ; shake horizontally + predef PredefShakeScreenHorizontally ; shake horizontally ld b,1 - predef_jump Func_480ff ; shake vertically + predef_jump PredefShakeScreenVertically ; shake vertically -FlashScreenEveryEightFrameBlocks: ; 78ff7 (1e:4ff7) - ld a,[W_SUBANIMCOUNTER] +FlashScreenEveryEightFrameBlocks: + ld a,[wSubAnimCounter] and a,7 ; is the subanimation counter exactly 8? call z,AnimationFlashScreen ; if so, flash the screen ret ; flashes the screen if the subanimation counter is divisible by 4 -FlashScreenEveryFourFrameBlocks: ; 79000 (1e:5000) - ld a,[W_SUBANIMCOUNTER] +FlashScreenEveryFourFrameBlocks: + ld a,[wSubAnimCounter] and a,3 call z,AnimationFlashScreen ret ; used for Explosion and Selfdestruct -DoExplodeSpecialEffects: ; 79009 (1e:5009) - ld a,[W_SUBANIMCOUNTER] +DoExplodeSpecialEffects: + ld a,[wSubAnimCounter] cp a,1 ; is it the end of the subanimation? jr nz,FlashScreenEveryFourFrameBlocks ; if it's the end of the subanimation, make the attacking pokemon disappear - hlCoord 1, 5 + coord hl, 1, 5 jp AnimationHideMonPic ; make pokemon disappear ; flashes the screen when subanimation counter is 1 modulo 4 -DoBlizzardSpecialEffects: ; 79016 (1e:5016) - ld a,[W_SUBANIMCOUNTER] +DoBlizzardSpecialEffects: + ld a,[wSubAnimCounter] cp a,13 jp z,AnimationFlashScreen cp a,9 @@ -875,9 +872,9 @@ DoBlizzardSpecialEffects: ; 79016 (1e:5016) ret ; flashes the screen at 3 points in the subanimation -; XXX is this unused? -Func_7902e: ; 7902e (1e:502e) - ld a,[W_SUBANIMCOUNTER] +; unused +FlashScreenUnused: + ld a,[wSubAnimCounter] cp a,14 jp z,AnimationFlashScreen cp a,9 @@ -887,18 +884,16 @@ Func_7902e: ; 7902e (1e:502e) ret ; function to make the pokemon disappear at the beginning of the animation -; XXX probably a trade-related animation -Func_79041: ; 79041 (1e:5041) - ld a,[W_SUBANIMCOUNTER] +TradeHidePokemon: + ld a,[wSubAnimCounter] cp a,6 ret nz - ld a,$2F - jp Func_7980c ; make pokemon disappear + ld a,2 * SCREEN_WIDTH + 7 + jp ClearMonPicFromTileMap ; make pokemon disappear ; function to make a shaking pokeball jump up at the end of the animation -; XXX probably a trade-related animation -Func_7904c: ; 7904c (1e:504c) - ld a,[W_SUBANIMCOUNTER] +TradeShakePokeball: + ld a,[wSubAnimCounter] cp a,1 ret nz ; if it's the end of the animation, make the ball jump up @@ -923,16 +918,15 @@ Func_7904c: ; 7904c (1e:504c) jr .loop .done call AnimationCleanOAM - ld a,(SFX_02_44 - SFX_Headers_02) / 3 - jp PlaySound ; play sound + ld a,SFX_TRADE_MACHINE + jp PlaySound -BallMoveDistances1: ; 79078 (1e:5078) +BallMoveDistances1: db -12,-12,-8 db $ff ; terminator ; function to make the pokeball jump up -; XXX probably a trade-related animation -Func_7907c ; 507C +TradeJumpPokeball: ld de,BallMoveDistances2 .loop ld hl,wOAMBuffer ; OAM buffer @@ -955,7 +949,7 @@ Func_7907c ; 507C cp a,$ff jr nz,.skipPlayingSound .playSound ; play sound if next move distance is 12 or this is the last one - ld a,(SFX_08_58 - SFX_Headers_08) / 3 + ld a,SFX_BATTLE_18 call PlaySound .skipPlayingSound push bc @@ -968,31 +962,31 @@ Func_7907c ; 507C pop de jr .loop -BallMoveDistances2: ; 790b3 (1e:50b3) +BallMoveDistances2: db 11,12,-12,-7,7,12,-8,8 db $ff ; terminator ; this function copies the current musical note graphic ; so that there are two musical notes flying towards the defending pokemon -DoGrowlSpecialEffects: ; 790bc (1e:50bc) +DoGrowlSpecialEffects: ld hl,wOAMBuffer ; OAM buffer ld de,wOAMBuffer + $10 ld bc,$10 call CopyData ; copy the musical note graphic - ld a,[W_SUBANIMCOUNTER] + ld a,[wSubAnimCounter] dec a call z,AnimationCleanOAM ; clean up at the end of the subanimation ret ; this is associated with Tail Whip, but Tail Whip doesn't use any subanimations -Func_790d0: ; 790d0 (1e:50d0) +TailWhipAnimationUnused: ld a,1 - ld [W_SUBANIMCOUNTER],a + ld [wSubAnimCounter],a ld c,20 jp DelayFrames ; Format: Special Effect ID (1 byte), Address (2 bytes) -SpecialEffectPointers: ; 790da (1e:50da) +SpecialEffectPointers: db SE_DARK_SCREEN_FLASH ; $FE dw AnimationFlashScreen db SE_DARK_SCREEN_PALETTE ; $FD @@ -1013,8 +1007,8 @@ SpecialEffectPointers: ; 790da (1e:50da) dw AnimationSlideMonDown db SE_FLASH_MON_PIC ; $F5 dw AnimationFlashMonPic - db SE_SLIDE_MON_OUT ; $F4 - dw AnimationSlideMonOut + db SE_SLIDE_MON_OFF ; $F4 + dw AnimationSlideMonOff db SE_BLINK_MON ; $F3 dw AnimationBlinkMon db SE_MOVE_MON_HORIZONTALLY ; $F2 @@ -1043,8 +1037,8 @@ SpecialEffectPointers: ; 790da (1e:50da) dw AnimationLeavesFalling db SE_PETALS_FALLING ; $E6 dw AnimationPetalsFalling - db SE_SLIDE_MON_HALF_LEFT ; $E5 - dw AnimationSlideMonHalfLeft + 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) @@ -1063,8 +1057,8 @@ SpecialEffectPointers: ; 790da (1e:50da) dw AnimationShowMonPic db SE_SHOW_ENEMY_MON_PIC ; $DC dw AnimationShowEnemyMonPic - db SE_SLIDE_ENEMY_MON_OUT ; $DB - dw AnimationSlideEnemyMonOut + db SE_SLIDE_ENEMY_MON_OFF ; $DB + dw AnimationSlideEnemyMonOff db SE_SHAKE_BACK_AND_FORTH ; $DA dw AnimationShakeBackAndForth db SE_SUBSTITUTE_MON ; $D9 @@ -1073,13 +1067,13 @@ SpecialEffectPointers: ; 790da (1e:50da) dw AnimationWavyScreen db $FF -AnimationDelay10: ; 79150 (1e:5150) +AnimationDelay10: ld c,10 jp DelayFrames ; calls a function with the turn flipped from player to enemy or vice versa ; input - hl - address of function to call -CallWithTurnFlipped: ; 79155 (1e:5155) +CallWithTurnFlipped: ld a,[H_WHOSETURN] push af xor a,1 @@ -1093,9 +1087,9 @@ CallWithTurnFlipped: ; 79155 (1e:5155) ret ; flashes the screen for an extended period (48 frames) -AnimationFlashScreenLong: ; 79165 (1e:5165) +AnimationFlashScreenLong: ld a,3 ; cycle through the palettes 3 times - ld [wd08a],a + ld [wFlashScreenLongCounter],a ld a,[wOnSGB] ; running on SGB? and a ld hl,FlashScreenLongMonochrome @@ -1111,15 +1105,15 @@ AnimationFlashScreenLong: ; 79165 (1e:5165) call FlashScreenLongDelay jr .innerLoop .endOfPalettes - ld a,[wd08a] + ld a,[wFlashScreenLongCounter] dec a - ld [wd08a],a + ld [wFlashScreenLongCounter],a pop hl jr nz,.loop ret ; BG palettes -FlashScreenLongMonochrome: ; 7918e (1e:518e) +FlashScreenLongMonochrome: db %11111001 ; 3, 3, 2, 1 db %11111110 ; 3, 3, 3, 2 db %11111111 ; 3, 3, 3, 3 @@ -1135,7 +1129,7 @@ FlashScreenLongMonochrome: ; 7918e (1e:518e) db $01 ; terminator ; BG palettes -FlashScreenLongSGB: ; 7919b (1e:519b) +FlashScreenLongSGB: db %11111000 ; 3, 3, 2, 0 db %11111100 ; 3, 3, 3, 0 db %11111111 ; 3, 3, 3, 3 @@ -1152,9 +1146,9 @@ FlashScreenLongSGB: ; 7919b (1e:519b) ; causes a delay of 2 frames for the first cycle ; causes a delay of 1 frame for the second and third cycles -FlashScreenLongDelay: ; 791a8 (1e:51a8) - ld a,[wd08a] - cp a,4 ; never true since [wd08a] starts at 3 +FlashScreenLongDelay: + ld a,[wFlashScreenLongCounter] + cp a,4 ; never true since [wFlashScreenLongCounter] starts at 3 ld c,4 jr z,.delayFrames cp a,3 @@ -1165,7 +1159,7 @@ FlashScreenLongDelay: ; 791a8 (1e:51a8) .delayFrames jp DelayFrames -AnimationFlashScreen: ; 791be (1e:51be) +AnimationFlashScreen: ld a,[rBGP] push af ; save initial palette ld a,%00011011 ; 0, 1, 2, 3 (inverted colors) @@ -1180,235 +1174,250 @@ AnimationFlashScreen: ; 791be (1e:51be) ld [rBGP],a ; restore initial palette ret -AnimationDarkScreenPalette: ; 791d6 (1e:51d6) +AnimationDarkScreenPalette: ; Changes the screen's palette to a dark palette. - ld bc, $6f6f - jr Func_791fc + lb bc, $6f, $6f + jr SetAnimationBGPalette -AnimationDarkenMonPalette: ; 791db (1e:51db) +AnimationDarkenMonPalette: ; Darkens the mon sprite's palette. - ld bc, $f9f4 - jr Func_791fc + lb bc, $f9, $f4 + jr SetAnimationBGPalette -Func_791e0: ; 791e0 (1e:51e0) - ld bc, $fef8 - jr Func_791fc +AnimationUnusedPalette1: + lb bc, $fe, $f8 + jr SetAnimationBGPalette -Func_791e5: ; 791e5 (1e:51e5) - ld bc, $ffff - jr Func_791fc +AnimationUnusedPalette2: + lb bc, $ff, $ff + jr SetAnimationBGPalette -AnimationResetScreenPalette: ; 791ea (1e:51ea) +AnimationResetScreenPalette: ; Restores the screen's palette to the normal palette. - ld bc, $e4e4 - jr Func_791fc + lb bc, $e4, $e4 + jr SetAnimationBGPalette -Func_791ef: ; 791ef (1e:51ef) - ld bc, $0000 - jr Func_791fc +AnimationUnusedPalette3: + lb bc, $00, $00 + jr SetAnimationBGPalette -AnimationLightScreenPalette: ; 791f4 (1e:51f4) +AnimationLightScreenPalette: ; Changes the screen to use a palette with light colors. - ld bc, $9090 - jr Func_791fc + lb bc, $90, $90 + jr SetAnimationBGPalette -Func_791f9: ; 791f9 (1e:51f9) - ld bc, $4040 +AnimationUnusedPalette4: + lb bc, $40, $40 -Func_791fc: ; 791fc (1e:51fc) +SetAnimationBGPalette: ld a, [wOnSGB] and a ld a, b - jr z, .asm_79204 + jr z, .next ld a, c -.asm_79204 - ld [rBGP], a ; $ff47 +.next + ld [rBGP], a ret ld b, $5 -AnimationShakeScreenVertically: ; 79209 (1e:5209) - predef_jump Func_480ff +AnimationShakeScreenVertically: + predef_jump PredefShakeScreenVertically -AnimationShakeScreen: ; 7920e (1e:520e) +AnimationShakeScreen: ; Shakes the screen for a while. Used in Earthquake/Fissure/etc. animations. ld b, $8 -AnimationShakeScreenHorizontallyFast: ; 79210 (1e:5210) - predef_jump Func_48125 +AnimationShakeScreenHorizontallyFast: + predef_jump PredefShakeScreenHorizontally -AnimationWaterDropletsEverywhere: ; 79215 (1e:5215) +AnimationWaterDropletsEverywhere: ; Draws water droplets all over the screen and makes them ; scroll. It's hard to describe, but it's the main animation ; in Surf/Mist/Toxic. xor a - ld [wd09f], a + ld [wWhichBattleAnimTileset], a call LoadAnimationTileset - ld d, $20 - ld a, $f0 - ld [W_BASECOORDX], a ; wd081 + ld d, 32 + ld a, -16 + ld [wBaseCoordX], a ld a, $71 - ld [wd09f], a -.asm_79228 - ld a, $10 - ld [W_BASECOORDY], a ; wd082 - ld a, $0 - ld [wd08a], a - call Func_79246 - ld a, $18 - ld [W_BASECOORDY], a ; wd082 - ld a, $20 - ld [wd08a], a - call Func_79246 + ld [wDropletTile], a +.loop + ld a, 16 + ld [wBaseCoordY], a + ld a, 0 + ld [wUnusedD08A], a + call _AnimationWaterDroplets + ld a, 24 + ld [wBaseCoordY], a + ld a, 32 + ld [wUnusedD08A], a + call _AnimationWaterDroplets dec d - jr nz, .asm_79228 + jr nz, .loop ret -Func_79246: ; 79246 (1e:5246) +_AnimationWaterDroplets: ld hl, wOAMBuffer -.asm_79249 - ld a, [W_BASECOORDY] ; wd082 - ld [hli], a - ld a, [W_BASECOORDX] ; wd081 - add $1b - ld [W_BASECOORDX], a ; wd081 - ld [hli], a - ld a, [wd09f] - ld [hli], a +.loop + ld a, [wBaseCoordY] + ld [hli], a ; Y + ld a, [wBaseCoordX] + add 27 + ld [wBaseCoordX], a + ld [hli], a ; X + ld a, [wDropletTile] + ld [hli], a ; tile xor a - ld [hli], a - ld a, [W_BASECOORDX] ; wd081 - cp $90 - jr c, .asm_79249 - sub $a8 - ld [W_BASECOORDX], a ; wd081 - ld a, [W_BASECOORDY] ; wd082 - add $10 - ld [W_BASECOORDY], a ; wd082 - cp $70 - jr c, .asm_79249 + ld [hli], a ; attribute + ld a, [wBaseCoordX] + cp 144 + jr c, .loop + sub 168 + ld [wBaseCoordX], a + ld a, [wBaseCoordY] + add 16 + ld [wBaseCoordY], a + cp 112 + jr c, .loop call AnimationCleanOAM jp DelayFrame -AnimationSlideMonUp: ; 7927a (1e:527a) +AnimationSlideMonUp: ; Slides the mon's sprite upwards. - ld c, $7 + ld c, 7 ld a, [H_WHOSETURN] and a - ld hl, wTileMap + $79 - ld de, wTileMap + $65 + coord hl, 1, 6 + coord de, 1, 5 ld a, $30 - jr z, .asm_79291 - ld hl, wTileMap + $20 - ld de, wTileMap + $c + jr z, .next + coord hl, 12, 1 + coord de, 12, 0 ld a, $ff -.asm_79291 - ld [wd09f], a - jp Func_792bf +.next + ld [wSlideMonUpBottomRowLeftTile], a + jp _AnimationSlideMonUp -AnimationSlideMonDown: ; 79297 (1e:5297) +AnimationSlideMonDown: ; Slides the mon's sprite down out of the screen. xor a call GetTileIDList -.asm_7929b +.loop call GetMonSpriteTileMapPointerFromRowCount push bc push de - call Func_79aae + call CopyPicTiles call Delay3 call AnimationHideMonPic pop de pop bc dec b - jr nz, .asm_7929b + jr nz, .loop ret -AnimationSlideMonOut: ; 792af (1e:52af) -; Slides the mon's sprite out of the screen horizontally. - ld e, $8 - ld a, $3 - ld [W_SUBANIMTRANSFORM], a ; W_SUBANIMTRANSFORM - jp Func_795f8 +AnimationSlideMonOff: +; Slides the mon's sprite off the screen horizontally. + ld e, 8 + ld a, 3 + ld [wSlideMonDelay], a + jp _AnimationSlideMonOff -AnimationSlideEnemyMonOut: ; 792b9 (1e:52b9) -; Slides the enemy mon out of the screen horizontally. - ld hl, AnimationSlideMonOut ; $52af +AnimationSlideEnemyMonOff: +; Slides the enemy mon off the screen horizontally. + ld hl, AnimationSlideMonOff jp CallWithTurnFlipped -Func_792bf: ; 792bf (1e:52bf) +_AnimationSlideMonUp: push de push hl push bc - ld b, $6 -.asm_792c4 + +; In each iteration, slide up all rows but the top one (which is overwritten). + ld b, 6 +.slideLoop push bc push de push hl - ld bc, $0007 + ld bc, 7 call CopyData +; Note that de and hl are popped in the same order they are pushed, swapping +; their values. When CopyData is called, hl points to a tile 1 row below +; the one de points to. To maintain this relationship, after swapping, we add 2 +; rows to hl so that it is 1 row below again. pop de pop hl - ld bc, $0028 + ld bc, SCREEN_WIDTH * 2 add hl, bc pop bc dec b - jr nz, .asm_792c4 + jr nz, .slideLoop + +; Fill in the bottom row of the mon pic with the next row's tile IDs. ld a, [H_WHOSETURN] and a - ld hl, wTileMap + $dd - jr z, .asm_792e2 - ld hl, wTileMap + $84 -.asm_792e2 - ld a, [wd09f] + coord hl, 1, 11 + jr z, .next + coord hl, 12, 6 +.next + ld a, [wSlideMonUpBottomRowLeftTile] inc a - ld [wd09f], a - ld c, $7 -.asm_792eb + ld [wSlideMonUpBottomRowLeftTile], a + ld c, 7 +.fillBottomRowLoop ld [hli], a - add $7 + add 7 dec c - jr nz, .asm_792eb - ld c, $2 + jr nz, .fillBottomRowLoop + + ld c, 2 call DelayFrames pop bc pop hl pop de dec c - jr nz, Func_792bf + jr nz, _AnimationSlideMonUp ret -Func_792fd: ; 792fd (1e:52fd) +ShakeEnemyHUD_WritePlayerMonPicOAM: +; Writes the OAM entries for a copy of the player mon's pic in OAM. +; The top 5 rows are reproduced in OAM, although only 2 are actually needed. ld a, $10 - ld [W_BASECOORDX], a + ld [wBaseCoordX], a ld a, $30 - ld [W_BASECOORDY], a + ld [wBaseCoordY], a ld hl, wOAMBuffer - ld d, $0 - ld c, $7 -.asm_7930e - ld a, [W_BASECOORDY] + ld d, 0 + ld c, 7 +.loop + ld a, [wBaseCoordY] ld e, a - ld b, $5 -.asm_79314 - call Func_79329 + ld b, 5 +.innerLoop + call BattleAnimWriteOAMEntry inc d dec b - jr nz, .asm_79314 + jr nz, .innerLoop dec c ret z inc d inc d - ld a, [W_BASECOORDX] - add $8 - ld [W_BASECOORDX], a - jr .asm_7930e + ld a, [wBaseCoordX] + add 8 + ld [wBaseCoordX], a + jr .loop -Func_79329: ; 79329 (1e:5329) +BattleAnimWriteOAMEntry: +; Y coordinate = e (increased by 8 each call, before the write to OAM) +; X coordinate = [wBaseCoordX] +; tile = d +; attributes = 0 ld a, e - add $8 + add 8 ld e, a ld [hli], a - ld a, [W_BASECOORDX] ; wd081 + ld a, [wBaseCoordX] ld [hli], a ld a, d ld [hli], a @@ -1416,21 +1425,22 @@ Func_79329: ; 79329 (1e:5329) ld [hli], a ret -AdjustOAMBlockXPos: ; 79337 (1e:5337) +AdjustOAMBlockXPos: ld l, e ld h, d -AdjustOAMBlockXPos2: ; 79339 (1e:5339) - ld de, $4 +AdjustOAMBlockXPos2: + ld de, 4 .loop - ld a, [wd08a] + ld a, [wCoordAdjustmentAmount] ld b, a ld a, [hl] add b - cp $a8 + cp 168 jr c, .skipPuttingEntryOffScreen +; put off-screen if X >= 168 dec hl - ld a, $a0 + ld a, 160 ld [hli], a .skipPuttingEntryOffScreen ld [hl], a @@ -1439,21 +1449,21 @@ AdjustOAMBlockXPos2: ; 79339 (1e:5339) jr nz, .loop ret -AdjustOAMBlockYPos: ; 79350 (1e:5350) +AdjustOAMBlockYPos: ld l, e ld h, d -AdjustOAMBlockYPos2: ; 79352 (1e:5352) - ld de, $4 +AdjustOAMBlockYPos2: + ld de, 4 .loop - ld a, [wd08a] + ld a, [wCoordAdjustmentAmount] ld b, a ld a, [hl] add b - cp $70 + cp 112 jr c, .skipSettingPreviousEntrysAttribute dec hl - ld a, $a0 ; bug, sets previous OAM entry's attribute + ld a, 160 ; bug, sets previous OAM entry's attribute ld [hli], a .skipSettingPreviousEntrysAttribute ld [hl], a @@ -1462,70 +1472,70 @@ AdjustOAMBlockYPos2: ; 79352 (1e:5352) jr nz, .loop ret -AnimationBlinkEnemyMon: ; 79369 (1e:5369) +AnimationBlinkEnemyMon: ; Make the enemy mon's sprite blink on and off for a second or two - ld hl, AnimationBlinkMon ; $536f + ld hl, AnimationBlinkMon jp CallWithTurnFlipped -AnimationBlinkMon: ; 7936f (1e:536f) +AnimationBlinkMon: ; Make the mon's sprite blink on and off for a second or two. push af - ld c, $6 -.asm_79372 + ld c, 6 +.loop push bc call AnimationHideMonPic - ld c, $5 + ld c, 5 call DelayFrames call AnimationShowMonPic - ld c, $5 + ld c, 5 call DelayFrames pop bc dec c - jr nz, .asm_79372 + jr nz, .loop pop af ret -AnimationFlashMonPic: ; 79389 (1e:5389) +AnimationFlashMonPic: ; Flashes the mon's sprite on and off ld a, [wBattleMonSpecies] - ld [wHPBarMaxHP + 1], a + ld [wChangeMonPicPlayerTurnSpecies], a ld a, [wEnemyMonSpecies] - ld [wHPBarMaxHP], a - jp Func_79793 + ld [wChangeMonPicEnemyTurnSpecies], a + jp ChangeMonPic -AnimationFlashEnemyMonPic: ; 79398 (1e:5398) +AnimationFlashEnemyMonPic: ; Flashes the enemy mon's sprite on and off ld hl, AnimationFlashMonPic jp CallWithTurnFlipped -AnimationShowMonPic: ; 7939e (1e:539e) +AnimationShowMonPic: xor a call GetTileIDList call GetMonSpriteTileMapPointerFromRowCount - call Func_79aae + call CopyPicTiles jp Delay3 -AnimationShowEnemyMonPic: ; 793ab (1e:53ab) +AnimationShowEnemyMonPic: ; Shows the emenmy mon's front sprite. Used in animations like Seismic Toss ; to make the mon's sprite reappear after disappears offscreen. ld hl, AnimationShowMonPic jp CallWithTurnFlipped -AnimationShakeBackAndForth: ; 793b1 (1e:53b1) +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] and a - ld hl, wTileMap + $64 - ld de, wTileMap + $66 - jr z, .asm_793c2 - ld hl, wTileMap + $b - ld de, wTileMap + $d + coord hl, 0, 5 + coord de, 2, 5 + jr z, .next + coord hl, 11, 0 + coord de, 13, 0 -.asm_793c2 +.next xor a ld c, $10 -.asm_793c5 +.loop push af push bc push de @@ -1537,113 +1547,113 @@ AnimationShakeBackAndForth: ; 793b1 (1e:53b1) push hl call GetTileIDList pop hl - call Func_79aae + call CopyPicTiles call Delay3 pop hl - ld bc, $0709 + lb bc, 7, 9 call ClearScreenArea pop af call GetTileIDList pop hl - call Func_79aae + call CopyPicTiles call Delay3 pop hl - ld bc, $0709 + lb bc, 7, 9 call ClearScreenArea pop hl pop de pop bc pop af dec c - jr nz, .asm_793c5 + jr nz, .loop ret -AnimationMoveMonHorizontally: ; 793f9 (1e:53f9) +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] ; $fff3 + ld a, [H_WHOSETURN] and a - hlCoord 2, 5 - jr z, .asm_79407 - hlCoord 11, 0 -.asm_79407 + coord hl, 2, 5 + jr z, .next + coord hl, 11, 0 +.next xor a push hl call GetTileIDList pop hl - call Func_79aae - ld c, $3 + call CopyPicTiles + ld c, 3 jp DelayFrames -AnimationResetMonPosition: ; 79415 (1e:5415) +AnimationResetMonPosition: ; Resets the mon's sprites to be located at the normal coordinates. - ld a, [H_WHOSETURN] ; $fff3 + ld a, [H_WHOSETURN] and a - ld a, $66 - jr z, .asm_7941e - ld a, $b -.asm_7941e - call Func_7980c + ld a, 5 * SCREEN_WIDTH + 2 + jr z, .next + ld a, 11 +.next + call ClearMonPicFromTileMap jp AnimationShowMonPic -AnimationSpiralBallsInward: ; 79424 (1e:5424) -; Creates an effect that looks like energy balls sprialing into the +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] ; $fff3 + ld a, [H_WHOSETURN] and a - jr z, .asm_79435 - ld a, $d8 - ld [wd08a], a - ld a, $50 - ld [W_SUBANIMTRANSFORM], a ; W_SUBANIMTRANSFORM - jr .asm_7943c -.asm_79435 + jr z, .playerTurn + ld a, -40 + ld [wSpiralBallsBaseY], a + ld a, 80 + ld [wSpiralBallsBaseX], a + jr .next +.playerTurn xor a - ld [wd08a], a - ld [W_SUBANIMTRANSFORM], a ; W_SUBANIMTRANSFORM -.asm_7943c - ld d, $7a - ld c, $3 + ld [wSpiralBallsBaseY], a + ld [wSpiralBallsBaseX], a +.next + ld d, $7a ; ball tile + ld c, 3 ; number of balls xor a - call Func_797e8 - ld hl, SpiralBallAnimationCoordinates ; $5476 -.asm_79447 + call InitMultipleObjectsOAM + ld hl, SpiralBallAnimationCoordinates +.loop push hl - ld c, $3 + ld c, 3 ld de, wOAMBuffer -.asm_7944d +.innerLoop ld a, [hl] cp $ff - jr z, .asm_7946f - ld a, [wd08a] + jr z, .done + ld a, [wSpiralBallsBaseY] add [hl] - ld [de], a + ld [de], a ; Y inc de inc hl - ld a, [W_SUBANIMTRANSFORM] ; W_SUBANIMTRANSFORM + ld a, [wSpiralBallsBaseX] add [hl] - ld [de], a + ld [de], a ; X inc hl inc de inc de inc de dec c - jr nz, .asm_7944d - ld c, $5 + jr nz, .innerLoop + ld c, 5 call DelayFrames pop hl inc hl inc hl - jr .asm_79447 -.asm_7946f + jr .loop +.done pop hl call AnimationCleanOAM jp AnimationFlashScreen -SpiralBallAnimationCoordinates: ; 79476 (1e:5476) +SpiralBallAnimationCoordinates: ; y, x pairs -; This is the sequence of screen coordinates that the spiraling +; This is the sequence of screen coordinates that the spiralling ; balls are positioned at. db $38, $28 db $40, $18 @@ -1668,131 +1678,132 @@ SpiralBallAnimationCoordinates: ; 79476 (1e:5476) db $50, $28 db $FF ; list terminator -AnimationSquishMonPic: ; 794a1 (1e:54a1) +AnimationSquishMonPic: ; Squishes the mon's sprite horizontally making it ; disappear. Used by Teleport/Sky Attack animations. - ld c, $4 -.asm_794a3 + ld c, 4 +.loop push bc - ld a, [H_WHOSETURN] ; $fff3 + ld a, [H_WHOSETURN] and a - jr z, .asm_794b1 - hlCoord 16, 0 - deCoord 14, 0 - jr .asm_794b7 -.asm_794b1 - hlCoord 5, 5 - deCoord 3, 5 -.asm_794b7 + jr z, .playerTurn + coord hl, 16, 0 + coord de, 14, 0 + jr .next +.playerTurn + coord hl, 5, 5 + coord de, 3, 5 +.next push de - xor a - ld [wd09f], a - call Func_794d4 + xor a ; left + ld [wSquishMonCurrentDirection], a + call _AnimationSquishMonPic pop hl - ld a, $1 - ld [wd09f], a - call Func_794d4 + ld a, 1 ; right + ld [wSquishMonCurrentDirection], a + call _AnimationSquishMonPic pop bc dec c - jr nz, .asm_794a3 + jr nz, .loop call AnimationHideMonPic - ld c, $2 + ld c, 2 jp DelayFrame -Func_794d4: ; 794d4 (1e:54d4) - ld c, $7 -.asm_794d6 +_AnimationSquishMonPic: + ld c, 7 +.loop push bc push hl - ld c, $3 - ld a, [wd09f] - cp $0 - jr nz, .asm_794e7 - call Func_7985b + ld c, 3 + ld a, [wSquishMonCurrentDirection] + cp 0 + jr nz, .right + call AnimCopyRowLeft dec hl - jr .asm_794eb -.asm_794e7 - call Func_79862 + jr .next +.right + call AnimCopyRowRight inc hl -.asm_794eb - ld [hl], $7f +.next + ld [hl], " " pop hl - ld de, $14 + ld de, SCREEN_WIDTH add hl, de pop bc dec c - jr nz, .asm_794d6 + jr nz, .loop jp Delay3 -AnimationShootBallsUpward: ; 794f9 (1e:54f9) +AnimationShootBallsUpward: ; Shoots one pillar of "energy" balls upwards. Used in Teleport/Sky Attack ; animations. - ld a, [H_WHOSETURN] ; $fff3 + ld a, [H_WHOSETURN] and a - jr z, .asm_79503 - ld bc, $80 - jr .asm_79506 -.asm_79503 - ld bc, $3028 -.asm_79506 + jr z, .playerTurn + lb bc, 0, 16 * 8 + jr .next +.playerTurn + lb bc, 6 * 8, 5 * 8 +.next ld a, b - ld [W_BASECOORDY], a ; wd082 + ld [wBaseCoordY], a ld a, c - ld [W_BASECOORDX], a ; wd081 - ld bc, $501 - call Func_79517 + ld [wBaseCoordX], a + lb bc, 5, 1 + call _AnimationShootBallsUpward jp AnimationCleanOAM -Func_79517: ; 79517 (1e:5517) +_AnimationShootBallsUpward: push bc xor a - ld [wd09f], a + ld [wWhichBattleAnimTileset], a call LoadAnimationTileset pop bc - ld d, $7a + ld d, $7a ; ball tile ld hl, wOAMBuffer push bc - ld a, [W_BASECOORDY] ; wd082 + ld a, [wBaseCoordY] ld e, a -.asm_7952a - call Func_79329 +.initOAMLoop + call BattleAnimWriteOAMEntry dec b - jr nz, .asm_7952a + jr nz, .initOAMLoop call DelayFrame pop bc ld a, b - ld [wd08a], a -.asm_79538 + ld [wNumShootingBalls], a +.loop push bc ld hl, wOAMBuffer -.asm_7953c - ld a, [W_BASECOORDY] ; wd082 - add $8 +.innerLoop + ld a, [wBaseCoordY] + add 8 ld e, a ld a, [hl] - cp e - jr z, .asm_7954b - add $fc + cp e ; has the ball reached the top? + jr z, .reachedTop + add -4 ; ball hasn't reached the top. move it up 4 pixels ld [hl], a - jr .asm_79554 -.asm_7954b - ld [hl], $0 - ld a, [wd08a] + jr .next +.reachedTop +; remove the ball once it has reached the top + ld [hl], 0 ; put it off-screen + ld a, [wNumShootingBalls] dec a - ld [wd08a], a -.asm_79554 - ld de, $4 - add hl, de + ld [wNumShootingBalls], a +.next + ld de, 4 + add hl, de ; next OAM entry dec b - jr nz, .asm_7953c + jr nz, .innerLoop call DelayFrames pop bc - ld a, [wd08a] + ld a, [wNumShootingBalls] and a - jr nz, .asm_79538 + jr nz, .loop ret -AnimationShootManyBallsUpward: ; 79566 (1e:5566) +AnimationShootManyBallsUpward: ; Shoots several pillars of "energy" balls upward. ld a, [H_WHOSETURN] and a @@ -1802,64 +1813,65 @@ AnimationShootManyBallsUpward: ; 79566 (1e:5566) ld hl, UpwardBallsAnimXCoordinatesEnemyTurn ld a, $28 ; y coordinate for "energy" ball pillar .player - ld [wTrainerSpriteOffset], a + ld [wSavedY], a .loop - ld a, [wTrainerSpriteOffset] - ld [W_BASECOORDY], a + ld a, [wSavedY] + ld [wBaseCoordY], a ld a, [hli] cp $ff jp z, AnimationCleanOAM - ld [W_BASECOORDX], a - ld bc, $0401 + ld [wBaseCoordX], a + lb bc, 4, 1 push hl - call Func_79517 + call _AnimationShootBallsUpward pop hl jr .loop -UpwardBallsAnimXCoordinatesPlayerTurn: ; 79591 (1e:5591) +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 -UpwardBallsAnimXCoordinatesEnemyTurn: ; 79598 (1e:5598) +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 -AnimationMinimizeMon: ; 7959f (1e:559f) +AnimationMinimizeMon: ; Changes the mon's sprite to a mini black sprite. Used by the ; Minimize animation. ld hl, wTempPic push hl xor a - ld bc, $310 + ld bc, 7 * 7 * $10 call FillMemory pop hl ld de, $194 add hl, de - ld de, MinimizedMonSprite ; $55c4 - ld c, $5 -.asm_795b4 + ld de, MinimizedMonSprite + ld c, MinimizedMonSpriteEnd - MinimizedMonSprite +.loop ld a, [de] ld [hli], a ld [hli], a inc de dec c - jr nz, .asm_795b4 - call Func_79652 + jr nz, .loop + call CopyTempPicToMonPic call Delay3 jp AnimationShowMonPic -MinimizedMonSprite: ; 795c4 (1e:55c4) +MinimizedMonSprite: INCBIN "gfx/minimized_mon_sprite.1bpp" +MinimizedMonSpriteEnd: -AnimationSlideMonDownAndHide: ; 795c9 (1e:55c9) +AnimationSlideMonDownAndHide: ; Slides the mon's sprite down and disappears. Used in Acid Armor. ld a, $1 ld c, $2 -.asm_795cd +.loop push bc push af call AnimationHideMonPic @@ -1867,168 +1879,182 @@ AnimationSlideMonDownAndHide: ; 795c9 (1e:55c9) push af call GetTileIDList call GetMonSpriteTileMapPointerFromRowCount - call Func_79aae - ld c, $8 + call CopyPicTiles + ld c, 8 call DelayFrames pop af inc a pop bc dec c - jr nz, .asm_795cd + jr nz, .loop call AnimationHideMonPic ld hl, wTempPic ld bc, $0310 xor a call FillMemory - jp Func_79652 + jp CopyTempPicToMonPic -Func_795f8: ; 795f8 (1e:55f8) - ld a, [H_WHOSETURN] ; $fff3 +_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] and a - jr z, .asm_79602 - hlCoord 12, 0 - jr .asm_79605 -.asm_79602 - hlCoord 0, 5 -.asm_79605 - ld d, $8 -.asm_79607 + jr z, .playerTurn + coord hl, 12, 0 + jr .next +.playerTurn + coord hl, 0, 5 +.next + ld d, 8 ; d's value is unused +.slideLoop ; iterates once for each time the pic slides by one tile push hl - ld b, $7 -.asm_7960a - ld c, $8 -.asm_7960c - ld a, [H_WHOSETURN] ; $fff3 + ld b, 7 +.rowLoop ; iterates once for each row + ld c, 8 +.tileLoop ; iterates once for each tile in the row + ld a, [H_WHOSETURN] and a - jr z, .asm_79616 - call Func_7963c - jr .asm_79619 -.asm_79616 - call Func_79633 -.asm_79619 + jr z, .playerTurn2 + call .EnemyNextTile + jr .next2 +.playerTurn2 + call .PlayerNextTile +.next2 ld [hli], a dec c - jr nz, .asm_7960c + jr nz, .tileLoop push de - ld de, $c + ld de, SCREEN_WIDTH - 8 add hl, de pop de dec b - jr nz, .asm_7960a - ld a, [W_SUBANIMTRANSFORM] ; W_SUBANIMTRANSFORM + jr nz, .rowLoop + ld a, [wSlideMonDelay] ld c, a call DelayFrames pop hl dec d dec e - jr nz, .asm_79607 + jr nz, .slideLoop ret -Func_79633: ; 79633 (1e:5633) +; Since mon pic tile numbers go from top to bottom, left to right in order, +; adding the height of the mon pic in tiles to a tile number gives the tile +; number of the tile one column to the right (and thus subtracting the height +; gives the reverse). If the next tile would be past the edge of the pic, the 2 +; functions below catch it by checking if the tile number is within the valid +; range and if not, replacing it with a blank tile. + +.PlayerNextTile ld a, [hl] - add $7 + add 7 +; This is a bug. The lower right corner tile of the mon back pic is blanked +; while the mon is sliding off the screen. It should compare with the max tile +; plus one instead. cp $61 ret c - ld a, $7f + ld a, " " ret -Func_7963c: ; 7963c (1e:563c) +.EnemyNextTile ld a, [hl] - sub $7 + sub 7 +; This has the same problem as above, but it has no visible effect because +; the lower right tile is in the first column to slide off the screen. cp $30 ret c - ld a, $7f + ld a, " " ret -AnimationSlideMonHalfLeft: ; 79645 (1e:5645) -; Slides the mon's sprite halfway out of the screen. It's used in Softboiled. - ld e, $4 - ld a, $4 - ld [W_SUBANIMTRANSFORM], a - call Func_795f8 +AnimationSlideMonHalfOff: +; Slides the mon's sprite halfway off the screen. It's used in Softboiled. + ld e, 4 + ld a, 4 + ld [wSlideMonDelay], a + call _AnimationSlideMonOff jp Delay3 -Func_79652: ; 79652 (1e:5652) - ld a, [H_WHOSETURN] ; $fff3 +CopyTempPicToMonPic: + ld a, [H_WHOSETURN] and a - ld hl, vBackPic - jr z, .asm_7965d - ld hl, vFrontPic -.asm_7965d + ld hl, vBackPic ; player turn + jr z, .next + ld hl, vFrontPic ; enemy turn +.next ld de, wTempPic ld bc, 7 * 7 jp CopyVideoData -AnimationWavyScreen: ; 79666 (1e:5666) +AnimationWavyScreen: ; used in Psywave/Psychic etc. ld hl, vBGMap0 - call Func_79e0d + call BattleAnimCopyTileMapToVRAM call Delay3 xor a ld [H_AUTOBGTRANSFERENABLED], a - ld a, $90 + ld a, SCREEN_HEIGHT_PIXELS ld [hWY], a - ld d, $80 - ld e, $8f + ld d, $80 ; terminator + ld e, SCREEN_HEIGHT_PIXELS - 1 ld c, $ff ld hl, WavyScreenLineOffsets -.asm_7967f +.loop push hl -.asm_79680 - call Func_796ae - ld a, [$ff44] - cp e - jr nz, .asm_79680 +.innerLoop + call WavyScreen_SetSCX + ld a, [rLY] + cp e ; is it the last visible line in the frame? + jr nz, .innerLoop ; keep going if not pop hl inc hl ld a, [hl] - cp d - jr nz, .asm_79691 - ld hl, WavyScreenLineOffsets -.asm_79691 + cp d ; have we reached the end? + jr nz, .next + ld hl, WavyScreenLineOffsets ; go back to the beginning if so +.next dec c - jr nz, .asm_7967f + jr nz, .loop xor a ld [hWY], a call SaveScreenTilesToBuffer2 call ClearScreen - ld a, $1 + ld a, 1 ld [H_AUTOBGTRANSFERENABLED], a call Delay3 call LoadScreenTilesFromBuffer2 ld hl, vBGMap1 - call Func_79e0d + call BattleAnimCopyTileMapToVRAM ret -Func_796ae: ; 796ae (1e:56ae) - ld a, [$ff41] - and $3 - jr nz, Func_796ae +WavyScreen_SetSCX: + ld a, [rSTAT] + and $3 ; is it H-blank? + jr nz, WavyScreen_SetSCX ; wait until it's H-blank ld a, [hl] - ld [$ff43], a + ld [rSCX], a inc hl ld a, [hl] - cp d + cp d ; have we reached the end? ret nz - ld hl, WavyScreenLineOffsets + ld hl, WavyScreenLineOffsets ; go back to the beginning if so ret -WavyScreenLineOffsets: ; 796bf (1e:56bf) +WavyScreenLineOffsets: ; Sequence of horizontal line pixel offsets for the wavy screen animation. ; This sequence vaguely resembles a sine wave. db 0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 2, 2, 1, 1, 1 db 0, 0, 0, 0, 0, -1, -1, -1, -2, -2, -2, -2, -2, -1, -1, -1 db $80 ; terminator -AnimationSubstitute: ; 796e0 (1e:56e0) +AnimationSubstitute: ; Changes the pokemon's sprite to the mini sprite ld hl, wTempPic xor a ld bc, $0310 call FillMemory - ld a, [$fff3] + ld a, [H_WHOSETURN] and a - jr z, .asm_79715 ; 0x796ed $26 + jr z, .playerTurn ld hl, SlowbroSprite ; facing down sprite ld de, wTempPic + $120 call CopySlowbroSpriteData @@ -2041,8 +2067,8 @@ AnimationSubstitute: ; 796e0 (1e:56e0) ld hl, SlowbroSprite + $30 ld de, wTempPic + $120 + $10 + $70 call CopySlowbroSpriteData - jr .asm_79739 -.asm_79715 + jr .next +.playerTurn ld hl, SlowbroSprite + $40 ; facing up sprite ld de, wTempPic + $120 + $70 call CopySlowbroSpriteData @@ -2055,32 +2081,33 @@ AnimationSubstitute: ; 796e0 (1e:56e0) ld hl, SlowbroSprite + $70 ld de, wTempPic + $120 + $f0 call CopySlowbroSpriteData -.asm_79739 - call Func_79652 +.next + call CopyTempPicToMonPic jp AnimationShowMonPic -CopySlowbroSpriteData: ; 7973f (1e:573f) +CopySlowbroSpriteData: ld bc, $0010 ld a, BANK(SlowbroSprite) jp FarCopyData2 -Func_79747: ; 79747 (1e:5747) - ld a, [H_WHOSETURN] ; $fff3 +HideSubstituteShowMonAnim: + ld a, [H_WHOSETURN] and a - ld hl, wccf7 - ld a, [W_PLAYERBATTSTATUS2] ; W_PLAYERBATTSTATUS2 - jr z, .asm_79758 - ld hl, wccf3 - ld a, [W_ENEMYBATTSTATUS2] ; W_ENEMYBATTSTATUS2 -.asm_79758 + ld hl, wPlayerMonMinimized + ld a, [wPlayerBattleStatus2] + jr z, .next1 + ld hl, wEnemyMonMinimized + ld a, [wEnemyBattleStatus2] +.next1 push hl - bit 4, a - jr nz, .asm_79762 +; if the substitute broke, slide it down, else slide it offscreen horizontally + bit HasSubstituteUp, a + jr nz, .substituteStillUp call AnimationSlideMonDown - jr .asm_79765 -.asm_79762 - call AnimationSlideMonOut -.asm_79765 + jr .next2 +.substituteStillUp + call AnimationSlideMonOff +.next2 pop hl ld a, [hl] and a @@ -2088,48 +2115,48 @@ Func_79747: ; 79747 (1e:5747) call AnimationFlashMonPic jp AnimationShowMonPic -Func_79771: ; 79771 (1e:5771) - call AnimationSlideMonOut +ReshowSubstituteAnim: + call AnimationSlideMonOff call AnimationSubstitute jp AnimationShowMonPic -AnimationBoundUpAndDown: ; 7977a (1e:577a) +AnimationBoundUpAndDown: ; Bounces the mon's sprite up and down several times. It is used ; by Splash's animation. - ld c, $5 -.asm_7977c + ld c, 5 +.loop push bc call AnimationSlideMonDown pop bc dec c - jr nz, .asm_7977c ; 0x79782 $f8 + jr nz, .loop jp AnimationShowMonPic -AnimationTransformMon: ; 79787 (1e:5787) +AnimationTransformMon: ; Redraws this mon's sprite as the back/front sprite of the opposing mon. ; Used in Transform. ld a, [wEnemyMonSpecies] - ld [wHPBarMaxHP + 1], a + ld [wChangeMonPicPlayerTurnSpecies], a ld a, [wBattleMonSpecies] - ld [wHPBarMaxHP], a + ld [wChangeMonPicEnemyTurnSpecies], a -Func_79793: ; 79793 (1e:5793) - ld a, [H_WHOSETURN] ; $fff3 +ChangeMonPic: + ld a, [H_WHOSETURN] and a - jr z, .asm_797b0 - ld a, [wHPBarMaxHP] + jr z, .playerTurn + ld a, [wChangeMonPicEnemyTurnSpecies] ld [wcf91], a ld [wd0b5], a xor a - ld [W_SPRITEFLIPPED], a + ld [wSpriteFlipped], a call GetMonHeader - hlCoord 12, 0 + coord hl, 12, 0 call LoadFrontSpriteByMonIndex - jr .asm_797d3 -.asm_797b0 + jr .done +.playerTurn ld a, [wBattleMonSpecies2] push af - ld a, [wHPBarMaxHP + 1] + ld a, [wChangeMonPicPlayerTurnSpecies] ld [wBattleMonSpecies2], a ld [wd0b5], a call GetMonHeader @@ -2137,59 +2164,63 @@ Func_79793: ; 79793 (1e:5793) xor a call GetTileIDList call GetMonSpriteTileMapPointerFromRowCount - call Func_79aae + call CopyPicTiles pop af ld [wBattleMonSpecies2], a -.asm_797d3 - ld b, $1 - jp GoPAL_SET +.done + ld b, SET_PAL_BATTLE + jp RunPaletteCommand -AnimationHideEnemyMonPic: ; 797d8 (1e:57d8) +AnimationHideEnemyMonPic: ; Hides the enemy mon's sprite xor a - ld [H_AUTOBGTRANSFERENABLED], a ; $ffba - ld hl, AnimationHideMonPic ; $5801 + ld [H_AUTOBGTRANSFERENABLED], a + ld hl, AnimationHideMonPic call CallWithTurnFlipped ld a, $1 - ld [H_AUTOBGTRANSFERENABLED], a ; $ffba + ld [H_AUTOBGTRANSFERENABLED], a jp Delay3 -Func_797e8: ; 797e8 (1e:57e8) +InitMultipleObjectsOAM: +; Writes c OAM entries with tile d. +; Sets their Y coordinates to sequential multiples of 8, starting from 0. +; Sets their X coordinates to 0. +; Loads animation tileset a. push bc push de - ld [wd09f], a + ld [wWhichBattleAnimTileset], a call LoadAnimationTileset pop de pop bc xor a ld e, a - ld [W_BASECOORDX], a ; wd081 + ld [wBaseCoordX], a ld hl, wOAMBuffer -.asm_797fa - call Func_79329 +.loop + call BattleAnimWriteOAMEntry dec c - jr nz, .asm_797fa + jr nz, .loop ret -AnimationHideMonPic: ; 79801 (1e:5801) +AnimationHideMonPic: ; Hides the mon's sprite. - ld a, [H_WHOSETURN] ; $fff3 + ld a, [H_WHOSETURN] and a - jr z, .asm_7980a - ld a, $c - jr Func_7980c -.asm_7980a - ld a, $65 + jr z, .playerTurn + ld a, 12 + jr ClearMonPicFromTileMap +.playerTurn + ld a, 5 * SCREEN_WIDTH + 1 -Func_7980c: ; 7980c (1e:580c) +ClearMonPicFromTileMap: push hl push de push bc ld e, a - ld d, $0 - ld hl, wTileMap + ld d, 0 + coord hl, 0, 0 add hl, de - ld bc, $707 + lb bc, 7, 7 call ClearScreenArea pop bc pop de @@ -2199,7 +2230,7 @@ Func_7980c: ; 7980c (1e:580c) ; puts the tile map destination address of a mon sprite in hl, given the row count in b ; The usual row count is 7, but it may be smaller when sliding a mon sprite in/out, ; in order to show only a portion of the mon sprite. -GetMonSpriteTileMapPointerFromRowCount: ; 79820 (1e:5820) +GetMonSpriteTileMapPointerFromRowCount: push de ld a, [H_WHOSETURN] and a @@ -2209,7 +2240,7 @@ GetMonSpriteTileMapPointerFromRowCount: ; 79820 (1e:5820) .enemyTurn ld a, 12 .next - ld hl, wTileMap + coord hl, 0, 0 ld e, a ld d, 0 add hl, de @@ -2232,7 +2263,7 @@ GetMonSpriteTileMapPointerFromRowCount: ; 79820 (1e:5820) ; de = tile ID list pointer ; b = number of rows ; c = number of columns -GetTileIDList: ; 79842 (1e:5842) +GetTileIDList: ld hl, TileIDListPointerTable ld e, a ld d, 0 @@ -2253,29 +2284,32 @@ GetTileIDList: ; 79842 (1e:5842) ld b, a ret -Func_7985b: ; 7985b (1e:585b) +AnimCopyRowLeft: +; copy a row of c tiles 1 tile left ld a, [hld] ld [hli], a inc hl dec c - jr nz, Func_7985b + jr nz, AnimCopyRowLeft ret -Func_79862: ; 79862 (1e:5862) +AnimCopyRowRight: +; copy a row of c tiles 1 tile right ld a, [hli] ld [hld], a dec hl dec c - jr nz, Func_79862 + jr nz, AnimCopyRowRight ret -Func_79869: ; 79869 (1e:5869) +; get the sound of the move id in b +GetMoveSoundB: ld a, b - call Func_7986f + call GetMoveSound ld b, a ret -Func_7986f: ; 7986f (1e:586f) +GetMoveSound: ld hl,MoveSoundTable ld e,a ld d,0 @@ -2298,26 +2332,26 @@ Func_7986f: ; 7986f (1e:586f) call GetCryData ld b,a pop hl - ld a,[wc0f1] + ld a,[wFrequencyModifier] add [hl] - ld [wc0f1],a + ld [wFrequencyModifier],a inc hl - ld a,[wc0f2] + ld a,[wTempoModifier] add [hl] - ld [wc0f2],a + ld [wTempoModifier],a jr .done .NotCryMove ld a,[hli] - ld [wc0f1],a + ld [wFrequencyModifier],a ld a,[hli] - ld [wc0f2],a + ld [wTempoModifier],a .done ld a,b ret -IsCryMove: ; 798ad (1e:58ad) +IsCryMove: ; set carry if the move animation involves playing a monster cry - ld a,[W_ANIMATIONID] + ld a,[wAnimationID] cp a,GROWL jr z,.CryMove cp a,ROAR @@ -2328,201 +2362,206 @@ IsCryMove: ; 798ad (1e:58ad) scf ret -MoveSoundTable: ; 798bc (1e:58bc) - db (SFX_08_4a - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_4c - SFX_Headers_08) / 3,$10,$80 - db (SFX_08_5d - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_4b - SFX_Headers_08) / 3,$01,$80 - db (SFX_08_4d - SFX_Headers_08) / 3,$00,$40 - db (SFX_08_77 - SFX_Headers_08) / 3,$00,$ff - db (SFX_08_4d - SFX_Headers_08) / 3,$10,$60 - db (SFX_08_4d - SFX_Headers_08) / 3,$20,$80 - db (SFX_08_4d - SFX_Headers_08) / 3,$00,$a0 - db (SFX_08_50 - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_4f - SFX_Headers_08) / 3,$20,$40 - db (SFX_08_4f - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_4e - SFX_Headers_08) / 3,$00,$a0 - db (SFX_08_51 - SFX_Headers_08) / 3,$10,$c0 - db (SFX_08_51 - SFX_Headers_08) / 3,$00,$a0 - db (SFX_08_52 - SFX_Headers_08) / 3,$00,$c0 - db (SFX_08_52 - SFX_Headers_08) / 3,$10,$a0 - db (SFX_08_53 - SFX_Headers_08) / 3,$00,$e0 - db (SFX_08_51 - SFX_Headers_08) / 3,$20,$c0 - db (SFX_08_54 - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_62 - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_55 - SFX_Headers_08) / 3,$01,$80 - db (SFX_08_60 - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_57 - SFX_Headers_08) / 3,$f0,$40 - db (SFX_08_5a - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_57 - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_61 - SFX_Headers_08) / 3,$10,$80 - db (SFX_08_5b - SFX_Headers_08) / 3,$01,$a0 - db (SFX_08_58 - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_5e - SFX_Headers_08) / 3,$00,$60 - db (SFX_08_5e - SFX_Headers_08) / 3,$01,$40 - db (SFX_08_5f - SFX_Headers_08) / 3,$00,$a0 - db (SFX_08_5a - SFX_Headers_08) / 3,$10,$a0 - db (SFX_08_60 - SFX_Headers_08) / 3,$00,$c0 - db (SFX_08_54 - SFX_Headers_08) / 3,$10,$60 - db (SFX_08_5a - SFX_Headers_08) / 3,$00,$a0 - db (SFX_08_62 - SFX_Headers_08) / 3,$11,$c0 - db (SFX_08_5a - SFX_Headers_08) / 3,$20,$c0 - db (SFX_08_61 - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_5b - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_5b - SFX_Headers_08) / 3,$20,$c0 - db (SFX_08_59 - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_71 - SFX_Headers_08) / 3,$ff,$40 - db (SFX_08_5e - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_4b - SFX_Headers_08) / 3,$00,$c0 - db (SFX_08_4b - SFX_Headers_08) / 3,$00,$40 - db (SFX_08_75 - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_67 - SFX_Headers_08) / 3,$40,$60 - db (SFX_08_67 - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_67 - SFX_Headers_08) / 3,$ff,$40 - db (SFX_08_6a - SFX_Headers_08) / 3,$80,$c0 - db (SFX_08_59 - SFX_Headers_08) / 3,$10,$a0 - db (SFX_08_59 - SFX_Headers_08) / 3,$21,$e0 - db (SFX_08_69 - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_64 - SFX_Headers_08) / 3,$20,$60 - db (SFX_08_6a - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_6c - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_68 - SFX_Headers_08) / 3,$40,$80 - db (SFX_08_69 - SFX_Headers_08) / 3,$f0,$e0 - db (SFX_08_6d - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_6a - SFX_Headers_08) / 3,$f0,$60 - db (SFX_08_68 - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_76 - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_47 - SFX_Headers_08) / 3,$01,$a0 - db (SFX_08_53 - SFX_Headers_08) / 3,$f0,$20 - db (SFX_08_63 - SFX_Headers_08) / 3,$01,$c0 - db (SFX_08_63 - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_5a - SFX_Headers_08) / 3,$00,$e0 - db (SFX_08_66 - SFX_Headers_08) / 3,$01,$60 - db (SFX_08_66 - SFX_Headers_08) / 3,$20,$40 - db (SFX_08_64 - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_64 - SFX_Headers_08) / 3,$40,$c0 - db (SFX_08_5b - SFX_Headers_08) / 3,$03,$60 - db (SFX_08_65 - SFX_Headers_08) / 3,$11,$e0 - db (SFX_08_52 - SFX_Headers_08) / 3,$20,$e0 - db (SFX_08_6e - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_5c - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_5c - SFX_Headers_08) / 3,$11,$a0 - db (SFX_08_5c - SFX_Headers_08) / 3,$01,$c0 - db (SFX_08_53 - SFX_Headers_08) / 3,$14,$c0 - db (SFX_08_5b - SFX_Headers_08) / 3,$02,$a0 - db (SFX_08_69 - SFX_Headers_08) / 3,$f0,$80 - db (SFX_08_69 - SFX_Headers_08) / 3,$20,$c0 - db (SFX_08_6f - SFX_Headers_08) / 3,$00,$20 - db (SFX_08_6f - SFX_Headers_08) / 3,$20,$80 - db (SFX_08_6e - SFX_Headers_08) / 3,$12,$60 - db (SFX_08_66 - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_54 - SFX_Headers_08) / 3,$01,$e0 - db (SFX_08_69 - SFX_Headers_08) / 3,$0f,$e0 - db (SFX_08_69 - SFX_Headers_08) / 3,$11,$20 - db (SFX_08_50 - SFX_Headers_08) / 3,$10,$40 - db (SFX_08_4f - SFX_Headers_08) / 3,$10,$c0 - db (SFX_08_54 - SFX_Headers_08) / 3,$00,$20 - db (SFX_08_70 - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_75 - SFX_Headers_08) / 3,$11,$18 - db (SFX_08_49 - SFX_Headers_08) / 3,$20,$c0 - db (SFX_08_48 - SFX_Headers_08) / 3,$20,$c0 - db (SFX_08_65 - SFX_Headers_08) / 3,$00,$10 - db (SFX_08_66 - SFX_Headers_08) / 3,$f0,$20 - db (SFX_08_73 - SFX_Headers_08) / 3,$f0,$c0 - db (SFX_08_51 - SFX_Headers_08) / 3,$f0,$e0 - db (SFX_08_49 - SFX_Headers_08) / 3,$f0,$40 - db (SFX_08_71 - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_73 - SFX_Headers_08) / 3,$80,$40 - db (SFX_08_73 - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_54 - SFX_Headers_08) / 3,$11,$20 - db (SFX_08_54 - SFX_Headers_08) / 3,$22,$10 - db (SFX_08_5b - SFX_Headers_08) / 3,$f1,$ff - db (SFX_08_53 - SFX_Headers_08) / 3,$f1,$ff - db (SFX_08_54 - SFX_Headers_08) / 3,$33,$30 - db (SFX_08_72 - SFX_Headers_08) / 3,$40,$c0 - db (SFX_08_4e - SFX_Headers_08) / 3,$20,$20 - db (SFX_08_4e - SFX_Headers_08) / 3,$f0,$10 - db (SFX_08_4f - SFX_Headers_08) / 3,$f8,$10 - db (SFX_08_51 - SFX_Headers_08) / 3,$f0,$10 - db (SFX_08_65 - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_58 - SFX_Headers_08) / 3,$00,$c0 - db (SFX_08_72 - SFX_Headers_08) / 3,$c0,$ff - db (SFX_08_49 - SFX_Headers_08) / 3,$f2,$20 - db (SFX_08_74 - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_74 - SFX_Headers_08) / 3,$00,$40 - db (SFX_08_49 - SFX_Headers_08) / 3,$00,$40 - db (SFX_08_51 - SFX_Headers_08) / 3,$10,$ff - db (SFX_08_6a - SFX_Headers_08) / 3,$20,$20 - db (SFX_08_72 - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_69 - SFX_Headers_08) / 3,$1f,$20 - db (SFX_08_65 - SFX_Headers_08) / 3,$2f,$80 - db (SFX_08_4f - SFX_Headers_08) / 3,$1f,$ff - db (SFX_08_6b - SFX_Headers_08) / 3,$1f,$60 - db (SFX_08_66 - SFX_Headers_08) / 3,$1e,$20 - db (SFX_08_66 - SFX_Headers_08) / 3,$1f,$18 - db (SFX_08_54 - SFX_Headers_08) / 3,$0f,$80 - db (SFX_08_49 - SFX_Headers_08) / 3,$f8,$10 - db (SFX_08_48 - SFX_Headers_08) / 3,$18,$20 - db (SFX_08_72 - SFX_Headers_08) / 3,$08,$40 - db (SFX_08_57 - SFX_Headers_08) / 3,$01,$e0 - db (SFX_08_51 - SFX_Headers_08) / 3,$09,$ff - db (SFX_08_75 - SFX_Headers_08) / 3,$42,$01 - db (SFX_08_5c - SFX_Headers_08) / 3,$00,$ff - db (SFX_08_72 - SFX_Headers_08) / 3,$08,$e0 - db (SFX_08_64 - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_49 - SFX_Headers_08) / 3,$88,$10 - db (SFX_08_65 - SFX_Headers_08) / 3,$48,$ff - db (SFX_08_48 - SFX_Headers_08) / 3,$ff,$ff - db (SFX_08_64 - SFX_Headers_08) / 3,$ff,$10 - db (SFX_08_48 - SFX_Headers_08) / 3,$ff,$04 - db (SFX_08_5c - SFX_Headers_08) / 3,$01,$ff - db (SFX_08_53 - SFX_Headers_08) / 3,$f8,$ff - db (SFX_08_4c - SFX_Headers_08) / 3,$f0,$f0 - db (SFX_08_4f - SFX_Headers_08) / 3,$08,$10 - db (SFX_08_4d - SFX_Headers_08) / 3,$f0,$ff - db (SFX_08_5a - SFX_Headers_08) / 3,$f0,$ff - db (SFX_08_74 - SFX_Headers_08) / 3,$10,$ff - db (SFX_08_4e - SFX_Headers_08) / 3,$f0,$20 - db (SFX_08_6b - SFX_Headers_08) / 3,$f0,$60 - db (SFX_08_61 - SFX_Headers_08) / 3,$12,$10 - db (SFX_08_76 - SFX_Headers_08) / 3,$f0,$20 - db (SFX_08_5e - SFX_Headers_08) / 3,$12,$ff - db (SFX_08_71 - SFX_Headers_08) / 3,$80,$04 - db (SFX_08_73 - SFX_Headers_08) / 3,$f0,$10 - db (SFX_08_69 - SFX_Headers_08) / 3,$f8,$ff - db (SFX_08_66 - SFX_Headers_08) / 3,$f0,$ff - db (SFX_08_51 - SFX_Headers_08) / 3,$01,$ff - db (SFX_08_6c - SFX_Headers_08) / 3,$d8,$04 - db (SFX_08_4b - SFX_Headers_08) / 3,$00,$80 - db (SFX_08_4b - SFX_Headers_08) / 3,$00,$80 - -Func_79aae: ; 79aae (1e:5aae) +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 + +CopyPicTiles: ld a, [H_WHOSETURN] and a ld a, $31 ; base tile ID of player mon sprite - jr z, .asm_79ab6 + jr z, .next ; enemy turn xor a ; base tile ID of enemy mon sprite -.asm_79ab6 +.next ld [hBaseTileID], a - jr asm_79acb + jr CopyTileIDs_NoBGTransfer -Func_79aba: ; 79aba (1e:5aba) +; copy the tiles used when a mon is being sent out of or into a pokeball +CopyDownscaledMonTiles: call GetPredefRegisters - ld a, [wcd6c] + ld a, [wDownscaledMonSize] and a - jr nz, .asm_79ac8 - ld de, Unknown_79b02 ; $5b02 - jr asm_79acb -.asm_79ac8 - ld de, Unknown_79b1b ; $5b1b -asm_79acb: ; 79acb (1e:5acb) + jr nz, .smallerSize + ld de, DownscaledMonTiles_5x5 + jr CopyTileIDs_NoBGTransfer +.smallerSize + ld de, DownscaledMonTiles_3x3 +; fall through + +CopyTileIDs_NoBGTransfer: xor a ld [H_AUTOBGTRANSFERENABLED], a +; fall through ; b = number of rows ; c = number of columns -CopyTileIDs: ; 79ace (1e:5ace) +CopyTileIDs: push hl .rowLoop push bc @@ -2547,7 +2586,7 @@ CopyTileIDs: ; 79ace (1e:5ace) pop hl ret -TileIDListPointerTable: ; 79aea (1e:5aea) +TileIDListPointerTable: dw Unknown_79b24 db $77 dw Unknown_79b55 @@ -2565,19 +2604,19 @@ TileIDListPointerTable: ; 79aea (1e:5aea) dw Unknown_79c50 db $3C -Unknown_79b02: ; 79b02 (1e:5b02) +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 -Unknown_79b1b: ; 79b1b (1e:5b1b) +DownscaledMonTiles_3x3: db $31,$46,$5B db $34,$49,$5E db $37,$4C,$61 -Unknown_79b24: ; 79b24 (1e:5b24) +Unknown_79b24: db $00,$07,$0E,$15,$1C,$23,$2A db $01,$08,$0F,$16,$1D,$24,$2B db $02,$09,$10,$17,$1E,$25,$2C @@ -2586,19 +2625,19 @@ Unknown_79b24: ; 79b24 (1e:5b24) db $05,$0C,$13,$1A,$21,$28,$2F db $06,$0D,$14,$1B,$22,$29,$30 -Unknown_79b55: ; 79b55 (1e:5b55) +Unknown_79b55: 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 -Unknown_79b78: ; 79b78 (1e:5b78) +Unknown_79b78: db $00,$07,$0E,$15,$1C,$23,$2A db $02,$09,$10,$17,$1E,$25,$2C db $04,$0B,$12,$19,$20,$27,$2E -Unknown_79b8d: ; 79b8d (1e:5b8d) +Unknown_79b8d: db $00,$00,$00,$00,$00,$00,$00 db $00,$00,$00,$00,$00,$19,$00 db $02,$06,$0B,$10,$14,$1A,$00 @@ -2607,7 +2646,7 @@ Unknown_79b8d: ; 79b8d (1e:5b8d) db $04,$09,$0E,$13,$17,$1D,$1F db $05,$0A,$0F,$01,$18,$1E,$20 -Unknown_79bbe: ; 79bbe (1e:5bbe) +Unknown_79bbe: db $00,$00,$00,$30,$00,$37,$00 db $00,$00,$2B,$31,$34,$38,$3D db $21,$26,$2C,$01,$35,$39,$3E @@ -2616,7 +2655,7 @@ Unknown_79bbe: ; 79bbe (1e:5bbe) db $24,$29,$2F,$01,$01,$3B,$00 db $25,$2A,$01,$01,$01,$3C,$00 -Unknown_79bef: ; 79bef (1e:5bef) +Unknown_79bef: db $00,$00,$00,$00,$00,$00,$00 db $00,$00,$47,$4D,$00,$00,$00 db $00,$00,$48,$4E,$52,$56,$5B @@ -2625,7 +2664,7 @@ Unknown_79bef: ; 79bef (1e:5bef) db $41,$45,$4B,$51,$4C,$59,$5D db $42,$46,$4C,$4C,$55,$5A,$5E -Unknown_79c20: ; 79c20 (1e:5c20) +Unknown_79c20: db $31,$32,$32,$32,$32,$33 db $34,$35,$36,$36,$37,$38 db $34,$39,$3A,$3A,$3B,$38 @@ -2635,138 +2674,143 @@ Unknown_79c20: ; 79c20 (1e:5c20) db $41,$43,$4B,$4C,$4D,$4E db $4F,$50,$50,$50,$51,$52 -Unknown_79c50: ; 79c50 (1e:5c50) +Unknown_79c50: 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 -AnimationLeavesFalling: ; 79c74 (1e:5c74) +AnimationLeavesFalling: ; Makes leaves float down from the top of the screen. This is used ; in Razor Leaf's animation. - ld a, [$ff48] + ld a, [rOBP0] push af - ld a, [wcc79] - ld [$ff48], a - ld d, $37 - ld a, $3 - ld [W_SUBANIMTRANSFORM], a - call Func_79c97 + ld a, [wAnimPalette] + ld [rOBP0], a + ld d, $37 ; leaf tile + ld a, 3 ; number of leaves + ld [wNumFallingObjects], a + call AnimationFallingObjects pop af - ld [$ff48], a + ld [rOBP0], a ret -AnimationPetalsFalling: ; 79c8a (1e:5c8a) +AnimationPetalsFalling: ; Makes lots of petals fall down from the top of the screen. It's used in ; the animation for Petal Dance. - ld d, $71 - ld a, $14 - ld [W_SUBANIMTRANSFORM], a - call Func_79c97 + ld d, $71 ; petal tile + ld a, 20 ; number of petals + ld [wNumFallingObjects], a + call AnimationFallingObjects jp ClearSprites -Func_79c97: ; 79c97 (1e:5c97) +AnimationFallingObjects: ld c, a - ld a, $1 - call Func_797e8 - call Func_79d2a - call Func_79d52 + ld a, 1 + call InitMultipleObjectsOAM + call FallingObjects_InitXCoords + call FallingObjects_InitMovementData ld hl, wOAMBuffer - ld [hl], $0 -.asm_79ca8 - ld hl, wTrainerSpriteOffset - ld de, $0000 - ld a, [W_SUBANIMTRANSFORM] + ld [hl], 0 +.loop + ld hl, wFallingObjectsMovementData + ld de, 0 + ld a, [wNumFallingObjects] ld c, a -.asm_79cb2 +.innerLoop push bc push hl push de ld a, [hl] - ld [wd08a], a - call Func_79d16 - call Func_79cdb + ld [wFallingObjectMovementByte], a + call FallingObjects_UpdateMovementByte + call FallingObjects_UpdateOAMEntry pop de - ld hl, $0004 + ld hl, 4 add hl, de ld e, l ld d, h pop hl - ld a, [wd08a] + ld a, [wFallingObjectMovementByte] ld [hli], a pop bc dec c - jr nz, .asm_79cb2 + jr nz, .innerLoop call Delay3 ld hl, wOAMBuffer - ld a, [hl] - cp $68 - jr nz, .asm_79ca8 + ld a, [hl] ; Y + cp 104 ; has the top falling object reached 104 yet? + jr nz, .loop ; keep moving the falling objects down until it does ret -Func_79cdb: ; 79cdb (1e:5cdb) +FallingObjects_UpdateOAMEntry: +; Increases Y by 2 pixels and adjusts X and X flip based on the falling object's +; movement byte. ld hl, wOAMBuffer add hl, de ld a, [hl] inc a inc a - cp $70 - jr c, .asm_79ce8 - ld a, $a0 -.asm_79ce8 - ld [hli], a - ld a, [wd08a] + cp 112 + jr c, .next + ld a, 160 ; if Y >= 112, put it off-screen +.next + ld [hli], a ; Y + ld a, [wFallingObjectMovementByte] ld b, a - ld de, Unknown_79d0d + ld de, FallingObjects_DeltaXs and $7f add e - jr nc, .asm_79cf6 + jr nc, .noCarry inc d -.asm_79cf6 +.noCarry ld e, a ld a, b and $80 - jr nz, .asm_79d03 + jr nz, .movingLeft +; moving right ld a, [de] add [hl] - ld [hli], a + ld [hli], a ; X inc hl - xor a - jr .asm_79d0b -.asm_79d03 + xor a ; no horizontal flip + jr .next2 +.movingLeft ld a, [de] ld b, a ld a, [hl] sub b - ld [hli], a + ld [hli], a ; X inc hl - ld a, $20 -.asm_79d0b - ld [hl], a + ld a, (1 << OAM_X_FLIP) +.next2 + ld [hl], a ; attribute ret -Unknown_79d0d: ; 79d0d (1e:5d0d) - db $00,$01,$03,$05,$07,$09,$0B,$0D,$0F +FallingObjects_DeltaXs: + db 0, 1, 3, 5, 7, 9, 11, 13, 15 -Func_79d16: ; 79d16 (1e:5d16) - ld a, [wd08a] +FallingObjects_UpdateMovementByte: + ld a, [wFallingObjectMovementByte] inc a ld b, a and $7f - cp $9 + cp 9 ; have we reached the end of the delta-Xs? ld a, b - jr nz, .asm_79d26 + jr nz, .next +; We've reached the end of the delta-Xs, so wrap to the start and change +; direction from right to left or vice versa. and $80 xor $80 -.asm_79d26 - ld [wd08a], a +.next + ld [wFallingObjectMovementByte], a ret -Func_79d2a: ; 79d2a (1e:5d2a) +FallingObjects_InitXCoords: ld hl, wOAMBuffer + $01 - ld de, Unknown_79d3e - ld a, [W_SUBANIMTRANSFORM] + ld de, FallingObjects_InitialXCoords + ld a, [wNumFallingObjects] ld c, a -.asm_79d34 +.loop ld a, [de] ld [hli], a inc hl @@ -2774,70 +2818,102 @@ Func_79d2a: ; 79d2a (1e:5d2a) inc hl inc de dec c - jr nz, .asm_79d34 + jr nz, .loop ret -Unknown_79d3e: ; 79d3e (1e:5d3e) +FallingObjects_InitialXCoords: db $38,$40,$50,$60,$70,$88,$90,$56,$67,$4A,$77,$84,$98,$32,$22,$5C,$6C,$7D,$8E,$99 -Func_79d52: ; 79d52 (1e:5d52) - ld hl, wTrainerSpriteOffset - ld de, Unknown_79d63 - ld a, [W_SUBANIMTRANSFORM] +FallingObjects_InitMovementData: + ld hl, wFallingObjectsMovementData + ld de, FallingObjects_InitialMovementData + ld a, [wNumFallingObjects] ld c, a -.asm_79d5c +.loop ld a, [de] ld [hli], a inc de dec c - jr nz, .asm_79d5c + jr nz, .loop ret -Unknown_79d63: ; 79d63 (1e:5d63) +FallingObjects_InitialMovementData: db $00,$84,$06,$81,$02,$88,$01,$83,$05,$89,$09,$80,$07,$87,$03,$82,$04,$85,$08,$86 -AnimationShakeEnemyHUD: ; 79d77 (1e:5d77) +AnimationShakeEnemyHUD: +; Shakes the enemy HUD. + +; Make a copy of the back pic's tile patterns in sprite tile pattern VRAM. ld de, vBackPic ld hl, vSprites ld bc, 7 * 7 call CopyVideoData + xor a ld [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. ld hl, vBGMap0 - call Func_79e0d - ld a, $90 + call BattleAnimCopyTileMapToVRAM + +; 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 hl, vBGMap0 + $320 - call Func_79e0d - ld a, $38 + +; Copy wTileMap to VRAM such that the row below the enemy HUD (in wTileMap) is +; lined up with row 0 of the window. + ld hl, vBGMap1 - $20 * 7 + call BattleAnimCopyTileMapToVRAM + +; Move the window so that the row below the enemy HUD (in BG map 0) lines up +; with the top row of the window on the screen. This makes it so that the window +; covers everything below the enemy HD with a copy that looks just like what +; was there before. + ld a, 7 * 8 ld [hWY], a - call Func_792fd + +; 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 +; range overlaps with that of the enemy HUD and we don't want to shake the top +; of the back pic when we shake the enemy HUD. The OAM copy won't be affected +; by SCX. + call ShakeEnemyHUD_WritePlayerMonPicOAM + ld hl, vBGMap0 - call Func_79e0d + call BattleAnimCopyTileMapToVRAM + +; Remove the back pic from the BG map. call AnimationHideMonPic call Delay3 - ld de, $0208 - call Func_79de9 + +; Use SCX to shake the regular BG. The window and the back pic OAM copy are +; not affected. + lb de, 2, 8 + call ShakeEnemyHUD_ShakeBG + +; Restore the original graphics. call AnimationShowMonPic call ClearSprites - ld a, $90 + ld a, SCREEN_HEIGHT_PIXELS ld [hWY], a ld hl, vBGMap1 - call Func_79e0d + call BattleAnimCopyTileMapToVRAM xor a ld [hWY], a call SaveScreenTilesToBuffer1 ld hl, vBGMap0 - call Func_79e0d + call BattleAnimCopyTileMapToVRAM call ClearScreen call Delay3 call LoadScreenTilesFromBuffer1 ld hl, vBGMap1 - jp Func_79e0d + jp BattleAnimCopyTileMapToVRAM ; b = tile ID list index ; c = base tile ID -CopyTileIDsFromList: ; 79dda (1e:5dda) +CopyTileIDsFromList: call GetPredefRegisters ld a, c ld [hBaseTileID], a @@ -2847,38 +2923,38 @@ CopyTileIDsFromList: ; 79dda (1e:5dda) pop hl jp CopyTileIDs -Func_79de9: ; 79de9 (1e:5de9) +ShakeEnemyHUD_ShakeBG: ld a, [hSCX] - ld [wTrainerSpriteOffset], a -.asm_79dee - ld a, [wTrainerSpriteOffset] + ld [wTempSCX], a +.loop + ld a, [wTempSCX] add d ld [hSCX], a - ld c, $2 + ld c, 2 call DelayFrames - ld a, [wTrainerSpriteOffset] + ld a, [wTempSCX] sub d ld [hSCX], a - ld c, $2 + ld c, 2 call DelayFrames dec e - jr nz, .asm_79dee - ld a, [wTrainerSpriteOffset] + jr nz, .loop + ld a, [wTempSCX] ld [hSCX], a ret -Func_79e0d: ; 79e0d (1e:5e0d) +BattleAnimCopyTileMapToVRAM: ld a, h - ld [$ffbd], a + ld [H_AUTOBGTRANSFERDEST + 1], a ld a, l ld [H_AUTOBGTRANSFERDEST], a jp Delay3 -TossBallAnimation: ; 79e16 (1e:5e16) - ld a,[W_ISINBATTLE] +TossBallAnimation: + ld a,[wIsInBattle] cp a,2 jr z,.BlockBall ; if in trainer battle, play different animation - ld a,[wd11e] + ld a,[wPokeBallAnimData] ld b,a ; upper nybble: how many animations (from PokeBallAnimations) to play @@ -2891,7 +2967,7 @@ TossBallAnimation: ; 79e16 (1e:5e16) ; store these for later ld a,b and a,$F - ld [wWhichTrade],a + ld [wNumShakes],a ld hl,.PokeBallAnimations ; choose which toss animation to use @@ -2906,7 +2982,7 @@ TossBallAnimation: ; 79e16 (1e:5e16) .done ld a,b .PlayNextAnimation - ld [W_ANIMATIONID],a + ld [wAnimationID],a push bc push hl call PlayAnimation @@ -2917,42 +2993,42 @@ TossBallAnimation: ; 79e16 (1e:5e16) jr nz,.PlayNextAnimation ret -.PokeBallAnimations: ; 79e50 (1e:5e50) +.PokeBallAnimations: ; sequence of animations that make up the Poké Ball toss db POOF_ANIM,HIDEPIC_ANIM,SHAKE_ANIM,POOF_ANIM,SHOWPIC_ANIM -.BlockBall ; 5E55 +.BlockBall ld a,TOSS_ANIM - ld [W_ANIMATIONID],a + ld [wAnimationID],a call PlayAnimation - ld a,(SFX_08_43 - SFX_Headers_08) / 3 - call PlaySound ; play sound effect + ld a,SFX_FAINT_THUD + call PlaySound ld a,BLOCKBALL_ANIM - ld [W_ANIMATIONID],a + ld [wAnimationID],a jp PlayAnimation -PlayApplyingAttackSound: ; 79e6a (1e:5e6a) +PlayApplyingAttackSound: ; play a different sound depending if move is not very effective, neutral, or super-effective ; don't play any sound at all if move is ineffective call WaitForSoundToFinish ld a, [wDamageMultipliers] and $7f ret z - cp $a + cp 10 ld a, $20 ld b, $30 - ld c, (SFX_08_50 - SFX_Headers_08) / 3 - jr z, .asm_79e8b + ld c, SFX_DAMAGE + jr z, .playSound ld a, $e0 ld b, $ff - ld c, (SFX_08_5a - SFX_Headers_08) / 3 - jr nc, .asm_79e8b + ld c, SFX_SUPER_EFFECTIVE + jr nc, .playSound ld a, $50 ld b, $1 - ld c, (SFX_08_51 - SFX_Headers_08) / 3 -.asm_79e8b - ld [wc0f1], a + ld c, SFX_NOT_VERY_EFFECTIVE +.playSound + ld [wFrequencyModifier], a ld a, b - ld [wc0f2], a + ld [wTempoModifier], a ld a, c jp PlaySound diff --git a/engine/battle/bank_e_misc.asm b/engine/battle/bank_e_misc.asm index 78b27108..33af6f6f 100644..100755 --- a/engine/battle/bank_e_misc.asm +++ b/engine/battle/bank_e_misc.asm @@ -1,5 +1,5 @@ ; formats a string at wMovesString that lists the moves at wMoves -FormatMovesString: ; 39b87 (e:5b87) +FormatMovesString: ld hl, wMoves ld de, wMovesString ld b, $0 @@ -24,7 +24,7 @@ FormatMovesString: ; 39b87 (e:5b87) jr .copyNameLoop .doneCopyingName ld a, b - ld [wcd6c], a + ld [wNumMovesMinusOne], a inc b ld a, $4e ; line break ld [de], a @@ -52,49 +52,49 @@ FormatMovesString: ; 39b87 (e:5b87) ret ; XXX this is called in a few places, but it doesn't appear to do anything useful -Func_39bd5: ; 39bd5 (e:5bd5) - ld a, [wd11b] - cp $1 - jr nz, .asm_39be6 +InitList: + ld a, [wInitListType] + cp INIT_ENEMYOT_LIST + jr nz, .notEnemy ld hl, wEnemyPartyCount ld de, wEnemyMonOT ld a, ENEMYOT_NAME - jr .asm_39c18 -.asm_39be6 - cp $4 - jr nz, .calcAttackStat4 + jr .done +.notEnemy + cp INIT_PLAYEROT_LIST + jr nz, .notPlayer ld hl, wPartyCount ld de, wPartyMonOT ld a, PLAYEROT_NAME - jr .asm_39c18 -.calcAttackStat4 - cp $5 - jr nz, .asm_39c02 - ld hl, wStringBuffer2 + 11 + jr .done +.notPlayer + cp INIT_MON_LIST + jr nz, .notMonster + ld hl, wItemList ld de, MonsterNames ld a, MONSTER_NAME - jr .asm_39c18 -.asm_39c02 - cp $2 - jr nz, .asm_39c10 + jr .done +.notMonster + cp INIT_BAG_ITEM_LIST + jr nz, .notBag ld hl, wNumBagItems ld de, ItemNames ld a, ITEM_NAME - jr .asm_39c18 -.asm_39c10 - ld hl, wStringBuffer2 + 11 + jr .done +.notBag + ld hl, wItemList ld de, ItemNames ld a, ITEM_NAME -.asm_39c18 +.done ld [wNameListType], a ld a, l - ld [wList], a + ld [wListPointer], a ld a, h - ld [wList + 1], a + ld [wListPointer + 1], a ld a, e - ld [wcf8d], a + ld [wUnusedCF8D], a ld a, d - ld [wcf8e], a + ld [wUnusedCF8D + 1], a ld bc, ItemPrices ld a, c ld [wItemPrices], a @@ -102,10 +102,10 @@ Func_39bd5: ; 39bd5 (e:5bd5) ld [wItemPrices + 1], a ret -; get species of mon e in list [wcc49] for LoadMonData -GetMonSpecies: ; 39c37 (e:5c37) +; get species of mon e in list [wMonDataLocation] for LoadMonData +GetMonSpecies: ld hl, wPartySpecies - ld a, [wcc49] + ld a, [wMonDataLocation] and a jr z, .getSpecies dec a @@ -119,4 +119,4 @@ GetMonSpecies: ; 39c37 (e:5c37) add hl, de ld a, [hl] ld [wcf91], a - ret
\ No newline at end of file + ret diff --git a/engine/battle/battle_transitions.asm b/engine/battle/battle_transitions.asm index f1aa4161..9e02c56f 100644 --- a/engine/battle/battle_transitions.asm +++ b/engine/battle/battle_transitions.asm @@ -1,5 +1,5 @@ -BattleTransition: ; 7096d (1c:496d) - ld a, $1 +BattleTransition: + ld a, 1 ld [H_AUTOBGTRANSFERENABLED], a call Delay3 xor a @@ -7,10 +7,13 @@ BattleTransition: ; 7096d (1c:496d) 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, [H_DOWNARROWBLINKCNT2] + ld a, [hSpriteIndexOrTextID] ; enemy trainer sprite index (0 if wild battle) ld c, a - ld b, $0 + ld b, 0 ld de, $10 .loop1 ld a, [hl] @@ -21,13 +24,15 @@ BattleTransition: ; 7096d (1c:496d) add hl, de dec c jr nz, .loop1 + +; Clear OAM except for the blocks used by the player and enemy trainer sprites. ld hl, wOAMBuffer + $10 - ld c, $9 + ld c, 9 .loop2 ld a, b swap a cp l - jr z, .skip2 + jr z, .skip2 ; skip clearing the block if the enemy trainer is using it push hl push bc ld bc, $10 @@ -40,9 +45,10 @@ BattleTransition: ; 7096d (1c:496d) add hl, de dec c jr nz, .loop2 + call Delay3 call LoadBattleTransitionTile - ld bc, $0 + ld bc, 0 ld a, [wLinkState] cp LINK_STATE_BATTLING jr z, .linkBattle @@ -64,7 +70,7 @@ BattleTransition: ; 7096d (1c:496d) ; bit 0: set if trainer battle ; bit 1: set if enemy is at least 3 levels higher than player ; bit 2: set if dungeon map -BattleTransitions: ; 709d2 (1c:49d2) +BattleTransitions: dw BattleTransition_DoubleCircle ; %000 dw BattleTransition_Spiral ; %001 dw BattleTransition_Circle ; %010 @@ -74,9 +80,9 @@ BattleTransitions: ; 709d2 (1c:49d2) dw BattleTransition_VerticalStripes ; %110 dw BattleTransition_Split ; %111 -GetBattleTransitionID_WildOrTrainer: ; 709e2 (1c:49e2) - ld a, [W_CUROPPONENT] - cp $c8 +GetBattleTransitionID_WildOrTrainer: + ld a, [wCurOpponent] + cp 200 jr nc, .trainer res 0, c ret @@ -84,7 +90,7 @@ GetBattleTransitionID_WildOrTrainer: ; 709e2 (1c:49e2) set 0, c ret -GetBattleTransitionID_CompareLevels: ; 709ef (1c:49ef) +GetBattleTransitionID_CompareLevels: ld hl, wPartyMon1HP .faintedLoop ld a, [hli] @@ -99,24 +105,24 @@ GetBattleTransitionID_CompareLevels: ; 709ef (1c:49ef) ld a, [hl] add $3 ld e, a - ld a, [W_CURENEMYLVL] + ld a, [wCurEnemyLVL] sub e jr nc, .highLevelEnemy res 1, c - ld a, $1 - ld [wcd47], a + ld a, 1 + ld [wBattleTransitionSpiralDirection], a ret .highLevelEnemy set 1, c xor a - ld [wcd47], a + ld [wBattleTransitionSpiralDirection], a ret ; fails to recognize VICTORY_ROAD_2, VICTORY_ROAD_3, all ROCKET_HIDEOUT maps, ; MANSION_1, SEAFOAM_ISLANDS_[2-5], POWER_PLANT, DIGLETTS_CAVE ; and SILPH_CO_[9-11]F as dungeon maps -GetBattleTransitionID_IsDungeonMap: ; 70a19 (1c:4a19) - ld a, [W_CURMAP] +GetBattleTransitionID_IsDungeonMap: + ld a, [wCurMap] ld e, a ld hl, DungeonMaps1 .loop1 @@ -145,18 +151,18 @@ GetBattleTransitionID_IsDungeonMap: ; 70a19 (1c:4a19) res 2, c ret -; GetBattleTransitionID_IsDungeonMap checks if W_CURMAP +; GetBattleTransitionID_IsDungeonMap checks if wCurMap ; is equal to one of these maps -DungeonMaps1: ; 70a3f (1c:4a3f) +DungeonMaps1: db VIRIDIAN_FOREST db ROCK_TUNNEL_1 db SEAFOAM_ISLANDS_1 db ROCK_TUNNEL_2 db $FF -; GetBattleTransitionID_IsDungeonMap checks if W_CURMAP +; GetBattleTransitionID_IsDungeonMap checks if wCurMap ; is in between or equal to each pair of maps -DungeonMaps2: ; 70a44 (1c:4a44) +DungeonMaps2: ; all MT_MOON maps db MT_MOON_1 db MT_MOON_3 @@ -175,16 +181,17 @@ DungeonMaps2: ; 70a44 (1c:4a44) db UNKNOWN_DUNGEON_1 db $FF -LoadBattleTransitionTile: ; 70a4d (1c:4a4d) +LoadBattleTransitionTile: ld hl, vChars1 + $7f0 ld de, BattleTransitionTile - ld bc, (BANK(BattleTransitionTile) << 8) + $01 + lb bc, BANK(BattleTransitionTile), (BattleTransitionTileEnd - BattleTransitionTile) / $10 jp CopyVideoData -BattleTransitionTile: ; 70a59 (1c:4a59) +BattleTransitionTile: INCBIN "gfx/battle_transition.2bpp" +BattleTransitionTileEnd: -BattleTransition_BlackScreen: ; 70a69 (1c:4a69) +BattleTransition_BlackScreen: ld a, $ff ld [rBGP], a ld [rOBP0], a @@ -195,61 +202,61 @@ BattleTransition_BlackScreen: ; 70a69 (1c:4a69) ; called regardless of mon levels, but does an ; outward spiral if enemy is at least 3 levels ; higher than player and does an inward spiral otherwise -BattleTransition_Spiral: ; 70a72 (1c:4a72) - ld a, [wcd47] +BattleTransition_Spiral: + ld a, [wBattleTransitionSpiralDirection] and a jr z, .outwardSpiral call BattleTransition_InwardSpiral jr .done .outwardSpiral - hlCoord 10, 10 + coord hl, 10, 10 ld a, $3 - ld [wd09f], a + ld [wOutwardSpiralCurrentDirection], a ld a, l - ld [wd09b], a + ld [wOutwardSpiralTileMapPointer + 1], a ld a, h - ld [wd09a], a - ld b, $78 -.loop1 - ld c, $3 -.loop2 + ld [wOutwardSpiralTileMapPointer], a + ld b, 120 +.loop + ld c, 3 +.innerLoop push bc call BattleTransition_OutwardSpiral_ pop bc dec c - jr nz, .loop2 + jr nz, .innerLoop call DelayFrame dec b - jr nz, .loop1 + jr nz, .loop .done call BattleTransition_BlackScreen xor a - ld [wd09b], a - ld [wd09a], a + ld [wOutwardSpiralTileMapPointer + 1], a + ld [wOutwardSpiralTileMapPointer], a ret -BattleTransition_InwardSpiral: ; 70aaa (1c:4aaa) - ld a, $7 - ld [wWhichTrade], a - ld hl, wTileMap - ld c, $11 - ld de, $14 +BattleTransition_InwardSpiral: + ld a, 7 + ld [wInwardSpiralUpdateScreenCounter], a + coord hl, 0, 0 + ld c, SCREEN_HEIGHT - 1 + ld de, SCREEN_WIDTH call BattleTransition_InwardSpiral_ inc c jr .skip .loop - ld de, $14 + ld de, SCREEN_WIDTH call BattleTransition_InwardSpiral_ .skip inc c - ld de, $1 + ld de, 1 call BattleTransition_InwardSpiral_ dec c dec c - ld de, $ffec + ld de, -SCREEN_WIDTH call BattleTransition_InwardSpiral_ inc c - ld de, rIE + ld de, -1 call BattleTransition_InwardSpiral_ dec c dec c @@ -258,101 +265,101 @@ BattleTransition_InwardSpiral: ; 70aaa (1c:4aaa) jr nz, .loop ret -BattleTransition_InwardSpiral_: ; 70ae0 (1c:4ae0) +BattleTransition_InwardSpiral_: push bc .loop ld [hl], $ff add hl, de push bc - ld a, [wWhichTrade] + ld a, [wInwardSpiralUpdateScreenCounter] dec a jr nz, .skip call BattleTransition_TransferDelay3 - ld a, $7 + ld a, 7 .skip - ld [wWhichTrade], a + ld [wInwardSpiralUpdateScreenCounter], a pop bc dec c jr nz, .loop pop bc ret -BattleTransition_OutwardSpiral_: ; 70af9 (1c:4af9) - ld bc, $ffec - ld de, $14 - ld a, [wd09b] +BattleTransition_OutwardSpiral_: + ld bc, -SCREEN_WIDTH + ld de, SCREEN_WIDTH + ld a, [wOutwardSpiralTileMapPointer + 1] ld l, a - ld a, [wd09a] + ld a, [wOutwardSpiralTileMapPointer] ld h, a - ld a, [wd09f] + ld a, [wOutwardSpiralCurrentDirection] cp $0 - jr z, .zero + jr z, .up cp $1 - jr z, .one + jr z, .left cp $2 - jr z, .two + jr z, .down cp $3 - jr z, .three -.done1 + jr z, .right +.keepSameDirection ld [hl], $ff -.done2_ +.done ld a, l - ld [wd09b], a + ld [wOutwardSpiralTileMapPointer + 1], a ld a, h - ld [wd09a], a + ld [wOutwardSpiralTileMapPointer], a ret -.zero +.up dec hl ld a, [hl] cp $ff - jr nz, .done2 + jr nz, .changeDirection inc hl add hl, bc - jr .done1 -.one + jr .keepSameDirection +.left add hl, de ld a, [hl] cp $ff - jr nz, .done2 + jr nz, .changeDirection add hl, bc dec hl - jr .done1 -.two + jr .keepSameDirection +.down inc hl ld a, [hl] cp $ff - jr nz, .done2 + jr nz, .changeDirection dec hl add hl, de - jr .done1 -.three + jr .keepSameDirection +.right add hl, bc ld a, [hl] cp $ff - jr nz, .done2 + jr nz, .changeDirection add hl, de inc hl - jr .done1 -.done2 + jr .keepSameDirection +.changeDirection ld [hl], $ff - ld a, [wd09f] + ld a, [wOutwardSpiralCurrentDirection] inc a cp $4 jr nz, .skip xor a .skip - ld [wd09f], a - jr .done2_ + ld [wOutwardSpiralCurrentDirection], a + jr .done FlashScreen: -BattleTransition_FlashScreen_: ; 70b5d (1c:4b5d) +BattleTransition_FlashScreen_: ld hl, BattleTransition_FlashScreenPalettes .loop ld a, [hli] cp $1 jr z, .done ld [rBGP], a - ld c, $2 + ld c, 2 call DelayFrames jr .loop .done @@ -360,66 +367,66 @@ BattleTransition_FlashScreen_: ; 70b5d (1c:4b5d) jr nz, BattleTransition_FlashScreen_ ret -BattleTransition_FlashScreenPalettes: ; 70b72 (1c:4b72) +BattleTransition_FlashScreenPalettes: db $F9,$FE,$FF,$FE,$F9,$E4,$90,$40,$00,$40,$90,$E4 db $01 ; terminator ; used for low level trainer dungeon battles -BattleTransition_Shrink: ; 70b7f (1c:4b7f) - ld c, $9 +BattleTransition_Shrink: + ld c, SCREEN_HEIGHT / 2 .loop push bc xor a ld [H_AUTOBGTRANSFERENABLED], a - hlCoord 0, 7 - deCoord 0, 8 - ld bc, $ffd8 + coord hl, 0, 7 + coord de, 0, 8 + ld bc, -SCREEN_WIDTH * 2 call BattleTransition_CopyTiles1 - hlCoord 0, 10 - deCoord 0, 9 - ld bc, $28 + coord hl, 0, 10 + coord de, 0, 9 + ld bc, SCREEN_WIDTH * 2 call BattleTransition_CopyTiles1 - hlCoord 8, 0 - deCoord 9, 0 - ld bc, $fffe + coord hl, 8, 0 + coord de, 9, 0 + ld bc, -2 call BattleTransition_CopyTiles2 - hlCoord 11, 0 - deCoord 10, 0 - ld bc, $2 + coord hl, 11, 0 + coord de, 10, 0 + ld bc, 2 call BattleTransition_CopyTiles2 ld a, $1 ld [H_AUTOBGTRANSFERENABLED], a - ld c, $6 + ld c, 6 call DelayFrames pop bc dec c jr nz, .loop call BattleTransition_BlackScreen - ld c, $a + ld c, 10 jp DelayFrames ; used for high level trainer dungeon battles -BattleTransition_Split: ; 70bca (1c:4bca) - ld c, $9 +BattleTransition_Split: + ld c, SCREEN_HEIGHT / 2 xor a ld [H_AUTOBGTRANSFERENABLED], a .loop push bc - hlCoord 0, 16 - deCoord 0, 17 - ld bc, $ffd8 + coord hl, 0, 16 + coord de, 0, 17 + ld bc, -SCREEN_WIDTH * 2 call BattleTransition_CopyTiles1 - hlCoord 0, 1 - ld de, wTileMap - ld bc, $28 + coord hl, 0, 1 + coord de, 0, 0 + ld bc, SCREEN_WIDTH * 2 call BattleTransition_CopyTiles1 - hlCoord 18, 0 - deCoord 19, 0 - ld bc, $fffe + coord hl, 18, 0 + coord de, 19, 0 + ld bc, -2 call BattleTransition_CopyTiles2 - hlCoord 1, 0 - ld de, wTileMap - ld bc, $2 + coord hl, 1, 0 + coord de, 0, 0 + ld bc, 2 call BattleTransition_CopyTiles2 call BattleTransition_TransferDelay3 call Delay3 @@ -427,26 +434,26 @@ BattleTransition_Split: ; 70bca (1c:4bca) dec c jr nz, .loop call BattleTransition_BlackScreen - ld c, $a + ld c, 10 jp DelayFrames -BattleTransition_CopyTiles1: ; 70c12 (1c:4c12) +BattleTransition_CopyTiles1: ld a, c - ld [wWhichTrade], a + ld [wBattleTransitionCopyTilesOffset], a ld a, b - ld [wTrainerEngageDistance], a - ld c, $8 + ld [wBattleTransitionCopyTilesOffset + 1], a + ld c, 8 .loop1 push bc push hl push de - ld bc, $14 + ld bc, SCREEN_WIDTH call CopyData pop hl pop de - ld a, [wWhichTrade] + ld a, [wBattleTransitionCopyTilesOffset] ld c, a - ld a, [wTrainerEngageDistance] + ld a, [wBattleTransitionCopyTilesOffset + 1] ld b, a add hl, bc pop bc @@ -455,35 +462,35 @@ BattleTransition_CopyTiles1: ; 70c12 (1c:4c12) ld l, e ld h, d ld a, $ff - ld c, $14 + ld c, SCREEN_WIDTH .loop2 ld [hli], a dec c jr nz, .loop2 ret -BattleTransition_CopyTiles2: ; 70c3f (1c:4c3f) +BattleTransition_CopyTiles2: ld a, c - ld [wWhichTrade], a + ld [wBattleTransitionCopyTilesOffset], a ld a, b - ld [wTrainerEngageDistance], a - ld c, $9 + ld [wBattleTransitionCopyTilesOffset + 1], a + ld c, SCREEN_HEIGHT / 2 .loop1 push bc push hl push de - ld c, $12 + ld c, SCREEN_HEIGHT .loop2 ld a, [hl] ld [de], a ld a, e - add $14 + add SCREEN_WIDTH jr nc, .noCarry1 inc d .noCarry1 ld e, a ld a, l - add $14 + add SCREEN_WIDTH jr nc, .noCarry2 inc h .noCarry2 @@ -492,9 +499,9 @@ BattleTransition_CopyTiles2: ; 70c3f (1c:4c3f) jr nz, .loop2 pop hl pop de - ld a, [wWhichTrade] + ld a, [wBattleTransitionCopyTilesOffset] ld c, a - ld a, [wTrainerEngageDistance] + ld a, [wBattleTransitionCopyTilesOffset + 1] ld b, a add hl, bc pop bc @@ -502,8 +509,8 @@ BattleTransition_CopyTiles2: ; 70c3f (1c:4c3f) jr nz, .loop1 ld l, e ld h, d - ld de, $14 - ld c, $12 + ld de, SCREEN_WIDTH + ld c, SCREEN_HEIGHT .loop3 ld [hl], $ff add hl, de @@ -512,10 +519,10 @@ BattleTransition_CopyTiles2: ; 70c3f (1c:4c3f) ret ; used for high level wild dungeon battles -BattleTransition_VerticalStripes: ; 70c7e (1c:4c7e) - ld c, $12 - ld hl, wTileMap - deCoord 1, 17 +BattleTransition_VerticalStripes: + ld c, SCREEN_HEIGHT + coord hl, 0, 0 + coord de, 1, 17 xor a ld [H_AUTOBGTRANSFERENABLED], a .loop @@ -528,20 +535,20 @@ BattleTransition_VerticalStripes: ; 70c7e (1c:4c7e) call BattleTransition_VerticalStripes_ call BattleTransition_TransferDelay3 pop hl - ld bc, $ffec + ld bc, -SCREEN_WIDTH add hl, bc ld e, l ld d, h pop hl - ld bc, $14 + ld bc, SCREEN_WIDTH add hl, bc pop bc dec c jr nz, .loop jp BattleTransition_BlackScreen -BattleTransition_VerticalStripes_: ; 70caa (1c:4caa) - ld c, $a +BattleTransition_VerticalStripes_: + ld c, SCREEN_WIDTH / 2 .loop ld [hl], $ff inc hl @@ -551,10 +558,10 @@ BattleTransition_VerticalStripes_: ; 70caa (1c:4caa) ret ; used for low level wild dungeon battles -BattleTransition_HorizontalStripes: ; 70cb4 (1c:4cb4) - ld c, $14 - ld hl, wTileMap - deCoord 19, 1 +BattleTransition_HorizontalStripes: + ld c, SCREEN_WIDTH + coord hl, 0, 0 + coord de, 19, 1 xor a ld [H_AUTOBGTRANSFERENABLED], a .loop @@ -575,9 +582,9 @@ BattleTransition_HorizontalStripes: ; 70cb4 (1c:4cb4) jr nz, .loop jp BattleTransition_BlackScreen -BattleTransition_HorizontalStripes_: ; 70cd8 (1c:4cd8) - ld c, $9 - ld de, $28 +BattleTransition_HorizontalStripes_: + ld c, SCREEN_HEIGHT / 2 + ld de, SCREEN_WIDTH * 2 .loop ld [hl], $ff add hl, de @@ -588,31 +595,31 @@ BattleTransition_HorizontalStripes_: ; 70cd8 (1c:4cd8) ; used for high level wild non-dungeon battles ; makes one full circle around the screen ; by animating each half circle one at a time -BattleTransition_Circle: ; 70ce4 (1c:4ce4) +BattleTransition_Circle: call BattleTransition_FlashScreen - ld bc, $000a + lb bc, 0, SCREEN_WIDTH / 2 ld hl, BattleTransition_HalfCircle1 call BattleTransition_Circle_Sub1 - ld c, $a - ld b, $1 + ld c, SCREEN_WIDTH / 2 + ld b, 1 ld hl, BattleTransition_HalfCircle2 call BattleTransition_Circle_Sub1 jp BattleTransition_BlackScreen -BattleTransition_FlashScreen: ; 70cfd (1c:4cfd) +BattleTransition_FlashScreen: ld b, $3 call BattleTransition_FlashScreen_ xor a ld [H_AUTOBGTRANSFERENABLED], a ret -BattleTransition_Circle_Sub1: ; 70d06 (1c:4d06) +BattleTransition_Circle_Sub1: push bc push hl ld a, b call BattleTransition_Circle_Sub2 pop hl - ld bc, $0005 + ld bc, 5 add hl, bc call BattleTransition_TransferDelay3 pop bc @@ -620,8 +627,8 @@ BattleTransition_Circle_Sub1: ; 70d06 (1c:4d06) jr nz, BattleTransition_Circle_Sub1 ret -BattleTransition_TransferDelay3: ; 70d19 (1c:4d19) - ld a, $1 +BattleTransition_TransferDelay3: + ld a, 1 ld [H_AUTOBGTRANSFERENABLED], a call Delay3 xor a @@ -631,9 +638,9 @@ BattleTransition_TransferDelay3: ; 70d19 (1c:4d19) ; used for low level wild non-dungeon battles ; makes two half circles around the screen ; by animating both half circles at the same time -BattleTransition_DoubleCircle: ; 70d24 (1c:4d24) +BattleTransition_DoubleCircle: call BattleTransition_FlashScreen - ld c, $a + ld c, SCREEN_WIDTH / 2 ld hl, BattleTransition_HalfCircle1 ld de, BattleTransition_HalfCircle2 .loop @@ -647,7 +654,7 @@ BattleTransition_DoubleCircle: ; 70d24 (1c:4d24) ld a, $1 call BattleTransition_Circle_Sub2 pop hl - ld bc, $5 + ld bc, 5 add hl, bc ld e, l ld d, h @@ -659,10 +666,10 @@ BattleTransition_DoubleCircle: ; 70d24 (1c:4d24) jr nz, .loop jp BattleTransition_BlackScreen -BattleTransition_Circle_Sub2: ; 70d50 (1c:4d50) - ld [wWhichTrade], a +BattleTransition_Circle_Sub2: + ld [wBattleTransitionCircleScreenQuadrantY], a ld a, [hli] - ld [wTrainerEngageDistance], a + ld [wBattleTransitionCircleScreenQuadrantX], a ld a, [hli] ld e, a ld a, [hli] @@ -672,7 +679,7 @@ BattleTransition_Circle_Sub2: ; 70d50 (1c:4d50) ld l, a jp BattleTransition_Circle_Sub3 -BattleTransition_HalfCircle1: ; 70d61 (1c:4d61) +BattleTransition_HalfCircle1: db $01 dw BattleTransition_CircleData1 dwCoord 18, 6 @@ -713,7 +720,7 @@ BattleTransition_HalfCircle1: ; 70d61 (1c:4d61) dw BattleTransition_CircleData1 dwCoord 1, 6 -BattleTransition_HalfCircle2: ; 70d93 (1c:4d93) +BattleTransition_HalfCircle2: db $00 dw BattleTransition_CircleData1 dwCoord 1, 11 @@ -754,14 +761,14 @@ BattleTransition_HalfCircle2: ; 70d93 (1c:4d93) dw BattleTransition_CircleData1 dwCoord 18, 11 -BattleTransition_Circle_Sub3: ; 70dc5 (1c:4dc5) +BattleTransition_Circle_Sub3: push hl ld a, [de] ld c, a inc de .loop1 ld [hl], $ff - ld a, [wTrainerEngageDistance] + ld a, [wBattleTransitionCircleScreenQuadrantX] and a jr z, .skip1 inc hl @@ -772,11 +779,11 @@ BattleTransition_Circle_Sub3: ; 70dc5 (1c:4dc5) dec c jr nz, .loop1 pop hl - ld a, [wWhichTrade] + ld a, [wBattleTransitionCircleScreenQuadrantY] and a - ld bc, $14 + ld bc, SCREEN_WIDTH jr z, .skip3 - ld bc, $ffec + ld bc, -SCREEN_WIDTH .skip3 add hl, bc ld a, [de] @@ -787,7 +794,7 @@ BattleTransition_Circle_Sub3: ; 70dc5 (1c:4dc5) jr z, BattleTransition_Circle_Sub3 ld c, a .loop2 - ld a, [wTrainerEngageDistance] + ld a, [wBattleTransitionCircleScreenQuadrantX] and a jr z, .skip4 dec hl @@ -799,17 +806,17 @@ BattleTransition_Circle_Sub3: ; 70dc5 (1c:4dc5) jr nz, .loop2 jr BattleTransition_Circle_Sub3 -BattleTransition_CircleData1: ; 70dfe (1c:4dfe) +BattleTransition_CircleData1: db $02,$03,$05,$04,$09,$FF -BattleTransition_CircleData2: ; 70e04 (1c:4e04) +BattleTransition_CircleData2: db $01,$01,$02,$02,$04,$02,$04,$02,$03,$FF -BattleTransition_CircleData3: ; 70e0e (1c:4e0e) +BattleTransition_CircleData3: db $02,$01,$03,$01,$04,$01,$04,$01,$04,$01,$03,$01,$02,$01,$01,$01,$01,$FF -BattleTransition_CircleData4: ; 70e20 (1c:4e20) +BattleTransition_CircleData4: db $04,$01,$04,$00,$03,$01,$03,$00,$02,$01,$02,$00,$01,$FF -BattleTransition_CircleData5: ; 70e2e (1c:4e2e) +BattleTransition_CircleData5: db $04,$00,$03,$00,$03,$00,$02,$00,$02,$00,$01,$00,$01,$00,$01,$FF diff --git a/engine/battle/common_text.asm b/engine/battle/common_text.asm index 9a00bd98..3d46c947 100644 --- a/engine/battle/common_text.asm +++ b/engine/battle/common_text.asm @@ -1,8 +1,8 @@ -PrintBeginningBattleText: ; 58d99 (16:4d99) - ld a, [W_ISINBATTLE] ; W_ISINBATTLE +PrintBeginningBattleText: + ld a, [wIsInBattle] dec a jr nz, .trainerBattle - ld a, [W_CURMAP] ; W_CURMAP + ld a, [wCurMap] cp POKEMONTOWER_3 jr c, .notPokemonTower cp LAVENDER_HOUSE_1 @@ -11,7 +11,7 @@ PrintBeginningBattleText: ; 58d99 (16:4d99) ld a, [wEnemyMonSpecies2] call PlayCry ld hl, WildMonAppearedText - ld a, [W_MOVEMISSED] ; W_MOVEMISSED + ld a, [wMoveMissed] and a jr z, .notFishing ld hl, HookedMonAttackedText @@ -19,7 +19,7 @@ PrintBeginningBattleText: ; 58d99 (16:4d99) jr .wildBattle .trainerBattle call .playSFX - ld c, $14 + ld c, 20 call DelayFrames ld hl, TrainerWantsToFightText .wildBattle @@ -61,40 +61,40 @@ PrintBeginningBattleText: ; 58d99 (16:4d99) .playSFX xor a - ld [wc0f1], a + ld [wFrequencyModifier], a ld a, $80 - ld [wc0f2], a - ld a, (SFX_08_77 - SFX_Headers_08) / 3 + ld [wTempoModifier], a + ld a, SFX_SILPH_SCOPE call PlaySound jp WaitForSoundToFinish .done ret -WildMonAppearedText: ; 58e3b (16:4e3b) +WildMonAppearedText: TX_FAR _WildMonAppearedText db "@" -HookedMonAttackedText: ; 58e40 (16:4e40) +HookedMonAttackedText: TX_FAR _HookedMonAttackedText db "@" -EnemyAppearedText: ; 58e45 (16:4e45) +EnemyAppearedText: TX_FAR _EnemyAppearedText db "@" -TrainerWantsToFightText: ; 58e4a (16:4e4a) +TrainerWantsToFightText: TX_FAR _TrainerWantsToFightText db "@" -UnveiledGhostText: ; 58e4f (16:4e4f) +UnveiledGhostText: TX_FAR _UnveiledGhostText db "@" -GhostCantBeIDdText: ; 58e54 (16:4e54) +GhostCantBeIDdText: TX_FAR _GhostCantBeIDdText db "@" -PrintSendOutMonMessage: ; 58e59 (16:4e59) +PrintSendOutMonMessage: ld hl, wEnemyMonHP ld a, [hli] or [hl] @@ -104,10 +104,10 @@ PrintSendOutMonMessage: ; 58e59 (16:4e59) ld [H_MULTIPLICAND], a ld hl, wEnemyMonHP ld a, [hli] - ld [wcce3], a + ld [wLastSwitchInEnemyMonHP], a ld [H_MULTIPLICAND + 1], a ld a, [hl] - ld [wcce4], a + ld [wLastSwitchInEnemyMonHP + 1], a ld [H_MULTIPLICAND + 2], a ld a, 25 ld [H_MULTIPLIER], a @@ -120,7 +120,7 @@ PrintSendOutMonMessage: ; 58e59 (16:4e59) srl a rr b ld a, b - ld b, $4 + ld b, 4 ld [H_DIVISOR], 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 @@ -137,56 +137,56 @@ PrintSendOutMonMessage: ; 58e59 (16:4e59) .printText jp PrintText -GoText: ; 58eae (16:4eae) +GoText: TX_FAR _GoText - db $08 ; asm + TX_ASM jr PrintPlayerMon1Text -DoItText: ; 58eb5 (16:4eb5) +DoItText: TX_FAR _DoItText - db $08 ; asm + TX_ASM jr PrintPlayerMon1Text -GetmText: ; 58ebc (16:4ebc) +GetmText: TX_FAR _GetmText - db $08 ; asm + TX_ASM jr PrintPlayerMon1Text -EnemysWeakText: ; 58ec3 (16:4ec3) +EnemysWeakText: TX_FAR _EnemysWeakText - db $08 ; asm + TX_ASM PrintPlayerMon1Text: ld hl, PlayerMon1Text ret -PlayerMon1Text: ; 58ecc (16:4ecc) +PlayerMon1Text: TX_FAR _PlayerMon1Text db "@" -RetreatMon: ; 58ed1 (16:4ed1) +RetreatMon: ld hl, PlayerMon2Text jp PrintText -PlayerMon2Text: ; 58ed7 (16:4ed7) +PlayerMon2Text: TX_FAR _PlayerMon2Text - db $08 ; asm + TX_ASM push de push bc ld hl, wEnemyMonHP + 1 - ld de, wcce4 + ld de, wLastSwitchInEnemyMonHP + 1 ld b, [hl] dec hl ld a, [de] sub b - ld [$ff98], a + ld [H_MULTIPLICAND + 2], a dec de ld b, [hl] ld a, [de] sbc b - ld [$ff97], a - ld a, $19 - ld [H_POWEROFTEN], a + ld [H_MULTIPLICAND + 1], a + ld a, 25 + ld [H_MULTIPLIER], a call Multiply ld hl, wEnemyMonMaxHP ld a, [hli] @@ -196,43 +196,48 @@ PlayerMon2Text: ; 58ed7 (16:4ed7) srl a rr b ld a, b - ld b, $4 - ld [H_POWEROFTEN], a + ld b, 4 + ld [H_DIVISOR], a call Divide pop bc pop de - ld a, [$ff98] - ld hl, EnoughText + ld a, [H_QUOTIENT + 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. +; If the enemy mon has gained HP, then a is garbage due to wrap-around and +; can fall in any of the ranges below. + ld hl, EnoughText ; HP stayed the same and a ret z - ld hl, ComeBackText - cp $1e + ld hl, ComeBackText ; HP went down 1% - 29% + cp 30 ret c - ld hl, OKExclamationText - cp $46 + ld hl, OKExclamationText ; HP went down 30% - 69% + cp 70 ret c - ld hl, GoodText + ld hl, GoodText ; HP went down 70% or more ret -EnoughText: ; 58f25 (16:4f25) +EnoughText: TX_FAR _EnoughText - db $08 ; asm + TX_ASM jr PrintComeBackText -OKExclamationText: ; 58f2c (16:4f2c) +OKExclamationText: TX_FAR _OKExclamationText - db $08 ; asm + TX_ASM jr PrintComeBackText -GoodText: ; 58f33 (16:4f33) +GoodText: TX_FAR _GoodText - db $08 ; asm + TX_ASM jr PrintComeBackText -PrintComeBackText: ; 58f3a (16:4f3a) +PrintComeBackText: ld hl, ComeBackText ret -ComeBackText: ; 58f3e (16:4f3e) +ComeBackText: TX_FAR _ComeBackText db "@" diff --git a/engine/battle/core.asm b/engine/battle/core.asm index 48bed512..153a9048 100755 --- a/engine/battle/core.asm +++ b/engine/battle/core.asm @@ -1,7 +1,7 @@ BattleCore: ; These are move effects (second value from the Moves table in bank $E). -ResidualEffects1: ; 3c000 (f:4000) +ResidualEffects1: ; most non-side effects db CONVERSION_EFFECT db HAZE_EFFECT @@ -20,13 +20,13 @@ ResidualEffects1: ; 3c000 (f:4000) db LEECH_SEED_EFFECT db SPLASH_EFFECT db -1 -SetDamageEffects: ; 3c011 (f:4011) +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: ; 3c014 (f:4014) +ResidualEffects2: ; non-side effects not included in ResidualEffects1 ; stat-affecting moves, sleep-inflicting moves, and Bide ; e.g., Meditate, Bide, Hypnosis @@ -58,7 +58,7 @@ ResidualEffects2: ; 3c014 (f:4014) db ACCURACY_DOWN2_EFFECT db EVASION_DOWN2_EFFECT db -1 -AlwaysHappenSideEffects: ; 3c030 (f:4030) +AlwaysHappenSideEffects: ; Attacks that aren't finished after they faint the opponent. db DRAIN_HP_EFFECT db EXPLODE_EFFECT @@ -71,7 +71,7 @@ AlwaysHappenSideEffects: ; 3c030 (f:4030) db TWINEEDLE_EFFECT db RAGE_EFFECT db -1 -SpecialEffects: ; 3c03b (f:403b) +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 @@ -90,19 +90,19 @@ SpecialEffects: ; 3c03b (f:403b) db JUMP_KICK_EFFECT db RECOIL_EFFECT ; fallthrough to Next EffectsArray -SpecialEffectsCont: ; 3c049 (f:4049) +SpecialEffectsCont: ; damaging moves whose effect is executed prior to damage calculation db THRASH_PETAL_DANCE_EFFECT db TRAPPING_EFFECT db -1 -SlidePlayerAndEnemySilhouettesOnScreen: ; 3c04c (f:404c) +SlidePlayerAndEnemySilhouettesOnScreen: call LoadPlayerBackPic ld a, MESSAGE_BOX ; the usual text box at the bottom of the screen ld [wTextBoxID], a call DisplayTextBoxID - hlCoord 1, 5 - ld bc, $307 + coord hl, 1, 5 + lb bc, 3, 7 call ClearScreenArea call DisableLCD call LoadFontTilePatterns @@ -110,14 +110,14 @@ SlidePlayerAndEnemySilhouettesOnScreen: ; 3c04c (f:404c) ld hl, vBGMap0 ld bc, $400 .clearBackgroundLoop - ld a, $7f + ld a, " " ld [hli], a dec bc ld a, b or c jr nz, .clearBackgroundLoop ; copy the work RAM tile map to VRAM - ld hl, wTileMap + coord hl, 0, 0 ld de, vBGMap0 ld b, 18 ; number of rows .copyRowLoop @@ -175,27 +175,25 @@ SlidePlayerAndEnemySilhouettesOnScreen: ; 3c04c (f:404c) ld a, $1 ld [H_AUTOBGTRANSFERENABLED], a ld a, $31 - ld [$ffe1], a - hlCoord 1, 5 - predef Func_3f0c6 + ld [hStartTileID], a + coord hl, 1, 5 + predef CopyUncompressedPicToTilemap xor a ld [hWY], a ld [rWY], a inc a ld [H_AUTOBGTRANSFERENABLED], a call Delay3 - ld b, $1 - call GoPAL_SET + ld b, SET_PAL_BATTLE + call RunPaletteCommand call HideSprites - ld hl, PrintBeginningBattleText - ld b, BANK(PrintBeginningBattleText) - jp Bankswitch + jpab 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 ; the reason for this is that it shares Y coordinates with the lower part of the enemy pic, so background scrolling wouldn't work for both pics ; instead, the enemy pic is part of the background and uses the scroll register, while the player's head is a sprite and is slid by changing its X coordinates in a loop -SlidePlayerHeadLeft: ; 3c0ff (f:40ff) +SlidePlayerHeadLeft: push bc ld hl, wOAMBuffer + $01 ld c, $15 ; number of OAM entries @@ -209,7 +207,7 @@ SlidePlayerHeadLeft: ; 3c0ff (f:40ff) pop bc ret -SetScrollXForSlidingPlayerBodyLeft: ; 3c110 (f:4110) +SetScrollXForSlidingPlayerBodyLeft: ld a, [rLY] cp l jr nz, SetScrollXForSlidingPlayerBodyLeft @@ -221,13 +219,13 @@ SetScrollXForSlidingPlayerBodyLeft: ; 3c110 (f:4110) jr z, .loop ret -StartBattle: ; 3c11e (f:411e) +StartBattle: xor a ld [wPartyGainExpFlags], a ld [wPartyFoughtCurrentEnemyFlags], a - ld [wcd6a], a + ld [wActionResultOrTookBattleTurn], a inc a - ld [wd11d], a + ld [wFirstMonsNotOutYet], a ld hl, wEnemyMon1HP ld bc, wEnemyMon2 - wEnemyMon1 - 1 ld d, $3 @@ -241,7 +239,7 @@ StartBattle: ; 3c11e (f:411e) .foundFirstAliveEnemyMon ld a, d ld [wSerialExchangeNybbleReceiveData], a - ld a, [W_ISINBATTLE] + ld a, [wIsInBattle] dec a ; is it a trainer battle? call nz, EnemySendOutFirstMon ; if it is a trainer battle, send out enemy mon ld c, 40 @@ -253,17 +251,17 @@ StartBattle: ; 3c11e (f:411e) and a jp z, HandlePlayerBlackOut ; jump if no mon is alive call LoadScreenTilesFromBuffer1 - ld a, [W_BATTLETYPE] + ld a, [wBattleType] and a ; is it a normal battle? jp z, .playerSendOutFirstMon ; if so, send out player mon ; safari zone battle .displaySafariZoneBattleMenu call DisplayBattleMenu ret c ; return if the player ran from battle - ld a, [wcd6a] + ld a, [wActionResultOrTookBattleTurn] and a ; was the item used successfully? jr z, .displaySafariZoneBattleMenu ; if not, display the menu again; XXX does this ever jump? - ld a, [W_NUMSAFARIBALLS] + ld a, [wNumSafariBalls] and a jr nz, .notOutOfSafariBalls call LoadScreenTilesFromBuffer1 @@ -324,13 +322,13 @@ StartBattle: ; 3c11e (f:411e) ld [wcf91], a ld [wBattleMonSpecies2], a call LoadScreenTilesFromBuffer1 - hlCoord 1, 5 + coord hl, 1, 5 ld a, $9 call SlideTrainerPicOffScreen call SaveScreenTilesToBuffer1 ld a, [wWhichPokemon] ld c, a - ld b, $1 + ld b, FLAG_SET push bc ld hl, wPartyGainExpFlags predef FlagActionPredef @@ -343,7 +341,7 @@ StartBattle: ; 3c11e (f:411e) jr MainInBattleLoop ; wild mon or link battle enemy ran from battle -EnemyRan: ; 3c202 (f:4202) +EnemyRan: call LoadScreenTilesFromBuffer1 ld a, [wLinkState] cp LINK_STATE_BATTLING @@ -355,23 +353,21 @@ EnemyRan: ; 3c202 (f:4202) ld hl, EnemyRanText .printText call PrintText - ld a, (SFX_08_44 - SFX_Headers_08) / 3 + ld a, SFX_RUN call PlaySoundWaitForCurrent xor a ld [H_WHOSETURN], a - ld hl, AnimationSlideEnemyMonOut - ld b, BANK(AnimationSlideEnemyMonOut) - jp Bankswitch + jpab AnimationSlideEnemyMonOff -WildRanText: ; 3c229 (f:4229) +WildRanText: TX_FAR _WildRanText db "@" -EnemyRanText: ; 3c22e (f:422e) +EnemyRanText: TX_FAR _EnemyRanText db "@" -MainInBattleLoop: ; 3c233 (f:4233) +MainInBattleLoop: call ReadPlayerMonCurHPAndStatus ld hl, wBattleMonHP ld a, [hli] @@ -383,14 +379,14 @@ MainInBattleLoop: ; 3c233 (f:4233) jp z, HandleEnemyMonFainted ; if enemy mon HP is 0, jump call SaveScreenTilesToBuffer1 xor a - ld [wd11d], a - ld a, [W_PLAYERBATTSTATUS2] + ld [wFirstMonsNotOutYet], a + ld a, [wPlayerBattleStatus2] and (1 << NeedsToRecharge) | (1 << UsingRage) ; check if the player is using Rage or needs to recharge jr nz, .selectEnemyMove ; the player is not using Rage and doesn't need to recharge - ld hl, W_ENEMYBATTSTATUS1 + ld hl, wEnemyBattleStatus1 res Flinched, [hl] ; reset flinch bit - ld hl, W_PLAYERBATTSTATUS1 + ld hl, wPlayerBattleStatus1 res Flinched, [hl] ; reset flinch bit ld a, [hl] and (1 << ThrashingAbout) | (1 << ChargingUp) ; check if the player is thrashing about or charging for an attack @@ -404,10 +400,10 @@ MainInBattleLoop: ; 3c233 (f:4233) ld a, [wBattleMonStatus] and (1 << FRZ) | SLP ; is mon frozen or asleep? jr nz, .selectEnemyMove ; if so, jump - ld a, [W_PLAYERBATTSTATUS1] + ld a, [wPlayerBattleStatus1] and (1 << StoringEnergy) | (1 << UsingTrappingMove) ; check player is using Bide or using a multi-turn attack like wrap jr nz, .selectEnemyMove ; if so, jump - ld a, [W_ENEMYBATTSTATUS1] + ld a, [wEnemyBattleStatus1] bit UsingTrappingMove, a ; check if enemy is using a multi-turn attack like wrap jr z, .selectPlayerMove ; if not, jump ; enemy is using a mult-turn attack like wrap, so player is trapped and cannot execute a move @@ -415,12 +411,12 @@ MainInBattleLoop: ; 3c233 (f:4233) ld [wPlayerSelectedMove], a jr .selectEnemyMove .selectPlayerMove - ld a, [wcd6a] - and a + ld a, [wActionResultOrTookBattleTurn] + and a ; has the player already used the turn (e.g. by using an item, trying to run or switching pokemon) jr nz, .selectEnemyMove ld [wMoveMenuType], a inc a - ld [W_ANIMATIONID], a + ld [wAnimationID], a xor a ld [wMenuItemToSwap], a call MoveSelectionMenu @@ -436,18 +432,18 @@ MainInBattleLoop: ; 3c233 (f:4233) jr nz, .noLinkBattle ; link battle ld a, [wSerialExchangeNybbleReceiveData] - cp $f + cp LINKBATTLE_RUN jp z, EnemyRan - cp $e + cp LINKBATTLE_STRUGGLE jr z, .noLinkBattle - cp $d + cp LINKBATTLE_NO_ACTION jr z, .noLinkBattle - sub $4 + sub 4 jr c, .noLinkBattle ; the link battle enemy has switched mons - ld a, [W_PLAYERBATTSTATUS1] + ld a, [wPlayerBattleStatus1] bit UsingTrappingMove, a ; check if using multi-turn move like Wrap - jr z, .asm_3c2dd + jr z, .specialMoveNotUsed ld a, [wPlayerMoveListIndex] ld hl, wBattleMonMoves ld c, a @@ -456,9 +452,9 @@ MainInBattleLoop: ; 3c233 (f:4233) ld a, [hl] cp METRONOME ; a MIRROR MOVE check is missing, might lead to a desync in link battles ; when combined with multi-turn moves - jr nz, .asm_3c2dd + jr nz, .specialMoveNotUsed ld [wPlayerSelectedMove], a -.asm_3c2dd +.specialMoveNotUsed callab SwitchEnemyMon .noLinkBattle ld a, [wPlayerSelectedMove] @@ -492,8 +488,8 @@ MainInBattleLoop: ; 3c233 (f:4233) jr nc, .playerMovesFirst ; if player is faster jr .enemyMovesFirst ; if enemy is faster .speedEqual ; 50/50 chance for both players - ld a, [$ffaa] - cp $2 + ld a, [hSerialConnectionStatus] + cp USING_INTERNAL_CLOCK jr z, .invertOutcome call BattleRandom cp $80 @@ -561,7 +557,7 @@ MainInBattleLoop: ; 3c233 (f:4233) call CheckNumAttacksLeft jp MainInBattleLoop -HandlePoisonBurnLeechSeed: ; 3c3bd (f:43bd) +HandlePoisonBurnLeechSeed: ld hl, wBattleMonHP ld de, wBattleMonStatus ld a, [H_WHOSETURN] @@ -588,11 +584,11 @@ HandlePoisonBurnLeechSeed: ; 3c3bd (f:43bd) pop hl call HandlePoisonBurnLeechSeed_DecreaseOwnHP .notBurnedOrPoisoned - ld de, W_PLAYERBATTSTATUS2 + ld de, wPlayerBattleStatus2 ld a, [H_WHOSETURN] and a jr z, .playersTurn2 - ld de, W_ENEMYBATTSTATUS2 + ld de, wEnemyBattleStatus2 .playersTurn2 ld a, [de] add a @@ -620,20 +616,20 @@ HandlePoisonBurnLeechSeed: ; 3c3bd (f:43bd) or [hl] ret nz ; test if fainted call DrawHUDsAndHPBars - ld c, $14 + ld c, 20 call DelayFrames xor a ret -HurtByPoisonText: ; 3c42e (f:442e) +HurtByPoisonText: TX_FAR _HurtByPoisonText db "@" -HurtByBurnText: ; 3c433 (f:4433) +HurtByBurnText: TX_FAR _HurtByBurnText db "@" -HurtByLeechSeedText: ; 3c438 (f:4438) +HurtByLeechSeedText: TX_FAR _HurtByLeechSeedText db "@" @@ -641,7 +637,7 @@ HurtByLeechSeedText: ; 3c438 (f:4438) ; note that the toxic ticks are considered even if the damage is not poison (hence the Leech Seed glitch) ; hl: HP pointer ; bc (out): total damage -HandlePoisonBurnLeechSeed_DecreaseOwnHP: ; 3c43d (f:443d) +HandlePoisonBurnLeechSeed_DecreaseOwnHP: push hl push hl ld bc, $e ; skip to max HP @@ -663,13 +659,13 @@ HandlePoisonBurnLeechSeed_DecreaseOwnHP: ; 3c43d (f:443d) jr nz, .nonZeroDamage inc c ; damage is at least 1 .nonZeroDamage - ld hl, W_PLAYERBATTSTATUS3 - ld de, W_PLAYERTOXICCOUNTER + ld hl, wPlayerBattleStatus3 + ld de, wPlayerToxicCounter ld a, [H_WHOSETURN] and a jr z, .playersTurn - ld hl, W_ENEMYBATTSTATUS3 - ld de, W_ENEMYTOXICCOUNTER + ld hl, wEnemyBattleStatus3 + ld de, wEnemyToxicCounter .playersTurn bit BadlyPoisoned, [hl] jr z, .noToxic @@ -709,7 +705,7 @@ HandlePoisonBurnLeechSeed_DecreaseOwnHP: ; 3c43d (f:443d) ; adds bc to enemy HP ; bc isn't updated if HP substracted was capped to prevent overkill -HandlePoisonBurnLeechSeed_IncreaseEnemyHP: ; 3c4a3 (f:44a3) +HandlePoisonBurnLeechSeed_IncreaseEnemyHP: push hl ld hl, wEnemyMonMaxHP ld a, [H_WHOSETURN] @@ -721,8 +717,8 @@ HandlePoisonBurnLeechSeed_IncreaseEnemyHP: ; 3c4a3 (f:44a3) ld [wHPBarMaxHP+1], a ld a, [hl] ld [wHPBarMaxHP], a - ld de, $fff2 - add hl, de ; skip back fomr max hp to current hp + ld de, wBattleMonHP - wBattleMonMaxHP + add hl, de ; skip back from max hp to current hp ld a, [hl] ld [wHPBarOldHP], a ; add bc to current HP add c @@ -759,13 +755,13 @@ HandlePoisonBurnLeechSeed_IncreaseEnemyHP: ; 3c4a3 (f:44a3) pop hl ret -UpdateCurMonHPBar: ; 3c4f6 (f:44f6) - hlCoord 10, 9 ; tile pointer to player HP bar +UpdateCurMonHPBar: + coord hl, 10, 9 ; tile pointer to player HP bar ld a, [H_WHOSETURN] and a ld a, $1 jr z, .playersTurn - hlCoord 2, 2 ; tile pointer to enemy HP bar + coord hl, 2, 2 ; tile pointer to enemy HP bar xor a .playersTurn push bc @@ -774,25 +770,25 @@ UpdateCurMonHPBar: ; 3c4f6 (f:44f6) pop bc ret -CheckNumAttacksLeft: ; 3c50f (f:450f) +CheckNumAttacksLeft: ld a, [wPlayerNumAttacksLeft] and a jr nz, .checkEnemy ; player has 0 attacks left - ld hl, W_PLAYERBATTSTATUS1 + ld hl, wPlayerBattleStatus1 res UsingTrappingMove, [hl] ; player not using multi-turn attack like wrap any more .checkEnemy ld a, [wEnemyNumAttacksLeft] and a ret nz ; enemy has 0 attacks left - ld hl, W_ENEMYBATTSTATUS1 + ld hl, wEnemyBattleStatus1 res UsingTrappingMove, [hl] ; enemy not using multi-turn attack like wrap any more ret -HandleEnemyMonFainted: ; 3c525 (f:4525) +HandleEnemyMonFainted: xor a - ld [wccf0], a + ld [wInHandlePlayerMonFainted], a call FaintEnemyPokemon call AnyPartyAlive ld a, d @@ -802,7 +798,7 @@ HandleEnemyMonFainted: ; 3c525 (f:4525) ld a, [hli] or [hl] ; is battle mon HP zero? call nz, DrawPlayerHUDAndHPBar ; if battle mon HP is not zero, draw player HD and HP bar - ld a, [W_ISINBATTLE] + ld a, [wIsInBattle] dec a ret z ; return if it's a wild battle call AnyEnemyPokemonAliveCheck @@ -816,16 +812,16 @@ HandleEnemyMonFainted: ; 3c525 (f:4525) call ChooseNextMon .skipReplacingBattleMon ld a, $1 - ld [wcd6a], a + ld [wActionResultOrTookBattleTurn], a call ReplaceFaintedEnemyMon jp z, EnemyRan xor a - ld [wcd6a], a + ld [wActionResultOrTookBattleTurn], a jp MainInBattleLoop -FaintEnemyPokemon ; 0x3c567 +FaintEnemyPokemon: call ReadPlayerMonCurHPAndStatus - ld a, [W_ISINBATTLE] + ld a, [wIsInBattle] dec a jr z, .wild ld a, [wEnemyMonPartyPos] @@ -836,41 +832,50 @@ FaintEnemyPokemon ; 0x3c567 ld [hli], a ld [hl], a .wild - ld hl, W_PLAYERBATTSTATUS1 + ld hl, wPlayerBattleStatus1 res AttackingMultipleTimes, [hl] - xor a - ld [wPlayerNumHits], a +; Bug. This only zeroes the high byte of the player's accumulated damage, +; setting the accumulated damage to itself mod 256 instead of 0 as was probably +; intended. That alone is problematic, but this mistake has another more severe +; effect. This function's counterpart for when the player mon faints, +; RemoveFaintedPlayerMon, zeroes both the high byte and the low byte. In a link +; battle, the other player's Game Boy will call that function in response to +; the enemy mon (the player mon from the other side's perspective) fainting, +; and the states of the two Game Boys will go out of sync unless the damage +; was congruent to 0 modulo 256. + xor a + ld [wPlayerBideAccumulatedDamage], a ld hl, wEnemyStatsToDouble ; clear enemy statuses ld [hli], a ld [hli], a ld [hli], a ld [hli], a ld [hl], a - ld [W_ENEMYDISABLEDMOVE], a - ld [wccef], a - ld [wccf3], a + ld [wEnemyDisabledMove], a + ld [wEnemyDisabledMoveNumber], a + ld [wEnemyMonMinimized], a ld hl, wPlayerUsedMove ld [hli], a ld [hl], a - hlCoord 12, 5 - deCoord 12, 6 + coord hl, 12, 5 + coord de, 12, 6 call SlideDownFaintedMonPic - ld hl, wTileMap - ld bc, $40b + coord hl, 0, 0 + lb bc, 4, 11 call ClearScreenArea - ld a, [W_ISINBATTLE] + ld a, [wIsInBattle] dec a jr z, .wild_win xor a - ld [wc0f1], a - ld [wc0f2], a - ld a, (SFX_08_48 - SFX_Headers_08) / 3 ; SFX_FALL? + ld [wFrequencyModifier], a + ld [wTempoModifier], a + ld a, SFX_FAINT_FALL call PlaySoundWaitForCurrent .sfxwait - ld a, [wc02a] - cp (SFX_08_48 - SFX_Headers_08) / 3 + ld a, [wChannelSoundIDs + Ch4] + cp SFX_FAINT_FALL jr z, .sfxwait - ld a, (SFX_08_43 - SFX_Headers_08) / 3 ; SFX_DROP + ld a, SFX_FAINT_THUD call PlaySound call WaitForSoundToFinish jr .sfxplayed @@ -879,13 +884,15 @@ FaintEnemyPokemon ; 0x3c567 ld a, MUSIC_DEFEATED_WILD_MON call PlayBattleVictoryMusic .sfxplayed +; bug: win sfx is played for wild battles before checking for player mon HP +; this can lead to odd scenarios where both player and enemy faint, as the win sfx plays yet the player never won the battle ld hl, wBattleMonHP ld a, [hli] or [hl] jr nz, .playermonnotfaint - ld a, [wccf0] - and a - jr nz, .playermonnotfaint + ld a, [wInHandlePlayerMonFainted] + and a ; was this called by HandlePlayerMonFainted? + jr nz, .playermonnotfaint ; if so, don't call RemoveFaintedPlayerMon twice call RemoveFaintedPlayerMon .playermonnotfaint call AnyPartyAlive @@ -898,7 +905,7 @@ FaintEnemyPokemon ; 0x3c567 call SaveScreenTilesToBuffer1 xor a ld [wBattleResult], a - ld b, EXP__ALL + ld b, EXP_ALL call IsItemInBag push af jr z, .giveExpToMonsThatFought ; if no exp all, then jump @@ -938,23 +945,23 @@ FaintEnemyPokemon ; 0x3c567 jr nz, .gainExpFlagsLoop ld a, b ld [wPartyGainExpFlags], a - ld hl, GainExperience - ld b, BANK(GainExperience) - jp Bankswitch + jpab GainExperience -EnemyMonFaintedText: ; 0x3c63e +EnemyMonFaintedText: TX_FAR _EnemyMonFaintedText db "@" -EndLowHealthAlarm: ; 3c643 (f:4643) +EndLowHealthAlarm: +; This function is called when the player has the won the battle. It turns off +; the low health alarm and prevents it from reactivating until the next battle. xor a - ld [wLowHealthAlarm], a ;disable low health alarm - ld [wc02a], a + ld [wLowHealthAlarm], a ; turn off low health alarm + ld [wChannelSoundIDs + Ch4], a inc a - ld [wccf6], a + ld [wLowHealthAlarmDisabled], a ; prevent it from reactivating ret -AnyEnemyPokemonAliveCheck: ; 3c64f (f:464f) +AnyEnemyPokemonAliveCheck: ld a, [wEnemyPartyCount] ld b, a xor a @@ -972,8 +979,8 @@ AnyEnemyPokemonAliveCheck: ; 3c64f (f:464f) ret ; stores whether enemy ran in Z flag -ReplaceFaintedEnemyMon: ; 3c664 (f:4664) - ld hl, wcf1e +ReplaceFaintedEnemyMon: + ld hl, wEnemyHPBarColor ld e, $30 call GetBattleHealthBarColor callab DrawEnemyPokeballs @@ -983,31 +990,31 @@ ReplaceFaintedEnemyMon: ; 3c664 (f:4664) ; link battle call LinkBattleExchangeData ld a, [wSerialExchangeNybbleReceiveData] - cp $f + cp LINKBATTLE_RUN ret z call LoadScreenTilesFromBuffer1 .notLinkBattle call EnemySendOut xor a - ld [W_ENEMYMOVENUM], a - ld [wcd6a], a + ld [wEnemyMoveNum], a + ld [wActionResultOrTookBattleTurn], a ld [wAILayer2Encouragement], a inc a ; reset Z flag ret -TrainerBattleVictory: ; 3c696 (f:4696) +TrainerBattleVictory: call EndLowHealthAlarm ld b, MUSIC_DEFEATED_GYM_LEADER - ld a, [W_GYMLEADERNO] + ld a, [wGymLeaderNo] and a jr nz, .gymleader ld b, MUSIC_DEFEATED_TRAINER .gymleader - ld a, [W_TRAINERCLASS] + ld a, [wTrainerClass] cp SONY3 ; final battle against rival jr nz, .notrival ld b, MUSIC_DEFEATED_GYM_LEADER - ld hl, W_FLAGS_D733 + ld hl, wFlags_D733 set 1, [hl] .notrival ld a, [wLinkState] @@ -1020,37 +1027,38 @@ TrainerBattleVictory: ; 3c696 (f:4696) cp LINK_STATE_BATTLING ret z call ScrollTrainerPicAfterBattle - ld c, $28 + ld c, 40 call DelayFrames call PrintEndBattleText +; win money ld hl, MoneyForWinningText call PrintText ld de, wPlayerMoney + 2 - ld hl, wd07b + ld hl, wAmountMoneyWon + 2 ld c, $3 predef_jump AddBCDPredef -MoneyForWinningText: ; 3c6e4 (f:46e4) +MoneyForWinningText: TX_FAR _MoneyForWinningText db "@" -TrainerDefeatedText: ; 3c6e9 (f:46e9) +TrainerDefeatedText: TX_FAR _TrainerDefeatedText db "@" -PlayBattleVictoryMusic: ; 3c6ee (f:46ee) +PlayBattleVictoryMusic: push af ld a, $ff - ld [wc0ee], a + ld [wNewSoundID], a call PlaySoundWaitForCurrent ld c, BANK(Music_DefeatedTrainer) pop af call PlayMusic jp Delay3 -HandlePlayerMonFainted: ; 3c700 (f:4700) - ld a, $1 - ld [wccf0], a +HandlePlayerMonFainted: + ld a, 1 + ld [wInHandlePlayerMonFainted], a call RemoveFaintedPlayerMon call AnyPartyAlive ; test if any more mons are alive ld a, d @@ -1062,7 +1070,7 @@ HandlePlayerMonFainted: ; 3c700 (f:4700) jr nz, .doUseNextMonDialogue ; if not, jump ; the enemy mon has 0 HP call FaintEnemyPokemon - ld a, [W_ISINBATTLE] + ld a, [wIsInBattle] dec a ret z ; if wild encounter, battle is over call AnyEnemyPokemonAliveCheck @@ -1074,21 +1082,21 @@ HandlePlayerMonFainted: ; 3c700 (f:4700) jp nz, MainInBattleLoop ; if the enemy mon has more than 0 HP, go back to battle loop ; the enemy mon has 0 HP ld a, $1 - ld [wcd6a], a + ld [wActionResultOrTookBattleTurn], a call ReplaceFaintedEnemyMon jp z, EnemyRan ; if enemy ran from battle rather than sending out another mon, jump xor a - ld [wcd6a], a + ld [wActionResultOrTookBattleTurn], a jp MainInBattleLoop ; resets flags, slides mon's pic down, plays cry, and prints fainted message -RemoveFaintedPlayerMon: ; 3c741 (f:4741) +RemoveFaintedPlayerMon: ld a, [wPlayerMonNumber] ld c, a ld hl, wPartyGainExpFlags - ld b, $0 + ld b, FLAG_RESET predef FlagActionPredef ; clear gain exp flag for fainted mon - ld hl, W_ENEMYBATTSTATUS1 + ld hl, wEnemyBattleStatus1 res 2, [hl] ; reset "attacking multiple times" flag ld a, [wLowHealthAlarm] bit 7, a ; skip sound flag (red bar (?)) @@ -1097,52 +1105,57 @@ RemoveFaintedPlayerMon: ; 3c741 (f:4741) ld [wLowHealthAlarm], a ;disable low health alarm call WaitForSoundToFinish .skipWaitForSound -; bug? if the player mon faints while the enemy mon is using bide, -; the accumulated damage is overwritten. xxx what values can [wLowHealthAlarm] have here? +; a is 0, so this zeroes the enemy's accumulated damage. ld hl, wEnemyBideAccumulatedDamage ld [hli], a ld [hl], a ld [wBattleMonStatus], a call ReadPlayerMonCurHPAndStatus - hlCoord 9, 7 - ld bc, $50b + coord hl, 9, 7 + lb bc, 5, 11 call ClearScreenArea - hlCoord 1, 10 - deCoord 1, 11 + coord hl, 1, 10 + coord de, 1, 11 call SlideDownFaintedMonPic ld a, $1 ld [wBattleResult], a - ld a, [wccf0] - and a - ret z + +; When the player mon and enemy mon faint at the same time and the fact that the +; enemy mon has fainted is detected first (e.g. when the player mon knocks out +; the enemy mon using a move with recoil and faints due to the recoil), don't +; play the player mon's cry or show the "[player mon] fainted!" message. + ld a, [wInHandlePlayerMonFainted] + and a ; was this called by HandleEnemyMonFainted? + ret z ; if so, return + ld a, [wBattleMonSpecies] call PlayCry ld hl, PlayerMonFaintedText jp PrintText -PlayerMonFaintedText: ; 3c796 (f:4796) +PlayerMonFaintedText: TX_FAR _PlayerMonFaintedText db "@" ; asks if you want to use next mon ; stores whether you ran in C flag -DoUseNextMonDialogue: ; 3c79b (f:479b) +DoUseNextMonDialogue: call PrintEmptyString call SaveScreenTilesToBuffer1 - ld a, [W_ISINBATTLE] + ld a, [wIsInBattle] and a dec a ret nz ; return if it's a trainer battle ld hl, UseNextMonText call PrintText .displayYesNoBox - hlCoord 13, 9 - ld bc, $a0e + coord hl, 13, 9 + lb bc, 10, 14 ld a, TWO_OPTION_MENU ld [wTextBoxID], a call DisplayTextBoxID - ld a, [wd12e] - cp $2 ; did the player choose NO? + ld a, [wMenuExitMethod] + cp CHOSE_SECOND_ITEM ; did the player choose NO? jr z, .tryRunning ; if the player chose NO, try running and a ; reset carry ret @@ -1154,15 +1167,15 @@ DoUseNextMonDialogue: ; 3c79b (f:479b) ld de, wEnemyMonSpeed jp TryRunningFromBattle -UseNextMonText: ; 3c7d3 (f:47d3) +UseNextMonText: TX_FAR _UseNextMonText db "@" ; choose next player mon to send out ; stores whether enemy mon has no HP left in Z flag -ChooseNextMon: ; 3c7d8 (f:47d8) - ld a, $2 - ld [wd07d], a +ChooseNextMon: + ld a, BATTLE_PARTY_MENU + ld [wPartyMenuTypeOrMessageID], a call DisplayPartyMenu .checkIfMonChosen jr nc, .monChosen @@ -1176,17 +1189,17 @@ ChooseNextMon: ; 3c7d8 (f:47d8) cp LINK_STATE_BATTLING jr nz, .notLinkBattle inc a - ld [wcd6a], a + ld [wActionResultOrTookBattleTurn], a call LinkBattleExchangeData .notLinkBattle xor a - ld [wcd6a], a + ld [wActionResultOrTookBattleTurn], a call ClearSprites ld a, [wWhichPokemon] ld [wPlayerMonNumber], a ld c, a ld hl, wPartyGainExpFlags - ld b, $1 + ld b, FLAG_SET push bc predef FlagActionPredef pop bc @@ -1196,7 +1209,7 @@ ChooseNextMon: ; 3c7d8 (f:47d8) call GBPalWhiteOut call LoadHudTilePatterns call LoadScreenTilesFromBuffer1 - call GoPAL_SET_CF1C + call RunDefaultPaletteCommand call GBPalNormal call SendOutMon ld hl, wEnemyMonHP @@ -1206,27 +1219,27 @@ ChooseNextMon: ; 3c7d8 (f:47d8) ; called when player is out of usable mons. ; prints approriate lose message, sets carry flag if player blacked out (special case for initial rival fight) -HandlePlayerBlackOut: ; 3c837 (f:4837) +HandlePlayerBlackOut: ld a, [wLinkState] cp LINK_STATE_BATTLING jr z, .notSony1Battle - ld a, [W_CUROPPONENT] - cp $c8 + SONY1 + ld a, [wCurOpponent] + cp OPP_SONY1 jr nz, .notSony1Battle - ld hl, wTileMap ; sony 1 battle - ld bc, $815 + coord hl, 0, 0 ; sony 1 battle + lb bc, 8, 21 call ClearScreenArea call ScrollTrainerPicAfterBattle - ld c, $28 + ld c, 40 call DelayFrames ld hl, Sony1WinText call PrintText - ld a, [W_CURMAP] + ld a, [wCurMap] cp OAKS_LAB ret z ; starter battle in oak's lab: don't black out .notSony1Battle - ld b, $0 - call GoPAL_SET + ld b, SET_PAL_BATTLE_BLACK + call RunPaletteCommand ld hl, PlayerBlackedOutText2 ld a, [wLinkState] cp LINK_STATE_BATTLING @@ -1241,21 +1254,21 @@ HandlePlayerBlackOut: ; 3c837 (f:4837) scf ret -Sony1WinText: ; 3c884 (f:4884) +Sony1WinText: TX_FAR _Sony1WinText db "@" -PlayerBlackedOutText2: ; 3c889 (f:4889) +PlayerBlackedOutText2: TX_FAR _PlayerBlackedOutText2 db "@" -LinkBattleLostText: ; 3c88e (f:488e) +LinkBattleLostText: TX_FAR _LinkBattleLostText db "@" ; slides pic of fainted mon downwards until it disappears ; bug: when this is called, [H_AUTOBGTRANSFERENABLED] is non-zero, so there is screen tearing -SlideDownFaintedMonPic: ; 3c893 (f:4893) +SlideDownFaintedMonPic: ld a, [wd730] push af set 6, a @@ -1274,7 +1287,7 @@ SlideDownFaintedMonPic: ; 3c893 (f:4893) call CopyData pop de pop hl - ld bc, -20 + ld bc, -SCREEN_WIDTH add hl, bc push hl ld h, d @@ -1286,7 +1299,7 @@ SlideDownFaintedMonPic: ; 3c893 (f:4893) pop bc dec b jr nz, .rowLoop - ld bc, 20 + ld bc, SCREEN_WIDTH add hl, bc ld de, SevenSpacesText call PlaceString @@ -1301,15 +1314,15 @@ SlideDownFaintedMonPic: ; 3c893 (f:4893) ld [wd730], a ret -SevenSpacesText: ; 3c8d7 (f:48d7) +SevenSpacesText: db " @" ; 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 -SlideTrainerPicOffScreen: ; 3c8df (f:48df) - ld [$FF8B], a +SlideTrainerPicOffScreen: + ld [hSlideAmount], a ld c, a .slideStepLoop ; each iteration, the trainer pic is slid one tile left/right push bc @@ -1317,10 +1330,10 @@ SlideTrainerPicOffScreen: ; 3c8df (f:48df) ld b, 7 ; number of rows .rowLoop push hl - ld a, [$FF8B] + ld a, [hSlideAmount] ld c, a .columnLoop - ld a, [$FF8B] + ld a, [hSlideAmount] cp 8 jr z, .slideRight .slideLeft ; slide player sprite off screen @@ -1349,13 +1362,13 @@ SlideTrainerPicOffScreen: ; 3c8df (f:48df) ret ; send out a trainer's mon -EnemySendOut: ; 3c90e (f:490e) +EnemySendOut: ld hl,wPartyGainExpFlags xor a ld [hl],a ld a,[wPlayerMonNumber] ld c,a - ld b,1 + ld b,FLAG_SET push bc predef FlagActionPredef ld hl,wPartyFoughtCurrentEnemyFlags @@ -1365,7 +1378,7 @@ EnemySendOut: ; 3c90e (f:490e) predef FlagActionPredef ; don't change wPartyGainExpFlags or wPartyFoughtCurrentEnemyFlags -EnemySendOutFirstMon: ; 3c92a (f:492a) +EnemySendOutFirstMon: xor a ld hl,wEnemyStatsToDouble ; clear enemy statuses ld [hli],a @@ -1373,17 +1386,17 @@ EnemySendOutFirstMon: ; 3c92a (f:492a) ld [hli],a ld [hli],a ld [hl],a - ld [W_ENEMYDISABLEDMOVE],a - ld [wccef],a - ld [wccf3],a + ld [wEnemyDisabledMove],a + ld [wEnemyDisabledMoveNumber],a + ld [wEnemyMonMinimized],a ld hl,wPlayerUsedMove ld [hli],a ld [hl],a dec a ld [wAICount],a - ld hl,W_PLAYERBATTSTATUS1 + ld hl,wPlayerBattleStatus1 res 5,[hl] - hlCoord 18, 0 + coord hl, 18, 0 ld a,8 call SlideTrainerPicOffScreen call PrintEmptyString @@ -1421,7 +1434,7 @@ EnemySendOutFirstMon: ; 3c92a (f:492a) ld bc,wEnemyMon2 - wEnemyMon1 call AddNTimes ld a,[hl] - ld [W_CURENEMYLVL],a + ld [wCurEnemyLVL],a ld a,[wWhichPokemon] inc a ld hl,wEnemyPartyCount @@ -1434,12 +1447,12 @@ EnemySendOutFirstMon: ; 3c92a (f:492a) call LoadEnemyMonData ld hl,wEnemyMonHP ld a,[hli] - ld [wcce3],a + ld [wLastSwitchInEnemyMonHP],a ld a,[hl] - ld [wcce4],a + ld [wLastSwitchInEnemyMonHP + 1],a ld a,1 ld [wCurrentMenuItem],a - ld a,[wd11d] + ld a,[wFirstMonsNotOutYet] dec a jr z,.next4 ld a,[wPartyCount] @@ -1448,21 +1461,21 @@ EnemySendOutFirstMon: ; 3c92a (f:492a) ld a,[wLinkState] cp LINK_STATE_BATTLING jr z,.next4 - ld a,[W_OPTIONS] + ld a,[wOptions] bit 6,a jr nz,.next4 ld hl, TrainerAboutToUseText call PrintText - hlCoord 0, 7 - ld bc,$0801 + coord hl, 0, 7 + lb bc, 8, 1 ld a,TWO_OPTION_MENU ld [wTextBoxID],a call DisplayTextBoxID ld a,[wCurrentMenuItem] and a jr nz,.next4 - ld a,2 - ld [wd07d],a + ld a,BATTLE_PARTY_MENU + ld [wPartyMenuTypeOrMessageID],a call DisplayPartyMenu .next9 ld a,1 @@ -1488,11 +1501,11 @@ EnemySendOutFirstMon: ; 3c92a (f:492a) call LoadScreenTilesFromBuffer1 .next4 call ClearSprites - ld hl,wTileMap - ld bc,$040B + coord hl, 0, 0 + lb bc, 4, 11 call ClearScreenArea - ld b,1 - call GoPAL_SET + ld b, SET_PAL_BATTLE + call RunPaletteCommand call GBPalNormal ld hl,TrainerSentOutText call PrintText @@ -1502,10 +1515,10 @@ EnemySendOutFirstMon: ; 3c92a (f:492a) call GetMonHeader ld de,vFrontPic call LoadMonFrontSprite - ld a,$CF - ld [$FFE1],a - hlCoord 15, 6 - predef Func_3f073 + ld a,-$31 + ld [hStartTileID],a + coord hl, 15, 6 + predef AnimateSendingOutMon ld a,[wEnemyMonSpecies2] call PlayCry call DrawEnemyHUDAndHPBar @@ -1518,17 +1531,17 @@ EnemySendOutFirstMon: ; 3c92a (f:492a) call SaveScreenTilesToBuffer1 jp SwitchPlayerMon -TrainerAboutToUseText: ; 3ca79 (f:4a79) +TrainerAboutToUseText: TX_FAR _TrainerAboutToUseText db "@" -TrainerSentOutText: ; 3ca7e (f:4a7e) +TrainerSentOutText: TX_FAR _TrainerSentOutText db "@" ; 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: ; 3ca83 (f:4a83) +AnyPartyAlive: ld a, [wPartyCount] ld e, a xor a @@ -1546,7 +1559,7 @@ AnyPartyAlive: ; 3ca83 (f:4a83) ; tests if player mon has fainted ; stores whether mon has fainted in Z flag -HasMonFainted: ; 3ca97 (f:4a97) +HasMonFainted: ld a, [wWhichPokemon] ld hl, wPartyMon1HP ld bc, wPartyMon2 - wPartyMon1 @@ -1554,7 +1567,7 @@ HasMonFainted: ; 3ca97 (f:4a97) ld a, [hli] or [hl] ret nz - ld a, [wd11d] + ld a, [wFirstMonsNotOutYet] and a jr nz, .done ld hl, NoWillText @@ -1563,22 +1576,22 @@ HasMonFainted: ; 3ca97 (f:4a97) xor a ret -NoWillText: ; 3cab4 (f:4ab4) +NoWillText: TX_FAR _NoWillText db "@" ; try to run from battle (hl = player speed, de = enemy speed) ; stores whether the attempt was successful in carry flag -TryRunningFromBattle: ; 3cab9 (f:4ab9) +TryRunningFromBattle: call IsGhostBattle jp z, .canEscape ; jump if it's a ghost battle - ld a, [W_BATTLETYPE] - cp $2 + ld a, [wBattleType] + cp BATTLE_TYPE_SAFARI jp z, .canEscape ; jump if it's a safari battle ld a, [wLinkState] cp LINK_STATE_BATTLING jp z, .canEscape - ld a, [W_ISINBATTLE] + ld a, [wIsInBattle] dec a jr nz, .trainerBattle ; jump if it's a trainer battle ld a, [wNumRunAttempts] @@ -1589,14 +1602,14 @@ TryRunningFromBattle: ; 3cab9 (f:4ab9) ld a, [hl] ld [H_MULTIPLICAND + 2], a ld a, [de] - ld [$ff8d], a + ld [hEnemySpeed], a inc de ld a, [de] - ld [$ff8e], a + ld [hEnemySpeed + 1], a call LoadScreenTilesFromBuffer1 ld de, H_MULTIPLICAND + 1 - ld hl, $ff8d - ld c, $2 + ld hl, hEnemySpeed + ld c, 2 call StringCmp jr nc, .canEscape ; jump if player speed greater than enemy speed xor a @@ -1608,9 +1621,9 @@ TryRunningFromBattle: ; 3cab9 (f:4ab9) ld [H_DIVIDEND], a ld a, [H_PRODUCT + 3] ld [H_DIVIDEND + 1], a - ld a, [$ff8d] + ld a, [hEnemySpeed] ld b, a - ld a, [$ff8e] + ld a, [hEnemySpeed + 1] ; divide enemy speed by 4 srl b rr a @@ -1641,19 +1654,19 @@ TryRunningFromBattle: ; 3cab9 (f:4ab9) ld b, a ld a, [H_QUOTIENT + 3] cp b - jr nc, .canEscape ; if the random value was less than or equal to the quotient + 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 ; can't escape ld a, $1 - ld [wcd6a], a + ld [wActionResultOrTookBattleTurn], a ; you lose your turn when you can't escape ld hl, CantEscapeText jr .printCantEscapeOrNoRunningText .trainerBattle ld hl, NoRunningText .printCantEscapeOrNoRunningText call PrintText - ld a, $1 - ld [wd11f], a + ld a, 1 + ld [wForcePlayerToChooseMon], a call SaveScreenTilesToBuffer1 and a ; reset carry ret @@ -1665,19 +1678,19 @@ TryRunningFromBattle: ; 3cab9 (f:4ab9) ; link battle call SaveScreenTilesToBuffer1 xor a - ld [wcd6a], a - ld a, $f + ld [wActionResultOrTookBattleTurn], a + ld a, LINKBATTLE_RUN ld [wPlayerMoveListIndex], a call LinkBattleExchangeData call LoadScreenTilesFromBuffer1 ld a, [wSerialExchangeNybbleReceiveData] - cp $f + cp LINKBATTLE_RUN ld a, $2 jr z, .playSound dec a .playSound ld [wBattleResult], a - ld a, (SFX_08_44 - SFX_Headers_08) / 3 + ld a, SFX_RUN call PlaySoundWaitForCurrent ld hl, GotAwayText call PrintText @@ -1686,37 +1699,37 @@ TryRunningFromBattle: ; 3cab9 (f:4ab9) scf ; set carry ret -CantEscapeText: ; 3cb97 (f:4b97) +CantEscapeText: TX_FAR _CantEscapeText db "@" -NoRunningText: ; 3cb9c (f:4b9c) +NoRunningText: TX_FAR _NoRunningText db "@" -GotAwayText: ; 3cba1 (f:4ba1) +GotAwayText: TX_FAR _GotAwayText db "@" ; copies from party data to battle mon data when sending out a new player mon -LoadBattleMonFromParty: ; 3cba6 (f:4ba6) +LoadBattleMonFromParty: ld a, [wWhichPokemon] - ld bc, $2c + ld bc, wPartyMon2 - wPartyMon1 ld hl, wPartyMon1Species call AddNTimes ld de, wBattleMonSpecies - ld bc, $c + ld bc, wBattleMonDVs - wBattleMonSpecies call CopyData - ld bc, $f + ld bc, wPartyMon1DVs - wPartyMon1OTID add hl, bc ld de, wBattleMonDVs - ld bc, $2 + ld bc, NUM_DVS call CopyData ld de, wBattleMonPP - ld bc, $4 + ld bc, NUM_MOVES call CopyData ld de, wBattleMonLevel - ld bc, $b + ld bc, wBattleMonPP - wBattleMonLevel call CopyData ld a, [wBattleMonSpecies2] ld [wd0b5], a @@ -1725,16 +1738,16 @@ LoadBattleMonFromParty: ; 3cba6 (f:4ba6) ld a, [wPlayerMonNumber] call SkipFixedLengthTextEntries ld de, wBattleMonNick - ld bc, $b + ld bc, NAME_LENGTH call CopyData ld hl, wBattleMonLevel ld de, wPlayerMonUnmodifiedLevel ; block of memory used for unmodified stats - ld bc, $b + ld bc, 1 + NUM_STATS * 2 call CopyData call ApplyBurnAndParalysisPenaltiesToPlayer call ApplyBadgeStatBoosts ld a, $7 ; default stat modifier - ld b, $8 + ld b, NUM_STAT_MODS ld hl, wPlayerMonAttackMod .statModLoop ld [hli], a @@ -1743,24 +1756,24 @@ LoadBattleMonFromParty: ; 3cba6 (f:4ba6) ret ; copies from enemy party data to current enemy mon data when sending out a new enemy mon -LoadEnemyMonFromParty: ; 3cc13 (f:4c13) +LoadEnemyMonFromParty: ld a, [wWhichPokemon] - ld bc, $2c + ld bc, wEnemyMon2 - wEnemyMon1 ld hl, wEnemyMons call AddNTimes ld de, wEnemyMonSpecies - ld bc, $c + ld bc, wEnemyMonDVs - wEnemyMonSpecies call CopyData - ld bc, $f + ld bc, wEnemyMon1DVs - wEnemyMon1OTID add hl, bc ld de, wEnemyMonDVs - ld bc, $2 + ld bc, NUM_DVS call CopyData ld de, wEnemyMonPP - ld bc, $4 + ld bc, NUM_MOVES call CopyData ld de, wEnemyMonLevel - ld bc, $b + ld bc, wEnemyMonPP - wEnemyMonLevel call CopyData ld a, [wEnemyMonSpecies] ld [wd0b5], a @@ -1769,16 +1782,16 @@ LoadEnemyMonFromParty: ; 3cc13 (f:4c13) ld a, [wWhichPokemon] call SkipFixedLengthTextEntries ld de, wEnemyMonNick - ld bc, $b + ld bc, NAME_LENGTH call CopyData ld hl, wEnemyMonLevel ld de, wEnemyMonUnmodifiedLevel ; block of memory used for unmodified stats - ld bc, $b + ld bc, 1 + NUM_STATS * 2 call CopyData call ApplyBurnAndParalysisPenaltiesToEnemy - ld hl, W_MONHBASESTATS + ld hl, wMonHBaseStats ld de, wEnemyMonBaseStats - ld b, $5 + ld b, NUM_STATS .copyBaseStatsLoop ld a, [hli] ld [de], a @@ -1786,7 +1799,7 @@ LoadEnemyMonFromParty: ; 3cc13 (f:4c13) dec b jr nz, .copyBaseStatsLoop ld a, $7 ; default stat modifier - ld b, $8 + ld b, NUM_STAT_MODS ld hl, wEnemyMonStatMods .statModLoop ld [hli], a @@ -1796,7 +1809,7 @@ LoadEnemyMonFromParty: ; 3cc13 (f:4c13) ld [wEnemyMonPartyPos], a ret -SendOutMon: ; 3cc91 (f:4c91) +SendOutMon: callab PrintSendOutMonMessage ld hl, wEnemyMonHP ld a, [hli] @@ -1807,13 +1820,13 @@ SendOutMon: ; 3cc91 (f:4c91) call DrawPlayerHUDAndHPBar predef LoadMonBackPic xor a - ld [$ffe1], a - ld hl, wcc2d + ld [hStartTileID], a + ld hl, wBattleAndStartSavedMenuItem ld [hli], a ld [hl], a ld [wBoostExpByExpAll], a ld [wDamageMultipliers], a - ld [W_PLAYERMOVENUM], a + ld [wPlayerMoveNum], a ld hl, wPlayerUsedMove ld [hli], a ld [hl], a @@ -1823,56 +1836,56 @@ SendOutMon: ; 3cc91 (f:4c91) ld [hli], a ld [hli], a ld [hl], a - ld [W_PLAYERDISABLEDMOVE], a - ld [wccee], a - ld [wccf7], a - ld b, $1 - call GoPAL_SET - ld hl, W_ENEMYBATTSTATUS1 + ld [wPlayerDisabledMove], a + ld [wPlayerDisabledMoveNumber], a + ld [wPlayerMonMinimized], a + ld b, SET_PAL_BATTLE + call RunPaletteCommand + ld hl, wEnemyBattleStatus1 res UsingTrappingMove, [hl] ld a, $1 ld [H_WHOSETURN], a ld a, POOF_ANIM call PlayMoveAnimation - hlCoord 4, 11 - predef Func_3f073 + coord hl, 4, 11 + predef AnimateSendingOutMon ld a, [wcf91] call PlayCry call PrintEmptyString jp SaveScreenTilesToBuffer1 -; show 2 stages of the player getting smaller before disappearing -AnimateRetreatingPlayerMon: ; 3ccfa (f:4cfa) - hlCoord 1, 5 - ld bc, $707 +; show 2 stages of the player mon getting smaller before disappearing +AnimateRetreatingPlayerMon: + coord hl, 1, 5 + lb bc, 7, 7 call ClearScreenArea - hlCoord 3, 7 - ld bc, $505 + coord hl, 3, 7 + lb bc, 5, 5 xor a - ld [wcd6c], a - ld [H_DOWNARROWBLINKCNT1], a - predef Func_79aba - ld c, $4 + ld [wDownscaledMonSize], a + ld [hBaseTileID], a + predef CopyDownscaledMonTiles + ld c, 4 call DelayFrames call .clearScreenArea - hlCoord 4, 9 - ld bc, $303 - ld a, $1 - ld [wcd6c], a + coord hl, 4, 9 + lb bc, 3, 3 + ld a, 1 + ld [wDownscaledMonSize], a xor a - ld [H_DOWNARROWBLINKCNT1], a - predef Func_79aba + ld [hBaseTileID], a + predef CopyDownscaledMonTiles call Delay3 call .clearScreenArea ld a, $4c Coorda 5, 11 .clearScreenArea - hlCoord 1, 5 - ld bc, $707 + coord hl, 1, 5 + lb bc, 7, 7 jp ClearScreenArea ; reads player's current mon's HP into wBattleMonHP -ReadPlayerMonCurHPAndStatus: ; 3cd43 (f:4d43) +ReadPlayerMonCurHPAndStatus: ld a, [wPlayerMonNumber] ld hl, wPartyMon1HP ld bc, wPartyMon2 - wPartyMon1 @@ -1883,83 +1896,83 @@ ReadPlayerMonCurHPAndStatus: ; 3cd43 (f:4d43) ld bc, $4 ; 2 bytes HP, 1 byte unknown (unused?), 1 byte status jp CopyData -DrawHUDsAndHPBars: ; 3cd5a (f:4d5a) +DrawHUDsAndHPBars: call DrawPlayerHUDAndHPBar jp DrawEnemyHUDAndHPBar -DrawPlayerHUDAndHPBar: ; 3cd60 (f:4d60) +DrawPlayerHUDAndHPBar: xor a ld [H_AUTOBGTRANSFERENABLED], a - hlCoord 9, 7 - ld bc, $50b + coord hl, 9, 7 + lb bc, 5, 11 call ClearScreenArea callab PlacePlayerHUDTiles - hlCoord 18, 9 + coord hl, 18, 9 ld [hl], $73 ld de, wBattleMonNick - hlCoord 10, 7 + coord hl, 10, 7 call CenterMonName call PlaceString ld hl, wBattleMonSpecies ld de, wLoadedMon - ld bc, $c + ld bc, wBattleMonDVs - wBattleMonSpecies call CopyData ld hl, wBattleMonLevel ld de, wLoadedMonLevel - ld bc, $b + ld bc, wBattleMonPP - wBattleMonLevel call CopyData - hlCoord 14, 8 + coord hl, 14, 8 push hl inc hl ld de, wLoadedMonStatus call PrintStatusConditionNotFainted pop hl - jr nz, .asm_3cdae + jr nz, .doNotPrintLevel call PrintLevel -.asm_3cdae +.doNotPrintLevel ld a, [wLoadedMonSpecies] ld [wcf91], a - hlCoord 10, 9 + coord hl, 10, 9 predef DrawHP ld a, $1 ld [H_AUTOBGTRANSFERENABLED], a - ld hl, wcf1d + ld hl, wPlayerHPBarColor call GetBattleHealthBarColor ld hl, wBattleMonHP ld a, [hli] or [hl] - jr z, .asm_3cdd9 - ld a, [wccf6] - and a - ret nz - ld a, [wcf1d] - cp $2 - jr z, .asm_3cde6 -.asm_3cdd9 + jr z, .fainted + ld a, [wLowHealthAlarmDisabled] + and a ; has the alarm been disabled because the player has already won? + ret nz ; if so, return + ld a, [wPlayerHPBarColor] + cp HP_BAR_RED + jr z, .setLowHealthAlarm +.fainted ld hl, wLowHealthAlarm bit 7, [hl] ;low health alarm enabled? ld [hl], $0 ret z xor a - ld [wc02a], a + ld [wChannelSoundIDs + Ch4], a ret -.asm_3cde6 +.setLowHealthAlarm ld hl, wLowHealthAlarm set 7, [hl] ;enable low health alarm ret -DrawEnemyHUDAndHPBar: ; 3cdec (f:4dec) +DrawEnemyHUDAndHPBar: xor a ld [H_AUTOBGTRANSFERENABLED], a - ld hl, wTileMap - ld bc, $40c + coord hl, 0, 0 + lb bc, 4, 12 call ClearScreenArea callab PlaceEnemyHUDTiles ld de, wEnemyMonNick - hlCoord 1, 0 + coord hl, 1, 0 call CenterMonName call PlaceString - hlCoord 4, 1 + coord hl, 4, 1 push hl inc hl ld de, wEnemyMonStatus @@ -2032,27 +2045,27 @@ DrawEnemyHUDAndHPBar: ; 3cdec (f:4dec) .drawHPBar xor a ld [wHPBarType], a - hlCoord 2, 2 + coord hl, 2, 2 call DrawHPBar ld a, $1 ld [H_AUTOBGTRANSFERENABLED], a - ld hl, wcf1e + ld hl, wEnemyHPBarColor -GetBattleHealthBarColor: ; 3ce90 (f:4e90) +GetBattleHealthBarColor: ld b, [hl] call GetHealthBarColor ld a, [hl] cp b ret z - ld b, $1 - jp GoPAL_SET + ld b, SET_PAL_BATTLE + jp RunPaletteCommand ; center's mon's name on the battle screen ; if the name is 1 or 2 letters long, it is printed 2 spaces more to the right than usual ; (i.e. for names longer than 4 letters) ; if the name is 3 or 4 letters long, it is printed 1 space more to the right than usual ; (i.e. for names longer than 4 letters) -CenterMonName: ; 3ce9c (f:4e9c) +CenterMonName: push de inc hl inc hl @@ -2060,11 +2073,11 @@ CenterMonName: ; 3ce9c (f:4e9c) .loop inc de ld a, [de] - cp $50 + cp "@" jr z, .done inc de ld a, [de] - cp $50 + cp "@" jr z, .done dec hl dec b @@ -2073,30 +2086,30 @@ CenterMonName: ; 3ce9c (f:4e9c) pop de ret -DisplayBattleMenu: ; 3ceb3 (f:4eb3) +DisplayBattleMenu: call LoadScreenTilesFromBuffer1 ; restore saved screen - ld a, [W_BATTLETYPE] + ld a, [wBattleType] and a jr nz, .nonstandardbattle call DrawHUDsAndHPBars call PrintEmptyString call SaveScreenTilesToBuffer1 .nonstandardbattle - ld a, [W_BATTLETYPE] - cp $2 ; safari + ld a, [wBattleType] + cp BATTLE_TYPE_SAFARI ld a, BATTLE_MENU_TEMPLATE jr nz, .menuselected ld a, SAFARI_BATTLE_MENU_TEMPLATE .menuselected ld [wTextBoxID], a call DisplayTextBoxID - ld a, [W_BATTLETYPE] + ld a, [wBattleType] dec a jp nz, .handleBattleMenuInput ; handle menu input if it's not the old man tutorial ; the following happens for the old man tutorial ld hl, wPlayerName - ld de, W_GRASSRATE - ld bc, $b + ld de, wGrassRate + ld bc, NAME_LENGTH call CopyData ; temporarily save the player name in unused space, ; which is supposed to get overwritten when entering a ; map with wild Pokémon. Due to an oversight, the data @@ -2104,25 +2117,25 @@ DisplayBattleMenu: ; 3ceb3 (f:4eb3) ; Missingno. glitch can show up. ld hl, .oldManName ld de, wPlayerName - ld bc, $b + ld bc, NAME_LENGTH call CopyData ; the following simulates the keystrokes by drawing menus on screen - hlCoord 9, 14 + coord hl, 9, 14 ld [hl], "▶" - ld c, $50 + ld c, 80 call DelayFrames - ld [hl], $7f - hlCoord 9, 16 + ld [hl], " " + coord hl, 9, 16 ld [hl], "▶" - ld c, $32 + ld c, 50 call DelayFrames - ld [hl], $ec + ld [hl], "▷" ld a, $2 ; select the "ITEM" menu jp .upperLeftMenuItemWasNotSelected .oldManName db "OLD MAN@" .handleBattleMenuInput - ld a, [wcc2d] + ld a, [wBattleAndStartSavedMenuItem] ld [wCurrentMenuItem], a ld [wLastMenuItem], a sub 2 ; check if the cursor is in the left column @@ -2132,8 +2145,8 @@ DisplayBattleMenu: ; 3ceb3 (f:4eb3) ld [wLastMenuItem], a jr .rightColumn .leftColumn ; put cursor in left column of menu - ld a, [W_BATTLETYPE] - cp $2 + ld a, [wBattleType] + cp BATTLE_TYPE_SAFARI ld a, " " jr z, .safariLeftColumn ; put cursor in left column for normal battle menu (i.e. when it's not a Safari battle) @@ -2144,9 +2157,9 @@ DisplayBattleMenu: ; 3ceb3 (f:4eb3) .safariLeftColumn Coorda 13, 14 Coorda 13, 16 - hlCoord 7, 14 - ld de, W_NUMSAFARIBALLS - ld bc, $102 + coord hl, 7, 14 + ld de, wNumSafariBalls + lb bc, 1, 2 call PrintNumber ld b, $1 ; top menu item X .leftColumn_WaitForInput @@ -2165,8 +2178,8 @@ DisplayBattleMenu: ; 3ceb3 (f:4eb3) jr nz, .rightColumn jr .AButtonPressed ; the A button was pressed .rightColumn ; put cursor in right column of menu - ld a, [W_BATTLETYPE] - cp $2 + ld a, [wBattleType] + cp BATTLE_TYPE_SAFARI ld a, " " jr z, .safariRightColumn ; put cursor in right column for normal battle menu (i.e. when it's not a Safari battle) @@ -2177,9 +2190,9 @@ DisplayBattleMenu: ; 3ceb3 (f:4eb3) .safariRightColumn Coorda 1, 14 ; clear upper cursor position in left column Coorda 1, 16 ; clear lower cursor position in left column - hlCoord 7, 14 - ld de, W_NUMSAFARIBALLS - ld bc, $102 + coord hl, 7, 14 + ld de, wNumSafariBalls + lb bc, 1, 2 call PrintNumber ld b, $d ; top menu item X .rightColumn_WaitForInput @@ -2202,10 +2215,10 @@ DisplayBattleMenu: ; 3ceb3 (f:4eb3) ld [wCurrentMenuItem], a .AButtonPressed call PlaceUnfilledArrowMenuCursor - ld a, [W_BATTLETYPE] - cp $2 ; is it a Safari battle? + ld a, [wBattleType] + cp BATTLE_TYPE_SAFARI ld a, [wCurrentMenuItem] - ld [wcc2d], a + ld [wBattleAndStartSavedMenuItem], a jr z, .handleMenuSelection ; not Safari battle ; swap the IDs of the item menu and party menu (this is probably because they swapped the positions @@ -2224,8 +2237,8 @@ DisplayBattleMenu: ; 3ceb3 (f:4eb3) and a jr nz, .upperLeftMenuItemWasNotSelected ; the upper left menu item was selected - ld a, [W_BATTLETYPE] - cp $2 + ld a, [wBattleType] + cp BATTLE_TYPE_SAFARI jr z, .throwSafariBallWasSelected ; the "FIGHT" menu was selected xor a @@ -2252,8 +2265,8 @@ DisplayBattleMenu: ; 3ceb3 (f:4eb3) .notLinkBattle call SaveScreenTilesToBuffer2 - ld a, [W_BATTLETYPE] - cp $2 ; is it a safari battle? + ld a, [wBattleType] + cp BATTLE_TYPE_SAFARI jr nz, BagWasSelected ; bait was selected @@ -2263,21 +2276,21 @@ DisplayBattleMenu: ; 3ceb3 (f:4eb3) BagWasSelected: call LoadScreenTilesFromBuffer1 - ld a, [W_BATTLETYPE] + ld a, [wBattleType] and a ; is it a normal battle? jr nz, .next ; normal battle call DrawHUDsAndHPBars .next - ld a, [W_BATTLETYPE] + ld a, [wBattleType] dec a ; is it the old man tutorial? jr nz, DisplayPlayerBag ; no, it is a normal battle ld hl, OldManItemList ld a, l - ld [wList], a + ld [wListPointer], a ld a, h - ld [wList + 1], a + ld [wListPointer + 1], a jr DisplayBagMenu OldManItemList: @@ -2289,22 +2302,22 @@ DisplayPlayerBag: ; get the pointer to player's bag when in a normal battle ld hl, wNumBagItems ld a, l - ld [wList], a + ld [wListPointer], a ld a, h - ld [wList + 1], a + ld [wListPointer + 1], a DisplayBagMenu: xor a - ld [wcf93], a + ld [wPrintItemPrices], a ld a, ITEMLISTMENU ld [wListMenuID], a - ld a, [wcc2c] + ld a, [wBagSavedMenuItem] ld [wCurrentMenuItem], a call DisplayListMenuID ld a, [wCurrentMenuItem] - ld [wcc2c], a + ld [wBagSavedMenuItem], a ld a, $0 - ld [wcc37], a + ld [wMenuWatchMovingOutOfBounds], a ld [wMenuItemToSwap], a jp c, DisplayBattleMenu ; go back to battle menu if an item was not selected @@ -2315,36 +2328,36 @@ UseBagItem: call GetItemName call CopyStringToCF4B ; copy name xor a - ld [wd152], a + ld [wPseudoItemID], a call UseItem call LoadHudTilePatterns call ClearSprites xor a ld [wCurrentMenuItem], a - ld a, [W_BATTLETYPE] - cp $2 ; is it a safari battle? + ld a, [wBattleType] + cp BATTLE_TYPE_SAFARI jr z, .checkIfMonCaptured - ld a, [wcd6a] + ld a, [wActionResultOrTookBattleTurn] and a ; was the item used successfully? jp z, BagWasSelected ; if not, go back to the bag menu - ld a, [W_PLAYERBATTSTATUS1] + ld a, [wPlayerBattleStatus1] bit UsingTrappingMove, a ; is the player using a multi-turn move like wrap? jr z, .checkIfMonCaptured ld hl, wPlayerNumAttacksLeft dec [hl] jr nz, .checkIfMonCaptured - ld hl, W_PLAYERBATTSTATUS1 + ld hl, wPlayerBattleStatus1 res UsingTrappingMove, [hl] ; not using multi-turn move any more .checkIfMonCaptured - ld a, [wd11c] + ld a, [wCapturedMonSpecies] and a ; was the enemy mon captured with a ball? jr nz, .returnAfterCapturingMon - ld a, [W_BATTLETYPE] - cp $2 ; is it a safari battle? + ld a, [wBattleType] + cp BATTLE_TYPE_SAFARI jr z, .returnAfterUsingItem_NoCapture ; not a safari battle call LoadScreenTilesFromBuffer1 @@ -2359,7 +2372,7 @@ UseBagItem: .returnAfterCapturingMon call GBPalNormal xor a - ld [wd11c], a + ld [wCapturedMonSpecies], a ld a, $2 ld [wBattleResult], a scf ; set carry @@ -2374,8 +2387,8 @@ PartyMenuOrRockOrRun: jp nz, BattleMenu_RunWasSelected ; party menu or rock was selected call SaveScreenTilesToBuffer2 - ld a, [W_BATTLETYPE] - cp $2 ; is it a safari battle? + ld a, [wBattleType] + cp BATTLE_TYPE_SAFARI jr nz, .partyMenuWasSelected ; safari battle ld a, SAFARI_ROCK @@ -2383,8 +2396,8 @@ PartyMenuOrRockOrRun: jp UseBagItem .partyMenuWasSelected call LoadScreenTilesFromBuffer1 - xor a - ld [wd07d], a + xor a ; NORMAL_PARTY_MENU + ld [wPartyMenuTypeOrMessageID], a ld [wMenuItemToSwap], a call DisplayPartyMenu .checkIfPartyMonWasSelected @@ -2394,16 +2407,16 @@ PartyMenuOrRockOrRun: call GBPalWhiteOut call LoadHudTilePatterns call LoadScreenTilesFromBuffer2 - call GoPAL_SET_CF1C + call RunDefaultPaletteCommand call GBPalNormal jp DisplayBattleMenu .partyMonDeselected - hlCoord 11, 11 - ld bc, $81 - ld a, $7f + coord hl, 11, 11 + ld bc, 6 * SCREEN_WIDTH + 9 + ld a, " " call FillMemory - xor a - ld [wd07d], a + xor a ; NORMAL_PARTY_MENU + ld [wPartyMenuTypeOrMessageID], a call GoBackToPartyMenu jr .checkIfPartyMonWasSelected .partyMonWasSelected @@ -2434,20 +2447,20 @@ PartyMenuOrRockOrRun: and a ; was Switch selected? jr z, .switchMon ; if so, jump ; Stats was selected - xor a - ld [wcc49], a + xor a ; PLAYER_PARTY_DATA + ld [wMonDataLocation], a ld hl, wPartyMon1 call ClearSprites ; display the two status screens predef StatusScreen predef StatusScreen2 ; now we need to reload the enemy mon pic - ld a, [W_ENEMYBATTSTATUS2] + ld a, [wEnemyBattleStatus2] bit HasSubstituteUp, a ; does the enemy mon have a substitute? ld hl, AnimationSubstitute jr nz, .doEnemyMonAnimation ; enemy mon doesn't have substitute - ld a, [wccf3] + ld a, [wEnemyMonMinimized] and a ; has the enemy mon used Minimise? ld hl, AnimationMinimizeMon jr nz, .doEnemyMonAnimation @@ -2478,24 +2491,24 @@ PartyMenuOrRockOrRun: call HasMonFainted jp z, .partyMonDeselected ; can't switch to fainted mon ld a, $1 - ld [wcd6a], a + ld [wActionResultOrTookBattleTurn], a call GBPalWhiteOut call ClearSprites call LoadHudTilePatterns call LoadScreenTilesFromBuffer1 - call GoPAL_SET_CF1C + call RunDefaultPaletteCommand call GBPalNormal ; fall through to SwitchPlayerMon -SwitchPlayerMon: ; 3d1ba (f:51ba) +SwitchPlayerMon: callab RetreatMon - ld c, $32 + ld c, 50 call DelayFrames call AnimateRetreatingPlayerMon ld a, [wWhichPokemon] ld [wPlayerMonNumber], a ld c, a - ld b, $1 + ld b, FLAG_SET push bc ld hl, wPartyGainExpFlags predef FlagActionPredef @@ -2510,26 +2523,26 @@ SwitchPlayerMon: ; 3d1ba (f:51ba) and a ret -AlreadyOutText: ; 3d1f5 (f:51f5) +AlreadyOutText: TX_FAR _AlreadyOutText db "@" -BattleMenu_RunWasSelected: ; 3d1fa (f:51fa) +BattleMenu_RunWasSelected: call LoadScreenTilesFromBuffer1 ld a, $3 ld [wCurrentMenuItem], a ld hl, wBattleMonSpeed ld de, wEnemyMonSpeed call TryRunningFromBattle - ld a, $0 - ld [wd11f], a + ld a, 0 + ld [wForcePlayerToChooseMon], a ret c - ld a, [wcd6a] + ld a, [wActionResultOrTookBattleTurn] and a - ret nz + ret nz ; return if the player couldn't escape jp DisplayBattleMenu -MoveSelectionMenu: ; 3d219 (f:5219) +MoveSelectionMenu: ld a, [wMoveMenuType] dec a jr z, .mimicmenu @@ -2560,17 +2573,18 @@ MoveSelectionMenu: ; 3d219 (f:5219) ret z ld hl, wBattleMonMoves call .loadmoves - hlCoord 4, 12 - ld b, $4 - ld c, $e - di + coord hl, 4, 12 + ld b, 4 + ld c, 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 - hlCoord 4, 12 + coord hl, 4, 12 ld [hl], $7a - hlCoord 10, 12 + coord hl, 10, 12 ld [hl], $7e ei - hlCoord 6, 13 + coord hl, 6, 13 call .writemoves ld b, $5 ld a, $c @@ -2578,11 +2592,11 @@ MoveSelectionMenu: ; 3d219 (f:5219) .mimicmenu ld hl, wEnemyMonMoves call .loadmoves - hlCoord 0, 7 - ld b, $4 - ld c, $e + coord hl, 0, 7 + ld b, 4 + ld c, 14 call TextBoxBorder - hlCoord 2, 8 + coord hl, 2, 8 call .writemoves ld b, $1 ld a, $7 @@ -2590,22 +2604,22 @@ MoveSelectionMenu: ; 3d219 (f:5219) .relearnmenu ld a, [wWhichPokemon] ld hl, wPartyMon1Moves - ld bc, $2c + ld bc, wPartyMon2 - wPartyMon1 call AddNTimes call .loadmoves - hlCoord 4, 7 - ld b, $4 - ld c, $e + coord hl, 4, 7 + ld b, 4 + ld c, 14 call TextBoxBorder - hlCoord 6, 8 + coord hl, 6, 8 call .writemoves ld b, $5 ld a, $7 .menuset ld hl, wTopMenuItemY - ld [hli], a + ld [hli], a ; wTopMenuItemY ld a, b - ld [hli], a + ld [hli], a ; wTopMenuItemX ld a, [wMoveMenuType] cp $1 jr z, .selectedmoveknown @@ -2614,30 +2628,30 @@ MoveSelectionMenu: ; 3d219 (f:5219) ld a, [wPlayerMoveListIndex] inc a .selectedmoveknown - ld [hli], a + ld [hli], a ; wCurrentMenuItem inc hl ; wTileBehindCursor untouched - ld a, [wcd6c] + ld a, [wNumMovesMinusOne] inc a inc a - ld [hli], a + ld [hli], a ; wMaxMenuItem ld a, [wMoveMenuType] dec a - ld b, $c1 ; can't use B + ld b, D_UP | D_DOWN | A_BUTTON jr z, .matchedkeyspicked dec a - ld b, $c3 + ld b, D_UP | D_DOWN | A_BUTTON | B_BUTTON jr z, .matchedkeyspicked ld a, [wLinkState] cp LINK_STATE_BATTLING jr z, .matchedkeyspicked - ld a, [W_FLAGS_D733] - bit 0, a - ld b, $c7 + ld a, [wFlags_D733] + bit BIT_TEST_BATTLE, a + ld b, D_UP | D_DOWN | A_BUTTON | B_BUTTON | SELECT jr z, .matchedkeyspicked ld b, $ff .matchedkeyspicked ld a, b - ld [hli], a + ld [hli], a ; wMenuWatchedKeys ld a, [wMoveMenuType] cp $1 jr z, .movelistindex1 @@ -2647,29 +2661,29 @@ MoveSelectionMenu: ; 3d219 (f:5219) ld [hl], a ; fallthrough -SelectMenuItem: ; 3d2fe (f:52fe) +SelectMenuItem: ld a, [wMoveMenuType] and a jr z, .battleselect dec a jr nz, .select - hlCoord 1, 14 + coord hl, 1, 14 ld de, WhichTechniqueString call PlaceString jr .select .battleselect - ld a, [W_FLAGS_D733] - bit 0, a + ld a, [wFlags_D733] + bit BIT_TEST_BATTLE, a jr nz, .select call PrintMenuItem ld a, [wMenuItemToSwap] and a jr z, .select - hlCoord 5, 13 + coord hl, 5, 13 dec a - ld bc, $14 + ld bc, SCREEN_WIDTH call AddNTimes - ld [hl], $ec + ld [hl], "▷" .select ld hl, hFlags_0xFFF6 set 1, [hl] @@ -2677,9 +2691,9 @@ SelectMenuItem: ; 3d2fe (f:52fe) ld hl, hFlags_0xFFF6 res 1, [hl] bit 6, a - jp nz, CursorUp ; up + jp nz, SelectMenuItem_CursorUp ; up bit 7, a - jp nz, CursorDown ; down + jp nz, SelectMenuItem_CursorDown ; down bit 2, a jp nz, SwapMovesInMenu ; select bit 1, a ; B, but was it reset above? @@ -2692,10 +2706,10 @@ SelectMenuItem: ; 3d2fe (f:52fe) ld b, a ld a, [wMoveMenuType] dec a ; if not mimic - jr nz, .nob + jr nz, .notB pop af ret -.nob +.notB dec a ld a, b ld [wPlayerMoveListIndex], a @@ -2712,14 +2726,14 @@ SelectMenuItem: ; 3d2fe (f:52fe) add hl, bc ld a, [hl] and $3f - jr z, .nopp - ld a, [W_PLAYERDISABLEDMOVE] + jr z, .noPP + ld a, [wPlayerDisabledMove] swap a and $f dec a cp c jr z, .disabled - ld a, [W_PLAYERBATTSTATUS3] + ld a, [wPlayerBattleStatus3] bit 3, a ; transformed jr nz, .dummy ; game freak derp .dummy @@ -2735,38 +2749,38 @@ SelectMenuItem: ; 3d2fe (f:52fe) .disabled ld hl, MoveDisabledText jr .print -.nopp +.noPP ld hl, MoveNoPPText .print call PrintText call LoadScreenTilesFromBuffer1 jp MoveSelectionMenu -MoveNoPPText: ; 3d3ae (f:53ae) +MoveNoPPText: TX_FAR _MoveNoPPText db "@" -MoveDisabledText: ; 3d3b3 (f:53b3) +MoveDisabledText: TX_FAR _MoveDisabledText db "@" -WhichTechniqueString: ; 3d3b8 (f:53b8) +WhichTechniqueString: db "WHICH TECHNIQUE?@" -CursorUp: ; 3d3c9 (f:53c9) +SelectMenuItem_CursorUp: ld a, [wCurrentMenuItem] and a jp nz, SelectMenuItem call EraseMenuCursor - ld a, [wcd6c] + ld a, [wNumMovesMinusOne] inc a ld [wCurrentMenuItem], a jp SelectMenuItem -CursorDown: ; 3d3dd (f:53dd) +SelectMenuItem_CursorDown: ld a, [wCurrentMenuItem] ld b, a - ld a, [wcd6c] + ld a, [wNumMovesMinusOne] inc a inc a cp b @@ -2776,14 +2790,14 @@ CursorDown: ; 3d3dd (f:53dd) ld [wCurrentMenuItem], a jp SelectMenuItem -AnyMoveToSelect: ; 3d3f5 (f:53f5) +AnyMoveToSelect: ; return z and Struggle as the selected move if all moves have 0 PP and/or are disabled ld a, STRUGGLE ld [wPlayerSelectedMove], a - ld a, [W_PLAYERDISABLEDMOVE] + ld a, [wPlayerDisabledMove] and a ld hl, wBattleMonPP - jr nz, .asm_3d40e + jr nz, .handleDisabledMove ld a, [hli] or [hl] inc hl @@ -2792,38 +2806,38 @@ AnyMoveToSelect: ; 3d3f5 (f:53f5) or [hl] and $3f ret nz - jr .asm_3d423 -.asm_3d40e + jr .noMovesLeft +.handleDisabledMove swap a - and $f + and $f ; get disabled move ld b, a - ld d, $5 + ld d, NUM_MOVES + 1 xor a -.asm_3d416 +.handleDisabledMovePPLoop dec d - jr z, .asm_3d421 - ld c, [hl] + jr z, .allMovesChecked + ld c, [hl] ; get move PP inc hl - dec b - jr z, .asm_3d416 + dec b ; is this the disabled move? + jr z, .handleDisabledMovePPLoop ; if so, ignore its PP value or c - jr .asm_3d416 -.asm_3d421 - and a - ret nz -.asm_3d423 + jr .handleDisabledMovePPLoop +.allMovesChecked + and a ; any PP left? + ret nz ; return if a move has PP left +.noMovesLeft ld hl, NoMovesLeftText call PrintText - ld c, $3c + ld c, 60 call DelayFrames xor a ret -NoMovesLeftText: ; 3d430 (f:5430) +NoMovesLeftText: TX_FAR _NoMovesLeftText db "@" -SwapMovesInMenu: ; 3d435 (f:5435) +SwapMovesInMenu: ld a, [wMenuItemToSwap] and a jr z, .noMenuItemSelected @@ -2832,7 +2846,7 @@ SwapMovesInMenu: ; 3d435 (f:5435) ld hl, wBattleMonPP call .swapBytes ; swap move PP ; update the index of the disabled move if necessary - ld hl, W_PLAYERDISABLEDMOVE + ld hl, wPlayerDisabledMove ld a, [hl] swap a and $f @@ -2867,7 +2881,7 @@ SwapMovesInMenu: ; 3d435 (f:5435) push hl call .swapBytes ; swap moves pop hl - ld bc, $15 + ld bc, wPartyMon1PP - wPartyMon1Moves add hl, bc call .swapBytes ; swap move PP xor a @@ -2899,14 +2913,14 @@ SwapMovesInMenu: ; 3d435 (f:5435) ld [wMenuItemToSwap], a ; select the current menu item for swapping jp MoveSelectionMenu -PrintMenuItem: ; 3d4b6 (f:54b6) +PrintMenuItem: xor a ld [H_AUTOBGTRANSFERENABLED], a - hlCoord 0, 8 - ld b, $3 - ld c, $9 + coord hl, 0, 8 + ld b, 3 + ld c, 9 call TextBoxBorder - ld a, [W_PLAYERDISABLEDMOVE] + ld a, [wPlayerDisabledMove] and a jr z, .notDisabled swap a @@ -2915,7 +2929,7 @@ PrintMenuItem: ; 3d4b6 (f:54b6) ld a, [wCurrentMenuItem] cp b jr nz, .notDisabled - hlCoord 1, 10 + coord hl, 1, 10 ld de, DisabledText call PlaceString jr .moveDisabled @@ -2929,13 +2943,13 @@ PrintMenuItem: ; 3d4b6 (f:54b6) ld c, a ld b, $0 ; which item in the menu is the cursor pointing to? (0-3) add hl, bc ; point to the item (move) in memory - ld a, [hl] - ld [wPlayerSelectedMove], a ; update wPlayerSelectedMove even if the move + ld a, [hl] + ld [wPlayerSelectedMove], a ; update wPlayerSelectedMove even if the move ; isn't actually selected (just pointed to by the cursor) ld a, [wPlayerMonNumber] ld [wWhichPokemon], a - ld a, $4 - ld [wcc49], a + ld a, BATTLE_MON_DATA + ld [wMonDataLocation], a callab GetMaxPP ld hl, wCurrentMenuItem ld c, [hl] @@ -2946,77 +2960,73 @@ PrintMenuItem: ; 3d4b6 (f:54b6) ld a, [hl] and $3f ld [wcd6d], a -; print TYPE/<type> and <curPP>/<maxPP> - hlCoord 1, 9 +; print TYPE/<type> and <curPP>/<maxPP> + coord hl, 1, 9 ld de, TypeText call PlaceString - hlCoord 7, 11 + coord hl, 7, 11 ld [hl], "/" - hlCoord 5, 9 + coord hl, 5, 9 ld [hl], "/" - hlCoord 5, 11 + coord hl, 5, 11 ld de, wcd6d - ld bc, $102 + lb bc, 1, 2 call PrintNumber - hlCoord 8, 11 - ld de, wd11e - ld bc, $102 + coord hl, 8, 11 + ld de, wMaxPP + lb bc, 1, 2 call PrintNumber - call GetCurrentMove - hlCoord 2, 10 + call GetCurrentMove + coord hl, 2, 10 predef PrintMoveType .moveDisabled ld a, $1 ld [H_AUTOBGTRANSFERENABLED], a jp Delay3 -DisabledText: ; 3d555 (f:5555) -IF DEF(_YELLOW) - db "Disabled!@" -ELSE +DisabledText: db "disabled!@" -ENDC -TypeText: ; 3d55f (f:555f) +TypeText: db "TYPE@" -SelectEnemyMove: ; 3d564 (f:5564) +SelectEnemyMove: ld a, [wLinkState] - sub $4 + sub LINK_STATE_BATTLING jr nz, .noLinkBattle ; link battle call SaveScreenTilesToBuffer1 call LinkBattleExchangeData call LoadScreenTilesFromBuffer1 ld a, [wSerialExchangeNybbleReceiveData] - cp $e - jp z, .asm_3d601 - cp $d + cp LINKBATTLE_STRUGGLE + jp z, .linkedOpponentUsedStruggle + cp LINKBATTLE_NO_ACTION jr z, .unableToSelectMove - cp $4 + cp 4 ret nc ld [wEnemyMoveListIndex], a ld c, a ld hl, wEnemyMonMoves - ld b, $0 + ld b, 0 add hl, bc ld a, [hl] jr .done .noLinkBattle - ld a, [W_ENEMYBATTSTATUS2] + ld a, [wEnemyBattleStatus2] and (1 << NeedsToRecharge) | (1 << UsingRage) ; need to recharge or using rage ret nz - ld hl, W_ENEMYBATTSTATUS1 + ld hl, wEnemyBattleStatus1 ld a, [hl] and (1 << ChargingUp) | (1 << ThrashingAbout) ; using a charging move or thrash/petal dance ret nz ld a, [wEnemyMonStatus] and SLP | 1 << FRZ ; sleeping or frozen ret nz - ld a, [W_ENEMYBATTSTATUS1] + ld a, [wEnemyBattleStatus1] and (1 << UsingTrappingMove) | (1 << StoringEnergy) ; using a trapping move like wrap or bide ret nz - ld a, [W_PLAYERBATTSTATUS1] + ld a, [wPlayerBattleStatus1] bit UsingTrappingMove, a ; caught in player's trapping move (e.g. wrap) jr z, .canSelectMove .unableToSelectMove @@ -3027,12 +3037,12 @@ SelectEnemyMove: ; 3d564 (f:5564) ld a, [hld] and a jr nz, .atLeastTwoMovesAvailable - ld a, [W_ENEMYDISABLEDMOVE] + ld a, [wEnemyDisabledMove] and a ld a, STRUGGLE ; struggle if the only move is disabled jr nz, .done .atLeastTwoMovesAvailable - ld a, [W_ISINBATTLE] + ld a, [wIsInBattle] dec a jr z, .chooseRandomMove ; wild encounter callab AIEnemyTrainerChooseMoves @@ -3040,23 +3050,23 @@ SelectEnemyMove: ; 3d564 (f:5564) push hl call BattleRandom ld b, $1 - cp $3f ; select move 1 in [0,3e] (63/256 chance) + cp $3f ; select move 1, [0,3e] (63/256 chance) jr c, .moveChosen inc hl inc b - cp $7f ; select move 1 in [3f,7e] (64/256 chance) + cp $7f ; select move 2, [3f,7e] (64/256 chance) jr c, .moveChosen inc hl inc b - cp $be ; select move 1 in [7f,bd] (63/256 chance) + cp $be ; select move 3, [7f,bd] (63/256 chance) jr c, .moveChosen inc hl - inc b ; select move 4 in [be,ff] (66/256 chance) + inc b ; select move 4, [be,ff] (66/256 chance) .moveChosen ld a, b dec a ld [wEnemyMoveListIndex], a - ld a, [W_ENEMYDISABLEDMOVE] + ld a, [wEnemyDisabledMove] swap a and $f cp b @@ -3068,72 +3078,73 @@ SelectEnemyMove: ; 3d564 (f:5564) .done ld [wEnemySelectedMove], a ret -.asm_3d601 +.linkedOpponentUsedStruggle ld a, STRUGGLE jr .done ; this appears to exchange data with the other gameboy during link battles -LinkBattleExchangeData: ; 3d605 (f:5605) +LinkBattleExchangeData: ld a, $ff ld [wSerialExchangeNybbleReceiveData], a ld a, [wPlayerMoveListIndex] - cp $f ; is the player running from battle? - jr z, .asm_3d630 - ld a, [wcd6a] - and a - jr nz, .asm_3d629 + cp LINKBATTLE_RUN ; is the player running from battle? + jr z, .doExchange + ld a, [wActionResultOrTookBattleTurn] + and a ; is the player switching in another mon? + jr nz, .switching +; the player used a move ld a, [wPlayerSelectedMove] cp STRUGGLE - ld b, $e - jr z, .asm_3d62f - dec b - inc a - jr z, .asm_3d62f + ld b, LINKBATTLE_STRUGGLE + jr z, .next + dec b ; LINKBATTLE_NO_ACTION + inc a ; does move equal -1 (i.e. no action)? + jr z, .next ld a, [wPlayerMoveListIndex] - jr .asm_3d630 -.asm_3d629 + jr .doExchange +.switching ld a, [wWhichPokemon] - add $4 + add 4 ld b, a -.asm_3d62f +.next ld a, b -.asm_3d630 +.doExchange ld [wSerialExchangeNybbleSendData], a callab PrintWaitingText -.asm_3d63b +.syncLoop1 call Serial_ExchangeNybble call DelayFrame ld a, [wSerialExchangeNybbleReceiveData] inc a - jr z, .asm_3d63b - ld b, $a -.asm_3d649 + jr z, .syncLoop1 + ld b, 10 +.syncLoop2 call DelayFrame call Serial_ExchangeNybble dec b - jr nz, .asm_3d649 - ld b, $a -.asm_3d654 + jr nz, .syncLoop2 + ld b, 10 +.syncLoop3 call DelayFrame call Serial_SendZeroByte dec b - jr nz, .asm_3d654 + jr nz, .syncLoop3 ret -ExecutePlayerMove: ; 3d65e (f:565e) +ExecutePlayerMove: xor a ld [H_WHOSETURN], a ; set player's turn ld a, [wPlayerSelectedMove] inc a jp z, ExecutePlayerMoveDone ; for selected move = FF, skip most of player's turn xor a - ld [W_MOVEMISSED], a + ld [wMoveMissed], a ld [wMonIsDisobedient], a ld [wMoveDidntMiss], a ld a, $a ld [wDamageMultipliers], a - ld a, [wcd6a] - and a + ld a, [wActionResultOrTookBattleTurn] + and a ; has the player already used the turn (e.g. by using an item, trying to run or switching pokemon) jp nz, ExecutePlayerMoveDone call PrintGhostText jp z, ExecutePlayerMoveDone @@ -3142,14 +3153,14 @@ ExecutePlayerMove: ; 3d65e (f:565e) jp [hl] .playerHasNoSpecialCondition call GetCurrentMove - ld hl, W_PLAYERBATTSTATUS1 + ld hl, wPlayerBattleStatus1 bit ChargingUp, [hl] ; charging up for attack jr nz, PlayerCanExecuteChargingMove call CheckForDisobedience jp z, ExecutePlayerMoveDone -CheckIfPlayerNeedsToChargeUp: ; 3d69a (f:569a) - ld a, [W_PLAYERMOVEEFFECT] +CheckIfPlayerNeedsToChargeUp: + ld a, [wPlayerMoveEffect] cp CHARGE_EFFECT jp z, JumpMoveEffect cp FLY_EFFECT @@ -3157,31 +3168,31 @@ CheckIfPlayerNeedsToChargeUp: ; 3d69a (f:569a) jr PlayerCanExecuteMove ; in-battle stuff -PlayerCanExecuteChargingMove: ; 3d6a9 (f:56a9) - ld hl,W_PLAYERBATTSTATUS1 +PlayerCanExecuteChargingMove: + ld hl,wPlayerBattleStatus1 res ChargingUp,[hl] ; reset charging up and invulnerability statuses if mon was charging up for an attack ; being fully paralyzed or hurting oneself in confusion removes charging up status ; resulting in the Pokemon being invulnerable for the whole battle res Invulnerable,[hl] -PlayerCanExecuteMove: ; 3d6b0 (f:56b0) +PlayerCanExecuteMove: call PrintMonName1Text ld hl,DecrementPP ld de,wPlayerSelectedMove ; pointer to the move just used ld b,BANK(DecrementPP) call Bankswitch - ld a,[W_PLAYERMOVEEFFECT] ; effect of the move just used + ld a,[wPlayerMoveEffect] ; effect of the move just used ld hl,ResidualEffects1 ld de,1 call IsInArray - jp c,JumpMoveEffect ; ResidualEffects1 moves skip damage calculation and accuracy tests - ; unless executed as part of their exclusive effect functions - ld a,[W_PLAYERMOVEEFFECT] + jp c,JumpMoveEffect ; ResidualEffects1 moves skip damage calculation and accuracy tests + ; unless executed as part of their exclusive effect functions + ld a,[wPlayerMoveEffect] ld hl,SpecialEffectsCont ld de,1 call IsInArray - call c,JumpMoveEffect ; execute the effects of SpecialEffectsCont moves (e.g. Wrap, Thrash) but don't skip anything -PlayerCalcMoveDamage: ; 3d6dc (f:56dc) - ld a,[W_PLAYERMOVEEFFECT] + call c,JumpMoveEffect ; execute the effects of SpecialEffectsCont moves (e.g. Wrap, Thrash) but don't skip anything +PlayerCalcMoveDamage: + ld a,[wPlayerMoveEffect] ld hl,SetDamageEffects ld de,1 call IsInArray @@ -3197,43 +3208,43 @@ PlayerCalcMoveDamage: ; 3d6dc (f:56dc) call RandomizeDamage .moveHitTest call MoveHitTest -handleIfPlayerMoveMissed - ld a,[W_MOVEMISSED] +handleIfPlayerMoveMissed: + ld a,[wMoveMissed] and a jr z,getPlayerAnimationType - ld a,[W_PLAYERMOVEEFFECT] - sub a,EXPLODE_EFFECT + ld a,[wPlayerMoveEffect] + sub a,EXPLODE_EFFECT jr z,playPlayerMoveAnimation ; don't play any animation if the move missed, unless it was EXPLODE_EFFECT jr playerCheckIfFlyOrChargeEffect -getPlayerAnimationType - ld a,[W_PLAYERMOVEEFFECT] +getPlayerAnimationType: + ld a,[wPlayerMoveEffect] and a ld a,4 ; move has no effect other than dealing damage jr z,playPlayerMoveAnimation ld a,5 ; move has effect -playPlayerMoveAnimation +playPlayerMoveAnimation: push af - ld a,[W_PLAYERBATTSTATUS2] - bit 4,a - ld hl,Func_79747 - ld b,BANK(Func_79747) + ld a,[wPlayerBattleStatus2] + bit HasSubstituteUp,a + ld hl,HideSubstituteShowMonAnim + ld b,BANK(HideSubstituteShowMonAnim) call nz,Bankswitch pop af ld [wAnimationType],a - ld a,[W_PLAYERMOVENUM] + ld a,[wPlayerMoveNum] call PlayMoveAnimation call HandleExplodingAnimation call DrawPlayerHUDAndHPBar - ld a,[W_PLAYERBATTSTATUS2] - bit 4,a - ld hl,Func_79771 - ld b,BANK(Func_79771) + ld a,[wPlayerBattleStatus2] + bit HasSubstituteUp,a + ld hl,ReshowSubstituteAnim + ld b,BANK(ReshowSubstituteAnim) call nz,Bankswitch jr MirrorMoveCheck -playerCheckIfFlyOrChargeEffect - ld c,$1E +playerCheckIfFlyOrChargeEffect: + ld c,30 call DelayFrames - ld a,[W_PLAYERMOVEEFFECT] + ld a,[wPlayerMoveEffect] cp a,FLY_EFFECT jr z,.playAnim cp a,CHARGE_EFFECT @@ -3244,8 +3255,8 @@ playerCheckIfFlyOrChargeEffect ld [wAnimationType],a ld a,STATUS_AFFECTED_ANIM call PlayMoveAnimation -MirrorMoveCheck - ld a,[W_PLAYERMOVEEFFECT] +MirrorMoveCheck: + ld a,[wPlayerMoveEffect] cp a,MIRROR_MOVE_EFFECT jr nz,.metronomeCheck call MirrorMoveCopyMove @@ -3259,16 +3270,16 @@ MirrorMoveCheck call MetronomePickMove jp CheckIfPlayerNeedsToChargeUp ; Go back to damage calculation for the move picked by Metronome .next - ld a,[W_PLAYERMOVEEFFECT] + ld a,[wPlayerMoveEffect] ld hl,ResidualEffects2 ld de,1 call IsInArray jp c,JumpMoveEffect ; done here after executing effects of ResidualEffects2 - ld a,[W_MOVEMISSED] + ld a,[wMoveMissed] and a jr z,.moveDidNotMiss call PrintMoveFailureText - ld a,[W_PLAYERMOVEEFFECT] + ld a,[wPlayerMoveEffect] cp a,EXPLODE_EFFECT ; even if Explosion or Selfdestruct missed, its effect still needs to be activated jr z,.notDone jp ExecutePlayerMoveDone ; otherwise, we're done if the move missed @@ -3279,7 +3290,7 @@ MirrorMoveCheck ld a,1 ld [wMoveDidntMiss],a .notDone - ld a,[W_PLAYERMOVEEFFECT] + ld a,[wPlayerMoveEffect] ld hl,AlwaysHappenSideEffects ld de,1 call IsInArray @@ -3291,13 +3302,13 @@ MirrorMoveCheck ret z ; don't do anything else if the enemy fainted call HandleBuildingRage - ld hl,W_PLAYERBATTSTATUS1 + ld hl,wPlayerBattleStatus1 bit AttackingMultipleTimes,[hl] jr z,.executeOtherEffects ld a,[wPlayerNumAttacksLeft] dec a ld [wPlayerNumAttacksLeft],a - jp nz,getPlayerAnimationType ; for multi-hit moves, apply attack until PlayerNumAttacksLeft hits 0 or the enemy faints. + jp nz,getPlayerAnimationType ; for multi-hit moves, apply attack until PlayerNumAttacksLeft hits 0 or the enemy faints. ; damage calculation and accuracy tests only happen for the first hit res AttackingMultipleTimes,[hl] ; clear attacking multiple times status when all attacks are over ld hl,MultiHitText @@ -3305,7 +3316,7 @@ MirrorMoveCheck xor a ld [wPlayerNumHits],a .executeOtherEffects - ld a,[W_PLAYERMOVEEFFECT] + ld a,[wPlayerMoveEffect] and a jp z,ExecutePlayerMoveDone ld hl,SpecialEffects @@ -3317,17 +3328,17 @@ MirrorMoveCheck ; Responsible for executing Twineedle's second side effect (poison). jp ExecutePlayerMoveDone -MultiHitText: ; 3d805 (f:5805) +MultiHitText: TX_FAR _MultiHitText db "@" -ExecutePlayerMoveDone: ; 3d80a (f:580a) +ExecutePlayerMoveDone: xor a - ld [wcd6a],a + ld [wActionResultOrTookBattleTurn],a ld b,1 ret -PrintGhostText: ; 3d811 (f:5811) +PrintGhostText: ; print the ghost battle messages call IsGhostBattle ret nz @@ -3347,19 +3358,19 @@ PrintGhostText: ; 3d811 (f:5811) xor a ret -ScaredText: ; 3d830 (f:5830) +ScaredText: TX_FAR _ScaredText db "@" -GetOutText: ; 3d835 (f:5835) +GetOutText: TX_FAR _GetOutText db "@" -IsGhostBattle: ; 3d83a (f:583a) - ld a,[W_ISINBATTLE] +IsGhostBattle: + ld a,[wIsInBattle] dec a ret nz - ld a,[W_CURMAP] + ld a,[wCurMap] cp a,POKEMONTOWER_1 jr c,.next cp a,LAVENDER_HOUSE_1 @@ -3374,7 +3385,7 @@ IsGhostBattle: ; 3d83a (f:583a) ; checks for various status conditions affecting the player mon ; stores whether the mon cannot use a move this turn in Z flag -CheckPlayerStatusConditions: ; 3d854 (f:5854) +CheckPlayerStatusConditions: ld hl,wBattleMonStatus ld a,[hl] and a,SLP ; sleep mask @@ -3412,7 +3423,7 @@ CheckPlayerStatusConditions: ; 3d854 (f:5854) jp .returnToHL .HeldInPlaceCheck - ld a,[W_ENEMYBATTSTATUS1] + ld a,[wEnemyBattleStatus1] bit UsingTrappingMove,a ; is enemy using a mult-turn move like wrap? jp z,.FlinchedCheck ld hl,CantMoveText @@ -3421,7 +3432,7 @@ CheckPlayerStatusConditions: ; 3d854 (f:5854) jp .returnToHL .FlinchedCheck - ld hl,W_PLAYERBATTSTATUS1 + ld hl,wPlayerBattleStatus1 bit Flinched,[hl] jp z,.HyperBeamCheck res Flinched,[hl] ; reset player's flinch status @@ -3431,7 +3442,7 @@ CheckPlayerStatusConditions: ; 3d854 (f:5854) jp .returnToHL .HyperBeamCheck - ld hl,W_PLAYERBATTSTATUS2 + ld hl,wPlayerBattleStatus2 bit NeedsToRecharge,[hl] jr z,.AnyMoveDisabledCheck res NeedsToRecharge,[hl] ; reset player's recharge status @@ -3441,27 +3452,27 @@ CheckPlayerStatusConditions: ; 3d854 (f:5854) jp .returnToHL .AnyMoveDisabledCheck - ld hl,W_PLAYERDISABLEDMOVE + ld hl,wPlayerDisabledMove ld a,[hl] and a jr z,.ConfusedCheck dec a ld [hl],a - and a,$F ; did Disable counter hit 0? + and $f ; did Disable counter hit 0? jr nz,.ConfusedCheck ld [hl],a - ld [wccee],a + ld [wPlayerDisabledMoveNumber],a ld hl,DisabledNoMoreText call PrintText .ConfusedCheck - ld a,[W_PLAYERBATTSTATUS1] + ld a,[wPlayerBattleStatus1] add a ; is player confused? jr nc,.TriedToUseDisabledMoveCheck - ld hl,W_PLAYERCONFUSEDCOUNTER + ld hl,wPlayerConfusedCounter dec [hl] jr nz,.IsConfused - ld hl,W_PLAYERBATTSTATUS1 + ld hl,wPlayerBattleStatus1 res Confused,[hl] ; if confused counter hit 0, reset confusion status ld hl,ConfusedNoMoreText call PrintText @@ -3476,15 +3487,16 @@ CheckPlayerStatusConditions: ; 3d854 (f:5854) call BattleRandom cp a,$80 ; 50% chance to hurt itself jr c,.TriedToUseDisabledMoveCheck - ld hl,W_PLAYERBATTSTATUS1 + ld hl,wPlayerBattleStatus1 ld a,[hl] - and a, 1 << Confused ; if mon hurts itself, clear every other status from W_PLAYERBATTSTATUS1 + and a, 1 << Confused ; if mon hurts itself, clear every other status from wPlayerBattleStatus1 ld [hl],a call HandleSelfConfusionDamage jr .MonHurtItselfOrFullyParalysed .TriedToUseDisabledMoveCheck - ld a,[wccee] +; prevents a disabled move that was selected before being disabled from being used + ld a,[wPlayerDisabledMoveNumber] and a jr z,.ParalysisCheck ld hl,wPlayerSelectedMove @@ -3505,12 +3517,12 @@ CheckPlayerStatusConditions: ; 3d854 (f:5854) call PrintText .MonHurtItselfOrFullyParalysed - ld hl,W_PLAYERBATTSTATUS1 + ld hl,wPlayerBattleStatus1 ld a,[hl] - ; clear bide, thrashing, charging up, and trapping moves such as warp (already cleared for confusion damage) - and a, (1 << AttackingMultipleTimes) | (1 << Flinched) | (1 << Invulnerable) | (1 << Confused) + ; clear bide, thrashing, charging up, and trapping moves such as warp (already cleared for confusion damage) + and $ff ^ ((1 << StoringEnergy) | (1 << ThrashingAbout) | (1 << ChargingUp) | (1 << UsingTrappingMove)) ld [hl],a - ld a,[W_PLAYERMOVEEFFECT] + ld a,[wPlayerMoveEffect] cp a,FLY_EFFECT jr z,.FlyOrChargeEffect cp a,CHARGE_EFFECT @@ -3527,12 +3539,12 @@ CheckPlayerStatusConditions: ; 3d854 (f:5854) jp .returnToHL ; if using a two-turn move, we need to recharge the first turn .BideCheck - ld hl,W_PLAYERBATTSTATUS1 + ld hl,wPlayerBattleStatus1 bit StoringEnergy,[hl] ; is mon using bide? jr z,.ThrashingAboutCheck xor a - ld [W_PLAYERMOVENUM],a - ld hl,W_DAMAGE + ld [wPlayerMoveNum],a + ld hl,wDamage ld a,[hli] ld b,a ld c,[hl] @@ -3549,30 +3561,30 @@ CheckPlayerStatusConditions: ; 3d854 (f:5854) ld hl,ExecutePlayerMoveDone jp .returnToHL ; unless mon unleashes energy, can't move this turn .UnleashEnergy - ld hl,W_PLAYERBATTSTATUS1 + ld hl,wPlayerBattleStatus1 res StoringEnergy,[hl] ; not using bide any more ld hl,UnleashedEnergyText call PrintText ld a,1 - ld [W_PLAYERMOVEPOWER],a + ld [wPlayerMovePower],a ld hl,wPlayerBideAccumulatedDamage + 1 ld a,[hld] add a ld b,a - ld [W_DAMAGE + 1],a + ld [wDamage + 1],a ld a,[hl] rl a ; double the damage - ld [W_DAMAGE],a + ld [wDamage],a or b jr nz,.next ld a,1 - ld [W_MOVEMISSED],a + ld [wMoveMissed],a .next xor a ld [hli],a ld [hl],a ld a,BIDE - ld [W_PLAYERMOVENUM],a + ld [wPlayerMoveNum],a ld hl,handleIfPlayerMoveMissed ; skip damage calculation, DecrementPP and MoveHitTest jp .returnToHL @@ -3580,22 +3592,22 @@ CheckPlayerStatusConditions: ; 3d854 (f:5854) bit ThrashingAbout,[hl] ; is mon using thrash or petal dance? jr z,.MultiturnMoveCheck ld a,THRASH - ld [W_PLAYERMOVENUM],a + ld [wPlayerMoveNum],a ld hl,ThrashingAboutText call PrintText ld hl,wPlayerNumAttacksLeft - dec [hl] ; did Trashing About counter hit 0? + dec [hl] ; did Thrashing About counter hit 0? ld hl,PlayerCalcMoveDamage ; skip DecrementPP - jp nz,.returnToHL + jp nz,.returnToHL push hl - ld hl,W_PLAYERBATTSTATUS1 - res ThrashingAbout,[hl] ; no longer trashing about + ld hl,wPlayerBattleStatus1 + res ThrashingAbout,[hl] ; no longer thrashing about set Confused,[hl] ; confused call BattleRandom and a,3 inc a inc a ; confused for 2-5 turns - ld [W_PLAYERCONFUSEDCOUNTER],a + ld [wPlayerConfusedCounter],a pop hl ; skip DecrementPP jp .returnToHL @@ -3607,13 +3619,13 @@ CheckPlayerStatusConditions: ; 3d854 (f:5854) ld a,[wPlayerNumAttacksLeft] dec a ; did multi-turn move end? ld [wPlayerNumAttacksLeft],a - ld hl,getPlayerAnimationType ; if it didn't, skip damage calculation (deal damage equal to last hit), + ld hl,getPlayerAnimationType ; if it didn't, skip damage calculation (deal damage equal to last hit), ; DecrementPP and MoveHitTest jp nz,.returnToHL jp .returnToHL .RageCheck - ld a, [W_PLAYERBATTSTATUS2] + ld a, [wPlayerBattleStatus2] bit UsingRage, a ; is mon using rage? jp z, .checkPlayerStatusConditionsDone ; if we made it this far, mon can move normally this turn ld a, RAGE @@ -3621,7 +3633,7 @@ CheckPlayerStatusConditions: ; 3d854 (f:5854) call GetMoveName call CopyStringToCF4B xor a - ld [W_PLAYERMOVEEFFECT], a + ld [wPlayerMoveEffect], a ld hl, PlayerCanExecuteMove jp .returnToHL @@ -3634,77 +3646,77 @@ CheckPlayerStatusConditions: ; 3d854 (f:5854) and a ret -FastAsleepText: ; 3da3d (f:5a3d) +FastAsleepText: TX_FAR _FastAsleepText db "@" -WokeUpText: ; 3da42 (f:5a42) +WokeUpText: TX_FAR _WokeUpText db "@" -IsFrozenText: ; 3da47 (f:5a47) +IsFrozenText: TX_FAR _IsFrozenText db "@" -FullyParalyzedText: ; 3da4c (f:5a4c) +FullyParalyzedText: TX_FAR _FullyParalyzedText db "@" -FlinchedText: ; 3da51 (f:5a51) +FlinchedText: TX_FAR _FlinchedText db "@" -MustRechargeText: ; 3da56 (f:5a56) +MustRechargeText: TX_FAR _MustRechargeText db "@" -DisabledNoMoreText: ; 3da5b (f:5a5b) +DisabledNoMoreText: TX_FAR _DisabledNoMoreText db "@" -IsConfusedText: ; 3da60 (f:5a60) +IsConfusedText: TX_FAR _IsConfusedText db "@" -HurtItselfText: ; 3da65 (f:5a65) +HurtItselfText: TX_FAR _HurtItselfText db "@" -ConfusedNoMoreText: ; 3da6a (f:5a6a) +ConfusedNoMoreText: TX_FAR _ConfusedNoMoreText db "@" -SavingEnergyText: ; 3da6f (f:5a6f) +SavingEnergyText: TX_FAR _SavingEnergyText db "@" -UnleashedEnergyText: ; 3da74 (f:5a74) +UnleashedEnergyText: TX_FAR _UnleashedEnergyText db "@" -ThrashingAboutText: ; 3da79 (f:5a79) +ThrashingAboutText: TX_FAR _ThrashingAboutText db "@" -AttackContinuesText: ; 3da7e (f:5a7e) +AttackContinuesText: TX_FAR _AttackContinuesText db "@" -CantMoveText: ; 3da83 (f:5a83) +CantMoveText: TX_FAR _CantMoveText db "@" -PrintMoveIsDisabledText: ; 3da88 (f:5a88) +PrintMoveIsDisabledText: ld hl, wPlayerSelectedMove - ld de, W_PLAYERBATTSTATUS1 + ld de, wPlayerBattleStatus1 ld a, [H_WHOSETURN] and a jr z, .removeChargingUp inc hl - ld de, W_ENEMYBATTSTATUS1 + ld de, wEnemyBattleStatus1 .removeChargingUp ld a, [de] - res ChargingUp, a ; end the pokemon's + res ChargingUp, a ; end the pokemon's ld [de], a ld a, [hl] ld [wd11e], a @@ -3712,11 +3724,11 @@ PrintMoveIsDisabledText: ; 3da88 (f:5a88) ld hl, MoveIsDisabledText jp PrintText -MoveIsDisabledText: ; 3daa8 (f:5aa8) +MoveIsDisabledText: TX_FAR _MoveIsDisabledText db "@" -HandleSelfConfusionDamage: ; 3daad (f:5aad) +HandleSelfConfusionDamage: ld hl, HurtItselfText call PrintText ld hl, wEnemyMonDefense @@ -3728,7 +3740,7 @@ HandleSelfConfusionDamage: ; 3daad (f:5aad) ld [hli], a ld a, [wBattleMonDefense + 1] ld [hl], a - ld hl, W_PLAYERMOVEEFFECT + ld hl, wPlayerMoveEffect push hl ld a, [hl] push af @@ -3760,24 +3772,29 @@ HandleSelfConfusionDamage: ; 3daad (f:5aad) ld [H_WHOSETURN], a jp ApplyDamageToPlayerPokemon -PrintMonName1Text: ; 3daf5 (f:5af5) +PrintMonName1Text: ld hl, MonName1Text jp PrintText -MonName1Text: ; 3dafb (f:5afb) +; this function wastes time calling DetermineExclamationPointTextNum +; and choosing between Used1Text and Used2Text, even though +; those text strings are identical and both continue at PrintInsteadText +; this likely had to do with Japanese grammar that got translated, +; but the functionality didn't get removed +MonName1Text: TX_FAR _MonName1Text - db $08 ; asm + TX_ASM ld a, [H_WHOSETURN] and a - ld a, [W_PLAYERMOVENUM] + ld a, [wPlayerMoveNum] ld hl, wPlayerUsedMove - jr z, .asm_3db11 - ld a, [W_ENEMYMOVENUM] + jr z, .playerTurn + ld a, [wEnemyMoveNum] ld hl, wEnemyUsedMove -.asm_3db11 +.playerTurn ld [hl], a ld [wd11e], a - call Func_3db85 + call DetermineExclamationPointTextNum ld a, [wMonIsDisobedient] and a ld hl, Used2Text @@ -3789,35 +3806,37 @@ MonName1Text: ; 3dafb (f:5afb) ld hl, Used1Text ret -Used1Text: ; 3db2d (f:5b2d) +Used1Text: TX_FAR _Used1Text - db $08 ; asm + TX_ASM jr PrintInsteadText -Used2Text: ; 3db34 (f:5b34) +Used2Text: TX_FAR _Used2Text - db $08 ; asm + TX_ASM + ; fall through -PrintInsteadText: ; 3db39 (f:5b39) +PrintInsteadText: ld a, [wMonIsDisobedient] and a - jr z, PrintCF4BText + jr z, PrintMoveName ld hl, InsteadText ret -InsteadText: ; 3db43 (f:5b43) +InsteadText: TX_FAR _InsteadText - db $08 ; asm + TX_ASM + ; fall through -PrintCF4BText: ; 3db48 (f:5b48) - ld hl, CF4BText +PrintMoveName: + ld hl, _PrintMoveName ret -CF4BText: ; 3db4c (f:5b4c) +_PrintMoveName: TX_FAR _CF4BText - db $08 ; asm + TX_ASM ld hl, ExclamationPointPointerTable - ld a, [wd11e] + ld a, [wd11e] ; exclamation point num add a push bc ld b, $0 @@ -3829,56 +3848,63 @@ CF4BText: ; 3db4c (f:5b4c) ld l, a ret -ExclamationPointPointerTable: ; 3db62 (f:5b62) +ExclamationPointPointerTable: dw ExclamationPoint1Text dw ExclamationPoint2Text dw ExclamationPoint3Text dw ExclamationPoint4Text dw ExclamationPoint5Text -ExclamationPoint1Text: ; 3db6c (f:5b6c) +ExclamationPoint1Text: TX_FAR _ExclamationPoint1Text db "@" -ExclamationPoint2Text: ; 3db71 (f:5b71) +ExclamationPoint2Text: TX_FAR _ExclamationPoint2Text db "@" -ExclamationPoint3Text: ; 3db76 (f:5b76) +ExclamationPoint3Text: TX_FAR _ExclamationPoint3Text db "@" -ExclamationPoint4Text: ; 3db7b (f:5b7b) +ExclamationPoint4Text: TX_FAR _ExclamationPoint4Text db "@" -ExclamationPoint5Text: ; 3db80 (f:5b80) +ExclamationPoint5Text: TX_FAR _ExclamationPoint5Text db "@" -Func_3db85: ; 3db85 (f:5b85) +; this function does nothing useful +; if the move being used is in set [1-4] from ExclamationPointMoveSets, +; use ExclamationPoint[1-4]Text +; otherwise, use ExclamationPoint5Text +; but all five text strings are identical +; this likely had to do with Japanese grammar that got translated, +; but the functionality didn't get removed +DetermineExclamationPointTextNum: push bc - ld a, [wd11e] ; move number + ld a, [wd11e] ; move ID ld c, a ld b, $0 - ld hl, UnknownMovesList_3dba3 -.asm_3db8f + ld hl, ExclamationPointMoveSets +.loop ld a, [hli] cp $ff - jr z, .asm_3db9d + jr z, .done cp c - jr z, .asm_3db9d + jr z, .done and a - jr nz, .asm_3db8f + jr nz, .loop inc b - jr .asm_3db8f -.asm_3db9d + jr .loop +.done ld a, b - ld [wd11e], a + ld [wd11e], a ; exclamation point num pop bc ret -UnknownMovesList_3dba3: ; 3dba3 (f:5ba3) +ExclamationPointMoveSets: db SWORDS_DANCE, GROWTH db $00 db RECOVER, BIDE, SELFDESTRUCT, AMNESIA @@ -3893,12 +3919,12 @@ UnknownMovesList_3dba3: ; 3dba3 (f:5ba3) db $00 db $FF ; terminator -PrintMoveFailureText: ; 3dbe2 (f:5be2) - ld de, W_PLAYERMOVEEFFECT +PrintMoveFailureText: + ld de, wPlayerMoveEffect ld a, [H_WHOSETURN] and a jr z, .playersTurn - ld de, W_ENEMYMOVEEFFECT + ld de, wEnemyMoveEffect .playersTurn ld hl, DoesntAffectMonText ld a, [wDamageMultipliers] @@ -3920,8 +3946,8 @@ PrintMoveFailureText: ; 3dbe2 (f:5be2) ret nz ; if you get here, the mon used jump kick or hi jump kick and missed - ld hl, W_DAMAGE ; since the move missed, W_DAMAGE will always contain 0 at this point. - ; Thus, recoil damage will always be equal to 1 + ld hl, wDamage ; since the move missed, wDamage will always contain 0 at this point. + ; Thus, recoil damage will always be equal to 1 ; even if it was intended to be potential damage/8. ld a, [hli] ld b, [hl] @@ -3942,7 +3968,7 @@ PrintMoveFailureText: ; 3dbe2 (f:5be2) ld hl, KeptGoingAndCrashedText call PrintText ld b, $4 - predef Func_48125 + predef PredefShakeScreenHorizontally ld a, [H_WHOSETURN] and a jr nz, .enemyTurn @@ -3950,28 +3976,28 @@ PrintMoveFailureText: ; 3dbe2 (f:5be2) .enemyTurn jp ApplyDamageToEnemyPokemon -AttackMissedText: ; 3dc42 (f:5c42) +AttackMissedText: TX_FAR _AttackMissedText db "@" -KeptGoingAndCrashedText: ; 3dc47 (f:5c47) +KeptGoingAndCrashedText: TX_FAR _KeptGoingAndCrashedText db "@" -UnaffectedText: ; 3dc4c (f:5c4c) +UnaffectedText: TX_FAR _UnaffectedText db "@" -PrintDoesntAffectText: ; 3dc51 (f:5c51) +PrintDoesntAffectText: ld hl, DoesntAffectMonText jp PrintText -DoesntAffectMonText: ; 3dc57 (f:5c57) +DoesntAffectMonText: TX_FAR _DoesntAffectMonText db "@" ; if there was a critical hit or an OHKO was successful, print the corresponding text -PrintCriticalOHKOText: ; 3dc5c (f:5c5c) +PrintCriticalOHKOText: ld a, [wCriticalHitOrOHKO] and a jr z, .done ; do nothing if there was no critical hit or successful OHKO @@ -3988,24 +4014,24 @@ PrintCriticalOHKOText: ; 3dc5c (f:5c5c) xor a ld [wCriticalHitOrOHKO], a .done - ld c, $14 + ld c, 20 jp DelayFrames -CriticalOHKOTextPointers: ; 3dc7a (f:5c7a) +CriticalOHKOTextPointers: dw CriticalHitText dw OHKOText -CriticalHitText: ; 3dc7e (f:5c7e) +CriticalHitText: TX_FAR _CriticalHitText db "@" -OHKOText: ; 3dc83 (f:5c83) +OHKOText: TX_FAR _OHKOText db "@" ; checks if a traded mon will disobey due to lack of badges ; stores whether the mon will use a move in Z flag -CheckForDisobedience: ; 3dc88 (f:5c88) +CheckForDisobedience: xor a ld [wMonIsDisobedient], a ld a, [wLinkState] @@ -4030,7 +4056,7 @@ CheckForDisobedience: ; 3dc88 (f:5c88) ; it was traded .monIsTraded ; what level might disobey? - ld hl, W_OBTAINEDBADGES + ld hl, wObtainedBadges bit 7, [hl] ld a, 101 jr nz, .next @@ -4112,7 +4138,7 @@ CheckForDisobedience: ; 3dc88 (f:5c88) ld a, [wBattleMonMoves + 1] and a ; is the second move slot empty? jr z, .monDoesNothing ; mon will not use move if it only knows one move - ld a, [wccee] + ld a, [wPlayerDisabledMoveNumber] and a jr nz, .monDoesNothing ld a, [wPlayerSelectedMove] @@ -4184,38 +4210,38 @@ CheckForDisobedience: ; 3dc88 (f:5c88) xor a ; set Z flag ret -LoafingAroundText: ; 3ddb6 (f:5db6) +LoafingAroundText: TX_FAR _LoafingAroundText db "@" -BeganToNapText: ; 3ddbb (f:5dbb) +BeganToNapText: TX_FAR _BeganToNapText db "@" -WontObeyText: ; 3ddc0 (f:5dc0) +WontObeyText: TX_FAR _WontObeyText db "@" -TurnedAwayText: ; 3ddc5 (f:5dc5) +TurnedAwayText: TX_FAR _TurnedAwayText db "@" -IgnoredOrdersText: ; 3ddca (f:5dca) +IgnoredOrdersText: TX_FAR _IgnoredOrdersText db "@" ; sets b, c, d, and e for the CalculateDamage routine in the case of an attack by the player mon -GetDamageVarsForPlayerAttack: ; 3ddcf (f:5dcf) +GetDamageVarsForPlayerAttack: xor a - ld hl, W_DAMAGE ; damage to eventually inflict, initialise to zero + ld hl, wDamage ; damage to eventually inflict, initialise to zero ldi [hl], a ld [hl], a - ld hl, W_PLAYERMOVEPOWER + ld hl, wPlayerMovePower ld a, [hli] and a ld d, a ; d = move power ret z ; return if move power is zero - ld a, [hl] ; a = [W_PLAYERMOVETYPE] + ld a, [hl] ; a = [wPlayerMoveType] cp FIRE ; types >= FIRE are all special jr nc, .specialAttack .physicalAttack @@ -4223,7 +4249,7 @@ GetDamageVarsForPlayerAttack: ; 3ddcf (f:5dcf) ld a, [hli] ld b, a ld c, [hl] ; bc = enemy defense - ld a, [W_ENEMYBATTSTATUS3] + ld a, [wEnemyBattleStatus3] bit HasReflectUp, a ; check for Reflect jr z, .physicalAttackCritCheck ; if the enemy has used Reflect, double the enemy's defense @@ -4253,7 +4279,7 @@ GetDamageVarsForPlayerAttack: ; 3ddcf (f:5dcf) ld a, [hli] ld b, a ld c, [hl] ; bc = enemy special - ld a, [W_ENEMYBATTSTATUS3] + ld a, [wEnemyBattleStatus3] bit HasLightScreenUp, a ; check for Light Screen jr z, .specialAttackCritCheck ; if the enemy has used Light Screen, double the enemy's special @@ -4318,17 +4344,17 @@ GetDamageVarsForPlayerAttack: ; 3ddcf (f:5dcf) ret ; sets b, c, d, and e for the CalculateDamage routine in the case of an attack by the enemy mon -GetDamageVarsForEnemyAttack: ; 3de75 (f:5e75) - ld hl, W_DAMAGE ; damage to eventually inflict, initialise to zero +GetDamageVarsForEnemyAttack: + ld hl, wDamage ; damage to eventually inflict, initialise to zero xor a ld [hli], a ld [hl], a - ld hl, W_ENEMYMOVEPOWER + ld hl, wEnemyMovePower ld a, [hli] ld d, a ; d = move power and a ret z ; return if move power is zero - ld a, [hl] ; a = [W_ENEMYMOVETYPE] + ld a, [hl] ; a = [wEnemyMoveType] cp FIRE ; types >= FIRE are all special jr nc, .specialAttack .physicalAttack @@ -4336,7 +4362,7 @@ GetDamageVarsForEnemyAttack: ; 3de75 (f:5e75) ld a, [hli] ld b, a ld c, [hl] ; bc = player defense - ld a, [W_PLAYERBATTSTATUS3] + ld a, [wPlayerBattleStatus3] bit HasReflectUp, a ; check for Reflect jr z, .physicalAttackCritCheck ; if the player has used Reflect, double the player's defense @@ -4366,7 +4392,7 @@ GetDamageVarsForEnemyAttack: ; 3de75 (f:5e75) ld a, [hli] ld b, a ld c, [hl] - ld a, [W_PLAYERBATTSTATUS3] + ld a, [wPlayerBattleStatus3] bit HasLightScreenUp, a ; check for Light Screen jr z, .specialAttackCritCheck ; if the player has used Light Screen, double the player's special @@ -4433,7 +4459,7 @@ GetDamageVarsForEnemyAttack: ; 3de75 (f:5e75) ; get stat c of enemy mon ; c: stat to get (HP=1,Attack=2,Defense=3,Speed=4,Special=5) -GetEnemyMonStat: ; 3df1c (f:5f1c) +GetEnemyMonStat: push de push bc ld a, [wLinkState] @@ -4456,7 +4482,7 @@ GetEnemyMonStat: ; 3df1c (f:5f1c) ret .notLinkBattle ld a, [wEnemyMonLevel] - ld [W_CURENEMYLVL], a + ld [wCurEnemyLVL], a ld a, [wEnemyMonSpecies] ld [wd0b5], a call GetMonHeader @@ -4474,18 +4500,18 @@ GetEnemyMonStat: ; 3df1c (f:5f1c) pop de ret -CalculateDamage: ; 3df65 (f:5f65) +CalculateDamage: ; input: -; b: attack -; c: opponent defense -; d: base power -; e: level +; b: attack +; c: opponent defense +; d: base power +; e: level ld a, [H_WHOSETURN] ; whose turn? and a - ld a, [W_PLAYERMOVEEFFECT] + ld a, [wPlayerMoveEffect] jr z, .effect - ld a, [W_ENEMYMOVEEFFECT] + ld a, [wEnemyMoveEffect] .effect ; EXPLODE_EFFECT halves defense. @@ -4562,7 +4588,7 @@ CalculateDamage: ; 3df65 (f:5f65) ld b, 4 call Divide - ld hl, W_DAMAGE + ld hl, wDamage ld b, [hl] ld a, [H_QUOTIENT + 3] add b @@ -4636,46 +4662,45 @@ CalculateDamage: ; 3df65 (f:5f65) and a ret -JumpToOHKOMoveEffect: ; 3e016 (f:6016) +JumpToOHKOMoveEffect: call JumpMoveEffect - ld a, [W_MOVEMISSED] + ld a, [wMoveMissed] dec a ret -UnusedHighCriticalMoves: ; 3e01e (f:601e) +UnusedHighCriticalMoves: db KARATE_CHOP db RAZOR_LEAF db CRABHAMMER db SLASH db $FF -; 3e023 ; determines if attack is a critical hit ; azure heights claims "the fastest pokémon (who are,not coincidentally, ; among the most popular) tend to CH about 20 to 25% of the time." -CriticalHitTest: ; 3e023 (f:6023) +CriticalHitTest: xor a ld [wCriticalHitOrOHKO], a ld a, [H_WHOSETURN] and a ld a, [wEnemyMonSpecies] - jr nz, .asm_3e032 + jr nz, .handleEnemy ld a, [wBattleMonSpecies] -.asm_3e032 +.handleEnemy ld [wd0b5], a call GetMonHeader - ld a, [W_MONHBASESPEED] + ld a, [wMonHBaseSpeed] ld b, a srl b ; (effective (base speed/2)) ld a, [H_WHOSETURN] and a - ld hl, W_PLAYERMOVEPOWER - ld de, W_PLAYERBATTSTATUS2 + ld hl, wPlayerMovePower + ld de, wPlayerBattleStatus2 jr z, .calcCriticalHitProbability - ld hl, W_ENEMYMOVEPOWER - ld de, W_ENEMYBATTSTATUS2 -.calcCriticalHitProbability ; 0x3e04f + ld hl, wEnemyMovePower + ld de, wEnemyBattleStatus2 +.calcCriticalHitProbability ld a, [hld] ; read base power from RAM and a ret z ; do nothing if zero @@ -4721,7 +4746,7 @@ CriticalHitTest: ; 3e023 (f:6023) ret ; high critical hit moves -HighCriticalMoves: ; 3e08e (f:608e) +HighCriticalMoves: db KARATE_CHOP db RAZOR_LEAF db CRABHAMMER @@ -4730,7 +4755,7 @@ HighCriticalMoves: ; 3e08e (f:608e) ; function to determine if Counter hits and if so, how much damage it does -HandleCounterMove: ; 3e093 (f:6093) +HandleCounterMove: ; The variables checked by Counter are updated whenever the cursor points to a new move in the battle selection menu. ; This is irrelevant for the opponent's side outside of link battles, since the move selection is controlled by the AI. ; However, in the scenario where the player switches out and the opponent uses Counter, @@ -4741,18 +4766,18 @@ HandleCounterMove: ; 3e093 (f:6093) and a ; player's turn ld hl,wEnemySelectedMove - ld de,W_ENEMYMOVEPOWER + ld de,wEnemyMovePower ld a,[wPlayerSelectedMove] jr z,.next ; enemy's turn ld hl,wPlayerSelectedMove - ld de,W_PLAYERMOVEPOWER + ld de,wPlayerMovePower ld a,[wEnemySelectedMove] .next cp a,COUNTER ret nz ; return if not using Counter ld a,$01 - ld [W_MOVEMISSED],a ; initialize the move missed variable to true (it is set to false below if the move hits) + ld [wMoveMissed],a ; initialize the move missed variable to true (it is set to false below if the move hits) ld a,[hl] cp a,COUNTER ret z ; miss if the opponent's last selected move is Counter. @@ -4770,11 +4795,11 @@ HandleCounterMove: ; 3e093 (f:6093) xor a ret .counterableType - ld hl,W_DAMAGE + ld hl,wDamage ld a,[hli] or [hl] ret z ; If we made it here, Counter still misses if the last move used in battle did no damage to its target. - ; W_DAMAGE is shared by both players, so Counter may strike back damage dealt by the Counter user itself + ; wDamage is shared by both players, so Counter may strike back damage dealt by the Counter user itself ; if the conditions meet, even though 99% of the times damage will come from the target. ; if it did damage, double it ld a,[hl] @@ -4790,27 +4815,27 @@ HandleCounterMove: ; 3e093 (f:6093) ld [hl],a .noCarry xor a - ld [W_MOVEMISSED],a + ld [wMoveMissed],a call MoveHitTest ; do the normal move hit test in addition to Counter's special rules xor a ret -ApplyAttackToEnemyPokemon: ; 3e0df (f:60df) - ld a,[W_PLAYERMOVEEFFECT] +ApplyAttackToEnemyPokemon: + ld a,[wPlayerMoveEffect] cp a,OHKO_EFFECT jr z,ApplyDamageToEnemyPokemon cp a,SUPER_FANG_EFFECT jr z,.superFangEffect cp a,SPECIAL_DAMAGE_EFFECT jr z,.specialDamage - ld a,[W_PLAYERMOVEPOWER] + ld a,[wPlayerMovePower] and a jp z,ApplyAttackToEnemyPokemonDone ; no attack to apply if base power is 0 jr ApplyDamageToEnemyPokemon .superFangEffect ; set the damage to half the target's HP ld hl,wEnemyMonHP - ld de,W_DAMAGE + ld de,wDamage ld a,[hli] srl a ld [de],a @@ -4829,7 +4854,7 @@ ApplyAttackToEnemyPokemon: ; 3e0df (f:60df) ld hl,wBattleMonLevel ld a,[hl] ld b,a ; Seismic Toss deals damage equal to the user's level - ld a,[W_PLAYERMOVENUM] + ld a,[wPlayerMoveNum] cp a,SEISMIC_TOSS jr z,.storeDamage cp a,NIGHT_SHADE @@ -4855,20 +4880,20 @@ ApplyAttackToEnemyPokemon: ; 3e0df (f:60df) jr nc,.loop ld b,a .storeDamage ; store damage value at b - ld hl,W_DAMAGE + ld hl,wDamage xor a ld [hli],a ld a,b ld [hl],a -ApplyDamageToEnemyPokemon: ; 3e142 (f:6142) - ld hl,W_DAMAGE +ApplyDamageToEnemyPokemon: + ld hl,wDamage ld a,[hli] ld b,a ld a,[hl] or b jr z,ApplyAttackToEnemyPokemonDone ; we're done if damage is 0 - ld a,[W_ENEMYBATTSTATUS2] + ld a,[wEnemyBattleStatus2] bit HasSubstituteUp,a ; does the enemy have a substitute? jp nz,AttackSubstitute ; subtract the damage from the pokemon's current HP @@ -4886,7 +4911,7 @@ ApplyDamageToEnemyPokemon: ; 3e142 (f:6142) sbc b ld [wEnemyMonHP],a jr nc,.animateHpBar -; if more damage was done than the current HP, zero the HP and set the damage (W_DAMAGE) +; if more damage was done than the current HP, zero the HP and set the damage (wDamage) ; equal to how much HP the pokemon had before the attack ld a,[wHPBarOldHP+1] ld [hli],a @@ -4907,29 +4932,29 @@ ApplyDamageToEnemyPokemon: ; 3e142 (f:6142) ld [wHPBarNewHP+1],a ld a,[hl] ld [wHPBarNewHP],a - hlCoord 2, 2 + coord hl, 2, 2 xor a ld [wHPBarType],a predef UpdateHPBar2 ; animate the HP bar shortening -ApplyAttackToEnemyPokemonDone: ; 3e19d (f:619d) +ApplyAttackToEnemyPokemonDone: jp DrawHUDsAndHPBars -ApplyAttackToPlayerPokemon: ; 3e1a0 (f:61a0) - ld a,[W_ENEMYMOVEEFFECT] +ApplyAttackToPlayerPokemon: + ld a,[wEnemyMoveEffect] cp a,OHKO_EFFECT jr z,ApplyDamageToPlayerPokemon cp a,SUPER_FANG_EFFECT jr z,.superFangEffect cp a,SPECIAL_DAMAGE_EFFECT jr z,.specialDamage - ld a,[W_ENEMYMOVEPOWER] + ld a,[wEnemyMovePower] and a jp z,ApplyAttackToPlayerPokemonDone jr ApplyDamageToPlayerPokemon .superFangEffect ; set the damage to half the target's HP ld hl,wBattleMonHP - ld de,W_DAMAGE + ld de,wDamage ld a,[hli] srl a ld [de],a @@ -4948,7 +4973,7 @@ ApplyAttackToPlayerPokemon: ; 3e1a0 (f:61a0) ld hl,wEnemyMonLevel ld a,[hl] ld b,a - ld a,[W_ENEMYMOVENUM] + ld a,[wEnemyMoveNum] cp a,SEISMIC_TOSS jr z,.storeDamage cp a,NIGHT_SHADE @@ -4974,20 +4999,20 @@ ApplyAttackToPlayerPokemon: ; 3e1a0 (f:61a0) jr nc,.loop ld b,a .storeDamage - ld hl,W_DAMAGE + ld hl,wDamage xor a ld [hli],a ld a,b ld [hl],a -ApplyDamageToPlayerPokemon: ; 3e200 (f:6200) - ld hl,W_DAMAGE +ApplyDamageToPlayerPokemon: + ld hl,wDamage ld a,[hli] ld b,a ld a,[hl] or b jr z,ApplyAttackToPlayerPokemonDone ; we're done if damage is 0 - ld a,[W_PLAYERBATTSTATUS2] + ld a,[wPlayerBattleStatus2] bit HasSubstituteUp,a ; does the player have a substitute? jp nz,AttackSubstitute ; subtract the damage from the pokemon's current HP @@ -5006,7 +5031,7 @@ ApplyDamageToPlayerPokemon: ; 3e200 (f:6200) ld [wBattleMonHP],a ld [wHPBarNewHP+1],a jr nc,.animateHpBar -; if more damage was done than the current HP, zero the HP and set the damage (W_DAMAGE) +; if more damage was done than the current HP, zero the HP and set the damage (wDamage) ; equal to how much HP the pokemon had before the attack ld a,[wHPBarOldHP+1] ld [hli],a @@ -5025,34 +5050,34 @@ ApplyDamageToPlayerPokemon: ; 3e200 (f:6200) ld [wHPBarMaxHP+1],a ld a,[hl] ld [wHPBarMaxHP],a - hlCoord 10, 9 + coord hl, 10, 9 ld a,$01 ld [wHPBarType],a predef UpdateHPBar2 ; animate the HP bar shortening -ApplyAttackToPlayerPokemonDone +ApplyAttackToPlayerPokemonDone: jp DrawHUDsAndHPBars -AttackSubstitute: ; 3e25e (f:625e) +AttackSubstitute: ; Unlike the two ApplyAttackToPokemon functions, Attack Substitute is shared by player and enemy. ; Self-confusion damage as well as Hi-Jump Kick and Jump Kick recoil cause a momentary turn swap before being applied. -; If the user has a Substitute up and would take damage because of that, +; If the user has a Substitute up and would take damage because of that, ; damage will be applied to the other player's Substitute. -; Normal recoil such as from Double-Edge isn't affected by this glitch, +; Normal recoil such as from Double-Edge isn't affected by this glitch, ; because this function is never called in that case. ld hl,SubstituteTookDamageText call PrintText ; values for player turn ld de,wEnemySubstituteHP - ld bc,W_ENEMYBATTSTATUS2 + ld bc,wEnemyBattleStatus2 ld a,[H_WHOSETURN] and a jr z,.applyDamageToSubstitute ; values for enemy turn ld de,wPlayerSubstituteHP - ld bc,W_PLAYERBATTSTATUS2 + ld bc,wPlayerBattleStatus2 .applyDamageToSubstitute - ld hl,W_DAMAGE + ld hl,wDamage ld a,[hli] and a jr nz,.substituteBroke ; damage > 0xFF always breaks substitutes @@ -5062,7 +5087,7 @@ AttackSubstitute: ; 3e25e (f:625e) ld [de],a ret nc .substituteBroke -; If the target's Substitute breaks, W_DAMAGE isn't updated with the amount of HP +; If the target's Substitute breaks, wDamage isn't updated with the amount of HP ; the Substitute had before being attacked. ld h,b ld l,c @@ -5073,41 +5098,41 @@ AttackSubstitute: ; 3e25e (f:625e) ld a,[H_WHOSETURN] xor a,$01 ld [H_WHOSETURN],a - callab Func_79747 ; animate the substitute breaking + callab HideSubstituteShowMonAnim ; animate the substitute breaking ; flip the turn back to the way it was ld a,[H_WHOSETURN] xor a,$01 ld [H_WHOSETURN],a - ld hl,W_PLAYERMOVEEFFECT ; value for player's turn + ld hl,wPlayerMoveEffect ; value for player's turn and a jr z,.nullifyEffect - ld hl,W_ENEMYMOVEEFFECT ; value for enemy's turn + ld hl,wEnemyMoveEffect ; value for enemy's turn .nullifyEffect xor a ld [hl],a ; zero the effect of the attacker's move jp DrawHUDsAndHPBars -SubstituteTookDamageText: ; 3e2ac (f:62ac) +SubstituteTookDamageText: TX_FAR _SubstituteTookDamageText db "@" -SubstituteBrokeText: ; 3e2b1 (f:62b1) +SubstituteBrokeText: TX_FAR _SubstituteBrokeText db "@" ; this function raises the attack modifier of a pokemon using Rage when that pokemon is attacked -HandleBuildingRage: ; 3e2b6 (f:62b6) +HandleBuildingRage: ; values for the player turn - ld hl,W_ENEMYBATTSTATUS2 + ld hl,wEnemyBattleStatus2 ld de,wEnemyMonStatMods - ld bc,W_ENEMYMOVENUM + ld bc,wEnemyMoveNum ld a,[H_WHOSETURN] and a jr z,.next ; values for the enemy turn - ld hl,W_PLAYERBATTSTATUS2 + ld hl,wPlayerBattleStatus2 ld de,wPlayerMonStatMods - ld bc,W_PLAYERMOVENUM + ld bc,wPlayerMoveNum .next bit UsingRage,[hl] ; is the pokemon being attacked under the effect of Rage? ret z ; return if not @@ -5138,13 +5163,13 @@ HandleBuildingRage: ; 3e2b6 (f:62b6) ld [H_WHOSETURN],a ret -BuildingRageText: ; 3e2f8 (f:62f8) +BuildingRageText: TX_FAR _BuildingRageText db "@" ; copy last move for Mirror Move ; sets zero flag on failure and unsets zero flag on success -MirrorMoveCopyMove: ; 3e2fd (f:62fd) +MirrorMoveCopyMove: ; Mirror Move makes use of ccf1 (wPlayerUsedMove) and ccf2 (wEnemyUsedMove) addresses, ; which are mainly used to print the "[Pokemon] used [Move]" text. ; Both are set to 0 whenever a new Pokemon is sent out @@ -5156,11 +5181,11 @@ MirrorMoveCopyMove: ; 3e2fd (f:62fd) ; values for player turn ld a,[wEnemyUsedMove] ld hl,wPlayerSelectedMove - ld de,W_PLAYERMOVENUM + ld de,wPlayerMoveNum jr z,.next ; values for enemy turn ld a,[wPlayerUsedMove] - ld de,W_ENEMYMOVENUM + ld de,wEnemyMoveNum ld hl,wEnemySelectedMove .next ld [hl],a @@ -5174,16 +5199,16 @@ MirrorMoveCopyMove: ; 3e2fd (f:62fd) xor a ret -MirrorMoveFailedText: ; 3e324 (f:6324) +MirrorMoveFailedText: TX_FAR _MirrorMoveFailedText db "@" ; function used to reload move data for moves like Mirror Move and Metronome -ReloadMoveData: ; 3e329 (f:6329) +ReloadMoveData: ld [wd11e],a dec a ld hl,Moves - ld bc,$0006 + ld bc,MoveEnd - Moves call AddNTimes ld a,BANK(Moves) call FarCopyData ; copy the move's stats @@ -5196,19 +5221,19 @@ ReloadMoveData: ; 3e329 (f:6329) ret ; function that picks a random move for metronome -MetronomePickMove: ; 3e348 (f:6348) +MetronomePickMove: xor a ld [wAnimationType],a ld a,METRONOME call PlayMoveAnimation ; play Metronome's animation ; values for player turn - ld de,W_PLAYERMOVENUM + ld de,wPlayerMoveNum ld hl,wPlayerSelectedMove ld a,[H_WHOSETURN] and a jr z,.pickMoveLoop ; values for enemy turn - ld de,W_ENEMYMOVENUM + ld de,wEnemyMoveNum ld hl,wEnemySelectedMove ; loop to pick a random number in the range [1, $a5) to be the move used by Metronome .pickMoveLoop @@ -5225,7 +5250,7 @@ MetronomePickMove: ; 3e348 (f:6348) ; this function increments the current move's PP ; it's used to prevent moves that run another move within the same turn ; (like Mirror Move and Metronome) from losing 2 PP -IncrementMovePP: ; 3e373 (f:6373) +IncrementMovePP: ld a,[H_WHOSETURN] and a ; values for player turn @@ -5257,7 +5282,7 @@ IncrementMovePP: ; 3e373 (f:6373) ret ; function to adjust the base damage of an attack to account for type effectiveness -AdjustDamageForMoveType: ; 3e3a5 (f:63a5) +AdjustDamageForMoveType: ; values for player turn ld hl,wBattleMonType ld a,[hli] @@ -5267,8 +5292,8 @@ AdjustDamageForMoveType: ; 3e3a5 (f:63a5) ld a,[hli] ld d,a ; d = type 1 of defender ld e,[hl] ; e = type 2 of defender - ld a,[W_PLAYERMOVETYPE] - ld [wd11e],a + ld a,[wPlayerMoveType] + ld [wMoveType],a ld a,[H_WHOSETURN] and a jr z,.next @@ -5281,10 +5306,10 @@ AdjustDamageForMoveType: ; 3e3a5 (f:63a5) ld a,[hli] ld d,a ; d = type 1 of defender ld e,[hl] ; e = type 2 of defender - ld a,[W_ENEMYMOVETYPE] - ld [wd11e],a + ld a,[wEnemyMoveType] + ld [wMoveType],a .next - ld a,[wd11e] ; move type + ld a,[wMoveType] cp b ; does the move type match type 1 of the attacker? jr z,.sameTypeAttackBonus cp c ; does the move type match type 2 of the attacker? @@ -5292,7 +5317,7 @@ AdjustDamageForMoveType: ; 3e3a5 (f:63a5) jr .skipSameTypeAttackBonus .sameTypeAttackBonus ; if the move type matches one of the attacker's types - ld hl,W_DAMAGE + 1 + ld hl,wDamage + 1 ld a,[hld] ld h,[hl] ld l,a ; hl = damage @@ -5303,14 +5328,14 @@ AdjustDamageForMoveType: ; 3e3a5 (f:63a5) add hl,bc ; hl = floor(1.5 * damage) ; store damage ld a,h - ld [W_DAMAGE],a + ld [wDamage],a ld a,l - ld [W_DAMAGE + 1],a + ld [wDamage + 1],a ld hl,wDamageMultipliers set 7,[hl] .skipSameTypeAttackBonus - ld a,[wd11e] - ld b,a ; b = move type + ld a,[wMoveType] + ld b,a ld hl,TypeEffects .loop ld a,[hli] ; a = "attacking type" of the current type pair @@ -5338,7 +5363,7 @@ AdjustDamageForMoveType: ; 3e3a5 (f:63a5) ld [wDamageMultipliers],a xor a ld [H_MULTIPLICAND],a - ld hl,W_DAMAGE + ld hl,wDamage ld a,[hli] ld [H_MULTIPLICAND + 1],a ld a,[hld] @@ -5359,7 +5384,7 @@ AdjustDamageForMoveType: ; 3e3a5 (f:63a5) ; if damage is 0, make the move miss ; this only occurs if a move that would do 2 or 3 damage is 0.25x effective against the target inc a - ld [W_MOVEMISSED],a + ld [wMoveMissed],a .skipTypeImmunity pop bc pop hl @@ -5373,29 +5398,29 @@ AdjustDamageForMoveType: ; 3e3a5 (f:63a5) ; function to tell how effective the type of an enemy attack is on the player's current pokemon ; this doesn't take into account the effects that dual types can have ; (e.g. 4x weakness / resistance, weaknesses and resistances canceling) -; the result is stored in [wd11e] +; the result is stored in [wTypeEffectiveness] ; ($05 is not very effective, $10 is neutral, $14 is super effective) ; as far is can tell, this is only used once in some AI code to help decide which move to use -AIGetTypeEffectiveness: ; 3e449 (f:6449) - ld a,[W_ENEMYMOVETYPE] - ld d,a ; d = type of enemy move +AIGetTypeEffectiveness: + ld a,[wEnemyMoveType] + ld d,a ; d = type of enemy move ld hl,wBattleMonType - ld b,[hl] ; b = type 1 of player's pokemon + ld b,[hl] ; b = type 1 of player's pokemon inc hl - ld c,[hl] ; c = type 2 of player's pokemon + ld c,[hl] ; c = type 2 of player's pokemon ld a,$10 - ld [wd11e],a ; initialize [wd11e] to neutral effectiveness + ld [wTypeEffectiveness],a ; initialize to neutral effectiveness ld hl,TypeEffects .loop ld a,[hli] cp a,$ff ret z - cp d ; match the type of the move + cp d ; match the type of the move jr nz,.nextTypePair1 ld a,[hli] - cp b ; match with type 1 of pokemon + cp b ; match with type 1 of pokemon jr z,.done - cp c ; or match with type 2 of pokemon + cp c ; or match with type 2 of pokemon jr z,.done jr .nextTypePair2 .nextTypePair1 @@ -5405,23 +5430,23 @@ AIGetTypeEffectiveness: ; 3e449 (f:6449) jr .loop .done ld a,[hl] - ld [wd11e],a ; store damage multiplier + ld [wTypeEffectiveness],a ; store damage multiplier ret INCLUDE "data/type_effects.asm" ; some tests that need to pass for a move to hit -MoveHitTest: ; 3e56b (f:656b) +MoveHitTest: ; player's turn - ld hl,W_ENEMYBATTSTATUS1 - ld de,W_PLAYERMOVEEFFECT + ld hl,wEnemyBattleStatus1 + ld de,wPlayerMoveEffect ld bc,wEnemyMonStatus ld a,[H_WHOSETURN] and a jr z,.dreamEaterCheck ; enemy's turn - ld hl,W_PLAYERBATTSTATUS1 - ld de,W_ENEMYMOVEEFFECT + ld hl,wPlayerBattleStatus1 + ld de,wEnemyMoveEffect ld bc,wBattleMonStatus .dreamEaterCheck ld a,[de] @@ -5450,7 +5475,7 @@ MoveHitTest: ; 3e56b (f:656b) jr nz,.enemyTurn .playerTurn ; this checks if the move effect is disallowed by mist - ld a,[W_PLAYERMOVEEFFECT] + ld a,[wPlayerMoveEffect] cp a,ATTACK_DOWN1_EFFECT jr c,.skipEnemyMistCheck cp a,HAZE_EFFECT + 1 @@ -5467,16 +5492,16 @@ MoveHitTest: ; 3e56b (f:656b) ; FLASH, CONVERSION*, HAZE*, SCREECH, LIGHT SCREEN*, REFLECT* ; the moves that are marked with an asterisk are not affected since this ; function is not called when those moves are used - ld a,[W_ENEMYBATTSTATUS2] + ld a,[wEnemyBattleStatus2] bit ProtectedByMist,a ; is mon protected by mist? jp nz,.moveMissed .skipEnemyMistCheck - ld a,[W_PLAYERBATTSTATUS2] + ld a,[wPlayerBattleStatus2] bit UsingXAccuracy,a ; is the player using X Accuracy? ret nz ; if so, always hit regardless of accuracy/evasion jr .calcHitChance .enemyTurn - ld a,[W_ENEMYMOVEEFFECT] + ld a,[wEnemyMoveEffect] cp a,ATTACK_DOWN1_EFFECT jr c,.skipPlayerMistCheck cp a,HAZE_EFFECT + 1 @@ -5488,21 +5513,21 @@ MoveHitTest: ; 3e56b (f:656b) jr .skipPlayerMistCheck .playerMistCheck ; similar to enemy mist check - ld a,[W_PLAYERBATTSTATUS2] + ld a,[wPlayerBattleStatus2] bit ProtectedByMist,a ; is mon protected by mist? jp nz,.moveMissed .skipPlayerMistCheck - ld a,[W_ENEMYBATTSTATUS2] + ld a,[wEnemyBattleStatus2] bit UsingXAccuracy,a ; is the enemy using X Accuracy? ret nz ; if so, always hit regardless of accuracy/evasion .calcHitChance call CalcHitChance ; scale the move accuracy according to attacker's accuracy and target's evasion - ld a,[W_PLAYERMOVEACCURACY] + ld a,[wPlayerMoveAccuracy] ld b,a ld a,[H_WHOSETURN] and a jr z,.doAccuracyCheck - ld a,[W_ENEMYMOVEACCURACY] + ld a,[wEnemyMoveAccuracy] ld b,a .doAccuracyCheck ; if the random number generated is greater than or equal to the scaled accuracy, the move misses @@ -5513,26 +5538,26 @@ MoveHitTest: ; 3e56b (f:656b) ret .moveMissed xor a - ld hl,W_DAMAGE ; zero the damage + ld hl,wDamage ; zero the damage ld [hli],a ld [hl],a inc a - ld [W_MOVEMISSED],a + ld [wMoveMissed],a ld a,[H_WHOSETURN] and a jr z,.playerTurn2 .enemyTurn2 - ld hl,W_ENEMYBATTSTATUS1 + ld hl,wEnemyBattleStatus1 res UsingTrappingMove,[hl] ; end multi-turn attack e.g. wrap ret .playerTurn2 - ld hl,W_PLAYERBATTSTATUS1 + ld hl,wPlayerBattleStatus1 res UsingTrappingMove,[hl] ; end multi-turn attack e.g. wrap ret ; values for player turn -CalcHitChance: ; 3e624 (f:6624) - ld hl,W_PLAYERMOVEACCURACY +CalcHitChance: + ld hl,wPlayerMoveAccuracy ld a,[H_WHOSETURN] and a ld a,[wPlayerMonAccuracyMod] @@ -5541,7 +5566,7 @@ CalcHitChance: ; 3e624 (f:6624) ld c,a jr z,.next ; values for enemy turn - ld hl,W_ENEMYMOVEACCURACY + ld hl,wEnemyMoveAccuracy ld a,[wEnemyMonAccuracyMod] ld b,a ld a,[wPlayerMonEvasionMod] @@ -5563,7 +5588,7 @@ CalcHitChance: ; 3e624 (f:6624) ; the second iteration multiplies by the evasion ratio .loop push bc - ld hl, StatModifierRatios ; $76cb ; stat modifier ratios + ld hl, StatModifierRatios ; stat modifier ratios dec b sla b ld c,b @@ -5603,8 +5628,8 @@ CalcHitChance: ; 3e624 (f:6624) ret ; multiplies damage by a random percentage from ~85% to 100% -RandomizeDamage: ; 3e687 (f:6687) - ld hl, W_DAMAGE +RandomizeDamage: + ld hl, wDamage ld a, [hli] and a jr nz, .DamageGreaterThanOne @@ -5633,14 +5658,14 @@ RandomizeDamage: ; 3e687 (f:6687) call Divide ; divide the result by 255 ; store the modified damage ld a, [H_QUOTIENT + 2] - ld hl, W_DAMAGE + ld hl, wDamage ld [hli], a ld a, [H_QUOTIENT + 3] ld [hl], a ret ; for more detailed commentary, see equivalent function for player side (ExecutePlayerMove) -ExecuteEnemyMove: ; 3e6bc (f:66bc) +ExecuteEnemyMove: ld a, [wEnemySelectedMove] inc a jp z, ExecuteEnemyMoveDone @@ -5651,15 +5676,15 @@ ExecuteEnemyMove: ; 3e6bc (f:66bc) jr nz, .executeEnemyMove ld b, $1 ld a, [wSerialExchangeNybbleReceiveData] - cp $e + cp LINKBATTLE_STRUGGLE jr z, .executeEnemyMove - cp $4 + cp 4 ret nc .executeEnemyMove ld hl, wAILayer2Encouragement inc [hl] xor a - ld [W_MOVEMISSED], a + ld [wMoveMissed], a ld [wMoveDidntMiss], a ld a, $a ld [wDamageMultipliers], a @@ -5667,23 +5692,23 @@ ExecuteEnemyMove: ; 3e6bc (f:66bc) jr nz, .enemyHasNoSpecialConditions jp [hl] .enemyHasNoSpecialConditions - ld hl, W_ENEMYBATTSTATUS1 + ld hl, wEnemyBattleStatus1 bit ChargingUp, [hl] ; is the enemy charging up for attack? jr nz, EnemyCanExecuteChargingMove ; if so, jump call GetCurrentMove -CheckIfEnemyNeedsToChargeUp: ; 3e6fc (f:66fc) - ld a, [W_ENEMYMOVEEFFECT] +CheckIfEnemyNeedsToChargeUp: + ld a, [wEnemyMoveEffect] cp CHARGE_EFFECT jp z, JumpMoveEffect cp FLY_EFFECT jp z, JumpMoveEffect jr EnemyCanExecuteMove -EnemyCanExecuteChargingMove: ; 3e70b (f:670b) - ld hl, W_ENEMYBATTSTATUS1 +EnemyCanExecuteChargingMove: + ld hl, wEnemyBattleStatus1 res ChargingUp, [hl] ; no longer charging up for attack res Invulnerable, [hl] ; no longer invulnerable to typical attacks - ld a, [W_ENEMYMOVENUM] + ld a, [wEnemyMoveNum] ld [wd0b5], a ld a, BANK(MoveNames) ld [wPredefBank], a @@ -5692,23 +5717,23 @@ EnemyCanExecuteChargingMove: ; 3e70b (f:670b) call GetName ld de, wcd6d call CopyStringToCF4B -EnemyCanExecuteMove: ; 3e72b (f:672b) +EnemyCanExecuteMove: xor a ld [wMonIsDisobedient], a call PrintMonName1Text - ld a, [W_ENEMYMOVEEFFECT] + ld a, [wEnemyMoveEffect] ld hl, ResidualEffects1 ld de, $1 call IsInArray jp c, JumpMoveEffect - ld a, [W_ENEMYMOVEEFFECT] + ld a, [wEnemyMoveEffect] ld hl, SpecialEffectsCont ld de, $1 call IsInArray call c, JumpMoveEffect -EnemyCalcMoveDamage: ; 3e750 (f:6750) +EnemyCalcMoveDamage: call SwapPlayerAndEnemyLevels - ld a, [W_ENEMYMOVEEFFECT] + ld a, [wEnemyMoveEffect] ld hl, SetDamageEffects ld de, $1 call IsInArray @@ -5724,54 +5749,54 @@ EnemyCalcMoveDamage: ; 3e750 (f:6750) call AdjustDamageForMoveType call RandomizeDamage -EnemyMoveHitTest: ; 3e77f (f:677f) +EnemyMoveHitTest: call MoveHitTest -handleIfEnemyMoveMissed: ; 3e782 (f:6782) - ld a, [W_MOVEMISSED] +handleIfEnemyMoveMissed: + ld a, [wMoveMissed] and a - jr z, .asm_3e791 - ld a, [W_ENEMYMOVEEFFECT] + jr z, .moveDidNotMiss + ld a, [wEnemyMoveEffect] cp EXPLODE_EFFECT - jr z, asm_3e7a0 + jr z, handleExplosionMiss jr EnemyCheckIfFlyOrChargeEffect -.asm_3e791 +.moveDidNotMiss call SwapPlayerAndEnemyLevels -GetEnemyAnimationType: ; 3e794 (f:6794) - ld a, [W_ENEMYMOVEEFFECT] +GetEnemyAnimationType: + ld a, [wEnemyMoveEffect] and a ld a, $1 jr z, playEnemyMoveAnimation ld a, $2 jr playEnemyMoveAnimation -asm_3e7a0: ; 3e7a0 (f:67a0) +handleExplosionMiss: call SwapPlayerAndEnemyLevels xor a -playEnemyMoveAnimation: ; 3e7a4 (f:67a4) +playEnemyMoveAnimation: push af - ld a, [W_ENEMYBATTSTATUS2] + ld a, [wEnemyBattleStatus2] bit HasSubstituteUp, a ; does mon have a substitute? - ld hl, Func_79747 - ld b, BANK(Func_79747) + ld hl, HideSubstituteShowMonAnim + ld b, BANK(HideSubstituteShowMonAnim) call nz, Bankswitch pop af ld [wAnimationType], a - ld a, [W_ENEMYMOVENUM] + ld a, [wEnemyMoveNum] call PlayMoveAnimation call HandleExplodingAnimation call DrawEnemyHUDAndHPBar - ld a, [W_ENEMYBATTSTATUS2] + ld a, [wEnemyBattleStatus2] bit HasSubstituteUp, a ; does mon have a substitute? - ld hl, Func_79771 - ld b, BANK(Func_79771) + ld hl, ReshowSubstituteAnim + ld b, BANK(ReshowSubstituteAnim) call nz, Bankswitch ; slide the substitute's sprite out jr EnemyCheckIfMirrorMoveEffect -EnemyCheckIfFlyOrChargeEffect: ; 3e7d1 (f:67d1) +EnemyCheckIfFlyOrChargeEffect: call SwapPlayerAndEnemyLevels - ld c, $1e + ld c, 30 call DelayFrames - ld a, [W_ENEMYMOVEEFFECT] + ld a, [wEnemyMoveEffect] cp FLY_EFFECT jr z, .playAnim cp CHARGE_EFFECT @@ -5782,8 +5807,8 @@ EnemyCheckIfFlyOrChargeEffect: ; 3e7d1 (f:67d1) ld [wAnimationType], a ld a,STATUS_AFFECTED_ANIM call PlayMoveAnimation -EnemyCheckIfMirrorMoveEffect: ; 3e7ef (f:67ef) - ld a, [W_ENEMYMOVEEFFECT] +EnemyCheckIfMirrorMoveEffect: + ld a, [wEnemyMoveEffect] cp MIRROR_MOVE_EFFECT jr nz, .notMirrorMoveEffect call MirrorMoveCopyMove @@ -5795,27 +5820,27 @@ EnemyCheckIfMirrorMoveEffect: ; 3e7ef (f:67ef) call MetronomePickMove jp CheckIfEnemyNeedsToChargeUp .notMetronomeEffect - ld a, [W_ENEMYMOVEEFFECT] + ld a, [wEnemyMoveEffect] ld hl, ResidualEffects2 ld de, $1 call IsInArray jp c, JumpMoveEffect - ld a, [W_MOVEMISSED] + ld a, [wMoveMissed] and a - jr z, .asm_3e82b + jr z, .moveDidNotMiss call PrintMoveFailureText - ld a, [W_ENEMYMOVEEFFECT] + ld a, [wEnemyMoveEffect] cp EXPLODE_EFFECT - jr z, .asm_3e83e + jr z, .handleExplosionMiss jp ExecuteEnemyMoveDone -.asm_3e82b +.moveDidNotMiss call ApplyAttackToPlayerPokemon call PrintCriticalOHKOText callab DisplayEffectiveness ld a, 1 ld [wMoveDidntMiss], a -.asm_3e83e - ld a, [W_ENEMYMOVEEFFECT] +.handleExplosionMiss + ld a, [wEnemyMoveEffect] ld hl, AlwaysHappenSideEffects ld de, $1 call IsInArray @@ -5826,9 +5851,9 @@ EnemyCheckIfMirrorMoveEffect: ; 3e7ef (f:67ef) or b ret z call HandleBuildingRage - ld hl, W_ENEMYBATTSTATUS1 + ld hl, wEnemyBattleStatus1 bit AttackingMultipleTimes, [hl] ; is mon hitting multiple times? (example: double kick) - jr z, .asm_3e873 + jr z, .notMultiHitMove push hl ld hl, wEnemyNumAttacksLeft dec [hl] @@ -5839,8 +5864,8 @@ EnemyCheckIfMirrorMoveEffect: ; 3e7ef (f:67ef) call PrintText xor a ld [wEnemyNumHits], a -.asm_3e873 - ld a, [W_ENEMYMOVEEFFECT] +.notMultiHitMove + ld a, [wEnemyMoveEffect] and a jr z, ExecuteEnemyMoveDone ld hl, SpecialEffects @@ -5849,17 +5874,17 @@ EnemyCheckIfMirrorMoveEffect: ; 3e7ef (f:67ef) call nc, JumpMoveEffect jr ExecuteEnemyMoveDone -HitXTimesText: ; 3e887 (f:6887) +HitXTimesText: TX_FAR _HitXTimesText db "@" -ExecuteEnemyMoveDone: ; 3e88c (f:688c) +ExecuteEnemyMoveDone: ld b, $1 ret ; checks for various status conditions affecting the enemy mon ; stores whether the mon cannot use a move this turn in Z flag -CheckEnemyStatusConditions: ; 3e88f (f:688f) +CheckEnemyStatusConditions: ld hl, wEnemyMonStatus ld a, [hl] and SLP ; sleep mask @@ -5874,14 +5899,14 @@ CheckEnemyStatusConditions: ; 3e88f (f:688f) ld [wAnimationType], a ld a,SLP_ANIM call PlayMoveAnimation - jr .next1 + jr .sleepDone .wokeUp ld hl, WokeUpText call PrintText -.next1 +.sleepDone xor a ld [wEnemyUsedMove], a - ld hl, ExecuteEnemyMoveDone + ld hl, ExecuteEnemyMoveDone ; enemy can't move this turn jp .enemyReturnToHL .checkIfFrozen bit FRZ, [hl] @@ -5890,56 +5915,56 @@ CheckEnemyStatusConditions: ; 3e88f (f:688f) call PrintText xor a ld [wEnemyUsedMove], a - ld hl, ExecuteEnemyMoveDone + ld hl, ExecuteEnemyMoveDone ; enemy can't move this turn jp .enemyReturnToHL .checkIfTrapped - ld a, [W_PLAYERBATTSTATUS1] + ld a, [wPlayerBattleStatus1] bit UsingTrappingMove, a ; is the player using a multi-turn attack like warp jp z, .checkIfFlinched ld hl, CantMoveText call PrintText - ld hl, ExecuteEnemyMoveDone + ld hl, ExecuteEnemyMoveDone ; enemy can't move this turn jp .enemyReturnToHL .checkIfFlinched - ld hl, W_ENEMYBATTSTATUS1 + ld hl, wEnemyBattleStatus1 bit Flinched, [hl] ; check if enemy mon flinched jp z, .checkIfMustRecharge res Flinched, [hl] ld hl, FlinchedText call PrintText - ld hl, ExecuteEnemyMoveDone + ld hl, ExecuteEnemyMoveDone ; enemy can't move this turn jp .enemyReturnToHL .checkIfMustRecharge - ld hl, W_ENEMYBATTSTATUS2 + ld hl, wEnemyBattleStatus2 bit NeedsToRecharge, [hl] ; check if enemy mon has to recharge after using a move jr z, .checkIfAnyMoveDisabled res NeedsToRecharge, [hl] ld hl, MustRechargeText call PrintText - ld hl, ExecuteEnemyMoveDone + ld hl, ExecuteEnemyMoveDone ; enemy can't move this turn jp .enemyReturnToHL .checkIfAnyMoveDisabled - ld hl, W_ENEMYDISABLEDMOVE + ld hl, wEnemyDisabledMove ld a, [hl] and a jr z, .checkIfConfused - dec a + dec a ; decrement disable counter ld [hl], a - and $f + and $f ; did disable counter hit 0? jr nz, .checkIfConfused ld [hl], a - ld [wccef], a + ld [wEnemyDisabledMoveNumber], a ld hl, DisabledNoMoreText call PrintText .checkIfConfused - ld a, [W_ENEMYBATTSTATUS1] + ld a, [wEnemyBattleStatus1] add a ; check if enemy mon is confused jp nc, .checkIfTriedToUseDisabledMove - ld hl, W_ENEMYCONFUSEDCOUNTER + ld hl, wEnemyConfusedCounter dec [hl] jr nz, .isConfused - ld hl, W_ENEMYBATTSTATUS1 - res Confused, [hl] + ld hl, wEnemyBattleStatus1 + res Confused, [hl] ; if confused counter hit 0, reset confusion status ld hl, ConfusedNoMoreText call PrintText jp .checkIfTriedToUseDisabledMove @@ -5953,9 +5978,9 @@ CheckEnemyStatusConditions: ; 3e88f (f:688f) call BattleRandom cp $80 jr c, .checkIfTriedToUseDisabledMove - ld hl, W_ENEMYBATTSTATUS1 + ld hl, wEnemyBattleStatus1 ld a, [hl] - and 1 << Confused + and 1 << Confused ; if mon hurts itself, clear every other status from wEnemyBattleStatus1 ld [hl], a ld hl, HurtItselfText call PrintText @@ -5968,7 +5993,7 @@ CheckEnemyStatusConditions: ; 3e88f (f:688f) ld [hli], a ld a, [wEnemyMonDefense + 1] ld [hl], a - ld hl, W_ENEMYMOVEEFFECT + ld hl, wEnemyMoveEffect push hl ld a, [hl] push af @@ -5999,31 +6024,32 @@ CheckEnemyStatusConditions: ; 3e88f (f:688f) call ApplyDamageToEnemyPokemon jr .monHurtItselfOrFullyParalysed .checkIfTriedToUseDisabledMove - ld a, [wccef] +; prevents a disabled move that was selected before being disabled from being used + ld a, [wEnemyDisabledMoveNumber] and a jr z, .checkIfParalysed ld hl, wEnemySelectedMove cp [hl] jr nz, .checkIfParalysed call PrintMoveIsDisabledText - ld hl, ExecuteEnemyMoveDone + ld hl, ExecuteEnemyMoveDone ; if a disabled move was somehow selected, player can't move this turn jp .enemyReturnToHL .checkIfParalysed ld hl, wEnemyMonStatus bit PAR, [hl] jr z, .checkIfUsingBide call BattleRandom - cp $3f + cp $3f ; 25% to be fully paralysed jr nc, .checkIfUsingBide ld hl, FullyParalyzedText call PrintText .monHurtItselfOrFullyParalysed - ld hl, W_ENEMYBATTSTATUS1 + ld hl, wEnemyBattleStatus1 ld a, [hl] - ; clear bide, thrashing about, charging up, and multi-turn moves such as warp - and (1 << AttackingMultipleTimes) | (1 << Flinched) | (1 << Invulnerable) | (1 << Confused) + ; clear bide, thrashing about, charging up, and multi-turn moves such as warp + and $ff ^ ((1 << StoringEnergy) | (1 << ThrashingAbout) | (1 << ChargingUp) | (1 << UsingTrappingMove)) ld [hl], a - ld a, [W_ENEMYMOVEEFFECT] + ld a, [wEnemyMoveEffect] cp FLY_EFFECT jr z, .flyOrChargeEffect cp CHARGE_EFFECT @@ -6036,78 +6062,78 @@ CheckEnemyStatusConditions: ; 3e88f (f:688f) call PlayMoveAnimation .notFlyOrChargeEffect ld hl, ExecuteEnemyMoveDone - jp .enemyReturnToHL + jp .enemyReturnToHL ; if using a two-turn move, enemy needs to recharge the first turn .checkIfUsingBide - ld hl, W_ENEMYBATTSTATUS1 + ld hl, wEnemyBattleStatus1 bit StoringEnergy, [hl] ; is mon using bide? jr z, .checkIfThrashingAbout xor a - ld [W_ENEMYMOVENUM], a - ld hl, W_DAMAGE + ld [wEnemyMoveNum], a + ld hl, wDamage ld a, [hli] ld b, a ld c, [hl] ld hl, wEnemyBideAccumulatedDamage + 1 ld a, [hl] - add c + add c ; accumulate damage taken ld [hld], a ld a, [hl] adc b ld [hl], a ld hl, wEnemyNumAttacksLeft - dec [hl] + dec [hl] ; did Bide counter hit 0? jr z, .unleashEnergy ld hl, ExecuteEnemyMoveDone - jp .enemyReturnToHL + jp .enemyReturnToHL ; unless mon unleashes energy, can't move this turn .unleashEnergy - ld hl, W_ENEMYBATTSTATUS1 + ld hl, wEnemyBattleStatus1 res StoringEnergy, [hl] ; not using bide any more ld hl, UnleashedEnergyText call PrintText ld a, $1 - ld [W_ENEMYMOVEPOWER], a + ld [wEnemyMovePower], a ld hl, wEnemyBideAccumulatedDamage + 1 ld a, [hld] add a ld b, a - ld [W_DAMAGE + 1], a + ld [wDamage + 1], a ld a, [hl] - rl a - ld [W_DAMAGE], a + rl a ; double the damage + ld [wDamage], a or b - jr nz, .next2 + jr nz, .next ld a, $1 - ld [W_MOVEMISSED], a -.next2 + ld [wMoveMissed], a +.next xor a ld [hli], a ld [hl], a ld a, BIDE - ld [W_ENEMYMOVENUM], a + ld [wEnemyMoveNum], a call SwapPlayerAndEnemyLevels - ld hl, handleIfEnemyMoveMissed + ld hl, handleIfEnemyMoveMissed ; skip damage calculation, DecrementPP and MoveHitTest jp .enemyReturnToHL .checkIfThrashingAbout bit ThrashingAbout, [hl] ; is mon using thrash or petal dance? jr z, .checkIfUsingMultiturnMove ld a, THRASH - ld [W_ENEMYMOVENUM], a + ld [wEnemyMoveNum], a ld hl, ThrashingAboutText call PrintText ld hl, wEnemyNumAttacksLeft - dec [hl] - ld hl, EnemyCalcMoveDamage + dec [hl] ; did Thrashing About counter hit 0? + ld hl, EnemyCalcMoveDamage ; skip DecrementPP jp nz, .enemyReturnToHL push hl - ld hl, W_ENEMYBATTSTATUS1 + ld hl, wEnemyBattleStatus1 res ThrashingAbout, [hl] ; mon is no longer using thrash or petal dance set Confused, [hl] ; mon is now confused call BattleRandom and $3 inc a - inc a - ld [W_ENEMYCONFUSEDCOUNTER], a - pop hl + inc a ; confused for 2-5 turns + ld [wEnemyConfusedCounter], a + pop hl ; skip DecrementPP jp .enemyReturnToHL .checkIfUsingMultiturnMove bit UsingTrappingMove, [hl] ; is mon using multi-turn move? @@ -6115,20 +6141,21 @@ CheckEnemyStatusConditions: ; 3e88f (f:688f) ld hl, AttackContinuesText call PrintText ld hl, wEnemyNumAttacksLeft - dec [hl] - ld hl, GetEnemyAnimationType + dec [hl] ; did multi-turn move end? + ld hl, GetEnemyAnimationType ; if it didn't, skip damage calculation (deal damage equal to last hit), + ; DecrementPP and MoveHitTest jp nz, .enemyReturnToHL jp .enemyReturnToHL .checkIfUsingRage - ld a, [W_ENEMYBATTSTATUS2] + ld a, [wEnemyBattleStatus2] bit UsingRage, a ; is mon using rage? - jp z, .checkEnemyStatusConditionsDone + jp z, .checkEnemyStatusConditionsDone ; if we made it this far, mon can move normally this turn ld a, RAGE ld [wd11e], a call GetMoveName call CopyStringToCF4B xor a - ld [W_ENEMYMOVEEFFECT], a + ld [wEnemyMoveEffect], a ld hl, EnemyCanExecuteMove jp .enemyReturnToHL .enemyReturnToHL @@ -6139,25 +6166,25 @@ CheckEnemyStatusConditions: ; 3e88f (f:688f) and a ; clear Z flag ret -GetCurrentMove: ; 3eabe (f:6abe) +GetCurrentMove: ld a, [H_WHOSETURN] and a jp z, .player - ld de, W_ENEMYMOVENUM + ld de, wEnemyMoveNum ld a, [wEnemySelectedMove] jr .selected .player - ld de, W_PLAYERMOVENUM - ld a, [W_FLAGS_D733] - bit 0, a - ld a, [wccd9] + ld de, wPlayerMoveNum + ld a, [wFlags_D733] + bit BIT_TEST_BATTLE, a + ld a, [wTestBattlePlayerSelectedMove] jr nz, .selected ld a, [wPlayerSelectedMove] .selected ld [wd0b5], a dec a ld hl, Moves - ld bc, $6 + ld bc, MoveEnd - Moves call AddNTimes ld a, BANK(Moves) call FarCopyData @@ -6170,7 +6197,7 @@ GetCurrentMove: ; 3eabe (f:6abe) ld de, wcd6d jp CopyStringToCF4B -LoadEnemyMonData: ; 3eb01 (f:6b01) +LoadEnemyMonData: ld a, [wLinkState] cp LINK_STATE_BATTLING jp z, LoadEnemyMonFromParty @@ -6178,13 +6205,13 @@ LoadEnemyMonData: ; 3eb01 (f:6b01) ld [wEnemyMonSpecies], a ld [wd0b5], a call GetMonHeader - ld a, [W_ENEMYBATTSTATUS3] + ld a, [wEnemyBattleStatus3] bit Transformed, a ; is enemy mon transformed? - ld hl, wcceb ; copied DVs from when it used Transform + ld hl, wTransformedEnemyMonOriginalDVs ; original DVs before transforming ld a, [hli] ld b, [hl] jr nz, .storeDVs - ld a, [W_ISINBATTLE] + ld a, [wIsInBattle] cp $2 ; is it a trainer battle? ; fixed DVs for trainer mon ld a, $98 @@ -6199,7 +6226,7 @@ LoadEnemyMonData: ; 3eb01 (f:6b01) ld [hli], a ld [hl], b ld de, wEnemyMonLevel - ld a, [W_CURENEMYLVL] + ld a, [wCurEnemyLVL] ld [de], a inc de ld b, $0 @@ -6207,10 +6234,10 @@ LoadEnemyMonData: ; 3eb01 (f:6b01) push hl call CalcStats pop hl - ld a, [W_ISINBATTLE] + ld a, [wIsInBattle] cp $2 ; is it a trainer battle? jr z, .copyHPAndStatusFromPartyData - ld a, [W_ENEMYBATTSTATUS3] + ld a, [wEnemyBattleStatus3] bit Transformed, a ; is enemy mon transformed? jr nz, .copyTypes ; if transformed, jump ; if it's a wild mon and not transformed, init the current HP to max HP and the status to 0 @@ -6239,7 +6266,7 @@ LoadEnemyMonData: ; 3eb01 (f:6b01) ld [wEnemyMonStatus], a jr .copyTypes .copyTypes - ld hl, W_MONHTYPES + ld hl, wMonHTypes ld de, wEnemyMonType ld a, [hli] ; copy type 1 ld [de], a @@ -6250,7 +6277,7 @@ LoadEnemyMonData: ; 3eb01 (f:6b01) ld a, [hli] ; copy catch rate ld [de], a inc de - ld a, [W_ISINBATTLE] + ld a, [wIsInBattle] cp $2 ; is it a trainer battle? jr nz, .copyStandardMoves ; if it's a trainer battle, copy moves from enemy party data @@ -6263,7 +6290,7 @@ LoadEnemyMonData: ; 3eb01 (f:6b01) jr .loadMovePPs .copyStandardMoves ; for a wild mon, first copy default moves from the mon header - ld hl, W_MONHMOVES + ld hl, wMonHMoves ld a, [hli] ld [de], a inc de @@ -6279,22 +6306,22 @@ LoadEnemyMonData: ; 3eb01 (f:6b01) dec de dec de xor a - ld [wHPBarMaxHP], a + ld [wLearningMovesFromDayCare], a predef WriteMonMoves ; get moves based on current level .loadMovePPs ld hl, wEnemyMonMoves - ld de, wEnemyMonSpecial + 1 + ld de, wEnemyMonPP - 1 predef LoadMovePPs - ld hl, W_MONHBASESTATS + ld hl, wMonHBaseStats ld de, wEnemyMonBaseStats - ld b, $5 + ld b, NUM_STATS .copyBaseStatsLoop ld a, [hli] ld [de], a inc de dec b jr nz, .copyBaseStatsLoop - ld hl, W_MONHCATCHRATE + ld hl, wMonHCatchRate ld a, [hli] ld [de], a inc de @@ -6305,7 +6332,7 @@ LoadEnemyMonData: ; 3eb01 (f:6b01) call GetMonName ld hl, wcd6d ld de, wEnemyMonNick - ld bc, $b + ld bc, NAME_LENGTH call CopyData ld a, [wEnemyMonSpecies2] ld [wd11e], a @@ -6313,15 +6340,15 @@ LoadEnemyMonData: ; 3eb01 (f:6b01) ld a, [wd11e] dec a ld c, a - ld b, $1 + ld b, FLAG_SET ld hl, wPokedexSeen predef FlagActionPredef ; mark this mon as seen in the pokedex ld hl, wEnemyMonLevel ld de, wEnemyMonUnmodifiedLevel - ld bc, $b + ld bc, 1 + NUM_STATS * 2 call CopyData ld a, $7 ; default stat mod - ld b, $8 ; number of stat mods + ld b, NUM_STAT_MODS ; number of stat mods ld hl, wEnemyMonStatMods .statModLoop ld [hli], a @@ -6330,7 +6357,7 @@ LoadEnemyMonData: ; 3eb01 (f:6b01) ret ; calls BattleTransition to show the battle transition animation and initializes some battle variables -DoBattleTransitionAndInitBattleVariables: ; 3ec32 (f:6c32) +DoBattleTransitionAndInitBattleVariables: ld a, [wLinkState] cp LINK_STATE_BATTLING jr nz, .next @@ -6362,11 +6389,11 @@ DoBattleTransitionAndInitBattleVariables: ; 3ec32 (f:6c32) ld [hli], a ld [hli], a ld [hl], a - ld [W_PLAYERDISABLEDMOVE], a + ld [wPlayerDisabledMove], a ret ; swaps the level values of the BattleMon and EnemyMon structs -SwapPlayerAndEnemyLevels: ; 3ec81 (f:6c81) +SwapPlayerAndEnemyLevels: push bc ld a, [wBattleMonLevel] ld b, a @@ -6380,8 +6407,8 @@ SwapPlayerAndEnemyLevels: ; 3ec81 (f:6c81) ; loads either red back pic or old man back pic ; also writes OAM data and loads tile patterns for the Red or Old Man back sprite's head ; (for use when scrolling the player sprite and enemy's silhouettes on screen) -LoadPlayerBackPic: ; 3ec92 (f:6c92) - ld a, [W_BATTLETYPE] +LoadPlayerBackPic: + ld a, [wBattleType] dec a ; is it the old man tutorial? ld de, RedPicBack jr nz, .next @@ -6392,7 +6419,7 @@ LoadPlayerBackPic: ; 3ec92 (f:6c92) predef ScaleSpriteByTwo ld hl, wOAMBuffer xor a - ld [$FF8B], a ; initial tile number + ld [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 @@ -6406,16 +6433,16 @@ LoadPlayerBackPic: ; 3ec92 (f:6c92) add d ; increase Y by height of tile ld d, a inc hl - ld a, [$FF8B] + ld a, [hOAMTile] ld [hli], a ; OAM tile number inc a ; increment tile number - ld [$FF8B], a + ld [hOAMTile], a inc hl dec c jr nz, .innerLoop - ld a, [$FF8B] + ld a, [hOAMTile] add $4 ; increase tile number by 4 - ld [$FF8B], a + ld [hOAMTile], a ld a, $8 ; width of tile add e ; increase X by width of tile ld e, a @@ -6428,7 +6455,7 @@ LoadPlayerBackPic: ; 3ec92 (f:6c92) xor a ld [$4000], a ld hl, vSprites - ld de, S_SPRITEBUFFER1 + ld de, sSpriteBuffer1 ld a, [H_LOADEDROMBANK] ld b, a ld c, 7 * 7 @@ -6436,35 +6463,31 @@ LoadPlayerBackPic: ; 3ec92 (f:6c92) xor a ld [$0], a ld a, $31 - ld [$ffe1], a - hlCoord 1, 5 - predef_jump Func_3f0c6 + ld [hStartTileID], a + coord hl, 1, 5 + predef_jump CopyUncompressedPicToTilemap ; does nothing since no stats are ever selected (barring glitches) -DoubleOrHalveSelectedStats: ; 3ed02 (f:6d02) +DoubleOrHalveSelectedStats: callab DoubleSelectedStats - ld hl, HalveSelectedStats - ld b, BANK(HalveSelectedStats) - jp Bankswitch + jpab HalveSelectedStats -ScrollTrainerPicAfterBattle: ; 3ed12 (f:6d12) - ld hl, _ScrollTrainerPicAfterBattle - ld b, BANK(_ScrollTrainerPicAfterBattle) - jp Bankswitch +ScrollTrainerPicAfterBattle: + jpab _ScrollTrainerPicAfterBattle -ApplyBurnAndParalysisPenaltiesToPlayer: ; 3ed1a (f:6d1a) +ApplyBurnAndParalysisPenaltiesToPlayer: ld a, $1 jr ApplyBurnAndParalysisPenalties -ApplyBurnAndParalysisPenaltiesToEnemy: ; 3ed1e (f:6d1e) +ApplyBurnAndParalysisPenaltiesToEnemy: xor a -ApplyBurnAndParalysisPenalties: ; 3ed1f (f:6d1f) +ApplyBurnAndParalysisPenalties: ld [H_WHOSETURN], a call QuarterSpeedDueToParalysis jp HalveAttackDueToBurn -QuarterSpeedDueToParalysis: ; 3ed27 (f:6d27) +QuarterSpeedDueToParalysis: ld a, [H_WHOSETURN] and a jr z, .playerTurn @@ -6507,7 +6530,7 @@ QuarterSpeedDueToParalysis: ; 3ed27 (f:6d27) ld [hl], b ret -HalveAttackDueToBurn: ; 3ed64 (f:6d64) +HalveAttackDueToBurn: ld a, [H_WHOSETURN] and a jr z, .playerTurn @@ -6546,26 +6569,26 @@ HalveAttackDueToBurn: ; 3ed64 (f:6d64) ld [hl], b ret -CalculateModifiedStats: ; 3ed99 (f:6d99) +CalculateModifiedStats: ld c, 0 .loop call CalculateModifiedStat inc c ld a, c - cp 4 + cp NUM_STATS - 1 jr nz, .loop ret ; calculate modified stat for stat c (0 = attack, 1 = defense, 2 = speed, 3 = special) -CalculateModifiedStat: ; 3eda5 (f:6da5) +CalculateModifiedStat: push bc push bc - ld a, [wd11e] + ld a, [wCalculateWhoseStats] and a ld a, c ld hl, wBattleMonAttack ld de, wPlayerMonUnmodifiedAttack - ld bc, wPlayerMonAttackMod + ld bc, wPlayerMonStatMods jr z, .next ld hl, wEnemyMonAttack ld de, wEnemyMonUnmodifiedAttack @@ -6635,11 +6658,11 @@ CalculateModifiedStat: ; 3eda5 (f:6da5) pop bc ret -ApplyBadgeStatBoosts: ; 3ee19 (f:6e19) +ApplyBadgeStatBoosts: ld a, [wLinkState] cp LINK_STATE_BATTLING ret z ; return if link battle - ld a, [W_OBTAINEDBADGES] + ld a, [wObtainedBadges] ld b, a ld hl, wBattleMonAttack ld c, $4 @@ -6688,35 +6711,35 @@ ApplyBadgeStatBoosts: ; 3ee19 (f:6e19) ld [hld], a ret -LoadHudAndHpBarAndStatusTilePatterns: ; 3ee58 (f:6e58) +LoadHudAndHpBarAndStatusTilePatterns: call LoadHpBarAndStatusTilePatterns -LoadHudTilePatterns: ; 3ee5b (f:6e5b) +LoadHudTilePatterns: ld a, [rLCDC] add a ; is LCD disabled? jr c, .lcdEnabled .lcdDisabled ld hl, BattleHudTiles1 ld de, vChars2 + $6d0 - ld bc, $18 + ld bc, BattleHudTiles1End - BattleHudTiles1 ld a, BANK(BattleHudTiles1) call FarCopyDataDouble ld hl, BattleHudTiles2 ld de, vChars2 + $730 - ld bc, $30 + ld bc, BattleHudTiles3End - BattleHudTiles2 ld a, BANK(BattleHudTiles2) jp FarCopyDataDouble .lcdEnabled ld de, BattleHudTiles1 ld hl, vChars2 + $6d0 - ld bc, (BANK(BattleHudTiles1) << 8) + $03 + lb bc, BANK(BattleHudTiles1), (BattleHudTiles1End - BattleHudTiles1) / $8 call CopyVideoDataDouble ld de, BattleHudTiles2 ld hl, vChars2 + $730 - ld bc, (BANK(BattleHudTiles2) << 8) + $06 + lb bc, BANK(BattleHudTiles2), (BattleHudTiles3End - BattleHudTiles2) / $8 jp CopyVideoDataDouble -PrintEmptyString: ; 3ee94 (f:6e94) +PrintEmptyString: ld hl, .emptyString jp PrintText .emptyString @@ -6749,8 +6772,8 @@ BattleRandom: push hl push bc push af - -; point to seed 0 so we pick the first number the next time + +; point to seed 0 so we pick the first number the next time xor a ld [wLinkBattleRandomNumberListIndex], a @@ -6759,11 +6782,11 @@ BattleRandom: .loop ld a, [hl] ld c, a -; multiply by 5 +; multiply by 5 add a add a add c -; add 1 +; add 1 inc a ld [hli], a dec b @@ -6775,22 +6798,22 @@ BattleRandom: ret -HandleExplodingAnimation: ; 3eed3 (f:6ed3) +HandleExplodingAnimation: ld a, [H_WHOSETURN] and a - ld hl, wEnemyMonType1 ; wcfea - ld de, W_ENEMYBATTSTATUS1 - ld a, [W_PLAYERMOVENUM] - jr z, .asm_3eeea - ld hl, wBattleMonType1 ; wd019 - ld de, W_ENEMYBATTSTATUS1 - ld a, [W_ENEMYMOVENUM] -.asm_3eeea + ld hl, wEnemyMonType1 + ld de, wEnemyBattleStatus1 + ld a, [wPlayerMoveNum] + jr z, .player + ld hl, wBattleMonType1 + ld de, wEnemyBattleStatus1 + ld a, [wEnemyMoveNum] +.player cp SELFDESTRUCT - jr z, .asm_3eef1 + jr z, .isExplodingMove cp EXPLOSION ret nz -.asm_3eef1 +.isExplodingMove ld a, [de] bit Invulnerable, a ; fly/dig ret nz @@ -6800,28 +6823,29 @@ HandleExplodingAnimation: ; 3eed3 (f:6ed3) ld a, [hl] cp GHOST ret z - ld a, [W_MOVEMISSED] + ld a, [wMoveMissed] and a ret nz ld a, 5 ld [wAnimationType], a -PlayMoveAnimation: ; 3ef07 (f:6f07) - ld [W_ANIMATIONID],a +PlayMoveAnimation: + ld [wAnimationID],a call Delay3 predef_jump MoveAnimation -InitBattle: ; 3ef12 (f:6f12) - ld a, [W_CUROPPONENT] +InitBattle: + ld a, [wCurOpponent] and a - jr z, asm_3ef23 + jr z, DetermineWildOpponent -InitOpponent: ; 3ef18 (f:6f18) - ld a, [W_CUROPPONENT] +InitOpponent: + ld a, [wCurOpponent] ld [wcf91], a ld [wEnemyMonSpecies2], a - jr asm_3ef3d -asm_3ef23: ; 3ef23 (f:6f23) + jr InitBattleCommon + +DetermineWildOpponent: ld a, [wd732] bit 1, a jr z, .asm_3ef2f @@ -6834,47 +6858,47 @@ asm_3ef23: ; 3ef23 (f:6f23) ret nz callab TryDoWildEncounter ret nz -asm_3ef3d: ; 3ef3d (f:6f3d) +InitBattleCommon: ld a, [wMapPalOffset] push af - ld hl, wd358 + ld hl, wLetterPrintingDelayFlags ld a, [hl] push af res 1, [hl] callab InitBattleVariables ld a, [wEnemyMonSpecies2] - sub $c8 + sub 200 jp c, InitWildBattle - ld [W_TRAINERCLASS], a + ld [wTrainerClass], a call GetTrainerInformation callab ReadTrainer call DoBattleTransitionAndInitBattleVariables call _LoadTrainerPic xor a ld [wEnemyMonSpecies2], a - ld [$ffe1], a + ld [hStartTileID], a dec a ld [wAICount], a - hlCoord 12, 0 - predef Func_3f0c6 + coord hl, 12, 0 + predef CopyUncompressedPicToTilemap ld a, $ff ld [wEnemyMonPartyPos], a ld a, $2 - ld [W_ISINBATTLE], a - jp InitBattle_Common + ld [wIsInBattle], a + jp _InitBattleCommon -InitWildBattle: ; 3ef8b (f:6f8b) +InitWildBattle: ld a, $1 - ld [W_ISINBATTLE], a + ld [wIsInBattle], a call LoadEnemyMonData call DoBattleTransitionAndInitBattleVariables - ld a, [W_CUROPPONENT] + ld a, [wCurOpponent] cp MAROWAK jr z, .isGhost call IsGhostBattle jr nz, .isNoGhost .isGhost - ld hl, W_MONHSPRITEDIM + ld hl, wMonHSpriteDim ld a, $66 ld [hli], a ; write sprite dimensions ld bc, GhostPic @@ -6907,15 +6931,15 @@ InitWildBattle: ; 3ef8b (f:6f8b) call LoadMonFrontSprite ; load mon sprite .spriteLoaded xor a - ld [W_TRAINERCLASS], a - ld [$ffe1], a - hlCoord 12, 0 - predef Func_3f0c6 + ld [wTrainerClass], a + ld [hStartTileID], a + coord hl, 12, 0 + predef CopyUncompressedPicToTilemap ; common code that executes after init battle code specific to trainer or wild battles -InitBattle_Common: ; 3efeb (f:6feb) - ld b, $0 - call GoPAL_SET +_InitBattleCommon: + ld b, SET_PAL_BATTLE_BLACK + call RunPaletteCommand call SlidePlayerAndEnemySilhouettesOnScreen xor a ld [H_AUTOBGTRANSFERENABLED], a @@ -6924,41 +6948,41 @@ InitBattle_Common: ; 3efeb (f:6feb) call SaveScreenTilesToBuffer1 call ClearScreen ld a, $98 - ld [$ffbd], a + ld [H_AUTOBGTRANSFERDEST + 1], a ld a, $1 ld [H_AUTOBGTRANSFERENABLED], a call Delay3 ld a, $9c - ld [$ffbd], a + ld [H_AUTOBGTRANSFERDEST + 1], a call LoadScreenTilesFromBuffer1 - hlCoord 9, 7 - ld bc, $50a + coord hl, 9, 7 + lb bc, 5, 10 call ClearScreenArea - hlCoord 1, 0 - ld bc, $40a + coord hl, 1, 0 + lb bc, 4, 10 call ClearScreenArea call ClearSprites - ld a, [W_ISINBATTLE] + ld a, [wIsInBattle] dec a ; is it a wild battle? call z, DrawEnemyHUDAndHPBar ; draw enemy HUD and HP bar if it's a wild battle call StartBattle callab EndOfBattle pop af - ld [wd358], a + ld [wLetterPrintingDelayFlags], a pop af ld [wMapPalOffset], a - ld a, [wd0d4] + ld a, [wSavedTilesetType] ld [hTilesetType], a scf ret .emptyString db "@" -_LoadTrainerPic: ; 3f04b (f:704b) +_LoadTrainerPic: ; wd033-wd034 contain pointer to pic - ld a, [wd033] + ld a, [wTrainerPicPointer] ld e, a - ld a, [wd034] + ld a, [wTrainerPicPointer + 1] ld d, a ; de contains pointer to trainer pic ld a, [wLinkState] and a @@ -6973,115 +6997,116 @@ _LoadTrainerPic: ; 3f04b (f:704b) jp LoadUncompressedSpriteData ; unreferenced -Func_3f069: ; 3f069 (f:7069) +ResetCryModifiers: xor a - ld [wc0f1], a - ld [wc0f2], a + ld [wFrequencyModifier], a + ld [wTempoModifier], a jp PlaySound -Func_3f073: ; 3f073 (f:7073) +; animates the mon "growing" out of the pokeball +AnimateSendingOutMon: ld a, [wPredefRegisters] ld h, a ld a, [wPredefRegisters + 1] ld l, a - ld a, [$ffe1] - ld [H_DOWNARROWBLINKCNT1], a + ld a, [hStartTileID] + ld [hBaseTileID], a ld b, $4c - ld a, [W_ISINBATTLE] + ld a, [wIsInBattle] and a - jr z, .asm_3f0bc + jr z, .notInBattle add b ld [hl], a call Delay3 - ld bc, -41 + ld bc, -(SCREEN_WIDTH * 2 + 1) add hl, bc - ld a, $1 - ld [wcd6c], a - ld bc, $303 - predef Func_79aba - ld c, $4 + ld a, 1 + ld [wDownscaledMonSize], a + lb bc, 3, 3 + predef CopyDownscaledMonTiles + ld c, 4 call DelayFrames - ld bc, -41 + ld bc, -(SCREEN_WIDTH * 2 + 1) add hl, bc xor a - ld [wcd6c], a - ld bc, $505 - predef Func_79aba - ld c, $5 + ld [wDownscaledMonSize], a + lb bc, 5, 5 + predef CopyDownscaledMonTiles + ld c, 5 call DelayFrames - ld bc, -41 - jr .asm_3f0bf -.asm_3f0bc - ld bc, -123 -.asm_3f0bf + ld bc, -(SCREEN_WIDTH * 2 + 1) + jr .next +.notInBattle + ld bc, -(SCREEN_WIDTH * 6 + 3) +.next add hl, bc - ld a, [H_DOWNARROWBLINKCNT1] + ld a, [hBaseTileID] add $31 - jr asm_3f0d0 + jr CopyUncompressedPicToHL -Func_3f0c6: ; 3f0c6 (f:70c6) +CopyUncompressedPicToTilemap: ld a, [wPredefRegisters] ld h, a ld a, [wPredefRegisters + 1] ld l, a - ld a, [$ffe1] -asm_3f0d0: ; 3f0d0 (f:70d0) - ld bc, $707 - ld de, $14 + ld a, [hStartTileID] +CopyUncompressedPicToHL: + lb bc, 7, 7 + ld de, SCREEN_WIDTH push af - ld a, [W_SPRITEFLIPPED] + ld a, [wSpriteFlipped] and a - jr nz, .asm_3f0ed + jr nz, .flipped pop af -.asm_3f0de +.loop push bc push hl -.asm_3f0e0 +.innerLoop ld [hl], a add hl, de inc a dec c - jr nz, .asm_3f0e0 + jr nz, .innerLoop pop hl inc hl pop bc dec b - jr nz, .asm_3f0de + jr nz, .loop ret - -.asm_3f0ed + +.flipped push bc - ld b, $0 + ld b, 0 dec c add hl, bc pop bc pop af -.asm_3f0f4 +.flippedLoop push bc push hl -.asm_3f0f6 +.flippedInnerLoop ld [hl], a add hl, de inc a dec c - jr nz, .asm_3f0f6 + jr nz, .flippedInnerLoop pop hl dec hl pop bc dec b - jr nz, .asm_3f0f4 + jr nz, .flippedLoop ret -LoadMonBackPic: ; 3f103 (f:7103) +LoadMonBackPic: ; Assumes the monster's attributes have ; been loaded with GetMonHeader. ld a, [wBattleMonSpecies2] ld [wcf91], a - hlCoord 1, 5 - ld b, $7 - ld c, $8 + coord hl, 1, 5 + ld b, 7 + ld c, 8 call ClearScreenArea - ld hl, W_MONHBACKSPRITE - W_MONHEADER + ld hl, wMonHBackSprite - wMonHeader call UncompressMonSprite predef ScaleSpriteByTwo ld de, vBackPic @@ -7093,17 +7118,17 @@ LoadMonBackPic: ; 3f103 (f:7103) ld b, a jp CopyVideoData -JumpMoveEffect: ; 3f132 (f:7132) +JumpMoveEffect: call _JumpMoveEffect ld b, $1 ret -_JumpMoveEffect: ; 3f138 (f:7138) +_JumpMoveEffect: ld a, [H_WHOSETURN] and a - ld a, [W_PLAYERMOVEEFFECT] + ld a, [wPlayerMoveEffect] jr z, .next1 - ld a, [W_ENEMYMOVEEFFECT] + ld a, [wEnemyMoveEffect] .next1 dec a ; subtract 1, there is no special effect for 00 add a ; x2, 16bit pointers @@ -7116,7 +7141,7 @@ _JumpMoveEffect: ; 3f138 (f:7138) ld l, a jp [hl] ; jump to special effect handler -MoveEffectPointerTable: ; 3f150 (f:7150) +MoveEffectPointerTable: dw SleepEffect ; unused effect dw PoisonEffect ; POISON_SIDE_EFFECT1 dw DrainHPEffect ; DRAIN_HP_EFFECT @@ -7204,14 +7229,14 @@ MoveEffectPointerTable: ; 3f150 (f:7150) dw SplashEffect ; SPLASH_EFFECT dw DisableEffect ; DISABLE_EFFECT -SleepEffect: ; 3f1fc (f:71fc) +SleepEffect: ld de, wEnemyMonStatus - ld bc, W_ENEMYBATTSTATUS2 + ld bc, wEnemyBattleStatus2 ld a, [H_WHOSETURN] and a jp z, .sleepEffect ld de, wBattleMonStatus - ld bc, W_PLAYERBATTSTATUS2 + ld bc, wPlayerBattleStatus2 .sleepEffect ld a, [bc] @@ -7233,7 +7258,7 @@ SleepEffect: ; 3f1fc (f:71fc) push de call MoveHitTest ; apply accuracy tests pop de - ld a, [W_MOVEMISSED] + ld a, [wMoveMissed] and a jr nz, .didntAffect .setSleepCounter @@ -7248,22 +7273,22 @@ SleepEffect: ; 3f1fc (f:71fc) .didntAffect jp PrintDidntAffectText -FellAsleepText: ; 3f245 (f:7245) +FellAsleepText: TX_FAR _FellAsleepText db "@" -AlreadyAsleepText: ; 3f24a (f:724a) +AlreadyAsleepText: TX_FAR _AlreadyAsleepText db "@" -PoisonEffect: ; 3f24f (f:724f) +PoisonEffect: ld hl, wEnemyMonStatus - ld de, W_PLAYERMOVEEFFECT + ld de, wPlayerMoveEffect ld a, [H_WHOSETURN] and a jr z, .poisonEffect ld hl, wBattleMonStatus - ld de, W_ENEMYMOVEEFFECT + ld de, wEnemyMoveEffect .poisonEffect call CheckTargetSubstitute jr nz, .noEffect ; can't posion a substitute target @@ -7289,7 +7314,7 @@ PoisonEffect: ; 3f24f (f:724f) call MoveHitTest ; apply accuracy tests pop de pop hl - ld a, [W_MOVEMISSED] + ld a, [wMoveMissed] and a jr nz, .didntAffect jr .inflictPoison @@ -7305,13 +7330,13 @@ PoisonEffect: ; 3f24f (f:724f) ld a, [H_WHOSETURN] and a ld b, ANIM_C7 - ld hl, W_PLAYERBATTSTATUS3 + ld hl, wPlayerBattleStatus3 ld a, [de] - ld de, W_PLAYERTOXICCOUNTER + ld de, wPlayerToxicCounter jr nz, .ok ld b, ANIM_A9 - ld hl, W_ENEMYBATTSTATUS3 - ld de, W_ENEMYTOXICCOUNTER + ld hl, wEnemyBattleStatus3 + ld de, wEnemyToxicCounter .ok cp TOXIC jr nz, .normalPoison ; done if move is not Toxic @@ -7319,18 +7344,18 @@ PoisonEffect: ; 3f24f (f:724f) xor a ld [de], a ld hl, BadlyPoisonedText - jr .asm_3f2c0 + jr .continue .normalPoison ld hl, PoisonedText -.asm_3f2c0 +.continue pop de ld a, [de] cp POISON_EFFECT - jr z, .asm_3f2cd + jr z, .regularPoisonEffect ld a, b call PlayBattleAnimation2 jp PrintText -.asm_3f2cd +.regularPoisonEffect call PlayCurrentMoveAnimation2 jp PrintText .noEffect @@ -7338,31 +7363,29 @@ PoisonEffect: ; 3f24f (f:724f) cp POISON_EFFECT ret nz .didntAffect - ld c, $32 + ld c, 50 call DelayFrames jp PrintDidntAffectText -PoisonedText: ; 3f2df (f:72df) +PoisonedText: TX_FAR _PoisonedText db "@" -BadlyPoisonedText: ; 3f2e4 (f:72e4) +BadlyPoisonedText: TX_FAR _BadlyPoisonedText db "@" -DrainHPEffect: ; 3f2e9 (f:72e9) - ld hl, DrainHPEffect_ - ld b, BANK(DrainHPEffect_) - jp Bankswitch +DrainHPEffect: + jpab DrainHPEffect_ -ExplodeEffect: ; 3f2f1 (f:72f1) +ExplodeEffect: ld hl, wBattleMonHP - ld de, W_PLAYERBATTSTATUS2 + ld de, wPlayerBattleStatus2 ld a, [H_WHOSETURN] and a jr z, .faintUser ld hl, wEnemyMonHP - ld de, W_ENEMYBATTSTATUS2 + ld de, wEnemyBattleStatus2 .faintUser xor a ld [hli], a ; set the mon's HP to 0 @@ -7374,7 +7397,7 @@ ExplodeEffect: ; 3f2f1 (f:72f1) ld [de], a ret -FreezeBurnParalyzeEffect: ; 3f30c (f:730c) +FreezeBurnParalyzeEffect: xor a ld [wAnimationType], a call CheckTargetSubstitute ; test bit 4 of d063/d068 flags [target has substitute flag] @@ -7385,7 +7408,7 @@ FreezeBurnParalyzeEffect: ; 3f30c (f:730c) ld a, [wEnemyMonStatus] and a jp nz, CheckDefrost ; can't inflict status if opponent is already statused - ld a, [W_PLAYERMOVETYPE] + ld a, [wPlayerMoveType] ld b, a ld a, [wEnemyMonType1] cp b ; do target type 1 and move type match? @@ -7393,7 +7416,7 @@ FreezeBurnParalyzeEffect: ; 3f30c (f:730c) ld a, [wEnemyMonType2] cp b ; do target type 2 and move type match? ret z ; return if they match - ld a, [W_PLAYERMOVEEFFECT] + ld a, [wPlayerMoveEffect] 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.. @@ -7433,11 +7456,11 @@ FreezeBurnParalyzeEffect: ; 3f30c (f:730c) call PlayBattleAnimation ld hl, FrozenText jp PrintText -opponentAttacker: ; 3f382 (f:7382) +opponentAttacker: ld a, [wBattleMonStatus] ; mostly same as above with addresses swapped for opponent and a jp nz, CheckDefrost - ld a, [W_ENEMYMOVETYPE] + ld a, [wEnemyMoveType] ld b, a ld a, [wBattleMonType1] cp b @@ -7445,7 +7468,7 @@ opponentAttacker: ; 3f382 (f:7382) ld a, [wBattleMonType2] cp b ret z - ld a, [W_ENEMYMOVEEFFECT] + ld a, [wEnemyMoveEffect] cp a, PARALYZE_SIDE_EFFECT1 + 1 ld b, $1a jr c, .next1 @@ -7479,26 +7502,26 @@ opponentAttacker: ; 3f382 (f:7382) ld hl, FrozenText jp PrintText -BurnedText: ; 3f3d8 (f:73d8) +BurnedText: TX_FAR _BurnedText db "@" -FrozenText: ; 3f3dd (f:73dd) +FrozenText: TX_FAR _FrozenText db "@" -CheckDefrost: ; 3f3e2 (f:73e2) +CheckDefrost: ; any fire-type move that has a chance inflict burn (all but Fire Spin) will defrost a frozen target - and a, 1 << FRZ ; are they frozen? + and a, 1 << FRZ ; are they frozen? ret z ; return if so ld a, [H_WHOSETURN] and a jr nz, .opponent ;player [attacker] - ld a, [W_PLAYERMOVETYPE] + ld a, [wPlayerMoveType] sub a, 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 [wEnemyMonStatus], a ; set opponent status to 00 ["defrost" a frozen monster] ld hl, wEnemyMon1Status ld a, [wEnemyMonPartyPos] ld bc, wEnemyMon2 - wEnemyMon1 @@ -7508,7 +7531,7 @@ CheckDefrost: ; 3f3e2 (f:73e2) ld hl, FireDefrostedText jr .common .opponent - ld a, [W_ENEMYMOVETYPE] ; same as above with addresses swapped + ld a, [wEnemyMoveType] ; same as above with addresses swapped sub a, FIRE ret nz ld [wBattleMonStatus], a @@ -7522,18 +7545,18 @@ CheckDefrost: ; 3f3e2 (f:73e2) .common jp PrintText -FireDefrostedText: ; 3f423 (f:7423) +FireDefrostedText: TX_FAR _FireDefrostedText db "@" -StatModifierUpEffect: ; 3f428 (f:7428) +StatModifierUpEffect: ld hl, wPlayerMonStatMods - ld de, W_PLAYERMOVEEFFECT + ld de, wPlayerMoveEffect ld a, [H_WHOSETURN] and a jr z, .statModifierUpEffect ld hl, wEnemyMonStatMods - ld de, W_ENEMYMOVEEFFECT + ld de, wEnemyMoveEffect .statModifierUpEffect ld a, [de] sub ATTACK_UP1_EFFECT @@ -7600,17 +7623,17 @@ StatModifierUpEffect: ; 3f428 (f:7428) add hl, bc pop bc xor a - ld [H_MULTIPLICAND], 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 + ld [H_MULTIPLIER], a call Multiply ld a, [hl] - ld [H_DIVISOR], a + ld [H_DIVISOR], a ld b, $4 call Divide pop hl @@ -7625,36 +7648,38 @@ StatModifierUpEffect: ; 3f428 (f:7428) ld a, 999 % $100 ld [H_MULTIPLICAND + 2], a -UpdateStat: ; 3f4c3 (f:74c3) +UpdateStat: ld a, [H_PRODUCT + 2] ld [hli], a ld a, [H_PRODUCT + 3] ld [hl], a pop hl -UpdateStatDone: ; 3f4ca (f:74ca) +UpdateStatDone: ld b, c inc b - call Func_3f688 - ld hl, W_PLAYERBATTSTATUS2 - ld de, W_PLAYERMOVENUM - ld bc, wccf7 + call PrintStatText + ld hl, wPlayerBattleStatus2 + ld de, wPlayerMoveNum + ld bc, wPlayerMonMinimized ld a, [H_WHOSETURN] and a jr z, .asm_3f4e6 - ld hl, W_ENEMYBATTSTATUS2 - ld de, W_ENEMYMOVENUM - ld bc, wccf3 + ld hl, wEnemyBattleStatus2 + ld de, wEnemyMoveNum + ld bc, wEnemyMonMinimized .asm_3f4e6 ld a, [de] cp MINIMIZE jr nz, .asm_3f4f9 - bit HasSubstituteUp, [hl] ; substitute + ; if a substitute is up, slide off the substitute and show the mon pic before + ; playing the minimize animation + bit HasSubstituteUp, [hl] push af push bc - ld hl, Func_79747 - ld b, BANK(Func_79747) + ld hl, HideSubstituteShowMonAnim + ld b, BANK(HideSubstituteShowMonAnim) push de - call nz, Bankswitch ; play Minimize animation unless there's Substitute involved + call nz, Bankswitch pop de .asm_3f4f9 call PlayCurrentMoveAnimation @@ -7664,8 +7689,8 @@ UpdateStatDone: ; 3f4ca (f:74ca) pop bc ld a, $1 ld [bc], a - ld hl, Func_79771 - ld b, BANK(Func_79771) + ld hl, ReshowSubstituteAnim + ld b, BANK(ReshowSubstituteAnim) pop af call nz, Bankswitch .applyBadgeBoostsAndStatusPenalties @@ -7680,47 +7705,47 @@ UpdateStatDone: ; 3f4ca (f:74ca) 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: ; 3f520 (f:7520) +RestoreOriginalStatModifier: pop hl dec [hl] -PrintNothingHappenedText: ; 3f522 (f:7522) +PrintNothingHappenedText: ld hl, NothingHappenedText jp PrintText -MonsStatsRoseText: ; 3f528 (f:7528) +MonsStatsRoseText: TX_FAR _MonsStatsRoseText - db $08 ; asm + TX_ASM ld hl, GreatlyRoseText ld a, [H_WHOSETURN] and a - ld a, [W_PLAYERMOVEEFFECT] - jr z, .asm_3f53b - ld a, [W_ENEMYMOVEEFFECT] -.asm_3f53b + ld a, [wPlayerMoveEffect] + jr z, .playerTurn + ld a, [wEnemyMoveEffect] +.playerTurn cp ATTACK_DOWN1_EFFECT ret nc ld hl, RoseText ret -GreatlyRoseText: ; 3f542 (f:7542) - db $0a +GreatlyRoseText: + TX_DELAY TX_FAR _GreatlyRoseText - -RoseText: ; 3f547 (f:7547) +; fallthrough +RoseText: TX_FAR _RoseText db "@" -StatModifierDownEffect: ; 3f54c (f:754c) +StatModifierDownEffect: ld hl, wEnemyMonStatMods - ld de, W_PLAYERMOVEEFFECT - ld bc, W_ENEMYBATTSTATUS1 + ld de, wPlayerMoveEffect + ld bc, wEnemyBattleStatus1 ld a, [H_WHOSETURN] and a jr z, .statModifierDownEffect ld hl, wPlayerMonStatMods - ld de, W_ENEMYMOVEEFFECT - ld bc, W_PLAYERBATTSTATUS1 + ld de, wEnemyMoveEffect + ld bc, wPlayerBattleStatus1 ld a, [wLinkState] cp LINK_STATE_BATTLING jr z, .statModifierDownEffect @@ -7747,7 +7772,7 @@ StatModifierDownEffect: ; 3f54c (f:754c) pop bc pop de pop hl - ld a, [W_MOVEMISSED] + ld a, [wMoveMissed] and a jp nz, MoveMissed ld a, [bc] @@ -7795,16 +7820,16 @@ StatModifierDownEffect: ; 3f54c (f:754c) ld a, c add e ld e, a - jr nc, .asm_3f5e4 + jr nc, .noCarry inc d ; de = unmodified stat -.asm_3f5e4 +.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, Func_3f64d + jp z, CantLowerAnymore_Pop .recalculateStat ; recalculate affected stat ; paralysis and burn penalties, as well as badge boosts are ignored @@ -7818,17 +7843,17 @@ StatModifierDownEffect: ; 3f54c (f:754c) add hl, bc pop bc xor a - ld [H_MULTIPLICAND], 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 + ld [H_MULTIPLIER], a call Multiply ld a, [hl] - ld [H_DIVISOR], a + ld [H_DIVISOR], a ld b, $4 call Divide pop hl @@ -7841,18 +7866,18 @@ StatModifierDownEffect: ; 3f54c (f:754c) ld a, $1 ld [H_MULTIPLICAND + 2], a -UpdateLoweredStat: ; 3f624 (f:7624) +UpdateLoweredStat: ld a, [H_PRODUCT + 2] ld [hli], a ld a, [H_PRODUCT + 3] ld [hl], a pop de pop hl -UpdateLoweredStatDone: ; 3f62c (f:762c) +UpdateLoweredStatDone: ld b, c inc b push de - call Func_3f688 + call PrintStatText pop de ld a, [de] cp $44 @@ -7872,66 +7897,67 @@ UpdateLoweredStatDone: ; 3f62c (f:762c) call QuarterSpeedDueToParalysis jp HalveAttackDueToBurn -Func_3f64d: ; 3f64d (f:764d) +CantLowerAnymore_Pop: pop de pop hl inc [hl] -CantLowerAnymore: ; 3f650 (f:7650) +CantLowerAnymore: ld a, [de] cp ATTACK_DOWN_SIDE_EFFECT ret nc ld hl, NothingHappenedText jp PrintText -MoveMissed: ; 3f65a (f:765a) +MoveMissed: ld a, [de] cp $44 ret nc jp ConditionalPrintButItFailed -MonsStatsFellText: ; 3f661 (f:7661) +MonsStatsFellText: TX_FAR _MonsStatsFellText - db $08 ; asm + TX_ASM ld hl, FellText ld a, [H_WHOSETURN] and a - ld a, [W_PLAYERMOVEEFFECT] - jr z, .asm_3f674 - ld a, [W_ENEMYMOVEEFFECT] -.asm_3f674 - cp $1a + 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 $44 + cp ATTACK_DOWN_SIDE_EFFECT ret nc ld hl, GreatlyFellText ret -GreatlyFellText: ; 3f67e (f:767e) - db $0a +GreatlyFellText: + TX_DELAY TX_FAR _GreatlyFellText - -FellText: ; 3f683 (f:7683) +; fallthrough +FellText: TX_FAR _FellText db "@" -Func_3f688: ; 3f688 (f:7688) +PrintStatText: ld hl, StatsTextStrings - ld c, $50 -.asm_3f68d + ld c, "@" +.findStatName_outer dec b - jr z, .asm_3f696 -.asm_3f690 + jr z, .foundStatName +.findStatName_inner ld a, [hli] cp c - jr z, .asm_3f68d - jr .asm_3f690 -.asm_3f696 + jr z, .findStatName_outer + jr .findStatName_inner +.foundStatName ld de, wcf4b ld bc, $a jp CopyData -StatsTextStrings: ; 3f69f (f:769f) +StatsTextStrings: db "ATTACK@" db "DEFENSE@" db "SPEED@" @@ -7939,7 +7965,7 @@ StatsTextStrings: ; 3f69f (f:769f) db "ACCURACY@" db "EVADE@" -StatModifierRatios: ; 3f6cb (f:76cb) +StatModifierRatios: ; first byte is numerator, second byte is denominator db 25, 100 ; 0.25 db 28, 100 ; 0.28 @@ -7955,14 +7981,14 @@ StatModifierRatios: ; 3f6cb (f:76cb) db 35, 10 ; 3.50 db 4, 1 ; 4.00 -BideEffect: ; 3f6e5 (f:76e5) - ld hl, W_PLAYERBATTSTATUS1 +BideEffect: + ld hl, wPlayerBattleStatus1 ld de, wPlayerBideAccumulatedDamage ld bc, wPlayerNumAttacksLeft ld a, [H_WHOSETURN] and a jr z, .bideEffect - ld hl, W_ENEMYBATTSTATUS1 + ld hl, wEnemyBattleStatus1 ld de, wEnemyBideAccumulatedDamage ld bc, wEnemyNumAttacksLeft .bideEffect @@ -7971,8 +7997,8 @@ BideEffect: ; 3f6e5 (f:76e5) ld [de], a inc de ld [de], a - ld [W_PLAYERMOVEEFFECT], a - ld [W_ENEMYMOVEEFFECT], a + ld [wPlayerMoveEffect], a + ld [wEnemyMoveEffect], a call BattleRandom and $1 inc a @@ -7982,13 +8008,13 @@ BideEffect: ; 3f6e5 (f:76e5) add XSTATITEM_ANIM jp PlayBattleAnimation2 -ThrashPetalDanceEffect: ; 3f717 (f:7717) - ld hl, W_PLAYERBATTSTATUS1 +ThrashPetalDanceEffect: + ld hl, wPlayerBattleStatus1 ld de, wPlayerNumAttacksLeft ld a, [H_WHOSETURN] and a jr z, .thrashPetalDanceEffect - ld hl, W_ENEMYBATTSTATUS1 + ld hl, wEnemyBattleStatus1 ld de, wEnemyNumAttacksLeft .thrashPetalDanceEffect set ThrashingAbout, [hl] ; mon is now using thrash/petal dance @@ -8001,140 +8027,140 @@ ThrashPetalDanceEffect: ; 3f717 (f:7717) add ANIM_B0 jp PlayBattleAnimation2 -SwitchAndTeleportEffect: ; 3f739 (f:7739) +SwitchAndTeleportEffect: ld a, [H_WHOSETURN] and a - jr nz, .asm_3f791 - ld a, [W_ISINBATTLE] + jr nz, .handleEnemy + ld a, [wIsInBattle] dec a - jr nz, .asm_3f77e - ld a, [W_CURENEMYLVL] + jr nz, .notWildBattle1 + ld a, [wCurEnemyLVL] ld b, a ld a, [wBattleMonLevel] - cp b - jr nc, .asm_3f76e + 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 -.asm_3f751 + inc c ; c = sum of player level and enemy level +.rejectionSampleLoop1 call BattleRandom - cp c - jr nc, .asm_3f751 + cp c ; get a random number between 0 and c + jr nc, .rejectionSampleLoop1 srl b - srl b - cp b - jr nc, .asm_3f76e - ld c, $32 + 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, [W_PLAYERMOVENUM] + ld a, [wPlayerMoveNum] cp TELEPORT jp nz, PrintDidntAffectText jp PrintButItFailedText_ -.asm_3f76e +.playerMoveWasSuccessful call ReadPlayerMonCurHPAndStatus xor a ld [wAnimationType], a inc a ld [wEscapedFromBattle], a - ld a, [W_PLAYERMOVENUM] - jr .asm_3f7e4 -.asm_3f77e - ld c, $32 + ld a, [wPlayerMoveNum] + jr .playAnimAndPrintText +.notWildBattle1 + ld c, 50 call DelayFrames ld hl, IsUnaffectedText - ld a, [W_PLAYERMOVENUM] + ld a, [wPlayerMoveNum] cp TELEPORT jp nz, PrintText jp PrintButItFailedText_ -.asm_3f791 - ld a, [W_ISINBATTLE] +.handleEnemy + ld a, [wIsInBattle] dec a - jr nz, .asm_3f7d1 + jr nz, .notWildBattle2 ld a, [wBattleMonLevel] ld b, a - ld a, [W_CURENEMYLVL] + ld a, [wCurEnemyLVL] cp b - jr nc, .asm_3f7c1 + jr nc, .enemyMoveWasSuccessful add b ld c, a inc c -.asm_3f7a4 +.rejectionSampleLoop2 call BattleRandom cp c - jr nc, .asm_3f7a4 + jr nc, .rejectionSampleLoop2 srl b srl b cp b - jr nc, .asm_3f7c1 - ld c, $32 + jr nc, .enemyMoveWasSuccessful + ld c, 50 call DelayFrames - ld a, [W_ENEMYMOVENUM] + ld a, [wEnemyMoveNum] cp TELEPORT jp nz, PrintDidntAffectText jp PrintButItFailedText_ -.asm_3f7c1 +.enemyMoveWasSuccessful call ReadPlayerMonCurHPAndStatus xor a ld [wAnimationType], a inc a ld [wEscapedFromBattle], a - ld a, [W_ENEMYMOVENUM] - jr .asm_3f7e4 -.asm_3f7d1 - ld c, $32 + ld a, [wEnemyMoveNum] + jr .playAnimAndPrintText +.notWildBattle2 + ld c, 50 call DelayFrames ld hl, IsUnaffectedText - ld a, [W_ENEMYMOVENUM] + ld a, [wEnemyMoveNum] cp TELEPORT jp nz, PrintText jp ConditionalPrintButItFailed -.asm_3f7e4 +.playAnimAndPrintText push af call PlayBattleAnimation - ld c, $14 + ld c, 20 call DelayFrames pop af ld hl, RanFromBattleText cp TELEPORT - jr z, .asm_3f7ff + jr z, .printText ld hl, RanAwayScaredText cp ROAR - jr z, .asm_3f7ff + jr z, .printText ld hl, WasBlownAwayText -.asm_3f7ff +.printText jp PrintText -RanFromBattleText: ; 3f802 (f:7802) +RanFromBattleText: TX_FAR _RanFromBattleText db "@" -RanAwayScaredText: ; 3f807 (f:7807) +RanAwayScaredText: TX_FAR _RanAwayScaredText db "@" -WasBlownAwayText: ; 3f80c (f:780c) +WasBlownAwayText: TX_FAR _WasBlownAwayText db "@" -TwoToFiveAttacksEffect: ; 3f811 (f:7811) - ld hl, W_PLAYERBATTSTATUS1 +TwoToFiveAttacksEffect: + ld hl, wPlayerBattleStatus1 ld de, wPlayerNumAttacksLeft ld bc, wPlayerNumHits ld a, [H_WHOSETURN] and a jr z, .twoToFiveAttacksEffect - ld hl, W_ENEMYBATTSTATUS1 + ld hl, wEnemyBattleStatus1 ld de, wEnemyNumAttacksLeft ld bc, wEnemyNumHits .twoToFiveAttacksEffect bit AttackingMultipleTimes, [hl] ; is mon attacking multiple times? ret nz set AttackingMultipleTimes, [hl] ; mon is now attacking multiple times - ld hl, W_PLAYERMOVEEFFECT + ld hl, wPlayerMoveEffect ld a, [H_WHOSETURN] and a jr z, .setNumberOfHits - ld hl, W_ENEMYMOVEEFFECT + ld hl, wEnemyMoveEffect .setNumberOfHits ld a, [hl] cp TWINEEDLE_EFFECT @@ -8146,10 +8172,11 @@ TwoToFiveAttacksEffect: ; 3f811 (f:7811) call BattleRandom and $3 cp $2 - jr c, .asm_3f851 + jr c, .gotNumHits +; if the number of hits was greater than 2, re-roll again for a lower chance call BattleRandom and $3 -.asm_3f851 +.gotNumHits inc a inc a .saveNumberOfHits @@ -8161,16 +8188,16 @@ TwoToFiveAttacksEffect: ; 3f811 (f:7811) ld [hl], a ; set Twineedle's effect to poison effect jr .saveNumberOfHits -FlinchSideEffect: ; 3f85b (f:785b) +FlinchSideEffect: call CheckTargetSubstitute ret nz - ld hl, W_ENEMYBATTSTATUS1 - ld de, W_PLAYERMOVEEFFECT + ld hl, wEnemyBattleStatus1 + ld de, wPlayerMoveEffect ld a, [H_WHOSETURN] and a jr z, .flinchSideEffect - ld hl, W_PLAYERBATTSTATUS1 - ld de, W_ENEMYMOVEEFFECT + ld hl, wPlayerBattleStatus1 + ld de, wEnemyMoveEffect .flinchSideEffect ld a, [de] cp FLINCH_SIDE_EFFECT1 @@ -8185,20 +8212,18 @@ FlinchSideEffect: ; 3f85b (f:785b) call ClearHyperBeam ret -OneHitKOEffect: ; 3f884 (f:7884) - ld hl, OneHitKOEffect_ - ld b, BANK(OneHitKOEffect_) - jp Bankswitch +OneHitKOEffect: + jpab OneHitKOEffect_ -ChargeEffect: ; 3f88c (f:788c) - ld hl, W_PLAYERBATTSTATUS1 - ld de, W_PLAYERMOVEEFFECT +ChargeEffect: + ld hl, wPlayerBattleStatus1 + ld de, wPlayerMoveEffect ld a, [H_WHOSETURN] and a ld b, XSTATITEM_ANIM jr z, .chargeEffect - ld hl, W_ENEMYBATTSTATUS1 - ld de, W_ENEMYMOVEEFFECT + ld hl, wEnemyBattleStatus1 + ld de, wEnemyMoveEffect ld b, ANIM_AF .chargeEffect set ChargingUp, [hl] @@ -8220,71 +8245,71 @@ ChargeEffect: ; 3f88c (f:788c) ld a, b call PlayBattleAnimation ld a, [de] - ld [wWhichTrade], a + ld [wChargeMoveNum], a ld hl, ChargeMoveEffectText jp PrintText -ChargeMoveEffectText: ; 3f8c8 (f:78c8) +ChargeMoveEffectText: TX_FAR _ChargeMoveEffectText - db $08 ; asm - ld a, [wWhichTrade] + TX_ASM + ld a, [wChargeMoveNum] cp RAZOR_WIND ld hl, MadeWhirlwindText - jr z, .asm_3f8f8 + jr z, .gotText cp SOLARBEAM ld hl, TookInSunlightText - jr z, .asm_3f8f8 + jr z, .gotText cp SKULL_BASH ld hl, LoweredItsHeadText - jr z, .asm_3f8f8 + jr z, .gotText cp SKY_ATTACK ld hl, SkyAttackGlowingText - jr z, .asm_3f8f8 + jr z, .gotText cp FLY ld hl, FlewUpHighText - jr z, .asm_3f8f8 + jr z, .gotText cp DIG ld hl, DugAHoleText -.asm_3f8f8 +.gotText ret -MadeWhirlwindText: ; 3f8f9 (f:78f9) +MadeWhirlwindText: TX_FAR _MadeWhirlwindText db "@" -TookInSunlightText: ; 3f8fe (f:78fe) +TookInSunlightText: TX_FAR _TookInSunlightText db "@" -LoweredItsHeadText: ; 3f903 (f:7903) +LoweredItsHeadText: TX_FAR _LoweredItsHeadText db "@" -SkyAttackGlowingText: ; 3f908 (f:7908) +SkyAttackGlowingText: TX_FAR _SkyAttackGlowingText db "@" -FlewUpHighText: ; 3f90d (f:790d) +FlewUpHighText: TX_FAR _FlewUpHighText db "@" -DugAHoleText: ; 3f912 (f:7912) +DugAHoleText: TX_FAR _DugAHoleText db "@" -TrappingEffect: ; 3f917 (f:7917) - ld hl, W_PLAYERBATTSTATUS1 +TrappingEffect: + ld hl, wPlayerBattleStatus1 ld de, wPlayerNumAttacksLeft ld a, [H_WHOSETURN] and a jr z, .trappingEffect - ld hl, W_ENEMYBATTSTATUS1 + ld hl, wEnemyBattleStatus1 ld de, wEnemyNumAttacksLeft .trappingEffect bit UsingTrappingMove, [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 + 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 UsingTrappingMove, [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 @@ -8297,52 +8322,46 @@ TrappingEffect: ; 3f917 (f:7917) ld [de], a ret -MistEffect: ; 3f941 (f:7941) - ld hl, MistEffect_ - ld b, BANK(MistEffect_) - jp Bankswitch +MistEffect: + jpab MistEffect_ -FocusEnergyEffect: ; 3f949 (f:7949) - ld hl, FocusEnergyEffect_ - ld b, BANK(FocusEnergyEffect_) - jp Bankswitch +FocusEnergyEffect: + jpab FocusEnergyEffect_ -RecoilEffect: ; 3f951 (f:7951) - ld hl, RecoilEffect_ - ld b, BANK(RecoilEffect_) - jp Bankswitch +RecoilEffect: + jpab RecoilEffect_ -ConfusionSideEffect: ; 3f959 (f:7959) +ConfusionSideEffect: call BattleRandom - cp $19 + cp $19 ; ~10% chance ret nc jr ConfusionSideEffectSuccess -ConfusionEffect: ; 3f961 (f:7961) +ConfusionEffect: call CheckTargetSubstitute jr nz, ConfusionEffectFailed call MoveHitTest - ld a, [W_MOVEMISSED] + ld a, [wMoveMissed] and a jr nz, ConfusionEffectFailed -ConfusionSideEffectSuccess: ; 3f96f (f:796f) +ConfusionSideEffectSuccess: ld a, [H_WHOSETURN] and a - ld hl, W_ENEMYBATTSTATUS1 - ld bc, W_ENEMYCONFUSEDCOUNTER - ld a, [W_PLAYERMOVEEFFECT] + ld hl, wEnemyBattleStatus1 + ld bc, wEnemyConfusedCounter + ld a, [wPlayerMoveEffect] jr z, .confuseTarget - ld hl, W_PLAYERBATTSTATUS1 - ld bc, W_PLAYERCONFUSEDCOUNTER - ld a, [W_ENEMYMOVEEFFECT] + 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 + and $3 inc a inc a ld [bc], a ; confusion status will last 2-5 turns @@ -8352,80 +8371,76 @@ ConfusionSideEffectSuccess: ; 3f96f (f:796f) ld hl, BecameConfusedText jp PrintText -BecameConfusedText: ; 3f9a1 (f:79a1) +BecameConfusedText: TX_FAR _BecameConfusedText db "@" -ConfusionEffectFailed: ; 3f9a6 (f:79a6) +ConfusionEffectFailed: cp CONFUSION_SIDE_EFFECT ret z - ld c, $32 + ld c, 50 call DelayFrames jp ConditionalPrintButItFailed -ParalyzeEffect: ; 3f9b1 (f:79b1) - ld hl, ParalyzeEffect_ - ld b, BANK(ParalyzeEffect_) - jp Bankswitch +ParalyzeEffect: + jpab ParalyzeEffect_ -SubstituteEffect: ; 3f9b9 (f:79b9) - ld hl, SubstituteEffect_ - ld b, BANK(SubstituteEffect_) - jp Bankswitch +SubstituteEffect: + jpab SubstituteEffect_ -HyperBeamEffect: ; 3f9c1 (f:79c1) - ld hl, W_PLAYERBATTSTATUS2 +HyperBeamEffect: + ld hl, wPlayerBattleStatus2 ld a, [H_WHOSETURN] and a jr z, .hyperBeamEffect - ld hl, W_ENEMYBATTSTATUS2 + ld hl, wEnemyBattleStatus2 .hyperBeamEffect set NeedsToRecharge, [hl] ; mon now needs to recharge ret -ClearHyperBeam: ; 3f9cf (f:79cf) +ClearHyperBeam: push hl - ld hl, W_ENEMYBATTSTATUS2 + ld hl, wEnemyBattleStatus2 ld a, [H_WHOSETURN] and a - jr z, .asm_3f9db - ld hl, W_PLAYERBATTSTATUS2 -.asm_3f9db + jr z, .playerTurn + ld hl, wPlayerBattleStatus2 +.playerTurn res NeedsToRecharge, [hl] ; mon no longer needs to recharge pop hl ret -RageEffect: ; 3f9df (f:79df) - ld hl, W_PLAYERBATTSTATUS2 +RageEffect: + ld hl, wPlayerBattleStatus2 ld a, [H_WHOSETURN] and a jr z, .player - ld hl, W_ENEMYBATTSTATUS2 + ld hl, wEnemyBattleStatus2 .player set UsingRage, [hl] ; mon is now in "rage" mode ret -MimicEffect: ; 3f9ed (f:79ed) - ld c, $32 +MimicEffect: + ld c, 50 call DelayFrames call MoveHitTest - ld a, [W_MOVEMISSED] + ld a, [wMoveMissed] and a - jr nz, .asm_3fa74 + jr nz, .mimicMissed ld a, [H_WHOSETURN] and a ld hl, wBattleMonMoves - ld a, [W_PLAYERBATTSTATUS1] - jr nz, .asm_3fa13 + ld a, [wPlayerBattleStatus1] + jr nz, .enemyTurn ld a, [wLinkState] cp LINK_STATE_BATTLING - jr nz, .asm_3fa3a + jr nz, .letPlayerChooseMove ld hl, wEnemyMonMoves - ld a, [W_ENEMYBATTSTATUS1] -.asm_3fa13 + ld a, [wEnemyBattleStatus1] +.enemyTurn bit Invulnerable, a - jr nz, .asm_3fa74 -.asm_3fa17 + jr nz, .mimicMissed +.getRandomMove push hl call BattleRandom and $3 @@ -8435,20 +8450,20 @@ MimicEffect: ; 3f9ed (f:79ed) ld a, [hl] pop hl and a - jr z, .asm_3fa17 + jr z, .getRandomMove ld d, a ld a, [H_WHOSETURN] and a ld hl, wBattleMonMoves ld a, [wPlayerMoveListIndex] - jr z, .asm_3fa5f + jr z, .playerTurn ld hl, wEnemyMonMoves ld a, [wEnemyMoveListIndex] - jr .asm_3fa5f -.asm_3fa3a - ld a, [W_ENEMYBATTSTATUS1] + jr .playerTurn +.letPlayerChooseMove + ld a, [wEnemyBattleStatus1] bit Invulnerable, a - jr nz, .asm_3fa74 + jr nz, .mimicMissed ld a, [wCurrentMenuItem] push af ld a, $1 @@ -8463,7 +8478,7 @@ MimicEffect: ; 3f9ed (f:79ed) ld d, [hl] pop af ld hl, wBattleMonMoves -.asm_3fa5f +.playerTurn ld c, a ld b, $0 add hl, bc @@ -8474,39 +8489,38 @@ MimicEffect: ; 3f9ed (f:79ed) call PlayCurrentMoveAnimation ld hl, MimicLearnedMoveText jp PrintText -.asm_3fa74 +.mimicMissed jp PrintButItFailedText_ -MimicLearnedMoveText: ; 3fa77 (f:7a77) +MimicLearnedMoveText: TX_FAR _MimicLearnedMoveText db "@" -LeechSeedEffect: ; 3fa7c (f:7a7c) - ld hl, LeechSeedEffect_ - ld b, BANK(LeechSeedEffect_) - jp Bankswitch +LeechSeedEffect: + jpab LeechSeedEffect_ -SplashEffect: ; 3fa84 (f:7a84) +SplashEffect: call PlayCurrentMoveAnimation jp PrintNoEffectText -DisableEffect: ; 3fa8a (f:7a8a) +DisableEffect: call MoveHitTest - ld a, [W_MOVEMISSED] + ld a, [wMoveMissed] and a - jr nz, .asm_3fb06 - ld de, W_ENEMYDISABLEDMOVE + jr nz, .moveMissed + ld de, wEnemyDisabledMove ld hl, wEnemyMonMoves ld a, [H_WHOSETURN] and a - jr z, .asm_3faa4 - ld de, W_PLAYERDISABLEDMOVE + jr z, .disableEffect + ld de, wPlayerDisabledMove ld hl, wBattleMonMoves -.asm_3faa4 +.disableEffect +; no effect if target already has a move disabled ld a, [de] and a - jr nz, .asm_3fb06 -.asm_3faa8 + jr nz, .moveMissed +.pickMoveToDisable push hl call BattleRandom and $3 @@ -8516,20 +8530,21 @@ DisableEffect: ; 3fa8a (f:7a8a) ld a, [hl] pop hl and a - jr z, .asm_3faa8 - ld [wd11e], 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, .asm_3facf + jr nz, .enemyTurn ld a, [wLinkState] cp LINK_STATE_BATTLING - pop hl - jr nz, .asm_3fae1 + pop hl ; wEnemyMonMoves + jr nz, .playerTurnNotLinkBattle +; .playerTurnLinkBattle push hl ld hl, wEnemyMonPP -.asm_3facf +.enemyTurn push hl ld a, [hli] or [hl] @@ -8538,144 +8553,133 @@ DisableEffect: ; 3fa8a (f:7a8a) inc hl or [hl] and $3f - pop hl - jr z, .asm_3fb05 + 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, .asm_3faa8 -.asm_3fae1 + 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 - inc c + inc a ; 1-8 turns disabled + inc c ; move 1-4 will be disabled swap c - add c + add c ; map disabled move to high nibble of wEnemyDisabledMove / wPlayerDisabledMove ld [de], a call PlayCurrentMoveAnimation2 - ld hl, wccee + ld hl, wPlayerDisabledMoveNumber ld a, [H_WHOSETURN] and a - jr nz, .asm_3faf8 - inc hl -.asm_3faf8 - ld a, [wd11e] + jr nz, .printDisableText + inc hl ; wEnemyDisabledMoveNumber +.printDisableText + ld a, [wd11e] ; move number ld [hl], a call GetMoveName ld hl, MoveWasDisabledText jp PrintText -.asm_3fb05 +.moveMissedPopHL pop hl -.asm_3fb06 +.moveMissed jp PrintButItFailedText_ -MoveWasDisabledText: ; 3fb09 (f:7b09) +MoveWasDisabledText: TX_FAR _MoveWasDisabledText db "@" -PayDayEffect: ; 3fb0e (f:7b0e) - ld hl, PayDayEffect_ - ld b, BANK(PayDayEffect_) - jp Bankswitch - -ConversionEffect: ; 3fb16 (f:7b16) - ld hl, ConversionEffect_ - ld b, BANK(ConversionEffect_) - jp Bankswitch - -HazeEffect: ; 3fb1e (f:7b1e) - ld hl, HazeEffect_ - ld b, BANK(HazeEffect_) - jp Bankswitch - -HealEffect: ; 3fb26 (f:7b26) - ld hl, HealEffect_ - ld b, BANK(HealEffect_) - jp Bankswitch - -TransformEffect: ; 3fb2e (f:7b2e) - ld hl, TransformEffect_ - ld b, BANK(TransformEffect_) - jp Bankswitch - -ReflectLightScreenEffect: ; 3fb36 (f:7b36) - ld hl, ReflectLightScreenEffect_ - ld b, BANK(ReflectLightScreenEffect_) - jp Bankswitch - -NothingHappenedText: ; 3fb3e (f:7b3e) +PayDayEffect: + jpab PayDayEffect_ + +ConversionEffect: + jpab ConversionEffect_ + +HazeEffect: + jpab HazeEffect_ + +HealEffect: + jpab HealEffect_ + +TransformEffect: + jpab TransformEffect_ + +ReflectLightScreenEffect: + jpab ReflectLightScreenEffect_ + +NothingHappenedText: TX_FAR _NothingHappenedText db "@" -PrintNoEffectText: ; 3fb43 (f:7b43) +PrintNoEffectText: ld hl, NoEffectText jp PrintText -NoEffectText: ; 3fb49 (f:7b49) +NoEffectText: TX_FAR _NoEffectText db "@" -ConditionalPrintButItFailed: ; 3fb4e (f:7b4e) +ConditionalPrintButItFailed: ld a, [wMoveDidntMiss] and a ret nz ; return if the side effect failed, yet the attack was successful -PrintButItFailedText_: ; 3fb53 (f:7b53) +PrintButItFailedText_: ld hl, ButItFailedText jp PrintText -ButItFailedText: ; 3fb59 (f:7b59) +ButItFailedText: TX_FAR _ButItFailedText db "@" -PrintDidntAffectText: ; 3fb5e (f:7b5e) +PrintDidntAffectText: ld hl, DidntAffectText jp PrintText -DidntAffectText: ; 3fb64 (f:7b64) +DidntAffectText: TX_FAR _DidntAffectText db "@" -IsUnaffectedText: ; 3fb69 (f:7b69) +IsUnaffectedText: TX_FAR _IsUnaffectedText db "@" -PrintMayNotAttackText: ; 3fb6e (f:7b6e) +PrintMayNotAttackText: ld hl, ParalyzedMayNotAttackText jp PrintText -ParalyzedMayNotAttackText: ; 3fb74 (f:7b74) +ParalyzedMayNotAttackText: TX_FAR _ParalyzedMayNotAttackText db "@" -CheckTargetSubstitute: ; 3fb79 (f:7b79) +CheckTargetSubstitute: push hl - ld hl, W_ENEMYBATTSTATUS2 - ld a, [H_WHOSETURN] + ld hl, wEnemyBattleStatus2 + ld a, [H_WHOSETURN] and a jr z, .next1 - ld hl, W_PLAYERBATTSTATUS2 + ld hl, wPlayerBattleStatus2 .next1 - bit HasSubstituteUp, [hl] + bit HasSubstituteUp, [hl] pop hl ret -PlayCurrentMoveAnimation2: ; 3fb89 (f:7b89) +PlayCurrentMoveAnimation2: ; animation at MOVENUM will be played unless MOVENUM is 0 ; plays wAnimationType 3 or 6 ld a, [H_WHOSETURN] and a - ld a, [W_PLAYERMOVENUM] + ld a, [wPlayerMoveNum] jr z, .notEnemyTurn - ld a, [W_ENEMYMOVENUM] + ld a, [wEnemyMoveNum] .notEnemyTurn and a ret z -PlayBattleAnimation2: ; 3fb96 (f:7b96) +PlayBattleAnimation2: ; play animation ID at a and animation type 6 or 3 - ld [W_ANIMATIONID], a + ld [wAnimationID], a ld a, [H_WHOSETURN] and a ld a, $6 @@ -8685,26 +8689,26 @@ PlayBattleAnimation2: ; 3fb96 (f:7b96) ld [wAnimationType], a jp PlayBattleAnimationGotID -PlayCurrentMoveAnimation: ; 3fba8 (f:7ba8) +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, [W_PLAYERMOVENUM] + ld a, [wPlayerMoveNum] jr z, .notEnemyTurn - ld a, [W_ENEMYMOVENUM] + ld a, [wEnemyMoveNum] .notEnemyTurn and a ret z -PlayBattleAnimation: ; 3fbb9 (f:7bb9) +PlayBattleAnimation: ; play animation ID at a and predefined animation type - ld [W_ANIMATIONID], a + ld [wAnimationID], a -PlayBattleAnimationGotID: ; 3fbbc (f:7bbc) -; play animation at W_ANIMATIONID +PlayBattleAnimationGotID: +; play animation at wAnimationID push hl push de push bc diff --git a/engine/battle/decrement_pp.asm b/engine/battle/decrement_pp.asm index ecf5040b..e23a85ba 100644 --- a/engine/battle/decrement_pp.asm +++ b/engine/battle/decrement_pp.asm @@ -1,23 +1,23 @@ -DecrementPP: ; 68000 (1a:4000) +DecrementPP: ; after using a move, decrement pp in battle and (if not transformed?) in party ld a, [de] cp a, STRUGGLE ret z ; if the pokemon is using "struggle", there's nothing to do ; we don't decrement PP for "struggle" - ld hl, W_PLAYERBATTSTATUS1 - ld a, [hli] ; load the W_PLAYERBATTSTATUS1 pokemon status flags and increment hl to load the - ; W_PLAYERBATTSTATUS2 status flags later + ld hl, wPlayerBattleStatus1 + ld a, [hli] ; load the wPlayerBattleStatus1 pokemon status flags and increment hl to load the + ; wPlayerBattleStatus2 status flags later and a, (1 << StoringEnergy) | (1 << ThrashingAbout) | (1 << AttackingMultipleTimes) ret nz ; if any of these statuses are true, don't decrement PP - bit UsingRage, [hl] + bit UsingRage, [hl] ret nz ; don't decrement PP either if Pokemon is using Rage ld hl, wBattleMonPP ; PP of first move (in battle) - -; decrement PP in the battle struct - call .DecrementPP - -; decrement PP in the party struct - ld a, [W_PLAYERBATTSTATUS3] + +; decrement PP in the battle struct + call .DecrementPP + +; decrement PP in the party struct + ld a, [wPlayerBattleStatus3] bit Transformed, a ret nz ; Return if transformed. Pokemon Red stores the "current pokemon's" PP ; separately from the "Pokemon in your party's" PP. This is @@ -31,9 +31,9 @@ DecrementPP: ; 68000 (1a:4000) ld hl, wPartyMon1PP ; PP of first move (in party) ld a, [wPlayerMonNumber] ; which mon in party is active - ld bc, wPartyMon2 - wPartyMon1 + ld bc, wPartyMon2 - wPartyMon1 call AddNTimes ; calculate address of the mon to modify -.DecrementPP +.DecrementPP: ld a, [wPlayerMoveListIndex] ; which move (0, 1, 2, 3) did we use? ld c, a ld b, 0 diff --git a/engine/battle/display_effectiveness.asm b/engine/battle/display_effectiveness.asm index 17f0bd5b..85f2bc3e 100644 --- a/engine/battle/display_effectiveness.asm +++ b/engine/battle/display_effectiveness.asm @@ -1,4 +1,4 @@ -DisplayEffectiveness: ; 2fb7b (b:7b7b) +DisplayEffectiveness: ld a, [wDamageMultipliers] and a, $7F cp a, $0A @@ -9,10 +9,10 @@ DisplayEffectiveness: ; 2fb7b (b:7b7b) .done jp PrintText -SuperEffectiveText: ; 2fb8e (b:7b8e) +SuperEffectiveText: TX_FAR _SuperEffectiveText db "@" -NotVeryEffectiveText: ; 2fb93 (b:7b93) +NotVeryEffectiveText: TX_FAR _NotVeryEffectiveText db "@" diff --git a/engine/battle/draw_hud_pokeball_gfx.asm b/engine/battle/draw_hud_pokeball_gfx.asm index fce3701c..f44d64f5 100644 --- a/engine/battle/draw_hud_pokeball_gfx.asm +++ b/engine/battle/draw_hud_pokeball_gfx.asm @@ -1,50 +1,50 @@ -DrawAllPokeballs: ; 3a849 (e:6849) +DrawAllPokeballs: call LoadPartyPokeballGfx call SetupOwnPartyPokeballs - ld a, [W_ISINBATTLE] ; W_ISINBATTLE + ld a, [wIsInBattle] dec a ret z ; return if wild pokémon jp SetupEnemyPartyPokeballs -DrawEnemyPokeballs: ; 0x3a857 +DrawEnemyPokeballs: call LoadPartyPokeballGfx jp SetupEnemyPartyPokeballs -LoadPartyPokeballGfx: ; 3a85d (e:685d) - ld de, PokeballTileGraphics ; $697e +LoadPartyPokeballGfx: + ld de, PokeballTileGraphics ld hl, vSprites + $310 - ld bc, (BANK(PokeballTileGraphics) << 8) + $04 + lb bc, BANK(PokeballTileGraphics), (PokeballTileGraphicsEnd - PokeballTileGraphics) / $10 jp CopyVideoData -SetupOwnPartyPokeballs: ; 3a869 (e:6869) +SetupOwnPartyPokeballs: call PlacePlayerHUDTiles ld hl, wPartyMon1 - ld de, wPartyCount ; wPartyCount + ld de, wPartyCount call SetupPokeballs ld a, $60 - ld hl, W_BASECOORDX ; wd081 + ld hl, wBaseCoordX ld [hli], a ld [hl], a - ld a, $8 - ld [wTrainerEngageDistance], a + ld a, 8 + ld [wHUDPokeballGfxOffsetX], a ld hl, wOAMBuffer jp WritePokeballOAMData -SetupEnemyPartyPokeballs: ; 3a887 (e:6887) +SetupEnemyPartyPokeballs: call PlaceEnemyHUDTiles ld hl, wEnemyMons - ld de, wEnemyPartyCount ; wEnemyPartyCount + ld de, wEnemyPartyCount call SetupPokeballs - ld hl, W_BASECOORDX ; wd081 + ld hl, wBaseCoordX ld a, $48 ld [hli], a ld [hl], $20 - ld a, $f8 - ld [wTrainerEngageDistance], a + ld a, -8 + ld [wHUDPokeballGfxOffsetX], a ld hl, wOAMBuffer + PARTY_LENGTH * 4 jp WritePokeballOAMData -SetupPokeballs: ; 0x3a8a6 +SetupPokeballs: ld a, [de] push af ld de, wBuffer @@ -66,7 +66,7 @@ SetupPokeballs: ; 0x3a8a6 jr nz, .monloop ret -PickPokeball: ; 3a8c2 (e:68c2) +PickPokeball: inc hl ld a, [hli] and a @@ -90,96 +90,96 @@ PickPokeball: ; 3a8c2 (e:68c2) .done ld a, b ld [de], a - ld bc, $0028 ; rest of mon struct - add hl, bc + ld bc, wPartyMon2 - wPartyMon1Status + add hl, bc ; next mon struct ret -WritePokeballOAMData: ; 3a8e1 (e:68e1) +WritePokeballOAMData: ld de, wBuffer ld c, PARTY_LENGTH .loop - ld a, [W_BASECOORDY] ; wd082 + ld a, [wBaseCoordY] ld [hli], a - ld a, [W_BASECOORDX] ; wd081 + ld a, [wBaseCoordX] ld [hli], a ld a, [de] ld [hli], a xor a ld [hli], a - ld a, [W_BASECOORDX] ; wd081 + ld a, [wBaseCoordX] ld b, a - ld a, [wTrainerEngageDistance] + ld a, [wHUDPokeballGfxOffsetX] add b - ld [W_BASECOORDX], a ; wd081 + ld [wBaseCoordX], a inc de dec c jr nz, .loop ret -PlacePlayerHUDTiles: ; 3a902 (e:6902) - ld hl, PlayerBattleHUDGraphicsTiles ; $6916 - ld de, wTrainerFacingDirection +PlacePlayerHUDTiles: + ld hl, PlayerBattleHUDGraphicsTiles + ld de, wHUDGraphicsTiles ld bc, $3 call CopyData - hlCoord 18, 10 - ld de, rIE ; $ffff + coord hl, 18, 10 + ld de, -1 jr PlaceHUDTiles -PlayerBattleHUDGraphicsTiles: ; 3a916 (e:6916) +PlayerBattleHUDGraphicsTiles: ; The tile numbers for specific parts of the battle display for the player's pokemon db $73 ; unused ($73 is hardcoded into the routine that uses these bytes) db $77 ; lower-right corner tile of the HUD db $6F ; lower-left triangle tile of the HUD -PlaceEnemyHUDTiles: ; 3a919 (e:6919) - ld hl, EnemyBattleHUDGraphicsTiles ; $692d - ld de, wTrainerFacingDirection +PlaceEnemyHUDTiles: + ld hl, EnemyBattleHUDGraphicsTiles + ld de, wHUDGraphicsTiles ld bc, $3 call CopyData - hlCoord 1, 2 + coord hl, 1, 2 ld de, $1 jr PlaceHUDTiles -EnemyBattleHUDGraphicsTiles: ; 3a92d (e:692d) +EnemyBattleHUDGraphicsTiles: ; The tile numbers for specific parts of the battle display for the enemy db $73 ; unused ($73 is hardcoded in the routine that uses these bytes) db $74 ; lower-left corner tile of the HUD db $78 ; lower-right triangle tile of the HUD -PlaceHUDTiles: ; 3a930 (e:6930) +PlaceHUDTiles: ld [hl], $73 - ld bc, $14 + ld bc, SCREEN_WIDTH add hl, bc - ld a, [wTrainerScreenY] + ld a, [wHUDGraphicsTiles + 1] ; leftmost tile ld [hl], a - ld a, $8 -.asm_3a93c + ld a, 8 +.loop add hl, de ld [hl], $76 dec a - jr nz, .asm_3a93c + jr nz, .loop add hl, de - ld a, [wTrainerScreenX] + ld a, [wHUDGraphicsTiles + 2] ; rightmost tile ld [hl], a ret -SetupPlayerAndEnemyPokeballs: ; 3a948 (e:6948) +SetupPlayerAndEnemyPokeballs: call LoadPartyPokeballGfx - ld hl, wPartyMon1Species ; wPartyMon1Species (aliases: wPartyMon1) - ld de, wPartyCount ; wPartyCount + ld hl, wPartyMons + ld de, wPartyCount call SetupPokeballs - ld hl, W_BASECOORDX ; wd081 + ld hl, wBaseCoordX ld a, $50 ld [hli], a ld [hl], $40 - ld a, $8 - ld [wTrainerEngageDistance], a + ld a, 8 + ld [wHUDPokeballGfxOffsetX], a ld hl, wOAMBuffer call WritePokeballOAMData - ld hl, wEnemyMons ; wEnemyMon1Species - ld de, wEnemyPartyCount ; wEnemyPartyCount + ld hl, wEnemyMons + ld de, wEnemyPartyCount call SetupPokeballs - ld hl, W_BASECOORDX ; wd081 + ld hl, wBaseCoordX ld a, $50 ld [hli], a ld [hl], $68 @@ -187,5 +187,6 @@ SetupPlayerAndEnemyPokeballs: ; 3a948 (e:6948) jp WritePokeballOAMData ; four tiles: pokeball, black pokeball (status ailment), crossed out pokeball (faited) and pokeball slot (no mon) -PokeballTileGraphics:: ; 3a97e (e:697e) +PokeballTileGraphics:: INCBIN "gfx/pokeball.2bpp" +PokeballTileGraphicsEnd: diff --git a/engine/battle/end_of_battle.asm b/engine/battle/end_of_battle.asm index f03dd07f..c77e3b39 100644..100755 --- a/engine/battle/end_of_battle.asm +++ b/engine/battle/end_of_battle.asm @@ -1,4 +1,4 @@ -EndOfBattle: ; 137aa (4:77aa) +EndOfBattle: ld a, [wLinkState] cp LINK_STATE_BATTLING jr nz, .notLinkBattle @@ -19,9 +19,9 @@ EndOfBattle: ; 137aa (4:77aa) jr z, .placeWinOrLoseString ld de, DrawText .placeWinOrLoseString - hlCoord 6, 8 + coord hl, 6, 8 call PlaceString - ld c, $c8 + ld c, 200 call DelayFrames jr .evolution .notLinkBattle @@ -41,20 +41,20 @@ EndOfBattle: ; 137aa (4:77aa) call PrintText .evolution xor a - ld [wccd4], a + ld [wForceEvolution], a predef EvolutionAfterBattle .resetVariables xor a ld [wLowHealthAlarm], a ;disable low health alarm - ld [wc02a], a - ld [W_ISINBATTLE], a - ld [W_BATTLETYPE], a - ld [W_MOVEMISSED], a - ld [W_CUROPPONENT], a - ld [wd11f], a + ld [wChannelSoundIDs + Ch4], a + ld [wIsInBattle], a + ld [wBattleType], a + ld [wMoveMissed], a + ld [wCurOpponent], a + ld [wForcePlayerToChooseMon], a ld [wNumRunAttempts], a ld [wEscapedFromBattle], a - ld hl, wcc2b + ld hl, wPartyAndBillsPCSavedMenuItem ld [hli], a ld [hli], a ld [hli], a @@ -74,15 +74,15 @@ EndOfBattle: ; 137aa (4:77aa) ld [wDestinationWarpID], a ret -YouWinText: ; 13853 (4:7853) +YouWinText: db "YOU WIN@" -YouLoseText: ; 1385b (4:785b) +YouLoseText: db "YOU LOSE@" -DrawText: ; 13864 (4:7864) +DrawText: db " DRAW@" -PickUpPayDayMoneyText: ; 1386b (4:786b) +PickUpPayDayMoneyText: TX_FAR _PickUpPayDayMoneyText - db "@"
\ No newline at end of file + db "@" diff --git a/engine/battle/experience.asm b/engine/battle/experience.asm index 9bd67654..24748338 100644 --- a/engine/battle/experience.asm +++ b/engine/battle/experience.asm @@ -1,4 +1,4 @@ -GainExperience: ; 5524f (15:524f) +GainExperience: ld a, [wLinkState] cp LINK_STATE_BATTLING ret z ; return if link battle @@ -15,7 +15,7 @@ GainExperience: ; 5524f (15:524f) ld hl, wPartyGainExpFlags ld a, [wWhichPokemon] ld c, a - ld b, $2 + ld b, FLAG_TEST predef FlagActionPredef ld a, c and a ; is mon's gain exp flag set? @@ -26,7 +26,7 @@ GainExperience: ; 5524f (15:524f) ld d, h ld e, l ld hl, wEnemyMonBaseStats - ld c, $5 + ld c, NUM_STATS .gainStatExpLoop ld a, [hli] ld b, a ; enemy mon base stat @@ -49,11 +49,11 @@ GainExperience: ; 5524f (15:524f) ld [de], a .nextBaseStat dec c - jr z, .asm_552a1 + jr z, .statExpDone inc de inc de jr .gainStatExpLoop -.asm_552a1 +.statExpDone xor a ld [H_MULTIPLICAND], a ld [H_MULTIPLICAND + 1], a @@ -66,7 +66,7 @@ GainExperience: ; 5524f (15:524f) ld [H_DIVISOR], a ld b, 4 call Divide - ld hl, -((wPartyMon1HPExp + 1) - wPartyMon1OTID + 4 * 2) + ld hl, wPartyMon1OTID - (wPartyMon1DVs - 1) add hl, de ld b, [hl] ; party mon OTID inc hl @@ -76,14 +76,14 @@ GainExperience: ; 5524f (15:524f) ld b, [hl] ld a, [wPlayerID + 1] cp b - ld a, $0 + ld a, 0 jr z, .next .tradedMon call BoostExp ; traded mon exp boost - ld a, $1 + ld a, 1 .next ld [wGainBoostedExp], a - ld a, [W_ISINBATTLE] + ld a, [wIsInBattle] dec a ; is it a trainer battle? call nz, BoostExp ; if so, boost exp inc hl @@ -92,12 +92,12 @@ GainExperience: ; 5524f (15:524f) ; add the gained exp to the party mon's exp ld b, [hl] ld a, [H_QUOTIENT + 3] - ld [wcf4c], a + ld [wExpAmountGained + 1], a add b ld [hld], a ld b, [hl] ld a, [H_QUOTIENT + 2] - ld [wcf4b], a + ld [wExpAmountGained], a adc b ld [hl], a jr nc, .noCarry @@ -119,11 +119,11 @@ GainExperience: ; 5524f (15:524f) ld d, MAX_LEVEL callab CalcExperience ; get max exp ; compare max exp with current exp - ld a, [$ff96] + ld a, [hExperience] ld b, a - ld a, [$ff97] + ld a, [hExperience + 1] ld c, a - ld a, [$ff98] + ld a, [hExperience + 2] ld d, a pop hl ld a, [hld] @@ -148,8 +148,8 @@ GainExperience: ; 5524f (15:524f) call GetPartyMonName ld hl, GainedText call PrintText - xor a ; party mon data - ld [wcc49], a + xor a ; PLAYER_PARTY_DATA + ld [wMonDataLocation], a call LoadMonData pop hl ld bc, wPartyMon1Level - wPartyMon1Exp @@ -160,11 +160,11 @@ GainExperience: ; 5524f (15:524f) ld a, [hl] ; current level cp d jp z, .nextMon ; if level didn't change, go to next mon - ld a, [W_CURENEMYLVL] + ld a, [wCurEnemyLVL] push af push hl ld a, d - ld [W_CURENEMYLVL], a + ld [wCurEnemyLVL], a ld [hl], a ld bc, wPartyMon1Species - wPartyMon1Level add hl, bc @@ -220,19 +220,19 @@ GainExperience: ; 5524f (15:524f) add hl, bc push hl ld de, wBattleMonLevel - ld bc, $b ; size of stats + ld bc, 1 + NUM_STATS * 2 ; size of stats call CopyData pop hl - ld a, [W_PLAYERBATTSTATUS3] + ld a, [wPlayerBattleStatus3] bit 3, a ; is the mon transformed? jr nz, .recalcStatChanges ; the mon is not transformed, so update the unmodified stats ld de, wPlayerMonUnmodifiedLevel - ld bc, $b + ld bc, 1 + NUM_STATS * 2 call CopyData .recalcStatChanges - xor a - ld [wd11e], a + xor a ; battle mon + ld [wCalculateWhoseStats], a callab CalculateModifiedStats callab ApplyBurnAndParalysisPenaltiesToPlayer callab ApplyBadgeStatBoosts @@ -242,26 +242,26 @@ GainExperience: ; 5524f (15:524f) .printGrewLevelText ld hl, GrewLevelText call PrintText - xor a ; party mon data - ld [wcc49], a + xor a ; PLAYER_PARTY_DATA + ld [wMonDataLocation], a call LoadMonData ld d, $1 callab PrintStatsBox call WaitForTextScrollButtonPress call LoadScreenTilesFromBuffer1 - xor a - ld [wcc49], a + xor a ; PLAYER_PARTY_DATA + ld [wMonDataLocation], a ld a, [wd0b5] ld [wd11e], a predef LearnMoveFromLevelUp - ld hl, wccd3 + ld hl, wCanEvolveFlags ld a, [wWhichPokemon] ld c, a - ld b, $1 + ld b, FLAG_SET predef FlagActionPredef pop hl pop af - ld [W_CURENEMYLVL], a + ld [wCurEnemyLVL], a .nextMon ld a, [wPartyCount] @@ -281,7 +281,7 @@ GainExperience: ; 5524f (15:524f) ld [hl], a ; clear gain exp flags ld a, [wPlayerMonNumber] ld c, a - ld b, $1 + ld b, FLAG_SET push bc predef FlagActionPredef ; set the gain exp flag for the mon that is currently out ld hl, wPartyFoughtCurrentEnemyFlags @@ -291,7 +291,7 @@ GainExperience: ; 5524f (15:524f) predef_jump FlagActionPredef ; set the fought current enemy flag for the mon that is currently out ; divide enemy base stats, catch rate, and base exp by the number of mons gaining exp -DivideExpDataByNumMonsGainingExp: ; 5546c (15:546c) +DivideExpDataByNumMonsGainingExp: ld a, [wPartyGainExpFlags] ld b, a xor a @@ -308,7 +308,7 @@ DivideExpDataByNumMonsGainingExp: ; 5546c (15:546c) ret c ; return if only one mon is gaining exp ld [wd11e], a ; store number of mons gaining exp ld hl, wEnemyMonBaseStats - ld c, $7 + ld c, wEnemyMonBaseExp + 1 - wEnemyMonBaseStats .divideLoop xor a ld [H_DIVIDEND], a @@ -325,7 +325,7 @@ DivideExpDataByNumMonsGainingExp: ; 5546c (15:546c) ret ; multiplies exp by 1.5 -BoostExp: ; 5549f (15:549f) +BoostExp: ld a, [H_QUOTIENT + 2] ld b, a ld a, [H_QUOTIENT + 3] @@ -339,9 +339,9 @@ BoostExp: ; 5549f (15:549f) ld [H_QUOTIENT + 2], a ret -GainedText: ; 554b2 (15:54b2) +GainedText: TX_FAR _GainedText - db $08 ; asm + TX_ASM ld a, [wBoostExpByExpAll] ld hl, WithExpAllText and a @@ -353,20 +353,20 @@ GainedText: ; 554b2 (15:54b2) ld hl, BoostedText ret -WithExpAllText: ; 554cb (15:54cb) +WithExpAllText: TX_FAR _WithExpAllText - db $08 ; asm + TX_ASM ld hl, ExpPointsText ret -BoostedText: ; 554d4 (15:54d4) +BoostedText: TX_FAR _BoostedText -ExpPointsText: ; 554d8 (15:54d8) +ExpPointsText: TX_FAR _ExpPointsText db "@" -GrewLevelText: ; 554dd (15:54dd) +GrewLevelText: TX_FAR _GrewLevelText - db $0b + TX_SFX_LEVEL_UP db "@" diff --git a/engine/battle/get_trainer_name.asm b/engine/battle/get_trainer_name.asm index 961f25cf..36ca019e 100644 --- a/engine/battle/get_trainer_name.asm +++ b/engine/battle/get_trainer_name.asm @@ -1,16 +1,16 @@ -GetTrainerName_: ; 13a58 (4:7a58) - ld hl, W_GRASSRATE +GetTrainerName_: + ld hl, wGrassRate ld a, [wLinkState] and a - jr nz, .rival - ld hl, W_RIVALNAME - ld a, [W_TRAINERCLASS] + jr nz, .foundName + ld hl, wRivalName + ld a, [wTrainerClass] cp SONY1 - jr z, .rival + jr z, .foundName cp SONY2 - jr z, .rival + jr z, .foundName cp SONY3 - jr z, .rival + jr z, .foundName ld [wd0b5], a ld a, TRAINER_NAME ld [wNameListType], a @@ -18,7 +18,7 @@ GetTrainerName_: ; 13a58 (4:7a58) ld [wPredefBank], a call GetName ld hl, wcd6d -.rival - ld de, W_TRAINERNAME +.foundName + ld de, wTrainerName ld bc, $d jp CopyData diff --git a/engine/battle/ghost_marowak_anim.asm b/engine/battle/ghost_marowak_anim.asm index 73d3bcc2..7adb20d8 100644 --- a/engine/battle/ghost_marowak_anim.asm +++ b/engine/battle/ghost_marowak_anim.asm @@ -1,21 +1,21 @@ -MarowakAnim: ; 708ca (1c:48ca) +MarowakAnim: ; animate the ghost being unveiled as a Marowak ld a, $e4 ld [rOBP1], a 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 - hlCoord 12, 0 - ld bc, $707 + coord hl, 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 ; replace ghost pic with Marowak in BG ld a, MAROWAK - ld [wHPBarMaxHP], a + ld [wChangeMonPicEnemyTurnSpecies], a ld a, $1 ld [H_WHOSETURN], a - callab Func_79793 + callab ChangeMonPic ; alternate between black and light grey 8 times. ; this makes the ghost's body appear to flash ld d, $80 @@ -49,28 +49,28 @@ MarowakAnim: ; 708ca (1c:48ca) jp ClearSprites ; copies a mon pic's from background VRAM to sprite VRAM and sets up OAM -CopyMonPicFromBGToSpriteVRAM: ; 7092a (1c:492a) +CopyMonPicFromBGToSpriteVRAM: ld de, vFrontPic ld hl, vSprites ld bc, 7 * 7 call CopyVideoData ld a, $10 - ld [W_BASECOORDY], a + ld [wBaseCoordY], a ld a, $70 - ld [W_BASECOORDX], a + ld [wBaseCoordX], a ld hl, wOAMBuffer - ld bc, $606 + lb bc, 6, 6 ld d, $8 .oamLoop push bc - ld a, [W_BASECOORDY] + ld a, [wBaseCoordY] ld e, a .oamInnerLoop ld a, e add $8 ld e, a ld [hli], a - ld a, [W_BASECOORDX] + ld a, [wBaseCoordX] ld [hli], a ld a, d ld [hli], a @@ -80,9 +80,9 @@ CopyMonPicFromBGToSpriteVRAM: ; 7092a (1c:492a) dec c jr nz, .oamInnerLoop inc d - ld a, [W_BASECOORDX] + ld a, [wBaseCoordX] add $8 - ld [W_BASECOORDX], a + ld [wBaseCoordX], a pop bc dec b jr nz, .oamLoop diff --git a/engine/battle/init_battle_variables.asm b/engine/battle/init_battle_variables.asm index 457cc4e1..bdd5d8f4 100644 --- a/engine/battle/init_battle_variables.asm +++ b/engine/battle/init_battle_variables.asm @@ -1,10 +1,10 @@ -InitBattleVariables: ; 525af (14:65af) +InitBattleVariables: ld a, [hTilesetType] - ld [wd0d4], a + ld [wSavedTilesetType], a xor a - ld [wcd6a], a + ld [wActionResultOrTookBattleTurn], a ld [wBattleResult], a - ld hl, wcc2b + ld hl, wPartyAndBillsPCSavedMenuItem ld [hli], a ld [hli], a ld [hli], a @@ -13,28 +13,26 @@ InitBattleVariables: ; 525af (14:65af) ld [wCriticalHitOrOHKO], a ld [wBattleMonSpecies], a ld [wPartyGainExpFlags], a - ld [wPlayerMonNumber], a + ld [wPlayerMonNumber], a ld [wEscapedFromBattle], a ld [wMapPalOffset], a - ld hl, wcf1d - ld [hli], a - ld [hl], a - ld hl, wccd3 + ld hl, wPlayerHPBarColor + ld [hli], a ; wPlayerHPBarColor + ld [hl], a ; wEnemyHPBarColor + ld hl, wCanEvolveFlags ld b, $3c .loop ld [hli], a dec b jr nz, .loop - inc a - ld [wccd9], a - ld a, [W_CURMAP] + inc a ; POUND + ld [wTestBattlePlayerSelectedMove], a + ld a, [wCurMap] cp SAFARI_ZONE_EAST jr c, .notSafariBattle cp SAFARI_ZONE_REST_HOUSE_1 jr nc, .notSafariBattle - ld a, $2 ; safari battle - ld [W_BATTLETYPE], a + ld a, BATTLE_TYPE_SAFARI + ld [wBattleType], a .notSafariBattle - ld hl, PlayBattleMusic - ld b, BANK(PlayBattleMusic) - jp Bankswitch + jpab PlayBattleMusic diff --git a/engine/battle/link_battle_versus_text.asm b/engine/battle/link_battle_versus_text.asm index 7320da29..76559117 100644 --- a/engine/battle/link_battle_versus_text.asm +++ b/engine/battle/link_battle_versus_text.asm @@ -1,18 +1,18 @@ ; display "[player] VS [enemy]" text box with pokeballs representing their parties next to the names -DisplayLinkBattleVersusTextBox: ; 372d6 (d:72d6) +DisplayLinkBattleVersusTextBox: call LoadTextBoxTilePatterns - hlCoord 3, 4 - ld b, $7 - ld c, $c + coord hl, 3, 4 + ld b, 7 + ld c, 12 call TextBoxBorder - hlCoord 4, 5 + coord hl, 4, 5 ld de, wPlayerName call PlaceString - hlCoord 4, 10 + coord hl, 4, 10 ld de, wLinkEnemyTrainerName call PlaceString ; place bold "VS" tiles between the names - hlCoord 9, 8 + coord hl, 9, 8 ld a, $69 ld [hli], a ld [hl], $6a diff --git a/engine/battle/moveEffects/conversion_effect.asm b/engine/battle/moveEffects/conversion_effect.asm index 511df2fd..9c347876 100644 --- a/engine/battle/moveEffects/conversion_effect.asm +++ b/engine/battle/moveEffects/conversion_effect.asm @@ -1,18 +1,19 @@ -ConversionEffect_: ; 139a3 (4:79a3) +ConversionEffect_: ld hl, wEnemyMonType1 ld de, wBattleMonType1 ld a, [H_WHOSETURN] and a - ld a, [W_ENEMYBATTSTATUS1] - jr z, .asm_139b8 + ld a, [wEnemyBattleStatus1] + jr z, .conversionEffect push hl ld h, d ld l, e pop de - ld a, [W_PLAYERBATTSTATUS1] -.asm_139b8 + ld a, [wPlayerBattleStatus1] +.conversionEffect bit Invulnerable, a ; is mon immune to typical attacks (dig/fly) jr nz, PrintButItFailedText +; copy target's types to user ld a, [hli] ld [de], a inc de @@ -23,12 +24,12 @@ ConversionEffect_: ; 139a3 (4:79a3) ld hl, ConvertedTypeText jp PrintText -ConvertedTypeText: ; 139cd (4:79cd) +ConvertedTypeText: TX_FAR _ConvertedTypeText db "@" -PrintButItFailedText: ; 139d2 (4:79d2) +PrintButItFailedText: ld hl, PrintButItFailedText_ -CallBankF: ; 139d5 (4:79d5) +CallBankF: ld b, BANK(PrintButItFailedText_) jp Bankswitch diff --git a/engine/battle/moveEffects/drain_hp_effect.asm b/engine/battle/moveEffects/drain_hp_effect.asm index 517d53d1..e5f4681a 100644 --- a/engine/battle/moveEffects/drain_hp_effect.asm +++ b/engine/battle/moveEffects/drain_hp_effect.asm @@ -1,5 +1,5 @@ -DrainHPEffect_: ; 783f (1:783f) - ld hl, W_DAMAGE +DrainHPEffect_: + ld hl, wDamage ld a, [hl] srl a ; divide damage by 2 ld [hli], a @@ -17,8 +17,8 @@ DrainHPEffect_: ; 783f (1:783f) ld a, [H_WHOSETURN] and a jp z, .addDamageToAttackerHP - ld hl, wEnemyMonHP - ld de, wEnemyMonMaxHP + ld hl, wEnemyMonHP + ld de, wEnemyMonMaxHP .addDamageToAttackerHP ld bc, wHPBarOldHP+1 ; copy current HP to wHPBarOldHP @@ -36,12 +36,12 @@ DrainHPEffect_: ; 783f (1:783f) dec bc ld [bc], a ; add damage to attacker's HP and copy new HP to wHPBarNewHP - ld a, [W_DAMAGE + 1] + ld a, [wDamage + 1] ld b, [hl] add b ld [hld], a ld [wHPBarNewHP], a - ld a, [W_DAMAGE] + ld a, [wDamage] ld b, [hl] adc b ld [hli], a @@ -71,10 +71,10 @@ DrainHPEffect_: ; 783f (1:783f) .next ld a, [H_WHOSETURN] and a - hlCoord 10, 9 + coord hl, 10, 9 ld a, $1 jr z, .next2 - hlCoord 2, 2 + coord hl, 2, 2 xor a .next2 ld [wHPBarType], a @@ -85,9 +85,9 @@ DrainHPEffect_: ; 783f (1:783f) ld hl, SuckedHealthText ld a, [H_WHOSETURN] and a - ld a, [W_PLAYERMOVEEFFECT] + ld a, [wPlayerMoveEffect] jr z, .next3 - ld a, [W_ENEMYMOVEEFFECT] + ld a, [wEnemyMoveEffect] .next3 cp DREAM_EATER_EFFECT jr nz, .printText @@ -95,10 +95,10 @@ DrainHPEffect_: ; 783f (1:783f) .printText jp PrintText -SuckedHealthText: ; 78dc (1:78dc) +SuckedHealthText: TX_FAR _SuckedHealthText db "@" -DreamWasEatenText: ; 78e1 (1:78e1) +DreamWasEatenText: TX_FAR _DreamWasEatenText db "@" diff --git a/engine/battle/moveEffects/focus_energy_effect.asm b/engine/battle/moveEffects/focus_energy_effect.asm index f01e61cc..69301d8e 100644 --- a/engine/battle/moveEffects/focus_energy_effect.asm +++ b/engine/battle/moveEffects/focus_energy_effect.asm @@ -1,9 +1,9 @@ -FocusEnergyEffect_: ; 27f86 (9:7f86) - ld hl, W_PLAYERBATTSTATUS2 +FocusEnergyEffect_: + ld hl, wPlayerBattleStatus2 ld a, [H_WHOSETURN] and a jr z, .notEnemy - ld hl, W_ENEMYBATTSTATUS2 + ld hl, wEnemyBattleStatus2 .notEnemy bit GettingPumped, [hl] ; is mon already using focus energy? jr nz, .alreadyUsing @@ -12,13 +12,11 @@ FocusEnergyEffect_: ; 27f86 (9:7f86) ld hl, GettingPumpedText jp PrintText .alreadyUsing - ld c, $32 + ld c, 50 call DelayFrames - ld hl, PrintButItFailedText_ - ld b, BANK(PrintButItFailedText_) - jp Bankswitch + jpab PrintButItFailedText_ -GettingPumpedText: ; 27fb3 (9:7fb3) - db $0a +GettingPumpedText: + TX_DELAY TX_FAR _GettingPumpedText db "@" diff --git a/engine/battle/moveEffects/haze_effect.asm b/engine/battle/moveEffects/haze_effect.asm index 2343e784..06907bcc 100644 --- a/engine/battle/moveEffects/haze_effect.asm +++ b/engine/battle/moveEffects/haze_effect.asm @@ -1,59 +1,64 @@ -HazeEffect_: ; 139da (4:79da) +HazeEffect_: ld a, $7 +; store 7 on every stat mod ld hl, wPlayerMonAttackMod call ResetStatMods ld hl, wEnemyMonAttackMod call ResetStatMods +; copy unmodified stats to battle stats ld hl, wPlayerMonUnmodifiedAttack ld de, wBattleMonAttack call ResetStats ld hl, wEnemyMonUnmodifiedAttack ld de, wEnemyMonAttack call ResetStats +; cure non-volatile status, but only for the target ld hl, wEnemyMonStatus ld de, wEnemySelectedMove ld a, [H_WHOSETURN] and a - jr z, .asm_13a09 + jr z, .cureStatuses ld hl, wBattleMonStatus - dec de + dec de ; wPlayerSelectedMove -.asm_13a09 +.cureStatuses ld a, [hl] ld [hl], $0 - and $27 - jr z, .asm_13a13 + and SLP | (1 << FRZ) + jr z, .cureVolatileStatuses +; prevent the Pokemon from executing a move if it was asleep or frozen ld a, $ff ld [de], a -.asm_13a13 +.cureVolatileStatuses xor a - ld [W_PLAYERDISABLEDMOVE], a - ld [W_ENEMYDISABLEDMOVE], a - ld hl, wccee + ld [wPlayerDisabledMove], a + ld [wEnemyDisabledMove], a + ld hl, wPlayerDisabledMoveNumber ld [hli], a ld [hl], a - ld hl, W_PLAYERBATTSTATUS1 - call CureStatuses - ld hl, W_ENEMYBATTSTATUS1 - call CureStatuses + ld hl, wPlayerBattleStatus1 + call CureVolatileStatuses + ld hl, wEnemyBattleStatus1 + call CureVolatileStatuses ld hl, PlayCurrentMoveAnimation call CallBankF ld hl, StatusChangesEliminatedText jp PrintText -CureStatuses: ; 13a37 (4:7a37) +CureVolatileStatuses: res Confused, [hl] inc hl ; BATTSTATUS2 ld a, [hl] - and (1 << UsingRage) | (1 << NeedsToRecharge) | (1 << HasSubstituteUp) | (1 << 3) ; clear all but these from BATTSTATUS2 + ; clear UsingXAccuracy, ProtectedByMist, GettingPumped, and Seeded statuses + and $ff ^((1 << UsingXAccuracy) | (1 << ProtectedByMist) | (1 << GettingPumped) | (1 << Seeded)) ld [hli], a ; BATTSTATUS3 ld a, [hl] and %11110000 | (1 << Transformed) ; clear Bad Poison, Reflect and Light Screen statuses ld [hl], a ret -ResetStatMods: ; 13a43 (4:7a43) +ResetStatMods: ld b, $8 .loop ld [hli], a @@ -61,7 +66,7 @@ ResetStatMods: ; 13a43 (4:7a43) jr nz, .loop ret -ResetStats: ; 13a4a (4:7a4a) +ResetStats: ld b, $8 .loop ld a, [hli] @@ -71,6 +76,6 @@ ResetStats: ; 13a4a (4:7a4a) jr nz, .loop ret -StatusChangesEliminatedText: ; 13a53 (4:7a53) +StatusChangesEliminatedText: TX_FAR _StatusChangesEliminatedText db "@" diff --git a/engine/battle/moveEffects/heal_effect.asm b/engine/battle/moveEffects/heal_effect.asm index 22d482e7..b7d8283f 100644 --- a/engine/battle/moveEffects/heal_effect.asm +++ b/engine/battle/moveEffects/heal_effect.asm @@ -1,25 +1,26 @@ -HealEffect_: ; 3b9ec (e:79ec) +HealEffect_: ld a, [H_WHOSETURN] and a ld de, wBattleMonHP ld hl, wBattleMonMaxHP - ld a, [W_PLAYERMOVENUM] - jr z, .asm_3ba03 + ld a, [wPlayerMoveNum] + jr z, .healEffect ld de, wEnemyMonHP ld hl, wEnemyMonMaxHP - ld a, [W_ENEMYMOVENUM] -.asm_3ba03 + ld a, [wEnemyMoveNum] +.healEffect ld b, a ld a, [de] - cp [hl] + cp [hl] ; most significant bytes comparison is ignored + ; causes the move to miss if max HP is 255 or 511 points higher than the current HP inc de inc hl ld a, [de] sbc [hl] - jp z, .failed + jp z, .failed ; no effect if user's HP is already at its maximum ld a, b cp REST - jr nz, .asm_3ba37 + jr nz, .healHP push hl push de push af @@ -28,31 +29,33 @@ HealEffect_: ; 3b9ec (e:79ec) ld hl, wBattleMonStatus ld a, [H_WHOSETURN] and a - jr z, .asm_3ba25 + jr z, .restEffect ld hl, wEnemyMonStatus -.asm_3ba25 +.restEffect ld a, [hl] and a - ld [hl], 2 ; Number of turns from Rest - ld hl, StartedSleepingEffect - jr z, .asm_3ba31 - ld hl, FellAsleepBecameHealthyText -.asm_3ba31 + ld [hl], 2 ; clear status and set number of turns asleep to 2 + ld hl, StartedSleepingEffect ; if mon didn't have an status + jr z, .printRestText + ld hl, FellAsleepBecameHealthyText ; if mon had an status +.printRestText call PrintText pop af pop de pop hl -.asm_3ba37 +.healHP ld a, [hld] ld [wHPBarMaxHP], a ld c, a ld a, [hl] ld [wHPBarMaxHP+1], a ld b, a - jr z, .asm_3ba47 + jr z, .gotHPAmountToHeal +; Recover and Softboiled only heal for half the mon's max HP srl b rr c -.asm_3ba47 +.gotHPAmountToHeal +; update HP ld a, [de] ld [wHPBarOldHP], a add c @@ -72,7 +75,8 @@ HealEffect_: ; 3b9ec (e:79ec) dec hl ld a, [de] sbc [hl] - jr c, .asm_3ba6f + jr c, .playAnim +; copy max HP to current HP if an overflow ocurred ld a, [hli] ld [de], a ld [wHPBarNewHP+1], a @@ -80,17 +84,17 @@ HealEffect_: ; 3b9ec (e:79ec) ld a, [hl] ld [de], a ld [wHPBarNewHP], a -.asm_3ba6f +.playAnim ld hl, PlayCurrentMoveAnimation call BankswitchEtoF ld a, [H_WHOSETURN] and a - hlCoord 10, 9 + coord hl, 10, 9 ld a, $1 - jr z, .asm_3ba83 - hlCoord 2, 2 + jr z, .updateHPBar + coord hl, 2, 2 xor a -.asm_3ba83 +.updateHPBar ld [wHPBarType], a predef UpdateHPBar2 ld hl, DrawHUDsAndHPBars @@ -103,14 +107,14 @@ HealEffect_: ; 3b9ec (e:79ec) ld hl, PrintButItFailedText_ jp BankswitchEtoF -StartedSleepingEffect: ; 3baa2 (e:7aa2) +StartedSleepingEffect: TX_FAR _StartedSleepingEffect db "@" -FellAsleepBecameHealthyText: ; 3baa7 (e:7aa7) +FellAsleepBecameHealthyText: TX_FAR _FellAsleepBecameHealthyText db "@" -RegainedHealthText: ; 3baac (e:7aac) +RegainedHealthText: TX_FAR _RegainedHealthText db "@" diff --git a/engine/battle/moveEffects/leech_seed_effect.asm b/engine/battle/moveEffects/leech_seed_effect.asm index a257d143..0f3a2666 100644 --- a/engine/battle/moveEffects/leech_seed_effect.asm +++ b/engine/battle/moveEffects/leech_seed_effect.asm @@ -1,39 +1,40 @@ -LeechSeedEffect_: ; 2bea9 (a:7ea9) +LeechSeedEffect_: callab MoveHitTest - ld a, [W_MOVEMISSED] ; W_MOVEMISSED + ld a, [wMoveMissed] and a - jr nz, .asm_2bee7 - ld hl, W_ENEMYBATTSTATUS2 ; W_ENEMYBATTSTATUS2 - ld de, wEnemyMonType1 ; wcfea (aliases: wEnemyMonType) - ld a, [H_WHOSETURN] ; $fff3 + jr nz, .moveMissed + ld hl, wEnemyBattleStatus2 + ld de, wEnemyMonType1 + ld a, [H_WHOSETURN] and a - jr z, .asm_2bec8 - ld hl, W_PLAYERBATTSTATUS2 ; W_PLAYERBATTSTATUS2 - ld de, wBattleMonType1 ; wd019 (aliases: wBattleMonType) -.asm_2bec8 + jr z, .leechSeedEffect + ld hl, wPlayerBattleStatus2 + ld de, wBattleMonType1 +.leechSeedEffect +; miss if the target is grass-type or already seeded ld a, [de] cp GRASS - jr z, .asm_2bee7 + jr z, .moveMissed inc de ld a, [de] cp GRASS - jr z, .asm_2bee7 + jr z, .moveMissed bit Seeded, [hl] - jr nz, .asm_2bee7 + jr nz, .moveMissed set Seeded, [hl] callab PlayCurrentMoveAnimation - ld hl, WasSeededText ; $7ef2 + ld hl, WasSeededText jp PrintText -.asm_2bee7 - ld c, $32 +.moveMissed + ld c, 50 call DelayFrames - ld hl, EvadedAttackText ; $7ef7 + ld hl, EvadedAttackText jp PrintText -WasSeededText: ; 2bef2 (a:7ef2) +WasSeededText: TX_FAR _WasSeededText db "@" -EvadedAttackText: ; 2bef7 (a:7ef7) +EvadedAttackText: TX_FAR _EvadedAttackText db "@" diff --git a/engine/battle/moveEffects/mist_effect.asm b/engine/battle/moveEffects/mist_effect.asm index adee1dfd..b92777de 100644 --- a/engine/battle/moveEffects/mist_effect.asm +++ b/engine/battle/moveEffects/mist_effect.asm @@ -1,21 +1,19 @@ -MistEffect_: ; 33f2b (c:7f2b) - ld hl, W_PLAYERBATTSTATUS2 - ld a, [$fff3] +MistEffect_: + ld hl, wPlayerBattleStatus2 + ld a, [H_WHOSETURN] and a - jr z, .asm_33f36 - ld hl, W_ENEMYBATTSTATUS2 -.asm_33f36 + jr z, .mistEffect + ld hl, wEnemyBattleStatus2 +.mistEffect bit ProtectedByMist, [hl] ; is mon protected by mist? - jr nz, .asm_33f4a + jr nz, .mistAlreadyInUse set ProtectedByMist, [hl] ; mon is now protected by mist callab PlayCurrentMoveAnimation ld hl, ShroudedInMistText jp PrintText -.asm_33f4a - ld hl, PrintButItFailedText_ - ld b, BANK(PrintButItFailedText_) - jp Bankswitch +.mistAlreadyInUse + jpab PrintButItFailedText_ -ShroudedInMistText: ; 33f52 (c:7f52) +ShroudedInMistText: TX_FAR _ShroudedInMistText db "@" diff --git a/engine/battle/moveEffects/one_hit_ko_effect.asm b/engine/battle/moveEffects/one_hit_ko_effect.asm index 84418e33..827e2197 100644 --- a/engine/battle/moveEffects/one_hit_ko_effect.asm +++ b/engine/battle/moveEffects/one_hit_ko_effect.asm @@ -1,5 +1,5 @@ -OneHitKOEffect_: ; 33f57 (c:7f57) - ld hl, W_DAMAGE +OneHitKOEffect_: + ld hl, wDamage xor a ld [hli], a ld [hl], a ; set the damage output to zero @@ -7,12 +7,13 @@ OneHitKOEffect_: ; 33f57 (c:7f57) ld [wCriticalHitOrOHKO], a ld hl, wBattleMonSpeed + 1 ld de, wEnemyMonSpeed + 1 - ld a, [H_WHOSETURN] ; $fff3 + ld a, [H_WHOSETURN] and a - jr z, .asm_33f72 + jr z, .compareSpeed ld hl, wEnemyMonSpeed + 1 ld de, wBattleMonSpeed + 1 -.asm_33f72 +.compareSpeed +; set damage to 65535 and OHKO flag is the user's current speed is higher than the target's ld a, [de] dec de ld b, a @@ -22,15 +23,16 @@ OneHitKOEffect_: ; 33f57 (c:7f57) ld b, a ld a, [hl] sbc b - jr c, .asm_33f8a - ld hl, W_DAMAGE + jr c, .userIsSlower + ld hl, wDamage ld a, $ff ld [hli], a ld [hl], a ld a, $2 ld [wCriticalHitOrOHKO], a ret -.asm_33f8a +.userIsSlower +; keep damage at 0 and set move missed flag if target's current speed is higher instead ld a, $1 - ld [W_MOVEMISSED], a + ld [wMoveMissed], a ret diff --git a/engine/battle/moveEffects/paralyze_effect.asm b/engine/battle/moveEffects/paralyze_effect.asm index 69acbb01..95979ae6 100644 --- a/engine/battle/moveEffects/paralyze_effect.asm +++ b/engine/battle/moveEffects/paralyze_effect.asm @@ -1,11 +1,11 @@ -ParalyzeEffect_: ; 52601 (14:6601) +ParalyzeEffect_: ld hl, wEnemyMonStatus - ld de, W_PLAYERMOVETYPE + ld de, wPlayerMoveType ld a, [H_WHOSETURN] and a jp z, .next - ld hl, wBattleMonStatus - ld de, W_ENEMYMOVETYPE + ld hl, wBattleMonStatus + ld de, wEnemyMoveType .next ld a, [hl] and a ; does the target already have a status ailment? @@ -28,7 +28,7 @@ ParalyzeEffect_: ; 52601 (14:6601) push hl callab MoveHitTest pop hl - ld a, [W_MOVEMISSED] + ld a, [wMoveMissed] and a jr nz, .didntAffect set PAR, [hl] @@ -36,18 +36,12 @@ ParalyzeEffect_: ; 52601 (14:6601) ld c, 30 call DelayFrames callab PlayCurrentMoveAnimation - ld hl, PrintMayNotAttackText - ld b, BANK(PrintMayNotAttackText) - jp Bankswitch + jpab PrintMayNotAttackText .didntAffect ld c, 50 call DelayFrames - ld hl, PrintDidntAffectText - ld b, BANK(PrintDidntAffectText) - jp Bankswitch + jpab PrintDidntAffectText .doesntAffect ld c, 50 call DelayFrames - ld hl, PrintDoesntAffectText - ld b, BANK(PrintDoesntAffectText) - jp Bankswitch + jpab PrintDoesntAffectText diff --git a/engine/battle/moveEffects/pay_day_effect.asm b/engine/battle/moveEffects/pay_day_effect.asm index 75a005ed..e5daf014 100644 --- a/engine/battle/moveEffects/pay_day_effect.asm +++ b/engine/battle/moveEffects/pay_day_effect.asm @@ -1,20 +1,22 @@ -PayDayEffect_ ; 2feb8 (b:7eb8) +PayDayEffect_: xor a ld hl, wcd6d ld [hli], a ld a, [H_WHOSETURN] and a ld a, [wBattleMonLevel] - jr z, .asm_2fec8 + jr z, .payDayEffect ld a, [wEnemyMonLevel] -.asm_2fec8 +.payDayEffect +; level * 2 add a ld [H_DIVIDEND + 3], a xor a ld [H_DIVIDEND], a ld [H_DIVIDEND + 1], a ld [H_DIVIDEND + 2], a - ld a, $64 +; convert to BCD + ld a, 100 ld [H_DIVISOR], a ld b, $4 call Divide @@ -22,7 +24,7 @@ PayDayEffect_ ; 2feb8 (b:7eb8) ld [hli], a ld a, [H_REMAINDER] ld [H_DIVIDEND + 3], a - ld a, $a + ld a, 10 ld [H_DIVISOR], a ld b, $4 call Divide @@ -38,6 +40,6 @@ PayDayEffect_ ; 2feb8 (b:7eb8) ld hl, CoinsScatteredText jp PrintText -CoinsScatteredText: ; 2ff04 (b:7f04) +CoinsScatteredText: TX_FAR _CoinsScatteredText db "@" diff --git a/engine/battle/moveEffects/recoil_effect.asm b/engine/battle/moveEffects/recoil_effect.asm index 0460b208..7fc90c44 100644 --- a/engine/battle/moveEffects/recoil_effect.asm +++ b/engine/battle/moveEffects/recoil_effect.asm @@ -1,36 +1,37 @@ -RecoilEffect_: ; 1392c (4:792c) +RecoilEffect_: ld a, [H_WHOSETURN] and a - ld a, [W_PLAYERMOVENUM] + ld a, [wPlayerMoveNum] ld hl, wBattleMonMaxHP - jr z, .asm_1393d - ld a, [W_ENEMYMOVENUM] + jr z, .recoilEffect + ld a, [wEnemyMoveNum] ld hl, wEnemyMonMaxHP -.asm_1393d +.recoilEffect ld d, a - ld a, [W_DAMAGE] + ld a, [wDamage] ld b, a - ld a, [W_DAMAGE + 1] + ld a, [wDamage + 1] ld c, a srl b rr c ld a, d - cp STRUGGLE - jr z, .asm_13953 + cp STRUGGLE ; struggle deals 50% recoil damage + jr z, .gotRecoilDamage srl b rr c -.asm_13953 +.gotRecoilDamage ld a, b or c - jr nz, .asm_13958 - inc c -.asm_13958 + jr nz, .updateHP + inc c ; minimum recoil damage is 1 +.updateHP +; substract HP from user due to the recoil damage ld a, [hli] ld [wHPBarMaxHP+1], a ld a, [hl] ld [wHPBarMaxHP], a push bc - ld bc, $fff2 + ld bc, wBattleMonHP - wBattleMonMaxHP add hl, bc pop bc ld a, [hl] @@ -43,26 +44,27 @@ RecoilEffect_: ; 1392c (4:792c) sbc b ld [hl], a ld [wHPBarNewHP+1], a - jr nc, .asm_13982 + jr nc, .getHPBarCoords +; if recoil damage is higher than the Pokemon's HP, set its HP to 0 xor a ld [hli], a ld [hl], a ld hl, wHPBarNewHP ld [hli], a ld [hl], a -.asm_13982 - hlCoord 10, 9 +.getHPBarCoords + coord hl, 10, 9 ld a, [H_WHOSETURN] and a ld a, $1 - jr z, .asm_13990 - hlCoord 2, 2 + jr z, .updateHPBar + coord hl, 2, 2 xor a -.asm_13990 +.updateHPBar ld [wHPBarType], a predef UpdateHPBar2 ld hl, HitWithRecoilText jp PrintText -HitWithRecoilText: ; 1399e (4:799e) +HitWithRecoilText: TX_FAR _HitWithRecoilText db "@" diff --git a/engine/battle/moveEffects/reflect_light_screen_effect.asm b/engine/battle/moveEffects/reflect_light_screen_effect.asm index 39a2c154..b45fbe20 100644 --- a/engine/battle/moveEffects/reflect_light_screen_effect.asm +++ b/engine/battle/moveEffects/reflect_light_screen_effect.asm @@ -1,12 +1,12 @@ -ReflectLightScreenEffect_: ; 3bb97 (e:7b97) - ld hl, W_PLAYERBATTSTATUS3 - ld de, W_PLAYERMOVEEFFECT +ReflectLightScreenEffect_: + ld hl, wPlayerBattleStatus3 + ld de, wPlayerMoveEffect ld a, [H_WHOSETURN] and a - jr z, .asm_3bba8 - ld hl, W_ENEMYBATTSTATUS3 - ld de, W_ENEMYMOVEEFFECT -.asm_3bba8 + jr z, .reflectLightScreenEffect + ld hl, wEnemyBattleStatus3 + ld de, wEnemyMoveEffect +.reflectLightScreenEffect ld a, [de] cp LIGHT_SCREEN_EFFECT jr nz, .reflect @@ -14,32 +14,32 @@ ReflectLightScreenEffect_: ; 3bb97 (e:7b97) jr nz, .moveFailed set HasLightScreenUp, [hl] ; mon is now protected by light screen ld hl, LightScreenProtectedText - jr .asm_3bbc1 + jr .playAnim .reflect bit HasReflectUp, [hl] ; is mon already protected by reflect? jr nz, .moveFailed set HasReflectUp, [hl] ; mon is now protected by reflect ld hl, ReflectGainedArmorText -.asm_3bbc1 +.playAnim push hl ld hl, PlayCurrentMoveAnimation call BankswitchEtoF pop hl jp PrintText .moveFailed - ld c, $32 + ld c, 50 call DelayFrames ld hl, PrintButItFailedText_ jp BankswitchEtoF -LightScreenProtectedText: ; 3bbd7 (e:7bd7) +LightScreenProtectedText: TX_FAR _LightScreenProtectedText db "@" -ReflectGainedArmorText: ; 3bbdc (e:7bdc) +ReflectGainedArmorText: TX_FAR _ReflectGainedArmorText db "@" -BankswitchEtoF: ; 3bbe1 (e:7be1) +BankswitchEtoF: ld b, BANK(BattleCore) jp Bankswitch diff --git a/engine/battle/moveEffects/substitute_effect.asm b/engine/battle/moveEffects/substitute_effect.asm index e88def4a..03314ebf 100644 --- a/engine/battle/moveEffects/substitute_effect.asm +++ b/engine/battle/moveEffects/substitute_effect.asm @@ -1,61 +1,61 @@ -SubstituteEffect_: ; 17dad (5:7dad) +SubstituteEffect_: ld c, 50 call DelayFrames ld hl, wBattleMonMaxHP ld de, wPlayerSubstituteHP - ld bc, W_PLAYERBATTSTATUS2 + ld bc, wPlayerBattleStatus2 ld a, [H_WHOSETURN] and a jr z, .notEnemy ld hl, wEnemyMonMaxHP ld de, wEnemySubstituteHP - ld bc, W_ENEMYBATTSTATUS2 + ld bc, wEnemyBattleStatus2 .notEnemy - ld a, [bc] ;load flags - bit HasSubstituteUp, a ;user already has substitute? - jr nz, .alreadyHasSubstitute ;skip this code if so - ;user doesn't have a substitute [yet] + ld a, [bc] + bit HasSubstituteUp, a ; user already has substitute? + jr nz, .alreadyHasSubstitute +; quarter health to remove from user +; assumes max HP is 1023 or lower push bc - ld a, [hli] ;load max hp + ld a, [hli] ld b, [hl] - srl a ;max hp / 4, [quarter health to remove from user] - rr b srl a rr b + srl a + rr b ; max hp / 4 push de ld de, wBattleMonHP - wBattleMonMaxHP - add hl, de ; point hl to current HP + 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 a, [hld] ;load current hp - sub b ;subtract [max hp / 4] - ld d, a ;save low byte result in D + ld [de], a ; save copy of HP to subtract in ccd7/ccd8 [how much HP substitute has] + ld a, [hld] +; subtract [max hp / 4] to current HP + sub b + ld d, a ld a, [hl] - sbc a, 0 ;borrow from high byte if needed + sbc 0 pop bc - jr c, .notEnoughHP ;underflow means user would be left with negative health - ;bug: note since it only brances on carry, it will possibly leave user with 0HP + jr c, .notEnoughHP ; underflow means user would be left with negative health + ; bug: since it only brances on carry, it will possibly leave user with 0 HP .userHasZeroOrMoreHP - ldi [hl], a ;store high byte HP - ld [hl], d ;store low byte HP + ldi [hl], a ; save resulting HP after substraction into current HP + ld [hl], d ld h, b ld l, c - set HasSubstituteUp, [hl] ;set bit 4 of flags, user now has substitute - ld a, [W_OPTIONS] ;load options - bit 7, a ;battle animation is enabled? - ld hl, PlayCurrentMoveAnimation ;animation enabled: 0F:7BA8 + set HasSubstituteUp, [hl] + ld a, [wOptions] + bit 7, a ; battle animation is enabled? + ld hl, PlayCurrentMoveAnimation ld b, BANK(PlayCurrentMoveAnimation) jr z, .animationEnabled - ld hl, AnimationSubstitute ;animation disabled: 1E:56E0 + ld hl, AnimationSubstitute ld b, BANK(AnimationSubstitute) .animationEnabled - call Bankswitch ;jump to routine depending on animation setting + call Bankswitch ; jump to routine depending on animation setting ld hl, SubstituteText call PrintText - ld hl, DrawHUDsAndHPBars - ld b, BANK(DrawHUDsAndHPBars) - jp Bankswitch + jpab DrawHUDsAndHPBars .alreadyHasSubstitute ld hl, HasSubstituteText jr .printText @@ -64,14 +64,14 @@ SubstituteEffect_: ; 17dad (5:7dad) .printText jp PrintText -SubstituteText: ; 17e1d (5:7e1d) +SubstituteText: TX_FAR _SubstituteText db "@" -HasSubstituteText: ; 17e22 (5:7e22) +HasSubstituteText: TX_FAR _HasSubstituteText db "@" -TooWeakSubstituteText: ; 17e27 (5:7e27) +TooWeakSubstituteText: TX_FAR _TooWeakSubstituteText db "@" diff --git a/engine/battle/moveEffects/transform_effect.asm b/engine/battle/moveEffects/transform_effect.asm index 6e25712a..45f8c910 100644 --- a/engine/battle/moveEffects/transform_effect.asm +++ b/engine/battle/moveEffects/transform_effect.asm @@ -1,55 +1,59 @@ -TransformEffect_: ; 3bab1 (e:7ab1) +TransformEffect_: ld hl, wBattleMonSpecies ld de, wEnemyMonSpecies - ld bc, W_ENEMYBATTSTATUS3 - ld a, [W_ENEMYBATTSTATUS1] + ld bc, wEnemyBattleStatus3 + ld a, [wEnemyBattleStatus1] ld a, [H_WHOSETURN] and a - jr nz, .asm_3bad1 + jr nz, .hitTest ld hl, wEnemyMonSpecies ld de, wBattleMonSpecies - ld bc, W_PLAYERBATTSTATUS3 + ld bc, wPlayerBattleStatus3 ld [wPlayerMoveListIndex], a - ld a, [W_PLAYERBATTSTATUS1] -.asm_3bad1 + ld a, [wPlayerBattleStatus1] +.hitTest bit Invulnerable, a ; is mon invulnerable to typical attacks? (fly/dig) jp nz, .failed push hl push de push bc - ld hl, W_PLAYERBATTSTATUS2 + ld hl, wPlayerBattleStatus2 ld a, [H_WHOSETURN] and a - jr z, .asm_3bae4 - ld hl, W_ENEMYBATTSTATUS2 -.asm_3bae4 + jr z, .transformEffect + ld hl, wEnemyBattleStatus2 +.transformEffect +; animation(s) played are different if target has Substitute up bit HasSubstituteUp, [hl] push af - ld hl, Func_79747 - ld b, BANK(Func_79747) + ld hl, HideSubstituteShowMonAnim + ld b, BANK(HideSubstituteShowMonAnim) call nz, Bankswitch - ld a, [W_OPTIONS] + ld a, [wOptions] add a ld hl, PlayCurrentMoveAnimation ld b, BANK(PlayCurrentMoveAnimation) - jr nc, .asm_3baff + jr nc, .gotAnimToPlay ld hl, AnimationTransformMon ld b, BANK(AnimationTransformMon) -.asm_3baff +.gotAnimToPlay call Bankswitch - ld hl, Func_79771 - ld b, BANK(Func_79771) + ld hl, ReshowSubstituteAnim + ld b, BANK(ReshowSubstituteAnim) pop af call nz, Bankswitch pop bc ld a, [bc] - set Transformed, a + set Transformed, a ; mon is now Transformed ld [bc], a pop de pop hl push hl +; transform user into opposing Pokemon +; species ld a, [hl] ld [de], a +; type 1, type 2, catch rate, and moves ld bc, $5 add hl, bc inc de @@ -62,20 +66,23 @@ TransformEffect_: ; 3bab1 (e:7ab1) call CopyData ld a, [H_WHOSETURN] and a - jr z, .asm_3bb32 + jr z, .next +; save enemy mon DVs at wTransformedEnemyMonOriginalDVs ld a, [de] - ld [wcceb], a + ld [wTransformedEnemyMonOriginalDVs], a inc de ld a, [de] - ld [wccec], a + ld [wTransformedEnemyMonOriginalDVs + 1], a dec de -.asm_3bb32 +.next +; DVs ld a, [hli] ld [de], a inc de ld a, [hli] ld [de], a inc de +; Attack, Defense, Speed, and Special stats inc hl inc hl inc hl @@ -84,48 +91,51 @@ TransformEffect_: ; 3bab1 (e:7ab1) inc de ld bc, $8 call CopyData - ld bc, $ffef - add hl, bc - ld b, $4 -.asm_3bb4a + ld bc, wBattleMonMoves - wBattleMonPP + add hl, bc ; ld hl, wBattleMonMoves + ld b, NUM_MOVES +.copyPPLoop +; 5 PP for all moves ld a, [hli] and a - jr z, .asm_3bb57 + jr z, .lessThanFourMoves ld a, $5 ld [de], a inc de dec b - jr nz, .asm_3bb4a - jr .asm_3bb5d -.asm_3bb57 + jr nz, .copyPPLoop + jr .copyStats +.lessThanFourMoves +; 0 PP for blank moves xor a ld [de], a inc de dec b - jr nz, .asm_3bb57 -.asm_3bb5d + jr nz, .lessThanFourMoves +.copyStats +; original (unmodified) stats and stat mods pop hl ld a, [hl] ld [wd11e], a call GetMonName ld hl, wEnemyMonUnmodifiedAttack ld de, wPlayerMonUnmodifiedAttack - call .copyBasedOnTurn + call .copyBasedOnTurn ; original (unmodified) stats ld hl, wEnemyMonStatMods ld de, wPlayerMonStatMods - call .copyBasedOnTurn + call .copyBasedOnTurn ; stat mods ld hl, TransformedText jp PrintText .copyBasedOnTurn ld a, [H_WHOSETURN] and a - jr z, .asm_3bb86 + jr z, .gotStatsOrModsToCopy push hl ld h, d ld l, e pop de -.asm_3bb86 +.gotStatsOrModsToCopy ld bc, $8 jp CopyData @@ -133,6 +143,6 @@ TransformEffect_: ; 3bab1 (e:7ab1) ld hl, PrintButItFailedText_ jp BankswitchEtoF -TransformedText: ; 3bb92 (e:7b92) +TransformedText: TX_FAR _TransformedText db "@" diff --git a/engine/battle/print_type.asm b/engine/battle/print_type.asm index 38c701a8..f717f871 100644 --- a/engine/battle/print_type.asm +++ b/engine/battle/print_type.asm @@ -1,16 +1,16 @@ ; [wd0b5] = pokemon ID ; hl = dest addr -PrintMonType: ; 27d6b (9:7d6b) +PrintMonType: call GetPredefRegisters push hl call GetMonHeader pop hl push hl - ld a, [W_MONHTYPE1] + ld a, [wMonHType1] call PrintType - ld a, [W_MONHTYPE1] + ld a, [wMonHType1] ld b, a - ld a, [W_MONHTYPE2] + ld a, [wMonHType2] cp b pop hl jr z, EraseType2Text @@ -19,25 +19,25 @@ PrintMonType: ; 27d6b (9:7d6b) ; a = type ; hl = dest addr -PrintType: ; 27d89 (9:7d89) +PrintType: push hl jr PrintType_ ; erase "TYPE2/" if the mon only has 1 type -EraseType2Text: ; 27d8c (9:7d8c) +EraseType2Text: ld a, " " ld bc, $13 add hl, bc ld bc, $6 jp FillMemory -PrintMoveType: ; 27d98 (9:7d98) +PrintMoveType: call GetPredefRegisters push hl - ld a, [W_PLAYERMOVETYPE] + ld a, [wPlayerMoveType] ; fall through -PrintType_: ; 27d9f (9:7d9f) +PrintType_: add a ld hl, TypeNames ld e, a diff --git a/engine/battle/read_trainer_party.asm b/engine/battle/read_trainer_party.asm index f1e3aaf1..3672d8dc 100644..100755 --- a/engine/battle/read_trainer_party.asm +++ b/engine/battle/read_trainer_party.asm @@ -1,4 +1,4 @@ -ReadTrainer: ; 39c53 (e:5c53) +ReadTrainer: ; don't change any moves in a link battle ld a,[wLinkState] @@ -15,7 +15,7 @@ ReadTrainer: ; 39c53 (e:5c53) ld [hl],a ; get the pointer to trainer data for this class - ld a,[W_CUROPPONENT] + ld a,[wCurOpponent] sub $C9 ; convert value from pokemon to trainer add a,a ld hl,TrainerDataPointers @@ -25,7 +25,7 @@ ReadTrainer: ; 39c53 (e:5c53) ld a,[hli] ld h,[hl] ld l,a - ld a,[W_TRAINERNO] + ld a,[wTrainerNo] ld b,a ; At this point b contains the trainer number, ; and hl points to the trainer class. @@ -43,20 +43,20 @@ ReadTrainer: ; 39c53 (e:5c53) ; if the first byte of trainer data is FF, ; - each pokemon has a specific level ; (as opposed to the whole team being of the same level) -; - if [W_LONEATTACKNO] != 0, one pokemon on the team has a special move +; - if [wLoneAttackNo] != 0, one pokemon on the team has a special move ; else the first byte is the level of every pokemon on the team .IterateTrainer ld a,[hli] cp $FF ; is the trainer special? jr z,.SpecialTrainer ; if so, check for special moves - ld [W_CURENEMYLVL],a + ld [wCurEnemyLVL],a .LoopTrainerData ld a,[hli] and a ; have we reached the end of the trainer data? jr z,.FinishUp ld [wcf91],a ; write species somewhere (XXX why?) - ld a,1 - ld [wcc49],a + ld a,ENEMY_PARTY_DATA + ld [wMonDataLocation],a push hl call AddPartyMon pop hl @@ -65,22 +65,22 @@ ReadTrainer: ; 39c53 (e:5c53) ; if this code is being run: ; - each pokemon has a specific level ; (as opposed to the whole team being of the same level) -; - if [W_LONEATTACKNO] != 0, one pokemon on the team has a special move +; - if [wLoneAttackNo] != 0, one pokemon on the team has a special move ld a,[hli] and a ; have we reached the end of the trainer data? jr z,.AddLoneMove - ld [W_CURENEMYLVL],a + ld [wCurEnemyLVL],a ld a,[hli] ld [wcf91],a - ld a,1 - ld [wcc49],a + ld a,ENEMY_PARTY_DATA + ld [wMonDataLocation],a push hl call AddPartyMon pop hl jr .SpecialTrainer .AddLoneMove ; does the trainer have a single monster with a different move - ld a,[W_LONEATTACKNO] ; Brock is 01, Misty is 02, Erika is 04, etc + ld a,[wLoneAttackNo] ; Brock is 01, Misty is 02, Erika is 04, etc and a jr z,.AddTeamMove dec a @@ -100,8 +100,8 @@ ReadTrainer: ; 39c53 (e:5c53) ; check if our trainer's team has special moves ; get trainer class number - ld a,[W_CUROPPONENT] - sub $C8 + ld a,[wCurOpponent] + sub 200 ld b,a ld hl,TeamMoves @@ -130,7 +130,7 @@ ReadTrainer: ; 39c53 (e:5c53) ld [wEnemyMon1Moves + 2],a ; starter - ld a,[W_RIVALSTARTER] + ld a,[wRivalStarter] cp STARTER3 ld b,MEGA_DRAIN jr z,.GiveStarterMove @@ -141,24 +141,26 @@ ReadTrainer: ; 39c53 (e:5c53) .GiveStarterMove ld a,b ld [wEnemyMon6Moves + 2],a -.FinishUp ; XXX this needs documenting - xor a ; clear D079-D07B - ld de,wd079 +.FinishUp +; clear wAmountMoneyWon addresses + xor a + ld de,wAmountMoneyWon ld [de],a inc de ld [de],a inc de ld [de],a - ld a,[W_CURENEMYLVL] + ld a,[wCurEnemyLVL] ld b,a .LastLoop - ld hl,wd047 - ld c,2 +; update wAmountMoneyWon addresses (money to win) based on enemy's level + ld hl,wTrainerBaseMoney + 1 + ld c,2 ; wAmountMoneyWon is a 3-byte number push bc predef AddBCDPredef pop bc inc de inc de dec b - jr nz,.LastLoop - ret
\ No newline at end of file + jr nz,.LastLoop ; repeat wCurEnemyLVL times + ret diff --git a/engine/battle/safari_zone.asm b/engine/battle/safari_zone.asm index 6b0e2220..1eb1a615 100755 --- a/engine/battle/safari_zone.asm +++ b/engine/battle/safari_zone.asm @@ -1,4 +1,4 @@ -PrintSafariZoneBattleText: ; 4277 (1:4277) +PrintSafariZoneBattleText: ld hl, wSafariBaitFactor ld a, [hl] and a @@ -18,7 +18,7 @@ PrintSafariZoneBattleText: ; 4277 (1:4277) ld a, [wEnemyMonSpecies] ld [wd0b5], a call GetMonHeader - ld a, [W_MONHCATCHRATE] + ld a, [wMonHCatchRate] ld [wEnemyMonCatchRate], a pop hl .asm_429f @@ -27,10 +27,10 @@ PrintSafariZoneBattleText: ; 4277 (1:4277) pop hl jp PrintText -SafariZoneEatingText: ; 42a7 (1:42a7) +SafariZoneEatingText: TX_FAR _SafariZoneEatingText db "@" -SafariZoneAngryText: ; 42ac (1:42ac) +SafariZoneAngryText: TX_FAR _SafariZoneAngryText db "@" diff --git a/engine/battle/save_trainer_name.asm b/engine/battle/save_trainer_name.asm index 84ef1f69..7e2c911c 100644 --- a/engine/battle/save_trainer_name.asm +++ b/engine/battle/save_trainer_name.asm @@ -1,6 +1,6 @@ -SaveTrainerName: ; 27e4a (9:7e4a) +SaveTrainerName: ld hl,TrainerNamePointers - ld a,[W_TRAINERCLASS] + ld a,[wTrainerClass] dec a ld c,a ld b,0 @@ -18,95 +18,95 @@ SaveTrainerName: ; 27e4a (9:7e4a) jr nz,.CopyCharacter ret -TrainerNamePointers: ; 27e64 (9:7e64) +TrainerNamePointers: ; what is the point of these? dw YoungsterName dw BugCatcherName dw LassName - dw W_TRAINERNAME + dw wTrainerName dw JrTrainerMName dw JrTrainerFName dw PokemaniacName dw SuperNerdName - dw W_TRAINERNAME - dw W_TRAINERNAME + dw wTrainerName + dw wTrainerName dw BurglarName dw EngineerName dw JugglerXName - dw W_TRAINERNAME + dw wTrainerName dw SwimmerName - dw W_TRAINERNAME - dw W_TRAINERNAME + dw wTrainerName + dw wTrainerName dw BeautyName - dw W_TRAINERNAME + dw wTrainerName dw RockerName dw JugglerName - dw W_TRAINERNAME - dw W_TRAINERNAME + dw wTrainerName + dw wTrainerName dw BlackbeltName - dw W_TRAINERNAME + dw wTrainerName dw ProfOakName dw ChiefName dw ScientistName - dw W_TRAINERNAME + dw wTrainerName dw RocketName dw CooltrainerMName dw CooltrainerFName - dw W_TRAINERNAME - dw W_TRAINERNAME - dw W_TRAINERNAME - dw W_TRAINERNAME - dw W_TRAINERNAME - dw W_TRAINERNAME - dw W_TRAINERNAME - dw W_TRAINERNAME - dw W_TRAINERNAME - dw W_TRAINERNAME - dw W_TRAINERNAME - dw W_TRAINERNAME - dw W_TRAINERNAME - dw W_TRAINERNAME - dw W_TRAINERNAME + 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: ; 27ec2 (9:7ec2) +YoungsterName: db "YOUNGSTER@" -BugCatcherName: ; 27ecc (9:7ecc) +BugCatcherName: db "BUG CATCHER@" -LassName: ; 27ed8 (9:7ed8) +LassName: db "LASS@" -JrTrainerMName: ; 27edd (9:7edd) +JrTrainerMName: db "JR.TRAINER♂@" -JrTrainerFName: ; 27ee9 (9:7ee9) +JrTrainerFName: db "JR.TRAINER♀@" -PokemaniacName: ; 27ef5 (9:7ef5) +PokemaniacName: db "POKéMANIAC@" -SuperNerdName: ; 27f00 (9:7f00) +SuperNerdName: db "SUPER NERD@" -BurglarName: ; 27f0b (9:7f0b) +BurglarName: db "BURGLAR@" -EngineerName: ; 27f13 (9:7f13) +EngineerName: db "ENGINEER@" -JugglerXName: ; 27f1c (9:7f1c) +JugglerXName: db "JUGGLER@" -SwimmerName: ; 27f24 (9:7f24) +SwimmerName: db "SWIMMER@" -BeautyName: ; 27f2c (9:7f2c) +BeautyName: db "BEAUTY@" -RockerName: ; 27f33 (9:7f33) +RockerName: db "ROCKER@" -JugglerName: ; 27f3a (9:7f3a) +JugglerName: db "JUGGLER@" -BlackbeltName: ; 27f42 (9:7f42) +BlackbeltName: db "BLACKBELT@" -ProfOakName: ; 27f4c (9:7f4c) +ProfOakName: db "PROF.OAK@" -ChiefName: ; 27f55 (9:7f55) +ChiefName: db "CHIEF@" -ScientistName: ; 27f5b (9:7f5b) +ScientistName: db "SCIENTIST@" -RocketName: ; 27f65 (9:7f65) +RocketName: db "ROCKET@" -CooltrainerMName: ; 27f6c (9:7f6c) +CooltrainerMName: db "COOLTRAINER♂@" -CooltrainerFName: ; 27f79 (9:7f79) +CooltrainerFName: db "COOLTRAINER♀@" diff --git a/engine/battle/scale_sprites.asm b/engine/battle/scale_sprites.asm index dae4ad42..98521528 100644 --- a/engine/battle/scale_sprites.asm +++ b/engine/battle/scale_sprites.asm @@ -1,16 +1,16 @@ ; scales both uncompressed sprite chunks by two in every dimension (creating 2x2 output pixels per input pixel) ; assumes that input sprite chunks are 4x4 tiles, and the rightmost and bottommost 4 pixels will be ignored ; resulting in a 7*7 tile output sprite chunk -ScaleSpriteByTwo: ; 2fe40 (b:7e40) - ld de, S_SPRITEBUFFER1 + (4*4*8) - 5 ; last byte of input data, last 4 rows already skipped - ld hl, S_SPRITEBUFFER0 + SPRITEBUFFERSIZE - 1 ; end of destination buffer +ScaleSpriteByTwo: + ld de, sSpriteBuffer1 + (4*4*8) - 5 ; last byte of input data, last 4 rows already skipped + ld hl, sSpriteBuffer0 + SPRITEBUFFERSIZE - 1 ; end of destination buffer call ScaleLastSpriteColumnByTwo ; last tile column is special case call ScaleFirstThreeSpriteColumnsByTwo ; scale first 3 tile columns - ld de, S_SPRITEBUFFER2 + (4*4*8) - 5 ; last byte of input data, last 4 rows already skipped - ld hl, S_SPRITEBUFFER1 + SPRITEBUFFERSIZE - 1 ; end of destination buffer + ld de, sSpriteBuffer2 + (4*4*8) - 5 ; last byte of input data, last 4 rows already skipped + ld hl, sSpriteBuffer1 + SPRITEBUFFERSIZE - 1 ; end of destination buffer call ScaleLastSpriteColumnByTwo ; last tile column is special case -ScaleFirstThreeSpriteColumnsByTwo: ; 2fe55 (b:7e55) +ScaleFirstThreeSpriteColumnsByTwo: ld b, $3 ; 3 tile columns .columnLoop ld c, 4*8 - 4 ; $1c, 4 tiles minus 4 unused rows @@ -39,18 +39,18 @@ ScaleFirstThreeSpriteColumnsByTwo: ; 2fe55 (b:7e55) jr nz, .columnLoop ret -ScaleLastSpriteColumnByTwo: ; 2fe7d (b:7e7d) +ScaleLastSpriteColumnByTwo: ld a, 4*8 - 4 ; $1c, 4 tiles minus 4 unused rows - ld [H_SPRITEINTERLACECOUNTER], a ; $ff8b - ld bc, -1 ; $ffff + ld [H_SPRITEINTERLACECOUNTER], a + ld bc, -1 .columnInnerLoop ld a, [de] dec de swap a ; only high nybble contains information call ScalePixelsByTwo - ld a, [H_SPRITEINTERLACECOUNTER] ; $ff8b + ld a, [H_SPRITEINTERLACECOUNTER] dec a - ld [H_SPRITEINTERLACECOUNTER], a ; $ff8b + ld [H_SPRITEINTERLACECOUNTER], a jr nz, .columnInnerLoop dec de ; skip last 4 rows of new column dec de @@ -61,7 +61,7 @@ ScaleLastSpriteColumnByTwo: ; 2fe7d (b:7e7d) ; scales the given 4 bits in a (4x1 pixels) to 2 output bytes (8x2 pixels) ; hl: destination pointer ; bc: destination pointer offset (added after the two bytes have been written) -ScalePixelsByTwo: ; 2fe97 (b:7e97) +ScalePixelsByTwo: push hl and $f ld hl, DuplicateBitsTable @@ -78,7 +78,7 @@ ScalePixelsByTwo: ; 2fe97 (b:7e97) ret ; repeats each input bit twice -DuplicateBitsTable: ; 2fea8 (b:7ea8) +DuplicateBitsTable: db $00, $03, $0c, $0f db $30, $33, $3c, $3f db $c0, $c3, $cc, $cf diff --git a/engine/battle/scroll_draw_trainer_pic.asm b/engine/battle/scroll_draw_trainer_pic.asm index 18df86e0..98893dcf 100644 --- a/engine/battle/scroll_draw_trainer_pic.asm +++ b/engine/battle/scroll_draw_trainer_pic.asm @@ -1,12 +1,12 @@ -_ScrollTrainerPicAfterBattle: ; 396d3 (e:56d3) +_ScrollTrainerPicAfterBattle: ; Load the enemy trainer's pic and scrolls it into ; the screen from the right. xor a ld [wEnemyMonSpecies2], a - ld b, $1 - call GoPAL_SET + ld b, SET_PAL_BATTLE + call RunPaletteCommand callab _LoadTrainerPic - hlCoord 19, 0 + coord hl, 19, 0 ld c, $0 .scrollLoop inc c @@ -32,7 +32,7 @@ _ScrollTrainerPicAfterBattle: ; 396d3 (e:56d3) jr .scrollLoop ; write one 7-tile column of the trainer pic to the tilemap -DrawTrainerPicColumn: ; 39707 (e:5707) +DrawTrainerPicColumn: push hl push de push bc diff --git a/engine/battle/trainer_ai.asm b/engine/battle/trainer_ai.asm index 191cfd5e..b175fcaf 100644 --- a/engine/battle/trainer_ai.asm +++ b/engine/battle/trainer_ai.asm @@ -1,25 +1,25 @@ ; creates a set of moves that may be used and returns its address in hl ; unused slots are filled with 0, all used slots may be chosen with equal probability -AIEnemyTrainerChooseMoves: ; 39719 (e:5719) +AIEnemyTrainerChooseMoves: ld a, $a - ld hl, wHPBarMaxHP ; init temporary move selection array. Only the moves with the lowest numbers are chosen in the end + ld hl, wBuffer ; init temporary move selection array. Only the moves with the lowest numbers are chosen in the end ld [hli], a ; move 1 ld [hli], a ; move 2 ld [hli], a ; move 3 ld [hl], a ; move 4 - ld a, [W_ENEMYDISABLEDMOVE] ; forbid disabled move (if any) + ld a, [wEnemyDisabledMove] ; forbid disabled move (if any) swap a and $f jr z, .noMoveDisabled - ld hl, wHPBarMaxHP + ld hl, wBuffer dec a ld c, a ld b, $0 add hl, bc ; advance pointer to forbidden move ld [hl], $50 ; forbid (highly discourage) disabled move .noMoveDisabled - ld hl, TrainerClassMoveChoiceModifications ; 589B - ld a, [W_TRAINERCLASS] + ld hl, TrainerClassMoveChoiceModifications + ld a, [wTrainerClass] ld b, a .loopTrainerClasses dec b @@ -40,11 +40,11 @@ AIEnemyTrainerChooseMoves: ; 39719 (e:5719) and a jr z, .loopFindMinimumEntries push hl - ld hl, AIMoveChoiceModificationFunctionPointers ; $57a3 + ld hl, AIMoveChoiceModificationFunctionPointers dec a add a ld c, a - ld b, $0 + ld b, 0 add hl, bc ; skip to pointer ld a, [hli] ; read pointer into hl ld h, [hl] @@ -53,9 +53,9 @@ AIEnemyTrainerChooseMoves: ; 39719 (e:5719) push de jp [hl] ; execute modification function .loopFindMinimumEntries ; all entries will be decremented sequentially until one of them is zero - ld hl, wHPBarMaxHP ; temp move selection array + ld hl, wBuffer ; temp move selection array ld de, wEnemyMonMoves ; enemy moves - ld c, $4 + ld c, NUM_MOVES .loopDecrementEntries ld a, [de] inc de @@ -73,15 +73,15 @@ AIEnemyTrainerChooseMoves: ; 39719 (e:5719) inc [hl] dec hl inc a - cp $5 + cp NUM_MOVES + 1 jr nz, .loopUndoPartialIteration - ld hl, wHPBarMaxHP ; temp move selection array + ld hl, wBuffer ; temp move selection array ld de, wEnemyMonMoves ; enemy moves - ld c, $4 + ld c, NUM_MOVES .filterMinimalEntries ; all minimal entries now have value 1. All other slots will be disabled (move set to 0) ld a, [de] and a - jr nz, .moveExisting ; 0x3978a $1 + jr nz, .moveExisting ld [hl], a .moveExisting ld a, [hl] @@ -97,20 +97,20 @@ AIEnemyTrainerChooseMoves: ; 39719 (e:5719) inc de dec c jr nz, .filterMinimalEntries - ld hl, wHPBarMaxHP ; use created temporary array as move set + ld hl, wBuffer ; use created temporary array as move set ret .useOriginalMoveSet ld hl, wEnemyMonMoves ; use original move set ret -AIMoveChoiceModificationFunctionPointers: ; 397a3 (e:57a3) +AIMoveChoiceModificationFunctionPointers: dw AIMoveChoiceModification1 dw AIMoveChoiceModification2 dw AIMoveChoiceModification3 dw AIMoveChoiceModification4 ; unused, does nothing ; discourages moves that cause no damage but only a status ailment if player's mon already has one -AIMoveChoiceModification1: ; 397ab (e:57ab) +AIMoveChoiceModification1: ld a, [wBattleMonStatus] and a ret z ; return if no status ailment on player's mon @@ -126,10 +126,10 @@ AIMoveChoiceModification1: ; 397ab (e:57ab) ret z ; no more moves in move set inc de call ReadMove - ld a, [W_ENEMYMOVEPOWER] + ld a, [wEnemyMovePower] and a jr nz, .nextMove - ld a, [W_ENEMYMOVEEFFECT] + ld a, [wEnemyMoveEffect] push hl push de push bc @@ -145,7 +145,7 @@ AIMoveChoiceModification1: ; 397ab (e:57ab) ld [hl], a jr .nextMove -StatusAilmentMoveEffects ; 57e2 +StatusAilmentMoveEffects: db $01 ; unused sleep effect db SLEEP_EFFECT db POISON_EFFECT @@ -155,9 +155,9 @@ StatusAilmentMoveEffects ; 57e2 ; slightly encourage moves with specific effects. ; in particular, stat-modifying moves and other move effects ; that fall in-bewteen -AIMoveChoiceModification2: ; 397e7 (e:57e7) +AIMoveChoiceModification2: ld a, [wAILayer2Encouragement] - cp $1 + cp $1 ret nz ld hl, wBuffer - 1 ; temp move selection array (-1 byte offset) ld de, wEnemyMonMoves ; enemy moves @@ -171,7 +171,7 @@ AIMoveChoiceModification2: ; 397e7 (e:57e7) ret z ; no more moves in move set inc de call ReadMove - ld a, [W_ENEMYMOVEEFFECT] + ld a, [wEnemyMoveEffect] cp ATTACK_UP1_EFFECT jr c, .nextMove cp BIDE_EFFECT @@ -182,16 +182,16 @@ AIMoveChoiceModification2: ; 397e7 (e:57e7) jr c, .preferMove jr .nextMove .preferMove - dec [hl] ; sligthly encourage this move + dec [hl] ; slightly encourage this move jr .nextMove ; encourages moves that are effective against the player's mon (even if non-damaging). ; discourage damaging moves that are ineffective or not very effective against the player's mon, ; unless there's no damaging move that deals at least neutral damage -AIMoveChoiceModification3: ; 39817 (e:5817) +AIMoveChoiceModification3: ld hl, wBuffer - 1 ; temp move selection array (-1 byte offset) ld de, wEnemyMonMoves ; enemy moves - ld b, $5 + ld b, NUM_MOVES + 1 .nextMove dec b ret z ; processed all 4 moves @@ -208,7 +208,7 @@ AIMoveChoiceModification3: ; 39817 (e:5817) pop de pop bc pop hl - ld a, [wd11e] + ld a, [wTypeEffectiveness] cp $10 jr z, .nextMove jr c, .notEffectiveMove @@ -218,7 +218,7 @@ AIMoveChoiceModification3: ; 39817 (e:5817) push hl push de push bc - ld a, [W_ENEMYMOVETYPE] + ld a, [wEnemyMoveType] ld d, a ld hl, wEnemyMonMoves ; enemy moves ld b, NUM_MOVES + 1 @@ -230,17 +230,17 @@ AIMoveChoiceModification3: ; 39817 (e:5817) and a jr z, .done call ReadMove - ld a, [W_ENEMYMOVEEFFECT] + ld a, [wEnemyMoveEffect] cp SUPER_FANG_EFFECT jr z, .betterMoveFound ; Super Fang is considered to be a better move cp SPECIAL_DAMAGE_EFFECT jr z, .betterMoveFound ; any special damage moves are considered to be better moves cp FLY_EFFECT jr z, .betterMoveFound ; Fly is considered to be a better move - ld a, [W_ENEMYMOVETYPE] + ld a, [wEnemyMoveType] cp d jr z, .loopMoves - ld a, [W_ENEMYMOVEPOWER] + ld a, [wEnemyMovePower] and a jr nz, .betterMoveFound ; damaging moves of a different type are considered to be better moves jr .loopMoves @@ -255,18 +255,18 @@ AIMoveChoiceModification3: ; 39817 (e:5817) jr z, .nextMove inc [hl] ; sligthly discourage this move jr .nextMove -AIMoveChoiceModification4: ; 39883 (e:5883) +AIMoveChoiceModification4: ret -ReadMove: ; 39884 (e:5884) +ReadMove: push hl push de push bc dec a ld hl,Moves - ld bc,6 + ld bc,MoveEnd - Moves call AddNTimes - ld de,W_ENEMYMOVENUM + ld de,wEnemyMoveNum call CopyData pop bc pop de @@ -275,13 +275,13 @@ ReadMove: ; 39884 (e:5884) ; move choice modification methods that are applied for each trainer class ; 0 is sentinel value -TrainerClassMoveChoiceModifications: ; 3989b (e:589b) +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,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 @@ -311,7 +311,7 @@ TrainerClassMoveChoiceModifications: ; 3989b (e:589b) db 1,0 ; BRUNO db 1,0 ; BROCK db 1,3,0 ; MISTY - db 1,3,0 ; LT__SURGE + db 1,3,0 ; LT_SURGE db 1,3,0 ; ERIKA db 1,3,0 ; KOGA db 1,3,0 ; BLAINE @@ -325,8 +325,8 @@ TrainerClassMoveChoiceModifications: ; 3989b (e:589b) db 1,3,0 ; LANCE INCLUDE "engine/battle/trainer_pic_money_pointers.asm" - -INCLUDE "text/trainer_names.asm" + +INCLUDE "text/trainer_names.asm" INCLUDE "engine/battle/bank_e_misc.asm" @@ -336,16 +336,15 @@ INCLUDE "data/trainer_moves.asm" INCLUDE "data/trainer_parties.asm" -TrainerAI: ; 3a52e (e:652e) -;XXX called at 34964, 3c342, 3c398 +TrainerAI: and a - ld a,[W_ISINBATTLE] + ld a,[wIsInBattle] dec a ret z ; if not a trainer, we're done here ld a,[wLinkState] cp LINK_STATE_BATTLING ret z - ld a,[W_TRAINERCLASS] ; what trainer class is this? + ld a,[wTrainerClass] ; what trainer class is this? dec a ld c,a ld b,0 @@ -369,7 +368,7 @@ TrainerAI: ; 3a52e (e:652e) call Random jp [hl] -TrainerAIPointers: ; 3a55c (e:655c) +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 @@ -421,27 +420,27 @@ TrainerAIPointers: ; 3a55c (e:655c) dbw 2,AgathaAI ; agatha dbw 1,LanceAI ; lance -JugglerAI: ; 3a5e9 (e:65e9) +JugglerAI: cp $40 ret nc jp AISwitchIfEnoughMons -BlackbeltAI: ; 3a5ef (e:65ef) +BlackbeltAI: cp $20 ret nc jp AIUseXAttack -GiovanniAI: ; 3a5f5 (e:65f5) +GiovanniAI: cp $40 ret nc jp AIUseGuardSpec -CooltrainerMAI: ; 3a5fb (e:65fb) +CooltrainerMAI: cp $40 ret nc jp AIUseXAttack -CooltrainerFAI: ; 3a601 (e:6601) +CooltrainerFAI: cp $40 ld a,$A call AICheckIfHPBelowFraction @@ -451,24 +450,24 @@ CooltrainerFAI: ; 3a601 (e:6601) ret nc jp AISwitchIfEnoughMons -BrockAI: ; 3a614 (e:6614) +BrockAI: ; if his active monster has a status condition, use a full heal ld a,[wEnemyMonStatus] and a ret z jp AIUseFullHeal -MistyAI: ; 3a61c (e:661c) +MistyAI: cp $40 ret nc jp AIUseXDefend -LtSurgeAI: ; 3a622 (e:6622) +LtSurgeAI: cp $40 ret nc jp AIUseXSpeed -ErikaAI: ; 3a628 (e:6628) +ErikaAI: cp $80 ret nc ld a,$A @@ -476,17 +475,17 @@ ErikaAI: ; 3a628 (e:6628) ret nc jp AIUseSuperPotion -KogaAI: ; 3a634 (e:6634) +KogaAI: cp $40 ret nc jp AIUseXAttack -BlaineAI: ; 3a63a (e:663a) +BlaineAI: cp $40 ret nc jp AIUseSuperPotion -SabrinaAI: ; 3a640 (e:6640) +SabrinaAI: cp $40 ret nc ld a,$A @@ -494,7 +493,7 @@ SabrinaAI: ; 3a640 (e:6640) ret nc jp AIUseHyperPotion -Sony2AI: ; 3a64c (e:664c) +Sony2AI: cp $20 ret nc ld a,5 @@ -502,7 +501,7 @@ Sony2AI: ; 3a64c (e:664c) ret nc jp AIUsePotion -Sony3AI: ; 3a658 (e:6658) +Sony3AI: cp $20 ret nc ld a,5 @@ -510,7 +509,7 @@ Sony3AI: ; 3a658 (e:6658) ret nc jp AIUseFullRestore -LoreleiAI: ; 3a664 (e:6664) +LoreleiAI: cp $80 ret nc ld a,5 @@ -518,12 +517,12 @@ LoreleiAI: ; 3a664 (e:6664) ret nc jp AIUseSuperPotion -BrunoAI: ; 3a670 (e:6670) +BrunoAI: cp $40 ret nc jp AIUseXDefend -AgathaAI: ; 3a676 (e:6676) +AgathaAI: cp $14 jp c,AISwitchIfEnoughMons cp $80 @@ -533,7 +532,7 @@ AgathaAI: ; 3a676 (e:6676) ret nc jp AIUseSuperPotion -LanceAI: ; 3a687 (e:6687) +LanceAI: cp $80 ret nc ld a,5 @@ -541,26 +540,26 @@ LanceAI: ; 3a687 (e:6687) ret nc jp AIUseHyperPotion -GenericAI: ; 3a693 (e:6693) +GenericAI: and a ; clear carry ret ; end of individual trainer AI routines -DecrementAICount: ; 3a695 (e:6695) +DecrementAICount: ld hl,wAICount dec [hl] scf ret -Func_3a69b: ; 3a69b (e:669b) - ld a,(SFX_08_3e - SFX_Headers_08) / 3 +AIPlayRestoringSFX: + ld a,SFX_HEAL_AILMENT jp PlaySoundWaitForCurrent -AIUseFullRestore: ; 3a6a0 (e:66a0) +AIUseFullRestore: call AICureStatus ld a,FULL_RESTORE - ld [wcf05],a + ld [wAIItem],a ld de,wHPBarOldHP ld hl,wEnemyMonHP + 1 ld a,[hld] @@ -581,27 +580,27 @@ AIUseFullRestore: ; 3a6a0 (e:66a0) ld [wEnemyMonHP],a jr AIPrintItemUseAndUpdateHPBar -AIUsePotion: ; 3a6ca (e:66ca) +AIUsePotion: ; enemy trainer heals his monster with a potion ld a,POTION ld b,20 jr AIRecoverHP -AIUseSuperPotion: ; 3a6d0 (e:66d0) +AIUseSuperPotion: ; enemy trainer heals his monster with a super potion ld a,SUPER_POTION ld b,50 jr AIRecoverHP -AIUseHyperPotion: ; 3a6d6 (e:66d6) +AIUseHyperPotion: ; enemy trainer heals his monster with a hyper potion ld a,HYPER_POTION ld b,200 ; fallthrough -AIRecoverHP: ; 3a6da (e:66da) +AIRecoverHP: ; heal b HP and print "trainer used $(a) on pokemon!" - ld [wcf05],a + ld [wAIItem],a ld hl,wEnemyMonHP + 1 ld a,[hl] ld [wHPBarOldHP],a @@ -640,15 +639,15 @@ AIRecoverHP: ; 3a6da (e:66da) ld [wHPBarNewHP+1],a ; fallthrough -AIPrintItemUseAndUpdateHPBar: ; 3a718 (e:6718) +AIPrintItemUseAndUpdateHPBar: call AIPrintItemUse_ - hlCoord 2, 2 + coord hl, 2, 2 xor a ld [wHPBarType],a predef UpdateHPBar2 jp DecrementAICount -AISwitchIfEnoughMons: ; 3a72a (e:672a) +AISwitchIfEnoughMons: ; enemy trainer switches if there are 3 or more unfainted mons in party ld a,[wEnemyPartyCount] ld c,a @@ -666,7 +665,7 @@ AISwitchIfEnoughMons: ; 3a72a (e:672a) inc d .Fainted push bc - ld bc,$2C + ld bc, wEnemyMon2 - wEnemyMon1 add hl,bc pop bc dec c @@ -678,7 +677,7 @@ AISwitchIfEnoughMons: ; 3a72a (e:672a) and a ret -SwitchEnemyMon: ; 3a74b (e:674b) +SwitchEnemyMon: ; prepare to withdraw the active monster: copy hp, number, and status to roster @@ -695,11 +694,13 @@ SwitchEnemyMon: ; 3a74b (e:674b) ld hl, AIBattleWithdrawText call PrintText + ; This wFirstMonsNotOutYet variable is abused to prevent the player from + ; switching in a new mon in response to this switch. ld a,1 - ld [wd11d],a + ld [wFirstMonsNotOutYet],a callab EnemySendOut xor a - ld [wd11d],a + ld [wFirstMonsNotOutYet],a ld a,[wLinkState] cp LINK_STATE_BATTLING @@ -707,17 +708,17 @@ SwitchEnemyMon: ; 3a74b (e:674b) scf ret -AIBattleWithdrawText: ; 3a781 (e:6781) +AIBattleWithdrawText: TX_FAR _AIBattleWithdrawText db "@" -AIUseFullHeal: ; 3a786 (e:6786) - call Func_3a69b +AIUseFullHeal: + call AIPlayRestoringSFX call AICureStatus ld a,FULL_HEAL jp AIPrintItemUse -AICureStatus: ; 3a791 (e:6791) +AICureStatus: ; cures the status of enemy's active pokemon ld a,[wEnemyMonPartyPos] ld hl,wEnemyMon1Status @@ -726,32 +727,32 @@ AICureStatus: ; 3a791 (e:6791) xor a ld [hl],a ; clear status in enemy team roster ld [wEnemyMonStatus],a ; clear status of active enemy - ld hl,W_ENEMYBATTSTATUS3 + ld hl,wEnemyBattleStatus3 res 0,[hl] ret -AIUseXAccuracy: ; 0x3a7a8 unused - call Func_3a69b - ld hl,W_ENEMYBATTSTATUS2 +AIUseXAccuracy: ; unused + call AIPlayRestoringSFX + ld hl,wEnemyBattleStatus2 set 0,[hl] ld a,X_ACCURACY jp AIPrintItemUse -AIUseGuardSpec: ; 3a7b5 (e:67b5) - call Func_3a69b - ld hl,W_ENEMYBATTSTATUS2 +AIUseGuardSpec: + call AIPlayRestoringSFX + ld hl,wEnemyBattleStatus2 set 1,[hl] - ld a,GUARD_SPEC_ + ld a,GUARD_SPEC jp AIPrintItemUse -AIUseDireHit: ; 0x3a7c2 unused - call Func_3a69b - ld hl,W_ENEMYBATTSTATUS2 +AIUseDireHit: ; unused + call AIPlayRestoringSFX + ld hl,wEnemyBattleStatus2 set 2,[hl] ld a,DIRE_HIT jp AIPrintItemUse -AICheckIfHPBelowFraction: ; 3a7cf (e:67cf) +AICheckIfHPBelowFraction: ; return carry if enemy trainer's current HP is below 1 / a of the maximum ld [H_DIVISOR],a ld hl,wEnemyMonMaxHP @@ -777,38 +778,38 @@ AICheckIfHPBelowFraction: ; 3a7cf (e:67cf) sub c ret -AIUseXAttack: ; 3a7f2 (e:67f2) +AIUseXAttack: ld b,$A ld a,X_ATTACK jr AIIncreaseStat -AIUseXDefend: ; 3a7f8 (e:67f8) +AIUseXDefend: ld b,$B ld a,X_DEFEND jr AIIncreaseStat -AIUseXSpeed: ; 3a7fe (e:67fe) +AIUseXSpeed: ld b,$C ld a,X_SPEED jr AIIncreaseStat -AIUseXSpecial: ; 3a804 (e:6804) +AIUseXSpecial: ld b,$D ld a,X_SPECIAL ; fallthrough -AIIncreaseStat: ; 3a808 (e:6808) - ld [wcf05],a +AIIncreaseStat: + ld [wAIItem],a push bc call AIPrintItemUse_ pop bc - ld hl,W_ENEMYMOVEEFFECT + ld hl,wEnemyMoveEffect ld a,[hld] push af ld a,[hl] push af push hl - ld a,$AF + ld a,ANIM_AF ld [hli],a ld [hl],b callab StatModifierUpEffect @@ -819,19 +820,19 @@ AIIncreaseStat: ; 3a808 (e:6808) ld [hl],a jp DecrementAICount -AIPrintItemUse: ; 3a82c (e:682c) - ld [wcf05],a +AIPrintItemUse: + ld [wAIItem],a call AIPrintItemUse_ jp DecrementAICount -AIPrintItemUse_: ; 3a835 (e:6835) -; print "x used [wcf05] on z!" - ld a,[wcf05] +AIPrintItemUse_: +; print "x used [wAIItem] on z!" + ld a,[wAIItem] ld [wd11e],a call GetItemName ld hl, AIBattleUseItemText jp PrintText -AIBattleUseItemText: ; 3a844 (e:6844) +AIBattleUseItemText: TX_FAR _AIBattleUseItemText db "@" diff --git a/engine/battle/trainer_pic_money_pointers.asm b/engine/battle/trainer_pic_money_pointers.asm index 3d32eb00..37678e74 100644..100755 --- a/engine/battle/trainer_pic_money_pointers.asm +++ b/engine/battle/trainer_pic_money_pointers.asm @@ -1,4 +1,4 @@ -TrainerPicAndMoneyPointers: ; 39914 (e:5914) +TrainerPicAndMoneyPointers: ; trainer pic pointers and base money. ; money received after battle = base money × level of highest-level enemy mon dw YoungsterPic @@ -140,4 +140,4 @@ TrainerPicAndMoneyPointers: ; 39914 (e:5914) money 9900 dw LancePic - money 9900
\ No newline at end of file + money 9900 diff --git a/engine/battle/unused_stats_functions.asm b/engine/battle/unused_stats_functions.asm index 23ddbc20..55f78fd3 100644 --- a/engine/battle/unused_stats_functions.asm +++ b/engine/battle/unused_stats_functions.asm @@ -1,5 +1,5 @@ ; does nothing since no stats are ever selected (barring glitches) -DoubleSelectedStats: ; 39680 (e:5680) +DoubleSelectedStats: ld a, [H_WHOSETURN] and a ld a, [wPlayerStatsToDouble] @@ -29,7 +29,7 @@ DoubleSelectedStats: ; 39680 (e:5680) ret ; does nothing since no stats are ever selected (barring glitches) -HalveSelectedStats: ; 396a7 (e:56a7) +HalveSelectedStats: ld a, [H_WHOSETURN] and a ld a, [wPlayerStatsToHalve] diff --git a/engine/battle/wild_encounters.asm b/engine/battle/wild_encounters.asm index 03119b90..231c46e7 100644 --- a/engine/battle/wild_encounters.asm +++ b/engine/battle/wild_encounters.asm @@ -1,6 +1,6 @@ ; try to initiate a wild pokemon encounter ; returns success in Z -TryDoWildEncounter: ; 13870 (4:7870) +TryDoWildEncounter: ld a, [wNPCMovementScriptPointerTableNum] and a ret nz @@ -18,33 +18,33 @@ TryDoWildEncounter: ; 13870 (4:7870) jr z, .CantEncounter ld a, [wRepelRemainingSteps] and a - jr z, .asm_1389e + jr z, .next dec a jr z, .lastRepelStep ld [wRepelRemainingSteps], a -.asm_1389e -; determine if wild pokémon can appear in the half-block we’re standing in +.next +; determine if wild pokemon can appear in the half-block we're standing in ; is the bottom right tile (9,9) of the half-block we're standing in a grass/water tile? - hlCoord 9, 9 + coord hl, 9, 9 ld c, [hl] - ld a, [W_GRASSTILE] + ld a, [wGrassTile] cp c - ld a, [W_GRASSRATE] + ld a, [wGrassRate] jr z, .CanEncounter ld a, $14 ; in all tilesets with a water tile, this is its id cp c - ld a, [W_WATERRATE] + ld a, [wWaterRate] jr z, .CanEncounter -; even if not in grass/water, standing anywhere we can encounter pokémon -; so long as the map is “indoor” and has wild pokémon defined. -; …as long as it’s not Viridian Forest or Safari Zone. - ld a, [W_CURMAP] +; even if not in grass/water, standing anywhere we can encounter pokemon +; 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? jr c, .CantEncounter2 - ld a, [W_CURMAPTILESET] + ld a, [wCurMapTileset] cp FOREST ; Viridian Forest/Safari Zone jr z, .CantEncounter2 - ld a, [W_GRASSRATE] + ld a, [wGrassRate] .CanEncounter ; compare encounter chance with a random number to determine if there will be an encounter ld b, a @@ -61,20 +61,20 @@ TryDoWildEncounter: ; 13870 (4:7870) inc hl jr .determineEncounterSlot .gotEncounterSlot -; determine which wild pokémon (grass or water) can appear in the half-block we’re standing in +; determine which wild pokemon (grass or water) can appear in the half-block we're standing in ld c, [hl] - ld hl, W_GRASSMONS - aCoord 8, 9 - cp $14 ; is the bottom left tile (8,9) of the half-block we're standing in a water tile? + ld hl, wGrassMons + aCoord 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, W_WATERMONS + ld hl, wWaterMons ; since the bottom right tile of a "left shore" half-block is $14 but the bottom left tile is not, -; "left shore" half-blocks (such as the one in the east coast of Cinnabar) load grass encounters. +; "left shore" half-blocks (such as the one in the east coast of Cinnabar) load grass encounters. .gotWildEncounterType - ld b, $0 + ld b, 0 add hl, bc ld a, [hli] - ld [W_CURENEMYLVL], a + ld [wCurEnemyLVL], a ld a, [hl] ld [wcf91], a ld [wEnemyMonSpecies2], a @@ -83,14 +83,14 @@ TryDoWildEncounter: ; 13870 (4:7870) jr z, .willEncounter ld a, [wPartyMon1Level] ld b, a - ld a, [W_CURENEMYLVL] + ld a, [wCurEnemyLVL] cp b jr c, .CantEncounter2 ; repel prevents encounters if the leading party mon's level is higher than the wild mon jr .willEncounter .lastRepelStep ld [wRepelRemainingSteps], a - ld a, $d2 - ld [H_DOWNARROWBLINKCNT2], a + ld a, TEXT_REPEL_WORE_OFF + ld [hSpriteIndexOrTextID], a call EnableAutoTextBoxDrawing call DisplayTextID .CantEncounter2 @@ -101,7 +101,7 @@ TryDoWildEncounter: ; 13870 (4:7870) xor a ret -WildMonEncounterSlotChances: ; 13918 (4:7918) +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 |