* 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. */
| 103 | * @param game The game data. Used to find the UFO's mission. |
| 104 | */ |
| 105 | void Ufo::load(const YAML::Node &node, const Ruleset &ruleset, SavedGame &game) |
| 106 | { |
| 107 | MovingTarget::load(node); |
| 108 | _id = node["id"].as<int>(_id); |
| 109 | _crashId = node["crashId"].as<int>(_crashId); |
| 110 | _landId = node["landId"].as<int>(_landId); |
| 111 | _damage = node["damage"].as<int>(_damage); |
| 112 | _altitude = node["altitude"].as<std::string>(_altitude); |
| 113 | _direction = node["direction"].as<std::string>(_direction); |
| 114 | _detected = node["detected"].as<bool>(_detected); |
| 115 | _hyperDetected = node["hyperDetected"].as<bool>(_hyperDetected); |
| 116 | _secondsRemaining = node["secondsRemaining"].as<size_t>(_secondsRemaining); |
| 117 | _inBattlescape = node["inBattlescape"].as<bool>(_inBattlescape); |
| 118 | double lon = _lon; |
| 119 | double lat = _lat; |
| 120 | if (const YAML::Node &dest = node["dest"]) |
| 121 | { |
| 122 | lon = dest["lon"].as<double>(); |
| 123 | lat = dest["lat"].as<double>(); |
| 124 | } |
| 125 | _dest = new Waypoint(); |
| 126 | _dest->setLongitude(lon); |
| 127 | _dest->setLatitude(lat); |
| 128 | if (const YAML::Node &status = node["status"]) |
| 129 | { |
| 130 | _status = (UfoStatus)status.as<int>(); |
| 131 | } |
| 132 | else |
| 133 | { |
| 134 | if (_damage >= _rules->getMaxDamage()) |
| 135 | { |
| 136 | _status = DESTROYED; |
| 137 | } |
| 138 | else if (_damage >= _rules->getMaxDamage() / 2) |
| 139 | { |
| 140 | _status = CRASHED; |
| 141 | } |
| 142 | else if (_altitude == "STR_GROUND") |
| 143 | { |
| 144 | _status = LANDED; |
| 145 | } |
| 146 | else |
| 147 | { |
| 148 | _status = FLYING; |
| 149 | } |
| 150 | } |
| 151 | if (game.getMonthsPassed() != -1) |
| 152 | { |
| 153 | int missionID = node["mission"].as<int>(); |
| 154 | std::vector<AlienMission *>::const_iterator found = std::find_if(game.getAlienMissions().begin(), game.getAlienMissions().end(), matchMissionID(missionID)); |
| 155 | if (found == game.getAlienMissions().end()) |
| 156 | { |
| 157 | // Corrupt save file. |
| 158 | throw Exception("Unknown mission, save file is corrupt."); |
| 159 | } |
| 160 | _mission = *found; |
| 161 | |
| 162 | std::string tid = node["trajectory"].as<std::string>(); |
nothing calls this directly
no test coverage detected