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
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
|
#include "beanstalkSubtask.h"
#include "backgroundAnimations.h"
#include "collision.h"
#include "common.h"
#include "fade.h"
#include "game.h"
#include "item.h"
#include "main.h"
#include "manager.h"
#include "manager/diggingCaveEntranceManager.h"
#include "menu.h"
#include "object.h"
#include "asm.h"
#include "flags.h"
#include "room.h"
#include "player.h"
#include "screen.h"
#include "scroll.h"
#include "tiles.h"
#include "affine.h"
#include "subtask.h"
#include "ui.h"
extern void sub_0807C898(void);
extern void sub_0805BB74(s32);
extern void LoadRoomGfx(void);
extern void LoadRoomTileSet(void);
extern void sub_0807C4F8(void);
extern void gMapData;
extern u8 gUpdateVisibleTiles;
extern u16 gMapDataTopSpecial[];
extern u16 gMapDataBottomSpecial[];
extern const u8 gGlobalGfxAndPalettes[];
extern const u8 gEntityListLUT[];
typedef struct {
u16 tileType;
u16 kind;
u16 id;
u16 type;
u16 type2;
u16 unk_a;
} Data;
extern const u16 gUnk_080B4410[]; // TODO figure out structure
extern void (*const gUnk_080B4458[])(void);
extern const s16 gUnk_080B4468[]; // TODO struct xy
extern const s16 gUnk_080B4478[]; // TODO struct xy
extern const s16 gUnk_080B4488[];
extern const s16 gUnk_080B4490[]; // TODO struct xy
extern const u16 gUnk_080B44A0[];
extern const s16 gUnk_080B44A8[]; // TODO struct xy
extern const u32 gUnk_080B44B8[]; // TODO actually function pointers?
extern const Data gUnk_080B44C0[];
extern const Data gUnk_080B44C2[];
void sub_0801AD6C(const Data*, u32);
bool32 sub_0801A4F8(void);
bool32 sub_0801AA58(Entity*, u32, u32);
void RenderMapLayerToSubTileMap(u16* subTileMap, MapLayer* mapLayer);
u32 GetTileSetIndexForSpecialTile(u32 position, u32 tileIndex);
extern u32 sub_0807BDB8(Entity* this, u32 param_2);
extern void sub_0804B388(u32 a1, u32 a2);
extern u32 sub_080A7CFC(u32 a1, u32 tmp); // TODO does this really have a second param?
extern void OpenSmallChest(u32 pos, u32 layer);
extern bool32 sub_08079778();
extern Transition* FindApplicableAreaTransition(u32, u32);
extern const s16 gUnk_080B4490[];
extern const s16 gUnk_080B4468[];
extern const s16 gUnk_080B4478[];
bool32 sub_0801A2B0(MapLayer* mapLayer, u32 position, u32 collisionType);
bool32 sub_0801A9F0(u32 param_1, u32 param_2, u32 param_3);
u32 sub_0801A570(Entity*, u32);
bool32 sub_0801A458(MapLayer* mapLayer, u32 position, u32 collisionType);
bool32 sub_0801A370(MapLayer* mapLayer, u32 position);
u32 sub_0801A8D0(Entity* this, u32 param_2);
void sub_0801967C(void) {
gUnk_080B4458[gMenu.overlayType]();
}
void sub_08019698(void) {
Entity* object;
const u16* ptr;
ptr = &gUnk_080B4410[gUI.field_0x3 * 7];
SetLocalFlagByBank(FLAG_BANK_1, ptr[2]);
LoadAuxiliaryRoom(ptr[0], ptr[1]);
gRoomControls.scroll_x += ptr[3];
gRoomControls.scroll_y += ptr[4];
gUpdateVisibleTiles = 1;
UpdateScrollVram();
gScreen.lcd.displayControl &= 0xfeff;
object = CreateObject(BEANSTALK, 0, 0);
if (object != NULL) {
object->x.HALF.HI = gRoomControls.scroll_x + ptr[5];
object->y.HALF.HI = gRoomControls.scroll_y + ptr[6];
}
LoadGfxGroup(0x11);
FlushSprites();
DrawEntities();
CopyOAM();
SetFade(FADE_INSTANT, 8);
gUnk_02018EB0.unk_0++;
}
void sub_08019740(void) {
if (gFadeControl.active == 0) {
gUnk_02018EB0.unk_0++;
gUnk_02018EB0.unk_4 = 0x186;
}
}
void sub_08019764(void) {
FlushSprites();
UpdateEntities();
DrawEntities();
CopyOAM();
if ((--gUnk_02018EB0.unk_4 == 0) || ((gInput.newKeys & (B_BUTTON | START_BUTTON)) != 0)) {
gUnk_02018EB0.unk_0++;
}
}
void sub_080197A0(void) {
MenuFadeIn(2, 0xb);
}
void SetBGDefaults(void) {
gMapBottom.bgSettings = (BgSettings*)&gScreen.bg2;
gMapBottom.bgSettings->control = gUnk_080B77C0[0];
gMapTop.bgSettings = &gScreen.bg1;
gMapTop.bgSettings->control = gUnk_080B77C0[1];
}
void LoadMapData(MapDataDefinition* dataDefinition) {
u32 uVar1;
u8* src;
void* dest;
do {
dest = dataDefinition->dest;
if (dest != NULL) {
src = &gMapData + (dataDefinition->src & 0x7fffffff);
if ((dataDefinition->size & MAP_COMPRESSED) != 0) {
if ((u32)dest >> 0x18 == 6) {
LZ77UnCompVram(src, dest);
} else {
LZ77UnCompWram(src, dest);
}
} else {
MemCopy(src, dest, dataDefinition->size);
}
} else {
LoadPaletteGroup(*(u16*)dataDefinition);
sub_080533CC();
}
dataDefinition++;
} while (((dataDefinition - 1)->src & MAP_MULTIPLE) != 0);
}
// Has ifdefs for other variants
u32 UpdatePlayerCollision(void) {
u32 direction;
u32 tileType;
MapLayer* mapLayer;
Transition* transition;
Entity* pushedBlock;
Entity* player;
u32 position;
u32 index;
const s16* ptr1;
const s16* ptr2;
s32 framestate;
u32 tmp2;
u32 tmp3;
// There are some weird assignment necessary to access gPlayerEntity.base.animationState correctly.
u32 animationState1;
u32 animationState2;
u32 animationState3;
if (gPlayerState.framestate == PL_STATE_IDLE) {
framestate = gPlayerState.framestate_last;
} else {
framestate = gPlayerState.framestate;
}
switch (framestate) {
case PL_STATE_GUSTJAR:
return 0;
case PL_STATE_DIE:
return 0;
case PL_STATE_DROWN:
return 0;
}
if (gPlayerState.dash_state != 0 || gPlayerEntity.base.action == PLAYER_CLIMB) {
direction = gPlayerEntity.base.direction;
} else {
direction = gPlayerState.direction;
}
if (((direction & (DIR_NOT_MOVING_CHECK | 0x3)) == 0) && (gPlayerState.field_0xa == 0)) {
index = sub_0807BDB8(&gPlayerEntity.base, direction >> 2);
if (index != 0xff && (gRoomControls.scroll_flags & 4) == 0) {
ptr1 = &gUnk_080B4490[index * 2];
if (GetCollisionDataAtTilePos(COORD_TO_TILE_OFFSET(&gPlayerEntity.base, -ptr1[0], -ptr1[1]),
gPlayerEntity.base.collisionLayer) == COLLISION_DATA_255) {
if ((((gPlayerState.flags & (PL_FLAGS10000 | PL_FLAGS2)) != 0) ||
((gPlayerState.sword_state & 0x10) != 0)) ||
((DoApplicableTransition(gPlayerEntity.base.x.HALF.HI - gRoomControls.origin_x,
gPlayerEntity.base.y.HALF.HI - gRoomControls.origin_y, index, 5) == 0 &&
(((gPlayerState.heldObject != 0 || ((gPlayerState.gustJarState & 0xf) != 0)) ||
(sub_0807BD14(&gPlayerEntity.base, index) == 0)))))) {
return 3;
}
gPlayerEntity.base.direction = (index << 3);
return 0xf;
}
}
}
mapLayer = GetLayerByIndex(gPlayerEntity.base.collisionLayer);
ptr1 = &gUnk_080B4468[gPlayerEntity.base.animationState & 6];
position = COORD_TO_TILE_OFFSET(&gPlayerEntity.base, -ptr1[0], -ptr1[1]);
tileType = GetTileTypeAtTilePos(position, gPlayerEntity.base.collisionLayer);
if (tileType < 0x4000) {
direction = GetActTileForTileType(tileType);
} else {
direction = tileType;
}
animationState1 = gPlayerEntity.base.animationState;
animationState2 = animationState1 & 0xff;
switch (direction) {
case SPECIAL_TILE_0:
if (sub_0801A458(mapLayer, position, 2) == 0) {
return 0;
}
mapLayer->mapData[position] = 0x4001 + (gPlayerEntity.base.animationState >> 1);
if ((gPlayerState.flags & PL_MINISH) != 0) {
gPlayerState.pushedObject = 0xc0;
} else {
gPlayerState.pushedObject = 0xa0;
}
gPlayerState.queued_action = PLAYER_PUSH;
gPlayerState.flags |= PL_BUSY;
gPlayerEntity.base.x.HALF.LO = 0;
gPlayerEntity.base.y.HALF.LO = 0;
gPlayerEntity.base.direction = Direction8FromAnimationState(gPlayerEntity.base.animationState);
return 1;
case ACT_TILE_40:
if ((gPlayerState.flags & PL_MINISH) != 0) {
return 0;
}
gPlayerEntity.base.action = gPlayerEntity.base.action;
if (gPlayerState.field_0xa != 0) {
return 0;
}
if ((Direction8FromAnimationState(gPlayerEntity.base.animationState)) - gPlayerState.direction !=
DirectionNorth) {
return 0;
}
if ((gPlayerEntity.base.direction & DIR_NOT_MOVING_CHECK) != 0) {
return 0;
}
if (GetCollisionDataAtTilePos(position, gPlayerEntity.base.collisionLayer) != COLLISION_DATA_15) {
return 0;
}
if (sub_08079778() == 0) {
return 0;
}
ptr1 = &gUnk_080B4478[gPlayerEntity.base.animationState & 6];
transition =
FindApplicableAreaTransition((gPlayerEntity.base.x.HALF.HI - gRoomControls.origin_x) + ptr1[0],
(gPlayerEntity.base.y.HALF.HI - gRoomControls.origin_y) + ptr1[1]);
if (transition == NULL) {
return 0;
}
if ((gPlayerEntity.base.animationState & 2) != 0) {
gPlayerEntity.base.y.HALF.HI = gRoomControls.origin_y + transition->startY + 6;
} else {
gPlayerEntity.base.x.HALF.HI = gRoomControls.origin_x + transition->startX;
}
sub_08078AC0(4, 0, 1);
return 0;
case SPECIAL_TILE_27:
if (sub_0801A2B0(mapLayer, position, 0xb) == 0) {
return 0;
}
// Start moving the boulder.
mapLayer->mapData[position] = SPECIAL_TILE_28 + (gPlayerEntity.base.animationState / 2);
gPlayerState.pushedObject = 0xa0;
gPlayerState.queued_action = PLAYER_PUSH;
gPlayerState.flags |= PL_BUSY;
gPlayerEntity.base.x.HALF.LO = 0;
gPlayerEntity.base.y.HALF.LO = 0;
gPlayerEntity.base.direction = Direction8FromAnimationState(gPlayerEntity.base.animationState);
gPlayerEntity.base.type = 1;
return 1;
case ACT_TILE_112:
if ((gPlayerState.field_0x35 & 0x80) == 0) {
if ((gPlayerEntity.base.frame & 1) != 0) {
if (sub_0801A9F0(gPlayerState.field_0x35 << 2, tileType, position) != 0) {
return 1;
}
}
}
return 0;
case ACT_TILE_58:
case ACT_TILE_91:
case SPECIAL_TILE_81:
if (gPlayerState.flags & PL_MINISH) {
return 0;
}
if (gPlayerEntity.base.animationState != IdleNorth) {
return 0;
}
gHUD.rActionInteractTile = R_ACTION_READ;
if ((gPlayerState.playerInput.newInput & (INPUT_ACTION | INPUT_40)) == 0) {
return 0;
}
gPlayerState.mobility = 1;
sub_080A7CFC(position, gPlayerEntity.base.collisionLayer);
return 1;
case ACT_TILE_26:
if ((animationState1 & 0xff) != 0) {
return 0;
}
if ((gPlayerState.flags & (PL_DRUGGED | PL_MINISH)) != 0) {
return 0;
}
gHUD.rActionInteractTile = R_ACTION_OPEN;
if ((gPlayerState.playerInput.newInput & (INPUT_ACTION | INPUT_INTERACT)) == 0) {
return 0;
}
gPlayerState.mobility = 1;
OpenSmallChest(position, gPlayerEntity.base.collisionLayer);
return 2;
case ACT_TILE_113:
if (HasDungeonSmallKey() == 0) {
return 0;
}
gHUD.rActionInteractTile = R_ACTION_OPEN;
if ((gPlayerState.playerInput.newInput & (INPUT_ACTION | INPUT_INTERACT)) == 0) {
return 0;
}
gPlayerState.mobility = 1;
sub_0804B388(position, gPlayerEntity.base.collisionLayer);
return 2;
case ACT_TILE_61:
case SPECIAL_TILE_64 ... SPECIAL_TILE_72:
if ((gPlayerState.flags & PL_DRUGGED) != 0) {
return 0;
}
if (sub_08079778() == 0) {
return 0;
}
#if !(defined(EU) || defined(JP))
if (gPlayerState.field_0xa != 0) {
return 0;
}
#endif
if ((Direction8FromAnimationState(gPlayerEntity.base.animationState)) - gPlayerState.direction !=
DirectionNorth) {
return 0;
}
if ((gPlayerEntity.base.direction & 0x80) != 0) {
return 0;
}
if (gPlayerEntity.base.subtimer < 6) {
return 0;
}
gPlayerState.jump_status = 0x81;
gPlayerState.flags |= PL_USE_PORTAL;
gPlayerState.queued_action = PLAYER_USEPORTAL;
gPlayerEntity.base.zVelocity = 0x20000;
COLLISION_OFF(&gPlayerEntity.base);
return 1;
case SPECIAL_TILE_11:
if (sub_0801A2B0(mapLayer, position, 8) == 0) {
return 0;
}
if ((gPlayerEntity.base.collisionLayer == 3) && (gMapTop.mapData[position] == SPECIAL_TILE_11)) {
gMapTop.mapData[position] = SPECIAL_TILE_12 + (gPlayerEntity.base.animationState >> 1);
} else {
mapLayer->mapData[position] = SPECIAL_TILE_12 + (gPlayerEntity.base.animationState >> 1);
}
gPlayerState.pushedObject = 0xa0;
gPlayerState.queued_action = PLAYER_PUSH;
gPlayerState.flags |= PL_BUSY;
gPlayerEntity.base.x.HALF.LO = 0;
gPlayerEntity.base.y.HALF.LO = 0;
gPlayerEntity.base.direction = Direction8FromAnimationState(gPlayerEntity.base.animationState);
return 1;
case SPECIAL_TILE_90:
if (sub_0801A2B0(mapLayer, position, 2) == 0) {
return 0;
}
// Move ice block.
mapLayer->mapData[position] = SPECIAL_TILE_91 + (gPlayerEntity.base.animationState >> 1);
gPlayerState.pushedObject = 0x98;
gPlayerState.queued_action = PLAYER_PUSH;
gPlayerState.flags |= PL_BUSY;
gPlayerEntity.base.x.HALF.LO = 0;
gPlayerEntity.base.y.HALF.LO = 0;
gPlayerEntity.base.direction = Direction8FromAnimationState(gPlayerEntity.base.animationState);
return 1;
case SPECIAL_TILE_54:
if (sub_0801A2B0(mapLayer, position, 0xb) == 0) {
return 0;
}
mapLayer->mapData[position] = SPECIAL_TILE_55 + (gPlayerEntity.base.animationState >> 1);
gPlayerState.pushedObject = 0xa0;
gPlayerState.queued_action = PLAYER_PUSH;
gPlayerState.flags |= PL_BUSY;
gPlayerEntity.base.x.HALF.LO = 0;
gPlayerEntity.base.y.HALF.LO = 0;
gPlayerEntity.base.direction = Direction8FromAnimationState(gPlayerEntity.base.animationState);
return 1;
case SPECIAL_TILE_62:
if ((animationState1 & 0xff) != 0) {
return 0;
}
if (((gPlayerState.field_0x35 | gPlayerState.direction) & DIR_NOT_MOVING_CHECK) != 0) {
return 0;
}
if ((gPlayerEntity.base.frame & 2) == 0) {
return 0;
}
mapLayer->mapData[position] = SPECIAL_TILE_63;
gPlayerState.pushedObject = 0x82;
gPlayerState.queued_action = PLAYER_PUSH;
gPlayerState.flags |= PL_BUSY;
gPlayerEntity.base.x.HALF.LO = 0;
gPlayerEntity.base.y.HALF.LO = 0;
gPlayerEntity.base.direction = Direction8FromAnimationState(gPlayerEntity.base.animationState);
return 1;
case ACT_TILE_114:
if ((gPlayerState.field_0x35 & 0x80) != 0) {
return 0;
}
if ((gPlayerEntity.base.frame & 1) == 0) {
return 0;
}
position = sub_0801A570(&gPlayerEntity.base, 1);
if (position == 0xffff) {
return 0;
}
tmp2 = (position >> 0xc) - 1;
position &= 0xfff;
// TODO convert to for loop?
index = 0;
tmp3 = 0;
while (index < 3) {
if ((((*(u32*)(&(((GenericEntity*)gPlayerClones[0]))->field_0x6c)) & (1 << index)) != 0) &&
(sub_0801A570(gPlayerClones[index], 0) == position)) {
tmp3++;
}
index++;
}
if (tmp3 < tmp2) {
return 0;
}
pushedBlock = CreateObject(PUSHED_BLOCK, tmp2, 0);
if (pushedBlock == NULL) {
return 0;
}
pushedBlock->direction = Direction8FromAnimationState(gPlayerEntity.base.animationState);
pushedBlock->x.HALF.HI = ((position & 0xfff & 0x3f) << 4) + 8 + gRoomControls.origin_x;
pushedBlock->y.HALF.HI = ((position & 0xfc0) >> 2) + 8 + gRoomControls.origin_y;
pushedBlock->collisionLayer = gPlayerEntity.base.collisionLayer;
gPlayerState.pushedObject = 0xa0;
gPlayerState.queued_action = PLAYER_PUSH;
gPlayerState.flags |= PL_BUSY;
gPlayerEntity.base.x.HALF.LO = 0;
gPlayerEntity.base.y.HALF.LO = 0;
gPlayerEntity.base.direction = pushedBlock->direction;
return 1;
case SPECIAL_TILE_43 ... SPECIAL_TILE_45:
if (sub_0801A370(mapLayer, position) != 0) {
mapLayer->mapData[position] = SPECIAL_TILE_48 + ((gPlayerEntity.base.animationState & 4) >> 2);
if ((gPlayerState.flags & PL_MINISH) != 0) {
gPlayerState.pushedObject = 0xa0;
} else {
gPlayerState.pushedObject = 0x90;
}
gPlayerState.queued_action = PLAYER_PUSH;
gPlayerState.flags |= PL_BUSY;
gPlayerEntity.base.x.HALF.LO = 0;
gPlayerEntity.base.y.HALF.LO = 0;
gPlayerEntity.base.direction = Direction8FromAnimationState(gPlayerEntity.base.animationState);
return 1;
} else {
return 0;
}
case SPECIAL_TILE_74:
if (sub_0801A458(mapLayer, position, 8) == 0) {
return 0;
}
mapLayer->mapData[position] = SPECIAL_TILE_75 + (gPlayerEntity.base.animationState >> 1);
if ((gPlayerState.flags & PL_MINISH) != 0) {
gPlayerState.pushedObject = 0xc0;
} else {
gPlayerState.pushedObject = 0xa0;
}
gPlayerState.queued_action = PLAYER_PUSH;
gPlayerState.flags |= PL_BUSY;
gPlayerEntity.base.x.HALF.LO = 0;
gPlayerEntity.base.y.HALF.LO = 0;
gPlayerEntity.base.direction = Direction8FromAnimationState(gPlayerEntity.base.animationState);
return 1;
case SPECIAL_TILE_82:
if (gPlayerState.field_0x35 != 0) {
return 0;
}
SetTile(SPECIAL_TILE_84, position, gPlayerEntity.base.collisionLayer);
return 4;
case SPECIAL_TILE_83:
if (gPlayerState.field_0x35 != 6) {
return 0;
}
SetTile(SPECIAL_TILE_84, position, gPlayerEntity.base.collisionLayer);
return 4;
case SPECIAL_TILE_85:
position--;
// fallthrough
case SPECIAL_TILE_86:
if (gPlayerState.field_0x35 != 0) {
return 0;
}
if ((gPlayerEntity.base.y.HALF.HI & 0xf) < 10) {
return 0;
}
for (index = 0; index < 3; index++) {
if (sub_0801A8D0(gPlayerClones[index], 0) == position) {
SetTile(SPECIAL_TILE_89, position, gPlayerEntity.base.collisionLayer);
return 4;
}
}
return 0;
case SPECIAL_TILE_87:
position -= 0x40;
// fallthrough
case SPECIAL_TILE_88:
if (gPlayerState.field_0x35 != 6) {
return 0;
}
if ((gPlayerEntity.base.x.HALF.HI & 0xf) < 10) {
return 0;
}
for (index = 0; index < 3; index++) {
if (sub_0801A8D0(gPlayerClones[index], 6) == position) {
SetTile(SPECIAL_TILE_89, position, gPlayerEntity.base.collisionLayer);
return 4;
}
}
return 0;
case SPECIAL_TILE_95:
animationState3 = 2;
animationState3 &= animationState1;
if (animationState3 == 0) {
return 0;
}
if (((gPlayerState.field_0x35 | gPlayerState.direction) & DIR_NOT_MOVING_CHECK) != 0) {
return 0;
}
if ((gPlayerEntity.base.frame & 1) == 0) {
return 0;
}
SetTile(SPECIAL_TILE_116, position, gPlayerEntity.base.collisionLayer);
gPlayerState.pushedObject = 0xa0;
gPlayerState.queued_action = PLAYER_PUSH;
gPlayerState.flags |= PL_BUSY;
gPlayerEntity.base.x.HALF.LO = 0;
gPlayerEntity.base.y.HALF.LO = 0;
gPlayerEntity.base.direction = Direction8FromAnimationState(gPlayerEntity.base.animationState);
return 1;
case SPECIAL_TILE_125:
animationState3 = gPlayerEntity.base.animationState;
if ((animationState2) != 4) {
return 0;
}
if (((gPlayerState.field_0x35 | gPlayerState.direction) & DIR_NOT_MOVING_CHECK) != 0) {
return 0;
}
if ((gPlayerEntity.base.frame & 1) == 0) {
return 0;
}
SetTile(SPECIAL_TILE_116, position, gPlayerEntity.base.collisionLayer);
SetActTileAtTilePos(ACT_TILE_13, position, gPlayerEntity.base.collisionLayer);
return 1;
default:
return 0;
}
}
bool32 sub_0801A2B0(MapLayer* mapLayer, u32 position, u32 collisionType) {
u16 uVar1;
s16 x;
s16 y;
u16 temp4;
uVar1 = gUnk_080B4488[gPlayerEntity.base.animationState >> 1];
if ((((gPlayerState.field_0x35 | gPlayerState.direction) & DIR_NOT_MOVING_CHECK) == 0) &&
((gPlayerEntity.base.frame & 1) != 0)) {
position = (u16)(position - (-uVar1)); // necessary for match
temp4 = GetActTileForTileType(GetTileTypeAtTilePos(position, gPlayerEntity.base.collisionLayer));
switch (temp4) {
case 0x52:
break;
case 0x26:
case 0x27:
return FALSE;
case 0x29:
return FALSE;
case 0x74:
return FALSE;
default:
if ((mapLayer->collisionData[(position)] != 0x28)) {
x = (((position & 0x3f) * 0x10 + (u32)gRoomControls.origin_x));
y = (((position >> 6) * 0x10 + (u32)gRoomControls.origin_y));
if ((!IsTileCollision(mapLayer->collisionData, x, y, collisionType))) {
return TRUE;
}
}
break;
}
}
return FALSE;
}
bool32 sub_0801A370(MapLayer* mapLayer, u32 position) {
MapLayer* topLayer;
u32 tileType;
u32 pos;
s32 offset;
s32 temp;
if ((gPlayerEntity.base.animationState & 2) == 0) {
return FALSE;
}
if (!sub_0801A4F8()) {
return FALSE;
}
topLayer = GetLayerByIndex(LAYER_TOP);
offset = gUnk_080B4488[gPlayerEntity.base.animationState >> 1];
pos = position + offset;
tileType = GetTileTypeAtTilePos(pos, gPlayerEntity.base.collisionLayer);
switch (tileType) {
case SPECIAL_TILE_43:
pos += offset;
break;
case SPECIAL_TILE_44 ... SPECIAL_TILE_47:
return TRUE;
}
if (topLayer->collisionData[pos - 0x80] == 0x46) {
return FALSE;
}
switch ((u16)GetActTileForTileType(GetTileTypeAtTilePos(pos, gPlayerEntity.base.collisionLayer))) {
case 0x52:
return FALSE;
case 0x26:
case 0x27:
return FALSE;
case 0x29:
return FALSE;
case 0x74:
return FALSE;
}
switch (temp = mapLayer->collisionData[pos]) {
case 0:
return TRUE;
case 5:
case 0x45:
if (offset == 1) {
return TRUE;
}
break;
case 0xa:
case 0x44:
if (offset == -1) {
return TRUE;
}
break;
}
return FALSE;
}
bool32 sub_0801A458(MapLayer* mapLayer, u32 position, u32 collisionType) {
u32 tileType;
u32 pos;
s32 offset = gUnk_080B4488[gPlayerEntity.base.animationState >> 1];
if (sub_0801A4F8()) {
pos = position + offset;
tileType = GetTileTypeAtTilePos(pos, gPlayerEntity.base.collisionLayer);
switch (GetActTileForTileType(tileType)) {
case 0x52:
case 0x26:
case 0x27:
case 0x29:
case 0x74:
return FALSE;
default:
if (((mapLayer->collisionData[pos] != 0x28) &&
(!IsTileCollision(mapLayer->collisionData, (pos & 0x3f) * 0x10 + gRoomControls.origin_x,
(pos >> 6) * 0x10 + gRoomControls.origin_y, collisionType))) &&
(0xe < (u32)mapLayer->collisionData[pos] - 1)) {
return TRUE;
}
break;
}
}
return FALSE;
}
bool32 sub_0801A4F8(void) {
u32 tmp;
if ((gPlayerState.flags & PL_MINISH) != 0) {
if (GetInventoryValue(ITEM_POWER_BRACELETS) != 1) {
return FALSE;
}
if ((gPlayerState.direction & DIR_NOT_MOVING_CHECK) != 0) {
return FALSE;
}
if (gPlayerState.direction != gPlayerEntity.base.direction) {
return FALSE;
}
tmp = (((gPlayerEntity.base.direction + 4) & DirectionWest) >> 3);
if ((gUnk_080B44A0[tmp] & gPlayerEntity.base.collisions) == 0) {
return FALSE;
}
} else {
if (((gPlayerState.field_0x35 | gPlayerState.direction) & DIR_NOT_MOVING_CHECK) != 0) {
return FALSE;
}
if ((gPlayerEntity.base.frame & 1) == 0) {
return FALSE;
}
}
return TRUE;
}
u32 sub_0801A570(Entity* this, u32 param_2) {
MapLayer* layer;
u32 tileType;
u32 position;
u32 index1;
u32 index2;
u16* tileTypes;
u8* collisionData;
if (this == NULL) {
return 0xffff;
}
layer = GetLayerByIndex(this->collisionLayer);
tileTypes = layer->tileTypes;
index1 = 4;
index2 = 2;
switch (this->animationState >> 1) {
case 0:
default:
position = COORD_TO_TILE_OFFSET(this, 0, 10);
do {
if (tileTypes[layer->mapData[position]] == 0x370)
break;
position--;
index1--;
} while (index1 != 0);
position = position - 0x40;
do {
if (tileTypes[layer->mapData[(position)]] != 0x374)
break;
index2++;
position -= 0x40;
} while (index2 < 4);
if (param_2 == 0) {
return position;
}
index1 = GetTileTypeAtTilePos(position, this->collisionLayer);
if ((index1 - 0x369) > 1) {
position = 0xffff;
} else {
collisionData = layer->collisionData - 0x40 + position;
for (index1 = 0; index1 < index2; index1++) {
if (collisionData[index1] != 0) {
position = 0xffff;
break;
}
}
}
break;
case 1:
position = COORD_TO_TILE_OFFSET(this, -10, 0);
do {
if (layer->tileTypes[layer->mapData[position]] == 0x370)
break;
position += 0x40;
index1--;
} while (index1 != 0);
position = position - 0x40;
do {
if (tileTypes[layer->mapData[(position)]] != 0x374)
break;
index2++;
position -= 0x40;
} while (index2 < 4);
if (param_2 == 0) {
return position;
}
index1 = GetTileTypeAtTilePos(position, this->collisionLayer);
if (!(index1 == 0x369) && !(index1 == 0x36d))
position = 0xffff;
else {
collisionData = layer->collisionData + (position + index2);
for (index1 = 0; index1 < index2; index1++) {
if (collisionData[index1 * 0x40] != 0) {
position = 0xffff;
break;
}
}
}
break;
case 2:
position = COORD_TO_TILE_OFFSET(this, 0, -10);
do {
if (layer->tileTypes[layer->mapData[position]] == 0x36f)
break;
position++;
index1--;
} while (index1 != 0);
position = position - 1;
do {
if (tileTypes[layer->mapData[position]] != 0x372)
break;
index2++;
position--;
} while (index2 < 4);
if (param_2 == 0) {
return position;
}
index1 = GetTileTypeAtTilePos(position, this->collisionLayer);
if (!(index1 == 0x369) && !(index1 == 0x36b))
position = 0xffff;
else {
collisionData = layer->collisionData + (position + (index2 * 0x40));
for (index1 = 0; index1 < index2; index1++) {
if (collisionData[index1] != 0) {
position = 0xffff;
break;
}
}
}
break;
case 3:
position = COORD_TO_TILE_OFFSET(this, 10, 0);
do {
if (layer->tileTypes[layer->mapData[position]] == 0x36f)
break;
position -= 0x40;
index1--;
} while (index1 != 0);
position = position - 1;
do {
if (tileTypes[layer->mapData[position]] != 0x372)
break;
index2++;
position--;
} while (index2 < 4);
if (param_2 == 0) {
return position;
}
index1 = GetTileTypeAtTilePos(position, this->collisionLayer);
if (!(index1 == 0x369) && !(index1 == 0x36c))
position = 0xffff;
else {
collisionData = layer->collisionData - 1 + position;
for (index1 = 0; index1 < index2; index1++) {
if (collisionData[index1 * 0x40] != 0) {
position = 0xffff;
break;
}
}
}
}
if (param_2 != 0) {
position |= index2 << 0xc;
}
return position;
}
u32 sub_0801A8D0(Entity* this, u32 param_2) {
u16* mapData;
u32 tileIndex;
u32 position;
if (this == NULL)
return 0xffff;
mapData = GetLayerByIndex(this->collisionLayer)->mapData;
if (param_2 == 0) {
position = COORD_TO_TILE_OFFSET(this, 0, 8);
tileIndex = mapData[position];
if (tileIndex == SPECIAL_TILE_85) {
return position - 1;
}
if (tileIndex == SPECIAL_TILE_86) {
return position;
}
} else {
position = COORD_TO_TILE_OFFSET(this, 8, 0);
tileIndex = mapData[position];
if (tileIndex == SPECIAL_TILE_87) {
return position - 0x40;
}
if (tileIndex == SPECIAL_TILE_88) {
return position;
}
}
return 0xffff;
}
bool32 sub_0801A980(void) {
u16 tileType;
const s16* ptr;
GetLayerByIndex(gPlayerEntity.base.collisionLayer); // TODO result unused?
ptr = &gUnk_080B44A8[gPlayerEntity.base.animationState & 6];
tileType = GetTileTypeAtTilePos(COORD_TO_TILE_OFFSET(&gPlayerEntity.base, -ptr[0], -ptr[1]),
gPlayerEntity.base.collisionLayer);
if (tileType < 0x4000) {
GetActTileForTileType(tileType);
}
return FALSE;
}
bool32 sub_0801A9F0(u32 param_1, u32 param_2, u32 param_3) {
bool32 cond = FALSE;
switch (param_2) {
case 0x360:
cond = TRUE;
break;
case 0x361:
if (param_1 == 0) {
cond = TRUE;
}
break;
case 0x364:
if (param_1 == 8) {
cond = TRUE;
}
break;
case 0x362:
if (param_1 == 0x10) {
cond = TRUE;
}
break;
case 0x363:
if (param_1 == 0x18) {
cond = TRUE;
}
break;
default:
break;
}
if (cond) {
return sub_0801AA58(&gPlayerEntity.base, param_3, param_1);
}
return FALSE;
}
bool32 sub_0801AA58(Entity* this, u32 param_2, u32 param_3) {
MapLayer* mapLayer;
Entity* object;
u32 temp;
mapLayer = GetLayerByIndex(this->collisionLayer);
if (((mapLayer->collisionData[param_2 + gUnk_080B4488[param_3 >> 3]] == 0) ||
((u8)(mapLayer->collisionData[param_2 + gUnk_080B4488[param_3 >> 3]] - 0x20) < 0x20))) {
object = CreateObject(PUSHED_BLOCK, 0, 0);
if (object != NULL) {
object->direction = param_3;
object->x.HALF.HI = ((((param_2)&0x3f) << 4) + 8) + gRoomControls.origin_x;
object->y.HALF.HI = (((param_2 & 0xfc0) >> 2) + 8) + gRoomControls.origin_y;
object->collisionLayer = this->collisionLayer;
gPlayerState.pushedObject = 0xa0;
gPlayerState.queued_action = PLAYER_PUSH;
gPlayerState.flags |= PL_BUSY;
this->x.HALF.LO = 0;
this->y.HALF.LO = 0;
this->direction = param_3;
return TRUE;
}
}
return FALSE;
}
void RenderMapLayerToSubTileMap(u16* subTileMap, MapLayer* mapLayer) {
u16* subTiles;
u16* mapData;
u16* mapDataOriginal;
u16 tileY;
u16 tileX;
u32 tilePosAndLayer;
u32 layerIndex;
// Index into the tileSet at MapLayer.tiles
u32 tileSetIndex;
if (mapLayer == &gMapBottom) {
layerIndex = 1;
} else {
layerIndex = 2;
}
tilePosAndLayer = layerIndex << 0xc;
mapDataOriginal = mapLayer->mapDataOriginal;
mapData = mapLayer->mapData;
for (tileY = 0; tileY < 0x40; tileY++) {
for (tileX = 0; tileX < 0x10; tileX++) {
// inner loop seems to be unrolled four times for some reason?
if (mapData[0] < 0x4000) {
tileSetIndex = mapData[0] * 4;
} else {
tileSetIndex = GetTileSetIndexForSpecialTile(tilePosAndLayer, mapDataOriginal[0]);
}
subTiles = mapLayer->subTiles + tileSetIndex;
subTileMap[0] = subTiles[0];
subTileMap[1] = subTiles[1];
subTileMap[0x80 + 0] = subTiles[2];
subTileMap[0x80 + 1] = subTiles[3];
subTileMap += 2;
if (mapData[1] < 0x4000) {
tileSetIndex = mapData[1] * 4;
} else {
tileSetIndex = GetTileSetIndexForSpecialTile(tilePosAndLayer + 1, mapDataOriginal[1]);
}
subTiles = mapLayer->subTiles + tileSetIndex;
subTileMap[0] = subTiles[0];
subTileMap[1] = subTiles[1];
subTileMap[0x80 + 0] = subTiles[2];
subTileMap[0x80 + 1] = subTiles[3];
subTileMap += 2;
if (mapData[2] < 0x4000) {
tileSetIndex = mapData[2] * 4;
} else {
tileSetIndex = GetTileSetIndexForSpecialTile(tilePosAndLayer + 2, mapDataOriginal[2]);
}
subTiles = mapLayer->subTiles + tileSetIndex;
subTileMap[0] = subTiles[0];
subTileMap[1] = subTiles[1];
subTileMap[0x80 + 0] = subTiles[2];
subTileMap[0x80 + 1] = subTiles[3];
subTileMap += 2;
if (mapData[3] < 0x4000) {
tileSetIndex = mapData[3] * 4;
} else {
tileSetIndex = GetTileSetIndexForSpecialTile(tilePosAndLayer + 3, mapDataOriginal[3]);
}
subTiles = mapLayer->subTiles + tileSetIndex;
subTileMap[0] = subTiles[0];
subTileMap[1] = subTiles[1];
subTileMap[0x80 + 0] = subTiles[2];
subTileMap[0x80 + 1] = subTiles[3];
subTileMap += 2;
mapData += 4;
mapDataOriginal += 4;
tilePosAndLayer = (u16)(tilePosAndLayer + 4);
}
subTileMap = subTileMap + 0x80;
}
}
u32 GetTileSetIndexForSpecialTile(u32 tilePosAndLayer, u32 tileIndex) {
u32 index;
SpecialTileEntry* ptr;
u32 count;
ptr = gTilesForSpecialTiles;
count = gRoomVars.tileEntityCount;
for (index = 0; index < count; ptr++, index++) {
if (tilePosAndLayer == ptr->tilePosAndLayer) {
return ptr->tileIndex * 4;
}
}
return tileIndex * 4;
}
void sub_0801AC98(void) {
u32 position;
u32 width;
u32 height;
u32 indexX;
u32 indexY;
const Data* ptr;
width = gRoomControls.width >> 4;
height = gRoomControls.height >> 4;
position = 0;
for (indexY = 0; indexY < height; indexY++) {
for (indexX = 0; indexX < width; indexX++, position++) {
for (ptr = gUnk_080B44C0; ptr->tileType != 0xffff; ptr++) {
if (ptr->tileType == GetTileTypeAtTilePos(position, 1)) {
if (gUnk_080B44B8[ptr->unk_a] != 0) {
sub_0801AD6C(ptr, position);
break;
}
}
}
for (ptr = gUnk_080B44C2; ptr->tileType != 0xffff; ptr++) {
if (ptr->tileType == GetTileTypeAtTilePos(position, 2)) {
if (gUnk_080B44B8[ptr->unk_a] != 0) {
sub_0801AD6C(ptr, position);
break;
}
}
}
}
position = position + (0x40 - width);
}
}
void sub_0801AD6C(const Data* param_1, u32 tilePos) {
Entity* entity;
Manager* manager;
s32 tmpX1;
s32 tmpY1;
s32 tmpX2;
s32 tmpY2;
if (param_1->kind != MANAGER) {
entity = GetEmptyEntity();
if (entity != NULL) {
entity->kind = (u8)param_1->kind;
entity->id = (u8)param_1->id;
entity->type = (u8)param_1->type;
entity->type2 = (u8)param_1->type2;
tmpX1 = ((u16)tilePos & 0x3f) * 0x10 + 8;
entity->x.HALF.HI = tmpX1 + gRoomControls.origin_x;
tmpY1 = (s16)((tilePos & 0xfc0) >> 2) + 8;
entity->y.HALF.HI = tmpY1 + gRoomControls.origin_y;
entity->collisionLayer = 0;
ResolveCollisionLayer(entity);
AppendEntityToList(entity, gEntityListLUT[entity->kind]);
}
} else {
manager = GetEmptyManager();
if (manager != NULL) {
manager->kind = (u8)param_1->kind;
manager->id = (u8)param_1->id;
manager->type = (u8)param_1->type;
manager->type2 = (u8)param_1->type2;
// TODO are these fields common for all managers or does this usually create managers of certain types?
tmpX2 = ((u16)tilePos & 0x3f) * 0x10 + 8;
*(u16*)(&manager[1].timer + 10) = tmpX2 + gRoomControls.origin_x;
tmpY2 = (s16)((tilePos & 0xfc0) >> 2) + 8;
*(u16*)(&manager[1].timer + 12) = tmpY2 + gRoomControls.origin_y;
AppendEntityToList((Entity*)manager, gEntityListLUT[manager->kind]);
}
}
}
bool32 sub_0801AE30(void) {
return TRUE;
}
u32 sub_0801AE34(void) {
return gRoomControls.scroll_flags >> 1 & 1;
}
void sub_0801AE44(bool32 loadGfx) {
void (*func)(void);
gRoomControls.tileSet = (u32)NULL;
LoadRoomTileSet();
if (loadGfx != 0) {
LoadRoomGfx();
}
sub_080809D4();
UpdateIsDiggingCave();
if (gRoomTransition.field2d != 0) {
sub_0807C898();
}
if (gArea.lightType != 0) {
MemFill16(0xf, (void*)0x600f000, 0x800);
sub_0805BB74(-1);
}
func = GetCurrentRoomProperty(5);
if (func != NULL) {
func();
}
if ((gDiggingCaveEntranceTransition.isDiggingCave == 0) && (gArea.onEnter != NULL)) {
gArea.onEnter(gArea.transitionManager);
}
if ((gRoomControls.scroll_flags & 1) == 0) {
if (gMapBottom.bgSettings != NULL) {
RenderMapLayerToSubTileMap(gMapDataBottomSpecial, &gMapBottom);
}
if (gMapTop.bgSettings != NULL) {
RenderMapLayerToSubTileMap(gMapDataTopSpecial, &gMapTop);
}
} else {
sub_0807C4F8();
}
UpdateScrollVram();
}
void SetMultipleTiles(const TileData* tileData, u32 basePosition, u32 layer) {
while (tileData->tileIndex != -1) {
SetTile((u16)tileData->tileIndex, basePosition + tileData->tilePosOffset, layer);
tileData++;
}
}
// Add a new entry at the end of gTilesForSpecialTiles
void RegisterInteractTile(u32 tileIndex, u32 tilePos, u32 layer) {
u32 index;
if ((tileIndex < 0x4000) && (gRoomTransition.field30 == 0)) {
index = gRoomVars.tileEntityCount;
if (index < 0x100) {
gTilesForSpecialTiles[index].tileIndex = tileIndex;
gTilesForSpecialTiles[index].tilePosAndLayer = (layer << 12) | tilePos;
gRoomVars.tileEntityCount = index + 1;
}
}
}
void UnregisterInteractTile(u32 tilePos, s32 layer) {
u32 count;
SpecialTileEntry* ptr;
u32 tilePosAndLayer;
u32 t;
layer = layer << 12;
tilePosAndLayer = tilePos | layer;
ptr = gTilesForSpecialTiles;
count = gRoomVars.tileEntityCount;
t = 0;
if (t >= count) {
return;
}
if (tilePosAndLayer == ptr->tilePosAndLayer) {
count--;
gRoomVars.tileEntityCount = count;
ptr[0] = ptr[count];
return;
}
while (tilePosAndLayer != ptr->tilePosAndLayer) {
ptr++;
t++;
if (t >= count) {
return;
}
}
count--;
gRoomVars.tileEntityCount = count;
ptr = gTilesForSpecialTiles;
ptr[t] = ptr[count];
}
const struct_080B44D0 gUnk_080B44D0[] = {
{ 0x67, SPECIAL_TILE_132 }, { 0x68, SPECIAL_TILE_133 }, { 0x69, SPECIAL_TILE_134 }, { 0x6a, SPECIAL_TILE_135 },
{ 0x6b, SPECIAL_TILE_136 }, { 0x27, SPECIAL_TILE_131 }, { 0x23, SPECIAL_TILE_141 }, { 0x0, 0x0 },
};
// used for minish houses, seems to overwrite all tiles with certain collision values on layer 1 for them?
void sub_0801AFE4(void) {
const struct_080B44D0* ptr;
u8* collisionData;
u32 x;
u32 y;
u32 width;
u32 height;
collisionData = gMapBottom.collisionData;
width = gRoomControls.width / 16;
height = gRoomControls.height / 16;
for (y = 0; y < height; y++) {
for (x = 0; x < width; x++) {
for (ptr = gUnk_080B44D0; ptr->collision != 0; ptr++) {
if (ptr->collision == *collisionData) {
SetTile(ptr->tileIndex, y * 0x40 + x, LAYER_BOTTOM);
break;
}
}
collisionData++;
}
collisionData = collisionData + (0x40 - width);
}
}
|