3 /* Purpose: Object Auto-picker/Destroyer */
6 * Copyright (c) 2002 Mogami
8 * This software may be copied and distributed for educational, research, and
9 * not for profit purposes provided that this copyright and statement are
10 * included in all such copies.
16 #define MAX_LINELEN 1024
22 #define FLG_COLLECTING 1
24 #define FLG_UNIDENTIFIED 3
25 #define FLG_IDENTIFIED 4
26 #define FLG_STAR_IDENTIFIED 5
28 #define FLG_MORE_THAN 7
30 #define FLG_MORE_BONUS 9
31 #define FLG_MORE_BONUS2 10
32 #define FLG_WORTHLESS 11
33 #define FLG_ARTIFACT 12
35 #define FLG_NAMELESS 14
39 #define FLG_UNREADABLE 18
48 #define FLG_WEAPONS 31
50 #define FLG_MISSILES 33
51 #define FLG_DEVICES 34
54 #define FLG_SPELLBOOKS 37
56 #define FLG_SHIELDS 39
59 #define FLG_AMULETS 42
65 #define FLG_FAVORITE 48
67 #define FLG_NOUN_BEGIN FLG_ITEMS
68 #define FLG_NOUN_END FLG_FAVORITE
72 #define KEY_ALL "¤¹¤Ù¤Æ¤Î"
76 * MEGA HACK -- MPW¤Î¥Ð¥°½ü¤±¡£
77 * pre-processÃæ¤Ë¡Ö¼ý¡×¤Î»ú¤Î2¥Ð¥¤¥ÈÌܤ¬¾¡¼ê¤Ë¾Ã¤¨¤Æ¤·¤Þ¤¦¡£
79 #define KEY_COLLECTING "\x8e\xfb½¸Ãæ¤Î"
81 #define KEY_COLLECTING "¼ý½¸Ãæ¤Î"
84 #define KEY_UNIDENTIFIED "̤´ÕÄê¤Î"
85 #define KEY_IDENTIFIED "´ÕÄêºÑ¤ß¤Î"
86 #define KEY_STAR_IDENTIFIED "*´ÕÄê*ºÑ¤ß¤Î"
87 #define KEY_BOOSTED "¥À¥¤¥¹Ìܤΰ㤦"
88 #define KEY_MORE_THAN "¥À¥¤¥¹ÌÜ"
89 #define KEY_DICE "°Ê¾å¤Î"
90 #define KEY_MORE_BONUS "½¤ÀµÃÍ"
91 #define KEY_MORE_BONUS2 "°Ê¾å¤Î"
92 #define KEY_WORTHLESS "̵²ÁÃͤÎ"
93 #define KEY_ARTIFACT "¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È"
94 #define KEY_EGO "¥¨¥´"
95 #define KEY_NAMELESS "̵ÌäÎ"
96 #define KEY_UNAWARE "̤ȽÌÀ¤Î"
97 #define KEY_WANTED "¾Þ¶â¼ó¤Î"
98 #define KEY_UNIQUE "¥æ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼¤Î"
99 #define KEY_HUMAN "¿Í´Ö¤Î"
100 #define KEY_UNREADABLE "Æɤá¤Ê¤¤"
101 #define KEY_REALM1 "Âè°ìÎΰè¤Î"
102 #define KEY_REALM2 "ÂèÆóÎΰè¤Î"
103 #define KEY_FIRST "1ºýÌܤÎ"
104 #define KEY_SECOND "2ºýÌܤÎ"
105 #define KEY_THIRD "3ºýÌܤÎ"
106 #define KEY_FOURTH "4ºýÌܤÎ"
107 #define KEY_ITEMS "¥¢¥¤¥Æ¥à"
108 #define KEY_WEAPONS "Éð´ï"
109 #define KEY_ARMORS "Ëɶñ"
110 #define KEY_MISSILES "Ìð"
111 #define KEY_DEVICES "ËâË¡¥¢¥¤¥Æ¥à"
112 #define KEY_LIGHTS "¸÷¸»"
113 #define KEY_JUNKS "¤¬¤é¤¯¤¿"
114 #define KEY_SPELLBOOKS "ËâË¡½ñ"
115 #define KEY_HAFTED "Æß´ï"
116 #define KEY_SHIELDS "½â"
117 #define KEY_BOWS "µÝ"
118 #define KEY_RINGS "»ØÎØ"
119 #define KEY_AMULETS "¥¢¥ß¥å¥ì¥Ã¥È"
120 #define KEY_SUITS "³»"
121 #define KEY_CLOAKS "¥¯¥í¡¼¥¯"
122 #define KEY_HELMS "³õ"
123 #define KEY_GLOVES "äƼê"
124 #define KEY_BOOTS "·¤"
125 #define KEY_FAVORITE "ÆÀ°ÕÉð´ï"
129 #define KEY_ALL "all"
130 #define KEY_COLLECTING "collecting"
131 #define KEY_UNIDENTIFIED "unidentified"
132 #define KEY_IDENTIFIED "identified"
133 #define KEY_STAR_IDENTIFIED "*identified*"
134 #define KEY_BOOSTED "dice boosted"
135 #define KEY_MORE_THAN "more than"
136 #define KEY_DICE " dice"
137 #define KEY_MORE_BONUS "more bonus than"
138 #define KEY_MORE_BONUS2 ""
139 #define KEY_WORTHLESS "worthless"
140 #define KEY_ARTIFACT "artifact"
141 #define KEY_EGO "ego"
142 #define KEY_NAMELESS "nameless"
143 #define KEY_UNAWARE "unaware"
144 #define KEY_WANTED "wanted"
145 #define KEY_UNIQUE "unique monster's"
146 #define KEY_HUMAN "human"
147 #define KEY_UNREADABLE "unreadable"
148 #define KEY_REALM1 "first realm's"
149 #define KEY_REALM2 "second realm's"
150 #define KEY_FIRST "first"
151 #define KEY_SECOND "second"
152 #define KEY_THIRD "third"
153 #define KEY_FOURTH "fourth"
154 #define KEY_ITEMS "items"
155 #define KEY_WEAPONS "weapons"
156 #define KEY_ARMORS "armors"
157 #define KEY_MISSILES "missiles"
158 #define KEY_DEVICES "magical devices"
159 #define KEY_LIGHTS "lights"
160 #define KEY_JUNKS "junks"
161 #define KEY_SPELLBOOKS "spellbooks"
162 #define KEY_HAFTED "hafted weapons"
163 #define KEY_SHIELDS "shields"
164 #define KEY_BOWS "bows"
165 #define KEY_RINGS "rings"
166 #define KEY_AMULETS "amulets"
167 #define KEY_SUITS "suits"
168 #define KEY_CLOAKS "cloaks"
169 #define KEY_HELMS "helms"
170 #define KEY_GLOVES "gloves"
171 #define KEY_BOOTS "boots"
172 #define KEY_FAVORITE "favorite weapons"
176 #define MATCH_KEY(KEY) (!strncmp(ptr, KEY, sizeof(KEY)-1)\
177 ? (ptr += sizeof(KEY)-1, (' '==*ptr) ? ptr++ : 0, TRUE) : FALSE)
178 #define MATCH_KEY2(KEY) (!strncmp(ptr, KEY, sizeof(KEY)-1)\
179 ? (prev_ptr = ptr, ptr += sizeof(KEY)-1, (' '==*ptr) ? ptr++ : 0, TRUE) : FALSE)
182 #define ADD_KEY(KEY) strcat(ptr, KEY)
184 #define ADD_KEY(KEY) (strcat(ptr, KEY), strcat(ptr, " "))
186 #define ADD_KEY2(KEY) strcat(ptr, KEY)
188 #define ADD_FLG(FLG) (entry->flag[FLG / 32] |= (1L << (FLG % 32)))
189 #define REM_FLG(FLG) (entry->flag[FLG / 32] &= ~(1L << (FLG % 32)))
190 #define ADD_FLG_NOUN(FLG) (ADD_FLG(FLG), prev_flg = FLG)
191 #define IS_FLG(FLG) (entry->flag[FLG / 32] & (1L << (FLG % 32)))
194 static char kanji_colon[] = "¡§";
199 * A function to create new entry
201 static bool autopick_new_entry(autopick_type *entry, cptr str, bool allow_default)
206 char buf[MAX_LINELEN];
207 cptr prev_ptr, ptr, old_ptr;
210 if (str[1] == ':') switch (str[0])
213 case 'A': case 'P': case 'C':
217 entry->flag[0] = entry->flag[1] = 0L;
220 act = DO_AUTOPICK | DO_DISPLAY;
223 if ((act & DO_AUTOPICK) && *str == '!')
226 act |= DO_AUTODESTROY;
229 else if ((act & DO_AUTOPICK) && *str == '~')
232 act |= DONT_AUTOPICK;
235 else if ((act & DO_AUTOPICK) && *str == ';')
238 act |= DO_QUERY_AUTOPICK;
241 else if ((act & DO_DISPLAY) && *str == '(')
250 /* don't mind upper or lower case */
252 for (i = 0; *str; i++)
263 /* Auto-inscription? */
271 if (isupper(c)) c = tolower(c);
277 /* Skip empty line unless allow_default */
278 if (!allow_default && *buf == 0) return FALSE;
280 /* Skip comment line */
281 if (*buf == 0 && insc) return FALSE;
283 ptr = prev_ptr = buf;
286 while (old_ptr != ptr)
288 /* Save current location */
291 if (MATCH_KEY(KEY_ALL)) ADD_FLG(FLG_ALL);
292 if (MATCH_KEY(KEY_COLLECTING)) ADD_FLG(FLG_COLLECTING);
293 if (MATCH_KEY(KEY_UNIDENTIFIED)) ADD_FLG(FLG_UNIDENTIFIED);
294 if (MATCH_KEY(KEY_IDENTIFIED)) ADD_FLG(FLG_IDENTIFIED);
295 if (MATCH_KEY(KEY_STAR_IDENTIFIED)) ADD_FLG(FLG_STAR_IDENTIFIED);
296 if (MATCH_KEY(KEY_BOOSTED)) ADD_FLG(FLG_BOOSTED);
298 /*** Weapons whose dd*ds is more than nn ***/
299 if (MATCH_KEY2(KEY_MORE_THAN))
304 /* Drop leading spaces */
305 while (' ' == *ptr) ptr++;
308 while ('0' <= *ptr && *ptr <= '9')
310 entry->dice = 10 * entry->dice + (*ptr - '0');
317 (void)MATCH_KEY(KEY_DICE);
318 ADD_FLG(FLG_MORE_THAN);
324 /*** Items whose magical bonus is more than n ***/
325 if (MATCH_KEY2(KEY_MORE_BONUS))
330 /* Drop leading spaces */
331 while (' ' == *ptr) ptr++;
334 while ('0' <= *ptr && *ptr <= '9')
336 entry->bonus = 10 * entry->bonus + (*ptr - '0');
343 (void)MATCH_KEY(KEY_MORE_BONUS2);
344 ADD_FLG(FLG_MORE_BONUS);
350 if (MATCH_KEY(KEY_WORTHLESS)) ADD_FLG(FLG_WORTHLESS);
351 if (MATCH_KEY(KEY_EGO)) ADD_FLG(FLG_EGO);
352 if (MATCH_KEY(KEY_NAMELESS)) ADD_FLG(FLG_NAMELESS);
353 if (MATCH_KEY(KEY_UNAWARE)) ADD_FLG(FLG_UNAWARE);
354 if (MATCH_KEY(KEY_WANTED)) ADD_FLG(FLG_WANTED);
355 if (MATCH_KEY(KEY_UNIQUE)) ADD_FLG(FLG_UNIQUE);
356 if (MATCH_KEY(KEY_HUMAN)) ADD_FLG(FLG_HUMAN);
357 if (MATCH_KEY(KEY_UNREADABLE)) ADD_FLG(FLG_UNREADABLE);
358 if (MATCH_KEY(KEY_REALM1)) ADD_FLG(FLG_REALM1);
359 if (MATCH_KEY(KEY_REALM2)) ADD_FLG(FLG_REALM2);
360 if (MATCH_KEY(KEY_FIRST)) ADD_FLG(FLG_FIRST);
361 if (MATCH_KEY(KEY_SECOND)) ADD_FLG(FLG_SECOND);
362 if (MATCH_KEY(KEY_THIRD)) ADD_FLG(FLG_THIRD);
363 if (MATCH_KEY(KEY_FOURTH)) ADD_FLG(FLG_FOURTH);
366 /* Not yet found any noun */
369 if (MATCH_KEY2(KEY_ARTIFACT)) ADD_FLG_NOUN(FLG_ARTIFACT);
371 if (MATCH_KEY2(KEY_ITEMS)) ADD_FLG_NOUN(FLG_ITEMS);
372 else if (MATCH_KEY2(KEY_WEAPONS)) ADD_FLG_NOUN(FLG_WEAPONS);
373 else if (MATCH_KEY2(KEY_ARMORS)) ADD_FLG_NOUN(FLG_ARMORS);
374 else if (MATCH_KEY2(KEY_MISSILES)) ADD_FLG_NOUN(FLG_MISSILES);
375 else if (MATCH_KEY2(KEY_DEVICES)) ADD_FLG_NOUN(FLG_DEVICES);
376 else if (MATCH_KEY2(KEY_LIGHTS)) ADD_FLG_NOUN(FLG_LIGHTS);
377 else if (MATCH_KEY2(KEY_JUNKS)) ADD_FLG_NOUN(FLG_JUNKS);
378 else if (MATCH_KEY2(KEY_SPELLBOOKS)) ADD_FLG_NOUN(FLG_SPELLBOOKS);
379 else if (MATCH_KEY2(KEY_HAFTED)) ADD_FLG_NOUN(FLG_HAFTED);
380 else if (MATCH_KEY2(KEY_SHIELDS)) ADD_FLG_NOUN(FLG_SHIELDS);
381 else if (MATCH_KEY2(KEY_BOWS)) ADD_FLG_NOUN(FLG_BOWS);
382 else if (MATCH_KEY2(KEY_RINGS)) ADD_FLG_NOUN(FLG_RINGS);
383 else if (MATCH_KEY2(KEY_AMULETS)) ADD_FLG_NOUN(FLG_AMULETS);
384 else if (MATCH_KEY2(KEY_SUITS)) ADD_FLG_NOUN(FLG_SUITS);
385 else if (MATCH_KEY2(KEY_CLOAKS)) ADD_FLG_NOUN(FLG_CLOAKS);
386 else if (MATCH_KEY2(KEY_HELMS)) ADD_FLG_NOUN(FLG_HELMS);
387 else if (MATCH_KEY2(KEY_GLOVES)) ADD_FLG_NOUN(FLG_GLOVES);
388 else if (MATCH_KEY2(KEY_BOOTS)) ADD_FLG_NOUN(FLG_BOOTS);
389 else if (MATCH_KEY2(KEY_FAVORITE)) ADD_FLG_NOUN(FLG_FAVORITE);
391 /* Last 'keyword' must be at the correct location */
395 else if (ptr[0] == kanji_colon[0] && ptr[1] == kanji_colon[1])
398 else if (*ptr == '\0')
400 /* There was no noun */
403 /* Add extra word "items" */
404 ADD_FLG_NOUN(FLG_ITEMS);
411 /* A noun type keyword didn't end correctly */
412 entry->flag[prev_flg/32] &= ~(1L<< (prev_flg%32));
417 /* Save this auto-picker entry line */
418 entry->name = string_make(ptr);
420 entry->insc = string_make(insc);
429 static bool is_favorite(object_type *o_ptr)
431 /* Only weapons match */
432 if (!(TV_WEAPON_BEGIN <= o_ptr->tval && o_ptr->tval <= TV_WEAPON_END))
435 /* Favorite weapons are varied depend on the class */
436 switch (p_ptr->pclass)
440 u32b flgs[TR_FLAG_SIZE];
441 object_flags_known(o_ptr, flgs);
443 if (!have_flag(flgs, TR_BLESSED) &&
444 !(o_ptr->tval == TV_HAFTED))
450 case CLASS_FORCETRAINER:
452 if (!(s_info[p_ptr->pclass].w_max[o_ptr->tval-TV_WEAPON_BEGIN][o_ptr->sval]))
456 case CLASS_BEASTMASTER:
459 u32b flgs[TR_FLAG_SIZE];
460 object_flags_known(o_ptr, flgs);
462 /* Is it known to be suitable to using while riding? */
463 if (!(have_flag(flgs, TR_RIDING)))
471 if (s_info[p_ptr->pclass].w_max[o_ptr->tval-TV_WEAPON_BEGIN][o_ptr->sval] <= WEAPON_EXP_BEGINNER)
476 /* All weapons are okay for non-special classes */
485 * Get auto-picker entry from o_ptr.
487 static void autopick_entry_from_object(autopick_type *entry, object_type *o_ptr)
489 /* Assume that object name is to be added */
493 entry->insc = string_make(quark_str(o_ptr->inscription));
494 entry->action = DO_AUTOPICK | DO_DISPLAY;
495 entry->flag[0] = entry->flag[1] = 0L;
499 if (!object_aware_p(o_ptr))
501 ADD_FLG(FLG_UNAWARE);
504 /* Not really identified */
505 else if (!object_known_p(o_ptr))
507 if (!(o_ptr->ident & IDENT_SENSE))
509 ADD_FLG(FLG_UNIDENTIFIED);
513 /* Pseudo-identified */
514 switch (o_ptr->feeling)
518 ADD_FLG(FLG_NAMELESS);
523 ADD_FLG(FLG_NAMELESS);
524 ADD_FLG(FLG_WORTHLESS);
529 ADD_FLG(FLG_WORTHLESS);
533 /* It's not know as useless so... */
534 ADD_FLG(FLG_UNIDENTIFIED);
546 ego_item_type *e_ptr = &e_info[o_ptr->name2];
547 entry->name = string_make(e_name + e_ptr->name);
553 else if (o_ptr->name1 || o_ptr->art_name)
554 ADD_FLG(FLG_ARTIFACT);
556 /* Non-ego, non-artifact */
559 /* Wearable nameless object */
560 if ((TV_EQUIP_BEGIN <= o_ptr->tval && o_ptr->tval <= TV_EQUIP_END))
561 ADD_FLG(FLG_NAMELESS);
570 case TV_HAFTED: case TV_POLEARM: case TV_SWORD: case TV_DIGGING:
571 k_ptr = &k_info[o_ptr->k_idx];
572 if ((o_ptr->dd != k_ptr->dd) || (o_ptr->ds != k_ptr->ds))
573 ADD_FLG(FLG_BOOSTED);
576 if (o_ptr->tval == TV_CORPSE && object_is_shoukinkubi(o_ptr))
578 REM_FLG(FLG_WORTHLESS);
582 if ((o_ptr->tval == TV_CORPSE || o_ptr->tval == TV_STATUE)
583 && (r_info[o_ptr->pval].flags1 & RF1_UNIQUE))
588 if (o_ptr->tval == TV_CORPSE && strchr("pht", r_info[o_ptr->pval].d_char))
593 if (o_ptr->tval >= TV_LIFE_BOOK &&
594 !check_book_realm(o_ptr->tval, o_ptr->sval))
596 ADD_FLG(FLG_UNREADABLE);
597 if (o_ptr->tval != TV_ARCANE_BOOK) name = FALSE;
600 if (REALM1_BOOK == o_ptr->tval &&
601 p_ptr->pclass != CLASS_SORCERER &&
602 p_ptr->pclass != CLASS_RED_MAGE)
608 if (REALM2_BOOK == o_ptr->tval &&
609 p_ptr->pclass != CLASS_SORCERER &&
610 p_ptr->pclass != CLASS_RED_MAGE)
616 if (o_ptr->tval >= TV_LIFE_BOOK && 0 == o_ptr->sval)
618 if (o_ptr->tval >= TV_LIFE_BOOK && 1 == o_ptr->sval)
620 if (o_ptr->tval >= TV_LIFE_BOOK && 2 == o_ptr->sval)
622 if (o_ptr->tval >= TV_LIFE_BOOK && 3 == o_ptr->sval)
625 if (o_ptr->tval == TV_SHOT || o_ptr->tval == TV_BOLT
626 || o_ptr->tval == TV_ARROW)
627 ADD_FLG(FLG_MISSILES);
628 else if (o_ptr->tval == TV_SCROLL || o_ptr->tval == TV_STAFF
629 || o_ptr->tval == TV_WAND || o_ptr->tval == TV_ROD)
630 ADD_FLG(FLG_DEVICES);
631 else if (o_ptr->tval == TV_LITE)
633 else if (o_ptr->tval == TV_SKELETON || o_ptr->tval == TV_BOTTLE
634 || o_ptr->tval == TV_JUNK || o_ptr->tval == TV_STATUE)
636 else if (o_ptr->tval >= TV_LIFE_BOOK)
637 ADD_FLG(FLG_SPELLBOOKS);
638 else if (o_ptr->tval == TV_POLEARM || o_ptr->tval == TV_SWORD
639 || o_ptr->tval == TV_DIGGING || o_ptr->tval == TV_HAFTED)
640 ADD_FLG(FLG_WEAPONS);
641 else if (o_ptr->tval == TV_SHIELD)
642 ADD_FLG(FLG_SHIELDS);
643 else if (o_ptr->tval == TV_BOW)
645 else if (o_ptr->tval == TV_RING)
647 else if (o_ptr->tval == TV_AMULET)
648 ADD_FLG(FLG_AMULETS);
649 else if (o_ptr->tval == TV_DRAG_ARMOR || o_ptr->tval == TV_HARD_ARMOR ||
650 o_ptr->tval == TV_SOFT_ARMOR)
652 else if (o_ptr->tval == TV_CLOAK)
654 else if (o_ptr->tval == TV_HELM)
656 else if (o_ptr->tval == TV_GLOVES)
658 else if (o_ptr->tval == TV_BOOTS)
664 char o_name[MAX_NLEN];
665 object_desc(o_name, o_ptr, FALSE, 0);
667 entry->name = string_make(o_name);
670 else if (!entry->name)
672 entry->name = string_make("");
680 * A function to delete entry
682 static void autopick_free_entry(autopick_type *entry)
684 string_free(entry->name);
685 string_free(entry->insc);
690 * Initialize auto-picker preference
692 #define MAX_AUTOPICK_DEFAULT 200
694 void init_autopicker(void)
696 static const char easy_autopick_inscription[] = "(:=g";
702 max_max_autopick = MAX_AUTOPICK_DEFAULT;
703 C_MAKE(autopick_list, max_max_autopick, autopick_type);
707 /* Clear old entries */
708 for( i = 0; i < max_autopick; i++)
709 autopick_free_entry(&autopick_list[i]);
713 /* There is always one entry "=g" */
714 autopick_new_entry(&entry, easy_autopick_inscription, TRUE);
715 autopick_list[max_autopick++] = entry;
720 * Add one line to autopick_list[]
722 static void add_autopick_list(autopick_type *entry)
724 /* There is no enough space to add one line */
725 if (max_autopick >= max_max_autopick)
727 int old_max_max_autopick = max_max_autopick;
728 autopick_type *old_autopick_list = autopick_list;
730 /* Increase size of list */
731 max_max_autopick += MAX_AUTOPICK_DEFAULT;
734 C_MAKE(autopick_list, max_max_autopick, autopick_type);
736 /* Copy from old list to new list */
737 C_COPY(autopick_list, old_autopick_list, old_max_max_autopick, autopick_type);
740 C_FREE(old_autopick_list, old_max_max_autopick, autopick_type);
744 autopick_list[max_autopick] = *entry;
751 * Process line for auto picker/destroyer.
753 errr process_pickpref_file_line(char *buf)
755 autopick_type an_entry, *entry = &an_entry;
758 /* Nuke illegal char */
759 for(i = 0; buf[i]; i++)
768 if (isspace(buf[i]) && buf[i] != ' ')
773 if (!autopick_new_entry(entry, buf, FALSE)) return 0;
775 /* Already has the same entry? */
776 for(i = 0; i < max_autopick; i++)
777 if(!strcmp(entry->name, autopick_list[i].name)
778 && entry->flag[0] == autopick_list[i].flag[0]
779 && entry->flag[1] == autopick_list[i].flag[1]
780 && entry->dice == autopick_list[i].dice
781 && entry->bonus == autopick_list[i].bonus) return 0;
783 add_autopick_list(entry);
789 * Reconstruct preference line from entry
791 cptr autopick_line_from_entry(autopick_type *entry)
793 char buf[MAX_LINELEN];
795 bool sepa_flag = TRUE;
798 if (!(entry->action & DO_DISPLAY)) strcat(buf, "(");
799 if (entry->action & DO_QUERY_AUTOPICK) strcat(buf, ";");
800 if (entry->action & DO_AUTODESTROY) strcat(buf, "!");
801 if (entry->action & DONT_AUTOPICK) strcat(buf, "~");
805 if (IS_FLG(FLG_ALL)) ADD_KEY(KEY_ALL);
806 if (IS_FLG(FLG_COLLECTING)) ADD_KEY(KEY_COLLECTING);
807 if (IS_FLG(FLG_UNIDENTIFIED)) ADD_KEY(KEY_UNIDENTIFIED);
808 if (IS_FLG(FLG_IDENTIFIED)) ADD_KEY(KEY_IDENTIFIED);
809 if (IS_FLG(FLG_STAR_IDENTIFIED)) ADD_KEY(KEY_STAR_IDENTIFIED);
810 if (IS_FLG(FLG_UNAWARE)) ADD_KEY(KEY_UNAWARE);
811 if (IS_FLG(FLG_BOOSTED)) ADD_KEY(KEY_BOOSTED);
813 if (IS_FLG(FLG_MORE_THAN))
815 ADD_KEY(KEY_MORE_THAN);
816 strcat(ptr, format("%d", entry->dice));
820 if (IS_FLG(FLG_MORE_BONUS))
822 ADD_KEY(KEY_MORE_BONUS);
823 strcat(ptr, format("%d", entry->bonus));
824 ADD_KEY(KEY_MORE_BONUS2);
827 if (IS_FLG(FLG_UNREADABLE)) ADD_KEY(KEY_UNREADABLE);
828 if (IS_FLG(FLG_REALM1)) ADD_KEY(KEY_REALM1);
829 if (IS_FLG(FLG_REALM2)) ADD_KEY(KEY_REALM2);
830 if (IS_FLG(FLG_FIRST)) ADD_KEY(KEY_FIRST);
831 if (IS_FLG(FLG_SECOND)) ADD_KEY(KEY_SECOND);
832 if (IS_FLG(FLG_THIRD)) ADD_KEY(KEY_THIRD);
833 if (IS_FLG(FLG_FOURTH)) ADD_KEY(KEY_FOURTH);
834 if (IS_FLG(FLG_WANTED)) ADD_KEY(KEY_WANTED);
835 if (IS_FLG(FLG_UNIQUE)) ADD_KEY(KEY_UNIQUE);
836 if (IS_FLG(FLG_HUMAN)) ADD_KEY(KEY_HUMAN);
837 if (IS_FLG(FLG_WORTHLESS)) ADD_KEY(KEY_WORTHLESS);
838 if (IS_FLG(FLG_NAMELESS)) ADD_KEY(KEY_NAMELESS);
839 if (IS_FLG(FLG_EGO)) ADD_KEY(KEY_EGO);
841 if (IS_FLG(FLG_ARTIFACT)) ADD_KEY(KEY_ARTIFACT);
843 if (IS_FLG(FLG_ITEMS)) ADD_KEY2(KEY_ITEMS);
844 else if (IS_FLG(FLG_WEAPONS)) ADD_KEY2(KEY_WEAPONS);
845 else if (IS_FLG(FLG_ARMORS)) ADD_KEY2(KEY_ARMORS);
846 else if (IS_FLG(FLG_MISSILES)) ADD_KEY2(KEY_MISSILES);
847 else if (IS_FLG(FLG_DEVICES)) ADD_KEY2(KEY_DEVICES);
848 else if (IS_FLG(FLG_LIGHTS)) ADD_KEY2(KEY_LIGHTS);
849 else if (IS_FLG(FLG_JUNKS)) ADD_KEY2(KEY_JUNKS);
850 else if (IS_FLG(FLG_SPELLBOOKS)) ADD_KEY2(KEY_SPELLBOOKS);
851 else if (IS_FLG(FLG_HAFTED)) ADD_KEY2(KEY_HAFTED);
852 else if (IS_FLG(FLG_SHIELDS)) ADD_KEY2(KEY_SHIELDS);
853 else if (IS_FLG(FLG_BOWS)) ADD_KEY2(KEY_BOWS);
854 else if (IS_FLG(FLG_RINGS)) ADD_KEY2(KEY_RINGS);
855 else if (IS_FLG(FLG_AMULETS)) ADD_KEY2(KEY_AMULETS);
856 else if (IS_FLG(FLG_SUITS)) ADD_KEY2(KEY_SUITS);
857 else if (IS_FLG(FLG_CLOAKS)) ADD_KEY2(KEY_CLOAKS);
858 else if (IS_FLG(FLG_HELMS)) ADD_KEY2(KEY_HELMS);
859 else if (IS_FLG(FLG_GLOVES)) ADD_KEY2(KEY_GLOVES);
860 else if (IS_FLG(FLG_BOOTS)) ADD_KEY2(KEY_BOOTS);
861 else if (IS_FLG(FLG_FAVORITE)) ADD_KEY2(KEY_FAVORITE);
863 /* You don't need sepalator after adjective */
864 /* 'artifact' is not true adjective */
865 else if (!IS_FLG(FLG_ARTIFACT))
868 if (entry->name && entry->name[0])
872 if (sepa_flag) strcat(buf, ":");
875 while (entry->name[j] && i < MAX_LINELEN - 2 - 1)
878 if (iskanji(entry->name[j]))
879 buf[i++] = entry->name[j++];
881 buf[i++] = entry->name[j++];
892 while (entry->insc[j] && i < MAX_LINELEN - 2)
895 if (iskanji(entry->insc[j]))
896 buf[i++] = entry->insc[j++];
898 buf[i++] = entry->insc[j++];
903 return string_make(buf);
908 * Reconstruct preference line from entry and kill entry
910 static cptr autopick_line_from_entry_kill(autopick_type *entry)
912 cptr ptr = autopick_line_from_entry(entry);
914 /* Free memory for original entry */
915 autopick_free_entry(entry);
922 * A function for Auto-picker/destroyer
923 * Examine whether the object matches to the entry
925 static bool is_autopick_aux(object_type *o_ptr, autopick_type *entry, cptr o_name)
928 cptr ptr = entry->name;
930 /*** Unidentified ***/
931 if (IS_FLG(FLG_UNIDENTIFIED)
932 && (object_known_p(o_ptr) || (o_ptr->ident & IDENT_SENSE)))
936 if (IS_FLG(FLG_IDENTIFIED) && !object_known_p(o_ptr))
939 /*** *Identified* ***/
940 if (IS_FLG(FLG_STAR_IDENTIFIED) &&
941 (!object_known_p(o_ptr) || !(o_ptr->ident & IDENT_MENTAL)))
944 /*** Dice boosted (weapon of slaying) ***/
945 if (IS_FLG(FLG_BOOSTED))
947 object_kind *k_ptr = &k_info[o_ptr->k_idx];
949 switch( o_ptr->tval )
955 if ((o_ptr->dd != k_ptr->dd) || (o_ptr->ds != k_ptr->ds))
964 /*** Weapons which dd*ds is more than nn ***/
965 if (IS_FLG(FLG_MORE_THAN))
967 if (o_ptr->dd * o_ptr->ds < entry->dice)
971 /*** Weapons whic dd*ds is more than nn ***/
972 if (IS_FLG(FLG_MORE_BONUS))
974 if (!object_known_p(o_ptr)) return FALSE;
978 if (o_ptr->pval < entry->bonus) return FALSE;
982 if (o_ptr->to_h < entry->bonus &&
983 o_ptr->to_d < entry->bonus &&
984 o_ptr->to_a < entry->bonus &&
985 o_ptr->pval < entry->bonus)
990 /*** Worthless items ***/
991 if (IS_FLG(FLG_WORTHLESS) && object_value(o_ptr) > 0)
994 /*** Artifact object ***/
995 if (IS_FLG(FLG_ARTIFACT))
997 if (!object_known_p(o_ptr) || (!o_ptr->name1 && !o_ptr->art_name))
1001 /*** Ego object ***/
1002 if (IS_FLG(FLG_EGO))
1004 if (!object_known_p(o_ptr) || !o_ptr->name2)
1009 if (IS_FLG(FLG_NAMELESS))
1011 if (!(TV_EQUIP_BEGIN <= o_ptr->tval && o_ptr->tval <= TV_EQUIP_END))
1014 /* Inscription is a some sort of 'name' */
1015 if (o_ptr->inscription) return FALSE;
1018 if (object_known_p(o_ptr))
1020 /* Artifacts and Ego objects are not okay */
1021 if (o_ptr->name1 || o_ptr->art_name || o_ptr->name2)
1025 /* Pseudo-identified */
1026 else if (o_ptr->ident & IDENT_SENSE)
1028 switch (o_ptr->feeling)
1038 /* It's not nameless */
1046 /* Not known to be nameless */
1051 /*** Unaware items ***/
1052 if (IS_FLG(FLG_UNAWARE) && object_aware_p(o_ptr))
1055 /*** Wanted monster's corpse/skeletons ***/
1056 if (IS_FLG(FLG_WANTED) &&
1057 (o_ptr->tval != TV_CORPSE || !object_is_shoukinkubi(o_ptr)))
1060 /*** Unique monster's corpse/skeletons/statues ***/
1061 if (IS_FLG(FLG_UNIQUE) &&
1062 ((o_ptr->tval != TV_CORPSE && o_ptr->tval != TV_STATUE) ||
1063 !(r_info[o_ptr->pval].flags1 & RF1_UNIQUE)))
1066 /*** Human corpse/skeletons (for Daemon magic) ***/
1067 if (IS_FLG(FLG_HUMAN) &&
1068 (o_ptr->tval != TV_CORPSE ||
1069 !strchr("pht", r_info[o_ptr->pval].d_char)))
1072 /*** Unreadable spellbooks ***/
1073 if (IS_FLG(FLG_UNREADABLE) &&
1074 (o_ptr->tval < TV_LIFE_BOOK ||
1075 check_book_realm(o_ptr->tval, o_ptr->sval)))
1078 /*** First realm spellbooks ***/
1079 if (IS_FLG(FLG_REALM1) &&
1080 (REALM1_BOOK != o_ptr->tval ||
1081 p_ptr->pclass == CLASS_SORCERER ||
1082 p_ptr->pclass == CLASS_RED_MAGE))
1085 /*** Second realm spellbooks ***/
1086 if (IS_FLG(FLG_REALM2) &&
1087 (REALM2_BOOK != o_ptr->tval ||
1088 p_ptr->pclass == CLASS_SORCERER ||
1089 p_ptr->pclass == CLASS_RED_MAGE))
1092 /*** First rank spellbooks ***/
1093 if (IS_FLG(FLG_FIRST) &&
1094 (o_ptr->tval < TV_LIFE_BOOK || 0 != o_ptr->sval))
1097 /*** Second rank spellbooks ***/
1098 if (IS_FLG(FLG_SECOND) &&
1099 (o_ptr->tval < TV_LIFE_BOOK || 1 != o_ptr->sval))
1102 /*** Third rank spellbooks ***/
1103 if (IS_FLG(FLG_THIRD) &&
1104 (o_ptr->tval < TV_LIFE_BOOK || 2 != o_ptr->sval))
1107 /*** Fourth rank spellbooks ***/
1108 if (IS_FLG(FLG_FOURTH) &&
1109 (o_ptr->tval < TV_LIFE_BOOK || 3 != o_ptr->sval))
1113 if (IS_FLG(FLG_WEAPONS))
1115 if (!(TV_WEAPON_BEGIN <= o_ptr->tval && o_ptr->tval <= TV_WEAPON_END))
1118 else if (IS_FLG(FLG_ARMORS))
1120 if (!(TV_ARMOR_BEGIN <= o_ptr->tval && o_ptr->tval <= TV_ARMOR_END))
1123 else if (IS_FLG(FLG_MISSILES))
1127 case TV_SHOT: case TV_BOLT: case TV_ARROW:
1129 default: return FALSE;
1132 else if (IS_FLG(FLG_DEVICES))
1136 case TV_SCROLL: case TV_STAFF: case TV_WAND: case TV_ROD:
1138 default: return FALSE;
1141 else if (IS_FLG(FLG_LIGHTS))
1143 if (!(o_ptr->tval == TV_LITE))
1146 else if (IS_FLG(FLG_JUNKS))
1150 case TV_SKELETON: case TV_BOTTLE:
1151 case TV_JUNK: case TV_STATUE:
1153 default: return FALSE;
1156 else if (IS_FLG(FLG_SPELLBOOKS))
1158 if (!(o_ptr->tval >= TV_LIFE_BOOK))
1161 else if (IS_FLG(FLG_HAFTED))
1163 if (!(o_ptr->tval == TV_HAFTED))
1166 else if (IS_FLG(FLG_SHIELDS))
1168 if (!(o_ptr->tval == TV_SHIELD))
1171 else if (IS_FLG(FLG_BOWS))
1173 if (!(o_ptr->tval == TV_BOW))
1176 else if (IS_FLG(FLG_RINGS))
1178 if (!(o_ptr->tval == TV_RING))
1181 else if (IS_FLG(FLG_AMULETS))
1183 if (!(o_ptr->tval == TV_AMULET))
1186 else if (IS_FLG(FLG_SUITS))
1188 if (!(o_ptr->tval == TV_DRAG_ARMOR ||
1189 o_ptr->tval == TV_HARD_ARMOR ||
1190 o_ptr->tval == TV_SOFT_ARMOR))
1193 else if (IS_FLG(FLG_CLOAKS))
1195 if (!(o_ptr->tval == TV_CLOAK))
1198 else if (IS_FLG(FLG_HELMS))
1200 if (!(o_ptr->tval == TV_CROWN || o_ptr->tval == TV_HELM))
1203 else if (IS_FLG(FLG_GLOVES))
1205 if (!(o_ptr->tval == TV_GLOVES))
1208 else if (IS_FLG(FLG_BOOTS))
1210 if (!(o_ptr->tval == TV_BOOTS))
1213 else if (IS_FLG(FLG_FAVORITE))
1215 if (!is_favorite(o_ptr))
1219 /* Keyword don't match */
1223 if (strncmp(o_name, ptr, strlen(ptr))) return FALSE;
1228 if (!strstr_j(o_name, ptr)) return FALSE;
1230 if (!strstr(o_name, ptr)) return FALSE;
1234 /* TRUE when it need not to be 'collecting' */
1235 if (!IS_FLG(FLG_COLLECTING)) return TRUE;
1237 /* Check if there is a same item */
1238 for (j = 0; j < INVEN_PACK; j++)
1241 * 'Collecting' means the item must be absorbed
1242 * into an inventory slot.
1243 * But an item can not be absorbed into itself!
1245 if ((&inventory[j] != o_ptr) &&
1246 object_similar(&inventory[j], o_ptr))
1250 /* Not collecting */
1256 * A function for Auto-picker/destroyer
1257 * Examine whether the object matches to the list of keywords or not.
1259 int is_autopick(object_type *o_ptr)
1262 char o_name[MAX_NLEN];
1264 if (o_ptr->tval == TV_GOLD) return -1;
1266 object_desc(o_name, o_ptr, FALSE, 3);
1268 /* Force to be lower case string */
1269 for (i = 0; o_name[i]; i++)
1272 if (iskanji(o_name[i]))
1276 if (isupper(o_name[i]))
1277 o_name[i] = tolower(o_name[i]);
1280 for (i=0; i < max_autopick; i++)
1282 autopick_type *entry = &autopick_list[i];
1284 if (is_autopick_aux(o_ptr, entry, o_name)) return i;
1287 /* No matching entry */
1295 void auto_inscribe_item(int item, int idx)
1299 /* Get the item (in the pack) */
1300 if (item >= 0) o_ptr = &inventory[item];
1302 /* Get the item (on the floor) */
1303 else o_ptr = &o_list[0 - item];
1305 /* Auto-inscription or Re-inscribe for resistances {%} */
1306 if ((idx < 0 || !autopick_list[idx].insc) && !o_ptr->inscription)
1309 if (!o_ptr->inscription)
1310 o_ptr->inscription = quark_add(autopick_list[idx].insc);
1312 if (item > INVEN_PACK)
1314 /* Redraw inscription */
1315 p_ptr->window |= (PW_EQUIP);
1317 /* {.} and {$} effect p_ptr->warning and TRC_TELEPORT_SELF */
1318 p_ptr->update |= (PU_BONUS);
1322 /* Redraw inscription */
1323 p_ptr->window |= (PW_INVEN);
1329 * Automatically destroy items in this grid.
1331 static bool is_opt_confirm_destroy(object_type *o_ptr)
1333 if (!destroy_items) return FALSE;
1335 /* Known to be worthless? */
1337 if (object_value(o_ptr) > 0) return FALSE;
1340 if ((o_ptr->tval >= TV_MISSILE_BEGIN) && (o_ptr->tval <= TV_ARMOR_END)) return FALSE;
1343 if ((o_ptr->tval == TV_CHEST) && o_ptr->pval) return FALSE;
1347 if (o_ptr->tval == TV_CORPSE
1348 && object_is_shoukinkubi(o_ptr)) return FALSE;
1352 if (o_ptr->tval == TV_CORPSE) return FALSE;
1355 if ((o_ptr->tval == TV_SKELETON) || (o_ptr->tval == TV_BOTTLE) || (o_ptr->tval == TV_JUNK) || (o_ptr->tval == TV_STATUE)) return FALSE;
1359 if (p_ptr->prace == RACE_DEMON)
1361 if (o_ptr->tval == TV_CORPSE &&
1362 o_ptr->sval == SV_CORPSE &&
1363 strchr("pht", r_info[o_ptr->pval].d_char))
1367 if (p_ptr->pclass == CLASS_ARCHER)
1369 if (o_ptr->tval == TV_SKELETON ||
1370 (o_ptr->tval == TV_CORPSE && o_ptr->sval == SV_SKELETON))
1373 else if (p_ptr->pclass == CLASS_NINJA)
1375 if (o_ptr->tval == TV_LITE &&
1376 o_ptr->name2 == EGO_LITE_DARKNESS)
1379 else if (p_ptr->pclass == CLASS_BEASTMASTER ||
1380 p_ptr->pclass == CLASS_CAVALRY)
1382 if (o_ptr->tval == TV_WAND &&
1383 o_ptr->sval == SV_WAND_HEAL_MONSTER)
1388 if (o_ptr->tval == TV_GOLD) return FALSE;
1395 * Automatically destroy an item if it is to be destroyed
1397 static object_type autopick_last_destroyed_object;
1399 bool auto_destroy_item(int item, int autopick_idx)
1401 bool destroy = FALSE;
1404 /* Don't destroy equipped items */
1405 if (item > INVEN_PACK) return FALSE;
1407 /* Get the item (in the pack) */
1408 if (item >= 0) o_ptr = &inventory[item];
1410 /* Get the item (on the floor) */
1411 else o_ptr = &o_list[0 - item];
1413 /* Easy-Auto-Destroyer */
1414 if (is_opt_confirm_destroy(o_ptr)) destroy = TRUE;
1416 /* Protected by auto-picker */
1417 if (autopick_idx >= 0 &&
1418 !(autopick_list[autopick_idx].action & DO_AUTODESTROY))
1423 /* Auto-picker/destroyer */
1424 if (autopick_idx >= 0 &&
1425 (autopick_list[autopick_idx].action & DO_AUTODESTROY))
1429 /* Not to be destroyed */
1430 if (!destroy) return FALSE;
1432 /* Now decided to destroy */
1437 if (!can_player_destroy_object(o_ptr))
1439 char o_name[MAX_NLEN];
1441 /* Describe the object (with {terrible/special}) */
1442 object_desc(o_name, o_ptr, TRUE, 3);
1446 msg_format("%s¤ÏÇ˲õÉÔǽ¤À¡£", o_name);
1448 msg_format("You cannot auto-destroy %s.", o_name);
1455 /* Record name of destroyed item */
1456 COPY(&autopick_last_destroyed_object, o_ptr, object_type);
1459 o_ptr->marked |= OM_AUTODESTROY;
1460 p_ptr->notice |= PN_AUTODESTROY;
1467 * Auto-destroy marked item
1469 static void delayed_auto_destroy_aux(int item)
1473 /* Get the item (in the pack) */
1474 if (item >= 0) o_ptr = &inventory[item];
1476 /* Get the item (on the floor) */
1477 else o_ptr = &o_list[0 - item];
1479 if (o_ptr->k_idx && o_ptr->marked & OM_AUTODESTROY)
1481 char o_name[MAX_NLEN];
1483 /* Describe the object (with {terrible/special}) */
1484 object_desc(o_name, o_ptr, TRUE, 3);
1486 /* Eliminate the item (from the pack) */
1489 inven_item_increase(item, -(o_ptr->number));
1490 inven_item_optimize(item);
1493 /* Eliminate the item (from the floor) */
1496 delete_object_idx(0 - item);
1499 /* Print a message */
1501 msg_format("%s¤ò¼«Æ°Ç˲õ¤·¤Þ¤¹¡£", o_name);
1503 msg_format("Auto-destroying %s.", o_name);
1510 * Auto-destroy marked item in inventry and on floor
1512 void delayed_auto_destroy(void)
1517 * Scan inventry in reverse order to prevent
1518 * skipping after inven_item_optimize()
1520 for (item = INVEN_TOTAL - 1; item >= 0 ; item--)
1521 delayed_auto_destroy_aux(item);
1523 /* Scan the pile of objects */
1524 item = cave[py][px].o_idx;
1527 int next = o_list[item].next_o_idx;
1528 delayed_auto_destroy_aux(-item);
1535 * Automatically pickup/destroy items in this grid.
1537 void auto_pickup_items(cave_type *c_ptr)
1539 s16b this_o_idx, next_o_idx = 0;
1541 /* Scan the pile of objects */
1542 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1546 /* Acquire object */
1547 object_type *o_ptr = &o_list[this_o_idx];
1549 /* Acquire next object */
1550 next_o_idx = o_ptr->next_o_idx;
1552 idx = is_autopick(o_ptr);
1554 /* Item index for floor -1,-2,-3,... */
1555 auto_inscribe_item((-this_o_idx), idx);
1558 (autopick_list[idx].action & (DO_AUTOPICK | DO_QUERY_AUTOPICK)))
1562 if (!inven_carry_okay(o_ptr))
1564 char o_name[MAX_NLEN];
1566 /* Describe the object */
1567 object_desc(o_name, o_ptr, TRUE, 3);
1571 msg_format("¥¶¥Ã¥¯¤Ë¤Ï%s¤òÆþ¤ì¤ë·ä´Ö¤¬¤Ê¤¤¡£", o_name);
1573 msg_format("You have no room for %s.", o_name);
1575 /* Hack - remember that the item has given a message here. */
1576 o_ptr->marked |= OM_NOMSG;
1580 else if (autopick_list[idx].action & DO_QUERY_AUTOPICK)
1582 char out_val[MAX_NLEN+20];
1583 char o_name[MAX_NLEN];
1585 if (o_ptr->marked & OM_NO_QUERY)
1587 /* Already answered as 'No' */
1591 /* Describe the object */
1592 object_desc(o_name, o_ptr, TRUE, 3);
1595 sprintf(out_val, "%s¤ò½¦¤¤¤Þ¤¹¤«? ", o_name);
1597 sprintf(out_val, "Pick up %s? ", o_name);
1600 if (!get_check(out_val))
1602 /* Hack - remember that the item has given a message here. */
1603 o_ptr->marked |= (OM_NOMSG | OM_NO_QUERY);
1608 py_pickup_aux(this_o_idx);
1615 * When always_pickup is 'yes', we disable
1616 * auto-destroyer from autopick function, and do only
1617 * easy-auto-destroyer.
1621 if (auto_destroy_item((-this_o_idx), idx))
1628 #define PT_DEFAULT 0
1629 #define PT_WITH_PNAME 1
1632 * Get file name for autopick preference
1634 static cptr pickpref_filename(int filename_mode)
1637 static const char namebase[] = "picktype";
1639 static const char namebase[] = "pickpref";
1642 switch (filename_mode)
1645 return format("%s.prf", namebase);
1648 return format("%s-%s.prf", namebase, player_name);
1656 static const char autoregister_header[] = "?:$AUTOREGISTER";
1659 * Clear auto registered lines in the picktype.prf .
1661 static bool clear_auto_register(void)
1663 char tmp_file[1024];
1664 char pref_file[1024];
1669 bool autoregister = FALSE;
1672 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_WITH_PNAME));
1673 pref_fff = my_fopen(pref_file, "r");
1677 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_DEFAULT));
1678 pref_fff = my_fopen(pref_file, "r");
1687 /* Open a new (temporary) file */
1688 tmp_fff = my_fopen_temp(tmp_file, sizeof(tmp_file));
1692 /* Close the preference file */
1696 msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤¤Þ¤»¤ó¤Ç¤·¤¿¡£", tmp_file);
1698 msg_format("Failed to create temporary file %s.", tmp_file);
1705 /* Loop for every line */
1709 if (my_fgets(pref_fff, buf, sizeof(buf))) break;
1713 /* Delete auto-registered line */
1715 /* Count auto-destroy preference lines */
1716 if (buf[0] != '#' && buf[0] != '?') num++;
1719 /* We are looking for auto-registered line */
1722 if (streq(buf, autoregister_header))
1724 /* Delete all further lines */
1725 autoregister = TRUE;
1729 /* Copy orginally lines */
1730 fprintf(tmp_fff, "%s\n", buf);
1736 my_fclose(pref_fff);
1742 msg_format("°ÊÁ°¤Î¥¥ã¥é¥¯¥¿¡¼ÍѤμ«Æ°ÀßÄê(%d¹Ô)¤¬»Ä¤Ã¤Æ¤¤¤Þ¤¹¡£", num);
1743 strcpy(buf, "¸Å¤¤ÀßÄê¹Ô¤Ïºï½ü¤·¤Þ¤¹¡£¤è¤í¤·¤¤¤Ç¤¹¤«¡©");
1745 msg_format("Auto registered lines (%d lines) for previous character are remaining.", num);
1746 strcpy(buf, "These lines will be deleted. Are you sure? ");
1749 /* You can cancel it */
1750 if (!get_check(buf))
1753 autoregister = FALSE;
1756 msg_print("¥¨¥Ç¥£¥¿¤Î¥«¥Ã¥È&¥Ú¡¼¥¹¥ÈÅù¤ò»È¤Ã¤ÆɬÍפʹԤòÈòÆñ¤·¤Æ¤¯¤À¤µ¤¤¡£");
1758 msg_print("Use cut & paste of auto picker editor (_) to keep old prefs.");
1764 /* If there are some changes, overwrite the original file with new one */
1767 /* Copy contents of temporary file */
1769 tmp_fff = my_fopen(tmp_file, "r");
1770 pref_fff = my_fopen(pref_file, "w");
1772 while (!my_fgets(tmp_fff, buf, sizeof(buf)))
1773 fprintf(pref_fff, "%s\n", buf);
1775 my_fclose(pref_fff);
1779 /* Kill the temporary file */
1787 * Automatically register an auto-destroy preference line
1789 bool add_auto_register(object_type *o_ptr)
1792 char pref_file[1024];
1794 autopick_type an_entry, *entry = &an_entry;
1796 int match_autopick = is_autopick(o_ptr);
1798 /* Already registered */
1799 if (match_autopick != -1)
1802 byte act = autopick_list[match_autopick].action;
1805 if (act & DO_AUTOPICK) what = "¼«Æ°¤Ç½¦¤¦";
1806 else if (act & DO_AUTODESTROY) what = "¼«Æ°Ç˲õ¤¹¤ë";
1807 else if (act & DONT_AUTOPICK) what = "ÊüÃÖ¤¹¤ë";
1808 else /* if (act & DO_QUERY_AUTOPICK) */ what = "³Îǧ¤·¤Æ½¦¤¦";
1810 msg_format("¤½¤Î¥¢¥¤¥Æ¥à¤Ï´û¤Ë%s¤è¤¦¤ËÀßÄꤵ¤ì¤Æ¤¤¤Þ¤¹¡£", what);
1812 if (act & DO_AUTOPICK) what = "auto-pickup";
1813 else if (act & DO_AUTODESTROY) what = "auto-destroy";
1814 else if (act & DONT_AUTOPICK) what = "leave on floor";
1815 else /* if (act & DO_QUERY_AUTOPICK) */ what = "query auto-pickup";
1817 msg_format("The object is already registered to %s.", what);
1824 if (!p_ptr->autopick_autoregister)
1826 /* Clear old auto registered lines */
1827 if (!clear_auto_register()) return FALSE;
1830 /* Try a filename with player name */
1831 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_WITH_PNAME));
1832 pref_fff = my_fopen(pref_file, "r");
1836 /* Use default name */
1837 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_DEFAULT));
1838 pref_fff = my_fopen(pref_file, "r");
1841 /* Check the header */
1845 if (my_fgets(pref_fff, buf, sizeof(buf)))
1847 /* No header found */
1848 p_ptr->autopick_autoregister = FALSE;
1853 if (streq(buf, autoregister_header))
1855 /* Found the header */
1856 p_ptr->autopick_autoregister = TRUE;
1862 /* Close read only FILE* */
1865 /* Open for append */
1866 pref_fff = my_fopen(pref_file, "a");
1871 msg_format("%s ¤ò³«¤¯¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¤Ç¤·¤¿¡£", pref_file);
1873 msg_format("Failed to open %s.", pref_file);
1881 if (!p_ptr->autopick_autoregister)
1883 /* Add the header */
1884 fprintf(pref_fff, "%s\n", autoregister_header);
1887 fprintf(pref_fff, "%s\n", "# *·Ù¹ð!!* °Ê¹ß¤Î¹Ô¤Ï¼«Æ°ÅÐÏ¿¤µ¤ì¤¿¤â¤Î¤Ç¤¹¡£");
1888 fprintf(pref_fff, "%s\n", "# ¸å¤Ç¼«Æ°Åª¤Ëºï½ü¤µ¤ì¤Þ¤¹¤Î¤Ç¡¢É¬ÍפʹԤϾå¤ÎÊý¤Ø°ÜÆ°¤·¤Æ¤ª¤¤¤Æ¤¯¤À¤µ¤¤¡£");
1890 fprintf(pref_fff, "%s\n", "# *Waring!* The lines below will be deleated later.");
1891 fprintf(pref_fff, "%s\n", "# Keep it by cut & paste if you need these lines for future characters.");
1894 /* Now auto register is in-use */
1895 p_ptr->autopick_autoregister = TRUE;
1898 /* Get a preference entry */
1899 autopick_entry_from_object(entry, o_ptr);
1901 /* Set to auto-destroy (with no-display) */
1902 entry->action = DO_AUTODESTROY;
1904 /* Load the new line as preference */
1905 add_autopick_list(entry);
1907 /* Add a line to the file */
1908 /* Don't kill "entry" */
1909 fprintf(pref_fff, "%s\n", autopick_line_from_entry(entry));
1911 /* Close the file */
1918 /******** Auto-picker/destroyer editor **********/
1920 #define MAX_YANK MAX_LINELEN
1921 #define MAX_LINES 3000
1923 #define MARK_MARK 0x01
1924 #define MARK_BY_SHIFT 0x02
1926 #define LSTAT_BYPASS 0x01
1927 #define LSTAT_EXPRESSION 0x02
1928 #define LSTAT_AUTOREGISTER 0x04
1930 #define QUIT_WITHOUT_SAVE 1
1931 #define QUIT_AND_SAVE 2
1934 * Struct for yank buffer
1936 typedef struct chain_str {
1937 struct chain_str *next;
1943 * Data struct for text editor
1949 int old_wid, old_hgt;
1951 int old_upper, old_left;
1955 object_type *search_o_ptr;
1957 cptr last_destroyed;
1959 chain_str_type *yank;
1963 byte states[MAX_LINES];
1975 * Dirty flag for text editor
1977 #define DIRTY_ALL 0x01
1978 #define DIRTY_MODE 0x04
1979 #define DIRTY_SCREEN 0x08
1980 #define DIRTY_NOT_FOUND 0x10
1981 #define DIRTY_NO_SEARCH 0x20
1982 #define DIRTY_EXPRESSION 0x40
1986 * Describe which kind of object is Auto-picked/destroyed
1988 static void describe_autopick(char *buff, autopick_type *entry)
1990 cptr str = entry->name;
1991 byte act = entry->action;
1992 cptr insc = entry->insc;
1998 cptr before_str[100], body_str;
2001 body_str = "¥¢¥¤¥Æ¥à";
2003 /*** Collecting items ***/
2004 /*** Which can be absorbed into a slot as a bundle ***/
2005 if (IS_FLG(FLG_COLLECTING))
2006 before_str[before_n++] = "¼ý½¸Ãæ¤Ç´û¤Ë»ý¤Ã¤Æ¤¤¤ë¥¹¥í¥Ã¥È¤Ë¤Þ¤È¤á¤é¤ì¤ë";
2008 /*** Unidentified ***/
2009 if (IS_FLG(FLG_UNIDENTIFIED))
2010 before_str[before_n++] = "̤´ÕÄê¤Î";
2012 /*** Identified ***/
2013 if (IS_FLG(FLG_IDENTIFIED))
2014 before_str[before_n++] = "´ÕÄêºÑ¤ß¤Î";
2016 /*** *Identified* ***/
2017 if (IS_FLG(FLG_STAR_IDENTIFIED))
2018 before_str[before_n++] = "´°Á´¤Ë´ÕÄêºÑ¤ß¤Î";
2020 /*** Dice boosted (weapon of slaying) ***/
2021 if (IS_FLG(FLG_BOOSTED))
2023 before_str[before_n++] = "¥À¥á¡¼¥¸¥À¥¤¥¹¤¬Ä̾ï¤è¤êÂ礤¤";
2027 /*** Weapons whose dd*ds is more than nn ***/
2028 if (IS_FLG(FLG_MORE_THAN))
2030 static char more_than_desc_str[] = "___";
2031 before_str[before_n++] = "¥À¥á¡¼¥¸¥À¥¤¥¹¤ÎºÇÂçÃͤ¬";
2034 sprintf(more_than_desc_str,"%d", entry->dice);
2035 before_str[before_n++] = more_than_desc_str;
2036 before_str[before_n++] = "°Ê¾å¤Î";
2039 /*** Items whose magical bonus is more than nn ***/
2040 if (IS_FLG(FLG_MORE_BONUS))
2042 static char more_bonus_desc_str[] = "___";
2043 before_str[before_n++] = "½¤ÀµÃͤ¬(+";
2045 sprintf(more_bonus_desc_str,"%d", entry->bonus);
2046 before_str[before_n++] = more_bonus_desc_str;
2047 before_str[before_n++] = ")°Ê¾å¤Î";
2050 /*** Worthless items ***/
2051 if (IS_FLG(FLG_WORTHLESS))
2052 before_str[before_n++] = "Ź¤Ç̵²ÁÃͤÈȽÄꤵ¤ì¤ë";
2055 if (IS_FLG(FLG_ARTIFACT))
2057 before_str[before_n++] = "¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È¤Î";
2062 if (IS_FLG(FLG_EGO))
2064 before_str[before_n++] = "¥¨¥´¥¢¥¤¥Æ¥à¤Î";
2069 if (IS_FLG(FLG_NAMELESS))
2071 before_str[before_n++] = "¥¨¥´¤Ç¤â¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È¤Ç¤â¤Ê¤¤";
2075 /*** Unaware items ***/
2076 if (IS_FLG(FLG_UNAWARE))
2077 before_str[before_n++] = "̤´ÕÄê¤Ç¤½¤Î¸ú²Ì¤âȽÌÀ¤·¤Æ¤¤¤Ê¤¤";
2079 /*** Wanted monster's corpse/skeletons ***/
2080 if (IS_FLG(FLG_WANTED))
2082 before_str[before_n++] = "¥Ï¥ó¥¿¡¼»ö̳½ê¤Ç¾Þ¶â¼ó¤È¤µ¤ì¤Æ¤¤¤ë";
2083 body_str = "»àÂΤä¹ü";
2086 /*** Human corpse/skeletons (for Daemon magic) ***/
2087 if (IS_FLG(FLG_HUMAN))
2089 before_str[before_n++] = "°ËâËâË¡¤Ç»È¤¦¤¿¤á¤Î¿Í´Ö¤ä¥Ò¥å¡¼¥Þ¥Î¥¤¥É¤Î";
2090 body_str = "»àÂΤä¹ü";
2093 /*** Unique monster's corpse/skeletons/statues ***/
2094 if (IS_FLG(FLG_UNIQUE))
2096 before_str[before_n++] = "¥æ¥Ë¡¼¥¯¥â¥ó¥¹¥¿¡¼¤Î";
2097 body_str = "»àÂΤä¹ü";
2100 /*** Unreadable spellbooks ***/
2101 if (IS_FLG(FLG_UNREADABLE))
2103 before_str[before_n++] = "¤¢¤Ê¤¿¤¬Æɤá¤Ê¤¤Îΰè¤Î";
2104 body_str = "ËâË¡½ñ";
2107 /*** First realm spellbooks ***/
2108 if (IS_FLG(FLG_REALM1))
2110 before_str[before_n++] = "Âè°ìÎΰè¤Î";
2111 body_str = "ËâË¡½ñ";
2114 /*** Second realm spellbooks ***/
2115 if (IS_FLG(FLG_REALM2))
2117 before_str[before_n++] = "ÂèÆóÎΰè¤Î";
2118 body_str = "ËâË¡½ñ";
2121 /*** First rank spellbooks ***/
2122 if (IS_FLG(FLG_FIRST))
2124 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î1ºýÌܤÎ";
2125 body_str = "ËâË¡½ñ";
2128 /*** Second rank spellbooks ***/
2129 if (IS_FLG(FLG_SECOND))
2131 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î2ºýÌܤÎ";
2132 body_str = "ËâË¡½ñ";
2135 /*** Third rank spellbooks ***/
2136 if (IS_FLG(FLG_THIRD))
2138 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î3ºýÌܤÎ";
2139 body_str = "ËâË¡½ñ";
2142 /*** Fourth rank spellbooks ***/
2143 if (IS_FLG(FLG_FOURTH))
2145 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î4ºýÌܤÎ";
2146 body_str = "ËâË¡½ñ";
2150 if (IS_FLG(FLG_ITEMS))
2151 ; /* Nothing to do */
2152 else if (IS_FLG(FLG_WEAPONS))
2154 else if (IS_FLG(FLG_ARMORS))
2156 else if (IS_FLG(FLG_MISSILES))
2157 body_str = "ÃƤäÌð¤ä¥¯¥í¥¹¥Ü¥¦¤ÎÌð";
2158 else if (IS_FLG(FLG_DEVICES))
2159 body_str = "´¬Êª¤äËâË¡ËÀ¤ä¾ó¤ä¥í¥Ã¥É";
2160 else if (IS_FLG(FLG_LIGHTS))
2161 body_str = "¸÷¸»ÍѤΥ¢¥¤¥Æ¥à";
2162 else if (IS_FLG(FLG_JUNKS))
2163 body_str = "Àޤ줿ËÀÅù¤Î¥¬¥é¥¯¥¿";
2164 else if (IS_FLG(FLG_SPELLBOOKS))
2165 body_str = "ËâË¡½ñ";
2166 else if (IS_FLG(FLG_HAFTED))
2168 else if (IS_FLG(FLG_SHIELDS))
2170 else if (IS_FLG(FLG_BOWS))
2171 body_str = "¥¹¥ê¥ó¥°¤äµÝ¤ä¥¯¥í¥¹¥Ü¥¦";
2172 else if (IS_FLG(FLG_RINGS))
2174 else if (IS_FLG(FLG_AMULETS))
2175 body_str = "¥¢¥ß¥å¥ì¥Ã¥È";
2176 else if (IS_FLG(FLG_SUITS))
2178 else if (IS_FLG(FLG_CLOAKS))
2179 body_str = "¥¯¥í¡¼¥¯";
2180 else if (IS_FLG(FLG_HELMS))
2181 body_str = "¥Ø¥ë¥á¥Ã¥È¤ä´§";
2182 else if (IS_FLG(FLG_GLOVES))
2184 else if (IS_FLG(FLG_BOOTS))
2185 body_str = "¥Ö¡¼¥Ä";
2186 else if (IS_FLG(FLG_FAVORITE))
2187 body_str = "ÆÀ°ÕÉð´ï";
2191 strcat(buff, "Á´¤Æ¤Î");
2192 else for (i = 0; i < before_n && before_str[i]; i++)
2193 strcat(buff, before_str[i]);
2195 strcat(buff, body_str);
2205 strcat(buff, "¤Ç¡¢Ì¾Á°¤¬¡Ö");
2206 strncat(buff, str, 80);
2208 strcat(buff, "¡×¤Ç»Ï¤Þ¤ë¤â¤Î");
2210 strcat(buff, "¡×¤ò´Þ¤à¤â¤Î");
2215 strncat(buff, format("¤Ë¡Ö%s¡×", insc), 80);
2217 if (strstr(insc, "%%all"))
2218 strcat(buff, "(%%all¤ÏÁ´Ç½ÎϤòɽ¤¹±Ñ»ú¤Îµ¹æ¤ÇÃÖ´¹)");
2219 else if (strstr(insc, "%all"))
2220 strcat(buff, "(%all¤ÏÁ´Ç½ÎϤòɽ¤¹µ¹æ¤ÇÃÖ´¹)");
2221 else if (strstr(insc, "%%"))
2222 strcat(buff, "(%%¤ÏÄɲÃǽÎϤòɽ¤¹±Ñ»ú¤Îµ¹æ¤ÇÃÖ´¹)");
2223 else if (strstr(insc, "%"))
2224 strcat(buff, "(%¤ÏÄɲÃǽÎϤòɽ¤¹µ¹æ¤ÇÃÖ´¹)");
2226 strcat(buff, "¤È¹ï¤ó¤Ç");
2231 if (act & DONT_AUTOPICK)
2232 strcat(buff, "ÊüÃÖ¤¹¤ë¡£");
2233 else if (act & DO_AUTODESTROY)
2234 strcat(buff, "Ç˲õ¤¹¤ë¡£");
2235 else if (act & DO_QUERY_AUTOPICK)
2236 strcat(buff, "³Îǧ¤Î¸å¤Ë½¦¤¦¡£");
2238 strcat(buff, "½¦¤¦¡£");
2240 if (act & DO_DISPLAY)
2242 if (act & DONT_AUTOPICK)
2243 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'N'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
2244 else if (act & DO_AUTODESTROY)
2245 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'K'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
2247 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'M'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
2250 strcat(buff, "Á´ÂΥޥåפˤÏɽ¼¨¤·¤Ê¤¤¡£");
2254 cptr before_str[20], after_str[20], which_str[20], whose_str[20], body_str;
2255 int before_n = 0, after_n = 0, which_n = 0, whose_n = 0;
2259 /*** Collecting items ***/
2260 /*** Which can be absorbed into a slot as a bundle ***/
2261 if (IS_FLG(FLG_COLLECTING))
2262 which_str[which_n++] = "can be absorbed into an existing inventory slot";
2264 /*** Unidentified ***/
2265 if (IS_FLG(FLG_UNIDENTIFIED))
2266 before_str[before_n++] = "unidentified";
2268 /*** Identified ***/
2269 if (IS_FLG(FLG_IDENTIFIED))
2270 before_str[before_n++] = "identified";
2272 /*** *Identified* ***/
2273 if (IS_FLG(FLG_STAR_IDENTIFIED))
2274 before_str[before_n++] = "fully identified";
2276 /*** Worthless items ***/
2277 if (IS_FLG(FLG_WORTHLESS))
2279 before_str[before_n++] = "worthless";
2280 which_str[which_n++] = "can not be sold at stores";
2284 if (IS_FLG(FLG_ARTIFACT))
2286 before_str[before_n++] = "artifact";
2290 if (IS_FLG(FLG_EGO))
2292 before_str[before_n++] = "ego";
2296 if (IS_FLG(FLG_NAMELESS))
2298 body_str = "equipment";
2299 which_str[which_n++] = "is neither ego-item nor artifact";
2302 /*** Unaware items ***/
2303 if (IS_FLG(FLG_UNAWARE))
2305 before_str[before_n++] = "unidentified";
2306 whose_str[whose_n++] = "basic abilities are not known";
2309 /*** Dice boosted (weapon of slaying) ***/
2310 if (IS_FLG(FLG_BOOSTED))
2312 body_str = "weapons";
2313 whose_str[whose_n++] = "damage dice is bigger than normal";
2316 /*** Weapons whose dd*ds is more than nn ***/
2317 if (IS_FLG(FLG_MORE_THAN))
2319 static char more_than_desc_str[] =
2320 "maximum damage from dice is bigger than __";
2321 body_str = "weapons";
2323 sprintf(more_than_desc_str + sizeof(more_than_desc_str) - 3,
2325 whose_str[whose_n++] = more_than_desc_str;
2328 /*** Items whose magical bonus is more than nn ***/
2329 if (IS_FLG(FLG_MORE_BONUS))
2331 static char more_bonus_desc_str[] =
2332 "magical bonus is bigger than (+__)";
2334 sprintf(more_bonus_desc_str + sizeof(more_bonus_desc_str) - 4,
2335 "%d)", entry->bonus);
2336 whose_str[whose_n++] = more_bonus_desc_str;
2339 /*** Wanted monster's corpse/skeletons ***/
2340 if (IS_FLG(FLG_WANTED))
2342 body_str = "corpse or skeletons";
2343 which_str[which_n++] = "is wanted at the Hunter's Office";
2346 /*** Human corpse/skeletons (for Daemon magic) ***/
2347 if (IS_FLG(FLG_HUMAN))
2349 before_str[before_n++] = "humanoid";
2350 body_str = "corpse or skeletons";
2351 which_str[which_n++] = "can be used for Daemon magic";
2354 /*** Unique monster's corpse/skeletons/statues ***/
2355 if (IS_FLG(FLG_UNIQUE))
2357 before_str[before_n++] = "unique monster's";
2358 body_str = "corpse or skeletons";
2361 /*** Unreadable spellbooks ***/
2362 if (IS_FLG(FLG_UNREADABLE))
2364 body_str = "spellbooks";
2365 after_str[after_n++] = "of different realms from yours";
2368 /*** First realm spellbooks ***/
2369 if (IS_FLG(FLG_REALM1))
2371 body_str = "spellbooks";
2372 after_str[after_n++] = "of your first realm";
2375 /*** Second realm spellbooks ***/
2376 if (IS_FLG(FLG_REALM2))
2378 body_str = "spellbooks";
2379 after_str[after_n++] = "of your second realm";
2382 /*** First rank spellbooks ***/
2383 if (IS_FLG(FLG_FIRST))
2385 before_str[before_n++] = "first one of four";
2386 body_str = "spellbooks";
2389 /*** Second rank spellbooks ***/
2390 if (IS_FLG(FLG_SECOND))
2392 before_str[before_n++] = "second one of four";
2393 body_str = "spellbooks";
2396 /*** Third rank spellbooks ***/
2397 if (IS_FLG(FLG_THIRD))
2399 before_str[before_n++] = "third one of four";
2400 body_str = "spellbooks";
2403 /*** Fourth rank spellbooks ***/
2404 if (IS_FLG(FLG_FOURTH))
2406 before_str[before_n++] = "fourth one of four";
2407 body_str = "spellbooks";
2411 if (IS_FLG(FLG_ITEMS))
2412 ; /* Nothing to do */
2413 else if (IS_FLG(FLG_WEAPONS))
2414 body_str = "weapons";
2415 else if (IS_FLG(FLG_ARMORS))
2416 body_str = "armors";
2417 else if (IS_FLG(FLG_MISSILES))
2418 body_str = "shots, arrows or crossbow bolts";
2419 else if (IS_FLG(FLG_DEVICES))
2420 body_str = "scrolls, wands, staves or rods";
2421 else if (IS_FLG(FLG_LIGHTS))
2422 body_str = "light sources";
2423 else if (IS_FLG(FLG_JUNKS))
2424 body_str = "junk such as broken sticks";
2425 else if (IS_FLG(FLG_SPELLBOOKS))
2426 body_str = "spellbooks";
2427 else if (IS_FLG(FLG_HAFTED))
2428 body_str = "hafted weapons";
2429 else if (IS_FLG(FLG_SHIELDS))
2430 body_str = "shields";
2431 else if (IS_FLG(FLG_BOWS))
2432 body_str = "slings, bows or crossbows";
2433 else if (IS_FLG(FLG_RINGS))
2435 else if (IS_FLG(FLG_AMULETS))
2436 body_str = "amulets";
2437 else if (IS_FLG(FLG_SUITS))
2438 body_str = "body armors";
2439 else if (IS_FLG(FLG_CLOAKS))
2440 body_str = "cloaks";
2441 else if (IS_FLG(FLG_HELMS))
2442 body_str = "helms or crowns";
2443 else if (IS_FLG(FLG_GLOVES))
2444 body_str = "gloves";
2445 else if (IS_FLG(FLG_BOOTS))
2447 else if (IS_FLG(FLG_FAVORITE))
2448 body_str = "favorite weapons";
2450 /* Prepare a string for item name */
2457 whose_str[whose_n++] = "name is beginning with \"";
2460 which_str[which_n++] = "have \"";
2464 /* Describe action flag */
2465 if (act & DONT_AUTOPICK)
2466 strcpy(buff, "Leave on floor ");
2467 else if (act & DO_AUTODESTROY)
2468 strcpy(buff, "Destroy ");
2469 else if (act & DO_QUERY_AUTOPICK)
2470 strcpy(buff, "Ask to pick up ");
2472 strcpy(buff, "Pickup ");
2474 /* Auto-insctiption */
2477 strncat(buff, format("and inscribe \"%s\"", insc), 80);
2479 if (strstr(insc, "%all"))
2480 strcat(buff, ", replacing %all with code string representing all abilities,");
2481 else if (strstr(insc, "%"))
2482 strcat(buff, ", replacing % with code string representing extra random abilities,");
2484 strcat(buff, " on ");
2489 strcat(buff, "all ");
2490 else for (i = 0; i < before_n && before_str[i]; i++)
2492 strcat(buff, before_str[i]);
2497 strcat(buff, body_str);
2500 for (i = 0; i < after_n && after_str[i]; i++)
2503 strcat(buff, after_str[i]);
2507 for (i = 0; i < whose_n && whose_str[i]; i++)
2510 strcat(buff, " whose ");
2512 strcat(buff, ", and ");
2514 strcat(buff, whose_str[i]);
2517 /* Item name ; whose name is beginning with "str" */
2524 /* whose ..., and which .... */
2525 if (whose_n && which_n)
2526 strcat(buff, ", and ");
2529 for (i = 0; i < which_n && which_str[i]; i++)
2532 strcat(buff, " which ");
2534 strcat(buff, ", and ");
2536 strcat(buff, which_str[i]);
2539 /* Item name ; which have "str" as part of its name */
2542 strncat(buff, str, 80);
2543 strcat(buff, "\" as part of its name");
2547 /* Describe whether it will be displayed on the full map or not */
2548 if (act & DO_DISPLAY)
2550 if (act & DONT_AUTOPICK)
2551 strcat(buff, " Display these items when you press the N key in the full 'M'ap.");
2552 else if (act & DO_AUTODESTROY)
2553 strcat(buff, " Display these items when you press the K key in the full 'M'ap.");
2555 strcat(buff, " Display these items when you press the M key in the full 'M'ap.");
2558 strcat(buff, " Not displayed in the full map.");
2565 * Read whole lines of a file to memory
2567 static cptr *read_text_lines(cptr filename, bool user)
2569 cptr *lines_list = NULL;
2577 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2581 path_build(buf, sizeof(buf), ANGBAND_DIR_PREF, filename);
2585 fff = my_fopen(buf, "r");
2589 /* Allocate list of pointers */
2590 C_MAKE(lines_list, MAX_LINES, cptr);
2593 while (0 == my_fgets(fff, buf, sizeof(buf)))
2595 lines_list[lines++] = string_make(buf);
2596 if (lines >= MAX_LINES - 1) break;
2599 lines_list[0] = string_make("");
2604 if (!fff) return NULL;
2609 static cptr *read_pickpref_text_lines(int *filename_mode_p)
2614 *filename_mode_p = PT_WITH_PNAME;
2615 strcpy(buf, pickpref_filename(*filename_mode_p));
2616 lines_list = read_text_lines(buf, TRUE);
2620 *filename_mode_p = PT_DEFAULT;
2621 strcpy(buf, pickpref_filename(*filename_mode_p));
2622 lines_list = read_text_lines(buf, TRUE);
2627 strcpy(buf, pickpref_filename(*filename_mode_p));
2628 lines_list = read_text_lines(buf, FALSE);
2633 /* Allocate list of pointers */
2634 C_MAKE(lines_list, MAX_LINES, cptr);
2635 lines_list[0] = string_make("");
2642 * Write whole lines of memory to a file.
2644 static bool write_text_lines(cptr filename, cptr *lines_list)
2651 /* Build the filename */
2652 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2655 fff = my_fopen(buf, "w");
2658 for (lines = 0; lines_list[lines]; lines++)
2659 my_fputs(fff, lines_list[lines], 1024);
2664 if (!fff) return FALSE;
2670 * Free memory of lines_list.
2672 static void free_text_lines(cptr *lines_list)
2676 for (lines = 0; lines_list[lines]; lines++)
2677 string_free(lines_list[lines]);
2679 /* free list of pointers */
2680 C_FREE((char **)lines_list, MAX_LINES, char *);
2685 * Delete or insert string
2687 static void toggle_keyword(text_body_type *tb, int flg)
2689 int by1, by2, bx1, bx2, y;
2693 /* Select this line */
2700 if (tb->my < tb->cy)
2715 /* String on these lines are not really selected */
2716 if (tb->lines_list[by1][bx1] == '\0' && by1 < tb->cy) by1++;
2717 if (bx2 == 0 && by1 < by2) by2--;
2720 /* Set/Reset flag of each line */
2721 for (y = by1; y <= by2; y++)
2723 autopick_type an_entry, *entry = &an_entry;
2725 if (!autopick_new_entry(entry, tb->lines_list[y], !fixed)) continue;
2727 string_free(tb->lines_list[y]);
2731 /* Add? or Remove? */
2732 if (!IS_FLG(flg)) add = TRUE;
2735 /* No more change */
2739 /* You can use only one noun flag */
2740 if (FLG_NOUN_BEGIN <= flg && flg <= FLG_NOUN_END)
2743 for (i = FLG_NOUN_BEGIN; i <= FLG_NOUN_END; i++)
2747 /* You can use only one identify state flag */
2748 else if (FLG_UNAWARE <= flg && flg <= FLG_STAR_IDENTIFIED)
2751 for (i = FLG_UNAWARE; i <= FLG_STAR_IDENTIFIED; i++)
2755 /* You can use only one flag in artifact/ego/nameless */
2756 else if (FLG_ARTIFACT <= flg && flg <= FLG_NAMELESS)
2759 for (i = FLG_ARTIFACT; i <= FLG_NAMELESS; i++)
2763 if (add) ADD_FLG(flg);
2766 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
2769 tb->dirty_flags |= DIRTY_ALL;
2771 /* Text is changed */
2778 * Change command letter
2780 static void toggle_command_letter(text_body_type *tb, byte flg)
2782 autopick_type an_entry, *entry = &an_entry;
2783 int by1, by2, bx1, bx2, y;
2787 /* Select this line */
2794 if (tb->my < tb->cy)
2809 /* String on these lines are not really selected */
2810 if (tb->lines_list[by1][bx1] == '\0' && by1 < tb->cy) by1++;
2811 if (bx2 == 0 && by1 < by2) by2--;
2813 /* Set/Reset flag of each line */
2814 for (y = by1; y <= by2; y++)
2818 if (!autopick_new_entry(entry, tb->lines_list[y], FALSE)) continue;
2820 string_free(tb->lines_list[y]);
2824 /* Add? or Remove? */
2825 if (!(entry->action & flg)) add = TRUE;
2828 /* No more change */
2832 /* Count number of letter (by negative number) */
2833 if (entry->action & DONT_AUTOPICK) wid--;
2834 else if (entry->action & DO_AUTODESTROY) wid--;
2835 else if (entry->action & DO_QUERY_AUTOPICK) wid--;
2836 if (!(entry->action & DO_DISPLAY)) wid--;
2838 /* Set/Reset the flag */
2839 if (flg != DO_DISPLAY)
2841 entry->action &= ~(DO_AUTOPICK | DONT_AUTOPICK | DO_AUTODESTROY | DO_QUERY_AUTOPICK);
2842 if (add) entry->action |= flg;
2843 else entry->action |= DO_AUTOPICK;
2847 entry->action &= ~(DO_DISPLAY);
2848 if (add) entry->action |= flg;
2851 /* Correct cursor location */
2854 if (entry->action & DONT_AUTOPICK) wid++;
2855 else if (entry->action & DO_AUTODESTROY) wid++;
2856 else if (entry->action & DO_QUERY_AUTOPICK) wid++;
2857 if (!(entry->action & DO_DISPLAY)) wid++;
2859 if (wid > 0) tb->cx++;
2860 if (wid < 0 && tb->cx > 0) tb->cx--;
2863 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
2866 tb->dirty_flags |= DIRTY_ALL;
2868 /* Text is changed */
2874 * Delete or insert string
2876 static void add_keyword(text_body_type *tb, int flg)
2878 int by1, by2, bx1, bx2, y;
2880 /* Select this line */
2887 if (tb->my < tb->cy)
2902 /* String on these lines are not really selected */
2903 if (tb->lines_list[by1][bx1] == '\0' && by1 < tb->cy) by1++;
2904 if (bx2 == 0 && by1 < by2) by2--;
2906 /* Set/Reset flag of each line */
2907 for (y = by1; y <= by2; y++)
2909 autopick_type an_entry, *entry = &an_entry;
2911 if (!autopick_new_entry(entry, tb->lines_list[y], FALSE)) continue;
2913 /* There is the flag already */
2916 /* Free memory for the entry */
2917 autopick_free_entry(entry);
2922 string_free(tb->lines_list[y]);
2924 /* Remove all noun flag */
2925 if (FLG_NOUN_BEGIN <= flg && flg <= FLG_NOUN_END)
2928 for (i = FLG_NOUN_BEGIN; i <= FLG_NOUN_END; i++)
2934 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
2937 tb->dirty_flags |= DIRTY_ALL;
2939 /* Text is changed */
2946 * Check if this line is expression or not.
2947 * And update it if it is.
2949 static void check_expression_line(text_body_type *tb, int y)
2951 cptr s = tb->lines_list[y];
2953 if ((s[0] == '?' && s[1] == ':') ||
2954 (tb->states[y] & LSTAT_BYPASS))
2956 /* Expressions need re-evaluation */
2957 tb->dirty_flags |= DIRTY_EXPRESSION;
2963 * Insert return code and split the line
2965 static bool insert_return_code(text_body_type *tb)
2967 char buf[MAX_LINELEN];
2970 for (k = 0; tb->lines_list[k]; k++)
2971 /* count number of lines */ ;
2973 if (k >= MAX_LINES - 2) return FALSE;
2976 /* Move down lines */
2977 for (; tb->cy < k; k--)
2979 tb->lines_list[k+1] = tb->lines_list[k];
2980 tb->states[k+1] = tb->states[k];
2983 /* Split current line */
2984 for (i = j = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
2987 if (iskanji(tb->lines_list[tb->cy][i]))
2988 buf[j++] = tb->lines_list[tb->cy][i++];
2990 buf[j++] = tb->lines_list[tb->cy][i];
2993 tb->lines_list[tb->cy+1] = string_make(&tb->lines_list[tb->cy][i]);
2994 string_free(tb->lines_list[tb->cy]);
2995 tb->lines_list[tb->cy] = string_make(buf);
2997 /* Expressions need re-evaluation */
2998 tb->dirty_flags |= DIRTY_EXPRESSION;
3000 /* Text is changed */
3008 * Choose an item and get auto-picker entry from it.
3010 static object_type *choose_object(cptr q, cptr s)
3014 if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR | USE_EQUIP))) return NULL;
3016 /* Get the item (in the pack) */
3017 if (item >= 0) return &inventory[item];
3019 /* Get the item (on the floor) */
3020 else return &o_list[0 - item];
3025 * Choose an item and get auto-picker entry from it.
3027 static bool entry_from_choosed_object(autopick_type *entry)
3034 q = "¤É¤Î¥¢¥¤¥Æ¥à¤òÅÐÏ¿¤·¤Þ¤¹¤«? ";
3035 s = "¥¢¥¤¥Æ¥à¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£";
3037 q = "Enter which item? ";
3038 s = "You have nothing to enter.";
3040 o_ptr = choose_object(q, s);
3041 if (!o_ptr) return FALSE;
3043 autopick_entry_from_object(entry, o_ptr);
3049 * Choose an item for search
3051 static byte get_object_for_search(object_type **o_handle, cptr *search_strp)
3053 char buf[MAX_NLEN+20];
3059 q = "¤É¤Î¥¢¥¤¥Æ¥à¤ò¸¡º÷¤·¤Þ¤¹¤«? ";
3060 s = "¥¢¥¤¥Æ¥à¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£";
3062 q = "Enter which item? ";
3063 s = "You have nothing to enter.";
3065 o_ptr = choose_object(q, s);
3066 if (!o_ptr) return 0;
3070 string_free(*search_strp);
3071 object_desc(buf, *o_handle, FALSE, 3);
3072 *search_strp = string_make(format("<%s>", buf));
3078 * Prepare for search by destroyed object
3080 static byte get_destroyed_object_for_search(object_type **o_handle, cptr *search_strp)
3082 char buf[MAX_NLEN+20];
3084 if (!autopick_last_destroyed_object.k_idx) return 0;
3086 *o_handle = &autopick_last_destroyed_object;
3088 string_free(*search_strp);
3089 object_desc(buf, *o_handle, FALSE, 3);
3090 *search_strp = string_make(format("<%s>", buf));
3096 * Choose an item or string for search
3098 static byte get_string_for_search(object_type **o_handle, cptr *search_strp)
3101 char buf[MAX_NLEN+20];
3104 int k_flag[MAX_NLEN+20];
3105 char prompt[] = "¸¡º÷(^I:»ý¤Áʪ ^L:Ç˲õ¤µ¤ì¤¿Êª): ";
3107 char prompt[] = "Search key(^I:inven ^L:destroyed): ";
3109 int col = sizeof(prompt) - 1;
3111 if (*search_strp) strcpy(buf, *search_strp);
3114 /* Display prompt */
3117 /* Display the default answer */
3118 Term_erase(col, 0, 255);
3119 Term_putstr(col, 0, -1, TERM_YELLOW, buf);
3129 Term_gotoxy(col + pos, 0);
3134 /* Count length of macro trigger which induced this key */
3135 trig_len = strlen(inkey_macro_trigger_string);
3137 /* HACK -- ignore macro defined on ASCII keys */
3139 if (trig_len == 1 && !iskanji(inkey_macro_trigger_string[0]))
3144 /* Get original key */
3145 key = inkey_macro_trigger_string[0];
3147 /* Kill further macro expansion */
3152 if (key == 0x7F) key = KTRL('d');
3155 /* Analyze the key */
3168 if (!pos && *o_handle) return (back ? -1 : 1);
3169 string_free(*search_strp);
3170 *search_strp = string_make(buf);
3172 return (back ? -1 : 1);
3176 return get_object_for_search(o_handle, search_strp);
3179 /* Prepare string for destroyed object if there is one. */
3180 if (get_destroyed_object_for_search(o_handle, search_strp))
3190 if (k_flag[pos]) pos--;
3205 if (pos + 1 < MAX_NLEN)
3213 else if (pos < MAX_NLEN && isprint(key))
3220 if (pos < MAX_NLEN && isprint(key)) buf[pos++] = key;
3229 /* Update the entry */
3230 Term_erase(col, 0, 255);
3231 Term_putstr(col, 0, -1, TERM_WHITE, buf);
3239 * Search next line matches for o_ptr
3241 static bool search_for_object(text_body_type *tb, object_type *o_ptr, bool forward)
3244 autopick_type an_entry, *entry = &an_entry;
3245 char o_name[MAX_NLEN];
3247 object_desc(o_name, o_ptr, FALSE, 3);
3249 /* Force to be lower case string */
3250 for (i = 0; o_name[i]; i++)
3253 if (iskanji(o_name[i]))
3257 if (isupper(o_name[i]))
3258 o_name[i] = tolower(o_name[i]);
3267 if (!tb->lines_list[++i]) break;
3274 /* Ignore bypassed lines */
3275 if (tb->states[i] & LSTAT_BYPASS) continue;
3277 if (!autopick_new_entry(entry, tb->lines_list[i], FALSE)) continue;
3279 if (is_autopick_aux(o_ptr, entry, o_name))
3292 * Search next line matches to the string
3294 static bool search_for_string(text_body_type *tb, cptr search_str, bool forward)
3304 if (!tb->lines_list[++i]) break;
3311 /* Ignore bypassed lines */
3312 if (tb->states[i] & LSTAT_BYPASS) continue;
3315 pos = strstr_j(tb->lines_list[i], search_str);
3317 pos = strstr(tb->lines_list[i], search_str);
3321 tb->cx = (int)(pos - tb->lines_list[i]);
3334 * Editor command id's
3337 #define EC_SAVEQUIT 2
3348 #define EC_PGDOWN 13
3350 #define EC_BOTTOM 15
3355 #define EC_KILL_LINE 20
3356 #define EC_DELETE_CHAR 21
3357 #define EC_BACKSPACE 22
3358 #define EC_SEARCH_STR 23
3359 #define EC_SEARCH_FORW 24
3360 #define EC_SEARCH_BACK 25
3361 #define EC_SEARCH_OBJ 26
3362 #define EC_SEARCH_DESTROYED 27
3363 #define EC_INSERT_OBJECT 28
3364 #define EC_INSERT_DESTROYED 29
3365 #define EC_INSERT_BLOCK 30
3366 #define EC_INSERT_MACRO 31
3367 #define EC_INSERT_KEYMAP 32
3368 #define EC_CL_AUTOPICK 33
3369 #define EC_CL_DESTROY 34
3370 #define EC_CL_LEAVE 35
3371 #define EC_CL_QUERY 36
3372 #define EC_CL_NO_DISP 37
3373 #define EC_OK_COLLECTING 38
3374 #define EC_IK_UNAWARE 39
3375 #define EC_IK_UNIDENTIFIED 40
3376 #define EC_IK_IDENTIFIED 41
3377 #define EC_IK_STAR_IDENTIFIED 42
3378 #define EC_OK_BOOSTED 43
3379 #define EC_OK_MORE_THAN 44
3380 #define EC_OK_MORE_BONUS 45
3381 #define EC_OK_WORTHLESS 46
3382 #define EC_OK_ARTIFACT 47
3383 #define EC_OK_EGO 48
3384 #define EC_OK_NAMELESS 49
3385 #define EC_OK_WANTED 50
3386 #define EC_OK_UNIQUE 51
3387 #define EC_OK_HUMAN 52
3388 #define EC_OK_UNREADABLE 53
3389 #define EC_OK_REALM1 54
3390 #define EC_OK_REALM2 55
3391 #define EC_OK_FIRST 56
3392 #define EC_OK_SECOND 57
3393 #define EC_OK_THIRD 58
3394 #define EC_OK_FOURTH 59
3395 #define EC_KK_WEAPONS 60
3396 #define EC_KK_FAVORITE 61
3397 #define EC_KK_ARMORS 62
3398 #define EC_KK_MISSILES 63
3399 #define EC_KK_DEVICES 64
3400 #define EC_KK_LIGHTS 65
3401 #define EC_KK_JUNKS 66
3402 #define EC_KK_SPELLBOOKS 67
3403 #define EC_KK_SHIELDS 68
3404 #define EC_KK_BOWS 69
3405 #define EC_KK_RINGS 70
3406 #define EC_KK_AMULETS 71
3407 #define EC_KK_SUITS 72
3408 #define EC_KK_CLOAKS 73
3409 #define EC_KK_HELMS 74
3410 #define EC_KK_GLOVES 75
3411 #define EC_KK_BOOTS 76
3417 #define MN_QUIT "¥»¡¼¥Ö̵¤·¤Ç½ªÎ»"
3418 #define MN_SAVEQUIT "¥»¡¼¥Ö¤·¤Æ½ªÎ»"
3419 #define MN_REVERT "Á´¤Æ¤ÎÊѹ¹¤òÇË´þ"
3420 #define MN_HELP "¥Ø¥ë¥×"
3422 #define MN_MOVE "¥«¡¼¥½¥ë°ÜÆ°"
3423 #define MN_LEFT "º¸"
3424 #define MN_DOWN "²¼"
3426 #define MN_RIGHT "±¦"
3427 #define MN_BOL "¹Ô¤ÎÀèƬ"
3428 #define MN_EOL "¹Ô¤Î½ªÃ¼"
3429 #define MN_PGUP "¾å¤Î¥Ú¡¼¥¸"
3430 #define MN_PGDOWN "²¼¤Î¥Ú¡¼¥¸"
3431 #define MN_TOP "1¹ÔÌܤذÜÆ°"
3432 #define MN_BOTTOM "ºÇ²¼¹Ô¤Ø°ÜÆ°"
3434 #define MN_EDIT "ÊÔ½¸"
3435 #define MN_CUT "¥«¥Ã¥È"
3436 #define MN_COPY "¥³¥Ô¡¼"
3437 #define MN_PASTE "¥Ú¡¼¥¹¥È"
3438 #define MN_BLOCK "ÁªÂòÈϰϤλØÄê"
3439 #define MN_KILL_LINE "¹Ô¤Î»Ä¤ê¤òºï½ü"
3440 #define MN_DELETE_CHAR "1ʸ»úºï½ü"
3441 #define MN_BACKSPACE "¥Ð¥Ã¥¯¥¹¥Ú¡¼¥¹"
3442 #define MN_RETURN "²þ¹Ô"
3443 #define MN_RETURN "²þ¹Ô"
3445 #define MN_SEARCH "¸¡º÷"
3446 #define MN_SEARCH_STR "ʸ»úÎó¤Ç¸¡º÷"
3447 #define MN_SEARCH_FORW "Á°Êý¤ØºÆ¸¡º÷"
3448 #define MN_SEARCH_BACK "¸åÊý¤ØºÆ¸¡º÷"
3449 #define MN_SEARCH_OBJ "¥¢¥¤¥Æ¥à¤òÁªÂò¤·¤Æ¸¡º÷"
3450 #define MN_SEARCH_DESTROYED "¼«Æ°Ç˲õ¤µ¤ì¤¿¥¢¥¤¥Æ¥à¤Ç¸¡º÷"
3452 #define MN_INSERT "¿§¡¹ÁÞÆþ"
3453 #define MN_INSERT_OBJECT "ÁªÂò¤·¤¿¥¢¥¤¥Æ¥à¤Î̾Á°¤òÁÞÆþ"
3454 #define MN_INSERT_DESTROYED "¼«Æ°Ç˲õ¤µ¤ì¤¿¥¢¥¤¥Æ¥à¤Î̾Á°¤òÁÞÆþ"
3455 #define MN_INSERT_BLOCK "¾ò·ïʬ´ô¥Ö¥í¥Ã¥¯¤ÎÎã¤òÁÞÆþ"
3456 #define MN_INSERT_MACRO "¥Þ¥¯¥íÄêµÁ¤òÁÞÆþ"
3457 #define MN_INSERT_KEYMAP "¥¡¼¥Þ¥Ã¥×ÄêµÁ¤òÁÞÆþ"
3459 #define MN_COMMAND_LETTER "½¦¤¤/Ç˲õ/ÊüÃÖ¤ÎÁªÂò"
3460 #define MN_CL_AUTOPICK "¡Ö ¡× (¼«Æ°½¦¤¤)"
3461 #define MN_CL_DESTROY "¡Ö!¡× (¼«Æ°Ç˲õ)"
3462 #define MN_CL_LEAVE "¡Ö~¡× (ÊüÃÖ)"
3463 #define MN_CL_QUERY "¡Ö;¡× (³Îǧ¤·¤Æ½¦¤¦)"
3464 #define MN_CL_NO_DISP "¡Ö(¡× (¥Þ¥Ã¥×¥³¥Þ¥ó¥É¤Çɽ¼¨¤·¤Ê¤¤)"
3466 #define MN_ADJECTIVE_GEN "·ÁÍÆ»ì(°ìÈÌ)¤ÎÁªÂò"
3468 #define MN_ADJECTIVE_SPECIAL "·ÁÍÆ»ì(Æüì)¤ÎÁªÂò"
3469 #define MN_BOOSTED "¥À¥¤¥¹Ìܤΰ㤦 (Éð´ï)"
3470 #define MN_MORE_THAN "¥À¥¤¥¹ÌÜ # °Ê¾å¤Î (Éð´ï)"
3471 #define MN_MORE_BONUS "½¤ÀµÃÍ # °Ê¾å¤Î (»ØÎØÅù)"
3472 #define MN_ARTIFACT "¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È (ÁõÈ÷)"
3473 #define MN_EGO "¥¨¥´ (ÁõÈ÷)"
3474 #define MN_NAMELESS "̵ÌäΠ(ÁõÈ÷)"
3475 #define MN_WANTED "¾Þ¶â¼ó¤Î (»àÂÎ)"
3476 #define MN_UNIQUE "¥æ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼¤Î (»àÂÎ)"
3477 #define MN_HUMAN "¿Í´Ö¤Î (»àÂÎ)"
3478 #define MN_UNREADABLE "Æɤá¤Ê¤¤ (ËâË¡½ñ)"
3479 #define MN_REALM1 "Âè°ìÎΰè¤Î (ËâË¡½ñ)"
3480 #define MN_REALM2 "ÂèÆóÎΰè¤Î (ËâË¡½ñ)"
3481 #define MN_FIRST "1ºýÌܤΠ(ËâË¡½ñ)"
3482 #define MN_SECOND "2ºýÌܤΠ(ËâË¡½ñ)"
3483 #define MN_THIRD "3ºýÌܤΠ(ËâË¡½ñ)"
3484 #define MN_FOURTH "4ºýÌܤΠ(ËâË¡½ñ)"
3486 #define MN_NOUN "̾»ì¤ÎÁªÂò"
3490 #define MN_QUIT "Quit without save"
3491 #define MN_SAVEQUIT "Save & Quit"
3492 #define MN_REVERT "Revert all changes"
3493 #define MN_HELP "Help"
3495 #define MN_MOVE "Move cursor"
3496 #define MN_LEFT "Left"
3497 #define MN_DOWN "Down"
3499 #define MN_RIGHT "Right"
3500 #define MN_BOL "Beggining of line"
3501 #define MN_EOL "End of line"
3502 #define MN_PGUP "Page up"
3503 #define MN_PGDOWN "Page down"
3504 #define MN_TOP "Top"
3505 #define MN_BOTTOM "Bottom"
3507 #define MN_EDIT "Edit"
3508 #define MN_CUT "Cut"
3509 #define MN_COPY "Copy"
3510 #define MN_PASTE "Paste"
3511 #define MN_BLOCK "Select block"
3512 #define MN_KILL_LINE "Kill rest of line"
3513 #define MN_DELETE_CHAR "Delete character"
3514 #define MN_BACKSPACE "Backspace"
3515 #define MN_RETURN "Return"
3516 #define MN_RETURN "Return"
3518 #define MN_SEARCH "Search"
3519 #define MN_SEARCH_STR "Search by string"
3520 #define MN_SEARCH_FORW "Search forward"
3521 #define MN_SEARCH_BACK "Search backward"
3522 #define MN_SEARCH_OBJ "Search by inventory object"
3523 #define MN_SEARCH_DESTROYED "Search by destroyed object"
3525 #define MN_INSERT "Insert..."
3526 #define MN_INSERT_OBJECT "Insert name of choosen object"
3527 #define MN_INSERT_DESTROYED "Insert name of destroyed object"
3528 #define MN_INSERT_BLOCK "Insert conditional block"
3529 #define MN_INSERT_MACRO "Insert a macro definition"
3530 #define MN_INSERT_KEYMAP "Insert a keymap definition"
3532 #define MN_COMMAND_LETTER "Command letter"
3533 #define MN_CL_AUTOPICK "' ' (Auto pick)"
3534 #define MN_CL_DESTROY "'!' (Auto destroy)"
3535 #define MN_CL_LEAVE "'~' (Leave it on the floor)"
3536 #define MN_CL_QUERY "';' (Query to pick up)"
3537 #define MN_CL_NO_DISP "'(' (No display on the large map)"
3539 #define MN_ADJECTIVE_GEN "Adjective (general)"
3541 #define MN_ADJECTIVE_SPECIAL "Adjective (special)"
3542 #define MN_BOOSTED "dice boosted (weapons)"
3543 #define MN_MORE_THAN "more than # dice (weapons)"
3544 #define MN_MORE_BONUS "more bonus than # (rings etc.)"
3545 #define MN_ARTIFACT "artifact (equipments)"
3546 #define MN_EGO "ego (equipments)"
3547 #define MN_NAMELESS "nameless (equipments)"
3548 #define MN_WANTED "wanted (corpse)"
3549 #define MN_UNIQUE "unique (corpse)"
3550 #define MN_HUMAN "human (corpse)"
3551 #define MN_UNREADABLE "unreadable (spellbooks)"
3552 #define MN_REALM1 "realm1 (spellbooks)"
3553 #define MN_REALM2 "realm2 (spellbooks)"
3554 #define MN_FIRST "first (spellbooks)"
3555 #define MN_SECOND "second (spellbooks)"
3556 #define MN_THIRD "third (spellbooks)"
3557 #define MN_FOURTH "fourth (spellbooks)"
3559 #define MN_NOUN "Keywords (noun)"
3569 } command_menu_type;
3572 command_menu_type menu_data[] =
3574 {MN_HELP, 0, -1, EC_HELP},
3575 {MN_QUIT, 0, KTRL('q'), EC_QUIT},
3576 {MN_SAVEQUIT, 0, KTRL('w'), EC_SAVEQUIT},
3577 {MN_REVERT, 0, KTRL('z'), EC_REVERT},
3579 {MN_EDIT, 0, -1, -1},
3580 {MN_CUT, 1, KTRL('x'), EC_CUT},
3581 {MN_COPY, 1, KTRL('c'), EC_COPY},
3582 {MN_PASTE, 1, KTRL('v'), EC_PASTE},
3583 {MN_BLOCK, 1, KTRL('g'), EC_BLOCK},
3584 {MN_KILL_LINE, 1, KTRL('k'), EC_KILL_LINE},
3585 {MN_DELETE_CHAR, 1, KTRL('d'), EC_DELETE_CHAR},
3586 {MN_BACKSPACE, 1, KTRL('h'), EC_BACKSPACE},
3587 {MN_RETURN, 1, KTRL('j'), EC_RETURN},
3588 {MN_RETURN, 1, KTRL('m'), EC_RETURN},
3590 {MN_SEARCH, 0, -1, -1},
3591 {MN_SEARCH_STR, 1, KTRL('s'), EC_SEARCH_STR},
3592 {MN_SEARCH_FORW, 1, -1, EC_SEARCH_FORW},
3593 {MN_SEARCH_BACK, 1, KTRL('r'), EC_SEARCH_BACK},
3594 {MN_SEARCH_OBJ, 1, KTRL('y'), EC_SEARCH_OBJ},
3595 {MN_SEARCH_DESTROYED, 1, -1, EC_SEARCH_DESTROYED},
3597 {MN_MOVE, 0, -1, -1},
3598 {MN_LEFT, 1, KTRL('b'), EC_LEFT},
3599 {MN_DOWN, 1, KTRL('n'), EC_DOWN},
3600 {MN_UP, 1, KTRL('p'), EC_UP},
3601 {MN_RIGHT, 1, KTRL('f'), EC_RIGHT},
3602 {MN_BOL, 1, KTRL('a'), EC_BOL},
3603 {MN_EOL, 1, KTRL('e'), EC_EOL},
3604 {MN_PGUP, 1, KTRL('o'), EC_PGUP},
3605 {MN_PGDOWN, 1, KTRL('l'), EC_PGDOWN},
3606 {MN_TOP, 1, KTRL('t'), EC_TOP},
3607 {MN_BOTTOM, 1, KTRL('u'), EC_BOTTOM},
3609 {MN_INSERT, 0, -1, -1},
3610 {MN_INSERT_OBJECT, 1, KTRL('i'), EC_INSERT_OBJECT},
3611 {MN_INSERT_DESTROYED, 1, -1, EC_INSERT_DESTROYED},
3612 {MN_INSERT_BLOCK, 1, -1, EC_INSERT_BLOCK},
3613 {MN_INSERT_MACRO, 1, -1, EC_INSERT_MACRO},
3614 {MN_INSERT_KEYMAP, 1, -1, EC_INSERT_KEYMAP},
3616 {MN_ADJECTIVE_GEN, 0, -1, -1},
3617 {KEY_UNAWARE, 1, -1, EC_IK_UNAWARE},
3618 {KEY_UNIDENTIFIED, 1, -1, EC_IK_UNIDENTIFIED},
3619 {KEY_IDENTIFIED, 1, -1, EC_IK_IDENTIFIED},
3620 {KEY_STAR_IDENTIFIED, 1, -1, EC_IK_STAR_IDENTIFIED},
3621 {KEY_COLLECTING, 1, -1, EC_OK_COLLECTING},
3622 {KEY_WORTHLESS, 1, -1, EC_OK_WORTHLESS},
3624 {MN_ADJECTIVE_SPECIAL, 0, -1, -1},
3625 {MN_BOOSTED, 1, -1, EC_OK_BOOSTED},
3626 {MN_MORE_THAN, 1, -1, EC_OK_MORE_THAN},
3627 {MN_MORE_BONUS, 1, -1, EC_OK_MORE_BONUS},
3628 {MN_ARTIFACT, 1, -1, EC_OK_ARTIFACT},
3629 {MN_EGO, 1, -1, EC_OK_EGO},
3630 {MN_NAMELESS, 1, -1, EC_OK_NAMELESS},
3631 {MN_WANTED, 1, -1, EC_OK_WANTED},
3632 {MN_UNIQUE, 1, -1, EC_OK_UNIQUE},
3633 {MN_HUMAN, 1, -1, EC_OK_HUMAN},
3634 {MN_UNREADABLE, 1, -1, EC_OK_UNREADABLE},
3635 {MN_REALM1, 1, -1, EC_OK_REALM1},
3636 {MN_REALM2, 1, -1, EC_OK_REALM2},
3637 {MN_FIRST, 1, -1, EC_OK_FIRST},
3638 {MN_SECOND, 1, -1, EC_OK_SECOND},
3639 {MN_THIRD, 1, -1, EC_OK_THIRD},
3640 {MN_FOURTH, 1, -1, EC_OK_FOURTH},
3642 {MN_NOUN, 0, -1, -1},
3643 {KEY_WEAPONS, 1, -1, EC_KK_WEAPONS},
3644 {KEY_FAVORITE, 1, -1, EC_KK_FAVORITE},
3645 {KEY_ARMORS, 1, -1, EC_KK_ARMORS},
3646 {KEY_MISSILES, 1, -1, EC_KK_MISSILES},
3647 {KEY_DEVICES, 1, -1, EC_KK_DEVICES},
3648 {KEY_LIGHTS, 1, -1, EC_KK_LIGHTS},
3649 {KEY_JUNKS, 1, -1, EC_KK_JUNKS},
3650 {KEY_SPELLBOOKS, 1, -1, EC_KK_SPELLBOOKS},
3651 {KEY_SHIELDS, 1, -1, EC_KK_SHIELDS},
3652 {KEY_BOWS, 1, -1, EC_KK_BOWS},
3653 {KEY_RINGS, 1, -1, EC_KK_RINGS},
3654 {KEY_AMULETS, 1, -1, EC_KK_AMULETS},
3655 {KEY_SUITS, 1, -1, EC_KK_SUITS},
3656 {KEY_CLOAKS, 1, -1, EC_KK_CLOAKS},
3657 {KEY_HELMS, 1, -1, EC_KK_HELMS},
3658 {KEY_GLOVES, 1, -1, EC_KK_GLOVES},
3659 {KEY_BOOTS, 1, -1, EC_KK_BOOTS},
3661 {MN_COMMAND_LETTER, 0, -1, -1},
3662 {MN_CL_AUTOPICK, 1, -1, EC_CL_AUTOPICK},
3663 {MN_CL_DESTROY, 1, -1, EC_CL_DESTROY},
3664 {MN_CL_LEAVE, 1, -1, EC_CL_LEAVE},
3665 {MN_CL_QUERY, 1, -1, EC_CL_QUERY},
3666 {MN_CL_NO_DISP, 1, -1, EC_CL_NO_DISP},
3673 * Find a command by 'key'.
3675 static int get_com_id(char key)
3679 for (i = 0; menu_data[i].name; i++)
3681 if (menu_data[i].key == key)
3683 return menu_data[i].com_id;
3692 * Display the menu, and get a command
3694 static int do_command_menu(int level, int start)
3699 int col0 = 5 + level*7;
3700 int row0 = 1 + level*3;
3702 int menu_id_list[26];
3704 char linestr[MAX_LINELEN];
3706 /* Get max length */
3708 for (i = start; menu_data[i].level >= level; i++)
3712 /* Ignore lower level sub menus */
3713 if (menu_data[i].level > level) continue;
3715 len = strlen(menu_data[i].name);
3716 if (len > max_len) max_len = len;
3718 menu_id_list[menu_key] = i;
3722 while (menu_key < 26)
3724 menu_id_list[menu_key] = -1;
3728 /* Extra space for displaying menu key and command key */
3729 max_menu_wid = max_len + 3 + 3;
3731 /* Prepare box line */
3733 strcat(linestr, "+");
3734 for (i = 0; i < max_menu_wid + 2; i++)
3736 strcat(linestr, "-");
3738 strcat(linestr, "+");
3748 int row1 = row0 + 1;
3751 Term_putstr(col0, row0, -1, TERM_WHITE, linestr);
3753 /* Draw menu items */
3755 for (i = start; menu_data[i].level >= level; i++)
3757 char com_key_str[3];
3760 /* Ignore lower level sub menus */
3761 if (menu_data[i].level > level) continue;
3763 if (menu_data[i].com_id == -1)
3766 strcpy(com_key_str, "¢§");
3768 strcpy(com_key_str, ">");
3771 else if (menu_data[i].key != -1)
3773 com_key_str[0] = '^';
3774 com_key_str[1] = menu_data[i].key + '@';
3775 com_key_str[2] = '\0';
3779 com_key_str[0] = '\0';
3782 str = format("| %c) %-*s %2s | ", menu_key + 'a', max_len, menu_data[i].name, com_key_str);
3784 Term_putstr(col0, row1++, -1, TERM_WHITE, str);
3789 /* Draw bottom line */
3790 Term_putstr(col0, row1, -1, TERM_WHITE, linestr);
3792 /* The menu was shown */
3796 prt(format("(a-%c) ¥³¥Þ¥ó¥É:", menu_key + 'a' - 1), 0, 0);
3798 prt(format("(a-%c) Command:", menu_key + 'a' - 1), 0, 0);
3802 if (key == ESCAPE) return 0;
3804 if ('a' <= key && key <= 'z')
3806 menu_id = menu_id_list[key - 'a'];
3810 com_id = menu_data[menu_id].com_id;
3814 com_id = do_command_menu(level + 1, menu_id + 1);
3816 if (com_id) return com_id;
3828 com_id = get_com_id(key);
3829 if (com_id) return com_id;
3836 static chain_str_type *new_chain_str(cptr str)
3838 chain_str_type *chain;
3840 size_t len = strlen(str);
3842 chain = (chain_str_type *)ralloc(sizeof(chain_str_type) + len * sizeof(char));
3844 strcpy(chain->s, str);
3851 static void kill_yank_chain(text_body_type *tb)
3853 chain_str_type *chain = tb->yank;
3855 tb->yank_eol = TRUE;
3859 chain_str_type *next = chain->next;
3860 size_t len = strlen(chain->s);
3862 rnfree(chain, sizeof(chain_str_type) + len * sizeof(char));
3869 static void add_str_to_yank(text_body_type *tb, cptr str)
3871 chain_str_type *chain;
3873 tb->yank_eol = FALSE;
3875 if (NULL == tb->yank)
3877 tb->yank = new_chain_str(str);
3887 chain->next = new_chain_str(str);
3892 chain = chain->next;
3897 #define DESCRIPT_HGT 3
3902 static void draw_text_editor(text_body_type *tb)
3905 int by1 = -1, bx1 = -1, by2 = -1, bx2 = -1;
3908 Term_get_size(&tb->wid, &tb->hgt);
3911 * Top line (-1), description line (-3), separator (-1)
3914 tb->hgt -= 2 + DESCRIPT_HGT;
3917 /* Don't let cursor at second byte of kanji */
3918 for (i = 0; tb->lines_list[tb->cy][i]; i++)
3919 if (iskanji(tb->lines_list[tb->cy][i]))
3930 /* Scroll if necessary */
3931 if (tb->cy < tb->upper || tb->upper + tb->hgt <= tb->cy)
3932 tb->upper = tb->cy - (tb->hgt)/2;
3935 if ((tb->cx < tb->left + 10 && tb->left > 0) || tb->left + tb->wid - 5 <= tb->cx)
3936 tb->left = tb->cx - (tb->wid)*2/3;
3940 /* Redraw whole window after resize */
3941 if (tb->old_wid != tb->wid || tb->old_hgt != tb->hgt)
3942 tb->dirty_flags |= DIRTY_SCREEN;
3944 /* Redraw all text after scroll */
3945 else if (tb->old_upper != tb->upper || tb->old_left != tb->left)
3946 tb->dirty_flags |= DIRTY_ALL;
3949 if (tb->dirty_flags & DIRTY_SCREEN)
3951 tb->dirty_flags |= (DIRTY_ALL | DIRTY_MODE);
3957 /* Redraw mode line */
3958 if (tb->dirty_flags & DIRTY_MODE)
3960 char buf[MAX_LINELEN];
3962 int sepa_length = tb->wid;
3965 for (i = 0; i < sepa_length; i++)
3969 Term_putstr(0, tb->hgt + 1, sepa_length, TERM_WHITE, buf);
3972 if (tb->dirty_flags & DIRTY_EXPRESSION)
3977 for (y = 0; tb->lines_list[y]; y++)
3981 cptr s = tb->lines_list[y];
3983 /* Update this line's state */
3984 tb->states[y] = state;
3986 if (*s++ != '?') continue;
3987 if (*s++ != ':') continue;
3989 /* Lines below this line are auto-registered */
3990 if (streq(s, "$AUTOREGISTER"))
3991 state |= LSTAT_AUTOREGISTER;
3993 /* Parse the expr */
3994 v = process_pref_file_expr(&s, &f);
3997 if (streq(v, "0")) state |= LSTAT_BYPASS;
3998 else state &= ~LSTAT_BYPASS;
4000 /* Re-update this line's state */
4001 tb->states[y] = state | LSTAT_EXPRESSION;
4004 tb->dirty_flags |= DIRTY_ALL;
4009 int tmp_cx = tb->cx;
4010 int len = strlen(tb->lines_list[tb->cy]);
4012 /* Correct cursor location */
4013 if (tb->cx > len) tmp_cx = len;
4015 tb->dirty_flags |= DIRTY_ALL;
4017 if (tb->my < tb->cy ||
4018 (tb->my == tb->cy && tb->mx < tmp_cx))
4034 /* Dump up to tb->hgt lines of messages */
4035 for (i = 0; i < tb->hgt; i++)
4041 int y = tb->upper+i;
4043 /* clean or dirty? */
4044 if (!(tb->dirty_flags & DIRTY_ALL) && (tb->dirty_line != y))
4047 msg = tb->lines_list[y];
4050 /* Apply horizontal scroll */
4051 for (j = 0; *msg; msg++, j++)
4053 if (j == tb->left) break;
4069 Term_erase(0, i + 1, tb->wid);
4071 if (tb->states[y] & LSTAT_AUTOREGISTER)
4073 /* Warning color -- These lines will be deleted later */
4078 /* Bypassed line will be displayed by darker color */
4079 if (tb->states[y] & LSTAT_BYPASS) color = TERM_SLATE;
4080 else color = TERM_WHITE;
4085 /* Dump the messages, bottom to top */
4086 Term_putstr(leftcol, i + 1, tb->wid - 1, color, msg);
4091 int x0 = leftcol + tb->left;
4096 if (by1 <= y && y < by2) sx1 = strlen(msg);
4097 if (y == by1) sx0 = bx1;
4098 if (y == by2) sx1 = bx2;
4100 Term_gotoxy(leftcol, i + 1);
4101 if (x0 < sx0) Term_addstr(sx0 - x0, color, msg);
4102 if (x0 < sx1) Term_addstr(sx1 - sx0, TERM_YELLOW, msg + (sx0 - x0));
4103 Term_addstr(-1, color, msg + (sx1 - x0));
4107 for (; i < tb->hgt; i++)
4110 Term_erase(0, i + 1, tb->wid);
4113 /* Display information when updated */
4114 if (tb->old_cy != tb->cy || (tb->dirty_flags & (DIRTY_ALL | DIRTY_NOT_FOUND | DIRTY_NO_SEARCH)) || tb->dirty_line == tb->cy)
4116 autopick_type an_entry, *entry = &an_entry;
4118 /* Clear information line */
4119 for (i = 0; i < DESCRIPT_HGT; i++)
4122 Term_erase(0, tb->hgt + 2 + i, tb->wid);
4125 /* Display information */
4126 if (tb->dirty_flags & DIRTY_NOT_FOUND)
4129 prt(format("¥Ñ¥¿¡¼¥ó¤¬¸«¤Ä¤«¤ê¤Þ¤»¤ó: %s", tb->search_str), tb->hgt + 1 + 1, 0);
4131 prt(format("Pattern not found: %s", tb->search_str), tb->hgt + 1 + 1, 0);
4134 else if (tb->dirty_flags & DIRTY_NO_SEARCH)
4137 prt("¸¡º÷Ãæ¤Î¥Ñ¥¿¡¼¥ó¤¬¤¢¤ê¤Þ¤»¤ó('/'¤Ç¸¡º÷)¡£", tb->hgt + 1 + 1, 0);
4139 prt("No pattern to search. (Press '/' to search.)", tb->hgt +1 + 1, 0);
4142 else if (tb->lines_list[tb->cy][0] == '#')
4145 prt("¤³¤Î¹Ô¤Ï¥³¥á¥ó¥È¤Ç¤¹¡£", tb->hgt +1 + 1, 0);
4147 prt("This line is a comment.", tb->hgt +1 + 1, 0);
4150 else if (tb->lines_list[tb->cy][1] == ':')
4154 switch(tb->lines_list[tb->cy][0])
4158 str = "¤³¤Î¹Ô¤Ï¾ò·ïʬ´ô¼°¤Ç¤¹¡£";
4160 str = "This line is a Conditional Expression.";
4166 str = "¤³¤Î¹Ô¤Ï¥Þ¥¯¥í¤Î¼Â¹ÔÆâÍƤòÄêµÁ¤·¤Þ¤¹¡£";
4168 str = "This line defines a Macro action.";
4173 str = "¤³¤Î¹Ô¤Ï¥Þ¥¯¥í¤Î¥È¥ê¥¬¡¼¡¦¥¡¼¤òÄêµÁ¤·¤Þ¤¹¡£";
4175 str = "This line defines a Macro trigger key.";
4180 str = "¤³¤Î¹Ô¤Ï¥¡¼ÇÛÃÖ¤òÄêµÁ¤·¤Þ¤¹¡£";
4182 str = "This line defines a Keymap.";
4187 /* Draw the first line */
4188 if (str) prt(str, tb->hgt +1 + 1, 0);
4192 switch(tb->lines_list[tb->cy][0])
4195 if (tb->states[tb->cy] & LSTAT_BYPASS)
4198 str = "¸½ºß¤Î¼°¤ÎÃͤϡֵ¶(=0)¡×¤Ç¤¹¡£";
4200 str = "The expression is 'False'(=0) currently.";
4206 str = "¸½ºß¤Î¼°¤ÎÃͤϡֿ¿(=1)¡×¤Ç¤¹¡£";
4208 str = "The expression is 'True'(=1) currently.";
4214 if (tb->states[tb->cy] & LSTAT_AUTOREGISTER)
4217 str = "¤³¤Î¹Ô¤Ï¸å¤Çºï½ü¤µ¤ì¤Þ¤¹¡£";
4219 str = "This line will be delete later.";
4223 else if (tb->states[tb->cy] & LSTAT_BYPASS)
4226 str = "¤³¤Î¹Ô¤Ï¸½ºß¤Ï̵¸ú¤Ê¾õÂ֤Ǥ¹¡£";
4228 str = "This line is bypassed currently.";
4234 /* Draw the second line */
4235 if (str) prt(str, tb->hgt +1 + 2, 0);
4238 /* Get description of an autopicker preference line */
4239 else if (autopick_new_entry(entry, tb->lines_list[tb->cy], FALSE))
4241 char buf[MAX_LINELEN];
4242 char temp[MAX_LINELEN];
4245 describe_autopick(buf, entry);
4247 if (tb->states[tb->cy] & LSTAT_AUTOREGISTER)
4250 strcat(buf, "¤³¤Î¹Ô¤Ï¸å¤Çºï½ü¤µ¤ì¤Þ¤¹¡£");
4252 strcat(buf, " This line will be delete later.");
4256 if (tb->states[tb->cy] & LSTAT_BYPASS)
4259 strcat(buf, "¤³¤Î¹Ô¤Ï¸½ºß¤Ï̵¸ú¤Ê¾õÂ֤Ǥ¹¡£");
4261 strcat(buf, " This line is bypassed currently.");
4265 roff_to_buf(buf, 81, temp, sizeof(temp));
4267 for (i = 0; i < 3; i++)
4273 prt(t, tb->hgt +1 + 1 + i, 0);
4277 autopick_free_entry(entry);
4284 * Kill segment of a line
4286 static void kill_line_segment(text_body_type *tb, int y, int x0, int x1, bool whole)
4288 char buf[MAX_LINELEN];
4289 cptr s = tb->lines_list[y];
4294 if (x0 == x1) return;
4296 /* Kill whole line? */
4297 if (whole && x0 == 0 && s[x1] == '\0' && tb->lines_list[y+1])
4301 string_free(tb->lines_list[y]);
4303 /* Shift lines up */
4304 for (i = y; tb->lines_list[i+1]; i++)
4305 tb->lines_list[i] = tb->lines_list[i+1];
4306 tb->lines_list[i] = NULL;
4308 /* Expressions need re-evaluation */
4309 tb->dirty_flags |= DIRTY_EXPRESSION;
4314 /* Before the segment */
4315 for (x = 0; x < x0; x++)
4318 /* After the segment */
4319 for (x = x1; s[x]; x++)
4325 string_free(tb->lines_list[y]);
4326 tb->lines_list[y] = string_make(buf);
4328 /* Expressions may need re-evaluation */
4329 check_expression_line(tb, y);
4331 /* Text is changed */
4337 * Get a trigger key and insert ASCII string for the trigger
4339 static bool insert_macro_line(text_body_type *tb)
4348 /* Do not process macros */
4354 /* Read the pattern */
4360 /* Do not process macros */
4363 /* Do not wait for keys */
4366 /* Attempt to read a key */
4376 /* Convert the trigger */
4377 ascii_to_text(tmp, buf);
4380 if(!tmp[0]) return FALSE;
4384 /* Insert preference string */
4385 insert_return_code(tb);
4386 string_free(tb->lines_list[tb->cy]);
4387 tb->lines_list[tb->cy] = string_make(format("P:%s", tmp));
4389 /* Acquire action */
4390 i = macro_find_exact(buf);
4394 /* Nothing defined */
4399 /* Analyze the current action */
4400 ascii_to_text(tmp, macro__act[i]);
4403 /* Insert blank action preference line */
4404 insert_return_code(tb);
4405 string_free(tb->lines_list[tb->cy]);
4406 tb->lines_list[tb->cy] = string_make(format("A:%s", tmp));
4413 * Get a command key and insert ASCII string for the key
4415 static bool insert_keymap_line(text_body_type *tb)
4423 if (rogue_like_commands)
4425 mode = KEYMAP_MODE_ROGUE;
4431 mode = KEYMAP_MODE_ORIG;
4444 /* Convert the trigger */
4445 ascii_to_text(tmp, buf);
4448 if(!tmp[0]) return FALSE;
4452 /* Insert preference string */
4453 insert_return_code(tb);
4454 string_free(tb->lines_list[tb->cy]);
4455 tb->lines_list[tb->cy] = string_make(format("C:%d:%s", mode, tmp));
4457 /* Look up the keymap */
4458 act = keymap_act[mode][(byte)(buf[0])];
4460 /* Insert blank action preference line */
4461 insert_return_code(tb);
4462 string_free(tb->lines_list[tb->cy]);
4463 tb->lines_list[tb->cy] = string_make(format("A:%s", act));
4470 * Execute a single editor command
4472 static bool do_editor_command(text_body_type *tb, int com_id)
4480 if (!get_check("Á´¤Æ¤ÎÊѹ¹¤òÇË´þ¤·¤Æ¤«¤é½ªÎ»¤·¤Þ¤¹¡£¤è¤í¤·¤¤¤Ç¤¹¤«¡© ")) break;
4482 if (!get_check("Discard all changes and quit. Are you sure? ")) break;
4485 return QUIT_WITHOUT_SAVE;
4488 return QUIT_AND_SAVE;
4491 /* Revert to original */
4493 if (!get_check("Á´¤Æ¤ÎÊѹ¹¤òÇË´þ¤·¤Æ¸µ¤Î¾õÂÖ¤ËÌᤷ¤Þ¤¹¡£¤è¤í¤·¤¤¤Ç¤¹¤«¡© ")) break;
4495 if (!get_check("Discard all changes and revert to original file. Are you sure? ")) break;
4498 free_text_lines(tb->lines_list);
4499 tb->lines_list = read_pickpref_text_lines(&tb->filename_mode);
4500 tb->dirty_flags |= DIRTY_ALL | DIRTY_MODE | DIRTY_EXPRESSION;
4501 tb->cx = tb->cy = 0;
4504 /* Text is not changed */
4505 tb->changed = FALSE;
4509 /* Peruse the main help file */
4511 (void)show_file(TRUE, "jeditor.txt", NULL, 0, 0);
4513 (void)show_file(TRUE, "editor.txt", NULL, 0, 0);
4516 tb->dirty_flags |= DIRTY_SCREEN;
4521 /* Split a line or insert end of line */
4523 /* Ignore selection */
4529 tb->dirty_flags |= DIRTY_ALL;
4532 insert_return_code(tb);
4537 tb->dirty_flags |= DIRTY_ALL;
4547 len = strlen(tb->lines_list[tb->cy]);
4548 if (len < tb->cx) tb->cx = len;
4550 else if (tb->cy > 0)
4553 tb->cx = strlen(tb->lines_list[tb->cy]);
4559 if (tb->lines_list[tb->cy + 1]) tb->cy++;
4564 if (tb->cy > 0) tb->cy--;
4573 if (iskanji(tb->lines_list[tb->cy][tb->cx])) tb->cx++;
4576 len = strlen(tb->lines_list[tb->cy]);
4579 if (tb->lines_list[tb->cy + 1])
4591 /* Beginning of line */
4597 tb->cx = strlen(tb->lines_list[tb->cy]);
4601 while (0 < tb->cy && tb->upper <= tb->cy)
4603 while (0 < tb->upper && tb->cy + 1 < tb->upper + tb->hgt)
4609 while (tb->cy < tb->upper + tb->hgt && tb->lines_list[tb->cy + 1])
4619 while (tb->lines_list[tb->cy + 1])
4625 int by1, bx1, by2, bx2;
4628 /* Copy the text first */
4629 do_editor_command(tb, EC_COPY);
4631 if (tb->my < tb->cy ||
4632 (tb->my == tb->cy && tb->mx < tb->cx))
4647 /* Kill lines in reverse order */
4648 for (y = by2; y >= by1; y--)
4651 int x1 = strlen(tb->lines_list[y]);
4653 if (y == by1) x0 = bx1;
4654 if (y == by2) x1 = bx2;
4656 kill_line_segment(tb, y, x0, x1, TRUE);
4659 /* Correct cursor position */
4663 /* Disable selection */
4667 tb->dirty_flags |= DIRTY_ALL;
4674 int by1, bx1, by2, bx2;
4676 int len = strlen(tb->lines_list[tb->cy]);
4678 /* Correct cursor location */
4679 if (tb->cx > len) tb->cx = len;
4681 /* Use single line? */
4686 if (tb->lines_list[tb->cy + 1])
4688 /* Select a single line */
4694 /* Select bottom line */
4699 if (tb->my < tb->cy ||
4700 (tb->my == tb->cy && tb->mx < tb->cx))
4715 /* Kill old yank buffer */
4716 kill_yank_chain(tb);
4718 /* Copy string to yank buffer */
4719 for (y = by1; y <= by2; y++)
4722 char buf[MAX_LINELEN];
4725 int x1 = strlen(tb->lines_list[y]);
4727 if (y == by1) x0 = bx1;
4728 if (y == by2) x1 = bx2;
4730 for (i = 0; i < x1 - x0; i++)
4732 buf[i] = tb->lines_list[y][x0 + i];
4736 add_str_to_yank(tb, buf);
4739 /* Disable selection */
4743 tb->dirty_flags |= DIRTY_ALL;
4749 /* Paste killed text */
4751 chain_str_type *chain = tb->yank;
4752 int len = strlen(tb->lines_list[tb->cy]);
4754 /* Nothing to do? */
4757 /* Correct cursor location */
4758 if (tb->cx > len) tb->cx = len;
4760 /* Ignore selection */
4766 tb->dirty_flags |= DIRTY_ALL;
4772 cptr yank_str = chain->s;
4774 char buf[MAX_LINELEN];
4776 char rest[MAX_LINELEN], *rest_ptr = rest;
4778 /* Save preceding string */
4779 for(i = 0; i < tb->cx; i++)
4780 buf[i] = tb->lines_list[tb->cy][i];
4782 strcpy(rest, &(tb->lines_list[tb->cy][i]));
4784 /* Paste yank buffer */
4785 while (*yank_str && i < MAX_LINELEN-1)
4787 buf[i++] = *yank_str++;
4793 chain = chain->next;
4795 if (chain || tb->yank_eol)
4797 /* There is an end of line between chain nodes */
4799 insert_return_code(tb);
4801 /* Replace this line with new one */
4802 string_free(tb->lines_list[tb->cy]);
4803 tb->lines_list[tb->cy] = string_make(buf);
4805 /* Move to next line */
4812 /* Final line doesn't have end of line */
4814 tb->cx = strlen(buf);
4816 /* Rest of original line */
4817 while (*rest_ptr && i < MAX_LINELEN-1)
4819 buf[i++] = *rest_ptr++;
4825 /* Replace this line with new one */
4826 string_free(tb->lines_list[tb->cy]);
4827 tb->lines_list[tb->cy] = string_make(buf);
4834 tb->dirty_flags |= DIRTY_ALL;
4836 /* Expressions need re-evaluation */
4837 tb->dirty_flags |= DIRTY_EXPRESSION;
4839 /* Text is changed */
4848 /* Disable the selection */
4852 tb->dirty_flags |= DIRTY_ALL;
4856 tb->mark = MARK_MARK;
4858 /* Repeating this command swaps cursor position */
4859 if (com_id == tb->old_com_id)
4871 tb->dirty_flags |= DIRTY_ALL;
4875 int len = strlen(tb->lines_list[tb->cy]);
4877 /* Mark the point 1 */
4881 /* Correct cursor location */
4882 if (tb->cx > len) tb->mx = len;
4889 /* Kill rest of line */
4891 int len = strlen(tb->lines_list[tb->cy]);
4893 /* Correct cursor location */
4894 if (tb->cx > len) tb->cx = len;
4896 /* Ignore selection */
4902 tb->dirty_flags |= DIRTY_ALL;
4905 /* Append only if this command is repeated. */
4906 if (tb->old_com_id != com_id)
4908 kill_yank_chain(tb);
4912 /* Really deleted some text */
4915 /* Add deleted string to yank buffer */
4916 add_str_to_yank(tb, &(tb->lines_list[tb->cy][tb->cx]));
4918 kill_line_segment(tb, tb->cy, tb->cx, len, FALSE);
4921 tb->dirty_line = tb->cy;
4923 /* Leave end of line character */
4927 /* Cut the end of line character only */
4928 if (tb->yank_eol) add_str_to_yank(tb, "");
4930 /* Cut end of line */
4931 tb->yank_eol = TRUE;
4933 do_editor_command(tb, EC_DELETE_CHAR);
4937 case EC_DELETE_CHAR:
4938 /* DELETE == go forward + BACK SPACE */
4940 /* Ignore selection */
4946 tb->dirty_flags |= DIRTY_ALL;
4950 if (iskanji(tb->lines_list[tb->cy][tb->cx])) tb->cx++;
4954 do_editor_command(tb, EC_BACKSPACE);
4962 char buf[MAX_LINELEN];
4964 /* Ignore selection */
4970 tb->dirty_flags |= DIRTY_ALL;
4973 len = strlen(tb->lines_list[tb->cy]);
4976 if (tb->lines_list[tb->cy + 1])
4990 /* delete a return code and union two lines */
4991 if (tb->cy == 0) break;
4992 tb->cx = strlen(tb->lines_list[tb->cy-1]);
4993 strcpy(buf, tb->lines_list[tb->cy-1]);
4994 strcat(buf, tb->lines_list[tb->cy]);
4995 string_free(tb->lines_list[tb->cy-1]);
4996 string_free(tb->lines_list[tb->cy]);
4997 tb->lines_list[tb->cy-1] = string_make(buf);
4999 for (i = tb->cy; tb->lines_list[i+1]; i++)
5000 tb->lines_list[i] = tb->lines_list[i+1];
5002 tb->lines_list[i] = NULL;
5006 tb->dirty_flags |= DIRTY_ALL;
5008 /* Expressions need re-evaluation */
5009 tb->dirty_flags |= DIRTY_EXPRESSION;
5011 /* Text is changed */
5017 for (i = j = k = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
5021 if (iskanji(tb->lines_list[tb->cy][i]))
5022 buf[j++] = tb->lines_list[tb->cy][i++];
5024 buf[j++] = tb->lines_list[tb->cy][i];
5031 for (; tb->lines_list[tb->cy][i]; i++)
5032 buf[j++] = tb->lines_list[tb->cy][i];
5034 string_free(tb->lines_list[tb->cy]);
5035 tb->lines_list[tb->cy] = string_make(buf);
5038 tb->dirty_line = tb->cy;
5040 /* Expressions may need re-evaluation */
5041 check_expression_line(tb, tb->cy);
5043 /* Text is changed */
5053 /* Become dirty because of item/equip menu */
5054 tb->dirty_flags |= DIRTY_SCREEN;
5056 search_dir = get_string_for_search(&tb->search_o_ptr, &tb->search_str);
5058 if (!search_dir) break;
5060 if (search_dir == 1) do_editor_command(tb, EC_SEARCH_FORW);
5061 else do_editor_command(tb, EC_SEARCH_BACK);
5065 case EC_SEARCH_FORW:
5066 if (tb->search_o_ptr)
5068 if (!search_for_object(tb, tb->search_o_ptr, TRUE)) tb->dirty_flags |= DIRTY_NOT_FOUND;
5070 else if (tb->search_str)
5072 if (!search_for_string(tb, tb->search_str, TRUE)) tb->dirty_flags |= DIRTY_NOT_FOUND;
5076 tb->dirty_flags |= DIRTY_NO_SEARCH;
5080 case EC_SEARCH_BACK:
5081 if (tb->search_o_ptr)
5083 if (!search_for_object(tb, tb->search_o_ptr, FALSE)) tb->dirty_flags |= DIRTY_NOT_FOUND;
5085 else if (tb->search_str)
5087 if (!search_for_string(tb, tb->search_str, FALSE)) tb->dirty_flags |= DIRTY_NOT_FOUND;
5091 tb->dirty_flags |= DIRTY_NO_SEARCH;
5096 /* Become dirty because of item/equip menu */
5097 tb->dirty_flags |= DIRTY_SCREEN;
5099 if (!get_object_for_search(&tb->search_o_ptr, &tb->search_str)) break;
5101 do_editor_command(tb, EC_SEARCH_FORW);
5104 case EC_SEARCH_DESTROYED:
5105 if (!get_destroyed_object_for_search(&tb->search_o_ptr, &tb->search_str)) break;
5107 do_editor_command(tb, EC_SEARCH_FORW);
5110 case EC_INSERT_OBJECT:
5112 /* Insert choosen item name */
5114 autopick_type an_entry, *entry = &an_entry;
5116 if (!entry_from_choosed_object(entry))
5118 /* Now dirty because of item/equip menu */
5119 tb->dirty_flags |= DIRTY_SCREEN;
5124 insert_return_code(tb);
5125 string_free(tb->lines_list[tb->cy]);
5126 tb->lines_list[tb->cy] = autopick_line_from_entry_kill(entry);
5128 /* Now dirty because of item/equip menu */
5129 tb->dirty_flags |= DIRTY_SCREEN;
5134 case EC_INSERT_DESTROYED:
5135 /* Insert a name of last destroyed item */
5136 if (tb->last_destroyed)
5139 insert_return_code(tb);
5140 string_free(tb->lines_list[tb->cy]);
5141 tb->lines_list[tb->cy] = string_make(tb->last_destroyed);
5144 tb->dirty_flags |= DIRTY_ALL;
5146 /* Text is changed */
5151 case EC_INSERT_BLOCK:
5153 /* Insert a conditinal expression line */
5156 /* Conditional Expression for Class and Race */
5157 sprintf(classrace, "?:[AND [EQU $RACE %s] [EQU $CLASS %s]]",
5159 rp_ptr->E_title, cp_ptr->E_title
5161 rp_ptr->title, cp_ptr->title
5166 insert_return_code(tb);
5167 string_free(tb->lines_list[tb->cy]);
5168 tb->lines_list[tb->cy] = string_make(classrace);
5170 insert_return_code(tb);
5171 string_free(tb->lines_list[tb->cy]);
5172 tb->lines_list[tb->cy] = string_make("?:1");
5175 tb->dirty_flags |= DIRTY_ALL;
5177 /* Text is changed */
5183 case EC_INSERT_MACRO:
5184 /* Draw_everythig (delete menu) */
5185 draw_text_editor(tb);
5188 Term_erase(0, tb->cy - tb->upper + 1, tb->wid);
5192 Term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW, "P:<¥È¥ê¥¬¡¼¥¡¼>: ");
5194 Term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW, "P:<Trigger key>: ");
5196 if (insert_macro_line(tb))
5198 /* Prepare to input action */
5202 tb->dirty_flags |= DIRTY_ALL;
5204 /* Text is changed */
5210 case EC_INSERT_KEYMAP:
5211 /* Draw_everythig (delete menu) */
5212 draw_text_editor(tb);
5215 Term_erase(0, tb->cy - tb->upper + 1, tb->wid);
5219 Term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW, format("C:%d:<¥³¥Þ¥ó¥É¥¡¼>: ", (rogue_like_commands ? KEYMAP_MODE_ROGUE : KEYMAP_MODE_ORIG)));
5221 Term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW, format("C:%d:<Keypress>: ", (rogue_like_commands ? KEYMAP_MODE_ROGUE : KEYMAP_MODE_ORIG)));
5224 if (insert_keymap_line(tb))
5226 /* Prepare to input action */
5230 tb->dirty_flags |= DIRTY_ALL;
5232 /* Text is changed */
5237 case EC_CL_AUTOPICK: toggle_command_letter(tb, DO_AUTOPICK); break;
5238 case EC_CL_DESTROY: toggle_command_letter(tb, DO_AUTODESTROY); break;
5239 case EC_CL_LEAVE: toggle_command_letter(tb, DONT_AUTOPICK); break;
5240 case EC_CL_QUERY: toggle_command_letter(tb, DO_QUERY_AUTOPICK); break;
5241 case EC_CL_NO_DISP: toggle_command_letter(tb, DO_DISPLAY); break;
5243 case EC_IK_UNAWARE: toggle_keyword(tb, FLG_UNAWARE); break;
5244 case EC_IK_UNIDENTIFIED: toggle_keyword(tb, FLG_UNIDENTIFIED); break;
5245 case EC_IK_IDENTIFIED: toggle_keyword(tb, FLG_IDENTIFIED); break;
5246 case EC_IK_STAR_IDENTIFIED: toggle_keyword(tb, FLG_STAR_IDENTIFIED); break;
5247 case EC_KK_WEAPONS: toggle_keyword(tb, FLG_WEAPONS); break;
5248 case EC_KK_FAVORITE: toggle_keyword(tb, FLG_FAVORITE); break;
5249 case EC_KK_ARMORS: toggle_keyword(tb, FLG_ARMORS); break;
5250 case EC_KK_MISSILES: toggle_keyword(tb, FLG_MISSILES); break;
5251 case EC_KK_DEVICES: toggle_keyword(tb, FLG_DEVICES); break;
5252 case EC_KK_LIGHTS: toggle_keyword(tb, FLG_LIGHTS); break;
5253 case EC_KK_JUNKS: toggle_keyword(tb, FLG_JUNKS); break;
5254 case EC_KK_SPELLBOOKS: toggle_keyword(tb, FLG_SPELLBOOKS); break;
5255 case EC_KK_SHIELDS: toggle_keyword(tb, FLG_SHIELDS); break;
5256 case EC_KK_BOWS: toggle_keyword(tb, FLG_BOWS); break;
5257 case EC_KK_RINGS: toggle_keyword(tb, FLG_RINGS); break;
5258 case EC_KK_AMULETS: toggle_keyword(tb, FLG_AMULETS); break;
5259 case EC_KK_SUITS: toggle_keyword(tb, FLG_SUITS); break;
5260 case EC_KK_CLOAKS: toggle_keyword(tb, FLG_CLOAKS); break;
5261 case EC_KK_HELMS: toggle_keyword(tb, FLG_HELMS); break;
5262 case EC_KK_GLOVES: toggle_keyword(tb, FLG_GLOVES); break;
5263 case EC_KK_BOOTS: toggle_keyword(tb, FLG_BOOTS); break;
5264 case EC_OK_COLLECTING: toggle_keyword(tb, FLG_COLLECTING); break;
5265 case EC_OK_BOOSTED: toggle_keyword(tb, FLG_BOOSTED); break;
5266 case EC_OK_MORE_THAN: toggle_keyword(tb, FLG_MORE_THAN); break;
5267 case EC_OK_MORE_BONUS: toggle_keyword(tb, FLG_MORE_BONUS); break;
5268 case EC_OK_WORTHLESS: toggle_keyword(tb, FLG_WORTHLESS); break;
5269 case EC_OK_ARTIFACT: toggle_keyword(tb, FLG_ARTIFACT); break;
5270 case EC_OK_EGO: toggle_keyword(tb, FLG_EGO); break;
5271 case EC_OK_NAMELESS: toggle_keyword(tb, FLG_NAMELESS); break;
5272 case EC_OK_WANTED: toggle_keyword(tb, FLG_WANTED); break;
5273 case EC_OK_UNIQUE: toggle_keyword(tb, FLG_UNIQUE); break;
5274 case EC_OK_HUMAN: toggle_keyword(tb, FLG_HUMAN); break;
5275 case EC_OK_UNREADABLE:
5276 toggle_keyword(tb, FLG_UNREADABLE);
5277 add_keyword(tb, FLG_SPELLBOOKS);
5280 toggle_keyword(tb, FLG_REALM1);
5281 add_keyword(tb, FLG_SPELLBOOKS);
5284 toggle_keyword(tb, FLG_REALM2);
5285 add_keyword(tb, FLG_SPELLBOOKS);
5288 toggle_keyword(tb, FLG_FIRST);
5289 add_keyword(tb, FLG_SPELLBOOKS);
5292 toggle_keyword(tb, FLG_SECOND);
5293 add_keyword(tb, FLG_SPELLBOOKS);
5296 toggle_keyword(tb, FLG_THIRD);
5297 add_keyword(tb, FLG_SPELLBOOKS);
5300 toggle_keyword(tb, FLG_FOURTH);
5301 add_keyword(tb, FLG_SPELLBOOKS);
5305 /* Save old command */
5306 tb->old_com_id = com_id;
5313 * Insert single letter at cursor position.
5315 static void insert_single_letter(text_body_type *tb, int key)
5318 char buf[MAX_LINELEN];
5320 /* Save preceding string */
5321 for (i = j = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
5322 buf[j++] = tb->lines_list[tb->cy][i];
5324 /* Add a character */
5332 if (j+2 < MAX_LINELEN)
5344 if (j+1 < MAX_LINELEN)
5350 for (; tb->lines_list[tb->cy][i] && j + 1 < MAX_LINELEN; i++)
5351 buf[j++] = tb->lines_list[tb->cy][i];
5354 /* Replace current line with new line */
5355 string_free(tb->lines_list[tb->cy]);
5356 tb->lines_list[tb->cy] = string_make(buf);
5358 /* Move to correct collumn */
5359 len = strlen(tb->lines_list[tb->cy]);
5360 if (len < tb->cx) tb->cx = len;
5363 tb->dirty_line = tb->cy;
5365 /* Expressions may need re-evaluation */
5366 check_expression_line(tb, tb->cy);
5368 /* Text is changed */
5375 * Get macro trigger string directly and translate it to the command id.
5377 static int analyze_move_key(text_body_type *tb)
5379 static const struct {
5382 } move_key_list[] = {
5385 {"Right]", EC_RIGHT},
5387 {"Page_Up]", EC_PGUP},
5388 {"Page_Down]", EC_PGDOWN},
5390 {"End]", EC_BOTTOM},
5391 {"KP_Down]", EC_DOWN},
5392 {"KP_Left]", EC_LEFT},
5393 {"KP_Right]", EC_RIGHT},
5395 {"KP_Page_Up]", EC_PGUP},
5396 {"KP_Page_Down]", EC_PGDOWN},
5397 {"KP_Home]", EC_TOP},
5398 {"KP_End]", EC_BOTTOM},
5401 {"KP_6]", EC_RIGHT},
5404 {"KP_3]", EC_PGDOWN},
5406 {"KP_1]", EC_BOTTOM},
5410 static const char shiftstr[] = "shift-";
5411 bool shifted = FALSE;
5417 /* Get ascii form */
5418 ascii_to_text(buf, inkey_macro_trigger_string);
5423 if (prefix(str, shiftstr))
5425 str += sizeof(shiftstr) - 1;
5429 for (i = 0; move_key_list[i].keyname; i++)
5431 if (streq(str, move_key_list[i].keyname))
5433 com_id = move_key_list[i].com_id;
5438 if (!com_id) return 0;
5440 /* Kill further macro expansion */
5446 * Un-shifted cursor keys cancells
5447 * selection created by shift+cursor.
5449 if (tb->mark & MARK_BY_SHIFT)
5454 tb->dirty_flags |= DIRTY_ALL;
5459 /* Start selection by shift + cursor keys */
5462 int len = strlen(tb->lines_list[tb->cy]);
5464 tb->mark = MARK_MARK | MARK_BY_SHIFT;
5468 /* Correct cursor location */
5469 if (tb->cx > len) tb->mx = len;
5471 /* Need to redraw text */
5472 if (com_id == EC_UP || com_id == EC_DOWN)
5474 /* Redraw all text */
5475 tb->dirty_flags |= DIRTY_ALL;
5479 tb->dirty_line = tb->cy;
5488 * In-game editor of Object Auto-picker/Destoryer
5490 void do_cmd_edit_autopick(void)
5492 static int cx_save = 0;
5493 static int cy_save = 0;
5495 text_body_type text_body, *tb = &text_body;
5497 autopick_type an_entry, *entry = &an_entry;
5498 char buf[MAX_LINELEN];
5503 static s32b old_autosave_turn = 0L;
5506 tb->changed = FALSE;
5509 tb->upper = tb->left = 0;
5511 tb->mx = tb->my = 0;
5512 tb->old_cy = tb->old_upper = tb->old_left = -1;
5513 tb->old_wid = tb->old_hgt = -1;
5517 tb->search_o_ptr = NULL;
5518 tb->search_str = NULL;
5519 tb->last_destroyed = NULL;
5520 tb->dirty_flags = DIRTY_ALL | DIRTY_MODE | DIRTY_EXPRESSION;
5521 tb->dirty_line = -1;
5522 tb->filename_mode = PT_DEFAULT;
5525 if (turn > old_autosave_turn + 100L)
5527 do_cmd_save_game(TRUE);
5528 old_autosave_turn = turn;
5531 /* HACK -- Reset start_time to stop counting playtime while edit */
5534 /* Free old entries */
5537 /* Command Description of the 'Last Destroyed Item' */
5538 if (autopick_last_destroyed_object.k_idx)
5540 autopick_entry_from_object(entry, &autopick_last_destroyed_object);
5541 tb->last_destroyed = autopick_line_from_entry_kill(entry);
5544 /* Read or initialize whole text */
5545 tb->lines_list = read_pickpref_text_lines(&tb->filename_mode);
5547 /* Reset cursor position if needed */
5548 for (i = 0; i < tb->cy; i++)
5550 if (!tb->lines_list[i])
5552 tb->cy = tb->cx = 0;
5557 /* Save the screen */
5560 /* Process requests until done */
5566 /* Draw_everythig */
5567 draw_text_editor(tb);
5569 /* Display header line */
5571 prt("(^Q:½ªÎ» ^W:¥»¡¼¥Ö¤·¤Æ½ªÎ», ESC:¥á¥Ë¥å¡¼, ¤½¤Î¾:ÆþÎÏ)", 0, 0);
5573 prt("(^Q:quit, ^W:save&quit, ESC:menu, Other:input text)", 0, 0);
5577 /* Display current position */
5578 prt (format("(%d,%d)", tb->cx, tb->cy), 0, 60);
5582 /* Display current position and mark position */
5583 prt (format("(%d,%d)-(%d,%d)", tb->mx, tb->my, tb->cx, tb->cy), 0, 60);
5587 Term_gotoxy(tb->cx - tb->left, tb->cy - tb->upper + 1);
5590 tb->dirty_flags = 0;
5591 tb->dirty_line = -1;
5593 /* Save old key and location */
5594 tb->old_cy = tb->cy;
5595 tb->old_upper = tb->upper;
5596 tb->old_left = tb->left;
5597 tb->old_wid = tb->wid;
5598 tb->old_hgt = tb->hgt;
5603 /* Count length of macro trigger which induced this key */
5604 trig_len = strlen(inkey_macro_trigger_string);
5606 /* HACK -- ignore macro defined on ASCII keys */
5608 if (trig_len == 1 && !iskanji(inkey_macro_trigger_string[0]))
5613 /* Get original key */
5614 key = inkey_macro_trigger_string[0];
5616 /* Kill further macro expansion */
5621 if (key == 0x7F) key = KTRL('d');
5624 /* Movement special keys */
5625 if (trig_len > 1) com_id = analyze_move_key(tb);
5633 else if (key == ESCAPE)
5635 com_id = do_command_menu(0, 0);
5637 /* Redraw all text later */
5638 tb->dirty_flags |= DIRTY_SCREEN;
5641 /* Insert a character */
5642 else if (!iscntrl(key & 0xff))
5644 /* Ignore selection */
5650 tb->dirty_flags |= DIRTY_ALL;
5653 insert_single_letter(tb, key);
5659 /* Other commands */
5662 com_id = get_com_id(key);
5665 if (com_id) quit = do_editor_command(tb, com_id);
5668 /* Restore the screen */
5671 /* Get the filename of preference */
5672 strcpy(buf, pickpref_filename(tb->filename_mode));
5674 if (quit == QUIT_AND_SAVE)
5675 write_text_lines(buf, tb->lines_list);
5677 free_text_lines(tb->lines_list);
5679 string_free(tb->last_destroyed);
5681 /* Destroy string chain */
5682 kill_yank_chain(tb);
5684 /* Reload autopick pref */
5685 process_pickpref_file(buf);
5687 /* HACK -- reset start_time so that playtime is not increase while edit */
5688 start_time = time(NULL);
5690 /* Save cursor location */