diff options
author | j-p-e-g <j-p-e-g@c06c8d41-db1a-0410-9941-cceddc491573> | 2008-06-10 07:41:27 +0000 |
---|---|---|
committer | j-p-e-g <j-p-e-g@c06c8d41-db1a-0410-9941-cceddc491573> | 2008-06-10 07:41:27 +0000 |
commit | aa3717c904d5d25c9f58f5d17e66379966f00a8f (patch) | |
tree | b0e55eb934017aada2332593ee8aa8979aeb9b58 /crawl-ref/source | |
parent | 172979dfbcd139f1adba90624340e9e6e5184cae (diff) | |
download | crawl-ref-aa3717c904d5d25c9f58f5d17e66379966f00a8f.tar.gz crawl-ref-aa3717c904d5d25c9f58f5d17e66379966f00a8f.zip |
Move pickup_butcher_tool.txt into (the recently freed) pickup.lua,
re-enable it (whoops) and clean up its code.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@5698 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source')
-rw-r--r-- | crawl-ref/source/clua.cc | 64 | ||||
-rw-r--r-- | crawl-ref/source/dat/lua/pickup.lua | 65 | ||||
-rw-r--r-- | crawl-ref/source/enum.h | 8 | ||||
-rw-r--r-- | crawl-ref/source/food.cc | 7 | ||||
-rw-r--r-- | crawl-ref/source/invent.cc | 13 | ||||
-rw-r--r-- | crawl-ref/source/item_use.cc | 17 | ||||
-rw-r--r-- | crawl-ref/source/itemname.cc | 16 | ||||
-rw-r--r-- | crawl-ref/source/items.cc | 3 |
8 files changed, 142 insertions, 51 deletions
diff --git a/crawl-ref/source/clua.cc b/crawl-ref/source/clua.cc index 41945a89f7..7f1e2180b0 100644 --- a/crawl-ref/source/clua.cc +++ b/crawl-ref/source/clua.cc @@ -930,10 +930,12 @@ static int l_item_swap_slots(lua_State *ls) int slot1 = luaL_checkint(ls, 1), slot2 = luaL_checkint(ls, 2); bool verbose = lua_toboolean(ls, 3); - if (slot1 < 0 || slot1 >= ENDOFPACK || - slot2 < 0 || slot2 >= ENDOFPACK || - slot1 == slot2 || !is_valid_item(you.inv[slot1])) + if (slot1 < 0 || slot1 >= ENDOFPACK + || slot2 < 0 || slot2 >= ENDOFPACK + || slot1 == slot2 || !is_valid_item(you.inv[slot1])) + { return (0); + } swap_inv_slots(slot1, slot2, verbose); @@ -1399,8 +1401,8 @@ static int l_item_slot(lua_State *ls) LUA_ITEM(item, 1); if (item) { - int slot = in_inventory(*item)? item->link : - letter_to_index(item->slot); + int slot = in_inventory(*item) ? item->link + : letter_to_index(item->slot); lua_pushnumber(ls, slot); } else @@ -1686,13 +1688,13 @@ static int food_ischunk(lua_State *ls) static const struct luaL_reg food_lib[] = { - { "do_eat", food_do_eat }, - { "prompt_floor", food_prompt_floor }, + { "do_eat", food_do_eat }, + { "prompt_floor", food_prompt_floor }, { "prompt_inventory", food_prompt_inventory }, - { "can_eat", food_can_eat }, - { "eat", food_eat }, - { "rotting", food_rotting }, - { "ischunk", food_ischunk }, + { "can_eat", food_can_eat }, + { "eat", food_eat }, + { "rotting", food_rotting }, + { "ischunk", food_ischunk }, { NULL, NULL }, }; @@ -2200,32 +2202,32 @@ static int option_hboolean(lua_State *ls, const char *name, void *data, static option_handler handlers[] = { // Boolean options come first - { "easy_open", &Options.easy_open, option_hboolean }, - { "colour_map", &Options.colour_map, option_hboolean }, - { "clean_map", &Options.clean_map, option_hboolean }, + { "easy_open", &Options.easy_open, option_hboolean }, + { "colour_map", &Options.colour_map, option_hboolean }, + { "clean_map", &Options.clean_map, option_hboolean }, { "show_uncursed", &Options.show_uncursed, option_hboolean }, - { "easy_open", &Options.easy_open, option_hboolean }, - { "easy_armour", &Options.easy_unequip, option_hboolean }, - { "easy_unequip", &Options.easy_unequip, option_hboolean }, - { "easy_butcher", &Options.easy_butcher, option_hboolean }, + { "easy_open", &Options.easy_open, option_hboolean }, + { "easy_armour", &Options.easy_unequip, option_hboolean }, + { "easy_unequip", &Options.easy_unequip, option_hboolean }, + { "easy_butcher", &Options.easy_butcher, option_hboolean }, { "always_confirm_butcher", &Options.always_confirm_butcher, option_hboolean }, - { "default_target", &Options.default_target, option_hboolean }, + { "default_target", &Options.default_target, option_hboolean }, { "autopickup_no_burden", &Options.autopickup_no_burden, option_hboolean }, - { "note_skill_max", &Options.note_skill_max, option_hboolean }, - { "delay_message_clear", &Options.delay_message_clear, option_hboolean }, - { "no_dark_brand", &Options.no_dark_brand, option_hboolean }, - { "auto_list", &Options.auto_list, option_hboolean }, - { "pickup_thrown", &Options.pickup_thrown, option_hboolean }, - { "pickup_dropped", &Options.pickup_dropped, option_hboolean }, - { "show_waypoints", &Options.show_waypoints, option_hboolean }, - { "item_colour", &Options.item_colour, option_hboolean }, + { "note_skill_max", &Options.note_skill_max, option_hboolean }, + { "delay_message_clear", &Options.delay_message_clear, option_hboolean }, + { "no_dark_brand", &Options.no_dark_brand, option_hboolean }, + { "auto_list", &Options.auto_list, option_hboolean }, + { "pickup_thrown", &Options.pickup_thrown, option_hboolean }, + { "pickup_dropped", &Options.pickup_dropped, option_hboolean }, + { "show_waypoints", &Options.show_waypoints, option_hboolean }, + { "item_colour", &Options.item_colour, option_hboolean }, { "target_zero_exp", &Options.target_zero_exp, option_hboolean }, - { "target_wrap", &Options.target_wrap, option_hboolean }, - { "easy_exit_menu", &Options.easy_exit_menu, option_hboolean }, + { "target_wrap", &Options.target_wrap, option_hboolean }, + { "easy_exit_menu", &Options.easy_exit_menu, option_hboolean }, { "dos_use_background_intensity", &Options.dos_use_background_intensity, - option_hboolean }, + option_hboolean }, { "menu_colour_prefix_class", &Options.menu_colour_prefix_class, - option_hboolean }, + option_hboolean }, }; static const option_handler *get_handler(const char *optname) diff --git a/crawl-ref/source/dat/lua/pickup.lua b/crawl-ref/source/dat/lua/pickup.lua new file mode 100644 index 0000000000..e1306f1b83 --- /dev/null +++ b/crawl-ref/source/dat/lua/pickup.lua @@ -0,0 +1,65 @@ +--------------------------------------------------------------------------- +-- eat.lua: +-- Pick up a butchering weapon if we don't already have one. +-- This requires ) to be in the autopickup option line. +-- +-- To use this, add this line to your init.txt: +-- lua_file = lua/pickup.lua +--------------------------------------------------------------------------- +function can_butcher(it) + if item.name(it):find("distort", 0, true) then + return false + end + + local skill = item.weap_skill(it) + -- Have to handle polearms separately, since only some of them can butcher. + if skill == "Polearms" or skill == "Staves" then + local butcherable_polearms = { + "scythe", "lajatang", "halberd", "bardiche", "glaive" + } + + for _, weap in ipairs(butcherable_polearms) do + if string.find( item.name(it, "a"), weap ) then + return true + end + end + return false + else + return string.find( skill, "Blades" ) or skill == "Axes" + end +end + +function ch_autopickup(it) + if item.class(it, true) == "weapon" then + + -- Trolls and Ghouls don't need weapons to butcher things, and Mummies + -- and Spriggans can't eat chunks. Ideally, we could detect a player + -- with the claws mutation here too, but that's not currently possible. + if you.race() == "Troll" + or you.race() == "Ghoul" + or you.race() == "Mummy" + or you.race() == "Spriggan" then + return false + end + + -- The item is not a good butchering tool, either. + if item.cursed(it) or not can_butcher(it) then + return false + end + + -- Check the inventory for butchering tools. + local inv = item.inventory() + for _, inv_it in ipairs(inv) do + if item.class(inv_it, true) == "weapon" + and can_butcher(inv_it) + and not item.cursed(inv_it) then + return false + end + end + end + + -- If we got here, we found no butchering tool in the inventory + -- AND this weapon is a good candidate tool for a butchering tool. + -- Ergo: pick it up. + return true +end
\ No newline at end of file diff --git a/crawl-ref/source/enum.h b/crawl-ref/source/enum.h index 6d385d1110..6dc9dca27e 100644 --- a/crawl-ref/source/enum.h +++ b/crawl-ref/source/enum.h @@ -2771,6 +2771,14 @@ enum friendly_pickup_type FRIENDLY_PICKUP_ALL }; +enum montravel_target_type +{ + MTRAV_NONE = 0, + MTRAV_PLAYER, // Travelling to reach the player. + MTRAV_PATROL, // Travelling to reach the patrol point. + MTRAV_UNREACHABLE // Not travelling because player is unreachable. +}; + #ifdef WIZARD enum wizard_option_type diff --git a/crawl-ref/source/food.cc b/crawl-ref/source/food.cc index 621abf33bd..adcb48127b 100644 --- a/crawl-ref/source/food.cc +++ b/crawl-ref/source/food.cc @@ -185,6 +185,10 @@ static bool _find_butchering_implement( bool fallback ) // automatically. if (const item_def *wpn = you.weapon()) { + // No switching necessary. + if (can_cut_meat( *wpn )) + return (false); + if (wpn->base_type == OBJ_WEAPONS && item_type_known(*wpn) && get_weapon_brand(*wpn) == SPWPN_DISTORTION) @@ -195,9 +199,6 @@ static bool _find_butchering_implement( bool fallback ) return (false); } - // No switching necessary. - if (can_cut_meat( *wpn )) - return (false); } int old_weapon = you.equip[EQ_WEAPON]; diff --git a/crawl-ref/source/invent.cc b/crawl-ref/source/invent.cc index 466352587e..bfd8a4ccaa 100644 --- a/crawl-ref/source/invent.cc +++ b/crawl-ref/source/invent.cc @@ -819,8 +819,8 @@ static bool _item_class_selected(const item_def &i, int selector) static bool _userdef_item_selected(const item_def &i, int selector) { #if defined(CLUA_BINDINGS) - const char *luafn = selector == OSEL_WIELD ? "ch_item_wieldable" : - NULL; + const char *luafn = selector == OSEL_WIELD ? "ch_item_wieldable" + : NULL; return (luafn && clua.callbooleanfn(false, luafn, "u", &i)); #else return (false); @@ -829,16 +829,19 @@ static bool _userdef_item_selected(const item_def &i, int selector) static bool _is_item_selected(const item_def &i, int selector) { - return _item_class_selected(i, selector) - || _userdef_item_selected(i, selector); + return (_item_class_selected(i, selector) + || _userdef_item_selected(i, selector)); } static void _get_inv_items_to_show(std::vector<const item_def*> &v, int selector) { for (int i = 0; i < ENDOFPACK; i++) { - if (is_valid_item(you.inv[i]) && _is_item_selected(you.inv[i], selector)) + if (is_valid_item(you.inv[i]) + && _is_item_selected(you.inv[i], selector)) + { v.push_back( &you.inv[i] ); + } } } diff --git a/crawl-ref/source/item_use.cc b/crawl-ref/source/item_use.cc index a704d4c989..e91c6b9296 100644 --- a/crawl-ref/source/item_use.cc +++ b/crawl-ref/source/item_use.cc @@ -862,8 +862,7 @@ bool can_wear_armour(const item_def &item, bool verbose, bool ignore_temporary) if (sub_type == ARM_NAGA_BARDING) can_wear = (you.species == SP_NAGA); - - if (sub_type == ARM_CENTAUR_BARDING) + else if (sub_type == ARM_CENTAUR_BARDING) can_wear = (you.species == SP_CENTAUR); if (!can_wear) @@ -921,14 +920,14 @@ bool can_wear_armour(const item_def &item, bool verbose, bool ignore_temporary) if (you.species == SP_NAGA && sub_type == ARM_NAGA_BARDING && (ignore_temporary || !player_is_shapechanged())) { - // it fits + // It fits. return (true); } else if (you.species == SP_CENTAUR && sub_type == ARM_CENTAUR_BARDING && (ignore_temporary || !player_is_shapechanged())) { - // it fits + // It fits. return (true); } else if (slot == EQ_HELMET) @@ -976,13 +975,13 @@ bool can_wear_armour(const item_def &item, bool verbose, bool ignore_temporary) } // Giant races - if ((you.species >= SP_OGRE && you.species <= SP_OGRE_MAGE) + if (you.species >= SP_OGRE && you.species <= SP_OGRE_MAGE || player_genus(GENPC_DRACONIAN)) { - if ((sub_type >= ARM_LEATHER_ARMOUR - && sub_type <= ARM_PLATE_MAIL) - || (sub_type >= ARM_GLOVES - && sub_type <= ARM_BUCKLER) + if (sub_type >= ARM_LEATHER_ARMOUR + && sub_type <= ARM_PLATE_MAIL + || sub_type >= ARM_GLOVES + && sub_type <= ARM_BUCKLER || sub_type == ARM_CRYSTAL_PLATE_MAIL || is_hard_helmet(item)) { diff --git a/crawl-ref/source/itemname.cc b/crawl-ref/source/itemname.cc index 919db49454..82bddb848e 100644 --- a/crawl-ref/source/itemname.cc +++ b/crawl-ref/source/itemname.cc @@ -2341,15 +2341,19 @@ bool is_dangerous_item(const item_def &item) bool is_useless_item(const item_def &item, bool temp) { - if (!item_type_known(item)) - return (false); - switch (item.base_type) { case OBJ_ARMOUR: return (!can_wear_armour(item, false, true)); + case OBJ_BOOKS: + return (item.sub_type != BOOK_DESTRUCTION + && item.sub_type != BOOK_MANUAL && you.religion == GOD_TROG); + case OBJ_SCROLLS: + if (!item_type_known(item)) + return (false); + // A bad item is always useless. if (is_bad_item(item)) return (true); @@ -2368,6 +2372,9 @@ bool is_useless_item(const item_def &item, bool temp) case OBJ_POTIONS: { + if (!item_type_known(item)) + return (false); + switch (item.sub_type) { case POT_CONFUSION: @@ -2410,6 +2417,9 @@ bool is_useless_item(const item_def &item, bool temp) return (false); } case OBJ_JEWELLERY: + if (!item_type_known(item)) + return (false); + if (is_bad_item(item)) return (true); diff --git a/crawl-ref/source/items.cc b/crawl-ref/source/items.cc index d4ff6e63fa..354257023a 100644 --- a/crawl-ref/source/items.cc +++ b/crawl-ref/source/items.cc @@ -2247,6 +2247,9 @@ bool item_needs_autopickup(const item_def &item) std::string itemname; return ((Options.autopickups & (1L << item.base_type) +#ifdef CLUA_BINDINGS + && clua.callbooleanfn(true, "ch_autopickup", "u", &item) +#endif && !is_useless_item(item) && !is_inedible(item) || _is_forced_autopickup(item, itemname)) && (Options.pickup_dropped || !(item.flags & ISFLAG_DROPPED)) |