| 431 | } |
| 432 | |
| 433 | command_result df_regrass(color_ostream &out, vector<string> ¶meters) |
| 434 | { |
| 435 | regrass_options options; |
| 436 | df::coord pos_1, pos_2; |
| 437 | |
| 438 | if (!Lua::CallLuaModuleFunction(out, "plugins.regrass", "parse_commandline", |
| 439 | std::make_tuple(&options, &pos_1, &pos_2, parameters))) |
| 440 | { // Failure in Lua script. |
| 441 | return CR_WRONG_USAGE; |
| 442 | } |
| 443 | else if (options.forced_plant == -2) |
| 444 | { // Print all grass raw IDs. |
| 445 | for (auto p_raw : world->raws.plants.grasses) |
| 446 | out.print("{}: {}\n", p_raw->index, p_raw->id); |
| 447 | return CR_OK; |
| 448 | } |
| 449 | |
| 450 | DEBUG(log, out).print("pos_1 = ({}, {}, {})\npos_2 = ({}, {}, {})\n", |
| 451 | pos_1.x, pos_1.y, pos_1.z, pos_2.x, pos_2.y, pos_2.z); |
| 452 | |
| 453 | if (options.block && options.zlevel) { |
| 454 | out.printerr("Choose only --block or --zlevel!\n"); |
| 455 | return CR_WRONG_USAGE; |
| 456 | } |
| 457 | else if (options.block && (!pos_1.isValid() || pos_2.isValid())) { |
| 458 | out.printerr("Invalid pos for --block (or used more than one!)\n"); |
| 459 | return CR_WRONG_USAGE; |
| 460 | } |
| 461 | else if (!Core::getInstance().isMapLoaded()) { |
| 462 | out.printerr("Map not loaded!\n"); |
| 463 | return CR_FAILURE; |
| 464 | } |
| 465 | |
| 466 | if (options.force) { |
| 467 | DEBUG(log, out).print("forced_plant = {}\n", options.forced_plant); |
| 468 | auto p_raw = vector_get(world->raws.plants.all, options.forced_plant); |
| 469 | if (p_raw) { |
| 470 | if (!p_raw->flags.is_set(plant_raw_flags::GRASS)) { |
| 471 | out.printerr("Plant raw wasn't grass: {} ({})\n", options.forced_plant, p_raw->id); |
| 472 | return CR_FAILURE; |
| 473 | } |
| 474 | out.print("Forced grass: {}\n", p_raw->id); |
| 475 | } |
| 476 | else { |
| 477 | out.printerr("Plant raw not found for --force: {}\n", options.forced_plant); |
| 478 | return CR_FAILURE; |
| 479 | } |
| 480 | } |
| 481 | |
| 482 | int count = 0; |
| 483 | if (options.zlevel) |
| 484 | { // Specified z-levels or viewport z. |
| 485 | auto z1 = pos_1.isValid() ? pos_1.z : Gui::getViewportPos().z; |
| 486 | auto z2 = pos_2.isValid() ? pos_2.z : z1; |
| 487 | DEBUG(log, out).print("Regrassing z-levels {} to {}...\n", z1, z2); |
| 488 | count = regrass_cuboid(out, options, cuboid(0, 0, z1, |
| 489 | world->map.x_count-1, world->map.y_count-1, z2)); |
| 490 | } |
nothing calls this directly
no test coverage detected