Loading

Paste #palkdis9e

  1. /**
  2.  * Load a voxel stack from the save game file.
  3.  * @param ldr Input stream to read.
  4.  */
  5. void VoxelStack::Load(Loader &ldr)
  6. {
  7.     this->Clear();
  8.     uint32 version = ldr.OpenBlock("VSTK");
  9.     if (version == 1) {
  10.         int16 base = ldr.GetWord();
  11.         uint16 height = ldr.GetWord();
  12.         uint8 owner = ldr.GetByte();
  13.         if (base < 0 || base + height > WORLD_Z_SIZE || owner >= OWN_COUNT) {
  14.             ldr.SetFailMessage("Incorrect voxel stack size");
  15.         } else {
  16.             this->base = base;
  17.             this->height = height;
  18.             this->owner = (TileOwner)owner;
  19.             delete[] this->voxels;
  20.             this->voxels = (height > 0) ? MakeNewVoxels(height) : nullptr;
  21.             for (uint i = 0; i < height; i++) this->voxels[i].Load(ldr, version);
  22.         }
  23.     }
  24.     ldr.CloseBlock();
  25. }
  26.  
  27. /**
  28.  * Save a voxel stack to the save game file.
  29.  * @param svr Output stream to write.
  30.  */
  31. void VoxelStack::Save(Saver &svr) const
  32. {
  33.     svr.StartBlock("VSTK", 1);
  34.     svr.PutWord(this->base);
  35.     svr.PutWord(this->height);
  36.     svr.PutByte(this->owner);
  37.     for (uint i = 0; i < this->height; i++) this->voxels[i].Save(svr);
  38.     svr.EndBlock();
  39. }

Comments