From 8ee15e29f95da59fa00c59e22db79a4e104794f4 Mon Sep 17 00:00:00 2001 From: dshaligram Date: Wed, 11 Jul 2007 09:56:56 +0000 Subject: [1737348] Allow stash.lua to annotate item names for autopickup so autopickup can use matches like } - 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 -- cgit v1.2.3-54-g00ecf