Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/CPZ/CPZSetup.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: CPZSetup Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectCPZSetup *CPZSetup;
11
12
void CPZSetup_Update(void) {}
13
14
void CPZSetup_LateUpdate(void) {}
15
16
void CPZSetup_StaticUpdate(void)
17
{
18
// Animate the converyor belt thingys in the background
19
if (!(Zone->timer & 3)) {
20
--CPZSetup->aniTileFrame;
21
CPZSetup->aniTileFrame &= 0xF;
22
RSDK.DrawAniTiles(CPZSetup->aniTiles, 762, 109, CPZSetup->aniTileFrame + 48, 16, 16);
23
}
24
25
if (!(Zone->timer & 7)) {
26
++CPZSetup->background->deformationOffset;
27
28
++CPZSetup->bgTowerLightPalIndex;
29
CPZSetup->bgTowerLightPalIndex &= 15;
30
RSDK.SetPaletteEntry(0, 159, RSDK.GetPaletteEntry(3, CPZSetup->bgTowerLightPalIndex));
31
32
++CPZSetup->rainbowLightPalIndex;
33
CPZSetup->rainbowLightPalIndex %= 21;
34
RSDK.SetPaletteEntry(0, 158, RSDK.GetPaletteEntry(3, CPZSetup->rainbowLightPalIndex + 16));
35
36
CPZSetup->chemLiquidPalIndex1 += 3;
37
CPZSetup->chemLiquidPalIndex1 %= 27;
38
RSDK.SetPaletteEntry(0, 141, RSDK.GetPaletteEntry(3, CPZSetup->chemLiquidPalIndex1 + 48));
39
40
CPZSetup->chemLiquidPalIndex2 += 3;
41
CPZSetup->chemLiquidPalIndex2 %= 27;
42
RSDK.SetPaletteEntry(0, 142, RSDK.GetPaletteEntry(3, CPZSetup->chemLiquidPalIndex2 + 48));
43
44
CPZSetup->chemLiquidPalIndex3 += 3;
45
CPZSetup->chemLiquidPalIndex3 %= 27;
46
RSDK.SetPaletteEntry(0, 143, RSDK.GetPaletteEntry(3, CPZSetup->chemLiquidPalIndex3 + 48));
47
}
48
}
49
50
void CPZSetup_Draw(void) {}
51
52
void CPZSetup_Create(void *data) {}
53
54
void CPZSetup_StageLoad(void)
55
{
56
CPZSetup->aniTiles = RSDK.LoadSpriteSheet("CPZ/Objects.gif", SCOPE_STAGE);
57
58
RSDK.SetDrawGroupProperties(0, 0, Water_DrawHook_ApplyWaterPalette);
59
RSDK.SetDrawGroupProperties(Zone->hudDrawGroup, 0, Water_DrawHook_RemoveWaterPalette);
60
Water->waterPalette = 2;
61
62
CPZSetup->chemLiquidPalIndex1 = 0;
63
CPZSetup->chemLiquidPalIndex2 = 1;
64
CPZSetup->chemLiquidPalIndex3 = 2;
65
66
CPZSetup->background = RSDK.GetTileLayer(0);
67
for (int32 i = 0; i < 0x400; ++i) {
68
CPZSetup->background->deformationData[i] = CPZSetup->deformation[i & 0x3F];
69
}
70
71
#if MANIA_USE_PLUS
72
if (SceneInfo->filter & FILTER_ENCORE) {
73
RSDK.LoadPalette(0, "EncoreCPZ.act", 0b0000000011111111);
74
RSDK.LoadPalette(2, "EncoreCPZw.act", 0b0000000011111111);
75
RSDK.CopyPalette(0, 128, 1, 0, 10);
76
}
77
#endif
78
79
Animals->animalTypes[0] = ANIMAL_LOCKY;
80
Animals->animalTypes[1] = ANIMAL_POCKY;
81
82
if (Zone->actID) {
83
RSDK.SetPaletteMask(0x00F000);
84
RSDK.SetPaletteEntry(0, 0xFF, 0x00F000);
85
86
BGSwitch->switchCallback[CPZ_BG_CPZ2] = CPZSetup_BGSwitch_Act2BG;
87
BGSwitch->switchCallback[CPZ_BG_CPZ1] = CPZSetup_BGSwitch_Act1BG;
88
89
BGSwitch->layerIDs[0] = CPZ_BG_CPZ1;
90
BGSwitch->layerIDs[1] = CPZ_BG_CPZ1;
91
BGSwitch->layerIDs[2] = CPZ_BG_CPZ1;
92
BGSwitch->layerIDs[3] = CPZ_BG_CPZ1;
93
94
bool32 setCPZ1BG = false;
95
if (!CutsceneRules_CheckStageReload() && CutsceneRules_CheckPlayerPos(TO_FIXED(172), TO_FIXED(6288), TO_FIXED(598), TO_FIXED(6528))) {
96
setCPZ1BG = true;
97
98
Zone->cameraBoundsB[0] = 6528;
99
Zone->cameraBoundsB[1] = 6528;
100
Zone->cameraBoundsB[2] = 6528;
101
Zone->cameraBoundsB[3] = 6528;
102
}
103
104
if (isMainGameMode() && globals->atlEnabled) {
105
if (!CutsceneRules_CheckStageReload())
106
Zone_ReloadStoredEntities(TO_FIXED(384), TO_FIXED(6528), true);
107
}
108
109
if (isMainGameMode() && CutsceneRules_IsAct2()) {
110
foreach_all(CPZ2Outro, outro)
111
{
112
CPZSetup->outro = outro;
113
Zone->stageFinishCallback = CPZSetup_StageFinish_EndAct2;
114
foreach_break;
115
}
116
}
117
118
BGSwitch->screenID = 0;
119
if (setCPZ1BG) {
120
for (; BGSwitch->screenID < RSDK.GetVideoSetting(VIDEOSETTING_SCREENCOUNT); BGSwitch->screenID++) CPZSetup_BGSwitch_Act1BG();
121
122
BGSwitch->layerIDs[0] = CPZ_BG_CPZ1;
123
BGSwitch->layerIDs[1] = CPZ_BG_CPZ1;
124
BGSwitch->layerIDs[2] = CPZ_BG_CPZ1;
125
BGSwitch->layerIDs[3] = CPZ_BG_CPZ1;
126
127
TileLayer *backgroundAct1 = RSDK.GetTileLayer(3);
128
129
backgroundAct1->scrollPos += -0x118000 * backgroundAct1->parallaxFactor;
130
for (int32 i = 0; i < backgroundAct1->scrollInfoCount; ++i)
131
backgroundAct1->scrollInfo[i].scrollPos += TO_FIXED(71) * backgroundAct1->scrollInfo[i].parallaxFactor;
132
}
133
else {
134
for (; BGSwitch->screenID < RSDK.GetVideoSetting(VIDEOSETTING_SCREENCOUNT); BGSwitch->screenID++) CPZSetup_BGSwitch_Act2BG();
135
136
BGSwitch->layerIDs[0] = CPZ_BG_CPZ2;
137
BGSwitch->layerIDs[1] = CPZ_BG_CPZ2;
138
BGSwitch->layerIDs[2] = CPZ_BG_CPZ2;
139
BGSwitch->layerIDs[3] = CPZ_BG_CPZ2;
140
}
141
}
142
else {
143
if (isMainGameMode()) {
144
if (globals->enableIntro) {
145
if (!CutsceneRules_CheckStageReload()) {
146
globals->suppressAutoMusic = true;
147
globals->suppressTitlecard = true;
148
}
149
}
150
}
151
152
if (isMainGameMode()) {
153
if (CutsceneRules_IsAct1())
154
Zone->stageFinishCallback = CPZSetup_StageFinish_EndAct1;
155
}
156
157
RSDK.SetPaletteEntry(0, 0xFF, 0xF0F0F0);
158
RSDK.SetPaletteEntry(2, 0xFF, RSDK.GetPaletteEntry(2, 137));
159
}
160
}
161
162
void CPZSetup_BGSwitch_Act2BG(void)
163
{
164
RSDK.GetTileLayer(0)->drawGroup[BGSwitch->screenID] = 0;
165
RSDK.GetTileLayer(1)->drawGroup[BGSwitch->screenID] = 0;
166
RSDK.GetTileLayer(2)->drawGroup[BGSwitch->screenID] = 0;
167
RSDK.GetTileLayer(3)->drawGroup[BGSwitch->screenID] = DRAWGROUP_COUNT;
168
}
169
170
void CPZSetup_BGSwitch_Act1BG(void)
171
{
172
RSDK.GetTileLayer(0)->drawGroup[BGSwitch->screenID] = DRAWGROUP_COUNT;
173
RSDK.GetTileLayer(1)->drawGroup[BGSwitch->screenID] = DRAWGROUP_COUNT;
174
RSDK.GetTileLayer(2)->drawGroup[BGSwitch->screenID] = DRAWGROUP_COUNT;
175
RSDK.GetTileLayer(3)->drawGroup[BGSwitch->screenID] = 0;
176
}
177
178
void CPZSetup_StageFinish_EndAct1(void)
179
{
180
RSDK.GetTileLayer(0);
181
Zone_StoreEntities(TO_FIXED(ScreenInfo->position.x + ScreenInfo->center.x), TO_FIXED(ScreenInfo->size.y + ScreenInfo->position.y));
182
RSDK.LoadScene();
183
}
184
185
void CPZSetup_StageFinish_EndAct2(void) { CPZSetup->outro->active = ACTIVE_NORMAL; }
186
187
#if GAME_INCLUDE_EDITOR
188
void CPZSetup_EditorDraw(void) {}
189
190
void CPZSetup_EditorLoad(void)
191
{
192
RSDK_ACTIVE_VAR(BGSwitch, bgID);
193
RSDK_ENUM_VAR("Act 2 BG", CPZ_BG_CPZ2);
194
RSDK_ENUM_VAR("Act 1 BG", CPZ_BG_CPZ1);
195
196
RSDK_ACTIVE_VAR(Decoration, type);
197
RSDK_ENUM_VAR("Warning Sign", CPZ_DECORATION_WARNSIGN);
198
199
RSDK_ACTIVE_VAR(ParallaxSprite, aniID);
200
RSDK_ENUM_VAR("Girder", CPZ_PARALLAXSPRITE_GIRDER);
201
RSDK_ENUM_VAR("Chemical 1", CPZ_PARALLAXSPRITE_CHEMICAL1);
202
RSDK_ENUM_VAR("Chemical 2", CPZ_PARALLAXSPRITE_CHEMICAL2);
203
}
204
#endif
205
206
void CPZSetup_Serialize(void) {}
207
208