Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/FBZ/FBZSetup.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: FBZSetup Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectFBZSetup *FBZSetup;
11
12
void FBZSetup_Update(void) {}
13
14
void FBZSetup_LateUpdate(void) {}
15
16
void FBZSetup_StaticUpdate(void)
17
{
18
if (!(Zone->timer & 1)) {
19
++FBZSetup->cylinderAniFrame;
20
FBZSetup->cylinderAniFrame &= 7;
21
22
if (Zone->actID == 1) // Cylinder H (left cylinder on the sheet)
23
RSDK.DrawAniTiles(FBZSetup->aniTiles, 381, 0, 16 * FBZSetup->cylinderAniFrame, 256, 16);
24
25
// Cylinder V (right cylinder on the sheet)
26
RSDK.DrawAniTiles(FBZSetup->aniTiles, 401, 16 * (FBZSetup->cylinderAniFrame + 16), 0, 16, 126);
27
}
28
29
if (!(Zone->timer & 3)) {
30
++FBZSetup->propellerShaftAniFrameUnused;
31
FBZSetup->propellerShaftAniFrameUnused &= 3;
32
33
++FBZSetup->propellerShaftAniFrame;
34
FBZSetup->propellerShaftAniFrame &= 7;
35
36
++FBZSetup->spiralPlatformAniFrame;
37
FBZSetup->spiralPlatformAniFrame %= 6;
38
39
// Propeller Shaft AniTiles (unused?, these don't match propellers, just some clouds)
40
RSDK.DrawAniTiles(FBZSetup->aniTiles, 377, 16 * (FBZSetup->propellerShaftAniFrameUnused + 24), 16, 16, 32);
41
42
// Propeller Shaft AniTiles
43
RSDK.DrawAniTiles(FBZSetup->aniTiles, 379, 16 * (FBZSetup->propellerShaftAniFrame + 24), 0, 16, 32);
44
45
// Spiral Platform AniTiles (unused in-game)
46
RSDK.DrawAniTiles(FBZSetup->aniTiles, 397, 384, 16 * (FBZSetup->spiralPlatformAniFrame + 2), 64, 16);
47
}
48
49
RSDK.GetTileLayer(FBZSetup->backgroundOutside)->scrollPos = (RSDK.Sin512(Zone->persistentTimer) + 512) << 10;
50
}
51
52
void FBZSetup_Draw(void) {}
53
54
void FBZSetup_Create(void *data) {}
55
56
void FBZSetup_StageLoad(void)
57
{
58
FBZSetup->aniTiles = RSDK.LoadSpriteSheet("FBZ/AniTiles.gif", SCOPE_STAGE);
59
60
FBZSetup->backgroundOutside = RSDK.GetTileLayerID("Background Outside");
61
62
Animals->animalTypes[0] = ANIMAL_FLICKY;
63
Animals->animalTypes[1] = ANIMAL_RICKY;
64
65
BGSwitch->switchCallback[FBZ_BG_INSIDE1] = FBZSetup_BGSwitch_ShowInside1;
66
BGSwitch->switchCallback[FBZ_BG_INSIDE2] = FBZSetup_BGSwitch_ShowInside2;
67
BGSwitch->switchCallback[FBZ_BG_INSIDE1_NOSTORM] = FBZSetup_BGSwitch_ShowInside1_NoStorm;
68
69
TileLayer *backgroundInside = RSDK.GetTileLayer(0);
70
backgroundInside->drawGroup[0] = 0;
71
backgroundInside->drawGroup[1] = 0;
72
backgroundInside->drawGroup[2] = 0;
73
backgroundInside->drawGroup[3] = 0;
74
if (!Zone->actID)
75
backgroundInside->scanlineCallback = FBZSetup_Scanline_BGInside;
76
77
int32 ang = -336;
78
int32 scanlineY = 0;
79
for (int32 i = 0; i < 0x400; ++i) {
80
FBZSetup->scanlineDeformX[i] = 32 * (abs(RSDK.Sin1024(ang >> 1)) + 0x400);
81
FBZSetup->positionYMove[i] = 32 * (abs(RSDK.Cos1024(ang >> 1)) + 0x800);
82
83
FBZSetup->scanlinePosY[i] = scanlineY & 0x1FF0000;
84
ang += 3;
85
scanlineY += FBZSetup->positionYMove[i];
86
}
87
88
// Yeah, this is actually here in the original
89
// This (& the one in MSZSpotlight) is how I found out about what these funcs do LOL
90
RSDK_ACTIVE_VAR(GenericTrigger, triggerID);
91
RSDK_ENUM_VAR("Show Exterior", FBZ_GENERICTRIGGER_EXTERIOR);
92
RSDK_ENUM_VAR("Show Interior", FBZ_GENERICTRIGGER_INTERIOR);
93
94
GenericTrigger->callbacks[FBZ_GENERICTRIGGER_EXTERIOR] = FBZSetup_Trigger_ShowExterior;
95
GenericTrigger->callbacks[FBZ_GENERICTRIGGER_INTERIOR] = FBZSetup_Trigger_ShowInterior;
96
97
if (globals->gameMode == MODE_COMPETITION) {
98
foreach_all(ParallaxSprite, parallaxSprite) { destroyEntity(parallaxSprite); }
99
}
100
101
if (isMainGameMode() && CutsceneRules_IsAct1()) {
102
foreach_all(FBZ1Outro, outro)
103
{
104
Zone->shouldRecoverPlayers = true;
105
FBZSetup->outro = outro;
106
foreach_break;
107
}
108
Zone->stageFinishCallback = FBZSetup_StageFinish_EndAct1;
109
}
110
111
if (isMainGameMode() && globals->atlEnabled && !CutsceneRules_CheckStageReload()) {
112
FBZSetup_ActTransitionLoad();
113
}
114
115
#if MANIA_USE_PLUS
116
if (isMainGameMode() && CutsceneRules_IsAct2())
117
Zone->stageFinishCallback = FBZSetup_StageFinish_EndAct2;
118
119
if ((SceneInfo->filter & FILTER_ENCORE)) {
120
RSDK.LoadPalette(0, "EncoreFBZ.act", 0b0000000011111111);
121
RSDK.CopyPalette(0, 1, 1, 1, 0b0000000011111111);
122
RSDK.LoadPalette(2, "EncoreFBZs.act", 0b0000000011111111);
123
RSDK.LoadPalette(3, "EncoreFBZf.act", 0b0000000011111111);
124
RSDK.LoadPalette(4, "EncoreFBZi.act", 0b0000000011111111);
125
}
126
#endif
127
}
128
129
void FBZSetup_ActTransitionLoad(void)
130
{
131
Zone_ReloadStoredEntities(WIDE_SCR_XCENTER << 16, 4324 << 16, false);
132
Zone->cameraBoundsL[0] = 0;
133
Zone->cameraBoundsB[0] = 4324;
134
Zone->cameraBoundsL[1] = 0;
135
Zone->cameraBoundsB[1] = 4324;
136
Zone->cameraBoundsL[2] = 0;
137
Zone->cameraBoundsB[2] = 4324;
138
Zone->cameraBoundsL[3] = 0;
139
Zone->cameraBoundsB[3] = 4324;
140
141
int32 id = 0;
142
TileLayer *layer = RSDK.GetTileLayer(2);
143
for (int32 i = 0; i < layer->scrollInfoCount; ++i) {
144
layer->scrollInfo[i].scrollPos = globals->parallaxOffset[id++];
145
}
146
147
foreach_all(ParallaxSprite, parallaxSprite) { parallaxSprite->scrollPos.x = globals->parallaxOffset[id++]; }
148
}
149
150
void FBZSetup_AddDynamicBG(ScanlineInfo *scanlines, int32 parallaxFactorX, int32 parallaxFactorY, int32 startLine, int32 lineCount, int32 sourcePosY)
151
{
152
RSDKScreenInfo *screen = &ScreenInfo[SceneInfo->currentScreenID];
153
154
int32 scanlineX = (parallaxFactorX * screen->position.x) << 8;
155
int32 screenY = (parallaxFactorY * screen->position.y) >> 8;
156
157
int32 start = startLine - screenY;
158
int32 end = start + lineCount;
159
160
if (start < SCREEN_YSIZE && end > 0) {
161
end = MIN(end, SCREEN_YSIZE);
162
163
// sourcePosY = start layer line
164
int32 scanlineY = sourcePosY;
165
if (start < 0) {
166
scanlineY = sourcePosY - (start << 16);
167
start = 0;
168
}
169
170
ScanlineInfo *scanlinePtr = &scanlines[start];
171
int32 count = end - start;
172
for (int32 i = 0; i < count; ++i) {
173
scanlinePtr->position.x = scanlineX;
174
scanlinePtr->position.y = scanlineY;
175
scanlinePtr->deform.x = 0x10000;
176
177
++scanlinePtr;
178
scanlineY += 0x10000;
179
}
180
}
181
}
182
183
void FBZSetup_Scanline_BGInside(ScanlineInfo *scanlines)
184
{
185
RSDKScreenInfo *screen = &ScreenInfo[SceneInfo->currentScreenID];
186
int32 y = screen->position.y >> 3;
187
188
// Handle the cool deformation on the BG Inside layer
189
ScanlineInfo *scanlinePtr = scanlines;
190
for (int32 i = 0; i < SCREEN_YSIZE; ++i) {
191
int32 pos = (i + y) & 0x3FF;
192
scanlinePtr->deform.x = FBZSetup->scanlineDeformX[pos];
193
scanlinePtr->deform.y = 0;
194
scanlinePtr->position.x = ((screen->position.x << 14) - FBZSetup->scanlineDeformX[pos] * screen->center.x) & 0xFFFF8000;
195
scanlinePtr->position.y = FBZSetup->scanlinePosY[pos];
196
++scanlinePtr;
197
}
198
199
// Add Other bits of the layer to overlay so it's not so barren
200
FBZSetup_AddDynamicBG(scanlines, 128, 32, 0, 112, 576 << 16);
201
FBZSetup_AddDynamicBG(scanlines, 128, 32, 456, 128, 512 << 16);
202
FBZSetup_AddDynamicBG(scanlines, 112, 64, 420, 16, 816 << 16);
203
FBZSetup_AddDynamicBG(scanlines, 144, 80, 640, 48, 768 << 16);
204
FBZSetup_AddDynamicBG(scanlines, 160, 96, 512, 64, 704 << 16);
205
}
206
207
void FBZSetup_BGSwitch_ShowInside1(void)
208
{
209
RSDK.GetTileLayer(0)->drawGroup[BGSwitch->screenID] = DRAWGROUP_COUNT;
210
211
if (Zone->actID == 1) {
212
RSDK.GetTileLayer(1)->drawGroup[BGSwitch->screenID] = DRAWGROUP_COUNT;
213
RSDK.GetTileLayer(3)->drawGroup[BGSwitch->screenID] = 0;
214
}
215
else {
216
RSDK.GetTileLayer(1)->drawGroup[BGSwitch->screenID] = 0;
217
}
218
}
219
220
void FBZSetup_BGSwitch_ShowInside2(void)
221
{
222
RSDK.GetTileLayer(0)->drawGroup[BGSwitch->screenID] = 0;
223
224
if (Zone->actID == 1) {
225
RSDK.GetTileLayer(1)->drawGroup[BGSwitch->screenID] = 0;
226
RSDK.GetTileLayer(2)->drawGroup[BGSwitch->screenID] = DRAWGROUP_COUNT;
227
RSDK.GetTileLayer(3)->drawGroup[BGSwitch->screenID] = DRAWGROUP_COUNT;
228
}
229
else {
230
RSDK.GetTileLayer(1)->drawGroup[BGSwitch->screenID] = DRAWGROUP_COUNT;
231
}
232
}
233
234
void FBZSetup_BGSwitch_ShowInside1_NoStorm(void)
235
{
236
RSDK.GetTileLayer(0)->drawGroup[BGSwitch->screenID] = DRAWGROUP_COUNT;
237
238
if (Zone->actID == 1) {
239
RSDK.GetTileLayer(1)->drawGroup[BGSwitch->screenID] = DRAWGROUP_COUNT;
240
RSDK.GetTileLayer(2)->drawGroup[BGSwitch->screenID] = 0;
241
}
242
else {
243
RSDK.GetTileLayer(1)->drawGroup[BGSwitch->screenID] = 0;
244
}
245
}
246
247
void FBZSetup_Trigger_ShowExterior(void)
248
{
249
int32 id = (2 * (Zone->actID != 0) + 3);
250
RSDK.GetTileLayer(id)->drawGroup[GenericTrigger->playerID] = DRAWGROUP_COUNT;
251
RSDK.GetTileLayer(id + 1)->drawGroup[GenericTrigger->playerID] = 6;
252
253
foreach_active(ParallaxSprite, parallaxSprite)
254
{
255
if (!parallaxSprite->visible) {
256
parallaxSprite->visible = true;
257
parallaxSprite->state = ParallaxSprite_State_FadeIntoHalf;
258
}
259
}
260
}
261
262
void FBZSetup_Trigger_ShowInterior(void)
263
{
264
int32 id = (2 * (Zone->actID != 0) + 3);
265
RSDK.GetTileLayer(id)->drawGroup[GenericTrigger->playerID] = 6;
266
RSDK.GetTileLayer(id + 1)->drawGroup[GenericTrigger->playerID] = DRAWGROUP_COUNT;
267
268
foreach_active(ParallaxSprite, parallaxSprite) { parallaxSprite->state = ParallaxSprite_State_FadeOut; }
269
}
270
271
void FBZSetup_StageFinish_EndAct1(void) { FBZSetup->outro->active = ACTIVE_NORMAL; }
272
#if MANIA_USE_PLUS
273
void FBZSetup_StageFinish_EndAct2(void) { CREATE_ENTITY(FBZ2Outro, NULL, 0, 0); }
274
#endif
275
276
#if GAME_INCLUDE_EDITOR
277
void FBZSetup_EditorDraw(void) {}
278
279
void FBZSetup_EditorLoad(void)
280
{
281
RSDK_ACTIVE_VAR(GenericTrigger, triggerID);
282
RSDK_ENUM_VAR("Show Exterior", FBZ_GENERICTRIGGER_EXTERIOR);
283
RSDK_ENUM_VAR("Show Interior", FBZ_GENERICTRIGGER_INTERIOR);
284
285
RSDK_ACTIVE_VAR(BGSwitch, bgID);
286
RSDK_ENUM_VAR("Show Inside 1", FBZ_BG_INSIDE1);
287
RSDK_ENUM_VAR("Show Inside 2", FBZ_BG_INSIDE2);
288
RSDK_ENUM_VAR("Show Inside 1 (No Storm)", FBZ_BG_INSIDE1_NOSTORM);
289
290
RSDK_ACTIVE_VAR(Decoration, type);
291
RSDK_ENUM_VAR("Blueprint 1", FBZ_DECORATION_BLUEPRINT1);
292
RSDK_ENUM_VAR("Blueprint 2", FBZ_DECORATION_BLUEPRINT2);
293
294
RSDK_ACTIVE_VAR(ParallaxSprite, aniID);
295
RSDK_ENUM_VAR("Clouds", FBZ_PARALLAXSPRITE_CLOUDS);
296
}
297
#endif
298
299
void FBZSetup_Serialize(void) {}
300
301