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
|
/**
* @file pot.c
* @ingroup Objects
*
* @brief Pot object
*/
#include "entity.h"
#include "flags.h"
#include "object/pot.h"
#include "hitbox.h"
#include "object.h"
#include "asm.h"
#include "effects.h"
#include "physics.h"
#include "object/itemOnGround.h"
#include "player.h"
#include "room.h"
#include "sound.h"
#include "tiles.h"
typedef struct {
/*0x00*/ Entity base;
/*0x68*/ u8 unused1[8];
/*0x70*/ u16 unk_70;
/*0x72*/ u8 unused2[11];
/*0x7d*/ u8 unk_7d;
/*0x7e*/ u8 unused3[8];
/*0x86*/ u16 flag;
} PotEntity;
void Pot_Action5(PotEntity*);
static void BreakPot(PotEntity*, Entity*);
void sub_08082608(PotEntity* this);
void Pot_Init(PotEntity* this);
void Pot_Action1(PotEntity* this);
void Pot_Action2(PotEntity* this);
void Pot_Action3(PotEntity* this);
void Pot_Action4(PotEntity* this);
void Pot_Action5(PotEntity* this);
void sub_08082510(PotEntity* this);
void nullsub_511(PotEntity* this);
void sub_08082588(PotEntity* this);
void sub_0808259C(PotEntity* this);
void sub_080825E8(PotEntity* this);
void sub_080825F0(PotEntity* this);
void sub_08082608(PotEntity* this);
void sub_08082818(PotEntity* this);
void nullsub_512(PotEntity* this);
void sub_080827F8(PotEntity* this);
void sub_08082778(PotEntity* this);
void sub_0808270C(PotEntity* this);
void sub_080826FC(PotEntity* this);
extern void RegisterCarryEntity(Entity*);
extern void CheckOnLayerTransition(Entity*);
void Pot(PotEntity* this) {
static void (*const Pot_Actions[])(PotEntity*) = {
Pot_Init, Pot_Action1, Pot_Action2, Pot_Action3, Pot_Action4, Pot_Action5,
};
Pot_Actions[super->action](this);
super->contactFlags = 0;
}
void Pot_Init(PotEntity* this) {
if (super->type2 == 1 && CheckFlags(this->flag)) {
DeleteThisEntity();
}
super->action = 1;
super->hitbox = (Hitbox*)&gHitbox_18;
super->speed = 0x80;
super->y.HALF.HI += 3;
super->carryFlags = 0;
COLLISION_ON(super);
super->health = 1;
super->collisionFlags = 7;
super->hitType = 0x6E;
super->collisionMask = 0x84;
super->gustJarFlags = 0x12;
if (super->collisionLayer == 0) {
ResolveCollisionLayer(super);
}
this->unk_70 = GetTileIndex(COORD_TO_TILE(super), super->collisionLayer);
if (this->unk_70 == SPECIAL_TILE_0) {
DeleteThisEntity();
}
SetTile(SPECIAL_TILE_0, COORD_TO_TILE(super), super->collisionLayer);
InitializeAnimation(super, 5);
}
void Pot_Action1(PotEntity* this) {
u32 tileType;
u32 var0 = super->contactFlags & 0x7F;
switch (var0) {
case 0x13:
super->action = 3;
super->subAction = 0;
break;
case 0x1D:
SetTile((u16)this->unk_70, COORD_TO_TILE(super), super->collisionLayer);
super->action = 5;
super->zVelocity = Q_16_16(2.625);
super->spriteOffsetY = 0;
super->spriteSettings.shadow = 1;
super->spritePriority.b1 = 3;
COLLISION_OFF(super);
Pot_Action5(this);
break;
default:
tileType = GetTileTypeAtEntity(super);
if (tileType != 0x4000) {
switch (tileType) {
case SPECIAL_TILE_4:
case SPECIAL_TILE_3:
case SPECIAL_TILE_2:
case SPECIAL_TILE_1:
super->direction = (tileType - SPECIAL_TILE_1) * 8;
super->timer = 32;
super->action = 4;
if (gPlayerState.flags & PL_MINISH) {
super->speed >>= 1;
super->timer = 64;
}
SetTile((u16)this->unk_70, COORD_TO_TILE(super), super->collisionLayer);
EnqueueSFX(SFX_10F);
break;
case SPECIAL_TILE_103:
SetTile((u16)this->unk_70, COORD_TO_TILE(super), super->collisionLayer);
DeleteThisEntity();
break;
default:
if (GetActTileAtEntity(super) == ACT_TILE_13) {
CreateFx(super, FX_FALL_DOWN, 0);
} else if (tileType == SPECIAL_TILE_5) {
gPlayerState.lastSwordMove = SWORD_MOVE_BREAK_POT;
SetTile((u16)this->unk_70, COORD_TO_TILE(super), super->collisionLayer);
}
BreakPot(this, NULL);
break;
}
} else {
RegisterCarryEntity(super);
}
break;
}
}
void Pot_Action2(PotEntity* this) {
static void (*const subActionFuncs[])(PotEntity*) = {
sub_08082510, nullsub_511, sub_08082588, sub_0808259C, sub_080825E8, sub_080825F0, sub_08082608,
};
subActionFuncs[super->subAction](this);
}
void sub_08082510(PotEntity* this) {
COLLISION_ON(super);
super->hitbox = (Hitbox*)&gUnk_080FD340;
super->collisionFlags = 7;
super->hitType = 1;
super->collisionMask = gPlayerEntity.base.collisionMask;
super->spriteOffsetY = 0;
SetTile((u16)this->unk_70, COORD_TO_TILE(super), super->collisionLayer);
super->subAction++;
}
void nullsub_511(PotEntity* this) {
}
void sub_08082588(PotEntity* this) {
super->spritePriority.b1 = 3;
}
void sub_0808259C(PotEntity* this) {
switch (GetTileHazardType(super)) {
case 2:
CreateFx(super, FX_WATER_SPLASH, 0);
break;
case 1:
CreateFx(super, FX_FALL_DOWN, 0);
break;
case 3:
CreateFx(super, FX_LAVA_SPLASH, 0);
break;
default:
BreakPot(this, &gPlayerEntity.base);
return;
}
DeleteThisEntity();
}
void sub_080825E8(PotEntity* this) {
DeleteThisEntity();
}
void sub_080825F0(PotEntity* this) {
if (gPlayerState.heldObject == 0) {
sub_08082608(this);
}
}
void sub_08082608(PotEntity* this) {
super->action = 1;
super->subAction = 0;
}
void Pot_Action4(PotEntity* this) {
u32 tileType;
sub_0800445C(super);
if (super->timer-- != 0) {
LinearMoveUpdate(super);
CheckOnLayerTransition(super);
return;
}
if (sub_0800442E(super)) {
return;
}
super->action = 1;
if (gPlayerState.flags & PL_MINISH) {
super->speed <<= 1;
}
this->unk_70 = GetTileIndex(COORD_TO_TILE(super), super->collisionLayer);
tileType = GetTileTypeAtEntity(super);
switch (tileType) {
case 0x71:
case 0x72:
BreakPot(this, NULL);
break;
default:
SetTile(SPECIAL_TILE_0, COORD_TO_TILE(super), super->collisionLayer);
RegisterCarryEntity(super);
break;
}
}
void Pot_Action3(PotEntity* this) {
static void (*const subActionFuncs[])(PotEntity*) = {
sub_080826FC, sub_0808270C, sub_08082778, sub_080827F8, nullsub_512, sub_08082818,
};
subActionFuncs[super->subAction](this);
}
void sub_080826FC(PotEntity* this) {
super->subAction = 1;
super->gustJarTolerance = 48;
super->timer = 0;
}
void sub_0808270C(PotEntity* this) {
if ((gPlayerState.gustJarState & 0xF) != 0x1 || (super->contactFlags & 0x7F) != 0x13) {
super->spriteOffsetX = 0;
super->action = 1;
SetTile(SPECIAL_TILE_0, COORD_TO_TILE(super), super->collisionLayer);
} else {
sub_0806F4E8(super);
}
}
void sub_08082778(PotEntity* this) {
if (super->timer == 0) {
super->timer = 1;
super->spriteOffsetX = 0;
super->spriteOffsetY = -2;
SetTile((u16)this->unk_70, COORD_TO_TILE(super), super->collisionLayer);
}
if ((gPlayerState.gustJarState & 0xF) != 0x1 || (super->contactFlags & 0x7F) != 0x13) {
BreakPot(this, NULL);
} else {
sub_0806F3E4(super);
}
}
void sub_080827F8(PotEntity* this) {
if (gPlayerState.gustJarState == 0) {
BreakPot(this, NULL);
}
}
void nullsub_512(PotEntity* this) {
}
void sub_08082818(PotEntity* this) {
BreakPot(this, NULL);
}
void Pot_Action5(PotEntity* this) {
if (super->zVelocity < 0) {
super->spriteSettings.flipY = 1;
}
if (GravityUpdate(super, Q_8_8(32.0)) == 0) {
BreakPot(this, NULL);
}
}
static void BreakPot(PotEntity* this, Entity* parent) {
u32 parameter = sub_0808288C(super, super->type, this->unk_7d, super->type2);
Entity* fxEntity = CreateFx(super, FX_POT_SHATTER, parameter);
if (fxEntity) {
fxEntity->parent = parent;
}
if (super->type2 == 1) {
SetFlag(this->flag);
}
DeleteThisEntity();
}
u32 sub_0808288C(Entity* this, u32 form, u32 arg2, u32 arg3) {
ItemOnGroundEntity* entity;
u32 result = 0;
switch (form) {
case 0xFF:
result = 0;
break;
case 0:
result = 0x80;
break;
default:
entity = (ItemOnGroundEntity*)CreateObjectWithParent(this, GROUND_ITEM, form, arg2);
if (entity != NULL) {
if (arg3 == 2) {
entity->base.timer = 5;
entity->flag = ((PotEntity*)this)->flag; // This function is also used by flyingSkull.
} else {
entity->base.timer = 0;
}
}
break;
}
return result;
}
|