OSDN Git Service

[Refactor] #37353 コメント整理 / Refactor comments.
[hengband/hengband.git] / src / object2.c
index fb06588..b29d176 100644 (file)
  */
 
 #include "angband.h"
+#include "object-hook.h"
+#include "object-curse.h"
+
+static void one_sustain(object_type *o_ptr);
+
 
 static cptr const kaji_tips[5] =
 {
@@ -31,18 +36,35 @@ static cptr const kaji_tips[5] =
 };
 
 /*!
+ * @brief 対象のオブジェクトにランダムな能力維持を一つ付加する。/ Choose one random sustain
+ * @details 重複の抑止はない。
+ * @param o_ptr 対象のオブジェクト構造体ポインタ
+ * @return なし
+ */
+static void one_sustain(object_type *o_ptr)
+{
+       switch (randint0(6))
+       {
+       case 0: add_flag(o_ptr->art_flags, TR_SUST_STR); break;
+       case 1: add_flag(o_ptr->art_flags, TR_SUST_INT); break;
+       case 2: add_flag(o_ptr->art_flags, TR_SUST_WIS); break;
+       case 3: add_flag(o_ptr->art_flags, TR_SUST_DEX); break;
+       case 4: add_flag(o_ptr->art_flags, TR_SUST_CON); break;
+       case 5: add_flag(o_ptr->art_flags, TR_SUST_CHR); break;
+       }
+}
+
+/*!
  * @brief 床上、モンスター所持でスタックされたアイテムを削除しスタックを補完する / Excise a dungeon object from any stacks
  * @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];
@@ -59,14 +81,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 */
@@ -91,7 +110,6 @@ void excise_object_idx(int o_idx)
                                /* Forget next pointer */
                                o_ptr->next_o_idx = 0;
 
-                               /* Done */
                                break;
                        }
 
@@ -105,8 +123,8 @@ void excise_object_idx(int o_idx)
        {
                cave_type *c_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];
@@ -115,14 +133,11 @@ void excise_object_idx(int o_idx)
                for (this_o_idx = c_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 */
@@ -147,7 +162,6 @@ void excise_object_idx(int o_idx)
                                /* Forget next pointer */
                                o_ptr->next_o_idx = 0;
 
-                               /* Done */
                                break;
                        }
 
@@ -165,7 +179,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;
 
@@ -178,17 +192,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 */
@@ -203,17 +214,14 @@ 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;
-
+       OBJECT_IDX this_o_idx, next_o_idx = 0;
 
        /* Refuse "illegal" locations */
        if (!in_bounds(y, x)) return;
 
-
        /* Grid */
        c_ptr = &cave[y][x];
 
@@ -221,14 +229,10 @@ void delete_object(int y, int x)
        for (this_o_idx = c_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 */
@@ -250,23 +254,18 @@ void delete_object(int y, int x)
  * @param i2 整理したい配列の終点
  * @return なし
  */
-static void compact_objects_aux(int i1, int i2)
+static void compact_objects_aux(OBJECT_IDX i1, OBJECT_IDX i2)
 {
-       int i;
-
+       OBJECT_IDX i;
        cave_type *c_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 */
@@ -279,12 +278,8 @@ static void compact_objects_aux(int i1, int i2)
                        o_ptr->next_o_idx = i2;
                }
        }
-
-
-       /* Acquire object */
        o_ptr = &o_list[i1];
 
-
        /* Monster */
        if (o_ptr->held_m_idx)
        {
@@ -304,7 +299,7 @@ static void compact_objects_aux(int i1, int i2)
        /* Dungeon */
        else
        {
-               int y, x;
+               POSITION y, x;
 
                /* Acquire location */
                y = o_ptr->iy;
@@ -321,7 +316,6 @@ static void compact_objects_aux(int i1, int i2)
                }
        }
 
-
        /* Structure copy */
        o_list[i2] = o_list[i1];
 
@@ -348,21 +342,17 @@ static void compact_objects_aux(int i1, int i2)
  */
 void compact_objects(int size)
 {
-       int i, 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);
        }
 
@@ -424,7 +414,6 @@ void compact_objects(int size)
                        /* Apply the saving throw */
                        if (randint0(100) < chance) continue;
 
-                       /* Delete the object */
                        delete_object_idx(i);
 
                        /* Count it */
@@ -503,8 +492,8 @@ void wipe_o_list(void)
                        cave_type *c_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];
@@ -512,8 +501,6 @@ void wipe_o_list(void)
                        /* Hack -- see above */
                        c_ptr->o_idx = 0;
                }
-
-               /* Wipe the object */
                object_wipe(o_ptr);
        }
 
@@ -533,10 +520,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.
  */
-s16b o_pop(void)
+OBJECT_IDX o_pop(void)
 {
-       int i;
-
+       OBJECT_IDX i;
 
        /* Initial allocation */
        if (o_max < max_o_idx)
@@ -559,8 +545,6 @@ s16b o_pop(void)
        for (i = 1; i < o_max; i++)
        {
                object_type *o_ptr;
-
-               /* Acquire object */
                o_ptr = &o_list[i];
 
                /* Skip live objects */
@@ -577,7 +561,6 @@ s16b o_pop(void)
        /* Warn the player (except during dungeon creation) */
        if (character_dungeon) msg_print(_("アイテムが多すぎる!", "Too many objects!"));
 
-       /* Oops */
        return (0);
 }
 
@@ -636,11 +619,11 @@ 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;
 
@@ -752,8 +735,6 @@ s16b get_obj_num(int level)
                if (table[i].level < table[j].level) i = j;
        }
 
-
-       /* Result */
        return (table[i].index);
 }
 
@@ -821,7 +802,6 @@ void object_aware(object_type *o_ptr)
        }
 }
 
-
 /*!
  * @brief オブジェクトを試行済にする /
  * Something has been "sampled"
@@ -834,6 +814,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 未鑑定なベースアイテムの基本価格を返す /
@@ -877,7 +930,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;
@@ -905,7 +958,7 @@ static s32b object_value_base(object_type *o_ptr)
 s32b flag_cost(object_type *o_ptr, int plusses)
 {
        s32b total = 0;
-       u32b flgs[TR_FLAG_SIZE];
+       BIT_FLAGS flgs[TR_FLAG_SIZE];
        s32b tmp_cost;
        int count;
        int i;
@@ -1135,12 +1188,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];
 
 
@@ -1260,7 +1311,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:
@@ -1270,7 +1320,6 @@ s32b object_value_real(object_type *o_ptr)
                         */
                        value += (value * o_ptr->pval / (k_ptr->pval * 2));
 
-                       /* Done */
                        break;
                }
 
@@ -1284,7 +1333,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;
                }
 
@@ -1305,7 +1353,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;
                }
 
@@ -1326,7 +1373,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;
                }
 
@@ -1345,14 +1391,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;
@@ -1397,10 +1442,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))
@@ -1467,10 +1511,8 @@ bool can_player_destroy_object(object_type *o_ptr)
                /* Combine the pack */
                p_ptr->notice |= (PN_COMBINE);
 
-               /* Window stuff */
                p_ptr->window |= (PW_INVEN | PW_EQUIP);
 
