Viewing Issue Simple Details Jump to Notes ] Wiki ] View Advanced ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0005240 [DCSS] Patches trivial always 2012-01-20 06:52 2012-01-20 15:51
Reporter XuaXua View Status public  
Assigned To elliptic
Priority normal Resolution done  
Status closed   Product Branch 0.10 ancient branch
Summary 0005240: Cleaned up Autofight Lua
Description Consolidated two long and nearly identical methods to a utility method and re-ordered the top three elseifs for logic (put no target in view at top.

function hit_target(is_adjacent)
  local x, y, info = get_target()
  if info == nil then
    crawl.mpr("No target in view!")
  elseif you.confused() then
    crawl.mpr("You are too confused!")
  elseif hp_is_low() then
    crawl.mpr("You are too injured to fight blindly!")
  elseif info.can_hit == 3 then
    attack_fire(x,y)
  elseif info.can_hit == 2 then
    attack_melee(x,y)
  elseif info.can_hit == 1 then
    attack_reach(x,y)
  elseif is_adjacent then
    crawl.mpr("No target in range!")
  else
    move_towards(x,y)
  end
end

function hit_closest()
  hit_target(false)
end

function hit_adjacent()
  hit_target(true)
end


Not sure how to create a patch, so I just attached revised autofight.lua (tested, it works!).

This is in anticipation of my next autofight patch which will hopefully allow for a non-intrusive pause when a new enemy comes into view.
Additional Information
Tags No tags attached.
Attached Files ? file icon autofight.lua [^] (6,054 bytes) 2012-01-20 06:52
? file icon autofight_with_net.lua [^] (6,121 bytes) 2012-01-20 06:58
? file icon autofight_constrain.lua [^] (6,123 bytes) 2012-01-20 07:00

- Relationships

-  Notes
(0016759)
XuaXua (reporter)
2012-01-20 06:59

Seriously?

One version and someone actually CHANGED AUTOFIGHT.LUA to add some caught-in-net code?

ARGLE HARGLE BARGLE revised file uploaded.
(0016760)
XuaXua (reporter)
2012-01-20 07:01
edited on: 2012-01-20 07:01

also uploaded autofight_constrain.lua with a more generic message because does caught actually mean net always or can it mean caught by a naga or octopode or tentacle?

function hit_target(is_adjacent)
  local x, y, info = get_target()
  if info == nil then
    crawl.mpr("No target in view!")
  elseif you.caught() then
    crawl.mpr("You are too constrained!")
  elseif you.confused() then
    crawl.mpr("You are too confused!")
  elseif hp_is_low() then
    crawl.mpr("You are too injured to fight blindly!")
  elseif info.can_hit == 3 then
    attack_fire(x,y)
  elseif info.can_hit == 2 then
    attack_melee(x,y)
  elseif info.can_hit == 1 then
    attack_reach(x,y)
  elseif is_adjacent then
    crawl.mpr("No target in range!")
  else
    move_towards(x,y)
  end
end


(0016761)
elliptic (developer)
2012-01-20 07:37

I merged hit_closest and hit_adjacent as requested. The net message is correct as-is, since it doesn't have anything to do with constriction. And I'll need a reason to reorder the elseifs... I chose the current order consciously, because you always want to know whether you are confused if you don't realize it yet, even if no monsters are in sight.
(0016765)
XuaXua (reporter)
2012-01-20 15:51

That's fine. I went with the logical order considering "if you're pressing this key, you want to attack something you can see.

- Well, can't see anything, this key is useless.
- Well, you can see, but you're too confused (movement near danger is already neutered with a y/n prompt, so there's no harm anymore).
- Well, you are too to attack.
- Well, you are too hurt to attack
- ok attack

- Issue History
Date Modified Username Field Change
2012-01-20 06:52 XuaXua New Issue
2012-01-20 06:52 XuaXua File Added: autofight.lua
2012-01-20 06:58 XuaXua File Added: autofight_with_net.lua
2012-01-20 06:59 XuaXua Note Added: 0016759
2012-01-20 07:00 XuaXua File Added: autofight_constrain.lua
2012-01-20 07:01 XuaXua Note Added: 0016760
2012-01-20 07:01 XuaXua Note Edited: 0016760
2012-01-20 07:37 elliptic Note Added: 0016761
2012-01-20 07:37 elliptic Status new => resolved
2012-01-20 07:37 elliptic Fixed in Branch => 0.10 development branch
2012-01-20 07:37 elliptic Resolution open => done
2012-01-20 07:37 elliptic Assigned To => elliptic
2012-01-20 15:51 XuaXua Note Added: 0016765
2012-01-20 15:51 XuaXua Status resolved => closed


Mantis 1.1.8[^]
Copyright © 2000 - 2009 Mantis Group
Powered by Mantis Bugtracker