summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlibjet <libj3t@gmail.com>2020-05-21 15:03:50 +0100
committerlibjet <libj3t@gmail.com>2020-05-21 15:03:50 +0100
commit5352a66c1124ae69430590f1b7b1abf022f3436e (patch)
tree4ffab03846b2bbd94ed10ec85d1d23fdad9bba71
parentaa4e2677fe574014cf1c43ba890df9773a83fc10 (diff)
Add engine/events/poisonstep.asm
-rwxr-xr-xengine/events/poisonstep.asm154
-rw-r--r--main.asm5
2 files changed, 157 insertions, 2 deletions
diff --git a/engine/events/poisonstep.asm b/engine/events/poisonstep.asm
new file mode 100755
index 00000000..98a6e25a
--- /dev/null
+++ b/engine/events/poisonstep.asm
@@ -0,0 +1,154 @@
+DoPoisonStep::
+ ld a, [wPartyCount]
+ and a
+ jr z, .no_faint
+
+ xor a
+ ld c, wPoisonStepDataEnd - wPoisonStepData
+ ld hl, wPoisonStepData
+.loop_clearPoisonStepData
+ ld [hli], a
+ dec c
+ jr nz, .loop_clearPoisonStepData
+
+ xor a
+ ld [wCurPartyMon], a
+.loop_check_poison
+ call .DamageMonIfPoisoned
+ jr nc, .not_poisoned
+; the output flag is stored in c, copy it to [wPoisonStepPartyFlags + [wCurPartyMon]]
+; and set the corresponding flag in wPoisonStepFlagSum
+ ld a, [wCurPartyMon]
+ ld e, a
+ ld d, 0
+ ld hl, wPoisonStepPartyFlags
+ add hl, de
+ ld [hl], c
+ ld a, [wPoisonStepFlagSum]
+ or c
+ ld [wPoisonStepFlagSum], a
+
+.not_poisoned
+ ld a, [wPartyCount]
+ ld hl, wCurPartyMon
+ inc [hl]
+ cp [hl]
+ jr nz, .loop_check_poison
+
+ ld a, [wPoisonStepFlagSum]
+ and %10
+ jr nz, .someone_has_fainted
+ ld a, [wPoisonStepFlagSum]
+ and %01
+ jr z, .no_faint
+ call .PlayPoisonSFX
+ xor a
+ ret
+
+.someone_has_fainted
+ ld a, BANK(.Script_MonFaintedToPoison)
+ ld hl, .Script_MonFaintedToPoison
+ call CallScript
+ scf
+ ret
+
+.no_faint
+ xor a
+ ret
+
+.DamageMonIfPoisoned:
+; check if mon is poisoned, return if not
+ ld a, MON_STATUS
+ call GetPartyParamLocation
+ ld a, [hl]
+ and 1 << PSN
+ ret z
+
+; check if mon is already fainted, return if so
+ ld a, MON_HP
+ call GetPartyParamLocation
+ ld a, [hli]
+ ld b, a
+ ld c, [hl]
+ or c
+ ret z
+
+; do 1 HP damage
+ dec bc
+ ld [hl], c
+ dec hl
+ ld [hl], b
+
+; check if mon has fainted as a result of poison damage
+ ld a, b
+ or c
+ jr nz, .not_fainted
+
+; the mon has fainted, reset its status, set carry, and return %10
+ ld a, MON_STATUS
+ call GetPartyParamLocation
+ ld [hl], 0
+ ld c, %10
+ scf
+ ret
+
+.not_fainted
+; set carry and return %01
+ ld c, %01
+ scf
+ ret
+
+.PlayPoisonSFX:
+ ld de, SFX_POISON
+ call PlaySFX
+ ld b, $2
+ predef LoadPoisonBGPals
+ call DelayFrame
+ ret
+
+.Script_MonFaintedToPoison:
+ callasm .PlayPoisonSFX
+ opentext
+ callasm .CheckWhitedOut
+ iffalse .whiteout
+ closetext
+ end
+
+.whiteout
+ farsjump Script_OverworldWhiteout
+
+.CheckWhitedOut:
+ xor a
+ ld [wCurPartyMon], a
+ ld de, wPoisonStepPartyFlags
+.party_loop
+ push de
+ ld a, [de]
+ and %10
+ jr z, .mon_not_fainted
+ ld c, HAPPINESS_POISONFAINT
+ farcall ChangeHappiness
+ farcall GetPartyNick
+ ld hl, .PoisonFaintText
+ call PrintText
+
+.mon_not_fainted
+ pop de
+ inc de
+ ld hl, wCurPartyMon
+ inc [hl]
+ ld a, [wPartyCount]
+ cp [hl]
+ jr nz, .party_loop
+ predef CheckPlayerPartyForFitMon
+ ld a, d
+ ld [wScriptVar], a
+ ret
+
+.PoisonFaintText:
+ text_far _PoisonFaintText
+ text_end
+
+.PoisonWhiteoutText:
+ text_far _PoisonWhiteoutText
+ text_end
diff --git a/main.asm b/main.asm
index 60e75e04..7c8a15b5 100644
--- a/main.asm
+++ b/main.asm
@@ -361,8 +361,9 @@ INCLUDE "engine/pokemon/party_menu.asm"
LoadFishingGFX::
dr $5054f, $50610
-DoPoisonStep::
- dr $50610, $506f2
+
+INCLUDE "engine/events/poisonstep.asm"
+
SweetScentFromMenu::
dr $506f2, $50763
_Squirtbottle::