OSDN Git Service

Extend features of tiling. (separation of Cell size and Tile size / add offset position.)
[hengband/hengband.git] / src / object2.c
index 44b894c..fd70402 100644 (file)
@@ -1,22 +1,24 @@
-/* File: object2.c */
-
-/*
- * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
- *
- * This software may be copied and distributed for educational, research,
- * and not for profit purposes provided that this copyright and statement
- * are included in all such copies.  Other copyrights may also apply.
+/*!
+ * @file object2.c
+ * @brief ¥ª¥Ö¥¸¥§¥¯¥È¤Î¼ÂÁõ / Object code, part 2
+ * @date 2014/01/11
+ * @author
+ * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke\n
+ *\n
+ * This software may be copied and distributed for educational, research,\n
+ * and not for profit purposes provided that this copyright and statement\n
+ * are included in all such copies.  Other copyrights may also apply.\n
+ * 2014 Deskull rearranged comment for Doxygen.\n
  */
 
-/* Purpose: Object code, part 2 */
-
 #include "angband.h"
 
 #include "kajitips.h"
 
-
-/*
- * Excise a dungeon object from any stacks
+/*!
+ * @brief ¾²¾å¡¢¥â¥ó¥¹¥¿¡¼½ê»ý¤Ç¥¹¥¿¥Ã¥¯¤µ¤ì¤¿¥¢¥¤¥Æ¥à¤òºï½ü¤·¥¹¥¿¥Ã¥¯¤òÊä´°¤¹¤ë / Excise a dungeon object from any stacks
+ * @param o_idx ºï½üÂоݤΥª¥Ö¥¸¥§¥¯¥È¹½Â¤ÂΥݥ¤¥ó¥¿
+ * @return ¤Ê¤·
  */
 void excise_object_idx(int o_idx)
 {
@@ -140,10 +142,12 @@ void excise_object_idx(int o_idx)
        }
 }
 
-
-/*
+/*!
+ * @brief ¥ª¥Ö¥¸¥§¥¯¥È¤òºï½ü¤¹¤ë /
  * Delete a dungeon object
- *
+ * @param o_idx ºï½üÂоݤΥª¥Ö¥¸¥§¥¯¥È¹½Â¤ÂΥݥ¤¥ó¥¿
+ * @return ¤Ê¤·
+ * @details
  * Handle "stacks" of objects correctly.
  */
 void delete_object_idx(int o_idx)
@@ -177,8 +181,12 @@ void delete_object_idx(int o_idx)
 }
 
 
-/*
- * Deletes all objects at given location
+/*!
+ * @brief ¥Õ¥í¥¢¤Ë¥Þ¥¹¤ËÍî¤Á¤Æ¤¤¤ë¥ª¥Ö¥¸¥§¥¯¥È¤òÁ´¤Æºï½ü¤¹¤ë / Deletes all objects at given location
+ * Delete a dungeon object
+ * @param y ºï½ü¤·¤¿¥Õ¥í¥¢¥Þ¥¹¤ÎYºÂɸ
+ * @param x ºï½ü¤·¤¿¥Õ¥í¥¢¥Þ¥¹¤ÎXºÂɸ
+ * @return ¤Ê¤·
  */
 void delete_object(int y, int x)
 {
@@ -220,8 +228,12 @@ void delete_object(int y, int x)
 }
 
 
-/*
+/*!
+ * @brief ¥°¥í¡¼¥Ð¥ë¥ª¥Ö¥¸¥§¥¯¥ÈÇÛÎó¤ËÂФ·»ØÄêÈϰϤΥª¥Ö¥¸¥§¥¯¥È¤òÀ°Íý¤·¤ÆID¤Î¼ã¤¤½ç¤Ë´ó¤»¤ë /
  * Move an object from index i1 to index i2 in the object list
+ * @param i1 À°Íý¤·¤¿¤¤ÇÛÎó¤Î»ÏÅÀ
+ * @param i2 À°Íý¤·¤¿¤¤ÇÛÎó¤Î½ªÅÀ
+ * @return ¤Ê¤·
  */
 static void compact_objects_aux(int i1, int i2)
 {
@@ -303,17 +315,21 @@ static void compact_objects_aux(int i1, int i2)
 }
 
 
-/*
- * Compact and Reorder the object list
- *
- * This function can be very dangerous, use with caution!
- *
- * When actually "compacting" objects, we base the saving throw on a
- * combination of object level, distance from player, and current
- * "desperation".
- *
- * After "compacting" (if needed), we "reorder" the objects into a more
- * compact order, and we reset the allocation info, and the "live" array.
+/*!
+ * @brief ¥°¥í¡¼¥Ð¥ë¥ª¥Ö¥¸¥§¥¯¥ÈÇÛÎ󤫤éÍ¥ÀèÅÙ¤ÎÄ㤤¤â¤Î¤òºï½ü¤·¡¢¥Ç¡¼¥¿¤ò°µ½Ì¤¹¤ë¡£ /
+ * Compact and Reorder the object list.
+ * @param size ºÇÄã¤Ç¤â¸º¤é¤·¤¿¤¤¥ª¥Ö¥¸¥§¥¯¥È¿ô¤Î¿å½à
+ * @return ¤Ê¤·
+ * @details
+ * ¡Ê´í¸±¤Ê¤Î¤Ç»ÈÍѤˤÏÃí°Õ¤¹¤ë¤³¤È¡Ë
+ * This function can be very dangerous, use with caution!\n
+ *\n
+ * When actually "compacting" objects, we base the saving throw on a\n
+ * combination of object level, distance from player, and current\n
+ * "desperation".\n
+ *\n
+ * After "compacting" (if needed), we "reorder" the objects into a more\n
+ * compact order, and we reset the allocation info, and the "live" array.\n
  */
 void compact_objects(int size)
 {
@@ -359,7 +375,7 @@ void compact_objects(int size)
                        if (!o_ptr->k_idx) continue;
 
                        /* Hack -- High level objects start out "immune" */
-                       if (get_object_level(o_ptr) > cur_lev) continue;
+                       if (k_info[o_ptr->k_idx].level > cur_lev) continue;
 
                        /* Monster */
                        if (o_ptr->held_m_idx)
@@ -392,7 +408,7 @@ void compact_objects(int size)
                        chance = 90;
 
                        /* Hack -- only compact artifacts in emergencies */
-                       if ((artifact_p(o_ptr) || o_ptr->art_name) &&
+                       if ((object_is_fixed_artifact(o_ptr) || o_ptr->art_name) &&
                            (cnt < 1000)) chance = 100;
 
                        /* Apply the saving throw */
@@ -424,16 +440,17 @@ void compact_objects(int size)
 }
 
 
-/*
+/*!
+ * @brief ¥°¥í¡¼¥Ð¥ë¥ª¥Ö¥¸¥§¥¯¥ÈÇÛÎó¤ò½é´ü²½¤¹¤ë /
  * Delete all the items when player leaves the level
- *
- * Note -- we do NOT visually reflect these (irrelevant) changes
- *
+ * @note we do NOT visually reflect these (irrelevant) changes
+ * @details
  * Hack -- we clear the "c_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)
 {
@@ -451,7 +468,7 @@ void wipe_o_list(void)
                if (!character_dungeon || preserve_mode)
                {
                        /* Hack -- Preserve unknown artifacts */
-                       if (artifact_p(o_ptr) && !object_known_p(o_ptr))
+                       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;
@@ -498,9 +515,11 @@ void wipe_o_list(void)
 }
 
 
-/*
+/*!
+ * @brief ¥°¥í¡¼¥Ð¥ë¥ª¥Ö¥¸¥§¥¯¥ÈÇÛÎ󤫤é¶õ¤­¤ò¼èÆÀ¤¹¤ë /
  * Acquires and returns the index of a "free" object.
- *
+ * @return ³«¤¤¤Æ¤¤¤ë¥ª¥Ö¥¸¥§¥¯¥ÈÍ×ÁǤÎID
+ * @details
  * This routine should almost never fail, but in case it does,
  * we must be sure to handle "failure" of this routine.
  */
@@ -558,8 +577,11 @@ s16b o_pop(void)
 }
 
 
-/*
+/*!
+ * @brief ¥ª¥Ö¥¸¥§¥¯¥ÈÀ¸À®¥Æ¡¼¥Ö¥ë¤ËÀ¸À®À©Ìó¤ò²Ã¤¨¤ë /
  * Apply a "object restriction function" to the "object allocation table"
+ * @return ¾ï¤Ë0¤òÊÖ¤¹¡£
+ * @details À¸À®¤ÎÀ©Ìó¤Ï¥°¥í¡¼¥Ð¥ë¤Îget_obj_num_hook´Ø¿ô¥Ý¥¤¥ó¥¿¤Ç²Ã¤¨¤ë
  */
 static errr get_obj_num_prep(void)
 {
@@ -591,20 +613,23 @@ static errr get_obj_num_prep(void)
 }
 
 
-/*
+/*!
+ * @brief ¥ª¥Ö¥¸¥§¥¯¥ÈÀ¸À®¥Æ¡¼¥Ö¥ë¤«¤é¥¢¥¤¥Æ¥à¤ò¼èÆÀ¤¹¤ë /
  * Choose an object kind that seems "appropriate" to the given level
- *
- * This function uses the "prob2" field of the "object allocation table",
- * and various local information, to calculate the "prob3" field of the
- * same table, which is then used to choose an "appropriate" object, in
- * a relatively efficient manner.
- *
- * It is (slightly) more likely to acquire an object of the given level
- * than one of a lower level.  This is done by choosing several objects
- * appropriate to the given level and keeping the "hardest" one.
- *
- * Note that if no objects are "appropriate", then this function will
- * fail, and return zero, but this should *almost* never happen.
+ * @param level À¸À®³¬
+ * @return Áª¤Ð¤ì¤¿¥ª¥Ö¥¸¥§¥¯¥È¥Ù¡¼¥¹ID
+ * @details
+ * This function uses the "prob2" field of the "object allocation table",\n
+ * and various local information, to calculate the "prob3" field of the\n
+ * same table, which is then used to choose an "appropriate" object, in\n
+ * a relatively efficient manner.\n
+ *\n
+ * It is (slightly) more likely to acquire an object of the given level\n
+ * than one of a lower level.  This is done by choosing several objects\n
+ * appropriate to the given level and keeping the "hardest" one.\n
+ *\n
+ * Note that if no objects are "appropriate", then this function will\n
+ * fail, and return zero, but this should *almost* never happen.\n
  */
 s16b get_obj_num(int level)
 {
@@ -728,20 +753,23 @@ s16b get_obj_num(int level)
 }
 
 
-/*
+/*!
+ * @brief ¥ª¥Ö¥¸¥§¥¯¥È¤ò´ÕÄêºÑ¤Ë¤¹¤ë /
  * Known is true when the "attributes" of an object are "known".
- * These include tohit, todam, toac, cost, and pval (charges).
- *
- * Note that "knowing" an object gives you everything that an "awareness"
- * gives you, and much more.  In fact, the player is always "aware" of any
- * item of which he has full "knowledge".
- *
- * But having full knowledge of, say, one "wand of wonder", does not, by
- * itself, give you knowledge, or even awareness, of other "wands of wonder".
- * It happens that most "identify" routines (including "buying from a shop")
- * will make the player "aware" of the object as well as fully "know" it.
- *
- * This routine also removes any inscriptions generated by "feelings".
+ * @param o_ptr ´ÕÄêºÑ¤Ë¤¹¤ë¥ª¥Ö¥¸¥§¥¯¥È¤Î¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿
+ * @return ¤Ê¤·
+ * These include tohit, todam, toac, cost, and pval (charges).\n
+ *\n
+ * Note that "knowing" an object gives you everything that an "awareness"\n
+ * gives you, and much more.  In fact, the player is always "aware" of any\n
+ * item of which he has full "knowledge".\n
+ *\n
+ * But having full knowledge of, say, one "wand of wonder", does not, by\n
+ * itself, give you knowledge, or even awareness, of other "wands of wonder".\n
+ * It happens that most "identify" routines (including "buying from a shop")\n
+ * will make the player "aware" of the object as well as fully "know" it.\n
+ *\n
+ * This routine also removes any inscriptions generated by "feelings".\n
  */
 void object_known(object_type *o_ptr)
 {
@@ -758,21 +786,18 @@ void object_known(object_type *o_ptr)
        o_ptr->ident |= (IDENT_KNOWN);
 }
 
-
-/*
+/*!
+ * @brief ¥ª¥Ö¥¸¥§¥¯¥È¤ò¡ö´ÕÄê¡öºÑ¤Ë¤¹¤ë /
  * The player is now aware of the effects of the given object.
+ * @param o_ptr ¡ö´ÕÄê¡öºÑ¤Ë¤¹¤ë¥ª¥Ö¥¸¥§¥¯¥È¤Î¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿
+ * @return ¤Ê¤·
  */
 void object_aware(object_type *o_ptr)
 {
-       bool mihanmei = !object_aware_p(o_ptr);
+       bool mihanmei = !object_is_aware(o_ptr);
 
-#ifndef SCRIPT_OBJ_KIND
        /* Fully aware of the effects */
        k_info[o_ptr->k_idx].aware = TRUE;
-#else /* SCRIPT_OBJ_KIND */
-       /* Fully aware of the effects */
-       o_ptr->aware = TRUE;
-#endif /* SCRIPT_OBJ_KIND */
 
        if(mihanmei && !(k_info[o_ptr->k_idx].gen_flags & TRG_INSTA_ART) && record_ident &&
           !p_ptr->is_dead && ((o_ptr->tval >= TV_AMULET && o_ptr->tval <= TV_POTION) || (o_ptr->tval == TV_FOOD)))
@@ -792,28 +817,29 @@ void object_aware(object_type *o_ptr)
 }
 
 
-/*
+/*!
+ * @brief ¥ª¥Ö¥¸¥§¥¯¥È¤ò»î¹ÔºÑ¤Ë¤¹¤ë /
  * Something has been "sampled"
+ * @param o_ptr »î¹ÔºÑ¤Ë¤¹¤ë¥ª¥Ö¥¸¥§¥¯¥È¤Î¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿
+ * @return ¤Ê¤·
  */
 void object_tried(object_type *o_ptr)
 {
-#ifndef SCRIPT_OBJ_KIND
        /* Mark it as tried (even if "aware") */
        k_info[o_ptr->k_idx].tried = TRUE;
-#else /* SCRIPT_OBJ_KIND */
-       o_ptr->tried = TRUE;
-#endif /* SCRIPT_OBJ_KIND */
 }
 
 
-/*
- * Return the "value" of an "unknown" item
- * Make a guess at the value of non-aware items
+/*!
+ * @brief Ì¤´ÕÄê¤Ê¥Ù¡¼¥¹¥¢¥¤¥Æ¥à¤Î´ðËܲÁ³Ê¤òÊÖ¤¹ /
+ * Return the "value" of an "unknown" item Make a guess at the value of non-aware items
+ * @param o_ptr Ì¤´ÕÄê²Á³Ê¤ò³Îǧ¤·¤¿¤¤¥ª¥Ö¥¸¥§¥¯¥È¤Î¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿
+ * @return ¥ª¥Ö¥¸¥§¥¯¥È¤Î̤´ÕÄê²Á³Ê
  */
 static s32b object_value_base(object_type *o_ptr)
 {
        /* Aware item -- use template cost */
-       if (object_aware_p(o_ptr)) return (get_object_cost(o_ptr));
+       if (object_is_aware(o_ptr)) return (k_info[o_ptr->k_idx].cost);
 
        /* Analyze the type */
        switch (o_ptr->tval)
@@ -864,7 +890,13 @@ static s32b object_value_base(object_type *o_ptr)
 }
 
 
