OSDN Git Service

[Refactor] #39076 "inventory_list" の 置換処理で誤ったコメントを修正/削除. / Fix and delete wrong repla...
[hengband/hengband.git] / src / object2.c
index f22ffd6..7c2be2a 100644 (file)
  */
 
 #include "angband.h"
+#include "util.h"
+#include "world.h"
+#include "term.h"
+
+#include "object.h"
+
+#include "cmd-dump.h"
+#include "cmd-spell.h"
+#include "spells.h"
+#include "dungeon.h"
+#include "floor.h"
+#include "grid.h"
+#include "objectkind.h"
+#include "object-boost.h"
+#include "object-ego.h"
+#include "object-flavor.h"
 #include "object-hook.h"
 #include "object-curse.h"
+#include "objectkind-hook.h"
 #include "artifact.h"
-#include "player-status.h"
 #include "feature.h"
+#include "player-status.h"
 #include "player-move.h"
-
-static void one_sustain(object_type *o_ptr);
-
-/*!
- * @brief 対象のオブジェクトにランダムな能力維持を一つ付加する。/ Choose one random sustain
- * @details 重複の抑止はない。
- * @param o_ptr 対象のオブジェクト構造体ポインタ
- * @return なし
- */
-static void one_sustain(object_type *o_ptr)
-{
-       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;
-               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;
-       }
-}
+#include "player-effects.h"
+#include "player-class.h"
+#include "player-personality.h"
+#include "monster.h"
+#include "monsterrace-hook.h"
+#include "object-ego.h"
+#include "view-mainwindow.h"
 
 /*!
  * @brief 床上、モンスター所持でスタックされたアイテムを削除しスタックを補完する / Excise a dungeon object from any stacks
@@ -53,18 +56,18 @@ void excise_object_idx(OBJECT_IDX o_idx)
        OBJECT_IDX prev_o_idx = 0;
 
        /* Object */
-       j_ptr = &current_floor_ptr->o_list[o_idx];
+       j_ptr = &p_ptr->current_floor_ptr->o_list[o_idx];
 
-       if (j_ptr->held_m_idx)
+       if (OBJECT_IS_HELD_MONSTER(j_ptr))
        {
                monster_type *m_ptr;
-               m_ptr = &current_floor_ptr->m_list[j_ptr->held_m_idx];
+               m_ptr = &p_ptr->current_floor_ptr->m_list[j_ptr->held_m_idx];
 
                /* Scan all objects in the grid */
                for (this_o_idx = m_ptr->hold_o_idx; this_o_idx; this_o_idx = next_o_idx)
                {
                        object_type *o_ptr;
-                       o_ptr = &current_floor_ptr->o_list[this_o_idx];
+                       o_ptr = &p_ptr->current_floor_ptr->o_list[this_o_idx];
                        next_o_idx = o_ptr->next_o_idx;
 
                        if (this_o_idx == o_idx)
@@ -82,7 +85,7 @@ void excise_object_idx(OBJECT_IDX o_idx)
                                        object_type *k_ptr;
 
                                        /* Previous object */
-                                       k_ptr = &current_floor_ptr->o_list[prev_o_idx];
+                                       k_ptr = &p_ptr->current_floor_ptr->o_list[prev_o_idx];
 
                                        /* Remove from list */
                                        k_ptr->next_o_idx = next_o_idx;
@@ -107,13 +110,13 @@ void excise_object_idx(OBJECT_IDX o_idx)
                POSITION y = j_ptr->iy;
                POSITION x = j_ptr->ix;
 
-               g_ptr = &current_floor_ptr->grid_array[y][x];
+               g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
 
                /* Scan all objects in the grid */
                for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
                {
                        object_type *o_ptr;
-                       o_ptr = &current_floor_ptr->o_list[this_o_idx];
+                       o_ptr = &p_ptr->current_floor_ptr->o_list[this_o_idx];
                        next_o_idx = o_ptr->next_o_idx;
 
                        if (this_o_idx == o_idx)
@@ -131,7 +134,7 @@ void excise_object_idx(OBJECT_IDX o_idx)
                                        object_type *k_ptr;
 
                                        /* Previous object */
-                                       k_ptr = &current_floor_ptr->o_list[prev_o_idx];
+                                       k_ptr = &p_ptr->current_floor_ptr->o_list[prev_o_idx];
 
                                        /* Remove from list */
                                        k_ptr->next_o_idx = next_o_idx;
@@ -165,23 +168,20 @@ void delete_object_idx(OBJECT_IDX o_idx)
        excise_object_idx(o_idx);
 
        /* Object */
-       j_ptr = &current_floor_ptr->o_list[o_idx];
+       j_ptr = &p_ptr->current_floor_ptr->o_list[o_idx];
 
        /* Dungeon floor */
-       if (!(j_ptr->held_m_idx))
+       if (!OBJECT_IS_HELD_MONSTER(j_ptr))
        {
                POSITION y, x;
-
                y = j_ptr->iy;
                x = j_ptr->ix;
-
-               /* Visual update */
                lite_spot(y, x);
        }
        object_wipe(j_ptr);
 
        /* Count objects */
-       o_cnt--;
+       p_ptr->current_floor_ptr->o_cnt--;
 }
 
 
@@ -198,26 +198,25 @@ void delete_object(POSITION y, POSITION x)
        OBJECT_IDX this_o_idx, next_o_idx = 0;
 
        /* Refuse "illegal" locations */
-       if (!in_bounds(y, x)) return;
+       if (!in_bounds(p_ptr->current_floor_ptr, y, x)) return;
 
-       g_ptr = &current_floor_ptr->grid_array[y][x];
+       g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
 
        /* Scan all objects in the grid */
        for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
        {
                object_type *o_ptr;
-               o_ptr = &current_floor_ptr->o_list[this_o_idx];
+               o_ptr = &p_ptr->current_floor_ptr->o_list[this_o_idx];
                next_o_idx = o_ptr->next_o_idx;
                object_wipe(o_ptr);
 
                /* Count objects */
-               o_cnt--;
+               p_ptr->current_floor_ptr->o_cnt--;
        }
 
        /* Objects are gone */
        g_ptr->o_idx = 0;
 
-       /* Visual update */
        lite_spot(y, x);
 }
 
@@ -239,9 +238,9 @@ static void compact_objects_aux(OBJECT_IDX i1, OBJECT_IDX i2)
        if (i1 == i2) return;
 
        /* Repair objects */
-       for (i = 1; i < o_max; i++)
+       for (i = 1; i < p_ptr->current_floor_ptr->o_max; i++)
        {
-               o_ptr = &current_floor_ptr->o_list[i];
+               o_ptr = &p_ptr->current_floor_ptr->o_list[i];
 
                /* Skip "dead" objects */
                if (!o_ptr->k_idx) continue;
@@ -253,14 +252,12 @@ static void compact_objects_aux(OBJECT_IDX i1, OBJECT_IDX i2)
                        o_ptr->next_o_idx = i2;
                }
        }
-       o_ptr = &current_floor_ptr->o_list[i1];
+       o_ptr = &p_ptr->current_floor_ptr->o_list[i1];
 
-       if (o_ptr->held_m_idx)
+       if (OBJECT_IS_HELD_MONSTER(o_ptr))
        {
                monster_type *m_ptr;
-
-               /* Acquire monster */
-               m_ptr = &current_floor_ptr->m_list[o_ptr->held_m_idx];
+               m_ptr = &p_ptr->current_floor_ptr->m_list[o_ptr->held_m_idx];
 
                /* Repair monster */
                if (m_ptr->hold_o_idx == i1)
@@ -280,7 +277,7 @@ static void compact_objects_aux(OBJECT_IDX i1, OBJECT_IDX i2)
                x = o_ptr->ix;
 
                /* Acquire grid */
-               g_ptr = &current_floor_ptr->grid_array[y][x];
+               g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
 
                /* Repair grid */
                if (g_ptr->o_idx == i1)
@@ -291,7 +288,7 @@ static void compact_objects_aux(OBJECT_IDX i1, OBJECT_IDX i2)
        }
 
        /* Structure copy */
-       current_floor_ptr->o_list[i2] = current_floor_ptr->o_list[i1];
+       p_ptr->current_floor_ptr->o_list[i2] = p_ptr->current_floor_ptr->o_list[i1];
 
        /* Wipe the hole */
        object_wipe(o_ptr);
@@ -341,22 +338,19 @@ void compact_objects(int size)
                cur_dis = 5 * (20 - cnt);
 
                /* Examine the objects */
