Petr Mrázek 2012-05-19 18:37:02 +02:00
commit b8ce3b45e1
4 changed files with 171 additions and 80 deletions

@ -825,7 +825,7 @@ Or this:
This will hide previously revealed tiles (or show hidden with the 0 option). 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 paint shape ANY
filter material any filter material any
filter shape any filter shape any
filter any
You can use several different brushes for painting tiles: You can use several different brushes for painting tiles:
* Point. (point) * Point. (point)

@ -206,12 +206,85 @@ private:
Core *c_; Core *c_;
}; };
inline std::ostream &operator<<(std::ostream &stream, const Brush& brush) { command_result parseRectangle(color_ostream & out,
vector<string> & input, int start, int end,
int & width, int & height, int & zLevels,
bool hasConsole = true)
{
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());
} else {
newZLevels = 1; // So 'range w h' won't ask for it.
}
}
string command = "";
std::stringstream str;
CommandHistory hist;
if (newWidth < 1) {
if (hasConsole) {
Console &con = static_cast<Console&>(out);
str.str("");
str << "Set range width <" << width << "> ";
con.lineedit(str.str(), command, hist);
hist.add(command);
newWidth = command.empty() ? width : atoi(command.c_str());
} else {
return CR_WRONG_USAGE;
}
}
if (newHeight < 1) {
if (hasConsole) {
Console &con = static_cast<Console&>(out);
str.str("");
str << "Set range height <" << height << "> ";
con.lineedit(str.str(), command, hist);
hist.add(command);
newHeight = command.empty() ? height : atoi(command.c_str());
} else {
return CR_WRONG_USAGE;
}
}
if (newZLevels < 1) {
if (hasConsole) {
Console &con = static_cast<Console&>(out);
str.str("");
str << "Set range z-levels <" << zLevels << "> ";
con.lineedit(str.str(), command, hist);
hist.add(command);
newZLevels = command.empty() ? zLevels : atoi(command.c_str());
} else {
return CR_WRONG_USAGE;
}
}
width = newWidth < 1? 1 : newWidth;
height = newHeight < 1? 1 : newHeight;
zLevels = newZLevels < 1? 1 : newZLevels;
return CR_OK;
}
inline std::ostream &operator<<(std::ostream &stream, const Brush& brush)
{
stream << brush.str(); stream << brush.str();
return stream; 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(); stream << brush->str();
return stream; return stream;
} }

