diff options
author | Bardur Arantsson <bardur@scientician.net> | 2012-04-08 21:11:11 +0200 |
---|---|---|
committer | Bardur Arantsson <bardur@scientician.net> | 2012-04-08 21:15:15 +0200 |
commit | 588796622eef2419931bf759188a90822be8574f (patch) | |
tree | c5d8957194d9c6b6a352f0e5dd330317b37b4548 | |
parent | 3db3a9506e165a6480c51d79ee8ddb2ca509f600 (diff) |
Lua: God quest: Move generate_relic() to C
-rw-r--r-- | lib/mods/theme/scpt/god.lua | 59 | ||||
-rw-r--r-- | lib/scpt/god.lua | 59 | ||||
-rw-r--r-- | src/plots.h | 1 | ||||
-rw-r--r-- | src/q_god.c | 88 | ||||
-rw-r--r-- | src/quest.pkg | 1 |
5 files changed, 94 insertions, 114 deletions
diff --git a/lib/mods/theme/scpt/god.lua b/lib/mods/theme/scpt/god.lua index 71a85660..1c932029 100644 --- a/lib/mods/theme/scpt/god.lua +++ b/lib/mods/theme/scpt/god.lua @@ -174,12 +174,12 @@ add_quest 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 - generate_relic() + quest_god_generate_relic() else -- 1/5 chance of generation chance = randint(5) if (chance == 5) then - generate_relic() + quest_god_generate_relic() else god_quest.relic_gen_tries = god_quest.relic_gen_tries + 1 end @@ -277,61 +277,6 @@ add_quest }, } --- this function generates the relic at a randomly determined place in the temple. -function generate_relic() - local tries, grid, x, y, relic - - -- initialise tries variable - tries = 1000 - - while (tries > 0) do - - tries = tries - 1 - -- get grid coordinates from current height/width, minus one to prevent relic being generated in outside wall. (would crash the game) - y = randint(cur_hgt-1) - x = randint(cur_wid-1) - grid = cave(y, x) - - -- are the coordinates on a floor, not on a permanent feature (eg stairs), and not on a trap ? - if (cave_is(grid, FF1_FLOOR) == TRUE) and (cave_is(grid, FF1_PERMANENT) == FALSE) and (grid.t_idx == 0) then break end - - end - - -- create relic - relic = create_object(TV_JUNK, god_quest.relic_num) - - -- inscribe it to prevent automatizer 'accidents' - relic.note = quark_add("quest") - - -- If no safe co-ords were found, put it in the players backpack - if tries == 0 then - - -- explain it - msg_print(TERM_L_BLUE, "You luckily stumble across the relic on the stairs!") - - if (inven_carry_okay(relic)) then - inven_carry(relic, FALSE) - else - -- no place found, drop it on the stairs - drop_near(relic, -1, player.py, player.px) - end - - else - -- drop it - drop_near(relic, -1, y, x) - end - - -- Only generate once! - god_quest.relic_generated = TRUE - - -- Reset some variables - god_quest.relic_gen_tries = 0 - -end - - - - function set_god_dungeon_attributes() -- dungeon properties altered according to which god player is worshipping, diff --git a/lib/scpt/god.lua b/lib/scpt/god.lua index cc8b8fff..bb7aa92c 100644 --- a/lib/scpt/god.lua +++ b/lib/scpt/god.lua @@ -166,12 +166,12 @@ add_quest 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 - generate_relic() + quest_god_generate_relic() else -- 1/5 chance of generation chance = randint(5) if (chance == 5) then - generate_relic() + quest_god_generate_relic() else god_quest.relic_gen_tries = god_quest.relic_gen_tries + 1 end @@ -269,61 +269,6 @@ add_quest }, } --- this function generates the relic at a randomly determined place in the temple. -function generate_relic() - local tries, grid, x, y, relic - - -- initialise tries variable - tries = 1000 - - while (tries > 0) do - - tries = tries - 1 - -- get grid coordinates from current height/width, minus one to prevent relic being generated in outside wall. (would crash the game) - y = randint(cur_hgt-1) - x = randint(cur_wid-1) - grid = cave(y, x) - - -- are the coordinates on a floor, not on a permanent feature (eg stairs), and not on a trap ? - if (cave_is(grid, FF1_FLOOR) == TRUE) and (cave_is(grid, FF1_PERMANENT) == FALSE) and (grid.t_idx == 0) then break end - - end - - -- create relic - relic = create_object(TV_JUNK, god_quest.relic_num) - - -- inscribe it to prevent automatizer 'accidents' - relic.note = quark_add("quest") - - -- If no safe co-ords were found, put it in the players backpack - if tries == 0 then - - -- explain it - msg_print(TERM_L_BLUE, "You luckily stumble across the relic on the stairs!") - - if (inven_carry_okay(relic)) then - inven_carry(relic, FALSE) - else - -- no place found, drop it on the stairs - drop_near(relic, -1, player.py, player.px) - end - - else - -- drop it - drop_near(relic, -1, y, x) - end - - -- Only generate once! - god_quest.relic_generated = TRUE - - -- Reset some variables - god_quest.relic_gen_tries = 0 - -end - - - - function set_god_dungeon_attributes() -- dungeon properties altered according to which god player is worshipping, diff --git a/src/plots.h b/src/plots.h index eaeeb818..31653f36 100644 --- a/src/plots.h +++ b/src/plots.h @@ -65,3 +65,4 @@ extern bool_ quest_fireproof_describe(FILE *fff); /******* Plot God Quest **************/ extern void quest_god_place_rand_dung(); +extern void quest_god_generate_relic(); diff --git a/src/q_god.c b/src/q_god.c index 070b2a02..5725c984 100644 --- a/src/q_god.c +++ b/src/q_god.c @@ -29,6 +29,32 @@ static void set_dung_x(int x) exec_lua(format("god_quest.dung_x = %d", x)); } +static int get_relic_num() +{ + return get_lua_int("god_quest.relic_num"); +} + +static void set_relic_generated(bool_ v) +{ + switch (v) + { + case TRUE: + exec_lua("god_quest.relic_generated = TRUE"); + break; + case FALSE: + exec_lua("god_quest.relic_generated = FALSE"); + break; + default: + assert(FALSE); + break; + } +} + +static void set_relic_gen_tries(int v) +{ + exec_lua(format("god_quest.relic_gen_tries = %d", v)); +} + void quest_god_place_rand_dung() { int x = -1, y = -1, tries; @@ -95,3 +121,65 @@ void quest_god_place_rand_dung() set_dung_x(x); set_dung_y(y); } + +void quest_god_generate_relic() +{ + int tries = 1000, x = -1, y = -1; + object_type relic; + + tries = 1000; + + while (tries > 0) + { + cave_type *c_ptr; + tries = tries - 1; + /* get grid coordinates from current height/width, + * minus one to prevent relic being generated in + * outside wall. (would crash the game) */ + y = randint(cur_hgt-1); + x = randint(cur_wid-1); + c_ptr = &cave[y][x]; + + /* are the coordinates on a floor, not on a permanent feature (eg stairs), and not on a trap ? */ + if ((f_info[c_ptr->feat].flags1 & FF1_FLOOR) && + (!(f_info[c_ptr->feat].flags1 & FF1_PERMANENT)) && + (c_ptr->t_idx == 0)) + { + break; + } + } + + /* create relic */ + object_prep(&relic, lookup_kind(TV_JUNK, get_relic_num())); + + /* inscribe it to prevent automatizer 'accidents' */ + relic.note = quark_add("quest"); + + /* If no safe co-ords were found, put it in the players backpack */ + if (tries == 0) + { + /* explain it */ + cmsg_print(TERM_L_BLUE, "You luckily stumble across the relic on the stairs!"); + + if (inven_carry_okay(&relic)) + { + inven_carry(&relic, FALSE); + } + else + { + /* no place found, drop it on the stairs */ + drop_near(&relic, -1, p_ptr->py, p_ptr->px); + } + } + else + { + /* drop it */ + drop_near(&relic, -1, y, x); + } + + /* Only generate once! */ + set_relic_generated(TRUE); + + /* Reset some variables */ + set_relic_gen_tries(0); +} diff --git a/src/quest.pkg b/src/quest.pkg index 3b8fc922..e5780e3f 100644 --- a/src/quest.pkg +++ b/src/quest.pkg @@ -164,3 +164,4 @@ extern void desc_quest @ quest_desc(int q_idx, int d, char *desc); * God quest */ extern void quest_god_place_rand_dung(); +extern void quest_god_generate_relic(); |