diff options
author | Bardur Arantsson <bardur@scientician.net> | 2012-04-05 23:42:13 +0200 |
---|---|---|
committer | Bardur Arantsson <bardur@scientician.net> | 2012-04-07 15:28:26 +0200 |
commit | 62e385cb769000cfefa052b1ab3e155314e7ac37 (patch) | |
tree | a3f9acc5147789393128df51dadd0599c4aacb5e | |
parent | a9b597979d99a53c56d2fa5b8498834364fef7a9 (diff) |
Lua: Move HOOK_CALC_BONUS corruption code to C
-rw-r--r-- | lib/core/crpt_aux.lua | 21 | ||||
-rw-r--r-- | lib/mods/theme/core/crpt_aux.lua | 21 | ||||
-rw-r--r-- | lib/mods/theme/scpt/corrupt.lua | 63 | ||||
-rw-r--r-- | lib/scpt/corrupt.lua | 63 | ||||
-rw-r--r-- | src/externs.h | 16 | ||||
-rw-r--r-- | src/lua_bind.c | 13 | ||||
-rw-r--r-- | src/player.pkg | 19 | ||||
-rw-r--r-- | src/variable.c | 18 | ||||
-rw-r--r-- | src/xtra1.c | 75 |
9 files changed, 163 insertions, 146 deletions
diff --git a/lib/core/crpt_aux.lua b/lib/core/crpt_aux.lua index 97f8d4b6..c1772c04 100644 --- a/lib/core/crpt_aux.lua +++ b/lib/core/crpt_aux.lua @@ -140,7 +140,6 @@ function add_corruption(c) assert(c.get_text, "No corruption get_text") assert(c.lose_text, "No corruption lose_text") assert(c.desc, "No corruption desc") - assert(c.hooks, "Nothing to do for corruption") if not c.random then c.random = TRUE end if not c.removable then c.removable = TRUE end if not c.allow then c.allow = function() return not nil end end @@ -155,16 +154,18 @@ function add_corruption(c) end local index, h - for index, h in c.hooks do - add_hook_script(index, "__lua__corrupt_callback"..__corruptions_callbacks_max, "__lua__corrupt_callback"..__corruptions_callbacks_max) - setglobal("__lua__corrupt_callback"..__corruptions_callbacks_max, - function (...) - if test_depend_corrupt(%__corruptions_max) == TRUE then - return call(%h, arg) + if type(c.hooks) == "table" then + for index, h in c.hooks do + add_hook_script(index, "__lua__corrupt_callback"..__corruptions_callbacks_max, "__lua__corrupt_callback"..__corruptions_callbacks_max) + setglobal("__lua__corrupt_callback"..__corruptions_callbacks_max, + function (...) + if test_depend_corrupt(%__corruptions_max) == TRUE then + return call(%h, arg) + end end - end - ) - __corruptions_callbacks_max = __corruptions_callbacks_max + 1 + ) + __corruptions_callbacks_max = __corruptions_callbacks_max + 1 + end end if type(c.desc) == "table" then diff --git a/lib/mods/theme/core/crpt_aux.lua b/lib/mods/theme/core/crpt_aux.lua index 97f8d4b6..c1772c04 100644 --- a/lib/mods/theme/core/crpt_aux.lua +++ b/lib/mods/theme/core/crpt_aux.lua @@ -140,7 +140,6 @@ function add_corruption(c) assert(c.get_text, "No corruption get_text") assert(c.lose_text, "No corruption lose_text") assert(c.desc, "No corruption desc") - assert(c.hooks, "Nothing to do for corruption") if not c.random then c.random = TRUE end if not c.removable then c.removable = TRUE end if not c.allow then c.allow = function() return not nil end end @@ -155,16 +154,18 @@ function add_corruption(c) end local index, h - for index, h in c.hooks do - add_hook_script(index, "__lua__corrupt_callback"..__corruptions_callbacks_max, "__lua__corrupt_callback"..__corruptions_callbacks_max) - setglobal("__lua__corrupt_callback"..__corruptions_callbacks_max, - function (...) - if test_depend_corrupt(%__corruptions_max) == TRUE then - return call(%h, arg) + if type(c.hooks) == "table" then + for index, h in c.hooks do + add_hook_script(index, "__lua__corrupt_callback"..__corruptions_callbacks_max, "__lua__corrupt_callback"..__corruptions_callbacks_max) + setglobal("__lua__corrupt_callback"..__corruptions_callbacks_max, + function (...) + if test_depend_corrupt(%__corruptions_max) == TRUE then + return call(%h, arg) + end end - end - ) - __corruptions_callbacks_max = __corruptions_callbacks_max + 1 + ) + __corruptions_callbacks_max = __corruptions_callbacks_max + 1 + end end if type(c.desc) == "table" then diff --git a/lib/mods/theme/scpt/corrupt.lua b/lib/mods/theme/scpt/corrupt.lua index f402add3..51d7233b 100644 --- a/lib/mods/theme/scpt/corrupt.lua +++ b/lib/mods/theme/scpt/corrupt.lua @@ -15,10 +15,6 @@ CORRUPT_BALROG_AURA = add_corruption }, ["hooks"] = { - [HOOK_CALC_BONUS] = function() - player.xtra_f3 = bor(player.xtra_f3, TR3_SH_FIRE) - player.xtra_f3 = bor(player.xtra_f3, TR3_LITE1) - end, [HOOK_READ] = function(obj) if magik(5) == TRUE then msg_print("Your demon aura burns the scroll before you read it!") @@ -41,14 +37,6 @@ CORRUPT_BALROG_WINGS = add_corruption " Creates ugly, but working, wings allowing you to fly", " But it reduces charisma by 4 and dexterity by 2" }, - ["hooks"] = - { - [HOOK_CALC_BONUS] = function() - player.xtra_f4 = bor(player.xtra_f4, TR4_FLY) - player.modify_stat(A_CHR, -4) - player.modify_stat(A_DEX, -2) - end, - }, } CORRUPT_BALROG_STRENGTH = add_corruption @@ -62,15 +50,6 @@ CORRUPT_BALROG_STRENGTH = add_corruption " Provides 3 strength and 1 constitution", " But it reduces charisma by 1 and dexterity by 3" }, - ["hooks"] = - { - [HOOK_CALC_BONUS] = function() - player.modify_stat(A_STR, 3) - player.modify_stat(A_CON, 1) - player.modify_stat(A_DEX, -3) - player.modify_stat(A_CHR, -1) - end, - }, } CORRUPT_BALROG_FORM = add_corruption @@ -120,13 +99,6 @@ CORRUPT_DEMON_SPIRIT = add_corruption return not nil end end, - ["hooks"] = - { - [HOOK_CALC_BONUS] = function() - player.modify_stat(A_INT, 1) - player.modify_stat(A_CHR, -2) - end, - }, } CORRUPT_DEMON_HIDE = add_corruption @@ -150,15 +122,6 @@ CORRUPT_DEMON_HIDE = add_corruption return not nil end end, - ["hooks"] = - { - [HOOK_CALC_BONUS] = function() - player.to_a = player.to_a + player.lev - player.dis_to_a = player.dis_to_a + player.lev - player.pspeed = player.pspeed - (player.lev / 7) - if player.lev >= 40 then player.xtra_f2 = bor(player.xtra_f2, TR2_IM_FIRE) end - end, - }, } CORRUPT_DEMON_BREATH = add_corruption @@ -214,15 +177,6 @@ CORRUPT_DEMON_REALM = add_corruption return not nil end end, - ["hooks"] = - { - [HOOK_CALC_BONUS] = function() - -- 1500 may seem a lot, but people are rather unlikely to get the corruption very soon - -- due to the dependencies - if s_info[SKILL_DAEMON + 1].mod == 0 then s_info[SKILL_DAEMON + 1].mod = 1500 end - s_info[SKILL_DAEMON + 1].hidden = FALSE; - end, - }, } @@ -252,9 +206,6 @@ CORRUPT_RANDOM_TELEPORT = add_corruption -- No oppose field, it will be automatically set when we declare the anti-telep corruption to oppose us ["hooks"] = { - [HOOK_CALC_BONUS] = function() - player.xtra_f3 = bor(player.xtra_f3, TR3_TELEPORT) - end, [HOOK_PROCESS_WORLD] = function() if rand_int(300) == 1 then if magik(70) == TRUE then @@ -303,11 +254,6 @@ CORRUPT_ANTI_TELEPORT = add_corruption [HOOK_CALC_POWERS] = function() player.add_power(POWER_COR_SPACE_TIME) end, - [HOOK_CALC_BONUS] = function() - if player.corrupt_anti_teleport_stopped == FALSE then - player.resist_continuum = TRUE - end - end, [HOOK_PROCESS_WORLD] = function() if player.corrupt_anti_teleport_stopped == TRUE then local amt = player.msp + player.csp @@ -347,13 +293,6 @@ CORRUPT_TROLL_BLOOD = add_corruption return not nil end end, - ["hooks"] = - { - [HOOK_CALC_BONUS] = function() - player.xtra_f3 = bor(player.xtra_f3, TR3_REGEN, TR3_AGGRAVATE) - player.xtra_esp = bor(player.xtra_esp, ESP_TROLL) - end, - }, } -- The vampire corruption set @@ -1082,8 +1021,6 @@ CORRUPT_ = add_corruption }, ["hooks"] = { - [HOOK_CALC_BONUS] = function() - end, }, } ]] diff --git a/lib/scpt/corrupt.lua b/lib/scpt/corrupt.lua index 550f8bc0..1435df6e 100644 --- a/lib/scpt/corrupt.lua +++ b/lib/scpt/corrupt.lua @@ -14,10 +14,6 @@ CORRUPT_BALROG_AURA = add_corruption }, ["hooks"] = { - [HOOK_CALC_BONUS] = function() - player.xtra_f3 = bor(player.xtra_f3, TR3_SH_FIRE) - player.xtra_f3 = bor(player.xtra_f3, TR3_LITE1) - end, [HOOK_READ] = function(obj) if magik(5) == TRUE then msg_print("Your demon aura burns the scroll before you read it!") @@ -40,14 +36,6 @@ CORRUPT_BALROG_WINGS = add_corruption " Creates ugly, but working, wings allowing you to fly", " But it reduces charisma by 4 and dexterity by 2" }, - ["hooks"] = - { - [HOOK_CALC_BONUS] = function() - player.xtra_f4 = bor(player.xtra_f4, TR4_FLY) - player.modify_stat(A_CHR, -4) - player.modify_stat(A_DEX, -2) - end, - }, } CORRUPT_BALROG_STRENGTH = add_corruption @@ -61,15 +49,6 @@ CORRUPT_BALROG_STRENGTH = add_corruption " Provides 3 strength and 1 constitution", " But it reduces charisma by 1 and dexterity by 3" }, - ["hooks"] = - { - [HOOK_CALC_BONUS] = function() - player.modify_stat(A_STR, 3) - player.modify_stat(A_CON, 1) - player.modify_stat(A_DEX, -3) - player.modify_stat(A_CHR, -1) - end, - }, } CORRUPT_BALROG_FORM = add_corruption @@ -110,13 +89,6 @@ CORRUPT_DEMON_SPIRIT = add_corruption " Increases your intelligence by 1", " But reduce your charisma by 2", }, - ["hooks"] = - { - [HOOK_CALC_BONUS] = function() - player.modify_stat(A_INT, 1) - player.modify_stat(A_CHR, -2) - end, - }, } CORRUPT_DEMON_HIDE = add_corruption @@ -131,15 +103,6 @@ CORRUPT_DEMON_HIDE = add_corruption " Provides immunity to fire at level 40", " But reduces speed by your level / 7", }, - ["hooks"] = - { - [HOOK_CALC_BONUS] = function() - player.to_a = player.to_a + player.lev - player.dis_to_a = player.dis_to_a + player.lev - player.pspeed = player.pspeed - (player.lev / 7) - if player.lev >= 40 then player.xtra_f2 = bor(player.xtra_f2, TR2_IM_FIRE) end - end, - }, } CORRUPT_DEMON_BREATH = add_corruption @@ -186,15 +149,6 @@ CORRUPT_DEMON_REALM = add_corruption [CORRUPT_DEMON_HIDE] = TRUE, [CORRUPT_DEMON_BREATH] = TRUE }, - ["hooks"] = - { - [HOOK_CALC_BONUS] = function() - -- 1500 may seem a lot, but people are rather unlikely to get the corruption very soon - -- due to the dependencies - if s_info[SKILL_DAEMON + 1].mod == 0 then s_info[SKILL_DAEMON + 1].mod = 1500 end - s_info[SKILL_DAEMON + 1].hidden = FALSE; - end, - }, } @@ -215,9 +169,6 @@ CORRUPT_RANDOM_TELEPORT = add_corruption -- No oppose field, it will be automatically set when we declare the anti-telep corruption to oppose us ["hooks"] = { - [HOOK_CALC_BONUS] = function() - player.xtra_f3 = bor(player.xtra_f3, TR3_TELEPORT) - end, [HOOK_PROCESS_WORLD] = function() if rand_int(300) == 1 then if magik(70) == TRUE then @@ -257,11 +208,6 @@ CORRUPT_ANTI_TELEPORT = add_corruption [HOOK_CALC_POWERS] = function() player.add_power(POWER_COR_SPACE_TIME) end, - [HOOK_CALC_BONUS] = function() - if player.corrupt_anti_teleport_stopped == FALSE then - player.resist_continuum = TRUE - end - end, [HOOK_PROCESS_WORLD] = function() if player.corrupt_anti_teleport_stopped == TRUE then local amt = player.msp + player.csp @@ -300,13 +246,6 @@ CORRUPT_TROLL_BLOOD = add_corruption return not nil end end, - ["hooks"] = - { - [HOOK_CALC_BONUS] = function() - player.xtra_f3 = bor(player.xtra_f3, TR3_REGEN, TR3_AGGRAVATE) - player.xtra_esp = bor(player.xtra_esp, ESP_TROLL) - end, - }, } -- The vampire corruption set @@ -426,8 +365,6 @@ CORRUPT_ = add_corruption }, ["hooks"] = { - [HOOK_CALC_BONUS] = function() - end, }, } ]] diff --git a/src/externs.h b/src/externs.h index 6821fd30..c8e34c84 100644 --- a/src/externs.h +++ b/src/externs.h @@ -604,6 +604,20 @@ extern s32b max_gods; extern timer_type *gl_timers; extern s16b tim_precognition; extern const char *get_version_string(); +extern s16b CORRUPT_BALROG_AURA; +extern s16b CORRUPT_BALROG_WINGS; +extern s16b CORRUPT_BALROG_STRENGTH; +extern s16b CORRUPT_BALROG_FORM; +extern s16b CORRUPT_DEMON_SPIRIT; +extern s16b CORRUPT_DEMON_HIDE; +extern s16b CORRUPT_DEMON_BREATH; +extern s16b CORRUPT_DEMON_REALM; +extern s16b CORRUPT_RANDOM_TELEPORT; +extern s16b CORRUPT_ANTI_TELEPORT; +extern s16b CORRUPT_TROLL_BLOOD; +extern s16b CORRUPT_VAMPIRE_TEETH; +extern s16b CORRUPT_VAMPIRE_STRENGTH; +extern s16b CORRUPT_VAMPIRE_VAMPIRE; /* plots.c */ extern FILE *hook_file; @@ -1834,6 +1848,8 @@ extern void lua_delete_list(list_type *, int size); extern void lua_add_to_list(list_type *, int idx, cptr str); extern void lua_display_list(int y, int x, int h, int w, cptr title, list_type *list, int max, int begin, int sel, byte sel_color); +extern bool_ player_has_corruption(int corruption_idx); + extern cptr compass(int y, int x, int y2, int x2); extern cptr approximate_distance(int y, int x, int y2, int x2); diff --git a/src/lua_bind.c b/src/lua_bind.c index 765b8072..424d1f74 100644 --- a/src/lua_bind.c +++ b/src/lua_bind.c @@ -586,6 +586,19 @@ void lua_display_list(int y, int x, int h, int w, cptr title, list_type* list, i } /* + * Corruptions + */ +bool_ player_has_corruption(int corruption_idx) +{ + if (corruption_idx < 0) + { + return FALSE; + } + + return (p_ptr->corruptions[corruption_idx]); +} + +/* * Gods */ s16b add_new_gods(char *name) diff --git a/src/player.pkg b/src/player.pkg index ef85926a..16370b0a 100644 --- a/src/player.pkg +++ b/src/player.pkg @@ -1815,6 +1815,25 @@ struct player_type bool leaving; }; +/** + * Corruptions + */ +extern s16b CORRUPT_BALROG_AURA; +extern s16b CORRUPT_BALROG_WINGS; +extern s16b CORRUPT_BALROG_STRENGTH; +extern s16b CORRUPT_BALROG_FORM; +extern s16b CORRUPT_DEMON_SPIRIT; +extern s16b CORRUPT_DEMON_HIDE; +extern s16b CORRUPT_DEMON_BREATH; +extern s16b CORRUPT_DEMON_REALM; +extern s16b CORRUPT_RANDOM_TELEPORT; +extern s16b CORRUPT_ANTI_TELEPORT; +extern s16b CORRUPT_TROLL_BLOOD; +extern s16b CORRUPT_VAMPIRE_TEETH; +extern s16b CORRUPT_VAMPIRE_STRENGTH; +extern s16b CORRUPT_VAMPIRE_VAMPIRE; + + /** @name Spellbinder triggers * @{ */ /** @def SPELLBINDER_HP75 diff --git a/src/variable.c b/src/variable.c index 5b1afc3b..3c2295b1 100644 --- a/src/variable.c +++ b/src/variable.c @@ -1598,6 +1598,24 @@ timer_type *gl_timers = NULL; s16b tim_precognition = 0; /** + * Corruptions + */ +s16b CORRUPT_BALROG_AURA = -1; +s16b CORRUPT_BALROG_WINGS = -1; +s16b CORRUPT_BALROG_STRENGTH = -1; +s16b CORRUPT_BALROG_FORM = -1; +s16b CORRUPT_DEMON_SPIRIT = -1; +s16b CORRUPT_DEMON_HIDE = -1; +s16b CORRUPT_DEMON_BREATH = -1; +s16b CORRUPT_DEMON_REALM = -1; +s16b CORRUPT_RANDOM_TELEPORT = -1; +s16b CORRUPT_ANTI_TELEPORT = -1; +s16b CORRUPT_TROLL_BLOOD = -1; +s16b CORRUPT_VAMPIRE_TEETH = -1; +s16b CORRUPT_VAMPIRE_STRENGTH = -1; +s16b CORRUPT_VAMPIRE_VAMPIRE = -1; + +/** * Get the version string. */ const char *get_version_string() diff --git a/src/xtra1.c b/src/xtra1.c index 1d2d8ba0..c30d6e4d 100644 --- a/src/xtra1.c +++ b/src/xtra1.c @@ -2503,6 +2503,78 @@ static void calc_schools() } } +/* Apply corruptions */ +static void calc_corruptions() +{ + if (player_has_corruption(CORRUPT_BALROG_AURA)) + { + p_ptr->xtra_f3 |= TR3_SH_FIRE; + p_ptr->xtra_f3 |= TR3_LITE1; + } + + if (player_has_corruption(CORRUPT_BALROG_WINGS)) + { + p_ptr->xtra_f4 |= TR4_FLY; + p_ptr->stat_add[A_CHR] -= 4; + p_ptr->stat_add[A_DEX] -= 2; + } + + if (player_has_corruption(CORRUPT_BALROG_STRENGTH)) + { + p_ptr->stat_add[A_STR] += 3; + p_ptr->stat_add[A_CON] += 1; + p_ptr->stat_add[A_DEX] -= 3; + p_ptr->stat_add[A_CHR] -= 1; + } + + if (player_has_corruption(CORRUPT_DEMON_SPIRIT)) + { + p_ptr->stat_add[A_INT] += 1; + p_ptr->stat_add[A_CHR] -= 2; + } + + if (player_has_corruption(CORRUPT_DEMON_HIDE)) + { + p_ptr->to_a = p_ptr->to_a + p_ptr->lev; + p_ptr->dis_to_a = p_ptr->dis_to_a + p_ptr->lev; + p_ptr->pspeed = p_ptr->pspeed - (p_ptr->lev / 7); + if (p_ptr->lev >= 40) + { + p_ptr->xtra_f2 |= TR2_IM_FIRE; + } + } + + if (player_has_corruption(CORRUPT_DEMON_REALM)) + { + /* 1500 may seem a lot, but people are rather unlikely to + get the corruption very soon due to the dependencies. */ + if (s_info[SKILL_DAEMON].mod == 0) + { + s_info[SKILL_DAEMON].mod = 1500; + } + s_info[SKILL_DAEMON].hidden = FALSE; + } + + if (player_has_corruption(CORRUPT_RANDOM_TELEPORT)) + { + p_ptr->xtra_f3 |= TR3_TELEPORT; + } + + if (player_has_corruption(CORRUPT_ANTI_TELEPORT)) + { + if (p_ptr->corrupt_anti_teleport_stopped == FALSE) + { + p_ptr->resist_continuum = TRUE; + } + } + + if (player_has_corruption(CORRUPT_TROLL_BLOOD)) + { + p_ptr->xtra_f3 |= (TR3_REGEN | TR3_AGGRAVATE); + p_ptr->xtra_esp |= ESP_TROLL; + } +} + /* Apply flags */ static int extra_blows; static int extra_shots; @@ -2920,6 +2992,9 @@ void calc_bonuses(bool_ silent) /* Take care of spell schools */ calc_schools(); + /* Take care of corruptions */ + calc_corruptions(); + /* The powers gived by the wielded monster */ calc_wield_monster(); |