----------------------------------------------------------------------------------------------webtiles
--WIP rc file, no promises
--more uptodate at underhound
VERSION=tonumber(crawl.version("major"))
function utf8char(unicode)
    -- mostly cited from https://github.com/Stepets/utf8.lua/blob/master/utf8.lua
	if unicode <= 0x7F then return string.char(unicode) end
	if (unicode <= 0x7FF) then
		local Byte0 = 0xC0 + math.floor(unicode / 0x40);
		local Byte1 = 0x80 + (unicode % 0x40);
		return string.char(Byte0, Byte1);
	end;
	if (unicode <= 0xFFFF) then
		local Byte0 = 0xE0 +  math.floor(unicode / 0x1000);
		local Byte1 = 0x80 + (math.floor(unicode / 0x40) % 0x40);
		local Byte2 = 0x80 + (unicode % 0x40);
		return string.char(Byte0, Byte1, Byte2);
	end;
	if (unicode <= 0x10FFFF) then
		local code = unicode
		local Byte3= 0x80 + (code % 0x40);
		code       = math.floor(code / 0x40)
		local Byte2= 0x80 + (code % 0x40);
		code       = math.floor(code / 0x40)
		local Byte1= 0x80 + (code % 0x40);
		code       = math.floor(code / 0x40)
		local Byte0= 0xF0 + code;
		return string.char(Byte0, Byte1, Byte2, Byte3);
	end;
	error 'Unicode cannot be greater than U+10FFFF!'
end
--echoall(crawl.getch())
--crawl.more()
local dummy_keys_made=0
function get_command(cmd,nodummy,bindkey)
	--returns key combo of cmd, ready to be plugged into sendkeys
	 --makes dummy keys from U+10FFFF downward if it can't get the keycode, or that keycode can't be send with sendkeys
	 --because sendkeys is less buggy than do_commands
	
	--use bindkey to plug  into bindkey instead
	
	local ok=true
	
	local result=crawl.get_command(cmd)
	
	result=result:gsub("Space",' ') 
	--theoretical To-Do: Reverse all special cases of keycode_to_name in https://github.com/crawl/crawl/blob/master/crawl-ref/source/macro.cc
	--just add special cases in that line above as needed. Or accept adding dummy keys!
	
	local modifier=""..(result:match("Ctrl.") and (bindkey and "^" or "\*") or "")..(result:match("Shift.") and "\/" or "")
	if modifier=="\*\/" or modifier:match("\/") and bindkey then ok=false else
		result=result:gsub("Ctrl.",""):gsub(".ppercase.",""):gsub("Shift.","")
		--if result=="0" then
			----crawl.setopt("bindkey [
			--error 'error in rc function get_command, no bound key'
		--end
		--if result:match("Numpad") then result=result:gsub("Numpad ","100") end
		if not(result==result:match("[%w%s%p]"))
			and not pcall(function()
				if #result==1 then 
					--pcall(function() result=utf8char(string.byte(result)) end)
					result=utf8char(string.byte(result))
				elseif result:match("%d") and not(result:match("F")) and not(result:match("%-")) then
					result=utf8char(tonumber(result:match("%d+")))
				else--if bindkey and result==result:match("F%d+") then --TD check if works
					ok=false
				end
			end)
		then ok=false end
	
	end
	
	if not ok then --make a dummy key instead
		if nodummy then
			error 'get_command can not get command.'
		else
			local number=1114111-dummy_keys_made
			dummy_keys_made=dummy_keys_made+1
			crawl.setopt("bindkey=[\\{"..tostring(number).."}] "..cmd)
			return utf8char(number)
		end
	else
		return modifier..result
	end
	
end
----------------------------------------------------------------------------------------------------------------
local r_td={}
 --table of functions to call in ready()
 --table.insert(r_td,functionname) to run functionname() once in ready
 --r_td[functionname]=1 to run only once at most, if the order doesn't matter
 --functionname may add itself to r_td to be run next time again
 --r_td is empty by the time the functions are running
function r_run_r_td()
	if next(r_td) then
		local td={}
		for k in pairs(r_td) do
			td[k]=r_td[k]
			r_td[k]=nil
		end
		for k in pairs(td) do
			if td[k]==1 then
				k()
			else
				td[k]()
			end
			td[k]=nil
		end
	end
end
----------------------------------------------------------------------------------------------------------------
local r_funcs={}
function r_run_r_funcs()
	for k in pairs(r_funcs) do
		r_funcs[k]()
	end
end----------------------------------------------------------------------------------------------------------------
local cmsg_funcs={}
function cmsg_run_cmsg_funcs(msg, ch)
	for k in pairs(cmsg_funcs) do
		cmsg_funcs[k](msg, ch)
	end
end
----------------------------------------------------------------------------------------------------------------
local move_careful = false --mostly you.feel_safe, true if manual exploring is expected and enforced to be "careful" with --more--
local reset_more_message_options = false
--initialised by c_persist
local autopickup_is_on = true --the last known state of options.autopick_on
local td_start_deactivate_autopickup=true
local auto_wmm=true
local wmm_on = false
local monster_warning = false
local dma_table={}
function r_meta_move_careful()
	--the only function actually called in ready(), to see the order here
	--old functions
	--r_tell_time()
	--r_autopickup_is_on()
	--echoall("mmc")--
	r_warnings()
	r_is_autopickup_on()
	r_chk_vis_invis()
	r_move_careful()
	r_warn_more_monsters()
	r_monster_warning()
	--r_reset_cmsg_sending()
	
	
end
function toggle_move_careful_on()
	if auto_wmm and wmm_on then toggle_warn_more_monsters(true) end
	move_careful = true
	--crawl.setopt("force_more_message -= into view")
	--crawl.setopt("force_more_message += You are feeling hungry")
	
	crawl.setopt("bindkey = [j] CMD_SAFE_MOVE_LEFT")
	crawl.setopt("bindkey = [,] CMD_SAFE_MOVE_DOWN")
	crawl.setopt("bindkey = [i] CMD_SAFE_MOVE_UP")
	crawl.setopt("bindkey = [l] CMD_SAFE_MOVE_RIGHT")
	crawl.setopt("bindkey = [u] CMD_SAFE_MOVE_UP_LEFT")
	crawl.setopt("bindkey = [o] CMD_SAFE_MOVE_UP_RIGHT")
	crawl.setopt("bindkey = [m] CMD_SAFE_MOVE_DOWN_LEFT")
	crawl.setopt("bindkey = [.] CMD_SAFE_MOVE_DOWN_RIGHT")
	
	
	for k in pairs(dma_table) do
		dma_table[k]=nil
	end
	crawl.mpr("No danger in sight...")
end
function toggle_move_careful_off()
	crawl.flush_input()
	you.stop_activity()
	--if not(wmm_on) then crawl.more() end
	if not(monster_warning) then
		monster_warning = true
		crawl.mpr("!")
		crawl.more()
	end
	--if auto_wmm and wmm_on==false then toggle_warn_more_monsters(true) end --already done in next line
	toggle_move_careful_off_noprompt()
end
function toggle_move_careful_off_noprompt()
	crawl.flush_input()
	you.stop_activity()
	if auto_wmm and wmm_on==false then toggle_warn_more_monsters(true) end
	move_careful = false
	--reset_more_message_options = true
	
	crawl.setopt("bindkey = [j] CMD_MOVE_LEFT")
	crawl.setopt("bindkey = [,] CMD_MOVE_DOWN")
	crawl.setopt("bindkey = [i] CMD_MOVE_UP")
	crawl.setopt("bindkey = [l] CMD_MOVE_RIGHT")
	crawl.setopt("bindkey = [u] CMD_MOVE_UP_LEFT")
	crawl.setopt("bindkey = [o] CMD_MOVE_UP_RIGHT")
	crawl.setopt("bindkey = [m] CMD_MOVE_DOWN_LEFT")
	crawl.setopt("bindkey = [.] CMD_MOVE_DOWN_RIGHT")
	
	
	for k in pairs(dma_table) do
		dma_table[k]=nil
	end
end
function r_move_careful()
	--force more if danger starts
	--move careful, aka explore manually. Also used to decide whether it is safe to equip things
	if move_careful then
		if (not(you.feel_safe()) or you.silenced()) then
			toggle_move_careful_off() --this also sends a --more--
		else
			if not(autopickup_is_on) then
				toggle_move_careful_off()
			end
		end
	else
		if (you.feel_safe() and not(you.silenced())) then
		if autopickup_is_on then
			toggle_move_careful_on()
		else
			crawl.mpr("AP is off.",4)
		end
		end
	end
	
	--
	--if not(move_careful) and reset_more_message_options then --reset to default: Here used when there is danger
		--reset_more_message_options = false
		--if not(auto_wmm) then crawl.setopt("force_more_message += into view") end
		--crawl.setopt("force_more_message -= You are feeling hungry")
	--end
end
local td_deactivate_autopickup=0
function r_chk_vis_invis()
	--react to "indirectly" visible invisible monster
	if autopickup_is_on then --TD: only check if you sInv
		local detected=false
		local LOS=you.los()
		for x = -LOS,LOS do
			for y = -LOS,LOS do
				if view.invisible_monster(x,y) and view.cell_see_cell(0,0,x,y) then
				
					crawl.mpr("There is something invisible around!")
					deactivate_autopickup()
					
					detected=true; break
				end
			end
			if detected then break end
		end
	end
end
-------------------------------------------------------------------------------------------------------------
function deactivate_autopickup()
	crawl.mpr("lua detected that AP should be OFF:") 
	--crawl.do_commands({"CMD_TOGGLE_AUTOPICKUP"}) 
	crawl.sendkeys( get_command("CMD_TOGGLE_AUTOPICKUP") )
	
	td_deactivate_autopickup=0
	
	if autopickup_is_on then autopickup_turns_off() end
end
function r_is_autopickup_on()
	if not(options.autopick_on==autopickup_is_on) then
		if autopickup_is_on then
			autopickup_turns_off()
		else
			autopickup_turns_on()
		end
	end
	
	if td_deactivate_autopickup>1 then
		td_deactivate_autopickup=td_deactivate_autopickup-1
	else
	if td_deactivate_autopickup==1 then
		if autopickup_is_on then
			deactivate_autopickup()
			if not(move_careful) then
				crawl.mpr("There is something invisible around!!")
				crawl.more()
			end
		end
		td_deactivate_autopickup=0
	end end
end
local cmsg_sending = false
function cmsg_is_autopickup_on(msg) --goes in c_message(msg, ch)
	
	--if not(msg:match("%-%-%-")) then crawl.mpr("---"..msg) end
	
	
	if
		msg:match(".omething.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.? misses you%p") or
		msg:match(".omething enters a") or
		msg:match(".omething sets off the alarm") or
		msg:match(".omething launches a net") or
		msg:match("web moves frantically as something is caught in it") or
		msg:match("ou feel you are being watched by something")
	then
		if autopickup_is_on then
			--deactivate_autopickup() --cmsg shouldn't send commands if you can avoid it, let ready() handle it
			td_deactivate_autopickup=1
			--if not(move_careful) then
				--crawl.mpr("There is something invisible around!!")
				--crawl.more()
			--end
		end
	end
end
--function r_reset_cmsg_sending()
 --cmsg pauses and calls itself if it sends a message
 --always check cmsg_sending and set cmsg_sending=true before sending something in cmsg
 --actually, because it pauses you can just reset it immediately
 --unused, this can be deleted
	--cmsg_sending = false
--end
local wmm_noap_on = false
function autopickup_turns_off()--called in cmsg, stay silent
	autopickup_is_on=false
	
	if wmm_on==false then
		toggle_warn_more_monsters(true)
	else
		toggle_warn_more_monsters(true)
		toggle_warn_more_monsters(true)
	end
	
	--crawl.setopt("force_more_message -= into view")
end
function autopickup_turns_on()--called in cmsg, stay silent
	autopickup_is_on=true
	if not(auto_wmm) and wmm_on then toggle_warn_more_monsters(true) end
	--if not(move_careful) and not(auto_wmm) then crawl.setopt("force_more_message += into view") end
end
-------------------------------------------------------------------------------------------------------------
  
local wmm_just_on = false
local wmm_count = 0
local wmm_list = {}
local r_wmm_list = {}
function toggle_warn_more_monsters(silent) --silent means called by ap turning off, or auto_wmm. state of silent is noted in wmm_noap_on, but that is unused otherwise.
--must be silent if called from cmsg!
	if wmm_on then
		wmm_on = false
		for n, k in pairs(wmm_list) do
			wmm_list[n] = nil
		end
		if not(silent) then crawl.mpr("warn_more_monsters off") end
		wmm_noap_on=false
	else
		wmm_on = true
		wmm_just_on = true
		if not(silent) then
			crawl.mpr("warn_more_monsters on")
		else
			wmm_noap_on=true
		end
	end
end
crawl.setopt("runrest_ignore_monster ^= fire vortex:2")
crawl.setopt("runrest_ignore_monster ^= spatial vortex:2")
local wmm_options="of distortion, carrying a wand of"
if VERSION<.28 then	
	crawl.setopt("flash_screen_message +=".." is wielding.*distortion, there is a.*distortion, of distortion comes into view, carrying a wand of")
end
function r_warn_more_monsters()
		--crawl.mpr("ready"..tostring(wmm_on)..tostring(wmm_noap_on))
	if wmm_on then
		local w_monster = nil
		local new_monsters = ""
		local element
		
		local LOS=you.los()
		for x = -LOS,LOS do
			for y = -LOS,LOS do
				local w_monster_obj = monster.get_monster_at(x, y)
				if
					not(  w_monster_obj==nil )
					and not(  ( w_monster_obj:is_safe()
						--and w_monster_obj:is_stationary() )  )
						) )
					and not(w_monster_obj:attitude()>1)
					and not(w_monster_obj:status():match("summoned"))
					--and not(w_monster_obj:name():match("fire vortex"))
					--and not(w_monster_obj:name():match("spatial vortex"))
					and view.cell_see_cell(0,0,x,y)
				then
					w_monster = w_monster_obj:name()
					wmm_count = 1
					while is_in_wlist(w_monster,wmm_count,r_wmm_list) do
						wmm_count = wmm_count + 1
						--crawl.mpr(tostring(wmm_count))
					end
					r_wmm_list[w_monster] = wmm_count
					--crawl.mpr(w_monster.."w"..tostring(wmm_count))
					
					if not(is_in_wlist(w_monster,wmm_count,wmm_list)) then
						wmm_list[w_monster] = wmm_count
						--crawl.mpr(w_monster.." "..tostring(wmm_count))
						--new_monsters = true
						if not(new_monsters=="") then new_monsters = new_monsters..", " end
						if VERSION>.27 then
							new_monsters = new_monsters..w_monster_obj:target_desc().." "..tostring(wmm_count)
						else
							new_monsters = new_monsters..w_monster.." "..tostring(wmm_count)
						end
					end
				end
			end
		end
		if not(new_monsters=="") and (VERSION>.27 or not(wmm_just_on)) then
			if VERSION>.27 then	crawl.setopt("flash_screen_message +="..wmm_options) end
			crawl.mpr(new_monsters)
			if VERSION>.27 then	crawl.setopt("flash_screen_message -="..wmm_options) end
			if not(monster_warning) and not(wmm_just_on) then
				monster_warning = true
				crawl.more()
			end
		end
		wmm_just_on = false
		for n, k in pairs(r_wmm_list) do
			r_wmm_list[n] = nil
		end
	end
