Attempting to decode AI switching

This commit is contained in:
PikalaxALT
2015-11-08 19:09:36 -05:00
parent ac824f62fc
commit 59d67a44be
9 changed files with 202 additions and 216 deletions

View File

@@ -45,14 +45,14 @@ DontSwitch: ; 38041
SwitchOften: ; 38045 SwitchOften: ; 38045
callab CheckAbleToSwitch callab CheckAbleToSwitch
ld a, [wc717] ld a, [wEnemySwitchMonParam]
and $f0 and $f0
jp z, DontSwitch jp z, DontSwitch
cp $10 cp $10
jr nz, .not_10 jr nz, .not_10
call Random call Random
cp $80 cp 1 + 50 percent
jr c, .switch jr c, .switch
jp DontSwitch jp DontSwitch
.not_10 .not_10
@@ -60,35 +60,35 @@ SwitchOften: ; 38045
cp $20 cp $20
jr nz, .not_20 jr nz, .not_20
call Random call Random
cp 200 cp -1 + 79 percent
jr c, .switch jr c, .switch
jp DontSwitch jp DontSwitch
.not_20 .not_20
; $30 ; $30
call Random call Random
cp 10 cp 4 percent
jp c, DontSwitch jp c, DontSwitch
.switch .switch
ld a, [wc717] ld a, [wEnemySwitchMonParam]
and $f and $f
inc a inc a
; In register 'a' is the number (1-6) of the Pkmn to switch to ; In register 'a' is the number (1-6) of the Pkmn to switch to
ld [wc718], a ld [wEnemySwitchMonIndex], a
jp AI_TrySwitch jp AI_TrySwitch
; 38083 ; 38083
SwitchRarely: ; 38083 SwitchRarely: ; 38083
callab CheckAbleToSwitch callab CheckAbleToSwitch
ld a, [wc717] ld a, [wEnemySwitchMonParam]
and $f0 and $f0
jp z, DontSwitch jp z, DontSwitch
cp $10 cp $10
jr nz, .not_10 jr nz, .not_10
call Random call Random
cp 20 cp 8 percent
jr c, .switch jr c, .switch
jp DontSwitch jp DontSwitch
.not_10 .not_10
@@ -96,34 +96,34 @@ SwitchRarely: ; 38083
cp $20 cp $20
jr nz, .not_20 jr nz, .not_20
call Random call Random
cp 30 cp 12 percent
jr c, .switch jr c, .switch
jp DontSwitch jp DontSwitch
.not_20 .not_20
; $30 ; $30
call Random call Random
cp 200 cp -1 + 79 percent
jp c, DontSwitch jp c, DontSwitch
.switch .switch
ld a, [wc717] ld a, [wEnemySwitchMonParam]
and $f and $f
inc a inc a
ld [wc718], a ld [wEnemySwitchMonIndex], a
jp AI_TrySwitch jp AI_TrySwitch
; 380c1 ; 380c1
SwitchSometimes: ; 380c1 SwitchSometimes: ; 380c1
callab CheckAbleToSwitch callab CheckAbleToSwitch
ld a, [wc717] ld a, [wEnemySwitchMonParam]
and $f0 and $f0
jp z, DontSwitch jp z, DontSwitch
cp $10 cp $10
jr nz, .not_10 jr nz, .not_10
call Random call Random
cp 50 cp -1 + 20 percent
jr c, .switch jr c, .switch
jp DontSwitch jp DontSwitch
.not_10 .not_10
@@ -131,21 +131,21 @@ SwitchSometimes: ; 380c1
cp $20 cp $20
jr nz, .not_20 jr nz, .not_20
call Random call Random
cp $80 cp 1 + 50 percent
jr c, .switch jr c, .switch
jp DontSwitch jp DontSwitch
.not_20 .not_20
; $30 ; $30
call Random call Random
cp 50 cp -1 + 20 percent
jp c, DontSwitch jp c, DontSwitch
.switch .switch
ld a, [wc717] ld a, [wEnemySwitchMonParam]
and $f and $f
inc a inc a
ld [wc718], a ld [wEnemySwitchMonIndex], a
jp AI_TrySwitch jp AI_TrySwitch
; 380ff ; 380ff
@@ -225,7 +225,7 @@ endr
xor a xor a
ld [de], a ld [de], a
inc a inc a
ld [wc70f], a ld [wEnemyGoesFirst], a
ld hl, EnemySubStatus3 ld hl, EnemySubStatus3
res SUBSTATUS_BIDE, [hl] res SUBSTATUS_BIDE, [hl]
@@ -701,7 +701,7 @@ AI_TrySwitch: ; 3844b
AI_Switch: ; 3846c AI_Switch: ; 3846c
ld a, $1 ld a, $1
ld [wEnemyIsSwitching], a ld [wEnemyIsSwitching], a
ld [wc70f], a ld [wEnemyGoesFirst], a
ld hl, EnemySubStatus4 ld hl, EnemySubStatus4
res SUBSTATUS_RAGE, [hl] res SUBSTATUS_RAGE, [hl]
xor a xor a

View File

@@ -576,7 +576,7 @@ AI_Smart_Explosion: ; 388a6
; Unless this is the enemy's last Pokemon... ; Unless this is the enemy's last Pokemon...
push hl push hl
callba CheckEnemyHasMonToSwitchTo callba FindAliveEnemyMons
pop hl pop hl
jr nc, .asm_388b7 jr nc, .asm_388b7
@@ -2028,7 +2028,7 @@ endr
jp nz, AIDiscourageMove jp nz, AIDiscourageMove
push hl push hl
callba CheckEnemyHasMonToSwitchTo callba FindAliveEnemyMons
pop hl pop hl
jr nc, .asm_38eb0 jr nc, .asm_38eb0
@@ -2160,7 +2160,7 @@ endr
AI_Smart_PerishSong: ; 38f4a AI_Smart_PerishSong: ; 38f4a
push hl push hl
callab CheckEnemyHasMonToSwitchTo callab FindAliveEnemyMons
pop hl pop hl
jr c, .no jr c, .no

View File

