| 292 | } |
| 293 | |
| 294 | static int32_t estimate_logs(const df::plant *plant) { |
| 295 | if (!plant->tree_info) |
| 296 | return 0; |
| 297 | |
| 298 | df::plant_tree_tile** tiles = plant->tree_info->body; |
| 299 | |
| 300 | if (!tiles) |
| 301 | return 0; |
| 302 | |
| 303 | MaterialInfo mi; |
| 304 | mi.decode(MaterialInfo::PLANT_BASE, plant->material); |
| 305 | bool is_shroom = mi.plant->flags.is_set(df::plant_raw_flags::TREE_HAS_MUSHROOM_CAP); |
| 306 | |
| 307 | int32_t trunks = 0, parent_dir = 0; |
| 308 | const int32_t area = plant->tree_info->dim_y * plant->tree_info->dim_x; |
| 309 | for (int z = 0; z < plant->tree_info->body_height; z++) { |
| 310 | df::plant_tree_tile* tilesRow = tiles[z]; |
| 311 | if (!tilesRow) |
| 312 | return 0; // tree data is corrupt; let's not touch it |
| 313 | for (int i = 0; i < area; i++) { |
| 314 | auto & tile = tilesRow[i]; |
| 315 | trunks += tile.bits.trunk; |
| 316 | parent_dir += (tile.bits.parent_dir == 0) ? 0 : 1; |
| 317 | } |
| 318 | } |
| 319 | return is_shroom ? parent_dir : trunks; |
| 320 | } |
| 321 | |
| 322 | static void bucket_tree(df::plant *plant, bool designate_clearcut, bool *designated, bool *can_chop, |
| 323 | map<int32_t, int32_t> *tree_counts, map<int32_t, int32_t> *designated_tree_counts, |