in some more detail (a LOT more detail for potions).
Where to add this for crawlrc?
Also, while I appreciate being listed as author of trapwalk.lua, I'd rather not have my email address shown.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1881 c06c8d41-db1a-0410-9941-cceddc491573
KX23OEQBBLMQHTFCA4TYYEGLHCETXVZCXALYR5U5RELKJMMB66SAC SSCG2FLJMUTTIRXBFSPLAUUBUIN375ZGL5UOAF3SC62ZIILSMMKAC 5RRCORYDFW2N2YPUM4PDYZGI6RY7YWVMGWTY5ZIDVO6JRD5R5GAQC RPOZZWKG5GLPHVZZ7ZKMKS64ZMV2LDCQSARBJFJ6FZOTOKCQO7FAC UL7XFKMUX3WIU4O2LZANK4ECJ654UZPDBFGNXUEYZYOLKBYBCG6AC RREJL4WZKWFEMA62AC5G5UDTOXMW4UULIQXVA5RPFASPODMHQZ7AC K2CS6TCX2NDVL2ASEHGP4J4K4IJ6FP3ANNKTSIWVG43HPYSBX6ZQC 547JREUJXTZNYVGHNNAET5F5O5JYYGNTDQB6ABZNT7YX5EY64OHAC SDLKLUNFGVKDS55DDJZCBAVIB7NL3RRYPTACAY65SCUQKV6APFSAC RVST2QHYJ757ZHK4AUJ5NGPDZ44AD6RVFVXYPKQIBJXZBDNUCHXQC UF4ODJOCV3ZL7DXRLLOFVWHUKKJX34FO4ZM6VJAWEJ3QVP3XZ2AAC ----------------------------------------------------------------------------- pickup.lua:-- Smarter autopickup handling that takes into account the item type-- in combination with your character's race, religion, knowledge,-- and eating habits.---- To use this, add this line to your init.txt:-- lua_file = lua/pickup.lua---- Notes:-- * This script only handles items of classes with autopickup on.-- * Any result can still be overridden using autopickup_exceptions.---------------------------------------------------------------------------function make_hash(ls)local h = { }for _, i in ipairs(ls) doh[i] = trueendreturn hendfunction you_undead()return you.race() == "Mummy" or you.race() == "Ghoul"end-- not identifiedfunction unknown_potion(type)return type == 0endfunction good_potion(type)return type == 1endfunction bad_potion(it)return type == 2end-- special casesfunction spec_potion(it)return type == 3endfunction ch_autopickup(it)local spells = make_hash( you.spells() )if item.class(it) == "Potions" thenlocal type = item.potion_type(it)-- "bad" potions only for Evaporateif spells["Evaporate"] and bad_potion(type) thenreturn trueend-- no potions for Mummies, also: no bad potions for anyone elseif you.race() == "Mummy" or bad_potion(type) thenreturn falseend-- pickup "good" and unID'd potionsif good_potion(type) or unknown_potion(type) thenreturn trueend-- special handlingif spec_potion(type) then-- undead cannot use berserkif item.subtype(it) == "berserk" thenif you_undead() thenreturn falseelsereturn trueendend-- special cases for water and porridgeif item.subtype(it) == "water" or item.subtype(it) == "porridge" thenreturn food.can_eat(it, false)endend-- anything not handled until here can be picked upreturn trueendif item.class(it) == "Comestibles" thenreturn food.can_eat(it, false)endif item.class(it) == "Books" and you.god() == "Trog" thenreturn falseendif item.class(it) == "Jewellery" thenif item.subtype == "hunger" or item.subtype == "inaccuracy" thenreturn falseendif you_undead() and(item.subtype(it) == "regeneration" or item.subtype(it) == "rage") thenreturn falseendend-- we only get here if class autopickup ONreturn trueend
static int l_item_potion_type(lua_State *ls){LUA_ITEM(item, 1);int val = 99;if (item && item->base_type == OBJ_POTIONS){if (!item_type_known(*item))val = 0;else{switch(item->sub_type){// good potions:case POT_HEALING:case POT_HEAL_WOUNDS:case POT_SPEED:case POT_MIGHT:case POT_GAIN_STRENGTH:case POT_GAIN_DEXTERITY:case POT_GAIN_INTELLIGENCE:case POT_LEVITATION:case POT_INVISIBILITY:case POT_EXPERIENCE:case POT_MAGIC:case POT_RESTORE_ABILITIES:case POT_CURE_MUTATION:val = 1;break;// bad potions:case POT_POISON:case POT_STRONG_POISON:case POT_SLOWING:case POT_PARALYSIS:case POT_CONFUSION:case POT_DEGENERATION:case POT_DECAY:case POT_MUTATION:val = 2;break;// need more refined handling:case POT_BERSERK_RAGE:case POT_WATER:case POT_PORRIDGE:default:val = 3;}}}lua_pushnumber(ls, val);return (1);}