end
function is_in_wlist(name,id,wlist)
	if not(wlist[name]==nil) and wlist[name]>=id then
		return true
	else
		return false
	end
end
------------------------------------------------------------------------------------------------------------
function start_deactivate_autopickup()
	
	if c_persist.ap==nil then
		c_persist.ap={}
	end
	if c_persist.ap[you.name()]==nil then
		c_persist.ap[you.name()]=true
	end
	--autopickup_is_on = c_persist.ap[you.name()]
	td_start_deactivate_autopickup=not(c_persist.ap[you.name()])
	c_persist.ap[you.name()]=nil
	--if csave_is_autopickup_off then autopickup_is_on=false td_start_deactivate_autopickup=true end
	--if not(autopickup_is_on) then autopickup_turns_off() end
	if td_start_deactivate_autopickup then
		if not(you.turns()==0) then
			crawl.mpr("Autopickup was off when saving.")
			deactivate_autopickup()
		end
		--if not(autopickup_is_on) then td_start_deactivate_autopickup=false end
	end
end
function csave_is_autopickup_on()
	c_persist.ap[you.name()]=autopickup_is_on
end
-------------------------------------------------------------------------------------------------------------
function monster_warning_td()
	if not(monster_warning) then
		monster_warning = "td"
	elseif monster_warning=="skip" then
		monster_warning = "skipchk"
	end
end
--crawl.setopt("message_color += yellow:out of view")
local last_msg, last_ch = "", ""
function cmsg_warnings(msg, ch)
--if not(msg:match("%-%-%-")) then
	--crawl.mpr("---"..msg.."-"..last_msg)
	
	--if last_ch=="monster_warning" and not(msg:match("out of view")) then
		--if false and monster_warning=="skip" then
			--monster_warning = "skipchk"
		--else
			--monster_warning=true
			--crawl.more()
		--end
	--elseif
	if last_msg:match("ou are slowing down") and you.status("petrifying") then
		if not(cmsg_sending) then
			cmsg_sending = true
			
			--crawl.mpr("You are petrifying soon!")
			while not(crawl.yesno("-- Do you realize you are petrifying? --",true,"n",true)) do end
			crawl.mpr("...",2)
			
			cmsg_sending = false
		end
		
	elseif last_msg:match("ou feel yourself slow down") then
		if not(cmsg_sending) then
			cmsg_sending = true
			
			if you.slowed() then
				while not(crawl.yesno("-- Do you realize you are slowed? --",true,"n",true)) do end
			else
				while not(crawl.yesno("-- Do you realize your haste has expired? --",true,"n",true)) do end
			end
			crawl.mpr("...",2)
			
			cmsg_sending = false
		end
	
	--elseif last_msg:match("flickers and vanishes") and not(autopickup_is_on) then
		--crawl.more()
		
	elseif last_msg:match("finished your manual") then
		if not(cmsg_sending) then
			cmsg_sending = true
			
			while not(crawl.yesno("-- press y --",true,"n",true)) do end
			crawl.mpr("...",2)
			
			cmsg_sending = false
		end
	end
		
	--alternative to the last_ch handling, sometimes one less more, but sometimes slower at interrupting input, doesnt catch all out of view with the more
	if
		ch=="monster_warning"
	then
		mark_positions()
		monster_warning_td()
	end
	
	--if msg:match("out of view") and not(msg:match("ortex")) then
		--if not(cmsg_sending)then
			--cmsg_sending=true
			
			----crawl.mpr(msg:gsub("moves out of view.","is about to move out of view!"):gsub("lightgrey","yellow"),2)
			--crawl.mpr(msg:gsub("moves out of view.","is about to move out of view!"):gsub("%a+>","yellow>"),2)
			--monster_warning=true
			--crawl.more()
			
			--cmsg_sending = false
		--end
	--end
	
	last_msg, last_ch = msg, ch
--end
end
local deltable={}
if VERSION>=.28 then deltable=nil end
function mark_positions()
local LOS=you.los()
	for x = -LOS,LOS do
		for y = -LOS,LOS do
			if
				not(  monster.get_monster_at(x, y)==nil )
				and not(  ( monster.get_monster_at(x, y):is_safe()
					and monster.get_monster_at(x, y):is_stationary() )  )
				and not(monster.get_monster_at(x, y):attitude()>1)
				and view.cell_see_cell(0,0,x,y)
			then
				if VERSION<.28 then
					if not(you.branch()=="Abyss") then --no exclusions in Abyss
						travel.set_exclude(x,y,0)
						table.insert(deltable, { x, y })
					end
					
				else
					--table.insert(deltable, { x, y })
					--table.insert(deltable, true)
					travel.set_travel_trail( x+( y==0 and (x==0 and 0 or math.abs(x)/x) or 0) , y+(y==0 and 0 or math.abs(y)/y) )
					travel.set_travel_trail(x,y)
				end
				
				--table.insert(r_td, rtd_mark_positions)
				r_td[rtd_mark_positions]=1
			end
		end
	end
end
function rtd_mark_positions()
	if VERSION<.28 then
		for k in pairs(deltable) do
			travel.del_exclude(deltable[k][1],deltable[k][2])
		end
		
		deltable={}
	else
		--if false and next(deltable) then --TD delete
			----for k in pairs(deltable) do
				----travel.set_travel_trail(deltable[k][1],deltable[k][2])
			----end
			--deltable={}
			
			--table.insert(r_td, rtd_mark_positions)
			
		--else
			travel.clear_travel_trail()
		--end
	end
end
function r_warnings()
	cmsg_warnings("","")
	if monster_warning=="td" then
		crawl.more()
	elseif monster_warning=="skipchk" and you.feel_safe() then --something went into view, and out of view. would work with "out of view" handling above, but that's not needed since mark_positions is used
		crawl.mpr("you immediately lose sight...")
		crawl.more()
	end
end
function r_monster_warning()
if monster_warning then
	--if monster_warning=="td" then
		--crawl.more()
	--else
	monster_warning=false
end
end
 
------------------------------------------------------------------------------------------------------------
local function delta_to_cmd(dx, dy) 
  local d2v = {
    [-1] = { [-1] = "CMD_MOVE_UP_LEFT",  [0] = "CMD_MOVE_LEFT",  [1] = "CMD_MOVE_DOWN_LEFT"},
    [0]  = { [-1] = "CMD_MOVE_UP",                               [1] = "CMD_MOVE_DOWN"},
    [1]  = { [-1] = "CMD_MOVE_UP_RIGHT", [0] = "CMD_MOVE_RIGHT", [1] = "CMD_MOVE_DOWN_RIGHT"}, }
  return d2v[dx][dy]
end
local function delta_to_safe_cmd(dx, dy) 
  local d2v = {
    [-1] = { [-1] = "CMD_SAFE_MOVE_UP_LEFT",  [0] = "CMD_SAFE_MOVE_LEFT",  [1] = "CMD_SAFE_MOVE_DOWN_LEFT"},
    [0]  = { [-1] = "CMD_SAFE_MOVE_UP",                               [1] = "CMD_SAFE_MOVE_DOWN"},
    [1]  = { [-1] = "CMD_SAFE_MOVE_UP_RIGHT", [0] = "CMD_SAFE_MOVE_RIGHT", [1] = "CMD_SAFE_MOVE_DOWN_RIGHT"}, }
  return d2v[dx][dy]
end
local movekeys={}
--local dma_table={}
function r_disable_move_attack()
	--crawl.mpr("rdma")
	local LOS=you.los()
	for x = -1,1 do
		for y = -1,1 do
			local monster_obj = monster.get_monster_at(x, y)
			local cmd=delta_to_cmd(x,y)
			if
				not(  monster_obj==nil )
				and not(monster_obj:attitude()>2)
				or view.invisible_monster(x,y)
			then
				if not(dma_table[cmd]) then
					if not movekeys[cmd] then movekeys[cmd]=get_command(cmd,true,true) end
					local key=movekeys[cmd]
					crawl.setopt("bindkey = ["..key.."] CMD_NO_CMD_DEFAULT")
					--crawl.mpr("bindkey = ["..key.."] CMD_NO_CMD_DEFAULT")
					dma_table[cmd]=true
				end
			else
				if dma_table[cmd] then
					local current_cmd
					if not(move_careful) then
						current_cmd=delta_to_cmd(x,y)
					else
						current_cmd=delta_to_safe_cmd(x,y)
					end
					local key=movekeys[cmd]
					crawl.setopt("bindkey = ["..key.."] "..current_cmd)
					--crawl.mpr("bindkey = ["..key.."] "..current_cmd)
					dma_table[cmd]=false
				end
			end
		end
	end
end
table.insert(r_funcs, r_disable_move_attack)
------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------
local path
function show_enemy_beam_path()
	crawl.mpr("Select enemy:",2)
	local x, y = crawl.get_target()
	local x0=0
	local y0=0
	--echoall(x)
	--echoall(y)
	if x==nil and y==nil then return
	--elseif x==0 and y==0 then		
		--crawl.mpr("Select start:",2)
		--x0, y0 = crawl.get_target()
		--crawl.mpr("Select enemy:",2)
		--x, y = crawl.get_target()
	elseif monster.get_monster_at(x, y)==nil or monster.get_monster_at(x, y):attitude()>3 then
		x0, y0 = x, y
		crawl.mpr("Selected Start. Select enemy:",2)
		x, y = crawl.get_target()
	end
	
	path=spells.path("Magic Dart",x0,y0,x,y)
	--path=spells.path("Lightning Bolt",x0,y0,x,y)
	--dump(path)
	if VERSION<.28 then
		if not(you.branch()=="Abyss") then --no exclusions in Abyss
			for k in pairs(path) do
				travel.set_exclude(path[k][1],path[k][2],0)
			end
		end
		
		table.insert(r_td, rtd_show_enemy_beam_path)
	else
		for k in pairs(path) do
			travel.set_travel_trail(path[k][1],path[k][2])
		end
	end
end
function rtd_show_enemy_beam_path()
	if not(you.branch()=="Abyss") then
		for k in pairs(path) do
			travel.del_exclude(path[k][1],path[k][2])
		end
	else
		local found=false
		crawl.mpr("Select tile:",2)
		local x, y = crawl.get_target()
		while x do
			for k in pairs(path) do
				if x==path[k][1] and y==path[k][2] then
					crawl.mpr("Tile is in beam path.",2)
					found=true
					break;
				end
			end
			if found then break end
			crawl.mpr("Tile is not in beam path.",6)
			x, y = crawl.get_target()
		end
		
	end
	
