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

Function df_regrass

plugins/regrass.cpp:433–524  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

431}
432
433command_result df_regrass(color_ostream &out, vector<string> &parameters)
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 }

Callers

nothing calls this directly

Calls 11

CallLuaModuleFunctionFunction · 0.85
vector_getFunction · 0.85
regrass_cuboidFunction · 0.85
cuboidClass · 0.85
getTileBlockFunction · 0.85
regrass_blockFunction · 0.85
regrass_tileFunction · 0.85
regrass_mapFunction · 0.85
is_setMethod · 0.80
printMethod · 0.45
isValidMethod · 0.45

Tested by

no test coverage detected