dfhack/tools/examples/construction_dump.cpp

96 lines
2.9 KiB
C++

2010-04-09 16:24:41 -06:00
// Just show some position data
#include <iostream>
#include <iomanip>
#include <climits>
#include <vector>
#include <sstream>
#include <ctime>
#include <cstdio>
2010-06-04 16:02:02 -06:00
#include <stdio.h>
2010-04-09 16:24:41 -06:00
2010-06-04 16:02:02 -06:00
#define DFHACK_WANT_MISCUTILS
2010-05-25 22:48:23 -06:00
#include <DFHack.h>
2010-04-09 16:24:41 -06:00
using namespace DFHack;
int main (int numargs, const char ** args)
{
2010-05-23 15:06:10 -06:00
DFHack::ContextManager DFMgr("Memory.xml");
DFHack::Context* DF;
2010-04-09 16:24:41 -06:00
try
{
2010-05-23 15:06:10 -06:00
DF = DFMgr.getSingleContext();
DF->Attach();
2010-04-09 16:24:41 -06:00
}
2010-06-04 16:02:02 -06:00
catch (std::exception& e)
2010-04-09 16:24:41 -06:00
{
2010-06-04 16:02:02 -06:00
std::cerr << e.what() << std::endl;
2010-04-09 16:24:41 -06:00
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
2011-03-18 04:38:37 -06:00
DFHack::Gui *Gui = DF->getGui();
2010-04-09 16:24:41 -06:00
2010-05-23 15:06:10 -06:00
DFHack::Constructions *Cons = DF->getConstructions();
DFHack::Materials *Mats = DF->getMaterials();
2010-04-28 10:09:32 -06:00
Mats->ReadInorganicMaterials();
2010-06-06 17:54:40 -06:00
Mats->ReadOrganicMaterials();
2010-04-09 16:24:41 -06:00
uint32_t numConstr;
Cons->Start(numConstr);
int32_t cx, cy, cz;
2011-03-18 04:38:37 -06:00
Gui->getCursorCoords(cx,cy,cz);
2010-04-09 16:24:41 -06:00
if(cx != -30000)
{
t_construction con;
for(uint32_t i = 0; i < numConstr; i++)
{
Cons->Read(i,con);
if(cx == con.x && cy == con.y && cz == con.z)
{
printf("Construction %d/%d/%d @ 0x%x\n", con.x, con.y, con.z,con.origin);
// inorganic stuff - we can recognize that
2010-04-09 21:48:50 -06:00
printf("Material: form %d, type %d, index %d\n",con.form, con.mat_type, con.mat_idx);
2010-06-04 16:02:02 -06:00
std::string matstr = "unknown";
2010-04-09 16:24:41 -06:00
if(con.mat_type == 0)
{
if(con.mat_idx != 0xffffffff)
2010-04-28 10:09:32 -06:00
matstr = Mats->inorganic[con.mat_idx].id;
else matstr = "inorganic";
2010-04-09 16:24:41 -06:00
}
2010-06-06 17:54:40 -06:00
if(con.mat_type == 420)
{
if(con.mat_idx != 0xffffffff)
matstr = Mats->organic[con.mat_idx].id;
else matstr = "organic";
}
2010-04-09 21:48:50 -06:00
switch(con.form)
2010-04-09 16:24:41 -06:00
{
case constr_bar:
printf("It is made of %s bars!\n",matstr.c_str());
break;
case constr_block:
printf("It is made of %s blocks!\n",matstr.c_str());
break;
case constr_boulder:
printf("It is made of %s stones!\n",matstr.c_str());
break;
case constr_logs:
printf("It is made of %s logs!\n",matstr.c_str());
break;
default:
printf("It is made of something we don't know yet! The material is %s.\n",matstr.c_str());
}
hexdump(DF,con.origin,32);
2010-04-09 16:24:41 -06:00
}
}
}
#ifndef LINUX_BUILD
cout << "Done. Press any key to continue" << endl;
cin.ignore();
#endif
return 0;
}