OSDN Git Service

[Refactor] #37353 item_tester_refill_lantern() を object-hook.c へ移動。 / Move item_teste...
[hengband/hengband.git] / src / cmd-item.c
index a86e00a..8fedc95 100644 (file)
 #include "cmd-zapwand.h"
 
 #include "object-hook.h"
+#include "sort.h"
+#include "quest.h"
+#include "artifact.h"
+#include "avatar.h"
+#include "player-status.h"
 
 
 /*!
@@ -146,8 +151,8 @@ void do_cmd_wield(void)
        object_type *q_ptr;
        object_type *o_ptr;
 
-       cptr act;
-       cptr q, s;
+       concptr act;
+       concptr q, s;
 
        GAME_TEXT o_name[MAX_NLEN];
 
@@ -178,7 +183,7 @@ void do_cmd_wield(void)
        case TV_SHIELD:
        case TV_CARD:
                /* Dual wielding */
-               if (buki_motteruka(INVEN_RARM) && buki_motteruka(INVEN_LARM))
+               if (has_melee_weapon(INVEN_RARM) && has_melee_weapon(INVEN_LARM))
                {
                        /* Restrict the choices */
                        item_tester_hook = item_tester_hook_melee_weapon;
@@ -186,11 +191,11 @@ void do_cmd_wield(void)
                        /* Choose a weapon from the equipment only */
                        q = _("どちらの武器と取り替えますか?", "Replace which weapon? ");
                        s = _("おっと。", "Oops.");
-                       if (!get_item(&slot, q, s, (USE_EQUIP | IGNORE_BOTHHAND_SLOT))) return;
+                       if (!choose_object(&slot, q, s, (USE_EQUIP | IGNORE_BOTHHAND_SLOT))) return;
                        if (slot == INVEN_RARM) need_switch_wielding = INVEN_LARM;
                }
 
-               else if (buki_motteruka(INVEN_LARM)) slot = INVEN_RARM;
+               else if (has_melee_weapon(INVEN_LARM)) slot = INVEN_RARM;
 
                /* Both arms are already used by non-weapon */
                else if (inventory[INVEN_RARM].k_idx && !object_is_melee_weapon(&inventory[INVEN_RARM]) &&
@@ -202,7 +207,7 @@ void do_cmd_wield(void)
                        /* Choose a hand */
                        q = _("どちらの手に装備しますか?", "Equip which hand? ");
                        s = _("おっと。", "Oops.");
-                       if (!get_item(&slot, q, s, (USE_EQUIP))) return;
+                       if (!choose_object(&slot, q, s, (USE_EQUIP))) return;
                }
                break;
 
@@ -217,7 +222,7 @@ void do_cmd_wield(void)
                        if (!get_check(_("二刀流で戦いますか?", "Dual wielding? "))) slot = INVEN_RARM;
                }
 
-               else if (!inventory[INVEN_RARM].k_idx && buki_motteruka(INVEN_LARM))
+               else if (!inventory[INVEN_RARM].k_idx && has_melee_weapon(INVEN_LARM))
                {
                        if (!get_check(_("二刀流で戦いますか?", "Dual wielding? "))) slot = INVEN_LARM;
                }
@@ -232,8 +237,8 @@ void do_cmd_wield(void)
                        q = _("どちらの手に装備しますか?", "Equip which hand? ");
                        s = _("おっと。", "Oops.");
                        
-                       if (!get_item(&slot, q, s, (USE_EQUIP))) return;
-                       if ((slot == INVEN_LARM) && !buki_motteruka(INVEN_RARM))
+                       if (!choose_object(&slot, q, s, (USE_EQUIP))) return;
+                       if ((slot == INVEN_LARM) && !has_melee_weapon(INVEN_RARM))
                                need_switch_wielding = INVEN_RARM;
                }
                break;
@@ -254,7 +259,7 @@ void do_cmd_wield(void)
                /* Restrict the choices */
                select_ring_slot = TRUE;
 
