Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pret
GitHub Repository: pret/pokered
Path: blob/master/engine/events/in_game_trades.asm
1271 views
1
; TradeTextPointers1-3 indexes
2
const_def
3
const TRADETEXT_WANNA_TRADE ; 0
4
const TRADETEXT_NO_TRADE ; 1
5
const TRADETEXT_WRONG_MON ; 2
6
const TRADETEXT_THANKS ; 3
7
const TRADETEXT_AFTER_TRADE ; 4
8
DEF NUM_TRADE_TEXTS EQU const_value
9
10
DoInGameTradeDialogue:
11
; trigger the trade offer/action specified by wWhichTrade
12
call SaveScreenTilesToBuffer2
13
ld hl, TradeMons
14
ld a, [wWhichTrade]
15
ld b, a
16
swap a
17
sub b
18
sub b
19
ld c, a
20
ld b, 0
21
add hl, bc
22
ld a, [hli]
23
ld [wInGameTradeGiveMonSpecies], a
24
ld a, [hli]
25
ld [wInGameTradeReceiveMonSpecies], a
26
ld a, [hli]
27
push af
28
ld de, wInGameTradeMonNick
29
ld bc, NAME_LENGTH
30
call CopyData
31
pop af
32
ld l, a
33
ld h, 0
34
ld de, InGameTradeTextPointers
35
add hl, hl
36
add hl, de
37
ld a, [hli]
38
ld [wInGameTradeTextPointerTablePointer], a
39
ld a, [hl]
40
ld [wInGameTradeTextPointerTablePointer + 1], a
41
ld a, [wInGameTradeGiveMonSpecies]
42
ld de, wInGameTradeGiveMonName
43
call InGameTrade_GetMonName
44
ld a, [wInGameTradeReceiveMonSpecies]
45
ld de, wInGameTradeReceiveMonName
46
call InGameTrade_GetMonName
47
ld hl, wCompletedInGameTradeFlags
48
ld a, [wWhichTrade]
49
ld c, a
50
ld b, FLAG_TEST
51
predef FlagActionPredef
52
ld a, c
53
and a
54
ld a, TRADETEXT_AFTER_TRADE
55
ld [wInGameTradeTextPointerTableIndex], a
56
jr nz, .printText
57
; if the trade hasn't been done yet
58
ASSERT TRADETEXT_WANNA_TRADE == 0
59
xor a
60
ld [wInGameTradeTextPointerTableIndex], a
61
call .printText
62
ld a, TRADETEXT_NO_TRADE
63
ld [wInGameTradeTextPointerTableIndex], a
64
call YesNoChoice
65
ld a, [wCurrentMenuItem]
66
and a
67
jr nz, .printText
68
call InGameTrade_DoTrade
69
jr c, .printText
70
ld hl, TradedForText
71
call PrintText
72
.printText
73
ld hl, wInGameTradeTextPointerTableIndex
74
ld a, [hld] ; wInGameTradeTextPointerTableIndex
75
ld e, a
76
ld d, 0
77
ld a, [hld] ; wInGameTradeTextPointerTablePointer + 1
78
ld l, [hl] ; wInGameTradeTextPointerTablePointer
79
ld h, a
80
add hl, de
81
add hl, de
82
ld a, [hli]
83
ld h, [hl]
84
ld l, a
85
jp PrintText
86
87
; copies name of species a to hl
88
InGameTrade_GetMonName:
89
push de
90
ld [wNamedObjectIndex], a
91
call GetMonName
92
ld hl, wNameBuffer
93
pop de
94
ld bc, NAME_LENGTH
95
jp CopyData
96
97
INCLUDE "data/events/trades.asm"
98
99
InGameTrade_DoTrade:
100
xor a ; NORMAL_PARTY_MENU
101
ld [wPartyMenuTypeOrMessageID], a
102
dec a
103
ld [wUpdateSpritesEnabled], a
104
call DisplayPartyMenu
105
push af
106
call InGameTrade_RestoreScreen
107
pop af
108
ld a, TRADETEXT_NO_TRADE
109
jp c, .tradeFailed ; jump if the player didn't select a pokemon
110
ld a, [wInGameTradeGiveMonSpecies]
111
ld b, a
112
ld a, [wCurPartySpecies]
113
cp b
114
ld a, TRADETEXT_WRONG_MON
115
jr nz, .tradeFailed ; jump if the selected mon's species is not the required one
116
ld a, [wWhichPokemon]
117
ld hl, wPartyMon1Level
118
ld bc, wPartyMon2 - wPartyMon1
119
call AddNTimes
120
ld a, [hl]
121
ld [wCurEnemyLevel], a
122
ld hl, wCompletedInGameTradeFlags
123
ld a, [wWhichTrade]
124
ld c, a
125
ld b, FLAG_SET
126
predef FlagActionPredef
127
ld hl, ConnectCableText
128
call PrintText
129
ld a, [wWhichPokemon]
130
push af
131
ld a, [wCurEnemyLevel]
132
push af
133
call LoadHpBarAndStatusTilePatterns
134
call InGameTrade_PrepareTradeData
135
predef InternalClockTradeAnim
136
pop af
137
ld [wCurEnemyLevel], a
138
pop af
139
ld [wWhichPokemon], a
140
ld a, [wInGameTradeReceiveMonSpecies]
141
ld [wCurPartySpecies], a
142
xor a
143
ld [wMonDataLocation], a ; not used
144
ld [wRemoveMonFromBox], a
145
call RemovePokemon
146
ld a, $80 ; prevent the player from naming the mon
147
ld [wMonDataLocation], a
148
call AddPartyMon
149
call InGameTrade_CopyDataToReceivedMon
150
callfar InGameTrade_CheckForTradeEvo
151
call ClearScreen
152
call InGameTrade_RestoreScreen
153
farcall RedrawMapView
154
and a
155
ld a, TRADETEXT_THANKS
156
jr .tradeSucceeded
157
.tradeFailed
158
scf
159
.tradeSucceeded
160
ld [wInGameTradeTextPointerTableIndex], a
161
ret
162
163
InGameTrade_RestoreScreen:
164
call GBPalWhiteOutWithDelay3
165
call RestoreScreenTilesAndReloadTilePatterns
166
call ReloadTilesetTilePatterns
167
call LoadScreenTilesFromBuffer2
168
call Delay3
169
call LoadGBPal
170
ld c, 10
171
call DelayFrames
172
farjp LoadWildData
173
174
InGameTrade_PrepareTradeData:
175
ld hl, wTradedPlayerMonSpecies
176
ld a, [wInGameTradeGiveMonSpecies]
177
ld [hli], a ; wTradedPlayerMonSpecies
178
ld a, [wInGameTradeReceiveMonSpecies]
179
ld [hl], a ; wTradedEnemyMonSpecies
180
ld hl, wPartyMonOT
181
ld bc, NAME_LENGTH
182
ld a, [wWhichPokemon]
183
call AddNTimes
184
ld de, wTradedPlayerMonOT
185
ld bc, NAME_LENGTH
186
call InGameTrade_CopyData
187
ld hl, InGameTrade_TrainerString
188
ld de, wTradedEnemyMonOT
189
call InGameTrade_CopyData
190
ld de, wLinkEnemyTrainerName
191
call InGameTrade_CopyData
192
ld hl, wPartyMon1OTID
193
ld bc, wPartyMon2 - wPartyMon1
194
ld a, [wWhichPokemon]
195
call AddNTimes
196
ld de, wTradedPlayerMonOTID
197
ld bc, $2
198
call InGameTrade_CopyData
199
call Random
200
ld hl, hRandomAdd
201
ld de, wTradedEnemyMonOTID
202
jp CopyData
203
204
InGameTrade_CopyData:
205
push hl
206
push bc
207
call CopyData
208
pop bc
209
pop hl
210
ret
211
212
InGameTrade_CopyDataToReceivedMon:
213
ld hl, wPartyMonNicks
214
ld bc, NAME_LENGTH
215
call InGameTrade_GetReceivedMonPointer
216
ld hl, wInGameTradeMonNick
217
ld bc, NAME_LENGTH
218
call CopyData
219
ld hl, wPartyMonOT
220
ld bc, NAME_LENGTH
221
call InGameTrade_GetReceivedMonPointer
222
ld hl, InGameTrade_TrainerString
223
ld bc, NAME_LENGTH
224
call CopyData
225
ld hl, wPartyMon1OTID
226
ld bc, wPartyMon2 - wPartyMon1
227
call InGameTrade_GetReceivedMonPointer
228
ld hl, wTradedEnemyMonOTID
229
ld bc, $2
230
jp CopyData
231
232
; the received mon's index is (partyCount - 1),
233
; so this adds bc to hl (partyCount - 1) times and moves the result to de
234
InGameTrade_GetReceivedMonPointer:
235
ld a, [wPartyCount]
236
dec a
237
call AddNTimes
238
ld e, l
239
ld d, h
240
ret
241
242
InGameTrade_TrainerString:
243
dname "<TRAINER>", NAME_LENGTH
244
245
InGameTradeTextPointers:
246
; entries correspond to TRADE_DIALOGSET_* constants
247
table_width 2
248
dw TradeTextPointers1
249
dw TradeTextPointers2
250
dw TradeTextPointers3
251
assert_table_length NUM_TRADE_DIALOGSETS
252
253
TradeTextPointers1:
254
table_width 2
255
dw WannaTrade1Text
256
dw NoTrade1Text
257
dw WrongMon1Text
258
dw Thanks1Text
259
dw AfterTrade1Text
260
assert_table_length NUM_TRADE_TEXTS
261
262
TradeTextPointers2:
263
table_width 2
264
dw WannaTrade2Text
265
dw NoTrade2Text
266
dw WrongMon2Text
267
dw Thanks2Text
268
dw AfterTrade2Text
269
assert_table_length NUM_TRADE_TEXTS
270
271
TradeTextPointers3:
272
table_width 2
273
dw WannaTrade3Text
274
dw NoTrade3Text
275
dw WrongMon3Text
276
dw Thanks3Text
277
dw AfterTrade3Text
278
assert_table_length NUM_TRADE_TEXTS
279
280
ConnectCableText:
281
text_far _ConnectCableText
282
text_end
283
284
TradedForText:
285
text_far _TradedForText
286
sound_get_key_item
287
text_pause
288
text_end
289
290
WannaTrade1Text:
291
text_far _WannaTrade1Text
292
text_end
293
294
NoTrade1Text:
295
text_far _NoTrade1Text
296
text_end
297
298
WrongMon1Text:
299
text_far _WrongMon1Text
300
text_end
301
302
Thanks1Text:
303
text_far _Thanks1Text
304
text_end
305
306
AfterTrade1Text:
307
text_far _AfterTrade1Text
308
text_end
309
310
WannaTrade2Text:
311
text_far _WannaTrade2Text
312
text_end
313
314
NoTrade2Text:
315
text_far _NoTrade2Text
316
text_end
317
318
WrongMon2Text:
319
text_far _WrongMon2Text
320
text_end
321
322
Thanks2Text:
323
text_far _Thanks2Text
324
text_end
325
326
AfterTrade2Text:
327
text_far _AfterTrade2Text
328
text_end
329
330
WannaTrade3Text:
331
text_far _WannaTrade3Text
332
text_end
333
334
NoTrade3Text:
335
text_far _NoTrade3Text
336
text_end
337
338
WrongMon3Text:
339
text_far _WrongMon3Text
340
text_end
341
342
Thanks3Text:
343
text_far _Thanks3Text
344
text_end
345
346
AfterTrade3Text:
347
text_far _AfterTrade3Text
348
text_end
349
350