From f97e2bf4103cc09478220decd35c9732c10863aa Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Thu, 19 Apr 2012 17:44:26 -0600 Subject: [PATCH 1/5] Make tiletypes more useful * Add any option to clear paint/filter * Add aquifer bit * Stop filtering process killing execute early * Filter on all bits, not just dig --- README.rst | 3 +- plugins/tiletypes.cpp | 77 +++++++++++++++++++++++++++++++++++-------- 2 files changed, 66 insertions(+), 14 deletions(-) diff --git a/README.rst b/README.rst index 0efe194d7..f1e95a74e 100644 --- a/README.rst +++ b/README.rst @@ -825,7 +825,7 @@ Or this: This will hide previously revealed tiles (or show hidden with the 0 option). -Any paint or filter option can be disabled entirely by using the ANY keyword: +Any paint or filter option (or the entire paint or filter) can be disabled entirely by using the ANY keyword: :: @@ -833,6 +833,7 @@ Any paint or filter option can be disabled entirely by using the ANY keyword: paint shape ANY filter material any filter shape any + filter any You can use several different brushes for painting tiles: * Point. (point) diff --git a/plugins/tiletypes.cpp b/plugins/tiletypes.cpp index 73ec9f963..230870f8d 100644 --- a/plugins/tiletypes.cpp +++ b/plugins/tiletypes.cpp @@ -86,6 +86,7 @@ void help( color_ostream & out, std::vector &commands, int start, i << " run / (empty) : paint!" << std::endl << std::endl << "Filter/paint options:" << std::endl + << " Any: reset to default (no filter/paint)" << std::endl << " Shape / sh / s: set tile shape information" << std::endl << " Material / mat / m: set tile material information" << std::endl << " Special / sp: set special tile information" << std::endl @@ -96,6 +97,7 @@ void help( color_ostream & out, std::vector &commands, int start, i << " Light / l: set light flag" << std::endl << " Subterranean / st: set subterranean flag" << std::endl << " Skyview / sv: set skyview flag" << std::endl + << " Aquifer / aqua: set aquifer flag" << std::endl << "See help [option] for more information" << std::endl; } else if (option == "shape" || option == "s" ||option == "sh") @@ -159,6 +161,11 @@ void help( color_ostream & out, std::vector &commands, int start, i out << "Available skyview flags:" << std::endl << " ANY, 0, 1" << std::endl; } + else if (option == "aquifer" || option == "aqua") + { + out << "Available aquifer flags:" << std::endl + << " ANY, 0, 1" << std::endl; + } } struct TileType @@ -172,8 +179,14 @@ struct TileType int light; int subterranean; int skyview; + int aquifer; TileType() + { + clear(); + } + + void clear() { shape = tiletype_shape::NONE; material = tiletype_material::NONE; @@ -184,13 +197,31 @@ struct TileType light = -1; subterranean = -1; skyview = -1; + aquifer = -1; } bool empty() { return shape == -1 && material == -1 && special == -1 && variant == -1 - && hidden == -1 && light == -1 && subterranean == -1 && skyview == -1 - && dig == -1; + && dig == -1 && hidden == -1 && light == -1 && subterranean == -1 + && skyview == -1 && aquifer == -1; + } + + inline bool matches(const df::tiletype source, + const df::tile_designation des) + { + bool rv = true; + rv &= (shape == -1 || shape == tileShape(source)); + rv &= (material == -1 || material == tileMaterial(source)); + rv &= (special == -1 || special == tileSpecial(source)); + rv &= (variant == -1 || variant == tileVariant(source)); + rv &= (dig == -1 || (dig != 0) == (des.bits.dig != tile_dig_designation::No)); + rv &= (hidden == -1 || (hidden != 0) == des.bits.hidden); + rv &= (light == -1 || (light != 0) == des.bits.light); + rv &= (subterranean == -1 || (subterranean != 0) == des.bits.subterranean); + rv &= (skyview == -1 || (skyview != 0) == des.bits.outside); + rv &= (aquifer == -1 || (aquifer != 0) == des.bits.water_table); + return rv; } }; @@ -310,6 +341,19 @@ std::ostream &operator<<(std::ostream &stream, const TileType &paint) needSpace = true; } + if (paint.aquifer >= 0) + { + if (needSpace) + { + stream << " "; + needSpace = false; + } + + stream << (paint.aquifer ? "AQUIFER" : "NO AQUIFER"); + used = true; + needSpace = true; + } + if (!used) { stream << "any"; @@ -437,7 +481,11 @@ bool processTileType(color_ostream & out, TileType &paint, std::vector -1 && filter.shape != tileShape(source)) - || (filter.material > -1 && filter.material != tileMaterial(source)) - || (filter.special > -1 && filter.special != tileSpecial(source)) - || (filter.variant > -1 && filter.variant != tileVariant(source)) - || (filter.dig > -1 && (filter.dig != 0) != (des.bits.dig != tile_dig_designation::No)) - ) + if (!filter.matches(source, des)) { - return CR_OK; + continue; } df::tiletype_shape shape = paint.shape; @@ -707,6 +750,11 @@ command_result executePaintJob(color_ostream &out) des.bits.outside = paint.skyview; } + if (paint.aquifer > -1) + { + des.bits.water_table = paint.aquifer; + } + // Remove liquid from walls, etc if (type != -1 && !DFHack::FlowPassable(type)) { @@ -782,6 +830,9 @@ command_result processCommand(color_ostream &out, std::vector &comm } if (width < 1 || height < 1) { + width = width < 1? 1 : width; + height = height < 1? 1 : height; + z_levels = z_levels < 1? 1 : z_levels; if (hasConsole) { Console &con = static_cast(out); CommandHistory hist; @@ -804,9 +855,9 @@ command_result processCommand(color_ostream &out, std::vector &comm } } - if (width < 1) width = 1; - if (height < 1) height = 1; - if (z_levels < 1) z_levels = 1; + width = width < 1? 1 : width; + height = height < 1? 1 : height; + z_levels = z_levels < 1? 1 : z_levels; delete brush; brush = new RectangleBrush(width, height, z_levels, 0, 0, 0); From 52138d8998e38b6af550749ac7fd226a7bd86edd Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Thu, 19 Apr 2012 21:13:07 -0600 Subject: [PATCH 2/5] Improve the range function of tiletypes a bit and add the functionality to liquids. --- plugins/Brushes.h | 52 ++++++++++++++++++++++++++++++++++++++-- plugins/liquids.cpp | 55 +++++++++++++++++++++++-------------------- plugins/tiletypes.cpp | 36 +++++----------------------- 3 files changed, 86 insertions(+), 57 deletions(-) diff --git a/plugins/Brushes.h b/plugins/Brushes.h index a525d279c..39f1614bd 100644 --- a/plugins/Brushes.h +++ b/plugins/Brushes.h @@ -196,12 +196,60 @@ private: Core *c_; }; -inline std::ostream &operator<<(std::ostream &stream, const Brush& brush) { +command_result parseRectangle(color_ostream & out, + int & width, int & height, int & zLevels, + int oldWidth, int oldHeight, int oldZLevels, + bool hasConsole = true) +{ + out << "Parse:" << endl + << "\tW:" << width << " - " << oldWidth << endl + << "\tW:" << height << " - " << oldHeight << endl + << "\tW:" << zLevels << " - " << oldZLevels << endl + << "Console: " << hasConsole << endl; + if (width < 1 || height < 1) { + if (hasConsole) { + string command = ""; + std::stringstream str; + Console &con = static_cast(out); + CommandHistory hist; + + str.str(""); + str << "Set range width <" << oldWidth << "> "; + con.lineedit(str.str(), command, hist); + hist.add(command); + width = command == "" ? oldWidth : atoi(command.c_str()); + + str.str(""); + str << "Set range height <" << oldHeight << "> "; + con.lineedit(str.str(), command, hist); + hist.add(command); + height = command == "" ? oldHeight : atoi(command.c_str()); + + str.str(""); + str << "Set range z-levels <" << oldZLevels << "> "; + con.lineedit(str.str(), command, hist); + hist.add(command); + zLevels = command == "" ? oldZLevels : atoi(command.c_str()); + } else { + return CR_WRONG_USAGE; + } + } + + width = width < 1? 1 : width; + height = height < 1? 1 : height; + zLevels = zLevels < 1? 1 : zLevels; + + return CR_OK; +} + +inline std::ostream &operator<<(std::ostream &stream, const Brush& brush) +{ stream << brush.str(); return stream; } -inline std::ostream &operator<<(std::ostream &stream, const Brush* brush) { +inline std::ostream &operator<<(std::ostream &stream, const Brush* brush) +{ stream << brush->str(); return stream; } diff --git a/plugins/liquids.cpp b/plugins/liquids.cpp index 167e51ce8..ff222126d 100644 --- a/plugins/liquids.cpp +++ b/plugins/liquids.cpp @@ -107,22 +107,27 @@ command_result df_liquids (color_ostream &out_, vector & parameters) return CR_FAILURE; } + std::vector commands; bool end = false; out << "Welcome to the liquid spawner.\nType 'help' or '?' for a list of available commands, 'q' to quit.\nPress return after a command to confirm." << std::endl; while(!end) { - string command = ""; + string input = ""; std::stringstream str; str <<"[" << mode << ":" << brushname; if (brushname == "range") str << "(w" << width << ":h" << height << ":z" << z_levels << ")"; str << ":" << amount << ":" << flowmode << ":" << setmode << "]#"; - if(out.lineedit(str.str(),command,liquids_hist) == -1) + if(out.lineedit(str.str(),input,liquids_hist) == -1) return CR_FAILURE; - liquids_hist.add(command); + liquids_hist.add(input); + + commands.clear(); + Core::cheap_tokenise(input, commands); + string command = commands.empty() ? "" : commands[0]; if(command=="help" || command == "?") { @@ -195,28 +200,28 @@ command_result df_liquids (color_ostream &out_, vector & parameters) } else if(command == "range" || command == "r") { - std::stringstream str; - CommandHistory range_hist; - str << " :set range width<" << width << "># "; - out.lineedit(str.str(),command,range_hist); - range_hist.add(command); - width = command == "" ? width : atoi (command.c_str()); - if(width < 1) width = 1; - - str.str(""); - str << " :set range height<" << height << "># "; - out.lineedit(str.str(),command,range_hist); - range_hist.add(command); - height = command == "" ? height : atoi (command.c_str()); - if(height < 1) height = 1; - - str.str(""); - str << " :set range z-levels<" << z_levels << "># "; - out.lineedit(str.str(),command,range_hist); - range_hist.add(command); - z_levels = command == "" ? z_levels : atoi (command.c_str()); - if(z_levels < 1) z_levels = 1; - if(width == 1 && height == 1 && z_levels == 1) + int oldWidth = width, oldHeight = height, oldZLevels = z_levels; + width = height = z_levels = 0; + + if (commands.size() >= 3) + { + width = atoi(commands[1].c_str()); + height = atoi(commands[2].c_str()); + + if (commands.size() >= 4) { + z_levels = atoi(commands[3].c_str()); + } + } + + command_result res = parseRectangle(out, width, height, z_levels, + oldWidth, oldHeight, oldZLevels); + + if (res != CR_OK) + { + return res; + } + + if (width == 1 && height == 1 && z_levels == 1) { brushname = "point"; } diff --git a/plugins/tiletypes.cpp b/plugins/tiletypes.cpp index 230870f8d..236ac1fa1 100644 --- a/plugins/tiletypes.cpp +++ b/plugins/tiletypes.cpp @@ -819,46 +819,22 @@ command_result processCommand(color_ostream &out, std::vector &comm { int width = 0, height = 0, z_levels = 0; - if (commands.size() > loc + 1) + if (commands.size() >= loc) { width = toint(commands[loc++]); height = toint(commands[loc++]); - if (commands.size() > loc) { + if (commands.size() >= loc) { z_levels = toint(commands[loc++]); } } - if (width < 1 || height < 1) { - width = width < 1? 1 : width; - height = height < 1? 1 : height; - z_levels = z_levels < 1? 1 : z_levels; - if (hasConsole) { - Console &con = static_cast(out); - CommandHistory hist; - - ss_o << "Set range width <" << width << "> "; - con.lineedit(ss_o.str(),command,hist); - width = command == "" ? width : toint(command); - - ss_o.str(""); - ss_o << "Set range height <" << height << "> "; - con.lineedit(ss_o.str(),command,hist); - height = command == "" ? height : toint(command); - - ss_o.str(""); - ss_o << "Set range z-levels <" << z_levels << "> "; - con.lineedit(ss_o.str(),command,hist); - z_levels = command == "" ? z_levels : toint(command); - } else { - return CR_WRONG_USAGE; - } + command_result res = parseRectangle(out, width, height, z_levels, width, height, z_levels, hasConsole); + if (res != CR_OK) + { + return res; } - width = width < 1? 1 : width; - height = height < 1? 1 : height; - z_levels = z_levels < 1? 1 : z_levels; - delete brush; brush = new RectangleBrush(width, height, z_levels, 0, 0, 0); } From 567b3e2a52a3be8949c4536cff15e68b55f87fc6 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Sat, 21 Apr 2012 11:26:40 -0600 Subject: [PATCH 3/5] Fix range on tiletypes and make it saner for both plugins. --- plugins/Brushes.h | 63 ++++++++++++++++++++++++++++++------------- plugins/liquids.cpp | 18 ++----------- plugins/tiletypes.cpp | 18 +++---------- 3 files changed, 50 insertions(+), 49 deletions(-) diff --git a/plugins/Brushes.h b/plugins/Brushes.h index 39f1614bd..7cbc73daa 100644 --- a/plugins/Brushes.h +++ b/plugins/Brushes.h @@ -197,47 +197,72 @@ private: }; command_result parseRectangle(color_ostream & out, + vector & input, int start, int end, int & width, int & height, int & zLevels, - int oldWidth, int oldHeight, int oldZLevels, bool hasConsole = true) { - out << "Parse:" << endl - << "\tW:" << width << " - " << oldWidth << endl - << "\tW:" << height << " - " << oldHeight << endl - << "\tW:" << zLevels << " - " << oldZLevels << endl - << "Console: " << hasConsole << endl; - if (width < 1 || height < 1) { + int newWidth = 0, newHeight = 0, newZLevels = 1; + // z is different so 'range w h' won't ask for it. + + if (end > start + 1) + { + newWidth = atoi(input[start++].c_str()); + newHeight = atoi(input[start++].c_str()); + } + + if (end > start) { + newZLevels = atoi(input[start++].c_str()); + } + + string command = ""; + std::stringstream str; + CommandHistory hist; + + if (newWidth < 1) { if (hasConsole) { - string command = ""; - std::stringstream str; Console &con = static_cast(out); - CommandHistory hist; str.str(""); - str << "Set range width <" << oldWidth << "> "; + str << "Set range width <" << width << "> "; con.lineedit(str.str(), command, hist); hist.add(command); - width = command == "" ? oldWidth : atoi(command.c_str()); + newWidth = command == "" ? width : atoi(command.c_str()); + } else { + return CR_WRONG_USAGE; + } + } + + if (newHeight < 1) { + if (hasConsole) { + Console &con = static_cast(out); str.str(""); - str << "Set range height <" << oldHeight << "> "; + str << "Set range height <" << height << "> "; con.lineedit(str.str(), command, hist); hist.add(command); - height = command == "" ? oldHeight : atoi(command.c_str()); + newHeight = command == "" ? height : atoi(command.c_str()); + } else { + return CR_WRONG_USAGE; + } + } + + if (newZLevels < 1) { + if (hasConsole) { + Console &con = static_cast(out); str.str(""); - str << "Set range z-levels <" << oldZLevels << "> "; + str << "Set range z-levels <" << zLevels << "> "; con.lineedit(str.str(), command, hist); hist.add(command); - zLevels = command == "" ? oldZLevels : atoi(command.c_str()); + newZLevels = command == "" ? zLevels : atoi(command.c_str()); } else { return CR_WRONG_USAGE; } } - width = width < 1? 1 : width; - height = height < 1? 1 : height; - zLevels = zLevels < 1? 1 : zLevels; + width = newWidth < 1? 1 : newWidth; + height = newHeight < 1? 1 : newHeight; + zLevels = newZLevels < 1? 1 : zLevels; return CR_OK; } diff --git a/plugins/liquids.cpp b/plugins/liquids.cpp index ff222126d..1ecf98b1f 100644 --- a/plugins/liquids.cpp +++ b/plugins/liquids.cpp @@ -200,22 +200,8 @@ command_result df_liquids (color_ostream &out_, vector & parameters) } else if(command == "range" || command == "r") { - int oldWidth = width, oldHeight = height, oldZLevels = z_levels; - width = height = z_levels = 0; - - if (commands.size() >= 3) - { - width = atoi(commands[1].c_str()); - height = atoi(commands[2].c_str()); - - if (commands.size() >= 4) { - z_levels = atoi(commands[3].c_str()); - } - } - - command_result res = parseRectangle(out, width, height, z_levels, - oldWidth, oldHeight, oldZLevels); - + command_result res = parseRectangle(out, commands, 1, commands.size(), + width, height, z_levels); if (res != CR_OK) { return res; diff --git a/plugins/tiletypes.cpp b/plugins/tiletypes.cpp index 236ac1fa1..b7914f259 100644 --- a/plugins/tiletypes.cpp +++ b/plugins/tiletypes.cpp @@ -788,7 +788,6 @@ command_result processCommand(color_ostream &out, std::vector &comm return executePaintJob(out); } - std::ostringstream ss_o; int loc = start; std::string command = commands[loc++]; @@ -817,26 +816,17 @@ command_result processCommand(color_ostream &out, std::vector &comm } else if (command == "range" || command == "r") { - int width = 0, height = 0, z_levels = 0; + int width = 1, height = 1, zLevels = 1; - if (commands.size() >= loc) - { - width = toint(commands[loc++]); - height = toint(commands[loc++]); - - if (commands.size() >= loc) { - z_levels = toint(commands[loc++]); - } - } - - command_result res = parseRectangle(out, width, height, z_levels, width, height, z_levels, hasConsole); + command_result res = parseRectangle(out, commands, loc, end, + width, height, zLevels, hasConsole); if (res != CR_OK) { return res; } delete brush; - brush = new RectangleBrush(width, height, z_levels, 0, 0, 0); + brush = new RectangleBrush(width, height, zLevels, 0, 0, 0); } else if (command == "block") { From 833bf518d973473d8abf8533e58b069610ddeb9c Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Mon, 7 May 2012 18:31:28 -0600 Subject: [PATCH 4/5] Fix some issues --- plugins/Brushes.h | 20 ++++++++++---------- plugins/tiletypes.cpp | 20 ++++++++++++++------ 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/plugins/Brushes.h b/plugins/Brushes.h index 7cbc73daa..a408f47b9 100644 --- a/plugins/Brushes.h +++ b/plugins/Brushes.h @@ -201,17 +201,17 @@ command_result parseRectangle(color_ostream & out, int & width, int & height, int & zLevels, bool hasConsole = true) { - int newWidth = 0, newHeight = 0, newZLevels = 1; - // z is different so 'range w h' won't ask for it. + int newWidth = 0, newHeight = 0, newZLevels = 0; if (end > start + 1) { newWidth = atoi(input[start++].c_str()); newHeight = atoi(input[start++].c_str()); - } - - if (end > start) { - newZLevels = atoi(input[start++].c_str()); + if (end > start) { + newZLevels = atoi(input[start++].c_str()); + } else { + newZLevels = 1; // So 'range w h' won't ask for it. + } } string command = ""; @@ -226,7 +226,7 @@ command_result parseRectangle(color_ostream & out, str << "Set range width <" << width << "> "; con.lineedit(str.str(), command, hist); hist.add(command); - newWidth = command == "" ? width : atoi(command.c_str()); + newWidth = command.empty() ? width : atoi(command.c_str()); } else { return CR_WRONG_USAGE; } @@ -240,7 +240,7 @@ command_result parseRectangle(color_ostream & out, str << "Set range height <" << height << "> "; con.lineedit(str.str(), command, hist); hist.add(command); - newHeight = command == "" ? height : atoi(command.c_str()); + newHeight = command.empty() ? height : atoi(command.c_str()); } else { return CR_WRONG_USAGE; } @@ -254,7 +254,7 @@ command_result parseRectangle(color_ostream & out, str << "Set range z-levels <" << zLevels << "> "; con.lineedit(str.str(), command, hist); hist.add(command); - newZLevels = command == "" ? zLevels : atoi(command.c_str()); + newZLevels = command.empty() ? zLevels : atoi(command.c_str()); } else { return CR_WRONG_USAGE; } @@ -262,7 +262,7 @@ command_result parseRectangle(color_ostream & out, width = newWidth < 1? 1 : newWidth; height = newHeight < 1? 1 : newHeight; - zLevels = newZLevels < 1? 1 : zLevels; + zLevels = newZLevels < 1? 1 : newZLevels; return CR_OK; } diff --git a/plugins/tiletypes.cpp b/plugins/tiletypes.cpp index b7914f259..59bdc7b3d 100644 --- a/plugins/tiletypes.cpp +++ b/plugins/tiletypes.cpp @@ -461,14 +461,10 @@ bool tryVariant(std::string value, TileType &paint) bool processTileType(color_ostream & out, TileType &paint, std::vector ¶ms, int start, int end) { - if (params.size() < start + 2) - { - return false; - } - int loc = start; std::string option = params[loc++]; - std::string value = params[loc++]; + std::string value = end <= loc ? "" : params[loc++]; + tolower(option); toupper(value); int valInt; if (value == "ANY") @@ -605,6 +601,18 @@ bool processTileType(color_ostream & out, TileType &paint, std::vector= -1 && valInt < 2) + { + paint.aquifer = valInt; + found = true; + } + else + { + out << "Unknown aquifer flag: " << value << std::endl; + } + } else if (option == "all" || option == "a") { loc--; From 5bd90e28b865de4ac4d766546e82b8f547b9ffeb Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Mon, 7 May 2012 19:30:33 -0600 Subject: [PATCH 5/5] Add a missing return in tiletypes --- plugins/tiletypes.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/tiletypes.cpp b/plugins/tiletypes.cpp index 59bdc7b3d..2cd1770b2 100644 --- a/plugins/tiletypes.cpp +++ b/plugins/tiletypes.cpp @@ -781,6 +781,7 @@ command_result executePaintJob(color_ostream &out) if (map.WriteAll()) { out.print("OK\n"); + return CR_OK; } else {