OSDN Git Service

[Refactor] #37353 コメント整理。 / Refactor comments.
[hengband/hengband.git] / src / object2.c
index 99232bb..720a9cb 100644 (file)
@@ -45,7 +45,7 @@ static concptr const kaji_tips[5] =
  */
 static void one_sustain(object_type *o_ptr)
 {
-       switch (randint0(6))
+       switch (randint0(A_MAX))
        {
        case 0: add_flag(o_ptr->art_flags, TR_SUST_STR); break;
        case 1: add_flag(o_ptr->art_flags, TR_SUST_INT); break;
@@ -123,15 +123,15 @@ void excise_object_idx(OBJECT_IDX o_idx)
        /* Dungeon */
        else
        {
-               cave_type *c_ptr;
+               grid_type *g_ptr;
 
                POSITION y = j_ptr->iy;
                POSITION x = j_ptr->ix;
 
-               c_ptr = &cave[y][x];
+               g_ptr = &grid_array[y][x];
 
                /* Scan all objects in the grid */
-               for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
+               for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
                {
                        object_type *o_ptr;
                        o_ptr = &o_list[this_o_idx];
@@ -145,7 +145,7 @@ void excise_object_idx(OBJECT_IDX o_idx)
                                if (prev_o_idx == 0)
                                {
                                        /* Remove from list */
-                                       c_ptr->o_idx = next_o_idx;
+                                       g_ptr->o_idx = next_o_idx;
                                }
 
                                /* Real previous */
@@ -217,16 +217,16 @@ void delete_object_idx(OBJECT_IDX o_idx)
  */
 void delete_object(POSITION y, POSITION x)
 {
-       cave_type *c_ptr;
+       grid_type *g_ptr;
        OBJECT_IDX this_o_idx, next_o_idx = 0;
 
        /* Refuse "illegal" locations */
        if (!in_bounds(y, x)) return;
 
-       c_ptr = &cave[y][x];
+       g_ptr = &grid_array[y][x];
 
        /* Scan all objects in the grid */
-       for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
+       for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
        {
                object_type *o_ptr;
                o_ptr = &o_list[this_o_idx];
@@ -240,7 +240,7 @@ void delete_object(POSITION y, POSITION x)
        }
 
        /* Objects are gone */
-       c_ptr->o_idx = 0;
+       g_ptr->o_idx = 0;
 
        /* Visual update */
        lite_spot(y, x);
@@ -257,7 +257,7 @@ void delete_object(POSITION y, POSITION x)
 static void compact_objects_aux(OBJECT_IDX i1, OBJECT_IDX i2)
 {
        OBJECT_IDX i;
-       cave_type *c_ptr;
+       grid_type *g_ptr;
        object_type *o_ptr;
 
        /* Do nothing */
@@ -306,13 +306,13 @@ static void compact_objects_aux(OBJECT_IDX i1, OBJECT_IDX i2)
                x = o_ptr->ix;
 
                /* Acquire grid */
-               c_ptr = &cave[y][x];
+               g_ptr = &grid_array[y][x];
 
                /* Repair grid */
-               if (c_ptr->o_idx == i1)
+               if (g_ptr->o_idx == i1)
                {
                        /* Repair */
-                       c_ptr->o_idx = i2;
+                       g_ptr->o_idx = i2;
                }
        }
 
@@ -442,7 +442,7 @@ void compact_objects(int size)
  * Delete all the items when player leaves the level
  * @note we do NOT visually reflect these (irrelevant) changes
  * @details
- * Hack -- we clear the "c_ptr->o_idx" field for every grid,
+ * Hack -- we clear the "g_ptr->o_idx" field for every grid,
  * and the "m_ptr->next_o_idx" field for every monster, since
  * we know we are clearing every object.  Technically, we only
  * clear those fields for grids/monsters containing objects,
@@ -487,17 +487,17 @@ void wipe_o_list(void)
                /* Dungeon */
                else
                {
-                       cave_type *c_ptr;
+                       grid_type *g_ptr;
 
                        /* Access location */
                        POSITION y = o_ptr->iy;
                        POSITION x = o_ptr->ix;
 
                        /* Access grid */
-                       c_ptr = &cave[y][x];
+                       g_ptr = &grid_array[y][x];
 
                        /* Hack -- see above */
-                       c_ptr->o_idx = 0;
+                       g_ptr->o_idx = 0;
                }
                object_wipe(o_ptr);
        }
@@ -628,7 +628,7 @@ OBJECT_IDX get_obj_num(DEPTH level)
        if (level > MAX_DEPTH - 1) level = MAX_DEPTH - 1;
 
        /* Boost level */
-       if ((level > 0) && !(d_info[dungeon_type].flags1 & DF1_BEGINNER))
+       if ((level > 0) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_BEGINNER))
        {
                /* Occasional "boost" */
                if (one_in_(GREAT_OBJ))
@@ -892,7 +892,7 @@ byte value_check_aux2(object_type *o_ptr)
  * @param o_ptr 未鑑定価格を確認したいオブジェクトの構造体参照ポインタ
  * @return オブジェクトの未鑑定価格
  */
-static s32b object_value_base(object_type *o_ptr)
+static PRICE object_value_base(object_type *o_ptr)
 {
        /* Aware item -- use template cost */
        if (object_is_aware(o_ptr)) return (k_info[o_ptr->k_idx].cost);
@@ -953,11 +953,11 @@ static s32b object_value_base(object_type *o_ptr)
  * @param plusses フラグに与える価格の基本重み
  * @return オブジェクトのフラグ価格
  */
-s32b flag_cost(object_type *o_ptr, int plusses)
+PRICE flag_cost(object_type *o_ptr, int plusses)
 {
-       s32b total = 0;
+       PRICE total = 0;
        BIT_FLAGS flgs[TR_FLAG_SIZE];
-       s32b tmp_cost;
+       PRICE tmp_cost;
        int count;
        int i;
        object_kind *k_ptr = &k_info[o_ptr->k_idx];
@@ -1470,11 +1470,9 @@ PRICE object_value(object_type *o_ptr)
                value = object_value_base(o_ptr);
        }
 
-
        /* Apply discount (if any) */
        if (o_ptr->discount) value -= (value * o_ptr->discount / 100L);
 
-
        /* Return the final value */
        return (value);
 }
@@ -1505,10 +1503,7 @@ bool can_player_destroy_object(object_type *o_ptr)
 
                /* We have "felt" it (again) */
                o_ptr->ident |= (IDENT_SENSE);
-
-               /* Combine the pack */
                p_ptr->update |= (PU_COMBINE);
-
                p_ptr->window |= (PW_INVEN | PW_EQUIP);
 
                return FALSE;
@@ -2124,142 +2119,6 @@ static void object_mention(object_type *o_ptr)
        msg_format_wizard(CHEAT_OBJECT, _("%sを生成しました。", "%s was generated."), o_name);
 }
 
-/*!
- * @brief INSTA_ART型の固定アーティファクトの生成を確率に応じて試行する。
- * Mega-Hack -- Attempt to create one of the "Special Objects"
- * @param o_ptr 生成に割り当てたいオブジェクトの構造体参照ポインタ
- * @return 生成に成功したらTRUEを返す。
- * @details
- * We are only called from "make_object()", and we assume that\n
- * "apply_magic()" is called immediately after we return.\n
- *\n
- * Note -- see "make_artifact()" and "apply_magic()"\n
- */
-static bool make_artifact_special(object_type *o_ptr)
-{
-       IDX i;
-       KIND_OBJECT_IDX k_idx = 0;
-
-       /*! @note 地上ではキャンセルする / No artifacts in the town */
-       if (!dun_level) return (FALSE);
-
-       /*! @note get_obj_num_hookによる指定がある場合は生成をキャンセルする / Themed object */
-       if (get_obj_num_hook) return (FALSE);
-
-       /*! @note 全固定アーティファクト中からIDの若い順に生成対象とその確率を走査する / Check the artifact list (just the "specials") */
-       for (i = 0; i < max_a_idx; i++)
-       {
-               artifact_type *a_ptr = &a_info[i];
-
-               /*! @note アーティファクト名が空の不正なデータは除外する / Skip "empty" artifacts */
-               if (!a_ptr->name) continue;
-
-               /*! @note 既に生成回数がカウントされたアーティファクト、QUESTITEMと非INSTA_ARTは除外 / Cannot make an artifact twice */
-               if (a_ptr->cur_num) continue;
-               if (a_ptr->gen_flags & TRG_QUESTITEM) continue;
-               if (!(a_ptr->gen_flags & TRG_INSTA_ART)) continue;
-
-               /*! @note アーティファクト生成階が現在に対して足りない場合は高確率で1/(不足階層*2)を満たさないと生成リストに加えられない /
-                *  XXX XXX Enforce minimum "depth" (loosely) */
-               if (a_ptr->level > object_level)
-               {
-                       /* @note  / Acquire the "out-of-depth factor". Roll for out-of-depth creation. */
-                       int d = (a_ptr->level - object_level) * 2;
-                       if (!one_in_(d)) continue;
-               }
-
-               /*! @note 1/(レア度)の確率を満たさないと除外される / Artifact "rarity roll" */
-               if (!one_in_(a_ptr->rarity)) continue;
-
-               /*! @note INSTA_ART型固定アーティファクトのベースアイテムもチェック対象とする。ベースアイテムの生成階層が足りない場合1/(不足階層*5) を満たさないと除外される。 /
-                *  Find the base object. XXX XXX Enforce minimum "object" level (loosely). Acquire the "out-of-depth factor". Roll for out-of-depth creation. */
-               k_idx = lookup_kind(a_ptr->tval, a_ptr->sval);
-               if (k_info[k_idx].level > object_level)
-               {
-                       int d = (k_info[k_idx].level - object_level) * 5;
-                       if (!one_in_(d)) continue;
-               }
-
-               /*! @note 前述の条件を満たしたら、後のIDのアーティファクトはチェックせずすぐ確定し生成処理に移す /
-                * Assign the template. Mega-Hack -- mark the item as an artifact. Hack: Some artifacts get random extra powers. Success. */
-               object_prep(o_ptr, k_idx);
-
-               o_ptr->name1 = i;
-               random_artifact_resistance(o_ptr, a_ptr);
-               return (TRUE);
-       }
-
-       /*! @note 全INSTA_ART固定アーティファクトを試行しても決まらなかった場合 FALSEを返す / Failure */
-       return (FALSE);
-}
-
-
-/*!
- * @brief 非INSTA_ART型の固定アーティファクトの生成を確率に応じて試行する。
- * Mega-Hack -- Attempt to create one of the "Special Objects"
- * @param o_ptr 生成に割り当てたいオブジェクトの構造体参照ポインタ
- * @return 生成に成功したらTRUEを返す。
- * @details
- * Attempt to change an object into an artifact\n
- * This routine should only be called by "apply_magic()"\n
- * Note -- see "make_artifact_special()" and "apply_magic()"\n
- */
-static bool make_artifact(object_type *o_ptr)
-{
-       ARTIFACT_IDX i;
-
-       /* No artifacts in the town */
-       if (!dun_level) return (FALSE);
-
-       /* Paranoia -- no "plural" artifacts */
-       if (o_ptr->number != 1) return (FALSE);
-
-       /* Check the artifact list (skip the "specials") */
-       for (i = 0; i < max_a_idx; i++)
-       {
-               artifact_type *a_ptr = &a_info[i];
-
-               /* Skip "empty" items */
-               if (!a_ptr->name) continue;
-
-               /* Cannot make an artifact twice */
-               if (a_ptr->cur_num) continue;
-
-               if (a_ptr->gen_flags & TRG_QUESTITEM) continue;
-
-               if (a_ptr->gen_flags & TRG_INSTA_ART) continue;
-
-               /* Must have the correct fields */
-               if (a_ptr->tval != o_ptr->tval) continue;
-               if (a_ptr->sval != o_ptr->sval) continue;
-
-               /* XXX XXX Enforce minimum "depth" (loosely) */
-               if (a_ptr->level > dun_level)
-               {
-                       /* Acquire the "out-of-depth factor" */
-                       int d = (a_ptr->level - dun_level) * 2;
-
-                       /* Roll for out-of-depth creation */
-                       if (!one_in_(d)) continue;
-               }
-
-               /* We must make the "rarity roll" */
-               if (!one_in_(a_ptr->rarity)) continue;
-
-               /* Hack -- mark the item as an artifact */
-               o_ptr->name1 = i;
-
-               /* Hack: Some artifacts get random extra powers */
-               random_artifact_resistance(o_ptr, a_ptr);
-
-               /* Success */
-               return (TRUE);
-       }
-
-       /* Failure */
-       return (FALSE);
-}
-
 
 /*!
  * @brief アイテムのエゴをレア度の重みに合わせてランダムに選択する
@@ -4295,14 +4154,14 @@ void apply_magic(object_type *o_ptr, DEPTH lev, BIT_FLAGS mode)
        f1 = lev + 10;
 
        /* Maximal chance of being "good" */
-       if (f1 > d_info[dungeon_type].obj_good) f1 = d_info[dungeon_type].obj_good;
+       if (f1 > d_info[p_ptr->dungeon_idx].obj_good) f1 = d_info[p_ptr->dungeon_idx].obj_good;
 
        /* Base chance of being "great" */
        f2 = f1 * 2 / 3;
 
        /* Maximal chance of being "great" */
-       if ((p_ptr->pseikaku != SEIKAKU_MUNCHKIN) && (f2 > d_info[dungeon_type].obj_great))
-               f2 = d_info[dungeon_type].obj_great;
+       if ((p_ptr->pseikaku != SEIKAKU_MUNCHKIN) && (f2 > d_info[p_ptr->dungeon_idx].obj_great))
+               f2 = d_info[p_ptr->dungeon_idx].obj_great;
 
        if (p_ptr->muta3 & MUT3_GOOD_LUCK)
        {
@@ -4868,7 +4727,7 @@ void place_object(POSITION y, POSITION x, BIT_FLAGS mode)
        OBJECT_IDX o_idx;
 
        /* Acquire grid */
-       cave_type *c_ptr = &cave[y][x];
+       grid_type *g_ptr = &grid_array[y][x];
 
        object_type forge;
        object_type *q_ptr;
@@ -4881,7 +4740,7 @@ void place_object(POSITION y, POSITION x, BIT_FLAGS mode)
        if (!cave_drop_bold(y, x)) return;
 
        /* Avoid stacking on other objects */
-       if (c_ptr->o_idx) return;
+       if (g_ptr->o_idx) return;
 
        q_ptr = &forge;
        object_wipe(q_ptr);
@@ -4906,10 +4765,10 @@ void place_object(POSITION y, POSITION x, BIT_FLAGS mode)
                o_ptr->ix = x;
 
                /* Build a stack */
-               o_ptr->next_o_idx = c_ptr->o_idx;
+               o_ptr->next_o_idx = g_ptr->o_idx;
 
                /* Place the object */
-               c_ptr->o_idx = o_idx;
+               g_ptr->o_idx = o_idx;
 
                note_spot(y, x);
 
@@ -4982,7 +4841,7 @@ void place_gold(POSITION y, POSITION x)
        OBJECT_IDX o_idx;
 
        /* Acquire grid */
-       cave_type *c_ptr = &cave[y][x];
+       grid_type *g_ptr = &grid_array[y][x];
 
        object_type forge;
        object_type *q_ptr;
@@ -4995,7 +4854,7 @@ void place_gold(POSITION y, POSITION x)
        if (!cave_drop_bold(y, x)) return;
 
        /* Avoid stacking on other objects */
-       if (c_ptr->o_idx) return;
+       if (g_ptr->o_idx) return;
 
        q_ptr = &forge;
        object_wipe(q_ptr);
@@ -5020,10 +4879,10 @@ void place_gold(POSITION y, POSITION x)
                o_ptr->ix = x;
 
                /* Build a stack */
-               o_ptr->next_o_idx = c_ptr->o_idx;
+               o_ptr->next_o_idx = g_ptr->o_idx;
 
                /* Place the object */
-               c_ptr->o_idx = o_idx;
+               g_ptr->o_idx = o_idx;
 
                note_spot(y, x);
 
@@ -5066,7 +4925,7 @@ OBJECT_IDX drop_near(object_type *j_ptr, PERCENTAGE chance, POSITION y, POSITION
        OBJECT_IDX o_idx = 0;
        OBJECT_IDX this_o_idx, next_o_idx = 0;
 
-       cave_type *c_ptr;
+       grid_type *g_ptr;
 
        GAME_TEXT o_name[MAX_NLEN];
 
@@ -5132,7 +4991,7 @@ OBJECT_IDX drop_near(object_type *j_ptr, PERCENTAGE chance, POSITION y, POSITION
                        if (!projectable(y, x, ty, tx)) continue;
 
                        /* Obtain grid */
-                       c_ptr = &cave[ty][tx];
+                       g_ptr = &grid_array[ty][tx];
 
                        /* Require floor space */
                        if (!cave_drop_bold(ty, tx)) continue;
@@ -5141,7 +5000,7 @@ OBJECT_IDX drop_near(object_type *j_ptr, PERCENTAGE chance, POSITION y, POSITION
                        k = 0;
 
                        /* Scan objects in that grid */
-                       for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
+                       for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
                        {
                                object_type *o_ptr;
                                o_ptr = &o_list[this_o_idx];
@@ -5289,10 +5148,10 @@ OBJECT_IDX drop_near(object_type *j_ptr, PERCENTAGE chance, POSITION y, POSITION
        }
 
 
-       c_ptr = &cave[by][bx];
+       g_ptr = &grid_array[by][bx];
 
        /* Scan objects in that grid for combination */
-       for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
+       for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
        {
                object_type *o_ptr;
                o_ptr = &o_list[this_o_idx];
@@ -5353,10 +5212,10 @@ OBJECT_IDX drop_near(object_type *j_ptr, PERCENTAGE chance, POSITION y, POSITION
                j_ptr->held_m_idx = 0;
 
                /* Build a stack */
-               j_ptr->next_o_idx = c_ptr->o_idx;
+               j_ptr->next_o_idx = g_ptr->o_idx;
 
                /* Place the object */
-               c_ptr->o_idx = o_idx;
+               g_ptr->o_idx = o_idx;
 
                /* Success */
                done = TRUE;
@@ -5376,169 +5235,6 @@ OBJECT_IDX drop_near(object_type *j_ptr, PERCENTAGE chance, POSITION y, POSITION
        return (o_idx);
 }
 
-
-/*!
- * @brief 獲得ドロップを行う。
- * Scatter some "great" objects near the player
- * @param y1 配置したいフロアのY座標
- * @param x1 配置したいフロアのX座標
- * @param num 獲得の処理回数
- * @param great TRUEならば必ず高級品以上を落とす
- * @param special TRUEならば必ず特別品を落とす
- * @param known TRUEならばオブジェクトが必ず*鑑定*済になる
- * @return なし
- */
-void acquirement(POSITION y1, POSITION x1, int num, bool great, bool special, bool known)
-{
-       object_type *i_ptr;
-       object_type object_type_body;
-       BIT_FLAGS mode = AM_GOOD | (great || special ? AM_GREAT : 0L) | (special ? AM_SPECIAL : 0L) ;
-
-       /* Acquirement */
-       while (num--)
-       {
-               i_ptr = &object_type_body;
-               object_wipe(i_ptr);
-
-               /* Make a good (or great) object (if possible) */
-               if (!make_object(i_ptr, mode)) continue;
-
-               if (known)
-               {
-                       object_aware(i_ptr);
-                       object_known(i_ptr);
-               }
-
-               /* Drop the object */
-               (void)drop_near(i_ptr, -1, y1, x1);
-       }
-}
-
-/*
- * Scatter some "amusing" objects near the player
- */
-
-#define AMS_NOTHING   0x00 /* No restriction */
-#define AMS_NO_UNIQUE 0x01 /* Don't make the amusing object of uniques */
-#define AMS_FIXED_ART 0x02 /* Make a fixed artifact based on the amusing object */
-#define AMS_MULTIPLE  0x04 /* Drop 1-3 objects for one type */
-#define AMS_PILE      0x08 /* Drop 1-99 pile objects for one type */
-
-typedef struct
-{
-       OBJECT_TYPE_VALUE tval;
-       OBJECT_SUBTYPE_VALUE sval;
-       PERCENTAGE prob;
-       byte flag;
-} amuse_type;
-
-amuse_type amuse_info[] =
-{
-       { TV_BOTTLE, SV_ANY, 5, AMS_NOTHING },
-       { TV_JUNK, SV_ANY, 3, AMS_MULTIPLE },
-       { TV_SPIKE, SV_ANY, 10, AMS_PILE },
-       { TV_STATUE, SV_ANY, 15, AMS_NOTHING },
-       { TV_CORPSE, SV_ANY, 15, AMS_NO_UNIQUE },
-       { TV_SKELETON, SV_ANY, 10, AMS_NO_UNIQUE },
-       { TV_FIGURINE, SV_ANY, 10, AMS_NO_UNIQUE },
-       { TV_PARCHMENT, SV_ANY, 1, AMS_NOTHING },
-       { TV_POLEARM, SV_TSURIZAO, 3, AMS_NOTHING }, //Fishing Pole of Taikobo
-       { TV_SWORD, SV_BROKEN_DAGGER, 3, AMS_FIXED_ART }, //Broken Dagger of Magician
-       { TV_SWORD, SV_BROKEN_DAGGER, 10, AMS_NOTHING },
-       { TV_SWORD, SV_BROKEN_SWORD, 5, AMS_NOTHING },
-       { TV_SCROLL, SV_SCROLL_AMUSEMENT, 10, AMS_NOTHING },
-
-       { 0, 0, 0 }
-};
-
-/*!
- * @brief 誰得ドロップを行う。
- * @param y1 配置したいフロアのY座標
- * @param x1 配置したいフロアのX座標
- * @param num 誰得の処理回数
- * @param known TRUEならばオブジェクトが必ず*鑑定*済になる
- * @return なし
- */
-void amusement(POSITION y1, POSITION x1, int num, bool known)
-{
-       object_type *i_ptr;
-       object_type object_type_body;
-       int n, t = 0;
-
-       for (n = 0; amuse_info[n].tval != 0; n++)
-       {
-               t += amuse_info[n].prob;
-       }
-
-       /* Acquirement */
-       while (num)
-       {
-               int i;
-               KIND_OBJECT_IDX k_idx;
-               ARTIFACT_IDX a_idx = 0;
-               int r = randint0(t);
-               bool insta_art, fixed_art;
-
-               for (i = 0; ; i++)
-               {
-                       r -= amuse_info[i].prob;
-                       if (r <= 0) break;
-               }
-               i_ptr = &object_type_body;
-               object_wipe(i_ptr);
-               k_idx = lookup_kind(amuse_info[i].tval, amuse_info[i].sval);
-
-               /* Paranoia - reroll if nothing */
-               if (!k_idx) continue;
-
-               /* Search an artifact index if need */
-               insta_art = (k_info[k_idx].gen_flags & TRG_INSTA_ART);
-               fixed_art = (amuse_info[i].flag & AMS_FIXED_ART);
-
-               if (insta_art || fixed_art)
-               {
-                       for (a_idx = 1; a_idx < max_a_idx; a_idx++)
-                       {
-                               if (insta_art && !(a_info[a_idx].gen_flags & TRG_INSTA_ART)) continue;
-                               if (a_info[a_idx].tval != k_info[k_idx].tval) continue;
-                               if (a_info[a_idx].sval != k_info[k_idx].sval) continue;
-                               if (a_info[a_idx].cur_num > 0) continue;
-                               break;
-                       }
-
-                       if (a_idx >= max_a_idx) continue;
-               }
-
-               /* Make an object (if possible) */
-               object_prep(i_ptr, k_idx);
-               if (a_idx) i_ptr->name1 = a_idx;
-               apply_magic(i_ptr, 1, AM_NO_FIXED_ART);
-
-               if (amuse_info[i].flag & AMS_NO_UNIQUE)
-               {
-                       if (r_info[i_ptr->pval].flags1 & RF1_UNIQUE) continue;
-               }
-
-               if (amuse_info[i].flag & AMS_MULTIPLE) i_ptr->number = randint1(3);
-               if (amuse_info[i].flag & AMS_PILE) i_ptr->number = randint1(99);
-
-               if (known)
-               {
-                       object_aware(i_ptr);
-                       object_known(i_ptr);
-               }
-
-               /* Paranoia - reroll if nothing */
-               if (!(i_ptr->k_idx)) continue;
-
-               /* Drop the object */
-               (void)drop_near(i_ptr, -1, y1, x1);
-
-               num--;
-       }
-}
-
-
 /*!
  * @brief 魔道具の使用回数の残量を示すメッセージを表示する /
  * Describe the charges on an item in the inventory.
@@ -5644,10 +5340,7 @@ void inven_item_increase(INVENTORY_IDX item, ITEM_NUMBER num)
 
                /* Recalculate mana XXX */
                p_ptr->update |= (PU_MANA);
-
-               /* Combine the pack */
                p_ptr->update |= (PU_COMBINE);
-
                p_ptr->window |= (PW_INVEN | PW_EQUIP);
 
                /* Hack -- Clear temporary elemental brands if player takes off weapons */
@@ -6862,7 +6555,7 @@ static int blow_damcalc(monster_type *m_ptr, monster_blow *blow_ptr)
 bool process_warning(POSITION xx, POSITION yy)
 {
        POSITION mx, my;
-       cave_type *c_ptr;
+       grid_type *g_ptr;
        GAME_TEXT o_name[MAX_NLEN];
 
 #define WARNING_AWARE_RANGE 12
@@ -6879,11 +6572,11 @@ bool process_warning(POSITION xx, POSITION yy)
 
                        if (!in_bounds(my, mx) || (distance(my, mx, yy, xx) > WARNING_AWARE_RANGE)) continue;
 
-                       c_ptr = &cave[my][mx];
+                       g_ptr = &grid_array[my][mx];
 
-                       if (!c_ptr->m_idx) continue;
+                       if (!g_ptr->m_idx) continue;
 
-                       m_ptr = &m_list[c_ptr->m_idx];
+                       m_ptr = &m_list[g_ptr->m_idx];
 
                        if (MON_CSLEEP(m_ptr)) continue;
                        if (!is_hostile(m_ptr)) continue;
@@ -6897,42 +6590,42 @@ bool process_warning(POSITION xx, POSITION yy)
                                BIT_FLAGS f5 = r_ptr->a_ability_flags1;
                                BIT_FLAGS f6 = r_ptr->a_ability_flags2;
 
-                               if (!(d_info[dungeon_type].flags1 & DF1_NO_MAGIC))
+                               if (!(d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_MAGIC))
                                {
-                                       if (f4 & RF4_BA_CHAO) spell_damcalc_by_spellnum(MS_BALL_CHAOS, GF_CHAOS, c_ptr->m_idx, &dam_max0);
-                                       if (f5 & RF5_BA_MANA) spell_damcalc_by_spellnum(MS_BALL_MANA, GF_MANA, c_ptr->m_idx, &dam_max0);
-                                       if (f5 & RF5_BA_DARK) spell_damcalc_by_spellnum(MS_BALL_DARK, GF_DARK, c_ptr->m_idx, &dam_max0);
-                                       if (f5 & RF5_BA_LITE) spell_damcalc_by_spellnum(MS_STARBURST, GF_LITE, c_ptr->m_idx, &dam_max0);
-                                       if (f6 & RF6_HAND_DOOM) spell_damcalc_by_spellnum(MS_HAND_DOOM, GF_HAND_DOOM, c_ptr->m_idx, &dam_max0);
-                                       if (f6 & RF6_PSY_SPEAR) spell_damcalc_by_spellnum(MS_PSY_SPEAR, GF_PSY_SPEAR, c_ptr->m_idx, &dam_max0);
+                                       if (f4 & RF4_BA_CHAO) spell_damcalc_by_spellnum(MS_BALL_CHAOS, GF_CHAOS, g_ptr->m_idx, &dam_max0);
+                                       if (f5 & RF5_BA_MANA) spell_damcalc_by_spellnum(MS_BALL_MANA, GF_MANA, g_ptr->m_idx, &dam_max0);
+                                       if (f5 & RF5_BA_DARK) spell_damcalc_by_spellnum(MS_BALL_DARK, GF_DARK, g_ptr->m_idx, &dam_max0);
+                                       if (f5 & RF5_BA_LITE) spell_damcalc_by_spellnum(MS_STARBURST, GF_LITE, g_ptr->m_idx, &dam_max0);
+                                       if (f6 & RF6_HAND_DOOM) spell_damcalc_by_spellnum(MS_HAND_DOOM, GF_HAND_DOOM, g_ptr->m_idx, &dam_max0);
+                                       if (f6 & RF6_PSY_SPEAR) spell_damcalc_by_spellnum(MS_PSY_SPEAR, GF_PSY_SPEAR, g_ptr->m_idx, &dam_max0);
                                }
-                               if (f4 & RF4_ROCKET) spell_damcalc_by_spellnum(MS_ROCKET, GF_ROCKET, c_ptr->m_idx, &dam_max0);
-                               if (f4 & RF4_BR_ACID) spell_damcalc_by_spellnum(MS_BR_ACID, GF_ACID, c_ptr->m_idx, &dam_max0);
-                               if (f4 & RF4_BR_ELEC) spell_damcalc_by_spellnum(MS_BR_ELEC, GF_ELEC, c_ptr->m_idx, &dam_max0);
-                               if (f4 & RF4_BR_FIRE) spell_damcalc_by_spellnum(MS_BR_FIRE, GF_FIRE, c_ptr->m_idx, &dam_max0);
-                               if (f4 & RF4_BR_COLD) spell_damcalc_by_spellnum(MS_BR_COLD, GF_COLD, c_ptr->m_idx, &dam_max0);
-                               if (f4 & RF4_BR_POIS) spell_damcalc_by_spellnum(MS_BR_POIS, GF_POIS, c_ptr->m_idx, &dam_max0);
-                               if (f4 & RF4_BR_NETH) spell_damcalc_by_spellnum(MS_BR_NETHER, GF_NETHER, c_ptr->m_idx, &dam_max0);
-                               if (f4 & RF4_BR_LITE) spell_damcalc_by_spellnum(MS_BR_LITE, GF_LITE, c_ptr->m_idx, &dam_max0);
-                               if (f4 & RF4_BR_DARK) spell_damcalc_by_spellnum(MS_BR_DARK, GF_DARK, c_ptr->m_idx, &dam_max0);
-                               if (f4 & RF4_BR_CONF) spell_damcalc_by_spellnum(MS_BR_CONF, GF_CONFUSION, c_ptr->m_idx, &dam_max0);
-                               if (f4 & RF4_BR_SOUN) spell_damcalc_by_spellnum(MS_BR_SOUND, GF_SOUND, c_ptr->m_idx, &dam_max0);
-                               if (f4 & RF4_BR_CHAO) spell_damcalc_by_spellnum(MS_BR_CHAOS, GF_CHAOS, c_ptr->m_idx, &dam_max0);
-                               if (f4 & RF4_BR_DISE) spell_damcalc_by_spellnum(MS_BR_DISEN, GF_DISENCHANT, c_ptr->m_idx, &dam_max0);
-                               if (f4 & RF4_BR_NEXU) spell_damcalc_by_spellnum(MS_BR_NEXUS, GF_NEXUS, c_ptr->m_idx, &dam_max0);
-                               if (f4 & RF4_BR_TIME) spell_damcalc_by_spellnum(MS_BR_TIME, GF_TIME, c_ptr->m_idx, &dam_max0);
-                               if (f4 & RF4_BR_INER) spell_damcalc_by_spellnum(MS_BR_INERTIA, GF_INERTIAL, c_ptr->m_idx, &dam_max0);
-                               if (f4 & RF4_BR_GRAV) spell_damcalc_by_spellnum(MS_BR_GRAVITY, GF_GRAVITY, c_ptr->m_idx, &dam_max0);
-                               if (f4 & RF4_BR_SHAR) spell_damcalc_by_spellnum(MS_BR_SHARDS, GF_SHARDS, c_ptr->m_idx, &dam_max0);
-                               if (f4 & RF4_BR_PLAS) spell_damcalc_by_spellnum(MS_BR_PLASMA, GF_PLASMA, c_ptr->m_idx, &dam_max0);
-                               if (f4 & RF4_BR_WALL) spell_damcalc_by_spellnum(MS_BR_FORCE, GF_FORCE, c_ptr->m_idx, &dam_max0);
-                               if (f4 & RF4_BR_MANA) spell_damcalc_by_spellnum(MS_BR_MANA, GF_MANA, c_ptr->m_idx, &dam_max0);
-                               if (f4 & RF4_BR_NUKE) spell_damcalc_by_spellnum(MS_BR_NUKE, GF_NUKE, c_ptr->m_idx, &dam_max0);
-                               if (f4 & RF4_BR_DISI) spell_damcalc_by_spellnum(MS_BR_DISI, GF_DISINTEGRATE, c_ptr->m_idx, &dam_max0);
+                               if (f4 & RF4_ROCKET) spell_damcalc_by_spellnum(MS_ROCKET, GF_ROCKET, g_ptr->m_idx, &dam_max0);
+                               if (f4 & RF4_BR_ACID) spell_damcalc_by_spellnum(MS_BR_ACID, GF_ACID, g_ptr->m_idx, &dam_max0);
+                               if (f4 & RF4_BR_ELEC) spell_damcalc_by_spellnum(MS_BR_ELEC, GF_ELEC, g_ptr->m_idx, &dam_max0);
+                               if (f4 & RF4_BR_FIRE) spell_damcalc_by_spellnum(MS_BR_FIRE, GF_FIRE, g_ptr->m_idx, &dam_max0);
+                               if (f4 & RF4_BR_COLD) spell_damcalc_by_spellnum(MS_BR_COLD, GF_COLD, g_ptr->m_idx, &dam_max0);
+                               if (f4 & RF4_BR_POIS) spell_damcalc_by_spellnum(MS_BR_POIS, GF_POIS, g_ptr->m_idx, &dam_max0);
+                               if (f4 & RF4_BR_NETH) spell_damcalc_by_spellnum(MS_BR_NETHER, GF_NETHER, g_ptr->m_idx, &dam_max0);
+                               if (f4 & RF4_BR_LITE) spell_damcalc_by_spellnum(MS_BR_LITE, GF_LITE, g_ptr->m_idx, &dam_max0);
+                               if (f4 & RF4_BR_DARK) spell_damcalc_by_spellnum(MS_BR_DARK, GF_DARK, g_ptr->m_idx, &dam_max0);
+                               if (f4 & RF4_BR_CONF) spell_damcalc_by_spellnum(MS_BR_CONF, GF_CONFUSION, g_ptr->m_idx, &dam_max0);
+                               if (f4 & RF4_BR_SOUN) spell_damcalc_by_spellnum(MS_BR_SOUND, GF_SOUND, g_ptr->m_idx, &dam_max0);
+                               if (f4 & RF4_BR_CHAO) spell_damcalc_by_spellnum(MS_BR_CHAOS, GF_CHAOS, g_ptr->m_idx, &dam_max0);
+                               if (f4 & RF4_BR_DISE) spell_damcalc_by_spellnum(MS_BR_DISEN, GF_DISENCHANT, g_ptr->m_idx, &dam_max0);
+                               if (f4 & RF4_BR_NEXU) spell_damcalc_by_spellnum(MS_BR_NEXUS, GF_NEXUS, g_ptr->m_idx, &dam_max0);
+                               if (f4 & RF4_BR_TIME) spell_damcalc_by_spellnum(MS_BR_TIME, GF_TIME, g_ptr->m_idx, &dam_max0);
+                               if (f4 & RF4_BR_INER) spell_damcalc_by_spellnum(MS_BR_INERTIA, GF_INERTIAL, g_ptr->m_idx, &dam_max0);
+                               if (f4 & RF4_BR_GRAV) spell_damcalc_by_spellnum(MS_BR_GRAVITY, GF_GRAVITY, g_ptr->m_idx, &dam_max0);
+                               if (f4 & RF4_BR_SHAR) spell_damcalc_by_spellnum(MS_BR_SHARDS, GF_SHARDS, g_ptr->m_idx, &dam_max0);
+                               if (f4 & RF4_BR_PLAS) spell_damcalc_by_spellnum(MS_BR_PLASMA, GF_PLASMA, g_ptr->m_idx, &dam_max0);
+                               if (f4 & RF4_BR_WALL) spell_damcalc_by_spellnum(MS_BR_FORCE, GF_FORCE, g_ptr->m_idx, &dam_max0);
+                               if (f4 & RF4_BR_MANA) spell_damcalc_by_spellnum(MS_BR_MANA, GF_MANA, g_ptr->m_idx, &dam_max0);
+                               if (f4 & RF4_BR_NUKE) spell_damcalc_by_spellnum(MS_BR_NUKE, GF_NUKE, g_ptr->m_idx, &dam_max0);
+                               if (f4 & RF4_BR_DISI) spell_damcalc_by_spellnum(MS_BR_DISI, GF_DISINTEGRATE, g_ptr->m_idx, &dam_max0);
                        }
 
                        /* Monster melee attacks */
-                       if (!(r_ptr->flags1 & RF1_NEVER_BLOW) && !(d_info[dungeon_type].flags1 & DF1_NO_MELEE))
+                       if (!(r_ptr->flags1 & RF1_NEVER_BLOW) && !(d_info[p_ptr->dungeon_idx].flags1 & DF1_NO_MELEE))
                        {
                                if (mx <= xx + 1 && mx >= xx - 1 && my <= yy + 1 && my >= yy - 1)
                                {
@@ -6977,9 +6670,9 @@ bool process_warning(POSITION xx, POSITION yy)
        }
        else old_damage = old_damage / 2;
 
-       c_ptr = &cave[yy][xx];
-       if (((!easy_disarm && is_trap(c_ptr->feat))
-           || (c_ptr->mimic && is_trap(c_ptr->feat))) && !one_in_(13))
+       g_ptr = &grid_array[yy][xx];
+       if (((!easy_disarm && is_trap(g_ptr->feat))
+           || (g_ptr->mimic && is_trap(g_ptr->feat))) && !one_in_(13))
        {
                object_type *o_ptr = choose_warning_item();
 
@@ -7511,7 +7204,7 @@ static void drain_essence(void)
                if (!get_check(format(_("本当に%sから抽出してよろしいですか?", "Really extract from %s? "), o_name))) return;
        }
 
-       p_ptr->energy_use = 100;
+       take_turn(p_ptr, 100);;
 
        object_flags(o_ptr, old_flgs);
        if (have_flag(old_flgs, TR_KILL_DRAGON)) add_flag(old_flgs, TR_SLAY_DRAGON);
@@ -7694,10 +7387,7 @@ static void drain_essence(void)
 
        /* Apply autodestroy/inscription to the drained item */
        autopick_alter_item(item, TRUE);
-
-       /* Combine the pack */
        p_ptr->update |= (PU_COMBINE | PU_REORDER);
-
        p_ptr->window |= (PW_INVEN);
 }
 
@@ -8194,7 +7884,7 @@ static void add_essence(ESSENCE_IDX mode)
                        if ((o_ptr->to_h >= p_ptr->lev/5+5) && (o_ptr->to_d >= p_ptr->lev/5+5))
                        {
                                msg_print(_("改良に失敗した。", "You failed to enchant."));
-                               p_ptr->energy_use = 100;
+                               take_turn(p_ptr, 100);;
                                return;
                        }
                        else
@@ -8208,7 +7898,7 @@ static void add_essence(ESSENCE_IDX mode)
                        if (o_ptr->to_a >= p_ptr->lev/5+5)
                        {
                                msg_print(_("改良に失敗した。", "You failed to enchant."));
-                               p_ptr->energy_use = 100;
+                               take_turn(p_ptr, 100);;
                                return;
                        }
                        else
@@ -8285,17 +7975,14 @@ static void add_essence(ESSENCE_IDX mode)
                }
        }
 
-       p_ptr->energy_use = 100;
+       take_turn(p_ptr, 100);
 
 #ifdef JP
        msg_format("%sに%sの能力を付加しました。", o_name, es_ptr->add_name);
 #else
        msg_format("You have added ability of %s to %s.", es_ptr->add_name, o_name);
 #endif
-
-       /* Combine the pack */
        p_ptr->update |= (PU_COMBINE | PU_REORDER);
-
        p_ptr->window |= (PW_INVEN);
 }
 
@@ -8322,7 +8009,7 @@ static void erase_essence(void)
        object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
        if (!get_check(format(_("よろしいですか? [%s]", "Are you sure? [%s]"), o_name))) return;
 
-       p_ptr->energy_use = 100;
+       take_turn(p_ptr, 100);;
 
        if (o_ptr->xtra3 == 1 + ESSENCE_SLAY_GLOVE)
        {
@@ -8336,10 +8023,7 @@ static void erase_essence(void)
        object_flags(o_ptr, flgs);
        if (!(have_pval_flags(flgs))) o_ptr->pval = 0;
        msg_print(_("エッセンスを取り去った。", "You removed all essence you have added."));
-
-       /* Combine the pack */
        p_ptr->update |= (PU_COMBINE | PU_REORDER);
-
        p_ptr->window |= (PW_INVEN);
 }
 
@@ -8357,11 +8041,7 @@ void do_cmd_kaji(bool only_browse)
 
        if (!only_browse)
        {
-               if (p_ptr->confused)
-               {
-                       msg_print(_("混乱していて作業できない!", "You are too confused!"));
-                       return;
-               }
+               if (cmd_limit_confused(p_ptr)) return;
                if (p_ptr->blind)
                {
                        msg_print(_("目が見えなくて作業できない!", "You are blind!"));