| | 581 | /* Cast a spell from a book */ |
| | 582 | void do_cmd_cast(cmd_code code, cmd_arg args[]) |
| | 583 | { |
| | 584 | int spell = args[0].choice; |
| | 585 | |
| | 586 | int item_list[INVEN_TOTAL + MAX_FLOOR_STACK]; |
| | 587 | int item_num; |
| | 588 | int i; |
| | 589 | |
| | 590 | cptr p = ((cp_ptr->spell_book == TV_MAGIC_BOOK) ? "spell" : "prayer"); |
| | 591 | |
| | 592 | /* Check the player can cast spells at all */ |
| | 593 | if (!player_can_cast()) |
| | 594 | return; |
| | 595 | |
| | 596 | /* Check spell is in a book they can access */ |
| | 597 | item_tester_hook = obj_can_browse; |
| | 598 | item_num = scan_items(item_list, N_ELEMENTS(item_list), (USE_INVEN | USE_FLOOR)); |
| | 599 | |
| | 600 | /* Check through all available books */ |
| | 601 | for (i = 0; i < item_num; i++) |
| | 602 | { |
| | 603 | if (spell_in_book(spell, item_list[i])) |
| | 604 | { |
| | 605 | if (spell_okay(spell, TRUE, FALSE)) |
| | 606 | { |
| | 607 | /* Cast a spell */ |
| | 608 | if (spell_cast(spell)) |
| | 609 | p_ptr->energy_use = 100; |
| | 610 | } |
| | 611 | else |
| | 612 | { |
| | 613 | /* Spell is present, but player incapable. */ |
| | 614 | msg_format("You cannot cast that %p.", p); |
| | 615 | } |
| | 616 | |
| | 617 | return; |
| | 618 | } |
| | 619 | } |
| | 620 | |
| | 621 | } |
| | 622 | |
| | 623 | |