summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2010-01-12 08:27:55 +0100
committerBardur Arantsson <bardur@scientician.net>2010-01-12 08:27:55 +0100
commite809d2fe548a0dad3c005fd3c7805446cefd138d (patch)
treea1a963aa9401614b26ce0c40887e6e6581aee00e /lib
parent7d264acf35b2899a16040690a1d248b2999617c9 (diff)
Import Killerbunnies patch: Two new automatizer rules types <inventory> and /equipment> for checking whether an object is in your inventory (equipment respectively).
Diffstat (limited to 'lib')
-rw-r--r--lib/core/auto.lua54
-rw-r--r--lib/core/xml.lua28
2 files changed, 82 insertions, 0 deletions
diff --git a/lib/core/auto.lua b/lib/core/auto.lua
index fa2457ff..ba613664 100644
--- a/lib/core/auto.lua
+++ b/lib/core/auto.lua
@@ -196,6 +196,38 @@ function gen_rule_fct(r)
f = gen_rule_fct(r[1])
end
return function(object) return not %f(object) end
+ elseif r.label == "inventory" then
+ local f
+ if not r[1] then
+ f = function(object) return end
+ else
+ f = gen_rule_fct(r[1])
+ end
+ return function(object)
+ local i = 0
+ while i < INVEN_WIELD do
+ if %f(player.inventory(i)) then
+ return TRUE
+ end
+ i = i + 1
+ end
+ end
+ elseif r.label == "equipment" then
+ local f
+ if not r[1] then
+ f = function(object) return end
+ else
+ f = gen_rule_fct(r[1])
+ end
+ return function(object)
+ local i = INVEN_WIELD
+ while i < INVEN_TOTAL do
+ if %f(player.inventory(i)) then
+ return TRUE
+ end
+ i = i + 1
+ end
+ end
elseif r.label == "name" then
return function(object) if strlower(object_desc(object, -1, 0)) == strlower(%r[1]) then return TRUE end end
elseif r.label == "contain" then
@@ -737,6 +769,28 @@ auto_aux.types_desc =
return xml:collect("<ability>"..n.."</ability>")
end,
},
+ ["inventory"] =
+ {
+ {
+ "Check is true if something in player's inventory matches",
+ "the contained rule",
+ },
+ xml:collect([[<inventory><foo1>...</foo1></inventory>]]),
+ function ()
+ return xml:collect("<inventory></inventory>")
+ end,
+ },
+ ["equipment"] =
+ {
+ {
+ "Check is true if something in player's equipment matches",
+ "the contained rule",
+ },
+ xml:collect([[<equipment><foo1>...</foo1></equipment>]]),
+ function ()
+ return xml:collect("<equipment></equipment>")
+ end,
+ },
}
function auto_aux:display_desc(sel)
diff --git a/lib/core/xml.lua b/lib/core/xml.lua
index f1188d51..14f0511f 100644
--- a/lib/core/xml.lua
+++ b/lib/core/xml.lua
@@ -173,6 +173,34 @@ function xml:english_xml(t, tab, not_flag)
nextlevel = tab
end
children_not_flag = not nil
+ elseif t.label == "inventory" then
+ if not_flag then
+ xml.write(TERM_WHITE, tab)
+ xml.write(ecol, "Nothing in your ")
+ xml.write(bcol, "inventory")
+ xml.write(ecol, " matches the following:")
+ xml.write(TERM_WHITE, "\n")
+ else
+ xml.write(TERM_WHITE, tab)
+ xml.write(ecol, "Something in your ")
+ xml.write(bcol, "inventory")
+ xml.write(ecol, " matches the following:")
+ xml.write(TERM_WHITE, "\n")
+ end
+ elseif t.label == "equipment" then
+ if not_flag then
+ xml.write(TERM_WHITE, tab)
+ xml.write(ecol, "Nothing in your ")
+ xml.write(bcol, "equipment")
+ xml.write(ecol, " matches the following:")
+ xml.write(TERM_WHITE, "\n")
+ else
+ xml.write(TERM_WHITE, tab)
+ xml.write(ecol, "Something in your ")
+ xml.write(bcol, "equipment")
+ xml.write(ecol, " matches the following:")
+ xml.write(TERM_WHITE, "\n")
+ end
elseif t.label == "comment" then
xml.write(TERM_WHITE, tab)
xml.write(TERM_WHITE, "(" .. t[1] .. ")")