diff options
author | Bardur Arantsson <bardur@scientician.net> | 2012-04-08 23:44:37 +0200 |
---|---|---|
committer | Bardur Arantsson <bardur@scientician.net> | 2012-04-08 23:50:51 +0200 |
commit | c07642d436b48aa3687b5e74d6ec68997ed3cd99 (patch) | |
tree | e6d8917291bce2d9064cacca91ad8714bfda8fb5 | |
parent | ee2c62aa4c179945ba24a2545239328a28c8adc1 (diff) |
Lua: God quests: Move HOOK_LEVEL_END_GEN code to C
-rw-r--r-- | lib/mods/theme/scpt/god.lua | 35 | ||||
-rw-r--r-- | lib/scpt/god.lua | 35 | ||||
-rw-r--r-- | src/plots.h | 1 | ||||
-rw-r--r-- | src/q_god.c | 75 | ||||
-rw-r--r-- | src/quest.pkg | 1 |
5 files changed, 79 insertions, 68 deletions
diff --git a/lib/mods/theme/scpt/god.lua b/lib/mods/theme/scpt/god.lua index be8c09a5..d5097e85 100644 --- a/lib/mods/theme/scpt/god.lua +++ b/lib/mods/theme/scpt/god.lua @@ -153,40 +153,7 @@ add_quest end end, [HOOK_LEVEL_END_GEN] = function() - local chance - - -- Check for dungeon - if (current_dungeon_idx ~= god_quest.DUNGEON_GOD) or (quest(GOD_QUEST).status == QUEST_STATUS_UNTAKEN) then - return - -- if the relic has been created at this point, then it was created on the *PREVIOUS* call of HOOK_LEVEL_END_GEN, and - -- therefore the player has caused another level generation in the temple and hence failed the quest. - elseif (god_quest.relic_generated == TRUE) and quest(GOD_QUEST).status ~= QUEST_STATUS_FAILED then - - -- fail the quest, don't give another one, don't give this message again - quest(GOD_QUEST).status = QUEST_STATUS_FAILED - -- God issues instructions - cmsg_print(TERM_L_BLUE, "The voice of "..deity(player.pgod).name.." booms in your head:") - - cmsg_print(TERM_YELLOW, "'Thou art a fool!") - cmsg_print(TERM_YELLOW, "I told thee to look carefully for the relic. It appears thou hast missed the") - cmsg_print(TERM_YELLOW, "opportunity to claim it in my name, as I sense that those monsters who ") - cmsg_print(TERM_YELLOW, "have overrun my temple have destroyed it themselves.") - cmsg_print(TERM_YELLOW, "I shall not ask thee to do such a thing again, as thou hast failed me in this") - cmsg_print(TERM_YELLOW, "simple task!'") - else - -- Force relic generation on 5th attempt if others have been unsuccessful. - if (god_quest.relic_gen_tries == 4) and (god_quest.relic_generated == FALSE) then - quest_god_generate_relic() - else - -- 1/5 chance of generation - chance = randint(5) - if (chance == 5) then - quest_god_generate_relic() - else - god_quest.relic_gen_tries = god_quest.relic_gen_tries + 1 - end - end - end + quest_god_level_end_gen_hook() end, [HOOK_ENTER_DUNGEON] = function(d_idx) -- call the function to set the dungeon variables (dependant on pgod) the first time we enter the dungeon diff --git a/lib/scpt/god.lua b/lib/scpt/god.lua index 938ef802..d3908a43 100644 --- a/lib/scpt/god.lua +++ b/lib/scpt/god.lua @@ -145,40 +145,7 @@ add_quest end end, [HOOK_LEVEL_END_GEN] = function() - local chance - - -- Check for dungeon - if (current_dungeon_idx ~= god_quest.DUNGEON_GOD) or (quest(GOD_QUEST).status == QUEST_STATUS_UNTAKEN) then - return - -- if the relic has been created at this point, then it was created on the *PREVIOUS* call of HOOK_LEVEL_END_GEN, and - -- therefore the player has caused another level generation in the temple and hence failed the quest. - elseif (god_quest.relic_generated == TRUE) and quest(GOD_QUEST).status ~= QUEST_STATUS_FAILED then - - -- fail the quest, don't give another one, don't give this message again - quest(GOD_QUEST).status = QUEST_STATUS_FAILED - -- God issues instructions - cmsg_print(TERM_L_BLUE, "The voice of "..deity(player.pgod).name.." booms in your head:") - - cmsg_print(TERM_YELLOW, "'Thou art a fool!") - cmsg_print(TERM_YELLOW, "I told thee to look carefully for the relic. It appears thou hast missed the") - cmsg_print(TERM_YELLOW, "opportunity to claim it in my name, as I sense that those monsters who ") - cmsg_print(TERM_YELLOW, "have overrun my temple have destroyed it themselves.") - cmsg_print(TERM_YELLOW, "I shall not ask thee to do such a thing again, as thou hast failed me in this") - cmsg_print(TERM_YELLOW, "simple task!'") - else - -- Force relic generation on 5th attempt if others have been unsuccessful. - if (god_quest.relic_gen_tries == 4) and (god_quest.relic_generated == FALSE) then - quest_god_generate_relic() - else - -- 1/5 chance of generation - chance = randint(5) - if (chance == 5) then - quest_god_generate_relic() - else - god_quest.relic_gen_tries = god_quest.relic_gen_tries + 1 - end - end - end + quest_god_level_end_gen_hook() end, [HOOK_ENTER_DUNGEON] = function(d_idx) -- call the function to set the dungeon variables (dependant on pgod) the first time we enter the dungeon diff --git a/src/plots.h b/src/plots.h index 9ec9bf80..47f5e30f 100644 --- a/src/plots.h +++ b/src/plots.h @@ -75,3 +75,4 @@ extern void quest_god_set_god_dungeon_attributes_aule(); 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(); diff --git a/src/q_god.c b/src/q_god.c index 9b302011..3c0f38a5 100644 --- a/src/q_god.c +++ b/src/q_god.c @@ -34,6 +34,16 @@ static int get_relic_num() return get_lua_int("god_quest.relic_num"); } +static int get_status() +{ + return exec_lua("return quest(GOD_QUEST).status"); +} + +static void set_status(int new_status) +{ + exec_lua(format("quest(GOD_QUEST).status = %d", new_status)); +} + static void set_relic_generated(bool_ v) { switch (v) @@ -50,11 +60,21 @@ static void set_relic_generated(bool_ v) } } +static bool_ get_relic_generated() +{ + return get_lua_int("god_quest.relic_generated"); +} + static void set_relic_gen_tries(int v) { exec_lua(format("god_quest.relic_gen_tries = %d", v)); } +static int get_relic_gen_tries() +{ + return get_lua_int("god_quest.relic_gen_tries"); +} + void quest_god_place_rand_dung() { int x = -1, y = -1, tries; @@ -621,3 +641,58 @@ void quest_god_set_god_dungeon_attributes_mandos() d_info[DUNGEON_GOD].rules[0].r_char[4] = '\0'; d_info[DUNGEON_GOD].rules[0].mflags3 = RF3_UNDEAD | RF3_EVIL; } + +void quest_god_level_end_gen_hook() +{ + /* Check for dungeon */ + if ((dungeon_type != DUNGEON_GOD) || + (get_status() == QUEST_STATUS_UNTAKEN)) + { + return; + } + + /* if the relic has been created at this point, then it was + created on the *PREVIOUS* call of HOOK_LEVEL_END_GEN, and + therefore the player has caused another level generation in + the temple and hence failed the quest.*/ + + else if ((get_relic_generated() == TRUE) && + (get_status() != QUEST_STATUS_FAILED)) + { + /* fail the quest, don't give another one, don't give + * this message again */ + set_status(QUEST_STATUS_FAILED); + + /* 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, "'Thou art a fool!"); + cmsg_print(TERM_YELLOW, "I told thee to look carefully for the relic. It appears thou hast missed the"); + cmsg_print(TERM_YELLOW, "opportunity to claim it in my name, as I sense that those monsters who "); + cmsg_print(TERM_YELLOW, "have overrun my temple have destroyed it themselves."); + cmsg_print(TERM_YELLOW, "I shall not ask thee to do such a thing again, as thou hast failed me in this"); + cmsg_print(TERM_YELLOW, "simple task!'"); + } + + /* Force relic generation on 5th attempt if others have been + * unsuccessful. */ + + else if ((get_relic_gen_tries() == 4) && + (get_relic_generated() == FALSE)) + { + quest_god_generate_relic(); + } + + else + { + /* 1/5 chance of generation */ + if (magik(20)) + { + quest_god_generate_relic(); + } + else + { + set_relic_gen_tries(get_relic_gen_tries() + 1); + } + } +} diff --git a/src/quest.pkg b/src/quest.pkg index c2610d9e..3bb707a4 100644 --- a/src/quest.pkg +++ b/src/quest.pkg @@ -174,3 +174,4 @@ extern void quest_god_set_god_dungeon_attributes_aule(); 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(); |