2012-02-16 08:22:05 -07:00
|
|
|
// 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 <Console.h>
|
|
|
|
#include <Export.h>
|
|
|
|
#include <PluginManager.h>
|
|
|
|
#include <set>
|
|
|
|
// DF data structure definition headers
|
|
|
|
#include "DataDefs.h"
|
2012-02-16 21:30:34 -07:00
|
|
|
#include "modules/Maps.h"
|
2016-08-13 19:44:01 -06:00
|
|
|
#include "df/map_block.h"
|
2012-02-16 21:30:34 -07:00
|
|
|
#include "df/world.h"
|
|
|
|
#include "TileTypes.h"
|
2012-02-16 08:22:05 -07:00
|
|
|
|
|
|
|
using namespace DFHack;
|
|
|
|
using namespace df::enums;
|
2012-02-16 21:30:34 -07:00
|
|
|
using df::global::world;
|
2012-02-16 08:22:05 -07:00
|
|
|
|
|
|
|
// Here go all the command declarations...
|
|
|
|
// mostly to allow having the mandatory stuff on top of the file and commands on the bottom
|
2012-03-10 06:25:00 -07:00
|
|
|
command_result tilesieve (color_ostream &out, std::vector <std::string> & parameters);
|
2012-02-16 08:22:05 -07:00
|
|
|
|
2012-02-21 10:19:17 -07:00
|
|
|
// A plugin must be able to return its name. This must correspond to the filename - skeleton.plug.so or skeleton.plug.dll
|
|
|
|
DFHACK_PLUGIN("tilesieve");
|
2012-02-16 08:22:05 -07:00
|
|
|
|
|
|
|
// Mandatory init function. If you have some global state, create it here.
|
2012-03-10 06:25:00 -07:00
|
|
|
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
|
2012-02-16 08:22:05 -07:00
|
|
|
{
|
|
|
|
// Fill the command list with your commands.
|
|
|
|
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.
|
2012-03-10 06:25:00 -07:00
|
|
|
DFhackCExport command_result plugin_shutdown ( color_ostream &out )
|
2012-02-16 08:22:05 -07:00
|
|
|
{
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
struct xyz
|
|
|
|
{
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
int z;
|
|
|
|
};
|
|
|
|
|
2012-03-10 06:25:00 -07:00
|
|
|
command_result tilesieve(color_ostream &out, std::vector<std::string> & params)
|
2012-02-16 08:22:05 -07:00
|
|
|
{
|
2012-03-10 06:25:00 -07:00
|
|
|
CoreSuspender suspend;
|
|
|
|
|
2012-02-16 08:22:05 -07:00
|
|
|
if (!Maps::IsValid())
|
|
|
|
{
|
2012-03-10 06:25:00 -07:00
|
|
|
out.printerr("Map is not available!\n");
|
2012-02-16 08:22:05 -07:00
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
2012-03-10 06:25:00 -07:00
|
|
|
out.print("Scanning.\n");
|
2012-02-16 08:22:05 -07:00
|
|
|
std::set <df::tiletype> seen;
|
|
|
|
for (auto iter = world->map.map_blocks.begin(); iter != world->map.map_blocks.end(); iter++)
|
|
|
|
{
|
|
|
|
df::map_block *block = *iter;
|
|
|
|
df::tiletype tt;
|
|
|
|
// for each tile in block
|
|
|
|
for (uint32_t x = 0; x < 16; x++) for (uint32_t y = 0; y < 16; y++)
|
|
|
|
{
|
2012-02-16 21:30:34 -07:00
|
|
|
tt = block->tiletype[x][y];
|
|
|
|
const char * name = tileName(tt);
|
|
|
|
if(tileShape(tt) != tiletype_shape::NONE )
|
2012-02-16 08:22:05 -07:00
|
|
|
continue;
|
|
|
|
if(name && strlen(name) != 0)
|
|
|
|
continue;
|
|
|
|
if(seen.count(tt))
|
|
|
|
continue;
|
|
|
|
seen.insert(tt);
|
2012-03-10 06:25:00 -07:00
|
|
|
out.print("Found tile %x @ %d %d %d\n", tt, block->map_pos.x + x, block->map_pos.y + y, block->map_pos.z);
|
2012-02-16 08:22:05 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return CR_OK;
|
|
|
|
}
|