+ int next = o_list[item].next_o_idx;
+ delayed_auto_destroy_aux(-item);
+ item = next;
+ }
+}
+
+
+/*
+ * Automatically pickup/destroy items in this grid.
+ */
+void auto_pickup_items(cave_type *c_ptr)
+{
+ s16b this_o_idx, next_o_idx = 0;
+
+ /* Scan the pile of objects */
+ for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
+ {
+ int idx;
+
+ /* Acquire object */
+ object_type *o_ptr = &o_list[this_o_idx];
+
+ /* Acquire next object */
+ next_o_idx = o_ptr->next_o_idx;
+
+ idx = is_autopick(o_ptr);
+
+ /* Item index for floor -1,-2,-3,... */
+ auto_inscribe_item((-this_o_idx), idx);
+
+ if (idx >= 0 &&
+ (autopick_list[idx].action & (DO_AUTOPICK | DO_QUERY_AUTOPICK)))
+ {
+ disturb(0,0);
+
+ if (!inven_carry_okay(o_ptr))
+ {
+ char o_name[MAX_NLEN];
+
+ /* Describe the object */
+ object_desc(o_name, o_ptr, TRUE, 3);
+
+ /* Message */
+#ifdef JP
+ msg_format("¥¶¥Ã¥¯¤Ë¤Ï%s¤òÆþ¤ì¤ë·ä´Ö¤¬¤Ê¤¤¡£", o_name);
+#else
+ msg_format("You have no room for %s.", o_name);
+#endif
+ /* Hack - remember that the item has given a message here. */
+ o_ptr->marked |= OM_NOMSG;
+
+ continue;
+ }
+ else if (autopick_list[idx].action & DO_QUERY_AUTOPICK)
+ {
+ char out_val[MAX_NLEN+20];
+ char o_name[MAX_NLEN];
+
+ if (o_ptr->marked & OM_NO_QUERY)
+ {
+ /* Already answered as 'No' */
+ continue;
+ }
+
+ /* Describe the object */
+ object_desc(o_name, o_ptr, TRUE, 3);
+
+#ifdef JP
+ sprintf(out_val, "%s¤ò½¦¤¤¤Þ¤¹¤«? ", o_name);
+#else
+ sprintf(out_val, "Pick up %s? ", o_name);
+#endif
+
+ if (!get_check(out_val))
+ {
+ /* Hack - remember that the item has given a message here. */
+ o_ptr->marked |= (OM_NOMSG | OM_NO_QUERY);
+ continue;
+ }
+
+ }
+ py_pickup_aux(this_o_idx);
+
+ continue;
+ }
+
+ /*
+ * Do auto-destroy;
+ * When always_pickup is 'yes', we disable
+ * auto-destroyer from autopick function, and do only
+ * easy-auto-destroyer.
+ */
+ else
+ {
+ if (auto_destroy_item((-this_o_idx), idx))
+ continue;
+ }
+ }
+}
+
+
+#define PT_DEFAULT 0
+#define PT_WITH_PNAME 1
+
+/*
+ * Get file name for autopick preference
+ */
+static cptr pickpref_filename(int filename_mode)
+{
+#ifdef JP
+ static const char namebase[] = "picktype";
+#else
+ static const char namebase[] = "pickpref";
+#endif
+
+ switch (filename_mode)
+ {
+ case PT_DEFAULT:
+ return format("%s.prf", namebase);
+
+ case PT_WITH_PNAME:
+ return format("%s-%s.prf", namebase, player_name);
+
+ default:
+ return NULL;
+ }
+}
+
+
+static const char autoregister_header[] = "?:$AUTOREGISTER";
+
+/*
+ * Clear auto registered lines in the picktype.prf .
+ */
+static bool clear_auto_register(void)
+{
+ char tmp_file[1024];
+ char pref_file[1024];
+ char buf[1024];
+ FILE *pref_fff;
+ FILE *tmp_fff;
+ int num = 0;
+ bool autoregister = FALSE;
+ bool okay = TRUE;
+
+ path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_WITH_PNAME));
+ pref_fff = my_fopen(pref_file, "r");
+
+ if (!pref_fff)
+ {
+ path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_DEFAULT));
+ pref_fff = my_fopen(pref_file, "r");
+ }
+
+ if (!pref_fff)
+ {
+ /* No file yet */
+ return TRUE;
+ }
+
+ /* Open a new (temporary) file */
+ tmp_fff = my_fopen_temp(tmp_file, sizeof(tmp_file));
+
+ if (!tmp_fff)
+ {
+ /* Close the preference file */
+ fclose(pref_fff);
+
+#ifdef JP
+ msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤¤Þ¤»¤ó¤Ç¤·¤¿¡£", tmp_file);
+#else
+ msg_format("Failed to create temporary file %s.", tmp_file);
+#endif
+ msg_print(NULL);
+ return FALSE;
+ }
+
+
+ /* Loop for every line */
+ while (TRUE)
+ {
+ /* Read a line */
+ if (my_fgets(pref_fff, buf, sizeof(buf))) break;
+
+ if (autoregister)
+ {
+ /* Delete auto-registered line */
+
+ /* Count auto-destroy preference lines */
+ if (buf[0] != '#' && buf[0] != '?') num++;
+ }
+
+ /* We are looking for auto-registered line */
+ else
+ {
+ if (streq(buf, autoregister_header))
+ {
+ /* Delete all further lines */
+ autoregister = TRUE;
+ }
+ else
+ {
+ /* Copy orginally lines */
+ fprintf(tmp_fff, "%s\n", buf);
+ }
+ }
+ }
+
+ /* Close files */
+ my_fclose(pref_fff);
+ my_fclose(tmp_fff);
+
+ if (num)
+ {
+#ifdef JP
+ msg_format("°ÊÁ°¤Î¥¥ã¥é¥¯¥¿¡¼ÍѤμ«Æ°ÀßÄê(%d¹Ô)¤¬»Ä¤Ã¤Æ¤¤¤Þ¤¹¡£", num);
+ strcpy(buf, "¸Å¤¤ÀßÄê¹Ô¤Ïºï½ü¤·¤Þ¤¹¡£¤è¤í¤·¤¤¤Ç¤¹¤«¡©");
+#else
+ msg_format("Auto registered lines (%d lines) for previous character are remaining.", num);
+ strcpy(buf, "These lines will be deleted. Are you sure? ");
+#endif
+
+ /* You can cancel it */
+ if (!get_check(buf))
+ {
+ okay = FALSE;
+ autoregister = FALSE;
+
+#ifdef JP
+ msg_print("¥¨¥Ç¥£¥¿¤Î¥«¥Ã¥È&¥Ú¡¼¥¹¥ÈÅù¤ò»È¤Ã¤ÆɬÍפʹԤòÈòÆñ¤·¤Æ¤¯¤À¤µ¤¤¡£");
+#else
+ msg_print("Use cut & paste of auto picker editor (_) to keep old prefs.");
+#endif
+ }
+ }
+
+
+ /* If there are some changes, overwrite the original file with new one */
+ if (autoregister)
+ {
+ /* Copy contents of temporary file */
+
+ tmp_fff = my_fopen(tmp_file, "r");
+ pref_fff = my_fopen(pref_file, "w");
+
+ while (!my_fgets(tmp_fff, buf, sizeof(buf)))
+ fprintf(pref_fff, "%s\n", buf);
+
+ my_fclose(pref_fff);
+ my_fclose(tmp_fff);
+ }
+
+ /* Kill the temporary file */
+ fd_kill(tmp_file);
+
+ return okay;
+}
+
+
+/*
+ * Automatically register an auto-destroy preference line
+ */
+bool add_auto_register(object_type *o_ptr)
+{
+ char buf[1024];
+ char pref_file[1024];
+ FILE *pref_fff;
+ autopick_type an_entry, *entry = &an_entry;
+
+ int match_autopick = is_autopick(o_ptr);
+
+ /* Already registered */
+ if (match_autopick != -1)
+ {
+ cptr what;
+ byte act = autopick_list[match_autopick].action;
+
+#ifdef JP
+ if (act & DO_AUTOPICK) what = "¼«Æ°¤Ç½¦¤¦";
+ else if (act & DO_AUTODESTROY) what = "¼«Æ°Ç˲õ¤¹¤ë";
+ else if (act & DONT_AUTOPICK) what = "ÊüÃÖ¤¹¤ë";
+ else /* if (act & DO_QUERY_AUTOPICK) */ what = "³Îǧ¤·¤Æ½¦¤¦";
+
+ msg_format("¤½¤Î¥¢¥¤¥Æ¥à¤Ï´û¤Ë%s¤è¤¦¤ËÀßÄꤵ¤ì¤Æ¤¤¤Þ¤¹¡£", what);
+#else
+ if (act & DO_AUTOPICK) what = "auto-pickup";
+ else if (act & DO_AUTODESTROY) what = "auto-destroy";
+ else if (act & DONT_AUTOPICK) what = "leave on floor";
+ else /* if (act & DO_QUERY_AUTOPICK) */ what = "query auto-pickup";
+
+ msg_format("The object is already registered to %s.", what);
+#endif
+
+ return FALSE;
+ }
+
+
+ if (!p_ptr->autopick_autoregister)
+ {
+ /* Clear old auto registered lines */
+ if (!clear_auto_register()) return FALSE;