-/* Return the value of the flags the object has... */
+/*!
+ * @brief ¥ª¥Ö¥¸¥§¥¯¥È¤Î¥Õ¥é¥°Îफ¤é²Á³Ê¤ò»»½Ð¤¹¤ë /
+ * Return the value of the flags the object has...
+ * @param o_ptr ¥Õ¥é¥°²Á³Ê¤ò³Îǧ¤·¤¿¤¤¥ª¥Ö¥¸¥§¥¯¥È¤Î¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿
+ * @param plusses ¥Õ¥é¥°¤ËÍ¿¤¨¤ë²Á³Ê¤Î´ðËܽŤß
+ * @return ¥ª¥Ö¥¸¥§¥¯¥È¤Î¥Õ¥é¥°²Á³Ê
+ */
 s32b flag_cost(object_type *o_ptr, int plusses)
 {
        s32b total = 0;
@@ -884,7 +916,7 @@ s32b flag_cost(object_type *o_ptr, int plusses)
                flgs[i] &= ~(k_ptr->flags[i]);
 
        /* Exclude fixed flags of the fixed artifact. */
-       if (o_ptr->name1)
+       if (object_is_fixed_artifact(o_ptr))
        {
                artifact_type *a_ptr = &a_info[o_ptr->name1];
 
@@ -893,7 +925,7 @@ s32b flag_cost(object_type *o_ptr, int plusses)
        }
 
        /* Exclude fixed flags of the ego-item. */
-       else if (o_ptr->name2)
+       else if (object_is_ego(o_ptr))
        {
                ego_item_type *e_ptr = &e_info[o_ptr->name2];
 
@@ -964,7 +996,7 @@ s32b flag_cost(object_type *o_ptr, int plusses)
        if (have_flag(flgs, TR_EASY_SPELL)) total += 1500;
        if (have_flag(flgs, TR_THROW)) total += 5000;
        if (have_flag(flgs, TR_FREE_ACT)) total += 4500;
-       if (have_flag(flgs, TR_HOLD_LIFE)) total += 8500;
+       if (have_flag(flgs, TR_HOLD_EXP)) total += 8500;
 
        tmp_cost = 0;
        count = 0;
@@ -999,8 +1031,13 @@ s32b flag_cost(object_type *o_ptr, int plusses)
        if (have_flag(flgs, TR_TY_CURSE)) total -= 15000;
        if (have_flag(flgs, TR_HIDE_TYPE)) total += 0;
        if (have_flag(flgs, TR_SHOW_MODS)) total += 0;
-       if (have_flag(flgs, TR_FEATHER)) total += 1250;
-       if (have_flag(flgs, TR_LITE)) total += 1250;
+       if (have_flag(flgs, TR_LEVITATION)) total += 1250;
+       if (have_flag(flgs, TR_LITE_1)) total += 1500;
+       if (have_flag(flgs, TR_LITE_2)) total += 2500;
+       if (have_flag(flgs, TR_LITE_3)) total += 4000;
+       if (have_flag(flgs, TR_LITE_M1)) total -= 1500;
+       if (have_flag(flgs, TR_LITE_M2)) total -= 2500;
+       if (have_flag(flgs, TR_LITE_M3)) total -= 4000;
        if (have_flag(flgs, TR_SEE_INVIS)) total += 2000;
        if (have_flag(flgs, TR_TELEPATHY)) total += 20000;
        if (have_flag(flgs, TR_ESP_ANIMAL)) total += 1000;
@@ -1027,15 +1064,29 @@ s32b flag_cost(object_type *o_ptr, int plusses)
        if (have_flag(flgs, TR_IGNORE_COLD)) total += 100;
        if (have_flag(flgs, TR_ACTIVATE)) total += 100;
        if (have_flag(flgs, TR_DRAIN_EXP)) total -= 12500;
+       if (have_flag(flgs, TR_DRAIN_HP)) total -= 12500;
+       if (have_flag(flgs, TR_DRAIN_MANA)) total -= 12500;
+       if (have_flag(flgs, TR_CALL_ANIMAL)) total -= 12500;
+       if (have_flag(flgs, TR_CALL_DEMON)) total -= 10000;
+       if (have_flag(flgs, TR_CALL_DRAGON)) total -= 10000;
+       if (have_flag(flgs, TR_CALL_UNDEAD)) total -= 10000;
+       if (have_flag(flgs, TR_COWARDICE)) total -= 5000;
+       if (have_flag(flgs, TR_LOW_MELEE)) total -= 5000;
+       if (have_flag(flgs, TR_LOW_AC)) total -= 5000;
+       if (have_flag(flgs, TR_LOW_MAGIC)) total -= 15000;
+       if (have_flag(flgs, TR_FAST_DIGEST)) total -= 10000;
+       if (have_flag(flgs, TR_SLOW_REGEN)) total -= 10000;
        if (have_flag(flgs, TR_TELEPORT))
        {
-               if (cursed_p(o_ptr))
+               if (object_is_cursed(o_ptr))
                        total -= 7500;
                else
                        total += 250;
        }
        if (have_flag(flgs, TR_AGGRAVATE)) total -= 10000;
        if (have_flag(flgs, TR_BLESSED)) total += 750;
+       if (o_ptr->curse_flags & TR_ADD_L_CURSE) total -= 5000;
+       if (o_ptr->curse_flags & TR_ADD_H_CURSE) total -= 12500;
        if (o_ptr->curse_flags & TRC_CURSED) total -= 5000;
        if (o_ptr->curse_flags & TRC_HEAVY_CURSE) total -= 12500;
        if (o_ptr->curse_flags & TRC_PERMA_CURSE) total -= 15000;
@@ -1043,108 +1094,41 @@ s32b flag_cost(object_type *o_ptr, int plusses)
        /* Also, give some extra for activatable powers... */
        if (o_ptr->art_name && (have_flag(o_ptr->art_flags, TR_ACTIVATE)))
        {
-               int type = o_ptr->xtra2;
-
-               if (type == ACT_SUNLIGHT) total += 250;
-               else if (type == ACT_BO_MISS_1) total += 250;
-               else if (type == ACT_BA_POIS_1) total += 300;
-               else if (type == ACT_BO_ELEC_1) total += 250;
-               else if (type == ACT_BO_ACID_1) total += 250;
-               else if (type == ACT_BO_COLD_1) total += 250;
-               else if (type == ACT_BO_FIRE_1) total += 250;
-               else if (type == ACT_BA_COLD_1) total += 750;
-               else if (type == ACT_BA_FIRE_1) total += 1000;
-               else if (type == ACT_DRAIN_1) total += 500;
-               else if (type == ACT_BA_COLD_2) total += 1250;
-               else if (type == ACT_BA_ELEC_2) total += 1500;
-               else if (type == ACT_DRAIN_2) total += 750;
-               else if (type == ACT_VAMPIRE_1) total += 1000;
-               else if (type == ACT_BO_MISS_2) total += 1000;
-               else if (type == ACT_BA_FIRE_2) total += 1750;
-               else if (type == ACT_BA_COLD_3) total += 2500;
-               else if (type == ACT_BA_ELEC_3) total += 2500;
-               else if (type == ACT_WHIRLWIND) total += 7500;
-               else if (type == ACT_VAMPIRE_2) total += 2500;
-               else if (type == ACT_CALL_CHAOS) total += 5000;
-               else if (type == ACT_ROCKET) total += 5000;
-               else if (type == ACT_DISP_EVIL) total += 4000;
-               else if (type == ACT_DISP_GOOD) total += 3500;
-               else if (type == ACT_BA_MISS_3) total += 5000;
-               else if (type == ACT_CONFUSE) total += 500;
-               else if (type == ACT_SLEEP) total += 750;
-               else if (type == ACT_QUAKE) total += 600;
-               else if (type == ACT_TERROR) total += 2500;
-               else if (type == ACT_TELE_AWAY) total += 2000;
-               else if (type == ACT_BANISH_EVIL) total += 2000;
-               else if (type == ACT_GENOCIDE) total += 10000;
-               else if (type == ACT_MASS_GENO) total += 10000;
-               else if (type == ACT_CHARM_ANIMAL) total += 7500;
-               else if (type == ACT_CHARM_UNDEAD) total += 10000;
-               else if (type == ACT_CHARM_OTHER) total += 10000;
-               else if (type == ACT_CHARM_ANIMALS) total += 12500;
-               else if (type == ACT_CHARM_OTHERS) total += 17500;
-               else if (type == ACT_SUMMON_ANIMAL) total += 10000;
-               else if (type == ACT_SUMMON_PHANTOM) total += 12000;
-               else if (type == ACT_SUMMON_ELEMENTAL) total += 15000;
-               else if (type == ACT_SUMMON_DEMON) total += 20000;
-               else if (type == ACT_SUMMON_UNDEAD) total += 20000;
-               else if (type == ACT_CURE_LW) total += 500;
-               else if (type == ACT_CURE_MW) total += 750;
-               else if (type == ACT_CURE_POISON) total += 1000;
-               else if (type == ACT_REST_LIFE) total += 7500;
-               else if (type == ACT_REST_ALL) total += 15000;
-               else if (type == ACT_CURE_700) total += 10000;
-               else if (type == ACT_CURE_1000) total += 15000;
-               else if (type == ACT_ESP) total += 1500;
-               else if (type == ACT_BERSERK) total += 800;
-               else if (type == ACT_PROT_EVIL) total += 5000;
-               else if (type == ACT_RESIST_ALL) total += 5000;
-               else if (type == ACT_SPEED) total += 15000;
-               else if (type == ACT_XTRA_SPEED) total += 25000;
-               else if (type == ACT_WRAITH) total += 25000;
-               else if (type == ACT_INVULN) total += 25000;
-               else if (type == ACT_LIGHT) total += 150;
-               else if (type == ACT_MAP_LIGHT) total += 500;
-               else if (type == ACT_DETECT_ALL) total += 1000;
-               else if (type == ACT_DETECT_XTRA) total += 12500;
-               else if (type == ACT_ID_FULL) total += 10000;
-               else if (type == ACT_ID_PLAIN) total += 1250;
-               else if (type == ACT_RUNE_EXPLO) total += 4000;
-               else if (type == ACT_RUNE_PROT) total += 10000;
-               else if (type == ACT_SATIATE) total += 2000;
-               else if (type == ACT_DEST_DOOR) total += 100;
-               else if (type == ACT_STONE_MUD) total += 1000;
-               else if (type == ACT_RECHARGE) total += 1000;
-               else if (type == ACT_ALCHEMY) total += 10000;
-               else if (type == ACT_DIM_DOOR) total += 10000;
-               else if (type == ACT_TELEPORT) total += 2000;
-               else if (type == ACT_RECALL) total += 7500;
+               const activation_type* const act_ptr = find_activation_info(o_ptr);
+               if (act_ptr) {
+                       total += act_ptr->value;
+               }
        }
 
        return total;
 }
 
 
-/*
- * Return the "real" price of a "known" item, not including discounts
- *
- * Wand and staffs get cost for each charge
- *
- * Armor is worth an extra 100 gold per bonus point to armor class.
- *
- * Weapons are worth an extra 100 gold per bonus point (AC,TH,TD).
- *
- * Missiles are only worth 5 gold per bonus point, since they
- * usually appear in groups of 20, and we want the player to get
- * the same amount of cash for any "equivalent" item.  Note that
- * missiles never have any of the "pval" flags, and in fact, they
- * only have a few of the available flags, primarily of the "slay"
- * and "brand" and "ignore" variety.
- *
- * Armor with a negative armor bonus is worthless.
- * Weapons with negative hit+damage bonuses are worthless.
- *
- * Every wearable item with a "pval" bonus is worth extra (see below).
+/*!
+ * @brief ¥ª¥Ö¥¸¥§¥¯¥È¤Î¿¿¤Î²Á³Ê¤ò»»½Ð¤¹¤ë /
+ * Return the value of the flags the object has...
+ * @param o_ptr ËܲÁ³Ê¤ò³Îǧ¤·¤¿¤¤¥ª¥Ö¥¸¥§¥¯¥È¤Î¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿
+ * @return ¥ª¥Ö¥¸¥§¥¯¥È¤ÎËܲÁ³Ê
+ * @details
+ * Return the "real" price of a "known" item, not including discounts\n
+ *\n
+ * Wand and staffs get cost for each charge\n
+ *\n
+ * Armor is worth an extra 100 gold per bonus point to armor class.\n
+ *\n
+ * Weapons are worth an extra 100 gold per bonus point (AC,TH,TD).\n
+ *\n
+ * Missiles are only worth 5 gold per bonus point, since they\n
+ * usually appear in groups of 20, and we want the player to get\n
+ * the same amount of cash for any "equivalent" item.  Note that\n
+ * missiles never have any of the "pval" flags, and in fact, they\n
+ * only have a few of the available flags, primarily of the "slay"\n
+ * and "brand" and "ignore" variety.\n
+ *\n
+ * Armor with a negative armor bonus is worthless.\n
+ * Weapons with negative hit+damage bonuses are worthless.\n
+ *\n
+ * Every wearable item with a "pval" bonus is worth extra (see below).\n
  */
 s32b object_value_real(object_type *o_ptr)
 {
@@ -1156,16 +1140,16 @@ s32b object_value_real(object_type *o_ptr)
 
 
        /* Hack -- "worthless" items */
-       if (!get_object_cost(o_ptr)) return (0L);
+       if (!k_info[o_ptr->k_idx].cost) return (0L);
 
        /* Base cost */
-       value = get_object_cost(o_ptr);
+       value = k_info[o_ptr->k_idx].cost;
 
        /* Extract some flags */
        object_flags(o_ptr, flgs);
 
        /* Artifact */
-       if (o_ptr->name1)
+       if (object_is_fixed_artifact(o_ptr))
        {
                artifact_type *a_ptr = &a_info[o_ptr->name1];
 
@@ -1181,7 +1165,7 @@ s32b object_value_real(object_type *o_ptr)
        }
 
        /* Ego-Item */
-       else if (o_ptr->name2)
+       else if (object_is_ego(o_ptr))
        {
                ego_item_type *e_ptr = &e_info[o_ptr->name2];
 
@@ -1394,16 +1378,19 @@ s32b object_value_real(object_type *o_ptr)
 }
 
 
-/*
+/*!
+ * @brief ¥ª¥Ö¥¸¥§¥¯¥È²Á³Ê»»½Ð¤Î¥á¥¤¥ó¥ë¡¼¥Á¥ó /
  * Return the price of an item including plusses (and charges)
- *
- * This function returns the "value" of the given item (qty one)
- *
- * Never notice "unknown" bonuses or properties, including "curses",
- * since that would give the player information he did not have.
- *
- * Note that discounted items stay discounted forever, even if
- * the discount is "forgotten" by the player via memory loss.
+ * @param o_ptr È½ÌÀ¤·¤Æ¤¤¤ë¸½²Á³Ê¤ò³Îǧ¤·¤¿¤¤¥ª¥Ö¥¸¥§¥¯¥È¤Î¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿
+ * @return ¥ª¥Ö¥¸¥§¥¯¥È¤ÎȽÌÀ¤·¤Æ¤¤¤ë¸½²Á³Ê
+ * @details
+ * This function returns the "value" of the given item (qty one)\n
+ *\n
+ * Never notice "unknown" bonuses or properties, including "curses",\n
+ * since that would give the player information he did not have.\n
+ *\n
+ * Note that discounted items stay discounted forever, even if\n
+ * the discount is "forgotten" by the player via memory loss.\n
  */
 s32b object_value(object_type *o_ptr)
 {
@@ -1411,13 +1398,13 @@ s32b object_value(object_type *o_ptr)
 
 
        /* Unknown items -- acquire a base value */
-       if (object_known_p(o_ptr))
+       if (object_is_known(o_ptr))
        {
                /* Broken items -- worthless */
-               if (broken_p(o_ptr)) return (0L);
+               if (object_is_broken(o_ptr)) return (0L);
 
                /* Cursed items -- worthless */
-               if (cursed_p(o_ptr)) return (0L);
+               if (object_is_cursed(o_ptr)) return (0L);
 
                /* Real value (see above) */
                value = object_value_real(o_ptr);
@@ -1427,10 +1414,10 @@ s32b object_value(object_type *o_ptr)
        else
        {
                /* Hack -- Felt broken items */
-               if ((o_ptr->ident & (IDENT_SENSE)) && broken_p(o_ptr)) return (0L);
+               if ((o_ptr->ident & (IDENT_SENSE)) && object_is_broken(o_ptr)) return (0L);
 
                /* Hack -- Felt cursed items */
-               if ((o_ptr->ident & (IDENT_SENSE)) && cursed_p(o_ptr)) return (0L);
+               if ((o_ptr->ident & (IDENT_SENSE)) && object_is_cursed(o_ptr)) return (0L);
 
                /* Base value (see above) */
                value = object_value_base(o_ptr);
@@ -1446,21 +1433,25 @@ s32b 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 (!artifact_p(o_ptr) && !o_ptr->art_name) return TRUE;
+       if (!object_is_artifact(o_ptr)) return TRUE;
 
        /* If object is unidentified, makes fake inscription */
-       if (!object_known_p(o_ptr))
+       if (!object_is_known(o_ptr))
        {
                byte feel = FEEL_SPECIAL;
 
                /* Hack -- Handle icky artifacts */
-               if (cursed_p(o_ptr) || broken_p(o_ptr)) feel = FEEL_TERRIBLE;
+               if (object_is_cursed(o_ptr) || object_is_broken(o_ptr)) feel = FEEL_TERRIBLE;
 
                /* Hack -- inscribe the artifact */
                o_ptr->feeling = feel;
@@ -1483,21 +1474,21 @@ bool can_player_destroy_object(object_type *o_ptr)
 }
 
 
-/*
+/*!
+ * @brief ËâË¡ËÀ¤ä¥í¥Ã¥É¤Î¥¹¥í¥Ã¥Èʬ³ä»þ¤Ë»ÈÍѲó¿ô¤òʬÇÛ¤¹¤ë /
  * Distribute charges of rods or wands.
- *
- * o_ptr = source item
- * q_ptr = target item, must be of the same type as o_ptr
- * amt   = number of items that are transfered
+ * @param o_ptr Ê¬³ä¸µ¥ª¥Ö¥¸¥§¥¯¥È¤Î¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿ source item
+ * @param q_ptr Ê¬³äÀ襪¥Ö¥¸¥§¥¯¥È¤Î¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿ target item, must be of the same type as o_ptr
+ * @param amt Ê¬³ä¤·¤¿¤¤²ó¿ôÎÌ number of items that are transfered
+ * @return ¤Ê¤·
+ * @details
+ * Hack -- If rods or wands are dropped, the total maximum timeout or\n
+ * charges need to be allocated between the two stacks.  If all the items\n
+ * are being dropped, it makes for a neater message to leave the original\n
+ * stack's pval alone. -LM-\n
  */
 void distribute_charges(object_type *o_ptr, object_type *q_ptr, int amt)
 {
-       /*
-        * Hack -- If rods or wands are dropped, the total maximum timeout or
-        * charges need to be allocated between the two stacks.  If all the items
-        * are being dropped, it makes for a neater message to leave the original
-        * stack's pval alone. -LM-
-        */
        if ((o_ptr->tval == TV_WAND) || (o_ptr->tval == TV_ROD))
        {
                q_ptr->pval = o_ptr->pval * amt / o_ptr->number;
@@ -1519,13 +1510,18 @@ void distribute_charges(object_type *o_ptr, object_type *q_ptr, int amt)
        }
 }
 
+/*!
+ * @brief ËâË¡ËÀ¤ä¥í¥Ã¥É¤Î»ÈÍѲó¿ô¤ò¸º¤é¤¹ /
+ * @param o_ptr ¥ª¥Ö¥¸¥§¥¯¥È¤Î¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿ source item
+ * @param amt ¸º¤é¤·¤¿¤¤²ó¿ôÎÌ number of items that are transfered
+ * @return ¤Ê¤·
+ * @details
+ * Hack -- If rods or wand are destroyed, the total maximum timeout or\n
+ * charges of the stack needs to be reduced, unless all the items are\n
+ * being destroyed. -LM-\n
+ */
 void reduce_charges(object_type *o_ptr, int amt)
 {
-       /*
-        * Hack -- If rods or wand are destroyed, the total maximum timeout or
-        * charges of the stack needs to be reduced, unless all the items are
-        * being destroyed. -LM-
-        */
        if (((o_ptr->tval == TV_WAND) || (o_ptr->tval == TV_ROD)) &&
                (amt < o_ptr->number))
        {
@@ -1533,7 +1529,6 @@ void reduce_charges(object_type *o_ptr, int amt)
        }
 }
 
-
 /*
  * Determine if an item can "absorb" a second item
  *
@@ -1561,11 +1556,14 @@ void reduce_charges(object_type *o_ptr, int amt)
 #define MAX_STACK_SIZE 99
 
 
-/*
- *  Determine if an item can partly absorb a second item.
- *  Return maximum number of stack.
+/*!
+ * @brief Î¾¥ª¥Ö¥¸¥§¥¯¥È¤ò¥¹¥í¥Ã¥È¤Ë½Å¤Í¹ç¤ï¤»²Äǽ¤ÊºÇÂç¿ô¤òÊÖ¤¹¡£
+ * Determine if an item can partly absorb a second item. Return maximum number of stack.
+ * @param o_ptr ¸¡¾Ú¤·¤¿¤¤¥ª¥Ö¥¸¥§¥¯¥È¤Î¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿1
+ * @param j_ptr ¸¡¾Ú¤·¤¿¤¤¥ª¥Ö¥¸¥§¥¯¥È¤Î¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿2
+ * @return ½Å¤Í¹ç¤ï¤»²Äǽ¤Ê¥¢¥¤¥Æ¥à¿ô
  */
-static int object_similar_part(object_type *o_ptr, object_type *j_ptr)
+int object_similar_part(object_type *o_ptr, object_type *j_ptr)
 {
        int i;
 
@@ -1620,9 +1618,9 @@ static int object_similar_part(object_type *o_ptr, object_type *j_ptr)
                {
                        /* Require either knowledge or known empty for both staffs. */
                        if ((!(o_ptr->ident & (IDENT_EMPTY)) &&
-                               !object_known_p(o_ptr)) ||
+                               !object_is_known(o_ptr)) ||
                                (!(j_ptr->ident & (IDENT_EMPTY)) &&
-                               !object_known_p(j_ptr))) return 0;
+                               !object_is_known(j_ptr))) return 0;
 
                        /* Require identical charges, since staffs are bulky. */
                        if (o_ptr->pval != j_ptr->pval) return 0;
@@ -1636,9 +1634,9 @@ static int object_similar_part(object_type *o_ptr, object_type *j_ptr)
                {
                        /* Require either knowledge or known empty for both wands. */
                        if ((!(o_ptr->ident & (IDENT_EMPTY)) &&
-                               !object_known_p(o_ptr)) ||
+                               !object_is_known(o_ptr)) ||
                                (!(j_ptr->ident & (IDENT_EMPTY)) &&
-                               !object_known_p(j_ptr))) return 0;
+                               !object_is_known(j_ptr))) return 0;
 
                        /* Wand charges combine in O&ZAngband.  */
 
@@ -1679,7 +1677,7 @@ static int object_similar_part(object_type *o_ptr, object_type *j_ptr)
                case TV_WHISTLE:
                {
                        /* Require full knowledge of both items */
-                       if (!object_known_p(o_ptr) || !object_known_p(j_ptr)) return 0;
+                       if (!object_is_known(o_ptr) || !object_is_known(j_ptr)) return 0;
 
                        /* Fall through */
                }
@@ -1690,7 +1688,7 @@ static int object_similar_part(object_type *o_ptr, object_type *j_ptr)
                case TV_SHOT:
                {
                        /* Require identical knowledge of both items */
-                       if (object_known_p(o_ptr) != object_known_p(j_ptr)) return 0;
+                       if (object_is_known(o_ptr) != object_is_known(j_ptr)) return 0;
                        if (o_ptr->feeling != j_ptr->feeling) return 0;
 
                        /* Require identical "bonuses" */
@@ -1701,11 +1699,8 @@ static int object_similar_part(object_type *o_ptr, object_type *j_ptr)
                        /* Require identical "pval" code */
                        if (o_ptr->pval != j_ptr->pval) return 0;
 
-                       /* Require identical "artifact" names */
-                       if (o_ptr->name1 != j_ptr->name1) return 0;
-
-                       /* Random artifacts never stack */
-                       if (o_ptr->art_name || j_ptr->art_name) return 0;
+                       /* Artifacts never stack */
+                       if (object_is_artifact(o_ptr) || object_is_artifact(j_ptr)) return 0;
 
                        /* Require identical "ego-item" names */
                        if (o_ptr->name2 != j_ptr->name2) return 0;
@@ -1733,7 +1728,7 @@ static int object_similar_part(object_type *o_ptr, object_type *j_ptr)
                default:
                {
                        /* Require knowledge */
-                       if (!object_known_p(o_ptr) || !object_known_p(j_ptr)) return 0;
+                       if (!object_is_known(o_ptr) || !object_is_known(j_ptr)) return 0;
 
                        /* Probably okay */
                        break;
@@ -1768,8 +1763,12 @@ static int object_similar_part(object_type *o_ptr, object_type *j_ptr)
        return max_num;
 }
 
-/*
- *  Determine if an item can absorb a second item.
+/*!
+ * @brief Î¾¥ª¥Ö¥¸¥§¥¯¥È¤ò¥¹¥í¥Ã¥È¤Ë½Å¤Í¤ë¤³¤È¤¬¤Ç¤­¤ë¤«¤É¤¦¤«¤òÊÖ¤¹¡£
+ * Determine if an item can absorb a second item.
+ * @param o_ptr ¸¡¾Ú¤·¤¿¤¤¥ª¥Ö¥¸¥§¥¯¥È¤Î¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿1
+ * @param j_ptr ¸¡¾Ú¤·¤¿¤¤¥ª¥Ö¥¸¥§¥¯¥È¤Î¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿2
+ * @return ½Å¤Í¹ç¤ï¤»²Äǽ¤Ê¤é¤ÐTRUE¤òÊÖ¤¹¡£
  */
 bool object_similar(object_type *o_ptr, object_type *j_ptr)
 {
@@ -1791,9 +1790,12 @@ bool object_similar(object_type *o_ptr, object_type *j_ptr)
 }
 
 
-
-/*
+/*!
+ * @brief Î¾¥ª¥Ö¥¸¥§¥¯¥È¤ò¥¹¥í¥Ã¥È¤Ë½Å¤Í¹ç¤ï¤»¤ë¡£
  * Allow one item to "absorb" another, assuming they are similar
+ * @param o_ptr ½Å¤Í¹ç¤ï¤»Àè¤Î¥ª¥Ö¥¸¥§¥¯¥È¤Î¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿
+ * @param j_ptr ½Å¤Í¹ç¤ï¤»¸µ¤Î¥ª¥Ö¥¸¥§¥¯¥È¤Î¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿
+ * @return ¤Ê¤·
  */
 void object_absorb(object_type *o_ptr, object_type *j_ptr)
 {
@@ -1805,7 +1807,7 @@ void object_absorb(object_type *o_ptr, object_type *j_ptr)
        o_ptr->number = (total > max_num) ? max_num : total;
 
        /* Hack -- blend "known" status */
-       if (object_known_p(j_ptr)) object_known(o_ptr);
+       if (object_is_known(j_ptr)) object_known(o_ptr);
 
        /* Hack -- clear "storebought" if only one has it */
        if (((o_ptr->ident & IDENT_STORE) || (j_ptr->ident & IDENT_STORE)) &&
@@ -1843,8 +1845,12 @@ void object_absorb(object_type *o_ptr, object_type *j_ptr)
 }
 
 
-/*
+/*!
+ * @brief tval¤Èsval¤ËÂбþ¤¹¤ë¥Ù¡¼¥¹¥¢¥¤¥Æ¥à¤ÎID¤òÊÖ¤¹¡£
  * Find the index of the object_kind with the given tval and sval
+ * @param tval ¸¡º÷¤·¤¿¤¤¥Ù¡¼¥¹¥¢¥¤¥Æ¥à¤Îtval
+ * @param sval ¸¡º÷¤·¤¿¤¤¥Ù¡¼¥¹¥¢¥¤¥Æ¥à¤Îsval
+ * @return ¤Ê¤·
  */
 s16b lookup_kind(int tval, int sval)
 {
@@ -1894,8 +1900,11 @@ s16b lookup_kind(int tval, int sval)
 }
 
 
-/*
+/*!
+ * @brief ¥ª¥Ö¥¸¥§¥¯¥È¤ò½é´ü²½¤¹¤ë
  * Wipe an object clean.
+ * @param o_ptr ½é´ü²½¤·¤¿¤¤¥ª¥Ö¥¸¥§¥¯¥È¤Î¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿
+ * @return ¤Ê¤·
  */
 void object_wipe(object_type *o_ptr)
 {
@@ -1904,18 +1913,26 @@ void object_wipe(object_type *o_ptr)
 }
 
 
-/*
- * Prepare an object based on an existing object
+/*!
+ * @brief ¥ª¥Ö¥¸¥§¥¯¥È¤òÊ£À½¤¹¤ë
+ * Wipe an object clean.
+ * @param o_ptr Ê£À½¸µ¤Î¥ª¥Ö¥¸¥§¥¯¥È¤Î¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿
+ * @param j_ptr Ê£À½Àè¤Î¥ª¥Ö¥¸¥§¥¯¥È¤Î¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿
+ * @return ¤Ê¤·
  */
 void object_copy(object_type *o_ptr, object_type *j_ptr)
 {
        /* Copy the structure */
-       COPY(o_ptr, j_ptr, object_type);
+       (void)COPY(o_ptr, j_ptr, object_type);
 }
 
 
-/*
+/*!
+ * @brief ¥ª¥Ö¥¸¥§¥¯¥È¹½Â¤ÂΤ˥١¼¥¹¥¢¥¤¥Æ¥à¤òºîÀ®¤¹¤ë
  * Prepare an object based on an object kind.
+ * @param o_ptr ÂåÆþ¤·¤¿¤¤¥ª¥Ö¥¸¥§¥¯¥È¤Î¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿
+ * @param k_idx ¿·¤¿¤ËºîÀ®¤·¤¿¤¤¥Ù¡¼¥¹¥¢¥¤¥Æ¥à¾ðÊó¤ÎID
+ * @return ¤Ê¤·
  */
 void object_prep(object_type *o_ptr, int k_idx)
 {
@@ -1950,8 +1967,11 @@ void object_prep(object_type *o_ptr, int k_idx)
        o_ptr->dd = k_ptr->dd;
        o_ptr->ds = k_ptr->ds;
 
+       /* Default activation */
+       if (k_ptr->act_idx > 0) o_ptr->xtra2 = k_ptr->act_idx;
+
        /* Hack -- worthless items are always "broken" */
-       if (get_object_cost(o_ptr) <= 0) o_ptr->ident |= (IDENT_BROKEN);
+       if (k_info[o_ptr->k_idx].cost <= 0) o_ptr->ident |= (IDENT_BROKEN);
 
        /* Hack -- cursed items are always "cursed" */
        if (k_ptr->gen_flags & (TRG_CURSED)) o_ptr->curse_flags |= (TRC_CURSED);
@@ -1963,44 +1983,48 @@ void object_prep(object_type *o_ptr, int k_idx)
 }
 
 
-/*
+/*!
+ * @brief ¾å¼Á°Ê¾å¤Î¥ª¥Ö¥¸¥§¥¯¥È¤ËÍ¿¤¨¤ë¤¿¤á¤Î³Æ¼ï¥Ü¡¼¥Ê¥¹¤òÀµµ¬Íð¿ô¤â²Ã¤¨¤Æ»»½Ð¤¹¤ë¡£
  * Help determine an "enchantment bonus" for an object.
- *
- * To avoid floating point but still provide a smooth distribution of bonuses,
- * we simply round the results of division in such a way as to "average" the
- * correct floating point value.
- *
- * This function has been changed.  It uses "randnor()" to choose values from
- * a normal distribution, whose mean moves from zero towards the max as the
- * level increases, and whose standard deviation is equal to 1/4 of the max,
- * and whose values are forced to lie between zero and the max, inclusive.
- *
- * Since the "level" rarely passes 100 before Morgoth is dead, it is very
- * rare to get the "full" enchantment on an object, even a deep levels.
- *
- * It is always possible (albeit unlikely) to get the "full" enchantment.
- *
- * A sample distribution of values from "m_bonus(10, N)" is shown below:
- *
- *   N       0     1     2     3     4     5     6     7     8     9    10
- * ---    ----  ----  ----  ----  ----  ----  ----  ----  ----  ----  ----
- *   0   66.37 13.01  9.73  5.47  2.89  1.31  0.72  0.26  0.12  0.09  0.03
- *   8   46.85 24.66 12.13  8.13  4.20  2.30  1.05  0.36  0.19  0.08  0.05
- *  16   30.12 27.62 18.52 10.52  6.34  3.52  1.95  0.90  0.31  0.15  0.05
- *  24   22.44 15.62 30.14 12.92  8.55  5.30  2.39  1.63  0.62  0.28  0.11
- *  32   16.23 11.43 23.01 22.31 11.19  7.18  4.46  2.13  1.20  0.45  0.41
- *  40   10.76  8.91 12.80 29.51 16.00  9.69  5.90  3.43  1.47  0.88  0.65
- *  48    7.28  6.81 10.51 18.27 27.57 11.76  7.85  4.99  2.80  1.22  0.94
- *  56    4.41  4.73  8.52 11.96 24.94 19.78 11.06  7.18  3.68  1.96  1.78
- *  64    2.81  3.07  5.65  9.17 13.01 31.57 13.70  9.30  6.04  3.04  2.64
- *  72    1.87  1.99  3.68  7.15 10.56 20.24 25.78 12.17  7.52  4.42  4.62
- *  80    1.02  1.23  2.78  4.75  8.37 12.04 27.61 18.07 10.28  6.52  7.33
- *  88    0.70  0.57  1.56  3.12  6.34 10.06 15.76 30.46 12.58  8.47 10.38
- *  96    0.27  0.60  1.25  2.28  4.30  7.60 10.77 22.52 22.51 11.37 16.53
- * 104    0.22  0.42  0.77  1.36  2.62  5.33  8.93 13.05 29.54 15.23 22.53
- * 112    0.15  0.20  0.56  0.87  2.00  3.83  6.86 10.06 17.89 27.31 30.27
- * 120    0.03  0.11  0.31  0.46  1.31  2.48  4.60  7.78 11.67 25.53 45.72
- * 128    0.02  0.01  0.13  0.33  0.83  1.41  3.24  6.17  9.57 14.22 64.07
+ * @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
  */
 s16b m_bonus(int max, int level)
 {
@@ -2045,8 +2069,10 @@ s16b m_bonus(int max, int level)
 }
 
 
-/*
- * Cheat -- describe a created object for the user
+/*!
+ * @brief ¥Ç¥Ð¥Ã¥°»þ¤Ë¥¢¥¤¥Æ¥àÀ¸À®¾ðÊó¤ò¥á¥Ã¥»¡¼¥¸¤Ë½ÐÎϤ¹¤ë / Cheat -- describe a created object for the user
+ * @param o_ptr ¥Ç¥Ð¥Ã¥°½ÐÎϤ¹¤ë¥ª¥Ö¥¸¥§¥¯¥È¤Î¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿
+ * @return ¤Ê¤·
  */
 static void object_mention(object_type *o_ptr)
 {
@@ -2056,7 +2082,7 @@ static void object_mention(object_type *o_ptr)
        object_desc(o_name, o_ptr, (OD_NAME_ONLY | OD_STORE));
 
        /* Artifact */
-       if (artifact_p(o_ptr))
+       if (object_is_fixed_artifact(o_ptr))
        {
                /* Silly message */
 #ifdef JP
@@ -2079,7 +2105,7 @@ static void object_mention(object_type *o_ptr)
        }
 
        /* Ego-item */
-       else if (ego_item_p(o_ptr))
+       else if (object_is_ego(o_ptr))
        {
                /* Silly message */
 #ifdef JP
@@ -2103,14 +2129,16 @@ static void object_mention(object_type *o_ptr)
        }
 }
 
-
-/*
+/*!
+ * @brief INSTA_ART·¿¤Î¸ÇÄꥢ¡¼¥Æ¥£¥Õ¥¡¥¯¥È¤ÎÀ¸À®¤ò³ÎΨ¤Ë±þ¤¸¤Æ»î¹Ô¤¹¤ë¡£
  * Mega-Hack -- Attempt to create one of the "Special Objects"
- *
- * We are only called from "make_object()", and we assume that
- * "apply_magic()" is called immediately after we return.
- *
- * Note -- see "make_artifact()" and "apply_magic()"
+ * @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)
 {
@@ -2182,12 +2210,15 @@ static bool make_artifact_special(object_type *o_ptr)
 }
 
 
-/*
- * Attempt to change an object into an artifact
- *
- * This routine should only be called by "apply_magic()"
- *
- * Note -- see "make_artifact_special()" and "apply_magic()"
+/*!
+ * @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)
 {
@@ -2247,8 +2278,12 @@ static bool make_artifact(object_type *o_ptr)
 }
 
 
-/*
- *  Choose random ego type
+/*!
+ * @brief ¥¢¥¤¥Æ¥à¤Î¥¨¥´¤ò¥ì¥¢Å٤νŤߤ˹ç¤ï¤»¤Æ¥é¥ó¥À¥à¤ËÁªÂò¤¹¤ë
+ * Choose random ego type
+ * @param slot ¼èÆÀ¤·¤¿¤¤¥¨¥´¤ÎÁõÈ÷Éô°Ì
+ * @param good TRUE¤Ê¤é¤ÐÄ̾ï¤Î¥¨¥´¡¢FALSE¤Ê¤é¤Ð¼ö¤¤¤Î¥¨¥´¤¬ÁªÂòÂоݤȤʤ롣
+ * @return ÁªÂò¤µ¤ì¤¿¥¨¥´¾ðÊó¤ÎID¡¢Ëü°ìÁªÂò¤Ç¤­¤Ê¤«¤Ã¤¿¾ì¹ç¤Ïmax_e_idx¤¬Ê֤롣
  */
 static byte get_random_ego(byte slot, bool good)
 {
@@ -2287,12 +2322,16 @@ static byte get_random_ego(byte slot, bool good)
 }
 
 
-/*
+/*!
+ * @brief Éð´ï·Ï¥ª¥Ö¥¸¥§¥¯¥È¤ËÀ¸À®¥é¥ó¥¯¤´¤È¤Î¶¯²½¤òÍ¿¤¨¤ë¥µ¥Ö¥ë¡¼¥Á¥ó
  * Apply magic to an item known to be a "weapon"
- *
- * Hack -- note special base damage dice boosting
- * Hack -- note special processing for weapon/digger
- * Hack -- note special rating boost for dragon scale mail
+ * @param o_ptr ¶¯²½¤òÍ¿¤¨¤¿¤¤¥ª¥Ö¥¸¥§¥¯¥È¤Î¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿
+ * @param level À¸À®´ð½à³¬
+ * @param power À¸À®¥é¥ó¥¯
+ * @return ¤Ê¤·
+ * @details
+ * Hack -- note special base damage dice boosting\n
+ * Hack -- note special processing for weapon/digger\n
  */
 static void a_m_aux_1(object_type *o_ptr, int level, int power)
 {
@@ -2398,6 +2437,8 @@ static void a_m_aux_1(object_type *o_ptr, int level, int power)
                                                continue;
                                        if (o_ptr->name2 == EGO_EARTHQUAKES && o_ptr->tval != TV_HAFTED)
                                                continue;
+                                       if (o_ptr->name2 == EGO_WEIRD && o_ptr->tval != TV_SWORD)
+                                               continue;
                                        break;
                                }
 
@@ -2456,7 +2497,7 @@ static void a_m_aux_1(object_type *o_ptr, int level, int power)
                                        break;
                                case EGO_PATTERN:
                                        if (one_in_(3))
-                                               add_flag(o_ptr->art_flags, TR_HOLD_LIFE);
+                                               add_flag(o_ptr->art_flags, TR_HOLD_EXP);
                                        if (one_in_(3))
                                                add_flag(o_ptr->art_flags, TR_DEX);
                                        if (one_in_(5))
@@ -2475,6 +2516,21 @@ static void a_m_aux_1(object_type *o_ptr, int level, int power)
                                        if (one_in_(5))
                                                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) ? 
+                                               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);
+                                               
+                                       
+                                       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);
+                                       if (one_in_(5)) add_flag(o_ptr->art_flags, TR_CALL_DEMON);
+                                       break;
                                }
 
                                if (!o_ptr->art_name)
@@ -2493,11 +2549,27 @@ static void a_m_aux_1(object_type *o_ptr, int level, int power)
                                /* Roll for ego-item */
                                if (randint0(MAX_DEPTH) < level)
                                {
-                                       o_ptr->name2 = get_random_ego(INVEN_RARM, FALSE);
+                                       while(1)
+                                       {
+                                               o_ptr->name2 = get_random_ego(INVEN_RARM, FALSE);
+                                               if (o_ptr->name2 == EGO_WEIRD && o_ptr->tval != TV_SWORD)
+                                               {
+                                                       continue;
+                                               }
+                                               break;
+                                       }
                                        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);
                                        }
                                }
                        }
@@ -2567,7 +2639,11 @@ static void a_m_aux_1(object_type *o_ptr, int level, int power)
        }
 }
 
-
+/*!
+ * @brief ¥É¥é¥´¥óÁõÈ÷¤Ë¥é¥ó¥À¥à¤ÊÂÑÀ­¤òÍ¿¤¨¤ë
+ * @param o_ptr ¶¯²½¤òÍ¿¤¨¤¿¤¤¥ª¥Ö¥¸¥§¥¯¥È¤Î¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿
+ * @return ¤Ê¤·
+ */
 static void dragon_resist(object_type * o_ptr)
 {
        do
@@ -2580,7 +2656,11 @@ static void dragon_resist(object_type * o_ptr)
        while (one_in_(2));
 }
 
-
+/*!
+ * @brief ¥ª¥Ö¥¸¥§¥¯¥È¤Ë¥é¥ó¥À¥à¤Ê¶¯¤¤ESP¤òÍ¿¤¨¤ë
+ * @param o_ptr ¶¯²½¤òÍ¿¤¨¤¿¤¤¥ª¥Ö¥¸¥§¥¯¥È¤Î¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿
+ * @return ¤Ê¤·
+ */
 static bool add_esp_strong(object_type *o_ptr)
 {
        bool nonliv = FALSE;
@@ -2595,52 +2675,51 @@ static bool add_esp_strong(object_type *o_ptr)
        return nonliv;
 }
 
-
-#define MAX_ESP_WEAK 9
+/*!
+ * @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 = 0;
-       int idx[MAX_ESP_WEAK];
-       int flg[MAX_ESP_WEAK];
-       int n = (extra) ? (3 + randint1(randint1(6))) : randint1(3);
-       int left = MAX_ESP_WEAK;
-
-       for (i = 0; i < MAX_ESP_WEAK; i++) flg[i] = i + 1;
+       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));
 
-       /* Shuffle esp flags */
-       for (i = 0; i < n; i++)
+       /* Add unduplicated weak esp flags randomly */
+       for (i = 0; i < add_count; ++ i)
        {
-               int k = randint0(left--);
-
-               idx[i] = flg[k];
-
-               while (k < left)
-               {
-                       flg[k] = flg[k + 1];
-                       k++;
-               }
-       }
+               int choice = rand_range(i, MAX_ESP_WEAK - 1);
 
-       while (n--) switch (idx[n])
-       {
-       case 1: add_flag(o_ptr->art_flags, TR_ESP_ANIMAL); break;
-       case 2: add_flag(o_ptr->art_flags, TR_ESP_UNDEAD); break;
-       case 3: add_flag(o_ptr->art_flags, TR_ESP_DEMON); break;
-       case 4: add_flag(o_ptr->art_flags, TR_ESP_ORC); break;
-       case 5: add_flag(o_ptr->art_flags, TR_ESP_TROLL); break;
-       case 6: add_flag(o_ptr->art_flags, TR_ESP_GIANT); break;
-       case 7: add_flag(o_ptr->art_flags, TR_ESP_DRAGON);   break;
-       case 8: add_flag(o_ptr->art_flags, TR_ESP_HUMAN); break;
-       case 9: add_flag(o_ptr->art_flags, TR_ESP_GOOD); break;
+               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"
- *
- * Hack -- note special processing for crown/helm
- * Hack -- note special processing for robe of permanence
+ * @param o_ptr ¶¯²½¤òÍ¿¤¨¤¿¤¤¥ª¥Ö¥¸¥§¥¯¥È¤Î¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿
+ * @param level À¸À®´ð½à³¬
+ * @param power À¸À®¥é¥ó¥¯
+ * @return ¤Ê¤·
+ * @details
+ * Hack -- note special processing for crown/helm\n
+ * Hack -- note special processing for robe of permanence\n
  */
 static void a_m_aux_2(object_type *o_ptr, int level, int power)
 {
@@ -2685,8 +2764,6 @@ static void a_m_aux_2(object_type *o_ptr, int level, int power)
        {
                case TV_DRAG_ARMOR:
                {
-                       /* Rating boost */
-                       rating += 30;
                        if (one_in_(50) || (power > 2)) /* power > 2 is debug only */
                                create_artifact(o_ptr, FALSE);
 
@@ -2736,31 +2813,64 @@ static void a_m_aux_2(object_type *o_ptr, int level, int power)
 
                                        switch (o_ptr->name2)
                                        {
-                                       case EGO_RESISTANCE:
-                                               if (one_in_(4))
-                                                       add_flag(o_ptr->art_flags, TR_RES_POIS);
-                                               break;
-                                       case EGO_ELVENKIND:
-                                               break;
-                                       case EGO_DWARVEN:
+                                         case EGO_DWARVEN:
                                                if (o_ptr->tval != TV_HARD_ARMOR)
                                                {
                                                        okay_flag = FALSE;
                                                        break;
                                                }
-                                               else
+                                         case EGO_DRUID:
+                                               if (o_ptr->tval != TV_SOFT_ARMOR)
                                                {
-                                                       o_ptr->weight = (2 * k_info[o_ptr->k_idx].weight / 3);
-                                                       o_ptr->ac = k_info[o_ptr->k_idx].ac + 5;
-                                                       if (one_in_(4))
-                                                               add_flag(o_ptr->art_flags, TR_CON);
+                                                       okay_flag = FALSE;
                                                        break;
                                                }
+                                         default:
+                                               break;
                                        }
 
                                        if (okay_flag)
                                                break;
                                }
+                               switch (o_ptr->name2)
+                               {
+                                 case EGO_RESISTANCE:
+                                       if (one_in_(4))
+                                               add_flag(o_ptr->art_flags, TR_RES_POIS);
+                                               break;
+                                 case EGO_DWARVEN:
+                                       o_ptr->weight = (2 * k_info[o_ptr->k_idx].weight / 3);
+                                       o_ptr->ac = k_info[o_ptr->k_idx].ac + 5;
+                                       break;
+                                       
+                                 case EGO_A_DEMON:
+                                       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);
+                                               
+                                       if (one_in_(3)) add_flag(o_ptr->art_flags, TR_AGGRAVATE);
+                                       if (one_in_(3)) add_flag(o_ptr->art_flags, TR_ADD_L_CURSE);
+                                       if (one_in_(5)) add_flag(o_ptr->art_flags, TR_ADD_H_CURSE);
+                                       if (one_in_(5)) add_flag(o_ptr->art_flags, TR_DRAIN_HP);
+                                       if (one_in_(5)) add_flag(o_ptr->art_flags, TR_DRAIN_MANA);
+                                       if (one_in_(5)) add_flag(o_ptr->art_flags, TR_DRAIN_EXP);
+                                       if (one_in_(5)) add_flag(o_ptr->art_flags, TR_TY_CURSE);
+                                       if (one_in_(5)) add_flag(o_ptr->art_flags, TR_CALL_DEMON);
+                                       break;
+                                 case EGO_A_MORGUL:
+                                       if (one_in_(3)) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
+                                       if (one_in_(9)) add_flag(o_ptr->art_flags, TR_TY_CURSE);
+                                       if (one_in_(4)) add_flag(o_ptr->art_flags, TR_ADD_H_CURSE);
+                                       if (one_in_(6)) add_flag(o_ptr->art_flags, TR_AGGRAVATE);
+                                       if (one_in_(9)) add_flag(o_ptr->art_flags, TR_NO_MAGIC);
+                                       if (one_in_(9)) add_flag(o_ptr->art_flags, TR_NO_TELE);
+                                       break;
+                                 default:
+                                       break;
+                               }
                        }
 
                        break;
@@ -2771,9 +2881,6 @@ static void a_m_aux_2(object_type *o_ptr, int level, int power)
 
                        if (o_ptr->sval == SV_DRAGON_SHIELD)
                        {
-                               /* Rating boost */
-                               rating += 5;
-
                                /* Mention the item */
                                if (cheat_peek) object_mention(o_ptr);
                                dragon_resist(o_ptr);
@@ -2788,7 +2895,17 @@ static void a_m_aux_2(object_type *o_ptr, int level, int power)
                                        create_artifact(o_ptr, FALSE);
                                        break;
                                }
-                               o_ptr->name2 = get_random_ego(INVEN_LARM, TRUE);
+                               
+                               while(1)
+                               {
+                                       o_ptr->name2 = get_random_ego(INVEN_LARM, TRUE);
+                                       if (o_ptr->sval != SV_SMALL_METAL_SHIELD && o_ptr->sval != SV_LARGE_METAL_SHIELD 
+                                                               && o_ptr->name2 == EGO_S_DWARVEN)
+                                       {
+                                               continue;
+                                       }
+                                       break;
+                               }
                                
                                switch (o_ptr->name2)
                                {
@@ -2800,6 +2917,11 @@ static void a_m_aux_2(object_type *o_ptr, int level, int power)
                                        if (o_ptr->sval == SV_MIRROR_SHIELD)
                                                o_ptr->name2 = 0;
                                        break;
+                                       
+                               case EGO_S_DWARVEN:
+                                       o_ptr->weight = (2 * k_info[o_ptr->k_idx].weight / 3);
+                                       o_ptr->ac = k_info[o_ptr->k_idx].ac + 3;
+                                       break;
                                }
                        }
                        break;
