pokered/engine/battle/moveEffects/substitute_effect.asm

78 lines
1.8 KiB
NASM
Raw Normal View History

SubstituteEffect_: ; 17dad (5:7dad)
2014-05-22 22:13:20 +00:00
ld c, 50
call DelayFrames
ld hl, wBattleMonMaxHP
2014-05-22 22:13:20 +00:00
ld de, wPlayerSubstituteHP
ld bc, W_PLAYERBATTSTATUS2
2015-02-08 00:24:16 +00:00
ld a, [H_WHOSETURN]
2014-05-22 22:13:20 +00:00
and a
jr z, .notEnemy
ld hl, wEnemyMonMaxHP
2014-05-22 22:13:20 +00:00
ld de, wEnemySubstituteHP
ld bc, W_ENEMYBATTSTATUS2
.notEnemy
2015-06-11 22:41:33 +00:00
ld a, [bc]
bit HasSubstituteUp, a ; user already has substitute?
2015-06-11 22:41:33 +00:00
jr nz, .alreadyHasSubstitute
; quarter health to remove from user
2015-06-11 22:41:33 +00:00
; assumes max HP is 1023 or lower
2014-05-22 22:13:20 +00:00
push bc
ld a, [hli]
2014-05-22 22:13:20 +00:00
ld b, [hl]
2015-06-11 22:41:33 +00:00
srl a
2014-05-22 22:13:20 +00:00
rr b
srl a
rr b ; max hp / 4
2014-05-22 22:13:20 +00:00
push de
2015-02-08 00:24:16 +00:00
ld de, wBattleMonHP - wBattleMonMaxHP
add hl, de ; point hl to current HP low byte
2014-05-22 22:13:20 +00:00
pop de
2015-06-11 22:41:33 +00:00
ld a, b
ld [de], a ; save copy of HP to subtract in ccd7/ccd8 [how much HP substitute has]
ld a, [hld]
2015-06-11 22:41:33 +00:00
; subtract [max hp / 4] to current HP
sub b
ld d, a
2014-05-22 22:13:20 +00:00
ld a, [hl]
2015-06-11 22:41:33 +00:00
sbc 0
2014-05-22 22:13:20 +00:00
pop bc
jr c, .notEnoughHP ; underflow means user would be left with negative health
; bug: since it only brances on carry, it will possibly leave user with 0 HP
2014-05-22 22:13:20 +00:00
.userHasZeroOrMoreHP
ldi [hl], a ; save resulting HP after substraction into current HP
2015-06-11 22:41:33 +00:00
ld [hl], d
2014-05-22 22:13:20 +00:00
ld h, b
ld l, c
2015-06-11 22:41:33 +00:00
set HasSubstituteUp, [hl]
ld a, [W_OPTIONS]
bit 7, a ; battle animation is enabled?
2015-06-11 22:41:33 +00:00
ld hl, PlayCurrentMoveAnimation
2015-02-08 00:24:16 +00:00
ld b, BANK(PlayCurrentMoveAnimation)
2014-05-22 22:13:20 +00:00
jr z, .animationEnabled
2015-06-11 22:41:33 +00:00
ld hl, AnimationSubstitute
2014-05-22 22:13:20 +00:00
ld b, BANK(AnimationSubstitute)
.animationEnabled
call Bankswitch ; jump to routine depending on animation setting
2014-05-22 22:13:20 +00:00
ld hl, SubstituteText
call PrintText
2015-07-19 18:56:13 +00:00
jpab DrawHUDsAndHPBars
2014-05-22 22:13:20 +00:00
.alreadyHasSubstitute
ld hl, HasSubstituteText
jr .printText
.notEnoughHP
ld hl, TooWeakSubstituteText
.printText
jp PrintText
SubstituteText: ; 17e1d (5:7e1d)
TX_FAR _SubstituteText
db "@"
HasSubstituteText: ; 17e22 (5:7e22)
TX_FAR _HasSubstituteText
db "@"
TooWeakSubstituteText: ; 17e27 (5:7e27)
TX_FAR _TooWeakSubstituteText
db "@"