end
------------------------------------------------------------------------------------------------------------
local reminding = false
local remind_start=0
function remindMe()
	reminding=true
	remind_start=you.time()  
	crawl.mpr("reminder set!")
	table.insert(r_td,rtd_remindMe)
end
function rtd_remindMe()
	if reminding then
		--if you.time()>remind_start+1500 then
		if you.time()+10>remind_start+230 then
			--crawl.mpr("time to eat!")
			crawl.mpr("Reminder reminding you to do the thing!",4)
			reminding = false
			crawl.more()
		else
			table.insert(r_td,rtd_remindMe)
		end
	end
end
  -------------------------------------------------------------------------------------------------------------
  
  
local cooldownstatus=0
function rested(minmpmult)
	return ( (({you.hp()})[1]==({you.hp()})[2] or you.status("non-regenerating"))
			and ( ({you.mp()})[1]==({you.mp()})[2]
				or minmpmult and ({you.mp()})[1]>=({you.mp()})[2]*minmpmult )
			and you.contaminated()==0 and you.swift()==0
			and (you.corrosion()==0 or (you.branch()=="Dis" and you.corrosion()<=2))
			and not( you.slowed() or you.confused() or you.breath_timeout() or you.on_fire() or you.poisoned()
				or you.petrifying() or you.teleporting() or you.silencing() or you.exhausted()
				or you.status("can't hop") or you.status("doom-hounded") or you.status("frozen")
				or (you.status("weak-willed") and not you.branch()=="Tar")
				or you.status("no potions") --only the killer clown effect
				or you.status("sap magic")
				or you.status("barbed spikes")
				or you.transform()=="pig" or you.transform()=="fungus" or you.transform()=="wisp"
				or you.status():match("vulnerable") --only fire vulnerable atm, I think
				or you.status("berserk cooldown") or you.status("berserking")
				--or you.status():match("weak") --needs testing
				--or (you.status("glowing") and TD:notalwaysglowing)
				-- -Recite, -Vortex -TD
				-- -Dragoncall:
				or cooldownstatus>0
				 ))
end
function cmsg_cooldownstatus(msg, ch)
	if msg:match("roar of the dragon horde subsides") then
		cooldownstatus=cooldownstatus+1
	elseif msg:match("ou can once more reach out to the dragon horde") then
		cooldownstatus=math.max(cooldownstatus-1,0)
	end
end
table.insert(cmsg_funcs,cmsg_cooldownstatus)
  -------------------------------------------------------------------------------------------------------------
local restingf = false
local restingf_start=0
local restingf_end=0
local restingf_till_reminding=false
local restingf_useless_anyway=false
function rest_for(n)
	restingf = true
	restingf_start=you.time()  
	restingf_end=restingf_start+n
	if reminding then restingf_till_reminding=true end
	crawl.mpr("You start waiting...")
end
function r_rest_for()
	local hp, mhp = you.hp()
	local mp, mmp = you.mp()
	if restingf then
		if
			not(move_careful) or (not(restingf_till_reminding) and you.time()+1>restingf_end)
			--or rested() or you.hunger()<1 or (restingf_till_reminding and not(reminding)) then--HUNGER
			or (rested() and not(restingf_useless_anyway)) or (restingf_till_reminding and not(reminding))
			--or rested()
		then
			restingf = false
			restingf_till_reminding=false
			restingf_useless_anyway=false
			crawl.mpr("You stop resting.")
			if you.time()==restingf_start then
				if crawl.yesno("Really wait?",true,"N") then
					restingf_useless_anyway=true
					restingf = true
					rest_for_turn()
				else
					--crawl.mpr("Actually, you don't start resting.")
					crawl.mpr("You don't start waiting.")
				end
			else
				if (wait_x_equip_off and move_careful) then
					rest_for_turn()
				end
				--wait_x_last="" --toggle for reset
			end
		else
			rest_for_turn()
		end
	end
end
function rest_for_turn()
	if wait_x_last=="" then
		crawl.mpr("You wait.")
		crawl.do_commands({"CMD_WAIT"}) 
	else
		_G[wait_x_last]()
	end
end
function k_rest_for()
	--rest_for(230)
	rest_for(100)
end
  -------------------------------------------------------------------------------------------------------------
function you_wait()
	crawl.mpr("You wait.")
	crawl.do_commands({"CMD_WAIT"})
	wait_x_last=""
end
  -------------------------------------------------------------------------------------------------------------
function rest_with_prompt()
	if autopickup_is_on then
		if
			rested()
		then
			if crawl.yesno("Really wait for up to 100 decaAut?",true,"N") then
				--crawl.do_commands({"CMD_REST"})
				crawl.sendkeys(get_command("CMD_REST"))
			else
				crawl.mpr("You don't start waiting.")
			end
		else
			--crawl.do_commands({"CMD_REST"}) --leads to a bug in an older version when you use the repeating command
			crawl.sendkeys(get_command("CMD_REST"))
		end
	else
		crawl.mpr("You don't start waiting.")
	end
end
------------------------------------------------------------------------------------------------------------
local rest_wait_percent = 100
function toggle_rest_wait_percent()
	if rest_wait_percent == 100 then
		rest_wait_percent = 98
		crawl.setopt("rest_wait_percent = 98")
		crawl.mpr("rest_wait_percent = 98")
	else
		rest_wait_percent = 100
		crawl.setopt("rest_wait_percent = 100")
		crawl.mpr("rest_wait_percent = 100")
	end
end
function start_rest_wait_percent()
	--if you.xl()<14 then
	if true then
		rest_wait_percent = 100
		crawl.setopt("rest_wait_percent = 100")
	else
		rest_wait_percent = 98
		crawl.setopt("rest_wait_percent = 98")	
	end
end
  -------------------------------------------------------------------------------------------------------------
--local super_resting = false
function super_rest()
	--super_resting=true
	--crawl.setopt("rest_wait_both = true")
	--crawl.setopt("runrest_ignore_message ^= magic, HP, contam")
	crawl.setopt("rest_wait_percent = 100")
	--crawl.do_commands({"CMD_REST"})
	rest_with_prompt()
	table.insert(r_td,rtd_super_rest)
end
function rtd_super_rest()
	--super resting
	--if super_resting then
		--crawl.setopt("rest_wait_both = false")
		--crawl.setopt("runrest_ignore_message -= magic, HP, contam")
		--crawl.setopt("rest_wait_percent = 98")
		crawl.setopt("rest_wait_percent = "..tostring(rest_wait_percent))
		--super_resting = false
	--end
end
------------------------------------------------------------------------------------------------------------
  
  
local togglable_rest_is="normal"
function toggle_togglable_rest()
	if togglable_rest_is=="normal" then
		togglable_rest_is="until"
		crawl.mpr("using equip rest")
	else
		togglable_rest_is="normal"
		crawl.mpr("using regular rest")
	end
end
  
function togglable_rest()
	if togglable_rest_is=="normal" then
		rest_with_prompt()
	else
		rest_until()
	end
end
  
  -------------------------------------------------------------------------------------------------------------
  
local avoidapproach="approach"
local travel_open_doors = avoidapproach
crawl.setopt("travel_open_doors = open") --it's only set to travel_open_doors in explore_simpler
function toggle_travel_open_doors()
	if travel_open_doors == avoidapproach then
		travel_open_doors = "open"
		--crawl.setopt("travel_open_doors = open") --commeted out bc explore function sets it.
		crawl.mpr("travel_open_doors = open")
	else
		travel_open_doors = avoidapproach
		--crawl.setopt("travel_open_doors = "..avoidapproach)
		crawl.mpr("travel_open_doors = "..avoidapproach)
	end
end
function toggle_avoidapproach()
	if avoidapproach == "avoid" then
		avoidapproach = "approach"
		if travel_open_doors == "avoid" then
			travel_open_doors=avoidapproach
		end
	else
		avoidapproach = "avoid"
		if travel_open_doors == "approach" then
			travel_open_doors=avoidapproach
		end
	end
	crawl.mpr("travel_open_doors = "..(((travel_open_doors:match("open") or "")..", would be "):match("open, would be ") or "")..avoidapproach)
end
  -------------------------------------------------------------------------------------------------------------
local just_exploring = false
local exploring = false
function r_meta_explore()
	r_just_explore()
	r_explore_simpler()
end
crawl.setopt("explore_auto_rest = true") 
function just_explore()
	just_exploring=true
	crawl.setopt("explore_auto_rest = false")
	explore_simpler()
end
function r_just_explore()
	if just_exploring then
	crawl.setopt("explore_auto_rest = true") 
	just_exploring=false
	end  
end
function explore_simpler() --TD merge with just_explore
	exploring=true
	monster_warning="skip" --skip it during next round, but only if monsters are in view
	--toggle_move_careful_off_noprompt()	
	if travel_open_doors == avoidapproach then crawl.setopt("travel_open_doors = "..avoidapproach) end
	if not(you.branch()=="Shoals" and you.flying()) or crawl.yesno("Really autoexplore?",true,"N") then crawl.sendkeys( get_command("CMD_EXPLORE") ) end
end
function r_explore_simpler()
	if exploring then
	crawl.setopt("travel_open_doors = open")
	exploring=false
	end  
end
------------------------------------------------------------------------------------------------------------
local interrupt=false
--local interrupt_turn=-100
--local interrupt_was
function reset_interrupt()
	--echoall("---"..tostring(interrupt))--
	--if interrupt then interrupt_was=interrupt end
	interrupt=false
	--interrupt_turn=you.turns()
end
function do_interrupt(reason)
	if reason then 
		interrupt=reason; table.insert(r_td, reset_interrupt)
	end
end
------------------------------------------------------------------------------------------------------------
local ctrl_exploring=false --says whether it should run
local ctrl_explore_timestamp=-1 -- negatives tell you that the rtd isn't active and for what reason
function ctrl_explore()
	ctrl_exploring=true
	if ctrl_explore_timestamp<0 then
		--table.insert(r_td,rtd_ctrl_explore)
		rtd_ctrl_explore()
		--ctrl_explore_timestamp=-1
		--toggle_move_careful_off_noprompt()
		crawl.setopt("message_color += mute:ove the cursor to view the level map")
		crawl.setopt("message_color += mute:eturning to the game...")
	end
	
end
function rtd_ctrl_explore()
	--crawl.mpr("cx")--
	if ctrl_exploring then
		if not(interrupt) then
			if ctrl_explore_timestamp=0) --wrong if already G running
							--rtd_ctrl_explore()
							--echoall("G")
							crawl.sendkeys(get_command("CMD_INTERLEVEL_TRAVEL").."\13")
							manual_explore=false --now works similar to just_explore, until at the target
							xsummon_resume_ctrl_x=true
						else
							manual_explore=false
							togglable_explore()
							--if ctrl_explore_timestamp>0 then ctrl_explore_timestamp=ctrl_explore_timestamp+10 end
						end
						
						if autocall or resummons==1 then table.insert(r_td,rtd_explore_summon) end
					elseif not(interrupt:match("miscast")) then
						explore_summon_reset()
					else
						manual_explore=true
						if autocall or resummons==1 then table.insert(r_td,rtd_explore_summon) end
					end
				else
					explore_summon_reset(true)				
				end
			end))
		else
			table.insert(r_td,rtd_explore_summon)
		end
	else
		explore_summon_reset(true)
	end
end
function rtd_explore_summon()
	--echoall("xs")--
	xsummon_interrupt_chk(true)
	
	if not(xsummon) or you.where()~=xsummonfloor then
		explore_summon_reset(xsummonfloor)
		return
	end
		
	local restedv=( ({you.mp()})[1]==({you.mp()})[2] )
	--rested()--TD ignore hp and low contamination... only mp?
	--echoall("xs",move_careful, restedv, resummons)
	if move_careful and ( not(restedv) or xsummon_delay_condition() ) then
		--echoall("xsm")
		manual_explore=not(ctrl_exploring or xsummon_resume_ctrl_x)
		table.insert(r_td,rtd_explore_summon)
		--echoall(xsummon_resume_ctrl_x)--
		if xsummon_resume_ctrl_x then
			xsummon_resume_ctrl_x=false
			togglable_explore()
		end
	else --not movecarful or rested
			
			--ctrl_expl is going to be interrupted this round
			
			--if ctrl_exploring then manual_explore=false end--unn bc already done when starting cx
			
			--if we just ended map mode, r fires, we aren't in this else block yet,
			--but manual is set as false bc cx fires after this.
			--If we take a step in the next round, it might go in this block, so we need to check that cx wasn't ended by interrupt, because otherwise manual=false is intended.
			--echoall(ctrl_explore_timestamp)--
			if togglable_explore_is=="ctrl_explore" and ctrl_explore_timestamp<0 and ctrl_explore_timestamp~=-3 then 
				--echoall(ctrl_explore_timestamp)--
				manual_explore=true
			end
			
			
		--echoall(resummons,xsummonalt)
		
		if restedv then
			if resummons=xsummonsbeforedelay and you.time()0
					and xsummon_delay_condition()
				then
					xsummon_interrupt=true
				else
					crawl.mpr("MP restored.")
					result=true
				end
			end
		end
		
		--if iname=="full_mp" then echoall(xsummon, (ctrl_exploring or just_exploring)) end
		
		if result then
			--echoall("cia cx false")--
		--echoall("---n "..tostring(iname))
		--echoall("---c "..tostring(cause))--
		--echoall("---e "..tostring(extra))
			do_interrupt(iname..(iname=="message" and (" "..tostring(cause).." "..tostring(extra)) or ""))
		end
		return result
	end
