From bbc3d962b7793b2a54e0e723049ecb706f945153 Mon Sep 17 00:00:00 2001 From: dshaligram Date: Tue, 2 Sep 2008 17:03:12 +0000 Subject: Trunk->0.4 r6868: [2029973] Saner autopickup exceptions (doy). git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/branches/stone_soup-0.4@6869 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/externs.h | 3 +-- crawl-ref/source/initfile.cc | 18 ++++++++++++------ crawl-ref/source/items.cc | 39 ++++++++++----------------------------- 3 files changed, 23 insertions(+), 37 deletions(-) (limited to 'crawl-ref') diff --git a/crawl-ref/source/externs.h b/crawl-ref/source/externs.h index fdd48acfbb..922b15d9e9 100644 --- a/crawl-ref/source/externs.h +++ b/crawl-ref/source/externs.h @@ -1723,8 +1723,7 @@ public: std::vector > mp_colour; std::string map_file_name; // name of mapping file to use - std::vector never_pickup; // Objects we'll never pick up - std::vector always_pickup; // Stuff we always pick up + std::vector > force_autopickup; std::vector note_monsters; // Interesting monsters std::vector note_messages; // Interesting messages std::vector > autoinscriptions; diff --git a/crawl-ref/source/initfile.cc b/crawl-ref/source/initfile.cc index 98db34eaeb..b589964586 100644 --- a/crawl-ref/source/initfile.cc +++ b/crawl-ref/source/initfile.cc @@ -884,8 +884,7 @@ void game_options::reset_options() mp_colour.push_back(std::pair(50, YELLOW)); mp_colour.push_back(std::pair(25, RED)); - never_pickup.clear(); - always_pickup.clear(); + force_autopickup.clear(); note_monsters.clear(); note_messages.clear(); autoinscriptions.clear(); @@ -2381,7 +2380,14 @@ void game_options::read_option_line(const std::string &str, bool runscript) } else if (key == "ban_pickup") { - append_vector(never_pickup, split_string(",", field)); + std::vector args = split_string(",", field); + for (int i = 0, size = args.size(); i < size; ++i) + { + const std::string &s = args[i]; + if (s.empty()) + continue; + force_autopickup.push_back(std::make_pair(s, false)); + } } else if (key == "autopickup_exceptions") { @@ -2393,11 +2399,11 @@ void game_options::read_option_line(const std::string &str, bool runscript) continue; if (s[0] == '>') - never_pickup.push_back( s.substr(1) ); + force_autopickup.push_back(std::make_pair(s.substr(1), false)); else if (s[0] == '<') - always_pickup.push_back( s.substr(1) ); + force_autopickup.push_back(std::make_pair(s.substr(1), true)); else - never_pickup.push_back( s ); + force_autopickup.push_back(std::make_pair(s, false)); } } else if (key == "note_items") diff --git a/crawl-ref/source/items.cc b/crawl-ref/source/items.cc index 4fd9dc21c7..2c1a077769 100644 --- a/crawl-ref/source/items.cc +++ b/crawl-ref/source/items.cc @@ -2182,34 +2182,14 @@ static inline std::string _autopickup_item_name(const item_def &item) + item.name(DESC_PLAIN); } -static bool _is_denied_autopickup(const item_def &item, std::string &iname) +static bool _is_option_autopickup(const item_def &item, std::string &iname) { if (iname.empty()) iname = _autopickup_item_name(item); - for (unsigned i = 0, size = Options.never_pickup.size(); i < size; ++i) - if (Options.never_pickup[i].matches(iname)) - return (true); - -#ifdef CLUA_BINDINGS - if (clua.callbooleanfn(false, "ch_deny_autopickup", "us", - &item, iname.c_str())) - { - return (true); - } -#endif - - return (false); -} - -static bool _is_forced_autopickup(const item_def &item, std::string &iname) -{ - if (iname.empty()) - iname = _autopickup_item_name(item); - - for (unsigned i = 0, size = Options.always_pickup.size(); i < size; ++i) - if (Options.always_pickup[i].matches(iname)) - return (true); + for (unsigned i = 0, size = Options.force_autopickup.size(); i < size; ++i) + if (Options.force_autopickup[i].first.matches(iname)) + return Options.force_autopickup[i].second; #ifdef CLUA_BINDINGS if (clua.callbooleanfn(false, "ch_force_autopickup", "us", @@ -2219,7 +2199,7 @@ static bool _is_forced_autopickup(const item_def &item, std::string &iname) } #endif - return (false); + return (Options.autopickups & (1L << item.base_type)); } bool item_needs_autopickup(const item_def &item) @@ -2233,11 +2213,12 @@ bool item_needs_autopickup(const item_def &item) if ((item.flags & ISFLAG_THROWN) && Options.pickup_thrown) return (true); + if ((item.flags & ISFLAG_DROPPED) && !Options.pickup_dropped) { + return (false); + } + std::string itemname; - return ((Options.autopickups & (1L << item.base_type) - || _is_forced_autopickup(item, itemname)) - && (Options.pickup_dropped || !(item.flags & ISFLAG_DROPPED)) - && !_is_denied_autopickup(item, itemname)); + return _is_option_autopickup(item, itemname); } bool can_autopickup() -- cgit v1.2.3-54-g00ecf