diff options
| author | Alexander Gavrilov | 2012-09-06 22:45:19 +0400 |
|---|---|---|
| committer | Alexander Gavrilov | 2012-09-06 22:45:19 +0400 |
| commit | c971a819def1c5cc29dc926f62456c336a1dfa17 (patch) | |
| tree | a03b4fd14884603b15a5e96609408603c6566b12 /library/modules | |
| parent | d0e630d4c35717bad682894e33e7dd57f86ac126 (diff) | |
| download | dfhack-c971a819def1c5cc29dc926f62456c336a1dfa17.tar.gz dfhack-c971a819def1c5cc29dc926f62456c336a1dfa17.tar.bz2 dfhack-c971a819def1c5cc29dc926f62456c336a1dfa17.tar.xz | |
Experimental creation of map blocks in gui/liquids script.
Diffstat (limited to 'library/modules')
| -rw-r--r-- | library/modules/Maps.cpp | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/library/modules/Maps.cpp b/library/modules/Maps.cpp index 305f1296..d0401164 100644 --- a/library/modules/Maps.cpp +++ b/library/modules/Maps.cpp @@ -157,6 +157,39 @@ df::map_block *Maps::getTileBlock (int32_t x, int32_t y, int32_t z) return world->map.block_index[x >> 4][y >> 4][z]; } +df::map_block *Maps::ensureTileBlock (int32_t x, int32_t y, int32_t z) +{ + if (!isValidTilePos(x,y,z)) + return NULL; + + auto column = world->map.block_index[x >> 4][y >> 4]; + auto &slot = column[z]; + if (slot) + return slot; + + // Find another block below + int z2 = z; + while (z2 >= 0 && !column[z2]) z2--; + if (z2 < 0) + return NULL; + + slot = new df::map_block(); + slot->region_pos = column[z2]->region_pos; + slot->map_pos = column[z2]->map_pos; + slot->map_pos.z = z; + + // Assume sky + df::tile_designation dsgn(0); + dsgn.bits.light = true; + dsgn.bits.outside = true; + + for (int tx = 0; tx < 16; tx++) + for (int ty = 0; ty < 16; ty++) + slot->designation[tx][ty] = dsgn; + + return slot; +} + df::tiletype *Maps::getTileType(int32_t x, int32_t y, int32_t z) { df::map_block *block = getTileBlock(x,y,z); @@ -513,8 +546,14 @@ MapExtras::Block::Block(MapCache *parent, DFCoord _bcoord) : parent(parent) valid = false; bcoord = _bcoord; block = Maps::getBlock(bcoord); - item_counts = NULL; tags = NULL; + + init(); +} + +void MapExtras::Block::init() +{ + item_counts = NULL; tiles = NULL; basemats = NULL; @@ -537,6 +576,23 @@ MapExtras::Block::Block(MapCache *parent, DFCoord _bcoord) : parent(parent) } } +bool MapExtras::Block::Allocate() +{ + if (block) + return true; + + block = Maps::ensureTileBlock(bcoord.x*16, bcoord.y*16, bcoord.z); + if (!block) + return false; + + delete item_counts; + delete tiles; + delete basemats; + init(); + + return true; +} + MapExtras::Block::~Block() { delete[] item_counts; |
