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 * A function for Auto-picker/destroyer
1277 * Examine whether the object matches to the list of keywords or not.
1279 int is_autopick(object_type *o_ptr)
1282 char o_name[MAX_NLEN];
1284 if (o_ptr->tval == TV_GOLD) return -1;
1286 object_desc(o_name, o_ptr, FALSE, 3);
1288 /* Force to be lower case string */
1289 for (i = 0; o_name[i]; i++)
1292 if (iskanji(o_name[i]))
1296 if (isupper(o_name[i]))
1297 o_name[i] = tolower(o_name[i]);
1300 for (i=0; i < max_autopick; i++)
1302 autopick_type *entry = &autopick_list[i];
1304 if (is_autopick_aux(o_ptr, entry, o_name)) return i;
1307 /* No matching entry */
1315 void auto_inscribe_item(int item, int idx)
1319 /* Get the item (in the pack) */
1320 if (item >= 0) o_ptr = &inventory[item];
1322 /* Get the item (on the floor) */
1323 else o_ptr = &o_list[0 - item];
1325 /* Auto-inscription or Re-inscribe for resistances {%} */
1326 if ((idx < 0 || !autopick_list[idx].insc) && !o_ptr->inscription)
1329 if (!o_ptr->inscription)
1330 o_ptr->inscription = quark_add(autopick_list[idx].insc);
1332 if (item > INVEN_PACK)
1334 /* Redraw inscription */
1335 p_ptr->window |= (PW_EQUIP);
1337 /* {.} and {$} effect p_ptr->warning and TRC_TELEPORT_SELF */
1338 p_ptr->update |= (PU_BONUS);
1342 /* Redraw inscription */
1343 p_ptr->window |= (PW_INVEN);
1349 * Automatically destroy items in this grid.
1351 static bool is_opt_confirm_destroy(object_type *o_ptr)
1353 if (!destroy_items) return FALSE;
1355 /* Known to be worthless? */
1357 if (object_value(o_ptr) > 0) return FALSE;
1360 if ((o_ptr->tval >= TV_MISSILE_BEGIN) && (o_ptr->tval <= TV_ARMOR_END)) return FALSE;
1363 if ((o_ptr->tval == TV_CHEST) && o_ptr->pval) return FALSE;
1367 if (o_ptr->tval == TV_CORPSE
1368 && object_is_shoukinkubi(o_ptr)) return FALSE;
1372 if (o_ptr->tval == TV_CORPSE) return FALSE;
1375 if ((o_ptr->tval == TV_SKELETON) || (o_ptr->tval == TV_BOTTLE) || (o_ptr->tval == TV_JUNK) || (o_ptr->tval == TV_STATUE)) return FALSE;
1379 if (p_ptr->prace == RACE_DEMON)
1381 if (o_ptr->tval == TV_CORPSE &&
1382 o_ptr->sval == SV_CORPSE &&
1383 strchr("pht", r_info[o_ptr->pval].d_char))
1387 if (p_ptr->pclass == CLASS_ARCHER)
1389 if (o_ptr->tval == TV_SKELETON ||
1390 (o_ptr->tval == TV_CORPSE && o_ptr->sval == SV_SKELETON))
1393 else if (p_ptr->pclass == CLASS_NINJA)
1395 if (o_ptr->tval == TV_LITE &&
1396 o_ptr->name2 == EGO_LITE_DARKNESS)
1399 else if (p_ptr->pclass == CLASS_BEASTMASTER ||
1400 p_ptr->pclass == CLASS_CAVALRY)
1402 if (o_ptr->tval == TV_WAND &&
1403 o_ptr->sval == SV_WAND_HEAL_MONSTER)
1408 if (o_ptr->tval == TV_GOLD) return FALSE;
1415 * Automatically destroy an item if it is to be destroyed
1417 static object_type autopick_last_destroyed_object;
1419 bool auto_destroy_item(int item, int autopick_idx)
1421 bool destroy = FALSE;
1424 /* Don't destroy equipped items */
1425 if (item > INVEN_PACK) return FALSE;
1427 /* Get the item (in the pack) */
1428 if (item >= 0) o_ptr = &inventory[item];
1430 /* Get the item (on the floor) */
1431 else o_ptr = &o_list[0 - item];
1433 /* Easy-Auto-Destroyer */
1434 if (is_opt_confirm_destroy(o_ptr)) destroy = TRUE;
1436 /* Protected by auto-picker */
1437 if (autopick_idx >= 0 &&
1438 !(autopick_list[autopick_idx].action & DO_AUTODESTROY))
1443 /* Auto-picker/destroyer */
1444 if (autopick_idx >= 0 &&
1445 (autopick_list[autopick_idx].action & DO_AUTODESTROY))
1449 /* Not to be destroyed */
1450 if (!destroy) return FALSE;
1452 /* Now decided to destroy */
1457 if (!can_player_destroy_object(o_ptr))
1459 char o_name[MAX_NLEN];
1461 /* Describe the object (with {terrible/special}) */
1462 object_desc(o_name, o_ptr, TRUE, 3);
1466 msg_format("%s¤ÏÇ˲õÉÔǽ¤À¡£", o_name);
1468 msg_format("You cannot auto-destroy %s.", o_name);
1475 /* Record name of destroyed item */
1476 COPY(&autopick_last_destroyed_object, o_ptr, object_type);
1479 o_ptr->marked |= OM_AUTODESTROY;
1480 p_ptr->notice |= PN_AUTODESTROY;
1487 * Auto-destroy marked item
1489 static void delayed_auto_destroy_aux(int item)
1493 /* Get the item (in the pack) */
1494 if (item >= 0) o_ptr = &inventory[item];
1496 /* Get the item (on the floor) */
1497 else o_ptr = &o_list[0 - item];
1499 if (o_ptr->k_idx && o_ptr->marked & OM_AUTODESTROY)
1501 char o_name[MAX_NLEN];
1503 /* Describe the object (with {terrible/special}) */
1504 object_desc(o_name, o_ptr, TRUE, 3);
1506 /* Eliminate the item (from the pack) */
1509 inven_item_increase(item, -(o_ptr->number));
1510 inven_item_optimize(item);
1513 /* Eliminate the item (from the floor) */
1516 delete_object_idx(0 - item);
1519 /* Print a message */
1521 msg_format("%s¤ò¼«Æ°Ç˲õ¤·¤Þ¤¹¡£", o_name);
1523 msg_format("Auto-destroying %s.", o_name);
1530 * Auto-destroy marked item in inventry and on floor
1532 void delayed_auto_destroy(void)
1537 * Scan inventry in reverse order to prevent
1538 * skipping after inven_item_optimize()
1540 for (item = INVEN_TOTAL - 1; item >= 0 ; item--)
1541 delayed_auto_destroy_aux(item);
1543 /* Scan the pile of objects */
1544 item = cave[py][px].o_idx;
1547 int next = o_list[item].next_o_idx;
1548 delayed_auto_destroy_aux(-item);
1555 * Automatically pickup/destroy items in this grid.
1557 void auto_pickup_items(cave_type *c_ptr)
1559 s16b this_o_idx, next_o_idx = 0;
1561 /* Scan the pile of objects */
1562 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1566 /* Acquire object */
1567 object_type *o_ptr = &o_list[this_o_idx];
1569 /* Acquire next object */
1570 next_o_idx = o_ptr->next_o_idx;
1572 idx = is_autopick(o_ptr);
1574 /* Item index for floor -1,-2,-3,... */
1575 auto_inscribe_item((-this_o_idx), idx);
1578 (autopick_list[idx].action & (DO_AUTOPICK | DO_QUERY_AUTOPICK)))
1582 if (!inven_carry_okay(o_ptr))
1584 char o_name[MAX_NLEN];
1586 /* Describe the object */
1587 object_desc(o_name, o_ptr, TRUE, 3);
1591 msg_format("¥¶¥Ã¥¯¤Ë¤Ï%s¤òÆþ¤ì¤ë·ä´Ö¤¬¤Ê¤¤¡£", o_name);
1593 msg_format("You have no room for %s.", o_name);
1595 /* Hack - remember that the item has given a message here. */
1596 o_ptr->marked |= OM_NOMSG;
1600 else if (autopick_list[idx].action & DO_QUERY_AUTOPICK)
1602 char out_val[MAX_NLEN+20];
1603 char o_name[MAX_NLEN];
1605 if (o_ptr->marked & OM_NO_QUERY)
1607 /* Already answered as 'No' */
1611 /* Describe the object */
1612 object_desc(o_name, o_ptr, TRUE, 3);
1615 sprintf(out_val, "%s¤ò½¦¤¤¤Þ¤¹¤«? ", o_name);
1617 sprintf(out_val, "Pick up %s? ", o_name);
1620 if (!get_check(out_val))
1622 /* Hack - remember that the item has given a message here. */
1623 o_ptr->marked |= (OM_NOMSG | OM_NO_QUERY);
1628 py_pickup_aux(this_o_idx);
1635 * When always_pickup is 'yes', we disable
1636 * auto-destroyer from autopick function, and do only
1637 * easy-auto-destroyer.
1641 if (auto_destroy_item((-this_o_idx), idx))
1648 #define PT_DEFAULT 0
1649 #define PT_WITH_PNAME 1
1652 * Get file name for autopick preference
1654 static cptr pickpref_filename(int filename_mode)
1657 static const char namebase[] = "picktype";
1659 static const char namebase[] = "pickpref";
1662 switch (filename_mode)
1665 return format("%s.prf", namebase);
1668 return format("%s-%s.prf", namebase, player_name);
1676 static const char autoregister_header[] = "?:$AUTOREGISTER";
1679 * Clear auto registered lines in the picktype.prf .
1681 static bool clear_auto_register(void)
1683 char tmp_file[1024];
1684 char pref_file[1024];
1689 bool autoregister = FALSE;
1692 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_WITH_PNAME));
1693 pref_fff = my_fopen(pref_file, "r");
1697 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_DEFAULT));
1698 pref_fff = my_fopen(pref_file, "r");
1707 /* Open a new (temporary) file */
1708 tmp_fff = my_fopen_temp(tmp_file, sizeof(tmp_file));
1712 /* Close the preference file */
1716 msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤¤Þ¤»¤ó¤Ç¤·¤¿¡£", tmp_file);
1718 msg_format("Failed to create temporary file %s.", tmp_file);
1725 /* Loop for every line */
1729 if (my_fgets(pref_fff, buf, sizeof(buf))) break;
1733 /* Delete auto-registered line */
1735 /* Count auto-destroy preference lines */
1736 if (buf[0] != '#' && buf[0] != '?') num++;
1739 /* We are looking for auto-registered line */
1742 if (streq(buf, autoregister_header))
1744 /* Delete all further lines */
1745 autoregister = TRUE;
1749 /* Copy orginally lines */
1750 fprintf(tmp_fff, "%s\n", buf);
1756 my_fclose(pref_fff);
1762 msg_format("°ÊÁ°¤Î¥¥ã¥é¥¯¥¿¡¼ÍѤμ«Æ°ÀßÄê(%d¹Ô)¤¬»Ä¤Ã¤Æ¤¤¤Þ¤¹¡£", num);
1763 strcpy(buf, "¸Å¤¤ÀßÄê¹Ô¤Ïºï½ü¤·¤Þ¤¹¡£¤è¤í¤·¤¤¤Ç¤¹¤«¡©");
1765 msg_format("Auto registered lines (%d lines) for previous character are remaining.", num);
1766 strcpy(buf, "These lines will be deleted. Are you sure? ");
1769 /* You can cancel it */
1770 if (!get_check(buf))
1773 autoregister = FALSE;
1776 msg_print("¥¨¥Ç¥£¥¿¤Î¥«¥Ã¥È&¥Ú¡¼¥¹¥ÈÅù¤ò»È¤Ã¤ÆɬÍפʹԤòÈòÆñ¤·¤Æ¤¯¤À¤µ¤¤¡£");
1778 msg_print("Use cut & paste of auto picker editor (_) to keep old prefs.");
1784 /* If there are some changes, overwrite the original file with new one */
1787 /* Copy contents of temporary file */
1789 tmp_fff = my_fopen(tmp_file, "r");
1790 pref_fff = my_fopen(pref_file, "w");
1792 while (!my_fgets(tmp_fff, buf, sizeof(buf)))
1793 fprintf(pref_fff, "%s\n", buf);
1795 my_fclose(pref_fff);
1799 /* Kill the temporary file */
1807 * Automatically register an auto-destroy preference line
1809 bool add_auto_register(object_type *o_ptr)
1812 char pref_file[1024];
1814 autopick_type an_entry, *entry = &an_entry;
1816 int match_autopick = is_autopick(o_ptr);
1818 /* Already registered */
1819 if (match_autopick != -1)
1822 byte act = autopick_list[match_autopick].action;
1825 if (act & DO_AUTOPICK) what = "¼«Æ°¤Ç½¦¤¦";
1826 else if (act & DO_AUTODESTROY) what = "¼«Æ°Ç˲õ¤¹¤ë";
1827 else if (act & DONT_AUTOPICK) what = "ÊüÃÖ¤¹¤ë";
1828 else /* if (act & DO_QUERY_AUTOPICK) */ what = "³Îǧ¤·¤Æ½¦¤¦";
1830 msg_format("¤½¤Î¥¢¥¤¥Æ¥à¤Ï´û¤Ë%s¤è¤¦¤ËÀßÄꤵ¤ì¤Æ¤¤¤Þ¤¹¡£", what);
1832 if (act & DO_AUTOPICK) what = "auto-pickup";
1833 else if (act & DO_AUTODESTROY) what = "auto-destroy";
1834 else if (act & DONT_AUTOPICK) what = "leave on floor";
1835 else /* if (act & DO_QUERY_AUTOPICK) */ what = "query auto-pickup";
1837 msg_format("The object is already registered to %s.", what);
1844 if (!p_ptr->autopick_autoregister)
1846 /* Clear old auto registered lines */
1847 if (!clear_auto_register()) return FALSE;
1850 /* Try a filename with player name */
1851 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_WITH_PNAME));
1852 pref_fff = my_fopen(pref_file, "r");
1856 /* Use default name */
1857 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_DEFAULT));
1858 pref_fff = my_fopen(pref_file, "r");
1861 /* Check the header */
1865 if (my_fgets(pref_fff, buf, sizeof(buf)))
1867 /* No header found */
1868 p_ptr->autopick_autoregister = FALSE;
1873 if (streq(buf, autoregister_header))
1875 /* Found the header */
1876 p_ptr->autopick_autoregister = TRUE;
1882 /* Close read only FILE* */
1885 /* Open for append */
1886 pref_fff = my_fopen(pref_file, "a");
1891 msg_format("%s ¤ò³«¤¯¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¤Ç¤·¤¿¡£", pref_file);
1893 msg_format("Failed to open %s.", pref_file);
1901 if (!p_ptr->autopick_autoregister)
1903 /* Add the header */
1904 fprintf(pref_fff, "%s\n", autoregister_header);
1907 fprintf(pref_fff, "%s\n", "# *·Ù¹ð!!* °Ê¹ß¤Î¹Ô¤Ï¼«Æ°ÅÐÏ¿¤µ¤ì¤¿¤â¤Î¤Ç¤¹¡£");
1908 fprintf(pref_fff, "%s\n", "# ¸å¤Ç¼«Æ°Åª¤Ëºï½ü¤µ¤ì¤Þ¤¹¤Î¤Ç¡¢É¬ÍפʹԤϾå¤ÎÊý¤Ø°ÜÆ°¤·¤Æ¤ª¤¤¤Æ¤¯¤À¤µ¤¤¡£");
1910 fprintf(pref_fff, "%s\n", "# *Waring!* The lines below will be deleated later.");
1911 fprintf(pref_fff, "%s\n", "# Keep it by cut & paste if you need these lines for future characters.");
1914 /* Now auto register is in-use */
1915 p_ptr->autopick_autoregister = TRUE;
1918 /* Get a preference entry */
1919 autopick_entry_from_object(entry, o_ptr);
1921 /* Set to auto-destroy (with no-display) */
1922 entry->action = DO_AUTODESTROY;
1924 /* Load the new line as preference */
1925 add_autopick_list(entry);
1927 /* Add a line to the file */
1928 /* Don't kill "entry" */
1929 fprintf(pref_fff, "%s\n", autopick_line_from_entry(entry));
1931 /* Close the file */
1938 /******** Auto-picker/destroyer editor **********/
1940 #define MAX_YANK MAX_LINELEN
1941 #define MAX_LINES 3000
1943 #define MARK_MARK 0x01
1944 #define MARK_BY_SHIFT 0x02
1946 #define LSTAT_BYPASS 0x01
1947 #define LSTAT_EXPRESSION 0x02
1948 #define LSTAT_AUTOREGISTER 0x04
1950 #define QUIT_WITHOUT_SAVE 1
1951 #define QUIT_AND_SAVE 2
1954 * Struct for yank buffer
1956 typedef struct chain_str {
1957 struct chain_str *next;
1963 * Data struct for text editor
1969 int old_wid, old_hgt;
1971 int old_upper, old_left;
1975 object_type *search_o_ptr;
1977 cptr last_destroyed;
1979 chain_str_type *yank;
1983 byte states[MAX_LINES];
1995 * Dirty flag for text editor
1997 #define DIRTY_ALL 0x01
1998 #define DIRTY_MODE 0x04
1999 #define DIRTY_SCREEN 0x08
2000 #define DIRTY_NOT_FOUND 0x10
2001 #define DIRTY_NO_SEARCH 0x20
2002 #define DIRTY_EXPRESSION 0x40
2006 * Describe which kind of object is Auto-picked/destroyed
2008 static void describe_autopick(char *buff, autopick_type *entry)
2010 cptr str = entry->name;
2011 byte act = entry->action;
2012 cptr insc = entry->insc;
2018 cptr before_str[100], body_str;
2021 body_str = "¥¢¥¤¥Æ¥à";
2023 /*** Collecting items ***/
2024 /*** Which can be absorbed into a slot as a bundle ***/
2025 if (IS_FLG(FLG_COLLECTING))
2026 before_str[before_n++] = "¼ý½¸Ãæ¤Ç´û¤Ë»ý¤Ã¤Æ¤¤¤ë¥¹¥í¥Ã¥È¤Ë¤Þ¤È¤á¤é¤ì¤ë";
2028 /*** Unidentified ***/
2029 if (IS_FLG(FLG_UNIDENTIFIED))
2030 before_str[before_n++] = "̤´ÕÄê¤Î";
2032 /*** Identified ***/
2033 if (IS_FLG(FLG_IDENTIFIED))
2034 before_str[before_n++] = "´ÕÄêºÑ¤ß¤Î";
2036 /*** *Identified* ***/
2037 if (IS_FLG(FLG_STAR_IDENTIFIED))
2038 before_str[before_n++] = "´°Á´¤Ë´ÕÄêºÑ¤ß¤Î";
2040 /*** Dice boosted (weapon of slaying) ***/
2041 if (IS_FLG(FLG_BOOSTED))
2043 before_str[before_n++] = "¥À¥á¡¼¥¸¥À¥¤¥¹¤¬Ä̾ï¤è¤êÂ礤¤";
2047 /*** Weapons whose dd*ds is more than nn ***/
2048 if (IS_FLG(FLG_MORE_THAN))
2050 static char more_than_desc_str[] = "___";
2051 before_str[before_n++] = "¥À¥á¡¼¥¸¥À¥¤¥¹¤ÎºÇÂçÃͤ¬";
2054 sprintf(more_than_desc_str,"%d", entry->dice);
2055 before_str[before_n++] = more_than_desc_str;
2056 before_str[before_n++] = "°Ê¾å¤Î";
2059 /*** Items whose magical bonus is more than nn ***/
2060 if (IS_FLG(FLG_MORE_BONUS))
2062 static char more_bonus_desc_str[] = "___";
2063 before_str[before_n++] = "½¤ÀµÃͤ¬(+";
2065 sprintf(more_bonus_desc_str,"%d", entry->bonus);
2066 before_str[before_n++] = more_bonus_desc_str;
2067 before_str[before_n++] = ")°Ê¾å¤Î";
2070 /*** Worthless items ***/
2071 if (IS_FLG(FLG_WORTHLESS))
2072 before_str[before_n++] = "Ź¤Ç̵²ÁÃͤÈȽÄꤵ¤ì¤ë";
2075 if (IS_FLG(FLG_ARTIFACT))
2077 before_str[before_n++] = "¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È¤Î";
2082 if (IS_FLG(FLG_EGO))
2084 before_str[before_n++] = "¥¨¥´¥¢¥¤¥Æ¥à¤Î";
2089 if (IS_FLG(FLG_NAMELESS))
2091 before_str[before_n++] = "¥¨¥´¤Ç¤â¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È¤Ç¤â¤Ê¤¤";
2095 /*** Unaware items ***/
2096 if (IS_FLG(FLG_UNAWARE))
2097 before_str[before_n++] = "̤´ÕÄê¤Ç¤½¤Î¸ú²Ì¤âȽÌÀ¤·¤Æ¤¤¤Ê¤¤";
2099 /*** Wanted monster's corpse/skeletons ***/
2100 if (IS_FLG(FLG_WANTED))
2102 before_str[before_n++] = "¥Ï¥ó¥¿¡¼»ö̳½ê¤Ç¾Þ¶â¼ó¤È¤µ¤ì¤Æ¤¤¤ë";
2103 body_str = "»àÂΤä¹ü";
2106 /*** Human corpse/skeletons (for Daemon magic) ***/
2107 if (IS_FLG(FLG_HUMAN))
2109 before_str[before_n++] = "°ËâËâË¡¤Ç»È¤¦¤¿¤á¤Î¿Í´Ö¤ä¥Ò¥å¡¼¥Þ¥Î¥¤¥É¤Î";
2110 body_str = "»àÂΤä¹ü";
2113 /*** Unique monster's corpse/skeletons/statues ***/
2114 if (IS_FLG(FLG_UNIQUE))
2116 before_str[before_n++] = "¥æ¥Ë¡¼¥¯¥â¥ó¥¹¥¿¡¼¤Î";
2117 body_str = "»àÂΤä¹ü";
2120 /*** Unreadable spellbooks ***/
2121 if (IS_FLG(FLG_UNREADABLE))
2123 before_str[before_n++] = "¤¢¤Ê¤¿¤¬Æɤá¤Ê¤¤Îΰè¤Î";
2124 body_str = "ËâË¡½ñ";
2127 /*** First realm spellbooks ***/
2128 if (IS_FLG(FLG_REALM1))
2130 before_str[before_n++] = "Âè°ìÎΰè¤Î";
2131 body_str = "ËâË¡½ñ";
2134 /*** Second realm spellbooks ***/
2135 if (IS_FLG(FLG_REALM2))
2137 before_str[before_n++] = "ÂèÆóÎΰè¤Î";
2138 body_str = "ËâË¡½ñ";
2141 /*** First rank spellbooks ***/
2142 if (IS_FLG(FLG_FIRST))
2144 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î1ºýÌܤÎ";
2145 body_str = "ËâË¡½ñ";
2148 /*** Second rank spellbooks ***/
2149 if (IS_FLG(FLG_SECOND))
2151 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î2ºýÌܤÎ";
2152 body_str = "ËâË¡½ñ";
2155 /*** Third rank spellbooks ***/
2156 if (IS_FLG(FLG_THIRD))
2158 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î3ºýÌܤÎ";
2159 body_str = "ËâË¡½ñ";
2162 /*** Fourth rank spellbooks ***/
2163 if (IS_FLG(FLG_FOURTH))
2165 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î4ºýÌܤÎ";
2166 body_str = "ËâË¡½ñ";
2170 if (IS_FLG(FLG_ITEMS))
2171 ; /* Nothing to do */
2172 else if (IS_FLG(FLG_WEAPONS))
2174 else if (IS_FLG(FLG_ARMORS))
2176 else if (IS_FLG(FLG_MISSILES))
2177 body_str = "ÃƤäÌð¤ä¥¯¥í¥¹¥Ü¥¦¤ÎÌð";
2178 else if (IS_FLG(FLG_DEVICES))
2179 body_str = "´¬Êª¤äËâË¡ËÀ¤ä¾ó¤ä¥í¥Ã¥É";
2180 else if (IS_FLG(FLG_LIGHTS))
2181 body_str = "¸÷¸»ÍѤΥ¢¥¤¥Æ¥à";
2182 else if (IS_FLG(FLG_JUNKS))
2183 body_str = "Àޤ줿ËÀÅù¤Î¥¬¥é¥¯¥¿";
2184 else if (IS_FLG(FLG_SPELLBOOKS))
2185 body_str = "ËâË¡½ñ";
2186 else if (IS_FLG(FLG_HAFTED))
2188 else if (IS_FLG(FLG_SHIELDS))
2190 else if (IS_FLG(FLG_BOWS))
2191 body_str = "¥¹¥ê¥ó¥°¤äµÝ¤ä¥¯¥í¥¹¥Ü¥¦";
2192 else if (IS_FLG(FLG_RINGS))
2194 else if (IS_FLG(FLG_AMULETS))
2195 body_str = "¥¢¥ß¥å¥ì¥Ã¥È";
2196 else if (IS_FLG(FLG_SUITS))
2198 else if (IS_FLG(FLG_CLOAKS))
2199 body_str = "¥¯¥í¡¼¥¯";
2200 else if (IS_FLG(FLG_HELMS))
2201 body_str = "¥Ø¥ë¥á¥Ã¥È¤ä´§";
2202 else if (IS_FLG(FLG_GLOVES))
2204 else if (IS_FLG(FLG_BOOTS))
2205 body_str = "¥Ö¡¼¥Ä";
2206 else if (IS_FLG(FLG_FAVORITE))
2207 body_str = "ÆÀ°ÕÉð´ï";
2211 strcat(buff, "Á´¤Æ¤Î");
2212 else for (i = 0; i < before_n && before_str[i]; i++)
2213 strcat(buff, before_str[i]);
2215 strcat(buff, body_str);
2225 strcat(buff, "¤Ç¡¢Ì¾Á°¤¬¡Ö");
2226 strncat(buff, str, 80);
2228 strcat(buff, "¡×¤Ç»Ï¤Þ¤ë¤â¤Î");
2230 strcat(buff, "¡×¤ò´Þ¤à¤â¤Î");
2235 strncat(buff, format("¤Ë¡Ö%s¡×", insc), 80);
2237 if (strstr(insc, "%%all"))
2238 strcat(buff, "(%%all¤ÏÁ´Ç½ÎϤòɽ¤¹±Ñ»ú¤Îµ¹æ¤ÇÃÖ´¹)");
2239 else if (strstr(insc, "%all"))
2240 strcat(buff, "(%all¤ÏÁ´Ç½ÎϤòɽ¤¹µ¹æ¤ÇÃÖ´¹)");
2241 else if (strstr(insc, "%%"))
2242 strcat(buff, "(%%¤ÏÄɲÃǽÎϤòɽ¤¹±Ñ»ú¤Îµ¹æ¤ÇÃÖ´¹)");
2243 else if (strstr(insc, "%"))
2244 strcat(buff, "(%¤ÏÄɲÃǽÎϤòɽ¤¹µ¹æ¤ÇÃÖ´¹)");
2246 strcat(buff, "¤È¹ï¤ó¤Ç");
2251 if (act & DONT_AUTOPICK)
2252 strcat(buff, "ÊüÃÖ¤¹¤ë¡£");
2253 else if (act & DO_AUTODESTROY)
2254 strcat(buff, "Ç˲õ¤¹¤ë¡£");
2255 else if (act & DO_QUERY_AUTOPICK)
2256 strcat(buff, "³Îǧ¤Î¸å¤Ë½¦¤¦¡£");
2258 strcat(buff, "½¦¤¦¡£");
2260 if (act & DO_DISPLAY)
2262 if (act & DONT_AUTOPICK)
2263 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'N'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
2264 else if (act & DO_AUTODESTROY)
2265 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'K'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
2267 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'M'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
2270 strcat(buff, "Á´ÂΥޥåפˤÏɽ¼¨¤·¤Ê¤¤¡£");
2274 cptr before_str[20], after_str[20], which_str[20], whose_str[20], body_str;
2275 int before_n = 0, after_n = 0, which_n = 0, whose_n = 0;
2279 /*** Collecting items ***/
2280 /*** Which can be absorbed into a slot as a bundle ***/
2281 if (IS_FLG(FLG_COLLECTING))
2282 which_str[which_n++] = "can be absorbed into an existing inventory slot";
2284 /*** Unidentified ***/
2285 if (IS_FLG(FLG_UNIDENTIFIED))
2286 before_str[before_n++] = "unidentified";
2288 /*** Identified ***/
2289 if (IS_FLG(FLG_IDENTIFIED))
2290 before_str[before_n++] = "identified";
2292 /*** *Identified* ***/
2293 if (IS_FLG(FLG_STAR_IDENTIFIED))
2294 before_str[before_n++] = "fully identified";
2296 /*** Worthless items ***/
2297 if (IS_FLG(FLG_WORTHLESS))
2299 before_str[before_n++] = "worthless";
2300 which_str[which_n++] = "can not be sold at stores";
2304 if (IS_FLG(FLG_ARTIFACT))
2306 before_str[before_n++] = "artifact";
2310 if (IS_FLG(FLG_EGO))
2312 before_str[before_n++] = "ego";
2316 if (IS_FLG(FLG_NAMELESS))
2318 body_str = "equipment";
2319 which_str[which_n++] = "is neither ego-item nor artifact";
2322 /*** Unaware items ***/
2323 if (IS_FLG(FLG_UNAWARE))
2325 before_str[before_n++] = "unidentified";
2326 whose_str[whose_n++] = "basic abilities are not known";
2329 /*** Dice boosted (weapon of slaying) ***/
2330 if (IS_FLG(FLG_BOOSTED))
2332 body_str = "weapons";
2333 whose_str[whose_n++] = "damage dice is bigger than normal";
2336 /*** Weapons whose dd*ds is more than nn ***/
2337 if (IS_FLG(FLG_MORE_THAN))
2339 static char more_than_desc_str[] =
2340 "maximum damage from dice is bigger than __";
2341 body_str = "weapons";
2343 sprintf(more_than_desc_str + sizeof(more_than_desc_str) - 3,
2345 whose_str[whose_n++] = more_than_desc_str;
2348 /*** Items whose magical bonus is more than nn ***/
2349 if (IS_FLG(FLG_MORE_BONUS))
2351 static char more_bonus_desc_str[] =
2352 "magical bonus is bigger than (+__)";
2354 sprintf(more_bonus_desc_str + sizeof(more_bonus_desc_str) - 4,
2355 "%d)", entry->bonus);
2356 whose_str[whose_n++] = more_bonus_desc_str;
2359 /*** Wanted monster's corpse/skeletons ***/
2360 if (IS_FLG(FLG_WANTED))
2362 body_str = "corpse or skeletons";
2363 which_str[which_n++] = "is wanted at the Hunter's Office";
2366 /*** Human corpse/skeletons (for Daemon magic) ***/
2367 if (IS_FLG(FLG_HUMAN))
2369 before_str[before_n++] = "humanoid";
2370 body_str = "corpse or skeletons";
2371 which_str[which_n++] = "can be used for Daemon magic";
2374 /*** Unique monster's corpse/skeletons/statues ***/
2375 if (IS_FLG(FLG_UNIQUE))
2377 before_str[before_n++] = "unique monster's";
2378 body_str = "corpse or skeletons";
2381 /*** Unreadable spellbooks ***/
2382 if (IS_FLG(FLG_UNREADABLE))
2384 body_str = "spellbooks";
2385 after_str[after_n++] = "of different realms from yours";
2388 /*** First realm spellbooks ***/
2389 if (IS_FLG(FLG_REALM1))
2391 body_str = "spellbooks";
2392 after_str[after_n++] = "of your first realm";
2395 /*** Second realm spellbooks ***/
2396 if (IS_FLG(FLG_REALM2))
2398 body_str = "spellbooks";
2399 after_str[after_n++] = "of your second realm";
2402 /*** First rank spellbooks ***/
2403 if (IS_FLG(FLG_FIRST))
2405 before_str[before_n++] = "first one of four";
2406 body_str = "spellbooks";
2409 /*** Second rank spellbooks ***/
2410 if (IS_FLG(FLG_SECOND))
2412 before_str[before_n++] = "second one of four";
2413 body_str = "spellbooks";
2416 /*** Third rank spellbooks ***/
2417 if (IS_FLG(FLG_THIRD))
2419 before_str[before_n++] = "third one of four";
2420 body_str = "spellbooks";
2423 /*** Fourth rank spellbooks ***/
2424 if (IS_FLG(FLG_FOURTH))
2426 before_str[before_n++] = "fourth one of four";
2427 body_str = "spellbooks";
2431 if (IS_FLG(FLG_ITEMS))
2432 ; /* Nothing to do */
2433 else if (IS_FLG(FLG_WEAPONS))
2434 body_str = "weapons";
2435 else if (IS_FLG(FLG_ARMORS))
2436 body_str = "armors";
2437 else if (IS_FLG(FLG_MISSILES))
2438 body_str = "shots, arrows or crossbow bolts";
2439 else if (IS_FLG(FLG_DEVICES))
2440 body_str = "scrolls, wands, staves or rods";
2441 else if (IS_FLG(FLG_LIGHTS))
2442 body_str = "light sources";
2443 else if (IS_FLG(FLG_JUNKS))
2444 body_str = "junk such as broken sticks";
2445 else if (IS_FLG(FLG_SPELLBOOKS))
2446 body_str = "spellbooks";
2447 else if (IS_FLG(FLG_HAFTED))
2448 body_str = "hafted weapons";
2449 else if (IS_FLG(FLG_SHIELDS))
2450 body_str = "shields";
2451 else if (IS_FLG(FLG_BOWS))
2452 body_str = "slings, bows or crossbows";
2453 else if (IS_FLG(FLG_RINGS))
2455 else if (IS_FLG(FLG_AMULETS))
2456 body_str = "amulets";
2457 else if (IS_FLG(FLG_SUITS))
2458 body_str = "body armors";
2459 else if (IS_FLG(FLG_CLOAKS))
2460 body_str = "cloaks";
2461 else if (IS_FLG(FLG_HELMS))
2462 body_str = "helms or crowns";
2463 else if (IS_FLG(FLG_GLOVES))
2464 body_str = "gloves";
2465 else if (IS_FLG(FLG_BOOTS))
2467 else if (IS_FLG(FLG_FAVORITE))
2468 body_str = "favorite weapons";
2470 /* Prepare a string for item name */
2477 whose_str[whose_n++] = "name is beginning with \"";
2480 which_str[which_n++] = "have \"";
2484 /* Describe action flag */
2485 if (act & DONT_AUTOPICK)
2486 strcpy(buff, "Leave on floor ");
2487 else if (act & DO_AUTODESTROY)
2488 strcpy(buff, "Destroy ");
2489 else if (act & DO_QUERY_AUTOPICK)
2490 strcpy(buff, "Ask to pick up ");
2492 strcpy(buff, "Pickup ");
2494 /* Auto-insctiption */
2497 strncat(buff, format("and inscribe \"%s\"", insc), 80);
2499 if (strstr(insc, "%all"))
2500 strcat(buff, ", replacing %all with code string representing all abilities,");
2501 else if (strstr(insc, "%"))
2502 strcat(buff, ", replacing % with code string representing extra random abilities,");
2504 strcat(buff, " on ");
2509 strcat(buff, "all ");
2510 else for (i = 0; i < before_n && before_str[i]; i++)
2512 strcat(buff, before_str[i]);
2517 strcat(buff, body_str);
2520 for (i = 0; i < after_n && after_str[i]; i++)
2523 strcat(buff, after_str[i]);
2527 for (i = 0; i < whose_n && whose_str[i]; i++)
2530 strcat(buff, " whose ");
2532 strcat(buff, ", and ");
2534 strcat(buff, whose_str[i]);
2537 /* Item name ; whose name is beginning with "str" */
2544 /* whose ..., and which .... */
2545 if (whose_n && which_n)
2546 strcat(buff, ", and ");
2549 for (i = 0; i < which_n && which_str[i]; i++)
2552 strcat(buff, " which ");
2554 strcat(buff, ", and ");
2556 strcat(buff, which_str[i]);
2559 /* Item name ; which have "str" as part of its name */
2562 strncat(buff, str, 80);
2563 strcat(buff, "\" as part of its name");
2567 /* Describe whether it will be displayed on the full map or not */
2568 if (act & DO_DISPLAY)
2570 if (act & DONT_AUTOPICK)
2571 strcat(buff, " Display these items when you press the N key in the full 'M'ap.");
2572 else if (act & DO_AUTODESTROY)
2573 strcat(buff, " Display these items when you press the K key in the full 'M'ap.");
2575 strcat(buff, " Display these items when you press the M key in the full 'M'ap.");
2578 strcat(buff, " Not displayed in the full map.");
2585 * Read whole lines of a file to memory
2587 static cptr *read_text_lines(cptr filename, bool user)
2589 cptr *lines_list = NULL;
2597 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2601 path_build(buf, sizeof(buf), ANGBAND_DIR_PREF, filename);
2605 fff = my_fopen(buf, "r");
2609 /* Allocate list of pointers */
2610 C_MAKE(lines_list, MAX_LINES, cptr);
2613 while (0 == my_fgets(fff, buf, sizeof(buf)))
2615 lines_list[lines++] = string_make(buf);
2616 if (lines >= MAX_LINES - 1) break;
2619 lines_list[0] = string_make("");
2624 if (!fff) return NULL;
2629 static cptr *read_pickpref_text_lines(int *filename_mode_p)
2634 *filename_mode_p = PT_WITH_PNAME;
2635 strcpy(buf, pickpref_filename(*filename_mode_p));
2636 lines_list = read_text_lines(buf, TRUE);
2640 *filename_mode_p = PT_DEFAULT;
2641 strcpy(buf, pickpref_filename(*filename_mode_p));
2642 lines_list = read_text_lines(buf, TRUE);
2647 strcpy(buf, pickpref_filename(*filename_mode_p));
2648 lines_list = read_text_lines(buf, FALSE);
2653 /* Allocate list of pointers */
2654 C_MAKE(lines_list, MAX_LINES, cptr);
2655 lines_list[0] = string_make("");
2662 * Write whole lines of memory to a file.
2664 static bool write_text_lines(cptr filename, cptr *lines_list)
2671 /* Build the filename */
2672 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2675 fff = my_fopen(buf, "w");
2678 for (lines = 0; lines_list[lines]; lines++)
2679 my_fputs(fff, lines_list[lines], 1024);
2684 if (!fff) return FALSE;
2690 * Free memory of lines_list.
2692 static void free_text_lines(cptr *lines_list)
2696 for (lines = 0; lines_list[lines]; lines++)
2697 string_free(lines_list[lines]);
2699 /* free list of pointers */
2700 C_FREE((char **)lines_list, MAX_LINES, char *);
2705 * Delete or insert string
2707 static void toggle_keyword(text_body_type *tb, int flg)
2709 int by1, by2, bx1, bx2, y;
2713 /* Select this line */
2720 if (tb->my < tb->cy)
2735 /* String on these lines are not really selected */
2736 if (tb->lines_list[by1][bx1] == '\0' && by1 < tb->cy) by1++;
2737 if (bx2 == 0 && by1 < by2) by2--;
2740 /* Set/Reset flag of each line */
2741 for (y = by1; y <= by2; y++)
2743 autopick_type an_entry, *entry = &an_entry;
2745 if (!autopick_new_entry(entry, tb->lines_list[y], !fixed)) continue;
2747 string_free(tb->lines_list[y]);
2751 /* Add? or Remove? */
2752 if (!IS_FLG(flg)) add = TRUE;
2755 /* No more change */
2759 /* You can use only one noun flag */
2760 if (FLG_NOUN_BEGIN <= flg && flg <= FLG_NOUN_END)
2763 for (i = FLG_NOUN_BEGIN; i <= FLG_NOUN_END; i++)
2767 /* You can use only one identify state flag */
2768 else if (FLG_UNAWARE <= flg && flg <= FLG_STAR_IDENTIFIED)
2771 for (i = FLG_UNAWARE; i <= FLG_STAR_IDENTIFIED; i++)
2775 /* You can use only one flag in artifact/ego/nameless */
2776 else if (FLG_ARTIFACT <= flg && flg <= FLG_NAMELESS)
2779 for (i = FLG_ARTIFACT; i <= FLG_NAMELESS; i++)
2783 if (add) ADD_FLG(flg);
2786 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
2789 tb->dirty_flags |= DIRTY_ALL;
2791 /* Text is changed */
2798 * Change command letter
2800 static void toggle_command_letter(text_body_type *tb, byte flg)
2802 autopick_type an_entry, *entry = &an_entry;
2803 int by1, by2, bx1, bx2, y;
2807 /* Select this line */
2814 if (tb->my < tb->cy)
2829 /* String on these lines are not really selected */
2830 if (tb->lines_list[by1][bx1] == '\0' && by1 < tb->cy) by1++;
2831 if (bx2 == 0 && by1 < by2) by2--;
2833 /* Set/Reset flag of each line */
2834 for (y = by1; y <= by2; y++)
2838 if (!autopick_new_entry(entry, tb->lines_list[y], FALSE)) continue;
2840 string_free(tb->lines_list[y]);
2844 /* Add? or Remove? */
2845 if (!(entry->action & flg)) add = TRUE;
2848 /* No more change */
2852 /* Count number of letter (by negative number) */
2853 if (entry->action & DONT_AUTOPICK) wid--;
2854 else if (entry->action & DO_AUTODESTROY) wid--;
2855 else if (entry->action & DO_QUERY_AUTOPICK) wid--;
2856 if (!(entry->action & DO_DISPLAY)) wid--;
2858 /* Set/Reset the flag */
2859 if (flg != DO_DISPLAY)
2861 entry->action &= ~(DO_AUTOPICK | DONT_AUTOPICK | DO_AUTODESTROY | DO_QUERY_AUTOPICK);
2862 if (add) entry->action |= flg;
2863 else entry->action |= DO_AUTOPICK;
2867 entry->action &= ~(DO_DISPLAY);
2868 if (add) entry->action |= flg;
2871 /* Correct cursor location */
2874 if (entry->action & DONT_AUTOPICK) wid++;
2875 else if (entry->action & DO_AUTODESTROY) wid++;
2876 else if (entry->action & DO_QUERY_AUTOPICK) wid++;
2877 if (!(entry->action & DO_DISPLAY)) wid++;
2879 if (wid > 0) tb->cx++;
2880 if (wid < 0 && tb->cx > 0) tb->cx--;
2883 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
2886 tb->dirty_flags |= DIRTY_ALL;
2888 /* Text is changed */
2894 * Delete or insert string
2896 static void add_keyword(text_body_type *tb, int flg)
2898 int by1, by2, bx1, bx2, y;
2900 /* Select this line */
2907 if (tb->my < tb->cy)
2922 /* String on these lines are not really selected */
2923 if (tb->lines_list[by1][bx1] == '\0' && by1 < tb->cy) by1++;
2924 if (bx2 == 0 && by1 < by2) by2--;
2926 /* Set/Reset flag of each line */
2927 for (y = by1; y <= by2; y++)
2929 autopick_type an_entry, *entry = &an_entry;
2931 if (!autopick_new_entry(entry, tb->lines_list[y], FALSE)) continue;
2933 /* There is the flag already */
2936 /* Free memory for the entry */
2937 autopick_free_entry(entry);
2942 string_free(tb->lines_list[y]);
2944 /* Remove all noun flag */
2945 if (FLG_NOUN_BEGIN <= flg && flg <= FLG_NOUN_END)
2948 for (i = FLG_NOUN_BEGIN; i <= FLG_NOUN_END; i++)
2954 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
2957 tb->dirty_flags |= DIRTY_ALL;
2959 /* Text is changed */
2966 * Check if this line is expression or not.
2967 * And update it if it is.
2969 static void check_expression_line(text_body_type *tb, int y)
2971 cptr s = tb->lines_list[y];
2973 if ((s[0] == '?' && s[1] == ':') ||
2974 (tb->states[y] & LSTAT_BYPASS))
2976 /* Expressions need re-evaluation */
2977 tb->dirty_flags |= DIRTY_EXPRESSION;
2983 * Insert return code and split the line
2985 static bool insert_return_code(text_body_type *tb)
2987 char buf[MAX_LINELEN];
2990 for (k = 0; tb->lines_list[k]; k++)
2991 /* count number of lines */ ;
2993 if (k >= MAX_LINES - 2) return FALSE;
2996 /* Move down lines */
2997 for (; tb->cy < k; k--)
2999 tb->lines_list[k+1] = tb->lines_list[k];
3000 tb->states[k+1] = tb->states[k];
3003 /* Split current line */
3004 for (i = j = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
3007 if (iskanji(tb->lines_list[tb->cy][i]))
3008 buf[j++] = tb->lines_list[tb->cy][i++];
3010 buf[j++] = tb->lines_list[tb->cy][i];
3013 tb->lines_list[tb->cy+1] = string_make(&tb->lines_list[tb->cy][i]);
3014 string_free(tb->lines_list[tb->cy]);
3015 tb->lines_list[tb->cy] = string_make(buf);
3017 /* Expressions need re-evaluation */
3018 tb->dirty_flags |= DIRTY_EXPRESSION;
3020 /* Text is changed */
3028 * Choose an item and get auto-picker entry from it.
3030 static object_type *choose_object(cptr q, cptr s)
3034 if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR | USE_EQUIP))) return NULL;
3036 /* Get the item (in the pack) */
3037 if (item >= 0) return &inventory[item];
3039 /* Get the item (on the floor) */
3040 else return &o_list[0 - item];
3045 * Choose an item and get auto-picker entry from it.
3047 static bool entry_from_choosed_object(autopick_type *entry)
3054 q = "¤É¤Î¥¢¥¤¥Æ¥à¤òÅÐÏ¿¤·¤Þ¤¹¤«? ";
3055 s = "¥¢¥¤¥Æ¥à¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£";
3057 q = "Enter which item? ";
3058 s = "You have nothing to enter.";
3060 o_ptr = choose_object(q, s);
3061 if (!o_ptr) return FALSE;
3063 autopick_entry_from_object(entry, o_ptr);
3069 * Choose an item for search
3071 static byte get_object_for_search(object_type **o_handle, cptr *search_strp)
3073 char buf[MAX_NLEN+20];
3079 q = "¤É¤Î¥¢¥¤¥Æ¥à¤ò¸¡º÷¤·¤Þ¤¹¤«? ";
3080 s = "¥¢¥¤¥Æ¥à¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£";
3082 q = "Enter which item? ";
3083 s = "You have nothing to enter.";
3085 o_ptr = choose_object(q, s);
3086 if (!o_ptr) return 0;
3090 string_free(*search_strp);
3091 object_desc(buf, *o_handle, FALSE, 3);
3092 *search_strp = string_make(format("<%s>", buf));
3098 * Prepare for search by destroyed object
3100 static byte get_destroyed_object_for_search(object_type **o_handle, cptr *search_strp)
3102 char buf[MAX_NLEN+20];
3104 if (!autopick_last_destroyed_object.k_idx) return 0;
3106 *o_handle = &autopick_last_destroyed_object;
3108 string_free(*search_strp);
3109 object_desc(buf, *o_handle, FALSE, 3);
3110 *search_strp = string_make(format("<%s>", buf));
3116 * Choose an item or string for search
3118 static byte get_string_for_search(object_type **o_handle, cptr *search_strp)
3124 * TERM_YELLOW : Overwrite mode
3125 * TERM_WHITE : Insert mode
3127 byte color = TERM_YELLOW;
3128 char buf[MAX_NLEN+20];
3129 const size_t len = 80;
3132 char prompt[] = "¸¡º÷(^I:»ý¤Áʪ ^L:Ç˲õ¤µ¤ì¤¿Êª): ";
3134 char prompt[] = "Search key(^I:inven ^L:destroyed): ";
3136 int col = sizeof(prompt) - 1;
3138 if (*search_strp) strcpy(buf, *search_strp);
3141 /* Display prompt */
3151 /* Display the string */
3152 Term_erase(col, 0, 255);
3153 Term_putstr(col, 0, -1, color, buf);
3156 Term_gotoxy(col + pos, 0);
3158 /* Get a special key code */
3159 skey = inkey_special();
3161 /* Analyze the key */
3169 /* Now on insert mode */
3172 /* No move at biggining of line */
3173 if (0 == pos) break;
3177 int next_pos = i + 1;
3180 if (iskanji(buf[next_pos])) next_pos++;
3183 /* Is there the cursor at next position? */
3184 if (next_pos >= pos) break;
3190 /* Get previous position */
3198 /* Now on insert mode */
3201 /* No move at end of line */
3202 if ('\0' == buf[pos]) break;
3206 if (iskanji(buf[pos])) pos += 2;
3224 if (!pos && *o_handle) return (back ? -1 : 1);
3225 string_free(*search_strp);
3226 *search_strp = string_make(buf);
3228 return (back ? -1 : 1);
3232 return get_object_for_search(o_handle, search_strp);
3235 /* Prepare string for destroyed object if there is one. */
3236 if (get_destroyed_object_for_search(o_handle, search_strp))
3243 /* Now on insert mode */
3246 /* No move at biggining of line */
3249 /* Go left 1 unit */
3252 /* Fall through to 'Delete key' */
3260 /* Now on insert mode */
3263 /* Position of next character */
3267 /* Next character is one more byte away */
3268 if (iskanji(src)) src++;
3273 /* Move characters at src to dst */
3274 while ('\0' != (buf[dst++] = buf[src++]))
3282 /* Insert a character */
3287 /* Ignore special keys */
3288 if (skey & SKEY_MASK) break;
3290 /* Get a character code */
3293 if (color == TERM_YELLOW)
3295 /* Overwrite default string */
3298 /* Go to insert mode */
3302 /* Save right part of string */
3303 strcpy(tmp, buf + pos);
3309 /* Bypass macro processing */
3327 if (pos < len && (isprint(c) || iskana(c)))
3329 if (pos < len && isprint(c))
3343 /* Write back the left part of string */
3344 my_strcat(buf, tmp, len + 1);
3351 } /* while (TRUE) */
3356 * Search next line matches for o_ptr
3358 static bool search_for_object(text_body_type *tb, object_type *o_ptr, bool forward)
3361 autopick_type an_entry, *entry = &an_entry;
3362 char o_name[MAX_NLEN];
3364 object_desc(o_name, o_ptr, FALSE, 3);
3366 /* Force to be lower case string */
3367 for (i = 0; o_name[i]; i++)
3370 if (iskanji(o_name[i]))
3374 if (isupper(o_name[i]))
3375 o_name[i] = tolower(o_name[i]);
3384 if (!tb->lines_list[++i]) break;
3391 /* Ignore bypassed lines */
3392 if (tb->states[i] & LSTAT_BYPASS) continue;
3394 if (!autopick_new_entry(entry, tb->lines_list[i], FALSE)) continue;
3396 if (is_autopick_aux(o_ptr, entry, o_name))
3409 * Search next line matches to the string
3411 static bool search_for_string(text_body_type *tb, cptr search_str, bool forward)
3421 if (!tb->lines_list[++i]) break;
3428 /* Ignore bypassed lines */
3429 if (tb->states[i] & LSTAT_BYPASS) continue;
3432 pos = strstr_j(tb->lines_list[i], search_str);
3434 pos = strstr(tb->lines_list[i], search_str);
3438 tb->cx = (int)(pos - tb->lines_list[i]);
3451 * Editor command id's
3454 #define EC_SAVEQUIT 2
3465 #define EC_PGDOWN 13
3467 #define EC_BOTTOM 15
3472 #define EC_KILL_LINE 20
3473 #define EC_DELETE_CHAR 21
3474 #define EC_BACKSPACE 22
3475 #define EC_SEARCH_STR 23
3476 #define EC_SEARCH_FORW 24
3477 #define EC_SEARCH_BACK 25
3478 #define EC_SEARCH_OBJ 26
3479 #define EC_SEARCH_DESTROYED 27
3480 #define EC_INSERT_OBJECT 28
3481 #define EC_INSERT_DESTROYED 29
3482 #define EC_INSERT_BLOCK 30
3483 #define EC_INSERT_MACRO 31
3484 #define EC_INSERT_KEYMAP 32
3485 #define EC_CL_AUTOPICK 33
3486 #define EC_CL_DESTROY 34
3487 #define EC_CL_LEAVE 35
3488 #define EC_CL_QUERY 36
3489 #define EC_CL_NO_DISP 37
3490 #define EC_OK_COLLECTING 38
3491 #define EC_IK_UNAWARE 39
3492 #define EC_IK_UNIDENTIFIED 40
3493 #define EC_IK_IDENTIFIED 41
3494 #define EC_IK_STAR_IDENTIFIED 42
3495 #define EC_OK_BOOSTED 43
3496 #define EC_OK_MORE_THAN 44
3497 #define EC_OK_MORE_BONUS 45
3498 #define EC_OK_WORTHLESS 46
3499 #define EC_OK_ARTIFACT 47
3500 #define EC_OK_EGO 48
3501 #define EC_OK_NAMELESS 49
3502 #define EC_OK_WANTED 50
3503 #define EC_OK_UNIQUE 51
3504 #define EC_OK_HUMAN 52
3505 #define EC_OK_UNREADABLE 53
3506 #define EC_OK_REALM1 54
3507 #define EC_OK_REALM2 55
3508 #define EC_OK_FIRST 56
3509 #define EC_OK_SECOND 57
3510 #define EC_OK_THIRD 58
3511 #define EC_OK_FOURTH 59
3512 #define EC_KK_WEAPONS 60
3513 #define EC_KK_FAVORITE 61
3514 #define EC_KK_ARMORS 62
3515 #define EC_KK_MISSILES 63
3516 #define EC_KK_DEVICES 64
3517 #define EC_KK_LIGHTS 65
3518 #define EC_KK_JUNKS 66
3519 #define EC_KK_SPELLBOOKS 67
3520 #define EC_KK_SHIELDS 68
3521 #define EC_KK_BOWS 69
3522 #define EC_KK_RINGS 70
3523 #define EC_KK_AMULETS 71
3524 #define EC_KK_SUITS 72
3525 #define EC_KK_CLOAKS 73
3526 #define EC_KK_HELMS 74
3527 #define EC_KK_GLOVES 75
3528 #define EC_KK_BOOTS 76
3534 #define MN_QUIT "¥»¡¼¥Ö̵¤·¤Ç½ªÎ»"
3535 #define MN_SAVEQUIT "¥»¡¼¥Ö¤·¤Æ½ªÎ»"
3536 #define MN_REVERT "Á´¤Æ¤ÎÊѹ¹¤òÇË´þ"
3537 #define MN_HELP "¥Ø¥ë¥×"
3539 #define MN_MOVE "¥«¡¼¥½¥ë°ÜÆ°"
3540 #define MN_LEFT "º¸"
3541 #define MN_DOWN "²¼"
3543 #define MN_RIGHT "±¦"
3544 #define MN_BOL "¹Ô¤ÎÀèƬ"
3545 #define MN_EOL "¹Ô¤Î½ªÃ¼"
3546 #define MN_PGUP "¾å¤Î¥Ú¡¼¥¸"
3547 #define MN_PGDOWN "²¼¤Î¥Ú¡¼¥¸"
3548 #define MN_TOP "1¹ÔÌܤذÜÆ°"
3549 #define MN_BOTTOM "ºÇ²¼¹Ô¤Ø°ÜÆ°"
3551 #define MN_EDIT "ÊÔ½¸"
3552 #define MN_CUT "¥«¥Ã¥È"
3553 #define MN_COPY "¥³¥Ô¡¼"
3554 #define MN_PASTE "¥Ú¡¼¥¹¥È"
3555 #define MN_BLOCK "ÁªÂòÈϰϤλØÄê"
3556 #define MN_KILL_LINE "¹Ô¤Î»Ä¤ê¤òºï½ü"
3557 #define MN_DELETE_CHAR "1ʸ»úºï½ü"
3558 #define MN_BACKSPACE "¥Ð¥Ã¥¯¥¹¥Ú¡¼¥¹"
3559 #define MN_RETURN "²þ¹Ô"
3560 #define MN_RETURN "²þ¹Ô"
3562 #define MN_SEARCH "¸¡º÷"
3563 #define MN_SEARCH_STR "ʸ»úÎó¤Ç¸¡º÷"
3564 #define MN_SEARCH_FORW "Á°Êý¤ØºÆ¸¡º÷"
3565 #define MN_SEARCH_BACK "¸åÊý¤ØºÆ¸¡º÷"
3566 #define MN_SEARCH_OBJ "¥¢¥¤¥Æ¥à¤òÁªÂò¤·¤Æ¸¡º÷"
3567 #define MN_SEARCH_DESTROYED "¼«Æ°Ç˲õ¤µ¤ì¤¿¥¢¥¤¥Æ¥à¤Ç¸¡º÷"
3569 #define MN_INSERT "¿§¡¹ÁÞÆþ"
3570 #define MN_INSERT_OBJECT "ÁªÂò¤·¤¿¥¢¥¤¥Æ¥à¤Î̾Á°¤òÁÞÆþ"
3571 #define MN_INSERT_DESTROYED "¼«Æ°Ç˲õ¤µ¤ì¤¿¥¢¥¤¥Æ¥à¤Î̾Á°¤òÁÞÆþ"
3572 #define MN_INSERT_BLOCK "¾ò·ïʬ´ô¥Ö¥í¥Ã¥¯¤ÎÎã¤òÁÞÆþ"
3573 #define MN_INSERT_MACRO "¥Þ¥¯¥íÄêµÁ¤òÁÞÆþ"
3574 #define MN_INSERT_KEYMAP "¥¡¼¥Þ¥Ã¥×ÄêµÁ¤òÁÞÆþ"
3576 #define MN_COMMAND_LETTER "½¦¤¤/Ç˲õ/ÊüÃÖ¤ÎÁªÂò"
3577 #define MN_CL_AUTOPICK "¡Ö ¡× (¼«Æ°½¦¤¤)"
3578 #define MN_CL_DESTROY "¡Ö!¡× (¼«Æ°Ç˲õ)"
3579 #define MN_CL_LEAVE "¡Ö~¡× (ÊüÃÖ)"
3580 #define MN_CL_QUERY "¡Ö;¡× (³Îǧ¤·¤Æ½¦¤¦)"
3581 #define MN_CL_NO_DISP "¡Ö(¡× (¥Þ¥Ã¥×¥³¥Þ¥ó¥É¤Çɽ¼¨¤·¤Ê¤¤)"
3583 #define MN_ADJECTIVE_GEN "·ÁÍÆ»ì(°ìÈÌ)¤ÎÁªÂò"
3585 #define MN_ADJECTIVE_SPECIAL "·ÁÍÆ»ì(Æüì)¤ÎÁªÂò"
3586 #define MN_BOOSTED "¥À¥¤¥¹Ìܤΰ㤦 (Éð´ï)"
3587 #define MN_MORE_THAN "¥À¥¤¥¹ÌÜ # °Ê¾å¤Î (Éð´ï)"
3588 #define MN_MORE_BONUS "½¤ÀµÃÍ # °Ê¾å¤Î (»ØÎØÅù)"
3589 #define MN_ARTIFACT "¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È (ÁõÈ÷)"
3590 #define MN_EGO "¥¨¥´ (ÁõÈ÷)"
3591 #define MN_NAMELESS "̵ÌäΠ(ÁõÈ÷)"
3592 #define MN_WANTED "¾Þ¶â¼ó¤Î (»àÂÎ)"
3593 #define MN_UNIQUE "¥æ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼¤Î (»àÂÎ)"
3594 #define MN_HUMAN "¿Í´Ö¤Î (»àÂÎ)"
3595 #define MN_UNREADABLE "Æɤá¤Ê¤¤ (ËâË¡½ñ)"
3596 #define MN_REALM1 "Âè°ìÎΰè¤Î (ËâË¡½ñ)"
3597 #define MN_REALM2 "ÂèÆóÎΰè¤Î (ËâË¡½ñ)"
3598 #define MN_FIRST "1ºýÌܤΠ(ËâË¡½ñ)"
3599 #define MN_SECOND "2ºýÌܤΠ(ËâË¡½ñ)"
3600 #define MN_THIRD "3ºýÌܤΠ(ËâË¡½ñ)"
3601 #define MN_FOURTH "4ºýÌܤΠ(ËâË¡½ñ)"
3603 #define MN_NOUN "̾»ì¤ÎÁªÂò"
3607 #define MN_QUIT "Quit without save"
3608 #define MN_SAVEQUIT "Save & Quit"
3609 #define MN_REVERT "Revert all changes"
3610 #define MN_HELP "Help"
3612 #define MN_MOVE "Move cursor"
3613 #define MN_LEFT "Left"
3614 #define MN_DOWN "Down"
3616 #define MN_RIGHT "Right"
3617 #define MN_BOL "Beggining of line"
3618 #define MN_EOL "End of line"
3619 #define MN_PGUP "Page up"
3620 #define MN_PGDOWN "Page down"
3621 #define MN_TOP "Top"
3622 #define MN_BOTTOM "Bottom"
3624 #define MN_EDIT "Edit"
3625 #define MN_CUT "Cut"
3626 #define MN_COPY "Copy"
3627 #define MN_PASTE "Paste"
3628 #define MN_BLOCK "Select block"
3629 #define MN_KILL_LINE "Kill rest of line"
3630 #define MN_DELETE_CHAR "Delete character"
3631 #define MN_BACKSPACE "Backspace"
3632 #define MN_RETURN "Return"
3633 #define MN_RETURN "Return"
3635 #define MN_SEARCH "Search"
3636 #define MN_SEARCH_STR "Search by string"
3637 #define MN_SEARCH_FORW "Search forward"
3638 #define MN_SEARCH_BACK "Search backward"
3639 #define MN_SEARCH_OBJ "Search by inventory object"
3640 #define MN_SEARCH_DESTROYED "Search by destroyed object"
3642 #define MN_INSERT "Insert..."
3643 #define MN_INSERT_OBJECT "Insert name of choosen object"
3644 #define MN_INSERT_DESTROYED "Insert name of destroyed object"
3645 #define MN_INSERT_BLOCK "Insert conditional block"
3646 #define MN_INSERT_MACRO "Insert a macro definition"
3647 #define MN_INSERT_KEYMAP "Insert a keymap definition"
3649 #define MN_COMMAND_LETTER "Command letter"
3650 #define MN_CL_AUTOPICK "' ' (Auto pick)"
3651 #define MN_CL_DESTROY "'!' (Auto destroy)"
3652 #define MN_CL_LEAVE "'~' (Leave it on the floor)"
3653 #define MN_CL_QUERY "';' (Query to pick up)"
3654 #define MN_CL_NO_DISP "'(' (No display on the large map)"
3656 #define MN_ADJECTIVE_GEN "Adjective (general)"
3658 #define MN_ADJECTIVE_SPECIAL "Adjective (special)"
3659 #define MN_BOOSTED "dice boosted (weapons)"
3660 #define MN_MORE_THAN "more than # dice (weapons)"
3661 #define MN_MORE_BONUS "more bonus than # (rings etc.)"
3662 #define MN_ARTIFACT "artifact (equipments)"
3663 #define MN_EGO "ego (equipments)"
3664 #define MN_NAMELESS "nameless (equipments)"
3665 #define MN_WANTED "wanted (corpse)"
3666 #define MN_UNIQUE "unique (corpse)"
3667 #define MN_HUMAN "human (corpse)"
3668 #define MN_UNREADABLE "unreadable (spellbooks)"
3669 #define MN_REALM1 "realm1 (spellbooks)"
3670 #define MN_REALM2 "realm2 (spellbooks)"
3671 #define MN_FIRST "first (spellbooks)"
3672 #define MN_SECOND "second (spellbooks)"
3673 #define MN_THIRD "third (spellbooks)"
3674 #define MN_FOURTH "fourth (spellbooks)"
3676 #define MN_NOUN "Keywords (noun)"
3686 } command_menu_type;
3689 command_menu_type menu_data[] =
3691 {MN_HELP, 0, -1, EC_HELP},
3692 {MN_QUIT, 0, KTRL('q'), EC_QUIT},
3693 {MN_SAVEQUIT, 0, KTRL('w'), EC_SAVEQUIT},
3694 {MN_REVERT, 0, KTRL('z'), EC_REVERT},
3696 {MN_EDIT, 0, -1, -1},
3697 {MN_CUT, 1, KTRL('x'), EC_CUT},
3698 {MN_COPY, 1, KTRL('c'), EC_COPY},
3699 {MN_PASTE, 1, KTRL('v'), EC_PASTE},
3700 {MN_BLOCK, 1, KTRL('g'), EC_BLOCK},
3701 {MN_KILL_LINE, 1, KTRL('k'), EC_KILL_LINE},
3702 {MN_DELETE_CHAR, 1, KTRL('d'), EC_DELETE_CHAR},
3703 {MN_BACKSPACE, 1, KTRL('h'), EC_BACKSPACE},
3704 {MN_RETURN, 1, KTRL('j'), EC_RETURN},
3705 {MN_RETURN, 1, KTRL('m'), EC_RETURN},
3707 {MN_SEARCH, 0, -1, -1},
3708 {MN_SEARCH_STR, 1, KTRL('s'), EC_SEARCH_STR},
3709 {MN_SEARCH_FORW, 1, -1, EC_SEARCH_FORW},
3710 {MN_SEARCH_BACK, 1, KTRL('r'), EC_SEARCH_BACK},
3711 {MN_SEARCH_OBJ, 1, KTRL('y'), EC_SEARCH_OBJ},
3712 {MN_SEARCH_DESTROYED, 1, -1, EC_SEARCH_DESTROYED},
3714 {MN_MOVE, 0, -1, -1},
3715 {MN_LEFT, 1, KTRL('b'), EC_LEFT},
3716 {MN_DOWN, 1, KTRL('n'), EC_DOWN},
3717 {MN_UP, 1, KTRL('p'), EC_UP},
3718 {MN_RIGHT, 1, KTRL('f'), EC_RIGHT},
3719 {MN_BOL, 1, KTRL('a'), EC_BOL},
3720 {MN_EOL, 1, KTRL('e'), EC_EOL},
3721 {MN_PGUP, 1, KTRL('o'), EC_PGUP},
3722 {MN_PGDOWN, 1, KTRL('l'), EC_PGDOWN},
3723 {MN_TOP, 1, KTRL('t'), EC_TOP},
3724 {MN_BOTTOM, 1, KTRL('u'), EC_BOTTOM},
3726 {MN_INSERT, 0, -1, -1},
3727 {MN_INSERT_OBJECT, 1, KTRL('i'), EC_INSERT_OBJECT},
3728 {MN_INSERT_DESTROYED, 1, -1, EC_INSERT_DESTROYED},
3729 {MN_INSERT_BLOCK, 1, -1, EC_INSERT_BLOCK},
3730 {MN_INSERT_MACRO, 1, -1, EC_INSERT_MACRO},
3731 {MN_INSERT_KEYMAP, 1, -1, EC_INSERT_KEYMAP},
3733 {MN_ADJECTIVE_GEN, 0, -1, -1},
3734 {KEY_UNAWARE, 1, -1, EC_IK_UNAWARE},
3735 {KEY_UNIDENTIFIED, 1, -1, EC_IK_UNIDENTIFIED},
3736 {KEY_IDENTIFIED, 1, -1, EC_IK_IDENTIFIED},
3737 {KEY_STAR_IDENTIFIED, 1, -1, EC_IK_STAR_IDENTIFIED},
3738 {KEY_COLLECTING, 1, -1, EC_OK_COLLECTING},
3739 {KEY_WORTHLESS, 1, -1, EC_OK_WORTHLESS},
3741 {MN_ADJECTIVE_SPECIAL, 0, -1, -1},
3742 {MN_BOOSTED, 1, -1, EC_OK_BOOSTED},
3743 {MN_MORE_THAN, 1, -1, EC_OK_MORE_THAN},
3744 {MN_MORE_BONUS, 1, -1, EC_OK_MORE_BONUS},
3745 {MN_ARTIFACT, 1, -1, EC_OK_ARTIFACT},
3746 {MN_EGO, 1, -1, EC_OK_EGO},
3747 {MN_NAMELESS, 1, -1, EC_OK_NAMELESS},
3748 {MN_WANTED, 1, -1, EC_OK_WANTED},
3749 {MN_UNIQUE, 1, -1, EC_OK_UNIQUE},
3750 {MN_HUMAN, 1, -1, EC_OK_HUMAN},
3751 {MN_UNREADABLE, 1, -1, EC_OK_UNREADABLE},
3752 {MN_REALM1, 1, -1, EC_OK_REALM1},
3753 {MN_REALM2, 1, -1, EC_OK_REALM2},
3754 {MN_FIRST, 1, -1, EC_OK_FIRST},
3755 {MN_SECOND, 1, -1, EC_OK_SECOND},
3756 {MN_THIRD, 1, -1, EC_OK_THIRD},
3757 {MN_FOURTH, 1, -1, EC_OK_FOURTH},
3759 {MN_NOUN, 0, -1, -1},
3760 {KEY_WEAPONS, 1, -1, EC_KK_WEAPONS},
3761 {KEY_FAVORITE, 1, -1, EC_KK_FAVORITE},
3762 {KEY_ARMORS, 1, -1, EC_KK_ARMORS},
3763 {KEY_MISSILES, 1, -1, EC_KK_MISSILES},
3764 {KEY_DEVICES, 1, -1, EC_KK_DEVICES},
3765 {KEY_LIGHTS, 1, -1, EC_KK_LIGHTS},
3766 {KEY_JUNKS, 1, -1, EC_KK_JUNKS},
3767 {KEY_SPELLBOOKS, 1, -1, EC_KK_SPELLBOOKS},
3768 {KEY_SHIELDS, 1, -1, EC_KK_SHIELDS},
3769 {KEY_BOWS, 1, -1, EC_KK_BOWS},
3770 {KEY_RINGS, 1, -1, EC_KK_RINGS},
3771 {KEY_AMULETS, 1, -1, EC_KK_AMULETS},
3772 {KEY_SUITS, 1, -1, EC_KK_SUITS},
3773 {KEY_CLOAKS, 1, -1, EC_KK_CLOAKS},
3774 {KEY_HELMS, 1, -1, EC_KK_HELMS},
3775 {KEY_GLOVES, 1, -1, EC_KK_GLOVES},
3776 {KEY_BOOTS, 1, -1, EC_KK_BOOTS},
3778 {MN_COMMAND_LETTER, 0, -1, -1},
3779 {MN_CL_AUTOPICK, 1, -1, EC_CL_AUTOPICK},
3780 {MN_CL_DESTROY, 1, -1, EC_CL_DESTROY},
3781 {MN_CL_LEAVE, 1, -1, EC_CL_LEAVE},
3782 {MN_CL_QUERY, 1, -1, EC_CL_QUERY},
3783 {MN_CL_NO_DISP, 1, -1, EC_CL_NO_DISP},
3785 {MN_DELETE_CHAR, -1, 0x7F, EC_DELETE_CHAR},
3792 * Find a command by 'key'.
3794 static int get_com_id(char key)
3798 for (i = 0; menu_data[i].name; i++)
3800 if (menu_data[i].key == key)
3802 return menu_data[i].com_id;
3811 * Display the menu, and get a command
3813 static int do_command_menu(int level, int start)
3818 int col0 = 5 + level*7;
3819 int row0 = 1 + level*3;
3821 int menu_id_list[26];
3823 char linestr[MAX_LINELEN];
3825 /* Get max length */
3827 for (i = start; menu_data[i].level >= level; i++)
3831 /* Ignore lower level sub menus */
3832 if (menu_data[i].level > level) continue;
3834 len = strlen(menu_data[i].name);
3835 if (len > max_len) max_len = len;
3837 menu_id_list[menu_key] = i;
3841 while (menu_key < 26)
3843 menu_id_list[menu_key] = -1;
3847 /* Extra space for displaying menu key and command key */
3848 max_menu_wid = max_len + 3 + 3;
3850 /* Prepare box line */
3852 strcat(linestr, "+");
3853 for (i = 0; i < max_menu_wid + 2; i++)
3855 strcat(linestr, "-");
3857 strcat(linestr, "+");
3867 int row1 = row0 + 1;
3870 Term_putstr(col0, row0, -1, TERM_WHITE, linestr);
3872 /* Draw menu items */
3874 for (i = start; menu_data[i].level >= level; i++)
3876 char com_key_str[3];
3879 /* Ignore lower level sub menus */
3880 if (menu_data[i].level > level) continue;
3882 if (menu_data[i].com_id == -1)
3885 strcpy(com_key_str, "¢§");
3887 strcpy(com_key_str, ">");
3890 else if (menu_data[i].key != -1)
3892 com_key_str[0] = '^';
3893 com_key_str[1] = menu_data[i].key + '@';
3894 com_key_str[2] = '\0';
3898 com_key_str[0] = '\0';
3901 str = format("| %c) %-*s %2s | ", menu_key + 'a', max_len, menu_data[i].name, com_key_str);
3903 Term_putstr(col0, row1++, -1, TERM_WHITE, str);
3908 /* Draw bottom line */
3909 Term_putstr(col0, row1, -1, TERM_WHITE, linestr);
3911 /* The menu was shown */
3915 prt(format("(a-%c) ¥³¥Þ¥ó¥É:", menu_key + 'a' - 1), 0, 0);
3917 prt(format("(a-%c) Command:", menu_key + 'a' - 1), 0, 0);
3921 if (key == ESCAPE) return 0;
3923 if ('a' <= key && key <= 'z')
3925 menu_id = menu_id_list[key - 'a'];
3929 com_id = menu_data[menu_id].com_id;
3933 com_id = do_command_menu(level + 1, menu_id + 1);
3935 if (com_id) return com_id;
3947 com_id = get_com_id(key);
3948 if (com_id) return com_id;
3955 static chain_str_type *new_chain_str(cptr str)
3957 chain_str_type *chain;
3959 size_t len = strlen(str);
3961 chain = (chain_str_type *)ralloc(sizeof(chain_str_type) + len * sizeof(char));
3963 strcpy(chain->s, str);
3970 static void kill_yank_chain(text_body_type *tb)
3972 chain_str_type *chain = tb->yank;
3974 tb->yank_eol = TRUE;
3978 chain_str_type *next = chain->next;
3979 size_t len = strlen(chain->s);
3981 rnfree(chain, sizeof(chain_str_type) + len * sizeof(char));
3988 static void add_str_to_yank(text_body_type *tb, cptr str)
3990 chain_str_type *chain;
3992 tb->yank_eol = FALSE;
3994 if (NULL == tb->yank)
3996 tb->yank = new_chain_str(str);
4006 chain->next = new_chain_str(str);
4011 chain = chain->next;
4016 #define DESCRIPT_HGT 3
4021 static void draw_text_editor(text_body_type *tb)
4024 int by1 = -1, bx1 = -1, by2 = -1, bx2 = -1;
4027 Term_get_size(&tb->wid, &tb->hgt);
4030 * Top line (-1), description line (-3), separator (-1)
4033 tb->hgt -= 2 + DESCRIPT_HGT;
4036 /* Don't let cursor at second byte of kanji */
4037 for (i = 0; tb->lines_list[tb->cy][i]; i++)
4038 if (iskanji(tb->lines_list[tb->cy][i]))
4049 /* Scroll if necessary */
4050 if (tb->cy < tb->upper || tb->upper + tb->hgt <= tb->cy)
4051 tb->upper = tb->cy - (tb->hgt)/2;
4054 if ((tb->cx < tb->left + 10 && tb->left > 0) || tb->left + tb->wid - 5 <= tb->cx)
4055 tb->left = tb->cx - (tb->wid)*2/3;
4059 /* Redraw whole window after resize */
4060 if (tb->old_wid != tb->wid || tb->old_hgt != tb->hgt)
4061 tb->dirty_flags |= DIRTY_SCREEN;
4063 /* Redraw all text after scroll */
4064 else if (tb->old_upper != tb->upper || tb->old_left != tb->left)
4065 tb->dirty_flags |= DIRTY_ALL;
4068 if (tb->dirty_flags & DIRTY_SCREEN)
4070 tb->dirty_flags |= (DIRTY_ALL | DIRTY_MODE);
4076 /* Redraw mode line */
4077 if (tb->dirty_flags & DIRTY_MODE)
4079 char buf[MAX_LINELEN];
4081 int sepa_length = tb->wid;
4084 for (i = 0; i < sepa_length; i++)
4088 Term_putstr(0, tb->hgt + 1, sepa_length, TERM_WHITE, buf);
4091 if (tb->dirty_flags & DIRTY_EXPRESSION)
4096 for (y = 0; tb->lines_list[y]; y++)
4100 cptr s = tb->lines_list[y];
4102 /* Update this line's state */
4103 tb->states[y] = state;
4105 if (*s++ != '?') continue;
4106 if (*s++ != ':') continue;
4108 /* Lines below this line are auto-registered */
4109 if (streq(s, "$AUTOREGISTER"))
4110 state |= LSTAT_AUTOREGISTER;
4112 /* Parse the expr */
4113 v = process_pref_file_expr(&s, &f);
4116 if (streq(v, "0")) state |= LSTAT_BYPASS;
4117 else state &= ~LSTAT_BYPASS;
4119 /* Re-update this line's state */
4120 tb->states[y] = state | LSTAT_EXPRESSION;
4123 tb->dirty_flags |= DIRTY_ALL;
4128 int tmp_cx = tb->cx;
4129 int len = strlen(tb->lines_list[tb->cy]);
4131 /* Correct cursor location */
4132 if (tb->cx > len) tmp_cx = len;
4134 tb->dirty_flags |= DIRTY_ALL;
4136 if (tb->my < tb->cy ||
4137 (tb->my == tb->cy && tb->mx < tmp_cx))
4153 /* Dump up to tb->hgt lines of messages */
4154 for (i = 0; i < tb->hgt; i++)
4160 int y = tb->upper+i;
4162 /* clean or dirty? */
4163 if (!(tb->dirty_flags & DIRTY_ALL) && (tb->dirty_line != y))
4166 msg = tb->lines_list[y];
4169 /* Apply horizontal scroll */
4170 for (j = 0; *msg; msg++, j++)
4172 if (j == tb->left) break;
4188 Term_erase(0, i + 1, tb->wid);
4190 if (tb->states[y] & LSTAT_AUTOREGISTER)
4192 /* Warning color -- These lines will be deleted later */
4197 /* Bypassed line will be displayed by darker color */
4198 if (tb->states[y] & LSTAT_BYPASS) color = TERM_SLATE;
4199 else color = TERM_WHITE;
4204 /* Dump the messages, bottom to top */
4205 Term_putstr(leftcol, i + 1, tb->wid - 1, color, msg);
4210 int x0 = leftcol + tb->left;
4215 if (by1 <= y && y < by2) sx1 = strlen(msg);
4216 if (y == by1) sx0 = bx1;
4217 if (y == by2) sx1 = bx2;
4219 Term_gotoxy(leftcol, i + 1);
4220 if (x0 < sx0) Term_addstr(sx0 - x0, color, msg);
4221 if (x0 < sx1) Term_addstr(sx1 - sx0, TERM_YELLOW, msg + (sx0 - x0));
4222 Term_addstr(-1, color, msg + (sx1 - x0));
4226 for (; i < tb->hgt; i++)
4229 Term_erase(0, i + 1, tb->wid);
4232 /* Display information when updated */
4233 if (tb->old_cy != tb->cy || (tb->dirty_flags & (DIRTY_ALL | DIRTY_NOT_FOUND | DIRTY_NO_SEARCH)) || tb->dirty_line == tb->cy)
4235 autopick_type an_entry, *entry = &an_entry;
4237 /* Clear information line */
4238 for (i = 0; i < DESCRIPT_HGT; i++)
4241 Term_erase(0, tb->hgt + 2 + i, tb->wid);
4244 /* Display information */
4245 if (tb->dirty_flags & DIRTY_NOT_FOUND)
4248 prt(format("¥Ñ¥¿¡¼¥ó¤¬¸«¤Ä¤«¤ê¤Þ¤»¤ó: %s", tb->search_str), tb->hgt + 1 + 1, 0);
4250 prt(format("Pattern not found: %s", tb->search_str), tb->hgt + 1 + 1, 0);
4253 else if (tb->dirty_flags & DIRTY_NO_SEARCH)
4256 prt("¸¡º÷Ãæ¤Î¥Ñ¥¿¡¼¥ó¤¬¤¢¤ê¤Þ¤»¤ó('/'¤Ç¸¡º÷)¡£", tb->hgt + 1 + 1, 0);
4258 prt("No pattern to search. (Press '/' to search.)", tb->hgt +1 + 1, 0);
4261 else if (tb->lines_list[tb->cy][0] == '#')
4264 prt("¤³¤Î¹Ô¤Ï¥³¥á¥ó¥È¤Ç¤¹¡£", tb->hgt +1 + 1, 0);
4266 prt("This line is a comment.", tb->hgt +1 + 1, 0);
4269 else if (tb->lines_list[tb->cy][1] == ':')
4273 switch(tb->lines_list[tb->cy][0])
4277 str = "¤³¤Î¹Ô¤Ï¾ò·ïʬ´ô¼°¤Ç¤¹¡£";
4279 str = "This line is a Conditional Expression.";
4285 str = "¤³¤Î¹Ô¤Ï¥Þ¥¯¥í¤Î¼Â¹ÔÆâÍƤòÄêµÁ¤·¤Þ¤¹¡£";
4287 str = "This line defines a Macro action.";
4292 str = "¤³¤Î¹Ô¤Ï¥Þ¥¯¥í¤Î¥È¥ê¥¬¡¼¡¦¥¡¼¤òÄêµÁ¤·¤Þ¤¹¡£";
4294 str = "This line defines a Macro trigger key.";
4299 str = "¤³¤Î¹Ô¤Ï¥¡¼ÇÛÃÖ¤òÄêµÁ¤·¤Þ¤¹¡£";
4301 str = "This line defines a Keymap.";
4306 /* Draw the first line */
4307 if (str) prt(str, tb->hgt +1 + 1, 0);
4311 switch(tb->lines_list[tb->cy][0])
4314 if (tb->states[tb->cy] & LSTAT_BYPASS)
4317 str = "¸½ºß¤Î¼°¤ÎÃͤϡֵ¶(=0)¡×¤Ç¤¹¡£";
4319 str = "The expression is 'False'(=0) currently.";
4325 str = "¸½ºß¤Î¼°¤ÎÃͤϡֿ¿(=1)¡×¤Ç¤¹¡£";
4327 str = "The expression is 'True'(=1) currently.";
4333 if (tb->states[tb->cy] & LSTAT_AUTOREGISTER)
4336 str = "¤³¤Î¹Ô¤Ï¸å¤Çºï½ü¤µ¤ì¤Þ¤¹¡£";
4338 str = "This line will be delete later.";
4342 else if (tb->states[tb->cy] & LSTAT_BYPASS)
4345 str = "¤³¤Î¹Ô¤Ï¸½ºß¤Ï̵¸ú¤Ê¾õÂ֤Ǥ¹¡£";
4347 str = "This line is bypassed currently.";
4353 /* Draw the second line */
4354 if (str) prt(str, tb->hgt +1 + 2, 0);
4357 /* Get description of an autopicker preference line */
4358 else if (autopick_new_entry(entry, tb->lines_list[tb->cy], FALSE))
4360 char buf[MAX_LINELEN];
4361 char temp[MAX_LINELEN];
4364 describe_autopick(buf, entry);
4366 if (tb->states[tb->cy] & LSTAT_AUTOREGISTER)
4369 strcat(buf, "¤³¤Î¹Ô¤Ï¸å¤Çºï½ü¤µ¤ì¤Þ¤¹¡£");
4371 strcat(buf, " This line will be delete later.");
4375 if (tb->states[tb->cy] & LSTAT_BYPASS)
4378 strcat(buf, "¤³¤Î¹Ô¤Ï¸½ºß¤Ï̵¸ú¤Ê¾õÂ֤Ǥ¹¡£");
4380 strcat(buf, " This line is bypassed currently.");
4384 roff_to_buf(buf, 81, temp, sizeof(temp));
4386 for (i = 0; i < 3; i++)
4392 prt(t, tb->hgt +1 + 1 + i, 0);
4396 autopick_free_entry(entry);
4403 * Kill segment of a line
4405 static void kill_line_segment(text_body_type *tb, int y, int x0, int x1, bool whole)
4407 char buf[MAX_LINELEN];
4408 cptr s = tb->lines_list[y];
4413 if (x0 == x1) return;
4415 /* Kill whole line? */
4416 if (whole && x0 == 0 && s[x1] == '\0' && tb->lines_list[y+1])
4420 string_free(tb->lines_list[y]);
4422 /* Shift lines up */
4423 for (i = y; tb->lines_list[i+1]; i++)
4424 tb->lines_list[i] = tb->lines_list[i+1];
4425 tb->lines_list[i] = NULL;
4427 /* Expressions need re-evaluation */
4428 tb->dirty_flags |= DIRTY_EXPRESSION;
4433 /* Before the segment */
4434 for (x = 0; x < x0; x++)
4437 /* After the segment */
4438 for (x = x1; s[x]; x++)
4444 string_free(tb->lines_list[y]);
4445 tb->lines_list[y] = string_make(buf);
4447 /* Expressions may need re-evaluation */
4448 check_expression_line(tb, y);
4450 /* Text is changed */
4456 * Get a trigger key and insert ASCII string for the trigger
4458 static bool insert_macro_line(text_body_type *tb)
4467 /* Do not process macros */
4473 /* Read the pattern */
4479 /* Do not process macros */
4482 /* Do not wait for keys */
4485 /* Attempt to read a key */
4495 /* Convert the trigger */
4496 ascii_to_text(tmp, buf);
4499 if(!tmp[0]) return FALSE;
4503 /* Insert preference string */
4504 insert_return_code(tb);
4505 string_free(tb->lines_list[tb->cy]);
4506 tb->lines_list[tb->cy] = string_make(format("P:%s", tmp));
4508 /* Acquire action */
4509 i = macro_find_exact(buf);
4513 /* Nothing defined */
4518 /* Analyze the current action */
4519 ascii_to_text(tmp, macro__act[i]);
4522 /* Insert blank action preference line */
4523 insert_return_code(tb);
4524 string_free(tb->lines_list[tb->cy]);
4525 tb->lines_list[tb->cy] = string_make(format("A:%s", tmp));
4532 * Get a command key and insert ASCII string for the key
4534 static bool insert_keymap_line(text_body_type *tb)
4542 if (rogue_like_commands)
4544 mode = KEYMAP_MODE_ROGUE;
4550 mode = KEYMAP_MODE_ORIG;
4563 /* Convert the trigger */
4564 ascii_to_text(tmp, buf);
4567 if(!tmp[0]) return FALSE;
4571 /* Insert preference string */
4572 insert_return_code(tb);
4573 string_free(tb->lines_list[tb->cy]);
4574 tb->lines_list[tb->cy] = string_make(format("C:%d:%s", mode, tmp));
4576 /* Look up the keymap */
4577 act = keymap_act[mode][(byte)(buf[0])];
4579 /* Insert blank action preference line */
4580 insert_return_code(tb);
4581 string_free(tb->lines_list[tb->cy]);
4582 tb->lines_list[tb->cy] = string_make(format("A:%s", act));
4589 * Execute a single editor command
4591 static bool do_editor_command(text_body_type *tb, int com_id)
4599 if (!get_check("Á´¤Æ¤ÎÊѹ¹¤òÇË´þ¤·¤Æ¤«¤é½ªÎ»¤·¤Þ¤¹¡£¤è¤í¤·¤¤¤Ç¤¹¤«¡© ")) break;
4601 if (!get_check("Discard all changes and quit. Are you sure? ")) break;
4604 return QUIT_WITHOUT_SAVE;
4607 return QUIT_AND_SAVE;
4610 /* Revert to original */
4612 if (!get_check("Á´¤Æ¤ÎÊѹ¹¤òÇË´þ¤·¤Æ¸µ¤Î¾õÂÖ¤ËÌᤷ¤Þ¤¹¡£¤è¤í¤·¤¤¤Ç¤¹¤«¡© ")) break;
4614 if (!get_check("Discard all changes and revert to original file. Are you sure? ")) break;
4617 free_text_lines(tb->lines_list);
4618 tb->lines_list = read_pickpref_text_lines(&tb->filename_mode);
4619 tb->dirty_flags |= DIRTY_ALL | DIRTY_MODE | DIRTY_EXPRESSION;
4620 tb->cx = tb->cy = 0;
4623 /* Text is not changed */
4624 tb->changed = FALSE;
4628 /* Peruse the main help file */
4630 (void)show_file(TRUE, "jeditor.txt", NULL, 0, 0);
4632 (void)show_file(TRUE, "editor.txt", NULL, 0, 0);
4635 tb->dirty_flags |= DIRTY_SCREEN;
4640 /* Split a line or insert end of line */
4642 /* Ignore selection */
4648 tb->dirty_flags |= DIRTY_ALL;
4651 insert_return_code(tb);
4656 tb->dirty_flags |= DIRTY_ALL;
4666 len = strlen(tb->lines_list[tb->cy]);
4667 if (len < tb->cx) tb->cx = len;
4669 else if (tb->cy > 0)
4672 tb->cx = strlen(tb->lines_list[tb->cy]);
4678 if (tb->lines_list[tb->cy + 1]) tb->cy++;
4683 if (tb->cy > 0) tb->cy--;
4692 if (iskanji(tb->lines_list[tb->cy][tb->cx])) tb->cx++;
4695 len = strlen(tb->lines_list[tb->cy]);
4698 if (tb->lines_list[tb->cy + 1])
4710 /* Beginning of line */
4716 tb->cx = strlen(tb->lines_list[tb->cy]);
4720 while (0 < tb->cy && tb->upper <= tb->cy)
4722 while (0 < tb->upper && tb->cy + 1 < tb->upper + tb->hgt)
4728 while (tb->cy < tb->upper + tb->hgt && tb->lines_list[tb->cy + 1])
4738 while (tb->lines_list[tb->cy + 1])
4744 int by1, bx1, by2, bx2;
4747 /* Copy the text first */
4748 do_editor_command(tb, EC_COPY);
4750 if (tb->my < tb->cy ||
4751 (tb->my == tb->cy && tb->mx < tb->cx))
4766 /* Kill lines in reverse order */
4767 for (y = by2; y >= by1; y--)
4770 int x1 = strlen(tb->lines_list[y]);
4772 if (y == by1) x0 = bx1;
4773 if (y == by2) x1 = bx2;
4775 kill_line_segment(tb, y, x0, x1, TRUE);
4778 /* Correct cursor position */
4782 /* Disable selection */
4786 tb->dirty_flags |= DIRTY_ALL;
4793 int by1, bx1, by2, bx2;
4795 int len = strlen(tb->lines_list[tb->cy]);
4797 /* Correct cursor location */
4798 if (tb->cx > len) tb->cx = len;
4800 /* Use single line? */
4805 if (tb->lines_list[tb->cy + 1])
4807 /* Select a single line */
4813 /* Select bottom line */
4818 if (tb->my < tb->cy ||
4819 (tb->my == tb->cy && tb->mx < tb->cx))
4834 /* Kill old yank buffer */
4835 kill_yank_chain(tb);
4837 /* Copy string to yank buffer */
4838 for (y = by1; y <= by2; y++)
4841 char buf[MAX_LINELEN];
4844 int x1 = strlen(tb->lines_list[y]);
4846 if (y == by1) x0 = bx1;
4847 if (y == by2) x1 = bx2;
4849 for (i = 0; i < x1 - x0; i++)
4851 buf[i] = tb->lines_list[y][x0 + i];
4855 add_str_to_yank(tb, buf);
4858 /* Disable selection */
4862 tb->dirty_flags |= DIRTY_ALL;
4868 /* Paste killed text */
4870 chain_str_type *chain = tb->yank;
4871 int len = strlen(tb->lines_list[tb->cy]);
4873 /* Nothing to do? */
4876 /* Correct cursor location */
4877 if (tb->cx > len) tb->cx = len;
4879 /* Ignore selection */
4885 tb->dirty_flags |= DIRTY_ALL;
4891 cptr yank_str = chain->s;
4893 char buf[MAX_LINELEN];
4895 char rest[MAX_LINELEN], *rest_ptr = rest;
4897 /* Save preceding string */
4898 for(i = 0; i < tb->cx; i++)
4899 buf[i] = tb->lines_list[tb->cy][i];
4901 strcpy(rest, &(tb->lines_list[tb->cy][i]));
4903 /* Paste yank buffer */
4904 while (*yank_str && i < MAX_LINELEN-1)
4906 buf[i++] = *yank_str++;
4912 chain = chain->next;
4914 if (chain || tb->yank_eol)
4916 /* There is an end of line between chain nodes */
4918 insert_return_code(tb);
4920 /* Replace this line with new one */
4921 string_free(tb->lines_list[tb->cy]);
4922 tb->lines_list[tb->cy] = string_make(buf);
4924 /* Move to next line */
4931 /* Final line doesn't have end of line */
4933 tb->cx = strlen(buf);
4935 /* Rest of original line */
4936 while (*rest_ptr && i < MAX_LINELEN-1)
4938 buf[i++] = *rest_ptr++;
4944 /* Replace this line with new one */
4945 string_free(tb->lines_list[tb->cy]);
4946 tb->lines_list[tb->cy] = string_make(buf);
4953 tb->dirty_flags |= DIRTY_ALL;
4955 /* Expressions need re-evaluation */
4956 tb->dirty_flags |= DIRTY_EXPRESSION;
4958 /* Text is changed */
4967 /* Disable the selection */
4971 tb->dirty_flags |= DIRTY_ALL;
4975 tb->mark = MARK_MARK;
4977 /* Repeating this command swaps cursor position */
4978 if (com_id == tb->old_com_id)
4990 tb->dirty_flags |= DIRTY_ALL;
4994 int len = strlen(tb->lines_list[tb->cy]);
4996 /* Mark the point 1 */
5000 /* Correct cursor location */
5001 if (tb->cx > len) tb->mx = len;
5008 /* Kill rest of line */
5010 int len = strlen(tb->lines_list[tb->cy]);
5012 /* Correct cursor location */
5013 if (tb->cx > len) tb->cx = len;
5015 /* Ignore selection */
5021 tb->dirty_flags |= DIRTY_ALL;
5024 /* Append only if this command is repeated. */
5025 if (tb->old_com_id != com_id)
5027 kill_yank_chain(tb);
5031 /* Really deleted some text */
5034 /* Add deleted string to yank buffer */
5035 add_str_to_yank(tb, &(tb->lines_list[tb->cy][tb->cx]));
5037 kill_line_segment(tb, tb->cy, tb->cx, len, FALSE);
5040 tb->dirty_line = tb->cy;
5042 /* Leave end of line character */
5046 /* Cut the end of line character only */
5047 if (tb->yank_eol) add_str_to_yank(tb, "");
5049 /* Cut end of line */
5050 tb->yank_eol = TRUE;
5052 do_editor_command(tb, EC_DELETE_CHAR);
5056 case EC_DELETE_CHAR:
5057 /* DELETE == go forward + BACK SPACE */
5059 /* Ignore selection */
5065 tb->dirty_flags |= DIRTY_ALL;
5069 if (iskanji(tb->lines_list[tb->cy][tb->cx])) tb->cx++;
5073 do_editor_command(tb, EC_BACKSPACE);
5081 char buf[MAX_LINELEN];
5083 /* Ignore selection */
5089 tb->dirty_flags |= DIRTY_ALL;
5092 len = strlen(tb->lines_list[tb->cy]);
5095 if (tb->lines_list[tb->cy + 1])
5109 /* delete a return code and union two lines */
5110 if (tb->cy == 0) break;
5111 tb->cx = strlen(tb->lines_list[tb->cy-1]);
5112 strcpy(buf, tb->lines_list[tb->cy-1]);
5113 strcat(buf, tb->lines_list[tb->cy]);
5114 string_free(tb->lines_list[tb->cy-1]);
5115 string_free(tb->lines_list[tb->cy]);
5116 tb->lines_list[tb->cy-1] = string_make(buf);
5118 for (i = tb->cy; tb->lines_list[i+1]; i++)
5119 tb->lines_list[i] = tb->lines_list[i+1];
5121 tb->lines_list[i] = NULL;
5125 tb->dirty_flags |= DIRTY_ALL;
5127 /* Expressions need re-evaluation */
5128 tb->dirty_flags |= DIRTY_EXPRESSION;
5130 /* Text is changed */
5136 for (i = j = k = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
5140 if (iskanji(tb->lines_list[tb->cy][i]))
5141 buf[j++] = tb->lines_list[tb->cy][i++];
5143 buf[j++] = tb->lines_list[tb->cy][i];
5150 for (; tb->lines_list[tb->cy][i]; i++)
5151 buf[j++] = tb->lines_list[tb->cy][i];
5153 string_free(tb->lines_list[tb->cy]);
5154 tb->lines_list[tb->cy] = string_make(buf);
5157 tb->dirty_line = tb->cy;
5159 /* Expressions may need re-evaluation */
5160 check_expression_line(tb, tb->cy);
5162 /* Text is changed */
5172 /* Become dirty because of item/equip menu */
5173 tb->dirty_flags |= DIRTY_SCREEN;
5175 search_dir = get_string_for_search(&tb->search_o_ptr, &tb->search_str);
5177 if (!search_dir) break;
5179 if (search_dir == 1) do_editor_command(tb, EC_SEARCH_FORW);
5180 else do_editor_command(tb, EC_SEARCH_BACK);
5184 case EC_SEARCH_FORW:
5185 if (tb->search_o_ptr)
5187 if (!search_for_object(tb, tb->search_o_ptr, TRUE)) tb->dirty_flags |= DIRTY_NOT_FOUND;
5189 else if (tb->search_str)
5191 if (!search_for_string(tb, tb->search_str, TRUE)) tb->dirty_flags |= DIRTY_NOT_FOUND;
5195 tb->dirty_flags |= DIRTY_NO_SEARCH;
5199 case EC_SEARCH_BACK:
5200 if (tb->search_o_ptr)
5202 if (!search_for_object(tb, tb->search_o_ptr, FALSE)) tb->dirty_flags |= DIRTY_NOT_FOUND;
5204 else if (tb->search_str)
5206 if (!search_for_string(tb, tb->search_str, FALSE)) tb->dirty_flags |= DIRTY_NOT_FOUND;
5210 tb->dirty_flags |= DIRTY_NO_SEARCH;
5215 /* Become dirty because of item/equip menu */
5216 tb->dirty_flags |= DIRTY_SCREEN;
5218 if (!get_object_for_search(&tb->search_o_ptr, &tb->search_str)) break;
5220 do_editor_command(tb, EC_SEARCH_FORW);
5223 case EC_SEARCH_DESTROYED:
5224 if (!get_destroyed_object_for_search(&tb->search_o_ptr, &tb->search_str)) break;
5226 do_editor_command(tb, EC_SEARCH_FORW);
5229 case EC_INSERT_OBJECT:
5231 /* Insert choosen item name */
5233 autopick_type an_entry, *entry = &an_entry;
5235 if (!entry_from_choosed_object(entry))
5237 /* Now dirty because of item/equip menu */
5238 tb->dirty_flags |= DIRTY_SCREEN;
5243 insert_return_code(tb);
5244 string_free(tb->lines_list[tb->cy]);
5245 tb->lines_list[tb->cy] = autopick_line_from_entry_kill(entry);
5247 /* Now dirty because of item/equip menu */
5248 tb->dirty_flags |= DIRTY_SCREEN;
5253 case EC_INSERT_DESTROYED:
5254 /* Insert a name of last destroyed item */
5255 if (tb->last_destroyed)
5258 insert_return_code(tb);
5259 string_free(tb->lines_list[tb->cy]);
5260 tb->lines_list[tb->cy] = string_make(tb->last_destroyed);
5263 tb->dirty_flags |= DIRTY_ALL;
5265 /* Text is changed */
5270 case EC_INSERT_BLOCK:
5272 /* Insert a conditinal expression line */
5275 /* Conditional Expression for Class and Race */
5276 sprintf(classrace, "?:[AND [EQU $RACE %s] [EQU $CLASS %s]]",
5278 rp_ptr->E_title, cp_ptr->E_title
5280 rp_ptr->title, cp_ptr->title
5285 insert_return_code(tb);
5286 string_free(tb->lines_list[tb->cy]);
5287 tb->lines_list[tb->cy] = string_make(classrace);
5289 insert_return_code(tb);
5290 string_free(tb->lines_list[tb->cy]);
5291 tb->lines_list[tb->cy] = string_make("?:1");
5294 tb->dirty_flags |= DIRTY_ALL;
5296 /* Text is changed */
5302 case EC_INSERT_MACRO:
5303 /* Draw_everythig (delete menu) */
5304 draw_text_editor(tb);
5307 Term_erase(0, tb->cy - tb->upper + 1, tb->wid);
5311 Term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW, "P:<¥È¥ê¥¬¡¼¥¡¼>: ");
5313 Term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW, "P:<Trigger key>: ");
5315 if (insert_macro_line(tb))
5317 /* Prepare to input action */
5321 tb->dirty_flags |= DIRTY_ALL;
5323 /* Text is changed */
5329 case EC_INSERT_KEYMAP:
5330 /* Draw_everythig (delete menu) */
5331 draw_text_editor(tb);
5334 Term_erase(0, tb->cy - tb->upper + 1, tb->wid);
5338 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)));
5340 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)));
5343 if (insert_keymap_line(tb))
5345 /* Prepare to input action */
5349 tb->dirty_flags |= DIRTY_ALL;
5351 /* Text is changed */
5356 case EC_CL_AUTOPICK: toggle_command_letter(tb, DO_AUTOPICK); break;
5357 case EC_CL_DESTROY: toggle_command_letter(tb, DO_AUTODESTROY); break;
5358 case EC_CL_LEAVE: toggle_command_letter(tb, DONT_AUTOPICK); break;
5359 case EC_CL_QUERY: toggle_command_letter(tb, DO_QUERY_AUTOPICK); break;
5360 case EC_CL_NO_DISP: toggle_command_letter(tb, DO_DISPLAY); break;
5362 case EC_IK_UNAWARE: toggle_keyword(tb, FLG_UNAWARE); break;
5363 case EC_IK_UNIDENTIFIED: toggle_keyword(tb, FLG_UNIDENTIFIED); break;
5364 case EC_IK_IDENTIFIED: toggle_keyword(tb, FLG_IDENTIFIED); break;
5365 case EC_IK_STAR_IDENTIFIED: toggle_keyword(tb, FLG_STAR_IDENTIFIED); break;
5366 case EC_KK_WEAPONS: toggle_keyword(tb, FLG_WEAPONS); break;
5367 case EC_KK_FAVORITE: toggle_keyword(tb, FLG_FAVORITE); break;
5368 case EC_KK_ARMORS: toggle_keyword(tb, FLG_ARMORS); break;
5369 case EC_KK_MISSILES: toggle_keyword(tb, FLG_MISSILES); break;
5370 case EC_KK_DEVICES: toggle_keyword(tb, FLG_DEVICES); break;
5371 case EC_KK_LIGHTS: toggle_keyword(tb, FLG_LIGHTS); break;
5372 case EC_KK_JUNKS: toggle_keyword(tb, FLG_JUNKS); break;
5373 case EC_KK_SPELLBOOKS: toggle_keyword(tb, FLG_SPELLBOOKS); break;
5374 case EC_KK_SHIELDS: toggle_keyword(tb, FLG_SHIELDS); break;
5375 case EC_KK_BOWS: toggle_keyword(tb, FLG_BOWS); break;
5376 case EC_KK_RINGS: toggle_keyword(tb, FLG_RINGS); break;
5377 case EC_KK_AMULETS: toggle_keyword(tb, FLG_AMULETS); break;
5378 case EC_KK_SUITS: toggle_keyword(tb, FLG_SUITS); break;
5379 case EC_KK_CLOAKS: toggle_keyword(tb, FLG_CLOAKS); break;
5380 case EC_KK_HELMS: toggle_keyword(tb, FLG_HELMS); break;
5381 case EC_KK_GLOVES: toggle_keyword(tb, FLG_GLOVES); break;
5382 case EC_KK_BOOTS: toggle_keyword(tb, FLG_BOOTS); break;
5383 case EC_OK_COLLECTING: toggle_keyword(tb, FLG_COLLECTING); break;
5384 case EC_OK_BOOSTED: toggle_keyword(tb, FLG_BOOSTED); break;
5385 case EC_OK_MORE_THAN: toggle_keyword(tb, FLG_MORE_THAN); break;
5386 case EC_OK_MORE_BONUS: toggle_keyword(tb, FLG_MORE_BONUS); break;
5387 case EC_OK_WORTHLESS: toggle_keyword(tb, FLG_WORTHLESS); break;
5388 case EC_OK_ARTIFACT: toggle_keyword(tb, FLG_ARTIFACT); break;
5389 case EC_OK_EGO: toggle_keyword(tb, FLG_EGO); break;
5390 case EC_OK_NAMELESS: toggle_keyword(tb, FLG_NAMELESS); break;
5391 case EC_OK_WANTED: toggle_keyword(tb, FLG_WANTED); break;
5392 case EC_OK_UNIQUE: toggle_keyword(tb, FLG_UNIQUE); break;
5393 case EC_OK_HUMAN: toggle_keyword(tb, FLG_HUMAN); break;
5394 case EC_OK_UNREADABLE:
5395 toggle_keyword(tb, FLG_UNREADABLE);
5396 add_keyword(tb, FLG_SPELLBOOKS);
5399 toggle_keyword(tb, FLG_REALM1);
5400 add_keyword(tb, FLG_SPELLBOOKS);
5403 toggle_keyword(tb, FLG_REALM2);
5404 add_keyword(tb, FLG_SPELLBOOKS);
5407 toggle_keyword(tb, FLG_FIRST);
5408 add_keyword(tb, FLG_SPELLBOOKS);
5411 toggle_keyword(tb, FLG_SECOND);
5412 add_keyword(tb, FLG_SPELLBOOKS);
5415 toggle_keyword(tb, FLG_THIRD);
5416 add_keyword(tb, FLG_SPELLBOOKS);
5419 toggle_keyword(tb, FLG_FOURTH);
5420 add_keyword(tb, FLG_SPELLBOOKS);
5424 /* Save old command */
5425 tb->old_com_id = com_id;
5432 * Insert single letter at cursor position.
5434 static void insert_single_letter(text_body_type *tb, int key)
5437 char buf[MAX_LINELEN];
5439 /* Save preceding string */
5440 for (i = j = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
5441 buf[j++] = tb->lines_list[tb->cy][i];
5443 /* Add a character */
5451 if (j+2 < MAX_LINELEN)
5463 if (j+1 < MAX_LINELEN)
5469 for (; tb->lines_list[tb->cy][i] && j + 1 < MAX_LINELEN; i++)
5470 buf[j++] = tb->lines_list[tb->cy][i];
5473 /* Replace current line with new line */
5474 string_free(tb->lines_list[tb->cy]);
5475 tb->lines_list[tb->cy] = string_make(buf);
5477 /* Move to correct collumn */
5478 len = strlen(tb->lines_list[tb->cy]);
5479 if (len < tb->cx) tb->cx = len;
5482 tb->dirty_line = tb->cy;
5484 /* Expressions may need re-evaluation */
5485 check_expression_line(tb, tb->cy);
5487 /* Text is changed */
5493 * Check special key code and get a movement command id
5495 static int analyze_move_key(text_body_type *tb, int skey)
5499 /* Not a special key */
5500 if (!(skey & SKEY_MASK)) return 0;
5502 /* Convert from a special key code to an editor command */
5503 switch(skey & ~SKEY_MOD_MASK)
5505 case SKEY_DOWN: com_id = EC_DOWN; break;
5506 case SKEY_LEFT: com_id = EC_LEFT; break;
5507 case SKEY_RIGHT: com_id = EC_RIGHT; break;
5508 case SKEY_UP: com_id = EC_UP; break;
5509 case SKEY_PGUP: com_id = EC_PGUP; break;
5510 case SKEY_PGDOWN: com_id = EC_PGDOWN; break;
5511 case SKEY_TOP: com_id = EC_TOP; break;
5512 case SKEY_BOTTOM: com_id = EC_BOTTOM; break;
5515 /* Not a special movement key */
5519 /* Without shift modifier */
5520 if (!(skey & SKEY_MOD_SHIFT))
5523 * Un-shifted cursor keys cancells
5524 * selection created by shift+cursor.
5526 if (tb->mark & MARK_BY_SHIFT)
5531 tb->dirty_flags |= DIRTY_ALL;
5535 /* With shift modifier */
5538 /* Start selection by shift + cursor keys */
5541 int len = strlen(tb->lines_list[tb->cy]);
5543 tb->mark = MARK_MARK | MARK_BY_SHIFT;
5547 /* Correct cursor location */
5548 if (tb->cx > len) tb->mx = len;
5550 /* Need to redraw text */
5551 if (com_id == EC_UP || com_id == EC_DOWN)
5553 /* Redraw all text */
5554 tb->dirty_flags |= DIRTY_ALL;
5558 tb->dirty_line = tb->cy;
5567 * In-game editor of Object Auto-picker/Destoryer
5569 void do_cmd_edit_autopick(void)
5571 static int cx_save = 0;
5572 static int cy_save = 0;
5574 text_body_type text_body, *tb = &text_body;
5576 autopick_type an_entry, *entry = &an_entry;
5577 char buf[MAX_LINELEN];
5582 static s32b old_autosave_turn = 0L;
5585 tb->changed = FALSE;
5588 tb->upper = tb->left = 0;
5590 tb->mx = tb->my = 0;
5591 tb->old_cy = tb->old_upper = tb->old_left = -1;
5592 tb->old_wid = tb->old_hgt = -1;
5596 tb->search_o_ptr = NULL;
5597 tb->search_str = NULL;
5598 tb->last_destroyed = NULL;
5599 tb->dirty_flags = DIRTY_ALL | DIRTY_MODE | DIRTY_EXPRESSION;
5600 tb->dirty_line = -1;
5601 tb->filename_mode = PT_DEFAULT;
5604 if (turn > old_autosave_turn + 100L)
5606 do_cmd_save_game(TRUE);
5607 old_autosave_turn = turn;
5610 /* HACK -- Reset start_time to stop counting playtime while edit */
5613 /* Free old entries */
5616 /* Command Description of the 'Last Destroyed Item' */
5617 if (autopick_last_destroyed_object.k_idx)
5619 autopick_entry_from_object(entry, &autopick_last_destroyed_object);
5620 tb->last_destroyed = autopick_line_from_entry_kill(entry);
5623 /* Read or initialize whole text */
5624 tb->lines_list = read_pickpref_text_lines(&tb->filename_mode);
5626 /* Reset cursor position if needed */
5627 for (i = 0; i < tb->cy; i++)
5629 if (!tb->lines_list[i])
5631 tb->cy = tb->cx = 0;
5636 /* Save the screen */
5639 /* Process requests until done */
5644 /* Draw_everythig */
5645 draw_text_editor(tb);
5647 /* Display header line */
5649 prt("(^Q:½ªÎ» ^W:¥»¡¼¥Ö¤·¤Æ½ªÎ», ESC:¥á¥Ë¥å¡¼, ¤½¤Î¾:ÆþÎÏ)", 0, 0);
5651 prt("(^Q:quit, ^W:save&quit, ESC:menu, Other:input text)", 0, 0);
5655 /* Display current position */
5656 prt (format("(%d,%d)", tb->cx, tb->cy), 0, 60);
5660 /* Display current position and mark position */
5661 prt (format("(%d,%d)-(%d,%d)", tb->mx, tb->my, tb->cx, tb->cy), 0, 60);
5665 Term_gotoxy(tb->cx - tb->left, tb->cy - tb->upper + 1);
5668 tb->dirty_flags = 0;
5669 tb->dirty_line = -1;
5671 /* Save old key and location */
5672 tb->old_cy = tb->cy;
5673 tb->old_upper = tb->upper;
5674 tb->old_left = tb->left;
5675 tb->old_wid = tb->wid;
5676 tb->old_hgt = tb->hgt;
5679 key = inkey_special();
5682 if (key & SKEY_MASK)
5684 /* Get a movement command */
5685 com_id = analyze_move_key(tb, key);
5689 else if (key == ESCAPE)
5691 com_id = do_command_menu(0, 0);
5693 /* Redraw all text later */
5694 tb->dirty_flags |= DIRTY_SCREEN;
5697 /* Insert a character */
5698 else if (!iscntrl((unsigned char)key))
5700 /* Ignore selection */
5706 tb->dirty_flags |= DIRTY_ALL;
5709 insert_single_letter(tb, key);
5715 /* Other commands */
5718 com_id = get_com_id(key);
5721 if (com_id) quit = do_editor_command(tb, com_id);
5724 /* Restore the screen */
5727 /* Get the filename of preference */
5728 strcpy(buf, pickpref_filename(tb->filename_mode));
5730 if (quit == QUIT_AND_SAVE)
5731 write_text_lines(buf, tb->lines_list);
5733 free_text_lines(tb->lines_list);
5735 string_free(tb->last_destroyed);
5737 /* Destroy string chain */
5738 kill_yank_chain(tb);
5740 /* Reload autopick pref */
5741 process_pickpref_file(buf);
5743 /* HACK -- reset start_time so that playtime is not increase while edit */
5744 start_time = time(NULL);
5746 /* Save cursor location */