summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/core/s_aux.lua97
-rw-r--r--lib/mods/theme/core/s_aux.lua97
-rw-r--r--lib/mods/theme/scpt/mkeys.lua2
-rw-r--r--lib/scpt/mkeys.lua2
-rw-r--r--src/cmd5.c2
-rw-r--r--src/externs.h1
-rw-r--r--src/lua_bind.c4
-rw-r--r--src/object.pkg1
-rw-r--r--src/object1.c5
-rw-r--r--src/spells.pkg27
-rw-r--r--src/spells1.c2
-rw-r--r--src/spells3.c6
-rw-r--r--src/spells4.c120
13 files changed, 131 insertions, 235 deletions
diff --git a/lib/core/s_aux.lua b/lib/core/s_aux.lua
index 20cf4964..76f01637 100644
--- a/lib/core/s_aux.lua
+++ b/lib/core/s_aux.lua
@@ -218,33 +218,6 @@ function get_mana(s)
return spell(s).mana + get_level(s, spell(s).mana_max - spell(s).mana, 0)
end
--- Return the amount of power(mana, piety, whatever) for the spell
-function get_power(s)
- if check_affect(s, "piety", FALSE) then
- return player.grace
- else
- return player.csp
- end
-end
-
--- Return the amount of power(mana, piety, whatever) for the spell
-function get_power_name(s)
- if check_affect(s, "piety", FALSE) then
- return "piety"
- else
- return "mana"
- end
-end
-
--- Changes the amount of power(mana, piety, whatever) for the spell
-function adjust_power(s, x)
- if check_affect(s, "piety", FALSE) then
- inc_piety(GOD_ALL, x)
- else
- increase_mana(x)
- end
-end
-
-- Get spell school name(s) as a /-separated string.
function spell_school_name(s)
local xx, sch_str
@@ -292,76 +265,6 @@ function get_spell_stat(s)
else return __tmp_spells[s].stat end
end
-function cast_school_spell(s, s_ptr, no_cost)
- local use = FALSE
-
- -- No magic
- if (player.antimagic > 0) then
- msg_print("Your anti-magic field disrupts any magic attempts.")
- return
- end
-
- -- No magic
- if (player.anti_magic == TRUE) then
- msg_print("Your anti-magic shell disrupts any magic attempts.")
- return
- end
-
- -- if it costs something then some condition must be met
- if not no_cost then
- -- Require lite
- if (check_affect(s, "blind")) and ((player.blind > 0) or (no_lite() == TRUE)) then
- msg_print("You cannot see!")
- return
- end
-
- -- Not when confused
- if (check_affect(s, "confusion")) and (player.confused > 0) then
- msg_print("You are too confused!")
- return
- end
-
- -- Enough mana
- if (get_mana(s) > get_power(s)) then
- if (get_check("You do not have enough "..get_power_name(s)..", do you want to try anyway?") == FALSE) then return end
- end
-
- -- Invoke the spell effect
- if (magik(spell_chance(s)) == FALSE) then
- if (__spell_spell[s]() ~= nil) then
- use = TRUE
- end
- else
- local index, sch
-
- -- added because this is *extremely* important --pelpel
- if (flush_failure) then flush() end
-
- msg_print("You failed to get the spell off!")
- for index, sch in __spell_school[s] do
- if __schools[sch].fail then
- __schools[sch].fail(spell_chance(s))
- end
- end
- use = TRUE
- end
- else
- __spell_spell[s]()
- end
-
- if use == TRUE then
- -- Reduce mana
- adjust_power(s, -get_mana(s))
-
- -- Take a turn
- if is_magestaff() == TRUE then energy_use = 80
- else energy_use = 100 end
- end
-
- player.redraw = bor(player.redraw, PR_MANA)
- player.window = bor(player.window, PW_PLAYER)
-end
-
-- Can the spell be randomly found(in random books)
function can_spell_random(i)
diff --git a/lib/mods/theme/core/s_aux.lua b/lib/mods/theme/core/s_aux.lua
index 20cf4964..76f01637 100644
--- a/lib/mods/theme/core/s_aux.lua
+++ b/lib/mods/theme/core/s_aux.lua
@@ -218,33 +218,6 @@ function get_mana(s)
return spell(s).mana + get_level(s, spell(s).mana_max - spell(s).mana, 0)
end
--- Return the amount of power(mana, piety, whatever) for the spell
-function get_power(s)
- if check_affect(s, "piety", FALSE) then
- return player.grace
- else
- return player.csp
- end
-end
-
--- Return the amount of power(mana, piety, whatever) for the spell
-function get_power_name(s)
- if check_affect(s, "piety", FALSE) then
- return "piety"
- else
- return "mana"
- end
-end
-
--- Changes the amount of power(mana, piety, whatever) for the spell
-function adjust_power(s, x)
- if check_affect(s, "piety", FALSE) then
- inc_piety(GOD_ALL, x)
- else
- increase_mana(x)
- end
-end
-
-- Get spell school name(s) as a /-separated string.
function spell_school_name(s)
local xx, sch_str
@@ -292,76 +265,6 @@ function get_spell_stat(s)
else return __tmp_spells[s].stat end
end
-function cast_school_spell(s, s_ptr, no_cost)
- local use = FALSE
-
- -- No magic
- if (player.antimagic > 0) then
- msg_print("Your anti-magic field disrupts any magic attempts.")
- return
- end
-
- -- No magic
- if (player.anti_magic == TRUE) then
- msg_print("Your anti-magic shell disrupts any magic attempts.")
- return
- end
-
- -- if it costs something then some condition must be met
- if not no_cost then
- -- Require lite
- if (check_affect(s, "blind")) and ((player.blind > 0) or (no_lite() == TRUE)) then
- msg_print("You cannot see!")
- return
- end
-
- -- Not when confused
- if (check_affect(s, "confusion")) and (player.confused > 0) then
- msg_print("You are too confused!")
- return
- end
-
- -- Enough mana
- if (get_mana(s) > get_power(s)) then
- if (get_check("You do not have enough "..get_power_name(s)..", do you want to try anyway?") == FALSE) then return end
- end
-
- -- Invoke the spell effect
- if (magik(spell_chance(s)) == FALSE) then
- if (__spell_spell[s]() ~= nil) then
- use = TRUE
- end
- else
- local index, sch
-
- -- added because this is *extremely* important --pelpel
- if (flush_failure) then flush() end
-
- msg_print("You failed to get the spell off!")
- for index, sch in __spell_school[s] do
- if __schools[sch].fail then
- __schools[sch].fail(spell_chance(s))
- end
- end
- use = TRUE
- end
- else
- __spell_spell[s]()
- end
-
- if use == TRUE then
- -- Reduce mana
- adjust_power(s, -get_mana(s))
-
- -- Take a turn
- if is_magestaff() == TRUE then energy_use = 80
- else energy_use = 100 end
- end
-
- player.redraw = bor(player.redraw, PR_MANA)
- player.window = bor(player.window, PW_PLAYER)
-end
-
-- Can the spell be randomly found(in random books)
function can_spell_random(i)
diff --git a/lib/mods/theme/scpt/mkeys.lua b/lib/mods/theme/scpt/mkeys.lua
index 96fc2934..c46cbace 100644
--- a/lib/mods/theme/scpt/mkeys.lua
+++ b/lib/mods/theme/scpt/mkeys.lua
@@ -39,7 +39,7 @@ add_mkey
-- Actualy cast the choice
if (s ~= -1) then
- cast_school_spell(s, spell(s))
+ cast_school_spell(s)
end
end,
}
diff --git a/lib/scpt/mkeys.lua b/lib/scpt/mkeys.lua
index 96fc2934..c46cbace 100644
--- a/lib/scpt/mkeys.lua
+++ b/lib/scpt/mkeys.lua
@@ -39,7 +39,7 @@ add_mkey
-- Actualy cast the choice
if (s ~= -1) then
- cast_school_spell(s, spell(s))
+ cast_school_spell(s)
end
end,
}
diff --git a/src/cmd5.c b/src/cmd5.c
index 5f0201fc..d0c60042 100644
--- a/src/cmd5.c
+++ b/src/cmd5.c
@@ -2409,7 +2409,7 @@ void cast_school_spell()
/* Actualy cast the choice */
if (spell != -1)
{
- exec_lua(format("cast_school_spell(%d, spell(%d))", spell, spell));
+ lua_cast_school_spell(spell, FALSE);
}
}
diff --git a/src/externs.h b/src/externs.h
index d933b2be..e48b99cd 100644
--- a/src/externs.h
+++ b/src/externs.h
@@ -1916,6 +1916,7 @@ int print_book(s16b sval, s32b pval, object_type *obj);
int school_book_length(int sval);
int spell_x(int sval, int pval, int i);
bool_ school_book_contains_spell(int sval, s32b spell_idx);
+void lua_cast_school_spell(s32b spell_idx, bool_ no_cost);
/* randart.c */
extern int get_activation_power(void);
diff --git a/src/lua_bind.c b/src/lua_bind.c
index e7870189..456e653d 100644
--- a/src/lua_bind.c
+++ b/src/lua_bind.c
@@ -249,10 +249,6 @@ int get_mana(s32b s) {
return exec_lua(format("return get_mana(%d)", s));
}
-int get_power(s32b s) {
- return exec_lua(format("return get_power(%d)", s));
-}
-
static int get_spell_stat(s32b s) {
return exec_lua(format("return get_spell_stat(%d)", s));
}
diff --git a/src/object.pkg b/src/object.pkg
index 1ff281c7..4859e35b 100644
--- a/src/object.pkg
+++ b/src/object.pkg
@@ -1132,7 +1132,6 @@ extern object_type *new_object();
extern void end_object(object_type *o_ptr);
extern bool get_item @ get_item_aux(int *cp, cptr pmt, cptr str, int mode);
extern void lua_set_item_tester(int tval, char *fct);
-extern bool is_magestaff();
extern void identify_pack_fully(void);
extern s16b inven_carry(object_type *o_ptr, bool final);
extern s32b calc_total_weight(void);
diff --git a/src/object1.c b/src/object1.c
index 3b418651..2be0984c 100644
--- a/src/object1.c
+++ b/src/object1.c
@@ -2828,6 +2828,8 @@ void display_ammo_damage(object_type *o_ptr)
*/
void describe_device(object_type *o_ptr)
{
+ char buf[128];
+
/* Wands/... of shcool spell */
if (((o_ptr->tval == TV_WAND) || (o_ptr->tval == TV_STAFF)) && object_known_p(o_ptr))
{
@@ -2844,7 +2846,8 @@ void describe_device(object_type *o_ptr)
text_out_c(TERM_L_BLUE, format("%d", school_spells[o_ptr->pval2].skill_level));
text_out("\nSpell fail: ");
- text_out_c(TERM_GREEN, string_exec_lua(format("return tostring(spell_chance(%d))", o_ptr->pval2)));
+ sprintf(buf, FMTs32b, spell_chance(o_ptr->pval2));
+ text_out_c(TERM_GREEN, buf);
text_out("\nSpell info: ");
text_out_c(TERM_YELLOW, get_spell_info(o_ptr->pval2));
diff --git a/src/spells.pkg b/src/spells.pkg
index 18620ccd..c259f672 100644
--- a/src/spells.pkg
+++ b/src/spells.pkg
@@ -2297,36 +2297,10 @@ extern s32b lua_get_level(s32b s, s32b lvl, s32b max, s32b min, s32b bonus);
/** Get level of device */
extern s32b get_level_device(s32b s, s32b max, s32b min);
-/** Get change of failure for spell. */
-extern s32b spell_chance(s32b s);
-
/** Get level of spell */
extern s32b get_level(s32b s, s32b max, s32b min);
-/** @fn lua_spell_chance(s32b chance, int level, int skill_level, int mana, int cur_mana, int stat)
- * @dgonly
- * @brief Get the chance a spell will fail.\n
- * @param chance Number \n chance is the inital chance a spell will work.
- * @brief Initial chance
- * @param level Number \n level represents the level of player skill.
- * @brief Player skill level
- * @param skill_level Number \n *unused*.
- * @brief *Unused*
- * @param mana Number \n mana is the mana required by the spell.
- * @brief Spell mana
- * @param cur_mana Number \n cur_mana is the player's current mana.
- * @brief Player mana
- * @param stat Number \n stat is the required casting statistic (INT or WIS).
- * @brief Casting statistic
- * @return Number \n Chance of failure.
- * @note
- * Note: do not call this function directly.\n
- * By order of DG.
- * @note (see file lua_bind.c)
- */
-extern s32b lua_spell_chance(s32b chance, int level, int skill_level, int mana, int cur_mana, int stat);
-
/** @fn lua_spell_device_chance(s32b chance, int level, int base_level)
* @dgonly
* @brief Get the chance a device will fail.\n
@@ -2908,3 +2882,4 @@ void init_school_books();
extern s32b SCHOOL_UDUN;
extern s32b SCHOOL_MELKOR;
+void lua_cast_school_spell @ cast_school_spell(s32b spell_idx, bool no_cost = FALSE);
diff --git a/src/spells1.c b/src/spells1.c
index 477dfdb9..ccd9f489 100644
--- a/src/spells1.c
+++ b/src/spells1.c
@@ -1259,7 +1259,7 @@ void spellbinder_trigger()
for (i = 0; i < p_ptr->spellbinder_num; i++)
{
msg_format("Triggering spell %s.", school_spells[p_ptr->spellbinder[i]].name);
- exec_lua(format("cast_school_spell(%d, spell(%d), TRUE)", p_ptr->spellbinder[i], p_ptr->spellbinder[i]));
+ lua_cast_school_spell(p_ptr->spellbinder[i], TRUE);
}
p_ptr->spellbinder_num = 0;
p_ptr->spellbinder_trigger = 0;
diff --git a/src/spells3.c b/src/spells3.c
index b7019e0f..f83ab513 100644
--- a/src/spells3.c
+++ b/src/spells3.c
@@ -2527,11 +2527,7 @@ void meta_inertia_control_timer_callback()
else if ((p_ptr->inertia_controlled_spell != -1) &&
(!p_ptr->wild_mode))
{
- char buf[128];
- sprintf(buf,
- "__spell_spell[" FMTs32b "]()",
- p_ptr->inertia_controlled_spell);
- exec_lua(buf);
+ lua_cast_school_spell(p_ptr->inertia_controlled_spell, TRUE);
}
}
diff --git a/src/spells4.c b/src/spells4.c
index 0429e1c1..aa62d827 100644
--- a/src/spells4.c
+++ b/src/spells4.c
@@ -35,6 +35,31 @@ static bool_ castable_while_confused(int s)
return exec_lua(buf);
}
+/** Describe what type of energy the spell uses for casting */
+cptr get_power_name(s32b s)
+{
+ return uses_piety_to_cast(s) ? "piety" : "mana";
+}
+
+/* Changes the amount of power(mana, piety, whatever) for the spell */
+void adjust_power(s32b s, s32b amount)
+{
+ if (uses_piety_to_cast(s))
+ {
+ inc_piety(GOD_ALL, amount);
+ }
+ else
+ {
+ increase_mana(amount);
+ }
+}
+
+/* Return the amount of power available for casting spell */
+s32b get_power(s32b s)
+{
+ return uses_piety_to_cast(s) ? p_ptr->grace : p_ptr->csp;
+}
+
/* Output the describtion when it is used as a spell */
void print_spell_desc(int s, int y)
{
@@ -483,3 +508,98 @@ int print_book(s16b sval, s32b pval, object_type *obj)
prt(format(" %-20s%-16s Level Cost Fail Info", "Name", "School"), 1, 0);
return y;
}
+
+static bool_ call_spell_function(s32b s)
+{
+ char buf[128];
+ sprintf(buf, "return (__spell_spell[" FMTs32b "]() ~= nil)", s);
+ return exec_lua(buf);
+}
+
+void lua_cast_school_spell(s32b s, bool_ no_cost)
+{
+ bool_ use = FALSE;
+
+ /* No magic? */
+ if (p_ptr->antimagic > 0)
+ {
+ msg_print("Your anti-magic field disrupts any magic attempts.");
+ return;
+ }
+
+ /* No magic? */
+ if (p_ptr->anti_magic)
+ {
+ msg_print("Your anti-magic shell disrupts any magic attempts.");
+ return;
+ }
+
+ /* if it costs something then some condition must be met */
+ if (!no_cost)
+ {
+ /* Require lite */
+ if (!castable_while_blind(s) && ((p_ptr->blind > 0) || no_lite()))
+ {
+ msg_print("You cannot see!");
+ return;
+ }
+
+ /* Not when confused */
+ if (!castable_while_confused(s) && (p_ptr->confused > 0))
+ {
+ msg_print("You are too confused!");
+ return;
+ }
+
+ /* Enough mana */
+ if (get_mana(s) > get_power(s))
+ {
+ char buf[128];
+ sprintf(buf,
+ "You do not have enough %s, do you want to try anyway?",
+ get_power_name(s));
+
+ if (!get_check(buf))
+ {
+ return;
+ }
+ }
+
+ /* Invoke the spell effect */
+ if (!magik(spell_chance(s)))
+ {
+ use = call_spell_function(s);
+ }
+ else
+ {
+ use = TRUE;
+
+ /* failures are dangerous; we'll flush the input buffer
+ so it isn't missed. */
+ if (flush_failure)
+ {
+ flush();
+ }
+
+ msg_print("You failed to get the spell off!");
+ }
+ }
+ else
+ {
+ call_spell_function(s);
+ }
+
+ /* Use the mana/piety */
+ if (use == TRUE)
+ {
+ /* Reduce mana */
+ adjust_power(s, -get_mana(s));
+
+ /* Take a turn */
+ energy_use = is_magestaff() ? 80 : 100;
+ }
+
+ /* Refresh player */
+ p_ptr->redraw |= PR_MANA;
+ p_ptr->window |= PW_PLAYER;
+}