OSDN Git Service

Add crown ego -- of basilisk
[hengband/hengband.git] / src / object2.c
index 1294cb3..1ff9986 100644 (file)
@@ -359,7 +359,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 +392,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 */
@@ -451,7 +451,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;
@@ -561,7 +561,7 @@ s16b o_pop(void)
 /*
  * Apply a "object restriction function" to the "object allocation table"
  */
-errr get_obj_num_prep(void)
+static errr get_obj_num_prep(void)
 {
        int i;
 
@@ -764,15 +764,10 @@ void object_known(object_type *o_ptr)
  */
 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)))
@@ -785,7 +780,7 @@ void object_aware(object_type *o_ptr)
                object_copy(q_ptr, o_ptr);
 
                q_ptr->number = 1;
-               object_desc(o_name, q_ptr, TRUE, 0);
+               object_desc(o_name, q_ptr, OD_NAME_ONLY);
                
                do_cmd_write_nikki(NIKKI_HANMEI, 0, o_name);
        }
@@ -797,12 +792,8 @@ void object_aware(object_type *o_ptr)
  */
 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 */
 }
 
 
@@ -813,7 +804,7 @@ void object_tried(object_type *o_ptr)
 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)
@@ -865,47 +856,46 @@ static s32b object_value_base(object_type *o_ptr)
 
 
 /* Return the value of the flags the object has... */
-s32b flag_cost(object_type * o_ptr, int plusses)
+s32b flag_cost(object_type *o_ptr, int plusses)
 {
        s32b total = 0;
        u32b flgs[TR_FLAG_SIZE];
        s32b tmp_cost;
        int count;
        int i;
+       object_kind *k_ptr = &k_info[o_ptr->k_idx];
 
        object_flags(o_ptr, flgs);
 
-       if (o_ptr->name1)
+       /*
+        * Exclude fixed flags of the base item.
+        * pval bonuses of base item will be treated later.
+        */
+       for (i = 0; i < TR_FLAG_SIZE; i++)
+               flgs[i] &= ~(k_ptr->flags[i]);
+
+       /* Exclude fixed flags of the fixed artifact. */
+       if (object_is_fixed_artifact(o_ptr))
        {
                artifact_type *a_ptr = &a_info[o_ptr->name1];
 
                for (i = 0; i < TR_FLAG_SIZE; i++)
                        flgs[i] &= ~(a_ptr->flags[i]);
        }
-       else
-       {
-               if ((o_ptr->tval == TV_RING) || (o_ptr->tval == TV_AMULET))
-               {
-                       object_kind *k_ptr = &k_info[o_ptr->k_idx];
-
-                       for (i = 0; i < TR_FLAG_SIZE; i++)
-                               flgs[i] &= ~(k_ptr->flags[i]);
-               }
-
-               if (o_ptr->name2)
-               {
-                       ego_item_type *e_ptr = &e_info[o_ptr->name2];
 
-                       for (i = 0; i < TR_FLAG_SIZE; i++)
-                               flgs[i] &= ~(e_ptr->flags[i]);
+       /* Exclude fixed flags of the ego-item. */
+       else if (object_is_ego(o_ptr))
+       {
+               ego_item_type *e_ptr = &e_info[o_ptr->name2];
 
-               }
-               else if (o_ptr->art_name)
-               {
-                       total = 5000;
-               }
+               for (i = 0; i < TR_FLAG_SIZE; i++)
+                       flgs[i] &= ~(e_ptr->flags[i]);
        }
 
+
+       /*
+        * Calucurate values of remaining flags
+        */
        if (have_flag(flgs, TR_STR)) total += (1500 * plusses);
        if (have_flag(flgs, TR_INT)) total += (1500 * plusses);
        if (have_flag(flgs, TR_WIS)) total += (1500 * plusses);
@@ -921,7 +911,6 @@ s32b flag_cost(object_type * o_ptr, int plusses)
                total += (10000 + (2500 * plusses));
        if ((have_flag(flgs, TR_BLOWS)) && (plusses > 0))
                total += (10000 + (2500 * plusses));
-       if (have_flag(flgs, TR_DEC_MANA)) total += 10000;
 
        tmp_cost = 0;
        count = 0;
@@ -1001,7 +990,7 @@ 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_LEVITATION)) total += 1250;
        if (have_flag(flgs, TR_LITE)) total += 1250;
        if (have_flag(flgs, TR_SEE_INVIS)) total += 2000;
        if (have_flag(flgs, TR_TELEPATHY)) total += 20000;
@@ -1020,6 +1009,7 @@ s32b flag_cost(object_type * o_ptr, int plusses)
        if (have_flag(flgs, TR_SLOW_DIGEST)) total += 750;
        if (have_flag(flgs, TR_REGEN)) total += 2500;
        if (have_flag(flgs, TR_WARNING)) total += 2000;
+       if (have_flag(flgs, TR_DEC_MANA)) total += 10000;
        if (have_flag(flgs, TR_XTRA_MIGHT)) total += 2250;
        if (have_flag(flgs, TR_XTRA_SHOTS)) total += 10000;
        if (have_flag(flgs, TR_IGNORE_ACID)) total += 100;
@@ -1028,15 +1018,19 @@ 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_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;
@@ -1044,82 +1038,10 @@ 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;
@@ -1157,16 +1079,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];
 
@@ -1176,11 +1098,13 @@ s32b object_value_real(object_type *o_ptr)
                /* Hack -- Use the artifact cost instead */
                value = a_ptr->cost;
                value += flag_cost(o_ptr, o_ptr->pval);
+
+               /* Don't add pval bonuses etc. */
                return (value);
        }
 
        /* Ego-Item */
-       else if (o_ptr->name2)
+       else if (object_is_ego(o_ptr))
        {
                ego_item_type *e_ptr = &e_info[o_ptr->name2];
 
@@ -1203,62 +1127,59 @@ s32b object_value_real(object_type *o_ptr)
                if (flag) value += flag_cost(o_ptr, o_ptr->pval);
        }
 
