From a5a4f737005258097fb46a7c746ac202575fd03e Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 2 Apr 2012 22:10:00 +0200 Subject: Lua: Move module initialization code to C --- src/dungeon.c | 16 ---------------- 1 file changed, 16 deletions(-) (limited to 'src/dungeon.c') diff --git a/src/dungeon.c b/src/dungeon.c index 6d732f00..9b384dce 100644 --- a/src/dungeon.c +++ b/src/dungeon.c @@ -5296,22 +5296,6 @@ void play_game(bool_ new_game) /* Roll new character */ if (new_game) { - s32b ret; - - /* Are we authorized to create new chars? */ - call_lua("get_module_info", "(s)", "d", "allow_birth", &ret); - - if (!ret) - { - msg_box("Sorry, this module does not allow character creation.", -1, -1); - - /* Close stuff */ - close_game(); - - /* Quit */ - quit(NULL); - } - process_hooks(HOOK_INIT, "()"); /* The dungeon is not ready */ -- cgit v1.2.3 From e620b7e9e0b6a70f4c350c84a7c18ea2b523eab4 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Fri, 6 Apr 2012 15:11:18 +0200 Subject: Lua: Refactor HOOK_PROCESS_WORLD code from corrupt.lua to C --- src/dungeon.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'src/dungeon.c') diff --git a/src/dungeon.c b/src/dungeon.c index 9b384dce..bcd727ca 100644 --- a/src/dungeon.c +++ b/src/dungeon.c @@ -1015,6 +1015,52 @@ void apply_effect(int y, int x) bool_ is_recall = FALSE; +/* + * Hook for corruptions + */ +static void process_world_corruptions() +{ + if (player_has_corruption(CORRUPT_RANDOM_TELEPORT)) + { + if (rand_int(300) == 1) + { + if (magik(70)) + { + if (get_check("Teleport?")) + { + teleport_player(50); + } + else + { + disturb(0, 0); + msg_print("Your corruption takes over you, you teleport!"); + teleport_player(50); + } + } + } + } + + if (player_has_corruption(CORRUPT_ANTI_TELEPORT)) + { + if (p_ptr->corrupt_anti_teleport_stopped) + { + int amt = p_ptr->msp + p_ptr->csp; + amt = amt / 100; + if (amt < 1) { + amt = 1; + } + increase_mana(-amt); + if (p_ptr->csp == 0) + { + p_ptr->corrupt_anti_teleport_stopped = FALSE; + msg_print("You stop controlling your corruption."); + p_ptr->update = p_ptr->update | PU_BONUS; + } + } + } +} + + /* * Handle certain things once every 10 game turns * @@ -1061,6 +1107,9 @@ static void process_world(void) /* Let the script live! */ process_hooks(HOOK_PROCESS_WORLD, "()"); + /* Handle corruptions */ + process_world_corruptions(); + /* Handle the player song */ check_music(); } -- cgit v1.2.3 From 462adc54506f1555582a60eb35ca077317185f05 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 10 Apr 2012 19:25:00 +0200 Subject: Lua: Gods: Move Varda's HOOK_PROCESS_WORLD to C --- src/dungeon.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) (limited to 'src/dungeon.c') diff --git a/src/dungeon.c b/src/dungeon.c index bcd727ca..ddbd36bf 100644 --- a/src/dungeon.c +++ b/src/dungeon.c @@ -1061,6 +1061,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 * @@ -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(); } -- cgit v1.2.3 From 2586acc8701593574b52922af7540d3efa83b5b9 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 10 Apr 2012 19:40:52 +0200 Subject: Lua: Gods: Move Ulmo's HOOK_PROCESS_WORLD to C --- src/dungeon.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'src/dungeon.c') diff --git a/src/dungeon.c b/src/dungeon.c index ddbd36bf..fa9da194 100644 --- a/src/dungeon.c +++ b/src/dungeon.c @@ -1120,6 +1120,49 @@ static void process_world_gods() } } } + + GOD(GOD_ULMO) + { + if (grace_delay_trigger()) + { + int i; + /* Ulmo likes the Edain (except Easterlings) */ + if (streq(race_name, "Human") || + streq(race_name, "Dunadan") || + streq(race_name, "Druadan") || + streq(race_name, "RohanKnight")) + { + inc_piety(GOD_ALL, 2); + } + else if (streq(race_name, "Easterling") || + streq(race_name, "Demon") || + streq(race_name, "Orc")) + { + /* hated races */ + inc_piety(GOD_ALL, -2); + } + else + { + inc_piety(GOD_ALL, 1); + } + + if (p_ptr->praying) + { + inc_piety(GOD_ALL, -1); + } + + /* Gain 1 point for each trident in inventory */ + for (i = 0; i < INVEN_TOTAL; i++) + { + if ((p_ptr->inventory[i].tval == TV_POLEARM) && + (p_ptr->inventory[i].sval == SV_TRIDENT)) + { + inc_piety(GOD_ALL, 1); + } + } + } + } + } /* -- cgit v1.2.3 From 767d7864bbeff83c8ad2f70a86dd5b8445cdccc7 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 10 Apr 2012 19:59:22 +0200 Subject: Lua: Gods: Move Aule's HOOK_PROCESS_WORLD to C --- src/dungeon.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) (limited to 'src/dungeon.c') diff --git a/src/dungeon.c b/src/dungeon.c index fa9da194..282def7e 100644 --- a/src/dungeon.c +++ b/src/dungeon.c @@ -1163,6 +1163,87 @@ static void process_world_gods() } } + GOD(GOD_AULE) + { + if (grace_delay_trigger()) + { + int i; + + /* Aule likes Dwarves and Dark Elves (Eol's + * influence here) */ + if (!(streq(race_name, "Dwarf") || + streq(race_name, "Petty-dwarf") || + streq(race_name, "Gnome") || + streq(race_name, "Dark-Elf"))) + { + inc_piety(GOD_ALL, -1); + } + + /* Search inventory for axe or hammer - Gain 1 + * point of grace for each hammer or axe */ + for (i = 0; i < INVEN_TOTAL; i++) + { + int tval = p_ptr->inventory[i].tval; + int sval = p_ptr->inventory[i].sval; + + switch (tval) + { + case TV_AXE: + inc_piety(GOD_ALL, 1); + break; + + case TV_HAFTED: + if ((sval == SV_WAR_HAMMER) || + (sval == SV_LUCERN_HAMMER) || + (sval == SV_GREAT_HAMMER)) + { + inc_piety(GOD_ALL, 1); + } + break; + } + } + + /* Praying may grant you a free stone skin + * once in a while */ + if (p_ptr->praying) + { + int chance; + s32b grace; + + inc_piety(GOD_ALL, -2); + grace = p_ptr->grace; /* shorthand */ + + chance = 1; + if (grace >= 50000) + { + chance = 50000; + } + else + { + chance = 50000 - grace; + } + + if (randint(100000) <= 100000 / chance) + { + s16b type = 0; + + if (grace >= 10000) + { + type = SHIELD_COUNTER; + } + + set_shield( + randint(10) + 10 + (grace / 100), + 10 + (grace / 100), + type, + 2 + (grace / 200), + 3 + (grace / 400)); + + msg_print("Aule casts Stone Skin on you."); + } + } + } + } } /* -- cgit v1.2.3 From 4904124f7669d16c28271c1b94bc78633c699723 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 10 Apr 2012 20:09:44 +0200 Subject: Lua: Gods: Move Mandos's HOOK_PROCESS_WORLD to C --- src/dungeon.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/dungeon.c') diff --git a/src/dungeon.c b/src/dungeon.c index 282def7e..db936b8a 100644 --- a/src/dungeon.c +++ b/src/dungeon.c @@ -1090,6 +1090,7 @@ static bool_ grace_delay_trigger() static void process_world_gods() { const char *race_name = rp_ptr->title + rp_name; + const char *subrace_name = rmp_ptr->title + rmp_name; GOD(GOD_VARDA) { @@ -1244,6 +1245,41 @@ static void process_world_gods() } } } + + GOD(GOD_MANDOS) + { + if (grace_delay_trigger()) + { + /* He loves astral beings */ + if (streq(subrace_name, "LostSoul")) + { + inc_piety(GOD_ALL, 1); + } + + /* He likes High Elves only, though, as races */ + if (!streq(race_name, "High-Elf")) + { + inc_piety(GOD_ALL, -1); + } + + /* Really hates vampires and demons */ + if (streq(subrace_name, "Vampire") || + streq(race_name, "Demon")) + { + inc_piety(GOD_ALL, -10); + } + else + { + inc_piety(GOD_ALL, 2); + } + /* he really doesn't like to be disturbed */ + if (p_ptr->praying) + { + inc_piety(GOD_ALL, -5); + } + } + } + } /* -- cgit v1.2.3 From b34352dcd834057993a5e4c146b5b61cca41da15 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 10 Apr 2012 20:17:39 +0200 Subject: Lua: Gods: Move GRACE_DELAY Lua variable to player_type struct --- src/dungeon.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src/dungeon.c') diff --git a/src/dungeon.c b/src/dungeon.c index db936b8a..57aafb0b 100644 --- a/src/dungeon.c +++ b/src/dungeon.c @@ -1066,14 +1066,12 @@ static void process_world_corruptions() */ 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)); + p_ptr->grace_delay++; - if (new_grace_delay >= 15) + if (p_ptr->grace_delay >= 15) { /* reset */ - exec_lua("GRACE_DELAY = 0"); + p_ptr->grace_delay = 0; /* triggered */ return TRUE; } -- cgit v1.2.3 From 571ab5e1b1e20c8dc87a48a518caeee6f4e8a825 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 11 Apr 2012 19:44:49 +0200 Subject: Lua: Move intros to C --- src/dungeon.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/dungeon.c') diff --git a/src/dungeon.c b/src/dungeon.c index 57aafb0b..ec2ab0e4 100644 --- a/src/dungeon.c +++ b/src/dungeon.c @@ -5567,7 +5567,8 @@ void play_game(bool_ new_game) /* Roll new character */ if (new_game) { - process_hooks(HOOK_INIT, "()"); + /* Show intro */ + modules[game_module_idx].intro(); /* The dungeon is not ready */ character_dungeon = FALSE; -- cgit v1.2.3 From 6ef98743b002c48fb3bf720fb07936e34926b313 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 8 May 2012 18:59:59 +0200 Subject: Lua: Move "Meta" spell functions to C --- src/dungeon.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/dungeon.c') diff --git a/src/dungeon.c b/src/dungeon.c index ec2ab0e4..fcca8a21 100644 --- a/src/dungeon.c +++ b/src/dungeon.c @@ -1345,7 +1345,14 @@ static void process_world(void) if (!t_ptr->countdown) { t_ptr->countdown = t_ptr->delay; - call_lua(t_ptr->callback, "()", ""); + if (t_ptr->callback_c) + { + t_ptr->callback_c(); + } + if (t_ptr->callback) + { + call_lua(t_ptr->callback, "()", ""); + } } } -- cgit v1.2.3 From 656d66ee0e61c74f2730e2fffbea0304129d319b Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 9 May 2012 22:42:22 +0200 Subject: Lua: Remove Lua compat bits of timer_type --- src/dungeon.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'src/dungeon.c') diff --git a/src/dungeon.c b/src/dungeon.c index fcca8a21..fd2cc546 100644 --- a/src/dungeon.c +++ b/src/dungeon.c @@ -13,6 +13,8 @@ #include "angband.h" #include "lua/lua.h" #include "tolua.h" +#include + extern lua_State* L; #define TY_CURSE_CHANCE 100 @@ -1345,14 +1347,8 @@ static void process_world(void) if (!t_ptr->countdown) { t_ptr->countdown = t_ptr->delay; - if (t_ptr->callback_c) - { - t_ptr->callback_c(); - } - if (t_ptr->callback) - { - call_lua(t_ptr->callback, "()", ""); - } + assert(t_ptr->callback != NULL); + t_ptr->callback(); } } -- cgit v1.2.3 From 3eb4eab63e98e349f2b71ea74b2ded792f15e8d8 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sun, 13 May 2012 18:49:33 +0200 Subject: Lua: Move "Music" spell functions to C --- src/dungeon.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/dungeon.c') diff --git a/src/dungeon.c b/src/dungeon.c index fd2cc546..b23a4829 100644 --- a/src/dungeon.c +++ b/src/dungeon.c @@ -950,8 +950,8 @@ static void check_music() if (p_ptr->csp < use_mana) { msg_print("You stop your spell."); - p_ptr->music_extra = MUSIC_NONE; - p_ptr->music_extra2 = MUSIC_NONE; + p_ptr->music_extra = 0; + p_ptr->music_extra2 = 0; } else { -- cgit v1.2.3 From 22290738f1f65c6b11b98c6a2db13f81dacb3d28 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 14 May 2012 07:42:28 +0200 Subject: Lua: Move "Mandos" spell functions to C --- src/dungeon.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/dungeon.c') diff --git a/src/dungeon.c b/src/dungeon.c index b23a4829..e60f1ef0 100644 --- a/src/dungeon.c +++ b/src/dungeon.c @@ -1325,9 +1325,6 @@ static void process_world(void) */ if (dun_level || (!p_ptr->wild_mode)) { - /* Let the script live! */ - process_hooks(HOOK_PROCESS_WORLD, "()"); - /* Handle corruptions */ process_world_corruptions(); @@ -2150,6 +2147,12 @@ static void process_world(void) (void)set_tim_breath(p_ptr->tim_magic_breath - 1, TRUE); } + /* Timed precognition */ + if (p_ptr->tim_precognition > 0) + { + set_tim_precognition(p_ptr->tim_precognition - 1); + } + /* Timed regen */ if (p_ptr->tim_regen) { -- cgit v1.2.3 From d98a999477698bb0a304c4995df44f2b7ef5389d Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 29 May 2012 06:25:07 +0200 Subject: Lua: Convert all the spell metadata to C code (Yay automated translation!) --- src/dungeon.c | 26 +++----------------------- 1 file changed, 3 insertions(+), 23 deletions(-) (limited to 'src/dungeon.c') diff --git a/src/dungeon.c b/src/dungeon.c index e60f1ef0..342779b2 100644 --- a/src/dungeon.c +++ b/src/dungeon.c @@ -801,30 +801,10 @@ bool_ decays(object_type *o_ptr) static int process_lasting_spell(s16b music) { - int oldtop, use_mana; + spell_type *spell = spell_at(-music); - if (music > 0) return FALSE; - - oldtop = lua_gettop(L); - - music = -music; - - /* Push the function */ - lua_getglobal(L, "exec_lasting_spell"); - - /* Push the spell */ - tolua_pushnumber(L, music); - - /* Call the function */ - if (lua_call(L, 1, 1)) - { - cmsg_format(TERM_VIOLET, "ERROR in lua_call while calling lasting spell"); - return 0; - } - - use_mana = tolua_getnumber(L, -(lua_gettop(L) - oldtop), 0); - lua_settop(L, oldtop); - return use_mana; + assert(spell->lasting_func != NULL); + return spell->lasting_func(); } static void gere_class_special() -- cgit v1.2.3 From 1f9f122249c0828c206293ba0f757f9bfd016d8e Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Thu, 7 Jun 2012 20:36:15 +0200 Subject: Lua: Move "Void Jumpgates" help to C --- src/dungeon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/dungeon.c') diff --git a/src/dungeon.c b/src/dungeon.c index 342779b2..840094c1 100644 --- a/src/dungeon.c +++ b/src/dungeon.c @@ -5625,7 +5625,7 @@ void play_game(bool_ new_game) /* Initialize hooks */ init_hooks(); - ingame_help(p_ptr->help.enabled); + init_hooks_help(); /* React to changes */ Term_xtra(TERM_XTRA_REACT, 0); -- cgit v1.2.3 From c1e4d667aaa5b99f87a99dc32131b8e941cebd35 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Fri, 8 Jun 2012 18:39:56 +0200 Subject: Lua: Add new-style handling for HOOK_END_TURN --- src/dungeon.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/dungeon.c') diff --git a/src/dungeon.c b/src/dungeon.c index 840094c1..ff3cbdb9 100644 --- a/src/dungeon.c +++ b/src/dungeon.c @@ -5321,6 +5321,11 @@ static void dungeon(void) /* Process the appropriate hooks */ process_hooks(HOOK_END_TURN, "(d)", is_quest(dun_level)); + { + hook_end_turn_in in = { is_quest(dun_level) }; + process_hooks_new(HOOK_END_TURN, &in, NULL); + } + /* Make it pulsate and live !!!! */ if ((dungeon_flags1 & DF1_EVOLVE) && dun_level) { -- cgit v1.2.3 From 625f73559675c8bc7e627cd6dc5ab924aa10a068 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 9 Jun 2012 09:49:52 +0200 Subject: Lua: Add new-style hook support for HOOK_GAME_START --- src/dungeon.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/dungeon.c') diff --git a/src/dungeon.c b/src/dungeon.c index ff3cbdb9..f4803e3b 100644 --- a/src/dungeon.c +++ b/src/dungeon.c @@ -5653,6 +5653,7 @@ void play_game(bool_ new_game) /* Ok tell the scripts that the game is about to start */ process_hooks(HOOK_GAME_START, "()"); + process_hooks_new(HOOK_GAME_START, NULL, NULL); /* Character is now "complete" */ character_generated = TRUE; -- cgit v1.2.3 From a0107d942872735f1faa0e857174a6c467180d75 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 9 Jun 2012 20:54:07 +0200 Subject: Lua: Move automatic stat gain to C --- src/dungeon.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/dungeon.c') diff --git a/src/dungeon.c b/src/dungeon.c index f4803e3b..af46976d 100644 --- a/src/dungeon.c +++ b/src/dungeon.c @@ -5631,6 +5631,7 @@ void play_game(bool_ new_game) /* Initialize hooks */ init_hooks(); init_hooks_help(); + init_hooks_module(); /* React to changes */ Term_xtra(TERM_XTRA_REACT, 0); -- cgit v1.2.3 From 6add91e17080e06cae938a31c53c94e59c7f0bfb Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 19 Jun 2012 18:32:22 +0200 Subject: Lua: Move automatizer to C --- src/dungeon.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/dungeon.c') diff --git a/src/dungeon.c b/src/dungeon.c index af46976d..ce259344 100644 --- a/src/dungeon.c +++ b/src/dungeon.c @@ -5420,7 +5420,11 @@ static void load_all_pref_files(void) process_pref_file(buf); /* Process player specific automatizer sets */ - tome_dofile_anywhere(ANGBAND_DIR_USER, format("%s.atm", player_name), FALSE); + /* TODO: Disabled temporarily because it causes duplicate + * rules on save and subsequent game load. */ + /* sprintf(buf2, "%s.atm", player_name); */ + /* path_build(buf, sizeof(buf), ANGBAND_DIR_USER, buf2); */ + /* automatizer_init(buf); */ } /* -- cgit v1.2.3 From 64e064330c5c595d0b8553028e0c5ca95c5e5392 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 19 Jun 2012 18:32:22 +0200 Subject: Lua: Remove Lua --- src/dungeon.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/dungeon.c') diff --git a/src/dungeon.c b/src/dungeon.c index ce259344..d13da812 100644 --- a/src/dungeon.c +++ b/src/dungeon.c @@ -11,12 +11,8 @@ */ #include "angband.h" -#include "lua/lua.h" -#include "tolua.h" #include -extern lua_State* L; - #define TY_CURSE_CHANCE 100 #define DG_CURSE_CHANCE 50 #define AUTO_CURSE_CHANCE 15 -- cgit v1.2.3