diff --git a/examples/veinlook.cpp b/examples/veinlook.cpp index a77f284c1..87832944c 100644 --- a/examples/veinlook.cpp +++ b/examples/veinlook.cpp @@ -272,11 +272,12 @@ main(int argc, char *argv[]) finish(0); } + // FIXME: could fail on small forts int cursorX = x_max/2 - 1; int cursorY = y_max/2 - 1; int cursorZ = z_max/2 - 1; - // FIXME: could fail on small forts + int vein = 0; // walk the map! @@ -318,13 +319,15 @@ main(int argc, char *argv[]) cursorY = max(cursorY, 0); cursorZ = max(cursorZ, 0); - cursorX = min(cursorX, x_max - 3); - cursorY = min(cursorY, y_max - 3); - cursorZ = min(cursorZ, z_max - 3); + cursorX = min(cursorX, x_max - 1); + cursorY = min(cursorY, y_max - 1); + cursorZ = min(cursorZ, z_max - 1); DF.Suspend(); - for(int i = 0; i < 3; i++) - for(int j = 0; j < 3; j++) + for(int i = -1; i <= 1; i++) + { + for(int j = -1; j <= 1; j++) + { if(DF.isValidBlock(cursorX+i,cursorY+j,cursorZ)) { // read data @@ -338,22 +341,24 @@ main(int argc, char *argv[]) color = pickColor(tiletypes[x][y]); if(designations[x][y].bits.hidden) { - puttile(x+i*16,y+j*16,tiletypes[x][y], color); + puttile(x+(i+1)*16,y+(j+1)*16,tiletypes[x][y], color); } else { attron(A_STANDOUT); - puttile(x+i*16,y+j*16,tiletypes[x][y], color); + puttile(x+(i+1)*16,y+(j+1)*16,tiletypes[x][y], color); attroff(A_STANDOUT); } } } - if(i == 1 && j == 1) + if(i == 0 && j == 0) { veinVector.clear(); DF.ReadVeins(cursorX+i,cursorY+j,cursorZ,veinVector); } } + } + } gotoxy(0,48); cprintf("arrow keys, PGUP, PGDN = navigate"); gotoxy(0,49); @@ -361,7 +366,7 @@ main(int argc, char *argv[]) gotoxy(0,50); if(vein == veinVector.size()) vein = veinVector.size() - 1; if(vein < -1) vein = -1; - cprintf("X %d/%d, Y %d/%d, Z %d/%d. Vein %d of %d",cursorX + 1,x_max,cursorY + 1,y_max,cursorZ + 1,z_max,vein+1,veinVector.size()); + cprintf("X %d/%d, Y %d/%d, Z %d/%d. Vein %d of %d",cursorX+1,x_max,cursorY+1,y_max,cursorZ,z_max,vein+1,veinVector.size()); if(!veinVector.empty()) { if(vein != -1 && vein < veinVector.size()) diff --git a/library/DFHackAPI.cpp b/library/DFHackAPI.cpp index 602f90e60..3594773dd 100644 --- a/library/DFHackAPI.cpp +++ b/library/DFHackAPI.cpp @@ -221,9 +221,18 @@ bool API::DestroyMap() bool API::isValidBlock (uint32_t x, uint32_t y, uint32_t z) { + if (x < 0 || x >= d->x_block_count || y < 0 || y >= d->y_block_count || z < 0 || z >= d->z_block_count) + return false; return d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z] != 0; } +uint32_t API::getBlockPtr (uint32_t x, uint32_t y, uint32_t z) +{ + if (x < 0 || x >= d->x_block_count || y < 0 || y >= d->y_block_count || z < 0 || z >= d->z_block_count) + return 0; + return d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z]; +} + // 256 * sizeof(uint16_t) bool API::ReadTileTypes (uint32_t x, uint32_t y, uint32_t z, uint16_t *buffer) { diff --git a/library/DFHackAPI.h b/library/DFHackAPI.h index ce7ef8dac..7601d17d7 100644 --- a/library/DFHackAPI.h +++ b/library/DFHackAPI.h @@ -128,6 +128,10 @@ namespace DFHack * Return false/0 on failure, buffer allocated by client app, 256 items long */ bool isValidBlock(uint32_t blockx, uint32_t blocky, uint32_t blockz); + /** + * Get the address of a block or 0 if block is not valid + */ + uint32_t getBlockPtr (uint32_t x, uint32_t y, uint32_t z); bool ReadTileTypes(uint32_t blockx, uint32_t blocky, uint32_t blockz, uint16_t *buffer); // 256 * sizeof(uint16_t) bool WriteTileTypes(uint32_t blockx, uint32_t blocky, uint32_t blockz, uint16_t *buffer); // 256 * sizeof(uint16_t)