-               /* Done */
                return FALSE;
        }
 
@@ -1831,8 +1873,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- */
@@ -1857,11 +1899,11 @@ void object_absorb(object_type *o_ptr, object_type *j_ptr)
  * @param sval 検索したいベースアイテムのsval
  * @return なし
  */
-s16b lookup_kind(int tval, int sval)
+IDX lookup_kind(OBJECT_TYPE_VALUE tval, OBJECT_SUBTYPE_VALUE sval)
 {
-       int k;
+       IDX k;
        int num = 0;
-       int bk = 0;
+       IDX bk = 0;
 
        /* Look for it */
        for (k = 1; k < max_k_idx; k++)
@@ -1891,12 +1933,10 @@ s16b lookup_kind(int tval, int sval)
        }
 
 #if 0
-       /* Oops */
        msg_format(_("アイテムがない (%d,%d)", "No object (%d,%d)"), tval, sval);
 #endif
 
 
-       /* Oops */
        return (0);
 }
 
@@ -1935,7 +1975,7 @@ void object_copy(object_type *o_ptr, object_type *j_ptr)
  * @param k_idx 新たに作成したいベースアイテム情報のID
  * @return なし
  */
-void object_prep(object_type *o_ptr, int k_idx)
+void object_prep(object_type *o_ptr, KIND_OBJECT_IDX k_idx)
 {
        object_kind *k_ptr = &k_info[k_idx];
 
@@ -1969,7 +2009,7 @@ void object_prep(object_type *o_ptr, int k_idx)
        o_ptr->ds = k_ptr->ds;
 
        /* Default activation */
-       if (k_ptr->act_idx > 0) o_ptr->xtra2 = k_ptr->act_idx;
+       if (k_ptr->act_idx > 0) o_ptr->xtra2 = (XTRA8)k_ptr->act_idx;
 
        /* Hack -- worthless items are always "broken" */
        if (k_info[o_ptr->k_idx].cost <= 0) o_ptr->ident |= (IDENT_BROKEN);
@@ -2027,7 +2067,7 @@ void object_prep(object_type *o_ptr, int k_idx)
  * 120    0.03  0.11  0.31  0.46  1.31  2.48  4.60  7.78 11.67 25.53 45.72\n
  * 128    0.02  0.01  0.13  0.33  0.83  1.41  3.24  6.17  9.57 14.22 64.07\n
  */
-s16b m_bonus(int max, int level)
+int m_bonus(int max, DEPTH level)
 {
        int bonus, stand, extra, value;
 
@@ -2064,8 +2104,6 @@ s16b m_bonus(int max, int level)
 
        /* Enforce the maximum value */
        if (value > max) return (max);
-
-       /* Result */
        return (value);
 }
 
@@ -2103,8 +2141,8 @@ static void object_mention(object_type *o_ptr)
  */
 static bool make_artifact_special(object_type *o_ptr)
 {
-       int i;
-       int k_idx = 0;
+       IDX i;
+       KIND_OBJECT_IDX k_idx = 0;
 
        /*! @note 地上ではキャンセルする / No artifacts in the town */
        if (!dun_level) return (FALSE);
@@ -2172,7 +2210,7 @@ static bool make_artifact_special(object_type *o_ptr)
  */
 static bool make_artifact(object_type *o_ptr)
 {
-       int i;
+       IDX i;
 
 
        /* No artifacts in the town */
@@ -2283,13 +2321,13 @@ static byte get_random_ego(byte slot, bool good)
  * Hack -- note special base damage dice boosting\n
  * Hack -- note special processing for weapon/digger\n
  */
-static void a_m_aux_1(object_type *o_ptr, int level, int power)
+static void a_m_aux_1(object_type *o_ptr, DEPTH level, int power)
 {
-       int tohit1 = randint1(5) + m_bonus(5, level);
-       int todam1 = randint1(5) + m_bonus(5, level);
+       HIT_PROB tohit1 = randint1(5) + (HIT_PROB)m_bonus(5, level);
+       HIT_POINT todam1 = randint1(5) + (HIT_POINT)m_bonus(5, level);
 
-       int tohit2 = m_bonus(10, level);
-       int todam2 = m_bonus(10, level);
+       HIT_PROB tohit2 = (HIT_PROB)m_bonus(10, level);
+       HIT_POINT todam2 = (HIT_POINT)m_bonus(10, level);
 
        if ((o_ptr->tval == TV_BOLT) || (o_ptr->tval == TV_ARROW) || (o_ptr->tval == TV_SHOT))
        {
@@ -2454,13 +2492,13 @@ static void a_m_aux_1(object_type *o_ptr, int level, int power)
                                                add_flag(o_ptr->art_flags, TR_RES_FEAR);
                                        break;
                                case EGO_SHARPNESS:
-                                       o_ptr->pval = m_bonus(5, level) + 1;
+                                       o_ptr->pval = (PARAMETER_VALUE)m_bonus(5, level) + 1;
                                        break;
                                case EGO_EARTHQUAKES:
                                        if (one_in_(3) && (level > 60))
                                                add_flag(o_ptr->art_flags, TR_BLOWS);
                                        else
-                                               o_ptr->pval = m_bonus(3, level);
+                                               o_ptr->pval = (PARAMETER_VALUE)m_bonus(3, level);
                                        break;
                                case EGO_VAMPIRIC:
                                        if (one_in_(5))
@@ -2671,11 +2709,10 @@ 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)
 {
-       int toac1 = randint1(5) + m_bonus(5, level);
-
-       int toac2 = m_bonus(10, level);
+       ARMOUR_CLASS toac1 = (ARMOUR_CLASS)randint1(5) + m_bonus(5, level);
+       ARMOUR_CLASS toac2 = (ARMOUR_CLASS)m_bonus(10, level);
 
        /* Good */
        if (power > 0)
@@ -2759,24 +2796,23 @@ static void a_m_aux_2(object_type *o_ptr, int level, int power)
 
                                        switch (o_ptr->name2)
                                        {
-                                         case EGO_DWARVEN:
-                                               if (o_ptr->tval != TV_HARD_ARMOR)
-                                               {
-                                                       okay_flag = FALSE;
-                                                       break;
-                                               }
-                                         case EGO_DRUID:
-                                               if (o_ptr->tval != TV_SOFT_ARMOR)
-                                               {
-                                                       okay_flag = FALSE;
-                                                       break;
-                                               }
-                                         default:
+                                               case EGO_DWARVEN:
+                                                       if (o_ptr->tval != TV_HARD_ARMOR)
+                                                       {
+                                                               okay_flag = FALSE;
+                                                       }
+                                               break;
+                                               case EGO_DRUID:
+                                                       if (o_ptr->tval != TV_SOFT_ARMOR)
+                                                       {
+                                                               okay_flag = FALSE;
+                                                       }
+                                               break;
+                                               default:
                                                break;
                                        }
 
-                                       if (okay_flag)
-                                               break;
+                                       if (okay_flag) break;
                                }
                                switch (o_ptr->name2)
                                {
@@ -3105,7 +3141,7 @@ static void a_m_aux_2(object_type *o_ptr, int level, int power)
                                        o_ptr->to_d -= 6;
                                        o_ptr->to_h -= 6;
                                        break;
-                                 case EGO_NAZGUL:
+                               case EGO_NAZGUL:
                                        o_ptr->to_d -= 3;
                                        o_ptr->to_h -= 3;
                                        if (one_in_(3)) add_flag(o_ptr->art_flags, TR_COWARDICE);
@@ -3141,7 +3177,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)
@@ -3154,7 +3190,7 @@ static void a_m_aux_3(object_type *o_ptr, int level, int power)
                                case SV_RING_ATTACKS:
                                {
                                        /* Stat bonus */
-                                       o_ptr->pval = m_bonus(2, level);
+                                       o_ptr->pval = (PARAMETER_VALUE)m_bonus(2, level);
                                        if (one_in_(15)) o_ptr->pval++;
                                        if (o_ptr->pval < 1) o_ptr->pval = 1;
 
@@ -3185,7 +3221,7 @@ static void a_m_aux_3(object_type *o_ptr, int level, int power)
                                case SV_RING_DEX:
                                {
                                        /* Stat bonus */
-                                       o_ptr->pval = 1 + m_bonus(5, level);
+                                       o_ptr->pval = 1 + (PARAMETER_VALUE)m_bonus(5, level);
 
                                        /* Cursed */
                                        if (power < 0)
@@ -3207,7 +3243,7 @@ static void a_m_aux_3(object_type *o_ptr, int level, int power)
                                case SV_RING_SPEED:
                                {
                                        /* Base speed (1 to 10) */
-                                       o_ptr->pval = randint1(5) + m_bonus(5, level);
+                                       o_ptr->pval = randint1(5) + (PARAMETER_VALUE)m_bonus(5, level);
 
                                        /* Super-charge the ring */
                                        while (randint0(100) < 50) o_ptr->pval++;
@@ -3239,7 +3275,7 @@ static void a_m_aux_3(object_type *o_ptr, int level, int power)
                                        while (one_in_(4));
 
                                        /* Bonus to armor class */
-                                       o_ptr->to_a = 10 + randint1(5) + m_bonus(10, level);
+                                       o_ptr->to_a = 10 + randint1(5) + (ARMOUR_CLASS)m_bonus(10, level);
                                }
                                break;
 
@@ -3253,7 +3289,7 @@ static void a_m_aux_3(object_type *o_ptr, int level, int power)
                                case SV_RING_SEARCHING:
                                {
                                        /* Bonus to searching */
-                                       o_ptr->pval = 1 + m_bonus(5, level);
+                                       o_ptr->pval = 1 + (PARAMETER_VALUE)m_bonus(5, level);
 
                                        /* Cursed */
                                        if (power < 0)
@@ -3278,7 +3314,7 @@ static void a_m_aux_3(object_type *o_ptr, int level, int power)
                                case SV_RING_ELEC:
                                {
                                        /* Bonus to armor class */
-                                       o_ptr->to_a = 5 + randint1(5) + m_bonus(10, level);
+                                       o_ptr->to_a = 5 + randint1(5) + (ARMOUR_CLASS)m_bonus(10, level);
                                        break;
                                }
 
@@ -3293,7 +3329,7 @@ static void a_m_aux_3(object_type *o_ptr, int level, int power)
                                        o_ptr->curse_flags |= TRC_CURSED;
 
                                        /* Penalize */
-                                       o_ptr->pval = 0 - (1 + m_bonus(5, level));
+                                       o_ptr->pval = 0 - (1 + (PARAMETER_VALUE)m_bonus(5, level));
                                        if (power > 0) power = 0 - power;
 
                                        break;
@@ -3309,8 +3345,8 @@ static void a_m_aux_3(object_type *o_ptr, int level, int power)
                                        o_ptr->curse_flags |= TRC_CURSED;
 
                                        /* Penalize */
-                                       o_ptr->to_a = 0 - (5 + m_bonus(10, level));
-                                       o_ptr->pval = 0 - (1 + m_bonus(5, level));
+                                       o_ptr->to_a = 0 - (5 + (ARMOUR_CLASS)m_bonus(10, level));
+                                       o_ptr->pval = 0 - (1 + (PARAMETER_VALUE)m_bonus(5, level));
                                        if (power > 0) power = 0 - power;
 
                                        break;
@@ -3320,7 +3356,7 @@ static void a_m_aux_3(object_type *o_ptr, int level, int power)
                                case SV_RING_DAMAGE:
                                {
                                        /* Bonus to damage */
-                                       o_ptr->to_d = 1 + randint1(5) + m_bonus(16, level);
+                                       o_ptr->to_d = 1 + randint1(5) + (HIT_POINT)m_bonus(16, level);
 
                                        /* Cursed */
                                        if (power < 0)
@@ -3342,7 +3378,7 @@ static void a_m_aux_3(object_type *o_ptr, int level, int power)
                                case SV_RING_ACCURACY:
                                {
                                        /* Bonus to hit */
-                                       o_ptr->to_h = 1 + randint1(5) + m_bonus(16, level);
+                                       o_ptr->to_h = 1 + randint1(5) + (HIT_PROB)m_bonus(16, level);
 
                                        /* Cursed */
                                        if (power < 0)
@@ -3364,7 +3400,7 @@ static void a_m_aux_3(object_type *o_ptr, int level, int power)
                                case SV_RING_PROTECTION:
                                {
                                        /* Bonus to armor class */
-                                       o_ptr->to_a = 5 + randint1(8) + m_bonus(10, level);
+                                       o_ptr->to_a = 5 + randint1(8) + (ARMOUR_CLASS)m_bonus(10, level);
 
                                        /* Cursed */
                                        if (power < 0)
@@ -3386,8 +3422,8 @@ static void a_m_aux_3(object_type *o_ptr, int level, int power)
                                case SV_RING_SLAYING:
                                {
                                        /* Bonus to damage and to hit */
-                                       o_ptr->to_d = randint1(5) + m_bonus(12, level);
-                                       o_ptr->to_h = randint1(5) + m_bonus(12, level);
+                                       o_ptr->to_d = randint1(5) + (HIT_POINT)m_bonus(12, level);
+                                       o_ptr->to_h = randint1(5) + (HIT_PROB)m_bonus(12, level);
 
                                        /* Cursed */
                                        if (power < 0)
@@ -3408,7 +3444,7 @@ static void a_m_aux_3(object_type *o_ptr, int level, int power)
 
                                case SV_RING_MUSCLE:
                                {
-                                       o_ptr->pval = 1 + m_bonus(3, level);
+                                       o_ptr->pval = 1 + (PARAMETER_VALUE)m_bonus(3, level);
                                        if (one_in_(4)) o_ptr->pval++;
 
                                        /* Cursed */
@@ -3645,7 +3681,7 @@ static void a_m_aux_3(object_type *o_ptr, int level, int power)
                                case SV_AMULET_WISDOM:
                                case SV_AMULET_CHARISMA:
                                {
-                                       o_ptr->pval = 1 + m_bonus(5, level);
+                                       o_ptr->pval = 1 + (PARAMETER_VALUE)m_bonus(5, level);
 
                                        /* Cursed */
                                        if (power < 0)
@@ -3704,7 +3740,7 @@ static void a_m_aux_3(object_type *o_ptr, int level, int power)
                                /* Amulet of searching */
                                case SV_AMULET_SEARCHING:
                                {
-                                       o_ptr->pval = randint1(2) + m_bonus(4, level);
+                                       o_ptr->pval = randint1(2) + (PARAMETER_VALUE)m_bonus(4, level);
 
                                        /* Cursed */
                                        if (power < 0)
@@ -3725,8 +3761,8 @@ static void a_m_aux_3(object_type *o_ptr, int level, int power)
                                /* Amulet of the Magi -- never cursed */
                                case SV_AMULET_THE_MAGI:
                                {
-                                       o_ptr->pval = randint1(5) + m_bonus(5, level);
-                                       o_ptr->to_a = randint1(5) + m_bonus(5, level);
+                                       o_ptr->pval = randint1(5) + (PARAMETER_VALUE)m_bonus(5, level);
+                                       o_ptr->to_a = randint1(5) + (ARMOUR_CLASS)m_bonus(5, level);
 
                                        /* gain one low ESP */
                                        add_esp_weak(o_ptr, FALSE);
@@ -3744,8 +3780,8 @@ static void a_m_aux_3(object_type *o_ptr, int level, int power)
                                        o_ptr->curse_flags |= (TRC_CURSED);
 
                                        /* Penalize */
-                                       o_ptr->pval = 0 - (randint1(5) + m_bonus(5, level));
-                                       o_ptr->to_a = 0 - (randint1(5) + m_bonus(5, level));
+                                       o_ptr->pval = 0 - (randint1(5) + (PARAMETER_VALUE)m_bonus(5, level));
+                                       o_ptr->to_a = 0 - (randint1(5) + (ARMOUR_CLASS)m_bonus(5, level));
                                        if (power > 0) power = 0 - power;
 
                                        break;
@@ -3753,7 +3789,7 @@ static void a_m_aux_3(object_type *o_ptr, int level, int power)
 
                                case SV_AMULET_MAGIC_MASTERY:
                                {
-                                       o_ptr->pval = 1 + m_bonus(4, level);
+                                       o_ptr->pval = 1 + (PARAMETER_VALUE)m_bonus(4, level);
 
                                        /* Cursed */
                                        if (power < 0)
@@ -3925,7 +3961,7 @@ static void a_m_aux_3(object_type *o_ptr, int level, int power)
  * @param r_idx チェックしたいモンスター種族のID
  * @return 人形にできるならTRUEを返す
  */
-static bool item_monster_okay(int r_idx)
+static bool item_monster_okay(MONRACE_IDX r_idx)
 {
        monster_race *r_ptr = &r_info[r_idx];
 
@@ -3937,7 +3973,6 @@ static bool item_monster_okay(int r_idx)
        if (r_ptr->flags1 & RF1_FORCE_DEPTH) return (FALSE);
        if (r_ptr->flags7 & RF7_UNIQUE2) return (FALSE);
 
-       /* Okay */
        return (TRUE);
 }
 
@@ -3952,7 +3987,7 @@ static bool item_monster_okay(int 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];
 
@@ -4079,7 +4114,7 @@ static void a_m_aux_4(object_type *o_ptr, int level, int power)
 
                case TV_FIGURINE:
                {
-                       int i = 1;
+                       PARAMETER_VALUE i = 1;
                        int check;
 
                        monster_race *r_ptr;
@@ -4118,7 +4153,7 @@ static void a_m_aux_4(object_type *o_ptr, int level, int power)
 
                case TV_CORPSE:
                {
-                       int i = 1;
+                       PARAMETER_VALUE i = 1;
                        int check;
 
                        u32b match = 0;
@@ -4168,7 +4203,7 @@ static void a_m_aux_4(object_type *o_ptr, int level, int power)
 
                case TV_STATUE:
                {
-                       int i = 1;
+                       PARAMETER_VALUE i = 1;
 
                        monster_race *r_ptr;
 
@@ -4199,7 +4234,7 @@ static void a_m_aux_4(object_type *o_ptr, int level, int power)
 
                case TV_CHEST:
                {
-                       byte obj_level = k_info[o_ptr->k_idx].level;
+                       DEPTH obj_level = k_info[o_ptr->k_idx].level;
 
                        /* Hack -- skip ruined chests */
                        if (obj_level <= 0) break;
@@ -4254,7 +4289,7 @@ static void a_m_aux_4(object_type *o_ptr, int level, int power)
  * "good" and "great" arguments are false.  As a total hack, if "great" is\n
  * true, then the item gets 3 extra "attempts" to become an artifact.\n
  */
-void apply_magic(object_type *o_ptr, int lev, u32b mode)
+void apply_magic(object_type *o_ptr, DEPTH lev, BIT_FLAGS mode)
 {
        int i, rolls, f1, f2, power;
 
@@ -4397,7 +4432,6 @@ void apply_magic(object_type *o_ptr, int lev, u32b 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;
        }
 
@@ -4519,7 +4553,7 @@ void apply_magic(object_type *o_ptr, int lev, u32b mode)
                }
 
                /* Hack -- apply activatin index if needed */
-               if (e_ptr->act_idx) o_ptr->xtra2 = e_ptr->act_idx;
+               if (e_ptr->act_idx) o_ptr->xtra2 = (XTRA8)e_ptr->act_idx;
 
                /* Hack -- apply extra penalties if needed */
                if ((object_is_cursed(o_ptr) || object_is_broken(o_ptr)) && !(e_ptr->gen_flags & (TRG_POWERFUL)))
@@ -4634,7 +4668,6 @@ void apply_magic(object_type *o_ptr, int lev, u32b mode)
                                o_ptr->pval = 2;
                }
                
-               /* Done */
                return;
        }
 
@@ -4665,7 +4698,7 @@ void apply_magic(object_type *o_ptr, int lev, u32b mode)
  * @param k_idx 判定したいベースアイテムのID
  * @return ベースアイテムが上質ならばTRUEを返す。
  */
-static bool kind_is_good(int k_idx)
+static bool kind_is_good(KIND_OBJECT_IDX k_idx)
 {
        object_kind *k_ptr = &k_info[k_idx];
 
@@ -4756,10 +4789,10 @@ static bool kind_is_good(int k_idx)
  * This routine uses "object_level" for the "generation level".\n
  * We assume that the given object has been "wiped".\n
  */
-bool make_object(object_type *j_ptr, u32b mode)
+bool make_object(object_type *j_ptr, BIT_FLAGS mode)
 {
-       int prob, base;
-       byte obj_level;
+       PERCENTAGE prob;
+       DEPTH base;
 
 
        /* Chance of "special object" */
@@ -4772,7 +4805,7 @@ bool make_object(object_type *j_ptr, u32b mode)
        /* Generate a special object, or a normal object */
        if (!one_in_(prob) || !make_artifact_special(j_ptr))
        {
-               int k_idx;
+               KIND_OBJECT_IDX k_idx;
 
                /* Good objects */
                if ((mode & AM_GOOD) && !get_obj_num_hook)
@@ -4820,9 +4853,6 @@ bool make_object(object_type *j_ptr, u32b mode)
                }
        }
 
-       obj_level = k_info[j_ptr->k_idx].level;
-       if (object_is_fixed_artifact(j_ptr)) obj_level = a_info[j_ptr->name1].level;
-
        if (cheat_peek) object_mention(j_ptr);
 
        /* Success */
@@ -4842,9 +4872,9 @@ bool make_object(object_type *j_ptr, u32b mode)
  * This routine uses "object_level" for the "generation level".\n
  * This routine requires a clean floor grid destination.\n
  */
-void place_object(int y, int x, u32b mode)
+void place_object(POSITION y, POSITION x, BIT_FLAGS mode)
 {
-       s16b o_idx;
+       OBJECT_IDX o_idx;
 
        /* Acquire grid */
        cave_type *c_ptr = &cave[y][x];
@@ -4862,11 +4892,7 @@ void place_object(int y, int x, u32b mode)
        /* Avoid stacking on other objects */
        if (c_ptr->o_idx) return;
 
-
-       /* Get local object */
        q_ptr = &forge;
-
-       /* Wipe the object */
        object_wipe(q_ptr);
 
        /* Make an object (if possible) */
@@ -4880,14 +4906,11 @@ void place_object(int y, int x, u32b 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;
 
@@ -4897,10 +4920,8 @@ void place_object(int y, int x, u32b mode)
                /* Place the object */
                c_ptr->o_idx = o_idx;
 
-               /* Notice */
                note_spot(y, x);
 
-               /* Redraw */
                lite_spot(y, x);
        }
        else
@@ -4925,10 +4946,8 @@ void place_object(int y, int x, u32b 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;
 
@@ -4948,7 +4967,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));
@@ -4967,14 +4986,13 @@ bool make_gold(object_type *j_ptr)
  * @details
  * The location must be a legal, clean, floor grid.
  */
-void place_gold(int y, int x)
+void place_gold(POSITION y, POSITION x)
 {
-       s16b o_idx;
+       OBJECT_IDX o_idx;
 
        /* Acquire grid */
        cave_type *c_ptr = &cave[y][x];
 
-
        object_type forge;
        object_type *q_ptr;
 
@@ -4988,17 +5006,12 @@ void place_gold(int y, int x)
        /* Avoid stacking on other objects */
        if (c_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();
 
@@ -5006,8 +5019,6 @@ void place_gold(int y, int x)
        if (o_idx)
        {
                object_type *o_ptr;
-
-               /* Acquire object */
                o_ptr = &o_list[o_idx];
 
                /* Copy the object */
@@ -5023,10 +5034,8 @@ void place_gold(int y, int x)
                /* Place the object */
                c_ptr->o_idx = o_idx;
 
-               /* Notice */
                note_spot(y, x);
 
-               /* Redraw */
                lite_spot(y, x);
        }
 }
@@ -5039,7 +5048,7 @@ void place_gold(int y, int 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
@@ -5054,18 +5063,17 @@ void place_gold(int y, int 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;
 
@@ -5086,15 +5094,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)"));
 
@@ -5127,7 +5131,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;
 
@@ -5150,8 +5153,6 @@ s16b drop_near(object_type *j_ptr, int chance, int y, int x)
                        for (this_o_idx = c_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 */
@@ -5189,7 +5190,6 @@ s16b drop_near(object_type *j_ptr, int chance, int y, int x)
                        by = ty;
                        bx = tx;
 
-                       /* Okay */
                        flag = TRUE;
                }
        }
@@ -5198,12 +5198,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
 
 
@@ -5232,7 +5230,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;
        }
 
@@ -5253,7 +5250,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
@@ -5309,8 +5305,6 @@ s16b drop_near(object_type *j_ptr, int chance, int y, int x)
        for (this_o_idx = c_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 */
@@ -5325,7 +5319,6 @@ s16b drop_near(object_type *j_ptr, int chance, int y, int x)
                        /* Success */
                        done = TRUE;
 
-                       /* Done */
                        break;
                }
        }
@@ -5336,7 +5329,6 @@ s16b drop_near(object_type *j_ptr, int chance, int y, int x)
        /* Failure */
        if (!done && !o_idx)
        {
-               /* Message */
 #ifdef JP
                msg_format("%sは消えた。", o_name);
 #else
@@ -5390,7 +5382,6 @@ s16b drop_near(object_type *j_ptr, int chance, int y, int x)
        /* Draw the spot */
        lite_spot(by, bx);
 
-       /* Sound */
        sound(SOUND_DROP);
 
        /* Mega-Hack -- no message if "dropped" by player */
@@ -5400,9 +5391,6 @@ 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);
 }
 
@@ -5418,19 +5406,16 @@ s16b drop_near(object_type *j_ptr, int chance, int y, int x)
  * @param known TRUEならばオブジェクトが必ず*鑑定*済になる
  * @return なし
  */
-void acquirement(int y1, int x1, int num, bool great, bool special, bool known)
+void acquirement(POSITION y1, POSITION x1, int num, bool great, bool special, bool known)
 {
        object_type *i_ptr;
        object_type object_type_body;
-       u32b mode = AM_GOOD | (great || special ? AM_GREAT : 0L) | (special ? AM_SPECIAL : 0L) ;
+       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) */
@@ -5459,9 +5444,9 @@ void acquirement(int y1, int x1, int num, bool great, bool special, bool known)
 
 typedef struct
 {
-       int tval;
-       int sval;
-       int prob;
+       OBJECT_TYPE_VALUE tval;
+       OBJECT_SUBTYPE_VALUE sval;
+       PERCENTAGE prob;
        byte flag;
 } amuse_type;
 
@@ -5492,7 +5477,7 @@ amuse_type amuse_info[] =
  * @param known TRUEならばオブジェクトが必ず*鑑定*済になる
  * @return なし
  */
-void amusement(int y1, int x1, int num, bool known)
+void amusement(POSITION y1, POSITION x1, int num, bool known)
 {
        object_type *i_ptr;
        object_type object_type_body;
@@ -5506,7 +5491,9 @@ void amusement(int y1, int x1, int num, bool known)
        /* Acquirement */
        while (num)
        {
-               int i, k_idx, a_idx = 0;
+               int i;
+               KIND_OBJECT_IDX k_idx;
+               ARTIFACT_IDX a_idx = 0;
                int r = randint0(t);
                bool insta_art, fixed_art;
 
@@ -5515,14 +5502,8 @@ void amusement(int y1, int x1, int num, bool known)
                        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 */
@@ -5576,135 +5557,13 @@ void amusement(int y1, int x1, int num, bool known)
 }
 
 
-#define MAX_NORMAL_TRAPS 18
-
-/* See init_feat_variables() in init2.c */
-static s16b normal_traps[MAX_NORMAL_TRAPS];
-
-/*!
- * @brief タグに従って、基本トラップテーブルを初期化する / Initialize arrays for normal traps
- * @return なし
- */
-void init_normal_traps(void)
-{
-       int cur_trap = 0;
-
-       normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_TRAPDOOR");
-       normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_PIT");
-       normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_SPIKED_PIT");
-       normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_POISON_PIT");
-       normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_TY_CURSE");
-       normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_TELEPORT");
-       normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_FIRE");
-       normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_ACID");
-       normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_SLOW");
-       normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_LOSE_STR");
-       normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_LOSE_DEX");
-       normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_LOSE_CON");
-       normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_BLIND");
-       normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_CONFUSE");
-       normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_POISON");
-       normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_SLEEP");
-       normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_TRAPS");
-       normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_ALARM");
-}
-
-/*!
- * @brief 基本トラップをランダムに選択する /
- * Get random trap
- * @return 選択したトラップのID
- * @details
- * XXX XXX XXX This routine should be redone to reflect trap "level".\n
- * That is, it does not make sense to have spiked pits at 50 feet.\n
- * Actually, it is not this routine, but the "trap instantiation"\n
- * code, which should also check for "trap doors" on quest levels.\n
- */
-s16b choose_random_trap(void)
-{
-       s16b feat;
-
-       /* Pick a trap */
-       while (1)
-       {
-               /* Hack -- pick a trap */
-               feat = normal_traps[randint0(MAX_NORMAL_TRAPS)];
-
-               /* Accept non-trapdoors */
-               if (!have_flag(f_info[feat].flags, FF_MORE)) break;
-
-               /* Hack -- no trap doors on special levels */
-               if (p_ptr->inside_arena || quest_number(dun_level)) continue;
-
-               /* Hack -- no trap doors on the deepest level */
-               if (dun_level >= d_info[dungeon_type].maxdepth) continue;
-
-               break;
-       }
-
-       return feat;
-}
-
-/*!
- * @brief マスに存在するトラップを秘匿する /
- * Disclose an invisible trap
- * @param y 秘匿したいマスのY座標
- * @param x 秘匿したいマスのX座標
- * @return なし
- */
-void disclose_grid(int y, int x)
-{
-       cave_type *c_ptr = &cave[y][x];
-
-       if (cave_have_flag_grid(c_ptr, FF_SECRET))
-       {
-               /* No longer hidden */
-               cave_alter_feat(y, x, FF_SECRET);
-       }
-       else if (c_ptr->mimic)
-       {
-               /* No longer hidden */
-               c_ptr->mimic = 0;
-
-               /* Notice */
-               note_spot(y, x);
-
-               /* Redraw */
-               lite_spot(y, x);
-       }
-}
-
-/*!
- * @brief マスをトラップを配置する /
- * The location must be a legal, naked, floor grid.
- * @param y 配置したいマスのY座標
- * @param x 配置したいマスのX座標
- * @return
- * Note that all traps start out as "invisible" and "untyped", and then\n
- * when they are "discovered" (by detecting them or setting them off),\n
- * the trap is "instantiated" as a visible, "typed", trap.\n
- */
-void place_trap(int y, int x)
-{
-       cave_type *c_ptr = &cave[y][x];
-
-       /* Paranoia -- verify location */
-       if (!in_bounds(y, x)) return;
-
-       /* Require empty, clean, floor grid */
-       if (!cave_clean_bold(y, x)) return;
-
-       /* Place an invisible trap */
-       c_ptr->mimic = c_ptr->feat;
-       c_ptr->feat = choose_random_trap();
-}
-
 /*!
  * @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];
 
@@ -5727,14 +5586,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
@@ -5747,15 +5604,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];
 
-       /* Get a description */
        object_desc(o_name, o_ptr, 0);
 
-       /* Print a message */
 #ifdef JP
        /* "no more" の場合はこちらで表示する */
        if (o_ptr->number <= 0)
@@ -5775,13 +5630,13 @@ void inven_item_describe(int item)
 }
 
 /*!
- * @brief ã\82¢ã\82¤ã\83\86ã\83 ã\81®残り所持数メッセージを表示する /
+ * @brief ã\82¢ã\82¤ã\83\86ã\83 ã\82\92å¢\97ã\82\84ã\81\97残り所持数メッセージを表示する /
  * 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, int num)
 {
        object_type *o_ptr = &inventory[item];
 
@@ -5793,7 +5648,7 @@ void inven_item_increase(int item, int num)
        else if (num < 0) num = 0;
 
        /* Un-apply */
-       num -= o_ptr->number;
+       num -= (ITEM_NUMBER)o_ptr->number;
 
        /* Change the number and weight */
        if (num)
@@ -5813,7 +5668,6 @@ void inven_item_increase(int item, int num)
                /* Combine the pack */
                p_ptr->notice |= (PN_COMBINE);
 
-               /* Window stuff */
                p_ptr->window |= (PW_INVEN | PW_EQUIP);
 
                /* Hack -- Clear temporary elemental brands if player takes off weapons */
@@ -5837,7 +5691,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];
 
@@ -5865,7 +5719,6 @@ void inven_item_optimize(int item)
                /* Erase the "final" slot */
                object_wipe(&inventory[i]);
 
-               /* Window stuff */
                p_ptr->window |= (PW_INVEN);
        }
 
@@ -5887,11 +5740,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);
 }
 
@@ -5901,7 +5752,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];
 
@@ -5924,14 +5775,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
@@ -5944,15 +5793,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];
 
-       /* Get a description */
        object_desc(o_name, o_ptr, 0);
 
-       /* Print a message */
 #ifdef JP
        /* "no more" の場合はこちらで表示を分ける */
        if (o_ptr->number <= 0)
@@ -5977,7 +5824,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, int num)
 {
        object_type *o_ptr = &o_list[item];
 
@@ -5989,10 +5836,10 @@ void floor_item_increase(int item, int num)
        else if (num < 0) num = 0;
 
        /* Un-apply */
-       num -= o_ptr->number;
+       num -= (int)o_ptr->number;
 
        /* Change the number */
-       o_ptr->number += num;
+       o_ptr->number += (ITEM_NUMBER)num;
 }
 
 
@@ -6002,7 +5849,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];
 
@@ -6012,7 +5859,6 @@ void floor_item_optimize(int item)
        /* Only optimize empty items */
        if (o_ptr->number) return;
 
-       /* Delete the object */
        delete_object_idx(item);
 }
 
@@ -6042,7 +5888,6 @@ bool inven_carry_okay(object_type *o_ptr)
                if (object_similar(j_ptr, o_ptr)) return (TRUE);
        }
 
-       /* Nope */
        return (FALSE);
 }
 
@@ -6157,8 +6002,8 @@ bool object_sort_comp(object_type *o_ptr, s32b o_value, object_type *j_ptr)
  */
 s16b inven_carry(object_type *o_ptr)
 {
-       int i, j, k;
-       int n = -1;
+       INVENTORY_IDX i, j, k;
+       INVENTORY_IDX n = -1;
 
        object_type *j_ptr;
 
@@ -6186,7 +6031,6 @@ s16b inven_carry(object_type *o_ptr)
                        /* Recalculate bonuses */
                        p_ptr->update |= (PU_BONUS);
 
-                       /* Window stuff */
                        p_ptr->window |= (PW_INVEN);
 
                        /* Success */
@@ -6268,7 +6112,6 @@ s16b inven_carry(object_type *o_ptr)
        /* Combine and Reorder pack */
        p_ptr->notice |= (PN_COMBINE | PN_REORDER);
 
-       /* Window stuff */
        p_ptr->window |= (PW_INVEN);
 
        /* Return the slot */
@@ -6288,9 +6131,9 @@ s16b inven_carry(object_type *o_ptr)
  * to fall to the ground.\n
  * Return the inventory slot into which the item is placed.\n
  */
-s16b inven_takeoff(int item, int amt)
+INVENTORY_IDX inven_takeoff(INVENTORY_IDX item, ITEM_NUMBER amt)
 {
-       int slot;
+       INVENTORY_IDX slot;
 
        object_type forge;
        object_type *q_ptr;
@@ -6310,8 +6153,6 @@ s16b inven_takeoff(int item, int amt)
 
        /* Verify */
        if (amt > o_ptr->number) amt = o_ptr->number;
-
-       /* Get local object */
        q_ptr = &forge;
 
        /* Obtain a local object */
@@ -6320,7 +6161,6 @@ s16b inven_takeoff(int item, int amt)
        /* Modify quantity */
        q_ptr->number = amt;
 
-       /* Describe the object */
        object_desc(o_name, q_ptr, 0);
 
        /* Took off weapon */
@@ -6355,7 +6195,6 @@ s16b inven_takeoff(int item, int 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
@@ -6377,11 +6216,10 @@ s16b inven_takeoff(int item, int amt)
  * @details
  * The object will be dropped "near" the current location
  */
-void inven_drop(int item, int amt)
+void inven_drop(INVENTORY_IDX item, ITEM_NUMBER amt)
 {
        object_type forge;
        object_type *q_ptr;
-
        object_type *o_ptr;
 
        char o_name[MAX_NLEN];
@@ -6407,8 +6245,6 @@ void inven_drop(int item, int amt)
                o_ptr = &inventory[item];
        }
 
-
-       /* Get local object */
        q_ptr = &forge;
 
        /* Obtain local object */
@@ -6423,7 +6259,6 @@ void inven_drop(int item, int 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 */
@@ -6457,7 +6292,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 */
@@ -6468,7 +6302,6 @@ void combine_pack(void)
                        {
                                int max_num;
 
-                               /* Get the item */
                                j_ptr = &inventory[j];
 
                                /* Skip empty items */
@@ -6530,13 +6363,11 @@ void combine_pack(void)
                                                }
                                        }
 
-                                       /* Window stuff */
                                        p_ptr->window |= (PW_INVEN);
 
                                        /* Take note */
                                        combined = TRUE;
 
-                                       /* Done */
                                        break;
                                }
                        }
@@ -6544,7 +6375,6 @@ void combine_pack(void)
        }
        while (combined);
 
-       /* Message */
        if (flag) msg_print(_("ザックの中のアイテムをまとめ直した。", "You combine some items in your pack."));
 }
 
@@ -6571,7 +6401,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 */
@@ -6591,8 +6420,6 @@ void reorder_pack(void)
 
                /* Take note */
                flag = TRUE;
-
-               /* Get local object */
                q_ptr = &forge;
 
                /* Save a copy of the moving item */
@@ -6608,11 +6435,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."));
 }
 
@@ -6624,14 +6449,14 @@ void reorder_pack(void)
  * @details
  * Include list of usable spells for readible books
  */
-void display_koff(int k_idx)
+void display_koff(KIND_OBJECT_IDX k_idx)
 {
        int y;
 
        object_type forge;
        object_type *q_ptr;
        int         sval;
-       int         use_realm;
+       REALM_IDX   use_realm;
 
        char o_name[MAX_NLEN];
 
@@ -6645,14 +6470,10 @@ void display_koff(int 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 */
@@ -6678,7 +6499,7 @@ void display_koff(int k_idx)
        {
                int     spell = -1;
                int     num = 0;
-               byte    spells[64];
+               SPELL_IDX    spells[64];
 
                /* Extract spells */
                for (spell = 0; spell < 32; spell++)
@@ -6714,7 +6535,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);
@@ -6738,7 +6559,7 @@ object_type *choose_warning_item(void)
  * @param max 算出した最大ダメージを返すポインタ
  * @return なし
  */
-static void spell_damcalc(monster_type *m_ptr, int typ, int 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;
@@ -6983,10 +6804,10 @@ static void spell_damcalc(monster_type *m_ptr, int typ, int dam, int *max)
 * @param max 算出した最大ダメージを返すポインタ
 * @return なし
 */
-void spell_damcalc_by_spellnum(int spell_num, int typ, int 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];
-    int dam = monspell_damage((spell_num), m_idx, DAM_MAX);
+    HIT_POINT dam = monspell_damage((spell_num), m_idx, DAM_MAX);
     spell_damcalc(m_ptr, typ, dam, max);
 }
 
@@ -7005,7 +6826,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)
                {
@@ -7074,9 +6895,9 @@ 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;
+       POSITION mx, my;
        cave_type *c_ptr;
        char o_name[MAX_NLEN];
 
@@ -7108,42 +6929,42 @@ 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 (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, 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_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, 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);
                        }
 
                        /* Monster melee attacks */
@@ -7186,7 +7007,7 @@ 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? "));
                }
        }
@@ -7203,7 +7024,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? "));
        }
 
@@ -7211,40 +7032,12 @@ bool process_warning(int xx, int yy)
 }
 
 /*!
- * @brief エッセンスの付加可能な武器や矢弾かを返す
- * @param o_ptr チェックしたいオブジェクトの構造体参照ポインタ
- * @return エッセンスの付加可能な武器か矢弾ならばTRUEを返す。
- */
-static bool item_tester_hook_melee_ammo(object_type *o_ptr)
-{
-       switch (o_ptr->tval)
-       {
-               case TV_HAFTED:
-               case TV_POLEARM:
-               case TV_DIGGING:
-               case TV_BOLT:
-               case TV_ARROW:
-               case TV_SHOT:
-               {
-                       return (TRUE);
-               }
-               case TV_SWORD:
-               {
-                       if (o_ptr->sval != SV_DOKUBARI) return (TRUE);
-               }
-       }
-
-       return (FALSE);
-}
-
-
-/*!
  * エッセンス情報の構造体 / A structure for smithing
  */
 typedef struct {
        int add;       /* TR flag number or special essence id */
        cptr add_name; /* Name of this ability */
-       int type;      /* Menu number */
+       ESSENCE_IDX type;      /* Menu number */
        int essence;   /* Index for carrying essences */
        int value;     /* Needed value to add this ability */
 } essence_type;
@@ -7721,15 +7514,20 @@ static void display_essence(void)
 static void drain_essence(void)
 {
        int drain_value[sizeof(p_ptr->magic_num1) / sizeof(s32b)];
-       int i, item;
+       int i;
+       OBJECT_IDX item;
        int dec = 4;
        bool observe = FALSE;
-       int old_ds, old_dd, old_to_h, old_to_d, old_ac, old_to_a, old_pval, old_name2, old_timeout;
-       u32b old_flgs[TR_FLAG_SIZE], new_flgs[TR_FLAG_SIZE];
+       int old_ds, old_dd, old_to_h, old_to_d, old_ac, old_to_a, old_pval, old_name2;
+       TIME_EFFECT old_timeout;
+       BIT_FLAGS old_flgs[TR_FLAG_SIZE], new_flgs[TR_FLAG_SIZE];
        object_type *o_ptr;
-       cptr            q, s;
-       byte iy, ix, marked, number;
-       s16b next_o_idx, weight;
+       cptr q, s;
+       POSITION iy, ix;
+       byte_hack marked;
+       ITEM_NUMBER number;
+       OBJECT_IDX next_o_idx;
+       WEIGHT weight;
 
        for (i = 0; i < sizeof(drain_value) / sizeof(int); i++)
                drain_value[i] = 0;
@@ -7737,7 +7535,6 @@ static void drain_essence(void)
        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.");
 
@@ -7829,7 +7626,7 @@ static void drain_essence(void)
        for (i = 0; essence_info[i].add_name; i++)
        {
                essence_type *es_ptr = &essence_info[i];
-               int pval = 0;
+               PARAMETER_VALUE pval = 0;
 
                if (es_ptr->add < TR_FLAG_MAX && is_pval_flag(es_ptr->add) && old_pval)
                        pval = (have_flag(new_flgs, es_ptr->add)) ? old_pval - o_ptr->pval : old_pval;
@@ -7949,7 +7746,6 @@ static void drain_essence(void)
        /* Combine the pack */
        p_ptr->notice |= (PN_COMBINE | PN_REORDER);
 
-       /* Window stuff */
        p_ptr->window |= (PW_INVEN);
 }
 
@@ -7957,11 +7753,11 @@ static void drain_essence(void)
  * @brief 付加するエッセンスの大別を選択する
  * @return 選んだエッセンスの大別ID
  */
-static int choose_essence(void)
+static COMMAND_CODE choose_essence(void)
 {
-       int mode = 0;
+       COMMAND_CODE mode = 0;
        char choice;
-       int menu_line = (use_menu ? 1 : 0);
+       COMMAND_CODE menu_line = (use_menu ? 1 : 0);
 
 #ifdef JP
        cptr menu_name[] = {
@@ -7984,14 +7780,11 @@ static int choose_essence(void)
                "Others"
        };
 #endif
-       const int mode_max = 7;
+       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();
@@ -8053,7 +7846,7 @@ static int choose_essence(void)
                                return 0;
                        }
 
-                       if (isupper(choice)) choice = tolower(choice);
+                       if (isupper(choice)) choice = (char)tolower(choice);
 
                        if ('a' <= choice && choice <= 'a' + (char)mode_max - 1)
                                mode = (int)choice - 'a' + 1;
@@ -8061,9 +7854,7 @@ static int choose_essence(void)
                screen_load();
        }
 
-#ifdef ALLOW_REPEAT
        repeat_push(mode);
-#endif /* ALLOW_REPEAT */
        return mode;
 }
 