-               if (!get_item(&slot, q, s, (USE_EQUIP | IGNORE_BOTHHAND_SLOT)))
+               if (!choose_object(&slot, q, s, (USE_EQUIP | IGNORE_BOTHHAND_SLOT)))
                {
                        select_ring_slot = FALSE;
                        return;
@@ -373,24 +378,16 @@ void do_cmd_wield(void)
        /* Wear the new stuff */
        object_copy(o_ptr, q_ptr);
 
-       /* Player touches it */
        o_ptr->marked |= OM_TOUCHED;
 
-       /* Increase the weight */
        p_ptr->total_weight += q_ptr->weight;
 
        /* Increment the equip counter by hand */
        equip_cnt++;
 
-#ifdef JP
-#define STR_WIELD_RARM "%s(%c)を右手に装備した。"
-#define STR_WIELD_LARM "%s(%c)を左手に装備した。"
-#define STR_WIELD_ARMS "%s(%c)を両手で構えた。"
-#else
-#define STR_WIELD_RARM "You are wielding %s (%c) in your right hand."
-#define STR_WIELD_LARM "You are wielding %s (%c) in your left hand."
-#define STR_WIELD_ARMS "You are wielding %s (%c) with both hands."
-#endif
+#define STR_WIELD_RARM _("%s(%c)を右手に装備した。", "You are wielding %s (%c) in your right hand.")
+#define STR_WIELD_LARM _("%s(%c)を左手に装備した。", "You are wielding %s (%c) in your left hand.")
+#define STR_WIELD_ARMS _("%s(%c)を両手で構えた。", "You are wielding %s (%c) with both hands.")
 
        /* Where is the item now */
        switch (slot)
@@ -461,7 +458,7 @@ void kamaenaoshi(INVENTORY_IDX item)
 
        if (item == INVEN_RARM)
        {
-               if (buki_motteruka(INVEN_LARM))
+               if (has_melee_weapon(INVEN_LARM))
                {
                        o_ptr = &inventory[INVEN_LARM];
                        object_desc(o_name, o_ptr, 0);
@@ -491,7 +488,7 @@ void kamaenaoshi(INVENTORY_IDX item)
                o_ptr = &inventory[INVEN_RARM];
                if (o_ptr->k_idx) object_desc(o_name, o_ptr, 0);
 
-               if (buki_motteruka(INVEN_RARM))
+               if (has_melee_weapon(INVEN_RARM))
                {
                        if (object_allow_two_hands_wielding(o_ptr) && CAN_TWO_HANDS_WIELDING())
                                msg_format(_("%sを両手で構えた。", "You are wielding %s with both hands."), o_name);
@@ -517,7 +514,7 @@ void do_cmd_takeoff(void)
 {
        OBJECT_IDX item;
        object_type *o_ptr;
-       cptr q, s;
+       concptr q, s;
 
        if (p_ptr->special_defense & KATA_MUSOU)
        {
@@ -527,20 +524,8 @@ void do_cmd_takeoff(void)
        q = _("どれを装備からはずしますか? ", "Take off which item? ");
        s = _("はずせる装備がない。", "You are not wearing anything to take off.");
 
-       if (!get_item(&item, q, s, (USE_EQUIP | IGNORE_BOTHHAND_SLOT))) 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];
-       }
-
+       o_ptr = choose_object(&item, q, s, (USE_EQUIP | IGNORE_BOTHHAND_SLOT));
+       if (!o_ptr) return;
 
        /* Item is cursed */
        if (object_is_cursed(o_ptr))
@@ -595,7 +580,7 @@ void do_cmd_drop(void)
 
        object_type *o_ptr;
 
-       cptr q, s;
+       concptr q, s;
 
        if (p_ptr->special_defense & KATA_MUSOU)
        {
@@ -605,20 +590,8 @@ void do_cmd_drop(void)
        q = _("どのアイテムを落としますか? ", "Drop which item? ");
        s = _("落とせるアイテムを持っていない。", "You have nothing to drop.");
 
-       if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | IGNORE_BOTHHAND_SLOT))) 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];
-       }
-
+       o_ptr = choose_object(&item, q, s, (USE_EQUIP | USE_INVEN | IGNORE_BOTHHAND_SLOT));
+       if (!o_ptr) return;
 
        /* Hack -- Cannot remove cursed items */
        if ((item >= INVEN_RARM) && object_is_cursed(o_ptr))
@@ -654,34 +627,6 @@ void do_cmd_drop(void)
        p_ptr->redraw |= (PR_EQUIPPY);
 }
 
