coord_vec points(MapCache & mc, DFHack::DFCoord start) { coord_vec v; bool juststarted = true; while (mc.testCoord(start)) { uint16_t tt = mc.tiletypeAt(start); if(DFHack::LowPassable(tt) || juststarted && DFHack::HighPassable(tt)) { v.push_back(start); juststarted = false; start.z++; } else break; } return v; };
coord_vec points(MapCache & mc, DFHack::DFCoord start) { coord_vec v; DFHack::DFCoord blockc = start % 16; DFHack::DFCoord iterc = blockc * 16; if( !mc.testCoord(start) ) return v; for(int xi = 0; xi < 16; xi++) { for(int yi = 0; yi < 16; yi++) { v.push_back(iterc); iterc.y++; } iterc.x ++; } return v; };
coord_vec points(MapCache & mc, DFHack::DFCoord start) { coord_vec v; DFHack::DFCoord iterstart(start.x - cx_, start.y - cy_, start.z - cz_); DFHack::DFCoord iter = iterstart; for(int xi = 0; xi < x_; xi++) { for(int yi = 0; yi < y_; yi++) { for(int zi = 0; zi < z_; zi++) { if(mc.testCoord(iter)) v.push_back(iter); iter.z++; } iter.z = iterstart.z; iter.y++; } iter.y = iterstart.y; iter.x ++; } return v; };
int main (int argc, char* argv[]) { // Command line options bool updown = false; if(argc > 1 && strcmp(argv[1],"-x") == 0) updown = true; DFHack::ContextManager DFMgr("Memory.xml"); DFHack::Context * DF; try { DF = DFMgr.getSingleContext(); DF->Attach(); } catch (exception& e) { cerr << e.what() << endl; #ifndef LINUX_BUILD cin.ignore(); #endif return 1; } uint32_t x_max,y_max,z_max; DFHack::Maps * Maps = DF->getMaps(); DFHack::Gui * Gui = DF->getGui(); // init the map if(!Maps->Start()) { cerr << "Can't init map. Make sure you have a map loaded in DF." << endl; DF->Detach(); #ifndef LINUX_BUILD cin.ignore(); #endif return 1; } int32_t cx, cy, cz; Maps->getSize(x_max,y_max,z_max); uint32_t tx_max = x_max * 16; uint32_t ty_max = y_max * 16; Gui->getCursorCoords(cx,cy,cz); while(cx == -30000) { cerr << "Cursor is not active. Point the cursor at a vein." << endl; DF->Resume(); cin.ignore(); DF->Suspend(); Gui->getCursorCoords(cx,cy,cz); } DFHack::DFCoord xy ((uint32_t)cx,(uint32_t)cy,cz); if(xy.x == 0 || xy.x == tx_max - 1 || xy.y == 0 || xy.y == ty_max - 1) { cerr << "I won't dig the borders. That would be cheating!" << endl; DF->Detach(); #ifndef LINUX_BUILD cin.ignore(); #endif return 1; } MapCache * MCache = new MapCache(Maps); DFHack::t_designation des = MCache->designationAt(xy); int16_t tt = MCache->tiletypeAt(xy); int16_t veinmat = MCache->veinMaterialAt(xy); if( veinmat == -1 ) { cerr << "This tile is non-vein. Bye :)" << endl; delete MCache; DF->Detach(); #ifndef LINUX_BUILD cin.ignore(); #endif return 1; } printf("%d/%d/%d tiletype: %d, veinmat: %d, designation: 0x%x ... DIGGING!\n", cx,cy,cz, tt, veinmat, des.whole); stack <DFHack::DFCoord> flood; flood.push(xy); while( !flood.empty() ) { DFHack::DFCoord current = flood.top(); flood.pop(); int16_t vmat2 = MCache->veinMaterialAt(current); tt = MCache->tiletypeAt(current); if(!DFHack::isWallTerrain(tt)) continue; if(vmat2!=veinmat) continue; // found a good tile, dig+unset material DFHack::t_designation des = MCache->designationAt(current); DFHack::t_designation des_minus; DFHack::t_designation des_plus; des_plus.whole = des_minus.whole = 0; int16_t vmat_minus = -1; int16_t vmat_plus = -1; bool below = 0; bool above = 0; if(updown) { if(MCache->testCoord(current-1)) { below = 1; des_minus = MCache->designationAt(current-1); vmat_minus = MCache->veinMaterialAt(current-1); } if(MCache->testCoord(current+1)) { above = 1; des_plus = MCache->designationAt(current+1); vmat_plus = MCache->veinMaterialAt(current+1); } } if(MCache->testCoord(current)) { MCache->clearMaterialAt(current); if(current.x < tx_max - 2) { flood.push(DFHack::DFCoord(current.x + 1, current.y, current.z)); if(current.y < ty_max - 2) { flood.push(DFHack::DFCoord(current.x + 1, current.y + 1,current.z)); flood.push(DFHack::DFCoord(current.x, current.y + 1,current.z)); } if(current.y > 1) { flood.push(DFHack::DFCoord(current.x + 1, current.y - 1,current.z)); flood.push(DFHack::DFCoord(current.x, current.y - 1,current.z)); } } if(current.x > 1) { flood.push(DFHack::DFCoord(current.x - 1, current.y,current.z)); if(current.y < ty_max - 2) { flood.push(DFHack::DFCoord(current.x - 1, current.y + 1,current.z)); flood.push(DFHack::DFCoord(current.x, current.y + 1,current.z)); } if(current.y > 1) { flood.push(DFHack::DFCoord(current.x - 1, current.y - 1,current.z)); flood.push(DFHack::DFCoord(current.x, current.y - 1,current.z)); } } if(updown) { if(current.z > 0 && below && vmat_minus == vmat2) { flood.push(current-1); if(des_minus.bits.dig == DFHack::designation_d_stair) des_minus.bits.dig = DFHack::designation_ud_stair; else des_minus.bits.dig = DFHack::designation_u_stair; MCache->setDesignationAt(current-1,des_minus); des.bits.dig = DFHack::designation_d_stair; } if(current.z < z_max - 1 && above && vmat_plus == vmat2) { flood.push(current+ 1); if(des_plus.bits.dig == DFHack::designation_u_stair) des_plus.bits.dig = DFHack::designation_ud_stair; else des_plus.bits.dig = DFHack::designation_d_stair; MCache->setDesignationAt(current+1,des_plus); if(des.bits.dig == DFHack::designation_d_stair) des.bits.dig = DFHack::designation_ud_stair; else des.bits.dig = DFHack::designation_u_stair; } } if(des.bits.dig == DFHack::designation_no) des.bits.dig = DFHack::designation_default; MCache->setDesignationAt(current,des); } } MCache->WriteAll(); delete MCache; DF->Detach(); #ifndef LINUX_BUILD cout << "Done. Press any key to continue" << endl; cin.ignore(); #endif return 0; }
command_result revflood(color_ostream &out, vector<string> & params) { for(size_t i = 0; i < params.size();i++) { if(params[i] == "help" || params[i] == "?") return CR_WRONG_USAGE; } CoreSuspender suspend; uint32_t x_max,y_max,z_max; if (!Maps::IsValid()) { out.printerr("Map is not available!\n"); return CR_FAILURE; } if(revealed != NOT_REVEALED) { out.printerr("This is only safe to use with non-revealed map.\n"); return CR_FAILURE; } t_gamemodes gm; World::ReadGameMode(gm); if(!World::isFortressMode(gm.g_type) || gm.g_mode != game_mode::DWARF ) { out.printerr("Only in proper dwarf mode.\n"); return CR_FAILURE; } int32_t cx, cy, cz; Maps::getSize(x_max,y_max,z_max); uint32_t tx_max = x_max * 16; uint32_t ty_max = y_max * 16; Gui::getCursorCoords(cx,cy,cz); if(cx == -30000) { out.printerr("Cursor is not active. Point the cursor at some empty space you want to be unhidden.\n"); return CR_FAILURE; } DFCoord xy ((uint32_t)cx,(uint32_t)cy,cz); MapCache * MCache = new MapCache; df::tiletype tt = MCache->tiletypeAt(xy); if(isWallTerrain(tt)) { out.printerr("Point the cursor at some empty space you want to be unhidden.\n"); delete MCache; return CR_FAILURE; } // hide all tiles, flush cache Maps::getSize(x_max,y_max,z_max); for(size_t i = 0; i < world->map.map_blocks.size(); i++) { df::map_block * b = world->map.map_blocks[i]; // change the hidden flag to 0 for (uint32_t x = 0; x < 16; x++) for (uint32_t y = 0; y < 16; y++) { b->designation[x][y].bits.hidden = 1; } } MCache->trash(); typedef std::pair <DFCoord, bool> foo; std::stack < foo > flood; flood.push( foo(xy,false) ); while( !flood.empty() ) { foo tile = flood.top(); DFCoord & current = tile.first; bool & from_below = tile.second; flood.pop(); if(!MCache->testCoord(current)) continue; df::tiletype tt = MCache->baseTiletypeAt(current); df::tile_designation des = MCache->designationAt(current); if(!des.bits.hidden) { continue; } bool below = 0; bool above = 0; bool sides = 0; bool unhide = 1; // by tile shape, determine behavior and action switch (tileShape(tt)) { // walls: case tiletype_shape::WALL: if(from_below) unhide = 0; break; // air/free space case tiletype_shape::EMPTY: case tiletype_shape::RAMP_TOP: case tiletype_shape::STAIR_UPDOWN: case tiletype_shape::STAIR_DOWN: case tiletype_shape::BROOK_TOP: above = below = sides = true; break; // has floor case tiletype_shape::FORTIFICATION: case tiletype_shape::STAIR_UP: case tiletype_shape::RAMP: case tiletype_shape::FLOOR: case tiletype_shape::BRANCH: case tiletype_shape::TRUNK_BRANCH: case tiletype_shape::TWIG: case tiletype_shape::SAPLING: case tiletype_shape::SHRUB: case tiletype_shape::BOULDER: case tiletype_shape::PEBBLES: case tiletype_shape::BROOK_BED: case tiletype_shape::ENDLESS_PIT: if(from_below) unhide = 0; above = sides = true; break; } if (tileMaterial(tt) == tiletype_material::PLANT || tileMaterial(tt) == tiletype_material::MUSHROOM) { if(from_below) unhide = 0; above = sides = true; } if(unhide) { des.bits.hidden = false; MCache->setDesignationAt(current,des); } if(sides) { flood.push(foo(DFCoord(current.x + 1, current.y ,current.z),false)); flood.push(foo(DFCoord(current.x + 1, current.y + 1 ,current.z),false)); flood.push(foo(DFCoord(current.x, current.y + 1 ,current.z),false)); flood.push(foo(DFCoord(current.x - 1, current.y + 1 ,current.z),false)); flood.push(foo(DFCoord(current.x - 1, current.y ,current.z),false)); flood.push(foo(DFCoord(current.x - 1, current.y - 1 ,current.z),false)); flood.push(foo(DFCoord(current.x, current.y - 1 ,current.z),false)); flood.push(foo(DFCoord(current.x + 1, current.y - 1 ,current.z),false)); } if(above) { flood.push(foo(DFCoord(current.x, current.y ,current.z + 1),true)); } if(below) { flood.push(foo(DFCoord(current.x, current.y ,current.z - 1),false)); } } MCache->WriteAll(); delete MCache; return CR_OK; }