From 28059a7f351736d307aa45372e52f6e74fe85549 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Thu, 16 Feb 2012 16:22:05 +0100 Subject: [PATCH] Tilesieve devel tool --- library/xml | 2 +- plugins/devel/CMakeLists.txt | 1 + plugins/devel/tilesieve.cpp | 83 ++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 plugins/devel/tilesieve.cpp diff --git a/library/xml b/library/xml index bfc15c208..ce65a57dc 160000 --- a/library/xml +++ b/library/xml @@ -1 +1 @@ -Subproject commit bfc15c2083e525cb1f7a9dae6d0594c6bbcaff63 +Subproject commit ce65a57dc89a9d6f422cfa92d774e5d84f3df884 diff --git a/plugins/devel/CMakeLists.txt b/plugins/devel/CMakeLists.txt index 49fefd253..85a43b157 100644 --- a/plugins/devel/CMakeLists.txt +++ b/plugins/devel/CMakeLists.txt @@ -9,4 +9,5 @@ DFHACK_PLUGIN(notes notes.cpp) DFHACK_PLUGIN(memview memview.cpp) DFHACK_PLUGIN(catsplosion catsplosion.cpp) DFHACK_PLUGIN(buildprobe buildprobe.cpp) +DFHACK_PLUGIN(tilesieve tilesieve.cpp) #DFHACK_PLUGIN(tiles tiles.cpp) diff --git a/plugins/devel/tilesieve.cpp b/plugins/devel/tilesieve.cpp new file mode 100644 index 000000000..7f29c9619 --- /dev/null +++ b/plugins/devel/tilesieve.cpp @@ -0,0 +1,83 @@ +// This is a generic plugin that does nothing useful apart from acting as an example... of a plugin that does nothing :D + +// some headers required for a plugin. Nothing special, just the basics. +#include "Core.h" +#include +#include +#include +#include +// DF data structure definition headers +#include "DataDefs.h" +//#include "df/world.h" + +using namespace DFHack; +using namespace df::enums; + +// Here go all the command declarations... +// mostly to allow having the mandatory stuff on top of the file and commands on the bottom +command_result tilesieve (Core * c, std::vector & parameters); + +// A plugins must be able to return its name. This must correspond to the filename - skeleton.plug.so or skeleton.plug.dll +DFhackCExport const char * plugin_name ( void ) +{ + return "tilesieve"; +} + +// Mandatory init function. If you have some global state, create it here. +DFhackCExport command_result plugin_init ( Core * c, std::vector &commands) +{ + // Fill the command list with your commands. + commands.clear(); + commands.push_back(PluginCommand( + "tilesieve", "Scan map for unknown tiles.", + tilesieve, false, /* true means that the command can't be used from non-interactive user interface */ + // Extended help string. Used by CR_WRONG_USAGE and the help command: + " This command scans the whole map for tiles that aren't recognized yet.\n" + )); + return CR_OK; +} + +// This is called right before the plugin library is removed from memory. +DFhackCExport command_result plugin_shutdown ( Core * c ) +{ + return CR_OK; +} +struct xyz +{ + int x; + int y; + int z; +}; + +command_result tilesieve(DFHack::Core * c, std::vector & params) +{ + Console & con = c->con; + CoreSuspender suspend(c); + if (!Maps::IsValid()) + { + c->con.printerr("Map is not available!\n"); + return CR_FAILURE; + } + c->con.print("Scanning.\n"); + std::set seen; + for (auto iter = world->map.map_blocks.begin(); iter != world->map.map_blocks.end(); iter++) + { + df::map_block *block = *iter; + df::tiletype tt; + const char * name = tileName(tt); + // for each tile in block + for (uint32_t x = 0; x < 16; x++) for (uint32_t y = 0; y < 16; y++) + { + tt = block.tiletypes[x][y]; + if(tileShape(tt) != df::tiletype_shape::None ) + continue; + if(name && strlen(name) != 0) + continue; + if(seen.count(tt)) + continue; + seen.insert(tt); + c->con.print("Found tile %d @ %d %d %d\n", tt, seen.map_pos.x + x, seen.map_pos.y + y, seen.map_pos.z); + } + } + return CR_OK; +}