-               for (i = 1; i < o_max; i++)
+               for (i = 1; i < p_ptr->current_floor_ptr->o_max; i++)
                {
-                       o_ptr = &current_floor_ptr->o_list[i];
+                       o_ptr = &p_ptr->current_floor_ptr->o_list[i];
 
-                       /* Skip dead objects */
-                       if (!o_ptr->k_idx) continue;
+                       if (!OBJECT_IS_VALID(o_ptr)) continue;
 
                        /* Hack -- High level objects start out "immune" */
                        if (k_info[o_ptr->k_idx].level > cur_lev) continue;
 
-                       if (o_ptr->held_m_idx)
+                       if (OBJECT_IS_HELD_MONSTER(o_ptr))
                        {
                                monster_type *m_ptr;
-
-                               /* Acquire monster */
-                               m_ptr = &current_floor_ptr->m_list[o_ptr->held_m_idx];
+                               m_ptr = &p_ptr->current_floor_ptr->m_list[o_ptr->held_m_idx];
 
                                y = m_ptr->fy;
                                x = m_ptr->fx;
@@ -394,92 +388,21 @@ void compact_objects(int size)
 
 
        /* Excise dead objects (backwards!) */
-       for (i = o_max - 1; i >= 1; i--)
+       for (i = p_ptr->current_floor_ptr->o_max - 1; i >= 1; i--)
        {
-               o_ptr = &current_floor_ptr->o_list[i];
+               o_ptr = &p_ptr->current_floor_ptr->o_list[i];
 
                /* Skip real objects */
                if (o_ptr->k_idx) continue;
 
                /* Move last object into open hole */
-               compact_objects_aux(o_max - 1, i);
-
-               /* Compress "o_max" */
-               o_max--;
-       }
-}
-
-
-/*!
- * @brief グローバルオブジェクト配列を初期化する /
- * Delete all the items when player leaves the level
- * @note we do NOT visually reflect these (irrelevant) changes
- * @details
- * 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,
- * and we clear it once for every such object.
- * @return なし
- */
-void wipe_o_list(void)
-{
-       int i;
-
-       /* Delete the existing objects */
-       for (i = 1; i < o_max; i++)
-       {
-               object_type *o_ptr = &current_floor_ptr->o_list[i];
-
-               /* Skip dead objects */
-               if (!o_ptr->k_idx) continue;
+               compact_objects_aux(p_ptr->current_floor_ptr->o_max - 1, i);
 
-               /* Mega-Hack -- preserve artifacts */
-               if (!character_dungeon || preserve_mode)
-               {
-                       /* Hack -- Preserve unknown artifacts */
-                       if (object_is_fixed_artifact(o_ptr) && !object_is_known(o_ptr))
-                       {
-                               /* Mega-Hack -- Preserve the artifact */
-                               a_info[o_ptr->name1].cur_num = 0;
-                       }
-               }
-
-               if (o_ptr->held_m_idx)
-               {
-                       monster_type *m_ptr;
-                       m_ptr = &current_floor_ptr->m_list[o_ptr->held_m_idx];
-
-                       /* Hack -- see above */
-                       m_ptr->hold_o_idx = 0;
-               }
-
-               /* Dungeon */
-               else
-               {
-                       grid_type *g_ptr;
-
-                       /* Access location */
-                       POSITION y = o_ptr->iy;
-                       POSITION x = o_ptr->ix;
-
-                       /* Access grid */
-                       g_ptr = &current_floor_ptr->grid_array[y][x];
-
-                       /* Hack -- see above */
-                       g_ptr->o_idx = 0;
-               }
-               object_wipe(o_ptr);
+               /* Compress "p_ptr->current_floor_ptr->o_max" */
+               p_ptr->current_floor_ptr->o_max--;
        }
-
-       /* Reset "o_max" */
-       o_max = 1;
-
-       /* Reset "o_cnt" */
-       o_cnt = 0;
 }
 
-
 /*!
  * @brief グローバルオブジェクト配列から空きを取得する /
  * Acquires and returns the index of a "free" object.
@@ -493,16 +416,16 @@ OBJECT_IDX o_pop(void)
        OBJECT_IDX i;
 
        /* Initial allocation */
-       if (o_max < current_floor_ptr->max_o_idx)
+       if (p_ptr->current_floor_ptr->o_max < current_world_ptr->max_o_idx)
        {
                /* Get next space */
-               i = o_max;
+               i = p_ptr->current_floor_ptr->o_max;
 
                /* Expand object array */
-               o_max++;
+               p_ptr->current_floor_ptr->o_max++;
 
                /* Count objects */
-               o_cnt++;
+               p_ptr->current_floor_ptr->o_cnt++;
 
                /* Use this object */
                return (i);
@@ -510,16 +433,16 @@ OBJECT_IDX o_pop(void)
 
 
        /* Recycle dead objects */
-       for (i = 1; i < o_max; i++)
+       for (i = 1; i < p_ptr->current_floor_ptr->o_max; i++)
        {
                object_type *o_ptr;
-               o_ptr = &current_floor_ptr->o_list[i];
+               o_ptr = &p_ptr->current_floor_ptr->o_list[i];
 
                /* Skip live objects */
                if (o_ptr->k_idx) continue;
 
                /* Count objects */
-               o_cnt++;
+               p_ptr->current_floor_ptr->o_cnt++;
 
                /* Use this object */
                return (i);
@@ -527,11 +450,15 @@ OBJECT_IDX o_pop(void)
 
 
        /* Warn the player (except during dungeon creation) */
-       if (character_dungeon) msg_print(_("アイテムが多すぎる!", "Too many objects!"));
+       if (current_world_ptr->character_dungeon) msg_print(_("アイテムが多すぎる!", "Too many objects!"));
 
        return (0);
 }
 
+/*
+ * Hack -- function hook to restrict "get_obj_num_prep()" function
+ */
+bool(*get_obj_num_hook)(KIND_OBJECT_IDX k_idx);
 
 /*!
  * @brief オブジェクト生成テーブルに生成制約を加える /
@@ -587,7 +514,7 @@ 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
  */
-OBJECT_IDX get_obj_num(DEPTH level)
+OBJECT_IDX get_obj_num(DEPTH level, BIT_FLAGS mode)
 {
        int i, j, p;
        KIND_OBJECT_IDX k_idx;
@@ -620,14 +547,12 @@ OBJECT_IDX get_obj_num(DEPTH level)
                /* Default */
                table[i].prob3 = 0;
 
-               /* Access the index */
                k_idx = table[i].index;
 
                /* Access the actual kind */
                k_ptr = &k_info[k_idx];
 
-               /* Hack -- prevent embedded chests */
-               if (opening_chest && (k_ptr->tval == TV_CHEST)) continue;
+               if ((mode & AM_FORBID_CHEST) && (k_ptr->tval == TV_CHEST)) continue;
 
                /* Accept */
                table[i].prob3 = table[i].prob2;
@@ -706,7 +631,6 @@ OBJECT_IDX get_obj_num(DEPTH level)
        return (table[i].index);
 }
 
-
 /*!
  * @brief オブジェクトを鑑定済にする /
  * Known is true when the "attributes" of an object are "known".
@@ -766,7 +690,7 @@ void object_aware(object_type *o_ptr)
                q_ptr->number = 1;
                object_desc(o_name, q_ptr, OD_NAME_ONLY);
                
-               do_cmd_write_nikki(NIKKI_HANMEI, 0, o_name);
+               exe_write_diary(p_ptr, NIKKI_HANMEI, 0, o_name);
        }
 }
 
@@ -1449,40 +1373,6 @@ PRICE object_value(object_type *o_ptr)
 
 
 
-/*!
- * @brief 破壊可能なアイテムかを返す /
- * Determines whether an object can be destroyed, and makes fake inscription.
- * @param o_ptr 破壊可能かを確認したいオブジェクトの構造体参照ポインタ
- * @return オブジェクトが破壊可能ならばTRUEを返す
- */
-bool can_player_destroy_object(object_type *o_ptr)
-{
-       /* Artifacts cannot be destroyed */
-       if (!object_is_artifact(o_ptr)) return TRUE;
-
-       /* If object is unidentified, makes fake inscription */
-       if (!object_is_known(o_ptr))
-       {
-               byte feel = FEEL_SPECIAL;
-
-               /* Hack -- Handle icky artifacts */
-               if (object_is_cursed(o_ptr) || object_is_broken(o_ptr)) feel = FEEL_TERRIBLE;
-
-               /* Hack -- inscribe the artifact */
-               o_ptr->feeling = feel;
-
-               /* We have "felt" it (again) */
-               o_ptr->ident |= (IDENT_SENSE);
-               p_ptr->update |= (PU_COMBINE);
-               p_ptr->window |= (PW_INVEN | PW_EQUIP);
-
-               return FALSE;
-       }
-
-       /* Identified artifact -- Nothing to do */
-       return FALSE;
-}
-
 
 /*!
  * @brief 魔法棒やロッドのスロット分割時に使用回数を分配する /
@@ -1988,90 +1878,6 @@ void object_prep(object_type *o_ptr, KIND_OBJECT_IDX k_idx)
 
 
 /*!
- * @brief 上質以上のオブジェクトに与えるための各種ボーナスを正規乱数も加えて算出する。
- * Help determine an "enchantment bonus" for an object.
- * @param max ボーナス値の限度
- * @param level ボーナス値に加味する基準生成階
- * @return 算出されたボーナス値
- * @details
- * To avoid floating point but still provide a smooth distribution of bonuses,\n
- * we simply round the results of division in such a way as to "average" the\n
- * correct floating point value.\n
- *\n
- * This function has been changed.  It uses "randnor()" to choose values from\n
- * a normal distribution, whose mean moves from zero towards the max as the\n
- * level increases, and whose standard deviation is equal to 1/4 of the max,\n
- * and whose values are forced to lie between zero and the max, inclusive.\n
- *\n
- * Since the "level" rarely passes 100 before Morgoth is dead, it is very\n
- * rare to get the "full" enchantment on an object, even a deep levels.\n
- *\n
- * It is always possible (albeit unlikely) to get the "full" enchantment.\n
- *\n
- * A sample distribution of values from "m_bonus(10, N)" is shown below:\n
- *\n
- *   N       0     1     2     3     4     5     6     7     8     9    10\n
- * ---    ----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----\n
- *   0   66.37 13.01  9.73  5.47  2.89  1.31  0.72  0.26  0.12  0.09  0.03\n
- *   8   46.85 24.66 12.13  8.13  4.20  2.30  1.05  0.36  0.19  0.08  0.05\n
- *  16   30.12 27.62 18.52 10.52  6.34  3.52  1.95  0.90  0.31  0.15  0.05\n
- *  24   22.44 15.62 30.14 12.92  8.55  5.30  2.39  1.63  0.62  0.28  0.11\n
- *  32   16.23 11.43 23.01 22.31 11.19  7.18  4.46  2.13  1.20  0.45  0.41\n
- *  40   10.76  8.91 12.80 29.51 16.00  9.69  5.90  3.43  1.47  0.88  0.65\n
- *  48    7.28  6.81 10.51 18.27 27.57 11.76  7.85  4.99  2.80  1.22  0.94\n
- *  56    4.41  4.73  8.52 11.96 24.94 19.78 11.06  7.18  3.68  1.96  1.78\n
- *  64    2.81  3.07  5.65  9.17 13.01 31.57 13.70  9.30  6.04  3.04  2.64\n
- *  72    1.87  1.99  3.68  7.15 10.56 20.24 25.78 12.17  7.52  4.42  4.62\n
- *  80    1.02  1.23  2.78  4.75  8.37 12.04 27.61 18.07 10.28  6.52  7.33\n
- *  88    0.70  0.57  1.56  3.12  6.34 10.06 15.76 30.46 12.58  8.47 10.38\n
- *  96    0.27  0.60  1.25  2.28  4.30  7.60 10.77 22.52 22.51 11.37 16.53\n
- * 104    0.22  0.42  0.77  1.36  2.62  5.33  8.93 13.05 29.54 15.23 22.53\n
- * 112    0.15  0.20  0.56  0.87  2.00  3.83  6.86 10.06 17.89 27.31 30.27\n
- * 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
- */
-int m_bonus(int max, DEPTH level)
-{
-       int bonus, stand, extra, value;
-
-
-       /* Paranoia -- enforce maximal "level" */
-       if (level > MAX_DEPTH - 1) level = MAX_DEPTH - 1;
-
-
-       /* The "bonus" moves towards the max */
-       bonus = ((max * level) / MAX_DEPTH);
-
-       /* Hack -- determine fraction of error */
-       extra = ((max * level) % MAX_DEPTH);
-
-       /* Hack -- simulate floating point computations */
-       if (randint0(MAX_DEPTH) < extra) bonus++;
-
-
-       /* The "stand" is equal to one quarter of the max */
-       stand = (max / 4);
-
-       /* Hack -- determine fraction of error */
-       extra = (max % 4);
-
-       /* Hack -- simulate floating point computations */
-       if (randint0(4) < extra) stand++;
-
-
-       /* Choose an "interesting" value */
-       value = randnor(bonus, stand);
-
-       /* Enforce the minimum value */
-       if (value < 0) return (0);
-
-       /* Enforce the maximum value */
-       if (value > max) return (max);
-       return (value);
-}
-
-
-/*!
  * @brief デバッグ時にアイテム生成情報をメッセージに出力する / Cheat -- describe a created object for the user
  * @param o_ptr デバッグ出力するオブジェクトの構造体参照ポインタ
  * @return なし
@@ -2145,7 +1951,7 @@ 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, DEPTH level, int power)
+void apply_magic_weapon(object_type *o_ptr, DEPTH level, int power)
 {
        HIT_PROB tohit1 = randint1(5) + (HIT_PROB)m_bonus(5, level);
        HIT_POINT todam1 = randint1(5) + (HIT_POINT)m_bonus(5, level);
@@ -2155,8 +1961,8 @@ static void a_m_aux_1(object_type *o_ptr, DEPTH level, int power)
 
        if ((o_ptr->tval == TV_BOLT) || (o_ptr->tval == TV_ARROW) || (o_ptr->tval == TV_SHOT))
        {
-               tohit2 = (tohit2+1)/2;
-               todam2 = (todam2+1)/2;
+               tohit2 = (tohit2 + 1) / 2;
+               todam2 = (todam2 + 1) / 2;
        }
 
        /* Good */
@@ -2204,7 +2010,7 @@ static void a_m_aux_1(object_type *o_ptr, DEPTH level, int power)
                        if (power > 1)
                        {
                                if (one_in_(30) || (power > 2)) /* power > 2 is debug only */
-                                       create_artifact(o_ptr, FALSE);
+                                       become_random_artifact(o_ptr, FALSE);
                                else
                                        /* Special Ego-item */
                                        o_ptr->name2 = EGO_DIGGING;
@@ -2227,7 +2033,6 @@ static void a_m_aux_1(object_type *o_ptr, DEPTH level, int power)
                        break;
                }
 
-
                case TV_HAFTED:
                case TV_POLEARM:
                case TV_SWORD:
@@ -2237,7 +2042,7 @@ static void a_m_aux_1(object_type *o_ptr, DEPTH level, int power)
                        {
                                if (one_in_(40) || (power > 2)) /* power > 2 is debug only */
                                {
-                                       create_artifact(o_ptr, FALSE);
+                                       become_random_artifact(o_ptr, FALSE);
                                        break;
                                }
                                while (1)
@@ -2281,16 +2086,14 @@ static void a_m_aux_1(object_type *o_ptr, DEPTH level, int power)
                                                do
                                                {
                                                        o_ptr->dd++;
-                                               }
-                                               while (one_in_(o_ptr->dd));
-                                               
+                                               } while (one_in_(o_ptr->dd));
+
                                                do
                                                {
                                                        o_ptr->ds++;
-                                               }
-                                               while (one_in_(o_ptr->ds));
+                                               } while (one_in_(o_ptr->ds));
                                        }
