MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / loadScenarioProgress

Function loadScenarioProgress

src/OpenLoco/src/Scenario/ScenarioManager.cpp:238–275  ·  view source on GitHub ↗

0x00444C4E

Source from the content-addressed store, hash-verified

236
237 // 0x00444C4E
238 static void loadScenarioProgress(ScenarioIndexEntry& entry, Scenario::Options& options)
239 {
240 const auto deliveredCargoObjTempLoaded = ObjectManager::loadTemporaryObject(options.objectiveDeliveredCargo);
241 Scenario::Objective objective = options.objective;
242 Scenario::ObjectiveProgress progress{};
243 progress.timeLimitUntilYear = objective.timeLimitYears + options.scenarioStartYear - 1;
244 if (deliveredCargoObjTempLoaded)
245 {
246 objective.deliveredCargoType = 0xFF; // Used to indicate formatChallengeArguments to use tempObj
247 }
248 std::optional<ObjectHeader> previousCurrency;
249 if (ObjectManager::get<CurrencyObject>() != nullptr)
250 {
251 previousCurrency = ObjectManager::getHeader(LoadedObjectHandle{ ObjectType::currency, 0 });
252 ObjectManager::unload(*previousCurrency);
253 }
254 ObjectManager::load(options.currency);
255 Gfx::loadCurrency();
256
257 FormatArguments args{};
258 Scenario::formatChallengeArguments(objective, progress, args);
259
260 FormatArgumentsView argsView{ args };
261 const auto stringId = argsView.pop<StringId>();
262
263 // TODO: Validate that argsView is copied in the current state.
264 StringManager::formatString(entry.objective, stringId, argsView);
265
266 ObjectManager::freeTemporaryObject();
267
268 // Original didn't clean up like this
269 if (previousCurrency)
270 {
271 ObjectManager::unload(options.currency);
272 ObjectManager::load(*previousCurrency);
273 Gfx::loadCurrency();
274 }
275 }
276
277 static std::optional<uint32_t> findScenario(const fs::path& fileName)
278 {

Callers 1

createIndexFunction · 0.85

Calls 7

loadTemporaryObjectFunction · 0.85
unloadFunction · 0.85
loadCurrencyFunction · 0.85
formatChallengeArgumentsFunction · 0.85
formatStringFunction · 0.85
freeTemporaryObjectFunction · 0.85
loadFunction · 0.70

Tested by

no test coverage detected