forked from Rangi42/polishedcrystal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnpc_movement.asm
executable file
·457 lines (403 loc) · 5.14 KB
/
npc_movement.asm
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
Function6ec1: ; 6ec1
ld hl, OBJECT_FLAGS1
add hl, bc
bit 4, [hl]
jr nz, .continue
push hl
push bc
ld hl, OBJECT_PALETTE
add hl, bc
bit 5, [hl]
jr z, .not_bit_5
call Function6f2c
jr .resume
.not_bit_5
call Function6f07
.resume
pop bc
pop hl
ret c
.continue
bit 6, [hl]
jr nz, .bit_6
push hl
push bc
call WillPersonBumpIntoSomeoneElse
pop bc
pop hl
ret c
.bit_6
bit 5, [hl]
jr nz, .bit_5
push hl
call HasPersonReachedMovementLimit
pop hl
ret c
push hl
call IsPersonMovingOffEdgeOfScreen
pop hl
ret c
.bit_5
and a
ret
; 6f07
Function6f07: ; 6f07
call Function6f5f
ret c
ld hl, OBJECT_NEXT_MAP_X
add hl, bc
ld d, [hl]
ld hl, OBJECT_NEXT_MAP_Y
add hl, bc
ld e, [hl]
ld hl, OBJECT_PALETTE
add hl, bc
bit 7, [hl]
jp nz, Function6fa1
ld hl, OBJECT_NEXT_TILE
add hl, bc
ld a, [hl]
ld d, a
call GetTileCollision
and a
jr z, Function6f3e
scf
ret
; 6f2c
Function6f2c: ; 6f2c
call Function6f5f
ret c
ld hl, OBJECT_NEXT_TILE
add hl, bc
ld a, [hl]
call GetTileCollision
cp $1
jr z, Function6f3e
scf
ret
; 6f3e
Function6f3e: ; 6f3e
ld hl, OBJECT_NEXT_TILE
add hl, bc
ld a, [hl]
call Function6f7f
ret nc
push af
ld hl, OBJECT_DIRECTION_WALKING
add hl, bc
ld a, [hl]
and 3
ld e, a
ld d, 0
ld hl, .data_6f5b
add hl, de
pop af
and [hl]
ret z
scf
ret
; 6f5b
.data_6f5b
db 1 << DOWN, 1 << UP, 1 << RIGHT, 1 << LEFT
; 6f5f
Function6f5f: ; 6f5f
ld hl, OBJECT_STANDING_TILE
add hl, bc
ld a, [hl]
call Function6f7f
ret nc
push af
ld hl, OBJECT_DIRECTION_WALKING
add hl, bc
and 3
ld e, a
ld d, 0
ld hl, .data_6f7b
add hl, de
pop af
and [hl]
ret z
scf
ret
; 6f7b
.data_6f7b
db 1 << UP, 1 << DOWN, 1 << LEFT, 1 << RIGHT
; 6f7f
Function6f7f: ; 6f7f
ld d, a
and $f0
cp $b0
jr z, .done
cp $c0
jr z, .done
xor a
ret
.done
ld a, d
and 7
ld e, a
ld d, 0
ld hl, .data_6f99
add hl, de
ld a, [hl]
scf
ret
; 6f99
.data_6f99
db 8, 4, 1, 2
db 10, 6, 9, 5
; 6fa1
Function6fa1: ; 6fa1
ld hl, OBJECT_DIRECTION_WALKING
add hl, bc
ld a, [hl]
and 3
jr z, .asm_6fb2
dec a
jr z, .asm_6fb7
dec a
jr z, .asm_6fbb
jr .asm_6fbf
.asm_6fb2
inc e
push de
inc d
jr .asm_6fc2
.asm_6fb7
push de
inc d
jr .asm_6fc2
.asm_6fbb
push de
inc e
jr .asm_6fc2
.asm_6fbf
inc d
push de
inc e
.asm_6fc2
call GetCoordTile
call GetTileCollision
pop de
and a
jr nz, .asm_6fd7
call GetCoordTile
call GetTileCollision
and a
jr nz, .asm_6fd7
xor a
ret
.asm_6fd7
scf
ret
; 6fd9
CheckFacingObject:: ; 6fd9
call GetFacingTileCoord
; Double the distance for counter tiles.
cp COLL_COUNTER
jr nz, .asm_6ff1
ld a, [wPlayerStandingMapX]
sub d
cpl
inc a
add d
ld d, a
ld a, [wPlayerStandingMapY]
sub e
cpl
inc a
add e
ld e, a
.asm_6ff1
xor a
ld [hMapObjectIndexBuffer], a
call IsNPCAtCoord
ret nc
ld hl, OBJECT_DIRECTION_WALKING
add hl, bc
ld a, [hl]
cp STANDING
jr z, .standing
xor a
ret
.standing
scf
ret
; 7009
WillPersonBumpIntoSomeoneElse: ; 7009
ld hl, OBJECT_NEXT_MAP_X
add hl, bc
ld d, [hl]
ld hl, OBJECT_NEXT_MAP_Y
add hl, bc
ld e, [hl]
IsNPCAtCoord: ; 7041
ld bc, wObjectStructs
xor a
.loop
ld [hObjectStructIndexBuffer], a
call DoesObjectHaveASprite
jr z, .next
ld hl, OBJECT_FLAGS1
add hl, bc
bit 7, [hl]
jr nz, .next
ld hl, OBJECT_PALETTE
add hl, bc
bit 7, [hl]
jr z, .got
call Function7171
jr nc, .ok
jr .ok2
.got
ld hl, OBJECT_NEXT_MAP_X
add hl, bc
ld a, [hl]
cp d
jr nz, .ok
ld hl, OBJECT_NEXT_MAP_Y
add hl, bc
ld a, [hl]
cp e
jr nz, .ok
.ok2
ld a, [hMapObjectIndexBuffer]
ld l, a
ld a, [hObjectStructIndexBuffer]
cp l
jr nz, .setcarry
.ok
ld hl, OBJECT_MAP_X
add hl, bc
ld a, [hl]
cp d
jr nz, .next
ld hl, OBJECT_MAP_Y
add hl, bc
ld a, [hl]
cp e
jr nz, .next
ld a, [hMapObjectIndexBuffer]
ld l, a
ld a, [hObjectStructIndexBuffer]
cp l
jr nz, .setcarry
.next
ld hl, OBJECT_STRUCT_LENGTH
add hl, bc
ld b, h
ld c, l
ld a, [hObjectStructIndexBuffer]
inc a
cp NUM_OBJECT_STRUCTS
jr nz, .loop
and a
ret
.setcarry
scf
ret
; 70a4
HasPersonReachedMovementLimit: ; 70a4
ld hl, OBJECT_RADIUS
add hl, bc
ld a, [hl]
and a
jr z, .nope
and $f
jr z, .check_y
ld e, a
ld d, a
ld hl, OBJECT_INIT_X
add hl, bc
ld a, [hl]
sub d
ld d, a
ld a, [hl]
add e
ld e, a
ld hl, OBJECT_NEXT_MAP_X
add hl, bc
ld a, [hl]
cp d
jr z, .yes
cp e
jr z, .yes
.check_y
ld hl, OBJECT_RADIUS
add hl, bc
ld a, [hl]
swap a
and $f
jr z, .nope
ld e, a
ld d, a
ld hl, OBJECT_INIT_Y
add hl, bc
ld a, [hl]
sub d
ld d, a
ld a, [hl]
add e
ld e, a
ld hl, OBJECT_NEXT_MAP_Y
add hl, bc
ld a, [hl]
cp d
jr z, .yes
cp e
jr z, .yes
.nope
xor a
ret
.yes
scf
ret
; 70ed
IsPersonMovingOffEdgeOfScreen: ; 70ed
ld hl, OBJECT_NEXT_MAP_X
add hl, bc
ld a, [wXCoord]
cp [hl]
jr z, .check_y
jr nc, .yes
add $9
cp [hl]
jr c, .yes
.check_y
ld hl, OBJECT_NEXT_MAP_Y
add hl, bc
ld a, [wYCoord]
cp [hl]
jr z, .nope
jr nc, .yes
add $8
cp [hl]
jr c, .yes
.nope
and a
ret
.yes
scf
ret
; 7113
Function7171: ; 7171
ld hl, OBJECT_NEXT_MAP_X
add hl, bc
ld a, d
sub [hl]
jr c, .nope
cp $2
jr nc, .nope
ld hl, OBJECT_NEXT_MAP_Y
add hl, bc
ld a, e
sub [hl]
jr c, .nope
cp $2
jr nc, .nope
scf
ret
.nope
and a
ret
; 718d