OSDN Git Service

[Refactor] #37353 do_cmd_throw()を整理。 / Refactor do_cmd_throw().
[hengband/hengband.git] / src / cmd3.c
index 6bddaa3..cd1a67e 100644 (file)
 
 
 #include "angband.h"
+#include "selfinfo.h"
+#include "cmd-activate.h"
+#include "cmd-eat.h"
+#include "cmd-quaff.h"
+#include "cmd-read.h"
+#include "cmd-usestaff.h"
+#include "cmd-zaprod.h"
+#include "cmd-zapwand.h"
 
 
 
@@ -221,7 +229,7 @@ bool select_ring_slot = FALSE;
  */
 void do_cmd_wield(void)
 {
-       int item, slot;
+       OBJECT_IDX item, slot;
 
        object_type forge;
        object_type *q_ptr;
@@ -234,7 +242,7 @@ void do_cmd_wield(void)
 
        cptr q, s;
 
-       int need_switch_wielding = 0;
+       OBJECT_IDX need_switch_wielding = 0;
 
        if (p_ptr->special_defense & KATA_MUSOU)
        {
@@ -636,7 +644,7 @@ void kamaenaoshi(int item)
  */
 void do_cmd_takeoff(void)
 {
-       int item;
+       OBJECT_IDX item;
 
        object_type *o_ptr;
 
@@ -732,7 +740,8 @@ void do_cmd_takeoff(void)
  */
 void do_cmd_drop(void)
 {
-       int item, amt = 1;
+       OBJECT_IDX item;
+       int amt = 1;
 
        object_type *o_ptr;
 
@@ -839,18 +848,18 @@ static bool high_level_book(object_type *o_ptr)
  */
 void do_cmd_destroy(void)
 {
-       int                     item, amt = 1;
-       int                     old_number;
+       OBJECT_IDX item;
+       QUANTITY amt = 1;
+       QUANTITY old_number;
 
-       bool            force = FALSE;
+       bool force = FALSE;
 
-       object_type             *o_ptr;
-       object_type             forge;
-       object_type             *q_ptr = &forge;
-
-       char            o_name[MAX_NLEN];
+       object_type *o_ptr;
+       object_type forge;
+       object_type *q_ptr = &forge;
 
-       char            out_val[MAX_NLEN+40];
+       char o_name[MAX_NLEN];
+       char out_val[MAX_NLEN+40];
 
        cptr q, s;
 
@@ -1061,10 +1070,8 @@ void do_cmd_destroy(void)
  */
 void do_cmd_observe(void)
 {
-       int                     item;
-
+       OBJECT_IDX item;
        object_type             *o_ptr;
-
        char            o_name[MAX_NLEN];
 
        cptr q, s;
@@ -1120,10 +1127,8 @@ void do_cmd_observe(void)
  */
 void do_cmd_uninscribe(void)
 {
-       int   item;
-
+       OBJECT_IDX item;
        object_type *o_ptr;
-
        cptr q, s;
 
        item_tester_no_ryoute = TRUE;
@@ -1182,14 +1187,10 @@ void do_cmd_uninscribe(void)
  */
 void do_cmd_inscribe(void)
 {
-       int                     item;
-
+       OBJECT_IDX item;
        object_type             *o_ptr;
-
        char            o_name[MAX_NLEN];
-
        char            out_val[80];
-
        cptr q, s;
 
        item_tester_no_ryoute = TRUE;
@@ -1279,7 +1280,7 @@ static bool item_tester_refill_lantern(object_type *o_ptr)
  */
 static void do_cmd_refill_lamp(void)
 {
-       int item;
+       OBJECT_IDX item;
 
        object_type *o_ptr;
        object_type *j_ptr;
@@ -1388,7 +1389,7 @@ static bool item_tester_refill_torch(object_type *o_ptr)
  */
 static void do_cmd_refill_torch(void)
 {
-       int item;
+       OBJECT_IDX item;
 
        object_type *o_ptr;
        object_type *j_ptr;
@@ -1795,7 +1796,9 @@ void ang_sort_swap_hook(vptr u, vptr v, int a, int b)
  */
 void do_cmd_query_symbol(void)
 {
-       int             i, n, r_idx;
+       IDX i;
+       int n;
+       MONRACE_IDX r_idx;
        char    sym, query;
        char    buf[128];
 
@@ -1808,7 +1811,7 @@ void do_cmd_query_symbol(void)
        bool    recall = FALSE;
 
        u16b    why = 0;
-       u16b    *who;
+       IDX     *who;
 
        /* Get a character, or abort */
        if (!get_com(_("知りたい文字を入力して下さい(記号 or ^A全,^Uユ,^N非ユ,^R乗馬,^M名前): ", 
@@ -1865,7 +1868,7 @@ void do_cmd_query_symbol(void)
        prt(buf, 0, 0);
 
        /* Allocate the "who" array */
-       C_MAKE(who, max_r_idx, u16b);
+       C_MAKE(who, max_r_idx, IDX);
 
        /* Collect matching monsters */
        for (n = 0, i = 1; i < max_r_idx; i++)
@@ -1895,7 +1898,7 @@ void do_cmd_query_symbol(void)
 #ifdef JP
                    if (iskanji( temp[xx])) { xx++; continue; }
 #endif
-                   if (isupper(temp[xx])) temp[xx]=tolower(temp[xx]);
+                   if (isupper(temp[xx])) temp[xx] = (char)tolower(temp[xx]);
                  }
   
 #ifdef JP
@@ -1904,14 +1907,14 @@ void do_cmd_query_symbol(void)
                  strcpy(temp2, r_name+r_ptr->name);
 #endif
                  for (xx=0; temp2[xx] && xx<80; xx++)
-                   if (isupper(temp2[xx])) temp2[xx]=tolower(temp2[xx]);
+                   if (isupper(temp2[xx])) temp2[xx] = (char)tolower(temp2[xx]);
   
 #ifdef JP
                  if (my_strstr(temp2, temp) || my_strstr(r_name + r_ptr->name, temp) )
 #else
                  if (my_strstr(temp2, temp))
 #endif
-                         who[n++]=i;
+                         who[n++] = i;
                }
 
                /* Collect "appropriate" monsters */
@@ -1922,7 +1925,7 @@ void do_cmd_query_symbol(void)
        if (!n)
        {
                /* Free the "who" array */
-               C_KILL(who, max_r_idx, u16b);
+               C_KILL(who, max_r_idx, IDX);
 
                return;
        }
@@ -1958,7 +1961,7 @@ void do_cmd_query_symbol(void)
        if (query != 'y')
        {
                /* Free the "who" array */
-               C_KILL(who, max_r_idx, u16b);
+               C_KILL(who, max_r_idx, IDX);
 
                return;
        }
@@ -2051,10 +2054,190 @@ void do_cmd_query_symbol(void)
        }
 
        /* Free the "who" array */
-       C_KILL(who, max_r_idx, u16b);
+       C_KILL(who, max_r_idx, IDX);
 
        /* Re-display the identity */
        prt(buf, 0, 0);
 }
 
 
+/*!
+* @brief オブジェクトをプレイヤーが簡易使用コマンドで利用できるかを判定する /
+* Hook to determine if an object is useable
+* @param o_ptr 判定したいオブジェクトの構造体参照ポインタ
+* @return 利用可能ならばTRUEを返す
+*/
+static bool item_tester_hook_use(object_type *o_ptr)
+{
+       u32b flgs[TR_FLAG_SIZE];
+
+       /* Ammo */
+       if (o_ptr->tval == p_ptr->tval_ammo)
+               return (TRUE);
+
+       /* Useable object */
+       switch (o_ptr->tval)
+       {
+       case TV_SPIKE:
+       case TV_STAFF:
+       case TV_WAND:
+       case TV_ROD:
+       case TV_SCROLL:
+       case TV_POTION:
+       case TV_FOOD:
+       {
+               return (TRUE);
+       }
+
+       default:
+       {
+               int i;
+
+               /* Not known */
+               if (!object_is_known(o_ptr)) return (FALSE);
+
+               /* HACK - only items from the equipment can be activated */
+               for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
+               {
+                       if (&inventory[i] == o_ptr)
+                       {
+                               /* Extract the flags */
+                               object_flags(o_ptr, flgs);
+
+                               /* Check activation flag */
+                               if (have_flag(flgs, TR_ACTIVATE)) return (TRUE);
+                       }
+               }
+       }
+       }
+
+       /* Assume not */
+       return (FALSE);
+}
+
+
+/*!
+ * @brief アイテムを汎用的に「使う」コマンドのメインルーチン /
+ * Use an item
+ * @return なし
+ * @details
+ * XXX - Add actions for other item types
+ */
+void do_cmd_use(void)
+{
+       OBJECT_IDX item;
+       object_type *o_ptr;
+       cptr        q, s;
+
+       if (p_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
+       {
+               set_action(ACTION_NONE);
+       }
+
+       item_tester_no_ryoute = TRUE;
+       /* Prepare the hook */
+       item_tester_hook = item_tester_hook_use;
+
+       /* Get an item */
+       q = _("どれを使いますか?", "Use which item? ");
+       s = _("使えるものがありません。", "You have nothing to use.");
+
+       if (!get_item(&item, q, s, (USE_INVEN | USE_EQUIP | USE_FLOOR))) return;
+
+       /* Get the item (in the pack) */
+       if (item >= 0)
+       {
+               o_ptr = &inventory[item];
+       }
+       /* Get the item (on the floor) */
+       else
+       {
+               o_ptr = &o_list[0 - item];
+       }
+
+       switch (o_ptr->tval)
+       {
+               /* Spike a door */
+               case TV_SPIKE:
+               {
+                       do_cmd_spike();
+                       break;
+               }
+
+               /* Eat some food */
+               case TV_FOOD:
+               {
+                       do_cmd_eat_food_aux(item);
+                       break;
+               }
+
+               /* Aim a wand */
+               case TV_WAND:
+               {
+                       do_cmd_aim_wand_aux(item);
+                       break;
+               }
+
+               /* Use a staff */
+               case TV_STAFF:
+               {
+                       do_cmd_use_staff_aux(item);
+                       break;
+               }
+
+               /* Zap a rod */
+               case TV_ROD:
+               {
+                       do_cmd_zap_rod_aux(item);
+                       break;
+               }
+
+               /* Quaff a potion */
+               case TV_POTION:
+               {
+                       do_cmd_quaff_potion_aux(item);
+                       break;
+               }
+
+               /* Read a scroll */
+               case TV_SCROLL:
+               {
+                       /* Check some conditions */
+                       if (p_ptr->blind)
+                       {
+                               msg_print(_("目が見えない。", "You can't see anything."));
+                               return;
+                       }
+                       if (no_lite())
+                       {
+                               msg_print(_("明かりがないので、暗くて読めない。", "You have no light to read by."));
+                               return;
+                       }
+                       if (p_ptr->confused)
+                       {
+                               msg_print(_("混乱していて読めない!", "You are too confused!"));
+                               return;
+                       }
+
+                 do_cmd_read_scroll_aux(item, TRUE);
+                 break;
+               }
+
+               /* Fire ammo */
+               case TV_SHOT:
+               case TV_ARROW:
+               case TV_BOLT:
+               {
+                       do_cmd_fire_aux(item, &inventory[INVEN_BOW]);
+                       break;
+               }
+
+               /* Activate an artifact */
+               default:
+               {
+                       do_cmd_activate_aux(item);
+                       break;
+               }
+       }
+}
+