summaryrefslogtreecommitdiff
path: root/src/q_library.c
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2012-04-08 18:06:02 +0200
committerBardur Arantsson <bardur@scientician.net>2012-04-08 18:19:36 +0200
commit00205df89e9c1bc2560d907c7fe6f9530a493d3b (patch)
tree5717c258a66d4f6120239210c57e385b2aef56a3 /src/q_library.c
parent1a33c8c5f7eb8d36642c59c37284cc8f06c3e102 (diff)
Lua: Library quest: Move HOOK_STAIR code to C
Diffstat (limited to 'src/q_library.c')
-rw-r--r--src/q_library.c46
1 files changed, 46 insertions, 0 deletions
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");