ref: e0445806694a80a98e4d803478a2675ec8803ba6
parent: 929d0aa0817d76bddc764adcd37a78034c29170d
author: PikalaxALT <[email protected]>
date: Sat Nov 7 03:05:57 EST 2015
battle/ai/switch.asm and more battle/effect_commands.asm
--- a/battle/ai/items.asm
+++ b/battle/ai/items.asm
@@ -44,7 +44,7 @@
; 38045
SwitchOften: ; 38045
- callab Function34941
+ callab CheckAbleToSwitch
ld a, [wc717]
and $f0
jp z, DontSwitch
@@ -80,7 +80,7 @@
; 38083
SwitchRarely: ; 38083
- callab Function34941
+ callab CheckAbleToSwitch
ld a, [wc717]
and $f0
jp z, DontSwitch
@@ -115,7 +115,7 @@
; 380c1
SwitchSometimes: ; 380c1
- callab Function34941
+ callab CheckAbleToSwitch
ld a, [wc717]
and $f0
jp z, DontSwitch
@@ -665,7 +665,7 @@
xor a
ld [wd10a], a
call AIUsedItemSound
- predef Functionc6e0
+ predef AnimateHPBar
jp AIUpdateHUD
--- a/battle/ai/scoring.asm
+++ b/battle/ai/scoring.asm
@@ -981,7 +981,7 @@
; Consider player's type(s) if its moves are unknown.
push hl
- callab Function3484e
+ callab CheckPlayerMoveTypeMatchups
ld a, [wc716]
cp 10 ; neutral
pop hl
@@ -1908,7 +1908,7 @@
; Otherwise, discourage this move unless the player only has not very effective moves against the enemy.
push hl
- callab Function3484e
+ callab CheckPlayerMoveTypeMatchups
ld a, [wc716]
cp $b ; not very effective
pop hl
@@ -2169,7 +2169,7 @@
jr nz, .yes
push hl
- callab Function3484e
+ callab CheckPlayerMoveTypeMatchups
ld a, [wc716]
cp 10 ; 1.0
pop hl
@@ -2431,7 +2431,7 @@
; Consider player's type(s) if its moves are unknown.
push hl
- callab Function3484e
+ callab CheckPlayerMoveTypeMatchups
ld a, [wc716]
cp 10 ; neutral
pop hl
--- /dev/null
+++ b/battle/ai/switch.asm
@@ -1,0 +1,662 @@
+CheckPlayerMoveTypeMatchups: ; 3484e
+; Check how well the moves you've already used
+; fare against the enemy's Pokemon. Used to
+; score a potential switch.
+ push hl
+ push de
+ push bc
+ ld a, 10
+ ld [wc716], a
+ ld hl, PlayerUsedMoves
+ ld a, [hl]
+ and a
+ jr z, .unknown_moves
+
+ ld d, NUM_MOVES
+ ld e, 0
+.loop
+ ld a, [hli]
+ and a
+ jr z, .exit
+ push hl
+ dec a
+ ld hl, Moves + MOVE_POWER
+ call GetMoveAttr
+ and a
+ jr z, .next
+
+ inc hl
+ call GetMoveByte
+ ld hl, EnemyMonType
+ call CheckTypeMatchup
+ ld a, [wTypeMatchup]
+ cp 10 + 1 ; 1.0 + 0.1
+ jr nc, .super_effective
+ and a
+ jr z, .next
+ cp 10 ; 1.0
+ jr nc, .neutral
+
+.not_very_effective
+ ld a, e
+ cp 1 ; 0.1
+ jr nc, .next
+ ld e, 1
+ jr .next
+
+.neutral
+ ld e, 2
+ jr .next
+
+.super_effective
+ call .DecreaseScore
+ pop hl
+ jr .done
+
+.next
+ pop hl
+ dec d
+ jr nz, .loop
+
+.exit
+ ld a, e
+ cp 2
+ jr z, .done
+ call .IncreaseScore
+ ld a, e
+ and a
+ jr nz, .done
+ call .IncreaseScore
+ jr .done
+
+.unknown_moves
+ ld a, [BattleMonType1]
+ ld b, a
+ ld hl, EnemyMonType1
+ call CheckTypeMatchup
+ ld a, [wTypeMatchup]
+ cp 10 + 1 ; 1.0 + 0.1
+ jr c, .ok
+ call .DecreaseScore
+.ok
+ ld a, [BattleMonType2]
+ cp b
+ jr z, .ok2
+ call CheckTypeMatchup
+ ld a, [wTypeMatchup]
+ cp 10 + 1 ; 1.0 + 0.1
+ jr c, .ok2
+ call .DecreaseScore
+.ok2
+
+.done
+ call .CheckEnemyMoveMatchups
+ pop bc
+ pop de
+ pop hl
+ ret
+; 348de
+
+
+.CheckEnemyMoveMatchups: ; 348de
+ ld de, EnemyMonMoves
+ ld b, NUM_MOVES + 1
+ ld c, 0
+
+ ld a, [wTypeMatchup]
+ push af
+.loop2
+ dec b
+ jr z, .exit2
+
+ ld a, [de]
+ and a
+ jr z, .exit2
+
+ inc de
+ dec a
+ ld hl, Moves + MOVE_POWER
+ call GetMoveAttr
+ and a
+ jr z, .loop2
+
+ inc hl
+ call GetMoveByte
+ ld hl, BattleMonType1
+ call CheckTypeMatchup
+
+ ld a, [wTypeMatchup]
+ ; immune
+ and a
+ jr z, .loop2
+
+ ; not very effective
+ inc c
+ cp 10
+ jr c, .loop2
+
+ ; neutral
+rept 5
+ inc c
+endr
+ cp 10
+ jr z, .loop2
+
+ ; super effective
+ ld c, 100
+ jr .loop2
+
+.exit2
+ pop af
+ ld [wTypeMatchup], a
+
+ ld a, c
+ and a
+ jr z, .doubledown ; double down
+ cp 5
+ jr c, .DecreaseScore ; down
+ cp 100
+ ret c
+ jr .IncreaseScore ; up
+
+.doubledown
+ call .DecreaseScore
+
+ ; fallthrough
+; 34931
+
+
+.DecreaseScore: ; 34931
+ ld a, [wc716]
+ dec a
+ ld [wc716], a
+ ret
+; 34939
+
+
+.IncreaseScore: ; 34939
+ ld a, [wc716]
+ inc a
+ ld [wc716], a
+ ret
+; 34941
+
+CheckAbleToSwitch: ; 34941
+ xor a
+ ld [wc717], a
+ call CountEnemyAliveMons
+ ret c
+
+ ld a, [EnemySubStatus1]
+ bit SUBSTATUS_PERISH, a
+ jr z, .no_perish
+
+ ld a, [EnemyPerishCount]
+ cp 1
+ jr nz, .no_perish
+
+ ; Perish count is 1
+
+ call CountEnemyAliveMons
+ call Function34b77
+ call Function34b20
+ call Function34a85
+
+ ld a, e
+ cp 2
+ jr nz, .not_2
+
+ ld a, [wc716]
+ add $30
+ ld [wc717], a
+ ret
+
+.not_2
+ call CountEnemyAliveMons
+ sla c
+ sla c
+ ld b, $ff
+
+.loop1
+ inc b
+ sla c
+ jr nc, .loop1
+
+ ld a, b
+ add $30
+ ld [wc717], a
+ ret
+
+.no_perish
+
+ call CheckPlayerMoveTypeMatchups
+ ld a, [wc716]
+ cp 11
+ ret nc
+
+ ld a, [LastEnemyCounterMove]
+ and a
+ jr z, .asm_349d2
+
+ call Function34a2a
+ ld a, [wc716]
+ and a
+ jr z, .asm_349d2
+
+ ld c, a
+ call Function34aa7
+ ld a, [wc716]
+ cp $ff
+ ret z
+
+ ld b, a
+ ld a, e
+ cp 2
+ jr z, .asm_349be
+
+ call CheckPlayerMoveTypeMatchups
+ ld a, [wc716]
+ cp 10
+ ret nc
+
+ ld a, b
+ add $10
+ ld [wc717], a
+ ret
+
+.asm_349be
+ ld c, $10
+ call CheckPlayerMoveTypeMatchups
+ ld a, [wc716]
+ cp 10
+ jr nc, .asm_349cc
+ ld c, $20
+
+.asm_349cc
+ ld a, b
+ add c
+ ld [wc717], a
+ ret
+
+.asm_349d2
+ call CheckPlayerMoveTypeMatchups
+ ld a, [wc716]
+ cp 10
+ ret nc
+
+ call CountEnemyAliveMons
+ call Function34b77
+ call Function34b20
+ call Function34a85
+
+ ld a, e
+ cp $2
+ ret nz
+
+ ld a, [wc716]
+ add $10
+ ld [wc717], a
+ ret
+; 349f4
+
+
+CountEnemyAliveMons: ; 349f4
+ ld a, [OTPartyCount]
+ cp 2
+ jr c, .only_one
+
+ ld d, a
+ ld e, 0
+ ld b, 1 << (PARTY_LENGTH - 1)
+ ld c, 0
+ ld hl, OTPartyMon1HP
+
+.loop
+ ld a, [CurOTMon]
+ cp e
+ jr z, .next
+
+ push bc
+ ld b, [hl]
+ inc hl
+ ld a, [hld]
+ or b
+ pop bc
+ jr z, .next
+
+ ld a, c
+ or b
+ ld c, a
+
+.next
+ srl b
+ push bc
+ ld bc, PARTYMON_STRUCT_LENGTH
+ add hl, bc
+ pop bc
+ inc e
+ dec d
+ jr nz, .loop
+
+ ld a, c
+ and a
+ jr nz, .more_than_one
+
+.only_one
+ scf
+ ret
+
+.more_than_one
+ and a
+ ret
+; 34a2a
+
+
+Function34a2a: ; 34a2a
+ ld hl, OTPartyMon1
+ ld a, [OTPartyCount]
+ ld b, a
+ ld c, 1 << (PARTY_LENGTH - 1)
+ ld d, 0
+ xor a
+ ld [wc716], a
+
+.asm_34a39
+ ld a, [CurOTMon]
+ cp d
+ push hl
+ jr z, .asm_34a77
+
+ push hl
+ push bc
+ ld bc, MON_HP
+ add hl, bc
+ pop bc
+ ld a, [hli]
+ or [hl]
+ pop hl
+ jr z, .asm_34a77
+
+ ld a, [hl]
+ ld [CurSpecies], a
+ call GetBaseData
+ ld a, [LastEnemyCounterMove]
+ dec a
+ ld hl, Moves + MOVE_POWER
+ call GetMoveAttr
+ and a
+ jr z, .asm_34a77
+
+ inc hl
+ call GetMoveByte
+ ld hl, BaseType
+ call CheckTypeMatchup
+ ld a, [wTypeMatchup]
+ and a
+ jr nz, .asm_34a77
+
+ ld a, [wc716]
+ or c
+ ld [wc716], a
+.asm_34a77
+ pop hl
+ dec b
+ ret z
+
+ push bc
+ ld bc, PARTYMON_STRUCT_LENGTH
+ add hl, bc
+ pop bc
+
+ inc d
+ srl c
+ jr .asm_34a39
+; 34a85
+
+
+Function34a85: ; 34a85
+ push bc
+ ld a, [OTPartyCount]
+ ld e, a
+ ld hl, OTPartyMon1HP
+ ld b, 1 << (PARTY_LENGTH - 1)
+ ld c, 0
+.asm_34a91
+ ld a, [hli]
+ or [hl]
+ jr z, .asm_34a98
+
+ ld a, b
+ or c
+ ld c, a
+
+.asm_34a98
+ srl b
+ push bc
+ ld bc, PartyMon2HP - (PartyMon1HP + 1)
+ add hl, bc
+ pop bc
+ dec e
+ jr nz, .asm_34a91
+
+ ld a, c
+ pop bc
+
+ and c
+ ld c, a
+
+ ; fallthrough
+; 34aa7
+
+Function34aa7: ; 34aa7
+
+ ld a, $ff
+ ld [wc716], a
+ ld hl, OTPartyMon1Moves
+ ld b, 1 << (PARTY_LENGTH - 1)
+ ld d, 0
+ ld e, 0
+.asm_34ab5
+ ld a, b
+ and c
+ jr z, .asm_34b00
+
+ push hl
+ push bc
+ ld b, NUM_MOVES
+ ld c, 0
+.asm_34abf
+ ld a, [hli]
+ and a
+ push hl
+ jr z, .asm_34aef
+
+ dec a
+ ld hl, Moves + MOVE_POWER
+ call GetMoveAttr
+ and a
+ jr z, .asm_34ae9
+
+ inc hl
+ call GetMoveByte
+ ld hl, BattleMonType1
+ call CheckTypeMatchup
+ ld a, [wTypeMatchup]
+ cp 10
+ jr c, .asm_34ae9
+
+ ld e, 1
+ cp 11
+ jr c, .asm_34ae9
+
+ ld e, 2
+ jr .asm_34aef
+
+.asm_34ae9
+ pop hl
+ dec b
+ jr nz, .asm_34abf
+
+ jr .asm_34af0
+
+.asm_34aef
+ pop hl
+.asm_34af0
+ ld a, e
+ pop bc
+ pop hl
+ cp $2
+ jr z, .asm_34b0e
+
+ cp $1
+ jr nz, .asm_34b00
+
+ ld a, d
+ or b
+ ld d, a
+ jr .asm_34b00
+
+.asm_34b00
+ push bc
+ ld bc, PARTYMON_STRUCT_LENGTH
+ add hl, bc
+ pop bc
+ srl b
+ jr nc, .asm_34ab5
+
+ ld a, d
+ ld b, a
+ and a
+ ret z
+
+.asm_34b0e
+ push bc
+ sla b
+ sla b
+ ld c, $ff
+.asm_34b15
+ inc c
+ sla b
+ jr nc, .asm_34b15
+
+ ld a, c
+ ld [wc716], a
+ pop bc
+ ret
+; 34b20
+
+
+Function34b20: ; 34b20
+ push bc
+ ld hl, OTPartySpecies
+ ld b, 1 << (PARTY_LENGTH - 1)
+ ld c, 0
+
+.asm_34b28
+ ld a, [hli]
+ cp $ff
+ jr z, .asm_34b72
+
+ push hl
+ ld [CurSpecies], a
+ call GetBaseData
+ ld a, [LastEnemyCounterMove]
+ and a
+ jr z, .asm_34b4a
+
+ dec a
+ ld hl, Moves + MOVE_POWER
+ call GetMoveAttr
+ and a
+ jr z, .asm_34b4a
+
+ inc hl
+ call GetMoveByte
+ jr .asm_34b5d
+
+.asm_34b4a
+ ld a, [BattleMonType1]
+ ld hl, BaseType
+ call CheckTypeMatchup
+ ld a, [wTypeMatchup]
+ cp $b
+ jr nc, .asm_34b6d
+ ld a, [BattleMonType2]
+
+.asm_34b5d
+ ld hl, BaseType
+ call CheckTypeMatchup
+ ld a, [wTypeMatchup]
+ cp $b
+ jr nc, .asm_34b6d
+
+ ld a, b
+ or c
+ ld c, a
+
+.asm_34b6d
+ srl b
+ pop hl
+ jr .asm_34b28
+
+.asm_34b72
+ ld a, c
+ pop bc
+ and c
+ ld c, a
+ ret
+; 34b77
+
+
+Function34b77: ; 34b77
+ push bc
+ ld de, OTPartySpecies
+ ld b, 1 << (PARTY_LENGTH - 1)
+ ld c, 0
+ ld hl, OTPartyMon1HP
+
+.loop
+ ld a, [de]
+ inc de
+ cp $ff
+ jr z, .done
+
+ push hl
+ push bc
+ ld b, [hl]
+ inc hl
+ ld c, [hl]
+rept 2
+ inc hl
+endr
+ srl c
+ rl b
+ srl c
+ rl b
+ ld a, [hld]
+ cp c
+ ld a, [hl]
+ sbc b
+ pop bc
+ jr nc, .next
+
+ ld a, b
+ or c
+ ld c, a
+
+.next
+ srl b
+ pop hl
+ push bc
+ ld bc, PARTYMON_STRUCT_LENGTH
+ add hl, bc
+ pop bc
+ jr .loop
+
+.done
+ ld a, c
+ pop bc
+ and c
+ ld c, a
+ ret
+; 34bb1
--- a/battle/core.asm
+++ b/battle/core.asm
@@ -1865,13 +1865,13 @@
SubtractHPFromTarget: ; 3cc39
call SubtractHP
- jp Function3cd3c
+ jp UpdateHPBar
; 3cc3f
SubtractHPFromUser: ; 3cc3f
; Subtract HP from Pkmn
call SubtractHP
- jp Function3cd36
+ jp UpdateHPBarBattleHuds
; 3cc45
@@ -2040,20 +2040,20 @@
ld hl, BattleMonMaxHP
.ok
ld a, [hli]
- ld [Buffer1 + 1], a
+ ld [Buffer2], a
ld a, [hld]
- ld [Buffer1 + 0], a
+ ld [Buffer1], a
dec hl
ld a, [hl]
- ld [Buffer1 + 2], a
+ ld [Buffer3], a
add c
ld [hld], a
- ld [Buffer1 + 4], a
+ ld [Buffer5], a
ld a, [hl]
- ld [Buffer1 + 3], a
+ ld [Buffer4], a
adc b
ld [hli], a
- ld [Buffer1 + 5], a
+ ld [Buffer6], a
ld a, [Buffer1]
ld c, a
@@ -2066,23 +2066,23 @@
jr c, .asm_3cd2d
ld a, b
ld [hli], a
- ld [Buffer1 + 5], a
+ ld [Buffer6], a
ld a, c
ld [hl], a
- ld [Buffer1 + 4], a
+ ld [Buffer5], a
.asm_3cd2d
call SwitchTurnCore
- call Function3cd36
+ call UpdateHPBarBattleHuds
jp SwitchTurnCore
; 3cd36
-Function3cd36: ; 3cd36
- call Function3cd3c
+UpdateHPBarBattleHuds: ; 3cd36
+ call UpdateHPBar
jp UpdateBattleHuds
; 3cd3c
-Function3cd3c: ; 3cd3c
+UpdateHPBar: ; 3cd3c
hlcoord 10, 9
ld a, [hBattleTurn]
and a
@@ -2093,7 +2093,7 @@
.ok
push bc
ld [wd10a], a
- predef Functionc6e0
+ predef AnimateHPBar
pop bc
ret
; 3cd55
@@ -4558,7 +4558,7 @@
.asm_3dda4
ld [wd10a], a
- predef Functionc6e0
+ predef AnimateHPBar
UseOpponentItem:
call RefreshBattleHuds
callab GetOpponentItem
--- a/battle/effect_command_pointers.asm
+++ b/battle/effect_command_pointers.asm
@@ -163,7 +163,7 @@
dw BattleCommand_Teleport ; 36778
dw BattleCommand_BeatUp ; 35461
dw BattleCommand_RageDamage ; 3527b
- dw BattleCommanda3 ; 34833
+ dw BattleCommand_ResetTypeMatchup ; 34833
dw BattleCommand_AllStatsUp ; 36500
dw BattleCommanda5 ; 35165
dw BattleCommand_RaiseSubNoAnim ; 365af
--- a/battle/effect_commands.asm
+++ b/battle/effect_commands.asm
@@ -1600,12 +1600,14 @@
; 34833
-BattleCommanda3: ; 34833
+BattleCommand_ResetTypeMatchup: ; 34833
+; Reset the type matchup multiplier to 1.0, if the type matchup is not 0.
+; If there is immunity in play, the move automatically misses.
call BattleCheckTypeMatchup
ld a, [wTypeMatchup]
and a
ld a, 10 ; 1.0
- jr nz, .skip
+ jr nz, .reset
call ResetDamage
xor a
ld [TypeModifier], a
@@ -1613,674 +1615,13 @@
ld [AttackMissed], a
ret
-.skip
+.reset
ld [wTypeMatchup], a
ret
; 3484e
+INCLUDE "battle/ai/switch.asm"
-Function3484e: ; 3484e
- push hl
- push de
- push bc
- ld a, 10
- ld [wc716], a
- ld hl, PlayerUsedMoves
- ld a, [hl]
- and a
- jr z, .unknown_moves
-
- ld d, NUM_MOVES
- ld e, 0
-.loop
- ld a, [hli]
- and a
- jr z, .exit
- push hl
- dec a
- ld hl, Moves + MOVE_POWER
- call GetMoveAttr
- and a
- jr z, .next
-
- inc hl
- call GetMoveByte
- ld hl, EnemyMonType
- call CheckTypeMatchup
- ld a, [wTypeMatchup]
- cp 10 + 1 ; 1.0 + 0.1
- jr nc, .super_effective
- and a
- jr z, .next
- cp 10 ; 1.0
- jr nc, .neutral
-
-.not_very_effective
- ld a, e
- cp 1 ; 0.1
- jr nc, .next
- ld e, 1
- jr .next
-
-.neutral
- ld e, 2
- jr .next
-
-.super_effective
- call Function34931
- pop hl
- jr .done
-
-.next
- pop hl
- dec d
- jr nz, .loop
-
-.exit
- ld a, e
- cp 2
- jr z, .done
- call Function34939
- ld a, e
- and a
- jr nz, .done
- call Function34939
- jr .done
-
-.unknown_moves
- ld a, [BattleMonType1]
- ld b, a
- ld hl, EnemyMonType1
- call CheckTypeMatchup
- ld a, [wTypeMatchup]
- cp 10 + 1 ; 1.0 + 0.1
- jr c, .ok
- call Function34931
-.ok
- ld a, [BattleMonType2]
- cp b
- jr z, .ok2
- call CheckTypeMatchup
- ld a, [wTypeMatchup]
- cp 10 + 1 ; 1.0 + 0.1
- jr c, .ok2
- call Function34931
-.ok2
-
-.done
- call Function348de
- pop bc
- pop de
- pop hl
- ret
-; 348de
-
-
-Function348de: ; 348de
- ld de, EnemyMonMoves
- ld b, NUM_MOVES + 1
- ld c, 0
-
- ld a, [wTypeMatchup]
- push af
-.loop
- dec b
- jr z, .exit
-
- ld a, [de]
- and a
- jr z, .exit
-
- inc de
- dec a
- ld hl, Moves + MOVE_POWER
- call GetMoveAttr
- and a
- jr z, .loop
-
- inc hl
- call GetMoveByte
- ld hl, BattleMonType1
- call CheckTypeMatchup
-
- ld a, [wTypeMatchup]
- ; immune
- and a
- jr z, .loop
-
- ; not very effective
- inc c
- cp 10
- jr c, .loop
-
- ; neutral
-rept 5
- inc c
-endr
- cp 10
- jr z, .loop
-
- ; super effective
- ld c, 100
- jr .loop
-
-.exit
- pop af
- ld [wTypeMatchup], a
-
- ld a, c
- and a
- jr z, .doubledown ; double down
- cp 5
- jr c, Function34931 ; down
- cp 100
- ret c
- jr Function34939 ; up
-
-.doubledown
- call Function34931
-
- ; fallthrough
-; 34931
-
-
-Function34931: ; 34931
- ld a, [wc716]
- dec a
- ld [wc716], a
- ret
-; 34939
-
-
-Function34939: ; 34939
- ld a, [wc716]
- inc a
- ld [wc716], a
- ret
-; 34941
-
-
-Function34941: ; 34941
- xor a
- ld [wc717], a
- call CountEnemyAliveMons
- ret c
-
- ld a, [EnemySubStatus1]
- bit SUBSTATUS_PERISH, a
- jr z, .no_perish
-
- ld a, [EnemyPerishCount]
- cp 1
- jr nz, .no_perish
-
- ; Perish count is 1
-
- call CountEnemyAliveMons
- call Function34b77
- call Function34b20
- call Function34a85
-
- ld a, e
- cp 2
- jr nz, .asm_34971
-
- ld a, [wc716]
- add $30
- ld [wc717], a
- ret
-
-.asm_34971
- call CountEnemyAliveMons
- sla c
- sla c
- ld b, $ff
-
-.asm_3497a
- inc b
- sla c
- jr nc, .asm_3497a
-
- ld a, b
- add $30
- ld [wc717], a
- ret
-
-.no_perish
-
- call Function3484e
- ld a, [wc716]
- cp 11
- ret nc
-
- ld a, [LastEnemyCounterMove]
- and a
- jr z, .asm_349d2
-
- call Function34a2a
- ld a, [wc716]
- and a
- jr z, .asm_349d2
-
- ld c, a
- call Function34aa7
- ld a, [wc716]
- cp $ff
- ret z
-
- ld b, a
- ld a, e
- cp 2
- jr z, .asm_349be
-
- call Function3484e
- ld a, [wc716]
- cp 10
- ret nc
-
- ld a, b
- add $10
- ld [wc717], a
- ret
-
-.asm_349be
- ld c, $10
- call Function3484e
- ld a, [wc716]
- cp 10
- jr nc, .asm_349cc
- ld c, $20
-
-.asm_349cc
- ld a, b
- add c
- ld [wc717], a
- ret
-
-.asm_349d2
- call Function3484e
- ld a, [wc716]
- cp 10
- ret nc
-
- call CountEnemyAliveMons
- call Function34b77
- call Function34b20
- call Function34a85
-
- ld a, e
- cp $2
- ret nz
-
- ld a, [wc716]
- add $10
- ld [wc717], a
- ret
-; 349f4
-
-
-CountEnemyAliveMons: ; 349f4
- ld a, [OTPartyCount]
- cp 2
- jr c, .only_one
-
- ld d, a
- ld e, 0
- ld b, 1 << (PARTY_LENGTH - 1)
- ld c, 0
- ld hl, OTPartyMon1HP
-
-.loop
- ld a, [CurOTMon]
- cp e
- jr z, .next
-
- push bc
- ld b, [hl]
- inc hl
- ld a, [hld]
- or b
- pop bc
- jr z, .next
-
- ld a, c
- or b
- ld c, a
-
-.next
- srl b
- push bc
- ld bc, PARTYMON_STRUCT_LENGTH
- add hl, bc
- pop bc
- inc e
- dec d
- jr nz, .loop
-
- ld a, c
- and a
- jr nz, .more_than_one
-
-.only_one
- scf
- ret
-
-.more_than_one
- and a
- ret
-; 34a2a
-
-
-Function34a2a: ; 34a2a
- ld hl, OTPartyMon1
- ld a, [OTPartyCount]
- ld b, a
- ld c, 1 << (PARTY_LENGTH - 1)
- ld d, 0
- xor a
- ld [wc716], a
-
-.asm_34a39
- ld a, [CurOTMon]
- cp d
- push hl
- jr z, .asm_34a77
-
- push hl
- push bc
- ld bc, MON_HP
- add hl, bc
- pop bc
- ld a, [hli]
- or [hl]
- pop hl
- jr z, .asm_34a77
-
- ld a, [hl]
- ld [CurSpecies], a
- call GetBaseData
- ld a, [LastEnemyCounterMove]
- dec a
- ld hl, Moves + MOVE_POWER
- call GetMoveAttr
- and a
- jr z, .asm_34a77
-
- inc hl
- call GetMoveByte
- ld hl, BaseType
- call CheckTypeMatchup
- ld a, [wTypeMatchup]
- and a
- jr nz, .asm_34a77
-
- ld a, [wc716]
- or c
- ld [wc716], a
-.asm_34a77
- pop hl
- dec b
- ret z
-
- push bc
- ld bc, PARTYMON_STRUCT_LENGTH
- add hl, bc
- pop bc
-
- inc d
- srl c
- jr .asm_34a39
-; 34a85
-
-
-Function34a85: ; 34a85
- push bc
- ld a, [OTPartyCount]
- ld e, a
- ld hl, OTPartyMon1HP
- ld b, 1 << (PARTY_LENGTH - 1)
- ld c, 0
-.asm_34a91
- ld a, [hli]
- or [hl]
- jr z, .asm_34a98
-
- ld a, b
- or c
- ld c, a
-
-.asm_34a98
- srl b
- push bc
- ld bc, PartyMon2HP - (PartyMon1HP + 1)
- add hl, bc
- pop bc
- dec e
- jr nz, .asm_34a91
-
- ld a, c
- pop bc
-
- and c
- ld c, a
-
- ; fallthrough
-; 34aa7
-
-Function34aa7: ; 34aa7
-
- ld a, $ff
- ld [wc716], a
- ld hl, OTPartyMon1Moves
- ld b, 1 << (PARTY_LENGTH - 1)
- ld d, 0
- ld e, 0
-.asm_34ab5
- ld a, b
- and c
- jr z, .asm_34b00
-
- push hl
- push bc
- ld b, NUM_MOVES
- ld c, 0
-.asm_34abf
- ld a, [hli]
- and a
- push hl
- jr z, .asm_34aef
-
- dec a
- ld hl, Moves + MOVE_POWER
- call GetMoveAttr
- and a
- jr z, .asm_34ae9
-
- inc hl
- call GetMoveByte
- ld hl, BattleMonType1
- call CheckTypeMatchup
- ld a, [wTypeMatchup]
- cp 10
- jr c, .asm_34ae9
-
- ld e, 1
- cp 11
- jr c, .asm_34ae9
-
- ld e, 2
- jr .asm_34aef
-
-.asm_34ae9
- pop hl
- dec b
- jr nz, .asm_34abf
-
- jr .asm_34af0
-
-.asm_34aef
- pop hl
-.asm_34af0
- ld a, e
- pop bc
- pop hl
- cp $2
- jr z, .asm_34b0e
-
- cp $1
- jr nz, .asm_34b00
-
- ld a, d
- or b
- ld d, a
- jr .asm_34b00
-
-.asm_34b00
- push bc
- ld bc, PARTYMON_STRUCT_LENGTH
- add hl, bc
- pop bc
- srl b
- jr nc, .asm_34ab5
-
- ld a, d
- ld b, a
- and a
- ret z
-
-.asm_34b0e
- push bc
- sla b
- sla b
- ld c, $ff
-.asm_34b15
- inc c
- sla b
- jr nc, .asm_34b15
-
- ld a, c
- ld [wc716], a
- pop bc
- ret
-; 34b20
-
-
-Function34b20: ; 34b20
- push bc
- ld hl, OTPartySpecies
- ld b, 1 << (PARTY_LENGTH - 1)
- ld c, 0
-
-.asm_34b28
- ld a, [hli]
- cp $ff
- jr z, .asm_34b72
-
- push hl
- ld [CurSpecies], a
- call GetBaseData
- ld a, [LastEnemyCounterMove]
- and a
- jr z, .asm_34b4a
-
- dec a
- ld hl, Moves + MOVE_POWER
- call GetMoveAttr
- and a
- jr z, .asm_34b4a
-
- inc hl
- call GetMoveByte
- jr .asm_34b5d
-
-.asm_34b4a
- ld a, [BattleMonType1]
- ld hl, BaseType
- call CheckTypeMatchup
- ld a, [wTypeMatchup]
- cp $b
- jr nc, .asm_34b6d
- ld a, [BattleMonType2]
-
-.asm_34b5d
- ld hl, BaseType
- call CheckTypeMatchup
- ld a, [wTypeMatchup]
- cp $b
- jr nc, .asm_34b6d
-
- ld a, b
- or c
- ld c, a
-
-.asm_34b6d
- srl b
- pop hl
- jr .asm_34b28
-
-.asm_34b72
- ld a, c
- pop bc
- and c
- ld c, a
- ret
-; 34b77
-
-
-Function34b77: ; 34b77
- push bc
- ld de, OTPartySpecies
- ld b, 1 << (PARTY_LENGTH - 1)
- ld c, 0
- ld hl, OTPartyMon1HP
-
-.loop
- ld a, [de]
- inc de
- cp $ff
- jr z, .done
-
- push hl
- push bc
- ld b, [hl]
- inc hl
- ld c, [hl]
-rept 2
- inc hl
-endr
- srl c
- rl b
- srl c
- rl b
- ld a, [hld]
- cp c
- ld a, [hl]
- sbc b
- pop bc
- jr nc, .next
-
- ld a, b
- or c
- ld c, a
-
-.next
- srl b
- pop hl
- push bc
- ld bc, PARTYMON_STRUCT_LENGTH
- add hl, bc
- pop bc
- jr .loop
-
-.done
- ld a, c
- pop bc
- and c
- ld c, a
- ret
-; 34bb1
-
-
TypeMatchup: ; 34bb1
INCLUDE "battle/type_matchup.asm"
; 34cfd
@@ -2779,11 +2120,11 @@
and a
ld de, PlayerRolloutCount
ld a, 1
- jr z, .asm_34f76
+ jr z, .got_rollout_count
ld de, EnemyRolloutCount
ld a, 4
-.asm_34f76
+.got_rollout_count
ld [wcfca], a
ld a, BATTLE_VARS_MOVE_EFFECT
call GetBattleVar
@@ -3234,18 +2575,18 @@
ld a, [hld]
ld [Buffer2], a
ld a, [hl]
- ld [wd1ec], a
+ ld [Buffer3], a
xor a
ld [hld], a
ld a, [hl]
- ld [wd1ed], a
+ ld [Buffer4], a
xor a
ld [hl], a
- ld [wd1ee], a
- ld [wd1ef], a
+ ld [Buffer5], a
+ ld [Buffer6], a
ld h, b
ld l, c
- predef Functionc6e0
+ predef AnimateHPBar
call RefreshBattleHuds
call BattleCommand_SwitchTurn
@@ -4449,7 +3790,7 @@
cp EFFECT_COUNTER
ret z
- call BattleCommanda3
+ call BattleCommand_ResetTypeMatchup
ld a, [wTypeMatchup]
and a
ret z
@@ -4633,12 +3974,12 @@
ld a, $1
ld [wd10a], a
hlcoord 10, 9
- predef Functionc6e0
+ predef AnimateHPBar
ld hl, EnemyMonHP
ld a, [hli]
- ld [wd1ed], a
+ ld [Buffer4], a
ld a, [hli]
- ld [wd1ec], a
+ ld [Buffer3], a
ld a, [hli]
ld [Buffer2], a
ld a, [hl]
@@ -4648,7 +3989,7 @@
ld [wd10a], a
call ResetDamage
hlcoord 2, 2
- predef Functionc6e0
+ predef AnimateHPBar
callba Function178000
ld hl, SharedPainText
@@ -4661,9 +4002,9 @@
ld [Buffer2], a
ld a, [hld]
ld b, a
- ld [wd1ec], a
+ ld [Buffer3], a
ld a, [hl]
- ld [wd1ed], a
+ ld [Buffer4], a
rept 2
dec de
endr
@@ -4708,10 +4049,10 @@
.asm_359c2
ld a, c
ld [hld], a
- ld [wd1ee], a
+ ld [Buffer5], a
ld a, b
ld [hli], a
- ld [wd1ef], a
+ ld [Buffer6], a
ret
; 359cd
@@ -5331,20 +4672,20 @@
ld a, [hld]
ld b, a
ld a, [EnemyMonHP + 1]
- ld [wd1ec], a
+ ld [Buffer3], a
sub b
ld [EnemyMonHP + 1], a
ld a, [hl]
ld b, a
ld a, [EnemyMonHP]
- ld [wd1ec + 1], a
+ ld [Buffer4], a
sbc b
ld [EnemyMonHP], a
jr nc, .asm_35d59
- ld a, [wd1ed]
+ ld a, [Buffer4]
ld [hli], a
- ld a, [wd1ec]
+ ld a, [Buffer3]
ld [hl], a
xor a
@@ -5360,13 +4701,13 @@
ld [Buffer1], a
ld hl, EnemyMonHP
ld a, [hli]
- ld [wd1ef], a
+ ld [Buffer6], a
ld a, [hl]
- ld [wd1ee], a
+ ld [Buffer5], a
hlcoord 2, 2
xor a
ld [wd10a], a
- predef Functionc6e0
+ predef AnimateHPBar
.asm_35d7b
jp RefreshBattleHuds
; 35d7e
@@ -5391,21 +4732,21 @@
ld a, [hld]
ld b, a
ld a, [BattleMonHP + 1]
- ld [wd1ec], a
+ ld [Buffer3], a
sub b
ld [BattleMonHP + 1], a
- ld [wd1ee], a
+ ld [Buffer5], a
ld b, [hl]
ld a, [BattleMonHP]
- ld [wd1ec + 1], a
+ ld [Buffer4], a
sbc b
ld [BattleMonHP], a
- ld [wd1ee + 1], a
+ ld [Buffer6], a
jr nc, .asm_35dc5
- ld a, [wd1ec + 1]
+ ld a, [Buffer4]
ld [hli], a
- ld a, [wd1ec]
+ ld a, [Buffer3]
ld [hl], a
xor a
@@ -5412,7 +4753,7 @@
ld hl, BattleMonHP
ld [hli], a
ld [hl], a
- ld hl, wd1ee
+ ld hl, Buffer5
ld [hli], a
ld [hl], a
@@ -5425,7 +4766,7 @@
hlcoord 10, 9
ld a, $1
ld [wd10a], a
- predef Functionc6e0
+ predef AnimateHPBar
.asm_35ddd
jp RefreshBattleHuds
; 35de0
@@ -5826,7 +5167,7 @@
ld hl, EnemyMonHP
ld de, EnemyMonMaxHP
.battlemonhp
- ld bc, wd1ed
+ ld bc, Buffer4
ld a, [hli]
ld [bc], a
ld a, [hl]
@@ -5843,12 +5184,12 @@
ld b, [hl]
add b
ld [hld], a
- ld [wd1ee], a
+ ld [Buffer5], a
ld a, [hDividend]
ld b, [hl]
adc b
ld [hli], a
- ld [wd1ef], a
+ ld [Buffer6], a
jr c, .okay2 ; 0x36056 $c
ld a, [hld]
ld b, a
@@ -5864,11 +5205,11 @@
.okay2
ld a, [de]
ld [hld], a
- ld [wd1ee], a
+ ld [Buffer5], a
dec de
ld a, [de]
ld [hli], a
- ld [wd1ef], a
+ ld [Buffer6], a
inc de
.okay3
ld a, [hBattleTurn]
@@ -5880,7 +5221,7 @@
xor a
.hp_bar
ld [wd10a], a
- predef Functionc6e0
+ predef AnimateHPBar
call RefreshBattleHuds
jp UpdateBattleMonInParty
; 3608c
@@ -8019,20 +7360,20 @@
dec hl
endr
ld a, [hl]
- ld [wd1ec], a
+ ld [Buffer3], a
sub c
ld [hld], a
- ld [wd1ee], a
+ ld [Buffer5], a
ld a, [hl]
- ld [wd1ed], a
+ ld [Buffer4], a
sbc b
ld [hl], a
- ld [wd1ef], a
+ ld [Buffer6], a
jr nc, .asm_36cfe
xor a
ld [hli], a
ld [hl], a
- ld hl, wd1ee
+ ld hl, Buffer5
ld [hli], a
ld [hl], a
.asm_36cfe
@@ -8045,7 +7386,7 @@
xor a
.asm_36d0c
ld [wd10a], a
- predef Functionc6e0
+ predef AnimateHPBar
call RefreshBattleHuds
ld hl, RecoilText
jp StdBattleTextBox
@@ -10097,7 +9438,7 @@
cp EFFECT_MIRROR_COAT
ret z
- call BattleCommanda3
+ call BattleCommand_ResetTypeMatchup
ld a, [wTypeMatchup]
and a
ret z
--- a/battle/moves/move_effects.asm
+++ b/battle/moves/move_effects.asm
@@ -898,7 +898,7 @@
doturn
usedmovetext
unleashenergy
- effect0xa3
+ resettypematchup
checkhit
hittarget
effect0xa5
@@ -1398,7 +1398,7 @@
doturn
constantdamage
checkhit
- effect0xa3
+ resettypematchup
hittarget
resulttext
checkfaint
--- a/engine/predef.asm
+++ b/engine/predef.asm
@@ -41,7 +41,7 @@
add_predef SentGetPkmnIntoFromBox
add_predef SentPkmnIntoBox
add_predef GiveEgg
- add_predef Functionc6e0
+ add_predef AnimateHPBar
add_predef CalcPkmnStats
add_predef CalcPkmnStatC
add_predef CanLearnTMHMMove
--- a/items/item_effects.asm
+++ b/items/item_effects.asm
@@ -1842,7 +1842,7 @@
call AddNTimes
ld a, $2
ld [wd10a], a
- predef_jump Functionc6e0
+ predef_jump AnimateHPBar
Functionf1f9: ; f1f9 (3:71f9)
call Functionf20b
--- a/macros/move_effect.asm
+++ b/macros/move_effect.asm
@@ -167,7 +167,7 @@
command teleport
command beatup
command ragedamage
- command effect0xa3
+ command resettypematchup
command allstatsup
command effect0xa5
command raisesubnoanim
--- a/main.asm
+++ b/main.asm
@@ -4525,9 +4525,9 @@
ret
; c6e0
-Functionc6e0: ; c6e0
+AnimateHPBar: ; c6e0
call WaitBGMap
- call Functiond627
+ call _AnimateHPBar
call WaitBGMap
ret
; c6ea
@@ -7495,11 +7495,11 @@
inc [hl]
ret
-Functiond627: ; d627
+_AnimateHPBar: ; d627
call Functiond65f
- jr c, .asm_d645
+ jr c, .do_player
call Functiond670
-.asm_d62f
+.enemy_loop
push bc
push hl
call Functiond6e2
@@ -7513,12 +7513,12 @@
pop hl
pop bc
pop af
- jr nc, .asm_d62f
+ jr nc, .enemy_loop
ret
-.asm_d645
+.do_player
call Functiond670
-.asm_d648
+.player_loop
push bc
push hl
call Functiond6f5
@@ -7533,7 +7533,7 @@
pop hl
pop bc
pop af
- jr nc, .asm_d648
+ jr nc, .player_loop
ret
; d65f
@@ -7540,14 +7540,14 @@
Functiond65f: ; d65f
ld a, [Buffer2]
and a
- jr nz, .asm_d66e
+ jr nz, .player
ld a, [Buffer1]
cp $30
- jr nc, .asm_d66e
+ jr nc, .player
and a
ret
-.asm_d66e
+.player
scf
ret
; d670
--- a/wram.asm
+++ b/wram.asm
@@ -1776,6 +1776,7 @@
wd1ed:: ds 1
Buffer5::
wd1ee:: ds 1
+Buffer6::
wd1ef:: ds 1
wd1f0:: ds 1
wd1f1:: ds 1