3 /* Purpose: Object Auto-picker/Destroyer */
6 * Copyright (c) 2002 Mogami
8 * This software may be copied and distributed for educational, research, and
9 * not for profit purposes provided that this copyright and statement are
10 * included in all such copies.
16 #define MAX_LINELEN 1024
22 #define FLG_COLLECTING 1
24 #define FLG_UNIDENTIFIED 3
25 #define FLG_IDENTIFIED 4
26 #define FLG_STAR_IDENTIFIED 5
28 #define FLG_MORE_THAN 7
30 #define FLG_MORE_BONUS 9
31 #define FLG_MORE_BONUS2 10
32 #define FLG_WORTHLESS 11
33 #define FLG_ARTIFACT 12
35 #define FLG_NAMELESS 14
39 #define FLG_UNREADABLE 18
48 #define FLG_WEAPONS 31
50 #define FLG_MISSILES 33
51 #define FLG_DEVICES 34
54 #define FLG_SPELLBOOKS 37
56 #define FLG_SHIELDS 39
59 #define FLG_AMULETS 42
65 #define FLG_FAVORITE 48
67 #define FLG_NOUN_BEGIN FLG_ITEMS
68 #define FLG_NOUN_END FLG_FAVORITE
72 #define KEY_ALL "¤¹¤Ù¤Æ¤Î"
76 * MEGA HACK -- MPW¤Î¥Ð¥°½ü¤±¡£
77 * pre-processÃæ¤Ë¡Ö¼ý¡×¤Î»ú¤Î2¥Ð¥¤¥ÈÌܤ¬¾¡¼ê¤Ë¾Ã¤¨¤Æ¤·¤Þ¤¦¡£
79 #define KEY_COLLECTING "\x8e\xfb½¸Ãæ¤Î"
81 #define KEY_COLLECTING "¼ý½¸Ãæ¤Î"
84 #define KEY_UNIDENTIFIED "̤´ÕÄê¤Î"
85 #define KEY_IDENTIFIED "´ÕÄêºÑ¤ß¤Î"
86 #define KEY_STAR_IDENTIFIED "*´ÕÄê*ºÑ¤ß¤Î"
87 #define KEY_BOOSTED "¥À¥¤¥¹Ìܤΰ㤦"
88 #define KEY_MORE_THAN "¥À¥¤¥¹ÌÜ"
89 #define KEY_DICE "°Ê¾å¤Î"
90 #define KEY_MORE_BONUS "½¤ÀµÃÍ"
91 #define KEY_MORE_BONUS2 "°Ê¾å¤Î"
92 #define KEY_WORTHLESS "̵²ÁÃͤÎ"
93 #define KEY_ARTIFACT "¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È"
94 #define KEY_EGO "¥¨¥´"
95 #define KEY_NAMELESS "̵ÌäÎ"
96 #define KEY_UNAWARE "̤ȽÌÀ¤Î"
97 #define KEY_WANTED "¾Þ¶â¼ó¤Î"
98 #define KEY_UNIQUE "¥æ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼¤Î"
99 #define KEY_HUMAN "¿Í´Ö¤Î"
100 #define KEY_UNREADABLE "Æɤá¤Ê¤¤"
101 #define KEY_REALM1 "Âè°ìÎΰè¤Î"
102 #define KEY_REALM2 "ÂèÆóÎΰè¤Î"
103 #define KEY_FIRST "1ºýÌܤÎ"
104 #define KEY_SECOND "2ºýÌܤÎ"
105 #define KEY_THIRD "3ºýÌܤÎ"
106 #define KEY_FOURTH "4ºýÌܤÎ"
107 #define KEY_ITEMS "¥¢¥¤¥Æ¥à"
108 #define KEY_WEAPONS "Éð´ï"
109 #define KEY_ARMORS "Ëɶñ"
110 #define KEY_MISSILES "Ìð"
111 #define KEY_DEVICES "ËâË¡¥¢¥¤¥Æ¥à"
112 #define KEY_LIGHTS "¸÷¸»"
113 #define KEY_JUNKS "¤¬¤é¤¯¤¿"
114 #define KEY_SPELLBOOKS "ËâË¡½ñ"
115 #define KEY_HAFTED "Æß´ï"
116 #define KEY_SHIELDS "½â"
117 #define KEY_BOWS "µÝ"
118 #define KEY_RINGS "»ØÎØ"
119 #define KEY_AMULETS "¥¢¥ß¥å¥ì¥Ã¥È"
120 #define KEY_SUITS "³»"
121 #define KEY_CLOAKS "¥¯¥í¡¼¥¯"
122 #define KEY_HELMS "³õ"
123 #define KEY_GLOVES "äƼê"
124 #define KEY_BOOTS "·¤"
125 #define KEY_FAVORITE "ÆÀ°ÕÉð´ï"
129 #define KEY_ALL "all"
130 #define KEY_COLLECTING "collecting"
131 #define KEY_UNIDENTIFIED "unidentified"
132 #define KEY_IDENTIFIED "identified"
133 #define KEY_STAR_IDENTIFIED "*identified*"
134 #define KEY_BOOSTED "dice boosted"
135 #define KEY_MORE_THAN "more than"
136 #define KEY_DICE " dice"
137 #define KEY_MORE_BONUS "more bonus than"
138 #define KEY_MORE_BONUS2 ""
139 #define KEY_WORTHLESS "worthless"
140 #define KEY_ARTIFACT "artifact"
141 #define KEY_EGO "ego"
142 #define KEY_NAMELESS "nameless"
143 #define KEY_UNAWARE "unaware"
144 #define KEY_WANTED "wanted"
145 #define KEY_UNIQUE "unique monster's"
146 #define KEY_HUMAN "human"
147 #define KEY_UNREADABLE "unreadable"
148 #define KEY_REALM1 "first realm's"
149 #define KEY_REALM2 "second realm's"
150 #define KEY_FIRST "first"
151 #define KEY_SECOND "second"
152 #define KEY_THIRD "third"
153 #define KEY_FOURTH "fourth"
154 #define KEY_ITEMS "items"
155 #define KEY_WEAPONS "weapons"
156 #define KEY_ARMORS "armors"
157 #define KEY_MISSILES "missiles"
158 #define KEY_DEVICES "magical devices"
159 #define KEY_LIGHTS "lights"
160 #define KEY_JUNKS "junks"
161 #define KEY_SPELLBOOKS "spellbooks"
162 #define KEY_HAFTED "hafted weapons"
163 #define KEY_SHIELDS "shields"
164 #define KEY_BOWS "bows"
165 #define KEY_RINGS "rings"
166 #define KEY_AMULETS "amulets"
167 #define KEY_SUITS "suits"
168 #define KEY_CLOAKS "cloaks"
169 #define KEY_HELMS "helms"
170 #define KEY_GLOVES "gloves"
171 #define KEY_BOOTS "boots"
172 #define KEY_FAVORITE "favorite weapons"
176 #define MATCH_KEY(KEY) (!strncmp(ptr, KEY, sizeof(KEY)-1)\
177 ? (ptr += sizeof(KEY)-1, (' '==*ptr) ? ptr++ : 0, TRUE) : FALSE)
178 #define MATCH_KEY2(KEY) (!strncmp(ptr, KEY, sizeof(KEY)-1)\
179 ? (prev_ptr = ptr, ptr += sizeof(KEY)-1, (' '==*ptr) ? ptr++ : 0, TRUE) : FALSE)
182 #define ADD_KEY(KEY) strcat(ptr, KEY)
184 #define ADD_KEY(KEY) (strcat(ptr, KEY), strcat(ptr, " "))
186 #define ADD_KEY2(KEY) strcat(ptr, KEY)
188 #define ADD_FLG(FLG) (entry->flag[FLG / 32] |= (1L << (FLG % 32)))
189 #define REM_FLG(FLG) (entry->flag[FLG / 32] &= ~(1L << (FLG % 32)))
190 #define ADD_FLG_NOUN(FLG) (ADD_FLG(FLG), prev_flg = FLG)
191 #define IS_FLG(FLG) (entry->flag[FLG / 32] & (1L << (FLG % 32)))
194 static char kanji_colon[] = "¡§";
199 * A function to create new entry
201 static bool autopick_new_entry(autopick_type *entry, cptr str, bool allow_default)
206 char buf[MAX_LINELEN];
207 cptr prev_ptr, ptr, old_ptr;
210 if (str[1] == ':') switch (str[0])
213 case 'A': case 'P': case 'C':
217 entry->flag[0] = entry->flag[1] = 0L;
220 act = DO_AUTOPICK | DO_DISPLAY;
223 if ((act & DO_AUTOPICK) && *str == '!')
226 act |= DO_AUTODESTROY;
229 else if ((act & DO_AUTOPICK) && *str == '~')
232 act |= DONT_AUTOPICK;
235 else if ((act & DO_AUTOPICK) && *str == ';')
238 act |= DO_QUERY_AUTOPICK;
241 else if ((act & DO_DISPLAY) && *str == '(')
250 /* don't mind upper or lower case */
252 for (i = 0; *str; i++)
263 /* Auto-inscription? */
271 if (isupper(c)) c = tolower(c);
277 /* Skip empty line unless allow_default */
278 if (!allow_default && *buf == 0) return FALSE;
280 /* Skip comment line */
281 if (*buf == 0 && insc) return FALSE;
283 ptr = prev_ptr = buf;
286 while (old_ptr != ptr)
288 /* Save current location */
291 if (MATCH_KEY(KEY_ALL)) ADD_FLG(FLG_ALL);
292 if (MATCH_KEY(KEY_COLLECTING)) ADD_FLG(FLG_COLLECTING);
293 if (MATCH_KEY(KEY_UNIDENTIFIED)) ADD_FLG(FLG_UNIDENTIFIED);
294 if (MATCH_KEY(KEY_IDENTIFIED)) ADD_FLG(FLG_IDENTIFIED);
295 if (MATCH_KEY(KEY_STAR_IDENTIFIED)) ADD_FLG(FLG_STAR_IDENTIFIED);
296 if (MATCH_KEY(KEY_BOOSTED)) ADD_FLG(FLG_BOOSTED);
298 /*** Weapons whose dd*ds is more than nn ***/
299 if (MATCH_KEY2(KEY_MORE_THAN))
304 /* Drop leading spaces */
305 while (' ' == *ptr) ptr++;
308 while ('0' <= *ptr && *ptr <= '9')
310 entry->dice = 10 * entry->dice + (*ptr - '0');
317 (void)MATCH_KEY(KEY_DICE);
318 ADD_FLG(FLG_MORE_THAN);
324 /*** Items whose magical bonus is more than n ***/
325 if (MATCH_KEY2(KEY_MORE_BONUS))
330 /* Drop leading spaces */
331 while (' ' == *ptr) ptr++;
334 while ('0' <= *ptr && *ptr <= '9')
336 entry->bonus = 10 * entry->bonus + (*ptr - '0');
343 (void)MATCH_KEY(KEY_MORE_BONUS2);
344 ADD_FLG(FLG_MORE_BONUS);
350 if (MATCH_KEY(KEY_WORTHLESS)) ADD_FLG(FLG_WORTHLESS);
351 if (MATCH_KEY(KEY_EGO)) ADD_FLG(FLG_EGO);
352 if (MATCH_KEY(KEY_NAMELESS)) ADD_FLG(FLG_NAMELESS);
353 if (MATCH_KEY(KEY_UNAWARE)) ADD_FLG(FLG_UNAWARE);
354 if (MATCH_KEY(KEY_WANTED)) ADD_FLG(FLG_WANTED);
355 if (MATCH_KEY(KEY_UNIQUE)) ADD_FLG(FLG_UNIQUE);
356 if (MATCH_KEY(KEY_HUMAN)) ADD_FLG(FLG_HUMAN);
357 if (MATCH_KEY(KEY_UNREADABLE)) ADD_FLG(FLG_UNREADABLE);
358 if (MATCH_KEY(KEY_REALM1)) ADD_FLG(FLG_REALM1);
359 if (MATCH_KEY(KEY_REALM2)) ADD_FLG(FLG_REALM2);
360 if (MATCH_KEY(KEY_FIRST)) ADD_FLG(FLG_FIRST);
361 if (MATCH_KEY(KEY_SECOND)) ADD_FLG(FLG_SECOND);
362 if (MATCH_KEY(KEY_THIRD)) ADD_FLG(FLG_THIRD);
363 if (MATCH_KEY(KEY_FOURTH)) ADD_FLG(FLG_FOURTH);
366 /* Not yet found any noun */
369 if (MATCH_KEY2(KEY_ARTIFACT)) ADD_FLG_NOUN(FLG_ARTIFACT);
371 if (MATCH_KEY2(KEY_ITEMS)) ADD_FLG_NOUN(FLG_ITEMS);
372 else if (MATCH_KEY2(KEY_WEAPONS)) ADD_FLG_NOUN(FLG_WEAPONS);
373 else if (MATCH_KEY2(KEY_ARMORS)) ADD_FLG_NOUN(FLG_ARMORS);
374 else if (MATCH_KEY2(KEY_MISSILES)) ADD_FLG_NOUN(FLG_MISSILES);
375 else if (MATCH_KEY2(KEY_DEVICES)) ADD_FLG_NOUN(FLG_DEVICES);
376 else if (MATCH_KEY2(KEY_LIGHTS)) ADD_FLG_NOUN(FLG_LIGHTS);
377 else if (MATCH_KEY2(KEY_JUNKS)) ADD_FLG_NOUN(FLG_JUNKS);
378 else if (MATCH_KEY2(KEY_SPELLBOOKS)) ADD_FLG_NOUN(FLG_SPELLBOOKS);
379 else if (MATCH_KEY2(KEY_HAFTED)) ADD_FLG_NOUN(FLG_HAFTED);
380 else if (MATCH_KEY2(KEY_SHIELDS)) ADD_FLG_NOUN(FLG_SHIELDS);
381 else if (MATCH_KEY2(KEY_BOWS)) ADD_FLG_NOUN(FLG_BOWS);
382 else if (MATCH_KEY2(KEY_RINGS)) ADD_FLG_NOUN(FLG_RINGS);
383 else if (MATCH_KEY2(KEY_AMULETS)) ADD_FLG_NOUN(FLG_AMULETS);
384 else if (MATCH_KEY2(KEY_SUITS)) ADD_FLG_NOUN(FLG_SUITS);
385 else if (MATCH_KEY2(KEY_CLOAKS)) ADD_FLG_NOUN(FLG_CLOAKS);
386 else if (MATCH_KEY2(KEY_HELMS)) ADD_FLG_NOUN(FLG_HELMS);
387 else if (MATCH_KEY2(KEY_GLOVES)) ADD_FLG_NOUN(FLG_GLOVES);
388 else if (MATCH_KEY2(KEY_BOOTS)) ADD_FLG_NOUN(FLG_BOOTS);
389 else if (MATCH_KEY2(KEY_FAVORITE)) ADD_FLG_NOUN(FLG_FAVORITE);
391 /* Last 'keyword' must be at the correct location */
395 else if (ptr[0] == kanji_colon[0] && ptr[1] == kanji_colon[1])
398 else if (*ptr == '\0')
400 /* There was no noun */
403 /* Add extra word "items" */
404 ADD_FLG_NOUN(FLG_ITEMS);
411 /* A noun type keyword didn't end correctly */
412 entry->flag[prev_flg/32] &= ~(1L<< (prev_flg%32));
417 /* Save this auto-picker entry line */
418 entry->name = string_make(ptr);
420 entry->insc = string_make(insc);
429 static bool is_favorite(object_type *o_ptr)
431 /* Only weapons match */
432 if (!(TV_WEAPON_BEGIN <= o_ptr->tval && o_ptr->tval <= TV_WEAPON_END))
435 /* Favorite weapons are varied depend on the class */
436 switch (p_ptr->pclass)
440 u32b flgs[TR_FLAG_SIZE];
441 object_flags_known(o_ptr, flgs);
443 if (!have_flag(flgs, TR_BLESSED) &&
444 !(o_ptr->tval == TV_HAFTED))
450 case CLASS_FORCETRAINER:
452 if (!(s_info[p_ptr->pclass].w_max[o_ptr->tval-TV_WEAPON_BEGIN][o_ptr->sval]))
456 case CLASS_BEASTMASTER:
459 u32b flgs[TR_FLAG_SIZE];
460 object_flags_known(o_ptr, flgs);
462 /* Is it known to be suitable to using while riding? */
463 if (!(have_flag(flgs, TR_RIDING)))
471 if (s_info[p_ptr->pclass].w_max[o_ptr->tval-TV_WEAPON_BEGIN][o_ptr->sval] <= WEAPON_EXP_BEGINNER)
476 /* All weapons are okay for non-special classes */
485 * Get auto-picker entry from o_ptr.
487 static void autopick_entry_from_object(autopick_type *entry, object_type *o_ptr)
489 /* Assume that object name is to be added */
493 entry->insc = string_make(quark_str(o_ptr->inscription));
494 entry->action = DO_AUTOPICK | DO_DISPLAY;
495 entry->flag[0] = entry->flag[1] = 0L;
499 if (!object_aware_p(o_ptr))
501 ADD_FLG(FLG_UNAWARE);
504 /* Not really identified */
505 else if (!object_known_p(o_ptr))
507 if (!(o_ptr->ident & IDENT_SENSE))
509 ADD_FLG(FLG_UNIDENTIFIED);
513 /* Pseudo-identified */
514 switch (o_ptr->feeling)
518 ADD_FLG(FLG_NAMELESS);
523 ADD_FLG(FLG_NAMELESS);
524 ADD_FLG(FLG_WORTHLESS);
529 ADD_FLG(FLG_WORTHLESS);
537 /* It's not known to be useless so... */
538 ADD_FLG(FLG_UNIDENTIFIED);
551 ego_item_type *e_ptr = &e_info[o_ptr->name2];
552 entry->name = string_make(e_name + e_ptr->name);
554 if (TV_WEAPON_BEGIN <= o_ptr->tval &&
555 o_ptr->tval <= TV_ARMOR_END)
558 * Base name of ego weapons and armors
559 * are almost meaningless. Ignore it.
568 else if (o_ptr->name1 || o_ptr->art_name)
569 ADD_FLG(FLG_ARTIFACT);
571 /* Non-ego, non-artifact */
574 /* Wearable nameless object */
575 if ((TV_EQUIP_BEGIN <= o_ptr->tval && o_ptr->tval <= TV_EQUIP_END))
576 ADD_FLG(FLG_NAMELESS);
585 case TV_HAFTED: case TV_POLEARM: case TV_SWORD: case TV_DIGGING:
586 k_ptr = &k_info[o_ptr->k_idx];
587 if ((o_ptr->dd != k_ptr->dd) || (o_ptr->ds != k_ptr->ds))
588 ADD_FLG(FLG_BOOSTED);
591 if (o_ptr->tval == TV_CORPSE && object_is_shoukinkubi(o_ptr))
593 REM_FLG(FLG_WORTHLESS);
597 if ((o_ptr->tval == TV_CORPSE || o_ptr->tval == TV_STATUE)
598 && (r_info[o_ptr->pval].flags1 & RF1_UNIQUE))
603 if (o_ptr->tval == TV_CORPSE && strchr("pht", r_info[o_ptr->pval].d_char))
608 if (o_ptr->tval >= TV_LIFE_BOOK &&
609 !check_book_realm(o_ptr->tval, o_ptr->sval))
611 ADD_FLG(FLG_UNREADABLE);
612 if (o_ptr->tval != TV_ARCANE_BOOK) name = FALSE;
615 if (REALM1_BOOK == o_ptr->tval &&
616 p_ptr->pclass != CLASS_SORCERER &&
617 p_ptr->pclass != CLASS_RED_MAGE)
623 if (REALM2_BOOK == o_ptr->tval &&
624 p_ptr->pclass != CLASS_SORCERER &&
625 p_ptr->pclass != CLASS_RED_MAGE)
631 if (o_ptr->tval >= TV_LIFE_BOOK && 0 == o_ptr->sval)
633 if (o_ptr->tval >= TV_LIFE_BOOK && 1 == o_ptr->sval)
635 if (o_ptr->tval >= TV_LIFE_BOOK && 2 == o_ptr->sval)
637 if (o_ptr->tval >= TV_LIFE_BOOK && 3 == o_ptr->sval)
640 if (o_ptr->tval == TV_SHOT || o_ptr->tval == TV_BOLT
641 || o_ptr->tval == TV_ARROW)
642 ADD_FLG(FLG_MISSILES);
643 else if (o_ptr->tval == TV_SCROLL || o_ptr->tval == TV_STAFF
644 || o_ptr->tval == TV_WAND || o_ptr->tval == TV_ROD)
645 ADD_FLG(FLG_DEVICES);
646 else if (o_ptr->tval == TV_LITE)
648 else if (o_ptr->tval == TV_SKELETON || o_ptr->tval == TV_BOTTLE
649 || o_ptr->tval == TV_JUNK || o_ptr->tval == TV_STATUE)
651 else if (o_ptr->tval >= TV_LIFE_BOOK)
652 ADD_FLG(FLG_SPELLBOOKS);
653 else if (o_ptr->tval == TV_POLEARM || o_ptr->tval == TV_SWORD
654 || o_ptr->tval == TV_DIGGING || o_ptr->tval == TV_HAFTED)
655 ADD_FLG(FLG_WEAPONS);
656 else if (o_ptr->tval == TV_SHIELD)
657 ADD_FLG(FLG_SHIELDS);
658 else if (o_ptr->tval == TV_BOW)
660 else if (o_ptr->tval == TV_RING)
662 else if (o_ptr->tval == TV_AMULET)
663 ADD_FLG(FLG_AMULETS);
664 else if (o_ptr->tval == TV_DRAG_ARMOR || o_ptr->tval == TV_HARD_ARMOR ||
665 o_ptr->tval == TV_SOFT_ARMOR)
667 else if (o_ptr->tval == TV_CLOAK)
669 else if (o_ptr->tval == TV_HELM)
671 else if (o_ptr->tval == TV_GLOVES)
673 else if (o_ptr->tval == TV_BOOTS)
679 char o_name[MAX_NLEN];
680 object_desc(o_name, o_ptr, FALSE, 0);
682 entry->name = string_make(o_name);
685 else if (!entry->name)
687 entry->name = string_make("");
695 * A function to delete entry
697 static void autopick_free_entry(autopick_type *entry)
699 string_free(entry->name);
700 string_free(entry->insc);
705 * Initialize auto-picker preference
707 #define MAX_AUTOPICK_DEFAULT 200
709 void init_autopicker(void)
711 static const char easy_autopick_inscription[] = "(:=g";
717 max_max_autopick = MAX_AUTOPICK_DEFAULT;
718 C_MAKE(autopick_list, max_max_autopick, autopick_type);
722 /* Clear old entries */
723 for( i = 0; i < max_autopick; i++)
724 autopick_free_entry(&autopick_list[i]);
728 /* There is always one entry "=g" */
729 autopick_new_entry(&entry, easy_autopick_inscription, TRUE);
730 autopick_list[max_autopick++] = entry;
735 * Add one line to autopick_list[]
737 static void add_autopick_list(autopick_type *entry)
739 /* There is no enough space to add one line */
740 if (max_autopick >= max_max_autopick)
742 int old_max_max_autopick = max_max_autopick;
743 autopick_type *old_autopick_list = autopick_list;
745 /* Increase size of list */
746 max_max_autopick += MAX_AUTOPICK_DEFAULT;
749 C_MAKE(autopick_list, max_max_autopick, autopick_type);
751 /* Copy from old list to new list */
752 C_COPY(autopick_list, old_autopick_list, old_max_max_autopick, autopick_type);
755 C_FREE(old_autopick_list, old_max_max_autopick, autopick_type);
759 autopick_list[max_autopick] = *entry;
766 * Process line for auto picker/destroyer.
768 errr process_pickpref_file_line(char *buf)
770 autopick_type an_entry, *entry = &an_entry;
773 /* Nuke illegal char */
774 for(i = 0; buf[i]; i++)
783 if (isspace(buf[i]) && buf[i] != ' ')
788 if (!autopick_new_entry(entry, buf, FALSE)) return 0;
790 /* Already has the same entry? */
791 for(i = 0; i < max_autopick; i++)
792 if(!strcmp(entry->name, autopick_list[i].name)
793 && entry->flag[0] == autopick_list[i].flag[0]
794 && entry->flag[1] == autopick_list[i].flag[1]
795 && entry->dice == autopick_list[i].dice
796 && entry->bonus == autopick_list[i].bonus) return 0;
798 add_autopick_list(entry);
804 * Reconstruct preference line from entry
806 cptr autopick_line_from_entry(autopick_type *entry)
808 char buf[MAX_LINELEN];
810 bool sepa_flag = TRUE;
813 if (!(entry->action & DO_DISPLAY)) strcat(buf, "(");
814 if (entry->action & DO_QUERY_AUTOPICK) strcat(buf, ";");
815 if (entry->action & DO_AUTODESTROY) strcat(buf, "!");
816 if (entry->action & DONT_AUTOPICK) strcat(buf, "~");
820 if (IS_FLG(FLG_ALL)) ADD_KEY(KEY_ALL);
821 if (IS_FLG(FLG_COLLECTING)) ADD_KEY(KEY_COLLECTING);
822 if (IS_FLG(FLG_UNIDENTIFIED)) ADD_KEY(KEY_UNIDENTIFIED);
823 if (IS_FLG(FLG_IDENTIFIED)) ADD_KEY(KEY_IDENTIFIED);
824 if (IS_FLG(FLG_STAR_IDENTIFIED)) ADD_KEY(KEY_STAR_IDENTIFIED);
825 if (IS_FLG(FLG_UNAWARE)) ADD_KEY(KEY_UNAWARE);
826 if (IS_FLG(FLG_BOOSTED)) ADD_KEY(KEY_BOOSTED);
828 if (IS_FLG(FLG_MORE_THAN))
830 ADD_KEY(KEY_MORE_THAN);
831 strcat(ptr, format("%d", entry->dice));
835 if (IS_FLG(FLG_MORE_BONUS))
837 ADD_KEY(KEY_MORE_BONUS);
838 strcat(ptr, format("%d", entry->bonus));
839 ADD_KEY(KEY_MORE_BONUS2);
842 if (IS_FLG(FLG_UNREADABLE)) ADD_KEY(KEY_UNREADABLE);
843 if (IS_FLG(FLG_REALM1)) ADD_KEY(KEY_REALM1);
844 if (IS_FLG(FLG_REALM2)) ADD_KEY(KEY_REALM2);
845 if (IS_FLG(FLG_FIRST)) ADD_KEY(KEY_FIRST);
846 if (IS_FLG(FLG_SECOND)) ADD_KEY(KEY_SECOND);
847 if (IS_FLG(FLG_THIRD)) ADD_KEY(KEY_THIRD);
848 if (IS_FLG(FLG_FOURTH)) ADD_KEY(KEY_FOURTH);
849 if (IS_FLG(FLG_WANTED)) ADD_KEY(KEY_WANTED);
850 if (IS_FLG(FLG_UNIQUE)) ADD_KEY(KEY_UNIQUE);
851 if (IS_FLG(FLG_HUMAN)) ADD_KEY(KEY_HUMAN);
852 if (IS_FLG(FLG_WORTHLESS)) ADD_KEY(KEY_WORTHLESS);
853 if (IS_FLG(FLG_NAMELESS)) ADD_KEY(KEY_NAMELESS);
854 if (IS_FLG(FLG_EGO)) ADD_KEY(KEY_EGO);
856 if (IS_FLG(FLG_ARTIFACT)) ADD_KEY(KEY_ARTIFACT);
858 if (IS_FLG(FLG_ITEMS)) ADD_KEY2(KEY_ITEMS);
859 else if (IS_FLG(FLG_WEAPONS)) ADD_KEY2(KEY_WEAPONS);
860 else if (IS_FLG(FLG_ARMORS)) ADD_KEY2(KEY_ARMORS);
861 else if (IS_FLG(FLG_MISSILES)) ADD_KEY2(KEY_MISSILES);
862 else if (IS_FLG(FLG_DEVICES)) ADD_KEY2(KEY_DEVICES);
863 else if (IS_FLG(FLG_LIGHTS)) ADD_KEY2(KEY_LIGHTS);
864 else if (IS_FLG(FLG_JUNKS)) ADD_KEY2(KEY_JUNKS);
865 else if (IS_FLG(FLG_SPELLBOOKS)) ADD_KEY2(KEY_SPELLBOOKS);
866 else if (IS_FLG(FLG_HAFTED)) ADD_KEY2(KEY_HAFTED);
867 else if (IS_FLG(FLG_SHIELDS)) ADD_KEY2(KEY_SHIELDS);
868 else if (IS_FLG(FLG_BOWS)) ADD_KEY2(KEY_BOWS);
869 else if (IS_FLG(FLG_RINGS)) ADD_KEY2(KEY_RINGS);
870 else if (IS_FLG(FLG_AMULETS)) ADD_KEY2(KEY_AMULETS);
871 else if (IS_FLG(FLG_SUITS)) ADD_KEY2(KEY_SUITS);
872 else if (IS_FLG(FLG_CLOAKS)) ADD_KEY2(KEY_CLOAKS);
873 else if (IS_FLG(FLG_HELMS)) ADD_KEY2(KEY_HELMS);
874 else if (IS_FLG(FLG_GLOVES)) ADD_KEY2(KEY_GLOVES);
875 else if (IS_FLG(FLG_BOOTS)) ADD_KEY2(KEY_BOOTS);
876 else if (IS_FLG(FLG_FAVORITE)) ADD_KEY2(KEY_FAVORITE);
878 /* You don't need sepalator after adjective */
879 /* 'artifact' is not true adjective */
880 else if (!IS_FLG(FLG_ARTIFACT))
883 if (entry->name && entry->name[0])
887 if (sepa_flag) strcat(buf, ":");
890 while (entry->name[j] && i < MAX_LINELEN - 2 - 1)
893 if (iskanji(entry->name[j]))
894 buf[i++] = entry->name[j++];
896 buf[i++] = entry->name[j++];
907 while (entry->insc[j] && i < MAX_LINELEN - 2)
910 if (iskanji(entry->insc[j]))
911 buf[i++] = entry->insc[j++];
913 buf[i++] = entry->insc[j++];
918 return string_make(buf);
923 * Reconstruct preference line from entry and kill entry
925 static cptr autopick_line_from_entry_kill(autopick_type *entry)
927 cptr ptr = autopick_line_from_entry(entry);
929 /* Free memory for original entry */
930 autopick_free_entry(entry);
937 * A function for Auto-picker/destroyer
938 * Examine whether the object matches to the entry
940 static bool is_autopick_aux(object_type *o_ptr, autopick_type *entry, cptr o_name)
943 cptr ptr = entry->name;
945 /*** Unidentified ***/
946 if (IS_FLG(FLG_UNIDENTIFIED)
947 && (object_known_p(o_ptr) || (o_ptr->ident & IDENT_SENSE)))
951 if (IS_FLG(FLG_IDENTIFIED) && !object_known_p(o_ptr))
954 /*** *Identified* ***/
955 if (IS_FLG(FLG_STAR_IDENTIFIED) &&
956 (!object_known_p(o_ptr) || !(o_ptr->ident & IDENT_MENTAL)))
959 /*** Dice boosted (weapon of slaying) ***/
960 if (IS_FLG(FLG_BOOSTED))
962 object_kind *k_ptr = &k_info[o_ptr->k_idx];
964 switch( o_ptr->tval )
970 if ((o_ptr->dd != k_ptr->dd) || (o_ptr->ds != k_ptr->ds))
979 /*** Weapons which dd*ds is more than nn ***/
980 if (IS_FLG(FLG_MORE_THAN))
982 if (o_ptr->dd * o_ptr->ds < entry->dice)
986 /*** Weapons whic dd*ds is more than nn ***/
987 if (IS_FLG(FLG_MORE_BONUS))
989 if (!object_known_p(o_ptr)) return FALSE;
993 if (o_ptr->pval < entry->bonus) return FALSE;
997 if (o_ptr->to_h < entry->bonus &&
998 o_ptr->to_d < entry->bonus &&
999 o_ptr->to_a < entry->bonus &&
1000 o_ptr->pval < entry->bonus)
1005 /*** Worthless items ***/
1006 if (IS_FLG(FLG_WORTHLESS) && object_value(o_ptr) > 0)
1009 /*** Artifact object ***/
1010 if (IS_FLG(FLG_ARTIFACT))
1012 if (!object_known_p(o_ptr) || (!o_ptr->name1 && !o_ptr->art_name))
1016 /*** Ego object ***/
1017 if (IS_FLG(FLG_EGO))
1019 /* Need to be an ego item */
1020 if (!o_ptr->name2) return FALSE;
1022 /* Need to be known to be an ego */
1023 if (!object_known_p(o_ptr) &&
1024 !((o_ptr->ident & IDENT_SENSE) && o_ptr->feeling == FEEL_EXCELLENT))
1029 if (IS_FLG(FLG_NAMELESS))
1031 if (!(TV_EQUIP_BEGIN <= o_ptr->tval && o_ptr->tval <= TV_EQUIP_END))
1034 /* Inscription is a some sort of 'name' */
1035 if (o_ptr->inscription) return FALSE;
1038 if (object_known_p(o_ptr))
1040 /* Artifacts and Ego objects are not okay */
1041 if (o_ptr->name1 || o_ptr->art_name || o_ptr->name2)
1045 /* Pseudo-identified */
1046 else if (o_ptr->ident & IDENT_SENSE)
1048 switch (o_ptr->feeling)
1058 /* It's not nameless */
1066 /* Not known to be nameless */
1071 /*** Unaware items ***/
1072 if (IS_FLG(FLG_UNAWARE) && object_aware_p(o_ptr))
1075 /*** Wanted monster's corpse/skeletons ***/
1076 if (IS_FLG(FLG_WANTED) &&
1077 (o_ptr->tval != TV_CORPSE || !object_is_shoukinkubi(o_ptr)))
1080 /*** Unique monster's corpse/skeletons/statues ***/
1081 if (IS_FLG(FLG_UNIQUE) &&
1082 ((o_ptr->tval != TV_CORPSE && o_ptr->tval != TV_STATUE) ||
1083 !(r_info[o_ptr->pval].flags1 & RF1_UNIQUE)))
1086 /*** Human corpse/skeletons (for Daemon magic) ***/
1087 if (IS_FLG(FLG_HUMAN) &&
1088 (o_ptr->tval != TV_CORPSE ||
1089 !strchr("pht", r_info[o_ptr->pval].d_char)))
1092 /*** Unreadable spellbooks ***/
1093 if (IS_FLG(FLG_UNREADABLE) &&
1094 (o_ptr->tval < TV_LIFE_BOOK ||
1095 check_book_realm(o_ptr->tval, o_ptr->sval)))
1098 /*** First realm spellbooks ***/
1099 if (IS_FLG(FLG_REALM1) &&
1100 (REALM1_BOOK != o_ptr->tval ||
1101 p_ptr->pclass == CLASS_SORCERER ||
1102 p_ptr->pclass == CLASS_RED_MAGE))
1105 /*** Second realm spellbooks ***/
1106 if (IS_FLG(FLG_REALM2) &&
1107 (REALM2_BOOK != o_ptr->tval ||
1108 p_ptr->pclass == CLASS_SORCERER ||
1109 p_ptr->pclass == CLASS_RED_MAGE))
1112 /*** First rank spellbooks ***/
1113 if (IS_FLG(FLG_FIRST) &&
1114 (o_ptr->tval < TV_LIFE_BOOK || 0 != o_ptr->sval))
1117 /*** Second rank spellbooks ***/
1118 if (IS_FLG(FLG_SECOND) &&
1119 (o_ptr->tval < TV_LIFE_BOOK || 1 != o_ptr->sval))
1122 /*** Third rank spellbooks ***/
1123 if (IS_FLG(FLG_THIRD) &&
1124 (o_ptr->tval < TV_LIFE_BOOK || 2 != o_ptr->sval))
1127 /*** Fourth rank spellbooks ***/
1128 if (IS_FLG(FLG_FOURTH) &&
1129 (o_ptr->tval < TV_LIFE_BOOK || 3 != o_ptr->sval))
1133 if (IS_FLG(FLG_WEAPONS))
1135 if (!(TV_WEAPON_BEGIN <= o_ptr->tval && o_ptr->tval <= TV_WEAPON_END))
1138 else if (IS_FLG(FLG_ARMORS))
1140 if (!(TV_ARMOR_BEGIN <= o_ptr->tval && o_ptr->tval <= TV_ARMOR_END))
1143 else if (IS_FLG(FLG_MISSILES))
1147 case TV_SHOT: case TV_BOLT: case TV_ARROW:
1149 default: return FALSE;
1152 else if (IS_FLG(FLG_DEVICES))
1156 case TV_SCROLL: case TV_STAFF: case TV_WAND: case TV_ROD:
1158 default: return FALSE;
1161 else if (IS_FLG(FLG_LIGHTS))
1163 if (!(o_ptr->tval == TV_LITE))
1166 else if (IS_FLG(FLG_JUNKS))
1170 case TV_SKELETON: case TV_BOTTLE:
1171 case TV_JUNK: case TV_STATUE:
1173 default: return FALSE;
1176 else if (IS_FLG(FLG_SPELLBOOKS))
1178 if (!(o_ptr->tval >= TV_LIFE_BOOK))
1181 else if (IS_FLG(FLG_HAFTED))
1183 if (!(o_ptr->tval == TV_HAFTED))
1186 else if (IS_FLG(FLG_SHIELDS))
1188 if (!(o_ptr->tval == TV_SHIELD))
1191 else if (IS_FLG(FLG_BOWS))
1193 if (!(o_ptr->tval == TV_BOW))
1196 else if (IS_FLG(FLG_RINGS))
1198 if (!(o_ptr->tval == TV_RING))
1201 else if (IS_FLG(FLG_AMULETS))
1203 if (!(o_ptr->tval == TV_AMULET))
1206 else if (IS_FLG(FLG_SUITS))
1208 if (!(o_ptr->tval == TV_DRAG_ARMOR ||
1209 o_ptr->tval == TV_HARD_ARMOR ||
1210 o_ptr->tval == TV_SOFT_ARMOR))
1213 else if (IS_FLG(FLG_CLOAKS))
1215 if (!(o_ptr->tval == TV_CLOAK))
1218 else if (IS_FLG(FLG_HELMS))
1220 if (!(o_ptr->tval == TV_CROWN || o_ptr->tval == TV_HELM))
1223 else if (IS_FLG(FLG_GLOVES))
1225 if (!(o_ptr->tval == TV_GLOVES))
1228 else if (IS_FLG(FLG_BOOTS))
1230 if (!(o_ptr->tval == TV_BOOTS))
1233 else if (IS_FLG(FLG_FAVORITE))
1235 if (!is_favorite(o_ptr))
1239 /* Keyword don't match */
1243 if (strncmp(o_name, ptr, strlen(ptr))) return FALSE;
1248 if (!strstr_j(o_name, ptr)) return FALSE;
1250 if (!strstr(o_name, ptr)) return FALSE;
1254 /* TRUE when it need not to be 'collecting' */
1255 if (!IS_FLG(FLG_COLLECTING)) return TRUE;
1257 /* Check if there is a same item */
1258 for (j = 0; j < INVEN_PACK; j++)
1261 * 'Collecting' means the item must be absorbed
1262 * into an inventory slot.
1263 * But an item can not be absorbed into itself!
1265 if ((&inventory[j] != o_ptr) &&
1266 object_similar(&inventory[j], o_ptr))
1270 /* Not collecting */
1276 * Convert string to lower case
1278 static void str_tolower(char *str)
1280 /* Force to be lower case string */
1290 *str = tolower(*str);
1296 * A function for Auto-picker/destroyer
1297 * Examine whether the object matches to the list of keywords or not.
1299 int is_autopick(object_type *o_ptr)
1302 char o_name[MAX_NLEN];
1304 if (o_ptr->tval == TV_GOLD) return -1;
1306 /* Prepare object name string first */
1307 object_desc(o_name, o_ptr, FALSE, 3);
1309 /* Convert the string to lower case */
1310 str_tolower(o_name);
1312 /* Look for a matching entry in the list */
1313 for (i=0; i < max_autopick; i++)
1315 autopick_type *entry = &autopick_list[i];
1317 if (is_autopick_aux(o_ptr, entry, o_name)) return i;
1320 /* No matching entry */
1328 static void auto_inscribe_item(object_type *o_ptr, int idx)
1330 /* Are there auto-inscription? */
1331 if (idx < 0 || !autopick_list[idx].insc) return;
1333 if (!o_ptr->inscription)
1334 o_ptr->inscription = quark_add(autopick_list[idx].insc);
1336 /* Redraw inscription */
1337 p_ptr->window |= (PW_EQUIP | PW_INVEN);
1339 /* {.} and {$} effect p_ptr->warning and TRC_TELEPORT_SELF */
1340 p_ptr->update |= (PU_BONUS);
1345 * Automatically destroy items in this grid.
1347 static bool is_opt_confirm_destroy(object_type *o_ptr)
1349 if (!destroy_items) return FALSE;
1351 /* Known to be worthless? */
1353 if (object_value(o_ptr) > 0) return FALSE;
1356 if ((o_ptr->tval >= TV_MISSILE_BEGIN) && (o_ptr->tval <= TV_ARMOR_END)) return FALSE;
1359 if ((o_ptr->tval == TV_CHEST) && o_ptr->pval) return FALSE;
1363 if (o_ptr->tval == TV_CORPSE
1364 && object_is_shoukinkubi(o_ptr)) return FALSE;
1368 if (o_ptr->tval == TV_CORPSE) return FALSE;
1371 if ((o_ptr->tval == TV_SKELETON) || (o_ptr->tval == TV_BOTTLE) || (o_ptr->tval == TV_JUNK) || (o_ptr->tval == TV_STATUE)) return FALSE;
1375 if (p_ptr->prace == RACE_DEMON)
1377 if (o_ptr->tval == TV_CORPSE &&
1378 o_ptr->sval == SV_CORPSE &&
1379 strchr("pht", r_info[o_ptr->pval].d_char))
1383 if (p_ptr->pclass == CLASS_ARCHER)
1385 if (o_ptr->tval == TV_SKELETON ||
1386 (o_ptr->tval == TV_CORPSE && o_ptr->sval == SV_SKELETON))
1389 else if (p_ptr->pclass == CLASS_NINJA)
1391 if (o_ptr->tval == TV_LITE &&
1392 o_ptr->name2 == EGO_LITE_DARKNESS)
1395 else if (p_ptr->pclass == CLASS_BEASTMASTER ||
1396 p_ptr->pclass == CLASS_CAVALRY)
1398 if (o_ptr->tval == TV_WAND &&
1399 o_ptr->sval == SV_WAND_HEAL_MONSTER)
1404 if (o_ptr->tval == TV_GOLD) return FALSE;
1411 * Automatically destroy an item if it is to be destroyed
1413 * When always_pickup is 'yes', we disable auto-destroyer function of
1414 * auto-picker/destroyer, and do only easy-auto-destroyer.
1416 static object_type autopick_last_destroyed_object;
1418 static void auto_destroy_item(object_type *o_ptr, int autopick_idx)
1420 bool destroy = FALSE;
1422 /* Easy-Auto-Destroyer (3rd priority) */
1423 if (is_opt_confirm_destroy(o_ptr)) destroy = TRUE;
1425 /* Protected by auto-picker (2nd priotity) */
1426 if (autopick_idx >= 0 &&
1427 !(autopick_list[autopick_idx].action & DO_AUTODESTROY))
1430 /* Auto-destroyer works only when !always_pickup */
1433 /* Auto-picker/destroyer (1st priority) */
1434 if (autopick_idx >= 0 &&
1435 (autopick_list[autopick_idx].action & DO_AUTODESTROY))
1439 /* Not to be destroyed */
1440 if (!destroy) return;
1442 /* Now decided to destroy */
1447 if (!can_player_destroy_object(o_ptr))
1449 char o_name[MAX_NLEN];
1451 /* Describe the object (with {terrible/special}) */
1452 object_desc(o_name, o_ptr, TRUE, 3);
1456 msg_format("%s¤ÏÇ˲õÉÔǽ¤À¡£", o_name);
1458 msg_format("You cannot auto-destroy %s.", o_name);
1465 /* Record name of destroyed item */
1466 COPY(&autopick_last_destroyed_object, o_ptr, object_type);
1469 o_ptr->marked |= OM_AUTODESTROY;
1470 p_ptr->notice |= PN_AUTODESTROY;
1477 * Auto-destroy marked item
1479 static void delayed_auto_destroy_aux(int item)
1483 /* Get the item (in the pack) */
1484 if (item >= 0) o_ptr = &inventory[item];
1486 /* Get the item (on the floor) */
1487 else o_ptr = &o_list[0 - item];
1489 if (o_ptr->k_idx && o_ptr->marked & OM_AUTODESTROY)
1491 char o_name[MAX_NLEN];
1493 /* Describe the object (with {terrible/special}) */
1494 object_desc(o_name, o_ptr, TRUE, 3);
1496 /* Eliminate the item (from the pack) */
1499 inven_item_increase(item, -(o_ptr->number));
1500 inven_item_optimize(item);
1503 /* Eliminate the item (from the floor) */
1506 delete_object_idx(0 - item);
1509 /* Print a message */
1511 msg_format("%s¤ò¼«Æ°Ç˲õ¤·¤Þ¤¹¡£", o_name);
1513 msg_format("Auto-destroying %s.", o_name);
1520 * Auto-destroy marked items in inventry and on floor
1522 void delayed_auto_destroy(void)
1527 * Scan inventry in reverse order to prevent
1528 * skipping after inven_item_optimize()
1530 for (item = INVEN_TOTAL - 1; item >= 0 ; item--)
1531 delayed_auto_destroy_aux(item);
1533 /* Scan the pile of objects */
1534 item = cave[py][px].o_idx;
1537 int next = o_list[item].next_o_idx;
1538 delayed_auto_destroy_aux(-item);
1545 * Auto-inscription and/or destroy
1547 * Auto-destroyer works only on inventory or on floor stack only when
1550 void auto_do_item(int item, bool destroy)
1555 /* Get the item (in the pack) */
1556 if (item >= 0) o_ptr = &inventory[item];
1558 /* Get the item (on the floor) */
1559 else o_ptr = &o_list[0 - item];
1561 /* Get the index in the auto-pick/destroy list */
1562 idx = is_autopick(o_ptr);
1564 /* Do auto-inscription */
1565 auto_inscribe_item(o_ptr, idx);
1567 /* Do auto-destroy if needed */
1568 if (destroy && item <= INVEN_PACK)
1569 auto_destroy_item(o_ptr, idx);
1574 * Automatically pickup/destroy items in this grid.
1576 void auto_pickup_items(cave_type *c_ptr)
1578 s16b this_o_idx, next_o_idx = 0;
1580 /* Scan the pile of objects */
1581 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1585 /* Acquire object */
1586 object_type *o_ptr = &o_list[this_o_idx];
1588 /* Acquire next object */
1589 next_o_idx = o_ptr->next_o_idx;
1591 /* Get the index of auto-picker list */
1592 idx = is_autopick(o_ptr);
1594 /* Nothing defined on auto-picker? */
1595 if (idx < 0) continue;
1597 /* Always do auto-inscription first */
1598 auto_inscribe_item(o_ptr, idx);
1600 /* Do auto-destroy */
1601 if (autopick_list[idx].action & DO_AUTODESTROY)
1603 auto_destroy_item(o_ptr, idx);
1607 /* Disturb on auto-pick */
1610 /* Is there an inventory space? */
1611 if (!inven_carry_okay(o_ptr))
1613 char o_name[MAX_NLEN];
1615 /* Describe the object */
1616 object_desc(o_name, o_ptr, TRUE, 3);
1620 msg_format("¥¶¥Ã¥¯¤Ë¤Ï%s¤òÆþ¤ì¤ë·ä´Ö¤¬¤Ê¤¤¡£", o_name);
1622 msg_format("You have no room for %s.", o_name);
1625 * Hack - No duplicate messages.
1626 * remember that a message is given for the item here.
1628 o_ptr->marked |= OM_NOMSG;
1634 if (autopick_list[idx].action & DO_QUERY_AUTOPICK)
1636 char out_val[MAX_NLEN+20];
1637 char o_name[MAX_NLEN];
1639 if (o_ptr->marked & OM_NO_QUERY)
1641 /* Already answered as 'No' */
1645 /* Describe the object */
1646 object_desc(o_name, o_ptr, TRUE, 3);
1649 sprintf(out_val, "%s¤ò½¦¤¤¤Þ¤¹¤«? ", o_name);
1651 sprintf(out_val, "Pick up %s? ", o_name);
1654 if (!get_check(out_val))
1657 * Hack - No duplicate messages/questions.
1658 * remember that a message is given
1659 * for the item here.
1661 o_ptr->marked |= (OM_NOMSG | OM_NO_QUERY);
1668 py_pickup_aux(this_o_idx);
1673 #define PT_DEFAULT 0
1674 #define PT_WITH_PNAME 1
1677 * Get file name for autopick preference
1679 static cptr pickpref_filename(int filename_mode)
1682 static const char namebase[] = "picktype";
1684 static const char namebase[] = "pickpref";
1687 switch (filename_mode)
1690 return format("%s.prf", namebase);
1693 return format("%s-%s.prf", namebase, player_name);
1701 static const char autoregister_header[] = "?:$AUTOREGISTER";
1704 * Clear auto registered lines in the picktype.prf .
1706 static bool clear_auto_register(void)
1708 char tmp_file[1024];
1709 char pref_file[1024];
1714 bool autoregister = FALSE;
1717 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_WITH_PNAME));
1718 pref_fff = my_fopen(pref_file, "r");
1722 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_DEFAULT));
1723 pref_fff = my_fopen(pref_file, "r");
1732 /* Open a new (temporary) file */
1733 tmp_fff = my_fopen_temp(tmp_file, sizeof(tmp_file));
1737 /* Close the preference file */
1741 msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤¤Þ¤»¤ó¤Ç¤·¤¿¡£", tmp_file);
1743 msg_format("Failed to create temporary file %s.", tmp_file);
1750 /* Loop for every line */
1754 if (my_fgets(pref_fff, buf, sizeof(buf))) break;
1758 /* Delete auto-registered line */
1760 /* Count auto-destroy preference lines */
1761 if (buf[0] != '#' && buf[0] != '?') num++;
1764 /* We are looking for auto-registered line */
1767 if (streq(buf, autoregister_header))
1769 /* Delete all further lines */
1770 autoregister = TRUE;
1774 /* Copy orginally lines */
1775 fprintf(tmp_fff, "%s\n", buf);
1781 my_fclose(pref_fff);
1787 msg_format("°ÊÁ°¤Î¥¥ã¥é¥¯¥¿¡¼ÍѤμ«Æ°ÀßÄê(%d¹Ô)¤¬»Ä¤Ã¤Æ¤¤¤Þ¤¹¡£", num);
1788 strcpy(buf, "¸Å¤¤ÀßÄê¹Ô¤Ïºï½ü¤·¤Þ¤¹¡£¤è¤í¤·¤¤¤Ç¤¹¤«¡©");
1790 msg_format("Auto registered lines (%d lines) for previous character are remaining.", num);
1791 strcpy(buf, "These lines will be deleted. Are you sure? ");
1794 /* You can cancel it */
1795 if (!get_check(buf))
1798 autoregister = FALSE;
1801 msg_print("¥¨¥Ç¥£¥¿¤Î¥«¥Ã¥È&¥Ú¡¼¥¹¥ÈÅù¤ò»È¤Ã¤ÆɬÍפʹԤòÈòÆñ¤·¤Æ¤¯¤À¤µ¤¤¡£");
1803 msg_print("Use cut & paste of auto picker editor (_) to keep old prefs.");
1809 /* If there are some changes, overwrite the original file with new one */
1812 /* Copy contents of temporary file */
1814 tmp_fff = my_fopen(tmp_file, "r");
1815 pref_fff = my_fopen(pref_file, "w");
1817 while (!my_fgets(tmp_fff, buf, sizeof(buf)))
1818 fprintf(pref_fff, "%s\n", buf);
1820 my_fclose(pref_fff);
1824 /* Kill the temporary file */
1832 * Automatically register an auto-destroy preference line
1834 bool add_auto_register(object_type *o_ptr)
1837 char pref_file[1024];
1839 autopick_type an_entry, *entry = &an_entry;
1841 int match_autopick = is_autopick(o_ptr);
1843 /* Already registered */
1844 if (match_autopick != -1)
1847 byte act = autopick_list[match_autopick].action;
1850 if (act & DO_AUTOPICK) what = "¼«Æ°¤Ç½¦¤¦";
1851 else if (act & DO_AUTODESTROY) what = "¼«Æ°Ç˲õ¤¹¤ë";
1852 else if (act & DONT_AUTOPICK) what = "ÊüÃÖ¤¹¤ë";
1853 else /* if (act & DO_QUERY_AUTOPICK) */ what = "³Îǧ¤·¤Æ½¦¤¦";
1855 msg_format("¤½¤Î¥¢¥¤¥Æ¥à¤Ï´û¤Ë%s¤è¤¦¤ËÀßÄꤵ¤ì¤Æ¤¤¤Þ¤¹¡£", what);
1857 if (act & DO_AUTOPICK) what = "auto-pickup";
1858 else if (act & DO_AUTODESTROY) what = "auto-destroy";
1859 else if (act & DONT_AUTOPICK) what = "leave on floor";
1860 else /* if (act & DO_QUERY_AUTOPICK) */ what = "query auto-pickup";
1862 msg_format("The object is already registered to %s.", what);
1869 if (!p_ptr->autopick_autoregister)
1871 /* Clear old auto registered lines */
1872 if (!clear_auto_register()) return FALSE;
1875 /* Try a filename with player name */
1876 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_WITH_PNAME));
1877 pref_fff = my_fopen(pref_file, "r");
1881 /* Use default name */
1882 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_DEFAULT));
1883 pref_fff = my_fopen(pref_file, "r");
1886 /* Check the header */
1890 if (my_fgets(pref_fff, buf, sizeof(buf)))
1892 /* No header found */
1893 p_ptr->autopick_autoregister = FALSE;
1898 if (streq(buf, autoregister_header))
1900 /* Found the header */
1901 p_ptr->autopick_autoregister = TRUE;
1907 /* Close read only FILE* */
1910 /* Open for append */
1911 pref_fff = my_fopen(pref_file, "a");
1916 msg_format("%s ¤ò³«¤¯¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¤Ç¤·¤¿¡£", pref_file);
1918 msg_format("Failed to open %s.", pref_file);
1926 if (!p_ptr->autopick_autoregister)
1928 /* Add the header */
1929 fprintf(pref_fff, "%s\n", autoregister_header);
1932 fprintf(pref_fff, "%s\n", "# *·Ù¹ð!!* °Ê¹ß¤Î¹Ô¤Ï¼«Æ°ÅÐÏ¿¤µ¤ì¤¿¤â¤Î¤Ç¤¹¡£");
1933 fprintf(pref_fff, "%s\n", "# ¸å¤Ç¼«Æ°Åª¤Ëºï½ü¤µ¤ì¤Þ¤¹¤Î¤Ç¡¢É¬ÍפʹԤϾå¤ÎÊý¤Ø°ÜÆ°¤·¤Æ¤ª¤¤¤Æ¤¯¤À¤µ¤¤¡£");
1935 fprintf(pref_fff, "%s\n", "# *Waring!* The lines below will be deleated later.");
1936 fprintf(pref_fff, "%s\n", "# Keep it by cut & paste if you need these lines for future characters.");
1939 /* Now auto register is in-use */
1940 p_ptr->autopick_autoregister = TRUE;
1943 /* Get a preference entry */
1944 autopick_entry_from_object(entry, o_ptr);
1946 /* Set to auto-destroy (with no-display) */
1947 entry->action = DO_AUTODESTROY;
1949 /* Load the new line as preference */
1950 add_autopick_list(entry);
1952 /* Add a line to the file */
1953 /* Don't kill "entry" */
1954 fprintf(pref_fff, "%s\n", autopick_line_from_entry(entry));
1956 /* Close the file */
1963 /******** Auto-picker/destroyer editor **********/
1965 #define MAX_YANK MAX_LINELEN
1966 #define MAX_LINES 3000
1968 #define MARK_MARK 0x01
1969 #define MARK_BY_SHIFT 0x02
1971 #define LSTAT_BYPASS 0x01
1972 #define LSTAT_EXPRESSION 0x02
1973 #define LSTAT_AUTOREGISTER 0x04
1975 #define QUIT_WITHOUT_SAVE 1
1976 #define QUIT_AND_SAVE 2
1979 * Struct for yank buffer
1981 typedef struct chain_str {
1982 struct chain_str *next;
1988 * Data struct for text editor
1994 int old_wid, old_hgt;
1996 int old_upper, old_left;
2000 object_type *search_o_ptr;
2002 cptr last_destroyed;
2004 chain_str_type *yank;
2008 byte states[MAX_LINES];
2020 * Dirty flag for text editor
2022 #define DIRTY_ALL 0x0001
2023 #define DIRTY_MODE 0x0004
2024 #define DIRTY_SCREEN 0x0008
2025 #define DIRTY_NOT_FOUND 0x0010
2026 #define DIRTY_NO_SEARCH 0x0020
2027 #define DIRTY_EXPRESSION 0x0040
2028 #define DIRTY_SKIP_INACTIVE 0x0080
2029 #define DIRTY_INACTIVE 0x0100
2032 * Describe which kind of object is Auto-picked/destroyed
2034 static void describe_autopick(char *buff, autopick_type *entry)
2036 cptr str = entry->name;
2037 byte act = entry->action;
2038 cptr insc = entry->insc;
2044 cptr before_str[100], body_str;
2047 body_str = "¥¢¥¤¥Æ¥à";
2049 /*** Collecting items ***/
2050 /*** Which can be absorbed into a slot as a bundle ***/
2051 if (IS_FLG(FLG_COLLECTING))
2052 before_str[before_n++] = "¼ý½¸Ãæ¤Ç´û¤Ë»ý¤Ã¤Æ¤¤¤ë¥¹¥í¥Ã¥È¤Ë¤Þ¤È¤á¤é¤ì¤ë";
2054 /*** Unidentified ***/
2055 if (IS_FLG(FLG_UNIDENTIFIED))
2056 before_str[before_n++] = "̤´ÕÄê¤Î";
2058 /*** Identified ***/
2059 if (IS_FLG(FLG_IDENTIFIED))
2060 before_str[before_n++] = "´ÕÄêºÑ¤ß¤Î";
2062 /*** *Identified* ***/
2063 if (IS_FLG(FLG_STAR_IDENTIFIED))
2064 before_str[before_n++] = "´°Á´¤Ë´ÕÄêºÑ¤ß¤Î";
2066 /*** Dice boosted (weapon of slaying) ***/
2067 if (IS_FLG(FLG_BOOSTED))
2069 before_str[before_n++] = "¥À¥á¡¼¥¸¥À¥¤¥¹¤¬Ä̾ï¤è¤êÂ礤¤";
2073 /*** Weapons whose dd*ds is more than nn ***/
2074 if (IS_FLG(FLG_MORE_THAN))
2076 static char more_than_desc_str[] = "___";
2077 before_str[before_n++] = "¥À¥á¡¼¥¸¥À¥¤¥¹¤ÎºÇÂçÃͤ¬";
2080 sprintf(more_than_desc_str,"%d", entry->dice);
2081 before_str[before_n++] = more_than_desc_str;
2082 before_str[before_n++] = "°Ê¾å¤Î";
2085 /*** Items whose magical bonus is more than nn ***/
2086 if (IS_FLG(FLG_MORE_BONUS))
2088 static char more_bonus_desc_str[] = "___";
2089 before_str[before_n++] = "½¤ÀµÃͤ¬(+";
2091 sprintf(more_bonus_desc_str,"%d", entry->bonus);
2092 before_str[before_n++] = more_bonus_desc_str;
2093 before_str[before_n++] = ")°Ê¾å¤Î";
2096 /*** Worthless items ***/
2097 if (IS_FLG(FLG_WORTHLESS))
2098 before_str[before_n++] = "Ź¤Ç̵²ÁÃͤÈȽÄꤵ¤ì¤ë";
2101 if (IS_FLG(FLG_ARTIFACT))
2103 before_str[before_n++] = "¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È¤Î";
2108 if (IS_FLG(FLG_EGO))
2110 before_str[before_n++] = "¥¨¥´¥¢¥¤¥Æ¥à¤Î";
2115 if (IS_FLG(FLG_NAMELESS))
2117 before_str[before_n++] = "¥¨¥´¤Ç¤â¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È¤Ç¤â¤Ê¤¤";
2121 /*** Unaware items ***/
2122 if (IS_FLG(FLG_UNAWARE))
2123 before_str[before_n++] = "̤´ÕÄê¤Ç¤½¤Î¸ú²Ì¤âȽÌÀ¤·¤Æ¤¤¤Ê¤¤";
2125 /*** Wanted monster's corpse/skeletons ***/
2126 if (IS_FLG(FLG_WANTED))
2128 before_str[before_n++] = "¥Ï¥ó¥¿¡¼»ö̳½ê¤Ç¾Þ¶â¼ó¤È¤µ¤ì¤Æ¤¤¤ë";
2129 body_str = "»àÂΤä¹ü";
2132 /*** Human corpse/skeletons (for Daemon magic) ***/
2133 if (IS_FLG(FLG_HUMAN))
2135 before_str[before_n++] = "°ËâËâË¡¤Ç»È¤¦¤¿¤á¤Î¿Í´Ö¤ä¥Ò¥å¡¼¥Þ¥Î¥¤¥É¤Î";
2136 body_str = "»àÂΤä¹ü";
2139 /*** Unique monster's corpse/skeletons/statues ***/
2140 if (IS_FLG(FLG_UNIQUE))
2142 before_str[before_n++] = "¥æ¥Ë¡¼¥¯¥â¥ó¥¹¥¿¡¼¤Î";
2143 body_str = "»àÂΤä¹ü";
2146 /*** Unreadable spellbooks ***/
2147 if (IS_FLG(FLG_UNREADABLE))
2149 before_str[before_n++] = "¤¢¤Ê¤¿¤¬Æɤá¤Ê¤¤Îΰè¤Î";
2150 body_str = "ËâË¡½ñ";
2153 /*** First realm spellbooks ***/
2154 if (IS_FLG(FLG_REALM1))
2156 before_str[before_n++] = "Âè°ìÎΰè¤Î";
2157 body_str = "ËâË¡½ñ";
2160 /*** Second realm spellbooks ***/
2161 if (IS_FLG(FLG_REALM2))
2163 before_str[before_n++] = "ÂèÆóÎΰè¤Î";
2164 body_str = "ËâË¡½ñ";
2167 /*** First rank spellbooks ***/
2168 if (IS_FLG(FLG_FIRST))
2170 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î1ºýÌܤÎ";
2171 body_str = "ËâË¡½ñ";
2174 /*** Second rank spellbooks ***/
2175 if (IS_FLG(FLG_SECOND))
2177 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î2ºýÌܤÎ";
2178 body_str = "ËâË¡½ñ";
2181 /*** Third rank spellbooks ***/
2182 if (IS_FLG(FLG_THIRD))
2184 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î3ºýÌܤÎ";
2185 body_str = "ËâË¡½ñ";
2188 /*** Fourth rank spellbooks ***/
2189 if (IS_FLG(FLG_FOURTH))
2191 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î4ºýÌܤÎ";
2192 body_str = "ËâË¡½ñ";
2196 if (IS_FLG(FLG_ITEMS))
2197 ; /* Nothing to do */
2198 else if (IS_FLG(FLG_WEAPONS))
2200 else if (IS_FLG(FLG_ARMORS))
2202 else if (IS_FLG(FLG_MISSILES))
2203 body_str = "ÃƤäÌð¤ä¥¯¥í¥¹¥Ü¥¦¤ÎÌð";
2204 else if (IS_FLG(FLG_DEVICES))
2205 body_str = "´¬Êª¤äËâË¡ËÀ¤ä¾ó¤ä¥í¥Ã¥É";
2206 else if (IS_FLG(FLG_LIGHTS))
2207 body_str = "¸÷¸»ÍѤΥ¢¥¤¥Æ¥à";
2208 else if (IS_FLG(FLG_JUNKS))
2209 body_str = "Àޤ줿ËÀÅù¤Î¥¬¥é¥¯¥¿";
2210 else if (IS_FLG(FLG_SPELLBOOKS))
2211 body_str = "ËâË¡½ñ";
2212 else if (IS_FLG(FLG_HAFTED))
2214 else if (IS_FLG(FLG_SHIELDS))
2216 else if (IS_FLG(FLG_BOWS))
2217 body_str = "¥¹¥ê¥ó¥°¤äµÝ¤ä¥¯¥í¥¹¥Ü¥¦";
2218 else if (IS_FLG(FLG_RINGS))
2220 else if (IS_FLG(FLG_AMULETS))
2221 body_str = "¥¢¥ß¥å¥ì¥Ã¥È";
2222 else if (IS_FLG(FLG_SUITS))
2224 else if (IS_FLG(FLG_CLOAKS))
2225 body_str = "¥¯¥í¡¼¥¯";
2226 else if (IS_FLG(FLG_HELMS))
2227 body_str = "¥Ø¥ë¥á¥Ã¥È¤ä´§";
2228 else if (IS_FLG(FLG_GLOVES))
2230 else if (IS_FLG(FLG_BOOTS))
2231 body_str = "¥Ö¡¼¥Ä";
2232 else if (IS_FLG(FLG_FAVORITE))
2233 body_str = "ÆÀ°ÕÉð´ï";
2237 strcat(buff, "Á´¤Æ¤Î");
2238 else for (i = 0; i < before_n && before_str[i]; i++)
2239 strcat(buff, before_str[i]);
2241 strcat(buff, body_str);
2251 strcat(buff, "¤Ç¡¢Ì¾Á°¤¬¡Ö");
2252 strncat(buff, str, 80);
2254 strcat(buff, "¡×¤Ç»Ï¤Þ¤ë¤â¤Î");
2256 strcat(buff, "¡×¤ò´Þ¤à¤â¤Î");
2261 strncat(buff, format("¤Ë¡Ö%s¡×", insc), 80);
2263 if (strstr(insc, "%%all"))
2264 strcat(buff, "(%%all¤ÏÁ´Ç½ÎϤòɽ¤¹±Ñ»ú¤Îµ¹æ¤ÇÃÖ´¹)");
2265 else if (strstr(insc, "%all"))
2266 strcat(buff, "(%all¤ÏÁ´Ç½ÎϤòɽ¤¹µ¹æ¤ÇÃÖ´¹)");
2267 else if (strstr(insc, "%%"))
2268 strcat(buff, "(%%¤ÏÄɲÃǽÎϤòɽ¤¹±Ñ»ú¤Îµ¹æ¤ÇÃÖ´¹)");
2269 else if (strstr(insc, "%"))
2270 strcat(buff, "(%¤ÏÄɲÃǽÎϤòɽ¤¹µ¹æ¤ÇÃÖ´¹)");
2272 strcat(buff, "¤È¹ï¤ó¤Ç");
2277 if (act & DONT_AUTOPICK)
2278 strcat(buff, "ÊüÃÖ¤¹¤ë¡£");
2279 else if (act & DO_AUTODESTROY)
2280 strcat(buff, "Ç˲õ¤¹¤ë¡£");
2281 else if (act & DO_QUERY_AUTOPICK)
2282 strcat(buff, "³Îǧ¤Î¸å¤Ë½¦¤¦¡£");
2284 strcat(buff, "½¦¤¦¡£");
2286 if (act & DO_DISPLAY)
2288 if (act & DONT_AUTOPICK)
2289 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'N'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
2290 else if (act & DO_AUTODESTROY)
2291 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'K'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
2293 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'M'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
2296 strcat(buff, "Á´ÂΥޥåפˤÏɽ¼¨¤·¤Ê¤¤¡£");
2300 cptr before_str[20], after_str[20], which_str[20], whose_str[20], body_str;
2301 int before_n = 0, after_n = 0, which_n = 0, whose_n = 0;
2305 /*** Collecting items ***/
2306 /*** Which can be absorbed into a slot as a bundle ***/
2307 if (IS_FLG(FLG_COLLECTING))
2308 which_str[which_n++] = "can be absorbed into an existing inventory slot";
2310 /*** Unidentified ***/
2311 if (IS_FLG(FLG_UNIDENTIFIED))
2312 before_str[before_n++] = "unidentified";
2314 /*** Identified ***/
2315 if (IS_FLG(FLG_IDENTIFIED))
2316 before_str[before_n++] = "identified";
2318 /*** *Identified* ***/
2319 if (IS_FLG(FLG_STAR_IDENTIFIED))
2320 before_str[before_n++] = "fully identified";
2322 /*** Worthless items ***/
2323 if (IS_FLG(FLG_WORTHLESS))
2325 before_str[before_n++] = "worthless";
2326 which_str[which_n++] = "can not be sold at stores";
2330 if (IS_FLG(FLG_ARTIFACT))
2332 before_str[before_n++] = "artifact";
2336 if (IS_FLG(FLG_EGO))
2338 before_str[before_n++] = "ego";
2342 if (IS_FLG(FLG_NAMELESS))
2344 body_str = "equipment";
2345 which_str[which_n++] = "is neither ego-item nor artifact";
2348 /*** Unaware items ***/
2349 if (IS_FLG(FLG_UNAWARE))
2351 before_str[before_n++] = "unidentified";
2352 whose_str[whose_n++] = "basic abilities are not known";
2355 /*** Dice boosted (weapon of slaying) ***/
2356 if (IS_FLG(FLG_BOOSTED))
2358 body_str = "weapons";
2359 whose_str[whose_n++] = "damage dice is bigger than normal";
2362 /*** Weapons whose dd*ds is more than nn ***/
2363 if (IS_FLG(FLG_MORE_THAN))
2365 static char more_than_desc_str[] =
2366 "maximum damage from dice is bigger than __";
2367 body_str = "weapons";
2369 sprintf(more_than_desc_str + sizeof(more_than_desc_str) - 3,
2371 whose_str[whose_n++] = more_than_desc_str;
2374 /*** Items whose magical bonus is more than nn ***/
2375 if (IS_FLG(FLG_MORE_BONUS))
2377 static char more_bonus_desc_str[] =
2378 "magical bonus is bigger than (+__)";
2380 sprintf(more_bonus_desc_str + sizeof(more_bonus_desc_str) - 4,
2381 "%d)", entry->bonus);
2382 whose_str[whose_n++] = more_bonus_desc_str;
2385 /*** Wanted monster's corpse/skeletons ***/
2386 if (IS_FLG(FLG_WANTED))
2388 body_str = "corpse or skeletons";
2389 which_str[which_n++] = "is wanted at the Hunter's Office";
2392 /*** Human corpse/skeletons (for Daemon magic) ***/
2393 if (IS_FLG(FLG_HUMAN))
2395 before_str[before_n++] = "humanoid";
2396 body_str = "corpse or skeletons";
2397 which_str[which_n++] = "can be used for Daemon magic";
2400 /*** Unique monster's corpse/skeletons/statues ***/
2401 if (IS_FLG(FLG_UNIQUE))
2403 before_str[before_n++] = "unique monster's";
2404 body_str = "corpse or skeletons";
2407 /*** Unreadable spellbooks ***/
2408 if (IS_FLG(FLG_UNREADABLE))
2410 body_str = "spellbooks";
2411 after_str[after_n++] = "of different realms from yours";
2414 /*** First realm spellbooks ***/
2415 if (IS_FLG(FLG_REALM1))
2417 body_str = "spellbooks";
2418 after_str[after_n++] = "of your first realm";
2421 /*** Second realm spellbooks ***/
2422 if (IS_FLG(FLG_REALM2))
2424 body_str = "spellbooks";
2425 after_str[after_n++] = "of your second realm";
2428 /*** First rank spellbooks ***/
2429 if (IS_FLG(FLG_FIRST))
2431 before_str[before_n++] = "first one of four";
2432 body_str = "spellbooks";
2435 /*** Second rank spellbooks ***/
2436 if (IS_FLG(FLG_SECOND))
2438 before_str[before_n++] = "second one of four";
2439 body_str = "spellbooks";
2442 /*** Third rank spellbooks ***/
2443 if (IS_FLG(FLG_THIRD))
2445 before_str[before_n++] = "third one of four";
2446 body_str = "spellbooks";
2449 /*** Fourth rank spellbooks ***/
2450 if (IS_FLG(FLG_FOURTH))
2452 before_str[before_n++] = "fourth one of four";
2453 body_str = "spellbooks";
2457 if (IS_FLG(FLG_ITEMS))
2458 ; /* Nothing to do */
2459 else if (IS_FLG(FLG_WEAPONS))
2460 body_str = "weapons";
2461 else if (IS_FLG(FLG_ARMORS))
2462 body_str = "armors";
2463 else if (IS_FLG(FLG_MISSILES))
2464 body_str = "shots, arrows or crossbow bolts";
2465 else if (IS_FLG(FLG_DEVICES))
2466 body_str = "scrolls, wands, staves or rods";
2467 else if (IS_FLG(FLG_LIGHTS))
2468 body_str = "light sources";
2469 else if (IS_FLG(FLG_JUNKS))
2470 body_str = "junk such as broken sticks";
2471 else if (IS_FLG(FLG_SPELLBOOKS))
2472 body_str = "spellbooks";
2473 else if (IS_FLG(FLG_HAFTED))
2474 body_str = "hafted weapons";
2475 else if (IS_FLG(FLG_SHIELDS))
2476 body_str = "shields";
2477 else if (IS_FLG(FLG_BOWS))
2478 body_str = "slings, bows or crossbows";
2479 else if (IS_FLG(FLG_RINGS))
2481 else if (IS_FLG(FLG_AMULETS))
2482 body_str = "amulets";
2483 else if (IS_FLG(FLG_SUITS))
2484 body_str = "body armors";
2485 else if (IS_FLG(FLG_CLOAKS))
2486 body_str = "cloaks";
2487 else if (IS_FLG(FLG_HELMS))
2488 body_str = "helms or crowns";
2489 else if (IS_FLG(FLG_GLOVES))
2490 body_str = "gloves";
2491 else if (IS_FLG(FLG_BOOTS))
2493 else if (IS_FLG(FLG_FAVORITE))
2494 body_str = "favorite weapons";
2496 /* Prepare a string for item name */
2503 whose_str[whose_n++] = "name is beginning with \"";
2506 which_str[which_n++] = "have \"";
2510 /* Describe action flag */
2511 if (act & DONT_AUTOPICK)
2512 strcpy(buff, "Leave on floor ");
2513 else if (act & DO_AUTODESTROY)
2514 strcpy(buff, "Destroy ");
2515 else if (act & DO_QUERY_AUTOPICK)
2516 strcpy(buff, "Ask to pick up ");
2518 strcpy(buff, "Pickup ");
2520 /* Auto-insctiption */
2523 strncat(buff, format("and inscribe \"%s\"", insc), 80);
2525 if (strstr(insc, "%all"))
2526 strcat(buff, ", replacing %all with code string representing all abilities,");
2527 else if (strstr(insc, "%"))
2528 strcat(buff, ", replacing % with code string representing extra random abilities,");
2530 strcat(buff, " on ");
2535 strcat(buff, "all ");
2536 else for (i = 0; i < before_n && before_str[i]; i++)
2538 strcat(buff, before_str[i]);
2543 strcat(buff, body_str);
2546 for (i = 0; i < after_n && after_str[i]; i++)
2549 strcat(buff, after_str[i]);
2553 for (i = 0; i < whose_n && whose_str[i]; i++)
2556 strcat(buff, " whose ");
2558 strcat(buff, ", and ");
2560 strcat(buff, whose_str[i]);
2563 /* Item name ; whose name is beginning with "str" */
2570 /* whose ..., and which .... */
2571 if (whose_n && which_n)
2572 strcat(buff, ", and ");
2575 for (i = 0; i < which_n && which_str[i]; i++)
2578 strcat(buff, " which ");
2580 strcat(buff, ", and ");
2582 strcat(buff, which_str[i]);
2585 /* Item name ; which have "str" as part of its name */
2588 strncat(buff, str, 80);
2589 strcat(buff, "\" as part of its name");
2593 /* Describe whether it will be displayed on the full map or not */
2594 if (act & DO_DISPLAY)
2596 if (act & DONT_AUTOPICK)
2597 strcat(buff, " Display these items when you press the N key in the full 'M'ap.");
2598 else if (act & DO_AUTODESTROY)
2599 strcat(buff, " Display these items when you press the K key in the full 'M'ap.");
2601 strcat(buff, " Display these items when you press the M key in the full 'M'ap.");
2604 strcat(buff, " Not displayed in the full map.");
2611 * Read whole lines of a file to memory
2613 static cptr *read_text_lines(cptr filename, bool user)
2615 cptr *lines_list = NULL;
2623 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2627 path_build(buf, sizeof(buf), ANGBAND_DIR_PREF, filename);
2631 fff = my_fopen(buf, "r");
2635 /* Allocate list of pointers */
2636 C_MAKE(lines_list, MAX_LINES, cptr);
2639 while (0 == my_fgets(fff, buf, sizeof(buf)))
2641 lines_list[lines++] = string_make(buf);
2642 if (lines >= MAX_LINES - 1) break;
2645 lines_list[0] = string_make("");
2650 if (!fff) return NULL;
2655 static cptr *read_pickpref_text_lines(int *filename_mode_p)
2660 *filename_mode_p = PT_WITH_PNAME;
2661 strcpy(buf, pickpref_filename(*filename_mode_p));
2662 lines_list = read_text_lines(buf, TRUE);
2666 *filename_mode_p = PT_DEFAULT;
2667 strcpy(buf, pickpref_filename(*filename_mode_p));
2668 lines_list = read_text_lines(buf, TRUE);
2673 strcpy(buf, pickpref_filename(*filename_mode_p));
2674 lines_list = read_text_lines(buf, FALSE);
2679 /* Allocate list of pointers */
2680 C_MAKE(lines_list, MAX_LINES, cptr);
2681 lines_list[0] = string_make("");
2688 * Write whole lines of memory to a file.
2690 static bool write_text_lines(cptr filename, cptr *lines_list)
2697 /* Build the filename */
2698 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2701 fff = my_fopen(buf, "w");
2704 for (lines = 0; lines_list[lines]; lines++)
2705 my_fputs(fff, lines_list[lines], 1024);
2710 if (!fff) return FALSE;
2716 * Free memory of lines_list.
2718 static void free_text_lines(cptr *lines_list)
2722 for (lines = 0; lines_list[lines]; lines++)
2723 string_free(lines_list[lines]);
2725 /* free list of pointers */
2726 C_FREE((char **)lines_list, MAX_LINES, char *);
2731 * Delete or insert string
2733 static void toggle_keyword(text_body_type *tb, int flg)
2735 int by1, by2, bx1, bx2, y;
2739 /* Select this line */
2746 if (tb->my < tb->cy)
2761 /* String on these lines are not really selected */
2762 if (tb->lines_list[by1][bx1] == '\0' && by1 < tb->cy) by1++;
2763 if (bx2 == 0 && by1 < by2) by2--;
2766 /* Set/Reset flag of each line */
2767 for (y = by1; y <= by2; y++)
2769 autopick_type an_entry, *entry = &an_entry;
2771 if (!autopick_new_entry(entry, tb->lines_list[y], !fixed)) continue;
2773 string_free(tb->lines_list[y]);
2777 /* Add? or Remove? */
2778 if (!IS_FLG(flg)) add = TRUE;
2781 /* No more change */
2785 /* You can use only one noun flag */
2786 if (FLG_NOUN_BEGIN <= flg && flg <= FLG_NOUN_END)
2789 for (i = FLG_NOUN_BEGIN; i <= FLG_NOUN_END; i++)
2793 /* You can use only one identify state flag */
2794 else if (FLG_UNAWARE <= flg && flg <= FLG_STAR_IDENTIFIED)
2797 for (i = FLG_UNAWARE; i <= FLG_STAR_IDENTIFIED; i++)
2801 /* You can use only one flag in artifact/ego/nameless */
2802 else if (FLG_ARTIFACT <= flg && flg <= FLG_NAMELESS)
2805 for (i = FLG_ARTIFACT; i <= FLG_NAMELESS; i++)
2809 if (add) ADD_FLG(flg);
2812 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
2815 tb->dirty_flags |= DIRTY_ALL;
2817 /* Text is changed */
2824 * Change command letter
2826 static void toggle_command_letter(text_body_type *tb, byte flg)
2828 autopick_type an_entry, *entry = &an_entry;
2829 int by1, by2, bx1, bx2, y;
2833 /* Select this line */
2840 if (tb->my < tb->cy)
2855 /* String on these lines are not really selected */
2856 if (tb->lines_list[by1][bx1] == '\0' && by1 < tb->cy) by1++;
2857 if (bx2 == 0 && by1 < by2) by2--;
2859 /* Set/Reset flag of each line */
2860 for (y = by1; y <= by2; y++)
2864 if (!autopick_new_entry(entry, tb->lines_list[y], FALSE)) continue;
2866 string_free(tb->lines_list[y]);
2870 /* Add? or Remove? */
2871 if (!(entry->action & flg)) add = TRUE;
2874 /* No more change */
2878 /* Count number of letter (by negative number) */
2879 if (entry->action & DONT_AUTOPICK) wid--;
2880 else if (entry->action & DO_AUTODESTROY) wid--;
2881 else if (entry->action & DO_QUERY_AUTOPICK) wid--;
2882 if (!(entry->action & DO_DISPLAY)) wid--;
2884 /* Set/Reset the flag */
2885 if (flg != DO_DISPLAY)
2887 entry->action &= ~(DO_AUTOPICK | DONT_AUTOPICK | DO_AUTODESTROY | DO_QUERY_AUTOPICK);
2888 if (add) entry->action |= flg;
2889 else entry->action |= DO_AUTOPICK;
2893 entry->action &= ~(DO_DISPLAY);
2894 if (add) entry->action |= flg;
2897 /* Correct cursor location */
2900 if (entry->action & DONT_AUTOPICK) wid++;
2901 else if (entry->action & DO_AUTODESTROY) wid++;
2902 else if (entry->action & DO_QUERY_AUTOPICK) wid++;
2903 if (!(entry->action & DO_DISPLAY)) wid++;
2905 if (wid > 0) tb->cx++;
2906 if (wid < 0 && tb->cx > 0) tb->cx--;
2909 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
2912 tb->dirty_flags |= DIRTY_ALL;
2914 /* Text is changed */
2920 * Delete or insert string
2922 static void add_keyword(text_body_type *tb, int flg)
2924 int by1, by2, bx1, bx2, y;
2926 /* Select this line */
2933 if (tb->my < tb->cy)
2948 /* String on these lines are not really selected */
2949 if (tb->lines_list[by1][bx1] == '\0' && by1 < tb->cy) by1++;
2950 if (bx2 == 0 && by1 < by2) by2--;
2952 /* Set/Reset flag of each line */
2953 for (y = by1; y <= by2; y++)
2955 autopick_type an_entry, *entry = &an_entry;
2957 if (!autopick_new_entry(entry, tb->lines_list[y], FALSE)) continue;
2959 /* There is the flag already */
2962 /* Free memory for the entry */
2963 autopick_free_entry(entry);
2968 string_free(tb->lines_list[y]);
2970 /* Remove all noun flag */
2971 if (FLG_NOUN_BEGIN <= flg && flg <= FLG_NOUN_END)
2974 for (i = FLG_NOUN_BEGIN; i <= FLG_NOUN_END; i++)
2980 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
2983 tb->dirty_flags |= DIRTY_ALL;
2985 /* Text is changed */
2992 * Check if this line is expression or not.
2993 * And update it if it is.
2995 static void check_expression_line(text_body_type *tb, int y)
2997 cptr s = tb->lines_list[y];
2999 if ((s[0] == '?' && s[1] == ':') ||
3000 (tb->states[y] & LSTAT_BYPASS))
3002 /* Expressions need re-evaluation */
3003 tb->dirty_flags |= DIRTY_EXPRESSION;
3009 * Insert return code and split the line
3011 static bool insert_return_code(text_body_type *tb)
3013 char buf[MAX_LINELEN];
3016 for (k = 0; tb->lines_list[k]; k++)
3017 /* count number of lines */ ;
3019 if (k >= MAX_LINES - 2) return FALSE;
3022 /* Move down lines */
3023 for (; tb->cy < k; k--)
3025 tb->lines_list[k+1] = tb->lines_list[k];
3026 tb->states[k+1] = tb->states[k];
3029 /* Split current line */
3030 for (i = j = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
3033 if (iskanji(tb->lines_list[tb->cy][i]))
3034 buf[j++] = tb->lines_list[tb->cy][i++];
3036 buf[j++] = tb->lines_list[tb->cy][i];
3039 tb->lines_list[tb->cy+1] = string_make(&tb->lines_list[tb->cy][i]);
3040 string_free(tb->lines_list[tb->cy]);
3041 tb->lines_list[tb->cy] = string_make(buf);
3043 /* Expressions need re-evaluation */
3044 tb->dirty_flags |= DIRTY_EXPRESSION;
3046 /* Text is changed */
3054 * Choose an item and get auto-picker entry from it.
3056 static object_type *choose_object(cptr q, cptr s)
3060 if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR | USE_EQUIP))) return NULL;
3062 /* Get the item (in the pack) */
3063 if (item >= 0) return &inventory[item];
3065 /* Get the item (on the floor) */
3066 else return &o_list[0 - item];
3071 * Choose an item and get auto-picker entry from it.
3073 static bool entry_from_choosed_object(autopick_type *entry)
3080 q = "¤É¤Î¥¢¥¤¥Æ¥à¤òÅÐÏ¿¤·¤Þ¤¹¤«? ";
3081 s = "¥¢¥¤¥Æ¥à¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£";
3083 q = "Enter which item? ";
3084 s = "You have nothing to enter.";
3086 o_ptr = choose_object(q, s);
3087 if (!o_ptr) return FALSE;
3089 autopick_entry_from_object(entry, o_ptr);
3095 * Choose an item for search
3097 static byte get_object_for_search(object_type **o_handle, cptr *search_strp)
3099 char buf[MAX_NLEN+20];
3105 q = "¤É¤Î¥¢¥¤¥Æ¥à¤ò¸¡º÷¤·¤Þ¤¹¤«? ";
3106 s = "¥¢¥¤¥Æ¥à¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£";
3108 q = "Enter which item? ";
3109 s = "You have nothing to enter.";
3111 o_ptr = choose_object(q, s);
3112 if (!o_ptr) return 0;
3116 string_free(*search_strp);
3117 object_desc(buf, *o_handle, FALSE, 3);
3118 *search_strp = string_make(format("<%s>", buf));
3124 * Prepare for search by destroyed object
3126 static byte get_destroyed_object_for_search(object_type **o_handle, cptr *search_strp)
3128 char buf[MAX_NLEN+20];
3130 if (!autopick_last_destroyed_object.k_idx) return 0;
3132 *o_handle = &autopick_last_destroyed_object;
3134 string_free(*search_strp);
3135 object_desc(buf, *o_handle, FALSE, 3);
3136 *search_strp = string_make(format("<%s>", buf));
3142 * Choose an item or string for search
3144 static byte get_string_for_search(object_type **o_handle, cptr *search_strp)
3150 * TERM_YELLOW : Overwrite mode
3151 * TERM_WHITE : Insert mode
3153 byte color = TERM_YELLOW;
3154 char buf[MAX_NLEN+20];
3158 char prompt[] = "¸¡º÷(^I:»ý¤Áʪ ^L:Ç˲õ¤µ¤ì¤¿Êª): ";
3160 char prompt[] = "Search key(^I:inven ^L:destroyed): ";
3162 int col = sizeof(prompt) - 1;
3164 if (*search_strp) strcpy(buf, *search_strp);
3167 /* Display prompt */
3177 /* Display the string */
3178 Term_erase(col, 0, 255);
3179 Term_putstr(col, 0, -1, color, buf);
3182 Term_gotoxy(col + pos, 0);
3184 /* Get a special key code */
3185 skey = inkey_special();
3187 /* Analyze the key */
3195 /* Now on insert mode */
3198 /* No move at beginning of line */
3199 if (0 == pos) break;
3203 int next_pos = i + 1;
3206 if (iskanji(buf[i])) next_pos++;
3209 /* Is there the cursor at next position? */
3210 if (next_pos >= pos) break;
3216 /* Get previous position */
3224 /* Now on insert mode */
3227 /* No move at end of line */
3228 if ('\0' == buf[pos]) break;
3232 if (iskanji(buf[pos])) pos += 2;
3250 if (!pos && *o_handle) return (back ? -1 : 1);
3251 string_free(*search_strp);
3252 *search_strp = string_make(buf);
3254 return (back ? -1 : 1);
3258 return get_object_for_search(o_handle, search_strp);
3261 /* Prepare string for destroyed object if there is one. */
3262 if (get_destroyed_object_for_search(o_handle, search_strp))
3272 /* Now on insert mode */
3275 /* No move at beginning of line */
3276 if (0 == pos) break;
3280 int next_pos = i + 1;
3283 if (iskanji(buf[i])) next_pos++;
3286 /* Is there the cursor at next position? */
3287 if (next_pos >= pos) break;
3293 /* Get previous position */
3296 /* Fall through to 'Delete key' */
3305 /* Now on insert mode */
3308 /* No move at end of line */
3309 if ('\0' == buf[pos]) break;
3311 /* Position of next character */
3315 /* Next character is one more byte away */
3316 if (iskanji(buf[pos])) src++;
3321 /* Move characters at src to dst */
3322 while ('\0' != (buf[dst++] = buf[src++]))
3330 /* Insert a character */
3335 /* Ignore special keys */
3336 if (skey & SKEY_MASK) break;
3338 /* Get a character code */
3341 if (color == TERM_YELLOW)
3343 /* Overwrite default string */
3346 /* Go to insert mode */
3350 /* Save right part of string */
3351 strcpy(tmp, buf + pos);
3357 /* Bypass macro processing */
3375 if (pos < len && (isprint(c) || iskana(c)))
3377 if (pos < len && isprint(c))
3391 /* Write back the left part of string */
3392 my_strcat(buf, tmp, len + 1);
3399 } /* while (TRUE) */
3404 * Search next line matches for o_ptr
3406 static void search_for_object(text_body_type *tb, object_type *o_ptr, bool forward)
3408 autopick_type an_entry, *entry = &an_entry;
3409 char o_name[MAX_NLEN];
3410 int bypassed_cy = -1;
3412 /* Start searching from current cursor position */
3415 /* Prepare object name string first */
3416 object_desc(o_name, o_ptr, FALSE, 3);
3418 /* Convert the string to lower case */
3419 str_tolower(o_name);
3426 if (!tb->lines_list[++i]) break;
3433 /* Is this line is a correct entry? */
3434 if (!autopick_new_entry(entry, tb->lines_list[i], FALSE)) continue;
3436 /* Does this line match to the object? */
3437 if (!is_autopick_aux(o_ptr, entry, o_name)) continue;
3440 /* Found a line but it's inactive */
3441 if (tb->states[i] & LSTAT_BYPASS)
3443 /* If it is first found, remember it */
3444 if (bypassed_cy == -1) bypassed_cy = i;
3447 /* Found an active line! */
3450 /* Move to this line */
3454 if (bypassed_cy != -1)
3456 /* Mark as some lines are skipped */
3457 tb->dirty_flags |= DIRTY_SKIP_INACTIVE;
3465 if (bypassed_cy != -1)
3467 /* Move to the remembered line */
3469 tb->cy = bypassed_cy;
3471 /* Mark as this line is inactive */
3472 tb->dirty_flags |= DIRTY_INACTIVE;
3477 /* Mark as NOT FOUND */
3478 tb->dirty_flags |= DIRTY_NOT_FOUND;
3486 * Search next line matches to the string
3488 static void search_for_string(text_body_type *tb, cptr search_str, bool forward)
3490 int bypassed_cy = -1;
3491 int bypassed_cx = 0;
3493 /* Start searching from current cursor position */
3503 if (!tb->lines_list[++i]) break;
3510 /* Look for the string pattern */
3512 pos = strstr_j(tb->lines_list[i], search_str);
3514 pos = strstr(tb->lines_list[i], search_str);
3520 /* Found a line but it's inactive */
3521 if ((tb->states[i] & LSTAT_BYPASS) &&
3522 !(tb->states[i] & LSTAT_EXPRESSION))
3524 /* If it is first found, remember it */
3525 if (bypassed_cy == -1)
3528 bypassed_cx = (int)(pos - tb->lines_list[i]);
3532 /* Found an active line! */
3535 /* Move to this location */
3536 tb->cx = (int)(pos - tb->lines_list[i]);
3539 if (bypassed_cy != -1)
3541 /* Mark as some lines are skipped */
3542 tb->dirty_flags |= DIRTY_SKIP_INACTIVE;
3550 if (bypassed_cy != -1)
3552 /* Move to the remembered line */
3553 tb->cx = bypassed_cx;
3554 tb->cy = bypassed_cy;
3556 /* Mark as this line is inactive */
3557 tb->dirty_flags |= DIRTY_INACTIVE;
3562 /* Mark as NOT FOUND */
3563 tb->dirty_flags |= DIRTY_NOT_FOUND;
3573 * Editor command id's
3576 #define EC_SAVEQUIT 2
3587 #define EC_PGDOWN 13
3589 #define EC_BOTTOM 15
3594 #define EC_KILL_LINE 20
3595 #define EC_DELETE_CHAR 21
3596 #define EC_BACKSPACE 22
3597 #define EC_SEARCH_STR 23
3598 #define EC_SEARCH_FORW 24
3599 #define EC_SEARCH_BACK 25
3600 #define EC_SEARCH_OBJ 26
3601 #define EC_SEARCH_DESTROYED 27
3602 #define EC_INSERT_OBJECT 28
3603 #define EC_INSERT_DESTROYED 29
3604 #define EC_INSERT_BLOCK 30
3605 #define EC_INSERT_MACRO 31
3606 #define EC_INSERT_KEYMAP 32
3607 #define EC_CL_AUTOPICK 33
3608 #define EC_CL_DESTROY 34
3609 #define EC_CL_LEAVE 35
3610 #define EC_CL_QUERY 36
3611 #define EC_CL_NO_DISP 37
3612 #define EC_OK_COLLECTING 38
3613 #define EC_IK_UNAWARE 39
3614 #define EC_IK_UNIDENTIFIED 40
3615 #define EC_IK_IDENTIFIED 41
3616 #define EC_IK_STAR_IDENTIFIED 42
3617 #define EC_OK_BOOSTED 43
3618 #define EC_OK_MORE_THAN 44
3619 #define EC_OK_MORE_BONUS 45
3620 #define EC_OK_WORTHLESS 46
3621 #define EC_OK_ARTIFACT 47
3622 #define EC_OK_EGO 48
3623 #define EC_OK_NAMELESS 49
3624 #define EC_OK_WANTED 50
3625 #define EC_OK_UNIQUE 51
3626 #define EC_OK_HUMAN 52
3627 #define EC_OK_UNREADABLE 53
3628 #define EC_OK_REALM1 54
3629 #define EC_OK_REALM2 55
3630 #define EC_OK_FIRST 56
3631 #define EC_OK_SECOND 57
3632 #define EC_OK_THIRD 58
3633 #define EC_OK_FOURTH 59
3634 #define EC_KK_WEAPONS 60
3635 #define EC_KK_FAVORITE 61
3636 #define EC_KK_ARMORS 62
3637 #define EC_KK_MISSILES 63
3638 #define EC_KK_DEVICES 64
3639 #define EC_KK_LIGHTS 65
3640 #define EC_KK_JUNKS 66
3641 #define EC_KK_SPELLBOOKS 67
3642 #define EC_KK_SHIELDS 68
3643 #define EC_KK_BOWS 69
3644 #define EC_KK_RINGS 70
3645 #define EC_KK_AMULETS 71
3646 #define EC_KK_SUITS 72
3647 #define EC_KK_CLOAKS 73
3648 #define EC_KK_HELMS 74
3649 #define EC_KK_GLOVES 75
3650 #define EC_KK_BOOTS 76
3656 #define MN_QUIT "¥»¡¼¥Ö̵¤·¤Ç½ªÎ»"
3657 #define MN_SAVEQUIT "¥»¡¼¥Ö¤·¤Æ½ªÎ»"
3658 #define MN_REVERT "Á´¤Æ¤ÎÊѹ¹¤òÇË´þ"
3659 #define MN_HELP "¥Ø¥ë¥×"
3661 #define MN_MOVE "¥«¡¼¥½¥ë°ÜÆ°"
3662 #define MN_LEFT "º¸"
3663 #define MN_DOWN "²¼"
3665 #define MN_RIGHT "±¦"
3666 #define MN_BOL "¹Ô¤ÎÀèƬ"
3667 #define MN_EOL "¹Ô¤Î½ªÃ¼"
3668 #define MN_PGUP "¾å¤Î¥Ú¡¼¥¸"
3669 #define MN_PGDOWN "²¼¤Î¥Ú¡¼¥¸"
3670 #define MN_TOP "1¹ÔÌܤذÜÆ°"
3671 #define MN_BOTTOM "ºÇ²¼¹Ô¤Ø°ÜÆ°"
3673 #define MN_EDIT "ÊÔ½¸"
3674 #define MN_CUT "¥«¥Ã¥È"
3675 #define MN_COPY "¥³¥Ô¡¼"
3676 #define MN_PASTE "¥Ú¡¼¥¹¥È"
3677 #define MN_BLOCK "ÁªÂòÈϰϤλØÄê"
3678 #define MN_KILL_LINE "¹Ô¤Î»Ä¤ê¤òºï½ü"
3679 #define MN_DELETE_CHAR "1ʸ»úºï½ü"
3680 #define MN_BACKSPACE "¥Ð¥Ã¥¯¥¹¥Ú¡¼¥¹"
3681 #define MN_RETURN "²þ¹Ô"
3682 #define MN_RETURN "²þ¹Ô"
3684 #define MN_SEARCH "¸¡º÷"
3685 #define MN_SEARCH_STR "ʸ»úÎó¤Ç¸¡º÷"
3686 #define MN_SEARCH_FORW "Á°Êý¤ØºÆ¸¡º÷"
3687 #define MN_SEARCH_BACK "¸åÊý¤ØºÆ¸¡º÷"
3688 #define MN_SEARCH_OBJ "¥¢¥¤¥Æ¥à¤òÁªÂò¤·¤Æ¸¡º÷"
3689 #define MN_SEARCH_DESTROYED "¼«Æ°Ç˲õ¤µ¤ì¤¿¥¢¥¤¥Æ¥à¤Ç¸¡º÷"
3691 #define MN_INSERT "¿§¡¹ÁÞÆþ"
3692 #define MN_INSERT_OBJECT "ÁªÂò¤·¤¿¥¢¥¤¥Æ¥à¤Î̾Á°¤òÁÞÆþ"
3693 #define MN_INSERT_DESTROYED "¼«Æ°Ç˲õ¤µ¤ì¤¿¥¢¥¤¥Æ¥à¤Î̾Á°¤òÁÞÆþ"
3694 #define MN_INSERT_BLOCK "¾ò·ïʬ´ô¥Ö¥í¥Ã¥¯¤ÎÎã¤òÁÞÆþ"
3695 #define MN_INSERT_MACRO "¥Þ¥¯¥íÄêµÁ¤òÁÞÆþ"
3696 #define MN_INSERT_KEYMAP "¥¡¼¥Þ¥Ã¥×ÄêµÁ¤òÁÞÆþ"
3698 #define MN_COMMAND_LETTER "½¦¤¤/Ç˲õ/ÊüÃÖ¤ÎÁªÂò"
3699 #define MN_CL_AUTOPICK "¡Ö ¡× (¼«Æ°½¦¤¤)"
3700 #define MN_CL_DESTROY "¡Ö!¡× (¼«Æ°Ç˲õ)"
3701 #define MN_CL_LEAVE "¡Ö~¡× (ÊüÃÖ)"
3702 #define MN_CL_QUERY "¡Ö;¡× (³Îǧ¤·¤Æ½¦¤¦)"
3703 #define MN_CL_NO_DISP "¡Ö(¡× (¥Þ¥Ã¥×¥³¥Þ¥ó¥É¤Çɽ¼¨¤·¤Ê¤¤)"
3705 #define MN_ADJECTIVE_GEN "·ÁÍÆ»ì(°ìÈÌ)¤ÎÁªÂò"
3707 #define MN_ADJECTIVE_SPECIAL "·ÁÍÆ»ì(Æüì)¤ÎÁªÂò"
3708 #define MN_BOOSTED "¥À¥¤¥¹Ìܤΰ㤦 (Éð´ï)"
3709 #define MN_MORE_THAN "¥À¥¤¥¹ÌÜ # °Ê¾å¤Î (Éð´ï)"
3710 #define MN_MORE_BONUS "½¤ÀµÃÍ # °Ê¾å¤Î (»ØÎØÅù)"
3711 #define MN_ARTIFACT "¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È (ÁõÈ÷)"
3712 #define MN_EGO "¥¨¥´ (ÁõÈ÷)"
3713 #define MN_NAMELESS "̵ÌäΠ(ÁõÈ÷)"
3714 #define MN_WANTED "¾Þ¶â¼ó¤Î (»àÂÎ)"
3715 #define MN_UNIQUE "¥æ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼¤Î (»àÂÎ)"
3716 #define MN_HUMAN "¿Í´Ö¤Î (»àÂÎ)"
3717 #define MN_UNREADABLE "Æɤá¤Ê¤¤ (ËâË¡½ñ)"
3718 #define MN_REALM1 "Âè°ìÎΰè¤Î (ËâË¡½ñ)"
3719 #define MN_REALM2 "ÂèÆóÎΰè¤Î (ËâË¡½ñ)"
3720 #define MN_FIRST "1ºýÌܤΠ(ËâË¡½ñ)"
3721 #define MN_SECOND "2ºýÌܤΠ(ËâË¡½ñ)"
3722 #define MN_THIRD "3ºýÌܤΠ(ËâË¡½ñ)"
3723 #define MN_FOURTH "4ºýÌܤΠ(ËâË¡½ñ)"
3725 #define MN_NOUN "̾»ì¤ÎÁªÂò"
3729 #define MN_QUIT "Quit without save"
3730 #define MN_SAVEQUIT "Save & Quit"
3731 #define MN_REVERT "Revert all changes"
3732 #define MN_HELP "Help"
3734 #define MN_MOVE "Move cursor"
3735 #define MN_LEFT "Left"
3736 #define MN_DOWN "Down"
3738 #define MN_RIGHT "Right"
3739 #define MN_BOL "Beggining of line"
3740 #define MN_EOL "End of line"
3741 #define MN_PGUP "Page up"
3742 #define MN_PGDOWN "Page down"
3743 #define MN_TOP "Top"
3744 #define MN_BOTTOM "Bottom"
3746 #define MN_EDIT "Edit"
3747 #define MN_CUT "Cut"
3748 #define MN_COPY "Copy"
3749 #define MN_PASTE "Paste"
3750 #define MN_BLOCK "Select block"
3751 #define MN_KILL_LINE "Kill rest of line"
3752 #define MN_DELETE_CHAR "Delete character"
3753 #define MN_BACKSPACE "Backspace"
3754 #define MN_RETURN "Return"
3755 #define MN_RETURN "Return"
3757 #define MN_SEARCH "Search"
3758 #define MN_SEARCH_STR "Search by string"
3759 #define MN_SEARCH_FORW "Search forward"
3760 #define MN_SEARCH_BACK "Search backward"
3761 #define MN_SEARCH_OBJ "Search by inventory object"
3762 #define MN_SEARCH_DESTROYED "Search by destroyed object"
3764 #define MN_INSERT "Insert..."
3765 #define MN_INSERT_OBJECT "Insert name of choosen object"
3766 #define MN_INSERT_DESTROYED "Insert name of destroyed object"
3767 #define MN_INSERT_BLOCK "Insert conditional block"
3768 #define MN_INSERT_MACRO "Insert a macro definition"
3769 #define MN_INSERT_KEYMAP "Insert a keymap definition"
3771 #define MN_COMMAND_LETTER "Command letter"
3772 #define MN_CL_AUTOPICK "' ' (Auto pick)"
3773 #define MN_CL_DESTROY "'!' (Auto destroy)"
3774 #define MN_CL_LEAVE "'~' (Leave it on the floor)"
3775 #define MN_CL_QUERY "';' (Query to pick up)"
3776 #define MN_CL_NO_DISP "'(' (No display on the large map)"
3778 #define MN_ADJECTIVE_GEN "Adjective (general)"
3780 #define MN_ADJECTIVE_SPECIAL "Adjective (special)"
3781 #define MN_BOOSTED "dice boosted (weapons)"
3782 #define MN_MORE_THAN "more than # dice (weapons)"
3783 #define MN_MORE_BONUS "more bonus than # (rings etc.)"
3784 #define MN_ARTIFACT "artifact (equipments)"
3785 #define MN_EGO "ego (equipments)"
3786 #define MN_NAMELESS "nameless (equipments)"
3787 #define MN_WANTED "wanted (corpse)"
3788 #define MN_UNIQUE "unique (corpse)"
3789 #define MN_HUMAN "human (corpse)"
3790 #define MN_UNREADABLE "unreadable (spellbooks)"
3791 #define MN_REALM1 "realm1 (spellbooks)"
3792 #define MN_REALM2 "realm2 (spellbooks)"
3793 #define MN_FIRST "first (spellbooks)"
3794 #define MN_SECOND "second (spellbooks)"
3795 #define MN_THIRD "third (spellbooks)"
3796 #define MN_FOURTH "fourth (spellbooks)"
3798 #define MN_NOUN "Keywords (noun)"
3808 } command_menu_type;
3811 command_menu_type menu_data[] =
3813 {MN_HELP, 0, -1, EC_HELP},
3814 {MN_QUIT, 0, KTRL('q'), EC_QUIT},
3815 {MN_SAVEQUIT, 0, KTRL('w'), EC_SAVEQUIT},
3816 {MN_REVERT, 0, KTRL('z'), EC_REVERT},
3818 {MN_EDIT, 0, -1, -1},
3819 {MN_CUT, 1, KTRL('x'), EC_CUT},
3820 {MN_COPY, 1, KTRL('c'), EC_COPY},
3821 {MN_PASTE, 1, KTRL('v'), EC_PASTE},
3822 {MN_BLOCK, 1, KTRL('g'), EC_BLOCK},
3823 {MN_KILL_LINE, 1, KTRL('k'), EC_KILL_LINE},
3824 {MN_DELETE_CHAR, 1, KTRL('d'), EC_DELETE_CHAR},
3825 {MN_BACKSPACE, 1, KTRL('h'), EC_BACKSPACE},
3826 {MN_RETURN, 1, KTRL('j'), EC_RETURN},
3827 {MN_RETURN, 1, KTRL('m'), EC_RETURN},
3829 {MN_SEARCH, 0, -1, -1},
3830 {MN_SEARCH_STR, 1, KTRL('s'), EC_SEARCH_STR},
3831 {MN_SEARCH_FORW, 1, -1, EC_SEARCH_FORW},
3832 {MN_SEARCH_BACK, 1, KTRL('r'), EC_SEARCH_BACK},
3833 {MN_SEARCH_OBJ, 1, KTRL('y'), EC_SEARCH_OBJ},
3834 {MN_SEARCH_DESTROYED, 1, -1, EC_SEARCH_DESTROYED},
3836 {MN_MOVE, 0, -1, -1},
3837 {MN_LEFT, 1, KTRL('b'), EC_LEFT},
3838 {MN_DOWN, 1, KTRL('n'), EC_DOWN},
3839 {MN_UP, 1, KTRL('p'), EC_UP},
3840 {MN_RIGHT, 1, KTRL('f'), EC_RIGHT},
3841 {MN_BOL, 1, KTRL('a'), EC_BOL},
3842 {MN_EOL, 1, KTRL('e'), EC_EOL},
3843 {MN_PGUP, 1, KTRL('o'), EC_PGUP},
3844 {MN_PGDOWN, 1, KTRL('l'), EC_PGDOWN},
3845 {MN_TOP, 1, KTRL('t'), EC_TOP},
3846 {MN_BOTTOM, 1, KTRL('u'), EC_BOTTOM},
3848 {MN_INSERT, 0, -1, -1},
3849 {MN_INSERT_OBJECT, 1, KTRL('i'), EC_INSERT_OBJECT},
3850 {MN_INSERT_DESTROYED, 1, -1, EC_INSERT_DESTROYED},
3851 {MN_INSERT_BLOCK, 1, -1, EC_INSERT_BLOCK},
3852 {MN_INSERT_MACRO, 1, -1, EC_INSERT_MACRO},
3853 {MN_INSERT_KEYMAP, 1, -1, EC_INSERT_KEYMAP},
3855 {MN_ADJECTIVE_GEN, 0, -1, -1},
3856 {KEY_UNAWARE, 1, -1, EC_IK_UNAWARE},
3857 {KEY_UNIDENTIFIED, 1, -1, EC_IK_UNIDENTIFIED},
3858 {KEY_IDENTIFIED, 1, -1, EC_IK_IDENTIFIED},
3859 {KEY_STAR_IDENTIFIED, 1, -1, EC_IK_STAR_IDENTIFIED},
3860 {KEY_COLLECTING, 1, -1, EC_OK_COLLECTING},
3861 {KEY_WORTHLESS, 1, -1, EC_OK_WORTHLESS},
3863 {MN_ADJECTIVE_SPECIAL, 0, -1, -1},
3864 {MN_BOOSTED, 1, -1, EC_OK_BOOSTED},
3865 {MN_MORE_THAN, 1, -1, EC_OK_MORE_THAN},
3866 {MN_MORE_BONUS, 1, -1, EC_OK_MORE_BONUS},
3867 {MN_ARTIFACT, 1, -1, EC_OK_ARTIFACT},
3868 {MN_EGO, 1, -1, EC_OK_EGO},
3869 {MN_NAMELESS, 1, -1, EC_OK_NAMELESS},
3870 {MN_WANTED, 1, -1, EC_OK_WANTED},
3871 {MN_UNIQUE, 1, -1, EC_OK_UNIQUE},
3872 {MN_HUMAN, 1, -1, EC_OK_HUMAN},
3873 {MN_UNREADABLE, 1, -1, EC_OK_UNREADABLE},
3874 {MN_REALM1, 1, -1, EC_OK_REALM1},
3875 {MN_REALM2, 1, -1, EC_OK_REALM2},
3876 {MN_FIRST, 1, -1, EC_OK_FIRST},
3877 {MN_SECOND, 1, -1, EC_OK_SECOND},
3878 {MN_THIRD, 1, -1, EC_OK_THIRD},
3879 {MN_FOURTH, 1, -1, EC_OK_FOURTH},
3881 {MN_NOUN, 0, -1, -1},
3882 {KEY_WEAPONS, 1, -1, EC_KK_WEAPONS},
3883 {KEY_FAVORITE, 1, -1, EC_KK_FAVORITE},
3884 {KEY_ARMORS, 1, -1, EC_KK_ARMORS},
3885 {KEY_MISSILES, 1, -1, EC_KK_MISSILES},
3886 {KEY_DEVICES, 1, -1, EC_KK_DEVICES},
3887 {KEY_LIGHTS, 1, -1, EC_KK_LIGHTS},
3888 {KEY_JUNKS, 1, -1, EC_KK_JUNKS},
3889 {KEY_SPELLBOOKS, 1, -1, EC_KK_SPELLBOOKS},
3890 {KEY_SHIELDS, 1, -1, EC_KK_SHIELDS},
3891 {KEY_BOWS, 1, -1, EC_KK_BOWS},
3892 {KEY_RINGS, 1, -1, EC_KK_RINGS},
3893 {KEY_AMULETS, 1, -1, EC_KK_AMULETS},
3894 {KEY_SUITS, 1, -1, EC_KK_SUITS},
3895 {KEY_CLOAKS, 1, -1, EC_KK_CLOAKS},
3896 {KEY_HELMS, 1, -1, EC_KK_HELMS},
3897 {KEY_GLOVES, 1, -1, EC_KK_GLOVES},
3898 {KEY_BOOTS, 1, -1, EC_KK_BOOTS},
3900 {MN_COMMAND_LETTER, 0, -1, -1},
3901 {MN_CL_AUTOPICK, 1, -1, EC_CL_AUTOPICK},
3902 {MN_CL_DESTROY, 1, -1, EC_CL_DESTROY},
3903 {MN_CL_LEAVE, 1, -1, EC_CL_LEAVE},
3904 {MN_CL_QUERY, 1, -1, EC_CL_QUERY},
3905 {MN_CL_NO_DISP, 1, -1, EC_CL_NO_DISP},
3907 {MN_DELETE_CHAR, -1, 0x7F, EC_DELETE_CHAR},
3914 * Find a command by 'key'.
3916 static int get_com_id(char key)
3920 for (i = 0; menu_data[i].name; i++)
3922 if (menu_data[i].key == key)
3924 return menu_data[i].com_id;
3933 * Display the menu, and get a command
3935 static int do_command_menu(int level, int start)
3940 int col0 = 5 + level*7;
3941 int row0 = 1 + level*3;
3943 int menu_id_list[26];
3945 char linestr[MAX_LINELEN];
3947 /* Get max length */
3949 for (i = start; menu_data[i].level >= level; i++)
3953 /* Ignore lower level sub menus */
3954 if (menu_data[i].level > level) continue;
3956 len = strlen(menu_data[i].name);
3957 if (len > max_len) max_len = len;
3959 menu_id_list[menu_key] = i;
3963 while (menu_key < 26)
3965 menu_id_list[menu_key] = -1;
3969 /* Extra space for displaying menu key and command key */
3970 max_menu_wid = max_len + 3 + 3;
3972 /* Prepare box line */
3974 strcat(linestr, "+");
3975 for (i = 0; i < max_menu_wid + 2; i++)
3977 strcat(linestr, "-");
3979 strcat(linestr, "+");
3989 int row1 = row0 + 1;
3992 Term_putstr(col0, row0, -1, TERM_WHITE, linestr);
3994 /* Draw menu items */
3996 for (i = start; menu_data[i].level >= level; i++)
3998 char com_key_str[3];
4001 /* Ignore lower level sub menus */
4002 if (menu_data[i].level > level) continue;
4004 if (menu_data[i].com_id == -1)
4007 strcpy(com_key_str, "¢§");
4009 strcpy(com_key_str, ">");
4012 else if (menu_data[i].key != -1)
4014 com_key_str[0] = '^';
4015 com_key_str[1] = menu_data[i].key + '@';
4016 com_key_str[2] = '\0';
4020 com_key_str[0] = '\0';
4023 str = format("| %c) %-*s %2s | ", menu_key + 'a', max_len, menu_data[i].name, com_key_str);
4025 Term_putstr(col0, row1++, -1, TERM_WHITE, str);
4030 /* Draw bottom line */
4031 Term_putstr(col0, row1, -1, TERM_WHITE, linestr);
4033 /* The menu was shown */
4037 prt(format("(a-%c) ¥³¥Þ¥ó¥É:", menu_key + 'a' - 1), 0, 0);
4039 prt(format("(a-%c) Command:", menu_key + 'a' - 1), 0, 0);
4043 if (key == ESCAPE) return 0;
4045 if ('a' <= key && key <= 'z')
4047 menu_id = menu_id_list[key - 'a'];
4051 com_id = menu_data[menu_id].com_id;
4055 com_id = do_command_menu(level + 1, menu_id + 1);
4057 if (com_id) return com_id;
4069 com_id = get_com_id(key);
4070 if (com_id) return com_id;
4077 static chain_str_type *new_chain_str(cptr str)
4079 chain_str_type *chain;
4081 size_t len = strlen(str);
4083 chain = (chain_str_type *)ralloc(sizeof(chain_str_type) + len * sizeof(char));
4085 strcpy(chain->s, str);
4092 static void kill_yank_chain(text_body_type *tb)
4094 chain_str_type *chain = tb->yank;
4096 tb->yank_eol = TRUE;
4100 chain_str_type *next = chain->next;
4101 size_t len = strlen(chain->s);
4103 rnfree(chain, sizeof(chain_str_type) + len * sizeof(char));
4110 static void add_str_to_yank(text_body_type *tb, cptr str)
4112 chain_str_type *chain;
4114 tb->yank_eol = FALSE;
4116 if (NULL == tb->yank)
4118 tb->yank = new_chain_str(str);
4128 chain->next = new_chain_str(str);
4133 chain = chain->next;
4138 #define DESCRIPT_HGT 3
4143 static void draw_text_editor(text_body_type *tb)
4146 int by1 = -1, bx1 = -1, by2 = -1, bx2 = -1;
4149 Term_get_size(&tb->wid, &tb->hgt);
4152 * Top line (-1), description line (-3), separator (-1)
4155 tb->hgt -= 2 + DESCRIPT_HGT;
4158 /* Don't let cursor at second byte of kanji */
4159 for (i = 0; tb->lines_list[tb->cy][i]; i++)
4160 if (iskanji(tb->lines_list[tb->cy][i]))
4171 /* Scroll if necessary */
4172 if (tb->cy < tb->upper || tb->upper + tb->hgt <= tb->cy)
4173 tb->upper = tb->cy - (tb->hgt)/2;
4176 if ((tb->cx < tb->left + 10 && tb->left > 0) || tb->left + tb->wid - 5 <= tb->cx)
4177 tb->left = tb->cx - (tb->wid)*2/3;
4181 /* Redraw whole window after resize */
4182 if (tb->old_wid != tb->wid || tb->old_hgt != tb->hgt)
4183 tb->dirty_flags |= DIRTY_SCREEN;
4185 /* Redraw all text after scroll */
4186 else if (tb->old_upper != tb->upper || tb->old_left != tb->left)
4187 tb->dirty_flags |= DIRTY_ALL;
4190 if (tb->dirty_flags & DIRTY_SCREEN)
4192 tb->dirty_flags |= (DIRTY_ALL | DIRTY_MODE);
4198 /* Redraw mode line */
4199 if (tb->dirty_flags & DIRTY_MODE)
4201 char buf[MAX_LINELEN];
4203 int sepa_length = tb->wid;
4206 for (i = 0; i < sepa_length; i++)
4210 Term_putstr(0, tb->hgt + 1, sepa_length, TERM_WHITE, buf);
4213 if (tb->dirty_flags & DIRTY_EXPRESSION)
4218 for (y = 0; tb->lines_list[y]; y++)
4222 cptr s = tb->lines_list[y];
4224 /* Update this line's state */
4225 tb->states[y] = state;
4227 if (*s++ != '?') continue;
4228 if (*s++ != ':') continue;
4230 /* Lines below this line are auto-registered */
4231 if (streq(s, "$AUTOREGISTER"))
4232 state |= LSTAT_AUTOREGISTER;
4234 /* Parse the expr */
4235 v = process_pref_file_expr(&s, &f);
4238 if (streq(v, "0")) state |= LSTAT_BYPASS;
4239 else state &= ~LSTAT_BYPASS;
4241 /* Re-update this line's state */
4242 tb->states[y] = state | LSTAT_EXPRESSION;
4245 tb->dirty_flags |= DIRTY_ALL;
4250 int tmp_cx = tb->cx;
4251 int len = strlen(tb->lines_list[tb->cy]);
4253 /* Correct cursor location */
4254 if (tb->cx > len) tmp_cx = len;
4256 tb->dirty_flags |= DIRTY_ALL;
4258 if (tb->my < tb->cy ||
4259 (tb->my == tb->cy && tb->mx < tmp_cx))
4275 /* Dump up to tb->hgt lines of messages */
4276 for (i = 0; i < tb->hgt; i++)
4282 int y = tb->upper+i;
4284 /* clean or dirty? */
4285 if (!(tb->dirty_flags & DIRTY_ALL) && (tb->dirty_line != y))
4288 msg = tb->lines_list[y];
4291 /* Apply horizontal scroll */
4292 for (j = 0; *msg; msg++, j++)
4294 if (j == tb->left) break;
4310 Term_erase(0, i + 1, tb->wid);
4312 if (tb->states[y] & LSTAT_AUTOREGISTER)
4314 /* Warning color -- These lines will be deleted later */
4319 /* Bypassed line will be displayed by darker color */
4320 if (tb->states[y] & LSTAT_BYPASS) color = TERM_SLATE;
4321 else color = TERM_WHITE;
4326 /* Dump the messages, bottom to top */
4327 Term_putstr(leftcol, i + 1, tb->wid - 1, color, msg);
4332 int x0 = leftcol + tb->left;
4337 if (by1 <= y && y < by2) sx1 = strlen(msg);
4338 if (y == by1) sx0 = bx1;
4339 if (y == by2) sx1 = bx2;
4341 Term_gotoxy(leftcol, i + 1);
4342 if (x0 < sx0) Term_addstr(sx0 - x0, color, msg);
4343 if (x0 < sx1) Term_addstr(sx1 - sx0, TERM_YELLOW, msg + (sx0 - x0));
4344 Term_addstr(-1, color, msg + (sx1 - x0));
4348 for (; i < tb->hgt; i++)
4351 Term_erase(0, i + 1, tb->wid);
4354 /* Display information when updated */
4355 if (tb->old_cy != tb->cy || (tb->dirty_flags & (DIRTY_ALL | DIRTY_NOT_FOUND | DIRTY_NO_SEARCH)) || tb->dirty_line == tb->cy)
4357 autopick_type an_entry, *entry = &an_entry;
4358 cptr str1 = NULL, str2 = NULL;
4361 /* Clear information line */
4362 for (i = 0; i < DESCRIPT_HGT; i++)
4365 Term_erase(0, tb->hgt + 2 + i, tb->wid);
4368 /* Display information */
4369 if (tb->dirty_flags & DIRTY_NOT_FOUND)
4372 str1 = format("¥Ñ¥¿¡¼¥ó¤¬¸«¤Ä¤«¤ê¤Þ¤»¤ó: %s", tb->search_str);
4374 str1 = format("Pattern not found: %s", tb->search_str);
4377 else if (tb->dirty_flags & DIRTY_SKIP_INACTIVE)
4380 str1 = format("̵¸ú¾õÂ֤ιԤò¥¹¥¥Ã¥×¤·¤Þ¤·¤¿¡£(%s¤ò¸¡º÷Ãæ)", tb->search_str);
4382 str1 = format("Some inactive lines are skipped. (Searching %s)", tb->search_str);
4385 else if (tb->dirty_flags & DIRTY_INACTIVE)
4388 str1 = format("̵¸ú¾õÂ֤ιԤÀ¤±¤¬¸«ÉÕ¤«¤ê¤Þ¤·¤¿¡£(%s¤ò¸¡º÷Ãæ)", tb->search_str);
4390 str1 = format("Found only an inactive line. (Searching %s)", tb->search_str);
4393 else if (tb->dirty_flags & DIRTY_NO_SEARCH)
4396 str1 = "¸¡º÷¤¹¤ë¥Ñ¥¿¡¼¥ó¤¬¤¢¤ê¤Þ¤»¤ó(^S ¤Ç¸¡º÷)¡£";
4398 str1 = "No pattern to search. (Press ^S to search.)";
4401 else if (tb->lines_list[tb->cy][0] == '#')
4404 str1 = "¤³¤Î¹Ô¤Ï¥³¥á¥ó¥È¤Ç¤¹¡£";
4406 str1 = "This line is a comment.";
4409 else if (tb->lines_list[tb->cy][1] == ':')
4411 switch(tb->lines_list[tb->cy][0])
4415 str1 = "¤³¤Î¹Ô¤Ï¾ò·ïʬ´ô¼°¤Ç¤¹¡£";
4417 str1 = "This line is a Conditional Expression.";
4423 str1 = "¤³¤Î¹Ô¤Ï¥Þ¥¯¥í¤Î¼Â¹ÔÆâÍƤòÄêµÁ¤·¤Þ¤¹¡£";
4425 str1 = "This line defines a Macro action.";
4430 str1 = "¤³¤Î¹Ô¤Ï¥Þ¥¯¥í¤Î¥È¥ê¥¬¡¼¡¦¥¡¼¤òÄêµÁ¤·¤Þ¤¹¡£";
4432 str1 = "This line defines a Macro trigger key.";
4437 str1 = "¤³¤Î¹Ô¤Ï¥¡¼ÇÛÃÖ¤òÄêµÁ¤·¤Þ¤¹¡£";
4439 str1 = "This line defines a Keymap.";
4444 switch(tb->lines_list[tb->cy][0])
4447 if (tb->states[tb->cy] & LSTAT_BYPASS)
4450 str2 = "¸½ºß¤Î¼°¤ÎÃͤϡֵ¶(=0)¡×¤Ç¤¹¡£";
4452 str2 = "The expression is 'False'(=0) currently.";
4458 str2 = "¸½ºß¤Î¼°¤ÎÃͤϡֿ¿(=1)¡×¤Ç¤¹¡£";
4460 str2 = "The expression is 'True'(=1) currently.";
4466 if (tb->states[tb->cy] & LSTAT_AUTOREGISTER)
4469 str2 = "¤³¤Î¹Ô¤Ï¸å¤Çºï½ü¤µ¤ì¤Þ¤¹¡£";
4471 str2 = "This line will be delete later.";
4475 else if (tb->states[tb->cy] & LSTAT_BYPASS)
4478 str2 = "¤³¤Î¹Ô¤Ï¸½ºß¤Ï̵¸ú¤Ê¾õÂ֤Ǥ¹¡£";
4480 str2 = "This line is bypassed currently.";
4487 /* Get description of an autopicker preference line */
4488 else if (autopick_new_entry(entry, tb->lines_list[tb->cy], FALSE))
4490 char buf[MAX_LINELEN];
4491 char temp[MAX_LINELEN];
4494 describe_autopick(buf, entry);
4496 if (tb->states[tb->cy] & LSTAT_AUTOREGISTER)
4499 strcat(buf, "¤³¤Î¹Ô¤Ï¸å¤Çºï½ü¤µ¤ì¤Þ¤¹¡£");
4501 strcat(buf, " This line will be delete later.");
4505 if (tb->states[tb->cy] & LSTAT_BYPASS)
4508 strcat(buf, "¤³¤Î¹Ô¤Ï¸½ºß¤Ï̵¸ú¤Ê¾õÂ֤Ǥ¹¡£");
4510 strcat(buf, " This line is bypassed currently.");
4514 roff_to_buf(buf, 81, temp, sizeof(temp));
4516 for (i = 0; i < 3; i++)
4522 prt(t, tb->hgt +1 + 1 + i, 0);
4526 autopick_free_entry(entry);
4529 /* Draw the first line */
4530 if (str1) prt(str1, tb->hgt +1 + 1, 0);
4532 /* Draw the second line */
4533 if (str2) prt(str2, tb->hgt +1 + 2, 0);
4539 * Kill segment of a line
4541 static void kill_line_segment(text_body_type *tb, int y, int x0, int x1, bool whole)
4543 char buf[MAX_LINELEN];
4544 cptr s = tb->lines_list[y];
4549 if (x0 == x1) return;
4551 /* Kill whole line? */
4552 if (whole && x0 == 0 && s[x1] == '\0' && tb->lines_list[y+1])
4556 string_free(tb->lines_list[y]);
4558 /* Shift lines up */
4559 for (i = y; tb->lines_list[i+1]; i++)
4560 tb->lines_list[i] = tb->lines_list[i+1];
4561 tb->lines_list[i] = NULL;
4563 /* Expressions need re-evaluation */
4564 tb->dirty_flags |= DIRTY_EXPRESSION;
4569 /* Before the segment */
4570 for (x = 0; x < x0; x++)
4573 /* After the segment */
4574 for (x = x1; s[x]; x++)
4580 string_free(tb->lines_list[y]);
4581 tb->lines_list[y] = string_make(buf);
4583 /* Expressions may need re-evaluation */
4584 check_expression_line(tb, y);
4586 /* Text is changed */
4592 * Get a trigger key and insert ASCII string for the trigger
4594 static bool insert_macro_line(text_body_type *tb)
4603 /* Do not process macros */
4609 /* Read the pattern */
4615 /* Do not process macros */
4618 /* Do not wait for keys */
4621 /* Attempt to read a key */
4631 /* Convert the trigger */
4632 ascii_to_text(tmp, buf);
4635 if(!tmp[0]) return FALSE;
4639 /* Insert preference string */
4640 insert_return_code(tb);
4641 string_free(tb->lines_list[tb->cy]);
4642 tb->lines_list[tb->cy] = string_make(format("P:%s", tmp));
4644 /* Acquire action */
4645 i = macro_find_exact(buf);
4649 /* Nothing defined */
4654 /* Analyze the current action */
4655 ascii_to_text(tmp, macro__act[i]);
4658 /* Insert blank action preference line */
4659 insert_return_code(tb);
4660 string_free(tb->lines_list[tb->cy]);
4661 tb->lines_list[tb->cy] = string_make(format("A:%s", tmp));
4668 * Get a command key and insert ASCII string for the key
4670 static bool insert_keymap_line(text_body_type *tb)
4678 if (rogue_like_commands)
4680 mode = KEYMAP_MODE_ROGUE;
4686 mode = KEYMAP_MODE_ORIG;
4699 /* Convert the trigger */
4700 ascii_to_text(tmp, buf);
4703 if(!tmp[0]) return FALSE;
4707 /* Insert preference string */
4708 insert_return_code(tb);
4709 string_free(tb->lines_list[tb->cy]);
4710 tb->lines_list[tb->cy] = string_make(format("C:%d:%s", mode, tmp));
4712 /* Look up the keymap */
4713 act = keymap_act[mode][(byte)(buf[0])];
4715 /* Insert blank action preference line */
4716 insert_return_code(tb);
4717 string_free(tb->lines_list[tb->cy]);
4718 tb->lines_list[tb->cy] = string_make(format("A:%s", act));
4725 * Execute a single editor command
4727 static bool do_editor_command(text_body_type *tb, int com_id)
4735 if (!get_check("Á´¤Æ¤ÎÊѹ¹¤òÇË´þ¤·¤Æ¤«¤é½ªÎ»¤·¤Þ¤¹¡£¤è¤í¤·¤¤¤Ç¤¹¤«¡© ")) break;
4737 if (!get_check("Discard all changes and quit. Are you sure? ")) break;
4740 return QUIT_WITHOUT_SAVE;
4743 return QUIT_AND_SAVE;
4746 /* Revert to original */
4748 if (!get_check("Á´¤Æ¤ÎÊѹ¹¤òÇË´þ¤·¤Æ¸µ¤Î¾õÂÖ¤ËÌᤷ¤Þ¤¹¡£¤è¤í¤·¤¤¤Ç¤¹¤«¡© ")) break;
4750 if (!get_check("Discard all changes and revert to original file. Are you sure? ")) break;
4753 free_text_lines(tb->lines_list);
4754 tb->lines_list = read_pickpref_text_lines(&tb->filename_mode);
4755 tb->dirty_flags |= DIRTY_ALL | DIRTY_MODE | DIRTY_EXPRESSION;
4756 tb->cx = tb->cy = 0;
4759 /* Text is not changed */
4760 tb->changed = FALSE;
4764 /* Peruse the main help file */
4766 (void)show_file(TRUE, "jeditor.txt", NULL, 0, 0);
4768 (void)show_file(TRUE, "editor.txt", NULL, 0, 0);
4771 tb->dirty_flags |= DIRTY_SCREEN;
4776 /* Split a line or insert end of line */
4778 /* Ignore selection */
4784 tb->dirty_flags |= DIRTY_ALL;
4787 insert_return_code(tb);
4792 tb->dirty_flags |= DIRTY_ALL;
4802 len = strlen(tb->lines_list[tb->cy]);
4803 if (len < tb->cx) tb->cx = len;
4805 else if (tb->cy > 0)
4808 tb->cx = strlen(tb->lines_list[tb->cy]);
4814 if (tb->lines_list[tb->cy + 1]) tb->cy++;
4819 if (tb->cy > 0) tb->cy--;
4828 if (iskanji(tb->lines_list[tb->cy][tb->cx])) tb->cx++;
4831 len = strlen(tb->lines_list[tb->cy]);
4834 if (tb->lines_list[tb->cy + 1])
4846 /* Beginning of line */
4852 tb->cx = strlen(tb->lines_list[tb->cy]);
4856 while (0 < tb->cy && tb->upper <= tb->cy)
4858 while (0 < tb->upper && tb->cy + 1 < tb->upper + tb->hgt)
4864 while (tb->cy < tb->upper + tb->hgt && tb->lines_list[tb->cy + 1])
4874 while (tb->lines_list[tb->cy + 1])
4880 int by1, bx1, by2, bx2;
4883 /* Copy the text first */
4884 do_editor_command(tb, EC_COPY);
4886 if (tb->my < tb->cy ||
4887 (tb->my == tb->cy && tb->mx < tb->cx))
4902 /* Kill lines in reverse order */
4903 for (y = by2; y >= by1; y--)
4906 int x1 = strlen(tb->lines_list[y]);
4908 if (y == by1) x0 = bx1;
4909 if (y == by2) x1 = bx2;
4911 kill_line_segment(tb, y, x0, x1, TRUE);
4914 /* Correct cursor position */
4918 /* Disable selection */
4922 tb->dirty_flags |= DIRTY_ALL;
4929 int by1, bx1, by2, bx2;
4931 int len = strlen(tb->lines_list[tb->cy]);
4933 /* Correct cursor location */
4934 if (tb->cx > len) tb->cx = len;
4936 /* Use single line? */
4941 if (tb->lines_list[tb->cy + 1])
4943 /* Select a single line */
4949 /* Select bottom line */
4954 if (tb->my < tb->cy ||
4955 (tb->my == tb->cy && tb->mx < tb->cx))
4970 /* Kill old yank buffer */
4971 kill_yank_chain(tb);
4973 /* Copy string to yank buffer */
4974 for (y = by1; y <= by2; y++)
4977 char buf[MAX_LINELEN];
4980 int x1 = strlen(tb->lines_list[y]);
4982 if (y == by1) x0 = bx1;
4983 if (y == by2) x1 = bx2;
4985 for (i = 0; i < x1 - x0; i++)
4987 buf[i] = tb->lines_list[y][x0 + i];
4991 add_str_to_yank(tb, buf);
4994 /* Disable selection */
4998 tb->dirty_flags |= DIRTY_ALL;
5004 /* Paste killed text */
5006 chain_str_type *chain = tb->yank;
5007 int len = strlen(tb->lines_list[tb->cy]);
5009 /* Nothing to do? */
5012 /* Correct cursor location */
5013 if (tb->cx > len) tb->cx = len;
5015 /* Ignore selection */
5021 tb->dirty_flags |= DIRTY_ALL;
5027 cptr yank_str = chain->s;
5029 char buf[MAX_LINELEN];
5031 char rest[MAX_LINELEN], *rest_ptr = rest;
5033 /* Save preceding string */
5034 for(i = 0; i < tb->cx; i++)
5035 buf[i] = tb->lines_list[tb->cy][i];
5037 strcpy(rest, &(tb->lines_list[tb->cy][i]));
5039 /* Paste yank buffer */
5040 while (*yank_str && i < MAX_LINELEN-1)
5042 buf[i++] = *yank_str++;
5048 chain = chain->next;
5050 if (chain || tb->yank_eol)
5052 /* There is an end of line between chain nodes */
5054 insert_return_code(tb);
5056 /* Replace this line with new one */
5057 string_free(tb->lines_list[tb->cy]);
5058 tb->lines_list[tb->cy] = string_make(buf);
5060 /* Move to next line */
5067 /* Final line doesn't have end of line */
5069 tb->cx = strlen(buf);
5071 /* Rest of original line */
5072 while (*rest_ptr && i < MAX_LINELEN-1)
5074 buf[i++] = *rest_ptr++;
5080 /* Replace this line with new one */
5081 string_free(tb->lines_list[tb->cy]);
5082 tb->lines_list[tb->cy] = string_make(buf);
5089 tb->dirty_flags |= DIRTY_ALL;
5091 /* Expressions need re-evaluation */
5092 tb->dirty_flags |= DIRTY_EXPRESSION;
5094 /* Text is changed */
5103 /* Disable the selection */
5107 tb->dirty_flags |= DIRTY_ALL;
5111 tb->mark = MARK_MARK;
5113 /* Repeating this command swaps cursor position */
5114 if (com_id == tb->old_com_id)
5126 tb->dirty_flags |= DIRTY_ALL;
5130 int len = strlen(tb->lines_list[tb->cy]);
5132 /* Mark the point 1 */
5136 /* Correct cursor location */
5137 if (tb->cx > len) tb->mx = len;
5144 /* Kill rest of line */
5146 int len = strlen(tb->lines_list[tb->cy]);
5148 /* Correct cursor location */
5149 if (tb->cx > len) tb->cx = len;
5151 /* Ignore selection */
5157 tb->dirty_flags |= DIRTY_ALL;
5160 /* Append only if this command is repeated. */
5161 if (tb->old_com_id != com_id)
5163 kill_yank_chain(tb);
5167 /* Really deleted some text */
5170 /* Add deleted string to yank buffer */
5171 add_str_to_yank(tb, &(tb->lines_list[tb->cy][tb->cx]));
5173 kill_line_segment(tb, tb->cy, tb->cx, len, FALSE);
5176 tb->dirty_line = tb->cy;
5178 /* Leave end of line character */
5182 /* Cut the end of line character only */
5183 if (tb->yank_eol) add_str_to_yank(tb, "");
5185 /* Cut end of line */
5186 tb->yank_eol = TRUE;
5188 do_editor_command(tb, EC_DELETE_CHAR);
5192 case EC_DELETE_CHAR:
5193 /* DELETE == go forward + BACK SPACE */
5195 /* Ignore selection */
5201 tb->dirty_flags |= DIRTY_ALL;
5205 if (iskanji(tb->lines_list[tb->cy][tb->cx])) tb->cx++;
5209 do_editor_command(tb, EC_BACKSPACE);
5217 char buf[MAX_LINELEN];
5219 /* Ignore selection */
5225 tb->dirty_flags |= DIRTY_ALL;
5228 len = strlen(tb->lines_list[tb->cy]);
5231 if (tb->lines_list[tb->cy + 1])
5245 /* delete a return code and union two lines */
5246 if (tb->cy == 0) break;
5247 tb->cx = strlen(tb->lines_list[tb->cy-1]);
5248 strcpy(buf, tb->lines_list[tb->cy-1]);
5249 strcat(buf, tb->lines_list[tb->cy]);
5250 string_free(tb->lines_list[tb->cy-1]);
5251 string_free(tb->lines_list[tb->cy]);
5252 tb->lines_list[tb->cy-1] = string_make(buf);
5254 for (i = tb->cy; tb->lines_list[i+1]; i++)
5255 tb->lines_list[i] = tb->lines_list[i+1];
5257 tb->lines_list[i] = NULL;
5261 tb->dirty_flags |= DIRTY_ALL;
5263 /* Expressions need re-evaluation */
5264 tb->dirty_flags |= DIRTY_EXPRESSION;
5266 /* Text is changed */
5272 for (i = j = k = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
5276 if (iskanji(tb->lines_list[tb->cy][i]))
5277 buf[j++] = tb->lines_list[tb->cy][i++];
5279 buf[j++] = tb->lines_list[tb->cy][i];
5286 for (; tb->lines_list[tb->cy][i]; i++)
5287 buf[j++] = tb->lines_list[tb->cy][i];
5289 string_free(tb->lines_list[tb->cy]);
5290 tb->lines_list[tb->cy] = string_make(buf);
5293 tb->dirty_line = tb->cy;
5295 /* Expressions may need re-evaluation */
5296 check_expression_line(tb, tb->cy);
5298 /* Text is changed */
5308 /* Become dirty because of item/equip menu */
5309 tb->dirty_flags |= DIRTY_SCREEN;
5311 search_dir = get_string_for_search(&tb->search_o_ptr, &tb->search_str);
5313 if (!search_dir) break;
5315 if (search_dir == 1) do_editor_command(tb, EC_SEARCH_FORW);
5316 else do_editor_command(tb, EC_SEARCH_BACK);
5320 case EC_SEARCH_FORW:
5321 if (tb->search_o_ptr)
5323 search_for_object(tb, tb->search_o_ptr, TRUE);
5325 else if (tb->search_str)
5327 search_for_string(tb, tb->search_str, TRUE);
5331 tb->dirty_flags |= DIRTY_NO_SEARCH;
5335 case EC_SEARCH_BACK:
5336 if (tb->search_o_ptr)
5338 search_for_object(tb, tb->search_o_ptr, FALSE);
5340 else if (tb->search_str)
5342 search_for_string(tb, tb->search_str, FALSE);
5346 tb->dirty_flags |= DIRTY_NO_SEARCH;
5351 /* Become dirty because of item/equip menu */
5352 tb->dirty_flags |= DIRTY_SCREEN;
5354 if (!get_object_for_search(&tb->search_o_ptr, &tb->search_str)) break;
5356 do_editor_command(tb, EC_SEARCH_FORW);
5359 case EC_SEARCH_DESTROYED:
5360 if (!get_destroyed_object_for_search(&tb->search_o_ptr, &tb->search_str))
5362 /* There is no object to search */
5363 tb->dirty_flags |= DIRTY_NO_SEARCH;
5368 do_editor_command(tb, EC_SEARCH_FORW);
5371 case EC_INSERT_OBJECT:
5373 /* Insert choosen item name */
5375 autopick_type an_entry, *entry = &an_entry;
5377 if (!entry_from_choosed_object(entry))
5379 /* Now dirty because of item/equip menu */
5380 tb->dirty_flags |= DIRTY_SCREEN;
5385 insert_return_code(tb);
5386 string_free(tb->lines_list[tb->cy]);
5387 tb->lines_list[tb->cy] = autopick_line_from_entry_kill(entry);
5389 /* Now dirty because of item/equip menu */
5390 tb->dirty_flags |= DIRTY_SCREEN;
5395 case EC_INSERT_DESTROYED:
5396 /* Insert a name of last destroyed item */
5397 if (tb->last_destroyed)
5400 insert_return_code(tb);
5401 string_free(tb->lines_list[tb->cy]);
5402 tb->lines_list[tb->cy] = string_make(tb->last_destroyed);
5405 tb->dirty_flags |= DIRTY_ALL;
5407 /* Text is changed */
5412 case EC_INSERT_BLOCK:
5414 /* Insert a conditinal expression line */
5415 char expression[80];
5417 /* Conditional Expression for Class and Race */
5418 sprintf(expression, "?:[AND [EQU $RACE %s] [EQU $CLASS %s] [GEQ $LEVEL %02d]]",
5420 rp_ptr->E_title, cp_ptr->E_title,
5422 rp_ptr->title, cp_ptr->title,
5428 insert_return_code(tb);
5429 string_free(tb->lines_list[tb->cy]);
5430 tb->lines_list[tb->cy] = string_make(expression);
5432 insert_return_code(tb);
5433 string_free(tb->lines_list[tb->cy]);
5434 tb->lines_list[tb->cy] = string_make("?:1");
5437 tb->dirty_flags |= DIRTY_ALL;
5439 /* Text is changed */
5445 case EC_INSERT_MACRO:
5446 /* Draw_everythig (delete menu) */
5447 draw_text_editor(tb);
5450 Term_erase(0, tb->cy - tb->upper + 1, tb->wid);
5454 Term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW, "P:<¥È¥ê¥¬¡¼¥¡¼>: ");
5456 Term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW, "P:<Trigger key>: ");
5458 if (insert_macro_line(tb))
5460 /* Prepare to input action */
5464 tb->dirty_flags |= DIRTY_ALL;
5466 /* Text is changed */
5472 case EC_INSERT_KEYMAP:
5473 /* Draw_everythig (delete menu) */
5474 draw_text_editor(tb);
5477 Term_erase(0, tb->cy - tb->upper + 1, tb->wid);
5481 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)));
5483 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)));
5486 if (insert_keymap_line(tb))
5488 /* Prepare to input action */
5492 tb->dirty_flags |= DIRTY_ALL;
5494 /* Text is changed */
5499 case EC_CL_AUTOPICK: toggle_command_letter(tb, DO_AUTOPICK); break;
5500 case EC_CL_DESTROY: toggle_command_letter(tb, DO_AUTODESTROY); break;
5501 case EC_CL_LEAVE: toggle_command_letter(tb, DONT_AUTOPICK); break;
5502 case EC_CL_QUERY: toggle_command_letter(tb, DO_QUERY_AUTOPICK); break;
5503 case EC_CL_NO_DISP: toggle_command_letter(tb, DO_DISPLAY); break;
5505 case EC_IK_UNAWARE: toggle_keyword(tb, FLG_UNAWARE); break;
5506 case EC_IK_UNIDENTIFIED: toggle_keyword(tb, FLG_UNIDENTIFIED); break;
5507 case EC_IK_IDENTIFIED: toggle_keyword(tb, FLG_IDENTIFIED); break;
5508 case EC_IK_STAR_IDENTIFIED: toggle_keyword(tb, FLG_STAR_IDENTIFIED); break;
5509 case EC_KK_WEAPONS: toggle_keyword(tb, FLG_WEAPONS); break;
5510 case EC_KK_FAVORITE: toggle_keyword(tb, FLG_FAVORITE); break;
5511 case EC_KK_ARMORS: toggle_keyword(tb, FLG_ARMORS); break;
5512 case EC_KK_MISSILES: toggle_keyword(tb, FLG_MISSILES); break;
5513 case EC_KK_DEVICES: toggle_keyword(tb, FLG_DEVICES); break;
5514 case EC_KK_LIGHTS: toggle_keyword(tb, FLG_LIGHTS); break;
5515 case EC_KK_JUNKS: toggle_keyword(tb, FLG_JUNKS); break;
5516 case EC_KK_SPELLBOOKS: toggle_keyword(tb, FLG_SPELLBOOKS); break;
5517 case EC_KK_SHIELDS: toggle_keyword(tb, FLG_SHIELDS); break;
5518 case EC_KK_BOWS: toggle_keyword(tb, FLG_BOWS); break;
5519 case EC_KK_RINGS: toggle_keyword(tb, FLG_RINGS); break;
5520 case EC_KK_AMULETS: toggle_keyword(tb, FLG_AMULETS); break;
5521 case EC_KK_SUITS: toggle_keyword(tb, FLG_SUITS); break;
5522 case EC_KK_CLOAKS: toggle_keyword(tb, FLG_CLOAKS); break;
5523 case EC_KK_HELMS: toggle_keyword(tb, FLG_HELMS); break;
5524 case EC_KK_GLOVES: toggle_keyword(tb, FLG_GLOVES); break;
5525 case EC_KK_BOOTS: toggle_keyword(tb, FLG_BOOTS); break;
5526 case EC_OK_COLLECTING: toggle_keyword(tb, FLG_COLLECTING); break;
5527 case EC_OK_BOOSTED: toggle_keyword(tb, FLG_BOOSTED); break;
5528 case EC_OK_MORE_THAN: toggle_keyword(tb, FLG_MORE_THAN); break;
5529 case EC_OK_MORE_BONUS: toggle_keyword(tb, FLG_MORE_BONUS); break;
5530 case EC_OK_WORTHLESS: toggle_keyword(tb, FLG_WORTHLESS); break;
5531 case EC_OK_ARTIFACT: toggle_keyword(tb, FLG_ARTIFACT); break;
5532 case EC_OK_EGO: toggle_keyword(tb, FLG_EGO); break;
5533 case EC_OK_NAMELESS: toggle_keyword(tb, FLG_NAMELESS); break;
5534 case EC_OK_WANTED: toggle_keyword(tb, FLG_WANTED); break;
5535 case EC_OK_UNIQUE: toggle_keyword(tb, FLG_UNIQUE); break;
5536 case EC_OK_HUMAN: toggle_keyword(tb, FLG_HUMAN); break;
5537 case EC_OK_UNREADABLE:
5538 toggle_keyword(tb, FLG_UNREADABLE);
5539 add_keyword(tb, FLG_SPELLBOOKS);
5542 toggle_keyword(tb, FLG_REALM1);
5543 add_keyword(tb, FLG_SPELLBOOKS);
5546 toggle_keyword(tb, FLG_REALM2);
5547 add_keyword(tb, FLG_SPELLBOOKS);
5550 toggle_keyword(tb, FLG_FIRST);
5551 add_keyword(tb, FLG_SPELLBOOKS);
5554 toggle_keyword(tb, FLG_SECOND);
5555 add_keyword(tb, FLG_SPELLBOOKS);
5558 toggle_keyword(tb, FLG_THIRD);
5559 add_keyword(tb, FLG_SPELLBOOKS);
5562 toggle_keyword(tb, FLG_FOURTH);
5563 add_keyword(tb, FLG_SPELLBOOKS);
5567 /* Save old command */
5568 tb->old_com_id = com_id;
5575 * Insert single letter at cursor position.
5577 static void insert_single_letter(text_body_type *tb, int key)
5580 char buf[MAX_LINELEN];
5582 /* Save preceding string */
5583 for (i = j = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
5584 buf[j++] = tb->lines_list[tb->cy][i];
5586 /* Add a character */
5594 if (j+2 < MAX_LINELEN)
5606 if (j+1 < MAX_LINELEN)
5612 for (; tb->lines_list[tb->cy][i] && j + 1 < MAX_LINELEN; i++)
5613 buf[j++] = tb->lines_list[tb->cy][i];
5616 /* Replace current line with new line */
5617 string_free(tb->lines_list[tb->cy]);
5618 tb->lines_list[tb->cy] = string_make(buf);
5620 /* Move to correct collumn */
5621 len = strlen(tb->lines_list[tb->cy]);
5622 if (len < tb->cx) tb->cx = len;
5625 tb->dirty_line = tb->cy;
5627 /* Expressions may need re-evaluation */
5628 check_expression_line(tb, tb->cy);
5630 /* Text is changed */
5636 * Check special key code and get a movement command id
5638 static int analyze_move_key(text_body_type *tb, int skey)
5642 /* Not a special key */
5643 if (!(skey & SKEY_MASK)) return 0;
5645 /* Convert from a special key code to an editor command */
5646 switch(skey & ~SKEY_MOD_MASK)
5648 case SKEY_DOWN: com_id = EC_DOWN; break;
5649 case SKEY_LEFT: com_id = EC_LEFT; break;
5650 case SKEY_RIGHT: com_id = EC_RIGHT; break;
5651 case SKEY_UP: com_id = EC_UP; break;
5652 case SKEY_PGUP: com_id = EC_PGUP; break;
5653 case SKEY_PGDOWN: com_id = EC_PGDOWN; break;
5654 case SKEY_TOP: com_id = EC_TOP; break;
5655 case SKEY_BOTTOM: com_id = EC_BOTTOM; break;
5658 /* Not a special movement key */
5662 /* Without shift modifier */
5663 if (!(skey & SKEY_MOD_SHIFT))
5666 * Un-shifted cursor keys cancells
5667 * selection created by shift+cursor.
5669 if (tb->mark & MARK_BY_SHIFT)
5674 tb->dirty_flags |= DIRTY_ALL;
5678 /* With shift modifier */
5681 /* Start selection by shift + cursor keys */
5684 int len = strlen(tb->lines_list[tb->cy]);
5686 tb->mark = MARK_MARK | MARK_BY_SHIFT;
5690 /* Correct cursor location */
5691 if (tb->cx > len) tb->mx = len;
5693 /* Need to redraw text */
5694 if (com_id == EC_UP || com_id == EC_DOWN)
5696 /* Redraw all text */
5697 tb->dirty_flags |= DIRTY_ALL;
5701 tb->dirty_line = tb->cy;
5710 * In-game editor of Object Auto-picker/Destoryer
5712 void do_cmd_edit_autopick(void)
5714 static int cx_save = 0;
5715 static int cy_save = 0;
5717 text_body_type text_body, *tb = &text_body;
5719 autopick_type an_entry, *entry = &an_entry;
5720 char buf[MAX_LINELEN];
5725 static s32b old_autosave_turn = 0L;
5728 tb->changed = FALSE;
5731 tb->upper = tb->left = 0;
5733 tb->mx = tb->my = 0;
5734 tb->old_cy = tb->old_upper = tb->old_left = -1;
5735 tb->old_wid = tb->old_hgt = -1;
5739 tb->search_o_ptr = NULL;
5740 tb->search_str = NULL;
5741 tb->last_destroyed = NULL;
5742 tb->dirty_flags = DIRTY_ALL | DIRTY_MODE | DIRTY_EXPRESSION;
5743 tb->dirty_line = -1;
5744 tb->filename_mode = PT_DEFAULT;
5747 if (turn > old_autosave_turn + 100L)
5749 do_cmd_save_game(TRUE);
5750 old_autosave_turn = turn;
5753 /* HACK -- Reset start_time to stop counting playtime while edit */
5756 /* Free old entries */
5759 /* Command Description of the 'Last Destroyed Item' */
5760 if (autopick_last_destroyed_object.k_idx)
5762 autopick_entry_from_object(entry, &autopick_last_destroyed_object);
5763 tb->last_destroyed = autopick_line_from_entry_kill(entry);
5766 /* Read or initialize whole text */
5767 tb->lines_list = read_pickpref_text_lines(&tb->filename_mode);
5769 /* Reset cursor position if needed */
5770 for (i = 0; i < tb->cy; i++)
5772 if (!tb->lines_list[i])
5774 tb->cy = tb->cx = 0;
5779 /* Save the screen */
5782 /* Process requests until done */
5787 /* Draw_everythig */
5788 draw_text_editor(tb);
5790 /* Display header line */
5792 prt("(^Q:½ªÎ» ^W:¥»¡¼¥Ö¤·¤Æ½ªÎ», ESC:¥á¥Ë¥å¡¼, ¤½¤Î¾:ÆþÎÏ)", 0, 0);
5794 prt("(^Q:quit, ^W:save&quit, ESC:menu, Other:input text)", 0, 0);
5798 /* Display current position */
5799 prt (format("(%d,%d)", tb->cx, tb->cy), 0, 60);
5803 /* Display current position and mark position */
5804 prt (format("(%d,%d)-(%d,%d)", tb->mx, tb->my, tb->cx, tb->cy), 0, 60);
5808 Term_gotoxy(tb->cx - tb->left, tb->cy - tb->upper + 1);
5811 tb->dirty_flags = 0;
5812 tb->dirty_line = -1;
5814 /* Save old key and location */
5815 tb->old_cy = tb->cy;
5816 tb->old_upper = tb->upper;
5817 tb->old_left = tb->left;
5818 tb->old_wid = tb->wid;
5819 tb->old_hgt = tb->hgt;
5822 key = inkey_special();
5825 if (key & SKEY_MASK)
5827 /* Get a movement command */
5828 com_id = analyze_move_key(tb, key);
5832 else if (key == ESCAPE)
5834 com_id = do_command_menu(0, 0);
5836 /* Redraw all text later */
5837 tb->dirty_flags |= DIRTY_SCREEN;
5840 /* Insert a character */
5841 else if (!iscntrl((unsigned char)key))
5843 /* Ignore selection */
5849 tb->dirty_flags |= DIRTY_ALL;
5852 insert_single_letter(tb, key);
5858 /* Other commands */
5861 com_id = get_com_id(key);
5864 if (com_id) quit = do_editor_command(tb, com_id);
5865 } /* while (TRUE) */
5867 /* Restore the screen */
5870 /* Get the filename of preference */
5871 strcpy(buf, pickpref_filename(tb->filename_mode));
5873 if (quit == QUIT_AND_SAVE)
5874 write_text_lines(buf, tb->lines_list);
5876 free_text_lines(tb->lines_list);
5878 string_free(tb->last_destroyed);
5880 /* Destroy string chain */
5881 kill_yank_chain(tb);
5883 /* Reload autopick pref */
5884 process_pickpref_file(buf);
5886 /* HACK -- reset start_time so that playtime is not increase while edit */
5887 start_time = time(NULL);
5889 /* Save cursor location */