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 * Convert string to lower case
487 static void str_tolower(char *str)
489 /* Force to be lower case string */
499 *str = tolower(*str);
505 * Get auto-picker entry from o_ptr.
507 static void autopick_entry_from_object(autopick_type *entry, object_type *o_ptr)
509 /* Assume that object name is to be added */
512 char name_str[MAX_NLEN];
514 /* Initialize name string */
517 entry->insc = string_make(quark_str(o_ptr->inscription));
518 entry->action = DO_AUTOPICK | DO_DISPLAY;
519 entry->flag[0] = entry->flag[1] = 0L;
523 if (!object_aware_p(o_ptr))
525 ADD_FLG(FLG_UNAWARE);
528 /* Not really identified */
529 else if (!object_known_p(o_ptr))
531 if (!(o_ptr->ident & IDENT_SENSE))
533 ADD_FLG(FLG_UNIDENTIFIED);
537 /* Pseudo-identified */
538 switch (o_ptr->feeling)
542 ADD_FLG(FLG_NAMELESS);
547 ADD_FLG(FLG_NAMELESS);
548 ADD_FLG(FLG_WORTHLESS);
553 ADD_FLG(FLG_WORTHLESS);
561 /* It's not known to be useless so... */
562 ADD_FLG(FLG_UNIDENTIFIED);
575 if (TV_WEAPON_BEGIN <= o_ptr->tval &&
576 o_ptr->tval <= TV_ARMOR_END)
579 * Base name of ego weapons and armors
580 * are almost meaningless.
581 * Register the ego type only.
583 ego_item_type *e_ptr = &e_info[o_ptr->name2];
584 strcpy(name_str, e_name + e_ptr->name);
586 /* Don't use the object description */
594 else if (o_ptr->name1 || o_ptr->art_name)
595 ADD_FLG(FLG_ARTIFACT);
597 /* Non-ego, non-artifact */
600 /* Wearable nameless object */
601 if ((TV_EQUIP_BEGIN <= o_ptr->tval && o_ptr->tval <= TV_EQUIP_END))
602 ADD_FLG(FLG_NAMELESS);
611 case TV_HAFTED: case TV_POLEARM: case TV_SWORD: case TV_DIGGING:
612 k_ptr = &k_info[o_ptr->k_idx];
613 if ((o_ptr->dd != k_ptr->dd) || (o_ptr->ds != k_ptr->ds))
614 ADD_FLG(FLG_BOOSTED);
617 if (o_ptr->tval == TV_CORPSE && object_is_shoukinkubi(o_ptr))
619 REM_FLG(FLG_WORTHLESS);
623 if ((o_ptr->tval == TV_CORPSE || o_ptr->tval == TV_STATUE)
624 && (r_info[o_ptr->pval].flags1 & RF1_UNIQUE))
629 if (o_ptr->tval == TV_CORPSE && my_strchr("pht", r_info[o_ptr->pval].d_char))
634 if (o_ptr->tval >= TV_LIFE_BOOK &&
635 !check_book_realm(o_ptr->tval, o_ptr->sval))
637 ADD_FLG(FLG_UNREADABLE);
638 if (o_ptr->tval != TV_ARCANE_BOOK) name = FALSE;
641 if (REALM1_BOOK == o_ptr->tval &&
642 p_ptr->pclass != CLASS_SORCERER &&
643 p_ptr->pclass != CLASS_RED_MAGE)
649 if (REALM2_BOOK == o_ptr->tval &&
650 p_ptr->pclass != CLASS_SORCERER &&
651 p_ptr->pclass != CLASS_RED_MAGE)
657 if (o_ptr->tval >= TV_LIFE_BOOK && 0 == o_ptr->sval)
659 if (o_ptr->tval >= TV_LIFE_BOOK && 1 == o_ptr->sval)
661 if (o_ptr->tval >= TV_LIFE_BOOK && 2 == o_ptr->sval)
663 if (o_ptr->tval >= TV_LIFE_BOOK && 3 == o_ptr->sval)
666 if (o_ptr->tval == TV_SHOT || o_ptr->tval == TV_BOLT
667 || o_ptr->tval == TV_ARROW)
668 ADD_FLG(FLG_MISSILES);
669 else if (o_ptr->tval == TV_SCROLL || o_ptr->tval == TV_STAFF
670 || o_ptr->tval == TV_WAND || o_ptr->tval == TV_ROD)
671 ADD_FLG(FLG_DEVICES);
672 else if (o_ptr->tval == TV_LITE)
674 else if (o_ptr->tval == TV_SKELETON || o_ptr->tval == TV_BOTTLE
675 || o_ptr->tval == TV_JUNK || o_ptr->tval == TV_STATUE)
677 else if (o_ptr->tval >= TV_LIFE_BOOK)
678 ADD_FLG(FLG_SPELLBOOKS);
679 else if (o_ptr->tval == TV_POLEARM || o_ptr->tval == TV_SWORD
680 || o_ptr->tval == TV_DIGGING || o_ptr->tval == TV_HAFTED)
681 ADD_FLG(FLG_WEAPONS);
682 else if (o_ptr->tval == TV_SHIELD)
683 ADD_FLG(FLG_SHIELDS);
684 else if (o_ptr->tval == TV_BOW)
686 else if (o_ptr->tval == TV_RING)
688 else if (o_ptr->tval == TV_AMULET)
689 ADD_FLG(FLG_AMULETS);
690 else if (o_ptr->tval == TV_DRAG_ARMOR || o_ptr->tval == TV_HARD_ARMOR ||
691 o_ptr->tval == TV_SOFT_ARMOR)
693 else if (o_ptr->tval == TV_CLOAK)
695 else if (o_ptr->tval == TV_HELM)
697 else if (o_ptr->tval == TV_GLOVES)
699 else if (o_ptr->tval == TV_BOOTS)
702 /* Prepare the object description */
705 object_desc(name_str, o_ptr, FALSE, 0);
708 /* Register the name in lowercase */
709 str_tolower(name_str);
710 entry->name = string_make(name_str);
717 * A function to delete entry
719 static void autopick_free_entry(autopick_type *entry)
721 string_free(entry->name);
722 string_free(entry->insc);
727 * Initialize auto-picker preference
729 #define MAX_AUTOPICK_DEFAULT 200
731 void init_autopicker(void)
733 static const char easy_autopick_inscription[] = "(:=g";
739 max_max_autopick = MAX_AUTOPICK_DEFAULT;
740 C_MAKE(autopick_list, max_max_autopick, autopick_type);
744 /* Clear old entries */
745 for( i = 0; i < max_autopick; i++)
746 autopick_free_entry(&autopick_list[i]);
750 /* There is always one entry "=g" */
751 autopick_new_entry(&entry, easy_autopick_inscription, TRUE);
752 autopick_list[max_autopick++] = entry;
757 * Add one line to autopick_list[]
759 static void add_autopick_list(autopick_type *entry)
761 /* There is no enough space to add one line */
762 if (max_autopick >= max_max_autopick)
764 int old_max_max_autopick = max_max_autopick;
765 autopick_type *old_autopick_list = autopick_list;
767 /* Increase size of list */
768 max_max_autopick += MAX_AUTOPICK_DEFAULT;
771 C_MAKE(autopick_list, max_max_autopick, autopick_type);
773 /* Copy from old list to new list */
774 C_COPY(autopick_list, old_autopick_list, old_max_max_autopick, autopick_type);
777 C_FREE(old_autopick_list, old_max_max_autopick, autopick_type);
781 autopick_list[max_autopick] = *entry;
788 * Process line for auto picker/destroyer.
790 errr process_pickpref_file_line(char *buf)
792 autopick_type an_entry, *entry = &an_entry;
795 /* Nuke illegal char */
796 for(i = 0; buf[i]; i++)
805 if (isspace(buf[i]) && buf[i] != ' ')
810 if (!autopick_new_entry(entry, buf, FALSE)) return 0;
812 /* Already has the same entry? */
813 for(i = 0; i < max_autopick; i++)
814 if(!strcmp(entry->name, autopick_list[i].name)
815 && entry->flag[0] == autopick_list[i].flag[0]
816 && entry->flag[1] == autopick_list[i].flag[1]
817 && entry->dice == autopick_list[i].dice
818 && entry->bonus == autopick_list[i].bonus) return 0;
820 add_autopick_list(entry);
826 * Reconstruct preference line from entry
828 cptr autopick_line_from_entry(autopick_type *entry)
830 char buf[MAX_LINELEN];
832 bool sepa_flag = TRUE;
835 if (!(entry->action & DO_DISPLAY)) strcat(buf, "(");
836 if (entry->action & DO_QUERY_AUTOPICK) strcat(buf, ";");
837 if (entry->action & DO_AUTODESTROY) strcat(buf, "!");
838 if (entry->action & DONT_AUTOPICK) strcat(buf, "~");
842 if (IS_FLG(FLG_ALL)) ADD_KEY(KEY_ALL);
843 if (IS_FLG(FLG_COLLECTING)) ADD_KEY(KEY_COLLECTING);
844 if (IS_FLG(FLG_UNIDENTIFIED)) ADD_KEY(KEY_UNIDENTIFIED);
845 if (IS_FLG(FLG_IDENTIFIED)) ADD_KEY(KEY_IDENTIFIED);
846 if (IS_FLG(FLG_STAR_IDENTIFIED)) ADD_KEY(KEY_STAR_IDENTIFIED);
847 if (IS_FLG(FLG_UNAWARE)) ADD_KEY(KEY_UNAWARE);
848 if (IS_FLG(FLG_BOOSTED)) ADD_KEY(KEY_BOOSTED);
850 if (IS_FLG(FLG_MORE_THAN))
852 ADD_KEY(KEY_MORE_THAN);
853 strcat(ptr, format("%d", entry->dice));
857 if (IS_FLG(FLG_MORE_BONUS))
859 ADD_KEY(KEY_MORE_BONUS);
860 strcat(ptr, format("%d", entry->bonus));
861 ADD_KEY(KEY_MORE_BONUS2);
864 if (IS_FLG(FLG_UNREADABLE)) ADD_KEY(KEY_UNREADABLE);
865 if (IS_FLG(FLG_REALM1)) ADD_KEY(KEY_REALM1);
866 if (IS_FLG(FLG_REALM2)) ADD_KEY(KEY_REALM2);
867 if (IS_FLG(FLG_FIRST)) ADD_KEY(KEY_FIRST);
868 if (IS_FLG(FLG_SECOND)) ADD_KEY(KEY_SECOND);
869 if (IS_FLG(FLG_THIRD)) ADD_KEY(KEY_THIRD);
870 if (IS_FLG(FLG_FOURTH)) ADD_KEY(KEY_FOURTH);
871 if (IS_FLG(FLG_WANTED)) ADD_KEY(KEY_WANTED);
872 if (IS_FLG(FLG_UNIQUE)) ADD_KEY(KEY_UNIQUE);
873 if (IS_FLG(FLG_HUMAN)) ADD_KEY(KEY_HUMAN);
874 if (IS_FLG(FLG_WORTHLESS)) ADD_KEY(KEY_WORTHLESS);
875 if (IS_FLG(FLG_NAMELESS)) ADD_KEY(KEY_NAMELESS);
876 if (IS_FLG(FLG_EGO)) ADD_KEY(KEY_EGO);
878 if (IS_FLG(FLG_ARTIFACT)) ADD_KEY(KEY_ARTIFACT);
880 if (IS_FLG(FLG_ITEMS)) ADD_KEY2(KEY_ITEMS);
881 else if (IS_FLG(FLG_WEAPONS)) ADD_KEY2(KEY_WEAPONS);
882 else if (IS_FLG(FLG_ARMORS)) ADD_KEY2(KEY_ARMORS);
883 else if (IS_FLG(FLG_MISSILES)) ADD_KEY2(KEY_MISSILES);
884 else if (IS_FLG(FLG_DEVICES)) ADD_KEY2(KEY_DEVICES);
885 else if (IS_FLG(FLG_LIGHTS)) ADD_KEY2(KEY_LIGHTS);
886 else if (IS_FLG(FLG_JUNKS)) ADD_KEY2(KEY_JUNKS);
887 else if (IS_FLG(FLG_SPELLBOOKS)) ADD_KEY2(KEY_SPELLBOOKS);
888 else if (IS_FLG(FLG_HAFTED)) ADD_KEY2(KEY_HAFTED);
889 else if (IS_FLG(FLG_SHIELDS)) ADD_KEY2(KEY_SHIELDS);
890 else if (IS_FLG(FLG_BOWS)) ADD_KEY2(KEY_BOWS);
891 else if (IS_FLG(FLG_RINGS)) ADD_KEY2(KEY_RINGS);
892 else if (IS_FLG(FLG_AMULETS)) ADD_KEY2(KEY_AMULETS);
893 else if (IS_FLG(FLG_SUITS)) ADD_KEY2(KEY_SUITS);
894 else if (IS_FLG(FLG_CLOAKS)) ADD_KEY2(KEY_CLOAKS);
895 else if (IS_FLG(FLG_HELMS)) ADD_KEY2(KEY_HELMS);
896 else if (IS_FLG(FLG_GLOVES)) ADD_KEY2(KEY_GLOVES);
897 else if (IS_FLG(FLG_BOOTS)) ADD_KEY2(KEY_BOOTS);
898 else if (IS_FLG(FLG_FAVORITE)) ADD_KEY2(KEY_FAVORITE);
900 /* You don't need sepalator after adjective */
901 /* 'artifact' is not true adjective */
902 else if (!IS_FLG(FLG_ARTIFACT))
905 if (entry->name && entry->name[0])
909 if (sepa_flag) strcat(buf, ":");
912 while (entry->name[j] && i < MAX_LINELEN - 2 - 1)
915 if (iskanji(entry->name[j]))
916 buf[i++] = entry->name[j++];
918 buf[i++] = entry->name[j++];
929 while (entry->insc[j] && i < MAX_LINELEN - 2)
932 if (iskanji(entry->insc[j]))
933 buf[i++] = entry->insc[j++];
935 buf[i++] = entry->insc[j++];
940 return string_make(buf);
945 * Reconstruct preference line from entry and kill entry
947 static cptr autopick_line_from_entry_kill(autopick_type *entry)
949 cptr ptr = autopick_line_from_entry(entry);
951 /* Free memory for original entry */
952 autopick_free_entry(entry);
959 * A function for Auto-picker/destroyer
960 * Examine whether the object matches to the entry
962 static bool is_autopick_aux(object_type *o_ptr, autopick_type *entry, cptr o_name)
965 cptr ptr = entry->name;
967 /*** Unidentified ***/
968 if (IS_FLG(FLG_UNIDENTIFIED)
969 && (object_known_p(o_ptr) || (o_ptr->ident & IDENT_SENSE)))
973 if (IS_FLG(FLG_IDENTIFIED) && !object_known_p(o_ptr))
976 /*** *Identified* ***/
977 if (IS_FLG(FLG_STAR_IDENTIFIED) &&
978 (!object_known_p(o_ptr) || !(o_ptr->ident & IDENT_MENTAL)))
981 /*** Dice boosted (weapon of slaying) ***/
982 if (IS_FLG(FLG_BOOSTED))
984 object_kind *k_ptr = &k_info[o_ptr->k_idx];
986 switch( o_ptr->tval )
992 if ((o_ptr->dd != k_ptr->dd) || (o_ptr->ds != k_ptr->ds))
1001 /*** Weapons which dd*ds is more than nn ***/
1002 if (IS_FLG(FLG_MORE_THAN))
1004 if (o_ptr->dd * o_ptr->ds < entry->dice)
1008 /*** Weapons whic dd*ds is more than nn ***/
1009 if (IS_FLG(FLG_MORE_BONUS))
1011 if (!object_known_p(o_ptr)) return FALSE;
1015 if (o_ptr->pval < entry->bonus) return FALSE;
1019 if (o_ptr->to_h < entry->bonus &&
1020 o_ptr->to_d < entry->bonus &&
1021 o_ptr->to_a < entry->bonus &&
1022 o_ptr->pval < entry->bonus)
1027 /*** Worthless items ***/
1028 if (IS_FLG(FLG_WORTHLESS) && object_value(o_ptr) > 0)
1031 /*** Artifact object ***/
1032 if (IS_FLG(FLG_ARTIFACT))
1034 if (!object_known_p(o_ptr) || (!o_ptr->name1 && !o_ptr->art_name))
1038 /*** Ego object ***/
1039 if (IS_FLG(FLG_EGO))
1041 /* Need to be an ego item */
1042 if (!o_ptr->name2) return FALSE;
1044 /* Need to be known to be an ego */
1045 if (!object_known_p(o_ptr) &&
1046 !((o_ptr->ident & IDENT_SENSE) && o_ptr->feeling == FEEL_EXCELLENT))
1051 if (IS_FLG(FLG_NAMELESS))
1053 if (!(TV_EQUIP_BEGIN <= o_ptr->tval && o_ptr->tval <= TV_EQUIP_END))
1056 /* Inscription is a some sort of 'name' */
1057 if (o_ptr->inscription) return FALSE;
1060 if (object_known_p(o_ptr))
1062 /* Artifacts and Ego objects are not okay */
1063 if (o_ptr->name1 || o_ptr->art_name || o_ptr->name2)
1067 /* Pseudo-identified */
1068 else if (o_ptr->ident & IDENT_SENSE)
1070 switch (o_ptr->feeling)
1080 /* It's not nameless */
1088 /* Not known to be nameless */
1093 /*** Unaware items ***/
1094 if (IS_FLG(FLG_UNAWARE) && object_aware_p(o_ptr))
1097 /*** Wanted monster's corpse/skeletons ***/
1098 if (IS_FLG(FLG_WANTED) &&
1099 (o_ptr->tval != TV_CORPSE || !object_is_shoukinkubi(o_ptr)))
1102 /*** Unique monster's corpse/skeletons/statues ***/
1103 if (IS_FLG(FLG_UNIQUE) &&
1104 ((o_ptr->tval != TV_CORPSE && o_ptr->tval != TV_STATUE) ||
1105 !(r_info[o_ptr->pval].flags1 & RF1_UNIQUE)))
1108 /*** Human corpse/skeletons (for Daemon magic) ***/
1109 if (IS_FLG(FLG_HUMAN) &&
1110 (o_ptr->tval != TV_CORPSE ||
1111 !my_strchr("pht", r_info[o_ptr->pval].d_char)))
1114 /*** Unreadable spellbooks ***/
1115 if (IS_FLG(FLG_UNREADABLE) &&
1116 (o_ptr->tval < TV_LIFE_BOOK ||
1117 check_book_realm(o_ptr->tval, o_ptr->sval)))
1120 /*** First realm spellbooks ***/
1121 if (IS_FLG(FLG_REALM1) &&
1122 (REALM1_BOOK != o_ptr->tval ||
1123 p_ptr->pclass == CLASS_SORCERER ||
1124 p_ptr->pclass == CLASS_RED_MAGE))
1127 /*** Second realm spellbooks ***/
1128 if (IS_FLG(FLG_REALM2) &&
1129 (REALM2_BOOK != o_ptr->tval ||
1130 p_ptr->pclass == CLASS_SORCERER ||
1131 p_ptr->pclass == CLASS_RED_MAGE))
1134 /*** First rank spellbooks ***/
1135 if (IS_FLG(FLG_FIRST) &&
1136 (o_ptr->tval < TV_LIFE_BOOK || 0 != o_ptr->sval))
1139 /*** Second rank spellbooks ***/
1140 if (IS_FLG(FLG_SECOND) &&
1141 (o_ptr->tval < TV_LIFE_BOOK || 1 != o_ptr->sval))
1144 /*** Third rank spellbooks ***/
1145 if (IS_FLG(FLG_THIRD) &&
1146 (o_ptr->tval < TV_LIFE_BOOK || 2 != o_ptr->sval))
1149 /*** Fourth rank spellbooks ***/
1150 if (IS_FLG(FLG_FOURTH) &&
1151 (o_ptr->tval < TV_LIFE_BOOK || 3 != o_ptr->sval))
1155 if (IS_FLG(FLG_WEAPONS))
1157 if (!(TV_WEAPON_BEGIN <= o_ptr->tval && o_ptr->tval <= TV_WEAPON_END))
1160 else if (IS_FLG(FLG_ARMORS))
1162 if (!(TV_ARMOR_BEGIN <= o_ptr->tval && o_ptr->tval <= TV_ARMOR_END))
1165 else if (IS_FLG(FLG_MISSILES))
1169 case TV_SHOT: case TV_BOLT: case TV_ARROW:
1171 default: return FALSE;
1174 else if (IS_FLG(FLG_DEVICES))
1178 case TV_SCROLL: case TV_STAFF: case TV_WAND: case TV_ROD:
1180 default: return FALSE;
1183 else if (IS_FLG(FLG_LIGHTS))
1185 if (!(o_ptr->tval == TV_LITE))
1188 else if (IS_FLG(FLG_JUNKS))
1192 case TV_SKELETON: case TV_BOTTLE:
1193 case TV_JUNK: case TV_STATUE:
1195 default: return FALSE;
1198 else if (IS_FLG(FLG_SPELLBOOKS))
1200 if (!(o_ptr->tval >= TV_LIFE_BOOK))
1203 else if (IS_FLG(FLG_HAFTED))
1205 if (!(o_ptr->tval == TV_HAFTED))
1208 else if (IS_FLG(FLG_SHIELDS))
1210 if (!(o_ptr->tval == TV_SHIELD))
1213 else if (IS_FLG(FLG_BOWS))
1215 if (!(o_ptr->tval == TV_BOW))
1218 else if (IS_FLG(FLG_RINGS))
1220 if (!(o_ptr->tval == TV_RING))
1223 else if (IS_FLG(FLG_AMULETS))
1225 if (!(o_ptr->tval == TV_AMULET))
1228 else if (IS_FLG(FLG_SUITS))
1230 if (!(o_ptr->tval == TV_DRAG_ARMOR ||
1231 o_ptr->tval == TV_HARD_ARMOR ||
1232 o_ptr->tval == TV_SOFT_ARMOR))
1235 else if (IS_FLG(FLG_CLOAKS))
1237 if (!(o_ptr->tval == TV_CLOAK))
1240 else if (IS_FLG(FLG_HELMS))
1242 if (!(o_ptr->tval == TV_CROWN || o_ptr->tval == TV_HELM))
1245 else if (IS_FLG(FLG_GLOVES))
1247 if (!(o_ptr->tval == TV_GLOVES))
1250 else if (IS_FLG(FLG_BOOTS))
1252 if (!(o_ptr->tval == TV_BOOTS))
1255 else if (IS_FLG(FLG_FAVORITE))
1257 if (!is_favorite(o_ptr))
1261 /* Keyword don't match */
1265 if (strncmp(o_name, ptr, strlen(ptr))) return FALSE;
1269 if (!my_strstr(o_name, ptr)) return FALSE;
1272 /* TRUE when it need not to be 'collecting' */
1273 if (!IS_FLG(FLG_COLLECTING)) return TRUE;
1275 /* Check if there is a same item */
1276 for (j = 0; j < INVEN_PACK; j++)
1279 * 'Collecting' means the item must be absorbed
1280 * into an inventory slot.
1281 * But an item can not be absorbed into itself!
1283 if ((&inventory[j] != o_ptr) &&
1284 object_similar(&inventory[j], o_ptr))
1288 /* Not collecting */
1294 * A function for Auto-picker/destroyer
1295 * Examine whether the object matches to the list of keywords or not.
1297 int is_autopick(object_type *o_ptr)
1300 char o_name[MAX_NLEN];
1302 if (o_ptr->tval == TV_GOLD) return -1;
1304 /* Prepare object name string first */
1305 object_desc(o_name, o_ptr, FALSE, 3);
1307 /* Convert the string to lower case */
1308 str_tolower(o_name);
1310 /* Look for a matching entry in the list */
1311 for (i=0; i < max_autopick; i++)
1313 autopick_type *entry = &autopick_list[i];
1315 if (is_autopick_aux(o_ptr, entry, o_name)) return i;
1318 /* No matching entry */
1326 static void auto_inscribe_item(object_type *o_ptr, int idx)
1328 /* Are there auto-inscription? */
1329 if (idx < 0 || !autopick_list[idx].insc) return;
1331 if (!o_ptr->inscription)
1332 o_ptr->inscription = quark_add(autopick_list[idx].insc);
1334 /* Redraw inscription */
1335 p_ptr->window |= (PW_EQUIP | PW_INVEN);
1337 /* {.} and {$} effect p_ptr->warning and TRC_TELEPORT_SELF */
1338 p_ptr->update |= (PU_BONUS);
1343 * Automatically destroy items in this grid.
1345 static bool is_opt_confirm_destroy(object_type *o_ptr)
1347 if (!destroy_items) return FALSE;
1349 /* Known to be worthless? */
1351 if (object_value(o_ptr) > 0) return FALSE;
1354 if ((o_ptr->tval >= TV_MISSILE_BEGIN) && (o_ptr->tval <= TV_ARMOR_END)) return FALSE;
1357 if ((o_ptr->tval == TV_CHEST) && o_ptr->pval) return FALSE;
1361 if (o_ptr->tval == TV_CORPSE
1362 && object_is_shoukinkubi(o_ptr)) return FALSE;
1366 if (o_ptr->tval == TV_CORPSE) return FALSE;
1369 if ((o_ptr->tval == TV_SKELETON) || (o_ptr->tval == TV_BOTTLE) || (o_ptr->tval == TV_JUNK) || (o_ptr->tval == TV_STATUE)) return FALSE;
1373 if (p_ptr->prace == RACE_DEMON)
1375 if (o_ptr->tval == TV_CORPSE &&
1376 o_ptr->sval == SV_CORPSE &&
1377 my_strchr("pht", r_info[o_ptr->pval].d_char))
1381 if (p_ptr->pclass == CLASS_ARCHER)
1383 if (o_ptr->tval == TV_SKELETON ||
1384 (o_ptr->tval == TV_CORPSE && o_ptr->sval == SV_SKELETON))
1387 else if (p_ptr->pclass == CLASS_NINJA)
1389 if (o_ptr->tval == TV_LITE &&
1390 o_ptr->name2 == EGO_LITE_DARKNESS)
1393 else if (p_ptr->pclass == CLASS_BEASTMASTER ||
1394 p_ptr->pclass == CLASS_CAVALRY)
1396 if (o_ptr->tval == TV_WAND &&
1397 o_ptr->sval == SV_WAND_HEAL_MONSTER)
1402 if (o_ptr->tval == TV_GOLD) return FALSE;
1409 * Automatically destroy an item if it is to be destroyed
1411 * When always_pickup is 'yes', we disable auto-destroyer function of
1412 * auto-picker/destroyer, and do only easy-auto-destroyer.
1414 static object_type autopick_last_destroyed_object;
1416 static void auto_destroy_item(object_type *o_ptr, int autopick_idx)
1418 bool destroy = FALSE;
1420 /* Easy-Auto-Destroyer (3rd priority) */
1421 if (is_opt_confirm_destroy(o_ptr)) destroy = TRUE;
1423 /* Protected by auto-picker (2nd priotity) */
1424 if (autopick_idx >= 0 &&
1425 !(autopick_list[autopick_idx].action & DO_AUTODESTROY))
1428 /* Auto-destroyer works only when !always_pickup */
1431 /* Auto-picker/destroyer (1st priority) */
1432 if (autopick_idx >= 0 &&
1433 (autopick_list[autopick_idx].action & DO_AUTODESTROY))
1437 /* Not to be destroyed */
1438 if (!destroy) return;
1440 /* Now decided to destroy */
1445 if (!can_player_destroy_object(o_ptr))
1447 char o_name[MAX_NLEN];
1449 /* Describe the object (with {terrible/special}) */
1450 object_desc(o_name, o_ptr, TRUE, 3);
1454 msg_format("%s¤ÏÇ˲õÉÔǽ¤À¡£", o_name);
1456 msg_format("You cannot auto-destroy %s.", o_name);
1463 /* Record name of destroyed item */
1464 COPY(&autopick_last_destroyed_object, o_ptr, object_type);
1467 o_ptr->marked |= OM_AUTODESTROY;
1468 p_ptr->notice |= PN_AUTODESTROY;
1475 * Auto-destroy marked item
1477 static void delayed_auto_destroy_aux(int item)
1481 /* Get the item (in the pack) */
1482 if (item >= 0) o_ptr = &inventory[item];
1484 /* Get the item (on the floor) */
1485 else o_ptr = &o_list[0 - item];
1487 if (o_ptr->k_idx && o_ptr->marked & OM_AUTODESTROY)
1489 char o_name[MAX_NLEN];
1491 /* Describe the object (with {terrible/special}) */
1492 object_desc(o_name, o_ptr, TRUE, 3);
1494 /* Eliminate the item (from the pack) */
1497 inven_item_increase(item, -(o_ptr->number));
1498 inven_item_optimize(item);
1501 /* Eliminate the item (from the floor) */
1504 delete_object_idx(0 - item);
1507 /* Print a message */
1509 msg_format("%s¤ò¼«Æ°Ç˲õ¤·¤Þ¤¹¡£", o_name);
1511 msg_format("Auto-destroying %s.", o_name);
1518 * Auto-destroy marked items in inventry and on floor
1520 void delayed_auto_destroy(void)
1525 * Scan inventry in reverse order to prevent
1526 * skipping after inven_item_optimize()
1528 for (item = INVEN_TOTAL - 1; item >= 0 ; item--)
1529 delayed_auto_destroy_aux(item);
1531 /* Scan the pile of objects */
1532 item = cave[py][px].o_idx;
1535 int next = o_list[item].next_o_idx;
1536 delayed_auto_destroy_aux(-item);
1543 * Auto-inscription and/or destroy
1545 * Auto-destroyer works only on inventory or on floor stack only when
1548 void auto_do_item(int item, bool destroy)
1553 /* Get the item (in the pack) */
1554 if (item >= 0) o_ptr = &inventory[item];
1556 /* Get the item (on the floor) */
1557 else o_ptr = &o_list[0 - item];
1559 /* Get the index in the auto-pick/destroy list */
1560 idx = is_autopick(o_ptr);
1562 /* Do auto-inscription */
1563 auto_inscribe_item(o_ptr, idx);
1565 /* Do auto-destroy if needed */
1566 if (destroy && item <= INVEN_PACK)
1567 auto_destroy_item(o_ptr, idx);
1572 * Automatically pickup/destroy items in this grid.
1574 void auto_pickup_items(cave_type *c_ptr)
1576 s16b this_o_idx, next_o_idx = 0;
1578 /* Scan the pile of objects */
1579 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1583 /* Acquire object */
1584 object_type *o_ptr = &o_list[this_o_idx];
1586 /* Acquire next object */
1587 next_o_idx = o_ptr->next_o_idx;
1589 idx = is_autopick(o_ptr);
1591 /* Item index for floor -1,-2,-3,... */
1592 auto_inscribe_item(o_ptr, idx);
1595 (autopick_list[idx].action & (DO_AUTOPICK | DO_QUERY_AUTOPICK)))
1599 if (!inven_carry_okay(o_ptr))
1601 char o_name[MAX_NLEN];
1603 /* Describe the object */
1604 object_desc(o_name, o_ptr, TRUE, 3);
1608 msg_format("¥¶¥Ã¥¯¤Ë¤Ï%s¤òÆþ¤ì¤ë·ä´Ö¤¬¤Ê¤¤¡£", o_name);
1610 msg_format("You have no room for %s.", o_name);
1612 /* Hack - remember that the item has given a message here. */
1613 o_ptr->marked |= OM_NOMSG;
1617 else if (autopick_list[idx].action & DO_QUERY_AUTOPICK)
1619 char out_val[MAX_NLEN+20];
1620 char o_name[MAX_NLEN];
1622 if (o_ptr->marked & OM_NO_QUERY)
1624 /* Already answered as 'No' */
1628 /* Describe the object */
1629 object_desc(o_name, o_ptr, TRUE, 3);
1632 sprintf(out_val, "%s¤ò½¦¤¤¤Þ¤¹¤«? ", o_name);
1634 sprintf(out_val, "Pick up %s? ", o_name);
1637 if (!get_check(out_val))
1639 /* Hack - remember that the item has given a message here. */
1640 o_ptr->marked |= (OM_NOMSG | OM_NO_QUERY);
1645 py_pickup_aux(this_o_idx);
1650 * When always_pickup is 'yes', we disable
1651 * auto-destroyer from autopick function, and do only
1652 * easy-auto-destroyer.
1656 auto_destroy_item(o_ptr, idx);
1662 #define PT_DEFAULT 0
1663 #define PT_WITH_PNAME 1
1666 * Get file name for autopick preference
1668 static cptr pickpref_filename(int filename_mode)
1671 static const char namebase[] = "picktype";
1673 static const char namebase[] = "pickpref";
1676 switch (filename_mode)
1679 return format("%s.prf", namebase);
1682 return format("%s-%s.prf", namebase, player_name);
1690 static const char autoregister_header[] = "?:$AUTOREGISTER";
1693 * Clear auto registered lines in the picktype.prf .
1695 static bool clear_auto_register(void)
1697 char tmp_file[1024];
1698 char pref_file[1024];
1703 bool autoregister = FALSE;
1706 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_WITH_PNAME));
1707 pref_fff = my_fopen(pref_file, "r");
1711 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_DEFAULT));
1712 pref_fff = my_fopen(pref_file, "r");
1721 /* Open a new (temporary) file */
1722 tmp_fff = my_fopen_temp(tmp_file, sizeof(tmp_file));
1726 /* Close the preference file */
1730 msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤¤Þ¤»¤ó¤Ç¤·¤¿¡£", tmp_file);
1732 msg_format("Failed to create temporary file %s.", tmp_file);
1739 /* Loop for every line */
1743 if (my_fgets(pref_fff, buf, sizeof(buf))) break;
1747 /* Delete auto-registered line */
1749 /* Count auto-destroy preference lines */
1750 if (buf[0] != '#' && buf[0] != '?') num++;
1753 /* We are looking for auto-registered line */
1756 if (streq(buf, autoregister_header))
1758 /* Delete all further lines */
1759 autoregister = TRUE;
1763 /* Copy orginally lines */
1764 fprintf(tmp_fff, "%s\n", buf);
1770 my_fclose(pref_fff);
1776 msg_format("°ÊÁ°¤Î¥¥ã¥é¥¯¥¿¡¼ÍѤμ«Æ°ÀßÄê(%d¹Ô)¤¬»Ä¤Ã¤Æ¤¤¤Þ¤¹¡£", num);
1777 strcpy(buf, "¸Å¤¤ÀßÄê¹Ô¤Ïºï½ü¤·¤Þ¤¹¡£¤è¤í¤·¤¤¤Ç¤¹¤«¡©");
1779 msg_format("Auto registered lines (%d lines) for previous character are remaining.", num);
1780 strcpy(buf, "These lines will be deleted. Are you sure? ");
1783 /* You can cancel it */
1784 if (!get_check(buf))
1787 autoregister = FALSE;
1790 msg_print("¥¨¥Ç¥£¥¿¤Î¥«¥Ã¥È&¥Ú¡¼¥¹¥ÈÅù¤ò»È¤Ã¤ÆɬÍפʹԤòÈòÆñ¤·¤Æ¤¯¤À¤µ¤¤¡£");
1792 msg_print("Use cut & paste of auto picker editor (_) to keep old prefs.");
1798 /* If there are some changes, overwrite the original file with new one */
1801 /* Copy contents of temporary file */
1803 tmp_fff = my_fopen(tmp_file, "r");
1804 pref_fff = my_fopen(pref_file, "w");
1806 while (!my_fgets(tmp_fff, buf, sizeof(buf)))
1807 fprintf(pref_fff, "%s\n", buf);
1809 my_fclose(pref_fff);
1813 /* Kill the temporary file */
1821 * Automatically register an auto-destroy preference line
1823 bool add_auto_register(object_type *o_ptr)
1826 char pref_file[1024];
1828 autopick_type an_entry, *entry = &an_entry;
1830 int match_autopick = is_autopick(o_ptr);
1832 /* Already registered */
1833 if (match_autopick != -1)
1836 byte act = autopick_list[match_autopick].action;
1839 if (act & DO_AUTOPICK) what = "¼«Æ°¤Ç½¦¤¦";
1840 else if (act & DO_AUTODESTROY) what = "¼«Æ°Ç˲õ¤¹¤ë";
1841 else if (act & DONT_AUTOPICK) what = "ÊüÃÖ¤¹¤ë";
1842 else /* if (act & DO_QUERY_AUTOPICK) */ what = "³Îǧ¤·¤Æ½¦¤¦";
1844 msg_format("¤½¤Î¥¢¥¤¥Æ¥à¤Ï´û¤Ë%s¤è¤¦¤ËÀßÄꤵ¤ì¤Æ¤¤¤Þ¤¹¡£", what);
1846 if (act & DO_AUTOPICK) what = "auto-pickup";
1847 else if (act & DO_AUTODESTROY) what = "auto-destroy";
1848 else if (act & DONT_AUTOPICK) what = "leave on floor";
1849 else /* if (act & DO_QUERY_AUTOPICK) */ what = "query auto-pickup";
1851 msg_format("The object is already registered to %s.", what);
1858 if (!p_ptr->autopick_autoregister)
1860 /* Clear old auto registered lines */
1861 if (!clear_auto_register()) return FALSE;
1864 /* Try a filename with player name */
1865 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_WITH_PNAME));
1866 pref_fff = my_fopen(pref_file, "r");
1870 /* Use default name */
1871 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_DEFAULT));
1872 pref_fff = my_fopen(pref_file, "r");
1875 /* Check the header */
1879 if (my_fgets(pref_fff, buf, sizeof(buf)))
1881 /* No header found */
1882 p_ptr->autopick_autoregister = FALSE;
1887 if (streq(buf, autoregister_header))
1889 /* Found the header */
1890 p_ptr->autopick_autoregister = TRUE;
1896 /* Close read only FILE* */
1899 /* Open for append */
1900 pref_fff = my_fopen(pref_file, "a");
1905 msg_format("%s ¤ò³«¤¯¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¤Ç¤·¤¿¡£", pref_file);
1907 msg_format("Failed to open %s.", pref_file);
1915 if (!p_ptr->autopick_autoregister)
1917 /* Add the header */
1918 fprintf(pref_fff, "%s\n", autoregister_header);
1921 fprintf(pref_fff, "%s\n", "# *·Ù¹ð!!* °Ê¹ß¤Î¹Ô¤Ï¼«Æ°ÅÐÏ¿¤µ¤ì¤¿¤â¤Î¤Ç¤¹¡£");
1922 fprintf(pref_fff, "%s\n", "# ¸å¤Ç¼«Æ°Åª¤Ëºï½ü¤µ¤ì¤Þ¤¹¤Î¤Ç¡¢É¬ÍפʹԤϾå¤ÎÊý¤Ø°ÜÆ°¤·¤Æ¤ª¤¤¤Æ¤¯¤À¤µ¤¤¡£");
1924 fprintf(pref_fff, "%s\n", "# *Waring!* The lines below will be deleated later.");
1925 fprintf(pref_fff, "%s\n", "# Keep it by cut & paste if you need these lines for future characters.");
1928 /* Now auto register is in-use */
1929 p_ptr->autopick_autoregister = TRUE;
1932 /* Get a preference entry */
1933 autopick_entry_from_object(entry, o_ptr);
1935 /* Set to auto-destroy (with no-display) */
1936 entry->action = DO_AUTODESTROY;
1938 /* Load the new line as preference */
1939 add_autopick_list(entry);
1941 /* Add a line to the file */
1942 /* Don't kill "entry" */
1943 fprintf(pref_fff, "%s\n", autopick_line_from_entry(entry));
1945 /* Close the file */
1952 /******** Auto-picker/destroyer editor **********/
1954 #define MAX_YANK MAX_LINELEN
1955 #define MAX_LINES 3000
1957 #define MARK_MARK 0x01
1958 #define MARK_BY_SHIFT 0x02
1960 #define LSTAT_BYPASS 0x01
1961 #define LSTAT_EXPRESSION 0x02
1962 #define LSTAT_AUTOREGISTER 0x04
1964 #define QUIT_WITHOUT_SAVE 1
1965 #define QUIT_AND_SAVE 2
1968 * Struct for yank buffer
1970 typedef struct chain_str {
1971 struct chain_str *next;
1977 * Data struct for text editor
1983 int old_wid, old_hgt;
1985 int old_upper, old_left;
1989 object_type *search_o_ptr;
1991 cptr last_destroyed;
1993 chain_str_type *yank;
1997 byte states[MAX_LINES];
2009 * Dirty flag for text editor
2011 #define DIRTY_ALL 0x0001
2012 #define DIRTY_MODE 0x0004
2013 #define DIRTY_SCREEN 0x0008
2014 #define DIRTY_NOT_FOUND 0x0010
2015 #define DIRTY_NO_SEARCH 0x0020
2016 #define DIRTY_EXPRESSION 0x0040
2017 #define DIRTY_SKIP_INACTIVE 0x0080
2018 #define DIRTY_INACTIVE 0x0100
2021 * Describe which kind of object is Auto-picked/destroyed
2023 static void describe_autopick(char *buff, autopick_type *entry)
2025 cptr str = entry->name;
2026 byte act = entry->action;
2027 cptr insc = entry->insc;
2033 cptr before_str[100], body_str;
2036 body_str = "¥¢¥¤¥Æ¥à";
2038 /*** Collecting items ***/
2039 /*** Which can be absorbed into a slot as a bundle ***/
2040 if (IS_FLG(FLG_COLLECTING))
2041 before_str[before_n++] = "¼ý½¸Ãæ¤Ç´û¤Ë»ý¤Ã¤Æ¤¤¤ë¥¹¥í¥Ã¥È¤Ë¤Þ¤È¤á¤é¤ì¤ë";
2043 /*** Unidentified ***/
2044 if (IS_FLG(FLG_UNIDENTIFIED))
2045 before_str[before_n++] = "̤´ÕÄê¤Î";
2047 /*** Identified ***/
2048 if (IS_FLG(FLG_IDENTIFIED))
2049 before_str[before_n++] = "´ÕÄêºÑ¤ß¤Î";
2051 /*** *Identified* ***/
2052 if (IS_FLG(FLG_STAR_IDENTIFIED))
2053 before_str[before_n++] = "´°Á´¤Ë´ÕÄêºÑ¤ß¤Î";
2055 /*** Dice boosted (weapon of slaying) ***/
2056 if (IS_FLG(FLG_BOOSTED))
2058 before_str[before_n++] = "¥À¥á¡¼¥¸¥À¥¤¥¹¤¬Ä̾ï¤è¤êÂ礤¤";
2062 /*** Weapons whose dd*ds is more than nn ***/
2063 if (IS_FLG(FLG_MORE_THAN))
2065 static char more_than_desc_str[] = "___";
2066 before_str[before_n++] = "¥À¥á¡¼¥¸¥À¥¤¥¹¤ÎºÇÂçÃͤ¬";
2069 sprintf(more_than_desc_str,"%d", entry->dice);
2070 before_str[before_n++] = more_than_desc_str;
2071 before_str[before_n++] = "°Ê¾å¤Î";
2074 /*** Items whose magical bonus is more than nn ***/
2075 if (IS_FLG(FLG_MORE_BONUS))
2077 static char more_bonus_desc_str[] = "___";
2078 before_str[before_n++] = "½¤ÀµÃͤ¬(+";
2080 sprintf(more_bonus_desc_str,"%d", entry->bonus);
2081 before_str[before_n++] = more_bonus_desc_str;
2082 before_str[before_n++] = ")°Ê¾å¤Î";
2085 /*** Worthless items ***/
2086 if (IS_FLG(FLG_WORTHLESS))
2087 before_str[before_n++] = "Ź¤Ç̵²ÁÃͤÈȽÄꤵ¤ì¤ë";
2090 if (IS_FLG(FLG_ARTIFACT))
2092 before_str[before_n++] = "¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È¤Î";
2097 if (IS_FLG(FLG_EGO))
2099 before_str[before_n++] = "¥¨¥´¥¢¥¤¥Æ¥à¤Î";
2104 if (IS_FLG(FLG_NAMELESS))
2106 before_str[before_n++] = "¥¨¥´¤Ç¤â¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È¤Ç¤â¤Ê¤¤";
2110 /*** Unaware items ***/
2111 if (IS_FLG(FLG_UNAWARE))
2112 before_str[before_n++] = "̤´ÕÄê¤Ç¤½¤Î¸ú²Ì¤âȽÌÀ¤·¤Æ¤¤¤Ê¤¤";
2114 /*** Wanted monster's corpse/skeletons ***/
2115 if (IS_FLG(FLG_WANTED))
2117 before_str[before_n++] = "¥Ï¥ó¥¿¡¼»ö̳½ê¤Ç¾Þ¶â¼ó¤È¤µ¤ì¤Æ¤¤¤ë";
2118 body_str = "»àÂΤä¹ü";
2121 /*** Human corpse/skeletons (for Daemon magic) ***/
2122 if (IS_FLG(FLG_HUMAN))
2124 before_str[before_n++] = "°ËâËâË¡¤Ç»È¤¦¤¿¤á¤Î¿Í´Ö¤ä¥Ò¥å¡¼¥Þ¥Î¥¤¥É¤Î";
2125 body_str = "»àÂΤä¹ü";
2128 /*** Unique monster's corpse/skeletons/statues ***/
2129 if (IS_FLG(FLG_UNIQUE))
2131 before_str[before_n++] = "¥æ¥Ë¡¼¥¯¥â¥ó¥¹¥¿¡¼¤Î";
2132 body_str = "»àÂΤä¹ü";
2135 /*** Unreadable spellbooks ***/
2136 if (IS_FLG(FLG_UNREADABLE))
2138 before_str[before_n++] = "¤¢¤Ê¤¿¤¬Æɤá¤Ê¤¤Îΰè¤Î";
2139 body_str = "ËâË¡½ñ";
2142 /*** First realm spellbooks ***/
2143 if (IS_FLG(FLG_REALM1))
2145 before_str[before_n++] = "Âè°ìÎΰè¤Î";
2146 body_str = "ËâË¡½ñ";
2149 /*** Second realm spellbooks ***/
2150 if (IS_FLG(FLG_REALM2))
2152 before_str[before_n++] = "ÂèÆóÎΰè¤Î";
2153 body_str = "ËâË¡½ñ";
2156 /*** First rank spellbooks ***/
2157 if (IS_FLG(FLG_FIRST))
2159 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î1ºýÌܤÎ";
2160 body_str = "ËâË¡½ñ";
2163 /*** Second rank spellbooks ***/
2164 if (IS_FLG(FLG_SECOND))
2166 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î2ºýÌܤÎ";
2167 body_str = "ËâË¡½ñ";
2170 /*** Third rank spellbooks ***/
2171 if (IS_FLG(FLG_THIRD))
2173 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î3ºýÌܤÎ";
2174 body_str = "ËâË¡½ñ";
2177 /*** Fourth rank spellbooks ***/
2178 if (IS_FLG(FLG_FOURTH))
2180 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î4ºýÌܤÎ";
2181 body_str = "ËâË¡½ñ";
2185 if (IS_FLG(FLG_ITEMS))
2186 ; /* Nothing to do */
2187 else if (IS_FLG(FLG_WEAPONS))
2189 else if (IS_FLG(FLG_ARMORS))
2191 else if (IS_FLG(FLG_MISSILES))
2192 body_str = "ÃƤäÌð¤ä¥¯¥í¥¹¥Ü¥¦¤ÎÌð";
2193 else if (IS_FLG(FLG_DEVICES))
2194 body_str = "´¬Êª¤äËâË¡ËÀ¤ä¾ó¤ä¥í¥Ã¥É";
2195 else if (IS_FLG(FLG_LIGHTS))
2196 body_str = "¸÷¸»ÍѤΥ¢¥¤¥Æ¥à";
2197 else if (IS_FLG(FLG_JUNKS))
2198 body_str = "Àޤ줿ËÀÅù¤Î¥¬¥é¥¯¥¿";
2199 else if (IS_FLG(FLG_SPELLBOOKS))
2200 body_str = "ËâË¡½ñ";
2201 else if (IS_FLG(FLG_HAFTED))
2203 else if (IS_FLG(FLG_SHIELDS))
2205 else if (IS_FLG(FLG_BOWS))
2206 body_str = "¥¹¥ê¥ó¥°¤äµÝ¤ä¥¯¥í¥¹¥Ü¥¦";
2207 else if (IS_FLG(FLG_RINGS))
2209 else if (IS_FLG(FLG_AMULETS))
2210 body_str = "¥¢¥ß¥å¥ì¥Ã¥È";
2211 else if (IS_FLG(FLG_SUITS))
2213 else if (IS_FLG(FLG_CLOAKS))
2214 body_str = "¥¯¥í¡¼¥¯";
2215 else if (IS_FLG(FLG_HELMS))
2216 body_str = "¥Ø¥ë¥á¥Ã¥È¤ä´§";
2217 else if (IS_FLG(FLG_GLOVES))
2219 else if (IS_FLG(FLG_BOOTS))
2220 body_str = "¥Ö¡¼¥Ä";
2221 else if (IS_FLG(FLG_FAVORITE))
2222 body_str = "ÆÀ°ÕÉð´ï";
2226 strcat(buff, "Á´¤Æ¤Î");
2227 else for (i = 0; i < before_n && before_str[i]; i++)
2228 strcat(buff, before_str[i]);
2230 strcat(buff, body_str);
2240 strcat(buff, "¤Ç¡¢Ì¾Á°¤¬¡Ö");
2241 strncat(buff, str, 80);
2243 strcat(buff, "¡×¤Ç»Ï¤Þ¤ë¤â¤Î");
2245 strcat(buff, "¡×¤ò´Þ¤à¤â¤Î");
2250 strncat(buff, format("¤Ë¡Ö%s¡×", insc), 80);
2252 if (my_strstr(insc, "%%all"))
2253 strcat(buff, "(%%all¤ÏÁ´Ç½ÎϤòɽ¤¹±Ñ»ú¤Îµ¹æ¤ÇÃÖ´¹)");
2254 else if (my_strstr(insc, "%all"))
2255 strcat(buff, "(%all¤ÏÁ´Ç½ÎϤòɽ¤¹µ¹æ¤ÇÃÖ´¹)");
2256 else if (my_strstr(insc, "%%"))
2257 strcat(buff, "(%%¤ÏÄɲÃǽÎϤòɽ¤¹±Ñ»ú¤Îµ¹æ¤ÇÃÖ´¹)");
2258 else if (my_strstr(insc, "%"))
2259 strcat(buff, "(%¤ÏÄɲÃǽÎϤòɽ¤¹µ¹æ¤ÇÃÖ´¹)");
2261 strcat(buff, "¤È¹ï¤ó¤Ç");
2266 if (act & DONT_AUTOPICK)
2267 strcat(buff, "ÊüÃÖ¤¹¤ë¡£");
2268 else if (act & DO_AUTODESTROY)
2269 strcat(buff, "Ç˲õ¤¹¤ë¡£");
2270 else if (act & DO_QUERY_AUTOPICK)
2271 strcat(buff, "³Îǧ¤Î¸å¤Ë½¦¤¦¡£");
2273 strcat(buff, "½¦¤¦¡£");
2275 if (act & DO_DISPLAY)
2277 if (act & DONT_AUTOPICK)
2278 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'N'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
2279 else if (act & DO_AUTODESTROY)
2280 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'K'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
2282 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'M'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
2285 strcat(buff, "Á´ÂΥޥåפˤÏɽ¼¨¤·¤Ê¤¤¡£");
2289 cptr before_str[20], after_str[20], which_str[20], whose_str[20], body_str;
2290 int before_n = 0, after_n = 0, which_n = 0, whose_n = 0;
2294 /*** Collecting items ***/
2295 /*** Which can be absorbed into a slot as a bundle ***/
2296 if (IS_FLG(FLG_COLLECTING))
2297 which_str[which_n++] = "can be absorbed into an existing inventory slot";
2299 /*** Unidentified ***/
2300 if (IS_FLG(FLG_UNIDENTIFIED))
2301 before_str[before_n++] = "unidentified";
2303 /*** Identified ***/
2304 if (IS_FLG(FLG_IDENTIFIED))
2305 before_str[before_n++] = "identified";
2307 /*** *Identified* ***/
2308 if (IS_FLG(FLG_STAR_IDENTIFIED))
2309 before_str[before_n++] = "fully identified";
2311 /*** Worthless items ***/
2312 if (IS_FLG(FLG_WORTHLESS))
2314 before_str[before_n++] = "worthless";
2315 which_str[which_n++] = "can not be sold at stores";
2319 if (IS_FLG(FLG_ARTIFACT))
2321 before_str[before_n++] = "artifact";
2325 if (IS_FLG(FLG_EGO))
2327 before_str[before_n++] = "ego";
2331 if (IS_FLG(FLG_NAMELESS))
2333 body_str = "equipment";
2334 which_str[which_n++] = "is neither ego-item nor artifact";
2337 /*** Unaware items ***/
2338 if (IS_FLG(FLG_UNAWARE))
2340 before_str[before_n++] = "unidentified";
2341 whose_str[whose_n++] = "basic abilities are not known";
2344 /*** Dice boosted (weapon of slaying) ***/
2345 if (IS_FLG(FLG_BOOSTED))
2347 body_str = "weapons";
2348 whose_str[whose_n++] = "damage dice is bigger than normal";
2351 /*** Weapons whose dd*ds is more than nn ***/
2352 if (IS_FLG(FLG_MORE_THAN))
2354 static char more_than_desc_str[] =
2355 "maximum damage from dice is bigger than __";
2356 body_str = "weapons";
2358 sprintf(more_than_desc_str + sizeof(more_than_desc_str) - 3,
2360 whose_str[whose_n++] = more_than_desc_str;
2363 /*** Items whose magical bonus is more than nn ***/
2364 if (IS_FLG(FLG_MORE_BONUS))
2366 static char more_bonus_desc_str[] =
2367 "magical bonus is bigger than (+__)";
2369 sprintf(more_bonus_desc_str + sizeof(more_bonus_desc_str) - 4,
2370 "%d)", entry->bonus);
2371 whose_str[whose_n++] = more_bonus_desc_str;
2374 /*** Wanted monster's corpse/skeletons ***/
2375 if (IS_FLG(FLG_WANTED))
2377 body_str = "corpse or skeletons";
2378 which_str[which_n++] = "is wanted at the Hunter's Office";
2381 /*** Human corpse/skeletons (for Daemon magic) ***/
2382 if (IS_FLG(FLG_HUMAN))
2384 before_str[before_n++] = "humanoid";
2385 body_str = "corpse or skeletons";
2386 which_str[which_n++] = "can be used for Daemon magic";
2389 /*** Unique monster's corpse/skeletons/statues ***/
2390 if (IS_FLG(FLG_UNIQUE))
2392 before_str[before_n++] = "unique monster's";
2393 body_str = "corpse or skeletons";
2396 /*** Unreadable spellbooks ***/
2397 if (IS_FLG(FLG_UNREADABLE))
2399 body_str = "spellbooks";
2400 after_str[after_n++] = "of different realms from yours";
2403 /*** First realm spellbooks ***/
2404 if (IS_FLG(FLG_REALM1))
2406 body_str = "spellbooks";
2407 after_str[after_n++] = "of your first realm";
2410 /*** Second realm spellbooks ***/
2411 if (IS_FLG(FLG_REALM2))
2413 body_str = "spellbooks";
2414 after_str[after_n++] = "of your second realm";
2417 /*** First rank spellbooks ***/
2418 if (IS_FLG(FLG_FIRST))
2420 before_str[before_n++] = "first one of four";
2421 body_str = "spellbooks";
2424 /*** Second rank spellbooks ***/
2425 if (IS_FLG(FLG_SECOND))
2427 before_str[before_n++] = "second one of four";
2428 body_str = "spellbooks";
2431 /*** Third rank spellbooks ***/
2432 if (IS_FLG(FLG_THIRD))
2434 before_str[before_n++] = "third one of four";
2435 body_str = "spellbooks";
2438 /*** Fourth rank spellbooks ***/
2439 if (IS_FLG(FLG_FOURTH))
2441 before_str[before_n++] = "fourth one of four";
2442 body_str = "spellbooks";
2446 if (IS_FLG(FLG_ITEMS))
2447 ; /* Nothing to do */
2448 else if (IS_FLG(FLG_WEAPONS))
2449 body_str = "weapons";
2450 else if (IS_FLG(FLG_ARMORS))
2451 body_str = "armors";
2452 else if (IS_FLG(FLG_MISSILES))
2453 body_str = "shots, arrows or crossbow bolts";
2454 else if (IS_FLG(FLG_DEVICES))
2455 body_str = "scrolls, wands, staves or rods";
2456 else if (IS_FLG(FLG_LIGHTS))
2457 body_str = "light sources";
2458 else if (IS_FLG(FLG_JUNKS))
2459 body_str = "junk such as broken sticks";
2460 else if (IS_FLG(FLG_SPELLBOOKS))
2461 body_str = "spellbooks";
2462 else if (IS_FLG(FLG_HAFTED))
2463 body_str = "hafted weapons";
2464 else if (IS_FLG(FLG_SHIELDS))
2465 body_str = "shields";
2466 else if (IS_FLG(FLG_BOWS))
2467 body_str = "slings, bows or crossbows";
2468 else if (IS_FLG(FLG_RINGS))
2470 else if (IS_FLG(FLG_AMULETS))
2471 body_str = "amulets";
2472 else if (IS_FLG(FLG_SUITS))
2473 body_str = "body armors";
2474 else if (IS_FLG(FLG_CLOAKS))
2475 body_str = "cloaks";
2476 else if (IS_FLG(FLG_HELMS))
2477 body_str = "helms or crowns";
2478 else if (IS_FLG(FLG_GLOVES))
2479 body_str = "gloves";
2480 else if (IS_FLG(FLG_BOOTS))
2482 else if (IS_FLG(FLG_FAVORITE))
2483 body_str = "favorite weapons";
2485 /* Prepare a string for item name */
2492 whose_str[whose_n++] = "name is beginning with \"";
2495 which_str[which_n++] = "have \"";
2499 /* Describe action flag */
2500 if (act & DONT_AUTOPICK)
2501 strcpy(buff, "Leave on floor ");
2502 else if (act & DO_AUTODESTROY)
2503 strcpy(buff, "Destroy ");
2504 else if (act & DO_QUERY_AUTOPICK)
2505 strcpy(buff, "Ask to pick up ");
2507 strcpy(buff, "Pickup ");
2509 /* Auto-insctiption */
2512 strncat(buff, format("and inscribe \"%s\"", insc), 80);
2514 if (my_strstr(insc, "%all"))
2515 strcat(buff, ", replacing %all with code string representing all abilities,");
2516 else if (my_strstr(insc, "%"))
2517 strcat(buff, ", replacing % with code string representing extra random abilities,");
2519 strcat(buff, " on ");
2524 strcat(buff, "all ");
2525 else for (i = 0; i < before_n && before_str[i]; i++)
2527 strcat(buff, before_str[i]);
2532 strcat(buff, body_str);
2535 for (i = 0; i < after_n && after_str[i]; i++)
2538 strcat(buff, after_str[i]);
2542 for (i = 0; i < whose_n && whose_str[i]; i++)
2545 strcat(buff, " whose ");
2547 strcat(buff, ", and ");
2549 strcat(buff, whose_str[i]);
2552 /* Item name ; whose name is beginning with "str" */
2559 /* whose ..., and which .... */
2560 if (whose_n && which_n)
2561 strcat(buff, ", and ");
2564 for (i = 0; i < which_n && which_str[i]; i++)
2567 strcat(buff, " which ");
2569 strcat(buff, ", and ");
2571 strcat(buff, which_str[i]);
2574 /* Item name ; which have "str" as part of its name */
2577 strncat(buff, str, 80);
2578 strcat(buff, "\" as part of its name");
2582 /* Describe whether it will be displayed on the full map or not */
2583 if (act & DO_DISPLAY)
2585 if (act & DONT_AUTOPICK)
2586 strcat(buff, " Display these items when you press the N key in the full 'M'ap.");
2587 else if (act & DO_AUTODESTROY)
2588 strcat(buff, " Display these items when you press the K key in the full 'M'ap.");
2590 strcat(buff, " Display these items when you press the M key in the full 'M'ap.");
2593 strcat(buff, " Not displayed in the full map.");
2600 * Read whole lines of a file to memory
2602 static cptr *read_text_lines(cptr filename, bool user)
2604 cptr *lines_list = NULL;
2612 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2616 path_build(buf, sizeof(buf), ANGBAND_DIR_PREF, filename);
2620 fff = my_fopen(buf, "r");
2624 /* Allocate list of pointers */
2625 C_MAKE(lines_list, MAX_LINES, cptr);
2628 while (0 == my_fgets(fff, buf, sizeof(buf)))
2630 lines_list[lines++] = string_make(buf);
2631 if (lines >= MAX_LINES - 1) break;
2634 lines_list[0] = string_make("");
2639 if (!fff) return NULL;
2644 static cptr *read_pickpref_text_lines(int *filename_mode_p)
2649 *filename_mode_p = PT_WITH_PNAME;
2650 strcpy(buf, pickpref_filename(*filename_mode_p));
2651 lines_list = read_text_lines(buf, TRUE);
2655 *filename_mode_p = PT_DEFAULT;
2656 strcpy(buf, pickpref_filename(*filename_mode_p));
2657 lines_list = read_text_lines(buf, TRUE);
2662 strcpy(buf, pickpref_filename(*filename_mode_p));
2663 lines_list = read_text_lines(buf, FALSE);
2668 /* Allocate list of pointers */
2669 C_MAKE(lines_list, MAX_LINES, cptr);
2670 lines_list[0] = string_make("");
2677 * Write whole lines of memory to a file.
2679 static bool write_text_lines(cptr filename, cptr *lines_list)
2686 /* Build the filename */
2687 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2690 fff = my_fopen(buf, "w");
2693 for (lines = 0; lines_list[lines]; lines++)
2694 my_fputs(fff, lines_list[lines], 1024);
2699 if (!fff) return FALSE;
2705 * Free memory of lines_list.
2707 static void free_text_lines(cptr *lines_list)
2711 for (lines = 0; lines_list[lines]; lines++)
2712 string_free(lines_list[lines]);
2714 /* free list of pointers */
2715 C_FREE((char **)lines_list, MAX_LINES, char *);
2720 * Delete or insert string
2722 static void toggle_keyword(text_body_type *tb, int flg)
2728 /* Some lines are selected */
2731 by1 = MIN(tb->my, tb->cy);
2732 by2 = MAX(tb->my, tb->cy);
2735 /* No mark -- Select current line */
2736 else /* if (!tb->mark) */
2742 /* Set/Reset flag of each line */
2743 for (y = by1; y <= by2; y++)
2745 autopick_type an_entry, *entry = &an_entry;
2747 if (!autopick_new_entry(entry, tb->lines_list[y], !fixed)) continue;
2749 string_free(tb->lines_list[y]);
2753 /* Add? or Remove? */
2754 if (!IS_FLG(flg)) add = TRUE;
2757 /* No more change */
2761 /* You can use only one noun flag */
2762 if (FLG_NOUN_BEGIN <= flg && flg <= FLG_NOUN_END)
2765 for (i = FLG_NOUN_BEGIN; i <= FLG_NOUN_END; i++)
2769 /* You can use only one identify state flag */
2770 else if (FLG_UNAWARE <= flg && flg <= FLG_STAR_IDENTIFIED)
2773 for (i = FLG_UNAWARE; i <= FLG_STAR_IDENTIFIED; i++)
2777 /* You can use only one flag in artifact/ego/nameless */
2778 else if (FLG_ARTIFACT <= flg && flg <= FLG_NAMELESS)
2781 for (i = FLG_ARTIFACT; i <= FLG_NAMELESS; i++)
2785 if (add) ADD_FLG(flg);
2788 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
2791 tb->dirty_flags |= DIRTY_ALL;
2793 /* Text is changed */
2800 * Change command letter
2802 static void toggle_command_letter(text_body_type *tb, byte flg)
2804 autopick_type an_entry, *entry = &an_entry;
2809 /* Some lines are selected */
2812 by1 = MIN(tb->my, tb->cy);
2813 by2 = MAX(tb->my, tb->cy);
2816 /* No mark -- Select current line */
2817 else /* if (!tb->mark) */
2823 /* Set/Reset flag of each line */
2824 for (y = by1; y <= by2; y++)
2828 if (!autopick_new_entry(entry, tb->lines_list[y], FALSE)) continue;
2830 string_free(tb->lines_list[y]);
2834 /* Add? or Remove? */
2835 if (!(entry->action & flg)) add = TRUE;
2838 /* No more change */
2842 /* Count number of letter (by negative number) */
2843 if (entry->action & DONT_AUTOPICK) wid--;
2844 else if (entry->action & DO_AUTODESTROY) wid--;
2845 else if (entry->action & DO_QUERY_AUTOPICK) wid--;
2846 if (!(entry->action & DO_DISPLAY)) wid--;
2848 /* Set/Reset the flag */
2849 if (flg != DO_DISPLAY)
2851 entry->action &= ~(DO_AUTOPICK | DONT_AUTOPICK | DO_AUTODESTROY | DO_QUERY_AUTOPICK);
2852 if (add) entry->action |= flg;
2853 else entry->action |= DO_AUTOPICK;
2857 entry->action &= ~(DO_DISPLAY);
2858 if (add) entry->action |= flg;
2861 /* Correct cursor location */
2864 if (entry->action & DONT_AUTOPICK) wid++;
2865 else if (entry->action & DO_AUTODESTROY) wid++;
2866 else if (entry->action & DO_QUERY_AUTOPICK) wid++;
2867 if (!(entry->action & DO_DISPLAY)) wid++;
2869 if (wid > 0) tb->cx++;
2870 if (wid < 0 && tb->cx > 0) tb->cx--;
2873 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
2876 tb->dirty_flags |= DIRTY_ALL;
2878 /* Text is changed */
2884 * Delete or insert string
2886 static void add_keyword(text_body_type *tb, int flg)
2890 /* Some lines are selected */
2893 by1 = MIN(tb->my, tb->cy);
2894 by2 = MAX(tb->my, tb->cy);
2897 /* No mark -- Select current line */
2898 else /* if (!tb->mark) */
2904 /* Set/Reset flag of each line */
2905 for (y = by1; y <= by2; y++)
2907 autopick_type an_entry, *entry = &an_entry;
2909 if (!autopick_new_entry(entry, tb->lines_list[y], FALSE)) continue;
2911 /* There is the flag already */
2914 /* Free memory for the entry */
2915 autopick_free_entry(entry);
2920 string_free(tb->lines_list[y]);
2922 /* Remove all noun flag */
2923 if (FLG_NOUN_BEGIN <= flg && flg <= FLG_NOUN_END)
2926 for (i = FLG_NOUN_BEGIN; i <= FLG_NOUN_END; i++)
2932 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
2935 tb->dirty_flags |= DIRTY_ALL;
2937 /* Text is changed */
2944 * Check if this line is expression or not.
2945 * And update it if it is.
2947 static void check_expression_line(text_body_type *tb, int y)
2949 cptr s = tb->lines_list[y];
2951 if ((s[0] == '?' && s[1] == ':') ||
2952 (tb->states[y] & LSTAT_BYPASS))
2954 /* Expressions need re-evaluation */
2955 tb->dirty_flags |= DIRTY_EXPRESSION;
2961 * Insert return code and split the line
2963 static bool insert_return_code(text_body_type *tb)
2965 char buf[MAX_LINELEN];
2968 for (k = 0; tb->lines_list[k]; k++)
2969 /* count number of lines */ ;
2971 if (k >= MAX_LINES - 2) return FALSE;
2974 /* Move down lines */
2975 for (; tb->cy < k; k--)
2977 tb->lines_list[k+1] = tb->lines_list[k];
2978 tb->states[k+1] = tb->states[k];
2981 /* Split current line */
2982 for (i = j = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
2985 if (iskanji(tb->lines_list[tb->cy][i]))
2986 buf[j++] = tb->lines_list[tb->cy][i++];
2988 buf[j++] = tb->lines_list[tb->cy][i];
2991 tb->lines_list[tb->cy+1] = string_make(&tb->lines_list[tb->cy][i]);
2992 string_free(tb->lines_list[tb->cy]);
2993 tb->lines_list[tb->cy] = string_make(buf);
2995 /* Expressions need re-evaluation */
2996 tb->dirty_flags |= DIRTY_EXPRESSION;
2998 /* Text is changed */
3006 * Choose an item and get auto-picker entry from it.
3008 static object_type *choose_object(cptr q, cptr s)
3012 if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR | USE_EQUIP))) return NULL;
3014 /* Get the item (in the pack) */
3015 if (item >= 0) return &inventory[item];
3017 /* Get the item (on the floor) */
3018 else return &o_list[0 - item];
3023 * Choose an item and get auto-picker entry from it.
3025 static bool entry_from_choosed_object(autopick_type *entry)
3032 q = "¤É¤Î¥¢¥¤¥Æ¥à¤òÅÐÏ¿¤·¤Þ¤¹¤«? ";
3033 s = "¥¢¥¤¥Æ¥à¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£";
3035 q = "Enter which item? ";
3036 s = "You have nothing to enter.";
3038 o_ptr = choose_object(q, s);
3039 if (!o_ptr) return FALSE;
3041 autopick_entry_from_object(entry, o_ptr);
3047 * Choose an item for search
3049 static byte get_object_for_search(object_type **o_handle, cptr *search_strp)
3051 char buf[MAX_NLEN+20];
3057 q = "¤É¤Î¥¢¥¤¥Æ¥à¤ò¸¡º÷¤·¤Þ¤¹¤«? ";
3058 s = "¥¢¥¤¥Æ¥à¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£";
3060 q = "Enter which item? ";
3061 s = "You have nothing to enter.";
3063 o_ptr = choose_object(q, s);
3064 if (!o_ptr) return 0;
3068 string_free(*search_strp);
3069 object_desc(buf, *o_handle, FALSE, 3);
3070 *search_strp = string_make(format("<%s>", buf));
3076 * Prepare for search by destroyed object
3078 static byte get_destroyed_object_for_search(object_type **o_handle, cptr *search_strp)
3080 char buf[MAX_NLEN+20];
3082 if (!autopick_last_destroyed_object.k_idx) return 0;
3084 *o_handle = &autopick_last_destroyed_object;
3086 string_free(*search_strp);
3087 object_desc(buf, *o_handle, FALSE, 3);
3088 *search_strp = string_make(format("<%s>", buf));
3094 * Choose an item or string for search
3096 static byte get_string_for_search(object_type **o_handle, cptr *search_strp)
3102 * TERM_YELLOW : Overwrite mode
3103 * TERM_WHITE : Insert mode
3105 byte color = TERM_YELLOW;
3106 char buf[MAX_NLEN+20];
3110 char prompt[] = "¸¡º÷(^I:»ý¤Áʪ ^L:Ç˲õ¤µ¤ì¤¿Êª): ";
3112 char prompt[] = "Search key(^I:inven ^L:destroyed): ";
3114 int col = sizeof(prompt) - 1;
3116 if (*search_strp) strcpy(buf, *search_strp);
3119 /* Display prompt */
3129 /* Display the string */
3130 Term_erase(col, 0, 255);
3131 Term_putstr(col, 0, -1, color, buf);
3134 Term_gotoxy(col + pos, 0);
3136 /* Get a special key code */
3137 skey = inkey_special();
3139 /* Analyze the key */
3147 /* Now on insert mode */
3150 /* No move at beginning of line */
3151 if (0 == pos) break;
3155 int next_pos = i + 1;
3158 if (iskanji(buf[i])) next_pos++;
3161 /* Is there the cursor at next position? */
3162 if (next_pos >= pos) break;
3168 /* Get previous position */
3176 /* Now on insert mode */
3179 /* No move at end of line */
3180 if ('\0' == buf[pos]) break;
3184 if (iskanji(buf[pos])) pos += 2;
3202 if (!pos && *o_handle) return (back ? -1 : 1);
3203 string_free(*search_strp);
3204 *search_strp = string_make(buf);
3206 return (back ? -1 : 1);
3210 return get_object_for_search(o_handle, search_strp);
3213 /* Prepare string for destroyed object if there is one. */
3214 if (get_destroyed_object_for_search(o_handle, search_strp))
3224 /* Now on insert mode */
3227 /* No move at beginning of line */
3228 if (0 == pos) break;
3232 int next_pos = i + 1;
3235 if (iskanji(buf[i])) next_pos++;
3238 /* Is there the cursor at next position? */
3239 if (next_pos >= pos) break;
3245 /* Get previous position */
3248 /* Fall through to 'Delete key' */
3257 /* Now on insert mode */
3260 /* No move at end of line */
3261 if ('\0' == buf[pos]) break;
3263 /* Position of next character */
3267 /* Next character is one more byte away */
3268 if (iskanji(buf[pos])) src++;
3273 /* Move characters at src to dst */
3274 while ('\0' != (buf[dst++] = buf[src++]))
3282 /* Insert a character */
3287 /* Ignore special keys */
3288 if (skey & SKEY_MASK) break;
3290 /* Get a character code */
3293 if (color == TERM_YELLOW)
3295 /* Overwrite default string */
3298 /* Go to insert mode */
3302 /* Save right part of string */
3303 strcpy(tmp, buf + pos);
3309 /* Bypass macro processing */
3327 if (pos < len && (isprint(c) || iskana(c)))
3329 if (pos < len && isprint(c))
3343 /* Write back the left part of string */
3344 my_strcat(buf, tmp, len + 1);
3351 } /* while (TRUE) */
3356 * Search next line matches for o_ptr
3358 static void search_for_object(text_body_type *tb, object_type *o_ptr, bool forward)
3360 autopick_type an_entry, *entry = &an_entry;
3361 char o_name[MAX_NLEN];
3362 int bypassed_cy = -1;
3364 /* Start searching from current cursor position */
3367 /* Prepare object name string first */
3368 object_desc(o_name, o_ptr, FALSE, 3);
3370 /* Convert the string to lower case */
3371 str_tolower(o_name);
3378 if (!tb->lines_list[++i]) break;
3385 /* Is this line is a correct entry? */
3386 if (!autopick_new_entry(entry, tb->lines_list[i], FALSE)) continue;
3388 /* Does this line match to the object? */
3389 if (!is_autopick_aux(o_ptr, entry, o_name)) continue;
3392 /* Found a line but it's inactive */
3393 if (tb->states[i] & LSTAT_BYPASS)
3395 /* If it is first found, remember it */
3396 if (bypassed_cy == -1) bypassed_cy = i;
3399 /* Found an active line! */
3402 /* Move to this line */
3406 if (bypassed_cy != -1)
3408 /* Mark as some lines are skipped */
3409 tb->dirty_flags |= DIRTY_SKIP_INACTIVE;
3417 if (bypassed_cy != -1)
3419 /* Move to the remembered line */
3421 tb->cy = bypassed_cy;
3423 /* Mark as this line is inactive */
3424 tb->dirty_flags |= DIRTY_INACTIVE;
3429 /* Mark as NOT FOUND */
3430 tb->dirty_flags |= DIRTY_NOT_FOUND;
3438 * Search next line matches to the string
3440 static void search_for_string(text_body_type *tb, cptr search_str, bool forward)
3442 int bypassed_cy = -1;
3443 int bypassed_cx = 0;
3445 /* Start searching from current cursor position */
3455 if (!tb->lines_list[++i]) break;
3462 /* Look for the string pattern */
3463 pos = my_strstr(tb->lines_list[i], search_str);
3468 /* Found a line but it's inactive */
3469 if ((tb->states[i] & LSTAT_BYPASS) &&
3470 !(tb->states[i] & LSTAT_EXPRESSION))
3472 /* If it is first found, remember it */
3473 if (bypassed_cy == -1)
3476 bypassed_cx = (int)(pos - tb->lines_list[i]);
3480 /* Found an active line! */
3483 /* Move to this location */
3484 tb->cx = (int)(pos - tb->lines_list[i]);
3487 if (bypassed_cy != -1)
3489 /* Mark as some lines are skipped */
3490 tb->dirty_flags |= DIRTY_SKIP_INACTIVE;
3498 if (bypassed_cy != -1)
3500 /* Move to the remembered line */
3501 tb->cx = bypassed_cx;
3502 tb->cy = bypassed_cy;
3504 /* Mark as this line is inactive */
3505 tb->dirty_flags |= DIRTY_INACTIVE;
3510 /* Mark as NOT FOUND */
3511 tb->dirty_flags |= DIRTY_NOT_FOUND;
3521 * Editor command id's
3524 #define EC_SAVEQUIT 2
3535 #define EC_PGDOWN 13
3537 #define EC_BOTTOM 15
3542 #define EC_KILL_LINE 20
3543 #define EC_DELETE_CHAR 21
3544 #define EC_BACKSPACE 22
3545 #define EC_SEARCH_STR 23
3546 #define EC_SEARCH_FORW 24
3547 #define EC_SEARCH_BACK 25
3548 #define EC_SEARCH_OBJ 26
3549 #define EC_SEARCH_DESTROYED 27
3550 #define EC_INSERT_OBJECT 28
3551 #define EC_INSERT_DESTROYED 29
3552 #define EC_INSERT_BLOCK 30
3553 #define EC_INSERT_MACRO 31
3554 #define EC_INSERT_KEYMAP 32
3555 #define EC_CL_AUTOPICK 33
3556 #define EC_CL_DESTROY 34
3557 #define EC_CL_LEAVE 35
3558 #define EC_CL_QUERY 36
3559 #define EC_CL_NO_DISP 37
3560 #define EC_OK_COLLECTING 38
3561 #define EC_IK_UNAWARE 39
3562 #define EC_IK_UNIDENTIFIED 40
3563 #define EC_IK_IDENTIFIED 41
3564 #define EC_IK_STAR_IDENTIFIED 42
3565 #define EC_OK_BOOSTED 43
3566 #define EC_OK_MORE_THAN 44
3567 #define EC_OK_MORE_BONUS 45
3568 #define EC_OK_WORTHLESS 46
3569 #define EC_OK_ARTIFACT 47
3570 #define EC_OK_EGO 48
3571 #define EC_OK_NAMELESS 49
3572 #define EC_OK_WANTED 50
3573 #define EC_OK_UNIQUE 51
3574 #define EC_OK_HUMAN 52
3575 #define EC_OK_UNREADABLE 53
3576 #define EC_OK_REALM1 54
3577 #define EC_OK_REALM2 55
3578 #define EC_OK_FIRST 56
3579 #define EC_OK_SECOND 57
3580 #define EC_OK_THIRD 58
3581 #define EC_OK_FOURTH 59
3582 #define EC_KK_WEAPONS 60
3583 #define EC_KK_FAVORITE 61
3584 #define EC_KK_ARMORS 62
3585 #define EC_KK_MISSILES 63
3586 #define EC_KK_DEVICES 64
3587 #define EC_KK_LIGHTS 65
3588 #define EC_KK_JUNKS 66
3589 #define EC_KK_SPELLBOOKS 67
3590 #define EC_KK_SHIELDS 68
3591 #define EC_KK_BOWS 69
3592 #define EC_KK_RINGS 70
3593 #define EC_KK_AMULETS 71
3594 #define EC_KK_SUITS 72
3595 #define EC_KK_CLOAKS 73
3596 #define EC_KK_HELMS 74
3597 #define EC_KK_GLOVES 75
3598 #define EC_KK_BOOTS 76
3604 #define MN_QUIT "¥»¡¼¥Ö̵¤·¤Ç½ªÎ»"
3605 #define MN_SAVEQUIT "¥»¡¼¥Ö¤·¤Æ½ªÎ»"
3606 #define MN_REVERT "Á´¤Æ¤ÎÊѹ¹¤òÇË´þ"
3607 #define MN_HELP "¥Ø¥ë¥×"
3609 #define MN_MOVE "¥«¡¼¥½¥ë°ÜÆ°"
3610 #define MN_LEFT "º¸"
3611 #define MN_DOWN "²¼"
3613 #define MN_RIGHT "±¦"
3614 #define MN_BOL "¹Ô¤ÎÀèƬ"
3615 #define MN_EOL "¹Ô¤Î½ªÃ¼"
3616 #define MN_PGUP "¾å¤Î¥Ú¡¼¥¸"
3617 #define MN_PGDOWN "²¼¤Î¥Ú¡¼¥¸"
3618 #define MN_TOP "1¹ÔÌܤذÜÆ°"
3619 #define MN_BOTTOM "ºÇ²¼¹Ô¤Ø°ÜÆ°"
3621 #define MN_EDIT "ÊÔ½¸"
3622 #define MN_CUT "¥«¥Ã¥È"
3623 #define MN_COPY "¥³¥Ô¡¼"
3624 #define MN_PASTE "¥Ú¡¼¥¹¥È"
3625 #define MN_BLOCK "ÁªÂòÈϰϤλØÄê"
3626 #define MN_KILL_LINE "¹Ô¤Î»Ä¤ê¤òºï½ü"
3627 #define MN_DELETE_CHAR "1ʸ»úºï½ü"
3628 #define MN_BACKSPACE "¥Ð¥Ã¥¯¥¹¥Ú¡¼¥¹"
3629 #define MN_RETURN "²þ¹Ô"
3630 #define MN_RETURN "²þ¹Ô"
3632 #define MN_SEARCH "¸¡º÷"
3633 #define MN_SEARCH_STR "ʸ»úÎó¤Ç¸¡º÷"
3634 #define MN_SEARCH_FORW "Á°Êý¤ØºÆ¸¡º÷"
3635 #define MN_SEARCH_BACK "¸åÊý¤ØºÆ¸¡º÷"
3636 #define MN_SEARCH_OBJ "¥¢¥¤¥Æ¥à¤òÁªÂò¤·¤Æ¸¡º÷"
3637 #define MN_SEARCH_DESTROYED "¼«Æ°Ç˲õ¤µ¤ì¤¿¥¢¥¤¥Æ¥à¤Ç¸¡º÷"
3639 #define MN_INSERT "¿§¡¹ÁÞÆþ"
3640 #define MN_INSERT_OBJECT "ÁªÂò¤·¤¿¥¢¥¤¥Æ¥à¤Î̾Á°¤òÁÞÆþ"
3641 #define MN_INSERT_DESTROYED "¼«Æ°Ç˲õ¤µ¤ì¤¿¥¢¥¤¥Æ¥à¤Î̾Á°¤òÁÞÆþ"
3642 #define MN_INSERT_BLOCK "¾ò·ïʬ´ô¥Ö¥í¥Ã¥¯¤ÎÎã¤òÁÞÆþ"
3643 #define MN_INSERT_MACRO "¥Þ¥¯¥íÄêµÁ¤òÁÞÆþ"
3644 #define MN_INSERT_KEYMAP "¥¡¼¥Þ¥Ã¥×ÄêµÁ¤òÁÞÆþ"
3647 #define MN_COMMAND_LETTER "½¦¤¤/Ç˲õ/\x95\xfaÃÖ¤ÎÁªÂò"
3649 #define MN_COMMAND_LETTER "½¦¤¤/Ç˲õ/ÊüÃÖ¤ÎÁªÂò"
3651 #define MN_CL_AUTOPICK "¡Ö ¡× (¼«Æ°½¦¤¤)"
3652 #define MN_CL_DESTROY "¡Ö!¡× (¼«Æ°Ç˲õ)"
3654 #define MN_CL_LEAVE "¡Ö~¡× (\x95\xfaÃÖ)"
3656 #define MN_CL_LEAVE "¡Ö~¡× (ÊüÃÖ)"
3658 #define MN_CL_QUERY "¡Ö;¡× (³Îǧ¤·¤Æ½¦¤¦)"
3659 #define MN_CL_NO_DISP "¡Ö(¡× (¥Þ¥Ã¥×¥³¥Þ¥ó¥É¤Çɽ¼¨¤·¤Ê¤¤)"
3661 #define MN_ADJECTIVE_GEN "·ÁÍÆ»ì(°ìÈÌ)¤ÎÁªÂò"
3663 #define MN_ADJECTIVE_SPECIAL "·ÁÍÆ»ì(Æüì)¤ÎÁªÂò"
3664 #define MN_BOOSTED "¥À¥¤¥¹Ìܤΰ㤦 (Éð´ï)"
3665 #define MN_MORE_THAN "¥À¥¤¥¹ÌÜ # °Ê¾å¤Î (Éð´ï)"
3666 #define MN_MORE_BONUS "½¤ÀµÃÍ # °Ê¾å¤Î (»ØÎØÅù)"
3667 #define MN_ARTIFACT "¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È (ÁõÈ÷)"
3668 #define MN_EGO "¥¨¥´ (ÁõÈ÷)"
3669 #define MN_NAMELESS "̵ÌäΠ(ÁõÈ÷)"
3670 #define MN_WANTED "¾Þ¶â¼ó¤Î (»àÂÎ)"
3671 #define MN_UNIQUE "¥æ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼¤Î (»àÂÎ)"
3672 #define MN_HUMAN "¿Í´Ö¤Î (»àÂÎ)"
3673 #define MN_UNREADABLE "Æɤá¤Ê¤¤ (ËâË¡½ñ)"
3674 #define MN_REALM1 "Âè°ìÎΰè¤Î (ËâË¡½ñ)"
3675 #define MN_REALM2 "ÂèÆóÎΰè¤Î (ËâË¡½ñ)"
3676 #define MN_FIRST "1ºýÌܤΠ(ËâË¡½ñ)"
3677 #define MN_SECOND "2ºýÌܤΠ(ËâË¡½ñ)"
3678 #define MN_THIRD "3ºýÌܤΠ(ËâË¡½ñ)"
3679 #define MN_FOURTH "4ºýÌܤΠ(ËâË¡½ñ)"
3681 #define MN_NOUN "̾»ì¤ÎÁªÂò"
3685 #define MN_QUIT "Quit without save"
3686 #define MN_SAVEQUIT "Save & Quit"
3687 #define MN_REVERT "Revert all changes"
3688 #define MN_HELP "Help"
3690 #define MN_MOVE "Move cursor"
3691 #define MN_LEFT "Left"
3692 #define MN_DOWN "Down"
3694 #define MN_RIGHT "Right"
3695 #define MN_BOL "Beggining of line"
3696 #define MN_EOL "End of line"
3697 #define MN_PGUP "Page up"
3698 #define MN_PGDOWN "Page down"
3699 #define MN_TOP "Top"
3700 #define MN_BOTTOM "Bottom"
3702 #define MN_EDIT "Edit"
3703 #define MN_CUT "Cut"
3704 #define MN_COPY "Copy"
3705 #define MN_PASTE "Paste"
3706 #define MN_BLOCK "Select block"
3707 #define MN_KILL_LINE "Kill rest of line"
3708 #define MN_DELETE_CHAR "Delete character"
3709 #define MN_BACKSPACE "Backspace"
3710 #define MN_RETURN "Return"
3711 #define MN_RETURN "Return"
3713 #define MN_SEARCH "Search"
3714 #define MN_SEARCH_STR "Search by string"
3715 #define MN_SEARCH_FORW "Search forward"
3716 #define MN_SEARCH_BACK "Search backward"
3717 #define MN_SEARCH_OBJ "Search by inventory object"
3718 #define MN_SEARCH_DESTROYED "Search by destroyed object"
3720 #define MN_INSERT "Insert..."
3721 #define MN_INSERT_OBJECT "Insert name of choosen object"
3722 #define MN_INSERT_DESTROYED "Insert name of destroyed object"
3723 #define MN_INSERT_BLOCK "Insert conditional block"
3724 #define MN_INSERT_MACRO "Insert a macro definition"
3725 #define MN_INSERT_KEYMAP "Insert a keymap definition"
3727 #define MN_COMMAND_LETTER "Command letter"
3728 #define MN_CL_AUTOPICK "' ' (Auto pick)"
3729 #define MN_CL_DESTROY "'!' (Auto destroy)"
3730 #define MN_CL_LEAVE "'~' (Leave it on the floor)"
3731 #define MN_CL_QUERY "';' (Query to pick up)"
3732 #define MN_CL_NO_DISP "'(' (No display on the large map)"
3734 #define MN_ADJECTIVE_GEN "Adjective (general)"
3736 #define MN_ADJECTIVE_SPECIAL "Adjective (special)"
3737 #define MN_BOOSTED "dice boosted (weapons)"
3738 #define MN_MORE_THAN "more than # dice (weapons)"
3739 #define MN_MORE_BONUS "more bonus than # (rings etc.)"
3740 #define MN_ARTIFACT "artifact (equipments)"
3741 #define MN_EGO "ego (equipments)"
3742 #define MN_NAMELESS "nameless (equipments)"
3743 #define MN_WANTED "wanted (corpse)"
3744 #define MN_UNIQUE "unique (corpse)"
3745 #define MN_HUMAN "human (corpse)"
3746 #define MN_UNREADABLE "unreadable (spellbooks)"
3747 #define MN_REALM1 "realm1 (spellbooks)"
3748 #define MN_REALM2 "realm2 (spellbooks)"
3749 #define MN_FIRST "first (spellbooks)"
3750 #define MN_SECOND "second (spellbooks)"
3751 #define MN_THIRD "third (spellbooks)"
3752 #define MN_FOURTH "fourth (spellbooks)"
3754 #define MN_NOUN "Keywords (noun)"
3764 } command_menu_type;
3767 command_menu_type menu_data[] =
3769 {MN_HELP, 0, -1, EC_HELP},
3770 {MN_QUIT, 0, KTRL('q'), EC_QUIT},
3771 {MN_SAVEQUIT, 0, KTRL('w'), EC_SAVEQUIT},
3772 {MN_REVERT, 0, KTRL('z'), EC_REVERT},
3774 {MN_EDIT, 0, -1, -1},
3775 {MN_CUT, 1, KTRL('x'), EC_CUT},
3776 {MN_COPY, 1, KTRL('c'), EC_COPY},
3777 {MN_PASTE, 1, KTRL('v'), EC_PASTE},
3778 {MN_BLOCK, 1, KTRL('g'), EC_BLOCK},
3779 {MN_KILL_LINE, 1, KTRL('k'), EC_KILL_LINE},
3780 {MN_DELETE_CHAR, 1, KTRL('d'), EC_DELETE_CHAR},
3781 {MN_BACKSPACE, 1, KTRL('h'), EC_BACKSPACE},
3782 {MN_RETURN, 1, KTRL('j'), EC_RETURN},
3783 {MN_RETURN, 1, KTRL('m'), EC_RETURN},
3785 {MN_SEARCH, 0, -1, -1},
3786 {MN_SEARCH_STR, 1, KTRL('s'), EC_SEARCH_STR},
3787 {MN_SEARCH_FORW, 1, -1, EC_SEARCH_FORW},
3788 {MN_SEARCH_BACK, 1, KTRL('r'), EC_SEARCH_BACK},
3789 {MN_SEARCH_OBJ, 1, KTRL('y'), EC_SEARCH_OBJ},
3790 {MN_SEARCH_DESTROYED, 1, -1, EC_SEARCH_DESTROYED},
3792 {MN_MOVE, 0, -1, -1},
3793 {MN_LEFT, 1, KTRL('b'), EC_LEFT},
3794 {MN_DOWN, 1, KTRL('n'), EC_DOWN},
3795 {MN_UP, 1, KTRL('p'), EC_UP},
3796 {MN_RIGHT, 1, KTRL('f'), EC_RIGHT},
3797 {MN_BOL, 1, KTRL('a'), EC_BOL},
3798 {MN_EOL, 1, KTRL('e'), EC_EOL},
3799 {MN_PGUP, 1, KTRL('o'), EC_PGUP},
3800 {MN_PGDOWN, 1, KTRL('l'), EC_PGDOWN},
3801 {MN_TOP, 1, KTRL('t'), EC_TOP},
3802 {MN_BOTTOM, 1, KTRL('u'), EC_BOTTOM},
3804 {MN_INSERT, 0, -1, -1},
3805 {MN_INSERT_OBJECT, 1, KTRL('i'), EC_INSERT_OBJECT},
3806 {MN_INSERT_DESTROYED, 1, -1, EC_INSERT_DESTROYED},
3807 {MN_INSERT_BLOCK, 1, -1, EC_INSERT_BLOCK},
3808 {MN_INSERT_MACRO, 1, -1, EC_INSERT_MACRO},
3809 {MN_INSERT_KEYMAP, 1, -1, EC_INSERT_KEYMAP},
3811 {MN_ADJECTIVE_GEN, 0, -1, -1},
3812 {KEY_UNAWARE, 1, -1, EC_IK_UNAWARE},
3813 {KEY_UNIDENTIFIED, 1, -1, EC_IK_UNIDENTIFIED},
3814 {KEY_IDENTIFIED, 1, -1, EC_IK_IDENTIFIED},
3815 {KEY_STAR_IDENTIFIED, 1, -1, EC_IK_STAR_IDENTIFIED},
3816 {KEY_COLLECTING, 1, -1, EC_OK_COLLECTING},
3817 {KEY_WORTHLESS, 1, -1, EC_OK_WORTHLESS},
3819 {MN_ADJECTIVE_SPECIAL, 0, -1, -1},
3820 {MN_BOOSTED, 1, -1, EC_OK_BOOSTED},
3821 {MN_MORE_THAN, 1, -1, EC_OK_MORE_THAN},
3822 {MN_MORE_BONUS, 1, -1, EC_OK_MORE_BONUS},
3823 {MN_ARTIFACT, 1, -1, EC_OK_ARTIFACT},
3824 {MN_EGO, 1, -1, EC_OK_EGO},
3825 {MN_NAMELESS, 1, -1, EC_OK_NAMELESS},
3826 {MN_WANTED, 1, -1, EC_OK_WANTED},
3827 {MN_UNIQUE, 1, -1, EC_OK_UNIQUE},
3828 {MN_HUMAN, 1, -1, EC_OK_HUMAN},
3829 {MN_UNREADABLE, 1, -1, EC_OK_UNREADABLE},
3830 {MN_REALM1, 1, -1, EC_OK_REALM1},
3831 {MN_REALM2, 1, -1, EC_OK_REALM2},
3832 {MN_FIRST, 1, -1, EC_OK_FIRST},
3833 {MN_SECOND, 1, -1, EC_OK_SECOND},
3834 {MN_THIRD, 1, -1, EC_OK_THIRD},
3835 {MN_FOURTH, 1, -1, EC_OK_FOURTH},
3837 {MN_NOUN, 0, -1, -1},
3838 {KEY_WEAPONS, 1, -1, EC_KK_WEAPONS},
3839 {KEY_FAVORITE, 1, -1, EC_KK_FAVORITE},
3840 {KEY_ARMORS, 1, -1, EC_KK_ARMORS},
3841 {KEY_MISSILES, 1, -1, EC_KK_MISSILES},
3842 {KEY_DEVICES, 1, -1, EC_KK_DEVICES},
3843 {KEY_LIGHTS, 1, -1, EC_KK_LIGHTS},
3844 {KEY_JUNKS, 1, -1, EC_KK_JUNKS},
3845 {KEY_SPELLBOOKS, 1, -1, EC_KK_SPELLBOOKS},
3846 {KEY_SHIELDS, 1, -1, EC_KK_SHIELDS},
3847 {KEY_BOWS, 1, -1, EC_KK_BOWS},
3848 {KEY_RINGS, 1, -1, EC_KK_RINGS},
3849 {KEY_AMULETS, 1, -1, EC_KK_AMULETS},
3850 {KEY_SUITS, 1, -1, EC_KK_SUITS},
3851 {KEY_CLOAKS, 1, -1, EC_KK_CLOAKS},
3852 {KEY_HELMS, 1, -1, EC_KK_HELMS},
3853 {KEY_GLOVES, 1, -1, EC_KK_GLOVES},
3854 {KEY_BOOTS, 1, -1, EC_KK_BOOTS},
3856 {MN_COMMAND_LETTER, 0, -1, -1},
3857 {MN_CL_AUTOPICK, 1, -1, EC_CL_AUTOPICK},
3858 {MN_CL_DESTROY, 1, -1, EC_CL_DESTROY},
3859 {MN_CL_LEAVE, 1, -1, EC_CL_LEAVE},
3860 {MN_CL_QUERY, 1, -1, EC_CL_QUERY},
3861 {MN_CL_NO_DISP, 1, -1, EC_CL_NO_DISP},
3863 {MN_DELETE_CHAR, -1, 0x7F, EC_DELETE_CHAR},
3870 * Find a command by 'key'.
3872 static int get_com_id(char key)
3876 for (i = 0; menu_data[i].name; i++)
3878 if (menu_data[i].key == key)
3880 return menu_data[i].com_id;
3889 * Display the menu, and get a command
3891 static int do_command_menu(int level, int start)
3896 int col0 = 5 + level*7;
3897 int row0 = 1 + level*3;
3899 int menu_id_list[26];
3901 char linestr[MAX_LINELEN];
3903 /* Get max length */
3905 for (i = start; menu_data[i].level >= level; i++)
3909 /* Ignore lower level sub menus */
3910 if (menu_data[i].level > level) continue;
3912 len = strlen(menu_data[i].name);
3913 if (len > max_len) max_len = len;
3915 menu_id_list[menu_key] = i;
3919 while (menu_key < 26)
3921 menu_id_list[menu_key] = -1;
3925 /* Extra space for displaying menu key and command key */
3926 max_menu_wid = max_len + 3 + 3;
3928 /* Prepare box line */
3930 strcat(linestr, "+");
3931 for (i = 0; i < max_menu_wid + 2; i++)
3933 strcat(linestr, "-");
3935 strcat(linestr, "+");
3945 int row1 = row0 + 1;
3948 Term_putstr(col0, row0, -1, TERM_WHITE, linestr);
3950 /* Draw menu items */
3952 for (i = start; menu_data[i].level >= level; i++)
3954 char com_key_str[3];
3957 /* Ignore lower level sub menus */
3958 if (menu_data[i].level > level) continue;
3960 if (menu_data[i].com_id == -1)
3963 strcpy(com_key_str, "¢§");
3965 strcpy(com_key_str, ">");
3968 else if (menu_data[i].key != -1)
3970 com_key_str[0] = '^';
3971 com_key_str[1] = menu_data[i].key + '@';
3972 com_key_str[2] = '\0';
3976 com_key_str[0] = '\0';
3979 str = format("| %c) %-*s %2s | ", menu_key + 'a', max_len, menu_data[i].name, com_key_str);
3981 Term_putstr(col0, row1++, -1, TERM_WHITE, str);
3986 /* Draw bottom line */
3987 Term_putstr(col0, row1, -1, TERM_WHITE, linestr);
3989 /* The menu was shown */
3993 prt(format("(a-%c) ¥³¥Þ¥ó¥É:", menu_key + 'a' - 1), 0, 0);
3995 prt(format("(a-%c) Command:", menu_key + 'a' - 1), 0, 0);
3999 if (key == ESCAPE) return 0;
4001 if ('a' <= key && key <= 'z')
4003 menu_id = menu_id_list[key - 'a'];
4007 com_id = menu_data[menu_id].com_id;
4011 com_id = do_command_menu(level + 1, menu_id + 1);
4013 if (com_id) return com_id;
4025 com_id = get_com_id(key);
4026 if (com_id) return com_id;
4033 static chain_str_type *new_chain_str(cptr str)
4035 chain_str_type *chain;
4037 size_t len = strlen(str);
4039 chain = (chain_str_type *)ralloc(sizeof(chain_str_type) + len * sizeof(char));
4041 strcpy(chain->s, str);
4048 static void kill_yank_chain(text_body_type *tb)
4050 chain_str_type *chain = tb->yank;
4052 tb->yank_eol = TRUE;
4056 chain_str_type *next = chain->next;
4057 size_t len = strlen(chain->s);
4059 rnfree(chain, sizeof(chain_str_type) + len * sizeof(char));
4066 static void add_str_to_yank(text_body_type *tb, cptr str)
4068 chain_str_type *chain;
4070 tb->yank_eol = FALSE;
4072 if (NULL == tb->yank)
4074 tb->yank = new_chain_str(str);
4084 chain->next = new_chain_str(str);
4089 chain = chain->next;
4094 #define DESCRIPT_HGT 3
4099 static void draw_text_editor(text_body_type *tb)
4102 int by1 = 0, by2 = 0;
4105 Term_get_size(&tb->wid, &tb->hgt);
4108 * Top line (-1), description line (-3), separator (-1)
4111 tb->hgt -= 2 + DESCRIPT_HGT;
4114 /* Don't let cursor at second byte of kanji */
4115 for (i = 0; tb->lines_list[tb->cy][i]; i++)
4116 if (iskanji(tb->lines_list[tb->cy][i]))
4127 /* Scroll if necessary */
4128 if (tb->cy < tb->upper || tb->upper + tb->hgt <= tb->cy)
4129 tb->upper = tb->cy - (tb->hgt)/2;
4132 if ((tb->cx < tb->left + 10 && tb->left > 0) || tb->left + tb->wid - 5 <= tb->cx)
4133 tb->left = tb->cx - (tb->wid)*2/3;
4137 /* Redraw whole window after resize */
4138 if (tb->old_wid != tb->wid || tb->old_hgt != tb->hgt)
4139 tb->dirty_flags |= DIRTY_SCREEN;
4141 /* Redraw all text after scroll */
4142 else if (tb->old_upper != tb->upper || tb->old_left != tb->left)
4143 tb->dirty_flags |= DIRTY_ALL;
4146 if (tb->dirty_flags & DIRTY_SCREEN)
4148 tb->dirty_flags |= (DIRTY_ALL | DIRTY_MODE);
4154 /* Redraw mode line */
4155 if (tb->dirty_flags & DIRTY_MODE)
4157 char buf[MAX_LINELEN];
4159 int sepa_length = tb->wid;
4162 for (i = 0; i < sepa_length; i++)
4166 Term_putstr(0, tb->hgt + 1, sepa_length, TERM_WHITE, buf);
4169 if (tb->dirty_flags & DIRTY_EXPRESSION)
4174 for (y = 0; tb->lines_list[y]; y++)
4178 cptr s = tb->lines_list[y];
4180 /* Update this line's state */
4181 tb->states[y] = state;
4183 if (*s++ != '?') continue;
4184 if (*s++ != ':') continue;
4186 /* Lines below this line are auto-registered */
4187 if (streq(s, "$AUTOREGISTER"))
4188 state |= LSTAT_AUTOREGISTER;
4190 /* Parse the expr */
4191 v = process_pref_file_expr(&s, &f);
4194 if (streq(v, "0")) state |= LSTAT_BYPASS;
4195 else state &= ~LSTAT_BYPASS;
4197 /* Re-update this line's state */
4198 tb->states[y] = state | LSTAT_EXPRESSION;
4201 tb->dirty_flags |= DIRTY_ALL;
4206 int tmp_cx = tb->cx;
4207 int len = strlen(tb->lines_list[tb->cy]);
4209 /* Correct cursor location */
4210 if (tb->cx > len) tmp_cx = len;
4212 tb->dirty_flags |= DIRTY_ALL;
4214 by1 = MIN(tb->my, tb->cy);
4215 by2 = MAX(tb->my, tb->cy);
4218 /* Dump up to tb->hgt lines of messages */
4219 for (i = 0; i < tb->hgt; i++)
4225 int y = tb->upper+i;
4227 /* clean or dirty? */
4228 if (!(tb->dirty_flags & DIRTY_ALL) && (tb->dirty_line != y))
4231 msg = tb->lines_list[y];
4234 /* Apply horizontal scroll */
4235 for (j = 0; *msg; msg++, j++)
4237 if (j == tb->left) break;
4253 Term_erase(0, i + 1, tb->wid);
4255 if (tb->states[y] & LSTAT_AUTOREGISTER)
4257 /* Warning color -- These lines will be deleted later */
4262 /* Bypassed line will be displayed by darker color */
4263 if (tb->states[y] & LSTAT_BYPASS) color = TERM_SLATE;
4264 else color = TERM_WHITE;
4267 /* No mark or Out of mark */
4268 if (!tb->mark || (y < by1 || by2 < y))
4270 /* Dump the messages, bottom to top */
4271 Term_putstr(leftcol, i + 1, tb->wid - 1, color, msg);
4274 /* Multiple lines selected */
4275 else if (by1 != by2)
4277 /* Dump the messages, bottom to top */
4278 Term_putstr(leftcol, i + 1, tb->wid - 1, TERM_YELLOW, msg);
4281 /* Single line selected */
4284 int x0 = leftcol + tb->left;
4285 int len = strlen(tb->lines_list[tb->cy]);
4286 int bx1 = MIN(tb->mx, tb->cx);
4287 int bx2 = MAX(tb->mx, tb->cx);
4289 /* Correct cursor location */
4290 if (bx2 > len) bx2 = len;
4292 Term_gotoxy(leftcol, i + 1);
4293 if (x0 < bx1) Term_addstr(bx1 - x0, color, msg);
4294 if (x0 < bx2) Term_addstr(bx2 - bx1, TERM_YELLOW, msg + (bx1 - x0));
4295 Term_addstr(-1, color, msg + (bx2 - x0));
4299 for (; i < tb->hgt; i++)
4302 Term_erase(0, i + 1, tb->wid);
4305 /* Display information when updated */
4306 if (tb->old_cy != tb->cy || (tb->dirty_flags & (DIRTY_ALL | DIRTY_NOT_FOUND | DIRTY_NO_SEARCH)) || tb->dirty_line == tb->cy)
4308 autopick_type an_entry, *entry = &an_entry;
4309 cptr str1 = NULL, str2 = NULL;
4312 /* Clear information line */
4313 for (i = 0; i < DESCRIPT_HGT; i++)
4316 Term_erase(0, tb->hgt + 2 + i, tb->wid);
4319 /* Display information */
4320 if (tb->dirty_flags & DIRTY_NOT_FOUND)
4323 str1 = format("¥Ñ¥¿¡¼¥ó¤¬¸«¤Ä¤«¤ê¤Þ¤»¤ó: %s", tb->search_str);
4325 str1 = format("Pattern not found: %s", tb->search_str);
4328 else if (tb->dirty_flags & DIRTY_SKIP_INACTIVE)
4331 str1 = format("̵¸ú¾õÂ֤ιԤò¥¹¥¥Ã¥×¤·¤Þ¤·¤¿¡£(%s¤ò¸¡º÷Ãæ)", tb->search_str);
4333 str1 = format("Some inactive lines are skipped. (Searching %s)", tb->search_str);
4336 else if (tb->dirty_flags & DIRTY_INACTIVE)
4339 str1 = format("̵¸ú¾õÂ֤ιԤÀ¤±¤¬¸«ÉÕ¤«¤ê¤Þ¤·¤¿¡£(%s¤ò¸¡º÷Ãæ)", tb->search_str);
4341 str1 = format("Found only an inactive line. (Searching %s)", tb->search_str);
4344 else if (tb->dirty_flags & DIRTY_NO_SEARCH)
4347 str1 = "¸¡º÷¤¹¤ë¥Ñ¥¿¡¼¥ó¤¬¤¢¤ê¤Þ¤»¤ó(^S ¤Ç¸¡º÷)¡£";
4349 str1 = "No pattern to search. (Press ^S to search.)";
4352 else if (tb->lines_list[tb->cy][0] == '#')
4355 str1 = "¤³¤Î¹Ô¤Ï¥³¥á¥ó¥È¤Ç¤¹¡£";
4357 str1 = "This line is a comment.";
4360 else if (tb->lines_list[tb->cy][1] == ':')
4362 switch(tb->lines_list[tb->cy][0])
4366 str1 = "¤³¤Î¹Ô¤Ï¾ò·ïʬ´ô¼°¤Ç¤¹¡£";
4368 str1 = "This line is a Conditional Expression.";
4374 str1 = "¤³¤Î¹Ô¤Ï¥Þ¥¯¥í¤Î¼Â¹ÔÆâÍƤòÄêµÁ¤·¤Þ¤¹¡£";
4376 str1 = "This line defines a Macro action.";
4381 str1 = "¤³¤Î¹Ô¤Ï¥Þ¥¯¥í¤Î¥È¥ê¥¬¡¼¡¦¥¡¼¤òÄêµÁ¤·¤Þ¤¹¡£";
4383 str1 = "This line defines a Macro trigger key.";
4388 str1 = "¤³¤Î¹Ô¤Ï¥¡¼ÇÛÃÖ¤òÄêµÁ¤·¤Þ¤¹¡£";
4390 str1 = "This line defines a Keymap.";
4395 switch(tb->lines_list[tb->cy][0])
4398 if (tb->states[tb->cy] & LSTAT_BYPASS)
4401 str2 = "¸½ºß¤Î¼°¤ÎÃͤϡֵ¶(=0)¡×¤Ç¤¹¡£";
4403 str2 = "The expression is 'False'(=0) currently.";
4409 str2 = "¸½ºß¤Î¼°¤ÎÃͤϡֿ¿(=1)¡×¤Ç¤¹¡£";
4411 str2 = "The expression is 'True'(=1) currently.";
4417 if (tb->states[tb->cy] & LSTAT_AUTOREGISTER)
4420 str2 = "¤³¤Î¹Ô¤Ï¸å¤Çºï½ü¤µ¤ì¤Þ¤¹¡£";
4422 str2 = "This line will be delete later.";
4426 else if (tb->states[tb->cy] & LSTAT_BYPASS)
4429 str2 = "¤³¤Î¹Ô¤Ï¸½ºß¤Ï̵¸ú¤Ê¾õÂ֤Ǥ¹¡£";
4431 str2 = "This line is bypassed currently.";
4438 /* Get description of an autopicker preference line */
4439 else if (autopick_new_entry(entry, tb->lines_list[tb->cy], FALSE))
4441 char buf[MAX_LINELEN];
4442 char temp[MAX_LINELEN];
4445 describe_autopick(buf, entry);
4447 if (tb->states[tb->cy] & LSTAT_AUTOREGISTER)
4450 strcat(buf, "¤³¤Î¹Ô¤Ï¸å¤Çºï½ü¤µ¤ì¤Þ¤¹¡£");
4452 strcat(buf, " This line will be delete later.");
4456 if (tb->states[tb->cy] & LSTAT_BYPASS)
4459 strcat(buf, "¤³¤Î¹Ô¤Ï¸½ºß¤Ï̵¸ú¤Ê¾õÂ֤Ǥ¹¡£");
4461 strcat(buf, " This line is bypassed currently.");
4465 roff_to_buf(buf, 81, temp, sizeof(temp));
4467 for (i = 0; i < 3; i++)
4473 prt(t, tb->hgt +1 + 1 + i, 0);
4477 autopick_free_entry(entry);
4480 /* Draw the first line */
4481 if (str1) prt(str1, tb->hgt +1 + 1, 0);
4483 /* Draw the second line */
4484 if (str2) prt(str2, tb->hgt +1 + 2, 0);
4490 * Kill segment of a line
4492 static void kill_line_segment(text_body_type *tb, int y, int x0, int x1, bool whole)
4494 char buf[MAX_LINELEN];
4495 cptr s = tb->lines_list[y];
4499 /* Kill whole line? */
4500 if (whole && x0 == 0 && s[x1] == '\0' && tb->lines_list[y+1])
4504 string_free(tb->lines_list[y]);
4506 /* Shift lines up */
4507 for (i = y; tb->lines_list[i+1]; i++)
4508 tb->lines_list[i] = tb->lines_list[i+1];
4509 tb->lines_list[i] = NULL;
4511 /* Expressions need re-evaluation */
4512 tb->dirty_flags |= DIRTY_EXPRESSION;
4518 if (x0 == x1) return;
4520 /* Before the segment */
4521 for (x = 0; x < x0; x++)
4524 /* After the segment */
4525 for (x = x1; s[x]; x++)
4531 string_free(tb->lines_list[y]);
4532 tb->lines_list[y] = string_make(buf);
4534 /* Expressions may need re-evaluation */
4535 check_expression_line(tb, y);
4537 /* Text is changed */
4543 * Get a trigger key and insert ASCII string for the trigger
4545 static bool insert_macro_line(text_body_type *tb)
4554 /* Do not process macros */
4560 /* Read the pattern */
4566 /* Do not process macros */
4569 /* Do not wait for keys */
4572 /* Attempt to read a key */
4582 /* Convert the trigger */
4583 ascii_to_text(tmp, buf);
4586 if(!tmp[0]) return FALSE;
4590 /* Insert preference string */
4591 insert_return_code(tb);
4592 string_free(tb->lines_list[tb->cy]);
4593 tb->lines_list[tb->cy] = string_make(format("P:%s", tmp));
4595 /* Acquire action */
4596 i = macro_find_exact(buf);
4600 /* Nothing defined */
4605 /* Analyze the current action */
4606 ascii_to_text(tmp, macro__act[i]);
4609 /* Insert blank action preference line */
4610 insert_return_code(tb);
4611 string_free(tb->lines_list[tb->cy]);
4612 tb->lines_list[tb->cy] = string_make(format("A:%s", tmp));
4619 * Get a command key and insert ASCII string for the key
4621 static bool insert_keymap_line(text_body_type *tb)
4629 if (rogue_like_commands)
4631 mode = KEYMAP_MODE_ROGUE;
4637 mode = KEYMAP_MODE_ORIG;
4650 /* Convert the trigger */
4651 ascii_to_text(tmp, buf);
4654 if(!tmp[0]) return FALSE;
4658 /* Insert preference string */
4659 insert_return_code(tb);
4660 string_free(tb->lines_list[tb->cy]);
4661 tb->lines_list[tb->cy] = string_make(format("C:%d:%s", mode, tmp));
4663 /* Look up the keymap */
4664 act = keymap_act[mode][(byte)(buf[0])];
4666 /* Insert blank action preference line */
4667 insert_return_code(tb);
4668 string_free(tb->lines_list[tb->cy]);
4669 tb->lines_list[tb->cy] = string_make(format("A:%s", act));
4676 * Execute a single editor command
4678 static bool do_editor_command(text_body_type *tb, int com_id)
4686 if (!get_check("Á´¤Æ¤ÎÊѹ¹¤òÇË´þ¤·¤Æ¤«¤é½ªÎ»¤·¤Þ¤¹¡£¤è¤í¤·¤¤¤Ç¤¹¤«¡© ")) break;
4688 if (!get_check("Discard all changes and quit. Are you sure? ")) break;
4691 return QUIT_WITHOUT_SAVE;
4694 return QUIT_AND_SAVE;
4697 /* Revert to original */
4699 if (!get_check("Á´¤Æ¤ÎÊѹ¹¤òÇË´þ¤·¤Æ¸µ¤Î¾õÂÖ¤ËÌᤷ¤Þ¤¹¡£¤è¤í¤·¤¤¤Ç¤¹¤«¡© ")) break;
4701 if (!get_check("Discard all changes and revert to original file. Are you sure? ")) break;
4704 free_text_lines(tb->lines_list);
4705 tb->lines_list = read_pickpref_text_lines(&tb->filename_mode);
4706 tb->dirty_flags |= DIRTY_ALL | DIRTY_MODE | DIRTY_EXPRESSION;
4707 tb->cx = tb->cy = 0;
4710 /* Text is not changed */
4711 tb->changed = FALSE;
4715 /* Peruse the main help file */
4717 (void)show_file(TRUE, "jeditor.txt", NULL, 0, 0);
4719 (void)show_file(TRUE, "editor.txt", NULL, 0, 0);
4722 tb->dirty_flags |= DIRTY_SCREEN;
4727 /* Split a line or insert end of line */
4729 /* Ignore selection */
4735 tb->dirty_flags |= DIRTY_ALL;
4738 insert_return_code(tb);
4743 tb->dirty_flags |= DIRTY_ALL;
4753 len = strlen(tb->lines_list[tb->cy]);
4754 if (len < tb->cx) tb->cx = len;
4756 else if (tb->cy > 0)
4759 tb->cx = strlen(tb->lines_list[tb->cy]);
4765 if (tb->lines_list[tb->cy + 1]) tb->cy++;
4770 if (tb->cy > 0) tb->cy--;
4779 if (iskanji(tb->lines_list[tb->cy][tb->cx])) tb->cx++;
4782 len = strlen(tb->lines_list[tb->cy]);
4785 if (tb->lines_list[tb->cy + 1])
4797 /* Beginning of line */
4803 tb->cx = strlen(tb->lines_list[tb->cy]);
4807 while (0 < tb->cy && tb->upper <= tb->cy)
4809 while (0 < tb->upper && tb->cy + 1 < tb->upper + tb->hgt)
4815 while (tb->cy < tb->upper + tb->hgt && tb->lines_list[tb->cy + 1])
4825 while (tb->lines_list[tb->cy + 1])
4831 /* Copy the text first */
4832 do_editor_command(tb, EC_COPY);
4834 /* Single line case */
4835 if (tb->my == tb->cy)
4837 int bx1 = MIN(tb->mx, tb->cx);
4838 int bx2 = MAX(tb->mx, tb->cx);
4839 int len = strlen(tb->lines_list[tb->cy]);
4841 /* Correct fake cursor position */
4842 if (bx2 > len) bx2 = len;
4844 kill_line_segment(tb, tb->cy, bx1, bx2, TRUE);
4846 /* New cursor position */
4850 /* Multiple lines case */
4851 else /* if (tb->my != tb->cy) */
4855 int by1 = MIN(tb->my, tb->cy);
4856 int by2 = MAX(tb->my, tb->cy);
4858 /* Kill lines in reverse order */
4859 for (y = by2; y >= by1; y--)
4861 int len = strlen(tb->lines_list[y]);
4863 kill_line_segment(tb, y, 0, len, TRUE);
4866 /* New cursor position */
4872 /* Disable selection */
4876 tb->dirty_flags |= DIRTY_ALL;
4883 int len = strlen(tb->lines_list[tb->cy]);
4885 /* Correct cursor location */
4886 if (tb->cx > len) tb->cx = len;
4888 /* Use single line? */
4891 /* Select a single line */
4897 /* Kill old yank buffer */
4898 kill_yank_chain(tb);
4901 /* Single line case */
4902 if (tb->my == tb->cy)
4905 char buf[MAX_LINELEN];
4906 int bx1 = MIN(tb->mx, tb->cx);
4907 int bx2 = MAX(tb->mx, tb->cx);
4909 /* Correct fake cursor position */
4910 if (bx2 > len) bx2 = len;
4912 /* Whole part of this line is selected */
4913 if (bx1 == 0 && bx2 == len)
4915 /* Copy this line */
4916 add_str_to_yank(tb, tb->lines_list[tb->cy]);
4918 /* Add end of line to the buffer */
4919 add_str_to_yank(tb, "");
4922 /* Segment of this line is selected */
4925 for (i = 0; i < bx2 - bx1; i++)
4927 buf[i] = tb->lines_list[tb->cy][bx1 + i];
4931 /* Copy this segment of line */
4932 add_str_to_yank(tb, buf);
4936 /* Multiple lines case */
4937 else /* if (tb->my != tb->cy) */
4941 int by1 = MIN(tb->my, tb->cy);
4942 int by2 = MAX(tb->my, tb->cy);
4945 for (y = by1; y <= by2; y++)
4947 /* Copy this line */
4948 add_str_to_yank(tb, tb->lines_list[y]);
4951 /* Add final end of line to the buffer */
4952 add_str_to_yank(tb, "");
4955 /* Disable selection */
4959 tb->dirty_flags |= DIRTY_ALL;
4965 /* Paste killed text */
4967 chain_str_type *chain = tb->yank;
4968 int len = strlen(tb->lines_list[tb->cy]);
4970 /* Nothing to do? */
4973 /* Correct cursor location */
4974 if (tb->cx > len) tb->cx = len;
4976 /* Ignore selection */
4982 tb->dirty_flags |= DIRTY_ALL;
4988 cptr yank_str = chain->s;
4990 char buf[MAX_LINELEN];
4992 char rest[MAX_LINELEN], *rest_ptr = rest;
4994 /* Save preceding string */
4995 for(i = 0; i < tb->cx; i++)
4996 buf[i] = tb->lines_list[tb->cy][i];
4998 strcpy(rest, &(tb->lines_list[tb->cy][i]));
5000 /* Paste yank buffer */
5001 while (*yank_str && i < MAX_LINELEN-1)
5003 buf[i++] = *yank_str++;
5009 chain = chain->next;
5011 if (chain || tb->yank_eol)
5013 /* There is an end of line between chain nodes */
5015 insert_return_code(tb);
5017 /* Replace this line with new one */
5018 string_free(tb->lines_list[tb->cy]);
5019 tb->lines_list[tb->cy] = string_make(buf);
5021 /* Move to next line */
5028 /* Final line doesn't have end of line */
5030 tb->cx = strlen(buf);
5032 /* Rest of original line */
5033 while (*rest_ptr && i < MAX_LINELEN-1)
5035 buf[i++] = *rest_ptr++;
5041 /* Replace this line with new one */
5042 string_free(tb->lines_list[tb->cy]);
5043 tb->lines_list[tb->cy] = string_make(buf);
5050 tb->dirty_flags |= DIRTY_ALL;
5052 /* Expressions need re-evaluation */
5053 tb->dirty_flags |= DIRTY_EXPRESSION;
5055 /* Text is changed */
5064 /* Disable the selection */
5068 tb->dirty_flags |= DIRTY_ALL;
5072 tb->mark = MARK_MARK;
5074 /* Repeating this command swaps cursor position */
5075 if (com_id == tb->old_com_id)
5087 tb->dirty_flags |= DIRTY_ALL;
5091 int len = strlen(tb->lines_list[tb->cy]);
5093 /* Mark the point 1 */
5097 /* Correct cursor location */
5098 if (tb->cx > len) tb->mx = len;
5105 /* Kill rest of line */
5107 int len = strlen(tb->lines_list[tb->cy]);
5109 /* Correct cursor location */
5110 if (tb->cx > len) tb->cx = len;
5112 /* Ignore selection */
5118 tb->dirty_flags |= DIRTY_ALL;
5121 /* Append only if this command is repeated. */
5122 if (tb->old_com_id != com_id)
5124 kill_yank_chain(tb);
5128 /* Really deleted some text */
5131 /* Add deleted string to yank buffer */
5132 add_str_to_yank(tb, &(tb->lines_list[tb->cy][tb->cx]));
5134 kill_line_segment(tb, tb->cy, tb->cx, len, FALSE);
5137 tb->dirty_line = tb->cy;
5139 /* Leave end of line character */
5143 /* Cut the end of line character only */
5144 if (tb->yank_eol) add_str_to_yank(tb, "");
5146 /* Cut end of line */
5147 tb->yank_eol = TRUE;
5149 do_editor_command(tb, EC_DELETE_CHAR);
5153 case EC_DELETE_CHAR:
5154 /* DELETE == go forward + BACK SPACE */
5156 /* Ignore selection */
5162 tb->dirty_flags |= DIRTY_ALL;
5166 if (iskanji(tb->lines_list[tb->cy][tb->cx])) tb->cx++;
5170 do_editor_command(tb, EC_BACKSPACE);
5178 char buf[MAX_LINELEN];
5180 /* Ignore selection */
5186 tb->dirty_flags |= DIRTY_ALL;
5189 len = strlen(tb->lines_list[tb->cy]);
5192 if (tb->lines_list[tb->cy + 1])
5206 /* delete a return code and union two lines */
5207 if (tb->cy == 0) break;
5208 tb->cx = strlen(tb->lines_list[tb->cy-1]);
5209 strcpy(buf, tb->lines_list[tb->cy-1]);
5210 strcat(buf, tb->lines_list[tb->cy]);
5211 string_free(tb->lines_list[tb->cy-1]);
5212 string_free(tb->lines_list[tb->cy]);
5213 tb->lines_list[tb->cy-1] = string_make(buf);
5215 for (i = tb->cy; tb->lines_list[i+1]; i++)
5216 tb->lines_list[i] = tb->lines_list[i+1];
5218 tb->lines_list[i] = NULL;
5222 tb->dirty_flags |= DIRTY_ALL;
5224 /* Expressions need re-evaluation */
5225 tb->dirty_flags |= DIRTY_EXPRESSION;
5227 /* Text is changed */
5233 for (i = j = k = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
5237 if (iskanji(tb->lines_list[tb->cy][i]))
5238 buf[j++] = tb->lines_list[tb->cy][i++];
5240 buf[j++] = tb->lines_list[tb->cy][i];
5247 for (; tb->lines_list[tb->cy][i]; i++)
5248 buf[j++] = tb->lines_list[tb->cy][i];
5250 string_free(tb->lines_list[tb->cy]);
5251 tb->lines_list[tb->cy] = string_make(buf);
5254 tb->dirty_line = tb->cy;
5256 /* Expressions may need re-evaluation */
5257 check_expression_line(tb, tb->cy);
5259 /* Text is changed */
5269 /* Become dirty because of item/equip menu */
5270 tb->dirty_flags |= DIRTY_SCREEN;
5272 search_dir = get_string_for_search(&tb->search_o_ptr, &tb->search_str);
5274 if (!search_dir) break;
5276 if (search_dir == 1) do_editor_command(tb, EC_SEARCH_FORW);
5277 else do_editor_command(tb, EC_SEARCH_BACK);
5281 case EC_SEARCH_FORW:
5282 if (tb->search_o_ptr)
5284 search_for_object(tb, tb->search_o_ptr, TRUE);
5286 else if (tb->search_str)
5288 search_for_string(tb, tb->search_str, TRUE);
5292 tb->dirty_flags |= DIRTY_NO_SEARCH;
5296 case EC_SEARCH_BACK:
5297 if (tb->search_o_ptr)
5299 search_for_object(tb, tb->search_o_ptr, FALSE);
5301 else if (tb->search_str)
5303 search_for_string(tb, tb->search_str, FALSE);
5307 tb->dirty_flags |= DIRTY_NO_SEARCH;
5312 /* Become dirty because of item/equip menu */
5313 tb->dirty_flags |= DIRTY_SCREEN;
5315 if (!get_object_for_search(&tb->search_o_ptr, &tb->search_str)) break;
5317 do_editor_command(tb, EC_SEARCH_FORW);
5320 case EC_SEARCH_DESTROYED:
5321 if (!get_destroyed_object_for_search(&tb->search_o_ptr, &tb->search_str))
5323 /* There is no object to search */
5324 tb->dirty_flags |= DIRTY_NO_SEARCH;
5329 do_editor_command(tb, EC_SEARCH_FORW);
5332 case EC_INSERT_OBJECT:
5334 /* Insert choosen item name */
5336 autopick_type an_entry, *entry = &an_entry;
5338 if (!entry_from_choosed_object(entry))
5340 /* Now dirty because of item/equip menu */
5341 tb->dirty_flags |= DIRTY_SCREEN;
5346 insert_return_code(tb);
5347 string_free(tb->lines_list[tb->cy]);
5348 tb->lines_list[tb->cy] = autopick_line_from_entry_kill(entry);
5350 /* Now dirty because of item/equip menu */
5351 tb->dirty_flags |= DIRTY_SCREEN;
5356 case EC_INSERT_DESTROYED:
5357 /* Insert a name of last destroyed item */
5358 if (tb->last_destroyed)
5361 insert_return_code(tb);
5362 string_free(tb->lines_list[tb->cy]);
5363 tb->lines_list[tb->cy] = string_make(tb->last_destroyed);
5366 tb->dirty_flags |= DIRTY_ALL;
5368 /* Text is changed */
5373 case EC_INSERT_BLOCK:
5375 /* Insert a conditinal expression line */
5376 char expression[80];
5378 /* Conditional Expression for Class and Race */
5379 sprintf(expression, "?:[AND [EQU $RACE %s] [EQU $CLASS %s] [GEQ $LEVEL %02d]]",
5381 rp_ptr->E_title, cp_ptr->E_title,
5383 rp_ptr->title, cp_ptr->title,
5389 insert_return_code(tb);
5390 string_free(tb->lines_list[tb->cy]);
5391 tb->lines_list[tb->cy] = string_make(expression);
5393 insert_return_code(tb);
5394 string_free(tb->lines_list[tb->cy]);
5395 tb->lines_list[tb->cy] = string_make("?:1");
5398 tb->dirty_flags |= DIRTY_ALL;
5400 /* Text is changed */
5406 case EC_INSERT_MACRO:
5407 /* Draw_everythig (delete menu) */
5408 draw_text_editor(tb);
5411 Term_erase(0, tb->cy - tb->upper + 1, tb->wid);
5415 Term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW, "P:<¥È¥ê¥¬¡¼¥¡¼>: ");
5417 Term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW, "P:<Trigger key>: ");
5419 if (insert_macro_line(tb))
5421 /* Prepare to input action */
5425 tb->dirty_flags |= DIRTY_ALL;
5427 /* Text is changed */
5433 case EC_INSERT_KEYMAP:
5434 /* Draw_everythig (delete menu) */
5435 draw_text_editor(tb);
5438 Term_erase(0, tb->cy - tb->upper + 1, tb->wid);
5442 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)));
5444 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)));
5447 if (insert_keymap_line(tb))
5449 /* Prepare to input action */
5453 tb->dirty_flags |= DIRTY_ALL;
5455 /* Text is changed */
5460 case EC_CL_AUTOPICK: toggle_command_letter(tb, DO_AUTOPICK); break;
5461 case EC_CL_DESTROY: toggle_command_letter(tb, DO_AUTODESTROY); break;
5462 case EC_CL_LEAVE: toggle_command_letter(tb, DONT_AUTOPICK); break;
5463 case EC_CL_QUERY: toggle_command_letter(tb, DO_QUERY_AUTOPICK); break;
5464 case EC_CL_NO_DISP: toggle_command_letter(tb, DO_DISPLAY); break;
5466 case EC_IK_UNAWARE: toggle_keyword(tb, FLG_UNAWARE); break;
5467 case EC_IK_UNIDENTIFIED: toggle_keyword(tb, FLG_UNIDENTIFIED); break;
5468 case EC_IK_IDENTIFIED: toggle_keyword(tb, FLG_IDENTIFIED); break;
5469 case EC_IK_STAR_IDENTIFIED: toggle_keyword(tb, FLG_STAR_IDENTIFIED); break;
5470 case EC_KK_WEAPONS: toggle_keyword(tb, FLG_WEAPONS); break;
5471 case EC_KK_FAVORITE: toggle_keyword(tb, FLG_FAVORITE); break;
5472 case EC_KK_ARMORS: toggle_keyword(tb, FLG_ARMORS); break;
5473 case EC_KK_MISSILES: toggle_keyword(tb, FLG_MISSILES); break;
5474 case EC_KK_DEVICES: toggle_keyword(tb, FLG_DEVICES); break;
5475 case EC_KK_LIGHTS: toggle_keyword(tb, FLG_LIGHTS); break;
5476 case EC_KK_JUNKS: toggle_keyword(tb, FLG_JUNKS); break;
5477 case EC_KK_SPELLBOOKS: toggle_keyword(tb, FLG_SPELLBOOKS); break;
5478 case EC_KK_SHIELDS: toggle_keyword(tb, FLG_SHIELDS); break;
5479 case EC_KK_BOWS: toggle_keyword(tb, FLG_BOWS); break;
5480 case EC_KK_RINGS: toggle_keyword(tb, FLG_RINGS); break;
5481 case EC_KK_AMULETS: toggle_keyword(tb, FLG_AMULETS); break;
5482 case EC_KK_SUITS: toggle_keyword(tb, FLG_SUITS); break;
5483 case EC_KK_CLOAKS: toggle_keyword(tb, FLG_CLOAKS); break;
5484 case EC_KK_HELMS: toggle_keyword(tb, FLG_HELMS); break;
5485 case EC_KK_GLOVES: toggle_keyword(tb, FLG_GLOVES); break;
5486 case EC_KK_BOOTS: toggle_keyword(tb, FLG_BOOTS); break;
5487 case EC_OK_COLLECTING: toggle_keyword(tb, FLG_COLLECTING); break;
5488 case EC_OK_BOOSTED: toggle_keyword(tb, FLG_BOOSTED); break;
5489 case EC_OK_MORE_THAN: toggle_keyword(tb, FLG_MORE_THAN); break;
5490 case EC_OK_MORE_BONUS: toggle_keyword(tb, FLG_MORE_BONUS); break;
5491 case EC_OK_WORTHLESS: toggle_keyword(tb, FLG_WORTHLESS); break;
5492 case EC_OK_ARTIFACT: toggle_keyword(tb, FLG_ARTIFACT); break;
5493 case EC_OK_EGO: toggle_keyword(tb, FLG_EGO); break;
5494 case EC_OK_NAMELESS: toggle_keyword(tb, FLG_NAMELESS); break;
5495 case EC_OK_WANTED: toggle_keyword(tb, FLG_WANTED); break;
5496 case EC_OK_UNIQUE: toggle_keyword(tb, FLG_UNIQUE); break;
5497 case EC_OK_HUMAN: toggle_keyword(tb, FLG_HUMAN); break;
5498 case EC_OK_UNREADABLE:
5499 toggle_keyword(tb, FLG_UNREADABLE);
5500 add_keyword(tb, FLG_SPELLBOOKS);
5503 toggle_keyword(tb, FLG_REALM1);
5504 add_keyword(tb, FLG_SPELLBOOKS);
5507 toggle_keyword(tb, FLG_REALM2);
5508 add_keyword(tb, FLG_SPELLBOOKS);
5511 toggle_keyword(tb, FLG_FIRST);
5512 add_keyword(tb, FLG_SPELLBOOKS);
5515 toggle_keyword(tb, FLG_SECOND);
5516 add_keyword(tb, FLG_SPELLBOOKS);
5519 toggle_keyword(tb, FLG_THIRD);
5520 add_keyword(tb, FLG_SPELLBOOKS);
5523 toggle_keyword(tb, FLG_FOURTH);
5524 add_keyword(tb, FLG_SPELLBOOKS);
5528 /* Save old command */
5529 tb->old_com_id = com_id;
5536 * Insert single letter at cursor position.
5538 static void insert_single_letter(text_body_type *tb, int key)
5541 char buf[MAX_LINELEN];
5543 /* Save preceding string */
5544 for (i = j = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
5545 buf[j++] = tb->lines_list[tb->cy][i];
5547 /* Add a character */
5555 if (j+2 < MAX_LINELEN)
5567 if (j+1 < MAX_LINELEN)
5573 for (; tb->lines_list[tb->cy][i] && j + 1 < MAX_LINELEN; i++)
5574 buf[j++] = tb->lines_list[tb->cy][i];
5577 /* Replace current line with new line */
5578 string_free(tb->lines_list[tb->cy]);
5579 tb->lines_list[tb->cy] = string_make(buf);
5581 /* Move to correct collumn */
5582 len = strlen(tb->lines_list[tb->cy]);
5583 if (len < tb->cx) tb->cx = len;
5586 tb->dirty_line = tb->cy;
5588 /* Expressions may need re-evaluation */
5589 check_expression_line(tb, tb->cy);
5591 /* Text is changed */
5597 * Check special key code and get a movement command id
5599 static int analyze_move_key(text_body_type *tb, int skey)
5603 /* Not a special key */
5604 if (!(skey & SKEY_MASK)) return 0;
5606 /* Convert from a special key code to an editor command */
5607 switch(skey & ~SKEY_MOD_MASK)
5609 case SKEY_DOWN: com_id = EC_DOWN; break;
5610 case SKEY_LEFT: com_id = EC_LEFT; break;
5611 case SKEY_RIGHT: com_id = EC_RIGHT; break;
5612 case SKEY_UP: com_id = EC_UP; break;
5613 case SKEY_PGUP: com_id = EC_PGUP; break;
5614 case SKEY_PGDOWN: com_id = EC_PGDOWN; break;
5615 case SKEY_TOP: com_id = EC_TOP; break;
5616 case SKEY_BOTTOM: com_id = EC_BOTTOM; break;
5619 /* Not a special movement key */
5623 /* Without shift modifier */
5624 if (!(skey & SKEY_MOD_SHIFT))
5627 * Un-shifted cursor keys cancells
5628 * selection created by shift+cursor.
5630 if (tb->mark & MARK_BY_SHIFT)
5635 tb->dirty_flags |= DIRTY_ALL;
5639 /* With shift modifier */
5642 /* Start selection by shift + cursor keys */
5645 int len = strlen(tb->lines_list[tb->cy]);
5647 tb->mark = MARK_MARK | MARK_BY_SHIFT;
5651 /* Correct cursor location */
5652 if (tb->cx > len) tb->mx = len;
5654 /* Need to redraw text */
5655 if (com_id == EC_UP || com_id == EC_DOWN)
5657 /* Redraw all text */
5658 tb->dirty_flags |= DIRTY_ALL;
5662 tb->dirty_line = tb->cy;
5671 * In-game editor of Object Auto-picker/Destoryer
5673 void do_cmd_edit_autopick(void)
5675 static int cx_save = 0;
5676 static int cy_save = 0;
5678 text_body_type text_body, *tb = &text_body;
5680 autopick_type an_entry, *entry = &an_entry;
5681 char buf[MAX_LINELEN];
5686 static s32b old_autosave_turn = 0L;
5689 tb->changed = FALSE;
5692 tb->upper = tb->left = 0;
5694 tb->mx = tb->my = 0;
5695 tb->old_cy = tb->old_upper = tb->old_left = -1;
5696 tb->old_wid = tb->old_hgt = -1;
5700 tb->search_o_ptr = NULL;
5701 tb->search_str = NULL;
5702 tb->last_destroyed = NULL;
5703 tb->dirty_flags = DIRTY_ALL | DIRTY_MODE | DIRTY_EXPRESSION;
5704 tb->dirty_line = -1;
5705 tb->filename_mode = PT_DEFAULT;
5708 if (turn > old_autosave_turn + 100L)
5710 do_cmd_save_game(TRUE);
5711 old_autosave_turn = turn;
5714 /* HACK -- Reset start_time to stop counting playtime while edit */
5717 /* Free old entries */
5720 /* Command Description of the 'Last Destroyed Item' */
5721 if (autopick_last_destroyed_object.k_idx)
5723 autopick_entry_from_object(entry, &autopick_last_destroyed_object);
5724 tb->last_destroyed = autopick_line_from_entry_kill(entry);
5727 /* Read or initialize whole text */
5728 tb->lines_list = read_pickpref_text_lines(&tb->filename_mode);
5730 /* Reset cursor position if needed */
5731 for (i = 0; i < tb->cy; i++)
5733 if (!tb->lines_list[i])
5735 tb->cy = tb->cx = 0;
5740 /* Save the screen */
5743 /* Process requests until done */
5748 /* Draw_everythig */
5749 draw_text_editor(tb);
5751 /* Display header line */
5753 prt("(^Q:½ªÎ» ^W:¥»¡¼¥Ö¤·¤Æ½ªÎ», ESC:¥á¥Ë¥å¡¼, ¤½¤Î¾:ÆþÎÏ)", 0, 0);
5755 prt("(^Q:Quit, ^W:Save&Quit, ESC:Menu, Other:Input text)", 0, 0);
5759 /* Display current position */
5760 prt (format("(%d,%d)", tb->cx, tb->cy), 0, 60);
5764 /* Display current position and mark position */
5765 prt (format("(%d,%d)-(%d,%d)", tb->mx, tb->my, tb->cx, tb->cy), 0, 60);
5769 Term_gotoxy(tb->cx - tb->left, tb->cy - tb->upper + 1);
5772 tb->dirty_flags = 0;
5773 tb->dirty_line = -1;
5775 /* Save old key and location */
5776 tb->old_cy = tb->cy;
5777 tb->old_upper = tb->upper;
5778 tb->old_left = tb->left;
5779 tb->old_wid = tb->wid;
5780 tb->old_hgt = tb->hgt;
5783 key = inkey_special();
5786 if (key & SKEY_MASK)
5788 /* Get a movement command */
5789 com_id = analyze_move_key(tb, key);
5793 else if (key == ESCAPE)
5795 com_id = do_command_menu(0, 0);
5797 /* Redraw all text later */
5798 tb->dirty_flags |= DIRTY_SCREEN;
5801 /* Insert a character */
5802 else if (!iscntrl((unsigned char)key))
5804 /* Ignore selection */
5810 tb->dirty_flags |= DIRTY_ALL;
5813 insert_single_letter(tb, key);
5819 /* Other commands */
5822 com_id = get_com_id(key);
5825 if (com_id) quit = do_editor_command(tb, com_id);
5826 } /* while (TRUE) */
5828 /* Restore the screen */
5831 /* Get the filename of preference */
5832 strcpy(buf, pickpref_filename(tb->filename_mode));
5834 if (quit == QUIT_AND_SAVE)
5835 write_text_lines(buf, tb->lines_list);
5837 free_text_lines(tb->lines_list);
5839 string_free(tb->last_destroyed);
5841 /* Destroy string chain */
5842 kill_yank_chain(tb);
5844 /* Reload autopick pref */
5845 process_pickpref_file(buf);
5847 /* HACK -- reset start_time so that playtime is not increase while edit */
5848 start_time = time(NULL);
5850 /* Save cursor location */