MCPcopy Create free account
hub / github.com/DFHack/dfhack / cleanitems

Function cleanitems

plugins/cleaners.cpp:102–128  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

100}
101
102command_result cleanitems (color_ostream &out)
103{
104 // Invoked from clean(), already suspended
105 int cleaned_items = 0, cleaned_total = 0;
106 for (auto i : world->items.other.IN_PLAY) {
107 // currently, all item classes extend item_actual, so this should be safe
108 df::item_actual *item = virtual_cast<df::item_actual>(i);
109 if (item && item->contaminants && item->contaminants->size())
110 {
111 std::vector<df::spatter*> saved;
112 for (size_t j = 0; j < item->contaminants->size(); j++)
113 {
114 auto obj = (*item->contaminants)[j];
115 if (obj->flags.whole & 0x8000) // DFHack-generated contaminant
116 saved.push_back(obj);
117 else
118 delete obj;
119 }
120 cleaned_items++;
121 cleaned_total += item->contaminants->size() - saved.size();
122 item->contaminants->swap(saved);
123 }
124 }
125 if (cleaned_total)
126 out.print("Removed {} contaminants from {} items.\n", cleaned_total, cleaned_items);
127 return CR_OK;
128}
129
130command_result cleanunits (color_ostream &out)
131{

Callers 1

cleanFunction · 0.85

Calls 3

sizeMethod · 0.45
swapMethod · 0.45
printMethod · 0.45

Tested by

no test coverage detected