summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2012-04-06 11:40:03 +0200
committerBardur Arantsson <bardur@scientician.net>2012-04-07 15:28:26 +0200
commit3f819c170739b098f9f7951fc9c2ff407f3bbf03 (patch)
tree911a13dd8d57a68c701fe4d38dd82653482abbfa
parent6a860ab9022123d9fc5387424ef49eb3a814c64b (diff)
Lua: Moved corruption "can_gain" checks to C
-rw-r--r--lib/core/crpt_aux.lua6
-rw-r--r--lib/mods/theme/core/crpt_aux.lua6
-rw-r--r--lib/mods/theme/scpt/corrupt.lua261
-rw-r--r--lib/scpt/corrupt.lua8
-rw-r--r--src/externs.h1
-rw-r--r--src/lua_bind.c45
-rw-r--r--src/player.pkg1
7 files changed, 49 insertions, 279 deletions
diff --git a/lib/core/crpt_aux.lua b/lib/core/crpt_aux.lua
index c1772c04..85cddbf3 100644
--- a/lib/core/crpt_aux.lua
+++ b/lib/core/crpt_aux.lua
@@ -55,11 +55,7 @@ function test_depend_corrupt(corrupt, can_gain)
end
-- are we even allowed to get it?
- if __corruptions[corrupt].can_gain and (not __corruptions[corrupt].can_gain()) then
- return FALSE
- end
-
- return TRUE
+ return player_can_gain_corruption(corrupt)
end
-- Gain a new corruption
diff --git a/lib/mods/theme/core/crpt_aux.lua b/lib/mods/theme/core/crpt_aux.lua
index c1772c04..85cddbf3 100644
--- a/lib/mods/theme/core/crpt_aux.lua
+++ b/lib/mods/theme/core/crpt_aux.lua
@@ -55,11 +55,7 @@ function test_depend_corrupt(corrupt, can_gain)
end
-- are we even allowed to get it?
- if __corruptions[corrupt].can_gain and (not __corruptions[corrupt].can_gain()) then
- return FALSE
- end
-
- return TRUE
+ return player_can_gain_corruption(corrupt)
end
-- Gain a new corruption
diff --git a/lib/mods/theme/scpt/corrupt.lua b/lib/mods/theme/scpt/corrupt.lua
index 5cacd2b7..440a1d81 100644
--- a/lib/mods/theme/scpt/corrupt.lua
+++ b/lib/mods/theme/scpt/corrupt.lua
@@ -79,15 +79,6 @@ CORRUPT_DEMON_SPIRIT = add_corruption
" Increases your intelligence by 1",
" But reduce your charisma by 2",
},
-["can_gain"] = function()
- -- Maiar can't get this one!
- local str = get_race_name()
- if str == "Maia" then
- return nil
- else
- return not nil
- end
- end,
}
CORRUPT_DEMON_HIDE = add_corruption
@@ -102,15 +93,6 @@ CORRUPT_DEMON_HIDE = add_corruption
" Provides immunity to fire at level 40",
" But reduces speed by your level / 7",
},
-["can_gain"] = function()
- -- Maiar can't get this one!
- local str = get_race_name()
- if str == "Maia" then
- return nil
- else
- return not nil
- end
- end,
}
CORRUPT_DEMON_BREATH = add_corruption
@@ -149,15 +131,6 @@ CORRUPT_DEMON_REALM = add_corruption
[CORRUPT_DEMON_HIDE] = TRUE,
[CORRUPT_DEMON_BREATH] = TRUE
},
-["can_gain"] = function()
- -- Maiar can't get this one!
- local str = get_race_name()
- if str == "Maia" then
- return nil
- else
- return not nil
- end
- end,
}
@@ -175,15 +148,6 @@ CORRUPT_RANDOM_TELEPORT = add_corruption
{
" Randomly teleports you around",
},
-["can_gain"] = function()
- -- Maiar can't get this one!
- local str = get_race_name()
- if str == "Maia" then
- return nil
- else
- return not nil
- end
- end,
-- No oppose field, it will be automatically set when we declare the anti-telep corruption to oppose us
["hooks"] =
{
@@ -218,15 +182,6 @@ CORRUPT_ANTI_TELEPORT = add_corruption
{
[CORRUPT_RANDOM_TELEPORT] = TRUE
},
- ["can_gain"] = function()
- -- Maiar can't get this one!
- local str = get_race_name()
- if str == "Maia" then
- return nil
- else
- return not nil
- end
- end,
["hooks"] =
{
[HOOK_BIRTH_OBJECTS] = function()
@@ -265,15 +220,6 @@ CORRUPT_TROLL_BLOOD = add_corruption
" It also enables you to feel the presence of other troll beings",
" But it will make your presence more noticeable and aggravating",
},
- ["can_gain"] = function()
- -- Ok trolls should not get this one. never.
- local str = get_race_name()
- if (str == "Maia") or (str == "Troll") then
- return nil
- else
- return not nil
- end
- end,
}
-- The vampire corruption set
@@ -290,15 +236,6 @@ CORRUPT_VAMPIRE_TEETH = add_corruption
" Your teeth allow you to drain blood to feed yourself",
" However your stomach now only accepts blood.",
},
- ["can_gain"] = function()
- -- Maiar can't get this one!
- local str = get_race_name()
- if str == "Maia" then
- return nil
- else
- return not nil
- end
- end,
["allow"] = function()
if test_race_flags(1, PR1_NO_SUBRACE_CHANGE) == FALSE then return not nil else return nil end
end,
@@ -330,15 +267,6 @@ CORRUPT_VAMPIRE_STRENGTH = add_corruption
{
[CORRUPT_VAMPIRE_TEETH] = TRUE,
},
- ["can_gain"] = function()
- -- Maiar can't get this one!
- local str = get_race_name()
- if str == "Maia" then
- return nil
- else
- return not nil
- end
- end,
["gain"] = function()
-- Apply the bonuses/penalities
subrace(SUBRACE_SAVE).r_mhp = subrace(SUBRACE_SAVE).r_mhp + 1
@@ -376,15 +304,6 @@ CORRUPT_VAMPIRE_VAMPIRE = add_corruption
{
[CORRUPT_VAMPIRE_STRENGTH] = TRUE,
},
- ["can_gain"] = function()
- -- Maiar can't get this one!
- local str = get_race_name()
- if str == "Maia" then
- return nil
- else
- return not nil
- end
- end,
["gain"] = function()
-- Be a Vampire and be proud of it
local title = get_subrace_title(SUBRACE_SAVE)
@@ -420,15 +339,6 @@ MUT1_SPIT_ACID = add_corruption
" Damage=level Radius 1+(level/30)",
" Level=9, Cost=9, Stat=DEX, Difficulty=15",
},
- ["can_gain"] = function()
- -- Maiar can't get this one!
- local str = get_race_name()
- if str == "Maia" then
- return nil
- else
- return not nil
- end
- end,
["hooks"] =
{
[HOOK_CALC_POWERS] = function()
@@ -449,15 +359,6 @@ MUT1_BR_FIRE = add_corruption
" Damage=2*level Radius 1+(level/20)",
" Level=20, Cost=10, Stat=CON, Difficulty=18",
},
- ["can_gain"] = function()
- -- Maiar can't get this one!
- local str = get_race_name()
- if str == "Maia" then
- return nil
- else
- return not nil
- end
- end,
["hooks"] =
{
[HOOK_CALC_POWERS] = function()
@@ -478,15 +379,6 @@ MUT1_HYPN_GAZE = add_corruption
" Power=level",
" Level=12, Cost=12, Stat=CHR, Difficulty=18",
},
- ["can_gain"] = function()
- -- Maiar can't get this one!
- local str = get_race_name()
- if str == "Maia" then
- return nil
- else
- return not nil
- end
- end,
["hooks"] =
{
[HOOK_CALC_POWERS] = function()
@@ -507,15 +399,6 @@ MUT1_TELEKINES = add_corruption
" Max weight equal to (level) pounds",
" Level=9, Cost=9, Stat=WIS, Difficulty=14",
},
- ["can_gain"] = function()
- -- Maiar can't get this one!
- local str = get_race_name()
- if str == "Maia" then
- return nil
- else
- return not nil
- end
- end,
["hooks"] =
{
[HOOK_CALC_POWERS] = function()
@@ -536,15 +419,6 @@ MUT1_VTELEPORT = add_corruption
" Distance 10+4*level squares",
" Level=7, Cost=7, Stat=WIS, Difficulty=15",
},
- ["can_gain"] = function()
- -- Maiar can't get this one!
- local str = get_race_name()
- if str == "Maia" then
- return nil
- else
- return not nil
- end
- end,
["hooks"] =
{
[HOOK_CALC_POWERS] = function()
@@ -565,15 +439,6 @@ MUT1_MIND_BLST = add_corruption
" Psi Damage (3+(level-1)/5)d3",
" Level=5, Cost=3, Stat=WIS, Difficulty=15",
},
- ["can_gain"] = function()
- -- Maiar can't get this one!
- local str = get_race_name()
- if str == "Maia" then
- return nil
- else
- return not nil
- end
- end,
["hooks"] =
{
[HOOK_CALC_POWERS] = function()
@@ -595,15 +460,6 @@ MUT1_VAMPIRISM = add_corruption
" heals you and satiates you. Doesn't work on all monsters",
" Level=4, Cost=5, Stat=CON, Difficulty=9",
},
- ["can_gain"] = function()
- -- Maiar can't get this one!
- local str = get_race_name()
- if str == "Maia" then
- return nil
- else
- return not nil
- end
- end,
["hooks"] =
{
[HOOK_CALC_POWERS] = function()
@@ -624,15 +480,6 @@ MUT1_SMELL_MET = add_corruption
" Radius 25",
" Level=3, Cost=2, Stat=INT, Difficulty=12",
},
- ["can_gain"] = function()
- -- Maiar can't get this one!
- local str = get_race_name()
- if str == "Maia" then
- return nil
- else
- return not nil
- end
- end,
["hooks"] =
{
[HOOK_CALC_POWERS] = function()
@@ -653,15 +500,6 @@ MUT1_SMELL_MON = add_corruption
" Radius 25",
" Level=5, Cost=4, Stat=INT, Difficulty=15",
},
- ["can_gain"] = function()
- -- Maiar can't get this one!
- local str = get_race_name()
- if str == "Maia" then
- return nil
- else
- return not nil
- end
- end,
["hooks"] =
{
[HOOK_CALC_POWERS] = function()
@@ -681,15 +519,6 @@ MUT1_BLINK = add_corruption
" You can teleport yourself short distances (10 squares).",
" Level=3, Cost=3, Stat=WIS, Difficulty=12",
},
- ["can_gain"] = function()
- -- Maiar can't get this one!
- local str = get_race_name()
- if str == "Maia" then
- return nil
- else
- return not nil
- end
- end,
["hooks"] =
{
[HOOK_CALC_POWERS] = function()
@@ -710,15 +539,6 @@ MUT1_EAT_ROCK = add_corruption
" leaving an empty space behind.",
" Level=8, Cost=12, Stat=CON, Difficulty=18",
},
- ["can_gain"] = function()
- -- Maiar can't get this one!
- local str = get_race_name()
- if str == "Maia" then
- return nil
- else
- return not nil
- end
- end,
["hooks"] =
{
[HOOK_CALC_POWERS] = function()
@@ -739,15 +559,6 @@ MUT1_SWAP_POS = add_corruption
" unless it resists teleportation.",
" Level=15, Cost=12, Stat=DEX, Difficulty=16",
},
- ["can_gain"] = function()
- -- Maiar can't get this one!
- local str = get_race_name()
- if str == "Maia" then
- return nil
- else
- return not nil
- end
- end,
["hooks"] =
{
[HOOK_CALC_POWERS] = function()
@@ -768,15 +579,6 @@ MUT1_SHRIEK = add_corruption
" Damage=level*4, Radius=8, centered on player",
" Level=4, Cost=4, Stat=CON, Difficulty=6",
},
- ["can_gain"] = function()
- -- Maiar can't get this one!
- local str = get_race_name()
- if str == "Maia" then
- return nil
- else
- return not nil
- end
- end,
["hooks"] =
{
[HOOK_CALC_POWERS] = function()
@@ -797,15 +599,6 @@ MUT1_ILLUMINE = add_corruption
" Damage=2d(level/2) Radius=(level/10)+1",
" Level=3, Cost=2, Stat=INT, Difficulty=10",
},
- ["can_gain"] = function()
- -- Maiar can't get this one!
- local str = get_race_name()
- if str == "Maia" then
- return nil
- else
- return not nil
- end
- end,
["hooks"] =
{
[HOOK_CALC_POWERS] = function()
@@ -826,15 +619,6 @@ MUT1_DET_CURSE = add_corruption
" It detects cursed items in the inventory",
" Level=7, Cost=14, Stat=WIS, Difficulty=14",
},
- ["can_gain"] = function()
- -- Maiar can't get this one!
- local str = get_race_name()
- if str == "Maia" then
- return nil
- else
- return not nil
- end
- end,
["hooks"] =
{
[HOOK_CALC_POWERS] = function()
@@ -855,15 +639,6 @@ MUT1_BERSERK = add_corruption
" It grants super-heroism. Duration=10+1d(level)",
" Level=8, Cost=8, Stat=STR, Difficulty=14",
},
- ["can_gain"] = function()
- -- Maiar can't get this one!
- local str = get_race_name()
- if str == "Maia" then
- return nil
- else
- return not nil
- end
- end,
["hooks"] =
{
[HOOK_CALC_POWERS] = function()
@@ -885,15 +660,6 @@ MUT1_MIDAS_TCH = add_corruption
" Turns a non-artifact object into 1/3 its value in gold",
" Level=10, Cost=5, Stat=INT, Difficulty=12",
},
- ["can_gain"] = function()
- -- Maiar can't get this one!
- local str = get_race_name()
- if str == "Maia" then
- return nil
- else
- return not nil
- end
- end,
["hooks"] =
{
[HOOK_CALC_POWERS] = function()
@@ -914,15 +680,6 @@ MUT1_GROW_MOLD = add_corruption
" Summons up to 8 molds around the player",
" Level=1, Cost=6, Stat=CON, Difficulty=14",
},
- ["can_gain"] = function()
- -- Maiar can't get this one!
- local str = get_race_name()
- if str == "Maia" then
- return nil
- else
- return not nil
- end
- end,
["hooks"] =
{
[HOOK_CALC_POWERS] = function()
@@ -944,15 +701,6 @@ MUT1_RESIST = add_corruption
" elements and poison. Duration=20 + d20",
" Level=10, Cost=12, Stat=CON, Difficulty=12",
},
- ["can_gain"] = function()
- -- Maiar can't get this one!
- local str = get_race_name()
- if str == "Maia" then
- return nil
- else
- return not nil
- end
- end,
["hooks"] =
{
[HOOK_CALC_POWERS] = function()
@@ -973,15 +721,6 @@ MUT1_EARTHQUAKE = add_corruption
" Radius=10, center on the player",
" Level=12, Cost=12, Stat=STR, Difficulty=16",
},
- ["can_gain"] = function()
- -- Maiar can't get this one!
- local str = get_race_name()
- if str == "Maia" then
- return nil
- else
- return not nil
- end
- end,
["hooks"] =
{
[HOOK_CALC_POWERS] = function()
diff --git a/lib/scpt/corrupt.lua b/lib/scpt/corrupt.lua
index ae9eff8c..f72ddf2d 100644
--- a/lib/scpt/corrupt.lua
+++ b/lib/scpt/corrupt.lua
@@ -219,14 +219,6 @@ CORRUPT_TROLL_BLOOD = add_corruption
" It also enables you to feel the presence of other troll beings",
" But it will make your presence more noticeable and aggravating",
},
- ["can_gain"] = function()
- -- Ok trolls should not get this one. never.
- if get_race_name() == "Troll" then
- return nil
- else
- return not nil
- end
- end,
}
-- The vampire corruption set
diff --git a/src/externs.h b/src/externs.h
index 97569fc0..469f9633 100644
--- a/src/externs.h
+++ b/src/externs.h
@@ -1869,6 +1869,7 @@ 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 bool_ player_can_gain_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 424d1f74..e9eb95a0 100644
--- a/src/lua_bind.c
+++ b/src/lua_bind.c
@@ -11,6 +11,7 @@
*/
#include "angband.h"
+#include <assert.h>
#include "lua.h"
#include "tolua.h"
@@ -595,9 +596,53 @@ bool_ player_has_corruption(int corruption_idx)
return FALSE;
}
+
+
return (p_ptr->corruptions[corruption_idx]);
}
+bool_ player_can_gain_corruption(int corruption_idx)
+{
+ cptr r_name = rp_ptr->title + rp_name;
+ bool_ allowed = TRUE; /* Allowed by default */
+
+ assert(corruption_idx >= 0);
+
+ if (corruption_idx == CORRUPT_TROLL_BLOOD)
+ {
+ /* Ok trolls should not get this one. never. */
+ if (streq(r_name, "Troll"))
+ {
+ allowed = FALSE;
+ }
+ }
+
+ /* Theme module adds additional restrictions for Maiar */
+
+ if (game_module_idx == MODULE_THEME)
+ {
+ if (streq(r_name, "Maia"))
+ {
+ /* We use a whitelist of corruptions for Maiar */
+ bool_ allow = FALSE;
+ if ((corruption_idx == CORRUPT_BALROG_AURA) ||
+ (corruption_idx == CORRUPT_BALROG_WINGS) ||
+ (corruption_idx == CORRUPT_BALROG_STRENGTH) ||
+ (corruption_idx == CORRUPT_BALROG_FORM) ||
+ (corruption_idx == CORRUPT_DEMON_BREATH))
+ {
+ allow = TRUE;
+ };
+
+ /* Mix result into 'allowed' flag */
+ allowed = allowed & allow;
+ }
+ }
+
+ /* Result */
+ return allowed;
+}
+
/*
* Gods
*/
diff --git a/src/player.pkg b/src/player.pkg
index f34d108b..16b280c9 100644
--- a/src/player.pkg
+++ b/src/player.pkg
@@ -1853,6 +1853,7 @@ extern s16b MUT1_GROW_MOLD;
extern s16b MUT1_RESIST;
extern s16b MUT1_EARTHQUAKE;
+extern bool player_can_gain_corruption(int corruption_idx);
/** @name Spellbinder triggers
* @{ */