pokered/engine/battle/move_effects/substitute.asm

78 lines
1.8 KiB
NASM
Raw Normal View History

2016-06-12 00:24:04 +00:00
SubstituteEffect_:
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
2015-08-31 02:38:41 +00:00
ld bc, wPlayerBattleStatus2
ldh a, [hWhoseTurn]
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
2015-08-31 02:38:41 +00:00
ld bc, wEnemyBattleStatus2
2014-05-22 22:13:20 +00:00
.notEnemy
2015-06-11 22:41:33 +00:00
ld a, [bc]
2017-12-29 23:59:48 +00:00
bit HAS_SUBSTITUTE_UP, 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
2020-06-28 03:03:39 +00:00
ld [de], a ; save copy of HP to subtract in wPlayerSubstituteHP/wEnemySubstituteHP
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
2017-06-24 20:01:43 +00:00
; bug: since it only branches on carry, it will possibly leave user with 0 HP
2014-05-22 22:13:20 +00:00
.userHasZeroOrMoreHP
2017-06-24 20:01:43 +00:00
ldi [hl], a ; save resulting HP after subtraction 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
2017-12-29 23:59:48 +00:00
set HAS_SUBSTITUTE_UP, [hl]
2015-08-31 02:38:41 +00:00
ld a, [wOptions]
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
jpfar DrawHUDsAndHPBars
2014-05-22 22:13:20 +00:00
.alreadyHasSubstitute
ld hl, HasSubstituteText
jr .printText
.notEnoughHP
ld hl, TooWeakSubstituteText
.printText
jp PrintText
2016-06-12 00:24:04 +00:00
SubstituteText:
text_far _SubstituteText
text_end
2014-05-22 22:13:20 +00:00
2016-06-12 00:24:04 +00:00
HasSubstituteText:
text_far _HasSubstituteText
text_end
2014-05-22 22:13:20 +00:00
2016-06-12 00:24:04 +00:00
TooWeakSubstituteText:
text_far _TooWeakSubstituteText
text_end