summaryrefslogtreecommitdiff
path: root/src/cmd5.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd5.c')
-rw-r--r--src/cmd5.c70
1 files changed, 33 insertions, 37 deletions
diff --git a/src/cmd5.c b/src/cmd5.c
index d0c60042..e322186b 100644
--- a/src/cmd5.c
+++ b/src/cmd5.c
@@ -2101,14 +2101,14 @@ bool_ get_item_hook_find_spell(int *item)
{
int i, spell;
char buf[80];
- char buf2[100];
strcpy(buf, "Manathrust");
if (!get_string("Spell name? ", buf, 79))
return FALSE;
- sprintf(buf2, "return find_spell(\"%s\")", buf);
- spell = exec_lua(buf2);
+
+ spell = find_spell(buf);
if (spell == -1) return FALSE;
+
for (i = 0; i < INVEN_TOTAL; i++)
{
object_type *o_ptr = &p_ptr->inventory[i];
@@ -2147,9 +2147,31 @@ bool_ get_item_hook_find_spell(int *item)
}
/*
+ * Is the spell castable?
+ */
+bool_ is_ok_spell(s32b spell_idx, object_type *o_ptr)
+{
+ spell_type *spell = spell_at(spell_idx);
+ assert(o_ptr != NULL);
+
+ if (get_level(spell_idx, 50, 0) == 0)
+ {
+ return FALSE;
+ }
+
+ if (o_ptr->pval < spell->minimum_pval)
+ {
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+
+/*
* Get a spell from a book
*/
-s32b get_school_spell(cptr do_what, cptr check_fct, s16b force_book)
+s32b get_school_spell(cptr do_what, s16b force_book)
{
int i, item;
s32b spell = -1;
@@ -2320,13 +2342,13 @@ s32b get_school_spell(cptr do_what, cptr check_fct, s16b force_book)
}
else
{
- s32b ok;
+ bool_ ok;
/* Save the spell index */
spell = spell_x(sval, pval, i);
/* Do we need to do some pre test */
- call_lua(check_fct, "(d,O)", "d", spell, o_ptr, &ok);
+ ok = is_ok_spell(spell, o_ptr);
/* Require "okay" spells */
if (!ok)
@@ -2344,10 +2366,10 @@ s32b get_school_spell(cptr do_what, cptr check_fct, s16b force_book)
}
else
{
- s32b ok;
+ bool_ ok;
/* Require "okay" spells */
- call_lua(check_fct, "(d, O)", "d", hack_force_spell, hack_force_spell_obj, &ok);
+ ok = is_ok_spell(hack_force_spell, hack_force_spell_obj);
if (ok)
{
flag = TRUE;
@@ -2404,7 +2426,7 @@ void cast_school_spell()
return;
}
- spell = get_school_spell("cast", "is_ok_spell", 0);
+ spell = get_school_spell("cast", 0);
/* Actualy cast the choice */
if (spell != -1)
@@ -2502,14 +2524,14 @@ static bool_ hook_school_can_spellable(object_type *o_ptr)
*/
void do_cmd_copy_spell()
{
- int spell = get_school_spell("copy", "is_ok_spell", 0);
+ int spell = get_school_spell("copy", 0);
int item;
object_type *o_ptr;
if (spell == -1) return;
/* Spells that cannot be randomly created cannot be copied */
- if (exec_lua(format("return can_spell_random(%d)", spell)) == FALSE)
+ if (can_spell_random(spell) <= 0)
{
msg_print("This spell cannot be copied.");
return;
@@ -2523,29 +2545,3 @@ void do_cmd_copy_spell()
o_ptr->pval2 = spell;
inven_item_describe(item);
}
-
-/*
- * Finds a spell by name, optimized for speed
- */
-int find_spell(const char *name)
-{
- int oldtop, spell;
- oldtop = lua_gettop(L);
-
- lua_getglobal(L, "find_spell");
- tolua_pushstring(L, name);
-
- /* Call the function */
- if (lua_call(L, 1, 1))
- {
- cmsg_format(TERM_VIOLET, "ERROR in lua_call while calling 'find_spell'.");
- lua_settop(L, oldtop);
- return -1;
- }
-
- spell = tolua_getnumber(L, -(lua_gettop(L) - oldtop), -1);
-
- lua_settop(L, oldtop);
-
- return spell;
-}