ref: 59d67a44be4f76131b432b94b1cb6361b58a9a26
parent: ac824f62fc6bdbc63f2f9fb7bd17e4827a535f36
author: PikalaxALT <PikalaxALT@gmail.com>
date: Sun Nov 8 14:09:36 EST 2015
Attempting to decode AI switching
--- a/battle/ai/items.asm
+++ b/battle/ai/items.asm
@@ -45,7 +45,7 @@
SwitchOften: ; 38045
callab CheckAbleToSwitch
- ld a, [wc717]
+ ld a, [wEnemySwitchMonParam]
and $f0
jp z, DontSwitch
@@ -52,7 +52,7 @@
cp $10
jr nz, .not_10
call Random
- cp $80
+ cp 1 + 50 percent
jr c, .switch
jp DontSwitch
.not_10
@@ -60,7 +60,7 @@
cp $20
jr nz, .not_20
call Random
- cp 200
+ cp -1 + 79 percent
jr c, .switch
jp DontSwitch
.not_20
@@ -67,21 +67,21 @@
; $30
call Random
- cp 10
+ cp 4 percent
jp c, DontSwitch
.switch
- ld a, [wc717]
+ ld a, [wEnemySwitchMonParam]
and $f
inc a
; In register 'a' is the number (1-6) of the Pkmn to switch to
- ld [wc718], a
+ ld [wEnemySwitchMonIndex], a
jp AI_TrySwitch
; 38083
SwitchRarely: ; 38083
callab CheckAbleToSwitch
- ld a, [wc717]
+ ld a, [wEnemySwitchMonParam]
and $f0
jp z, DontSwitch
@@ -88,7 +88,7 @@
cp $10
jr nz, .not_10
call Random
- cp 20
+ cp 8 percent
jr c, .switch
jp DontSwitch
.not_10
@@ -96,7 +96,7 @@
cp $20
jr nz, .not_20
call Random
- cp 30
+ cp 12 percent
jr c, .switch
jp DontSwitch
.not_20
@@ -103,20 +103,20 @@
; $30
call Random
- cp 200
+ cp -1 + 79 percent
jp c, DontSwitch
.switch
- ld a, [wc717]
+ ld a, [wEnemySwitchMonParam]
and $f
inc a
- ld [wc718], a
+ ld [wEnemySwitchMonIndex], a
jp AI_TrySwitch
; 380c1
SwitchSometimes: ; 380c1
callab CheckAbleToSwitch
- ld a, [wc717]
+ ld a, [wEnemySwitchMonParam]
and $f0
jp z, DontSwitch
@@ -123,7 +123,7 @@
cp $10
jr nz, .not_10
call Random
- cp 50
+ cp -1 + 20 percent
jr c, .switch
jp DontSwitch
.not_10
@@ -131,7 +131,7 @@
cp $20
jr nz, .not_20
call Random
- cp $80
+ cp 1 + 50 percent
jr c, .switch
jp DontSwitch
.not_20
@@ -138,14 +138,14 @@
; $30
call Random
- cp 50
+ cp -1 + 20 percent
jp c, DontSwitch
.switch
- ld a, [wc717]
+ ld a, [wEnemySwitchMonParam]
and $f
inc a
- ld [wc718], a
+ ld [wEnemySwitchMonIndex], a
jp AI_TrySwitch
; 380ff
@@ -225,7 +225,7 @@
xor a
ld [de], a
inc a
- ld [wc70f], a
+ ld [wEnemyGoesFirst], a
ld hl, EnemySubStatus3
res SUBSTATUS_BIDE, [hl]
@@ -701,7 +701,7 @@
AI_Switch: ; 3846c
ld a, $1
ld [wEnemyIsSwitching], a
- ld [wc70f], a
+ ld [wEnemyGoesFirst], a
ld hl, EnemySubStatus4
res SUBSTATUS_RAGE, [hl]
xor a
--- a/battle/ai/scoring.asm
+++ b/battle/ai/scoring.asm
@@ -576,7 +576,7 @@
; Unless this is the enemy's last Pokemon...
push hl
- callba CheckEnemyHasMonToSwitchTo
+ callba FindAliveEnemyMons
pop hl
jr nc, .asm_388b7
@@ -2028,7 +2028,7 @@
jp nz, AIDiscourageMove
push hl
- callba CheckEnemyHasMonToSwitchTo
+ callba FindAliveEnemyMons
pop hl
jr nc, .asm_38eb0
@@ -2160,7 +2160,7 @@
AI_Smart_PerishSong: ; 38f4a
push hl
- callab CheckEnemyHasMonToSwitchTo
+ callab FindAliveEnemyMons
pop hl
jr c, .no
--- a/battle/ai/switch.asm
+++ b/battle/ai/switch.asm
@@ -183,8 +183,8 @@
CheckAbleToSwitch: ; 34941
xor a
- ld [wc717], a
- call CheckEnemyHasMonToSwitchTo
+ ld [wEnemySwitchMonParam], a
+ call FindAliveEnemyMons
ret c
ld a, [EnemySubStatus1]
@@ -197,9 +197,9 @@
; Perish count is 1
- call CheckEnemyHasMonToSwitchTo
- call Function34b77
- call Function34b20
+ call FindAliveEnemyMons
+ call FindEnemyMonsWithEnoughHP
+ call FindEnemyMonsThatResistPlayer
call Function34a85
ld a, e
@@ -208,11 +208,11 @@
ld a, [wc716]
add $30
- ld [wc717], a
+ ld [wEnemySwitchMonParam], a
ret
.not_2
- call CheckEnemyHasMonToSwitchTo
+ call FindAliveEnemyMons
sla c
sla c
ld b, $ff
@@ -224,7 +224,7 @@
ld a, b
add $30
- ld [wc717], a
+ ld [wEnemySwitchMonParam], a
ret
.no_perish
@@ -236,12 +236,12 @@
ld a, [LastEnemyCounterMove]
and a
- jr z, .asm_349d2
+ jr z, .no_last_counter_move
call Function34a2a
ld a, [wc716]
and a
- jr z, .asm_349d2
+ jr z, .no_last_counter_move
ld c, a
call Function34aa7
@@ -252,7 +252,7 @@
ld b, a
ld a, e
cp 2
- jr z, .asm_349be
+ jr z, .not_2_again
call CheckPlayerMoveTypeMatchups
ld a, [wc716]
@@ -261,32 +261,32 @@
ld a, b
add $10
- ld [wc717], a
+ ld [wEnemySwitchMonParam], a
ret
-.asm_349be
+.not_2_again
ld c, $10
call CheckPlayerMoveTypeMatchups
ld a, [wc716]
cp 10
- jr nc, .asm_349cc
+ jr nc, .okay
ld c, $20
-.asm_349cc
+.okay
ld a, b
add c
- ld [wc717], a
+ ld [wEnemySwitchMonParam], a
ret
-.asm_349d2
+.no_last_counter_move
call CheckPlayerMoveTypeMatchups
ld a, [wc716]
cp 10
ret nc
- call CheckEnemyHasMonToSwitchTo
- call Function34b77
- call Function34b20
+ call FindAliveEnemyMons
+ call FindEnemyMonsWithEnoughHP
+ call FindEnemyMonsThatResistPlayer
call Function34a85
ld a, e
@@ -295,12 +295,12 @@
ld a, [wc716]
add $10
- ld [wc717], a
+ ld [wEnemySwitchMonParam], a
ret
; 349f4
-CheckEnemyHasMonToSwitchTo: ; 349f4
+FindAliveEnemyMons: ; 349f4
ld a, [OTPartyCount]
cp 2
jr c, .only_one
@@ -421,16 +421,16 @@
ld hl, OTPartyMon1HP
ld b, 1 << (PARTY_LENGTH - 1)
ld c, 0
-.asm_34a91
+.loop
ld a, [hli]
or [hl]
- jr z, .asm_34a98
+ jr z, .next
ld a, b
or c
ld c, a
-.asm_34a98
+.next
srl b
push bc
ld bc, PartyMon2HP - (PartyMon1HP + 1)
@@ -437,7 +437,7 @@
add hl, bc
pop bc
dec e
- jr nz, .asm_34a91
+ jr nz, .loop
ld a, c
pop bc
@@ -456,26 +456,26 @@
ld b, 1 << (PARTY_LENGTH - 1)
ld d, 0
ld e, 0
-.asm_34ab5
+.loop
ld a, b
and c
- jr z, .asm_34b00
+ jr z, .next
push hl
push bc
ld b, NUM_MOVES
ld c, 0
-.asm_34abf
+.loop3
ld a, [hli]
and a
push hl
- jr z, .asm_34aef
+ jr z, .break3
dec a
ld hl, Moves + MOVE_POWER
call GetMoveAttr
and a
- jr z, .asm_34ae9
+ jr z, .nope
inc hl
call GetMoveByte
@@ -483,46 +483,46 @@
call CheckTypeMatchup
ld a, [wTypeMatchup]
cp 10
- jr c, .asm_34ae9
+ jr c, .nope
ld e, 1
- cp 11
- jr c, .asm_34ae9
+ cp 10 + 1
+ jr c, .nope
ld e, 2
- jr .asm_34aef
+ jr .break3
-.asm_34ae9
+.nope
pop hl
dec b
- jr nz, .asm_34abf
+ jr nz, .loop3
- jr .asm_34af0
+ jr .done
-.asm_34aef
+.break3
pop hl
-.asm_34af0
+.done
ld a, e
pop bc
pop hl
cp $2
- jr z, .asm_34b0e
+ jr z, .done2
cp $1
- jr nz, .asm_34b00
+ jr nz, .next
ld a, d
or b
ld d, a
- jr .asm_34b00
+ jr .next
-.asm_34b00
+.next
push bc
ld bc, PARTYMON_STRUCT_LENGTH
add hl, bc
pop bc
srl b
- jr nc, .asm_34ab5
+ jr nc, .loop
ld a, d
ld b, a
@@ -529,15 +529,15 @@
and a
ret z
-.asm_34b0e
+.done2
push bc
sla b
sla b
ld c, $ff
-.asm_34b15
+.loop2
inc c
sla b
- jr nc, .asm_34b15
+ jr nc, .loop2
ld a, c
ld [wc716], a
@@ -546,16 +546,16 @@
; 34b20
-Function34b20: ; 34b20
+FindEnemyMonsThatResistPlayer: ; 34b20
push bc
ld hl, OTPartySpecies
ld b, 1 << (PARTY_LENGTH - 1)
ld c, 0
-.asm_34b28
+.loop
ld a, [hli]
cp $ff
- jr z, .asm_34b72
+ jr z, .done
push hl
ld [CurSpecies], a
@@ -562,44 +562,44 @@
call GetBaseData
ld a, [LastEnemyCounterMove]
and a
- jr z, .asm_34b4a
+ jr z, .skip_move
dec a
ld hl, Moves + MOVE_POWER
call GetMoveAttr
and a
- jr z, .asm_34b4a
+ jr z, .skip_move
inc hl
call GetMoveByte
- jr .asm_34b5d
+ jr .check_type
-.asm_34b4a
+.skip_move
ld a, [BattleMonType1]
ld hl, BaseType
call CheckTypeMatchup
ld a, [wTypeMatchup]
- cp $b
- jr nc, .asm_34b6d
+ cp 10 + 1
+ jr nc, .dont_choose_mon
ld a, [BattleMonType2]
-.asm_34b5d
+.check_type
ld hl, BaseType
call CheckTypeMatchup
ld a, [wTypeMatchup]
- cp $b
- jr nc, .asm_34b6d
+ cp 10 + 1
+ jr nc, .dont_choose_mon
ld a, b
or c
ld c, a
-.asm_34b6d
+.dont_choose_mon
srl b
pop hl
- jr .asm_34b28
+ jr .loop
-.asm_34b72
+.done
ld a, c
pop bc
and c
@@ -608,7 +608,7 @@
; 34b77
-Function34b77: ; 34b77
+FindEnemyMonsWithEnoughHP: ; 34b77
push bc
ld de, OTPartySpecies
ld b, 1 << (PARTY_LENGTH - 1)
@@ -629,10 +629,14 @@
rept 2
inc hl
endr
+; hl = MaxHP + 1
+; b = (4 * b) % $100 + (c & 3)
+; c = c / 4
srl c
rl b
srl c
rl b
+; a = (MaxHP / $100) - b - (1 if c > (MaxHP % $100) else 0)
ld a, [hld]
cp c
ld a, [hl]
--- a/battle/core.asm
+++ b/battle/core.asm
@@ -38,7 +38,7 @@
dec a
jr z, .wild
xor a
- ld [wc718], a
+ ld [wEnemySwitchMonIndex], a
call NewEnemyMonStatus
call ResetEnemyStatLevels
call BreakAttraction
@@ -104,7 +104,7 @@
cp $2
jr nz, .not_linked_2
xor a
- ld [wc718], a
+ ld [wEnemySwitchMonIndex], a
call NewEnemyMonStatus
call ResetEnemyStatLevels
call BreakAttraction
@@ -136,7 +136,7 @@
and $c0
ld [wBattleResult], a
ld hl, BattleText_EnemyFled
- call Function3d2e0
+ call CheckMobileBattleError
jr nc, .asm_3c115
ld hl, wcd2a
@@ -150,7 +150,7 @@
.asm_3c118
call StopDangerSound
- call Function3d2e0
+ call CheckMobileBattleError
jr c, .asm_3c126
ld de, SFX_RUN
@@ -179,7 +179,7 @@
ld [CurDamage], a
ld [CurDamage + 1], a
- call Function3c27c
+ call HandleBerserkGene
call UpdateBattleMonInParty
callba AIChooseMove
@@ -191,7 +191,7 @@
jp c, .quit
.not_disconnected
- call Function3c410
+ call CheckPlayerLockedIn
jr c, .skip_iteration
.loop1
call BattleMenu
@@ -199,27 +199,27 @@
ld a, [BattleEnded]
and a
jr nz, .quit
- ld a, [wd232] ; roared/whirlwinded/teleported
+ ld a, [wForcedSwitch] ; roared/whirlwinded/teleported
and a
jr nz, .quit
.skip_iteration
- call Function3c434
+ call ParsePlayerAction
jr nz, .loop1
- call Function3c300
+ call EnemyTriesToFlee
jr c, .quit
call DetermineMoveOrder
jr c, .false
- call Function3c5fe
+ call Battle_EnemyFirst
jr .proceed
.false
- call Function3c664
+ call Battle_PlayerFirst
.proceed
- call Function3d2e0
+ call CheckMobileBattleError
jr c, .quit
- ld a, [wd232]
+ ld a, [wForcedSwitch]
and a
jr nz, .quit
@@ -355,7 +355,7 @@
ret
; 3c27c
-Function3c27c: ; 3c27c
+HandleBerserkGene: ; 3c27c
ld a, [hLinkPlayerNumber]
cp $1
jr z, .reverse
@@ -432,7 +432,7 @@
jp StdBattleTextBox
; 3c300
-Function3c300: ; 3c300
+EnemyTriesToFlee: ; 3c300
ld a, [wLinkMode]
and a
jr z, .not_linked
@@ -592,7 +592,7 @@
ret
; 3c410
-Function3c410: ; 3c410
+CheckPlayerLockedIn: ; 3c410
ld a, [PlayerSubStatus4]
and 1 << SUBSTATUS_RECHARGE
jp nz, .quit
@@ -618,25 +618,25 @@
ret
; 3c434
-Function3c434: ; 3c434
- call Function3c410
- jp c, .asm_3c4ba
+ParsePlayerAction: ; 3c434
+ call CheckPlayerLockedIn
+ jp c, .locked_in
ld hl, PlayerSubStatus5
bit SUBSTATUS_ENCORED, [hl]
- jr z, .asm_3c449
+ jr z, .not_encored
ld a, [LastPlayerMove]
ld [CurPlayerMove], a
- jr .asm_3c47c
+ jr .encored
-.asm_3c449
+.not_encored
ld a, [wd0ec]
cp $2
- jr z, .asm_3c4ce
+ jr z, .reset_rage
and a
- jr nz, .asm_3c4b5
+ jr nz, .reset_bide
ld a, [PlayerSubStatus3]
and 1 << SUBSTATUS_BIDE
- jr nz, .asm_3c4ba
+ jr nz, .locked_in
xor a
ld [wd235], a
inc a ; POUND
@@ -647,16 +647,16 @@
call UpdateBattleHuds
ld a, [CurPlayerMove]
cp STRUGGLE
- jr z, .asm_3c476
+ jr z, .struggle
call PlayClickSFX
-.asm_3c476
+.struggle
ld a, $1
ld [hBGMapMode], a
pop af
ret nz
-.asm_3c47c
+.encored
call SetPlayerTurn
callab UpdateMoveData
xor a
@@ -663,34 +663,34 @@
ld [wPlayerCharging], a
ld a, [wPlayerMoveStruct + MOVE_EFFECT]
cp EFFECT_FURY_CUTTER
- jr z, .asm_3c494
+ jr z, .continue_fury_cutter
xor a
ld [PlayerFuryCutterCount], a
-.asm_3c494
+.continue_fury_cutter
ld a, [wPlayerMoveStruct + MOVE_EFFECT]
cp EFFECT_RAGE
- jr z, .asm_3c4a4
+ jr z, .continue_rage
ld hl, PlayerSubStatus4
res SUBSTATUS_RAGE, [hl]
xor a
ld [wPlayerRageCounter], a
-.asm_3c4a4
+.continue_rage
ld a, [wPlayerMoveStruct + MOVE_EFFECT]
cp EFFECT_PROTECT
- jr z, .asm_3c4c9
+ jr z, .continue_protect
cp EFFECT_ENDURE
- jr z, .asm_3c4c9
+ jr z, .continue_protect
xor a
ld [PlayerProtectCount], a
- jr .asm_3c4c9
+ jr .continue_protect
-.asm_3c4b5
+.reset_bide
ld hl, PlayerSubStatus3
res SUBSTATUS_BIDE, [hl]
-.asm_3c4ba
+.locked_in
xor a
ld [PlayerFuryCutterCount], a
ld [PlayerProtectCount], a
@@ -698,12 +698,12 @@
ld hl, PlayerSubStatus4
res SUBSTATUS_RAGE, [hl]
-.asm_3c4c9
- call Function3e7c1
+.continue_protect
+ call ParseEnemyAction
xor a
ret
-.asm_3c4ce
+.reset_rage
xor a
ld [PlayerFuryCutterCount], a
ld [PlayerProtectCount], a
@@ -932,19 +932,19 @@
; 3c5fe
-Function3c5fe: ; 3c5fe
+Battle_EnemyFirst: ; 3c5fe
call LoadTileMapToTempTileMap
call TryEnemyFlee
jp c, WildFled_EnemyFled_LinkBattleCanceled
call SetEnemyTurn
ld a, $1
- ld [wc70f], a
+ ld [wEnemyGoesFirst], a
callab AI_SwitchOrTryItem
jr c, .switch_item
call EnemyTurn_EndOpponentProtectEndureDestinyBond
- call Function3d2e0
+ call CheckMobileBattleError
ret c
- ld a, [wd232]
+ ld a, [wForcedSwitch]
and a
ret nz
call HasPlayerFainted
@@ -958,9 +958,9 @@
jp z, HandleEnemyMonFaint
call RefreshBattleHuds
call PlayerTurn_EndOpponentProtectEndureDestinyBond
- call Function3d2e0
+ call CheckMobileBattleError
ret c
- ld a, [wd232]
+ ld a, [wForcedSwitch]
and a
ret nz
call HasEnemyFainted
@@ -976,18 +976,18 @@
ret
; 3c664
-Function3c664: ; 3c664
+Battle_PlayerFirst: ; 3c664
xor a
- ld [wc70f], a
+ ld [wEnemyGoesFirst], a
call SetEnemyTurn
callab AI_SwitchOrTryItem
push af
call PlayerTurn_EndOpponentProtectEndureDestinyBond
pop bc
- ld a, [wd232]
+ ld a, [wForcedSwitch]
and a
ret nz
- call Function3d2e0
+ call CheckMobileBattleError
ret c
call HasEnemyFainted
jp z, HandleEnemyMonFaint
@@ -1006,9 +1006,9 @@
call TryEnemyFlee
jp c, WildFled_EnemyFled_LinkBattleCanceled
call EnemyTurn_EndOpponentProtectEndureDestinyBond
- call Function3d2e0
+ call CheckMobileBattleError
ret c
- ld a, [wd232]
+ ld a, [wForcedSwitch]
and a
ret nz
call HasPlayerFainted
@@ -2154,7 +2154,7 @@
.dont_flee
call Function3d227
- call Function3d2e0
+ call CheckMobileBattleError
jp c, WildFled_EnemyFled_LinkBattleCanceled
ld a, $1
@@ -2437,7 +2437,7 @@
EnemyPartyMonEntrance: ; 3cf78
push af
xor a
- ld [wc718], a
+ ld [wEnemySwitchMonIndex], a
call NewEnemyMonStatus
call ResetEnemyStatLevels
call BreakAttraction
@@ -2805,7 +2805,7 @@
.asm_3d190
call Function3d227
- call Function3d2e0
+ call CheckMobileBattleError
jp c, WildFled_EnemyFled_LinkBattleCanceled
ld a, c
and a
@@ -2900,7 +2900,7 @@
.skip_link
xor a
ld [wd0ec], a
- call Function3d2e0
+ call CheckMobileBattleError
jr c, .asm_3d251
ld hl, EnemyMonHP
ld a, [hli]
@@ -2968,7 +2968,7 @@
; 3d2e0
-Function3d2e0: ; 3d2e0
+CheckMobileBattleError: ; 3d2e0
ld a, [wLinkMode]
cp LINK_MOBILE
jr nz, .not_mobile ; It's not a mobile battle
@@ -3057,7 +3057,7 @@
.pick
call PickPartyMonInBattle
ret nc
- call Function3d2e0
+ call CheckMobileBattleError
ret c
ld de, SFX_WRONG
@@ -3082,7 +3082,7 @@
.pick
call ForcePickPartyMonInBattle
- call Function3d2e0
+ call CheckMobileBattleError
ret c
call SwitchMonAlreadyOut
jr c, .pick
@@ -3306,7 +3306,7 @@
Function3d4c3: ; 3d4c3
call ResetEnemyBattleVars
- ld a, [wc718]
+ ld a, [wEnemySwitchMonIndex]
dec a
ld b, a
call LoadEnemyPkmnToSwitchTo
@@ -3376,7 +3376,7 @@
jr .return_carry
.not_linked
- ld a, [wc718]
+ ld a, [wEnemySwitchMonIndex]
and a
jr z, .check_wd264
@@ -4031,8 +4031,8 @@
ld [CurPlayerMove], a
call Function3e8e4
call Call_LoadTempTileMapToTileMap
- call Function3d2e0
- jr c, .asm_3d9f5
+ call CheckMobileBattleError
+ jr c, .mobile
; Got away safely
ld a, [wBattleAction]
@@ -4059,15 +4059,15 @@
scf
ret
-.asm_3d9f5
+.mobile
call StopDangerSound
ld hl, wcd2a
bit 4, [hl]
- jr nz, .asm_3da05
+ jr nz, .skip_link_error
ld hl, BattleText_LinkErrorBattleCanceled
call StdBattleTextBox
-.asm_3da05
+.skip_link_error
call WaitSFX
call LoadTileMapToTempTileMap
scf
@@ -5353,13 +5353,13 @@
jr .asm_3e2a8
.asm_3e2c8
- call Function3d2e0
+ call CheckMobileBattleError
jr c, .asm_3e2da
jr Function3e299
.asm_3e2cf
call Function3e308
- call Function3d2e0
+ call CheckMobileBattleError
jr c, .asm_3e2da
jp Function3e290
@@ -5470,7 +5470,7 @@
call WriteBackup
.not_linked
- call Function3e7c1
+ call ParseEnemyAction
ld a, [wLinkMode]
and a
jr nz, .linked
@@ -6070,7 +6070,7 @@
-Function3e7c1: ; 3e7c1
+ParseEnemyAction: ; 3e7c1
ld a, [wEnemyIsSwitching]
and a
ret nz
@@ -8740,7 +8740,7 @@
ld [OtherTrainerClass], a
ld [wd266], a
ld [wd267], a
- ld [wd232], a
+ ld [wForcedSwitch], a
ld [wd0d8], a
ld [wKeyItemsPocketCursor], a
ld [wItemsPocketCursor], a
@@ -8813,7 +8813,7 @@
; 3f77c
Function3f77c: ; 3f77c
- callba Function3d2e0
+ callba CheckMobileBattleError
jp c, Function3f80f
call Function3f830
jr nz, .asm_3f797
--- a/battle/effect_commands.asm
+++ b/battle/effect_commands.asm
@@ -6530,7 +6530,7 @@
xor a
ld [wcfca], a
inc a
- ld [wd232], a
+ ld [wForcedSwitch], a
ld [wKickCounter], a
call SetBattleDraw
call BattleCommand_LowerSub
@@ -6598,15 +6598,15 @@
xor a
ld [wcfca], a
inc a
- ld [wd232], a
+ ld [wForcedSwitch], a
call SetBattleDraw
ld a, [wPlayerMoveStruct + MOVE_ANIM]
jp .succeed
.trainer
- call CheckEnemyHasMonToSwitchTo
+ call FindAliveEnemyMons
jr c, .switch_fail ; 3686c $5c
- ld a, [wc70f]
+ ld a, [wEnemyGoesFirst]
and a
jr z, .switch_fail ; 36872 $56
call UpdateEnemyMonInParty
@@ -6643,7 +6643,7 @@
jr z, .random_loop_trainer ; 368b1 $e7
ld a, d
inc a
- ld [wc718], a
+ ld [wEnemySwitchMonIndex], a
callab Function3d4c3
ld hl, DraggedOutText
@@ -6691,7 +6691,7 @@
xor a
ld [wcfca], a
inc a
- ld [wd232], a
+ ld [wForcedSwitch], a
call SetBattleDraw
ld a, [wEnemyMoveStruct + MOVE_ANIM]
jr .succeed
@@ -6700,7 +6700,7 @@
call CheckPlayerHasMonToSwitchTo
jr c, .fail
- ld a, [wc70f]
+ ld a, [wEnemyGoesFirst]
cp $1
jr z, .switch_fail
@@ -6991,7 +6991,7 @@
Function36abf: ; 36abf
push bc
- ld a, [wc70f]
+ ld a, [wEnemyGoesFirst]
ld b, a
ld a, [hBattleTurn]
xor b
@@ -8943,7 +8943,7 @@
call BatonPass_LinkPlayerSwitch
; Mobile link battles handle entrances differently
- callba Function3d2e0
+ callba CheckMobileBattleError
jp c, EndMoveEffect
ld hl, PassedBattleMonEntrance
@@ -8968,12 +8968,12 @@
call BatonPass_LinkEnemySwitch
; Mobile link battles handle entrances differently
- callba Function3d2e0
+ callba CheckMobileBattleError
jp c, EndMoveEffect
; Passed enemy PartyMon entrance
xor a
- ld [wc718], a
+ ld [wEnemySwitchMonIndex], a
ld hl, EnemySwitch_SetMode
call CallBattleCore
ld hl, ResetBattleParticipants
--- a/items/item_effects.asm
+++ b/items/item_effects.asm
@@ -2288,7 +2288,7 @@
dec a
jr nz, .asm_f4a6
inc a
- ld [wd232], a
+ ld [wForcedSwitch], a
ld a, [wBattleResult]
and 3 << 6
or $2
--- a/main.asm
+++ b/main.asm
@@ -32256,7 +32256,7 @@
ld [BattleMonSpecies], a
ld [wBattleParticipantsNotFainted], a
ld [CurBattleMon], a
- ld [wd232], a
+ ld [wForcedSwitch], a
ld [TimeOfDayPal], a
ld [PlayerTurnsTaken], a
ld [EnemyTurnsTaken], a
@@ -33688,7 +33688,7 @@
; so we have always the same AI, regardless of the loaded class of trainer
ld a, [InBattleTowerBattle]
bit 0, a
- jr nz, .asm_4412f
+ jr nz, .battle_tower_skip
ld a, [TrainerClass]
dec a
@@ -33695,7 +33695,7 @@
ld bc, 7 ; Trainer2AI - Trainer1AI
call AddNTimes
-.asm_4412f
+.battle_tower_skip
lb bc, CHECK_FLAG, 0
push bc
push hl
@@ -33766,12 +33766,12 @@
.PickLowestScoreMoves
ld a, c
-.asm_44175
+.move_loop
inc [hl]
dec hl
inc a
cp NUM_MOVES + 1
- jr nz, .asm_44175
+ jr nz, .move_loop
ld hl, Buffer1
ld de, EnemyMonMoves
@@ -33778,28 +33778,28 @@
ld c, NUM_MOVES
; Give a score of 0 to a blank move
-.asm_44184
+.loop2
ld a, [de]
and a
- jr nz, .asm_44189
+ jr nz, .skip_load
ld [hl], a
; Disregard the move if its score is not 1
-.asm_44189
+.skip_load
ld a, [hl]
dec a
- jr z, .asm_44191
+ jr z, .keep
xor a
ld [hli], a
- jr .asm_44193
+ jr .after_toss
-.asm_44191
+.keep
ld a, [de]
ld [hli], a
-.asm_44193
+.after_toss
inc de
dec c
- jr nz, .asm_44184
+ jr nz, .loop2
; Randomly choose one of the moves with a score of 1
.ChooseMove
@@ -60912,7 +60912,7 @@
; 92ee0
Function92ee0: ; 92ee0
- ld hl, wc70f
+ ld hl, wEnemyGoesFirst
ld a, [wc700]
cp [hl]
call z, Function92f0c
@@ -60920,7 +60920,7 @@
; 92eeb
Function92eeb: ; 92eeb
- ld hl, wc70f
+ ld hl, wEnemyGoesFirst
ld a, [wc701]
cp [hl]
call z, Function92f0c
@@ -60928,7 +60928,7 @@
; 92ef6
Function92ef6: ; 92ef6
- ld hl, wc70f
+ ld hl, wEnemyGoesFirst
ld a, [wc702]
cp [hl]
call z, Function92f0c
@@ -61033,7 +61033,7 @@
; 92f80
Function92f80: ; 92f80
- ld hl, wc70f
+ ld hl, wEnemyGoesFirst
ld a, [wc701]
cp [hl]
ret nz
--- a/misc/mobile_5f.asm
+++ b/misc/mobile_5f.asm
@@ -1928,7 +1928,7 @@
ld a, $5c
ld [wc70e], a
ld a, $1
- ld [wc70f], a
+ ld [wEnemyGoesFirst], a
ld hl, wc708
call LoadMenuDataHeader
call InterpretMenu2
@@ -2155,7 +2155,7 @@
jr .asm_17ddc9
.asm_17ddb7
- ld a, [wc70f]
+ ld a, [wEnemyGoesFirst]
ld l, a
ld a, [wc710]
ld h, a
@@ -2219,7 +2219,7 @@
jr nz, .asm_17de26
ld a, [wc70e]
ld l, a
- ld a, [wc70f]
+ ld a, [wEnemyGoesFirst]
ld h, a
jr .asm_17de2e
@@ -2277,7 +2277,7 @@
.asm_17de78
ld a, [wc70e]
ld l, a
- ld a, [wc70f]
+ ld a, [wEnemyGoesFirst]
ld h, a
jr .asm_17de8a
@@ -2879,7 +2879,7 @@
jr .asm_17e250
.asm_17e23e
- ld a, [wc70f]
+ ld a, [wEnemyGoesFirst]
ld l, a
ld a, [wc710]
ld h, a
--- a/wram.asm
+++ b/wram.asm
@@ -452,7 +452,7 @@
ds -70
wBT_OTTemp:: battle_tower_struct wBT_OTTemp
- ds -BATTLE_TOWER_STRUCT_LENGTH
+ ds wBT_OTTemp - @
wMisc::
wBattle::
@@ -818,7 +818,7 @@
FailedMessage:: ; c70e
ds 1
-wc70f:: ds 1
+wEnemyGoesFirst:: ds 1
wc710::
wPlayerIsSwitching:: ds 1 ; c710
wc711::
@@ -831,8 +831,9 @@
ds NUM_MOVES
wc716:: ds 1
+wEnemySwitchMonParam::
wc717:: ds 1
-wc718:: ds 1
+wEnemySwitchMonIndex:: ds 1
wc719:: ds 1
LastPlayerMon:: ; c71a
wc71a:: ds 1
@@ -912,25 +913,6 @@
wc7e8:: ds 24
-
-RSSET 0 ; Offsets for wBT_OTTemp:: @ $c608
-wBT_OTTemp_0 RB NAME_LENGTH + -1 ; $c608
-wBT_OTTemp_TrainerClass RB 1 ; $c608 + $a = $c612
-wBT_OTTemp_Pkmn1 RB $30 ; PARTYMON_STRUCT_LENGTH ; $c608 + $b = $c613
-wBT_OTTemp_Pkmn1Name RB PKMN_NAME_LENGTH + -1 ; $c608 + $45 = $c64d
-wBT_OTTemp_45 RB 1
-wBT_OTTemp_Pkmn2 RB $30 ; PARTYMON_STRUCT_LENGTH ; $c608 + $46 = $c64e
-wBT_OTTemp_Pkmn2Name RB PKMN_NAME_LENGTH + -1 ; $c608 + $76 = $c67e
-wBT_OTTemp_80 RB 1
-wBT_OTTemp_Pkmn3 RB $30 ; PARTYMON_STRUCT_LENGTH ; $c608 + $81 = $c689
-wBT_OTTemp_Pkmn3Name RB PKMN_NAME_LENGTH + -1 ; $c608 + $b1 = $c6b9
-wBT_OTTemp_BB RB 1
-
-GLOBAL wBT_OTTemp_TrainerClass, wBT_OTTemp_Pkmn1, wBT_OTTemp_Pkmn1Name, wBT_OTTemp_Pkmn2, wBT_OTTemp_Pkmn2Name, wBT_OTTemp_Pkmn3, wBT_OTTemp_Pkmn3Name
-GLOBAL wBT_OTTemp_45, wBT_OTTemp_80, wBT_OTTemp_BB
-
-
-
SECTION "Overworld Map", WRAM0 [$c800]
wc800::
@@ -1863,7 +1845,7 @@
; (Joey, Mikey, Albert, etc.)
ds 1
-wd232:: ds 1
+wForcedSwitch:: ds 1
TrainerClass:: ; d233
ds 1