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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
|
CheckForMobileBattleRules:
ld de, .PointerTables
call BattleTower_ExecuteJumptable
ret z
call BattleTower_PleaseReturnWhenReady
scf
ret
.PointerTables:
db 2
dw .Functions
dw .TextPointers
.Functions:
dw BattleTower_CheckPartyLengthIs3
dw BattleTower_CheckPartyHasThreeMonsThatAreNotEggs
.TextPointers:
dw .BTExcuseMeText
dw NeedAtLeastThreeMonText
dw EggDoesNotQualifyText
.BTExcuseMeText:
text_far _BTExcuseMeText
text_end
_CheckForBattleTowerRules:
ld hl, wStringBuffer2
ld [hl], "3"
inc hl
ld [hl], "@"
ld de, .PointerTables
call BattleTower_ExecuteJumptable
ret z
call BattleTower_PleaseReturnWhenReady
scf
ret
.PointerTables:
db 4
dw .Functions
dw .TextPointers
.Functions:
dw CheckBTRule_PartyCountEq3
dw CheckBTRule_PartySpeciesAreUnique
dw CheckBTRule_PartyItemsAreUnique
dw CheckBTRule_HasPartyAnEgg
.TextPointers:
dw ExcuseMeYoureNotReadyText
dw OnlyThreeMonMayBeEnteredText
dw TheMonMustAllBeDifferentKindsText
dw TheMonMustNotHoldTheSameItemsText
dw YouCantTakeAnEggText
ExcuseMeYoureNotReadyText:
text_far _ExcuseMeYoureNotReadyText
text_end
BattleTower_PleaseReturnWhenReady:
ld hl, .BattleTowerReturnWhenReadyText
call PrintText
ret
.BattleTowerReturnWhenReadyText:
text_far _BattleTowerReturnWhenReadyText
text_end
NeedAtLeastThreeMonText:
text_far _NeedAtLeastThreeMonText
text_end
EggDoesNotQualifyText:
text_far _EggDoesNotQualifyText
text_end
OnlyThreeMonMayBeEnteredText:
text_far _OnlyThreeMonMayBeEnteredText
text_end
TheMonMustAllBeDifferentKindsText:
text_far _TheMonMustAllBeDifferentKindsText
text_end
TheMonMustNotHoldTheSameItemsText:
text_far _TheMonMustNotHoldTheSameItemsText
text_end
YouCantTakeAnEggText:
text_far _YouCantTakeAnEggText
text_end
BattleTower_ExecuteJumptable:
ld bc, 0
.loop
call .DoJumptableFunction
call c, .PrintFailureText
call .Next_CheckReachedEnd
jr nz, .loop
ld a, b
and a
ret
.DoJumptableFunction:
push de
push bc
call .GetFunctionPointer
ld a, c
rst JumpTable
pop bc
pop de
ret
.Next_CheckReachedEnd:
inc c
ld a, [de]
cp c
ret
.GetFunctionPointer:
inc de
ld a, [de]
ld l, a
inc de
ld a, [de]
ld h, a
ret
.GetTextPointers:
inc de
inc de
inc de
ld a, [de]
ld l, a
inc de
ld a, [de]
ld h, a
ret
.LoadTextPointer:
ld a, [hli]
ld h, [hl]
ld l, a
ret
.PrintFailureText:
push de
push bc
ld a, b
and a
call z, .PrintFirstText
pop bc
call .PrintNthText
ld b, 1
pop de
ret
.PrintFirstText:
push de
call .GetTextPointers
call .LoadTextPointer
call PrintText
pop de
ret
.PrintNthText:
push bc
call .GetTextPointers
inc hl
inc hl
ld b, 0
add hl, bc
add hl, bc
call .LoadTextPointer
call PrintText
pop bc
ret
BattleTower_CheckPartyLengthIs3:
ld a, [wPartyCount]
cp BATTLETOWER_PARTY_LENGTH
ret
BattleTower_CheckPartyHasThreeMonsThatAreNotEggs:
ld hl, wPartyCount
ld a, [hli]
ld b, 0
ld c, a
.loop
ld a, [hli]
cp EGG
jr z, .egg
inc b
.egg
dec c
jr nz, .loop
ld a, [wPartyCount]
cp b
ret z
ld a, b
cp BATTLETOWER_PARTY_LENGTH
ret
CheckBTRule_PartyCountEq3:
ld a, [wPartyCount]
cp BATTLETOWER_PARTY_LENGTH
ret z
scf
ret
CheckBTRule_PartySpeciesAreUnique:
ld hl, wPartyMon1Species
call CheckPartyValueIsUnique
ret
CheckPartyValueIsUnique:
ld de, wPartyCount
ld a, [de]
inc de
dec a
jr z, .done
ld b, a
.loop
push hl
push de
ld c, b
call .isegg
jr z, .next
ld a, [hl]
and a
jr z, .next
.loop2
call .nextmon
call .isegg
jr z, .next2
cp [hl]
jr z, .gotcha
.next2
dec c
jr nz, .loop2
.next
pop de
pop hl
call .nextmon
dec b
jr nz, .loop
.done
and a
ret
.gotcha
pop de
pop hl
scf
ret
.nextmon
push bc
ld bc, PARTYMON_STRUCT_LENGTH
add hl, bc
inc de
pop bc
ret
.isegg
push bc
ld b, a
ld a, [de]
cp EGG
ld a, b
pop bc
ret
CheckBTRule_PartyItemsAreUnique:
ld hl, wPartyMon1Item
call CheckPartyValueIsUnique
ret
CheckBTRule_HasPartyAnEgg:
ld hl, wPartyCount
ld a, [hli]
ld c, a
.loop
ld a, [hli]
cp EGG
jr z, .found
dec c
jr nz, .loop
and a
ret
.found
scf
ret
|