void VeinGenerator::write_tiles() { for (int x = 0; x < size.x; x++) { for (int y = 0; y < size.y; y++) { df::coord2d column(x,y); int top = findTopBlock(map, x, y); for (int z = top; z >= 0; z--) { Block *b = map.BlockAt(df::coord(x,y,z)); if (!b || !b->is_valid()) continue; write_block_tiles(b, column, z); b->Write(); map.discardBlock(b); } map.trash(); } } }
bool VeinGenerator::scan_tiles() { for (int x = 0; x < size.x; x++) { for (int y = 0; y < size.y; y++) { df::coord2d column(x,y); int top = findTopBlock(map, x, y); // First find where layers start and end for (int z = top; z >= 0; z--) { Block *b = map.BlockAt(df::coord(x,y,z)); if (!b || !b->is_valid()) continue; if (!scan_layer_depth(b, column, z)) return false; } if (!adjust_layer_depth(column)) return false; // Collect tile data for (int z = top; z >= 0; z--) { Block *b = map.BlockAt(df::coord(x,y,z)); if (!b || !b->is_valid()) continue; if (!scan_block_tiles(b, column, z)) return false; map.discardBlock(b); } // Discard this column of parsed blocks map.trash(); } } return true; }
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; }