end
--echoall("m",chk_interrupt_activity.macro)
--local old_chk_interrupt_activity_macro = chk_interrupt_activity.macro
--chk_interrupt_activity.macro = function(iname,cause,extra)
	--return chk_interrupt_activity.travel(iname,cause,extra)
		--and move_careful
		----and old_chk_interrupt_activity_macro(iname,cause,extra)
		--or false --ensure that it never sends nil
--end
--chk_interrupt_activity.run = chk_interrupt_activity.travel
--chk_interrupt_activity.rest = chk_interrupt_activity.run
--local old_chk_interrupt_activities=chk_interrupt_activities
--function chk_interrupt_activities(iname, cause, extra)
--return chk_interrupt_activity.run(iname, cause, extra) and old_chk_interrupt_activities(iname, cause, extra) end
--local old_c_interrupt_activity= c_interrupt_activity
--function  c_interrupt_activity(aname, iname, cause, extra)
	--echoall(aname)
	--return old_c_interrupt_activity(aname, iname, cause, extra)
--end --
function xsummon_interrupt_chk(nostop)
	if xsummon_interrupt then
		if not(xsummon_delay_condition()) then
			if you.turn_is_over() and not(nostop) then you.stop_activity() end
			--echoall("xsic")--
			do_interrupt("xsummon_interrupt")
			xsummon_interrupt=false
		end
	end
end
function ch_mon_is_safe(monster, is_safe, moving, dis) --hook
	xsummon_interrupt_chk()
	return is_safe
end
local function mod_rr_handle_message(mess,ch)
    --local ch, mess = rr_split_channel(cause)
    chnum=crawl.msgch_num(ch)
    
    for _, x in ipairs(g_rr_ignored) do
        if chnum and x.filter:matches(mess, chnum) then
            return x.value
        end
    end
    return false
end
local function ally_attacked_out_of_view_msg_test(msg, ch)
--TD what if ally is destroyed before identified? test
--assumes rr_handle_message found the message sus
--used to decide whether to send a monster warning more prompt
	local LOS=you.los()
	for x = -LOS,LOS do
		for y = -LOS,LOS do
			local monster_obj = monster.get_monster_at(x, y)
			if
				not(  monster_obj==nil )
				and monster_obj:attitude()>3
				and view.cell_see_cell(0,0,x,y)
			then
				local name = monster_obj:name()
				if msg:find("your "..name,0,true) then return true end
			end
		end
	end
	return false
end
function no_other_ally_in_view(msg)
--stationaries dont count
	local LOS=you.los()
	local found=false
	for x = -LOS,LOS do
		for y = -LOS,LOS do
			local monster_obj = monster.get_monster_at(x, y)
			if
				not(  monster_obj==nil )
				and monster_obj:attitude()>3
				and view.cell_see_cell(0,0,x,y)
			then
				local name = monster_obj:name()
				--echoall("---"..name)
				if msg:find(name,0,true) then
					if not(found) then
						found=true
					else
						return false --found two with that name
					end
				elseif not(monster_obj:is_stationary()) then
					return false --found a different one that's mobile
				end
			end
		end
	end
	return true
end
crawl.setopt("runrest_ignore_message ^= prompt:[Ww]here to\?")
function cmsg_xsummon(msg, ch)
	--if msg:match("you miscast") then
	
	if	move_careful then
		if
			xsummon
			and msg:match("our.* disappears in a puff of smoke")
			and no_other_ally_in_view(msg)
			 --it still exists during the message
			 --when resummoning, for this brief moment both new and old exist
			 --so it's false in that case
			 --which is desired, but feels hacky to rely on that phenomon
			 --but otherwise it would be no_ally_in_view, and then it would also just work.
		then
			if you.turn_is_over() then you.stop_activity() end
			--echoall("---cm xf")
			table.insert(r_td, (function() crawl.mpr("No more allies in sight.") end))
			do_interrupt("no allies")
			xsummonalt=false
		elseif mod_rr_handle_message(msg,ch)then
			you.stop_activity() --so that you don't check again in chk_interrupt
			--echoall("---cm xff"..msg)
			do_interrupt("mod_rr "..ch..":"..msg)
			if ally_attacked_out_of_view_msg_test(msg, ch) then
				monster_warning_td()
			end
		end
	end
end
table.insert(cmsg_funcs,cmsg_xsummon)
------------------------------------------------------------------------------------------------------------
function start_explore_summon()
	
	if c_persist.xs==nil then
		c_persist.xs={}
	end	
	if c_persist.xs[you.name()]==nil then
		c_persist.xs[you.name()]={ xsummon, xsummon2, xsummonalt }
	end
	xsummon=c_persist.xs[you.name()][1]
	xsummon2=c_persist.xs[you.name()][2]
	xsummonalt=c_persist.xs[you.name()][3]
	c_persist.xs[you.name()]=nil
end
function csave_explore_summon()
	c_persist.xs[you.name()]={ xsummon, xsummon2, xsummonalt }
end
  -------------------------------------------------------------------------------------------------------------
  
function explore_chk_and_summon_toggle()
	local function f()
		crawl.setopt("message_color += mute:prompt:.*")
		crawl.setopt("message_color += mute:[Ww]aypoint")
		crawl.setopt("message_color += mute:ove the cursor to view")
		crawl.setopt("message_color += mute:urning to the game")
		crawl.setopt("message_color += mute:\\(")
		crawl.sendkeys(get_command("CMD_DISPLAY_MAP")..get_command("CMD_MAP_EXPLORE")..get_command("CMD_MAP_ADD_WAYPOINT").."0\27")
		table.insert(r_td, (function()
			crawl.setopt("message_color -= mute:prompt:.*")
			crawl.setopt("message_color -= mute:[Ww]aypoint")
			crawl.setopt("message_color -= mute:ove the cursor to view")
			crawl.setopt("message_color -= mute:urning to the game")
			crawl.setopt("message_color -= mute:\\(")
			if ({ travel.waypoint_delta(0) })[1]==0 and ({ travel.waypoint_delta(0) })[2]==0 then
				just_explore()
			else
				crawl.mpr("not fully explored.")
			end
		end))
	end
	if xsummon and you.where()==xsummonfloor then
		xsummonfloor=""
		f()
	else
		crawl.mpr("starting explore_summon")
		explore_summon_manual()
		table.insert(r_td, 1, f)
	end
end
-------------------------------------------------------------------------------------------------------------
local rest_until_normal_mp = {}
rest_until_normal_mp.a = false --if true, run rest_until again
rest_until_normal_mp.z = false --if true, the original equip should be reequipped when rested
local mp_buff=0
local original_equip={}
local old_original_equip={}
function rest_until()
	
	----equips staff at p, rings at Y, and then Z, if those are of magical power, then regenerates as if these weren't equipped	
	-- then equips back to old stuff unless you were interrupted by a monster
	-- basically calls itself in ready() by setting variables
	---uses rest_with_prompt(), but could be crawl.sendkeys( get_command("CMD_REST") )
	
	---inscribe mpp, mpY or mpZ repectively
	---to do this with artefacts
	
	---atm this is always necessary because !R autoinsciption is not considered
	---to undo change the three conditions back
	mp_buff=0 --will be increased according to your equip, so that the function knows how much to rest
	------------if you have +mp equip that isn't at slots p, Y or Z, it will not be taken into account; this is a feature.
	local turn_free=true --will be toggled to false if we equip something
	local badletters=false --will be toggled to true if you named the ring on jour left hand Z or the ring on your right hand Y
	--the next code blocks check the equip and slots, then equip something if necessary
	if (not(items.inslot(items.letter_to_index("p"))==nil)) and (items.inslot(items.letter_to_index("p")):name():match("staff of powernever") or items.inslot(items.letter_to_index("p")).inscription:match("mpp")) then
		crawl.mpr("mpp")
		if (items.equipped_at(0)==nil) then
			turn_free=false
			crawl.process_keys("wp")
		else
		if not(items.equipped_at(0):name()=="staff of power" or items.equipped_at(0).inscription:match("mpp")=="mpp") then
			original_equip.weapon=items.index_to_letter(items.equipped_at(0).slot)
			turn_free=false
			crawl.process_keys("wp")
			crawl.mpr("test")
		end
		end
		if items.inslot(items.letter_to_index("p")):name()=="staff of power" then
			mp_buff=mp_buff+15
		else
			mp_buff=mp_buff+9
	end
	end
	if turn_free and (not(items.inslot(items.letter_to_index("Y"))==nil)) and (items.inslot(items.letter_to_index("Y")):name():match("ring of magical powernever") or items.inslot(items.letter_to_index("Y")).inscription:match("mpY")) then
		if not(items.equipped_at(8)==nil) and items.index_to_letter(items.equipped_at(8).slot)=="Y" then
			crawl.mpr("Please assign correct letters for your rings and check your equip.")
			rest_until_normal_mp.a=false
			rest_until_normal_mp.z=false 
			badletters=true
			original_equip={}
		else
		if (items.equipped_at(7)==nil) then
			turn_free=false
			crawl.process_keys("PY")
		else
		if not(items.equipped_at(7):name()=="ring of magical power" or items.equipped_at(7).inscription:match("mpY")) then
			original_equip.lring=items.index_to_letter(items.equipped_at(7).slot)
			turn_free=false
			crawl.process_keys("R"..original_equip.lring.."PY")
		end
		end
		mp_buff=mp_buff+9
		end 
	end
	if turn_free and (not(items.inslot(items.letter_to_index("Z"))==nil)) and (items.inslot(items.letter_to_index("Z")):name():match("ring of magical powernever") or items.inslot(items.letter_to_index("Z")).inscription:match("mpZ")) then
		if not(items.equipped_at(7)==nil) and items.index_to_letter(items.equipped_at(7).slot)=="Z" then
			crawl.mpr("Please assign correct letters for your rings and check your equip.")
			rest_until_normal_mp.a=false
			rest_until_normal_mp.z=false 
			badletters=true
			original_equip={}
		else
		if (items.equipped_at(8)==nil) then
			turn_free=false
			crawl.process_keys("PZ")
		else
		if not(items.equipped_at(8):name()=="ring of magical power" or items.equipped_at(8).inscription:match("mpZ")=="mpZ") then
			original_equip.rring=items.index_to_letter(items.equipped_at(8).slot)
			turn_free=false
			crawl.process_keys("R"..original_equip.rring.."PZ")
		end
		end
		mp_buff=mp_buff+9
		end
	end
	
	--now to use the variables we set, and set globals to call the function again in the next turn, if needed:
	--local hp, mhp = you.hp()
	local mp, mmp = you.mp()
	
	if not(badletters) then
	if mp_buff==0 then
		rest_with_prompt()
	else
		if turn_free then
			local percent = math.floor(100*(mmp-mp_buff)/mmp)
			crawl.setopt("rest_wait_percent = "..percent)
			rest_until_normal_mp.z=true	 
			if not(mp>(mmp-mp_buff-2)) then
				rest_with_prompt()
			end
		else
			crawl.mpr("equipped something")
			rest_until_normal_mp.a=true	 
		end
	end
	end
end
function r_rest_until() --this runs in ready()
	local hp, mhp = you.hp()
	local mp, mmp = you.mp()
	if rest_until_normal_mp.a then
		rest_until_normal_mp.a=false
		if move_careful then
			rest_until() 
		end
	else
	if rest_until_normal_mp.z and ( mp>(mmp-mp_buff-2) or not(you.feel_safe()) or not(move_careful) ) then
		--crawl.mpr("test2")
		crawl.setopt("rest_wait_percent = "..rest_wait_percent)
		if not(you.feel_safe()) or not(move_careful) then
			rest_until_normal_mp.z=false
			if
				not(original_equip.weapon==nil)
				and not(original_equip.lring==nil)
				and not(original_equip.rring==nil)
			then
				old_original_equip=original_equip
				original_equip={}
			else
				crawl.mpr("original_equip=={}")
			end
			crawl.mpr("Danger! Your equip may be inadequate!")
		else
			if not(original_equip.weapon==nil) then
				crawl.process_keys("w"..original_equip.weapon)
				original_equip.weapon=nil
			elseif not(original_equip.lring==nil) then
				crawl.process_keys("RYP"..original_equip.lring)
				original_equip.lring=nil
			elseif not(original_equip.rring==nil) then
				crawl.process_keys("RZP"..original_equip.rring)
				original_equip.rring=nil
				rest_until_normal_mp.z=false
			end
			if original_equip.weapon==nil and original_equip.lring==nil and original_equip.rring==nil then
				rest_until_normal_mp.z=false
			end
		end
	end
	end
