summaryrefslogtreecommitdiff
path: root/engine/events/poisonstep.asm
blob: 00c7477bce1c59719125a9e41e50599427d00811 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
DoPoisonStep:: ; 505da
	ld a, [PartyCount]
	and a
	jr z, .no_faint

	xor a
	ld c, 7
	ld hl, EngineBuffer1
.loop_clearEngineBuffer1
	ld [hli], a
	dec c
	jr nz, .loop_clearEngineBuffer1

	xor a
	ld [CurPartyMon], a
.loop_check_poison
	call .DamageMonIfPoisoned
	jr nc, .not_poisoned
; the output flag is stored in c, copy it to the ([CurPartyMon] + 2)nd EngineBuffer
; and set the corresponding flag in EngineBuffer1
	ld a, [CurPartyMon]
	ld e, a
	ld d, 0
	ld hl, EngineBuffer2
	add hl, de
	ld [hl], c
	ld a, [EngineBuffer1]
	or c
	ld [EngineBuffer1], a

.not_poisoned
	ld a, [PartyCount]
	ld hl, CurPartyMon
	inc [hl]
	cp [hl]
	jr nz, .loop_check_poison

	ld a, [EngineBuffer1]
	and %10
	jr nz, .someone_has_fainted
	ld a, [EngineBuffer1]
	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
; 5062e

.DamageMonIfPoisoned: ; 5062e
; 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
; 50658

.PlayPoisonSFX: ; 50658
	ld de, SFX_POISON
	call PlaySFX
	ld b, $2
	predef LoadPoisonBGPals
	call DelayFrame
	ret
; 50669

.Script_MonFaintedToPoison: ; 50669
	callasm .PlayPoisonSFX
	opentext
	callasm .CheckWhitedOut
	iffalse .whiteout
	closetext
	end
; 50677

.whiteout ; 50677
	farjump Script_OverworldWhiteout
; 5067b

.CheckWhitedOut: ; 5067b
	xor a
	ld [CurPartyMon], a
	ld de, EngineBuffer2
.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, CurPartyMon
	inc [hl]
	ld a, [PartyCount]
	cp [hl]
	jr nz, .party_loop
	predef CheckPlayerPartyForFitPkmn
	ld a, d
	ld [ScriptVar], a
	ret
; 506b2

.PoisonFaintText: ; 506b2
	text_jump UnknownText_0x1c0acc
	db "@"
; 506b7

.PoisonWhiteOutText: ; 506b7
	text_jump UnknownText_0x1c0ada
	db "@"
; 506bc