2011-07-25 02:14:58 -06:00
|
|
|
// Just show some position data
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <iomanip>
|
|
|
|
#include <climits>
|
|
|
|
#include <vector>
|
2012-01-15 13:54:14 -07:00
|
|
|
#include <string>
|
2011-07-25 02:14:58 -06:00
|
|
|
#include <sstream>
|
|
|
|
#include <ctime>
|
|
|
|
#include <cstdio>
|
|
|
|
using namespace std;
|
|
|
|
|
2011-12-31 04:48:42 -07:00
|
|
|
#include "Core.h"
|
2012-01-15 13:54:14 -07:00
|
|
|
#include "Console.h"
|
|
|
|
#include "Export.h"
|
|
|
|
#include "PluginManager.h"
|
|
|
|
#include "modules/Units.h"
|
|
|
|
#include "modules/Maps.h"
|
|
|
|
#include "modules/Gui.h"
|
|
|
|
#include "modules/Materials.h"
|
|
|
|
#include "modules/MapCache.h"
|
|
|
|
#include "MiscUtils.h"
|
2011-07-25 02:14:58 -06:00
|
|
|
|
2012-01-24 10:32:34 -07:00
|
|
|
#include "df/world.h"
|
|
|
|
|
|
|
|
|
2011-07-25 02:14:58 -06:00
|
|
|
using std::vector;
|
|
|
|
using std::string;
|
|
|
|
using namespace DFHack;
|
2012-01-24 10:32:34 -07:00
|
|
|
using namespace DFHack::Simple;
|
2012-01-21 17:31:15 -07:00
|
|
|
using namespace df::enums;
|
2012-01-24 10:32:34 -07:00
|
|
|
using df::global::world;
|
2011-07-25 02:14:58 -06:00
|
|
|
|
2012-02-13 21:54:08 -07:00
|
|
|
command_result df_probe (Core * c, vector <string> & parameters);
|
|
|
|
command_result df_cprobe (Core * c, vector <string> & parameters);
|
2011-07-25 02:14:58 -06:00
|
|
|
|
|
|
|
DFhackCExport const char * plugin_name ( void )
|
|
|
|
{
|
|
|
|
return "probe";
|
|
|
|
}
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
|
|
|
|
{
|
|
|
|
commands.clear();
|
|
|
|
commands.push_back(PluginCommand("probe",
|
|
|
|
"A tile probe",
|
|
|
|
df_probe));
|
2011-11-01 17:26:45 -06:00
|
|
|
commands.push_back(PluginCommand("cprobe",
|
|
|
|
"A creature probe",
|
|
|
|
df_cprobe));
|
2011-07-25 02:14:58 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_shutdown ( Core * c )
|
|
|
|
{
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-02-13 21:54:08 -07:00
|
|
|
command_result df_cprobe (Core * c, vector <string> & parameters)
|
2011-11-01 17:26:45 -06:00
|
|
|
{
|
|
|
|
Console & con = c->con;
|
2012-01-21 17:31:15 -07:00
|
|
|
CoreSuspender suspend(c);
|
2011-11-01 17:26:45 -06:00
|
|
|
DFHack::Gui *Gui = c->getGui();
|
|
|
|
int32_t cursorX, cursorY, cursorZ;
|
|
|
|
Gui->getCursorCoords(cursorX,cursorY,cursorZ);
|
|
|
|
if(cursorX == -30000)
|
|
|
|
{
|
|
|
|
con.printerr("No cursor; place cursor over creature to probe.\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-01-31 09:55:38 -07:00
|
|
|
for(size_t i = 0; i < world->units.all.size(); i++)
|
2011-11-01 17:26:45 -06:00
|
|
|
{
|
2012-01-24 10:32:34 -07:00
|
|
|
df::unit * unit = world->units.all[i];
|
2012-01-21 12:03:39 -07:00
|
|
|
if(unit->pos.x == cursorX && unit->pos.y == cursorY && unit->pos.z == cursorZ)
|
2011-11-01 17:26:45 -06:00
|
|
|
{
|
2012-01-21 12:03:39 -07:00
|
|
|
con.print("Creature %d, race %d (%x), civ %d (%x)\n", unit->id, unit->race, unit->race, unit->civ_id, unit->civ_id);
|
2011-11-01 17:26:45 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2012-02-13 21:54:08 -07:00
|
|
|
command_result df_probe (Core * c, vector <string> & parameters)
|
2011-07-25 02:14:58 -06:00
|
|
|
{
|
|
|
|
//bool showBlock, showDesig, showOccup, showTile, showMisc;
|
|
|
|
Console & con = c->con;
|
|
|
|
/*
|
|
|
|
if (!parseOptions(parameters, showBlock, showDesig, showOccup,
|
|
|
|
showTile, showMisc))
|
|
|
|
{
|
|
|
|
con.printerr("Unknown parameters!\n");
|
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2012-01-21 17:31:15 -07:00
|
|
|
CoreSuspender suspend(c);
|
2011-07-25 02:14:58 -06:00
|
|
|
|
|
|
|
DFHack::Gui *Gui = c->getGui();
|
|
|
|
DFHack::Materials *Materials = c->getMaterials();
|
|
|
|
DFHack::VersionInfo* mem = c->vinfo;
|
2011-11-02 21:30:59 -06:00
|
|
|
std::vector<t_matglossInorganic> inorganic;
|
|
|
|
bool hasmats = Materials->CopyInorganicMaterials(inorganic);
|
2011-07-25 02:14:58 -06:00
|
|
|
|
2012-01-19 20:44:17 -07:00
|
|
|
if (!Maps::IsValid())
|
2011-07-25 02:14:58 -06:00
|
|
|
{
|
2012-01-19 20:44:17 -07:00
|
|
|
c->con.printerr("Map is not available!\n");
|
|
|
|
return CR_FAILURE;
|
2011-07-25 02:14:58 -06:00
|
|
|
}
|
2012-01-19 20:44:17 -07:00
|
|
|
MapExtras::MapCache mc;
|
2011-07-25 02:14:58 -06:00
|
|
|
|
2012-01-19 20:44:17 -07:00
|
|
|
int32_t regionX, regionY, regionZ;
|
|
|
|
Maps::getPosition(regionX,regionY,regionZ);
|
2011-07-25 02:14:58 -06:00
|
|
|
|
2012-01-19 20:44:17 -07:00
|
|
|
int32_t cursorX, cursorY, cursorZ;
|
|
|
|
Gui->getCursorCoords(cursorX,cursorY,cursorZ);
|
|
|
|
if(cursorX == -30000)
|
|
|
|
{
|
|
|
|
con.printerr("No cursor; place cursor over tile to probe.\n");
|
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
DFCoord cursor (cursorX,cursorY,cursorZ);
|
2011-07-25 02:14:58 -06:00
|
|
|
|
2012-01-19 20:44:17 -07:00
|
|
|
uint32_t blockX = cursorX / 16;
|
|
|
|
uint32_t tileX = cursorX % 16;
|
|
|
|
uint32_t blockY = cursorY / 16;
|
|
|
|
uint32_t tileY = cursorY % 16;
|
2011-07-25 02:14:58 -06:00
|
|
|
|
2012-01-19 20:44:17 -07:00
|
|
|
MapExtras::Block * b = mc.BlockAt(cursor/16);
|
|
|
|
if(!b && !b->valid)
|
|
|
|
{
|
|
|
|
con.printerr("No data.\n");
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
mapblock40d & block = b->raw;
|
|
|
|
con.print("block addr: 0x%x\n\n", block.origin);
|
2011-07-25 02:14:58 -06:00
|
|
|
/*
|
2012-01-19 20:44:17 -07:00
|
|
|
if (showBlock)
|
|
|
|
{
|
|
|
|
con.print("block flags:\n");
|
|
|
|
print_bits<uint32_t>(block.blockflags.whole,con);
|
|
|
|
con.print("\n\n");
|
|
|
|
}
|
2011-07-25 02:14:58 -06:00
|
|
|
*/
|
2012-02-13 15:56:33 -07:00
|
|
|
df::tiletype tiletype = mc.tiletypeAt(cursor);
|
2012-01-19 20:44:17 -07:00
|
|
|
df::tile_designation &des = block.designation[tileX][tileY];
|
2011-07-25 02:14:58 -06:00
|
|
|
/*
|
2012-01-19 20:44:17 -07:00
|
|
|
if(showDesig)
|
|
|
|
{
|
|
|
|
con.print("designation\n");
|
|
|
|
print_bits<uint32_t>(block.designation[tileX][tileY].whole,
|
|
|
|
con);
|
|
|
|
con.print("\n\n");
|
|
|
|
}
|
2011-07-25 02:14:58 -06:00
|
|
|
|
2012-01-19 20:44:17 -07:00
|
|
|
if(showOccup)
|
|
|
|
{
|
|
|
|
con.print("occupancy\n");
|
|
|
|
print_bits<uint32_t>(block.occupancy[tileX][tileY].whole,
|
|
|
|
con);
|
|
|
|
con.print("\n\n");
|
|
|
|
}
|
2011-07-25 02:14:58 -06:00
|
|
|
*/
|
|
|
|
|
2012-01-19 20:44:17 -07:00
|
|
|
// tiletype
|
|
|
|
con.print("tiletype: %d", tiletype);
|
|
|
|
if(tileName(tiletype))
|
|
|
|
con.print(" = %s",tileName(tiletype));
|
|
|
|
con.print("\n");
|
2011-07-25 02:14:58 -06:00
|
|
|
|
2012-02-13 15:56:33 -07:00
|
|
|
df::tiletype_shape shape = tileShape(tiletype);
|
|
|
|
df::tiletype_material material = tileMaterial(tiletype);
|
|
|
|
df::tiletype_special special = tileSpecial(tiletype);
|
2012-02-13 18:17:38 -07:00
|
|
|
df::tiletype_variant variant = tileVariant(tiletype);
|
2012-01-19 20:44:17 -07:00
|
|
|
con.print("%-10s: %4d %s\n","Class" ,shape,
|
2012-02-13 18:17:38 -07:00
|
|
|
ENUM_KEY_STR(tiletype_shape, shape));
|
2012-01-19 20:44:17 -07:00
|
|
|
con.print("%-10s: %4d %s\n","Material" ,
|
2012-02-13 18:17:38 -07:00
|
|
|
material, ENUM_KEY_STR(tiletype_material, material));
|
2012-01-19 20:44:17 -07:00
|
|
|
con.print("%-10s: %4d %s\n","Special" ,
|
2012-02-13 18:17:38 -07:00
|
|
|
special, ENUM_KEY_STR(tiletype_special, special));
|
|
|
|
con.print("%-10s: %4d %s\n" ,"Variant" ,
|
|
|
|
variant, ENUM_KEY_STR(tiletype_variant, variant));
|
2012-01-19 20:44:17 -07:00
|
|
|
con.print("%-10s: %s\n" ,"Direction",
|
|
|
|
tileDirection(tiletype).getStr());
|
|
|
|
con.print("\n");
|
2011-07-25 02:14:58 -06:00
|
|
|
|
2012-01-19 20:44:17 -07:00
|
|
|
con.print("temperature1: %d U\n",mc.temperature1At(cursor));
|
|
|
|
con.print("temperature2: %d U\n",mc.temperature2At(cursor));
|
2011-07-25 02:14:58 -06:00
|
|
|
|
2012-01-19 20:44:17 -07:00
|
|
|
// biome, geolayer
|
|
|
|
con << "biome: " << des.bits.biome << std::endl;
|
|
|
|
con << "geolayer: " << des.bits.geolayer_index
|
|
|
|
<< std::endl;
|
|
|
|
int16_t base_rock = mc.baseMaterialAt(cursor);
|
|
|
|
if(base_rock != -1)
|
|
|
|
{
|
|
|
|
con << "Layer material: " << dec << base_rock;
|
|
|
|
if(hasmats)
|
|
|
|
con << " / " << inorganic[base_rock].id
|
|
|
|
<< " / "
|
|
|
|
<< inorganic[base_rock].name
|
|
|
|
<< endl;
|
|
|
|
else
|
|
|
|
con << endl;
|
|
|
|
}
|
|
|
|
int16_t vein_rock = mc.veinMaterialAt(cursor);
|
|
|
|
if(vein_rock != -1)
|
|
|
|
{
|
|
|
|
con << "Vein material (final): " << dec << vein_rock;
|
|
|
|
if(hasmats)
|
|
|
|
con << " / " << inorganic[vein_rock].id
|
|
|
|
<< " / "
|
|
|
|
<< inorganic[vein_rock].name
|
|
|
|
<< endl;
|
|
|
|
else
|
|
|
|
con << endl;
|
|
|
|
}
|
|
|
|
// liquids
|
|
|
|
if(des.bits.flow_size)
|
|
|
|
{
|
2012-01-21 17:31:15 -07:00
|
|
|
if(des.bits.liquid_type == tile_liquid::Magma)
|
2012-01-19 20:44:17 -07:00
|
|
|
con <<"magma: ";
|
|
|
|
else con <<"water: ";
|
|
|
|
con << des.bits.flow_size << std::endl;
|
|
|
|
}
|
|
|
|
if(des.bits.flow_forbid)
|
|
|
|
con << "flow forbid" << std::endl;
|
|
|
|
if(des.bits.pile)
|
|
|
|
con << "stockpile?" << std::endl;
|
|
|
|
if(des.bits.rained)
|
|
|
|
con << "rained?" << std::endl;
|
|
|
|
if(des.bits.smooth)
|
|
|
|
con << "smooth?" << std::endl;
|
|
|
|
if(des.bits.water_salt)
|
|
|
|
con << "salty" << endl;
|
|
|
|
if(des.bits.water_stagnant)
|
|
|
|
con << "stagnant" << endl;
|
2011-07-25 02:14:58 -06:00
|
|
|
|
2012-01-19 20:44:17 -07:00
|
|
|
#define PRINT_FLAG( X ) con.print("%-16s= %c\n", #X , ( des.X ? 'Y' : ' ' ) )
|
|
|
|
PRINT_FLAG( bits.hidden );
|
|
|
|
PRINT_FLAG( bits.light );
|
|
|
|
PRINT_FLAG( bits.outside );
|
|
|
|
PRINT_FLAG( bits.subterranean );
|
|
|
|
PRINT_FLAG( bits.water_table );
|
|
|
|
PRINT_FLAG( bits.rained );
|
2011-07-25 02:14:58 -06:00
|
|
|
|
2012-01-20 03:28:00 -07:00
|
|
|
df::coord2d pc(blockX, blockY);
|
2011-07-25 02:14:58 -06:00
|
|
|
|
2012-01-19 20:44:17 -07:00
|
|
|
t_feature local;
|
|
|
|
t_feature global;
|
|
|
|
Maps::ReadFeatures(&(b->raw),&local,&global);
|
|
|
|
PRINT_FLAG( bits.feature_local );
|
|
|
|
if(local.type != -1)
|
|
|
|
{
|
|
|
|
con.print("%-16s", "");
|
|
|
|
con.print(" %4d", block.local_feature);
|
|
|
|
con.print(" (%2d)", local.type);
|
|
|
|
con.print(" addr 0x%X ", local.origin);
|
|
|
|
con.print(" %s\n", sa_feature(local.type));
|
|
|
|
}
|
|
|
|
PRINT_FLAG( bits.feature_global );
|
|
|
|
if(global.type != -1)
|
|
|
|
{
|
|
|
|
con.print("%-16s", "");
|
|
|
|
con.print(" %4d", block.global_feature);
|
|
|
|
con.print(" (%2d)", global.type);
|
|
|
|
con.print(" %s\n", sa_feature(global.type));
|
2011-07-25 02:14:58 -06:00
|
|
|
}
|
2012-01-19 20:44:17 -07:00
|
|
|
#undef PRINT_FLAG
|
|
|
|
con << "local feature idx: " << block.local_feature
|
|
|
|
<< endl;
|
|
|
|
con << "global feature idx: " << block.global_feature
|
|
|
|
<< endl;
|
|
|
|
con << "mystery: " << block.mystery << endl;
|
|
|
|
con << std::endl;
|
2011-07-25 02:14:58 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|