summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/dat/lua/pickup.lua
blob: 254d17994bca1010dd25189ee3d8359364b39bbd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
------------------------------------------------------------
-- 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) do
        h[i] = true
    end
    return h
end

-- don't count Vampires here because of all those exceptions
function you_real_undead()
    return you.race() == "Mummy" or you.race() == "Ghoul" 
end

-- not identified
function unknown_potion(type)
    return type == 0
end

function good_potion(type)
    return type == 1
end

function bad_potion(type)
    return type == 2
end

-- special cases
function spec_potion(type)
    return type == 3
end

function ch_autopickup(it)
    local spells = make_hash( you.spells() )

    if item.class(it) == "Potions" then

        local type = item.potion_type(it)

        -- "bad" potions only for Evaporate
        if spells["Evaporate"] and bad_potion(type) then
           return true
        end

        -- no potions for Mummies
        -- also: no bad potions for anyone else
        if you.race() == "Mummy" or bad_potion(type) then
           return false
        end

        -- pickup "good" and unID'd potions
        if good_potion(type) or unknown_potion(type) then
           return true
        end

        -- special handling
        if spec_potion(type) then

           -- real undead cannot use berserk
           -- or anything involving mutations
           if item.subtype(it) == "berserk" 
                or item.subtype(it) == "gain ability"
                or item.subtype(it) == "cure mutation" 
                or item.subtype(it) == "mutation" then
              if you_real_undead() then
                 return false
              else 
                 return true
              end
           end

           -- special cases for blood, water, and porridge
           if item.subtype(it) == "blood" 
                or item.subtype(it) == "water" 
                or item.subtype(it) == "porridge" then
              return food.can_eat(it, false)
           end
        end

        -- anything not handled until here can be picked up
        return true
    end

    if item.class(it) == "Carrion" 
         or item.class(it) == "Comestibles" then
       return food.can_eat(it, false)
    end

    if item.class(it) == "Books" and item.subtype(it) == "spellbook" 
         and you.god() == "Trog" then
       return false
    end

    if item.class(it) == "Jewellery" then
       if item.subtype(it) == "hunger" 
            or item.subtype(it) == "inaccuracy" then
          return false
       end 
       if you_real_undead() and
            (item.subtype(it) == "regeneration" 
               or item.subtype(it) == "rage" 
               or item.subtype(it) == "sustenance"
                  and you.race() == "Mummy") then
          return false
       end 
    end

    -- we only get here if class autopickup ON
    return true
end