@@ -2809,9 +2931,6 @@ static void a_m_aux_2(object_type *o_ptr, int level, int power)
                {
                        if (o_ptr->sval == SV_SET_OF_DRAGON_GLOVES)
                        {
-                               /* Rating boost */
-                               rating += 5;
-
                                /* Mention the item */
                                if (cheat_peek) object_mention(o_ptr);
                                dragon_resist(o_ptr);
@@ -2840,9 +2959,6 @@ static void a_m_aux_2(object_type *o_ptr, int level, int power)
                {
                        if (o_ptr->sval == SV_PAIR_OF_DRAGON_GREAVE)
                        {
-                               /* Rating boost */
-                               rating += 5;
-
                                /* Mention the item */
                                if (cheat_peek) object_mention(o_ptr);
                                dragon_resist(o_ptr);
@@ -2902,6 +3018,7 @@ static void a_m_aux_2(object_type *o_ptr, int level, int power)
                                        case EGO_MIGHT:
                                        case EGO_REGENERATION:
                                        case EGO_LORDLINESS:
+                                       case EGO_BASILISK:
                                                break;
                                        case EGO_SEEING:
                                                if (one_in_(3))
@@ -2921,8 +3038,26 @@ static void a_m_aux_2(object_type *o_ptr, int level, int power)
 
                        /* Very cursed */
                        else if (power < -1)
-                       {
-                               o_ptr->name2 = get_random_ego(INVEN_HEAD, FALSE);
+                       {       
+                               while (1)
+                               {
+                                       bool ok_flag = TRUE;
+                                       o_ptr->name2 = get_random_ego(INVEN_HEAD, FALSE);
+
+                                       switch (o_ptr->name2)
+                                       {
+                                         case EGO_ANCIENT_CURSE:
+                                               if (one_in_(3)) add_flag(o_ptr->art_flags, TR_NO_MAGIC);
+                                               if (one_in_(3)) add_flag(o_ptr->art_flags, TR_NO_TELE);
+                                               if (one_in_(3)) add_flag(o_ptr->art_flags, TR_TY_CURSE);
+                                               if (one_in_(3)) add_flag(o_ptr->art_flags, TR_DRAIN_EXP);
+                                               if (one_in_(3)) add_flag(o_ptr->art_flags, TR_DRAIN_HP);
+                                               if (one_in_(3)) add_flag(o_ptr->art_flags, TR_DRAIN_MANA);
+                                               break;
+                                       }
+                                       if (ok_flag)
+                                               break; /* while (1) */
+                               }
                        }
 
                        break;
@@ -2932,9 +3067,6 @@ static void a_m_aux_2(object_type *o_ptr, int level, int power)
                {
                        if (o_ptr->sval == SV_DRAGON_HELM)
                        {
-                               /* Rating boost */
-                               rating += 5;
-
                                /* Mention the item */
                                if (cheat_peek) object_mention(o_ptr);
                                dragon_resist(o_ptr);
@@ -2956,11 +3088,10 @@ static void a_m_aux_2(object_type *o_ptr, int level, int power)
 
                                        switch (o_ptr->name2)
                                        {
-                                       case EGO_INTELLIGENCE:
-                                       case EGO_WISDOM:
-                                       case EGO_BEAUTY:
-                                       case EGO_LITE:
+                                       case EGO_BRILLIANCE:
+                                       case EGO_DARK:
                                        case EGO_INFRAVISION:
+                                       case EGO_H_PROTECTION:
                                                break;
                                        case EGO_SEEING:
                                                if (one_in_(7))
@@ -2969,6 +3100,27 @@ static void a_m_aux_2(object_type *o_ptr, int level, int power)
                                                        else add_esp_weak(o_ptr, FALSE);
                                                }
                                                break;
+                                       case EGO_LITE:
+                                               if (one_in_(3)) add_flag(o_ptr->art_flags, TR_LITE_1);
+                                               if (one_in_(3)) add_flag(o_ptr->art_flags, TR_LITE_2);
+                                               break;
+                                       case EGO_H_DEMON:
+                                               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);
+                                               
+                                               if (one_in_(3)) add_flag(o_ptr->art_flags, TR_AGGRAVATE);
+                                               if (one_in_(3)) add_flag(o_ptr->art_flags, TR_ADD_L_CURSE);
+                                               if (one_in_(5)) add_flag(o_ptr->art_flags, TR_ADD_H_CURSE);
+                                               if (one_in_(5)) add_flag(o_ptr->art_flags, TR_DRAIN_HP);
+                                               if (one_in_(5)) add_flag(o_ptr->art_flags, TR_DRAIN_MANA);
+                                               if (one_in_(5)) add_flag(o_ptr->art_flags, TR_DRAIN_EXP);
+                                               if (one_in_(5)) add_flag(o_ptr->art_flags, TR_TY_CURSE);
+                                               if (one_in_(5)) add_flag(o_ptr->art_flags, TR_CALL_DEMON);
+                                               break;
                                        default:/* not existing helm (Magi, Might, etc...)*/
                                                ok_flag = FALSE;
                                        }
@@ -2980,7 +3132,19 @@ static void a_m_aux_2(object_type *o_ptr, int level, int power)
                        /* Very cursed */
                        else if (power < -1)
                        {
-                               o_ptr->name2 = get_random_ego(INVEN_HEAD, FALSE);
+                               while (1)
+                               {
+                                       bool ok_flag = TRUE;
+                                       o_ptr->name2 = get_random_ego(INVEN_HEAD, FALSE);
+
+                                       switch (o_ptr->name2)
+                                       {
+                                         case EGO_ANCIENT_CURSE:
+                                               ok_flag = FALSE;
+                                       }
+                                       if (ok_flag)
+                                               break; /* while (1) */
+                               }
                        }
                        break;
                }
@@ -3003,6 +3167,14 @@ static void a_m_aux_2(object_type *o_ptr, int level, int power)
                                        o_ptr->to_d -= 6;
                                        o_ptr->to_h -= 6;
                                        break;
+                                 case EGO_NAZGUL:
+                                       o_ptr->to_d -= 3;
+                                       o_ptr->to_h -= 3;
+                                       if (one_in_(3)) add_flag(o_ptr->art_flags, TR_COWARDICE);
+                                       if (one_in_(3)) add_flag(o_ptr->art_flags, TR_CALL_UNDEAD);
+                                       if (one_in_(3)) add_flag(o_ptr->art_flags, TR_SLOW_REGEN);
+                                       if (one_in_(3)) add_flag(o_ptr->art_flags, TR_DRAIN_EXP);
+                                       break;
                                }
 
                        }
@@ -3019,13 +3191,16 @@ static void a_m_aux_2(object_type *o_ptr, int level, int power)
 }
 
 
-/*
+/*!
+ * @brief Áõ¾þÉÊ·Ï¥ª¥Ö¥¸¥§¥¯¥È¤ËÀ¸À®¥é¥ó¥¯¤´¤È¤Î¶¯²½¤òÍ¿¤¨¤ë¥µ¥Ö¥ë¡¼¥Á¥ó
  * Apply magic to an item known to be a "ring" or "amulet"
- *
- * Hack -- note special rating boost for ring of speed
- * Hack -- note special rating boost for amulet of the magi
- * Hack -- note special "pval boost" code for ring of speed
- * Hack -- note that some items must be cursed (or blessed)
+ * @param o_ptr ¶¯²½¤òÍ¿¤¨¤¿¤¤¥ª¥Ö¥¸¥§¥¯¥È¤Î¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿
+ * @param level À¸À®´ð½à³¬
+ * @param power À¸À®¥é¥ó¥¯
+ * @return ¤Ê¤·
+ * @details
+ * Hack -- note special "pval boost" code for ring of speed\n
+ * Hack -- note that some items must be cursed (or blessed)\n
  */
 static void a_m_aux_3(object_type *o_ptr, int level, int power)
 {
@@ -3113,9 +3288,6 @@ static void a_m_aux_3(object_type *o_ptr, int level, int power)
                                                break;
                                        }
 
-                                       /* Rating boost */
-                                       rating += 25;
-
                                        /* Mention the item */
                                        if (cheat_peek) object_mention(o_ptr);
 
@@ -3132,7 +3304,6 @@ static void a_m_aux_3(object_type *o_ptr, int level, int power)
 
                                        /* Bonus to armor class */
                                        o_ptr->to_a = 10 + randint1(5) + m_bonus(10, level);
-                                       rating += 15;
                                }
                                break;
 
@@ -3331,7 +3502,7 @@ static void a_m_aux_3(object_type *o_ptr, int level, int power)
                                        break;
                                }
                        }
-                       if ((one_in_(400) && (power > 0) && !cursed_p(o_ptr) && (level > 79))
+                       if ((one_in_(400) && (power > 0) && !object_is_cursed(o_ptr) && (level > 79))
                            || (power > 2)) /* power > 2 is debug only */
                        {
                                o_ptr->pval = MIN(o_ptr->pval, 4);
@@ -3354,7 +3525,7 @@ static void a_m_aux_3(object_type *o_ptr, int level, int power)
                                                o_ptr->name2 = EGO_RING_REGEN;
                                                break;
                                        case 5: case 6:
-                                               if (have_flag(k_ptr->flags, TR_LITE)) break;
+                                               if (have_flag(k_ptr->flags, TR_LITE_1)) break;
                                                o_ptr->name2 = EGO_RING_LITE;
                                                break;
                                        case 7: case 8:
@@ -3624,9 +3795,6 @@ static void a_m_aux_3(object_type *o_ptr, int level, int power)
                                        /* gain one low ESP */
                                        add_esp_weak(o_ptr, FALSE);
 
-                                       /* Boost the rating */
-                                       rating += 15;
-
                                        /* Mention the item */
                                        if (cheat_peek) object_mention(o_ptr);
 
@@ -3670,7 +3838,7 @@ static void a_m_aux_3(object_type *o_ptr, int level, int power)
                                        break;
                                }
                        }
-                       if ((one_in_(150) && (power > 0) && !cursed_p(o_ptr) && (level > 79))
+                       if ((one_in_(150) && (power > 0) && !object_is_cursed(o_ptr) && (level > 79))
                            || (power > 2)) /* power > 2 is debug only */
                        {
                                o_ptr->pval = MIN(o_ptr->pval, 4);
@@ -3697,11 +3865,11 @@ static void a_m_aux_3(object_type *o_ptr, int level, int power)
                                                o_ptr->name2 = EGO_AMU_SEE_INVIS;
                                                break;
                                        case 7: case 8:
-                                               if (have_flag(k_ptr->flags, TR_HOLD_LIFE)) break;
-                                               o_ptr->name2 = EGO_AMU_HOLD_LIFE;
+                                               if (have_flag(k_ptr->flags, TR_HOLD_EXP)) break;
+                                               o_ptr->name2 = EGO_AMU_HOLD_EXP;
                                                break;
                                        case 9:
-                                               if (have_flag(k_ptr->flags, TR_FEATHER)) break;
+                                               if (have_flag(k_ptr->flags, TR_LEVITATION)) break;
                                                o_ptr->name2 = EGO_AMU_LEVITATION;
                                                break;
                                        case 10: case 11: case 21:
@@ -3819,9 +3987,10 @@ static void a_m_aux_3(object_type *o_ptr, int level, int power)
        }
 }
 
-
-/*
- * Hack -- help pick an item type
+/*!
+ * @brief ¥â¥ó¥¹¥¿¡¼¤¬¿Í·Á¤Î¥Ù¡¼¥¹¤Ë¤Ç¤­¤ë¤«¤òÊÖ¤¹
+ * @param r_idx ¥Á¥§¥Ã¥¯¤·¤¿¤¤¥â¥ó¥¹¥¿¡¼¼ï²¤ÎID
+ * @return ¿Í·Á¤Ë¤Ç¤­¤ë¤Ê¤éTRUE¤òÊÖ¤¹
  */
 static bool item_monster_okay(int r_idx)
 {
@@ -3840,9 +4009,14 @@ static bool item_monster_okay(int r_idx)
 }
 
 
-/*
+/*!
+ * @brief ¤½¤Î¾»¨Â¿¤Î¥ª¥Ö¥¸¥§¥¯¥È¤ËÀ¸À®¥é¥ó¥¯¤´¤È¤Î¶¯²½¤òÍ¿¤¨¤ë¥µ¥Ö¥ë¡¼¥Á¥ó
  * Apply magic to an item known to be "boring"
- *
+ * @param o_ptr ¶¯²½¤òÍ¿¤¨¤¿¤¤¥ª¥Ö¥¸¥§¥¯¥È¤Î¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿
+ * @param level À¸À®´ð½à³¬
+ * @param power À¸À®¥é¥ó¥¯
+ * @return ¤Ê¤·
+ * @details
  * Hack -- note the special code for various items
  */
 static void a_m_aux_4(object_type *o_ptr, int level, int power)
@@ -3925,6 +4099,19 @@ static void a_m_aux_4(object_type *o_ptr, int level, int power)
                                {
                                case EGO_LITE_DARKNESS:
                                        o_ptr->xtra4 = 0;
+                                       
+                                       if (o_ptr->sval == SV_LITE_TORCH)
+                                       {
+                                               add_flag(o_ptr->art_flags, TR_LITE_M1);
+                                       }
+                                       else if (o_ptr->sval == SV_LITE_LANTERN)
+                                       {
+                                               add_flag(o_ptr->art_flags, TR_LITE_M2);
+                                       }
+                                       else if (o_ptr->sval == SV_LITE_FEANOR)
+                                       {
+                                               add_flag(o_ptr->art_flags, TR_LITE_M3);
+                                       }
                                        break;
                                }
                        }
@@ -3979,6 +4166,9 @@ static void a_m_aux_4(object_type *o_ptr, int level, int power)
                                /* Ignore dead monsters */
                                if (!r_ptr->rarity) continue;
 
+                               /* Ignore uncommon monsters */
+                               if (r_ptr->rarity > 100) continue;
+
                                /* Prefer less out-of-depth monsters */
                                if (randint0(check)) continue;
 
@@ -3999,7 +4189,7 @@ static void a_m_aux_4(object_type *o_ptr, int level, int power)
 #endif
 
                                                          r_name + r_ptr->name, check - 1,
-                                                         !cursed_p(o_ptr) ? "" : " {cursed}");
+                                                         !object_is_cursed(o_ptr) ? "" : " {cursed}");
                        }
 
                        break;
@@ -4103,7 +4293,7 @@ static void a_m_aux_4(object_type *o_ptr, int level, int power)
 
                case TV_CHEST:
                {
-                       byte obj_level = get_object_level(o_ptr);
+                       byte obj_level = k_info[o_ptr->k_idx].level;
 
                        /* Hack -- skip ruined chests */
                        if (obj_level <= 0) break;
@@ -4122,37 +4312,41 @@ static void a_m_aux_4(object_type *o_ptr, int level, int power)
        }
 }
 
-
-/*
+/*!
+ * @brief À¸À®¤µ¤ì¤¿¥Ù¡¼¥¹¥¢¥¤¥Æ¥à¤ËËâˡŪ¤Ê¶¯²½¤òÍ¿¤¨¤ë¥á¥¤¥ó¥ë¡¼¥Á¥ó
  * Complete the "creation" of an object by applying "magic" to the item
- *
- * This includes not only rolling for random bonuses, but also putting the
- * finishing touches on ego-items and artifacts, giving charges to wands and
- * staffs, giving fuel to lites, and placing traps on chests.
- *
- * In particular, note that "Instant Artifacts", if "created" by an external
- * routine, must pass through this function to complete the actual creation.
- *
- * The base "chance" of the item being "good" increases with the "level"
- * parameter, which is usually derived from the dungeon level, being equal
- * to the level plus 10, up to a maximum of 75.  If "good" is true, then
- * the object is guaranteed to be "good".  If an object is "good", then
- * the chance that the object will be "great" (ego-item or artifact), also
- * increases with the "level", being equal to half the level, plus 5, up to
- * a maximum of 20.  If "great" is true, then the object is guaranteed to be
- * "great".  At dungeon level 65 and below, 15/100 objects are "great".
- *
- * If the object is not "good", there is a chance it will be "cursed", and
- * if it is "cursed", there is a chance it will be "broken".  These chances
- * are related to the "good" / "great" chances above.
- *
- * Otherwise "normal" rings and amulets will be "good" half the time and
- * "cursed" half the time, unless the ring/amulet is always good or cursed.
- *
- * If "okay" is true, and the object is going to be "great", then there is
- * a chance that an artifact will be created.  This is true even if both the
- * "good" and "great" arguments are false.  As a total hack, if "great" is
- * true, then the item gets 3 extra "attempts" to become an artifact.
+ * @param o_ptr ¶¯²½¤òÍ¿¤¨¤¿¤¤¥ª¥Ö¥¸¥§¥¯¥È¤Î¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿
+ * @param lev À¸À®´ð½à³¬
+ * @param mode À¸À®¥ª¥×¥·¥ç¥ó
+ * @return ¤Ê¤·
+ * @details
+ * This includes not only rolling for random bonuses, but also putting the\n
+ * finishing touches on ego-items and artifacts, giving charges to wands and\n
+ * staffs, giving fuel to lites, and placing traps on chests.\n
+ *\n
+ * In particular, note that "Instant Artifacts", if "created" by an external\n
+ * routine, must pass through this function to complete the actual creation.\n
+ *\n
+ * The base "chance" of the item being "good" increases with the "level"\n
+ * parameter, which is usually derived from the dungeon level, being equal\n
+ * to the level plus 10, up to a maximum of 75.  If "good" is true, then\n
+ * the object is guaranteed to be "good".  If an object is "good", then\n
+ * the chance that the object will be "great" (ego-item or artifact), also\n
+ * increases with the "level", being equal to half the level, plus 5, up to\n
+ * a maximum of 20.  If "great" is true, then the object is guaranteed to be\n
+ * "great".  At dungeon level 65 and below, 15/100 objects are "great".\n
+ *\n
+ * If the object is not "good", there is a chance it will be "cursed", and\n
+ * if it is "cursed", there is a chance it will be "broken".  These chances\n
+ * are related to the "good" / "great" chances above.\n
+ *\n
+ * Otherwise "normal" rings and amulets will be "good" half the time and\n
+ * "cursed" half the time, unless the ring/amulet is always good or cursed.\n
+ *\n
+ * If "okay" is true, and the object is going to be "great", then there is\n
+ * a chance that an artifact will be created.  This is true even if both the\n
+ * "good" and "great" arguments are false.  As a total hack, if "great" is\n
+ * true, then the item gets 3 extra "attempts" to become an artifact.\n
  */
 void apply_magic(object_type *o_ptr, int lev, u32b mode)
 {
@@ -4256,7 +4450,7 @@ void apply_magic(object_type *o_ptr, int lev, u32b mode)
 
 
        /* Hack -- analyze artifacts */
-       if (o_ptr->name1)
+       if (object_is_fixed_artifact(o_ptr))
        {
                artifact_type *a_ptr = &a_info[o_ptr->name1];
 
@@ -4276,6 +4470,15 @@ void apply_magic(object_type *o_ptr, int lev, u32b mode)
                o_ptr->to_h = a_ptr->to_h;
                o_ptr->to_d = a_ptr->to_d;
                o_ptr->weight = a_ptr->weight;
+               o_ptr->xtra2 = a_ptr->act_idx;
+
+               if (o_ptr->name1 == ART_MILIM)
+               {
+                   if(p_ptr->pseikaku == SEIKAKU_SEXY)
+                   {
+                       o_ptr->pval = 3;
+                   }
+               }
 
                /* Hack -- extract the "broken" flag */
                if (!a_ptr->cost) o_ptr->ident |= (IDENT_BROKEN);
@@ -4288,17 +4491,6 @@ void apply_magic(object_type *o_ptr, int lev, u32b mode)
                if (a_ptr->gen_flags & (TRG_RANDOM_CURSE1)) o_ptr->curse_flags |= get_curse(1, o_ptr);
                if (a_ptr->gen_flags & (TRG_RANDOM_CURSE2)) o_ptr->curse_flags |= get_curse(2, o_ptr);
 
-               /* Mega-Hack -- increase the rating */
-               rating += 10;
-
-               /* Mega-Hack -- increase the rating again */
-               if (a_ptr->cost > 50000L) rating += 10;
-
-               /* Mega-Hack -- increase the rating again */
-               if (a_ptr->cost > 100000L) rating += 10;
-
-               /* Set the good item flag */
-               good_item_flag = TRUE;
 
                /* Cheat -- peek at the item */
                if (cheat_peek) object_mention(o_ptr);
@@ -4390,10 +4582,8 @@ void apply_magic(object_type *o_ptr, int lev, u32b mode)
                add_flag(o_ptr->art_flags, TR_CHR);
        }
 
-       if (o_ptr->art_name) rating += 30;
-
        /* Hack -- analyze ego-items */
-       else if (o_ptr->name2)
+       if (object_is_ego(o_ptr))
        {
                ego_item_type *e_ptr = &e_info[o_ptr->name2];
 
@@ -4415,9 +4605,22 @@ void apply_magic(object_type *o_ptr, int lev, u32b mode)
                if (e_ptr->gen_flags & (TRG_XTRA_D_RES)) one_dragon_ele_resistance(o_ptr);
                if (e_ptr->gen_flags & (TRG_XTRA_L_RES)) one_lordly_high_resistance(o_ptr);
                if (e_ptr->gen_flags & (TRG_XTRA_RES)) one_resistance(o_ptr);
+               if (e_ptr->gen_flags & (TRG_XTRA_DICE))
+               {
+                       do
+                       {
+                               o_ptr->dd++;
+                       }
+                       while (one_in_(o_ptr->dd));
+
+                       if (o_ptr->dd > 9) o_ptr->dd = 9;
+               }
+
+               /* Hack -- apply activatin index if needed */
+               if (e_ptr->act_idx) o_ptr->xtra2 = e_ptr->act_idx;
 
                /* Hack -- apply extra penalties if needed */
-               if (cursed_p(o_ptr) || broken_p(o_ptr))
+               if ((object_is_cursed(o_ptr) || object_is_broken(o_ptr)) && !(e_ptr->gen_flags & (TRG_POWERFUL)))
                {
                        /* Hack -- obtain bonuses */
                        if (e_ptr->max_to_h) o_ptr->to_h -= randint1(e_ptr->max_to_h);
@@ -4450,6 +4653,34 @@ void apply_magic(object_type *o_ptr, int lev, u32b mode)
                                        o_ptr->to_a -= randint1(256-e_ptr->max_to_a);
                                else o_ptr->to_a += randint1(e_ptr->max_to_a);
                        }
+                       
+                       /* Accuracy ego must have high to_h */
+                       if(o_ptr->name2 == EGO_ACCURACY)
+                       {
+                               while(o_ptr->to_h < o_ptr->to_d + 10)
+                               {
+                                       o_ptr->to_h += 5;
+                                       o_ptr->to_d -= 5;
+                               }
+                               o_ptr->to_h = MAX(o_ptr->to_h, 15);
+                       }
+                       
+                       /* Accuracy ego must have high to_h */
+                       if(o_ptr->name2 == EGO_VELOCITY)
+                       {
+                               while(o_ptr->to_d < o_ptr->to_h + 10)
+                               {
+                                       o_ptr->to_d += 5;
+                                       o_ptr->to_h -= 5;
+                               }
+                               o_ptr->to_d = MAX(o_ptr->to_d, 15);
+                       }
+                       
+                       /* Protection ego must have high to_a */
+                       if((o_ptr->name2 == EGO_PROTECTION) || (o_ptr->name2 == EGO_S_PROTECTION) || (o_ptr->name2 == EGO_H_PROTECTION))
+                       {
+                               o_ptr->to_a = MAX(o_ptr->to_a, 15);
+                       }
 
                        /* Hack -- obtain pval */
                        if (e_ptr->max_pval)
@@ -4459,6 +4690,17 @@ void apply_magic(object_type *o_ptr, int lev, u32b mode)
                                        o_ptr->pval++;
                                        if ((lev > 60) && one_in_(3) && ((o_ptr->dd*(o_ptr->ds+1)) < 15)) o_ptr->pval++;
                                }
+                               else if (o_ptr->name2 == EGO_DEMON)
+                               {
+                                       if(have_flag(o_ptr->art_flags, TR_BLOWS))
+                                       {
+                                               o_ptr->pval += randint1(2);
+                                       }
+                                       else
+                                       {
+                                               o_ptr->pval += randint1(e_ptr->max_pval);
+                                       }
+                               }
                                else if (o_ptr->name2 == EGO_ATTACKS)
                                {
                                        o_ptr->pval = randint1(e_ptr->max_pval*lev/100+1);
@@ -4471,10 +4713,16 @@ void apply_magic(object_type *o_ptr, int lev, u32b mode)
                                        o_ptr->pval = randint1(e_ptr->max_pval);
                                        if (o_ptr->sval == SV_ELVEN_CLOAK) o_ptr->pval += randint1(2);
                                }
+                               else if (o_ptr->name2 == EGO_A_DEMON || o_ptr->name2 == EGO_DRUID || o_ptr->name2 == EGO_OLOG)
+                               {
+                                       o_ptr->pval = randint1(e_ptr->max_pval);
+                               }
                                else
                                {
                                        o_ptr->pval += randint1(e_ptr->max_pval);
                                }
+                               
+                               
                        }
                        if ((o_ptr->name2 == EGO_SPEED) && (lev < 50))
                        {
@@ -4484,12 +4732,9 @@ void apply_magic(object_type *o_ptr, int lev, u32b mode)
                                o_ptr->pval = 2;
                }
 
-               /* Hack -- apply rating bonus */
-               rating += e_ptr->rating;
-
                /* Cheat -- describe the item */
                if (cheat_peek) object_mention(o_ptr);
-
+               
                /* Done */
                return;
        }
@@ -4500,7 +4745,7 @@ void apply_magic(object_type *o_ptr, int lev, u32b mode)
                object_kind *k_ptr = &k_info[o_ptr->k_idx];
 
                /* Hack -- acquire "broken" flag */
-               if (!get_object_cost(o_ptr)) o_ptr->ident |= (IDENT_BROKEN);
+               if (!k_info[o_ptr->k_idx].cost) o_ptr->ident |= (IDENT_BROKEN);
 
                /* Hack -- acquire "cursed" flag */
                if (k_ptr->gen_flags & (TRG_CURSED)) o_ptr->curse_flags |= (TRC_CURSED);
@@ -4513,8 +4758,11 @@ void apply_magic(object_type *o_ptr, int lev, u32b mode)
 }
 
 
-/*
+/*!
+ * @brief ¥Ù¡¼¥¹¥¢¥¤¥Æ¥à¤¬¾å¼Á¤È¤·¤Æ°·¤ï¤ì¤ë¤«¤É¤¦¤«¤òÊÖ¤¹¡£
  * Hack -- determine if a template is "good"
+ * @param k_idx È½Äꤷ¤¿¤¤¥Ù¡¼¥¹¥¢¥¤¥Æ¥à¤ÎID
+ * @return ¥Ù¡¼¥¹¥¢¥¤¥Æ¥à¤¬¾å¼Á¤Ê¤é¤ÐTRUE¤òÊÖ¤¹¡£
  */
 static bool kind_is_good(int k_idx)
 {
@@ -4564,11 +4812,12 @@ static bool kind_is_good(int k_idx)
                case TV_CHAOS_BOOK:
                case TV_DEATH_BOOK:
                case TV_TRUMP_BOOK:
-               case TV_ENCHANT_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);
@@ -4595,15 +4844,16 @@ static bool kind_is_good(int k_idx)
        return (FALSE);
 }
 
-
-/*
+/*!
+ * @brief À¸À®³¬¤Ë±þ¤¸¤¿¥Ù¡¼¥¹¥¢¥¤¥Æ¥à¤ÎÀ¸À®¤ò¹Ô¤¦¡£
  * Attempt to make an object (normal or good/great)
- *
- * This routine plays nasty games to generate the "special artifacts".
- *
- * This routine uses "object_level" for the "generation level".
- *
- * We assume that the given object has been "wiped".
+ * @param j_ptr À¸À®·ë²Ì¤ò¼ý¤á¤¿¤¤¥ª¥Ö¥¸¥§¥¯¥È¹½Â¤ÂΤλ²¾È¥Ý¥¤¥ó¥¿
+ * @param mode ¥ª¥×¥·¥ç¥ó¥Õ¥é¥°
+ * @return À¸À®¤ËÀ®¸ù¤·¤¿¤éTRUE¤òÊÖ¤¹¡£
+ * @details
+ * This routine plays nasty games to generate the "special artifacts".\n
+ * This routine uses "object_level" for the "generation level".\n
+ * We assume that the given object has been "wiped".\n
  */
 bool make_object(object_type *j_ptr, u32b mode)
 {
@@ -4669,16 +4919,13 @@ bool make_object(object_type *j_ptr, u32b mode)
                }
        }
 
-       obj_level = get_object_level(j_ptr);
-       if (artifact_p(j_ptr)) obj_level = a_info[j_ptr->name1].level;
+       obj_level = k_info[j_ptr->k_idx].level;
+       if (object_is_fixed_artifact(j_ptr)) obj_level = a_info[j_ptr->name1].level;
 
        /* Notice "okay" out-of-depth objects */
-       if (!cursed_p(j_ptr) && !broken_p(j_ptr) &&
+       if (!object_is_cursed(j_ptr) && !object_is_broken(j_ptr) &&
            (obj_level > dun_level))
        {
-               /* Rating increase */
-               rating += (obj_level - dun_level);
-
                /* Cheat -- peek at items */
                if (cheat_peek) object_mention(j_ptr);
        }
@@ -4688,14 +4935,17 @@ bool make_object(object_type *j_ptr, u32b mode)
 }
 
 
-/*
+/*!
+ * @brief ¥Õ¥í¥¢¤Î»ØÄê°ÌÃÖ¤ËÀ¸À®³¬¤Ë±þ¤¸¤¿¥Ù¡¼¥¹¥¢¥¤¥Æ¥à¤ÎÀ¸À®¤ò¹Ô¤¦¡£
  * Attempt to place an object (normal or good/great) at the given location.
- *
- * This routine plays nasty games to generate the "special artifacts".
- *
- * This routine uses "object_level" for the "generation level".
- *
- * This routine requires a clean floor grid destination.
+ * @param y ÇÛÃÖ¤·¤¿¤¤¥Õ¥í¥¢¤ÎYºÂɸ
+ * @param x ÇÛÃÖ¤·¤¿¤¤¥Õ¥í¥¢¤ÎXºÂɸ
+ * @param mode ¥ª¥×¥·¥ç¥ó¥Õ¥é¥°
+ * @return À¸À®¤ËÀ®¸ù¤·¤¿¤éTRUE¤òÊÖ¤¹¡£
+ * @details
+ * This routine plays nasty games to generate the "special artifacts".\n
+ * This routine uses "object_level" for the "generation level".\n
+ * This routine requires a clean floor grid destination.\n
  */
 void place_object(int y, int x, u32b mode)
 {
@@ -4761,7 +5011,7 @@ void place_object(int y, int x, u32b mode)
        else
        {
                /* Hack -- Preserve artifacts */
-               if (q_ptr->name1)
+               if (object_is_fixed_artifact(q_ptr))
                {
                        a_info[q_ptr->name1].cur_num = 0;
                }
@@ -4769,9 +5019,12 @@ void place_object(int y, int x, u32b mode)
 }
 
 
-/*
+/*!
+ * @brief À¸À®³¬¤Ë±þ¤¸¤¿ºâÊõ¥ª¥Ö¥¸¥§¥¯¥È¤ÎÀ¸À®¤ò¹Ô¤¦¡£
  * Make a treasure object
- *
+ * @param j_ptr À¸À®·ë²Ì¤ò¼ý¤á¤¿¤¤¥ª¥Ö¥¸¥§¥¯¥È¹½Â¤ÂΤλ²¾È¥Ý¥¤¥ó¥¿
+ * @return À¸À®¤ËÀ®¸ù¤·¤¿¤éTRUE¤òÊÖ¤¹¡£
+ * @details
  * The location must be a legal, clean, floor grid.
  */
 bool make_gold(object_type *j_ptr)
@@ -4810,9 +5063,13 @@ bool make_gold(object_type *j_ptr)
 }
 
 
-/*
+/*!
+ * @brief ¥Õ¥í¥¢¤Î»ØÄê°ÌÃÖ¤ËÀ¸À®³¬¤Ë±þ¤¸¤¿ºâÊõ¥ª¥Ö¥¸¥§¥¯¥È¤ÎÀ¸À®¤ò¹Ô¤¦¡£
  * Places a treasure (Gold or Gems) at given location
- *
+ * @param y ÇÛÃÖ¤·¤¿¤¤¥Õ¥í¥¢¤ÎYºÂɸ
+ * @param x ÇÛÃÖ¤·¤¿¤¤¥Õ¥í¥¢¤ÎXºÂɸ
+ * @return À¸À®¤ËÀ®¸ù¤·¤¿¤éTRUE¤òÊÖ¤¹¡£
+ * @details
  * The location must be a legal, clean, floor grid.
  */
 void place_gold(int y, int x)
@@ -4880,21 +5137,27 @@ void place_gold(int y, int x)
 }
 
 
-/*
+/*!
+ * @brief À¸À®ºÑ¤Î¥ª¥Ö¥¸¥§¥¯¥È¤ò¥Õ¥í¥¢¤Î½êÄê¤Î°ÌÃÖ¤ËÍî¤È¤¹¡£
  * Let an object fall to the ground at or near a location.
- *
- * The initial location is assumed to be "in_bounds()".
- *
- * This function takes a parameter "chance".  This is the percentage
- * chance that the item will "disappear" instead of drop.  If the object
- * has been thrown, then this is the chance of disappearance on contact.
- *
- * Hack -- this function uses "chance" to determine if it should produce
- * some form of "description" of the drop event (under the player).
- *
- * We check several locations to see if we can find a location at which
- * the object can combine, stack, or be placed.  Artifacts will try very
- * hard to be placed, including "teleporting" to a useful grid if needed.
+ * @param j_ptr Íî¤È¤·¤¿¤¤¥ª¥Ö¥¸¥§¥¯¥È¹½Â¤ÂΤλ²¾È¥Ý¥¤¥ó¥¿
+ * @param chance ¥É¥í¥Ã¥×¤ÎÀ®¸ùΨ(%)
+ * @param y ÇÛÃÖ¤·¤¿¤¤¥Õ¥í¥¢¤ÎYºÂɸ
+ * @param x ÇÛÃÖ¤·¤¿¤¤¥Õ¥í¥¢¤ÎXºÂɸ
+ * @return À¸À®¤ËÀ®¸ù¤·¤¿¤éTRUE¤òÊÖ¤¹¡£
+ * @details
+ * The initial location is assumed to be "in_bounds()".\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
+ * has been thrown, then this is the chance of disappearance on contact.\n
+ *\n
+ * Hack -- this function uses "chance" to determine if it should produce\n
+ * some form of "description" of the drop event (under the player).\n
+ *\n
+ * We check several locations to see if we can find a location at which\n
+ * the object can combine, stack, or be placed.  Artifacts will try very\n
+ * hard to be placed, including "teleporting" to a useful grid if needed.\n
  */
 s16b drop_near(object_type *j_ptr, int chance, int y, int x)
 {
@@ -4903,7 +5166,7 @@ s16b drop_near(object_type *j_ptr, int chance, int y, int x)
        int bs, bn;
        int by, bx;
        int dy, dx;
-       int ty, tx;
+       int ty, tx = 0;
 
        s16b o_idx = 0;
 
@@ -4926,7 +5189,7 @@ s16b drop_near(object_type *j_ptr, int chance, int y, int x)
 
 
        /* Handle normal "breakage" */
-       if (!(j_ptr->art_name || artifact_p(j_ptr)) && (randint0(100) < chance))
+       if (!object_is_artifact(j_ptr) && (randint0(100) < chance))
        {
                /* Message */
 #ifdef JP
@@ -4981,8 +5244,8 @@ s16b drop_near(object_type *j_ptr, int chance, int y, int x)
                        /* Skip illegal grids */
                        if (!in_bounds(ty, tx)) continue;
 
-                       /* Require line of sight */
-                       if (!los(y, x, ty, tx)) continue;
+                       /* Require line of projection */
+                       if (!projectable(y, x, ty, tx)) continue;
 
                        /* Obtain grid */
                        c_ptr = &cave[ty][tx];
@@ -5043,7 +5306,7 @@ s16b drop_near(object_type *j_ptr, int chance, int y, int x)
 
 
        /* Handle lack of space */
-       if (!flag && !(artifact_p(j_ptr) || j_ptr->art_name))
+       if (!flag && !object_is_artifact(j_ptr))
        {
                /* Message */
 #ifdef JP
@@ -5068,21 +5331,14 @@ s16b drop_near(object_type *j_ptr, int chance, int y, int x)
 
 
        /* Find a grid */
-       for (i = 0; !flag; i++)
+       for (i = 0; !flag && (i < 1000); i++)
        {
                /* Bounce around */
-               if (i < 1000)
-               {
-                       ty = rand_spread(by, 1);
-                       tx = rand_spread(bx, 1);
-               }
+               ty = rand_spread(by, 1);
+               tx = rand_spread(bx, 1);
 
-               /* Random locations */
-               else
-               {
-                       ty = randint0(cur_hgt);
-                       tx = randint0(cur_wid);
-               }
+               /* Verify location */
+               if (!in_bounds(ty, tx)) continue;
 
                /* Bounce to that location */
                by = ty;
@@ -5091,15 +5347,80 @@ s16b drop_near(object_type *j_ptr, int chance, int y, int x)
                /* Require floor space */
                if (!cave_drop_bold(by, bx)) continue;
 
-               /* Avoid stacking on other objects */
-               if (cave[by][bx].o_idx) continue;
-
-
                /* Okay */
                flag = TRUE;
        }
 
 
+       if (!flag)
+       {
+               int candidates = 0, pick;
+
+               for (ty = 1; ty < cur_hgt - 1; ty++)
+               {
+                       for (tx = 1; tx < cur_wid - 1; tx++)
+                       {
+                               /* A valid space found */
+                               if (cave_drop_bold(ty, tx)) candidates++;
+                       }
+               }
+
+               /* No valid place! */
+               if (!candidates)
+               {
+                       /* Message */
+#ifdef JP
+                       msg_format("%s¤Ï¾Ã¤¨¤¿¡£", o_name);
+#else
+                       msg_format("The %s disappear%s.", o_name, (plural ? "" : "s"));
+#endif
+
+                       /* Debug */
+#ifdef JP
+                       if (p_ptr->wizard) msg_print("(¾²¥¹¥Ú¡¼¥¹¤¬¤Ê¤¤)");
+#else
+                       if (p_ptr->wizard) msg_print("(no floor space)");
+#endif
+
+                       /* Mega-Hack -- preserve artifacts */
+                       if (preserve_mode)
+                       {
+                               /* Hack -- Preserve unknown artifacts */
+                               if (object_is_fixed_artifact(j_ptr) && !object_is_known(j_ptr))
+                               {
+                                       /* Mega-Hack -- Preserve the artifact */
+                                       a_info[j_ptr->name1].cur_num = 0;
+                               }
+                       }
+
+                       /* Failure */
+                       return 0;
+               }
+
+               /* Choose a random one */
+               pick = randint1(candidates);
+
+               for (ty = 1; ty < cur_hgt - 1; ty++)
+               {
+                       for (tx = 1; tx < cur_wid - 1; tx++)
+                       {
+                               if (cave_drop_bold(ty, tx))
+                               {
+                                       pick--;
+
+                                       /* Is this a picked one? */
+                                       if (!pick) break;
+                               }
+                       }
+
+                       if (!pick) break;
+               }
+
+               by = ty;
+               bx = tx;
+       }
+
+
        /* Grid */
        c_ptr = &cave[by][bx];
 
@@ -5152,7 +5473,7 @@ s16b drop_near(object_type *j_ptr, int chance, int y, int x)
 
 
                /* Hack -- Preserve artifacts */
-               if (j_ptr->name1)
+               if (object_is_fixed_artifact(j_ptr))
                {
                        a_info[j_ptr->name1].cur_num = 0;
                }
@@ -5215,14 +5536,22 @@ s16b drop_near(object_type *j_ptr, int chance, int y, int x)
 }
 
 
-/*
+/*!
+ * @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(int y1, int x1, int num, bool great, bool known)
+void acquirement(int y1, int x1, int num, bool great, bool special, bool known)
 {
        object_type *i_ptr;
        object_type object_type_body;
-       u32b mode = AM_GOOD | (great ? AM_GREAT : 0L);
+       u32b mode = AM_GOOD | (great || special ? AM_GREAT : 0L) | (special ? AM_SPECIAL : 0L) ;
 
        /* Acquirement */
        while (num--)
@@ -5247,39 +5576,177 @@ void acquirement(int y1, int x1, int num, bool great, bool known)
        }
 }
 
+/*
+ * 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 */
 
-#define MAX_TRAPS              18
+typedef struct
+{
+       int tval;
+       int sval;
+       int prob;
+       byte flag;
+} amuse_type;
 
-static int trap_num[MAX_TRAPS] =
+amuse_type amuse_info[] =
 {
-       FEAT_TRAP_TRAPDOOR,
-       FEAT_TRAP_PIT,
-       FEAT_TRAP_SPIKED_PIT,
-       FEAT_TRAP_POISON_PIT,
-       FEAT_TRAP_TY_CURSE,
-       FEAT_TRAP_TELEPORT,
-       FEAT_TRAP_FIRE,
-       FEAT_TRAP_ACID,
-       FEAT_TRAP_SLOW,
-       FEAT_TRAP_LOSE_STR,
-       FEAT_TRAP_LOSE_DEX,
-       FEAT_TRAP_LOSE_CON,
-       FEAT_TRAP_BLIND,
-       FEAT_TRAP_CONFUSE,
-       FEAT_TRAP_POISON,
-       FEAT_TRAP_SLEEP,
-       FEAT_TRAP_TRAPS,
-       FEAT_TRAP_ALARM,
+       { 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(int y1, int 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, k_idx, a_idx = 0;
+               int r = randint0(t);
+               bool insta_art, fixed_art;
+
+               for (i = 0; ; i++)
+               {
+                       r -= amuse_info[i].prob;
+                       if (r <= 0) break;
+               }
+
+               /* Get local object */
+               i_ptr = &object_type_body;
+
+               /* Wipe the object */
+               object_wipe(i_ptr);
+
+               /* Wipe the object */
+               k_idx = lookup_kind(amuse_info[i].tval, amuse_info[i].sval);
+
+               /* Paranoia - reroll if nothing */
+               if (!k_idx) continue;
+
+               /* Search an artifact index if need */
+               insta_art = (k_info[k_idx].gen_flags & TRG_INSTA_ART);
+               fixed_art = (amuse_info[i].flag & AMS_FIXED_ART);
+
+               if (insta_art || fixed_art)
+               {
+                       for (a_idx = 1; a_idx < max_a_idx; a_idx++)
+                       {
+                               if (insta_art && !(a_info[a_idx].gen_flags & TRG_INSTA_ART)) continue;
+                               if (a_info[a_idx].tval != k_info[k_idx].tval) continue;
+                               if (a_info[a_idx].sval != k_info[k_idx].sval) continue;
+                               if (a_info[a_idx].cur_num > 0) continue;
+                               break;
+                       }
+
+                       if (a_idx >= max_a_idx) continue;
+               }
+
+               /* Make an object (if possible) */
+               object_prep(i_ptr, k_idx);
+               if (a_idx) i_ptr->name1 = a_idx;
+               apply_magic(i_ptr, 1, AM_NO_FIXED_ART);
+
+               if (amuse_info[i].flag & AMS_NO_UNIQUE)
+               {
+                       if (r_info[i_ptr->pval].flags1 & RF1_UNIQUE) continue;
+               }
+
+               if (amuse_info[i].flag & AMS_MULTIPLE) i_ptr->number = randint1(3);
+               if (amuse_info[i].flag & AMS_PILE) i_ptr->number = randint1(99);
+
+               if (known)
+               {
+                       object_aware(i_ptr);
+                       object_known(i_ptr);
+               }
+
+               /* Paranoia - reroll if nothing */
+               if (!(i_ptr->k_idx)) continue;
+
+               /* Drop the object */
+               (void)drop_near(i_ptr, -1, y1, x1);
+
+               num--;
+       }
+}
+
+
+#define MAX_NORMAL_TRAPS 18
+
+/* See init_feat_variables() in init2.c */
+static s16b normal_traps[MAX_NORMAL_TRAPS];
+
+/*!
+ * @brief ¥¿¥°¤Ë½¾¤Ã¤Æ¡¢´ðËܥȥé¥Ã¥×¥Æ¡¼¥Ö¥ë¤ò½é´ü²½¤¹¤ë / Initialize arrays for normal traps
+ * @return ¤Ê¤·
+ */
+void init_normal_traps(void)
+{
+       int cur_trap = 0;
+
+       normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_TRAPDOOR");
+       normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_PIT");
+       normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_SPIKED_PIT");
+       normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_POISON_PIT");
+       normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_TY_CURSE");
+       normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_TELEPORT");
+       normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_FIRE");
+       normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_ACID");
+       normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_SLOW");
+       normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_LOSE_STR");
+       normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_LOSE_DEX");
+       normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_LOSE_CON");
+       normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_BLIND");
+       normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_CONFUSE");
+       normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_POISON");
+       normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_SLEEP");
+       normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_TRAPS");
+       normal_traps[cur_trap++] = f_tag_to_index_in_init("TRAP_ALARM");
+}
+
+/*!
+ * @brief ´ðËܥȥé¥Ã¥×¤ò¥é¥ó¥À¥à¤ËÁªÂò¤¹¤ë /
  * Get random trap
- *
- * XXX XXX XXX This routine should be redone to reflect trap "level".
- * That is, it does not make sense to have spiked pits at 50 feet.
- * Actually, it is not this routine, but the "trap instantiation"
- * code, which should also check for "trap doors" on quest levels.
+ * @return ÁªÂò¤·¤¿¥È¥é¥Ã¥×¤ÎID
+ * @details
+ * XXX XXX XXX This routine should be redone to reflect trap "level".\n
+ * That is, it does not make sense to have spiked pits at 50 feet.\n
+ * Actually, it is not this routine, but the "trap instantiation"\n
+ * code, which should also check for "trap doors" on quest levels.\n
  */
 s16b choose_random_trap(void)
 {
@@ -5289,7 +5756,7 @@ s16b choose_random_trap(void)
        while (1)
        {
                /* Hack -- pick a trap */
-               feat = trap_num[randint0(MAX_TRAPS)];
+               feat = normal_traps[randint0(MAX_NORMAL_TRAPS)];
 
                /* Accept non-trapdoors */
                if (!have_flag(f_info[feat].flags, FF_MORE)) break;
@@ -5306,14 +5773,18 @@ s16b choose_random_trap(void)
        return feat;
 }
 
-/*
+/*!
+ * @brief ¥Þ¥¹¤Ë¸ºß¤¹¤ë¥È¥é¥Ã¥×¤òÈëÆ¿¤¹¤ë /
  * Disclose an invisible trap
+ * @param y ÈëÆ¿¤·¤¿¤¤¥Þ¥¹¤ÎYºÂɸ
+ * @param x ÈëÆ¿¤·¤¿¤¤¥Þ¥¹¤ÎXºÂɸ
+ * @return ¤Ê¤·
  */
 void disclose_grid(int y, int x)
 {
        cave_type *c_ptr = &cave[y][x];
 
-       if (have_flag(f_flags_grid(c_ptr), FF_SECRET))
+       if (cave_have_flag_grid(c_ptr, FF_SECRET))
        {
                /* No longer hidden */
                cave_alter_feat(y, x, FF_SECRET);
@@ -5331,15 +5802,15 @@ void disclose_grid(int y, int x)
        }
 }
 
-
-/*
- * Places a random trap at the given location.
- *
+/*!
+ * @brief ¥Þ¥¹¤ò¥È¥é¥Ã¥×¤òÇÛÃÖ¤¹¤ë /
  * The location must be a legal, naked, floor grid.
- *
- * Note that all traps start out as "invisible" and "untyped", and then
- * when they are "discovered" (by detecting them or setting them off),
- * the trap is "instantiated" as a visible, "typed", trap.
+ * @param y ÇÛÃÖ¤·¤¿¤¤¥Þ¥¹¤ÎYºÂɸ
+ * @param x ÇÛÃÖ¤·¤¿¤¤¥Þ¥¹¤ÎXºÂɸ
+ * @return
+ * Note that all traps start out as "invisible" and "untyped", and then\n
+ * when they are "discovered" (by detecting them or setting them off),\n
+ * the trap is "instantiated" as a visible, "typed", trap.\n
  */
 void place_trap(int y, int x)
 {
@@ -5356,9 +5827,11 @@ void place_trap(int y, int x)
        c_ptr->feat = choose_random_trap();
 }
 
-
-/*
+/*!
+ * @brief ËâÆ»¶ñ¤Î»ÈÍѲó¿ô¤Î»ÄÎ̤ò¼¨¤¹¥á¥Ã¥»¡¼¥¸¤òɽ¼¨¤¹¤ë /
  * Describe the charges on an item in the inventory.
+ * @param item »ÄÎ̤òɽ¼¨¤·¤¿¤¤¥×¥ì¥¤¥ä¡¼¤Î¥¢¥¤¥Æ¥à½ê»ý¥¹¥í¥Ã¥È
+ * @return ¤Ê¤·
  */
 void inven_item_charges(int item)
 {
@@ -5368,7 +5841,7 @@ void inven_item_charges(int item)
        if ((o_ptr->tval != TV_STAFF) && (o_ptr->tval != TV_WAND)) return;
 
        /* Require known item */
-       if (!object_known_p(o_ptr)) return;
+       if (!object_is_known(o_ptr)) return;
 
 #ifdef JP
        if (o_ptr->pval <= 0)
@@ -5397,9 +5870,11 @@ void inven_item_charges(int item)
 
 }
 
-
-/*
+/*!
+ * @brief ¥¢¥¤¥Æ¥à¤Î»Ä¤ê½ê»ý¿ô¥á¥Ã¥»¡¼¥¸¤òɽ¼¨¤¹¤ë /
  * Describe an item in the inventory.
+ * @param item »ÄÎ̤òɽ¼¨¤·¤¿¤¤¥×¥ì¥¤¥ä¡¼¤Î¥¢¥¤¥Æ¥à½ê»ý¥¹¥í¥Ã¥È
+ * @return ¤Ê¤·
  */
 void inven_item_describe(int item)
 {
@@ -5428,9 +5903,12 @@ void inven_item_describe(int item)
 
 }
 
-
-/*
+/*!
+ * @brief ¥¢¥¤¥Æ¥à¤Î»Ä¤ê½ê»ý¿ô¥á¥Ã¥»¡¼¥¸¤òɽ¼¨¤¹¤ë /
  * Increase the "number" of an item in the inventory
+ * @param item ½ê»ý¿ô¤òÁý¤ä¤·¤¿¤¤¥×¥ì¥¤¥ä¡¼¤Î¥¢¥¤¥Æ¥à½ê»ý¥¹¥í¥Ã¥È
+ * @param num Áý¤ä¤·¤¿¤¤ÎÌ
+ * @return ¤Ê¤·
  */
 void inven_item_increase(int item, int num)
 {
@@ -5482,9 +5960,11 @@ void inven_item_increase(int item, int num)
        }
 }
 
-
-/*
+/*!
+ * @brief ½ê»ý¥¢¥¤¥Æ¥à¥¹¥í¥Ã¥È¤«¤é½ê»ý¿ô¤Î¤Ê¤¯¤Ê¤Ã¤¿¥¢¥¤¥Æ¥à¤ò¾Ãµî¤¹¤ë /
  * Erase an inventory slot if it has no more items
+ * @param item ¾Ãµî¤·¤¿¤¤¥×¥ì¥¤¥ä¡¼¤Î¥¢¥¤¥Æ¥à½ê»ý¥¹¥í¥Ã¥È
+ * @return ¤Ê¤·
  */
 void inven_item_optimize(int item)
 {
@@ -5544,9 +6024,11 @@ void inven_item_optimize(int item)
        p_ptr->window |= (PW_SPELL);
 }
 
-
-/*
+/*!
+ * @brief ¾²¾å¤ÎËâÆ»¶ñ¤Î»Ä¤ê»ÄÎÌ¥á¥Ã¥»¡¼¥¸¤òɽ¼¨¤¹¤ë /
  * Describe the charges on an item on the floor.
+ * @param item ¥á¥Ã¥»¡¼¥¸¤ÎÂоݤˤ·¤¿¤¤¥¢¥¤¥Æ¥à½ê»ý¥¹¥í¥Ã¥È
+ * @return ¤Ê¤·
  */
 void floor_item_charges(int item)
 {
@@ -5556,7 +6038,7 @@ void floor_item_charges(int item)
        if ((o_ptr->tval != TV_STAFF) && (o_ptr->tval != TV_WAND)) return;
 
        /* Require known item */
-       if (!object_known_p(o_ptr)) return;
+       if (!object_is_known(o_ptr)) return;
 
 #ifdef JP
        if (o_ptr->pval <= 0)
@@ -5585,9 +6067,11 @@ void floor_item_charges(int item)
 
 }
 
-
-/*
- * Describe an item in the inventory.
+/*!
+ * @brief ¾²¾å¤Î¥¢¥¤¥Æ¥à¤Î»Ä¤ê¿ô¥á¥Ã¥»¡¼¥¸¤òɽ¼¨¤¹¤ë /
+ * Describe the charges on an item on the floor.
+ * @param item ¥á¥Ã¥»¡¼¥¸¤ÎÂоݤˤ·¤¿¤¤¥¢¥¤¥Æ¥à½ê»ý¥¹¥í¥Ã¥È
+ * @return ¤Ê¤·
  */
 void floor_item_describe(int item)
 {
@@ -5615,8 +6099,12 @@ void floor_item_describe(int item)
 }
 
 
-/*
+/*!
+ * @brief ¾²¾å¤Î¥¢¥¤¥Æ¥à¤Î¿ô¤òÁý¤ä¤¹ /
  * Increase the "number" of an item on the floor
+ * @param item Áý¤ä¤·¤¿¤¤¥¢¥¤¥Æ¥à¤Î½ê»ý¥¹¥í¥Ã¥È
+ * @param num Áý¤ä¤·¤¿¤¤¥¢¥¤¥Æ¥à¤Î¿ô
+ * @return ¤Ê¤·
  */
 void floor_item_increase(int item, int num)
 {
@@ -5637,8 +6125,11 @@ void floor_item_increase(int item, int num)
 }
 
 
-/*
+/*!
+ * @brief ¾²¾å¤Î¿ô¤Î̵¤¯¤Ê¤Ã¤¿¥¢¥¤¥Æ¥à¥¹¥í¥Ã¥È¤ò¾Ãµî¤¹¤ë /
  * Optimize an item on the floor (destroy "empty" items)
+ * @param item ¾Ãµî¤·¤¿¤¤¥¢¥¤¥Æ¥à¤Î½ê»ý¥¹¥í¥Ã¥È
+ * @return ¤Ê¤·
  */
 void floor_item_optimize(int item)
 {
@@ -5655,8 +6146,11 @@ void floor_item_optimize(int item)
 }
 
 
-/*
+/*!
+ * @brief ¥¢¥¤¥Æ¥à¤ò½¦¤¦ºÝ¤Ë¥¶¥Ã¥¯¤«¤é°î¤ì¤º¤ËºÑ¤à¤«¤òȽÄꤹ¤ë /
  * Check if we have space for an item in the pack without overflow
+ * @param o_ptr ½¦¤¤¤¿¤¤¥ª¥Ö¥¸¥§¥¯¥È¤Î¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿
+ * @return °î¤ì¤º¤ËºÑ¤à¤Ê¤éTRUE¤òÊÖ¤¹
  */
 bool inven_carry_okay(object_type *o_ptr)
 {
@@ -5681,23 +6175,114 @@ bool inven_carry_okay(object_type *o_ptr)
        return (FALSE);
 }
 
+/*!
+ * @brief ¥ª¥Ö¥¸¥§¥¯¥È¤òÄêµÁ¤µ¤ì¤¿´ð½à¤Ë½¾¤¤¥½¡¼¥È¤¹¤ë¤¿¤á¤Î´Ø¿ô /
+ * Check if we have space for an item in the pack without overflow
+ * @param o_ptr Èæ³ÓÂоݥª¥Ö¥¸¥§¥¯¥È¤Î¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿1
+ * @param o_value o_ptr¤Î¥¢¥¤¥Æ¥à²ÁÃ͡ʼêÆ°¤Ç¤¢¤é¤«¤¸¤áÂåÆþ¤¹¤ëɬÍפ¬¤¢¤ë¡©¡Ë
+ * @param j_ptr Èæ³ÓÂоݥª¥Ö¥¸¥§¥¯¥È¤Î¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿2
+ * @return o_ptr¤ÎÊý¤¬¾å°Ì¤Ê¤é¤ÐTRUE¤òÊÖ¤¹¡£
+ */
+bool object_sort_comp(object_type *o_ptr, s32b o_value, object_type *j_ptr)
+{
+       int o_type, j_type;
+
+       /* Use empty slots */
+       if (!j_ptr->k_idx) return TRUE;
+
+       /* Hack -- readable books always come first */
+       if ((o_ptr->tval == REALM1_BOOK) &&
+           (j_ptr->tval != REALM1_BOOK)) return TRUE;
+       if ((j_ptr->tval == REALM1_BOOK) &&
+           (o_ptr->tval != REALM1_BOOK)) return FALSE;
+
+       if ((o_ptr->tval == REALM2_BOOK) &&
+           (j_ptr->tval != REALM2_BOOK)) return TRUE;
+       if ((j_ptr->tval == REALM2_BOOK) &&
+           (o_ptr->tval != REALM2_BOOK)) return FALSE;
+
+       /* Objects sort by decreasing type */
+       if (o_ptr->tval > j_ptr->tval) return TRUE;
+       if (o_ptr->tval < j_ptr->tval) return FALSE;
+
+       /* Non-aware (flavored) items always come last */
+       /* Can happen in the home */
+       if (!object_is_aware(o_ptr)) return FALSE;
+       if (!object_is_aware(j_ptr)) return TRUE;
+
+       /* Objects sort by increasing sval */
+       if (o_ptr->sval < j_ptr->sval) return TRUE;
+       if (o_ptr->sval > j_ptr->sval) return FALSE;
+
+       /* Unidentified objects always come last */
+       /* Objects in the home can be unknown */
+       if (!object_is_known(o_ptr)) return FALSE;
+       if (!object_is_known(j_ptr)) return TRUE;
+
+       /* Fixed artifacts, random artifacts and ego items */
+       if (object_is_fixed_artifact(o_ptr)) o_type = 3;
+       else if (o_ptr->art_name) o_type = 2;
+       else if (object_is_ego(o_ptr)) o_type = 1;
+       else o_type = 0;
+
+       if (object_is_fixed_artifact(j_ptr)) j_type = 3;
+       else if (j_ptr->art_name) j_type = 2;
+       else if (object_is_ego(j_ptr)) j_type = 1;
+       else j_type = 0;
+
+       if (o_type < j_type) return TRUE;
+       if (o_type > j_type) return FALSE;
 
-/*
+       switch (o_ptr->tval)
+       {
+       case TV_FIGURINE:
+       case TV_STATUE:
+       case TV_CORPSE:
+       case TV_CAPTURE:
+               if (r_info[o_ptr->pval].level < r_info[j_ptr->pval].level) return TRUE;
+               if ((r_info[o_ptr->pval].level == r_info[j_ptr->pval].level) && (o_ptr->pval < j_ptr->pval)) return TRUE;
+               return FALSE;
+
+       case TV_SHOT:
+       case TV_ARROW:
+       case TV_BOLT:
+               /* Objects sort by increasing hit/damage bonuses */
+               if (o_ptr->to_h + o_ptr->to_d < j_ptr->to_h + j_ptr->to_d) return TRUE;
+               if (o_ptr->to_h + o_ptr->to_d > j_ptr->to_h + j_ptr->to_d) return FALSE;
+               break;
+
+       /* Hack:  otherwise identical rods sort by
+       increasing recharge time --dsb */
+       case TV_ROD:
+               if (o_ptr->pval < j_ptr->pval) return TRUE;
+               if (o_ptr->pval > j_ptr->pval) return FALSE;
+               break;
+       }
+
+       /* Objects sort by decreasing value */
+       return o_value > object_value(j_ptr);
+}
+
+
+/*!
+ * @brief ¥ª¥Ö¥¸¥§¥¯¥È¤ò¥×¥ì¥¤¥ä¡¼¤¬½¦¤Ã¤Æ½ê»ý¥¹¥í¥Ã¥È¤ËǼ¤á¤ë¥á¥¤¥ó¥ë¡¼¥Á¥ó /
  * Add an item to the players inventory, and return the slot used.
- *
- * If the new item can combine with an existing item in the inventory,
- * it will do so, using "object_similar()" and "object_absorb()", else,
- * the item will be placed into the "proper" location in the inventory.
- *
- * This function can be used to "over-fill" the player's pack, but only
- * once, and such an action must trigger the "overflow" code immediately.
- * Note that when the pack is being "over-filled", the new item must be
- * placed into the "overflow" slot, and the "overflow" must take place
- * before the pack is reordered, but (optionally) after the pack is
- * combined.  This may be tricky.  See "dungeon.c" for info.
- *
- * Note that this code must remove any location/stack information
- * from the object once it is placed into the inventory.
+ * @param o_ptr ½¦¤¦¥ª¥Ö¥¸¥§¥¯¥È¤Î¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿
+ * @return ¼ý¤á¤é¤ì¤¿½ê»ý¥¹¥í¥Ã¥È¤ÎID¡¢½¦¤¦¤³¤È¤¬¤Ç¤­¤Ê¤«¤Ã¤¿¾ì¹ç-1¤òÊÖ¤¹¡£
+ * @details
+ * If the new item can combine with an existing item in the inventory,\n
+ * it will do so, using "object_similar()" and "object_absorb()", else,\n
+ * the item will be placed into the "proper" location in the inventory.\n
+ *\n
+ * This function can be used to "over-fill" the player's pack, but only\n
+ * once, and such an action must trigger the "overflow" code immediately.\n
+ * Note that when the pack is being "over-filled", the new item must be\n
+ * placed into the "overflow" slot, and the "overflow" must take place\n
+ * before the pack is reordered, but (optionally) after the pack is\n
+ * combined.  This may be tricky.  See "dungeon.c" for info.\n
+ *\n
+ * Note that this code must remove any location/stack information\n
+ * from the object once it is placed into the inventory.\n
  */
 s16b inven_carry(object_type *o_ptr)
 {
@@ -5758,60 +6343,13 @@ s16b inven_carry(object_type *o_ptr)
        /* Reorder the pack */
        if (i < INVEN_PACK)
        {
-               s32b o_value, j_value;
-
                /* Get the "value" of the item */
-               o_value = object_value(o_ptr);
+               s32b o_value = object_value(o_ptr);
 
                /* Scan every occupied slot */
                for (j = 0; j < INVEN_PACK; j++)
                {
-                       j_ptr = &inventory[j];
-
-                       /* Use empty slots */
-                       if (!j_ptr->k_idx) break;
-
-                       /* Hack -- readable books always come first */
-                       if ((o_ptr->tval == REALM1_BOOK) &&
-                           (j_ptr->tval != REALM1_BOOK)) break;
-                       if ((j_ptr->tval == REALM1_BOOK) &&
-                           (o_ptr->tval != REALM1_BOOK)) continue;
-
-                       if ((o_ptr->tval == REALM2_BOOK) &&
-                           (j_ptr->tval != REALM2_BOOK)) break;
-                       if ((j_ptr->tval == REALM2_BOOK) &&
-                           (o_ptr->tval != REALM2_BOOK)) continue;
-
-                       /* Objects sort by decreasing type */
-                       if (o_ptr->tval > j_ptr->tval) break;
-                       if (o_ptr->tval < j_ptr->tval) continue;
-
-                       /* Non-aware (flavored) items always come last */
-                       if (!object_aware_p(o_ptr)) continue;
-                       if (!object_aware_p(j_ptr)) break;
-
-                       /* Objects sort by increasing sval */
-                       if (o_ptr->sval < j_ptr->sval) break;
-                       if (o_ptr->sval > j_ptr->sval) continue;
-
-                       /* Unidentified objects always come last */
-                       if (!object_known_p(o_ptr)) continue;
-                       if (!object_known_p(j_ptr)) break;
-
-                       /* Hack:  otherwise identical rods sort by
-                       increasing recharge time --dsb */
-                       if (o_ptr->tval == TV_ROD)
-                       {
-                               if (o_ptr->pval < j_ptr->pval) break;
-                               if (o_ptr->pval > j_ptr->pval) continue;
-                       }
-
-                       /* Determine the "value" of the pack item */
-                       j_value = object_value(j_ptr);
-
-                       /* Objects sort by decreasing value */
-                       if (o_value > j_value) break;
-                       if (o_value < j_value) continue;
+                       if (object_sort_comp(o_ptr, o_value, &inventory[j])) break;
                }
 
                /* Use that slot */
@@ -5844,8 +6382,8 @@ s16b inven_carry(object_type *o_ptr)
        /* Forget location */
        j_ptr->iy = j_ptr->ix = 0;
 
-       /* No longer marked */
-       j_ptr->marked = 0;
+       /* Player touches it, and no longer marked */
+       j_ptr->marked = OM_TOUCHED;
 
        /* Increase the weight */
        p_ptr->total_weight += (j_ptr->number * j_ptr->weight);
@@ -5867,15 +6405,17 @@ s16b inven_carry(object_type *o_ptr)
 }
 
 
-/*
+/*!
+ * @brief ÁõÈ÷¥¹¥í¥Ã¥È¤«¤é¥ª¥Ö¥¸¥§¥¯¥È¤ò³°¤¹¥á¥¤¥ó¥ë¡¼¥Á¥ó /
  * Take off (some of) a non-cursed equipment item
- *
- * Note that only one item at a time can be wielded per slot.
- *
- * Note that taking off an item when "full" may cause that item
- * to fall to the ground.
- *
- * Return the inventory slot into which the item is placed.
+ * @param item ¥ª¥Ö¥¸¥§¥¯¥È¤ò³°¤·¤¿¤¤½ê»ý¥Æ¡¼¥Ö¥ë¤ÎID
+ * @param amt ³°¤·¤¿¤¤¸Ä¿ô
+ * @return ¼ý¤á¤é¤ì¤¿½ê»ý¥¹¥í¥Ã¥È¤ÎID¡¢½¦¤¦¤³¤È¤¬¤Ç¤­¤Ê¤«¤Ã¤¿¾ì¹ç-1¤òÊÖ¤¹¡£
+ * @details
+ * Note that only one item at a time can be wielded per slot.\n
+ * Note that taking off an item when "full" may cause that item\n
+ * to fall to the ground.\n
+ * Return the inventory slot into which the item is placed.\n
  */
 s16b inven_takeoff(int item, int amt)
 {
@@ -5913,7 +6453,8 @@ s16b inven_takeoff(int item, int amt)
        object_desc(o_name, q_ptr, 0);
 
        /* Took off weapon */
-       if (item == INVEN_RARM)
+       if (((item == INVEN_RARM) || (item == INVEN_LARM)) &&
+           object_is_melee_weapon(o_ptr))
        {
 #ifdef JP
                act = "¤òÁõÈ÷¤«¤é¤Ï¤º¤·¤¿";
@@ -5976,9 +6517,13 @@ s16b inven_takeoff(int item, int amt)
 }
 
 
-/*
+/*!
+ * @brief ½ê»ý¥¹¥í¥Ã¥È¤«¤é¾²²¼¤Ë¥ª¥Ö¥¸¥§¥¯¥È¤òÍî¤È¤¹¥á¥¤¥ó¥ë¡¼¥Á¥ó /
  * Drop (some of) a non-cursed inventory/equipment item
- *
+ * @param item ½ê»ý¥Æ¡¼¥Ö¥ë¤ÎID
+ * @param amt Íî¤È¤·¤¿¤¤¸Ä¿ô
+ * @return ¤Ê¤·
+ * @details
  * The object will be dropped "near" the current location
  */
 void inven_drop(int item, int amt)
@@ -6045,9 +6590,11 @@ void inven_drop(int item, int amt)
 }
 
 
-/*
+/*!
+ * @brief ¥×¥ì¥¤¥ä¡¼¤Î½ê»ý¥¹¥í¥Ã¥È¤Ë¸ºß¤¹¤ë¥ª¥Ö¥¸¥§¥¯¥È¤ò¤Þ¤È¤á¤Ê¤ª¤¹ /
  * Combine items in the pack
- *
+ * @return ¤Ê¤·
+ * @details
  * Note special handling of the "overflow" slot
  */
 void combine_pack(void)
@@ -6055,93 +6602,101 @@ void combine_pack(void)
        int             i, j, k;
        object_type     *o_ptr;
        object_type     *j_ptr;
-       bool            flag = FALSE;
-
+       bool            flag = FALSE, combined;
 
-       /* Combine the pack (backwards) */
-       for (i = INVEN_PACK; i > 0; i--)
+       do
        {
-               /* Get the item */
-               o_ptr = &inventory[i];
-
-               /* Skip empty items */
-               if (!o_ptr->k_idx) continue;
+               combined = FALSE;
 
-               /* Scan the items above that item */
-               for (j = 0; j < i; j++)
+               /* Combine the pack (backwards) */
+               for (i = INVEN_PACK; i > 0; i--)
                {
-                       int max_num;
-
                        /* Get the item */
-                       j_ptr = &inventory[j];
+                       o_ptr = &inventory[i];
 
                        /* Skip empty items */
-                       if (!j_ptr->k_idx) continue;
-
-                       /*
-                        * Get maximum number of the stack if these
-                        * are similar, get zero otherwise.
-                        */
-                       max_num = object_similar_part(j_ptr, o_ptr);
+                       if (!o_ptr->k_idx) continue;
 
-                       /* Can we (partialy) drop "o_ptr" onto "j_ptr"? */
-                       if (max_num && j_ptr->number < max_num)
+                       /* Scan the items above that item */
+                       for (j = 0; j < i; j++)
                        {
-                               if (o_ptr->number + j_ptr->number <= max_num)
-                               {
-                                       /* Take note */
-                                       flag = TRUE;
+                               int max_num;
+
+                               /* Get the item */
+                               j_ptr = &inventory[j];
 
-                                       /* Add together the item counts */
-                                       object_absorb(j_ptr, o_ptr);
+                               /* Skip empty items */
+                               if (!j_ptr->k_idx) continue;
 
-                                       /* One object is gone */
-                                       inven_cnt--;
+                               /*
+                                * Get maximum number of the stack if these
+                                * are similar, get zero otherwise.
+                                */
+                               max_num = object_similar_part(j_ptr, o_ptr);
 
-                                       /* Slide everything down */
-                                       for (k = i; k < INVEN_PACK; k++)
+                               /* Can we (partialy) drop "o_ptr" onto "j_ptr"? */
+                               if (max_num && j_ptr->number < max_num)
+                               {
+                                       if (o_ptr->number + j_ptr->number <= max_num)
                                        {
-                                               /* Structure copy */
-                                               inventory[k] = inventory[k+1];
+                                               /* Take note */
+                                               flag = TRUE;
+
+                                               /* Add together the item counts */
+                                               object_absorb(j_ptr, o_ptr);
+
+                                               /* One object is gone */
+                                               inven_cnt--;
+
+                                               /* Slide everything down */
+                                               for (k = i; k < INVEN_PACK; k++)
+                                               {
+                                                       /* Structure copy */
+                                                       inventory[k] = inventory[k+1];
+                                               }
+
+                                               /* Erase the "final" slot */
+                                               object_wipe(&inventory[k]);
                                        }
-                                       
-                                       /* Erase the "final" slot */
-                                       object_wipe(&inventory[k]);
-                               }
-                               else
-                               {
-                                       int old_num = o_ptr->number;
-                                       int remain = j_ptr->number + o_ptr->number - max_num;
+                                       else
+                                       {
+                                               int old_num = o_ptr->number;
+                                               int remain = j_ptr->number + o_ptr->number - max_num;
 #if 0
-                                       o_ptr->number -= remain;
+                                               o_ptr->number -= remain;
 #endif
-                                       /* Add together the item counts */
-                                       object_absorb(j_ptr, o_ptr);
+                                               /* Add together the item counts */
+                                               object_absorb(j_ptr, o_ptr);
 
-                                       o_ptr->number = remain;
+                                               o_ptr->number = remain;
 
-                                       /* Hack -- if rods are stacking, add the pvals (maximum timeouts) and current timeouts together. -LM- */
-                                       if (o_ptr->tval == TV_ROD)
-                                       {
-                                               o_ptr->pval =  o_ptr->pval * remain / old_num;
-                                               o_ptr->timeout = o_ptr->timeout * remain / old_num;
-                                       }
+                                               /* Hack -- if rods are stacking, add the pvals (maximum timeouts) and current timeouts together. -LM- */
+                                               if (o_ptr->tval == TV_ROD)
+                                               {
+                                                       o_ptr->pval =  o_ptr->pval * remain / old_num;
+                                                       o_ptr->timeout = o_ptr->timeout * remain / old_num;
+                                               }
 
-                                       /* Hack -- if wands are stacking, combine the charges. -LM- */
-                                       if (o_ptr->tval == TV_WAND)
-                                       {
-                                               o_ptr->pval = o_ptr->pval * remain / old_num;
+                                               /* Hack -- if wands are stacking, combine the charges. -LM- */
+                                               if (o_ptr->tval == TV_WAND)
+                                               {
+                                                       o_ptr->pval = o_ptr->pval * remain / old_num;
+                                               }
                                        }
-                               }
 
-                               /* Window stuff */
-                               p_ptr->window |= (PW_INVEN);
-                               
-                               /* Done */
-                               break;
+                                       /* Window stuff */
+                                       p_ptr->window |= (PW_INVEN);
+
+                                       /* Take note */
+                                       combined = TRUE;
+
+                                       /* Done */
+                                       break;
+                               }
                        }
                }
        }
+       while (combined);
 
        /* Message */
 #ifdef JP
@@ -6151,20 +6706,19 @@ void combine_pack(void)
 #endif
 }
 
-
-/*
+/*!
+ * @brief ¥×¥ì¥¤¥ä¡¼¤Î½ê»ý¥¹¥í¥Ã¥È¤Ë¸ºß¤¹¤ë¥ª¥Ö¥¸¥§¥¯¥È¤òʤÓÂؤ¨¤ë /
  * Reorder items in the pack
- *
+ * @return ¤Ê¤·
+ * @details
  * Note special handling of the "overflow" slot
  */
 void reorder_pack(void)
 {
        int             i, j, k;
        s32b            o_value;
-       s32b            j_value;
        object_type     forge;
        object_type     *q_ptr;
-       object_type     *j_ptr;
        object_type     *o_ptr;
        bool            flag = FALSE;
 
@@ -6187,55 +6741,7 @@ void reorder_pack(void)
                /* Scan every occupied slot */
                for (j = 0; j < INVEN_PACK; j++)
                {
-                       /* Get the item already there */
-                       j_ptr = &inventory[j];
-
-                       /* Use empty slots */
-                       if (!j_ptr->k_idx) break;
-
-                       /* Hack -- readable books always come first */
-                       if ((o_ptr->tval == REALM1_BOOK) &&
-                           (j_ptr->tval != REALM1_BOOK)) break;
-                       if ((j_ptr->tval == REALM1_BOOK) &&
-                           (o_ptr->tval != REALM1_BOOK)) continue;
-
-                       if ((o_ptr->tval == REALM2_BOOK) &&
-                           (j_ptr->tval != REALM2_BOOK)) break;
-                       if ((j_ptr->tval == REALM2_BOOK) &&
-                           (o_ptr->tval != REALM2_BOOK)) continue;
-
-                       /* Objects sort by decreasing type */
-                       if (o_ptr->tval > j_ptr->tval) break;
-                       if (o_ptr->tval < j_ptr->tval) continue;
-
-                       /* Non-aware (flavored) items always come last */
-                       if (!object_aware_p(o_ptr)) continue;
-                       if (!object_aware_p(j_ptr)) break;
-
-                       /* Objects sort by increasing sval */
-                       if (o_ptr->sval < j_ptr->sval) break;
-                       if (o_ptr->sval > j_ptr->sval) continue;
-
-                       /* Unidentified objects always come last */
-                       if (!object_known_p(o_ptr)) continue;
-                       if (!object_known_p(j_ptr)) break;
-
-                       /* Hack:  otherwise identical rods sort by
-                       increasing recharge time --dsb */
-                       if (o_ptr->tval == TV_ROD)
-                       {
-                               if (o_ptr->pval < j_ptr->pval) break;
-                               if (o_ptr->pval > j_ptr->pval) continue;
-                       }
-
-                       /* Determine the "value" of the pack item */
-                       j_value = object_value(j_ptr);
-
-
-
-                       /* Objects sort by decreasing value */
-                       if (o_value > j_value) break;
-                       if (o_value < j_value) continue;
+                       if (object_sort_comp(o_ptr, o_value, &inventory[j])) break;
                }
 
                /* Never move down */
@@ -6273,10 +6779,12 @@ void reorder_pack(void)
 
 }
 
-
-/*
+/*!
+ * @brief ¸½ºß¥¢¥¯¥Æ¥£¥Ö¤Ë¤Ê¤Ã¤Æ¤¤¤ë¥¦¥£¥ó¥É¥¦¤Ë¥ª¥Ö¥¸¥§¥¯¥È¤Î¾ÜºÙ¤òɽ¼¨¤¹¤ë /
  * Hack -- display an object kind in the current window
- *
+ * @param k_idx ¥Ù¡¼¥¹¥¢¥¤¥Æ¥à¤Î»²¾ÈID
+ * @return ¤Ê¤·
+ * @details
  * Include list of usable spells for readible books
  */
 void display_koff(int k_idx)
@@ -6351,7 +6859,12 @@ void display_koff(int k_idx)
        }
 }
 