-                                       
+
                                        if (one_in_(5))
                                        {
                                                add_flag(o_ptr->art_flags, TR_BRAND_POIS);
@@ -2328,15 +2131,15 @@ static void a_m_aux_1(object_type *o_ptr, DEPTH level, int power)
                                                add_flag(o_ptr->art_flags, TR_SLAY_HUMAN);
                                        break;
                                case EGO_DEMON:
-                                       
-                                       if(one_in_(3)) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
-                                       one_in_(3) ? 
+
+                                       if (one_in_(3)) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
+                                       one_in_(3) ?
                                                add_flag(o_ptr->art_flags, TR_DRAIN_EXP) :
                                                one_in_(2) ?
-                                                       add_flag(o_ptr->art_flags, TR_DRAIN_HP) :
-                                                       add_flag(o_ptr->art_flags, TR_DRAIN_MANA);
-                                               
-                                       
+                                               add_flag(o_ptr->art_flags, TR_DRAIN_HP) :
+                                               add_flag(o_ptr->art_flags, TR_DRAIN_MANA);
+
+
                                        if (one_in_(3)) add_flag(o_ptr->art_flags, TR_CHAOTIC);
                                        if (one_in_(4)) add_flag(o_ptr->art_flags, TR_BLOWS);
                                        if (one_in_(5)) add_flag(o_ptr->art_flags, TR_ADD_H_CURSE);
@@ -2360,7 +2163,7 @@ static void a_m_aux_1(object_type *o_ptr, DEPTH level, int power)
                                /* Roll for ego-item */
                                if (randint0(MAX_DEPTH) < level)
                                {
-                                       while(1)
+                                       while (1)
                                        {
                                                o_ptr->name2 = get_random_ego(INVEN_RARM, FALSE);
                                                if (o_ptr->name2 == EGO_WEIRD && o_ptr->tval != TV_SWORD)
@@ -2371,16 +2174,18 @@ static void a_m_aux_1(object_type *o_ptr, DEPTH level, int power)
                                        }
                                        switch (o_ptr->name2)
                                        {
-                                       case EGO_MORGUL:
-                                               if (one_in_(6)) add_flag(o_ptr->art_flags, TR_TY_CURSE);
-                                               if (one_in_(3)) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
-                                       case EGO_WEIRD:
-                                               if (one_in_(4)) add_flag(o_ptr->art_flags, TR_BRAND_POIS);
-                                               if (one_in_(4)) add_flag(o_ptr->art_flags, TR_RES_NETHER);
-                                               if (one_in_(3)) add_flag(o_ptr->art_flags, TR_NO_MAGIC);
-                                               if (one_in_(6)) add_flag(o_ptr->art_flags, TR_NO_TELE);
-                                               if (one_in_(6)) add_flag(o_ptr->art_flags, TR_TY_CURSE);
-                                               if (one_in_(6)) add_flag(o_ptr->art_flags, TR_ADD_H_CURSE);
+                                               case EGO_MORGUL:
+                                                       if (one_in_(6)) add_flag(o_ptr->art_flags, TR_TY_CURSE);
+                                                       if (one_in_(3)) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
+                                                       break;
+                                               case EGO_WEIRD:
+                                                       if (one_in_(4)) add_flag(o_ptr->art_flags, TR_BRAND_POIS);
+                                                       if (one_in_(4)) add_flag(o_ptr->art_flags, TR_RES_NETHER);
+                                                       if (one_in_(3)) add_flag(o_ptr->art_flags, TR_NO_MAGIC);
+                                                       if (one_in_(6)) add_flag(o_ptr->art_flags, TR_NO_TELE);
+                                                       if (one_in_(6)) add_flag(o_ptr->art_flags, TR_TY_CURSE);
+                                                       if (one_in_(6)) add_flag(o_ptr->art_flags, TR_ADD_H_CURSE);
+                                                       break;
                                        }
                                }
                        }
