OSDN Git Service

[Refactor] #39068 show_inven(), show_equip() の item_tester_tval グローバル参照をローカル引数に収める.
[hengband/hengband.git] / src / cmd-item.c
index 0f770c5..3ab2d26 100644 (file)
 
 
 #include "angband.h"
+#include "core.h"
+#include "util.h"
+#include "autopick.h"
+#include "term.h"
+
 #include "selfinfo.h"
 #include "cmd-activate.h"
 #include "cmd-eat.h"
 #include "cmd-usestaff.h"
 #include "cmd-zaprod.h"
 #include "cmd-zapwand.h"
+#include "cmd-pet.h"
+#include "cmd-basic.h"
 
+#include "object-flavor.h"
 #include "object-hook.h"
+#include "object-ego.h"
 #include "sort.h"
 #include "quest.h"
 #include "artifact.h"
 #include "avatar.h"
 #include "player-status.h"
-
+#include "player-effects.h"
+#include "player-class.h"
+#include "player-personality.h"
+#include "monster.h"
+#include "view-mainwindow.h"
+#include "spells.h"
+#include "objectkind.h"
+#include "autopick.h"
+#include "targeting.h"
+#include "snipe.h"
+#include "player-race.h"
+#include "view-mainwindow.h"
 
 /*!
- * @brief 持ち物一覧を表示するコマンドのメインルーチン / Display inventory
+ * @brief 持ち物一覧を表示するコマンドのメインルーチン / Display p_ptr->inventory_list
  * @return なし 
  */
 void do_cmd_inven(void)
 {
        char out_val[160];
 
-       /* Note that we are in "inventory" mode */
+       /* Note that we are in "p_ptr->inventory_list" mode */
        command_wrk = FALSE;
 
-       /* Note that we are in "inventory" mode */
+       /* Note that we are in "p_ptr->inventory_list" mode */
        if (easy_floor) command_wrk = (USE_INVEN);
        screen_save();
 
-       /* Display the inventory */
-       (void)show_inven(0, USE_FULL);
+       /* Display the p_ptr->inventory_list */
+       (void)show_inven(0, USE_FULL, item_tester_tval);
 
 #ifdef JP
        sprintf(out_val, "持ち物: 合計 %3d.%1d kg (限界の%ld%%) コマンド: ",
@@ -97,7 +117,7 @@ void do_cmd_equip(void)
        if (easy_floor) command_wrk = (USE_EQUIP);
        screen_save();
 
-       (void)show_equip(0, USE_FULL);
+       (void)show_equip(0, USE_FULL, item_tester_tval);
 
        /* Build a prompt */
 #ifdef JP
@@ -197,8 +217,8 @@ void do_cmd_wield(void)
                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]) &&
-                        inventory[INVEN_LARM].k_idx && !object_is_melee_weapon(&inventory[INVEN_LARM]))
+               else if (p_ptr->inventory_list[INVEN_RARM].k_idx && !object_is_melee_weapon(&p_ptr->inventory_list[INVEN_RARM]) &&
+                        p_ptr->inventory_list[INVEN_LARM].k_idx && !object_is_melee_weapon(&p_ptr->inventory_list[INVEN_LARM]))
                {
                        /* Restrict the choices */
                        item_tester_hook = item_tester_hook_mochikae;
@@ -221,13 +241,13 @@ void do_cmd_wield(void)
                        if (!get_check(_("二刀流で戦いますか?", "Dual wielding? "))) slot = INVEN_RARM;
                }
 
-               else if (!inventory[INVEN_RARM].k_idx && has_melee_weapon(INVEN_LARM))
+               else if (!p_ptr->inventory_list[INVEN_RARM].k_idx && has_melee_weapon(INVEN_LARM))
                {
                        if (!get_check(_("二刀流で戦いますか?", "Dual wielding? "))) slot = INVEN_LARM;
                }
 
                /* Both arms are already used */
