summaryrefslogtreecommitdiff
path: root/engine/battle
diff options
context:
space:
mode:
Diffstat (limited to 'engine/battle')
-rwxr-xr-xengine/battle/15.asm8
-rwxr-xr-xengine/battle/1c.asm4
-rwxr-xr-xengine/battle/4_2.asm20
-rwxr-xr-xengine/battle/animations.asm197
-rwxr-xr-xengine/battle/core.asm173
-rwxr-xr-xengine/battle/d.asm2
-rwxr-xr-xengine/battle/e.asm10
7 files changed, 237 insertions, 177 deletions
diff --git a/engine/battle/15.asm b/engine/battle/15.asm
index 2fb3b108..0acf3514 100755
--- a/engine/battle/15.asm
+++ b/engine/battle/15.asm
@@ -1,6 +1,6 @@
GainExperience: ; 5524f (15:524f)
- ld a, [W_ISLINKBATTLE]
- cp $4
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
ret z ; return if link battle
call DivideExpDataByNumMonsGainingExp
ld hl, wPartyMon1
@@ -226,8 +226,8 @@ GainExperience: ; 5524f (15:524f)
ld a, [W_PLAYERBATTSTATUS3]
bit 3, a ; is the mon transformed?
jr nz, .recalcStatChanges
-; the mon is transformed, so copy transformed data
- ld de, wcd0f
+; the mon is not transformed, so update the unmodified stats
+ ld de, wPlayerMonUnmodifiedLevel
ld bc, $b
call CopyData
.recalcStatChanges
diff --git a/engine/battle/1c.asm b/engine/battle/1c.asm
index bceeac2b..b905777b 100755
--- a/engine/battle/1c.asm
+++ b/engine/battle/1c.asm
@@ -127,8 +127,8 @@ BattleTransition: ; 7096d (1c:496d)
call Delay3
call LoadBattleTransitionTile
ld bc, $0
- ld a, [W_ISLINKBATTLE]
- cp $4
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
jr z, .linkBattle
call GetBattleTransitionID_WildOrTrainer
call GetBattleTransitionID_CompareLevels
diff --git a/engine/battle/4_2.asm b/engine/battle/4_2.asm
index 6ab5c004..a3ef1264 100755
--- a/engine/battle/4_2.asm
+++ b/engine/battle/4_2.asm
@@ -1,6 +1,6 @@
EndOfBattle: ; 137aa (4:77aa)
- ld a, [W_ISLINKBATTLE]
- cp $4
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
jr nz, .notLinkBattle
; link battle
ld a, [wEnemyMonPartyPos]
@@ -110,7 +110,7 @@ Func_13870: ; 13870 (4:7870)
jr z, .lastRepelStep
ld [wRepelRemainingSteps], a
.asm_1389e
-; determine if wild pokémon can appear in the half-block we’re standing
+; determine if wild pokmon can appear in the half-block were standing
; is the bottom right tile (9,9) of the half-block are we standing a grass/water tile?
hlCoord 9, 9
ld c, [hl]
@@ -122,9 +122,9 @@ Func_13870: ; 13870 (4:7870)
cp c
ld a, [W_WATERRATE]
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.
+; even if not in grass/water, standing anywhere we can encounter pokmon
+; so long as the map is indoor and has wild pokmon defined.
+; as long as its not Viridian Forest or Safari Zone.
ld a, [W_CURMAP]
cp REDS_HOUSE_1F ; is this an indoor map?
jr c, .CantEncounter
@@ -148,7 +148,7 @@ Func_13870: ; 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
+; determine which wild pokmon (grass or water) can appear in the half-block were standing
ld c, [hl]
ld hl, W_GRASSMONS
aCoord 8, 9
@@ -314,7 +314,7 @@ HazeEffect_: ; 139da (4:79da)
call Func_13a43
ld hl, wEnemyMonAttackMod
call Func_13a43
- ld hl, wcd12
+ ld hl, wPlayerMonUnmodifiedAttack
ld de, wBattleMonAttack
call Func_13a4a
ld hl, wEnemyMonUnmodifiedAttack
@@ -386,8 +386,8 @@ StatusChangesEliminatedText: ; 13a53 (4:7a53)
db "@"
GetTrainerName_: ; 13a58 (4:7a58)
- ld hl, W_GRASSRATE
- ld a, [W_ISLINKBATTLE]
+ ld hl, W_GRASSRATE
+ ld a, [wLinkState]
and a
jr nz, .rival
ld hl, W_RIVALNAME ; wd34a
diff --git a/engine/battle/animations.asm b/engine/battle/animations.asm
index d84edeb8..d4cebb44 100755
--- a/engine/battle/animations.asm
+++ b/engine/battle/animations.asm
@@ -528,9 +528,9 @@ Func_78e23: ; 78e23 (1e:4e23)
ld [wcc79], a
ld b, $e4
ld a, [W_ANIMATIONID] ; W_ANIMATIONID
- cp ANIM_AA
+ cp TRADE_BALL_DROP_ANIM
jr c, .asm_78e3f
- cp ANIM_AD + 1
+ cp TRADE_BALL_POOF_ANIM + 1
jr nc, .asm_78e3f
ld b, $f0
.asm_78e3f
@@ -700,13 +700,13 @@ AnimationIdSpecialEffects: ; 78ef5 (1e:4ef5)
db ROCK_SLIDE
dw DoRockSlideSpecialEffects
- db ANIM_AA
+ db TRADE_BALL_DROP_ANIM
dw Func_79041
- db ANIM_AB
+ db TRADE_BALL_SHAKE_ANIM
dw Func_7904c
- db ANIM_AC
+ db TRADE_BALL_TILT_ANIM
dw Func_7907c
db TOSS_ANIM
@@ -960,9 +960,9 @@ Func_7907c ; 507C
ld c,5
call DelayFrames
pop bc
- ld a,[$ffae] ; background scroll X
+ ld a,[hSCX] ; background scroll X
sub a,8 ; scroll to the left
- ld [$ffae],a
+ ld [hSCX],a
pop de
jr .loop
@@ -1307,9 +1307,9 @@ AnimationSlideMonUp: ; 7927a (1e:527a)
AnimationSlideMonDown: ; 79297 (1e:5297)
; Slides the mon's sprite down out of the screen.
xor a
- call Func_79842
+ call GetTileIDList
.asm_7929b
- call Func_79820
+ call GetMonSpriteTileMapPointerFromRowCount
push bc
push de
call Func_79aae
@@ -1498,8 +1498,8 @@ AnimationFlashEnemyMonPic: ; 79398 (1e:5398)
AnimationShowMonPic: ; 7939e (1e:539e)
xor a
- call Func_79842
- call Func_79820
+ call GetTileIDList
+ call GetMonSpriteTileMapPointerFromRowCount
call Func_79aae
jp Delay3
@@ -1533,7 +1533,7 @@ AnimationShakeBackAndForth: ; 793b1 (1e:53b1)
push af
push hl
push hl
- call Func_79842
+ call GetTileIDList
pop hl
call Func_79aae
call Delay3
@@ -1541,7 +1541,7 @@ AnimationShakeBackAndForth: ; 793b1 (1e:53b1)
ld bc, $0709
call ClearScreenArea
pop af
- call Func_79842
+ call GetTileIDList
pop hl
call Func_79aae
call Delay3
@@ -1568,7 +1568,7 @@ AnimationMoveMonHorizontally: ; 793f9 (1e:53f9)
.asm_79407
xor a
push hl
- call Func_79842
+ call GetTileIDList
pop hl
call Func_79aae
ld c, $3
@@ -1863,8 +1863,8 @@ AnimationSlideMonDownAndHide: ; 795c9 (1e:55c9)
call AnimationHideMonPic
pop af
push af
- call Func_79842
- call Func_79820
+ call GetTileIDList
+ call GetMonSpriteTileMapPointerFromRowCount
call Func_79aae
ld c, $8
call DelayFrames
@@ -2133,8 +2133,8 @@ Func_79793: ; 79793 (1e:5793)
call GetMonHeader
predef LoadMonBackPic
xor a
- call Func_79842
- call Func_79820
+ call GetTileIDList
+ call GetMonSpriteTileMapPointerFromRowCount
call Func_79aae
pop af
ld [wBattleMonSpecies2], a
@@ -2194,37 +2194,46 @@ Func_7980c: ; 7980c (1e:580c)
pop hl
ret
-Func_79820: ; 79820 (1e:5820)
+; 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)
push de
- ld a, [H_WHOSETURN] ; $fff3
+ ld a, [H_WHOSETURN]
and a
- jr nz, .asm_7982a
- ld a, $65
- jr .asm_7982c
-.asm_7982a
- ld a, $c
-.asm_7982c
+ jr nz, .enemyTurn
+ ld a, 20 * 5 + 1
+ jr .next
+.enemyTurn
+ ld a, 12
+.next
ld hl, wTileMap
ld e, a
- ld d, $0
+ ld d, 0
add hl, de
- ld a, $7
+ ld a, 7
sub b
and a
- jr z, .asm_79840
- ld de, $14
-.asm_7983c
+ jr z, .done
+ ld de, 20
+.loop
add hl, de
dec a
- jr nz, .asm_7983c
-.asm_79840
+ jr nz, .loop
+.done
pop de
ret
-Func_79842: ; 79842 (1e:5842)
- ld hl, PointerTable_79aea ; $5aea
+; Input:
+; a = tile ID list index
+; Output:
+; de = tile ID list pointer
+; b = number of rows
+; c = number of columns
+GetTileIDList: ; 79842 (1e:5842)
+ ld hl, TileIDListPointerTable
ld e, a
- ld d, $0
+ ld d, 0
add hl, de
add hl, de
add hl, de
@@ -2486,13 +2495,14 @@ MoveSoundTable: ; 798bc (1e:58bc)
db (SFX_08_4b - SFX_Headers_08) / 3,$00,$80
Func_79aae: ; 79aae (1e:5aae)
- ld a, [H_WHOSETURN] ; $fff3
+ ld a, [H_WHOSETURN]
and a
- ld a, $31
+ ld a, $31 ; base tile ID of player mon sprite
jr z, .asm_79ab6
- xor a
+; enemy turn
+ xor a ; base tile ID of enemy mon sprite
.asm_79ab6
- ld [H_DOWNARROWBLINKCNT1], a ; $ff8b
+ ld [hBaseTileID], a
jr asm_79acb
Func_79aba: ; 79aba (1e:5aba)
@@ -2506,34 +2516,36 @@ Func_79aba: ; 79aba (1e:5aba)
ld de, Unknown_79b1b ; $5b1b
asm_79acb: ; 79acb (1e:5acb)
xor a
- ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
+ ld [H_AUTOBGTRANSFERENABLED], a
-Func_79ace: ; 79ace (1e:5ace)
+; b = number of rows
+; c = number of columns
+CopyTileIDs: ; 79ace (1e:5ace)
push hl
-.asm_79acf
+.rowLoop
push bc
push hl
- ld a, [H_DOWNARROWBLINKCNT1] ; $ff8b
+ ld a, [hBaseTileID]
ld b, a
-.asm_79ad4
+.columnLoop
ld a, [de]
add b
inc de
ld [hli], a
dec c
- jr nz, .asm_79ad4
+ jr nz, .columnLoop
pop hl
- ld bc, $14
+ ld bc, 20
add hl, bc
pop bc
dec b
- jr nz, .asm_79acf
+ jr nz, .rowLoop
ld a, $1
- ld [H_AUTOBGTRANSFERENABLED], a ; $ffba
+ ld [H_AUTOBGTRANSFERENABLED], a
pop hl
ret
-PointerTable_79aea: ; 79aea (1e:5aea)
+TileIDListPointerTable: ; 79aea (1e:5aea)
dw Unknown_79b24
db $77
dw Unknown_79b55
@@ -2552,34 +2564,79 @@ PointerTable_79aea: ; 79aea (1e:5aea)
db $3C
Unknown_79b02: ; 79b02 (1e:5b02)
- db $31,$38,$46,$54,$5B,$32,$39,$47,$55,$5C,$34,$3B,$49,$57,$5E,$36,$3D,$4B,$59,$60,$37,$3E,$4C,$5A,$61
+ 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)
- db $31,$46,$5B,$34,$49,$5E,$37,$4C,$61
+ db $31,$46,$5B
+ db $34,$49,$5E
+ db $37,$4C,$61
Unknown_79b24: ; 79b24 (1e:5b24)
- db $00,$07,$0E,$15,$1C,$23,$2A,$01,$08,$0F,$16,$1D,$24,$2B,$02,$09,$10,$17,$1E,$25,$2C,$03,$0A,$11,$18,$1F,$26,$2D,$04,$0B,$12,$19,$20,$27,$2E,$05,$0C,$13,$1A,$21,$28,$2F,$06,$0D,$14,$1B,$22,$29,$30
+ db $00,$07,$0E,$15,$1C,$23,$2A
+ db $01,$08,$0F,$16,$1D,$24,$2B
+ db $02,$09,$10,$17,$1E,$25,$2C
+ db $03,$0A,$11,$18,$1F,$26,$2D
+ db $04,$0B,$12,$19,$20,$27,$2E
+ db $05,$0C,$13,$1A,$21,$28,$2F
+ db $06,$0D,$14,$1B,$22,$29,$30
Unknown_79b55: ; 79b55 (1e:5b55)
- db $00,$07,$0E,$15,$1C,$23,$2A,$01,$08,$0F,$16,$1D,$24,$2B,$03,$0A,$11,$18,$1F,$26,$2D,$04,$0B,$12,$19,$20,$27,$2E,$05,$0C,$13,$1A,$21,$28,$2F
+ 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)
- db $00,$07,$0E,$15,$1C,$23,$2A,$02,$09,$10,$17,$1E,$25,$2C,$04,$0B,$12,$19,$20,$27,$2E
+ 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)
- db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$19,$00,$02,$06,$0B,$10,$14,$1A,$00,$00,$07,$0C,$11,$15,$1B,$00,$03,$08,$0D,$12,$16,$1C,$00,$04,$09,$0E,$13,$17,$1D,$1F,$05,$0A,$0F,$01,$18,$1E,$20
+ db $00,$00,$00,$00,$00,$00,$00
+ db $00,$00,$00,$00,$00,$19,$00
+ db $02,$06,$0B,$10,$14,$1A,$00
+ db $00,$07,$0C,$11,$15,$1B,$00
+ db $03,$08,$0D,$12,$16,$1C,$00
+ db $04,$09,$0E,$13,$17,$1D,$1F
+ db $05,$0A,$0F,$01,$18,$1E,$20
Unknown_79bbe: ; 79bbe (1e:5bbe)
- db $00,$00,$00,$30,$00,$37,$00,$00,$00,$2B,$31,$34,$38,$3D,$21,$26,$2C,$01,$35,$39,$3E,$22,$27,$2D,$32,$36,$01,$00,$23,$28,$2E,$33,$01,$3A,$00,$24,$29,$2F,$01,$01,$3B,$00,$25,$2A,$01,$01,$01,$3C,$00
+ db $00,$00,$00,$30,$00,$37,$00
+ db $00,$00,$2B,$31,$34,$38,$3D
+ db $21,$26,$2C,$01,$35,$39,$3E
+ db $22,$27,$2D,$32,$36,$01,$00
+ db $23,$28,$2E,$33,$01,$3A,$00
+ db $24,$29,$2F,$01,$01,$3B,$00
+ db $25,$2A,$01,$01,$01,$3C,$00
Unknown_79bef: ; 79bef (1e:5bef)
- db $00,$00,$00,$00,$00,$00,$00,$00,$00,$47,$4D,$00,$00,$00,$00,$00,$48,$4E,$52,$56,$5B,$3F,$43,$49,$4F,$53,$57,$5C,$40,$44,$4A,$50,$54,$58,$00,$41,$45,$4B,$51,$4C,$59,$5D,$42,$46,$4C,$4C,$55,$5A,$5E
+ db $00,$00,$00,$00,$00,$00,$00
+ db $00,$00,$47,$4D,$00,$00,$00
+ db $00,$00,$48,$4E,$52,$56,$5B
+ db $3F,$43,$49,$4F,$53,$57,$5C
+ db $40,$44,$4A,$50,$54,$58,$00
+ db $41,$45,$4B,$51,$4C,$59,$5D
+ db $42,$46,$4C,$4C,$55,$5A,$5E
Unknown_79c20: ; 79c20 (1e:5c20)
- db $31,$32,$32,$32,$32,$33,$34,$35,$36,$36,$37,$38,$34,$39,$3A,$3A,$3B,$38,$3C,$3D,$3E,$3E,$3F,$40,$41,$42,$43,$43,$44,$45,$46,$47,$43,$48,$49,$4A,$41,$43,$4B,$4C,$4D,$4E,$4F,$50,$50,$50,$51,$52
+ db $31,$32,$32,$32,$32,$33
+ db $34,$35,$36,$36,$37,$38
+ db $34,$39,$3A,$3A,$3B,$38
+ db $3C,$3D,$3E,$3E,$3F,$40
+ db $41,$42,$43,$43,$44,$45
+ db $46,$47,$43,$48,$49,$4A
+ db $41,$43,$4B,$4C,$4D,$4E
+ db $4F,$50,$50,$50,$51,$52
Unknown_79c50: ; 79c50 (1e:5c50)
- db $43,$55,$56,$53,$53,$53,$53,$53,$53,$53,$53,$53,$43,$57,$58,$54,$54,$54,$54,$54,$54,$54,$54,$54,$43,$59,$5A,$43,$43,$43,$43,$43,$43,$43,$43,$43
+ 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)
; Makes leaves float down from the top of the screen. This is used
@@ -2743,7 +2800,7 @@ AnimationShakeEnemyHUD: ; 79d77 (1e:5d77)
ld bc, 7 * 7
call CopyVideoData
xor a
- ld [$ffae], a
+ ld [hSCX], a
ld hl, vBGMap0
call Func_79e0d
ld a, $90
@@ -2776,34 +2833,36 @@ AnimationShakeEnemyHUD: ; 79d77 (1e:5d77)
ld hl, vBGMap1
jp Func_79e0d
-Func_79dda: ; 79dda (1e:5dda)
+; b = tile ID list index
+; c = base tile ID
+CopyTileIDsFromList: ; 79dda (1e:5dda)
call GetPredefRegisters
ld a, c
- ld [H_DOWNARROWBLINKCNT1], a ; $ff8b
+ ld [hBaseTileID], a
ld a, b
push hl
- call Func_79842
+ call GetTileIDList
pop hl
- jp Func_79ace
+ jp CopyTileIDs
Func_79de9: ; 79de9 (1e:5de9)
- ld a, [$ffae]
+ ld a, [hSCX]
ld [wTrainerSpriteOffset], a
.asm_79dee
ld a, [wTrainerSpriteOffset]
add d
- ld [$ffae], a
+ ld [hSCX], a
ld c, $2
call DelayFrames
ld a, [wTrainerSpriteOffset]
sub d
- ld [$ffae], a
+ ld [hSCX], a
ld c, $2
call DelayFrames
dec e
jr nz, .asm_79dee
ld a, [wTrainerSpriteOffset]
- ld [$ffae], a
+ ld [hSCX], a
ret
Func_79e0d: ; 79e0d (1e:5e0d)
diff --git a/engine/battle/core.asm b/engine/battle/core.asm
index 381c82b1..0c506e2b 100755
--- a/engine/battle/core.asm
+++ b/engine/battle/core.asm
@@ -99,7 +99,7 @@ SpecialEffectsCont: ; 3c049 (f:4049)
SlidePlayerAndEnemySilhouettesOnScreen: ; 3c04c (f:404c)
call LoadPlayerBackPic
ld a, $1 ; the usual text box at the bottom of the screen
- ld [wd125], a
+ ld [wTextBoxID], a
call DisplayTextBoxID
hlCoord 1, 5
ld bc, $307
@@ -240,7 +240,7 @@ StartBattle: ; 3c11e (f:411e)
jr .findFirstAliveEnemyMonLoop
.foundFirstAliveEnemyMon
ld a, d
- ld [wcc3e], a
+ ld [wSerialExchangeNybbleReceiveData], a
ld a, [W_ISINBATTLE]
dec a ; is it a trainer battle?
call nz, EnemySendOutFirstMon ; if it is a trainer battle, send out enemy mon
@@ -345,8 +345,8 @@ StartBattle: ; 3c11e (f:411e)
; wild mon or link battle enemy ran from battle
EnemyRan: ; 3c202 (f:4202)
call LoadScreenTilesFromBuffer1
- ld a, [W_ISLINKBATTLE]
- cp $4
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
ld hl, WildRanText
jr nz, .printText
; link battle
@@ -431,11 +431,11 @@ MainInBattleLoop: ; 3c233 (f:4233)
jr nz, MainInBattleLoop ; if the player didn't select a move, jump
.selectEnemyMove
call SelectEnemyMove
- ld a, [W_ISLINKBATTLE]
- cp $4
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
jr nz, .noLinkBattle
; link battle
- ld a, [wcc3e]
+ ld a, [wSerialExchangeNybbleReceiveData]
cp $f
jp z, EnemyRan
cp $e
@@ -838,7 +838,7 @@ FaintEnemyPokemon ; 0x3c567
ld hl, W_PLAYERBATTSTATUS1
res AttackingMultipleTimes, [hl]
xor a
- ld [W_NUMHITS], a
+ ld [wPlayerNumHits], a
ld hl, wd065 ; clear enemy statuses
ld [hli], a
ld [hli], a
@@ -976,12 +976,12 @@ ReplaceFaintedEnemyMon: ; 3c664 (f:4664)
ld e, $30
call GetBattleHealthBarColor
callab DrawEnemyPokeballs
- ld a, [W_ISLINKBATTLE]
- cp $4
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
jr nz, .notLinkBattle
; link battle
call LinkBattleExchangeData
- ld a, [wcc3e]
+ ld a, [wSerialExchangeNybbleReceiveData]
cp $f
ret z
call LoadScreenTilesFromBuffer1
@@ -1009,14 +1009,14 @@ TrainerBattleVictory: ; 3c696 (f:4696)
ld hl, W_FLAGS_D733
set 1, [hl]
.notrival
- ld a, [W_ISLINKBATTLE]
- cp $4
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
ld a, b
call nz, PlayBattleVictoryMusic
ld hl, TrainerDefeatedText
call PrintText
- ld a, [W_ISLINKBATTLE]
- cp $4
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
ret z
call ScrollTrainerPicAfterBattle
ld c, $28
@@ -1096,7 +1096,7 @@ RemoveFaintedPlayerMon: ; 3c741 (f:4741)
ld [wd083], a
call WaitForSoundToFinish
.skipWaitForSound
- ld hl, wcd05
+ ld hl, wEnemyNumHits
ld [hli], a
ld [hl], a
ld [wBattleMonStatus], a
@@ -1136,7 +1136,7 @@ DoUseNextMonDialogue: ; 3c79b (f:479b)
hlCoord 13, 9
ld bc, $a0e
ld a, $14 ; yes/no text box
- ld [wd125], a
+ ld [wTextBoxID], a
call DisplayTextBoxID
ld a, [wd12e]
cp $2 ; did the player choose NO?
@@ -1169,8 +1169,8 @@ ChooseNextMon: ; 3c7d8 (f:47d8)
.monChosen
call HasMonFainted
jr z, .goBackToPartyMenu ; if mon fainted, you have to choose another
- ld a, [W_ISLINKBATTLE]
- cp $4
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
jr nz, .notLinkBattle
inc a
ld [wcd6a], a
@@ -1204,8 +1204,8 @@ 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)
- ld a, [W_ISLINKBATTLE]
- cp $4
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
jr z, .notSony1Battle
ld a, [W_CUROPPONENT]
cp $c8 + SONY1
@@ -1225,8 +1225,8 @@ HandlePlayerBlackOut: ; 3c837 (f:4837)
ld b, $0
call GoPAL_SET
ld hl, PlayerBlackedOutText2
- ld a, [W_ISLINKBATTLE]
- cp $4
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
jr nz, .noLinkBattle
ld hl, LinkBattleLostText
.noLinkBattle
@@ -1385,10 +1385,10 @@ EnemySendOutFirstMon: ; 3c92a (f:492a)
call SlideTrainerPicOffScreen
call PrintEmptyString
call SaveScreenTilesToBuffer1
- ld a,[W_ISLINKBATTLE]
- cp 4
+ ld a,[wLinkState]
+ cp LINK_STATE_BATTLING
jr nz,.next
- ld a,[wcc3e]
+ ld a,[wSerialExchangeNybbleReceiveData]
sub 4
ld [wWhichPokemon],a
jr .next3
@@ -1442,8 +1442,8 @@ EnemySendOutFirstMon: ; 3c92a (f:492a)
ld a,[wPartyCount]
dec a
jr z,.next4
- ld a,[W_ISLINKBATTLE]
- cp 4
+ ld a,[wLinkState]
+ cp LINK_STATE_BATTLING
jr z,.next4
ld a,[W_OPTIONS]
bit 6,a
@@ -1453,7 +1453,7 @@ EnemySendOutFirstMon: ; 3c92a (f:492a)
hlCoord 0, 7
ld bc,$0801
ld a,$14
- ld [wd125],a
+ ld [wTextBoxID],a
call DisplayTextBoxID
ld a,[wCurrentMenuItem]
and a
@@ -1572,8 +1572,8 @@ TryRunningFromBattle: ; 3cab9 (f:4ab9)
ld a, [W_BATTLETYPE]
cp $2
jp z, .canEscape ; jump if it's a safari battle
- ld a, [W_ISLINKBATTLE]
- cp $4
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
jp z, .canEscape
ld a, [W_ISINBATTLE]
dec a
@@ -1654,8 +1654,8 @@ TryRunningFromBattle: ; 3cab9 (f:4ab9)
and a ; reset carry
ret
.canEscape
- ld a, [W_ISLINKBATTLE]
- cp $4
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
ld a, $2
jr nz, .playSound
; link battle
@@ -1666,7 +1666,7 @@ TryRunningFromBattle: ; 3cab9 (f:4ab9)
ld [wPlayerMoveListIndex], a
call LinkBattleExchangeData
call LoadScreenTilesFromBuffer1
- ld a, [wcc3e]
+ ld a, [wSerialExchangeNybbleReceiveData]
cp $f
ld a, $2
jr z, .playSound
@@ -2082,7 +2082,7 @@ DisplayBattleMenu: ; 3ceb3 (f:4eb3)
jr nz, .menuselected
ld a, $1b ; regular menu id
.menuselected
- ld [wd125], a
+ ld [wTextBoxID], a
call DisplayTextBoxID
ld a, [W_BATTLETYPE]
dec a
@@ -2234,8 +2234,8 @@ DisplayBattleMenu: ; 3ceb3 (f:4eb3)
jp nz, PartyMenuOrRockOrRun
; either the bag (normal battle) or bait (safari battle) was selected
- ld a, [W_ISLINKBATTLE]
- cp $4
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
jr nz, .notLinkBattle
; can't use items in link battles
@@ -2401,7 +2401,7 @@ PartyMenuOrRockOrRun:
jr .checkIfPartyMonWasSelected
.partyMonWasSelected
ld a, $c ; switch/stats/cancel menu
- ld [wd125], a
+ ld [wTextBoxID], a
call DisplayTextBoxID
ld hl, wTopMenuItemY
ld a, $c
@@ -2620,8 +2620,8 @@ MoveSelectionMenu: ; 3d219 (f:5219)
dec a
ld b, $c3
jr z, .matchedkeyspicked
- ld a, [W_ISLINKBATTLE]
- cp $4
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
jr z, .matchedkeyspicked
ld a, [W_FLAGS_D733]
bit 0, a
@@ -2974,14 +2974,14 @@ TypeText: ; 3d55f (f:555f)
db "TYPE@"
SelectEnemyMove: ; 3d564 (f:5564)
- ld a, [W_ISLINKBATTLE]
+ ld a, [wLinkState]
sub $4
jr nz, .noLinkBattle
; link battle
call SaveScreenTilesToBuffer1
call LinkBattleExchangeData
call LoadScreenTilesFromBuffer1
- ld a, [wcc3e]
+ ld a, [wSerialExchangeNybbleReceiveData]
cp $e
jp z, .asm_3d601
cp $d
@@ -3068,7 +3068,7 @@ SelectEnemyMove: ; 3d564 (f:5564)
; this appears to exchange data with the other gameboy during link battles
LinkBattleExchangeData: ; 3d605 (f:5605)
ld a, $ff
- ld [wcc3e], a
+ ld [wSerialExchangeNybbleReceiveData], a
ld a, [wPlayerMoveListIndex]
cp $f ; is the player running from battle?
jr z, .asm_3d630
@@ -3091,24 +3091,24 @@ LinkBattleExchangeData: ; 3d605 (f:5605)
.asm_3d62f
ld a, b
.asm_3d630
- ld [wcc42], a
+ ld [wSerialExchangeNybbleSendData], a
callab PrintWaitingText
.asm_3d63b
- call Func_22c3
+ call Serial_ExchangeNybble
call DelayFrame
- ld a, [wcc3e]
+ ld a, [wSerialExchangeNybbleReceiveData]
inc a
jr z, .asm_3d63b
ld b, $a
.asm_3d649
call DelayFrame
- call Func_22c3
+ call Serial_ExchangeNybble
dec b
jr nz, .asm_3d649
ld b, $a
.asm_3d654
call DelayFrame
- call Func_22ed
+ call Serial_SendZeroByte
dec b
jr nz, .asm_3d654
ret
@@ -3296,7 +3296,7 @@ MirrorMoveCheck
ld hl,MultiHitText
call PrintText
xor a
- ld [W_NUMHITS],a
+ ld [wPlayerNumHits],a
.executeOtherEffects
ld a,[W_PLAYERMOVEEFFECT]
and a
@@ -3529,7 +3529,7 @@ CheckPlayerStatusConditions: ; 3d854 (f:5854)
ld a,[hli]
ld b,a
ld c,[hl]
- ld hl,wd075
+ ld hl,wPlayerBideAccumulatedDamage + 1
ld a,[hl]
add c ; acumulate damage taken
ld [hld],a
@@ -3548,7 +3548,7 @@ CheckPlayerStatusConditions: ; 3d854 (f:5854)
call PrintText
ld a,1
ld [W_PLAYERMOVEPOWER],a
- ld hl,wd075
+ ld hl,wPlayerBideAccumulatedDamage + 1
ld a,[hld]
add a
ld b,a
@@ -3998,8 +3998,8 @@ OHKOText: ; 3dc83 (f:5c83)
CheckForDisobedience: ; 3dc88 (f:5c88)
xor a
ld [wcced], a
- ld a, [W_ISLINKBATTLE]
- cp $4
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
jr nz, .checkIfMonIsTraded
ld a, $1
and a
@@ -4424,8 +4424,8 @@ GetDamageVarsForEnemyAttack: ; 3de75 (f:5e75)
GetEnemyMonStat: ; 3df1c (f:5f1c)
push de
push bc
- ld a, [W_ISLINKBATTLE]
- cp $4
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
jr nz, .notLinkBattle
ld hl, wEnemyMon1Stats
dec c
@@ -5627,11 +5627,11 @@ ExecuteEnemyMove: ; 3e6bc (f:66bc)
jp z, ExecuteEnemyMoveDone
call PrintGhostText
jp z, ExecuteEnemyMoveDone
- ld a, [W_ISLINKBATTLE]
- cp $4
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
jr nz, .executeEnemyMove
ld b, $1
- ld a, [wcc3e]
+ ld a, [wSerialExchangeNybbleReceiveData]
cp $e
jr z, .executeEnemyMove
cp $4
@@ -5819,7 +5819,7 @@ asm_3e7ef: ; 3e7ef (f:67ef)
ld hl, HitXTimesText
call PrintText
xor a
- ld [wcd05], a
+ ld [wEnemyNumHits], a
.asm_3e873
ld a, [W_ENEMYMOVEEFFECT]
and a
@@ -6028,7 +6028,7 @@ CheckEnemyStatusConditions: ; 3e88f (f:688f)
ld a, [hli]
ld b, a
ld c, [hl]
- ld hl, wcd06
+ ld hl, wEnemyBideAccumulatedDamage + 1
ld a, [hl]
add c
ld [hld], a
@@ -6047,7 +6047,7 @@ CheckEnemyStatusConditions: ; 3e88f (f:688f)
call PrintText
ld a, $1
ld [W_ENEMYMOVEPOWER], a
- ld hl, wcd06
+ ld hl, wEnemyBideAccumulatedDamage + 1
ld a, [hld]
add a
ld b, a
@@ -6152,8 +6152,8 @@ GetCurrentMove: ; 3eabe (f:6abe)
jp CopyStringToCF4B
LoadEnemyMonData: ; 3eb01 (f:6b01)
- ld a, [W_ISLINKBATTLE]
- cp $4
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
jp z, LoadEnemyMonFromParty
ld a, [wEnemyMonSpecies2]
ld [wEnemyMonSpecies], a
@@ -6312,8 +6312,8 @@ LoadEnemyMonData: ; 3eb01 (f:6b01)
; calls BattleTransition to show the battle transition animation and initializes some battle variables
DoBattleTransitionAndInitBattleVariables: ; 3ec32 (f:6c32)
- ld a, [W_ISLINKBATTLE]
- cp $4
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
jr nz, .next
; link battle
xor a
@@ -6616,8 +6616,8 @@ CalculateModifiedStat: ; 3eda5 (f:6da5)
ret
ApplyBadgeStatBoosts: ; 3ee19 (f:6e19)
- ld a, [W_ISLINKBATTLE]
- cp $4
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
ret z ; return if link battle
ld a, [W_OBTAINEDBADGES]
ld b, a
@@ -6706,19 +6706,19 @@ PrintEmptyString: ; 3ee94 (f:6e94)
BattleRandom:
; Link battles use a shared PRNG.
- ld a, [W_ISLINKBATTLE]
- cp $4
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
jp nz, Random
push hl
push bc
- ld a, [wLinkBattleRNCount]
+ ld a, [wLinkBattleRandomNumberListIndex]
ld c, a
ld b, 0
- ld hl, wd148
+ ld hl, wLinkBattleRandomNumberList
add hl, bc
inc a
- ld [wLinkBattleRNCount], a
+ ld [wLinkBattleRandomNumberListIndex], a
cp 9
ld a, [hl]
pop bc
@@ -6732,8 +6732,9 @@ BattleRandom:
; point to seed 0 so we pick the first number the next time
xor a
- ld [wLinkBattleRNCount], a
- ld hl, wd148
+ ld [wLinkBattleRandomNumberListIndex], a
+
+ ld hl, wLinkBattleRandomNumberList
ld b, 9
.loop
ld a, [hl]
@@ -6939,7 +6940,7 @@ _LoadTrainerPic: ; 3f04b (f:704b)
ld e, a
ld a, [wd034]
ld d, a ; de contains pointer to trainer pic
- ld a, [W_ISLINKBATTLE]
+ ld a, [wLinkState]
and a
ld a, Bank(TrainerPics) ; this is where all the trainer pics are (not counting Red's)
jr z, .loadSprite
@@ -7698,8 +7699,8 @@ StatModifierDownEffect: ; 3f54c (f:754c)
ld hl, wPlayerMonStatMods
ld de, W_ENEMYMOVEEFFECT
ld bc, W_PLAYERBATTSTATUS1
- ld a, [W_ISLINKBATTLE]
- cp $4
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
jr z, .statModifierDownEffect
call BattleRandom
cp $40 ; 1/4 chance to miss by in regular battle
@@ -7934,13 +7935,13 @@ StatModifierRatios: ; 3f6cb (f:76cb)
BideEffect: ; 3f6e5 (f:76e5)
ld hl, W_PLAYERBATTSTATUS1
- ld de, W_NUMHITS
+ ld de, wPlayerBideAccumulatedDamage
ld bc, wPlayerNumAttacksLeft
ld a, [H_WHOSETURN]
and a
jr z, .bideEffect
ld hl, W_ENEMYBATTSTATUS1
- ld de, wcd05
+ ld de, wEnemyBideAccumulatedDamage
ld bc, wEnemyNumAttacksLeft
.bideEffect
set StoringEnergy, [hl] ; mon is now using bide
@@ -8096,13 +8097,13 @@ WasBlownAwayText: ; 3f80c (f:780c)
TwoToFiveAttacksEffect: ; 3f811 (f:7811)
ld hl, W_PLAYERBATTSTATUS1
ld de, wPlayerNumAttacksLeft
- ld bc, W_NUMHITS
+ ld bc, wPlayerNumHits
ld a, [H_WHOSETURN]
and a
jr z, .twoToFiveAttacksEffect
ld hl, W_ENEMYBATTSTATUS1
ld de, wEnemyNumAttacksLeft
- ld bc, wcd05
+ ld bc, wEnemyNumHits
.twoToFiveAttacksEffect
bit AttackingMultipleTimes, [hl] ; is mon attacking multiple times?
ret nz
@@ -8394,8 +8395,8 @@ MimicEffect: ; 3f9ed (f:79ed)
ld hl, wBattleMonMoves
ld a, [W_PLAYERBATTSTATUS1]
jr nz, .asm_3fa13
- ld a, [W_ISLINKBATTLE]
- cp $4
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
jr nz, .asm_3fa3a
ld hl, wEnemyMonMoves
ld a, [W_ENEMYBATTSTATUS1]
@@ -8500,8 +8501,8 @@ DisableEffect: ; 3fa8a (f:7a8a)
and a
ld hl, wBattleMonPP
jr nz, .asm_3facf
- ld a, [W_ISLINKBATTLE]
- cp $4
+ ld a, [wLinkState]
+ cp LINK_STATE_BATTLING
pop hl
jr nz, .asm_3fae1
push hl
@@ -8629,7 +8630,7 @@ ParalyzedMayNotAttackText: ; 3fb74 (f:7b74)
CheckTargetSubstitute: ; 3fb79 (f:7b79)
push hl
ld hl, W_ENEMYBATTSTATUS2
- ld a, [$fff3]
+ ld a, [H_WHOSETURN]
and a
jr z, .next1
ld hl, W_PLAYERBATTSTATUS2
diff --git a/engine/battle/d.asm b/engine/battle/d.asm
index 94a07eb6..7320da29 100755
--- a/engine/battle/d.asm
+++ b/engine/battle/d.asm
@@ -9,7 +9,7 @@ DisplayLinkBattleVersusTextBox: ; 372d6 (d:72d6)
ld de, wPlayerName
call PlaceString
hlCoord 4, 10
- ld de, W_GRASSRATE ; enemy name
+ ld de, wLinkEnemyTrainerName
call PlaceString
; place bold "VS" tiles between the names
hlCoord 9, 8
diff --git a/engine/battle/e.asm b/engine/battle/e.asm
index dd227be7..9f93baa6 100755
--- a/engine/battle/e.asm
+++ b/engine/battle/e.asm
@@ -700,7 +700,7 @@ Func_39c37: ; 39c37 (e:5c37)
ReadTrainer: ; 39c53 (e:5c53)
; don't change any moves in a link battle
- ld a,[W_ISLINKBATTLE]
+ ld a,[wLinkState]
and a
ret nz
@@ -872,8 +872,8 @@ TrainerAI: ; 3a52e (e:652e)
ld a,[W_ISINBATTLE]
dec a
ret z ; if not a trainer, we're done here
- ld a,[W_ISLINKBATTLE]
- cp 4
+ ld a,[wLinkState]
+ cp LINK_STATE_BATTLING
ret z
ld a,[W_TRAINERCLASS] ; what trainer class is this?
dec a
@@ -1230,8 +1230,8 @@ SwitchEnemyMon: ; 3a74b (e:674b)
xor a
ld [wd11d],a
- ld a,[W_ISLINKBATTLE]
- cp 4
+ ld a,[wLinkState]
+ cp LINK_STATE_BATTLING
ret z
scf
ret