* Saves a saved game's contents to a YAML file. * @param filename YAML filename. */
| 447 | * @param filename YAML filename. |
| 448 | */ |
| 449 | void SavedGame::save(const std::string &filename) const |
| 450 | { |
| 451 | std::string s = Options::getUserFolder() + filename; |
| 452 | std::ofstream sav(s.c_str()); |
| 453 | if (!sav) |
| 454 | { |
| 455 | throw Exception("Failed to save " + filename); |
| 456 | } |
| 457 | |
| 458 | YAML::Emitter out; |
| 459 | |
| 460 | // Saves the brief game info used in the saves list |
| 461 | YAML::Node brief; |
| 462 | brief["name"] = Language::wstrToUtf8(_name); |
| 463 | brief["version"] = OPENXCOM_VERSION_SHORT; |
| 464 | brief["build"] = OPENXCOM_VERSION_GIT; |
| 465 | brief["time"] = _time->save(); |
| 466 | if (_battleGame != 0) |
| 467 | { |
| 468 | brief["mission"] = _battleGame->getMissionType(); |
| 469 | brief["turn"] = _battleGame->getTurn(); |
| 470 | } |
| 471 | brief["rulesets"] = Options::rulesets; |
| 472 | if (_ironman) |
| 473 | brief["ironman"] = _ironman; |
| 474 | out << brief; |
| 475 | // Saves the full game data to the save |
| 476 | out << YAML::BeginDoc; |
| 477 | YAML::Node node; |
| 478 | node["difficulty"] = (int)_difficulty; |
| 479 | node["monthsPassed"] = _monthsPassed; |
| 480 | node["graphRegionToggles"] = _graphRegionToggles; |
| 481 | node["graphCountryToggles"] = _graphCountryToggles; |
| 482 | node["graphFinanceToggles"] = _graphFinanceToggles; |
| 483 | node["rng"] = RNG::getSeed(); |
| 484 | node["funds"] = _funds; |
| 485 | node["maintenance"] = _maintenance; |
| 486 | node["researchScores"] = _researchScores; |
| 487 | node["incomes"] = _incomes; |
| 488 | node["expenditures"] = _expenditures; |
| 489 | node["warned"] = _warned; |
| 490 | node["globeLon"] = _globeLon; |
| 491 | node["globeLat"] = _globeLat; |
| 492 | node["globeZoom"] = _globeZoom; |
| 493 | node["ids"] = _ids; |
| 494 | for (std::vector<Country*>::const_iterator i = _countries.begin(); i != _countries.end(); ++i) |
| 495 | { |
| 496 | node["countries"].push_back((*i)->save()); |
| 497 | } |
| 498 | for (std::vector<Region*>::const_iterator i = _regions.begin(); i != _regions.end(); ++i) |
| 499 | { |
| 500 | node["regions"].push_back((*i)->save()); |
| 501 | } |
| 502 | for (std::vector<Base*>::const_iterator i = _bases.begin(); i != _bases.end(); ++i) |
| 503 | { |
| 504 | node["bases"].push_back((*i)->save()); |
| 505 | } |
| 506 | for (std::vector<Waypoint*>::const_iterator i = _waypoints.begin(); i != _waypoints.end(); ++i) |
nothing calls this directly
no test coverage detected