/* Cast a spell from a book */ void do_cmd_cast(cmd_code code, cmd_arg args[]) { int spell = args[0].choice; int dir = args[1].direction; int item_list[INVEN_TOTAL + MAX_FLOOR_STACK]; int item_num; int i; cptr verb = ((cp_ptr->spell_book == TV_MAGIC_BOOK) ? "cast" : "recite"); cptr noun = ((cp_ptr->spell_book == TV_MAGIC_BOOK) ? "spell" : "prayer"); /* Check the player can cast spells at all */ if (!player_can_cast()) return; /* Check spell is in a book they can access */ item_tester_hook = obj_can_browse; item_num = scan_items(item_list, N_ELEMENTS(item_list), (USE_INVEN | USE_FLOOR)); /* Check through all available books */ for (i = 0; i < item_num; i++) { if (spell_in_book(spell, item_list[i])) { if (spell_okay_to_cast(spell)) { /* Get the spell */ const magic_type *s_ptr = &mp_ptr->info[spell]; /* Verify "dangerous" spells */ if (s_ptr->smana > p_ptr->csp) { /* Warning */ msg_format("You do not have enough mana to %s this %s.", verb, noun); /* Flush input */ flush(); /* Verify */ if (!get_check("Attempt it anyway? ")) return; } /* Cast a spell */ if (spell_cast(spell, dir)) p_ptr->energy_use = 100; } else { /* Spell is present, but player incapable. */ msg_format("You cannot %s that %s.", verb, noun); } return; } } }
/* Gain a specific spell, specified by spell number (for mages). */ void do_cmd_study_spell(cmd_code code, cmd_arg args[]) { int spell = args[0].choice; int item_list[INVEN_TOTAL + MAX_FLOOR_STACK]; int item_num; int i; /* Check the player can study at all atm */ if (!player_can_study()) return; /* Check that the player can actually learn the nominated spell. */ item_tester_hook = obj_can_browse; item_num = scan_items(item_list, N_ELEMENTS(item_list), (USE_INVEN | USE_FLOOR)); /* Check through all available books */ for (i = 0; i < item_num; i++) { if (spell_in_book(spell, item_list[i])) { if (spell_okay_to_study(spell)) { /* Spell is in an available book, and player is capable. */ spell_learn(spell); p_ptr->energy_use = 100; } else { /* Spell is present, but player incapable. */ msg("You cannot learn that spell."); } return; } } }