summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2015-02-23 09:11:55 +0100
committerBardur Arantsson <bardur@scientician.net>2015-02-23 09:11:55 +0100
commit0b74fd491aeda33e25a20986f40f6c461fb20f06 (patch)
tree6f1329635676b6bf995a71ba3c15a4d9f4aa42d3
parent528a95aaef400b264203d3e8621887ea0307e9ea (diff)
Split spell_chance into device and book variants
The code calling spell_chance() always actually knows which kind of spell its looking at, so we might as well exploit that.
-rw-r--r--src/cmd6.cc5
-rw-r--r--src/externs.h1
-rw-r--r--src/lua_bind.cc32
-rw-r--r--src/lua_bind.hpp9
-rw-r--r--src/object1.cc4
-rw-r--r--src/spells4.cc5
6 files changed, 35 insertions, 21 deletions
diff --git a/src/cmd6.cc b/src/cmd6.cc
index bf622ae9..e3c6449e 100644
--- a/src/cmd6.cc
+++ b/src/cmd6.cc
@@ -11,6 +11,7 @@
*/
#include "angband.h"
+#include "lua_bind.hpp"
#include "spell_type.h"
#include "hooks.h"
@@ -3743,7 +3744,7 @@ void do_cmd_use_staff(void)
set_stick_mode(o_ptr);
/* get the chance */
- chance = spell_chance(o_ptr->pval2);
+ chance = spell_chance_device(o_ptr->pval2);
/* Leave device mode */
unset_stick_mode();
@@ -3928,7 +3929,7 @@ void do_cmd_aim_wand(void)
set_stick_mode(o_ptr);
/* get the chance */
- chance = spell_chance(o_ptr->pval2);
+ chance = spell_chance_device(o_ptr->pval2);
/* Leave device mode */
unset_stick_mode();
diff --git a/src/externs.h b/src/externs.h
index 7979cc63..3586df38 100644
--- a/src/externs.h
+++ b/src/externs.h
@@ -2208,7 +2208,6 @@ extern int find_module(cptr name);
extern s32b lua_get_level(spell_type *spell, s32b lvl, s32b max, s32b min, s32b bonus);
extern int get_mana(s32b s);
extern s32b get_power(s32b s);
-extern s32b spell_chance(s32b s);
extern s32b get_level(s32b s, s32b max, s32b min);
extern void get_level_school(spell_type *spell, s32b max, s32b min, s32b *level, bool_ *na);
diff --git a/src/lua_bind.cc b/src/lua_bind.cc
index 82d4009a..fe740aa9 100644
--- a/src/lua_bind.cc
+++ b/src/lua_bind.cc
@@ -10,6 +10,7 @@
* included in all such copies.
*/
+#include "lua_bind.hpp"
#include "angband.h"
#include <assert.h>
@@ -108,10 +109,9 @@ int get_mana(s32b s)
return get_level_school_1(spell, mana_range.max, mana_range.min);
}
-/** Returns spell change of failure for spell cast from a device */
-static s32b spell_chance_device(s32b s)
+/** Returns spell chance of failure for spell cast from a device */
+static s32b spell_chance_device(spell_type *s_ptr)
{
- spell_type *s_ptr = spell_at(s);
int level = get_level_device_1(s_ptr, 50, 1);
int minfail;
s32b chance = spell_type_failure_rate(s_ptr);
@@ -167,18 +167,22 @@ static s32b spell_chance_school(s32b s)
return clamp_failure_chance(chance, minfail);
}
-/** Returns spell chance of failure for spell */
-s32b spell_chance(s32b s)
+s32b spell_chance_device(s32b s)
{
- /* Extract the base spell failure rate */
- if (get_level_use_stick > -1)
- {
- return spell_chance_device(s);
- }
- else
- {
- return spell_chance_school(s);
- }
+ // Device parameters initialized?
+ assert(get_level_use_stick > -1);
+
+ // Calculate the chance.
+ auto spell = spell_at(s);
+ return spell_chance_device(spell);
+}
+
+s32b spell_chance_book(s32b s)
+{
+ // Must NOT be a device!
+ assert(get_level_use_stick < 0);
+ // Delegate
+ return spell_chance_school(s);
}
s32b get_level(s32b s, s32b max, s32b min)
diff --git a/src/lua_bind.hpp b/src/lua_bind.hpp
new file mode 100644
index 00000000..3ac8e2bc
--- /dev/null
+++ b/src/lua_bind.hpp
@@ -0,0 +1,9 @@
+#pragma once
+
+#include "h-basic.h"
+
+/** Calculate spell failure rate for a device, i.e. a wand or staff. */
+extern s32b spell_chance_device(s32b s);
+
+/** Calculate spell failure rate for a spell book. */
+extern s32b spell_chance_book(s32b s);
diff --git a/src/object1.cc b/src/object1.cc
index 4dc266f5..e3f29bd3 100644
--- a/src/object1.cc
+++ b/src/object1.cc
@@ -11,7 +11,7 @@
*/
#include "angband.h"
-
+#include "lua_bind.hpp"
#include "quark.h"
#include "spell_type.h"
#include "spell_type.hpp"
@@ -2728,7 +2728,7 @@ void describe_device(object_type *o_ptr)
text_out_c(TERM_L_BLUE, format("%d", spell_type_skill_level(spell_at(o_ptr->pval2))));
text_out("\nSpell fail: ");
- sprintf(buf, FMTs32b, spell_chance(o_ptr->pval2));
+ sprintf(buf, FMTs32b, spell_chance_device(o_ptr->pval2));
text_out_c(TERM_GREEN, buf);
text_out("\nSpell info: ");
diff --git a/src/spells4.cc b/src/spells4.cc
index 31811449..76ea4400 100644
--- a/src/spells4.cc
+++ b/src/spells4.cc
@@ -2,6 +2,7 @@
#include <assert.h>
+#include "lua_bind.hpp"
#include "spell_type.h"
#include "spell_type.hpp"
#include "spell_idx_list.hpp"
@@ -445,7 +446,7 @@ int print_spell(cptr label_, byte color, int y, s32b s)
sch_str,
level_str,
get_mana(s),
- (int) spell_chance(s),
+ (int) spell_chance_book(s),
spell_info);
c_prt(color, buf, y, 0);
@@ -539,7 +540,7 @@ void lua_cast_school_spell(s32b s, bool_ no_cost)
}
/* Invoke the spell effect */
- if (!magik(spell_chance(s)))
+ if (!magik(spell_chance_book(s)))
{
use = (spell_type_produce_effect(spell, -1) != NO_CAST);
}