diff options
author | dshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573> | 2007-07-11 09:56:56 +0000 |
---|---|---|
committer | dshaligram <dshaligram@c06c8d41-db1a-0410-9941-cceddc491573> | 2007-07-11 09:56:56 +0000 |
commit | 8ee15e29f95da59fa00c59e22db79a4e104794f4 (patch) | |
tree | 3702f25e880318b75a4298ce70be345d7d02fc54 | |
parent | 4253009d0db24eb91b3daee9459f59a4a18f6142 (diff) | |
download | crawl-ref-8ee15e29f95da59fa00c59e22db79a4e104794f4.tar.gz crawl-ref-8ee15e29f95da59fa00c59e22db79a4e104794f4.zip |
[1737348] Allow stash.lua to annotate item names for autopickup so autopickup
can use matches like <Short Blades.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1832 c06c8d41-db1a-0410-9941-cceddc491573
-rw-r--r-- | crawl-ref/source/clua.cc | 5 | ||||
-rw-r--r-- | crawl-ref/source/dat/clua/userbase.lua | 5 | ||||
-rw-r--r-- | crawl-ref/source/dungeon.cc | 6 | ||||
-rw-r--r-- | crawl-ref/source/initfile.cc | 1 | ||||
-rw-r--r-- | crawl-ref/source/items.cc | 27 | ||||
-rw-r--r-- | crawl-ref/source/lua/stash.lua | 52 | ||||
-rw-r--r-- | crawl-ref/source/stash.cc | 24 | ||||
-rw-r--r-- | crawl-ref/source/stash.h | 4 |
8 files changed, 81 insertions, 43 deletions
diff --git a/crawl-ref/source/clua.cc b/crawl-ref/source/clua.cc index 5e9d621109..742a92a093 100644 --- a/crawl-ref/source/clua.cc +++ b/crawl-ref/source/clua.cc @@ -2043,7 +2043,7 @@ static int option_set(lua_State *ls) return (0); } -#define OPT_METATABLE "options.optaccess" +#define OPT_METATABLE "clua_metatable_optaccess" void luaopen_options(lua_State *ls) { int top = lua_gettop(ls); @@ -2067,8 +2067,7 @@ void luaopen_options(lua_State *ls) luaL_getmetatable(ls, OPT_METATABLE); lua_setmetatable(ls, -2); - - clua.setglobal("options"); + lua_setglobal(ls, "options"); } ///////////////////////////////////////////////////////////////////// diff --git a/crawl-ref/source/dat/clua/userbase.lua b/crawl-ref/source/dat/clua/userbase.lua index 669b4d8b84..15f56bfeb5 100644 --- a/crawl-ref/source/dat/clua/userbase.lua +++ b/crawl-ref/source/dat/clua/userbase.lua @@ -66,3 +66,8 @@ function c_interrupt_activity(aname, iname, cause, extra) return chk_interrupt_activity[aname](iname, cause, extra) end + +function opt_boolean(optname) + local optval = options[optname] + return optval == "true" or optval == "yes" +end
\ No newline at end of file diff --git a/crawl-ref/source/dungeon.cc b/crawl-ref/source/dungeon.cc index 533934abf5..07c41b7274 100644 --- a/crawl-ref/source/dungeon.cc +++ b/crawl-ref/source/dungeon.cc @@ -119,7 +119,7 @@ static void place_specific_stair(dungeon_feature_type stair, int dl = 0); static void place_branch_entrances(int dlevel, char level_type); static void place_extra_vaults(); -static void place_special_minivaults(int level_number, int level_type); +static void place_minivaults(int level_number, int level_type); static void place_traps( int level_number ); static void prepare_swamp(); static void prepare_shoals( int level_number ); @@ -700,7 +700,7 @@ static void build_dungeon_level(int level_number, int level_type) // Try to place minivaults that really badly want to be placed. Still // no guarantees, seeing this is a minivault. if (!player_in_branch(BRANCH_SHOALS)) - place_special_minivaults(level_number, level_type); + place_minivaults(level_number, level_type); place_branch_entrances( level_number, level_type ); place_extra_vaults(); dgn_verify_connectivity(nvaults); @@ -1330,7 +1330,7 @@ static builder_rc_type builder_by_branch(int level_number) return BUILD_CONTINUE; } -static void place_special_minivaults(int level_number, int level_type) +static void place_minivaults(int level_number, int level_type) { // Dungeon-style branches only, thankyouverymuch. if (level_type != LEVEL_DUNGEON) diff --git a/crawl-ref/source/initfile.cc b/crawl-ref/source/initfile.cc index 2467cc8b60..bcf373e371 100644 --- a/crawl-ref/source/initfile.cc +++ b/crawl-ref/source/initfile.cc @@ -1412,6 +1412,7 @@ void game_options::read_option_line(const std::string &str, bool runscript) if (key != "name" && key != "crawl_dir" && key != "race" && key != "class" && key != "ban_pickup" + && key != "autopickup_exceptions" && key != "stop_travel" && key != "sound" && key != "travel_stop_message" && key != "drop_filter" && key != "lua_file" diff --git a/crawl-ref/source/items.cc b/crawl-ref/source/items.cc index b83901bf6a..926876ead5 100644 --- a/crawl-ref/source/items.cc +++ b/crawl-ref/source/items.cc @@ -2615,9 +2615,16 @@ static void autoinscribe_item( item_def& item ) } } -static bool is_denied_autopickup(const item_def &item) +static inline std::string autopickup_item_name(const item_def &item) { - const std::string iname = item.name(DESC_PLAIN); + return userdef_annotate_item(STASH_LUA_SEARCH_ANNOTATE, &item, true) + + item.name(DESC_PLAIN); +} + +static bool is_denied_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)) @@ -2626,9 +2633,10 @@ static bool is_denied_autopickup(const item_def &item) return false; } -static bool is_forced_autopickup(const item_def &item) +static bool is_forced_autopickup(const item_def &item, std::string &iname) { - const std::string iname = item.name(DESC_PLAIN); + 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)) @@ -2658,14 +2666,15 @@ bool item_needs_autopickup(const item_def &item) if ((item.flags & ISFLAG_THROWN) && Options.pickup_thrown) return (true); + std::string itemname; return (((Options.autopickups & (1L << item.base_type)) - || is_forced_autopickup(item) + || is_forced_autopickup(item, itemname) #ifdef CLUA_BINDINGS - || clua.callbooleanfn(false, "ch_autopickup", "u", &item) + || clua.callbooleanfn(false, "ch_autopickup", "u", &item) #endif - ) - && (Options.pickup_dropped || !(item.flags & ISFLAG_DROPPED)) - && !is_denied_autopickup(item)); + ) + && (Options.pickup_dropped || !(item.flags & ISFLAG_DROPPED)) + && !is_denied_autopickup(item, itemname)); } bool can_autopickup() diff --git a/crawl-ref/source/lua/stash.lua b/crawl-ref/source/lua/stash.lua index ebdde34745..6af1178b79 100644 --- a/crawl-ref/source/lua/stash.lua +++ b/crawl-ref/source/lua/stash.lua @@ -1,30 +1,54 @@ --------------------------------------------------------------------------- -- stash.lua --- Annotates items for the stash-tracker's search. +-- Annotates items for the stash-tracker's search, and for autopickup +-- exception matches. -- -- To use this, add this line to your init.txt: -- lua_file = lua/stash.lua -- +-- Available annotations: +-- {artefact} for identified artefacs. +-- {ego} for identified branded items. +-- { <skill> } - the relevant weapon skill for weapons. +-- +-- You can optionally annotate items with the item class name (such as +-- "weapon" for weapons) by setting +-- annotate_item_class = true +-- in your init.txt. +-- +-- The full list of item class names is: +-- gold, weapon, missile, armour, wand, food, scroll, jewelry, potion, +-- book, staff, orb, misc, carrion +-- +-- Item annotations are always prefixed to the item name. For instance: +-- {artefact} the Staff of Wucad Mu --------------------------------------------------------------------------- +local ch_annotate_item_class = nil -- Annotate items for searches function ch_stash_search_annotate_item(it) - local annot = "" + local annot = "" + + if item.artefact(it) then + annot = annot .. "{artefact} " + elseif item.branded(it) then + annot = annot .. "{ego} " + end - if item.artifact(it) then - annot = annot .. "{artefact} " - elseif item.branded(it) then - annot = annot .. "{ego} " - elseif item.class(it, true) == "book" then - annot = annot .. "{book} " - end + local skill = item.weap_skill(it) + if skill then + annot = annot .. "{" .. skill .. "} " + end - local skill = item.weap_skill(it) - if skill then - annot = annot .. "{" .. skill .. "} " - end + if ch_annotate_item_class == nil then + ch_annotate_item_class = opt_boolean("annotate_item_class") + end + + if ch_annotate_item_class then + annot = annot .. "{" .. item.class(it, true) .. "}" + end - return annot + return annot end --- If you want dumps (.lst files) to be annotated, uncomment this line: diff --git a/crawl-ref/source/stash.cc b/crawl-ref/source/stash.cc index 6f67cb91c6..8068af9c6f 100644 --- a/crawl-ref/source/stash.cc +++ b/crawl-ref/source/stash.cc @@ -40,10 +40,6 @@ #define ST_MAJOR_VER ((unsigned char) 4) #define ST_MINOR_VER ((unsigned char) 7) -#define LUA_SEARCH_ANNOTATE "ch_stash_search_annotate_item" -#define LUA_DUMP_ANNOTATE "ch_stash_dump_annotate_item" -#define LUA_VIEW_ANNOTATE "ch_stash_view_annotate_item" - void stash_init_new_level() { // If there's an existing stash level for Pan, blow it away. @@ -57,11 +53,11 @@ std::string userdef_annotate_item(const char *s, const item_def *item, if (exclusive) lua_set_exclusive_item(item); std::string ann; - clua.callfn(s, "u>s", item, &ann); + if (!clua.callfn(s, "u>s", item, &ann)) + mprf(MSGCH_WARN, "Lua error: %s", clua.error.c_str()); if (exclusive) lua_set_exclusive_item(NULL); return (ann); - #else return (""); #endif @@ -72,11 +68,11 @@ std::string stash_annotate_item(const char *s, bool exclusive = false) { std::string text = userdef_annotate_item(s, item, exclusive); - if ( (item->base_type == OBJ_BOOKS && - item_type_known(*item) && - item->sub_type != BOOK_MANUAL && - item->sub_type != BOOK_DESTRUCTION) - || count_staff_spells(*item, true) > 1 ) + if ((item->base_type == OBJ_BOOKS + && item_type_known(*item) + && item->sub_type != BOOK_MANUAL + && item->sub_type != BOOK_DESTRUCTION) + || count_staff_spells(*item, true) > 1) { formatted_string fs; item_def dup = *item; @@ -510,7 +506,7 @@ bool Stash::matches_search(const std::string &prefix, const item_def &item = items[i]; std::string s = stash_item_name(item); std::string ann = stash_annotate_item( - LUA_SEARCH_ANNOTATE, &item); + STASH_LUA_SEARCH_ANNOTATE, &item); if (search.matches(prefix + " " + ann + s)) { if (!res.count++) @@ -578,7 +574,7 @@ void Stash::write(std::ostream &os, strncpy(buf, s.c_str(), sizeof buf); std::string ann = userdef_annotate_item( - LUA_DUMP_ANNOTATE, &item); + STASH_LUA_DUMP_ANNOTATE, &item); if (!ann.empty()) { @@ -823,7 +819,7 @@ bool ShopInfo::matches_search(const std::string &prefix, { std::string sname = shop_item_name(items[i]); std::string ann = stash_annotate_item( - LUA_SEARCH_ANNOTATE, &items[i].item, true); + STASH_LUA_SEARCH_ANNOTATE, &items[i].item, true); bool thismatch = false; if (search.matches(prefix + " " + ann + sname)) diff --git a/crawl-ref/source/stash.h b/crawl-ref/source/stash.h index 51ce593030..3d639a6491 100644 --- a/crawl-ref/source/stash.h +++ b/crawl-ref/source/stash.h @@ -328,4 +328,8 @@ void describe_stash(int x, int y); std::string userdef_annotate_item(const char *s, const item_def *item, bool exclusive = false); +#define STASH_LUA_SEARCH_ANNOTATE "ch_stash_search_annotate_item" +#define STASH_LUA_DUMP_ANNOTATE "ch_stash_dump_annotate_item" +#define STASH_LUA_VIEW_ANNOTATE "ch_stash_view_annotate_item" + #endif |