-/*!
- * @brief オブジェクトが高位の魔法書かどうかを判定する
- * @param o_ptr 判定したいオブジェクトの構造体参照ポインタ
- * @return オブジェクトが高位の魔法書ならばTRUEを返す
- */
-static bool high_level_book(object_type *o_ptr)
-{
-       if ((o_ptr->tval == TV_LIFE_BOOK) ||
-           (o_ptr->tval == TV_SORCERY_BOOK) ||
-           (o_ptr->tval == TV_NATURE_BOOK) ||
-           (o_ptr->tval == TV_CHAOS_BOOK) ||
-           (o_ptr->tval == TV_DEATH_BOOK) ||
-           (o_ptr->tval == TV_TRUMP_BOOK) ||
-           (o_ptr->tval == TV_CRAFT_BOOK) ||
-           (o_ptr->tval == TV_DAEMON_BOOK) ||
-           (o_ptr->tval == TV_CRUSADE_BOOK) ||
-           (o_ptr->tval == TV_MUSIC_BOOK) ||
-               (o_ptr->tval == TV_HEX_BOOK))
-       {
-               if (o_ptr->sval > 1)
-                       return TRUE;
-               else
-                       return FALSE;
-       }
-
-       return FALSE;
-}
-
 
 /*!
  * @brief アイテムを破壊するコマンドのメインルーチン / Destroy an item
@@ -702,7 +647,7 @@ void do_cmd_destroy(void)
        GAME_TEXT o_name[MAX_NLEN];
        char out_val[MAX_NLEN+40];
 
-       cptr q, s;
+       concptr q, s;
 
        if (p_ptr->special_defense & KATA_MUSOU)
        {
@@ -715,19 +660,8 @@ void do_cmd_destroy(void)
        q = _("どのアイテムを壊しますか? ", "Destroy which item? ");
        s = _("壊せるアイテムを持っていない。", "You have nothing to destroy.");
 
-       if (!get_item(&item, q, s, (USE_INVEN | 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];
-       }
+       o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR));
+       if (!o_ptr) return;
 
        /* Verify unless quantity given beforehand */
        if (!force && (confirm_destroy || (object_value(o_ptr) > 0)))
@@ -832,7 +766,7 @@ void do_cmd_destroy(void)
                floor_item_optimize(0 - item);
        }
 
-       if (high_level_book(q_ptr))
+       if (item_tester_high_level_book(q_ptr))
        {
                bool gain_expr = FALSE;
 
@@ -865,12 +799,12 @@ void do_cmd_destroy(void)
                        msg_print(_("更に経験を積んだような気がする。", "You feel more experienced."));
                        gain_exp(tester_exp * amt);
                }
-               if (high_level_book(q_ptr) && q_ptr->tval == TV_LIFE_BOOK)
+               if (item_tester_high_level_book(q_ptr) && q_ptr->tval == TV_LIFE_BOOK)
                {
                        chg_virtue(V_UNLIFE, 1);
                        chg_virtue(V_VITALITY, -1);
                }
-               else if (high_level_book(q_ptr) && q_ptr->tval == TV_DEATH_BOOK)
+               else if (item_tester_high_level_book(q_ptr) && q_ptr->tval == TV_DEATH_BOOK)
                {
                        chg_virtue(V_UNLIFE, -1);
                        chg_virtue(V_VITALITY, 1);
@@ -902,26 +836,13 @@ void do_cmd_observe(void)
        OBJECT_IDX item;
        object_type *o_ptr;
        GAME_TEXT o_name[MAX_NLEN];
-       cptr q, s;
-
+       concptr q, s;
 
        q = _("どのアイテムを調べますか? ", "Examine which item? ");
        s = _("調べられるアイテムがない。", "You have nothing to examine.");
 
-       if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT))) 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];
-       }
-
+       o_ptr = choose_object(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT));
+       if (!o_ptr) return;
 
        /* Require full knowledge */
        if (!(o_ptr->ident & IDENT_MENTAL))
@@ -930,11 +851,8 @@ void do_cmd_observe(void)
                return;
        }
 
-
-       /* Description */
        object_desc(o_name, o_ptr, 0);
        msg_format(_("%sを調べている...", "Examining %s..."), o_name);
