Changeset 1424 for trunk

Show
Ignore:
Timestamp:
06/01/09 16:05:44 (15 months ago)
Author:
ajps
Message:

Add some more basic arg checking for game commands, and fix a bug where we weren't passing a direction to aimable commands.

Location:
trunk/src
Files:
4 modified

Legend:

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

    r1420 r1424  
    429429        int snd; 
    430430        use_type use; 
     431        int items_allowed = 0; 
    431432 
    432433        /* Determine how this item is used. */ 
     
    435436                use = USE_TIMEOUT; 
    436437                snd = MSG_ZAP_ROD; 
     438                items_allowed = USE_INVEN | USE_FLOOR; 
    437439        } 
    438440        else if (obj_is_wand(o_ptr)) 
     
    440442                use = USE_CHARGE; 
    441443                snd = MSG_ZAP_ROD; 
     444                items_allowed = USE_INVEN | USE_FLOOR; 
    442445        } 
    443446        else if (obj_is_staff(o_ptr)) 
     
    445448                use = USE_CHARGE; 
    446449                snd = MSG_ZAP_ROD; 
     450                items_allowed = USE_INVEN | USE_FLOOR; 
    447451        } 
    448452        else if (obj_is_food(o_ptr)) 
     
    450454                use = USE_SINGLE; 
    451455                snd = MSG_EAT;           
     456                items_allowed = USE_INVEN | USE_FLOOR; 
    452457        } 
    453458        else if (obj_is_potion(o_ptr)) 
     
    455460                use = USE_SINGLE; 
    456461                snd = MSG_QUAFF;                 
     462                items_allowed = USE_INVEN | USE_FLOOR; 
    457463        } 
    458464        else if (obj_is_scroll(o_ptr)) 
    459465        { 
     466                /* Check player can use scroll */ 
     467                if (!player_can_read()) 
     468                        return; 
     469 
    460470                use = USE_SINGLE; 
    461471                snd = MSG_GENERIC;               
     472                items_allowed = USE_INVEN | USE_FLOOR; 
    462473        } 
    463474        else if (obj_can_activate(o_ptr)) 
    464475        { 
    465476                use = USE_TIMEOUT; 
    466                 snd = MSG_ACT_ARTIFACT;          
     477                snd = MSG_ACT_ARTIFACT; 
     478                items_allowed = USE_EQUIP; 
     479        } 
     480 
     481        /* Check if item is within player's reach. */ 
     482        if (items_allowed == 0 || !item_is_available(item, NULL, items_allowed)) 
     483        { 
     484                msg_print("You cannot use that item from its current location."); 
     485                return; 
    467486        } 
    468487 
     
    476495        if (obj_needs_aim(o_ptr)) 
    477496        { 
    478                 /* Get a direction, allow cancel */ 
    479                 if (!get_aim_dir(&dir)) 
    480                         return; 
     497                dir = args[1].direction; 
    481498        } 
    482499 
     
    795812        if (item_actions[act].action != NULL) 
    796813                item_actions[act].action(o_ptr, item); 
     814        else if (obj_needs_aim(o_ptr)) 
     815                cmd_insert(item_actions[act].command, item, DIR_UNKNOWN); 
    797816        else 
    798                 cmd_insert(item_actions[act].command, item);             
     817                cmd_insert(item_actions[act].command, item); 
    799818} 
    800819 
  • trunk/src/cmd5.c

    r1420 r1424  
    579579} 
    580580 
    581 /* Check if the given item is available for the player to use. */ 
    582 static bool item_is_available(int item, int mode) 
    583 { 
    584         int item_list[INVEN_TOTAL + MAX_FLOOR_STACK]; 
    585         int item_num; 
    586         int i; 
    587  
    588         item_num = scan_items(item_list, N_ELEMENTS(item_list), mode); 
    589  
    590         for (i = 0; i < item_num; i++) 
    591         { 
    592                 if (item_list[i] == item) 
    593                         return TRUE; 
    594         } 
    595  
    596         return FALSE; 
    597 } 
    598  
    599581/* Gain a random spell from the given book (for priests) */ 
    600582void do_cmd_study_book(cmd_code code, cmd_arg args[]) 
     
    613595 
    614596        /* Check that the player has access to the nominated spell book. */ 
    615         item_tester_hook = obj_can_browse; 
    616         if (!item_is_available(book, (USE_INVEN | USE_FLOOR))) 
     597        if (!item_is_available(book, obj_can_browse, (USE_INVEN | USE_FLOOR))) 
    617598        { 
    618599                msg_format("That item is not within your reach."); 
  • trunk/src/object/obj-util.c

    r1423 r1424  
    37223722 
    37233723 
    3724  
     3724/*  
     3725 * Check if the given item is available for the player to use.  
     3726 * 
     3727 * 'mode' defines which areas we should look at, a la scan_items(). 
     3728 */ 
     3729bool item_is_available(int item, bool (*tester)(const object_type *), int mode) 
     3730{ 
     3731        int item_list[INVEN_TOTAL + MAX_FLOOR_STACK]; 
     3732        int item_num; 
     3733        int i; 
     3734 
     3735        item_tester_hook = tester; 
     3736        item_tester_tval = 0; 
     3737        item_num = scan_items(item_list, N_ELEMENTS(item_list), mode); 
     3738 
     3739        for (i = 0; i < item_num; i++) 
     3740        { 
     3741                if (item_list[i] == item) 
     3742                        return TRUE; 
     3743        } 
     3744 
     3745        return FALSE; 
     3746} 
     3747 
     3748 
  • trunk/src/object/object.h

    r1420 r1424  
    171171bool get_item_okay(int item); 
    172172int scan_items(int *item_list, size_t item_list_max, int mode); 
     173bool item_is_available(int item, bool (*tester)(const object_type *), int mode); 
    173174 
    174175/* obj-power.c and randart.c */