diff options
author | Bardur Arantsson <bardur@scientician.net> | 2012-04-08 18:19:19 +0200 |
---|---|---|
committer | Bardur Arantsson <bardur@scientician.net> | 2012-04-08 18:19:36 +0200 |
commit | 2c0ec2974884386d9b332c6004758e64ab8ce709 (patch) | |
tree | df6865f3367344f6b6fa321c4b5cbe170dee5cc6 | |
parent | 00205df89e9c1bc2560d907c7fe6f9530a493d3b (diff) |
Lua: Library quest: Move HOOK_MONSTER_DEATH code to C
-rw-r--r-- | lib/mods/theme/scpt/library.lua | 20 | ||||
-rw-r--r-- | lib/scpt/library.lua | 20 | ||||
-rw-r--r-- | src/plots.h | 1 | ||||
-rw-r--r-- | src/q_library.c | 38 | ||||
-rw-r--r-- | src/util.pkg | 1 |
5 files changed, 33 insertions, 47 deletions
diff --git a/lib/mods/theme/scpt/library.lua b/lib/mods/theme/scpt/library.lua index 1f7e7d49..5ba5ed4c 100644 --- a/lib/mods/theme/scpt/library.lua +++ b/lib/mods/theme/scpt/library.lua @@ -104,25 +104,7 @@ add_quest return quest_library_stair_hook() end, [HOOK_MONSTER_DEATH] = function() - -- if they're in the quest and haven't won, continue - if (player.inside_quest ~= LIBRARY_QUEST) or (quest(LIBRARY_QUEST).status == QUEST_STATUS_COMPLETED) then - return FALSE - end - - i = 1 - count = -1 - while i <= m_max do - local monster = m_list[i] - if (monster.r_idx > 0) and (monster.status <= MSTATUS_ENEMY) then - count = count + 1 - end - i = i + 1 - end - - if count == 0 then - quest(LIBRARY_QUEST).status = QUEST_STATUS_COMPLETED - msg_print(TERM_YELLOW, "The library is safe now.") - end + return quest_library_monster_death_hook() end, }, } diff --git a/lib/scpt/library.lua b/lib/scpt/library.lua index 6368409d..2ee8c7d3 100644 --- a/lib/scpt/library.lua +++ b/lib/scpt/library.lua @@ -101,25 +101,7 @@ add_quest return quest_library_stair_hook() end, [HOOK_MONSTER_DEATH] = function() - -- if they're in the quest and haven't won, continue - if (player.inside_quest ~= LIBRARY_QUEST) or (quest(LIBRARY_QUEST).status == QUEST_STATUS_COMPLETED) then - return FALSE - end - - i = 1 - count = -1 - while i <= m_max do - local monster = m_list[i] - if (monster.r_idx > 0) and (monster.status <= MSTATUS_ENEMY) then - count = count + 1 - end - i = i + 1 - end - - if count == 0 then - quest(LIBRARY_QUEST).status = QUEST_STATUS_COMPLETED - msg_print(TERM_YELLOW, "The library is safe now.") - end + return quest_library_monster_death_hook() end, }, } diff --git a/src/plots.h b/src/plots.h index ce938a69..eabbf052 100644 --- a/src/plots.h +++ b/src/plots.h @@ -56,6 +56,7 @@ extern bool_ quest_bounty_describe(FILE *fff); /******* Plot Library Quest *******/ extern bool_ quest_library_gen_hook(); extern bool_ quest_library_stair_hook(); +extern void quest_library_monster_death_hook(); extern void quest_library_building(bool_ *paid, bool_ *recreate); /******* Plot Fireproof Quest *********/ diff --git a/src/q_library.c b/src/q_library.c index 8804e2dc..6aa47a81 100644 --- a/src/q_library.c +++ b/src/q_library.c @@ -308,25 +308,45 @@ bool_ quest_library_stair_hook() } } -static int get_status() +void quest_library_monster_death_hook() { - return exec_lua("return quest(LIBRARY_QUEST).status"); -} + int i, count = -1; -static void set_status(int new_status) -{ - exec_lua(format("quest(LIBRARY_QUEST).status = %d", new_status)); + /* if they're in the quest and haven't won, continue */ + if ((p_ptr->inside_quest != LIBRARY_QUEST()) || + (library_quest_get_status() == QUEST_STATUS_COMPLETED)) + { + return; + } + + /* Count all the enemies left alive */ + for (i = 0; i < m_max; i++) + { + monster_type *m_ptr = &m_list[i]; + if ((m_ptr->r_idx > 0) && + (m_ptr->status <= MSTATUS_ENEMY)) + { + count = count + 1; + } + } + + /* We've just killed the last monster */ + if (count == 0) + { + library_quest_set_status(QUEST_STATUS_COMPLETED); + cmsg_print(TERM_YELLOW, "The library is safe now."); + } } void quest_library_building(bool_ *paid, bool_ *recreate) { - int status = get_status(); + int status = library_quest_get_status(); /* the quest hasn't been requested already, right? */ if (status == QUEST_STATUS_UNTAKEN) { /* quest has been taken now */ - set_status(QUEST_STATUS_TAKEN); + library_quest_set_status(QUEST_STATUS_TAKEN); /* issue instructions */ msg_print("I need get some stock from my main library, but it is infested with monsters!"); @@ -344,7 +364,7 @@ void quest_library_building(bool_ *paid, bool_ *recreate) library_quest_fill_book(); if (library_quest_book_slots_left() == 0) { - set_status(QUEST_STATUS_REWARDED); + library_quest_set_status(QUEST_STATUS_REWARDED); { object_type forge; diff --git a/src/util.pkg b/src/util.pkg index c117ef0f..cb986b68 100644 --- a/src/util.pkg +++ b/src/util.pkg @@ -2475,6 +2475,7 @@ extern bool drop_text_right(byte c, cptr s, int y, int o); extern bool quest_library_gen_hook(); extern bool quest_library_stair_hook(); +extern void quest_library_monster_death_hook(); /** * Mimicry |