summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2012-04-07 21:11:58 +0200
committerBardur Arantsson <bardur@scientician.net>2012-04-07 21:18:12 +0200
commit92a7621e525ead5f41715efb92499cf289d2eea5 (patch)
tree8f462d7f951a720201a3c399635850866256efc3
parent5ea970c82ba3119ca3a5ee68037aee7cdda6dfa3 (diff)
Lua: Move Library Quest building action to C
-rw-r--r--lib/mods/theme/scpt/library.lua42
-rw-r--r--lib/scpt/library.lua42
-rw-r--r--src/bldg.c6
-rw-r--r--src/defines.h1
-rw-r--r--src/plots.h1
-rw-r--r--src/q_library.c65
-rw-r--r--src/variable.c2
7 files changed, 74 insertions, 85 deletions
diff --git a/lib/mods/theme/scpt/library.lua b/lib/mods/theme/scpt/library.lua
index 38c26599..d2851a23 100644
--- a/lib/mods/theme/scpt/library.lua
+++ b/lib/mods/theme/scpt/library.lua
@@ -160,45 +160,3 @@ add_quest
end,
},
}
-
--- Library store action
-add_building_action
-{
- ["index"] = 61,
- ["action"] = function()
- -- the quest hasn't been requested already, right?
- if quest(LIBRARY_QUEST).status == QUEST_STATUS_UNTAKEN then
- -- quest has been taken now
- quest(LIBRARY_QUEST).status = QUEST_STATUS_TAKEN
-
- -- issue instructions
- msg_print("I need get some stock from my main library, but it is infested with monsters!")
- msg_print("Please use the side entrance and vanquish the intruders for me.")
-
- return TRUE, FALSE, TRUE
- -- if quest completed
- elseif (quest(LIBRARY_QUEST).status == QUEST_STATUS_COMPLETED) then
- msg_print("Thank you! Let me make a special book for you.")
- msg_print("Tell me three spells and I will write them in the book.")
- library_quest_fill_book()
- if library_quest_book_slots_left() == 0 then
- quest(LIBRARY_QUEST).status = QUEST_STATUS_REWARDED
- book = create_object(TV_BOOK, 61)
- book.art_name = quark_add(player_name())
- book.found = OBJ_FOUND_REWARD
- set_aware(book)
- set_known(book)
- inven_carry(book, FALSE)
- end
-
- -- if the player asks for a quest when they already have it, but haven't failed it, give them some extra instructions
- elseif (quest(LIBRARY_QUEST).status == QUEST_STATUS_TAKEN) then
- msg_print("Please use the side entrance and vanquish the intruders for me.")
-
- -- quest failed or completed, then give no more quests
- elseif (quest(LIBRARY_QUEST).status == QUEST_STATUS_FAILED) or (quest(LIBRARY_QUEST).status == QUEST_STATUS_REWARDED) then
- msg_print("I have no more quests for you.")
- end
- return TRUE
- end,
-}
diff --git a/lib/scpt/library.lua b/lib/scpt/library.lua
index 5c98fe86..ad546b54 100644
--- a/lib/scpt/library.lua
+++ b/lib/scpt/library.lua
@@ -157,45 +157,3 @@ add_quest
end,
},
}
-
--- Library store action
-add_building_action
-{
- ["index"] = 61,
- ["action"] = function()
- -- the quest hasn't been requested already, right?
- if quest(LIBRARY_QUEST).status == QUEST_STATUS_UNTAKEN then
- -- quest has been taken now
- quest(LIBRARY_QUEST).status = QUEST_STATUS_TAKEN
-
- -- issue instructions
- msg_print("I need get some stock from my main library, but it is infested with monsters!")
- msg_print("Please use the side entrance and vanquish the intruders for me.")
-
- return TRUE, FALSE, TRUE
- -- if quest completed
- elseif (quest(LIBRARY_QUEST).status == QUEST_STATUS_COMPLETED) then
- msg_print("Thank you! Let me make a special book for you.")
- msg_print("Tell me three spells and I will write them in the book.")
- library_quest_fill_book()
- if library_quest_book_slots_left() == 0 then
- quest(LIBRARY_QUEST).status = QUEST_STATUS_REWARDED
- book = create_object(TV_BOOK, 61)
- book.art_name = quark_add(player_name())
- book.found = OBJ_FOUND_REWARD
- set_aware(book)
- set_known(book)
- inven_carry(book, FALSE)
- end
-
- -- if the player asks for a quest when they already have it, but haven't failed it, give them some extra instructions
- elseif (quest(LIBRARY_QUEST).status == QUEST_STATUS_TAKEN) then
- msg_print("Please use the side entrance and vanquish the intruders for me.")
-
- -- quest failed or completed, then give no more quests
- elseif (quest(LIBRARY_QUEST).status == QUEST_STATUS_FAILED) or (quest(LIBRARY_QUEST).status == QUEST_STATUS_REWARDED) then
- msg_print("I have no more quests for you.")
- end
- return TRUE
- end,
-}
diff --git a/src/bldg.c b/src/bldg.c
index 1845e838..66ca9d9d 100644
--- a/src/bldg.c
+++ b/src/bldg.c
@@ -2042,6 +2042,12 @@ bool_ bldg_process_command(store_type *s_ptr, int i)
break;
}
+ case BACT_LIBRARY_QUEST:
+ {
+ quest_library_building(&paid, &recreate);
+ break;
+ }
+
default:
{
if (process_hooks_ret(HOOK_BUILDING_ACTION, "dd", "(d)", bact))
diff --git a/src/defines.h b/src/defines.h
index f716e326..d78ed058 100644
--- a/src/defines.h
+++ b/src/defines.h
@@ -4046,6 +4046,7 @@
#define BACT_PAY_BACK_LOAN 53
#define BACT_DROP_ITEM 54
#define BACT_GET_ITEM 55
+#define BACT_LIBRARY_QUEST 61
/* If one adds new BACT_ do NOT forget to increase max_bact in variables.c */
diff --git a/src/plots.h b/src/plots.h
index 2d78ee02..73e4b8a8 100644
--- a/src/plots.h
+++ b/src/plots.h
@@ -55,3 +55,4 @@ extern bool_ quest_bounty_describe(FILE *fff);
/******* Plot Library Quest *******/
extern void quest_library_gen_hook();
+extern void quest_library_building(bool_ *paid, bool_ *recreate);
diff --git a/src/q_library.c b/src/q_library.c
index 25f20717..6bb8baaa 100644
--- a/src/q_library.c
+++ b/src/q_library.c
@@ -240,3 +240,68 @@ void quest_library_gen_hook()
library_quest_place_nrandom(
10, 10, 37, 67, MONSTER_MITHRIL_GOLEM, 1);
}
+
+static int get_status()
+{
+ return exec_lua("return quest(LIBRARY_QUEST).status");
+}
+
+static void set_status(int new_status)
+{
+ exec_lua(format("quest(LIBRARY_QUEST).status = %d", new_status));
+}
+
+void quest_library_building(bool_ *paid, bool_ *recreate)
+{
+ int status = 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);
+
+ /* issue instructions */
+ msg_print("I need get some stock from my main library, but it is infested with monsters!");
+ msg_print("Please use the side entrance and vanquish the intruders for me.");
+
+ *paid = FALSE;
+ *recreate = TRUE;
+ }
+
+ /* if quest completed */
+ else if (status == QUEST_STATUS_COMPLETED)
+ {
+ msg_print("Thank you! Let me make a special book for you.");
+ msg_print("Tell me three spells and I will write them in the book.");
+ library_quest_fill_book();
+ if (library_quest_book_slots_left() == 0)
+ {
+ set_status(QUEST_STATUS_REWARDED);
+
+ {
+ object_type forge;
+ object_type *q_ptr = &forge;
+ object_prep(q_ptr, lookup_kind(TV_BOOK, 61));
+ q_ptr->art_name = quark_add(player_name);
+ q_ptr->found = OBJ_FOUND_REWARD;
+ object_aware(q_ptr);
+ object_known(q_ptr);
+ inven_carry(q_ptr, FALSE);
+ }
+ }
+ }
+
+ /* if the player asks for a quest when they already have it,
+ * but haven't failed it, give them some extra instructions */
+ else if (status == QUEST_STATUS_TAKEN)
+ {
+ msg_print("Please use the side entrance and vanquish the intruders for me.");
+ }
+
+ /* quest failed or completed, then give no more quests */
+ else if ((status == QUEST_STATUS_FAILED) || (status == QUEST_STATUS_REWARDED))
+ {
+ msg_print("I have no more quests for you.");
+ }
+}
diff --git a/src/variable.c b/src/variable.c
index 52e16e01..c4388457 100644
--- a/src/variable.c
+++ b/src/variable.c
@@ -1533,7 +1533,7 @@ int cli_total = 0;
/*
* max_bact, only used so that lua scripts can add new bacts without worrying about the numbers
*/
-int max_bact = 56;
+int max_bact = 127;
/*
* Ingame contextual help