summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2007-07-24 05:34:35 +0000
committerdshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573>2007-07-24 05:34:35 +0000
commit0ce4685c4fe385d59c7abafc7ad8b1b5289b4f6e (patch)
tree5edbf07ba78c5a45e1da26a0c6c733c9216e061d
parentedbb46d293cfc03a4f5f2077b494d62f7c0873e0 (diff)
downloadcrawl-ref-0ce4685c4fe385d59c7abafc7ad8b1b5289b4f6e.tar.gz
crawl-ref-0ce4685c4fe385d59c7abafc7ad8b1b5289b4f6e.zip
Allow NetHack-style OPTION=foo,!bar,baz:x lines.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1922 c06c8d41-db1a-0410-9941-cceddc491573
-rw-r--r--crawl-ref/docs/crawl_options.txt46
-rw-r--r--crawl-ref/source/externs.h5
-rw-r--r--crawl-ref/source/initfile.cc41
3 files changed, 67 insertions, 25 deletions
diff --git a/crawl-ref/docs/crawl_options.txt b/crawl-ref/docs/crawl_options.txt
index d080639f54..f431b8f483 100644
--- a/crawl-ref/docs/crawl_options.txt
+++ b/crawl-ref/docs/crawl_options.txt
@@ -86,21 +86,37 @@ The contents of this text are:
--------------------------------------------------------------------------------
-There are basically three types of Crawl options: true/false values (booleans),
-numbers, and lists. An option is most often specified with its default value
-(if there is one); this should also explain which of the above-mentioned types
-it is. Each option should have some remarks on how it's typically used - beware
-that this depends strongly on your playing style and sometimes also on hardware
-or operating system.
-
-Note that the init.txt coming with regular distributions has all boolean
-options commented out. The commented-out values are always the _non-defaults_,
-so you can toggle boolean options by just uncommenting them.
-
-Some options need a path as an argument; here you have to use a filesystem path
-suitable for your system. Other options accept regular expressions (regexes):
-here you can simply use ordinary strings, adapt the suggested regexes to your
-needs or search the internet for regex syntax.
+There are three broad types of Crawl options: true/false values
+(booleans), arbitrary values, and lists of values. In this document,
+options are usually described with their default values (if there is a
+default); this should also explain which of the above-mentioned types
+it is. Each option should have some remarks on how it's typically used
+- but keep in mind that the options you want to use depend on your
+playing style and sometimes also on your operating system.
+
+The standard init.txt distributed with Crawl includes all boolean
+options, commented out. The commented-out values are always the
+_non-defaults_, so you can toggle boolean options by uncommenting
+them.
+
+There are two styles you can use to set options. The classic
+name=value syntax, one option per-line:
+ remember_name = true
+ explore_greedy = false
+ drop_mode = multi
+
+And the NetHack-style combined option line:
+ OPTION = remember_name, !explore_greedy, drop_mode:multi
+
+The second style is useful to specify simple options in a few lines,
+but it cannot be used for options that take complex lists of values
+(such as the autopickup_exceptions option).
+
+Some options need a path as an argument; here you have to use a
+filesystem path suitable for your system. Other options accept regular
+expressions (regexes): here you can simply use ordinary strings, adapt
+the suggested regexes to your needs or search the internet for regex
+syntax.
For long option names, you can define option aliases by doing:
alias := long_option_name
diff --git a/crawl-ref/source/externs.h b/crawl-ref/source/externs.h
index bba92b51c0..5bdb476cbc 100644
--- a/crawl-ref/source/externs.h
+++ b/crawl-ref/source/externs.h
@@ -1864,12 +1864,13 @@ private:
int read_explore_stop_conditions(const std::string &) const;
void validate_options();
- void add_all(const std::string &s, const std::string &separator,
- void (game_options::*add)(const std::string &));
+ void split_parse(const std::string &s, const std::string &separator,
+ void (game_options::*add)(const std::string &));
void add_mon_glyph_override(monster_type mtype, mon_display &mdisp);
void add_mon_glyph_overrides(const std::string &mons, mon_display &mdisp);
void add_mon_glyph_override(const std::string &);
mon_display parse_mon_glyph(const std::string &s) const;
+ void set_option_fragment(const std::string &s);
static const std::string interrupt_prefix;
};
diff --git a/crawl-ref/source/initfile.cc b/crawl-ref/source/initfile.cc
index 65386c6290..95b2494c36 100644
--- a/crawl-ref/source/initfile.cc
+++ b/crawl-ref/source/initfile.cc
@@ -97,7 +97,7 @@ int str_to_colour( const std::string &str, int default_colour,
"magic", "mutagenic", "warp", "enchant", "heal", "holy", "dark",
"death", "necro", "unholy", "vehumet", "crystal", "blood", "smoke",
"slime", "jewel", "elven", "dwarven", "orcish", "gila", "floor",
- "rock", "stone", "mist", "random"
+ "rock", "stone", "mist", "shimmer_blue", "random"
};
for (ret = 0; ret < 16; ret++)
@@ -1392,14 +1392,36 @@ void game_options::set_menu_sort(std::string field)
sort_menus.push_back(cond);
}
-void game_options::add_all(const std::string &s, const std::string &separator,
- void (game_options::*add)(const std::string &))
+void game_options::split_parse(
+ const std::string &s, const std::string &separator,
+ void (game_options::*add)(const std::string &))
{
const std::vector<std::string> defs = split_string(separator, s);
for (int i = 0, size = defs.size(); i < size; ++i)
(this->*add)( defs[i] );
}
+void game_options::set_option_fragment(const std::string &s)
+{
+ if (s.empty())
+ return;
+
+ std::string::size_type st = s.find(':');
+ if (st == std::string::npos)
+ {
+ // Boolean option.
+ if (s[0] == '!')
+ read_option_line(s.substr(1) + " = false");
+ else
+ read_option_line(s + " = true");
+ }
+ else
+ {
+ // key:val option.
+ read_option_line(s.substr(0, st) + " = " + s.substr(st + 1));
+ }
+}
+
void game_options::read_option_line(const std::string &str, bool runscript)
{
std::string key = "";
@@ -1476,7 +1498,7 @@ void game_options::read_option_line(const std::string &str, bool runscript)
&& key != "note_monsters" && key != "note_messages"
&& key.find("cset") != 0 && key != "dungeon"
&& key != "feature" && key != "fire_items_start"
- && key != "mon_glyph"
+ && key != "mon_glyph" && key != "opt" && key != "option"
&& key != "menu_colour" && key != "menu_color"
&& key != "message_colour" && key != "message_color"
&& key != "levels" && key != "level" && key != "entries")
@@ -1484,8 +1506,11 @@ void game_options::read_option_line(const std::string &str, bool runscript)
lowercase( field );
}
- // everything not a valid line is treated as a comment
- if (key == "autopickup")
+ if (key == "opt" || key == "option")
+ {
+ split_parse(field, ",", &game_options::set_option_fragment);
+ }
+ else if (key == "autopickup")
{
// clear out autopickup
autopickups = 0L;
@@ -1722,11 +1747,11 @@ void game_options::read_option_line(const std::string &str, bool runscript)
}
else if (key == "feature" || key == "dungeon")
{
- add_all(field, ";", &game_options::add_feature_override);
+ split_parse(field, ";", &game_options::add_feature_override);
}
else if (key == "mon_glyph")
{
- add_all(field, ",", &game_options::add_mon_glyph_override);
+ split_parse(field, ",", &game_options::add_mon_glyph_override);
}
else if (key == "friend_brand")
{