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
commit692699f064b2d792b61a5aa448b6844e8c713248 (patch)
tree9e25e80c55c3e2fea86de4d7ccfd037fe64aabc4
parente63216657a9a2711483517e8eb5bed46215ae6dd (diff)
Change spell_chance_device parameter to use spell_type pointer
There's no need to go through the extra indirection of the spell list.
-rw-r--r--src/cmd6.cc16
-rw-r--r--src/lua_bind.cc3
-rw-r--r--src/lua_bind.hpp3
-rw-r--r--src/object1.cc11
4 files changed, 22 insertions, 11 deletions
diff --git a/src/cmd6.cc b/src/cmd6.cc
index e3c6449e..594470f7 100644
--- a/src/cmd6.cc
+++ b/src/cmd6.cc
@@ -3695,7 +3695,7 @@ static void activate_stick(s16b s, bool_ *obvious, bool_ *use_charge)
*/
void do_cmd_use_staff(void)
{
- int item, ident, chance;
+ int item, ident;
bool_ obvious, use_charge;
@@ -3744,7 +3744,11 @@ void do_cmd_use_staff(void)
set_stick_mode(o_ptr);
/* get the chance */
- chance = spell_chance_device(o_ptr->pval2);
+ int chance;
+ {
+ auto spell = spell_at(o_ptr->pval2);
+ chance = spell_chance_device(spell);
+ }
/* Leave device mode */
unset_stick_mode();
@@ -3880,7 +3884,7 @@ void do_cmd_aim_wand(void)
{
bool_ obvious, use_charge;
- int item, ident, chance;
+ int item, ident;
object_type *o_ptr;
@@ -3929,7 +3933,11 @@ void do_cmd_aim_wand(void)
set_stick_mode(o_ptr);
/* get the chance */
- chance = spell_chance_device(o_ptr->pval2);
+ int chance;
+ {
+ auto spell = spell_at(o_ptr->pval2);
+ chance = spell_chance_device(spell);
+ }
/* Leave device mode */
unset_stick_mode();
diff --git a/src/lua_bind.cc b/src/lua_bind.cc
index 1e4303b7..6b22e1d2 100644
--- a/src/lua_bind.cc
+++ b/src/lua_bind.cc
@@ -150,13 +150,12 @@ static s32b spell_chance_school(s32b s)
return clamp_failure_chance(chance, minfail);
}
-s32b spell_chance_device(s32b s)
+s32b spell_chance_device(spell_type *spell_ptr)
{
// Device parameters initialized?
assert(get_level_use_stick > -1);
// Calculate the chance.
- auto spell_ptr = spell_at(s);
int level = get_level_device_1(spell_ptr, 50, 1);
s32b chance = spell_type_failure_rate(spell_ptr);
diff --git a/src/lua_bind.hpp b/src/lua_bind.hpp
index 3ac8e2bc..f4991bd3 100644
--- a/src/lua_bind.hpp
+++ b/src/lua_bind.hpp
@@ -1,9 +1,10 @@
#pragma once
#include "h-basic.h"
+#include "spell_type_fwd.h"
/** Calculate spell failure rate for a device, i.e. a wand or staff. */
-extern s32b spell_chance_device(s32b s);
+extern s32b spell_chance_device(spell_type *spell_ptr);
/** 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 e3f29bd3..96f01517 100644
--- a/src/object1.cc
+++ b/src/object1.cc
@@ -2713,8 +2713,11 @@ void describe_device(object_type *o_ptr)
/* Enter device mode */
set_stick_mode(o_ptr);
+ // Spell reference
+ auto spell = spell_at(o_ptr->pval2);
+
text_out("\nSpell description:\n");
- spell_type_description_foreach(spell_at(o_ptr->pval2),
+ spell_type_description_foreach(spell,
[] (std::string const &text) -> void {
text_out("\n");
text_out(text.c_str());
@@ -2725,14 +2728,14 @@ void describe_device(object_type *o_ptr)
text_out_c(TERM_L_BLUE, buf);
text_out("\nMinimum Magic Device level to increase spell level: ");
- text_out_c(TERM_L_BLUE, format("%d", spell_type_skill_level(spell_at(o_ptr->pval2))));
+ text_out_c(TERM_L_BLUE, format("%d", spell_type_skill_level(spell)));
text_out("\nSpell fail: ");
- sprintf(buf, FMTs32b, spell_chance_device(o_ptr->pval2));
+ sprintf(buf, FMTs32b, spell_chance_device(spell));
text_out_c(TERM_GREEN, buf);
text_out("\nSpell info: ");
- text_out_c(TERM_YELLOW, spell_type_info(spell_at(o_ptr->pval2)));
+ text_out_c(TERM_YELLOW, spell_type_info(spell));
/* Leave device mode */
unset_stick_mode();