OSDN Git Service

[Refactor] monster_name() で一部 cmd2.c の投擲対象処理を整理。
[hengband/hengband.git] / src / cmd-item.c
index f8a12d5..7dc6d1e 100644 (file)
@@ -27,6 +27,7 @@
 #include "artifact.h"
 #include "avatar.h"
 #include "player-status.h"
+#include "monster.h"
 
 
 /*!
@@ -64,7 +65,7 @@ void do_cmd_inven(void)
        /* Process "Escape" */
        if (command_new == ESCAPE)
        {
-               int wid, hgt;
+               TERM_LEN wid, hgt;
 
                Term_get_size(&wid, &hgt);
 
@@ -90,7 +91,6 @@ void do_cmd_equip(void)
 {
        char out_val[160];
 
-
        /* Note that we are in "equipment" mode */
        command_wrk = TRUE;
 
@@ -118,7 +118,7 @@ void do_cmd_equip(void)
        /* Process "Escape" */
        if (command_new == ESCAPE)
        {
-               int wid, hgt;
+               TERM_LEN wid, hgt;
 
                Term_get_size(&wid, &hgt);
 
@@ -298,16 +298,12 @@ void do_cmd_wield(void)
 
        if ((o_ptr->name1 == ART_STONEMASK) && object_is_known(o_ptr) && (p_ptr->prace != RACE_VAMPIRE) && (p_ptr->prace != RACE_ANDROID))
        {
-               char dummy[MAX_NLEN+80];
+               char dummy[MAX_NLEN+100];
 
                object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
 
-#ifdef JP
-               sprintf(dummy, "%sを装備すると吸血鬼になります。よろしいですか?", o_name);
-#else
-               msg_format("%s will transforms you into a vampire permanently when equiped.", o_name);
-               sprintf(dummy, "Do you become a vampire?");
-#endif
+               sprintf(dummy, _("%sを装備すると吸血鬼になります。よろしいですか?",
+                       "%s will transforms you into a vampire permanently when equiped. Do you become a vampire?"), o_name);
 
                if (!get_check(dummy)) return;
        }
@@ -342,7 +338,7 @@ void do_cmd_wield(void)
                autopick_alter_item(item, FALSE);
        }
 
-       p_ptr->energy_use = 100;
+       take_turn(p_ptr, 100);
        q_ptr = &forge;
 
        /* Obtain local object */
@@ -432,7 +428,7 @@ void do_cmd_wield(void)
                o_ptr->ident |= (IDENT_SENSE);
        }
 
-       /* The Stone Mask make the player turn into a vampire! */
+       /* The Stone Mask make the player current_world_ptr->game_turn into a vampire! */
        if ((o_ptr->name1 == ART_STONEMASK) && (p_ptr->prace != RACE_VAMPIRE) && (p_ptr->prace != RACE_ANDROID))
        {
                /* Turn into a vampire */
@@ -553,13 +549,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;
                }
        }
 
-       /* Take a partial turn */
-       p_ptr->energy_use = 50;
+       take_turn(p_ptr, 50);
 
        /* Take off the item */
        (void)inven_takeoff(item, 255);
@@ -600,20 +595,13 @@ void do_cmd_drop(void)
                return;
        }
 
-
-       /* See how many items */
        if (o_ptr->number > 1)
        {
-               /* Get a quantity */
                amt = get_quantity(NULL, o_ptr->number);
-
-               /* Allow user abort */
                if (amt <= 0) return;
        }
 
-
-       /* Take a partial turn */
-       p_ptr->energy_use = 50;
+       take_turn(p_ptr, 50);
 
        /* Drop (some of) the item */
        inven_drop(item, amt);
@@ -715,13 +703,9 @@ void do_cmd_destroy(void)
                } /* while (TRUE) */
        }
 
-       /* See how many items */
        if (o_ptr->number > 1)
        {
-               /* Get a quantity */
                amt = get_quantity(NULL, o_ptr->number);
-
-               /* Allow user abort */
                if (amt <= 0) return;
        }
 
@@ -731,12 +715,12 @@ void do_cmd_destroy(void)
        object_desc(o_name, o_ptr, 0);
        o_ptr->number = old_number;
 
