-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathVaultManager.cpp
More file actions
272 lines (212 loc) · 7.73 KB
/
VaultManager.cpp
File metadata and controls
272 lines (212 loc) · 7.73 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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
#include "stdafx.h"
#include "VaultManager.h"
/// AUTOGENERATED METHODS ///
int VaultManager::AddRef() {
return Simulator::cStrategy::AddRef();
}
int VaultManager::Release() {
return Simulator::cStrategy::Release();
}
const char* VaultManager::GetName() const {
return "RattlerSpore::VaultManager";
}
bool VaultManager::Write(Simulator::ISerializerStream* stream)
{
return Simulator::ClassSerializer(this, ATTRIBUTES).Write(stream);
}
bool VaultManager::WriteToXML(Simulator::XmlSerializer* writexml)
{
return false;
}
bool VaultManager::Read(Simulator::ISerializerStream* stream)
{
return Simulator::ClassSerializer(this, ATTRIBUTES).Read(stream);
}
/// END OF AUTOGENERATED METHODS ///
////////////////////////////////////
using namespace Simulator;
Simulator::Attribute VaultManager::ATTRIBUTES[] = {
SimAttribute(VaultManager,vaultplanets,1),
SimAttribute(VaultManager,openedVaults,2),
SimAttribute(VaultManager,cutsceneSeti,3),
SimAttribute(VaultManager,cutsceneSysView,4),
SimAttribute(VaultManager,cutscenePlanetView,5),
// Add more attributes here
//
//
// This one must always be at the end
Simulator::Attribute(),
};
void VaultManager::Initialize() {
App::ConsolePrintF("SKIBIDI");
hash_map <ResourceKey, uint32_t> vaultplanets;
hash_map <ResourceKey, uint32_t> openedVaults;
bool cutsceneSeti = false; //Did the first cutscene in a save file?
bool cutsceneSysView = false; //Did the second cutscene in the solar system view?
bool cutscenePlanetView = false; //Did the third cutscene on the planet surface?
App::ConsolePrintF("bools %b %b %b ", cutsceneSeti, cutsceneSysView, cutscenePlanetView);
sInstance = this;
LoadPlanet = false;
}
void VaultManager::Dispose() {
}
void VaultManager::Update(int deltaTime, int deltaGameTime) {
if (GetCurrentGameMode() == GameModeIDs::kGameSpace) {
if (GetCurrentContext() == SpaceContext::SolarSystem) {
LoadPlanet = false;
if (GetActiveStarRecord()->GetType() != StarType::ProtoPlanetary && GetActiveStarRecord()->GetType() != StarType::BlackHole && GetActiveStarRecord()->GetType() != StarType::GalacticCore) {
uint32_t pid = GetActivePlanetRecord()->GetID().internalValue;
//When viewing a vault planet from the solar system view. If it is your first time encountering one, it shall play a cutscene when you hover over it.
if (isVaultPlanet(pid)) {
if (!cutsceneSysView) {
App::ConsolePrintF("Spawned A Ra'tal Drone.");
cutsceneSysView = true;
CinematicManager.PlayCinematic("RSPORE_VaultDetector", 0, 0, 0, 0, 0);
}
}
}
}
else if (GetCurrentContext() == SpaceContext::Planet) {
if (!LoadPlanet) {
uint32_t pid = GetActivePlanetRecord()->GetID().internalValue;
if (isVaultPlanet(pid)) {
//Summon the Eclipse Sentinel
App::ConsolePrintF("Spawned A Ra'tal Drone.");
cGameDataUFO* drone = CreateUFO(UfoType::SecurityDrone, nullptr);
drone->SetModelKey({ 0x25A8E66C, TypeIDs::ufo, GroupIDs::UFOModels });
drone->SetTarget(GetPlayerUFO());
drone->SetScale(5.0);
drone->SetDesiredSpeed(0.2, 1);
drone->mStandardSpeed = (0.3);
drone->mMaxHealthPoints = 75000;
drone->Heal(true);
//Give it weapons
ToolManager.LoadTool(ResourceKey({ 0x1a8de7dd, 0, 0 }), drone->mpNPCFarAirWeapon);
ToolManager.LoadTool(ResourceKey({ 0xfc22027a, 0, 0 }), drone->mpNPCMediumAirWeapon);
ToolManager.LoadTool(ResourceKey({ 0x3a8ad016, 0, 0 }), drone->mpNPCNearAirWeapon);
drone->SetPosition(Vector3(0, 1000, 0));
drone->mZoomAltitude = 1000;
//Play Vault intro cutscene when first land.
if (!cutscenePlanetView) {
cutscenePlanetView = true;
App::ConsolePrintF("Vault Planet Cutscene should've played.");
CinematicManager.PlayCinematic("RSPORE_VAULTCUT", 0, 0, 0, 0, 0);
}
}
LoadPlanet = true;
}
}
else {
LoadPlanet = false;
}
}
}
bool VaultManager::GenerateVault(cStarRecordPtr StrRecord)
{ //If black hole, or galactic object end.
if ((int)StrRecord->GetType() <= 3) {
App::ConsolePrintF("The system is a black hole.");
return false;
}
if (GetCurrentContext() != SpaceContext::Galaxy) {
return false;
}
if (StrRecord->GetTechLevel() == TechLevel::Creature) {
int i = 0;
bool generatedVault = false;
//set to 10 normally
int chmance = rand(12);
if (chmance > 1) {
return false;
}
//seriously replace with for each it keeps crashing
while (!generatedVault || (i <= StrRecord->mPlanetCount-1)) {
//replace with foreach
if (StrRecord->GetPlanetRecord(i) == nullptr) {
return false;
}
int rando = rand(14);
App::ConsolePrintF("rand %d", rando);
int pType = (int)StrRecord->GetPlanetRecord(i)->mType;
//If T0 T1 T2 or T3 then generate vault, otherwise if gas giant or asteroid belt, skip.
if(pType >= 2 && pType <= 5) {
//If statement was here that checked the boolean, however it resulted in returning a nullptr and crashes the game.
if (!VaultManagerA.cutsceneSeti) {
App::ConsolePrintF("The first vault cutscene should have played.");
CinematicManager.PlayCinematic("RSPORE_VAULTSETIWAIT", 0, 0, 0, 0, 0);
VaultManagerA.cutsceneSeti = true;
}
auto vaultplanet = StrRecord->GetPlanetRecord(i)->GetID();
//replace with hash_map
ResourceKey vpkey;
vpkey.instanceID = vaultplanet.internalValue;
vaultplanets.emplace(vpkey,vaultplanet.internalValue);
ResourceKey vaultScript;
ResourceKey planetSource;
//rattlesnake //prop //planetTerrainScripts_artDirected~
//vaultScript = ResourceKey(0x98eeb4f9, 0x00B1B104, 0x4184a200);
//vaultTEST //prop //planetTerrainScriptsRSPORE
vaultScript = ResourceKey(0xa395f2a9, 0x00B1B104, 0x8C2C3803);
planetSource = StrRecord->GetPlanetRecord(i)->GetTerrainScriptSource();
cPlanetRecord* recowd = StrRecord->GetPlanetRecord(i);
//cPlanetRecord::AssignTerrainT0(vaultplanet.GetRecord());
StrRecord->GetPlanetRecord(i)->SetGeneratedTerrainKey(vaultScript);
StrRecord->GetPlanetRecord(i)->GenerateTerrainKey();
StrRecord->GetPlanetRecord(i)->mCommodityNodes.clear();
//StrRecord->GetPlanetRecord(i)->mFlags = 17480;
//StrRecord->GetPlanetRecord(i)->mType = PlanetType::T1;
//StrRecord->GetPlanetRecord(i)->mSpiceGen = ResourceKey({ id(""),0,0 });
vaultplanet.GetRecord()->mPlanetObjects.clear();
App::ConsolePrintF("A vault has generated on planet %d", i);
return true;
}
i++;
}
}
App::ConsolePrintF("The system has the incorrect tech level.");
return false;
}
bool VaultManager::OpenVault(cPlanetRecordPtr PlRecord)
{
auto vaultplanet = PlRecord->GetID();
//replace with hash_map
ResourceKey vpkey;
vpkey.instanceID = vaultplanet.internalValue;
openedVaults.emplace(vpkey, vaultplanet.internalValue);
UTFWin::UILayout* mpUIlayout;
mpUIlayout = new UTFWin::UILayout();
if (mpUIlayout->LoadByID(id("vaultui"))) {
mpUIlayout->SetVisible(true);
}
return false;
}
void VaultManager::GiveRandBadge()
{
BadgeManager.AddToBadgeProgress(BadgeManagerEvent(0x97d26d2b), 10);
}
VaultManager* VaultManager::Get()
{
return sInstance;
}
bool VaultManager::isVaultPlanet(uint32_t PlanetID)
{ //Get rid of the simulator system, a regular vector would be more optimized.
// SavedBuildings.clear();
if (vaultplanets.find(ResourceKey().WithInstance(PlanetID)) != vaultplanets.end()) {
return true;
}
return false;
}
bool VaultManager::isGrobPlanet(uint32_t pID)
{
if (PlanetID(pID).GetRecord()->GetStarRecord()->mEmpireID == StarManager.GetGrobEmpireID() && PlanetID(pID).GetRecord()->GetTechLevel() == TechLevel::Empire) {
return true;
}
return false;
}
bool VaultManager::isSkondPlanet(uint32_t pID)
{
if (PlanetID(pID).GetRecord()->GetTechLevel() == TechLevel::City) {
return true;
}
return false;
}
VaultManager* VaultManager::sInstance;