Force_more on all "extremely dangerous" monsters?


Problems running or configuring the software, commands & options, compiling, different platforms, using the interface, documentation, etc.

Dungeon Dilettante

Posts: 3

Joined: Friday, 29th July 2016, 08:04

Post Tuesday, 2nd August 2016, 05:29

Force_more on all "extremely dangerous" monsters?

Is there a way to force a more message on all "extremely dangerous" (ie. red) monsters when they come into view? I know you can set it for individual monsters easily enough, but I'd like to set it for all red monsters since that is relative to your level.

Slime Squisher

Posts: 352

Joined: Monday, 14th December 2015, 00:43

Post Tuesday, 2nd August 2016, 09:49

Re: Force_more on all "extremely dangerous" monsters?

Okay, this should be doable but I don't have much experience with clua, so my first attempt was an utter failure and the second, while closer, didn't work either. I really don't have time for this right now, so let me just give you some pointers.

You want to alter force_more_message option; you can do it dynamically as evidenced by gammafunk's force_mores rc file. You need to check every monster in sight every turn; elliptic's qw does it by checking every square in sight then, if it's a monster, check its threat level and then act accordingly. Check those .rc files out, they're both on github.

Checking monsters in sight works like this:

  Code:
LOS = 7

function check_monsters_in_sight()
  local x, y
  local mons
  for x = -LOS, LOS do
    for y = -LOS, LOS do
      mons = monster.get_monster_at(x, y)
      if mons ~= nil then
        -- do something here!
      end
    end
  end
end


In this case, mons:name() will return the monster's name, mons:threat() will return its threat level as a number. 0 corresponds to dark grey/very low threat level, 1 to grey/low, 2 to yellow/high and 3 to red/very high.

Then you need to dynamically alter force_more_message option, you can use crawl.setopt for this. Example: crawl.setopt("force_more_message += your pattern goes here"). If you want to store your own data and make the game remember it, use c_persist class.

Slime Squisher

Posts: 352

Joined: Monday, 14th December 2015, 00:43

Post Tuesday, 2nd August 2016, 14:36

Re: Force_more on all "extremely dangerous" monsters?

Got a full script.

  Code:
{

-- line of sight radius
LOS = 7
-- add more prompt if a monster's threat level is equal or above this. 0 = very low/dark grey, 1 = low/grey, 2 = high/yellow, 3 = very high/red
THREAT_NOTIFICATION = 3

local threat_array = {}
-- switch to true if you want to see a debug message spam
local debug_messages = false

function debug_print(msg, condition)
  if debug_messages then
    if condition ~= nil and not condition then
      return
   else
      crawl.mpr(msg == nil and "nil" or msg)
   end
  end
end

function array_dump(array, for_options)
  local separator = for_options and "|" or ", "
  return table.concat(array, separator)
end

function array_find(array, item)
  for k,v in pairs(array) do
    if v == item then
     return k
   end
  end
  return 0
end

function init_threat_array()
  if c_persist.threat_array == nil then
    c_persist.threat_array = {}
  end
  debug_print("Old pattern: " .. array_dump(c_persist.threat_array, false))
  threat_array = c_persist.threat_array
end

function check_threat(mons)
  local name = mons:name()
  local threat = mons:threat()
  local index = array_find(threat_array, name)
  debug_print(name .. ", threat: " .. threat)
  if threat >= THREAT_NOTIFICATION then
   if index < 1 then                               -- if not found in threat list
     table.insert(threat_array, name)
     debug_print("added " .. name .. " to threats")
     crawl.more()                                  -- force more if the monster has just been added to threats
   end
  elseif threat < THREAT_NOTIFICATION then
    if index > 0 then
     table.remove(threat_array, index)
     debug_print("removed " .. name .. " from threats")
   end
  end
end

function check_monsters_in_sight()
  local x, y
  local mons
  for x = -LOS, LOS do
    for y = -LOS, LOS do
      mons = monster.get_monster_at(x, y)
      if mons ~= nil then
       check_threat(mons)
      end
    end
  end
end

function adjust_force_more()
  crawl.setopt("force_more_message -= (" .. array_dump(c_persist.threat_array, true)  .. ").*into view")
  if (#threat_array > 0) then
    crawl.setopt("force_more_message += (" .. array_dump(threat_array, true) .. ").*into view")
  end
  c_persist.threat_array = threat_array
  debug_print("New pattern: " .. array_dump(c_persist.threat_array))
end

function ready()
  init_threat_array()
  check_monsters_in_sight()
  adjust_force_more()
end

}


It works, I think. I only tested it on very early Dungeon levels, but it seems to add and remove threats correctly. It only reacts to "...comes into view" line, so each monster will trigger the more prompt only once, on the initial sighting. The bug where a removed threat (due to e.g. leveling up or loading a higher XL character) will trigger one additional more prompt on the next encounter might still be there or not, I'm not sure. The script also doesn't handle cases of polymorphed uniques so if you morph Blork into a wasp, "Blork the wasp" will not be removed until the next time you encounter Blork polymorphed into a wasp with a sufficiently high XL. Also, since the script uses c_persist, the threat array will be shared among all characters, but I *think* it should not be a problem. Anyway, if someone wants to improve it, feel free to.

Put this directly into your .rc file; if you already have something using ready() there, don't overwrite it, just add the ready() content from here to there and copy the rest of this code as-is. Same with the lua script brackets at the beginning and the end, if you have those already, you don't need another pair. Finally, to include lower levels of threats too, take a look at the THREAT_NOTIFICATION line and the comment above it.

For this message the author Leszczynek has received thanks: 3
any1, ddubois, Dungeoneer

Dungeon Dilettante

Posts: 3

Joined: Friday, 29th July 2016, 08:04

Post Wednesday, 3rd August 2016, 08:18

Re: Force_more on all "extremely dangerous" monsters?

Wow, that's a lot more involved than I was envisioning. I'll give it a try. You'd think this would be something that would be built into the game but I guess not. Nice work!

Return to Technical Support

Who is online

Users browsing this forum: No registered users and 25 guests

cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.