From 893ab1125bb3d25c184750aa146d3d6f5d82aa10 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Fri, 6 Apr 2012 16:00:55 +0200 Subject: Lua: Refactor vampire corruption logic to C --- lib/core/player.lua | 10 --------- lib/mods/theme/core/player.lua | 10 --------- lib/mods/theme/scpt/corrupt.lua | 50 +++-------------------------------------- lib/scpt/corrupt.lua | 50 +++-------------------------------------- 4 files changed, 6 insertions(+), 114 deletions(-) (limited to 'lib') diff --git a/lib/core/player.lua b/lib/core/player.lua index 16878228..03e9824f 100644 --- a/lib/core/player.lua +++ b/lib/core/player.lua @@ -123,13 +123,3 @@ add_hook_script(HOOK_MKEY, "__mkey_fct_activate", "__mkey_fct_activate") function subrace(racem) return race_mod_info[racem + 1] end - -function subrace_add_power(subrace, power) - for i = 1, 4 do - if subrace.powers[i] == -1 then - subrace.powers[i] = power - return not nil - end - end - return nil -end diff --git a/lib/mods/theme/core/player.lua b/lib/mods/theme/core/player.lua index 16878228..03e9824f 100644 --- a/lib/mods/theme/core/player.lua +++ b/lib/mods/theme/core/player.lua @@ -123,13 +123,3 @@ add_hook_script(HOOK_MKEY, "__mkey_fct_activate", "__mkey_fct_activate") function subrace(racem) return race_mod_info[racem + 1] end - -function subrace_add_power(subrace, power) - for i = 1, 4 do - if subrace.powers[i] == -1 then - subrace.powers[i] = power - return not nil - end - end - return nil -end diff --git a/lib/mods/theme/scpt/corrupt.lua b/lib/mods/theme/scpt/corrupt.lua index 2f3d30ce..1bb976df 100644 --- a/lib/mods/theme/scpt/corrupt.lua +++ b/lib/mods/theme/scpt/corrupt.lua @@ -189,15 +189,7 @@ CORRUPT_VAMPIRE_TEETH = add_corruption ["allow"] = function() if test_race_flags(1, PR1_NO_SUBRACE_CHANGE) == FALSE then return not nil else return nil end end, - ["gain"] = function() - switch_subrace(SUBRACE_SAVE, TRUE); - - subrace_add_power(subrace(SUBRACE_SAVE), PWR_VAMPIRISM) - subrace(SUBRACE_SAVE).flags1 = bor(subrace(SUBRACE_SAVE).flags1, PR1_VAMPIRE, PR1_UNDEAD, PR1_NO_SUBRACE_CHANGE) - end, - ["hooks"] = - { - }, + ["gain"] = function() player_gain_vampire_teeth() end, } CORRUPT_VAMPIRE_STRENGTH = add_corruption { @@ -217,25 +209,7 @@ CORRUPT_VAMPIRE_STRENGTH = add_corruption { [CORRUPT_VAMPIRE_TEETH] = TRUE, }, - ["gain"] = function() - -- Apply the bonuses/penalities - subrace(SUBRACE_SAVE).r_mhp = subrace(SUBRACE_SAVE).r_mhp + 1 - subrace(SUBRACE_SAVE).r_exp = subrace(SUBRACE_SAVE).r_exp + 100 - - subrace(SUBRACE_SAVE).r_adj[A_STR + 1] = subrace(SUBRACE_SAVE).r_adj[A_STR + 1] + 3 - subrace(SUBRACE_SAVE).r_adj[A_INT + 1] = subrace(SUBRACE_SAVE).r_adj[A_INT + 1] + 2 - subrace(SUBRACE_SAVE).r_adj[A_WIS + 1] = subrace(SUBRACE_SAVE).r_adj[A_WIS + 1] - 3 - subrace(SUBRACE_SAVE).r_adj[A_DEX + 1] = subrace(SUBRACE_SAVE).r_adj[A_DEX + 1] - 2 - subrace(SUBRACE_SAVE).r_adj[A_CON + 1] = subrace(SUBRACE_SAVE).r_adj[A_CON + 1] + 1 - subrace(SUBRACE_SAVE).r_adj[A_CHR + 1] = subrace(SUBRACE_SAVE).r_adj[A_CHR + 1] - 4 - - -- be reborn! - do_rebirth() - cmsg_print(TERM_L_DARK, "You feel death slipping inside.") - end, - ["hooks"] = - { - }, + ["gain"] = function() player_gain_vampire_strength() end, } CORRUPT_VAMPIRE_VAMPIRE = add_corruption { @@ -254,25 +228,7 @@ CORRUPT_VAMPIRE_VAMPIRE = add_corruption { [CORRUPT_VAMPIRE_STRENGTH] = TRUE, }, - ["gain"] = function() - -- Be a Vampire and be proud of it - local title = get_subrace_title(SUBRACE_SAVE) - if title == " " or title == "Vampire" then - title = "Vampire" - subrace(SUBRACE_SAVE).place = FALSE - else - title = "Vampire "..title - end - set_subrace_title(SUBRACE_SAVE, title) - - -- Bonus/and .. not bonus :) - subrace(SUBRACE_SAVE).flags1 = bor(subrace(SUBRACE_SAVE).flags1, PR1_HURT_LITE) - subrace(SUBRACE_SAVE).oflags2[2] = bor(subrace(SUBRACE_SAVE).oflags2[2], TR2_RES_POIS, TR2_RES_NETHER, TR2_RES_COLD, TR2_RES_DARK, TR2_HOLD_LIFE) - subrace(SUBRACE_SAVE).oflags3[2] = bor(subrace(SUBRACE_SAVE).oflags3[2], TR3_LITE1) - end, - ["hooks"] = - { - }, + ["gain"] = function() player_gain_vampire() end, } -- The old activable corruptions / mutations diff --git a/lib/scpt/corrupt.lua b/lib/scpt/corrupt.lua index 81690879..27746cc9 100644 --- a/lib/scpt/corrupt.lua +++ b/lib/scpt/corrupt.lua @@ -188,15 +188,7 @@ CORRUPT_VAMPIRE_TEETH = add_corruption ["allow"] = function() if test_race_flags(1, PR1_NO_SUBRACE_CHANGE) == FALSE then return not nil else return nil end end, - ["gain"] = function() - switch_subrace(SUBRACE_SAVE, TRUE); - - subrace_add_power(subrace(SUBRACE_SAVE), PWR_VAMPIRISM) - subrace(SUBRACE_SAVE).flags1 = bor(subrace(SUBRACE_SAVE).flags1, PR1_VAMPIRE, PR1_UNDEAD, PR1_NO_SUBRACE_CHANGE) - end, - ["hooks"] = - { - }, + ["gain"] = function() player_gain_vampire_teeth() end, } CORRUPT_VAMPIRE_STRENGTH = add_corruption { @@ -216,25 +208,7 @@ CORRUPT_VAMPIRE_STRENGTH = add_corruption { [CORRUPT_VAMPIRE_TEETH] = TRUE, }, - ["gain"] = function() - -- Apply the bonuses/penalities - subrace(SUBRACE_SAVE).r_mhp = subrace(SUBRACE_SAVE).r_mhp + 1 - subrace(SUBRACE_SAVE).r_exp = subrace(SUBRACE_SAVE).r_exp + 100 - - subrace(SUBRACE_SAVE).r_adj[A_STR + 1] = subrace(SUBRACE_SAVE).r_adj[A_STR + 1] + 3 - subrace(SUBRACE_SAVE).r_adj[A_INT + 1] = subrace(SUBRACE_SAVE).r_adj[A_INT + 1] + 2 - subrace(SUBRACE_SAVE).r_adj[A_WIS + 1] = subrace(SUBRACE_SAVE).r_adj[A_WIS + 1] - 3 - subrace(SUBRACE_SAVE).r_adj[A_DEX + 1] = subrace(SUBRACE_SAVE).r_adj[A_DEX + 1] - 2 - subrace(SUBRACE_SAVE).r_adj[A_CON + 1] = subrace(SUBRACE_SAVE).r_adj[A_CON + 1] + 1 - subrace(SUBRACE_SAVE).r_adj[A_CHR + 1] = subrace(SUBRACE_SAVE).r_adj[A_CHR + 1] - 4 - - -- be reborn! - do_rebirth() - cmsg_print(TERM_L_DARK, "You feel death slipping inside.") - end, - ["hooks"] = - { - }, + ["gain"] = function() player_gain_vampire_strength() end, } CORRUPT_VAMPIRE_VAMPIRE = add_corruption { @@ -253,25 +227,7 @@ CORRUPT_VAMPIRE_VAMPIRE = add_corruption { [CORRUPT_VAMPIRE_STRENGTH] = TRUE, }, - ["gain"] = function() - -- Be a Vampire and be proud of it - local title = get_subrace_title(SUBRACE_SAVE) - if title == " " or title == "Vampire" then - title = "Vampire" - subrace(SUBRACE_SAVE).place = FALSE - else - title = "Vampire "..title - end - set_subrace_title(SUBRACE_SAVE, title) - - -- Bonus/and .. not bonus :) - subrace(SUBRACE_SAVE).flags1 = bor(subrace(SUBRACE_SAVE).flags1, PR1_HURT_LITE) - subrace(SUBRACE_SAVE).oflags2[2] = bor(subrace(SUBRACE_SAVE).oflags2[2], TR2_RES_POIS, TR2_RES_NETHER, TR2_RES_COLD, TR2_RES_DARK, TR2_HOLD_LIFE) - subrace(SUBRACE_SAVE).oflags3[2] = bor(subrace(SUBRACE_SAVE).oflags3[2], TR3_LITE1) - end, - ["hooks"] = - { - }, + ["gain"] = function() player_gain_vampire() end, } -- cgit v1.2.3