diff options
author | Bardur Arantsson <bardur@scientician.net> | 2012-04-10 19:25:00 +0200 |
---|---|---|
committer | Bardur Arantsson <bardur@scientician.net> | 2012-04-10 20:19:16 +0200 |
commit | 462adc54506f1555582a60eb35ca077317185f05 (patch) | |
tree | 9a589398ef6d85de7d34c58a98c303c33bc5bf24 | |
parent | 5180b7b60f69b9a4a7642328df3a292cadb9fd49 (diff) |
Lua: Gods: Move Varda's HOOK_PROCESS_WORLD to C
-rw-r--r-- | lib/mods/theme/scpt/gods_new.lua | 27 | ||||
-rw-r--r-- | src/dungeon.c | 64 |
2 files changed, 64 insertions, 27 deletions
diff --git a/lib/mods/theme/scpt/gods_new.lua b/lib/mods/theme/scpt/gods_new.lua index 0a3b7283..2c227a3f 100644 --- a/lib/mods/theme/scpt/gods_new.lua +++ b/lib/mods/theme/scpt/gods_new.lua @@ -141,33 +141,6 @@ GOD_VARDA = add_god }, ["hooks"] = { - [HOOK_PROCESS_WORLD] = function() - if (player.pgod == GOD_VARDA) then - GRACE_DELAY = GRACE_DELAY + 1 - - -- piety increase if in light - if (GRACE_DELAY >= 15) then - if band(cave(player.py, player.px).info, CAVE_GLOW) ~= 0 then - set_grace(player.grace + 2) - end - if ( - (get_race_name() == "Orc") or - (get_race_name() == "Troll") or - (get_race_name() == "Dragon") or - (get_race_name() == "Demon")) then - -- Varda hates evils - set_grace(player.grace - 2) - else - set_grace(player.grace - 1) - end - - if (player.praying == TRUE) then - set_grace(player.grace - 1) - end - GRACE_DELAY = 0 - end - end - end, [HOOK_CALC_LITE] = function() if (player.pgod == GOD_VARDA) then -- increase lite radius diff --git a/src/dungeon.c b/src/dungeon.c index bcd727ca..ddbd36bf 100644 --- a/src/dungeon.c +++ b/src/dungeon.c @@ -1062,6 +1062,67 @@ static void process_world_corruptions() /* + * Shim for accessing Lua variable. + */ +static bool_ grace_delay_trigger() +{ + int grace_delay = get_lua_int("GRACE_DELAY"); + int new_grace_delay = 1 + grace_delay; + exec_lua(format("GRACE_DELAY = %d", new_grace_delay)); + + if (new_grace_delay >= 15) + { + /* reset */ + exec_lua("GRACE_DELAY = 0"); + /* triggered */ + return TRUE; + } + else + { + /* not triggered */ + return FALSE; + } +} + +/* + * Hook for gods + */ +static void process_world_gods() +{ + const char *race_name = rp_ptr->title + rp_name; + + GOD(GOD_VARDA) + { + if (grace_delay_trigger()) + { + /* Piety increases if in light. */ + if (cave[p_ptr->py][p_ptr->px].info & CAVE_GLOW) + { + inc_piety(GOD_ALL, 2); + } + + if (streq(race_name, "Orc") || + streq(race_name, "Troll") || + streq(race_name, "Dragon") || + streq(race_name, "Demon")) + { + /* Varda hates evil races */ + inc_piety(GOD_ALL, -2); + } else { + /* ... and everyone slightly less */ + inc_piety(GOD_ALL, -1); + } + + /* Prayer uses piety */ + if (p_ptr->praying) + { + inc_piety(GOD_ALL, -1); + } + } + } +} + +/* * Handle certain things once every 10 game turns * * Note that a single movement in the overhead wilderness mode @@ -1110,6 +1171,9 @@ static void process_world(void) /* Handle corruptions */ process_world_corruptions(); + /* Handle gods */ + process_world_gods(); + /* Handle the player song */ check_music(); } |