summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2012-06-09 21:34:30 +0200
committerBardur Arantsson <bardur@scientician.net>2012-06-09 22:02:48 +0200
commitabd9ab4c46bab7ccd3475a31b542873130682b81 (patch)
tree50f8644cd46f8e009cedd9275fa80a15f0476221 /src
parenta0107d942872735f1faa0e857174a6c467180d75 (diff)
Lua: Move "Drunk takes wine" code to C
Diffstat (limited to 'src')
-rw-r--r--src/cmd2.c6
-rw-r--r--src/modules.c41
-rw-r--r--src/types.h6
3 files changed, 52 insertions, 1 deletions
diff --git a/src/cmd2.c b/src/cmd2.c
index a2dcfa0a..7689f46a 100644
--- a/src/cmd2.c
+++ b/src/cmd2.c
@@ -5103,7 +5103,11 @@ void do_cmd_give()
/* Process hooks if there are any */
if (!process_hooks(HOOK_GIVE, "(d,d)", c_ptr->m_idx, item))
{
- msg_print("The monster does not want your item.");
+ hook_give_in in = { c_ptr->m_idx, item };
+ if (!process_hooks_new(HOOK_GIVE, &in, NULL))
+ {
+ msg_print("The monster does not want your item.");
+ }
}
/* Take a turn, even if the offer is declined */
diff --git a/src/modules.c b/src/modules.c
index ff8a24fb..bd2a1acb 100644
--- a/src/modules.c
+++ b/src/modules.c
@@ -513,8 +513,49 @@ static bool_ auto_stat_gain_hook(void *data, void *in, void *out)
return FALSE;
}
+static bool_ drunk_takes_wine(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("Singing, happy drunk")) &&
+ (o_ptr->tval == TV_FOOD) &&
+ ((o_ptr->sval == 38) ||
+ (o_ptr->sval == 39)))
+ {
+ cmsg_print(TERM_YELLOW, "'Hic!'");
+
+ /* Destroy item */
+ inc_stack_size_ex(in->item, -1, OPTIMIZE, NO_DESCRIBE);
+
+ /* Create empty bottle */
+ {
+ object_type forge;
+ object_prep(&forge, lookup_kind(TV_BOTTLE,1));
+ drop_near(&forge, 50, p_ptr->py, p_ptr->px);
+ return TRUE;
+ }
+ }
+ else
+ {
+ return FALSE;
+ }
+}
+
void init_hooks_module()
{
+ /*
+ * Common hooks
+ */
+ add_hook_new(HOOK_GIVE,
+ drunk_takes_wine,
+ "drunk_takes_wine",
+ NULL);
+
+ /*
+ * Module-specific hooks
+ */
switch (game_module_idx)
{
case MODULE_TOME:
diff --git a/src/types.h b/src/types.h
index 44ffd67a..ae1adcae 100644
--- a/src/types.h
+++ b/src/types.h
@@ -2287,6 +2287,12 @@ struct hook_identify_in {
identify_mode mode;
};
+typedef struct hook_give_in hook_give_in;
+struct hook_give_in {
+ int m_idx;
+ int item;
+};
+
/*
* Structure for the "quests"
*/