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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
|
PrintCinnabarQuiz:
ld a, [wSpritePlayerStateData1FacingDirection]
cp SPRITE_FACING_UP
ret nz
call EnableAutoTextBoxDrawing
tx_pre_jump CinnabarGymQuiz
CinnabarGymQuiz::
text_asm
xor a
ld [wOpponentAfterWrongAnswer], a
ld hl, wd475
res 7, [hl]
ld a, [wHiddenObjectFunctionArgument]
push af
and $f
ldh [hGymGateIndex], a
pop af
and $f0
swap a
ldh [hGymGateAnswer], a
ldh a, [hGymGateIndex]
ld hl, CinnabarGymQuizIntroText
cp 1
jr z, .onFirstQuestion
ld hl, CinnabarGymQuizShortIntroText
.onFirstQuestion
call PrintText
ldh a, [hGymGateIndex]
dec a
add a
ld d, 0
ld e, a
ld hl, CinnabarQuizQuestions
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
call PrintText
ld a, 1
ld [wDoNotWaitForButtonPressAfterDisplayingText], a
call CinnabarGymQuiz_1ea92
jp TextScriptEnd
CinnabarGymQuizDummyIntroText:
text_far _CinnabarGymQuizDummyIntroText
text_end
CinnabarGymQuizIntroText:
text_far _CinnabarGymQuizIntroText
text_end
CinnabarGymQuizShortIntroText:
text_far _CinnabarGymQuizShortIntroText
text_end
CinnabarQuizQuestions:
dw CinnabarQuizQuestionsText1
dw CinnabarQuizQuestionsText2
dw CinnabarQuizQuestionsText3
dw CinnabarQuizQuestionsText4
dw CinnabarQuizQuestionsText5
dw CinnabarQuizQuestionsText6
CinnabarQuizQuestionsText1:
text_far _CinnabarQuizQuestionsText1
text_end
CinnabarQuizQuestionsText2:
text_far _CinnabarQuizQuestionsText2
text_end
CinnabarQuizQuestionsText3:
text_far _CinnabarQuizQuestionsText3
text_end
CinnabarQuizQuestionsText4:
text_far _CinnabarQuizQuestionsText4
text_end
CinnabarQuizQuestionsText5:
text_far _CinnabarQuizQuestionsText5
text_end
CinnabarQuizQuestionsText6:
text_far _CinnabarQuizQuestionsText6
text_end
CinnabarGymQuiz_1ea92:
call YesNoChoice
ldh a, [hGymGateAnswer]
ld c, a
ld a, [wCurrentMenuItem]
cp c
jr nz, .wrongAnswer
ld hl, wCurrentMapScriptFlags
set 5, [hl]
ldh a, [hGymGateIndex]
ldh [hBackupGymGateIndex], a
ld hl, CinnabarGymQuizCorrectText
call PrintText
ldh a, [hBackupGymGateIndex]
AdjustEventBit EVENT_CINNABAR_GYM_GATE0_UNLOCKED, 0
ld c, a
ld b, FLAG_SET
call CinnabarGymGateFlagAction
jp UpdateCinnabarGymGateTileBlocks_
.wrongAnswer
call WaitForSoundToFinish
ld a, SFX_DENIED
call PlaySound
call WaitForSoundToFinish
ld hl, CinnabarGymQuizIncorrectText
call PrintText
ldh a, [hGymGateIndex]
add $2
AdjustEventBit EVENT_BEAT_CINNABAR_GYM_TRAINER_0, 2
ld c, a
ld b, FLAG_TEST
EventFlagAddress hl, EVENT_BEAT_CINNABAR_GYM_TRAINER_0
predef FlagActionPredef
ld a, c
and a
ret nz
ldh a, [hGymGateIndex]
add $2
ld [wOpponentAfterWrongAnswer], a
ld hl, wd475
set 7, [hl]
ret
CinnabarGymQuizCorrectText:
sound_get_item_1
text_far _CinnabarGymQuizCorrectText
text_promptbutton
text_asm
ldh a, [hBackupGymGateIndex]
AdjustEventBit EVENT_CINNABAR_GYM_GATE0_UNLOCKED, 0
ld c, a
ld b, FLAG_TEST
call CinnabarGymGateFlagAction
ld a, c
and a
jp nz, TextScriptEnd
call WaitForSoundToFinish
ld a, SFX_GO_INSIDE
call PlaySound
call WaitForSoundToFinish
jp TextScriptEnd
CinnabarGymQuizIncorrectText:
text_far _CinnabarGymQuizIncorrectText
text_end
CinnabarGymGateFlagAction:
EventFlagAddress hl, EVENT_CINNABAR_GYM_GATE0_UNLOCKED
predef_jump FlagActionPredef
UpdateCinnabarGymGateTileBlocks_::
; Update the overworld map with open floor blocks or locked gate blocks
; depending on event flags.
ld a, 6
ldh [hGymGateIndex], a
.loop
ldh a, [hGymGateIndex]
dec a
add a
add a
ld d, 0
ld e, a
ld hl, CinnabarGymGateCoords
add hl, de
ld a, [hli]
ld b, [hl]
ld c, a
inc hl
ld a, [hl]
ld [wGymGateTileBlock], a
push bc
ldh a, [hGymGateIndex]
ldh [hBackupGymGateIndex], a
AdjustEventBit EVENT_CINNABAR_GYM_GATE0_UNLOCKED, 0
ld c, a
ld b, FLAG_TEST
call CinnabarGymGateFlagAction
ld a, c
and a
jr nz, .unlocked
ld a, [wGymGateTileBlock]
jr .next
.unlocked
ld a, $e
.next
pop bc
ld [wNewTileBlockID], a
call CinnabarGym_ReplaceTileBlock
ld hl, hGymGateIndex
dec [hl]
jr nz, .loop
callfar RedrawMapView
ret
gym_gate_coord: MACRO
db \1, \2, \3, 0
ENDM
HORIZONTAL_GATE_BLOCK EQU $54
VERTICAL_GATE_BLOCK EQU $5f
CinnabarGymGateCoords:
; x coord, y coord, block id
gym_gate_coord 9, 3, HORIZONTAL_GATE_BLOCK
gym_gate_coord 6, 3, HORIZONTAL_GATE_BLOCK
gym_gate_coord 6, 6, HORIZONTAL_GATE_BLOCK
gym_gate_coord 3, 8, VERTICAL_GATE_BLOCK
gym_gate_coord 2, 6, HORIZONTAL_GATE_BLOCK
gym_gate_coord 2, 3, HORIZONTAL_GATE_BLOCK
CinnabarGym_ReplaceTileBlock:
; basically a copy of the first half of ReplaceTileBlock
; before checking if it is necessary to redraw the map view
ld hl, wOverworldMap
ld a, [wCurMapWidth]
add $6
ld e, a
ld d, $0
add hl, de
add hl, de
add hl, de
ld e, $3
add hl, de
ld e, a
ld a, b
and a
jr z, .addX
.addWidthYTimesLoop
add hl, de
dec b
jr nz, .addWidthYTimesLoop
.addX
add hl, bc
ld a, [wNewTileBlockID]
ld [hl], a
ret
|