@@ -183,8 +183,8 @@ endr
CheckAbleToSwitch: ; 34941 CheckAbleToSwitch: ; 34941
xor a xor a
ld [wc717], a ld [wEnemySwitchMonParam], a
call CheckEnemyHasMonToSwitchTo call FindAliveEnemyMons
ret c ret c
ld a, [EnemySubStatus1] ld a, [EnemySubStatus1]
@@ -197,9 +197,9 @@ CheckAbleToSwitch: ; 34941
; Perish count is 1 ; Perish count is 1
call CheckEnemyHasMonToSwitchTo call FindAliveEnemyMons
call Function34b77 call FindEnemyMonsWithEnoughHP
call Function34b20 call FindEnemyMonsThatResistPlayer
call Function34a85 call Function34a85
ld a, e ld a, e
@@ -208,11 +208,11 @@ CheckAbleToSwitch: ; 34941
ld a, [wc716] ld a, [wc716]
add $30 add $30
ld [wc717], a ld [wEnemySwitchMonParam], a
ret ret
.not_2 .not_2
call CheckEnemyHasMonToSwitchTo call FindAliveEnemyMons
sla c sla c
sla c sla c
ld b, $ff ld b, $ff
@@ -224,7 +224,7 @@ CheckAbleToSwitch: ; 34941
ld a, b ld a, b
add $30 add $30
ld [wc717], a ld [wEnemySwitchMonParam], a
ret ret
.no_perish .no_perish
@@ -236,12 +236,12 @@ CheckAbleToSwitch: ; 34941
ld a, [LastEnemyCounterMove] ld a, [LastEnemyCounterMove]
and a and a
jr z, .asm_349d2 jr z, .no_last_counter_move
call Function34a2a call Function34a2a
ld a, [wc716] ld a, [wc716]
and a and a
jr z, .asm_349d2 jr z, .no_last_counter_move
ld c, a ld c, a
call Function34aa7 call Function34aa7
@@ -252,7 +252,7 @@ CheckAbleToSwitch: ; 34941
ld b, a ld b, a
ld a, e ld a, e
cp 2 cp 2
jr z, .asm_349be jr z, .not_2_again
call CheckPlayerMoveTypeMatchups call CheckPlayerMoveTypeMatchups
ld a, [wc716] ld a, [wc716]
@@ -261,32 +261,32 @@ CheckAbleToSwitch: ; 34941
ld a, b ld a, b
add $10 add $10
ld [wc717], a ld [wEnemySwitchMonParam], a
ret ret
.asm_349be .not_2_again
ld c, $10 ld c, $10
call CheckPlayerMoveTypeMatchups call CheckPlayerMoveTypeMatchups
ld a, [wc716] ld a, [wc716]
cp 10 cp 10
jr nc, .asm_349cc jr nc, .okay
ld c, $20 ld c, $20
.asm_349cc .okay
ld a, b ld a, b
add c add c
ld [wc717], a ld [wEnemySwitchMonParam], a
ret ret
.asm_349d2 .no_last_counter_move
call CheckPlayerMoveTypeMatchups call CheckPlayerMoveTypeMatchups
ld a, [wc716] ld a, [wc716]
cp 10 cp 10
ret nc ret nc
call CheckEnemyHasMonToSwitchTo call FindAliveEnemyMons
call Function34b77 call FindEnemyMonsWithEnoughHP
call Function34b20 call FindEnemyMonsThatResistPlayer
call Function34a85 call Function34a85
ld a, e ld a, e
@@ -295,12 +295,12 @@ CheckAbleToSwitch: ; 34941
ld a, [wc716] ld a, [wc716]
add $10 add $10
ld [wc717], a ld [wEnemySwitchMonParam], a
ret ret
; 349f4 ; 349f4
CheckEnemyHasMonToSwitchTo: ; 349f4 FindAliveEnemyMons: ; 349f4
ld a, [OTPartyCount] ld a, [OTPartyCount]
cp 2 cp 2
jr c, .only_one jr c, .only_one
@@ -421,23 +421,23 @@ Function34a85: ; 34a85
ld hl, OTPartyMon1HP ld hl, OTPartyMon1HP
ld b, 1 << (PARTY_LENGTH - 1) ld b, 1 << (PARTY_LENGTH - 1)
ld c, 0 ld c, 0
.asm_34a91 .loop
ld a, [hli] ld a, [hli]
or [hl] or [hl]
jr z, .asm_34a98 jr z, .next
ld a, b ld a, b
or c or c
ld c, a ld c, a
.asm_34a98 .next
srl b srl b
push bc push bc
ld bc, PartyMon2HP - (PartyMon1HP + 1) ld bc, PartyMon2HP - (PartyMon1HP + 1)
add hl, bc add hl, bc
pop bc pop bc
dec e dec e
jr nz, .asm_34a91 jr nz, .loop
ld a, c ld a, c
pop bc pop bc
@@ -456,26 +456,26 @@ Function34aa7: ; 34aa7
ld b, 1 << (PARTY_LENGTH - 1) ld b, 1 << (PARTY_LENGTH - 1)
ld d, 0 ld d, 0
ld e, 0 ld e, 0
.asm_34ab5 .loop
ld a, b ld a, b
and c and c
jr z, .asm_34b00 jr z, .next
push hl push hl
push bc push bc
ld b, NUM_MOVES ld b, NUM_MOVES
ld c, 0 ld c, 0
.asm_34abf .loop3
ld a, [hli] ld a, [hli]
and a and a
push hl push hl
jr z, .asm_34aef jr z, .break3
dec a dec a
ld hl, Moves + MOVE_POWER ld hl, Moves + MOVE_POWER
call GetMoveAttr call GetMoveAttr
and a and a
jr z, .asm_34ae9 jr z, .nope
inc hl inc hl
call GetMoveByte call GetMoveByte
@@ -483,61 +483,61 @@ Function34aa7: ; 34aa7
call CheckTypeMatchup call CheckTypeMatchup
ld a, [wTypeMatchup] ld a, [wTypeMatchup]
cp 10 cp 10
jr c, .asm_34ae9 jr c, .nope
ld e, 1 ld e, 1
cp 11 cp 10 + 1
jr c, .asm_34ae9 jr c, .nope
ld e, 2 ld e, 2
jr .asm_34aef jr .break3
.asm_34ae9 .nope
pop hl pop hl
dec b dec b
jr nz, .asm_34abf jr nz, .loop3
jr .asm_34af0 jr .done
.asm_34aef .break3
pop hl pop hl
.asm_34af0 .done
ld a, e ld a, e
pop bc pop bc
pop hl pop hl
cp $2 cp $2
jr z, .asm_34b0e jr z, .done2
cp $1 cp $1
jr nz, .asm_34b00 jr nz, .next
ld a, d ld a, d
or b or b
ld d, a ld d, a
jr .asm_34b00 jr .next
.asm_34b00 .next
push bc push bc
ld bc, PARTYMON_STRUCT_LENGTH ld bc, PARTYMON_STRUCT_LENGTH
add hl, bc add hl, bc
pop bc pop bc
srl b srl b
jr nc, .asm_34ab5 jr nc, .loop
ld a, d ld a, d
ld b, a ld b, a
and a and a
ret z ret z
.asm_34b0e .done2
push bc push bc
sla b sla b
sla b sla b
ld c, $ff ld c, $ff
.asm_34b15 .loop2
inc c inc c
sla b sla b
jr nc, .asm_34b15 jr nc, .loop2
ld a, c ld a, c
ld [wc716], a ld [wc716], a
@@ -546,60 +546,60 @@ Function34aa7: ; 34aa7
; 34b20 ; 34b20
Function34b20: ; 34b20 FindEnemyMonsThatResistPlayer: ; 34b20
push bc push bc
ld hl, OTPartySpecies ld hl, OTPartySpecies
ld b, 1 << (PARTY_LENGTH - 1) ld b, 1 << (PARTY_LENGTH - 1)
ld c, 0 ld c, 0
.asm_34b28 .loop
ld a, [hli] ld a, [hli]
cp $ff cp $ff
jr z, .asm_34b72 jr z, .done
push hl push hl
ld [CurSpecies], a ld [CurSpecies], a
call GetBaseData call GetBaseData
ld a, [LastEnemyCounterMove] ld a, [LastEnemyCounterMove]
and a and a
jr z, .asm_34b4a jr z, .skip_move
dec a dec a
ld hl, Moves + MOVE_POWER ld hl, Moves + MOVE_POWER
call GetMoveAttr call GetMoveAttr
and a and a
jr z, .asm_34b4a jr z, .skip_move
inc hl inc hl
call GetMoveByte call GetMoveByte
jr .asm_34b5d jr .check_type
.asm_34b4a .skip_move
ld a, [BattleMonType1] ld a, [BattleMonType1]
ld hl, BaseType ld hl, BaseType
call CheckTypeMatchup call CheckTypeMatchup
ld a, [wTypeMatchup] ld a, [wTypeMatchup]
cp $b cp 10 + 1
jr nc, .asm_34b6d jr nc, .dont_choose_mon
ld a, [BattleMonType2] ld a, [BattleMonType2]
.asm_34b5d .check_type
ld hl, BaseType ld hl, BaseType
call CheckTypeMatchup call CheckTypeMatchup
ld a, [wTypeMatchup] ld a, [wTypeMatchup]
cp $b cp 10 + 1
jr nc, .asm_34b6d jr nc, .dont_choose_mon
ld a, b ld a, b
or c or c
ld c, a ld c, a
.asm_34b6d .dont_choose_mon
srl b srl b
pop hl pop hl
jr .asm_34b28 jr .loop
.asm_34b72 .done
ld a, c ld a, c
pop bc pop bc
and c and c
@@ -608,7 +608,7 @@ Function34b20: ; 34b20
; 34b77 ; 34b77
Function34b77: ; 34b77 FindEnemyMonsWithEnoughHP: ; 34b77
push bc push bc
ld de, OTPartySpecies ld de, OTPartySpecies
ld b, 1 << (PARTY_LENGTH - 1) ld b, 1 << (PARTY_LENGTH - 1)
@@ -629,10 +629,14 @@ Function34b77: ; 34b77
rept 2 rept 2
inc hl inc hl
endr endr
; hl = MaxHP + 1
; b = (4 * b) % $100 + (c & 3)
; c = c / 4
srl c srl c
rl b rl b
srl c srl c
rl b rl b
; a = (MaxHP / $100) - b - (1 if c > (MaxHP % $100) else 0)
ld a, [hld] ld a, [hld]
cp c cp c
ld a, [hl] ld a, [hl]

