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
1404 * Struct for yank buffer
1406 typedef struct chain_str {
1407 struct chain_str *next;
1413 * Data struct for text editor
1419 int old_wid, old_hgt;
1421 int old_upper, old_left;
1425 object_type *search_o_ptr;
1427 cptr last_destroyed;
1429 chain_str_type *yank;
1433 byte states[MAX_LINES];
1443 * Dirty flag for text editor
1445 #define DIRTY_ALL 0x01
1446 #define DIRTY_MODE 0x04
1447 #define DIRTY_SCREEN 0x08
1448 #define DIRTY_NOT_FOUND 0x10
1449 #define DIRTY_NO_SEARCH 0x20
1450 #define DIRTY_EXPRESSION 0x40
1454 * Describe which kind of object is Auto-picked/destroyed
1456 static void describe_autopick(char *buff, autopick_type *entry)
1458 cptr str = entry->name;
1459 byte act = entry->action;
1460 cptr insc = entry->insc;
1466 cptr before_str[100], body_str;
1469 body_str = "¥¢¥¤¥Æ¥à";
1471 /*** Collecting items ***/
1472 /*** Which can be absorbed into a slot as a bundle ***/
1473 if (IS_FLG(FLG_COLLECTING))
1474 before_str[before_n++] = "¼ý½¸Ãæ¤Ç´û¤Ë»ý¤Ã¤Æ¤¤¤ë¥¹¥í¥Ã¥È¤Ë¤Þ¤È¤á¤é¤ì¤ë";
1476 /*** Unidentified ***/
1477 if (IS_FLG(FLG_UNIDENTIFIED))
1478 before_str[before_n++] = "̤´ÕÄê¤Î";
1480 /*** Identified ***/
1481 if (IS_FLG(FLG_IDENTIFIED))
1482 before_str[before_n++] = "´ÕÄêºÑ¤ß¤Î";
1484 /*** *Identified* ***/
1485 if (IS_FLG(FLG_STAR_IDENTIFIED))
1486 before_str[before_n++] = "´°Á´¤Ë´ÕÄêºÑ¤ß¤Î";
1488 /*** Dice boosted (weapon of slaying) ***/
1489 if (IS_FLG(FLG_BOOSTED))
1491 before_str[before_n++] = "¥À¥á¡¼¥¸¥À¥¤¥¹¤¬Ä̾ï¤è¤êÂ礤¤";
1495 /*** Weapons whose dd*ds is more than nn ***/
1496 if (IS_FLG(FLG_MORE_THAN))
1498 static char more_than_desc_str[] = "___";
1499 before_str[before_n++] = "¥À¥á¡¼¥¸¥À¥¤¥¹¤ÎºÇÂçÃͤ¬";
1502 sprintf(more_than_desc_str,"%d", entry->dice);
1503 before_str[before_n++] = more_than_desc_str;
1504 before_str[before_n++] = "°Ê¾å¤Î";
1507 /*** Items whose magical bonus is more than nn ***/
1508 if (IS_FLG(FLG_MORE_BONUS))
1510 static char more_bonus_desc_str[] = "___";
1511 before_str[before_n++] = "½¤ÀµÃͤ¬(+";
1513 sprintf(more_bonus_desc_str,"%d", entry->bonus);
1514 before_str[before_n++] = more_bonus_desc_str;
1515 before_str[before_n++] = ")°Ê¾å¤Î";
1518 /*** Worthless items ***/
1519 if (IS_FLG(FLG_WORTHLESS))
1520 before_str[before_n++] = "Ź¤Ç̵²ÁÃͤÈȽÄꤵ¤ì¤ë";
1523 if (IS_FLG(FLG_ARTIFACT))
1525 before_str[before_n++] = "¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È¤Î";
1530 if (IS_FLG(FLG_EGO))
1532 before_str[before_n++] = "¥¨¥´¥¢¥¤¥Æ¥à¤Î";
1537 if (IS_FLG(FLG_NAMELESS))
1539 before_str[before_n++] = "¥¨¥´¤Ç¤â¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È¤Ç¤â¤Ê¤¤";
1543 /*** Unaware items ***/
1544 if (IS_FLG(FLG_UNAWARE))
1545 before_str[before_n++] = "̤´ÕÄê¤Ç¤½¤Î¸ú²Ì¤âȽÌÀ¤·¤Æ¤¤¤Ê¤¤";
1547 /*** Wanted monster's corpse/skeletons ***/
1548 if (IS_FLG(FLG_WANTED))
1550 before_str[before_n++] = "¥Ï¥ó¥¿¡¼»ö̳½ê¤Ç¾Þ¶â¼ó¤È¤µ¤ì¤Æ¤¤¤ë";
1551 body_str = "»àÂΤä¹ü";
1554 /*** Human corpse/skeletons (for Daemon magic) ***/
1555 if (IS_FLG(FLG_HUMAN))
1557 before_str[before_n++] = "°ËâËâË¡¤Ç»È¤¦¤¿¤á¤Î¿Í´Ö¤ä¥Ò¥å¡¼¥Þ¥Î¥¤¥É¤Î";
1558 body_str = "»àÂΤä¹ü";
1561 /*** Unique monster's corpse/skeletons/statues ***/
1562 if (IS_FLG(FLG_UNIQUE))
1564 before_str[before_n++] = "¥æ¥Ë¡¼¥¯¥â¥ó¥¹¥¿¡¼¤Î";
1565 body_str = "»àÂΤä¹ü";
1568 /*** Unreadable spellbooks ***/
1569 if (IS_FLG(FLG_UNREADABLE))
1571 before_str[before_n++] = "¤¢¤Ê¤¿¤¬Æɤá¤Ê¤¤Îΰè¤Î";
1572 body_str = "ËâË¡½ñ";
1575 /*** First realm spellbooks ***/
1576 if (IS_FLG(FLG_REALM1))
1578 before_str[before_n++] = "Âè°ìÎΰè¤Î";
1579 body_str = "ËâË¡½ñ";
1582 /*** Second realm spellbooks ***/
1583 if (IS_FLG(FLG_REALM2))
1585 before_str[before_n++] = "ÂèÆóÎΰè¤Î";
1586 body_str = "ËâË¡½ñ";
1589 /*** First rank spellbooks ***/
1590 if (IS_FLG(FLG_FIRST))
1592 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î1ºýÌܤÎ";
1593 body_str = "ËâË¡½ñ";
1596 /*** Second rank spellbooks ***/
1597 if (IS_FLG(FLG_SECOND))
1599 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î2ºýÌܤÎ";
1600 body_str = "ËâË¡½ñ";
1603 /*** Third rank spellbooks ***/
1604 if (IS_FLG(FLG_THIRD))
1606 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î3ºýÌܤÎ";
1607 body_str = "ËâË¡½ñ";
1610 /*** Fourth rank spellbooks ***/
1611 if (IS_FLG(FLG_FOURTH))
1613 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î4ºýÌܤÎ";
1614 body_str = "ËâË¡½ñ";
1618 if (IS_FLG(FLG_ITEMS))
1619 ; /* Nothing to do */
1620 else if (IS_FLG(FLG_WEAPONS))
1622 else if (IS_FLG(FLG_ARMORS))
1624 else if (IS_FLG(FLG_MISSILES))
1625 body_str = "ÃƤäÌð¤ä¥¯¥í¥¹¥Ü¥¦¤ÎÌð";
1626 else if (IS_FLG(FLG_DEVICES))
1627 body_str = "´¬Êª¤äËâË¡ËÀ¤ä¾ó¤ä¥í¥Ã¥É";
1628 else if (IS_FLG(FLG_LIGHTS))
1629 body_str = "¸÷¸»ÍѤΥ¢¥¤¥Æ¥à";
1630 else if (IS_FLG(FLG_JUNKS))
1631 body_str = "Àޤ줿ËÀÅù¤Î¥¬¥é¥¯¥¿";
1632 else if (IS_FLG(FLG_SPELLBOOKS))
1633 body_str = "ËâË¡½ñ";
1634 else if (IS_FLG(FLG_HAFTED))
1636 else if (IS_FLG(FLG_SHIELDS))
1638 else if (IS_FLG(FLG_BOWS))
1639 body_str = "¥¹¥ê¥ó¥°¤äµÝ¤ä¥¯¥í¥¹¥Ü¥¦";
1640 else if (IS_FLG(FLG_RINGS))
1642 else if (IS_FLG(FLG_AMULETS))
1643 body_str = "¥¢¥ß¥å¥ì¥Ã¥È";
1644 else if (IS_FLG(FLG_SUITS))
1646 else if (IS_FLG(FLG_CLOAKS))
1647 body_str = "¥¯¥í¡¼¥¯";
1648 else if (IS_FLG(FLG_HELMS))
1649 body_str = "¥Ø¥ë¥á¥Ã¥È¤ä´§";
1650 else if (IS_FLG(FLG_GLOVES))
1652 else if (IS_FLG(FLG_BOOTS))
1653 body_str = "¥Ö¡¼¥Ä";
1654 else if (IS_FLG(FLG_FAVORITE))
1655 body_str = "ÆÀ°ÕÉð´ï";
1659 strcat(buff, "Á´¤Æ¤Î");
1660 else for (i = 0; i < before_n && before_str[i]; i++)
1661 strcat(buff, before_str[i]);
1663 strcat(buff, body_str);
1673 strcat(buff, "¤Ç¡¢Ì¾Á°¤¬¡Ö");
1674 strncat(buff, str, 80);
1676 strcat(buff, "¡×¤Ç»Ï¤Þ¤ë¤â¤Î");
1678 strcat(buff, "¡×¤ò´Þ¤à¤â¤Î");
1683 strncat(buff, format("¤Ë¡Ö%s¡×", insc), 80);
1685 if (strstr(insc, "%%all"))
1686 strcat(buff, "(%%all¤ÏÁ´Ç½ÎϤòɽ¤¹±Ñ»ú¤Îµ¹æ¤ÇÃÖ´¹)");
1687 else if (strstr(insc, "%all"))
1688 strcat(buff, "(%all¤ÏÁ´Ç½ÎϤòɽ¤¹µ¹æ¤ÇÃÖ´¹)");
1689 else if (strstr(insc, "%%"))
1690 strcat(buff, "(%%¤ÏÄɲÃǽÎϤòɽ¤¹±Ñ»ú¤Îµ¹æ¤ÇÃÖ´¹)");
1691 else if (strstr(insc, "%"))
1692 strcat(buff, "(%¤ÏÄɲÃǽÎϤòɽ¤¹µ¹æ¤ÇÃÖ´¹)");
1694 strcat(buff, "¤È¹ï¤ó¤Ç");
1699 if (act & DONT_AUTOPICK)
1700 strcat(buff, "ÊüÃÖ¤¹¤ë¡£");
1701 else if (act & DO_AUTODESTROY)
1702 strcat(buff, "Ç˲õ¤¹¤ë¡£");
1703 else if (act & DO_QUERY_AUTOPICK)
1704 strcat(buff, "³Îǧ¤Î¸å¤Ë½¦¤¦¡£");
1706 strcat(buff, "½¦¤¦¡£");
1708 if (act & DO_DISPLAY)
1710 if (act & DONT_AUTOPICK)
1711 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'N'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
1712 else if (act & DO_AUTODESTROY)
1713 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'K'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
1715 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'M'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
1718 strcat(buff, "Á´ÂΥޥåפˤÏɽ¼¨¤·¤Ê¤¤");
1722 cptr before_str[20], after_str[20], which_str[20], whose_str[20], body_str;
1723 int before_n = 0, after_n = 0, which_n = 0, whose_n = 0;
1727 /*** Collecting items ***/
1728 /*** Which can be absorbed into a slot as a bundle ***/
1729 if (IS_FLG(FLG_COLLECTING))
1730 which_str[which_n++] = "can be absorbed into an existing inventory slot";
1732 /*** Unidentified ***/
1733 if (IS_FLG(FLG_UNIDENTIFIED))
1734 before_str[before_n++] = "unidentified";
1736 /*** Identified ***/
1737 if (IS_FLG(FLG_IDENTIFIED))
1738 before_str[before_n++] = "identified";
1740 /*** *Identified* ***/
1741 if (IS_FLG(FLG_STAR_IDENTIFIED))
1742 before_str[before_n++] = "fully identified";
1744 /*** Worthless items ***/
1745 if (IS_FLG(FLG_WORTHLESS))
1747 before_str[before_n++] = "worthless";
1748 which_str[which_n++] = "can not be sold at stores";
1752 if (IS_FLG(FLG_ARTIFACT))
1754 before_str[before_n++] = "artifact";
1758 if (IS_FLG(FLG_EGO))
1760 before_str[before_n++] = "ego";
1764 if (IS_FLG(FLG_NAMELESS))
1766 body_str = "equipment";
1767 which_str[which_n++] = "is neither ego-item nor artifact";
1770 /*** Unaware items ***/
1771 if (IS_FLG(FLG_UNAWARE))
1773 before_str[before_n++] = "unidentified";
1774 whose_str[whose_n++] = "basic abilities are not known";
1777 /*** Dice boosted (weapon of slaying) ***/
1778 if (IS_FLG(FLG_BOOSTED))
1780 body_str = "weapons";
1781 whose_str[whose_n++] = "damage dice is bigger than normal";
1784 /*** Weapons whose dd*ds is more than nn ***/
1785 if (IS_FLG(FLG_MORE_THAN))
1787 static char more_than_desc_str[] =
1788 "maximum damage from dice is bigger than __";
1789 body_str = "weapons";
1791 sprintf(more_than_desc_str + sizeof(more_than_desc_str) - 3,
1793 whose_str[whose_n++] = more_than_desc_str;
1796 /*** Items whose magical bonus is more than nn ***/
1797 if (IS_FLG(FLG_MORE_BONUS))
1799 static char more_bonus_desc_str[] =
1800 "magical bonus is bigger than (+__)";
1802 sprintf(more_bonus_desc_str + sizeof(more_bonus_desc_str) - 4,
1803 "%d)", entry->bonus);
1804 whose_str[whose_n++] = more_bonus_desc_str;
1807 /*** Wanted monster's corpse/skeletons ***/
1808 if (IS_FLG(FLG_WANTED))
1810 body_str = "corpse or skeletons";
1811 which_str[which_n++] = "is wanted at the Hunter's Office";
1814 /*** Human corpse/skeletons (for Daemon magic) ***/
1815 if (IS_FLG(FLG_HUMAN))
1817 before_str[before_n++] = "humanoid";
1818 body_str = "corpse or skeletons";
1819 which_str[which_n++] = "can be used for Daemon magic";
1822 /*** Unique monster's corpse/skeletons/statues ***/
1823 if (IS_FLG(FLG_UNIQUE))
1825 before_str[before_n++] = "unique monster's";
1826 body_str = "corpse or skeletons";
1829 /*** Unreadable spellbooks ***/
1830 if (IS_FLG(FLG_UNREADABLE))
1832 body_str = "spellbooks";
1833 after_str[after_n++] = "of different realms from yours";
1836 /*** First realm spellbooks ***/
1837 if (IS_FLG(FLG_REALM1))
1839 body_str = "spellbooks";
1840 after_str[after_n++] = "of your first realm";
1843 /*** Second realm spellbooks ***/
1844 if (IS_FLG(FLG_REALM2))
1846 body_str = "spellbooks";
1847 after_str[after_n++] = "of your second realm";
1850 /*** First rank spellbooks ***/
1851 if (IS_FLG(FLG_FIRST))
1853 before_str[before_n++] = "first one of four";
1854 body_str = "spellbooks";
1857 /*** Second rank spellbooks ***/
1858 if (IS_FLG(FLG_SECOND))
1860 before_str[before_n++] = "second one of four";
1861 body_str = "spellbooks";
1864 /*** Third rank spellbooks ***/
1865 if (IS_FLG(FLG_THIRD))
1867 before_str[before_n++] = "third one of four";
1868 body_str = "spellbooks";
1871 /*** Fourth rank spellbooks ***/
1872 if (IS_FLG(FLG_FOURTH))
1874 before_str[before_n++] = "fourth one of four";
1875 body_str = "spellbooks";
1879 if (IS_FLG(FLG_ITEMS))
1880 ; /* Nothing to do */
1881 else if (IS_FLG(FLG_WEAPONS))
1882 body_str = "weapons";
1883 else if (IS_FLG(FLG_ARMORS))
1884 body_str = "armors";
1885 else if (IS_FLG(FLG_MISSILES))
1886 body_str = "shots, arrows or crossbow bolts";
1887 else if (IS_FLG(FLG_DEVICES))
1888 body_str = "scrolls, wands, staves or rods";
1889 else if (IS_FLG(FLG_LIGHTS))
1890 body_str = "light sources";
1891 else if (IS_FLG(FLG_JUNKS))
1892 body_str = "junk such as broken sticks";
1893 else if (IS_FLG(FLG_SPELLBOOKS))
1894 body_str = "spellbooks";
1895 else if (IS_FLG(FLG_HAFTED))
1896 body_str = "hafted weapons";
1897 else if (IS_FLG(FLG_SHIELDS))
1898 body_str = "shields";
1899 else if (IS_FLG(FLG_BOWS))
1900 body_str = "slings, bows or crossbows";
1901 else if (IS_FLG(FLG_RINGS))
1903 else if (IS_FLG(FLG_AMULETS))
1904 body_str = "amulets";
1905 else if (IS_FLG(FLG_SUITS))
1906 body_str = "body armors";
1907 else if (IS_FLG(FLG_CLOAKS))
1908 body_str = "cloaks";
1909 else if (IS_FLG(FLG_HELMS))
1910 body_str = "helms or crowns";
1911 else if (IS_FLG(FLG_GLOVES))
1912 body_str = "gloves";
1913 else if (IS_FLG(FLG_BOOTS))
1915 else if (IS_FLG(FLG_FAVORITE))
1916 body_str = "favorite weapons";
1918 /* Prepare a string for item name */
1925 whose_str[whose_n++] = "name is beginning with \"";
1928 which_str[which_n++] = "have \"";
1932 /* Describe action flag */
1933 if (act & DONT_AUTOPICK)
1934 strcpy(buff, "Leave on floor ");
1935 else if (act & DO_AUTODESTROY)
1936 strcpy(buff, "Destroy ");
1937 else if (act & DO_QUERY_AUTOPICK)
1938 strcpy(buff, "Ask to pick up ");
1940 strcpy(buff, "Pickup ");
1942 /* Auto-insctiption */
1945 strncat(buff, format("and inscribe \"%s\"", insc), 80);
1947 if (strstr(insc, "%all"))
1948 strcat(buff, ", replacing %all with code string representing all abilities,");
1949 else if (strstr(insc, "%"))
1950 strcat(buff, ", replacing % with code string representing extra random abilities,");
1952 strcat(buff, " on ");
1957 strcat(buff, "all ");
1958 else for (i = 0; i < before_n && before_str[i]; i++)
1960 strcat(buff, before_str[i]);
1965 strcat(buff, body_str);
1968 for (i = 0; i < after_n && after_str[i]; i++)
1971 strcat(buff, after_str[i]);
1975 for (i = 0; i < whose_n && whose_str[i]; i++)
1978 strcat(buff, " whose ");
1980 strcat(buff, ", and ");
1982 strcat(buff, whose_str[i]);
1985 /* Item name ; whose name is beginning with "str" */
1992 /* whose ..., and which .... */
1993 if (whose_n && which_n)
1994 strcat(buff, ", and ");
1997 for (i = 0; i < which_n && which_str[i]; i++)
2000 strcat(buff, " which ");
2002 strcat(buff, ", and ");
2004 strcat(buff, which_str[i]);
2007 /* Item name ; which have "str" as part of its name */
2010 strncat(buff, str, 80);
2011 strcat(buff, "\" as part of its name");
2015 /* Describe whether it will be displayed on the full map or not */
2016 if (act & DO_DISPLAY)
2018 if (act & DONT_AUTOPICK)
2019 strcat(buff, " Display these items when you press the N key in the full 'M'ap.");
2020 else if (act & DO_AUTODESTROY)
2021 strcat(buff, " Display these items when you press the K key in the full 'M'ap.");
2023 strcat(buff, " Display these items when you press the M key in the full 'M'ap.");
2026 strcat(buff, " Not displayed in the full map.");
2033 * Read whole lines of a file to memory
2035 static cptr *read_text_lines(cptr filename, bool user)
2037 cptr *lines_list = NULL;
2045 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2049 path_build(buf, sizeof(buf), ANGBAND_DIR_PREF, filename);
2053 fff = my_fopen(buf, "r");
2057 /* Allocate list of pointers */
2058 C_MAKE(lines_list, MAX_LINES, cptr);
2061 while (0 == my_fgets(fff, buf, sizeof(buf)))
2063 lines_list[lines++] = string_make(buf);
2064 if (lines >= MAX_LINES - 1) break;
2067 lines_list[0] = string_make("");
2072 if (!fff) return NULL;
2077 #define PT_DEFAULT 0
2078 #define PT_WITH_PNAME 1
2080 static cptr *read_pickpref_text_lines(int *filename_mode_p)
2086 sprintf(buf, "picktype-%s.prf", player_name);
2088 sprintf(buf, "pickpref-%s.prf", player_name);
2090 lines_list = read_text_lines(buf, TRUE);
2095 lines_list = read_text_lines("picktype.prf", TRUE);
2097 lines_list = read_text_lines("pickpref.prf", TRUE);
2099 *filename_mode_p = PT_DEFAULT;
2105 lines_list = read_text_lines("picktype.prf", FALSE);
2107 lines_list = read_text_lines("pickpref.prf", FALSE);
2109 *filename_mode_p = PT_WITH_PNAME;
2114 /* Allocate list of pointers */
2115 C_MAKE(lines_list, MAX_LINES, cptr);
2116 lines_list[0] = string_make("");
2117 *filename_mode_p = PT_WITH_PNAME;
2124 * Write whole lines of memory to a file.
2126 static bool write_text_lines(cptr filename, cptr *lines_list)
2133 /* Build the filename */
2134 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
2137 fff = my_fopen(buf, "w");
2140 for (lines = 0; lines_list[lines]; lines++)
2141 my_fputs(fff, lines_list[lines], 1024);
2146 if (!fff) return FALSE;
2152 * Free memory of lines_list.
2154 static void free_text_lines(cptr *lines_list)
2158 for (lines = 0; lines_list[lines]; lines++)
2159 string_free(lines_list[lines]);
2161 /* free list of pointers */
2162 C_FREE((char **)lines_list, MAX_LINES, char *);
2167 * Delete or insert string
2169 static void toggle_keyword(text_body_type *tb, int flg)
2171 int by1, by2, bx1, bx2, y;
2175 /* Select this line */
2182 if (tb->my < tb->cy)
2197 /* String on these lines are not really selected */
2198 if (tb->lines_list[by1][bx1] == '\0' && by1 < tb->cy) by1++;
2199 if (bx2 == 0 && by1 < by2) by2--;
2202 /* Set/Reset flag of each line */
2203 for (y = by1; y <= by2; y++)
2205 autopick_type an_entry, *entry = &an_entry;
2207 if (!autopick_new_entry(entry, tb->lines_list[y], !fixed)) continue;
2209 string_free(tb->lines_list[y]);
2213 /* Add? or Remove? */
2214 if (!IS_FLG(flg)) add = TRUE;
2217 /* No more change */
2221 /* You can use only one noun flag */
2222 if (FLG_NOUN_BEGIN <= flg && flg <= FLG_NOUN_END)
2225 for (i = FLG_NOUN_BEGIN; i <= FLG_NOUN_END; i++)
2229 /* You can use only one identify state flag */
2230 else if (FLG_UNAWARE <= flg && flg <= FLG_STAR_IDENTIFIED)
2233 for (i = FLG_UNAWARE; i <= FLG_STAR_IDENTIFIED; i++)
2237 /* You can use only one flag in artifact/ego/nameless */
2238 else if (FLG_ARTIFACT <= flg && flg <= FLG_NAMELESS)
2241 for (i = FLG_ARTIFACT; i <= FLG_NAMELESS; i++)
2245 if (add) ADD_FLG(flg);
2248 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
2251 tb->dirty_flags |= DIRTY_ALL;
2257 * Change command letter
2259 static void toggle_command_letter(text_body_type *tb, byte flg)
2261 autopick_type an_entry, *entry = &an_entry;
2262 int by1, by2, bx1, bx2, y;
2266 /* Select this line */
2273 if (tb->my < tb->cy)
2288 /* String on these lines are not really selected */
2289 if (tb->lines_list[by1][bx1] == '\0' && by1 < tb->cy) by1++;
2290 if (bx2 == 0 && by1 < by2) by2--;
2292 /* Set/Reset flag of each line */
2293 for (y = by1; y <= by2; y++)
2297 if (!autopick_new_entry(entry, tb->lines_list[y], FALSE)) continue;
2299 string_free(tb->lines_list[y]);
2303 /* Add? or Remove? */
2304 if (!(entry->action & flg)) add = TRUE;
2307 /* No more change */
2311 /* Count number of letter (by negative number) */
2312 if (entry->action & DONT_AUTOPICK) wid--;
2313 else if (entry->action & DO_AUTODESTROY) wid--;
2314 else if (entry->action & DO_QUERY_AUTOPICK) wid--;
2315 if (!(entry->action & DO_DISPLAY)) wid--;
2317 /* Set/Reset the flag */
2318 if (flg != DO_DISPLAY)
2320 entry->action &= ~(DO_AUTOPICK | DONT_AUTOPICK | DO_AUTODESTROY | DO_QUERY_AUTOPICK);
2321 if (add) entry->action |= flg;
2322 else entry->action |= DO_AUTOPICK;
2326 entry->action &= ~(DO_DISPLAY);
2327 if (add) entry->action |= flg;
2330 /* Correct cursor location */
2333 if (entry->action & DONT_AUTOPICK) wid++;
2334 else if (entry->action & DO_AUTODESTROY) wid++;
2335 else if (entry->action & DO_QUERY_AUTOPICK) wid++;
2336 if (!(entry->action & DO_DISPLAY)) wid++;
2338 if (wid > 0) tb->cx++;
2339 if (wid < 0 && tb->cx > 0) tb->cx--;
2342 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
2345 tb->dirty_flags |= DIRTY_ALL;
2350 * Delete or insert string
2352 static void add_keyword(text_body_type *tb, int flg)
2354 int by1, by2, bx1, bx2, y;
2356 /* Select this line */
2363 if (tb->my < tb->cy)
2378 /* String on these lines are not really selected */
2379 if (tb->lines_list[by1][bx1] == '\0' && by1 < tb->cy) by1++;
2380 if (bx2 == 0 && by1 < by2) by2--;
2382 /* Set/Reset flag of each line */
2383 for (y = by1; y <= by2; y++)
2385 autopick_type an_entry, *entry = &an_entry;
2387 if (!autopick_new_entry(entry, tb->lines_list[y], FALSE)) continue;
2389 /* There is the flag already */
2392 /* Free memory for the entry */
2393 autopick_free_entry(entry);
2398 string_free(tb->lines_list[y]);
2400 /* Remove all noun flag */
2401 if (FLG_NOUN_BEGIN <= flg && flg <= FLG_NOUN_END)
2404 for (i = FLG_NOUN_BEGIN; i <= FLG_NOUN_END; i++)
2410 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
2413 tb->dirty_flags |= DIRTY_ALL;
2419 * Check if this line is expression or not.
2420 * And update it if it is.
2422 static void check_expression_line(text_body_type *tb, int y)
2424 cptr s = tb->lines_list[y];
2426 if ((s[0] == '?' && s[1] == ':') ||
2427 (tb->states[y] & LSTAT_BYPASS))
2429 /* Expressions need re-evaluation */
2430 tb->dirty_flags |= DIRTY_EXPRESSION;
2436 * Insert return code and split the line
2438 static bool insert_return_code(text_body_type *tb)
2440 char buf[MAX_LINELEN];
2443 for (k = 0; tb->lines_list[k]; k++)
2444 /* count number of lines */ ;
2446 if (k >= MAX_LINES - 2) return FALSE;
2449 /* Move down lines */
2450 for (; tb->cy < k; k--)
2452 tb->lines_list[k+1] = tb->lines_list[k];
2453 tb->states[k+1] = tb->states[k];
2456 /* Split current line */
2457 for (i = j = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
2460 if (iskanji(tb->lines_list[tb->cy][i]))
2461 buf[j++] = tb->lines_list[tb->cy][i++];
2463 buf[j++] = tb->lines_list[tb->cy][i];
2466 tb->lines_list[tb->cy+1] = string_make(&tb->lines_list[tb->cy][i]);
2467 string_free(tb->lines_list[tb->cy]);
2468 tb->lines_list[tb->cy] = string_make(buf);
2470 /* Expressions need re-evaluation */
2471 tb->dirty_flags |= DIRTY_EXPRESSION;
2478 * Get auto-picker entry from o_ptr.
2480 void autopick_entry_from_object(autopick_type *entry, object_type *o_ptr)
2482 char o_name[MAX_NLEN];
2483 object_desc(o_name, o_ptr, FALSE, 0);
2485 entry->name = string_make(o_name);
2486 entry->insc = string_make(quark_str(o_ptr->inscription));
2487 entry->action = DO_AUTOPICK | DO_DISPLAY;
2488 entry->flag[0] = entry->flag[1] = 0L;
2491 if (!object_aware_p(o_ptr))
2492 ADD_FLG(FLG_UNAWARE);
2493 if (object_value(o_ptr) <= 0)
2494 ADD_FLG(FLG_WORTHLESS);
2496 if (object_known_p(o_ptr))
2500 else if (o_ptr->name1 || o_ptr->art_name)
2501 ADD_FLG(FLG_ARTIFACT);
2507 case TV_HAFTED: case TV_POLEARM: case TV_SWORD: case TV_DIGGING:
2508 k_ptr = &k_info[o_ptr->k_idx];
2509 if ((o_ptr->dd != k_ptr->dd) || (o_ptr->ds != k_ptr->ds))
2510 ADD_FLG(FLG_BOOSTED);
2513 if (o_ptr->tval == TV_CORPSE && object_is_shoukinkubi(o_ptr))
2515 REM_FLG(FLG_WORTHLESS);
2516 ADD_FLG(FLG_WANTED);
2519 if ((o_ptr->tval == TV_CORPSE || o_ptr->tval == TV_STATUE)
2520 && (r_info[o_ptr->pval].flags1 & RF1_UNIQUE))
2522 REM_FLG(FLG_WORTHLESS);
2523 ADD_FLG(FLG_UNIQUE);
2526 if (o_ptr->tval == TV_CORPSE && strchr("pht", r_info[o_ptr->pval].d_char))
2528 REM_FLG(FLG_WORTHLESS);
2532 if (o_ptr->tval >= TV_LIFE_BOOK &&
2533 !check_book_realm(o_ptr->tval, o_ptr->sval))
2534 ADD_FLG(FLG_UNREADABLE);
2536 if (REALM1_BOOK == o_ptr->tval &&
2537 p_ptr->pclass != CLASS_SORCERER &&
2538 p_ptr->pclass != CLASS_RED_MAGE)
2539 ADD_FLG(FLG_REALM1);
2541 if (REALM2_BOOK == o_ptr->tval &&
2542 p_ptr->pclass != CLASS_SORCERER &&
2543 p_ptr->pclass != CLASS_RED_MAGE)
2544 ADD_FLG(FLG_REALM2);
2546 if (o_ptr->tval >= TV_LIFE_BOOK && 0 == o_ptr->sval)
2548 if (o_ptr->tval >= TV_LIFE_BOOK && 1 == o_ptr->sval)
2549 ADD_FLG(FLG_SECOND);
2550 if (o_ptr->tval >= TV_LIFE_BOOK && 2 == o_ptr->sval)
2552 if (o_ptr->tval >= TV_LIFE_BOOK && 3 == o_ptr->sval)
2553 ADD_FLG(FLG_FOURTH);
2555 if (o_ptr->tval == TV_SHOT || o_ptr->tval == TV_BOLT
2556 || o_ptr->tval == TV_ARROW)
2557 ADD_FLG(FLG_MISSILES);
2558 else if (o_ptr->tval == TV_SCROLL || o_ptr->tval == TV_STAFF
2559 || o_ptr->tval == TV_WAND || o_ptr->tval == TV_ROD)
2560 ADD_FLG(FLG_DEVICES);
2561 else if (o_ptr->tval == TV_LITE)
2562 ADD_FLG(FLG_LIGHTS);
2563 else if (o_ptr->tval == TV_SKELETON || o_ptr->tval == TV_BOTTLE
2564 || o_ptr->tval == TV_JUNK || o_ptr->tval == TV_STATUE)
2566 else if (o_ptr->tval >= TV_LIFE_BOOK)
2567 ADD_FLG(FLG_SPELLBOOKS);
2568 else if (is_favorite(o_ptr, FALSE))
2569 ADD_FLG(FLG_FAVORITE);
2570 else if (o_ptr->tval == TV_POLEARM || o_ptr->tval == TV_SWORD
2571 || o_ptr->tval == TV_DIGGING || o_ptr->tval == TV_HAFTED)
2572 ADD_FLG(FLG_WEAPONS);
2573 else if (o_ptr->tval == TV_SHIELD)
2574 ADD_FLG(FLG_SHIELDS);
2575 else if (o_ptr->tval == TV_BOW)
2577 else if (o_ptr->tval == TV_RING)
2579 else if (o_ptr->tval == TV_AMULET)
2580 ADD_FLG(FLG_AMULETS);
2581 else if (o_ptr->tval == TV_DRAG_ARMOR || o_ptr->tval == TV_HARD_ARMOR ||
2582 o_ptr->tval == TV_SOFT_ARMOR)
2584 else if (o_ptr->tval == TV_CLOAK)
2585 ADD_FLG(FLG_CLOAKS);
2586 else if (o_ptr->tval == TV_HELM)
2588 else if (o_ptr->tval == TV_GLOVES)
2589 ADD_FLG(FLG_GLOVES);
2590 else if (o_ptr->tval == TV_BOOTS)
2598 * Choose an item and get auto-picker entry from it.
2600 static object_type *choose_object(cptr q, cptr s)
2604 if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR | USE_EQUIP))) return NULL;
2606 /* Get the item (in the pack) */
2607 if (item >= 0) return &inventory[item];
2609 /* Get the item (on the floor) */
2610 else return &o_list[0 - item];
2615 * Choose an item and get auto-picker entry from it.
2617 static bool entry_from_choosed_object(autopick_type *entry)
2624 q = "¤É¤Î¥¢¥¤¥Æ¥à¤òÅÐÏ¿¤·¤Þ¤¹¤«? ";
2625 s = "¥¢¥¤¥Æ¥à¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£";
2627 q = "Enter which item? ";
2628 s = "You have nothing to enter.";
2630 o_ptr = choose_object(q, s);
2631 if (!o_ptr) return FALSE;
2633 autopick_entry_from_object(entry, o_ptr);
2639 * Choose an item for search
2641 static byte get_object_for_search(object_type **o_handle, cptr *search_strp)
2643 char buf[MAX_NLEN+20];
2649 q = "¤É¤Î¥¢¥¤¥Æ¥à¤ò¸¡º÷¤·¤Þ¤¹¤«? ";
2650 s = "¥¢¥¤¥Æ¥à¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£";
2652 q = "Enter which item? ";
2653 s = "You have nothing to enter.";
2655 o_ptr = choose_object(q, s);
2656 if (!o_ptr) return 0;
2660 string_free(*search_strp);
2661 object_desc(buf, *o_handle, FALSE, 3);
2662 *search_strp = string_make(format("<%s>", buf));
2668 * Prepare for search by destroyed object
2670 static byte get_destroyed_object_for_search(object_type **o_handle, cptr *search_strp)
2672 char buf[MAX_NLEN+20];
2674 if (!autopick_last_destroyed_object.k_idx) return 0;
2676 *o_handle = &autopick_last_destroyed_object;
2678 string_free(*search_strp);
2679 object_desc(buf, *o_handle, FALSE, 3);
2680 *search_strp = string_make(format("<%s>", buf));
2686 * Choose an item or string for search
2688 static byte get_string_for_search(object_type **o_handle, cptr *search_strp)
2691 char buf[MAX_NLEN+20];
2694 int k_flag[MAX_NLEN+20];
2695 char prompt[] = "¸¡º÷(^I:»ý¤Áʪ ^L:Ç˲õ¤µ¤ì¤¿Êª): ";
2697 char prompt[] = "Search key(^I:inven ^L:destroyed): ";
2699 int col = sizeof(prompt) - 1;
2701 if (*search_strp) strcpy(buf, *search_strp);
2704 /* Display prompt */
2707 /* Display the default answer */
2708 Term_erase(col, 0, 255);
2709 Term_putstr(col, 0, -1, TERM_YELLOW, buf);
2719 Term_gotoxy(col + pos, 0);
2724 /* Count length of macro trigger which induced this key */
2725 trig_len = strlen(inkey_macro_trigger_string);
2727 /* HACK -- ignore macro defined on ASCII keys */
2730 /* Get original key */
2731 key = inkey_macro_trigger_string[0];
2733 /* Kill further macro expansion */
2738 if (key == 0x7F) key = KTRL('d');
2741 /* Analyze the key */
2754 if (!pos && *o_handle) return (back ? -1 : 1);
2755 string_free(*search_strp);
2756 *search_strp = string_make(buf);
2758 return (back ? -1 : 1);
2762 return get_object_for_search(o_handle, search_strp);
2765 /* Prepare string for destroyed object if there is one. */
2766 if (get_destroyed_object_for_search(o_handle, search_strp))
2776 if (k_flag[pos]) pos--;
2791 if (pos + 1 < MAX_NLEN)
2799 else if (pos < MAX_NLEN && isprint(key))
2806 if (pos < MAX_NLEN && isprint(key)) buf[pos++] = key;
2815 /* Update the entry */
2816 Term_erase(col, 0, 255);
2817 Term_putstr(col, 0, -1, TERM_WHITE, buf);
2825 * Search next line matches for o_ptr
2827 static bool search_for_object(text_body_type *tb, object_type *o_ptr, bool forward)
2830 autopick_type an_entry, *entry = &an_entry;
2831 char o_name[MAX_NLEN];
2833 object_desc(o_name, o_ptr, FALSE, 3);
2835 /* Force to be lower case string */
2836 for (i = 0; o_name[i]; i++)
2839 if (iskanji(o_name[i]))
2843 if (isupper(o_name[i]))
2844 o_name[i] = tolower(o_name[i]);
2853 if (!tb->lines_list[++i]) break;
2860 /* Ignore bypassed lines */
2861 if (tb->states[i] & LSTAT_BYPASS) continue;
2863 if (!autopick_new_entry(entry, tb->lines_list[i], FALSE)) continue;
2865 if (is_autopick_aux(o_ptr, entry, o_name))
2878 * Search next line matches to the string
2880 static bool search_for_string(text_body_type *tb, cptr search_str, bool forward)
2890 if (!tb->lines_list[++i]) break;
2897 /* Ignore bypassed lines */
2898 if (tb->states[i] & LSTAT_BYPASS) continue;
2901 pos = strstr_j(tb->lines_list[i], search_str);
2903 pos = strstr(tb->lines_list[i], search_str);
2907 tb->cx = (int)(pos - tb->lines_list[i]);
2920 * Editor command id's
2933 #define EC_PGDOWN 12
2935 #define EC_BOTTOM 14
2940 #define EC_KILL_LINE 19
2941 #define EC_DELETE_CHAR 20
2942 #define EC_BACKSPACE 21
2943 #define EC_SEARCH_STR 22
2944 #define EC_SEARCH_FORW 23
2945 #define EC_SEARCH_BACK 24
2946 #define EC_SEARCH_OBJ 25
2947 #define EC_SEARCH_DESTROYED 26
2948 #define EC_INSERT_OBJECT 27
2949 #define EC_INSERT_DESTROYED 28
2950 #define EC_INSERT_BLOCK 29
2951 #define EC_INSERT_MACRO 30
2952 #define EC_INSERT_KEYMAP 31
2953 #define EC_CL_AUTOPICK 32
2954 #define EC_CL_DESTROY 33
2955 #define EC_CL_LEAVE 34
2956 #define EC_CL_QUERY 35
2957 #define EC_CL_NO_DISP 36
2958 #define EC_OK_COLLECTING 37
2959 #define EC_IK_UNAWARE 38
2960 #define EC_IK_UNIDENTIFIED 39
2961 #define EC_IK_IDENTIFIED 40
2962 #define EC_IK_STAR_IDENTIFIED 41
2963 #define EC_OK_BOOSTED 42
2964 #define EC_OK_MORE_THAN 43
2965 #define EC_OK_MORE_BONUS 44
2966 #define EC_OK_WORTHLESS 45
2967 #define EC_OK_ARTIFACT 46
2968 #define EC_OK_EGO 47
2969 #define EC_OK_NAMELESS 48
2970 #define EC_OK_WANTED 49
2971 #define EC_OK_UNIQUE 50
2972 #define EC_OK_HUMAN 51
2973 #define EC_OK_UNREADABLE 52
2974 #define EC_OK_REALM1 53
2975 #define EC_OK_REALM2 54
2976 #define EC_OK_FIRST 55
2977 #define EC_OK_SECOND 56
2978 #define EC_OK_THIRD 57
2979 #define EC_OK_FOURTH 58
2980 #define EC_KK_WEAPONS 59
2981 #define EC_KK_FAVORITE 60
2982 #define EC_KK_ARMORS 61
2983 #define EC_KK_MISSILES 62
2984 #define EC_KK_DEVICES 63
2985 #define EC_KK_LIGHTS 64
2986 #define EC_KK_JUNKS 65
2987 #define EC_KK_SPELLBOOKS 66
2988 #define EC_KK_SHIELDS 67
2989 #define EC_KK_BOWS 68
2990 #define EC_KK_RINGS 69
2991 #define EC_KK_AMULETS 70
2992 #define EC_KK_SUITS 71
2993 #define EC_KK_CLOAKS 72
2994 #define EC_KK_HELMS 73
2995 #define EC_KK_GLOVES 74
2996 #define EC_KK_BOOTS 75
3002 #define MN_QUIT "¥»¡¼¥Ö¤·¤Æ½ªÎ»"
3003 #define MN_REVERT "Á´¤Æ¤ÎÊѹ¹¤òÇË´þ"
3004 #define MN_HELP "¥Ø¥ë¥×"
3006 #define MN_MOVE "¥«¡¼¥½¥ë°ÜÆ°"
3007 #define MN_LEFT "º¸"
3008 #define MN_DOWN "²¼"
3010 #define MN_RIGHT "±¦"
3011 #define MN_BOL "¹Ô¤ÎÀèƬ"
3012 #define MN_EOL "¹Ô¤Î½ªÃ¼"
3013 #define MN_PGUP "¾å¤Î¥Ú¡¼¥¸"
3014 #define MN_PGDOWN "²¼¤Î¥Ú¡¼¥¸"
3015 #define MN_TOP "1¹ÔÌܤذÜÆ°"
3016 #define MN_BOTTOM "ºÇ²¼¹Ô¤Ø°ÜÆ°"
3018 #define MN_EDIT "ÊÔ½¸"
3019 #define MN_CUT "¥«¥Ã¥È"
3020 #define MN_COPY "¥³¥Ô¡¼"
3021 #define MN_PASTE "¥Ú¡¼¥¹¥È"
3022 #define MN_BLOCK "ÁªÂòÈϰϤλØÄê"
3023 #define MN_KILL_LINE "¹Ô¤Î»Ä¤ê¤òºï½ü"
3024 #define MN_DELETE_CHAR "1ʸ»úºï½ü"
3025 #define MN_BACKSPACE "¥Ð¥Ã¥¯¥¹¥Ú¡¼¥¹"
3026 #define MN_RETURN "²þ¹Ô"
3027 #define MN_RETURN "²þ¹Ô"
3029 #define MN_SEARCH "¸¡º÷"
3030 #define MN_SEARCH_STR "ʸ»úÎó¤Ç¸¡º÷"
3031 #define MN_SEARCH_FORW "Á°Êý¤ØºÆ¸¡º÷"
3032 #define MN_SEARCH_BACK "¸åÊý¤ØºÆ¸¡º÷"
3033 #define MN_SEARCH_OBJ "¥¢¥¤¥Æ¥à¤òÁªÂò¤·¤Æ¸¡º÷"
3034 #define MN_SEARCH_DESTROYED "¼«Æ°Ç˲õ¤µ¤ì¤¿¥¢¥¤¥Æ¥à¤Ç¸¡º÷"
3036 #define MN_INSERT "¿§¡¹ÁÞÆþ"
3037 #define MN_INSERT_OBJECT "ÁªÂò¤·¤¿¥¢¥¤¥Æ¥à¤Î̾Á°¤òÁÞÆþ"
3038 #define MN_INSERT_DESTROYED "¼«Æ°Ç˲õ¤µ¤ì¤¿¥¢¥¤¥Æ¥à¤Î̾Á°¤òÁÞÆþ"
3039 #define MN_INSERT_BLOCK "¾ò·ïʬ´ô¥Ö¥í¥Ã¥¯¤ÎÎã¤òÁÞÆþ"
3040 #define MN_INSERT_MACRO "¥Þ¥¯¥íÄêµÁ¤òÁÞÆþ"
3041 #define MN_INSERT_KEYMAP "¥¡¼¥Þ¥Ã¥×ÄêµÁ¤òÁÞÆþ"
3043 #define MN_COMMAND_LETTER "½¦¤¤/Ç˲õ/ÊüÃÖ¤ÎÁªÂò"
3044 #define MN_CL_AUTOPICK "¡Ö ¡× (¼«Æ°½¦¤¤)"
3045 #define MN_CL_DESTROY "¡Ö!¡× (¼«Æ°Ç˲õ)"
3046 #define MN_CL_LEAVE "¡Ö~¡× (ÊüÃÖ)"
3047 #define MN_CL_QUERY "¡Ö;¡× (³Îǧ¤·¤Æ½¦¤¦)"
3048 #define MN_CL_NO_DISP "¡Ö(¡× (¥Þ¥Ã¥×¥³¥Þ¥ó¥É¤Çɽ¼¨¤·¤Ê¤¤)"
3050 #define MN_ADJECTIVE_GEN "·ÁÍÆ»ì(°ìÈÌ)¤ÎÁªÂò"
3052 #define MN_ADJECTIVE_SPECIAL "·ÁÍÆ»ì(Æüì)¤ÎÁªÂò"
3053 #define MN_BOOSTED "¥À¥¤¥¹Ìܤΰ㤦 (Éð´ï)"
3054 #define MN_MORE_THAN "¥À¥¤¥¹ÌÜ # °Ê¾å¤Î (Éð´ï)"
3055 #define MN_MORE_BONUS "½¤ÀµÃÍ # °Ê¾å¤Î (»ØÎØÅù)"
3056 #define MN_ARTIFACT "¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È (ÁõÈ÷)"
3057 #define MN_EGO "¥¨¥´ (ÁõÈ÷)"
3058 #define MN_NAMELESS "̵ÌäΠ(ÁõÈ÷)"
3059 #define MN_WANTED "¾Þ¶â¼ó¤Î (»àÂÎ)"
3060 #define MN_UNIQUE "¥æ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼¤Î (»àÂÎ)"
3061 #define MN_HUMAN "¿Í´Ö¤Î (»àÂÎ)"
3062 #define MN_UNREADABLE "Æɤá¤Ê¤¤ (ËâË¡½ñ)"
3063 #define MN_REALM1 "Âè°ìÎΰè¤Î (ËâË¡½ñ)"
3064 #define MN_REALM2 "ÂèÆóÎΰè¤Î (ËâË¡½ñ)"
3065 #define MN_FIRST "1ºýÌܤΠ(ËâË¡½ñ)"
3066 #define MN_SECOND "2ºýÌܤΠ(ËâË¡½ñ)"
3067 #define MN_THIRD "3ºýÌܤΠ(ËâË¡½ñ)"
3068 #define MN_FOURTH "4ºýÌܤΠ(ËâË¡½ñ)"
3070 #define MN_NOUN "̾»ì¤ÎÁªÂò"
3074 #define MN_QUIT "Save & Quit"
3075 #define MN_REVERT "Revert all changes"
3076 #define MN_HELP "Help"
3078 #define MN_MOVE "Move cursor"
3079 #define MN_LEFT "Left"
3080 #define MN_DOWN "Down"
3082 #define MN_RIGHT "Right"
3083 #define MN_BOL "Beggining of line"
3084 #define MN_EOL "End of line"
3085 #define MN_PGUP "Page up"
3086 #define MN_PGDOWN "Page down"
3087 #define MN_TOP "Top"
3088 #define MN_BOTTOM "Bottom"
3090 #define MN_EDIT "Edit"
3091 #define MN_CUT "Cut"
3092 #define MN_COPY "Copy"
3093 #define MN_PASTE "Paste"
3094 #define MN_BLOCK "Select block"
3095 #define MN_KILL_LINE "Kill rest of line"
3096 #define MN_DELETE_CHAR "Delete character"
3097 #define MN_BACKSPACE "Backspace"
3098 #define MN_RETURN "Return"
3099 #define MN_RETURN "Return"
3101 #define MN_SEARCH "Search"
3102 #define MN_SEARCH_STR "Search by string"
3103 #define MN_SEARCH_FORW "Search forward"
3104 #define MN_SEARCH_BACK "Search backward"
3105 #define MN_SEARCH_OBJ "Search by inventory object"
3106 #define MN_SEARCH_DESTROYED "Search by destroyed object"
3108 #define MN_INSERT "Insert..."
3109 #define MN_INSERT_OBJECT "Insert name of choosen object"
3110 #define MN_INSERT_DESTROYED "Insert name of destroyed object"
3111 #define MN_INSERT_BLOCK "Insert conditional block"
3112 #define MN_INSERT_MACRO "Insert a macro definition"
3113 #define MN_INSERT_KEYMAP "Insert a keymap definition"
3115 #define MN_COMMAND_LETTER "Command letter"
3116 #define MN_CL_AUTOPICK "' ' (Auto pick)"
3117 #define MN_CL_DESTROY "'!' (Auto destroy)"
3118 #define MN_CL_LEAVE "'~' (Leave it on the floor)"
3119 #define MN_CL_QUERY "';' (Query to pick up)"
3120 #define MN_CL_NO_DISP "'(' (No display on the large map)"
3122 #define MN_ADJECTIVE_GEN "Adjective (general)"
3124 #define MN_ADJECTIVE_SPECIAL "Adjective (special)"
3125 #define MN_BOOSTED "dice boosted (weapons)"
3126 #define MN_MORE_THAN "more than # dice (weapons)"
3127 #define MN_MORE_BONUS "more bonus than # (rings etc.)"
3128 #define MN_ARTIFACT "artifact (equipments)"
3129 #define MN_EGO "ego (equipments)"
3130 #define MN_NAMELESS "nameless (equipments)"
3131 #define MN_WANTED "wanted (corpse)"
3132 #define MN_UNIQUE "unique (corpse)"
3133 #define MN_HUMAN "human (corpse)"
3134 #define MN_UNREADABLE "unreadable (spellbooks)"
3135 #define MN_REALM1 "realm1 (spellbooks)"
3136 #define MN_REALM2 "realm2 (spellbooks)"
3137 #define MN_FIRST "first (spellbooks)"
3138 #define MN_SECOND "second (spellbooks)"
3139 #define MN_THIRD "third (spellbooks)"
3140 #define MN_FOURTH "fourth (spellbooks)"
3142 #define MN_NOUN "Keywords (noun)"
3152 } command_menu_type;
3155 command_menu_type menu_data[] =
3157 {MN_QUIT, 0, KTRL('q'), EC_QUIT},
3158 {MN_REVERT, 0, KTRL('z'), EC_REVERT},
3159 {MN_HELP, 0, -1, EC_HELP},
3161 {MN_MOVE, 0, -1, -1},
3162 {MN_LEFT, 1, KTRL('b'), EC_LEFT},
3163 {MN_DOWN, 1, KTRL('n'), EC_DOWN},
3164 {MN_UP, 1, KTRL('p'), EC_UP},
3165 {MN_RIGHT, 1, KTRL('f'), EC_RIGHT},
3166 {MN_BOL, 1, KTRL('a'), EC_BOL},
3167 {MN_EOL, 1, KTRL('e'), EC_EOL},
3168 {MN_PGUP, 1, KTRL('o'), EC_PGUP},
3169 {MN_PGDOWN, 1, KTRL('l'), EC_PGDOWN},
3170 {MN_TOP, 1, KTRL('y'), EC_TOP},
3171 {MN_BOTTOM, 1, KTRL('u'), EC_BOTTOM},
3173 {MN_EDIT, 0, -1, -1},
3174 {MN_CUT, 1, KTRL('x'), EC_CUT},
3175 {MN_COPY, 1, KTRL('c'), EC_COPY},
3176 {MN_PASTE, 1, KTRL('v'), EC_PASTE},
3177 {MN_BLOCK, 1, KTRL('g'), EC_BLOCK},
3178 {MN_KILL_LINE, 1, KTRL('k'), EC_KILL_LINE},
3179 {MN_DELETE_CHAR, 1, KTRL('d'), EC_DELETE_CHAR},
3180 {MN_BACKSPACE, 1, KTRL('h'), EC_BACKSPACE},
3181 {MN_RETURN, 1, KTRL('j'), EC_RETURN},
3182 {MN_RETURN, 1, KTRL('m'), EC_RETURN},
3184 {MN_SEARCH, 0, -1, -1},
3185 {MN_SEARCH_STR, 1, KTRL('s'), EC_SEARCH_STR},
3186 {MN_SEARCH_FORW, 1, -1, EC_SEARCH_FORW},
3187 {MN_SEARCH_BACK, 1, KTRL('r'), EC_SEARCH_BACK},
3188 {MN_SEARCH_OBJ, 1, -1, EC_SEARCH_OBJ},
3189 {MN_SEARCH_DESTROYED, 1, -1, EC_SEARCH_DESTROYED},
3191 {MN_INSERT, 0, -1, -1},
3192 {MN_INSERT_OBJECT, 1, KTRL('i'), EC_INSERT_OBJECT},
3193 {MN_INSERT_DESTROYED, 1, -1, EC_INSERT_DESTROYED},
3194 {MN_INSERT_BLOCK, 1, -1, EC_INSERT_BLOCK},
3195 {MN_INSERT_MACRO, 1, -1, EC_INSERT_MACRO},
3196 {MN_INSERT_KEYMAP, 1, -1, EC_INSERT_KEYMAP},
3198 {MN_COMMAND_LETTER, 0, -1, -1},
3199 {MN_CL_AUTOPICK, 1, -1, EC_CL_AUTOPICK},
3200 {MN_CL_DESTROY, 1, -1, EC_CL_DESTROY},
3201 {MN_CL_LEAVE, 1, -1, EC_CL_LEAVE},
3202 {MN_CL_QUERY, 1, -1, EC_CL_QUERY},
3203 {MN_CL_NO_DISP, 1, -1, EC_CL_NO_DISP},
3205 {MN_ADJECTIVE_GEN, 0, -1, -1},
3206 {KEY_UNAWARE, 1, -1, EC_IK_UNAWARE},
3207 {KEY_UNIDENTIFIED, 1, -1, EC_IK_UNIDENTIFIED},
3208 {KEY_IDENTIFIED, 1, -1, EC_IK_IDENTIFIED},
3209 {KEY_STAR_IDENTIFIED, 1, -1, EC_IK_STAR_IDENTIFIED},
3210 {KEY_COLLECTING, 1, -1, EC_OK_COLLECTING},
3211 {KEY_WORTHLESS, 1, -1, EC_OK_WORTHLESS},
3213 {MN_ADJECTIVE_SPECIAL, 0, -1, -1},
3214 {MN_BOOSTED, 1, -1, EC_OK_BOOSTED},
3215 {MN_MORE_THAN, 1, -1, EC_OK_MORE_THAN},
3216 {MN_MORE_BONUS, 1, -1, EC_OK_MORE_BONUS},
3217 {MN_ARTIFACT, 1, -1, EC_OK_ARTIFACT},
3218 {MN_EGO, 1, -1, EC_OK_EGO},
3219 {MN_NAMELESS, 1, -1, EC_OK_NAMELESS},
3220 {MN_WANTED, 1, -1, EC_OK_WANTED},
3221 {MN_UNIQUE, 1, -1, EC_OK_UNIQUE},
3222 {MN_HUMAN, 1, -1, EC_OK_HUMAN},
3223 {MN_UNREADABLE, 1, -1, EC_OK_UNREADABLE},
3224 {MN_REALM1, 1, -1, EC_OK_REALM1},
3225 {MN_REALM2, 1, -1, EC_OK_REALM2},
3226 {MN_FIRST, 1, -1, EC_OK_FIRST},
3227 {MN_SECOND, 1, -1, EC_OK_SECOND},
3228 {MN_THIRD, 1, -1, EC_OK_THIRD},
3229 {MN_FOURTH, 1, -1, EC_OK_FOURTH},
3231 {MN_NOUN, 0, -1, -1},
3232 {KEY_WEAPONS, 1, -1, EC_KK_WEAPONS},
3233 {KEY_FAVORITE, 1, -1, EC_KK_FAVORITE},
3234 {KEY_ARMORS, 1, -1, EC_KK_ARMORS},
3235 {KEY_MISSILES, 1, -1, EC_KK_MISSILES},
3236 {KEY_DEVICES, 1, -1, EC_KK_DEVICES},
3237 {KEY_LIGHTS, 1, -1, EC_KK_LIGHTS},
3238 {KEY_JUNKS, 1, -1, EC_KK_JUNKS},
3239 {KEY_SPELLBOOKS, 1, -1, EC_KK_SPELLBOOKS},
3240 {KEY_SHIELDS, 1, -1, EC_KK_SHIELDS},
3241 {KEY_BOWS, 1, -1, EC_KK_BOWS},
3242 {KEY_RINGS, 1, -1, EC_KK_RINGS},
3243 {KEY_AMULETS, 1, -1, EC_KK_AMULETS},
3244 {KEY_SUITS, 1, -1, EC_KK_SUITS},
3245 {KEY_CLOAKS, 1, -1, EC_KK_CLOAKS},
3246 {KEY_HELMS, 1, -1, EC_KK_HELMS},
3247 {KEY_GLOVES, 1, -1, EC_KK_GLOVES},
3248 {KEY_BOOTS, 1, -1, EC_KK_BOOTS},
3255 * Find a command by 'key'.
3257 static int get_com_id(char key)
3261 for (i = 0; menu_data[i].name; i++)
3263 if (menu_data[i].key == key)
3265 return menu_data[i].com_id;
3274 * Display the menu, and get a command
3276 static int do_command_menu(int level, int start)
3281 int col0 = 5 + level*7;
3282 int row0 = 1 + level*3;
3284 int menu_id_list[26];
3286 char linestr[MAX_LINELEN];
3288 /* Get max length */
3290 for (i = start; menu_data[i].level >= level; i++)
3294 /* Ignore lower level sub menus */
3295 if (menu_data[i].level > level) continue;
3297 len = strlen(menu_data[i].name);
3298 if (len > max_len) max_len = len;
3300 menu_id_list[menu_key] = i;
3304 while (menu_key < 26)
3306 menu_id_list[menu_key] = -1;
3310 /* Extra space for displaying menu key and command key */
3311 max_menu_wid = max_len + 3 + 3;
3313 /* Prepare box line */
3315 strcat(linestr, "+");
3316 for (i = 0; i < max_menu_wid + 2; i++)
3318 strcat(linestr, "-");
3320 strcat(linestr, "+");
3330 int row1 = row0 + 1;
3333 Term_putstr(col0, row0, -1, TERM_WHITE, linestr);
3335 /* Draw menu items */
3337 for (i = start; menu_data[i].level >= level; i++)
3339 char com_key_str[3];
3342 /* Ignore lower level sub menus */
3343 if (menu_data[i].level > level) continue;
3345 if (menu_data[i].com_id == -1)
3348 strcpy(com_key_str, "¢§");
3350 strcpy(com_key_str, ">");
3353 else if (menu_data[i].key != -1)
3355 com_key_str[0] = '^';
3356 com_key_str[1] = menu_data[i].key + '@';
3357 com_key_str[2] = '\0';
3361 com_key_str[0] = '\0';
3364 str = format("| %c) %-*s %2s | ", menu_key + 'a', max_len, menu_data[i].name, com_key_str);
3366 Term_putstr(col0, row1++, -1, TERM_WHITE, str);
3371 /* Draw bottom line */
3372 Term_putstr(col0, row1, -1, TERM_WHITE, linestr);
3374 /* The menu was shown */
3378 prt(format("(a-%c) ¥³¥Þ¥ó¥É:", menu_key + 'a' - 1), 0, 0);
3380 prt(format("(a-%c) Command:", menu_key + 'a' - 1), 0, 0);
3384 if (key == ESCAPE) return 0;
3386 if ('a' <= key && key <= 'z')
3388 menu_id = menu_id_list[key - 'a'];
3392 com_id = menu_data[menu_id].com_id;
3396 com_id = do_command_menu(level + 1, menu_id + 1);
3398 if (com_id) return com_id;
3410 com_id = get_com_id(key);
3411 if (com_id) return com_id;
3418 static chain_str_type *new_chain_str(cptr str)
3420 chain_str_type *chain;
3422 size_t len = strlen(str);
3424 chain = (chain_str_type *)ralloc(sizeof(chain_str_type) + len * sizeof(char));
3426 strcpy(chain->s, str);
3433 static void kill_yank_chain(text_body_type *tb)
3435 chain_str_type *chain = tb->yank;
3437 tb->yank_eol = TRUE;
3441 chain_str_type *next = chain->next;
3442 size_t len = strlen(chain->s);
3444 rnfree(chain, sizeof(chain_str_type) + len * sizeof(char));
3451 static void add_str_to_yank(text_body_type *tb, cptr str)
3453 chain_str_type *chain;
3455 tb->yank_eol = FALSE;
3457 if (NULL == tb->yank)
3459 tb->yank = new_chain_str(str);
3469 chain->next = new_chain_str(str);
3474 chain = chain->next;
3479 #define DESCRIPT_HGT 3
3484 static void draw_text_editor(text_body_type *tb)
3487 int by1 = -1, bx1 = -1, by2 = -1, bx2 = -1;
3490 Term_get_size(&tb->wid, &tb->hgt);
3493 * Top line (-1), description line (-3), separator (-1)
3496 tb->hgt -= 2 + DESCRIPT_HGT;
3499 /* Don't let cursor at second byte of kanji */
3500 for (i = 0; tb->lines_list[tb->cy][i]; i++)
3501 if (iskanji(tb->lines_list[tb->cy][i]))
3512 /* Scroll if necessary */
3513 if (tb->cy < tb->upper || tb->upper + tb->hgt <= tb->cy)
3514 tb->upper = tb->cy - (tb->hgt)/2;
3517 if ((tb->cx < tb->left + 10 && tb->left > 0) || tb->left + tb->wid - 5 <= tb->cx)
3518 tb->left = tb->cx - (tb->wid)*2/3;
3522 /* Redraw whole window after resize */
3523 if (tb->old_wid != tb->wid || tb->old_hgt != tb->hgt)
3524 tb->dirty_flags |= DIRTY_SCREEN;
3526 /* Redraw all text after scroll */
3527 else if (tb->old_upper != tb->upper || tb->old_left != tb->left)
3528 tb->dirty_flags |= DIRTY_ALL;
3531 if (tb->dirty_flags & DIRTY_SCREEN)
3533 tb->dirty_flags |= (DIRTY_ALL | DIRTY_MODE);
3539 /* Redraw mode line */
3540 if (tb->dirty_flags & DIRTY_MODE)
3542 char buf[MAX_LINELEN];
3544 int sepa_length = tb->wid;
3547 for (i = 0; i < sepa_length; i++)
3551 Term_putstr(0, tb->hgt + 1, sepa_length, TERM_WHITE, buf);
3554 if (tb->dirty_flags & DIRTY_EXPRESSION)
3559 for (y = 0; tb->lines_list[y]; y++)
3563 cptr s = tb->lines_list[y];
3565 /* Update this line's state */
3566 tb->states[y] = state;
3568 if (*s++ != '?') continue;
3569 if (*s++ != ':') continue;
3571 /* Parse the expr */
3572 v = process_pref_file_expr(&s, &f);
3575 state = (streq(v, "0") ? LSTAT_BYPASS : 0);
3577 /* Re-update this line's state */
3578 tb->states[y] = state | LSTAT_EXPRESSION;
3581 tb->dirty_flags |= DIRTY_ALL;
3586 int tmp_cx = tb->cx;
3587 int len = strlen(tb->lines_list[tb->cy]);
3589 /* Correct cursor location */
3590 if (tb->cx > len) tmp_cx = len;
3592 tb->dirty_flags |= DIRTY_ALL;
3594 if (tb->my < tb->cy ||
3595 (tb->my == tb->cy && tb->mx < tmp_cx))
3611 /* Dump up to tb->hgt lines of messages */
3612 for (i = 0; i < tb->hgt; i++)
3618 int y = tb->upper+i;
3620 /* clean or dirty? */
3621 if (!(tb->dirty_flags & DIRTY_ALL) && (tb->dirty_line != y))
3624 msg = tb->lines_list[y];
3627 /* Apply horizontal scroll */
3628 for (j = 0; *msg; msg++, j++)
3630 if (j == tb->left) break;
3646 Term_erase(0, i + 1, tb->wid);
3648 /* Bypassed line will be displayed by darker color */
3649 if (tb->states[y] & LSTAT_BYPASS) color = TERM_SLATE;
3650 else color = TERM_WHITE;
3654 /* Dump the messages, bottom to top */
3655 Term_putstr(leftcol, i + 1, tb->wid - 1, color, msg);
3660 int x0 = leftcol + tb->left;
3665 if (by1 <= y && y < by2) sx1 = strlen(msg);
3666 if (y == by1) sx0 = bx1;
3667 if (y == by2) sx1 = bx2;
3669 Term_gotoxy(leftcol, i + 1);
3670 if (x0 < sx0) Term_addstr(sx0 - x0, color, msg);
3671 if (x0 < sx1) Term_addstr(sx1 - sx0, TERM_YELLOW, msg + (sx0 - x0));
3672 Term_addstr(-1, color, msg + (sx1 - x0));
3676 for (; i < tb->hgt; i++)
3679 Term_erase(0, i + 1, tb->wid);
3682 /* Display information when updated */
3683 if (tb->old_cy != tb->cy || (tb->dirty_flags & (DIRTY_ALL | DIRTY_NOT_FOUND | DIRTY_NO_SEARCH)) || tb->dirty_line == tb->cy)
3685 autopick_type an_entry, *entry = &an_entry;
3687 /* Clear information line */
3688 for (i = 0; i < DESCRIPT_HGT; i++)
3691 Term_erase(0, tb->hgt + 2 + i, tb->wid);
3694 /* Display information */
3695 if (tb->dirty_flags & DIRTY_NOT_FOUND)
3698 prt(format("¥Ñ¥¿¡¼¥ó¤¬¸«¤Ä¤«¤ê¤Þ¤»¤ó: %s", tb->search_str), tb->hgt + 1 + 1, 0);
3700 prt(format("Pattern not found: %s", tb->search_str), tb->hgt + 1 + 1, 0);
3703 else if (tb->dirty_flags & DIRTY_NO_SEARCH)
3706 prt("¸¡º÷Ãæ¤Î¥Ñ¥¿¡¼¥ó¤¬¤¢¤ê¤Þ¤»¤ó('/'¤Ç¸¡º÷)¡£", tb->hgt + 1 + 1, 0);
3708 prt("No pattern to search. (Press '/' to search.)", tb->hgt +1 + 1, 0);
3711 else if (tb->lines_list[tb->cy][0] == '#')
3714 prt("¤³¤Î¹Ô¤Ï¥³¥á¥ó¥È¤Ç¤¹¡£", tb->hgt +1 + 1, 0);
3716 prt("This line is a comment.", tb->hgt +1 + 1, 0);
3719 else if (tb->lines_list[tb->cy][1] == ':')
3723 switch(tb->lines_list[tb->cy][0])
3727 str = "¤³¤Î¹Ô¤Ï¾ò·ïʬ´ô¼°¤Ç¤¹¡£";
3729 str = "This line is a Conditional Expression.";
3735 str = "¤³¤Î¹Ô¤Ï¥Þ¥¯¥í¤Î¼Â¹ÔÆâÍƤòÄêµÁ¤·¤Þ¤¹¡£";
3737 str = "This line defines a Macro action.";
3742 str = "¤³¤Î¹Ô¤Ï¥Þ¥¯¥í¤Î¥È¥ê¥¬¡¼¡¦¥¡¼¤òÄêµÁ¤·¤Þ¤¹¡£";
3744 str = "This line defines a Macro trigger key.";
3749 str = "¤³¤Î¹Ô¤Ï¥¡¼ÇÛÃÖ¤òÄêµÁ¤·¤Þ¤¹¡£";
3751 str = "This line defines a Keymap.";
3756 /* Draw the first line */
3757 if (str) prt(str, tb->hgt +1 + 1, 0);
3761 switch(tb->lines_list[tb->cy][0])
3764 if (tb->states[tb->cy] & LSTAT_BYPASS)
3767 str = "¸½ºß¤Î¼°¤ÎÃͤϡֵ¶(=0)¡×¤Ç¤¹¡£";
3769 str = " The expression is 'False'(=0) currently.";
3775 str = "¸½ºß¤Î¼°¤ÎÃͤϡֿ¿(=1)¡×¤Ç¤¹¡£";
3777 str = " The expression is 'True'(=1) currently.";
3785 if (tb->states[tb->cy] & LSTAT_BYPASS)
3788 str = "¤³¤Î¹Ô¤Ï¸½ºß¤Ï̵¸ú¤Ê¾õÂ֤Ǥ¹¡£";
3790 str = " This line is bypassed currently.";
3796 /* Draw the second line */
3797 if (str) prt(str, tb->hgt +1 + 2, 0);
3800 /* Get description of an autopicker preference line */
3801 else if (autopick_new_entry(entry, tb->lines_list[tb->cy], FALSE))
3803 char buf[MAX_LINELEN];
3804 char temp[MAX_LINELEN];
3807 describe_autopick(buf, entry);
3809 if (tb->states[tb->cy] & LSTAT_BYPASS)
3812 strcat(buf, "¤³¤Î¹Ô¤Ï¸½ºß¤Ï̵¸ú¤Ê¾õÂ֤Ǥ¹¡£");
3814 strcat(buf, " This line is bypassed currently.");
3818 roff_to_buf(buf, 81, temp, sizeof(temp));
3820 for (i = 0; i < 3; i++)
3826 prt(t, tb->hgt +1 + 1 + i, 0);
3830 autopick_free_entry(entry);
3837 * Kill segment of a line
3839 static void kill_line_segment(text_body_type *tb, int y, int x0, int x1, bool whole)
3841 char buf[MAX_LINELEN];
3842 cptr s = tb->lines_list[y];
3847 if (x0 == x1) return;
3849 /* Kill whole line? */
3850 if (whole && x0 == 0 && s[x1] == '\0' && tb->lines_list[y+1])
3854 string_free(tb->lines_list[y]);
3856 /* Shift lines up */
3857 for (i = y; tb->lines_list[i+1]; i++)
3858 tb->lines_list[i] = tb->lines_list[i+1];
3859 tb->lines_list[i] = NULL;
3861 /* Expressions need re-evaluation */
3862 tb->dirty_flags |= DIRTY_EXPRESSION;
3867 /* Before the segment */
3868 for (x = 0; x < x0; x++)
3871 /* After the segment */
3872 for (x = x1; s[x]; x++)
3878 string_free(tb->lines_list[y]);
3879 tb->lines_list[y] = string_make(buf);
3881 /* Expressions may need re-evaluation */
3882 check_expression_line(tb, y);
3887 * Get a trigger key and insert ASCII string for the trigger
3889 static bool insert_macro_line(text_body_type *tb)
3898 /* Do not process macros */
3904 /* Read the pattern */
3910 /* Do not process macros */
3913 /* Do not wait for keys */
3916 /* Attempt to read a key */
3926 /* Convert the trigger */
3927 ascii_to_text(tmp, buf);
3930 if(!tmp[0]) return FALSE;
3934 /* Insert preference string */
3935 insert_return_code(tb);
3936 string_free(tb->lines_list[tb->cy]);
3937 tb->lines_list[tb->cy] = string_make(format("P:%s", tmp));
3939 /* Acquire action */
3940 i = macro_find_exact(buf);
3944 /* Nothing defined */
3949 /* Analyze the current action */
3950 ascii_to_text(tmp, macro__act[i]);
3953 /* Insert blank action preference line */
3954 insert_return_code(tb);
3955 string_free(tb->lines_list[tb->cy]);
3956 tb->lines_list[tb->cy] = string_make(format("A:%s", tmp));
3963 * Get a command key and insert ASCII string for the key
3965 static bool insert_keymap_line(text_body_type *tb)
3973 if (rogue_like_commands)
3975 mode = KEYMAP_MODE_ROGUE;
3981 mode = KEYMAP_MODE_ORIG;
3994 /* Convert the trigger */
3995 ascii_to_text(tmp, buf);
3998 if(!tmp[0]) return FALSE;
4002 /* Insert preference string */
4003 insert_return_code(tb);
4004 string_free(tb->lines_list[tb->cy]);
4005 tb->lines_list[tb->cy] = string_make(format("C:%d:%s", mode, tmp));
4007 /* Look up the keymap */
4008 act = keymap_act[mode][(byte)(buf[0])];
4010 /* Insert blank action preference line */
4011 insert_return_code(tb);
4012 string_free(tb->lines_list[tb->cy]);
4013 tb->lines_list[tb->cy] = string_make(format("A:%s", act));
4020 * Execute a single editor command
4022 static bool do_editor_command(text_body_type *tb, int com_id)
4030 /* Revert to original */
4032 if (!get_check("Á´¤Æ¤ÎÊѹ¹¤òÇË´þ¤·¤Æ¸µ¤Î¾õÂÖ¤ËÌᤷ¤Þ¤¹¡£¤è¤í¤·¤¤¤Ç¤¹¤«¡© ")) break;
4034 if (!get_check("Discard all changes and revert to original file. Are you sure? ")) break;
4037 free_text_lines(tb->lines_list);
4038 tb->lines_list = read_pickpref_text_lines(&tb->filename_mode);
4039 tb->dirty_flags |= DIRTY_ALL | DIRTY_MODE | DIRTY_EXPRESSION;
4040 tb->cx = tb->cy = 0;
4045 /* Peruse the main help file */
4047 (void)show_file(TRUE, "jeditor.txt", NULL, 0, 0);
4049 (void)show_file(TRUE, "editor.txt", NULL, 0, 0);
4052 tb->dirty_flags |= DIRTY_SCREEN;
4057 /* Split a line or insert end of line */
4059 /* Ignore selection */
4065 tb->dirty_flags |= DIRTY_ALL;
4068 insert_return_code(tb);
4073 tb->dirty_flags |= DIRTY_ALL;
4083 len = strlen(tb->lines_list[tb->cy]);
4084 if (len < tb->cx) tb->cx = len;
4086 else if (tb->cy > 0)
4089 tb->cx = strlen(tb->lines_list[tb->cy]);
4095 if (tb->lines_list[tb->cy + 1]) tb->cy++;
4100 if (tb->cy > 0) tb->cy--;
4109 if (iskanji(tb->lines_list[tb->cy][tb->cx])) tb->cx++;
4112 len = strlen(tb->lines_list[tb->cy]);
4115 if (tb->lines_list[tb->cy + 1])
4127 /* Beginning of line */
4133 tb->cx = strlen(tb->lines_list[tb->cy]);
4137 while (0 < tb->cy && tb->upper <= tb->cy)
4139 while (0 < tb->upper && tb->cy + 1 < tb->upper + tb->hgt)
4145 while (tb->cy < tb->upper + tb->hgt && tb->lines_list[tb->cy + 1])
4155 while (tb->lines_list[tb->cy + 1])
4161 int by1, bx1, by2, bx2;
4164 /* Copy the text first */
4165 do_editor_command(tb, EC_COPY);
4167 if (tb->my < tb->cy ||
4168 (tb->my == tb->cy && tb->mx < tb->cx))
4183 /* Kill lines in reverse order */
4184 for (y = by2; y >= by1; y--)
4187 int x1 = strlen(tb->lines_list[y]);
4189 if (y == by1) x0 = bx1;
4190 if (y == by2) x1 = bx2;
4192 kill_line_segment(tb, y, x0, x1, TRUE);
4195 /* Correct cursor position */
4199 /* Disable selection */
4203 tb->dirty_flags |= DIRTY_ALL;
4210 int by1, bx1, by2, bx2;
4212 int len = strlen(tb->lines_list[tb->cy]);
4214 /* Correct cursor location */
4215 if (tb->cx > len) tb->cx = len;
4217 /* Use single line? */
4222 if (tb->lines_list[tb->cy + 1])
4224 /* Select a single line */
4230 /* Select bottom line */
4235 if (tb->my < tb->cy ||
4236 (tb->my == tb->cy && tb->mx < tb->cx))
4251 /* Kill old yank buffer */
4252 kill_yank_chain(tb);
4254 /* Copy string to yank buffer */
4255 for (y = by1; y <= by2; y++)
4258 char buf[MAX_LINELEN];
4261 int x1 = strlen(tb->lines_list[y]);
4263 if (y == by1) x0 = bx1;
4264 if (y == by2) x1 = bx2;
4266 for (i = 0; i < x1 - x0; i++)
4268 buf[i] = tb->lines_list[y][x0 + i];
4272 add_str_to_yank(tb, buf);
4275 /* Disable selection */
4279 tb->dirty_flags |= DIRTY_ALL;
4285 /* Paste killed text */
4287 chain_str_type *chain = tb->yank;
4288 int len = strlen(tb->lines_list[tb->cy]);
4290 /* Nothing to do? */
4293 /* Correct cursor location */
4294 if (tb->cx > len) tb->cx = len;
4296 /* Ignore selection */
4302 tb->dirty_flags |= DIRTY_ALL;
4308 cptr yank_str = chain->s;
4310 char buf[MAX_LINELEN];
4312 char rest[MAX_LINELEN], *rest_ptr = rest;
4314 /* Save preceding string */
4315 for(i = 0; i < tb->cx; i++)
4316 buf[i] = tb->lines_list[tb->cy][i];
4318 strcpy(rest, &(tb->lines_list[tb->cy][i]));
4320 /* Paste yank buffer */
4321 while (*yank_str && i < MAX_LINELEN-1)
4323 buf[i++] = *yank_str++;
4329 chain = chain->next;
4331 if (chain || tb->yank_eol)
4333 /* There is an end of line between chain nodes */
4335 insert_return_code(tb);
4337 /* Replace this line with new one */
4338 string_free(tb->lines_list[tb->cy]);
4339 tb->lines_list[tb->cy] = string_make(buf);
4341 /* Move to next line */
4348 /* Final line doesn't have end of line */
4350 tb->cx = strlen(buf);
4352 /* Rest of original line */
4353 while (*rest_ptr && i < MAX_LINELEN-1)
4355 buf[i++] = *rest_ptr++;
4361 /* Replace this line with new one */
4362 string_free(tb->lines_list[tb->cy]);
4363 tb->lines_list[tb->cy] = string_make(buf);
4370 tb->dirty_flags |= DIRTY_ALL;
4372 /* Expressions need re-evaluation */
4373 tb->dirty_flags |= DIRTY_EXPRESSION;
4381 /* Disable the selection */
4385 tb->dirty_flags |= DIRTY_ALL;
4389 tb->mark = MARK_MARK;
4391 /* Repeating this command swaps cursor position */
4392 if (com_id == tb->old_com_id)
4404 tb->dirty_flags |= DIRTY_ALL;
4408 int len = strlen(tb->lines_list[tb->cy]);
4410 /* Mark the point 1 */
4414 /* Correct cursor location */
4415 if (tb->cx > len) tb->mx = len;
4422 /* Kill rest of line */
4424 int len = strlen(tb->lines_list[tb->cy]);
4426 /* Correct cursor location */
4427 if (tb->cx > len) tb->cx = len;
4429 /* Ignore selection */
4435 tb->dirty_flags |= DIRTY_ALL;
4438 /* Append only if this command is repeated. */
4439 if (tb->old_com_id != com_id)
4441 kill_yank_chain(tb);
4445 /* Really deleted some text */
4448 /* Add deleted string to yank buffer */
4449 add_str_to_yank(tb, &(tb->lines_list[tb->cy][tb->cx]));
4451 kill_line_segment(tb, tb->cy, tb->cx, len, FALSE);
4454 tb->dirty_line = tb->cy;
4456 /* Leave end of line character */
4460 /* Cut the end of line character only */
4461 if (tb->yank_eol) add_str_to_yank(tb, "");
4463 /* Cut end of line */
4464 tb->yank_eol = TRUE;
4466 do_editor_command(tb, EC_DELETE_CHAR);
4470 case EC_DELETE_CHAR:
4471 /* DELETE == go forward + BACK SPACE */
4473 /* Ignore selection */
4479 tb->dirty_flags |= DIRTY_ALL;
4483 if (iskanji(tb->lines_list[tb->cy][tb->cx])) tb->cx++;
4487 do_editor_command(tb, EC_BACKSPACE);
4495 char buf[MAX_LINELEN];
4497 /* Ignore selection */
4503 tb->dirty_flags |= DIRTY_ALL;
4506 len = strlen(tb->lines_list[tb->cy]);
4509 if (tb->lines_list[tb->cy + 1])
4523 /* delete a return code and union two lines */
4524 if (tb->cy == 0) break;
4525 tb->cx = strlen(tb->lines_list[tb->cy-1]);
4526 strcpy(buf, tb->lines_list[tb->cy-1]);
4527 strcat(buf, tb->lines_list[tb->cy]);
4528 string_free(tb->lines_list[tb->cy-1]);
4529 string_free(tb->lines_list[tb->cy]);
4530 tb->lines_list[tb->cy-1] = string_make(buf);
4532 for (i = tb->cy; tb->lines_list[i+1]; i++)
4533 tb->lines_list[i] = tb->lines_list[i+1];
4535 tb->lines_list[i] = NULL;
4539 tb->dirty_flags |= DIRTY_ALL;
4541 /* Expressions need re-evaluation */
4542 tb->dirty_flags |= DIRTY_EXPRESSION;
4547 for (i = j = k = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
4551 if (iskanji(tb->lines_list[tb->cy][i]))
4552 buf[j++] = tb->lines_list[tb->cy][i++];
4554 buf[j++] = tb->lines_list[tb->cy][i];
4561 for (; tb->lines_list[tb->cy][i]; i++)
4562 buf[j++] = tb->lines_list[tb->cy][i];
4564 string_free(tb->lines_list[tb->cy]);
4565 tb->lines_list[tb->cy] = string_make(buf);
4568 tb->dirty_line = tb->cy;
4570 /* Expressions may need re-evaluation */
4571 check_expression_line(tb, tb->cy);
4580 /* Become dirty because of item/equip menu */
4581 tb->dirty_flags |= DIRTY_SCREEN;
4583 search_dir = get_string_for_search(&tb->search_o_ptr, &tb->search_str);
4585 if (!search_dir) break;
4587 if (search_dir == 1) do_editor_command(tb, EC_SEARCH_FORW);
4588 else do_editor_command(tb, EC_SEARCH_BACK);
4592 case EC_SEARCH_FORW:
4593 if (tb->search_o_ptr)
4595 if (!search_for_object(tb, tb->search_o_ptr, TRUE)) tb->dirty_flags |= DIRTY_NOT_FOUND;
4597 else if (tb->search_str)
4599 if (!search_for_string(tb, tb->search_str, TRUE)) tb->dirty_flags |= DIRTY_NOT_FOUND;
4603 tb->dirty_flags |= DIRTY_NO_SEARCH;
4607 case EC_SEARCH_BACK:
4608 if (tb->search_o_ptr)
4610 if (!search_for_object(tb, tb->search_o_ptr, FALSE)) tb->dirty_flags |= DIRTY_NOT_FOUND;
4612 else if (tb->search_str)
4614 if (!search_for_string(tb, tb->search_str, FALSE)) tb->dirty_flags |= DIRTY_NOT_FOUND;
4618 tb->dirty_flags |= DIRTY_NO_SEARCH;
4623 /* Become dirty because of item/equip menu */
4624 tb->dirty_flags |= DIRTY_SCREEN;
4626 if (!get_object_for_search(&tb->search_o_ptr, &tb->search_str)) break;
4628 do_editor_command(tb, EC_SEARCH_FORW);
4631 case EC_SEARCH_DESTROYED:
4632 if (!get_destroyed_object_for_search(&tb->search_o_ptr, &tb->search_str)) break;
4634 do_editor_command(tb, EC_SEARCH_FORW);
4637 case EC_INSERT_OBJECT:
4639 /* Insert choosen item name */
4641 autopick_type an_entry, *entry = &an_entry;
4643 if (!entry_from_choosed_object(entry))
4645 /* Now dirty because of item/equip menu */
4646 tb->dirty_flags |= DIRTY_SCREEN;
4651 insert_return_code(tb);
4652 string_free(tb->lines_list[tb->cy]);
4653 tb->lines_list[tb->cy] = autopick_line_from_entry_kill(entry);
4655 /* Now dirty because of item/equip menu */
4656 tb->dirty_flags |= DIRTY_SCREEN;
4661 case EC_INSERT_DESTROYED:
4662 /* Insert a name of last destroyed item */
4663 if (tb->last_destroyed)
4666 insert_return_code(tb);
4667 string_free(tb->lines_list[tb->cy]);
4668 tb->lines_list[tb->cy] = string_make(tb->last_destroyed);
4671 tb->dirty_flags |= DIRTY_ALL;
4675 case EC_INSERT_BLOCK:
4677 /* Insert a conditinal expression line */
4680 /* Conditional Expression for Class and Race */
4681 sprintf(classrace, "?:[AND [EQU $RACE %s] [EQU $CLASS %s]]",
4683 rp_ptr->E_title, cp_ptr->E_title
4685 rp_ptr->title, cp_ptr->title
4690 insert_return_code(tb);
4691 string_free(tb->lines_list[tb->cy]);
4692 tb->lines_list[tb->cy] = string_make(classrace);
4694 insert_return_code(tb);
4695 string_free(tb->lines_list[tb->cy]);
4696 tb->lines_list[tb->cy] = string_make("?:1");
4699 tb->dirty_flags |= DIRTY_ALL;
4703 case EC_INSERT_MACRO:
4704 /* Draw_everythig (delete menu) */
4705 draw_text_editor(tb);
4708 Term_erase(0, tb->cy - tb->upper + 1, tb->wid);
4712 Term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW, "P:<¥È¥ê¥¬¡¼¥¡¼>: ");
4714 Term_putstr(0, tb->cy - tb->upper + 1, tb->wid - 1, TERM_YELLOW, "P:<Trigger key>: ");
4716 if (insert_macro_line(tb))
4718 /* Prepare to input action */
4722 tb->dirty_flags |= DIRTY_ALL;
4723 tb->dirty_flags |= DIRTY_MODE;
4728 case EC_INSERT_KEYMAP:
4729 /* Draw_everythig (delete menu) */
4730 draw_text_editor(tb);
4733 Term_erase(0, tb->cy - tb->upper + 1, tb->wid);
4737 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)));
4739 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)));
4742 if (insert_keymap_line(tb))
4744 /* Prepare to input action */
4748 tb->dirty_flags |= DIRTY_ALL;
4749 tb->dirty_flags |= DIRTY_MODE;
4753 case EC_CL_AUTOPICK: toggle_command_letter(tb, DO_AUTOPICK); break;
4754 case EC_CL_DESTROY: toggle_command_letter(tb, DO_AUTODESTROY); break;
4755 case EC_CL_LEAVE: toggle_command_letter(tb, DONT_AUTOPICK); break;
4756 case EC_CL_QUERY: toggle_command_letter(tb, DO_QUERY_AUTOPICK); break;
4757 case EC_CL_NO_DISP: toggle_command_letter(tb, DO_DISPLAY); break;
4759 case EC_IK_UNAWARE: toggle_keyword(tb, FLG_UNAWARE); break;
4760 case EC_IK_UNIDENTIFIED: toggle_keyword(tb, FLG_UNIDENTIFIED); break;
4761 case EC_IK_IDENTIFIED: toggle_keyword(tb, FLG_IDENTIFIED); break;
4762 case EC_IK_STAR_IDENTIFIED: toggle_keyword(tb, FLG_STAR_IDENTIFIED); break;
4763 case EC_KK_WEAPONS: toggle_keyword(tb, FLG_WEAPONS); break;
4764 case EC_KK_FAVORITE: toggle_keyword(tb, FLG_FAVORITE); break;
4765 case EC_KK_ARMORS: toggle_keyword(tb, FLG_ARMORS); break;
4766 case EC_KK_MISSILES: toggle_keyword(tb, FLG_MISSILES); break;
4767 case EC_KK_DEVICES: toggle_keyword(tb, FLG_DEVICES); break;
4768 case EC_KK_LIGHTS: toggle_keyword(tb, FLG_LIGHTS); break;
4769 case EC_KK_JUNKS: toggle_keyword(tb, FLG_JUNKS); break;
4770 case EC_KK_SPELLBOOKS: toggle_keyword(tb, FLG_SPELLBOOKS); break;
4771 case EC_KK_SHIELDS: toggle_keyword(tb, FLG_SHIELDS); break;
4772 case EC_KK_BOWS: toggle_keyword(tb, FLG_BOWS); break;
4773 case EC_KK_RINGS: toggle_keyword(tb, FLG_RINGS); break;
4774 case EC_KK_AMULETS: toggle_keyword(tb, FLG_AMULETS); break;
4775 case EC_KK_SUITS: toggle_keyword(tb, FLG_SUITS); break;
4776 case EC_KK_CLOAKS: toggle_keyword(tb, FLG_CLOAKS); break;
4777 case EC_KK_HELMS: toggle_keyword(tb, FLG_HELMS); break;
4778 case EC_KK_GLOVES: toggle_keyword(tb, FLG_GLOVES); break;
4779 case EC_KK_BOOTS: toggle_keyword(tb, FLG_BOOTS); break;
4780 case EC_OK_COLLECTING: toggle_keyword(tb, FLG_COLLECTING); break;
4781 case EC_OK_BOOSTED: toggle_keyword(tb, FLG_BOOSTED); break;
4782 case EC_OK_MORE_THAN: toggle_keyword(tb, FLG_MORE_THAN); break;
4783 case EC_OK_MORE_BONUS: toggle_keyword(tb, FLG_MORE_BONUS); break;
4784 case EC_OK_WORTHLESS: toggle_keyword(tb, FLG_WORTHLESS); break;
4785 case EC_OK_ARTIFACT: toggle_keyword(tb, FLG_ARTIFACT); break;
4786 case EC_OK_EGO: toggle_keyword(tb, FLG_EGO); break;
4787 case EC_OK_NAMELESS: toggle_keyword(tb, FLG_NAMELESS); break;
4788 case EC_OK_WANTED: toggle_keyword(tb, FLG_WANTED); break;
4789 case EC_OK_UNIQUE: toggle_keyword(tb, FLG_UNIQUE); break;
4790 case EC_OK_HUMAN: toggle_keyword(tb, FLG_HUMAN); break;
4791 case EC_OK_UNREADABLE:
4792 toggle_keyword(tb, FLG_UNREADABLE);
4793 add_keyword(tb, FLG_SPELLBOOKS);
4796 toggle_keyword(tb, FLG_REALM1);
4797 add_keyword(tb, FLG_SPELLBOOKS);
4800 toggle_keyword(tb, FLG_REALM2);
4801 add_keyword(tb, FLG_SPELLBOOKS);
4804 toggle_keyword(tb, FLG_FIRST);
4805 add_keyword(tb, FLG_SPELLBOOKS);
4808 toggle_keyword(tb, FLG_SECOND);
4809 add_keyword(tb, FLG_SPELLBOOKS);
4812 toggle_keyword(tb, FLG_THIRD);
4813 add_keyword(tb, FLG_SPELLBOOKS);
4816 toggle_keyword(tb, FLG_FOURTH);
4817 add_keyword(tb, FLG_SPELLBOOKS);
4821 /* Save old command */
4822 tb->old_com_id = com_id;
4829 * Insert single letter at cursor position.
4831 static void insert_single_letter(text_body_type *tb, int key)
4834 char buf[MAX_LINELEN];
4836 /* Save preceding string */
4837 for (i = j = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
4838 buf[j++] = tb->lines_list[tb->cy][i];
4840 /* Add a character */
4848 if (j+2 < MAX_LINELEN)
4860 if (j+1 < MAX_LINELEN)
4866 for (; tb->lines_list[tb->cy][i] && j + 1 < MAX_LINELEN; i++)
4867 buf[j++] = tb->lines_list[tb->cy][i];
4870 /* Replace current line with new line */
4871 string_free(tb->lines_list[tb->cy]);
4872 tb->lines_list[tb->cy] = string_make(buf);
4874 /* Move to correct collumn */
4875 len = strlen(tb->lines_list[tb->cy]);
4876 if (len < tb->cx) tb->cx = len;
4879 tb->dirty_line = tb->cy;
4881 /* Expressions may need re-evaluation */
4882 check_expression_line(tb, tb->cy);
4886 * In-game editor of Object Auto-picker/Destoryer
4888 void do_cmd_edit_autopick(void)
4890 text_body_type text_body, *tb = &text_body;
4892 autopick_type an_entry, *entry = &an_entry;
4893 char buf[MAX_LINELEN];
4898 static s32b old_autosave_turn = 0L;
4901 tb->cx = tb->cy = tb->upper = tb->left = 0;
4903 tb->mx = tb->my = 0;
4904 tb->old_cy = tb->old_upper = tb->old_left = -1;
4905 tb->old_wid = tb->old_hgt = -1;
4909 tb->search_o_ptr = NULL;
4910 tb->search_str = NULL;
4911 tb->last_destroyed = NULL;
4912 tb->dirty_flags = DIRTY_ALL | DIRTY_MODE | DIRTY_EXPRESSION;
4913 tb->dirty_line = -1;
4914 tb->filename_mode = PT_WITH_PNAME;
4917 if (turn > old_autosave_turn + 100L)
4919 do_cmd_save_game(TRUE);
4920 old_autosave_turn = turn;
4923 /* HACK -- Reset start_time to stop counting playtime while edit */
4926 /* Free old entries */
4929 /* Command Description of the 'Last Destroyed Item' */
4930 if (autopick_last_destroyed_object.k_idx)
4932 autopick_entry_from_object(entry, &autopick_last_destroyed_object);
4933 tb->last_destroyed = autopick_line_from_entry_kill(entry);
4936 /* Read or initialize whole text */
4937 tb->lines_list = read_pickpref_text_lines(&tb->filename_mode);
4939 /* Reset cursor position if needed */
4940 for (i = 0; i < tb->cy; i++)
4942 if (!tb->lines_list[i])
4944 tb->cy = tb->cx = 0;
4949 /* Save the screen */
4952 /* Process requests until done */
4958 /* Draw_everythig */
4959 draw_text_editor(tb);
4961 /* Display header line */
4963 prt("(^Q:½ªÎ», ESC:¥á¥Ë¥å¡¼, ¤½¤Î¾:ÆþÎÏ)", 0, 0);
4965 prt("(^Q:quit, ESC:menu, Other:input text)", 0, 0);
4969 /* Display current position */
4970 prt (format("(%d,%d)", tb->cx, tb->cy), 0, 60);
4974 /* Display current position and mark position */
4975 prt (format("(%d,%d)-(%d,%d)", tb->mx, tb->my, tb->cx, tb->cy), 0, 60);
4979 Term_gotoxy(tb->cx - tb->left, tb->cy - tb->upper + 1);
4982 tb->dirty_flags = 0;
4983 tb->dirty_line = -1;
4985 /* Save old key and location */
4986 tb->old_cy = tb->cy;
4987 tb->old_upper = tb->upper;
4988 tb->old_left = tb->left;
4989 tb->old_wid = tb->wid;
4990 tb->old_hgt = tb->hgt;
4995 /* Count length of macro trigger which induced this key */
4996 trig_len = strlen(inkey_macro_trigger_string);
4998 /* HACK -- ignore macro defined on ASCII keys */
5001 /* Get original key */
5002 key = inkey_macro_trigger_string[0];
5004 /* Kill further macro expansion */
5009 if (key == 0x7F) key = KTRL('d');
5012 /* Cursor key macroes to direction command */
5034 * Un-shifted cursor keys cancells
5035 * selection created by shift+cursor.
5037 if (tb->mark & MARK_BY_SHIFT)
5042 tb->dirty_flags |= DIRTY_ALL;
5046 /* Mega Hack!!! Start selection with shift + cursor keys */
5051 /* Get ascii form */
5052 ascii_to_text(buf, inkey_macro_trigger_string);
5054 if (strstr(buf, "shift-Down"))
5056 else if (strstr(buf, "shift-Left"))
5058 else if (strstr(buf, "shift-Right"))
5060 else if (strstr(buf, "shift-Up"))
5065 /* Kill further macro expansion */
5068 /* Start selection */
5071 int len = strlen(tb->lines_list[tb->cy]);
5073 tb->mark = MARK_MARK | MARK_BY_SHIFT;
5077 /* Correct cursor location */
5078 if (tb->cx > len) tb->mx = len;
5080 /* Need to redraw text */
5081 if (com_id == EC_UP || com_id == EC_DOWN)
5083 /* Redraw all text */
5084 tb->dirty_flags |= DIRTY_ALL;
5088 tb->dirty_line = tb->cy;
5101 else if (key == ESCAPE)
5103 com_id = do_command_menu(0, 0);
5105 /* Redraw all text later */
5106 tb->dirty_flags |= DIRTY_SCREEN;
5109 /* Insert a character */
5110 else if (!iscntrl(key & 0xff))
5112 /* Ignore selection */
5118 tb->dirty_flags |= DIRTY_ALL;
5121 insert_single_letter(tb, key);
5127 /* Other commands */
5130 com_id = get_com_id(key);
5133 if (com_id) quit = do_editor_command(tb, com_id);
5136 /* Restore the screen */
5139 switch (tb->filename_mode)
5143 strcpy(buf, "picktype.prf");
5145 strcpy(buf, "pickpref.prf");
5151 sprintf(buf, "picktype-%s.prf", player_name);
5153 sprintf(buf, "pickpref-%s.prf", player_name);
5158 write_text_lines(buf, tb->lines_list);
5159 free_text_lines(tb->lines_list);
5161 string_free(tb->last_destroyed);
5163 /* Destroy string chain */
5164 kill_yank_chain(tb);
5166 /* Reload autopick pref */
5167 process_pickpref_file(buf);
5169 /* HACK -- reset start_time so that playtime is not increase while edit */
5170 start_time = time(NULL);