summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2012-04-09 00:07:46 +0200
committerBardur Arantsson <bardur@scientician.net>2012-04-09 00:34:03 +0200
commit7fc396e625a96e48419b60359f721ad082d7f475 (patch)
tree910d0499567992377faf7ce7e2b6dcb4fab0168d
parent19a72f1025b0c25b62db56748e0e1f7097227abc (diff)
Lua: God quests: Move HOOK_PLAYER_LEVEL code to C
-rw-r--r--lib/mods/theme/scpt/god.lua48
-rw-r--r--lib/scpt/god.lua48
-rw-r--r--src/plots.h1
-rw-r--r--src/q_god.c128
-rw-r--r--src/quest.pkg1
5 files changed, 132 insertions, 94 deletions
diff --git a/lib/mods/theme/scpt/god.lua b/lib/mods/theme/scpt/god.lua
index a7c79924..061b23e6 100644
--- a/lib/mods/theme/scpt/god.lua
+++ b/lib/mods/theme/scpt/god.lua
@@ -108,53 +108,7 @@ add_quest
god_quest.relic_generated = FALSE
end,
[HOOK_PLAYER_LEVEL] = function(gained)
- if gained > 0 then
- -- roll for chance of quest
- local give_god_quest = magik(god_quest.CHANCE_OF_GOD_QUEST)
-
- -- check player is worshipping a god, not already on a god quest.
- if (player.astral ~= FALSE) or (player.pgod <= 0)
- or (quest(GOD_QUEST).status == QUEST_STATUS_TAKEN) or (quest(GOD_QUEST).status == QUEST_STATUS_FAILED)
- or (god_quest.quests_given >= god_quest.MAX_NUM_GOD_QUESTS) or (give_god_quest == FALSE)
- or ((current_dungeon_idx == god_quest.DUNGEON_GOD) and (dun_level > 0)) or (player.lev <= god_quest.dun_minplev) then
- -- Don't let a player get quests with trickery
- if player.lev > god_quest.dun_minplev then
- god_quest.dun_minplev = player.lev
- end
- return
- else
- -- each god has different characteristics, so the quests are differnet depending on your god
- setup_relic_number()
-
- -- This var will need resetting
- god_quest.relic_generated = FALSE
- quest(GOD_QUEST).status = QUEST_STATUS_TAKEN
- god_quest.quests_given = god_quest.quests_given + 1
-
- -- actually place the dungeon in a random place
- quest_god_place_rand_dung()
-
- -- store the variables of the coords where the player was given the quest
- god_quest.player_y, god_quest.player_x = player.get_wild_coord()
-
- -- God issues instructions
- cmsg_print(TERM_L_BLUE, "The voice of "..deity(player.pgod).name.." booms in your head:")
-
- cmsg_print(TERM_YELLOW, "'I have a task for thee.")
- cmsg_print(TERM_YELLOW, "Centuries ago an ancient relic of mine was broken apart.")
- cmsg_print(TERM_YELLOW, "The pieces of it have been lost in fallen temples.")
- cmsg_print(TERM_YELLOW, "Thou art to find my lost temple and retrieve a piece of the relic.")
- cmsg_print(TERM_YELLOW, "When thy task is done, thou art to lift it in the air and call upon my name.")
- cmsg_print(TERM_YELLOW, "I shall then come to reclaim what is mine!")
-
- msg_directions()
-
- -- Prepare depth of dungeon. If this was generated in set_god_dungeon_attributes(),
- -- then we'd have trouble if someone levelled up in the dungeon!
- god_quest.dun_mindepth = player.lev*2/3
- god_quest.dun_maxdepth = god_quest.dun_mindepth + 4
- end
- end
+ quest_god_player_level_hook(gained)
end,
[HOOK_LEVEL_END_GEN] = function()
quest_god_level_end_gen_hook()
diff --git a/lib/scpt/god.lua b/lib/scpt/god.lua
index 53363d65..3ccd14a0 100644
--- a/lib/scpt/god.lua
+++ b/lib/scpt/god.lua
@@ -100,53 +100,7 @@ add_quest
god_quest.relic_generated = FALSE
end,
[HOOK_PLAYER_LEVEL] = function(gained)
- if gained > 0 then
- -- roll for chance of quest
- local give_god_quest = magik(god_quest.CHANCE_OF_GOD_QUEST)
-
- -- check player is worshipping a god, not already on a god quest.
- if (player.astral ~= FALSE) or (player.pgod <= 0)
- or (quest(GOD_QUEST).status == QUEST_STATUS_TAKEN) or (quest(GOD_QUEST).status == QUEST_STATUS_FAILED)
- or (god_quest.quests_given >= god_quest.MAX_NUM_GOD_QUESTS) or (give_god_quest == FALSE)
- or ((current_dungeon_idx == god_quest.DUNGEON_GOD) and (dun_level > 0)) or (player.lev <= god_quest.dun_minplev) then
- -- Don't let a player get quests with trickery
- if player.lev > god_quest.dun_minplev then
- god_quest.dun_minplev = player.lev
- end
- return
- else
- -- each god has different characteristics, so the quests are differnet depending on your god
- setup_relic_number()
-
- -- This var will need resetting
- god_quest.relic_generated = FALSE
- quest(GOD_QUEST).status = QUEST_STATUS_TAKEN
- god_quest.quests_given = god_quest.quests_given + 1
-
- -- actually place the dungeon in a random place
- quest_god_place_rand_dung()
-
- -- store the variables of the coords where the player was given the quest
- god_quest.player_y, god_quest.player_x = player.get_wild_coord()
-
- -- God issues instructions
- cmsg_print(TERM_L_BLUE, "The voice of "..deity(player.pgod).name.." booms in your head:")
-
- cmsg_print(TERM_YELLOW, "'I have a task for thee.")
- cmsg_print(TERM_YELLOW, "Centuries ago an ancient relic of mine was broken apart.")
- cmsg_print(TERM_YELLOW, "The pieces of it have been lost in fallen temples.")
- cmsg_print(TERM_YELLOW, "Thou art to find my lost temple and retrieve a piece of the relic.")
- cmsg_print(TERM_YELLOW, "When thy task is done, thou art to lift it in the air and call upon my name.")
- cmsg_print(TERM_YELLOW, "I shall then come to reclaim what is mine!")
-
- msg_directions()
-
- -- Prepare depth of dungeon. If this was generated in set_god_dungeon_attributes(),
- -- then we'd have trouble if someone levelled up in the dungeon!
- god_quest.dun_mindepth = player.lev*2/3
- god_quest.dun_maxdepth = god_quest.dun_mindepth + 4
- end
- end
+ quest_god_player_level_hook(gained)
end,
[HOOK_LEVEL_END_GEN] = function()
quest_god_level_end_gen_hook()
diff --git a/src/plots.h b/src/plots.h
index 47f5e30f..01e6db0b 100644
--- a/src/plots.h
+++ b/src/plots.h
@@ -76,3 +76,4 @@ extern void quest_god_set_god_dungeon_attributes_varda();
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);
diff --git a/src/q_god.c b/src/q_god.c
index 3c0f38a5..020b8ca1 100644
--- a/src/q_god.c
+++ b/src/q_god.c
@@ -3,12 +3,18 @@
/* d_idx of the god_quest (Lost Temple) dungeon */
#define DUNGEON_GOD 30
+#define CHANCE_OF_GOD_QUEST 21
static int get_quests_given()
{
return get_lua_int("god_quest.quests_given");
}
+static void set_quests_given(int i)
+{
+ exec_lua(format("god_quest.quests_given = %d", i));
+}
+
static int get_dung_y()
{
return get_lua_int("god_quest.dung_y");
@@ -44,6 +50,11 @@ static void set_status(int new_status)
exec_lua(format("quest(GOD_QUEST).status = %d", new_status));
}
+static int MAX_NUM_GOD_QUESTS()
+{
+ return get_lua_int("god_quest.MAX_NUM_GOD_QUESTS");
+}
+
static void set_relic_generated(bool_ v)
{
switch (v)
@@ -75,6 +86,52 @@ static int get_relic_gen_tries()
return get_lua_int("god_quest.relic_gen_tries");
}
+static void set_player_y(int y)
+{
+ exec_lua(format("god_quest.player_y = %d", y));
+}
+
+static void set_player_x(int x)
+{
+ exec_lua(format("god_quest.player_x = %d", x));
+}
+
+static int get_dun_mindepth()
+{
+ return get_lua_int("god_quest.dun_mindepth");
+}
+
+static void set_dun_mindepth(int d)
+{
+ exec_lua(format("god_quest.dun_mindepth = %d", d));
+}
+
+static void set_dun_maxdepth(int d)
+{
+ exec_lua(format("god_quest.dun_maxdepth = %d", d));
+
+}
+
+static void set_dun_minplev(int p)
+{
+ exec_lua(format("god_quest.dun_minplev = %d", p));
+}
+
+static int get_dun_minplev()
+{
+ return get_lua_int("god_quest.dun_minplev");
+}
+
+static void setup_relic_number()
+{
+ exec_lua("setup_relic_number()");
+}
+
+static void msg_directions()
+{
+ exec_lua("msg_directions()");
+}
+
void quest_god_place_rand_dung()
{
int x = -1, y = -1, tries;
@@ -696,3 +753,74 @@ void quest_god_level_end_gen_hook()
}
}
}
+
+void quest_god_player_level_hook(int gained)
+{
+ if (gained <= 0)
+ {
+ return;
+ }
+
+ /* check player is worshipping a god, not already on a god quest. */
+ if ((p_ptr->astral) ||
+ (p_ptr->pgod <= 0) ||
+ (get_status() == QUEST_STATUS_TAKEN) ||
+ (get_status() == QUEST_STATUS_FAILED) ||
+ (get_quests_given() >= MAX_NUM_GOD_QUESTS()) ||
+ (magik(CHANCE_OF_GOD_QUEST) == FALSE) ||
+ ((dungeon_type == DUNGEON_GOD) &&
+ (dun_level > 0)) ||
+ (p_ptr->lev <= get_dun_minplev()))
+ {
+ /* Don't let a player get quests with trickery */
+ if (p_ptr->lev > get_dun_minplev())
+ {
+ set_dun_minplev(p_ptr->lev);
+ }
+ return;
+ }
+ else
+ {
+ /* each god has different characteristics, so the quests are differnet depending on your god */
+ setup_relic_number();
+
+ /* This var will need resetting */
+ set_relic_generated(FALSE);
+ set_status(QUEST_STATUS_TAKEN);
+ set_quests_given(get_quests_given() + 1);
+
+ /* actually place the dungeon in a random place */
+ quest_god_place_rand_dung();
+
+ /* store the variables of the coords where the player was given the quest */
+ if (p_ptr->wild_mode)
+ {
+ set_player_x(p_ptr->px);
+ set_player_y(p_ptr->py);
+ }
+ else
+ {
+ set_player_x(p_ptr->wilderness_x);
+ set_player_y(p_ptr->wilderness_y);
+ }
+
+ /* God issues instructions */
+ cmsg_format(TERM_L_BLUE, "The voice of %s booms in your head:", deity_info[p_ptr->pgod].name);
+
+ cmsg_print(TERM_YELLOW, "'I have a task for thee.");
+ cmsg_print(TERM_YELLOW, "Centuries ago an ancient relic of mine was broken apart.");
+ cmsg_print(TERM_YELLOW, "The pieces of it have been lost in fallen temples.");
+ cmsg_print(TERM_YELLOW, "Thou art to find my lost temple and retrieve a piece of the relic.");
+ cmsg_print(TERM_YELLOW, "When thy task is done, thou art to lift it in the air and call upon my name.");
+ cmsg_print(TERM_YELLOW, "I shall then come to reclaim what is mine!");
+
+ msg_directions();
+
+ /* Prepare depth of dungeon. If this was
+ * generated in set_god_dungeon_attributes(),
+ * then we'd have trouble if someone levelled
+ * up in the dungeon! */
+ set_dun_mindepth(p_ptr->lev*2/3);
+ set_dun_maxdepth(get_dun_mindepth() + 4);
+ }
+}
diff --git a/src/quest.pkg b/src/quest.pkg
index 3bb707a4..91f0e780 100644
--- a/src/quest.pkg
+++ b/src/quest.pkg
@@ -175,3 +175,4 @@ extern void quest_god_set_god_dungeon_attributes_varda();
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);