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.
19 #define FLG_COLLECTING 1
20 #define FLG_UNIDENTIFIED 2
21 #define FLG_IDENTIFIED 3
22 #define FLG_STAR_IDENTIFIED 4
24 #define FLG_MORE_THAN 6
26 #define FLG_MORE_BONUS 8
27 #define FLG_MORE_BONUS2 9
28 #define FLG_WORTHLESS 10
29 #define FLG_ARTIFACT 11
31 #define FLG_NAMELESS 13
32 #define FLG_UNAWARE 14
36 #define FLG_UNREADABLE 18
45 #define FLG_WEAPONS 31
47 #define FLG_MISSILES 33
48 #define FLG_DEVICES 34
51 #define FLG_SPELLBOOKS 37
53 #define FLG_SHIELDS 39
56 #define FLG_AMULETS 42
65 #define KEY_ALL "¤¹¤Ù¤Æ¤Î"
66 #define KEY_COLLECTING "¼ý½¸Ãæ¤Î"
67 #define KEY_UNIDENTIFIED "̤´ÕÄê¤Î"
68 #define KEY_IDENTIFIED "´ÕÄêºÑ¤ß¤Î"
69 #define KEY_STAR_IDENTIFIED "*´ÕÄê*ºÑ¤ß¤Î"
70 #define KEY_BOOSTED "¥À¥¤¥¹Ìܤΰ㤦"
71 #define KEY_MORE_THAN "¥À¥¤¥¹ÌÜ"
72 #define KEY_DICE "°Ê¾å¤Î"
73 #define KEY_MORE_BONUS "½¤ÀµÃͤ¬"
74 #define KEY_MORE_BONUS2 "°Ê¾å¤Î"
75 #define KEY_WORTHLESS "̵²ÁÃͤÎ"
76 #define KEY_ARTIFACT "¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È"
77 #define KEY_EGO "¥¨¥´"
78 #define KEY_NAMELESS "̵ÌäÎ"
79 #define KEY_UNAWARE "̤ȽÌÀ¤Î"
80 #define KEY_WANTED "¾Þ¶â¼ó¤Î"
81 #define KEY_UNIQUE "¥æ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼¤Î"
82 #define KEY_HUMAN "¿Í´Ö¤Î"
83 #define KEY_UNREADABLE "Æɤá¤Ê¤¤"
84 #define KEY_REALM1 "Âè°ìÎΰè¤Î"
85 #define KEY_REALM2 "ÂèÆóÎΰè¤Î"
86 #define KEY_FIRST "1ºýÌܤÎ"
87 #define KEY_SECOND "2ºýÌܤÎ"
88 #define KEY_THIRD "3ºýÌܤÎ"
89 #define KEY_FOURTH "4ºýÌܤÎ"
90 #define KEY_ITEMS "¥¢¥¤¥Æ¥à"
91 #define KEY_WEAPONS "Éð´ï"
92 #define KEY_ARMORS "Ëɶñ"
93 #define KEY_MISSILES "Ìð"
94 #define KEY_DEVICES "ËâË¡¥¢¥¤¥Æ¥à"
95 #define KEY_LIGHTS "¸÷¸»"
96 #define KEY_JUNKS "¤¬¤é¤¯¤¿"
97 #define KEY_SPELLBOOKS "ËâË¡½ñ"
98 #define KEY_HAFTED "Æß´ï"
99 #define KEY_SHIELDS "½â"
100 #define KEY_BOWS "µÝ"
101 #define KEY_RINGS "»ØÎØ"
102 #define KEY_AMULETS "¥¢¥ß¥å¥ì¥Ã¥È"
103 #define KEY_SUITS "³»"
104 #define KEY_CLOAKS "¥¯¥í¡¼¥¯"
105 #define KEY_HELMS "³õ"
106 #define KEY_GLOVES "äƼê"
107 #define KEY_BOOTS "·¤"
111 #define KEY_ALL "all"
112 #define KEY_COLLECTING "collecting"
113 #define KEY_UNIDENTIFIED "unidentified"
114 #define KEY_IDENTIFIED "identified"
115 #define KEY_STAR_IDENTIFIED "*identified*"
116 #define KEY_BOOSTED "dice boosted"
117 #define KEY_MORE_THAN "more than"
118 #define KEY_DICE " dice"
119 #define KEY_MORE_BONUS "more bonus than"
120 #define KEY_MORE_BONUS2 ""
121 #define KEY_WORTHLESS "worthless"
122 #define KEY_ARTIFACT "artifact"
123 #define KEY_EGO "ego"
124 #define KEY_NAMELESS "nameless"
125 #define KEY_UNAWARE "unaware"
126 #define KEY_WANTED "wanted"
127 #define KEY_UNIQUE "unique monster's"
128 #define KEY_HUMAN "human"
129 #define KEY_UNREADABLE "unreadable"
130 #define KEY_REALM1 "first realm's"
131 #define KEY_REALM2 "second realm's"
132 #define KEY_FIRST "first"
133 #define KEY_SECOND "second"
134 #define KEY_THIRD "third"
135 #define KEY_FOURTH "fourth"
136 #define KEY_ITEMS "items"
137 #define KEY_WEAPONS "weapons"
138 #define KEY_ARMORS "armors"
139 #define KEY_MISSILES "missiles"
140 #define KEY_DEVICES "magical devices"
141 #define KEY_LIGHTS "lights"
142 #define KEY_JUNKS "junks"
143 #define KEY_SPELLBOOKS "spellbooks"
144 #define KEY_HAFTED "hafted weapons"
145 #define KEY_SHIELDS "shields"
146 #define KEY_BOWS "bows"
147 #define KEY_RINGS "rings"
148 #define KEY_AMULETS "amulets"
149 #define KEY_SUITS "suits"
150 #define KEY_CLOAKS "cloaks"
151 #define KEY_HELMS "helms"
152 #define KEY_GLOVES "gloves"
153 #define KEY_BOOTS "boots"
157 #define MATCH_KEY(KEY) (!strncmp(ptr, KEY, sizeof(KEY)-1)\
158 ? (prev_ptr = ptr, ptr += sizeof(KEY)-1, (' '==*ptr) ? ptr++ : 0, TRUE) : FALSE)
161 #define ADD_KEY(KEY) strcat(ptr, KEY)
163 #define ADD_KEY(KEY) (strcat(ptr, KEY), strcat(ptr, " "))
165 #define ADD_KEY2(KEY) strcat(ptr, KEY)
167 #define ADD_FLG(FLG) (entry->flag[FLG / 32] |= (1L << (FLG % 32)))
168 #define REM_FLG(FLG) (entry->flag[FLG / 32] &= ~(1L << (FLG % 32)))
169 #define ADD_FLG_ADJ(FLG) (ADD_FLG(FLG), prev_flg = -1)
170 #define ADD_FLG_NOUN(FLG) (ADD_FLG(FLG), prev_flg = FLG)
171 #define IS_FLG(FLG) (entry->flag[FLG / 32] & (1L << (FLG % 32)))
174 static char kanji_colon[] = "¡§";
179 * Reconstruct preference line from entry
181 cptr autopick_line_from_entry(autopick_type *entry)
185 bool sepa_flag = TRUE;
188 if (!(entry->action & DO_DISPLAY)) strcat(buf, "(");
189 if (entry->action & DO_AUTODESTROY) strcat(buf, "!");
190 if (entry->action & DONT_AUTOPICK) strcat(buf, "~");
194 if (IS_FLG(FLG_ALL)) ADD_KEY(KEY_ALL);
195 if (IS_FLG(FLG_COLLECTING)) ADD_KEY(KEY_COLLECTING);
196 if (IS_FLG(FLG_UNIDENTIFIED)) ADD_KEY(KEY_UNIDENTIFIED);
197 if (IS_FLG(FLG_IDENTIFIED)) ADD_KEY(KEY_IDENTIFIED);
198 if (IS_FLG(FLG_STAR_IDENTIFIED)) ADD_KEY(KEY_STAR_IDENTIFIED);
199 if (IS_FLG(FLG_BOOSTED)) ADD_KEY(KEY_BOOSTED);
201 if (IS_FLG(FLG_MORE_THAN))
203 ADD_KEY(KEY_MORE_THAN);
204 strcat(ptr, format("%d", entry->dice));
208 if (IS_FLG(FLG_MORE_BONUS))
210 ADD_KEY(KEY_MORE_BONUS);
211 strcat(ptr, format("%d", entry->bonus));
212 ADD_KEY(KEY_MORE_BONUS2);
215 if (IS_FLG(FLG_WORTHLESS)) ADD_KEY(KEY_WORTHLESS);
216 if (IS_FLG(FLG_ARTIFACT)) ADD_KEY(KEY_ARTIFACT);
217 if (IS_FLG(FLG_EGO)) ADD_KEY(KEY_EGO);
218 if (IS_FLG(FLG_NAMELESS)) ADD_KEY(KEY_NAMELESS);
219 if (IS_FLG(FLG_UNAWARE)) ADD_KEY(KEY_UNAWARE);
220 if (IS_FLG(FLG_WANTED)) ADD_KEY(KEY_WANTED);
221 if (IS_FLG(FLG_UNIQUE)) ADD_KEY(KEY_UNIQUE);
222 if (IS_FLG(FLG_HUMAN)) ADD_KEY(KEY_HUMAN);
223 if (IS_FLG(FLG_UNREADABLE)) ADD_KEY(KEY_UNREADABLE);
224 if (IS_FLG(FLG_REALM1)) ADD_KEY(KEY_REALM1);
225 if (IS_FLG(FLG_REALM2)) ADD_KEY(KEY_REALM2);
226 if (IS_FLG(FLG_FIRST)) ADD_KEY(KEY_FIRST);
227 if (IS_FLG(FLG_SECOND)) ADD_KEY(KEY_SECOND);
228 if (IS_FLG(FLG_THIRD)) ADD_KEY(KEY_THIRD);
229 if (IS_FLG(FLG_FOURTH)) ADD_KEY(KEY_FOURTH);
231 if (IS_FLG(FLG_ITEMS)) ADD_KEY2(KEY_ITEMS);
232 else if (IS_FLG(FLG_WEAPONS)) ADD_KEY2(KEY_WEAPONS);
233 else if (IS_FLG(FLG_ARMORS)) ADD_KEY2(KEY_ARMORS);
234 else if (IS_FLG(FLG_MISSILES)) ADD_KEY2(KEY_MISSILES);
235 else if (IS_FLG(FLG_DEVICES)) ADD_KEY2(KEY_DEVICES);
236 else if (IS_FLG(FLG_LIGHTS)) ADD_KEY2(KEY_LIGHTS);
237 else if (IS_FLG(FLG_JUNKS)) ADD_KEY2(KEY_JUNKS);
238 else if (IS_FLG(FLG_SPELLBOOKS)) ADD_KEY2(KEY_SPELLBOOKS);
239 else if (IS_FLG(FLG_HAFTED)) ADD_KEY2(KEY_HAFTED);
240 else if (IS_FLG(FLG_SHIELDS)) ADD_KEY2(KEY_SHIELDS);
241 else if (IS_FLG(FLG_BOWS)) ADD_KEY2(KEY_BOWS);
242 else if (IS_FLG(FLG_RINGS)) ADD_KEY2(KEY_RINGS);
243 else if (IS_FLG(FLG_AMULETS)) ADD_KEY2(KEY_AMULETS);
244 else if (IS_FLG(FLG_SUITS)) ADD_KEY2(KEY_SUITS);
245 else if (IS_FLG(FLG_CLOAKS)) ADD_KEY2(KEY_CLOAKS);
246 else if (IS_FLG(FLG_HELMS)) ADD_KEY2(KEY_HELMS);
247 else if (IS_FLG(FLG_GLOVES)) ADD_KEY2(KEY_GLOVES);
248 else if (IS_FLG(FLG_BOOTS)) ADD_KEY2(KEY_BOOTS);
252 if (entry->name && *entry->name)
256 strcat(buf, entry->name);
260 if (entry->flag[0] == 0L && entry->flag[0] == 0L)
267 strcat(buf, entry->insc);
270 return string_make(buf);
274 * A function to create new entry
276 bool autopick_new_entry(autopick_type *entry, cptr str)
285 if (str[1] == ':') switch (str[0])
288 case 'A': case 'P': case 'C':
292 entry->flag[0] = entry->flag[1] = 0L;
295 act = DO_AUTOPICK | DO_DISPLAY;
298 if ((act & DO_AUTOPICK) && *str == '!')
301 act |= DO_AUTODESTROY;
304 else if ((act & DO_AUTOPICK) && *str == '~')
307 act |= DONT_AUTOPICK;
310 else if ((act & DO_DISPLAY) && *str == '(')
319 /* don't mind upper or lower case */
321 for (i = 0; *str; i++)
332 /* Auto-inscription? */
340 if (isupper(c)) c = tolower(c);
346 /* Skip empty line */
347 if (*buf == 0) return FALSE;
350 prev_ptr = ptr = buf;
352 if (MATCH_KEY(KEY_ALL)) ADD_FLG_ADJ(FLG_ALL);
353 if (MATCH_KEY(KEY_COLLECTING)) ADD_FLG_ADJ(FLG_COLLECTING);
354 if (MATCH_KEY(KEY_UNIDENTIFIED)) ADD_FLG_ADJ(FLG_UNIDENTIFIED);
355 if (MATCH_KEY(KEY_IDENTIFIED)) ADD_FLG_ADJ(FLG_IDENTIFIED);
356 if (MATCH_KEY(KEY_STAR_IDENTIFIED)) ADD_FLG_ADJ(FLG_STAR_IDENTIFIED);
357 if (MATCH_KEY(KEY_BOOSTED)) ADD_FLG_ADJ(FLG_BOOSTED);
359 /*** Weapons whose dd*ds is more than nn ***/
360 if (MATCH_KEY(KEY_MORE_THAN))
365 /* Drop leading spaces */
366 while (' ' == *ptr) ptr++;
369 while (isdigit(*ptr))
371 entry->dice = 10 * entry->dice + (*ptr - '0');
378 (void)MATCH_KEY(KEY_DICE);
379 ADD_FLG_ADJ(FLG_MORE_THAN);
385 /*** Items whose magical bonus is more than n ***/
386 if (MATCH_KEY(KEY_MORE_BONUS))
391 /* Drop leading spaces */
392 while (' ' == *ptr) ptr++;
395 while (isdigit(*ptr))
397 entry->bonus = 10 * entry->bonus + (*ptr - '0');
404 (void)MATCH_KEY(KEY_MORE_BONUS2);
405 ADD_FLG_ADJ(FLG_MORE_BONUS);
411 if (MATCH_KEY(KEY_WORTHLESS)) ADD_FLG_ADJ(FLG_WORTHLESS);
412 if (MATCH_KEY(KEY_ARTIFACT)) ADD_FLG_NOUN(FLG_ARTIFACT);
413 if (MATCH_KEY(KEY_EGO)) ADD_FLG_ADJ(FLG_EGO);
414 if (MATCH_KEY(KEY_NAMELESS)) ADD_FLG_ADJ(FLG_NAMELESS);
415 if (MATCH_KEY(KEY_UNAWARE)) ADD_FLG_ADJ(FLG_UNAWARE);
416 if (MATCH_KEY(KEY_WANTED)) ADD_FLG_ADJ(FLG_WANTED);
417 if (MATCH_KEY(KEY_UNIQUE)) ADD_FLG_ADJ(FLG_UNIQUE);
418 if (MATCH_KEY(KEY_HUMAN)) ADD_FLG_ADJ(FLG_HUMAN);
419 if (MATCH_KEY(KEY_UNREADABLE)) ADD_FLG_ADJ(FLG_UNREADABLE);
420 if (MATCH_KEY(KEY_REALM1)) ADD_FLG_ADJ(FLG_REALM1);
421 if (MATCH_KEY(KEY_REALM2)) ADD_FLG_ADJ(FLG_REALM2);
422 if (MATCH_KEY(KEY_FIRST)) ADD_FLG_ADJ(FLG_FIRST);
423 if (MATCH_KEY(KEY_SECOND)) ADD_FLG_ADJ(FLG_SECOND);
424 if (MATCH_KEY(KEY_THIRD)) ADD_FLG_ADJ(FLG_THIRD);
425 if (MATCH_KEY(KEY_FOURTH)) ADD_FLG_ADJ(FLG_FOURTH);
427 if (MATCH_KEY(KEY_ITEMS)) ADD_FLG_NOUN(FLG_ITEMS);
428 else if (MATCH_KEY(KEY_WEAPONS)) ADD_FLG_NOUN(FLG_WEAPONS);
429 else if (MATCH_KEY(KEY_ARMORS)) ADD_FLG_NOUN(FLG_ARMORS);
430 else if (MATCH_KEY(KEY_MISSILES)) ADD_FLG_NOUN(FLG_MISSILES);
431 else if (MATCH_KEY(KEY_DEVICES)) ADD_FLG_NOUN(FLG_DEVICES);
432 else if (MATCH_KEY(KEY_LIGHTS)) ADD_FLG_NOUN(FLG_LIGHTS);
433 else if (MATCH_KEY(KEY_JUNKS)) ADD_FLG_NOUN(FLG_JUNKS);
434 else if (MATCH_KEY(KEY_SPELLBOOKS)) ADD_FLG_NOUN(FLG_SPELLBOOKS);
435 else if (MATCH_KEY(KEY_HAFTED)) ADD_FLG_NOUN(FLG_HAFTED);
436 else if (MATCH_KEY(KEY_SHIELDS)) ADD_FLG_NOUN(FLG_SHIELDS);
437 else if (MATCH_KEY(KEY_BOWS)) ADD_FLG_NOUN(FLG_BOWS);
438 else if (MATCH_KEY(KEY_RINGS)) ADD_FLG_NOUN(FLG_RINGS);
439 else if (MATCH_KEY(KEY_AMULETS)) ADD_FLG_NOUN(FLG_AMULETS);
440 else if (MATCH_KEY(KEY_SUITS)) ADD_FLG_NOUN(FLG_SUITS);
441 else if (MATCH_KEY(KEY_CLOAKS)) ADD_FLG_NOUN(FLG_CLOAKS);
442 else if (MATCH_KEY(KEY_HELMS)) ADD_FLG_NOUN(FLG_HELMS);
443 else if (MATCH_KEY(KEY_GLOVES)) ADD_FLG_NOUN(FLG_GLOVES);
444 else if (MATCH_KEY(KEY_BOOTS)) ADD_FLG_NOUN(FLG_BOOTS);
446 /* Last 'keyword' must be at the correct location */
450 else if (ptr[0] == kanji_colon[0] && ptr[1] == kanji_colon[1])
453 else if (*ptr == '\0')
454 ; /* nothing to do */
460 /* A noun type keyword didn't end correctly */
461 entry->flag[prev_flg/32] &= ~(1L<< (prev_flg%32));
466 /* Save this auto-picker entry line */
467 entry->name = string_make(ptr);
469 entry->insc = string_make(insc);
475 * A function to delete entry
477 void autopick_free_entry(autopick_type *entry)
479 string_free(entry->name);
480 string_free(entry->insc);
484 * A function for Auto-picker/destroyer
485 * Examine whether the object matches to the list of keywords or not.
487 int is_autopick(object_type *o_ptr)
490 char o_name[MAX_NLEN];
492 if (o_ptr->tval == TV_GOLD) return -1;
494 object_desc(o_name, o_ptr, FALSE, 3);
496 /* Force to be lower case string */
497 for (i = 0; o_name[i]; i++)
500 if (iskanji(o_name[i]))
504 if (isupper(o_name[i]))
505 o_name[i] = tolower(o_name[i]);
508 for (i=0; i < max_autopick; i++)
510 autopick_type *entry = &autopick_list[i];
512 cptr ptr = autopick_list[i].name;
514 /*** Unidentified ***/
515 if (IS_FLG(FLG_UNIDENTIFIED)
516 && (object_known_p(o_ptr) || (o_ptr->ident & IDENT_SENSE)))
520 if (IS_FLG(FLG_IDENTIFIED) && !object_known_p(o_ptr))
523 /*** *Identified* ***/
524 if (IS_FLG(FLG_STAR_IDENTIFIED) &&
525 (!object_known_p(o_ptr) || !(o_ptr->ident & IDENT_MENTAL)))
528 /*** Dice boosted (weapon of slaying) ***/
529 if (IS_FLG(FLG_BOOSTED))
531 object_kind *k_ptr = &k_info[o_ptr->k_idx];
533 switch( o_ptr->tval )
539 if ((o_ptr->dd != k_ptr->dd) || (o_ptr->ds != k_ptr->ds))
548 /*** Weapons whic dd*ds is more than nn ***/
549 if (IS_FLG(FLG_MORE_THAN))
551 if (o_ptr->dd * o_ptr->ds < entry->dice)
555 /*** Weapons whic dd*ds is more than nn ***/
556 if (IS_FLG(FLG_MORE_BONUS))
558 if (!object_known_p(o_ptr)) continue;
560 if (k_info[o_ptr->k_idx].pval ||
561 (o_ptr->name2 && e_info[o_ptr->name2].max_pval))
563 if (o_ptr->pval < entry->bonus) continue;
567 if (o_ptr->to_h < entry->bonus &&
568 o_ptr->to_d < entry->bonus &&
569 o_ptr->to_a < entry->bonus &&
570 o_ptr->pval < entry->bonus)
575 /*** Worthless items ***/
576 if (IS_FLG(FLG_WORTHLESS) && object_value(o_ptr) > 0)
579 /*** Artifact object ***/
580 if (IS_FLG(FLG_ARTIFACT))
582 if (!object_known_p(o_ptr) || (!o_ptr->name1 && !o_ptr->art_name))
589 if (!object_known_p(o_ptr) || !o_ptr->name2)
594 if (IS_FLG(FLG_NAMELESS))
599 case TV_SHOT: case TV_ARROW: case TV_BOLT: case TV_BOW:
600 case TV_DIGGING: case TV_HAFTED: case TV_POLEARM: case TV_SWORD:
601 case TV_BOOTS: case TV_GLOVES: case TV_HELM: case TV_CROWN:
602 case TV_SHIELD: case TV_CLOAK:
603 case TV_SOFT_ARMOR: case TV_HARD_ARMOR: case TV_DRAG_ARMOR:
604 case TV_LITE: case TV_AMULET: case TV_RING: case TV_CARD:
605 if ((!object_known_p(o_ptr) || o_ptr->inscription
606 || o_ptr->name1 || o_ptr->name2 || o_ptr->art_name))
615 /*** Unaware items ***/
616 if (IS_FLG(FLG_UNAWARE) && object_aware_p(o_ptr))
619 /*** Wanted monster's corpse/skeletons ***/
620 if (IS_FLG(FLG_WANTED) &&
621 (o_ptr->tval != TV_CORPSE || !object_is_shoukinkubi(o_ptr)))
624 /*** Unique monster's corpse/skeletons/statues ***/
625 if (IS_FLG(FLG_UNIQUE) &&
626 ((o_ptr->tval != TV_CORPSE && o_ptr->tval != TV_STATUE) ||
627 !(r_info[o_ptr->pval].flags1 & RF1_UNIQUE)))
630 /*** Human corpse/skeletons (for Daemon magic) ***/
631 if (IS_FLG(FLG_HUMAN) &&
632 (o_ptr->tval != TV_CORPSE ||
633 !strchr("pht", r_info[o_ptr->pval].d_char)))
636 /*** Unreadable spellbooks ***/
637 if (IS_FLG(FLG_UNREADABLE) &&
638 (o_ptr->tval < TV_LIFE_BOOK ||
639 check_book_realm(o_ptr->tval, o_ptr->sval)))
642 /*** First realm spellbooks ***/
643 if (IS_FLG(FLG_REALM1) &&
644 (REALM1_BOOK != o_ptr->tval ||
645 p_ptr->pclass == CLASS_SORCERER ||
646 p_ptr->pclass == CLASS_RED_MAGE))
649 /*** Second realm spellbooks ***/
650 if (IS_FLG(FLG_REALM2) &&
651 (REALM2_BOOK != o_ptr->tval ||
652 p_ptr->pclass == CLASS_SORCERER ||
653 p_ptr->pclass == CLASS_RED_MAGE))
656 /*** First rank spellbooks ***/
657 if (IS_FLG(FLG_FIRST) &&
658 (o_ptr->tval < TV_LIFE_BOOK || 0 != o_ptr->sval))
661 /*** Second rank spellbooks ***/
662 if (IS_FLG(FLG_SECOND) &&
663 (o_ptr->tval < TV_LIFE_BOOK || 1 != o_ptr->sval))
666 /*** Third rank spellbooks ***/
667 if (IS_FLG(FLG_THIRD) &&
668 (o_ptr->tval < TV_LIFE_BOOK || 2 != o_ptr->sval))
671 /*** Fourth rank spellbooks ***/
672 if (IS_FLG(FLG_FOURTH) &&
673 (o_ptr->tval < TV_LIFE_BOOK || 3 != o_ptr->sval))
677 if (IS_FLG(FLG_WEAPONS))
681 case TV_BOW: case TV_HAFTED: case TV_POLEARM:
682 case TV_SWORD: case TV_DIGGING:
687 else if (IS_FLG(FLG_ARMORS))
691 case TV_BOOTS: case TV_GLOVES: case TV_CLOAK: case TV_CROWN:
692 case TV_HELM: case TV_SHIELD: case TV_SOFT_ARMOR:
693 case TV_HARD_ARMOR: case TV_DRAG_ARMOR:
698 else if (IS_FLG(FLG_MISSILES))
702 case TV_SHOT: case TV_BOLT: case TV_ARROW:
707 else if (IS_FLG(FLG_DEVICES))
711 case TV_SCROLL: case TV_STAFF: case TV_WAND: case TV_ROD:
716 else if (IS_FLG(FLG_LIGHTS))
718 if (!(o_ptr->tval == TV_LITE))
721 else if (IS_FLG(FLG_JUNKS))
725 case TV_SKELETON: case TV_BOTTLE:
726 case TV_JUNK: case TV_STATUE:
731 else if (IS_FLG(FLG_SPELLBOOKS))
733 if (!(o_ptr->tval >= TV_LIFE_BOOK))
736 else if (IS_FLG(FLG_HAFTED))
738 if (!(o_ptr->tval == TV_HAFTED))
741 else if (IS_FLG(FLG_SHIELDS))
743 if (!(o_ptr->tval == TV_SHIELD))
746 else if (IS_FLG(FLG_BOWS))
748 if (!(o_ptr->tval == TV_BOW))
751 else if (IS_FLG(FLG_RINGS))
753 if (!(o_ptr->tval == TV_RING))
756 else if (IS_FLG(FLG_AMULETS))
758 if (!(o_ptr->tval == TV_AMULET))
761 else if (IS_FLG(FLG_SUITS))
763 if (!(o_ptr->tval == TV_DRAG_ARMOR ||
764 o_ptr->tval == TV_HARD_ARMOR ||
765 o_ptr->tval == TV_SOFT_ARMOR))
768 else if (IS_FLG(FLG_CLOAKS))
770 if (!(o_ptr->tval == TV_CLOAK))
773 else if (IS_FLG(FLG_HELMS))
775 if (!(o_ptr->tval == TV_CROWN || o_ptr->tval == TV_HELM))
778 else if (IS_FLG(FLG_GLOVES))
780 if (!(o_ptr->tval == TV_GLOVES))
783 else if (IS_FLG(FLG_BOOTS))
785 if (!(o_ptr->tval == TV_BOOTS))
793 if (!strncmp(o_name, ptr, strlen(ptr)))
798 if (strstr_j(o_name, ptr))
800 if (strstr(o_name, ptr))
809 if (!IS_FLG(FLG_COLLECTING))
811 /* Check if there is a same item */
812 for (j = 0; j < INVEN_PACK; j++)
815 * 'Collecting' means the item must be absorbed
816 * into an inventory slot.
817 * But an item can not be absorbed into itself!
819 if ((&inventory[j] != o_ptr) &&
820 object_similar(&inventory[j], o_ptr))
831 * Automatically destroy items in this grid.
833 static bool is_opt_confirm_destroy(object_type *o_ptr)
835 if (!destroy_items) return FALSE;
837 /* Known to be worthless? */
839 if (object_value(o_ptr) > 0) return FALSE;
842 if ((o_ptr->tval >= TV_SHOT) && (o_ptr->tval <= TV_DRAG_ARMOR)) return FALSE;
845 if ((o_ptr->tval == TV_CHEST) && o_ptr->pval) return FALSE;
849 if (o_ptr->tval == TV_CORPSE
850 && object_is_shoukinkubi(o_ptr)) return FALSE;
854 if (o_ptr->tval == TV_CORPSE) return FALSE;
857 if ((o_ptr->tval == TV_SKELETON) || (o_ptr->tval == TV_BOTTLE) || (o_ptr->tval == TV_JUNK) || (o_ptr->tval == TV_STATUE)) return FALSE;
859 if (o_ptr->tval == TV_GOLD) return FALSE;
868 void auto_inscribe_item(int item, int idx)
872 /* Get the item (in the pack) */
873 if (item >= 0) o_ptr = &inventory[item];
875 /* Get the item (on the floor) */
876 else o_ptr = &o_list[0 - item];
878 /* Auto-inscription or Re-inscribe for resistances {%} */
879 if ((idx < 0 || !autopick_list[idx].insc) && !o_ptr->inscription)
882 if (o_ptr->inscription)
883 o_ptr->inscription = inscribe_flags(o_ptr, quark_str(o_ptr->inscription));
885 o_ptr->inscription = inscribe_flags(o_ptr, autopick_list[idx].insc);
887 if (item > INVEN_PACK)
889 /* Redraw inscription */
890 p_ptr->window |= (PW_EQUIP);
892 /* {.} and {$} effect p_ptr->warning and TRC_TELEPORT_SELF */
893 p_ptr->update |= (PU_BONUS);
897 /* Redraw inscription */
898 p_ptr->window |= (PW_INVEN);
904 * Automatically destroy an item if it is to be destroyed
906 bool auto_destroy_item(int item, int autopick_idx, bool wait_optimize)
908 bool destroy = FALSE;
909 char o_name[MAX_NLEN];
912 /* Don't destroy equipped items */
913 if (item > INVEN_PACK) return FALSE;
915 /* Get the item (in the pack) */
916 if (item >= 0) o_ptr = &inventory[item];
918 /* Get the item (on the floor) */
919 else o_ptr = &o_list[0 - item];
921 /* Easy-Auto-Destroyer */
922 if (is_opt_confirm_destroy(o_ptr)) destroy = TRUE;
924 /* Protected by auto-picker */
925 if (autopick_idx >= 0 &&
926 !(autopick_list[autopick_idx].action & DO_AUTODESTROY))
931 /* Auto-picker/destroyer */
932 if (autopick_idx >= 0 &&
933 (autopick_list[autopick_idx].action & DO_AUTODESTROY))
937 /* Not to be destroyed */
938 if (!destroy) return FALSE;
940 /* Now decided to destroy */
944 /* Describe the object (with {terrible/special}) */
945 object_desc(o_name, o_ptr, TRUE, 3);
948 if (!can_player_destroy_object(o_ptr))
952 msg_format("%s¤ÏÇ˲õÉÔǽ¤À¡£", o_name);
954 msg_format("You cannot auto-destroy %s.", o_name);
961 /* Record name of destroyed item */
962 autopick_free_entry(&autopick_entry_last_destroyed);
963 autopick_entry_from_object(&autopick_entry_last_destroyed, o_ptr);
965 /* Eliminate the item (from the pack) */
968 inven_item_increase(item, -(o_ptr->number));
971 * always optimize equipment.
972 * optimize inventry only when wait_optimize is FALSE.
974 if (!wait_optimize || item > INVEN_PACK)
975 inven_item_optimize(item);
978 /* Eliminate the item (from the floor) */
981 delete_object_idx(0 - item);
984 /* Print a message */
986 msg_format("%s¤ò¼«Æ°Ç˲õ¤·¤Þ¤¹¡£", o_name);
988 msg_format("Auto-destroying %s.", o_name);
996 * Optimize all inventry items after consumption of staves or scrolls.
998 void optimize_inventry_auto_destroy(void)
1002 for (i = 0; i <= INVEN_PACK; i++)
1003 inven_item_optimize(i);
1008 * Automatically pickup/destroy items in this grid.
1010 void auto_pickup_items(cave_type *c_ptr)
1012 s16b this_o_idx, next_o_idx = 0;
1014 /* Scan the pile of objects */
1015 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1019 /* Acquire object */
1020 object_type *o_ptr = &o_list[this_o_idx];
1022 /* Acquire next object */
1023 next_o_idx = o_ptr->next_o_idx;
1025 idx = is_autopick(o_ptr);
1027 /* Item index for floor -1,-2,-3,... */
1028 auto_inscribe_item((-this_o_idx), idx);
1030 if (idx >= 0 && (autopick_list[idx].action & DO_AUTOPICK))
1034 if (!inven_carry_okay(o_ptr))
1036 char o_name[MAX_NLEN];
1038 /* Describe the object */
1039 object_desc(o_name, o_ptr, TRUE, 3);
1043 msg_format("¥¶¥Ã¥¯¤Ë¤Ï%s¤òÆþ¤ì¤ë·ä´Ö¤¬¤Ê¤¤¡£", o_name);
1045 msg_format("You have no room for %s.", o_name);
1049 py_pickup_aux(this_o_idx);
1056 * When always_pickup is 'yes', we disable
1057 * auto-destroyer from autopick function, and do only
1058 * easy-auto-destroyer.
1062 if (auto_destroy_item((-this_o_idx), idx, FALSE))
1070 * Describe which kind of object is Auto-picked/destroyed
1072 static void describe_autopick(char *buff, autopick_type *entry)
1074 cptr str = entry->name;
1075 byte act = entry->action;
1076 cptr insc = entry->insc;
1082 cptr before_str[100], body_str;
1085 body_str = "¥¢¥¤¥Æ¥à";
1087 /*** Collecting items ***/
1088 /*** Which can be absorbed into a slot as a bundle ***/
1089 if (IS_FLG(FLG_COLLECTING))
1090 before_str[before_n++] = "¼ý½¸Ãæ¤Ç´û¤Ë»ý¤Ã¤Æ¤¤¤ë¥¹¥í¥Ã¥È¤Ë¤Þ¤È¤á¤é¤ì¤ë";
1092 /*** Unidentified ***/
1093 if (IS_FLG(FLG_UNIDENTIFIED))
1094 before_str[before_n++] = "̤´ÕÄê¤Î";
1096 /*** Identified ***/
1097 if (IS_FLG(FLG_IDENTIFIED))
1098 before_str[before_n++] = "´ÕÄêºÑ¤ß¤Î";
1100 /*** *Identified* ***/
1101 if (IS_FLG(FLG_STAR_IDENTIFIED))
1102 before_str[before_n++] = "´°Á´¤Ë´ÕÄêºÑ¤ß¤Î";
1104 /*** Dice boosted (weapon of slaying) ***/
1105 if (IS_FLG(FLG_BOOSTED))
1107 before_str[before_n++] = "¥À¥á¡¼¥¸¥À¥¤¥¹¤¬Ä̾ï¤è¤êÂ礤¤";
1111 /*** Weapons whose dd*ds is more than nn ***/
1112 if (IS_FLG(FLG_MORE_THAN))
1114 static char more_than_desc_str[] = "___";
1115 before_str[before_n++] = "¥À¥á¡¼¥¸¥À¥¤¥¹¤ÎºÇÂçÃͤ¬";
1118 sprintf(more_than_desc_str,"%d", entry->dice);
1119 before_str[before_n++] = more_than_desc_str;
1120 before_str[before_n++] = "°Ê¾å¤Î";
1123 /*** Items whose magical bonus is more than nn ***/
1124 if (IS_FLG(FLG_MORE_BONUS))
1126 static char more_bonus_desc_str[] = "___";
1127 before_str[before_n++] = "½¤ÀµÃͤ¬(+";
1129 sprintf(more_bonus_desc_str,"%d", entry->bonus);
1130 before_str[before_n++] = more_bonus_desc_str;
1131 before_str[before_n++] = ")°Ê¾å¤Î";
1134 /*** Worthless items ***/
1135 if (IS_FLG(FLG_WORTHLESS))
1136 before_str[before_n++] = "Ź¤Ç̵²ÁÃͤÈȽÄꤵ¤ì¤ë";
1139 if (IS_FLG(FLG_ARTIFACT))
1141 before_str[before_n++] = "¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È¤Î";
1146 if (IS_FLG(FLG_EGO))
1148 before_str[before_n++] = "¥¨¥´¥¢¥¤¥Æ¥à¤Î";
1153 if (IS_FLG(FLG_NAMELESS))
1155 before_str[before_n++] = "¥¨¥´¤Ç¤â¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È¤Ç¤â¤Ê¤¤";
1159 /*** Unaware items ***/
1160 if (IS_FLG(FLG_UNAWARE))
1161 before_str[before_n++] = "̤´ÕÄê¤Ç¤½¤Î¸ú²Ì¤âȽÌÀ¤·¤Æ¤¤¤Ê¤¤";
1163 /*** Wanted monster's corpse/skeletons ***/
1164 if (IS_FLG(FLG_WANTED))
1166 before_str[before_n++] = "¥Ï¥ó¥¿¡¼»ö̳½ê¤Ç¾Þ¶â¼ó¤È¤µ¤ì¤Æ¤¤¤ë";
1167 body_str = "»àÂΤä¹ü";
1170 /*** Human corpse/skeletons (for Daemon magic) ***/
1171 if (IS_FLG(FLG_HUMAN))
1173 before_str[before_n++] = "°ËâËâË¡¤Ç»È¤¦¤¿¤á¤Î¿Í´Ö¤ä¥Ò¥å¡¼¥Þ¥Î¥¤¥É¤Î";
1174 body_str = "»àÂΤä¹ü";
1177 /*** Unique monster's corpse/skeletons/statues ***/
1178 if (IS_FLG(FLG_UNIQUE))
1180 before_str[before_n++] = "¥æ¥Ë¡¼¥¯¥â¥ó¥¹¥¿¡¼¤Î";
1181 body_str = "»àÂΤä¹ü";
1184 /*** Unreadable spellbooks ***/
1185 if (IS_FLG(FLG_UNREADABLE))
1187 before_str[before_n++] = "¤¢¤Ê¤¿¤¬Æɤá¤Ê¤¤Îΰè¤Î";
1188 body_str = "ËâË¡½ñ";
1191 /*** First realm spellbooks ***/
1192 if (IS_FLG(FLG_REALM1))
1194 before_str[before_n++] = "Âè°ìÎΰè¤Î";
1195 body_str = "ËâË¡½ñ";
1198 /*** Second realm spellbooks ***/
1199 if (IS_FLG(FLG_REALM2))
1201 before_str[before_n++] = "ÂèÆóÎΰè¤Î";
1202 body_str = "ËâË¡½ñ";
1205 /*** First rank spellbooks ***/
1206 if (IS_FLG(FLG_FIRST))
1208 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î1ºýÌܤÎ";
1209 body_str = "ËâË¡½ñ";
1212 /*** Second rank spellbooks ***/
1213 if (IS_FLG(FLG_SECOND))
1215 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î2ºýÌܤÎ";
1216 body_str = "ËâË¡½ñ";
1219 /*** Third rank spellbooks ***/
1220 if (IS_FLG(FLG_THIRD))
1222 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î3ºýÌܤÎ";
1223 body_str = "ËâË¡½ñ";
1226 /*** Fourth rank spellbooks ***/
1227 if (IS_FLG(FLG_FOURTH))
1229 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î4ºýÌܤÎ";
1230 body_str = "ËâË¡½ñ";
1234 if (IS_FLG(FLG_ITEMS))
1235 ; /* Nothing to do */
1236 else if (IS_FLG(FLG_WEAPONS))
1238 else if (IS_FLG(FLG_ARMORS))
1240 else if (IS_FLG(FLG_MISSILES))
1241 body_str = "ÃƤäÌð¤ä¥¯¥í¥¹¥Ü¥¦¤ÎÌð";
1242 else if (IS_FLG(FLG_DEVICES))
1243 body_str = "´¬Êª¤äËâË¡ËÀ¤ä¾ó¤ä¥í¥Ã¥É";
1244 else if (IS_FLG(FLG_LIGHTS))
1245 body_str = "¸÷¸»ÍѤΥ¢¥¤¥Æ¥à";
1246 else if (IS_FLG(FLG_JUNKS))
1247 body_str = "Àޤ줿ËÀÅù¤Î¥¬¥é¥¯¥¿";
1248 else if (IS_FLG(FLG_SPELLBOOKS))
1249 body_str = "ËâË¡½ñ";
1250 else if (IS_FLG(FLG_HAFTED))
1252 else if (IS_FLG(FLG_SHIELDS))
1254 else if (IS_FLG(FLG_BOWS))
1255 body_str = "¥¹¥ê¥ó¥°¤äµÝ¤ä¥¯¥í¥¹¥Ü¥¦";
1256 else if (IS_FLG(FLG_RINGS))
1258 else if (IS_FLG(FLG_AMULETS))
1259 body_str = "¥¢¥ß¥å¥ì¥Ã¥È";
1260 else if (IS_FLG(FLG_SUITS))
1262 else if (IS_FLG(FLG_CLOAKS))
1263 body_str = "¥¯¥í¡¼¥¯";
1264 else if (IS_FLG(FLG_HELMS))
1265 body_str = "¥Ø¥ë¥á¥Ã¥È¤ä´§";
1266 else if (IS_FLG(FLG_GLOVES))
1268 else if (IS_FLG(FLG_BOOTS))
1269 body_str = "¥Ö¡¼¥Ä";
1273 strcat(buff, "Á´¤Æ¤Î");
1274 else for (i = 0; i < before_n && before_str[i]; i++)
1275 strcat(buff, before_str[i]);
1277 strcat(buff, body_str);
1287 strcat(buff, "¤Ç¡¢Ì¾Á°¤¬¡Ö");
1288 strncat(buff, str, 80);
1290 strcat(buff, "¡×¤Ç»Ï¤Þ¤ë¤â¤Î");
1292 strcat(buff, "¡×¤ò´Þ¤à¤â¤Î");
1296 strncat(buff, format("¤Ë¡Ö%s¡×¤È¹ï¤ó¤Ç", insc), 80);
1300 if (act & DONT_AUTOPICK)
1301 strcat(buff, "ÊüÃÖ¤¹¤ë¡£");
1302 else if (act & DO_AUTODESTROY)
1303 strcat(buff, "Ç˲õ¤¹¤ë¡£");
1305 strcat(buff, "½¦¤¦¡£");
1307 if (act & DO_DISPLAY)
1309 if (act & DONT_AUTOPICK)
1310 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'N'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
1311 else if (act & DO_AUTODESTROY)
1312 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'K'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
1314 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'M'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
1317 strcat(buff, "Á´ÂΥޥåפˤÏɽ¼¨¤·¤Ê¤¤");
1321 cptr before_str[20], after_str[20], which_str[20], whose_str[20], body_str;
1322 int before_n = 0, after_n = 0, which_n = 0, whose_n = 0;
1326 /*** Collecting items ***/
1327 /*** Which can be absorbed into a slot as a bundle ***/
1328 if (IS_FLG(FLG_COLLECTING))
1329 which_str[which_n++] = "can be absorbed into an existing inventory slot";
1331 /*** Unidentified ***/
1332 if (IS_FLG(FLG_UNIDENTIFIED))
1333 before_str[before_n++] = "unidentified";
1335 /*** Identified ***/
1336 if (IS_FLG(FLG_IDENTIFIED))
1337 before_str[before_n++] = "identified";
1339 /*** *Identified* ***/
1340 if (IS_FLG(FLG_STAR_IDENTIFIED))
1341 before_str[before_n++] = "fully identified";
1343 /*** Worthless items ***/
1344 if (IS_FLG(FLG_WORTHLESS))
1346 before_str[before_n++] = "worthless";
1347 which_str[which_n++] = "can not be sold at stores";
1351 if (IS_FLG(FLG_ARTIFACT))
1353 before_str[before_n++] = "artifact";
1357 if (IS_FLG(FLG_EGO))
1359 before_str[before_n++] = "ego";
1363 if (IS_FLG(FLG_NAMELESS))
1365 body_str = "equipment";
1366 which_str[which_n++] = "is neither ego-item nor artifact";
1369 /*** Unaware items ***/
1370 if (IS_FLG(FLG_UNAWARE))
1372 before_str[before_n++] = "unidentified";
1373 whose_str[whose_n++] = "basic abilities are not known";
1376 /*** Dice boosted (weapon of slaying) ***/
1377 if (IS_FLG(FLG_BOOSTED))
1379 body_str = "weapons";
1380 whose_str[whose_n++] = "damage dice is bigger than normal";
1383 /*** Weapons whose dd*ds is more than nn ***/
1384 if (IS_FLG(FLG_MORE_THAN))
1386 static char more_than_desc_str[] =
1387 "maximum damage from dice is bigger than __";
1388 body_str = "weapons";
1390 sprintf(more_than_desc_str + sizeof(more_than_desc_str) - 3,
1392 whose_str[whose_n++] = more_than_desc_str;
1395 /*** Items whose magical bonus is more than nn ***/
1396 if (IS_FLG(FLG_MORE_BONUS))
1398 static char more_bonus_desc_str[] =
1399 "magical bonus is bigger than (+__)";
1401 sprintf(more_bonus_desc_str + sizeof(more_bonus_desc_str) - 4,
1402 "%d)", entry->bonus);
1403 whose_str[whose_n++] = more_bonus_desc_str;
1406 /*** Wanted monster's corpse/skeletons ***/
1407 if (IS_FLG(FLG_WANTED))
1409 body_str = "corpse or skeletons";
1410 which_str[which_n++] = "is wanted at the Hunter's Office";
1413 /*** Human corpse/skeletons (for Daemon magic) ***/
1414 if (IS_FLG(FLG_HUMAN))
1416 before_str[before_n++] = "humanoid";
1417 body_str = "corpse or skeletons";
1418 which_str[which_n++] = "can be used for Daemon magic";
1421 /*** Unique monster's corpse/skeletons/statues ***/
1422 if (IS_FLG(FLG_UNIQUE))
1424 before_str[before_n++] = "unique monster's";
1425 body_str = "corpse or skeletons";
1428 /*** Unreadable spellbooks ***/
1429 if (IS_FLG(FLG_UNREADABLE))
1431 body_str = "spellbooks";
1432 after_str[after_n++] = "of different realms from yours";
1435 /*** First realm spellbooks ***/
1436 if (IS_FLG(FLG_REALM1))
1438 body_str = "spellbooks";
1439 after_str[after_n++] = "of your first realm";
1442 /*** Second realm spellbooks ***/
1443 if (IS_FLG(FLG_REALM2))
1445 body_str = "spellbooks";
1446 after_str[after_n++] = "of your second realm";
1449 /*** First rank spellbooks ***/
1450 if (IS_FLG(FLG_FIRST))
1452 before_str[before_n++] = "first one of four";
1453 body_str = "spellbooks";
1456 /*** Second rank spellbooks ***/
1457 if (IS_FLG(FLG_SECOND))
1459 before_str[before_n++] = "second one of four";
1460 body_str = "spellbooks";
1463 /*** Third rank spellbooks ***/
1464 if (IS_FLG(FLG_THIRD))
1466 before_str[before_n++] = "third one of four";
1467 body_str = "spellbooks";
1470 /*** Fourth rank spellbooks ***/
1471 if (IS_FLG(FLG_FOURTH))
1473 before_str[before_n++] = "fourth one of four";
1474 body_str = "spellbooks";
1478 if (IS_FLG(FLG_ITEMS))
1479 ; /* Nothing to do */
1480 else if (IS_FLG(FLG_WEAPONS))
1481 body_str = "weapons";
1482 else if (IS_FLG(FLG_ARMORS))
1483 body_str = "armors";
1484 else if (IS_FLG(FLG_MISSILES))
1485 body_str = "shots, arrows or crossbow bolts";
1486 else if (IS_FLG(FLG_DEVICES))
1487 body_str = "scrolls, wands, staves or rods";
1488 else if (IS_FLG(FLG_LIGHTS))
1489 body_str = "light sources";
1490 else if (IS_FLG(FLG_JUNKS))
1491 body_str = "junk such as broken sticks";
1492 else if (IS_FLG(FLG_SPELLBOOKS))
1493 body_str = "spellbooks";
1494 else if (IS_FLG(FLG_HAFTED))
1495 body_str = "hafted weapons";
1496 else if (IS_FLG(FLG_SHIELDS))
1497 body_str = "shields";
1498 else if (IS_FLG(FLG_BOWS))
1499 body_str = "slings, bows or crossbows";
1500 else if (IS_FLG(FLG_RINGS))
1502 else if (IS_FLG(FLG_AMULETS))
1503 body_str = "amulets";
1504 else if (IS_FLG(FLG_SUITS))
1505 body_str = "body armors";
1506 else if (IS_FLG(FLG_CLOAKS))
1507 body_str = "cloaks";
1508 else if (IS_FLG(FLG_HELMS))
1509 body_str = "helms or crowns";
1510 else if (IS_FLG(FLG_GLOVES))
1511 body_str = "gloves";
1512 else if (IS_FLG(FLG_BOOTS))
1515 /* Prepare a string for item name */
1522 whose_str[whose_n++] = "name is beginning with \"";
1525 which_str[which_n++] = "have \"";
1529 /* Describe action flag */
1530 if (act & DONT_AUTOPICK)
1531 strcpy(buff, "Leave on floor ");
1532 else if (act & DO_AUTODESTROY)
1533 strcpy(buff, "Destroy ");
1535 strcpy(buff, "Pickup ");
1537 /* Auto-insctiption */
1539 strncat(buff, format("and inscribe \"%s\" on ", insc), 80);
1543 strcat(buff, "all ");
1544 else for (i = 0; i < before_n && before_str[i]; i++)
1546 strcat(buff, before_str[i]);
1551 strcat(buff, body_str);
1554 for (i = 0; i < after_n && after_str[i]; i++)
1557 strcat(buff, after_str[i]);
1561 for (i = 0; i < whose_n && whose_str[i]; i++)
1564 strcat(buff, " whose ");
1566 strcat(buff, ", and ");
1568 strcat(buff, whose_str[i]);
1571 /* Item name ; whose name is beginning with "str" */
1578 /* whose ..., and which .... */
1579 if (whose_n && which_n)
1580 strcat(buff, ", and ");
1583 for (i = 0; i < which_n && which_str[i]; i++)
1586 strcat(buff, " which ");
1588 strcat(buff, ", and ");
1590 strcat(buff, which_str[i]);
1593 /* Item name ; which have "str" as part of its name */
1596 strncat(buff, str, 80);
1597 strcat(buff, "\" as part of its name");
1601 /* Describe whether it will be displayed on the full map or not */
1602 if (act & DO_DISPLAY)
1604 if (act & DONT_AUTOPICK)
1605 strcat(buff, " Display these items when you press 'N' in the full map('M').");
1606 else if (act & DO_AUTODESTROY)
1607 strcat(buff, " Display these items when you press 'K' in the full map('M').");
1609 strcat(buff, " Display these items when you press 'M' in the full map('M').");
1612 strcat(buff, " Not displayed in the full map.");
1618 #define MAX_LINES 3000
1621 * Read whole lines of a file to memory
1623 static cptr *read_text_lines(cptr filename, bool user)
1625 cptr *lines_list = NULL;
1633 /* Hack -- drop permissions */
1635 path_build(buf, 1024, ANGBAND_DIR_USER, filename);
1639 path_build(buf, 1024, ANGBAND_DIR_PREF, filename);
1643 fff = my_fopen(buf, "r");
1647 /* Allocate list of pointers */
1648 C_MAKE(lines_list, MAX_LINES, cptr);
1651 while (0 == my_fgets(fff, buf, 1024))
1653 lines_list[lines++] = string_make(buf);
1654 if (lines >= MAX_LINES - 1) break;
1657 lines_list[0] = string_make("");
1665 if (!fff) return NULL;
1669 static cptr *read_pickpref_text_lines(void)
1675 sprintf(buf, "picktype-%s.prf", player_name);
1677 sprintf(buf, "pickpref-%s.prf", player_name);
1679 lines_list = read_text_lines(buf, TRUE);
1684 lines_list = read_text_lines("picktype.prf", TRUE);
1686 lines_list = read_text_lines("pickpref.prf", TRUE);
1693 lines_list = read_text_lines("picktype.prf", FALSE);
1695 lines_list = read_text_lines("pickpref.prf", FALSE);
1701 /* Allocate list of pointers */
1702 C_MAKE(lines_list, MAX_LINES, cptr);
1703 lines_list[0] = string_make("");
1709 * Write whole lines of memory to a file.
1711 static bool write_text_lines(cptr filename, cptr *lines_list)
1718 /* Hack -- drop permissions */
1721 /* Build the filename */
1722 path_build(buf, 1024, ANGBAND_DIR_USER, filename);
1725 fff = my_fopen(buf, "w");
1728 for (lines = 0; lines_list[lines]; lines++)
1729 my_fputs(fff, lines_list[lines], 1024);
1737 if (!fff) return FALSE;
1743 * Free memory of lines_list.
1745 static void free_text_lines(cptr *lines_list)
1749 for (lines = 0; lines_list[lines]; lines++)
1750 string_free(lines_list[lines]);
1752 /* free list of pointers */
1753 C_FREE((char **)lines_list, MAX_LINES, char *);
1758 * Delete or insert string
1760 static void toggle_string(cptr *lines_list, int flg, int y)
1762 autopick_type an_entry, *entry = &an_entry;
1764 if (!autopick_new_entry(entry, lines_list[y]))
1767 string_free(lines_list[y]);
1773 lines_list[y] = autopick_line_from_entry(entry);
1777 * Insert return code and split the line
1779 static bool insert_return_code(cptr *lines_list, int cx, int cy)
1784 for (k = 0; lines_list[k]; k++)
1785 /* count number of lines */ ;
1787 if (k >= MAX_LINES - 2) return FALSE;
1790 /* Move down lines */
1792 lines_list[k+1] = lines_list[k];
1794 /* Split current line */
1795 for (i = j = 0; lines_list[cy][i] && i < cx; i++)
1798 if (iskanji(lines_list[cy][i]))
1799 buf[j++] = lines_list[cy][i++];
1801 buf[j++] = lines_list[cy][i];
1804 lines_list[cy+1] = string_make(&lines_list[cy][i]);
1805 string_free(lines_list[cy]);
1806 lines_list[cy] = string_make(buf);
1812 * Get auto-picker entry from o_ptr.
1814 void autopick_entry_from_object(autopick_type *entry, object_type *o_ptr)
1816 char o_name[MAX_NLEN];
1817 object_desc(o_name, o_ptr, FALSE, 0);
1819 entry->name = string_make(o_name);
1820 entry->insc = string_make(quark_str(o_ptr->inscription));
1821 entry->action = DO_AUTOPICK | DO_DISPLAY;
1822 entry->flag[0] = entry->flag[1] = 0L;
1825 if (!object_aware_p(o_ptr))
1826 ADD_FLG(FLG_UNAWARE);
1827 if (object_value(o_ptr) <= 0)
1828 ADD_FLG(FLG_WORTHLESS);
1830 if (object_known_p(o_ptr))
1834 else if (o_ptr->name1 || o_ptr->art_name)
1835 ADD_FLG(FLG_ARTIFACT);
1841 case TV_HAFTED: case TV_POLEARM: case TV_SWORD: case TV_DIGGING:
1842 k_ptr = &k_info[o_ptr->k_idx];
1843 if ((o_ptr->dd != k_ptr->dd) || (o_ptr->ds != k_ptr->ds))
1844 ADD_FLG(FLG_BOOSTED);
1847 if (o_ptr->tval == TV_CORPSE && object_is_shoukinkubi(o_ptr))
1849 REM_FLG(FLG_WORTHLESS);
1850 ADD_FLG(FLG_WANTED);
1853 if ((o_ptr->tval == TV_CORPSE || o_ptr->tval == TV_STATUE)
1854 && (r_info[o_ptr->pval].flags1 & RF1_UNIQUE))
1856 REM_FLG(FLG_WORTHLESS);
1857 ADD_FLG(FLG_UNIQUE);
1860 if (o_ptr->tval == TV_CORPSE && strchr("pht", r_info[o_ptr->pval].d_char))
1862 REM_FLG(FLG_WORTHLESS);
1866 if (o_ptr->tval >= TV_LIFE_BOOK &&
1867 !check_book_realm(o_ptr->tval, o_ptr->sval))
1868 ADD_FLG(FLG_UNREADABLE);
1870 if (REALM1_BOOK == o_ptr->tval &&
1871 p_ptr->pclass != CLASS_SORCERER &&
1872 p_ptr->pclass != CLASS_RED_MAGE)
1873 ADD_FLG(FLG_REALM1);
1875 if (REALM2_BOOK == o_ptr->tval &&
1876 p_ptr->pclass != CLASS_SORCERER &&
1877 p_ptr->pclass != CLASS_RED_MAGE)
1878 ADD_FLG(FLG_REALM2);
1880 if (o_ptr->tval >= TV_LIFE_BOOK && 0 == o_ptr->sval)
1882 if (o_ptr->tval >= TV_LIFE_BOOK && 1 == o_ptr->sval)
1883 ADD_FLG(FLG_SECOND);
1884 if (o_ptr->tval >= TV_LIFE_BOOK && 2 == o_ptr->sval)
1886 if (o_ptr->tval >= TV_LIFE_BOOK && 3 == o_ptr->sval)
1887 ADD_FLG(FLG_FOURTH);
1889 if (o_ptr->tval == TV_SHOT || o_ptr->tval == TV_BOLT
1890 || o_ptr->tval == TV_ARROW)
1891 ADD_FLG(FLG_MISSILES);
1892 else if (o_ptr->tval == TV_SCROLL || o_ptr->tval == TV_STAFF
1893 || o_ptr->tval == TV_WAND || o_ptr->tval == TV_ROD)
1894 ADD_FLG(FLG_DEVICES);
1895 else if (o_ptr->tval == TV_LITE)
1896 ADD_FLG(FLG_LIGHTS);
1897 else if (o_ptr->tval == TV_SKELETON || o_ptr->tval == TV_BOTTLE
1898 || o_ptr->tval == TV_JUNK || o_ptr->tval == TV_STATUE)
1900 else if (o_ptr->tval >= TV_LIFE_BOOK)
1901 ADD_FLG(FLG_SPELLBOOKS);
1902 else if (o_ptr->tval == TV_HAFTED)
1903 ADD_FLG(FLG_HAFTED);
1904 else if (o_ptr->tval == TV_POLEARM || o_ptr->tval == TV_SWORD
1905 || o_ptr->tval == TV_DIGGING)
1906 ADD_FLG(FLG_WEAPONS);
1907 else if (o_ptr->tval == TV_SHIELD)
1908 ADD_FLG(FLG_SHIELDS);
1909 else if (o_ptr->tval == TV_BOW)
1911 else if (o_ptr->tval == TV_RING)
1913 else if (o_ptr->tval == TV_AMULET)
1914 ADD_FLG(FLG_AMULETS);
1915 else if (o_ptr->tval == TV_DRAG_ARMOR || o_ptr->tval == TV_HARD_ARMOR ||
1916 o_ptr->tval == TV_SOFT_ARMOR)
1918 else if (o_ptr->tval == TV_CLOAK)
1919 ADD_FLG(FLG_CLOAKS);
1920 else if (o_ptr->tval == TV_HELM)
1922 else if (o_ptr->tval == TV_GLOVES)
1923 ADD_FLG(FLG_GLOVES);
1924 else if (o_ptr->tval == TV_BOOTS)
1931 * Choose an item and get auto-picker entry from it.
1933 static bool entry_from_choosed_object(autopick_type *entry)
1941 q = "¤É¤Î¥¢¥¤¥Æ¥à¤òÅÐÏ¿¤·¤Þ¤¹¤«? ";
1942 s = "¥¢¥¤¥Æ¥à¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£";
1944 q = "Entry which item? ";
1945 s = "You have nothing to entry.";
1947 if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR | USE_EQUIP))) return FALSE;
1949 /* Get the item (in the pack) */
1952 o_ptr = &inventory[item];
1955 /* Get the item (on the floor) */
1958 o_ptr = &o_list[0 - item];
1961 autopick_entry_from_object(entry, o_ptr);
1967 * Initialize auto-picker preference
1969 void init_autopicker(void)
1971 static const char easy_autopick_inscription[] = "(:=g";
1972 autopick_type entry;
1975 /* Clear old entries */
1976 for( i = 0; i < max_autopick; i++)
1977 autopick_free_entry(&autopick_list[i]);
1981 /* There is always one entry "=g" */
1982 autopick_new_entry(&entry, easy_autopick_inscription);
1983 autopick_list[max_autopick++] = entry;
1988 * Description of control commands
1993 static cptr ctrl_command_desc[] =
1996 #define LAST_DESTROYED 6
1997 "^P ^N ^B ^F ¾å²¼º¸±¦¤Ë°ÜÆ°",
1998 "^A ^E ¹Ô¤ÎÀèƬ¡¢½ªÃ¼",
1999 "^Q ÆþÎÏ/¥³¥Þ¥ó¥É¥â¡¼¥ÉÀÚ¤êÂؤ¨",
2000 "^R Êѹ¹¤òÁ´¤Æ¼è¤ê¾Ã¤·¤Æ¸µ¤ËÌ᤹",
2001 "------------------------------------",
2002 "^I »ý¤Áʪ/ÁõÈ÷¤«¤éÁªÂò",
2004 "^K ¥«¡¼¥½¥ë¤«¤é½ªÃ¼¤Þ¤Çºï½ü",
2005 "^Y ºï½ü(^K)¤·¤¿¹Ô¤òÁÞÆþ",
2006 "^C ¼ï²¡¢¿¦¶È¤Î¾ò·ï¼°¤òÁÞÆþ",
2007 "------------------------------------",
2008 "^S Êѹ¹ (!Ç˲õ/~ÊüÃÖ/½¦¤¦)",
2009 "^G \"(\" Á´ÂΥޥåפÇɽ¼¨¤·¤Ê¤¤",
2010 "^O \"#\" ¼«Æ°¹ï¤ß",
2011 "------------------------------------",
2012 "^U ̤´ÕÄê/̤ȽÌÀ/´ÕÄê/*´ÕÄê*",
2014 "^X ̵ÌÃ/¥¨¥´/¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È",
2018 #define LAST_DESTROYED 6
2019 "^P ^N ^B ^F Move Cursor",
2020 "^A ^E Beginning and End of Line",
2021 "^Q Toggle Insert/Command mode",
2022 "^R Revert to Original File",
2023 "------------------------------------",
2024 "^I Object in Inventry/Equipment",
2026 "^K Kill Rest of Line",
2027 "^Y Insert killed(^K) text",
2028 "^C Insert conditional expression",
2029 "------------------------------------",
2030 "^S Toggle(!Destroy/~Leave/Pick)",
2031 "^G \"(\" No display in the 'M'ap",
2032 "^O \"#\" Auto-Inscribe",
2033 "------------------------------------",
2034 "^U Toggle 'identified' state",
2036 "^X Toggle nameless/ego/artifact",
2037 "^Z \"collecting\"",
2043 #define MAX_YANK 1024
2044 #define MAX_LINELEN 1024
2045 #define DIRTY_ALL 0x01
2046 #define DIRTY_COMMAND 0x02
2047 #define DIRTY_MODE 0x04
2048 #define DIRTY_SCREEN 0x04
2051 * In-game editor of Object Auto-picker/Destoryer
2053 void do_cmd_edit_autopick(void)
2055 static int cx = 0, cy = 0;
2056 static int upper = 0, left = 0;
2058 cptr last_destroyed;
2059 char last_destroyed_command[WID_DESC+3];
2060 char yank_buf[MAX_YANK];
2062 autopick_type an_entry, *entry = &an_entry;
2063 char buf[MAX_LINELEN];
2069 int old_upper = -1, old_left = -1;
2071 int key = -1, old_key;
2073 bool edit_mode = FALSE;
2075 byte dirty_flags = DIRTY_ALL | DIRTY_COMMAND | DIRTY_MODE;
2076 int dirty_line = -1;
2078 int wid, hgt, old_wid = -1, old_hgt = -1;
2080 /* Free old entries */
2083 /* Name of the Last Destroyed Item */
2084 last_destroyed = autopick_line_from_entry(&autopick_entry_last_destroyed);
2086 /* Command Description of the Last Destroyed Item */
2089 strcpy(last_destroyed_command, "^L \"");
2090 strncpy(last_destroyed_command + 4, last_destroyed, WID_DESC-4);
2091 last_destroyed_command[WID_DESC+2] = '\0';
2096 strcpy(last_destroyed_command, "^L ºÇ¸å¤Ë¼«Æ°Ç˲õ¤·¤¿¥¢¥¤¥Æ¥à̾");
2098 strcpy(last_destroyed_command, "^L Last destroyed object");
2101 ctrl_command_desc[LAST_DESTROYED] = last_destroyed_command;
2103 /* Conditional Expression for Class and Race */
2104 sprintf(classrace, "?:[AND [EQU $RACE %s] [EQU $CLASS %s]]",
2106 rp_ptr->E_title, cp_ptr->E_title
2108 rp_ptr->title, cp_ptr->title
2112 /* Clear yank buffer */
2115 /* Read or initialize whole text */
2116 lines_list = read_pickpref_text_lines();
2118 /* Reset cursor position if needed */
2119 for (i = 0; i < cy; i++)
2128 /* Save the screen */
2131 /* Process requests until done */
2135 Term_get_size(&wid, &hgt);
2138 /* Don't let cursor at second byte of kanji */
2139 for (i = 0; lines_list[cy][i]; i++)
2140 if (iskanji(lines_list[cy][i]))
2151 /* Scroll if necessary */
2152 if (cy < upper || upper + hgt - 4 <= cy)
2153 upper = cy - (hgt-4)/2;
2156 if ((cx < left + 10 && left > 0) || left + wid - WID_DESC - 5 <= cx)
2157 left = cx - (wid - WID_DESC)*2/3;
2161 /* Redraw whole window after resize */
2162 if (old_wid != wid || old_hgt != hgt)
2163 dirty_flags |= DIRTY_SCREEN;
2165 /* Redraw all text after scroll */
2166 else if (old_upper != upper || old_left != left)
2167 dirty_flags |= DIRTY_ALL;
2170 if (dirty_flags & DIRTY_SCREEN)
2172 dirty_flags = DIRTY_ALL | DIRTY_COMMAND | DIRTY_MODE;
2178 if (dirty_flags & DIRTY_COMMAND)
2180 /* Display control command */
2181 for (i = 0; ctrl_command_desc[i]; i++)
2182 Term_putstr(wid - WID_DESC, i + 1, WID_DESC, TERM_WHITE, ctrl_command_desc[i]);
2185 /* Redraw mode line */
2186 if (dirty_flags & DIRTY_MODE)
2188 int sepa_length = wid - WID_DESC;
2191 for (i = 0; i < sepa_length; i++)
2197 strncpy(buf + sepa_length - 21, " (INSERT MODE) ", 16);
2199 strncpy(buf + sepa_length - 21, " (COMMAND MODE) ", 16);
2201 Term_putstr(0, hgt - 3, sepa_length, (byte) (edit_mode ? TERM_YELLOW : TERM_WHITE), buf);
2204 /* Dump up to 20, or hgt-4, lines of messages */
2205 for (i = 0; i < hgt - 4; i++)
2210 /* clean or dirty? */
2211 if (!(dirty_flags & DIRTY_ALL) && (dirty_line != upper+i))
2214 msg = lines_list[upper+i];
2217 /* Apply horizontal scroll */
2218 for (j = 0; *msg; msg++, j++)
2220 if (j == left) break;
2236 Term_erase(0, i + 1, wid - WID_DESC);
2238 /* Dump the messages, bottom to top */
2239 Term_putstr(leftcol, i + 1, wid - WID_DESC - 1, TERM_WHITE, msg);
2242 for (; i < hgt - 4; i++)
2245 Term_erase(0, i + 1, wid - WID_DESC);
2248 /* Display header line */
2251 prt("^Q ESC ¤Ç¥³¥Þ¥ó¥É¥â¡¼¥É¤Ø°Ü¹Ô¡¢Ä̾ï¤Îʸ»ú¤Ï¤½¤Î¤Þ¤ÞÆþÎÏ", 0, 0);
2253 prt("q _ ¤Ç½ªÎ»¡¢hjkl2468 ¤Ç°ÜÆ°¡¢^Q a i ¤ÇÆþÎϥ⡼¥É", 0, 0);
2256 prt("Press ^Q ESC to command mode, any letters to insert", 0, 0);
2258 prt("Press q _ to quit, hjkl2468 to move, ^Q a i to insert mode", 0, 0);
2260 /* Display current position */
2261 prt (format("(%d,%d)", cx, cy), 0, 70);
2263 /* Display information when updated */
2264 if (old_cy != cy || (dirty_flags & DIRTY_ALL) || dirty_line == cy)
2266 /* Clear information line */
2267 Term_erase(0, hgt - 3 + 1, wid);
2268 Term_erase(0, hgt - 3 + 2, wid);
2270 /* Display information */
2271 if (lines_list[cy][0] == '#')
2274 prt("¤³¤Î¹Ô¤Ï¥³¥á¥ó¥È¤Ç¤¹¡£", hgt - 3 + 1, 0);
2276 prt("This line is comment.", hgt - 3 + 1, 0);
2279 else if (lines_list[cy][1] == ':')
2281 switch(lines_list[cy][0])
2285 prt("¤³¤Î¹Ô¤Ï¾ò·ïʬ´ô¼°¤Ç¤¹¡£", hgt - 3 + 1, 0);
2287 prt("This line is Conditional Expression.", hgt - 3 + 1, 0);
2292 prt("¤³¤Î¹Ô¤Ï¥Þ¥¯¥í¤Î¼Â¹ÔÆâÍƤòÄêµÁ¤·¤Þ¤¹¡£", hgt - 3 + 1, 0);
2294 prt("This line defines Macro action.", hgt - 3 + 1, 0);
2299 prt("¤³¤Î¹Ô¤Ï¥Þ¥¯¥í¤Î¥È¥ê¥¬¡¼¡¦¥¡¼¤òÄêµÁ¤·¤Þ¤¹¡£", hgt - 3 + 1, 0);
2301 prt("This line defines Macro trigger key.", hgt - 3 + 1, 0);
2306 prt("¤³¤Î¹Ô¤Ï¥¡¼ÇÛÃÖ¤òÄêµÁ¤·¤Þ¤¹¡£", hgt - 3 + 1, 0);
2308 prt("This line defines Keymap.", hgt - 3 + 1, 0);
2314 /* Get description of an autopicker preference line */
2315 else if (autopick_new_entry(entry, lines_list[cy]))
2320 describe_autopick(buf, entry);
2322 roff_to_buf(buf, 81, temp);
2324 for (i = 0; i< 2; i++)
2330 prt(t, hgt - 3 + 1 + i, 0);
2334 autopick_free_entry(entry);
2339 Term_gotoxy(cx - left, cy - upper + 1);
2345 /* Save old key and location */
2353 /* Do not process macros except special keys */
2354 inkey_special = TRUE;
2365 /* Mode line is now dirty */
2366 dirty_flags |= DIRTY_MODE;
2369 /* Insert a character */
2370 else if (!iscntrl(key&0xff))
2374 /* Save preceding string */
2375 for (i = j = 0; lines_list[cy][i] && i < cx; i++)
2376 buf[j++] = lines_list[cy][i];
2378 /* Add a character */
2384 if (j+2 < MAX_LINELEN)
2396 if (j+1 < MAX_LINELEN)
2402 for (; lines_list[cy][i] && j + 1 < MAX_LINELEN; i++)
2403 buf[j++] = lines_list[cy][i];
2406 /* Replace current line with new line */
2407 string_free(lines_list[cy]);
2408 lines_list[cy] = string_make(buf);
2410 /* Move to correct collumn */
2411 len = strlen(lines_list[cy]);
2412 if (len < cx) cx = len;
2421 if (key == 'q' || key == '_') break;
2428 /* Mode line is now dirty */
2429 dirty_flags |= DIRTY_MODE;
2432 if (!autopick_new_entry(entry, lines_list[cy]))
2434 string_free(lines_list[cy]);
2436 entry->action &= ~DO_AUTODESTROY;
2437 if (entry->action & DO_AUTOPICK)
2439 entry->action &= ~DO_AUTOPICK;
2440 entry->action |= DONT_AUTOPICK;
2444 entry->action &= ~DONT_AUTOPICK;
2445 entry->action |= DO_AUTOPICK;
2448 lines_list[cy] = autopick_line_from_entry(entry);
2454 if (!autopick_new_entry(entry, lines_list[cy]))
2456 string_free(lines_list[cy]);
2458 entry->action &= ~DONT_AUTOPICK;
2459 if (entry->action & DO_AUTOPICK)
2461 entry->action &= ~DO_AUTOPICK;
2462 entry->action |= DO_AUTODESTROY;
2466 entry->action &= ~DO_AUTODESTROY;
2467 entry->action |= DO_AUTOPICK;
2470 lines_list[cy] = autopick_line_from_entry(entry);
2495 while (cy < upper + hgt-4 && lines_list[cy + 1])
2500 while (0 < cy && upper <= cy)
2502 while (0 < upper && cy + 1 < upper + hgt - 4)
2511 /* Beginning of line */
2519 len = strlen(lines_list[cy]);
2520 if (len < cx) cx = len;
2525 cx = strlen(lines_list[cy]);
2529 /* Insert a conditinal expression line */
2530 insert_return_code(lines_list, 0, cy);
2531 lines_list[cy] = string_make(classrace);
2533 insert_return_code(lines_list, 0, cy);
2534 lines_list[cy] = string_make("?:1");
2538 dirty_flags |= DIRTY_ALL;
2542 cx = strlen(lines_list[cy]);
2547 if (iskanji(lines_list[cy][cx])) cx++;
2550 len = strlen(lines_list[cy]);
2553 if (lines_list[cy + 1])
2563 /* Toggle display on the 'M'ap */
2564 if (!autopick_new_entry(entry, lines_list[cy]))
2566 string_free(lines_list[cy]);
2568 if (entry->action & DO_DISPLAY)
2570 entry->action &= ~DO_DISPLAY;
2575 entry->action |= DO_DISPLAY;
2579 lines_list[cy] = autopick_line_from_entry(entry);
2585 /* Insert choosen item name */
2586 if (!entry_from_choosed_object(entry))
2588 /* Now dirty because of item/equip menu */
2589 dirty_flags |= DIRTY_SCREEN;
2592 tmp = autopick_line_from_entry(entry);
2593 autopick_free_entry(entry);
2596 insert_return_code(lines_list, 0, cy);
2597 lines_list[cy] = tmp;
2600 /* Now dirty because of item/equip menu */
2601 dirty_flags |= DIRTY_SCREEN;
2605 /* Insert a name of last destroyed item */
2608 insert_return_code(lines_list, 0, cy);
2609 lines_list[cy] = string_make(last_destroyed);
2613 dirty_flags |= DIRTY_ALL;
2616 case '\n': case '\r':
2617 /* Split a line or insert end of line */
2618 insert_return_code(lines_list, cx, cy);
2623 dirty_flags |= DIRTY_ALL;
2627 if (lines_list[cy + 1]) cy++;
2630 /* Prepare to write auto-inscription text */
2631 if (!autopick_new_entry(entry, lines_list[cy]))
2633 string_free(lines_list[cy]);
2635 if (!entry->insc) entry->insc = string_make("");
2637 lines_list[cy] = autopick_line_from_entry(entry);
2639 /* Move to collumn for auto inscription */
2640 for (cx = 0; lines_list[cy][cx]; cx++)
2641 if (lines_list[cy][cx] == '#') break;
2647 dirty_flags |= DIRTY_MODE;
2655 edit_mode = !edit_mode;
2657 /* Mode line is now dirty */
2658 dirty_flags |= DIRTY_MODE;
2661 /* Revert to original */
2663 if (!get_check("Á´¤Æ¤ÎÊѹ¹¤òÇË´þ¤·¤Æ¸µ¤Î¾õÂÖ¤ËÌᤷ¤Þ¤¹¡£¤è¤í¤·¤¤¤Ç¤¹¤«¡© "))
2665 if (!get_check("Discard all change and revert to original file. Are you sure? "))
2669 free_text_lines(lines_list);
2670 lines_list = read_pickpref_text_lines();
2671 dirty_flags |= DIRTY_ALL | DIRTY_MODE;
2676 /* Rotate action; pickup/destroy/leave */
2677 if (!autopick_new_entry(entry, lines_list[cy]))
2679 string_free(lines_list[cy]);
2681 if (entry->action & DO_AUTOPICK)
2683 entry->action &= ~DO_AUTOPICK;
2684 entry->action |= DO_AUTODESTROY;
2686 else if (entry->action & DO_AUTODESTROY)
2688 entry->action &= ~DO_AUTODESTROY;
2689 entry->action |= DONT_AUTOPICK;
2691 else if (entry->action & DONT_AUTOPICK)
2693 entry->action &= ~DONT_AUTOPICK;
2694 entry->action |= DO_AUTOPICK;
2697 lines_list[cy] = autopick_line_from_entry(entry);
2706 /* Rotate identify-state; identified/unidentified/... */
2707 if (!autopick_new_entry(entry, lines_list[cy]))
2709 string_free(lines_list[cy]);
2711 if (IS_FLG(FLG_UNIDENTIFIED))
2713 REM_FLG(FLG_UNIDENTIFIED);
2714 ADD_FLG(FLG_UNAWARE);
2715 REM_FLG(FLG_IDENTIFIED);
2716 REM_FLG(FLG_STAR_IDENTIFIED);
2718 else if (IS_FLG(FLG_UNAWARE))
2720 REM_FLG(FLG_UNIDENTIFIED);
2721 REM_FLG(FLG_UNAWARE);
2722 ADD_FLG(FLG_IDENTIFIED);
2723 REM_FLG(FLG_STAR_IDENTIFIED);
2725 else if (IS_FLG(FLG_STAR_IDENTIFIED))
2727 REM_FLG(FLG_UNIDENTIFIED);
2728 REM_FLG(FLG_UNAWARE);
2729 REM_FLG(FLG_IDENTIFIED);
2730 REM_FLG(FLG_STAR_IDENTIFIED);
2732 else if (IS_FLG(FLG_IDENTIFIED))
2734 REM_FLG(FLG_UNIDENTIFIED);
2735 REM_FLG(FLG_UNAWARE);
2736 REM_FLG(FLG_IDENTIFIED);
2737 ADD_FLG(FLG_STAR_IDENTIFIED);
2741 ADD_FLG(FLG_UNIDENTIFIED);
2742 REM_FLG(FLG_UNAWARE);
2743 REM_FLG(FLG_IDENTIFIED);
2744 REM_FLG(FLG_STAR_IDENTIFIED);
2747 lines_list[cy] = autopick_line_from_entry(entry);
2754 while (cy < upper + hgt-4 && lines_list[cy + 1])
2759 /* Toggle 'worthless' */
2760 toggle_string(lines_list, FLG_WORTHLESS, cy);
2765 /* Rotate within nameless, ego, artifact */
2766 if (!autopick_new_entry(entry, lines_list[cy]))
2768 string_free(lines_list[cy]);
2770 if (IS_FLG(FLG_NAMELESS))
2772 REM_FLG(FLG_NAMELESS);
2774 REM_FLG(FLG_ARTIFACT);
2776 else if (IS_FLG(FLG_EGO))
2778 REM_FLG(FLG_NAMELESS);
2780 ADD_FLG(FLG_ARTIFACT);
2782 else if (IS_FLG(FLG_ARTIFACT))
2784 REM_FLG(FLG_NAMELESS);
2786 REM_FLG(FLG_ARTIFACT);
2790 ADD_FLG(FLG_NAMELESS);
2792 REM_FLG(FLG_ARTIFACT);
2795 lines_list[cy] = autopick_line_from_entry(entry);
2802 /* Paste killed text */
2803 if (strlen(yank_buf))
2805 for (j = 0; yank_buf[j]; j += strlen(yank_buf + j) + 1)
2809 /* Split current line */
2810 insert_return_code(lines_list, cx, cy);
2812 /* Paste yank buffer */
2813 for(i = 0; lines_list[cy][i]; i++)
2814 buf[i] = lines_list[cy][i];
2815 while (yank_buf[k] && i < MAX_LINELEN)
2816 buf[i++] = yank_buf[k++];
2819 string_free(lines_list[cy]);
2820 lines_list[cy] = string_make(buf);
2822 /* Move to the beggining of next line */
2828 dirty_flags |= DIRTY_ALL;
2832 /* Toggle 'collecting' */
2833 toggle_string(lines_list, FLG_COLLECTING, cy);
2839 /* Kill rest of line */
2840 if (lines_list[cy][0] != '\0' && (uint)cx < strlen(lines_list[cy]))
2842 /* Save preceding string */
2843 for (i = 0; lines_list[cy][i] && i < cx; i++)
2846 if (iskanji(lines_list[cy][i]))
2848 buf[i] = lines_list[cy][i];
2852 buf[i] = lines_list[cy][i];
2857 if (old_key == KTRL('k'))
2859 j += strlen(yank_buf + j) + 1;
2861 /* Copy following to yank buffer */
2862 while (lines_list[cy][i] && j < MAX_YANK - 2)
2863 yank_buf[j++] = lines_list[cy][i++];
2864 yank_buf[j++] = '\0';
2867 /* Replace current line with 'preceding string' */
2868 string_free(lines_list[cy]);
2869 lines_list[cy] = string_make(buf);
2878 /* DELETE == go forward + BACK SPACE */
2880 if (iskanji(lines_list[cy][cx])) cx++;
2888 len = strlen(lines_list[cy]);
2891 if (lines_list[cy + 1])
2905 /* delete a return code and union two lines */
2907 cx = strlen(lines_list[cy-1]);
2908 strcpy(buf, lines_list[cy-1]);
2909 strcat(buf, lines_list[cy]);
2910 string_free(lines_list[cy-1]);
2911 string_free(lines_list[cy]);
2912 lines_list[cy-1] = string_make(buf);
2913 for (i = cy; lines_list[i+1]; i++)
2914 lines_list[i] = lines_list[i+1];
2915 lines_list[i] = NULL;
2919 dirty_flags |= DIRTY_ALL;
2923 for (i = j = 0; lines_list[cy][i] && i < cx; i++)
2927 if (iskanji(lines_list[cy][i]))
2928 buf[j++] = lines_list[cy][i++];
2930 buf[j++] = lines_list[cy][i];
2937 for (; lines_list[cy][i]; i++)
2938 buf[j++] = lines_list[cy][i];
2940 string_free(lines_list[cy]);
2941 lines_list[cy] = string_make(buf);
2950 /* Restore the screen */
2954 sprintf(buf, "picktype-%s.prf", player_name);
2956 sprintf(buf, "pickpref-%s.prf", player_name);
2958 write_text_lines(buf, lines_list);
2959 free_text_lines(lines_list);
2961 string_free(last_destroyed);
2963 /* Reload autopick pref */
2964 process_pickpref_file(buf);