end
function rest_until_restore_equip()
	original_equip=old_original_equip
	rest_until_normal_mp.z=true
	if not(original_equip.weapon==nil) then
		crawl.process_keys("w"..original_equip.weapon)
		original_equip.weapon=nil
	else
	if not(original_equip.lring==nil) then
		crawl.process_keys("RYP"..original_equip.lring)
		original_equip.lring=nil
	else
	if not(original_equip.rring==nil) then
		crawl.process_keys("RZP"..original_equip.rring)
		original_equip.rring=nil
		rest_until_normal_mp.z=false
	end
	end
	end
	if original_equip.weapon==nil and original_equip.lring==nil and original_equip.rring==nil then rest_until_normal_mp.z=false end
end
  -------------------------------------------------------------------------------------------------------------
local crystal_ball_notified = false
function r_crystal_ball_notify()
	if (not(items.inslot(items.letter_to_index("c"))==nil)) and items.inslot(items.letter_to_index("c")):name()=="crystal ball of energy" then
	local mp, mmp = you.mp()
	local evo = you.skill("evocations")
	if ( (mp-9)/mmp<(76-2*math.floor(evo))/100 ) then
		if not(crystal_ball_notified) then
			crawl.mpr("You need to stay over "..tostring(math.floor(mmp*(76-2*math.floor(evo))/100)+1).." MP to use the crystal ball!",7)
			crawl.more()
			crystal_ball_notified = true
		end
	else
		crystal_ball_notified = false
	end
	end
end
  ---------------------------------------------------
function use_ball()
	if you.status("vitalised") or crawl.yesno("Really use the crystal ball?",true) then
		crawl.process_keys("Vc")
	else
		crawl.mpr("ok then.",2)
	end
end
  -------------------------------------------------------------------------------------------------------------
wait_x_last=""--just for info, used in rest_for
wait_x_equip_off=false
wait_weapon_equip=""
function wait_weapon()
	wait_x_last="wait_weapon"
	r_move_careful()
	if not(items.equipped_at(0)==nil) then
		wait_weapon_equip=items.index_to_letter(items.equipped_at(0).slot)
		crawl.sendkeys("w-")
		wait_x_equip_off=true
	else
		crawl.sendkeys("w*"..wait_weapon_equip)
		wait_x_equip_off=false
	end
end
wait_ring_equip=""
function wait_ring()
	wait_x_last="wait_ring"
	r_move_careful()
	if not(items.equipped_at(7)==nil) then
		wait_ring_equip=items.index_to_letter(items.equipped_at(7).slot)
		if (items.equipped_at(8)==nil) then
			crawl.sendkeys("R")
		else
			crawl.sendkeys("R"..wait_ring_equip)
			wait_x_equip_off=true
		end
	else
		crawl.sendkeys("P"..wait_ring_equip)
		wait_x_equip_off=false
	end
end
wait_ring_equip2=""
function wait_ring2()
	wait_x_last="wait_ring2"
	r_move_careful()
	if not(items.equipped_at(8)==nil) then
		wait_ring_equip2=items.index_to_letter(items.equipped_at(8).slot)
		if (items.equipped_at(7)==nil) then
			crawl.sendkeys("R")
		else
			crawl.sendkeys("R"..wait_ring_equip2)
			wait_x_equip_off=true
		end
	else
		crawl.sendkeys("P"..wait_ring_equip2)
		wait_x_equip_off=false
	end
end
  -------------------------------------------------------------------------------------------------------------
function bad_key()
	crawl.mpr("this key doesn't do anything right now!")
	crawl.more()
end
  -------------------------------------------------------------------------------------------------------------
gourm_reminded=true
function r_chk_gourm_fullness()
	if you.gourmand() then
		if you.hunger()==6 and not(gourm_reminded) then
			crawl.mpr("You are no longer engorged.")
			crawl.more()
			gourm_reminded=true
		elseif you.hunger()==7 and gourm_reminded then
			gourm_reminded=false
		end
	end
end
  -------------------------------------------------------------------------------------------------------------
function wiz_spell_costs()
	crawl.mpr("spc="..you.skill_cost("spellcasting").." spc*2="..(2*you.skill_cost("spellcasting")).." conj*3="..3*you.skill_cost("conjurations").." air="..you.skill_cost("air magic").." fire="..you.skill_cost("fire magic").." tl="..you.skill_cost("translocations").." hx="..you.skill_cost("hexes"))
	
	--crawl.mpr("spc*4="..(4*you.skill_cost("spellcasting")).." conj*3="..(3*you.skill_cost("conjurations")).." air*3+fire*2="..(3*you.skill_cost("air magic")+2*you.skill_cost("fire magic")).. " 4*spc-tl-hx="..(4*you.skill_cost("spellcasting")-you.skill_cost("translocations")-you.skill_cost("hexes")))
	crawl.mpr("spc*4="..(4*you.skill_cost("spellcasting")).." conj*2="..(2*you.skill_cost("conjurations")).." 2*tl="..(2*you.skill_cost("translocations")).." 2*hx="..(2*you.skill_cost("hexes")).." 2(tl+hx)="..(2*you.skill_cost("translocations")+2*you.skill_cost("hexes")))
end
  -------------------------------------------------------------------------------------------------------------
 
local sstnum=0
local sstspls = {"Apportation",
"Confusing Touch",
"Magic Dart",
"Foxfire",
"Blink",
"Passwall",
"Slow",
"Swiftness",
"Ozocubu's Armour",
"Mephitic Cloud",
"Gell's Gravitas",
"Cause Fear",
"Leda's Liquefaction",
"Enfeeble",
"Fulminant Prism",
"Iskenderun's Mystic Blast",
"Fireball",
"Iskenderun's Battlesphere",
"Yara's Violent Unravelling",
"Deflect Missiles",
"Dispersal",
"Orb of Destruction",
"Discord",
"Disjunction",
"Fire Storm",
"Polar Vortex",
"Shatter",
"Chain Lightning",
"Lehudib's Crystal Spear",
"Summon Lightning Spire",
"Teleport Other",
"Airstrike",
"Spellforged Servitor",
"Summon Guardian Golem",
"Vile Clutch",
"Death's Door",
"Necromutation",
"Borgnjor's Revivification",
"Iron Shot",
"Ignition",
"Passage of Golubria",
"Summon Butterflies",
"Regeneration",
"Confuse",
"Force Lance",
"Agony",
"Aura of Abjuration",
"Bolt of Cold",
"Bolt of Fire",
"Ring of Flames",
"Glaciate",
"Tornado",
"Controlled Blink",
"Invisibility",
"Darkness",}
local sst_responses={}
function sif_spells_test()
sstnum=1
end
function r_sif_spells_test()
if sstnum>0 then --sstnum==0 means nothing should be done
if sstnum<=table.maxn(sstspls) then
	if sstnum>1 then
		table.insert(sst_responses,crawl.messages(1))
	end
	crawl.sendkeys("Ä\6")
	crawl.sendkeys(sstspls[sstnum])
	crawl.sendkeys("\13a")
	sstnum=sstnum+1
else
	table.insert(sst_responses,crawl.messages(1))
	sstnum=0 
	local maxn=table.maxn(sstspls)
	for i=1,maxn,1 do
		if sst_responses[i]:match("Okay, then.")=="Okay, then." and not(spells.memorised(sstspls[i])) then
			crawl.mpr(sstspls[i])
		else if sst_responses[i]=="Memorise" then
			table.remove(sst_responses,i+1)
		end
		end
	end
	sst_responses={}
end
end
end
function ans_sif_spells_test() --called in c_answer_prompt()
if sstnum>0 then
	table.insert(sst_responses,"Memorise")
	crawl.sendkeys("N") 
end
end
  -------------------------------------------------------------------------------------------------------------
function prompt_orb()
	local mo=nil
	local orb_near=false
	for x=-1,1 do
		for y=-1,1 do
			mo=monster.get_monster_at(x,y)
			if
				not(mo==nil) and
					(mo:name()=="orb of destruction"
					or mo:name()=="battlesphere" and prompt_orb_battlesphere(x,y))
			then
				orb_near=true
				break
			end
		end
	end
	if not(orb_near) or crawl.yesno("Really cast Orb of Destruction?",true,"n") then
		crawl.sendkeys("YM")
	else
		crawl.mpr("ok then.",2)
	end
end
function prompt_orb_battlesphere(x0,y0)
	local mo=nil
	local orb_near=false
	for x=-1,1 do
		for y=-1,1 do
			mo=monster.get_monster_at(x0+x,y0+y)
			if not(mo==nil) and mo:name()=="orb of destruction" then
				orb_near=true
				break
			end
		end
	end
	return orb_near
