* Saves the saved battle game to a YAML file. * @return YAML node. */
| 353 | * @return YAML node. |
| 354 | */ |
| 355 | YAML::Node SavedBattleGame::save() const |
| 356 | { |
| 357 | YAML::Node node; |
| 358 | if (_objectiveDestroyed) |
| 359 | { |
| 360 | node["objectiveDestroyed"] = _objectiveDestroyed; |
| 361 | } |
| 362 | node["width"] = _mapsize_x; |
| 363 | node["length"] = _mapsize_y; |
| 364 | node["height"] = _mapsize_z; |
| 365 | node["missionType"] = _missionType; |
| 366 | node["globalshade"] = _globalShade; |
| 367 | node["turn"] = _turn; |
| 368 | node["selectedUnit"] = (_selectedUnit?_selectedUnit->getId():-1); |
| 369 | for (std::vector<MapDataSet*>::const_iterator i = _mapDataSets.begin(); i != _mapDataSets.end(); ++i) |
| 370 | { |
| 371 | node["mapdatasets"].push_back((*i)->getName()); |
| 372 | } |
| 373 | #if 0 |
| 374 | for (int i = 0; i < _mapsize_z * _mapsize_y * _mapsize_x; ++i) |
| 375 | { |
| 376 | if (!_tiles[i]->isVoid()) |
| 377 | { |
| 378 | node["tiles"].push_back(_tiles[i]->save()); |
| 379 | } |
| 380 | } |
| 381 | #else |
| 382 | // first, write out the field sizes we're going to use to write the tile data |
| 383 | node["tileIndexSize"] = Tile::serializationKey.index; |
| 384 | node["tileTotalBytesPer"] = Tile::serializationKey.totalBytes; |
| 385 | node["tileFireSize"] = Tile::serializationKey._fire; |
| 386 | node["tileSmokeSize"] = Tile::serializationKey._smoke; |
| 387 | node["tileIDSize"] = Tile::serializationKey._mapDataID; |
| 388 | node["tileSetIDSize"] = Tile::serializationKey._mapDataSetID; |
| 389 | node["tileBoolFieldsSize"] = Tile::serializationKey.boolFields; |
| 390 | |
| 391 | size_t tileDataSize = Tile::serializationKey.totalBytes * _mapsize_z * _mapsize_y * _mapsize_x; |
| 392 | Uint8* tileData = (Uint8*) calloc(tileDataSize, 1); |
| 393 | Uint8* w = tileData; |
| 394 | |
| 395 | for (int i = 0; i < _mapsize_z * _mapsize_y * _mapsize_x; ++i) |
| 396 | { |
| 397 | if (!_tiles[i]->isVoid()) |
| 398 | { |
| 399 | serializeInt(&w, Tile::serializationKey.index, i); |
| 400 | _tiles[i]->saveBinary(&w); |
| 401 | } |
| 402 | else |
| 403 | { |
| 404 | tileDataSize -= Tile::serializationKey.totalBytes; |
| 405 | } |
| 406 | } |
| 407 | node["totalTiles"] = tileDataSize / Tile::serializationKey.totalBytes; // not strictly necessary, just convenient |
| 408 | node["binTiles"] = YAML::Binary(tileData, tileDataSize); |
| 409 | free(tileData); |
| 410 | #endif |
| 411 | for (std::vector<Node*>::const_iterator i = _nodes.begin(); i != _nodes.end(); ++i) |
| 412 | { |
nothing calls this directly
no test coverage detected