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++];
285 while (entry->insc[j] && i < MAX_LINELEN - 2)
288 if (iskanji(entry->insc[j]))
289 buf[i++] = entry->insc[j++];
291 buf[i++] = entry->insc[j++];
296 return string_make(buf);
301 * Reconstruct preference line from entry and kill entry
303 static cptr autopick_line_from_entry_kill(autopick_type *entry)
305 cptr ptr = autopick_line_from_entry(entry);
307 /* Free memory for original entry */
308 autopick_free_entry(entry);
315 * A function to create new entry
317 bool autopick_new_entry(autopick_type *entry, cptr str)
322 char buf[MAX_LINELEN];
323 cptr prev_ptr, ptr, old_ptr;
326 if (str[1] == ':') switch (str[0])
329 case 'A': case 'P': case 'C':
333 entry->flag[0] = entry->flag[1] = 0L;
336 act = DO_AUTOPICK | DO_DISPLAY;
339 if ((act & DO_AUTOPICK) && *str == '!')
342 act |= DO_AUTODESTROY;
345 else if ((act & DO_AUTOPICK) && *str == '~')
348 act |= DONT_AUTOPICK;
351 else if ((act & DO_DISPLAY) && *str == '(')
360 /* don't mind upper or lower case */
362 for (i = 0; *str; i++)
373 /* Auto-inscription? */
381 if (isupper(c)) c = tolower(c);
387 /* Skip empty line */
388 if (*buf == 0) return FALSE;
390 ptr = prev_ptr = buf;
393 while (old_ptr != ptr)
395 /* Save current location */
398 if (MATCH_KEY(KEY_ALL)) ADD_FLG(FLG_ALL);
399 if (MATCH_KEY(KEY_COLLECTING)) ADD_FLG(FLG_COLLECTING);
400 if (MATCH_KEY(KEY_UNIDENTIFIED)) ADD_FLG(FLG_UNIDENTIFIED);
401 if (MATCH_KEY(KEY_IDENTIFIED)) ADD_FLG(FLG_IDENTIFIED);
402 if (MATCH_KEY(KEY_STAR_IDENTIFIED)) ADD_FLG(FLG_STAR_IDENTIFIED);
403 if (MATCH_KEY(KEY_BOOSTED)) ADD_FLG(FLG_BOOSTED);
405 /*** Weapons whose dd*ds is more than nn ***/
406 if (MATCH_KEY2(KEY_MORE_THAN))
411 /* Drop leading spaces */
412 while (' ' == *ptr) ptr++;
415 while (isdigit(*ptr))
417 entry->dice = 10 * entry->dice + (*ptr - '0');
424 (void)MATCH_KEY(KEY_DICE);
425 ADD_FLG(FLG_MORE_THAN);
431 /*** Items whose magical bonus is more than n ***/
432 if (MATCH_KEY2(KEY_MORE_BONUS))
437 /* Drop leading spaces */
438 while (' ' == *ptr) ptr++;
441 while (isdigit(*ptr))
443 entry->bonus = 10 * entry->bonus + (*ptr - '0');
450 (void)MATCH_KEY(KEY_MORE_BONUS2);
451 ADD_FLG(FLG_MORE_BONUS);
457 if (MATCH_KEY(KEY_WORTHLESS)) ADD_FLG(FLG_WORTHLESS);
458 if (MATCH_KEY(KEY_EGO)) ADD_FLG(FLG_EGO);
459 if (MATCH_KEY(KEY_NAMELESS)) ADD_FLG(FLG_NAMELESS);
460 if (MATCH_KEY(KEY_UNAWARE)) ADD_FLG(FLG_UNAWARE);
461 if (MATCH_KEY(KEY_WANTED)) ADD_FLG(FLG_WANTED);
462 if (MATCH_KEY(KEY_UNIQUE)) ADD_FLG(FLG_UNIQUE);
463 if (MATCH_KEY(KEY_HUMAN)) ADD_FLG(FLG_HUMAN);
464 if (MATCH_KEY(KEY_UNREADABLE)) ADD_FLG(FLG_UNREADABLE);
465 if (MATCH_KEY(KEY_REALM1)) ADD_FLG(FLG_REALM1);
466 if (MATCH_KEY(KEY_REALM2)) ADD_FLG(FLG_REALM2);
467 if (MATCH_KEY(KEY_FIRST)) ADD_FLG(FLG_FIRST);
468 if (MATCH_KEY(KEY_SECOND)) ADD_FLG(FLG_SECOND);
469 if (MATCH_KEY(KEY_THIRD)) ADD_FLG(FLG_THIRD);
470 if (MATCH_KEY(KEY_FOURTH)) ADD_FLG(FLG_FOURTH);
473 /* Not yet found any noun */
476 if (MATCH_KEY2(KEY_ARTIFACT)) ADD_FLG_NOUN(FLG_ARTIFACT);
478 if (MATCH_KEY2(KEY_ITEMS)) ADD_FLG_NOUN(FLG_ITEMS);
479 else if (MATCH_KEY2(KEY_WEAPONS)) ADD_FLG_NOUN(FLG_WEAPONS);
480 else if (MATCH_KEY2(KEY_ARMORS)) ADD_FLG_NOUN(FLG_ARMORS);
481 else if (MATCH_KEY2(KEY_MISSILES)) ADD_FLG_NOUN(FLG_MISSILES);
482 else if (MATCH_KEY2(KEY_DEVICES)) ADD_FLG_NOUN(FLG_DEVICES);
483 else if (MATCH_KEY2(KEY_LIGHTS)) ADD_FLG_NOUN(FLG_LIGHTS);
484 else if (MATCH_KEY2(KEY_JUNKS)) ADD_FLG_NOUN(FLG_JUNKS);
485 else if (MATCH_KEY2(KEY_SPELLBOOKS)) ADD_FLG_NOUN(FLG_SPELLBOOKS);
486 else if (MATCH_KEY2(KEY_HAFTED)) ADD_FLG_NOUN(FLG_HAFTED);
487 else if (MATCH_KEY2(KEY_SHIELDS)) ADD_FLG_NOUN(FLG_SHIELDS);
488 else if (MATCH_KEY2(KEY_BOWS)) ADD_FLG_NOUN(FLG_BOWS);
489 else if (MATCH_KEY2(KEY_RINGS)) ADD_FLG_NOUN(FLG_RINGS);
490 else if (MATCH_KEY2(KEY_AMULETS)) ADD_FLG_NOUN(FLG_AMULETS);
491 else if (MATCH_KEY2(KEY_SUITS)) ADD_FLG_NOUN(FLG_SUITS);
492 else if (MATCH_KEY2(KEY_CLOAKS)) ADD_FLG_NOUN(FLG_CLOAKS);
493 else if (MATCH_KEY2(KEY_HELMS)) ADD_FLG_NOUN(FLG_HELMS);
494 else if (MATCH_KEY2(KEY_GLOVES)) ADD_FLG_NOUN(FLG_GLOVES);
495 else if (MATCH_KEY2(KEY_BOOTS)) ADD_FLG_NOUN(FLG_BOOTS);
497 /* Last 'keyword' must be at the correct location */
501 else if (ptr[0] == kanji_colon[0] && ptr[1] == kanji_colon[1])
504 else if (*ptr == '\0')
505 ; /* nothing to do */
511 /* A noun type keyword didn't end correctly */
512 entry->flag[prev_flg/32] &= ~(1L<< (prev_flg%32));
517 /* Save this auto-picker entry line */
518 entry->name = string_make(ptr);
520 entry->insc = string_make(insc);
526 * A function to delete entry
528 void autopick_free_entry(autopick_type *entry)
530 string_free(entry->name);
531 string_free(entry->insc);
536 * A function for Auto-picker/destroyer
537 * Examine whether the object matches to the entry
539 static bool is_autopick_aux(object_type *o_ptr, autopick_type *entry, cptr o_name)
542 cptr ptr = entry->name;
544 /*** Unidentified ***/
545 if (IS_FLG(FLG_UNIDENTIFIED)
546 && (object_known_p(o_ptr) || (o_ptr->ident & IDENT_SENSE)))
550 if (IS_FLG(FLG_IDENTIFIED) && !object_known_p(o_ptr))
553 /*** *Identified* ***/
554 if (IS_FLG(FLG_STAR_IDENTIFIED) &&
555 (!object_known_p(o_ptr) || !(o_ptr->ident & IDENT_MENTAL)))
558 /*** Dice boosted (weapon of slaying) ***/
559 if (IS_FLG(FLG_BOOSTED))
561 object_kind *k_ptr = &k_info[o_ptr->k_idx];
563 switch( o_ptr->tval )
569 if ((o_ptr->dd != k_ptr->dd) || (o_ptr->ds != k_ptr->ds))
578 /*** Weapons whic dd*ds is more than nn ***/
579 if (IS_FLG(FLG_MORE_THAN))
581 if (o_ptr->dd * o_ptr->ds < entry->dice)
585 /*** Weapons whic dd*ds is more than nn ***/
586 if (IS_FLG(FLG_MORE_BONUS))
588 if (!object_known_p(o_ptr)) return FALSE;
590 if (k_info[o_ptr->k_idx].pval ||
591 (o_ptr->name2 && e_info[o_ptr->name2].max_pval))
593 if (o_ptr->pval < entry->bonus) return FALSE;
597 if (o_ptr->to_h < entry->bonus &&
598 o_ptr->to_d < entry->bonus &&
599 o_ptr->to_a < entry->bonus &&
600 o_ptr->pval < entry->bonus)
605 /*** Worthless items ***/
606 if (IS_FLG(FLG_WORTHLESS) && object_value(o_ptr) > 0)
609 /*** Artifact object ***/
610 if (IS_FLG(FLG_ARTIFACT))
612 if (!object_known_p(o_ptr) || (!o_ptr->name1 && !o_ptr->art_name))
619 if (!object_known_p(o_ptr) || !o_ptr->name2)
624 if (IS_FLG(FLG_NAMELESS))
629 case TV_SHOT: case TV_ARROW: case TV_BOLT: case TV_BOW:
630 case TV_DIGGING: case TV_HAFTED: case TV_POLEARM: case TV_SWORD:
631 case TV_BOOTS: case TV_GLOVES: case TV_HELM: case TV_CROWN:
632 case TV_SHIELD: case TV_CLOAK:
633 case TV_SOFT_ARMOR: case TV_HARD_ARMOR: case TV_DRAG_ARMOR:
634 case TV_LITE: case TV_AMULET: case TV_RING: case TV_CARD:
635 if ((!object_known_p(o_ptr) || o_ptr->inscription
636 || o_ptr->name1 || o_ptr->name2 || o_ptr->art_name))
645 /*** Unaware items ***/
646 if (IS_FLG(FLG_UNAWARE) && object_aware_p(o_ptr))
649 /*** Wanted monster's corpse/skeletons ***/
650 if (IS_FLG(FLG_WANTED) &&
651 (o_ptr->tval != TV_CORPSE || !object_is_shoukinkubi(o_ptr)))
654 /*** Unique monster's corpse/skeletons/statues ***/
655 if (IS_FLG(FLG_UNIQUE) &&
656 ((o_ptr->tval != TV_CORPSE && o_ptr->tval != TV_STATUE) ||
657 !(r_info[o_ptr->pval].flags1 & RF1_UNIQUE)))
660 /*** Human corpse/skeletons (for Daemon magic) ***/
661 if (IS_FLG(FLG_HUMAN) &&
662 (o_ptr->tval != TV_CORPSE ||
663 !strchr("pht", r_info[o_ptr->pval].d_char)))
666 /*** Unreadable spellbooks ***/
667 if (IS_FLG(FLG_UNREADABLE) &&
668 (o_ptr->tval < TV_LIFE_BOOK ||
669 check_book_realm(o_ptr->tval, o_ptr->sval)))
672 /*** First realm spellbooks ***/
673 if (IS_FLG(FLG_REALM1) &&
674 (REALM1_BOOK != o_ptr->tval ||
675 p_ptr->pclass == CLASS_SORCERER ||
676 p_ptr->pclass == CLASS_RED_MAGE))
679 /*** Second realm spellbooks ***/
680 if (IS_FLG(FLG_REALM2) &&
681 (REALM2_BOOK != o_ptr->tval ||
682 p_ptr->pclass == CLASS_SORCERER ||
683 p_ptr->pclass == CLASS_RED_MAGE))
686 /*** First rank spellbooks ***/
687 if (IS_FLG(FLG_FIRST) &&
688 (o_ptr->tval < TV_LIFE_BOOK || 0 != o_ptr->sval))
691 /*** Second rank spellbooks ***/
692 if (IS_FLG(FLG_SECOND) &&
693 (o_ptr->tval < TV_LIFE_BOOK || 1 != o_ptr->sval))
696 /*** Third rank spellbooks ***/
697 if (IS_FLG(FLG_THIRD) &&
698 (o_ptr->tval < TV_LIFE_BOOK || 2 != o_ptr->sval))
701 /*** Fourth rank spellbooks ***/
702 if (IS_FLG(FLG_FOURTH) &&
703 (o_ptr->tval < TV_LIFE_BOOK || 3 != o_ptr->sval))
707 if (IS_FLG(FLG_WEAPONS))
711 case TV_BOW: case TV_HAFTED: case TV_POLEARM:
712 case TV_SWORD: case TV_DIGGING:
714 default: return FALSE;
717 else if (IS_FLG(FLG_ARMORS))
721 case TV_BOOTS: case TV_GLOVES: case TV_CLOAK: case TV_CROWN:
722 case TV_HELM: case TV_SHIELD: case TV_SOFT_ARMOR:
723 case TV_HARD_ARMOR: case TV_DRAG_ARMOR:
725 default: return FALSE;
728 else if (IS_FLG(FLG_MISSILES))
732 case TV_SHOT: case TV_BOLT: case TV_ARROW:
734 default: return FALSE;
737 else if (IS_FLG(FLG_DEVICES))
741 case TV_SCROLL: case TV_STAFF: case TV_WAND: case TV_ROD:
743 default: return FALSE;
746 else if (IS_FLG(FLG_LIGHTS))
748 if (!(o_ptr->tval == TV_LITE))
751 else if (IS_FLG(FLG_JUNKS))
755 case TV_SKELETON: case TV_BOTTLE:
756 case TV_JUNK: case TV_STATUE:
758 default: return FALSE;
761 else if (IS_FLG(FLG_SPELLBOOKS))
763 if (!(o_ptr->tval >= TV_LIFE_BOOK))
766 else if (IS_FLG(FLG_HAFTED))
768 if (!(o_ptr->tval == TV_HAFTED))
771 else if (IS_FLG(FLG_SHIELDS))
773 if (!(o_ptr->tval == TV_SHIELD))
776 else if (IS_FLG(FLG_BOWS))
778 if (!(o_ptr->tval == TV_BOW))
781 else if (IS_FLG(FLG_RINGS))
783 if (!(o_ptr->tval == TV_RING))
786 else if (IS_FLG(FLG_AMULETS))
788 if (!(o_ptr->tval == TV_AMULET))
791 else if (IS_FLG(FLG_SUITS))
793 if (!(o_ptr->tval == TV_DRAG_ARMOR ||
794 o_ptr->tval == TV_HARD_ARMOR ||
795 o_ptr->tval == TV_SOFT_ARMOR))
798 else if (IS_FLG(FLG_CLOAKS))
800 if (!(o_ptr->tval == TV_CLOAK))
803 else if (IS_FLG(FLG_HELMS))
805 if (!(o_ptr->tval == TV_CROWN || o_ptr->tval == TV_HELM))
808 else if (IS_FLG(FLG_GLOVES))
810 if (!(o_ptr->tval == TV_GLOVES))
813 else if (IS_FLG(FLG_BOOTS))
815 if (!(o_ptr->tval == TV_BOOTS))
819 /* Keyword don't match */
823 if (strncmp(o_name, ptr, strlen(ptr))) return FALSE;
828 if (!strstr_j(o_name, ptr)) return FALSE;
830 if (!strstr(o_name, ptr)) return FALSE;
834 /* TRUE when it need not to be 'collecting' */
835 if (!IS_FLG(FLG_COLLECTING)) return TRUE;
837 /* Check if there is a same item */
838 for (j = 0; j < INVEN_PACK; j++)
841 * 'Collecting' means the item must be absorbed
842 * into an inventory slot.
843 * But an item can not be absorbed into itself!
845 if ((&inventory[j] != o_ptr) &&
846 object_similar(&inventory[j], o_ptr))
856 * A function for Auto-picker/destroyer
857 * Examine whether the object matches to the list of keywords or not.
859 int is_autopick(object_type *o_ptr)
862 char o_name[MAX_NLEN];
864 if (o_ptr->tval == TV_GOLD) return -1;
866 object_desc(o_name, o_ptr, FALSE, 3);
868 /* Force to be lower case string */
869 for (i = 0; o_name[i]; i++)
872 if (iskanji(o_name[i]))
876 if (isupper(o_name[i]))
877 o_name[i] = tolower(o_name[i]);
880 for (i=0; i < max_autopick; i++)
882 autopick_type *entry = &autopick_list[i];
884 if (is_autopick_aux(o_ptr, entry, o_name)) return i;
887 /* No matching entry */
893 * Automatically destroy items in this grid.
895 static bool is_opt_confirm_destroy(object_type *o_ptr)
897 if (!destroy_items) return FALSE;
899 /* Known to be worthless? */
901 if (object_value(o_ptr) > 0) return FALSE;
904 if ((o_ptr->tval >= TV_SHOT) && (o_ptr->tval <= TV_DRAG_ARMOR)) return FALSE;
907 if ((o_ptr->tval == TV_CHEST) && o_ptr->pval) return FALSE;
911 if (o_ptr->tval == TV_CORPSE
912 && object_is_shoukinkubi(o_ptr)) return FALSE;
916 if (o_ptr->tval == TV_CORPSE) return FALSE;
919 if ((o_ptr->tval == TV_SKELETON) || (o_ptr->tval == TV_BOTTLE) || (o_ptr->tval == TV_JUNK) || (o_ptr->tval == TV_STATUE)) return FALSE;
921 if (o_ptr->tval == TV_GOLD) return FALSE;
930 void auto_inscribe_item(int item, int idx)
934 /* Get the item (in the pack) */
935 if (item >= 0) o_ptr = &inventory[item];
937 /* Get the item (on the floor) */
938 else o_ptr = &o_list[0 - item];
940 /* Auto-inscription or Re-inscribe for resistances {%} */
941 if ((idx < 0 || !autopick_list[idx].insc) && !o_ptr->inscription)
944 if (o_ptr->inscription)
945 o_ptr->inscription = inscribe_flags(o_ptr, quark_str(o_ptr->inscription));
947 o_ptr->inscription = inscribe_flags(o_ptr, autopick_list[idx].insc);
949 if (item > INVEN_PACK)
951 /* Redraw inscription */
952 p_ptr->window |= (PW_EQUIP);
954 /* {.} and {$} effect p_ptr->warning and TRC_TELEPORT_SELF */
955 p_ptr->update |= (PU_BONUS);
959 /* Redraw inscription */
960 p_ptr->window |= (PW_INVEN);
966 * Automatically destroy an item if it is to be destroyed
968 bool auto_destroy_item(int item, int autopick_idx, bool wait_optimize)
970 bool destroy = FALSE;
971 char o_name[MAX_NLEN];
974 /* Don't destroy equipped items */
975 if (item > INVEN_PACK) return FALSE;
977 /* Get the item (in the pack) */
978 if (item >= 0) o_ptr = &inventory[item];
980 /* Get the item (on the floor) */
981 else o_ptr = &o_list[0 - item];
983 /* Easy-Auto-Destroyer */
984 if (is_opt_confirm_destroy(o_ptr)) destroy = TRUE;
986 /* Protected by auto-picker */
987 if (autopick_idx >= 0 &&
988 !(autopick_list[autopick_idx].action & DO_AUTODESTROY))
993 /* Auto-picker/destroyer */
994 if (autopick_idx >= 0 &&
995 (autopick_list[autopick_idx].action & DO_AUTODESTROY))
999 /* Not to be destroyed */
1000 if (!destroy) return FALSE;
1002 /* Now decided to destroy */
1006 /* Describe the object (with {terrible/special}) */
1007 object_desc(o_name, o_ptr, TRUE, 3);
1010 if (!can_player_destroy_object(o_ptr))
1014 msg_format("%s¤ÏÇ˲õÉÔǽ¤À¡£", o_name);
1016 msg_format("You cannot auto-destroy %s.", o_name);
1023 /* Record name of destroyed item */
1024 COPY(&autopick_last_destroyed_object, o_ptr, object_type);
1026 /* Eliminate the item (from the pack) */
1029 inven_item_increase(item, -(o_ptr->number));
1032 * always optimize equipment.
1033 * optimize inventry only when wait_optimize is FALSE.
1035 if (!wait_optimize || item > INVEN_PACK)
1036 inven_item_optimize(item);
1039 /* Eliminate the item (from the floor) */
1042 delete_object_idx(0 - item);
1045 /* Print a message */
1047 msg_format("%s¤ò¼«Æ°Ç˲õ¤·¤Þ¤¹¡£", o_name);
1049 msg_format("Auto-destroying %s.", o_name);
1057 * Optimize all inventry items after consumption of staves or scrolls.
1059 void optimize_inventry_auto_destroy(void)
1063 for (i = 0; i <= INVEN_PACK; i++)
1064 inven_item_optimize(i);
1069 * Automatically pickup/destroy items in this grid.
1071 void auto_pickup_items(cave_type *c_ptr)
1073 s16b this_o_idx, next_o_idx = 0;
1075 /* Scan the pile of objects */
1076 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1080 /* Acquire object */
1081 object_type *o_ptr = &o_list[this_o_idx];
1083 /* Acquire next object */
1084 next_o_idx = o_ptr->next_o_idx;
1086 idx = is_autopick(o_ptr);
1088 /* Item index for floor -1,-2,-3,... */
1089 auto_inscribe_item((-this_o_idx), idx);
1091 if (idx >= 0 && (autopick_list[idx].action & DO_AUTOPICK))
1095 if (!inven_carry_okay(o_ptr))
1097 char o_name[MAX_NLEN];
1099 /* Describe the object */
1100 object_desc(o_name, o_ptr, TRUE, 3);
1104 msg_format("¥¶¥Ã¥¯¤Ë¤Ï%s¤òÆþ¤ì¤ë·ä´Ö¤¬¤Ê¤¤¡£", o_name);
1106 msg_format("You have no room for %s.", o_name);
1110 py_pickup_aux(this_o_idx);
1117 * When always_pickup is 'yes', we disable
1118 * auto-destroyer from autopick function, and do only
1119 * easy-auto-destroyer.
1123 if (auto_destroy_item((-this_o_idx), idx, FALSE))
1131 * Describe which kind of object is Auto-picked/destroyed
1133 static void describe_autopick(char *buff, autopick_type *entry)
1135 cptr str = entry->name;
1136 byte act = entry->action;
1137 cptr insc = entry->insc;
1143 cptr before_str[100], body_str;
1146 body_str = "¥¢¥¤¥Æ¥à";
1148 /*** Collecting items ***/
1149 /*** Which can be absorbed into a slot as a bundle ***/
1150 if (IS_FLG(FLG_COLLECTING))
1151 before_str[before_n++] = "¼ý½¸Ãæ¤Ç´û¤Ë»ý¤Ã¤Æ¤¤¤ë¥¹¥í¥Ã¥È¤Ë¤Þ¤È¤á¤é¤ì¤ë";
1153 /*** Unidentified ***/
1154 if (IS_FLG(FLG_UNIDENTIFIED))
1155 before_str[before_n++] = "̤´ÕÄê¤Î";
1157 /*** Identified ***/
1158 if (IS_FLG(FLG_IDENTIFIED))
1159 before_str[before_n++] = "´ÕÄêºÑ¤ß¤Î";
1161 /*** *Identified* ***/
1162 if (IS_FLG(FLG_STAR_IDENTIFIED))
1163 before_str[before_n++] = "´°Á´¤Ë´ÕÄêºÑ¤ß¤Î";
1165 /*** Dice boosted (weapon of slaying) ***/
1166 if (IS_FLG(FLG_BOOSTED))
1168 before_str[before_n++] = "¥À¥á¡¼¥¸¥À¥¤¥¹¤¬Ä̾ï¤è¤êÂ礤¤";
1172 /*** Weapons whose dd*ds is more than nn ***/
1173 if (IS_FLG(FLG_MORE_THAN))
1175 static char more_than_desc_str[] = "___";
1176 before_str[before_n++] = "¥À¥á¡¼¥¸¥À¥¤¥¹¤ÎºÇÂçÃͤ¬";
1179 sprintf(more_than_desc_str,"%d", entry->dice);
1180 before_str[before_n++] = more_than_desc_str;
1181 before_str[before_n++] = "°Ê¾å¤Î";
1184 /*** Items whose magical bonus is more than nn ***/
1185 if (IS_FLG(FLG_MORE_BONUS))
1187 static char more_bonus_desc_str[] = "___";
1188 before_str[before_n++] = "½¤ÀµÃͤ¬(+";
1190 sprintf(more_bonus_desc_str,"%d", entry->bonus);
1191 before_str[before_n++] = more_bonus_desc_str;
1192 before_str[before_n++] = ")°Ê¾å¤Î";
1195 /*** Worthless items ***/
1196 if (IS_FLG(FLG_WORTHLESS))
1197 before_str[before_n++] = "Ź¤Ç̵²ÁÃͤÈȽÄꤵ¤ì¤ë";
1200 if (IS_FLG(FLG_ARTIFACT))
1202 before_str[before_n++] = "¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È¤Î";
1207 if (IS_FLG(FLG_EGO))
1209 before_str[before_n++] = "¥¨¥´¥¢¥¤¥Æ¥à¤Î";
1214 if (IS_FLG(FLG_NAMELESS))
1216 before_str[before_n++] = "¥¨¥´¤Ç¤â¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È¤Ç¤â¤Ê¤¤";
1220 /*** Unaware items ***/
1221 if (IS_FLG(FLG_UNAWARE))
1222 before_str[before_n++] = "̤´ÕÄê¤Ç¤½¤Î¸ú²Ì¤âȽÌÀ¤·¤Æ¤¤¤Ê¤¤";
1224 /*** Wanted monster's corpse/skeletons ***/
1225 if (IS_FLG(FLG_WANTED))
1227 before_str[before_n++] = "¥Ï¥ó¥¿¡¼»ö̳½ê¤Ç¾Þ¶â¼ó¤È¤µ¤ì¤Æ¤¤¤ë";
1228 body_str = "»àÂΤä¹ü";
1231 /*** Human corpse/skeletons (for Daemon magic) ***/
1232 if (IS_FLG(FLG_HUMAN))
1234 before_str[before_n++] = "°ËâËâË¡¤Ç»È¤¦¤¿¤á¤Î¿Í´Ö¤ä¥Ò¥å¡¼¥Þ¥Î¥¤¥É¤Î";
1235 body_str = "»àÂΤä¹ü";
1238 /*** Unique monster's corpse/skeletons/statues ***/
1239 if (IS_FLG(FLG_UNIQUE))
1241 before_str[before_n++] = "¥æ¥Ë¡¼¥¯¥â¥ó¥¹¥¿¡¼¤Î";
1242 body_str = "»àÂΤä¹ü";
1245 /*** Unreadable spellbooks ***/
1246 if (IS_FLG(FLG_UNREADABLE))
1248 before_str[before_n++] = "¤¢¤Ê¤¿¤¬Æɤá¤Ê¤¤Îΰè¤Î";
1249 body_str = "ËâË¡½ñ";
1252 /*** First realm spellbooks ***/
1253 if (IS_FLG(FLG_REALM1))
1255 before_str[before_n++] = "Âè°ìÎΰè¤Î";
1256 body_str = "ËâË¡½ñ";
1259 /*** Second realm spellbooks ***/
1260 if (IS_FLG(FLG_REALM2))
1262 before_str[before_n++] = "ÂèÆóÎΰè¤Î";
1263 body_str = "ËâË¡½ñ";
1266 /*** First rank spellbooks ***/
1267 if (IS_FLG(FLG_FIRST))
1269 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î1ºýÌܤÎ";
1270 body_str = "ËâË¡½ñ";
1273 /*** Second rank spellbooks ***/
1274 if (IS_FLG(FLG_SECOND))
1276 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î2ºýÌܤÎ";
1277 body_str = "ËâË¡½ñ";
1280 /*** Third rank spellbooks ***/
1281 if (IS_FLG(FLG_THIRD))
1283 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î3ºýÌܤÎ";
1284 body_str = "ËâË¡½ñ";
1287 /*** Fourth rank spellbooks ***/
1288 if (IS_FLG(FLG_FOURTH))
1290 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î4ºýÌܤÎ";
1291 body_str = "ËâË¡½ñ";
1295 if (IS_FLG(FLG_ITEMS))
1296 ; /* Nothing to do */
1297 else if (IS_FLG(FLG_WEAPONS))
1299 else if (IS_FLG(FLG_ARMORS))
1301 else if (IS_FLG(FLG_MISSILES))
1302 body_str = "ÃƤäÌð¤ä¥¯¥í¥¹¥Ü¥¦¤ÎÌð";
1303 else if (IS_FLG(FLG_DEVICES))
1304 body_str = "´¬Êª¤äËâË¡ËÀ¤ä¾ó¤ä¥í¥Ã¥É";
1305 else if (IS_FLG(FLG_LIGHTS))
1306 body_str = "¸÷¸»ÍѤΥ¢¥¤¥Æ¥à";
1307 else if (IS_FLG(FLG_JUNKS))
1308 body_str = "Àޤ줿ËÀÅù¤Î¥¬¥é¥¯¥¿";
1309 else if (IS_FLG(FLG_SPELLBOOKS))
1310 body_str = "ËâË¡½ñ";
1311 else if (IS_FLG(FLG_HAFTED))
1313 else if (IS_FLG(FLG_SHIELDS))
1315 else if (IS_FLG(FLG_BOWS))
1316 body_str = "¥¹¥ê¥ó¥°¤äµÝ¤ä¥¯¥í¥¹¥Ü¥¦";
1317 else if (IS_FLG(FLG_RINGS))
1319 else if (IS_FLG(FLG_AMULETS))
1320 body_str = "¥¢¥ß¥å¥ì¥Ã¥È";
1321 else if (IS_FLG(FLG_SUITS))
1323 else if (IS_FLG(FLG_CLOAKS))
1324 body_str = "¥¯¥í¡¼¥¯";
1325 else if (IS_FLG(FLG_HELMS))
1326 body_str = "¥Ø¥ë¥á¥Ã¥È¤ä´§";
1327 else if (IS_FLG(FLG_GLOVES))
1329 else if (IS_FLG(FLG_BOOTS))
1330 body_str = "¥Ö¡¼¥Ä";
1334 strcat(buff, "Á´¤Æ¤Î");
1335 else for (i = 0; i < before_n && before_str[i]; i++)
1336 strcat(buff, before_str[i]);
1338 strcat(buff, body_str);
1348 strcat(buff, "¤Ç¡¢Ì¾Á°¤¬¡Ö");
1349 strncat(buff, str, 80);
1351 strcat(buff, "¡×¤Ç»Ï¤Þ¤ë¤â¤Î");
1353 strcat(buff, "¡×¤ò´Þ¤à¤â¤Î");
1358 strncat(buff, format("¤Ë¡Ö%s¡×", insc), 80);
1360 if (strstr(insc, "%%all"))
1361 strcat(buff, "(%%all¤ÏÁ´Ç½ÎϤòɽ¤¹±Ñ»ú¤Îµ¹æ¤ÇÃÖ´¹)");
1362 else if (strstr(insc, "%all"))
1363 strcat(buff, "(%all¤ÏÁ´Ç½ÎϤòɽ¤¹µ¹æ¤ÇÃÖ´¹)");
1364 else if (strstr(insc, "%%"))
1365 strcat(buff, "(%%¤ÏÄɲÃǽÎϤòɽ¤¹±Ñ»ú¤Îµ¹æ¤ÇÃÖ´¹)");
1366 else if (strstr(insc, "%"))
1367 strcat(buff, "(%¤ÏÄɲÃǽÎϤòɽ¤¹µ¹æ¤ÇÃÖ´¹)");
1369 strcat(buff, "¤È¹ï¤ó¤Ç");
1374 if (act & DONT_AUTOPICK)
1375 strcat(buff, "ÊüÃÖ¤¹¤ë¡£");
1376 else if (act & DO_AUTODESTROY)
1377 strcat(buff, "Ç˲õ¤¹¤ë¡£");
1379 strcat(buff, "½¦¤¦¡£");
1381 if (act & DO_DISPLAY)
1383 if (act & DONT_AUTOPICK)
1384 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'N'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
1385 else if (act & DO_AUTODESTROY)
1386 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'K'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
1388 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'M'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
1391 strcat(buff, "Á´ÂΥޥåפˤÏɽ¼¨¤·¤Ê¤¤");
1395 cptr before_str[20], after_str[20], which_str[20], whose_str[20], body_str;
1396 int before_n = 0, after_n = 0, which_n = 0, whose_n = 0;
1400 /*** Collecting items ***/
1401 /*** Which can be absorbed into a slot as a bundle ***/
1402 if (IS_FLG(FLG_COLLECTING))
1403 which_str[which_n++] = "can be absorbed into an existing inventory slot";
1405 /*** Unidentified ***/
1406 if (IS_FLG(FLG_UNIDENTIFIED))
1407 before_str[before_n++] = "unidentified";
1409 /*** Identified ***/
1410 if (IS_FLG(FLG_IDENTIFIED))
1411 before_str[before_n++] = "identified";
1413 /*** *Identified* ***/
1414 if (IS_FLG(FLG_STAR_IDENTIFIED))
1415 before_str[before_n++] = "fully identified";
1417 /*** Worthless items ***/
1418 if (IS_FLG(FLG_WORTHLESS))
1420 before_str[before_n++] = "worthless";
1421 which_str[which_n++] = "can not be sold at stores";
1425 if (IS_FLG(FLG_ARTIFACT))
1427 before_str[before_n++] = "artifact";
1431 if (IS_FLG(FLG_EGO))
1433 before_str[before_n++] = "ego";
1437 if (IS_FLG(FLG_NAMELESS))
1439 body_str = "equipment";
1440 which_str[which_n++] = "is neither ego-item nor artifact";
1443 /*** Unaware items ***/
1444 if (IS_FLG(FLG_UNAWARE))
1446 before_str[before_n++] = "unidentified";
1447 whose_str[whose_n++] = "basic abilities are not known";
1450 /*** Dice boosted (weapon of slaying) ***/
1451 if (IS_FLG(FLG_BOOSTED))
1453 body_str = "weapons";
1454 whose_str[whose_n++] = "damage dice is bigger than normal";
1457 /*** Weapons whose dd*ds is more than nn ***/
1458 if (IS_FLG(FLG_MORE_THAN))
1460 static char more_than_desc_str[] =
1461 "maximum damage from dice is bigger than __";
1462 body_str = "weapons";
1464 sprintf(more_than_desc_str + sizeof(more_than_desc_str) - 3,
1466 whose_str[whose_n++] = more_than_desc_str;
1469 /*** Items whose magical bonus is more than nn ***/
1470 if (IS_FLG(FLG_MORE_BONUS))
1472 static char more_bonus_desc_str[] =
1473 "magical bonus is bigger than (+__)";
1475 sprintf(more_bonus_desc_str + sizeof(more_bonus_desc_str) - 4,
1476 "%d)", entry->bonus);
1477 whose_str[whose_n++] = more_bonus_desc_str;
1480 /*** Wanted monster's corpse/skeletons ***/
1481 if (IS_FLG(FLG_WANTED))
1483 body_str = "corpse or skeletons";
1484 which_str[which_n++] = "is wanted at the Hunter's Office";
1487 /*** Human corpse/skeletons (for Daemon magic) ***/
1488 if (IS_FLG(FLG_HUMAN))
1490 before_str[before_n++] = "humanoid";
1491 body_str = "corpse or skeletons";
1492 which_str[which_n++] = "can be used for Daemon magic";
1495 /*** Unique monster's corpse/skeletons/statues ***/
1496 if (IS_FLG(FLG_UNIQUE))
1498 before_str[before_n++] = "unique monster's";
1499 body_str = "corpse or skeletons";
1502 /*** Unreadable spellbooks ***/
1503 if (IS_FLG(FLG_UNREADABLE))
1505 body_str = "spellbooks";
1506 after_str[after_n++] = "of different realms from yours";
1509 /*** First realm spellbooks ***/
1510 if (IS_FLG(FLG_REALM1))
1512 body_str = "spellbooks";
1513 after_str[after_n++] = "of your first realm";
1516 /*** Second realm spellbooks ***/
1517 if (IS_FLG(FLG_REALM2))
1519 body_str = "spellbooks";
1520 after_str[after_n++] = "of your second realm";
1523 /*** First rank spellbooks ***/
1524 if (IS_FLG(FLG_FIRST))
1526 before_str[before_n++] = "first one of four";
1527 body_str = "spellbooks";
1530 /*** Second rank spellbooks ***/
1531 if (IS_FLG(FLG_SECOND))
1533 before_str[before_n++] = "second one of four";
1534 body_str = "spellbooks";
1537 /*** Third rank spellbooks ***/
1538 if (IS_FLG(FLG_THIRD))
1540 before_str[before_n++] = "third one of four";
1541 body_str = "spellbooks";
1544 /*** Fourth rank spellbooks ***/
1545 if (IS_FLG(FLG_FOURTH))
1547 before_str[before_n++] = "fourth one of four";
1548 body_str = "spellbooks";
1552 if (IS_FLG(FLG_ITEMS))
1553 ; /* Nothing to do */
1554 else if (IS_FLG(FLG_WEAPONS))
1555 body_str = "weapons";
1556 else if (IS_FLG(FLG_ARMORS))
1557 body_str = "armors";
1558 else if (IS_FLG(FLG_MISSILES))
1559 body_str = "shots, arrows or crossbow bolts";
1560 else if (IS_FLG(FLG_DEVICES))
1561 body_str = "scrolls, wands, staves or rods";
1562 else if (IS_FLG(FLG_LIGHTS))
1563 body_str = "light sources";
1564 else if (IS_FLG(FLG_JUNKS))
1565 body_str = "junk such as broken sticks";
1566 else if (IS_FLG(FLG_SPELLBOOKS))
1567 body_str = "spellbooks";
1568 else if (IS_FLG(FLG_HAFTED))
1569 body_str = "hafted weapons";
1570 else if (IS_FLG(FLG_SHIELDS))
1571 body_str = "shields";
1572 else if (IS_FLG(FLG_BOWS))
1573 body_str = "slings, bows or crossbows";
1574 else if (IS_FLG(FLG_RINGS))
1576 else if (IS_FLG(FLG_AMULETS))
1577 body_str = "amulets";
1578 else if (IS_FLG(FLG_SUITS))
1579 body_str = "body armors";
1580 else if (IS_FLG(FLG_CLOAKS))
1581 body_str = "cloaks";
1582 else if (IS_FLG(FLG_HELMS))
1583 body_str = "helms or crowns";
1584 else if (IS_FLG(FLG_GLOVES))
1585 body_str = "gloves";
1586 else if (IS_FLG(FLG_BOOTS))
1589 /* Prepare a string for item name */
1596 whose_str[whose_n++] = "name is beginning with \"";
1599 which_str[which_n++] = "have \"";
1603 /* Describe action flag */
1604 if (act & DONT_AUTOPICK)
1605 strcpy(buff, "Leave on floor ");
1606 else if (act & DO_AUTODESTROY)
1607 strcpy(buff, "Destroy ");
1609 strcpy(buff, "Pickup ");
1611 /* Auto-insctiption */
1614 strncat(buff, format("and inscribe \"%s\"", insc), 80);
1616 if (strstr(insc, "%all"))
1617 strcat(buff, ", replacing %all with code string representing all abilities,");
1618 else if (strstr(insc, "%"))
1619 strcat(buff, ", replacing % with code string representing extra random abilities,");
1621 strcat(buff, " on ");
1626 strcat(buff, "all ");
1627 else for (i = 0; i < before_n && before_str[i]; i++)
1629 strcat(buff, before_str[i]);
1634 strcat(buff, body_str);
1637 for (i = 0; i < after_n && after_str[i]; i++)
1640 strcat(buff, after_str[i]);
1644 for (i = 0; i < whose_n && whose_str[i]; i++)
1647 strcat(buff, " whose ");
1649 strcat(buff, ", and ");
1651 strcat(buff, whose_str[i]);
1654 /* Item name ; whose name is beginning with "str" */
1661 /* whose ..., and which .... */
1662 if (whose_n && which_n)
1663 strcat(buff, ", and ");
1666 for (i = 0; i < which_n && which_str[i]; i++)
1669 strcat(buff, " which ");
1671 strcat(buff, ", and ");
1673 strcat(buff, which_str[i]);
1676 /* Item name ; which have "str" as part of its name */
1679 strncat(buff, str, 80);
1680 strcat(buff, "\" as part of its name");
1684 /* Describe whether it will be displayed on the full map or not */
1685 if (act & DO_DISPLAY)
1687 if (act & DONT_AUTOPICK)
1688 strcat(buff, " Display these items when you press the N key in the full 'M'ap.");
1689 else if (act & DO_AUTODESTROY)
1690 strcat(buff, " Display these items when you press the K key in the full 'M'ap.");
1692 strcat(buff, " Display these items when you press the M key in the full 'M'ap.");
1695 strcat(buff, " Not displayed in the full map.");
1701 #define MAX_LINES 3000
1704 * Read whole lines of a file to memory
1706 static cptr *read_text_lines(cptr filename, bool user)
1708 cptr *lines_list = NULL;
1716 /* Hack -- drop permissions */
1718 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
1722 path_build(buf, sizeof(buf), ANGBAND_DIR_PREF, filename);
1726 fff = my_fopen(buf, "r");
1730 /* Allocate list of pointers */
1731 C_MAKE(lines_list, MAX_LINES, cptr);
1734 while (0 == my_fgets(fff, buf, sizeof(buf)))
1736 lines_list[lines++] = string_make(buf);
1737 if (lines >= MAX_LINES - 1) break;
1740 lines_list[0] = string_make("");
1748 if (!fff) return NULL;
1753 #define PT_DEFAULT 0
1754 #define PT_WITH_PNAME 1
1756 static cptr *read_pickpref_text_lines(int *filename_mode_p)
1762 sprintf(buf, "picktype-%s.prf", player_name);
1764 sprintf(buf, "pickpref-%s.prf", player_name);
1766 lines_list = read_text_lines(buf, TRUE);
1771 lines_list = read_text_lines("picktype.prf", TRUE);
1773 lines_list = read_text_lines("pickpref.prf", TRUE);
1775 *filename_mode_p = PT_DEFAULT;
1781 lines_list = read_text_lines("picktype.prf", FALSE);
1783 lines_list = read_text_lines("pickpref.prf", FALSE);
1785 *filename_mode_p = PT_WITH_PNAME;
1790 /* Allocate list of pointers */
1791 C_MAKE(lines_list, MAX_LINES, cptr);
1792 lines_list[0] = string_make("");
1793 *filename_mode_p = PT_WITH_PNAME;
1799 * Write whole lines of memory to a file.
1801 static bool write_text_lines(cptr filename, cptr *lines_list)
1808 /* Hack -- drop permissions */
1811 /* Build the filename */
1812 path_build(buf, sizeof(buf), ANGBAND_DIR_USER, filename);
1815 fff = my_fopen(buf, "w");
1818 for (lines = 0; lines_list[lines]; lines++)
1819 my_fputs(fff, lines_list[lines], 1024);
1827 if (!fff) return FALSE;
1833 * Free memory of lines_list.
1835 static void free_text_lines(cptr *lines_list)
1839 for (lines = 0; lines_list[lines]; lines++)
1840 string_free(lines_list[lines]);
1842 /* free list of pointers */
1843 C_FREE((char **)lines_list, MAX_LINES, char *);
1848 * Delete or insert string
1850 static void toggle_string(cptr *lines_list, int flg, int y)
1852 autopick_type an_entry, *entry = &an_entry;
1854 if (!autopick_new_entry(entry, lines_list[y]))
1857 string_free(lines_list[y]);
1863 lines_list[y] = autopick_line_from_entry_kill(entry);
1867 * Insert return code and split the line
1869 static bool insert_return_code(cptr *lines_list, int cx, int cy)
1871 char buf[MAX_LINELEN];
1874 for (k = 0; lines_list[k]; k++)
1875 /* count number of lines */ ;
1877 if (k >= MAX_LINES - 2) return FALSE;
1880 /* Move down lines */
1882 lines_list[k+1] = lines_list[k];
1884 /* Split current line */
1885 for (i = j = 0; lines_list[cy][i] && i < cx; i++)
1888 if (iskanji(lines_list[cy][i]))
1889 buf[j++] = lines_list[cy][i++];
1891 buf[j++] = lines_list[cy][i];
1894 lines_list[cy+1] = string_make(&lines_list[cy][i]);
1895 string_free(lines_list[cy]);
1896 lines_list[cy] = string_make(buf);
1902 * Get auto-picker entry from o_ptr.
1904 void autopick_entry_from_object(autopick_type *entry, object_type *o_ptr)
1906 char o_name[MAX_NLEN];
1907 object_desc(o_name, o_ptr, FALSE, 0);
1909 entry->name = string_make(o_name);
1910 entry->insc = string_make(quark_str(o_ptr->inscription));
1911 entry->action = DO_AUTOPICK | DO_DISPLAY;
1912 entry->flag[0] = entry->flag[1] = 0L;
1915 if (!object_aware_p(o_ptr))
1916 ADD_FLG(FLG_UNAWARE);
1917 if (object_value(o_ptr) <= 0)
1918 ADD_FLG(FLG_WORTHLESS);
1920 if (object_known_p(o_ptr))
1924 else if (o_ptr->name1 || o_ptr->art_name)
1925 ADD_FLG(FLG_ARTIFACT);
1931 case TV_HAFTED: case TV_POLEARM: case TV_SWORD: case TV_DIGGING:
1932 k_ptr = &k_info[o_ptr->k_idx];
1933 if ((o_ptr->dd != k_ptr->dd) || (o_ptr->ds != k_ptr->ds))
1934 ADD_FLG(FLG_BOOSTED);
1937 if (o_ptr->tval == TV_CORPSE && object_is_shoukinkubi(o_ptr))
1939 REM_FLG(FLG_WORTHLESS);
1940 ADD_FLG(FLG_WANTED);
1943 if ((o_ptr->tval == TV_CORPSE || o_ptr->tval == TV_STATUE)
1944 && (r_info[o_ptr->pval].flags1 & RF1_UNIQUE))
1946 REM_FLG(FLG_WORTHLESS);
1947 ADD_FLG(FLG_UNIQUE);
1950 if (o_ptr->tval == TV_CORPSE && strchr("pht", r_info[o_ptr->pval].d_char))
1952 REM_FLG(FLG_WORTHLESS);
1956 if (o_ptr->tval >= TV_LIFE_BOOK &&
1957 !check_book_realm(o_ptr->tval, o_ptr->sval))
1958 ADD_FLG(FLG_UNREADABLE);
1960 if (REALM1_BOOK == o_ptr->tval &&
1961 p_ptr->pclass != CLASS_SORCERER &&
1962 p_ptr->pclass != CLASS_RED_MAGE)
1963 ADD_FLG(FLG_REALM1);
1965 if (REALM2_BOOK == o_ptr->tval &&
1966 p_ptr->pclass != CLASS_SORCERER &&
1967 p_ptr->pclass != CLASS_RED_MAGE)
1968 ADD_FLG(FLG_REALM2);
1970 if (o_ptr->tval >= TV_LIFE_BOOK && 0 == o_ptr->sval)
1972 if (o_ptr->tval >= TV_LIFE_BOOK && 1 == o_ptr->sval)
1973 ADD_FLG(FLG_SECOND);
1974 if (o_ptr->tval >= TV_LIFE_BOOK && 2 == o_ptr->sval)
1976 if (o_ptr->tval >= TV_LIFE_BOOK && 3 == o_ptr->sval)
1977 ADD_FLG(FLG_FOURTH);
1979 if (o_ptr->tval == TV_SHOT || o_ptr->tval == TV_BOLT
1980 || o_ptr->tval == TV_ARROW)
1981 ADD_FLG(FLG_MISSILES);
1982 else if (o_ptr->tval == TV_SCROLL || o_ptr->tval == TV_STAFF
1983 || o_ptr->tval == TV_WAND || o_ptr->tval == TV_ROD)
1984 ADD_FLG(FLG_DEVICES);
1985 else if (o_ptr->tval == TV_LITE)
1986 ADD_FLG(FLG_LIGHTS);
1987 else if (o_ptr->tval == TV_SKELETON || o_ptr->tval == TV_BOTTLE
1988 || o_ptr->tval == TV_JUNK || o_ptr->tval == TV_STATUE)
1990 else if (o_ptr->tval >= TV_LIFE_BOOK)
1991 ADD_FLG(FLG_SPELLBOOKS);
1992 else if (o_ptr->tval == TV_HAFTED)
1993 ADD_FLG(FLG_HAFTED);
1994 else if (o_ptr->tval == TV_POLEARM || o_ptr->tval == TV_SWORD
1995 || o_ptr->tval == TV_DIGGING)
1996 ADD_FLG(FLG_WEAPONS);
1997 else if (o_ptr->tval == TV_SHIELD)
1998 ADD_FLG(FLG_SHIELDS);
1999 else if (o_ptr->tval == TV_BOW)
2001 else if (o_ptr->tval == TV_RING)
2003 else if (o_ptr->tval == TV_AMULET)
2004 ADD_FLG(FLG_AMULETS);
2005 else if (o_ptr->tval == TV_DRAG_ARMOR || o_ptr->tval == TV_HARD_ARMOR ||
2006 o_ptr->tval == TV_SOFT_ARMOR)
2008 else if (o_ptr->tval == TV_CLOAK)
2009 ADD_FLG(FLG_CLOAKS);
2010 else if (o_ptr->tval == TV_HELM)
2012 else if (o_ptr->tval == TV_GLOVES)
2013 ADD_FLG(FLG_GLOVES);
2014 else if (o_ptr->tval == TV_BOOTS)
2022 * Choose an item and get auto-picker entry from it.
2024 static object_type *choose_object(cptr q, cptr s)
2028 if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR | USE_EQUIP))) return NULL;
2030 /* Get the item (in the pack) */
2031 if (item >= 0) return &inventory[item];
2033 /* Get the item (on the floor) */
2034 else return &o_list[0 - item];
2039 * Choose an item and get auto-picker entry from it.
2041 static bool entry_from_choosed_object(autopick_type *entry)
2048 q = "¤É¤Î¥¢¥¤¥Æ¥à¤òÅÐÏ¿¤·¤Þ¤¹¤«? ";
2049 s = "¥¢¥¤¥Æ¥à¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£";
2051 q = "Entry which item? ";
2052 s = "You have nothing to entry.";
2054 o_ptr = choose_object(q, s);
2055 if (!o_ptr) return FALSE;
2057 autopick_entry_from_object(entry, o_ptr);
2063 * Choose an item or string for search
2065 static bool get_string_for_search(object_type **o_handle, cptr *search_strp)
2069 char buf[MAX_NLEN+20];
2072 int k_flag[MAX_NLEN+20];
2073 char prompt[] = "¸¡º÷(^I:»ý¤Áʪ ^L:Ç˲õ¤µ¤ì¤¿Êª): ";
2075 char prompt[] = "Search key(^I:inven ^L:destroyed): ";
2077 int col = sizeof(prompt) - 1;
2079 if (*search_strp) strcpy(buf, *search_strp);
2082 /* Display prompt */
2085 /* Display the default answer */
2086 Term_erase(col, 0, 255);
2087 Term_putstr(col, 0, -1, TERM_YELLOW, buf);
2096 Term_gotoxy(col + pos, 0);
2098 /* Do not process macros except special keys */
2099 inkey_special = TRUE;
2104 /* Analyze the key */
2113 if (!pos && *o_handle) return TRUE;
2114 string_free(*search_strp);
2115 *search_strp = string_make(buf);
2122 q = "¤É¤Î¥¢¥¤¥Æ¥à¤ò¸¡º÷¤·¤Þ¤¹¤«? ";
2123 s = "¥¢¥¤¥Æ¥à¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£";
2125 q = "Entry which item? ";
2126 s = "You have nothing to entry.";
2128 o_ptr = choose_object(q, s);
2129 if (!o_ptr) return FALSE;
2133 string_free(*search_strp);
2134 object_desc(buf, *o_handle, FALSE, 3);
2135 *search_strp = string_make(format("<%s>", buf));
2139 if (!autopick_last_destroyed_object.k_idx) break;
2140 *o_handle = &autopick_last_destroyed_object;
2142 string_free(*search_strp);
2143 object_desc(buf, *o_handle, FALSE, 3);
2144 *search_strp = string_make(format("<%s>", buf));
2153 if (k_flag[pos]) pos--;
2168 if (pos + 1 < MAX_NLEN)
2176 else if (pos < MAX_NLEN && isprint(i))
2183 if (pos < MAX_NLEN && isprint(i)) buf[pos++] = i;
2192 /* Update the entry */
2193 Term_erase(col, 0, 255);
2194 Term_putstr(col, 0, -1, TERM_WHITE, buf);
2202 * Search next line matches for o_ptr
2204 static bool search_for_object(cptr *lines_list, object_type *o_ptr, int *cxp, int *cyp, bool forward)
2207 autopick_type an_entry, *entry = &an_entry;
2208 char o_name[MAX_NLEN];
2210 object_desc(o_name, o_ptr, FALSE, 3);
2212 /* Force to be lower case string */
2213 for (i = 0; o_name[i]; i++)
2216 if (iskanji(o_name[i]))
2220 if (isupper(o_name[i]))
2221 o_name[i] = tolower(o_name[i]);
2230 if (!lines_list[++i]) break;
2237 if (!autopick_new_entry(entry, lines_list[i])) continue;
2239 if (is_autopick_aux(o_ptr, entry, o_name))
2252 * Search next line matches to the string
2254 static bool search_for_string(cptr *lines_list, cptr search_str, int *cxp, int *cyp, bool forward)
2264 if (!lines_list[++i]) break;
2271 pos = strstr_j(lines_list[i], search_str);
2273 pos = strstr(lines_list[i], search_str);
2277 *cxp = (int)(pos - lines_list[i]);
2288 * Initialize auto-picker preference
2290 void init_autopicker(void)
2292 static const char easy_autopick_inscription[] = "(:=g";
2293 autopick_type entry;
2296 /* Clear old entries */
2297 for( i = 0; i < max_autopick; i++)
2298 autopick_free_entry(&autopick_list[i]);
2302 /* There is always one entry "=g" */
2303 autopick_new_entry(&entry, easy_autopick_inscription);
2304 autopick_list[max_autopick++] = entry;
2309 * Get a trigger key and insert ASCII string for the trigger
2311 static bool insert_macro_line(cptr *lines_list, int cy)
2320 /* Do not process macros */
2326 /* Read the pattern */
2332 /* Do not process macros */
2335 /* Do not wait for keys */
2338 /* Attempt to read a key */
2348 /* Convert the trigger */
2349 ascii_to_text(tmp, buf);
2352 if(!tmp[0]) return FALSE;
2354 /* Insert preference string */
2355 insert_return_code(lines_list, 0, cy);
2356 string_free(lines_list[cy]);
2357 lines_list[cy] = string_make(format("P:%s", tmp));
2359 /* Insert blank action preference line */
2360 insert_return_code(lines_list, 0, cy);
2361 string_free(lines_list[cy]);
2362 lines_list[cy] = string_make("A:");
2369 * Get a command key and insert ASCII string for the key
2371 static bool insert_keymap_line(cptr *lines_list, int cy)
2378 if (rogue_like_commands)
2380 mode = KEYMAP_MODE_ROGUE;
2386 mode = KEYMAP_MODE_ORIG;
2399 /* Convert the trigger */
2400 ascii_to_text(tmp, buf);
2403 if(!tmp[0]) return FALSE;
2405 /* Insert preference string */
2406 insert_return_code(lines_list, 0, cy);
2407 string_free(lines_list[cy]);
2408 lines_list[cy] = string_make(format("C:%d:%s", mode, tmp));
2410 /* Insert blank action preference line */
2411 insert_return_code(lines_list, 0, cy);
2412 string_free(lines_list[cy]);
2413 lines_list[cy] = string_make("A:");
2420 * Description of control commands
2425 static cptr ctrl_command_desc[] =
2428 #define LAST_DESTROYED 6
2429 "^P ^N ^B ^F ¾å²¼º¸±¦¤Ë°ÜÆ°",
2430 "^A ^E ¹Ô¤ÎÀèƬ¡¢½ªÃ¼",
2431 "^Q ÆþÎÏ/¥³¥Þ¥ó¥É¥â¡¼¥ÉÀÚ¤êÂؤ¨",
2432 "^R Êѹ¹¤òÁ´¤Æ¼è¤ê¾Ã¤·¤Æ¸µ¤ËÌ᤹",
2433 "------------------------------------",
2434 "^I »ý¤Áʪ/ÁõÈ÷¤«¤éÁªÂò",
2436 "^K ¥«¡¼¥½¥ë¤«¤é½ªÃ¼¤Þ¤Çºï½ü",
2437 "^Y ºï½ü(^K)¤·¤¿¹Ô¤òÁÞÆþ",
2438 "^C ¼ï²¡¢¿¦¶È¤Î¾ò·ï¼°¤òÁÞÆþ",
2439 "------------------------------------",
2440 "^S Êѹ¹ (!Ç˲õ/~ÊüÃÖ/½¦¤¦)",
2441 "^G \"(\" Á´ÂΥޥåפÇɽ¼¨¤·¤Ê¤¤",
2442 "^O \"#\" ¼«Æ°¹ï¤ß",
2443 "------------------------------------",
2444 "^U ̤´ÕÄê/̤ȽÌÀ/´ÕÄê/*´ÕÄê*",
2446 "^X ̵ÌÃ/¥¨¥´/¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È",
2450 #define LAST_DESTROYED 6
2451 "^P ^N ^B ^F Move Cursor",
2452 "^A ^E Beginning and End of Line",
2453 "^Q Toggle Insert/Command mode",
2454 "^R Revert to Original File",
2455 "------------------------------------",
2456 "^I Object in Inventry/Equipment",
2458 "^K Kill Rest of Line",
2459 "^Y Insert killed(^K) text",
2460 "^C Insert conditional expression",
2461 "------------------------------------",
2462 "^S Toggle(!Destroy/~Leave/Pick)",
2463 "^G \"(\" No display in the 'M'ap",
2464 "^O \"#\" Auto-Inscribe",
2465 "------------------------------------",
2466 "^U Toggle 'identified' state",
2468 "^X Toggle nameless/ego/artifact",
2469 "^Z \"collecting\"",
2475 #define MAX_YANK MAX_LINELEN
2476 #define DIRTY_ALL 0x01
2477 #define DIRTY_COMMAND 0x02
2478 #define DIRTY_MODE 0x04
2479 #define DIRTY_SCREEN 0x08
2480 #define DIRTY_NOT_FOUND 0x10
2483 * In-game editor of Object Auto-picker/Destoryer
2485 void do_cmd_edit_autopick(void)
2487 static int cx = 0, cy = 0;
2488 static int upper = 0, left = 0;
2490 object_type *search_o_ptr = NULL;
2491 cptr search_str = NULL;
2492 cptr last_destroyed = NULL;
2493 char last_destroyed_command[WID_DESC+3];
2494 char yank_buf[MAX_YANK];
2496 autopick_type an_entry, *entry = &an_entry;
2497 char buf[MAX_LINELEN];
2499 int filename_mode = PT_WITH_PNAME;
2504 int old_upper = -1, old_left = -1;
2506 int key = -1, old_key;
2507 bool repeated_clearing = FALSE;
2508 bool edit_mode = FALSE;
2510 byte dirty_flags = DIRTY_ALL | DIRTY_COMMAND | DIRTY_MODE;
2511 int dirty_line = -1;
2513 int wid, hgt, old_wid = -1, old_hgt = -1;
2515 static s32b old_autosave_turn = 0L;
2518 if (turn > old_autosave_turn + 100L)
2520 do_cmd_save_game(TRUE);
2521 old_autosave_turn = turn;
2524 /* HACK -- Reset start_time to stop counting playtime while edit */
2527 /* Free old entries */
2530 /* Command Description of the 'Last Destroyed Item' */
2531 if (autopick_last_destroyed_object.k_idx)
2533 autopick_entry_from_object(entry, &autopick_last_destroyed_object);
2534 last_destroyed = autopick_line_from_entry_kill(entry);
2536 my_strcpy(last_destroyed_command, format("^L \"%s\"", last_destroyed), sizeof(last_destroyed_command));
2541 strcpy(last_destroyed_command, "^L ºÇ¸å¤Ë¼«Æ°Ç˲õ¤·¤¿¥¢¥¤¥Æ¥à̾");
2543 strcpy(last_destroyed_command, "^L Last destroyed object");
2546 ctrl_command_desc[LAST_DESTROYED] = last_destroyed_command;
2548 /* Conditional Expression for Class and Race */
2549 sprintf(classrace, "?:[AND [EQU $RACE %s] [EQU $CLASS %s]]",
2551 rp_ptr->E_title, cp_ptr->E_title
2553 rp_ptr->title, cp_ptr->title
2557 /* Clear yank buffer */
2560 /* Read or initialize whole text */
2561 lines_list = read_pickpref_text_lines(&filename_mode);
2563 /* Reset cursor position if needed */
2564 for (i = 0; i < cy; i++)
2573 /* Save the screen */
2576 /* Process requests until done */
2580 Term_get_size(&wid, &hgt);
2583 /* Don't let cursor at second byte of kanji */
2584 for (i = 0; lines_list[cy][i]; i++)
2585 if (iskanji(lines_list[cy][i]))
2596 /* Scroll if necessary */
2597 if (cy < upper || upper + hgt - 4 <= cy)
2598 upper = cy - (hgt-4)/2;
2601 if ((cx < left + 10 && left > 0) || left + wid - WID_DESC - 5 <= cx)
2602 left = cx - (wid - WID_DESC)*2/3;
2606 /* Redraw whole window after resize */
2607 if (old_wid != wid || old_hgt != hgt)
2608 dirty_flags |= DIRTY_SCREEN;
2610 /* Redraw all text after scroll */
2611 else if (old_upper != upper || old_left != left)
2612 dirty_flags |= DIRTY_ALL;
2615 if (dirty_flags & DIRTY_SCREEN)
2617 dirty_flags |= (DIRTY_ALL | DIRTY_COMMAND | DIRTY_MODE);
2623 if (dirty_flags & DIRTY_COMMAND)
2625 /* Display control command */
2626 for (i = 0; ctrl_command_desc[i]; i++)
2627 Term_putstr(wid - WID_DESC, i + 1, WID_DESC, TERM_WHITE, ctrl_command_desc[i]);
2630 /* Redraw mode line */
2631 if (dirty_flags & DIRTY_MODE)
2633 int sepa_length = wid - WID_DESC;
2636 for (i = 0; i < sepa_length; i++)
2642 strncpy(buf + sepa_length - 21, " (INSERT MODE) ", 16);
2644 strncpy(buf + sepa_length - 21, " (COMMAND MODE) ", 16);
2646 Term_putstr(0, hgt - 3, sepa_length, (byte) (edit_mode ? TERM_YELLOW : TERM_WHITE), buf);
2649 /* Dump up to 20, or hgt-4, lines of messages */
2650 for (i = 0; i < hgt - 4; i++)
2655 /* clean or dirty? */
2656 if (!(dirty_flags & DIRTY_ALL) && (dirty_line != upper+i))
2659 msg = lines_list[upper+i];
2662 /* Apply horizontal scroll */
2663 for (j = 0; *msg; msg++, j++)
2665 if (j == left) break;
2681 Term_erase(0, i + 1, wid - WID_DESC);
2683 /* Dump the messages, bottom to top */
2684 Term_putstr(leftcol, i + 1, wid - WID_DESC - 1, TERM_WHITE, msg);
2687 for (; i < hgt - 4; i++)
2690 Term_erase(0, i + 1, wid - WID_DESC);
2693 /* Display header line */
2696 prt("^Q ESC ¤Ç¥³¥Þ¥ó¥É¥â¡¼¥É¤Ø°Ü¹Ô¡¢Ä̾ï¤Îʸ»ú¤Ï¤½¤Î¤Þ¤ÞÆþÎÏ", 0, 0);
2698 prt("q _ ¤Ç½ªÎ»¡¢hjkl2468 ¤Ç°ÜÆ°¡¢^Q a i ¤ÇÆþÎϥ⡼¥É", 0, 0);
2701 prt("Press ^Q ESC to command mode, any letters to insert", 0, 0);
2703 prt("Press q _ to quit, hjkl2468 to move, ^Q a i to insert mode", 0, 0);
2705 /* Display current position */
2706 prt (format("(%d,%d)", cx, cy), 0, 70);
2708 /* Display information when updated */
2709 if (old_cy != cy || (dirty_flags & (DIRTY_ALL | DIRTY_NOT_FOUND)) || dirty_line == cy)
2711 /* Clear information line */
2712 Term_erase(0, hgt - 3 + 1, wid);
2713 Term_erase(0, hgt - 3 + 2, wid);
2715 /* Display information */
2716 if (dirty_flags & DIRTY_NOT_FOUND)
2719 prt(format("¥Ñ¥¿¡¼¥ó¤¬¸«¤Ä¤«¤ê¤Þ¤»¤ó: %s", search_str), hgt - 3 + 1, 0);
2721 prt(format("Pattern not found: %s", search_str), hgt - 3 + 1, 0);
2724 else if (lines_list[cy][0] == '#')
2727 prt("¤³¤Î¹Ô¤Ï¥³¥á¥ó¥È¤Ç¤¹¡£", hgt - 3 + 1, 0);
2729 prt("This line is comment.", hgt - 3 + 1, 0);
2732 else if (lines_list[cy][1] == ':')
2734 switch(lines_list[cy][0])
2738 prt("¤³¤Î¹Ô¤Ï¾ò·ïʬ´ô¼°¤Ç¤¹¡£", hgt - 3 + 1, 0);
2740 prt("This line is Conditional Expression.", hgt - 3 + 1, 0);
2745 prt("¤³¤Î¹Ô¤Ï¥Þ¥¯¥í¤Î¼Â¹ÔÆâÍƤòÄêµÁ¤·¤Þ¤¹¡£", hgt - 3 + 1, 0);
2747 prt("This line defines Macro action.", hgt - 3 + 1, 0);
2752 prt("¤³¤Î¹Ô¤Ï¥Þ¥¯¥í¤Î¥È¥ê¥¬¡¼¡¦¥¡¼¤òÄêµÁ¤·¤Þ¤¹¡£", hgt - 3 + 1, 0);
2754 prt("This line defines Macro trigger key.", hgt - 3 + 1, 0);
2759 prt("¤³¤Î¹Ô¤Ï¥¡¼ÇÛÃÖ¤òÄêµÁ¤·¤Þ¤¹¡£", hgt - 3 + 1, 0);
2761 prt("This line defines Keymap.", hgt - 3 + 1, 0);
2767 /* Get description of an autopicker preference line */
2768 else if (autopick_new_entry(entry, lines_list[cy]))
2773 describe_autopick(buf, entry);
2775 roff_to_buf(buf, 81, temp);
2777 for (i = 0; i< 2; i++)
2783 prt(t, hgt - 3 + 1 + i, 0);
2787 autopick_free_entry(entry);
2792 Term_gotoxy(cx - left, cy - upper + 1);
2798 /* Save old key and location */
2806 /* Do not process macros except special keys */
2807 inkey_special = TRUE;
2818 /* Mode line is now dirty */
2819 dirty_flags |= DIRTY_MODE;
2822 /* Insert a character */
2823 else if (!iscntrl(key&0xff))
2827 /* Save preceding string */
2828 for (i = j = 0; lines_list[cy][i] && i < cx; i++)
2829 buf[j++] = lines_list[cy][i];
2831 /* Add a character */
2837 if (j+2 < MAX_LINELEN)
2849 if (j+1 < MAX_LINELEN)
2855 for (; lines_list[cy][i] && j + 1 < MAX_LINELEN; i++)
2856 buf[j++] = lines_list[cy][i];
2859 /* Replace current line with new line */
2860 string_free(lines_list[cy]);
2861 lines_list[cy] = string_make(buf);
2863 /* Move to correct collumn */
2864 len = strlen(lines_list[cy]);
2865 if (len < cx) cx = len;
2874 if (key == 'q' || key == '_') break;
2881 /* Mode line is now dirty */
2882 dirty_flags |= DIRTY_MODE;
2885 if (!autopick_new_entry(entry, lines_list[cy]))
2887 if (old_key != key) repeated_clearing = FALSE;
2890 if (lines_list[cy + 1]) cy++;
2894 string_free(lines_list[cy]);
2898 if (entry->action & DONT_AUTOPICK)
2899 repeated_clearing = TRUE;
2901 repeated_clearing = FALSE;
2904 entry->action &= ~DO_AUTODESTROY;
2905 if (!repeated_clearing)
2907 entry->action &= ~DO_AUTOPICK;
2908 entry->action |= DONT_AUTOPICK;
2912 entry->action &= ~DONT_AUTOPICK;
2913 entry->action |= DO_AUTOPICK;
2916 lines_list[cy] = autopick_line_from_entry_kill(entry);
2922 if (lines_list[cy + 1]) cy++;
2926 if (!autopick_new_entry(entry, lines_list[cy]))
2928 if (old_key != key) repeated_clearing = FALSE;
2931 if (lines_list[cy + 1]) cy++;
2935 string_free(lines_list[cy]);
2939 if (entry->action & DO_AUTODESTROY)
2940 repeated_clearing = TRUE;
2942 repeated_clearing = FALSE;
2945 entry->action &= ~DONT_AUTOPICK;
2946 if (!repeated_clearing)
2948 entry->action &= ~DO_AUTOPICK;
2949 entry->action |= DO_AUTODESTROY;
2953 entry->action &= ~DO_AUTODESTROY;
2954 entry->action |= DO_AUTOPICK;
2957 lines_list[cy] = autopick_line_from_entry_kill(entry);
2963 if (lines_list[cy + 1]) cy++;
2967 /* Toggle display on the 'M'ap */
2968 if (!autopick_new_entry(entry, lines_list[cy]))
2970 if (old_key != key) repeated_clearing = FALSE;
2973 if (lines_list[cy + 1]) cy++;
2977 string_free(lines_list[cy]);
2981 if (entry->action & DO_DISPLAY)
2982 repeated_clearing = TRUE;
2984 repeated_clearing = FALSE;
2987 if (!repeated_clearing)
2988 entry->action |= DO_DISPLAY;
2990 entry->action &= ~DO_DISPLAY;
2992 lines_list[cy] = autopick_line_from_entry_kill(entry);
2998 if (lines_list[cy + 1]) cy++;
3018 while (cy < upper + hgt-4 && lines_list[cy + 1])
3023 while (0 < cy && upper <= cy)
3025 while (0 < upper && cy + 1 < upper + hgt - 4)
3034 while (lines_list[cy + 1])
3040 Term_erase(0, cy - upper + 1, wid - WID_DESC);
3044 Term_putstr(0, cy - upper + 1, wid - WID_DESC - 1, TERM_YELLOW, "P:<¥È¥ê¥¬¡¼¥¡¼>: ");
3046 Term_putstr(0, cy - upper + 1, wid - WID_DESC - 1, TERM_YELLOW, "P:<Trigger key>: ");
3048 if (insert_macro_line(lines_list, cy))
3050 /* Prepare to input action */
3055 dirty_flags |= DIRTY_ALL;
3056 dirty_flags |= DIRTY_MODE;
3063 Term_erase(0, cy - upper + 1, wid - WID_DESC);
3067 Term_putstr(0, cy - upper + 1, wid - WID_DESC - 1, TERM_YELLOW, format("C:%d:<¥³¥Þ¥ó¥É¥¡¼>: ", (rogue_like_commands ? KEYMAP_MODE_ROGUE : KEYMAP_MODE_ORIG)));
3069 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)));
3072 if (insert_keymap_line(lines_list, cy))
3074 /* Prepare to input action */
3079 dirty_flags |= DIRTY_ALL;
3080 dirty_flags |= DIRTY_MODE;
3084 /* Become dirty because of item/equip menu */
3085 dirty_flags |= DIRTY_SCREEN;
3087 if (!get_string_for_search(&search_o_ptr, &search_str))
3094 if (!search_for_object(lines_list, search_o_ptr, &cx, &cy, TRUE)) dirty_flags |= DIRTY_NOT_FOUND;
3096 else if (search_str)
3098 if (!search_for_string(lines_list, search_str, &cx, &cy, TRUE)) dirty_flags |= DIRTY_NOT_FOUND;
3104 if (!search_for_object(lines_list, search_o_ptr, &cx, &cy, FALSE)) dirty_flags |= DIRTY_NOT_FOUND;
3106 else if (search_str)
3108 if (!search_for_string(lines_list, search_str, &cx, &cy, FALSE)) dirty_flags |= DIRTY_NOT_FOUND;
3117 /* Beginning of line */
3125 len = strlen(lines_list[cy]);
3126 if (len < cx) cx = len;
3131 cx = strlen(lines_list[cy]);
3135 /* Insert a conditinal expression line */
3136 insert_return_code(lines_list, 0, cy);
3137 string_free(lines_list[cy]);
3138 lines_list[cy] = string_make(classrace);
3140 insert_return_code(lines_list, 0, cy);
3141 string_free(lines_list[cy]);
3142 lines_list[cy] = string_make("?:1");
3146 dirty_flags |= DIRTY_ALL;
3150 cx = strlen(lines_list[cy]);
3155 if (iskanji(lines_list[cy][cx])) cx++;
3158 len = strlen(lines_list[cy]);
3161 if (lines_list[cy + 1])
3171 /* Toggle display on the 'M'ap */
3172 if (!autopick_new_entry(entry, lines_list[cy]))
3174 string_free(lines_list[cy]);
3176 if (entry->action & DO_DISPLAY)
3178 entry->action &= ~DO_DISPLAY;
3183 entry->action |= DO_DISPLAY;
3187 lines_list[cy] = autopick_line_from_entry_kill(entry);
3193 /* Insert choosen item name */
3194 if (!entry_from_choosed_object(entry))
3196 /* Now dirty because of item/equip menu */
3197 dirty_flags |= DIRTY_SCREEN;
3201 insert_return_code(lines_list, 0, cy);
3202 string_free(lines_list[cy]);
3203 lines_list[cy] = autopick_line_from_entry_kill(entry);
3206 /* Now dirty because of item/equip menu */
3207 dirty_flags |= DIRTY_SCREEN;
3211 /* Insert a name of last destroyed item */
3214 insert_return_code(lines_list, 0, cy);
3215 string_free(lines_list[cy]);
3216 lines_list[cy] = string_make(last_destroyed);
3220 dirty_flags |= DIRTY_ALL;
3223 case '\n': case '\r':
3224 /* Split a line or insert end of line */
3225 insert_return_code(lines_list, cx, cy);
3230 dirty_flags |= DIRTY_ALL;
3234 if (lines_list[cy + 1]) cy++;
3237 /* Prepare to write auto-inscription text */
3238 if (!autopick_new_entry(entry, lines_list[cy]))
3240 string_free(lines_list[cy]);
3242 if (!entry->insc) entry->insc = string_make("");
3244 lines_list[cy] = autopick_line_from_entry_kill(entry);
3246 /* Move to collumn for auto inscription */
3247 for (cx = 0; lines_list[cy][cx]; cx++)
3248 if (lines_list[cy][cx] == '#') break;
3254 dirty_flags |= DIRTY_MODE;
3262 edit_mode = !edit_mode;
3264 /* Mode line is now dirty */
3265 dirty_flags |= DIRTY_MODE;
3268 /* Revert to original */
3270 if (!get_check("Á´¤Æ¤ÎÊѹ¹¤òÇË´þ¤·¤Æ¸µ¤Î¾õÂÖ¤ËÌᤷ¤Þ¤¹¡£¤è¤í¤·¤¤¤Ç¤¹¤«¡© "))
3272 if (!get_check("Discard all change and revert to original file. Are you sure? "))
3276 free_text_lines(lines_list);
3277 lines_list = read_pickpref_text_lines(&filename_mode);
3278 dirty_flags |= DIRTY_ALL | DIRTY_MODE;
3283 /* Rotate action; pickup/destroy/leave */
3284 if (!autopick_new_entry(entry, lines_list[cy]))
3286 string_free(lines_list[cy]);
3288 if (entry->action & DO_AUTOPICK)
3290 entry->action &= ~DO_AUTOPICK;
3291 entry->action |= DO_AUTODESTROY;
3293 else if (entry->action & DO_AUTODESTROY)
3295 entry->action &= ~DO_AUTODESTROY;
3296 entry->action |= DONT_AUTOPICK;
3298 else if (entry->action & DONT_AUTOPICK)
3300 entry->action &= ~DONT_AUTOPICK;
3301 entry->action |= DO_AUTOPICK;
3304 lines_list[cy] = autopick_line_from_entry_kill(entry);
3314 /* Rotate identify-state; identified/unidentified/... */
3315 if (!autopick_new_entry(entry, lines_list[cy]))
3317 string_free(lines_list[cy]);
3319 if (IS_FLG(FLG_UNIDENTIFIED))
3321 REM_FLG(FLG_UNIDENTIFIED);
3322 ADD_FLG(FLG_UNAWARE);
3323 REM_FLG(FLG_IDENTIFIED);
3324 REM_FLG(FLG_STAR_IDENTIFIED);
3326 else if (IS_FLG(FLG_UNAWARE))
3328 REM_FLG(FLG_UNIDENTIFIED);
3329 REM_FLG(FLG_UNAWARE);
3330 ADD_FLG(FLG_IDENTIFIED);
3331 REM_FLG(FLG_STAR_IDENTIFIED);
3333 else if (IS_FLG(FLG_STAR_IDENTIFIED))
3335 REM_FLG(FLG_UNIDENTIFIED);
3336 REM_FLG(FLG_UNAWARE);
3337 REM_FLG(FLG_IDENTIFIED);
3338 REM_FLG(FLG_STAR_IDENTIFIED);
3340 else if (IS_FLG(FLG_IDENTIFIED))
3342 REM_FLG(FLG_UNIDENTIFIED);
3343 REM_FLG(FLG_UNAWARE);
3344 REM_FLG(FLG_IDENTIFIED);
3345 ADD_FLG(FLG_STAR_IDENTIFIED);
3349 ADD_FLG(FLG_UNIDENTIFIED);
3350 REM_FLG(FLG_UNAWARE);
3351 REM_FLG(FLG_IDENTIFIED);
3352 REM_FLG(FLG_STAR_IDENTIFIED);
3355 lines_list[cy] = autopick_line_from_entry_kill(entry);
3362 while (cy < upper + hgt-4 && lines_list[cy + 1])
3367 /* Toggle 'worthless' */
3368 toggle_string(lines_list, FLG_WORTHLESS, cy);
3373 /* Rotate within nameless, ego, artifact */
3374 if (!autopick_new_entry(entry, lines_list[cy]))
3376 string_free(lines_list[cy]);
3378 if (IS_FLG(FLG_NAMELESS))
3380 REM_FLG(FLG_NAMELESS);
3382 REM_FLG(FLG_ARTIFACT);
3384 else if (IS_FLG(FLG_EGO))
3386 REM_FLG(FLG_NAMELESS);
3388 ADD_FLG(FLG_ARTIFACT);
3390 else if (IS_FLG(FLG_ARTIFACT))
3392 REM_FLG(FLG_NAMELESS);
3394 REM_FLG(FLG_ARTIFACT);
3398 ADD_FLG(FLG_NAMELESS);
3400 REM_FLG(FLG_ARTIFACT);
3403 lines_list[cy] = autopick_line_from_entry_kill(entry);
3410 /* Paste killed text */
3411 if (strlen(yank_buf))
3415 for (j = 0; yank_buf[j]; j += strlen(yank_buf + j) + 1)
3417 if (ret && '\n' == yank_buf[j])
3423 /* Split current line */
3424 insert_return_code(lines_list, cx, cy);
3426 /* Save preceding string */
3427 for(i = 0; lines_list[cy][i]; i++)
3428 buf[i] = lines_list[cy][i];
3430 /* Paste yank buffer */
3431 if ('\n' != yank_buf[j])
3434 while (yank_buf[k] && i < MAX_LINELEN-1)
3435 buf[i++] = yank_buf[k++];
3441 string_free(lines_list[cy]);
3442 lines_list[cy] = string_make(buf);
3444 /* Move to the beggining of next line */
3450 dirty_flags |= DIRTY_ALL;
3454 /* Toggle 'collecting' */
3455 toggle_string(lines_list, FLG_COLLECTING, cy);
3461 /* Kill rest of line */
3462 if ((uint)cx > strlen(lines_list[cy]))
3463 cx = (int)strlen(lines_list[cy]);
3465 /* Save preceding string */
3466 for (i = 0; lines_list[cy][i] && i < cx; i++)
3469 if (iskanji(lines_list[cy][i]))
3471 buf[i] = lines_list[cy][i];
3475 buf[i] = lines_list[cy][i];
3482 j += strlen(yank_buf + j) + 1;
3484 /* Copy following to yank buffer */
3485 if (lines_list[cy][i])
3487 while (lines_list[cy][i] && j < MAX_YANK - 2)
3488 yank_buf[j++] = lines_list[cy][i++];
3493 if (j < MAX_YANK - 2)
3494 yank_buf[j++] = '\n';
3497 yank_buf[j++] = '\0';
3500 /* Replace current line with 'preceding string' */
3501 string_free(lines_list[cy]);
3502 lines_list[cy] = string_make(buf);
3514 /* DELETE == go forward + BACK SPACE */
3516 if (iskanji(lines_list[cy][cx])) cx++;
3524 len = strlen(lines_list[cy]);
3527 if (lines_list[cy + 1])
3541 /* delete a return code and union two lines */
3543 cx = strlen(lines_list[cy-1]);
3544 strcpy(buf, lines_list[cy-1]);
3545 strcat(buf, lines_list[cy]);
3546 string_free(lines_list[cy-1]);
3547 string_free(lines_list[cy]);
3548 lines_list[cy-1] = string_make(buf);
3549 for (i = cy; lines_list[i+1]; i++)
3550 lines_list[i] = lines_list[i+1];
3551 lines_list[i] = NULL;
3555 dirty_flags |= DIRTY_ALL;
3559 for (i = j = k = 0; lines_list[cy][i] && i < cx; i++)
3563 if (iskanji(lines_list[cy][i]))
3564 buf[j++] = lines_list[cy][i++];
3566 buf[j++] = lines_list[cy][i];
3573 for (; lines_list[cy][i]; i++)
3574 buf[j++] = lines_list[cy][i];
3576 string_free(lines_list[cy]);
3577 lines_list[cy] = string_make(buf);
3586 /* Restore the screen */
3589 switch (filename_mode)
3593 strcpy(buf, "picktype.prf");
3595 strcpy(buf, "pickpref.prf");
3601 sprintf(buf, "picktype-%s.prf", player_name);
3603 sprintf(buf, "pickpref-%s.prf", player_name);
3608 write_text_lines(buf, lines_list);
3609 free_text_lines(lines_list);
3611 string_free(last_destroyed);
3613 /* Reload autopick pref */
3614 process_pickpref_file(buf);
3616 /* HACK -- reset start_time so that playtime is not increase while edit */
3617 start_time = time(NULL);