summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2012-06-09 22:01:58 +0200
committerBardur Arantsson <bardur@scientician.net>2012-06-09 22:03:47 +0200
commitf586b932a44f06bc17336cd8332bec43f17d3d88 (patch)
tree25425694afa1ff4558a68fe39c4d646f61d5d112
parentabd9ab4c46bab7ccd3475a31b542873130682b81 (diff)
Lua: Move "Hobbits like food" code to C
-rw-r--r--lib/mods/theme/scpt/misc.lua19
-rw-r--r--src/modules.c26
2 files changed, 26 insertions, 19 deletions
diff --git a/lib/mods/theme/scpt/misc.lua b/lib/mods/theme/scpt/misc.lua
index 21a81f83..3658b528 100644
--- a/lib/mods/theme/scpt/misc.lua
+++ b/lib/mods/theme/scpt/misc.lua
@@ -22,25 +22,6 @@ function longbottom_leaf(object)
end
add_hook_script(HOOK_EAT, "longbottom_leaf", "longbottom_leaf")
--- Hobbits like food
-function hobbit_food(m_idx, item)
-
- m_ptr = monster(m_idx)
- o_ptr = get_object(item)
-
- if (m_ptr.r_idx == test_monster_name("Scruffy-looking hobbit"))
- and (o_ptr.tval == TV_FOOD) then
- cmsg_print(TERM_YELLOW, "'Yum!'")
- inven_item_increase(item, -1)
- inven_item_optimize(item)
- return TRUE
- else
- return FALSE
- end
-end
-
-add_hook_script(HOOK_GIVE, "hobbit_food", "hobbit_food")
-
-- Smeagol likes rings
function smeagol_ring(m_idx, item)
diff --git a/src/modules.c b/src/modules.c
index bd2a1acb..6b476fd2 100644
--- a/src/modules.c
+++ b/src/modules.c
@@ -543,6 +543,27 @@ static bool_ drunk_takes_wine(void *data, void *in_, void *out)
}
}
+static bool_ hobbit_food(void *data, void *in_, void *out)
+{
+ hook_give_in *in = (hook_give_in *) in_;
+ monster_type *m_ptr = &m_list[in->m_idx];
+ object_type *o_ptr = get_object(in->item);
+
+ if ((m_ptr->r_idx == test_monster_name("Scruffy-looking hobbit")) &&
+ (o_ptr->tval == TV_FOOD))
+ {
+ cmsg_print(TERM_YELLOW, "'Yum!'");
+
+ inc_stack_size_ex(in->item, -1, OPTIMIZE, NO_DESCRIBE);
+
+ return TRUE;
+ }
+ else
+ {
+ return FALSE;
+ }
+}
+
void init_hooks_module()
{
/*
@@ -570,6 +591,11 @@ void init_hooks_module()
"auto_stat_gain",
NULL);
+ add_hook_new(HOOK_GIVE,
+ hobbit_food,
+ "hobbit_food",
+ NULL);
+
break;
}