@ -107,22 +107,27 @@ command_result df_liquids (color_ostream &out_, vector <string> & parameters)
return CR_FAILURE; return CR_FAILURE;
} }
std::vector<std::string> commands;
bool end = false; 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; 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) while(!end)
{ {
string command = ""; string input = "";
std::stringstream str; std::stringstream str;
str <<"[" << mode << ":" << brushname; str <<"[" << mode << ":" << brushname;
if (brushname == "range") if (brushname == "range")
str << "(w" << width << ":h" << height << ":z" << z_levels << ")"; str << "(w" << width << ":h" << height << ":z" << z_levels << ")";
str << ":" << amount << ":" << flowmode << ":" << setmode << "]#"; 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; 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 == "?") if(command=="help" || command == "?")
{ {
@ -195,28 +200,14 @@ command_result df_liquids (color_ostream &out_, vector <string> & parameters)
} }
else if(command == "range" || command == "r") else if(command == "range" || command == "r")
{ {
std::stringstream str; command_result res = parseRectangle(out, commands, 1, commands.size(),
CommandHistory range_hist; width, height, z_levels);
str << " :set range width<" << width << "># "; if (res != CR_OK)
out.lineedit(str.str(),command,range_hist); {
range_hist.add(command); return res;
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(""); if (width == 1 && height == 1 && z_levels == 1)
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)
{ {
brushname = "point"; brushname = "point";
} }

@ -86,6 +86,7 @@ void help( color_ostream & out, std::vector<std::string> &commands, int start, i
<< " run / (empty) : paint!" << std::endl << " run / (empty) : paint!" << std::endl
<< std::endl << std::endl
<< "Filter/paint options:" << 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 << " Shape / sh / s: set tile shape information" << std::endl
<< " Material / mat / m: set tile material information" << std::endl << " Material / mat / m: set tile material information" << std::endl
<< " Special / sp: set special tile information" << std::endl << " Special / sp: set special tile information" << std::endl
@ -96,6 +97,7 @@ void help( color_ostream & out, std::vector<std::string> &commands, int start, i
<< " Light / l: set light flag" << std::endl << " Light / l: set light flag" << std::endl
<< " Subterranean / st: set subterranean flag" << std::endl << " Subterranean / st: set subterranean flag" << std::endl
<< " Skyview / sv: set skyview 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; << "See help [option] for more information" << std::endl;
} }
else if (option == "shape" || option == "s" ||option == "sh") else if (option == "shape" || option == "s" ||option == "sh")
@ -159,6 +161,11 @@ void help( color_ostream & out, std::vector<std::string> &commands, int start, i
out << "Available skyview flags:" << std::endl out << "Available skyview flags:" << std::endl
<< " ANY, 0, 1" << 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 struct TileType
@ -172,8 +179,14 @@ struct TileType
int light; int light;
int subterranean; int subterranean;
int skyview; int skyview;
int aquifer;
TileType() TileType()
{
clear();
}
void clear()
{ {
shape = tiletype_shape::NONE; shape = tiletype_shape::NONE;
material = tiletype_material::NONE; material = tiletype_material::NONE;
@ -184,13 +197,31 @@ struct TileType
light = -1; light = -1;
subterranean = -1; subterranean = -1;
skyview = -1; skyview = -1;
aquifer = -1;
} }
bool empty() bool empty()
{ {
return shape == -1 && material == -1 && special == -1 && variant == -1 return shape == -1 && material == -1 && special == -1 && variant == -1
&& hidden == -1 && light == -1 && subterranean == -1 && skyview == -1 && dig == -1 && hidden == -1 && light == -1 && subterranean == -1
&& dig == -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; needSpace = true;
} }
if (paint.aquifer >= 0)
{
if (needSpace)
{
stream << " ";
needSpace = false;
}
stream << (paint.aquifer ? "AQUIFER" : "NO AQUIFER");
used = true;
needSpace = true;
}
if (!used) if (!used)
{ {
stream << "any"; stream << "any";
@ -417,14 +461,10 @@ bool tryVariant(std::string value, TileType &paint)
bool processTileType(color_ostream & out, TileType &paint, std::vector<std::string> &params, int start, int end) bool processTileType(color_ostream & out, TileType &paint, std::vector<std::string> &params, int start, int end)
{ {
if (params.size() < start + 2)
{
return false;
}
int loc = start; int loc = start;
std::string option = params[loc++]; std::string option = params[loc++];
std::string value = params[loc++]; std::string value = end <= loc ? "" : params[loc++];
tolower(option);
toupper(value); toupper(value);
int valInt; int valInt;
if (value == "ANY") if (value == "ANY")
@ -437,7 +477,11 @@ bool processTileType(color_ostream & out, TileType &paint, std::vector<std::stri
} }
bool found = false; bool found = false;
if (option == "shape" || option == "sh" || option == "s") if (option == "any")
{
paint.clear();
}
else if (option == "shape" || option == "sh" || option == "s")
{ {
if (is_valid_enum_item((df::tiletype_shape)valInt)) if (is_valid_enum_item((df::tiletype_shape)valInt))
{ {
@ -557,6 +601,18 @@ bool processTileType(color_ostream & out, TileType &paint, std::vector<std::stri
out << "Unknown skyview flag: " << value << std::endl; out << "Unknown skyview flag: " << value << std::endl;
} }
} }
else if (option == "aquifer" || option == "aqua")
{
if (valInt >= -1 && valInt < 2)
{
paint.aquifer = valInt;
found = true;
}
else
{
out << "Unknown aquifer flag: " << value << std::endl;
}
}
else if (option == "all" || option == "a") else if (option == "all" || option == "a")
{ {
loc--; loc--;
@ -622,14 +678,9 @@ command_result executePaintJob(color_ostream &out)
const df::tiletype source = map.tiletypeAt(*iter); const df::tiletype source = map.tiletypeAt(*iter);
df::tile_designation des = map.designationAt(*iter); df::tile_designation des = map.designationAt(*iter);
if ((filter.shape > -1 && filter.shape != tileShape(source)) if (!filter.matches(source, des))
|| (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))
)
{ {
return CR_OK; continue;
} }
df::tiletype_shape shape = paint.shape; df::tiletype_shape shape = paint.shape;
@ -710,6 +761,11 @@ command_result executePaintJob(color_ostream &out)
des.bits.outside = paint.skyview; des.bits.outside = paint.skyview;
} }
if (paint.aquifer > -1)
{
des.bits.water_table = paint.aquifer;
}
// Remove liquid from walls, etc // Remove liquid from walls, etc
if (type != -1 && !DFHack::FlowPassable(type)) if (type != -1 && !DFHack::FlowPassable(type))
{ {
@ -728,6 +784,7 @@ command_result executePaintJob(color_ostream &out)
if (map.WriteAll()) if (map.WriteAll())
{ {
out.print("OK\n"); out.print("OK\n");
return CR_OK;
} }
else else
{ {
@ -743,7 +800,6 @@ command_result processCommand(color_ostream &out, std::vector<std::string> &comm
return executePaintJob(out); return executePaintJob(out);
} }
std::ostringstream ss_o;
int loc = start; int loc = start;
std::string command = commands[loc++]; std::string command = commands[loc++];
@ -772,47 +828,17 @@ command_result processCommand(color_ostream &out, std::vector<std::string> &comm
} }
else if (command == "range" || command == "r") 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 + 1) command_result res = parseRectangle(out, commands, loc, end,
width, height, zLevels, hasConsole);
if (res != CR_OK)
{ {
width = toint(commands[loc++]); return res;
height = toint(commands[loc++]);
if (commands.size() > loc) {
z_levels = toint(commands[loc++]);
}
}
if (width < 1 || height < 1) {
if (hasConsole) {
Console &con = static_cast<Console&>(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;
}
} }
if (width < 1) width = 1;
if (height < 1) height = 1;
if (z_levels < 1) z_levels = 1;
delete brush; 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") else if (command == "block")
{ {