@@ -8072,10 +7863,11 @@ static int choose_essence(void)
  * @param mode エッセンスの大別ID
  * @return なし
  */
-static void add_essence(int mode)
+static void add_essence(ESSENCE_IDX mode)
 {
-       int item, max_num = 0;
-       int i;
+       OBJECT_IDX item;
+       int max_num = 0;
+       COMMAND_CODE i;
        bool flag,redraw;
        char choice;
        cptr            q, s;
@@ -8086,6 +7878,7 @@ static void add_essence(int mode)
        char o_name[MAX_NLEN];
        int use_essence;
        essence_type *es_ptr;
+       bool able[22] = { 0 };
 
        int menu_line = (use_menu ? 1 : 0);
 
@@ -8097,11 +7890,8 @@ static void add_essence(int 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;
@@ -8118,7 +7908,6 @@ static void add_essence(int mode)
        choice = (always_show_list || use_menu) ? ESCAPE:1;
        while (!flag)
        {
-               bool able[22];
                if( choice==ESCAPE ) choice = ' '; 
                else if( !get_com(out_val, &choice, FALSE) )break; 
 
@@ -8303,7 +8092,7 @@ static void add_essence(int mode)
                        ask = (isupper(choice));
 
                        /* Lowercase */
-                       if (ask) choice = tolower(choice);
+                       if (ask) choice = (char)tolower(choice);
 
                        /* Extract request */
                        i = (islower(choice) ? A2I(choice) : -1);
@@ -8337,11 +8126,8 @@ static void add_essence(int mode)
 
        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)
@@ -8356,7 +8142,6 @@ static void add_essence(int mode)
                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.");
 
@@ -8423,14 +8208,14 @@ static void add_essence(int mode)
                        {
                                char tmp[80];
                                char tmp_val[160];
-                               int pval;
-                               int limit = MIN(5, p_ptr->magic_num1[es_ptr->essence]/es_ptr->value);
+                               PARAMETER_VALUE pval;
+                               PARAMETER_VALUE limit = MIN(5, p_ptr->magic_num1[es_ptr->essence]/es_ptr->value);
 
                                sprintf(tmp, _("いくつ付加しますか? (1-%d): ", "Enchant how many? (1-%d): "), limit);
                                strcpy(tmp_val, "1");
 
                                if (!get_string(tmp, tmp_val, 1)) return;
-                               pval = atoi(tmp_val);
+                               pval = (PARAMETER_VALUE)atoi(tmp_val);
                                if (pval > limit) pval = limit;
                                else if (pval < 1) pval = 1;
                                o_ptr->pval += pval;
@@ -8448,7 +8233,8 @@ static void add_essence(int mode)
                {
                        char tmp_val[160];
                        int val;
-                       int get_to_h, get_to_d;
+                       HIT_PROB get_to_h;
+                       HIT_POINT get_to_d;
 
                        strcpy(tmp_val, "1");
                        if (!get_string(format(_("いくつ付加しますか? (1-%d):", "Enchant how many? (1-%d):"), p_ptr->lev/7+3), tmp_val, 2)) return;
@@ -8576,7 +8362,6 @@ static void add_essence(int mode)
        /* Combine the pack */
        p_ptr->notice |= (PN_COMBINE | PN_REORDER);
 
-       /* Window stuff */
        p_ptr->window |= (PW_INVEN);
 }
 
@@ -8586,15 +8371,14 @@ static void add_essence(int mode)
  */
 static void erase_essence(void)
 {
-       int item;
+       OBJECT_IDX item;
        cptr q, s;
        object_type *o_ptr;
        char o_name[MAX_NLEN];
-       u32b flgs[TR_FLAG_SIZE];
+       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.");
 
@@ -8633,7 +8417,6 @@ static void erase_essence(void)
        /* Combine the pack */
        p_ptr->notice |= (PN_COMBINE | PN_REORDER);
 
-       /* Window stuff */
        p_ptr->window |= (PW_INVEN);
 }
 
@@ -8644,10 +8427,10 @@ static void erase_essence(void)
  */
 void do_cmd_kaji(bool only_browse)
 {
-       int mode = 0;
+       COMMAND_CODE mode = 0;
        char choice;
 
-       int menu_line = (use_menu ? 1 : 0);
+       COMMAND_CODE menu_line = (use_menu ? 1 : 0);
 
        if (!only_browse)
        {
@@ -8668,11 +8451,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();
@@ -8728,19 +8508,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
                        {
@@ -8796,11 +8571,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;
@@ -8824,7 +8596,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))
        {
@@ -8845,7 +8617,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))
        {