From e809d2fe548a0dad3c005fd3c7805446cefd138d Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 12 Jan 2010 08:27:55 +0100 Subject: Import Killerbunnies patch: Two new automatizer rules types and /equipment> for checking whether an object is in your inventory (equipment respectively). --- lib/core/auto.lua | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/core/xml.lua | 28 ++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) (limited to 'lib/core') 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(""..n.."") end, }, + ["inventory"] = + { + { + "Check is true if something in player's inventory matches", + "the contained rule", + }, + xml:collect([[...]]), + function () + return xml:collect("") + end, + }, + ["equipment"] = + { + { + "Check is true if something in player's equipment matches", + "the contained rule", + }, + xml:collect([[...]]), + function () + return xml:collect("") + 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] .. ")") -- cgit v1.2.3