-/* Choose one of items that have warning flag */
+/*!
+ * @brief ·Ù¹ð¤òÊü¤Ä¥¢¥¤¥Æ¥à¤òÁªÂò¤¹¤ë /
+ * Choose one of items that have warning flag
+ * Calculate spell damages
+ * @return ·Ù¹ð¤ò¹Ô¤¦
+ */
 object_type *choose_warning_item(void)
 {
        int i;
@@ -6379,7 +6892,16 @@ object_type *choose_warning_item(void)
        return number ? &inventory[choices[randint0(number)]] : NULL;
 }
 
-/* Calculate spell damages */
+/*!
+ * @brief ·Ù¹ð´ð½à¤òÄê¤á¤ë¤¿¤á¤ËËâË¡¤Î¸ú²Ì°À­¤Ë´ð¤Å¤¤¤ÆºÇÂçËâË¡¥À¥á¡¼¥¸¤ò·×»»¤¹¤ë /
+ * Calculate spell damages
+ * @param m_ptr ËâË¡¤ò¹Ô»È¤¹¤ë¥â¥ó¥¹¥¿¡¼¤Î¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿
+ * @param typ ¸ú²Ì°À­¤ÎID
+ * @param dam ´ðËÜ¥À¥á¡¼¥¸
+ * @param limit ¥À¥á¡¼¥¸¤Î¸Â³¦ÃÍ
+ * @param max »»½Ð¤·¤¿ºÇÂç¥À¥á¡¼¥¸¤òÊÖ¤¹¥Ý¥¤¥ó¥¿
+ * @return ¤Ê¤·
+ */
 static void spell_damcalc(monster_type *m_ptr, int typ, int dam, int limit, int *max)
 {
        monster_race *r_ptr = &r_info[m_ptr->r_idx];
@@ -6533,7 +7055,7 @@ static void spell_damcalc(monster_type *m_ptr, int typ, int dam, int limit, int
                break;
 
        case GF_GRAVITY:
-               if (p_ptr->ffall) dam = (dam * 2) / 3;
+               if (p_ptr->levitation) dam = (dam * 2) / 3;
                break;
 
        case GF_ROCKET:
@@ -6618,7 +7140,13 @@ static void spell_damcalc(monster_type *m_ptr, int typ, int dam, int limit, int
        if (dam > *max) *max = dam;
 }
 
-/* Calculate blow damages */
+/*!
+ * @brief ·Ù¹ð´ð½à¤òÄê¤á¤ë¤¿¤á¤Ë¥â¥ó¥¹¥¿¡¼¤ÎÂÇ·âºÇÂç¥À¥á¡¼¥¸¤ò»»½Ð¤¹¤ë /
+ * Calculate blow damages
+ * @param m_ptr ÂÇ·â¤ò¹Ô»È¤¹¤ë¥â¥ó¥¹¥¿¡¼¤Î¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿
+ * @param blow_ptr ¥â¥ó¥¹¥¿¡¼¤ÎÂÇ·âǽÎϤι½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿
+ * @return »»½Ð¤µ¤ì¤¿ºÇÂç¥À¥á¡¼¥¸¤òÊÖ¤¹¡£
+ */
 static int blow_damcalc(monster_type *m_ptr, monster_blow *blow_ptr)
 {
        int  dam = blow_ptr->d_dice * blow_ptr->d_side;
@@ -6689,7 +7217,13 @@ static int blow_damcalc(monster_type *m_ptr, monster_blow *blow_ptr)
        return dam;
 }
 
-/* Examine the grid (xx,yy) and warn the player if there are any danger */
+/*!
+ * @brief ¥×¥ì¥¤¥ä¡¼¤¬ÆÃÄêÃÏÅÀ¤Ø°ÜÆ°¤·¤¿¾ì¹ç¤Ë·Ù¹ð¤òȯ¤¹¤ë½èÍý /
+ * Examine the grid (xx,yy) and warn the player if there are any danger
+ * @param xx ´í¸±À­¤òÄ´ºº¤¹¤ë¥Þ¥¹¤ÎXºÂɸ
+ * @param yy ´í¸±À­¤òÄ´ºº¤¹¤ë¥Þ¥¹¤ÎYºÂɸ
+ * @return ·Ù¹ð¤ò̵»ë¤·¤Æ¿Ê¤à¤³¤È¤òÁªÂò¤¹¤ë¤«¤«ÌäÂ̵꤬¤±¤ì¤ÐTRUE¡¢·Ù¹ð¤Ë½¾¤Ã¤¿¤Ê¤éFALSE¤òÊÖ¤¹¡£
+ */
 bool process_warning(int xx, int yy)
 {
        int mx, my;
@@ -6716,7 +7250,7 @@ bool process_warning(int xx, int yy)
 
                        m_ptr = &m_list[c_ptr->m_idx];
 
-                       if (m_ptr->csleep) continue;
+                       if (MON_CSLEEP(m_ptr)) continue;
                        if (!is_hostile(m_ptr)) continue;
 
                        r_ptr = &r_info[m_ptr->r_idx];
@@ -6810,7 +7344,7 @@ bool process_warning(int xx, int yy)
                        else strcpy(o_name, "body"); /* Warning ability without item */
                        msg_format("Your %s pulsates sharply!", o_name);
 #endif
-                       disturb(0, 0);
+                       disturb(0, 1);
 #ifdef JP
                        return get_check("ËÜÅö¤Ë¤³¤Î¤Þ¤Þ¿Ê¤à¤«¡©");
 #else
@@ -6834,7 +7368,7 @@ bool process_warning(int xx, int yy)
                else strcpy(o_name, "body"); /* Warning ability without item */
                msg_format("Your %s pulsates!", o_name);
 #endif
-               disturb(0, 0);
+               disturb(0, 1);
 #ifdef JP
                return get_check("ËÜÅö¤Ë¤³¤Î¤Þ¤Þ¿Ê¤à¤«¡©");
 #else
@@ -6845,7 +7379,11 @@ bool process_warning(int xx, int yy)
        return TRUE;
 }
 
-
+/*!
+ * @brief ¥¨¥Ã¥»¥ó¥¹¤ÎÉղòÄǽ¤ÊÉð´ï¤äÌðÃƤ«¤òÊÖ¤¹
+ * @param o_ptr ¥Á¥§¥Ã¥¯¤·¤¿¤¤¥ª¥Ö¥¸¥§¥¯¥È¤Î¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿
+ * @return ¥¨¥Ã¥»¥ó¥¹¤ÎÉղòÄǽ¤ÊÉð´ï¤«ÌðÃƤʤé¤ÐTRUE¤òÊÖ¤¹¡£
+ */
 static bool item_tester_hook_melee_ammo(object_type *o_ptr)
 {
        switch (o_ptr->tval)
@@ -6869,8 +7407,8 @@ static bool item_tester_hook_melee_ammo(object_type *o_ptr)
 }
 
 
-/*
- *  A structure for smithing
+/*!
+ * ¥¨¥Ã¥»¥ó¥¹¾ðÊó¤Î¹½Â¤ÂΠ/ A structure for smithing
  */
 typedef struct {
        int add;       /* TR flag number or special essence id */
@@ -6881,8 +7419,8 @@ typedef struct {
 } essence_type;
 
 
-/*
- *  Smithing type data for Weapon smith
+/*!
+ * ¥¨¥Ã¥»¥ó¥¹¾ðÊó¥Æ¡¼¥Ö¥ë Smithing type data for Weapon smith
  */
 #ifdef JP
 static essence_type essence_info[] = 
@@ -6920,7 +7458,7 @@ static essence_type essence_info[] =
        {TR_IM_COLD, "Î䵤ÌȱÖ", 2, TR_IM_ACID, 20},
        {TR_REFLECT, "È¿¼Í", 2, TR_REFLECT, 20},
        {TR_FREE_ACT, "ËãáãÃΤ餺", 3, TR_FREE_ACT, 20},
-       {TR_HOLD_LIFE, "À¸Ì¿ÎÏ°Ý»ý", 3, TR_HOLD_LIFE, 20},
+       {TR_HOLD_EXP, "·Ð¸³ÃÍ°Ý»ý", 3, TR_HOLD_EXP, 20},
        {TR_RES_ACID, "ÂÑ»À", 2, TR_RES_ACID, 15},
        {TR_RES_ELEC, "ÂÑÅÅ·â", 2, TR_RES_ELEC, 15},
        {TR_RES_FIRE, "ÂѲбê", 2, TR_RES_FIRE, 15},
@@ -6942,8 +7480,10 @@ static essence_type essence_info[] =
        {TR_SH_COLD, "", 0, -2, 0},
        {TR_NO_MAGIC, "È¿ËâË¡", 3, TR_NO_MAGIC, 15},
        {TR_WARNING, "·Ù¹ð", 3, TR_WARNING, 20},
-       {TR_FEATHER, "ÉâÍ·", 3, TR_FEATHER, 20},
-       {TR_LITE, "±Êµ×¸÷¸»", 3, TR_LITE, 15},
+       {TR_LEVITATION, "ÉâÍ·", 3, TR_LEVITATION, 20},
+       {TR_LITE_1, "±Êµ×¸÷¸»", 3, TR_LITE_1, 15},
+       {TR_LITE_2, "", 0, -2, 0},
+       {TR_LITE_3, "", 0, -2, 0},
        {TR_SEE_INVIS, "²Ä»ëÆ©ÌÀ", 3, TR_SEE_INVIS, 20},
        {TR_TELEPATHY, "¥Æ¥ì¥Ñ¥·¡¼", 6, TR_TELEPATHY, 15},
        {TR_SLOW_DIGEST, "Ãپò½", 3, TR_SLOW_DIGEST, 15},
@@ -7005,7 +7545,7 @@ static essence_type essence_info[] =
        {TR_MAGIC_MASTERY, "magic mastery", 4, TR_MAGIC_MASTERY, 20},
        {TR_STEALTH, "stealth", 4, TR_STEALTH, 40},
        {TR_SEARCH, "serching", 4, TR_SEARCH, 15},
-       {TR_INFRA, "inflavision", 4, TR_INFRA, 15},
+       {TR_INFRA, "infravision", 4, TR_INFRA, 15},
        {TR_TUNNEL, "digging", 4, TR_TUNNEL, 15},
        {TR_SPEED, "speed", 4, TR_SPEED, 12},
        {TR_BLOWS, "extra attack", 1, TR_BLOWS, 20},
@@ -7029,7 +7569,7 @@ static essence_type essence_info[] =
        {TR_IM_COLD, "cold immunity", 2, TR_IM_ACID, 20},
        {TR_REFLECT, "reflection", 2, TR_REFLECT, 20},
        {TR_FREE_ACT, "free action", 3, TR_FREE_ACT, 20},
-       {TR_HOLD_LIFE, "hold life", 3, TR_HOLD_LIFE, 20},
+       {TR_HOLD_EXP, "hold experience", 3, TR_HOLD_EXP, 20},
        {TR_RES_ACID, "resistance to acid", 2, TR_RES_ACID, 15},
        {TR_RES_ELEC, "resistance to electric", 2, TR_RES_ELEC, 15},
        {TR_RES_FIRE, "resistance to fire", 2, TR_RES_FIRE, 15},
@@ -7051,8 +7591,10 @@ static essence_type essence_info[] =
        {TR_SH_COLD, "", 0, -2, 0},
        {TR_NO_MAGIC, "anti magic", 3, TR_NO_MAGIC, 15},
        {TR_WARNING, "warning", 3, TR_WARNING, 20},
-       {TR_FEATHER, "levitation", 3, TR_FEATHER, 20},
-       {TR_LITE, "permanent light", 3, TR_LITE, 15},
+       {TR_LEVITATION, "levitation", 3, TR_LEVITATION, 20},
+       {TR_LITE_1, "permanent light", 3, TR_LITE_1, 15},
+       {TR_LITE_2, "", 0, -2, 0},
+       {TR_LITE_3, "", 0, -2, 0},
        {TR_SEE_INVIS, "see invisible", 3, TR_SEE_INVIS, 20},
        {TR_TELEPATHY, "telepathy", 6, TR_TELEPATHY, 15},
        {TR_SLOW_DIGEST, "slow digestion", 3, TR_SLOW_DIGEST, 15},
@@ -7105,11 +7647,11 @@ static essence_type essence_info[] =
 #endif
 
 
-/*
- *  Essense names for Weapon smith
+/*!
+ * ¥¨¥Ã¥»¥ó¥¹Ì¾¥Æ¡¼¥Ö¥ë / Essense names for Weapon smith
  */
 #ifdef JP
-static cptr essence_name[] = 
+cptr essence_name[] = 
 {
        "ÏÓÎÏ",
        "ÃÎǽ",
@@ -7158,7 +7700,7 @@ static cptr essence_name[] =
        "",
        "È¿¼Í",
        "ËãáãÃΤ餺",
-       "À¸Ì¿ÎÏ°Ý»ý",
+       "·Ð¸³ÃÍ°Ý»ý",
        "ÂÑ»À",
        "ÂÑÅÅ·â",
        "ÂѲбê",
@@ -7224,7 +7766,7 @@ static cptr essence_name[] =
        "",
        "stealth",
        "serching",
-       "inflavision",
+       "infravision",
        "digging",
        "speed",
        "extra atk",
@@ -7261,7 +7803,7 @@ static cptr essence_name[] =
        "",
        "reflection",
        "free action",
-       "hold life",
+       "hold exp",
        "res. acid",
        "res. elec.",
        "res. fire",
@@ -7314,7 +7856,10 @@ static cptr essence_name[] =
 };
 #endif
 
-
+/*!
+ * @brief ½ê»ý¤·¤Æ¤¤¤ë¥¨¥Ã¥»¥ó¥¹°ìÍ÷¤òɽ¼¨¤¹¤ë
+ * @return ¤Ê¤·
+ */
 static void display_essence(void)
 {
        int i, num = 0;
@@ -7345,13 +7890,17 @@ static void display_essence(void)
        return;
 }
 
+/*!
+ * @brief ¥¨¥Ã¥»¥ó¥¹¤ÎÃê½Ð½èÍý
+ * @return ¤Ê¤·
+ */
 static void drain_essence(void)
 {
        int drain_value[sizeof(p_ptr->magic_num1) / sizeof(s32b)];
        int i, item;
        int dec = 4;
        bool observe = FALSE;
-       int old_ds, old_dd, old_to_h, old_to_d, old_ac, old_to_a, old_pval, old_name2;
+       int old_ds, old_dd, old_to_h, old_to_d, old_ac, old_to_a, old_pval, old_name2, old_timeout;
        u32b old_flgs[TR_FLAG_SIZE], new_flgs[TR_FLAG_SIZE];
        object_type *o_ptr;
        cptr            q, s;
@@ -7361,7 +7910,7 @@ static void drain_essence(void)
        for (i = 0; i < sizeof(drain_value) / sizeof(int); i++)
                drain_value[i] = 0;
 
-       item_tester_hook = item_tester_hook_weapon_armour;
+       item_tester_hook = object_is_weapon_armour_ammo;
        item_tester_no_ryoute = TRUE;
 
        /* Get an item */
@@ -7387,7 +7936,8 @@ static void drain_essence(void)
                o_ptr = &o_list[0 - item];
        }
 
-       if (object_known_p(o_ptr) && (o_ptr->name1 || o_ptr->name2 || o_ptr->art_name || o_ptr->xtra3)) {
+       if (object_is_known(o_ptr) && !object_is_nameless(o_ptr))
+       {
                char o_name[MAX_NLEN];
                object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
 #ifdef JP
@@ -7418,12 +7968,27 @@ static void drain_essence(void)
        old_dd = o_ptr->dd;
        old_pval = o_ptr->pval;
        old_name2 = o_ptr->name2;
+       old_timeout = o_ptr->timeout;
        if (o_ptr->curse_flags & (TRC_CURSED | TRC_HEAVY_CURSE | TRC_PERMA_CURSE)) dec--;
+       if (have_flag(old_flgs, TR_ADD_L_CURSE)) dec--;
+       if (have_flag(old_flgs, TR_ADD_H_CURSE)) dec--;
        if (have_flag(old_flgs, TR_AGGRAVATE)) dec--;
        if (have_flag(old_flgs, TR_NO_TELE)) dec--;
        if (have_flag(old_flgs, TR_DRAIN_EXP)) dec--;
+       if (have_flag(old_flgs, TR_DRAIN_HP)) dec--;
+       if (have_flag(old_flgs, TR_DRAIN_MANA)) dec--;
+       if (have_flag(old_flgs, TR_CALL_ANIMAL)) dec--;
+       if (have_flag(old_flgs, TR_CALL_DEMON)) dec--;
+       if (have_flag(old_flgs, TR_CALL_DRAGON)) dec--;
+       if (have_flag(old_flgs, TR_CALL_UNDEAD)) dec--;
+       if (have_flag(old_flgs, TR_COWARDICE)) dec--;
+       if (have_flag(old_flgs, TR_LOW_MELEE)) dec--;
+       if (have_flag(old_flgs, TR_LOW_AC)) dec--;
+       if (have_flag(old_flgs, TR_LOW_MAGIC)) dec--;
+       if (have_flag(old_flgs, TR_FAST_DIGEST)) dec--;
+       if (have_flag(old_flgs, TR_SLOW_REGEN)) dec--;
        if (have_flag(old_flgs, TR_TY_CURSE)) dec--;
-
+       
        iy = o_ptr->iy;
        ix = o_ptr->ix;
        next_o_idx = o_ptr->next_o_idx;
@@ -7438,6 +8003,7 @@ static void drain_essence(void)
        o_ptr->next_o_idx=next_o_idx;
        o_ptr->marked=marked;
        o_ptr->number = number;
+       if (o_ptr->tval == TV_DRAG_ARMOR) o_ptr->timeout = old_timeout;
        if (item >= 0) p_ptr->total_weight += (o_ptr->weight*o_ptr->number - weight*number);
        o_ptr->ident |= (IDENT_MENTAL);
        object_aware(o_ptr);
@@ -7480,6 +8046,14 @@ static void drain_essence(void)
                                drain_value[TR_BRAND_COLD] += 10;
                                drain_value[TR_RES_COLD] += 10;
                        }
+                       else if (es_ptr->add == TR_LITE_2)
+                       {
+                               drain_value[TR_LITE_1] += 20;
+                       }
+                       else if (es_ptr->add == TR_LITE_3)
+                       {
+                               drain_value[TR_LITE_1] += 30;
+                       }
                }
        }
 
@@ -7512,8 +8086,7 @@ static void drain_essence(void)
        {
                drain_value[TR_DEX] += 20;
        }
-       if ((TV_MISSILE_BEGIN <= o_ptr->tval && o_ptr->tval <= TV_MISSILE_END) ||
-           (TV_WEAPON_BEGIN <=  o_ptr->tval && o_ptr->tval <= TV_WEAPON_END))
+       if (object_is_weapon_ammo(o_ptr))
        {
                if (old_ds > o_ptr->ds) drain_value[TR_ES_ATTACK] += (old_ds-o_ptr->ds)*10;
 
@@ -7537,19 +8110,12 @@ static void drain_essence(void)
        }
        if (!observe)
        {
-#ifdef JP
-               msg_print("¥¨¥Ã¥»¥ó¥¹¤ÏÃê½Ð¤Ç¤­¤Þ¤»¤ó¤Ç¤·¤¿¡£");
-#else
-               msg_print("You were not able to extract any essence.");
-#endif
+               msg_print(_("¥¨¥Ã¥»¥ó¥¹¤ÏÃê½Ð¤Ç¤­¤Þ¤»¤ó¤Ç¤·¤¿¡£", "You were not able to extract any essence."));
        }
        else
        {
-#ifdef JP
-               msg_print("Ãê½Ð¤·¤¿¥¨¥Ã¥»¥ó¥¹:");
-#else
-               msg_print("Extracted essences:");
-#endif
+               msg_print(_("Ãê½Ð¤·¤¿¥¨¥Ã¥»¥ó¥¹:", "Extracted essences:"));
+
                for (i = 0; essence_name[i]; i++)
                {
                        if (!essence_name[i][0]) continue;
@@ -7558,10 +8124,13 @@ static void drain_essence(void)
                        p_ptr->magic_num1[i] += drain_value[i];
                        p_ptr->magic_num1[i] = MIN(20000, p_ptr->magic_num1[i]);
                        msg_print(NULL);
-                       msg_format("%s...%d", essence_name[i], drain_value[i]);
+                       msg_format("%s...%d%s", essence_name[i], drain_value[i], _("¡£", ". "));
                }
        }
 
+       /* Apply autodestroy/inscription to the drained item */
+       autopick_alter_item(item, TRUE);
+
        /* Combine the pack */
        p_ptr->notice |= (PN_COMBINE | PN_REORDER);
 
@@ -7569,8 +8138,10 @@ static void drain_essence(void)
        p_ptr->window |= (PW_INVEN);
 }
 
-
-
+/*!
+ * @brief Éղ乤륨¥Ã¥»¥ó¥¹¤ÎÂçÊ̤òÁªÂò¤¹¤ë
+ * @return Áª¤ó¤À¥¨¥Ã¥»¥ó¥¹¤ÎÂçÊÌID
+ */
 static int choose_essence(void)
 {
        int mode = 0;
@@ -7685,6 +8256,11 @@ static int choose_essence(void)
        return mode;
 }
 
+/*!
+ * @brief ¥¨¥Ã¥»¥ó¥¹¤ò¼ÂºÝ¤ËÉղ乤ë
+ * @param mode ¥¨¥Ã¥»¥ó¥¹¤ÎÂçÊÌID
+ * @return ¤Ê¤·
+ */
 static void add_essence(int mode)
 {
        int item, max_num = 0;
@@ -7994,11 +8570,11 @@ static void add_essence(int mode)
        else if (mode == 1 || mode == 5)
                item_tester_hook = item_tester_hook_melee_ammo;
        else if (es_ptr->add == ESSENCE_ATTACK)
-               item_tester_hook = item_tester_hook_weapon;
+               item_tester_hook = object_allow_enchant_weapon;
        else if (es_ptr->add == ESSENCE_AC)
-               item_tester_hook = item_tester_hook_armour;
+               item_tester_hook = object_is_armour;
        else
-               item_tester_hook = item_tester_hook_weapon_armour;
+               item_tester_hook = object_is_weapon_armour_ammo;
        item_tester_no_ryoute = TRUE;
 
        /* Get an item */
@@ -8024,7 +8600,7 @@ static void add_essence(int mode)
                o_ptr = &o_list[0 - item];
        }
 
-       if ((mode != 10) && (o_ptr->name1 || o_ptr->art_name || o_ptr->xtra3))
+       if ((mode != 10) && (object_is_artifact(o_ptr) || object_is_smith(o_ptr)))
        {
 #ifdef JP
                msg_print("¤½¤Î¥¢¥¤¥Æ¥à¤Ï¤³¤ì°Ê¾å²þÎɤǤ­¤Ê¤¤¡£");
@@ -8295,37 +8871,10 @@ static void add_essence(int mode)
        p_ptr->window |= (PW_INVEN);
 }
 
-
-bool item_tester_hook_smith(object_type *o_ptr)
-{
-       switch (o_ptr->tval)
-       {
-               case TV_SWORD:
-               case TV_HAFTED:
-               case TV_POLEARM:
-               case TV_DIGGING:
-               case TV_BOW:
-               case TV_BOLT:
-               case TV_ARROW:
-               case TV_SHOT:
-               case TV_DRAG_ARMOR:
-               case TV_HARD_ARMOR:
-               case TV_SOFT_ARMOR:
-               case TV_SHIELD:
-               case TV_CLOAK:
-               case TV_CROWN:
-               case TV_HELM:
-               case TV_BOOTS:
-               case TV_GLOVES:
-               {
-                       if (o_ptr->xtra3) return (TRUE);
-               }
-       }
-
-       return (FALSE);
-}
-
-
+/*!
+ * @brief ¥¨¥Ã¥»¥ó¥¹¤ò¾Ãµî¤¹¤ë
+ * @return ¤Ê¤·
+ */
 static void erase_essence(void)
 {
        int item;
@@ -8334,7 +8883,7 @@ static void erase_essence(void)
        char o_name[MAX_NLEN];
        u32b flgs[TR_FLAG_SIZE];
 
-       item_tester_hook = item_tester_hook_smith;
+       item_tester_hook = object_is_smith;
 
        /* Get an item */
 #ifdef JP
@@ -8392,6 +8941,11 @@ static void erase_essence(void)
        p_ptr->window |= (PW_INVEN);
 }
 
+/*!
+ * @brief ÃÃÌꥳ¥Þ¥ó¥É¤Î¥á¥¤¥ó¥ë¡¼¥Á¥ó
+ * @param only_browse TRUE¤Ê¤é¤Ð¥¨¥Ã¥»¥ó¥¹°ìÍ÷¤Îɽ¼¨¤Î¤ß¤ò¹Ô¤¦
+ * @return ¤Ê¤·
+ */
 void do_cmd_kaji(bool only_browse)
 {
        int mode = 0;
@@ -8426,7 +8980,7 @@ void do_cmd_kaji(bool only_browse)
 #ifdef JP
                        msg_print("¤¦¤Þ¤¯¸«¤¨¤Ê¤¯¤Æºî¶È¤Ç¤­¤Ê¤¤¡ª");
 #else
-                       msg_print("You are hullcinating!");
+                       msg_print("You are hallucinating!");
 #endif
 
                        return;
@@ -8580,3 +9134,59 @@ void do_cmd_kaji(bool only_browse)
                case 5: add_essence(10);break;
        }
 }
