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

Function digl

plugins/dig.cpp:1600–1796  ·  view source on GitHub ↗

TODO: digl and digv share the longish floodfill code and only use different conditions to check if a tile should be marked for digging or not. to make the plugin a bit smaller and cleaner a main execute method would be nice (doing the floodfill stuff and do the checks dependin on whether called in "vein" or "layer" mode)

Source from the content-addressed store, hash-verified

1598// (doing the floodfill stuff and do the checks dependin on whether called in
1599// "vein" or "layer" mode)
1600command_result digl (color_ostream &out, vector <string> & parameters)
1601{
1602 uint32_t x_max,y_max,z_max;
1603 bool updown = false;
1604 bool undo = false;
1605 int32_t priority = parse_priority(out, parameters);
1606
1607 for(size_t i = 0; i < parameters.size();i++)
1608 {
1609 if(parameters[i]=="x")
1610 {
1611 out << "This might take a while for huge layers..." << std::endl;
1612 updown = true;
1613 }
1614 else if(parameters[i]=="undo")
1615 {
1616 out << "Removing dig designation." << std::endl;
1617 undo = true;
1618 }
1619 else
1620 return CR_WRONG_USAGE;
1621 }
1622
1623 auto &con = out;
1624
1625 if (!Maps::IsValid())
1626 {
1627 out.printerr("Map is not available!\n");
1628 return CR_FAILURE;
1629 }
1630
1631 int32_t cx, cy, cz;
1632 Maps::getSize(x_max,y_max,z_max);
1633 uint32_t tx_max = x_max * 16;
1634 uint32_t ty_max = y_max * 16;
1635 Gui::getCursorCoords(cx,cy,cz);
1636 while(cx == -30000)
1637 {
1638 con.printerr("Cursor is not active. Point the cursor at a vein.\n");
1639 return CR_FAILURE;
1640 }
1641 DFHack::DFCoord xy ((uint32_t)cx,(uint32_t)cy,cz);
1642 if(xy.x == 0 || xy.x == int32_t(tx_max) - 1 || xy.y == 0 || xy.y == int32_t(ty_max) - 1)
1643 {
1644 con.printerr("I won't dig the borders. That would be cheating!\n");
1645 return CR_FAILURE;
1646 }
1647 std::unique_ptr<MapExtras::MapCache> MCache = std::make_unique<MapExtras::MapCache>();
1648 df::tile_designation des = MCache->designationAt(xy);
1649 df::tiletype tt = MCache->tiletypeAt(xy);
1650 int16_t veinmat = MCache->veinMaterialAt(xy);
1651 int16_t basemat = MCache->layerMaterialAt(xy);
1652 if( veinmat != -1 )
1653 {
1654 con.printerr("This is a vein. Use digv instead!\n");
1655 return CR_FAILURE;
1656 }
1657 con.print("{}/{}/{}/ tiletype: {}, basemat: {}, designation: 0x{:x} ... DIGGING!\n", cx,cy,cz, ENUM_AS_STR(tt), basemat, des.whole);

Callers 1

diglxFunction · 0.85

Calls 10

parse_priorityFunction · 0.85
isWallTerrainFunction · 0.85
tileMaterialFunction · 0.85
tiletypeAtMethod · 0.80
topMethod · 0.80
setDesignationAtMethod · 0.80
WriteAllMethod · 0.80
sizeMethod · 0.45
printMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected