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

Function df_autodump_destroy_item

plugins/autodump.cpp:208–265  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

206static int last_frame = 0;
207
208command_result df_autodump_destroy_item(color_ostream &out, vector<string> &parameters)
209{
210 if (!parameters.empty())
211 return CR_WRONG_USAGE;
212
213 df::item *item = Gui::getSelectedItem(out);
214 if (!item)
215 return CR_FAILURE;
216
217 // Allow undoing the destroy.
218 if (world->frame_counter != last_frame)
219 {
220 last_frame = world->frame_counter;
221 pending_destroy.clear();
222 }
223
224 if (pending_destroy.count(item->id))
225 {
226 df::item_flags old_flags = pending_destroy[item->id];
227 pending_destroy.erase(item->id);
228
229 item->flags.bits.garbage_collect = false;
230 item->flags.bits.hidden = old_flags.bits.hidden;
231 item->flags.bits.dump = old_flags.bits.dump;
232 item->flags.bits.forbid = old_flags.bits.forbid;
233 return CR_OK;
234 }
235
236 // Check the item is good to destroy.
237 if (item->flags.bits.garbage_collect) {
238 out.printerr("Item is already marked for destroy.\n");
239 return CR_FAILURE;
240 }
241
242 if (item->flags.bits.construction ||
243 item->flags.bits.in_building ||
244 item->flags.bits.artifact)
245 {
246 out.printerr("Choosing not to destroy buildings, constructions and artifacts.\n");
247 return CR_FAILURE;
248 }
249
250 for (auto ref : item->general_refs) {
251 if (ref->getType() == general_ref_type::UNIT_HOLDER) {
252 out.printerr("Choosing not to destroy items in unit inventory.\n");
253 return CR_FAILURE;
254 }
255 }
256
257 // Set the flags.
258 pending_destroy[item->id] = item->flags;
259
260 item->flags.bits.garbage_collect = true;
261 item->flags.bits.hidden = true;
262 item->flags.bits.dump = true;
263 item->flags.bits.forbid = true;
264 return CR_OK;
265}

Callers

nothing calls this directly

Calls 6

getSelectedItemFunction · 0.85
getTypeMethod · 0.80
emptyMethod · 0.45
clearMethod · 0.45
countMethod · 0.45
eraseMethod · 0.45

Tested by

no test coverage detected