+
+
+/*!
+ * @brief ÅêÚ³»þ¤¿¤¤¤Þ¤Ä¤ËÅꤲ¤ä¤¹¤¤/¾Æ´þ/¥¢¥ó¥Ç¥Ã¥É¥¹¥ì¥¤¤ÎÆÃÊ̸ú²Ì¤òÊÖ¤¹¡£
+ * Torches have special abilities when they are flaming.
+ * @param o_ptr ÅêÚ³¤¹¤ë¥ª¥Ö¥¸¥§¥¯¥È¤Î¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿
+ * @param flgs ÆÃÊ̤ËÄɲ乤ë¥Õ¥é¥°¤òÊÖ¤¹»²¾È¥Ý¥¤¥ó¥¿
+ * @return ¤Ê¤·
+ */
+void torch_flags(object_type *o_ptr, u32b *flgs)
+{
+       if ((o_ptr->tval == TV_LITE) && (o_ptr->sval == SV_LITE_TORCH))
+       {
+               if (o_ptr->xtra4 > 0)
+               {
+                       add_flag(flgs, TR_BRAND_FIRE);
+                       add_flag(flgs, TR_KILL_UNDEAD);
+                       add_flag(flgs, TR_THROW);
+               }
+       }
+}
+
+/*!
+ * @brief ÅêÚ³»þ¤¿¤¤¤Þ¤Ä¤Ë¥À¥¤¥¹¤òÍ¿¤¨¤ë¡£
+ * Torches have special abilities when they are flaming.
+ * @param o_ptr ÅêÚ³¤¹¤ë¥ª¥Ö¥¸¥§¥¯¥È¤Î¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿
+ * @param dd ÆÃÊ̤ʥÀ¥¤¥¹¿ô¤òÊÖ¤¹»²¾È¥Ý¥¤¥ó¥¿
+ * @param ds ÆÃÊ̤ʥÀ¥¤¥¹ÌÌ¿ô¤òÊÖ¤¹»²¾È¥Ý¥¤¥ó¥¿
+ * @return ¤Ê¤·
+ */
+void torch_dice(object_type *o_ptr, int *dd, int *ds)
+{
+       if ((o_ptr->tval == TV_LITE) && (o_ptr->sval == SV_LITE_TORCH))
+       {
+               if (o_ptr->xtra4 > 0)
+               {
+                       (*dd) = 1;
+                       (*ds) = 6;
+               }
+       }
+}
+
+/*!
+ * @brief ÅêÚ³»þÌ¿Ã椷¤¿¤¿¤¤¤Þ¤Ä¤Î¼÷Ì¿¤ò½Ì¤á¤ë¡£
+ * Torches have special abilities when they are flaming.
+ * @param o_ptr ÅêÚ³¤¹¤ë¥ª¥Ö¥¸¥§¥¯¥È¤Î¹½Â¤Âλ²¾È¥Ý¥¤¥ó¥¿
+ * @return ¤Ê¤·
+ */
+void torch_lost_fuel(object_type *o_ptr)
+{
+       if ((o_ptr->tval == TV_LITE) && (o_ptr->sval == SV_LITE_TORCH))
+       {
+               o_ptr->xtra4 -= (FUEL_TORCH / 25);
+               if (o_ptr->xtra4 < 0) o_ptr->xtra4 = 0;
+       }
+}