| 423 | } |
| 424 | |
| 425 | command_result df_removeplant(color_ostream &out, const cuboid &bounds, const plant_options &options, vector<int32_t> *filter = nullptr) |
| 426 | { |
| 427 | if (!bounds.isValid()) |
| 428 | { |
| 429 | out.printerr("Invalid cuboid! ({}:{}, {}:{}, {}:{})\n", |
| 430 | bounds.x_min, bounds.x_max, bounds.y_min, bounds.y_max, bounds.z_min, bounds.z_max); |
| 431 | return CR_FAILURE; |
| 432 | } |
| 433 | |
| 434 | bool by_type = options.shrubs || options.saplings || options.trees; |
| 435 | bool do_filter = by_type && filter && !filter->empty(); |
| 436 | if (do_filter) // Sort filter vector |
| 437 | std::sort(filter->begin(), filter->end()); |
| 438 | |
| 439 | |
| 440 | int count = 0, count_bad = 0; |
| 441 | auto &vec = world->plants.all; |
| 442 | for (size_t i = vec.size(); i-- > 0;) |
| 443 | { |
| 444 | auto &plant = *vec[i]; |
| 445 | auto tt = Maps::getTileType(plant.pos); |
| 446 | |
| 447 | if (plant.tree_info) // TODO: handle trees |
| 448 | continue; // Not implemented |
| 449 | else if (by_type) |
| 450 | { |
| 451 | if (options.dead && !plant.damage_flags.bits.dead && tt && tileSpecial(*tt) != tiletype_special::DEAD) |
| 452 | continue; // Not removing living |
| 453 | /*else if (plant->tree_info && !options.trees) |
| 454 | continue; // Not removing trees*/ |
| 455 | else if (ENUM_ATTR(plant_type, is_shrub, plant.type)) |
| 456 | { |
| 457 | if (!options.shrubs) |
| 458 | continue; // Not removing shrubs |
| 459 | } |
| 460 | else if (!options.saplings) |
| 461 | continue; // Not removing saplings |
| 462 | } |
| 463 | |
| 464 | if (!plant_in_cuboid(&plant, bounds)) |
| 465 | continue; // Outside cuboid |
| 466 | else if (do_filter && (vector_contains(*filter, (int32_t)plant.material) == options.filter_ex)) |
| 467 | continue; // Filtered out |
| 468 | |
| 469 | bool bad_tt = false; |
| 470 | if (tt) |
| 471 | { |
| 472 | if (ENUM_ATTR(plant_type, is_shrub, plant.type)) |
| 473 | { |
| 474 | if (tileShape(*tt) != tiletype_shape::SHRUB) |
| 475 | { |
| 476 | out.printerr("Bad shrub tiletype at ({}, {}, {}): {}\n", |
| 477 | plant.pos.x, plant.pos.y, plant.pos.z, |
| 478 | ENUM_KEY_STR(tiletype, *tt)); |
| 479 | bad_tt = true; |
| 480 | } |
| 481 | } |
| 482 | else if (!plant.tree_info) |
no test coverage detected