Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rubberduckycooly
GitHub Repository: rubberduckycooly/Sonic-Mania-Decompilation
Path: blob/master/SonicMania/Objects/Helpers/CompetitionSession.c
338 views
1
// ---------------------------------------------------------------------
2
// RSDK Project: Sonic Mania
3
// Object Description: CompetitionSession Object
4
// Object Author: Christian Whitehead/Simon Thomley/Hunter Bridges
5
// Decompiled by: Rubberduckycooly & RMGRich
6
// ---------------------------------------------------------------------
7
8
#include "Game.h"
9
10
ObjectCompetitionSession *CompetitionSession = NULL;
11
12
void CompetitionSession_Update(void) {}
13
14
void CompetitionSession_LateUpdate(void) {}
15
16
void CompetitionSession_StaticUpdate(void) {}
17
18
void CompetitionSession_Draw(void) {}
19
20
void CompetitionSession_Create(void *data) {}
21
22
void CompetitionSession_StageLoad(void) {}
23
24
EntityCompetitionSession *CompetitionSession_GetSession(void) { return (EntityCompetitionSession *)globals->competitionSession; }
25
26
#if !MANIA_USE_PLUS
27
void CompetitionSession_ResetOptions(void)
28
{
29
EntityCompetitionSession *session = CompetitionSession_GetSession();
30
31
session->inMatch = false;
32
session->matchID = 0;
33
session->matchCount = 0;
34
session->stageIndex = 0;
35
36
for (int32 r = 0; r < 12; ++r) {
37
session->completedStages[r] = 0;
38
session->matchWinner[r] = 0;
39
}
40
41
for (int32 p = 0; p < 4; ++p) {
42
session->finishState[p] = FINISHTYPE_NOTFINISHED;
43
session->playerID[p] = 0;
44
session->time[p].minutes = 0;
45
session->time[p].seconds = 0;
46
session->time[p].milliseconds = 0;
47
session->rings[p] = 0;
48
session->score[p] = 0;
49
session->items[p] = 0;
50
session->totalRings[p] = 0;
51
session->wins[p] = 0;
52
session->lives[p] = 3;
53
}
54
}
55
56
void CompetitionSession_ClearMatchData(void)
57
{
58
EntityCompetitionSession *session = CompetitionSession_GetSession();
59
60
session->matchWinner[session->matchID] = 0;
61
for (int32 p = 0; p < PLAYER_COUNT; ++p) {
62
session->finishState[p] = FINISHTYPE_NOTFINISHED;
63
session->time[p].minutes = 0;
64
session->time[p].seconds = 0;
65
session->time[p].milliseconds = 0;
66
session->rings[p] = 0;
67
session->score[p] = 0;
68
session->items[p] = 0;
69
session->totalRings[p] = 0;
70
}
71
}
72
73
void CompetitionSession_DeriveWinner(int32 playerID, int32 finishType)
74
{
75
EntityCompetitionSession *session = CompetitionSession_GetSession();
76
session->finishState[playerID] = finishType;
77
78
if (finishType == FINISHTYPE_GAMEOVER) {
79
session->totalRings[playerID] = 0;
80
session->items[playerID] = 0;
81
session->rings[playerID] = 0;
82
session->score[playerID] = 0;
83
session->time[playerID].minutes = 9;
84
session->time[playerID].seconds = 59;
85
session->time[playerID].milliseconds = 59;
86
}
87
88
int32 deathCount = 0;
89
bool32 allPlayersFinished = true;
90
for (int32 p = 0; p < session->playerCount; ++p) {
91
if (!session->lives[p] || session->finishState[p] == FINISHTYPE_GAMEOVER)
92
++deathCount;
93
}
94
95
if (deathCount < session->playerCount - 1) {
96
for (int32 p = 0; p < session->playerCount; ++p) {
97
allPlayersFinished = allPlayersFinished && (!session->lives[p] || session->finishState[p]);
98
}
99
}
100
101
if (allPlayersFinished) {
102
if (!session->matchWinner[session->matchID]) {
103
uint32 winnerTime = 0xFFFFFFFF;
104
uint32 winnerRings = 0;
105
uint32 winnerScore = 0;
106
uint32 winnerItems = 0;
107
uint32 winnerTotalRings = 0;
108
109
int32 times[PLAYER_COUNT];
110
for (int32 p = 0; p < session->playerCount; ++p) {
111
int32 mins = session->time[p].minutes;
112
int32 secs = session->time[p].seconds;
113
int32 ms = session->time[p].milliseconds;
114
times[p] = ms + 100 * (secs + 60 * mins);
115
116
if (session->rings[p] > winnerRings)
117
winnerRings = session->rings[p];
118
119
if (session->totalRings[p] > winnerTotalRings)
120
winnerTotalRings = session->totalRings[p];
121
122
if (session->score[p] > winnerScore)
123
winnerScore = session->score[p];
124
125
if (session->items[p] > winnerItems)
126
winnerItems = session->items[p];
127
128
if (times[p] < winnerTime)
129
winnerTime = times[p];
130
}
131
132
int32 scores[PLAYER_COUNT];
133
memset(scores, 0, 4 * sizeof(int32));
134
int32 winner = 0;
135
for (int32 p = 0; p < session->playerCount; ++p) {
136
if (session->finishState[p] == FINISHTYPE_PASSEDSIGNPOST) {
137
int32 score = 0;
138
139
if (session->rings[p] == winnerRings)
140
score++;
141
142
if (session->totalRings[p] == winnerTotalRings)
143
++score;
144
145
if (session->score[p] == winnerScore)
146
++score;
147
148
if (times[p] == winnerTime)
149
++score;
150
151
if (session->items[p] == winnerItems)
152
++score;
153
154
LogHelpers_Print("player %d => score %d", p, score);
155
156
scores[p] = score;
157
if (score > winner)
158
winner = score;
159
}
160
}
161
162
session->matchWinner[session->matchID] = 0;
163
for (int32 p = 0; p < session->playerCount; ++p) {
164
bool32 isWinner = session->lives[p] > 0 && session->finishState[p] != FINISHTYPE_GAMEOVER && scores[p] == winner;
165
if (isWinner) {
166
LogHelpers_Print("DeriveWinner() -> %d", p);
167
CompetitionSession_WinMatchFor(p);
168
}
169
}
170
}
171
}
172
else {
173
LogHelpers_Print("DeriveWinner() -> %d", -1);
174
}
175
}
176
177
void CompetitionSession_WinMatchFor(int32 player)
178
{
179
EntityCompetitionSession *session = CompetitionSession_GetSession();
180
181
LogHelpers_Print("CompetitionSession_WinMatchFor(%d)", player);
182
++session->wins[player];
183
session->matchWinner[session->matchID] |= (1 << player);
184
}
185
#endif
186
187
#if GAME_INCLUDE_EDITOR
188
void CompetitionSession_EditorDraw(void) {}
189
190
void CompetitionSession_EditorLoad(void) {}
191
#endif
192
193
void CompetitionSession_Serialize(void) {}
194
195