Changeset 1426

Show
Ignore:
Timestamp:
06/04/09 20:27:55 (15 months ago)
Author:
ajps
Message:

Bit of input-checking on spell-casting 'command'.

Location:
trunk/src
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/cmd-obj.c

    r1424 r1426  
    367367} 
    368368 
    369 /* Cast a spell from a book */ 
    370 void do_cmd_cast(cmd_code code, cmd_arg args[]) 
    371 { 
    372         int spell = args[0].choice; 
    373  
    374         /* Cast a spell */ 
    375         if (spell_cast(spell)) 
    376             p_ptr->energy_use = 100; 
    377 } 
    378  
    379369static void obj_cast(object_type *o_ptr, int item) 
    380370{ 
     
    658648        else if (j_ptr->sval == SV_LITE_TORCH) 
    659649                refuel_torch(j_ptr, o_ptr, item); 
     650 
    660651} 
    661652 
  • trunk/src/cmd5.c

    r1424 r1426  
    579579} 
    580580 
     581/* Cast a spell from a book */ 
     582void 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 
    581624/* Gain a random spell from the given book (for priests) */ 
    582625void do_cmd_study_book(cmd_code code, cmd_arg args[])