/** * Generates a brand new saved game with starting data. * @return A new saved game. */ SavedGame *Ruleset::newSave() const { SavedGame *save = new SavedGame(); // Add countries for (std::vector<std::string>::const_iterator i = _countriesIndex.begin(); i != _countriesIndex.end(); ++i) { save->getCountries()->push_back(new Country(getCountry(*i))); } // Adjust funding to total $6M int missing = ((6000 - save->getCountryFunding()/1000) / (int)save->getCountries()->size()) * 1000; for (std::vector<Country*>::iterator i = save->getCountries()->begin(); i != save->getCountries()->end(); ++i) { (*i)->setFunding((*i)->getFunding().back() + missing); } save->setFunds(save->getCountryFunding()); // Add regions for (std::vector<std::string>::const_iterator i = _regionsIndex.begin(); i != _regionsIndex.end(); ++i) { save->getRegions()->push_back(new Region(getRegion(*i))); } // Set up IDs std::map<std::string, int> ids; for (std::vector<std::string>::const_iterator i = _craftsIndex.begin(); i != _craftsIndex.end(); ++i) { ids[*i] = 1; } save->initIds(ids); // Set up starting base Base *base = new Base(this); base->load(_startingBase, save, true); // Correct IDs for (std::vector<Craft*>::const_iterator i = base->getCrafts()->begin(); i != base->getCrafts()->end(); ++i) { save->getId((*i)->getRules()->getType()); } // Generate soldiers int soldiers = _startingBase["randomSoldiers"].as<int>(0); for (int i = 0; i < soldiers; ++i) { Soldier *soldier = new Soldier(getSoldier("XCOM"), getArmor("STR_NONE_UC"), &_names, save->getId("STR_SOLDIER")); soldier->setCraft(base->getCrafts()->front()); base->getSoldiers()->push_back(soldier); } save->getBases()->push_back(base); // Setup alien strategy save->getAlienStrategy().init(this); save->setTime(_startingTime); return save; }