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.
15 #define MAX_LINELEN 1024
17 static object_type autopick_last_destroyed_object;
23 #define FLG_COLLECTING 1
24 #define FLG_UNIDENTIFIED 2
25 #define FLG_IDENTIFIED 3
26 #define FLG_STAR_IDENTIFIED 4
28 #define FLG_MORE_THAN 6
30 #define FLG_MORE_BONUS 8
31 #define FLG_MORE_BONUS2 9
32 #define FLG_WORTHLESS 10
33 #define FLG_ARTIFACT 11
35 #define FLG_NAMELESS 13
36 #define FLG_UNAWARE 14
40 #define FLG_UNREADABLE 18
49 #define FLG_WEAPONS 31
51 #define FLG_MISSILES 33
52 #define FLG_DEVICES 34
55 #define FLG_SPELLBOOKS 37
57 #define FLG_SHIELDS 39
60 #define FLG_AMULETS 42
69 #define KEY_ALL "¤¹¤Ù¤Æ¤Î"
70 #define KEY_COLLECTING "¼ý½¸Ãæ¤Î"
71 #define KEY_UNIDENTIFIED "̤´ÕÄê¤Î"
72 #define KEY_IDENTIFIED "´ÕÄêºÑ¤ß¤Î"
73 #define KEY_STAR_IDENTIFIED "*´ÕÄê*ºÑ¤ß¤Î"
74 #define KEY_BOOSTED "¥À¥¤¥¹Ìܤΰ㤦"
75 #define KEY_MORE_THAN "¥À¥¤¥¹ÌÜ"
76 #define KEY_DICE "°Ê¾å¤Î"
77 #define KEY_MORE_BONUS "½¤ÀµÃͤ¬"
78 #define KEY_MORE_BONUS2 "°Ê¾å¤Î"
79 #define KEY_WORTHLESS "̵²ÁÃͤÎ"
80 #define KEY_ARTIFACT "¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È"
81 #define KEY_EGO "¥¨¥´"
82 #define KEY_NAMELESS "̵ÌäÎ"
83 #define KEY_UNAWARE "̤ȽÌÀ¤Î"
84 #define KEY_WANTED "¾Þ¶â¼ó¤Î"
85 #define KEY_UNIQUE "¥æ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼¤Î"
86 #define KEY_HUMAN "¿Í´Ö¤Î"
87 #define KEY_UNREADABLE "Æɤá¤Ê¤¤"
88 #define KEY_REALM1 "Âè°ìÎΰè¤Î"
89 #define KEY_REALM2 "ÂèÆóÎΰè¤Î"
90 #define KEY_FIRST "1ºýÌܤÎ"
91 #define KEY_SECOND "2ºýÌܤÎ"
92 #define KEY_THIRD "3ºýÌܤÎ"
93 #define KEY_FOURTH "4ºýÌܤÎ"
94 #define KEY_ITEMS "¥¢¥¤¥Æ¥à"
95 #define KEY_WEAPONS "Éð´ï"
96 #define KEY_ARMORS "Ëɶñ"
97 #define KEY_MISSILES "Ìð"
98 #define KEY_DEVICES "ËâË¡¥¢¥¤¥Æ¥à"
99 #define KEY_LIGHTS "¸÷¸»"
100 #define KEY_JUNKS "¤¬¤é¤¯¤¿"
101 #define KEY_SPELLBOOKS "ËâË¡½ñ"
102 #define KEY_HAFTED "Æß´ï"
103 #define KEY_SHIELDS "½â"
104 #define KEY_BOWS "µÝ"
105 #define KEY_RINGS "»ØÎØ"
106 #define KEY_AMULETS "¥¢¥ß¥å¥ì¥Ã¥È"
107 #define KEY_SUITS "³»"
108 #define KEY_CLOAKS "¥¯¥í¡¼¥¯"
109 #define KEY_HELMS "³õ"
110 #define KEY_GLOVES "äƼê"
111 #define KEY_BOOTS "·¤"
115 #define KEY_ALL "all"
116 #define KEY_COLLECTING "collecting"
117 #define KEY_UNIDENTIFIED "unidentified"
118 #define KEY_IDENTIFIED "identified"
119 #define KEY_STAR_IDENTIFIED "*identified*"
120 #define KEY_BOOSTED "dice boosted"
121 #define KEY_MORE_THAN "more than"
122 #define KEY_DICE " dice"
123 #define KEY_MORE_BONUS "more bonus than"
124 #define KEY_MORE_BONUS2 ""
125 #define KEY_WORTHLESS "worthless"
126 #define KEY_ARTIFACT "artifact"
127 #define KEY_EGO "ego"
128 #define KEY_NAMELESS "nameless"
129 #define KEY_UNAWARE "unaware"
130 #define KEY_WANTED "wanted"
131 #define KEY_UNIQUE "unique monster's"
132 #define KEY_HUMAN "human"
133 #define KEY_UNREADABLE "unreadable"
134 #define KEY_REALM1 "first realm's"
135 #define KEY_REALM2 "second realm's"
136 #define KEY_FIRST "first"
137 #define KEY_SECOND "second"
138 #define KEY_THIRD "third"
139 #define KEY_FOURTH "fourth"
140 #define KEY_ITEMS "items"
141 #define KEY_WEAPONS "weapons"
142 #define KEY_ARMORS "armors"
143 #define KEY_MISSILES "missiles"
144 #define KEY_DEVICES "magical devices"
145 #define KEY_LIGHTS "lights"
146 #define KEY_JUNKS "junks"
147 #define KEY_SPELLBOOKS "spellbooks"
148 #define KEY_HAFTED "hafted weapons"
149 #define KEY_SHIELDS "shields"
150 #define KEY_BOWS "bows"
151 #define KEY_RINGS "rings"
152 #define KEY_AMULETS "amulets"
153 #define KEY_SUITS "suits"
154 #define KEY_CLOAKS "cloaks"
155 #define KEY_HELMS "helms"
156 #define KEY_GLOVES "gloves"
157 #define KEY_BOOTS "boots"
161 #define MATCH_KEY(KEY) (!strncmp(ptr, KEY, sizeof(KEY)-1)\
162 ? (ptr += sizeof(KEY)-1, (' '==*ptr) ? ptr++ : 0, TRUE) : FALSE)
163 #define MATCH_KEY2(KEY) (!strncmp(ptr, KEY, sizeof(KEY)-1)\
164 ? (prev_ptr = ptr, ptr += sizeof(KEY)-1, (' '==*ptr) ? ptr++ : 0, TRUE) : FALSE)
167 #define ADD_KEY(KEY) strcat(ptr, KEY)
169 #define ADD_KEY(KEY) (strcat(ptr, KEY), strcat(ptr, " "))
171 #define ADD_KEY2(KEY) strcat(ptr, KEY)
173 #define ADD_FLG(FLG) (entry->flag[FLG / 32] |= (1L << (FLG % 32)))
174 #define REM_FLG(FLG) (entry->flag[FLG / 32] &= ~(1L << (FLG % 32)))
175 #define ADD_FLG_NOUN(FLG) (ADD_FLG(FLG), prev_flg = FLG)
176 #define IS_FLG(FLG) (entry->flag[FLG / 32] & (1L << (FLG % 32)))
179 static char kanji_colon[] = "¡§";
184 * Reconstruct preference line from entry
186 cptr autopick_line_from_entry(autopick_type *entry)
188 char buf[MAX_LINELEN];
190 bool sepa_flag = TRUE;
193 if (!(entry->action & DO_DISPLAY)) strcat(buf, "(");
194 if (entry->action & DO_AUTODESTROY) strcat(buf, "!");
195 if (entry->action & DONT_AUTOPICK) strcat(buf, "~");
199 if (IS_FLG(FLG_ALL)) ADD_KEY(KEY_ALL);
200 if (IS_FLG(FLG_COLLECTING)) ADD_KEY(KEY_COLLECTING);
201 if (IS_FLG(FLG_UNIDENTIFIED)) ADD_KEY(KEY_UNIDENTIFIED);
202 if (IS_FLG(FLG_IDENTIFIED)) ADD_KEY(KEY_IDENTIFIED);
203 if (IS_FLG(FLG_STAR_IDENTIFIED)) ADD_KEY(KEY_STAR_IDENTIFIED);
204 if (IS_FLG(FLG_UNAWARE)) ADD_KEY(KEY_UNAWARE);
205 if (IS_FLG(FLG_BOOSTED)) ADD_KEY(KEY_BOOSTED);
207 if (IS_FLG(FLG_MORE_THAN))
209 ADD_KEY(KEY_MORE_THAN);
210 strcat(ptr, format("%d", entry->dice));
214 if (IS_FLG(FLG_MORE_BONUS))
216 ADD_KEY(KEY_MORE_BONUS);
217 strcat(ptr, format("%d", entry->bonus));
218 ADD_KEY(KEY_MORE_BONUS2);
221 if (IS_FLG(FLG_UNREADABLE)) ADD_KEY(KEY_UNREADABLE);
222 if (IS_FLG(FLG_REALM1)) ADD_KEY(KEY_REALM1);
223 if (IS_FLG(FLG_REALM2)) ADD_KEY(KEY_REALM2);
224 if (IS_FLG(FLG_FIRST)) ADD_KEY(KEY_FIRST);
225 if (IS_FLG(FLG_SECOND)) ADD_KEY(KEY_SECOND);
226 if (IS_FLG(FLG_THIRD)) ADD_KEY(KEY_THIRD);
227 if (IS_FLG(FLG_FOURTH)) ADD_KEY(KEY_FOURTH);
228 if (IS_FLG(FLG_WANTED)) ADD_KEY(KEY_WANTED);
229 if (IS_FLG(FLG_UNIQUE)) ADD_KEY(KEY_UNIQUE);
230 if (IS_FLG(FLG_HUMAN)) ADD_KEY(KEY_HUMAN);
231 if (IS_FLG(FLG_WORTHLESS)) ADD_KEY(KEY_WORTHLESS);
232 if (IS_FLG(FLG_NAMELESS)) ADD_KEY(KEY_NAMELESS);
233 if (IS_FLG(FLG_EGO)) ADD_KEY(KEY_EGO);
235 if (IS_FLG(FLG_ARTIFACT)) ADD_KEY(KEY_ARTIFACT);
237 if (IS_FLG(FLG_ITEMS)) ADD_KEY2(KEY_ITEMS);
238 else if (IS_FLG(FLG_WEAPONS)) ADD_KEY2(KEY_WEAPONS);
239 else if (IS_FLG(FLG_ARMORS)) ADD_KEY2(KEY_ARMORS);
240 else if (IS_FLG(FLG_MISSILES)) ADD_KEY2(KEY_MISSILES);
241 else if (IS_FLG(FLG_DEVICES)) ADD_KEY2(KEY_DEVICES);
242 else if (IS_FLG(FLG_LIGHTS)) ADD_KEY2(KEY_LIGHTS);
243 else if (IS_FLG(FLG_JUNKS)) ADD_KEY2(KEY_JUNKS);
244 else if (IS_FLG(FLG_SPELLBOOKS)) ADD_KEY2(KEY_SPELLBOOKS);
245 else if (IS_FLG(FLG_HAFTED)) ADD_KEY2(KEY_HAFTED);
246 else if (IS_FLG(FLG_SHIELDS)) ADD_KEY2(KEY_SHIELDS);
247 else if (IS_FLG(FLG_BOWS)) ADD_KEY2(KEY_BOWS);
248 else if (IS_FLG(FLG_RINGS)) ADD_KEY2(KEY_RINGS);
249 else if (IS_FLG(FLG_AMULETS)) ADD_KEY2(KEY_AMULETS);
250 else if (IS_FLG(FLG_SUITS)) ADD_KEY2(KEY_SUITS);
251 else if (IS_FLG(FLG_CLOAKS)) ADD_KEY2(KEY_CLOAKS);
252 else if (IS_FLG(FLG_HELMS)) ADD_KEY2(KEY_HELMS);
253 else if (IS_FLG(FLG_GLOVES)) ADD_KEY2(KEY_GLOVES);
254 else if (IS_FLG(FLG_BOOTS)) ADD_KEY2(KEY_BOOTS);
256 /* You don't need sepalator after adjective */
257 /* 'artifact' is not true adjective */
258 else if (!IS_FLG(FLG_ARTIFACT))
261 if (entry->name && entry->name[0])
265 if (sepa_flag) strcat(buf, ":");
268 while (entry->name[j] && i < MAX_LINELEN - 2 - 1)
271 if (iskanji(entry->name[j]))
272 buf[i++] = entry->name[j++];
274 buf[i++] = entry->name[j++];
280 if (entry->flag[0] == 0L && entry->flag[0] == 0L)
290 while (entry->insc[j] && i < MAX_LINELEN - 2)
293 if (iskanji(entry->insc[j]))
294 buf[i++] = entry->insc[j++];
296 buf[i++] = entry->insc[j++];
301 return string_make(buf);
306 * Reconstruct preference line from entry and kill entry
308 static cptr autopick_line_from_entry_kill(autopick_type *entry)
310 cptr ptr = autopick_line_from_entry(entry);
312 /* Free memory for original entry */
313 autopick_free_entry(entry);
320 * A function to create new entry
322 bool autopick_new_entry(autopick_type *entry, cptr str)
327 char buf[MAX_LINELEN];
328 cptr prev_ptr, ptr, old_ptr;
331 if (str[1] == ':') switch (str[0])
334 case 'A': case 'P': case 'C':
338 entry->flag[0] = entry->flag[1] = 0L;
341 act = DO_AUTOPICK | DO_DISPLAY;
344 if ((act & DO_AUTOPICK) && *str == '!')
347 act |= DO_AUTODESTROY;
350 else if ((act & DO_AUTOPICK) && *str == '~')
353 act |= DONT_AUTOPICK;
356 else if ((act & DO_DISPLAY) && *str == '(')
365 /* don't mind upper or lower case */
367 for (i = 0; *str; i++)
378 /* Auto-inscription? */
386 if (isupper(c)) c = tolower(c);
392 /* Skip empty line */
393 if (*buf == 0) return FALSE;
398 while (old_ptr != ptr)
400 /* Save current location */
403 if (MATCH_KEY(KEY_ALL)) ADD_FLG(FLG_ALL);
404 if (MATCH_KEY(KEY_COLLECTING)) ADD_FLG(FLG_COLLECTING);
405 if (MATCH_KEY(KEY_UNIDENTIFIED)) ADD_FLG(FLG_UNIDENTIFIED);
406 if (MATCH_KEY(KEY_IDENTIFIED)) ADD_FLG(FLG_IDENTIFIED);
407 if (MATCH_KEY(KEY_STAR_IDENTIFIED)) ADD_FLG(FLG_STAR_IDENTIFIED);
408 if (MATCH_KEY(KEY_BOOSTED)) ADD_FLG(FLG_BOOSTED);
410 /*** Weapons whose dd*ds is more than nn ***/
411 if (MATCH_KEY2(KEY_MORE_THAN))
416 /* Drop leading spaces */
417 while (' ' == *ptr) ptr++;
420 while (isdigit(*ptr))
422 entry->dice = 10 * entry->dice + (*ptr - '0');
429 (void)MATCH_KEY(KEY_DICE);
430 ADD_FLG(FLG_MORE_THAN);
436 /*** Items whose magical bonus is more than n ***/
437 if (MATCH_KEY2(KEY_MORE_BONUS))
442 /* Drop leading spaces */
443 while (' ' == *ptr) ptr++;
446 while (isdigit(*ptr))
448 entry->bonus = 10 * entry->bonus + (*ptr - '0');
455 (void)MATCH_KEY(KEY_MORE_BONUS2);
456 ADD_FLG(FLG_MORE_BONUS);
462 if (MATCH_KEY(KEY_WORTHLESS)) ADD_FLG(FLG_WORTHLESS);
463 if (MATCH_KEY(KEY_EGO)) ADD_FLG(FLG_EGO);
464 if (MATCH_KEY(KEY_NAMELESS)) ADD_FLG(FLG_NAMELESS);
465 if (MATCH_KEY(KEY_UNAWARE)) ADD_FLG(FLG_UNAWARE);
466 if (MATCH_KEY(KEY_WANTED)) ADD_FLG(FLG_WANTED);
467 if (MATCH_KEY(KEY_UNIQUE)) ADD_FLG(FLG_UNIQUE);
468 if (MATCH_KEY(KEY_HUMAN)) ADD_FLG(FLG_HUMAN);
469 if (MATCH_KEY(KEY_UNREADABLE)) ADD_FLG(FLG_UNREADABLE);
470 if (MATCH_KEY(KEY_REALM1)) ADD_FLG(FLG_REALM1);
471 if (MATCH_KEY(KEY_REALM2)) ADD_FLG(FLG_REALM2);
472 if (MATCH_KEY(KEY_FIRST)) ADD_FLG(FLG_FIRST);
473 if (MATCH_KEY(KEY_SECOND)) ADD_FLG(FLG_SECOND);
474 if (MATCH_KEY(KEY_THIRD)) ADD_FLG(FLG_THIRD);
475 if (MATCH_KEY(KEY_FOURTH)) ADD_FLG(FLG_FOURTH);
478 /* Not yet found any noun */
481 if (MATCH_KEY2(KEY_ARTIFACT)) ADD_FLG_NOUN(FLG_ARTIFACT);
483 if (MATCH_KEY2(KEY_ITEMS)) ADD_FLG_NOUN(FLG_ITEMS);
484 else if (MATCH_KEY2(KEY_WEAPONS)) ADD_FLG_NOUN(FLG_WEAPONS);
485 else if (MATCH_KEY2(KEY_ARMORS)) ADD_FLG_NOUN(FLG_ARMORS);
486 else if (MATCH_KEY2(KEY_MISSILES)) ADD_FLG_NOUN(FLG_MISSILES);
487 else if (MATCH_KEY2(KEY_DEVICES)) ADD_FLG_NOUN(FLG_DEVICES);
488 else if (MATCH_KEY2(KEY_LIGHTS)) ADD_FLG_NOUN(FLG_LIGHTS);
489 else if (MATCH_KEY2(KEY_JUNKS)) ADD_FLG_NOUN(FLG_JUNKS);
490 else if (MATCH_KEY2(KEY_SPELLBOOKS)) ADD_FLG_NOUN(FLG_SPELLBOOKS);
491 else if (MATCH_KEY2(KEY_HAFTED)) ADD_FLG_NOUN(FLG_HAFTED);
492 else if (MATCH_KEY2(KEY_SHIELDS)) ADD_FLG_NOUN(FLG_SHIELDS);
493 else if (MATCH_KEY2(KEY_BOWS)) ADD_FLG_NOUN(FLG_BOWS);
494 else if (MATCH_KEY2(KEY_RINGS)) ADD_FLG_NOUN(FLG_RINGS);
495 else if (MATCH_KEY2(KEY_AMULETS)) ADD_FLG_NOUN(FLG_AMULETS);
496 else if (MATCH_KEY2(KEY_SUITS)) ADD_FLG_NOUN(FLG_SUITS);
497 else if (MATCH_KEY2(KEY_CLOAKS)) ADD_FLG_NOUN(FLG_CLOAKS);
498 else if (MATCH_KEY2(KEY_HELMS)) ADD_FLG_NOUN(FLG_HELMS);
499 else if (MATCH_KEY2(KEY_GLOVES)) ADD_FLG_NOUN(FLG_GLOVES);
500 else if (MATCH_KEY2(KEY_BOOTS)) ADD_FLG_NOUN(FLG_BOOTS);
502 /* Last 'keyword' must be at the correct location */
506 else if (ptr[0] == kanji_colon[0] && ptr[1] == kanji_colon[1])
509 else if (*ptr == '\0')
510 ; /* nothing to do */
516 /* A noun type keyword didn't end correctly */
517 entry->flag[prev_flg/32] &= ~(1L<< (prev_flg%32));
522 /* Save this auto-picker entry line */
523 entry->name = string_make(ptr);
525 entry->insc = string_make(insc);
531 * A function to delete entry
533 void autopick_free_entry(autopick_type *entry)
535 string_free(entry->name);
536 string_free(entry->insc);
541 * A function for Auto-picker/destroyer
542 * Examine whether the object matches to the entry
544 static bool is_autopick_aux(object_type *o_ptr, autopick_type *entry, cptr o_name)
547 cptr ptr = entry->name;
549 /*** Unidentified ***/
550 if (IS_FLG(FLG_UNIDENTIFIED)
551 && (object_known_p(o_ptr) || (o_ptr->ident & IDENT_SENSE)))
555 if (IS_FLG(FLG_IDENTIFIED) && !object_known_p(o_ptr))
558 /*** *Identified* ***/
559 if (IS_FLG(FLG_STAR_IDENTIFIED) &&
560 (!object_known_p(o_ptr) || !(o_ptr->ident & IDENT_MENTAL)))
563 /*** Dice boosted (weapon of slaying) ***/
564 if (IS_FLG(FLG_BOOSTED))
566 object_kind *k_ptr = &k_info[o_ptr->k_idx];
568 switch( o_ptr->tval )
574 if ((o_ptr->dd != k_ptr->dd) || (o_ptr->ds != k_ptr->ds))
583 /*** Weapons whic dd*ds is more than nn ***/
584 if (IS_FLG(FLG_MORE_THAN))
586 if (o_ptr->dd * o_ptr->ds < entry->dice)
590 /*** Weapons whic dd*ds is more than nn ***/
591 if (IS_FLG(FLG_MORE_BONUS))
593 if (!object_known_p(o_ptr)) return FALSE;
595 if (k_info[o_ptr->k_idx].pval ||
596 (o_ptr->name2 && e_info[o_ptr->name2].max_pval))
598 if (o_ptr->pval < entry->bonus) return FALSE;
602 if (o_ptr->to_h < entry->bonus &&
603 o_ptr->to_d < entry->bonus &&
604 o_ptr->to_a < entry->bonus &&
605 o_ptr->pval < entry->bonus)
610 /*** Worthless items ***/
611 if (IS_FLG(FLG_WORTHLESS) && object_value(o_ptr) > 0)
614 /*** Artifact object ***/
615 if (IS_FLG(FLG_ARTIFACT))
617 if (!object_known_p(o_ptr) || (!o_ptr->name1 && !o_ptr->art_name))
624 if (!object_known_p(o_ptr) || !o_ptr->name2)
629 if (IS_FLG(FLG_NAMELESS))
634 case TV_SHOT: case TV_ARROW: case TV_BOLT: case TV_BOW:
635 case TV_DIGGING: case TV_HAFTED: case TV_POLEARM: case TV_SWORD:
636 case TV_BOOTS: case TV_GLOVES: case TV_HELM: case TV_CROWN:
637 case TV_SHIELD: case TV_CLOAK:
638 case TV_SOFT_ARMOR: case TV_HARD_ARMOR: case TV_DRAG_ARMOR:
639 case TV_LITE: case TV_AMULET: case TV_RING: case TV_CARD:
640 if ((!object_known_p(o_ptr) || o_ptr->inscription
641 || o_ptr->name1 || o_ptr->name2 || o_ptr->art_name))
650 /*** Unaware items ***/
651 if (IS_FLG(FLG_UNAWARE) && object_aware_p(o_ptr))
654 /*** Wanted monster's corpse/skeletons ***/
655 if (IS_FLG(FLG_WANTED) &&
656 (o_ptr->tval != TV_CORPSE || !object_is_shoukinkubi(o_ptr)))
659 /*** Unique monster's corpse/skeletons/statues ***/
660 if (IS_FLG(FLG_UNIQUE) &&
661 ((o_ptr->tval != TV_CORPSE && o_ptr->tval != TV_STATUE) ||
662 !(r_info[o_ptr->pval].flags1 & RF1_UNIQUE)))
665 /*** Human corpse/skeletons (for Daemon magic) ***/
666 if (IS_FLG(FLG_HUMAN) &&
667 (o_ptr->tval != TV_CORPSE ||
668 !strchr("pht", r_info[o_ptr->pval].d_char)))
671 /*** Unreadable spellbooks ***/
672 if (IS_FLG(FLG_UNREADABLE) &&
673 (o_ptr->tval < TV_LIFE_BOOK ||
674 check_book_realm(o_ptr->tval, o_ptr->sval)))
677 /*** First realm spellbooks ***/
678 if (IS_FLG(FLG_REALM1) &&
679 (REALM1_BOOK != o_ptr->tval ||
680 p_ptr->pclass == CLASS_SORCERER ||
681 p_ptr->pclass == CLASS_RED_MAGE))
684 /*** Second realm spellbooks ***/
685 if (IS_FLG(FLG_REALM2) &&
686 (REALM2_BOOK != o_ptr->tval ||
687 p_ptr->pclass == CLASS_SORCERER ||
688 p_ptr->pclass == CLASS_RED_MAGE))
691 /*** First rank spellbooks ***/
692 if (IS_FLG(FLG_FIRST) &&
693 (o_ptr->tval < TV_LIFE_BOOK || 0 != o_ptr->sval))
696 /*** Second rank spellbooks ***/
697 if (IS_FLG(FLG_SECOND) &&
698 (o_ptr->tval < TV_LIFE_BOOK || 1 != o_ptr->sval))
701 /*** Third rank spellbooks ***/
702 if (IS_FLG(FLG_THIRD) &&
703 (o_ptr->tval < TV_LIFE_BOOK || 2 != o_ptr->sval))
706 /*** Fourth rank spellbooks ***/
707 if (IS_FLG(FLG_FOURTH) &&
708 (o_ptr->tval < TV_LIFE_BOOK || 3 != o_ptr->sval))
712 if (IS_FLG(FLG_WEAPONS))
716 case TV_BOW: case TV_HAFTED: case TV_POLEARM:
717 case TV_SWORD: case TV_DIGGING:
719 default: return FALSE;
722 else if (IS_FLG(FLG_ARMORS))
726 case TV_BOOTS: case TV_GLOVES: case TV_CLOAK: case TV_CROWN:
727 case TV_HELM: case TV_SHIELD: case TV_SOFT_ARMOR:
728 case TV_HARD_ARMOR: case TV_DRAG_ARMOR:
730 default: return FALSE;
733 else if (IS_FLG(FLG_MISSILES))
737 case TV_SHOT: case TV_BOLT: case TV_ARROW:
739 default: return FALSE;
742 else if (IS_FLG(FLG_DEVICES))
746 case TV_SCROLL: case TV_STAFF: case TV_WAND: case TV_ROD:
748 default: return FALSE;
751 else if (IS_FLG(FLG_LIGHTS))
753 if (!(o_ptr->tval == TV_LITE))
756 else if (IS_FLG(FLG_JUNKS))
760 case TV_SKELETON: case TV_BOTTLE:
761 case TV_JUNK: case TV_STATUE:
763 default: return FALSE;
766 else if (IS_FLG(FLG_SPELLBOOKS))
768 if (!(o_ptr->tval >= TV_LIFE_BOOK))
771 else if (IS_FLG(FLG_HAFTED))
773 if (!(o_ptr->tval == TV_HAFTED))
776 else if (IS_FLG(FLG_SHIELDS))
778 if (!(o_ptr->tval == TV_SHIELD))
781 else if (IS_FLG(FLG_BOWS))
783 if (!(o_ptr->tval == TV_BOW))
786 else if (IS_FLG(FLG_RINGS))
788 if (!(o_ptr->tval == TV_RING))
791 else if (IS_FLG(FLG_AMULETS))
793 if (!(o_ptr->tval == TV_AMULET))
796 else if (IS_FLG(FLG_SUITS))
798 if (!(o_ptr->tval == TV_DRAG_ARMOR ||
799 o_ptr->tval == TV_HARD_ARMOR ||
800 o_ptr->tval == TV_SOFT_ARMOR))
803 else if (IS_FLG(FLG_CLOAKS))
805 if (!(o_ptr->tval == TV_CLOAK))
808 else if (IS_FLG(FLG_HELMS))
810 if (!(o_ptr->tval == TV_CROWN || o_ptr->tval == TV_HELM))
813 else if (IS_FLG(FLG_GLOVES))
815 if (!(o_ptr->tval == TV_GLOVES))
818 else if (IS_FLG(FLG_BOOTS))
820 if (!(o_ptr->tval == TV_BOOTS))
824 /* Keyword don't match */
828 if (strncmp(o_name, ptr, strlen(ptr))) return FALSE;
833 if (!strstr_j(o_name, ptr)) return FALSE;
835 if (!strstr(o_name, ptr)) return FALSE;
839 /* TRUE when it need not to be 'collecting' */
840 if (!IS_FLG(FLG_COLLECTING)) return TRUE;
842 /* Check if there is a same item */
843 for (j = 0; j < INVEN_PACK; j++)
846 * 'Collecting' means the item must be absorbed
847 * into an inventory slot.
848 * But an item can not be absorbed into itself!
850 if ((&inventory[j] != o_ptr) &&
851 object_similar(&inventory[j], o_ptr))
861 * A function for Auto-picker/destroyer
862 * Examine whether the object matches to the list of keywords or not.
864 int is_autopick(object_type *o_ptr)
867 char o_name[MAX_NLEN];
869 if (o_ptr->tval == TV_GOLD) return -1;
871 object_desc(o_name, o_ptr, FALSE, 3);
873 /* Force to be lower case string */
874 for (i = 0; o_name[i]; i++)
877 if (iskanji(o_name[i]))
881 if (isupper(o_name[i]))
882 o_name[i] = tolower(o_name[i]);
885 for (i=0; i < max_autopick; i++)
887 autopick_type *entry = &autopick_list[i];
889 if (is_autopick_aux(o_ptr, entry, o_name)) return i;
892 /* No matching entry */
898 * Automatically destroy items in this grid.
900 static bool is_opt_confirm_destroy(object_type *o_ptr)
902 if (!destroy_items) return FALSE;
904 /* Known to be worthless? */
906 if (object_value(o_ptr) > 0) return FALSE;
909 if ((o_ptr->tval >= TV_SHOT) && (o_ptr->tval <= TV_DRAG_ARMOR)) return FALSE;
912 if ((o_ptr->tval == TV_CHEST) && o_ptr->pval) return FALSE;
916 if (o_ptr->tval == TV_CORPSE
917 && object_is_shoukinkubi(o_ptr)) return FALSE;
921 if (o_ptr->tval == TV_CORPSE) return FALSE;
924 if ((o_ptr->tval == TV_SKELETON) || (o_ptr->tval == TV_BOTTLE) || (o_ptr->tval == TV_JUNK) || (o_ptr->tval == TV_STATUE)) return FALSE;
926 if (o_ptr->tval == TV_GOLD) return FALSE;
935 void auto_inscribe_item(int item, int idx)
939 /* Get the item (in the pack) */
940 if (item >= 0) o_ptr = &inventory[item];
942 /* Get the item (on the floor) */
943 else o_ptr = &o_list[0 - item];
945 /* Auto-inscription or Re-inscribe for resistances {%} */
946 if ((idx < 0 || !autopick_list[idx].insc) && !o_ptr->inscription)
949 if (o_ptr->inscription)
950 o_ptr->inscription = inscribe_flags(o_ptr, quark_str(o_ptr->inscription));
952 o_ptr->inscription = inscribe_flags(o_ptr, autopick_list[idx].insc);
954 if (item > INVEN_PACK)
956 /* Redraw inscription */
957 p_ptr->window |= (PW_EQUIP);
959 /* {.} and {$} effect p_ptr->warning and TRC_TELEPORT_SELF */
960 p_ptr->update |= (PU_BONUS);
964 /* Redraw inscription */
965 p_ptr->window |= (PW_INVEN);
971 * Automatically destroy an item if it is to be destroyed
973 bool auto_destroy_item(int item, int autopick_idx, bool wait_optimize)
975 bool destroy = FALSE;
976 char o_name[MAX_NLEN];
979 /* Don't destroy equipped items */
980 if (item > INVEN_PACK) return FALSE;
982 /* Get the item (in the pack) */
983 if (item >= 0) o_ptr = &inventory[item];
985 /* Get the item (on the floor) */
986 else o_ptr = &o_list[0 - item];
988 /* Easy-Auto-Destroyer */
989 if (is_opt_confirm_destroy(o_ptr)) destroy = TRUE;
991 /* Protected by auto-picker */
992 if (autopick_idx >= 0 &&
993 !(autopick_list[autopick_idx].action & DO_AUTODESTROY))
998 /* Auto-picker/destroyer */
999 if (autopick_idx >= 0 &&
1000 (autopick_list[autopick_idx].action & DO_AUTODESTROY))
1004 /* Not to be destroyed */
1005 if (!destroy) return FALSE;
1007 /* Now decided to destroy */
1011 /* Describe the object (with {terrible/special}) */
1012 object_desc(o_name, o_ptr, TRUE, 3);
1015 if (!can_player_destroy_object(o_ptr))
1019 msg_format("%s¤ÏÇ˲õÉÔǽ¤À¡£", o_name);
1021 msg_format("You cannot auto-destroy %s.", o_name);
1028 /* Record name of destroyed item */
1029 COPY(&autopick_last_destroyed_object, o_ptr, object_type);
1031 /* Eliminate the item (from the pack) */
1034 inven_item_increase(item, -(o_ptr->number));
1037 * always optimize equipment.
1038 * optimize inventry only when wait_optimize is FALSE.
1040 if (!wait_optimize || item > INVEN_PACK)
1041 inven_item_optimize(item);
1044 /* Eliminate the item (from the floor) */
1047 delete_object_idx(0 - item);
1050 /* Print a message */
1052 msg_format("%s¤ò¼«Æ°Ç˲õ¤·¤Þ¤¹¡£", o_name);
1054 msg_format("Auto-destroying %s.", o_name);
1062 * Optimize all inventry items after consumption of staves or scrolls.
1064 void optimize_inventry_auto_destroy(void)
1068 for (i = 0; i <= INVEN_PACK; i++)
1069 inven_item_optimize(i);
1074 * Automatically pickup/destroy items in this grid.
1076 void auto_pickup_items(cave_type *c_ptr)
1078 s16b this_o_idx, next_o_idx = 0;
1080 /* Scan the pile of objects */
1081 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1085 /* Acquire object */
1086 object_type *o_ptr = &o_list[this_o_idx];
1088 /* Acquire next object */
1089 next_o_idx = o_ptr->next_o_idx;
1091 idx = is_autopick(o_ptr);
1093 /* Item index for floor -1,-2,-3,... */
1094 auto_inscribe_item((-this_o_idx), idx);
1096 if (idx >= 0 && (autopick_list[idx].action & DO_AUTOPICK))
1100 if (!inven_carry_okay(o_ptr))
1102 char o_name[MAX_NLEN];
1104 /* Describe the object */
1105 object_desc(o_name, o_ptr, TRUE, 3);
1109 msg_format("¥¶¥Ã¥¯¤Ë¤Ï%s¤òÆþ¤ì¤ë·ä´Ö¤¬¤Ê¤¤¡£", o_name);
1111 msg_format("You have no room for %s.", o_name);
1115 py_pickup_aux(this_o_idx);
1122 * When always_pickup is 'yes', we disable
1123 * auto-destroyer from autopick function, and do only
1124 * easy-auto-destroyer.
1128 if (auto_destroy_item((-this_o_idx), idx, FALSE))
1136 * Describe which kind of object is Auto-picked/destroyed
1138 static void describe_autopick(char *buff, autopick_type *entry)
1140 cptr str = entry->name;
1141 byte act = entry->action;
1142 cptr insc = entry->insc;
1148 cptr before_str[100], body_str;
1151 body_str = "¥¢¥¤¥Æ¥à";
1153 /*** Collecting items ***/
1154 /*** Which can be absorbed into a slot as a bundle ***/
1155 if (IS_FLG(FLG_COLLECTING))
1156 before_str[before_n++] = "¼ý½¸Ãæ¤Ç´û¤Ë»ý¤Ã¤Æ¤¤¤ë¥¹¥í¥Ã¥È¤Ë¤Þ¤È¤á¤é¤ì¤ë";
1158 /*** Unidentified ***/
1159 if (IS_FLG(FLG_UNIDENTIFIED))
1160 before_str[before_n++] = "̤´ÕÄê¤Î";
1162 /*** Identified ***/
1163 if (IS_FLG(FLG_IDENTIFIED))
1164 before_str[before_n++] = "´ÕÄêºÑ¤ß¤Î";
1166 /*** *Identified* ***/
1167 if (IS_FLG(FLG_STAR_IDENTIFIED))
1168 before_str[before_n++] = "´°Á´¤Ë´ÕÄêºÑ¤ß¤Î";
1170 /*** Dice boosted (weapon of slaying) ***/
1171 if (IS_FLG(FLG_BOOSTED))
1173 before_str[before_n++] = "¥À¥á¡¼¥¸¥À¥¤¥¹¤¬Ä̾ï¤è¤êÂ礤¤";
1177 /*** Weapons whose dd*ds is more than nn ***/
1178 if (IS_FLG(FLG_MORE_THAN))
1180 static char more_than_desc_str[] = "___";
1181 before_str[before_n++] = "¥À¥á¡¼¥¸¥À¥¤¥¹¤ÎºÇÂçÃͤ¬";
1184 sprintf(more_than_desc_str,"%d", entry->dice);
1185 before_str[before_n++] = more_than_desc_str;
1186 before_str[before_n++] = "°Ê¾å¤Î";
1189 /*** Items whose magical bonus is more than nn ***/
1190 if (IS_FLG(FLG_MORE_BONUS))
1192 static char more_bonus_desc_str[] = "___";
1193 before_str[before_n++] = "½¤ÀµÃͤ¬(+";
1195 sprintf(more_bonus_desc_str,"%d", entry->bonus);
1196 before_str[before_n++] = more_bonus_desc_str;
1197 before_str[before_n++] = ")°Ê¾å¤Î";
1200 /*** Worthless items ***/
1201 if (IS_FLG(FLG_WORTHLESS))
1202 before_str[before_n++] = "Ź¤Ç̵²ÁÃͤÈȽÄꤵ¤ì¤ë";
1205 if (IS_FLG(FLG_ARTIFACT))
1207 before_str[before_n++] = "¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È¤Î";
1212 if (IS_FLG(FLG_EGO))
1214 before_str[before_n++] = "¥¨¥´¥¢¥¤¥Æ¥à¤Î";
1219 if (IS_FLG(FLG_NAMELESS))
1221 before_str[before_n++] = "¥¨¥´¤Ç¤â¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È¤Ç¤â¤Ê¤¤";
1225 /*** Unaware items ***/
1226 if (IS_FLG(FLG_UNAWARE))
1227 before_str[before_n++] = "̤´ÕÄê¤Ç¤½¤Î¸ú²Ì¤âȽÌÀ¤·¤Æ¤¤¤Ê¤¤";
1229 /*** Wanted monster's corpse/skeletons ***/
1230 if (IS_FLG(FLG_WANTED))
1232 before_str[before_n++] = "¥Ï¥ó¥¿¡¼»ö̳½ê¤Ç¾Þ¶â¼ó¤È¤µ¤ì¤Æ¤¤¤ë";
1233 body_str = "»àÂΤä¹ü";
1236 /*** Human corpse/skeletons (for Daemon magic) ***/
1237 if (IS_FLG(FLG_HUMAN))
1239 before_str[before_n++] = "°ËâËâË¡¤Ç»È¤¦¤¿¤á¤Î¿Í´Ö¤ä¥Ò¥å¡¼¥Þ¥Î¥¤¥É¤Î";
1240 body_str = "»àÂΤä¹ü";
1243 /*** Unique monster's corpse/skeletons/statues ***/
1244 if (IS_FLG(FLG_UNIQUE))
1246 before_str[before_n++] = "¥æ¥Ë¡¼¥¯¥â¥ó¥¹¥¿¡¼¤Î";
1247 body_str = "»àÂΤä¹ü";
1250 /*** Unreadable spellbooks ***/
1251 if (IS_FLG(FLG_UNREADABLE))
1253 before_str[before_n++] = "¤¢¤Ê¤¿¤¬Æɤá¤Ê¤¤Îΰè¤Î";
1254 body_str = "ËâË¡½ñ";
1257 /*** First realm spellbooks ***/
1258 if (IS_FLG(FLG_REALM1))
1260 before_str[before_n++] = "Âè°ìÎΰè¤Î";
1261 body_str = "ËâË¡½ñ";
1264 /*** Second realm spellbooks ***/
1265 if (IS_FLG(FLG_REALM2))
1267 before_str[before_n++] = "ÂèÆóÎΰè¤Î";
1268 body_str = "ËâË¡½ñ";
1271 /*** First rank spellbooks ***/
1272 if (IS_FLG(FLG_FIRST))
1274 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î1ºýÌܤÎ";
1275 body_str = "ËâË¡½ñ";
1278 /*** Second rank spellbooks ***/
1279 if (IS_FLG(FLG_SECOND))
1281 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î2ºýÌܤÎ";
1282 body_str = "ËâË¡½ñ";
1285 /*** Third rank spellbooks ***/
1286 if (IS_FLG(FLG_THIRD))
1288 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î3ºýÌܤÎ";
1289 body_str = "ËâË¡½ñ";
1292 /*** Fourth rank spellbooks ***/
1293 if (IS_FLG(FLG_FOURTH))
1295 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î4ºýÌܤÎ";
1296 body_str = "ËâË¡½ñ";
1300 if (IS_FLG(FLG_ITEMS))
1301 ; /* Nothing to do */
1302 else if (IS_FLG(FLG_WEAPONS))
1304 else if (IS_FLG(FLG_ARMORS))
1306 else if (IS_FLG(FLG_MISSILES))
1307 body_str = "ÃƤäÌð¤ä¥¯¥í¥¹¥Ü¥¦¤ÎÌð";
1308 else if (IS_FLG(FLG_DEVICES))
1309 body_str = "´¬Êª¤äËâË¡ËÀ¤ä¾ó¤ä¥í¥Ã¥É";
1310 else if (IS_FLG(FLG_LIGHTS))
1311 body_str = "¸÷¸»ÍѤΥ¢¥¤¥Æ¥à";
1312 else if (IS_FLG(FLG_JUNKS))
1313 body_str = "Àޤ줿ËÀÅù¤Î¥¬¥é¥¯¥¿";
1314 else if (IS_FLG(FLG_SPELLBOOKS))
1315 body_str = "ËâË¡½ñ";
1316 else if (IS_FLG(FLG_HAFTED))
1318 else if (IS_FLG(FLG_SHIELDS))
1320 else if (IS_FLG(FLG_BOWS))
1321 body_str = "¥¹¥ê¥ó¥°¤äµÝ¤ä¥¯¥í¥¹¥Ü¥¦";
1322 else if (IS_FLG(FLG_RINGS))
1324 else if (IS_FLG(FLG_AMULETS))
1325 body_str = "¥¢¥ß¥å¥ì¥Ã¥È";
1326 else if (IS_FLG(FLG_SUITS))
1328 else if (IS_FLG(FLG_CLOAKS))
1329 body_str = "¥¯¥í¡¼¥¯";
1330 else if (IS_FLG(FLG_HELMS))
1331 body_str = "¥Ø¥ë¥á¥Ã¥È¤ä´§";
1332 else if (IS_FLG(FLG_GLOVES))
1334 else if (IS_FLG(FLG_BOOTS))
1335 body_str = "¥Ö¡¼¥Ä";
1339 strcat(buff, "Á´¤Æ¤Î");
1340 else for (i = 0; i < before_n && before_str[i]; i++)
1341 strcat(buff, before_str[i]);
1343 strcat(buff, body_str);
1353 strcat(buff, "¤Ç¡¢Ì¾Á°¤¬¡Ö");
1354 strncat(buff, str, 80);
1356 strcat(buff, "¡×¤Ç»Ï¤Þ¤ë¤â¤Î");
1358 strcat(buff, "¡×¤ò´Þ¤à¤â¤Î");
1363 strncat(buff, format("¤Ë¡Ö%s¡×", insc), 80);
1365 if (strstr(insc, "%%all"))
1366 strcat(buff, "(%%all¤ÏÁ´Ç½ÎϤòɽ¤¹±Ñ»ú¤Îµ¹æ¤ÇÃÖ´¹)");
1367 else if (strstr(insc, "%all"))
1368 strcat(buff, "(%all¤ÏÁ´Ç½ÎϤòɽ¤¹µ¹æ¤ÇÃÖ´¹)");
1369 else if (strstr(insc, "%%"))
1370 strcat(buff, "(%%¤ÏÄɲÃǽÎϤòɽ¤¹±Ñ»ú¤Îµ¹æ¤ÇÃÖ´¹)");
1371 else if (strstr(insc, "%"))
1372 strcat(buff, "(%¤ÏÄɲÃǽÎϤòɽ¤¹µ¹æ¤ÇÃÖ´¹)");
1374 strcat(buff, "¤È¹ï¤ó¤Ç");
1379 if (act & DONT_AUTOPICK)
1380 strcat(buff, "ÊüÃÖ¤¹¤ë¡£");
1381 else if (act & DO_AUTODESTROY)
1382 strcat(buff, "Ç˲õ¤¹¤ë¡£");
1384 strcat(buff, "½¦¤¦¡£");
1386 if (act & DO_DISPLAY)
1388 if (act & DONT_AUTOPICK)
1389 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'N'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
1390 else if (act & DO_AUTODESTROY)
1391 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'K'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
1393 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'M'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
1396 strcat(buff, "Á´ÂΥޥåפˤÏɽ¼¨¤·¤Ê¤¤");
1400 cptr before_str[20], after_str[20], which_str[20], whose_str[20], body_str;
1401 int before_n = 0, after_n = 0, which_n = 0, whose_n = 0;
1405 /*** Collecting items ***/
1406 /*** Which can be absorbed into a slot as a bundle ***/
1407 if (IS_FLG(FLG_COLLECTING))
1408 which_str[which_n++] = "can be absorbed into an existing inventory slot";
1410 /*** Unidentified ***/
1411 if (IS_FLG(FLG_UNIDENTIFIED))
1412 before_str[before_n++] = "unidentified";
1414 /*** Identified ***/
1415 if (IS_FLG(FLG_IDENTIFIED))
1416 before_str[before_n++] = "identified";
1418 /*** *Identified* ***/
1419 if (IS_FLG(FLG_STAR_IDENTIFIED))
1420 before_str[before_n++] = "fully identified";
1422 /*** Worthless items ***/
1423 if (IS_FLG(FLG_WORTHLESS))
1425 before_str[before_n++] = "worthless";
1426 which_str[which_n++] = "can not be sold at stores";
1430 if (IS_FLG(FLG_ARTIFACT))
1432 before_str[before_n++] = "artifact";
1436 if (IS_FLG(FLG_EGO))
1438 before_str[before_n++] = "ego";
1442 if (IS_FLG(FLG_NAMELESS))
1444 body_str = "equipment";
1445 which_str[which_n++] = "is neither ego-item nor artifact";
1448 /*** Unaware items ***/
1449 if (IS_FLG(FLG_UNAWARE))
1451 before_str[before_n++] = "unidentified";
1452 whose_str[whose_n++] = "basic abilities are not known";
1455 /*** Dice boosted (weapon of slaying) ***/
1456 if (IS_FLG(FLG_BOOSTED))
1458 body_str = "weapons";
1459 whose_str[whose_n++] = "damage dice is bigger than normal";
1462 /*** Weapons whose dd*ds is more than nn ***/
1463 if (IS_FLG(FLG_MORE_THAN))
1465 static char more_than_desc_str[] =
1466 "maximum damage from dice is bigger than __";
1467 body_str = "weapons";
1469 sprintf(more_than_desc_str + sizeof(more_than_desc_str) - 3,
1471 whose_str[whose_n++] = more_than_desc_str;
1474 /*** Items whose magical bonus is more than nn ***/
1475 if (IS_FLG(FLG_MORE_BONUS))
1477 static char more_bonus_desc_str[] =
1478 "magical bonus is bigger than (+__)";
1480 sprintf(more_bonus_desc_str + sizeof(more_bonus_desc_str) - 4,
1481 "%d)", entry->bonus);
1482 whose_str[whose_n++] = more_bonus_desc_str;
1485 /*** Wanted monster's corpse/skeletons ***/
1486 if (IS_FLG(FLG_WANTED))
1488 body_str = "corpse or skeletons";
1489 which_str[which_n++] = "is wanted at the Hunter's Office";
1492 /*** Human corpse/skeletons (for Daemon magic) ***/
1493 if (IS_FLG(FLG_HUMAN))
1495 before_str[before_n++] = "humanoid";
1496 body_str = "corpse or skeletons";
1497 which_str[which_n++] = "can be used for Daemon magic";
1500 /*** Unique monster's corpse/skeletons/statues ***/
1501 if (IS_FLG(FLG_UNIQUE))
1503 before_str[before_n++] = "unique monster's";
1504 body_str = "corpse or skeletons";
1507 /*** Unreadable spellbooks ***/
1508 if (IS_FLG(FLG_UNREADABLE))
1510 body_str = "spellbooks";
1511 after_str[after_n++] = "of different realms from yours";
1514 /*** First realm spellbooks ***/
1515 if (IS_FLG(FLG_REALM1))
1517 body_str = "spellbooks";
1518 after_str[after_n++] = "of your first realm";
1521 /*** Second realm spellbooks ***/
1522 if (IS_FLG(FLG_REALM2))
1524 body_str = "spellbooks";
1525 after_str[after_n++] = "of your second realm";
1528 /*** First rank spellbooks ***/
1529 if (IS_FLG(FLG_FIRST))
1531 before_str[before_n++] = "first one of four";
1532 body_str = "spellbooks";
1535 /*** Second rank spellbooks ***/
1536 if (IS_FLG(FLG_SECOND))
1538 before_str[before_n++] = "second one of four";
1539 body_str = "spellbooks";
1542 /*** Third rank spellbooks ***/
1543 if (IS_FLG(FLG_THIRD))
1545 before_str[before_n++] = "third one of four";
1546 body_str = "spellbooks";
1549 /*** Fourth rank spellbooks ***/
1550 if (IS_FLG(FLG_FOURTH))
1552 before_str[before_n++] = "fourth one of four";
1553 body_str = "spellbooks";
1557 if (IS_FLG(FLG_ITEMS))
1558 ; /* Nothing to do */
1559 else if (IS_FLG(FLG_WEAPONS))
1560 body_str = "weapons";
1561 else if (IS_FLG(FLG_ARMORS))
1562 body_str = "armors";
1563 else if (IS_FLG(FLG_MISSILES))
1564 body_str = "shots, arrows or crossbow bolts";
1565 else if (IS_FLG(FLG_DEVICES))
1566 body_str = "scrolls, wands, staves or rods";
1567 else if (IS_FLG(FLG_LIGHTS))
1568 body_str = "light sources";
1569 else if (IS_FLG(FLG_JUNKS))
1570 body_str = "junk such as broken sticks";
1571 else if (IS_FLG(FLG_SPELLBOOKS))
1572 body_str = "spellbooks";
1573 else if (IS_FLG(FLG_HAFTED))
1574 body_str = "hafted weapons";
1575 else if (IS_FLG(FLG_SHIELDS))
1576 body_str = "shields";
1577 else if (IS_FLG(FLG_BOWS))
1578 body_str = "slings, bows or crossbows";
1579 else if (IS_FLG(FLG_RINGS))
1581 else if (IS_FLG(FLG_AMULETS))
1582 body_str = "amulets";
1583 else if (IS_FLG(FLG_SUITS))
1584 body_str = "body armors";
1585 else if (IS_FLG(FLG_CLOAKS))
1586 body_str = "cloaks";
1587 else if (IS_FLG(FLG_HELMS))
1588 body_str = "helms or crowns";
1589 else if (IS_FLG(FLG_GLOVES))
1590 body_str = "gloves";
1591 else if (IS_FLG(FLG_BOOTS))
1594 /* Prepare a string for item name */
1601 whose_str[whose_n++] = "name is beginning with \"";
1604 which_str[which_n++] = "have \"";
1608 /* Describe action flag */
1609 if (act & DONT_AUTOPICK)
1610 strcpy(buff, "Leave on floor ");
1611 else if (act & DO_AUTODESTROY)
1612 strcpy(buff, "Destroy ");
1614 strcpy(buff, "Pickup ");
1616 /* Auto-insctiption */
1619 strncat(buff, format("and inscribe \"%s\"", insc), 80);
1621 if (strstr(insc, "%all"))
1622 strcat(buff, ", replacing %all with code string representing all abilities,");
1623 else if (strstr(insc, "%"))
1624 strcat(buff, ", replacing % with code string representing extra random abilities,");
1626 strcat(buff, " on ");
1631 strcat(buff, "all ");
1632 else for (i = 0; i < before_n && before_str[i]; i++)
1634 strcat(buff, before_str[i]);
1639 strcat(buff, body_str);
1642 for (i = 0; i < after_n && after_str[i]; i++)
1645 strcat(buff, after_str[i]);
1649 for (i = 0; i < whose_n && whose_str[i]; i++)
1652 strcat(buff, " whose ");
1654 strcat(buff, ", and ");
1656 strcat(buff, whose_str[i]);
1659 /* Item name ; whose name is beginning with "str" */
1666 /* whose ..., and which .... */
1667 if (whose_n && which_n)
1668 strcat(buff, ", and ");
1671 for (i = 0; i < which_n && which_str[i]; i++)
1674 strcat(buff, " which ");
1676 strcat(buff, ", and ");
1678 strcat(buff, which_str[i]);
1681 /* Item name ; which have "str" as part of its name */
1684 strncat(buff, str, 80);
1685 strcat(buff, "\" as part of its name");
1689 /* Describe whether it will be displayed on the full map or not */
1690 if (act & DO_DISPLAY)
1692 if (act & DONT_AUTOPICK)
1693 strcat(buff, " Display these items when you press the N key in the full 'M'ap.");
1694 else if (act & DO_AUTODESTROY)
1695 strcat(buff, " Display these items when you press the K key in the full 'M'ap.");
1697 strcat(buff, " Display these items when you press the M key in the full 'M'ap.");
1700 strcat(buff, " Not displayed in the full map.");
1706 #define MAX_LINES 3000
1709 * Read whole lines of a file to memory
1711 static cptr *read_text_lines(cptr filename, bool user)
1713 cptr *lines_list = NULL;
1721 /* Hack -- drop permissions */
1723 path_build(buf, 1024, ANGBAND_DIR_USER, filename);
1727 path_build(buf, 1024, ANGBAND_DIR_PREF, filename);
1731 fff = my_fopen(buf, "r");
1735 /* Allocate list of pointers */
1736 C_MAKE(lines_list, MAX_LINES, cptr);
1739 while (0 == my_fgets(fff, buf, 1024))
1741 lines_list[lines++] = string_make(buf);
1742 if (lines >= MAX_LINES - 1) break;
1745 lines_list[0] = string_make("");
1753 if (!fff) return NULL;
1757 static cptr *read_pickpref_text_lines(void)
1763 sprintf(buf, "picktype-%s.prf", player_name);
1765 sprintf(buf, "pickpref-%s.prf", player_name);
1767 lines_list = read_text_lines(buf, TRUE);
1772 lines_list = read_text_lines("picktype.prf", TRUE);
1774 lines_list = read_text_lines("pickpref.prf", TRUE);
1781 lines_list = read_text_lines("picktype.prf", FALSE);
1783 lines_list = read_text_lines("pickpref.prf", FALSE);
1789 /* Allocate list of pointers */
1790 C_MAKE(lines_list, MAX_LINES, cptr);
1791 lines_list[0] = string_make("");
1797 * Write whole lines of memory to a file.
1799 static bool write_text_lines(cptr filename, cptr *lines_list)
1806 /* Hack -- drop permissions */
1809 /* Build the filename */
1810 path_build(buf, 1024, ANGBAND_DIR_USER, filename);
1813 fff = my_fopen(buf, "w");
1816 for (lines = 0; lines_list[lines]; lines++)
1817 my_fputs(fff, lines_list[lines], 1024);
1825 if (!fff) return FALSE;
1831 * Free memory of lines_list.
1833 static void free_text_lines(cptr *lines_list)
1837 for (lines = 0; lines_list[lines]; lines++)
1838 string_free(lines_list[lines]);
1840 /* free list of pointers */
1841 C_FREE((char **)lines_list, MAX_LINES, char *);
1846 * Delete or insert string
1848 static void toggle_string(cptr *lines_list, int flg, int y)
1850 autopick_type an_entry, *entry = &an_entry;
1852 if (!autopick_new_entry(entry, lines_list[y]))
1855 string_free(lines_list[y]);
1861 lines_list[y] = autopick_line_from_entry_kill(entry);
1865 * Insert return code and split the line
1867 static bool insert_return_code(cptr *lines_list, int cx, int cy)
1869 char buf[MAX_LINELEN];
1872 for (k = 0; lines_list[k]; k++)
1873 /* count number of lines */ ;
1875 if (k >= MAX_LINES - 2) return FALSE;
1878 /* Move down lines */
1880 lines_list[k+1] = lines_list[k];
1882 /* Split current line */
1883 for (i = j = 0; lines_list[cy][i] && i < cx; i++)
1886 if (iskanji(lines_list[cy][i]))
1887 buf[j++] = lines_list[cy][i++];
1889 buf[j++] = lines_list[cy][i];
1892 lines_list[cy+1] = string_make(&lines_list[cy][i]);
1893 string_free(lines_list[cy]);
1894 lines_list[cy] = string_make(buf);
1900 * Get auto-picker entry from o_ptr.
1902 void autopick_entry_from_object(autopick_type *entry, object_type *o_ptr)
1904 char o_name[MAX_NLEN];
1905 object_desc(o_name, o_ptr, FALSE, 0);
1907 entry->name = string_make(o_name);
1908 entry->insc = string_make(quark_str(o_ptr->inscription));
1909 entry->action = DO_AUTOPICK | DO_DISPLAY;
1910 entry->flag[0] = entry->flag[1] = 0L;
1913 if (!object_aware_p(o_ptr))
1914 ADD_FLG(FLG_UNAWARE);
1915 if (object_value(o_ptr) <= 0)
1916 ADD_FLG(FLG_WORTHLESS);
1918 if (object_known_p(o_ptr))
1922 else if (o_ptr->name1 || o_ptr->art_name)
1923 ADD_FLG(FLG_ARTIFACT);
1929 case TV_HAFTED: case TV_POLEARM: case TV_SWORD: case TV_DIGGING:
1930 k_ptr = &k_info[o_ptr->k_idx];
1931 if ((o_ptr->dd != k_ptr->dd) || (o_ptr->ds != k_ptr->ds))
1932 ADD_FLG(FLG_BOOSTED);
1935 if (o_ptr->tval == TV_CORPSE && object_is_shoukinkubi(o_ptr))
1937 REM_FLG(FLG_WORTHLESS);
1938 ADD_FLG(FLG_WANTED);
1941 if ((o_ptr->tval == TV_CORPSE || o_ptr->tval == TV_STATUE)
1942 && (r_info[o_ptr->pval].flags1 & RF1_UNIQUE))
1944 REM_FLG(FLG_WORTHLESS);
1945 ADD_FLG(FLG_UNIQUE);
1948 if (o_ptr->tval == TV_CORPSE && strchr("pht", r_info[o_ptr->pval].d_char))
1950 REM_FLG(FLG_WORTHLESS);
1954 if (o_ptr->tval >= TV_LIFE_BOOK &&
1955 !check_book_realm(o_ptr->tval, o_ptr->sval))
1956 ADD_FLG(FLG_UNREADABLE);
1958 if (REALM1_BOOK == o_ptr->tval &&
1959 p_ptr->pclass != CLASS_SORCERER &&
1960 p_ptr->pclass != CLASS_RED_MAGE)
1961 ADD_FLG(FLG_REALM1);
1963 if (REALM2_BOOK == o_ptr->tval &&
1964 p_ptr->pclass != CLASS_SORCERER &&
1965 p_ptr->pclass != CLASS_RED_MAGE)
1966 ADD_FLG(FLG_REALM2);
1968 if (o_ptr->tval >= TV_LIFE_BOOK && 0 == o_ptr->sval)
1970 if (o_ptr->tval >= TV_LIFE_BOOK && 1 == o_ptr->sval)
1971 ADD_FLG(FLG_SECOND);
1972 if (o_ptr->tval >= TV_LIFE_BOOK && 2 == o_ptr->sval)
1974 if (o_ptr->tval >= TV_LIFE_BOOK && 3 == o_ptr->sval)
1975 ADD_FLG(FLG_FOURTH);
1977 if (o_ptr->tval == TV_SHOT || o_ptr->tval == TV_BOLT
1978 || o_ptr->tval == TV_ARROW)
1979 ADD_FLG(FLG_MISSILES);
1980 else if (o_ptr->tval == TV_SCROLL || o_ptr->tval == TV_STAFF
1981 || o_ptr->tval == TV_WAND || o_ptr->tval == TV_ROD)
1982 ADD_FLG(FLG_DEVICES);
1983 else if (o_ptr->tval == TV_LITE)
1984 ADD_FLG(FLG_LIGHTS);
1985 else if (o_ptr->tval == TV_SKELETON || o_ptr->tval == TV_BOTTLE
1986 || o_ptr->tval == TV_JUNK || o_ptr->tval == TV_STATUE)
1988 else if (o_ptr->tval >= TV_LIFE_BOOK)
1989 ADD_FLG(FLG_SPELLBOOKS);
1990 else if (o_ptr->tval == TV_HAFTED)
1991 ADD_FLG(FLG_HAFTED);
1992 else if (o_ptr->tval == TV_POLEARM || o_ptr->tval == TV_SWORD
1993 || o_ptr->tval == TV_DIGGING)
1994 ADD_FLG(FLG_WEAPONS);
1995 else if (o_ptr->tval == TV_SHIELD)
1996 ADD_FLG(FLG_SHIELDS);
1997 else if (o_ptr->tval == TV_BOW)
1999 else if (o_ptr->tval == TV_RING)
2001 else if (o_ptr->tval == TV_AMULET)
2002 ADD_FLG(FLG_AMULETS);
2003 else if (o_ptr->tval == TV_DRAG_ARMOR || o_ptr->tval == TV_HARD_ARMOR ||
2004 o_ptr->tval == TV_SOFT_ARMOR)
2006 else if (o_ptr->tval == TV_CLOAK)
2007 ADD_FLG(FLG_CLOAKS);
2008 else if (o_ptr->tval == TV_HELM)
2010 else if (o_ptr->tval == TV_GLOVES)
2011 ADD_FLG(FLG_GLOVES);
2012 else if (o_ptr->tval == TV_BOOTS)
2020 * Choose an item and get auto-picker entry from it.
2022 static object_type *choose_object(cptr q, cptr s)
2026 if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR | USE_EQUIP))) return NULL;
2028 /* Get the item (in the pack) */
2029 if (item >= 0) return &inventory[item];
2031 /* Get the item (on the floor) */
2032 else return &o_list[0 - item];
2037 * Choose an item and get auto-picker entry from it.
2039 static bool entry_from_choosed_object(autopick_type *entry)
2046 q = "¤É¤Î¥¢¥¤¥Æ¥à¤òÅÐÏ¿¤·¤Þ¤¹¤«? ";
2047 s = "¥¢¥¤¥Æ¥à¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£";
2049 q = "Entry which item? ";
2050 s = "You have nothing to entry.";
2052 o_ptr = choose_object(q, s);
2053 if (!o_ptr) return FALSE;
2055 autopick_entry_from_object(entry, o_ptr);
2061 * Choose an item or string for search
2063 static bool get_string_for_search(object_type **o_handle, cptr *search_strp)
2067 char buf[MAX_NLEN+20];
2070 int k_flag[MAX_NLEN+20];
2071 char prompt[] = "¸¡º÷(^I:»ý¤Áʪ ^L:Ç˲õ¤µ¤ì¤¿Êª): ";
2073 char prompt[] = "Search key(^I:inven ^L:destroyed): ";
2075 int col = sizeof(prompt) - 1;
2077 if (*search_strp) strcpy(buf, *search_strp);
2080 /* Display prompt */
2083 /* Display the default answer */
2084 Term_erase(col, 0, 255);
2085 Term_putstr(col, 0, -1, TERM_YELLOW, buf);
2094 Term_gotoxy(col + pos, 0);
2096 /* Do not process macros except special keys */
2097 inkey_special = TRUE;
2102 /* Analyze the key */
2111 if (!pos && *o_handle) return TRUE;
2112 string_free(*search_strp);
2113 *search_strp = string_make(buf);
2120 q = "¤É¤Î¥¢¥¤¥Æ¥à¤ò¸¡º÷¤·¤Þ¤¹¤«? ";
2121 s = "¥¢¥¤¥Æ¥à¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£";
2123 q = "Entry which item? ";
2124 s = "You have nothing to entry.";
2126 o_ptr = choose_object(q, s);
2127 if (!o_ptr) return FALSE;
2131 string_free(*search_strp);
2132 object_desc(buf, *o_handle, FALSE, 3);
2133 *search_strp = string_make(format("<%s>", buf));
2137 if (!autopick_last_destroyed_object.k_idx) break;
2138 *o_handle = &autopick_last_destroyed_object;
2140 string_free(*search_strp);
2141 object_desc(buf, *o_handle, FALSE, 3);
2142 *search_strp = string_make(format("<%s>", buf));
2151 if (k_flag[pos]) pos--;
2166 if (pos + 1 < MAX_NLEN)
2174 else if (pos < MAX_NLEN && isprint(i))
2181 if (pos < MAX_NLEN && isprint(i)) buf[pos++] = i;
2190 /* Update the entry */
2191 Term_erase(col, 0, 255);
2192 Term_putstr(col, 0, -1, TERM_WHITE, buf);
2200 * Search next line matches for o_ptr
2202 static bool search_for_object(cptr *lines_list, object_type *o_ptr, int *cxp, int *cyp, bool forward)
2205 autopick_type an_entry, *entry = &an_entry;
2206 char o_name[MAX_NLEN];
2208 object_desc(o_name, o_ptr, FALSE, 3);
2210 /* Force to be lower case string */
2211 for (i = 0; o_name[i]; i++)
2214 if (iskanji(o_name[i]))
2218 if (isupper(o_name[i]))
2219 o_name[i] = tolower(o_name[i]);
2228 if (!lines_list[++i]) break;
2235 if (!autopick_new_entry(entry, lines_list[i])) continue;
2237 if (is_autopick_aux(o_ptr, entry, o_name))
2250 * Search next line matches to the string
2252 static bool search_for_string(cptr *lines_list, cptr search_str, int *cxp, int *cyp, bool forward)
2262 if (!lines_list[++i]) break;
2269 pos = strstr_j(lines_list[i], search_str);
2271 pos = strstr(lines_list[i], search_str);
2275 *cxp = (int)(pos - lines_list[i]);
2286 * Initialize auto-picker preference
2288 void init_autopicker(void)
2290 static const char easy_autopick_inscription[] = "(:=g";
2291 autopick_type entry;
2294 /* Clear old entries */
2295 for( i = 0; i < max_autopick; i++)
2296 autopick_free_entry(&autopick_list[i]);
2300 /* There is always one entry "=g" */
2301 autopick_new_entry(&entry, easy_autopick_inscription);
2302 autopick_list[max_autopick++] = entry;
2307 * Get a trigger key and insert ASCII string for the trigger
2309 static bool insert_macro_line(cptr *lines_list, int cy)
2318 /* Do not process macros */
2324 /* Read the pattern */
2330 /* Do not process macros */
2333 /* Do not wait for keys */
2336 /* Attempt to read a key */
2346 /* Convert the trigger */
2347 ascii_to_text(tmp, buf);
2350 if(!tmp[0]) return FALSE;
2352 /* Insert preference string */
2353 insert_return_code(lines_list, 0, cy);
2354 string_free(lines_list[cy]);
2355 lines_list[cy] = string_make(format("P:%s", tmp));
2357 /* Insert blank action preference line */
2358 insert_return_code(lines_list, 0, cy);
2359 string_free(lines_list[cy]);
2360 lines_list[cy] = string_make("A:");
2367 * Get a command key and insert ASCII string for the key
2369 static bool insert_keymap_line(cptr *lines_list, int cy)
2376 if (rogue_like_commands)
2378 mode = KEYMAP_MODE_ROGUE;
2384 mode = KEYMAP_MODE_ORIG;
2397 /* Convert the trigger */
2398 ascii_to_text(tmp, buf);
2401 if(!tmp[0]) return FALSE;
2403 /* Insert preference string */
2404 insert_return_code(lines_list, 0, cy);
2405 string_free(lines_list[cy]);
2406 lines_list[cy] = string_make(format("C:%d:%s", mode, tmp));
2408 /* Insert blank action preference line */
2409 insert_return_code(lines_list, 0, cy);
2410 string_free(lines_list[cy]);
2411 lines_list[cy] = string_make("A:");
2418 * Description of control commands
2423 static cptr ctrl_command_desc[] =
2426 #define LAST_DESTROYED 6
2427 "^P ^N ^B ^F ¾å²¼º¸±¦¤Ë°ÜÆ°",
2428 "^A ^E ¹Ô¤ÎÀèƬ¡¢½ªÃ¼",
2429 "^Q ÆþÎÏ/¥³¥Þ¥ó¥É¥â¡¼¥ÉÀÚ¤êÂؤ¨",
2430 "^R Êѹ¹¤òÁ´¤Æ¼è¤ê¾Ã¤·¤Æ¸µ¤ËÌ᤹",
2431 "------------------------------------",
2432 "^I »ý¤Áʪ/ÁõÈ÷¤«¤éÁªÂò",
2434 "^K ¥«¡¼¥½¥ë¤«¤é½ªÃ¼¤Þ¤Çºï½ü",
2435 "^Y ºï½ü(^K)¤·¤¿¹Ô¤òÁÞÆþ",
2436 "^C ¼ï²¡¢¿¦¶È¤Î¾ò·ï¼°¤òÁÞÆþ",
2437 "------------------------------------",
2438 "^S Êѹ¹ (!Ç˲õ/~ÊüÃÖ/½¦¤¦)",
2439 "^G \"(\" Á´ÂΥޥåפÇɽ¼¨¤·¤Ê¤¤",
2440 "^O \"#\" ¼«Æ°¹ï¤ß",
2441 "------------------------------------",
2442 "^U ̤´ÕÄê/̤ȽÌÀ/´ÕÄê/*´ÕÄê*",
2444 "^X ̵ÌÃ/¥¨¥´/¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È",
2448 #define LAST_DESTROYED 6
2449 "^P ^N ^B ^F Move Cursor",
2450 "^A ^E Beginning and End of Line",
2451 "^Q Toggle Insert/Command mode",
2452 "^R Revert to Original File",
2453 "------------------------------------",
2454 "^I Object in Inventry/Equipment",
2456 "^K Kill Rest of Line",
2457 "^Y Insert killed(^K) text",
2458 "^C Insert conditional expression",
2459 "------------------------------------",
2460 "^S Toggle(!Destroy/~Leave/Pick)",
2461 "^G \"(\" No display in the 'M'ap",
2462 "^O \"#\" Auto-Inscribe",
2463 "------------------------------------",
2464 "^U Toggle 'identified' state",
2466 "^X Toggle nameless/ego/artifact",
2467 "^Z \"collecting\"",
2473 #define MAX_YANK MAX_LINELEN
2474 #define DIRTY_ALL 0x01
2475 #define DIRTY_COMMAND 0x02
2476 #define DIRTY_MODE 0x04
2477 #define DIRTY_SCREEN 0x08
2478 #define DIRTY_NOT_FOUND 0x10
2481 * In-game editor of Object Auto-picker/Destoryer
2483 void do_cmd_edit_autopick(void)
2485 static int cx = 0, cy = 0;
2486 static int upper = 0, left = 0;
2488 object_type *search_o_ptr = NULL;
2489 cptr search_str = NULL;
2490 cptr last_destroyed = NULL;
2491 char last_destroyed_command[WID_DESC+3];
2492 char yank_buf[MAX_YANK];
2494 autopick_type an_entry, *entry = &an_entry;
2495 char buf[MAX_LINELEN];
2501 int old_upper = -1, old_left = -1;
2503 int key = -1, old_key;
2504 bool repeated_clearing = FALSE;
2505 bool edit_mode = FALSE;
2507 byte dirty_flags = DIRTY_ALL | DIRTY_COMMAND | DIRTY_MODE;
2508 int dirty_line = -1;
2510 int wid, hgt, old_wid = -1, old_hgt = -1;
2512 /* Free old entries */
2515 /* Name of the Last Destroyed Item */
2516 if (autopick_last_destroyed_object.k_idx)
2518 autopick_entry_from_object(entry, &autopick_last_destroyed_object);
2519 last_destroyed = autopick_line_from_entry_kill(entry);
2522 /* Command Description of the Last Destroyed Item */
2525 strncpy(last_destroyed_command, format("^L \"%s\"", last_destroyed), WID_DESC+2);
2526 last_destroyed_command[WID_DESC+2] = '\0';
2531 strcpy(last_destroyed_command, "^L ºÇ¸å¤Ë¼«Æ°Ç˲õ¤·¤¿¥¢¥¤¥Æ¥à̾");
2533 strcpy(last_destroyed_command, "^L Last destroyed object");
2536 ctrl_command_desc[LAST_DESTROYED] = last_destroyed_command;
2538 /* Conditional Expression for Class and Race */
2539 sprintf(classrace, "?:[AND [EQU $RACE %s] [EQU $CLASS %s]]",
2541 rp_ptr->E_title, cp_ptr->E_title
2543 rp_ptr->title, cp_ptr->title
2547 /* Clear yank buffer */
2550 /* Read or initialize whole text */
2551 lines_list = read_pickpref_text_lines();
2553 /* Reset cursor position if needed */
2554 for (i = 0; i < cy; i++)
2563 /* Save the screen */
2566 /* Process requests until done */
2570 Term_get_size(&wid, &hgt);
2573 /* Don't let cursor at second byte of kanji */
2574 for (i = 0; lines_list[cy][i]; i++)
2575 if (iskanji(lines_list[cy][i]))
2586 /* Scroll if necessary */
2587 if (cy < upper || upper + hgt - 4 <= cy)
2588 upper = cy - (hgt-4)/2;
2591 if ((cx < left + 10 && left > 0) || left + wid - WID_DESC - 5 <= cx)
2592 left = cx - (wid - WID_DESC)*2/3;
2596 /* Redraw whole window after resize */
2597 if (old_wid != wid || old_hgt != hgt)
2598 dirty_flags |= DIRTY_SCREEN;
2600 /* Redraw all text after scroll */
2601 else if (old_upper != upper || old_left != left)
2602 dirty_flags |= DIRTY_ALL;
2605 if (dirty_flags & DIRTY_SCREEN)
2607 dirty_flags |= (DIRTY_ALL | DIRTY_COMMAND | DIRTY_MODE);
2613 if (dirty_flags & DIRTY_COMMAND)
2615 /* Display control command */
2616 for (i = 0; ctrl_command_desc[i]; i++)
2617 Term_putstr(wid - WID_DESC, i + 1, WID_DESC, TERM_WHITE, ctrl_command_desc[i]);
2620 /* Redraw mode line */
2621 if (dirty_flags & DIRTY_MODE)
2623 int sepa_length = wid - WID_DESC;
2626 for (i = 0; i < sepa_length; i++)
2632 strncpy(buf + sepa_length - 21, " (INSERT MODE) ", 16);
2634 strncpy(buf + sepa_length - 21, " (COMMAND MODE) ", 16);
2636 Term_putstr(0, hgt - 3, sepa_length, (byte) (edit_mode ? TERM_YELLOW : TERM_WHITE), buf);
2639 /* Dump up to 20, or hgt-4, lines of messages */
2640 for (i = 0; i < hgt - 4; i++)
2645 /* clean or dirty? */
2646 if (!(dirty_flags & DIRTY_ALL) && (dirty_line != upper+i))
2649 msg = lines_list[upper+i];
2652 /* Apply horizontal scroll */
2653 for (j = 0; *msg; msg++, j++)
2655 if (j == left) break;
2671 Term_erase(0, i + 1, wid - WID_DESC);
2673 /* Dump the messages, bottom to top */
2674 Term_putstr(leftcol, i + 1, wid - WID_DESC - 1, TERM_WHITE, msg);
2677 for (; i < hgt - 4; i++)
2680 Term_erase(0, i + 1, wid - WID_DESC);
2683 /* Display header line */
2686 prt("^Q ESC ¤Ç¥³¥Þ¥ó¥É¥â¡¼¥É¤Ø°Ü¹Ô¡¢Ä̾ï¤Îʸ»ú¤Ï¤½¤Î¤Þ¤ÞÆþÎÏ", 0, 0);
2688 prt("q _ ¤Ç½ªÎ»¡¢hjkl2468 ¤Ç°ÜÆ°¡¢^Q a i ¤ÇÆþÎϥ⡼¥É", 0, 0);
2691 prt("Press ^Q ESC to command mode, any letters to insert", 0, 0);
2693 prt("Press q _ to quit, hjkl2468 to move, ^Q a i to insert mode", 0, 0);
2695 /* Display current position */
2696 prt (format("(%d,%d)", cx, cy), 0, 70);
2698 /* Display information when updated */
2699 if (old_cy != cy || (dirty_flags & (DIRTY_ALL | DIRTY_NOT_FOUND)) || dirty_line == cy)
2701 /* Clear information line */
2702 Term_erase(0, hgt - 3 + 1, wid);
2703 Term_erase(0, hgt - 3 + 2, wid);
2705 /* Display information */
2706 if (dirty_flags & DIRTY_NOT_FOUND)
2709 prt(format("¥Ñ¥¿¡¼¥ó¤¬¸«¤Ä¤«¤ê¤Þ¤»¤ó: %s", search_str), hgt - 3 + 1, 0);
2711 prt(format("Pattern not found: %s", search_str), hgt - 3 + 1, 0);
2714 else if (lines_list[cy][0] == '#')
2717 prt("¤³¤Î¹Ô¤Ï¥³¥á¥ó¥È¤Ç¤¹¡£", hgt - 3 + 1, 0);
2719 prt("This line is comment.", hgt - 3 + 1, 0);
2722 else if (lines_list[cy][1] == ':')
2724 switch(lines_list[cy][0])
2728 prt("¤³¤Î¹Ô¤Ï¾ò·ïʬ´ô¼°¤Ç¤¹¡£", hgt - 3 + 1, 0);
2730 prt("This line is Conditional Expression.", hgt - 3 + 1, 0);
2735 prt("¤³¤Î¹Ô¤Ï¥Þ¥¯¥í¤Î¼Â¹ÔÆâÍƤòÄêµÁ¤·¤Þ¤¹¡£", hgt - 3 + 1, 0);
2737 prt("This line defines Macro action.", hgt - 3 + 1, 0);
2742 prt("¤³¤Î¹Ô¤Ï¥Þ¥¯¥í¤Î¥È¥ê¥¬¡¼¡¦¥¡¼¤òÄêµÁ¤·¤Þ¤¹¡£", hgt - 3 + 1, 0);
2744 prt("This line defines Macro trigger key.", hgt - 3 + 1, 0);
2749 prt("¤³¤Î¹Ô¤Ï¥¡¼ÇÛÃÖ¤òÄêµÁ¤·¤Þ¤¹¡£", hgt - 3 + 1, 0);
2751 prt("This line defines Keymap.", hgt - 3 + 1, 0);
2757 /* Get description of an autopicker preference line */
2758 else if (autopick_new_entry(entry, lines_list[cy]))
2763 describe_autopick(buf, entry);
2765 roff_to_buf(buf, 81, temp);
2767 for (i = 0; i< 2; i++)
2773 prt(t, hgt - 3 + 1 + i, 0);
2777 autopick_free_entry(entry);
2782 Term_gotoxy(cx - left, cy - upper + 1);
2788 /* Save old key and location */
2796 /* Do not process macros except special keys */
2797 inkey_special = TRUE;
2808 /* Mode line is now dirty */
2809 dirty_flags |= DIRTY_MODE;
2812 /* Insert a character */
2813 else if (!iscntrl(key&0xff))
2817 /* Save preceding string */
2818 for (i = j = 0; lines_list[cy][i] && i < cx; i++)
2819 buf[j++] = lines_list[cy][i];
2821 /* Add a character */
2827 if (j+2 < MAX_LINELEN)
2839 if (j+1 < MAX_LINELEN)
2845 for (; lines_list[cy][i] && j + 1 < MAX_LINELEN; i++)
2846 buf[j++] = lines_list[cy][i];
2849 /* Replace current line with new line */
2850 string_free(lines_list[cy]);
2851 lines_list[cy] = string_make(buf);
2853 /* Move to correct collumn */
2854 len = strlen(lines_list[cy]);
2855 if (len < cx) cx = len;
2864 if (key == 'q' || key == '_') break;
2871 /* Mode line is now dirty */
2872 dirty_flags |= DIRTY_MODE;
2875 if (!autopick_new_entry(entry, lines_list[cy]))
2877 if (old_key != key) repeated_clearing = FALSE;
2880 if (lines_list[cy + 1]) cy++;
2884 string_free(lines_list[cy]);
2888 if (entry->action & DONT_AUTOPICK)
2889 repeated_clearing = TRUE;
2891 repeated_clearing = FALSE;
2894 entry->action &= ~DO_AUTODESTROY;
2895 if (!repeated_clearing)
2897 entry->action &= ~DO_AUTOPICK;
2898 entry->action |= DONT_AUTOPICK;
2902 entry->action &= ~DONT_AUTOPICK;
2903 entry->action |= DO_AUTOPICK;
2906 lines_list[cy] = autopick_line_from_entry_kill(entry);
2912 if (lines_list[cy + 1]) cy++;
2916 if (!autopick_new_entry(entry, lines_list[cy]))
2918 if (old_key != key) repeated_clearing = FALSE;
2921 if (lines_list[cy + 1]) cy++;
2925 string_free(lines_list[cy]);
2929 if (entry->action & DO_AUTODESTROY)
2930 repeated_clearing = TRUE;
2932 repeated_clearing = FALSE;
2935 entry->action &= ~DONT_AUTOPICK;
2936 if (!repeated_clearing)
2938 entry->action &= ~DO_AUTOPICK;
2939 entry->action |= DO_AUTODESTROY;
2943 entry->action &= ~DO_AUTODESTROY;
2944 entry->action |= DO_AUTOPICK;
2947 lines_list[cy] = autopick_line_from_entry_kill(entry);
2953 if (lines_list[cy + 1]) cy++;
2957 /* Toggle display on the 'M'ap */
2958 if (!autopick_new_entry(entry, lines_list[cy]))
2960 if (old_key != key) repeated_clearing = FALSE;
2963 if (lines_list[cy + 1]) cy++;
2967 string_free(lines_list[cy]);
2971 if (entry->action & DO_DISPLAY)
2972 repeated_clearing = TRUE;
2974 repeated_clearing = FALSE;
2977 if (!repeated_clearing)
2978 entry->action |= DO_DISPLAY;
2980 entry->action &= ~DO_DISPLAY;
2982 lines_list[cy] = autopick_line_from_entry_kill(entry);
2988 if (lines_list[cy + 1]) cy++;
3008 while (cy < upper + hgt-4 && lines_list[cy + 1])
3013 while (0 < cy && upper <= cy)
3015 while (0 < upper && cy + 1 < upper + hgt - 4)
3024 while (lines_list[cy + 1])
3030 Term_erase(0, cy - upper + 1, wid - WID_DESC);
3034 Term_putstr(0, cy - upper + 1, wid - WID_DESC - 1, TERM_YELLOW, "P:<¥È¥ê¥¬¡¼¥¡¼>: ");
3036 Term_putstr(0, cy - upper + 1, wid - WID_DESC - 1, TERM_YELLOW, "P:<Trigger key>: ");
3038 if (insert_macro_line(lines_list, cy))
3040 /* Prepare to input action */
3045 dirty_flags |= DIRTY_ALL;
3046 dirty_flags |= DIRTY_MODE;
3053 Term_erase(0, cy - upper + 1, wid - WID_DESC);
3057 Term_putstr(0, cy - upper + 1, wid - WID_DESC - 1, TERM_YELLOW, format("C:%d:<¥³¥Þ¥ó¥É¥¡¼>: ", (rogue_like_commands ? KEYMAP_MODE_ROGUE : KEYMAP_MODE_ORIG)));
3059 Term_putstr(0, cy - upper + 1, wid - WID_DESC - 1, TERM_YELLOW, format("C:%d:<Keypress>: ", (rogue_like_commands ? KEYMAP_MODE_ROGUE : KEYMAP_MODE_ORIG)));
3062 if (insert_keymap_line(lines_list, cy))
3064 /* Prepare to input action */
3069 dirty_flags |= DIRTY_ALL;
3070 dirty_flags |= DIRTY_MODE;
3074 /* Become dirty because of item/equip menu */
3075 dirty_flags |= DIRTY_SCREEN;
3077 if (!get_string_for_search(&search_o_ptr, &search_str))
3084 if (!search_for_object(lines_list, search_o_ptr, &cx, &cy, TRUE)) dirty_flags |= DIRTY_NOT_FOUND;
3086 else if (search_str)
3088 if (!search_for_string(lines_list, search_str, &cx, &cy, TRUE)) dirty_flags |= DIRTY_NOT_FOUND;
3094 if (!search_for_object(lines_list, search_o_ptr, &cx, &cy, FALSE)) dirty_flags |= DIRTY_NOT_FOUND;
3096 else if (search_str)
3098 if (!search_for_string(lines_list, search_str, &cx, &cy, FALSE)) dirty_flags |= DIRTY_NOT_FOUND;
3107 /* Beginning of line */
3115 len = strlen(lines_list[cy]);
3116 if (len < cx) cx = len;
3121 cx = strlen(lines_list[cy]);
3125 /* Insert a conditinal expression line */
3126 insert_return_code(lines_list, 0, cy);
3127 lines_list[cy] = string_make(classrace);
3129 insert_return_code(lines_list, 0, cy);
3130 lines_list[cy] = string_make("?:1");
3134 dirty_flags |= DIRTY_ALL;
3138 cx = strlen(lines_list[cy]);
3143 if (iskanji(lines_list[cy][cx])) cx++;
3146 len = strlen(lines_list[cy]);
3149 if (lines_list[cy + 1])
3159 /* Toggle display on the 'M'ap */
3160 if (!autopick_new_entry(entry, lines_list[cy]))
3162 string_free(lines_list[cy]);
3164 if (entry->action & DO_DISPLAY)
3166 entry->action &= ~DO_DISPLAY;
3171 entry->action |= DO_DISPLAY;
3175 lines_list[cy] = autopick_line_from_entry_kill(entry);
3181 /* Insert choosen item name */
3182 if (!entry_from_choosed_object(entry))
3184 /* Now dirty because of item/equip menu */
3185 dirty_flags |= DIRTY_SCREEN;
3188 tmp = autopick_line_from_entry_kill(entry);
3192 insert_return_code(lines_list, 0, cy);
3193 lines_list[cy] = tmp;
3196 /* Now dirty because of item/equip menu */
3197 dirty_flags |= DIRTY_SCREEN;
3201 /* Insert a name of last destroyed item */
3204 insert_return_code(lines_list, 0, cy);
3205 lines_list[cy] = string_make(last_destroyed);
3209 dirty_flags |= DIRTY_ALL;
3212 case '\n': case '\r':
3213 /* Split a line or insert end of line */
3214 insert_return_code(lines_list, cx, cy);
3219 dirty_flags |= DIRTY_ALL;
3223 if (lines_list[cy + 1]) cy++;
3226 /* Prepare to write auto-inscription text */
3227 if (!autopick_new_entry(entry, lines_list[cy]))
3229 string_free(lines_list[cy]);
3231 if (!entry->insc) entry->insc = string_make("");
3233 lines_list[cy] = autopick_line_from_entry_kill(entry);
3235 /* Move to collumn for auto inscription */
3236 for (cx = 0; lines_list[cy][cx]; cx++)
3237 if (lines_list[cy][cx] == '#') break;
3243 dirty_flags |= DIRTY_MODE;
3251 edit_mode = !edit_mode;
3253 /* Mode line is now dirty */
3254 dirty_flags |= DIRTY_MODE;
3257 /* Revert to original */
3259 if (!get_check("Á´¤Æ¤ÎÊѹ¹¤òÇË´þ¤·¤Æ¸µ¤Î¾õÂÖ¤ËÌᤷ¤Þ¤¹¡£¤è¤í¤·¤¤¤Ç¤¹¤«¡© "))
3261 if (!get_check("Discard all change and revert to original file. Are you sure? "))
3265 free_text_lines(lines_list);
3266 lines_list = read_pickpref_text_lines();
3267 dirty_flags |= DIRTY_ALL | DIRTY_MODE;
3272 /* Rotate action; pickup/destroy/leave */
3273 if (!autopick_new_entry(entry, lines_list[cy]))
3275 string_free(lines_list[cy]);
3277 if (entry->action & DO_AUTOPICK)
3279 entry->action &= ~DO_AUTOPICK;
3280 entry->action |= DO_AUTODESTROY;
3282 else if (entry->action & DO_AUTODESTROY)
3284 entry->action &= ~DO_AUTODESTROY;
3285 entry->action |= DONT_AUTOPICK;
3287 else if (entry->action & DONT_AUTOPICK)
3289 entry->action &= ~DONT_AUTOPICK;
3290 entry->action |= DO_AUTOPICK;
3293 lines_list[cy] = autopick_line_from_entry_kill(entry);
3303 /* Rotate identify-state; identified/unidentified/... */
3304 if (!autopick_new_entry(entry, lines_list[cy]))
3306 string_free(lines_list[cy]);
3308 if (IS_FLG(FLG_UNIDENTIFIED))
3310 REM_FLG(FLG_UNIDENTIFIED);
3311 ADD_FLG(FLG_UNAWARE);
3312 REM_FLG(FLG_IDENTIFIED);
3313 REM_FLG(FLG_STAR_IDENTIFIED);
3315 else if (IS_FLG(FLG_UNAWARE))
3317 REM_FLG(FLG_UNIDENTIFIED);
3318 REM_FLG(FLG_UNAWARE);
3319 ADD_FLG(FLG_IDENTIFIED);
3320 REM_FLG(FLG_STAR_IDENTIFIED);
3322 else if (IS_FLG(FLG_STAR_IDENTIFIED))
3324 REM_FLG(FLG_UNIDENTIFIED);
3325 REM_FLG(FLG_UNAWARE);
3326 REM_FLG(FLG_IDENTIFIED);
3327 REM_FLG(FLG_STAR_IDENTIFIED);
3329 else if (IS_FLG(FLG_IDENTIFIED))
3331 REM_FLG(FLG_UNIDENTIFIED);
3332 REM_FLG(FLG_UNAWARE);
3333 REM_FLG(FLG_IDENTIFIED);
3334 ADD_FLG(FLG_STAR_IDENTIFIED);
3338 ADD_FLG(FLG_UNIDENTIFIED);
3339 REM_FLG(FLG_UNAWARE);
3340 REM_FLG(FLG_IDENTIFIED);
3341 REM_FLG(FLG_STAR_IDENTIFIED);
3344 lines_list[cy] = autopick_line_from_entry_kill(entry);
3351 while (cy < upper + hgt-4 && lines_list[cy + 1])
3356 /* Toggle 'worthless' */
3357 toggle_string(lines_list, FLG_WORTHLESS, cy);
3362 /* Rotate within nameless, ego, artifact */
3363 if (!autopick_new_entry(entry, lines_list[cy]))
3365 string_free(lines_list[cy]);
3367 if (IS_FLG(FLG_NAMELESS))
3369 REM_FLG(FLG_NAMELESS);
3371 REM_FLG(FLG_ARTIFACT);
3373 else if (IS_FLG(FLG_EGO))
3375 REM_FLG(FLG_NAMELESS);
3377 ADD_FLG(FLG_ARTIFACT);
3379 else if (IS_FLG(FLG_ARTIFACT))
3381 REM_FLG(FLG_NAMELESS);
3383 REM_FLG(FLG_ARTIFACT);
3387 ADD_FLG(FLG_NAMELESS);
3389 REM_FLG(FLG_ARTIFACT);
3392 lines_list[cy] = autopick_line_from_entry_kill(entry);
3399 /* Paste killed text */
3400 if (strlen(yank_buf))
3404 for (j = 0; yank_buf[j]; j += strlen(yank_buf + j) + 1)
3406 if (ret && '\n' == yank_buf[j])
3412 /* Split current line */
3413 insert_return_code(lines_list, cx, cy);
3415 /* Save preceding string */
3416 for(i = 0; lines_list[cy][i]; i++)
3417 buf[i] = lines_list[cy][i];
3419 /* Paste yank buffer */
3420 if ('\n' != yank_buf[j])
3423 while (yank_buf[k] && i < MAX_LINELEN-1)
3424 buf[i++] = yank_buf[k++];
3430 string_free(lines_list[cy]);
3431 lines_list[cy] = string_make(buf);
3433 /* Move to the beggining of next line */
3439 dirty_flags |= DIRTY_ALL;
3443 /* Toggle 'collecting' */
3444 toggle_string(lines_list, FLG_COLLECTING, cy);
3450 /* Kill rest of line */
3451 if ((uint)cx > strlen(lines_list[cy]))
3452 cx = (int)strlen(lines_list[cy]);
3454 /* Save preceding string */
3455 for (i = 0; lines_list[cy][i] && i < cx; i++)
3458 if (iskanji(lines_list[cy][i]))
3460 buf[i] = lines_list[cy][i];
3464 buf[i] = lines_list[cy][i];
3471 j += strlen(yank_buf + j) + 1;
3473 /* Copy following to yank buffer */
3474 if (lines_list[cy][i])
3476 while (lines_list[cy][i] && j < MAX_YANK - 2)
3477 yank_buf[j++] = lines_list[cy][i++];
3482 if (j < MAX_YANK - 2)
3483 yank_buf[j++] = '\n';
3486 yank_buf[j++] = '\0';
3489 /* Replace current line with 'preceding string' */
3490 string_free(lines_list[cy]);
3491 lines_list[cy] = string_make(buf);
3503 /* DELETE == go forward + BACK SPACE */
3505 if (iskanji(lines_list[cy][cx])) cx++;
3513 len = strlen(lines_list[cy]);
3516 if (lines_list[cy + 1])
3530 /* delete a return code and union two lines */
3532 cx = strlen(lines_list[cy-1]);
3533 strcpy(buf, lines_list[cy-1]);
3534 strcat(buf, lines_list[cy]);
3535 string_free(lines_list[cy-1]);
3536 string_free(lines_list[cy]);
3537 lines_list[cy-1] = string_make(buf);
3538 for (i = cy; lines_list[i+1]; i++)
3539 lines_list[i] = lines_list[i+1];
3540 lines_list[i] = NULL;
3544 dirty_flags |= DIRTY_ALL;
3548 for (i = j = 0; lines_list[cy][i] && i < cx; i++)
3552 if (iskanji(lines_list[cy][i]))
3553 buf[j++] = lines_list[cy][i++];
3555 buf[j++] = lines_list[cy][i];
3562 for (; lines_list[cy][i]; i++)
3563 buf[j++] = lines_list[cy][i];
3565 string_free(lines_list[cy]);
3566 lines_list[cy] = string_make(buf);
3575 /* Restore the screen */
3579 sprintf(buf, "picktype-%s.prf", player_name);
3581 sprintf(buf, "pickpref-%s.prf", player_name);
3583 write_text_lines(buf, lines_list);
3584 free_text_lines(lines_list);
3586 string_free(last_destroyed);
3588 /* Reload autopick pref */
3589 process_pickpref_file(buf);