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
|
/**
* @file doubleBookshelf.c
* @ingroup Objects
*
* @brief Double Bookshelf object
*/
#include "functions.h"
#include "object.h"
#include "tiles.h"
typedef struct {
/*0x00*/ Entity base;
/*0x68*/ u8 unk_68[0x18];
/*0x80*/ u16 tilePos;
/*0x82*/ u16 unk_82;
/*0x84*/ u8 unk_84;
/*0x85*/ u8 unk_85;
/*0x86*/ u16 unk_86;
} DoubleBookshelfEntity;
void sub_0809B334(DoubleBookshelfEntity*);
void sub_0809B0B0(DoubleBookshelfEntity*);
void sub_0809B234(DoubleBookshelfEntity*);
void sub_0809B274(DoubleBookshelfEntity*);
void sub_0809B358(DoubleBookshelfEntity*);
void sub_0809B38C(DoubleBookshelfEntity*);
void DoubleBookshelf_Init(DoubleBookshelfEntity*);
void DoubleBookshelf_Action1(DoubleBookshelfEntity*);
void DoubleBookshelf_Action2(DoubleBookshelfEntity*);
void DoubleBookshelf_Action3(DoubleBookshelfEntity*);
void DoubleBookshelf(DoubleBookshelfEntity* this) {
static void (*const DoubleBookshelf_Actions[])(DoubleBookshelfEntity*) = {
DoubleBookshelf_Init,
DoubleBookshelf_Action1,
DoubleBookshelf_Action2,
DoubleBookshelf_Action3,
};
DoubleBookshelf_Actions[super->action](this);
}
void DoubleBookshelf_Init(DoubleBookshelfEntity* this) {
DoubleBookshelfEntity* child;
super->frameIndex = super->type;
this->tilePos = COORD_TO_TILE(super);
if (super->type != 0) {
super->action = 1;
if (this->unk_84 == 0) {
super->subAction = 0;
} else {
super->subAction = 1;
}
} else {
super->action = 3;
super->subAction = 4;
this->unk_84 = 0;
UpdateSpriteForCollisionLayer(super);
child = (DoubleBookshelfEntity*)CreateObject(DOUBLE_BOOKSHELF, 1, 0);
if (child != NULL) {
(child->base).parent = super;
super->child = &child->base;
if (CheckFlags(this->unk_86) == 0) {
PositionRelative(super, &child->base, 0x100000, 0x100000);
child->unk_84 = 0;
} else {
PositionRelative(super, &child->base, 0, 0x100000);
child->unk_84 = 1;
}
}
sub_0809B334(this);
}
sub_0809B0B0(this);
}
void DoubleBookshelf_Action1(DoubleBookshelfEntity* this) {
GetTileType(this->unk_82, super->collisionLayer);
sub_0809B234(this);
}
void DoubleBookshelf_Action2(DoubleBookshelfEntity* this) {
LinearMoveUpdate(super);
if (--super->timer == 0) {
super->action = 1;
this->tilePos = COORD_TO_TILE(super);
SetPlayerControl(CONTROL_ENABLED);
sub_0809B0B0(this);
EnqueueSFX(SFX_BUTTON_PRESS);
}
}
void DoubleBookshelf_Action3(DoubleBookshelfEntity* this) {
sub_0809B234(this);
}
void sub_0809B0B0(DoubleBookshelfEntity* this) {
u32 tilePos = this->tilePos - 1;
u32 layer = super->collisionLayer;
switch (super->subAction) {
case 0:
this->unk_84 = 0;
this->unk_82 = tilePos + 2;
SetTile(SPECIAL_TILE_130, tilePos - 1, layer);
SetTile(SPECIAL_TILE_34, tilePos, layer);
SetTile(SPECIAL_TILE_34, tilePos + 1, layer);
SetTile(SPECIAL_TILE_34, tilePos + 2, layer);
break;
case 1:
this->unk_84 = 1;
this->unk_82 = tilePos;
SetTile(SPECIAL_TILE_95, tilePos, layer);
SetTile(SPECIAL_TILE_34, tilePos + 1, layer);
SetTile(SPECIAL_TILE_34, tilePos + 2, layer);
SetTile(SPECIAL_TILE_130, tilePos + 3, layer);
break;
case 2:
this->unk_84 = 1;
this->unk_82 = tilePos;
SetTile(SPECIAL_TILE_130, tilePos + 3, layer);
SetTile(SPECIAL_TILE_34, tilePos + 2, layer);
SetTile(SPECIAL_TILE_95, tilePos, layer);
SetFlag(((DoubleBookshelfEntity*)super->parent)->unk_86);
break;
case 3:
this->unk_84 = 0;
this->unk_82 = tilePos + 2;
SetTile(SPECIAL_TILE_130, tilePos - 1, layer);
SetTile(SPECIAL_TILE_34, tilePos, layer);
SetTile(SPECIAL_TILE_95, tilePos + 2, layer);
ClearFlag(((DoubleBookshelfEntity*)super->parent)->unk_86);
break;
case 4:
SetTile(SPECIAL_TILE_34, tilePos, layer);
SetTile(SPECIAL_TILE_34, tilePos + 1, layer);
SetTile(SPECIAL_TILE_34, tilePos + 2, layer);
break;
}
}
void sub_0809B234(DoubleBookshelfEntity* this) {
if (super->type != 0) {
super->spriteRendering.b3 = super->parent->spriteRendering.b3;
super->spritePriority.b0 = super->parent->spritePriority.b0;
} else {
sub_0809B274(this);
}
}
void sub_0809B274(DoubleBookshelfEntity* this) {
Entity* player = &gPlayerEntity.base;
switch (this->unk_84) {
case 0:
if (player->y.HALF.HI + 0x14 >= super->y.HALF.HI) {
return;
}
this->unk_84 = 1;
super->spritePriority.b0 = 5;
break;
case 1:
if (player->x.HALF.HI + 0x1c > super->x.HALF.HI) {
this->unk_84 = 2;
SetTile(SPECIAL_TILE_34, this->tilePos + 2, LAYER_BOTTOM);
sub_0809B358((DoubleBookshelfEntity*)super->child);
return;
}
if (player->y.HALF.HI + 0x10 <= super->y.HALF.HI) {
return;
}
this->unk_84 = 0;
super->spritePriority.b0 = 4;
break;
case 2:
if (player->x.HALF.HI + 0x20 >= super->x.HALF.HI) {
return;
}
this->unk_84 = 1;
RestorePrevTileEntity(this->tilePos + 2, 1);
sub_0809B38C((DoubleBookshelfEntity*)super->child);
return;
}
}
void sub_0809B334(DoubleBookshelfEntity* this) {
s32 index;
u32 tilePos = this->tilePos - 0x81;
for (index = 2; index >= 0; index--, tilePos++) {
SetTile(SPECIAL_TILE_38, tilePos, LAYER_BOTTOM);
}
}
void sub_0809B358(DoubleBookshelfEntity* this) {
static const u16 gUnk_08123D68[] = { SPECIAL_TILE_34, SPECIAL_TILE_34, SPECIAL_TILE_116,
SPECIAL_TILE_38, SPECIAL_TILE_116, SPECIAL_TILE_116,
SPECIAL_TILE_38, SPECIAL_TILE_116, SPECIAL_TILE_34,
SPECIAL_TILE_34 };
s32 index;
const u16* array = &gUnk_08123D68[this->unk_84];
u32 tilePos = this->tilePos + TILE_POS(-2, -2);
for (index = 4; index >= 0;) {
SetTile(*array, tilePos, LAYER_BOTTOM);
index--;
tilePos++;
array += 2;
}
}
void sub_0809B38C(DoubleBookshelfEntity* this) {
s32 index;
u32 tilePos = this->tilePos + TILE_POS(-2, -2);
for (index = 4; index >= 0;) {
RestorePrevTileEntity(tilePos, 1);
index--;
tilePos++;
}
}
|