From b1868f802cda6be502c494199a7a2f3feecc896e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 21 Aug 2011 23:02:05 +0200 Subject: [PATCH] Make autodump fix the block-local item ID vectors. --- library/include/dfhack/modules/Maps.h | 4 +++ plugins/autodump.cpp | 27 ++++++++++++++ plugins/devel/kittens.cpp | 52 +++++++++++++++++++++++++++ 3 files changed, 83 insertions(+) diff --git a/library/include/dfhack/modules/Maps.h b/library/include/dfhack/modules/Maps.h index 0873991e0..69797068f 100644 --- a/library/include/dfhack/modules/Maps.h +++ b/library/include/dfhack/modules/Maps.h @@ -79,6 +79,10 @@ namespace DFHack { return (other.comparate == comparate); } + bool operator!=(const DFCoord &other) const + { + return (other.comparate != comparate); + } // FIXME: peterix_: you could probably get away with not defining operator< if you defined a std::less specialization for Vertex. bool operator<(const DFCoord &other) const { diff --git a/plugins/autodump.cpp b/plugins/autodump.cpp index 701b091a4..c50e29318 100644 --- a/plugins/autodump.cpp +++ b/plugins/autodump.cpp @@ -14,7 +14,9 @@ using namespace std; #include #include #include +#include #include + #include #include #include @@ -166,6 +168,31 @@ DFhackCExport command_result df_autodump (Core * c, vector & parameters if (pos_cursor == pos_item) continue; + // Do we need to fix block-local item ID vector? + if(pos_item/16 != pos_cursor/16) + { + // yes... + cerr << "Moving from block to block!" << endl; + df_block * bl_src = Maps->getBlock(itm->x /16, itm->y/16, itm->z); + df_block * bl_tgt = Maps->getBlock(cx /16, cy/16, cz); + if(bl_src) + { + std::remove(bl_src->items.begin(), bl_src->items.end(),itm->id); + } + else + { + cerr << "No source block" << endl; + } + if(bl_tgt) + { + bl_tgt->items.push_back(itm->id); + } + else + { + cerr << "No target block" << endl; + } + } + // Move the item itm->x = pos_cursor.x; itm->y = pos_cursor.y; diff --git a/plugins/devel/kittens.cpp b/plugins/devel/kittens.cpp index c161df1e5..f333663c1 100644 --- a/plugins/devel/kittens.cpp +++ b/plugins/devel/kittens.cpp @@ -6,6 +6,7 @@ #include #include "dfhack/extra/stopwatch.h" #include "dfhack/modules/Maps.h" +#include "dfhack/modules/Items.h" #include using std::vector; @@ -23,6 +24,7 @@ DFhackCExport command_result kittens (Core * c, vector & parameters); DFhackCExport command_result ktimer (Core * c, vector & parameters); DFhackCExport command_result bflags (Core * c, vector & parameters); DFhackCExport command_result trackmenu (Core * c, vector & parameters); +DFhackCExport command_result mapitems (Core * c, vector & parameters); DFhackCExport const char * plugin_name ( void ) { @@ -36,6 +38,7 @@ DFhackCExport command_result plugin_init ( Core * c, std::vector commands.push_back(PluginCommand("ktimer","Measure time between game updates and console lag (toggle).",ktimer)); commands.push_back(PluginCommand("blockflags","Look up block flags",bflags)); commands.push_back(PluginCommand("trackmenu","Track menu ID changes (toggle).",trackmenu)); + commands.push_back(PluginCommand("mapitems","Check item ids under cursor against item ids in map block.",mapitems)); return CR_OK; } @@ -71,6 +74,55 @@ DFhackCExport command_result plugin_onupdate ( Core * c ) } return CR_OK; } + +DFhackCExport command_result mapitems (Core * c, vector & parameters) +{ + c->Suspend(); + vector vec_items; + Gui * g = c-> getGui(); + Maps* m = c->getMaps(); + Items* it = c->getItems(); + if(!m->Start()) + { + c->con.printerr("No map to probe\n"); + return CR_FAILURE; + } + if(!it->Start() || !it->readItemVector(vec_items)) + { + c->con.printerr("Failed to get items\n"); + return CR_FAILURE; + } + int32_t cx,cy,cz; + g->getCursorCoords(cx,cy,cz); + if(cx != -30000) + { + df_block * b = m->getBlock(cx/16,cy/16,cz); + if(b) + { + c->con.print("Items in block:\n"); + auto iter_b = b->items.begin(); + while (iter_b != b->items.end()) + { + c->con.print("%d\n",*iter_b); + iter_b++; + } + c->con.print("Items under cursor:\n"); + auto iter_it = vec_items.begin(); + while (iter_it != vec_items.end()) + { + t_item * itm = *iter_it; + if(itm->x == cx && itm->y == cy && itm->z == cz) + { + c->con.print("%d\n",itm->id); + } + iter_it ++; + } + } + } + c->Resume(); + return CR_OK; +} + DFhackCExport command_result trackmenu (Core * c, vector & parameters) { if(trackmenu_flg)