Veinlook now goes to map edges

API change: isValidBlock now checks for map boundaries
API change: added getBlockPtr. It returns a DF pointer to a block.
develop
Petr Mrázek 2010-02-18 09:10:39 +08:00 committed by belal
parent 1a03986cf7
commit 502af1e096
3 changed files with 28 additions and 10 deletions

@ -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())

@ -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)
{

@ -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)