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, bool others_ok)
431 /* Only weapons match */
434 case TV_BOW: case TV_HAFTED: case TV_POLEARM:
435 case TV_SWORD: case TV_DIGGING:
437 default: return FALSE;
440 /* Favorite weapons are varied depend on the class */
441 switch (p_ptr->pclass)
445 u32b flgs[TR_FLAG_SIZE];
446 object_flags_known(o_ptr, flgs);
448 if (!have_flag(flgs, TR_BLESSED) &&
449 !(o_ptr->tval == TV_HAFTED))
455 case CLASS_FORCETRAINER:
457 if (!(s_info[p_ptr->pclass].w_max[o_ptr->tval-TV_BOW][o_ptr->sval]))
461 case CLASS_BEASTMASTER:
464 u32b flgs[TR_FLAG_SIZE];
465 object_flags_known(o_ptr, flgs);
467 /* Is it known to be suitable to using while riding? */
468 if (!(have_flag(flgs, TR_RIDING)))
476 if (s_info[p_ptr->pclass].w_max[o_ptr->tval-TV_BOW][o_ptr->sval] <= WEAPON_EXP_BEGINNER)
481 /* Non-special class */
482 if (others_ok) return TRUE;
491 * Get auto-picker entry from o_ptr.
493 static void autopick_entry_from_object(autopick_type *entry, object_type *o_ptr)
495 /* Assume that object name is to be added */
499 entry->insc = string_make(quark_str(o_ptr->inscription));
500 entry->action = DO_AUTOPICK | DO_DISPLAY;
501 entry->flag[0] = entry->flag[1] = 0L;
504 if (!object_aware_p(o_ptr))
506 ADD_FLG(FLG_UNAWARE);
508 else if (!object_known_p(o_ptr))
510 ADD_FLG(FLG_UNIDENTIFIED);
516 ego_item_type *e_ptr = &e_info[o_ptr->name2];
517 entry->name = string_make(e_name + e_ptr->name);
521 else if (o_ptr->name1 || o_ptr->art_name)
522 ADD_FLG(FLG_ARTIFACT);
525 /* Wearable nameless object */
529 case TV_SHOT: case TV_ARROW: case TV_BOLT: case TV_BOW:
530 case TV_DIGGING: case TV_HAFTED: case TV_POLEARM: case TV_SWORD:
531 case TV_BOOTS: case TV_GLOVES: case TV_HELM: case TV_CROWN:
532 case TV_SHIELD: case TV_CLOAK:
533 case TV_SOFT_ARMOR: case TV_HARD_ARMOR: case TV_DRAG_ARMOR:
534 case TV_LITE: case TV_AMULET: case TV_RING: case TV_CARD:
536 ADD_FLG(FLG_NAMELESS);
547 case TV_HAFTED: case TV_POLEARM: case TV_SWORD: case TV_DIGGING:
548 k_ptr = &k_info[o_ptr->k_idx];
549 if ((o_ptr->dd != k_ptr->dd) || (o_ptr->ds != k_ptr->ds))
550 ADD_FLG(FLG_BOOSTED);
553 if (o_ptr->tval == TV_CORPSE && object_is_shoukinkubi(o_ptr))
555 REM_FLG(FLG_WORTHLESS);
559 if ((o_ptr->tval == TV_CORPSE || o_ptr->tval == TV_STATUE)
560 && (r_info[o_ptr->pval].flags1 & RF1_UNIQUE))
565 if (o_ptr->tval == TV_CORPSE && strchr("pht", r_info[o_ptr->pval].d_char))
570 if (o_ptr->tval >= TV_LIFE_BOOK &&
571 !check_book_realm(o_ptr->tval, o_ptr->sval))
573 ADD_FLG(FLG_UNREADABLE);
574 if (o_ptr->tval != TV_ARCANE_BOOK) name = FALSE;
577 if (REALM1_BOOK == o_ptr->tval &&
578 p_ptr->pclass != CLASS_SORCERER &&
579 p_ptr->pclass != CLASS_RED_MAGE)
585 if (REALM2_BOOK == o_ptr->tval &&
586 p_ptr->pclass != CLASS_SORCERER &&
587 p_ptr->pclass != CLASS_RED_MAGE)
593 if (o_ptr->tval >= TV_LIFE_BOOK && 0 == o_ptr->sval)
595 if (o_ptr->tval >= TV_LIFE_BOOK && 1 == o_ptr->sval)
597 if (o_ptr->tval >= TV_LIFE_BOOK && 2 == o_ptr->sval)
599 if (o_ptr->tval >= TV_LIFE_BOOK && 3 == o_ptr->sval)
602 if (o_ptr->tval == TV_SHOT || o_ptr->tval == TV_BOLT
603 || o_ptr->tval == TV_ARROW)
604 ADD_FLG(FLG_MISSILES);
605 else if (o_ptr->tval == TV_SCROLL || o_ptr->tval == TV_STAFF
606 || o_ptr->tval == TV_WAND || o_ptr->tval == TV_ROD)
607 ADD_FLG(FLG_DEVICES);
608 else if (o_ptr->tval == TV_LITE)
610 else if (o_ptr->tval == TV_SKELETON || o_ptr->tval == TV_BOTTLE
611 || o_ptr->tval == TV_JUNK || o_ptr->tval == TV_STATUE)
613 else if (o_ptr->tval >= TV_LIFE_BOOK)
614 ADD_FLG(FLG_SPELLBOOKS);
615 else if (is_favorite(o_ptr, FALSE))
616 ADD_FLG(FLG_FAVORITE);
617 else if (o_ptr->tval == TV_POLEARM || o_ptr->tval == TV_SWORD
618 || o_ptr->tval == TV_DIGGING || o_ptr->tval == TV_HAFTED)
619 ADD_FLG(FLG_WEAPONS);
620 else if (o_ptr->tval == TV_SHIELD)
621 ADD_FLG(FLG_SHIELDS);
622 else if (o_ptr->tval == TV_BOW)
624 else if (o_ptr->tval == TV_RING)
626 else if (o_ptr->tval == TV_AMULET)
627 ADD_FLG(FLG_AMULETS);
628 else if (o_ptr->tval == TV_DRAG_ARMOR || o_ptr->tval == TV_HARD_ARMOR ||
629 o_ptr->tval == TV_SOFT_ARMOR)
631 else if (o_ptr->tval == TV_CLOAK)
633 else if (o_ptr->tval == TV_HELM)
635 else if (o_ptr->tval == TV_GLOVES)
637 else if (o_ptr->tval == TV_BOOTS)
643 char o_name[MAX_NLEN];
644 object_desc(o_name, o_ptr, FALSE, 0);
646 entry->name = string_make(o_name);
649 else if (!entry->name)
651 entry->name = string_make("");
659 * A function to delete entry
661 static void autopick_free_entry(autopick_type *entry)
663 string_free(entry->name);
664 string_free(entry->insc);
669 * Initialize auto-picker preference
671 #define MAX_AUTOPICK_DEFAULT 200
673 void init_autopicker(void)
675 static const char easy_autopick_inscription[] = "(:=g";
681 max_max_autopick = MAX_AUTOPICK_DEFAULT;
682 C_MAKE(autopick_list, max_max_autopick, autopick_type);
686 /* Clear old entries */
687 for( i = 0; i < max_autopick; i++)
688 autopick_free_entry(&autopick_list[i]);
692 /* There is always one entry "=g" */
693 autopick_new_entry(&entry, easy_autopick_inscription, TRUE);
694 autopick_list[max_autopick++] = entry;
699 * Add one line to autopick_list[]
701 static void add_autopick_list(autopick_type *entry)
703 /* There is no enough space to add one line */
704 if (max_autopick >= max_max_autopick)
706 int old_max_max_autopick = max_max_autopick;
707 autopick_type *old_autopick_list = autopick_list;
709 /* Increase size of list */
710 max_max_autopick += MAX_AUTOPICK_DEFAULT;
713 C_MAKE(autopick_list, max_max_autopick, autopick_type);
715 /* Copy from old list to new list */
716 C_COPY(autopick_list, old_autopick_list, old_max_max_autopick, autopick_type);
719 C_FREE(old_autopick_list, old_max_max_autopick, autopick_type);
723 autopick_list[max_autopick] = *entry;
730 * Process line for auto picker/destroyer.
732 errr process_pickpref_file_line(char *buf)
734 autopick_type an_entry, *entry = &an_entry;
737 /* Nuke illegal char */
738 for(i = 0; buf[i]; i++)
747 if (isspace(buf[i]) && buf[i] != ' ')
752 if (!autopick_new_entry(entry, buf, FALSE)) return 0;
754 /* Already has the same entry? */
755 for(i = 0; i < max_autopick; i++)
756 if(!strcmp(entry->name, autopick_list[i].name)
757 && entry->flag[0] == autopick_list[i].flag[0]
758 && entry->flag[1] == autopick_list[i].flag[1]
759 && entry->dice == autopick_list[i].dice
760 && entry->bonus == autopick_list[i].bonus) return 0;
762 add_autopick_list(entry);
768 * Reconstruct preference line from entry
770 cptr autopick_line_from_entry(autopick_type *entry)
772 char buf[MAX_LINELEN];
774 bool sepa_flag = TRUE;
777 if (!(entry->action & DO_DISPLAY)) strcat(buf, "(");
778 if (entry->action & DO_QUERY_AUTOPICK) strcat(buf, ";");
779 if (entry->action & DO_AUTODESTROY) strcat(buf, "!");
780 if (entry->action & DONT_AUTOPICK) strcat(buf, "~");
784 if (IS_FLG(FLG_ALL)) ADD_KEY(KEY_ALL);
785 if (IS_FLG(FLG_COLLECTING)) ADD_KEY(KEY_COLLECTING);
786 if (IS_FLG(FLG_UNIDENTIFIED)) ADD_KEY(KEY_UNIDENTIFIED);
787 if (IS_FLG(FLG_IDENTIFIED)) ADD_KEY(KEY_IDENTIFIED);
788 if (IS_FLG(FLG_STAR_IDENTIFIED)) ADD_KEY(KEY_STAR_IDENTIFIED);
789 if (IS_FLG(FLG_UNAWARE)) ADD_KEY(KEY_UNAWARE);
790 if (IS_FLG(FLG_BOOSTED)) ADD_KEY(KEY_BOOSTED);
792 if (IS_FLG(FLG_MORE_THAN))
794 ADD_KEY(KEY_MORE_THAN);
795 strcat(ptr, format("%d", entry->dice));
799 if (IS_FLG(FLG_MORE_BONUS))
801 ADD_KEY(KEY_MORE_BONUS);
802 strcat(ptr, format("%d", entry->bonus));
803 ADD_KEY(KEY_MORE_BONUS2);
806 if (IS_FLG(FLG_UNREADABLE)) ADD_KEY(KEY_UNREADABLE);
807 if (IS_FLG(FLG_REALM1)) ADD_KEY(KEY_REALM1);
808 if (IS_FLG(FLG_REALM2)) ADD_KEY(KEY_REALM2);
809 if (IS_FLG(FLG_FIRST)) ADD_KEY(KEY_FIRST);
810 if (IS_FLG(FLG_SECOND)) ADD_KEY(KEY_SECOND);
811 if (IS_FLG(FLG_THIRD)) ADD_KEY(KEY_THIRD);
812 if (IS_FLG(FLG_FOURTH)) ADD_KEY(KEY_FOURTH);
813 if (IS_FLG(FLG_WANTED)) ADD_KEY(KEY_WANTED);
814 if (IS_FLG(FLG_UNIQUE)) ADD_KEY(KEY_UNIQUE);
815 if (IS_FLG(FLG_HUMAN)) ADD_KEY(KEY_HUMAN);
816 if (IS_FLG(FLG_WORTHLESS)) ADD_KEY(KEY_WORTHLESS);
817 if (IS_FLG(FLG_NAMELESS)) ADD_KEY(KEY_NAMELESS);
818 if (IS_FLG(FLG_EGO)) ADD_KEY(KEY_EGO);
820 if (IS_FLG(FLG_ARTIFACT)) ADD_KEY(KEY_ARTIFACT);
822 if (IS_FLG(FLG_ITEMS)) ADD_KEY2(KEY_ITEMS);
823 else if (IS_FLG(FLG_WEAPONS)) ADD_KEY2(KEY_WEAPONS);
824 else if (IS_FLG(FLG_ARMORS)) ADD_KEY2(KEY_ARMORS);
825 else if (IS_FLG(FLG_MISSILES)) ADD_KEY2(KEY_MISSILES);
826 else if (IS_FLG(FLG_DEVICES)) ADD_KEY2(KEY_DEVICES);
827 else if (IS_FLG(FLG_LIGHTS)) ADD_KEY2(KEY_LIGHTS);
828 else if (IS_FLG(FLG_JUNKS)) ADD_KEY2(KEY_JUNKS);
829 else if (IS_FLG(FLG_SPELLBOOKS)) ADD_KEY2(KEY_SPELLBOOKS);
830 else if (IS_FLG(FLG_HAFTED)) ADD_KEY2(KEY_HAFTED);
831 else if (IS_FLG(FLG_SHIELDS)) ADD_KEY2(KEY_SHIELDS);
832 else if (IS_FLG(FLG_BOWS)) ADD_KEY2(KEY_BOWS);
833 else if (IS_FLG(FLG_RINGS)) ADD_KEY2(KEY_RINGS);
834 else if (IS_FLG(FLG_AMULETS)) ADD_KEY2(KEY_AMULETS);
835 else if (IS_FLG(FLG_SUITS)) ADD_KEY2(KEY_SUITS);
836 else if (IS_FLG(FLG_CLOAKS)) ADD_KEY2(KEY_CLOAKS);
837 else if (IS_FLG(FLG_HELMS)) ADD_KEY2(KEY_HELMS);
838 else if (IS_FLG(FLG_GLOVES)) ADD_KEY2(KEY_GLOVES);
839 else if (IS_FLG(FLG_BOOTS)) ADD_KEY2(KEY_BOOTS);
840 else if (IS_FLG(FLG_FAVORITE)) ADD_KEY2(KEY_FAVORITE);
842 /* You don't need sepalator after adjective */
843 /* 'artifact' is not true adjective */
844 else if (!IS_FLG(FLG_ARTIFACT))
847 if (entry->name && entry->name[0])
851 if (sepa_flag) strcat(buf, ":");
854 while (entry->name[j] && i < MAX_LINELEN - 2 - 1)
857 if (iskanji(entry->name[j]))
858 buf[i++] = entry->name[j++];
860 buf[i++] = entry->name[j++];
871 while (entry->insc[j] && i < MAX_LINELEN - 2)
874 if (iskanji(entry->insc[j]))
875 buf[i++] = entry->insc[j++];
877 buf[i++] = entry->insc[j++];
882 return string_make(buf);
887 * Reconstruct preference line from entry and kill entry
889 static cptr autopick_line_from_entry_kill(autopick_type *entry)
891 cptr ptr = autopick_line_from_entry(entry);
893 /* Free memory for original entry */
894 autopick_free_entry(entry);
901 * A function for Auto-picker/destroyer
902 * Examine whether the object matches to the entry
904 static bool is_autopick_aux(object_type *o_ptr, autopick_type *entry, cptr o_name)
907 cptr ptr = entry->name;
909 /*** Unidentified ***/
910 if (IS_FLG(FLG_UNIDENTIFIED)
911 && (object_known_p(o_ptr) || (o_ptr->ident & IDENT_SENSE)))
915 if (IS_FLG(FLG_IDENTIFIED) && !object_known_p(o_ptr))
918 /*** *Identified* ***/
919 if (IS_FLG(FLG_STAR_IDENTIFIED) &&
920 (!object_known_p(o_ptr) || !(o_ptr->ident & IDENT_MENTAL)))
923 /*** Dice boosted (weapon of slaying) ***/
924 if (IS_FLG(FLG_BOOSTED))
926 object_kind *k_ptr = &k_info[o_ptr->k_idx];
928 switch( o_ptr->tval )
934 if ((o_ptr->dd != k_ptr->dd) || (o_ptr->ds != k_ptr->ds))
943 /*** Weapons which dd*ds is more than nn ***/
944 if (IS_FLG(FLG_MORE_THAN))
946 if (o_ptr->dd * o_ptr->ds < entry->dice)
950 /*** Weapons whic dd*ds is more than nn ***/
951 if (IS_FLG(FLG_MORE_BONUS))
953 if (!object_known_p(o_ptr)) return FALSE;
957 if (o_ptr->pval < entry->bonus) return FALSE;
961 if (o_ptr->to_h < entry->bonus &&
962 o_ptr->to_d < entry->bonus &&
963 o_ptr->to_a < entry->bonus &&
964 o_ptr->pval < entry->bonus)
969 /*** Worthless items ***/
970 if (IS_FLG(FLG_WORTHLESS) && object_value(o_ptr) > 0)
973 /*** Artifact object ***/
974 if (IS_FLG(FLG_ARTIFACT))
976 if (!object_known_p(o_ptr) || (!o_ptr->name1 && !o_ptr->art_name))
983 if (!object_known_p(o_ptr) || !o_ptr->name2)
988 if (IS_FLG(FLG_NAMELESS))
993 case TV_SHOT: case TV_ARROW: case TV_BOLT: case TV_BOW:
994 case TV_DIGGING: case TV_HAFTED: case TV_POLEARM: case TV_SWORD:
995 case TV_BOOTS: case TV_GLOVES: case TV_HELM: case TV_CROWN:
996 case TV_SHIELD: case TV_CLOAK:
997 case TV_SOFT_ARMOR: case TV_HARD_ARMOR: case TV_DRAG_ARMOR:
998 case TV_LITE: case TV_AMULET: case TV_RING: case TV_CARD:
999 if ((!object_known_p(o_ptr) || o_ptr->inscription
1000 || o_ptr->name1 || o_ptr->name2 || o_ptr->art_name))
1009 /*** Unaware items ***/
1010 if (IS_FLG(FLG_UNAWARE) && object_aware_p(o_ptr))
1013 /*** Wanted monster's corpse/skeletons ***/
1014 if (IS_FLG(FLG_WANTED) &&
1015 (o_ptr->tval != TV_CORPSE || !object_is_shoukinkubi(o_ptr)))
1018 /*** Unique monster's corpse/skeletons/statues ***/
1019 if (IS_FLG(FLG_UNIQUE) &&
1020 ((o_ptr->tval != TV_CORPSE && o_ptr->tval != TV_STATUE) ||
1021 !(r_info[o_ptr->pval].flags1 & RF1_UNIQUE)))
1024 /*** Human corpse/skeletons (for Daemon magic) ***/
1025 if (IS_FLG(FLG_HUMAN) &&
1026 (o_ptr->tval != TV_CORPSE ||
1027 !strchr("pht", r_info[o_ptr->pval].d_char)))
1030 /*** Unreadable spellbooks ***/
1031 if (IS_FLG(FLG_UNREADABLE) &&
1032 (o_ptr->tval < TV_LIFE_BOOK ||
1033 check_book_realm(o_ptr->tval, o_ptr->sval)))
1036 /*** First realm spellbooks ***/
1037 if (IS_FLG(FLG_REALM1) &&
1038 (REALM1_BOOK != o_ptr->tval ||
1039 p_ptr->pclass == CLASS_SORCERER ||
1040 p_ptr->pclass == CLASS_RED_MAGE))
1043 /*** Second realm spellbooks ***/
1044 if (IS_FLG(FLG_REALM2) &&
1045 (REALM2_BOOK != o_ptr->tval ||
1046 p_ptr->pclass == CLASS_SORCERER ||
1047 p_ptr->pclass == CLASS_RED_MAGE))
1050 /*** First rank spellbooks ***/
1051 if (IS_FLG(FLG_FIRST) &&
1052 (o_ptr->tval < TV_LIFE_BOOK || 0 != o_ptr->sval))
1055 /*** Second rank spellbooks ***/
1056 if (IS_FLG(FLG_SECOND) &&
1057 (o_ptr->tval < TV_LIFE_BOOK || 1 != o_ptr->sval))
1060 /*** Third rank spellbooks ***/
1061 if (IS_FLG(FLG_THIRD) &&
1062 (o_ptr->tval < TV_LIFE_BOOK || 2 != o_ptr->sval))
1065 /*** Fourth rank spellbooks ***/
1066 if (IS_FLG(FLG_FOURTH) &&
1067 (o_ptr->tval < TV_LIFE_BOOK || 3 != o_ptr->sval))
1071 if (IS_FLG(FLG_WEAPONS))
1075 case TV_BOW: case TV_HAFTED: case TV_POLEARM:
1076 case TV_SWORD: case TV_DIGGING:
1078 default: return FALSE;
1081 else if (IS_FLG(FLG_ARMORS))
1085 case TV_BOOTS: case TV_GLOVES: case TV_CLOAK: case TV_CROWN:
1086 case TV_HELM: case TV_SHIELD: case TV_SOFT_ARMOR:
1087 case TV_HARD_ARMOR: case TV_DRAG_ARMOR:
1089 default: return FALSE;
1092 else if (IS_FLG(FLG_MISSILES))
1096 case TV_SHOT: case TV_BOLT: case TV_ARROW:
1098 default: return FALSE;
1101 else if (IS_FLG(FLG_DEVICES))
1105 case TV_SCROLL: case TV_STAFF: case TV_WAND: case TV_ROD:
1107 default: return FALSE;
1110 else if (IS_FLG(FLG_LIGHTS))
1112 if (!(o_ptr->tval == TV_LITE))
1115 else if (IS_FLG(FLG_JUNKS))
1119 case TV_SKELETON: case TV_BOTTLE:
1120 case TV_JUNK: case TV_STATUE:
1122 default: return FALSE;
1125 else if (IS_FLG(FLG_SPELLBOOKS))
1127 if (!(o_ptr->tval >= TV_LIFE_BOOK))
1130 else if (IS_FLG(FLG_HAFTED))
1132 if (!(o_ptr->tval == TV_HAFTED))
1135 else if (IS_FLG(FLG_SHIELDS))
1137 if (!(o_ptr->tval == TV_SHIELD))
1140 else if (IS_FLG(FLG_BOWS))
1142 if (!(o_ptr->tval == TV_BOW))
1145 else if (IS_FLG(FLG_RINGS))
1147 if (!(o_ptr->tval == TV_RING))
1150 else if (IS_FLG(FLG_AMULETS))
1152 if (!(o_ptr->tval == TV_AMULET))
1155 else if (IS_FLG(FLG_SUITS))
1157 if (!(o_ptr->tval == TV_DRAG_ARMOR ||
1158 o_ptr->tval == TV_HARD_ARMOR ||
1159 o_ptr->tval == TV_SOFT_ARMOR))
1162 else if (IS_FLG(FLG_CLOAKS))
1164 if (!(o_ptr->tval == TV_CLOAK))
1167 else if (IS_FLG(FLG_HELMS))
1169 if (!(o_ptr->tval == TV_CROWN || o_ptr->tval == TV_HELM))
1172 else if (IS_FLG(FLG_GLOVES))
1174 if (!(o_ptr->tval == TV_GLOVES))
1177 else if (IS_FLG(FLG_BOOTS))
1179 if (!(o_ptr->tval == TV_BOOTS))
1182 else if (IS_FLG(FLG_FAVORITE))
1184 if (!is_favorite(o_ptr, TRUE))
1188 /* Keyword don't match */
1192 if (strncmp(o_name, ptr, strlen(ptr))) return FALSE;
1197 if (!strstr_j(o_name, ptr)) return FALSE;
1199 if (!strstr(o_name, ptr)) return FALSE;
1203 /* TRUE when it need not to be 'collecting' */
1204 if (!IS_FLG(FLG_COLLECTING)) return TRUE;
1206 /* Check if there is a same item */
1207 for (j = 0; j < INVEN_PACK; j++)
1210 * 'Collecting' means the item must be absorbed
1211 * into an inventory slot.
1212 * But an item can not be absorbed into itself!
1214 if ((&inventory[j] != o_ptr) &&
1215 object_similar(&inventory[j], o_ptr))
1219 /* Not collecting */
1225 * A function for Auto-picker/destroyer
1226 * Examine whether the object matches to the list of keywords or not.
1228 int is_autopick(object_type *o_ptr)
1231 char o_name[MAX_NLEN];
1233 if (o_ptr->tval == TV_GOLD) return -1;
1235 object_desc(o_name, o_ptr, FALSE, 3);
1237 /* Force to be lower case string */
1238 for (i = 0; o_name[i]; i++)
1241 if (iskanji(o_name[i]))
1245 if (isupper(o_name[i]))
1246 o_name[i] = tolower(o_name[i]);
1249 for (i=0; i < max_autopick; i++)
1251 autopick_type *entry = &autopick_list[i];
1253 if (is_autopick_aux(o_ptr, entry, o_name)) return i;
1256 /* No matching entry */
1264 void auto_inscribe_item(int item, int idx)
1268 /* Get the item (in the pack) */
1269 if (item >= 0) o_ptr = &inventory[item];
1271 /* Get the item (on the floor) */
1272 else o_ptr = &o_list[0 - item];
1274 /* Auto-inscription or Re-inscribe for resistances {%} */
1275 if ((idx < 0 || !autopick_list[idx].insc) && !o_ptr->inscription)
1278 if (!o_ptr->inscription)
1279 o_ptr->inscription = quark_add(autopick_list[idx].insc);
1281 if (item > INVEN_PACK)
1283 /* Redraw inscription */
1284 p_ptr->window |= (PW_EQUIP);
1286 /* {.} and {$} effect p_ptr->warning and TRC_TELEPORT_SELF */
1287 p_ptr->update |= (PU_BONUS);
1291 /* Redraw inscription */
1292 p_ptr->window |= (PW_INVEN);
1298 * Automatically destroy items in this grid.
1300 static bool is_opt_confirm_destroy(object_type *o_ptr)
1302 if (!destroy_items) return FALSE;
1304 /* Known to be worthless? */
1306 if (object_value(o_ptr) > 0) return FALSE;
1309 if ((o_ptr->tval >= TV_SHOT) && (o_ptr->tval <= TV_DRAG_ARMOR)) return FALSE;
1312 if ((o_ptr->tval == TV_CHEST) && o_ptr->pval) return FALSE;
1316 if (o_ptr->tval == TV_CORPSE
1317 && object_is_shoukinkubi(o_ptr)) return FALSE;
1321 if (o_ptr->tval == TV_CORPSE) return FALSE;
1324 if ((o_ptr->tval == TV_SKELETON) || (o_ptr->tval == TV_BOTTLE) || (o_ptr->tval == TV_JUNK) || (o_ptr->tval == TV_STATUE)) return FALSE;
1328 if (p_ptr->prace == RACE_DEMON)
1330 if (o_ptr->tval == TV_CORPSE &&
1331 o_ptr->sval == SV_CORPSE &&
1332 strchr("pht", r_info[o_ptr->pval].d_char))
1336 if (p_ptr->pclass == CLASS_ARCHER)
1338 if (o_ptr->tval == TV_SKELETON ||
1339 (o_ptr->tval == TV_CORPSE && o_ptr->sval == SV_SKELETON))
1342 else if (p_ptr->pclass == CLASS_NINJA)
1344 if (o_ptr->tval == TV_LITE &&
1345 o_ptr->name2 == EGO_LITE_DARKNESS)
1348 else if (p_ptr->pclass == CLASS_BEASTMASTER ||
1349 p_ptr->pclass == CLASS_CAVALRY)
1351 if (o_ptr->tval == TV_WAND &&
1352 o_ptr->sval == SV_WAND_HEAL_MONSTER)
1357 if (o_ptr->tval == TV_GOLD) return FALSE;
1364 * Automatically destroy an item if it is to be destroyed
1366 static object_type autopick_last_destroyed_object;
1368 bool auto_destroy_item(int item, int autopick_idx)
1370 bool destroy = FALSE;
1373 /* Don't destroy equipped items */
1374 if (item > INVEN_PACK) return FALSE;
1376 /* Get the item (in the pack) */
1377 if (item >= 0) o_ptr = &inventory[item];
1379 /* Get the item (on the floor) */
1380 else o_ptr = &o_list[0 - item];
1382 /* Easy-Auto-Destroyer */
1383 if (is_opt_confirm_destroy(o_ptr)) destroy = TRUE;
1385 /* Protected by auto-picker */
1386 if (autopick_idx >= 0 &&
1387 !(autopick_list[autopick_idx].action & DO_AUTODESTROY))
1392 /* Auto-picker/destroyer */
1393 if (autopick_idx >= 0 &&
1394 (autopick_list[autopick_idx].action & DO_AUTODESTROY))
1398 /* Not to be destroyed */
1399 if (!destroy) return FALSE;
1401 /* Now decided to destroy */
1406 if (!can_player_destroy_object(o_ptr))
1408 char o_name[MAX_NLEN];
1410 /* Describe the object (with {terrible/special}) */
1411 object_desc(o_name, o_ptr, TRUE, 3);
1415 msg_format("%s¤ÏÇ˲õÉÔǽ¤À¡£", o_name);
1417 msg_format("You cannot auto-destroy %s.", o_name);
1424 /* Record name of destroyed item */
1425 COPY(&autopick_last_destroyed_object, o_ptr, object_type);
1428 o_ptr->marked |= OM_AUTODESTROY;
1429 p_ptr->notice |= PN_AUTODESTROY;
1436 * Auto-destroy marked item
1438 static void delayed_auto_destroy_aux(int item)
1442 /* Get the item (in the pack) */
1443 if (item >= 0) o_ptr = &inventory[item];
1445 /* Get the item (on the floor) */
1446 else o_ptr = &o_list[0 - item];
1448 if (o_ptr->k_idx && o_ptr->marked & OM_AUTODESTROY)
1450 char o_name[MAX_NLEN];
1452 /* Describe the object (with {terrible/special}) */
1453 object_desc(o_name, o_ptr, TRUE, 3);
1455 /* Eliminate the item (from the pack) */
1458 inven_item_increase(item, -(o_ptr->number));
1459 inven_item_optimize(item);
1462 /* Eliminate the item (from the floor) */
1465 delete_object_idx(0 - item);
1468 /* Print a message */
1470 msg_format("%s¤ò¼«Æ°Ç˲õ¤·¤Þ¤¹¡£", o_name);
1472 msg_format("Auto-destroying %s.", o_name);
1479 * Auto-destroy marked item in inventry and on floor
1481 void delayed_auto_destroy(void)
1486 * Scan inventry in reverse order to prevent
1487 * skipping after inven_item_optimize()
1489 for (item = INVEN_TOTAL - 1; item >= 0 ; item--)
1490 delayed_auto_destroy_aux(item);
1492 /* Scan the pile of objects */
1493 item = cave[py][px].o_idx;
1496 int next = o_list[item].next_o_idx;
1497 delayed_auto_destroy_aux(-item);
1504 * Automatically pickup/destroy items in this grid.
1506 void auto_pickup_items(cave_type *c_ptr)
1508 s16b this_o_idx, next_o_idx = 0;
1510 /* Scan the pile of objects */
1511 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1515 /* Acquire object */
1516 object_type *o_ptr = &o_list[this_o_idx];
1518 /* Acquire next object */
1519 next_o_idx = o_ptr->next_o_idx;
1521 idx = is_autopick(o_ptr);
1523 /* Item index for floor -1,-2,-3,... */
1524 auto_inscribe_item((-this_o_idx), idx);
1527 (autopick_list[idx].action & (DO_AUTOPICK | DO_QUERY_AUTOPICK)))
1531 if (!inven_carry_okay(o_ptr))
1533 char o_name[MAX_NLEN];
1535 /* Describe the object */
1536 object_desc(o_name, o_ptr, TRUE, 3);
1540 msg_format("¥¶¥Ã¥¯¤Ë¤Ï%s¤òÆþ¤ì¤ë·ä´Ö¤¬¤Ê¤¤¡£", o_name);
1542 msg_format("You have no room for %s.", o_name);
1544 /* Hack - remember that the item has given a message here. */
1545 o_ptr->marked |= OM_NOMSG;
1549 else if (autopick_list[idx].action & DO_QUERY_AUTOPICK)
1551 char out_val[MAX_NLEN+20];
1552 char o_name[MAX_NLEN];
1554 if (o_ptr->marked & OM_NO_QUERY)
1556 /* Already answered as 'No' */
1560 /* Describe the object */
1561 object_desc(o_name, o_ptr, TRUE, 3);
1564 sprintf(out_val, "%s¤ò½¦¤¤¤Þ¤¹¤«? ", o_name);
1566 sprintf(out_val, "Pick up %s? ", o_name);
1569 if (!get_check(out_val))
1571 /* Hack - remember that the item has given a message here. */
1572 o_ptr->marked |= (OM_NOMSG | OM_NO_QUERY);
1577 py_pickup_aux(this_o_idx);
1584 * When always_pickup is 'yes', we disable
1585 * auto-destroyer from autopick function, and do only
1586 * easy-auto-destroyer.
1590 if (auto_destroy_item((-this_o_idx), idx))
1597 #define PT_DEFAULT 0
1598 #define PT_WITH_PNAME 1
1601 * Get file name for autopick preference
1603 static cptr pickpref_filename(int filename_mode)
1606 static const char namebase[] = "picktype";
1608 static const char namebase[] = "pickpref";
1611 switch (filename_mode)
1614 return format("%s.prf", namebase);
1617 return format("%s-%s.prf", namebase, player_name);
1625 static const char autoregister_header[] = "?:$AUTOREGISTER";
1628 * Clear auto registered lines in the picktype.prf .
1630 static bool clear_auto_register(void)
1632 char tmp_file[1024];
1633 char pref_file[1024];
1638 bool autoregister = FALSE;
1641 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_WITH_PNAME));
1642 pref_fff = my_fopen(pref_file, "r");
1646 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_DEFAULT));
1647 pref_fff = my_fopen(pref_file, "r");
1656 /* Open a new (temporary) file */
1657 tmp_fff = my_fopen_temp(tmp_file, sizeof(tmp_file));
1661 /* Close the preference file */
1665 msg_format("°ì»þ¥Õ¥¡¥¤¥ë %s ¤òºîÀ®¤Ç¤¤Þ¤»¤ó¤Ç¤·¤¿¡£", tmp_file);
1667 msg_format("Failed to create temporary file %s.", tmp_file);
1674 /* Loop for every line */
1678 if (my_fgets(pref_fff, buf, sizeof(buf))) break;
1682 /* Delete auto-registered line */
1684 /* Count auto-destroy preference lines */
1685 if (buf[0] != '#' && buf[0] != '?') num++;
1688 /* We are looking for auto-registered line */
1691 if (streq(buf, autoregister_header))
1693 /* Delete all further lines */
1694 autoregister = TRUE;
1698 /* Copy orginally lines */
1699 fprintf(tmp_fff, "%s\n", buf);
1705 my_fclose(pref_fff);
1711 msg_format("°ÊÁ°¤Î¥¥ã¥é¥¯¥¿¡¼ÍѤμ«Æ°ÀßÄê(%d¹Ô)¤¬»Ä¤Ã¤Æ¤¤¤Þ¤¹¡£", num);
1712 strcpy(buf, "¸Å¤¤ÀßÄê¹Ô¤Ïºï½ü¤·¤Þ¤¹¡£¤è¤í¤·¤¤¤Ç¤¹¤«¡©");
1714 msg_format("Auto registered lines (%d lines) for previous character are remaining.", num);
1715 strcpy(buf, "These lines will be deleted. Are you sure? ");
1718 /* You can cancel it */
1719 if (!get_check(buf))
1722 autoregister = FALSE;
1725 msg_print("¥¨¥Ç¥£¥¿¤Î¥«¥Ã¥È&¥Ú¡¼¥¹¥ÈÅù¤ò»È¤Ã¤ÆɬÍפʹԤòÈòÆñ¤·¤Æ¤¯¤À¤µ¤¤¡£");
1727 msg_print("Use cut & paste of auto picker editor (_) to keep old prefs.");
1733 /* If there are some changes, overwrite the original file with new one */
1736 /* Copy contents of temporary file */
1738 tmp_fff = my_fopen(tmp_file, "r");
1739 pref_fff = my_fopen(pref_file, "w");
1741 while (!my_fgets(tmp_fff, buf, sizeof(buf)))
1742 fprintf(pref_fff, "%s\n", buf);
1744 my_fclose(pref_fff);
1748 /* Kill the temporary file */
1756 * Automatically register an auto-destroy preference line
1758 bool add_auto_register(object_type *o_ptr)
1761 char pref_file[1024];
1763 autopick_type an_entry, *entry = &an_entry;
1765 int match_autopick = is_autopick(o_ptr);
1767 /* Already registered */
1768 if (match_autopick != -1)
1771 byte act = autopick_list[match_autopick].action;
1774 if (act & DO_AUTOPICK) what = "¼«Æ°¤Ç½¦¤¦";
1775 else if (act & DO_AUTODESTROY) what = "¼«Æ°Ç˲õ¤¹¤ë";
1776 else if (act & DONT_AUTOPICK) what = "ÊüÃÖ¤¹¤ë";
1777 else /* if (act & DO_QUERY_AUTOPICK) */ what = "³Îǧ¤·¤Æ½¦¤¦";
1779 msg_format("¤½¤Î¥¢¥¤¥Æ¥à¤Ï´û¤Ë%s¤è¤¦¤ËÀßÄꤵ¤ì¤Æ¤¤¤Þ¤¹¡£", what);
1781 if (act & DO_AUTOPICK) what = "auto-pickup";
1782 else if (act & DO_AUTODESTROY) what = "auto-destroy";
1783 else if (act & DONT_AUTOPICK) what = "leave on floor";
1784 else /* if (act & DO_QUERY_AUTOPICK) */ what = "query auto-pickup";
1786 msg_format("The object is already registered to %s.", what);
1793 if (!p_ptr->autopick_autoregister)
1795 /* Clear old auto registered lines */
1796 if (!clear_auto_register()) return FALSE;
1799 /* Try a filename with player name */
1800 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_WITH_PNAME));
1801 pref_fff = my_fopen(pref_file, "r");
1805 /* Use default name */
1806 path_build(pref_file, sizeof(pref_file), ANGBAND_DIR_USER, pickpref_filename(PT_DEFAULT));
1807 pref_fff = my_fopen(pref_file, "r");
1810 /* Check the header */
1814 if (my_fgets(pref_fff, buf, sizeof(buf)))
1816 /* No header found */
1817 p_ptr->autopick_autoregister = FALSE;
1822 if (streq(buf, autoregister_header))
1824 /* Found the header */
1825 p_ptr->autopick_autoregister = TRUE;
1831 /* Close read only FILE* */
1834 /* Open for append */
1835 pref_fff = my_fopen(pref_file, "a");
1840 msg_format("%s ¤ò³«¤¯¤³¤È¤¬¤Ç¤¤Þ¤»¤ó¤Ç¤·¤¿¡£", pref_file);
1842 msg_format("Failed to open %s.", pref_file);
1850 if (!p_ptr->autopick_autoregister)
1852 /* Add the header */
1853 fprintf(pref_fff, "%s\n", autoregister_header);
1856 fprintf(pref_fff, "%s\n", "# *·Ù¹ð!!* °Ê¹ß¤Î¹Ô¤Ï¼«Æ°ÅÐÏ¿¤µ¤ì¤¿¤â¤Î¤Ç¤¹¡£");
1857 fprintf(pref_fff, "%s\n", "# ¸å¤Ç¼«Æ°Åª¤Ëºï½ü¤µ¤ì¤Þ¤¹¤Î¤Ç¡¢É¬ÍפʹԤϾå¤ÎÊý¤Ø°ÜÆ°¤·¤Æ¤ª¤¤¤Æ¤¯¤À¤µ¤¤¡£");
1859 fprintf(pref_fff, "%s\n", "# *Waring!* The lines below will be deleated later.");
1860 fprintf(pref_fff, "%s\n", "# Keep it by cut & paste if you need these lines for future characters.");
1863 /* Now auto register is in-use */
1864 p_ptr->autopick_autoregister = TRUE;
1867 /* Get a preference entry */
1868 autopick_entry_from_object(entry, o_ptr);
1870 /* Set to auto-destroy (with no-display) */
1871 entry->action = DO_AUTODESTROY;
1873 /* Load the new line as preference */
1874 add_autopick_list(entry);
1876 /* Add a line to the file */
1877 /* Don't kill "entry" */
1878 fprintf(pref_fff, "%s\n", autopick_line_from_entry(entry));
1880 /* Close the file */
1887 /******** Auto-picker/destroyer editor **********/
1889 #define MAX_YANK MAX_LINELEN
1890 #define MAX_LINES 3000
1892 #define MARK_MARK 0x01
1893 #define MARK_BY_SHIFT 0x02
1895 #define LSTAT_BYPASS 0x01
1896 #define LSTAT_EXPRESSION 0x02
1897 #define LSTAT_AUTOREGISTER 0x04
1899 #define QUIT_WITHOUT_SAVE 1
1900 #define QUIT_AND_SAVE 2
1903 * Struct for yank buffer
1905 typedef struct chain_str {
1906 struct chain_str *next;
1912 * Data struct for text editor
1918 int old_wid, old_hgt;
1920 int old_upper, old_left;
1924 object_type *search_o_ptr;
1926 cptr last_destroyed;
1928 chain_str_type *yank;
1932 byte states[MAX_LINES];
1944 * Dirty flag for text editor
1946 #define DIRTY_ALL 0x01
1947 #define DIRTY_MODE 0x04
1948 #define DIRTY_SCREEN 0x08
1949 #define DIRTY_NOT_FOUND 0x10
1950 #define DIRTY_NO_SEARCH 0x20
1951 #define DIRTY_EXPRESSION 0x40
1955 * Describe which kind of object is Auto-picked/destroyed
1957 static void describe_autopick(char *buff, autopick_type *entry)
1959 cptr str = entry->name;
1960 byte act = entry->action;
1961 cptr insc = entry->insc;
1967 cptr before_str[100], body_str;
1970 body_str = "¥¢¥¤¥Æ¥à";
1972 /*** Collecting items ***/
1973 /*** Which can be absorbed into a slot as a bundle ***/
1974 if (IS_FLG(FLG_COLLECTING))
1975 before_str[before_n++] = "¼ý½¸Ãæ¤Ç´û¤Ë»ý¤Ã¤Æ¤¤¤ë¥¹¥í¥Ã¥È¤Ë¤Þ¤È¤á¤é¤ì¤ë";
1977 /*** Unidentified ***/
1978 if (IS_FLG(FLG_UNIDENTIFIED))
1979 before_str[before_n++] = "̤´ÕÄê¤Î";
1981 /*** Identified ***/
1982 if (IS_FLG(FLG_IDENTIFIED))
1983 before_str[before_n++] = "´ÕÄêºÑ¤ß¤Î";
1985 /*** *Identified* ***/
1986 if (IS_FLG(FLG_STAR_IDENTIFIED))
1987 before_str[before_n++] = "´°Á´¤Ë´ÕÄêºÑ¤ß¤Î";
1989 /*** Dice boosted (weapon of slaying) ***/
1990 if (IS_FLG(FLG_BOOSTED))
1992 before_str[before_n++] = "¥À¥á¡¼¥¸¥À¥¤¥¹¤¬Ä̾ï¤è¤êÂ礤¤";
1996 /*** Weapons whose dd*ds is more than nn ***/
1997 if (IS_FLG(FLG_MORE_THAN))
1999 static char more_than_desc_str[] = "___";
2000 before_str[before_n++] = "¥À¥á¡¼¥¸¥À¥¤¥¹¤ÎºÇÂçÃͤ¬";
2003 sprintf(more_than_desc_str,"%d", entry->dice);
2004 before_str[before_n++] = more_than_desc_str;
2005 before_str[before_n++] = "°Ê¾å¤Î";
2008 /*** Items whose magical bonus is more than nn ***/
2009 if (IS_FLG(FLG_MORE_BONUS))
2011 static char more_bonus_desc_str[] = "___";
2012 before_str[before_n++] = "½¤ÀµÃͤ¬(+";
2014 sprintf(more_bonus_desc_str,"%d", entry->bonus);
2015 before_str[before_n++] = more_bonus_desc_str;
2016 before_str[before_n++] = ")°Ê¾å¤Î";
2019 /*** Worthless items ***/
2020 if (IS_FLG(FLG_WORTHLESS))
2021 before_str[before_n++] = "Ź¤Ç̵²ÁÃͤÈȽÄꤵ¤ì¤ë";
2024 if (IS_FLG(FLG_ARTIFACT))
2026 before_str[before_n++] = "¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È¤Î";
2031 if (IS_FLG(FLG_EGO))
2033 before_str[before_n++] = "¥¨¥´¥¢¥¤¥Æ¥à¤Î";
2038 if (IS_FLG(FLG_NAMELESS))
2040 before_str[before_n++] = "¥¨¥´¤Ç¤â¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È¤Ç¤â¤Ê¤¤";
2044 /*** Unaware items ***/
2045 if (IS_FLG(FLG_UNAWARE))
2046 before_str[before_n++] = "̤´ÕÄê¤Ç¤½¤Î¸ú²Ì¤âȽÌÀ¤·¤Æ¤¤¤Ê¤¤";
2048 /*** Wanted monster's corpse/skeletons ***/
2049 if (IS_FLG(FLG_WANTED))
2051 before_str[before_n++] = "¥Ï¥ó¥¿¡¼»ö̳½ê¤Ç¾Þ¶â¼ó¤È¤µ¤ì¤Æ¤¤¤ë";
2052 body_str = "»àÂΤä¹ü";
2055 /*** Human corpse/skeletons (for Daemon magic) ***/
2056 if (IS_FLG(FLG_HUMAN))
2058 before_str[before_n++] = "°ËâËâË¡¤Ç»È¤¦¤¿¤á¤Î¿Í´Ö¤ä¥Ò¥å¡¼¥Þ¥Î¥¤¥É¤Î";
2059 body_str = "»àÂΤä¹ü";
2062 /*** Unique monster's corpse/skeletons/statues ***/
2063 if (IS_FLG(FLG_UNIQUE))
2065 before_str[before_n++] = "¥æ¥Ë¡¼¥¯¥â¥ó¥¹¥¿¡¼¤Î";
2066 body_str = "»àÂΤä¹ü";
2069 /*** Unreadable spellbooks ***/
2070 if (IS_FLG(FLG_UNREADABLE))
2072 before_str[before_n++] = "¤¢¤Ê¤¿¤¬Æɤá¤Ê¤¤Îΰè¤Î";
2073 body_str = "ËâË¡½ñ";
2076 /*** First realm spellbooks ***/
2077 if (IS_FLG(FLG_REALM1))
2079 before_str[before_n++] = "Âè°ìÎΰè¤Î";
2080 body_str = "ËâË¡½ñ";
2083 /*** Second realm spellbooks ***/
2084 if (IS_FLG(FLG_REALM2))
2086 before_str[before_n++] = "ÂèÆóÎΰè¤Î";
2087 body_str = "ËâË¡½ñ";
2090 /*** First rank spellbooks ***/
2091 if (IS_FLG(FLG_FIRST))
2093 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î1ºýÌܤÎ";
2094 body_str = "ËâË¡½ñ";
2097 /*** Second rank spellbooks ***/
2098 if (IS_FLG(FLG_SECOND))
2100 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î2ºýÌܤÎ";
2101 body_str = "ËâË¡½ñ";
2104 /*** Third rank spellbooks ***/
2105 if (IS_FLG(FLG_THIRD))
2107 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î3ºýÌܤÎ";
2108 body_str = "ËâË¡½ñ";
2111 /*** Fourth rank spellbooks ***/
2112 if (IS_FLG(FLG_FOURTH))
2114 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î4ºýÌܤÎ";
2115 body_str = "ËâË¡½ñ";
2119 if (IS_FLG(FLG_ITEMS))
2120 ; /* Nothing to do */
2121 else if (IS_FLG(FLG_WEAPONS))
2123 else if (IS_FLG(FLG_ARMORS))
2125 else if (IS_FLG(FLG_MISSILES))
2126 body_str = "ÃƤäÌð¤ä¥¯¥í¥¹¥Ü¥¦¤ÎÌð";
2127 else if (IS_FLG(FLG_DEVICES))
2128 body_str = "´¬Êª¤äËâË¡ËÀ¤ä¾ó¤ä¥í¥Ã¥É";
2129 else if (IS_FLG(FLG_LIGHTS))
2130 body_str = "¸÷¸»ÍѤΥ¢¥¤¥Æ¥à";
2131 else if (IS_FLG(FLG_JUNKS))
2132 body_str = "Àޤ줿ËÀÅù¤Î¥¬¥é¥¯¥¿";
2133 else if (IS_FLG(FLG_SPELLBOOKS))
2134 body_str = "ËâË¡½ñ";
2135 else if (IS_FLG(FLG_HAFTED))
2137 else if (IS_FLG(FLG_SHIELDS))
2139 else if (IS_FLG(FLG_BOWS))
2140 body_str = "¥¹¥ê¥ó¥°¤äµÝ¤ä¥¯¥í¥¹¥Ü¥¦";
2141 else if (IS_FLG(FLG_RINGS))
2143 else if (IS_FLG(FLG_AMULETS))
2144 body_str = "¥¢¥ß¥å¥ì¥Ã¥È";
2145 else if (IS_FLG(FLG_SUITS))
2147 else if (IS_FLG(FLG_CLOAKS))
2148 body_str = "¥¯¥í¡¼¥¯";
2149 else if (IS_FLG(FLG_HELMS))
2150 body_str = "¥Ø¥ë¥á¥Ã¥È¤ä´§";
2151 else if (IS_FLG(FLG_GLOVES))
2153 else if (IS_FLG(FLG_BOOTS))
2154 body_str = "¥Ö¡¼¥Ä";
2155 else if (IS_FLG(FLG_FAVORITE))
2156 body_str = "ÆÀ°ÕÉð´ï";
2160 strcat(buff, "Á´¤Æ¤Î");
2161 else for (i = 0; i < before_n && before_str[i]; i++)
2162 strcat(buff, before_str[i]);
2164 strcat(buff, body_str);
2174 strcat(buff, "¤Ç¡¢Ì¾Á°¤¬¡Ö");
2175 strncat(buff, str, 80);
2177 strcat(buff, "¡×¤Ç»Ï¤Þ¤ë¤â¤Î");
2179 strcat(buff, "¡×¤ò´Þ¤à¤â¤Î");
2184 strncat(buff, format("¤Ë¡Ö%s¡×", insc), 80);
2186 if (strstr(insc, "%%all"))
2187 strcat(buff, "(%%all¤ÏÁ´Ç½ÎϤòɽ¤¹±Ñ»ú¤Îµ¹æ¤ÇÃÖ´¹)");
2188 else if (strstr(insc, "%all"))
2189 strcat(buff, "(%all¤ÏÁ´Ç½ÎϤòɽ¤¹µ¹æ¤ÇÃÖ´¹)");
2190 else if (strstr(insc, "%%"))
2191 strcat(buff, "(%%¤ÏÄɲÃǽÎϤòɽ¤¹±Ñ»ú¤Îµ¹æ¤ÇÃÖ´¹)");
2192 else if (strstr(insc, "%"))
2193 strcat(buff, "(%¤ÏÄɲÃǽÎϤòɽ¤¹µ¹æ¤ÇÃÖ´¹)");
2195 strcat(buff, "¤È¹ï¤ó¤Ç");
2200 if (act & DONT_AUTOPICK)
2201 strcat(buff, "ÊüÃÖ¤¹¤ë¡£");
2202 else if (act & DO_AUTODESTROY)
2203 strcat(buff, "Ç˲õ¤¹¤ë¡£");
2204 else if (act & DO_QUERY_AUTOPICK)
2205 strcat(buff, "³Îǧ¤Î¸å¤Ë½¦¤¦¡£");
2207 strcat(buff, "½¦¤¦¡£");
2209 if (act & DO_DISPLAY)
2211 if (act & DONT_AUTOPICK)
2212 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'N'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
2213 else if (act & DO_AUTODESTROY)
2214 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'K'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
2216 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'M'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
2219 strcat(buff, "Á´ÂΥޥåפˤÏɽ¼¨¤·¤Ê¤¤");
2223 cptr before_str[20], after_str[20], which_str[20], whose_str[20], body_str;
2224 int before_n = 0, after_n = 0, which_n = 0, whose_n = 0;
2228 /*** Collecting items ***/
2229 /*** Which can be absorbed into a slot as a bundle ***/
2230 if (IS_FLG(FLG_COLLECTING))
2231 which_str[which_n++] = "can be absorbed into an existing inventory slot";
2233 /*** Unidentified ***/
2234 if (IS_FLG(FLG_UNIDENTIFIED))
2235 before_str[before_n++] = "unidentified";
2237 /*** Identified ***/
2238 if (IS_FLG(FLG_IDENTIFIED))
2239 before_str[before_n++] = "identified";
2241 /*** *Identified* ***/
2242 if (IS_FLG(FLG_STAR_IDENTIFIED))
2243 before_str[before_n++] = "fully identified";
2245 /*** Worthless items ***/
2246 if (IS_FLG(FLG_WORTHLESS))
2248 before_str[before_n++] = "worthless";
2249 which_str[which_n++] = "can not be sold at stores";
2253 if (IS_FLG(FLG_ARTIFACT))
2255 before_str[before_n++] = "artifact";
2259 if (IS_FLG(FLG_EGO))
2261 before_str[before_n++] = "ego";
2265 if (IS_FLG(FLG_NAMELESS))
2267 body_str = "equipment";
2268 which_str[which_n++] = "is neither ego-item nor artifact";
2271 /*** Unaware items ***/
2272 if (IS_FLG(FLG_UNAWARE))
2274 before_str[before_n++] = "unidentified";
2275 whose_str[whose_n++] = "basic abilities are not known";
2278 /*** Dice boosted (weapon of slaying) ***/
2279 if (IS_FLG(FLG_BOOSTED))
2281 body_str = "weapons";
2282 whose_str[whose_n++] = "damage dice is bigger than normal";
2285 /*** Weapons whose dd*ds is more than nn ***/
2286 if (IS_FLG(FLG_MORE_THAN))
2288 static char more_than_desc_str[] =
2289 "maximum damage from dice is bigger than __";
2290 body_str = "weapons";
2292 sprintf(more_than_desc_str + sizeof(more_than_desc_str) - 3,
2294 whose_str[whose_n++] = more_than_desc_str;
2297 /*** Items whose magical bonus is more than nn ***/
2298 if (IS_FLG(FLG_MORE_BONUS))
2300 static char more_bonus_desc_str[] =
2301 "magical bonus is bigger than (+__)";
2303 sprintf(more_bonus_desc_str + sizeof(more_bonus_desc_str) - 4,
2304 "%d)", entry->bonus);
2305 whose_str[whose_n++] = more_bonus_desc_str;
2308 /*** Wanted monster's corpse/skeletons ***/
2309 if (IS_FLG(FLG_WANTED))
2311 body_str = "corpse or skeletons";
2312 which_str[which_n++] = "is wanted at the Hunter's Office";
2315 /*** Human corpse/skeletons (for Daemon magic) ***/
2316 if (IS_FLG(FLG_HUMAN))
2318 before_str[before_n++] = "humanoid";
2319 body_str = "corpse or skeletons";
2320 which_str[which_n++] = "can be used for Daemon magic";
2323 /*** Unique monster's corpse/skeletons/statues ***/
2324 if (IS_FLG(FLG_UNIQUE))
2326 before_str[before_n++] = "unique monster's";
2327 body_str = "corpse or skeletons";
2330 /*** Unreadable spellbooks ***/
2331 if (IS_FLG(FLG_UNREADABLE))
2333 body_str = "spellbooks";
2334 after_str[after_n++] = "of different realms from yours";
2337 /*** First realm spellbooks ***/
2338 if (IS_FLG(FLG_REALM1))
2340 body_str = "spellbooks";
2341 after_str[after_n++] = "of your first realm";
2344 /*** Second realm spellbooks ***/
2345 if (IS_FLG(FLG_REALM2))
2347 body_str = "spellbooks";
2348 after_str[after_n++] = "of your second realm";
2351 /*** First rank spellbooks ***/
2352 if (IS_FLG(FLG_FIRST))
2354 before_str[before_n++] = "first one of four";
2355 body_str = "spellbooks";
2358 /*** Second rank spellbooks ***/
2359 if (IS_FLG(FLG_SECOND))
2361 before_str[before_n++] = "second one of four";
2362 body_str = "spellbooks";
2365 /*** Third rank spellbooks ***/
2366 if (IS_FLG(FLG_THIRD))
2368 before_str[before_n++] = "third one of four";
2369 body_str = "spellbooks";
2372 /*** Fourth rank spellbooks ***/
2373 if (IS_FLG(FLG_FOURTH))
2375 before_str[before_n++] = "fourth one of four";
2376 body_str = "spellbooks";
2380 if (IS_FLG(FLG_ITEMS))
2381 ; /* Nothing to do */
2382 else if (IS_FLG(FLG_WEAPONS))
2383 body_str = "weapons";
2384 else if (IS_FLG(FLG_ARMORS))
2385 body_str = "armors";
2386 else if (IS_FLG(FLG_MISSILES))
2387 body_str = "shots, arrows or crossbow bolts";
2388 else if (IS_FLG(FLG_DEVICES))
2389 body_str = "scrolls, wands, staves or rods";
2390 else if (IS_FLG(FLG_LIGHTS))
2391 body_str = "light sources";
2392 else if (IS_FLG(FLG_JUNKS))
2393 body_str = "junk such as broken sticks";
2394 else if (IS_FLG(FLG_SPELLBOOKS))
2395 body_str = "spellbooks";
2396 else if (IS_FLG(FLG_HAFTED))
2397 body_str = "hafted weapons";
2398 else if (IS_FLG(FLG_SHIELDS))
2399 body_str = "shields";
2400 else if (IS_FLG(FLG_BOWS))
2401 body_str = "slings, bows or crossbows";
2402 else if (IS_FLG(FLG_RINGS))
2404 else if (IS_FLG(FLG_AMULETS))
2405 body_str = "amulets";
2406 else if (IS_FLG(FLG_SUITS))
2407 body_str = "body armors";
2408 else if (IS_FLG(FLG_CLOAKS))
2409 body_str = "cloaks";
2410 else if (IS_FLG(FLG_HELMS))
2411 body_str = "helms or crowns";
2412 else if (IS_FLG(FLG_GLOVES))
2413 body_str = "gloves";
2414 else if (IS_FLG(FLG_BOOTS))
2416 else if (IS_FLG(FLG_FAVORITE))
2417 body_str = "favorite weapons";
2419 /* Prepare a string for item name */
2426 whose_str[whose_n++] = "name is beginning with \"";
2429 which_str[which_n++] = "have \"";
2433 /* Describe action flag */
2434 if (act & DONT_AUTOPICK)
2435 strcpy(buff, "Leave on floor ");
2436 else if (act & DO_AUTODESTROY)
2437 strcpy(buff, "Destroy ");
2438 else if (act & DO_QUERY_AUTOPICK)
2439 strcpy(buff, "Ask to pick up ");
2441 strcpy(buff, "Pickup ");
2443 /* Auto-insctiption */
2446 strncat(buff, format("and inscribe \"%s\"", insc), 80);
2448 if (strstr(insc, "%all"))
2449 strcat(buff, ", replacing %all with code string representing all abilities,");
2450 else if (strstr(insc, "%"))
2451 strcat(buff, ", replacing % with code string representing extra random abilities,");
2453 strcat(buff, " on ");
2458 strcat(buff, "all ");
2459 else for (i = 0; i < before_n && before_str[i]; i++)
2461 strcat(buff, before_str[i]);
2466 strcat(buff, body_str);
2469 for (i = 0; i < after_n && after_str[i]; i++)
2472 strcat(buff, after_str[i]);
2476 for (i = 0; i < whose_n && whose_str[i]; i++)
2479 strcat(buff, " whose ");
2481 strcat(buff, ", and ");
2483 strcat(buff, whose_str[i]);
2486 /* Item name ; whose name is beginning with "str" */
2493 /* whose ..., and which .... */
2494 if (whose_n && which_n)
2495 strcat(buff, ", and ");
2498 for (i = 0; i < which_n && which_str[i]; i++)
2501 strcat(buff, " which ");
2503 strcat(buff, ", and ");
2505 strcat(buff, which_str[i]);
2508 /* Item name ; which have "str" as part of its name */
2511 strncat(buff, str, 80);
2512 strcat(buff, "\" as part of its name");
2516 /* Describe whether it will be displayed on the full map or not */
2517 if (act & DO_DISPLAY)
2519 if (act & DONT_AUTOPICK)
2520 strcat(buff, " Display these items when you press the N key in the full 'M'ap.");
2521 else if (act & DO_AUTODESTROY)
2522 strcat(buff, " Display these items when you press the K key in the full 'M'ap.");
2524 strcat(buff, " Display these items when you press the M key in the full 'M'ap.");
2527 strcat(buff, " Not displayed in the full map.");
2534 * Read whole lines of a file to memory
2536 static cptr *read_text_lines(cptr filename, bool user)
2538 cptr *lines_list = NULL;
2546 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2550 path_build(buf, sizeof(buf), ANGBAND_DIR_PREF, filename);
2554 fff = my_fopen(buf, "r");
2558 /* Allocate list of pointers */
2559 C_MAKE(lines_list, MAX_LINES, cptr);
2562 while (0 == my_fgets(fff, buf, sizeof(buf)))
2564 lines_list[lines++] = string_make(buf);
2565 if (lines >= MAX_LINES - 1) break;
2568 lines_list[0] = string_make("");
2573 if (!fff) return NULL;
2578 static cptr *read_pickpref_text_lines(int *filename_mode_p)
2583 *filename_mode_p = PT_WITH_PNAME;
2584 strcpy(buf, pickpref_filename(*filename_mode_p));
2585 lines_list = read_text_lines(buf, TRUE);
2589 *filename_mode_p = PT_DEFAULT;
2590 strcpy(buf, pickpref_filename(*filename_mode_p));
2591 lines_list = read_text_lines(buf, TRUE);
2596 strcpy(buf, pickpref_filename(*filename_mode_p));
2597 lines_list = read_text_lines(buf, FALSE);
2602 /* Allocate list of pointers */
2603 C_MAKE(lines_list, MAX_LINES, cptr);
2604 lines_list[0] = string_make("");
2611 * Write whole lines of memory to a file.
2613 static bool write_text_lines(cptr filename, cptr *lines_list)
2620 /* Build the filename */
2621 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2624 fff = my_fopen(buf, "w");
2627 for (lines = 0; lines_list[lines]; lines++)
2628 my_fputs(fff, lines_list[lines], 1024);
2633 if (!fff) return FALSE;
2639 * Free memory of lines_list.
2641 static void free_text_lines(cptr *lines_list)
2645 for (lines = 0; lines_list[lines]; lines++)
2646 string_free(lines_list[lines]);
2648 /* free list of pointers */
2649 C_FREE((char **)lines_list, MAX_LINES, char *);
2654 * Delete or insert string
2656 static void toggle_keyword(text_body_type *tb, int flg)
2658 int by1, by2, bx1, bx2, y;
2662 /* Select this line */
2669 if (tb->my < tb->cy)
2684 /* String on these lines are not really selected */
2685 if (tb->lines_list[by1][bx1] == '\0' && by1 < tb->cy) by1++;
2686 if (bx2 == 0 && by1 < by2) by2--;
2689 /* Set/Reset flag of each line */
2690 for (y = by1; y <= by2; y++)
2692 autopick_type an_entry, *entry = &an_entry;
2694 if (!autopick_new_entry(entry, tb->lines_list[y], !fixed)) continue;
2696 string_free(tb->lines_list[y]);
2700 /* Add? or Remove? */
2701 if (!IS_FLG(flg)) add = TRUE;
2704 /* No more change */
2708 /* You can use only one noun flag */
2709 if (FLG_NOUN_BEGIN <= flg && flg <= FLG_NOUN_END)
2712 for (i = FLG_NOUN_BEGIN; i <= FLG_NOUN_END; i++)
2716 /* You can use only one identify state flag */
2717 else if (FLG_UNAWARE <= flg && flg <= FLG_STAR_IDENTIFIED)
2720 for (i = FLG_UNAWARE; i <= FLG_STAR_IDENTIFIED; i++)
2724 /* You can use only one flag in artifact/ego/nameless */
2725 else if (FLG_ARTIFACT <= flg && flg <= FLG_NAMELESS)
2728 for (i = FLG_ARTIFACT; i <= FLG_NAMELESS; i++)
2732 if (add) ADD_FLG(flg);
2735 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
2738 tb->dirty_flags |= DIRTY_ALL;
2740 /* Text is changed */
2747 * Change command letter
2749 static void toggle_command_letter(text_body_type *tb, byte flg)
2751 autopick_type an_entry, *entry = &an_entry;
2752 int by1, by2, bx1, bx2, y;
2756 /* Select this line */
2763 if (tb->my < tb->cy)
2778 /* String on these lines are not really selected */
2779 if (tb->lines_list[by1][bx1] == '\0' && by1 < tb->cy) by1++;
2780 if (bx2 == 0 && by1 < by2) by2--;
2782 /* Set/Reset flag of each line */
2783 for (y = by1; y <= by2; y++)
2787 if (!autopick_new_entry(entry, tb->lines_list[y], FALSE)) continue;
2789 string_free(tb->lines_list[y]);
2793 /* Add? or Remove? */
2794 if (!(entry->action & flg)) add = TRUE;
2797 /* No more change */
2801 /* Count number of letter (by negative number) */
2802 if (entry->action & DONT_AUTOPICK) wid--;
2803 else if (entry->action & DO_AUTODESTROY) wid--;
2804 else if (entry->action & DO_QUERY_AUTOPICK) wid--;
2805 if (!(entry->action & DO_DISPLAY)) wid--;
2807 /* Set/Reset the flag */
2808 if (flg != DO_DISPLAY)
2810 entry->action &= ~(DO_AUTOPICK | DONT_AUTOPICK | DO_AUTODESTROY | DO_QUERY_AUTOPICK);
2811 if (add) entry->action |= flg;
2812 else entry->action |= DO_AUTOPICK;
2816 entry->action &= ~(DO_DISPLAY);
2817 if (add) entry->action |= flg;
2820 /* Correct cursor location */
2823 if (entry->action & DONT_AUTOPICK) wid++;
2824 else if (entry->action & DO_AUTODESTROY) wid++;
2825 else if (entry->action & DO_QUERY_AUTOPICK) wid++;
2826 if (!(entry->action & DO_DISPLAY)) wid++;
2828 if (wid > 0) tb->cx++;
2829 if (wid < 0 && tb->cx > 0) tb->cx--;
2832 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
2835 tb->dirty_flags |= DIRTY_ALL;
2837 /* Text is changed */
2843 * Delete or insert string
2845 static void add_keyword(text_body_type *tb, int flg)
2847 int by1, by2, bx1, bx2, y;
2849 /* Select this line */
2856 if (tb->my < tb->cy)
2871 /* String on these lines are not really selected */
2872 if (tb->lines_list[by1][bx1] == '\0' && by1 < tb->cy) by1++;
2873 if (bx2 == 0 && by1 < by2) by2--;
2875 /* Set/Reset flag of each line */
2876 for (y = by1; y <= by2; y++)
2878 autopick_type an_entry, *entry = &an_entry;
2880 if (!autopick_new_entry(entry, tb->lines_list[y], FALSE)) continue;
2882 /* There is the flag already */
2885 /* Free memory for the entry */
2886 autopick_free_entry(entry);
2891 string_free(tb->lines_list[y]);
2893 /* Remove all noun flag */
2894 if (FLG_NOUN_BEGIN <= flg && flg <= FLG_NOUN_END)
2897 for (i = FLG_NOUN_BEGIN; i <= FLG_NOUN_END; i++)
2903 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
2906 tb->dirty_flags |= DIRTY_ALL;
2908 /* Text is changed */
2915 * Check if this line is expression or not.
2916 * And update it if it is.
2918 static void check_expression_line(text_body_type *tb, int y)
2920 cptr s = tb->lines_list[y];
2922 if ((s[0] == '?' && s[1] == ':') ||
2923 (tb->states[y] & LSTAT_BYPASS))
2925 /* Expressions need re-evaluation */
2926 tb->dirty_flags |= DIRTY_EXPRESSION;
2932 * Insert return code and split the line
2934 static bool insert_return_code(text_body_type *tb)
2936 char buf[MAX_LINELEN];
2939 for (k = 0; tb->lines_list[k]; k++)
2940 /* count number of lines */ ;
2942 if (k >= MAX_LINES - 2) return FALSE;
2945 /* Move down lines */
2946 for (; tb->cy < k; k--)
2948 tb->lines_list[k+1] = tb->lines_list[k];
2949 tb->states[k+1] = tb->states[k];
2952 /* Split current line */
2953 for (i = j = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
2956 if (iskanji(tb->lines_list[tb->cy][i]))
2957 buf[j++] = tb->lines_list[tb->cy][i++];
2959 buf[j++] = tb->lines_list[tb->cy][i];
2962 tb->lines_list[tb->cy+1] = string_make(&tb->lines_list[tb->cy][i]);
2963 string_free(tb->lines_list[tb->cy]);
2964 tb->lines_list[tb->cy] = string_make(buf);
2966 /* Expressions need re-evaluation */
2967 tb->dirty_flags |= DIRTY_EXPRESSION;
2969 /* Text is changed */
2977 * Choose an item and get auto-picker entry from it.
2979 static object_type *choose_object(cptr q, cptr s)
2983 if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR | USE_EQUIP))) return NULL;
2985 /* Get the item (in the pack) */
2986 if (item >= 0) return &inventory[item];
2988 /* Get the item (on the floor) */
2989 else return &o_list[0 - item];
2994 * Choose an item and get auto-picker entry from it.
2996 static bool entry_from_choosed_object(autopick_type *entry)
3003 q = "¤É¤Î¥¢¥¤¥Æ¥à¤òÅÐÏ¿¤·¤Þ¤¹¤«? ";
3004 s = "¥¢¥¤¥Æ¥à¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£";
3006 q = "Enter which item? ";
3007 s = "You have nothing to enter.";
3009 o_ptr = choose_object(q, s);
3010 if (!o_ptr) return FALSE;
3012 autopick_entry_from_object(entry, o_ptr);
3018 * Choose an item for search
3020 static byte get_object_for_search(object_type **o_handle, cptr *search_strp)
3022 char buf[MAX_NLEN+20];
3028 q = "¤É¤Î¥¢¥¤¥Æ¥à¤ò¸¡º÷¤·¤Þ¤¹¤«? ";
3029 s = "¥¢¥¤¥Æ¥à¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£";
3031 q = "Enter which item? ";
3032 s = "You have nothing to enter.";
3034 o_ptr = choose_object(q, s);
3035 if (!o_ptr) return 0;
3039 string_free(*search_strp);
3040 object_desc(buf, *o_handle, FALSE, 3);
3041 *search_strp = string_make(format("<%s>", buf));
3047 * Prepare for search by destroyed object
3049 static byte get_destroyed_object_for_search(object_type **o_handle, cptr *search_strp)
3051 char buf[MAX_NLEN+20];
3053 if (!autopick_last_destroyed_object.k_idx) return 0;
3055 *o_handle = &autopick_last_destroyed_object;
3057 string_free(*search_strp);
3058 object_desc(buf, *o_handle, FALSE, 3);
3059 *search_strp = string_make(format("<%s>", buf));
3065 * Choose an item or string for search
3067 static byte get_string_for_search(object_type **o_handle, cptr *search_strp)
3070 char buf[MAX_NLEN+20];
3073 int k_flag[MAX_NLEN+20];
3074 char prompt[] = "¸¡º÷(^I:»ý¤Áʪ ^L:Ç˲õ¤µ¤ì¤¿Êª): ";
3076 char prompt[] = "Search key(^I:inven ^L:destroyed): ";
3078 int col = sizeof(prompt) - 1;
3080 if (*search_strp) strcpy(buf, *search_strp);
3083 /* Display prompt */
3086 /* Display the default answer */
3087 Term_erase(col, 0, 255);
3088 Term_putstr(col, 0, -1, TERM_YELLOW, buf);
3098 Term_gotoxy(col + pos, 0);
3103 /* Count length of macro trigger which induced this key */
3104 trig_len = strlen(inkey_macro_trigger_string);
3106 /* HACK -- ignore macro defined on ASCII keys */
3109 /* Get original key */
3110 key = inkey_macro_trigger_string[0];
3112 /* Kill further macro expansion */
3117 if (key == 0x7F) key = KTRL('d');
3120 /* Analyze the key */
3133 if (!pos && *o_handle) return (back ? -1 : 1);
3134 string_free(*search_strp);
3135 *search_strp = string_make(buf);
3137 return (back ? -1 : 1);
3141 return get_object_for_search(o_handle, search_strp);
3144 /* Prepare string for destroyed object if there is one. */
3145 if (get_destroyed_object_for_search(o_handle, search_strp))
3155 if (k_flag[pos]) pos--;
3170 if (pos + 1 < MAX_NLEN)
3178 else if (pos < MAX_NLEN && isprint(key))
3185 if (pos < MAX_NLEN && isprint(key)) buf[pos++] = key;
3194 /* Update the entry */
3195 Term_erase(col, 0, 255);
3196 Term_putstr(col, 0, -1, TERM_WHITE, buf);
3204 * Search next line matches for o_ptr
3206 static bool search_for_object(text_body_type *tb, object_type *o_ptr, bool forward)
3209 autopick_type an_entry, *entry = &an_entry;
3210 char o_name[MAX_NLEN];
3212 object_desc(o_name, o_ptr, FALSE, 3);
3214 /* Force to be lower case string */
3215 for (i = 0; o_name[i]; i++)
3218 if (iskanji(o_name[i]))
3222 if (isupper(o_name[i]))
3223 o_name[i] = tolower(o_name[i]);
3232 if (!tb->lines_list[++i]) break;
3239 /* Ignore bypassed lines */
3240 if (tb->states[i] & LSTAT_BYPASS) continue;
3242 if (!autopick_new_entry(entry, tb->lines_list[i], FALSE)) continue;
3244 if (is_autopick_aux(o_ptr, entry, o_name))
3257 * Search next line matches to the string
3259 static bool search_for_string(text_body_type *tb, cptr search_str, bool forward)
3269 if (!tb->lines_list[++i]) break;
3276 /* Ignore bypassed lines */
3277 if (tb->states[i] & LSTAT_BYPASS) continue;
3280 pos = strstr_j(tb->lines_list[i], search_str);
3282 pos = strstr(tb->lines_list[i], search_str);
3286 tb->cx = (int)(pos - tb->lines_list[i]);
3299 * Editor command id's
3302 #define EC_SAVEQUIT 2
3313 #define EC_PGDOWN 13
3315 #define EC_BOTTOM 15
3320 #define EC_KILL_LINE 20
3321 #define EC_DELETE_CHAR 21
3322 #define EC_BACKSPACE 22
3323 #define EC_SEARCH_STR 23
3324 #define EC_SEARCH_FORW 24
3325 #define EC_SEARCH_BACK 25
3326 #define EC_SEARCH_OBJ 26
3327 #define EC_SEARCH_DESTROYED 27
3328 #define EC_INSERT_OBJECT 28
3329 #define EC_INSERT_DESTROYED 29
3330 #define EC_INSERT_BLOCK 30
3331 #define EC_INSERT_MACRO 31
3332 #define EC_INSERT_KEYMAP 32
3333 #define EC_CL_AUTOPICK 33
3334 #define EC_CL_DESTROY 34
3335 #define EC_CL_LEAVE 35
3336 #define EC_CL_QUERY 36
3337 #define EC_CL_NO_DISP 37
3338 #define EC_OK_COLLECTING 38
3339 #define EC_IK_UNAWARE 39
3340 #define EC_IK_UNIDENTIFIED 40
3341 #define EC_IK_IDENTIFIED 41
3342 #define EC_IK_STAR_IDENTIFIED 42
3343 #define EC_OK_BOOSTED 43
3344 #define EC_OK_MORE_THAN 44
3345 #define EC_OK_MORE_BONUS 45
3346 #define EC_OK_WORTHLESS 46
3347 #define EC_OK_ARTIFACT 47
3348 #define EC_OK_EGO 48
3349 #define EC_OK_NAMELESS 49
3350 #define EC_OK_WANTED 50
3351 #define EC_OK_UNIQUE 51
3352 #define EC_OK_HUMAN 52
3353 #define EC_OK_UNREADABLE 53
3354 #define EC_OK_REALM1 54
3355 #define EC_OK_REALM2 55
3356 #define EC_OK_FIRST 56
3357 #define EC_OK_SECOND 57
3358 #define EC_OK_THIRD 58
3359 #define EC_OK_FOURTH 59
3360 #define EC_KK_WEAPONS 60
3361 #define EC_KK_FAVORITE 61
3362 #define EC_KK_ARMORS 62
3363 #define EC_KK_MISSILES 63
3364 #define EC_KK_DEVICES 64
3365 #define EC_KK_LIGHTS 65
3366 #define EC_KK_JUNKS 66
3367 #define EC_KK_SPELLBOOKS 67
3368 #define EC_KK_SHIELDS 68
3369 #define EC_KK_BOWS 69
3370 #define EC_KK_RINGS 70
3371 #define EC_KK_AMULETS 71
3372 #define EC_KK_SUITS 72
3373 #define EC_KK_CLOAKS 73
3374 #define EC_KK_HELMS 74
3375 #define EC_KK_GLOVES 75
3376 #define EC_KK_BOOTS 76
3382 #define MN_QUIT "¥»¡¼¥Ö̵¤·¤Ç½ªÎ»"
3383 #define MN_SAVEQUIT "¥»¡¼¥Ö¤·¤Æ½ªÎ»"
3384 #define MN_REVERT "Á´¤Æ¤ÎÊѹ¹¤òÇË´þ"
3385 #define MN_HELP "¥Ø¥ë¥×"
3387 #define MN_MOVE "¥«¡¼¥½¥ë°ÜÆ°"
3388 #define MN_LEFT "º¸"
3389 #define MN_DOWN "²¼"
3391 #define MN_RIGHT "±¦"
3392 #define MN_BOL "¹Ô¤ÎÀèƬ"
3393 #define MN_EOL "¹Ô¤Î½ªÃ¼"
3394 #define MN_PGUP "¾å¤Î¥Ú¡¼¥¸"
3395 #define MN_PGDOWN "²¼¤Î¥Ú¡¼¥¸"
3396 #define MN_TOP "1¹ÔÌܤذÜÆ°"
3397 #define MN_BOTTOM "ºÇ²¼¹Ô¤Ø°ÜÆ°"
3399 #define MN_EDIT "ÊÔ½¸"
3400 #define MN_CUT "¥«¥Ã¥È"
3401 #define MN_COPY "¥³¥Ô¡¼"
3402 #define MN_PASTE "¥Ú¡¼¥¹¥È"
3403 #define MN_BLOCK "ÁªÂòÈϰϤλØÄê"
3404 #define MN_KILL_LINE "¹Ô¤Î»Ä¤ê¤òºï½ü"
3405 #define MN_DELETE_CHAR "1ʸ»úºï½ü"
3406 #define MN_BACKSPACE "¥Ð¥Ã¥¯¥¹¥Ú¡¼¥¹"
3407 #define MN_RETURN "²þ¹Ô"
3408 #define MN_RETURN "²þ¹Ô"
3410 #define MN_SEARCH "¸¡º÷"
3411 #define MN_SEARCH_STR "ʸ»úÎó¤Ç¸¡º÷"
3412 #define MN_SEARCH_FORW "Á°Êý¤ØºÆ¸¡º÷"
3413 #define MN_SEARCH_BACK "¸åÊý¤ØºÆ¸¡º÷"
3414 #define MN_SEARCH_OBJ "¥¢¥¤¥Æ¥à¤òÁªÂò¤·¤Æ¸¡º÷"
3415 #define MN_SEARCH_DESTROYED "¼«Æ°Ç˲õ¤µ¤ì¤¿¥¢¥¤¥Æ¥à¤Ç¸¡º÷"
3417 #define MN_INSERT "¿§¡¹ÁÞÆþ"
3418 #define MN_INSERT_OBJECT "ÁªÂò¤·¤¿¥¢¥¤¥Æ¥à¤Î̾Á°¤òÁÞÆþ"
3419 #define MN_INSERT_DESTROYED "¼«Æ°Ç˲õ¤µ¤ì¤¿¥¢¥¤¥Æ¥à¤Î̾Á°¤òÁÞÆþ"
3420 #define MN_INSERT_BLOCK "¾ò·ïʬ´ô¥Ö¥í¥Ã¥¯¤ÎÎã¤òÁÞÆþ"
3421 #define MN_INSERT_MACRO "¥Þ¥¯¥íÄêµÁ¤òÁÞÆþ"
3422 #define MN_INSERT_KEYMAP "¥¡¼¥Þ¥Ã¥×ÄêµÁ¤òÁÞÆþ"
3424 #define MN_COMMAND_LETTER "½¦¤¤/Ç˲õ/ÊüÃÖ¤ÎÁªÂò"
3425 #define MN_CL_AUTOPICK "¡Ö ¡× (¼«Æ°½¦¤¤)"
3426 #define MN_CL_DESTROY "¡Ö!¡× (¼«Æ°Ç˲õ)"
3427 #define MN_CL_LEAVE "¡Ö~¡× (ÊüÃÖ)"
3428 #define MN_CL_QUERY "¡Ö;¡× (³Îǧ¤·¤Æ½¦¤¦)"
3429 #define MN_CL_NO_DISP "¡Ö(¡× (¥Þ¥Ã¥×¥³¥Þ¥ó¥É¤Çɽ¼¨¤·¤Ê¤¤)"
3431 #define MN_ADJECTIVE_GEN "·ÁÍÆ»ì(°ìÈÌ)¤ÎÁªÂò"
3433 #define MN_ADJECTIVE_SPECIAL "·ÁÍÆ»ì(Æüì)¤ÎÁªÂò"
3434 #define MN_BOOSTED "¥À¥¤¥¹Ìܤΰ㤦 (Éð´ï)"
3435 #define MN_MORE_THAN "¥À¥¤¥¹ÌÜ # °Ê¾å¤Î (Éð´ï)"
3436 #define MN_MORE_BONUS "½¤ÀµÃÍ # °Ê¾å¤Î (»ØÎØÅù)"
3437 #define MN_ARTIFACT "¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È (ÁõÈ÷)"
3438 #define MN_EGO "¥¨¥´ (ÁõÈ÷)"
3439 #define MN_NAMELESS "̵ÌäΠ(ÁõÈ÷)"
3440 #define MN_WANTED "¾Þ¶â¼ó¤Î (»àÂÎ)"
3441 #define MN_UNIQUE "¥æ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼¤Î (»àÂÎ)"
3442 #define MN_HUMAN "¿Í´Ö¤Î (»àÂÎ)"
3443 #define MN_UNREADABLE "Æɤá¤Ê¤¤ (ËâË¡½ñ)"
3444 #define MN_REALM1 "Âè°ìÎΰè¤Î (ËâË¡½ñ)"
3445 #define MN_REALM2 "ÂèÆóÎΰè¤Î (ËâË¡½ñ)"
3446 #define MN_FIRST "1ºýÌܤΠ(ËâË¡½ñ)"
3447 #define MN_SECOND "2ºýÌܤΠ(ËâË¡½ñ)"
3448 #define MN_THIRD "3ºýÌܤΠ(ËâË¡½ñ)"
3449 #define MN_FOURTH "4ºýÌܤΠ(ËâË¡½ñ)"
3451 #define MN_NOUN "̾»ì¤ÎÁªÂò"
3455 #define MN_QUIT "Quit without save"
3456 #define MN_SAVEQUIT "Save & Quit"
3457 #define MN_REVERT "Revert all changes"
3458 #define MN_HELP "Help"
3460 #define MN_MOVE "Move cursor"
3461 #define MN_LEFT "Left"
3462 #define MN_DOWN "Down"
3464 #define MN_RIGHT "Right"
3465 #define MN_BOL "Beggining of line"
3466 #define MN_EOL "End of line"
3467 #define MN_PGUP "Page up"
3468 #define MN_PGDOWN "Page down"
3469 #define MN_TOP "Top"
3470 #define MN_BOTTOM "Bottom"
3472 #define MN_EDIT "Edit"
3473 #define MN_CUT "Cut"
3474 #define MN_COPY "Copy"
3475 #define MN_PASTE "Paste"
3476 #define MN_BLOCK "Select block"
3477 #define MN_KILL_LINE "Kill rest of line"
3478 #define MN_DELETE_CHAR "Delete character"
3479 #define MN_BACKSPACE "Backspace"
3480 #define MN_RETURN "Return"
3481 #define MN_RETURN "Return"
3483 #define MN_SEARCH "Search"
3484 #define MN_SEARCH_STR "Search by string"
3485 #define MN_SEARCH_FORW "Search forward"
3486 #define MN_SEARCH_BACK "Search backward"
3487 #define MN_SEARCH_OBJ "Search by inventory object"
3488 #define MN_SEARCH_DESTROYED "Search by destroyed object"
3490 #define MN_INSERT "Insert..."
3491 #define MN_INSERT_OBJECT "Insert name of choosen object"
3492 #define MN_INSERT_DESTROYED "Insert name of destroyed object"
3493 #define MN_INSERT_BLOCK "Insert conditional block"
3494 #define MN_INSERT_MACRO "Insert a macro definition"
3495 #define MN_INSERT_KEYMAP "Insert a keymap definition"
3497 #define MN_COMMAND_LETTER "Command letter"
3498 #define MN_CL_AUTOPICK "' ' (Auto pick)"
3499 #define MN_CL_DESTROY "'!' (Auto destroy)"
3500 #define MN_CL_LEAVE "'~' (Leave it on the floor)"
3501 #define MN_CL_QUERY "';' (Query to pick up)"
3502 #define MN_CL_NO_DISP "'(' (No display on the large map)"
3504 #define MN_ADJECTIVE_GEN "Adjective (general)"
3506 #define MN_ADJECTIVE_SPECIAL "Adjective (special)"
3507 #define MN_BOOSTED "dice boosted (weapons)"
3508 #define MN_MORE_THAN "more than # dice (weapons)"
3509 #define MN_MORE_BONUS "more bonus than # (rings etc.)"
3510 #define MN_ARTIFACT "artifact (equipments)"
3511 #define MN_EGO "ego (equipments)"
3512 #define MN_NAMELESS "nameless (equipments)"
3513 #define MN_WANTED "wanted (corpse)"
3514 #define MN_UNIQUE "unique (corpse)"
3515 #define MN_HUMAN "human (corpse)"
3516 #define MN_UNREADABLE "unreadable (spellbooks)"
3517 #define MN_REALM1 "realm1 (spellbooks)"
3518 #define MN_REALM2 "realm2 (spellbooks)"
3519 #define MN_FIRST "first (spellbooks)"
3520 #define MN_SECOND "second (spellbooks)"
3521 #define MN_THIRD "third (spellbooks)"
3522 #define MN_FOURTH "fourth (spellbooks)"
3524 #define MN_NOUN "Keywords (noun)"
3534 } command_menu_type;
3537 command_menu_type menu_data[] =
3539 {MN_HELP, 0, -1, EC_HELP},
3540 {MN_QUIT, 0, KTRL('q'), EC_QUIT},
3541 {MN_SAVEQUIT, 0, KTRL('w'), EC_SAVEQUIT},
3542 {MN_REVERT, 0, KTRL('z'), EC_REVERT},
3544 {MN_EDIT, 0, -1, -1},
3545 {MN_CUT, 1, KTRL('x'), EC_CUT},
3546 {MN_COPY, 1, KTRL('c'), EC_COPY},
3547 {MN_PASTE, 1, KTRL('v'), EC_PASTE},
3548 {MN_BLOCK, 1, KTRL('g'), EC_BLOCK},
3549 {MN_KILL_LINE, 1, KTRL('k'), EC_KILL_LINE},
3550 {MN_DELETE_CHAR, 1, KTRL('d'), EC_DELETE_CHAR},
3551 {MN_BACKSPACE, 1, KTRL('h'), EC_BACKSPACE},
3552 {MN_RETURN, 1, KTRL('j'), EC_RETURN},
3553 {MN_RETURN, 1, KTRL('m'), EC_RETURN},
3555 {MN_SEARCH, 0, -1, -1},
3556 {MN_SEARCH_STR, 1, KTRL('s'), EC_SEARCH_STR},
3557 {MN_SEARCH_FORW, 1, -1, EC_SEARCH_FORW},
3558 {MN_SEARCH_BACK, 1, KTRL('r'), EC_SEARCH_BACK},
3559 {MN_SEARCH_OBJ, 1, KTRL('t'), EC_SEARCH_OBJ},
3560 {MN_SEARCH_DESTROYED, 1, -1, EC_SEARCH_DESTROYED},
3562 {MN_MOVE, 0, -1, -1},
3563 {MN_LEFT, 1, KTRL('b'), EC_LEFT},
3564 {MN_DOWN, 1, KTRL('n'), EC_DOWN},
3565 {MN_UP, 1, KTRL('p'), EC_UP},
3566 {MN_RIGHT, 1, KTRL('f'), EC_RIGHT},
3567 {MN_BOL, 1, KTRL('a'), EC_BOL},
3568 {MN_EOL, 1, KTRL('e'), EC_EOL},
3569 {MN_PGUP, 1, KTRL('o'), EC_PGUP},
3570 {MN_PGDOWN, 1, KTRL('l'), EC_PGDOWN},
3571 {MN_TOP, 1, KTRL('y'), EC_TOP},
3572 {MN_BOTTOM, 1, KTRL('u'), EC_BOTTOM},
3574 {MN_INSERT, 0, -1, -1},
3575 {MN_INSERT_OBJECT, 1, KTRL('i'), EC_INSERT_OBJECT},
3576 {MN_INSERT_DESTROYED, 1, -1, EC_INSERT_DESTROYED},
3577 {MN_INSERT_BLOCK, 1, -1, EC_INSERT_BLOCK},
3578 {MN_INSERT_MACRO, 1, -1, EC_INSERT_MACRO},
3579 {MN_INSERT_KEYMAP, 1, -1, EC_INSERT_KEYMAP},
3581 {MN_ADJECTIVE_GEN, 0, -1, -1},
3582 {KEY_UNAWARE, 1, -1, EC_IK_UNAWARE},
3583 {KEY_UNIDENTIFIED, 1, -1, EC_IK_UNIDENTIFIED},
3584 {KEY_IDENTIFIED, 1, -1, EC_IK_IDENTIFIED},
3585 {KEY_STAR_IDENTIFIED, 1, -1, EC_IK_STAR_IDENTIFIED},
3586 {KEY_COLLECTING, 1, -1, EC_OK_COLLECTING},
3587 {KEY_WORTHLESS, 1, -1, EC_OK_WORTHLESS},
3589 {MN_ADJECTIVE_SPECIAL, 0, -1, -1},
3590 {MN_BOOSTED, 1, -1, EC_OK_BOOSTED},
3591 {MN_MORE_THAN, 1, -1, EC_OK_MORE_THAN},
3592 {MN_MORE_BONUS, 1, -1, EC_OK_MORE_BONUS},
3593 {MN_ARTIFACT, 1, -1, EC_OK_ARTIFACT},
3594 {MN_EGO, 1, -1, EC_OK_EGO},
3595 {MN_NAMELESS, 1, -1, EC_OK_NAMELESS},
3596 {MN_WANTED, 1, -1, EC_OK_WANTED},
3597 {MN_UNIQUE, 1, -1, EC_OK_UNIQUE},
3598 {MN_HUMAN, 1, -1, EC_OK_HUMAN},
3599 {MN_UNREADABLE, 1, -1, EC_OK_UNREADABLE},
3600 {MN_REALM1, 1, -1, EC_OK_REALM1},
3601 {MN_REALM2, 1, -1, EC_OK_REALM2},
3602 {MN_FIRST, 1, -1, EC_OK_FIRST},
3603 {MN_SECOND, 1, -1, EC_OK_SECOND},
3604 {MN_THIRD, 1, -1, EC_OK_THIRD},
3605 {MN_FOURTH, 1, -1, EC_OK_FOURTH},
3607 {MN_NOUN, 0, -1, -1},
3608 {KEY_WEAPONS, 1, -1, EC_KK_WEAPONS},
3609 {KEY_FAVORITE, 1, -1, EC_KK_FAVORITE},
3610 {KEY_ARMORS, 1, -1, EC_KK_ARMORS},
3611 {KEY_MISSILES, 1, -1, EC_KK_MISSILES},
3612 {KEY_DEVICES, 1, -1, EC_KK_DEVICES},
3613 {KEY_LIGHTS, 1, -1, EC_KK_LIGHTS},
3614 {KEY_JUNKS, 1, -1, EC_KK_JUNKS},
3615 {KEY_SPELLBOOKS, 1, -1, EC_KK_SPELLBOOKS},
3616 {KEY_SHIELDS, 1, -1, EC_KK_SHIELDS},
3617 {KEY_BOWS, 1, -1, EC_KK_BOWS},
3618 {KEY_RINGS, 1, -1, EC_KK_RINGS},
3619 {KEY_AMULETS, 1, -1, EC_KK_AMULETS},
3620 {KEY_SUITS, 1, -1, EC_KK_SUITS},
3621 {KEY_CLOAKS, 1, -1, EC_KK_CLOAKS},
3622 {KEY_HELMS, 1, -1, EC_KK_HELMS},
3623 {KEY_GLOVES, 1, -1, EC_KK_GLOVES},
3624 {KEY_BOOTS, 1, -1, EC_KK_BOOTS},
3626 {MN_COMMAND_LETTER, 0, -1, -1},
3627 {MN_CL_AUTOPICK, 1, -1, EC_CL_AUTOPICK},
3628 {MN_CL_DESTROY, 1, -1, EC_CL_DESTROY},
3629 {MN_CL_LEAVE, 1, -1, EC_CL_LEAVE},
3630 {MN_CL_QUERY, 1, -1, EC_CL_QUERY},
3631 {MN_CL_NO_DISP, 1, -1, EC_CL_NO_DISP},
3638 * Find a command by 'key'.
3640 static int get_com_id(char key)
3644 for (i = 0; menu_data[i].name; i++)
3646 if (menu_data[i].key == key)
3648 return menu_data[i].com_id;
3657 * Display the menu, and get a command
3659 static int do_command_menu(int level, int start)
3664 int col0 = 5 + level*7;
3665 int row0 = 1 + level*3;
3667 int menu_id_list[26];
3669 char linestr[MAX_LINELEN];
3671 /* Get max length */
3673 for (i = start; menu_data[i].level >= level; i++)
3677 /* Ignore lower level sub menus */
3678 if (menu_data[i].level > level) continue;
3680 len = strlen(menu_data[i].name);
3681 if (len > max_len) max_len = len;
3683 menu_id_list[menu_key] = i;
3687 while (menu_key < 26)
3689 menu_id_list[menu_key] = -1;
3693 /* Extra space for displaying menu key and command key */
3694 max_menu_wid = max_len + 3 + 3;
3696 /* Prepare box line */
3698 strcat(linestr, "+");
3699 for (i = 0; i < max_menu_wid + 2; i++)
3701 strcat(linestr, "-");
3703 strcat(linestr, "+");
3713 int row1 = row0 + 1;
3716 Term_putstr(col0, row0, -1, TERM_WHITE, linestr);
3718 /* Draw menu items */
3720 for (i = start; menu_data[i].level >= level; i++)
3722 char com_key_str[3];
3725 /* Ignore lower level sub menus */
3726 if (menu_data[i].level > level) continue;
3728 if (menu_data[i].com_id == -1)
3731 strcpy(com_key_str, "¢§");
3733 strcpy(com_key_str, ">");
3736 else if (menu_data[i].key != -1)
3738 com_key_str[0] = '^';
3739 com_key_str[1] = menu_data[i].key + '@';
3740 com_key_str[2] = '\0';
3744 com_key_str[0] = '\0';
3747 str = format("| %c) %-*s %2s | ", menu_key + 'a', max_len, menu_data[i].name, com_key_str);
3749 Term_putstr(col0, row1++, -1, TERM_WHITE, str);
3754 /* Draw bottom line */
3755 Term_putstr(col0, row1, -1, TERM_WHITE, linestr);
3757 /* The menu was shown */
3761 prt(format("(a-%c) ¥³¥Þ¥ó¥É:", menu_key + 'a' - 1), 0, 0);
3763 prt(format("(a-%c) Command:", menu_key + 'a' - 1), 0, 0);
3767 if (key == ESCAPE) return 0;
3769 if ('a' <= key && key <= 'z')
3771 menu_id = menu_id_list[key - 'a'];
3775 com_id = menu_data[menu_id].com_id;
3779 com_id = do_command_menu(level + 1, menu_id + 1);
3781 if (com_id) return com_id;
3793 com_id = get_com_id(key);
3794 if (com_id) return com_id;
3801 static chain_str_type *new_chain_str(cptr str)
3803 chain_str_type *chain;
3805 size_t len = strlen(str);
3807 chain = (chain_str_type *)ralloc(sizeof(chain_str_type) + len * sizeof(char));
3809 strcpy(chain->s, str);
3816 static void kill_yank_chain(text_body_type *tb)
3818 chain_str_type *chain = tb->yank;
3820 tb->yank_eol = TRUE;
3824 chain_str_type *next = chain->next;
3825 size_t len = strlen(chain->s);
3827 rnfree(chain, sizeof(chain_str_type) + len * sizeof(char));
3834 static void add_str_to_yank(text_body_type *tb, cptr str)
3836 chain_str_type *chain;
3838 tb->yank_eol = FALSE;
3840 if (NULL == tb->yank)
3842 tb->yank = new_chain_str(str);
3852 chain->next = new_chain_str(str);
3857 chain = chain->next;
3862 #define DESCRIPT_HGT 3
3867 static void draw_text_editor(text_body_type *tb)
3870 int by1 = -1, bx1 = -1, by2 = -1, bx2 = -1;
3873 Term_get_size(&tb->wid, &tb->hgt);
3876 * Top line (-1), description line (-3), separator (-1)
3879 tb->hgt -= 2 + DESCRIPT_HGT;
3882 /* Don't let cursor at second byte of kanji */
3883 for (i = 0; tb->lines_list[tb->cy][i]; i++)
3884 if (iskanji(tb->lines_list[tb->cy][i]))
3895 /* Scroll if necessary */
3896 if (tb->cy < tb->upper || tb->upper + tb->hgt <= tb->cy)
3897 tb->upper = tb->cy - (tb->hgt)/2;
3900 if ((tb->cx < tb->left + 10 && tb->left > 0) || tb->left + tb->wid - 5 <= tb->cx)
3901 tb->left = tb->cx - (tb->wid)*2/3;
3905 /* Redraw whole window after resize */
3906 if (tb->old_wid != tb->wid || tb->old_hgt != tb->hgt)
3907 tb->dirty_flags |= DIRTY_SCREEN;
3909 /* Redraw all text after scroll */
3910 else if (tb->old_upper != tb->upper || tb->old_left != tb->left)
3911 tb->dirty_flags |= DIRTY_ALL;
3914 if (tb->dirty_flags & DIRTY_SCREEN)
3916 tb->dirty_flags |= (DIRTY_ALL | DIRTY_MODE);
3922 /* Redraw mode line */
3923 if (tb->dirty_flags & DIRTY_MODE)
3925 char buf[MAX_LINELEN];
3927 int sepa_length = tb->wid;
3930 for (i = 0; i < sepa_length; i++)
3934 Term_putstr(0, tb->hgt + 1, sepa_length, TERM_WHITE, buf);
3937 if (tb->dirty_flags & DIRTY_EXPRESSION)
3942 for (y = 0; tb->lines_list[y]; y++)
3946 cptr s = tb->lines_list[y];
3948 /* Update this line's state */
3949 tb->states[y] = state;
3951 if (*s++ != '?') continue;
3952 if (*s++ != ':') continue;
3954 /* Lines below this line are auto-registered */
3955 if (streq(s, "$AUTOREGISTER"))
3956 state |= LSTAT_AUTOREGISTER;
3958 /* Parse the expr */
3959 v = process_pref_file_expr(&s, &f);
3962 if (streq(v, "0")) state |= LSTAT_BYPASS;
3963 else state &= ~LSTAT_BYPASS;
3965 /* Re-update this line's state */
3966 tb->states[y] = state | LSTAT_EXPRESSION;
3969 tb->dirty_flags |= DIRTY_ALL;
3974 int tmp_cx = tb->cx;
3975 int len = strlen(tb->lines_list[tb->cy]);
3977 /* Correct cursor location */
3978 if (tb->cx > len) tmp_cx = len;
3980 tb->dirty_flags |= DIRTY_ALL;
3982 if (tb->my < tb->cy ||
3983 (tb->my == tb->cy && tb->mx < tmp_cx))
3999 /* Dump up to tb->hgt lines of messages */
4000 for (i = 0; i < tb->hgt; i++)
4006 int y = tb->upper+i;
4008 /* clean or dirty? */
4009 if (!(tb->dirty_flags & DIRTY_ALL) && (tb->dirty_line != y))
4012 msg = tb->lines_list[y];
4015 /* Apply horizontal scroll */
4016 for (j = 0; *msg; msg++, j++)
4018 if (j == tb->left) break;
4034 Term_erase(0, i + 1, tb->wid);
4036 if (tb->states[y] & LSTAT_AUTOREGISTER)
4038 /* Warning color -- These lines will be deleted later */
4043 /* Bypassed line will be displayed by darker color */
4044 if (tb->states[y] & LSTAT_BYPASS) color = TERM_SLATE;
4045 else color = TERM_WHITE;
4050 /* Dump the messages, bottom to top */
4051 Term_putstr(leftcol, i + 1, tb->wid - 1, color, msg);
4056 int x0 = leftcol + tb->left;
4061 if (by1 <= y && y < by2) sx1 = strlen(msg);
4062 if (y == by1) sx0 = bx1;
4063 if (y == by2) sx1 = bx2;
4065 Term_gotoxy(leftcol, i + 1);
4066 if (x0 < sx0) Term_addstr(sx0 - x0, color, msg);
4067 if (x0 < sx1) Term_addstr(sx1 - sx0, TERM_YELLOW, msg + (sx0 - x0));
4068 Term_addstr(-1, color, msg + (sx1 - x0));
4072 for (; i < tb->hgt; i++)
4075 Term_erase(0, i + 1, tb->wid);
4078 /* Display information when updated */
4079 if (tb->old_cy != tb->cy || (tb->dirty_flags & (DIRTY_ALL | DIRTY_NOT_FOUND | DIRTY_NO_SEARCH)) || tb->dirty_line == tb->cy)
4081 autopick_type an_entry, *entry = &an_entry;
4083 /* Clear information line */
4084 for (i = 0; i < DESCRIPT_HGT; i++)
4087 Term_erase(0, tb->hgt + 2 + i, tb->wid);
4090 /* Display information */
4091 if (tb->dirty_flags & DIRTY_NOT_FOUND)
4094 prt(format("¥Ñ¥¿¡¼¥ó¤¬¸«¤Ä¤«¤ê¤Þ¤»¤ó: %s", tb->search_str), tb->hgt + 1 + 1, 0);
4096 prt(format("Pattern not found: %s", tb->search_str), tb->hgt + 1 + 1, 0);
4099 else if (tb->dirty_flags & DIRTY_NO_SEARCH)
4102 prt("¸¡º÷Ãæ¤Î¥Ñ¥¿¡¼¥ó¤¬¤¢¤ê¤Þ¤»¤ó('/'¤Ç¸¡º÷)¡£", tb->hgt + 1 + 1, 0);
4104 prt("No pattern to search. (Press '/' to search.)", tb->hgt +1 + 1, 0);
4107 else if (tb->lines_list[tb->cy][0] == '#')
4110 prt("¤³¤Î¹Ô¤Ï¥³¥á¥ó¥È¤Ç¤¹¡£", tb->hgt +1 + 1, 0);
4112 prt("This line is a comment.", tb->hgt +1 + 1, 0);
4115 else if (tb->lines_list[tb->cy][1] == ':')
4119 switch(tb->lines_list[tb->cy][0])
4123 str = "¤³¤Î¹Ô¤Ï¾ò·ïʬ´ô¼°¤Ç¤¹¡£";
4125 str = "This line is a Conditional Expression.";
4131 str = "¤³¤Î¹Ô¤Ï¥Þ¥¯¥í¤Î¼Â¹ÔÆâÍƤòÄêµÁ¤·¤Þ¤¹¡£";
4133 str = "This line defines a Macro action.";
4138 str = "¤³¤Î¹Ô¤Ï¥Þ¥¯¥í¤Î¥È¥ê¥¬¡¼¡¦¥¡¼¤òÄêµÁ¤·¤Þ¤¹¡£";
4140 str = "This line defines a Macro trigger key.";
4145 str = "¤³¤Î¹Ô¤Ï¥¡¼ÇÛÃÖ¤òÄêµÁ¤·¤Þ¤¹¡£";
4147 str = "This line defines a Keymap.";
4152 /* Draw the first line */
4153 if (str) prt(str, tb->hgt +1 + 1, 0);
4157 switch(tb->lines_list[tb->cy][0])
4160 if (tb->states[tb->cy] & LSTAT_BYPASS)
4163 str = "¸½ºß¤Î¼°¤ÎÃͤϡֵ¶(=0)¡×¤Ç¤¹¡£";
4165 str = "The expression is 'False'(=0) currently.";
4171 str = "¸½ºß¤Î¼°¤ÎÃͤϡֿ¿(=1)¡×¤Ç¤¹¡£";
4173 str = "The expression is 'True'(=1) currently.";
4179 if (tb->states[tb->cy] & LSTAT_AUTOREGISTER)
4182 str = "¤³¤Î¹Ô¤Ï¸å¤Çºï½ü¤µ¤ì¤Þ¤¹¡£";
4184 str = "This line will be delete later.";
4188 else if (tb->states[tb->cy] & LSTAT_BYPASS)
4191 str = "¤³¤Î¹Ô¤Ï¸½ºß¤Ï̵¸ú¤Ê¾õÂ֤Ǥ¹¡£";
4193 str = "This line is bypassed currently.";
4199 /* Draw the second line */
4200 if (str) prt(str, tb->hgt +1 + 2, 0);
4203 /* Get description of an autopicker preference line */
4204 else if (autopick_new_entry(entry, tb->lines_list[tb->cy], FALSE))
4206 char buf[MAX_LINELEN];
4207 char temp[MAX_LINELEN];
4210 describe_autopick(buf, entry);
4212 if (tb->states[tb->cy] & LSTAT_AUTOREGISTER)
4215 strcat(buf, "¤³¤Î¹Ô¤Ï¸å¤Çºï½ü¤µ¤ì¤Þ¤¹¡£");
4217 strcat(buf, " This line will be delete later.");
4221 if (tb->states[tb->cy] & LSTAT_BYPASS)
4224 strcat(buf, "¤³¤Î¹Ô¤Ï¸½ºß¤Ï̵¸ú¤Ê¾õÂ֤Ǥ¹¡£");
4226 strcat(buf, " This line is bypassed currently.");
4230 roff_to_buf(buf, 81, temp, sizeof(temp));
4232 for (i = 0; i < 3; i++)
4238 prt(t, tb->hgt +1 + 1 + i, 0);
4242 autopick_free_entry(entry);
4249 * Kill segment of a line
4251 static void kill_line_segment(text_body_type *tb, int y, int x0, int x1, bool whole)
4253 char buf[MAX_LINELEN];
4254 cptr s = tb->lines_list[y];
4259 if (x0 == x1) return;
4261 /* Kill whole line? */
4262 if (whole && x0 == 0 && s[x1] == '\0' && tb->lines_list[y+1])
4266 string_free(tb->lines_list[y]);
4268 /* Shift lines up */
4269 for (i = y; tb->lines_list[i+1]; i++)
4270 tb->lines_list[i] = tb->lines_list[i+1];
4271 tb->lines_list[i] = NULL;
4273 /* Expressions need re-evaluation */
4274 tb->dirty_flags |= DIRTY_EXPRESSION;
4279 /* Before the segment */
4280 for (x = 0; x < x0; x++)
4283 /* After the segment */
4284 for (x = x1; s[x]; x++)
4290 string_free(tb->lines_list[y]);
4291 tb->lines_list[y] = string_make(buf);
4293 /* Expressions may need re-evaluation */
4294 check_expression_line(tb, y);
4296 /* Text is changed */
4302 * Get a trigger key and insert ASCII string for the trigger
4304 static bool insert_macro_line(text_body_type *tb)
4313 /* Do not process macros */
4319 /* Read the pattern */
4325 /* Do not process macros */
4328 /* Do not wait for keys */
4331 /* Attempt to read a key */
4341 /* Convert the trigger */
4342 ascii_to_text(tmp, buf);
4345 if(!tmp[0]) return FALSE;
4349 /* Insert preference string */
4350 insert_return_code(tb);
4351 string_free(tb->lines_list[tb->cy]);
4352 tb->lines_list[tb->cy] = string_make(format("P:%s", tmp));
4354 /* Acquire action */
4355 i = macro_find_exact(buf);
4359 /* Nothing defined */
4364 /* Analyze the current action */
4365 ascii_to_text(tmp, macro__act[i]);
4368 /* Insert blank action preference line */
4369 insert_return_code(tb);
4370 string_free(tb->lines_list[tb->cy]);
4371 tb->lines_list[tb->cy] = string_make(format("A:%s", tmp));
4378 * Get a command key and insert ASCII string for the key
4380 static bool insert_keymap_line(text_body_type *tb)
4388 if (rogue_like_commands)
4390 mode = KEYMAP_MODE_ROGUE;
4396 mode = KEYMAP_MODE_ORIG;
4409 /* Convert the trigger */
4410 ascii_to_text(tmp, buf);
4413 if(!tmp[0]) return FALSE;
4417 /* Insert preference string */
4418 insert_return_code(tb);
4419 string_free(tb->lines_list[tb->cy]);
4420 tb->lines_list[tb->cy] = string_make(format("C:%d:%s", mode, tmp));
4422 /* Look up the keymap */
4423 act = keymap_act[mode][(byte)(buf[0])];
4425 /* Insert blank action preference line */
4426 insert_return_code(tb);
4427 string_free(tb->lines_list[tb->cy]);
4428 tb->lines_list[tb->cy] = string_make(format("A:%s", act));
4435 * Execute a single editor command
4437 static bool do_editor_command(text_body_type *tb, int com_id)
4445 if (!get_check("Á´¤Æ¤ÎÊѹ¹¤òÇË´þ¤·¤Æ¤«¤é½ªÎ»¤·¤Þ¤¹¡£¤è¤í¤·¤¤¤Ç¤¹¤«¡© ")) break;
4447 if (!get_check("Discard all changes and quit. Are you sure? ")) break;
4450 return QUIT_WITHOUT_SAVE;
4453 return QUIT_AND_SAVE;
4456 /* Revert to original */
4458 if (!get_check("Á´¤Æ¤ÎÊѹ¹¤òÇË´þ¤·¤Æ¸µ¤Î¾õÂÖ¤ËÌᤷ¤Þ¤¹¡£¤è¤í¤·¤¤¤Ç¤¹¤«¡© ")) break;
4460 if (!get_check("Discard all changes and revert to original file. Are you sure? ")) break;
4463 free_text_lines(tb->lines_list);
4464 tb->lines_list = read_pickpref_text_lines(&tb->filename_mode);
4465 tb->dirty_flags |= DIRTY_ALL | DIRTY_MODE | DIRTY_EXPRESSION;
4466 tb->cx = tb->cy = 0;
4469 /* Text is not changed */
4470 tb->changed = FALSE;
4474 /* Peruse the main help file */
4476 (void)show_file(TRUE, "jeditor.txt", NULL, 0, 0);
4478 (void)show_file(TRUE, "editor.txt", NULL, 0, 0);
4481 tb->dirty_flags |= DIRTY_SCREEN;
4486 /* Split a line or insert end of line */
4488 /* Ignore selection */
4494 tb->dirty_flags |= DIRTY_ALL;
4497 insert_return_code(tb);
4502 tb->dirty_flags |= DIRTY_ALL;
4512 len = strlen(tb->lines_list[tb->cy]);
4513 if (len < tb->cx) tb->cx = len;
4515 else if (tb->cy > 0)
4518 tb->cx = strlen(tb->lines_list[tb->cy]);
4524 if (tb->lines_list[tb->cy + 1]) tb->cy++;
4529 if (tb->cy > 0) tb->cy--;
4538 if (iskanji(tb->lines_list[tb->cy][tb->cx])) tb->cx++;
4541 len = strlen(tb->lines_list[tb->cy]);
4544 if (tb->lines_list[tb->cy + 1])
4556 /* Beginning of line */
4562 tb->cx = strlen(tb->lines_list[tb->cy]);
4566 while (0 < tb->cy && tb->upper <= tb->cy)
4568 while (0 < tb->upper && tb->cy + 1 < tb->upper + tb->hgt)
4574 while (tb->cy < tb->upper + tb->hgt && tb->lines_list[tb->cy + 1])
4584 while (tb->lines_list[tb->cy + 1])
4590 int by1, bx1, by2, bx2;
4593 /* Copy the text first */
4594 do_editor_command(tb, EC_COPY);
4596 if (tb->my < tb->cy ||
4597 (tb->my == tb->cy && tb->mx < tb->cx))
4612 /* Kill lines in reverse order */
4613 for (y = by2; y >= by1; y--)
4616 int x1 = strlen(tb->lines_list[y]);
4618 if (y == by1) x0 = bx1;
4619 if (y == by2) x1 = bx2;
4621 kill_line_segment(tb, y, x0, x1, TRUE);
4624 /* Correct cursor position */
4628 /* Disable selection */
4632 tb->dirty_flags |= DIRTY_ALL;
4639 int by1, bx1, by2, bx2;
4641 int len = strlen(tb->lines_list[tb->cy]);
4643 /* Correct cursor location */
4644 if (tb->cx > len) tb->cx = len;
4646 /* Use single line? */
4651 if (tb->lines_list[tb->cy + 1])
4653 /* Select a single line */
4659 /* Select bottom line */
4664 if (tb->my < tb->cy ||
4665 (tb->my == tb->cy && tb->mx < tb->cx))
4680 /* Kill old yank buffer */
4681 kill_yank_chain(tb);
4683 /* Copy string to yank buffer */
4684 for (y = by1; y <= by2; y++)
4687 char buf[MAX_LINELEN];
4690 int x1 = strlen(tb->lines_list[y]);
4692 if (y == by1) x0 = bx1;
4693 if (y == by2) x1 = bx2;
4695 for (i = 0; i < x1 - x0; i++)
4697 buf[i] = tb->lines_list[y][x0 + i];
4701 add_str_to_yank(tb, buf);
4704 /* Disable selection */
4708 tb->dirty_flags |= DIRTY_ALL;
4714 /* Paste killed text */
4716 chain_str_type *chain = tb->yank;
4717 int len = strlen(tb->lines_list[tb->cy]);
4719 /* Nothing to do? */
4722 /* Correct cursor location */
4723 if (tb->cx > len) tb->cx = len;
4725 /* Ignore selection */
4731 tb->dirty_flags |= DIRTY_ALL;
4737 cptr yank_str = chain->s;
4739 char buf[MAX_LINELEN];
4741 char rest[MAX_LINELEN], *rest_ptr = rest;
4743 /* Save preceding string */
4744 for(i = 0; i < tb->cx; i++)
4745 buf[i] = tb->lines_list[tb->cy][i];
4747 strcpy(rest, &(tb->lines_list[tb->cy][i]));
4749 /* Paste yank buffer */
4750 while (*yank_str && i < MAX_LINELEN-1)
4752 buf[i++] = *yank_str++;
4758 chain = chain->next;
4760 if (chain || tb->yank_eol)
4762 /* There is an end of line between chain nodes */
4764 insert_return_code(tb);
4766 /* Replace this line with new one */
4767 string_free(tb->lines_list[tb->cy]);
4768 tb->lines_list[tb->cy] = string_make(buf);
4770 /* Move to next line */
4777 /* Final line doesn't have end of line */
4779 tb->cx = strlen(buf);
4781 /* Rest of original line */
4782 while (*rest_ptr && i < MAX_LINELEN-1)
4784 buf[i++] = *rest_ptr++;
4790 /* Replace this line with new one */
4791 string_free(tb->lines_list[tb->cy]);
4792 tb->lines_list[tb->cy] = string_make(buf);
4799 tb->dirty_flags |= DIRTY_ALL;
4801 /* Expressions need re-evaluation */
4802 tb->dirty_flags |= DIRTY_EXPRESSION;
4804 /* Text is changed */
4813 /* Disable the selection */
4817 tb->dirty_flags |= DIRTY_ALL;
4821 tb->mark = MARK_MARK;
4823 /* Repeating this command swaps cursor position */
4824 if (com_id == tb->old_com_id)
4836 tb->dirty_flags |= DIRTY_ALL;
4840 int len = strlen(tb->lines_list[tb->cy]);
4842 /* Mark the point 1 */
4846 /* Correct cursor location */
4847 if (tb->cx > len) tb->mx = len;
4854 /* Kill rest of line */
4856 int len = strlen(tb->lines_list[tb->cy]);
4858 /* Correct cursor location */
4859 if (tb->cx > len) tb->cx = len;
4861 /* Ignore selection */
4867 tb->dirty_flags |= DIRTY_ALL;
4870 /* Append only if this command is repeated. */
4871 if (tb->old_com_id != com_id)
4873 kill_yank_chain(tb);
4877 /* Really deleted some text */
4880 /* Add deleted string to yank buffer */
4881 add_str_to_yank(tb, &(tb->lines_list[tb->cy][tb->cx]));
4883 kill_line_segment(tb, tb->cy, tb->cx, len, FALSE);
4886 tb->dirty_line = tb->cy;
4888 /* Leave end of line character */
4892 /* Cut the end of line character only */
4893 if (tb->yank_eol) add_str_to_yank(tb, "");
4895 /* Cut end of line */
4896 tb->yank_eol = TRUE;
4898 do_editor_command(tb, EC_DELETE_CHAR);
4902 case EC_DELETE_CHAR:
4903 /* DELETE == go forward + BACK SPACE */
4905 /* Ignore selection */
4911 tb->dirty_flags |= DIRTY_ALL;
4915 if (iskanji(tb->lines_list[tb->cy][tb->cx])) tb->cx++;
4919 do_editor_command(tb, EC_BACKSPACE);
4927 char buf[MAX_LINELEN];
4929 /* Ignore selection */
4935 tb->dirty_flags |= DIRTY_ALL;
4938 len = strlen(tb->lines_list[tb->cy]);
4941 if (tb->lines_list[tb->cy + 1])
4955 /* delete a return code and union two lines */
4956 if (tb->cy == 0) break;
4957 tb->cx = strlen(tb->lines_list[tb->cy-1]);
4958 strcpy(buf, tb->lines_list[tb->cy-1]);
4959 strcat(buf, tb->lines_list[tb->cy]);
4960 string_free(tb->lines_list[tb->cy-1]);
4961 string_free(tb->lines_list[tb->cy]);
4962 tb->lines_list[tb->cy-1] = string_make(buf);
4964 for (i = tb->cy; tb->lines_list[i+1]; i++)
4965 tb->lines_list[i] = tb->lines_list[i+1];
4967 tb->lines_list[i] = NULL;
4971 tb->dirty_flags |= DIRTY_ALL;
4973 /* Expressions need re-evaluation */
4974 tb->dirty_flags |= DIRTY_EXPRESSION;
4976 /* Text is changed */
4982 for (i = j = k = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
4986 if (iskanji(tb->lines_list[tb->cy][i]))
4987 buf[j++] = tb->lines_list[tb->cy][i++];
4989 buf[j++] = tb->lines_list[tb->cy][i];
4996 for (; tb->lines_list[tb->cy][i]; i++)
4997 buf[j++] = tb->lines_list[tb->cy][i];
4999 string_free(tb->lines_list[tb->cy]);
5000 tb->lines_list[tb->cy] = string_make(buf);
5003 tb->dirty_line = tb->cy;
5005 /* Expressions may need re-evaluation */
5006 check_expression_line(tb, tb->cy);
5008 /* Text is changed */
5018 /* Become dirty because of item/equip menu */
5019 tb->dirty_flags |= DIRTY_SCREEN;
5021 search_dir = get_string_for_search(&tb->search_o_ptr, &tb->search_str);
5023 if (!search_dir) break;
5025 if (search_dir == 1) do_editor_command(tb, EC_SEARCH_FORW);
5026 else do_editor_command(tb, EC_SEARCH_BACK);
5030 case EC_SEARCH_FORW:
5031 if (tb->search_o_ptr)
5033 if (!search_for_object(tb, tb->search_o_ptr, TRUE)) tb->dirty_flags |= DIRTY_NOT_FOUND;
5035 else if (tb->search_str)
5037 if (!search_for_string(tb, tb->search_str, TRUE)) tb->dirty_flags |= DIRTY_NOT_FOUND;
5041 tb->dirty_flags |= DIRTY_NO_SEARCH;
5045 case EC_SEARCH_BACK:
5046 if (tb->search_o_ptr)
5048 if (!search_for_object(tb, tb->search_o_ptr, FALSE)) tb->dirty_flags |= DIRTY_NOT_FOUND;
5050 else if (tb->search_str)
5052 if (!search_for_string(tb, tb->search_str, FALSE)) tb->dirty_flags |= DIRTY_NOT_FOUND;
5056 tb->dirty_flags |= DIRTY_NO_SEARCH;
5061 /* Become dirty because of item/equip menu */
5062 tb->dirty_flags |= DIRTY_SCREEN;
5064 if (!get_object_for_search(&tb->search_o_ptr, &tb->search_str)) break;
5066 do_editor_command(tb, EC_SEARCH_FORW);
5069 case EC_SEARCH_DESTROYED:
5070 if (!get_destroyed_object_for_search(&tb->search_o_ptr, &tb->search_str)) break;
5072 do_editor_command(tb, EC_SEARCH_FORW);
5075 case EC_INSERT_OBJECT:
5077 /* Insert choosen item name */
5079 autopick_type an_entry, *entry = &an_entry;
5081 if (!entry_from_choosed_object(entry))
5083 /* Now dirty because of item/equip menu */
5084 tb->dirty_flags |= DIRTY_SCREEN;
5089 insert_return_code(tb);
5090 string_free(tb->lines_list[tb->cy]);
5091 tb->lines_list[tb->cy] = autopick_line_from_entry_kill(entry);
5093 /* Now dirty because of item/equip menu */
5094 tb->dirty_flags |= DIRTY_SCREEN;
5099 case EC_INSERT_DESTROYED:
5100 /* Insert a name of last destroyed item */
5101 if (tb->last_destroyed)
5104 insert_return_code(tb);
5105 string_free(tb->lines_list[tb->cy]);
5106 tb->lines_list[tb->cy] = string_make(tb->last_destroyed);
5109 tb->dirty_flags |= DIRTY_ALL;
5111 /* Text is changed */
5116 case EC_INSERT_BLOCK:
5118 /* Insert a conditinal expression line */
5121 /* Conditional Expression for Class and Race */
5122 sprintf(classrace, "?:[AND [EQU $RACE %s] [EQU $CLASS %s]]",
5124 rp_ptr->E_title, cp_ptr->E_title
5126 rp_ptr->title, cp_ptr->title
5131 insert_return_code(tb);
5132 string_free(tb->lines_list[tb->cy]);
5133 tb->lines_list[tb->cy] = string_make(classrace);
5135 insert_return_code(tb);
5136 string_free(tb->lines_list[tb->cy]);
5137 tb->lines_list[tb->cy] = string_make("?:1");
5140 tb->dirty_flags |= DIRTY_ALL;
5142 /* Text is changed */
5148 case EC_INSERT_MACRO:
5149 /* Draw_everythig (delete menu) */
5150 draw_text_editor(tb);
5153 Term_erase(0, tb->cy - tb->upper + 1, tb->wid);
5157 Term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW, "P:<¥È¥ê¥¬¡¼¥¡¼>: ");
5159 Term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW, "P:<Trigger key>: ");
5161 if (insert_macro_line(tb))
5163 /* Prepare to input action */
5167 tb->dirty_flags |= DIRTY_ALL;
5169 /* Text is changed */
5175 case EC_INSERT_KEYMAP:
5176 /* Draw_everythig (delete menu) */
5177 draw_text_editor(tb);
5180 Term_erase(0, tb->cy - tb->upper + 1, tb->wid);
5184 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)));
5186 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)));
5189 if (insert_keymap_line(tb))
5191 /* Prepare to input action */
5195 tb->dirty_flags |= DIRTY_ALL;
5197 /* Text is changed */
5202 case EC_CL_AUTOPICK: toggle_command_letter(tb, DO_AUTOPICK); break;
5203 case EC_CL_DESTROY: toggle_command_letter(tb, DO_AUTODESTROY); break;
5204 case EC_CL_LEAVE: toggle_command_letter(tb, DONT_AUTOPICK); break;
5205 case EC_CL_QUERY: toggle_command_letter(tb, DO_QUERY_AUTOPICK); break;
5206 case EC_CL_NO_DISP: toggle_command_letter(tb, DO_DISPLAY); break;
5208 case EC_IK_UNAWARE: toggle_keyword(tb, FLG_UNAWARE); break;
5209 case EC_IK_UNIDENTIFIED: toggle_keyword(tb, FLG_UNIDENTIFIED); break;
5210 case EC_IK_IDENTIFIED: toggle_keyword(tb, FLG_IDENTIFIED); break;
5211 case EC_IK_STAR_IDENTIFIED: toggle_keyword(tb, FLG_STAR_IDENTIFIED); break;
5212 case EC_KK_WEAPONS: toggle_keyword(tb, FLG_WEAPONS); break;
5213 case EC_KK_FAVORITE: toggle_keyword(tb, FLG_FAVORITE); break;
5214 case EC_KK_ARMORS: toggle_keyword(tb, FLG_ARMORS); break;
5215 case EC_KK_MISSILES: toggle_keyword(tb, FLG_MISSILES); break;
5216 case EC_KK_DEVICES: toggle_keyword(tb, FLG_DEVICES); break;
5217 case EC_KK_LIGHTS: toggle_keyword(tb, FLG_LIGHTS); break;
5218 case EC_KK_JUNKS: toggle_keyword(tb, FLG_JUNKS); break;
5219 case EC_KK_SPELLBOOKS: toggle_keyword(tb, FLG_SPELLBOOKS); break;
5220 case EC_KK_SHIELDS: toggle_keyword(tb, FLG_SHIELDS); break;
5221 case EC_KK_BOWS: toggle_keyword(tb, FLG_BOWS); break;
5222 case EC_KK_RINGS: toggle_keyword(tb, FLG_RINGS); break;
5223 case EC_KK_AMULETS: toggle_keyword(tb, FLG_AMULETS); break;
5224 case EC_KK_SUITS: toggle_keyword(tb, FLG_SUITS); break;
5225 case EC_KK_CLOAKS: toggle_keyword(tb, FLG_CLOAKS); break;
5226 case EC_KK_HELMS: toggle_keyword(tb, FLG_HELMS); break;
5227 case EC_KK_GLOVES: toggle_keyword(tb, FLG_GLOVES); break;
5228 case EC_KK_BOOTS: toggle_keyword(tb, FLG_BOOTS); break;
5229 case EC_OK_COLLECTING: toggle_keyword(tb, FLG_COLLECTING); break;
5230 case EC_OK_BOOSTED: toggle_keyword(tb, FLG_BOOSTED); break;
5231 case EC_OK_MORE_THAN: toggle_keyword(tb, FLG_MORE_THAN); break;
5232 case EC_OK_MORE_BONUS: toggle_keyword(tb, FLG_MORE_BONUS); break;
5233 case EC_OK_WORTHLESS: toggle_keyword(tb, FLG_WORTHLESS); break;
5234 case EC_OK_ARTIFACT: toggle_keyword(tb, FLG_ARTIFACT); break;
5235 case EC_OK_EGO: toggle_keyword(tb, FLG_EGO); break;
5236 case EC_OK_NAMELESS: toggle_keyword(tb, FLG_NAMELESS); break;
5237 case EC_OK_WANTED: toggle_keyword(tb, FLG_WANTED); break;
5238 case EC_OK_UNIQUE: toggle_keyword(tb, FLG_UNIQUE); break;
5239 case EC_OK_HUMAN: toggle_keyword(tb, FLG_HUMAN); break;
5240 case EC_OK_UNREADABLE:
5241 toggle_keyword(tb, FLG_UNREADABLE);
5242 add_keyword(tb, FLG_SPELLBOOKS);
5245 toggle_keyword(tb, FLG_REALM1);
5246 add_keyword(tb, FLG_SPELLBOOKS);
5249 toggle_keyword(tb, FLG_REALM2);
5250 add_keyword(tb, FLG_SPELLBOOKS);
5253 toggle_keyword(tb, FLG_FIRST);
5254 add_keyword(tb, FLG_SPELLBOOKS);
5257 toggle_keyword(tb, FLG_SECOND);
5258 add_keyword(tb, FLG_SPELLBOOKS);
5261 toggle_keyword(tb, FLG_THIRD);
5262 add_keyword(tb, FLG_SPELLBOOKS);
5265 toggle_keyword(tb, FLG_FOURTH);
5266 add_keyword(tb, FLG_SPELLBOOKS);
5270 /* Save old command */
5271 tb->old_com_id = com_id;
5278 * Insert single letter at cursor position.
5280 static void insert_single_letter(text_body_type *tb, int key)
5283 char buf[MAX_LINELEN];
5285 /* Save preceding string */
5286 for (i = j = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
5287 buf[j++] = tb->lines_list[tb->cy][i];
5289 /* Add a character */
5297 if (j+2 < MAX_LINELEN)
5309 if (j+1 < MAX_LINELEN)
5315 for (; tb->lines_list[tb->cy][i] && j + 1 < MAX_LINELEN; i++)
5316 buf[j++] = tb->lines_list[tb->cy][i];
5319 /* Replace current line with new line */
5320 string_free(tb->lines_list[tb->cy]);
5321 tb->lines_list[tb->cy] = string_make(buf);
5323 /* Move to correct collumn */
5324 len = strlen(tb->lines_list[tb->cy]);
5325 if (len < tb->cx) tb->cx = len;
5328 tb->dirty_line = tb->cy;
5330 /* Expressions may need re-evaluation */
5331 check_expression_line(tb, tb->cy);
5333 /* Text is changed */
5338 * In-game editor of Object Auto-picker/Destoryer
5340 void do_cmd_edit_autopick(void)
5342 static int cx_save = 0;
5343 static int cy_save = 0;
5345 text_body_type text_body, *tb = &text_body;
5347 autopick_type an_entry, *entry = &an_entry;
5348 char buf[MAX_LINELEN];
5353 static s32b old_autosave_turn = 0L;
5356 tb->changed = FALSE;
5359 tb->upper = tb->left = 0;
5361 tb->mx = tb->my = 0;
5362 tb->old_cy = tb->old_upper = tb->old_left = -1;
5363 tb->old_wid = tb->old_hgt = -1;
5367 tb->search_o_ptr = NULL;
5368 tb->search_str = NULL;
5369 tb->last_destroyed = NULL;
5370 tb->dirty_flags = DIRTY_ALL | DIRTY_MODE | DIRTY_EXPRESSION;
5371 tb->dirty_line = -1;
5372 tb->filename_mode = PT_DEFAULT;
5375 if (turn > old_autosave_turn + 100L)
5377 do_cmd_save_game(TRUE);
5378 old_autosave_turn = turn;
5381 /* HACK -- Reset start_time to stop counting playtime while edit */
5384 /* Free old entries */
5387 /* Command Description of the 'Last Destroyed Item' */
5388 if (autopick_last_destroyed_object.k_idx)
5390 autopick_entry_from_object(entry, &autopick_last_destroyed_object);
5391 tb->last_destroyed = autopick_line_from_entry_kill(entry);
5394 /* Read or initialize whole text */
5395 tb->lines_list = read_pickpref_text_lines(&tb->filename_mode);
5397 /* Reset cursor position if needed */
5398 for (i = 0; i < tb->cy; i++)
5400 if (!tb->lines_list[i])
5402 tb->cy = tb->cx = 0;
5407 /* Save the screen */
5410 /* Process requests until done */
5416 /* Draw_everythig */
5417 draw_text_editor(tb);
5419 /* Display header line */
5421 prt("(^Q:½ªÎ» ^W:¥»¡¼¥Ö¤·¤Æ½ªÎ», ESC:¥á¥Ë¥å¡¼, ¤½¤Î¾:ÆþÎÏ)", 0, 0);
5423 prt("(^Q:quit, ^W:save&quit, ESC:menu, Other:input text)", 0, 0);
5427 /* Display current position */
5428 prt (format("(%d,%d)", tb->cx, tb->cy), 0, 60);
5432 /* Display current position and mark position */
5433 prt (format("(%d,%d)-(%d,%d)", tb->mx, tb->my, tb->cx, tb->cy), 0, 60);
5437 Term_gotoxy(tb->cx - tb->left, tb->cy - tb->upper + 1);
5440 tb->dirty_flags = 0;
5441 tb->dirty_line = -1;
5443 /* Save old key and location */
5444 tb->old_cy = tb->cy;
5445 tb->old_upper = tb->upper;
5446 tb->old_left = tb->left;
5447 tb->old_wid = tb->wid;
5448 tb->old_hgt = tb->hgt;
5453 /* Count length of macro trigger which induced this key */
5454 trig_len = strlen(inkey_macro_trigger_string);
5456 /* HACK -- ignore macro defined on ASCII keys */
5459 /* Get original key */
5460 key = inkey_macro_trigger_string[0];
5462 /* Kill further macro expansion */
5467 if (key == 0x7F) key = KTRL('d');
5470 /* Cursor key macroes to direction command */
5492 * Un-shifted cursor keys cancells
5493 * selection created by shift+cursor.
5495 if (tb->mark & MARK_BY_SHIFT)
5500 tb->dirty_flags |= DIRTY_ALL;
5504 /* Mega Hack!!! Start selection with shift + cursor keys */
5509 /* Get ascii form */
5510 ascii_to_text(buf, inkey_macro_trigger_string);
5512 if (strstr(buf, "shift-Down"))
5514 else if (strstr(buf, "shift-Left"))
5516 else if (strstr(buf, "shift-Right"))
5518 else if (strstr(buf, "shift-Up"))
5523 /* Kill further macro expansion */
5526 /* Start selection */
5529 int len = strlen(tb->lines_list[tb->cy]);
5531 tb->mark = MARK_MARK | MARK_BY_SHIFT;
5535 /* Correct cursor location */
5536 if (tb->cx > len) tb->mx = len;
5538 /* Need to redraw text */
5539 if (com_id == EC_UP || com_id == EC_DOWN)
5541 /* Redraw all text */
5542 tb->dirty_flags |= DIRTY_ALL;
5546 tb->dirty_line = tb->cy;
5559 else if (key == ESCAPE)
5561 com_id = do_command_menu(0, 0);
5563 /* Redraw all text later */
5564 tb->dirty_flags |= DIRTY_SCREEN;
5567 /* Insert a character */
5568 else if (!iscntrl(key & 0xff))
5570 /* Ignore selection */
5576 tb->dirty_flags |= DIRTY_ALL;
5579 insert_single_letter(tb, key);
5585 /* Other commands */
5588 com_id = get_com_id(key);
5591 if (com_id) quit = do_editor_command(tb, com_id);
5594 /* Restore the screen */
5597 /* Get the filename of preference */
5598 strcpy(buf, pickpref_filename(tb->filename_mode));
5600 if (quit == QUIT_AND_SAVE)
5601 write_text_lines(buf, tb->lines_list);
5603 free_text_lines(tb->lines_list);
5605 string_free(tb->last_destroyed);
5607 /* Destroy string chain */
5608 kill_yank_chain(tb);
5610 /* Reload autopick pref */
5611 process_pickpref_file(buf);
5613 /* HACK -- reset start_time so that playtime is not increase while edit */
5614 start_time = time(NULL);
5616 /* Save cursor location */