-               else if (inventory[INVEN_LARM].k_idx && inventory[INVEN_RARM].k_idx)
+               else if (p_ptr->inventory_list[INVEN_LARM].k_idx && p_ptr->inventory_list[INVEN_RARM].k_idx)
                {
                        /* Restrict the choices */
                        item_tester_hook = item_tester_hook_mochikae;
@@ -245,7 +265,7 @@ void do_cmd_wield(void)
        /* Rings */
        case TV_RING:
                /* Choose a ring slot */
-               if (inventory[INVEN_LEFT].k_idx && inventory[INVEN_RIGHT].k_idx)
+               if (p_ptr->inventory_list[INVEN_LEFT].k_idx && p_ptr->inventory_list[INVEN_RIGHT].k_idx)
                {
                        q = _("どちらの指輪と取り替えますか?", "Replace which ring? ");
                }
@@ -268,9 +288,9 @@ void do_cmd_wield(void)
        }
 
        /* Prevent wielding into a cursed slot */
-       if (object_is_cursed(&inventory[slot]))
+       if (object_is_cursed(&p_ptr->inventory_list[slot]))
        {
-               object_desc(o_name, &inventory[slot], (OD_OMIT_PREFIX | OD_NAME_ONLY));
+               object_desc(o_name, &p_ptr->inventory_list[slot], (OD_OMIT_PREFIX | OD_NAME_ONLY));
 
 #ifdef JP
                msg_format("%s%sは呪われているようだ。", describe_use(slot) , o_name );
@@ -307,10 +327,10 @@ void do_cmd_wield(void)
                if (!get_check(dummy)) return;
        }
 
-       if (need_switch_wielding && !object_is_cursed(&inventory[need_switch_wielding]))
+       if (need_switch_wielding && !object_is_cursed(&p_ptr->inventory_list[need_switch_wielding]))
        {
-               object_type *slot_o_ptr = &inventory[slot];
-               object_type *switch_o_ptr = &inventory[need_switch_wielding];
+               object_type *slot_o_ptr = &p_ptr->inventory_list[slot];
+               object_type *switch_o_ptr = &p_ptr->inventory_list[need_switch_wielding];
                object_type object_tmp;
                object_type *otmp_ptr = &object_tmp;
                GAME_TEXT switch_name[MAX_NLEN];
@@ -361,7 +381,7 @@ void do_cmd_wield(void)
        }
 
        /* Access the wield slot */
-       o_ptr = &inventory[slot];
+       o_ptr = &p_ptr->inventory_list[slot];
 
        /* Take off existing item */
        if (o_ptr->k_idx)
@@ -378,7 +398,7 @@ void do_cmd_wield(void)
        p_ptr->total_weight += q_ptr->weight;
 
        /* Increment the equip counter by hand */
-       equip_cnt++;
+       p_ptr->equip_cnt++;
 
 #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.")
