diff --git a/library/include/dfhack/modules/Maps.h b/library/include/dfhack/modules/Maps.h index 8ba1d354b..30945f313 100644 --- a/library/include/dfhack/modules/Maps.h +++ b/library/include/dfhack/modules/Maps.h @@ -575,6 +575,8 @@ namespace DFHack /// get size of the map in tiles void getSize(uint32_t& x, uint32_t& y, uint32_t& z); + /// get the position of the map on world map + void getPosition(int32_t& x, int32_t& y, int32_t& z); /** * Return false/0 on failure, buffer allocated by client app, 256 items long diff --git a/library/modules/Maps.cpp b/library/modules/Maps.cpp index 3b212ec38..fd7be68d6 100644 --- a/library/modules/Maps.cpp +++ b/library/modules/Maps.cpp @@ -62,7 +62,7 @@ struct Maps::Private { uint32_t * block; uint32_t x_block_count, y_block_count, z_block_count; - uint32_t regionX, regionY, regionZ; + int32_t regionX, regionY, regionZ; uint32_t worldSizeX, worldSizeY; uint32_t maps_module; @@ -319,9 +319,9 @@ bool Maps::Start() } // read position of the region inside DF world - p->readDWord (off.region_x_offset, d->regionX); - p->readDWord (off.region_y_offset, d->regionY); - p->readDWord (off.region_z_offset, d->regionZ); + p->readDWord (off.region_x_offset, (uint32_t &) d->regionX); + p->readDWord (off.region_y_offset, (uint32_t &) d->regionY); + p->readDWord (off.region_z_offset, (uint32_t &) d->regionZ); // alloc array for pointers to all blocks d->block = new uint32_t[mx*my*mz]; @@ -355,6 +355,15 @@ void Maps::getSize (uint32_t& x, uint32_t& y, uint32_t& z) z = d->z_block_count; } +// getter for map position +void Maps::getPosition (int32_t& x, int32_t& y, int32_t& z) +{ + MAPS_GUARD + x = d->regionX; + y = d->regionY; + z = d->regionZ; +} + bool Maps::Finish() { if (d->block != NULL) diff --git a/tools/supported/position.cpp b/tools/supported/position.cpp index ebd46139e..e9008986e 100644 --- a/tools/supported/position.cpp +++ b/tools/supported/position.cpp @@ -17,9 +17,9 @@ std::ostream &operator<<(std::ostream &stream, DFHack::t_gamemodes funzies) "Legends", "Menus", "Arena", - "Arena - Assumed", - "Kittens!", - "Worldgen" + "Arena - Assumed", + "Kittens!", + "Worldgen" }; char * cm[]= { @@ -48,15 +48,19 @@ int main (int argc, char** argv) } DFHack::Gui * Gui = 0; + DFHack::Maps * Maps = 0; DFHack::World * World = 0; DFHack::ContextManager DFMgr("Memory.xml"); DFHack::Context * DF; + bool have_maps = false; try { DF = DFMgr.getSingleContext(); DF->Attach(); Gui = DF->getGui(); + Maps = DF->getMaps(); World = DF->getWorld(); + have_maps = Maps->Start(); } catch (exception& e) { @@ -77,13 +81,29 @@ int main (int argc, char** argv) << " Tick: " << World->ReadCurrentTick() << endl; if (Gui) { - int32_t x,y,z; + int32_t vx,vy,vz; + int32_t cx,cy,cz; + int32_t wx,wy,wz; int32_t width,height; - - if(Gui->getViewCoords(x,y,z)) - cout << "view coords: " << x << "/" << y << "/" << z << endl; - if(Gui->getCursorCoords(x,y,z)) - cout << "cursor coords: " << x << "/" << y << "/" << z << endl; + if(have_maps) + { + Maps->getPosition(wx,wy,wz); + cout << "Map world offset: " << wx << "/" << wy << "/" << wz << " embark squares." << endl; + } + bool have_cursor = Gui->getCursorCoords(cx,cy,cz); + bool have_view = Gui->getViewCoords(vx,vy,vz); + if(have_view) + { + cout << "view coords: " << vx << "/" << vy << "/" << vz << endl; + if(have_maps) + cout << " world: " << vx+wx*48 << "/" << vy+wy*48 << "/" << vz+wz << endl; + } + if(have_cursor) + { + cout << "cursor coords: " << cx << "/" << cy << "/" << cz << endl; + if(have_maps) + cout << " world: " << cx+wx*48 << "/" << cy+wy*48 << "/" << cz+wz << endl; + } if(Gui->getWindowSize(width,height)) cout << "window size : " << width << " " << height << endl; }