summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2012-04-09 00:47:44 +0200
committerBardur Arantsson <bardur@scientician.net>2012-04-09 09:54:40 +0200
commitd497a80b25bb612d63daa70582fca5eeaa708fec (patch)
tree64a3faf0fd5550d4df4ab57d5b3be259a329d01a
parent7fc396e625a96e48419b60359f721ad082d7f475 (diff)
Lua: God quests: Move HOOK_GET code to C
-rw-r--r--lib/mods/theme/scpt/god.lua41
-rw-r--r--lib/scpt/god.lua41
-rw-r--r--src/plots.h1
-rw-r--r--src/q_god.c64
-rw-r--r--src/quest.pkg1
5 files changed, 68 insertions, 80 deletions
diff --git a/lib/mods/theme/scpt/god.lua b/lib/mods/theme/scpt/god.lua
index 061b23e6..7a03f49f 100644
--- a/lib/mods/theme/scpt/god.lua
+++ b/lib/mods/theme/scpt/god.lua
@@ -138,46 +138,7 @@ add_quest
end
end,
[HOOK_GET] = function(o_ptr, item)
- -- Is it the relic, and check to make sure the relic hasn't already been identified
- if (quest(GOD_QUEST).status == QUEST_STATUS_TAKEN) and (o_ptr.tval == TV_JUNK) and (o_ptr.sval == god_quest.relic_num)
- and (o_ptr.pval ~= TRUE) and (god_quest.relics_found < god_quest.quests_given) then
-
- -- more God talky-talky
- cmsg_print(TERM_L_BLUE, deity(player.pgod).name.." speaks to you:")
-
- -- Is it the last piece of the relic?
- if (god_quest.quests_given == god_quest.MAX_NUM_GOD_QUESTS) then
- cmsg_print(TERM_YELLOW, "'At last! Thou hast found all of the relic pieces.")
-
- -- reward player by increasing prayer skill
- cmsg_print(TERM_YELLOW, "Thou hast done exceptionally well! I shall increase thy prayer skill even more!'")
- skill(SKILL_PRAY).value = skill(SKILL_PRAY).value + (10 * (skill(SKILL_PRAY).mod))
-
- -- Take the relic piece
- floor_item_increase(item, -1)
- floor_item_optimize(item)
- else
- cmsg_print(TERM_YELLOW, "'Well done! Thou hast found part of the relic.")
- cmsg_print(TERM_YELLOW, "I shall surely ask thee to find more of it later!")
- cmsg_print(TERM_YELLOW, "I will take it from thee for now'")
-
- -- Take the relic piece
- floor_item_increase(item, -1)
- floor_item_optimize(item)
-
- -- reward player by increasing prayer skill
- cmsg_print(TERM_YELLOW, "'As a reward, I shall teach thee how to pray better'")
- skill(SKILL_PRAY).value = skill(SKILL_PRAY).value + (5 * (skill(SKILL_PRAY).mod))
- end
-
- -- relic piece has been identified
- o_ptr.pval = TRUE
- god_quest.relics_found = god_quest.relics_found + 1
-
- -- Make sure quests can be given again if neccesary
- quest(GOD_QUEST).status = QUEST_STATUS_UNTAKEN
- return TRUE
- end
+ return quest_god_get_hook(item)
end,
[HOOK_CHAR_DUMP] = function()
diff --git a/lib/scpt/god.lua b/lib/scpt/god.lua
index 3ccd14a0..9e1f2039 100644
--- a/lib/scpt/god.lua
+++ b/lib/scpt/god.lua
@@ -130,46 +130,7 @@ add_quest
end
end,
[HOOK_GET] = function(o_ptr, item)
- -- Is it the relic, and check to make sure the relic hasn't already been identified
- if (quest(GOD_QUEST).status == QUEST_STATUS_TAKEN) and (o_ptr.tval == TV_JUNK) and (o_ptr.sval == god_quest.relic_num)
- and (o_ptr.pval ~= TRUE) and (god_quest.relics_found < god_quest.quests_given) then
-
- -- more God talky-talky
- cmsg_print(TERM_L_BLUE, deity(player.pgod).name.." speaks to you:")
-
- -- Is it the last piece of the relic?
- if (god_quest.quests_given == god_quest.MAX_NUM_GOD_QUESTS) then
- cmsg_print(TERM_YELLOW, "'At last! Thou hast found all of the relic pieces.")
-
- -- reward player by increasing prayer skill
- cmsg_print(TERM_YELLOW, "Thou hast done exceptionally well! I shall increase thy prayer skill even more!'")
- skill(SKILL_PRAY).value = skill(SKILL_PRAY).value + (10 * (skill(SKILL_PRAY).mod))
-
- -- Take the relic piece
- floor_item_increase(item, -1)
- floor_item_optimize(item)
- else
- cmsg_print(TERM_YELLOW, "'Well done! Thou hast found part of the relic.")
- cmsg_print(TERM_YELLOW, "I shall surely ask thee to find more of it later!")
- cmsg_print(TERM_YELLOW, "I will take it from thee for now'")
-
- -- Take the relic piece
- floor_item_increase(item, -1)
- floor_item_optimize(item)
-
- -- reward player by increasing prayer skill
- cmsg_print(TERM_YELLOW, "'As a reward, I shall teach thee how to pray better'")
- skill(SKILL_PRAY).value = skill(SKILL_PRAY).value + (5 * (skill(SKILL_PRAY).mod))
- end
-
- -- relic piece has been identified
- o_ptr.pval = TRUE
- god_quest.relics_found = god_quest.relics_found + 1
-
- -- Make sure quests can be given again if neccesary
- quest(GOD_QUEST).status = QUEST_STATUS_UNTAKEN
- return TRUE
- end
+ return quest_god_get_hook(item)
end,
[HOOK_CHAR_DUMP] = function()
diff --git a/src/plots.h b/src/plots.h
index 01e6db0b..27cf25f0 100644
--- a/src/plots.h
+++ b/src/plots.h
@@ -77,3 +77,4 @@ extern void quest_god_set_god_dungeon_attributes_ulmo();
extern void quest_god_set_god_dungeon_attributes_mandos();
extern void quest_god_level_end_gen_hook();
extern void quest_god_player_level_hook(int gained);
+extern bool_ quest_god_get_hook(int o_idx);
diff --git a/src/q_god.c b/src/q_god.c
index 020b8ca1..bc2920a9 100644
--- a/src/q_god.c
+++ b/src/q_god.c
@@ -122,6 +122,16 @@ static int get_dun_minplev()
return get_lua_int("god_quest.dun_minplev");
}
+static int get_relics_found()
+{
+ return get_lua_int("god_quest.relics_found");
+}
+
+static void set_relics_found(int v)
+{
+ exec_lua(format("god_quest.relics_found = %d", v));
+}
+
static void setup_relic_number()
{
exec_lua("setup_relic_number()");
@@ -824,3 +834,57 @@ void quest_god_player_level_hook(int gained)
set_dun_maxdepth(get_dun_mindepth() + 4);
}
}
+
+bool_ quest_god_get_hook(int item)
+{
+ object_type *o_ptr = NULL;
+
+ item = -item; /* Workaround */
+ o_ptr = get_object(item);
+
+ /* -- Is it the relic, and check to make sure the relic hasn't already been identified */
+ if ((get_status() == QUEST_STATUS_TAKEN) &&
+ (o_ptr->tval == TV_JUNK) &&
+ (o_ptr->sval == get_relic_num()) &&
+ (o_ptr->pval != TRUE) &&
+ (get_relics_found() < get_quests_given()))
+ {
+ cmsg_format(TERM_L_BLUE, "%s speaks to you:", deity_info[p_ptr->pgod].name);
+
+ /* Is it the last piece of the relic? */
+ if (get_quests_given() == MAX_NUM_GOD_QUESTS())
+ {
+ cmsg_print(TERM_YELLOW, "'At last! Thou hast found all of the relic pieces.");
+
+ /* reward player by increasing prayer skill */
+ cmsg_print(TERM_YELLOW, "Thou hast done exceptionally well! I shall increase thy prayer skill even more!'");
+ s_info[SKILL_PRAY].value += (10 * s_info[SKILL_PRAY].mod);
+ }
+ else
+ {
+ cmsg_print(TERM_YELLOW, "'Well done! Thou hast found part of the relic.");
+ cmsg_print(TERM_YELLOW, "I shall surely ask thee to find more of it later!");
+ cmsg_print(TERM_YELLOW, "I will take it from thee for now'");
+
+ /* reward player by increasing prayer skill */
+ cmsg_print(TERM_YELLOW, "'As a reward, I shall teach thee how to pray better'");
+ s_info[SKILL_PRAY].value += (5 * s_info[SKILL_PRAY].mod);
+ }
+
+ /* Take the relic piece */
+ inc_stack_size_ex(item, -1, OPTIMIZE, NO_DESCRIBE);
+
+ /* relic piece has been identified */
+ o_ptr->pval = TRUE;
+ set_relics_found(get_relics_found() + 1);
+
+ /* Make sure quests can be given again if neccesary */
+ set_status(QUEST_STATUS_UNTAKEN);
+
+ /* Prevent further processing of 'take' action; we've
+ destroyed the item. */
+ return TRUE;
+ }
+
+ return FALSE;
+}
diff --git a/src/quest.pkg b/src/quest.pkg
index 91f0e780..dc5a91fc 100644
--- a/src/quest.pkg
+++ b/src/quest.pkg
@@ -176,3 +176,4 @@ extern void quest_god_set_god_dungeon_attributes_ulmo();
extern void quest_god_set_god_dungeon_attributes_mandos();
extern void quest_god_level_end_gen_hook();
extern void quest_god_player_level_hook(int gained);
+extern bool quest_god_get_hook(int o_idx);