diff options
-rw-r--r-- | lib/mods/theme/scpt/drunk.lua | 21 | ||||
-rw-r--r-- | lib/mods/theme/scpt/init.lua | 1 | ||||
-rw-r--r-- | lib/mods/theme/scpt/misc.lua | 26 | ||||
-rw-r--r-- | lib/scpt/drunk.lua | 21 | ||||
-rw-r--r-- | lib/scpt/init.lua | 1 | ||||
-rw-r--r-- | src/cmd2.c | 6 | ||||
-rw-r--r-- | src/modules.c | 41 | ||||
-rw-r--r-- | src/types.h | 6 |
8 files changed, 52 insertions, 71 deletions
diff --git a/lib/mods/theme/scpt/drunk.lua b/lib/mods/theme/scpt/drunk.lua deleted file mode 100644 index 7d90af8d..00000000 --- a/lib/mods/theme/scpt/drunk.lua +++ /dev/null @@ -1,21 +0,0 @@ --- silly function that allows a drunk to take a bottle of wine/ale from the player - -function drunk_takes_wine(m_idx, item) - - m_ptr = monster(m_idx) - o_ptr = get_object(item) - - if (m_ptr.r_idx == test_monster_name("Singing, happy drunk")) - and (o_ptr.tval == TV_FOOD) and ((o_ptr.sval == 38) or (o_ptr.sval == 39)) then - - cmsg_print(TERM_YELLOW, "'Hic!'") - - inven_item_increase(item, -1) - inven_item_optimize(item) - return TRUE - else - return FALSE - end -end - -add_hook_script(HOOK_GIVE, "drunk_takes_wine", "drunk_takes_wine") diff --git a/lib/mods/theme/scpt/init.lua b/lib/mods/theme/scpt/init.lua index 0d59bfd2..8cd2094a 100644 --- a/lib/mods/theme/scpt/init.lua +++ b/lib/mods/theme/scpt/init.lua @@ -14,7 +14,6 @@ init_school_books() initialize_bookable_spells() -- Add joke stuff -tome_dofile("drunk.lua") tome_dofile("joke.lua") -- Some tests, if the file is not present, this is fine diff --git a/lib/mods/theme/scpt/misc.lua b/lib/mods/theme/scpt/misc.lua index 726574d2..21a81f83 100644 --- a/lib/mods/theme/scpt/misc.lua +++ b/lib/mods/theme/scpt/misc.lua @@ -1,29 +1,3 @@ --- silly function that allows a drunk to take a bottle of wine/ale from the player - -function drunk_takes_wine(m_idx, item) - - m_ptr = monster(m_idx) - o_ptr = get_object(item) - - if (m_ptr.r_idx == test_monster_name("Singing, happy drunk")) - and (o_ptr.tval == TV_FOOD) and ((o_ptr.sval == 38) or (o_ptr.sval == 39)) then - - cmsg_print(TERM_YELLOW, "'Hic!'") - - inven_item_increase(item, -1) - inven_item_optimize(item) - --- HackSmurf: the drunk may drop an empty bottle - bottle = create_object(TV_BOTTLE,1) - drop_near(bottle, 50, player.py, player.px) - return TRUE - else - return FALSE - end -end - -add_hook_script(HOOK_GIVE, "drunk_takes_wine", "drunk_takes_wine") - -- A not-too-scummy way of generating junk for ammo function food_vessel(object) if ((object.tval == 80) and (object.sval == 43)) or diff --git a/lib/scpt/drunk.lua b/lib/scpt/drunk.lua deleted file mode 100644 index 7d90af8d..00000000 --- a/lib/scpt/drunk.lua +++ /dev/null @@ -1,21 +0,0 @@ --- silly function that allows a drunk to take a bottle of wine/ale from the player - -function drunk_takes_wine(m_idx, item) - - m_ptr = monster(m_idx) - o_ptr = get_object(item) - - if (m_ptr.r_idx == test_monster_name("Singing, happy drunk")) - and (o_ptr.tval == TV_FOOD) and ((o_ptr.sval == 38) or (o_ptr.sval == 39)) then - - cmsg_print(TERM_YELLOW, "'Hic!'") - - inven_item_increase(item, -1) - inven_item_optimize(item) - return TRUE - else - return FALSE - end -end - -add_hook_script(HOOK_GIVE, "drunk_takes_wine", "drunk_takes_wine") diff --git a/lib/scpt/init.lua b/lib/scpt/init.lua index b3c73304..d27ce23c 100644 --- a/lib/scpt/init.lua +++ b/lib/scpt/init.lua @@ -14,7 +14,6 @@ init_school_books() initialize_bookable_spells() -- Add joke stuff -tome_dofile("drunk.lua") tome_dofile("joke.lua") -- Some tests, if the file is not present, this is fine @@ -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" */ |