diff options
-rw-r--r-- | crawl-ref/docs/options_guide.txt | 10 | ||||
-rw-r--r-- | crawl-ref/settings/init.txt | 2 | ||||
-rw-r--r-- | crawl-ref/source/externs.h | 1 | ||||
-rw-r--r-- | crawl-ref/source/initfile.cc | 24 | ||||
-rw-r--r-- | crawl-ref/source/invent.cc | 5 | ||||
-rw-r--r-- | crawl-ref/source/invent.h | 2 | ||||
-rw-r--r-- | crawl-ref/source/itemname.cc | 28 | ||||
-rw-r--r-- | crawl-ref/source/itemname.h | 2 | ||||
-rw-r--r-- | crawl-ref/source/menu.cc | 2 | ||||
-rw-r--r-- | crawl-ref/source/menu.h | 5 |
10 files changed, 75 insertions, 6 deletions
diff --git a/crawl-ref/docs/options_guide.txt b/crawl-ref/docs/options_guide.txt index 30ee80e321..365b4e1e1b 100644 --- a/crawl-ref/docs/options_guide.txt +++ b/crawl-ref/docs/options_guide.txt @@ -214,6 +214,12 @@ You can define shortcuts for option values (variables). For example, could be used in conjunction with menu_colour = $useless:random uselessness +To prevent a variable from being changed you can make it a constant: + constant = useless + +This is usefull if you wish to prevent an included file from altering +a variable. + See settings/standard_colours.txt and settings/food_colouring.txt for usage of aliases and variables. @@ -491,6 +497,10 @@ drop_filter = <regex> regularly sacrifice all weapons except axes, use: drop_filter = axe, broadaxe + drop_filter will match against the same keywords menu_colour uses, + except that it lacks identification status and corpse/chunk + information. It defaults to useless_item. + When a drop_filter is set, using the select/deselect keys will set/clear selection of items that match the filter expression(s). diff --git a/crawl-ref/settings/init.txt b/crawl-ref/settings/init.txt index 0a30f19b95..0ef981a890 100644 --- a/crawl-ref/settings/init.txt +++ b/crawl-ref/settings/init.txt @@ -96,6 +96,8 @@ autopickup = $?!+"/% # There is a long list of autopickup exceptions in include = autopickup_exceptions.txt +drop_filter = useless_item + # default_autopickup = false # autopickup_no_burden = true # pickup_thrown = false diff --git a/crawl-ref/source/externs.h b/crawl-ref/source/externs.h index 41885c7f7a..97c91451fb 100644 --- a/crawl-ref/source/externs.h +++ b/crawl-ref/source/externs.h @@ -2221,6 +2221,7 @@ private: typedef std::map<std::string, std::string> string_map; string_map aliases; string_map variables; + std::set<std::string> constants; // Variables that can't be changed std::set<std::string> included; // Files we've included already. public: diff --git a/crawl-ref/source/initfile.cc b/crawl-ref/source/initfile.cc index bbd6dcdc4f..5032753e8b 100644 --- a/crawl-ref/source/initfile.cc +++ b/crawl-ref/source/initfile.cc @@ -933,6 +933,11 @@ void game_options::reset_options() // Forget any files we remembered as included. included.clear(); + + // Forget variables and such. + aliases.clear(); + variables.clear(); + constants.clear(); } void game_options::clear_cset_overrides() @@ -1561,7 +1566,13 @@ int game_options::read_explore_stop_conditions(const std::string &field) const void game_options::add_alias(const std::string &key, const std::string &val) { if (key[0] == '$') - variables[key.substr(1)] = val; + { + std::string name = key.substr(1); + // Don't alter if it's a constant. + if (constants.find(name) != constants.end()) + return; + variables[name] = val; + } else aliases[key] = val; } @@ -3043,6 +3054,17 @@ void game_options::read_option_line(const std::string &str, bool runscript) { _bindkey(field); } + else if (key == "constant") + { + if (variables.find(field) == variables.end()) + report_error(make_stringf("No variable named '%s' to make " + "constant", field.c_str())); + else if (constants.find(field) != constants.end()) + report_error(make_stringf("'%s' is already a constant", + field.c_str())); + else + constants.insert(field); + } // Catch-all else, copies option into map else if (runscript) diff --git a/crawl-ref/source/invent.cc b/crawl-ref/source/invent.cc index d91d2512b7..fa03f8b291 100644 --- a/crawl-ref/source/invent.cc +++ b/crawl-ref/source/invent.cc @@ -173,6 +173,11 @@ void InvEntry::select(int qty) MenuEntry::select(qty); } +std::string InvEntry::get_filter_text() const +{ + return (filtering_item_prefix(*item) + " " + get_text()); +} + std::string InvEntry::get_text() const { std::ostringstream tstr; diff --git a/crawl-ref/source/invent.h b/crawl-ref/source/invent.h index 844cbeadf6..079d15ff1e 100644 --- a/crawl-ref/source/invent.h +++ b/crawl-ref/source/invent.h @@ -99,6 +99,8 @@ public: virtual void select( int qty = -1 ); + virtual std::string get_filter_text() const; + #ifdef USE_TILE virtual bool tile(int &tile, TextureID &tex) const; #endif diff --git a/crawl-ref/source/itemname.cc b/crawl-ref/source/itemname.cc index 58356b012e..99554a5023 100644 --- a/crawl-ref/source/itemname.cc +++ b/crawl-ref/source/itemname.cc @@ -2508,11 +2508,16 @@ bool is_useless_item(const item_def &item, bool temp) } } -const std::string menu_colour_item_prefix(const item_def &item, bool temp) +static const std::string _item_prefix(const item_def &item, bool temp, + bool filter) { std::vector<std::string> prefixes; - if (item_ident(item, ISFLAG_KNOW_TYPE)) + // No identified/unidentified for filtering, since the user might + // want to filter on "ident" to find scrolls of identify. + if (filter) + ; + else if (item_ident(item, ISFLAG_KNOW_TYPE)) prefixes.push_back("identified"); else { @@ -2584,7 +2589,12 @@ const std::string menu_colour_item_prefix(const item_def &item, bool temp) else if (is_preferred_food(item)) prefixes.push_back("preferred"); - if (is_poisonous(item)) + // Don't include these for filtering, since the user might want + // to use "muta" to search for "potion of cure mutation", and + // similar. + if (filter) + ; + else if (is_poisonous(item)) prefixes.push_back("poisonous"); else if (is_mutagenic(item)) prefixes.push_back("mutagenic"); @@ -2622,7 +2632,7 @@ const std::string menu_colour_item_prefix(const item_def &item, bool temp) break; } - if (Options.menu_colour_prefix_class) + if (Options.menu_colour_prefix_class && !filter) prefixes.push_back(item_class_name(item.base_type, true)); std::string result = comma_separated_line(prefixes.begin(), prefixes.end(), @@ -2631,6 +2641,16 @@ const std::string menu_colour_item_prefix(const item_def &item, bool temp) return result; } +const std::string menu_colour_item_prefix(const item_def &item, bool temp) +{ + return _item_prefix(item, temp, false); +} + +const std::string filtering_item_prefix(const item_def &item, bool temp) +{ + return _item_prefix(item, temp, true); +} + const std::string get_menu_colour_prefix_tags(item_def &item, description_level_type desc) { diff --git a/crawl-ref/source/itemname.h b/crawl-ref/source/itemname.h index baab01e6b7..d735708246 100644 --- a/crawl-ref/source/itemname.h +++ b/crawl-ref/source/itemname.h @@ -128,6 +128,8 @@ void set_ident_type( object_class_type basetype, int subtype, * *********************************************************************** */ const std::string menu_colour_item_prefix(const item_def &item, bool temp = true); +const std::string filtering_item_prefix(const item_def &item, + bool temp = true); const std::string get_menu_colour_prefix_tags(item_def &item, description_level_type desc); const std::string get_message_colour_tags(item_def &item, diff --git a/crawl-ref/source/menu.cc b/crawl-ref/source/menu.cc index 74507803e2..6daa92f940 100644 --- a/crawl-ref/source/menu.cc +++ b/crawl-ref/source/menu.cc @@ -675,7 +675,7 @@ bool Menu::is_selectable(int item) const if (select_filter.empty()) return (true); - std::string text = items[item]->get_text(); + std::string text = items[item]->get_filter_text(); for (int i = 0, count = select_filter.size(); i < count; ++i) { if (select_filter[i].matches(text)) diff --git a/crawl-ref/source/menu.h b/crawl-ref/source/menu.h index 407c41210e..9ddc336e65 100644 --- a/crawl-ref/source/menu.h +++ b/crawl-ref/source/menu.h @@ -138,6 +138,11 @@ struct MenuEntry selected_qty = (qty == -1? quantity : qty); } + virtual std::string get_filter_text() const + { + return get_text(); + } + #ifdef USE_TILE virtual bool tile(int &idx, TextureID &tex) const { |