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);
427 * A function to delete entry
429 static void autopick_free_entry(autopick_type *entry)
431 string_free(entry->name);
432 string_free(entry->insc);
437 * Initialize auto-picker preference
439 void init_autopicker(void)
441 static const char easy_autopick_inscription[] = "(:=g";
445 /* Clear old entries */
446 for( i = 0; i < max_autopick; i++)
447 autopick_free_entry(&autopick_list[i]);
451 /* There is always one entry "=g" */
452 autopick_new_entry(&entry, easy_autopick_inscription, TRUE);
453 autopick_list[max_autopick++] = entry;
459 * Process line for auto picker/destroyer.
461 errr process_pickpref_file_line(char *buf)
466 if (max_autopick == MAX_AUTOPICK)
469 /* Nuke illegal char */
470 for(i = 0; buf[i]; i++)
479 if (isspace(buf[i]) && buf[i] != ' ')
484 if (!autopick_new_entry(&entry, buf, FALSE)) return 0;
486 /* Already has the same entry? */
487 for(i = 0; i < max_autopick; i++)
488 if(!strcmp(entry.name, autopick_list[i].name)
489 && entry.flag[0] == autopick_list[i].flag[0]
490 && entry.flag[1] == autopick_list[i].flag[1]
491 && entry.dice == autopick_list[i].dice
492 && entry.bonus == autopick_list[i].bonus) return 0;
494 autopick_list[max_autopick++] = entry;
500 * Reconstruct preference line from entry
502 cptr autopick_line_from_entry(autopick_type *entry)
504 char buf[MAX_LINELEN];
506 bool sepa_flag = TRUE;
509 if (!(entry->action & DO_DISPLAY)) strcat(buf, "(");
510 if (entry->action & DO_QUERY_AUTOPICK) strcat(buf, ";");
511 if (entry->action & DO_AUTODESTROY) strcat(buf, "!");
512 if (entry->action & DONT_AUTOPICK) strcat(buf, "~");
516 if (IS_FLG(FLG_ALL)) ADD_KEY(KEY_ALL);
517 if (IS_FLG(FLG_COLLECTING)) ADD_KEY(KEY_COLLECTING);
518 if (IS_FLG(FLG_UNIDENTIFIED)) ADD_KEY(KEY_UNIDENTIFIED);
519 if (IS_FLG(FLG_IDENTIFIED)) ADD_KEY(KEY_IDENTIFIED);
520 if (IS_FLG(FLG_STAR_IDENTIFIED)) ADD_KEY(KEY_STAR_IDENTIFIED);
521 if (IS_FLG(FLG_UNAWARE)) ADD_KEY(KEY_UNAWARE);
522 if (IS_FLG(FLG_BOOSTED)) ADD_KEY(KEY_BOOSTED);
524 if (IS_FLG(FLG_MORE_THAN))
526 ADD_KEY(KEY_MORE_THAN);
527 strcat(ptr, format("%d", entry->dice));
531 if (IS_FLG(FLG_MORE_BONUS))
533 ADD_KEY(KEY_MORE_BONUS);
534 strcat(ptr, format("%d", entry->bonus));
535 ADD_KEY(KEY_MORE_BONUS2);
538 if (IS_FLG(FLG_UNREADABLE)) ADD_KEY(KEY_UNREADABLE);
539 if (IS_FLG(FLG_REALM1)) ADD_KEY(KEY_REALM1);
540 if (IS_FLG(FLG_REALM2)) ADD_KEY(KEY_REALM2);
541 if (IS_FLG(FLG_FIRST)) ADD_KEY(KEY_FIRST);
542 if (IS_FLG(FLG_SECOND)) ADD_KEY(KEY_SECOND);
543 if (IS_FLG(FLG_THIRD)) ADD_KEY(KEY_THIRD);
544 if (IS_FLG(FLG_FOURTH)) ADD_KEY(KEY_FOURTH);
545 if (IS_FLG(FLG_WANTED)) ADD_KEY(KEY_WANTED);
546 if (IS_FLG(FLG_UNIQUE)) ADD_KEY(KEY_UNIQUE);
547 if (IS_FLG(FLG_HUMAN)) ADD_KEY(KEY_HUMAN);
548 if (IS_FLG(FLG_WORTHLESS)) ADD_KEY(KEY_WORTHLESS);
549 if (IS_FLG(FLG_NAMELESS)) ADD_KEY(KEY_NAMELESS);
550 if (IS_FLG(FLG_EGO)) ADD_KEY(KEY_EGO);
552 if (IS_FLG(FLG_ARTIFACT)) ADD_KEY(KEY_ARTIFACT);
554 if (IS_FLG(FLG_ITEMS)) ADD_KEY2(KEY_ITEMS);
555 else if (IS_FLG(FLG_WEAPONS)) ADD_KEY2(KEY_WEAPONS);
556 else if (IS_FLG(FLG_ARMORS)) ADD_KEY2(KEY_ARMORS);
557 else if (IS_FLG(FLG_MISSILES)) ADD_KEY2(KEY_MISSILES);
558 else if (IS_FLG(FLG_DEVICES)) ADD_KEY2(KEY_DEVICES);
559 else if (IS_FLG(FLG_LIGHTS)) ADD_KEY2(KEY_LIGHTS);
560 else if (IS_FLG(FLG_JUNKS)) ADD_KEY2(KEY_JUNKS);
561 else if (IS_FLG(FLG_SPELLBOOKS)) ADD_KEY2(KEY_SPELLBOOKS);
562 else if (IS_FLG(FLG_HAFTED)) ADD_KEY2(KEY_HAFTED);
563 else if (IS_FLG(FLG_SHIELDS)) ADD_KEY2(KEY_SHIELDS);
564 else if (IS_FLG(FLG_BOWS)) ADD_KEY2(KEY_BOWS);
565 else if (IS_FLG(FLG_RINGS)) ADD_KEY2(KEY_RINGS);
566 else if (IS_FLG(FLG_AMULETS)) ADD_KEY2(KEY_AMULETS);
567 else if (IS_FLG(FLG_SUITS)) ADD_KEY2(KEY_SUITS);
568 else if (IS_FLG(FLG_CLOAKS)) ADD_KEY2(KEY_CLOAKS);
569 else if (IS_FLG(FLG_HELMS)) ADD_KEY2(KEY_HELMS);
570 else if (IS_FLG(FLG_GLOVES)) ADD_KEY2(KEY_GLOVES);
571 else if (IS_FLG(FLG_BOOTS)) ADD_KEY2(KEY_BOOTS);
572 else if (IS_FLG(FLG_FAVORITE)) ADD_KEY2(KEY_FAVORITE);
574 /* You don't need sepalator after adjective */
575 /* 'artifact' is not true adjective */
576 else if (!IS_FLG(FLG_ARTIFACT))
579 if (entry->name && entry->name[0])
583 if (sepa_flag) strcat(buf, ":");
586 while (entry->name[j] && i < MAX_LINELEN - 2 - 1)
589 if (iskanji(entry->name[j]))
590 buf[i++] = entry->name[j++];
592 buf[i++] = entry->name[j++];
603 while (entry->insc[j] && i < MAX_LINELEN - 2)
606 if (iskanji(entry->insc[j]))
607 buf[i++] = entry->insc[j++];
609 buf[i++] = entry->insc[j++];
614 return string_make(buf);
619 * Reconstruct preference line from entry and kill entry
621 static cptr autopick_line_from_entry_kill(autopick_type *entry)
623 cptr ptr = autopick_line_from_entry(entry);
625 /* Free memory for original entry */
626 autopick_free_entry(entry);
635 static bool is_favorite(object_type *o_ptr, bool others_ok)
637 /* Only weapons match */
640 case TV_BOW: case TV_HAFTED: case TV_POLEARM:
641 case TV_SWORD: case TV_DIGGING:
643 default: return FALSE;
646 /* Favorite weapons are varied depend on the class */
647 switch (p_ptr->pclass)
651 u32b flgs[TR_FLAG_SIZE];
652 object_flags_known(o_ptr, flgs);
654 if (!have_flag(flgs, TR_BLESSED) &&
655 !(o_ptr->tval == TV_HAFTED))
661 case CLASS_FORCETRAINER:
663 if (!(s_info[p_ptr->pclass].w_max[o_ptr->tval-TV_BOW][o_ptr->sval]))
667 case CLASS_BEASTMASTER:
670 u32b flgs[TR_FLAG_SIZE];
671 object_flags_known(o_ptr, flgs);
673 /* Is it known to be suitable to using while riding? */
674 if (!(have_flag(flgs, TR_RIDING)))
682 if (s_info[p_ptr->pclass].w_max[o_ptr->tval-TV_BOW][o_ptr->sval] <= WEAPON_EXP_BEGINNER)
687 /* Non-special class */
688 if (others_ok) return TRUE;
696 * A function for Auto-picker/destroyer
697 * Examine whether the object matches to the entry
699 static bool is_autopick_aux(object_type *o_ptr, autopick_type *entry, cptr o_name)
702 cptr ptr = entry->name;
704 /*** Unidentified ***/
705 if (IS_FLG(FLG_UNIDENTIFIED)
706 && (object_known_p(o_ptr) || (o_ptr->ident & IDENT_SENSE)))
710 if (IS_FLG(FLG_IDENTIFIED) && !object_known_p(o_ptr))
713 /*** *Identified* ***/
714 if (IS_FLG(FLG_STAR_IDENTIFIED) &&
715 (!object_known_p(o_ptr) || !(o_ptr->ident & IDENT_MENTAL)))
718 /*** Dice boosted (weapon of slaying) ***/
719 if (IS_FLG(FLG_BOOSTED))
721 object_kind *k_ptr = &k_info[o_ptr->k_idx];
723 switch( o_ptr->tval )
729 if ((o_ptr->dd != k_ptr->dd) || (o_ptr->ds != k_ptr->ds))
738 /*** Weapons which dd*ds is more than nn ***/
739 if (IS_FLG(FLG_MORE_THAN))
741 if (o_ptr->dd * o_ptr->ds < entry->dice)
745 /*** Weapons whic dd*ds is more than nn ***/
746 if (IS_FLG(FLG_MORE_BONUS))
748 if (!object_known_p(o_ptr)) return FALSE;
752 if (o_ptr->pval < entry->bonus) return FALSE;
756 if (o_ptr->to_h < entry->bonus &&
757 o_ptr->to_d < entry->bonus &&
758 o_ptr->to_a < entry->bonus &&
759 o_ptr->pval < entry->bonus)
764 /*** Worthless items ***/
765 if (IS_FLG(FLG_WORTHLESS) && object_value(o_ptr) > 0)
768 /*** Artifact object ***/
769 if (IS_FLG(FLG_ARTIFACT))
771 if (!object_known_p(o_ptr) || (!o_ptr->name1 && !o_ptr->art_name))
778 if (!object_known_p(o_ptr) || !o_ptr->name2)
783 if (IS_FLG(FLG_NAMELESS))
788 case TV_SHOT: case TV_ARROW: case TV_BOLT: case TV_BOW:
789 case TV_DIGGING: case TV_HAFTED: case TV_POLEARM: case TV_SWORD:
790 case TV_BOOTS: case TV_GLOVES: case TV_HELM: case TV_CROWN:
791 case TV_SHIELD: case TV_CLOAK:
792 case TV_SOFT_ARMOR: case TV_HARD_ARMOR: case TV_DRAG_ARMOR:
793 case TV_LITE: case TV_AMULET: case TV_RING: case TV_CARD:
794 if ((!object_known_p(o_ptr) || o_ptr->inscription
795 || o_ptr->name1 || o_ptr->name2 || o_ptr->art_name))
804 /*** Unaware items ***/
805 if (IS_FLG(FLG_UNAWARE) && object_aware_p(o_ptr))
808 /*** Wanted monster's corpse/skeletons ***/
809 if (IS_FLG(FLG_WANTED) &&
810 (o_ptr->tval != TV_CORPSE || !object_is_shoukinkubi(o_ptr)))
813 /*** Unique monster's corpse/skeletons/statues ***/
814 if (IS_FLG(FLG_UNIQUE) &&
815 ((o_ptr->tval != TV_CORPSE && o_ptr->tval != TV_STATUE) ||
816 !(r_info[o_ptr->pval].flags1 & RF1_UNIQUE)))
819 /*** Human corpse/skeletons (for Daemon magic) ***/
820 if (IS_FLG(FLG_HUMAN) &&
821 (o_ptr->tval != TV_CORPSE ||
822 !strchr("pht", r_info[o_ptr->pval].d_char)))
825 /*** Unreadable spellbooks ***/
826 if (IS_FLG(FLG_UNREADABLE) &&
827 (o_ptr->tval < TV_LIFE_BOOK ||
828 check_book_realm(o_ptr->tval, o_ptr->sval)))
831 /*** First realm spellbooks ***/
832 if (IS_FLG(FLG_REALM1) &&
833 (REALM1_BOOK != o_ptr->tval ||
834 p_ptr->pclass == CLASS_SORCERER ||
835 p_ptr->pclass == CLASS_RED_MAGE))
838 /*** Second realm spellbooks ***/
839 if (IS_FLG(FLG_REALM2) &&
840 (REALM2_BOOK != o_ptr->tval ||
841 p_ptr->pclass == CLASS_SORCERER ||
842 p_ptr->pclass == CLASS_RED_MAGE))
845 /*** First rank spellbooks ***/
846 if (IS_FLG(FLG_FIRST) &&
847 (o_ptr->tval < TV_LIFE_BOOK || 0 != o_ptr->sval))
850 /*** Second rank spellbooks ***/
851 if (IS_FLG(FLG_SECOND) &&
852 (o_ptr->tval < TV_LIFE_BOOK || 1 != o_ptr->sval))
855 /*** Third rank spellbooks ***/
856 if (IS_FLG(FLG_THIRD) &&
857 (o_ptr->tval < TV_LIFE_BOOK || 2 != o_ptr->sval))
860 /*** Fourth rank spellbooks ***/
861 if (IS_FLG(FLG_FOURTH) &&
862 (o_ptr->tval < TV_LIFE_BOOK || 3 != o_ptr->sval))
866 if (IS_FLG(FLG_WEAPONS))
870 case TV_BOW: case TV_HAFTED: case TV_POLEARM:
871 case TV_SWORD: case TV_DIGGING:
873 default: return FALSE;
876 else if (IS_FLG(FLG_ARMORS))
880 case TV_BOOTS: case TV_GLOVES: case TV_CLOAK: case TV_CROWN:
881 case TV_HELM: case TV_SHIELD: case TV_SOFT_ARMOR:
882 case TV_HARD_ARMOR: case TV_DRAG_ARMOR:
884 default: return FALSE;
887 else if (IS_FLG(FLG_MISSILES))
891 case TV_SHOT: case TV_BOLT: case TV_ARROW:
893 default: return FALSE;
896 else if (IS_FLG(FLG_DEVICES))
900 case TV_SCROLL: case TV_STAFF: case TV_WAND: case TV_ROD:
902 default: return FALSE;
905 else if (IS_FLG(FLG_LIGHTS))
907 if (!(o_ptr->tval == TV_LITE))
910 else if (IS_FLG(FLG_JUNKS))
914 case TV_SKELETON: case TV_BOTTLE:
915 case TV_JUNK: case TV_STATUE:
917 default: return FALSE;
920 else if (IS_FLG(FLG_SPELLBOOKS))
922 if (!(o_ptr->tval >= TV_LIFE_BOOK))
925 else if (IS_FLG(FLG_HAFTED))
927 if (!(o_ptr->tval == TV_HAFTED))
930 else if (IS_FLG(FLG_SHIELDS))
932 if (!(o_ptr->tval == TV_SHIELD))
935 else if (IS_FLG(FLG_BOWS))
937 if (!(o_ptr->tval == TV_BOW))
940 else if (IS_FLG(FLG_RINGS))
942 if (!(o_ptr->tval == TV_RING))
945 else if (IS_FLG(FLG_AMULETS))
947 if (!(o_ptr->tval == TV_AMULET))
950 else if (IS_FLG(FLG_SUITS))
952 if (!(o_ptr->tval == TV_DRAG_ARMOR ||
953 o_ptr->tval == TV_HARD_ARMOR ||
954 o_ptr->tval == TV_SOFT_ARMOR))
957 else if (IS_FLG(FLG_CLOAKS))
959 if (!(o_ptr->tval == TV_CLOAK))
962 else if (IS_FLG(FLG_HELMS))
964 if (!(o_ptr->tval == TV_CROWN || o_ptr->tval == TV_HELM))
967 else if (IS_FLG(FLG_GLOVES))
969 if (!(o_ptr->tval == TV_GLOVES))
972 else if (IS_FLG(FLG_BOOTS))
974 if (!(o_ptr->tval == TV_BOOTS))
977 else if (IS_FLG(FLG_FAVORITE))
979 if (!is_favorite(o_ptr, TRUE))
983 /* Keyword don't match */
987 if (strncmp(o_name, ptr, strlen(ptr))) return FALSE;
992 if (!strstr_j(o_name, ptr)) return FALSE;
994 if (!strstr(o_name, ptr)) return FALSE;
998 /* TRUE when it need not to be 'collecting' */
999 if (!IS_FLG(FLG_COLLECTING)) return TRUE;
1001 /* Check if there is a same item */
1002 for (j = 0; j < INVEN_PACK; j++)
1005 * 'Collecting' means the item must be absorbed
1006 * into an inventory slot.
1007 * But an item can not be absorbed into itself!
1009 if ((&inventory[j] != o_ptr) &&
1010 object_similar(&inventory[j], o_ptr))
1014 /* Not collecting */
1020 * A function for Auto-picker/destroyer
1021 * Examine whether the object matches to the list of keywords or not.
1023 int is_autopick(object_type *o_ptr)
1026 char o_name[MAX_NLEN];
1028 if (o_ptr->tval == TV_GOLD) return -1;
1030 object_desc(o_name, o_ptr, FALSE, 3);
1032 /* Force to be lower case string */
1033 for (i = 0; o_name[i]; i++)
1036 if (iskanji(o_name[i]))
1040 if (isupper(o_name[i]))
1041 o_name[i] = tolower(o_name[i]);
1044 for (i=0; i < max_autopick; i++)
1046 autopick_type *entry = &autopick_list[i];
1048 if (is_autopick_aux(o_ptr, entry, o_name)) return i;
1051 /* No matching entry */
1059 void auto_inscribe_item(int item, int idx)
1063 /* Get the item (in the pack) */
1064 if (item >= 0) o_ptr = &inventory[item];
1066 /* Get the item (on the floor) */
1067 else o_ptr = &o_list[0 - item];
1069 /* Auto-inscription or Re-inscribe for resistances {%} */
1070 if ((idx < 0 || !autopick_list[idx].insc) && !o_ptr->inscription)
1073 if (!o_ptr->inscription)
1074 o_ptr->inscription = quark_add(autopick_list[idx].insc);
1076 if (item > INVEN_PACK)
1078 /* Redraw inscription */
1079 p_ptr->window |= (PW_EQUIP);
1081 /* {.} and {$} effect p_ptr->warning and TRC_TELEPORT_SELF */
1082 p_ptr->update |= (PU_BONUS);
1086 /* Redraw inscription */
1087 p_ptr->window |= (PW_INVEN);
1093 * Automatically destroy items in this grid.
1095 static bool is_opt_confirm_destroy(object_type *o_ptr)
1097 if (!destroy_items) return FALSE;
1099 /* Known to be worthless? */
1101 if (object_value(o_ptr) > 0) return FALSE;
1104 if ((o_ptr->tval >= TV_SHOT) && (o_ptr->tval <= TV_DRAG_ARMOR)) return FALSE;
1107 if ((o_ptr->tval == TV_CHEST) && o_ptr->pval) return FALSE;
1111 if (o_ptr->tval == TV_CORPSE
1112 && object_is_shoukinkubi(o_ptr)) return FALSE;
1116 if (o_ptr->tval == TV_CORPSE) return FALSE;
1119 if ((o_ptr->tval == TV_SKELETON) || (o_ptr->tval == TV_BOTTLE) || (o_ptr->tval == TV_JUNK) || (o_ptr->tval == TV_STATUE)) return FALSE;
1123 if (p_ptr->prace == RACE_DEMON)
1125 if (o_ptr->tval == TV_CORPSE &&
1126 o_ptr->sval == SV_CORPSE &&
1127 strchr("pht", r_info[o_ptr->pval].d_char))
1131 if (p_ptr->pclass == CLASS_ARCHER)
1133 if (o_ptr->tval == TV_SKELETON ||
1134 (o_ptr->tval == TV_CORPSE && o_ptr->sval == SV_SKELETON))
1137 else if (p_ptr->pclass == CLASS_NINJA)
1139 if (o_ptr->tval == TV_LITE &&
1140 o_ptr->name2 == EGO_LITE_DARKNESS)
1143 else if (p_ptr->pclass == CLASS_BEASTMASTER ||
1144 p_ptr->pclass == CLASS_CAVALRY)
1146 if (o_ptr->tval == TV_WAND &&
1147 o_ptr->sval == SV_WAND_HEAL_MONSTER)
1152 if (o_ptr->tval == TV_GOLD) return FALSE;
1159 * Automatically destroy an item if it is to be destroyed
1161 static object_type autopick_last_destroyed_object;
1163 bool auto_destroy_item(int item, int autopick_idx)
1165 bool destroy = FALSE;
1168 /* Don't destroy equipped items */
1169 if (item > INVEN_PACK) return FALSE;
1171 /* Get the item (in the pack) */
1172 if (item >= 0) o_ptr = &inventory[item];
1174 /* Get the item (on the floor) */
1175 else o_ptr = &o_list[0 - item];
1177 /* Easy-Auto-Destroyer */
1178 if (is_opt_confirm_destroy(o_ptr)) destroy = TRUE;
1180 /* Protected by auto-picker */
1181 if (autopick_idx >= 0 &&
1182 !(autopick_list[autopick_idx].action & DO_AUTODESTROY))
1187 /* Auto-picker/destroyer */
1188 if (autopick_idx >= 0 &&
1189 (autopick_list[autopick_idx].action & DO_AUTODESTROY))
1193 /* Not to be destroyed */
1194 if (!destroy) return FALSE;
1196 /* Now decided to destroy */
1201 if (!can_player_destroy_object(o_ptr))
1203 char o_name[MAX_NLEN];
1205 /* Describe the object (with {terrible/special}) */
1206 object_desc(o_name, o_ptr, TRUE, 3);
1210 msg_format("%s¤ÏÇ˲õÉÔǽ¤À¡£", o_name);
1212 msg_format("You cannot auto-destroy %s.", o_name);
1219 /* Record name of destroyed item */
1220 COPY(&autopick_last_destroyed_object, o_ptr, object_type);
1223 o_ptr->marked |= OM_AUTODESTROY;
1224 p_ptr->notice |= PN_AUTODESTROY;
1231 * Auto-destroy marked item
1233 static void delayed_auto_destroy_aux(int item)
1237 /* Get the item (in the pack) */
1238 if (item >= 0) o_ptr = &inventory[item];
1240 /* Get the item (on the floor) */
1241 else o_ptr = &o_list[0 - item];
1243 if (o_ptr->k_idx && o_ptr->marked & OM_AUTODESTROY)
1245 char o_name[MAX_NLEN];
1247 /* Describe the object (with {terrible/special}) */
1248 object_desc(o_name, o_ptr, TRUE, 3);
1250 /* Eliminate the item (from the pack) */
1253 inven_item_increase(item, -(o_ptr->number));
1254 inven_item_optimize(item);
1257 /* Eliminate the item (from the floor) */
1260 delete_object_idx(0 - item);
1263 /* Print a message */
1265 msg_format("%s¤ò¼«Æ°Ç˲õ¤·¤Þ¤¹¡£", o_name);
1267 msg_format("Auto-destroying %s.", o_name);
1274 * Auto-destroy marked item in inventry and on floor
1276 void delayed_auto_destroy(void)
1281 * Scan inventry in reverse order to prevent
1282 * skipping after inven_item_optimize()
1284 for (item = INVEN_TOTAL - 1; item >= 0 ; item--)
1285 delayed_auto_destroy_aux(item);
1287 /* Scan the pile of objects */
1288 item = cave[py][px].o_idx;
1291 int next = o_list[item].next_o_idx;
1292 delayed_auto_destroy_aux(-item);
1299 * Automatically pickup/destroy items in this grid.
1301 void auto_pickup_items(cave_type *c_ptr)
1303 s16b this_o_idx, next_o_idx = 0;
1305 /* Scan the pile of objects */
1306 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1310 /* Acquire object */
1311 object_type *o_ptr = &o_list[this_o_idx];
1313 /* Acquire next object */
1314 next_o_idx = o_ptr->next_o_idx;
1316 idx = is_autopick(o_ptr);
1318 /* Item index for floor -1,-2,-3,... */
1319 auto_inscribe_item((-this_o_idx), idx);
1322 (autopick_list[idx].action & (DO_AUTOPICK | DO_QUERY_AUTOPICK)))
1326 if (!inven_carry_okay(o_ptr))
1328 char o_name[MAX_NLEN];
1330 /* Describe the object */
1331 object_desc(o_name, o_ptr, TRUE, 3);
1335 msg_format("¥¶¥Ã¥¯¤Ë¤Ï%s¤òÆþ¤ì¤ë·ä´Ö¤¬¤Ê¤¤¡£", o_name);
1337 msg_format("You have no room for %s.", o_name);
1339 /* Hack - remember that the item has given a message here. */
1340 o_ptr->marked |= OM_NOMSG;
1344 else if (autopick_list[idx].action & DO_QUERY_AUTOPICK)
1346 char out_val[MAX_NLEN+20];
1347 char o_name[MAX_NLEN];
1349 if (o_ptr->marked & OM_NO_QUERY)
1351 /* Already answered as 'No' */
1355 /* Describe the object */
1356 object_desc(o_name, o_ptr, TRUE, 3);
1359 sprintf(out_val, "%s¤ò½¦¤¤¤Þ¤¹¤«? ", o_name);
1361 sprintf(out_val, "Pick up %s? ", o_name);
1364 if (!get_check(out_val))
1366 /* Hack - remember that the item has given a message here. */
1367 o_ptr->marked |= (OM_NOMSG | OM_NO_QUERY);
1372 py_pickup_aux(this_o_idx);
1379 * When always_pickup is 'yes', we disable
1380 * auto-destroyer from autopick function, and do only
1381 * easy-auto-destroyer.
1385 if (auto_destroy_item((-this_o_idx), idx))
1392 /******** Auto-picker/destroyer editor **********/
1394 #define MAX_YANK MAX_LINELEN
1395 #define MAX_LINES 3000
1397 #define MARK_MARK 0x01
1398 #define MARK_BY_SHIFT 0x02
1400 #define LSTAT_BYPASS 0x01
1401 #define LSTAT_EXPRESSION 0x02
1403 #define QUIT_WITHOUT_SAVE 1
1404 #define QUIT_AND_SAVE 2
1407 * Struct for yank buffer
1409 typedef struct chain_str {
1410 struct chain_str *next;
1416 * Data struct for text editor
1422 int old_wid, old_hgt;
1424 int old_upper, old_left;
1428 object_type *search_o_ptr;
1430 cptr last_destroyed;
1432 chain_str_type *yank;
1436 byte states[MAX_LINES];
1448 * Dirty flag for text editor
1450 #define DIRTY_ALL 0x01
1451 #define DIRTY_MODE 0x04
1452 #define DIRTY_SCREEN 0x08
1453 #define DIRTY_NOT_FOUND 0x10
1454 #define DIRTY_NO_SEARCH 0x20
1455 #define DIRTY_EXPRESSION 0x40
1459 * Describe which kind of object is Auto-picked/destroyed
1461 static void describe_autopick(char *buff, autopick_type *entry)
1463 cptr str = entry->name;
1464 byte act = entry->action;
1465 cptr insc = entry->insc;
1471 cptr before_str[100], body_str;
1474 body_str = "¥¢¥¤¥Æ¥à";
1476 /*** Collecting items ***/
1477 /*** Which can be absorbed into a slot as a bundle ***/
1478 if (IS_FLG(FLG_COLLECTING))
1479 before_str[before_n++] = "¼ý½¸Ãæ¤Ç´û¤Ë»ý¤Ã¤Æ¤¤¤ë¥¹¥í¥Ã¥È¤Ë¤Þ¤È¤á¤é¤ì¤ë";
1481 /*** Unidentified ***/
1482 if (IS_FLG(FLG_UNIDENTIFIED))
1483 before_str[before_n++] = "̤´ÕÄê¤Î";
1485 /*** Identified ***/
1486 if (IS_FLG(FLG_IDENTIFIED))
1487 before_str[before_n++] = "´ÕÄêºÑ¤ß¤Î";
1489 /*** *Identified* ***/
1490 if (IS_FLG(FLG_STAR_IDENTIFIED))
1491 before_str[before_n++] = "´°Á´¤Ë´ÕÄêºÑ¤ß¤Î";
1493 /*** Dice boosted (weapon of slaying) ***/
1494 if (IS_FLG(FLG_BOOSTED))
1496 before_str[before_n++] = "¥À¥á¡¼¥¸¥À¥¤¥¹¤¬Ä̾ï¤è¤êÂ礤¤";
1500 /*** Weapons whose dd*ds is more than nn ***/
1501 if (IS_FLG(FLG_MORE_THAN))
1503 static char more_than_desc_str[] = "___";
1504 before_str[before_n++] = "¥À¥á¡¼¥¸¥À¥¤¥¹¤ÎºÇÂçÃͤ¬";
1507 sprintf(more_than_desc_str,"%d", entry->dice);
1508 before_str[before_n++] = more_than_desc_str;
1509 before_str[before_n++] = "°Ê¾å¤Î";
1512 /*** Items whose magical bonus is more than nn ***/
1513 if (IS_FLG(FLG_MORE_BONUS))
1515 static char more_bonus_desc_str[] = "___";
1516 before_str[before_n++] = "½¤ÀµÃͤ¬(+";
1518 sprintf(more_bonus_desc_str,"%d", entry->bonus);
1519 before_str[before_n++] = more_bonus_desc_str;
1520 before_str[before_n++] = ")°Ê¾å¤Î";
1523 /*** Worthless items ***/
1524 if (IS_FLG(FLG_WORTHLESS))
1525 before_str[before_n++] = "Ź¤Ç̵²ÁÃͤÈȽÄꤵ¤ì¤ë";
1528 if (IS_FLG(FLG_ARTIFACT))
1530 before_str[before_n++] = "¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È¤Î";
1535 if (IS_FLG(FLG_EGO))
1537 before_str[before_n++] = "¥¨¥´¥¢¥¤¥Æ¥à¤Î";
1542 if (IS_FLG(FLG_NAMELESS))
1544 before_str[before_n++] = "¥¨¥´¤Ç¤â¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È¤Ç¤â¤Ê¤¤";
1548 /*** Unaware items ***/
1549 if (IS_FLG(FLG_UNAWARE))
1550 before_str[before_n++] = "̤´ÕÄê¤Ç¤½¤Î¸ú²Ì¤âȽÌÀ¤·¤Æ¤¤¤Ê¤¤";
1552 /*** Wanted monster's corpse/skeletons ***/
1553 if (IS_FLG(FLG_WANTED))
1555 before_str[before_n++] = "¥Ï¥ó¥¿¡¼»ö̳½ê¤Ç¾Þ¶â¼ó¤È¤µ¤ì¤Æ¤¤¤ë";
1556 body_str = "»àÂΤä¹ü";
1559 /*** Human corpse/skeletons (for Daemon magic) ***/
1560 if (IS_FLG(FLG_HUMAN))
1562 before_str[before_n++] = "°ËâËâË¡¤Ç»È¤¦¤¿¤á¤Î¿Í´Ö¤ä¥Ò¥å¡¼¥Þ¥Î¥¤¥É¤Î";
1563 body_str = "»àÂΤä¹ü";
1566 /*** Unique monster's corpse/skeletons/statues ***/
1567 if (IS_FLG(FLG_UNIQUE))
1569 before_str[before_n++] = "¥æ¥Ë¡¼¥¯¥â¥ó¥¹¥¿¡¼¤Î";
1570 body_str = "»àÂΤä¹ü";
1573 /*** Unreadable spellbooks ***/
1574 if (IS_FLG(FLG_UNREADABLE))
1576 before_str[before_n++] = "¤¢¤Ê¤¿¤¬Æɤá¤Ê¤¤Îΰè¤Î";
1577 body_str = "ËâË¡½ñ";
1580 /*** First realm spellbooks ***/
1581 if (IS_FLG(FLG_REALM1))
1583 before_str[before_n++] = "Âè°ìÎΰè¤Î";
1584 body_str = "ËâË¡½ñ";
1587 /*** Second realm spellbooks ***/
1588 if (IS_FLG(FLG_REALM2))
1590 before_str[before_n++] = "ÂèÆóÎΰè¤Î";
1591 body_str = "ËâË¡½ñ";
1594 /*** First rank spellbooks ***/
1595 if (IS_FLG(FLG_FIRST))
1597 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î1ºýÌܤÎ";
1598 body_str = "ËâË¡½ñ";
1601 /*** Second rank spellbooks ***/
1602 if (IS_FLG(FLG_SECOND))
1604 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î2ºýÌܤÎ";
1605 body_str = "ËâË¡½ñ";
1608 /*** Third rank spellbooks ***/
1609 if (IS_FLG(FLG_THIRD))
1611 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î3ºýÌܤÎ";
1612 body_str = "ËâË¡½ñ";
1615 /*** Fourth rank spellbooks ***/
1616 if (IS_FLG(FLG_FOURTH))
1618 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î4ºýÌܤÎ";
1619 body_str = "ËâË¡½ñ";
1623 if (IS_FLG(FLG_ITEMS))
1624 ; /* Nothing to do */
1625 else if (IS_FLG(FLG_WEAPONS))
1627 else if (IS_FLG(FLG_ARMORS))
1629 else if (IS_FLG(FLG_MISSILES))
1630 body_str = "ÃƤäÌð¤ä¥¯¥í¥¹¥Ü¥¦¤ÎÌð";
1631 else if (IS_FLG(FLG_DEVICES))
1632 body_str = "´¬Êª¤äËâË¡ËÀ¤ä¾ó¤ä¥í¥Ã¥É";
1633 else if (IS_FLG(FLG_LIGHTS))
1634 body_str = "¸÷¸»ÍѤΥ¢¥¤¥Æ¥à";
1635 else if (IS_FLG(FLG_JUNKS))
1636 body_str = "Àޤ줿ËÀÅù¤Î¥¬¥é¥¯¥¿";
1637 else if (IS_FLG(FLG_SPELLBOOKS))
1638 body_str = "ËâË¡½ñ";
1639 else if (IS_FLG(FLG_HAFTED))
1641 else if (IS_FLG(FLG_SHIELDS))
1643 else if (IS_FLG(FLG_BOWS))
1644 body_str = "¥¹¥ê¥ó¥°¤äµÝ¤ä¥¯¥í¥¹¥Ü¥¦";
1645 else if (IS_FLG(FLG_RINGS))
1647 else if (IS_FLG(FLG_AMULETS))
1648 body_str = "¥¢¥ß¥å¥ì¥Ã¥È";
1649 else if (IS_FLG(FLG_SUITS))
1651 else if (IS_FLG(FLG_CLOAKS))
1652 body_str = "¥¯¥í¡¼¥¯";
1653 else if (IS_FLG(FLG_HELMS))
1654 body_str = "¥Ø¥ë¥á¥Ã¥È¤ä´§";
1655 else if (IS_FLG(FLG_GLOVES))
1657 else if (IS_FLG(FLG_BOOTS))
1658 body_str = "¥Ö¡¼¥Ä";
1659 else if (IS_FLG(FLG_FAVORITE))
1660 body_str = "ÆÀ°ÕÉð´ï";
1664 strcat(buff, "Á´¤Æ¤Î");
1665 else for (i = 0; i < before_n && before_str[i]; i++)
1666 strcat(buff, before_str[i]);
1668 strcat(buff, body_str);
1678 strcat(buff, "¤Ç¡¢Ì¾Á°¤¬¡Ö");
1679 strncat(buff, str, 80);
1681 strcat(buff, "¡×¤Ç»Ï¤Þ¤ë¤â¤Î");
1683 strcat(buff, "¡×¤ò´Þ¤à¤â¤Î");
1688 strncat(buff, format("¤Ë¡Ö%s¡×", insc), 80);
1690 if (strstr(insc, "%%all"))
1691 strcat(buff, "(%%all¤ÏÁ´Ç½ÎϤòɽ¤¹±Ñ»ú¤Îµ¹æ¤ÇÃÖ´¹)");
1692 else if (strstr(insc, "%all"))
1693 strcat(buff, "(%all¤ÏÁ´Ç½ÎϤòɽ¤¹µ¹æ¤ÇÃÖ´¹)");
1694 else if (strstr(insc, "%%"))
1695 strcat(buff, "(%%¤ÏÄɲÃǽÎϤòɽ¤¹±Ñ»ú¤Îµ¹æ¤ÇÃÖ´¹)");
1696 else if (strstr(insc, "%"))
1697 strcat(buff, "(%¤ÏÄɲÃǽÎϤòɽ¤¹µ¹æ¤ÇÃÖ´¹)");
1699 strcat(buff, "¤È¹ï¤ó¤Ç");
1704 if (act & DONT_AUTOPICK)
1705 strcat(buff, "ÊüÃÖ¤¹¤ë¡£");
1706 else if (act & DO_AUTODESTROY)
1707 strcat(buff, "Ç˲õ¤¹¤ë¡£");
1708 else if (act & DO_QUERY_AUTOPICK)
1709 strcat(buff, "³Îǧ¤Î¸å¤Ë½¦¤¦¡£");
1711 strcat(buff, "½¦¤¦¡£");
1713 if (act & DO_DISPLAY)
1715 if (act & DONT_AUTOPICK)
1716 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'N'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
1717 else if (act & DO_AUTODESTROY)
1718 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'K'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
1720 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'M'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
1723 strcat(buff, "Á´ÂΥޥåפˤÏɽ¼¨¤·¤Ê¤¤");
1727 cptr before_str[20], after_str[20], which_str[20], whose_str[20], body_str;
1728 int before_n = 0, after_n = 0, which_n = 0, whose_n = 0;
1732 /*** Collecting items ***/
1733 /*** Which can be absorbed into a slot as a bundle ***/
1734 if (IS_FLG(FLG_COLLECTING))
1735 which_str[which_n++] = "can be absorbed into an existing inventory slot";
1737 /*** Unidentified ***/
1738 if (IS_FLG(FLG_UNIDENTIFIED))
1739 before_str[before_n++] = "unidentified";
1741 /*** Identified ***/
1742 if (IS_FLG(FLG_IDENTIFIED))
1743 before_str[before_n++] = "identified";
1745 /*** *Identified* ***/
1746 if (IS_FLG(FLG_STAR_IDENTIFIED))
1747 before_str[before_n++] = "fully identified";
1749 /*** Worthless items ***/
1750 if (IS_FLG(FLG_WORTHLESS))
1752 before_str[before_n++] = "worthless";
1753 which_str[which_n++] = "can not be sold at stores";
1757 if (IS_FLG(FLG_ARTIFACT))
1759 before_str[before_n++] = "artifact";
1763 if (IS_FLG(FLG_EGO))
1765 before_str[before_n++] = "ego";
1769 if (IS_FLG(FLG_NAMELESS))
1771 body_str = "equipment";
1772 which_str[which_n++] = "is neither ego-item nor artifact";
1775 /*** Unaware items ***/
1776 if (IS_FLG(FLG_UNAWARE))
1778 before_str[before_n++] = "unidentified";
1779 whose_str[whose_n++] = "basic abilities are not known";
1782 /*** Dice boosted (weapon of slaying) ***/
1783 if (IS_FLG(FLG_BOOSTED))
1785 body_str = "weapons";
1786 whose_str[whose_n++] = "damage dice is bigger than normal";
1789 /*** Weapons whose dd*ds is more than nn ***/
1790 if (IS_FLG(FLG_MORE_THAN))
1792 static char more_than_desc_str[] =
1793 "maximum damage from dice is bigger than __";
1794 body_str = "weapons";
1796 sprintf(more_than_desc_str + sizeof(more_than_desc_str) - 3,
1798 whose_str[whose_n++] = more_than_desc_str;
1801 /*** Items whose magical bonus is more than nn ***/
1802 if (IS_FLG(FLG_MORE_BONUS))
1804 static char more_bonus_desc_str[] =
1805 "magical bonus is bigger than (+__)";
1807 sprintf(more_bonus_desc_str + sizeof(more_bonus_desc_str) - 4,
1808 "%d)", entry->bonus);
1809 whose_str[whose_n++] = more_bonus_desc_str;
1812 /*** Wanted monster's corpse/skeletons ***/
1813 if (IS_FLG(FLG_WANTED))
1815 body_str = "corpse or skeletons";
1816 which_str[which_n++] = "is wanted at the Hunter's Office";
1819 /*** Human corpse/skeletons (for Daemon magic) ***/
1820 if (IS_FLG(FLG_HUMAN))
1822 before_str[before_n++] = "humanoid";
1823 body_str = "corpse or skeletons";
1824 which_str[which_n++] = "can be used for Daemon magic";
1827 /*** Unique monster's corpse/skeletons/statues ***/
1828 if (IS_FLG(FLG_UNIQUE))
1830 before_str[before_n++] = "unique monster's";
1831 body_str = "corpse or skeletons";
1834 /*** Unreadable spellbooks ***/
1835 if (IS_FLG(FLG_UNREADABLE))
1837 body_str = "spellbooks";
1838 after_str[after_n++] = "of different realms from yours";
1841 /*** First realm spellbooks ***/
1842 if (IS_FLG(FLG_REALM1))
1844 body_str = "spellbooks";
1845 after_str[after_n++] = "of your first realm";
1848 /*** Second realm spellbooks ***/
1849 if (IS_FLG(FLG_REALM2))
1851 body_str = "spellbooks";
1852 after_str[after_n++] = "of your second realm";
1855 /*** First rank spellbooks ***/
1856 if (IS_FLG(FLG_FIRST))
1858 before_str[before_n++] = "first one of four";
1859 body_str = "spellbooks";
1862 /*** Second rank spellbooks ***/
1863 if (IS_FLG(FLG_SECOND))
1865 before_str[before_n++] = "second one of four";
1866 body_str = "spellbooks";
1869 /*** Third rank spellbooks ***/
1870 if (IS_FLG(FLG_THIRD))
1872 before_str[before_n++] = "third one of four";
1873 body_str = "spellbooks";
1876 /*** Fourth rank spellbooks ***/
1877 if (IS_FLG(FLG_FOURTH))
1879 before_str[before_n++] = "fourth one of four";
1880 body_str = "spellbooks";
1884 if (IS_FLG(FLG_ITEMS))
1885 ; /* Nothing to do */
1886 else if (IS_FLG(FLG_WEAPONS))
1887 body_str = "weapons";
1888 else if (IS_FLG(FLG_ARMORS))
1889 body_str = "armors";
1890 else if (IS_FLG(FLG_MISSILES))
1891 body_str = "shots, arrows or crossbow bolts";
1892 else if (IS_FLG(FLG_DEVICES))
1893 body_str = "scrolls, wands, staves or rods";
1894 else if (IS_FLG(FLG_LIGHTS))
1895 body_str = "light sources";
1896 else if (IS_FLG(FLG_JUNKS))
1897 body_str = "junk such as broken sticks";
1898 else if (IS_FLG(FLG_SPELLBOOKS))
1899 body_str = "spellbooks";
1900 else if (IS_FLG(FLG_HAFTED))
1901 body_str = "hafted weapons";
1902 else if (IS_FLG(FLG_SHIELDS))
1903 body_str = "shields";
1904 else if (IS_FLG(FLG_BOWS))
1905 body_str = "slings, bows or crossbows";
1906 else if (IS_FLG(FLG_RINGS))
1908 else if (IS_FLG(FLG_AMULETS))
1909 body_str = "amulets";
1910 else if (IS_FLG(FLG_SUITS))
1911 body_str = "body armors";
1912 else if (IS_FLG(FLG_CLOAKS))
1913 body_str = "cloaks";
1914 else if (IS_FLG(FLG_HELMS))
1915 body_str = "helms or crowns";
1916 else if (IS_FLG(FLG_GLOVES))
1917 body_str = "gloves";
1918 else if (IS_FLG(FLG_BOOTS))
1920 else if (IS_FLG(FLG_FAVORITE))
1921 body_str = "favorite weapons";
1923 /* Prepare a string for item name */
1930 whose_str[whose_n++] = "name is beginning with \"";
1933 which_str[which_n++] = "have \"";
1937 /* Describe action flag */
1938 if (act & DONT_AUTOPICK)
1939 strcpy(buff, "Leave on floor ");
1940 else if (act & DO_AUTODESTROY)
1941 strcpy(buff, "Destroy ");
1942 else if (act & DO_QUERY_AUTOPICK)
1943 strcpy(buff, "Ask to pick up ");
1945 strcpy(buff, "Pickup ");
1947 /* Auto-insctiption */
1950 strncat(buff, format("and inscribe \"%s\"", insc), 80);
1952 if (strstr(insc, "%all"))
1953 strcat(buff, ", replacing %all with code string representing all abilities,");
1954 else if (strstr(insc, "%"))
1955 strcat(buff, ", replacing % with code string representing extra random abilities,");
1957 strcat(buff, " on ");
1962 strcat(buff, "all ");
1963 else for (i = 0; i < before_n && before_str[i]; i++)
1965 strcat(buff, before_str[i]);
1970 strcat(buff, body_str);
1973 for (i = 0; i < after_n && after_str[i]; i++)
1976 strcat(buff, after_str[i]);
1980 for (i = 0; i < whose_n && whose_str[i]; i++)
1983 strcat(buff, " whose ");
1985 strcat(buff, ", and ");
1987 strcat(buff, whose_str[i]);
1990 /* Item name ; whose name is beginning with "str" */
1997 /* whose ..., and which .... */
1998 if (whose_n && which_n)
1999 strcat(buff, ", and ");
2002 for (i = 0; i < which_n && which_str[i]; i++)
2005 strcat(buff, " which ");
2007 strcat(buff, ", and ");
2009 strcat(buff, which_str[i]);
2012 /* Item name ; which have "str" as part of its name */
2015 strncat(buff, str, 80);
2016 strcat(buff, "\" as part of its name");
2020 /* Describe whether it will be displayed on the full map or not */
2021 if (act & DO_DISPLAY)
2023 if (act & DONT_AUTOPICK)
2024 strcat(buff, " Display these items when you press the N key in the full 'M'ap.");
2025 else if (act & DO_AUTODESTROY)
2026 strcat(buff, " Display these items when you press the K key in the full 'M'ap.");
2028 strcat(buff, " Display these items when you press the M key in the full 'M'ap.");
2031 strcat(buff, " Not displayed in the full map.");
2038 * Read whole lines of a file to memory
2040 static cptr *read_text_lines(cptr filename, bool user)
2042 cptr *lines_list = NULL;
2050 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2054 path_build(buf, sizeof(buf), ANGBAND_DIR_PREF, filename);
2058 fff = my_fopen(buf, "r");
2062 /* Allocate list of pointers */
2063 C_MAKE(lines_list, MAX_LINES, cptr);
2066 while (0 == my_fgets(fff, buf, sizeof(buf)))
2068 lines_list[lines++] = string_make(buf);
2069 if (lines >= MAX_LINES - 1) break;
2072 lines_list[0] = string_make("");
2077 if (!fff) return NULL;
2082 #define PT_DEFAULT 0
2083 #define PT_WITH_PNAME 1
2085 static cptr *read_pickpref_text_lines(int *filename_mode_p)
2091 sprintf(buf, "picktype-%s.prf", player_name);
2093 sprintf(buf, "pickpref-%s.prf", player_name);
2095 lines_list = read_text_lines(buf, TRUE);
2100 lines_list = read_text_lines("picktype.prf", TRUE);
2102 lines_list = read_text_lines("pickpref.prf", TRUE);
2104 *filename_mode_p = PT_DEFAULT;
2110 lines_list = read_text_lines("picktype.prf", FALSE);
2112 lines_list = read_text_lines("pickpref.prf", FALSE);
2114 *filename_mode_p = PT_WITH_PNAME;
2119 /* Allocate list of pointers */
2120 C_MAKE(lines_list, MAX_LINES, cptr);
2121 lines_list[0] = string_make("");
2122 *filename_mode_p = PT_WITH_PNAME;
2129 * Write whole lines of memory to a file.
2131 static bool write_text_lines(cptr filename, cptr *lines_list)
2138 /* Build the filename */
2139 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2142 fff = my_fopen(buf, "w");
2145 for (lines = 0; lines_list[lines]; lines++)
2146 my_fputs(fff, lines_list[lines], 1024);
2151 if (!fff) return FALSE;
2157 * Free memory of lines_list.
2159 static void free_text_lines(cptr *lines_list)
2163 for (lines = 0; lines_list[lines]; lines++)
2164 string_free(lines_list[lines]);
2166 /* free list of pointers */
2167 C_FREE((char **)lines_list, MAX_LINES, char *);
2172 * Delete or insert string
2174 static void toggle_keyword(text_body_type *tb, int flg)
2176 int by1, by2, bx1, bx2, y;
2180 /* Select this line */
2187 if (tb->my < tb->cy)
2202 /* String on these lines are not really selected */
2203 if (tb->lines_list[by1][bx1] == '\0' && by1 < tb->cy) by1++;
2204 if (bx2 == 0 && by1 < by2) by2--;
2207 /* Set/Reset flag of each line */
2208 for (y = by1; y <= by2; y++)
2210 autopick_type an_entry, *entry = &an_entry;
2212 if (!autopick_new_entry(entry, tb->lines_list[y], !fixed)) continue;
2214 string_free(tb->lines_list[y]);
2218 /* Add? or Remove? */
2219 if (!IS_FLG(flg)) add = TRUE;
2222 /* No more change */
2226 /* You can use only one noun flag */
2227 if (FLG_NOUN_BEGIN <= flg && flg <= FLG_NOUN_END)
2230 for (i = FLG_NOUN_BEGIN; i <= FLG_NOUN_END; i++)
2234 /* You can use only one identify state flag */
2235 else if (FLG_UNAWARE <= flg && flg <= FLG_STAR_IDENTIFIED)
2238 for (i = FLG_UNAWARE; i <= FLG_STAR_IDENTIFIED; i++)
2242 /* You can use only one flag in artifact/ego/nameless */
2243 else if (FLG_ARTIFACT <= flg && flg <= FLG_NAMELESS)
2246 for (i = FLG_ARTIFACT; i <= FLG_NAMELESS; i++)
2250 if (add) ADD_FLG(flg);
2253 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
2256 tb->dirty_flags |= DIRTY_ALL;
2258 /* Text is changed */
2265 * Change command letter
2267 static void toggle_command_letter(text_body_type *tb, byte flg)
2269 autopick_type an_entry, *entry = &an_entry;
2270 int by1, by2, bx1, bx2, y;
2274 /* Select this line */
2281 if (tb->my < tb->cy)
2296 /* String on these lines are not really selected */
2297 if (tb->lines_list[by1][bx1] == '\0' && by1 < tb->cy) by1++;
2298 if (bx2 == 0 && by1 < by2) by2--;
2300 /* Set/Reset flag of each line */
2301 for (y = by1; y <= by2; y++)
2305 if (!autopick_new_entry(entry, tb->lines_list[y], FALSE)) continue;
2307 string_free(tb->lines_list[y]);
2311 /* Add? or Remove? */
2312 if (!(entry->action & flg)) add = TRUE;
2315 /* No more change */
2319 /* Count number of letter (by negative number) */
2320 if (entry->action & DONT_AUTOPICK) wid--;
2321 else if (entry->action & DO_AUTODESTROY) wid--;
2322 else if (entry->action & DO_QUERY_AUTOPICK) wid--;
2323 if (!(entry->action & DO_DISPLAY)) wid--;
2325 /* Set/Reset the flag */
2326 if (flg != DO_DISPLAY)
2328 entry->action &= ~(DO_AUTOPICK | DONT_AUTOPICK | DO_AUTODESTROY | DO_QUERY_AUTOPICK);
2329 if (add) entry->action |= flg;
2330 else entry->action |= DO_AUTOPICK;
2334 entry->action &= ~(DO_DISPLAY);
2335 if (add) entry->action |= flg;
2338 /* Correct cursor location */
2341 if (entry->action & DONT_AUTOPICK) wid++;
2342 else if (entry->action & DO_AUTODESTROY) wid++;
2343 else if (entry->action & DO_QUERY_AUTOPICK) wid++;
2344 if (!(entry->action & DO_DISPLAY)) wid++;
2346 if (wid > 0) tb->cx++;
2347 if (wid < 0 && tb->cx > 0) tb->cx--;
2350 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
2353 tb->dirty_flags |= DIRTY_ALL;
2355 /* Text is changed */
2361 * Delete or insert string
2363 static void add_keyword(text_body_type *tb, int flg)
2365 int by1, by2, bx1, bx2, y;
2367 /* Select this line */
2374 if (tb->my < tb->cy)
2389 /* String on these lines are not really selected */
2390 if (tb->lines_list[by1][bx1] == '\0' && by1 < tb->cy) by1++;
2391 if (bx2 == 0 && by1 < by2) by2--;
2393 /* Set/Reset flag of each line */
2394 for (y = by1; y <= by2; y++)
2396 autopick_type an_entry, *entry = &an_entry;
2398 if (!autopick_new_entry(entry, tb->lines_list[y], FALSE)) continue;
2400 /* There is the flag already */
2403 /* Free memory for the entry */
2404 autopick_free_entry(entry);
2409 string_free(tb->lines_list[y]);
2411 /* Remove all noun flag */
2412 if (FLG_NOUN_BEGIN <= flg && flg <= FLG_NOUN_END)
2415 for (i = FLG_NOUN_BEGIN; i <= FLG_NOUN_END; i++)
2421 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
2424 tb->dirty_flags |= DIRTY_ALL;
2426 /* Text is changed */
2433 * Check if this line is expression or not.
2434 * And update it if it is.
2436 static void check_expression_line(text_body_type *tb, int y)
2438 cptr s = tb->lines_list[y];
2440 if ((s[0] == '?' && s[1] == ':') ||
2441 (tb->states[y] & LSTAT_BYPASS))
2443 /* Expressions need re-evaluation */
2444 tb->dirty_flags |= DIRTY_EXPRESSION;
2450 * Insert return code and split the line
2452 static bool insert_return_code(text_body_type *tb)
2454 char buf[MAX_LINELEN];
2457 for (k = 0; tb->lines_list[k]; k++)
2458 /* count number of lines */ ;
2460 if (k >= MAX_LINES - 2) return FALSE;
2463 /* Move down lines */
2464 for (; tb->cy < k; k--)
2466 tb->lines_list[k+1] = tb->lines_list[k];
2467 tb->states[k+1] = tb->states[k];
2470 /* Split current line */
2471 for (i = j = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
2474 if (iskanji(tb->lines_list[tb->cy][i]))
2475 buf[j++] = tb->lines_list[tb->cy][i++];
2477 buf[j++] = tb->lines_list[tb->cy][i];
2480 tb->lines_list[tb->cy+1] = string_make(&tb->lines_list[tb->cy][i]);
2481 string_free(tb->lines_list[tb->cy]);
2482 tb->lines_list[tb->cy] = string_make(buf);
2484 /* Expressions need re-evaluation */
2485 tb->dirty_flags |= DIRTY_EXPRESSION;
2487 /* Text is changed */
2495 * Get auto-picker entry from o_ptr.
2497 void autopick_entry_from_object(autopick_type *entry, object_type *o_ptr)
2499 char o_name[MAX_NLEN];
2500 object_desc(o_name, o_ptr, FALSE, 0);
2502 entry->name = string_make(o_name);
2503 entry->insc = string_make(quark_str(o_ptr->inscription));
2504 entry->action = DO_AUTOPICK | DO_DISPLAY;
2505 entry->flag[0] = entry->flag[1] = 0L;
2508 if (!object_aware_p(o_ptr))
2509 ADD_FLG(FLG_UNAWARE);
2510 if (object_value(o_ptr) <= 0)
2511 ADD_FLG(FLG_WORTHLESS);
2513 if (object_known_p(o_ptr))
2517 else if (o_ptr->name1 || o_ptr->art_name)
2518 ADD_FLG(FLG_ARTIFACT);
2524 case TV_HAFTED: case TV_POLEARM: case TV_SWORD: case TV_DIGGING:
2525 k_ptr = &k_info[o_ptr->k_idx];
2526 if ((o_ptr->dd != k_ptr->dd) || (o_ptr->ds != k_ptr->ds))
2527 ADD_FLG(FLG_BOOSTED);
2530 if (o_ptr->tval == TV_CORPSE && object_is_shoukinkubi(o_ptr))
2532 REM_FLG(FLG_WORTHLESS);
2533 ADD_FLG(FLG_WANTED);
2536 if ((o_ptr->tval == TV_CORPSE || o_ptr->tval == TV_STATUE)
2537 && (r_info[o_ptr->pval].flags1 & RF1_UNIQUE))
2539 REM_FLG(FLG_WORTHLESS);
2540 ADD_FLG(FLG_UNIQUE);
2543 if (o_ptr->tval == TV_CORPSE && strchr("pht", r_info[o_ptr->pval].d_char))
2545 REM_FLG(FLG_WORTHLESS);
2549 if (o_ptr->tval >= TV_LIFE_BOOK &&
2550 !check_book_realm(o_ptr->tval, o_ptr->sval))
2551 ADD_FLG(FLG_UNREADABLE);
2553 if (REALM1_BOOK == o_ptr->tval &&
2554 p_ptr->pclass != CLASS_SORCERER &&
2555 p_ptr->pclass != CLASS_RED_MAGE)
2556 ADD_FLG(FLG_REALM1);
2558 if (REALM2_BOOK == o_ptr->tval &&
2559 p_ptr->pclass != CLASS_SORCERER &&
2560 p_ptr->pclass != CLASS_RED_MAGE)
2561 ADD_FLG(FLG_REALM2);
2563 if (o_ptr->tval >= TV_LIFE_BOOK && 0 == o_ptr->sval)
2565 if (o_ptr->tval >= TV_LIFE_BOOK && 1 == o_ptr->sval)
2566 ADD_FLG(FLG_SECOND);
2567 if (o_ptr->tval >= TV_LIFE_BOOK && 2 == o_ptr->sval)
2569 if (o_ptr->tval >= TV_LIFE_BOOK && 3 == o_ptr->sval)
2570 ADD_FLG(FLG_FOURTH);
2572 if (o_ptr->tval == TV_SHOT || o_ptr->tval == TV_BOLT
2573 || o_ptr->tval == TV_ARROW)
2574 ADD_FLG(FLG_MISSILES);
2575 else if (o_ptr->tval == TV_SCROLL || o_ptr->tval == TV_STAFF
2576 || o_ptr->tval == TV_WAND || o_ptr->tval == TV_ROD)
2577 ADD_FLG(FLG_DEVICES);
2578 else if (o_ptr->tval == TV_LITE)
2579 ADD_FLG(FLG_LIGHTS);
2580 else if (o_ptr->tval == TV_SKELETON || o_ptr->tval == TV_BOTTLE
2581 || o_ptr->tval == TV_JUNK || o_ptr->tval == TV_STATUE)
2583 else if (o_ptr->tval >= TV_LIFE_BOOK)
2584 ADD_FLG(FLG_SPELLBOOKS);
2585 else if (is_favorite(o_ptr, FALSE))
2586 ADD_FLG(FLG_FAVORITE);
2587 else if (o_ptr->tval == TV_POLEARM || o_ptr->tval == TV_SWORD
2588 || o_ptr->tval == TV_DIGGING || o_ptr->tval == TV_HAFTED)
2589 ADD_FLG(FLG_WEAPONS);
2590 else if (o_ptr->tval == TV_SHIELD)
2591 ADD_FLG(FLG_SHIELDS);
2592 else if (o_ptr->tval == TV_BOW)
2594 else if (o_ptr->tval == TV_RING)
2596 else if (o_ptr->tval == TV_AMULET)
2597 ADD_FLG(FLG_AMULETS);
2598 else if (o_ptr->tval == TV_DRAG_ARMOR || o_ptr->tval == TV_HARD_ARMOR ||
2599 o_ptr->tval == TV_SOFT_ARMOR)
2601 else if (o_ptr->tval == TV_CLOAK)
2602 ADD_FLG(FLG_CLOAKS);
2603 else if (o_ptr->tval == TV_HELM)
2605 else if (o_ptr->tval == TV_GLOVES)
2606 ADD_FLG(FLG_GLOVES);
2607 else if (o_ptr->tval == TV_BOOTS)
2615 * Choose an item and get auto-picker entry from it.
2617 static object_type *choose_object(cptr q, cptr s)
2621 if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR | USE_EQUIP))) return NULL;
2623 /* Get the item (in the pack) */
2624 if (item >= 0) return &inventory[item];
2626 /* Get the item (on the floor) */
2627 else return &o_list[0 - item];
2632 * Choose an item and get auto-picker entry from it.
2634 static bool entry_from_choosed_object(autopick_type *entry)
2641 q = "¤É¤Î¥¢¥¤¥Æ¥à¤òÅÐÏ¿¤·¤Þ¤¹¤«? ";
2642 s = "¥¢¥¤¥Æ¥à¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£";
2644 q = "Enter which item? ";
2645 s = "You have nothing to enter.";
2647 o_ptr = choose_object(q, s);
2648 if (!o_ptr) return FALSE;
2650 autopick_entry_from_object(entry, o_ptr);
2656 * Choose an item for search
2658 static byte get_object_for_search(object_type **o_handle, cptr *search_strp)
2660 char buf[MAX_NLEN+20];
2666 q = "¤É¤Î¥¢¥¤¥Æ¥à¤ò¸¡º÷¤·¤Þ¤¹¤«? ";
2667 s = "¥¢¥¤¥Æ¥à¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£";
2669 q = "Enter which item? ";
2670 s = "You have nothing to enter.";
2672 o_ptr = choose_object(q, s);
2673 if (!o_ptr) return 0;
2677 string_free(*search_strp);
2678 object_desc(buf, *o_handle, FALSE, 3);
2679 *search_strp = string_make(format("<%s>", buf));
2685 * Prepare for search by destroyed object
2687 static byte get_destroyed_object_for_search(object_type **o_handle, cptr *search_strp)
2689 char buf[MAX_NLEN+20];
2691 if (!autopick_last_destroyed_object.k_idx) return 0;
2693 *o_handle = &autopick_last_destroyed_object;
2695 string_free(*search_strp);
2696 object_desc(buf, *o_handle, FALSE, 3);
2697 *search_strp = string_make(format("<%s>", buf));
2703 * Choose an item or string for search
2705 static byte get_string_for_search(object_type **o_handle, cptr *search_strp)
2708 char buf[MAX_NLEN+20];
2711 int k_flag[MAX_NLEN+20];
2712 char prompt[] = "¸¡º÷(^I:»ý¤Áʪ ^L:Ç˲õ¤µ¤ì¤¿Êª): ";
2714 char prompt[] = "Search key(^I:inven ^L:destroyed): ";
2716 int col = sizeof(prompt) - 1;
2718 if (*search_strp) strcpy(buf, *search_strp);
2721 /* Display prompt */
2724 /* Display the default answer */
2725 Term_erase(col, 0, 255);
2726 Term_putstr(col, 0, -1, TERM_YELLOW, buf);
2736 Term_gotoxy(col + pos, 0);
2741 /* Count length of macro trigger which induced this key */
2742 trig_len = strlen(inkey_macro_trigger_string);
2744 /* HACK -- ignore macro defined on ASCII keys */
2747 /* Get original key */
2748 key = inkey_macro_trigger_string[0];
2750 /* Kill further macro expansion */
2755 if (key == 0x7F) key = KTRL('d');
2758 /* Analyze the key */
2771 if (!pos && *o_handle) return (back ? -1 : 1);
2772 string_free(*search_strp);
2773 *search_strp = string_make(buf);
2775 return (back ? -1 : 1);
2779 return get_object_for_search(o_handle, search_strp);
2782 /* Prepare string for destroyed object if there is one. */
2783 if (get_destroyed_object_for_search(o_handle, search_strp))
2793 if (k_flag[pos]) pos--;
2808 if (pos + 1 < MAX_NLEN)
2816 else if (pos < MAX_NLEN && isprint(key))
2823 if (pos < MAX_NLEN && isprint(key)) buf[pos++] = key;
2832 /* Update the entry */
2833 Term_erase(col, 0, 255);
2834 Term_putstr(col, 0, -1, TERM_WHITE, buf);
2842 * Search next line matches for o_ptr
2844 static bool search_for_object(text_body_type *tb, object_type *o_ptr, bool forward)
2847 autopick_type an_entry, *entry = &an_entry;
2848 char o_name[MAX_NLEN];
2850 object_desc(o_name, o_ptr, FALSE, 3);
2852 /* Force to be lower case string */
2853 for (i = 0; o_name[i]; i++)
2856 if (iskanji(o_name[i]))
2860 if (isupper(o_name[i]))
2861 o_name[i] = tolower(o_name[i]);
2870 if (!tb->lines_list[++i]) break;
2877 /* Ignore bypassed lines */
2878 if (tb->states[i] & LSTAT_BYPASS) continue;
2880 if (!autopick_new_entry(entry, tb->lines_list[i], FALSE)) continue;
2882 if (is_autopick_aux(o_ptr, entry, o_name))
2895 * Search next line matches to the string
2897 static bool search_for_string(text_body_type *tb, cptr search_str, bool forward)
2907 if (!tb->lines_list[++i]) break;
2914 /* Ignore bypassed lines */
2915 if (tb->states[i] & LSTAT_BYPASS) continue;
2918 pos = strstr_j(tb->lines_list[i], search_str);
2920 pos = strstr(tb->lines_list[i], search_str);
2924 tb->cx = (int)(pos - tb->lines_list[i]);
2937 * Editor command id's
2940 #define EC_SAVEQUIT 2
2951 #define EC_PGDOWN 13
2953 #define EC_BOTTOM 15
2958 #define EC_KILL_LINE 20
2959 #define EC_DELETE_CHAR 21
2960 #define EC_BACKSPACE 22
2961 #define EC_SEARCH_STR 23
2962 #define EC_SEARCH_FORW 24
2963 #define EC_SEARCH_BACK 25
2964 #define EC_SEARCH_OBJ 26
2965 #define EC_SEARCH_DESTROYED 27
2966 #define EC_INSERT_OBJECT 28
2967 #define EC_INSERT_DESTROYED 29
2968 #define EC_INSERT_BLOCK 30
2969 #define EC_INSERT_MACRO 31
2970 #define EC_INSERT_KEYMAP 32
2971 #define EC_CL_AUTOPICK 33
2972 #define EC_CL_DESTROY 34
2973 #define EC_CL_LEAVE 35
2974 #define EC_CL_QUERY 36
2975 #define EC_CL_NO_DISP 37
2976 #define EC_OK_COLLECTING 38
2977 #define EC_IK_UNAWARE 39
2978 #define EC_IK_UNIDENTIFIED 40
2979 #define EC_IK_IDENTIFIED 41
2980 #define EC_IK_STAR_IDENTIFIED 42
2981 #define EC_OK_BOOSTED 43
2982 #define EC_OK_MORE_THAN 44
2983 #define EC_OK_MORE_BONUS 45
2984 #define EC_OK_WORTHLESS 46
2985 #define EC_OK_ARTIFACT 47
2986 #define EC_OK_EGO 48
2987 #define EC_OK_NAMELESS 49
2988 #define EC_OK_WANTED 50
2989 #define EC_OK_UNIQUE 51
2990 #define EC_OK_HUMAN 52
2991 #define EC_OK_UNREADABLE 53
2992 #define EC_OK_REALM1 54
2993 #define EC_OK_REALM2 55
2994 #define EC_OK_FIRST 56
2995 #define EC_OK_SECOND 57
2996 #define EC_OK_THIRD 58
2997 #define EC_OK_FOURTH 59
2998 #define EC_KK_WEAPONS 60
2999 #define EC_KK_FAVORITE 61
3000 #define EC_KK_ARMORS 62
3001 #define EC_KK_MISSILES 63
3002 #define EC_KK_DEVICES 64
3003 #define EC_KK_LIGHTS 65
3004 #define EC_KK_JUNKS 66
3005 #define EC_KK_SPELLBOOKS 67
3006 #define EC_KK_SHIELDS 68
3007 #define EC_KK_BOWS 69
3008 #define EC_KK_RINGS 70
3009 #define EC_KK_AMULETS 71
3010 #define EC_KK_SUITS 72
3011 #define EC_KK_CLOAKS 73
3012 #define EC_KK_HELMS 74
3013 #define EC_KK_GLOVES 75
3014 #define EC_KK_BOOTS 76
3020 #define MN_QUIT "¥»¡¼¥Ö̵¤·¤Ç½ªÎ»"
3021 #define MN_SAVEQUIT "¥»¡¼¥Ö¤·¤Æ½ªÎ»"
3022 #define MN_REVERT "Á´¤Æ¤ÎÊѹ¹¤òÇË´þ"
3023 #define MN_HELP "¥Ø¥ë¥×"
3025 #define MN_MOVE "¥«¡¼¥½¥ë°ÜÆ°"
3026 #define MN_LEFT "º¸"
3027 #define MN_DOWN "²¼"
3029 #define MN_RIGHT "±¦"
3030 #define MN_BOL "¹Ô¤ÎÀèƬ"
3031 #define MN_EOL "¹Ô¤Î½ªÃ¼"
3032 #define MN_PGUP "¾å¤Î¥Ú¡¼¥¸"
3033 #define MN_PGDOWN "²¼¤Î¥Ú¡¼¥¸"
3034 #define MN_TOP "1¹ÔÌܤذÜÆ°"
3035 #define MN_BOTTOM "ºÇ²¼¹Ô¤Ø°ÜÆ°"
3037 #define MN_EDIT "ÊÔ½¸"
3038 #define MN_CUT "¥«¥Ã¥È"
3039 #define MN_COPY "¥³¥Ô¡¼"
3040 #define MN_PASTE "¥Ú¡¼¥¹¥È"
3041 #define MN_BLOCK "ÁªÂòÈϰϤλØÄê"
3042 #define MN_KILL_LINE "¹Ô¤Î»Ä¤ê¤òºï½ü"
3043 #define MN_DELETE_CHAR "1ʸ»úºï½ü"
3044 #define MN_BACKSPACE "¥Ð¥Ã¥¯¥¹¥Ú¡¼¥¹"
3045 #define MN_RETURN "²þ¹Ô"
3046 #define MN_RETURN "²þ¹Ô"
3048 #define MN_SEARCH "¸¡º÷"
3049 #define MN_SEARCH_STR "ʸ»úÎó¤Ç¸¡º÷"
3050 #define MN_SEARCH_FORW "Á°Êý¤ØºÆ¸¡º÷"
3051 #define MN_SEARCH_BACK "¸åÊý¤ØºÆ¸¡º÷"
3052 #define MN_SEARCH_OBJ "¥¢¥¤¥Æ¥à¤òÁªÂò¤·¤Æ¸¡º÷"
3053 #define MN_SEARCH_DESTROYED "¼«Æ°Ç˲õ¤µ¤ì¤¿¥¢¥¤¥Æ¥à¤Ç¸¡º÷"
3055 #define MN_INSERT "¿§¡¹ÁÞÆþ"
3056 #define MN_INSERT_OBJECT "ÁªÂò¤·¤¿¥¢¥¤¥Æ¥à¤Î̾Á°¤òÁÞÆþ"
3057 #define MN_INSERT_DESTROYED "¼«Æ°Ç˲õ¤µ¤ì¤¿¥¢¥¤¥Æ¥à¤Î̾Á°¤òÁÞÆþ"
3058 #define MN_INSERT_BLOCK "¾ò·ïʬ´ô¥Ö¥í¥Ã¥¯¤ÎÎã¤òÁÞÆþ"
3059 #define MN_INSERT_MACRO "¥Þ¥¯¥íÄêµÁ¤òÁÞÆþ"
3060 #define MN_INSERT_KEYMAP "¥¡¼¥Þ¥Ã¥×ÄêµÁ¤òÁÞÆþ"
3062 #define MN_COMMAND_LETTER "½¦¤¤/Ç˲õ/ÊüÃÖ¤ÎÁªÂò"
3063 #define MN_CL_AUTOPICK "¡Ö ¡× (¼«Æ°½¦¤¤)"
3064 #define MN_CL_DESTROY "¡Ö!¡× (¼«Æ°Ç˲õ)"
3065 #define MN_CL_LEAVE "¡Ö~¡× (ÊüÃÖ)"
3066 #define MN_CL_QUERY "¡Ö;¡× (³Îǧ¤·¤Æ½¦¤¦)"
3067 #define MN_CL_NO_DISP "¡Ö(¡× (¥Þ¥Ã¥×¥³¥Þ¥ó¥É¤Çɽ¼¨¤·¤Ê¤¤)"
3069 #define MN_ADJECTIVE_GEN "·ÁÍÆ»ì(°ìÈÌ)¤ÎÁªÂò"
3071 #define MN_ADJECTIVE_SPECIAL "·ÁÍÆ»ì(Æüì)¤ÎÁªÂò"
3072 #define MN_BOOSTED "¥À¥¤¥¹Ìܤΰ㤦 (Éð´ï)"
3073 #define MN_MORE_THAN "¥À¥¤¥¹ÌÜ # °Ê¾å¤Î (Éð´ï)"
3074 #define MN_MORE_BONUS "½¤ÀµÃÍ # °Ê¾å¤Î (»ØÎØÅù)"
3075 #define MN_ARTIFACT "¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È (ÁõÈ÷)"
3076 #define MN_EGO "¥¨¥´ (ÁõÈ÷)"
3077 #define MN_NAMELESS "̵ÌäΠ(ÁõÈ÷)"
3078 #define MN_WANTED "¾Þ¶â¼ó¤Î (»àÂÎ)"
3079 #define MN_UNIQUE "¥æ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼¤Î (»àÂÎ)"
3080 #define MN_HUMAN "¿Í´Ö¤Î (»àÂÎ)"
3081 #define MN_UNREADABLE "Æɤá¤Ê¤¤ (ËâË¡½ñ)"
3082 #define MN_REALM1 "Âè°ìÎΰè¤Î (ËâË¡½ñ)"
3083 #define MN_REALM2 "ÂèÆóÎΰè¤Î (ËâË¡½ñ)"
3084 #define MN_FIRST "1ºýÌܤΠ(ËâË¡½ñ)"
3085 #define MN_SECOND "2ºýÌܤΠ(ËâË¡½ñ)"
3086 #define MN_THIRD "3ºýÌܤΠ(ËâË¡½ñ)"
3087 #define MN_FOURTH "4ºýÌܤΠ(ËâË¡½ñ)"
3089 #define MN_NOUN "̾»ì¤ÎÁªÂò"
3093 #define MN_QUIT "Quit without save"
3094 #define MN_SAVEQUIT "Save & Quit"
3095 #define MN_REVERT "Revert all changes"
3096 #define MN_HELP "Help"
3098 #define MN_MOVE "Move cursor"
3099 #define MN_LEFT "Left"
3100 #define MN_DOWN "Down"
3102 #define MN_RIGHT "Right"
3103 #define MN_BOL "Beggining of line"
3104 #define MN_EOL "End of line"
3105 #define MN_PGUP "Page up"
3106 #define MN_PGDOWN "Page down"
3107 #define MN_TOP "Top"
3108 #define MN_BOTTOM "Bottom"
3110 #define MN_EDIT "Edit"
3111 #define MN_CUT "Cut"
3112 #define MN_COPY "Copy"
3113 #define MN_PASTE "Paste"
3114 #define MN_BLOCK "Select block"
3115 #define MN_KILL_LINE "Kill rest of line"
3116 #define MN_DELETE_CHAR "Delete character"
3117 #define MN_BACKSPACE "Backspace"
3118 #define MN_RETURN "Return"
3119 #define MN_RETURN "Return"
3121 #define MN_SEARCH "Search"
3122 #define MN_SEARCH_STR "Search by string"
3123 #define MN_SEARCH_FORW "Search forward"
3124 #define MN_SEARCH_BACK "Search backward"
3125 #define MN_SEARCH_OBJ "Search by inventory object"
3126 #define MN_SEARCH_DESTROYED "Search by destroyed object"
3128 #define MN_INSERT "Insert..."
3129 #define MN_INSERT_OBJECT "Insert name of choosen object"
3130 #define MN_INSERT_DESTROYED "Insert name of destroyed object"
3131 #define MN_INSERT_BLOCK "Insert conditional block"
3132 #define MN_INSERT_MACRO "Insert a macro definition"
3133 #define MN_INSERT_KEYMAP "Insert a keymap definition"
3135 #define MN_COMMAND_LETTER "Command letter"
3136 #define MN_CL_AUTOPICK "' ' (Auto pick)"
3137 #define MN_CL_DESTROY "'!' (Auto destroy)"
3138 #define MN_CL_LEAVE "'~' (Leave it on the floor)"
3139 #define MN_CL_QUERY "';' (Query to pick up)"
3140 #define MN_CL_NO_DISP "'(' (No display on the large map)"
3142 #define MN_ADJECTIVE_GEN "Adjective (general)"
3144 #define MN_ADJECTIVE_SPECIAL "Adjective (special)"
3145 #define MN_BOOSTED "dice boosted (weapons)"
3146 #define MN_MORE_THAN "more than # dice (weapons)"
3147 #define MN_MORE_BONUS "more bonus than # (rings etc.)"
3148 #define MN_ARTIFACT "artifact (equipments)"
3149 #define MN_EGO "ego (equipments)"
3150 #define MN_NAMELESS "nameless (equipments)"
3151 #define MN_WANTED "wanted (corpse)"
3152 #define MN_UNIQUE "unique (corpse)"
3153 #define MN_HUMAN "human (corpse)"
3154 #define MN_UNREADABLE "unreadable (spellbooks)"
3155 #define MN_REALM1 "realm1 (spellbooks)"
3156 #define MN_REALM2 "realm2 (spellbooks)"
3157 #define MN_FIRST "first (spellbooks)"
3158 #define MN_SECOND "second (spellbooks)"
3159 #define MN_THIRD "third (spellbooks)"
3160 #define MN_FOURTH "fourth (spellbooks)"
3162 #define MN_NOUN "Keywords (noun)"
3172 } command_menu_type;
3175 command_menu_type menu_data[] =
3177 {MN_HELP, 0, -1, EC_HELP},
3178 {MN_QUIT, 0, KTRL('q'), EC_QUIT},
3179 {MN_SAVEQUIT, 0, KTRL('w'), EC_SAVEQUIT},
3180 {MN_REVERT, 0, KTRL('z'), EC_REVERT},
3182 {MN_EDIT, 0, -1, -1},
3183 {MN_CUT, 1, KTRL('x'), EC_CUT},
3184 {MN_COPY, 1, KTRL('c'), EC_COPY},
3185 {MN_PASTE, 1, KTRL('v'), EC_PASTE},
3186 {MN_BLOCK, 1, KTRL('g'), EC_BLOCK},
3187 {MN_KILL_LINE, 1, KTRL('k'), EC_KILL_LINE},
3188 {MN_DELETE_CHAR, 1, KTRL('d'), EC_DELETE_CHAR},
3189 {MN_BACKSPACE, 1, KTRL('h'), EC_BACKSPACE},
3190 {MN_RETURN, 1, KTRL('j'), EC_RETURN},
3191 {MN_RETURN, 1, KTRL('m'), EC_RETURN},
3193 {MN_SEARCH, 0, -1, -1},
3194 {MN_SEARCH_STR, 1, KTRL('s'), EC_SEARCH_STR},
3195 {MN_SEARCH_FORW, 1, -1, EC_SEARCH_FORW},
3196 {MN_SEARCH_BACK, 1, KTRL('r'), EC_SEARCH_BACK},
3197 {MN_SEARCH_OBJ, 1, -1, EC_SEARCH_OBJ},
3198 {MN_SEARCH_DESTROYED, 1, -1, EC_SEARCH_DESTROYED},
3200 {MN_MOVE, 0, -1, -1},
3201 {MN_LEFT, 1, KTRL('b'), EC_LEFT},
3202 {MN_DOWN, 1, KTRL('n'), EC_DOWN},
3203 {MN_UP, 1, KTRL('p'), EC_UP},
3204 {MN_RIGHT, 1, KTRL('f'), EC_RIGHT},
3205 {MN_BOL, 1, KTRL('a'), EC_BOL},
3206 {MN_EOL, 1, KTRL('e'), EC_EOL},
3207 {MN_PGUP, 1, KTRL('o'), EC_PGUP},
3208 {MN_PGDOWN, 1, KTRL('l'), EC_PGDOWN},
3209 {MN_TOP, 1, KTRL('y'), EC_TOP},
3210 {MN_BOTTOM, 1, KTRL('u'), EC_BOTTOM},
3212 {MN_INSERT, 0, -1, -1},
3213 {MN_INSERT_OBJECT, 1, KTRL('i'), EC_INSERT_OBJECT},
3214 {MN_INSERT_DESTROYED, 1, -1, EC_INSERT_DESTROYED},
3215 {MN_INSERT_BLOCK, 1, -1, EC_INSERT_BLOCK},
3216 {MN_INSERT_MACRO, 1, -1, EC_INSERT_MACRO},
3217 {MN_INSERT_KEYMAP, 1, -1, EC_INSERT_KEYMAP},
3219 {MN_ADJECTIVE_GEN, 0, -1, -1},
3220 {KEY_UNAWARE, 1, -1, EC_IK_UNAWARE},
3221 {KEY_UNIDENTIFIED, 1, -1, EC_IK_UNIDENTIFIED},
3222 {KEY_IDENTIFIED, 1, -1, EC_IK_IDENTIFIED},
3223 {KEY_STAR_IDENTIFIED, 1, -1, EC_IK_STAR_IDENTIFIED},
3224 {KEY_COLLECTING, 1, -1, EC_OK_COLLECTING},
3225 {KEY_WORTHLESS, 1, -1, EC_OK_WORTHLESS},
3227 {MN_ADJECTIVE_SPECIAL, 0, -1, -1},
3228 {MN_BOOSTED, 1, -1, EC_OK_BOOSTED},
3229 {MN_MORE_THAN, 1, -1, EC_OK_MORE_THAN},
3230 {MN_MORE_BONUS, 1, -1, EC_OK_MORE_BONUS},
3231 {MN_ARTIFACT, 1, -1, EC_OK_ARTIFACT},
3232 {MN_EGO, 1, -1, EC_OK_EGO},
3233 {MN_NAMELESS, 1, -1, EC_OK_NAMELESS},
3234 {MN_WANTED, 1, -1, EC_OK_WANTED},
3235 {MN_UNIQUE, 1, -1, EC_OK_UNIQUE},
3236 {MN_HUMAN, 1, -1, EC_OK_HUMAN},
3237 {MN_UNREADABLE, 1, -1, EC_OK_UNREADABLE},
3238 {MN_REALM1, 1, -1, EC_OK_REALM1},
3239 {MN_REALM2, 1, -1, EC_OK_REALM2},
3240 {MN_FIRST, 1, -1, EC_OK_FIRST},
3241 {MN_SECOND, 1, -1, EC_OK_SECOND},
3242 {MN_THIRD, 1, -1, EC_OK_THIRD},
3243 {MN_FOURTH, 1, -1, EC_OK_FOURTH},
3245 {MN_NOUN, 0, -1, -1},
3246 {KEY_WEAPONS, 1, -1, EC_KK_WEAPONS},
3247 {KEY_FAVORITE, 1, -1, EC_KK_FAVORITE},
3248 {KEY_ARMORS, 1, -1, EC_KK_ARMORS},
3249 {KEY_MISSILES, 1, -1, EC_KK_MISSILES},
3250 {KEY_DEVICES, 1, -1, EC_KK_DEVICES},
3251 {KEY_LIGHTS, 1, -1, EC_KK_LIGHTS},
3252 {KEY_JUNKS, 1, -1, EC_KK_JUNKS},
3253 {KEY_SPELLBOOKS, 1, -1, EC_KK_SPELLBOOKS},
3254 {KEY_SHIELDS, 1, -1, EC_KK_SHIELDS},
3255 {KEY_BOWS, 1, -1, EC_KK_BOWS},
3256 {KEY_RINGS, 1, -1, EC_KK_RINGS},
3257 {KEY_AMULETS, 1, -1, EC_KK_AMULETS},
3258 {KEY_SUITS, 1, -1, EC_KK_SUITS},
3259 {KEY_CLOAKS, 1, -1, EC_KK_CLOAKS},
3260 {KEY_HELMS, 1, -1, EC_KK_HELMS},
3261 {KEY_GLOVES, 1, -1, EC_KK_GLOVES},
3262 {KEY_BOOTS, 1, -1, EC_KK_BOOTS},
3264 {MN_COMMAND_LETTER, 0, -1, -1},
3265 {MN_CL_AUTOPICK, 1, -1, EC_CL_AUTOPICK},
3266 {MN_CL_DESTROY, 1, -1, EC_CL_DESTROY},
3267 {MN_CL_LEAVE, 1, -1, EC_CL_LEAVE},
3268 {MN_CL_QUERY, 1, -1, EC_CL_QUERY},
3269 {MN_CL_NO_DISP, 1, -1, EC_CL_NO_DISP},
3276 * Find a command by 'key'.
3278 static int get_com_id(char key)
3282 for (i = 0; menu_data[i].name; i++)
3284 if (menu_data[i].key == key)
3286 return menu_data[i].com_id;
3295 * Display the menu, and get a command
3297 static int do_command_menu(int level, int start)
3302 int col0 = 5 + level*7;
3303 int row0 = 1 + level*3;
3305 int menu_id_list[26];
3307 char linestr[MAX_LINELEN];
3309 /* Get max length */
3311 for (i = start; menu_data[i].level >= level; i++)
3315 /* Ignore lower level sub menus */
3316 if (menu_data[i].level > level) continue;
3318 len = strlen(menu_data[i].name);
3319 if (len > max_len) max_len = len;
3321 menu_id_list[menu_key] = i;
3325 while (menu_key < 26)
3327 menu_id_list[menu_key] = -1;
3331 /* Extra space for displaying menu key and command key */
3332 max_menu_wid = max_len + 3 + 3;
3334 /* Prepare box line */
3336 strcat(linestr, "+");
3337 for (i = 0; i < max_menu_wid + 2; i++)
3339 strcat(linestr, "-");
3341 strcat(linestr, "+");
3351 int row1 = row0 + 1;
3354 Term_putstr(col0, row0, -1, TERM_WHITE, linestr);
3356 /* Draw menu items */
3358 for (i = start; menu_data[i].level >= level; i++)
3360 char com_key_str[3];
3363 /* Ignore lower level sub menus */
3364 if (menu_data[i].level > level) continue;
3366 if (menu_data[i].com_id == -1)
3369 strcpy(com_key_str, "¢§");
3371 strcpy(com_key_str, ">");
3374 else if (menu_data[i].key != -1)
3376 com_key_str[0] = '^';
3377 com_key_str[1] = menu_data[i].key + '@';
3378 com_key_str[2] = '\0';
3382 com_key_str[0] = '\0';
3385 str = format("| %c) %-*s %2s | ", menu_key + 'a', max_len, menu_data[i].name, com_key_str);
3387 Term_putstr(col0, row1++, -1, TERM_WHITE, str);
3392 /* Draw bottom line */
3393 Term_putstr(col0, row1, -1, TERM_WHITE, linestr);
3395 /* The menu was shown */
3399 prt(format("(a-%c) ¥³¥Þ¥ó¥É:", menu_key + 'a' - 1), 0, 0);
3401 prt(format("(a-%c) Command:", menu_key + 'a' - 1), 0, 0);
3405 if (key == ESCAPE) return 0;
3407 if ('a' <= key && key <= 'z')
3409 menu_id = menu_id_list[key - 'a'];
3413 com_id = menu_data[menu_id].com_id;
3417 com_id = do_command_menu(level + 1, menu_id + 1);
3419 if (com_id) return com_id;
3431 com_id = get_com_id(key);
3432 if (com_id) return com_id;
3439 static chain_str_type *new_chain_str(cptr str)
3441 chain_str_type *chain;
3443 size_t len = strlen(str);
3445 chain = (chain_str_type *)ralloc(sizeof(chain_str_type) + len * sizeof(char));
3447 strcpy(chain->s, str);
3454 static void kill_yank_chain(text_body_type *tb)
3456 chain_str_type *chain = tb->yank;
3458 tb->yank_eol = TRUE;
3462 chain_str_type *next = chain->next;
3463 size_t len = strlen(chain->s);
3465 rnfree(chain, sizeof(chain_str_type) + len * sizeof(char));
3472 static void add_str_to_yank(text_body_type *tb, cptr str)
3474 chain_str_type *chain;
3476 tb->yank_eol = FALSE;
3478 if (NULL == tb->yank)
3480 tb->yank = new_chain_str(str);
3490 chain->next = new_chain_str(str);
3495 chain = chain->next;
3500 #define DESCRIPT_HGT 3
3505 static void draw_text_editor(text_body_type *tb)
3508 int by1 = -1, bx1 = -1, by2 = -1, bx2 = -1;
3511 Term_get_size(&tb->wid, &tb->hgt);
3514 * Top line (-1), description line (-3), separator (-1)
3517 tb->hgt -= 2 + DESCRIPT_HGT;
3520 /* Don't let cursor at second byte of kanji */
3521 for (i = 0; tb->lines_list[tb->cy][i]; i++)
3522 if (iskanji(tb->lines_list[tb->cy][i]))
3533 /* Scroll if necessary */
3534 if (tb->cy < tb->upper || tb->upper + tb->hgt <= tb->cy)
3535 tb->upper = tb->cy - (tb->hgt)/2;
3538 if ((tb->cx < tb->left + 10 && tb->left > 0) || tb->left + tb->wid - 5 <= tb->cx)
3539 tb->left = tb->cx - (tb->wid)*2/3;
3543 /* Redraw whole window after resize */
3544 if (tb->old_wid != tb->wid || tb->old_hgt != tb->hgt)
3545 tb->dirty_flags |= DIRTY_SCREEN;
3547 /* Redraw all text after scroll */
3548 else if (tb->old_upper != tb->upper || tb->old_left != tb->left)
3549 tb->dirty_flags |= DIRTY_ALL;
3552 if (tb->dirty_flags & DIRTY_SCREEN)
3554 tb->dirty_flags |= (DIRTY_ALL | DIRTY_MODE);
3560 /* Redraw mode line */
3561 if (tb->dirty_flags & DIRTY_MODE)
3563 char buf[MAX_LINELEN];
3565 int sepa_length = tb->wid;
3568 for (i = 0; i < sepa_length; i++)
3572 Term_putstr(0, tb->hgt + 1, sepa_length, TERM_WHITE, buf);
3575 if (tb->dirty_flags & DIRTY_EXPRESSION)
3580 for (y = 0; tb->lines_list[y]; y++)
3584 cptr s = tb->lines_list[y];
3586 /* Update this line's state */
3587 tb->states[y] = state;
3589 if (*s++ != '?') continue;
3590 if (*s++ != ':') continue;
3592 /* Parse the expr */
3593 v = process_pref_file_expr(&s, &f);
3596 state = (streq(v, "0") ? LSTAT_BYPASS : 0);
3598 /* Re-update this line's state */
3599 tb->states[y] = state | LSTAT_EXPRESSION;
3602 tb->dirty_flags |= DIRTY_ALL;
3607 int tmp_cx = tb->cx;
3608 int len = strlen(tb->lines_list[tb->cy]);
3610 /* Correct cursor location */
3611 if (tb->cx > len) tmp_cx = len;
3613 tb->dirty_flags |= DIRTY_ALL;
3615 if (tb->my < tb->cy ||
3616 (tb->my == tb->cy && tb->mx < tmp_cx))
3632 /* Dump up to tb->hgt lines of messages */
3633 for (i = 0; i < tb->hgt; i++)
3639 int y = tb->upper+i;
3641 /* clean or dirty? */
3642 if (!(tb->dirty_flags & DIRTY_ALL) && (tb->dirty_line != y))
3645 msg = tb->lines_list[y];
3648 /* Apply horizontal scroll */
3649 for (j = 0; *msg; msg++, j++)
3651 if (j == tb->left) break;
3667 Term_erase(0, i + 1, tb->wid);
3669 /* Bypassed line will be displayed by darker color */
3670 if (tb->states[y] & LSTAT_BYPASS) color = TERM_SLATE;
3671 else color = TERM_WHITE;
3675 /* Dump the messages, bottom to top */
3676 Term_putstr(leftcol, i + 1, tb->wid - 1, color, msg);
3681 int x0 = leftcol + tb->left;
3686 if (by1 <= y && y < by2) sx1 = strlen(msg);
3687 if (y == by1) sx0 = bx1;
3688 if (y == by2) sx1 = bx2;
3690 Term_gotoxy(leftcol, i + 1);
3691 if (x0 < sx0) Term_addstr(sx0 - x0, color, msg);
3692 if (x0 < sx1) Term_addstr(sx1 - sx0, TERM_YELLOW, msg + (sx0 - x0));
3693 Term_addstr(-1, color, msg + (sx1 - x0));
3697 for (; i < tb->hgt; i++)
3700 Term_erase(0, i + 1, tb->wid);
3703 /* Display information when updated */
3704 if (tb->old_cy != tb->cy || (tb->dirty_flags & (DIRTY_ALL | DIRTY_NOT_FOUND | DIRTY_NO_SEARCH)) || tb->dirty_line == tb->cy)
3706 autopick_type an_entry, *entry = &an_entry;
3708 /* Clear information line */
3709 for (i = 0; i < DESCRIPT_HGT; i++)
3712 Term_erase(0, tb->hgt + 2 + i, tb->wid);
3715 /* Display information */
3716 if (tb->dirty_flags & DIRTY_NOT_FOUND)
3719 prt(format("¥Ñ¥¿¡¼¥ó¤¬¸«¤Ä¤«¤ê¤Þ¤»¤ó: %s", tb->search_str), tb->hgt + 1 + 1, 0);
3721 prt(format("Pattern not found: %s", tb->search_str), tb->hgt + 1 + 1, 0);
3724 else if (tb->dirty_flags & DIRTY_NO_SEARCH)
3727 prt("¸¡º÷Ãæ¤Î¥Ñ¥¿¡¼¥ó¤¬¤¢¤ê¤Þ¤»¤ó('/'¤Ç¸¡º÷)¡£", tb->hgt + 1 + 1, 0);
3729 prt("No pattern to search. (Press '/' to search.)", tb->hgt +1 + 1, 0);
3732 else if (tb->lines_list[tb->cy][0] == '#')
3735 prt("¤³¤Î¹Ô¤Ï¥³¥á¥ó¥È¤Ç¤¹¡£", tb->hgt +1 + 1, 0);
3737 prt("This line is a comment.", tb->hgt +1 + 1, 0);
3740 else if (tb->lines_list[tb->cy][1] == ':')
3744 switch(tb->lines_list[tb->cy][0])
3748 str = "¤³¤Î¹Ô¤Ï¾ò·ïʬ´ô¼°¤Ç¤¹¡£";
3750 str = "This line is a Conditional Expression.";
3756 str = "¤³¤Î¹Ô¤Ï¥Þ¥¯¥í¤Î¼Â¹ÔÆâÍƤòÄêµÁ¤·¤Þ¤¹¡£";
3758 str = "This line defines a Macro action.";
3763 str = "¤³¤Î¹Ô¤Ï¥Þ¥¯¥í¤Î¥È¥ê¥¬¡¼¡¦¥¡¼¤òÄêµÁ¤·¤Þ¤¹¡£";
3765 str = "This line defines a Macro trigger key.";
3770 str = "¤³¤Î¹Ô¤Ï¥¡¼ÇÛÃÖ¤òÄêµÁ¤·¤Þ¤¹¡£";
3772 str = "This line defines a Keymap.";
3777 /* Draw the first line */
3778 if (str) prt(str, tb->hgt +1 + 1, 0);
3782 switch(tb->lines_list[tb->cy][0])
3785 if (tb->states[tb->cy] & LSTAT_BYPASS)
3788 str = "¸½ºß¤Î¼°¤ÎÃͤϡֵ¶(=0)¡×¤Ç¤¹¡£";
3790 str = "The expression is 'False'(=0) currently.";
3796 str = "¸½ºß¤Î¼°¤ÎÃͤϡֿ¿(=1)¡×¤Ç¤¹¡£";
3798 str = "The expression is 'True'(=1) currently.";
3806 if (tb->states[tb->cy] & LSTAT_BYPASS)
3809 str = "¤³¤Î¹Ô¤Ï¸½ºß¤Ï̵¸ú¤Ê¾õÂ֤Ǥ¹¡£";
3811 str = "This line is bypassed currently.";
3817 /* Draw the second line */
3818 if (str) prt(str, tb->hgt +1 + 2, 0);
3821 /* Get description of an autopicker preference line */
3822 else if (autopick_new_entry(entry, tb->lines_list[tb->cy], FALSE))
3824 char buf[MAX_LINELEN];
3825 char temp[MAX_LINELEN];
3828 describe_autopick(buf, entry);
3830 if (tb->states[tb->cy] & LSTAT_BYPASS)
3833 strcat(buf, "¤³¤Î¹Ô¤Ï¸½ºß¤Ï̵¸ú¤Ê¾õÂ֤Ǥ¹¡£");
3835 strcat(buf, " This line is bypassed currently.");
3839 roff_to_buf(buf, 81, temp, sizeof(temp));
3841 for (i = 0; i < 3; i++)
3847 prt(t, tb->hgt +1 + 1 + i, 0);
3851 autopick_free_entry(entry);
3858 * Kill segment of a line
3860 static void kill_line_segment(text_body_type *tb, int y, int x0, int x1, bool whole)
3862 char buf[MAX_LINELEN];
3863 cptr s = tb->lines_list[y];
3868 if (x0 == x1) return;
3870 /* Kill whole line? */
3871 if (whole && x0 == 0 && s[x1] == '\0' && tb->lines_list[y+1])
3875 string_free(tb->lines_list[y]);
3877 /* Shift lines up */
3878 for (i = y; tb->lines_list[i+1]; i++)
3879 tb->lines_list[i] = tb->lines_list[i+1];
3880 tb->lines_list[i] = NULL;
3882 /* Expressions need re-evaluation */
3883 tb->dirty_flags |= DIRTY_EXPRESSION;
3888 /* Before the segment */
3889 for (x = 0; x < x0; x++)
3892 /* After the segment */
3893 for (x = x1; s[x]; x++)
3899 string_free(tb->lines_list[y]);
3900 tb->lines_list[y] = string_make(buf);
3902 /* Expressions may need re-evaluation */
3903 check_expression_line(tb, y);
3905 /* Text is changed */
3911 * Get a trigger key and insert ASCII string for the trigger
3913 static bool insert_macro_line(text_body_type *tb)
3922 /* Do not process macros */
3928 /* Read the pattern */
3934 /* Do not process macros */
3937 /* Do not wait for keys */
3940 /* Attempt to read a key */
3950 /* Convert the trigger */
3951 ascii_to_text(tmp, buf);
3954 if(!tmp[0]) return FALSE;
3958 /* Insert preference string */
3959 insert_return_code(tb);
3960 string_free(tb->lines_list[tb->cy]);
3961 tb->lines_list[tb->cy] = string_make(format("P:%s", tmp));
3963 /* Acquire action */
3964 i = macro_find_exact(buf);
3968 /* Nothing defined */
3973 /* Analyze the current action */
3974 ascii_to_text(tmp, macro__act[i]);
3977 /* Insert blank action preference line */
3978 insert_return_code(tb);
3979 string_free(tb->lines_list[tb->cy]);
3980 tb->lines_list[tb->cy] = string_make(format("A:%s", tmp));
3987 * Get a command key and insert ASCII string for the key
3989 static bool insert_keymap_line(text_body_type *tb)
3997 if (rogue_like_commands)
3999 mode = KEYMAP_MODE_ROGUE;
4005 mode = KEYMAP_MODE_ORIG;
4018 /* Convert the trigger */
4019 ascii_to_text(tmp, buf);
4022 if(!tmp[0]) return FALSE;
4026 /* Insert preference string */
4027 insert_return_code(tb);
4028 string_free(tb->lines_list[tb->cy]);
4029 tb->lines_list[tb->cy] = string_make(format("C:%d:%s", mode, tmp));
4031 /* Look up the keymap */
4032 act = keymap_act[mode][(byte)(buf[0])];
4034 /* Insert blank action preference line */
4035 insert_return_code(tb);
4036 string_free(tb->lines_list[tb->cy]);
4037 tb->lines_list[tb->cy] = string_make(format("A:%s", act));
4044 * Execute a single editor command
4046 static bool do_editor_command(text_body_type *tb, int com_id)
4054 if (!get_check("Á´¤Æ¤ÎÊѹ¹¤òÇË´þ¤·¤Æ¤«¤é½ªÎ»¤·¤Þ¤¹¡£¤è¤í¤·¤¤¤Ç¤¹¤«¡© ")) break;
4056 if (!get_check("Discard all changes and quit. Are you sure? ")) break;
4059 return QUIT_WITHOUT_SAVE;
4062 return QUIT_AND_SAVE;
4065 /* Revert to original */
4067 if (!get_check("Á´¤Æ¤ÎÊѹ¹¤òÇË´þ¤·¤Æ¸µ¤Î¾õÂÖ¤ËÌᤷ¤Þ¤¹¡£¤è¤í¤·¤¤¤Ç¤¹¤«¡© ")) break;
4069 if (!get_check("Discard all changes and revert to original file. Are you sure? ")) break;
4072 free_text_lines(tb->lines_list);
4073 tb->lines_list = read_pickpref_text_lines(&tb->filename_mode);
4074 tb->dirty_flags |= DIRTY_ALL | DIRTY_MODE | DIRTY_EXPRESSION;
4075 tb->cx = tb->cy = 0;
4078 /* Text is not changed */
4079 tb->changed = FALSE;
4083 /* Peruse the main help file */
4085 (void)show_file(TRUE, "jeditor.txt", NULL, 0, 0);
4087 (void)show_file(TRUE, "editor.txt", NULL, 0, 0);
4090 tb->dirty_flags |= DIRTY_SCREEN;
4095 /* Split a line or insert end of line */
4097 /* Ignore selection */
4103 tb->dirty_flags |= DIRTY_ALL;
4106 insert_return_code(tb);
4111 tb->dirty_flags |= DIRTY_ALL;
4121 len = strlen(tb->lines_list[tb->cy]);
4122 if (len < tb->cx) tb->cx = len;
4124 else if (tb->cy > 0)
4127 tb->cx = strlen(tb->lines_list[tb->cy]);
4133 if (tb->lines_list[tb->cy + 1]) tb->cy++;
4138 if (tb->cy > 0) tb->cy--;
4147 if (iskanji(tb->lines_list[tb->cy][tb->cx])) tb->cx++;
4150 len = strlen(tb->lines_list[tb->cy]);
4153 if (tb->lines_list[tb->cy + 1])
4165 /* Beginning of line */
4171 tb->cx = strlen(tb->lines_list[tb->cy]);
4175 while (0 < tb->cy && tb->upper <= tb->cy)
4177 while (0 < tb->upper && tb->cy + 1 < tb->upper + tb->hgt)
4183 while (tb->cy < tb->upper + tb->hgt && tb->lines_list[tb->cy + 1])
4193 while (tb->lines_list[tb->cy + 1])
4199 int by1, bx1, by2, bx2;
4202 /* Copy the text first */
4203 do_editor_command(tb, EC_COPY);
4205 if (tb->my < tb->cy ||
4206 (tb->my == tb->cy && tb->mx < tb->cx))
4221 /* Kill lines in reverse order */
4222 for (y = by2; y >= by1; y--)
4225 int x1 = strlen(tb->lines_list[y]);
4227 if (y == by1) x0 = bx1;
4228 if (y == by2) x1 = bx2;
4230 kill_line_segment(tb, y, x0, x1, TRUE);
4233 /* Correct cursor position */
4237 /* Disable selection */
4241 tb->dirty_flags |= DIRTY_ALL;
4248 int by1, bx1, by2, bx2;
4250 int len = strlen(tb->lines_list[tb->cy]);
4252 /* Correct cursor location */
4253 if (tb->cx > len) tb->cx = len;
4255 /* Use single line? */
4260 if (tb->lines_list[tb->cy + 1])
4262 /* Select a single line */
4268 /* Select bottom line */
4273 if (tb->my < tb->cy ||
4274 (tb->my == tb->cy && tb->mx < tb->cx))
4289 /* Kill old yank buffer */
4290 kill_yank_chain(tb);
4292 /* Copy string to yank buffer */
4293 for (y = by1; y <= by2; y++)
4296 char buf[MAX_LINELEN];
4299 int x1 = strlen(tb->lines_list[y]);
4301 if (y == by1) x0 = bx1;
4302 if (y == by2) x1 = bx2;
4304 for (i = 0; i < x1 - x0; i++)
4306 buf[i] = tb->lines_list[y][x0 + i];
4310 add_str_to_yank(tb, buf);
4313 /* Disable selection */
4317 tb->dirty_flags |= DIRTY_ALL;
4323 /* Paste killed text */
4325 chain_str_type *chain = tb->yank;
4326 int len = strlen(tb->lines_list[tb->cy]);
4328 /* Nothing to do? */
4331 /* Correct cursor location */
4332 if (tb->cx > len) tb->cx = len;
4334 /* Ignore selection */
4340 tb->dirty_flags |= DIRTY_ALL;
4346 cptr yank_str = chain->s;
4348 char buf[MAX_LINELEN];
4350 char rest[MAX_LINELEN], *rest_ptr = rest;
4352 /* Save preceding string */
4353 for(i = 0; i < tb->cx; i++)
4354 buf[i] = tb->lines_list[tb->cy][i];
4356 strcpy(rest, &(tb->lines_list[tb->cy][i]));
4358 /* Paste yank buffer */
4359 while (*yank_str && i < MAX_LINELEN-1)
4361 buf[i++] = *yank_str++;
4367 chain = chain->next;
4369 if (chain || tb->yank_eol)
4371 /* There is an end of line between chain nodes */
4373 insert_return_code(tb);
4375 /* Replace this line with new one */
4376 string_free(tb->lines_list[tb->cy]);
4377 tb->lines_list[tb->cy] = string_make(buf);
4379 /* Move to next line */
4386 /* Final line doesn't have end of line */
4388 tb->cx = strlen(buf);
4390 /* Rest of original line */
4391 while (*rest_ptr && i < MAX_LINELEN-1)
4393 buf[i++] = *rest_ptr++;
4399 /* Replace this line with new one */
4400 string_free(tb->lines_list[tb->cy]);
4401 tb->lines_list[tb->cy] = string_make(buf);
4408 tb->dirty_flags |= DIRTY_ALL;
4410 /* Expressions need re-evaluation */
4411 tb->dirty_flags |= DIRTY_EXPRESSION;
4413 /* Text is changed */
4422 /* Disable the selection */
4426 tb->dirty_flags |= DIRTY_ALL;
4430 tb->mark = MARK_MARK;
4432 /* Repeating this command swaps cursor position */
4433 if (com_id == tb->old_com_id)
4445 tb->dirty_flags |= DIRTY_ALL;
4449 int len = strlen(tb->lines_list[tb->cy]);
4451 /* Mark the point 1 */
4455 /* Correct cursor location */
4456 if (tb->cx > len) tb->mx = len;
4463 /* Kill rest of line */
4465 int len = strlen(tb->lines_list[tb->cy]);
4467 /* Correct cursor location */
4468 if (tb->cx > len) tb->cx = len;
4470 /* Ignore selection */
4476 tb->dirty_flags |= DIRTY_ALL;
4479 /* Append only if this command is repeated. */
4480 if (tb->old_com_id != com_id)
4482 kill_yank_chain(tb);
4486 /* Really deleted some text */
4489 /* Add deleted string to yank buffer */
4490 add_str_to_yank(tb, &(tb->lines_list[tb->cy][tb->cx]));
4492 kill_line_segment(tb, tb->cy, tb->cx, len, FALSE);
4495 tb->dirty_line = tb->cy;
4497 /* Leave end of line character */
4501 /* Cut the end of line character only */
4502 if (tb->yank_eol) add_str_to_yank(tb, "");
4504 /* Cut end of line */
4505 tb->yank_eol = TRUE;
4507 do_editor_command(tb, EC_DELETE_CHAR);
4511 case EC_DELETE_CHAR:
4512 /* DELETE == go forward + BACK SPACE */
4514 /* Ignore selection */
4520 tb->dirty_flags |= DIRTY_ALL;
4524 if (iskanji(tb->lines_list[tb->cy][tb->cx])) tb->cx++;
4528 do_editor_command(tb, EC_BACKSPACE);
4536 char buf[MAX_LINELEN];
4538 /* Ignore selection */
4544 tb->dirty_flags |= DIRTY_ALL;
4547 len = strlen(tb->lines_list[tb->cy]);
4550 if (tb->lines_list[tb->cy + 1])
4564 /* delete a return code and union two lines */
4565 if (tb->cy == 0) break;
4566 tb->cx = strlen(tb->lines_list[tb->cy-1]);
4567 strcpy(buf, tb->lines_list[tb->cy-1]);
4568 strcat(buf, tb->lines_list[tb->cy]);
4569 string_free(tb->lines_list[tb->cy-1]);
4570 string_free(tb->lines_list[tb->cy]);
4571 tb->lines_list[tb->cy-1] = string_make(buf);
4573 for (i = tb->cy; tb->lines_list[i+1]; i++)
4574 tb->lines_list[i] = tb->lines_list[i+1];
4576 tb->lines_list[i] = NULL;
4580 tb->dirty_flags |= DIRTY_ALL;
4582 /* Expressions need re-evaluation */
4583 tb->dirty_flags |= DIRTY_EXPRESSION;
4585 /* Text is changed */
4591 for (i = j = k = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
4595 if (iskanji(tb->lines_list[tb->cy][i]))
4596 buf[j++] = tb->lines_list[tb->cy][i++];
4598 buf[j++] = tb->lines_list[tb->cy][i];
4605 for (; tb->lines_list[tb->cy][i]; i++)
4606 buf[j++] = tb->lines_list[tb->cy][i];
4608 string_free(tb->lines_list[tb->cy]);
4609 tb->lines_list[tb->cy] = string_make(buf);
4612 tb->dirty_line = tb->cy;
4614 /* Expressions may need re-evaluation */
4615 check_expression_line(tb, tb->cy);
4617 /* Text is changed */
4627 /* Become dirty because of item/equip menu */
4628 tb->dirty_flags |= DIRTY_SCREEN;
4630 search_dir = get_string_for_search(&tb->search_o_ptr, &tb->search_str);
4632 if (!search_dir) break;
4634 if (search_dir == 1) do_editor_command(tb, EC_SEARCH_FORW);
4635 else do_editor_command(tb, EC_SEARCH_BACK);
4639 case EC_SEARCH_FORW:
4640 if (tb->search_o_ptr)
4642 if (!search_for_object(tb, tb->search_o_ptr, TRUE)) tb->dirty_flags |= DIRTY_NOT_FOUND;
4644 else if (tb->search_str)
4646 if (!search_for_string(tb, tb->search_str, TRUE)) tb->dirty_flags |= DIRTY_NOT_FOUND;
4650 tb->dirty_flags |= DIRTY_NO_SEARCH;
4654 case EC_SEARCH_BACK:
4655 if (tb->search_o_ptr)
4657 if (!search_for_object(tb, tb->search_o_ptr, FALSE)) tb->dirty_flags |= DIRTY_NOT_FOUND;
4659 else if (tb->search_str)
4661 if (!search_for_string(tb, tb->search_str, FALSE)) tb->dirty_flags |= DIRTY_NOT_FOUND;
4665 tb->dirty_flags |= DIRTY_NO_SEARCH;
4670 /* Become dirty because of item/equip menu */
4671 tb->dirty_flags |= DIRTY_SCREEN;
4673 if (!get_object_for_search(&tb->search_o_ptr, &tb->search_str)) break;
4675 do_editor_command(tb, EC_SEARCH_FORW);
4678 case EC_SEARCH_DESTROYED:
4679 if (!get_destroyed_object_for_search(&tb->search_o_ptr, &tb->search_str)) break;
4681 do_editor_command(tb, EC_SEARCH_FORW);
4684 case EC_INSERT_OBJECT:
4686 /* Insert choosen item name */
4688 autopick_type an_entry, *entry = &an_entry;
4690 if (!entry_from_choosed_object(entry))
4692 /* Now dirty because of item/equip menu */
4693 tb->dirty_flags |= DIRTY_SCREEN;
4698 insert_return_code(tb);
4699 string_free(tb->lines_list[tb->cy]);
4700 tb->lines_list[tb->cy] = autopick_line_from_entry_kill(entry);
4702 /* Now dirty because of item/equip menu */
4703 tb->dirty_flags |= DIRTY_SCREEN;
4708 case EC_INSERT_DESTROYED:
4709 /* Insert a name of last destroyed item */
4710 if (tb->last_destroyed)
4713 insert_return_code(tb);
4714 string_free(tb->lines_list[tb->cy]);
4715 tb->lines_list[tb->cy] = string_make(tb->last_destroyed);
4718 tb->dirty_flags |= DIRTY_ALL;
4720 /* Text is changed */
4725 case EC_INSERT_BLOCK:
4727 /* Insert a conditinal expression line */
4730 /* Conditional Expression for Class and Race */
4731 sprintf(classrace, "?:[AND [EQU $RACE %s] [EQU $CLASS %s]]",
4733 rp_ptr->E_title, cp_ptr->E_title
4735 rp_ptr->title, cp_ptr->title
4740 insert_return_code(tb);
4741 string_free(tb->lines_list[tb->cy]);
4742 tb->lines_list[tb->cy] = string_make(classrace);
4744 insert_return_code(tb);
4745 string_free(tb->lines_list[tb->cy]);
4746 tb->lines_list[tb->cy] = string_make("?:1");
4749 tb->dirty_flags |= DIRTY_ALL;
4751 /* Text is changed */
4757 case EC_INSERT_MACRO:
4758 /* Draw_everythig (delete menu) */
4759 draw_text_editor(tb);
4762 Term_erase(0, tb->cy - tb->upper + 1, tb->wid);
4766 Term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW, "P:<¥È¥ê¥¬¡¼¥¡¼>: ");
4768 Term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW, "P:<Trigger key>: ");
4770 if (insert_macro_line(tb))
4772 /* Prepare to input action */
4776 tb->dirty_flags |= DIRTY_ALL;
4778 /* Text is changed */
4784 case EC_INSERT_KEYMAP:
4785 /* Draw_everythig (delete menu) */
4786 draw_text_editor(tb);
4789 Term_erase(0, tb->cy - tb->upper + 1, tb->wid);
4793 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)));
4795 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)));
4798 if (insert_keymap_line(tb))
4800 /* Prepare to input action */
4804 tb->dirty_flags |= DIRTY_ALL;
4806 /* Text is changed */
4811 case EC_CL_AUTOPICK: toggle_command_letter(tb, DO_AUTOPICK); break;
4812 case EC_CL_DESTROY: toggle_command_letter(tb, DO_AUTODESTROY); break;
4813 case EC_CL_LEAVE: toggle_command_letter(tb, DONT_AUTOPICK); break;
4814 case EC_CL_QUERY: toggle_command_letter(tb, DO_QUERY_AUTOPICK); break;
4815 case EC_CL_NO_DISP: toggle_command_letter(tb, DO_DISPLAY); break;
4817 case EC_IK_UNAWARE: toggle_keyword(tb, FLG_UNAWARE); break;
4818 case EC_IK_UNIDENTIFIED: toggle_keyword(tb, FLG_UNIDENTIFIED); break;
4819 case EC_IK_IDENTIFIED: toggle_keyword(tb, FLG_IDENTIFIED); break;
4820 case EC_IK_STAR_IDENTIFIED: toggle_keyword(tb, FLG_STAR_IDENTIFIED); break;
4821 case EC_KK_WEAPONS: toggle_keyword(tb, FLG_WEAPONS); break;
4822 case EC_KK_FAVORITE: toggle_keyword(tb, FLG_FAVORITE); break;
4823 case EC_KK_ARMORS: toggle_keyword(tb, FLG_ARMORS); break;
4824 case EC_KK_MISSILES: toggle_keyword(tb, FLG_MISSILES); break;
4825 case EC_KK_DEVICES: toggle_keyword(tb, FLG_DEVICES); break;
4826 case EC_KK_LIGHTS: toggle_keyword(tb, FLG_LIGHTS); break;
4827 case EC_KK_JUNKS: toggle_keyword(tb, FLG_JUNKS); break;
4828 case EC_KK_SPELLBOOKS: toggle_keyword(tb, FLG_SPELLBOOKS); break;
4829 case EC_KK_SHIELDS: toggle_keyword(tb, FLG_SHIELDS); break;
4830 case EC_KK_BOWS: toggle_keyword(tb, FLG_BOWS); break;
4831 case EC_KK_RINGS: toggle_keyword(tb, FLG_RINGS); break;
4832 case EC_KK_AMULETS: toggle_keyword(tb, FLG_AMULETS); break;
4833 case EC_KK_SUITS: toggle_keyword(tb, FLG_SUITS); break;
4834 case EC_KK_CLOAKS: toggle_keyword(tb, FLG_CLOAKS); break;
4835 case EC_KK_HELMS: toggle_keyword(tb, FLG_HELMS); break;
4836 case EC_KK_GLOVES: toggle_keyword(tb, FLG_GLOVES); break;
4837 case EC_KK_BOOTS: toggle_keyword(tb, FLG_BOOTS); break;
4838 case EC_OK_COLLECTING: toggle_keyword(tb, FLG_COLLECTING); break;
4839 case EC_OK_BOOSTED: toggle_keyword(tb, FLG_BOOSTED); break;
4840 case EC_OK_MORE_THAN: toggle_keyword(tb, FLG_MORE_THAN); break;
4841 case EC_OK_MORE_BONUS: toggle_keyword(tb, FLG_MORE_BONUS); break;
4842 case EC_OK_WORTHLESS: toggle_keyword(tb, FLG_WORTHLESS); break;
4843 case EC_OK_ARTIFACT: toggle_keyword(tb, FLG_ARTIFACT); break;
4844 case EC_OK_EGO: toggle_keyword(tb, FLG_EGO); break;
4845 case EC_OK_NAMELESS: toggle_keyword(tb, FLG_NAMELESS); break;
4846 case EC_OK_WANTED: toggle_keyword(tb, FLG_WANTED); break;
4847 case EC_OK_UNIQUE: toggle_keyword(tb, FLG_UNIQUE); break;
4848 case EC_OK_HUMAN: toggle_keyword(tb, FLG_HUMAN); break;
4849 case EC_OK_UNREADABLE:
4850 toggle_keyword(tb, FLG_UNREADABLE);
4851 add_keyword(tb, FLG_SPELLBOOKS);
4854 toggle_keyword(tb, FLG_REALM1);
4855 add_keyword(tb, FLG_SPELLBOOKS);
4858 toggle_keyword(tb, FLG_REALM2);
4859 add_keyword(tb, FLG_SPELLBOOKS);
4862 toggle_keyword(tb, FLG_FIRST);
4863 add_keyword(tb, FLG_SPELLBOOKS);
4866 toggle_keyword(tb, FLG_SECOND);
4867 add_keyword(tb, FLG_SPELLBOOKS);
4870 toggle_keyword(tb, FLG_THIRD);
4871 add_keyword(tb, FLG_SPELLBOOKS);
4874 toggle_keyword(tb, FLG_FOURTH);
4875 add_keyword(tb, FLG_SPELLBOOKS);
4879 /* Save old command */
4880 tb->old_com_id = com_id;
4887 * Insert single letter at cursor position.
4889 static void insert_single_letter(text_body_type *tb, int key)
4892 char buf[MAX_LINELEN];
4894 /* Save preceding string */
4895 for (i = j = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
4896 buf[j++] = tb->lines_list[tb->cy][i];
4898 /* Add a character */
4906 if (j+2 < MAX_LINELEN)
4918 if (j+1 < MAX_LINELEN)
4924 for (; tb->lines_list[tb->cy][i] && j + 1 < MAX_LINELEN; i++)
4925 buf[j++] = tb->lines_list[tb->cy][i];
4928 /* Replace current line with new line */
4929 string_free(tb->lines_list[tb->cy]);
4930 tb->lines_list[tb->cy] = string_make(buf);
4932 /* Move to correct collumn */
4933 len = strlen(tb->lines_list[tb->cy]);
4934 if (len < tb->cx) tb->cx = len;
4937 tb->dirty_line = tb->cy;
4939 /* Expressions may need re-evaluation */
4940 check_expression_line(tb, tb->cy);
4942 /* Text is changed */
4947 * In-game editor of Object Auto-picker/Destoryer
4949 void do_cmd_edit_autopick(void)
4951 static int cx_save = 0;
4952 static int cy_save = 0;
4954 text_body_type text_body, *tb = &text_body;
4956 autopick_type an_entry, *entry = &an_entry;
4957 char buf[MAX_LINELEN];
4962 static s32b old_autosave_turn = 0L;
4965 tb->changed = FALSE;
4968 tb->upper = tb->left = 0;
4970 tb->mx = tb->my = 0;
4971 tb->old_cy = tb->old_upper = tb->old_left = -1;
4972 tb->old_wid = tb->old_hgt = -1;
4976 tb->search_o_ptr = NULL;
4977 tb->search_str = NULL;
4978 tb->last_destroyed = NULL;
4979 tb->dirty_flags = DIRTY_ALL | DIRTY_MODE | DIRTY_EXPRESSION;
4980 tb->dirty_line = -1;
4981 tb->filename_mode = PT_WITH_PNAME;
4984 if (turn > old_autosave_turn + 100L)
4986 do_cmd_save_game(TRUE);
4987 old_autosave_turn = turn;
4990 /* HACK -- Reset start_time to stop counting playtime while edit */
4993 /* Free old entries */
4996 /* Command Description of the 'Last Destroyed Item' */
4997 if (autopick_last_destroyed_object.k_idx)
4999 autopick_entry_from_object(entry, &autopick_last_destroyed_object);
5000 tb->last_destroyed = autopick_line_from_entry_kill(entry);
5003 /* Read or initialize whole text */
5004 tb->lines_list = read_pickpref_text_lines(&tb->filename_mode);
5006 /* Reset cursor position if needed */
5007 for (i = 0; i < tb->cy; i++)
5009 if (!tb->lines_list[i])
5011 tb->cy = tb->cx = 0;
5016 /* Save the screen */
5019 /* Process requests until done */
5025 /* Draw_everythig */
5026 draw_text_editor(tb);
5028 /* Display header line */
5030 prt("(^Q:½ªÎ» ^W:¥»¡¼¥Ö¤·¤Æ½ªÎ», ESC:¥á¥Ë¥å¡¼, ¤½¤Î¾:ÆþÎÏ)", 0, 0);
5032 prt("(^Q:quit, ^W:save&quit, ESC:menu, Other:input text)", 0, 0);
5036 /* Display current position */
5037 prt (format("(%d,%d)", tb->cx, tb->cy), 0, 60);
5041 /* Display current position and mark position */
5042 prt (format("(%d,%d)-(%d,%d)", tb->mx, tb->my, tb->cx, tb->cy), 0, 60);
5046 Term_gotoxy(tb->cx - tb->left, tb->cy - tb->upper + 1);
5049 tb->dirty_flags = 0;
5050 tb->dirty_line = -1;
5052 /* Save old key and location */
5053 tb->old_cy = tb->cy;
5054 tb->old_upper = tb->upper;
5055 tb->old_left = tb->left;
5056 tb->old_wid = tb->wid;
5057 tb->old_hgt = tb->hgt;
5062 /* Count length of macro trigger which induced this key */
5063 trig_len = strlen(inkey_macro_trigger_string);
5065 /* HACK -- ignore macro defined on ASCII keys */
5068 /* Get original key */
5069 key = inkey_macro_trigger_string[0];
5071 /* Kill further macro expansion */
5076 if (key == 0x7F) key = KTRL('d');
5079 /* Cursor key macroes to direction command */
5101 * Un-shifted cursor keys cancells
5102 * selection created by shift+cursor.
5104 if (tb->mark & MARK_BY_SHIFT)
5109 tb->dirty_flags |= DIRTY_ALL;
5113 /* Mega Hack!!! Start selection with shift + cursor keys */
5118 /* Get ascii form */
5119 ascii_to_text(buf, inkey_macro_trigger_string);
5121 if (strstr(buf, "shift-Down"))
5123 else if (strstr(buf, "shift-Left"))
5125 else if (strstr(buf, "shift-Right"))
5127 else if (strstr(buf, "shift-Up"))
5132 /* Kill further macro expansion */
5135 /* Start selection */
5138 int len = strlen(tb->lines_list[tb->cy]);
5140 tb->mark = MARK_MARK | MARK_BY_SHIFT;
5144 /* Correct cursor location */
5145 if (tb->cx > len) tb->mx = len;
5147 /* Need to redraw text */
5148 if (com_id == EC_UP || com_id == EC_DOWN)
5150 /* Redraw all text */
5151 tb->dirty_flags |= DIRTY_ALL;
5155 tb->dirty_line = tb->cy;
5168 else if (key == ESCAPE)
5170 com_id = do_command_menu(0, 0);
5172 /* Redraw all text later */
5173 tb->dirty_flags |= DIRTY_SCREEN;
5176 /* Insert a character */
5177 else if (!iscntrl(key & 0xff))
5179 /* Ignore selection */
5185 tb->dirty_flags |= DIRTY_ALL;
5188 insert_single_letter(tb, key);
5194 /* Other commands */
5197 com_id = get_com_id(key);
5200 if (com_id) quit = do_editor_command(tb, com_id);
5203 /* Restore the screen */
5206 switch (tb->filename_mode)
5210 strcpy(buf, "picktype.prf");
5212 strcpy(buf, "pickpref.prf");
5218 sprintf(buf, "picktype-%s.prf", player_name);
5220 sprintf(buf, "pickpref-%s.prf", player_name);
5225 if (tb->changed && quit == QUIT_AND_SAVE)
5226 write_text_lines(buf, tb->lines_list);
5228 free_text_lines(tb->lines_list);
5230 string_free(tb->last_destroyed);
5232 /* Destroy string chain */
5233 kill_yank_chain(tb);
5235 /* Reload autopick pref */
5236 process_pickpref_file(buf);
5238 /* HACK -- reset start_time so that playtime is not increase while edit */
5239 start_time = time(NULL);
5241 /* Save cursor location */