-
-       /* Analyze pval bonus */
+       /* Analyze pval bonus for normal object */
        switch (o_ptr->tval)
        {
-               case TV_SHOT:
-               case TV_ARROW:
-               case TV_BOLT:
-               case TV_BOW:
-               case TV_DIGGING:
-               case TV_HAFTED:
-               case TV_POLEARM:
-               case TV_SWORD:
-               case TV_BOOTS:
-               case TV_GLOVES:
-               case TV_HELM:
-               case TV_CROWN:
-               case TV_SHIELD:
-               case TV_CLOAK:
-               case TV_SOFT_ARMOR:
-               case TV_HARD_ARMOR:
-               case TV_DRAG_ARMOR:
-               case TV_LITE:
-               case TV_AMULET:
-               case TV_RING:
-               {
-                       /* Hack -- Negative "pval" is always bad */
-                       if (o_ptr->pval < 0) return (0L);
+       case TV_SHOT:
+       case TV_ARROW:
+       case TV_BOLT:
+       case TV_BOW:
+       case TV_DIGGING:
+       case TV_HAFTED:
+       case TV_POLEARM:
+       case TV_SWORD:
+       case TV_BOOTS:
+       case TV_GLOVES:
+       case TV_HELM:
+       case TV_CROWN:
+       case TV_SHIELD:
+       case TV_CLOAK:
+       case TV_SOFT_ARMOR:
+       case TV_HARD_ARMOR:
+       case TV_DRAG_ARMOR:
+       case TV_LITE:
+       case TV_AMULET:
+       case TV_RING:
+               /* No pval */
+               if (!o_ptr->pval) break;
+
+               /* Hack -- Negative "pval" is always bad */
+               if (o_ptr->pval < 0) return (0L);
+
+               /* Give credit for stat bonuses */
+               if (have_flag(flgs, TR_STR)) value += (o_ptr->pval * 200L);
+               if (have_flag(flgs, TR_INT)) value += (o_ptr->pval * 200L);
+               if (have_flag(flgs, TR_WIS)) value += (o_ptr->pval * 200L);
+               if (have_flag(flgs, TR_DEX)) value += (o_ptr->pval * 200L);
+               if (have_flag(flgs, TR_CON)) value += (o_ptr->pval * 200L);
+               if (have_flag(flgs, TR_CHR)) value += (o_ptr->pval * 200L);
+
+               /* Give credit for stealth and searching */
+               if (have_flag(flgs, TR_MAGIC_MASTERY)) value += (o_ptr->pval * 100);
+               if (have_flag(flgs, TR_STEALTH)) value += (o_ptr->pval * 100L);
+               if (have_flag(flgs, TR_SEARCH)) value += (o_ptr->pval * 100L);
+
+               /* Give credit for infra-vision and tunneling */
+               if (have_flag(flgs, TR_INFRA)) value += (o_ptr->pval * 50L);
+               if (have_flag(flgs, TR_TUNNEL)) value += (o_ptr->pval * 50L);
+
+               /* Give credit for extra attacks */
+               if (have_flag(flgs, TR_BLOWS)) value += (o_ptr->pval * 5000L);
+
+               /* Give credit for speed bonus */
+               if (have_flag(flgs, TR_SPEED)) value += (o_ptr->pval * 10000L);
 
-                       /* No pval */
-                       if (!o_ptr->pval) break;
-
-                       /* Give credit for stat bonuses */
-                       if (have_flag(flgs, TR_STR)) value += (o_ptr->pval * 200L);
-                       if (have_flag(flgs, TR_INT)) value += (o_ptr->pval * 200L);
-                       if (have_flag(flgs, TR_WIS)) value += (o_ptr->pval * 200L);
-                       if (have_flag(flgs, TR_DEX)) value += (o_ptr->pval * 200L);
-                       if (have_flag(flgs, TR_CON)) value += (o_ptr->pval * 200L);
-                       if (have_flag(flgs, TR_CHR)) value += (o_ptr->pval * 200L);
-
-                       /* Give credit for stealth and searching */
-                       if (have_flag(flgs, TR_MAGIC_MASTERY)) value += (o_ptr->pval * 100L);
-                       if (have_flag(flgs, TR_STEALTH)) value += (o_ptr->pval * 100L);
-                       if (have_flag(flgs, TR_SEARCH)) value += (o_ptr->pval * 100L);
-
-                       /* Give credit for infra-vision and tunneling */
-                       if (have_flag(flgs, TR_INFRA)) value += (o_ptr->pval * 50L);
-                       if (have_flag(flgs, TR_TUNNEL)) value += (o_ptr->pval * 50L);
-
-                       /* Give credit for extra attacks */
-                       if (have_flag(flgs, TR_BLOWS)) value += (o_ptr->pval * 5000L);
-
-                       /* Give credit for speed bonus */
-                       if (have_flag(flgs, TR_SPEED)) value += (o_ptr->pval * 10000L);
-
-                       break;
-               }
+               break;
        }
 
 
@@ -1388,6 +1309,9 @@ s32b object_value_real(object_type *o_ptr)
                }
        }
 
+       /* Worthless object */
+       if (value < 0) return 0L;
+
        /* Return the value */
        return (value);
 }
@@ -1410,13 +1334,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);
@@ -1426,10 +1350,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);
@@ -1451,12 +1375,15 @@ s32b object_value(object_type *o_ptr)
 bool can_player_destroy_object(object_type *o_ptr)
 {
        /* Artifacts cannot be destroyed */
-       if (artifact_p(o_ptr) || o_ptr->art_name)
+       if (!object_is_artifact(o_ptr)) return TRUE;
+
+       /* If object is unidentified, makes fake inscription */
+       if (!object_is_known(o_ptr))
        {
                byte feel = FEEL_SPECIAL;
 
                /* Hack -- Handle icky artifacts */
-               if (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;
@@ -1474,7 +1401,8 @@ bool can_player_destroy_object(object_type *o_ptr)
                return FALSE;
        }
 
-       return TRUE;
+       /* Identified artifact -- Nothing to do */
+       return FALSE;
 }
 
 
@@ -1560,7 +1488,7 @@ void reduce_charges(object_type *o_ptr, int amt)
  *  Determine if an item can partly absorb a second item.
  *  Return maximum number of stack.
  */
-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;
 
@@ -1615,9 +1543,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;
@@ -1631,9 +1559,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.  */
 
@@ -1666,20 +1594,15 @@ static int object_similar_part(object_type *o_ptr, object_type *j_ptr)
                case TV_SOFT_ARMOR:
                case TV_HARD_ARMOR:
                case TV_DRAG_ARMOR:
-               {
-                       /* Require permission */
-                       if (!stack_allow_items) return 0;
-
-                       /* Fall through */
-               }
 
                /* Rings, Amulets, Lites */
                case TV_RING:
                case TV_AMULET:
                case TV_LITE:
+               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 +1613,8 @@ 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" */
                        if (o_ptr->to_h != j_ptr->to_h) return 0;
@@ -1700,11 +1624,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;
@@ -1732,7 +1653,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;
@@ -1804,14 +1725,14 @@ 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_STOREB) || (j_ptr->ident & IDENT_STOREB)) &&
-           (!((o_ptr->ident & IDENT_STOREB) && (j_ptr->ident & IDENT_STOREB))))
+       if (((o_ptr->ident & IDENT_STORE) || (j_ptr->ident & IDENT_STORE)) &&
+           (!((o_ptr->ident & IDENT_STORE) && (j_ptr->ident & IDENT_STORE))))
        {
-               if (j_ptr->ident & IDENT_STOREB) j_ptr->ident &= 0xEF;
-               if (o_ptr->ident & IDENT_STOREB) o_ptr->ident &= 0xEF;
+               if (j_ptr->ident & IDENT_STORE) j_ptr->ident &= 0xEF;
+               if (o_ptr->ident & IDENT_STORE) o_ptr->ident &= 0xEF;
        }
 
        /* Hack -- blend "mental" status */
@@ -1909,7 +1830,7 @@ void object_wipe(object_type *o_ptr)
 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);
 }
 
 
@@ -1949,8 +1870,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);
@@ -2052,10 +1976,10 @@ static void object_mention(object_type *o_ptr)
        char o_name[MAX_NLEN];
 
        /* Describe */
-       object_desc_store(o_name, o_ptr, FALSE, 0);
+       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
@@ -2078,7 +2002,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
@@ -2291,7 +2215,6 @@ static byte get_random_ego(byte slot, bool good)
  *
  * Hack -- note special base damage dice boosting
  * Hack -- note special processing for weapon/digger
- * Hack -- note special rating boost for dragon scale mail
  */
 static void a_m_aux_1(object_type *o_ptr, int level, int power)
 {
@@ -2397,6 +2320,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;
                                }
 
@@ -2474,6 +2399,20 @@ 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);
+                                       break;
                                }
 
                                if (!o_ptr->art_name)
@@ -2492,11 +2431,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);
                                        }
                                }
                        }
@@ -2595,42 +2550,31 @@ static bool add_esp_strong(object_type *o_ptr)
 }
 
 
-#define MAX_ESP_WEAK 9
 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];
        }
 }
 
@@ -2684,8 +2628,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);
 
@@ -2735,31 +2677,63 @@ 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);
+                                       break;
+                                 case EGO_A_MORGUL:
+                                       if (one_in_(3)) o_ptr->curse_flags |= (TRC_HEAVY_CURSE);
+                                       if (one_in_(6)) 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_(4)) add_flag(o_ptr->art_flags, TR_AGGRAVATE);
+                                       if (one_in_(6)) add_flag(o_ptr->art_flags, TR_NO_MAGIC);
+                                       if (one_in_(6)) add_flag(o_ptr->art_flags, TR_NO_TELE);
+                                       break;
+                                 default:
+                                       break;
+                               }
                        }
 
                        break;
@@ -2770,9 +2744,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);
@@ -2787,7 +2758,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)
                                {
@@ -2799,6 +2780,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;
@@ -2808,9 +2794,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);
@@ -2839,9 +2822,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);
@@ -2901,6 +2881,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))
@@ -2931,9 +2912,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);
@@ -2955,11 +2933,11 @@ 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_BRILLIANCE:
                                        case EGO_LITE:
+                                       case EGO_DARK:
                                        case EGO_INFRAVISION:
+                                       case EGO_H_PROTECTION:
                                                break;
                                        case EGO_SEEING:
                                                if (one_in_(7))
@@ -3021,8 +2999,6 @@ static void a_m_aux_2(object_type *o_ptr, int level, int power)
 /*
  * 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)
  */
@@ -3112,9 +3088,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);
 
@@ -3131,7 +3104,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;
 
@@ -3330,7 +3302,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);
@@ -3623,9 +3595,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);
 
@@ -3669,7 +3638,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);
@@ -3700,7 +3669,7 @@ static void a_m_aux_3(object_type *o_ptr, int level, int power)
                                                o_ptr->name2 = EGO_AMU_HOLD_LIFE;
                                                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:
@@ -3829,8 +3798,8 @@ static bool item_monster_okay(int r_idx)
        /* No uniques */
        if (r_ptr->flags1 & RF1_UNIQUE) return (FALSE);
        if (r_ptr->flags7 & RF7_KAGE) return (FALSE);
-       if (r_ptr->flags3 & RF3_RES_ALL) return (FALSE);
-       if (r_ptr->flags7 & RF7_UNIQUE_7) return (FALSE);
+       if (r_ptr->flagsr & RFR_RES_ALL) return (FALSE);
+       if (r_ptr->flags7 & RF7_NAZGUL) return (FALSE);
        if (r_ptr->flags1 & RF1_FORCE_DEPTH) return (FALSE);
        if (r_ptr->flags7 & RF7_UNIQUE2) return (FALSE);
 
@@ -3978,6 +3947,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;
 
@@ -3998,7 +3970,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;
@@ -4102,7 +4074,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;
@@ -4169,7 +4141,7 @@ void apply_magic(object_type *o_ptr, int lev, u32b mode)
        if (f1 > d_info[dungeon_type].obj_good) f1 = d_info[dungeon_type].obj_good;
 
        /* Base chance of being "great" */
-       f2 = f1 / 2;
+       f2 = f1 * 2 / 3;
 
        /* Maximal chance of being "great" */
        if ((p_ptr->pseikaku != SEIKAKU_MUNCHKIN) && (f2 > d_info[dungeon_type].obj_great))
@@ -4255,7 +4227,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];
 
@@ -4275,6 +4247,7 @@ 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;
 
                /* Hack -- extract the "broken" flag */
                if (!a_ptr->cost) o_ptr->ident |= (IDENT_BROKEN);
@@ -4287,17 +4260,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);
@@ -4389,10 +4351,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];
 
@@ -4414,9 +4374,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);
@@ -4449,6 +4422,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)
@@ -4458,6 +4459,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);
@@ -4470,10 +4482,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))
                        {
@@ -4483,12 +4501,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;
        }
@@ -4499,7 +4514,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);
@@ -4563,11 +4578,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);
@@ -4623,25 +4639,25 @@ bool make_object(object_type *j_ptr, u32b mode)
                int k_idx;
 
                /* Good objects */
-               if (mode & AM_GOOD)
+               if ((mode & AM_GOOD) && !get_obj_num_hook)
                {
-                       /* Activate restriction */
+                       /* Activate restriction (if already specified, use that) */
                        get_obj_num_hook = kind_is_good;
-
-                       /* Prepare allocation table */
-                       get_obj_num_prep();
                }
 
+               /* Restricted objects - prepare allocation table */
+               if (get_obj_num_hook) get_obj_num_prep();
+
                /* Pick a random object */
                k_idx = get_obj_num(base);
 
-               /* Good objects */
+               /* Restricted objects */
                if (get_obj_num_hook)
                {
                        /* Clear restriction */
                        get_obj_num_hook = NULL;
 
-                       /* Prepare allocation table */
+                       /* Reset allocation table to default */
                        get_obj_num_prep();
                }
 
@@ -4668,16 +4684,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);
        }
@@ -4700,7 +4713,8 @@ void place_object(int y, int x, u32b mode)
 {
        s16b o_idx;
 
-       cave_type *c_ptr;
+       /* Acquire grid */
+       cave_type *c_ptr = &cave[y][x];
 
        object_type forge;
        object_type *q_ptr;
@@ -4709,8 +4723,11 @@ void place_object(int y, int x, u32b mode)
        /* Paranoia -- check bounds */
        if (!in_bounds(y, x)) return;
 
-       /* Require clean floor space */
-       if (!cave_clean_bold(y, x)) return;
+       /* Require floor space */
+       if (!cave_drop_bold(y, x)) return;
+
+       /* Avoid stacking on other objects */
+       if (c_ptr->o_idx) return;
 
 
        /* Get local object */
@@ -4741,9 +4758,6 @@ void place_object(int y, int x, u32b mode)
                o_ptr->iy = y;
                o_ptr->ix = x;
 
-               /* Acquire grid */
-               c_ptr = &cave[y][x];
-
                /* Build a stack */
                o_ptr->next_o_idx = c_ptr->o_idx;
 
@@ -4759,7 +4773,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;
                }
@@ -4817,7 +4831,9 @@ void place_gold(int y, int x)
 {
        s16b o_idx;
 
-       cave_type *c_ptr;
+       /* Acquire grid */
+       cave_type *c_ptr = &cave[y][x];
+
 
        object_type forge;
        object_type *q_ptr;
@@ -4826,8 +4842,11 @@ void place_gold(int y, int x)
        /* Paranoia -- check bounds */
        if (!in_bounds(y, x)) return;
 
-       /* Require clean floor space */
-       if (!cave_clean_bold(y, x)) return;
+       /* Require floor space */
+       if (!cave_drop_bold(y, x)) return;
+
+       /* Avoid stacking on other objects */
+       if (c_ptr->o_idx) return;
 
 
        /* Get local object */
@@ -4858,9 +4877,6 @@ void place_gold(int y, int x)
                o_ptr->iy = y;
                o_ptr->ix = x;
 
-               /* Acquire grid */
-               c_ptr = &cave[y][x];
-
                /* Build a stack */
                o_ptr->next_o_idx = c_ptr->o_idx;
 
@@ -4899,7 +4915,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;
 
@@ -4918,11 +4934,11 @@ s16b drop_near(object_type *j_ptr, int chance, int y, int x)
 #endif
 
        /* Describe object */
-       object_desc(o_name, j_ptr, FALSE, 0);
+       object_desc(o_name, j_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
 
 
        /* 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
@@ -4977,22 +4993,14 @@ 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];
 
                        /* Require floor space */
-                       if ((c_ptr->feat != FEAT_FLOOR) &&
-                           (c_ptr->feat != FEAT_SHAL_WATER) &&
-                           (c_ptr->feat != FEAT_GRASS) &&
-                           (c_ptr->feat != FEAT_DIRT) &&
-                           (c_ptr->feat != FEAT_FLOWER) &&
-                           (c_ptr->feat != FEAT_DEEP_GRASS) &&
-                           (c_ptr->feat != FEAT_SHAL_LAVA) &&
-                           (c_ptr->feat != FEAT_TREES)) continue;
-                       if (c_ptr->info & (CAVE_OBJECT)) continue;
+                       if (!cave_drop_bold(ty, tx)) continue;
 
                        /* No objects */
                        k = 0;
@@ -5047,7 +5055,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
@@ -5072,44 +5080,96 @@ 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);
-               }
-
-               /* Random locations */
-               else
-               {
-                       ty = randint0(cur_hgt);
-                       tx = randint0(cur_wid);
-               }
+               ty = rand_spread(by, 1);
+               tx = rand_spread(bx, 1);
 
-               /* Grid */
-               c_ptr = &cave[ty][tx];
-
-               /* Require floor space (or shallow terrain) -KMW- */
-               if ((c_ptr->feat != FEAT_FLOOR) &&
-                   (c_ptr->feat != FEAT_SHAL_WATER) &&
-                   (c_ptr->feat != FEAT_GRASS) &&
-                   (c_ptr->feat != FEAT_DIRT) &&
-                   (c_ptr->feat != FEAT_SHAL_LAVA)) continue;
+               /* Verify location */
+               if (!in_bounds(ty, tx)) continue;
 
                /* Bounce to that location */
                by = ty;
                bx = tx;
 
                /* Require floor space */
-               if (!cave_clean_bold(by, bx)) continue;
+               if (!cave_drop_bold(by, bx)) 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];
 
@@ -5162,7 +5222,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;
                }
@@ -5208,7 +5268,7 @@ s16b drop_near(object_type *j_ptr, int chance, int y, int x)
 
        /* Mega-Hack -- no message if "dropped" by player */
        /* Message when an object falls under the player */
-       if (chance && (by == py) && (bx == px))
+       if (chance && player_bold(by, bx))
        {
 #ifdef JP
                msg_print("²¿¤«¤¬Â­²¼¤Ëž¤¬¤Ã¤Æ¤­¤¿¡£");
@@ -5258,57 +5318,185 @@ void acquirement(int y1, int x1, int num, bool great, bool known)
 }
 
 
-#define MAX_TRAPS              18
+/*
+ * Scatter some "amusing" objects near the player
+ */
+
+#define AMS_NOTHING   0x00 /* No restriction */
+#define AMS_NO_UNIQUE 0x01 /* Don't make the amusing object of uniques */
+#define AMS_FIXED_ART 0x02 /* Make a fixed artifact based on the amusing object */
+#define AMS_MULTIPLE  0x04 /* Drop 1-3 objects for one type */
+#define AMS_PILE      0x08 /* Drop 1-99 pile objects for one type */
+
+typedef struct
+{
+       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 }
 };
 
-
-/*
- * 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.
- */
-byte choose_random_trap(void)
+void amusement(int y1, int x1, int num, bool known)
 {
-       byte feat;
+       object_type *i_ptr;
+       object_type object_type_body;
+       int n, t = 0;
 
-       /* Pick a trap */
-       while (1)
+       for (n = 0; amuse_info[n].tval != 0; n++)
        {
-               /* Hack -- pick a trap */
-               feat = trap_num[randint0(MAX_TRAPS)];
+               t += amuse_info[n].prob;
+       }
 
-               /* Accept non-trapdoors */
-               if (feat != FEAT_TRAP_TRAPDOOR) break;
+       /* Acquirement */
+       while (num)
+       {
+               int i, k_idx, a_idx = 0;
+               int r = randint0(t);
+               bool insta_art, fixed_art;
 
-               /* Hack -- no trap doors on special levels */
-               if (p_ptr->inside_arena || quest_number(dun_level)) continue;
+               for (i = 0; ; i++)
+               {
+                       r -= amuse_info[i].prob;
+                       if (r <= 0) break;
+               }
 
-               /* Hack -- no trap doors on the deepest level */
-               if (dun_level >= d_info[dungeon_type].maxdepth) continue;
+               /* 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];
+
+/*
+ * Initialize arrays for normal traps
+ */
+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");
+}
+
+/*
+ * 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.
+ */
+s16b choose_random_trap(void)
+{
+       s16b feat;
+
+       /* Pick a trap */
+       while (1)
+       {
+               /* Hack -- pick a trap */
+               feat = normal_traps[randint0(MAX_NORMAL_TRAPS)];
+
+               /* Accept non-trapdoors */
+               if (!have_flag(f_info[feat].flags, FF_MORE)) break;
+
+               /* Hack -- no trap doors on special levels */
+               if (p_ptr->inside_arena || quest_number(dun_level)) continue;
+
+               /* Hack -- no trap doors on the deepest level */
+               if (dun_level >= d_info[dungeon_type].maxdepth) continue;
 
                break;
        }
@@ -5323,17 +5511,22 @@ void disclose_grid(int y, int x)
 {
        cave_type *c_ptr = &cave[y][x];
 
-       /* Paranoia */
-       if (!c_ptr->mimic) return;
-
-       /* No longer hidden */
-       c_ptr->mimic = 0;
+       if (cave_have_flag_grid(c_ptr, FF_SECRET))
+       {
+               /* No longer hidden */
+               cave_alter_feat(y, x, FF_SECRET);
+       }
+       else if (c_ptr->mimic)
+       {
+               /* No longer hidden */
+               c_ptr->mimic = 0;
 
-       /* Notice */
-       note_spot(y, x);
+               /* Notice */
+               note_spot(y, x);
 
-       /* Redraw */
-       lite_spot(y, x);
+               /* Redraw */
+               lite_spot(y, x);
+       }
 }
 
 
@@ -5354,7 +5547,7 @@ void place_trap(int y, int x)
        if (!in_bounds(y, x)) return;
 
        /* Require empty, clean, floor grid */
-       if (!cave_naked_bold(y, x)) return;
+       if (!cave_clean_bold(y, x)) return;
 
        /* Place an invisible trap */
        c_ptr->mimic = c_ptr->feat;
@@ -5373,7 +5566,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)
@@ -5412,7 +5605,7 @@ void inven_item_describe(int item)
        char        o_name[MAX_NLEN];
 
        /* Get a description */
-       object_desc(o_name, o_ptr, TRUE, 3);
+       object_desc(o_name, o_ptr, 0);
 
        /* Print a message */
 #ifdef JP
@@ -5471,6 +5664,19 @@ void inven_item_increase(int item, int num)
 
                /* Window stuff */
                p_ptr->window |= (PW_INVEN | PW_EQUIP);
+
+               /* Hack -- Clear temporary elemental brands if player takes off weapons */
+               if (!o_ptr->number && p_ptr->ele_attack)
+               {
+                       if ((item == INVEN_RARM) || (item == INVEN_LARM))
+                       {
+                               if (!buki_motteruka(INVEN_RARM + INVEN_LARM - item))
+                               {
+                                       /* Clear all temporary elemental brands */
+                                       set_ele_attack(0, 0);
+                               }
+                       }
+               }
        }
 }
 
@@ -5548,7 +5754,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)
@@ -5587,7 +5793,7 @@ void floor_item_describe(int item)
        char        o_name[MAX_NLEN];
 
        /* Get a description */
-       object_desc(o_name, o_ptr, TRUE, 3);
+       object_desc(o_name, o_ptr, 0);
 
        /* Print a message */
 #ifdef JP
@@ -5674,6 +5880,87 @@ bool inven_carry_okay(object_type *o_ptr)
 }
 
 
+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);
+}
+
+
 /*
  * Add an item to the players inventory, and return the slot used.
  *
@@ -5750,60 +6037,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 */
@@ -5836,8 +6076,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);
@@ -5902,10 +6142,11 @@ s16b inven_takeoff(int item, int amt)
        q_ptr->number = amt;
 
        /* Describe the object */
-       object_desc(o_name, q_ptr, TRUE, 3);
+       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 = "¤òÁõÈ÷¤«¤é¤Ï¤º¤·¤¿";
@@ -6017,7 +6258,7 @@ void inven_drop(int item, int amt)
        q_ptr->number = amt;
 
        /* Describe local object */
-       object_desc(o_name, q_ptr, TRUE, 3);
+       object_desc(o_name, q_ptr, 0);
 
        /* Message */
 #ifdef JP
@@ -6047,93 +6288,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];
+               combined = FALSE;
 
-               /* Skip empty items */
-               if (!o_ptr->k_idx) continue;
-
-               /* 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;
 
-                                       /* Add together the item counts */
-                                       object_absorb(j_ptr, o_ptr);
+                               /* Get the item */
+                               j_ptr = &inventory[j];
 
-                                       /* One object is gone */
-                                       inven_cnt--;
+                               /* Skip empty items */
+                               if (!j_ptr->k_idx) continue;
 
-                                       /* Slide everything down */
-                                       for (k = i; k < INVEN_PACK; k++)
+                               /*
+                                * Get maximum number of the stack if these
+                                * are similar, get zero otherwise.
+                                */
+                               max_num = object_similar_part(j_ptr, o_ptr);
+
+                               /* 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
@@ -6153,10 +6402,8 @@ 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;
 
@@ -6179,55 +6426,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 */
@@ -6300,7 +6499,7 @@ void display_koff(int k_idx)
        object_prep(q_ptr, k_idx);
 
        /* Describe */
-       object_desc_store(o_name, q_ptr, FALSE, 0);
+       object_desc(o_name, q_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY | OD_STORE));
 
        /* Mention the object name */
        Term_putstr(0, 0, -1, TERM_WHITE, o_name);
@@ -6384,48 +6583,72 @@ static void spell_damcalc(monster_type *m_ptr, int typ, int dam, int limit, int
        switch (typ)
        {
        case GF_ELEC:
-               if (p_ptr->muta3 & MUT3_VULN_ELEM) dam *= 2;
-               if (p_ptr->special_defense & KATA_KOUKIJIN) dam += dam / 3;
-               if (prace_is_(RACE_ANDROID)) dam += dam / 3;
-               if (p_ptr->resist_elec) dam = (dam + 2) / 3;
-               if (IS_OPPOSE_ELEC())
-                       dam = (dam + 2) / 3;
-               if (p_ptr->immune_elec) dam = 0;
+               if (p_ptr->immune_elec)
+               {
+                       dam = 0;
+                       ignore_wraith_form = TRUE;
+               }
+               else
+               {
+                       if (p_ptr->muta3 & MUT3_VULN_ELEM) dam *= 2;
+                       if (p_ptr->special_defense & KATA_KOUKIJIN) dam += dam / 3;
+                       if (prace_is_(RACE_ANDROID)) dam += dam / 3;
+                       if (p_ptr->resist_elec) dam = (dam + 2) / 3;
+                       if (IS_OPPOSE_ELEC())
+                               dam = (dam + 2) / 3;
+               }
                break;
 
        case GF_POIS:
                if (p_ptr->resist_pois) dam = (dam + 2) / 3;
-               if (IS_OPPOSE_POIS())
-                       dam = (dam + 2) / 3;
+               if (IS_OPPOSE_POIS()) dam = (dam + 2) / 3;
                break;
 
        case GF_ACID:
-               if (p_ptr->muta3 & MUT3_VULN_ELEM) dam *= 2;
-               if (p_ptr->special_defense & KATA_KOUKIJIN) dam += dam / 3;
-               if (p_ptr->resist_acid) dam = (dam + 2) / 3;
-               if (IS_OPPOSE_ACID())
-                       dam = (dam + 2) / 3;
-               if (p_ptr->immune_acid) dam = 0;
+               if (p_ptr->immune_acid)
+               {
+                       dam = 0;
+                       ignore_wraith_form = TRUE;
+               }
+               else
+               {
+                       if (p_ptr->muta3 & MUT3_VULN_ELEM) dam *= 2;
+                       if (p_ptr->special_defense & KATA_KOUKIJIN) dam += dam / 3;
+                       if (p_ptr->resist_acid) dam = (dam + 2) / 3;
+                       if (IS_OPPOSE_ACID()) dam = (dam + 2) / 3;
+               }
                break;
 
        case GF_COLD:
        case GF_ICE:
-               if (p_ptr->muta3 & MUT3_VULN_ELEM) dam *= 2;
-               if (p_ptr->special_defense & KATA_KOUKIJIN) dam += dam / 3;
-               if (p_ptr->resist_cold) dam = (dam + 2) / 3;
-               if (IS_OPPOSE_COLD())
-                       dam = (dam + 2) / 3;
-               if (p_ptr->immune_cold) dam = 0;
+               if (p_ptr->immune_cold)
+               {
+                       dam = 0;
+                       ignore_wraith_form = TRUE;
+               }
+               else
+               {
+                       if (p_ptr->muta3 & MUT3_VULN_ELEM) dam *= 2;
+                       if (p_ptr->special_defense & KATA_KOUKIJIN) dam += dam / 3;
+                       if (p_ptr->resist_cold) dam = (dam + 2) / 3;
+                       if (IS_OPPOSE_COLD()) dam = (dam + 2) / 3;
+               }
                break;
 
        case GF_FIRE:
-               if (p_ptr->muta3 & MUT3_VULN_ELEM) dam *= 2;
-               if (prace_is_(RACE_ENT)) dam += dam / 3;
-               if (p_ptr->special_defense & KATA_KOUKIJIN) dam += dam / 3;
-               if (p_ptr->resist_fire) dam = (dam + 2) / 3;
-               if (IS_OPPOSE_FIRE())
-                       dam = (dam + 2) / 3;
-               if (p_ptr->immune_fire) dam = 0;
+               if (p_ptr->immune_fire)
+               {
+                       dam = 0;
+                       ignore_wraith_form = TRUE;
+               }
+               else
+               {
+                       if (p_ptr->muta3 & MUT3_VULN_ELEM) dam *= 2;
+                       if (prace_is_(RACE_ENT)) dam += dam / 3;
+                       if (p_ptr->special_defense & KATA_KOUKIJIN) dam += dam / 3;
+                       if (p_ptr->resist_fire) dam = (dam + 2) / 3;
+                       if (IS_OPPOSE_FIRE()) dam = (dam + 2) / 3;
+               }
                break;
 
        case GF_PSY_SPEAR:
@@ -6436,19 +6659,31 @@ static void spell_damcalc(monster_type *m_ptr, int typ, int dam, int limit, int
                if (!p_ptr->blind &&
                    ((inventory[INVEN_RARM].k_idx && (inventory[INVEN_RARM].name1 == ART_ZANTETSU)) ||
                     (inventory[INVEN_LARM].k_idx && (inventory[INVEN_LARM].name1 == ART_ZANTETSU))))
+               {
                        dam = 0;
+                       ignore_wraith_form = TRUE;
+               }
                break;
 
        case GF_LITE:
                if (p_ptr->resist_lite) dam /= 2; /* Worst case of 4 / (d4 + 7) */
                if (prace_is_(RACE_VAMPIRE) || (p_ptr->mimic_form == MIMIC_VAMPIRE)) dam *= 2;
                else if (prace_is_(RACE_S_FAIRY)) dam = dam * 4 / 3;
-               ignore_wraith_form = TRUE;
+
+               /*
+                * Cannot use "ignore_wraith_form" strictly (for "random one damage")
+                * "dam *= 2;" for later "dam /= 2"
+                */
+               if (p_ptr->wraith_form) dam *= 2;
                break;
 
        case GF_DARK:
-               if (p_ptr->resist_dark) dam /= 2; /* Worst case of 4 / (d4 + 7) */
-               if (prace_is_(RACE_VAMPIRE) || (p_ptr->mimic_form == MIMIC_VAMPIRE) || p_ptr->wraith_form) dam = 0;
+               if (prace_is_(RACE_VAMPIRE) || (p_ptr->mimic_form == MIMIC_VAMPIRE) || p_ptr->wraith_form)
+               {
+                       dam = 0;
+                       ignore_wraith_form = TRUE;
+               }
+               else if (p_ptr->resist_dark) dam /= 2; /* Worst case of 4 / (d4 + 7) */
                break;
 
        case GF_SHARDS:
@@ -6468,8 +6703,12 @@ static void spell_damcalc(monster_type *m_ptr, int typ, int dam, int limit, int
                break;
 
        case GF_NETHER:
-               if (p_ptr->resist_neth) dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
-               if (prace_is_(RACE_SPECTRE)) dam = 0;
+               if (prace_is_(RACE_SPECTRE))
+               {
+                       dam = 0;
+                       ignore_wraith_form = TRUE;
+               }
+               else if (p_ptr->resist_neth) dam = dam * 3 / 4; /* Worst case of 6 / (d4 + 7) */
                break;
 
        case GF_DISENCHANT:
@@ -6485,7 +6724,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:
@@ -6494,14 +6733,17 @@ static void spell_damcalc(monster_type *m_ptr, int typ, int dam, int limit, int
 
        case GF_NUKE:
                if (p_ptr->resist_pois) dam = (2 * dam + 2) / 5;
-               if (IS_OPPOSE_POIS())
-                       dam = (2 * dam + 2) / 5;
+               if (IS_OPPOSE_POIS()) dam = (2 * dam + 2) / 5;
                break;
 
        case GF_DEATH_RAY:
                if (p_ptr->mimic_form)
                {
-                       if (mimic_info[p_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_NONLIVING) dam = 0;
+                       if (mimic_info[p_ptr->mimic_form].MIMIC_FLAGS & MIMIC_IS_NONLIVING)
+                       {
+                               dam = 0;
+                               ignore_wraith_form = TRUE;
+                       }
                }
                else
                {
@@ -6514,6 +6756,7 @@ static void spell_damcalc(monster_type *m_ptr, int typ, int dam, int limit, int
                        case RACE_DEMON:
                        case RACE_SPECTRE:
                                dam = 0;
+                               ignore_wraith_form = TRUE;
                                break;
                        }
                }
@@ -6530,18 +6773,30 @@ static void spell_damcalc(monster_type *m_ptr, int typ, int dam, int limit, int
 
        case GF_MIND_BLAST:
        case GF_BRAIN_SMASH:
-               if (100 + rlev / 2 <= MAX(5, p_ptr->skill_sav)) dam = 0;
+               if (100 + rlev / 2 <= MAX(5, p_ptr->skill_sav))
+               {
+                       dam = 0;
+                       ignore_wraith_form = TRUE;
+               }
                break;
 
        case GF_CAUSE_1:
        case GF_CAUSE_2:
        case GF_CAUSE_3:
        case GF_HAND_DOOM:
-               if (100 + rlev / 2 <= p_ptr->skill_sav) dam = 0;
+               if (100 + rlev / 2 <= p_ptr->skill_sav)
+               {
+                       dam = 0;
+                       ignore_wraith_form = TRUE;
+               }
                break;
 
        case GF_CAUSE_4:
-               if ((100 + rlev / 2 <= p_ptr->skill_sav) && (m_ptr->r_idx != MON_KENSHIROU)) dam = 0;
+               if ((100 + rlev / 2 <= p_ptr->skill_sav) && (m_ptr->r_idx != MON_KENSHIROU))
+               {
+                       dam = 0;
+                       ignore_wraith_form = TRUE;
+               }
                break;
        }
 
@@ -6559,6 +6814,7 @@ static int blow_damcalc(monster_type *m_ptr, monster_blow *blow_ptr)
 {
        int  dam = blow_ptr->d_dice * blow_ptr->d_side;
        int  dummy_max = 0;
+       bool check_wraith_form = TRUE;
 
        if (blow_ptr->method != RBM_EXPLODE)
        {
@@ -6581,27 +6837,38 @@ static int blow_damcalc(monster_type *m_ptr, monster_blow *blow_ptr)
                case RBE_ACID:
                        spell_damcalc(m_ptr, GF_ACID, dam, 0, &dummy_max);
                        dam = dummy_max;
+                       check_wraith_form = FALSE;
                        break;
 
                case RBE_ELEC:
                        spell_damcalc(m_ptr, GF_ELEC, dam, 0, &dummy_max);
                        dam = dummy_max;
+                       check_wraith_form = FALSE;
                        break;
 
                case RBE_FIRE:
                        spell_damcalc(m_ptr, GF_FIRE, dam, 0, &dummy_max);
                        dam = dummy_max;
+                       check_wraith_form = FALSE;
                        break;
 
                case RBE_COLD:
                        spell_damcalc(m_ptr, GF_COLD, dam, 0, &dummy_max);
                        dam = dummy_max;
+                       check_wraith_form = FALSE;
                        break;
 
                case RBE_DR_MANA:
                        dam = 0;
+                       check_wraith_form = FALSE;
                        break;
                }
+
+               if (check_wraith_form && p_ptr->wraith_form)
+               {
+                       dam /= 2;
+                       if (!dam) dam = 1;
+               }
        }
        else
        {
@@ -6631,7 +6898,6 @@ bool process_warning(int xx, int yy)
                        int dam_max0 = 0;
                        monster_type *m_ptr;
                        monster_race *r_ptr;
-                       u32b f4, f5, f6;
 
                        if (!in_bounds(my, mx) || (distance(my, mx, yy, xx) > WARNING_AWARE_RANGE)) continue;
 
@@ -6641,31 +6907,32 @@ 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];
 
-                       f4 = r_ptr->flags4;
-                       f5 = r_ptr->flags5;
-                       f6 = r_ptr->flags6;
-
                        /* Monster spells (only powerful ones)*/
                        if (projectable(my, mx, yy, xx))
                        {
                                int breath_dam_div3 = m_ptr->hp / 3;
                                int breath_dam_div6 = m_ptr->hp / 6;
+                               u32b f4 = r_ptr->flags4;
+                               u32b f5 = r_ptr->flags5;
+                               u32b f6 = r_ptr->flags6;
 
                                if (!(d_info[dungeon_type].flags1 & DF1_NO_MAGIC))
                                {
                                        int rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1);
                                        int storm_dam = rlev * 4 + 150;
+                                       bool powerful = (bool)(r_ptr->flags2 & RF2_POWERFUL);
 
+                                       if (f4 & RF4_BA_CHAO) spell_damcalc(m_ptr, GF_CHAOS, rlev * (powerful ? 3 : 2) + 100, 0, &dam_max0);
                                        if (f5 & RF5_BA_MANA) spell_damcalc(m_ptr, GF_MANA, storm_dam, 0, &dam_max0);
                                        if (f5 & RF5_BA_DARK) spell_damcalc(m_ptr, GF_DARK, storm_dam, 0, &dam_max0);
                                        if (f5 & RF5_BA_LITE) spell_damcalc(m_ptr, GF_LITE, storm_dam, 0, &dam_max0);
                                        if (f6 & RF6_HAND_DOOM) spell_damcalc(m_ptr, GF_HAND_DOOM, p_ptr->chp * 6 / 10, 0, &dam_max0);
-                                       if (f6 & RF6_PSY_SPEAR) spell_damcalc(m_ptr, GF_PSY_SPEAR, (r_ptr->flags2 & RF2_POWERFUL) ? (rlev * 2 + 150) : (rlev * 3 / 2 + 100), 0, &dam_max0);
+                                       if (f6 & RF6_PSY_SPEAR) spell_damcalc(m_ptr, GF_PSY_SPEAR, powerful ? (rlev * 2 + 150) : (rlev * 3 / 2 + 100), 0, &dam_max0);
                                }
                                if (f4 & RF4_ROCKET) spell_damcalc(m_ptr, GF_ROCKET, m_ptr->hp / 4, 800, &dam_max0);
                                if (f4 & RF4_BR_ACID) spell_damcalc(m_ptr, GF_ACID, breath_dam_div3, 1600, &dam_max0);
@@ -6726,7 +6993,7 @@ bool process_warning(int xx, int yy)
                {
                        object_type *o_ptr = choose_warning_item();
 
-                       if (o_ptr) object_desc(o_name, o_ptr, FALSE, 0);
+                       if (o_ptr) object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
 #ifdef JP
                        else strcpy(o_name, "ÂÎ"); /* Warning ability without item */
                        msg_format("%s¤¬±Ô¤¯¿Ì¤¨¤¿¡ª", o_name);
@@ -6734,23 +7001,23 @@ 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
-                       return get_check("Realy want to go ahead? ");
+                       return get_check("Really want to go ahead? ");
 #endif
                }
        }
        else old_damage = old_damage / 2;
 
        c_ptr = &cave[yy][xx];
-       if (((!easy_disarm && (is_trap(c_ptr->feat) || c_ptr->feat == FEAT_INVIS))
+       if (((!easy_disarm && is_trap(c_ptr->feat))
            || (c_ptr->mimic && is_trap(c_ptr->feat))) && !one_in_(13))
        {
                object_type *o_ptr = choose_warning_item();
 
-               if (o_ptr) object_desc(o_name, o_ptr, FALSE, 0);
+               if (o_ptr) object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
 #ifdef JP
                else strcpy(o_name, "ÂÎ"); /* Warning ability without item */
                msg_format("%s¤¬¿Ì¤¨¤¿¡ª", o_name);
@@ -6758,11 +7025,11 @@ 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
-               return get_check("Realy want to go ahead? ");
+               return get_check("Really want to go ahead? ");
 #endif
        }
 
@@ -6866,7 +7133,7 @@ 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_LEVITATION, "ÉâÍ·", 3, TR_LEVITATION, 20},
        {TR_LITE, "±Êµ×¸÷¸»", 3, TR_LITE, 15},
        {TR_SEE_INVIS, "²Ä»ëÆ©ÌÀ", 3, TR_SEE_INVIS, 20},
        {TR_TELEPATHY, "¥Æ¥ì¥Ñ¥·¡¼", 6, TR_TELEPATHY, 15},
@@ -6929,7 +7196,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},
@@ -6975,7 +7242,7 @@ 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_LEVITATION, "levitation", 3, TR_LEVITATION, 20},
        {TR_LITE, "permanent light", 3, TR_LITE, 15},
        {TR_SEE_INVIS, "see invisible", 3, TR_SEE_INVIS, 20},
        {TR_TELEPATHY, "telepathy", 6, TR_TELEPATHY, 15},
@@ -7148,7 +7415,7 @@ static cptr essence_name[] =
        "",
        "stealth",
        "serching",
-       "inflavision",
+       "infravision",
        "digging",
        "speed",
        "extra atk",
@@ -7275,7 +7542,7 @@ static void drain_essence(void)
        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;
@@ -7285,7 +7552,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 */
@@ -7311,9 +7578,10 @@ 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, FALSE, 0);
+               object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
 #ifdef JP
                if (!get_check(format("ËÜÅö¤Ë%s¤«¤éÃê½Ð¤·¤Æ¤è¤í¤·¤¤¤Ç¤¹¤«¡©", o_name))) return;
 #else
@@ -7342,10 +7610,15 @@ 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_TY_CURSE)) dec--;
 
        iy = o_ptr->iy;
@@ -7362,6 +7635,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);
@@ -7436,7 +7710,7 @@ static void drain_essence(void)
        {
                drain_value[TR_DEX] += 20;
        }
-       if ((o_ptr->tval >= TV_SHOT) && (o_ptr->tval <= TV_SWORD) && (o_ptr->tval != TV_BOW))
+       if (object_is_weapon_ammo(o_ptr))
        {
                if (old_ds > o_ptr->ds) drain_value[TR_ES_ATTACK] += (old_ds-o_ptr->ds)*10;
 
@@ -7460,19 +7734,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;
@@ -7481,10 +7748,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);
 
@@ -7917,11 +8187,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 */
@@ -7947,17 +8217,17 @@ 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("¤½¤Î¥¢¥¤¥Æ¥à¤Ï¤³¤ì°Ê¾å²þÎɤǤ­¤Ê¤¤¡£");
 #else
-               msg_print("This item is no more able to be improved");
+               msg_print("This item is no more able to be improved.");
 #endif
                return;
        }
-       
-       object_desc(o_name, o_ptr, FALSE, 0);
+
+       object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
 
        use_essence = es_ptr->value;
        if ((o_ptr->tval >= TV_SHOT) && (o_ptr->tval <= TV_BOLT)) use_essence = (use_essence+9)/10;
@@ -7985,7 +8255,16 @@ static void add_essence(int mode)
                }
                if (is_pval_flag(es_ptr->add))
                {
-                       if (es_ptr->add == TR_BLOWS)
+                       if (o_ptr->pval < 0)
+                       {
+#ifdef JP
+                               msg_print("¤³¤Î¥¢¥¤¥Æ¥à¤ÎǽÎϽ¤Àµ¤ò¶¯²½¤¹¤ë¤³¤È¤Ï¤Ç¤­¤Ê¤¤¡£");
+#else
+                               msg_print("You cannot increase magic number of this item.");
+#endif
+                               return;
+                       }
+                       else if (es_ptr->add == TR_BLOWS)
                        {
                                if (o_ptr->pval > 1)
                                {
@@ -7995,15 +8274,21 @@ static void add_essence(int mode)
                                        if (!get_check("The magic number of this weapon will become 1. Are you sure? ")) return;
 #endif
                                }
+
                                o_ptr->pval = 1;
+#ifdef JP
+                               msg_format("¥¨¥Ã¥»¥ó¥¹¤ò%d¸Ä»ÈÍѤ·¤Þ¤¹¡£", use_essence);
+#else
+                               msg_format("It will take %d essences.", use_essence);
+#endif
                        }
-                       else if (o_ptr->pval)
+                       else if (o_ptr->pval > 0)
                        {
                                use_essence *= o_ptr->pval;
 #ifdef JP
-                               msg_format("¥¨¥Ã¥»¥ó¥¹¤ò%d¸Ä»ÈÍѤ·¤Þ¤¹¡£",use_essence);
+                               msg_format("¥¨¥Ã¥»¥ó¥¹¤ò%d¸Ä»ÈÍѤ·¤Þ¤¹¡£", use_essence);
 #else
-                               msg_format("It will take %d essences.",use_essence);
+                               msg_format("It will take %d essences.", use_essence);
 #endif
                        }
                        else
@@ -8013,7 +8298,6 @@ static void add_essence(int mode)
                                int pval;
                                int limit = MIN(5, p_ptr->magic_num1[es_ptr->essence]/es_ptr->value);
 
-
 #ifdef JP
                                sprintf(tmp, "¤¤¤¯¤ÄÉղä·¤Þ¤¹¤«¡© (1-%d): ", limit);
 #else
@@ -8025,14 +8309,15 @@ static void add_essence(int mode)
                                pval = atoi(tmp_val);
                                if (pval > limit) pval = limit;
                                else if (pval < 1) pval = 1;
-                               o_ptr->pval = pval;
+                               o_ptr->pval += pval;
                                use_essence *= pval;
 #ifdef JP
-                               msg_format("¥¨¥Ã¥»¥ó¥¹¤ò%d¸Ä»ÈÍѤ·¤Þ¤¹¡£",use_essence);
+                               msg_format("¥¨¥Ã¥»¥ó¥¹¤ò%d¸Ä»ÈÍѤ·¤Þ¤¹¡£", use_essence);
 #else
-                               msg_format("It will take %d essences.",use_essence);
+                               msg_format("It will take %d essences.", use_essence);
 #endif
                        }
