This file is indexed.

/usr/share/crawl/dat/clua/delays.lua is in crawl-common 2:0.19.3-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
---------------------------------------------------------------------------
-- delays.lua:
-- Controls delayed actions' stop conditions.
--
-- What it does:
--
--  * Any message in runrest_ignore_message will *not* stop your run.
--  * Poison damage will be ignored if it is less than x% of your current
--    hp and y% of your max hp if you have defined delay_safe_poison = x:y
--  * Any monster in runrest_ignore_monster will *not* stop your run
--    if it's at least the specified distance away.
--    You can specify this with runrest_ignore_monster = regex:distance.
---------------------------------------------------------------------------

chk_interrupt_activities = function (iname, cause, extra)
    if not delay_check_params() then
        return false
    end

    if iname == 'hp_loss' then
        return delay_handle_hploss(cause, extra)
    end

    return false
end

g_rr_ignored = { }

chk_interrupt_activity.run = function (iname, cause, extra)
    if iname == 'message' then
        return rr_handle_message(cause, extra)
    end

    return false
end

-- run no longer automatically implies rest as of 0.1.3.
chk_interrupt_activity.rest = chk_interrupt_activity.run
chk_interrupt_activity.travel = chk_interrupt_activity.run

function rr_handle_message(cause, extra)
    local ch, mess = rr_split_channel(cause)
    for _, x in ipairs(g_rr_ignored) do
        if x.filter:matches(mess, ch) then
            return x.value
        end
    end
    return false
end

function rr_split_channel(s)
    local chi = string.find(s, ':')
    local channel = -1
    if chi and chi > 1 then
        local chstr = string.sub(s, 1, chi - 1)
        channel = crawl.msgch_num(chstr)
    end

    local sor = s
    if chi then
        s = string.sub(s, chi + 1, -1)
    end

    return channel, s
end

function delay_handle_hploss(hplost, source)
    -- source == 1 for poisoning
    if not g_delay_pois_curhp_ratio or not g_delay_pois_maxhp_ratio or source ~= 1 then
        return false
    end

    -- If the the poison in your system is less than the given percentages
    -- of both current and maximum hp, ignore
    local hp, mhp = you.hp()
    local poison_damage_prediction = hp - you.poison_survival()
    if (poison_damage_prediction * 100 / hp) <= g_delay_pois_curhp_ratio
       and (poison_damage_prediction * 100 / mhp) <= g_delay_pois_maxhp_ratio then
        return nil
    end

    return false
end

function delay_check_params()
    if (not g_delay_pois_maxhp_ratio or not g_delay_pois_curhp_ratio)
            and (options.delay_safe_poison or options.runrest_safe_poison)
    then
        local opt = options.delay_safe_poison or options.runrest_safe_poison
        local cur_r, max_r
        _, _, cur_r, max_r = string.find(opt, "(%d+)%s*:%s*(%d+)")
        if cur_r and max_r then
            g_delay_pois_curhp_ratio = tonumber(cur_r)
            g_delay_pois_maxhp_ratio = tonumber(max_r)
        end
    end
    return true
end

function rr_add_message(s, v, mode)
    local channel, str = rr_split_channel(s)
    local filter = crawl.message_filter(str, channel)
    if mode < 0 then
        for k, p in pairs (g_rr_ignored) do
            if p.filter:equals(filter) and p.value == v then
                table.remove(g_rr_ignored, k)
                return
            end
        end
    else
        local entry = { filter = filter, value = v }
        local position = table.getn(g_rr_ignored) + 1
        if mode > 1 then
            position = 1
        end
        table.insert(g_rr_ignored, position, entry)
    end
end

function rr_message_adder(v)
    local function rr_add_messages(key, value, mode)
        if mode == 0 then
            -- Clear list
            for k in pairs (g_rr_ignored) do
                g_rr_ignored[k] = nil
            end
            if value == "" then
                return
            end
        end

        local segs = crawl.split(value, ',', mode > 1)
        for _, s in ipairs(segs) do
            rr_add_message(s, v, mode)
        end
    end
    return rr_add_messages
end

chk_lua_option.runrest_ignore_message = rr_message_adder(nil)
chk_lua_option.runrest_stop_message = rr_message_adder(true)
-- alias for compatibility with obsolete travel_stop_message
chk_lua_option.travel_stop_message = rr_message_adder(true)
-----------------------------------------------------------------------

g_rr_monsters        = { {}, {} }
g_rr_monsters_moving = { {}, {} }

function rr_add_monster(mons_table, s, mode)
    local parts = crawl.split(s, ":")

    if #parts ~= 2 then
        return
    end

    local re_str = parts[1]
    local regexp = crawl.regex(re_str)
    local dist   = tonumber(parts[2])

    if dist == 0 then
        return
    end

    if mode < 0 then
        for k, r in pairs(mons_table[1]) do
            if r:equals(regexp) and mons_table[2][k] == dist then
                table.remove(mons_table[1], k)
                table.remove(mons_table[2], k)
                return
            end
        end
    else
        local position = table.getn(mons_table[1]) + 1
        if mode > 1 then
            position = 1
        end
        table.insert(mons_table[1], position, regexp)
        table.insert(mons_table[2], position, dist)
    end
end

function rr_add_monsters(key, value, mode)
    local mons_table

    if (key == "runrest_ignore_monster") then
        mons_table = g_rr_monsters
    elseif (key == "runrest_ignore_monster_moving") then
        mons_table = g_rr_monsters_moving
    else
        return
    end

    if mode == 0 then
        -- Clear list
        for k in pairs (mons_table[1]) do
            mons_table[1][k] = nil
            mons_table[2][k] = nil
        end
        if value == "" then
            return
        end
    end

    local segs = crawl.split(value, ',', mode > 1)
    for _, s in ipairs(segs) do
        rr_add_monster(mons_table, s, mode)
    end
end

function ch_mon_is_safe(mon, default_is_safe, moving, dist)
    if default_is_safe then
        return true
    end

    local mons_table

    -- If player is moving and the monster is in g_rr_monsters_moving,
    -- then we do the distance comparison without decreasing the
    -- distance value.
    if moving then
        mons_table  = g_rr_monsters_moving

        for i = 1, #mons_table[1] do
            local m        = mons_table[1][i]
            local min_dist = mons_table[2][i]

            if m:matches(mon:desc()) then
                return min_dist <= dist
            end
        end
    end

    mons_table = g_rr_monsters

    -- Reduce distance by 1 if moving, since the safety check is
    -- done *before* moving closer to the monster
    if moving then
        dist = dist - 1
    end

    for i = 1, #mons_table[1] do
        local m        = mons_table[1][i]
        local min_dist = mons_table[2][i]

        if m:matches(mon:desc()) then
            return min_dist <= dist
        end
    end

    return false
end

chk_lua_option.runrest_ignore_monster            = rr_add_monsters
chk_lua_option.runrest_ignore_monster_moving     = rr_add_monsters