* Loads a saved game's contents from a YAML file. * @note Assumes the saved game is blank. * @param filename YAML filename. * @param rule Ruleset for the saved game. */
| 287 | * @param rule Ruleset for the saved game. |
| 288 | */ |
| 289 | void SavedGame::load(const std::string &filename, Ruleset *rule) |
| 290 | { |
| 291 | std::string s = Options::getUserFolder() + filename; |
| 292 | std::vector<YAML::Node> file = YAML::LoadAllFromFile(s); |
| 293 | if (file.empty()) |
| 294 | { |
| 295 | throw Exception(filename + " is not a vaild save file"); |
| 296 | } |
| 297 | |
| 298 | // Get brief save info |
| 299 | YAML::Node brief = file[0]; |
| 300 | /* |
| 301 | std::string version = brief["version"].as<std::string>(); |
| 302 | if (version != OPENXCOM_VERSION_SHORT) |
| 303 | { |
| 304 | throw Exception("Version mismatch"); |
| 305 | } |
| 306 | */ |
| 307 | _time->load(brief["time"]); |
| 308 | if (brief["name"]) |
| 309 | { |
| 310 | _name = Language::utf8ToWstr(brief["name"].as<std::string>()); |
| 311 | } |
| 312 | else |
| 313 | { |
| 314 | _name = Language::fsToWstr(filename); |
| 315 | } |
| 316 | _ironman = brief["ironman"].as<bool>(_ironman); |
| 317 | |
| 318 | // Get full save data |
| 319 | YAML::Node doc = file[1]; |
| 320 | _difficulty = (GameDifficulty)doc["difficulty"].as<int>(_difficulty); |
| 321 | if (doc["rng"] && (_ironman || !Options::newSeedOnLoad)) |
| 322 | RNG::setSeed(doc["rng"].as<uint64_t>()); |
| 323 | _monthsPassed = doc["monthsPassed"].as<int>(_monthsPassed); |
| 324 | _graphRegionToggles = doc["graphRegionToggles"].as<std::string>(_graphRegionToggles); |
| 325 | _graphCountryToggles = doc["graphCountryToggles"].as<std::string>(_graphCountryToggles); |
| 326 | _graphFinanceToggles = doc["graphFinanceToggles"].as<std::string>(_graphFinanceToggles); |
| 327 | _funds = doc["funds"].as< std::vector<int> >(_funds); |
| 328 | _maintenance = doc["maintenance"].as< std::vector<int> >(_maintenance); |
| 329 | _researchScores = doc["researchScores"].as< std::vector<int> >(_researchScores); |
| 330 | _incomes = doc["incomes"].as< std::vector<int> >(_incomes); |
| 331 | _expenditures = doc["expenditures"].as< std::vector<int> >(_expenditures); |
| 332 | _warned = doc["warned"].as<bool>(_warned); |
| 333 | _globeLon = doc["globeLon"].as<double>(_globeLon); |
| 334 | _globeLat = doc["globeLat"].as<double>(_globeLat); |
| 335 | _globeZoom = doc["globeZoom"].as<int>(_globeZoom); |
| 336 | _ids = doc["ids"].as< std::map<std::string, int> >(_ids); |
| 337 | |
| 338 | for (YAML::const_iterator i = doc["countries"].begin(); i != doc["countries"].end(); ++i) |
| 339 | { |
| 340 | std::string type = (*i)["type"].as<std::string>(); |
| 341 | if (rule->getCountry(type)) |
| 342 | { |
| 343 | Country *c = new Country(rule->getCountry(type), false); |
| 344 | c->load(*i); |
| 345 | _countries.push_back(c); |
| 346 | } |
no test coverage detected