Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/LRZ/LRZ2Setup.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: LRZ2Setup Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectLRZ2Setup *LRZ2Setup;
11
12
void LRZ2Setup_Update(void) {}
13
14
void LRZ2Setup_LateUpdate(void) {}
15
16
void LRZ2Setup_StaticUpdate(void)
17
{
18
// Lava
19
LRZ2Setup->lavaPalTimer += 24;
20
if (LRZ2Setup->lavaPalTimer >= 256) {
21
LRZ2Setup->lavaPalTimer -= 256;
22
23
RSDK.RotatePalette(1, 224, 227, true);
24
RSDK.RotatePalette(2, 224, 227, true);
25
RSDK.RotatePalette(3, 224, 227, true);
26
RSDK.RotatePalette(4, 224, 227, true);
27
}
28
29
// Conveyor Belt Animations
30
++LRZ2Setup->conveyorPalTimer;
31
if (LRZ2Setup->conveyorPalTimer == 128) {
32
LRZ2Setup->conveyorPalTimer = 0;
33
++LRZ2Setup->conveyorDstPal;
34
++LRZ2Setup->conveyorSrcPal;
35
36
if (LRZ2Setup->conveyorDstPal > 3)
37
LRZ2Setup->conveyorDstPal = 1;
38
39
if (LRZ2Setup->conveyorSrcPal > 3)
40
LRZ2Setup->conveyorSrcPal = 1;
41
}
42
43
RSDK.SetLimitedFade(0, LRZ2Setup->conveyorSrcPal, LRZ2Setup->conveyorDstPal, (RSDK.Cos256(LRZ2Setup->conveyorPalTimer) >> 1) + 0x80, 160, 168);
44
if (!LRZ2Setup->conveyorOff && !(Zone->timer & 1))
45
RSDK.RotatePalette(0, 228, 231, (LRZ2Setup->conveyorDir & 0xFF));
46
47
// Rock Hues
48
RSDK.SetLimitedFade(5, 1, 4, abs(RSDK.Cos1024(2 * (Zone->timer & 0x1FF)) >> 3), 224, 227);
49
RSDK.RotatePalette(3, 224, 227, true);
50
RSDK.RotatePalette(4, 224, 227, true);
51
52
RSDK.SetLimitedFade(6, 2, 4, abs(RSDK.Cos1024(2 * (Zone->timer & 0x1FF)) >> 3), 224, 227);
53
RSDK.RotatePalette(3, 224, 227, false);
54
RSDK.RotatePalette(4, 224, 227, false);
55
56
// Apply Lava Fading
57
RSDK.SetLimitedFade(0, 5, 6, LRZ2Setup->lavaPalTimer, 224, 227);
58
59
// Tile Behaviours
60
foreach_active(Player, player)
61
{
62
if (player->onGround) {
63
Hitbox *playerHitbox = Player_GetHitbox(player);
64
uint8 behaviour = LRZ2_TFLAGS_NORMAL;
65
int32 tileInfo = 0;
66
67
LRZ2Setup_GetTileInfo(player->position.x, player->position.y + (playerHitbox->bottom << 16), player->moveLayerPosition.x,
68
player->moveLayerPosition.y, player->collisionPlane, &tileInfo, &behaviour);
69
70
if (behaviour == LRZ2_TFLAGS_NORMAL) {
71
LRZ2Setup_GetTileInfo(player->position.x + (playerHitbox->right << 16), player->position.y + (playerHitbox->bottom << 16),
72
player->moveLayerPosition.x, player->moveLayerPosition.y, player->collisionPlane, &tileInfo, &behaviour);
73
}
74
75
if (behaviour == LRZ2_TFLAGS_NORMAL) {
76
LRZ2Setup_GetTileInfo(player->position.x + (playerHitbox->left << 16), player->position.y + (playerHitbox->bottom << 16),
77
player->moveLayerPosition.x, player->moveLayerPosition.y, player->collisionPlane, &tileInfo, &behaviour);
78
}
79
80
bool32 conveyorCollided = false;
81
uint8 conveyorDir = 0;
82
switch (behaviour) {
83
default: break;
84
case LRZ2_TFLAGS_LAVA: {
85
int32 solid = 1 << 14;
86
if (player->collisionPlane)
87
solid = 1 << 12;
88
89
if ((solid & tileInfo) && player->shield != SHIELD_FIRE)
90
Player_HurtFlip(player);
91
break;
92
}
93
94
case LRZ2_TFLAGS_CONVEYOR_L:
95
conveyorCollided = true;
96
conveyorDir = 0;
97
break;
98
99
case LRZ2_TFLAGS_CONVEYOR_R:
100
conveyorCollided = true;
101
conveyorDir = 1;
102
break;
103
}
104
105
if (!LRZ2Setup->conveyorOff && conveyorCollided) {
106
if (player->onGround) {
107
player->position.x += (2 * ((((tileInfo & 0x400) != 0) ^ (LRZ2Setup->conveyorDir & 0xFF)) != conveyorDir) - 1) << 17;
108
player->position.y += 0x10000;
109
}
110
}
111
}
112
}
113
}
114
115
void LRZ2Setup_Draw(void) {}
116
117
void LRZ2Setup_Create(void *data) {}
118
119
void LRZ2Setup_StageLoad(void)
120
{
121
Animals->animalTypes[0] = ANIMAL_FLICKY;
122
Animals->animalTypes[1] = ANIMAL_CUCKY;
123
124
if (!isMainGameMode() || !globals->atlEnabled || CutsceneRules_CheckStageReload()) {
125
for (int32 p = 0; p < Player->playerCount; ++p) {
126
Zone->cameraBoundsL[p] += 0x100;
127
}
128
}
129
else {
130
LRZ2Setup_HandleStageReload();
131
}
132
133
#if MANIA_USE_PLUS
134
if (SceneInfo->filter & FILTER_ENCORE) {
135
RSDK.LoadPalette(0, "EncoreLRZ2.act", 0b0000000011111111);
136
RSDK.CopyPalette(0, 128, 1, 128, 128);
137
}
138
#endif
139
140
LRZ2Setup->conveyorDstPal = 1;
141
LRZ2Setup->conveyorSrcPal = 2;
142
143
if (globals->gameMode == MODE_TIMEATTACK || globals->gameMode == MODE_COMPETITION)
144
GenericTrigger->callbacks[GENERICTRIGGER_LRZ2_OUTRO] = StateMachine_None;
145
else
146
GenericTrigger->callbacks[GENERICTRIGGER_LRZ2_OUTRO] = LRZ2Setup_Trigger_StartOutro;
147
}
148
149
void LRZ2Setup_HandleStageReload(void)
150
{
151
Vector2 pos = { 0, 0 };
152
153
foreach_all(DashLift, lift)
154
{
155
pos.x = lift->position.x;
156
pos.y = lift->position.y;
157
foreach_break;
158
}
159
160
Zone_ReloadStoredEntities(pos.x, pos.y, false);
161
162
foreach_all(Player, player)
163
{
164
player->position.x = pos.x;
165
player->position.y = pos.y - 0x100000;
166
}
167
168
CREATE_ENTITY(LRZ1Outro, NULL, 0, 0);
169
}
170
171
void LRZ2Setup_Trigger_StartOutro(void)
172
{
173
if (isMainGameMode()) {
174
EntityPlayer *player1 = RSDK_GET_ENTITY(SLOT_PLAYER1, Player);
175
176
#if MANIA_USE_PLUS
177
if (globals->gameMode == MODE_ENCORE)
178
globals->tempFlags = player1->position.y > (1024 << 16);
179
#endif
180
181
if (player1->stateInput) {
182
player1->stateInput = StateMachine_None;
183
player1->left = false;
184
player1->right = true;
185
186
for (int32 p = 0; p < Player->playerCount; ++p) StarPost->postIDs[p] = 0;
187
188
SaveGame_SavePlayerState();
189
190
globals->enableIntro = true;
191
globals->suppressAutoMusic = true;
192
globals->suppressTitlecard = true;
193
194
++SceneInfo->listPos;
195
if (!RSDK.CheckValidScene())
196
RSDK.SetScene("Presentation", "Title Screen");
197
198
Zone_StartFadeOut(10, 0x000000);
199
}
200
201
if (player1->superState == SUPERSTATE_SUPER || player1->state == Player_State_Transform)
202
globals->restartPowerups |= 0x80;
203
204
#if GAME_VERSION != VER_100
205
globals->restartMusicID = Music->activeTrack;
206
#endif
207
}
208
}
209
210
EntityButton *LRZ2Setup_SetupTagLink(int32 tag, Entity *entity)
211
{
212
// Yes..... :smirk:
213
// if (SceneInfo->inEditor)
214
// return NULL;
215
216
EntityButton *taggedButton = NULL;
217
if (tag > 0) {
218
if (Button) {
219
foreach_all(Button, button)
220
{
221
if (button->tag == tag) {
222
taggedButton = button;
223
foreach_break;
224
}
225
}
226
}
227
228
if (TurretSwitch && !taggedButton) {
229
foreach_all(TurretSwitch, turretSwitch)
230
{
231
if (turretSwitch->tag == tag) {
232
taggedButton = (EntityButton *)turretSwitch;
233
foreach_break;
234
}
235
}
236
}
237
}
238
239
if (taggedButton) {
240
if ((Button && taggedButton->classID == Button->classID) || (TurretSwitch && taggedButton->classID == TurretSwitch->classID)) {
241
if (entity) {
242
int32 distX = abs(entity->position.x - taggedButton->position.x);
243
int32 distY = abs(entity->position.y - taggedButton->position.y);
244
245
if (entity->updateRange.x < 0x800000 + distX)
246
entity->updateRange.x = 0x800000 + distX;
247
248
if (entity->updateRange.y < 0x800000 + distY)
249
entity->updateRange.y = 0x800000 + distY;
250
}
251
}
252
else {
253
taggedButton = NULL;
254
}
255
}
256
257
return taggedButton;
258
}
259
260
void LRZ2Setup_GetTileInfo(int32 x, int32 y, int32 moveOffsetX, int32 moveOffsetY, int32 cPlane, int32 *tile, uint8 *flags)
261
{
262
int32 tileLow = RSDK.GetTile(Zone->fgLayer[0], x >> 20, y >> 20);
263
int32 tileHigh = RSDK.GetTile(Zone->fgLayer[1], x >> 20, y >> 20);
264
265
int32 flagsLow = RSDK.GetTileFlags(tileLow, cPlane);
266
int32 flagsHigh = RSDK.GetTileFlags(tileHigh, cPlane);
267
268
int32 tileMove = 0;
269
int32 flagsMove = 0;
270
if (Zone->moveLayer) {
271
tileMove = RSDK.GetTile(Zone->moveLayer, (moveOffsetX + x) >> 20, (moveOffsetY + y) >> 20);
272
flagsMove = RSDK.GetTileFlags(tileMove, cPlane);
273
}
274
275
int32 tileSolidLow = 0;
276
int32 tileSolidHigh = 0;
277
int32 tileSolidMove = 0;
278
if (cPlane) {
279
tileSolidHigh = (tileHigh >> 14) & 3;
280
tileSolidLow = (tileLow >> 14) & 3;
281
}
282
else {
283
tileSolidHigh = (tileHigh >> 12) & 3;
284
tileSolidLow = (tileLow >> 12) & 3;
285
}
286
287
if (Zone->moveLayer)
288
tileSolidMove = (tileMove >> 12) & 3;
289
290
*tile = 0;
291
*flags = LRZ2_TFLAGS_NORMAL;
292
if (flagsMove && tileSolidMove) {
293
*tile = tileMove;
294
*flags = flagsMove;
295
}
296
else if (flagsHigh && tileSolidHigh) {
297
*tile = tileHigh;
298
*flags = flagsHigh;
299
}
300
else if (flagsLow && tileSolidLow) {
301
*tile = tileLow;
302
*flags = flagsLow;
303
}
304
}
305
306
#if GAME_INCLUDE_EDITOR
307
void LRZ2Setup_EditorDraw(void) {}
308
309
void LRZ2Setup_EditorLoad(void)
310
{
311
RSDK_ACTIVE_VAR(GenericTrigger, triggerID);
312
RSDK_ENUM_VAR("LRZ2 Outro", GENERICTRIGGER_LRZ2_OUTRO);
313
}
314
#endif
315
316
void LRZ2Setup_Serialize(void) {}
317
318