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

Function dig_tile

plugins/dig-now.cpp:458–564  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

456}
457
458static bool dig_tile(color_ostream &out, MapExtras::MapCache &map,
459 const DFCoord &pos, df::tile_dig_designation designation,
460 std::vector<dug_tile_info> &dug_tiles) {
461 df::tiletype tt = map.tiletypeAt(pos);
462
463 if (!is_diggable(map, pos, tt)) {
464 DEBUG(general).print("dig_tile: not diggable\n");
465 return false;
466 }
467
468 df::tiletype target_type = df::tiletype::Void;
469 switch(designation) {
470 case df::tile_dig_designation::Default:
471 if (can_dig_default(tt)) {
472 df::tiletype_shape shape = tileShape(tt);
473 df::tiletype_shape target_shape = df::tiletype_shape::FLOOR;
474 if (shape == df::tiletype_shape::STAIR_UPDOWN)
475 target_shape = df::tiletype_shape::STAIR_DOWN;
476 else if (shape == df::tiletype_shape::RAMP)
477 remove_ramp_top(map, DFCoord(pos.x, pos.y, pos.z+1));
478 target_type = get_target_type(tt, target_shape);
479 }
480 break;
481 case df::tile_dig_designation::Channel:
482 {
483 DFCoord pos_below(pos.x, pos.y, pos.z-1);
484 if (can_dig_channel(tt) && map.ensureBlockAt(pos_below)
485 && is_diggable(map, pos_below, map.tiletypeAt(pos_below))) {
486 TRACE(channels).print("dig_tile: channeling at ({}) [can_dig_channel: true]\n", pos_below);
487 target_type = df::tiletype::OpenSpace;
488 DFCoord pos_above(pos.x, pos.y, pos.z+1);
489 if (map.ensureBlockAt(pos_above)) {
490 remove_ramp_top(map, pos_above);
491 }
492 df::tile_dig_designation td_below = map.designationAt(pos_below).bits.dig;
493 if (dig_tile(out, map, pos_below, df::tile_dig_designation::Ramp, dug_tiles)) {
494 clean_ramps(map, pos_below);
495 if (td_below == df::tile_dig_designation::Default) {
496 dig_tile(out, map, pos_below, td_below, dug_tiles);
497 }
498 clean_ramps(map, pos);
499 propagate_vertical_flags(map, pos);
500 return true;
501 }
502 } else {
503 DEBUG(channels).print("dig_tile: failed to channel at ({}) [can_dig_channel: false]\n", pos_below);
504 }
505 break;
506 }
507 case df::tile_dig_designation::UpStair:
508 if (can_dig_up_stair(tt))
509 target_type = get_target_type(tt, df::tiletype_shape::STAIR_UP);
510 break;
511 case df::tile_dig_designation::DownStair:
512 if (can_dig_down_stair(tt)) {
513 target_type =
514 get_target_type(tt, df::tiletype_shape::STAIR_DOWN);
515

Callers 1

do_digFunction · 0.85

Calls 15

is_diggableFunction · 0.85
can_dig_defaultFunction · 0.85
tileShapeFunction · 0.85
remove_ramp_topFunction · 0.85
get_target_typeFunction · 0.85
can_dig_channelFunction · 0.85
clean_rampsFunction · 0.85
propagate_vertical_flagsFunction · 0.85
can_dig_up_stairFunction · 0.85
can_dig_down_stairFunction · 0.85
can_dig_up_down_stairFunction · 0.85
can_dig_rampFunction · 0.85

Tested by

no test coverage detected