background_colour = white
foreground_colour = black
bold_brightens_foreground = true
char_set = ascii
cset = cloud:xa4
cset = item_orb:0
use_fake_player_cursor = true
always_show_gems = true
more_gem_info = true
macros += M \{tab} ===auto_fight_safe
bindkey = [c] CMD_AUTOFIGHT_NOMOVE
{
-- Config
local HP_CRIT, HP_LOW = 0.3, 0.5
-- State
local last_turn = 0
local last_count = 0
local last_hp = 0
local last_mhp = 0
local cache_enemies = nil
local cache_monsters = nil
local cache_turn = -1
-- Shared direction list (8 directions)
local DIRS_8 =
{{-1,-1,"y"},{0,-1,"k"},{1,-1,"u"},{-1,0,"h"},{1,0,"l"},{-1,1,"b"},{0,1,"j"},{1,1,"n"}}
-- Tactical positioning memory (GLOBAL)
if not tactical_memory then
tactical_memory = {last_enemy_count=0, retreat_count=0}
end
local function count_walls(x, y)
local count = 0
for dx = -1, 1 do
for dy = -1, 1 do
if (dx ~= 0 or dy ~= 0) and not view.is_safe_square(x + dx, y + dy) then
count = count + 1 end
end
end
return count
end
local function is_empty_safe_square(x, y)
if not view.is_safe_square(x, y) then return false end
local m = monster.get_monster_at(x, y)
return not m or m:is_safe()
end
local function is_stuck()
return you.status("spiked") or you.status("petrified") or
you.transform():find("tree")
end
local function is_dangerous_monster(name)
return name:find("Sigmund") or name:find("Grinder") or name:find("priest")
or name:find("wizard") or name:find("hydra") or name:find("lich") or
name:find("fiend") or name:find("dragon")
end
local cache_terrain = nil
function scan_all_enemies()
if cache_enemies and cache_turn == you.turns() then return cache_enemies,
cache_monsters, cache_terrain end
local e = {adj=0, total=0, stab=0, far=0, ranged=false, reach=false,
danger_level=0}
local monsters = {}
local terrain = {best_anchor_x=0, best_anchor_y=0, best_anchor_score=-99}
local r = you.los()
for x = -r, r do
for y = -r, r do
local m = monster.get_monster_at(x, y)
if m and m:attitude() < 1 and not m:is_firewood() then
local d = math.max(math.abs(x), math.abs(y))
local t, name = m:threat(), m:name()
e.total = e.total + 1
if m:stabbability() >= 1 then e.stab = e.stab + 1 end
if d == 1 then e.adj = e.adj + 1 else e.far = e.far + 1 end
local mon_danger = (is_dangerous_monster(name) or t >= 3) and 3 or (t
>= 2) and 2 or 1
if mon_danger > e.danger_level then e.danger_level = mon_danger end
if m:range() >= 3 and not view.withheld(x,y) then e.ranged = true end
if d == 2 and m:reach_range() >= 2 then e.reach = true end
table.insert(monsters, {x=x, y=y, name=name, danger=mon_danger})
end
if math.abs(x) <= 3 and math.abs(y) <= 3 and view.is_safe_square(x, y)
and not m then
local walls = count_walls(x, y)
if walls >= 3 and walls <= 5 then
local score = walls * 10 - math.abs(x) - math.abs(y)
if score > terrain.best_anchor_score then
terrain.best_anchor_x, terrain.best_anchor_y,
terrain.best_anchor_score = x, y, score
end
end
end
end
end
cache_enemies, cache_monsters, cache_terrain = e, monsters, terrain
cache_turn = you.turns()
return e, monsters, terrain
end
-- HP tracking with critical more prompts
local function show_hp()
local hp, mhp = you.hp()
local diff = last_hp - hp
if diff > 0 then
if hp < mhp/2 and last_hp >= last_mhp/2 or hp < mhp/4 and last_hp >=
last_mhp/4 then
crawl.mpr("-" .. diff .. " hp (" .. hp .. "/" .. mhp .. ")
!!!")
crawl.more()
end
end
last_hp, last_mhp = hp, mhp
end
local function show_enemies(e)
if not e or not e.total or e.total == 0 then
if last_count ~= 0 then crawl.mpr("Clear") end
last_count = 0
return
end
local new = e.total - last_count
if new > 0 then crawl.mpr(new == 1 and "Monster" or "Monsters x" .. new) end
local deadly, dangerous = {}, {}
if cache_monsters then
for _, mon in ipairs(cache_monsters) do
if mon.danger and mon.danger >= 3 then table.insert(deadly, mon.name)
elseif mon.danger and mon.danger >= 2 then table.insert(dangerous,
mon.name) end
end
end
local dl = e.danger_level or 0
local total = e.total or 0
local c = (dl >= 3 or total >= 5) and "lightred" or (dl >= 2 or total >= 3)
and "yellow" or "white"
local m = total .. " mon" .. (total > 1 and "s" or "")
if #deadly > 0 then
m = m .. " - " .. deadly[1]
if #deadly > 1 then m = m .. " +" .. (#deadly - 1) end
if #dangerous > 0 then m = m .. " (+" .. #dangerous .. " dangerous)" end
elseif #dangerous > 0 then
m = m .. " - " .. dangerous[1]
if #dangerous > 1 then m = m .. " +" .. (#dangerous - 1) end
end
crawl.mpr("<" .. c .. ">" .. m .. "" .. c .. ">")
if new >= 3 then crawl.more() end
last_count = e.total
end
local function using_ranged_weapon()
local weapon = items.equipped_at("Weapon")
if not weapon then return false end
local name = weapon.name()
return name:find("bow") or name:find("crossbow") or name:find("sling") or name:find("javelin") or name:find("throwing")
end
local function check_danger_warnings(hp_pct, e)
if hp_pct < HP_CRIT then crawl.mpr("DANGER: Critical
HP")
elseif hp_pct < HP_LOW and e.danger_level >= 2 then
crawl.mpr("WARNING: Low HP") end
if e.adj >= 5 then crawl.mpr("DANGER: Surrounded") end
end
function auto_fight_safe()
if you.feel_safe() then
crawl.sendkeys("so")
return
end
local hp, mhp = you.hp()
local hp_pct = hp / mhp
local e, monsters = scan_all_enemies()
if e.total > 0 then check_danger_warnings(hp_pct, e) end
-- Depth warning (simplified)
local where = you.where()
if e.danger_level >= 2 and (where:find("Depths") or where:find("Vaults"))
then
crawl.mpr("WARNING: Dangerous depth")
end
-- Tactical positioning: find cover before combat
if e.total > 0 and e.adj == 0 and not e.reach and hp_pct >= 0.7 then
local should_reposition = (e.ranged and e.far > 0) or e.stab == 0
if should_reposition and not is_stuck() and tactical_memory.retreat_count
< 2 then
local move = find_cover_position()
if move then
tactical_memory.retreat_count = tactical_memory.retreat_count + 1
crawl.sendkeys(move)
return
end
end
end
-- Emergency consumables (Suggestions only)
if hp_pct < HP_CRIT then
if you.confused() or (you.poisoned() and you.poison_survival() < hp) then
crawl.mpr("SUGGESTION: Use Curing!")
end
crawl.mpr("SUGGESTION: Use Heal Wounds!")
end
if hp_pct < 0.2 and e.adj >= 6 and e.danger_level >= 3 then
crawl.mpr("SUGGESTION: BLINK!")
end
-- Ranged weapon retreat
local has_ranged = using_ranged_weapon()
if has_ranged and e.total > 0 and e.adj == 0 and e.stab == 0 and not
is_stuck() then
if e.far > 0 and tactical_memory.retreat_count < 4 then
local move = find_simple_retreat(monsters)
if move then
tactical_memory.retreat_count = tactical_memory.retreat_count + 1
crawl.sendkeys(move)
return
end
end
end
-- Fast path: low threat (No multi-tab)
if e.danger_level <= 1 and e.total <= 3 and hp_pct > 0.6 then
if e.stab > 0 then
crawl.setopt("autofight_wait = false")
crawl.sendkeys(9)
return
end
if e.ranged or e.reach then crawl.setopt("autofight_wait = false")
crawl.sendkeys(9) return end
local should_wait = e.adj == 0 and e.far > 0
if should_wait or is_stuck() then
crawl.setopt("autofight_wait = true")
crawl.sendkeys("c")
else
crawl.setopt("autofight_wait = false")
crawl.sendkeys(9)
end
return
end
-- High threat consumables (Suggestions only)
if e.danger_level >= 3 and hp_pct < HP_LOW then
crawl.mpr("SUGGESTION: Use Haste!")
end
if e.danger_level >= 2 and hp_pct < 0.6 and (e.adj >= 3 or e.total >= 4) then
crawl.mpr("SUGGESTION: Use Might!")
end
if e.stab > 0 then
crawl.setopt("autofight_wait = false")
crawl.sendkeys(9)
return
end
if e.ranged or e.reach or e.adj >= 1 then
crawl.setopt("autofight_wait = false")
crawl.sendkeys(9)
else
crawl.setopt("autofight_wait = true")
crawl.sendkeys("c")
end
end
function find_cover_position()
local best_dir, best_score = nil, 0
for _, d in ipairs(DIRS_8) do
local dx, dy, key = d[1], d[2], d[3]
if is_empty_safe_square(dx, dy) then
local wall_count = count_walls(dx, dy)
local score = (wall_count >= 3 and wall_count <= 5) and wall_count * 10
or (wall_count == 2 and 5 or 0)
if score > best_score then
best_score = score
best_dir = key
end
end
end
if best_score >= 30 then return best_dir end
-- Check 2-step positions (only if no good 1-step found)
local dirs2 =
{{-2,-2},{-1,-2},{0,-2},{1,-2},{2,-2},{-2,-1},{2,-1},{-2,0},{2,0},{-2,1},{2,1},{-2,2},{-1,2},{0,2},{1,2},{2,2}}
for _, d in ipairs(dirs2) do
local dx, dy = d[1], d[2]
if is_empty_safe_square(dx, dy) then
local wall_count = count_walls(dx, dy)
if wall_count >= 4 and wall_count <= 5 then
travel.set_waypoint(1, dx, dy)
return "G1"
end
end
end
return nil
end
function find_simple_retreat(monsters)
if not monsters or #monsters == 0 then return nil end
local closest_dist, closest_x, closest_y = 999, 0, 0
for _, mon in ipairs(monsters) do
local d = math.max(math.abs(mon.x), math.abs(mon.y))
if d < closest_dist then
closest_dist, closest_x, closest_y = d, mon.x, mon.y
end
end
if closest_dist > 3 then return nil end
-- Try to move in opposite direction from closest enemy
local best_dir, best_dist = nil, closest_dist
for _, d in ipairs(DIRS_8) do
local dx, dy, key = d[1], d[2], d[3]
if is_empty_safe_square(dx, dy) then
local new_dist = math.max(math.abs(closest_x - dx), math.abs(closest_y -
dy))
-- Check we're not moving adjacent to any other enemy
local safe = true
for _, mon in ipairs(monsters) do
if math.max(math.abs(mon.x - dx), math.abs(mon.y - dy)) == 1 then
safe = false
break
end
end
if safe and new_dist > best_dist then
best_dist, best_dir = new_dist, key
end
end
end
return best_dir
end
function ready()
if you.time() > last_turn then
last_turn = you.time()
cache_enemies = nil
cache_monsters = nil
cache_terrain = nil
cache_turn = -1
show_hp()
if not you.feel_safe() then
local e = scan_all_enemies()
if tactical_memory.last_enemy_count == 0 and e.total > 0 then
tactical_memory.retreat_count = 0
end
-- Show enemies after retreat check
show_enemies(e)
tactical_memory.last_enemy_count = e.total
else
-- Safe: reset enemy count for next first contact detection
tactical_memory.last_enemy_count = 0
end
end
end
}
##### Crawl Init file ###############################################
# For descriptions of all options, as well as some more in-depth information
# on setting them, consult the file
# options_guide.txt
# in your /docs directory. If you can't find it, the file is also available
# online at:
# https://github.com/crawl/crawl/blob/master/crawl-ref/docs/options_guide.txt
#
# Crawl uses the first file of the following list as its option file:
# * init.txt in the -rcdir directory (if specified)
# * .crawlrc in the -rcdir directory (if specified)
# * init.txt (in the Crawl directory)
# * ~/.crawl/init.txt (Unix only)
# * ~/.crawlrc (Unix only)
# * ~/init.txt (Unix only)
# * settings/init.txt (in the Crawl directory)
##### Some basic explanation of option syntax #######################
# Lines beginning with '#' are comments. The basic syntax is:
#
# field = value or field.subfield = value
#
# Only one specification is allowed per line.
#
# The terms are typically case-insensitive except in the fairly obvious
# cases (the character's name and specifying files or directories when
# on a system that has case-sensitive filenames).
#
# White space is stripped from the beginning and end of the line, as
# well as immediately before and after the '='. If the option allows
# multiple comma/semicolon-separated terms (such as
# autopickup_exceptions), all whitespace around the separator is also
# trimmed. All other whitespace is left intact.
#
# There are three broad types of Crawl options: true/false values (booleans),
# arbitrary values, and lists of values. The first two types use only the
# simple =, with later options - which includes your options that are different
# from the defaults - overriding earlier ones. List options allow using +=, ^=,
# -=, and = to append, prepend, remove, and reset, respectively. Usually you will
# want to use += to add to a list option. Lastly, there is := which you can use
# to create an alias, like so:
# ae := autopickup_exceptions
# From there on, 'ae' will be treated as if it you typed autopickup_exceptions,
# so you can save time typing it.
#
##### Other files ###################################################
# You can include other files from your options file using the 'include'
# option. Crawl will treat it as if you copied the whole text of that file
# into your options file in that spot. You can uncomment some of the following
# lines by removing the beginning '#' to include some of the other files in
# this folder.
# Some useful, more advanced options, implemented in LUA.
# include = advanced_optioneering.txt
# Alternative vi bindings for Dvorak users.
# include = dvorak_command_keys.txt
# Alternative vi bindings for Colemak users.
# include = colemak_command_keys.txt
# Alternative vi bindings for Neo users.
# include = neo_command_keys.txt
# Override the vi movement keys with a non-command.
# include = no_vi_command_keys.txt
# Turn the shift-vi keys into safe move, instead of run.
# include = safe_move_shift.txt