本文整理汇总了C++中Ufo::load方法的典型用法代码示例。如果您正苦于以下问题:C++ Ufo::load方法的具体用法?C++ Ufo::load怎么用?C++ Ufo::load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ufo
的用法示例。
在下文中一共展示了Ufo::load方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: load
/**
* Loads the UFO from a YAML file.
* @param node YAML node.
* @param mod The game mod. Use to access the trajectory rules.
* @param game The game data. Used to find the UFO's mission.
*/
void Ufo::load(const YAML::Node &node, const Mod *mod, SavedGame *game, Ufo *escorting)
{
MovingTarget::load(node);
_id = node["id"].as<int>(_id);
_escorting = escorting;
_escortId = node["escortId"].as<int>(_escortId);
_escortingId = node["escortingId"].as<int>(_escortingId);
_crashId = node["crashId"].as<int>(_crashId);
_landId = node["landId"].as<int>(_landId);
_damage = node["damage"].as<int>(_damage);
_shield = node["shield"].as<int>(_shield);
_shieldRechargeHandle = node["shieldRechargeHandle"].as<int>(_shieldRechargeHandle);
_altitude = node["altitude"].as<std::string>(_altitude);
_direction = node["direction"].as<std::string>(_direction);
_detected = node["detected"].as<bool>(_detected);
_hyperDetected = node["hyperDetected"].as<bool>(_hyperDetected);
_secondsRemaining = node["secondsRemaining"].as<size_t>(_secondsRemaining);
_inBattlescape = node["inBattlescape"].as<bool>(_inBattlescape);
double lon = _lon;
double lat = _lat;
if (const YAML::Node &dest = node["dest"])
{
lon = dest["lon"].as<double>();
lat = dest["lat"].as<double>();
}
_dest = new Waypoint();
_dest->setLongitude(lon);
_dest->setLatitude(lat);
if (const YAML::Node &status = node["status"])
{
_status = (UfoStatus)status.as<int>();
}
else
{
if (_damage >= _stats.damageMax)
{
_status = DESTROYED;
}
else if (_damage >= _stats.damageMax / 2)
{
_status = CRASHED;
}
else if (_altitude == "STR_GROUND")
{
_status = LANDED;
}
else
{
_status = FLYING;
}
}
if (game->getMonthsPassed() != -1 && node["mission"])
{
int missionID = node["mission"].as<int>();
std::vector<AlienMission *>::const_iterator found = std::find_if (game->getAlienMissions().begin(), game->getAlienMissions().end(), matchMissionID(missionID));
if (found == game->getAlienMissions().end())
{
// Corrupt save file.
throw Exception("Unknown UFO mission, save file is corrupt.");
}
_mission = *found;
_stats += _rules->getRaceBonus(_mission->getRace());
std::string tid = node["trajectory"].as<std::string>();
_trajectory = mod->getUfoTrajectory(tid);
if (_trajectory == 0)
{
// Corrupt save file.
throw Exception("Unknown UFO trajectory, save file is corrupt.");
}
_trajectoryPoint = node["trajectoryPoint"].as<size_t>(_trajectoryPoint);
}
_fireCountdown = node["fireCountdown"].as<int>(_fireCountdown);
_escapeCountdown = node["escapeCountdown"].as<int>(_escapeCountdown);
_retreating = node["retreating"].as<bool>(_retreating);
for (YAML::const_iterator ii = node["escorts"].begin(); ii != node["escorts"].end(); ++ii)
{
std::string type = (*ii)["type"].as<std::string>();
if (mod->getUfo(type))
{
Ufo *u = new Ufo(mod->getUfo(type), false);
u->load(*ii, mod, game, this);
_escorts.push_back(u);
}
/*else
{
Log(LOG_ERROR) << "Failed to load UFO " << type;
}*/
}
if (_inBattlescape)
setSpeed(0);
}
示例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)
{
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();
}
示例3: 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();
}