-       /* Describe it fully */
        if (!screen_object(o_ptr, SCROBJ_FORCE_DETAIL)) msg_print(_("特に変わったところはないようだ。", "You see nothing special."));
 }
 
@@ -949,24 +867,13 @@ void do_cmd_uninscribe(void)
 {
        OBJECT_IDX item;
        object_type *o_ptr;
-       cptr q, s;
+       concptr q, s;
 
        q = _("どのアイテムの銘を消しますか? ", "Un-inscribe which item? ");
        s = _("銘を消せるアイテムがない。", "You have nothing to un-inscribe.");
 
-       if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT))) 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];
-       }
+       o_ptr = choose_object(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT));
+       if (!o_ptr) return;
 
        /* Nothing to remove */
        if (!o_ptr->inscription)
@@ -999,27 +906,16 @@ void do_cmd_uninscribe(void)
 void do_cmd_inscribe(void)
 {
        OBJECT_IDX item;
-       object_type             *o_ptr;
+       object_type *o_ptr;
        GAME_TEXT o_name[MAX_NLEN];
-       char            out_val[80];
-       cptr q, s;
+       char out_val[80];
+       concptr q, s;
 
        q = _("どのアイテムに銘を刻みますか? ", "Inscribe which item? ");
        s = _("銘を刻めるアイテムがない。", "You have nothing to inscribe.");
 
-       if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT))) 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];
-       }
+       o_ptr = choose_object(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT));
+       if (!o_ptr) return;
 
        /* Describe the activity */
        object_desc(o_name, o_ptr, OD_OMIT_INSCRIPTION);
@@ -1054,27 +950,6 @@ void do_cmd_inscribe(void)
 }
 
 
-
-/*!
- * @brief オブジェクトがランタンの燃料になるかどうかを判定する
- * An "item_tester_hook" for refilling lanterns
- * @param o_ptr 判定したいオブジェクトの構造体参照ポインタ
- * @return オブジェクトがランタンの燃料になるならばTRUEを返す
- */
-static bool item_tester_refill_lantern(object_type *o_ptr)
-{
-       /* Flasks of oil are okay */
-       if (o_ptr->tval == TV_FLASK) return (TRUE);
-
-       /* Laterns are okay */
-       if ((o_ptr->tval == TV_LITE) &&
-           (o_ptr->sval == SV_LITE_LANTERN)) return (TRUE);
-
-       /* Assume not okay */
-       return (FALSE);
-}
-
-
 /*!
  * @brief ランタンに燃料を加えるコマンドのメインルーチン
  * Refill the players lamp (from the pack or floor)
@@ -1087,33 +962,16 @@ static void do_cmd_refill_lamp(void)
        object_type *o_ptr;
        object_type *j_ptr;
 
-       cptr q, s;
-
+       concptr q, s;
 
        /* Restrict the choices */
        item_tester_hook = item_tester_refill_lantern;
 
-#ifdef JP
-       q = "どの油つぼから注ぎますか? ";
-       s = "油つぼがない。";
-#else
-       q = "Refill with which flask? ";
-       s = "You have no flasks of oil.";
-#endif
-
-       if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR))) return;
-
-       /* Get the item (in the pack) */
-       if (item >= 0)
-       {
-               o_ptr = &inventory[item];
-       }
+       q = _("どの油つぼから注ぎますか? ", "Refill with which flask? ");
+       s = _("油つぼがない。", "You have no flasks of oil.");
 
-       /* Get the item (on the floor) */
-       else
-       {
-               o_ptr = &o_list[0 - item];
-       }
+       o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR));
+       if (!o_ptr) return;
 
        /* Take a partial turn */
        p_ptr->energy_use = 50;
@@ -1191,7 +1049,7 @@ static void do_cmd_refill_torch(void)
        object_type *o_ptr;
        object_type *j_ptr;
 
-       cptr q, s;
+       concptr q, s;
 
        /* Restrict the choices */
        item_tester_hook = item_tester_refill_torch;
@@ -1199,20 +1057,8 @@ static void do_cmd_refill_torch(void)
        q = _("どの松明で明かりを強めますか? ", "Refuel with which torch? ");
        s = _("他に松明がない。", "You have no extra torches.");
 
