summaryrefslogtreecommitdiff
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
parent7d264acf35b2899a16040690a1d248b2999617c9 (diff)
Import Killerbunnies patch: Two new automatizer rules types <inventory> and /equipment> for checking whether an object is in your inventory (equipment respectively).
-rw-r--r--changes.txt2
-rw-r--r--lib/core/auto.lua54
-rw-r--r--lib/core/xml.lua28
-rw-r--r--src/squeltch.c2
4 files changed, 86 insertions, 0 deletions
diff --git a/changes.txt b/changes.txt
index 071511e3..26e6e060 100644
--- a/changes.txt
+++ b/changes.txt
@@ -4,6 +4,8 @@ T.o.M.E 2.3.7 (ah)
may be both non-zero and invisible (to the player).
- Miscellaneous 64 bit fixes.
- Fix Lua errors when hitting <ESC> while choosing spell.
+- Killerbunnies: Automatizer: Add patch which adds new <inventory/>
+ and <equipment/> rules.
T.o.M.E 2.3.6 (ah)
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] .. ")")
diff --git a/src/squeltch.c b/src/squeltch.c
index cd52dc1a..c957fa38 100644
--- a/src/squeltch.c
+++ b/src/squeltch.c
@@ -155,6 +155,8 @@ static cptr types_list[] =
"level",
"skill",
"ability",
+ "inventory",
+ "equipment",
"comment",
NULL,
};