diff options
author | dshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573> | 2007-01-30 11:59:23 +0000 |
---|---|---|
committer | dshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573> | 2007-01-30 11:59:23 +0000 |
commit | 17d8bd89a7e6f4884334c0a8aa38907c43df5f81 (patch) | |
tree | afac3746a2146ac097c8d31426af07db1e7a1170 /crawl-ref/source | |
parent | b92ab27580d7d18a9458e3478d85ff8b8633106c (diff) | |
download | crawl-ref-17d8bd89a7e6f4884334c0a8aa38907c43df5f81.tar.gz crawl-ref-17d8bd89a7e6f4884334c0a8aa38907c43df5f81.zip |
Added autopickup_exceptions option modeled on NetHack's, so that it's easy to
request stuff to pick up without inscribing with =g. ban_pickup is now
semi-deprecated.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@908 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source')
-rw-r--r-- | crawl-ref/source/externs.h | 3 | ||||
-rw-r--r-- | crawl-ref/source/initfile.cc | 34 | ||||
-rw-r--r-- | crawl-ref/source/items.cc | 49 |
3 files changed, 61 insertions, 25 deletions
diff --git a/crawl-ref/source/externs.h b/crawl-ref/source/externs.h index 1458cac4c5..3d90aeb275 100644 --- a/crawl-ref/source/externs.h +++ b/crawl-ref/source/externs.h @@ -874,7 +874,8 @@ public: std::vector<std::pair<int, int> > mp_colour; std::string map_file_name; // name of mapping file to use - std::vector<text_pattern> banned_objects; // Objects we'll never pick up + std::vector<text_pattern> never_pickup; // Objects we'll never pick up + std::vector<text_pattern> always_pickup; // Stuff we always pick up std::vector<text_pattern> note_monsters; // Interesting monsters std::vector<text_pattern> note_messages; // Interesting messages std::vector<std::pair<text_pattern, std::string> > autoinscriptions; diff --git a/crawl-ref/source/initfile.cc b/crawl-ref/source/initfile.cc index 84e41f56f4..d5ae9102d1 100644 --- a/crawl-ref/source/initfile.cc +++ b/crawl-ref/source/initfile.cc @@ -741,7 +741,8 @@ void game_options::reset_options() mp_colour.push_back(std::pair<int, int>(100, LIGHTGREY)); mp_colour.push_back(std::pair<int, int>(50, YELLOW)); mp_colour.push_back(std::pair<int, int>(25, RED)); - banned_objects.clear(); + never_pickup.clear(); + always_pickup.clear(); note_monsters.clear(); note_messages.clear(); autoinscriptions.clear(); @@ -1802,22 +1803,39 @@ void game_options::read_option_line(const std::string &str, bool runscript) } else if (key == "ban_pickup") { - append_vector(banned_objects, split_string(",", field)); + append_vector(never_pickup, split_string(",", field)); + } + else if (key == "autopickup_exceptions") + { + std::vector<std::string> args = split_string(",", field); + for (int i = 0, size = args.size(); i < size; ++i) + { + const std::string &s = args[i]; + if (s.empty()) + continue; + + if (s[0] == '>') + never_pickup.push_back( s.substr(1) ); + else if (s[0] == '<') + always_pickup.push_back( s.substr(1) ); + else + never_pickup.push_back( s ); + } } else if (key == "note_items") { - append_vector(note_items, split_string(",", field)); + append_vector(note_items, split_string(",", field)); } else if (key == "autoinscribe") { - std::vector<std::string> thesplit = split_string(":", field); - autoinscriptions.push_back( - std::pair<text_pattern,std::string>(thesplit[0], - thesplit[1])); + std::vector<std::string> thesplit = split_string(":", field); + autoinscriptions.push_back( + std::pair<text_pattern,std::string>(thesplit[0], + thesplit[1])); } else if (key == "map_file_name") { - map_file_name = field; + map_file_name = field; } else if (key == "hp_colour" || key == "hp_color") { diff --git a/crawl-ref/source/items.cc b/crawl-ref/source/items.cc index 1c7e4681c3..a9093da5fa 100644 --- a/crawl-ref/source/items.cc +++ b/crawl-ref/source/items.cc @@ -2897,23 +2897,35 @@ static void autoinscribe_item( item_def& item ) /* if there's an inscription already do nothing */ if ( item.inscription.size() > 0 ) - return; + return; - for ( unsigned i = 0; i < Options.autoinscriptions.size(); ++i ) { - if ( Options.autoinscriptions[i].first.matches(iname) ) { - item.inscription += Options.autoinscriptions[i].second; - } + for ( unsigned i = 0; i < Options.autoinscriptions.size(); ++i ) + { + if ( Options.autoinscriptions[i].first.matches(iname) ) + { + item.inscription += Options.autoinscriptions[i].second; + } } } -static bool is_banned(const item_def &item) { - static char name[ITEMNAME_SIZE]; - item_name(item, DESC_INVENTORY, name, false); +static bool is_denied_autopickup(const item_def &item) +{ + std::string iname = item_name(item, DESC_PLAIN); + for (unsigned i = 0, size = Options.never_pickup.size(); i < size; ++i) + { + if (Options.never_pickup[i].matches(iname)) + return (true); + } + return false; +} - std::string iname = name; - for (unsigned i = 0; i < Options.banned_objects.size(); ++i) { - if (Options.banned_objects[i].matches(iname)) - return true; +static bool is_forced_autopickup(const item_def &item) +{ + std::string iname = item_name(item, DESC_PLAIN); + for (unsigned i = 0, size = Options.always_pickup.size(); i < size; ++i) + { + if (Options.always_pickup[i].matches(iname)) + return (true); } return false; } @@ -2933,15 +2945,20 @@ static void autoinscribe_items() bool item_needs_autopickup(const item_def &item) { - return (strstr(item.inscription.c_str(), "=g") != 0 - || ((item.flags & ISFLAG_THROWN) && Options.pickup_thrown) - || (((Options.autopickups & (1L << item.base_type)) + if (strstr(item.inscription.c_str(), "=g") != 0) + return (true); + + if ((item.flags & ISFLAG_THROWN) && Options.pickup_thrown) + return (true); + + return (((Options.autopickups & (1L << item.base_type)) + || is_forced_autopickup(item) #ifdef CLUA_BINDINGS || clua.callbooleanfn(false, "ch_autopickup", "u", &item) #endif ) && (Options.pickup_dropped || !(item.flags & ISFLAG_DROPPED)) - && !is_banned(item))); + && !is_denied_autopickup(item)); } bool can_autopickup() |