View File

@@ -38,7 +38,7 @@ Function3c000: ; 3c000
dec a dec a
jr z, .wild jr z, .wild
xor a xor a
ld [wc718], a ld [wEnemySwitchMonIndex], a
call NewEnemyMonStatus call NewEnemyMonStatus
call ResetEnemyStatLevels call ResetEnemyStatLevels
call BreakAttraction call BreakAttraction
@@ -104,7 +104,7 @@ Function3c000: ; 3c000
cp $2 cp $2
jr nz, .not_linked_2 jr nz, .not_linked_2
xor a xor a
ld [wc718], a ld [wEnemySwitchMonIndex], a
call NewEnemyMonStatus call NewEnemyMonStatus
call ResetEnemyStatLevels call ResetEnemyStatLevels
call BreakAttraction call BreakAttraction
@@ -136,7 +136,7 @@ WildFled_EnemyFled_LinkBattleCanceled: ; 3c0e5
and $c0 and $c0
ld [wBattleResult], a ld [wBattleResult], a
ld hl, BattleText_EnemyFled ld hl, BattleText_EnemyFled
call Function3d2e0 call CheckMobileBattleError
jr nc, .asm_3c115 jr nc, .asm_3c115
ld hl, wcd2a ld hl, wcd2a
@@ -150,7 +150,7 @@ WildFled_EnemyFled_LinkBattleCanceled: ; 3c0e5
.asm_3c118 .asm_3c118
call StopDangerSound call StopDangerSound
call Function3d2e0 call CheckMobileBattleError
jr c, .asm_3c126 jr c, .asm_3c126
ld de, SFX_RUN ld de, SFX_RUN
@@ -179,7 +179,7 @@ Function3c12f: ; 3c12f
ld [CurDamage], a ld [CurDamage], a
ld [CurDamage + 1], a ld [CurDamage + 1], a
call Function3c27c call HandleBerserkGene
call UpdateBattleMonInParty call UpdateBattleMonInParty
callba AIChooseMove callba AIChooseMove
@@ -191,7 +191,7 @@ Function3c12f: ; 3c12f
jp c, .quit jp c, .quit
.not_disconnected .not_disconnected
call Function3c410 call CheckPlayerLockedIn
jr c, .skip_iteration jr c, .skip_iteration
.loop1 .loop1
call BattleMenu call BattleMenu
@@ -199,27 +199,27 @@ Function3c12f: ; 3c12f
ld a, [BattleEnded] ld a, [BattleEnded]
and a and a
jr nz, .quit jr nz, .quit
ld a, [wd232] ; roared/whirlwinded/teleported ld a, [wForcedSwitch] ; roared/whirlwinded/teleported
and a and a
jr nz, .quit jr nz, .quit
.skip_iteration .skip_iteration
call Function3c434 call ParsePlayerAction
jr nz, .loop1 jr nz, .loop1
call Function3c300 call EnemyTriesToFlee
jr c, .quit jr c, .quit
call DetermineMoveOrder call DetermineMoveOrder
jr c, .false jr c, .false
call Function3c5fe call Battle_EnemyFirst
jr .proceed jr .proceed
.false .false
call Function3c664 call Battle_PlayerFirst
.proceed .proceed
call Function3d2e0 call CheckMobileBattleError
jr c, .quit jr c, .quit
ld a, [wd232] ld a, [wForcedSwitch]
and a and a
jr nz, .quit jr nz, .quit
@@ -355,7 +355,7 @@ CheckFaint_EnemyThenPlayer: ; 3c25c
ret ret
; 3c27c ; 3c27c
Function3c27c: ; 3c27c HandleBerserkGene: ; 3c27c
ld a, [hLinkPlayerNumber] ld a, [hLinkPlayerNumber]
cp $1 cp $1
jr z, .reverse jr z, .reverse
@@ -432,7 +432,7 @@ Function3c27c: ; 3c27c
jp StdBattleTextBox jp StdBattleTextBox
; 3c300 ; 3c300
Function3c300: ; 3c300 EnemyTriesToFlee: ; 3c300
ld a, [wLinkMode] ld a, [wLinkMode]
and a and a
jr z, .not_linked jr z, .not_linked
@@ -592,7 +592,7 @@ CheckContestBattleOver: ; 3c3f5
ret ret
; 3c410 ; 3c410
Function3c410: ; 3c410 CheckPlayerLockedIn: ; 3c410
ld a, [PlayerSubStatus4] ld a, [PlayerSubStatus4]
and 1 << SUBSTATUS_RECHARGE and 1 << SUBSTATUS_RECHARGE
jp nz, .quit jp nz, .quit
@@ -618,25 +618,25 @@ Function3c410: ; 3c410
ret ret
; 3c434 ; 3c434
Function3c434: ; 3c434 ParsePlayerAction: ; 3c434
call Function3c410 call CheckPlayerLockedIn
jp c, .asm_3c4ba jp c, .locked_in
ld hl, PlayerSubStatus5 ld hl, PlayerSubStatus5
bit SUBSTATUS_ENCORED, [hl] bit SUBSTATUS_ENCORED, [hl]
jr z, .asm_3c449 jr z, .not_encored
ld a, [LastPlayerMove] ld a, [LastPlayerMove]
ld [CurPlayerMove], a ld [CurPlayerMove], a
jr .asm_3c47c jr .encored
.asm_3c449 .not_encored
ld a, [wd0ec] ld a, [wd0ec]
cp $2 cp $2
jr z, .asm_3c4ce jr z, .reset_rage
and a and a
jr nz, .asm_3c4b5 jr nz, .reset_bide
ld a, [PlayerSubStatus3] ld a, [PlayerSubStatus3]
and 1 << SUBSTATUS_BIDE and 1 << SUBSTATUS_BIDE
jr nz, .asm_3c4ba jr nz, .locked_in
xor a xor a
ld [wd235], a ld [wd235], a
inc a ; POUND inc a ; POUND
@@ -647,50 +647,50 @@ Function3c434: ; 3c434
call UpdateBattleHuds call UpdateBattleHuds
ld a, [CurPlayerMove] ld a, [CurPlayerMove]
cp STRUGGLE cp STRUGGLE
jr z, .asm_3c476 jr z, .struggle
call PlayClickSFX call PlayClickSFX
.asm_3c476 .struggle
ld a, $1 ld a, $1
ld [hBGMapMode], a ld [hBGMapMode], a
pop af pop af
ret nz ret nz
.asm_3c47c .encored
call SetPlayerTurn call SetPlayerTurn
callab UpdateMoveData callab UpdateMoveData
xor a xor a
ld [wPlayerCharging], a ld [wPlayerCharging], a
ld a, [wPlayerMoveStruct + MOVE_EFFECT] ld a, [wPlayerMoveStruct + MOVE_EFFECT]
cp EFFECT_FURY_CUTTER cp EFFECT_FURY_CUTTER
jr z, .asm_3c494 jr z, .continue_fury_cutter
xor a xor a
ld [PlayerFuryCutterCount], a ld [PlayerFuryCutterCount], a
.asm_3c494 .continue_fury_cutter
ld a, [wPlayerMoveStruct + MOVE_EFFECT] ld a, [wPlayerMoveStruct + MOVE_EFFECT]
cp EFFECT_RAGE cp EFFECT_RAGE
jr z, .asm_3c4a4 jr z, .continue_rage
ld hl, PlayerSubStatus4 ld hl, PlayerSubStatus4
res SUBSTATUS_RAGE, [hl] res SUBSTATUS_RAGE, [hl]
xor a xor a
ld [wPlayerRageCounter], a ld [wPlayerRageCounter], a
.asm_3c4a4 .continue_rage
ld a, [wPlayerMoveStruct + MOVE_EFFECT] ld a, [wPlayerMoveStruct + MOVE_EFFECT]
cp EFFECT_PROTECT cp EFFECT_PROTECT
jr z, .asm_3c4c9 jr z, .continue_protect
cp EFFECT_ENDURE cp EFFECT_ENDURE
jr z, .asm_3c4c9 jr z, .continue_protect
xor a xor a
ld [PlayerProtectCount], a ld [PlayerProtectCount], a
jr .asm_3c4c9 jr .continue_protect
.asm_3c4b5 .reset_bide
ld hl, PlayerSubStatus3 ld hl, PlayerSubStatus3
res SUBSTATUS_BIDE, [hl] res SUBSTATUS_BIDE, [hl]
.asm_3c4ba .locked_in
xor a xor a
ld [PlayerFuryCutterCount], a ld [PlayerFuryCutterCount], a
ld [PlayerProtectCount], a ld [PlayerProtectCount], a
@@ -698,12 +698,12 @@ Function3c434: ; 3c434
ld hl, PlayerSubStatus4 ld hl, PlayerSubStatus4
res SUBSTATUS_RAGE, [hl] res SUBSTATUS_RAGE, [hl]
.asm_3c4c9 .continue_protect
call Function3e7c1 call ParseEnemyAction
xor a xor a
ret ret
.asm_3c4ce .reset_rage
xor a xor a
ld [PlayerFuryCutterCount], a ld [PlayerFuryCutterCount], a
ld [PlayerProtectCount], a ld [PlayerProtectCount], a
@@ -932,19 +932,19 @@ GetMoveEffect: ; 3c5ec
; 3c5fe ; 3c5fe
Function3c5fe: ; 3c5fe Battle_EnemyFirst: ; 3c5fe
call LoadTileMapToTempTileMap call LoadTileMapToTempTileMap
call TryEnemyFlee call TryEnemyFlee
jp c, WildFled_EnemyFled_LinkBattleCanceled jp c, WildFled_EnemyFled_LinkBattleCanceled
call SetEnemyTurn call SetEnemyTurn
ld a, $1 ld a, $1
ld [wc70f], a ld [wEnemyGoesFirst], a
callab AI_SwitchOrTryItem callab AI_SwitchOrTryItem
jr c, .switch_item jr c, .switch_item
call EnemyTurn_EndOpponentProtectEndureDestinyBond call EnemyTurn_EndOpponentProtectEndureDestinyBond
call Function3d2e0 call CheckMobileBattleError
ret c ret c
ld a, [wd232] ld a, [wForcedSwitch]
and a and a
ret nz ret nz
call HasPlayerFainted call HasPlayerFainted
@@ -958,9 +958,9 @@ Function3c5fe: ; 3c5fe
jp z, HandleEnemyMonFaint jp z, HandleEnemyMonFaint
call RefreshBattleHuds call RefreshBattleHuds
call PlayerTurn_EndOpponentProtectEndureDestinyBond call PlayerTurn_EndOpponentProtectEndureDestinyBond
call Function3d2e0 call CheckMobileBattleError
ret c ret c
ld a, [wd232] ld a, [wForcedSwitch]
and a and a
ret nz ret nz
call HasEnemyFainted call HasEnemyFainted
@@ -976,18 +976,18 @@ Function3c5fe: ; 3c5fe
ret ret
; 3c664 ; 3c664
Function3c664: ; 3c664 Battle_PlayerFirst: ; 3c664
xor a xor a
ld [wc70f], a ld [wEnemyGoesFirst], a
call SetEnemyTurn call SetEnemyTurn
callab AI_SwitchOrTryItem callab AI_SwitchOrTryItem
push af push af
call PlayerTurn_EndOpponentProtectEndureDestinyBond call PlayerTurn_EndOpponentProtectEndureDestinyBond
pop bc pop bc
ld a, [wd232] ld a, [wForcedSwitch]
and a and a
ret nz ret nz
call Function3d2e0 call CheckMobileBattleError
ret c ret c
call HasEnemyFainted call HasEnemyFainted
jp z, HandleEnemyMonFaint jp z, HandleEnemyMonFaint
@@ -1006,9 +1006,9 @@ Function3c664: ; 3c664
call TryEnemyFlee call TryEnemyFlee
jp c, WildFled_EnemyFled_LinkBattleCanceled jp c, WildFled_EnemyFled_LinkBattleCanceled
call EnemyTurn_EndOpponentProtectEndureDestinyBond call EnemyTurn_EndOpponentProtectEndureDestinyBond
call Function3d2e0 call CheckMobileBattleError
ret c ret c
ld a, [wd232] ld a, [wForcedSwitch]
and a and a
ret nz ret nz
call HasPlayerFainted call HasPlayerFainted
@@ -2154,7 +2154,7 @@ HandleEnemyMonFaint: ; 3cd55
.dont_flee .dont_flee
call Function3d227 call Function3d227
call Function3d2e0 call CheckMobileBattleError
jp c, WildFled_EnemyFled_LinkBattleCanceled jp c, WildFled_EnemyFled_LinkBattleCanceled
ld a, $1 ld a, $1
@@ -2437,7 +2437,7 @@ Function3cf4a: ; 3cf4a
EnemyPartyMonEntrance: ; 3cf78 EnemyPartyMonEntrance: ; 3cf78
push af push af
xor a xor a
ld [wc718], a ld [wEnemySwitchMonIndex], a
call NewEnemyMonStatus call NewEnemyMonStatus
call ResetEnemyStatLevels call ResetEnemyStatLevels
call BreakAttraction call BreakAttraction
@@ -2805,7 +2805,7 @@ HandlePlayerMonFaint: ; 3d14e
.asm_3d190 .asm_3d190
call Function3d227 call Function3d227
call Function3d2e0 call CheckMobileBattleError
jp c, WildFled_EnemyFled_LinkBattleCanceled jp c, WildFled_EnemyFled_LinkBattleCanceled
ld a, c ld a, c
and a and a
@@ -2900,7 +2900,7 @@ Function3d227: ; 3d227
.skip_link .skip_link
xor a xor a
ld [wd0ec], a ld [wd0ec], a
call Function3d2e0 call CheckMobileBattleError
jr c, .asm_3d251 jr c, .asm_3d251
ld hl, EnemyMonHP ld hl, EnemyMonHP
ld a, [hli] ld a, [hli]
@@ -2968,7 +2968,7 @@ Function3d2b3: ; 3d2b3
; 3d2e0 ; 3d2e0
Function3d2e0: ; 3d2e0 CheckMobileBattleError: ; 3d2e0
ld a, [wLinkMode] ld a, [wLinkMode]
cp LINK_MOBILE cp LINK_MOBILE
jr nz, .not_mobile ; It's not a mobile battle jr nz, .not_mobile ; It's not a mobile battle
@@ -3057,7 +3057,7 @@ ForcePickPartyMonInBattle: ; 3d362
.pick .pick
call PickPartyMonInBattle call PickPartyMonInBattle
ret nc ret nc
call Function3d2e0 call CheckMobileBattleError
ret c ret c
ld de, SFX_WRONG ld de, SFX_WRONG
@@ -3082,7 +3082,7 @@ ForcePickSwitchMonInBattle: ; 3d380
.pick .pick
call ForcePickPartyMonInBattle call ForcePickPartyMonInBattle
call Function3d2e0 call CheckMobileBattleError
ret c ret c
call SwitchMonAlreadyOut call SwitchMonAlreadyOut
jr c, .pick jr c, .pick
@@ -3306,7 +3306,7 @@ Function3d4ae: ; 3d4ae
Function3d4c3: ; 3d4c3 Function3d4c3: ; 3d4c3
call ResetEnemyBattleVars call ResetEnemyBattleVars
ld a, [wc718] ld a, [wEnemySwitchMonIndex]
dec a dec a
ld b, a ld b, a
call LoadEnemyPkmnToSwitchTo call LoadEnemyPkmnToSwitchTo
@@ -3376,7 +3376,7 @@ Function3d533: ; 3d533
jr .return_carry jr .return_carry
.not_linked .not_linked
ld a, [wc718] ld a, [wEnemySwitchMonIndex]
and a and a
jr z, .check_wd264 jr z, .check_wd264
@@ -4031,8 +4031,8 @@ TryToRunAwayFromBattle: ; 3d8b3
ld [CurPlayerMove], a ld [CurPlayerMove], a
call Function3e8e4 call Function3e8e4
call Call_LoadTempTileMapToTileMap call Call_LoadTempTileMapToTileMap
call Function3d2e0 call CheckMobileBattleError
jr c, .asm_3d9f5 jr c, .mobile
; Got away safely ; Got away safely
ld a, [wBattleAction] ld a, [wBattleAction]
@@ -4059,15 +4059,15 @@ TryToRunAwayFromBattle: ; 3d8b3
scf scf
ret ret
.asm_3d9f5 .mobile
call StopDangerSound call StopDangerSound
ld hl, wcd2a ld hl, wcd2a
bit 4, [hl] bit 4, [hl]
jr nz, .asm_3da05 jr nz, .skip_link_error
ld hl, BattleText_LinkErrorBattleCanceled ld hl, BattleText_LinkErrorBattleCanceled
call StdBattleTextBox call StdBattleTextBox
.asm_3da05 .skip_link_error
call WaitSFX call WaitSFX
call LoadTileMapToTempTileMap call LoadTileMapToTempTileMap
scf scf
@@ -5353,13 +5353,13 @@ Function3e299:
jr .asm_3e2a8 jr .asm_3e2a8
.asm_3e2c8 .asm_3e2c8
call Function3d2e0 call CheckMobileBattleError
jr c, .asm_3e2da jr c, .asm_3e2da
jr Function3e299 jr Function3e299
.asm_3e2cf .asm_3e2cf
call Function3e308 call Function3e308
call Function3d2e0 call CheckMobileBattleError
jr c, .asm_3e2da jr c, .asm_3e2da
jp Function3e290 jp Function3e290
@@ -5470,7 +5470,7 @@ PlayerSwitch: ; 3e3ad
call WriteBackup call WriteBackup
.not_linked .not_linked
call Function3e7c1 call ParseEnemyAction
ld a, [wLinkMode] ld a, [wLinkMode]
and a and a
jr nz, .linked jr nz, .linked
@@ -6070,7 +6070,7 @@ Function3e786: ; 3e786
Function3e7c1: ; 3e7c1 ParseEnemyAction: ; 3e7c1
ld a, [wEnemyIsSwitching] ld a, [wEnemyIsSwitching]
and a and a
ret nz ret nz
@@ -8740,7 +8740,7 @@ Function3f6d0: ; 3f6d0
ld [OtherTrainerClass], a ld [OtherTrainerClass], a
ld [wd266], a ld [wd266], a
ld [wd267], a ld [wd267], a
ld [wd232], a ld [wForcedSwitch], a
ld [wd0d8], a ld [wd0d8], a
ld [wKeyItemsPocketCursor], a ld [wKeyItemsPocketCursor], a
ld [wItemsPocketCursor], a ld [wItemsPocketCursor], a
@@ -8813,7 +8813,7 @@ Function3f759: ; 3f759
; 3f77c ; 3f77c
Function3f77c: ; 3f77c Function3f77c: ; 3f77c
callba Function3d2e0 callba CheckMobileBattleError
jp c, Function3f80f jp c, Function3f80f
call Function3f830 call Function3f830
jr nz, .asm_3f797 jr nz, .asm_3f797

