Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/GHZ/GHZSetup.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: GHZSetup Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectGHZSetup *GHZSetup;
11
12
void GHZSetup_Update(void) {}
13
14
void GHZSetup_LateUpdate(void) {}
15
16
void GHZSetup_StaticUpdate(void)
17
{
18
GHZSetup->paletteTimer += 42;
19
if (GHZSetup->paletteTimer >= 0x100) {
20
GHZSetup->paletteTimer -= 0x100;
21
RSDK.RotatePalette(1, 181, 184, true);
22
RSDK.RotatePalette(2, 181, 184, true);
23
RSDK.RotatePalette(1, 197, 200, true);
24
RSDK.RotatePalette(2, 197, 200, true);
25
}
26
RSDK.SetLimitedFade(0, 1, 2, GHZSetup->paletteTimer, 181, 184);
27
RSDK.SetLimitedFade(0, 1, 2, GHZSetup->paletteTimer, 197, 200);
28
29
--GHZSetup->sunFlowerTimer;
30
if (GHZSetup->sunFlowerTimer < 1) {
31
++GHZSetup->sunFlowerFrame;
32
GHZSetup->sunFlowerFrame &= 7;
33
GHZSetup->sunFlowerTimer = GHZSetup->sunFlowerDurationTable[GHZSetup->sunFlowerFrame];
34
RSDK.DrawAniTiles(GHZSetup->aniTiles, 427, 0, 32 * GHZSetup->sunFlowerFrame, 32, 32);
35
}
36
37
--GHZSetup->extendFlowerTimer;
38
if (GHZSetup->extendFlowerTimer < 1) {
39
++GHZSetup->extendFlowerFrame;
40
GHZSetup->extendFlowerFrame &= 0xF;
41
GHZSetup->extendFlowerTimer = GHZSetup->extendFlowerDurationTable[GHZSetup->extendFlowerFrame];
42
RSDK.DrawAniTiles(GHZSetup->aniTiles, 431, 0, 48 * GHZSetup->extendFlowerFrame + 256, 32, 48);
43
}
44
}
45
46
void GHZSetup_Draw(void) {}
47
48
void GHZSetup_Create(void *data) {}
49
50
void GHZSetup_StageLoad(void)
51
{
52
GHZSetup->aniTiles = RSDK.LoadSpriteSheet("GHZ/AniTiles.gif", SCOPE_STAGE);
53
54
Animals->animalTypes[0] = ANIMAL_FLICKY;
55
Animals->animalTypes[1] = ANIMAL_POCKY;
56
57
if (Zone->actID) {
58
BGSwitch->switchCallback[GHZ_BG_OUTSIDE] = GHZSetup_BGSwitch_Outside_Act2;
59
BGSwitch->switchCallback[GHZ_BG_CAVES] = GHZSetup_BGSwitch_Caves_Act2;
60
61
BGSwitch->layerIDs[0] = GHZ_BG_OUTSIDE;
62
BGSwitch->layerIDs[1] = GHZ_BG_OUTSIDE;
63
BGSwitch->layerIDs[2] = GHZ_BG_OUTSIDE;
64
BGSwitch->layerIDs[3] = GHZ_BG_OUTSIDE;
65
66
if (isMainGameMode() && globals->atlEnabled) {
67
if (!CutsceneRules_CheckStageReload())
68
GHZSetup_HandleActTransition();
69
}
70
71
if (isMainGameMode() && CutsceneRules_IsAct2())
72
Zone->stageFinishCallback = GHZSetup_StageFinish_EndAct2;
73
}
74
else {
75
TileLayer *backgroundOutside = RSDK.GetTileLayer(0);
76
backgroundOutside->scrollPos = 0x180000;
77
backgroundOutside->parallaxFactor = -backgroundOutside->parallaxFactor;
78
79
BGSwitch->switchCallback[GHZ_BG_OUTSIDE] = GHZSetup_BGSwitch_Outside_Act1;
80
BGSwitch->switchCallback[GHZ_BG_CAVES] = GHZSetup_BGSwitch_Caves_Act1;
81
82
if (!isMainGameMode() || !globals->atlEnabled || CutsceneRules_CheckStageReload()) {
83
BGSwitch->layerIDs[0] = GHZ_BG_OUTSIDE;
84
BGSwitch->layerIDs[1] = GHZ_BG_OUTSIDE;
85
BGSwitch->layerIDs[2] = GHZ_BG_OUTSIDE;
86
BGSwitch->layerIDs[3] = GHZ_BG_OUTSIDE;
87
}
88
else {
89
GHZSetup_SetupAct1BG();
90
}
91
92
if (isMainGameMode() && CutsceneRules_IsAct1())
93
Zone->stageFinishCallback = GHZSetup_StageFinish_EndAct1;
94
}
95
96
#if MANIA_USE_PLUS
97
if (SceneInfo->filter & FILTER_ENCORE || (RSDK.CheckSceneFolder("GHZCutscene") && globals->gameMode == MODE_ENCORE)) {
98
RSDK.LoadPalette(0, "EncoreGHZ.act", 0b0000000011111111);
99
RSDK.CopyPalette(0, 128, 1, 128, 80);
100
RSDK.CopyPalette(0, 128, 2, 128, 80);
101
RSDK.RotatePalette(2, 181, 184, true);
102
RSDK.RotatePalette(2, 197, 200, true);
103
104
if (Water) {
105
foreach_all(Water, water)
106
{
107
water->r = 0xA0;
108
water->g = 0xA0;
109
water->b = 0xE0;
110
}
111
}
112
}
113
#endif
114
}
115
116
void GHZSetup_SetupAct1BG(void)
117
{
118
if (CHECK_CHARACTER_ID(ID_KNUCKLES, 1)) {
119
BGSwitch->layerIDs[0] = GHZ_BG_CAVES;
120
BGSwitch->layerIDs[1] = GHZ_BG_CAVES;
121
BGSwitch->layerIDs[2] = GHZ_BG_CAVES;
122
BGSwitch->layerIDs[3] = GHZ_BG_CAVES;
123
124
for (BGSwitch->screenID = 0; BGSwitch->screenID < RSDK.GetVideoSetting(VIDEOSETTING_SCREENCOUNT); ++BGSwitch->screenID) {
125
GHZSetup_BGSwitch_Caves_Act2();
126
}
127
Zone_ReloadStoredEntities(WIDE_SCR_XCENTER << 16, 1724 << 16, true);
128
}
129
else {
130
Zone_ReloadStoredEntities(WIDE_SCR_XCENTER << 16, 1004 << 16, true);
131
TileLayer *outsideLayer = RSDK.GetTileLayer(RSDK.GetTileLayerID("BG Outside"));
132
EntityPlayer *player = RSDK_GET_ENTITY(SLOT_PLAYER1, Player);
133
134
player->onGround = true;
135
player->state = Player_State_Ground;
136
for (int32 s = 0; s < outsideLayer->scrollInfoCount; ++s) {
137
outsideLayer->scrollInfo[s].scrollPos += globals->parallaxOffset[0] * outsideLayer->scrollInfo[s].scrollSpeed;
138
}
139
}
140
}
141
void GHZSetup_StageFinish_EndAct1(void)
142
{
143
Zone_StoreEntities(15792 << 16, 1588 << 16);
144
RSDK.LoadScene();
145
}
146
void GHZSetup_HandleActTransition(void)
147
{
148
Zone->cameraBoundsL[0] = 256 - ScreenInfo->center.x;
149
Zone->cameraBoundsB[0] = 1412;
150
151
Zone_ReloadStoredEntities(256 << 16, 1412 << 16, true);
152
153
TileLayer *bgCave1 = RSDK.GetTileLayer(2);
154
bgCave1->scrollPos += 0xB000 * bgCave1->parallaxFactor;
155
for (int32 s = 0; s < bgCave1->scrollInfoCount; ++s) {
156
bgCave1->scrollInfo[s].scrollPos += 0x3CB000 * bgCave1->scrollInfo[s].parallaxFactor;
157
}
158
159
TileLayer *bgCave2 = RSDK.GetTileLayer(3);
160
bgCave2->scrollPos += 0xB000 * bgCave2->parallaxFactor;
161
for (int32 s = 0; s < bgCave2->scrollInfoCount; ++s) {
162
bgCave2->scrollInfo[s].scrollPos += 0x3CB000 * bgCave2->scrollInfo[s].parallaxFactor;
163
}
164
165
for (BGSwitch->screenID = 0; BGSwitch->screenID < RSDK.GetVideoSetting(VIDEOSETTING_SCREENCOUNT); ++BGSwitch->screenID) {
166
GHZSetup_BGSwitch_Caves_Act2();
167
}
168
}
169
void GHZSetup_BGSwitch_Outside_Act2(void)
170
{
171
RSDK.GetTileLayer(0)->drawGroup[BGSwitch->screenID] = 0;
172
RSDK.GetTileLayer(1)->drawGroup[BGSwitch->screenID] = 0;
173
RSDK.GetTileLayer(2)->drawGroup[BGSwitch->screenID] = DRAWGROUP_COUNT;
174
RSDK.GetTileLayer(3)->drawGroup[BGSwitch->screenID] = DRAWGROUP_COUNT;
175
}
176
void GHZSetup_BGSwitch_Caves_Act2(void)
177
{
178
RSDK.GetTileLayer(0)->drawGroup[BGSwitch->screenID] = DRAWGROUP_COUNT;
179
RSDK.GetTileLayer(1)->drawGroup[BGSwitch->screenID] = DRAWGROUP_COUNT;
180
RSDK.GetTileLayer(2)->drawGroup[BGSwitch->screenID] = 0;
181
RSDK.GetTileLayer(3)->drawGroup[BGSwitch->screenID] = 0;
182
}
183
void GHZSetup_BGSwitch_Outside_Act1(void)
184
{
185
RSDK.GetTileLayer(0)->drawGroup[BGSwitch->screenID] = 0;
186
RSDK.GetTileLayer(1)->drawGroup[BGSwitch->screenID] = DRAWGROUP_COUNT;
187
RSDK.GetTileLayer(2)->drawGroup[BGSwitch->screenID] = DRAWGROUP_COUNT;
188
}
189
void GHZSetup_BGSwitch_Caves_Act1(void)
190
{
191
RSDK.GetTileLayer(0)->drawGroup[BGSwitch->screenID] = DRAWGROUP_COUNT;
192
RSDK.GetTileLayer(1)->drawGroup[BGSwitch->screenID] = 0;
193
RSDK.GetTileLayer(2)->drawGroup[BGSwitch->screenID] = 0;
194
}
195
void GHZSetup_StageFinish_EndAct2(void) { CREATE_ENTITY(GHZ2Outro, INT_TO_VOID(true), 0, 0); }
196
197
#if GAME_INCLUDE_EDITOR
198
void GHZSetup_EditorDraw(void) {}
199
200
void GHZSetup_EditorLoad(void)
201
{
202
RSDK_ACTIVE_VAR(BGSwitch, bgID);
203
RSDK_ENUM_VAR("Outside BG", GHZ_BG_OUTSIDE);
204
RSDK_ENUM_VAR("Caves BG", GHZ_BG_CAVES);
205
206
RSDK_ACTIVE_VAR(Decoration, type);
207
RSDK_ENUM_VAR("Bridge Post", GHZ_DECORATION_BRIDGEPOST);
208
}
209
#endif
210
211
void GHZSetup_Serialize(void) {}
212
213