* Loads the craft from a YAML file. * @param node YAML node. * @param rule Ruleset for the saved game. * @param save Pointer to the saved game. */
| 83 | * @param save Pointer to the saved game. |
| 84 | */ |
| 85 | void Craft::load(const YAML::Node &node, const Ruleset *rule, SavedGame *save) |
| 86 | { |
| 87 | MovingTarget::load(node); |
| 88 | _id = node["id"].as<int>(_id); |
| 89 | _fuel = node["fuel"].as<int>(_fuel); |
| 90 | _damage = node["damage"].as<int>(_damage); |
| 91 | |
| 92 | if (const YAML::Node &dest = node["dest"]) |
| 93 | { |
| 94 | std::string type = dest["type"].as<std::string>(); |
| 95 | int id = dest["id"].as<int>(); |
| 96 | if (type == "STR_BASE") |
| 97 | { |
| 98 | returnToBase(); |
| 99 | } |
| 100 | else if (type == "STR_UFO") |
| 101 | { |
| 102 | for (std::vector<Ufo*>::iterator i = save->getUfos()->begin(); i != save->getUfos()->end(); ++i) |
| 103 | { |
| 104 | if ((*i)->getId() == id) |
| 105 | { |
| 106 | setDestination(*i); |
| 107 | break; |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | else if (type == "STR_WAYPOINT") |
| 112 | { |
| 113 | for (std::vector<Waypoint*>::iterator i = save->getWaypoints()->begin(); i != save->getWaypoints()->end(); ++i) |
| 114 | { |
| 115 | if ((*i)->getId() == id) |
| 116 | { |
| 117 | setDestination(*i); |
| 118 | break; |
| 119 | } |
| 120 | } |
| 121 | } |
| 122 | else if (type == "STR_TERROR_SITE") |
| 123 | { |
| 124 | for (std::vector<TerrorSite*>::iterator i = save->getTerrorSites()->begin(); i != save->getTerrorSites()->end(); ++i) |
| 125 | { |
| 126 | if ((*i)->getId() == id) |
| 127 | { |
| 128 | setDestination(*i); |
| 129 | break; |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | else if (type == "STR_ALIEN_BASE") |
| 134 | { |
| 135 | for (std::vector<AlienBase*>::iterator i = save->getAlienBases()->begin(); i != save->getAlienBases()->end(); ++i) |
| 136 | { |
| 137 | if ((*i)->getId() == id) |
| 138 | { |
| 139 | setDestination(*i); |
| 140 | break; |
| 141 | } |
| 142 | } |
nothing calls this directly
no test coverage detected