View File

@@ -6530,7 +6530,7 @@ BattleCommand_Teleport: ; 36778
xor a xor a
ld [wcfca], a ld [wcfca], a
inc a inc a
ld [wd232], a ld [wForcedSwitch], a
ld [wKickCounter], a ld [wKickCounter], a
call SetBattleDraw call SetBattleDraw
call BattleCommand_LowerSub call BattleCommand_LowerSub
@@ -6598,15 +6598,15 @@ BattleCommand_ForceSwitch: ; 3680f
xor a xor a
ld [wcfca], a ld [wcfca], a
inc a inc a
ld [wd232], a ld [wForcedSwitch], a
call SetBattleDraw call SetBattleDraw
ld a, [wPlayerMoveStruct + MOVE_ANIM] ld a, [wPlayerMoveStruct + MOVE_ANIM]
jp .succeed jp .succeed
.trainer .trainer
call CheckEnemyHasMonToSwitchTo call FindAliveEnemyMons
jr c, .switch_fail ; 3686c $5c jr c, .switch_fail ; 3686c $5c
ld a, [wc70f] ld a, [wEnemyGoesFirst]
and a and a
jr z, .switch_fail ; 36872 $56 jr z, .switch_fail ; 36872 $56
call UpdateEnemyMonInParty call UpdateEnemyMonInParty
@@ -6643,7 +6643,7 @@ BattleCommand_ForceSwitch: ; 3680f
jr z, .random_loop_trainer ; 368b1 $e7 jr z, .random_loop_trainer ; 368b1 $e7
ld a, d ld a, d
inc a inc a
ld [wc718], a ld [wEnemySwitchMonIndex], a
callab Function3d4c3 callab Function3d4c3
ld hl, DraggedOutText ld hl, DraggedOutText
@@ -6691,7 +6691,7 @@ BattleCommand_ForceSwitch: ; 3680f
xor a xor a
ld [wcfca], a ld [wcfca], a
inc a inc a
ld [wd232], a ld [wForcedSwitch], a
call SetBattleDraw call SetBattleDraw
ld a, [wEnemyMoveStruct + MOVE_ANIM] ld a, [wEnemyMoveStruct + MOVE_ANIM]
jr .succeed jr .succeed
@@ -6700,7 +6700,7 @@ BattleCommand_ForceSwitch: ; 3680f
call CheckPlayerHasMonToSwitchTo call CheckPlayerHasMonToSwitchTo
jr c, .fail jr c, .fail
ld a, [wc70f] ld a, [wEnemyGoesFirst]
cp $1 cp $1
jr z, .switch_fail jr z, .switch_fail
@@ -6991,7 +6991,7 @@ Function36ab5: ; 36ab5
Function36abf: ; 36abf Function36abf: ; 36abf
push bc push bc
ld a, [wc70f] ld a, [wEnemyGoesFirst]
ld b, a ld b, a
ld a, [hBattleTurn] ld a, [hBattleTurn]
xor b xor b
@@ -8943,7 +8943,7 @@ BattleCommand_BatonPass: ; 379c9
call BatonPass_LinkPlayerSwitch call BatonPass_LinkPlayerSwitch
; Mobile link battles handle entrances differently ; Mobile link battles handle entrances differently
callba Function3d2e0 callba CheckMobileBattleError
jp c, EndMoveEffect jp c, EndMoveEffect
ld hl, PassedBattleMonEntrance ld hl, PassedBattleMonEntrance
@@ -8968,12 +8968,12 @@ BattleCommand_BatonPass: ; 379c9
call BatonPass_LinkEnemySwitch call BatonPass_LinkEnemySwitch
; Mobile link battles handle entrances differently ; Mobile link battles handle entrances differently
callba Function3d2e0 callba CheckMobileBattleError
jp c, EndMoveEffect jp c, EndMoveEffect
; Passed enemy PartyMon entrance ; Passed enemy PartyMon entrance
xor a xor a
ld [wc718], a ld [wEnemySwitchMonIndex], a
ld hl, EnemySwitch_SetMode ld hl, EnemySwitch_SetMode
call CallBattleCore call CallBattleCore
ld hl, ResetBattleParticipants ld hl, ResetBattleParticipants

