diff --git a/library/include/dfhack/modules/Items.h b/library/include/dfhack/modules/Items.h index 3a06d0276..c7fda099e 100644 --- a/library/include/dfhack/modules/Items.h +++ b/library/include/dfhack/modules/Items.h @@ -105,6 +105,11 @@ struct t_itemref : public t_virtual int32_t value; }; +struct df_contaminant +{ + // fixme: figure it out +}; + /** * A partial mirror of a DF base type for items * \ingroup grp_items @@ -125,7 +130,22 @@ public: uint32_t id; // 18 std::vector unk1; + // 24 L, 28 W std::vector itemrefs; + // 30 L, 38 W - these were mostly unset (0xCC with malloc patch) + int16_t mystery_meat[12]; + // 48 L, 50 W + int32_t mystery1; + // 4C L, 54 W + int32_t mystery2; + // 50 L, 58 W + int32_t mystery3; + // 54 L, 5C W + int32_t mystery4; + // 58 L, 60 W + int32_t mystery5; + // 5C L, 64 W - pointer to vector of contaminants + std::vector * contaminants; public: // 0x0 virtual int32_t getType(); diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 844e7cabe..ccd74e42c 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -33,6 +33,7 @@ DFHACK_PLUGIN(plants plants.cpp) DFHACK_PLUGIN(fastdwarf fastdwarf.cpp) DFHACK_PLUGIN(prospector prospector.cpp) DFHACK_PLUGIN(cleanmap cleanmap.cpp) +DFHACK_PLUGIN(cleanitems cleanitems.cpp) DFHACK_PLUGIN(weather weather.cpp) DFHACK_PLUGIN(vdig vdig.cpp) DFHACK_PLUGIN(colonies colonies.cpp) diff --git a/plugins/cleanitems.cpp b/plugins/cleanitems.cpp index 5238614a9..4c7386c0b 100644 --- a/plugins/cleanitems.cpp +++ b/plugins/cleanitems.cpp @@ -22,61 +22,58 @@ DFhackCExport command_result df_cleanitems (Core * c, vector & paramete DFhackCExport const char * plugin_name ( void ) { - return "cleanitems"; + return "cleanitems"; } DFhackCExport command_result plugin_init ( Core * c, std::vector &commands) { - commands.clear(); - commands.push_back(PluginCommand("cleanitems", "Removes contaminants from items.", df_cleanitems)); - return CR_OK; + commands.clear(); + commands.push_back(PluginCommand("cleanitems", "Removes contaminants from items.", df_cleanitems)); + return CR_OK; } DFhackCExport command_result plugin_shutdown ( Core * c ) { - return CR_OK; + return CR_OK; } DFhackCExport command_result df_cleanitems (Core * c, vector & parameters) { - if(parameters.size() > 0) - { - string & p = parameters[0]; - if(p == "?" || p == "help") - { - c->con.print("This utility removes all contaminants from all objects in your fortress.\n"); - return CR_OK; - } - } - c->Suspend(); - DFHack::Items * Items = c->getItems(); + if(parameters.size() > 0) + { + string & p = parameters[0]; + if(p == "?" || p == "help") + { + c->con.print("This utility removes all contaminants from all objects in your fortress.\n"); + return CR_OK; + } + } + c->Suspend(); + DFHack::Items * Items = c->getItems(); - vector p_items; - if(!Items->readItemVector(p_items)) - { - c->con.printerr("Can't access the item vector.\n"); - c->Resume(); - return CR_FAILURE; - } - std::size_t numItems = p_items.size(); + vector p_items; + if(!Items->readItemVector(p_items)) + { + c->con.printerr("Can't access the item vector.\n"); + c->Resume(); + return CR_FAILURE; + } + std::size_t numItems = p_items.size(); - int cleaned_items = 0, cleaned_total = 0; - for (std::size_t i = 0; i < numItems; i++) - { - t_item * itm = p_items[i]; - // TODO - get peterix to expand the item base class so it includes this pointer - uint32_t cont_ptr = *(uint32_t *)((int8_t *)itm + 0x0064); - if (!cont_ptr) - continue; - std::vector *contaminants = (std::vector *)cont_ptr; - if (contaminants->size()) - { - cleaned_items++; - cleaned_total += contaminants->size(); - contaminants->clear(); - } - } - c->Resume(); - c->con.print("Done. %d items cleaned of %d contaminants.\n", cleaned_items, cleaned_total); - return CR_OK; + int cleaned_items = 0, cleaned_total = 0; + for (std::size_t i = 0; i < numItems; i++) + { + df_item * itm = p_items[i]; + if(!itm->contaminants) + continue; + if (itm->contaminants->size()) + { + cleaned_items++; + cleaned_total += itm->contaminants->size(); + itm->contaminants->clear(); + } + } + c->Resume(); + c->con.print("Done. %d items cleaned of %d contaminants.\n", cleaned_items, cleaned_total); + return CR_OK; } \ No newline at end of file