OSDN Git Service

2倍幅モード時の店内のアイテム名の描画位置修正.
[hengband/hengband.git] / src / autopick.c
index 5dd8858..7c47979 100644 (file)
 /*
  * Macros for Keywords
  */
-#define FLG_ALL              0
-#define FLG_COLLECTING      1
-#define FLG_UNAWARE         2 
-#define FLG_UNIDENTIFIED     3 
-#define FLG_IDENTIFIED      4 
-#define FLG_STAR_IDENTIFIED  5 
-#define FLG_BOOSTED         6 
-#define FLG_MORE_DICE       7 
-#define FLG_MORE_BONUS      10 
-#define FLG_WORTHLESS       11
-#define FLG_ARTIFACT        12
-#define FLG_EGO                     13
-#define FLG_NAMELESS        14
-#define FLG_RARE            15
-#define FLG_COMMON          16
-#define FLG_WANTED          17
-#define FLG_UNIQUE          18
-#define FLG_HUMAN           19
-#define FLG_UNREADABLE      20
-#define FLG_REALM1          21
-#define FLG_REALM2          22
-#define FLG_FIRST           23
-#define FLG_SECOND          24
-#define FLG_THIRD           25
-#define FLG_FOURTH          26
+#define FLG_ALL              0 
+#define FLG_UNAWARE         1 
+#define FLG_UNIDENTIFIED     2 
+#define FLG_IDENTIFIED      3 
+#define FLG_STAR_IDENTIFIED  4 
+#define FLG_COLLECTING      5 
+#define FLG_ARTIFACT        6 
+#define FLG_EGO                     7 
+#define FLG_GOOD            10
+#define FLG_NAMELESS        11
+#define FLG_AVERAGE         12
+#define FLG_WORTHLESS       13
+#define FLG_RARE            14
+#define FLG_COMMON          15
+#define FLG_BOOSTED         16
+#define FLG_MORE_DICE       17
+#define FLG_MORE_BONUS      18 
+#define FLG_WANTED          19
+#define FLG_UNIQUE          20
+#define FLG_HUMAN           21
+#define FLG_UNREADABLE      22
+#define FLG_REALM1          23
+#define FLG_REALM2          24
+#define FLG_FIRST           25
+#define FLG_SECOND          26
+#define FLG_THIRD           27
+#define FLG_FOURTH          28
 
 #define FLG_ITEMS           30
 #define FLG_WEAPONS         31
 #ifdef JP
 
 static char KEY_ALL[] = "¤¹¤Ù¤Æ¤Î";
-static char KEY_COLLECTING[] = "¼ý½¸Ãæ¤Î";
 static char KEY_UNAWARE[] = "̤ȽÌÀ¤Î";
 static char KEY_UNIDENTIFIED[] = "̤´ÕÄê¤Î";
 static char KEY_IDENTIFIED[] = "´ÕÄêºÑ¤ß¤Î";
 static char KEY_STAR_IDENTIFIED[] = "*´ÕÄê*ºÑ¤ß¤Î";
-static char KEY_BOOSTED[] = "¥À¥¤¥¹Ìܤΰ㤦";
-static char KEY_MORE_THAN[] =  "¥À¥¤¥¹ÌÜ";
-static char KEY_DICE[] =  "°Ê¾å¤Î";
-static char KEY_MORE_BONUS[] =  "½¤ÀµÃÍ";
-static char KEY_MORE_BONUS2[] =  "°Ê¾å¤Î";
-static char KEY_WORTHLESS[] = "̵²ÁÃͤÎ";
+static char KEY_COLLECTING[] = "¼ý½¸Ãæ¤Î";
 static char KEY_ARTIFACT[] = "¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È";
 static char KEY_EGO[] = "¥¨¥´";
+static char KEY_GOOD[] = "¾å¼Á¤Î";
 static char KEY_NAMELESS[] = "̵ÌäÎ";
+static char KEY_AVERAGE[] = "ʤÎ";
+static char KEY_WORTHLESS[] = "̵²ÁÃͤÎ";
 static char KEY_RARE[] = "¥ì¥¢¤Ê";
 static char KEY_COMMON[] = "¤¢¤ê¤Õ¤ì¤¿";
+static char KEY_BOOSTED[] = "¥À¥¤¥¹Ìܤΰ㤦";
+static char KEY_MORE_THAN[] =  "¥À¥¤¥¹ÌÜ";
+static char KEY_DICE[] =  "°Ê¾å¤Î";
+static char KEY_MORE_BONUS[] =  "½¤ÀµÃÍ";
+static char KEY_MORE_BONUS2[] =  "°Ê¾å¤Î";
 static char KEY_WANTED[] = "¾Þ¶â¼ó¤Î";
 static char KEY_UNIQUE[] = "¥æ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼¤Î";
 static char KEY_HUMAN[] = "¿Í´Ö¤Î";
@@ -121,22 +125,24 @@ static char KEY_BOOTS[] = "
 #else 
 
 static char KEY_ALL[] = "all";
-static char KEY_COLLECTING[] = "collecting";
 static char KEY_UNAWARE[] = "unaware";
 static char KEY_UNIDENTIFIED[] = "unidentified";
 static char KEY_IDENTIFIED[] = "identified";
 static char KEY_STAR_IDENTIFIED[] = "*identified*";
-static char KEY_BOOSTED[] = "dice boosted";
-static char KEY_MORE_THAN[] =  "more than";
-static char KEY_DICE[] =  " dice";
-static char KEY_MORE_BONUS[] =  "more bonus than";
-static char KEY_MORE_BONUS2[] =  "";
-static char KEY_WORTHLESS[] = "worthless";
+static char KEY_COLLECTING[] = "collecting";
 static char KEY_ARTIFACT[] = "artifact";
 static char KEY_EGO[] = "ego";
+static char KEY_GOOD[] = "good";
 static char KEY_NAMELESS[] = "nameless";
+static char KEY_AVERAGE[] = "average";
+static char KEY_WORTHLESS[] = "worthless";
 static char KEY_RARE[] = "rare";
 static char KEY_COMMON[] = "common";
+static char KEY_BOOSTED[] = "dice boosted";
+static char KEY_MORE_THAN[] =  "more than";
+static char KEY_DICE[] =  " dice";
+static char KEY_MORE_BONUS[] =  "more bonus than";
+static char KEY_MORE_BONUS2[] =  "";
 static char KEY_WANTED[] = "wanted";
 static char KEY_UNIQUE[] = "unique monster's";
 static char KEY_HUMAN[] = "human";
@@ -351,7 +357,9 @@ static bool autopick_new_entry(autopick_type *entry, cptr str, bool allow_defaul
 
                if (MATCH_KEY(KEY_WORTHLESS)) ADD_FLG(FLG_WORTHLESS);
                if (MATCH_KEY(KEY_EGO)) ADD_FLG(FLG_EGO);
+               if (MATCH_KEY(KEY_GOOD)) ADD_FLG(FLG_GOOD);
                if (MATCH_KEY(KEY_NAMELESS)) ADD_FLG(FLG_NAMELESS);
+               if (MATCH_KEY(KEY_AVERAGE)) ADD_FLG(FLG_AVERAGE);
                if (MATCH_KEY(KEY_RARE)) ADD_FLG(FLG_RARE);
                if (MATCH_KEY(KEY_COMMON)) ADD_FLG(FLG_COMMON);
                if (MATCH_KEY(KEY_WANTED)) ADD_FLG(FLG_WANTED);
@@ -428,134 +436,6 @@ static bool autopick_new_entry(autopick_type *entry, cptr str, bool allow_defaul
 
 
 /*
- * Favorite weapons
- */
-static bool is_favorite(object_type *o_ptr)
-{
-       /* Only melee weapons match */
-       if (!(o_ptr->tval == TV_POLEARM ||
-             o_ptr->tval == TV_SWORD ||
-             o_ptr->tval == TV_DIGGING ||
-             o_ptr->tval == TV_HAFTED))
-       {
-               return FALSE;
-       }
-
-       /* Favorite weapons are varied depend on the class */
-       switch (p_ptr->pclass)
-       {
-       case CLASS_PRIEST:
-       {
-               u32b flgs[TR_FLAG_SIZE];
-               object_flags_known(o_ptr, flgs);
-
-               if (!have_flag(flgs, TR_BLESSED) && 
-                   !(o_ptr->tval == TV_HAFTED))
-                       return FALSE;
-               break;
-       }
-
-       case CLASS_MONK:
-       case CLASS_FORCETRAINER:
-               /* Icky to wield? */
-               if (!(s_info[p_ptr->pclass].w_max[o_ptr->tval-TV_WEAPON_BEGIN][o_ptr->sval]))
-                       return FALSE;
-               break;
-
-       case CLASS_BEASTMASTER:
-       case CLASS_CAVALRY:
-       {
-               u32b flgs[TR_FLAG_SIZE];
-               object_flags_known(o_ptr, flgs);
-
-               /* Is it known to be suitable to using while riding? */
-               if (!(have_flag(flgs, TR_RIDING)))
-                       return FALSE;
-
-               break;
-       }
-
-       case CLASS_NINJA:
-               /* Icky to wield? */
-               if (s_info[p_ptr->pclass].w_max[o_ptr->tval-TV_WEAPON_BEGIN][o_ptr->sval] <= WEAPON_EXP_BEGINNER)
-                       return FALSE;
-               break;
-
-       default:
-               /* All weapons are okay for non-special classes */
-               return TRUE;
-       }
-
-       return TRUE;
-}
-
-
-/*
- * Rare weapons/aromors
- * including Blade of Chaos, Dragon armors, etc.
- */
-static bool is_rare(object_type *o_ptr)
-{
-       switch(o_ptr->tval)
-       {
-       case TV_HAFTED:
-               if (o_ptr->sval == SV_MACE_OF_DISRUPTION ||
-                   o_ptr->sval == SV_WIZSTAFF) return TRUE;
-               break;
-
-       case TV_POLEARM:
-               if (o_ptr->sval == SV_SCYTHE_OF_SLICING ||
-                   o_ptr->sval == SV_DEATH_SCYTHE) return TRUE;
-               break;
-
-       case TV_SWORD:
-               if (o_ptr->sval == SV_BLADE_OF_CHAOS ||
-                   o_ptr->sval == SV_DIAMOND_EDGE ||
-                   o_ptr->sval == SV_DOKUBARI ||
-                   o_ptr->sval == SV_HAYABUSA) return TRUE;
-               break;
-
-       case TV_SHIELD:
-               if (o_ptr->sval == SV_DRAGON_SHIELD ||
-                   o_ptr->sval == SV_MIRROR_SHIELD) return TRUE;
-               break;
-
-       case TV_HELM:
-               if (o_ptr->sval == SV_DRAGON_HELM) return TRUE;
-               break;
-
-       case TV_BOOTS:
-               if (o_ptr->sval == SV_PAIR_OF_DRAGON_GREAVE) return TRUE;
-               break;
-
-       case TV_CLOAK:
-               if (o_ptr->sval == SV_ELVEN_CLOAK ||
-                   o_ptr->sval == SV_ETHEREAL_CLOAK ||
-                   o_ptr->sval == SV_SHADOW_CLOAK) return TRUE;
-               break;
-
-       case TV_GLOVES:
-               if (o_ptr->sval == SV_SET_OF_DRAGON_GLOVES) return TRUE;
-               break;
-
-       case TV_SOFT_ARMOR:
-               if (o_ptr->sval == SV_KUROSHOUZOKU ||
-                   o_ptr->sval == SV_ABUNAI_MIZUGI) return TRUE;
-               break;
-
-       case TV_DRAG_ARMOR:
-               return TRUE;
-
-       default:
-               break;
-       }
-
-       /* Any others are not "rare" objects. */
-       return FALSE;
-}
-
-
-/*
  * Get auto-picker entry from o_ptr.
  */
 static void autopick_entry_from_object(autopick_type *entry, object_type *o_ptr)
@@ -582,14 +462,14 @@ static void autopick_entry_from_object(autopick_type *entry, object_type *o_ptr)
        entry->dice = 0;
 
        /* Unaware */
-       if (!object_aware_p(o_ptr))
+       if (!object_is_aware(o_ptr))
        {
                ADD_FLG(FLG_UNAWARE);
                bol_mark = TRUE;
        }
 
        /* Not really identified */
-       else if (!object_known_p(o_ptr))
+       else if (!object_is_known(o_ptr))
        {
                if (!(o_ptr->ident & IDENT_SENSE))
                {
@@ -639,11 +519,9 @@ static void autopick_entry_from_object(autopick_type *entry, object_type *o_ptr)
        else
        {
                /* Ego objects */
-               if (o_ptr->name2)
-                   
+               if (object_is_ego(o_ptr))
                {
-                       if (TV_WEAPON_BEGIN <= o_ptr->tval &&
-                           o_ptr->tval <= TV_ARMOR_END)
+                       if (object_is_weapon_armour_ammo(o_ptr))
                        {
                                /*
                                 * Base name of ego weapons and armors
@@ -662,26 +540,22 @@ static void autopick_entry_from_object(autopick_type *entry, object_type *o_ptr)
                                /* Don't use the object description */
                                name = FALSE;
 
-                               if (TV_WEAPON_BEGIN <= o_ptr->tval &&
-                                   o_ptr->tval <= TV_ARMOR_END)
-                               {
-                                       /* Restrict to 'common' equipments */
-                                       if (!is_rare(o_ptr)) ADD_FLG(FLG_COMMON);
-                               }
+                               /* Restrict to 'common' equipments */
+                               if (!object_is_rare(o_ptr)) ADD_FLG(FLG_COMMON);
                        }
 
                        ADD_FLG(FLG_EGO);
                }
 
                /* Artifact */
-               else if (o_ptr->name1 || o_ptr->art_name)
+               else if (object_is_artifact(o_ptr))
                        ADD_FLG(FLG_ARTIFACT);
 
                /* Non-ego, non-artifact */
                else
                {
                        /* Wearable nameless object */
-                       if ((TV_EQUIP_BEGIN <= o_ptr->tval && o_ptr->tval <= TV_EQUIP_END))
+                       if (object_is_equipment(o_ptr))
                                ADD_FLG(FLG_NAMELESS);
 
                        bol_mark = TRUE;
@@ -689,17 +563,17 @@ static void autopick_entry_from_object(autopick_type *entry, object_type *o_ptr)
 
        }
 
-
-       switch(o_ptr->tval)
+       /* Melee weapon with boosted dice */
+       if (object_is_melee_weapon(o_ptr))
        {
-               object_kind *k_ptr; 
-       case TV_HAFTED: case TV_POLEARM: case TV_SWORD: case TV_DIGGING:
-               k_ptr = &k_info[o_ptr->k_idx];
+               object_kind *k_ptr = &k_info[o_ptr->k_idx];
+
                if ((o_ptr->dd != k_ptr->dd) || (o_ptr->ds != k_ptr->ds))
                        ADD_FLG(FLG_BOOSTED);
        }
 
-       if (o_ptr->tval == TV_CORPSE && object_is_shoukinkubi(o_ptr))
+       /* Wanted monster's corpse */
+       if (object_is_shoukinkubi(o_ptr))
        {
                REM_FLG(FLG_WORTHLESS);
                ADD_FLG(FLG_WANTED);
@@ -748,8 +622,7 @@ static void autopick_entry_from_object(autopick_type *entry, object_type *o_ptr)
        if (o_ptr->tval >= TV_LIFE_BOOK && 3 == o_ptr->sval)
                ADD_FLG(FLG_FOURTH);
 
-       if (o_ptr->tval == TV_SHOT || o_ptr->tval == TV_BOLT
-                || o_ptr->tval == TV_ARROW)
+       if (object_is_ammo(o_ptr))
                ADD_FLG(FLG_MISSILES);
        else if (o_ptr->tval == TV_SCROLL || o_ptr->tval == TV_STAFF
                 || o_ptr->tval == TV_WAND || o_ptr->tval == TV_ROD)
@@ -868,7 +741,7 @@ static cptr pickpref_filename(int filename_mode)
                return format("%s.prf", namebase);
 
        case PT_WITH_PNAME:
-               return format("%s-%s.prf", namebase, player_name);
+               return format("%s-%s.prf", namebase, player_base);
 
        default:
                return NULL;
@@ -1054,7 +927,9 @@ cptr autopick_line_from_entry(autopick_type *entry)
        if (IS_FLG(FLG_UNIQUE)) ADD_KEY(KEY_UNIQUE);
        if (IS_FLG(FLG_HUMAN)) ADD_KEY(KEY_HUMAN);
        if (IS_FLG(FLG_WORTHLESS)) ADD_KEY(KEY_WORTHLESS);
+       if (IS_FLG(FLG_GOOD)) ADD_KEY(KEY_GOOD);
        if (IS_FLG(FLG_NAMELESS)) ADD_KEY(KEY_NAMELESS);
+       if (IS_FLG(FLG_AVERAGE)) ADD_KEY(KEY_AVERAGE);
        if (IS_FLG(FLG_RARE)) ADD_KEY(KEY_RARE);
        if (IS_FLG(FLG_COMMON)) ADD_KEY(KEY_COMMON);
        if (IS_FLG(FLG_EGO)) ADD_KEY(KEY_EGO);
@@ -1150,41 +1025,35 @@ static bool is_autopick_aux(object_type *o_ptr, autopick_type *entry, cptr o_nam
        cptr ptr = entry->name;
 
        /*** Unaware items ***/
-       if (IS_FLG(FLG_UNAWARE) && object_aware_p(o_ptr))
+       if (IS_FLG(FLG_UNAWARE) && object_is_aware(o_ptr))
                return FALSE;
 
        /*** Unidentified ***/
        if (IS_FLG(FLG_UNIDENTIFIED)
-           && (object_known_p(o_ptr) || (o_ptr->ident & IDENT_SENSE)))
+           && (object_is_known(o_ptr) || (o_ptr->ident & IDENT_SENSE)))
                return FALSE;
 
        /*** Identified ***/
-       if (IS_FLG(FLG_IDENTIFIED) && !object_known_p(o_ptr))
+       if (IS_FLG(FLG_IDENTIFIED) && !object_is_known(o_ptr))
                return FALSE;
 
        /*** *Identified* ***/
        if (IS_FLG(FLG_STAR_IDENTIFIED) &&
-           (!object_known_p(o_ptr) || !(o_ptr->ident & IDENT_MENTAL)))
+           (!object_is_known(o_ptr) || !(o_ptr->ident & IDENT_MENTAL)))
                return FALSE;
 
        /*** Dice boosted (weapon of slaying) ***/
        if (IS_FLG(FLG_BOOSTED))
        {
                object_kind *k_ptr = &k_info[o_ptr->k_idx];
-                       
-               switch( o_ptr->tval )
-               {
-               case TV_HAFTED:
-               case TV_POLEARM:
-               case TV_SWORD:
-               case TV_DIGGING:
-                       if ((o_ptr->dd != k_ptr->dd) || (o_ptr->ds != k_ptr->ds))
-                               break;
-                       else
-                               return FALSE;
-               default:
+
+               /* Require melee weapon */
+               if (!object_is_melee_weapon(o_ptr))
+                       return FALSE;
+
+               /* Require boosted dice */
+               if ((o_ptr->dd == k_ptr->dd) && (o_ptr->ds == k_ptr->ds))
                        return FALSE;
-               }
        }
 
        /*** Weapons which dd*ds is more than nn ***/
@@ -1197,7 +1066,7 @@ static bool is_autopick_aux(object_type *o_ptr, autopick_type *entry, cptr o_nam
        /*** Weapons whic dd*ds is more than nn ***/
        if (IS_FLG(FLG_MORE_BONUS))
        {
-               if (!object_known_p(o_ptr)) return FALSE;
+               if (!object_is_known(o_ptr)) return FALSE;
 
                if (o_ptr->pval)
                {
@@ -1220,7 +1089,7 @@ static bool is_autopick_aux(object_type *o_ptr, autopick_type *entry, cptr o_nam
        /*** Artifact object ***/
        if (IS_FLG(FLG_ARTIFACT))
        {
-               if (!object_known_p(o_ptr) || (!o_ptr->name1 && !o_ptr->art_name))
+               if (!object_is_known(o_ptr) || !object_is_artifact(o_ptr))
                        return FALSE;
        }
 
@@ -1228,25 +1097,64 @@ static bool is_autopick_aux(object_type *o_ptr, autopick_type *entry, cptr o_nam
        if (IS_FLG(FLG_EGO))
        {
                /* Need to be an ego item */
-               if (!o_ptr->name2) return FALSE;
+               if (!object_is_ego(o_ptr)) return FALSE;
 
                /* Need to be known to be an ego */
-               if (!object_known_p(o_ptr) &&
+               if (!object_is_known(o_ptr) &&
                    !((o_ptr->ident & IDENT_SENSE) && o_ptr->feeling == FEEL_EXCELLENT))
                        return FALSE;
        }
 
+       /*** Good ***/
+       if (IS_FLG(FLG_GOOD))
+       {
+               if (!object_is_equipment(o_ptr)) return FALSE;
+
+               /* Identified */
+               if (object_is_known(o_ptr))
+               {
+                       /* Artifacts and Ego objects are not okay */
+                       if (!object_is_nameless(o_ptr))
+                               return FALSE;
+
+                       /* Average are not okay */
+                       if (o_ptr->to_a <= 0 && (o_ptr->to_h + o_ptr->to_d) <= 0)
+                               return FALSE;
+               }
+
+               /* Pseudo-identified */
+               else if (o_ptr->ident & IDENT_SENSE)
+               {
+                       switch (o_ptr->feeling)
+                       {
+                       case FEEL_GOOD:
+                               /* It's good */
+                               break;
+
+                       default:
+                               /* It's not good */
+                               return FALSE;
+                       }
+               }
+
+               /* Unidentified */
+               else
+               {
+                       /* Not known to be good */
+                       return FALSE;
+               }
+       }
+
        /*** Nameless ***/
        if (IS_FLG(FLG_NAMELESS))
        {
-               if (!(TV_EQUIP_BEGIN <= o_ptr->tval && o_ptr->tval <= TV_EQUIP_END))
-                       return FALSE;
+               if (!object_is_equipment(o_ptr)) return FALSE;
 
                /* Identified */
-               if (object_known_p(o_ptr))
+               if (object_is_known(o_ptr))
                {
                        /* Artifacts and Ego objects are not okay */
-                       if (o_ptr->name1 || o_ptr->art_name || o_ptr->name2)
+                       if (!object_is_nameless(o_ptr))
                                return FALSE;
                }
 
@@ -1276,17 +1184,60 @@ static bool is_autopick_aux(object_type *o_ptr, autopick_type *entry, cptr o_nam
                }
        }
 
-       /*** Rere equpiments ***/
-       if (IS_FLG(FLG_RARE) && !is_rare(o_ptr))
+       /*** Average ***/
+       if (IS_FLG(FLG_AVERAGE))
+       {
+               if (!object_is_equipment(o_ptr)) return FALSE;
+
+               /* Identified */
+               if (object_is_known(o_ptr))
+               {
+                       /* Artifacts and Ego objects are not okay */
+                       if (!object_is_nameless(o_ptr))
+                               return FALSE;
+
+                       /* Cursed or broken objects are not okay */
+                       if (object_is_cursed(o_ptr) || object_is_broken(o_ptr))
+                               return FALSE;
+
+                       /* Good are not okay */
+                       if (o_ptr->to_a > 0 || (o_ptr->to_h + o_ptr->to_d) > 0)
+                               return FALSE;
+               }
+
+               /* Pseudo-identified */
+               else if (o_ptr->ident & IDENT_SENSE)
+               {
+                       switch (o_ptr->feeling)
+                       {
+                       case FEEL_AVERAGE:
+                               /* It's average */
+                               break;
+
+                       default:
+                               /* It's not average */
+                               return FALSE;
+                       }
+               }
+
+               /* Unidentified */
+               else
+               {
+                       /* Not known to be average */
+                       return FALSE;
+               }
+       }
+
+       /*** Rere equipments ***/
+       if (IS_FLG(FLG_RARE) && !object_is_rare(o_ptr))
                return FALSE;
 
-       /*** Common equpiments ***/
-       if (IS_FLG(FLG_COMMON) && is_rare(o_ptr))
+       /*** Common equipments ***/
+       if (IS_FLG(FLG_COMMON) && object_is_rare(o_ptr))
                return FALSE;
 
        /*** Wanted monster's corpse/skeletons ***/
-       if (IS_FLG(FLG_WANTED) &&
-           (o_ptr->tval != TV_CORPSE || !object_is_shoukinkubi(o_ptr)))
+       if (IS_FLG(FLG_WANTED) && !object_is_shoukinkubi(o_ptr))
                return FALSE;
 
        /*** Unique monster's corpse/skeletons/statues ***/
@@ -1344,27 +1295,22 @@ static bool is_autopick_aux(object_type *o_ptr, autopick_type *entry, cptr o_nam
        /*** Items ***/
        if (IS_FLG(FLG_WEAPONS))
        {
-               if (!(TV_WEAPON_BEGIN <= o_ptr->tval && o_ptr->tval <= TV_WEAPON_END))
+               if (!object_is_weapon(o_ptr))
                        return FALSE;
        }
        else if (IS_FLG(FLG_FAVORITE_WEAPONS))
        {
-               if (!is_favorite(o_ptr))
+               if (!object_is_favorite(o_ptr))
                        return FALSE;
        }
        else if (IS_FLG(FLG_ARMORS))
        {
-               if (!(TV_ARMOR_BEGIN <= o_ptr->tval && o_ptr->tval <= TV_ARMOR_END))
+               if (!object_is_armour(o_ptr))
                        return FALSE;
        }
        else if (IS_FLG(FLG_MISSILES))
        {
-               switch(o_ptr->tval)
-               {
-               case TV_SHOT: case TV_BOLT: case TV_ARROW:
-                       break;
-               default: return FALSE;
-               }
+               if (!object_is_ammo(o_ptr)) return FALSE;
        }
        else if (IS_FLG(FLG_DEVICES))
        {
@@ -1544,22 +1490,21 @@ static bool is_opt_confirm_destroy(object_type *o_ptr)
        /* Known to be worthless? */
        if (leave_worth)
                if (object_value(o_ptr) > 0) return FALSE;
-       
+
        if (leave_equip)
-               if ((o_ptr->tval >= TV_MISSILE_BEGIN) && (o_ptr->tval <= TV_ARMOR_END)) return FALSE;
-       
+               if (object_is_weapon_armour_ammo(o_ptr)) return FALSE;
+
        if (leave_chest)
                if ((o_ptr->tval == TV_CHEST) && o_ptr->pval) return FALSE;
-       
+
        if (leave_wanted)
        {
-               if (o_ptr->tval == TV_CORPSE
-                   && object_is_shoukinkubi(o_ptr)) return FALSE;
+               if (object_is_shoukinkubi(o_ptr)) return FALSE;
        }
-       
+
        if (leave_corpse)
                if (o_ptr->tval == TV_CORPSE) return FALSE;
-       
+
        if (leave_junk)
                if ((o_ptr->tval == TV_SKELETON) || (o_ptr->tval == TV_BOTTLE) || (o_ptr->tval == TV_JUNK) || (o_ptr->tval == TV_STATUE)) return FALSE;
 
@@ -1582,20 +1527,20 @@ static bool is_opt_confirm_destroy(object_type *o_ptr)
                else if (p_ptr->pclass == CLASS_NINJA)
                {
                        if (o_ptr->tval == TV_LITE &&
-                           o_ptr->name2 == EGO_LITE_DARKNESS)
+                           o_ptr->name2 == EGO_LITE_DARKNESS && object_is_known(o_ptr))
                                return FALSE;
                }
                else if (p_ptr->pclass == CLASS_BEASTMASTER ||
                         p_ptr->pclass == CLASS_CAVALRY)
                {
                        if (o_ptr->tval == TV_WAND &&
-                           o_ptr->sval == SV_WAND_HEAL_MONSTER)
+                           o_ptr->sval == SV_WAND_HEAL_MONSTER && object_is_aware(o_ptr))
                                return FALSE;
                }
        }
-       
+
        if (o_ptr->tval == TV_GOLD) return FALSE;
-       
+
        return TRUE;
 }
 
@@ -1679,7 +1624,7 @@ static void autopick_delayed_alter_aux(int item)
        /* Get the item (on the floor) */
        else o_ptr = &o_list[0 - item];
 
-       if (o_ptr->k_idx && o_ptr->marked & OM_AUTODESTROY)
+       if (o_ptr->k_idx && (o_ptr->marked & OM_AUTODESTROY))
        {
                char o_name[MAX_NLEN];
 
@@ -2022,8 +1967,7 @@ bool autopick_autoregister(object_type *o_ptr)
        }
 
        /* Known to be an artifact? */
-       if ((object_known_p(o_ptr) &&
-            (artifact_p(o_ptr) || o_ptr->art_name)) ||
+       if ((object_is_known(o_ptr) && object_is_artifact(o_ptr)) ||
            ((o_ptr->ident & IDENT_SENSE) &&
             (o_ptr->feeling == FEEL_TERRIBLE || o_ptr->feeling == FEEL_SPECIAL)))
        {
@@ -2293,6 +2237,13 @@ static void describe_autopick(char *buff, autopick_type *entry)
                body_str = "ÁõÈ÷";
        }
 
+       /*** Good ***/
+       if (IS_FLG(FLG_GOOD))
+       {
+               before_str[before_n++] = "¾å¼Á¤Î";
+               body_str = "ÁõÈ÷";
+       }
+
        /*** Nameless ***/
        if (IS_FLG(FLG_NAMELESS))
        {
@@ -2300,14 +2251,21 @@ static void describe_autopick(char *buff, autopick_type *entry)
                body_str = "ÁõÈ÷";
        }
 
-       /*** Rare equpiments ***/
+       /*** Average ***/
+       if (IS_FLG(FLG_AVERAGE))
+       {
+               before_str[before_n++] = "ʤÎ";
+               body_str = "ÁõÈ÷";
+       }
+
+       /*** Rare equipments ***/
        if (IS_FLG(FLG_RARE))
        {
                before_str[before_n++] = "¥É¥é¥´¥óÁõÈ÷¤ä¥«¥ª¥¹¡¦¥Ö¥ì¡¼¥ÉÅù¤ò´Þ¤àÄÁ¤·¤¤";
                body_str = "ÁõÈ÷";
        }
 
-       /*** Common equpiments ***/
+       /*** Common equipments ***/
        if (IS_FLG(FLG_COMMON))
        {
                before_str[before_n++] = "¤¢¤ê¤Õ¤ì¤¿(¥É¥é¥´¥óÁõÈ÷¤ä¥«¥ª¥¹¡¦¥Ö¥ì¡¼¥ÉÅù¤ÎÄÁ¤·¤¤Êª¤Ç¤Ï¤Ê¤¤)";
@@ -2520,7 +2478,7 @@ static void describe_autopick(char *buff, autopick_type *entry)
        if (IS_FLG(FLG_STAR_IDENTIFIED))
                before_str[before_n++] = "fully identified";
 
-       /*** Rare equpiments ***/
+       /*** Rare equipments ***/
        if (IS_FLG(FLG_RARE))
        {
                before_str[before_n++] = "very rare";
@@ -2528,7 +2486,7 @@ static void describe_autopick(char *buff, autopick_type *entry)
                after_str[after_n++] = "such like Dragon armors, Blades of Chaos, etc.";
        }
 
-       /*** Common equpiments ***/
+       /*** Common equipments ***/
        if (IS_FLG(FLG_COMMON))
        {
                before_str[before_n++] = "relatively common";
@@ -2555,6 +2513,13 @@ static void describe_autopick(char *buff, autopick_type *entry)
                before_str[before_n++] = "ego";
        }
 
+       /*** Good ***/
+       if (IS_FLG(FLG_GOOD))
+       {
+               body_str = "equipment";
+               which_str[which_n++] = "have good quality";
+       }
+
        /*** Nameless ***/
        if (IS_FLG(FLG_NAMELESS))
        {
@@ -2562,6 +2527,13 @@ static void describe_autopick(char *buff, autopick_type *entry)
                which_str[which_n++] = "is neither ego-item nor artifact";
        }
 
+       /*** Average ***/
+       if (IS_FLG(FLG_AVERAGE))
+       {
+               body_str = "equipment";
+               which_str[which_n++] = "have average quality";
+       }
+
        /*** Dice boosted (weapon of slaying) ***/
        if (IS_FLG(FLG_BOOSTED))
        {
@@ -3067,10 +3039,10 @@ static void toggle_keyword(text_body_type *tb, int flg)
                }
                
                /* You can use only one flag in artifact/ego/nameless */
-               else if (FLG_ARTIFACT <= flg && flg <= FLG_NAMELESS)
+               else if (FLG_ARTIFACT <= flg && flg <= FLG_AVERAGE)
                {
                        int i;
-                       for (i = FLG_ARTIFACT; i <= FLG_NAMELESS; i++)
+                       for (i = FLG_ARTIFACT; i <= FLG_AVERAGE; i++)
                                REM_FLG(i);
                }
                
@@ -3258,6 +3230,36 @@ static void check_expression_line(text_body_type *tb, int y)
 
 
 /*
+ * Add an empty line at the last of the file
+ */
+static bool add_empty_line(text_body_type *tb)
+{
+       int k;
+
+       for (k = 0; tb->lines_list[k]; k++)
+               /* count number of lines */ ;
+
+       /* Too many lines! */
+       if (k >= MAX_LINES - 2) return FALSE;
+
+       /* The last line is already empty */
+       if (!tb->lines_list[k-1][0]) return FALSE;
+
+       /* Create new empty line */
+       tb->lines_list[k] = string_make("");
+
+       /* Expressions need re-evaluation */
+       tb->dirty_flags |= DIRTY_EXPRESSION;
+
+       /* Text is changed */
+       tb->changed = TRUE;
+
+       /* A line is added */
+       return TRUE;
+}
+
+
+/*
  * Insert return code and split the line
  */
 static bool insert_return_code(text_body_type *tb)
@@ -3901,37 +3903,39 @@ static void search_for_string(text_body_type *tb, cptr search_str, bool forward)
 #define EC_OK_WORTHLESS               46
 #define EC_OK_ARTIFACT        47
 #define EC_OK_EGO             48
-#define EC_OK_NAMELESS        49
-#define EC_OK_RARE            50       
-#define EC_OK_COMMON          51
-#define EC_OK_WANTED          52
-#define EC_OK_UNIQUE          53
-#define EC_OK_HUMAN           54
-#define EC_OK_UNREADABLE       55
-#define EC_OK_REALM1          56
-#define EC_OK_REALM2          57
-#define EC_OK_FIRST           58
-#define EC_OK_SECOND          59
-#define EC_OK_THIRD           60
-#define EC_OK_FOURTH          61
-#define EC_KK_WEAPONS         62
-#define EC_KK_FAVORITE_WEAPONS 63
-#define EC_KK_ARMORS          64
-#define EC_KK_MISSILES        65
-#define EC_KK_DEVICES         66
-#define EC_KK_LIGHTS          67
-#define EC_KK_JUNKS           68
-#define EC_KK_CORPSES         69
-#define EC_KK_SPELLBOOKS       70
-#define EC_KK_SHIELDS         71
-#define EC_KK_BOWS            72
-#define EC_KK_RINGS           73
-#define EC_KK_AMULETS         74
-#define EC_KK_SUITS           75
-#define EC_KK_CLOAKS          76
-#define EC_KK_HELMS           77
-#define EC_KK_GLOVES          78
-#define EC_KK_BOOTS           79
+#define EC_OK_GOOD            49
+#define EC_OK_NAMELESS        50
+#define EC_OK_AVERAGE         51
+#define EC_OK_RARE            52       
+#define EC_OK_COMMON          53
+#define EC_OK_WANTED          54
+#define EC_OK_UNIQUE          55
+#define EC_OK_HUMAN           56
+#define EC_OK_UNREADABLE       57
+#define EC_OK_REALM1          58
+#define EC_OK_REALM2          59
+#define EC_OK_FIRST           60
+#define EC_OK_SECOND          61
+#define EC_OK_THIRD           62
+#define EC_OK_FOURTH          63
+#define EC_KK_WEAPONS         64
+#define EC_KK_FAVORITE_WEAPONS 65
+#define EC_KK_ARMORS          66
+#define EC_KK_MISSILES        67
+#define EC_KK_DEVICES         68
+#define EC_KK_LIGHTS          69
+#define EC_KK_JUNKS           70
+#define EC_KK_CORPSES         71
+#define EC_KK_SPELLBOOKS       72
+#define EC_KK_SHIELDS         73
+#define EC_KK_BOWS            74
+#define EC_KK_RINGS           75
+#define EC_KK_AMULETS         76
+#define EC_KK_SUITS           77
+#define EC_KK_CLOAKS          78
+#define EC_KK_HELMS           79
+#define EC_KK_GLOVES          80
+#define EC_KK_BOOTS           81
 
 
 /* Manu names */
@@ -3986,16 +3990,13 @@ static char MN_CL_QUERY[] = "
 static char MN_CL_NO_DISP[] = "¡Ö(¡× (¥Þ¥Ã¥×¥³¥Þ¥ó¥É¤Çɽ¼¨¤·¤Ê¤¤)";
 
 static char MN_ADJECTIVE_GEN[] = "·ÁÍÆ»ì(°ìÈÌ)¤ÎÁªÂò";
+static char MN_RARE[] = "¥ì¥¢¤Ê (ÁõÈ÷)";
+static char MN_COMMON[] = "¤¢¤ê¤Õ¤ì¤¿ (ÁõÈ÷)";
 
 static char MN_ADJECTIVE_SPECIAL[] = "·ÁÍÆ»ì(Æüì)¤ÎÁªÂò";
 static char MN_BOOSTED[] = "¥À¥¤¥¹Ìܤΰ㤦 (Éð´ï)";
 static char MN_MORE_DICE[] = "¥À¥¤¥¹ÌÜ # °Ê¾å¤Î (Éð´ï)";
 static char MN_MORE_BONUS[] = "½¤ÀµÃÍ # °Ê¾å¤Î (»ØÎØÅù)";
-static char MN_ARTIFACT[] = "¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È (ÁõÈ÷)";
-static char MN_EGO[] = "¥¨¥´ (ÁõÈ÷)";
-static char MN_NAMELESS[] = "̵ÌäΠ(ÁõÈ÷)";
-static char MN_RARE[] = "¥ì¥¢¤Ê (ÁõÈ÷)";
-static char MN_COMMON[] = "¤¢¤ê¤Õ¤ì¤¿ (ÁõÈ÷)";
 static char MN_WANTED[] = "¾Þ¶â¼ó¤Î (»àÂÎ)";
 static char MN_UNIQUE[] = "¥æ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼¤Î (»àÂÎ)";
 static char MN_HUMAN[] = "¿Í´Ö¤Î (»àÂÎ)";
@@ -4060,16 +4061,13 @@ static char MN_CL_QUERY[] = "';' (Query to pick up)";
 static char MN_CL_NO_DISP[] = "'(' (No display on the large map)";
 
 static char MN_ADJECTIVE_GEN[] = "Adjective (general)";
+static char MN_RARE[] = "rare (equipments)";
+static char MN_COMMON[] = "common (equipments)";
 
 static char MN_ADJECTIVE_SPECIAL[] = "Adjective (special)";
 static char MN_BOOSTED[] = "dice boosted (weapons)";
 static char MN_MORE_DICE[] = "more than # dice (weapons)";
 static char MN_MORE_BONUS[] = "more bonus than # (rings etc.)";
-static char MN_ARTIFACT[] = "artifact (equipments)";
-static char MN_EGO[] = "ego (equipments)";
-static char MN_NAMELESS[] = "nameless (equipments)";
-static char MN_RARE[] = "rare (equipments)";
-static char MN_COMMON[] = "common (equipments)";
 static char MN_WANTED[] = "wanted (corpse)";
 static char MN_UNIQUE[] = "unique (corpse)";
 static char MN_HUMAN[] = "human (corpse)";
@@ -4144,17 +4142,19 @@ command_menu_type menu_data[] =
        {KEY_IDENTIFIED, 1, -1, EC_IK_IDENTIFIED},
        {KEY_STAR_IDENTIFIED, 1, -1, EC_IK_STAR_IDENTIFIED},
        {KEY_COLLECTING, 1, -1, EC_OK_COLLECTING},
+       {KEY_ARTIFACT, 1, -1, EC_OK_ARTIFACT},
+       {KEY_EGO, 1, -1, EC_OK_EGO},
+       {KEY_GOOD, 1, -1, EC_OK_GOOD},
+       {KEY_NAMELESS, 1, -1, EC_OK_NAMELESS},
+       {KEY_AVERAGE, 1, -1, EC_OK_AVERAGE},
        {KEY_WORTHLESS, 1, -1, EC_OK_WORTHLESS},
+       {MN_RARE, 1, -1, EC_OK_RARE},
+       {MN_COMMON, 1, -1, EC_OK_COMMON},
 
        {MN_ADJECTIVE_SPECIAL, 0, -1, -1},
        {MN_BOOSTED, 1, -1, EC_OK_BOOSTED},
        {MN_MORE_DICE, 1, -1, EC_OK_MORE_DICE},
        {MN_MORE_BONUS, 1, -1, EC_OK_MORE_BONUS},
-       {MN_ARTIFACT, 1, -1, EC_OK_ARTIFACT},
-       {MN_EGO, 1, -1, EC_OK_EGO},
-       {MN_NAMELESS, 1, -1, EC_OK_NAMELESS},
-       {MN_RARE, 1, -1, EC_OK_RARE},
-       {MN_COMMON, 1, -1, EC_OK_COMMON},
        {MN_WANTED, 1, -1, EC_OK_WANTED},
        {MN_UNIQUE, 1, -1, EC_OK_UNIQUE},
        {MN_HUMAN, 1, -1, EC_OK_HUMAN},
@@ -4424,6 +4424,91 @@ static void add_str_to_yank(text_body_type *tb, cptr str)
 }
 
 
+/*
+ * Do work for the copy editor-command
+ */
+static void copy_text_to_yank(text_body_type *tb)
+{
+       int len = strlen(tb->lines_list[tb->cy]);
+
+       /* Correct cursor location */
+       if (tb->cx > len) tb->cx = len;
+
+       /* Use single line? */
+       if (!tb->mark)
+       {
+               /* Select a single line */
+               tb->cx = 0;
+               tb->my = tb->cy;
+               tb->mx = len;
+       }
+
+       /* Kill old yank buffer */
+       kill_yank_chain(tb);
+
+
+       /* Single line case */
+       if (tb->my == tb->cy)
+       {
+               int i;
+               char buf[MAX_LINELEN];
+               int bx1 = MIN(tb->mx, tb->cx);
+               int bx2 = MAX(tb->mx, tb->cx);
+
+               /* Correct fake cursor position */
+               if (bx2 > len) bx2 = len;
+
+               /* Whole part of this line is selected */
+               if (bx1 == 0 && bx2 == len)
+               {
+                       /* Copy this line */
+                       add_str_to_yank(tb, tb->lines_list[tb->cy]);
+
+                       /* Add end of line to the buffer */
+                       add_str_to_yank(tb, "");
+               }
+
+               /* Segment of this line is selected */
+               else
+               {
+                       for (i = 0; i < bx2 - bx1; i++)
+                       {
+                               buf[i] = tb->lines_list[tb->cy][bx1 + i];
+                       }
+                       buf[i] = '\0';
+
+                       /* Copy this segment of line */
+                       add_str_to_yank(tb, buf);
+               }
+       }
+
+       /* Multiple lines case */
+       else /* if (tb->my != tb->cy) */
+       {
+               int y;
+
+               int by1 = MIN(tb->my, tb->cy);
+               int by2 = MAX(tb->my, tb->cy);
+
+               /* Copy lines */
+               for (y = by1; y <= by2; y++)
+               {
+                       /* Copy this line */
+                       add_str_to_yank(tb, tb->lines_list[y]);
+               }
+
+               /* Add final end of line to the buffer */
+               add_str_to_yank(tb, "");
+       }
+
+       /* Disable selection */
+       tb->mark = 0;
+
+       /* Now dirty */
+       tb->dirty_flags |= DIRTY_ALL;
+}
+
+
 #define DESCRIPT_HGT 3
 
 /*
@@ -4451,7 +4536,12 @@ static void draw_text_editor(text_body_type *tb)
                        i++;
                        if (i == tb->cx)
                        {
-                               tb->cx--;
+                               /*
+                                * Move to a correct position in the
+                                * left or right
+                                */
+                               if (i & 1) tb->cx--;
+                               else tb->cx++;
                                break;
                        }
                }
@@ -4509,6 +4599,8 @@ static void draw_text_editor(text_body_type *tb)
                        char f;
                        cptr v;
                        cptr s = tb->lines_list[y];
+                       char *ss, *s_keep;
+                       int s_len;
 
                        /* Update this line's state */
                        tb->states[y] = state;
@@ -4520,8 +4612,15 @@ static void draw_text_editor(text_body_type *tb)
                        if (streq(s, "$AUTOREGISTER"))
                                state |= LSTAT_AUTOREGISTER;
 
+                       s_len = strlen(s);
+                       ss = (char *)string_make(s);
+                       s_keep = ss;
+
                        /* Parse the expr */
-                       v = process_pref_file_expr(&s, &f);
+                       v = process_pref_file_expr(&ss, &f);
+
+                       /* Cannot use string_free() because the string was "destroyed" */
+                       C_FREE(s_keep, s_len + 1, char);
 
                        /* Set flag */
                        if (streq(v, "0")) state |= LSTAT_BYPASS;
@@ -4536,12 +4635,6 @@ static void draw_text_editor(text_body_type *tb)
 
        if (tb->mark)
        {
-               int tmp_cx = tb->cx;
-               int len = strlen(tb->lines_list[tb->cy]);
-
-               /* Correct cursor location */
-               if (tb->cx > len) tmp_cx = len;
-
                tb->dirty_flags |= DIRTY_ALL;
 
                by1 = MIN(tb->my, tb->cy);
@@ -4996,10 +5089,22 @@ static bool insert_keymap_line(text_body_type *tb)
        /* Look up the keymap */
        act = keymap_act[mode][(byte)(buf[0])];
 
+       if (act)
+       {
+               /* Analyze the current action */
+               ascii_to_text(tmp, act);
+       }
+       else
+       {
+               /* No keymap defined -- Use trigger key itself as a default */
+
+               /* Nothing to do (use tmp) */
+       }
+
        /* Insert blank action preference line */
        insert_return_code(tb);
        string_free(tb->lines_list[tb->cy]);
-       tb->lines_list[tb->cy] = string_make(format("A:%s", act));
+       tb->lines_list[tb->cy] = string_make(format("A:%s", tmp));
 
        return TRUE;
 }
@@ -5081,10 +5186,30 @@ static bool do_editor_command(text_body_type *tb, int com_id)
                if (0 < tb->cx)
                {
                        int len;
+#ifdef JP
+                       int i;
+#endif
 
                        tb->cx--;
                        len = strlen(tb->lines_list[tb->cy]);
                        if (len < tb->cx) tb->cx = len;
+
+#ifdef JP
+                       /* Don't let cursor at second byte of kanji */
+                       for (i = 0; tb->lines_list[tb->cy][i]; i++)
+                       {
+                               if (iskanji(tb->lines_list[tb->cy][i]))
+                               {
+                                       i++;
+                                       if (i == tb->cx)
+                                       {
+                                               /* Move to the left */
+                                               tb->cx--;
+                                               break;
+                                       }
+                               }
+                       }
+#endif
                }
                else if (tb->cy > 0)
                {
@@ -5095,7 +5220,17 @@ static bool do_editor_command(text_body_type *tb, int com_id)
 
        case EC_DOWN:
                /* Next line */
-               if (tb->lines_list[tb->cy + 1]) tb->cy++;
+
+               /* Is this the last line? */
+               if (!tb->lines_list[tb->cy + 1])
+               {
+                       /* Add one more empty line if possible */
+                       if (!add_empty_line(tb)) break;
+               }
+
+               /* Go down */
+               tb->cy++;
+
                break;
 
        case EC_UP:
@@ -5115,13 +5250,19 @@ static bool do_editor_command(text_body_type *tb, int com_id)
                len = strlen(tb->lines_list[tb->cy]);
                if (len < tb->cx)
                {
-                       if (tb->lines_list[tb->cy + 1])
+                       /* Correct the cursor position */
+                       tb->cx = len;
+
+                       /* Is this the last line? */
+                       if (!tb->lines_list[tb->cy + 1])
                        {
-                               tb->cy++;
-                               tb->cx = 0;
+                               /* Add one more empty line if possible */
+                               if (!add_empty_line(tb)) break;
                        }
-                       else
-                               tb->cx = len;
+
+                       /* Move to the beginning of next line */
+                       tb->cy++;
+                       tb->cx = 0;
                }
                break;
        }
@@ -5145,8 +5286,18 @@ static bool do_editor_command(text_body_type *tb, int com_id)
 
        case EC_PGDOWN:
                /* Page down */
-               while (tb->cy < tb->upper + tb->hgt && tb->lines_list[tb->cy + 1])
+               while (tb->cy < tb->upper + tb->hgt)
+               {
+                       /* Is this the last line? */
+                       if (!tb->lines_list[tb->cy + 1])
+                       {
+                               /* Add one more empty line if possible */
+                               if (!add_empty_line(tb)) break;
+                       }
+
                        tb->cy++;
+               }
+
                tb->upper = tb->cy;
                break;
 
@@ -5155,14 +5306,27 @@ static bool do_editor_command(text_body_type *tb, int com_id)
                break;
 
        case EC_BOTTOM:
-               while (tb->lines_list[tb->cy + 1])
+               while (TRUE)
+               {
+                       /* Is this the last line? */
+                       if (!tb->lines_list[tb->cy + 1])
+                       {
+                               /* Add one more empty line if possible */
+                               if (!add_empty_line(tb)) break;
+                       }
+
                        tb->cy++;
+               }
+
+               /* Always at the biginning of the last line */
+               tb->cx = 0;
+
                break;
 
        case EC_CUT:
        {       
                /* Copy the text first */
-               do_editor_command(tb, EC_COPY);
+               copy_text_to_yank(tb);
 
                /* Single line case */
                if (tb->my == tb->cy)
@@ -5208,90 +5372,58 @@ static bool do_editor_command(text_body_type *tb, int com_id)
                /* Now dirty */
                tb->dirty_flags |= DIRTY_ALL;
 
+               /* Text is changed */
+               tb->changed = TRUE;
+
                break;
        }
 
        case EC_COPY:
-       {       
-               int len = strlen(tb->lines_list[tb->cy]);
-
-               /* Correct cursor location */
-               if (tb->cx > len) tb->cx = len;
-
-               /* Use single line? */
-               if (!tb->mark)
-               {
-                       /* Select a single line */
-                       tb->cx = 0;
-                       tb->my = tb->cy;
-                       tb->mx = len;
-               }
-
-               /* Kill old yank buffer */
-               kill_yank_chain(tb);
-
+               copy_text_to_yank(tb);
 
-               /* Single line case */
+               /*
+                * Move cursor position to the end of the selection
+                *
+                * Pressing ^C ^V correctly duplicates the selection.
+                */
                if (tb->my == tb->cy)
                {
-                       int i;
-                       char buf[MAX_LINELEN];
-                       int bx1 = MIN(tb->mx, tb->cx);
-                       int bx2 = MAX(tb->mx, tb->cx);
-
-                       /* Correct fake cursor position */
-                       if (bx2 > len) bx2 = len;
+                       tb->cx = MAX(tb->cx, tb->mx);
 
-                       /* Whole part of this line is selected */
-                       if (bx1 == 0 && bx2 == len)
+                       /*
+                        * When whole line is selected, the end of
+                        * line code is also copyed.
+                        */
+                       if (!tb->lines_list[tb->cy][tb->cx])
                        {
-                               /* Copy this line */
-                               add_str_to_yank(tb, tb->lines_list[tb->cy]);
-
-                               /* Add end of line to the buffer */
-                               add_str_to_yank(tb, "");
-                       }
-
-                       /* Segment of this line is selected */
-                       else
-                       {
-                               for (i = 0; i < bx2 - bx1; i++)
+                               /* Is this the last line? */
+                               if (!tb->lines_list[tb->cy + 1])
                                {
-                                       buf[i] = tb->lines_list[tb->cy][bx1 + i];
+                                       /* Add one more empty line if possible */
+                                       if (!add_empty_line(tb)) break;
                                }
-                               buf[i] = '\0';
 
-                               /* Copy this segment of line */
-                               add_str_to_yank(tb, buf);
+                               /* Go to the beginning of next line */
+                               tb->cy++;
+                               tb->cx = 0;
                        }
                }
-
-               /* Multiple lines case */
-               else /* if (tb->my != tb->cy) */
+               else
                {
-                       int y;
-
-                       int by1 = MIN(tb->my, tb->cy);
-                       int by2 = MAX(tb->my, tb->cy);
+                       tb->cy = MAX(tb->cy, tb->my);
 
-                       /* Copy lines */
-                       for (y = by1; y <= by2; y++)
+                       /* Is this the last line? */
+                       if (!tb->lines_list[tb->cy + 1])
                        {
-                               /* Copy this line */
-                               add_str_to_yank(tb, tb->lines_list[y]);
+                               /* Add one more empty line if possible */
+                               if (!add_empty_line(tb)) break;
                        }
 
-                       /* Add final end of line to the buffer */
-                       add_str_to_yank(tb, "");
+                       /* Go down */
+                       tb->cy++;
                }
 
-               /* Disable selection */
-               tb->mark = 0;
-
-               /* Now dirty */
-               tb->dirty_flags |= DIRTY_ALL;
                break;
-       }
 
        case EC_PASTE:
        {
@@ -5834,7 +5966,9 @@ static bool do_editor_command(text_body_type *tb, int com_id)
        case EC_OK_WORTHLESS: toggle_keyword(tb, FLG_WORTHLESS); break;
        case EC_OK_ARTIFACT: toggle_keyword(tb, FLG_ARTIFACT); break;
        case EC_OK_EGO: toggle_keyword(tb, FLG_EGO); break;
+       case EC_OK_GOOD: toggle_keyword(tb, FLG_GOOD); break;
        case EC_OK_NAMELESS: toggle_keyword(tb, FLG_NAMELESS); break;
+       case EC_OK_AVERAGE: toggle_keyword(tb, FLG_AVERAGE); break;
        case EC_OK_RARE: toggle_keyword(tb, FLG_RARE); break;
        case EC_OK_COMMON: toggle_keyword(tb, FLG_COMMON); break;
        case EC_OK_WANTED: toggle_keyword(tb, FLG_WANTED); break;
@@ -6049,6 +6183,11 @@ void do_cmd_edit_autopick(void)
        tb->dirty_line = -1;
        tb->filename_mode = PT_DEFAULT;
 
+       if (turn < old_autosave_turn)
+       {
+               while (old_autosave_turn > turn) old_autosave_turn -= TURNS_PER_TICK * TOWN_DAWN;
+       }
+
        /* Autosave */
        if (turn > old_autosave_turn + 100L)
        {