OSDN Git Service

[Refactor] #37353 コメント整理。 / Refactor comments.
[hengband/hengband.git] / src / object2.c
index 051e735..720a9cb 100644 (file)
 
 #include "angband.h"
 #include "object-hook.h"
+#include "object-curse.h"
+#include "artifact.h"
+#include "player-status.h"
 
 static void one_sustain(object_type *o_ptr);
 
 
-static cptr const kaji_tips[5] =
+static concptr const kaji_tips[5] =
 {
 #ifdef JP
        "現在持っているエッセンスの一覧を表示する。",
@@ -42,7 +45,7 @@ static cptr const kaji_tips[5] =
  */
 static void one_sustain(object_type *o_ptr)
 {
-       switch (randint0(6))
+       switch (randint0(A_MAX))
        {
        case 0: add_flag(o_ptr->art_flags, TR_SUST_STR); break;
        case 1: add_flag(o_ptr->art_flags, TR_SUST_INT); break;
@@ -58,14 +61,12 @@ static void one_sustain(object_type *o_ptr)
  * @param o_idx 削除対象のオブジェクト構造体ポインタ
  * @return なし
  */
-void excise_object_idx(int o_idx)
+void excise_object_idx(OBJECT_IDX o_idx)
 {
        object_type *j_ptr;
 
-       s16b this_o_idx, next_o_idx = 0;
-
-       s16b prev_o_idx = 0;
-
+       OBJECT_IDX this_o_idx, next_o_idx = 0;
+       OBJECT_IDX prev_o_idx = 0;
 
        /* Object */
        j_ptr = &o_list[o_idx];
@@ -82,14 +83,11 @@ void excise_object_idx(int o_idx)
                for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
                {
                        object_type *o_ptr;
-
-                       /* Acquire object */
                        o_ptr = &o_list[this_o_idx];
 
                        /* Acquire next object */
                        next_o_idx = o_ptr->next_o_idx;
 
-                       /* Done */
                        if (this_o_idx == o_idx)
                        {
                                /* No previous */
@@ -114,7 +112,6 @@ void excise_object_idx(int o_idx)
                                /* Forget next pointer */
                                o_ptr->next_o_idx = 0;
 
-                               /* Done */
                                break;
                        }
 
@@ -126,33 +123,29 @@ void excise_object_idx(int o_idx)
        /* Dungeon */
        else
        {
-               cave_type *c_ptr;
+               grid_type *g_ptr;
 
-               int y = j_ptr->iy;
-               int x = j_ptr->ix;
+               POSITION y = j_ptr->iy;
+               POSITION x = j_ptr->ix;
 
-               /* Grid */
-               c_ptr = &cave[y][x];
+               g_ptr = &grid_array[y][x];
 
                /* Scan all objects in the grid */
-               for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
+               for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
                {
                        object_type *o_ptr;
-
-                       /* Acquire object */
                        o_ptr = &o_list[this_o_idx];
 
                        /* Acquire next object */
                        next_o_idx = o_ptr->next_o_idx;
 
-                       /* Done */
                        if (this_o_idx == o_idx)
                        {
                                /* No previous */
                                if (prev_o_idx == 0)
                                {
                                        /* Remove from list */
-                                       c_ptr->o_idx = next_o_idx;
+                                       g_ptr->o_idx = next_o_idx;
                                }
 
                                /* Real previous */
@@ -170,7 +163,6 @@ void excise_object_idx(int o_idx)
                                /* Forget next pointer */
                                o_ptr->next_o_idx = 0;
 
-                               /* Done */
                                break;
                        }
 
@@ -188,7 +180,7 @@ void excise_object_idx(int o_idx)
  * @details
  * Handle "stacks" of objects correctly.
  */
-void delete_object_idx(int o_idx)
+void delete_object_idx(OBJECT_IDX o_idx)
 {
        object_type *j_ptr;
 
@@ -201,17 +193,14 @@ void delete_object_idx(int o_idx)
        /* Dungeon floor */
        if (!(j_ptr->held_m_idx))
        {
-               int y, x;
+               POSITION y, x;
 
-               /* Location */
                y = j_ptr->iy;
                x = j_ptr->ix;
 
                /* Visual update */
                lite_spot(y, x);
        }
-
-       /* Wipe the object */
        object_wipe(j_ptr);
 
        /* Count objects */
@@ -226,32 +215,24 @@ void delete_object_idx(int o_idx)
  * @param x 削除したフロアマスのX座標
  * @return なし
  */
-void delete_object(int y, int x)
+void delete_object(POSITION y, POSITION x)
 {
-       cave_type *c_ptr;
-
-       s16b this_o_idx, next_o_idx = 0;
-
+       grid_type *g_ptr;
+       OBJECT_IDX this_o_idx, next_o_idx = 0;
 
        /* Refuse "illegal" locations */
        if (!in_bounds(y, x)) return;
 
-
-       /* Grid */
-       c_ptr = &cave[y][x];
+       g_ptr = &grid_array[y][x];
 
        /* Scan all objects in the grid */
-       for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
+       for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
        {
                object_type *o_ptr;
-
-               /* Acquire object */
                o_ptr = &o_list[this_o_idx];
 
                /* Acquire next object */
                next_o_idx = o_ptr->next_o_idx;
-
-               /* Wipe the object */
                object_wipe(o_ptr);
 
                /* Count objects */
@@ -259,7 +240,7 @@ void delete_object(int y, int x)
        }
 
        /* Objects are gone */
-       c_ptr->o_idx = 0;
+       g_ptr->o_idx = 0;
 
        /* Visual update */
        lite_spot(y, x);
@@ -273,20 +254,18 @@ void delete_object(int y, int x)
  * @param i2 整理したい配列の終点
  * @return なし
  */
-static void compact_objects_aux(IDX i1, IDX i2)
+static void compact_objects_aux(OBJECT_IDX i1, OBJECT_IDX i2)
 {
-       IDX i;
-       cave_type *c_ptr;
+       OBJECT_IDX i;
+       grid_type *g_ptr;
        object_type *o_ptr;
 
        /* Do nothing */
        if (i1 == i2) return;
 
-
        /* Repair objects */
        for (i = 1; i < o_max; i++)
        {
-               /* Acquire object */
                o_ptr = &o_list[i];
 
                /* Skip "dead" objects */
@@ -299,12 +278,8 @@ static void compact_objects_aux(IDX i1, IDX i2)
                        o_ptr->next_o_idx = i2;
                }
        }
-
-
-       /* Acquire object */
        o_ptr = &o_list[i1];
 
-
        /* Monster */
        if (o_ptr->held_m_idx)
        {
@@ -324,24 +299,23 @@ static void compact_objects_aux(IDX i1, IDX i2)
        /* Dungeon */
        else
        {
-               int y, x;
+               POSITION y, x;
 
                /* Acquire location */
                y = o_ptr->iy;
                x = o_ptr->ix;
 
                /* Acquire grid */
-               c_ptr = &cave[y][x];
+               g_ptr = &grid_array[y][x];
 
                /* Repair grid */
-               if (c_ptr->o_idx == i1)
+               if (g_ptr->o_idx == i1)
                {
                        /* Repair */
-                       c_ptr->o_idx = i2;
+                       g_ptr->o_idx = i2;
                }
        }
 
-
        /* Structure copy */
        o_list[i2] = o_list[i1];
 
@@ -368,22 +342,17 @@ static void compact_objects_aux(IDX i1, IDX i2)
  */
 void compact_objects(int size)
 {
-       IDX i;
-       int y, x, num, cnt;
+       OBJECT_IDX i;
+       POSITION y, x;
+       int num, cnt;
        int cur_lev, cur_dis, chance;
        object_type *o_ptr;
 
-
        /* Compact */
        if (size)
        {
-               /* Message */
                msg_print(_("アイテム情報を圧縮しています...", "Compacting objects..."));
-
-               /* Redraw map */
                p_ptr->redraw |= (PR_MAP);
-
-               /* Window stuff */
                p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
        }
 
@@ -416,7 +385,6 @@ void compact_objects(int size)
                                /* Acquire monster */
                                m_ptr = &m_list[o_ptr->held_m_idx];
 
-                               /* Get the location */
                                y = m_ptr->fy;
                                x = m_ptr->fx;
 
@@ -427,7 +395,6 @@ void compact_objects(int size)
                        /* Dungeon */
                        else
                        {
-                               /* Get the location */
                                y = o_ptr->iy;
                                x = o_ptr->ix;
                        }
@@ -445,7 +412,6 @@ void compact_objects(int size)
                        /* Apply the saving throw */
                        if (randint0(100) < chance) continue;
 
-                       /* Delete the object */
                        delete_object_idx(i);
 
                        /* Count it */
@@ -476,7 +442,7 @@ void compact_objects(int size)
  * Delete all the items when player leaves the level
  * @note we do NOT visually reflect these (irrelevant) changes
  * @details
- * Hack -- we clear the "c_ptr->o_idx" field for every grid,
+ * Hack -- we clear the "g_ptr->o_idx" field for every grid,
  * and the "m_ptr->next_o_idx" field for every monster, since
  * we know we are clearing every object.  Technically, we only
  * clear those fields for grids/monsters containing objects,
@@ -521,20 +487,18 @@ void wipe_o_list(void)
                /* Dungeon */
                else
                {
-                       cave_type *c_ptr;
+                       grid_type *g_ptr;
 
                        /* Access location */
-                       int y = o_ptr->iy;
-                       int x = o_ptr->ix;
+                       POSITION y = o_ptr->iy;
+                       POSITION x = o_ptr->ix;
 
                        /* Access grid */
-                       c_ptr = &cave[y][x];
+                       g_ptr = &grid_array[y][x];
 
                        /* Hack -- see above */
-                       c_ptr->o_idx = 0;
+                       g_ptr->o_idx = 0;
                }
-
-               /* Wipe the object */
                object_wipe(o_ptr);
        }
 
@@ -554,10 +518,9 @@ void wipe_o_list(void)
  * This routine should almost never fail, but in case it does,
  * we must be sure to handle "failure" of this routine.
  */
-IDX o_pop(void)
+OBJECT_IDX o_pop(void)
 {
-       IDX i;
-
+       OBJECT_IDX i;
 
        /* Initial allocation */
        if (o_max < max_o_idx)
@@ -580,8 +543,6 @@ IDX o_pop(void)
        for (i = 1; i < o_max; i++)
        {
                object_type *o_ptr;
-
-               /* Acquire object */
                o_ptr = &o_list[i];
 
                /* Skip live objects */
@@ -598,7 +559,6 @@ IDX o_pop(void)
        /* Warn the player (except during dungeon creation) */
        if (character_dungeon) msg_print(_("アイテムが多すぎる!", "Too many objects!"));
 
-       /* Oops */
        return (0);
 }
 
@@ -657,18 +617,18 @@ static errr get_obj_num_prep(void)
  * Note that if no objects are "appropriate", then this function will\n
  * fail, and return zero, but this should *almost* never happen.\n
  */
-s16b get_obj_num(int level)
+OBJECT_IDX get_obj_num(DEPTH level)
 {
-       int             i, j, p;
-       int             k_idx;
-       long            value, total;
+       int i, j, p;
+       KIND_OBJECT_IDX k_idx;
+       long value, total;
        object_kind     *k_ptr;
        alloc_entry     *table = alloc_kind_table;
 
        if (level > MAX_DEPTH - 1) level = MAX_DEPTH - 1;
 
        /* Boost level */
-       if ((level > 0) && !(d_info[dungeon_type].flags1 & DF1_BEGINNER))
+       if ((level > 0) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_BEGINNER))
        {
                /* Occasional "boost" */
                if (one_in_(GREAT_OBJ))
@@ -773,8 +733,6 @@ s16b get_obj_num(int level)
                if (table[i].level < table[j].level) i = j;
        }
 
-
-       /* Result */
        return (table[i].index);
 }
 
@@ -830,7 +788,7 @@ void object_aware(object_type *o_ptr)
        {
                object_type forge;
                object_type *q_ptr;
-               char o_name[MAX_NLEN];
+               GAME_TEXT o_name[MAX_NLEN];
 
                q_ptr = &forge;
                object_copy(q_ptr, o_ptr);
@@ -842,7 +800,6 @@ void object_aware(object_type *o_ptr)
        }
 }
 
-
 /*!
  * @brief オブジェクトを試行済にする /
  * Something has been "sampled"
@@ -855,6 +812,79 @@ void object_tried(object_type *o_ptr)
        k_info[o_ptr->k_idx].tried = TRUE;
 }
 
+/*!
+* @brief 重度擬似鑑定の判断処理 / Return a "feeling" (or NULL) about an item.  Method 1 (Heavy).
+* @param o_ptr 擬似鑑定を行うオブジェクトの参照ポインタ。
+* @return 擬似鑑定結果のIDを返す。
+*/
+byte value_check_aux1(object_type *o_ptr)
+{
+       /* Artifacts */
+       if (object_is_artifact(o_ptr))
+       {
+               /* Cursed/Broken */
+               if (object_is_cursed(o_ptr) || object_is_broken(o_ptr)) return FEEL_TERRIBLE;
+
+               /* Normal */
+               return FEEL_SPECIAL;
+       }
+
+       /* Ego-Items */
+       if (object_is_ego(o_ptr))
+       {
+               /* Cursed/Broken */
+               if (object_is_cursed(o_ptr) || object_is_broken(o_ptr)) return FEEL_WORTHLESS;
+
+               /* Normal */
+               return FEEL_EXCELLENT;
+       }
+
+       /* Cursed items */
+       if (object_is_cursed(o_ptr)) return FEEL_CURSED;
+
+       /* Broken items */
+       if (object_is_broken(o_ptr)) return FEEL_BROKEN;
+
+       if ((o_ptr->tval == TV_RING) || (o_ptr->tval == TV_AMULET)) return FEEL_AVERAGE;
+
+       /* Good "armor" bonus */
+       if (o_ptr->to_a > 0) return FEEL_GOOD;
+
+       /* Good "weapon" bonus */
+       if (o_ptr->to_h + o_ptr->to_d > 0) return FEEL_GOOD;
+
+       /* Default to "average" */
+       return FEEL_AVERAGE;
+}
+
+/*!
+* @brief 軽度擬似鑑定の判断処理 / Return a "feeling" (or NULL) about an item.  Method 2 (Light).
+* @param o_ptr 擬似鑑定を行うオブジェクトの参照ポインタ。
+* @return 擬似鑑定結果のIDを返す。
+*/
+byte value_check_aux2(object_type *o_ptr)
+{
+       /* Cursed items (all of them) */
+       if (object_is_cursed(o_ptr)) return FEEL_CURSED;
+
+       /* Broken items (all of them) */
+       if (object_is_broken(o_ptr)) return FEEL_BROKEN;
+
+       /* Artifacts -- except cursed/broken ones */
+       if (object_is_artifact(o_ptr)) return FEEL_UNCURSED;
+
+       /* Ego-Items -- except cursed/broken ones */
+       if (object_is_ego(o_ptr)) return FEEL_UNCURSED;
+
+       /* Good armor bonus */
+       if (o_ptr->to_a > 0) return FEEL_UNCURSED;
+
+       /* Good weapon bonuses */
+       if (o_ptr->to_h + o_ptr->to_d > 0) return FEEL_UNCURSED;
+
+       /* No feeling */
+       return FEEL_NONE;
+}
 
 /*!
  * @brief 未鑑定なベースアイテムの基本価格を返す /
@@ -862,7 +892,7 @@ void object_tried(object_type *o_ptr)
  * @param o_ptr 未鑑定価格を確認したいオブジェクトの構造体参照ポインタ
  * @return オブジェクトの未鑑定価格
  */
-static s32b object_value_base(object_type *o_ptr)
+static PRICE object_value_base(object_type *o_ptr)
 {
        /* Aware item -- use template cost */
        if (object_is_aware(o_ptr)) return (k_info[o_ptr->k_idx].cost);
@@ -898,7 +928,7 @@ static s32b object_value_base(object_type *o_ptr)
                /* Figurines, relative to monster level */
                case TV_FIGURINE:
                {
-                       int level = r_info[o_ptr->pval].level;
+                       DEPTH level = r_info[o_ptr->pval].level;
                        if (level < 20) return level*50L;
                        else if (level < 30) return 1000+(level-20)*150L;
                        else if (level < 40) return 2500+(level-30)*350L;
@@ -923,11 +953,11 @@ static s32b object_value_base(object_type *o_ptr)
  * @param plusses フラグに与える価格の基本重み
  * @return オブジェクトのフラグ価格
  */
-s32b flag_cost(object_type *o_ptr, int plusses)
+PRICE flag_cost(object_type *o_ptr, int plusses)
 {
-       s32b total = 0;
-       u32b flgs[TR_FLAG_SIZE];
-       s32b tmp_cost;
+       PRICE total = 0;
+       BIT_FLAGS flgs[TR_FLAG_SIZE];
+       PRICE tmp_cost;
        int count;
        int i;
        object_kind *k_ptr = &k_info[o_ptr->k_idx];
@@ -1156,12 +1186,10 @@ s32b flag_cost(object_type *o_ptr, int plusses)
  *\n
  * Every wearable item with a "pval" bonus is worth extra (see below).\n
  */
-s32b object_value_real(object_type *o_ptr)
+PRICE object_value_real(object_type *o_ptr)
 {
-       s32b value;
-
-       u32b flgs[TR_FLAG_SIZE];
-
+       PRICE value;
+       BIT_FLAGS flgs[TR_FLAG_SIZE];
        object_kind *k_ptr = &k_info[o_ptr->k_idx];
 
 
@@ -1281,7 +1309,6 @@ s32b object_value_real(object_type *o_ptr)
                         */
                        value += (value * o_ptr->pval / o_ptr->number / (k_ptr->pval * 2));
 
-                       /* Done */
                        break;
                }
                case TV_STAFF:
@@ -1291,7 +1318,6 @@ s32b object_value_real(object_type *o_ptr)
                         */
                        value += (value * o_ptr->pval / (k_ptr->pval * 2));
 
-                       /* Done */
                        break;
                }
 
@@ -1305,7 +1331,6 @@ s32b object_value_real(object_type *o_ptr)
                        /* Give credit for bonuses */
                        value += ((o_ptr->to_h + o_ptr->to_d + o_ptr->to_a) * 200L);
 
-                       /* Done */
                        break;
                }
 
@@ -1326,7 +1351,6 @@ s32b object_value_real(object_type *o_ptr)
                        /* Give credit for bonuses */
                        value += (((o_ptr->to_h - k_ptr->to_h) + (o_ptr->to_d - k_ptr->to_d)) * 200L + (o_ptr->to_a) * 100L);
 
-                       /* Done */
                        break;
                }
 
@@ -1347,7 +1371,6 @@ s32b object_value_real(object_type *o_ptr)
                        value += (o_ptr->dd - k_ptr->dd) * o_ptr->ds * 250L;
                        value += (o_ptr->ds - k_ptr->ds) * o_ptr->dd * 250L;
 
-                       /* Done */
                        break;
                }
 
@@ -1366,14 +1389,13 @@ s32b object_value_real(object_type *o_ptr)
                        value += (o_ptr->dd - k_ptr->dd) * o_ptr->ds * 5L;
                        value += (o_ptr->ds - k_ptr->ds) * o_ptr->dd * 5L;
 
-                       /* Done */
                        break;
                }
 
                /* Figurines, relative to monster level */
                case TV_FIGURINE:
                {
-                       int level = r_info[o_ptr->pval].level;
+                       DEPTH level = r_info[o_ptr->pval].level;
                        if (level < 20) value = level*50L;
                        else if (level < 30) value = 1000+(level-20)*150L;
                        else if (level < 40) value = 2500+(level-30)*350L;
@@ -1418,10 +1440,9 @@ s32b object_value_real(object_type *o_ptr)
  * Note that discounted items stay discounted forever, even if\n
  * the discount is "forgotten" by the player via memory loss.\n
  */
-s32b object_value(object_type *o_ptr)
+PRICE object_value(object_type *o_ptr)
 {
-       s32b value;
-
+       PRICE value;
 
        /* Unknown items -- acquire a base value */
        if (object_is_known(o_ptr))
@@ -1449,11 +1470,9 @@ s32b object_value(object_type *o_ptr)
                value = object_value_base(o_ptr);
        }
 
-
        /* Apply discount (if any) */
        if (o_ptr->discount) value -= (value * o_ptr->discount / 100L);
 
-
        /* Return the final value */
        return (value);
 }
@@ -1484,14 +1503,9 @@ bool can_player_destroy_object(object_type *o_ptr)
 
                /* We have "felt" it (again) */
                o_ptr->ident |= (IDENT_SENSE);
-
-               /* Combine the pack */
-               p_ptr->notice |= (PN_COMBINE);
-
-               /* Window stuff */
+               p_ptr->update |= (PU_COMBINE);
                p_ptr->window |= (PW_INVEN | PW_EQUIP);
 
-               /* Done */
                return FALSE;
        }
 
@@ -1852,8 +1866,8 @@ void object_absorb(object_type *o_ptr, object_type *j_ptr)
        /* Hack -- blend "feelings" */
        if (j_ptr->feeling) o_ptr->feeling = j_ptr->feeling;
 
-       /* Hack -- could average discounts XXX XXX XXX */
-       /* Hack -- save largest discount XXX XXX XXX */
+       /* Hack -- could average discounts */
+       /* Hack -- save largest discount */
        if (o_ptr->discount < j_ptr->discount) o_ptr->discount = j_ptr->discount;
 
        /* Hack -- if rods are stacking, add the pvals (maximum timeouts) and current timeouts together. -LM- */
@@ -1878,11 +1892,11 @@ void object_absorb(object_type *o_ptr, object_type *j_ptr)
  * @param sval 検索したいベースアイテムのsval
  * @return なし
  */
-IDX lookup_kind(OBJECT_TYPE_VALUE tval, OBJECT_SUBTYPE_VALUE sval)
+KIND_OBJECT_IDX lookup_kind(OBJECT_TYPE_VALUE tval, OBJECT_SUBTYPE_VALUE sval)
 {
-       IDX k;
+       KIND_OBJECT_IDX k;
        int num = 0;
-       IDX bk = 0;
+       KIND_OBJECT_IDX bk = 0;
 
        /* Look for it */
        for (k = 1; k < max_k_idx; k++)
@@ -1912,12 +1926,10 @@ IDX lookup_kind(OBJECT_TYPE_VALUE tval, OBJECT_SUBTYPE_VALUE sval)
        }
 
 #if 0
-       /* Oops */
        msg_format(_("アイテムがない (%d,%d)", "No object (%d,%d)"), tval, sval);
 #endif
 
 
-       /* Oops */
        return (0);
 }
 
@@ -2085,8 +2097,6 @@ int m_bonus(int max, DEPTH level)
 
        /* Enforce the maximum value */
        if (value > max) return (max);
-
-       /* Result */
        return (value);
 }
 
@@ -2098,156 +2108,17 @@ int m_bonus(int max, DEPTH level)
  */
 static void object_mention(object_type *o_ptr)
 {
-       char o_name[MAX_NLEN];
+       GAME_TEXT o_name[MAX_NLEN];
 
        object_aware(o_ptr);
        object_known(o_ptr);
 
        /* Mark the item as fully known */
        o_ptr->ident |= (IDENT_MENTAL);
-
-       /* Description */
        object_desc(o_name, o_ptr, 0);
        msg_format_wizard(CHEAT_OBJECT, _("%sを生成しました。", "%s was generated."), o_name);
 }
 
-/*!
- * @brief INSTA_ART型の固定アーティファクトの生成を確率に応じて試行する。
- * Mega-Hack -- Attempt to create one of the "Special Objects"
- * @param o_ptr 生成に割り当てたいオブジェクトの構造体参照ポインタ
- * @return 生成に成功したらTRUEを返す。
- * @details
- * We are only called from "make_object()", and we assume that\n
- * "apply_magic()" is called immediately after we return.\n
- *\n
- * Note -- see "make_artifact()" and "apply_magic()"\n
- */
-static bool make_artifact_special(object_type *o_ptr)
-{
-       IDX i;
-       IDX k_idx = 0;
-
-       /*! @note 地上ではキャンセルする / No artifacts in the town */
-       if (!dun_level) return (FALSE);
-
-       /*! @note get_obj_num_hookによる指定がある場合は生成をキャンセルする / Themed object */
-       if (get_obj_num_hook) return (FALSE);
-
-       /*! @note 全固定アーティファクト中からIDの若い順に生成対象とその確率を走査する / Check the artifact list (just the "specials") */
-       for (i = 0; i < max_a_idx; i++)
-       {
-               artifact_type *a_ptr = &a_info[i];
-
-               /*! @note アーティファクト名が空の不正なデータは除外する / Skip "empty" artifacts */
-               if (!a_ptr->name) continue;
-
-               /*! @note 既に生成回数がカウントされたアーティファクト、QUESTITEMと非INSTA_ARTは除外 / Cannot make an artifact twice */
-               if (a_ptr->cur_num) continue;
-               if (a_ptr->gen_flags & TRG_QUESTITEM) continue;
-               if (!(a_ptr->gen_flags & TRG_INSTA_ART)) continue;
-
-               /*! @note アーティファクト生成階が現在に対して足りない場合は高確率で1/(不足階層*2)を満たさないと生成リストに加えられない /
-                *  XXX XXX Enforce minimum "depth" (loosely) */
-               if (a_ptr->level > object_level)
-               {
-                       /* @note  / Acquire the "out-of-depth factor". Roll for out-of-depth creation. */
-                       int d = (a_ptr->level - object_level) * 2;
-                       if (!one_in_(d)) continue;
-               }
-
-               /*! @note 1/(レア度)の確率を満たさないと除外される / Artifact "rarity roll" */
-               if (!one_in_(a_ptr->rarity)) continue;
-
-               /*! @note INSTA_ART型固定アーティファクトのベースアイテムもチェック対象とする。ベースアイテムの生成階層が足りない場合1/(不足階層*5) を満たさないと除外される。 /
-                *  Find the base object. XXX XXX Enforce minimum "object" level (loosely). Acquire the "out-of-depth factor". Roll for out-of-depth creation. */
-               k_idx = lookup_kind(a_ptr->tval, a_ptr->sval);
-               if (k_info[k_idx].level > object_level)
-               {
-                       int d = (k_info[k_idx].level - object_level) * 5;
-                       if (!one_in_(d)) continue;
-               }
-
-               /*! @note 前述の条件を満たしたら、後のIDのアーティファクトはチェックせずすぐ確定し生成処理に移す /
-                * Assign the template. Mega-Hack -- mark the item as an artifact. Hack: Some artifacts get random extra powers. Success. */
-               object_prep(o_ptr, k_idx);
-
-               o_ptr->name1 = i;
-               random_artifact_resistance(o_ptr, a_ptr);
-               return (TRUE);
-       }
-
-       /*! @note 全INSTA_ART固定アーティファクトを試行しても決まらなかった場合 FALSEを返す / Failure */
-       return (FALSE);
-}
-
-
-/*!
- * @brief 非INSTA_ART型の固定アーティファクトの生成を確率に応じて試行する。
- * Mega-Hack -- Attempt to create one of the "Special Objects"
- * @param o_ptr 生成に割り当てたいオブジェクトの構造体参照ポインタ
- * @return 生成に成功したらTRUEを返す。
- * @details
- * Attempt to change an object into an artifact\n
- * This routine should only be called by "apply_magic()"\n
- * Note -- see "make_artifact_special()" and "apply_magic()"\n
- */
-static bool make_artifact(object_type *o_ptr)
-{
-       IDX i;
-
-
-       /* No artifacts in the town */
-       if (!dun_level) return (FALSE);
-
-       /* Paranoia -- no "plural" artifacts */
-       if (o_ptr->number != 1) return (FALSE);
-
-       /* Check the artifact list (skip the "specials") */
-       for (i = 0; i < max_a_idx; i++)
-       {
-               artifact_type *a_ptr = &a_info[i];
-
-               /* Skip "empty" items */
-               if (!a_ptr->name) continue;
-
-               /* Cannot make an artifact twice */
-               if (a_ptr->cur_num) continue;
-
-               if (a_ptr->gen_flags & TRG_QUESTITEM) continue;
-
-               if (a_ptr->gen_flags & TRG_INSTA_ART) continue;
-
-               /* Must have the correct fields */
-               if (a_ptr->tval != o_ptr->tval) continue;
-               if (a_ptr->sval != o_ptr->sval) continue;
-
-               /* XXX XXX Enforce minimum "depth" (loosely) */
-               if (a_ptr->level > dun_level)
-               {
-                       /* Acquire the "out-of-depth factor" */
-                       int d = (a_ptr->level - dun_level) * 2;
-
-                       /* Roll for out-of-depth creation */
-                       if (!one_in_(d)) continue;
-               }
-
-               /* We must make the "rarity roll" */
-               if (!one_in_(a_ptr->rarity)) continue;
-
-               /* Hack -- mark the item as an artifact */
-               o_ptr->name1 = i;
-
-               /* Hack: Some artifacts get random extra powers */
-               random_artifact_resistance(o_ptr, a_ptr);
-
-               /* Success */
-               return (TRUE);
-       }
-
-       /* Failure */
-       return (FALSE);
-}
-
 
 /*!
  * @brief アイテムのエゴをレア度の重みに合わせてランダムに選択する
@@ -2692,7 +2563,7 @@ static void add_esp_weak(object_type *o_ptr, bool extra)
  * Hack -- note special processing for crown/helm\n
  * Hack -- note special processing for robe of permanence\n
  */
-static void a_m_aux_2(object_type *o_ptr, int level, int power)
+static void a_m_aux_2(object_type *o_ptr, DEPTH level, int power)
 {
        ARMOUR_CLASS toac1 = (ARMOUR_CLASS)randint1(5) + m_bonus(5, level);
        ARMOUR_CLASS toac2 = (ARMOUR_CLASS)m_bonus(10, level);
@@ -3160,7 +3031,7 @@ static void a_m_aux_2(object_type *o_ptr, int level, int power)
  * Hack -- note special "pval boost" code for ring of speed\n
  * Hack -- note that some items must be cursed (or blessed)\n
  */
-static void a_m_aux_3(object_type *o_ptr, int level, int power)
+static void a_m_aux_3(object_type *o_ptr, DEPTH level, int power)
 {
        /* Apply magic (good or bad) according to type */
        switch (o_ptr->tval)
@@ -3609,7 +3480,6 @@ static void a_m_aux_3(object_type *o_ptr, int level, int power)
                                                break;
                                        }
                                }
-                               /* Uncurse it */
                                o_ptr->curse_flags = 0L;
                        }
                        else if ((power == -2) && one_in_(2))
@@ -3892,7 +3762,6 @@ static void a_m_aux_3(object_type *o_ptr, int level, int power)
                                                }
                                        }
                                }