@@ -455,12 +475,12 @@ void kamaenaoshi(INVENTORY_IDX item)
        {
                if (has_melee_weapon(INVEN_LARM))
                {
-                       o_ptr = &inventory[INVEN_LARM];
+                       o_ptr = &p_ptr->inventory_list[INVEN_LARM];
                        object_desc(o_name, o_ptr, 0);
 
                        if (!object_is_cursed(o_ptr))
                        {
-                               new_o_ptr = &inventory[INVEN_RARM];
+                               new_o_ptr = &p_ptr->inventory_list[INVEN_RARM];
                                object_copy(new_o_ptr, o_ptr);
                                p_ptr->total_weight += o_ptr->weight;
                                inven_item_increase(INVEN_LARM, -((int)o_ptr->number));
@@ -480,7 +500,7 @@ void kamaenaoshi(INVENTORY_IDX item)
        }
        else if (item == INVEN_LARM)
        {
-               o_ptr = &inventory[INVEN_RARM];
+               o_ptr = &p_ptr->inventory_list[INVEN_RARM];
                if (o_ptr->k_idx) object_desc(o_name, o_ptr, 0);
 
                if (has_melee_weapon(INVEN_RARM))
@@ -490,7 +510,7 @@ void kamaenaoshi(INVENTORY_IDX item)
                }
                else if (!(empty_hands(FALSE) & EMPTY_HAND_RARM) && !object_is_cursed(o_ptr))
                {
-                       new_o_ptr = &inventory[INVEN_LARM];
+                       new_o_ptr = &p_ptr->inventory_list[INVEN_LARM];
                        object_copy(new_o_ptr, o_ptr);
                        p_ptr->total_weight += o_ptr->weight;
                        inven_item_increase(INVEN_RARM, -((int)o_ptr->number));
@@ -548,12 +568,12 @@ void do_cmd_takeoff(void)
                else
                {
                        msg_print(_("装備を外せなかった。", "You couldn't remove the equipment."));
-                       p_ptr->energy_use = 50;
+                       take_turn(p_ptr, 50);
                        return;
                }
        }
 
-       p_ptr->energy_use = 50;
+       take_turn(p_ptr, 50);
 
        /* Take off the item */
        (void)inven_takeoff(item, 255);
@@ -600,7 +620,7 @@ void do_cmd_drop(void)
                if (amt <= 0) return;
        }
 
-       p_ptr->energy_use = 50;
+       take_turn(p_ptr, 50);
 
        /* Drop (some of) the item */
        inven_drop(item, amt);
@@ -948,10 +968,10 @@ static void do_cmd_refill_lamp(void)
        o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR));
        if (!o_ptr) return;
 
-       p_ptr->energy_use = 50;
+       take_turn(p_ptr, 50);
 
        /* Access the lantern */
-       j_ptr = &inventory[INVEN_LITE];
+       j_ptr = &p_ptr->inventory_list[INVEN_LITE];
 
        /* Refuel */
        j_ptr->xtra4 += o_ptr->xtra4;
@@ -1015,10 +1035,10 @@ static void do_cmd_refill_torch(void)
        o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR));
        if (!o_ptr) return;
 
-       p_ptr->energy_use = 50;
+       take_turn(p_ptr, 50);
 
        /* Access the primary torch */
-       j_ptr = &inventory[INVEN_LITE];
+       j_ptr = &p_ptr->inventory_list[INVEN_LITE];
 
        /* Refuel */
        j_ptr->xtra4 += o_ptr->xtra4 + 5;
@@ -1078,7 +1098,7 @@ void do_cmd_refill(void)
        object_type *o_ptr;
 
        /* Get the light */
-       o_ptr = &inventory[INVEN_LITE];
+       o_ptr = &p_ptr->inventory_list[INVEN_LITE];
 
        if (p_ptr->special_defense & KATA_MUSOU)
        {
@@ -1233,113 +1253,6 @@ void do_cmd_locate(void)
 }
 
 
