|
|
@ -22,61 +22,58 @@ DFhackCExport command_result df_cleanitems (Core * c, vector <string> & paramete
|
|
|
|
|
|
|
|
|
|
|
|
DFhackCExport const char * plugin_name ( void )
|
|
|
|
DFhackCExport const char * plugin_name ( void )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return "cleanitems";
|
|
|
|
return "cleanitems";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
|
|
|
|
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
commands.clear();
|
|
|
|
commands.clear();
|
|
|
|
commands.push_back(PluginCommand("cleanitems", "Removes contaminants from items.", df_cleanitems));
|
|
|
|
commands.push_back(PluginCommand("cleanitems", "Removes contaminants from items.", df_cleanitems));
|
|
|
|
return CR_OK;
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_shutdown ( Core * c )
|
|
|
|
DFhackCExport command_result plugin_shutdown ( Core * c )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return CR_OK;
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DFhackCExport command_result df_cleanitems (Core * c, vector <string> & parameters)
|
|
|
|
DFhackCExport command_result df_cleanitems (Core * c, vector <string> & parameters)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(parameters.size() > 0)
|
|
|
|
if(parameters.size() > 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
string & p = parameters[0];
|
|
|
|
string & p = parameters[0];
|
|
|
|
if(p == "?" || p == "help")
|
|
|
|
if(p == "?" || p == "help")
|
|
|
|
{
|
|
|
|
{
|
|
|
|
c->con.print("This utility removes all contaminants from all objects in your fortress.\n");
|
|
|
|
c->con.print("This utility removes all contaminants from all objects in your fortress.\n");
|
|
|
|
return CR_OK;
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c->Suspend();
|
|
|
|
c->Suspend();
|
|
|
|
DFHack::Items * Items = c->getItems();
|
|
|
|
DFHack::Items * Items = c->getItems();
|
|
|
|
|
|
|
|
|
|
|
|
vector <t_item*> p_items;
|
|
|
|
vector <df_item*> p_items;
|
|
|
|
if(!Items->readItemVector(p_items))
|
|
|
|
if(!Items->readItemVector(p_items))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
c->con.printerr("Can't access the item vector.\n");
|
|
|
|
c->con.printerr("Can't access the item vector.\n");
|
|
|
|
c->Resume();
|
|
|
|
c->Resume();
|
|
|
|
return CR_FAILURE;
|
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
std::size_t numItems = p_items.size();
|
|
|
|
std::size_t numItems = p_items.size();
|
|
|
|
|
|
|
|
|
|
|
|
int cleaned_items = 0, cleaned_total = 0;
|
|
|
|
int cleaned_items = 0, cleaned_total = 0;
|
|
|
|
for (std::size_t i = 0; i < numItems; i++)
|
|
|
|
for (std::size_t i = 0; i < numItems; i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
t_item * itm = p_items[i];
|
|
|
|
df_item * itm = p_items[i];
|
|
|
|
// TODO - get peterix to expand the item base class so it includes this pointer
|
|
|
|
if(!itm->contaminants)
|
|
|
|
uint32_t cont_ptr = *(uint32_t *)((int8_t *)itm + 0x0064);
|
|
|
|
continue;
|
|
|
|
if (!cont_ptr)
|
|
|
|
if (itm->contaminants->size())
|
|
|
|
continue;
|
|
|
|
{
|
|
|
|
std::vector<void *> *contaminants = (std::vector<void *> *)cont_ptr;
|
|
|
|
cleaned_items++;
|
|
|
|
if (contaminants->size())
|
|
|
|
cleaned_total += itm->contaminants->size();
|
|
|
|
{
|
|
|
|
itm->contaminants->clear();
|
|
|
|
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;
|
|
|
|
c->Resume();
|
|
|
|
|
|
|
|
c->con.print("Done. %d items cleaned of %d contaminants.\n", cleaned_items, cleaned_total);
|
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|