-       p_ptr->energy_use = 100;
+       take_turn(p_ptr, 100);
 
        /* Artifacts cannot be destroyed */
        if (!can_player_destroy_object(o_ptr))
        {
-               p_ptr->energy_use = 0;
+               free_turn(p_ptr);
 
                msg_format(_("%sは破壊不可能だ。", "You cannot destroy %s."), o_name);
                return;
@@ -886,10 +870,7 @@ void do_cmd_uninscribe(void)
 
        /* Remove the incription */
        o_ptr->inscription = 0;
-
-       /* Combine the pack */
        p_ptr->update |= (PU_COMBINE);
-
        p_ptr->window |= (PW_INVEN | PW_EQUIP);
 
        /* .や$の関係で, 再計算が必要なはず -- henkma */
@@ -938,10 +919,7 @@ void do_cmd_inscribe(void)
        {
                /* Save the inscription */
                o_ptr->inscription = quark_add(out_val);
-
-               /* Combine the pack */
                p_ptr->update |= (PU_COMBINE);
-
                p_ptr->window |= (PW_INVEN | PW_EQUIP);
 
                /* .や$の関係で, 再計算が必要なはず -- henkma */
@@ -950,27 +928,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)
@@ -979,10 +936,8 @@ static bool item_tester_refill_lantern(object_type *o_ptr)
 static void do_cmd_refill_lamp(void)
 {
        OBJECT_IDX item;
-
        object_type *o_ptr;
        object_type *j_ptr;
-
        concptr q, s;
 
        /* Restrict the choices */
@@ -994,8 +949,7 @@ static void do_cmd_refill_lamp(void)
        o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR));
        if (!o_ptr) return;
 
-       /* Take a partial turn */
-       p_ptr->energy_use = 50;
+       take_turn(p_ptr, 50);
 
        /* Access the lantern */
        j_ptr = &inventory[INVEN_LITE];
@@ -1036,28 +990,9 @@ static void do_cmd_refill_lamp(void)
                floor_item_optimize(0 - item);
        }
 
-       /* Recalculate torch */
        p_ptr->update |= (PU_TORCH);
 }
 
-
-/*!
- * @brief オブジェクトが松明に束ねられるかどうかを判定する
- * An "item_tester_hook" for refilling torches
- * @param o_ptr 判定したいオブジェクトの構造体参照ポインタ
- * @return オブジェクトが松明に束ねられるならばTRUEを返す
- */
-static bool item_tester_refill_torch(object_type *o_ptr)
-{
-       /* Torches are okay */
-       if ((o_ptr->tval == TV_LITE) &&
-           (o_ptr->sval == SV_LITE_TORCH)) return (TRUE);
-
-       /* Assume not okay */
-       return (FALSE);
-}
-
-
 /*!
  * @brief 松明を束ねるコマンドのメインルーチン
  * Refuel the players torch (from the pack or floor)
@@ -1073,7 +1008,7 @@ static void do_cmd_refill_torch(void)
        concptr q, s;
 
        /* Restrict the choices */
-       item_tester_hook = item_tester_refill_torch;
+       item_tester_hook = object_can_refill_torch;
 
        q = _("どの松明で明かりを強めますか? ", "Refuel with which torch? ");
        s = _("他に松明がない。", "You have no extra torches.");
@@ -1081,8 +1016,7 @@ static void do_cmd_refill_torch(void)
        o_ptr = choose_object(&item, q, s, (USE_INVEN | USE_FLOOR));
        if (!o_ptr) return;
 
-       /* Take a partial turn */
-       p_ptr->energy_use = 50;
+       take_turn(p_ptr, 50);
 
        /* Access the primary torch */
        j_ptr = &inventory[INVEN_LITE];
@@ -1131,7 +1065,6 @@ static void do_cmd_refill_torch(void)
                floor_item_optimize(0 - item);
        }
 
-       /* Recalculate torch */
        p_ptr->update |= (PU_TORCH);
 }
 