-
-/*!
- * @brief モンスター種族情報を特定の基準によりソートするための比較処理
- * Sorting hook -- Comp function -- see below
- * @param u モンスター種族情報の入れるポインタ
- * @param v 条件基準ID
- * @param a 比較するモンスター種族のID1
- * @param b 比較するモンスター種族のID2
- * @return 2の方が大きければTRUEを返す
- * We use "u" to point to array of monster indexes,
- * and "v" to select the type of sorting to perform on "u".
- */
-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];
-       int w2 = who[b];
-
-       int z1, z2;
-
-       /* Sort by player kills */
-       if (*why >= 4)
-       {
-               /* Extract player kills */
-               z1 = r_info[w1].r_pkills;
-               z2 = r_info[w2].r_pkills;
-
-               /* Compare player kills */
-               if (z1 < z2) return (TRUE);
-               if (z1 > z2) return (FALSE);
-       }
-
-
-       /* Sort by total kills */
-       if (*why >= 3)
-       {
-               /* Extract total kills */
-               z1 = r_info[w1].r_tkills;
-               z2 = r_info[w2].r_tkills;
-
-               /* Compare total kills */
-               if (z1 < z2) return (TRUE);
-               if (z1 > z2) return (FALSE);
-       }
-
-
-       /* Sort by monster level */
-       if (*why >= 2)
-       {
-               /* Extract levels */
-               z1 = r_info[w1].level;
-               z2 = r_info[w2].level;
-
-               /* Compare levels */
-               if (z1 < z2) return (TRUE);
-               if (z1 > z2) return (FALSE);
-       }
-
-
-       /* Sort by monster experience */
-       if (*why >= 1)
-       {
-               /* Extract experience */
-               z1 = r_info[w1].mexp;
-               z2 = r_info[w2].mexp;
-
-               /* Compare experience */
-               if (z1 < z2) return (TRUE);
-               if (z1 > z2) return (FALSE);
-       }
-
-
-       /* Compare indexes */
-       return (w1 <= w2);
-}
-
-
-/*!
- * @brief モンスター種族情報を特定の基準によりソートするためのスワップ処理
- * Sorting hook -- Swap function -- see below
- * @param u モンスター種族情報の入れるポインタ
- * @param v 未使用
- * @param a スワップするモンスター種族のID1
- * @param b スワップするモンスター種族のID2
- * @return なし
- * @details
- * We use "u" to point to array of monster indexes,
- * and "v" to select the type of sorting to perform.
- */
-void ang_sort_swap_hook(vptr u, vptr v, int a, int b)
-{
-       u16b *who = (u16b*)(u);
-       u16b holder;
-
-       /* Unused */
-       (void)v;
-
-       /* Swap */
-       holder = who[a];
-       who[a] = who[b];
-       who[b] = holder;
-}
-
-
-
 /*!
  * @brief モンスターの思い出を見るコマンドのメインルーチン
  * Identify a character, allow recall of monsters
@@ -1484,9 +1397,7 @@ void do_cmd_query_symbol(void)
        /* Nothing to recall */
        if (!n)
        {
-               /* Free the "who" array */
-               C_KILL(who, max_r_idx, IDX);
-
+               C_KILL(who, max_r_idx, MONRACE_IDX);
                return;
        }
 
@@ -1499,12 +1410,8 @@ void do_cmd_query_symbol(void)
 
        why = 2;
 
-       /* Select the sort method */
-       ang_sort_comp = ang_sort_comp_hook;
-       ang_sort_swap = ang_sort_swap_hook;
-
        /* Sort the array */
-       ang_sort(who, &why, n);
+       ang_sort(who, &why, n, ang_sort_comp_hook, ang_sort_swap_hook);
 
        /* Sort by kills (and level) */
        if (query == 'k')
@@ -1516,21 +1423,14 @@ void do_cmd_query_symbol(void)
        /* Catch "escape" */
        if (query != 'y')
        {
-               /* Free the "who" array */
-               C_KILL(who, max_r_idx, IDX);
-
+               C_KILL(who, max_r_idx, MONRACE_IDX);
                return;
        }
 
        /* Sort if needed */
        if (why == 4)
        {
-               /* Select the sort method */
-               ang_sort_comp = ang_sort_comp_hook;
-               ang_sort_swap = ang_sort_swap_hook;
-
-               /* Sort the array */
-               ang_sort(who, &why, n);
+               ang_sort(who, &why, n, ang_sort_comp_hook, ang_sort_swap_hook);
        }
 
 
@@ -1565,7 +1465,6 @@ void do_cmd_query_symbol(void)
                        /* Hack -- Complete the prompt */
                        Term_addstr(-1, TERM_WHITE, _(" ['r'思い出, ESC]", " [(r)ecall, ESC]"));
 
-                       /* Command */
                        query = inkey();
 
                        /* Unrecall */
@@ -1704,7 +1603,7 @@ void do_cmd_use(void)
                case TV_ARROW:
                case TV_BOLT:
                {
-                       exe_fire(item, &inventory[INVEN_BOW]);
+                       exe_fire(item, &p_ptr->inventory_list[INVEN_BOW], SP_NONE);
                        break;
                }