/**
* Load a voxel stack from the save game file.
* @param ldr Input stream to read.
*/
void VoxelStack::Load(Loader &ldr)
{
this->Clear();
uint32 version = ldr.OpenBlock("VSTK");
if (version == 1) {
int16 base = ldr.GetWord();
uint16 height = ldr.GetWord();
uint8 owner = ldr.GetByte();
if (base < 0 || base + height > WORLD_Z_SIZE || owner >= OWN_COUNT) {
ldr.SetFailMessage("Incorrect voxel stack size");
} else {
this->base = base;
this->height = height;
this->owner = (TileOwner)owner;
delete[] this->voxels;
this->voxels = (height > 0) ? MakeNewVoxels(height) : nullptr;
for (uint i = 0; i < height; i++) this->voxels[i].Load(ldr, version);
}
}
ldr.CloseBlock();
}
/**
* Save a voxel stack to the save game file.
* @param svr Output stream to write.
*/
void VoxelStack::Save(Saver &svr) const
{
svr.StartBlock("VSTK", 1);
svr.PutWord(this->base);
svr.PutWord(this->height);
svr.PutByte(this->owner);
for (uint i = 0; i < this->height; i++) this->voxels[i].Save(svr);
svr.EndBlock();
}