@@ -1246,30 +1179,18 @@ void do_cmd_locate(void)
                /* Describe the location */
                if ((y2 == y1) && (x2 == x1))
                {
-#ifdef JP
-                       strcpy(tmp_val, "真上");
-#else
-                       tmp_val[0] = '\0';
-#endif
-
+                       strcpy(tmp_val, _("真上", "\0"));
                }
                else
                {
-#ifdef JP
                        sprintf(tmp_val, "%s%s",
-                               ((y2 < y1) ? "北" : (y2 > y1) ? "南" : ""),
-                               ((x2 < x1) ? "西" : (x2 > x1) ? "東" : ""));
-#else
-                       sprintf(tmp_val, "%s%s of",
-                               ((y2 < y1) ? " North" : (y2 > y1) ? " South" : ""),
-                               ((x2 < x1) ? " West" : (x2 > x1) ? " East" : ""));
-#endif
-
+                               ((y2 < y1) ? _("北", " North") : (y2 > y1) ? _("南", " South") : ""),
+                               ((x2 < x1) ? _("西", " West") : (x2 > x1) ? _("東", " East") : ""));
                }
 
                /* Prepare to ask which way to look */
-               sprintf(out_val, _("マップ位置 [%ld(%02ld),%ld(%02ld)] (プレイヤーの%s)  方向?", 
-                                              "Map sector [%ld(%02ld),%ld(%02ld)], which is%s your sector.  Direction?"),
+               sprintf(out_val, _("マップ位置 [%d(%02d),%d(%02d)] (プレイヤーの%s)  方向?", 
+                                              "Map sector [%d(%02d),%d(%02d)], which is%s your sector.  Direction?"),
                        y2 / (hgt / 2), y2 % (hgt / 2),
                        x2 / (wid / 2), x2 % (wid / 2), tmp_val);
 
@@ -1313,114 +1234,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
@@ -1442,19 +1255,19 @@ void do_cmd_query_symbol(void)
        IDX i;
        int n;
        MONRACE_IDX r_idx;
-       char    sym, query;
-       char    buf[128];
+       char sym, query;
+       char buf[128];
 
-       bool    all = FALSE;
-       bool    uniq = FALSE;
-       bool    norm = FALSE;
-       bool    ride = FALSE;
-       char    temp[80] = "";
+       bool all = FALSE;
+       bool uniq = FALSE;
+       bool norm = FALSE;
+       bool ride = FALSE;
+       char temp[80] = "";
 
-       bool    recall = FALSE;
+       bool recall = FALSE;
 
-       u16b    why = 0;
-       IDX     *who;
+       u16b why = 0;
+       MONRACE_IDX *who;
 
        /* Get a character, or abort */
        if (!get_com(_("知りたい文字を入力して下さい(記号 or ^A全,^Uユ,^N非ユ,^R乗馬,^M名前): ", 
@@ -1565,9 +1378,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;
        }
 
@@ -1580,12 +1391,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')
@@ -1597,21 +1404,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);
        }
 
 
@@ -1711,12 +1511,7 @@ void do_cmd_use(void)
                return;
        }
 
-       if (p_ptr->inside_arena)
-       {
-               msg_print(_("アリーナが魔法を吸収した!", "The arena absorbs all attempted magic!"));
-               msg_print(NULL);
-               return;
-       }
+       if (cmd_limit_arena(p_ptr)) return;
 
        if (p_ptr->special_defense & (KATA_MUSOU | KATA_KOUKIJIN))
        {
@@ -1778,25 +1573,11 @@ void do_cmd_use(void)
                /* 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;
-                       }
+                       if (cmd_limit_blind(p_ptr)) return;
+                       if (cmd_limit_confused(p_ptr)) return;
 
-                 do_cmd_read_scroll_aux(item, TRUE);
-                 break;
+                       do_cmd_read_scroll_aux(item, TRUE);
+                       break;
                }
 
                /* Fire ammo */
@@ -1804,7 +1585,7 @@ void do_cmd_use(void)
                case TV_ARROW:
                case TV_BOLT:
                {
-                       exe_fire(item, &inventory[INVEN_BOW]);
+                       exe_fire(item, &inventory[INVEN_BOW], SP_NONE);
                        break;
                }