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

Function scan_tree

plugins/autochop.cpp:366–413  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

364typedef multimap<int, df::plant *, std::greater<int>> TreesBySize;
365
366static int32_t scan_tree(color_ostream & out, df::plant *plant, int32_t *expected_yield,
367 TreesBySize *designatable_trees_by_size, bool designate_clearcut,
368 const vector<df::unit *> &citizens, int32_t *accessible_trees,
369 int32_t *inaccessible_trees, int32_t *designated_trees, int32_t *accessible_yield,
370 map<int32_t, int32_t> *tree_counts,
371 map<int32_t, int32_t> *designated_tree_counts,
372 map<int, PersistentDataItem *> &clearcut_burrows,
373 map<int, PersistentDataItem *> &chop_burrows) {
374 TRACE(cycle,out).print(" scanning tree at {},{},{}\n",
375 plant->pos.x, plant->pos.y, plant->pos.z);
376
377 if (!is_valid_tree(plant))
378 return 0;
379
380 bool accessible = is_accessible_tree(plant->pos, citizens);
381 int32_t yield = estimate_logs(plant);
382
383 if (accessible) {
384 if (accessible_trees)
385 ++*accessible_trees;
386 if (accessible_yield)
387 *accessible_yield += yield;
388 } else {
389 if (inaccessible_trees)
390 ++*inaccessible_trees;
391 }
392
393 bool can_chop = false;
394 bool designated = Designations::isPlantMarked(plant);
395 bool was_designated = designated;
396 bucket_tree(plant, designate_clearcut, &designated, &can_chop, tree_counts,
397 designated_tree_counts, clearcut_burrows, chop_burrows);
398
399 int32_t ret = 0;
400 if (designated) {
401 if (!was_designated)
402 ret = 1;
403 if (designated_trees)
404 ++*designated_trees;
405 if (expected_yield)
406 *expected_yield += yield;
407 } else if (can_chop && accessible) {
408 if (designatable_trees_by_size)
409 designatable_trees_by_size->emplace(yield, plant);
410 }
411
412 return ret;
413}
414
415// returns the number of trees that were newly marked
416static int32_t scan_trees(color_ostream & out, int32_t *expected_yield,

Callers 1

scan_treesFunction · 0.85

Calls 5

is_valid_treeFunction · 0.85
is_accessible_treeFunction · 0.85
estimate_logsFunction · 0.85
bucket_treeFunction · 0.85
printMethod · 0.45

Tested by

no test coverage detected