dfhack/tools/supported/position.cpp

129 lines
3.3 KiB
C++

// Just show some position data
#include <iostream>
#include <climits>
#include <vector>
#include <ctime>
using namespace std;
2010-05-25 22:48:23 -06:00
#include <DFHack.h>
std::ostream &operator<<(std::ostream &stream, DFHack::t_gamemodes funzies)
{
const char * gm[]=
{
"Fort",
"Adventurer",
"Legends",
"Menus",
"Arena",
2011-03-23 23:13:21 -06:00
"Arena - Assumed",
"Kittens!",
"Worldgen"
};
const char * cm[]=
{
"Managing",
"Direct Control",
"Kittens!",
"Menus"
};
if(funzies.game_mode <= DFHack::GM_MAX && funzies.control_mode <= DFHack::CM_MAX)
stream << "Game mode: " << gm[funzies.game_mode] << ", Control mode: " << cm[funzies.control_mode];
else
stream << "Game mode is too funky: (" << funzies.game_mode << "," << funzies.control_mode << ")";
return stream;
}
int main (int argc, char** argv)
{
bool quiet = false;
for(int i = 1; i < argc; i++)
{
string test = argv[i];
if(test == "-q")
{
quiet = true;
}
}
2011-03-18 04:38:37 -06:00
DFHack::Gui * Gui = 0;
2011-03-23 23:13:21 -06:00
DFHack::Maps * Maps = 0;
DFHack::World * World = 0;
2010-05-23 15:06:10 -06:00
DFHack::ContextManager DFMgr("Memory.xml");
DFHack::Context * DF;
2011-03-23 23:13:21 -06:00
bool have_maps = false;
try
{
2010-05-23 15:06:10 -06:00
DF = DFMgr.getSingleContext();
DF->Attach();
2011-03-18 04:38:37 -06:00
Gui = DF->getGui();
2011-03-23 23:13:21 -06:00
Maps = DF->getMaps();
World = DF->getWorld();
2011-03-23 23:13:21 -06:00
have_maps = Maps->Start();
}
catch (exception& e)
{
cerr << e.what() << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
DFHack::t_gamemodes gmm;
if(World->ReadGameMode(gmm))
{
cout << gmm << endl;
}
2011-03-06 14:20:08 -07:00
cout << "Year: " << World->ReadCurrentYear()
<< " Month: " << World->ReadCurrentMonth()
<< " Day: " << World->ReadCurrentDay()
<< " Tick: " << World->ReadCurrentTick() << endl;
2011-03-18 04:38:37 -06:00
if (Gui)
{
2011-03-23 23:13:21 -06:00
int32_t vx,vy,vz;
int32_t cx,cy,cz;
int32_t wx,wy,wz;
int32_t width,height;
2011-03-23 23:13:21 -06:00
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;
}
2011-03-18 04:38:37 -06:00
if(Gui->getWindowSize(width,height))
cout << "window size : " << width << " " << height << endl;
}
else
{
cerr << "cursor and window parameters are unsupported on your version of DF" << endl;
}
2010-05-23 15:06:10 -06:00
if(!DF->Detach())
{
cerr << "Can't detach from DF" << endl;
}
#ifndef LINUX_BUILD
if(!quiet)
{
cout << "Done. Press any key to continue" << endl;
cin.ignore();
}
#endif
return 0;
}