本文整理汇总了C++中Country::load方法的典型用法代码示例。如果您正苦于以下问题:C++ Country::load方法的具体用法?C++ Country::load怎么用?C++ Country::load使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Country
的用法示例。
在下文中一共展示了Country::load方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: load
/**
* 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.
*/
void SavedGame::load(const std::string &filename, Ruleset *rule)
{
std::string s = Options::getUserFolder() + filename + ".sav";
std::ifstream fin(s.c_str());
if (!fin)
{
throw Exception("Failed to load savegame");
}
YAML::Parser parser(fin);
YAML::Node doc;
// Get brief save info
parser.GetNextDocument(doc);
std::string v;
doc["version"] >> v;
if (v != Options::getVersion())
{
throw Exception("Version mismatch");
}
_time->load(doc["time"]);
// Get full save data
parser.GetNextDocument(doc);
int a = 0;
doc["difficulty"] >> a;
_difficulty = (GameDifficulty)a;
doc["funds"] >> _funds;
for (YAML::Iterator i = doc["countries"].begin(); i != doc["countries"].end(); ++i)
{
std::string type;
(*i)["type"] >> type;
Country *c = new Country(rule->getCountry(type), false);
c->load(*i);
_countries.push_back(c);
}
for (YAML::Iterator i = doc["regions"].begin(); i != doc["regions"].end(); ++i)
{
std::string type;
(*i)["type"] >> type;
Region *r = new Region(rule->getRegion(type));
r->load(*i);
_regions.push_back(r);
}
for (YAML::Iterator i = doc["ufos"].begin(); i != doc["ufos"].end(); ++i)
{
std::string type;
(*i)["type"] >> type;
Ufo *u = new Ufo(rule->getUfo(type));
u->load(*i);
_ufos.push_back(u);
}
doc["craftId"] >> _craftId;
for (YAML::Iterator i = doc["waypoints"].begin(); i != doc["waypoints"].end(); ++i)
{
Waypoint *w = new Waypoint();
w->load(*i);
_waypoints.push_back(w);
}
doc["ufoId"] >> _ufoId;
doc["waypointId"] >> _waypointId;
doc["soldierId"] >> _soldierId;
for (YAML::Iterator i = doc["bases"].begin(); i != doc["bases"].end(); ++i)
{
Base *b = new Base(rule);
b->load(*i, this);
_bases.push_back(b);
}
for(YAML::Iterator it=doc["discovered"].begin();it!=doc["discovered"].end();++it)
{
std::string research;
*it >> research;
_discovered.push_back(rule->getResearchProject(research));
}
if (const YAML::Node *pName = doc.FindValue("battleGame"))
{
_battleGame = new SavedBattleGame();
_battleGame->load(*pName, rule, this);
}
fin.close();
}
示例2: load
/**
* 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.
*/
void SavedGame::load(const std::string &filename, Ruleset *rule)
{
unsigned int size = 0;
std::string s = USER_DIR + filename + ".sav";
std::ifstream fin(s.c_str());
if (!fin)
{
throw Exception("Failed to load savegame");
}
YAML::Parser parser(fin);
YAML::Node doc;
// Get brief save info
parser.GetNextDocument(doc);
std::string v;
doc["version"] >> v;
if (v != "0.2")
{
throw Exception("Version mismatch");
}
_time->load(doc["time"]);
// Get full save data
parser.GetNextDocument(doc);
int a;
doc["difficulty"] >> a;
_difficulty = (GameDifficulty)a;
doc["funds"] >> _funds;
size = doc["countries"].size();
for (unsigned int i = 0; i < size; i++)
{
std::string type;
doc["countries"][i]["type"] >> type;
Country *c = new Country(rule->getCountry(type), false);
c->load(doc["countries"][i]);
_countries.push_back(c);
}
size = doc["regions"].size();
for (unsigned int i = 0; i < size; i++)
{
std::string type;
doc["regions"][i]["type"] >> type;
Region *r = new Region(rule->getRegion(type));
r->load(doc["regions"][i]);
_regions.push_back(r);
}
size = doc["ufos"].size();
for (unsigned int i = 0; i < size; i++)
{
std::string type;
doc["ufos"][i]["type"] >> type;
Ufo *u = new Ufo(rule->getUfo(type));
u->load(doc["ufos"][i]);
_ufos.push_back(u);
}
doc["craftId"] >> _craftId;
size = doc["waypoints"].size();
for (unsigned int i = 0; i < size; i++)
{
Waypoint *w = new Waypoint();
w->load(doc["waypoints"][i]);
_waypoints.push_back(w);
}
doc["ufoId"] >> _ufoId;
doc["waypointId"] >> _waypointId;
size = doc["bases"].size();
for (unsigned int i = 0; i < size; i++)
{
Base *b = new Base(rule);
b->load(doc["bases"][i], this);
_bases.push_back(b);
}
if (const YAML::Node *pName = doc.FindValue("battleGame"))
{
_battleGame = new SavedBattleGame();
_battleGame->load(*pName);
}
fin.close();
}