end
----------------------------------------------------------------------------------------------------------------
--unused, delete?
local autopickup_gold=true
crawl.setopt("autopickup = $?!+\"/")
		--crawl.setopt("autopickup_exceptions += gold piece")
		--crawl.setopt("autopickup_exceptions -= 1 then
			--crawl.sendkeys("V"..items.index_to_letter(items.equipped_at(0).slot))
			--crawl.do_commands({"CMD_EVOKE_WIELDED"})
			--crawl.do_commands({"CMD_PRIMARY_ATTACK"})
			attack_ignore_inscription()
		elseif false then
		--elseif items.fired_item() and items.fired_item().is_throwable then
			crawl.sendkeys("F\13")
			--crawl.do_commands({"CMD_EVOKE_WIELDED"})
			--crawl.do_commands({"CMD_PRIMARY_ATTACK"})
		else
			attack_ignore_inscription()
		end
		
	end
end
local attack_ignore_inscription_undo = 0
function attack_ignore_inscription()
	local direction = ""
	if target_delta_to_cmd(d.x, d.y) then
		direction=get_command(target_delta_to_cmd(d.x, d.y))
		--echoall(direction)
	end
	local insc = get_command("CMD_INSCRIBE_ITEM")
	local v = get_command("CMD_PRIMARY_ATTACK")
	crawl.setopt("message_color += mute:inscri")
	crawl.setopt('message_color += mute:'..util.trim(items.index_to_letter(items.equipped_at(0).slot))..'.-.')
	if items.equipped_at(0).inscription:find("!a") then
		if items.equipped_at(0).inscription:find("!a!a") then
			crawl.sendkeys(insc..items.index_to_letter(items.equipped_at(0).slot).."\8\8\8\8\13"..v..direction..firemaybe)
		else
			crawl.sendkeys(insc..items.index_to_letter(items.equipped_at(0).slot).."\8\8\13"..v..direction..firemaybe)
		end
	else
		crawl.sendkeys(v..direction..firemaybe)
	end
	attack_ignore_inscription_undo = 2
end
function r_attack_ignore_inscription()
	if attack_ignore_inscription_undo==2 then
		local insc = get_command("CMD_INSCRIBE_ITEM")
		crawl.sendkeys(insc..items.index_to_letter(items.equipped_at(0).slot).."!a\13")
		attack_ignore_inscription_undo = 3
	elseif attack_ignore_inscription_undo==3 then
		attack_ignore_inscription_undo = 0
		crawl.setopt("message_color -= mute:inscri")
		crawl.setopt('message_color -= mute:'..util.trim(items.index_to_letter(items.equipped_at(0).slot))..'.-.')
	end
end
----------------------------------------------------------------------------------------------------------------
local last_thrown_letter --in the next function, is actually next thrown
function throw()
	used_spell=false
	used_throw=true
	--crawl.sendkeys("F")
	local last_thrown_exists=false
	
	--echoall(last_thrown_letter)
	for k,v in ipairs(items.inventory()) do
		if items.inventory()[k].is_throwable then
			--echoall(items.index_to_letter(items.inventory()[k].slot))
			if items.index_to_letter(items.inventory()[k].slot)==last_thrown_letter then
				crawl.mpr("+"..items.index_to_letter(items.inventory()[k].slot).."-"..items.inventory()[k]:name_coloured())
				last_thrown_exists=true
			else
				crawl.mpr("-"..items.index_to_letter(items.inventory()[k].slot).."-"..items.inventory()[k]:name_coloured())
			end
		end
	end
	crawl.mpr("throw what?",2)
	--local input=crawl.c_input_line()
	local input=crawl.getch()
	input=utf8char(input)
	--if input and #input==1 and ( input:match("%l") or input:match("%u") ) then
	if input:match("%l") or input:match("%u") then
		last_thrown_letter=input
		last_thrown_exists=true
	--elseif input==nil or #input>0 or last_thrown_letter==nil then
	elseif not(input=="\13") or last_thrown_letter==nil then
		crawl.mpr("...",2)
		return
	end
	if last_thrown_exists then
		crawl.sendkeys("F"..last_thrown_letter)
	else
		crawl.mpr("ammunition not found.",2)
	end
	 
end
----------------------------------------------------------------------------------------------------------------
--Y.\{216}
local repeat_spellvar = {}
repeat_spellvar.a=false
function repeat_spell()
	if used_spell then
		crawl.setopt("message_colour -= mute:Casting:")
		crawl.setopt("message_colour += mute:know that spell")
		crawl.setopt("message_colour += mute:kay. then")
		repeat_spellvar.a=true
		--repeat_spellvar.m=crawl.messages(1)
		crawl.sendkeys("Y\27")
	elseif used_throw then
		--crawl.sendkeys("F\13f")
		if
			last_thrown_letter
			and items.inslot(items.letter_to_index(last_thrown_letter))
			and items.inslot(items.letter_to_index(last_thrown_letter)).is_throwable
		then
			crawl.sendkeys("F"..last_thrown_letter.."f")
		else
			crawl.mpr("ammunition not found.",2)
			crawl.more()
		end
	else
		evoke_prompt()
		crawl.sendkeys("f")
		--crawl.process_keys("f")
	end
end
function r_repeat_spell()
	
	if repeat_spellvar.a then
		local msg=crawl.messages(1)
				--crawl.mpr("f"..msg)
		--crawl.mpr("R"..crawl.trim(repeat_spellvar.m))
		crawl.setopt("message_colour += mute:Casting:")
		crawl.setopt("message_colour -= mute:know that spell")
		crawl.setopt("message_colour -= mute:kay. then")
		if msg:match("Casting:")=="Casting:" then
			msg=msg:gsub("Casting: ","")
			msg=msg:gsub(" %(.+","")
			if spells.dir_or_target(msg) then
				--crawl.mpr("f")
				--if msg=="Searing Ray" then
					--crawl.sendkeys(get_command("CMD_WAIT"))
				--else
					crawl.sendkeys("Y.!")
				--end
			else
				
				--if utf8char(crawl.getch())=="d" then
				if
					msg=="Shatter"
					or msg=="Foxfire"
					or msg=="Starburst"
					or utf8char(crawl.getch())=="f"
				then
					crawl.sendkeys("Y\13")
				end
			end
		end
		repeat_spellvar.a=false
	end
		
end
----------------------------------------------------------------------------------------------------------------
function cmsg_attack_noprompt(msg, ch)
	if 
		msg:match("eally attack near your battlesphere%?")
		or msg:match("eally attack near your spellforged servitor%?")
		or msg:match("eally attack near your spellforged servitor and battlesphere%?")
		or msg:match("eally attack near your battlesphere and spellforged servitor%?")
	then
		if not(cmsg_sending) then
			cmsg_sending=true
			
			crawl.sendkeys("Y")
			
			cmsg_sending=false
		end
	end
end
----------------------------------------------------------------------------------------------------------------
--if c_persist.branches==nil then
	--c_persist.branches={}
	--c_persist.branches[you.name()]={}
--else
--if c_persist.branches[you.name()]==nil then
	--c_persist.branches[you.name()]={}
--end end
--local branches = c_persist.branches[you.name()]
local branches = {}
function r_annotate_branchend()
	--except branches with just 2 floors
	if
		not(branches[you.branch()])
		and you.depth()==travel.find_deepest_explored(you.branch())
	then
		if you.depth()==1 then
			branches[you.branch()]=0 --just entered new branch
		else
			branches[you.branch()]=-1
			--this value means, first time visiting the latest branch level since reload
			
			--otherwise, it will be deepest explored depth of the branch before this turn
			--or nil, if you haven't reached the latest branch level since reload
			
			--if you reloaded while still on first lvl of branch, it will think you just entered it
			--to fix that, you would need to assign branches[x]=deepest for all branches when loading, or use c_persist, or maybe just you.turns_on_level()
			--not needed atm
		end
	end
		
	if branches[you.branch()] and you.depth()>branches[you.branch()] then
	--you just went down further than before
		if you.depth()>1 and not(branches[you.branch()]==-1) then
		--skip depth=1 because you cant calculate the branchend
		--dont change annotations if you just reloaded
			local branchend=(you.depth()-1)/you.depth_fraction()+1	--nan if you.depth()==1
			if (you.depth()>branchend-1.5 and you.depth()!\13")--annotate next level
			elseif you.depth()>branchend-0.5 then
				crawl.sendkeys("!.\8\8\8\8\8\8\8\8\8\8\13")--delete annotation of this lvl
			end
		end
		branches[you.branch()]=math.max(travel.find_deepest_explored(you.branch()), you.depth())--c_persist.branches[you.name()][you.branch()]=
	end
end
----------------------------------------------------------------------------------------------------------------
function krepeat()
	--crawl.sendkeys("`") --just repeats the macro instead of the previous action, looping forever
end
----------------------------------------------------------------------------------------------------------------
local safety_on = 0
local safety_time = 0
function r_safety_precaution()
	local hp, mhp = you.hp()
	if hpsafety_time then
			crawl.mpr("calling crawl.delay for 15 seconds.")
			if crawl.messages(1):match("crawl.delay") then
				crawl.delay(15000)
				crawl.mpr("...")
			end
			safety_time=you.time()
		end
	else
		safety_on=0
	end
end
---------------------------------------------------------------------------------------------------------------------------------------------------------
-- globals.lua
-- show all global variables
local seen={}
function dump(t,i,dontclear,start,limit)
	
	seen[t]=true
	local s={}
	local n=0
	for k in pairs(t) do
		n=n+1 s[n]=k
	end
	table.sort(s)
	for k,v in ipairs(s) do
		if ( not(start) or k>=start ) and ( not(limit) or k
################################################################################################################
#############
#todo list:
#transfer most r_ functions to use r_td instead
#change td_autopickup to use r_td
#make a retreat_rest function? go to nearest upstair, but abort if halfway healed, or rest there until the way back would heal you, then go back.
#make 1-radius exclusions at the explore horizon?
#remove usage of attack_ignore_inscription eventually
#add a priority distinction for r_td?
#make everything independent of my bindkeys
#add a notrested(), which returns nil or a table of reasons
#interrupt ctrl_explore when miscast during xsummon
#exclude traps?
#button to check if exploration is done? might be explore+noninstantsetting+keyinterrupt
#document settings assumed/overwritten by lua
#modularize the functions and document dependencies
#ß\{223} ^H\{8} ^Ö \{150}\{246}   ^J\{10} ^L\{12} ^K\{11}  ^Ä \{132}\{228}error ^Ü \{156} ^s 19
macros += M \{19} ===macro_save_now
macros += M S ===macro_save
#macros += M \{11} ===toggle_move_careful_on
macros += M \{11} ===show_enemy_beam_path
#macros += M H ===rest_until
#macros += M \{8} ===rest_until_restore_equip
macros += M \{8} ===toggle_togglable_rest
macros += M H ===rest_until_restore_equip
#macros += M \{246} ===explore_simpler
macros += M \{246} ===explore_chk_and_summon_toggle
#macros += M \{246} ===togglable_explore
#just_explore
macros += M \{10} ===k_rest_for
#macros += M q ===debuggg
macros += M \{12} ===remindMe
macros += M \{223} ===wiz_spell_costs
macros += M ] ===sif_spells_test
macros += M v ===evoke_prompt
macros += M \{248} ===toggle_warn_more_monsters
#^B\{2}
macros += M B ===throw
#macros += M ¹ 
#^8
macros += M \{-40} ===wait_ring
#^9
macros += M \{-39} ===wait_ring2
#^7
macros += M \{-41} ===wait_weapon
#^8
macros += M 8 ===wait_ring
#^9
macros += M 9 ===wait_ring2
#^7
macros += M 7 ===wait_weapon
#macros += M 9 ===super_rest
#macros += M 8 ===super_rest
#"K:"  default,
#"K1:" level-map,
#"K2:" targeting or
#"K3:" confirmation.
#ö 246          =x-61-74  => x-61=320
#ä 228          =x-61-92  => x-61=320
#ü x-61-68=252
#Ö 214
#Ä 196
#Ü 220
#W 23
#esc 27
#tab 9
#F8 - F9
macros += K \{-1073741889} =
macros += K \{-1073741890} =
macros += K \{-272} =
macros += K \{-273} =
macros += K - <
macros += K _ >
#macros += K - -
#macros += K _ _
#bindkey = [-] CMD_GO_UPSTAIRS
#bindkey = [_] CMD_GO_DOWNSTAIRS
#macros += K < -
#macros += K > _
#f11,12
macros += K \{-1073741892} -
macros += K \{-1073741893} _
macros += K \{-275} -
macros += K \{-276} _
#shaltgr-,altgr-
macros += K \{8212} -
macros += K \{8211} _
macros += K1 - <
macros += K1 _ >
#macros += K1 < -
#macros += K1 > _
macros += K1 < <
macros += K1 > >
macros += K1 n ]
macros += K1 y [
macros += K1 \{246} v
macros += K1 q \{23}
#why was this vvv commented out?
macros += K2 f !
#! dont't stop at target, @ stop, both ignore range
macros += K2 t @
#space as esc in targeting
macros += K2 \{32} \{27}
macros += K2 \{228} \{27}
macros += K2 \{246} +
macros += K2 x !\{1000}
#hopefully not actually a key at 1000
macros += M \{1000} ===remindMe
macros += K3 y Y
#doesnt seem to work -.-
macros += M # '
macros += M ' #
macros += M + =s!
#macros += M H 5
#macros += M H ===rest_with_prompt
#enter \{13}
#happens to be ^M as well
macros += M \{13} p
#macros += M p ===rest_with_prompt
macros += M p ===togglable_rest
#ä
#macros += M \{228} N!
macros += K \{228} `
macros += M z Y*!
macros += M a YH
macros += M s YJ
macros += M d YK
macros += M f YL
#macros += M x YX now M
macros += M x ===prompt_orb
macros += M A yh
macros += M S yj
macros += M D yk
macros += M F yl
macros += M X ym
#altgrF
macros += M \{273} F
macros += M E EA
#macros += M y Y*
#macros += M N D
macros += M y n
macros += M n Y*
macros += M Y D
macros += M N ===bad_key
#macros += M B A
#for nagas?^B\{2}, used to be B
macros += M \{2} ag
#macros += M Y a
#macros += M Y Vc
#place crystal ball at c
#no more ball
#macros += M Y ===use_ball
#macros += M b v
macros += M b a
#Ü
macros += M \{220} =i
#tab
#macros += M \{9} *
#no more hunger
#macros += M D e
#macros += M D n #see spellmacros
macros += M k k!
macros += M * N
#mouse
#ctrl u to altgr u
macros += M \{21} \{8595}
macros += M \{8595} ===rest_for_turn
#ctrl p to altgr p
macros += M \{16} \{254} 
macros += M \{254} ===k_rest_for
#fixing mouse clearing more()  not
#macros += M \{-9992} ===bad_key
#macros += K \{-9999} ==bad_key
#tab to shift-tab
#macros += M \{9} \{-233}
#macros += M \{-233} \{9}
macros += M \{9} h
macros += M \{-233} ===rest_for_turn
#macros += M e ===just_explore
#macros += M e ===explore_simpler
macros += M e ===togglable_explore
########left numbers  p ü+ ä enter   uoÖ 789ß
#                     2 1                345
#                  F       4 3       12     5
#   				  "  Z             §
#^1 ü
macros += M 1 \{252}
#macros += M  \{-15} \{252}
macros += M 2 ===togglable_rest
macros += M " ===rest_until_restore_equip
#local
##^2
macros += M \{-46} ===rest_with_prompt
##^3
#macros += M \{-45} ===toggle_togglable_rest
macros += M \{-45} ===toggle_togglable_explore
##^4
macros += M \{-44} ===toggle_rest_wait_percent
##^5
macros += M \{-43} ===toggle_travel_open_doors
##^6
macros += M \{-42} ===toggle_avoidapproach
#tiles
#^2
macros += M \{-14} ===rest_with_prompt
#^3
#macros += M \{-13} ===toggle_togglable_rest
macros += M \{-13} ===toggle_togglable_explore
#^4
macros += M \{-12} ===toggle_rest_wait_percent
#^5
macros += M \{-11} ===toggle_travel_open_doors
#^6
macros += M \{-10} ===toggle_avoidapproach
#macros += M 3 ===wait_weapon
#macros += M 4 ===wait_ring
#macros += M 5 ===wait_ring2
macros += M 3 ===explore_summon
macros += M 4 tr
macros += M 5 tt
#§ to Ö
macros += M \{167} \{214}
macros += M Z =s
#^Z
macros += M \{26} N
#^v to Ö
macros += M \{22} '
#F1-7
macros += M \{-1073741882} \{8595}
macros += M \{-1073741883} \{15}
macros += M \{-1073741884} ===rest_for_turn
macros += M \{-1073741885} ===k_rest_for
macros += M \{-1073741886} p
macros += M \{-1073741887} \\
macros += M \{-1073741888} \\-
macros += M \{-265} \{8595}
macros += M \{-266} \{15}
macros += M \{-267} ===rest_for_turn
macros += M \{-268} ===k_rest_for
macros += M \{-269} p
macros += M \{-270} \\
macros += M \{-271} \\-
##^o
#macros += M 1 \{15}
##^u 21
#macros += M 2 \{21}
#macros += M " ===switch_autopickup_gold
#macros += M 3 ===toggle_rest_wait_percent
#macros += M § ===toggle_rest_wait_percent
#macros += M 4 ===rest_until_restore_equip
#macros += M 5 ===rest_with_prompt
#12345 F1234  "§%
#æ 230
#bindkey = [æ] CMD_QUAFF
#macros += M 1 \{230}
#macros += M 1 \{-233}
#macros += M x ===rest_until
#` repeat
#bindkey = [q] CMD_PREV_CMD_AGAIN
#recast last used spell
#macros += M z ===repeat_spell
#macros += M x ===repeat_spell
macros += M c ===repeat_spell
#macros += M x ===bad_key
#macros += M q
#ü inventory
#macros += M w \{252}
#exploreenter
#rest
#macros += M r ===rest_with_prompt 
#macros += M t ===super_rest
########
#` repeat
#bindkey = [\{9}] CMD_PREV_CMD_AGAIN
##shifttab
#macros += M 1 \{-233}
##ü inventory
#macros += M 2 \{252}
##explore
#macros += M 3 ===just_explore
##rest
#macros += M 4 ===rest_with_prompt 
#macros += M 5 ===super_rest
###########
#disabling swing-only keys when not overwritten by bindkey
bindkey = [^H] CMD_NO_CMD_DEFAULT
bindkey = [^J] CMD_NO_CMD_DEFAULT
#bindkey = [^K] CMD_NO_CMD_DEFAULT
bindkey = [^L] CMD_NO_CMD_DEFAULT
bindkey = [^Y] CMD_NO_CMD_DEFAULT
bindkey = [^U] CMD_NO_CMD_DEFAULT
#bindkey = [^B] CMD_NO_CMD_DEFAULT
#bindkey = [^N] CMD_NO_CMD_DEFAULT
bindkey = [1] CMD_NO_CMD_DEFAULT
bindkey = [2] CMD_NO_CMD_DEFAULT
bindkey = [3] CMD_NO_CMD_DEFAULT
bindkey = [4] CMD_NO_CMD_DEFAULT
bindkey = [6] CMD_NO_CMD_DEFAULT
bindkey = [7] CMD_NO_CMD_DEFAULT
bindkey = [8] CMD_NO_CMD_DEFAULT
bindkey = [9] CMD_NO_CMD_DEFAULT
bindkey = [Ø] CMD_TARGET_SELECT_FORCE
bindkey = [ł] CMD_MAP_ANNOTATE_LEVEL
bindkey = [n] CMD_TARGET_CANCEL
#https://github.com/crawl/crawl/blob/master/crawl-ref/source/command-type.h
bindkey = [h] CMD_WAIT
bindkey = [j] CMD_MOVE_LEFT
bindkey = [,] CMD_MOVE_DOWN
bindkey = [i] CMD_MOVE_UP
bindkey = [l] CMD_MOVE_RIGHT
bindkey = [u] CMD_MOVE_UP_LEFT
bindkey = [o] CMD_MOVE_UP_RIGHT
bindkey = [m] CMD_MOVE_DOWN_LEFT
bindkey = [.] CMD_MOVE_DOWN_RIGHT
bindkey = [J] CMD_RUN_LEFT
bindkey = [;] CMD_RUN_DOWN
bindkey = [I] CMD_RUN_UP
bindkey = [L] CMD_RUN_RIGHT
bindkey = [U] CMD_RUN_UP_LEFT
bindkey = [O] CMD_RUN_UP_RIGHT
bindkey = [M] CMD_RUN_DOWN_LEFT
bindkey = [:] CMD_RUN_DOWN_RIGHT
bindkey = [j] CMD_TARGET_LEFT
bindkey = [,] CMD_TARGET_DOWN
bindkey = [i] CMD_TARGET_UP
bindkey = [l] CMD_TARGET_RIGHT
bindkey = [u] CMD_TARGET_UP_LEFT
bindkey = [o] CMD_TARGET_UP_RIGHT
bindkey = [m] CMD_TARGET_DOWN_LEFT
bindkey = [.] CMD_TARGET_DOWN_RIGHT
bindkey = [J] CMD_TARGET_DIR_LEFT
bindkey = [;] CMD_TARGET_DIR_DOWN
bindkey = [I] CMD_TARGET_DIR_UP
bindkey = [L] CMD_TARGET_DIR_RIGHT
bindkey = [U] CMD_TARGET_DIR_UP_LEFT
bindkey = [O] CMD_TARGET_DIR_UP_RIGHT
bindkey = [M] CMD_TARGET_DIR_DOWN_LEFT
bindkey = [:] CMD_TARGET_DIR_DOWN_RIGHT
bindkey = [j] CMD_MAP_MOVE_LEFT
bindkey = [,] CMD_MAP_MOVE_DOWN
bindkey = [i] CMD_MAP_MOVE_UP
bindkey = [l] CMD_MAP_MOVE_RIGHT
bindkey = [u] CMD_MAP_MOVE_UP_LEFT
bindkey = [o] CMD_MAP_MOVE_UP_RIGHT
bindkey = [m] CMD_MAP_MOVE_DOWN_LEFT
bindkey = [.] CMD_MAP_MOVE_DOWN_RIGHT
bindkey = [J] CMD_MAP_JUMP_LEFT
bindkey = [;] CMD_MAP_JUMP_DOWN
bindkey = [I] CMD_MAP_JUMP_UP
bindkey = [L] CMD_MAP_JUMP_RIGHT
bindkey = [U] CMD_MAP_JUMP_UP_LEFT
bindkey = [O] CMD_MAP_JUMP_UP_RIGHT
bindkey = [M] CMD_MAP_JUMP_DOWN_LEFT
bindkey = [:] CMD_MAP_JUMP_DOWN_RIGHT
bindkey = [p] CMD_MAP_ADD_WAYPOINT
bindkey = [a] CMD_MAP_EXPLORE
bindkey = [k] CMD_MAP_FIND_YOU
bindkey = [s] CMD_MAP_FIND_YOU
bindkey = [w] CMD_MAP_GOTO_TARGET
bindkey = [3] CMD_MAP_GOTO_TARGET
macros += K1 3 w
#macros += K1 w e
bindkey = [r] CMD_MAP_EXCLUDE_AREA
bindkey = [q] CMD_MAP_EXIT_MAP
#bindkey = [b] CMD_EXPLORE
#bindkey = [B] CMD_OPEN_DOOR
#bindkey = [h] CMD_DISPLAY_INVENTORY
#bindkey = [h] CMD_MAP_FIND_STASH
#bindkey = [H] CMD_DISPLAY_SPELLS
#bindkey = [y] CMD_DISPLAY_RELIGION
#bindkey = [Y] CMD_MAKE_NOTE
#bindkey = [n] CMD_DISPLAY_SKILLS
#bindkey = [N] CMD_MEMORISE_SPELL
bindkey = [b] CMD_EXPLORE
bindkey = [B] CMD_OPEN_DOOR
bindkey = [ü] CMD_DISPLAY_INVENTORY
bindkey = [ü] CMD_MAP_FIND_STASH
bindkey = [N] CMD_DISPLAY_SPELLS
bindkey = [þ] CMD_DISPLAY_RELIGION
bindkey = [Ö] CMD_REPLAY_MESSAGES
bindkey = [^N] CMD_MAKE_NOTE
bindkey = [p] CMD_DISPLAY_SKILLS
bindkey = [Ä] CMD_MEMORISE_SPELL
bindkey = [^X] CMD_LOOK_AROUND
bindkey = [K] CMD_DISPLAY_MAP
#bindkey = [] CMD_INTERLEVEL_TRAVEL
bindkey = [g] CMD_PICKUP
bindkey = [n] CMD_DROP
#bindkey = [N] CMD_NO_CMD_DEFAULT to spells for makro
bindkey = [z] CMD_NO_CMD_DEFAULT
bindkey = [Z] CMD_NO_CMD_DEFAULT
bindkey = [y] CMD_CAST_SPELL
bindkey = [Y] CMD_FORCE_CAST_SPELL
#altgr u
bindkey = [↓] CMD_RESISTS_SCREEN
bindkey = [k] CMD_FULL_VIEW
bindkey = [^B] CMD_FIRE
#CMD_FIRE_ITEM_NO_QUIVER
bindkey = [k] CMD_TARGET_TOGGLE_BEAM
bindkey = [ł] CMD_LUA_CONSOLE
#small_more = true
more := force_more_message 
stop := runrest_stop_message
ignore := runrest_ignore_message
stop += prompt:\?, danger:., warning:., monster_warning:.
#stop ^= sound:.
#done by lua now:
#force_more_message += into view, too close, being watched by
#force_more_message += into view, being watched by
#force_more_message += being watched by
#force_more_message += into view
#force_more_message += out of view
#force_more_message += deactivating autopickup
#force_more_message+=autopickup is now off
#timed portals
#more += timed_portal:^\W*(\b(\w\w\w\w\w\w+|\w\w?\w?\w?|([^H\W]..|H[^u\W].|Hu[^r\W])\w\w)\b\W*)+$, vibrate strangely
more += timed_portal:yellow, vibrate strangely
runrest_stop_message ^= timed_portal:., vibrate strangely
#force_more_message += increases to level, levels and is now at level
#flash_screen_message += increases to level, levels and is now at level
#done by c_msg now
#force_more_message += finished your manual
#flash_screen_message += finished your manual
# Dangerous weapons, handled by wmm_monsters()
#flash_screen_message += is wielding.*distortion
## dancing weapons require special handling...
#flash_screen_message += there is a.*distortion
#flash_screen_message += of distortion comes into view
#
#flash_screen_message += carrying a wand of
#flash_screen_message += wielding .* of distortion
##force_more_message += (?!.*(Here|Aim):)^.*wielding.*of distortion
#removing default made redundant by move_careful
force_more_message -= Marking area around .* as unsafe
more += [Yy]ou sense a monster nearby
more += magic feels tainted
more += lose access to your magic
more += [Yy]ou miscast
stop ^= [Yy]ou miscast
#more += [Nn]othing appears to happen
#stop ^= [Nn]othing appears to happen
force_more_message += You cannot blink
force_more_message += Your stasis prevents you from teleporting
# Interrupts from gammafunk.rc
more += You don't .* that spell
more += You fail to use your ability
more += You miscast.*(Blink|Borgnjor|Door|Invisibility)
more += You can't (read|drink|do)
more += You cannot .* while unable to breathe
more += You cannot .* in your current state
more += when .*silenced
more += too confused
more += There's something in the way
more += There's nothing to (close|open) nearby
more += not good enough to have a special ability
more += You are too berserk
more += no means to grasp
more += That item cannot be evoked
more += You are held in a net
more += You don't have any such object
more += You can't unwield
more += enough magic points
more += You don't have the energy to cast that spell
more += You are unable to access your magic
#debuffs
#force_more_message += contaminate
force_more_message += You become entangled
more += You are held in a net
more += calcifying dust hits you\W
more += floating eye.s view
more += floating eye seems to glare
more += floating eye gazes
#traps
force_more_message += ou hear a loud .Zot.
force_more_message += Your surroundings
# suddenly seem different.
force_more_message += wrath finds you
more += You are.*confused
# Bad things, gammafunk.rc
more += Your surroundings flicker
more += You cannot teleport right now
more += A sentinel's mark forms upon you
more += (blundered into a|invokes the power of) Zot
more += enter a teleport trap
more += Ouch! That really hurt!
#more += dispelling energy hits you
more += You are blasted by holy energy!
more += You are (blasted|electrocuted)!
#more += You are.*(confused|poisoned)
more += god:(sends|finds|silent|anger)
more += You feel a surge of divine spite
more += disloyal to dabble
more += lose consciousness
more += You are too injured to fight blindly
#more += calcifying dust hits
more += Space warps.*around you
more += Space bends around you
#more += watched by something #done by lua
#more += flickers and vanishes! #l
more += doesn't seem very happy
more += is no longer charmed
# Hell effects
more += hell_effect:
#buffs running out
more += finish channelling
force_more_message += Your divine stamina fades away.
force_more_message += Your ring of flames is guttering out
more += You feel less protected from missiles
#more += dispelling energy hits you
force_more_message += Your magical effects are unravelling
# Expiring effects, gammafunk
#more += You feel yourself slow down #l
more += You are starting to lose your buoyancy
more += Your hearing returns
more += Your transformation is almost over
more += You have a feeling this form
more += You feel yourself come back to life
more += time is quickly running out
more += life is in your own hands
more += You start to feel a little slower
force_more_message -= You have reached level
force_more_message += You have reached level 2
force_more_message += You have reached level 3
force_more_message += You have reached level 4
force_more_message += You have reached level 5
force_more_message += You have reached level 26
# Others, gfunk
#more += You have reached level
more += You rejoin the land of the living
#more += You have finished (your manual|forgetting about)
more += You have finished forgetting about
more += Your scales start
more += You feel monstrous
more += Jiyva alters your body
: if you.god() == "Xom" then
more += god:
: end
:if you.god() == "Xom" then
stop += god:
:else
ignore += god:
:end
# Bad things
stop ^= A huge blade swings out and slices into you
stop ^= starving
stop ^= wrath finds you
stop ^= lose consciousness
stop ^= hell_effect:
# Expiring effects
stop ^= You feel yourself slow down
stop ^= You are starting to lose your buoyancy
stop ^= Your hearing returns
stop ^= Your transformation is almost over
stop ^= back to life
stop ^= time is quickly running out
stop ^= life is in your own hands
stop ^= is no longer charmed
ability_slot += Fly|flight:lF
ability_slot += Stop Flying:L
ability_slot += Breathe:t
ability_slot += Invisibility:iv
# Abilities prone to miskeys.
ability_slot += Blink:IB
ability_slot += Berserk:k
ability_slot += Corrupt:C
ability_slot += Enter the Abyss:E
######################################
confirm_action += [Ss]ilence
force_spell_targeter += silence
force_more_message += eally cast .ilence
#force_more_message += magical contamination has completely faded away
#for vampire
runrest_ignore_message ^= very thirsty, almost devoid of blood, You feel devoid of blood, blood rots away, blood rot away
rest_wait_both = true
#runrest_ignore_message ^= HP
#runrest_ignore_message ^= magical contamination|(magic) 
#runrest_ignore_message ^= magic(?!al contamination)
#runrest_ignore_message ^= magic
#flash_screen_message += (?!foo)^.*bar
#contam
#runrest_stop_message ^= magical contamination
flash_screen_message += There is something invisible around
message_colour += yellow:There is something invisible around
#done by c_msg
#more += You feel yourself slow down
#flash_screen_message += You feel yourself slow down
message_colour += magenta:You feel yourself slow down
flash_screen_message +=you feeling lethargic
message_colour += magenta:you feeling lethargic
runrest_stop_message ^= gateway leading out appears
runrest_stop_message ^= ound a gateway leading out
runrest_stop_message ^= pressed. stopping travel
message_colour += mute:Cast which spell
message_colour += mute:Press: . . help. Shift.Dir
message_colour += mute:Press: . . help. Dir . move target cursor
message_colour += mute:Casting:
message_colour += mute:Confirm with . or Enter. or press . or . to list all spells
message_colour += mute:Your battlesphere fires
message_colour += mute:fulminant prism comes into view
#^TD? make safer for future enemies conjuring prisms
message_colour += mute:Press: . . help. Dir . move target
message_colour += mute:^Aiming\:
message_colour += mute:^Reach\:
message_colour += mute:^Shoot\:
message_colour += mute:^Attack\:
message_colour += mute:^Hit\:
message_color += mute:t -\s[A-Z][a-z]+!
message_color += mute:.rders for allies
message_color += mute:r...Retreat.*s...Stop.attacking
message_color += mute:g...Guard the area.*f...Follow.me
message_color += mute:(a|A)nything.else...Cancel
channel.sound = lightgreen
message_colour += lightgreen:You feel a bit more experienced
message_colour += cyan:battlesphere wa, cyan:battlesphere expends
#rest_wait_percent = 98
#set by lua
cloud_status = true
#confirm_action += ^Blink,
#auto_butcher = true
#confirm_butcher = never
#auto_eat_chunks = true
#explore_auto_rest = true
default_manual_training = true
#clear_messages = true
show_more = false
dump_message_count = 100
note_all_skill_levels = true
#online defaults
travel_delay = -1
rest_delay = -1
show_travel_trail = true
#travel_delay = 1
#show_travel_trail = false
runrest_stop_message ^= .omething.?.?.?.?.?.?.?.?.?.?.?.?.?.?.?.? misses you\.
runrest_stop_message ^= .omething enters a
runrest_stop_message ^= .omething sets off the alarm
runrest_stop_message ^= .omething launches a net
runrest_stop_message ^= You feel you are being watched by something
runrest_stop_message ^= .omething ?\w* \w+ your
runrest_stop_message ^= appears from out of your range of vision
runrest_stop_message ^= [Yy]our .+ resists
runrest_stop_message ^= reminder
#runrest_stop_message ^= your.* disappears in a puff of smoke
message_colour ^= cyan:your.* disappears in a puff of smoke
runrest_stop_message ^= battlesphere wavers
#tile_layout_priority = abilities, commands, inventory, memorisation, minimap, monsters, navigation, skills, spells, system commands
tile_layout_priority = monsters, minimap
#item_slot ^= (weapon|staff|ring|missle):-abcdefghijklmnopqrstuvwxyz
#item_slot += (weapon|staff|ring):-abcdefghijklmnopqrstuvwxyz
item_slot += potions? of lig:t
item_slot += potions? of cur:C
item_slot += potions? of magic:G
item_slot += potions? of ambros:A
item_slot += potions? of brill:B
item_slot += potions? of cancel:X
item_slot += potions? of hast:Q
item_slot += potions? of heal w:W
item_slot += potions? of invis:V
item_slot += potions? of resis:R
item_slot += scrolls? of blinking:K
item_slot += scrolls? of fear:J
item_slot += scrolls? of fog:O
item_slot += scrolls? of id:y
item_slot += scrolls? of pois:P
item_slot += scrolls? of torm:H
item_slot += scrolls? of magic map:M
item_slot += scrolls? of sil:I
item_slot += scrolls? of sum:U
item_slot += scrolls? of butter:U
item_slot += scrolls? of tel:N
#defglstyz
#abcdefghijklmnopqrsuvwxz
item_slot += wand of acid:j
item_slot += wand of quicks:j
item_slot += wand of light:j
item_slot += wand of charm:s
item_slot += wand of para:s
item_slot += wand of dig:d
item_slot += wand of flame:p
item_slot += wand of mindb:w
item_slot += wand of poly:r
item_slot += wand of iceb:o
#defstyz
#abquv
item_slot += scrolls? of vuln:L
#item_slot += scrolls? of amn:x
#item_slot += scrolls? of enchant arm:e
#item_slot += scrolls? of acqu:c
#item_slot += scrolls? of brand:g
#item_slot += scrolls? of enchant weap:z
item_slot += scrolls? of immo:f
#item_slot += scrolls? of noise:s
#item_slot += potions? of degen:d
item_slot += potions? of att:i
item_slot += potions? of flight:l
item_slot += potions? of might:m
item_slot += potions? of beserk:k
#item_slot += potions? of mut:n
#item_slot += potions? of exp:h
#TD no looksmth
item_slot += ((?potions? of might
#autopickup_exceptions ^= >potions? of degeneration
#autopickup_exceptions ^= >useless
ai := autoinscribe
autoinscribe += datura:!f
#autoinscribe += magical power:!R
autoinscribe += MP\+:!R!T!w
autoinscribe += potions? of resis:rElec rC+ rF+ rCorr rPois
autoinscribe += weapon:!a
ai += potions? of berserk rage:!q
ai += scrolls? of silence:!r
tile_tooltip_ms = 0
## Pickup aux armour you haven't found yet.
## Also picks up ego/artefact aux armour if you can wear it.
## Doesn't pick up shields or body armour.
{
local function autopickup(it, name)
	if it.is_useless then return false end
	
	local class  = it.class(true)
	if class == "armour" then
		local good_slots = {cloak="Cloak", helmet="Helmet",
							gloves="Gloves", boots="Boots"}
		st, _ = it.subtype()
		if good_slots[st] ~= nil and items.equipped_at(good_slots[st]) == nil then
			return true
		--elseif st ~= "body" and st ~= "shield" and (it.artefact or it.branded) then return true
		end 
	end
	--crawl.mpr(it:class().." "..(it:subtype() or ""))
	--crawl.mpr("<"..it:name_coloured())
	return nil
end
add_autopickup_func(autopickup)
}
#tile_full_screen = true
#buggy?
tile_window_width  = -90
tile_window_height = -90
tile_full_screen = false
tile_skip_title = true
#msg_min_height = 6
monster_item_view_coordinates = true
action_panel_filter -= attraction
explore_greedy_visit = artefacts
#,glowing_items
#explore_greedy_visit = asdf
#explore_greedy_visit -= asdf
#explore_greedy_visit -= glowing_items
explore_greedy_visit -= stacks
explore_stop += greedy_pickup
explore_stop -= greedy_pickup_smart
#explore_greedy=false
#show_more = true
:if tonumber(crawl.version("major"))>.26 then
#default 3
#fail_severity_to_confirm = 3
:crawl.setopt("fail_severity_to_confirm = 4")
:end
tile_viewport_scale = 1.0
#tile_map_scale = 0.5
tile_map_scale = 0.75
tile_level_map_hide_messages = false
tile_level_map_hide_sidebar = false
#explore_wall_bias = -1000
{
local turn_of_last_climb=0
function climbprompt(cmd)
	if
		turn_of_last_climb=({you.hp()})[2]*.5 )
		and ( cmd=="<" or rested(0.6) )
		or crawl.yesno("really climb?",true)
	then
		crawl.sendkeys(cmd)
		turn_of_last_climb=you.turns()+2 --processed before sendkeys, which takes 2 turns
	else
		crawl.mpr("ok, then.",2)
		turn_of_last_climb=0
	end
end
function climbup()
	climbprompt("<")
end
function climbdown()
	climbprompt(">")
end
}
macros += M < ===climbup
macros += M > ===climbdown
#interrupt_travel += full_mp
##tile_lava_col                = #552211
#tile_lava_col                = #440000
##tile_trap_col                = #aa6644
#tile_trap_col                = #aacc00
##tile_explore_horizon_col     = #6b301b
##tile_explore_horizon_col     = #6b301b
##feature += explore horizon {,,red,red,red,red,red}
#tile_display_mode=hybrid
#defaults
#tile_player_col              = white
#tile_monster_col             = #660000
#tile_neutral_col             = #660000
#tile_peaceful_col            = #664400
#tile_friendly_col            = #664400
#tile_plant_col               = #446633
#tile_item_col                = #005544
#tile_floor_col               = #333333
#tile_wall_col                = #666666
#tile_door_col                = #775544
#tile_explore_horizon_col     = #6b301b
#tile_unseen_col              = black
#tile_mapped_floor_col        = #222266
#tile_mapped_wall_col         = #444499
#tile_upstairs_col            = cyan
#tile_downstairs_col          = #ff00ff
#tile_branchstairs_col        = #ff7788
#tile_portal_col              = #ffdd00
#tile_transporter_col         = #0000ff
#tile_transporter_landing_col = #5200aa
#tile_feature_col             = #997700
#tile_trap_col                = #aa6644
#tile_water_col               = #114455
#tile_deep_water_col          = #001122
#tile_lava_col                = #552211
#tile_excluded_col            = #552266
#tile_excl_centre_col         = #552266
#tile_window_col              = #558855
#
#0f	1f		3f		7f		ff double the last category... delta of 1f*2^n
# 16	2d		5a		b4		between those for shift
#r					down branch
#m		tla	excl			trap
#my			
#ryy		lava	door	mon
# floor		wall	transp	player
#				mfl	mwl	horizon
#gy			
#cy				sea	wat		portal
#c			friend
#g		feat			plant	up
#no items
#almost invis: feat, tland
tile_player_col              = white
tile_monster_col             = #ffb400
tile_neutral_col             = #ffb400
tile_peaceful_col            = #1f3f3f
tile_friendly_col            = #1f3f3f
tile_plant_col               = #007f00
tile_item_col                = #1f1f1f
tile_floor_col               = #1f1f1f
tile_wall_col                = #3f3f3f
tile_door_col                = #7f5a00
tile_explore_horizon_col     = #b4b4ff
tile_unseen_col              = black
tile_mapped_floor_col        = #5a5aff
tile_mapped_wall_col         = #7f7fff
tile_upstairs_col            = #1fff1f
tile_downstairs_col          = #7f0000
tile_branchstairs_col        = #7f1f1f
tile_transporter_col         = #7f7f7f
tile_transporter_landing_col = #2d002d
tile_portal_col              = #7fffff
tile_feature_col             = #002d2d
tile_trap_col                = #ff00ff
tile_water_col               = #3f7fff
tile_deep_water_col          = #2d5aff
tile_lava_col                = #3f2d00
tile_excluded_col            = #3f003f
tile_excl_centre_col         = #3f003f
tile_window_col              = #558855
#https://github.com/crawl/crawl/blob/master/crawl-ref/source/rltiles/dc-mon.txt
#https://github.com/crawl/crawl/blob/master/crawl-ref/source/rltiles/dc-player.txt
#tile_player_tile = tile:MONS_SALAMANDER_MYSTIC
#tile_shield_offsets = 0,-8
:if not(you.race()=="Felid") then
#tile_player_tile = playermons
tile_player_tile = tile:MONS_SERVANT_OF_WHISPERS
#tile_player_tile = tile:MONS_WIZARD
#tile_player_tile = tile:MONS_SPRIGGAN_DEFENDER
:else
#tile_player_tile = playermons
:if tonumber(crawl.version("major"))<.31 then
tile_player_tile = tile:FELID_2
:else
:crawl.setopt("tile_player_tile = tile:FELID_SILLY")
:end
:end