summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorElectroDeoxys <ElectroDeoxys@gmail.com>2019-07-27 09:56:52 +0100
committerElectroDeoxys <ElectroDeoxys@gmail.com>2019-08-07 23:24:59 +0100
commitc389a257b6c1a43bba47aee765dadd051be74890 (patch)
treef30ebe867246d183d617165f549433eb378cbfdc /src
parent5e7a4a99fc6c3cb69826462f70f3c112dc834d4e (diff)
Disassemble CalculateDamage functions
Diffstat (limited to 'src')
-rw-r--r--src/engine/bank05.asm285
1 files changed, 261 insertions, 24 deletions
diff --git a/src/engine/bank05.asm b/src/engine/bank05.asm
index bc75e2f..3b9b1ae 100644
--- a/src/engine/bank05.asm
+++ b/src/engine/bank05.asm
@@ -96,7 +96,7 @@ CheckIfAnyMoveKnocksOutDefendingCard: ; 140ae (5:40ae)
; fallthrough
CheckIfMoveKnocksOutDefendingCard: ; 140b5 (5:40b5)
- call CalculateSelectedMoveDamageDoneToDefendingCard
+ call CalculateMoveDamage_VersusDefendingCard
ld a, DUELVARS_ARENA_CARD_HP
call GetNonTurnDuelistVariable
ld hl, wDamage
@@ -251,14 +251,14 @@ CheckEnergyNeededForAttack: ; 14279 (5:4279)
jr z, .no_move
ld a, [wLoadedMoveCategory]
cp POKEMON_POWER
- jr nz, .not_pokemon_power
+ jr nz, .is_move
.no_move
lb bc, $00, $00
ld e, c
scf
ret
-.not_pokemon_power
+.is_move
ldh a, [hTempPlayAreaLocation_ff9d]
ld e, a
call GetPlayAreaCardAttachedEnergies
@@ -446,7 +446,7 @@ Func_143bf: ; 143bf (5:43bf)
; input:
; a = move index to take into account
; hTempPlayAreaLocation_ff9d = location of attacking card to consider
-CalculateSelectedMoveDamageDoneToDefendingCard: ; 143e5 (5:43e5)
+CalculateMoveDamage_VersusDefendingCard: ; 143e5 (5:43e5)
ld [wSelectedMoveIndex], a
ld e, a
ldh a, [hTempPlayAreaLocation_ff9d]
@@ -456,9 +456,10 @@ CalculateSelectedMoveDamageDoneToDefendingCard: ; 143e5 (5:43e5)
call CopyMoveDataAndDamage_FromDeckIndex
ld a, [wLoadedMoveCategory]
cp POKEMON_POWER
- jr nz, .not_pokemon_power
+ jr nz, .is_move
- ; set wDamage, wAIMinDamage and wAIMaxDamage to zero
+; is a Pokémon Power
+; set wDamage, wAIMinDamage and wAIMaxDamage to zero
ld hl, wDamage
xor a
ld [hli], a
@@ -469,8 +470,8 @@ CalculateSelectedMoveDamageDoneToDefendingCard: ; 143e5 (5:43e5)
ld d, a
ret
-.not_pokemon_power
- ; set wAIMinDamage and wAIMaxDamage to damage of move
+.is_move
+; set wAIMinDamage and wAIMaxDamage to damage of move
ld a, [wDamage]
ld [wAIMinDamage], a
ld [wAIMaxDamage], a
@@ -488,7 +489,7 @@ CalculateSelectedMoveDamageDoneToDefendingCard: ; 143e5 (5:43e5)
; if temp. location is active, damage calculation can be done directly...
ldh a, [hTempPlayAreaLocation_ff9d]
or a
- jr z, CalculateDamageDoneToDefendingCard
+ jr z, CalculateDamage_VersusDefendingPokemon
; ...otherwise substatuses need to be temporarily reset to account
; for the switching, to obtain the right damage calculation...
@@ -510,7 +511,7 @@ CalculateSelectedMoveDamageDoneToDefendingCard: ; 143e5 (5:43e5)
push af
push hl
ld [hl], $00
- call CalculateDamageDoneToDefendingCard
+ call CalculateDamage_VersusDefendingPokemon
; ...and subsequently recovered to continue the battle normally
pop hl
pop af
@@ -528,19 +529,19 @@ CalculateSelectedMoveDamageDoneToDefendingCard: ; 143e5 (5:43e5)
; taking into account weakness/resistance/pluspowers/defenders/etc
; and outputs the result capped at a max of $ff
; input:
-; wAIMinDamage -> base damage
-; wAIMaxDamage -> base damage
-; wDamage -> base damage
-; hTempPlayAreaLocation_ff9d = turn holder's card location as the attacker
-CalculateDamageDoneToDefendingCard: ; 14453 (5:4453)
+; [wAIMinDamage] = base damage
+; [wAIMaxDamage] = base damage
+; [wDamage] = base damage
+; hTempPlayAreaLocation_ff9d = turn holder's card location as the attacker
+CalculateDamage_VersusDefendingPokemon: ; 14453 (5:4453)
ld hl, wAIMinDamage
- call _CalculateDamageDoneToDefendingCard
+ call _CalculateDamage_VersusDefendingPokemon
ld hl, wAIMaxDamage
- call _CalculateDamageDoneToDefendingCard
+ call _CalculateDamage_VersusDefendingPokemon
ld hl, wDamage
; fallthrough
-_CalculateDamageDoneToDefendingCard: ; 14462 (5:4462)
+_CalculateDamage_VersusDefendingPokemon: ; 14462 (5:4462)
ld e, [hl]
ld d, $00
push hl
@@ -580,7 +581,7 @@ _CalculateDamageDoneToDefendingCard: ; 14462 (5:4462)
res 7, d
jr nz, .not_resistant
- ; figure out if player's card is weak to this card
+; handle weakness
ldh a, [hTempPlayAreaLocation_ff9d]
call GetPlayAreaCardColor
call TranslateColorToWR
@@ -595,7 +596,7 @@ _CalculateDamageDoneToDefendingCard: ; 14462 (5:4462)
rl d
.not_weak
- ; figure out if player's card is resists this card
+; handle resistance
call SwapTurn
call GetArenaCardResistance
call SwapTurn
@@ -652,8 +653,244 @@ _CalculateDamageDoneToDefendingCard: ; 14462 (5:4462)
ret
; 0x1450b
-Func_1450b ; 1450b (5:450b)
- INCROM $1450b, $14663
+; stores in wDamage, wAIMinDamage and wAIMaxDamage the calculated damage
+; done to the Pokémon at hTempPlayAreaLocation_ff9d
+; by the defending Pokémon, using the move index at a
+; input:
+; a = move index
+; hTempPlayAreaLocation_ff9d = location of card to calculate
+; damage as the receiver
+CalculateMoveDamage_FromDefendingPokemon: ; 1450b (5:450b)
+ call SwapTurn
+ ld [wSelectedMoveIndex], a
+ ld e, a
+ ld a, DUELVARS_ARENA_CARD
+ call GetTurnDuelistVariable
+ ld d, a
+ call CopyMoveDataAndDamage_FromDeckIndex
+ call SwapTurn
+ ld a, [wLoadedMoveCategory]
+ cp POKEMON_POWER
+ jr nz, .is_move
+
+; is a Pokémon Power
+; set wDamage, wAIMinDamage and wAIMaxDamage to zero
+ ld hl, wDamage
+ xor a
+ ld [hli], a
+ ld [hl], a
+ ld [wAIMinDamage], a
+ ld [wAIMaxDamage], a
+ ld e, a
+ ld d, a
+ ret
+
+.is_move
+; set wAIMinDamage and wAIMaxDamage to damage of move
+ ld a, [wDamage]
+ ld [wAIMinDamage], a
+ ld [wAIMaxDamage], a
+ call SwapTurn
+ ldh a, [hTempPlayAreaLocation_ff9d]
+ push af
+ xor a
+ ldh [hTempPlayAreaLocation_ff9d], a
+ ld a, EFFECTCMDTYPE_AI
+ call TryExecuteEffectCommandFunction
+ pop af
+ ldh [hTempPlayAreaLocation_ff9d], a
+ call SwapTurn
+ ld a, [wAIMinDamage]
+ ld hl, wAIMaxDamage
+ or [hl]
+ jr nz, .calculation
+ ld a, [wDamage]
+ ld [wAIMinDamage], a
+ ld [wAIMaxDamage], a
+
+.calculation
+; if temp. location is active, damage calculation can be done directly...
+ ldh a, [hTempPlayAreaLocation_ff9d]
+ or a
+ jr z, CalculateDamage_FromDefendingPokemon
+
+; ...otherwise substatuses need to be temporarily reset to account
+; for the switching, to obtain the right damage calculation...
+ ld a, DUELVARS_ARENA_CARD_SUBSTATUS1
+ call GetTurnDuelistVariable
+ push af
+ push hl
+ ld [hl], $00
+ ; reset substatus2
+ ld l, DUELVARS_ARENA_CARD_SUBSTATUS2
+ ld a, [hl]
+ push af
+ push hl
+ ld [hl], $00
+ ; reset changed resistance
+ ld l, DUELVARS_ARENA_CARD_CHANGED_RESISTANCE
+ ld a, [hl]
+ push af
+ push hl
+ ld [hl], $00
+ call CalculateDamage_FromDefendingPokemon
+; ...and subsequently recovered to continue the battle normally
+ pop hl
+ pop af
+ ld [hl], a
+ pop hl
+ pop af
+ ld [hl], a
+ pop hl
+ pop af
+ ld [hl], a
+ ret
+
+; similar to CalculateDamage_VersusDefendingPokemon but reversed,
+; calculating damage of the defending Pokémon versus
+; the card located in hTempPlayAreaLocation_ff9d
+; taking into account weakness/resistance/pluspowers/defenders/etc
+; and poison damage for two turns
+; and outputs the result capped at a max of $ff
+; input:
+; [wAIMinDamage] = base damage
+; [wAIMaxDamage] = base damage
+; [wDamage] = base damage
+; hTempPlayAreaLocation_ff9d = location of card to calculate
+; damage as the receiver
+CalculateDamage_FromDefendingPokemon: ; 1458c (5:458c)
+ ld hl, wAIMinDamage
+ call _CalculateDamage_FromDefendingPokemon
+ ld hl, wAIMaxDamage
+ call _CalculateDamage_FromDefendingPokemon
+ ld hl, wDamage
+; fallthrough
+
+_CalculateDamage_FromDefendingPokemon: ; 1459b (5:459b)
+ ld e, [hl]
+ ld d, $00
+ push hl
+
+ ; load player active card's data
+ call SwapTurn
+ ld a, DUELVARS_ARENA_CARD
+ call GetTurnDuelistVariable
+ call LoadCardDataToBuffer2_FromDeckIndex
+ ld a, [wLoadedCard2ID]
+ ld [wTempTurnDuelistCardID], a
+ call SwapTurn
+
+ ; load opponent's card data
+ ldh a, [hTempPlayAreaLocation_ff9d]
+ add DUELVARS_ARENA_CARD
+ call GetTurnDuelistVariable
+ call LoadCardDataToBuffer2_FromDeckIndex
+ ld a, [wLoadedCard2ID]
+ ld [wTempNonTurnDuelistCardID], a
+
+ call SwapTurn
+ call HandleDoubleDamageSubstatus
+ bit 7, d
+ res 7, d
+ jr nz, .not_resistant
+
+; handle weakness
+ call GetArenaCardColor
+ call TranslateColorToWR
+ ld b, a
+ call SwapTurn
+ ldh a, [hTempPlayAreaLocation_ff9d]
+ or a
+ jr nz, .bench_weak
+ ld a, DUELVARS_ARENA_CARD_CHANGED_WEAKNESS
+ call GetTurnDuelistVariable
+ or a
+ jr nz, .unchanged_weak
+
+.bench_weak
+ ldh a, [hTempPlayAreaLocation_ff9d]
+ add DUELVARS_ARENA_CARD
+ call GetTurnDuelistVariable
+ call LoadCardDataToBuffer2_FromDeckIndex
+ ld a, [wLoadedCard2Weakness]
+.unchanged_weak
+ and b
+ jr z, .not_weak
+ ; double de
+ sla e
+ rl d
+
+.not_weak
+; handle resistance
+ ldh a, [hTempPlayAreaLocation_ff9d]
+ or a
+ jr nz, .bench_res
+ ld a, DUELVARS_ARENA_CARD_CHANGED_RESISTANCE
+ call GetTurnDuelistVariable
+ or a
+ jr nz, .unchanged_res
+
+.bench_res
+ ldh a, [hTempPlayAreaLocation_ff9d]
+ add DUELVARS_ARENA_CARD
+ call GetTurnDuelistVariable
+ call LoadCardDataToBuffer2_FromDeckIndex
+ ld a, [wLoadedCard2Resistance]
+.unchanged_res
+ and b
+ jr z, .not_resistant
+ ld hl, -30
+ add hl, de
+ ld e, l
+ ld d, h
+
+.not_resistant
+ ; apply pluspower and defender boosts
+ call SwapTurn
+ ld b, CARD_LOCATION_ARENA
+ call ApplyAttachedPluspower
+ call SwapTurn
+ ldh a, [hTempPlayAreaLocation_ff9d]
+ add CARD_LOCATION_ARENA
+ ld b, a
+ call ApplyAttachedDefender
+ ldh a, [hTempPlayAreaLocation_ff9d]
+ or a
+ call z, HandleDamageReduction
+ bit 7, d
+ jr z, .no_underflow
+ ld de, $0
+
+.no_underflow
+ ldh a, [hTempPlayAreaLocation_ff9d]
+ or a
+ jr nz, .done
+ ld a, DUELVARS_ARENA_CARD_STATUS
+ call GetTurnDuelistVariable
+ and DOUBLE_POISONED
+ jr z, .done
+ ld c, 40
+ and DOUBLE_POISONED & (POISONED ^ $ff)
+ jr nz, .add_poison
+ ld c, 20
+.add_poison
+ ld a, c
+ add e
+ ld e, a
+ ld a, $00
+ adc d
+ ld d, a
+
+.done
+ pop hl
+ ld [hl], e
+ ld a, d
+ or a
+ ret z
+ ld a, $ff
+ ld [hl], a
+ ret
+; 0x14663
Func_14663: ; 14663 (5:4663)
farcall Func_200e5
@@ -1743,7 +1980,7 @@ Func_173b1: ; 173b1 (5:73b1)
; 0x173e4
; input:
-; a = move to check
+; a = move index
Func_173e4: ; 173e4 (5:73e4)
ld [wSelectedMoveIndex], a
ldh a, [hTempPlayAreaLocation_ff9d]
@@ -1760,7 +1997,7 @@ Func_173e4: ; 173e4 (5:73e4)
; player's active Pokémon can use move
ld a, [wSelectedMoveIndex]
- call Func_1450b
+ call CalculateMoveDamage_FromDefendingPokemon
ldh a, [hTempPlayAreaLocation_ff9d]
add DUELVARS_ARENA_CARD_HP
call GetTurnDuelistVariable