@@ -2396,7 +2201,7 @@ static void a_m_aux_1(object_type *o_ptr, DEPTH level, int power)
                        {
                                if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
                                {
-                                       create_artifact(o_ptr, FALSE);
+                                       become_random_artifact(o_ptr, FALSE);
                                        break;
                                }
                                o_ptr->name2 = get_random_ego(INVEN_BOW, TRUE);
@@ -2415,7 +2220,7 @@ static void a_m_aux_1(object_type *o_ptr, DEPTH level, int power)
                        {
                                if (power > 2) /* power > 2 is debug only */
                                {
-                                       create_artifact(o_ptr, FALSE);
+                                       become_random_artifact(o_ptr, FALSE);
                                        break;
                                }
 
@@ -2451,77 +2256,6 @@ static void a_m_aux_1(object_type *o_ptr, DEPTH level, int power)
 }
 
 /*!
- * @brief ドラゴン装備にランダムな耐性を与える
- * @param o_ptr 強化を与えたいオブジェクトの構造体参照ポインタ
- * @return なし
- */
-static void dragon_resist(object_type * o_ptr)
-{
-       do
-       {
-               if (one_in_(4))
-                       one_dragon_ele_resistance(o_ptr);
-               else
-                       one_high_resistance(o_ptr);
-       }
-       while (one_in_(2));
-}
-
-/*!
- * @brief オブジェクトにランダムな強いESPを与える
- * @param o_ptr 強化を与えたいオブジェクトの構造体参照ポインタ
- * @return なし
- */
-static bool add_esp_strong(object_type *o_ptr)
-{
-       bool nonliv = FALSE;
-
-       switch (randint1(3))
-       {
-       case 1: add_flag(o_ptr->art_flags, TR_ESP_EVIL); break;
-       case 2: add_flag(o_ptr->art_flags, TR_TELEPATHY); break;
-       case 3: add_flag(o_ptr->art_flags, TR_ESP_NONLIVING); nonliv = TRUE; break;
-       }
-
-       return nonliv;
-}
-
-/*!
- * @brief オブジェクトにランダムな弱いESPを与える
- * @param o_ptr 強化を与えたいオブジェクトの構造体参照ポインタ
- * @param extra TRUEならばESPの最大付与数が増える(TRUE -> 3+1d6 / FALSE -> 1d3)
- * @return なし
- */
-static void add_esp_weak(object_type *o_ptr, bool extra)
-{
-       int i;
-       u32b weak_esp_list[] = {
-               TR_ESP_ANIMAL,
-               TR_ESP_UNDEAD,
-               TR_ESP_DEMON,
-               TR_ESP_ORC,
-               TR_ESP_TROLL,
-               TR_ESP_GIANT,
-               TR_ESP_DRAGON,
-               TR_ESP_HUMAN,
-               TR_ESP_GOOD,
-               TR_ESP_UNIQUE,
-       };
-       const int MAX_ESP_WEAK = sizeof(weak_esp_list) / sizeof(weak_esp_list[0]);
-       const int add_count = MIN(MAX_ESP_WEAK, (extra) ? (3 + randint1(randint1(6))) : randint1(3));
-
-       /* Add unduplicated weak esp flags randomly */
-       for (i = 0; i < add_count; ++ i)
-       {
-               int choice = rand_range(i, MAX_ESP_WEAK - 1);
-
-               add_flag(o_ptr->art_flags, weak_esp_list[choice]);
-               weak_esp_list[choice] = weak_esp_list[i];
-       }
-}
-
-
-/*!
  * @brief 防具系オブジェクトに生成ランクごとの強化を与えるサブルーチン
  * Apply magic to an item known to be "armor"
  * @param o_ptr 強化を与えたいオブジェクトの構造体参照ポインタ
@@ -2573,7 +2307,7 @@ static void a_m_aux_2(object_type *o_ptr, DEPTH level, int power)
                case TV_DRAG_ARMOR:
                {
                        if (one_in_(50) || (power > 2)) /* power > 2 is debug only */
-                               create_artifact(o_ptr, FALSE);
+                               become_random_artifact(o_ptr, FALSE);
                        break;
                }
 
@@ -2605,7 +2339,7 @@ static void a_m_aux_2(object_type *o_ptr, DEPTH level, int power)
 
                                if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
                                {
-                                       create_artifact(o_ptr, FALSE);
+                                       become_random_artifact(o_ptr, FALSE);
                                        break;
                                }
 
