diff options
author | Bardur Arantsson <bardur@scientician.net> | 2012-04-08 18:06:02 +0200 |
---|---|---|
committer | Bardur Arantsson <bardur@scientician.net> | 2012-04-08 18:19:36 +0200 |
commit | 00205df89e9c1bc2560d907c7fe6f9530a493d3b (patch) | |
tree | 5717c258a66d4f6120239210c57e385b2aef56a3 | |
parent | 1a33c8c5f7eb8d36642c59c37284cc8f06c3e102 (diff) |
Lua: Library quest: Move HOOK_STAIR code to C
-rw-r--r-- | lib/mods/theme/scpt/library.lua | 25 | ||||
-rw-r--r-- | lib/scpt/library.lua | 25 | ||||
-rw-r--r-- | src/plots.h | 1 | ||||
-rw-r--r-- | src/q_library.c | 46 | ||||
-rw-r--r-- | src/util.pkg | 1 |
5 files changed, 50 insertions, 48 deletions
diff --git a/lib/mods/theme/scpt/library.lua b/lib/mods/theme/scpt/library.lua index fca935fb..1f7e7d49 100644 --- a/lib/mods/theme/scpt/library.lua +++ b/lib/mods/theme/scpt/library.lua @@ -101,30 +101,7 @@ add_quest return quest_library_gen_hook() end, [HOOK_STAIR] = function() - local ret - - -- only ask this if player about to go up stairs of quest and hasn't won yet - if (player.inside_quest ~= LIBRARY_QUEST) or (quest(LIBRARY_QUEST).status == QUEST_STATUS_COMPLETED) then - return FALSE - end - - if cave(player.py, player.px).feat ~= FEAT_LESS then return end - - -- flush all pending input - flush() - - -- confirm - ret = get_check("Really abandon the quest?") - - -- if yes, then - if ret == TRUE then - -- fail the quest - quest(LIBRARY_QUEST).status = QUEST_STATUS_FAILED - return FALSE - else - -- if no, they stay in the quest - return TRUE - end + return quest_library_stair_hook() end, [HOOK_MONSTER_DEATH] = function() -- if they're in the quest and haven't won, continue diff --git a/lib/scpt/library.lua b/lib/scpt/library.lua index 202ba268..6368409d 100644 --- a/lib/scpt/library.lua +++ b/lib/scpt/library.lua @@ -98,30 +98,7 @@ add_quest return quest_library_gen_hook() end, [HOOK_STAIR] = function() - local ret - - -- only ask this if player about to go up stairs of quest and hasn't won yet - if (player.inside_quest ~= LIBRARY_QUEST) or (quest(LIBRARY_QUEST).status == QUEST_STATUS_COMPLETED) then - return FALSE - end - - if cave(player.py, player.px).feat ~= FEAT_LESS then return end - - -- flush all pending input - flush() - - -- confirm - ret = get_check("Really abandon the quest?") - - -- if yes, then - if ret == TRUE then - -- fail the quest - quest(LIBRARY_QUEST).status = QUEST_STATUS_FAILED - return FALSE - else - -- if no, they stay in the quest - return TRUE - end + return quest_library_stair_hook() end, [HOOK_MONSTER_DEATH] = function() -- if they're in the quest and haven't won, continue diff --git a/src/plots.h b/src/plots.h index da8a6cd2..ce938a69 100644 --- a/src/plots.h +++ b/src/plots.h @@ -55,6 +55,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_building(bool_ *paid, bool_ *recreate); /******* Plot Fireproof Quest *********/ diff --git a/src/q_library.c b/src/q_library.c index d7a098cd..8804e2dc 100644 --- a/src/q_library.c +++ b/src/q_library.c @@ -12,6 +12,16 @@ static int LIBRARY_QUEST() return get_lua_int("LIBRARY_QUEST"); } +static int library_quest_get_status() +{ + return exec_lua("return quest(LIBRARY_QUEST).status"); +} + +static void library_quest_set_status(int new_status) +{ + exec_lua(format("quest(LIBRARY_QUEST).status = %d", new_status)); +} + static s16b library_quest_place_random(int minY, int minX, int maxY, int maxX, int r_idx) { int y = randint(maxY - minY + 1) + minY; @@ -262,6 +272,42 @@ bool_ quest_library_gen_hook() return TRUE; } +bool_ quest_library_stair_hook() +{ + bool_ ret; + + /* only ask this if player about to go up stairs of quest and hasn't won yet */ + if ((p_ptr->inside_quest != LIBRARY_QUEST()) || + (library_quest_get_status() == QUEST_STATUS_COMPLETED)) + { + return FALSE; + } + + if (cave[p_ptr->py][p_ptr->px].feat != FEAT_LESS) + { + return FALSE; + } + + /* flush all pending input */ + flush(); + + /* confirm */ + ret = get_check("Really abandon the quest?"); + + /* if yes, then */ + if (ret == TRUE) + { + /* fail the quest */ + library_quest_set_status(QUEST_STATUS_FAILED); + return FALSE; + } + else + { + /* if no, they stay in the quest */ + return TRUE; + } +} + static int get_status() { return exec_lua("return quest(LIBRARY_QUEST).status"); diff --git a/src/util.pkg b/src/util.pkg index 49924e7f..c117ef0f 100644 --- a/src/util.pkg +++ b/src/util.pkg @@ -2474,6 +2474,7 @@ extern bool drop_text_left(byte c, cptr s, int y, int o); 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(); /** * Mimicry |