View File

@@ -2288,7 +2288,7 @@ PokeDoll: ; f48f
dec a dec a
jr nz, .asm_f4a6 jr nz, .asm_f4a6
inc a inc a
ld [wd232], a ld [wForcedSwitch], a
ld a, [wBattleResult] ld a, [wBattleResult]
and 3 << 6 and 3 << 6
or $2 or $2

View File

@@ -32256,7 +32256,7 @@ endr
ld [BattleMonSpecies], a ld [BattleMonSpecies], a
ld [wBattleParticipantsNotFainted], a ld [wBattleParticipantsNotFainted], a
ld [CurBattleMon], a ld [CurBattleMon], a
ld [wd232], a ld [wForcedSwitch], a
ld [TimeOfDayPal], a ld [TimeOfDayPal], a
ld [PlayerTurnsTaken], a ld [PlayerTurnsTaken], a
ld [EnemyTurnsTaken], a ld [EnemyTurnsTaken], a
@@ -33688,14 +33688,14 @@ endr
; so we have always the same AI, regardless of the loaded class of trainer ; so we have always the same AI, regardless of the loaded class of trainer
ld a, [InBattleTowerBattle] ld a, [InBattleTowerBattle]
bit 0, a bit 0, a
jr nz, .asm_4412f jr nz, .battle_tower_skip
ld a, [TrainerClass] ld a, [TrainerClass]
dec a dec a
ld bc, 7 ; Trainer2AI - Trainer1AI ld bc, 7 ; Trainer2AI - Trainer1AI
call AddNTimes call AddNTimes
.asm_4412f .battle_tower_skip
lb bc, CHECK_FLAG, 0 lb bc, CHECK_FLAG, 0
push bc push bc
push hl push hl
@@ -33766,40 +33766,40 @@ endr
.PickLowestScoreMoves .PickLowestScoreMoves
ld a, c ld a, c
.asm_44175 .move_loop
inc [hl] inc [hl]
dec hl dec hl
inc a inc a
cp NUM_MOVES + 1 cp NUM_MOVES + 1
jr nz, .asm_44175 jr nz, .move_loop
ld hl, Buffer1 ld hl, Buffer1
ld de, EnemyMonMoves ld de, EnemyMonMoves
ld c, NUM_MOVES ld c, NUM_MOVES
; Give a score of 0 to a blank move ; Give a score of 0 to a blank move
.asm_44184 .loop2
ld a, [de] ld a, [de]
and a and a
jr nz, .asm_44189 jr nz, .skip_load
ld [hl], a ld [hl], a
; Disregard the move if its score is not 1 ; Disregard the move if its score is not 1
.asm_44189 .skip_load
ld a, [hl] ld a, [hl]
dec a dec a
jr z, .asm_44191 jr z, .keep
xor a xor a
ld [hli], a ld [hli], a
jr .asm_44193 jr .after_toss
.asm_44191 .keep
ld a, [de] ld a, [de]
ld [hli], a ld [hli], a
.asm_44193 .after_toss
inc de inc de
dec c dec c
jr nz, .asm_44184 jr nz, .loop2
; Randomly choose one of the moves with a score of 1 ; Randomly choose one of the moves with a score of 1
.ChooseMove .ChooseMove
@@ -60912,7 +60912,7 @@ Function92ed5: ; 92ed5
; 92ee0 ; 92ee0
Function92ee0: ; 92ee0 Function92ee0: ; 92ee0
ld hl, wc70f ld hl, wEnemyGoesFirst
ld a, [wc700] ld a, [wc700]
cp [hl] cp [hl]
call z, Function92f0c call z, Function92f0c
@@ -60920,7 +60920,7 @@ Function92ee0: ; 92ee0
; 92eeb ; 92eeb
Function92eeb: ; 92eeb Function92eeb: ; 92eeb
ld hl, wc70f ld hl, wEnemyGoesFirst
ld a, [wc701] ld a, [wc701]
cp [hl] cp [hl]
call z, Function92f0c call z, Function92f0c
@@ -60928,7 +60928,7 @@ Function92eeb: ; 92eeb
; 92ef6 ; 92ef6
Function92ef6: ; 92ef6 Function92ef6: ; 92ef6
ld hl, wc70f ld hl, wEnemyGoesFirst
ld a, [wc702] ld a, [wc702]
cp [hl] cp [hl]
call z, Function92f0c call z, Function92f0c
@@ -61033,7 +61033,7 @@ Function92f70: ; 92f70
; 92f80 ; 92f80
Function92f80: ; 92f80 Function92f80: ; 92f80
ld hl, wc70f ld hl, wEnemyGoesFirst
ld a, [wc701] ld a, [wc701]
cp [hl] cp [hl]
ret nz ret nz