-                               /* Uncurse it */
                                o_ptr->curse_flags = 0L;
                        }
                        else if ((power == -2) && one_in_(2))
@@ -3956,7 +3825,6 @@ static bool item_monster_okay(MONRACE_IDX r_idx)
        if (r_ptr->flags1 & RF1_FORCE_DEPTH) return (FALSE);
        if (r_ptr->flags7 & RF7_UNIQUE2) return (FALSE);
 
-       /* Okay */
        return (TRUE);
 }
 
@@ -3971,7 +3839,7 @@ static bool item_monster_okay(MONRACE_IDX r_idx)
  * @details
  * Hack -- note the special code for various items
  */
-static void a_m_aux_4(object_type *o_ptr, int level, int power)
+static void a_m_aux_4(object_type *o_ptr, DEPTH level, int power)
 {
        object_kind *k_ptr = &k_info[o_ptr->k_idx];
 
@@ -4286,14 +4154,14 @@ void apply_magic(object_type *o_ptr, DEPTH lev, BIT_FLAGS mode)
        f1 = lev + 10;
 
        /* Maximal chance of being "good" */
-       if (f1 > d_info[dungeon_type].obj_good) f1 = d_info[dungeon_type].obj_good;
+       if (f1 > d_info[p_ptr->dungeon_idx].obj_good) f1 = d_info[p_ptr->dungeon_idx].obj_good;
 
        /* Base chance of being "great" */
        f2 = f1 * 2 / 3;
 
        /* Maximal chance of being "great" */
-       if ((p_ptr->pseikaku != SEIKAKU_MUNCHKIN) && (f2 > d_info[dungeon_type].obj_great))
-               f2 = d_info[dungeon_type].obj_great;
+       if ((p_ptr->pseikaku != SEIKAKU_MUNCHKIN) && (f2 > d_info[p_ptr->dungeon_idx].obj_great))
+               f2 = d_info[p_ptr->dungeon_idx].obj_great;
 
        if (p_ptr->muta3 & MUT3_GOOD_LUCK)
        {
@@ -4416,12 +4284,9 @@ void apply_magic(object_type *o_ptr, DEPTH lev, BIT_FLAGS mode)
                if (a_ptr->gen_flags & (TRG_RANDOM_CURSE1)) o_ptr->curse_flags |= get_curse(1, o_ptr);
                if (a_ptr->gen_flags & (TRG_RANDOM_CURSE2)) o_ptr->curse_flags |= get_curse(2, o_ptr);
 
-               /* Done */
                return;
        }
 
-
-       /* Apply magic */
        switch (o_ptr->tval)
        {
                case TV_DIGGING:
@@ -4653,7 +4518,6 @@ void apply_magic(object_type *o_ptr, DEPTH lev, BIT_FLAGS mode)
                                o_ptr->pval = 2;
                }
                
-               /* Done */
                return;
        }
 
