dfhack/tools/supported/probe.cpp

133 lines
4.5 KiB
C++

// 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
#define DFHACK_WANT_MISCUTILS
#define DFHACK_WANT_TILETYPES
2010-05-25 22:48:23 -06:00
#include <DFHack.h>
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 = DFMgr.getSingleContext();
try
{
2010-05-23 15:06:10 -06:00
DF->Attach();
}
2010-06-04 16:02:02 -06:00
catch (std::exception& e)
{
2010-06-04 16:02:02 -06:00
std::cerr << e.what() << std::endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
2010-08-28 14:07:31 -06:00
2010-05-23 15:06:10 -06:00
DFHack::Position *Pos = DF->getPosition();
DFHack::VersionInfo* mem = DF->getMemoryInfo();
2010-05-23 15:06:10 -06:00
DFHack::Maps *Maps = DF->getMaps();
DFHack::Process * p = DF->getProcess();
2010-08-28 14:07:31 -06:00
OffsetGroup *mapsg = mem->getGroup("Maps");
OffsetGroup *mapblockg = mapsg->getGroup("block");
OffsetGroup *localfeatg = mapsg->getGroup("features")->getGroup("local");
uint32_t region_x_offset = mapsg->getAddress("region_x");
uint32_t region_y_offset = mapsg->getAddress("region_y");
uint32_t region_z_offset = mapsg->getAddress("region_z");
uint32_t designatus = mapblockg->getOffset("designation");
uint32_t block_feature1 = mapblockg->getOffset("feature_local");
uint32_t block_feature2 = mapblockg->getOffset("feature_global");
uint32_t feature1_start_ptr = localfeatg->getAddress("start_ptr");
int32_t regionX, regionY, regionZ;
2010-08-28 14:07:31 -06:00
// read position of the region inside DF world
p->readDWord (region_x_offset, (uint32_t &)regionX);
p->readDWord (region_y_offset, (uint32_t &)regionY);
p->readDWord (region_z_offset, (uint32_t &)regionZ);
2010-08-28 14:07:31 -06:00
Maps->Start();
2010-08-28 14:07:31 -06:00
int32_t cursorX, cursorY, cursorZ;
Pos->getCursorCoords(cursorX,cursorY,cursorZ);
if(cursorX != -30000)
{
uint32_t blockX = cursorX / 16;
uint32_t tileX = cursorX % 16;
uint32_t blockY = cursorY / 16;
uint32_t tileY = cursorY % 16;
t_temperatures tmpb1, tmpb2;
mapblock40d block;
if(Maps->ReadBlock40d(blockX,blockY,cursorZ,&block))
{
Maps->ReadTemperatures(blockX,blockY,cursorZ,&tmpb1, &tmpb2);
printf("block addr: 0x%x\n", block.origin);
int16_t tiletype = block.tiletypes[tileX][tileY];
naked_designation &des = block.designation[tileX][tileY].bits;
uint32_t &desw = block.designation[tileX][tileY].whole;
2010-06-04 16:02:02 -06:00
print_bits<uint32_t>(block.designation[tileX][tileY].whole,std::cout);
std::cout << endl;
print_bits<uint32_t>(block.occupancy[tileX][tileY].whole,std::cout);
std::cout << endl;
2010-08-28 14:07:31 -06:00
// tiletype
2010-06-04 16:02:02 -06:00
std::cout <<"tiletype: " << tiletype;
if(tileTypeTable[tiletype].name)
2010-06-04 16:02:02 -06:00
std::cout << " = " << tileTypeTable[tiletype].name;
std::cout << std::endl;
std::cout <<"temperature1: " << tmpb1[tileX][tileY] << " U" << std::endl;
std::cout <<"temperature2: " << tmpb2[tileX][tileY] << " U" << std::endl;
2010-08-28 14:07:31 -06:00
// biome, geolayer
2010-06-04 16:02:02 -06:00
std::cout << "biome: " << des.biome << std::endl;
std::cout << "geolayer: " << des.geolayer_index << std::endl;
2010-08-28 14:07:31 -06:00
// liquids
if(des.flow_size)
{
if(des.liquid_type == DFHack::liquid_magma)
2010-06-04 16:02:02 -06:00
std::cout <<"magma: ";
else std::cout <<"water: ";
std::cout << des.flow_size << std::endl;
}
if(des.flow_forbid)
2010-06-04 16:02:02 -06:00
std::cout << "flow forbid" << std::endl;
if(des.pile)
2010-06-04 16:02:02 -06:00
std::cout << "stockpile?" << std::endl;
if(des.rained)
2010-06-04 16:02:02 -06:00
std::cout << "rained?" << std::endl;
if(des.smooth)
2010-06-04 16:02:02 -06:00
std::cout << "smooth?" << std::endl;
uint32_t designato = block.origin + designatus + (tileX * 16 + tileY) * sizeof(t_designation);
printf("designation offset: 0x%x\n", designato);
if(des.light)
2010-06-04 16:02:02 -06:00
std::cout << "Light ";
else
2010-06-04 16:02:02 -06:00
std::cout << " ";
if(des.skyview)
2010-06-04 16:02:02 -06:00
std::cout << "SkyView ";
else
2010-06-04 16:02:02 -06:00
std::cout << " ";
if(des.subterranean)
2010-06-04 16:02:02 -06:00
std::cout << "Underground ";
else
2010-06-04 16:02:02 -06:00
std::cout << " ";
std::cout << std::endl;
}
}
#ifndef LINUX_BUILD
2010-06-04 16:02:02 -06:00
std::cout << "Done. Press any key to continue" << std::endl;
cin.ignore();
#endif
return 0;
}