-       if (!get_item(&item, q, s, (USE_INVEN | 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];
-       }
-
+       o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR));
+       if (!o_ptr) return;
 
        /* Take a partial turn */
        p_ptr->energy_use = 50;
@@ -1361,17 +1207,14 @@ void do_cmd_look(void)
  */
 void do_cmd_locate(void)
 {
-       int             dir, y1, x1, y2, x2;
-
-       char    tmp_val[80];
-
-       char    out_val[160];
-
-       int wid, hgt;
+       DIRECTION dir;
+       POSITION y1, x1, y2, x2;
+       GAME_TEXT tmp_val[80];
+       GAME_TEXT out_val[160];
+       TERM_LEN wid, hgt;
 
        get_screen_size(&wid, &hgt);
 
-
        /* Start at current panel */
        y2 = y1 = panel_row_min;
        x2 = x1 = panel_col_min;
@@ -1404,8 +1247,8 @@ void do_cmd_locate(void)
                }
 
                /* Prepare to ask which way to look */
-               sprintf(out_val, _("マップ位置 [%d(%02d),%d(%02d)] (プレイヤーの%s)  方向?", 
-                                              "Map sector [%d(%02d),%d(%02d)], which is%s your sector.  Direction?"),
+               sprintf(out_val, _("マップ位置 [%ld(%02ld),%ld(%02ld)] (プレイヤーの%s)  方向?", 
+                                              "Map sector [%ld(%02ld),%ld(%02ld)], which is%s your sector.  Direction?"),
                        y2 / (hgt / 2), y2 % (hgt / 2),
                        x2 / (wid / 2), x2 % (wid / 2), tmp_val);
 
@@ -1443,9 +1286,7 @@ void do_cmd_locate(void)
        verify_panel();
 
        p_ptr->update |= (PU_MONSTERS);
-
        p_ptr->redraw |= (PR_MAP);
-
        p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
        handle_stuff();
 }
@@ -1466,7 +1307,6 @@ void do_cmd_locate(void)
 bool ang_sort_comp_hook(vptr u, vptr v, int a, int b)
 {
        u16b *who = (u16b*)(u);
-
        u16b *why = (u16b*)(v);
 
        int w1 = who[a];
@@ -1648,7 +1488,7 @@ void do_cmd_query_symbol(void)
        prt(buf, 0, 0);
 
        /* Allocate the "who" array */
-       C_MAKE(who, max_r_idx, IDX);
+       C_MAKE(who, max_r_idx, MONRACE_IDX);
 
        /* Collect matching monsters */
        for (n = 0, i = 1; i < max_r_idx; i++)
@@ -1715,8 +1555,6 @@ void do_cmd_query_symbol(void)
 
        /* Query */
        query = inkey();
-
-       /* Restore */
        prt(buf, 0, 0);
 
        why = 2;
@@ -1793,7 +1631,6 @@ void do_cmd_query_symbol(void)
                        /* Unrecall */
                        if (recall)
                        {
-                               /* Restore */
                                screen_load();
                        }
 
@@ -1846,7 +1683,7 @@ void do_cmd_use(void)
 {
        OBJECT_IDX item;
        object_type *o_ptr;
-       cptr q, s;
+       concptr q, s;
 
        if (p_ptr->wild_mode)
        {
@@ -1870,18 +1707,8 @@ void do_cmd_use(void)
        q = _("どれを使いますか?", "Use which item? ");
        s = _("使えるものがありません。", "You have nothing to use.");
 
-       if (!get_item(&item, q, s, (USE_INVEN | USE_EQUIP | USE_FLOOR | IGNORE_BOTHHAND_SLOT))) 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];
-       }
+       o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_EQUIP | USE_FLOOR | IGNORE_BOTHHAND_SLOT));
+       if (!o_ptr) return;
 
        switch (o_ptr->tval)
        {
@@ -1956,7 +1783,7 @@ void do_cmd_use(void)
                case TV_ARROW:
                case TV_BOLT:
                {
-                       do_cmd_fire_aux(item, &inventory[INVEN_BOW]);
+                       exe_fire(item, &inventory[INVEN_BOW]);
                        break;
                }