MCPcopy Create free account
hub / github.com/OpenXcom/OpenXcom / load

Method load

src/Savegame/Base.cpp:105–207  ·  view source on GitHub ↗

* Loads the base from a YAML file. * @param node YAML node. * @param save Pointer to saved game. * @param newGame Is this the first base of a new game? * @param newBattleGame Is this the base of a skirmish game? */

Source from the content-addressed store, hash-verified

103 * @param newBattleGame Is this the base of a skirmish game?
104 */
105void Base::load(const YAML::Node &node, SavedGame *save, bool newGame, bool newBattleGame)
106{
107 Target::load(node);
108 _name = Language::utf8ToWstr(node["name"].as<std::string>(""));
109
110 if (!newGame || !Options::customInitialBase || newBattleGame)
111 {
112 for (YAML::const_iterator i = node["facilities"].begin(); i != node["facilities"].end(); ++i)
113 {
114 std::string type = (*i)["type"].as<std::string>();
115 if (_rule->getBaseFacility(type))
116 {
117 BaseFacility *f = new BaseFacility(_rule->getBaseFacility(type), this);
118 f->load(*i);
119 _facilities.push_back(f);
120 }
121 }
122 }
123
124 for (YAML::const_iterator i = node["crafts"].begin(); i != node["crafts"].end(); ++i)
125 {
126 std::string type = (*i)["type"].as<std::string>();
127 if (_rule->getCraft(type))
128 {
129 Craft *c = new Craft(_rule->getCraft(type), this);
130 c->load(*i, _rule, save);
131 _crafts.push_back(c);
132 }
133 }
134
135 for (YAML::const_iterator i = node["soldiers"].begin(); i != node["soldiers"].end(); ++i)
136 {
137 Soldier *s = new Soldier(_rule->getSoldier("XCOM"), _rule->getArmor("STR_NONE_UC"));
138 s->load(*i, _rule, save);
139 s->setCraft(0);
140 if (const YAML::Node &craft = (*i)["craft"])
141 {
142 std::string type = craft["type"].as<std::string>();
143 int id = craft["id"].as<int>();
144 for (std::vector<Craft*>::iterator j = _crafts.begin(); j != _crafts.end(); ++j)
145 {
146 if ((*j)->getRules()->getType() == type && (*j)->getId() == id)
147 {
148 s->setCraft(*j);
149 break;
150 }
151 }
152 }
153 _soldiers.push_back(s);
154 }
155
156 _items->load(node["items"]);
157 // Some old saves have bad items, better get rid of them to avoid further bugs
158 for (std::map<std::string, int>::iterator i = _items->getContents()->begin(); i != _items->getContents()->end();)
159 {
160 if (std::find(_rule->getItemsList().begin(), _rule->getItemsList().end(), i->first) == _rule->getItemsList().end())
161 {
162 _items->getContents()->erase(i++);

Callers

nothing calls this directly

Calls 12

loadFunction · 0.85
getBaseFacilityMethod · 0.80
getContentsMethod · 0.80
getResearchMethod · 0.80
getManufactureMethod · 0.80
getCraftMethod · 0.45
getSoldierMethod · 0.45
getArmorMethod · 0.45
setCraftMethod · 0.45
getTypeMethod · 0.45
getRulesMethod · 0.45
getIdMethod · 0.45

Tested by

no test coverage detected