Example #1
0
/**
 * Loads the UFO from a YAML file.
 * @param node YAML node.
 * @param ruleset The game rules. 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 Ruleset &ruleset, SavedGame &game)
{
	MovingTarget::load(node);
	node["id"] >> _id;
	node["damage"] >> _damage;
	node["altitude"] >> _altitude;
	node["direction"] >> _direction;
	node["detected"] >> _detected;
	node["hyperDetected"] >> _hyperDetected;
	node["secondsRemaining"] >> _secondsRemaining;
	node["inBattlescape"] >> _inBattlescape;
	double lon, lat;
	node["dest"]["lon"] >> lon;
	node["dest"]["lat"] >> lat;
	_dest = new Waypoint();
	_dest->setLongitude(lon);
	_dest->setLatitude(lat);
	if (_altitude == "STR_GROUND")
	{
		_status = LANDED;
	}
	else
	{
		_status = FLYING;
	}
	if (_damage >= _rules->getMaxDamage())
	{
		_status = DESTROYED;
	}
	else if (_damage >= _rules->getMaxDamage() / 2)
	{
		_status = CRASHED;
	}
	int missionID;
	node["mission"] >> missionID;
	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 mission, save file is corrupt.");
	}
	_mission = *found;

	std::string tid;
	node["trajectory"] >> tid;
	_trajectory = ruleset.getUfoTrajectory(tid);
	node["trajectoryPoint"] >> _trajectoryPoint;
	if (_inBattlescape)
		setSpeed(0);
}
Example #2
0
/**
 * Loads the UFO from a YAML file.
 * @param node YAML node.
 * @param ruleset The game rules. 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 Ruleset &ruleset, SavedGame &game)
{
	MovingTarget::load(node);
	_id = node["id"].as<int>(_id);
	_crashId = node["crashId"].as<int>(_crashId);
	_landId = node["landId"].as<int>(_landId);
	_damage = node["damage"].as<int>(_damage);
	_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 >= _rules->getMaxDamage())
		{
			_status = DESTROYED;
		}
		else if (_damage >= _rules->getMaxDamage() / 2)
		{
			_status = CRASHED;
		}
		else if (_altitude == "STR_GROUND")
		{
			_status = LANDED;
		}
		else
		{
			_status = FLYING;
		}
	}
	if (game.getMonthsPassed() != -1)
	{
		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 mission, save file is corrupt.");
		}
		_mission = *found;

		std::string tid = node["trajectory"].as<std::string>();
		_trajectory = ruleset.getUfoTrajectory(tid);
		_trajectoryPoint = node["trajectoryPoint"].as<size_t>(_trajectoryPoint);
	}
	_fireCountdown = node["fireCountdown"].as<int>(_fireCountdown);
	_escapeCountdown = node["escapeCountdown"].as<int>(_escapeCountdown);
	if (_inBattlescape)
		setSpeed(0);
}