forked from HarbourMasters/Ghostship
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeneratePools.cpp
More file actions
204 lines (165 loc) · 7.14 KB
/
Copy pathGeneratePools.cpp
File metadata and controls
204 lines (165 loc) · 7.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#include "Logic.h"
#include "port/Rando/Spoiler/Spoiler.h"
#include "port/ui/Notification.h"
#include <libultraship/bridge/consolevariablebridge.h>
#include <sstream>
#include <random>
extern "C" {
#include "port/ShipUtils.h"
}
namespace Rando {
namespace Logic {
// Initial Check Shuffling containers
std::vector<std::vector<LevelShuffleEntry>> shuffledList;
std::vector<LevelShuffleEntry> shuffledLevelList;
std::vector<RandoCheckId> shuffledChecks;
std::vector<std::pair<RandoItemId, RandoAct>> shuffledItems;
// Initial Entrance Shuffling containers
std::vector<RandoEntranceId> entranceIds;
std::vector<int16_t> levelIds;
// Final Shuffle List
std::vector<LevelShuffleEntry> shuffledPool;
std::vector<RandoSaveEntrance> shuffledEntrances;
uint32_t GetRandoSeed(const std::string& input) {
if (finalSeed > 0) {
return finalSeed;
}
std::random_device rd;
if (CVarGetInteger("gRandoSettings.ManualSeedEntry", 0)) {
if (input.empty()) {
return rd();
} else {
return Ship_Hash(input);
}
}
return rd();
}
void ShuffleRandoItems(std::vector<std::pair<RandoItemId, RandoAct>>& shuffledItems, const std::string& input) {
uint32_t seed = GetRandoSeed(input);
std::mt19937 g(seed);
std::shuffle(shuffledItems.begin(), shuffledItems.end(), g);
finalSeed = seed;
}
void ShuffleRandoEntrances(std::vector<int16_t>& shuffledLevels, const std::string& input) {
uint32_t seed = GetRandoSeed(input);
std::mt19937 g(seed);
std::shuffle(shuffledLevels.begin(), shuffledLevels.end(), g);
finalSeed = seed;
}
void InitializeSaveChecks() {
for (auto& [randoCheckId, randoStaticCheck] : Rando::StaticData::Checks) {
RandoSaveCheck randoSaveCheck = { .randoItemId = randoStaticCheck.randoItemId,
.randoAct = randoStaticCheck.actData,
.obtained = false,
.skipped = false };
RANDO_SAVE_CHECKS(selectedFileNum)[randoCheckId] = randoSaveCheck;
}
}
void InitializeSaveEntrances() {
for (auto& [randoEntranceId, randoStaticEntrance] : Rando::StaticData::Entrances) {
RandoSaveEntrance randoSaveEntrance = { .randoEntranceId = randoEntranceId,
.destinationId = randoStaticEntrance.destinationId };
RANDO_SAVE_ENTRANCES(selectedFileNum)[randoEntranceId] = randoSaveEntrance;
}
}
void InitializeSaveOptions() {
for (auto& [randoOptionId, optionData] : Rando::StaticData::Options) {
RANDO_SAVE_OPTIONS(selectedFileNum)[randoOptionId] = optionData.defaultValue;
}
}
void GenerateShuffleList() {
shuffledPool.clear();
shuffledEntrances.clear();
for (int i = LEVEL_UNKNOWN_1; i < LEVEL_UNKNOWN_38; i++) {
shuffledLevelList.clear();
shuffledChecks.clear();
shuffledItems.clear();
for (auto& [randoCheckId, randoCheckData] : Rando::StaticData::Checks) {
if (randoCheckId == RC_UNKNOWN) {
continue;
}
if (randoCheckData.levelId != i) {
continue;
}
if (randoCheckData.randoCheckType == RCTYPE_STAR_RED_COIN &&
CVarGetInteger(Rando::StaticData::Options[RO_SHUFFLE_RED_COIN_STARS].cvar, 0) == RO_GENERIC_OFF) {
continue;
}
RandoItemType randoItemType = Rando::StaticData::Items[randoCheckData.randoItemId].randoItemType;
// TODO: Swap to RANDO_SAVE_OPTIONS once Save File is converted to JSON
if (randoItemType == RITYPE_COIN_BLUE &&
CVarGetInteger(Rando::StaticData::Options[RO_SHUFFLE_COINS_BLUE].cvar, 0) == RO_GENERIC_OFF) {
continue;
}
if (randoItemType == RITYPE_COIN_RED &&
CVarGetInteger(Rando::StaticData::Options[RO_SHUFFLE_COINS_RED].cvar, 0) == RO_GENERIC_OFF) {
continue;
}
if (randoItemType == RITYPE_STAR &&
CVarGetInteger(Rando::StaticData::Options[RO_SHUFFLE_STARS].cvar, 0) == RO_GENERIC_OFF) {
continue;
}
shuffledChecks.push_back(randoCheckId);
shuffledItems.push_back({ randoCheckData.randoItemId, randoCheckData.actData });
}
if (!shuffledItems.empty()) {
for (int v = 0; v < shuffledChecks.size(); v++) {
shuffledLevelList.push_back(
{ shuffledChecks[v], shuffledItems[v].first, shuffledItems[v].second, false, false });
}
shuffledList.push_back(shuffledLevelList);
}
}
for (auto& [randoEntranceId, randoStaticEntrance] : Rando::StaticData::Entrances) {
if (randoEntranceId == RE_UNKNOWN) {
continue;
}
if (randoStaticEntrance.randoEntranceType == RETYPE_BOWSER &&
CVarGetInteger(Rando::StaticData::Options[RO_SHUFFLE_ENTRANCES_BOWSER].cvar, 0) == RO_GENERIC_OFF) {
continue;
}
if (randoStaticEntrance.randoEntranceType == RETYPE_BOWSER_FINAL &&
CVarGetInteger(Rando::StaticData::Options[RO_SHUFFLE_ENTRANCES_BOWSER_FINAL].cvar, 0) == RO_GENERIC_OFF) {
continue;
}
if (randoStaticEntrance.randoEntranceType == RETYPE_CAP &&
CVarGetInteger(Rando::StaticData::Options[RO_SHUFFLE_ENTRANCES_CAP].cvar, 0) == RO_GENERIC_OFF) {
continue;
}
if (randoStaticEntrance.randoEntranceType == RETYPE_PAINTING &&
CVarGetInteger(Rando::StaticData::Options[RO_SHUFFLE_ENTRANCES_PAINTING].cvar, 0) == RO_GENERIC_OFF) {
continue;
}
if (randoStaticEntrance.randoEntranceType == RETYPE_SECRET &&
CVarGetInteger(Rando::StaticData::Options[RO_SHUFFLE_ENTRANCES_SECRET].cvar, 0) == RO_GENERIC_OFF) {
continue;
}
entranceIds.push_back(randoStaticEntrance.randoEntranceId);
levelIds.push_back(randoStaticEntrance.destinationId);
}
switch (CVarGetInteger(Rando::StaticData::Options[RO_LOGIC].cvar, 0)) {
case RO_LOGIC_GLITCHLESS:
case RO_LOGIC_NO_LOGIC:
ApplyNoLogicToSaveContext(shuffledList, levelIds);
break;
default:
break;
}
gSaveBuffer.files[selectedFileNum][0].shipSaveData.randoSaveData.finalSeed = finalSeed;
if (CVarGetInteger("gRandoSettings.GenerateLog", 0)) {
nlohmann::json spoilerLog = Rando::Spoiler::GenerateFromPoolGeneration(shuffledPool, shuffledEntrances);
if (spoilerLog.empty()) {
Notification::Emit(
{ .message = "Error: No Spoiler Log was created.", .messageColor = ImVec4(0.85f, 0.3f, 0, 1) });
} else {
std::string fileName = std::to_string(spoilerLog["finalSeed"].get<u32>()).c_str();
fileName += ".json";
Rando::Spoiler::SaveToFile(fileName, spoilerLog);
Notification::Emit({ .prefix = fileName + " ",
.message = "Spoiler Log created.",
.messageColor = ImVec4(0, 0.3f, 0.85f, 1) });
}
}
}
} // namespace Logic
} // namespace Rando