diff options
| author | Petr Mrázek | 2012-02-05 20:05:19 +0100 |
|---|---|---|
| committer | Petr Mrázek | 2012-02-05 20:05:19 +0100 |
| commit | 7d8a176e598cd71468103618e4d3979a9c99f3f9 (patch) | |
| tree | 390307f4524f5070c34b92a7b3bc4bc18edee315 /plugins/liquids.cpp | |
| parent | 1bcf96f4e84bfc6b6a3d1d7b550f9dc47c4855f2 (diff) | |
| parent | 5072c6e1f4c43774d347e57fef16be0c2642a2e0 (diff) | |
| download | dfhack-7d8a176e598cd71468103618e4d3979a9c99f3f9.tar.gz dfhack-7d8a176e598cd71468103618e4d3979a9c99f3f9.tar.bz2 dfhack-7d8a176e598cd71468103618e4d3979a9c99f3f9.tar.xz | |
Merge branch 'export-plugin' of https://github.com/espenhw/dfhack
Diffstat (limited to 'plugins/liquids.cpp')
| -rw-r--r-- | plugins/liquids.cpp | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/plugins/liquids.cpp b/plugins/liquids.cpp index 6e6c19ac..6d268316 100644 --- a/plugins/liquids.cpp +++ b/plugins/liquids.cpp @@ -1,5 +1,6 @@ #include <iostream> #include <vector> +#include <stack> #include <map> #include <set> #include <cstdlib> @@ -141,6 +142,64 @@ public: }; }; +/** + * Flood-fill water tiles from cursor (for wclean) + * example: remove salt flag from a river + */ +class FloodBrush : public Brush +{ +public: + FloodBrush(Core *c){c_ = c;}; + ~FloodBrush(){}; + coord_vec points(MapCache & mc, DFHack::DFCoord start) + { + coord_vec v; + + std::stack<DFCoord> to_flood; + to_flood.push(start); + + std::set<DFCoord> seen; + + while (!to_flood.empty()) { + DFCoord xy = to_flood.top(); + to_flood.pop(); + + df::tile_designation des = mc.designationAt(xy); + + if (seen.find(xy) == seen.end() + && des.bits.flow_size + && des.bits.liquid_type == tile_liquid::Water) { + v.push_back(xy); + seen.insert(xy); + + maybeFlood(DFCoord(xy.x - 1, xy.y, xy.z), to_flood, mc); + maybeFlood(DFCoord(xy.x + 1, xy.y, xy.z), to_flood, mc); + maybeFlood(DFCoord(xy.x, xy.y - 1, xy.z), to_flood, mc); + maybeFlood(DFCoord(xy.x, xy.y + 1, xy.z), to_flood, mc); + + uint16_t tt = mc.tiletypeAt(xy); + if (LowPassable(tt)) + { + maybeFlood(DFCoord(xy.x, xy.y, xy.z - 1), to_flood, mc); + } + if (HighPassable(tt)) + { + maybeFlood(DFCoord(xy.x, xy.y, xy.z + 1), to_flood, mc); + } + } + } + + return v; + } +private: + void maybeFlood(DFCoord c, std::stack<DFCoord> &to_flood, MapCache &mc) { + if (mc.testCoord(c)) { + to_flood.push(c); + } + } + Core *c_; +}; + CommandHistory liquids_hist; DFhackCExport command_result df_liquids (Core * c, vector <string> & parameters); @@ -229,6 +288,8 @@ DFhackCExport command_result df_liquids (Core * c, vector <string> & parameters) << "block - DF map block with cursor in it" << endl << " (regular spaced 16x16x1 blocks)" << endl << "column - Column from cursor, up through free space" << endl + << "flood - Flood-fill water tiles from cursor" << endl + << " (only makes sense with wclean)" << endl << "Other:" << endl << "q - quit" << endl << "help or ? - print this list of commands" << endl @@ -317,6 +378,12 @@ DFhackCExport command_result df_liquids (Core * c, vector <string> & parameters) brushname = "column"; brush = new ColumnBrush(); } + else if(command == "flood") + { + delete brush; + brushname = "flood"; + brush = new FloodBrush(c); + } else if(command == "q") { end = true; |
