@@ -26,22 +26,23 @@ namespace RTE {
26
26
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
27
27
28
28
bool PresetMan::GetGroups (std::list<std::string> &groupList, int whichModule, const std::string &withType, bool moduleSpace) const {
29
- RTEAssert (whichModule < g_ModuleMan.GetTotalModuleCount (), " Tried to access an out of bounds data module number!" );
30
-
31
29
bool foundAny = false ;
32
- auto &loadedModules = g_ModuleMan.GetLoadedDataModules ();
33
30
34
31
if (whichModule < 0 ) {
35
- for (DataModule * dataModule : loadedModules ) {
32
+ for (const auto &[moduleName, dataModule] : g_ModuleMan. GetLoadedDataModules () ) {
36
33
foundAny = dataModule->GetGroupsWithType (groupList, withType) || foundAny;
37
34
}
38
35
} else {
36
+ RTEAssert (whichModule < g_ModuleMan.GetTotalModuleCount (), " Trying to get from an out of bounds DataModule ID in PresetMan::GetGroups!" );
37
+
39
38
if (moduleSpace) {
40
- for (size_t officialModuleID = 0 ; officialModuleID < g_ModuleMan.GetOfficialModuleCount (); ++officialModuleID) {
41
- foundAny = loadedModules[officialModuleID]->GetGroupsWithType (groupList, withType) || foundAny;
39
+ for (const auto &[moduleName, dataModule] : g_ModuleMan.GetLoadedDataModules ()) {
40
+ if (dataModule->IsOfficial ()) {
41
+ foundAny = dataModule->GetGroupsWithType (groupList, withType) || foundAny;
42
+ }
42
43
}
43
44
}
44
- foundAny = loadedModules[ whichModule] ->GetGroupsWithType (groupList, withType) || foundAny;
45
+ foundAny = g_ModuleMan. GetDataModule ( whichModule) ->GetGroupsWithType (groupList, withType) || foundAny;
45
46
}
46
47
if (!groupList.empty () && (withType == " All" || withType.empty ())) {
47
48
// DataModule::GetGroupsWithType doesn't sort and filter dupes when getting all groups, so do it here.
@@ -66,7 +67,7 @@ namespace RTE {
66
67
reader >> ClassName;
67
68
pClass = Entity::ClassInfo::GetClass (ClassName);
68
69
69
- auto &loadedModules = g_ModuleMan.GetLoadedDataModules ( );
70
+ DataModule *dataModule = g_ModuleMan.GetDataModule (whichModule );
70
71
71
72
if (pClass && pClass->IsConcrete ()) {
72
73
// Instantiate
@@ -78,20 +79,24 @@ namespace RTE {
78
79
// Try to read in the preset instance's data from the reader
79
80
if (newInstance && newInstance->Create (reader, false ) < 0 ) {
80
81
// Abort loading if we can't create entity and it's not in a module that allows ignoring missing items.
81
- if (!g_ModuleMan. GetDataModule (whichModule) ->GetIgnoreMissingItems ()) {
82
+ if (!dataModule ->GetIgnoreMissingItems ()) {
82
83
RTEAbort (" Reading of a preset instance \" " + newInstance->GetPresetName () + " \" of class " + newInstance->GetClassName () + " failed in file " + reader.GetCurrentFilePath () + " , shortly before line #" + reader.GetCurrentFileLine ());
83
84
}
84
85
} else if (newInstance) {
85
86
// Try to add the instance to the collection
86
- loadedModules[whichModule] ->AddEntityPreset (newInstance, reader.GetPresetOverwriting (), entityFilePath);
87
+ dataModule ->AddEntityPreset (newInstance, reader.GetPresetOverwriting (), entityFilePath);
87
88
88
89
// Regardless of whether there was a collision or not, use whatever now exists in the instance map of that class and name
89
- pReturnPreset = loadedModules[whichModule] ->GetEntityPreset (newInstance->GetClassName (), newInstance->GetPresetName ());
90
+ pReturnPreset = dataModule ->GetEntityPreset (newInstance->GetClassName (), newInstance->GetPresetName ());
90
91
// If the instance wasn't found in the specific DataModule, try to find it in all the official ones instead
91
92
if (!pReturnPreset) {
92
- RTEAssert (g_ModuleMan.GetOfficialModuleCount () <= loadedModules.size (), " More official modules than modules loaded?!" );
93
- for (int i = 0 ; i < g_ModuleMan.GetOfficialModuleCount () && !pReturnPreset; ++i) {
94
- pReturnPreset = loadedModules[i]->GetEntityPreset (newInstance->GetClassName (), newInstance->GetPresetName ());
93
+ for (const auto &[moduleID, loadedModule] : g_ModuleMan.GetLoadedDataModules ()) {
94
+ if (loadedModule->IsOfficial ()) {
95
+ pReturnPreset = loadedModule->GetEntityPreset (newInstance->GetClassName (), newInstance->GetPresetName ());
96
+ if (pReturnPreset) {
97
+ break ;
98
+ }
99
+ }
95
100
}
96
101
}
97
102
}
@@ -111,8 +116,6 @@ namespace RTE {
111
116
112
117
const Entity *pRetEntity = nullptr ;
113
118
114
- auto &loadedModules = g_ModuleMan.GetLoadedDataModules ();
115
-
116
119
// Preset name might have "[ModuleName]/" preceding it, detect it here and select proper module!
117
120
int slashPos = presetName.find_first_of (' /' );
118
121
if (slashPos != std::string::npos) {
@@ -124,18 +127,25 @@ namespace RTE {
124
127
// All modules
125
128
if (whichModule < 0 ) {
126
129
// Search all modules
127
- for (int i = 0 ; i < loadedModules.size () && !pRetEntity; ++i) {
128
- pRetEntity = loadedModules[i]->GetEntityPreset (typeName, presetName);
130
+ for (const auto &[moduleID, dataModule] : g_ModuleMan.GetLoadedDataModules ()) {
131
+ pRetEntity = dataModule->GetEntityPreset (typeName, presetName);
132
+ if (pRetEntity) {
133
+ break ;
134
+ }
129
135
}
130
136
} else {
131
137
// Try to get it from the asked for module
132
- pRetEntity = loadedModules[ whichModule] ->GetEntityPreset (typeName, presetName);
138
+ pRetEntity = g_ModuleMan. GetDataModule ( whichModule) ->GetEntityPreset (typeName, presetName);
133
139
134
140
// If couldn't find it in there, then try all the official modules!
135
141
if (!pRetEntity) {
136
- RTEAssert (g_ModuleMan.GetOfficialModuleCount () <= loadedModules.size (), " More official modules than modules loaded?!" );
137
- for (int i = 0 ; i < g_ModuleMan.GetOfficialModuleCount () && !pRetEntity; ++i) {
138
- pRetEntity = loadedModules[i]->GetEntityPreset (typeName, presetName);
142
+ for (const auto &[moduleID, dataModule] : g_ModuleMan.GetLoadedDataModules ()) {
143
+ if (dataModule->IsOfficial ()) {
144
+ pRetEntity = dataModule->GetEntityPreset (typeName, presetName);
145
+ if (pRetEntity) {
146
+ break ;
147
+ }
148
+ }
139
149
}
140
150
}
141
151
}
@@ -170,9 +180,13 @@ namespace RTE {
170
180
171
181
// If couldn't find it in there, then try all the official modules!
172
182
if (pRetPath.empty ()) {
173
- RTEAssert (g_ModuleMan.GetOfficialModuleCount () <= loadedModules.size (), " More official modules than modules loaded?!" );
174
- for (int i = 0 ; i < g_ModuleMan.GetOfficialModuleCount () && pRetPath.empty (); ++i) {
175
- pRetPath = loadedModules[i]->GetEntityDataLocation (type, preset);
183
+ for (const auto &[moduleID, dataModule] : loadedModules) {
184
+ if (dataModule->IsOfficial ()) {
185
+ pRetPath = dataModule->GetEntityDataLocation (type, preset);
186
+ if (!pRetPath.empty ()) {
187
+ break ;
188
+ }
189
+ }
176
190
}
177
191
}
178
192
}
@@ -183,26 +197,27 @@ namespace RTE {
183
197
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
184
198
185
199
bool PresetMan::GetAllOfType (std::list<Entity *> &entityList, const std::string &typeName, int whichModule, bool moduleSpace) const {
186
- RTEAssert (whichModule < g_ModuleMan.GetTotalModuleCount (), " Trying to get from an out of bounds DataModule ID!" );
187
-
188
200
if (typeName.empty ()) {
189
201
return false ;
190
202
}
191
203
192
204
bool foundAny = false ;
193
- auto &loadedModules = g_ModuleMan.GetLoadedDataModules ();
194
205
195
206
if (whichModule < 0 ) {
196
- for (DataModule * dataModule : loadedModules ) {
207
+ for (const auto &[moduleName, dataModule] : g_ModuleMan. GetLoadedDataModules () ) {
197
208
foundAny = dataModule->GetAllOfType (entityList, typeName) || foundAny;
198
209
}
199
210
} else {
211
+ RTEAssert (whichModule < g_ModuleMan.GetTotalModuleCount (), " Trying to get from an out of bounds DataModule ID in PresetMan::GetAllOfType!" );
212
+
200
213
if (moduleSpace) {
201
- for (size_t officialModuleID = 0 ; officialModuleID < g_ModuleMan.GetOfficialModuleCount (); ++officialModuleID) {
202
- foundAny = loadedModules[officialModuleID]->GetAllOfType (entityList, typeName) || foundAny;
214
+ for (const auto &[moduleName, dataModule] : g_ModuleMan.GetLoadedDataModules ()) {
215
+ if (dataModule->IsOfficial ()) {
216
+ foundAny = dataModule->GetAllOfType (entityList, typeName) || foundAny;
217
+ }
203
218
}
204
219
}
205
- foundAny = loadedModules[ whichModule] ->GetAllOfType (entityList, typeName);
220
+ foundAny = g_ModuleMan. GetDataModule ( whichModule) ->GetAllOfType (entityList, typeName);
206
221
}
207
222
return foundAny;
208
223
}
@@ -213,21 +228,22 @@ namespace RTE {
213
228
RTEAssert (!groupNames.empty (), " Looking for empty groups in PresetMan::GetAllOfGroups!" );
214
229
215
230
bool foundAny = false ;
216
- auto &loadedModules = g_ModuleMan.GetLoadedDataModules ();
217
231
218
232
if (whichModule < 0 ) {
219
- for (DataModule * dataModule : loadedModules ) {
233
+ for (const auto &[moduleName, dataModule] : g_ModuleMan. GetLoadedDataModules () ) {
220
234
foundAny = dataModule->GetAllOfGroups (entityList, groupNames, typeName) || foundAny;
221
235
}
222
236
} else {
223
- RTEAssert (whichModule < loadedModules. size (), " Trying to get from an out of bounds DataModule ID in PresetMan::GetAllOfGroups!" );
237
+ RTEAssert (whichModule < g_ModuleMan. GetTotalModuleCount (), " Trying to get from an out of bounds DataModule ID in PresetMan::GetAllOfGroups!" );
224
238
225
239
if (moduleSpace) {
226
- for (size_t officialModuleID = 0 ; officialModuleID < g_ModuleMan.GetOfficialModuleCount (); ++officialModuleID) {
227
- foundAny = loadedModules[officialModuleID]->GetAllOfGroups (entityList, groupNames, typeName) || foundAny;
240
+ for (const auto &[moduleName, dataModule] : g_ModuleMan.GetLoadedDataModules ()) {
241
+ if (dataModule->IsOfficial ()) {
242
+ foundAny = dataModule->GetAllOfGroups (entityList, groupNames, typeName) || foundAny;
243
+ }
228
244
}
229
245
}
230
- foundAny = loadedModules[ whichModule] ->GetAllOfGroups (entityList, groupNames, typeName);
246
+ foundAny = g_ModuleMan. GetDataModule ( whichModule) ->GetAllOfGroups (entityList, groupNames, typeName);
231
247
}
232
248
return foundAny;
233
249
}
@@ -242,23 +258,22 @@ namespace RTE {
242
258
}
243
259
244
260
bool foundAny = false ;
245
- auto &loadedModules = g_ModuleMan.GetLoadedDataModules ();
246
261
247
262
if (whichModule < 0 ) {
248
- for (DataModule * dataModule : loadedModules ) {
263
+ for (const auto &[moduleID, dataModule] : g_ModuleMan. GetLoadedDataModules () ) {
249
264
foundAny = dataModule->GetAllNotOfGroups (entityList, groupNames, typeName) || foundAny;
250
265
}
251
266
} else {
252
- RTEAssert (whichModule < loadedModules. size (), " Trying to get from an out of bounds DataModule ID in PresetMan::GetAllNotOfGroups!" );
253
- foundAny = loadedModules[ whichModule] ->GetAllNotOfGroups (entityList, groupNames, typeName);
267
+ RTEAssert (whichModule < g_ModuleMan. GetTotalModuleCount (), " Trying to get from an out of bounds DataModule ID in PresetMan::GetAllNotOfGroups!" );
268
+ foundAny = g_ModuleMan. GetDataModule ( whichModule) ->GetAllNotOfGroups (entityList, groupNames, typeName);
254
269
}
255
270
return foundAny;
256
271
}
257
272
258
273
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
259
274
260
275
Entity * PresetMan::GetRandomOfGroup (const std::string &groupName, const std::string &typeName, int whichModule, bool moduleSpace) {
261
- RTEAssert (!groupName.empty (), " Looking for empty group!" );
276
+ RTEAssert (!groupName.empty (), " Looking for empty group in PresetMan::GetRandomOfGroup !" );
262
277
263
278
if (std::list<Entity *> entityList; GetAllOfGroups (entityList, { groupName }, typeName, whichModule, moduleSpace)) {
264
279
auto entityItr = entityList.begin ();
@@ -272,23 +287,21 @@ namespace RTE {
272
287
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
273
288
274
289
Entity * PresetMan::GetRandomBuyableOfGroupFromTech (const std::string &groupName, const std::string &typeName, int whichModule) {
275
- RTEAssert (!groupName.empty (), " Looking for empty group!" );
290
+ RTEAssert (!groupName.empty (), " Looking for empty group in PresetMan::GetRandomBuyableOfGroupFromTech !" );
276
291
277
292
bool foundAny = false ;
278
293
std::list<Entity *> entityList;
279
294
std::list<Entity *> tempList;
280
295
281
- auto &loadedModules = g_ModuleMan.GetLoadedDataModules ();
282
-
283
296
if (whichModule < 0 ) {
284
- for (DataModule * dataModule : loadedModules ) {
297
+ for (const auto &[moduleID, dataModule] : g_ModuleMan. GetLoadedDataModules () ) {
285
298
if (dataModule->IsFaction ()) {
286
299
foundAny = dataModule->GetAllOfGroups (tempList, { groupName }, typeName) || foundAny;
287
300
}
288
301
}
289
302
} else {
290
- RTEAssert (whichModule < loadedModules. size (), " Trying to get from an out of bounds DataModule ID!" );
291
- foundAny = loadedModules[ whichModule] ->GetAllOfGroups (tempList, { groupName }, typeName);
303
+ RTEAssert (whichModule < g_ModuleMan. GetTotalModuleCount (), " Trying to get from an out of bounds DataModule ID in PresetMan::GetRandomBuyableOfGroupFromTech !" );
304
+ foundAny = g_ModuleMan. GetDataModule ( whichModule) ->GetAllOfGroups (tempList, { groupName }, typeName);
292
305
}
293
306
294
307
// Filter found entities, we need only buyables.
@@ -390,7 +403,7 @@ namespace RTE {
390
403
391
404
void PresetMan::ReloadAllScripts () const {
392
405
g_LuaMan.ClearUserModuleCache ();
393
- for (const DataModule * dataModule : g_ModuleMan.GetLoadedDataModules ()) {
406
+ for (const auto &[moduleID, dataModule] : g_ModuleMan.GetLoadedDataModules ()) {
394
407
dataModule->ReloadAllScripts ();
395
408
}
396
409
g_ConsoleMan.PrintString (" SYSTEM: Scripts reloaded!" );
@@ -462,15 +475,18 @@ namespace RTE {
462
475
bool PresetMan::AddMaterialMapping (uint8_t fromID, uint8_t toID, int whichModule) const {
463
476
// RTEAssert(whichModule >= g_ModuleMan.GetOfficialModuleCount() && whichModule < g_ModuleMan.GetTotalModuleCount(), "Tried to make a material mapping in an official or out-of-bounds DataModule!");
464
477
465
- return g_ModuleMan.GetLoadedDataModules ()[whichModule]->AddMaterialMapping (fromID, toID);
478
+ if (DataModule *dataModule = g_ModuleMan.GetDataModule (whichModule); dataModule->IsOfficial ()) {
479
+ return dataModule->AddMaterialMapping (fromID, toID);
480
+ }
481
+ return false ;
466
482
}
467
483
468
484
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
469
485
470
486
bool PresetMan::AddEntityPreset (Entity *entityToAdd, int whichModule, bool overwriteSame, const std::string &readFromFile) const {
471
487
RTEAssert (whichModule >= 0 && whichModule < g_ModuleMan.GetTotalModuleCount (), " Tried to access an out of bounds data module number!" );
472
488
473
- return g_ModuleMan.GetLoadedDataModules ()[ whichModule] ->AddEntityPreset (entityToAdd, overwriteSame, readFromFile);
489
+ return g_ModuleMan.GetDataModule ( whichModule) ->AddEntityPreset (entityToAdd, overwriteSame, readFromFile);
474
490
}
475
491
476
492
// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -498,7 +514,7 @@ namespace RTE {
498
514
}
499
515
} else {
500
516
// Note that we'll return this instance regardless of whether the adding was successful or not.
501
- g_ModuleMan.GetLoadedDataModules ()[ whichModule] ->AddEntityPreset (newInstance, reader.GetPresetOverwriting (), entityFilePath);
517
+ g_ModuleMan.GetDataModule ( whichModule) ->AddEntityPreset (newInstance, reader.GetPresetOverwriting (), entityFilePath);
502
518
return newInstance;
503
519
}
504
520
}
0 commit comments