+
                        if (p_ptr->magic_num1[es_ptr->essence] < use_essence)
                        {
 #ifdef JP
@@ -8060,16 +8345,16 @@ static void add_essence(int mode)
                        else if (val < 1) val = 1;
                        use_essence *= val;
 #ifdef JP
-                       msg_format("¥¨¥Ã¥»¥ó¥¹¤ò%d¸Ä»ÈÍѤ·¤Þ¤¹¡£",use_essence);
+                       msg_format("¥¨¥Ã¥»¥ó¥¹¤ò%d¸Ä»ÈÍѤ·¤Þ¤¹¡£", use_essence);
 #else
-                       msg_format("It will take %d essences.",use_essence);
+                       msg_format("It will take %d essences.", use_essence);
 #endif
                        if (p_ptr->magic_num1[es_ptr->essence] < use_essence)
                        {
 #ifdef JP
                                msg_print("¥¨¥Ã¥»¥ó¥¹¤¬Â­¤ê¤Ê¤¤¡£");
 #else
-                               msg_print("You don't have enough essences");
+                               msg_print("You don't have enough essences.");
 #endif
                                return;
                        }
@@ -8171,7 +8456,7 @@ static void add_essence(int mode)
 #ifdef JP
                        msg_print("¥¨¥Ã¥»¥ó¥¹¤¬Â­¤ê¤Ê¤¤¡£");
 #else
-                       msg_print("You don't have enough essences");
+                       msg_print("You don't have enough essences.");
 #endif
                        return;
                }
@@ -8204,36 +8489,6 @@ static void add_essence(int mode)
 }
 
 
-static bool item_tester_hook_kaji(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);
-}
-
-
 static void erase_essence(void)
 {
        int item;
@@ -8242,7 +8497,7 @@ static void erase_essence(void)
        char o_name[MAX_NLEN];
        u32b flgs[TR_FLAG_SIZE];
 
-       item_tester_hook = item_tester_hook_kaji;
+       item_tester_hook = object_is_smith;
 
        /* Get an item */
 #ifdef JP
@@ -8267,7 +8522,7 @@ static void erase_essence(void)
                o_ptr = &o_list[0 - item];
        }
 
-       object_desc(o_name, o_ptr, FALSE, 0);
+       object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
 #ifdef JP
        if (!get_check(format("¤è¤í¤·¤¤¤Ç¤¹¤«¡© [%s]", o_name))) return;
 #else
@@ -8290,7 +8545,7 @@ static void erase_essence(void)
 #ifdef JP
        msg_print("¥¨¥Ã¥»¥ó¥¹¤ò¼è¤êµî¤Ã¤¿¡£");
 #else
-       msg_print("You removed all essence you have added");
+       msg_print("You removed all essence you have added.");
 #endif
 
        /* Combine the pack */
@@ -8334,7 +8589,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;
@@ -8488,3 +8743,41 @@ void do_cmd_kaji(bool only_browse)
                case 5: add_essence(10);break;
        }
 }
+
+
+/*
+ * Torches have special abilities when they are flaming.
+ */
+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);
+               }
+       }
+}
+
+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;
+               }
+       }
+}
+
+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;
+       }
+}