@@ -2693,7 +2427,7 @@ static void a_m_aux_2(object_type *o_ptr, DEPTH level, int power)
                        {
                                if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
                                {
-                                       create_artifact(o_ptr, FALSE);
+                                       become_random_artifact(o_ptr, FALSE);
                                        break;
                                }
                                
@@ -2739,7 +2473,7 @@ static void a_m_aux_2(object_type *o_ptr, DEPTH level, int power)
                        {
                                if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
                                {
-                                       create_artifact(o_ptr, FALSE);
+                                       become_random_artifact(o_ptr, FALSE);
                                        break;
                                }
                                o_ptr->name2 = get_random_ego(INVEN_HANDS, TRUE);
@@ -2766,7 +2500,7 @@ static void a_m_aux_2(object_type *o_ptr, DEPTH level, int power)
                        {
                                if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
                                {
-                                       create_artifact(o_ptr, FALSE);
+                                       become_random_artifact(o_ptr, FALSE);
                                        break;
                                }
                                o_ptr->name2 = get_random_ego(INVEN_FEET, TRUE);
@@ -2797,7 +2531,7 @@ static void a_m_aux_2(object_type *o_ptr, DEPTH level, int power)
                        {
                                if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
                                {
-                                       create_artifact(o_ptr, FALSE);
+                                       become_random_artifact(o_ptr, FALSE);
                                        break;
                                }
                                while (1)
@@ -2873,7 +2607,7 @@ static void a_m_aux_2(object_type *o_ptr, DEPTH level, int power)
                        {
                                if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
                                {
-                                       create_artifact(o_ptr, FALSE);
+                                       become_random_artifact(o_ptr, FALSE);
                                        break;
                                }
                                while (1)
@@ -2951,7 +2685,7 @@ static void a_m_aux_2(object_type *o_ptr, DEPTH level, int power)
                        {
                                if (one_in_(20) || (power > 2)) /* power > 2 is debug only */
                                {
-                                       create_artifact(o_ptr, FALSE);
+                                       become_random_artifact(o_ptr, FALSE);
                                        break;
                                }
                                o_ptr->name2 = get_random_ego(INVEN_OUTER, TRUE);
@@ -3300,7 +3034,7 @@ static void a_m_aux_3(object_type *o_ptr, DEPTH level, int power)
                        {
                                o_ptr->pval = MIN(o_ptr->pval, 4);
                                /* Randart amulet */
-                               create_artifact(o_ptr, FALSE);
+                               become_random_artifact(o_ptr, FALSE);
                        }
                        else if ((power == 2) && one_in_(2))
                        {
@@ -3632,7 +3366,7 @@ static void a_m_aux_3(object_type *o_ptr, DEPTH level, int power)
                        {
                                o_ptr->pval = MIN(o_ptr->pval, 4);
                                /* Randart amulet */
-                               create_artifact(o_ptr, FALSE);
+                               become_random_artifact(o_ptr, FALSE);
                        }
                        else if ((power == 2) && one_in_(2))
                        {
@@ -3775,26 +3509,6 @@ static void a_m_aux_3(object_type *o_ptr, DEPTH level, int power)
        }
 }
 
-/*!
- * @brief モンスターが人形のベースにできるかを返す
- * @param r_idx チェックしたいモンスター種族のID
- * @return 人形にできるならTRUEを返す
- */
-static bool item_monster_okay(MONRACE_IDX r_idx)
-{
-       monster_race *r_ptr = &r_info[r_idx];
-
-       /* No uniques */
-       if (r_ptr->flags1 & RF1_UNIQUE) return (FALSE);
-       if (r_ptr->flags7 & RF7_KAGE) return (FALSE);
-       if (r_ptr->flagsr & RFR_RES_ALL) return (FALSE);
-       if (r_ptr->flags7 & RF7_NAZGUL) return (FALSE);
-       if (r_ptr->flags1 & RF1_FORCE_DEPTH) return (FALSE);
-       if (r_ptr->flags7 & RF7_UNIQUE2) return (FALSE);
-
-       return (TRUE);
-}
-
 
 /*!
  * @brief その他雑多のオブジェクトに生成ランクごとの強化を与えるサブルーチン
@@ -3855,7 +3569,7 @@ static void a_m_aux_4(object_type *o_ptr, DEPTH level, int power)
 
                        if (power > 2) /* power > 2 is debug only */
                        {
-                               create_artifact(o_ptr, FALSE);
+                               become_random_artifact(o_ptr, FALSE);
                        }
                        else if ((power == 2) || ((power == 1) && one_in_(3)))
                        {
@@ -3948,7 +3662,7 @@ static void a_m_aux_4(object_type *o_ptr, DEPTH level, int power)
 
                                r_ptr = &r_info[i];
 
-                               check = (current_floor_ptr->dun_level < r_ptr->level) ? (r_ptr->level - current_floor_ptr->dun_level) : 0;
+                               check = (p_ptr->current_floor_ptr->dun_level < r_ptr->level) ? (r_ptr->level - p_ptr->current_floor_ptr->dun_level) : 0;
 
                                /* Ignore dead monsters */
                                if (!r_ptr->rarity) continue;
@@ -3994,11 +3708,11 @@ static void a_m_aux_4(object_type *o_ptr, DEPTH level, int power)
                        /* Pick a random non-unique monster race */
                        while (1)
                        {
-                               i = get_mon_num(current_floor_ptr->dun_level);
+                               i = get_mon_num(p_ptr->current_floor_ptr->dun_level);
 
                                r_ptr = &r_info[i];
 
-                               check = (current_floor_ptr->dun_level < r_ptr->level) ? (r_ptr->level - current_floor_ptr->dun_level) : 0;
+                               check = (p_ptr->current_floor_ptr->dun_level < r_ptr->level) ? (r_ptr->level - p_ptr->current_floor_ptr->dun_level) : 0;
 
                                /* Ignore dead monsters */
                                if (!r_ptr->rarity) continue;
@@ -4062,7 +3776,7 @@ static void a_m_aux_4(object_type *o_ptr, DEPTH level, int power)
                        o_ptr->pval = randint1(obj_level);
                        if (o_ptr->sval == SV_CHEST_KANDUME) o_ptr->pval = 6;
 
-                       o_ptr->xtra3 = current_floor_ptr->dun_level + 5;
+                       o_ptr->xtra3 = p_ptr->current_floor_ptr->dun_level + 5;
 
                        /* Never exceed "difficulty" of 55 to 59 */
                        if (o_ptr->pval > 55) o_ptr->pval = 55 + (byte)randint0(5);
@@ -4218,7 +3932,7 @@ void apply_magic(object_type *o_ptr, DEPTH lev, BIT_FLAGS mode)
                a_ptr->cur_num = 1;
 
                /* Hack -- Memorize location of artifact in saved floors */
-               if (character_dungeon)
+               if (current_world_ptr->character_dungeon)
                        a_ptr->floor_id = p_ptr->floor_id;
 
                /* Extract the other fields */
@@ -4263,19 +3977,19 @@ void apply_magic(object_type *o_ptr, DEPTH lev, BIT_FLAGS mode)
                case TV_ARROW:
                case TV_BOLT:
                {
-                       if (power) a_m_aux_1(o_ptr, lev, power);
+                       if (power) apply_magic_weapon(o_ptr, lev, power);
                        break;
                }
 
                case TV_POLEARM:
                {
-                       if (power && !(o_ptr->sval == SV_DEATH_SCYTHE)) a_m_aux_1(o_ptr, lev, power);
+                       if (power && !(o_ptr->sval == SV_DEATH_SCYTHE)) apply_magic_weapon(o_ptr, lev, power);
                        break;
                }
 
                case TV_SWORD:
                {
-                       if (power && !(o_ptr->sval == SV_DOKUBARI)) a_m_aux_1(o_ptr, lev, power);
+                       if (power && !(o_ptr->sval == SV_DOKUBARI)) apply_magic_weapon(o_ptr, lev, power);
                        break;
                }
 
@@ -4510,92 +4224,6 @@ void apply_magic(object_type *o_ptr, DEPTH lev, BIT_FLAGS mode)
 
 
 /*!
- * @brief ベースアイテムが上質として扱われるかどうかを返す。
- * Hack -- determine if a template is "good"
- * @param k_idx 判定したいベースアイテムのID
- * @return ベースアイテムが上質ならばTRUEを返す。
- */
-static bool kind_is_good(KIND_OBJECT_IDX k_idx)
-{
-       object_kind *k_ptr = &k_info[k_idx];
-
-       /* Analyze the item type */
-       switch (k_ptr->tval)
-       {
-               /* Armor -- Good unless damaged */
-               case TV_HARD_ARMOR:
-               case TV_SOFT_ARMOR:
-               case TV_DRAG_ARMOR:
-               case TV_SHIELD:
-               case TV_CLOAK:
-               case TV_BOOTS:
-               case TV_GLOVES:
-               case TV_HELM:
-               case TV_CROWN:
-               {
-                       if (k_ptr->to_a < 0) return (FALSE);
-                       return (TRUE);
-               }
-
-               /* Weapons -- Good unless damaged */
-               case TV_BOW:
-               case TV_SWORD:
-               case TV_HAFTED:
-               case TV_POLEARM:
-               case TV_DIGGING:
-               {
-                       if (k_ptr->to_h < 0) return (FALSE);
-                       if (k_ptr->to_d < 0) return (FALSE);
-                       return (TRUE);
-               }
-
-               /* Ammo -- Arrows/Bolts are good */
-               case TV_BOLT:
-               case TV_ARROW:
-               {
-                       return (TRUE);
-               }
-
-               /* Books -- High level books are good (except Arcane books) */
-               case TV_LIFE_BOOK:
-               case TV_SORCERY_BOOK:
-               case TV_NATURE_BOOK:
-               case TV_CHAOS_BOOK:
-               case TV_DEATH_BOOK:
-               case TV_TRUMP_BOOK:
-               case TV_CRAFT_BOOK:
-               case TV_DAEMON_BOOK:
-               case TV_CRUSADE_BOOK:
-               case TV_MUSIC_BOOK:
-               case TV_HISSATSU_BOOK:
-               case TV_HEX_BOOK:
-               {
-                       if (k_ptr->sval >= SV_BOOK_MIN_GOOD) return (TRUE);
-                       return (FALSE);
-               }
-
-               /* Rings -- Rings of Speed are good */
-               case TV_RING:
-               {
-                       if (k_ptr->sval == SV_RING_SPEED) return (TRUE);
-                       if (k_ptr->sval == SV_RING_LORDLY) return (TRUE);
-                       return (FALSE);
-               }
-
-               /* Amulets -- Amulets of the Magi and Resistance are good */
-               case TV_AMULET:
-               {
-                       if (k_ptr->sval == SV_AMULET_THE_MAGI) return (TRUE);
-                       if (k_ptr->sval == SV_AMULET_RESISTANCE) return (TRUE);
-                       return (FALSE);
-               }
-       }
-
-       /* Assume not good */
-       return (FALSE);
-}
-
-/*!
  * @brief 生成階に応じたベースアイテムの生成を行う。
  * Attempt to make an object (normal or good/great)
  * @param j_ptr 生成結果を収めたいオブジェクト構造体の参照ポインタ
@@ -4603,7 +4231,7 @@ static bool kind_is_good(KIND_OBJECT_IDX k_idx)
  * @return 生成に成功したらTRUEを返す。
  * @details
  * This routine plays nasty games to generate the "special artifacts".\n
- * This routine uses "current_floor_ptr->object_level" for the "generation level".\n
+ * This routine uses "p_ptr->current_floor_ptr->object_level" for the "generation level".\n
  * We assume that the given object has been "wiped".\n
  */
 bool make_object(object_type *j_ptr, BIT_FLAGS mode)
@@ -4616,7 +4244,7 @@ bool make_object(object_type *j_ptr, BIT_FLAGS mode)
        prob = ((mode & AM_GOOD) ? 10 : 1000);
 
        /* Base level for the object */
-       base = ((mode & AM_GOOD) ? (current_floor_ptr->object_level + 10) : current_floor_ptr->object_level);
+       base = ((mode & AM_GOOD) ? (p_ptr->current_floor_ptr->object_level + 10) : p_ptr->current_floor_ptr->object_level);
 
 
        /* Generate a special object, or a normal object */
@@ -4635,7 +4263,7 @@ bool make_object(object_type *j_ptr, BIT_FLAGS mode)
                if (get_obj_num_hook) get_obj_num_prep();
 
                /* Pick a random object */
-               k_idx = get_obj_num(base);
+               k_idx = get_obj_num(base, mode);
 
                /* Restricted objects */
                if (get_obj_num_hook)
@@ -4655,7 +4283,7 @@ bool make_object(object_type *j_ptr, BIT_FLAGS mode)
        }
 
        /* Apply magic (allow artifacts) */
-       apply_magic(j_ptr, current_floor_ptr->object_level, mode);
+       apply_magic(j_ptr, p_ptr->current_floor_ptr->object_level, mode);
 
        /* Hack -- generate multiple spikes/missiles */
        switch (j_ptr->tval)
@@ -4686,7 +4314,7 @@ bool make_object(object_type *j_ptr, BIT_FLAGS mode)
  * @return 生成に成功したらTRUEを返す。
  * @details
  * This routine plays nasty games to generate the "special artifacts".\n
- * This routine uses "current_floor_ptr->object_level" for the "generation level".\n
+ * This routine uses "p_ptr->current_floor_ptr->object_level" for the "generation level".\n
  * This routine requires a clean floor grid destination.\n
  */
 void place_object(POSITION y, POSITION x, BIT_FLAGS mode)
@@ -4694,17 +4322,17 @@ void place_object(POSITION y, POSITION x, BIT_FLAGS mode)
        OBJECT_IDX o_idx;
 
        /* Acquire grid */
-       grid_type *g_ptr = &current_floor_ptr->grid_array[y][x];
+       grid_type *g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
 
        object_type forge;
        object_type *q_ptr;
 
 
        /* Paranoia -- check bounds */
-       if (!in_bounds(y, x)) return;
+       if (!in_bounds(p_ptr->current_floor_ptr, y, x)) return;
 
        /* Require floor space */
-       if (!cave_drop_bold(y, x)) return;
+       if (!cave_drop_bold(p_ptr->current_floor_ptr, y, x)) return;
 
        /* Avoid stacking on other objects */
        if (g_ptr->o_idx) return;
@@ -4715,15 +4343,13 @@ void place_object(POSITION y, POSITION x, BIT_FLAGS mode)
        /* Make an object (if possible) */
        if (!make_object(q_ptr, mode)) return;
 
-
-       /* Make an object */
        o_idx = o_pop();
 
        /* Success */
        if (o_idx)
        {
                object_type *o_ptr;
-               o_ptr = &current_floor_ptr->o_list[o_idx];
+               o_ptr = &p_ptr->current_floor_ptr->o_list[o_idx];
 
                /* Structure Copy */
                object_copy(o_ptr, q_ptr);
@@ -4734,11 +4360,8 @@ void place_object(POSITION y, POSITION x, BIT_FLAGS mode)
                /* Build a stack */
                o_ptr->next_o_idx = g_ptr->o_idx;
 
-               /* Place the object */
                g_ptr->o_idx = o_idx;
-
                note_spot(y, x);
-
                lite_spot(y, x);
        }
        else
@@ -4752,6 +4375,8 @@ void place_object(POSITION y, POSITION x, BIT_FLAGS mode)
 }
 
 
+OBJECT_SUBTYPE_VALUE coin_type;        /* Hack -- force coin type */
+
 /*!
  * @brief 生成階に応じた財宝オブジェクトの生成を行う。
  * Make a treasure object
@@ -4766,12 +4391,12 @@ bool make_gold(object_type *j_ptr)
        s32b base;
 
        /* Hack -- Pick a Treasure variety */
-       i = ((randint1(current_floor_ptr->object_level + 2) + 2) / 2) - 1;
+       i = ((randint1(p_ptr->current_floor_ptr->object_level + 2) + 2) / 2) - 1;
 
        /* Apply "extra" magic */
        if (one_in_(GREAT_OBJ))
        {
-               i += randint1(current_floor_ptr->object_level + 1);
+               i += randint1(p_ptr->current_floor_ptr->object_level + 1);
        }
 
        /* Hack -- Creeping Coins only generate "themselves" */
@@ -4808,17 +4433,17 @@ void place_gold(POSITION y, POSITION x)
        OBJECT_IDX o_idx;
 
        /* Acquire grid */
-       grid_type *g_ptr = &current_floor_ptr->grid_array[y][x];
+       grid_type *g_ptr = &p_ptr->current_floor_ptr->grid_array[y][x];
 
        object_type forge;
        object_type *q_ptr;
 
 
        /* Paranoia -- check bounds */
-       if (!in_bounds(y, x)) return;
+       if (!in_bounds(p_ptr->current_floor_ptr, y, x)) return;
 
        /* Require floor space */
-       if (!cave_drop_bold(y, x)) return;
+       if (!cave_drop_bold(p_ptr->current_floor_ptr, y, x)) return;
 
        /* Avoid stacking on other objects */
        if (g_ptr->o_idx) return;
@@ -4829,16 +4454,13 @@ void place_gold(POSITION y, POSITION x)
        /* Make some gold */
        if (!make_gold(q_ptr)) return;
 
-       /* Make an object */
        o_idx = o_pop();
 
        /* Success */
        if (o_idx)
        {
                object_type *o_ptr;
-               o_ptr = &current_floor_ptr->o_list[o_idx];
-
-               /* Copy the object */
+               o_ptr = &p_ptr->current_floor_ptr->o_list[o_idx];
                object_copy(o_ptr, q_ptr);
 
                /* Save location */
@@ -4848,11 +4470,8 @@ void place_gold(POSITION y, POSITION x)
                /* Build a stack */
                o_ptr->next_o_idx = g_ptr->o_idx;
 
-               /* Place the object */
                g_ptr->o_idx = o_idx;
-
                note_spot(y, x);
-
                lite_spot(y, x);
        }
 }
@@ -4862,12 +4481,12 @@ void place_gold(POSITION y, POSITION x)
  * @brief 生成済のオブジェクトをフロアの所定の位置に落とす。
  * Let an object fall to the ground at or near a location.
  * @param j_ptr 落としたいオブジェクト構造体の参照ポインタ
- * @param chance ã\83\89ã\83­ã\83\83ã\83\97ã\81®æ\88\90å\8a\9f率(%)
+ * @param chance ã\83\89ã\83­ã\83\83ã\83\97ã\81®æ\88æ»\85率(%)
  * @param y 配置したいフロアのY座標
  * @param x 配置したいフロアのX座標
  * @return 生成に成功したらオブジェクトのIDを返す。
  * @details
- * The initial location is assumed to be "in_bounds()".\n
+ * The initial location is assumed to be "in_bounds(p_ptr->current_floor_ptr, )".\n
  *\n
  * This function takes a parameter "chance".  This is the percentage\n
  * chance that the item will "disappear" instead of drop.  If the object\n
@@ -4916,7 +4535,7 @@ OBJECT_IDX drop_near(object_type *j_ptr, PERCENTAGE chance, POSITION y, POSITION
 #else
                msg_format("The %s disappear%s.", o_name, (plural ? "" : "s"));
 #endif
-               if (p_ptr->wizard) msg_print(_("(破損)", "(breakage)"));
+               if (current_world_ptr->wizard) msg_print(_("(破損)", "(breakage)"));
 
                /* Failure */
                return (0);
@@ -4950,17 +4569,16 @@ OBJECT_IDX drop_near(object_type *j_ptr, PERCENTAGE chance, POSITION y, POSITION
                        ty = y + dy;
                        tx = x + dx;
 
-                       /* Skip illegal grids */
-                       if (!in_bounds(ty, tx)) continue;
+                       if (!in_bounds(p_ptr->current_floor_ptr, ty, tx)) continue;
 
                        /* Require line of projection */
-                       if (!projectable(y, x, ty, tx)) continue;
+                       if (!projectable(p_ptr->current_floor_ptr, y, x, ty, tx)) continue;
 
                        /* Obtain grid */
-                       g_ptr = &current_floor_ptr->grid_array[ty][tx];
+                       g_ptr = &p_ptr->current_floor_ptr->grid_array[ty][tx];
 
                        /* Require floor space */
-                       if (!cave_drop_bold(ty, tx)) continue;
+                       if (!cave_drop_bold(p_ptr->current_floor_ptr, ty, tx)) continue;
 
                        /* No objects */
                        k = 0;
@@ -4969,7 +4587,7 @@ OBJECT_IDX drop_near(object_type *j_ptr, PERCENTAGE chance, POSITION y, POSITION
                        for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
                        {
                                object_type *o_ptr;
-                               o_ptr = &current_floor_ptr->o_list[this_o_idx];
+                               o_ptr = &p_ptr->current_floor_ptr->o_list[this_o_idx];
                                next_o_idx = o_ptr->next_o_idx;
 
                                /* Check for possible combination */
@@ -4981,8 +4599,6 @@ OBJECT_IDX drop_near(object_type *j_ptr, PERCENTAGE chance, POSITION y, POSITION
 
                        /* Add new object */
                        if (!comb) k++;
-
-                       /* Paranoia */
                        if (k > 99) continue;
 
                        /* Calculate score */
@@ -5018,7 +4634,7 @@ OBJECT_IDX drop_near(object_type *j_ptr, PERCENTAGE chance, POSITION y, POSITION
                msg_format("The %s disappear%s.", o_name, (plural ? "" : "s"));
 #endif
 
-               if (p_ptr->wizard) msg_print(_("(床スペースがない)", "(no floor space)"));
+               if (current_world_ptr->wizard) msg_print(_("(床スペースがない)", "(no floor space)"));
 
                /* Failure */
                return (0);
@@ -5032,15 +4648,14 @@ OBJECT_IDX drop_near(object_type *j_ptr, PERCENTAGE chance, POSITION y, POSITION
                ty = rand_spread(by, 1);
                tx = rand_spread(bx, 1);
 
-               /* Verify location */
-               if (!in_bounds(ty, tx)) continue;
+               if (!in_bounds(p_ptr->current_floor_ptr, ty, tx)) continue;
 
                /* Bounce to that location */
                by = ty;
                bx = tx;
 
                /* Require floor space */
-               if (!cave_drop_bold(by, bx)) continue;
+               if (!cave_drop_bold(p_ptr->current_floor_ptr, by, bx)) continue;
 
                flag = TRUE;
        }
@@ -5050,12 +4665,12 @@ OBJECT_IDX drop_near(object_type *j_ptr, PERCENTAGE chance, POSITION y, POSITION
        {
                int candidates = 0, pick;
 
-               for (ty = 1; ty < current_floor_ptr->height - 1; ty++)
+               for (ty = 1; ty < p_ptr->current_floor_ptr->height - 1; ty++)
                {
-                       for (tx = 1; tx < current_floor_ptr->width - 1; tx++)
+                       for (tx = 1; tx < p_ptr->current_floor_ptr->width - 1; tx++)
                        {
                                /* A valid space found */
-                               if (cave_drop_bold(ty, tx)) candidates++;
+                               if (cave_drop_bold(p_ptr->current_floor_ptr, ty, tx)) candidates++;
                        }
                }
 
@@ -5068,7 +4683,7 @@ OBJECT_IDX drop_near(object_type *j_ptr, PERCENTAGE chance, POSITION y, POSITION
                        msg_format("The %s disappear%s.", o_name, (plural ? "" : "s"));
 #endif
 
-                       if (p_ptr->wizard) msg_print(_("(床スペースがない)", "(no floor space)"));
+                       if (current_world_ptr->wizard) msg_print(_("(床スペースがない)", "(no floor space)"));
 
                        /* Mega-Hack -- preserve artifacts */
                        if (preserve_mode)
@@ -5088,11 +4703,11 @@ OBJECT_IDX drop_near(object_type *j_ptr, PERCENTAGE chance, POSITION y, POSITION
                /* Choose a random one */
                pick = randint1(candidates);
 
-               for (ty = 1; ty < current_floor_ptr->height - 1; ty++)
+               for (ty = 1; ty < p_ptr->current_floor_ptr->height - 1; ty++)
                {
-                       for (tx = 1; tx < current_floor_ptr->width - 1; tx++)
+                       for (tx = 1; tx < p_ptr->current_floor_ptr->width - 1; tx++)
                        {
-                               if (cave_drop_bold(ty, tx))
+                               if (cave_drop_bold(p_ptr->current_floor_ptr, ty, tx))
                                {
                                        pick--;
 
@@ -5109,13 +4724,13 @@ OBJECT_IDX drop_near(object_type *j_ptr, PERCENTAGE chance, POSITION y, POSITION
        }
 
 
-       g_ptr = &current_floor_ptr->grid_array[by][bx];
+       g_ptr = &p_ptr->current_floor_ptr->grid_array[by][bx];
 
        /* Scan objects in that grid for combination */
        for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
        {
                object_type *o_ptr;
-               o_ptr = &current_floor_ptr->o_list[this_o_idx];
+               o_ptr = &p_ptr->current_floor_ptr->o_list[this_o_idx];
                next_o_idx = o_ptr->next_o_idx;
 
                /* Check for combination */
@@ -5141,7 +4756,7 @@ OBJECT_IDX drop_near(object_type *j_ptr, PERCENTAGE chance, POSITION y, POSITION
                msg_format("The %s disappear%s.", o_name, (plural ? "" : "s"));
 #endif
 
-               if (p_ptr->wizard) msg_print(_("(アイテムが多過ぎる)", "(too many objects)"));
+               if (current_world_ptr->wizard) msg_print(_("(アイテムが多過ぎる)", "(too many objects)"));
 
                /* Hack -- Preserve artifacts */
                if (object_is_fixed_artifact(j_ptr))
@@ -5157,10 +4772,10 @@ OBJECT_IDX drop_near(object_type *j_ptr, PERCENTAGE chance, POSITION y, POSITION
        if (!done)
        {
                /* Structure copy */
-               object_copy(&current_floor_ptr->o_list[o_idx], j_ptr);
+               object_copy(&p_ptr->current_floor_ptr->o_list[o_idx], j_ptr);
 
                /* Access new object */
-               j_ptr = &current_floor_ptr->o_list[o_idx];
+               j_ptr = &p_ptr->current_floor_ptr->o_list[o_idx];
 
                /* Locate */
                j_ptr->iy = by;
@@ -5172,7 +4787,6 @@ OBJECT_IDX drop_near(object_type *j_ptr, PERCENTAGE chance, POSITION y, POSITION
                /* Build a stack */
                j_ptr->next_o_idx = g_ptr->o_idx;
 
-               /* Place the object */
                g_ptr->o_idx = o_idx;
 
                /* Success */
@@ -5185,7 +4799,7 @@ OBJECT_IDX drop_near(object_type *j_ptr, PERCENTAGE chance, POSITION y, POSITION
 
        /* Mega-Hack -- no message if "dropped" by player */
        /* Message when an object falls under the player */
-       if (chance && player_bold(by, bx))
+       if (chance && player_bold(p_ptr, by, bx))
        {
                msg_print(_("何かが足下に転がってきた。", "You feel something roll beneath your feet."));
        }
@@ -5201,7 +4815,7 @@ OBJECT_IDX drop_near(object_type *j_ptr, PERCENTAGE chance, POSITION y, POSITION
  */
 void inven_item_charges(INVENTORY_IDX item)
 {
-       object_type *o_ptr = &inventory[item];
+       object_type *o_ptr = &p_ptr->inventory_list[item];
 
        /* Require staff/wand */
        if ((o_ptr->tval != TV_STAFF) && (o_ptr->tval != TV_WAND)) return;
@@ -5242,7 +4856,7 @@ void inven_item_charges(INVENTORY_IDX item)
  */
 void inven_item_describe(INVENTORY_IDX item)
 {
-       object_type *o_ptr = &inventory[item];
+       object_type *o_ptr = &p_ptr->inventory_list[item];
        GAME_TEXT o_name[MAX_NLEN];
 
        object_desc(o_name, o_ptr, 0);
@@ -5265,6 +4879,22 @@ void inven_item_describe(INVENTORY_IDX item)
 
 }
 
+void vary_item(INVENTORY_IDX item, ITEM_NUMBER num)
+{
+       if (item >= 0)
+       {
+               inven_item_increase(item, num);
+               inven_item_describe(item);
+               inven_item_optimize(item);
+       }
+       else
+       {
+               floor_item_increase(0 - item, num);
+               floor_item_describe(0 - item);
+               floor_item_optimize(0 - item);
+       }
+}
+
 /*!
  * @brief アイテムを増減させ残り所持数メッセージを表示する /
  * Increase the "number" of an item in the inventory
@@ -5274,7 +4904,7 @@ void inven_item_describe(INVENTORY_IDX item)
  */
 void inven_item_increase(INVENTORY_IDX item, ITEM_NUMBER num)
 {
-       object_type *o_ptr = &inventory[item];
+       object_type *o_ptr = &p_ptr->inventory_list[item];
 
        /* Apply */
        num += o_ptr->number;
@@ -5304,10 +4934,10 @@ void inven_item_increase(INVENTORY_IDX item, ITEM_NUMBER num)
                {
                        if ((item == INVEN_RARM) || (item == INVEN_LARM))
                        {
-                               if (!has_melee_weapon(INVEN_RARM + INVEN_LARM - item))
+                               if (!has_melee_weapon(p_ptr, INVEN_RARM + INVEN_LARM - item))
                                {
                                        /* Clear all temporary elemental brands */
-                                       set_ele_attack(0, 0);
+                                       set_ele_attack(p_ptr, 0, 0);
                                }
                        }
                }
@@ -5322,7 +4952,7 @@ void inven_item_increase(INVENTORY_IDX item, ITEM_NUMBER num)
  */
 void inven_item_optimize(INVENTORY_IDX item)
 {
-       object_type *o_ptr = &inventory[item];
+       object_type *o_ptr = &p_ptr->inventory_list[item];
 
        /* Only optimize real items */
        if (!o_ptr->k_idx) return;
@@ -5336,17 +4966,17 @@ void inven_item_optimize(INVENTORY_IDX item)
                int i;
 
                /* One less item */
-               inven_cnt--;
+               p_ptr->inven_cnt--;
 
                /* Slide everything down */
                for (i = item; i < INVEN_PACK; i++)
                {
                        /* Structure copy */
-                       inventory[i] = inventory[i+1];
+                       p_ptr->inventory_list[i] = p_ptr->inventory_list[i+1];
                }
 
                /* Erase the "final" slot */
-               object_wipe(&inventory[i]);
+               object_wipe(&p_ptr->inventory_list[i]);
 
                p_ptr->window |= (PW_INVEN);
        }
@@ -5355,10 +4985,10 @@ void inven_item_optimize(INVENTORY_IDX item)
        else
        {
                /* One less item */
-               equip_cnt--;
+               p_ptr->equip_cnt--;
 
                /* Erase the empty slot */
-               object_wipe(&inventory[item]);
+               object_wipe(&p_ptr->inventory_list[item]);
                p_ptr->update |= (PU_BONUS);
                p_ptr->update |= (PU_TORCH);
                p_ptr->update |= (PU_MANA);
@@ -5377,7 +5007,7 @@ void inven_item_optimize(INVENTORY_IDX item)
  */
 void floor_item_charges(INVENTORY_IDX item)
 {
-       object_type *o_ptr = &current_floor_ptr->o_list[item];
+       object_type *o_ptr = &p_ptr->current_floor_ptr->o_list[item];
 
        /* Require staff/wand */
        if ((o_ptr->tval != TV_STAFF) && (o_ptr->tval != TV_WAND)) return;
@@ -5418,7 +5048,7 @@ void floor_item_charges(INVENTORY_IDX item)
  */
 void floor_item_describe(INVENTORY_IDX item)
 {
-       object_type *o_ptr = &current_floor_ptr->o_list[item];
+       object_type *o_ptr = &p_ptr->current_floor_ptr->o_list[item];
        GAME_TEXT o_name[MAX_NLEN];
 
        object_desc(o_name, o_ptr, 0);
@@ -5449,7 +5079,7 @@ void floor_item_describe(INVENTORY_IDX item)
  */
 void floor_item_increase(INVENTORY_IDX item, ITEM_NUMBER num)
 {
-       object_type *o_ptr = &current_floor_ptr->o_list[item];
+       object_type *o_ptr = &p_ptr->current_floor_ptr->o_list[item];
 
        /* Apply */
        num += o_ptr->number;
@@ -5474,7 +5104,7 @@ void floor_item_increase(INVENTORY_IDX item, ITEM_NUMBER num)
  */
 void floor_item_optimize(INVENTORY_IDX item)
 {
-       object_type *o_ptr = &current_floor_ptr->o_list[item];
+       object_type *o_ptr = &p_ptr->current_floor_ptr->o_list[item];
 
        /* Paranoia -- be sure it exists */
        if (!o_ptr->k_idx) return;
@@ -5497,14 +5127,12 @@ bool inven_carry_okay(object_type *o_ptr)
        int j;
 
        /* Empty slot? */
-       if (inven_cnt < INVEN_PACK) return (TRUE);
+       if (p_ptr->inven_cnt < INVEN_PACK) return (TRUE);
 
        /* Similar slot? */
        for (j = 0; j < INVEN_PACK; j++)
        {
-               object_type *j_ptr = &inventory[j];
-
-               /* Skip non-objects */
+               object_type *j_ptr = &p_ptr->inventory_list[j];
                if (!j_ptr->k_idx) continue;
 
                /* Check if the two items can be combined */
@@ -5634,9 +5262,7 @@ s16b inven_carry(object_type *o_ptr)
        /* Check for combining */
        for (j = 0; j < INVEN_PACK; j++)
        {
-               j_ptr = &inventory[j];
-
-               /* Skip non-objects */
+               j_ptr = &p_ptr->inventory_list[j];
                if (!j_ptr->k_idx) continue;
 
                /* Hack -- track last item */
@@ -5656,14 +5282,12 @@ s16b inven_carry(object_type *o_ptr)
                }
        }
 
-
-       /* Paranoia */
-       if (inven_cnt > INVEN_PACK) return (-1);
+       if (p_ptr->inven_cnt > INVEN_PACK) return (-1);
 
        /* Find an empty slot */
        for (j = 0; j <= INVEN_PACK; j++)
        {
-               j_ptr = &inventory[j];
+               j_ptr = &p_ptr->inventory_list[j];
 
                /* Use it if found */
                if (!j_ptr->k_idx) break;
@@ -5682,7 +5306,7 @@ s16b inven_carry(object_type *o_ptr)
                /* Scan every occupied slot */
                for (j = 0; j < INVEN_PACK; j++)
                {
-                       if (object_sort_comp(o_ptr, o_value, &inventory[j])) break;
+                       if (object_sort_comp(o_ptr, o_value, &p_ptr->inventory_list[j])) break;
                }
 
                /* Use that slot */
@@ -5692,19 +5316,19 @@ s16b inven_carry(object_type *o_ptr)
                for (k = n; k >= i; k--)
                {
                        /* Hack -- Slide the item */
-                       object_copy(&inventory[k+1], &inventory[k]);
+                       object_copy(&p_ptr->inventory_list[k+1], &p_ptr->inventory_list[k]);
                }
 
                /* Wipe the empty slot */
-               object_wipe(&inventory[i]);
+               object_wipe(&p_ptr->inventory_list[i]);
        }
 
 
        /* Copy the item */
-       object_copy(&inventory[i], o_ptr);
+       object_copy(&p_ptr->inventory_list[i], o_ptr);
 
        /* Access new object */
-       j_ptr = &inventory[i];
+       j_ptr = &p_ptr->inventory_list[i];
 
        /* Forget stack */
        j_ptr->next_o_idx = 0;
@@ -5721,7 +5345,7 @@ s16b inven_carry(object_type *o_ptr)
        p_ptr->total_weight += (j_ptr->number * j_ptr->weight);
 
        /* Count the items */
-       inven_cnt++;
+       p_ptr->inven_cnt++;
        p_ptr->update |= (PU_BONUS | PU_COMBINE | PU_REORDER);
        p_ptr->window |= (PW_INVEN);
 
@@ -5757,16 +5381,12 @@ INVENTORY_IDX inven_takeoff(INVENTORY_IDX item, ITEM_NUMBER amt)
 
 
        /* Get the item to take off */
-       o_ptr = &inventory[item];
-
-       /* Paranoia */
+       o_ptr = &p_ptr->inventory_list[item];
        if (amt <= 0) return (-1);
 
        /* Verify */
        if (amt > o_ptr->number) amt = o_ptr->number;
        q_ptr = &forge;
-
-       /* Obtain a local object */
        object_copy(q_ptr, o_ptr);
 
        /* Modify quantity */
@@ -5836,7 +5456,7 @@ void inven_drop(INVENTORY_IDX item, ITEM_NUMBER amt)
        GAME_TEXT o_name[MAX_NLEN];
 
        /* Access original object */
-       o_ptr = &inventory[item];
+       o_ptr = &p_ptr->inventory_list[item];
 
        /* Error check */
        if (amt <= 0) return;
@@ -5851,7 +5471,7 @@ void inven_drop(INVENTORY_IDX item, ITEM_NUMBER amt)
                item = inven_takeoff(item, amt);
 
                /* Access original object */
-               o_ptr = &inventory[item];
+               o_ptr = &p_ptr->inventory_list[item];
        }
 
        q_ptr = &forge;
@@ -5873,10 +5493,7 @@ void inven_drop(INVENTORY_IDX item, ITEM_NUMBER amt)
        /* Drop it near the player */
        (void)drop_near(q_ptr, 0, p_ptr->y, p_ptr->x);
 
-       /* Modify, Describe, Optimize */
-       inven_item_increase(item, -amt);
-       inven_item_describe(item);
-       inven_item_optimize(item);
+       vary_item(item, -amt);
 }
 
 
@@ -5887,7 +5504,7 @@ void inven_drop(INVENTORY_IDX item, ITEM_NUMBER amt)
  * @details
  * Note special handling of the "overflow" slot
  */
-void combine_pack(void)
+void combine_pack(player_type *owner_ptr)
 {
        int             i, j, k;
        object_type *o_ptr;
@@ -5901,7 +5518,7 @@ void combine_pack(void)
                /* Combine the pack (backwards) */
                for (i = INVEN_PACK; i > 0; i--)
                {
-                       o_ptr = &inventory[i];
+                       o_ptr = &owner_ptr->inventory_list[i];
 
                        /* Skip empty items */
                        if (!o_ptr->k_idx) continue;
@@ -5911,7 +5528,7 @@ void combine_pack(void)
                        {
                                int max_num;
 
-                               j_ptr = &inventory[j];
+                               j_ptr = &owner_ptr->inventory_list[j];
 
                                /* Skip empty items */
                                if (!j_ptr->k_idx) continue;
@@ -5934,17 +5551,17 @@ void combine_pack(void)
                                                object_absorb(j_ptr, o_ptr);
 
                                                /* One object is gone */
-                                               inven_cnt--;
+                                               owner_ptr->inven_cnt--;
 
                                                /* Slide everything down */
                                                for (k = i; k < INVEN_PACK; k++)
                                                {
                                                        /* Structure copy */
-                                                       inventory[k] = inventory[k+1];
+                                                       owner_ptr->inventory_list[k] = owner_ptr->inventory_list[k+1];
                                                }
 
                                                /* Erase the "final" slot */
-                                               object_wipe(&inventory[k]);
+                                               object_wipe(&owner_ptr->inventory_list[k]);
                                        }
                                        else
                                        {
@@ -5972,7 +5589,7 @@ void combine_pack(void)
                                                }
                                        }
 
-                                       p_ptr->window |= (PW_INVEN);
+                                       owner_ptr->window |= (PW_INVEN);
 
                                        /* Take note */
                                        combined = TRUE;
@@ -6008,9 +5625,9 @@ void reorder_pack(void)
        for (i = 0; i < INVEN_PACK; i++)
        {
                /* Mega-Hack -- allow "proper" over-flow */
-               if ((i == INVEN_PACK) && (inven_cnt == INVEN_PACK)) break;
+               if ((i == INVEN_PACK) && (p_ptr->inven_cnt == INVEN_PACK)) break;
 
-               o_ptr = &inventory[i];
+               o_ptr = &p_ptr->inventory_list[i];
 
                /* Skip empty slots */
                if (!o_ptr->k_idx) continue;
@@ -6021,7 +5638,7 @@ void reorder_pack(void)
                /* Scan every occupied slot */
                for (j = 0; j < INVEN_PACK; j++)
                {
-                       if (object_sort_comp(o_ptr, o_value, &inventory[j])) break;
+                       if (object_sort_comp(o_ptr, o_value, &p_ptr->inventory_list[j])) break;
                }
 
                /* Never move down */
@@ -6032,17 +5649,17 @@ void reorder_pack(void)
                q_ptr = &forge;
 
                /* Save a copy of the moving item */
-               object_copy(q_ptr, &inventory[i]);
+               object_copy(q_ptr, &p_ptr->inventory_list[i]);
 
                /* Slide the objects */
                for (k = i; k > j; k--)
                {
                        /* Slide the item */
-                       object_copy(&inventory[k], &inventory[k-1]);
+                       object_copy(&p_ptr->inventory_list[k], &p_ptr->inventory_list[k-1]);
                }
 
                /* Insert the moving item */
-               object_copy(&inventory[j], q_ptr);
+               object_copy(&p_ptr->inventory_list[j], q_ptr);
 
                p_ptr->window |= (PW_INVEN);
        }
@@ -6122,7 +5739,7 @@ void display_koff(KIND_OBJECT_IDX k_idx)
                }
 
                /* Print spells */
-               print_spells(0, spells, num, 2, 0, use_realm);
+               print_spells(p_ptr, 0, spells, num, 2, 0, use_realm);
        }
 }
 
@@ -6181,3 +5798,40 @@ void torch_lost_fuel(object_type *o_ptr)
                if (o_ptr->xtra4 < 0) o_ptr->xtra4 = 0;
        }
 }
+
+/*!
+ * @brief 射撃武器に対応する矢/弾薬のベースアイテムIDを返す /
+ * @param o_ptr 判定する射撃武器のアイテム情報参照ポインタ
+ * @return 対応する矢/弾薬のベースアイテムID
+ */
+int bow_tval_ammo(object_type *o_ptr)
+{
+       /* Analyze the launcher */
+       switch (o_ptr->sval)
+       {
+       case SV_SLING:
+       {
+               return TV_SHOT;
+       }
+
+       case SV_SHORT_BOW:
+       case SV_LONG_BOW:
+       case SV_NAMAKE_BOW:
+       {
+               return TV_ARROW;
+       }
+
+       case SV_LIGHT_XBOW:
+       case SV_HEAVY_XBOW:
+       {
+               return TV_BOLT;
+       }
+       case SV_CRIMSON:
+       case SV_HARP:
+       {
+               return TV_NO_AMMO;
+       }
+       }
+
+       return 0;
+}