MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / newSave

Method newSave

src/Ruleset/Ruleset.cpp:567–620  ·  view source on GitHub ↗

* Generates a brand new saved game with starting data. * @return A new saved game. */

Source from the content-addressed store, hash-verified

565 * @return A new saved game.
566 */
567SavedGame *Ruleset::newSave() const
568{
569 SavedGame *save = new SavedGame();
570
571 // Add countries
572 for (std::vector<std::string>::const_iterator i = _countriesIndex.begin(); i != _countriesIndex.end(); ++i)
573 {
574 save->getCountries()->push_back(new Country(getCountry(*i)));
575 }
576 // Adjust funding to total $6M
577 int missing = ((_initialFunding - save->getCountryFunding()/1000) / (int)save->getCountries()->size()) * 1000;
578 for (std::vector<Country*>::iterator i = save->getCountries()->begin(); i != save->getCountries()->end(); ++i)
579 {
580 int funding = (*i)->getFunding().back() + missing;
581 if (funding < 0)
582 {
583 funding = (*i)->getFunding().back();
584 }
585 (*i)->setFunding(funding);
586 }
587 save->setFunds(save->getCountryFunding());
588
589 // Add regions
590 for (std::vector<std::string>::const_iterator i = _regionsIndex.begin(); i != _regionsIndex.end(); ++i)
591 {
592 save->getRegions()->push_back(new Region(getRegion(*i)));
593 }
594
595 // Set up starting base
596 Base *base = new Base(this);
597 base->load(_startingBase, save, true);
598
599 // Correct IDs
600 for (std::vector<Craft*>::const_iterator i = base->getCrafts()->begin(); i != base->getCrafts()->end(); ++i)
601 {
602 save->getId((*i)->getRules()->getType());
603 }
604
605 // Generate soldiers
606 int soldiers = _startingBase["randomSoldiers"].as<int>(0);
607 for (int i = 0; i < soldiers; ++i)
608 {
609 Soldier *soldier = genSoldier(save);
610 soldier->setCraft(base->getCrafts()->front());
611 base->getSoldiers()->push_back(soldier);
612 }
613
614 save->getBases()->push_back(base);
615 // Setup alien strategy
616 save->getAlienStrategy().init(this);
617 save->setTime(_startingTime);
618
619 return save;
620}
621
622/**
623 * Returns the list of soldier name pools.

Callers 1

btnOkClickMethod · 0.80

Calls 15

getCountriesMethod · 0.80
getCountryFundingMethod · 0.80
setFundingMethod · 0.80
setFundsMethod · 0.80
getRegionsMethod · 0.80
getBasesMethod · 0.80
loadMethod · 0.45
getCraftsMethod · 0.45
getIdMethod · 0.45
getTypeMethod · 0.45
getRulesMethod · 0.45
setCraftMethod · 0.45

Tested by

no test coverage detected