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;
1758 #define PT_DEFAULT 0
1759 #define PT_WITH_PNAME 1
1761 static cptr *read_pickpref_text_lines(int *filename_mode_p)
1767 sprintf(buf, "picktype-%s.prf", player_name);
1769 sprintf(buf, "pickpref-%s.prf", player_name);
1771 lines_list = read_text_lines(buf, TRUE);
1776 lines_list = read_text_lines("picktype.prf", TRUE);
1778 lines_list = read_text_lines("pickpref.prf", TRUE);
1780 *filename_mode_p = PT_DEFAULT;
1786 lines_list = read_text_lines("picktype.prf", FALSE);
1788 lines_list = read_text_lines("pickpref.prf", FALSE);
1790 *filename_mode_p = PT_WITH_PNAME;
1795 /* Allocate list of pointers */
1796 C_MAKE(lines_list, MAX_LINES, cptr);
1797 lines_list[0] = string_make("");
1798 *filename_mode_p = PT_WITH_PNAME;
1804 * Write whole lines of memory to a file.
1806 static bool write_text_lines(cptr filename, cptr *lines_list)
1813 /* Hack -- drop permissions */
1816 /* Build the filename */
1817 path_build(buf, 1024, ANGBAND_DIR_USER, filename);
1820 fff = my_fopen(buf, "w");
1823 for (lines = 0; lines_list[lines]; lines++)
1824 my_fputs(fff, lines_list[lines], 1024);
1832 if (!fff) return FALSE;
1838 * Free memory of lines_list.
1840 static void free_text_lines(cptr *lines_list)
1844 for (lines = 0; lines_list[lines]; lines++)
1845 string_free(lines_list[lines]);
1847 /* free list of pointers */
1848 C_FREE((char **)lines_list, MAX_LINES, char *);
1853 * Delete or insert string
1855 static void toggle_string(cptr *lines_list, int flg, int y)
1857 autopick_type an_entry, *entry = &an_entry;
1859 if (!autopick_new_entry(entry, lines_list[y]))
1862 string_free(lines_list[y]);
1868 lines_list[y] = autopick_line_from_entry_kill(entry);
1872 * Insert return code and split the line
1874 static bool insert_return_code(cptr *lines_list, int cx, int cy)
1876 char buf[MAX_LINELEN];
1879 for (k = 0; lines_list[k]; k++)
1880 /* count number of lines */ ;
1882 if (k >= MAX_LINES - 2) return FALSE;
1885 /* Move down lines */
1887 lines_list[k+1] = lines_list[k];
1889 /* Split current line */
1890 for (i = j = 0; lines_list[cy][i] && i < cx; i++)
1893 if (iskanji(lines_list[cy][i]))
1894 buf[j++] = lines_list[cy][i++];
1896 buf[j++] = lines_list[cy][i];
1899 lines_list[cy+1] = string_make(&lines_list[cy][i]);
1900 string_free(lines_list[cy]);
1901 lines_list[cy] = string_make(buf);
1907 * Get auto-picker entry from o_ptr.
1909 void autopick_entry_from_object(autopick_type *entry, object_type *o_ptr)
1911 char o_name[MAX_NLEN];
1912 object_desc(o_name, o_ptr, FALSE, 0);
1914 entry->name = string_make(o_name);
1915 entry->insc = string_make(quark_str(o_ptr->inscription));
1916 entry->action = DO_AUTOPICK | DO_DISPLAY;
1917 entry->flag[0] = entry->flag[1] = 0L;
1920 if (!object_aware_p(o_ptr))
1921 ADD_FLG(FLG_UNAWARE);
1922 if (object_value(o_ptr) <= 0)
1923 ADD_FLG(FLG_WORTHLESS);
1925 if (object_known_p(o_ptr))
1929 else if (o_ptr->name1 || o_ptr->art_name)
1930 ADD_FLG(FLG_ARTIFACT);
1936 case TV_HAFTED: case TV_POLEARM: case TV_SWORD: case TV_DIGGING:
1937 k_ptr = &k_info[o_ptr->k_idx];
1938 if ((o_ptr->dd != k_ptr->dd) || (o_ptr->ds != k_ptr->ds))
1939 ADD_FLG(FLG_BOOSTED);
1942 if (o_ptr->tval == TV_CORPSE && object_is_shoukinkubi(o_ptr))
1944 REM_FLG(FLG_WORTHLESS);
1945 ADD_FLG(FLG_WANTED);
1948 if ((o_ptr->tval == TV_CORPSE || o_ptr->tval == TV_STATUE)
1949 && (r_info[o_ptr->pval].flags1 & RF1_UNIQUE))
1951 REM_FLG(FLG_WORTHLESS);
1952 ADD_FLG(FLG_UNIQUE);
1955 if (o_ptr->tval == TV_CORPSE && strchr("pht", r_info[o_ptr->pval].d_char))
1957 REM_FLG(FLG_WORTHLESS);
1961 if (o_ptr->tval >= TV_LIFE_BOOK &&
1962 !check_book_realm(o_ptr->tval, o_ptr->sval))
1963 ADD_FLG(FLG_UNREADABLE);
1965 if (REALM1_BOOK == o_ptr->tval &&
1966 p_ptr->pclass != CLASS_SORCERER &&
1967 p_ptr->pclass != CLASS_RED_MAGE)
1968 ADD_FLG(FLG_REALM1);
1970 if (REALM2_BOOK == o_ptr->tval &&
1971 p_ptr->pclass != CLASS_SORCERER &&
1972 p_ptr->pclass != CLASS_RED_MAGE)
1973 ADD_FLG(FLG_REALM2);
1975 if (o_ptr->tval >= TV_LIFE_BOOK && 0 == o_ptr->sval)
1977 if (o_ptr->tval >= TV_LIFE_BOOK && 1 == o_ptr->sval)
1978 ADD_FLG(FLG_SECOND);
1979 if (o_ptr->tval >= TV_LIFE_BOOK && 2 == o_ptr->sval)
1981 if (o_ptr->tval >= TV_LIFE_BOOK && 3 == o_ptr->sval)
1982 ADD_FLG(FLG_FOURTH);
1984 if (o_ptr->tval == TV_SHOT || o_ptr->tval == TV_BOLT
1985 || o_ptr->tval == TV_ARROW)
1986 ADD_FLG(FLG_MISSILES);
1987 else if (o_ptr->tval == TV_SCROLL || o_ptr->tval == TV_STAFF
1988 || o_ptr->tval == TV_WAND || o_ptr->tval == TV_ROD)
1989 ADD_FLG(FLG_DEVICES);
1990 else if (o_ptr->tval == TV_LITE)
1991 ADD_FLG(FLG_LIGHTS);
1992 else if (o_ptr->tval == TV_SKELETON || o_ptr->tval == TV_BOTTLE
1993 || o_ptr->tval == TV_JUNK || o_ptr->tval == TV_STATUE)
1995 else if (o_ptr->tval >= TV_LIFE_BOOK)
1996 ADD_FLG(FLG_SPELLBOOKS);
1997 else if (o_ptr->tval == TV_HAFTED)
1998 ADD_FLG(FLG_HAFTED);
1999 else if (o_ptr->tval == TV_POLEARM || o_ptr->tval == TV_SWORD
2000 || o_ptr->tval == TV_DIGGING)
2001 ADD_FLG(FLG_WEAPONS);
2002 else if (o_ptr->tval == TV_SHIELD)
2003 ADD_FLG(FLG_SHIELDS);
2004 else if (o_ptr->tval == TV_BOW)
2006 else if (o_ptr->tval == TV_RING)
2008 else if (o_ptr->tval == TV_AMULET)
2009 ADD_FLG(FLG_AMULETS);
2010 else if (o_ptr->tval == TV_DRAG_ARMOR || o_ptr->tval == TV_HARD_ARMOR ||
2011 o_ptr->tval == TV_SOFT_ARMOR)
2013 else if (o_ptr->tval == TV_CLOAK)
2014 ADD_FLG(FLG_CLOAKS);
2015 else if (o_ptr->tval == TV_HELM)
2017 else if (o_ptr->tval == TV_GLOVES)
2018 ADD_FLG(FLG_GLOVES);
2019 else if (o_ptr->tval == TV_BOOTS)
2027 * Choose an item and get auto-picker entry from it.
2029 static object_type *choose_object(cptr q, cptr s)
2033 if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR | USE_EQUIP))) return NULL;
2035 /* Get the item (in the pack) */
2036 if (item >= 0) return &inventory[item];
2038 /* Get the item (on the floor) */
2039 else return &o_list[0 - item];
2044 * Choose an item and get auto-picker entry from it.
2046 static bool entry_from_choosed_object(autopick_type *entry)
2053 q = "¤É¤Î¥¢¥¤¥Æ¥à¤òÅÐÏ¿¤·¤Þ¤¹¤«? ";
2054 s = "¥¢¥¤¥Æ¥à¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£";
2056 q = "Entry which item? ";
2057 s = "You have nothing to entry.";
2059 o_ptr = choose_object(q, s);
2060 if (!o_ptr) return FALSE;
2062 autopick_entry_from_object(entry, o_ptr);
2068 * Choose an item or string for search
2070 static bool get_string_for_search(object_type **o_handle, cptr *search_strp)
2074 char buf[MAX_NLEN+20];
2077 int k_flag[MAX_NLEN+20];
2078 char prompt[] = "¸¡º÷(^I:»ý¤Áʪ ^L:Ç˲õ¤µ¤ì¤¿Êª): ";
2080 char prompt[] = "Search key(^I:inven ^L:destroyed): ";
2082 int col = sizeof(prompt) - 1;
2084 if (*search_strp) strcpy(buf, *search_strp);
2087 /* Display prompt */
2090 /* Display the default answer */
2091 Term_erase(col, 0, 255);
2092 Term_putstr(col, 0, -1, TERM_YELLOW, buf);
2101 Term_gotoxy(col + pos, 0);
2103 /* Do not process macros except special keys */
2104 inkey_special = TRUE;
2109 /* Analyze the key */
2118 if (!pos && *o_handle) return TRUE;
2119 string_free(*search_strp);
2120 *search_strp = string_make(buf);
2127 q = "¤É¤Î¥¢¥¤¥Æ¥à¤ò¸¡º÷¤·¤Þ¤¹¤«? ";
2128 s = "¥¢¥¤¥Æ¥à¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£";
2130 q = "Entry which item? ";
2131 s = "You have nothing to entry.";
2133 o_ptr = choose_object(q, s);
2134 if (!o_ptr) return FALSE;
2138 string_free(*search_strp);
2139 object_desc(buf, *o_handle, FALSE, 3);
2140 *search_strp = string_make(format("<%s>", buf));
2144 if (!autopick_last_destroyed_object.k_idx) break;
2145 *o_handle = &autopick_last_destroyed_object;
2147 string_free(*search_strp);
2148 object_desc(buf, *o_handle, FALSE, 3);
2149 *search_strp = string_make(format("<%s>", buf));
2158 if (k_flag[pos]) pos--;
2173 if (pos + 1 < MAX_NLEN)
2181 else if (pos < MAX_NLEN && isprint(i))
2188 if (pos < MAX_NLEN && isprint(i)) buf[pos++] = i;
2197 /* Update the entry */
2198 Term_erase(col, 0, 255);
2199 Term_putstr(col, 0, -1, TERM_WHITE, buf);
2207 * Search next line matches for o_ptr
2209 static bool search_for_object(cptr *lines_list, object_type *o_ptr, int *cxp, int *cyp, bool forward)
2212 autopick_type an_entry, *entry = &an_entry;
2213 char o_name[MAX_NLEN];
2215 object_desc(o_name, o_ptr, FALSE, 3);
2217 /* Force to be lower case string */
2218 for (i = 0; o_name[i]; i++)
2221 if (iskanji(o_name[i]))
2225 if (isupper(o_name[i]))
2226 o_name[i] = tolower(o_name[i]);
2235 if (!lines_list[++i]) break;
2242 if (!autopick_new_entry(entry, lines_list[i])) continue;
2244 if (is_autopick_aux(o_ptr, entry, o_name))
2257 * Search next line matches to the string
2259 static bool search_for_string(cptr *lines_list, cptr search_str, int *cxp, int *cyp, bool forward)
2269 if (!lines_list[++i]) break;
2276 pos = strstr_j(lines_list[i], search_str);
2278 pos = strstr(lines_list[i], search_str);
2282 *cxp = (int)(pos - lines_list[i]);
2293 * Initialize auto-picker preference
2295 void init_autopicker(void)
2297 static const char easy_autopick_inscription[] = "(:=g";
2298 autopick_type entry;
2301 /* Clear old entries */
2302 for( i = 0; i < max_autopick; i++)
2303 autopick_free_entry(&autopick_list[i]);
2307 /* There is always one entry "=g" */
2308 autopick_new_entry(&entry, easy_autopick_inscription);
2309 autopick_list[max_autopick++] = entry;
2314 * Get a trigger key and insert ASCII string for the trigger
2316 static bool insert_macro_line(cptr *lines_list, int cy)
2325 /* Do not process macros */
2331 /* Read the pattern */
2337 /* Do not process macros */
2340 /* Do not wait for keys */
2343 /* Attempt to read a key */
2353 /* Convert the trigger */
2354 ascii_to_text(tmp, buf);
2357 if(!tmp[0]) return FALSE;
2359 /* Insert preference string */
2360 insert_return_code(lines_list, 0, cy);
2361 string_free(lines_list[cy]);
2362 lines_list[cy] = string_make(format("P:%s", tmp));
2364 /* Insert blank action preference line */
2365 insert_return_code(lines_list, 0, cy);
2366 string_free(lines_list[cy]);
2367 lines_list[cy] = string_make("A:");
2374 * Get a command key and insert ASCII string for the key
2376 static bool insert_keymap_line(cptr *lines_list, int cy)
2383 if (rogue_like_commands)
2385 mode = KEYMAP_MODE_ROGUE;
2391 mode = KEYMAP_MODE_ORIG;
2404 /* Convert the trigger */
2405 ascii_to_text(tmp, buf);
2408 if(!tmp[0]) return FALSE;
2410 /* Insert preference string */
2411 insert_return_code(lines_list, 0, cy);
2412 string_free(lines_list[cy]);
2413 lines_list[cy] = string_make(format("C:%d:%s", mode, tmp));
2415 /* Insert blank action preference line */
2416 insert_return_code(lines_list, 0, cy);
2417 string_free(lines_list[cy]);
2418 lines_list[cy] = string_make("A:");
2425 * Description of control commands
2430 static cptr ctrl_command_desc[] =
2433 #define LAST_DESTROYED 6
2434 "^P ^N ^B ^F ¾å²¼º¸±¦¤Ë°ÜÆ°",
2435 "^A ^E ¹Ô¤ÎÀèƬ¡¢½ªÃ¼",
2436 "^Q ÆþÎÏ/¥³¥Þ¥ó¥É¥â¡¼¥ÉÀÚ¤êÂؤ¨",
2437 "^R Êѹ¹¤òÁ´¤Æ¼è¤ê¾Ã¤·¤Æ¸µ¤ËÌ᤹",
2438 "------------------------------------",
2439 "^I »ý¤Áʪ/ÁõÈ÷¤«¤éÁªÂò",
2441 "^K ¥«¡¼¥½¥ë¤«¤é½ªÃ¼¤Þ¤Çºï½ü",
2442 "^Y ºï½ü(^K)¤·¤¿¹Ô¤òÁÞÆþ",
2443 "^C ¼ï²¡¢¿¦¶È¤Î¾ò·ï¼°¤òÁÞÆþ",
2444 "------------------------------------",
2445 "^S Êѹ¹ (!Ç˲õ/~ÊüÃÖ/½¦¤¦)",
2446 "^G \"(\" Á´ÂΥޥåפÇɽ¼¨¤·¤Ê¤¤",
2447 "^O \"#\" ¼«Æ°¹ï¤ß",
2448 "------------------------------------",
2449 "^U ̤´ÕÄê/̤ȽÌÀ/´ÕÄê/*´ÕÄê*",
2451 "^X ̵ÌÃ/¥¨¥´/¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È",
2455 #define LAST_DESTROYED 6
2456 "^P ^N ^B ^F Move Cursor",
2457 "^A ^E Beginning and End of Line",
2458 "^Q Toggle Insert/Command mode",
2459 "^R Revert to Original File",
2460 "------------------------------------",
2461 "^I Object in Inventry/Equipment",
2463 "^K Kill Rest of Line",
2464 "^Y Insert killed(^K) text",
2465 "^C Insert conditional expression",
2466 "------------------------------------",
2467 "^S Toggle(!Destroy/~Leave/Pick)",
2468 "^G \"(\" No display in the 'M'ap",
2469 "^O \"#\" Auto-Inscribe",
2470 "------------------------------------",
2471 "^U Toggle 'identified' state",
2473 "^X Toggle nameless/ego/artifact",
2474 "^Z \"collecting\"",
2480 #define MAX_YANK MAX_LINELEN
2481 #define DIRTY_ALL 0x01
2482 #define DIRTY_COMMAND 0x02
2483 #define DIRTY_MODE 0x04
2484 #define DIRTY_SCREEN 0x08
2485 #define DIRTY_NOT_FOUND 0x10
2488 * In-game editor of Object Auto-picker/Destoryer
2490 void do_cmd_edit_autopick(void)
2492 static int cx = 0, cy = 0;
2493 static int upper = 0, left = 0;
2495 object_type *search_o_ptr = NULL;
2496 cptr search_str = NULL;
2497 cptr last_destroyed = NULL;
2498 char last_destroyed_command[WID_DESC+3];
2499 char yank_buf[MAX_YANK];
2501 autopick_type an_entry, *entry = &an_entry;
2502 char buf[MAX_LINELEN];
2504 int filename_mode = PT_WITH_PNAME;
2509 int old_upper = -1, old_left = -1;
2511 int key = -1, old_key;
2512 bool repeated_clearing = FALSE;
2513 bool edit_mode = FALSE;
2515 byte dirty_flags = DIRTY_ALL | DIRTY_COMMAND | DIRTY_MODE;
2516 int dirty_line = -1;
2518 int wid, hgt, old_wid = -1, old_hgt = -1;
2520 /* Free old entries */
2523 /* Name of the Last Destroyed Item */
2524 if (autopick_last_destroyed_object.k_idx)
2526 autopick_entry_from_object(entry, &autopick_last_destroyed_object);
2527 last_destroyed = autopick_line_from_entry_kill(entry);
2530 /* Command Description of the Last Destroyed Item */
2533 strncpy(last_destroyed_command, format("^L \"%s\"", last_destroyed), WID_DESC+2);
2534 last_destroyed_command[WID_DESC+2] = '\0';
2539 strcpy(last_destroyed_command, "^L ºÇ¸å¤Ë¼«Æ°Ç˲õ¤·¤¿¥¢¥¤¥Æ¥à̾");
2541 strcpy(last_destroyed_command, "^L Last destroyed object");
2544 ctrl_command_desc[LAST_DESTROYED] = last_destroyed_command;
2546 /* Conditional Expression for Class and Race */
2547 sprintf(classrace, "?:[AND [EQU $RACE %s] [EQU $CLASS %s]]",
2549 rp_ptr->E_title, cp_ptr->E_title
2551 rp_ptr->title, cp_ptr->title
2555 /* Clear yank buffer */
2558 /* Read or initialize whole text */
2559 lines_list = read_pickpref_text_lines(&filename_mode);
2561 /* Reset cursor position if needed */
2562 for (i = 0; i < cy; i++)
2571 /* Save the screen */
2574 /* Process requests until done */
2578 Term_get_size(&wid, &hgt);
2581 /* Don't let cursor at second byte of kanji */
2582 for (i = 0; lines_list[cy][i]; i++)
2583 if (iskanji(lines_list[cy][i]))
2594 /* Scroll if necessary */
2595 if (cy < upper || upper + hgt - 4 <= cy)
2596 upper = cy - (hgt-4)/2;
2599 if ((cx < left + 10 && left > 0) || left + wid - WID_DESC - 5 <= cx)
2600 left = cx - (wid - WID_DESC)*2/3;
2604 /* Redraw whole window after resize */
2605 if (old_wid != wid || old_hgt != hgt)
2606 dirty_flags |= DIRTY_SCREEN;
2608 /* Redraw all text after scroll */
2609 else if (old_upper != upper || old_left != left)
2610 dirty_flags |= DIRTY_ALL;
2613 if (dirty_flags & DIRTY_SCREEN)
2615 dirty_flags |= (DIRTY_ALL | DIRTY_COMMAND | DIRTY_MODE);
2621 if (dirty_flags & DIRTY_COMMAND)
2623 /* Display control command */
2624 for (i = 0; ctrl_command_desc[i]; i++)
2625 Term_putstr(wid - WID_DESC, i + 1, WID_DESC, TERM_WHITE, ctrl_command_desc[i]);
2628 /* Redraw mode line */
2629 if (dirty_flags & DIRTY_MODE)
2631 int sepa_length = wid - WID_DESC;
2634 for (i = 0; i < sepa_length; i++)
2640 strncpy(buf + sepa_length - 21, " (INSERT MODE) ", 16);
2642 strncpy(buf + sepa_length - 21, " (COMMAND MODE) ", 16);
2644 Term_putstr(0, hgt - 3, sepa_length, (byte) (edit_mode ? TERM_YELLOW : TERM_WHITE), buf);
2647 /* Dump up to 20, or hgt-4, lines of messages */
2648 for (i = 0; i < hgt - 4; i++)
2653 /* clean or dirty? */
2654 if (!(dirty_flags & DIRTY_ALL) && (dirty_line != upper+i))
2657 msg = lines_list[upper+i];
2660 /* Apply horizontal scroll */
2661 for (j = 0; *msg; msg++, j++)
2663 if (j == left) break;
2679 Term_erase(0, i + 1, wid - WID_DESC);
2681 /* Dump the messages, bottom to top */
2682 Term_putstr(leftcol, i + 1, wid - WID_DESC - 1, TERM_WHITE, msg);
2685 for (; i < hgt - 4; i++)
2688 Term_erase(0, i + 1, wid - WID_DESC);
2691 /* Display header line */
2694 prt("^Q ESC ¤Ç¥³¥Þ¥ó¥É¥â¡¼¥É¤Ø°Ü¹Ô¡¢Ä̾ï¤Îʸ»ú¤Ï¤½¤Î¤Þ¤ÞÆþÎÏ", 0, 0);
2696 prt("q _ ¤Ç½ªÎ»¡¢hjkl2468 ¤Ç°ÜÆ°¡¢^Q a i ¤ÇÆþÎϥ⡼¥É", 0, 0);
2699 prt("Press ^Q ESC to command mode, any letters to insert", 0, 0);
2701 prt("Press q _ to quit, hjkl2468 to move, ^Q a i to insert mode", 0, 0);
2703 /* Display current position */
2704 prt (format("(%d,%d)", cx, cy), 0, 70);
2706 /* Display information when updated */
2707 if (old_cy != cy || (dirty_flags & (DIRTY_ALL | DIRTY_NOT_FOUND)) || dirty_line == cy)
2709 /* Clear information line */
2710 Term_erase(0, hgt - 3 + 1, wid);
2711 Term_erase(0, hgt - 3 + 2, wid);
2713 /* Display information */
2714 if (dirty_flags & DIRTY_NOT_FOUND)
2717 prt(format("¥Ñ¥¿¡¼¥ó¤¬¸«¤Ä¤«¤ê¤Þ¤»¤ó: %s", search_str), hgt - 3 + 1, 0);
2719 prt(format("Pattern not found: %s", search_str), hgt - 3 + 1, 0);
2722 else if (lines_list[cy][0] == '#')
2725 prt("¤³¤Î¹Ô¤Ï¥³¥á¥ó¥È¤Ç¤¹¡£", hgt - 3 + 1, 0);
2727 prt("This line is comment.", hgt - 3 + 1, 0);
2730 else if (lines_list[cy][1] == ':')
2732 switch(lines_list[cy][0])
2736 prt("¤³¤Î¹Ô¤Ï¾ò·ïʬ´ô¼°¤Ç¤¹¡£", hgt - 3 + 1, 0);
2738 prt("This line is Conditional Expression.", hgt - 3 + 1, 0);
2743 prt("¤³¤Î¹Ô¤Ï¥Þ¥¯¥í¤Î¼Â¹ÔÆâÍƤòÄêµÁ¤·¤Þ¤¹¡£", hgt - 3 + 1, 0);
2745 prt("This line defines Macro action.", hgt - 3 + 1, 0);
2750 prt("¤³¤Î¹Ô¤Ï¥Þ¥¯¥í¤Î¥È¥ê¥¬¡¼¡¦¥¡¼¤òÄêµÁ¤·¤Þ¤¹¡£", hgt - 3 + 1, 0);
2752 prt("This line defines Macro trigger key.", hgt - 3 + 1, 0);
2757 prt("¤³¤Î¹Ô¤Ï¥¡¼ÇÛÃÖ¤òÄêµÁ¤·¤Þ¤¹¡£", hgt - 3 + 1, 0);
2759 prt("This line defines Keymap.", hgt - 3 + 1, 0);
2765 /* Get description of an autopicker preference line */
2766 else if (autopick_new_entry(entry, lines_list[cy]))
2771 describe_autopick(buf, entry);
2773 roff_to_buf(buf, 81, temp);
2775 for (i = 0; i< 2; i++)
2781 prt(t, hgt - 3 + 1 + i, 0);
2785 autopick_free_entry(entry);
2790 Term_gotoxy(cx - left, cy - upper + 1);
2796 /* Save old key and location */
2804 /* Do not process macros except special keys */
2805 inkey_special = TRUE;
2816 /* Mode line is now dirty */
2817 dirty_flags |= DIRTY_MODE;
2820 /* Insert a character */
2821 else if (!iscntrl(key&0xff))
2825 /* Save preceding string */
2826 for (i = j = 0; lines_list[cy][i] && i < cx; i++)
2827 buf[j++] = lines_list[cy][i];
2829 /* Add a character */
2835 if (j+2 < MAX_LINELEN)
2847 if (j+1 < MAX_LINELEN)
2853 for (; lines_list[cy][i] && j + 1 < MAX_LINELEN; i++)
2854 buf[j++] = lines_list[cy][i];
2857 /* Replace current line with new line */
2858 string_free(lines_list[cy]);
2859 lines_list[cy] = string_make(buf);
2861 /* Move to correct collumn */
2862 len = strlen(lines_list[cy]);
2863 if (len < cx) cx = len;
2872 if (key == 'q' || key == '_') break;
2879 /* Mode line is now dirty */
2880 dirty_flags |= DIRTY_MODE;
2883 if (!autopick_new_entry(entry, lines_list[cy]))
2885 if (old_key != key) repeated_clearing = FALSE;
2888 if (lines_list[cy + 1]) cy++;
2892 string_free(lines_list[cy]);
2896 if (entry->action & DONT_AUTOPICK)
2897 repeated_clearing = TRUE;
2899 repeated_clearing = FALSE;
2902 entry->action &= ~DO_AUTODESTROY;
2903 if (!repeated_clearing)
2905 entry->action &= ~DO_AUTOPICK;
2906 entry->action |= DONT_AUTOPICK;
2910 entry->action &= ~DONT_AUTOPICK;
2911 entry->action |= DO_AUTOPICK;
2914 lines_list[cy] = autopick_line_from_entry_kill(entry);
2920 if (lines_list[cy + 1]) cy++;
2924 if (!autopick_new_entry(entry, lines_list[cy]))
2926 if (old_key != key) repeated_clearing = FALSE;
2929 if (lines_list[cy + 1]) cy++;
2933 string_free(lines_list[cy]);
2937 if (entry->action & DO_AUTODESTROY)
2938 repeated_clearing = TRUE;
2940 repeated_clearing = FALSE;
2943 entry->action &= ~DONT_AUTOPICK;
2944 if (!repeated_clearing)
2946 entry->action &= ~DO_AUTOPICK;
2947 entry->action |= DO_AUTODESTROY;
2951 entry->action &= ~DO_AUTODESTROY;
2952 entry->action |= DO_AUTOPICK;
2955 lines_list[cy] = autopick_line_from_entry_kill(entry);
2961 if (lines_list[cy + 1]) cy++;
2965 /* Toggle display on the 'M'ap */
2966 if (!autopick_new_entry(entry, lines_list[cy]))
2968 if (old_key != key) repeated_clearing = FALSE;
2971 if (lines_list[cy + 1]) cy++;
2975 string_free(lines_list[cy]);
2979 if (entry->action & DO_DISPLAY)
2980 repeated_clearing = TRUE;
2982 repeated_clearing = FALSE;
2985 if (!repeated_clearing)
2986 entry->action |= DO_DISPLAY;
2988 entry->action &= ~DO_DISPLAY;
2990 lines_list[cy] = autopick_line_from_entry_kill(entry);
2996 if (lines_list[cy + 1]) cy++;
3016 while (cy < upper + hgt-4 && lines_list[cy + 1])
3021 while (0 < cy && upper <= cy)
3023 while (0 < upper && cy + 1 < upper + hgt - 4)
3032 while (lines_list[cy + 1])
3038 Term_erase(0, cy - upper + 1, wid - WID_DESC);
3042 Term_putstr(0, cy - upper + 1, wid - WID_DESC - 1, TERM_YELLOW, "P:<¥È¥ê¥¬¡¼¥¡¼>: ");
3044 Term_putstr(0, cy - upper + 1, wid - WID_DESC - 1, TERM_YELLOW, "P:<Trigger key>: ");
3046 if (insert_macro_line(lines_list, cy))
3048 /* Prepare to input action */
3053 dirty_flags |= DIRTY_ALL;
3054 dirty_flags |= DIRTY_MODE;
3061 Term_erase(0, cy - upper + 1, wid - WID_DESC);
3065 Term_putstr(0, cy - upper + 1, wid - WID_DESC - 1, TERM_YELLOW, format("C:%d:<¥³¥Þ¥ó¥É¥¡¼>: ", (rogue_like_commands ? KEYMAP_MODE_ROGUE : KEYMAP_MODE_ORIG)));
3067 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)));
3070 if (insert_keymap_line(lines_list, cy))
3072 /* Prepare to input action */
3077 dirty_flags |= DIRTY_ALL;
3078 dirty_flags |= DIRTY_MODE;
3082 /* Become dirty because of item/equip menu */
3083 dirty_flags |= DIRTY_SCREEN;
3085 if (!get_string_for_search(&search_o_ptr, &search_str))
3092 if (!search_for_object(lines_list, search_o_ptr, &cx, &cy, TRUE)) dirty_flags |= DIRTY_NOT_FOUND;
3094 else if (search_str)
3096 if (!search_for_string(lines_list, search_str, &cx, &cy, TRUE)) dirty_flags |= DIRTY_NOT_FOUND;
3102 if (!search_for_object(lines_list, search_o_ptr, &cx, &cy, FALSE)) dirty_flags |= DIRTY_NOT_FOUND;
3104 else if (search_str)
3106 if (!search_for_string(lines_list, search_str, &cx, &cy, FALSE)) dirty_flags |= DIRTY_NOT_FOUND;
3115 /* Beginning of line */
3123 len = strlen(lines_list[cy]);
3124 if (len < cx) cx = len;
3129 cx = strlen(lines_list[cy]);
3133 /* Insert a conditinal expression line */
3134 insert_return_code(lines_list, 0, cy);
3135 lines_list[cy] = string_make(classrace);
3137 insert_return_code(lines_list, 0, cy);
3138 lines_list[cy] = string_make("?:1");
3142 dirty_flags |= DIRTY_ALL;
3146 cx = strlen(lines_list[cy]);
3151 if (iskanji(lines_list[cy][cx])) cx++;
3154 len = strlen(lines_list[cy]);
3157 if (lines_list[cy + 1])
3167 /* Toggle display on the 'M'ap */
3168 if (!autopick_new_entry(entry, lines_list[cy]))
3170 string_free(lines_list[cy]);
3172 if (entry->action & DO_DISPLAY)
3174 entry->action &= ~DO_DISPLAY;
3179 entry->action |= DO_DISPLAY;
3183 lines_list[cy] = autopick_line_from_entry_kill(entry);
3189 /* Insert choosen item name */
3190 if (!entry_from_choosed_object(entry))
3192 /* Now dirty because of item/equip menu */
3193 dirty_flags |= DIRTY_SCREEN;
3196 tmp = autopick_line_from_entry_kill(entry);
3200 insert_return_code(lines_list, 0, cy);
3201 lines_list[cy] = tmp;
3204 /* Now dirty because of item/equip menu */
3205 dirty_flags |= DIRTY_SCREEN;
3209 /* Insert a name of last destroyed item */
3212 insert_return_code(lines_list, 0, cy);
3213 lines_list[cy] = string_make(last_destroyed);
3217 dirty_flags |= DIRTY_ALL;
3220 case '\n': case '\r':
3221 /* Split a line or insert end of line */
3222 insert_return_code(lines_list, cx, cy);
3227 dirty_flags |= DIRTY_ALL;
3231 if (lines_list[cy + 1]) cy++;
3234 /* Prepare to write auto-inscription text */
3235 if (!autopick_new_entry(entry, lines_list[cy]))
3237 string_free(lines_list[cy]);
3239 if (!entry->insc) entry->insc = string_make("");
3241 lines_list[cy] = autopick_line_from_entry_kill(entry);
3243 /* Move to collumn for auto inscription */
3244 for (cx = 0; lines_list[cy][cx]; cx++)
3245 if (lines_list[cy][cx] == '#') break;
3251 dirty_flags |= DIRTY_MODE;
3259 edit_mode = !edit_mode;
3261 /* Mode line is now dirty */
3262 dirty_flags |= DIRTY_MODE;
3265 /* Revert to original */
3267 if (!get_check("Á´¤Æ¤ÎÊѹ¹¤òÇË´þ¤·¤Æ¸µ¤Î¾õÂÖ¤ËÌᤷ¤Þ¤¹¡£¤è¤í¤·¤¤¤Ç¤¹¤«¡© "))
3269 if (!get_check("Discard all change and revert to original file. Are you sure? "))
3273 free_text_lines(lines_list);
3274 lines_list = read_pickpref_text_lines(&filename_mode);
3275 dirty_flags |= DIRTY_ALL | DIRTY_MODE;
3280 /* Rotate action; pickup/destroy/leave */
3281 if (!autopick_new_entry(entry, lines_list[cy]))
3283 string_free(lines_list[cy]);
3285 if (entry->action & DO_AUTOPICK)
3287 entry->action &= ~DO_AUTOPICK;
3288 entry->action |= DO_AUTODESTROY;
3290 else if (entry->action & DO_AUTODESTROY)
3292 entry->action &= ~DO_AUTODESTROY;
3293 entry->action |= DONT_AUTOPICK;
3295 else if (entry->action & DONT_AUTOPICK)
3297 entry->action &= ~DONT_AUTOPICK;
3298 entry->action |= DO_AUTOPICK;
3301 lines_list[cy] = autopick_line_from_entry_kill(entry);
3311 /* Rotate identify-state; identified/unidentified/... */
3312 if (!autopick_new_entry(entry, lines_list[cy]))
3314 string_free(lines_list[cy]);
3316 if (IS_FLG(FLG_UNIDENTIFIED))
3318 REM_FLG(FLG_UNIDENTIFIED);
3319 ADD_FLG(FLG_UNAWARE);
3320 REM_FLG(FLG_IDENTIFIED);
3321 REM_FLG(FLG_STAR_IDENTIFIED);
3323 else if (IS_FLG(FLG_UNAWARE))
3325 REM_FLG(FLG_UNIDENTIFIED);
3326 REM_FLG(FLG_UNAWARE);
3327 ADD_FLG(FLG_IDENTIFIED);
3328 REM_FLG(FLG_STAR_IDENTIFIED);
3330 else if (IS_FLG(FLG_STAR_IDENTIFIED))
3332 REM_FLG(FLG_UNIDENTIFIED);
3333 REM_FLG(FLG_UNAWARE);
3334 REM_FLG(FLG_IDENTIFIED);
3335 REM_FLG(FLG_STAR_IDENTIFIED);
3337 else if (IS_FLG(FLG_IDENTIFIED))
3339 REM_FLG(FLG_UNIDENTIFIED);
3340 REM_FLG(FLG_UNAWARE);
3341 REM_FLG(FLG_IDENTIFIED);
3342 ADD_FLG(FLG_STAR_IDENTIFIED);
3346 ADD_FLG(FLG_UNIDENTIFIED);
3347 REM_FLG(FLG_UNAWARE);
3348 REM_FLG(FLG_IDENTIFIED);
3349 REM_FLG(FLG_STAR_IDENTIFIED);
3352 lines_list[cy] = autopick_line_from_entry_kill(entry);
3359 while (cy < upper + hgt-4 && lines_list[cy + 1])
3364 /* Toggle 'worthless' */
3365 toggle_string(lines_list, FLG_WORTHLESS, cy);
3370 /* Rotate within nameless, ego, artifact */
3371 if (!autopick_new_entry(entry, lines_list[cy]))
3373 string_free(lines_list[cy]);
3375 if (IS_FLG(FLG_NAMELESS))
3377 REM_FLG(FLG_NAMELESS);
3379 REM_FLG(FLG_ARTIFACT);
3381 else if (IS_FLG(FLG_EGO))
3383 REM_FLG(FLG_NAMELESS);
3385 ADD_FLG(FLG_ARTIFACT);
3387 else if (IS_FLG(FLG_ARTIFACT))
3389 REM_FLG(FLG_NAMELESS);
3391 REM_FLG(FLG_ARTIFACT);
3395 ADD_FLG(FLG_NAMELESS);
3397 REM_FLG(FLG_ARTIFACT);
3400 lines_list[cy] = autopick_line_from_entry_kill(entry);
3407 /* Paste killed text */
3408 if (strlen(yank_buf))
3412 for (j = 0; yank_buf[j]; j += strlen(yank_buf + j) + 1)
3414 if (ret && '\n' == yank_buf[j])
3420 /* Split current line */
3421 insert_return_code(lines_list, cx, cy);
3423 /* Save preceding string */
3424 for(i = 0; lines_list[cy][i]; i++)
3425 buf[i] = lines_list[cy][i];
3427 /* Paste yank buffer */
3428 if ('\n' != yank_buf[j])
3431 while (yank_buf[k] && i < MAX_LINELEN-1)
3432 buf[i++] = yank_buf[k++];
3438 string_free(lines_list[cy]);
3439 lines_list[cy] = string_make(buf);
3441 /* Move to the beggining of next line */
3447 dirty_flags |= DIRTY_ALL;
3451 /* Toggle 'collecting' */
3452 toggle_string(lines_list, FLG_COLLECTING, cy);
3458 /* Kill rest of line */
3459 if ((uint)cx > strlen(lines_list[cy]))
3460 cx = (int)strlen(lines_list[cy]);
3462 /* Save preceding string */
3463 for (i = 0; lines_list[cy][i] && i < cx; i++)
3466 if (iskanji(lines_list[cy][i]))
3468 buf[i] = lines_list[cy][i];
3472 buf[i] = lines_list[cy][i];
3479 j += strlen(yank_buf + j) + 1;
3481 /* Copy following to yank buffer */
3482 if (lines_list[cy][i])
3484 while (lines_list[cy][i] && j < MAX_YANK - 2)
3485 yank_buf[j++] = lines_list[cy][i++];
3490 if (j < MAX_YANK - 2)
3491 yank_buf[j++] = '\n';
3494 yank_buf[j++] = '\0';
3497 /* Replace current line with 'preceding string' */
3498 string_free(lines_list[cy]);
3499 lines_list[cy] = string_make(buf);
3511 /* DELETE == go forward + BACK SPACE */
3513 if (iskanji(lines_list[cy][cx])) cx++;
3521 len = strlen(lines_list[cy]);
3524 if (lines_list[cy + 1])
3538 /* delete a return code and union two lines */
3540 cx = strlen(lines_list[cy-1]);
3541 strcpy(buf, lines_list[cy-1]);
3542 strcat(buf, lines_list[cy]);
3543 string_free(lines_list[cy-1]);
3544 string_free(lines_list[cy]);
3545 lines_list[cy-1] = string_make(buf);
3546 for (i = cy; lines_list[i+1]; i++)
3547 lines_list[i] = lines_list[i+1];
3548 lines_list[i] = NULL;
3552 dirty_flags |= DIRTY_ALL;
3556 for (i = j = 0; lines_list[cy][i] && i < cx; i++)
3560 if (iskanji(lines_list[cy][i]))
3561 buf[j++] = lines_list[cy][i++];
3563 buf[j++] = lines_list[cy][i];
3570 for (; lines_list[cy][i]; i++)
3571 buf[j++] = lines_list[cy][i];
3573 string_free(lines_list[cy]);
3574 lines_list[cy] = string_make(buf);
3583 /* Restore the screen */
3586 switch (filename_mode)
3590 strcpy(buf, "picktype.prf");
3592 strcpy(buf, "pickpref.prf");
3598 sprintf(buf, "picktype-%s.prf", player_name);
3600 sprintf(buf, "pickpref-%s.prf", player_name);
3605 write_text_lines(buf, lines_list);
3606 free_text_lines(lines_list);
3608 string_free(last_destroyed);
3610 /* Reload autopick pref */
3611 process_pickpref_file(buf);