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 /src/q_god.c | |
parent | 3db3a9506e165a6480c51d79ee8ddb2ca509f600 (diff) |
Lua: God quest: Move generate_relic() to C
Diffstat (limited to 'src/q_god.c')
-rw-r--r-- | src/q_god.c | 88 |
1 files changed, 88 insertions, 0 deletions
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); +} |