OSDN Git Service

[Refactor] #37353 cmd1~melee1間整理。 / Refactor between cmd1 and melee1.
[hengband/hengband.git] / src / object2.c
index 1692213..b800143 100644 (file)
@@ -13,6 +13,9 @@
 
 #include "angband.h"
 
+static void one_sustain(object_type *o_ptr);
+
+
 static cptr const kaji_tips[5] =
 {
 #ifdef JP
@@ -31,6 +34,25 @@ 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 なし
@@ -345,7 +367,8 @@ static void compact_objects_aux(IDX i1, IDX i2)
  */
 void compact_objects(int size)
 {
-       int i, y, x, num, cnt;
+       IDX i;
+       int y, x, num, cnt;
        int cur_lev, cur_dis, chance;
        object_type *o_ptr;
 
@@ -530,9 +553,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)
+IDX o_pop(void)
 {
-       int i;
+       IDX i;
 
 
        /* Initial allocation */
@@ -1854,11 +1877,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++)
@@ -1932,7 +1955,7 @@ void object_copy(object_type *o_ptr, object_type *j_ptr)
  * @param k_idx 新たに作成したいベースアイテム情報のID
  * @return なし
  */
-void object_prep(object_type *o_ptr, IDX k_idx)
+void object_prep(object_type *o_ptr, KIND_OBJECT_IDX k_idx)
 {
        object_kind *k_ptr = &k_info[k_idx];
 
@@ -1966,7 +1989,7 @@ void object_prep(object_type *o_ptr, IDX 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);
@@ -2024,7 +2047,7 @@ void object_prep(object_type *o_ptr, IDX 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;
 
@@ -2100,8 +2123,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;
+       IDX k_idx = 0;
 
        /*! @note 地上ではキャンセルする / No artifacts in the town */
        if (!dun_level) return (FALSE);
@@ -2169,7 +2192,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 */
@@ -2280,13 +2303,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)
 {
-       HIT_PROB tohit1 = randint1(5) + m_bonus(5, level);
-       HIT_POINT 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);
 
-       HIT_PROB tohit2 = m_bonus(10, level);
-       HIT_POINT 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))
        {
@@ -2451,13 +2474,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))
@@ -2670,8 +2693,8 @@ static void add_esp_weak(object_type *o_ptr, bool extra)
  */
 static void a_m_aux_2(object_type *o_ptr, int level, int power)
 {
-       ARMOUR_CLASS toac1 = randint1(5) + m_bonus(5, level);
-       ARMOUR_CLASS 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)
@@ -3100,7 +3123,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);
@@ -3149,7 +3172,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;
 
@@ -3180,7 +3203,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)
@@ -3202,7 +3225,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++;
@@ -3234,7 +3257,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;
 
@@ -3248,7 +3271,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)
@@ -3273,7 +3296,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;
                                }
 
@@ -3288,7 +3311,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;
@@ -3304,8 +3327,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;
@@ -3315,7 +3338,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)
@@ -3337,7 +3360,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)
@@ -3359,7 +3382,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)
@@ -3381,8 +3404,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)
@@ -3403,7 +3426,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 */
@@ -3640,7 +3663,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)
@@ -3699,7 +3722,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)
@@ -3720,8 +3743,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);
@@ -3739,8 +3762,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;
@@ -3748,7 +3771,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)
@@ -3920,7 +3943,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];
 
@@ -4113,7 +4136,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;
@@ -4194,7 +4217,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;
@@ -4249,7 +4272,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;
 
@@ -4514,7 +4537,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)))
@@ -4660,7 +4683,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];
 
@@ -4751,10 +4774,9 @@ 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;
 
 
        /* Chance of "special object" */
@@ -4767,7 +4789,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;
+               IDX k_idx;
 
                /* Good objects */
                if ((mode & AM_GOOD) && !get_obj_num_hook)
@@ -4815,9 +4837,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 */
@@ -4837,7 +4856,7 @@ 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(POSITION y, POSITION x, u32b mode)
+void place_object(POSITION y, POSITION x, BIT_FLAGS mode)
 {
        IDX o_idx;
 
@@ -5417,7 +5436,7 @@ void acquirement(int y1, int 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--)
@@ -5454,8 +5473,8 @@ void acquirement(int y1, int x1, int num, bool great, bool special, bool known)
 
 typedef struct
 {
-       int tval;
-       int sval;
+       OBJECT_TYPE_VALUE tval;
+       OBJECT_SUBTYPE_VALUE sval;
        int prob;
        byte flag;
 } amuse_type;
@@ -5501,7 +5520,8 @@ void amusement(int y1, int x1, int num, bool known)
        /* Acquirement */
        while (num)
        {
-               int i, k_idx, a_idx = 0;
+               int i;
+               IDX k_idx, a_idx = 0;
                int r = randint0(t);
                bool insta_art, fixed_art;
 
@@ -6152,8 +6172,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;
 
@@ -6283,9 +6303,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;
@@ -6372,11 +6392,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];
@@ -6619,14 +6638,14 @@ void reorder_pack(void)
  * @details
  * Include list of usable spells for readible books
  */
-void display_koff(int k_idx)
+void display_koff(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];
 
@@ -6673,7 +6692,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++)
@@ -6733,7 +6752,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, int typ, HIT_POINT dam, int *max)
 {
        monster_race *r_ptr = &r_info[m_ptr->r_idx];
        int          rlev = r_ptr->level;
@@ -6978,10 +6997,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, int 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);
 }
 
@@ -7239,7 +7258,7 @@ static bool item_tester_hook_melee_ammo(object_type *o_ptr)
 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;
@@ -7716,16 +7735,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;
        POSITION iy, ix;
-       byte_hack marked, number;
-       s16b next_o_idx, weight;
+       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;
@@ -7825,7 +7848,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;
@@ -7953,11 +7976,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[] = {
@@ -7980,7 +8003,7 @@ 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)
@@ -8049,7 +8072,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;
@@ -8068,10 +8091,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;
@@ -8114,7 +8138,7 @@ static void add_essence(int mode)
        choice = (always_show_list || use_menu) ? ESCAPE:1;
        while (!flag)
        {
-               bool able[22];
+               bool able[22] = {0};
                if( choice==ESCAPE ) choice = ' '; 
                else if( !get_com(out_val, &choice, FALSE) )break; 
 
@@ -8299,7 +8323,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);
@@ -8419,14 +8443,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;
@@ -8583,11 +8607,11 @@ 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;
 
@@ -8641,10 +8665,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)
        {