- Timestamp:
- 06/01/09 16:05:44 (15 months ago)
- Location:
- trunk/src
- Files:
-
- 4 modified
-
cmd-obj.c (modified) (8 diffs)
-
cmd5.c (modified) (2 diffs)
-
object/obj-util.c (modified) (1 diff)
-
object/object.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/cmd-obj.c
r1420 r1424 429 429 int snd; 430 430 use_type use; 431 int items_allowed = 0; 431 432 432 433 /* Determine how this item is used. */ … … 435 436 use = USE_TIMEOUT; 436 437 snd = MSG_ZAP_ROD; 438 items_allowed = USE_INVEN | USE_FLOOR; 437 439 } 438 440 else if (obj_is_wand(o_ptr)) … … 440 442 use = USE_CHARGE; 441 443 snd = MSG_ZAP_ROD; 444 items_allowed = USE_INVEN | USE_FLOOR; 442 445 } 443 446 else if (obj_is_staff(o_ptr)) … … 445 448 use = USE_CHARGE; 446 449 snd = MSG_ZAP_ROD; 450 items_allowed = USE_INVEN | USE_FLOOR; 447 451 } 448 452 else if (obj_is_food(o_ptr)) … … 450 454 use = USE_SINGLE; 451 455 snd = MSG_EAT; 456 items_allowed = USE_INVEN | USE_FLOOR; 452 457 } 453 458 else if (obj_is_potion(o_ptr)) … … 455 460 use = USE_SINGLE; 456 461 snd = MSG_QUAFF; 462 items_allowed = USE_INVEN | USE_FLOOR; 457 463 } 458 464 else if (obj_is_scroll(o_ptr)) 459 465 { 466 /* Check player can use scroll */ 467 if (!player_can_read()) 468 return; 469 460 470 use = USE_SINGLE; 461 471 snd = MSG_GENERIC; 472 items_allowed = USE_INVEN | USE_FLOOR; 462 473 } 463 474 else if (obj_can_activate(o_ptr)) 464 475 { 465 476 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; 467 486 } 468 487 … … 476 495 if (obj_needs_aim(o_ptr)) 477 496 { 478 /* Get a direction, allow cancel */ 479 if (!get_aim_dir(&dir)) 480 return; 497 dir = args[1].direction; 481 498 } 482 499 … … 795 812 if (item_actions[act].action != NULL) 796 813 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); 797 816 else 798 cmd_insert(item_actions[act].command, item); 817 cmd_insert(item_actions[act].command, item); 799 818 } 800 819 -
trunk/src/cmd5.c
r1420 r1424 579 579 } 580 580 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 599 581 /* Gain a random spell from the given book (for priests) */ 600 582 void do_cmd_study_book(cmd_code code, cmd_arg args[]) … … 613 595 614 596 /* 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))) 617 598 { 618 599 msg_format("That item is not within your reach."); -
trunk/src/object/obj-util.c
r1423 r1424 3722 3722 3723 3723 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 */ 3729 bool 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 171 171 bool get_item_okay(int item); 172 172 int scan_items(int *item_list, size_t item_list_max, int mode); 173 bool item_is_available(int item, bool (*tester)(const object_type *), int mode); 173 174 174 175 /* obj-power.c and randart.c */