@@ -4777,7 +4641,8 @@ static bool kind_is_good(KIND_OBJECT_IDX k_idx)
  */
 bool make_object(object_type *j_ptr, BIT_FLAGS mode)
 {
-       int prob, base;
+       PERCENTAGE prob;
+       DEPTH base;
 
 
        /* Chance of "special object" */
@@ -4790,7 +4655,7 @@ bool make_object(object_type *j_ptr, BIT_FLAGS mode)
        /* Generate a special object, or a normal object */
        if (!one_in_(prob) || !make_artifact_special(j_ptr))
        {
-               IDX k_idx;
+               KIND_OBJECT_IDX k_idx;
 
                /* Good objects */
                if ((mode & AM_GOOD) && !get_obj_num_hook)
@@ -4859,10 +4724,10 @@ bool make_object(object_type *j_ptr, BIT_FLAGS mode)
  */
 void place_object(POSITION y, POSITION x, BIT_FLAGS mode)
 {
-       IDX o_idx;
+       OBJECT_IDX o_idx;
 
        /* Acquire grid */
-       cave_type *c_ptr = &cave[y][x];
+       grid_type *g_ptr = &grid_array[y][x];
 
        object_type forge;
        object_type *q_ptr;
@@ -4875,13 +4740,9 @@ void place_object(POSITION y, POSITION x, BIT_FLAGS mode)
        if (!cave_drop_bold(y, x)) return;
 
        /* Avoid stacking on other objects */
-       if (c_ptr->o_idx) return;
+       if (g_ptr->o_idx) return;
 
-
-       /* Get local object */
        q_ptr = &forge;
-
-       /* Wipe the object */
        object_wipe(q_ptr);
 
        /* Make an object (if possible) */
@@ -4895,27 +4756,22 @@ void place_object(POSITION y, POSITION x, BIT_FLAGS mode)
        if (o_idx)
        {
                object_type *o_ptr;
-
-               /* Acquire object */
                o_ptr = &o_list[o_idx];
 
                /* Structure Copy */
                object_copy(o_ptr, q_ptr);
 
-               /* Location */
                o_ptr->iy = y;
                o_ptr->ix = x;
 
                /* Build a stack */
-               o_ptr->next_o_idx = c_ptr->o_idx;
+               o_ptr->next_o_idx = g_ptr->o_idx;
 
                /* Place the object */
-               c_ptr->o_idx = o_idx;
+               g_ptr->o_idx = o_idx;
 
-               /* Notice */
                note_spot(y, x);
 
-               /* Redraw */
                lite_spot(y, x);
        }
        else
@@ -4940,10 +4796,8 @@ void place_object(POSITION y, POSITION x, BIT_FLAGS mode)
 bool make_gold(object_type *j_ptr)
 {
        int i;
-
        s32b base;
 
-
        /* Hack -- Pick a Treasure variety */
        i = ((randint1(object_level + 2) + 2) / 2) - 1;
 
@@ -4963,7 +4817,7 @@ bool make_gold(object_type *j_ptr)
        object_prep(j_ptr, OBJ_GOLD_LIST + i);
 
        /* Hack -- Base coin cost */
-       base = k_info[OBJ_GOLD_LIST+i].cost;
+       base = k_info[OBJ_GOLD_LIST + i].cost;
 
        /* Determine how much the treasure is "worth" */
        j_ptr->pval = (base + (8L * randint1(base)) + randint1(8));
@@ -4984,11 +4838,10 @@ bool make_gold(object_type *j_ptr)
  */
 void place_gold(POSITION y, POSITION x)
 {
-       s16b o_idx;
+       OBJECT_IDX o_idx;
 
        /* Acquire grid */
-       cave_type *c_ptr = &cave[y][x];
-
+       grid_type *g_ptr = &grid_array[y][x];
 
        object_type forge;
        object_type *q_ptr;
@@ -5001,19 +4854,14 @@ void place_gold(POSITION y, POSITION x)
        if (!cave_drop_bold(y, x)) return;
 
        /* Avoid stacking on other objects */
-       if (c_ptr->o_idx) return;
+       if (g_ptr->o_idx) return;
 
-
-       /* Get local object */
        q_ptr = &forge;
-
-       /* Wipe the object */
        object_wipe(q_ptr);
 
        /* Make some gold */
        if (!make_gold(q_ptr)) return;
 
-
        /* Make an object */
        o_idx = o_pop();
 
@@ -5021,8 +4869,6 @@ void place_gold(POSITION y, POSITION x)
        if (o_idx)
        {
                object_type *o_ptr;
-
-               /* Acquire object */
                o_ptr = &o_list[o_idx];
 
                /* Copy the object */
@@ -5033,15 +4879,13 @@ void place_gold(POSITION y, POSITION x)
                o_ptr->ix = x;
 
                /* Build a stack */
-               o_ptr->next_o_idx = c_ptr->o_idx;
+               o_ptr->next_o_idx = g_ptr->o_idx;
 
                /* Place the object */
-               c_ptr->o_idx = o_idx;
+               g_ptr->o_idx = o_idx;
 
-               /* Notice */
                note_spot(y, x);
 
-               /* Redraw */
                lite_spot(y, x);
        }
 }
@@ -5054,7 +4898,7 @@ void place_gold(POSITION y, POSITION x)
  * @param chance ドロップの成功率(%)
  * @param y 配置したいフロアのY座標
  * @param x 配置したいフロアのX座標
- * @return 生成に成功したらTRUEを返す。
+ * @return 生成に成功したらオブジェクトのIDを返す。
  * @details
  * The initial location is assumed to be "in_bounds()".\n
  *\n
@@ -5069,22 +4913,21 @@ void place_gold(POSITION y, POSITION x)
  * the object can combine, stack, or be placed.  Artifacts will try very\n
  * hard to be placed, including "teleporting" to a useful grid if needed.\n
  */
-s16b drop_near(object_type *j_ptr, int chance, int y, int x)
+OBJECT_IDX drop_near(object_type *j_ptr, PERCENTAGE chance, POSITION y, POSITION x)
 {
        int i, k, d, s;
 
        int bs, bn;
-       int by, bx;
-       int dy, dx;
-       int ty, tx = 0;
-
-       s16b o_idx = 0;
+       POSITION by, bx;
+       POSITION dy, dx;
+       POSITION ty, tx = 0;
 
-       s16b this_o_idx, next_o_idx = 0;
+       OBJECT_IDX o_idx = 0;
+       OBJECT_IDX this_o_idx, next_o_idx = 0;
 
-       cave_type *c_ptr;
+       grid_type *g_ptr;
 
-       char o_name[MAX_NLEN];
+       GAME_TEXT o_name[MAX_NLEN];
 
        bool flag = FALSE;
        bool done = FALSE;
@@ -5101,15 +4944,11 @@ s16b drop_near(object_type *j_ptr, int chance, int y, int x)
        /* Handle normal "breakage" */
        if (!object_is_artifact(j_ptr) && (randint0(100) < chance))
        {
-               /* Message */
 #ifdef JP
                msg_format("%sは消えた。", o_name);
 #else
-               msg_format("The %s disappear%s.",
-                          o_name, (plural ? "" : "s"));
+               msg_format("The %s disappear%s.", o_name, (plural ? "" : "s"));
 #endif
-
-
                /* Debug */
                if (p_ptr->wizard) msg_print(_("(破損)", "(breakage)"));
 
@@ -5142,7 +4981,6 @@ s16b drop_near(object_type *j_ptr, int chance, int y, int x)
                        /* Ignore distant grids */
                        if (d > 10) continue;
 
-                       /* Location */
                        ty = y + dy;
                        tx = x + dx;
 
@@ -5153,7 +4991,7 @@ s16b drop_near(object_type *j_ptr, int chance, int y, int x)
                        if (!projectable(y, x, ty, tx)) continue;
 
                        /* Obtain grid */
-                       c_ptr = &cave[ty][tx];
+                       g_ptr = &grid_array[ty][tx];
 
                        /* Require floor space */
                        if (!cave_drop_bold(ty, tx)) continue;
@@ -5162,11 +5000,9 @@ s16b drop_near(object_type *j_ptr, int chance, int y, int x)
                        k = 0;
 
                        /* Scan objects in that grid */
-                       for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
+                       for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
                        {
                                object_type *o_ptr;
-
-                               /* Acquire object */
                                o_ptr = &o_list[this_o_idx];
 
                                /* Acquire next object */
@@ -5204,7 +5040,6 @@ s16b drop_near(object_type *j_ptr, int chance, int y, int x)
                        by = ty;
                        bx = tx;
 
-                       /* Okay */
                        flag = TRUE;
                }
        }
@@ -5213,12 +5048,10 @@ s16b drop_near(object_type *j_ptr, int chance, int y, int x)
        /* Handle lack of space */
        if (!flag && !object_is_artifact(j_ptr))
        {
-               /* Message */
 #ifdef JP
                msg_format("%sは消えた。", o_name);
 #else
-               msg_format("The %s disappear%s.",
-                          o_name, (plural ? "" : "s"));
+               msg_format("The %s disappear%s.", o_name, (plural ? "" : "s"));
 #endif
 
 
@@ -5247,7 +5080,6 @@ s16b drop_near(object_type *j_ptr, int chance, int y, int x)
                /* Require floor space */
                if (!cave_drop_bold(by, bx)) continue;
 
-               /* Okay */
                flag = TRUE;
        }
 
@@ -5268,7 +5100,6 @@ s16b drop_near(object_type *j_ptr, int chance, int y, int x)
                /* No valid place! */
                if (!candidates)
                {
-                       /* Message */
 #ifdef JP
                        msg_format("%sは消えた。", o_name);
 #else
@@ -5317,15 +5148,12 @@ s16b drop_near(object_type *j_ptr, int chance, int y, int x)
        }
 
 
-       /* Grid */
-       c_ptr = &cave[by][bx];
+       g_ptr = &grid_array[by][bx];
 
        /* Scan objects in that grid for combination */
-       for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
+       for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
        {
                object_type *o_ptr;
-
-               /* Acquire object */
                o_ptr = &o_list[this_o_idx];
 
                /* Acquire next object */
@@ -5334,32 +5162,26 @@ s16b drop_near(object_type *j_ptr, int chance, int y, int x)
                /* Check for combination */
                if (object_similar(o_ptr, j_ptr))
                {
-                       /* Combine the items */
                        object_absorb(o_ptr, j_ptr);
 
                        /* Success */
                        done = TRUE;
 
-                       /* Done */
                        break;
                }
        }
 
-       /* Get new object */
        if (!done) o_idx = o_pop();
 
        /* Failure */
        if (!done && !o_idx)
        {
-               /* Message */
 #ifdef JP
                msg_format("%sは消えた。", o_name);
 #else
-               msg_format("The %s disappear%s.",
-                          o_name, (plural ? "" : "s"));
+               msg_format("The %s disappear%s.", o_name, (plural ? "" : "s"));
 #endif
 
-
                /* Debug */
                if (p_ptr->wizard) msg_print(_("(アイテムが多過ぎる)", "(too many objects)"));
 
@@ -5390,22 +5212,17 @@ s16b drop_near(object_type *j_ptr, int chance, int y, int x)
                j_ptr->held_m_idx = 0;
 
                /* Build a stack */
-               j_ptr->next_o_idx = c_ptr->o_idx;
+               j_ptr->next_o_idx = g_ptr->o_idx;
 
                /* Place the object */
-               c_ptr->o_idx = o_idx;
+               g_ptr->o_idx = o_idx;
 
                /* Success */
                done = TRUE;
        }
 
-       /* Note the spot */
        note_spot(by, bx);
-
-       /* Draw the spot */
        lite_spot(by, bx);
-
-       /* Sound */
        sound(SOUND_DROP);
 
        /* Mega-Hack -- no message if "dropped" by player */
@@ -5415,190 +5232,16 @@ s16b drop_near(object_type *j_ptr, int chance, int y, int x)
                msg_print(_("何かが足下に転がってきた。", "You feel something roll beneath your feet."));
        }
 
-       /* XXX XXX XXX */
-
-       /* Result */
        return (o_idx);
 }
 
-
-/*!
- * @brief 獲得ドロップを行う。
- * Scatter some "great" objects near the player
- * @param y1 配置したいフロアのY座標
- * @param x1 配置したいフロアのX座標
- * @param num 獲得の処理回数
- * @param great TRUEならば必ず高級品以上を落とす
- * @param special TRUEならば必ず特別品を落とす
- * @param known TRUEならばオブジェクトが必ず*鑑定*済になる
- * @return なし
- */
-void acquirement(POSITION y1, POSITION x1, int num, bool great, bool special, bool known)
-{
-       object_type *i_ptr;
-       object_type object_type_body;
-       BIT_FLAGS mode = AM_GOOD | (great || special ? AM_GREAT : 0L) | (special ? AM_SPECIAL : 0L) ;
-
-       /* Acquirement */
-       while (num--)
-       {
-               /* Get local object */
-               i_ptr = &object_type_body;
-
-               /* Wipe the object */
-               object_wipe(i_ptr);
-
-               /* Make a good (or great) object (if possible) */
-               if (!make_object(i_ptr, mode)) continue;
-
-               if (known)
-               {
-                       object_aware(i_ptr);
-                       object_known(i_ptr);
-               }
-
-               /* Drop the object */
-               (void)drop_near(i_ptr, -1, y1, x1);
-       }
-}
-
-/*
- * Scatter some "amusing" objects near the player
- */
-
-#define AMS_NOTHING   0x00 /* No restriction */
-#define AMS_NO_UNIQUE 0x01 /* Don't make the amusing object of uniques */
-#define AMS_FIXED_ART 0x02 /* Make a fixed artifact based on the amusing object */
-#define AMS_MULTIPLE  0x04 /* Drop 1-3 objects for one type */
-#define AMS_PILE      0x08 /* Drop 1-99 pile objects for one type */
-
-typedef struct
-{
-       OBJECT_TYPE_VALUE tval;
-       OBJECT_SUBTYPE_VALUE sval;
-       int prob;
-       byte flag;
-} amuse_type;
-
-amuse_type amuse_info[] =
-{
-       { TV_BOTTLE, SV_ANY, 5, AMS_NOTHING },
-       { TV_JUNK, SV_ANY, 3, AMS_MULTIPLE },
-       { TV_SPIKE, SV_ANY, 10, AMS_PILE },
-       { TV_STATUE, SV_ANY, 15, AMS_NOTHING },
-       { TV_CORPSE, SV_ANY, 15, AMS_NO_UNIQUE },
-       { TV_SKELETON, SV_ANY, 10, AMS_NO_UNIQUE },
-       { TV_FIGURINE, SV_ANY, 10, AMS_NO_UNIQUE },
-       { TV_PARCHMENT, SV_ANY, 1, AMS_NOTHING },
-       { TV_POLEARM, SV_TSURIZAO, 3, AMS_NOTHING }, //Fishing Pole of Taikobo
-       { TV_SWORD, SV_BROKEN_DAGGER, 3, AMS_FIXED_ART }, //Broken Dagger of Magician
-       { TV_SWORD, SV_BROKEN_DAGGER, 10, AMS_NOTHING },
-       { TV_SWORD, SV_BROKEN_SWORD, 5, AMS_NOTHING },
-       { TV_SCROLL, SV_SCROLL_AMUSEMENT, 10, AMS_NOTHING },
-
-       { 0, 0, 0 }
-};
-
-/*!
- * @brief 誰得ドロップを行う。
- * @param y1 配置したいフロアのY座標
- * @param x1 配置したいフロアのX座標
- * @param num 誰得の処理回数
- * @param known TRUEならばオブジェクトが必ず*鑑定*済になる
- * @return なし
- */
-void amusement(POSITION y1, POSITION x1, int num, bool known)
-{
-       object_type *i_ptr;
-       object_type object_type_body;
-       int n, t = 0;
-
-       for (n = 0; amuse_info[n].tval != 0; n++)
-       {
-               t += amuse_info[n].prob;
-       }
-
-       /* Acquirement */
-       while (num)
-       {
-               int i;
-               IDX k_idx, a_idx = 0;
-               int r = randint0(t);
-               bool insta_art, fixed_art;
-
-               for (i = 0; ; i++)
-               {
-                       r -= amuse_info[i].prob;
-                       if (r <= 0) break;
-               }
-
-               /* Get local object */
-               i_ptr = &object_type_body;
-
-               /* Wipe the object */
-               object_wipe(i_ptr);
-
-               /* Wipe the object */
-               k_idx = lookup_kind(amuse_info[i].tval, amuse_info[i].sval);
-
-               /* Paranoia - reroll if nothing */
-               if (!k_idx) continue;
-
-               /* Search an artifact index if need */
-               insta_art = (k_info[k_idx].gen_flags & TRG_INSTA_ART);
-               fixed_art = (amuse_info[i].flag & AMS_FIXED_ART);
-
-               if (insta_art || fixed_art)
-               {
-                       for (a_idx = 1; a_idx < max_a_idx; a_idx++)
-                       {
-                               if (insta_art && !(a_info[a_idx].gen_flags & TRG_INSTA_ART)) continue;
-                               if (a_info[a_idx].tval != k_info[k_idx].tval) continue;
-                               if (a_info[a_idx].sval != k_info[k_idx].sval) continue;
-                               if (a_info[a_idx].cur_num > 0) continue;
-                               break;
-                       }
-
-                       if (a_idx >= max_a_idx) continue;
-               }
-
-               /* Make an object (if possible) */
-               object_prep(i_ptr, k_idx);
-               if (a_idx) i_ptr->name1 = a_idx;
-               apply_magic(i_ptr, 1, AM_NO_FIXED_ART);
-
-               if (amuse_info[i].flag & AMS_NO_UNIQUE)
-               {
-                       if (r_info[i_ptr->pval].flags1 & RF1_UNIQUE) continue;
-               }
-
-               if (amuse_info[i].flag & AMS_MULTIPLE) i_ptr->number = randint1(3);
-               if (amuse_info[i].flag & AMS_PILE) i_ptr->number = randint1(99);
-
-               if (known)
-               {
-                       object_aware(i_ptr);
-                       object_known(i_ptr);
-               }
-
-               /* Paranoia - reroll if nothing */
-               if (!(i_ptr->k_idx)) continue;
-
-               /* Drop the object */
-               (void)drop_near(i_ptr, -1, y1, x1);
-
-               num--;
-       }
-}
-
-
 /*!
  * @brief 魔道具の使用回数の残量を示すメッセージを表示する /
  * Describe the charges on an item in the inventory.
  * @param item 残量を表示したいプレイヤーのアイテム所持スロット
  * @return なし
  */
-void inven_item_charges(int item)
+void inven_item_charges(INVENTORY_IDX item)
 {
        object_type *o_ptr = &inventory[item];
 
@@ -5621,14 +5264,12 @@ void inven_item_charges(int item)
        /* Multiple charges */
        if (o_ptr->pval != 1)
        {
-               /* Print a message */
                msg_format("You have %d charges remaining.", o_ptr->pval);
        }
 
        /* Single charge */
        else
        {
-               /* Print a message */
                msg_format("You have %d charge remaining.", o_ptr->pval);
        }
 #endif
@@ -5641,15 +5282,13 @@ void inven_item_charges(int item)
  * @param item 残量を表示したいプレイヤーのアイテム所持スロット
  * @return なし
  */
-void inven_item_describe(int item)
+void inven_item_describe(INVENTORY_IDX item)
 {
        object_type *o_ptr = &inventory[item];
-       char        o_name[MAX_NLEN];
+       GAME_TEXT o_name[MAX_NLEN];
 
-       /* Get a description */
        object_desc(o_name, o_ptr, 0);
 
-       /* Print a message */
 #ifdef JP
        /* "no more" の場合はこちらで表示する */
        if (o_ptr->number <= 0)
@@ -5669,13 +5308,13 @@ void inven_item_describe(int item)
 }
 
 /*!
- * @brief ã\82¢ã\82¤ã\83\86ã\83 ã\81®残り所持数メッセージを表示する /
+ * @brief ã\82¢ã\82¤ã\83\86ã\83 ã\82\92å¢\97æ¸\9bã\81\95ã\81\9b残り所持数メッセージを表示する /
  * Increase the "number" of an item in the inventory
  * @param item 所持数を増やしたいプレイヤーのアイテム所持スロット
  * @param num 増やしたい量
  * @return なし
  */
-void inven_item_increase(int item, int num)
+void inven_item_increase(INVENTORY_IDX item, ITEM_NUMBER num)
 {
        object_type *o_ptr = &inventory[item];
 
@@ -5687,7 +5326,7 @@ void inven_item_increase(int item, int num)
        else if (num < 0) num = 0;
 
        /* Un-apply */
-       num -= (ITEM_NUMBER)o_ptr->number;
+       num -= o_ptr->number;
 
        /* Change the number and weight */
        if (num)
@@ -5697,17 +5336,11 @@ void inven_item_increase(int item, int num)
 
                /* Add the weight */
                p_ptr->total_weight += (num * o_ptr->weight);
-
-               /* Recalculate bonuses */
                p_ptr->update |= (PU_BONUS);
 
                /* Recalculate mana XXX */
                p_ptr->update |= (PU_MANA);
-
-               /* Combine the pack */
-               p_ptr->notice |= (PN_COMBINE);
-
-               /* Window stuff */
+               p_ptr->update |= (PU_COMBINE);
                p_ptr->window |= (PW_INVEN | PW_EQUIP);
 
                /* Hack -- Clear temporary elemental brands if player takes off weapons */
@@ -5715,7 +5348,7 @@ void inven_item_increase(int item, int num)
                {
                        if ((item == INVEN_RARM) || (item == INVEN_LARM))
                        {
-                               if (!buki_motteruka(INVEN_RARM + INVEN_LARM - item))
+                               if (!has_melee_weapon(INVEN_RARM + INVEN_LARM - item))
                                {
                                        /* Clear all temporary elemental brands */
                                        set_ele_attack(0, 0);
@@ -5731,7 +5364,7 @@ void inven_item_increase(int item, int num)
  * @param item 消去したいプレイヤーのアイテム所持スロット
  * @return なし
  */
-void inven_item_optimize(int item)
+void inven_item_optimize(INVENTORY_IDX item)
 {
        object_type *o_ptr = &inventory[item];
 
@@ -5759,7 +5392,6 @@ void inven_item_optimize(int item)
                /* Erase the "final" slot */
                object_wipe(&inventory[i]);
 
-               /* Window stuff */
                p_ptr->window |= (PW_INVEN);
        }
 
@@ -5771,8 +5403,6 @@ void inven_item_optimize(int item)
 
                /* Erase the empty slot */
                object_wipe(&inventory[item]);
-
-               /* Recalculate bonuses */
                p_ptr->update |= (PU_BONUS);
 
                /* Recalculate torch */
@@ -5781,11 +5411,9 @@ void inven_item_optimize(int item)
                /* Recalculate mana XXX */
                p_ptr->update |= (PU_MANA);
 
-               /* Window stuff */
                p_ptr->window |= (PW_EQUIP);
        }
 
-       /* Window stuff */
        p_ptr->window |= (PW_SPELL);
 }
 
@@ -5795,7 +5423,7 @@ void inven_item_optimize(int item)
  * @param item メッセージの対象にしたいアイテム所持スロット
  * @return なし
  */
-void floor_item_charges(int item)
+void floor_item_charges(INVENTORY_IDX item)
 {
        object_type *o_ptr = &o_list[item];
 
@@ -5818,14 +5446,12 @@ void floor_item_charges(int item)
        /* Multiple charges */
        if (o_ptr->pval != 1)
        {
-               /* Print a message */
                msg_format("There are %d charges remaining.", o_ptr->pval);
        }
 
        /* Single charge */
        else
        {
-               /* Print a message */
                msg_format("There is %d charge remaining.", o_ptr->pval);
        }
 #endif
@@ -5838,15 +5464,13 @@ void floor_item_charges(int item)
  * @param item メッセージの対象にしたいアイテム所持スロット
  * @return なし
  */
-void floor_item_describe(int item)
+void floor_item_describe(INVENTORY_IDX item)
 {
        object_type *o_ptr = &o_list[item];
-       char        o_name[MAX_NLEN];
+       GAME_TEXT o_name[MAX_NLEN];
 
-       /* Get a description */
        object_desc(o_name, o_ptr, 0);
 
-       /* Print a message */
 #ifdef JP
        /* "no more" の場合はこちらで表示を分ける */
        if (o_ptr->number <= 0)
@@ -5871,7 +5495,7 @@ void floor_item_describe(int item)
  * @param num 増やしたいアイテムの数
  * @return なし
  */
-void floor_item_increase(int item, int num)
+void floor_item_increase(INVENTORY_IDX item, ITEM_NUMBER num)
 {
        object_type *o_ptr = &o_list[item];
 
@@ -5883,10 +5507,10 @@ void floor_item_increase(int item, int num)
        else if (num < 0) num = 0;
 
        /* Un-apply */
-       num -= (int)o_ptr->number;
+       num -=  o_ptr->number;
 
        /* Change the number */
-       o_ptr->number += (ITEM_NUMBER)num;
+       o_ptr->number += num;
 }
 
 
@@ -5896,7 +5520,7 @@ void floor_item_increase(int item, int num)
  * @param item 消去したいアイテムの所持スロット
  * @return なし
  */
-void floor_item_optimize(int item)
+void floor_item_optimize(INVENTORY_IDX item)
 {
        object_type *o_ptr = &o_list[item];
 
@@ -5906,7 +5530,6 @@ void floor_item_optimize(int item)
        /* Only optimize empty items */
        if (o_ptr->number) return;
 
-       /* Delete the object */
        delete_object_idx(item);
 }
 
@@ -5936,7 +5559,6 @@ bool inven_carry_okay(object_type *o_ptr)
                if (object_similar(j_ptr, o_ptr)) return (TRUE);
        }
 
-       /* Nope */
        return (FALSE);
 }
 
@@ -6071,16 +5693,10 @@ s16b inven_carry(object_type *o_ptr)
                /* Check if the two items can be combined */
                if (object_similar(j_ptr, o_ptr))
                {
-                       /* Combine the items */
                        object_absorb(j_ptr, o_ptr);
 
-                       /* Increase the weight */
                        p_ptr->total_weight += (o_ptr->number * o_ptr->weight);
-
-                       /* Recalculate bonuses */
                        p_ptr->update |= (PU_BONUS);
-
-                       /* Window stuff */
                        p_ptr->window |= (PW_INVEN);
 
                        /* Success */
@@ -6150,19 +5766,11 @@ s16b inven_carry(object_type *o_ptr)
        /* Player touches it, and no longer marked */
        j_ptr->marked = OM_TOUCHED;
 
-       /* Increase the weight */
        p_ptr->total_weight += (j_ptr->number * j_ptr->weight);
 
        /* Count the items */
        inven_cnt++;
-
-       /* Recalculate bonuses */
-       p_ptr->update |= (PU_BONUS);
-
-       /* Combine and Reorder pack */
-       p_ptr->notice |= (PN_COMBINE | PN_REORDER);
-
-       /* Window stuff */
+       p_ptr->update |= (PU_BONUS | PU_COMBINE | PU_REORDER);
        p_ptr->window |= (PW_INVEN);
 
        /* Return the slot */
@@ -6191,9 +5799,9 @@ INVENTORY_IDX inven_takeoff(INVENTORY_IDX item, ITEM_NUMBER amt)
 
        object_type *o_ptr;
 
-       cptr act;
+       concptr act;
 
-       char o_name[MAX_NLEN];
+       GAME_TEXT o_name[MAX_NLEN];
 
 
        /* Get the item to take off */
@@ -6204,8 +5812,6 @@ INVENTORY_IDX inven_takeoff(INVENTORY_IDX item, ITEM_NUMBER amt)
 
        /* Verify */
        if (amt > o_ptr->number) amt = o_ptr->number;
-
-       /* Get local object */
        q_ptr = &forge;
 
        /* Obtain a local object */
@@ -6214,7 +5820,6 @@ INVENTORY_IDX inven_takeoff(INVENTORY_IDX item, ITEM_NUMBER amt)
        /* Modify quantity */
        q_ptr->number = amt;
 
-       /* Describe the object */
        object_desc(o_name, q_ptr, 0);
 
        /* Took off weapon */
@@ -6249,7 +5854,6 @@ INVENTORY_IDX inven_takeoff(INVENTORY_IDX item, ITEM_NUMBER amt)
        /* Carry the object */
        slot = inven_carry(q_ptr);
 
-       /* Message */
 #ifdef JP
        msg_format("%s(%c)%s。", o_name, index_to_label(slot), act);
 #else
@@ -6277,8 +5881,7 @@ void inven_drop(INVENTORY_IDX item, ITEM_NUMBER amt)
        object_type *q_ptr;
        object_type *o_ptr;
 
-       char o_name[MAX_NLEN];
-
+       GAME_TEXT o_name[MAX_NLEN];
 
        /* Access original object */
        o_ptr = &inventory[item];
@@ -6289,7 +5892,6 @@ void inven_drop(INVENTORY_IDX item, ITEM_NUMBER amt)
        /* Not too many */
        if (amt > o_ptr->number) amt = o_ptr->number;
 
-
        /* Take off equipment */
        if (item >= INVEN_RARM)
        {
@@ -6300,8 +5902,6 @@ void inven_drop(INVENTORY_IDX item, ITEM_NUMBER amt)
                o_ptr = &inventory[item];
        }
 
-
-       /* Get local object */
        q_ptr = &forge;
 
        /* Obtain local object */
@@ -6316,7 +5916,6 @@ void inven_drop(INVENTORY_IDX item, ITEM_NUMBER amt)
        /* Describe local object */
        object_desc(o_name, q_ptr, 0);
 
-       /* Message */
        msg_format(_("%s(%c)を落とした。", "You drop %s (%c)."), o_name, index_to_label(item));
 
        /* Drop it near the player */
@@ -6339,7 +5938,7 @@ void inven_drop(INVENTORY_IDX item, ITEM_NUMBER amt)
 void combine_pack(void)
 {
        int             i, j, k;
-       object_type     *o_ptr;
+       object_type *o_ptr;
        object_type     *j_ptr;
        bool            flag = FALSE, combined;
 
@@ -6350,7 +5949,6 @@ void combine_pack(void)
                /* Combine the pack (backwards) */
                for (i = INVEN_PACK; i > 0; i--)
                {
-                       /* Get the item */
                        o_ptr = &inventory[i];
 
                        /* Skip empty items */
@@ -6361,7 +5959,6 @@ void combine_pack(void)
                        {
                                int max_num;
 
-                               /* Get the item */
                                j_ptr = &inventory[j];
 
                                /* Skip empty items */
@@ -6423,13 +6020,11 @@ void combine_pack(void)
                                                }
                                        }
 
-                                       /* Window stuff */
                                        p_ptr->window |= (PW_INVEN);
 
                                        /* Take note */
                                        combined = TRUE;
 
-                                       /* Done */
                                        break;
                                }
                        }
@@ -6437,7 +6032,6 @@ void combine_pack(void)
        }
        while (combined);
 
-       /* Message */
        if (flag) msg_print(_("ザックの中のアイテムをまとめ直した。", "You combine some items in your pack."));
 }
 
@@ -6454,7 +6048,7 @@ void reorder_pack(void)
        s32b            o_value;
        object_type     forge;
        object_type     *q_ptr;
-       object_type     *o_ptr;
+       object_type *o_ptr;
        bool            flag = FALSE;
 
 
@@ -6464,7 +6058,6 @@ void reorder_pack(void)
                /* Mega-Hack -- allow "proper" over-flow */
                if ((i == INVEN_PACK) && (inven_cnt == INVEN_PACK)) break;
 
-               /* Get the item */
                o_ptr = &inventory[i];
 
                /* Skip empty slots */
@@ -6484,8 +6077,6 @@ void reorder_pack(void)
 
                /* Take note */
                flag = TRUE;
-
-               /* Get local object */
                q_ptr = &forge;
 
                /* Save a copy of the moving item */
@@ -6501,11 +6092,9 @@ void reorder_pack(void)
                /* Insert the moving item */
                object_copy(&inventory[j], q_ptr);
 
-               /* Window stuff */
                p_ptr->window |= (PW_INVEN);
        }
 
-       /* Message */
        if (flag) msg_print(_("ザックの中のアイテムを並べ直した。", "You reorder some items in your pack."));
 }
 
@@ -6517,7 +6106,7 @@ void reorder_pack(void)
  * @details
  * Include list of usable spells for readible books
  */
-void display_koff(IDX k_idx)
+void display_koff(KIND_OBJECT_IDX k_idx)
 {
        int y;
 
@@ -6526,7 +6115,7 @@ void display_koff(IDX k_idx)
        int         sval;
        REALM_IDX   use_realm;
 
-       char o_name[MAX_NLEN];
+       GAME_TEXT o_name[MAX_NLEN];
 
 
        /* Erase the window */
@@ -6538,14 +6127,10 @@ void display_koff(IDX k_idx)
 
        /* No info */
        if (!k_idx) return;
-
-       /* Get local object */
        q_ptr = &forge;
 
        /* Prepare the object */
        object_prep(q_ptr, k_idx);
-
-       /* Describe */
        object_desc(o_name, q_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY | OD_STORE));
 
        /* Mention the object name */
@@ -6607,7 +6192,7 @@ object_type *choose_warning_item(void)
        /* Search Inventory */
        for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
        {
-               u32b flgs[TR_FLAG_SIZE];
+               BIT_FLAGS flgs[TR_FLAG_SIZE];
                object_type *o_ptr = &inventory[i];
 
                object_flags(o_ptr, flgs);
@@ -6631,7 +6216,7 @@ object_type *choose_warning_item(void)
  * @param max 算出した最大ダメージを返すポインタ
  * @return なし
  */
-static void spell_damcalc(monster_type *m_ptr, int typ, HIT_POINT dam, int *max)
+static void spell_damcalc(monster_type *m_ptr, EFFECT_ID typ, HIT_POINT dam, int *max)
 {
        monster_race *r_ptr = &r_info[m_ptr->r_idx];
        int          rlev = r_ptr->level;
@@ -6876,7 +6461,7 @@ static void spell_damcalc(monster_type *m_ptr, int typ, HIT_POINT dam, int *max)
 * @param max 算出した最大ダメージを返すポインタ
 * @return なし
 */
-void spell_damcalc_by_spellnum(int spell_num, int typ, MONSTER_IDX m_idx, int *max)
+void spell_damcalc_by_spellnum(int spell_num, EFFECT_ID typ, MONSTER_IDX m_idx, int *max)
 {
     monster_type *m_ptr = &m_list[m_idx];
     HIT_POINT dam = monspell_damage((spell_num), m_idx, DAM_MAX);
@@ -6898,7 +6483,7 @@ static int blow_damcalc(monster_type *m_ptr, monster_blow *blow_ptr)
 
        if (blow_ptr->method != RBM_EXPLODE)
        {
-               int ac = p_ptr->ac + p_ptr->to_a;
+               ARMOUR_CLASS ac = p_ptr->ac + p_ptr->to_a;
 
                switch (blow_ptr->effect)
                {
@@ -6967,11 +6552,11 @@ static int blow_damcalc(monster_type *m_ptr, monster_blow *blow_ptr)
  * @param yy 危険性を調査するマスのY座標
  * @return 警告を無視して進むことを選択するかか問題が無ければTRUE、警告に従ったならFALSEを返す。
  */
-bool process_warning(int xx, int yy)
+bool process_warning(POSITION xx, POSITION yy)
 {
-       int mx, my;
-       cave_type *c_ptr;
-       char o_name[MAX_NLEN];
+       POSITION mx, my;
+       grid_type *g_ptr;
+       GAME_TEXT o_name[MAX_NLEN];
 
 #define WARNING_AWARE_RANGE 12
        int dam_max = 0;
@@ -6987,11 +6572,11 @@ bool process_warning(int xx, int yy)
 
                        if (!in_bounds(my, mx) || (distance(my, mx, yy, xx) > WARNING_AWARE_RANGE)) continue;
 
-                       c_ptr = &cave[my][mx];
+                       g_ptr = &grid_array[my][mx];
 
-                       if (!c_ptr->m_idx) continue;
+                       if (!g_ptr->m_idx) continue;
 
-                       m_ptr = &m_list[c_ptr->m_idx];
+                       m_ptr = &m_list[g_ptr->m_idx];
 
                        if (MON_CSLEEP(m_ptr)) continue;
                        if (!is_hostile(m_ptr)) continue;
@@ -7001,46 +6586,46 @@ bool process_warning(int xx, int yy)
                        /* Monster spells (only powerful ones)*/
                        if (projectable(my, mx, yy, xx))
             {
-                               u32b f4 = r_ptr->flags4;
-                               u32b f5 = r_ptr->a_ability_flags1;
-                               u32b f6 = r_ptr->a_ability_flags2;
+                               BIT_FLAGS f4 = r_ptr->flags4;
+                               BIT_FLAGS f5 = r_ptr->a_ability_flags1;
+                               BIT_FLAGS f6 = r_ptr->a_ability_flags2;
 
-                               if (!(d_info[dungeon_type].flags1 & DF1_NO_MAGIC))
+                               if (!(d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_MAGIC))
                                {
-                    if (f4 & RF4_BA_CHAO) spell_damcalc_by_spellnum(MS_BALL_CHAOS, GF_CHAOS, c_ptr->m_idx,  &dam_max0);
-                    if (f5 & RF5_BA_MANA) spell_damcalc_by_spellnum(MS_BALL_MANA, GF_MANA, c_ptr->m_idx, &dam_max0);
-                    if (f5 & RF5_BA_DARK) spell_damcalc_by_spellnum(MS_BALL_DARK, GF_DARK, c_ptr->m_idx, &dam_max0);
-                    if (f5 & RF5_BA_LITE) spell_damcalc_by_spellnum(MS_STARBURST, GF_LITE, c_ptr->m_idx, &dam_max0);
-                    if (f6 & RF6_HAND_DOOM) spell_damcalc_by_spellnum(MS_HAND_DOOM, GF_HAND_DOOM, c_ptr->m_idx, &dam_max0);
-                    if (f6 & RF6_PSY_SPEAR) spell_damcalc_by_spellnum(MS_PSY_SPEAR, GF_PSY_SPEAR, c_ptr->m_idx, &dam_max0);
+                                       if (f4 & RF4_BA_CHAO) spell_damcalc_by_spellnum(MS_BALL_CHAOS, GF_CHAOS, g_ptr->m_idx, &dam_max0);
+                                       if (f5 & RF5_BA_MANA) spell_damcalc_by_spellnum(MS_BALL_MANA, GF_MANA, g_ptr->m_idx, &dam_max0);
+                                       if (f5 & RF5_BA_DARK) spell_damcalc_by_spellnum(MS_BALL_DARK, GF_DARK, g_ptr->m_idx, &dam_max0);
+                                       if (f5 & RF5_BA_LITE) spell_damcalc_by_spellnum(MS_STARBURST, GF_LITE, g_ptr->m_idx, &dam_max0);
+                                       if (f6 & RF6_HAND_DOOM) spell_damcalc_by_spellnum(MS_HAND_DOOM, GF_HAND_DOOM, g_ptr->m_idx, &dam_max0);
+                                       if (f6 & RF6_PSY_SPEAR) spell_damcalc_by_spellnum(MS_PSY_SPEAR, GF_PSY_SPEAR, g_ptr->m_idx, &dam_max0);
                                }
-                if (f4 & RF4_ROCKET) spell_damcalc_by_spellnum(MS_ROCKET, GF_ROCKET, c_ptr->m_idx, &dam_max0);
-                if (f4 & RF4_BR_ACID) spell_damcalc_by_spellnum(MS_BR_ACID, GF_ACID, c_ptr->m_idx, &dam_max0);
-                if (f4 & RF4_BR_ELEC) spell_damcalc_by_spellnum(MS_BR_ELEC, GF_ELEC, c_ptr->m_idx, &dam_max0);
-                if (f4 & RF4_BR_FIRE) spell_damcalc_by_spellnum(MS_BR_FIRE, GF_FIRE, c_ptr->m_idx, &dam_max0);
-                if (f4 & RF4_BR_COLD) spell_damcalc_by_spellnum(MS_BR_COLD, GF_COLD, c_ptr->m_idx, &dam_max0);
-                if (f4 & RF4_BR_POIS) spell_damcalc_by_spellnum(MS_BR_POIS, GF_POIS, c_ptr->m_idx, &dam_max0);
-                if (f4 & RF4_BR_NETH) spell_damcalc_by_spellnum(MS_BR_NETHER, GF_NETHER, c_ptr->m_idx, &dam_max0);
-                if (f4 & RF4_BR_LITE) spell_damcalc_by_spellnum(MS_BR_LITE, GF_LITE, c_ptr->m_idx, &dam_max0);
-                if (f4 & RF4_BR_DARK) spell_damcalc_by_spellnum(MS_BR_DARK, GF_DARK, c_ptr->m_idx, &dam_max0);
-                if (f4 & RF4_BR_CONF) spell_damcalc_by_spellnum(MS_BR_CONF, GF_CONFUSION, c_ptr->m_idx, &dam_max0);
-                if (f4 & RF4_BR_SOUN) spell_damcalc_by_spellnum(MS_BR_SOUND, GF_SOUND, c_ptr->m_idx, &dam_max0);
-                if (f4 & RF4_BR_CHAO) spell_damcalc_by_spellnum(MS_BR_CHAOS, GF_CHAOS, c_ptr->m_idx, &dam_max0);
-                if (f4 & RF4_BR_DISE) spell_damcalc_by_spellnum(MS_BR_DISEN, GF_DISENCHANT, c_ptr->m_idx, &dam_max0);
-                if (f4 & RF4_BR_NEXU) spell_damcalc_by_spellnum(MS_BR_NEXUS, GF_NEXUS, c_ptr->m_idx, &dam_max0);
-                if (f4 & RF4_BR_TIME) spell_damcalc_by_spellnum(MS_BR_TIME, GF_TIME, c_ptr->m_idx, &dam_max0);
-                if (f4 & RF4_BR_INER) spell_damcalc_by_spellnum(MS_BR_INERTIA, GF_INERTIAL, c_ptr->m_idx, &dam_max0);
-                if (f4 & RF4_BR_GRAV) spell_damcalc_by_spellnum(MS_BR_GRAVITY, GF_GRAVITY, c_ptr->m_idx, &dam_max0);
-                if (f4 & RF4_BR_SHAR) spell_damcalc_by_spellnum(MS_BR_SHARDS, GF_SHARDS, c_ptr->m_idx, &dam_max0);
-                if (f4 & RF4_BR_PLAS) spell_damcalc_by_spellnum(MS_BR_PLASMA, GF_PLASMA, c_ptr->m_idx, &dam_max0);
-                if (f4 & RF4_BR_WALL) spell_damcalc_by_spellnum(MS_BR_FORCE, GF_FORCE, c_ptr->m_idx, &dam_max0);
-                if (f4 & RF4_BR_MANA) spell_damcalc_by_spellnum(MS_BR_MANA, GF_MANA, c_ptr->m_idx, &dam_max0);
-                if (f4 & RF4_BR_NUKE) spell_damcalc_by_spellnum(MS_BR_NUKE, GF_NUKE, c_ptr->m_idx, &dam_max0);
-                if (f4 & RF4_BR_DISI) spell_damcalc_by_spellnum(MS_BR_DISI, GF_DISINTEGRATE, c_ptr->m_idx, &dam_max0);
+                               if (f4 & RF4_ROCKET) spell_damcalc_by_spellnum(MS_ROCKET, GF_ROCKET, g_ptr->m_idx, &dam_max0);
+                               if (f4 & RF4_BR_ACID) spell_damcalc_by_spellnum(MS_BR_ACID, GF_ACID, g_ptr->m_idx, &dam_max0);
+                               if (f4 & RF4_BR_ELEC) spell_damcalc_by_spellnum(MS_BR_ELEC, GF_ELEC, g_ptr->m_idx, &dam_max0);
+                               if (f4 & RF4_BR_FIRE) spell_damcalc_by_spellnum(MS_BR_FIRE, GF_FIRE, g_ptr->m_idx, &dam_max0);
+                               if (f4 & RF4_BR_COLD) spell_damcalc_by_spellnum(MS_BR_COLD, GF_COLD, g_ptr->m_idx, &dam_max0);
+                               if (f4 & RF4_BR_POIS) spell_damcalc_by_spellnum(MS_BR_POIS, GF_POIS, g_ptr->m_idx, &dam_max0);
+                               if (f4 & RF4_BR_NETH) spell_damcalc_by_spellnum(MS_BR_NETHER, GF_NETHER, g_ptr->m_idx, &dam_max0);
+                               if (f4 & RF4_BR_LITE) spell_damcalc_by_spellnum(MS_BR_LITE, GF_LITE, g_ptr->m_idx, &dam_max0);
+                               if (f4 & RF4_BR_DARK) spell_damcalc_by_spellnum(MS_BR_DARK, GF_DARK, g_ptr->m_idx, &dam_max0);
+                               if (f4 & RF4_BR_CONF) spell_damcalc_by_spellnum(MS_BR_CONF, GF_CONFUSION, g_ptr->m_idx, &dam_max0);
+                               if (f4 & RF4_BR_SOUN) spell_damcalc_by_spellnum(MS_BR_SOUND, GF_SOUND, g_ptr->m_idx, &dam_max0);
+                               if (f4 & RF4_BR_CHAO) spell_damcalc_by_spellnum(MS_BR_CHAOS, GF_CHAOS, g_ptr->m_idx, &dam_max0);
+                               if (f4 & RF4_BR_DISE) spell_damcalc_by_spellnum(MS_BR_DISEN, GF_DISENCHANT, g_ptr->m_idx, &dam_max0);
+                               if (f4 & RF4_BR_NEXU) spell_damcalc_by_spellnum(MS_BR_NEXUS, GF_NEXUS, g_ptr->m_idx, &dam_max0);
+                               if (f4 & RF4_BR_TIME) spell_damcalc_by_spellnum(MS_BR_TIME, GF_TIME, g_ptr->m_idx, &dam_max0);
+                               if (f4 & RF4_BR_INER) spell_damcalc_by_spellnum(MS_BR_INERTIA, GF_INERTIAL, g_ptr->m_idx, &dam_max0);
+                               if (f4 & RF4_BR_GRAV) spell_damcalc_by_spellnum(MS_BR_GRAVITY, GF_GRAVITY, g_ptr->m_idx, &dam_max0);
+                               if (f4 & RF4_BR_SHAR) spell_damcalc_by_spellnum(MS_BR_SHARDS, GF_SHARDS, g_ptr->m_idx, &dam_max0);
+                               if (f4 & RF4_BR_PLAS) spell_damcalc_by_spellnum(MS_BR_PLASMA, GF_PLASMA, g_ptr->m_idx, &dam_max0);
+                               if (f4 & RF4_BR_WALL) spell_damcalc_by_spellnum(MS_BR_FORCE, GF_FORCE, g_ptr->m_idx, &dam_max0);
+                               if (f4 & RF4_BR_MANA) spell_damcalc_by_spellnum(MS_BR_MANA, GF_MANA, g_ptr->m_idx, &dam_max0);
+                               if (f4 & RF4_BR_NUKE) spell_damcalc_by_spellnum(MS_BR_NUKE, GF_NUKE, g_ptr->m_idx, &dam_max0);
+                               if (f4 & RF4_BR_DISI) spell_damcalc_by_spellnum(MS_BR_DISI, GF_DISINTEGRATE, g_ptr->m_idx, &dam_max0);
                        }
 
                        /* Monster melee attacks */
-                       if (!(r_ptr->flags1 & RF1_NEVER_BLOW) && !(d_info[dungeon_type].flags1 & DF1_NO_MELEE))
+                       if (!(r_ptr->flags1 & RF1_NEVER_BLOW) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_MELEE))
                        {
                                if (mx <= xx + 1 && mx >= xx - 1 && my <= yy + 1 && my >= yy - 1)
                                {
@@ -7079,15 +6664,15 @@ bool process_warning(int xx, int yy)
                 strcpy(o_name, _("体", "body")); /* Warning ability without item */
             msg_format(_("%sが鋭く震えた!", "Your %s pulsates sharply!"), o_name);
 
-                       disturb(0, 1);
+                       disturb(FALSE, TRUE);
             return get_check(_("本当にこのまま進むか?", "Really want to go ahead? "));
                }
        }
        else old_damage = old_damage / 2;
 
-       c_ptr = &cave[yy][xx];
-       if (((!easy_disarm && is_trap(c_ptr->feat))
-           || (c_ptr->mimic && is_trap(c_ptr->feat))) && !one_in_(13))
+       g_ptr = &grid_array[yy][xx];
+       if (((!easy_disarm && is_trap(g_ptr->feat))
+           || (g_ptr->mimic && is_trap(g_ptr->feat))) && !one_in_(13))
        {
                object_type *o_ptr = choose_warning_item();
 
@@ -7096,7 +6681,7 @@ bool process_warning(int xx, int yy)
         else
             strcpy(o_name, _("体", "body")); /* Warning ability without item */
         msg_format(_("%sが鋭く震えた!", "Your %s pulsates sharply!"), o_name);
-               disturb(0, 1);
+               disturb(FALSE, TRUE);
         return get_check(_("本当にこのまま進むか?", "Really want to go ahead? "));
        }
 
@@ -7108,7 +6693,7 @@ bool process_warning(int xx, int yy)
  */
 typedef struct {
        int add;       /* TR flag number or special essence id */
-       cptr add_name; /* Name of this ability */
+       concptr add_name; /* Name of this ability */
        ESSENCE_IDX type;      /* Menu number */
        int essence;   /* Index for carrying essences */
        int value;     /* Needed value to add this ability */
@@ -7347,7 +6932,7 @@ static essence_type essence_info[] =
  * エッセンス名テーブル / Essense names for Weapon smith
  */
 #ifdef JP
-cptr essence_name[] = 
+concptr essence_name[] = 
 {
        "腕力",
        "知能",
@@ -7450,7 +7035,7 @@ cptr essence_name[] =
 
 #else
 
-cptr essence_name[] = 
+concptr essence_name[] = 
 {
        "strength",
        "intelligen.",
@@ -7594,7 +7179,7 @@ static void drain_essence(void)
        TIME_EFFECT old_timeout;
        BIT_FLAGS old_flgs[TR_FLAG_SIZE], new_flgs[TR_FLAG_SIZE];
        object_type *o_ptr;
-       cptr q, s;
+       concptr q, s;
        POSITION iy, ix;
        byte_hack marked;
        ITEM_NUMBER number;
@@ -7605,34 +7190,21 @@ static void drain_essence(void)
                drain_value[i] = 0;
 
        item_tester_hook = object_is_weapon_armour_ammo;
-       item_tester_no_ryoute = TRUE;
 
-       /* Get an item */
        q = _("どのアイテムから抽出しますか?", "Extract from which item? ");
        s = _("抽出できるアイテムがありません。", "You have nothing you can extract from.");
 
-       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 | IGNORE_BOTHHAND_SLOT));
+       if (!o_ptr) return;
 
        if (object_is_known(o_ptr) && !object_is_nameless(o_ptr))
        {
-               char o_name[MAX_NLEN];
+               GAME_TEXT o_name[MAX_NLEN];
                object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
                if (!get_check(format(_("本当に%sから抽出してよろしいですか?", "Really extract from %s? "), o_name))) return;
        }
 
-       p_ptr->energy_use = 100;
+       take_turn(p_ptr, 100);;
 
        object_flags(o_ptr, old_flgs);
        if (have_flag(old_flgs, TR_KILL_DRAGON)) add_flag(old_flgs, TR_SLAY_DRAGON);
@@ -7815,11 +7387,7 @@ static void drain_essence(void)
 
        /* Apply autodestroy/inscription to the drained item */
        autopick_alter_item(item, TRUE);
-
-       /* Combine the pack */
-       p_ptr->notice |= (PN_COMBINE | PN_REORDER);
-
-       /* Window stuff */
+       p_ptr->update |= (PU_COMBINE | PU_REORDER);
        p_ptr->window |= (PW_INVEN);
 }
 
@@ -7834,7 +7402,7 @@ static COMMAND_CODE choose_essence(void)
        COMMAND_CODE menu_line = (use_menu ? 1 : 0);
 
 #ifdef JP
-       cptr menu_name[] = {
+       concptr menu_name[] = {
                "武器属性", 
                "耐性",
                "能力",
@@ -7844,7 +7412,7 @@ static COMMAND_CODE choose_essence(void)
                "その他"
        };
 #else
-       cptr menu_name[] = {
+       concptr menu_name[] = {
                "Brand weapon",
                "Resistance",
                "Ability",
@@ -7856,12 +7424,9 @@ static COMMAND_CODE choose_essence(void)
 #endif
        const COMMAND_CODE mode_max = 7;
 
-#ifdef ALLOW_REPEAT
        if (repeat_pull(&mode) && 1 <= mode && mode <= mode_max)
                return mode;
        mode = 0;
-#endif /* ALLOW_REPEAT */
-
        if (use_menu)
        {
                screen_save();
@@ -7931,9 +7496,7 @@ static COMMAND_CODE choose_essence(void)
                screen_load();
        }
 
-#ifdef ALLOW_REPEAT
        repeat_push(mode);
-#endif /* ALLOW_REPEAT */
        return mode;
 }
 
@@ -7949,12 +7512,12 @@ static void add_essence(ESSENCE_IDX mode)
        COMMAND_CODE i;
        bool flag,redraw;
        char choice;
-       cptr            q, s;
+       concptr            q, s;
        object_type *o_ptr;
        int ask = TRUE;
        char out_val[160];
        int num[22];
-       char o_name[MAX_NLEN];
+       GAME_TEXT o_name[MAX_NLEN];
        int use_essence;
        essence_type *es_ptr;
        bool able[22] = { 0 };
@@ -7969,11 +7532,8 @@ static void add_essence(ESSENCE_IDX mode)
                num[max_num++] = i;
        }
 
-#ifdef ALLOW_REPEAT
        if (!repeat_pull(&i) || i<0 || i>=max_num)
        {
-#endif /* ALLOW_REPEAT */
-
 
        /* Nothing chosen yet */
        flag = FALSE;
@@ -8061,8 +7621,6 @@ static void add_essence(ESSENCE_IDX mode)
 
                                /* Show list */
                                redraw = TRUE;
-
-                               /* Save the screen */
                                if (!use_menu) screen_save();
 
                                for (y = 1; y < 24; y++)
@@ -8159,8 +7717,6 @@ static void add_essence(ESSENCE_IDX mode)
                        {
                                /* Hide list */
                                redraw = FALSE;
-
-                               /* Restore the screen */
                                screen_load();
                        }
 
@@ -8202,17 +7758,12 @@ static void add_essence(ESSENCE_IDX mode)
                /* Stop the loop */
                flag = TRUE;
        }
-
-       /* Restore the screen */
        if (redraw) screen_load();
 
        if (!flag) return;
 
-#ifdef ALLOW_REPEAT
        repeat_push(i);
        }
-#endif /* ALLOW_REPEAT */
-
        es_ptr = &essence_info[num[i]];
 
        if (es_ptr->add == ESSENCE_SLAY_GLOVE)
@@ -8225,25 +7776,12 @@ static void add_essence(ESSENCE_IDX mode)
                item_tester_hook = object_is_armour;
        else
                item_tester_hook = object_is_weapon_armour_ammo;
-       item_tester_no_ryoute = TRUE;
 
-       /* Get an item */
        q = _("どのアイテムを改良しますか?", "Improve which item? ");
        s = _("改良できるアイテムがありません。", "You have nothing to improve.");
 
-       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 | IGNORE_BOTHHAND_SLOT));
+       if (!o_ptr) return;
 
        if ((mode != 10) && (object_is_artifact(o_ptr) || object_is_smith(o_ptr)))
        {
@@ -8346,7 +7884,7 @@ static void add_essence(ESSENCE_IDX mode)
                        if ((o_ptr->to_h >= p_ptr->lev/5+5) && (o_ptr->to_d >= p_ptr->lev/5+5))
                        {
                                msg_print(_("改良に失敗した。", "You failed to enchant."));
-                               p_ptr->energy_use = 100;
+                               take_turn(p_ptr, 100);;
                                return;
                        }
                        else
@@ -8360,7 +7898,7 @@ static void add_essence(ESSENCE_IDX mode)
                        if (o_ptr->to_a >= p_ptr->lev/5+5)
                        {
                                msg_print(_("改良に失敗した。", "You failed to enchant."));
-                               p_ptr->energy_use = 100;
+                               take_turn(p_ptr, 100);;
                                return;
                        }
                        else
@@ -8437,18 +7975,14 @@ static void add_essence(ESSENCE_IDX mode)
                }
        }
 
-       p_ptr->energy_use = 100;
+       take_turn(p_ptr, 100);
 
 #ifdef JP
        msg_format("%sに%sの能力を付加しました。", o_name, es_ptr->add_name);
 #else
        msg_format("You have added ability of %s to %s.", es_ptr->add_name, o_name);
 #endif
-
-       /* Combine the pack */
-       p_ptr->notice |= (PN_COMBINE | PN_REORDER);
-
-       /* Window stuff */
+       p_ptr->update |= (PU_COMBINE | PU_REORDER);
        p_ptr->window |= (PW_INVEN);
 }
 
@@ -8459,37 +7993,25 @@ static void add_essence(ESSENCE_IDX mode)
 static void erase_essence(void)
 {
        OBJECT_IDX item;
-       cptr q, s;
+       concptr q, s;
        object_type *o_ptr;
-       char o_name[MAX_NLEN];
+       GAME_TEXT o_name[MAX_NLEN];
        BIT_FLAGS flgs[TR_FLAG_SIZE];
 
        item_tester_hook = object_is_smith;
 
-       /* Get an item */
        q = _("どのアイテムのエッセンスを消去しますか?", "Remove from which item? ");
        s = _("エッセンスを付加したアイテムがありません。", "You have nothing to remove essence.");
 
-       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;
 
        object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
        if (!get_check(format(_("よろしいですか? [%s]", "Are you sure? [%s]"), o_name))) return;
 
-       p_ptr->energy_use = 100;
+       take_turn(p_ptr, 100);;
 
-       if (o_ptr->xtra3 == 1+ESSENCE_SLAY_GLOVE)
+       if (o_ptr->xtra3 == 1 + ESSENCE_SLAY_GLOVE)
        {
                o_ptr->to_h -= (o_ptr->xtra4>>8);
                o_ptr->to_d -= (o_ptr->xtra4 & 0x000f);
@@ -8501,11 +8023,7 @@ static void erase_essence(void)
        object_flags(o_ptr, flgs);
        if (!(have_pval_flags(flgs))) o_ptr->pval = 0;
        msg_print(_("エッセンスを取り去った。", "You removed all essence you have added."));
-
-       /* Combine the pack */
-       p_ptr->notice |= (PN_COMBINE | PN_REORDER);
-
-       /* Window stuff */
+       p_ptr->update |= (PU_COMBINE | PU_REORDER);
        p_ptr->window |= (PW_INVEN);
 }
 
@@ -8523,11 +8041,7 @@ void do_cmd_kaji(bool only_browse)
 
        if (!only_browse)
        {
-               if (p_ptr->confused)
-               {
-                       msg_print(_("混乱していて作業できない!", "You are too confused!"));
-                       return;
-               }
+               if (cmd_limit_confused(p_ptr)) return;
                if (p_ptr->blind)
                {
                        msg_print(_("目が見えなくて作業できない!", "You are blind!"));
@@ -8540,11 +8054,8 @@ void do_cmd_kaji(bool only_browse)
                }
        }
 
-#ifdef ALLOW_REPEAT
        if (!(repeat_pull(&mode) && 1 <= mode && mode <= 5))
        {
-#endif /* ALLOW_REPEAT */
-
        if (only_browse) screen_save();
        do {
        if (!only_browse) screen_save();
@@ -8600,19 +8111,14 @@ void do_cmd_kaji(bool only_browse)
        {
                while (!mode)
                {
+                       prt(_("  a) エッセンス一覧", "  a) List essences"), 2, 14);
+                       prt(_("  b) エッセンス抽出", "  b) Extract essence"), 3, 14);
+                       prt(_("  c) エッセンス消去", "  c) Remove essence"), 4, 14);
+                       prt(_("  d) エッセンス付加", "  d) Add essence"), 5, 14);
+                       prt(_("  e) 武器/防具強化", "  e) Enchant weapon/armor"), 6, 14);
 #ifdef JP
-                       prt("  a) エッセンス一覧", 2, 14);
-                       prt("  b) エッセンス抽出", 3, 14);
-                       prt("  c) エッセンス消去", 4, 14);
-                       prt("  d) エッセンス付加", 5, 14);
-                       prt("  e) 武器/防具強化", 6, 14);
                        if (!get_com(format("どの能力を%sますか:", only_browse ? "調べ" : "使い"), &choice, TRUE))
 #else
-                       prt("  a) List essences", 2, 14);
-                       prt("  b) Extract essence", 3, 14);
-                       prt("  c) Remove essence", 4, 14);
-                       prt("  d) Add essence", 5, 14);
-                       prt("  e) Enchant weapon/armor", 6, 14);
                        if (!get_com("Command :", &choice, TRUE))
 #endif
                        {
@@ -8668,11 +8174,8 @@ void do_cmd_kaji(bool only_browse)
        }
        if (!only_browse) screen_load();
        } while (only_browse);
-#ifdef ALLOW_REPEAT
        repeat_push(mode);
        }
-#endif /* ALLOW_REPEAT */
-
        switch(mode)
        {
                case 1: display_essence();break;
@@ -8696,7 +8199,7 @@ void do_cmd_kaji(bool only_browse)
  * @param flgs 特別に追加するフラグを返す参照ポインタ
  * @return なし
  */
-void torch_flags(object_type *o_ptr, u32b *flgs)
+void torch_flags(object_type *o_ptr, BIT_FLAGS *flgs)
 {
        if ((o_ptr->tval == TV_LITE) && (o_ptr->sval == SV_LITE_TORCH))
        {
@@ -8717,7 +8220,7 @@ void torch_flags(object_type *o_ptr, u32b *flgs)
  * @param ds 特別なダイス面数を返す参照ポインタ
  * @return なし
  */
-void torch_dice(object_type *o_ptr, int *dd, int *ds)
+void torch_dice(object_type *o_ptr, DICE_NUMBER *dd, DICE_SID *ds)
 {
        if ((o_ptr->tval == TV_LITE) && (o_ptr->sval == SV_LITE_TORCH))
        {