This repository was archived by the owner on Apr 1, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathunderwater_lava_platform.c
More file actions
270 lines (230 loc) · 7.87 KB
/
underwater_lava_platform.c
File metadata and controls
270 lines (230 loc) · 7.87 KB
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
#include "global.h"
#include "core.h"
#include "trig.h"
#include "game/entity.h"
#include "game/sa1_sa2_shared/collision.h"
#include "game/multiplayer/multiplayer_event_mgr.h"
#include "game/stage/terrain_collision.h"
#include "game/stage/player.h"
#include "game/water_effects.h"
#include "malloc_vram.h"
#include "lib/m4a/m4a.h"
#include "constants/animations.h"
#include "constants/char_states.h"
#include "constants/move_states.h"
#include "constants/songs.h"
#include "constants/zones.h"
#define LAVA_SPURT_RATE TIME(0, 1.7)
typedef struct {
/* 0x00 */ SpriteBase base;
/* 0x0C */ Sprite s;
/* 0x3C */ Hitbox reserved;
/* 0x44 */ Sprite s2;
/* 0x74 */ u8 unk74;
/* 0x78 */ s32 qUnk78;
/* 0x7C */ s32 qUnk7C;
/* 0x80 */ s32 unk80;
/* 0x84 */ s32 unk84;
} UnderwaterLavaPlatform; /* 0x88 */
void Task_UnderwaterLavaPlatform(void);
void Task_80929A0(void);
void TaskDestructor_UnderwaterLavaPlatform(struct Task *t);
void CreateEntity_UnderwaterLavaPlatform(MapEntity *me, u16 regionX, u16 regionY, u8 id)
{
struct Task *t
= TaskCreate(Task_UnderwaterLavaPlatform, sizeof(UnderwaterLavaPlatform), 0x2000, 0, TaskDestructor_UnderwaterLavaPlatform);
UnderwaterLavaPlatform *platform = TASK_DATA(t);
Sprite *s = &platform->s;
Sprite *s2 = &platform->s2;
platform->base.regionX = regionX;
platform->base.regionY = regionY;
platform->base.me = me;
platform->base.meX = me->x;
platform->base.id = id;
platform->qUnk78 = 0;
platform->qUnk7C = 0;
platform->unk74 = 0;
platform->unk80 = 0;
platform->unk84 = 0;
SET_MAP_ENTITY_INITIALIZED(me);
s->graphics.dest = ALLOC_TILES(SA1_ANIM_PLATFORM_LAVA_SPURT);
s->graphics.anim = SA1_ANIM_PLATFORM_LAVA;
s->variant = 0;
s->oamFlags = SPRITE_OAM_ORDER(18);
s->graphics.size = 0;
s->animCursor = 0;
s->qAnimDelay = Q(0);
s->prevVariant = -1;
s->animSpeed = SPRITE_ANIM_SPEED(1.0);
s->palId = 0;
s->hitboxes[0].index = HITBOX_STATE_INACTIVE;
s->frameFlags = SPRITE_FLAG(PRIORITY, 2);
s2->graphics.dest = ALLOC_TILES(SA1_ANIM_PLATFORM_HORZ_4_PURPLE);
s2->graphics.anim = SA1_ANIM_PLATFORM_HORZ_4_PURPLE;
s2->variant = 0;
s2->oamFlags = SPRITE_OAM_ORDER(17);
s2->graphics.size = 0;
s2->animCursor = 0;
s2->qAnimDelay = Q(0);
s2->prevVariant = -1;
s2->animSpeed = SPRITE_ANIM_SPEED(1.0);
s2->palId = 0;
s2->hitboxes[0].index = HITBOX_STATE_INACTIVE;
s2->frameFlags = SPRITE_FLAG(PRIORITY, 2);
}
void Task_UnderwaterLavaPlatform(void)
{
CamCoord worldX, worldY;
UnderwaterLavaPlatform *platform;
MapEntity *me;
Sprite *s;
Sprite *s2;
s32 i;
platform = TASK_DATA(gCurTask);
me = platform->base.me;
s = &platform->s;
s2 = &platform->s2;
worldX = TO_WORLD_POS(platform->base.meX, platform->base.regionX);
worldY = TO_WORLD_POS(me->y, platform->base.regionY);
s->x = worldX - gCamera.x;
s->y = worldY - gCamera.y - 3;
s2->x = worldX - gCamera.x;
s2->y = worldY - gCamera.y;
i = 0;
do {
s32 qPrevPlayerX = PLAYER(i).qWorldX;
if (Coll_Player_PlatformCrumbling(s2, worldX, worldY, &PLAYER(i)) & COLL_FLAG_8) {
PLAYER(i).qWorldY = Q(worldY - 27);
PLAYER(i).moveState &= ~MOVESTATE_IN_AIR;
}
PLAYER(i).qWorldX = qPrevPlayerX;
sub_80096B0(s, worldX, worldY, &PLAYER(i));
} while (++i < gNumSingleplayerCharacters);
if (IS_OUT_OF_DISPLAY_RANGE(worldX, worldY) && IS_OUT_OF_CAM_RANGE(s->x, s->y)) {
SET_MAP_ENTITY_NOT_INITIALIZED(me, platform->base.meX);
TaskDestroy(gCurTask);
return;
}
if (Mod(gStageTime, LAVA_SPURT_RATE) == 0) {
platform->unk84 = LAVA_SPURT_RATE;
platform->unk74 = 0;
platform->qUnk78 = -Q(5);
platform->qUnk7C = +Q(0);
platform->unk80 = 3;
s->graphics.anim = SA1_ANIM_PLATFORM_LAVA_SPURT;
s->variant = 0;
s->prevVariant = -1;
m4aSongNumStart(SE_LAVA_PLATFORM_SPURT);
gCurTask->main = Task_80929A0;
}
UpdateSpriteAnimation(s);
DisplaySprite(s);
UpdateSpriteAnimation(s2);
DisplaySprite(s2);
}
// (97.66%) https://decomp.me/scratch/cj6rs
NONMATCH("asm/non_matching/game/interactables/lava_platform__Task_80929A0.inc", void Task_80929A0(void))
{
CamCoord worldX, worldY;
UnderwaterLavaPlatform *platform;
MapEntity *me;
Sprite *s;
Sprite *s2;
s32 i;
platform = TASK_DATA(gCurTask);
me = platform->base.me;
s = &platform->s;
s2 = &platform->s2;
worldX = TO_WORLD_POS(platform->base.meX, platform->base.regionX);
worldY = TO_WORLD_POS(me->y, platform->base.regionY);
platform->qUnk78 += Q(37. / 256.);
platform->qUnk7C += platform->qUnk78;
s->x = worldX - gCamera.x;
s->y = worldY - gCamera.y - 3;
s2->x = worldX - gCamera.x;
s2->y = worldY - gCamera.y + I(platform->qUnk7C);
i = 0;
do {
// _08092A34_loop
if (GetBit(platform->unk74, i)) {
if (!Coll_Player_Entity_Intersection(s2, worldX, worldY + I(platform->qUnk7C), &PLAYER(i))) {
ClearBit(platform->unk74, i);
// asm("");
} else {
PLAYER(i).qWorldY += platform->qUnk78;
}
} else {
// _08092AC8
if (Coll_Player_PlatformCrumbling(s2, worldX, worldY + I(platform->qUnk7C), &PLAYER(i))) {
PLAYER(i).qWorldY = Q(worldY + I(platform->qUnk7C) - 27);
SetBit(platform->unk74, i);
if (PLAYER(i).moveState & MOVESTATE_IN_AIR) {
ClearBit(platform->unk74, i);
}
if (PLAYER(i).qSpeedAirY == Q(0)) {
if (PLAYER(i).charState != CHARSTATE_WALK_A) {
Player_TransitionCancelFlyingAndBoost(&PLAYER(i));
PLAYER(i).charState = CHARSTATE_WALK_A;
}
}
} else {
ClearBit(platform->unk74, i);
// asm("");
}
}
} while (++i < gNumSingleplayerCharacters);
// _08092BF4
if (--platform->unk84 == 48) {
s->prevVariant = -1;
s->graphics.anim = SA1_ANIM_PLATFORM_LAVA;
s->variant = 0;
// goto _08092E54;
UpdateSpriteAnimation(s);
} else if ((platform->unk84 >= 49) && (platform->unk84 < 96)) {
// _08092C2E
i = 0;
do {
if (PLAYER_SPR_INFO_HITBOX(i, 0)->index != HITBOX_STATE_INACTIVE) {
if (HB_COLLISION(worldX, worldY, s->hitboxes[1].b, I(PLAYER(i).qWorldX), I(PLAYER(i).qWorldY),
PLAYER_SPR_INFO_HITBOX(i, 0)->b
)) {
Coll_DamagePlayer(&PLAYER(i));
}
}
} while (++i < gNumSingleplayerCharacters);
UpdateSpriteAnimation(s);
} else if (platform->unk84 < 48) {
// _08092E68
if (UpdateSpriteAnimation(s) == ACMD_RESULT__ENDED) {
s->prevVariant = -1;
s->graphics.anim = SA1_ANIM_PLATFORM_LAVA;
s->variant = 0;
}
UpdateSpriteAnimation(s);
}
// _08092E92
if (platform->qUnk7C >= Q(0)) {
if (--platform->unk80 != 0) {
platform->qUnk78 = -Div(platform->qUnk78 * 2, 5);
platform->unk74 = 0;
platform->qUnk7C = Q(0);
} else {
// _08092EC8
s->prevVariant = -1;
s->graphics.anim = SA1_ANIM_PLATFORM_LAVA;
s->variant = 0;
gCurTask->main = Task_UnderwaterLavaPlatform;
}
}
// _08092EE6
DisplaySprite(s);
UpdateSpriteAnimation(s2);
DisplaySprite(s2);
}
END_NONMATCH
void TaskDestructor_UnderwaterLavaPlatform(struct Task *t)
{
UnderwaterLavaPlatform *platform = TASK_DATA(t);
VramFree(platform->s.graphics.dest);
VramFree(platform->s2.graphics.dest);
}