From 6d123687241f76775156faed5ebb48c4242236a0 Mon Sep 17 00:00:00 2001 From: expwnent Date: Sun, 19 Aug 2012 22:45:47 -0400 Subject: [PATCH] Added digtype to dig.cpp. Digtype allows designation of all veins of a given type. --- plugins/dig.cpp | 131 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 130 insertions(+), 1 deletion(-) diff --git a/plugins/dig.cpp b/plugins/dig.cpp index 21c199102..c1b6f6331 100644 --- a/plugins/dig.cpp +++ b/plugins/dig.cpp @@ -24,7 +24,7 @@ command_result diglx (color_ostream &out, vector & parameters); command_result digauto (color_ostream &out, vector & parameters); command_result digexp (color_ostream &out, vector & parameters); command_result digcircle (color_ostream &out, vector & parameters); - +command_result digtype (color_ostream &out, vector & parameters); DFHACK_PLUGIN("dig"); @@ -57,6 +57,18 @@ DFhackCExport command_result plugin_init ( color_ostream &out, std::vector & parameters) { return CR_NOT_IMPLEMENTED; } + +command_result digtype (color_ostream &out, vector & parameters) +{ + //mostly copy-pasted from digv + CoreSuspender suspend; + if ( parameters.size() > 1 ) + { + out.printerr("Too many parameters.\n"); + return CR_FAILURE; + } + + uint32_t targetDigType; + if ( parameters.size() == 1 ) + { + string parameter = parameters[0]; + if ( parameter == "clear" ) + targetDigType = tile_dig_designation::No; + else if ( parameter == "dig" ) + targetDigType = tile_dig_designation::Default; + else if ( parameter == "updown" ) + targetDigType = tile_dig_designation::UpDownStair; + else if ( parameter == "channel" ) + targetDigType = tile_dig_designation::Channel; + else if ( parameter == "ramp" ) + targetDigType = tile_dig_designation::Ramp; + else if ( parameter == "down" ) + targetDigType = tile_dig_designation::DownStair; + else if ( parameter == "up" ) + targetDigType = tile_dig_designation::UpStair; + else + { + out.printerr("Invalid parameter.\n"); + return CR_FAILURE; + } + } + else + { + targetDigType = -1; + } + + if (!Maps::IsValid()) + { + out.printerr("Map is not available!\n"); + return CR_FAILURE; + } + + int32_t cx, cy, cz; + uint32_t xMax,yMax,zMax; + Maps::getSize(xMax,yMax,zMax); + uint32_t tileXMax = xMax * 16; + uint32_t tileYMax = yMax * 16; + Gui::getCursorCoords(cx,cy,cz); + if (cx == -30000) + { + out.printerr("Cursor is not active. Point the cursor at a vein.\n"); + return CR_FAILURE; + } + DFHack::DFCoord xy ((uint32_t)cx,(uint32_t)cy,cz); + MapExtras::MapCache * mCache = new MapExtras::MapCache; + df::tile_designation baseDes = mCache->designationAt(xy); + df::tiletype tt = mCache->tiletypeAt(xy); + int16_t veinmat = mCache->veinMaterialAt(xy); + if( veinmat == -1 ) + { + out.printerr("This tile is not a vein.\n"); + delete mCache; + return CR_FAILURE; + } + out.print("(%d,%d,%d) tiletype: %d, veinmat: %d, designation: 0x%x ... DIGGING!\n", cx,cy,cz, tt, veinmat, baseDes.whole); + + if ( targetDigType != -1 ) + { + baseDes.bits.dig = (tile_dig_designation::tile_dig_designation)targetDigType; + } + else + { + if ( baseDes.bits.dig == tile_dig_designation::No ) + { + baseDes.bits.dig = tile_dig_designation::Default; + } + } + + for( uint32_t z = 0; z < zMax; z++ ) + { + for( uint32_t x = 1; x < tileXMax-1; x++ ) + { + for( uint32_t y = 1; y < tileYMax-1; y++ ) + { + DFHack::DFCoord current(x,y,z); + int16_t vmat2 = mCache->veinMaterialAt(current); + if ( vmat2 != veinmat ) + continue; + tt = mCache->tiletypeAt(current); + if (!DFHack::isWallTerrain(tt)) + continue; + + //designate it for digging + df::tile_designation des = mCache->designationAt(current); + if ( !mCache->testCoord(current) ) + { + out.printerr("testCoord failed at (%d,%d,%d)\n", x, y, z); + delete mCache; + return CR_FAILURE; + } + + df::tile_designation designation = mCache->designationAt(current); + designation.bits.dig = baseDes.bits.dig; + mCache->setDesignationAt(current, designation); + } + } + } + + mCache->WriteAll(); + delete mCache; + return CR_OK; +} +