View File

@@ -1928,7 +1928,7 @@ Function17dc1f: ; 17dc1f
ld a, $5c ld a, $5c
ld [wc70e], a ld [wc70e], a
ld a, $1 ld a, $1
ld [wc70f], a ld [wEnemyGoesFirst], a
ld hl, wc708 ld hl, wc708
call LoadMenuDataHeader call LoadMenuDataHeader
call InterpretMenu2 call InterpretMenu2
@@ -2155,7 +2155,7 @@ Function17dd49: ; 17dd49
jr .asm_17ddc9 jr .asm_17ddc9
.asm_17ddb7 .asm_17ddb7
ld a, [wc70f] ld a, [wEnemyGoesFirst]
ld l, a ld l, a
ld a, [wc710] ld a, [wc710]
ld h, a ld h, a
@@ -2219,7 +2219,7 @@ Function17ddcd: ; 17ddcd
jr nz, .asm_17de26 jr nz, .asm_17de26
ld a, [wc70e] ld a, [wc70e]
ld l, a ld l, a
ld a, [wc70f] ld a, [wEnemyGoesFirst]
ld h, a ld h, a
jr .asm_17de2e jr .asm_17de2e
@@ -2277,7 +2277,7 @@ Function17de32: ; 17de32
.asm_17de78 .asm_17de78
ld a, [wc70e] ld a, [wc70e]
ld l, a ld l, a
ld a, [wc70f] ld a, [wEnemyGoesFirst]
ld h, a ld h, a
jr .asm_17de8a jr .asm_17de8a
@@ -2879,7 +2879,7 @@ Function17e1a1: ; 17e1a1
jr .asm_17e250 jr .asm_17e250
.asm_17e23e .asm_17e23e
ld a, [wc70f] ld a, [wEnemyGoesFirst]
ld l, a ld l, a
ld a, [wc710] ld a, [wc710]
ld h, a ld h, a

