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

Method load

src/Savegame/SavedBattleGame.cpp:117–312  ·  view source on GitHub ↗

* Loads the saved battle game from a YAML file. * @param node YAML node. * @param rule for the saved game. * @param savedGame Pointer to saved game. */

Source from the content-addressed store, hash-verified

115 * @param savedGame Pointer to saved game.
116 */
117void SavedBattleGame::load(const YAML::Node &node, Ruleset *rule, SavedGame* savedGame)
118{
119 _mapsize_x = node["width"].as<int>(_mapsize_x);
120 _mapsize_y = node["length"].as<int>(_mapsize_y);
121 _mapsize_z = node["height"].as<int>(_mapsize_z);
122 _missionType = node["missionType"].as<std::string>(_missionType);
123 _globalShade = node["globalshade"].as<int>(_globalShade);
124 _turn = node["turn"].as<int>(_turn);
125 int selectedUnit = node["selectedUnit"].as<int>();
126
127 for (YAML::const_iterator i = node["mapdatasets"].begin(); i != node["mapdatasets"].end(); ++i)
128 {
129 std::string name = i->as<std::string>();
130 MapDataSet *mds = rule->getMapDataSet(name);
131 _mapDataSets.push_back(mds);
132 }
133
134 initMap(_mapsize_x, _mapsize_y, _mapsize_z);
135
136 if (!node["tileTotalBytesPer"])
137 {
138 // binary tile data not found, load old-style text tiles :(
139 for (YAML::const_iterator i = node["tiles"].begin(); i != node["tiles"].end(); ++i)
140 {
141 Position pos = (*i)["position"].as<Position>();
142 getTile(pos)->load((*i));
143 }
144 }
145 else
146 {
147 // load key to how the tile data was saved
148 Tile::SerializationKey serKey;
149 size_t totalTiles = node["totalTiles"].as<size_t>();
150
151 memset(&serKey, 0, sizeof(Tile::SerializationKey));
152 serKey.index = node["tileIndexSize"].as<Uint8>(serKey.index);
153 serKey.totalBytes = node["tileTotalBytesPer"].as<Uint32>(serKey.totalBytes);
154 serKey._fire = node["tileFireSize"].as<Uint8>(serKey._fire);
155 serKey._smoke = node["tileSmokeSize"].as<Uint8>(serKey._smoke);
156 serKey._mapDataID = node["tileIDSize"].as<Uint8>(serKey._mapDataID);
157 serKey._mapDataSetID = node["tileSetIDSize"].as<Uint8>(serKey._mapDataSetID);
158 serKey.boolFields = node["tileBoolFieldsSize"].as<Uint8>(1); // boolean flags used to be stored in an unmentioned byte (Uint8) :|
159
160 // load binary tile data!
161 YAML::Binary binTiles = node["binTiles"].as<YAML::Binary>();
162
163 Uint8 *r = (Uint8*)binTiles.data();
164 Uint8 *dataEnd = r + totalTiles * serKey.totalBytes;
165
166 while (r < dataEnd)
167 {
168 int index = unserializeInt(&r, serKey.index);
169 assert (index >= 0 && index < _mapsize_x * _mapsize_z * _mapsize_y);
170 _tiles[index]->loadBinary(r, serKey); // loadBinary's privileges to advance *r have been revoked
171 r += serKey.totalBytes-serKey.index; // r is now incremented strictly by totalBytes in case there are obsolete fields present in the data
172 }
173 }
174 if (_missionType == "STR_BASE_DEFENSE")

Callers

nothing calls this directly

Calls 15

unserializeIntFunction · 0.85
getMapDataSetMethod · 0.80
loadBinaryMethod · 0.80
getDifficultyMethod · 0.80
isOutMethod · 0.80
getOriginalFactionMethod · 0.80
adjustStatsMethod · 0.80
setAIStateMethod · 0.80
setSlotMethod · 0.80
moveToOwnerMethod · 0.80
setAmmoItemMethod · 0.80
getSoldierMethod · 0.45

Tested by

no test coverage detected