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
|
PlayerStepOutFromDoor:
ld hl, wd730
res 1, [hl]
call IsPlayerStandingOnDoorTile
jr nc, .notStandingOnDoor
ld a, $fc
ld [wJoyIgnore], a
ld hl, wd736
set 1, [hl]
ld a, $1
ld [wSimulatedJoypadStatesIndex], a
ld a, D_DOWN
ld [wSimulatedJoypadStatesEnd], a
xor a
ld [wSpriteStateData1 + 2], a
call StartSimulatingJoypadStates
ret
.notStandingOnDoor
xor a
ld [wWastedByteCD3A], a
ld [wSimulatedJoypadStatesIndex], a
ld [wSimulatedJoypadStatesEnd], a
ld hl, wd736
res 0, [hl]
res 1, [hl]
ld hl, wd730
res 7, [hl]
ret
_EndNPCMovementScript:
ld hl, wd730
res 7, [hl]
ld hl, wd72e
res 7, [hl]
ld hl, wd736
res 0, [hl]
res 1, [hl]
xor a
ld [wNPCMovementScriptSpriteOffset], a
ld [wNPCMovementScriptPointerTableNum], a
ld [wNPCMovementScriptFunctionNum], a
ld [wWastedByteCD3A], a
ld [wSimulatedJoypadStatesIndex], a
ld [wSimulatedJoypadStatesEnd], a
ret
PalletMovementScriptPointerTable:
dw PalletMovementScript_OakMoveLeft
dw PalletMovementScript_PlayerMoveLeft
dw PalletMovementScript_WaitAndWalkToLab
dw PalletMovementScript_WalkToLab
dw PalletMovementScript_Done
PalletMovementScript_OakMoveLeft:
ld a, [wXCoord]
sub $a
ld [wNumStepsToTake], a
jr z, .playerOnLeftTile
; The player is on the right tile of the northern path out of Pallet Town and
; Prof. Oak is below.
; Make Prof. Oak step to the left.
ld b, 0
ld c, a
ld hl, wNPCMovementDirections2
ld a, NPC_MOVEMENT_LEFT
call FillMemory
ld [hl], $ff
ld a, [wSpriteIndex]
ld [H_SPRITEINDEX], a
ld de, wNPCMovementDirections2
call MoveSprite
ld a, $1
ld [wNPCMovementScriptFunctionNum], a
jr .done
; The player is on the left tile of the northern path out of Pallet Town and
; Prof. Oak is below.
; Prof. Oak is already where he needs to be.
.playerOnLeftTile
ld a, $3
ld [wNPCMovementScriptFunctionNum], a
.done
ld hl, wFlags_D733
set 1, [hl]
ld a, $fc
ld [wJoyIgnore], a
ret
PalletMovementScript_PlayerMoveLeft:
ld a, [wd730]
bit 0, a ; is an NPC being moved by a script?
ret nz ; return if Oak is still moving
ld a, [wNumStepsToTake]
ld [wSimulatedJoypadStatesIndex], a
ld [hNPCMovementDirections2Index], a
predef ConvertNPCMovementDirectionsToJoypadMasks
call StartSimulatingJoypadStates
ld a, $2
ld [wNPCMovementScriptFunctionNum], a
ret
PalletMovementScript_WaitAndWalkToLab:
ld a, [wSimulatedJoypadStatesIndex]
and a ; is the player done moving left yet?
ret nz
PalletMovementScript_WalkToLab:
xor a
ld [wOverrideSimulatedJoypadStatesMask], a
ld a, [wSpriteIndex]
swap a
ld [wNPCMovementScriptSpriteOffset], a
xor a
ld [wSpriteStateData2 + $06], a
ld hl, wSimulatedJoypadStatesEnd
ld de, RLEList_PlayerWalkToLab
call DecodeRLEList
dec a
ld [wSimulatedJoypadStatesIndex], a
ld hl, wNPCMovementDirections2
ld de, RLEList_ProfOakWalkToLab
call DecodeRLEList
ld hl, wd72e
res 7, [hl]
ld hl, wd730
set 7, [hl]
ld a, $4
ld [wNPCMovementScriptFunctionNum], a
ret
RLEList_ProfOakWalkToLab:
db NPC_MOVEMENT_DOWN, $05
db NPC_MOVEMENT_LEFT, $01
db NPC_MOVEMENT_DOWN, $05
db NPC_MOVEMENT_RIGHT, $03
db NPC_MOVEMENT_UP, $01
db $E0, $01 ; stand still
db $FF
RLEList_PlayerWalkToLab:
db D_UP, $02
db D_RIGHT, $03
db D_DOWN, $05
db D_LEFT, $01
db D_DOWN, $06
db $FF
PalletMovementScript_Done:
ld a, [wSimulatedJoypadStatesIndex]
and a
ret nz
ld a, $0
ld [wMissableObjectIndex], a
predef HideObject
ld hl, wd730
res 7, [hl]
ld hl, wd72e
res 7, [hl]
jp EndNPCMovementScript
PewterMuseumGuyMovementScriptPointerTable:
dw PewterMovementScript_WalkToMuseum
dw PewterMovementScript_Done
PewterMovementScript_WalkToMuseum:
ld a, BANK(Music_MuseumGuy)
ld [wAudioROMBank], a
ld [wAudioSavedROMBank], a
ld a, MUSIC_MUSEUM_GUY
ld [wNewSoundID], a
call PlaySound
ld a, [wSpriteIndex]
swap a
ld [wNPCMovementScriptSpriteOffset], a
call StartSimulatingJoypadStates
ld hl, wSimulatedJoypadStatesEnd
ld de, RLEList_PewterMuseumPlayer
call DecodeRLEList
dec a
ld [wSimulatedJoypadStatesIndex], a
xor a
ld [wWhichPewterGuy], a
predef PewterGuys
ld hl, wNPCMovementDirections2
ld de, RLEList_PewterMuseumGuy
call DecodeRLEList
ld hl, wd72e
res 7, [hl]
ld a, $1
ld [wNPCMovementScriptFunctionNum], a
ret
RLEList_PewterMuseumPlayer:
db 0, $01
db D_UP, $03
db D_LEFT, $0D
db D_UP, $06
db $FF
RLEList_PewterMuseumGuy:
db NPC_MOVEMENT_UP, $06
db NPC_MOVEMENT_LEFT, $0D
db NPC_MOVEMENT_UP, $03
db NPC_MOVEMENT_LEFT, $01
db $FF
PewterMovementScript_Done:
ld a, [wSimulatedJoypadStatesIndex]
and a
ret nz
ld hl, wd730
res 7, [hl]
ld hl, wd72e
res 7, [hl]
jp EndNPCMovementScript
PewterGymGuyMovementScriptPointerTable:
dw PewterMovementScript_WalkToGym
dw PewterMovementScript_Done
PewterMovementScript_WalkToGym:
ld a, BANK(Music_MuseumGuy)
ld [wAudioROMBank], a
ld [wAudioSavedROMBank], a
ld a, MUSIC_MUSEUM_GUY
ld [wNewSoundID], a
call PlaySound
ld a, [wSpriteIndex]
swap a
ld [wNPCMovementScriptSpriteOffset], a
xor a
ld [wSpriteStateData2 + $06], a
ld hl, wSimulatedJoypadStatesEnd
ld de, RLEList_PewterGymPlayer
call DecodeRLEList
dec a
ld [wSimulatedJoypadStatesIndex], a
ld a, 1
ld [wWhichPewterGuy], a
predef PewterGuys
ld hl, wNPCMovementDirections2
ld de, RLEList_PewterGymGuy
call DecodeRLEList
ld hl, wd72e
res 7, [hl]
ld hl, wd730
set 7, [hl]
ld a, $1
ld [wNPCMovementScriptFunctionNum], a
ret
RLEList_PewterGymPlayer:
db 0, $01
db D_RIGHT, $02
db D_DOWN, $05
db D_LEFT, $0B
db D_UP, $05
db D_LEFT, $0F
db $FF
RLEList_PewterGymGuy:
db NPC_MOVEMENT_DOWN, $02
db NPC_MOVEMENT_LEFT, $0F
db NPC_MOVEMENT_UP, $05
db NPC_MOVEMENT_LEFT, $0B
db NPC_MOVEMENT_DOWN, $05
db NPC_MOVEMENT_RIGHT, $03
db $FF
FreezeEnemyTrainerSprite:
ld a, [wCurMap]
cp POKEMONTOWER_7
ret z ; the Rockets on Pokemon Tower 7F leave after battling, so don't freeze them
ld hl, RivalIDs
ld a, [wEngagedTrainerClass]
ld b, a
.loop
ld a, [hli]
cp $ff
jr z, .notRival
cp b
ret z ; the rival leaves after battling, so don't freeze him
jr .loop
.notRival
ld a, [wSpriteIndex]
ld [H_SPRITEINDEX], a
jp SetSpriteMovementBytesToFF
RivalIDs:
db OPP_SONY1
db OPP_SONY2
db OPP_SONY3
db $ff
|