View File

@@ -452,7 +452,7 @@ wOddEggOTName:: ds PKMN_NAME_LENGTH
ds -70 ds -70
wBT_OTTemp:: battle_tower_struct wBT_OTTemp wBT_OTTemp:: battle_tower_struct wBT_OTTemp
ds -BATTLE_TOWER_STRUCT_LENGTH ds wBT_OTTemp - @
wMisc:: wMisc::
wBattle:: wBattle::
@@ -818,7 +818,7 @@ wc70e::
FailedMessage:: ; c70e FailedMessage:: ; c70e
ds 1 ds 1
wc70f:: ds 1 wEnemyGoesFirst:: ds 1
wc710:: wc710::
wPlayerIsSwitching:: ds 1 ; c710 wPlayerIsSwitching:: ds 1 ; c710
wc711:: wc711::
@@ -831,8 +831,9 @@ PlayerUsedMoves:: ; c712
ds NUM_MOVES ds NUM_MOVES
wc716:: ds 1 wc716:: ds 1
wEnemySwitchMonParam::
wc717:: ds 1 wc717:: ds 1
wc718:: ds 1 wEnemySwitchMonIndex:: ds 1
wc719:: ds 1 wc719:: ds 1
LastPlayerMon:: ; c71a LastPlayerMon:: ; c71a
wc71a:: ds 1 wc71a:: ds 1
@@ -912,25 +913,6 @@ wMiscEnd::
wc7e8:: ds 24 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] SECTION "Overworld Map", WRAM0 [$c800]
wc800:: wc800::
@@ -1863,7 +1845,7 @@ OtherTrainerID:: ; d231
; (Joey, Mikey, Albert, etc.) ; (Joey, Mikey, Albert, etc.)
ds 1 ds 1
wd232:: ds 1 wForcedSwitch:: ds 1
TrainerClass:: ; d233 TrainerClass:: ; d233
ds 1 ds 1