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_FLG2(FLG) (entry->flag[FLG / 32] |= (1L << (FLG % 32)), prev_flg = FLG)
170 #define IS_FLG(FLG) (entry->flag[FLG / 32] & (1L << (FLG % 32)))
173 static char kanji_colon[] = "¡§";
178 * Reconstruct preference line from entry
180 cptr autopick_line_from_entry(autopick_type *entry)
184 bool sepa_flag = TRUE;
187 if (!(entry->action & DO_DISPLAY)) strcat(buf, "(");
188 if (entry->action & DO_AUTODESTROY) strcat(buf, "!");
189 if (entry->action & DONT_AUTOPICK) strcat(buf, "~");
193 if (IS_FLG(FLG_ALL)) ADD_KEY(KEY_ALL);
194 if (IS_FLG(FLG_COLLECTING)) ADD_KEY(KEY_COLLECTING);
195 if (IS_FLG(FLG_UNIDENTIFIED)) ADD_KEY(KEY_UNIDENTIFIED);
196 if (IS_FLG(FLG_IDENTIFIED)) ADD_KEY(KEY_IDENTIFIED);
197 if (IS_FLG(FLG_STAR_IDENTIFIED)) ADD_KEY(KEY_STAR_IDENTIFIED);
198 if (IS_FLG(FLG_BOOSTED)) ADD_KEY(KEY_BOOSTED);
200 if (IS_FLG(FLG_MORE_THAN))
202 ADD_KEY(KEY_MORE_THAN);
203 strcat(ptr, format("%d", entry->dice));
207 if (IS_FLG(FLG_MORE_BONUS))
209 ADD_KEY(KEY_MORE_BONUS);
210 strcat(ptr, format("%d", entry->bonus));
211 ADD_KEY(KEY_MORE_BONUS2);
214 if (IS_FLG(FLG_WORTHLESS)) ADD_KEY(KEY_WORTHLESS);
215 if (IS_FLG(FLG_ARTIFACT)) ADD_KEY(KEY_ARTIFACT);
216 if (IS_FLG(FLG_EGO)) ADD_KEY(KEY_EGO);
217 if (IS_FLG(FLG_NAMELESS)) ADD_KEY(KEY_NAMELESS);
218 if (IS_FLG(FLG_UNAWARE)) ADD_KEY(KEY_UNAWARE);
219 if (IS_FLG(FLG_WANTED)) ADD_KEY(KEY_WANTED);
220 if (IS_FLG(FLG_UNIQUE)) ADD_KEY(KEY_UNIQUE);
221 if (IS_FLG(FLG_HUMAN)) ADD_KEY(KEY_HUMAN);
222 if (IS_FLG(FLG_UNREADABLE)) ADD_KEY(KEY_UNREADABLE);
223 if (IS_FLG(FLG_REALM1)) ADD_KEY(KEY_REALM1);
224 if (IS_FLG(FLG_REALM2)) ADD_KEY(KEY_REALM2);
225 if (IS_FLG(FLG_FIRST)) ADD_KEY(KEY_FIRST);
226 if (IS_FLG(FLG_SECOND)) ADD_KEY(KEY_SECOND);
227 if (IS_FLG(FLG_THIRD)) ADD_KEY(KEY_THIRD);
228 if (IS_FLG(FLG_FOURTH)) ADD_KEY(KEY_FOURTH);
230 if (IS_FLG(FLG_ITEMS)) ADD_KEY2(KEY_ITEMS);
231 else if (IS_FLG(FLG_WEAPONS)) ADD_KEY2(KEY_WEAPONS);
232 else if (IS_FLG(FLG_ARMORS)) ADD_KEY2(KEY_ARMORS);
233 else if (IS_FLG(FLG_MISSILES)) ADD_KEY2(KEY_MISSILES);
234 else if (IS_FLG(FLG_DEVICES)) ADD_KEY2(KEY_DEVICES);
235 else if (IS_FLG(FLG_LIGHTS)) ADD_KEY2(KEY_LIGHTS);
236 else if (IS_FLG(FLG_JUNKS)) ADD_KEY2(KEY_JUNKS);
237 else if (IS_FLG(FLG_SPELLBOOKS)) ADD_KEY2(KEY_SPELLBOOKS);
238 else if (IS_FLG(FLG_HAFTED)) ADD_KEY2(KEY_HAFTED);
239 else if (IS_FLG(FLG_SHIELDS)) ADD_KEY2(KEY_SHIELDS);
240 else if (IS_FLG(FLG_BOWS)) ADD_KEY2(KEY_BOWS);
241 else if (IS_FLG(FLG_RINGS)) ADD_KEY2(KEY_RINGS);
242 else if (IS_FLG(FLG_AMULETS)) ADD_KEY2(KEY_AMULETS);
243 else if (IS_FLG(FLG_SUITS)) ADD_KEY2(KEY_SUITS);
244 else if (IS_FLG(FLG_CLOAKS)) ADD_KEY2(KEY_CLOAKS);
245 else if (IS_FLG(FLG_HELMS)) ADD_KEY2(KEY_HELMS);
246 else if (IS_FLG(FLG_GLOVES)) ADD_KEY2(KEY_GLOVES);
247 else if (IS_FLG(FLG_BOOTS)) ADD_KEY2(KEY_BOOTS);
251 if (entry->name && *entry->name)
255 strcat(buf, entry->name);
259 if (entry->flag[0] == 0L && entry->flag[0] == 0L)
266 strcat(buf, entry->insc);
269 return string_make(buf);
273 * A function to create new entry
275 bool autopick_new_entry(autopick_type *entry, cptr str)
284 if (str[1] == ':') switch (str[0])
287 case 'A': case 'P': case 'C':
291 entry->flag[0] = entry->flag[1] = 0L;
294 act = DO_AUTOPICK | DO_DISPLAY;
297 if ((act & DO_AUTOPICK) && *str == '!')
300 act |= DO_AUTODESTROY;
303 else if ((act & DO_AUTOPICK) && *str == '~')
306 act |= DONT_AUTOPICK;
309 else if ((act & DO_DISPLAY) && *str == '(')
318 /* don't mind upper or lower case */
320 for (i = 0; *str; i++)
331 /* Auto-inscription? */
339 if (isupper(c)) c = tolower(c);
345 /* Skip empty line */
346 if (*buf == 0) return FALSE;
349 prev_ptr = ptr = buf;
351 if (MATCH_KEY(KEY_ALL)) ADD_FLG(FLG_ALL);
352 if (MATCH_KEY(KEY_COLLECTING)) ADD_FLG(FLG_COLLECTING);
353 if (MATCH_KEY(KEY_UNIDENTIFIED)) ADD_FLG(FLG_UNIDENTIFIED);
354 if (MATCH_KEY(KEY_IDENTIFIED)) ADD_FLG(FLG_IDENTIFIED);
355 if (MATCH_KEY(KEY_STAR_IDENTIFIED)) ADD_FLG(FLG_STAR_IDENTIFIED);
356 if (MATCH_KEY(KEY_BOOSTED)) ADD_FLG(FLG_BOOSTED);
358 /*** Weapons whose dd*ds is more than nn ***/
359 if (MATCH_KEY(KEY_MORE_THAN))
364 /* Drop leading spaces */
365 while (' ' == *ptr) ptr++;
368 while (isdigit(*ptr))
370 entry->dice = 10 * entry->dice + (*ptr - '0');
377 (void)MATCH_KEY(KEY_DICE);
378 ADD_FLG(FLG_MORE_THAN);
384 /*** Items whose magical bonus is more than n ***/
385 if (MATCH_KEY(KEY_MORE_BONUS))
390 /* Drop leading spaces */
391 while (' ' == *ptr) ptr++;
394 while (isdigit(*ptr))
396 entry->bonus = 10 * entry->bonus + (*ptr - '0');
403 (void)MATCH_KEY(KEY_MORE_BONUS2);
404 ADD_FLG(FLG_MORE_BONUS);
410 if (MATCH_KEY(KEY_WORTHLESS)) ADD_FLG(FLG_WORTHLESS);
411 if (MATCH_KEY(KEY_ARTIFACT)) ADD_FLG(FLG_ARTIFACT);
412 if (MATCH_KEY(KEY_EGO)) ADD_FLG(FLG_EGO);
413 if (MATCH_KEY(KEY_NAMELESS)) ADD_FLG(FLG_NAMELESS);
414 if (MATCH_KEY(KEY_UNAWARE)) ADD_FLG(FLG_UNAWARE);
415 if (MATCH_KEY(KEY_WANTED)) ADD_FLG(FLG_WANTED);
416 if (MATCH_KEY(KEY_UNIQUE)) ADD_FLG(FLG_UNIQUE);
417 if (MATCH_KEY(KEY_HUMAN)) ADD_FLG(FLG_HUMAN);
418 if (MATCH_KEY(KEY_UNREADABLE)) ADD_FLG(FLG_UNREADABLE);
419 if (MATCH_KEY(KEY_REALM1)) ADD_FLG(FLG_REALM1);
420 if (MATCH_KEY(KEY_REALM2)) ADD_FLG(FLG_REALM2);
421 if (MATCH_KEY(KEY_FIRST)) ADD_FLG(FLG_FIRST);
422 if (MATCH_KEY(KEY_SECOND)) ADD_FLG(FLG_SECOND);
423 if (MATCH_KEY(KEY_THIRD)) ADD_FLG(FLG_THIRD);
424 if (MATCH_KEY(KEY_FOURTH)) ADD_FLG(FLG_FOURTH);
426 /* Reset previous word location */
429 if (MATCH_KEY(KEY_ITEMS)) ADD_FLG2(FLG_ITEMS);
430 else if (MATCH_KEY(KEY_WEAPONS)) ADD_FLG2(FLG_WEAPONS);
431 else if (MATCH_KEY(KEY_ARMORS)) ADD_FLG2(FLG_ARMORS);
432 else if (MATCH_KEY(KEY_MISSILES)) ADD_FLG2(FLG_MISSILES);
433 else if (MATCH_KEY(KEY_DEVICES)) ADD_FLG2(FLG_DEVICES);
434 else if (MATCH_KEY(KEY_LIGHTS)) ADD_FLG2(FLG_LIGHTS);
435 else if (MATCH_KEY(KEY_JUNKS)) ADD_FLG2(FLG_JUNKS);
436 else if (MATCH_KEY(KEY_SPELLBOOKS)) ADD_FLG2(FLG_SPELLBOOKS);
437 else if (MATCH_KEY(KEY_HAFTED)) ADD_FLG2(FLG_HAFTED);
438 else if (MATCH_KEY(KEY_SHIELDS)) ADD_FLG2(FLG_SHIELDS);
439 else if (MATCH_KEY(KEY_BOWS)) ADD_FLG2(FLG_BOWS);
440 else if (MATCH_KEY(KEY_RINGS)) ADD_FLG2(FLG_RINGS);
441 else if (MATCH_KEY(KEY_AMULETS)) ADD_FLG2(FLG_AMULETS);
442 else if (MATCH_KEY(KEY_SUITS)) ADD_FLG2(FLG_SUITS);
443 else if (MATCH_KEY(KEY_CLOAKS)) ADD_FLG2(FLG_CLOAKS);
444 else if (MATCH_KEY(KEY_HELMS)) ADD_FLG2(FLG_HELMS);
445 else if (MATCH_KEY(KEY_GLOVES)) ADD_FLG2(FLG_GLOVES);
446 else if (MATCH_KEY(KEY_BOOTS)) ADD_FLG2(FLG_BOOTS);
448 /* Last 'keyword' must be at the correct location */
451 else if (*ptr == '\0')
452 ; /* nothing to do */
454 else if (ptr[0] == kanji_colon[0] && ptr[1] == kanji_colon[1])
460 entry->flag[prev_flg/32] &= ~(1L<< (prev_flg%32));
463 entry->name = string_make(ptr);
465 entry->insc = string_make(insc);
471 * A function to delete entry
473 void autopick_free_entry(autopick_type *entry)
475 string_free(entry->name);
476 string_free(entry->insc);
480 * A function for Auto-picker/destroyer
481 * Examine whether the object matches to the list of keywords or not.
483 int is_autopick(object_type *o_ptr)
486 char o_name[MAX_NLEN];
488 if (o_ptr->tval == TV_GOLD) return -1;
490 object_desc(o_name, o_ptr, FALSE, 3);
492 /* Force to be lower case string */
493 for (i = 0; o_name[i]; i++)
496 if (iskanji(o_name[i]))
500 if (isupper(o_name[i]))
501 o_name[i] = tolower(o_name[i]);
504 for (i=0; i < max_autopick; i++)
506 autopick_type *entry = &autopick_list[i];
508 cptr ptr = autopick_list[i].name;
510 /*** Unidentified ***/
511 if (IS_FLG(FLG_UNIDENTIFIED)
512 && (object_known_p(o_ptr) || (o_ptr->ident & IDENT_SENSE)))
516 if (IS_FLG(FLG_IDENTIFIED) && !object_known_p(o_ptr))
519 /*** *Identified* ***/
520 if (IS_FLG(FLG_STAR_IDENTIFIED) &&
521 (!object_known_p(o_ptr) || !(o_ptr->ident & IDENT_MENTAL)))
524 /*** Dice boosted (weapon of slaying) ***/
525 if (IS_FLG(FLG_BOOSTED))
527 object_kind *k_ptr = &k_info[o_ptr->k_idx];
529 switch( o_ptr->tval )
535 if ((o_ptr->dd != k_ptr->dd) || (o_ptr->ds != k_ptr->ds))
544 /*** Weapons whic dd*ds is more than nn ***/
545 if (IS_FLG(FLG_MORE_THAN))
547 if (o_ptr->dd * o_ptr->ds < entry->dice)
551 /*** Weapons whic dd*ds is more than nn ***/
552 if (IS_FLG(FLG_MORE_BONUS))
554 if (!object_known_p(o_ptr)) continue;
556 if (k_info[o_ptr->k_idx].pval ||
557 (o_ptr->name2 && e_info[o_ptr->name2].max_pval))
559 if (o_ptr->pval < entry->bonus) continue;
563 if (o_ptr->to_h < entry->bonus &&
564 o_ptr->to_d < entry->bonus &&
565 o_ptr->to_a < entry->bonus &&
566 o_ptr->pval < entry->bonus)
571 /*** Worthless items ***/
572 if (IS_FLG(FLG_WORTHLESS) && object_value(o_ptr) > 0)
575 /*** Artifact object ***/
576 if (IS_FLG(FLG_ARTIFACT))
578 if (!object_known_p(o_ptr) || (!o_ptr->name1 && !o_ptr->art_name))
585 if (!object_known_p(o_ptr) || !o_ptr->name2)
590 if (IS_FLG(FLG_NAMELESS))
595 case TV_SHOT: case TV_ARROW: case TV_BOLT: case TV_BOW:
596 case TV_DIGGING: case TV_HAFTED: case TV_POLEARM: case TV_SWORD:
597 case TV_BOOTS: case TV_GLOVES: case TV_HELM: case TV_CROWN:
598 case TV_SHIELD: case TV_CLOAK:
599 case TV_SOFT_ARMOR: case TV_HARD_ARMOR: case TV_DRAG_ARMOR:
600 case TV_LITE: case TV_AMULET: case TV_RING: case TV_CARD:
601 if ((!object_known_p(o_ptr) || o_ptr->inscription
602 || o_ptr->name1 || o_ptr->name2 || o_ptr->art_name))
611 /*** Unaware items ***/
612 if (IS_FLG(FLG_UNAWARE) && object_aware_p(o_ptr))
615 /*** Wanted monster's corpse/skeletons ***/
616 if (IS_FLG(FLG_WANTED) &&
617 (o_ptr->tval != TV_CORPSE || !object_is_shoukinkubi(o_ptr)))
620 /*** Unique monster's corpse/skeletons/statues ***/
621 if (IS_FLG(FLG_UNIQUE) &&
622 ((o_ptr->tval != TV_CORPSE && o_ptr->tval != TV_STATUE) ||
623 !(r_info[o_ptr->pval].flags1 & RF1_UNIQUE)))
626 /*** Human corpse/skeletons (for Daemon magic) ***/
627 if (IS_FLG(FLG_HUMAN) &&
628 (o_ptr->tval != TV_CORPSE ||
629 !strchr("pht", r_info[o_ptr->pval].d_char)))
632 /*** Unreadable spellbooks ***/
633 if (IS_FLG(FLG_UNREADABLE) &&
634 (o_ptr->tval < TV_LIFE_BOOK ||
635 check_book_realm(o_ptr->tval, o_ptr->sval)))
638 /*** First realm spellbooks ***/
639 if (IS_FLG(FLG_REALM1) &&
640 (REALM1_BOOK != o_ptr->tval ||
641 p_ptr->pclass == CLASS_SORCERER ||
642 p_ptr->pclass == CLASS_RED_MAGE))
645 /*** Second realm spellbooks ***/
646 if (IS_FLG(FLG_REALM2) &&
647 (REALM2_BOOK != o_ptr->tval ||
648 p_ptr->pclass == CLASS_SORCERER ||
649 p_ptr->pclass == CLASS_RED_MAGE))
652 /*** First rank spellbooks ***/
653 if (IS_FLG(FLG_FIRST) &&
654 (o_ptr->tval < TV_LIFE_BOOK || 0 != o_ptr->sval))
657 /*** Second rank spellbooks ***/
658 if (IS_FLG(FLG_SECOND) &&
659 (o_ptr->tval < TV_LIFE_BOOK || 1 != o_ptr->sval))
662 /*** Third rank spellbooks ***/
663 if (IS_FLG(FLG_THIRD) &&
664 (o_ptr->tval < TV_LIFE_BOOK || 2 != o_ptr->sval))
667 /*** Fourth rank spellbooks ***/
668 if (IS_FLG(FLG_FOURTH) &&
669 (o_ptr->tval < TV_LIFE_BOOK || 3 != o_ptr->sval))
673 if (IS_FLG(FLG_WEAPONS))
677 case TV_BOW: case TV_HAFTED: case TV_POLEARM:
678 case TV_SWORD: case TV_DIGGING:
683 else if (IS_FLG(FLG_ARMORS))
687 case TV_BOOTS: case TV_GLOVES: case TV_CLOAK: case TV_CROWN:
688 case TV_HELM: case TV_SHIELD: case TV_SOFT_ARMOR:
689 case TV_HARD_ARMOR: case TV_DRAG_ARMOR:
694 else if (IS_FLG(FLG_MISSILES))
698 case TV_SHOT: case TV_BOLT: case TV_ARROW:
703 else if (IS_FLG(FLG_DEVICES))
707 case TV_SCROLL: case TV_STAFF: case TV_WAND: case TV_ROD:
712 else if (IS_FLG(FLG_LIGHTS))
714 if (!(o_ptr->tval == TV_LITE))
717 else if (IS_FLG(FLG_JUNKS))
721 case TV_SKELETON: case TV_BOTTLE:
722 case TV_JUNK: case TV_STATUE:
727 else if (IS_FLG(FLG_SPELLBOOKS))
729 if (!(o_ptr->tval >= TV_LIFE_BOOK))
732 else if (IS_FLG(FLG_HAFTED))
734 if (!(o_ptr->tval == TV_HAFTED))
737 else if (IS_FLG(FLG_SHIELDS))
739 if (!(o_ptr->tval == TV_SHIELD))
742 else if (IS_FLG(FLG_BOWS))
744 if (!(o_ptr->tval == TV_BOW))
747 else if (IS_FLG(FLG_RINGS))
749 if (!(o_ptr->tval == TV_RING))
752 else if (IS_FLG(FLG_AMULETS))
754 if (!(o_ptr->tval == TV_AMULET))
757 else if (IS_FLG(FLG_SUITS))
759 if (!(o_ptr->tval == TV_DRAG_ARMOR ||
760 o_ptr->tval == TV_HARD_ARMOR ||
761 o_ptr->tval == TV_SOFT_ARMOR))
764 else if (IS_FLG(FLG_CLOAKS))
766 if (!(o_ptr->tval == TV_CLOAK))
769 else if (IS_FLG(FLG_HELMS))
771 if (!(o_ptr->tval == TV_CROWN || o_ptr->tval == TV_HELM))
774 else if (IS_FLG(FLG_GLOVES))
776 if (!(o_ptr->tval == TV_GLOVES))
779 else if (IS_FLG(FLG_BOOTS))
781 if (!(o_ptr->tval == TV_BOOTS))
789 if (!strncmp(o_name, ptr, strlen(ptr)))
794 if (strstr_j(o_name, ptr))
796 if (strstr(o_name, ptr))
805 if (!IS_FLG(FLG_COLLECTING))
807 /* Check if there is a same item */
808 for (j = 0; j < INVEN_PACK; j++)
811 * 'Collecting' means the item must be absorbed
812 * into an inventory slot.
813 * But an item can not be absorbed into itself!
815 if ((&inventory[j] != o_ptr) &&
816 object_similar(&inventory[j], o_ptr))
827 * Automatically destroy items in this grid.
829 static bool is_opt_confirm_destroy(object_type *o_ptr)
831 if (!destroy_items) return FALSE;
833 /* Known to be worthless? */
835 if (object_value(o_ptr) > 0) return FALSE;
838 if ((o_ptr->tval >= TV_SHOT) && (o_ptr->tval <= TV_DRAG_ARMOR)) return FALSE;
841 if ((o_ptr->tval == TV_CHEST) && o_ptr->pval) return FALSE;
845 if (o_ptr->tval == TV_CORPSE
846 && object_is_shoukinkubi(o_ptr)) return FALSE;
850 if (o_ptr->tval == TV_CORPSE) return FALSE;
853 if ((o_ptr->tval == TV_SKELETON) || (o_ptr->tval == TV_BOTTLE) || (o_ptr->tval == TV_JUNK) || (o_ptr->tval == TV_STATUE)) return FALSE;
855 if (o_ptr->tval == TV_GOLD) return FALSE;
864 void auto_inscribe_item(int item, int idx)
868 /* Get the item (in the pack) */
869 if (item >= 0) o_ptr = &inventory[item];
871 /* Get the item (on the floor) */
872 else o_ptr = &o_list[0 - item];
874 /* Auto-inscription or Re-inscribe for resistances {%} */
875 if ((idx < 0 || !autopick_list[idx].insc) && !o_ptr->inscription)
878 if (o_ptr->inscription)
879 o_ptr->inscription = inscribe_flags(o_ptr, quark_str(o_ptr->inscription));
881 o_ptr->inscription = inscribe_flags(o_ptr, autopick_list[idx].insc);
883 if (item > INVEN_PACK)
885 /* Redraw inscription */
886 p_ptr->window |= (PW_EQUIP);
888 /* {.} and {$} effect p_ptr->warning and TRC_TELEPORT_SELF */
889 p_ptr->update |= (PU_BONUS);
893 /* Redraw inscription */
894 p_ptr->window |= (PW_INVEN);
900 * Automatically destroy an item if it is to be destroyed
902 bool auto_destroy_item(int item, int autopick_idx, bool wait_optimize)
904 bool destroy = FALSE;
905 char o_name[MAX_NLEN];
908 /* Don't destroy equipped items */
909 if (item > INVEN_PACK) return FALSE;
911 /* Get the item (in the pack) */
912 if (item >= 0) o_ptr = &inventory[item];
914 /* Get the item (on the floor) */
915 else o_ptr = &o_list[0 - item];
917 /* Easy-Auto-Destroyer */
918 if (is_opt_confirm_destroy(o_ptr)) destroy = TRUE;
920 /* Protected by auto-picker */
921 if (autopick_idx >= 0 &&
922 !(autopick_list[autopick_idx].action & DO_AUTODESTROY))
927 /* Auto-picker/destroyer */
928 if (autopick_idx >= 0 &&
929 (autopick_list[autopick_idx].action & DO_AUTODESTROY))
933 /* Not to be destroyed */
934 if (!destroy) return FALSE;
936 /* Now decided to destroy */
940 /* Describe the object (with {terrible/special}) */
941 object_desc(o_name, o_ptr, TRUE, 3);
944 if (!can_player_destroy_object(o_ptr))
948 msg_format("%s¤ÏÇ˲õÉÔǽ¤À¡£", o_name);
950 msg_format("You cannot auto-destroy %s.", o_name);
957 /* Record name of destroyed item */
958 autopick_free_entry(&autopick_entry_last_destroyed);
959 autopick_entry_from_object(&autopick_entry_last_destroyed, o_ptr);
961 /* Eliminate the item (from the pack) */
964 inven_item_increase(item, -(o_ptr->number));
967 * Optimize equipment when wait_optimize is TRUE.
968 * Optimize inventry later.
970 if (!wait_optimize || item > INVEN_PACK)
971 inven_item_optimize(item);
974 /* Eliminate the item (from the floor) */
977 delete_object_idx(0 - item);
980 /* Print a message */
982 msg_format("%s¤ò¼«Æ°Ç˲õ¤·¤Þ¤¹¡£", o_name);
984 msg_format("Auto-destroying %s.", o_name);
992 * Optimize all inventry items after consumption of staves or scrolls.
994 void optimize_inventry_auto_destroy(void)
998 for (i = 0; i <= INVEN_PACK; i++)
999 inven_item_optimize(i);
1004 * Automatically pickup/destroy items in this grid.
1006 void auto_pickup_items(cave_type *c_ptr)
1008 s16b this_o_idx, next_o_idx = 0;
1010 /* Scan the pile of objects */
1011 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1015 /* Acquire object */
1016 object_type *o_ptr = &o_list[this_o_idx];
1018 /* Acquire next object */
1019 next_o_idx = o_ptr->next_o_idx;
1021 idx = is_autopick(o_ptr);
1023 /* Item index for floor -1,-2,-3,... */
1024 auto_inscribe_item((-this_o_idx), idx);
1026 if (idx >= 0 && (autopick_list[idx].action & DO_AUTOPICK))
1030 if (!inven_carry_okay(o_ptr))
1032 char o_name[MAX_NLEN];
1034 /* Describe the object */
1035 object_desc(o_name, o_ptr, TRUE, 3);
1039 msg_format("¥¶¥Ã¥¯¤Ë¤Ï%s¤òÆþ¤ì¤ë·ä´Ö¤¬¤Ê¤¤¡£", o_name);
1041 msg_format("You have no room for %s.", o_name);
1045 py_pickup_aux(this_o_idx);
1052 * When always_pickup is 'yes', we disable
1053 * auto-destroyer from autopick function, and do only
1054 * easy-auto-destroyer.
1058 if (auto_destroy_item((-this_o_idx), idx, FALSE))
1066 * Describe which kind of object is Auto-picked/destroyed
1068 static void describe_autopick(char *buff, autopick_type *entry)
1070 cptr str = entry->name;
1071 byte act = entry->action;
1072 cptr insc = entry->insc;
1078 cptr before_str[100], body_str;
1081 body_str = "¥¢¥¤¥Æ¥à";
1083 /*** Collecting items ***/
1084 /*** Which can be absorbed into a slot as a bundle ***/
1085 if (IS_FLG(FLG_COLLECTING))
1086 before_str[before_n++] = "¼ý½¸Ãæ¤Ç´û¤Ë»ý¤Ã¤Æ¤¤¤ë¥¹¥í¥Ã¥È¤Ë¤Þ¤È¤á¤é¤ì¤ë";
1088 /*** Unidentified ***/
1089 if (IS_FLG(FLG_UNIDENTIFIED))
1090 before_str[before_n++] = "̤´ÕÄê¤Î";
1092 /*** Identified ***/
1093 if (IS_FLG(FLG_IDENTIFIED))
1094 before_str[before_n++] = "´ÕÄêºÑ¤ß¤Î";
1096 /*** *Identified* ***/
1097 if (IS_FLG(FLG_STAR_IDENTIFIED))
1098 before_str[before_n++] = "´°Á´¤Ë´ÕÄêºÑ¤ß¤Î";
1100 /*** Dice boosted (weapon of slaying) ***/
1101 if (IS_FLG(FLG_BOOSTED))
1103 before_str[before_n++] = "¥À¥á¡¼¥¸¥À¥¤¥¹¤¬Ä̾ï¤è¤êÂ礤¤";
1107 /*** Weapons whose dd*ds is more than nn ***/
1108 if (IS_FLG(FLG_MORE_THAN))
1110 static char more_than_desc_str[] = "___";
1111 before_str[before_n++] = "¥À¥á¡¼¥¸¥À¥¤¥¹¤ÎºÇÂçÃͤ¬";
1114 sprintf(more_than_desc_str,"%d", entry->dice);
1115 before_str[before_n++] = more_than_desc_str;
1116 before_str[before_n++] = "°Ê¾å¤Î";
1119 /*** Items whose magical bonus is more than nn ***/
1120 if (IS_FLG(FLG_MORE_BONUS))
1122 static char more_bonus_desc_str[] = "___";
1123 before_str[before_n++] = "½¤ÀµÃͤ¬(+";
1125 sprintf(more_bonus_desc_str,"%d", entry->bonus);
1126 before_str[before_n++] = more_bonus_desc_str;
1127 before_str[before_n++] = ")°Ê¾å¤Î";
1130 /*** Worthless items ***/
1131 if (IS_FLG(FLG_WORTHLESS))
1132 before_str[before_n++] = "Ź¤Ç̵²ÁÃͤÈȽÄꤵ¤ì¤ë";
1135 if (IS_FLG(FLG_ARTIFACT))
1137 before_str[before_n++] = "¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È¤Î";
1142 if (IS_FLG(FLG_EGO))
1144 before_str[before_n++] = "¥¨¥´¥¢¥¤¥Æ¥à¤Î";
1149 if (IS_FLG(FLG_NAMELESS))
1151 before_str[before_n++] = "¥¨¥´¤Ç¤â¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È¤Ç¤â¤Ê¤¤";
1155 /*** Unaware items ***/
1156 if (IS_FLG(FLG_UNAWARE))
1157 before_str[before_n++] = "̤´ÕÄê¤Ç¤½¤Î¸ú²Ì¤âȽÌÀ¤·¤Æ¤¤¤Ê¤¤";
1159 /*** Wanted monster's corpse/skeletons ***/
1160 if (IS_FLG(FLG_WANTED))
1162 before_str[before_n++] = "¥Ï¥ó¥¿¡¼»ö̳½ê¤Ç¾Þ¶â¼ó¤È¤µ¤ì¤Æ¤¤¤ë";
1163 body_str = "»àÂΤä¹ü";
1166 /*** Human corpse/skeletons (for Daemon magic) ***/
1167 if (IS_FLG(FLG_HUMAN))
1169 before_str[before_n++] = "°ËâËâË¡¤Ç»È¤¦¤¿¤á¤Î¿Í´Ö¤ä¥Ò¥å¡¼¥Þ¥Î¥¤¥É¤Î";
1170 body_str = "»àÂΤä¹ü";
1173 /*** Unique monster's corpse/skeletons/statues ***/
1174 if (IS_FLG(FLG_UNIQUE))
1176 before_str[before_n++] = "¥æ¥Ë¡¼¥¯¥â¥ó¥¹¥¿¡¼¤Î";
1177 body_str = "»àÂΤä¹ü";
1180 /*** Unreadable spellbooks ***/
1181 if (IS_FLG(FLG_UNREADABLE))
1183 before_str[before_n++] = "¤¢¤Ê¤¿¤¬Æɤá¤Ê¤¤Îΰè¤Î";
1184 body_str = "ËâË¡½ñ";
1187 /*** First realm spellbooks ***/
1188 if (IS_FLG(FLG_REALM1))
1190 before_str[before_n++] = "Âè°ìÎΰè¤Î";
1191 body_str = "ËâË¡½ñ";
1194 /*** Second realm spellbooks ***/
1195 if (IS_FLG(FLG_REALM2))
1197 before_str[before_n++] = "ÂèÆóÎΰè¤Î";
1198 body_str = "ËâË¡½ñ";
1201 /*** First rank spellbooks ***/
1202 if (IS_FLG(FLG_FIRST))
1204 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î1ºýÌܤÎ";
1205 body_str = "ËâË¡½ñ";
1208 /*** Second rank spellbooks ***/
1209 if (IS_FLG(FLG_SECOND))
1211 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î2ºýÌܤÎ";
1212 body_str = "ËâË¡½ñ";
1215 /*** Third rank spellbooks ***/
1216 if (IS_FLG(FLG_THIRD))
1218 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î3ºýÌܤÎ";
1219 body_str = "ËâË¡½ñ";
1222 /*** Fourth rank spellbooks ***/
1223 if (IS_FLG(FLG_FOURTH))
1225 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î4ºýÌܤÎ";
1226 body_str = "ËâË¡½ñ";
1230 if (IS_FLG(FLG_ITEMS))
1231 ; /* Nothing to do */
1232 else if (IS_FLG(FLG_WEAPONS))
1234 else if (IS_FLG(FLG_ARMORS))
1236 else if (IS_FLG(FLG_MISSILES))
1237 body_str = "ÃƤäÌð¤ä¥¯¥í¥¹¥Ü¥¦¤ÎÌð";
1238 else if (IS_FLG(FLG_DEVICES))
1239 body_str = "´¬Êª¤äËâË¡ËÀ¤ä¾ó¤ä¥í¥Ã¥É";
1240 else if (IS_FLG(FLG_LIGHTS))
1241 body_str = "¸÷¸»ÍѤΥ¢¥¤¥Æ¥à";
1242 else if (IS_FLG(FLG_JUNKS))
1243 body_str = "Àޤ줿ËÀÅù¤Î¥¬¥é¥¯¥¿";
1244 else if (IS_FLG(FLG_SPELLBOOKS))
1245 body_str = "ËâË¡½ñ";
1246 else if (IS_FLG(FLG_HAFTED))
1248 else if (IS_FLG(FLG_SHIELDS))
1250 else if (IS_FLG(FLG_BOWS))
1251 body_str = "¥¹¥ê¥ó¥°¤äµÝ¤ä¥¯¥í¥¹¥Ü¥¦";
1252 else if (IS_FLG(FLG_RINGS))
1254 else if (IS_FLG(FLG_AMULETS))
1255 body_str = "¥¢¥ß¥å¥ì¥Ã¥È";
1256 else if (IS_FLG(FLG_SUITS))
1258 else if (IS_FLG(FLG_CLOAKS))
1259 body_str = "¥¯¥í¡¼¥¯";
1260 else if (IS_FLG(FLG_HELMS))
1261 body_str = "¥Ø¥ë¥á¥Ã¥È¤ä´§";
1262 else if (IS_FLG(FLG_GLOVES))
1264 else if (IS_FLG(FLG_BOOTS))
1265 body_str = "¥Ö¡¼¥Ä";
1269 strcat(buff, "Á´¤Æ¤Î");
1270 else for (i = 0; i < before_n && before_str[i]; i++)
1271 strcat(buff, before_str[i]);
1273 strcat(buff, body_str);
1283 strcat(buff, "¤Ç¡¢Ì¾Á°¤¬¡Ö");
1284 strncat(buff, str, 80);
1286 strcat(buff, "¡×¤Ç»Ï¤Þ¤ë¤â¤Î");
1288 strcat(buff, "¡×¤ò´Þ¤à¤â¤Î");
1292 strncat(buff, format("¤Ë¡Ö%s¡×¤È¹ï¤ó¤Ç", insc), 80);
1296 if (act & DONT_AUTOPICK)
1297 strcat(buff, "ÊüÃÖ¤¹¤ë¡£");
1298 else if (act & DO_AUTODESTROY)
1299 strcat(buff, "Ç˲õ¤¹¤ë¡£");
1301 strcat(buff, "½¦¤¦¡£");
1303 if (act & DO_DISPLAY)
1305 if (act & DONT_AUTOPICK)
1306 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'N'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
1307 else if (act & DO_AUTODESTROY)
1308 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'K'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
1310 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'M'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
1313 strcat(buff, "Á´ÂΥޥåפˤÏɽ¼¨¤·¤Ê¤¤");
1317 cptr before_str[20], after_str[20], which_str[20], whose_str[20], body_str;
1318 int before_n = 0, after_n = 0, which_n = 0, whose_n = 0;
1322 /*** Collecting items ***/
1323 /*** Which can be absorbed into a slot as a bundle ***/
1324 if (IS_FLG(FLG_COLLECTING))
1325 which_str[which_n++] = "can be absorbed into an existing inventory slot";
1327 /*** Unidentified ***/
1328 if (IS_FLG(FLG_UNIDENTIFIED))
1329 before_str[before_n++] = "unidentified";
1331 /*** Identified ***/
1332 if (IS_FLG(FLG_IDENTIFIED))
1333 before_str[before_n++] = "identified";
1335 /*** *Identified* ***/
1336 if (IS_FLG(FLG_STAR_IDENTIFIED))
1337 before_str[before_n++] = "fully identified";
1339 /*** Worthless items ***/
1340 if (IS_FLG(FLG_WORTHLESS))
1342 before_str[before_n++] = "worthless";
1343 which_str[which_n++] = "can not be sold at stores";
1347 if (IS_FLG(FLG_ARTIFACT))
1349 before_str[before_n++] = "artifact";
1353 if (IS_FLG(FLG_EGO))
1355 before_str[before_n++] = "ego";
1359 if (IS_FLG(FLG_NAMELESS))
1361 body_str = "equipment";
1362 which_str[which_n++] = "is neither ego-item nor artifact";
1365 /*** Unaware items ***/
1366 if (IS_FLG(FLG_UNAWARE))
1368 before_str[before_n++] = "unidentified";
1369 whose_str[whose_n++] = "basic abilities are not known";
1372 /*** Dice boosted (weapon of slaying) ***/
1373 if (IS_FLG(FLG_BOOSTED))
1375 body_str = "weapons";
1376 whose_str[whose_n++] = "damage dice is bigger than normal";
1379 /*** Weapons whose dd*ds is more than nn ***/
1380 if (IS_FLG(FLG_MORE_THAN))
1382 static char more_than_desc_str[] =
1383 "maximum damage from dice is bigger than __";
1384 body_str = "weapons";
1386 sprintf(more_than_desc_str + sizeof(more_than_desc_str) - 3,
1388 whose_str[whose_n++] = more_than_desc_str;
1391 /*** Items whose magical bonus is more than nn ***/
1392 if (IS_FLG(FLG_MORE_BONUS))
1394 static char more_bonus_desc_str[] =
1395 "magical bonus is bigger than (+__)";
1397 sprintf(more_bonus_desc_str + sizeof(more_bonus_desc_str) - 4,
1398 "%d)", entry->bonus);
1399 whose_str[whose_n++] = more_bonus_desc_str;
1402 /*** Wanted monster's corpse/skeletons ***/
1403 if (IS_FLG(FLG_WANTED))
1405 body_str = "corpse or skeletons";
1406 which_str[which_n++] = "is wanted at the Hunter's Office";
1409 /*** Human corpse/skeletons (for Daemon magic) ***/
1410 if (IS_FLG(FLG_HUMAN))
1412 before_str[before_n++] = "humanoid";
1413 body_str = "corpse or skeletons";
1414 which_str[which_n++] = "can be used for Daemon magic";
1417 /*** Unique monster's corpse/skeletons/statues ***/
1418 if (IS_FLG(FLG_UNIQUE))
1420 before_str[before_n++] = "unique monster's";
1421 body_str = "corpse or skeletons";
1424 /*** Unreadable spellbooks ***/
1425 if (IS_FLG(FLG_UNREADABLE))
1427 body_str = "spellbooks";
1428 after_str[after_n++] = "of different realms from yours";
1431 /*** First realm spellbooks ***/
1432 if (IS_FLG(FLG_REALM1))
1434 body_str = "spellbooks";
1435 after_str[after_n++] = "of your first realm";
1438 /*** Second realm spellbooks ***/
1439 if (IS_FLG(FLG_REALM2))
1441 body_str = "spellbooks";
1442 after_str[after_n++] = "of your second realm";
1445 /*** First rank spellbooks ***/
1446 if (IS_FLG(FLG_FIRST))
1448 before_str[before_n++] = "first one of four";
1449 body_str = "spellbooks";
1452 /*** Second rank spellbooks ***/
1453 if (IS_FLG(FLG_SECOND))
1455 before_str[before_n++] = "second one of four";
1456 body_str = "spellbooks";
1459 /*** Third rank spellbooks ***/
1460 if (IS_FLG(FLG_THIRD))
1462 before_str[before_n++] = "third one of four";
1463 body_str = "spellbooks";
1466 /*** Fourth rank spellbooks ***/
1467 if (IS_FLG(FLG_FOURTH))
1469 before_str[before_n++] = "fourth one of four";
1470 body_str = "spellbooks";
1474 if (IS_FLG(FLG_ITEMS))
1475 ; /* Nothing to do */
1476 else if (IS_FLG(FLG_WEAPONS))
1477 body_str = "weapons";
1478 else if (IS_FLG(FLG_ARMORS))
1479 body_str = "armors";
1480 else if (IS_FLG(FLG_MISSILES))
1481 body_str = "shots, arrows or crossbow bolts";
1482 else if (IS_FLG(FLG_DEVICES))
1483 body_str = "scrolls, wands, staves or rods";
1484 else if (IS_FLG(FLG_LIGHTS))
1485 body_str = "light sources";
1486 else if (IS_FLG(FLG_JUNKS))
1487 body_str = "junk such as broken sticks";
1488 else if (IS_FLG(FLG_SPELLBOOKS))
1489 body_str = "spellbooks";
1490 else if (IS_FLG(FLG_HAFTED))
1491 body_str = "hafted weapons";
1492 else if (IS_FLG(FLG_SHIELDS))
1493 body_str = "shields";
1494 else if (IS_FLG(FLG_BOWS))
1495 body_str = "slings, bows or crossbows";
1496 else if (IS_FLG(FLG_RINGS))
1498 else if (IS_FLG(FLG_AMULETS))
1499 body_str = "amulets";
1500 else if (IS_FLG(FLG_SUITS))
1501 body_str = "body armors";
1502 else if (IS_FLG(FLG_CLOAKS))
1503 body_str = "cloaks";
1504 else if (IS_FLG(FLG_HELMS))
1505 body_str = "helms or crowns";
1506 else if (IS_FLG(FLG_GLOVES))
1507 body_str = "gloves";
1508 else if (IS_FLG(FLG_BOOTS))
1511 /* Prepare a string for item name */
1518 whose_str[whose_n++] = "name is beginning with \"";
1521 which_str[which_n++] = "have \"";
1525 /* Describe action flag */
1526 if (act & DONT_AUTOPICK)
1527 strcpy(buff, "Leave on floor ");
1528 else if (act & DO_AUTODESTROY)
1529 strcpy(buff, "Destroy ");
1531 strcpy(buff, "Pickup ");
1533 /* Auto-insctiption */
1535 strncat(buff, format("and inscribe \"%s\" on ", insc), 80);
1539 strcat(buff, "all ");
1540 else for (i = 0; i < before_n && before_str[i]; i++)
1542 strcat(buff, before_str[i]);
1547 strcat(buff, body_str);
1550 for (i = 0; i < after_n && after_str[i]; i++)
1553 strcat(buff, after_str[i]);
1557 for (i = 0; i < whose_n && whose_str[i]; i++)
1560 strcat(buff, " whose ");
1562 strcat(buff, ", and ");
1564 strcat(buff, whose_str[i]);
1567 /* Item name ; whose name is beginning with "str" */
1574 /* whose ..., and which .... */
1575 if (whose_n && which_n)
1576 strcat(buff, ", and ");
1579 for (i = 0; i < which_n && which_str[i]; i++)
1582 strcat(buff, " which ");
1584 strcat(buff, ", and ");
1586 strcat(buff, which_str[i]);
1589 /* Item name ; which have "str" as part of its name */
1592 strncat(buff, str, 80);
1593 strcat(buff, "\" as part of its name");
1597 /* Describe whether it will be displayed on the full map or not */
1598 if (act & DO_DISPLAY)
1600 if (act & DONT_AUTOPICK)
1601 strcat(buff, " Display these items when you press 'N' in the full map('M').");
1602 else if (act & DO_AUTODESTROY)
1603 strcat(buff, " Display these items when you press 'K' in the full map('M').");
1605 strcat(buff, " Display these items when you press 'M' in the full map('M').");
1608 strcat(buff, " Not displayed in the full map.");
1614 #define MAX_LINES 3000
1617 * Read whole lines of a file to memory
1619 static cptr *read_text_lines(cptr filename, bool user)
1621 cptr *lines_list = NULL;
1629 /* Hack -- drop permissions */
1631 path_build(buf, 1024, ANGBAND_DIR_USER, filename);
1635 path_build(buf, 1024, ANGBAND_DIR_PREF, filename);
1639 fff = my_fopen(buf, "r");
1643 /* Allocate list of pointers */
1644 C_MAKE(lines_list, MAX_LINES, cptr);
1647 while (0 == my_fgets(fff, buf, 1024))
1649 lines_list[lines++] = string_make(buf);
1650 if (lines >= MAX_LINES - 1) break;
1653 lines_list[0] = string_make("");
1661 if (!fff) return NULL;
1665 static cptr *read_pickpref_text_lines(void)
1671 sprintf(buf, "picktype-%s.prf", player_name);
1673 sprintf(buf, "pickpref-%s.prf", player_name);
1675 lines_list = read_text_lines(buf, TRUE);
1680 lines_list = read_text_lines("picktype.prf", TRUE);
1682 lines_list = read_text_lines("pickpref.prf", TRUE);
1689 lines_list = read_text_lines("picktype.prf", FALSE);
1691 lines_list = read_text_lines("pickpref.prf", FALSE);
1697 /* Allocate list of pointers */
1698 C_MAKE(lines_list, MAX_LINES, cptr);
1699 lines_list[0] = string_make("");
1705 * Write whole lines of memory to a file.
1707 static bool write_text_lines(cptr filename, cptr *lines_list)
1714 /* Hack -- drop permissions */
1717 /* Build the filename */
1718 path_build(buf, 1024, ANGBAND_DIR_USER, filename);
1721 fff = my_fopen(buf, "w");
1724 for (lines = 0; lines_list[lines]; lines++)
1725 my_fputs(fff, lines_list[lines], 1024);
1733 if (!fff) return FALSE;
1739 * Free memory of lines_list.
1741 static void free_text_lines(cptr *lines_list)
1745 for (lines = 0; lines_list[lines]; lines++)
1746 string_free(lines_list[lines]);
1748 /* free list of pointers */
1749 C_FREE((char **)lines_list, MAX_LINES, char *);
1754 * Delete or insert string
1756 static void toggle_string(cptr *lines_list, int flg, int y)
1758 autopick_type an_entry, *entry = &an_entry;
1760 if (!autopick_new_entry(entry, lines_list[y]))
1763 string_free(lines_list[y]);
1769 lines_list[y] = autopick_line_from_entry(entry);
1773 * Insert return code and split the line
1775 static bool insert_return_code(cptr *lines_list, int cx, int cy)
1780 for (k = 0; lines_list[k]; k++)
1781 /* count number of lines */ ;
1783 if (k >= MAX_LINES - 2) return FALSE;
1786 /* Move down lines */
1788 lines_list[k+1] = lines_list[k];
1790 /* Split current line */
1791 for (i = j = 0; lines_list[cy][i] && i < cx; i++)
1794 if (iskanji(lines_list[cy][i]))
1795 buf[j++] = lines_list[cy][i++];
1797 buf[j++] = lines_list[cy][i];
1800 lines_list[cy+1] = string_make(&lines_list[cy][i]);
1801 string_free(lines_list[cy]);
1802 lines_list[cy] = string_make(buf);
1808 * Get auto-picker entry from o_ptr.
1810 void autopick_entry_from_object(autopick_type *entry, object_type *o_ptr)
1812 char o_name[MAX_NLEN];
1813 object_desc(o_name, o_ptr, FALSE, 0);
1815 entry->name = string_make(o_name);
1816 entry->insc = string_make(quark_str(o_ptr->inscription));
1817 entry->action = DO_AUTOPICK | DO_DISPLAY;
1818 entry->flag[0] = entry->flag[1] = 0L;
1821 if (!object_aware_p(o_ptr))
1822 ADD_FLG(FLG_UNAWARE);
1823 if (object_value(o_ptr) <= 0)
1824 ADD_FLG(FLG_WORTHLESS);
1826 if (object_known_p(o_ptr))
1830 else if (o_ptr->name1 || o_ptr->art_name)
1831 ADD_FLG(FLG_ARTIFACT);
1837 case TV_HAFTED: case TV_POLEARM: case TV_SWORD: case TV_DIGGING:
1838 k_ptr = &k_info[o_ptr->k_idx];
1839 if ((o_ptr->dd != k_ptr->dd) || (o_ptr->ds != k_ptr->ds))
1840 ADD_FLG(FLG_BOOSTED);
1843 if (o_ptr->tval == TV_CORPSE && object_is_shoukinkubi(o_ptr))
1845 REM_FLG(FLG_WORTHLESS);
1846 ADD_FLG(FLG_WANTED);
1849 if ((o_ptr->tval == TV_CORPSE || o_ptr->tval == TV_STATUE)
1850 && (r_info[o_ptr->pval].flags1 & RF1_UNIQUE))
1852 REM_FLG(FLG_WORTHLESS);
1853 ADD_FLG(FLG_UNIQUE);
1856 if (o_ptr->tval == TV_CORPSE && strchr("pht", r_info[o_ptr->pval].d_char))
1858 REM_FLG(FLG_WORTHLESS);
1862 if (o_ptr->tval >= TV_LIFE_BOOK &&
1863 !check_book_realm(o_ptr->tval, o_ptr->sval))
1864 ADD_FLG(FLG_UNREADABLE);
1866 if (REALM1_BOOK == o_ptr->tval &&
1867 p_ptr->pclass != CLASS_SORCERER &&
1868 p_ptr->pclass != CLASS_RED_MAGE)
1869 ADD_FLG(FLG_REALM1);
1871 if (REALM2_BOOK == o_ptr->tval &&
1872 p_ptr->pclass != CLASS_SORCERER &&
1873 p_ptr->pclass != CLASS_RED_MAGE)
1874 ADD_FLG(FLG_REALM2);
1876 if (o_ptr->tval >= TV_LIFE_BOOK && 0 == o_ptr->sval)
1878 if (o_ptr->tval >= TV_LIFE_BOOK && 1 == o_ptr->sval)
1879 ADD_FLG(FLG_SECOND);
1880 if (o_ptr->tval >= TV_LIFE_BOOK && 2 == o_ptr->sval)
1882 if (o_ptr->tval >= TV_LIFE_BOOK && 3 == o_ptr->sval)
1883 ADD_FLG(FLG_FOURTH);
1885 if (o_ptr->tval == TV_SHOT || o_ptr->tval == TV_BOLT
1886 || o_ptr->tval == TV_ARROW)
1887 ADD_FLG(FLG_MISSILES);
1888 else if (o_ptr->tval == TV_SCROLL || o_ptr->tval == TV_STAFF
1889 || o_ptr->tval == TV_WAND || o_ptr->tval == TV_ROD)
1890 ADD_FLG(FLG_DEVICES);
1891 else if (o_ptr->tval == TV_LITE)
1892 ADD_FLG(FLG_LIGHTS);
1893 else if (o_ptr->tval == TV_SKELETON || o_ptr->tval == TV_BOTTLE
1894 || o_ptr->tval == TV_JUNK || o_ptr->tval == TV_STATUE)
1896 else if (o_ptr->tval >= TV_LIFE_BOOK)
1897 ADD_FLG(FLG_SPELLBOOKS);
1898 else if (o_ptr->tval == TV_HAFTED)
1899 ADD_FLG(FLG_HAFTED);
1900 else if (o_ptr->tval == TV_POLEARM || o_ptr->tval == TV_SWORD
1901 || o_ptr->tval == TV_DIGGING)
1902 ADD_FLG(FLG_WEAPONS);
1903 else if (o_ptr->tval == TV_SHIELD)
1904 ADD_FLG(FLG_SHIELDS);
1905 else if (o_ptr->tval == TV_BOW)
1907 else if (o_ptr->tval == TV_RING)
1909 else if (o_ptr->tval == TV_AMULET)
1910 ADD_FLG(FLG_AMULETS);
1911 else if (o_ptr->tval == TV_DRAG_ARMOR || o_ptr->tval == TV_HARD_ARMOR ||
1912 o_ptr->tval == TV_SOFT_ARMOR)
1914 else if (o_ptr->tval == TV_CLOAK)
1915 ADD_FLG(FLG_CLOAKS);
1916 else if (o_ptr->tval == TV_HELM)
1918 else if (o_ptr->tval == TV_GLOVES)
1919 ADD_FLG(FLG_GLOVES);
1920 else if (o_ptr->tval == TV_BOOTS)
1927 * Choose an item and get auto-picker entry from it.
1929 static bool entry_from_choosed_object(autopick_type *entry)
1937 q = "¤É¤Î¥¢¥¤¥Æ¥à¤òÅÐÏ¿¤·¤Þ¤¹¤«? ";
1938 s = "¥¢¥¤¥Æ¥à¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£";
1940 q = "Entry which item? ";
1941 s = "You have nothing to entry.";
1943 if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR | USE_EQUIP))) return FALSE;
1945 /* Get the item (in the pack) */
1948 o_ptr = &inventory[item];
1951 /* Get the item (on the floor) */
1954 o_ptr = &o_list[0 - item];
1957 autopick_entry_from_object(entry, o_ptr);
1963 * Initialize auto-picker preference
1965 void init_autopicker(void)
1967 static const char easy_autopick_inscription[] = "(:=g";
1968 autopick_type entry;
1971 /* Clear old entries */
1972 for( i = 0; i < max_autopick; i++)
1973 autopick_free_entry(&autopick_list[i]);
1977 /* There is always one entry "=g" */
1978 autopick_new_entry(&entry, easy_autopick_inscription);
1979 autopick_list[max_autopick++] = entry;
1984 * Description of control commands
1989 static cptr ctrl_command_desc[] =
1992 #define LAST_DESTROYED 6
1993 "^P ^N ^B ^F ¾å²¼º¸±¦¤Ë°ÜÆ°",
1994 "^A ^E ¹Ô¤ÎÀèƬ¡¢½ªÃ¼",
1995 "^Q ÆþÎÏ/¥³¥Þ¥ó¥É¥â¡¼¥ÉÀÚ¤êÂؤ¨",
1996 "^R Êѹ¹¤òÁ´¤Æ¼è¤ê¾Ã¤·¤Æ¸µ¤ËÌ᤹",
1997 "------------------------------------",
1998 "^I »ý¤Áʪ/ÁõÈ÷¤«¤éÁªÂò",
2000 "^K ¥«¡¼¥½¥ë¤«¤é½ªÃ¼¤Þ¤Çºï½ü",
2001 "^Y ºï½ü(^K)¤·¤¿¹Ô¤òÁÞÆþ",
2002 "^C ¼ï²¡¢¿¦¶È¤Î¾ò·ï¼°¤òÁÞÆþ",
2003 "------------------------------------",
2004 "^S Êѹ¹ (!Ç˲õ/~ÊüÃÖ/½¦¤¦)",
2005 "^G \"(\" Á´ÂΥޥåפÇɽ¼¨¤·¤Ê¤¤",
2006 "^O \"#\" ¼«Æ°¹ï¤ß",
2007 "------------------------------------",
2008 "^U ̤´ÕÄê/̤ȽÌÀ/´ÕÄê/*´ÕÄê*",
2010 "^X ̵ÌÃ/¥¨¥´/¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È",
2014 #define LAST_DESTROYED 6
2015 "^P ^N ^B ^F Move Cursor",
2016 "^A ^E Beginning and End of Line",
2017 "^Q Toggle Insert/Command mode",
2018 "^R Revert to Original File",
2019 "------------------------------------",
2020 "^I Object in Inventry/Equipment",
2022 "^K Kill Rest of Line",
2023 "^Y Insert killed(^K) text",
2024 "^C Insert conditional expression",
2025 "------------------------------------",
2026 "^S Toggle(!Destroy/~Leave/Pick)",
2027 "^G \"(\" No display in the 'M'ap",
2028 "^O \"#\" Auto-Inscribe",
2029 "------------------------------------",
2030 "^U Toggle 'identified' state",
2032 "^X Toggle nameless/ego/artifact",
2033 "^Z \"collecting\"",
2039 #define MAX_YANK 1024
2040 #define MAX_LINELEN 1024
2041 #define DIRTY_ALL 0x01
2042 #define DIRTY_COMMAND 0x02
2043 #define DIRTY_MODE 0x04
2044 #define DIRTY_SCREEN 0x04
2047 * In-game editor of Object Auto-picker/Destoryer
2049 void do_cmd_edit_autopick(void)
2051 static int cx = 0, cy = 0;
2052 static int upper = 0, left = 0;
2054 cptr last_destroyed;
2055 char last_destroyed_command[WID_DESC+3];
2056 char yank_buf[MAX_YANK];
2058 autopick_type an_entry, *entry = &an_entry;
2059 char buf[MAX_LINELEN];
2065 int old_upper = -1, old_left = -1;
2067 int key = -1, old_key;
2069 bool edit_mode = FALSE;
2071 byte dirty_flags = DIRTY_ALL | DIRTY_COMMAND | DIRTY_MODE;
2072 int dirty_line = -1;
2074 int wid, hgt, old_wid = -1, old_hgt = -1;
2076 /* Free old entries */
2079 /* Name of the Last Destroyed Item */
2080 last_destroyed = autopick_line_from_entry(&autopick_entry_last_destroyed);
2082 /* Command Description of the Last Destroyed Item */
2085 strcpy(last_destroyed_command, "^L \"");
2086 strncpy(last_destroyed_command + 4, last_destroyed, WID_DESC-4);
2087 last_destroyed_command[WID_DESC+2] = '\0';
2092 strcpy(last_destroyed_command, "^L ºÇ¸å¤Ë¼«Æ°Ç˲õ¤·¤¿¥¢¥¤¥Æ¥à̾");
2094 strcpy(last_destroyed_command, "^L Last destroyed object");
2097 ctrl_command_desc[LAST_DESTROYED] = last_destroyed_command;
2099 /* Conditional Expression for Class and Race */
2100 sprintf(classrace, "?:[AND [EQU $RACE %s] [EQU $CLASS %s]]",
2102 rp_ptr->E_title, cp_ptr->E_title
2104 rp_ptr->title, cp_ptr->title
2108 /* Clear yank buffer */
2111 /* Read or initialize whole text */
2112 lines_list = read_pickpref_text_lines();
2114 /* Reset cursor position if needed */
2115 for (i = 0; i < cy; i++)
2124 /* Save the screen */
2127 /* Process requests until done */
2131 Term_get_size(&wid, &hgt);
2134 /* Don't let cursor at second byte of kanji */
2135 for (i = 0; lines_list[cy][i]; i++)
2136 if (iskanji(lines_list[cy][i]))
2147 /* Scroll if necessary */
2148 if (cy < upper || upper + hgt - 4 <= cy)
2149 upper = cy - (hgt-4)/2;
2152 if ((cx < left + 10 && left > 0) || left + wid - WID_DESC - 5 <= cx)
2153 left = cx - (wid - WID_DESC)*2/3;
2157 /* Redraw whole window after resize */
2158 if (old_wid != wid || old_hgt != hgt)
2159 dirty_flags |= DIRTY_SCREEN;
2161 /* Redraw all text after scroll */
2162 else if (old_upper != upper || old_left != left)
2163 dirty_flags |= DIRTY_ALL;
2166 if (dirty_flags & DIRTY_SCREEN)
2168 dirty_flags = DIRTY_ALL | DIRTY_COMMAND | DIRTY_MODE;
2174 if (dirty_flags & DIRTY_COMMAND)
2176 /* Display control command */
2177 for (i = 0; ctrl_command_desc[i]; i++)
2178 Term_putstr(wid - WID_DESC, i + 1, WID_DESC, TERM_WHITE, ctrl_command_desc[i]);
2181 /* Redraw mode line */
2182 if (dirty_flags & DIRTY_MODE)
2184 int sepa_length = wid - WID_DESC;
2187 for (i = 0; i < sepa_length; i++)
2193 strncpy(buf + sepa_length - 21, " (INSERT MODE) ", 16);
2195 strncpy(buf + sepa_length - 21, " (COMMAND MODE) ", 16);
2197 Term_putstr(0, hgt - 3, sepa_length, (byte) (edit_mode ? TERM_YELLOW : TERM_WHITE), buf);
2200 /* Dump up to 20, or hgt-4, lines of messages */
2201 for (i = 0; i < hgt - 4; i++)
2206 /* clean or dirty? */
2207 if (!(dirty_flags & DIRTY_ALL) && (dirty_line != upper+i))
2210 msg = lines_list[upper+i];
2213 /* Apply horizontal scroll */
2214 for (j = 0; *msg; msg++, j++)
2216 if (j == left) break;
2232 Term_erase(0, i + 1, wid - WID_DESC);
2234 /* Dump the messages, bottom to top */
2235 Term_putstr(leftcol, i + 1, wid - WID_DESC - 1, TERM_WHITE, msg);
2238 for (; i < hgt - 4; i++)
2241 Term_erase(0, i + 1, wid - WID_DESC);
2244 /* Display header line */
2247 prt("^Q ESC ¤Ç¥³¥Þ¥ó¥É¥â¡¼¥É¤Ø°Ü¹Ô¡¢Ä̾ï¤Îʸ»ú¤Ï¤½¤Î¤Þ¤ÞÆþÎÏ", 0, 0);
2249 prt("q _ ¤Ç½ªÎ»¡¢hjkl2468 ¤Ç°ÜÆ°¡¢^Q a i ¤ÇÆþÎϥ⡼¥É", 0, 0);
2252 prt("Press ^Q ESC to command mode, any letters to insert", 0, 0);
2254 prt("Press q _ to quit, hjkl2468 to move, ^Q a i to insert mode", 0, 0);
2256 /* Display current position */
2257 prt (format("(%d,%d)", cx, cy), 0, 70);
2259 /* Display information when updated */
2260 if (old_cy != cy || (dirty_flags & DIRTY_ALL) || dirty_line == cy)
2262 /* Clear information line */
2263 Term_erase(0, hgt - 3 + 1, wid);
2264 Term_erase(0, hgt - 3 + 2, wid);
2266 /* Display information */
2267 if (lines_list[cy][0] == '#')
2270 prt("¤³¤Î¹Ô¤Ï¥³¥á¥ó¥È¤Ç¤¹¡£", hgt - 3 + 1, 0);
2272 prt("This line is comment.", hgt - 3 + 1, 0);
2275 else if (lines_list[cy][1] == ':')
2277 switch(lines_list[cy][0])
2281 prt("¤³¤Î¹Ô¤Ï¾ò·ïʬ´ô¼°¤Ç¤¹¡£", hgt - 3 + 1, 0);
2283 prt("This line is Conditional Expression.", hgt - 3 + 1, 0);
2288 prt("¤³¤Î¹Ô¤Ï¥Þ¥¯¥í¤Î¼Â¹ÔÆâÍƤòÄêµÁ¤·¤Þ¤¹¡£", hgt - 3 + 1, 0);
2290 prt("This line defines Macro action.", hgt - 3 + 1, 0);
2295 prt("¤³¤Î¹Ô¤Ï¥Þ¥¯¥í¤Î¥È¥ê¥¬¡¼¡¦¥¡¼¤òÄêµÁ¤·¤Þ¤¹¡£", hgt - 3 + 1, 0);
2297 prt("This line defines Macro trigger key.", hgt - 3 + 1, 0);
2302 prt("¤³¤Î¹Ô¤Ï¥¡¼ÇÛÃÖ¤òÄêµÁ¤·¤Þ¤¹¡£", hgt - 3 + 1, 0);
2304 prt("This line defines Keymap.", hgt - 3 + 1, 0);
2310 /* Get description of an autopicker preference line */
2311 else if (autopick_new_entry(entry, lines_list[cy]))
2316 describe_autopick(buf, entry);
2318 roff_to_buf(buf, 81, temp);
2320 for (i = 0; i< 2; i++)
2326 prt(t, hgt - 3 + 1 + i, 0);
2330 autopick_free_entry(entry);
2335 Term_gotoxy(cx - left, cy - upper + 1);
2341 /* Save old key and location */
2349 /* Do not process macros except special keys */
2350 inkey_special = TRUE;
2361 /* Mode line is now dirty */
2362 dirty_flags |= DIRTY_MODE;
2365 /* Insert a character */
2366 else if (!iscntrl(key&0xff))
2370 /* Save preceding string */
2371 for (i = j = 0; lines_list[cy][i] && i < cx; i++)
2372 buf[j++] = lines_list[cy][i];
2374 /* Add a character */
2380 if (j+2 < MAX_LINELEN)
2392 if (j+1 < MAX_LINELEN)
2398 for (; lines_list[cy][i] && j + 1 < MAX_LINELEN; i++)
2399 buf[j++] = lines_list[cy][i];
2402 /* Replace current line with new line */
2403 string_free(lines_list[cy]);
2404 lines_list[cy] = string_make(buf);
2406 /* Move to correct collumn */
2407 len = strlen(lines_list[cy]);
2408 if (len < cx) cx = len;
2417 if (key == 'q' || key == '_') break;
2424 /* Mode line is now dirty */
2425 dirty_flags |= DIRTY_MODE;
2428 if (!autopick_new_entry(entry, lines_list[cy]))
2430 string_free(lines_list[cy]);
2432 entry->action &= ~DO_AUTODESTROY;
2433 if (entry->action & DO_AUTOPICK)
2435 entry->action &= ~DO_AUTOPICK;
2436 entry->action |= DONT_AUTOPICK;
2440 entry->action &= ~DONT_AUTOPICK;
2441 entry->action |= DO_AUTOPICK;
2444 lines_list[cy] = autopick_line_from_entry(entry);
2450 if (!autopick_new_entry(entry, lines_list[cy]))
2452 string_free(lines_list[cy]);
2454 entry->action &= ~DONT_AUTOPICK;
2455 if (entry->action & DO_AUTOPICK)
2457 entry->action &= ~DO_AUTOPICK;
2458 entry->action |= DO_AUTODESTROY;
2462 entry->action &= ~DO_AUTODESTROY;
2463 entry->action |= DO_AUTOPICK;
2466 lines_list[cy] = autopick_line_from_entry(entry);
2491 while (cy < upper + hgt-4 && lines_list[cy + 1])
2496 while (0 < cy && upper <= cy)
2498 while (0 < upper && cy + 1 < upper + hgt - 4)
2507 /* Beginning of line */
2515 len = strlen(lines_list[cy]);
2516 if (len < cx) cx = len;
2521 cx = strlen(lines_list[cy]);
2525 /* Insert a conditinal expression line */
2526 insert_return_code(lines_list, 0, cy);
2527 lines_list[cy] = string_make(classrace);
2529 insert_return_code(lines_list, 0, cy);
2530 lines_list[cy] = string_make("?:1");
2534 dirty_flags |= DIRTY_ALL;
2538 cx = strlen(lines_list[cy]);
2543 if (iskanji(lines_list[cy][cx])) cx++;
2546 len = strlen(lines_list[cy]);
2549 if (lines_list[cy + 1])
2559 /* Toggle display on the 'M'ap */
2560 if (!autopick_new_entry(entry, lines_list[cy]))
2562 string_free(lines_list[cy]);
2564 if (entry->action & DO_DISPLAY)
2566 entry->action &= ~DO_DISPLAY;
2571 entry->action |= DO_DISPLAY;
2575 lines_list[cy] = autopick_line_from_entry(entry);
2581 /* Insert choosen item name */
2582 if (!entry_from_choosed_object(entry))
2584 /* Now dirty because of item/equip menu */
2585 dirty_flags |= DIRTY_SCREEN;
2588 tmp = autopick_line_from_entry(entry);
2589 autopick_free_entry(entry);
2592 insert_return_code(lines_list, 0, cy);
2593 lines_list[cy] = tmp;
2596 /* Now dirty because of item/equip menu */
2597 dirty_flags |= DIRTY_SCREEN;
2601 /* Insert a name of last destroyed item */
2604 insert_return_code(lines_list, 0, cy);
2605 lines_list[cy] = string_make(last_destroyed);
2609 dirty_flags |= DIRTY_ALL;
2612 case '\n': case '\r':
2613 /* Split a line or insert end of line */
2614 insert_return_code(lines_list, cx, cy);
2619 dirty_flags |= DIRTY_ALL;
2623 if (lines_list[cy + 1]) cy++;
2626 /* Prepare to write auto-inscription text */
2627 if (!autopick_new_entry(entry, lines_list[cy]))
2629 string_free(lines_list[cy]);
2631 if (!entry->insc) entry->insc = string_make("");
2633 lines_list[cy] = autopick_line_from_entry(entry);
2635 /* Move to collumn for auto inscription */
2636 for (cx = 0; lines_list[cy][cx]; cx++)
2637 if (lines_list[cy][cx] == '#') break;
2643 dirty_flags |= DIRTY_MODE;
2651 edit_mode = !edit_mode;
2653 /* Mode line is now dirty */
2654 dirty_flags |= DIRTY_MODE;
2657 /* Revert to original */
2659 if (!get_check("Á´¤Æ¤ÎÊѹ¹¤òÇË´þ¤·¤Æ¸µ¤Î¾õÂÖ¤ËÌᤷ¤Þ¤¹¡£¤è¤í¤·¤¤¤Ç¤¹¤«¡© "))
2661 if (!get_check("Discard all change and revert to original file. Are you sure? "))
2665 free_text_lines(lines_list);
2666 lines_list = read_pickpref_text_lines();
2667 dirty_flags |= DIRTY_ALL | DIRTY_MODE;
2672 /* Rotate action; pickup/destroy/leave */
2673 if (!autopick_new_entry(entry, lines_list[cy]))
2675 string_free(lines_list[cy]);
2677 if (entry->action & DO_AUTOPICK)
2679 entry->action &= ~DO_AUTOPICK;
2680 entry->action |= DO_AUTODESTROY;
2682 else if (entry->action & DO_AUTODESTROY)
2684 entry->action &= ~DO_AUTODESTROY;
2685 entry->action |= DONT_AUTOPICK;
2687 else if (entry->action & DONT_AUTOPICK)
2689 entry->action &= ~DONT_AUTOPICK;
2690 entry->action |= DO_AUTOPICK;
2693 lines_list[cy] = autopick_line_from_entry(entry);
2702 /* Rotate identify-state; identified/unidentified/... */
2703 if (!autopick_new_entry(entry, lines_list[cy]))
2705 string_free(lines_list[cy]);
2707 if (IS_FLG(FLG_UNIDENTIFIED))
2709 REM_FLG(FLG_UNIDENTIFIED);
2710 ADD_FLG(FLG_UNAWARE);
2711 REM_FLG(FLG_IDENTIFIED);
2712 REM_FLG(FLG_STAR_IDENTIFIED);
2714 else if (IS_FLG(FLG_UNAWARE))
2716 REM_FLG(FLG_UNIDENTIFIED);
2717 REM_FLG(FLG_UNAWARE);
2718 ADD_FLG(FLG_IDENTIFIED);
2719 REM_FLG(FLG_STAR_IDENTIFIED);
2721 else if (IS_FLG(FLG_STAR_IDENTIFIED))
2723 REM_FLG(FLG_UNIDENTIFIED);
2724 REM_FLG(FLG_UNAWARE);
2725 REM_FLG(FLG_IDENTIFIED);
2726 REM_FLG(FLG_STAR_IDENTIFIED);
2728 else if (IS_FLG(FLG_IDENTIFIED))
2730 REM_FLG(FLG_UNIDENTIFIED);
2731 REM_FLG(FLG_UNAWARE);
2732 REM_FLG(FLG_IDENTIFIED);
2733 ADD_FLG(FLG_STAR_IDENTIFIED);
2737 ADD_FLG(FLG_UNIDENTIFIED);
2738 REM_FLG(FLG_UNAWARE);
2739 REM_FLG(FLG_IDENTIFIED);
2740 REM_FLG(FLG_STAR_IDENTIFIED);
2743 lines_list[cy] = autopick_line_from_entry(entry);
2750 while (cy < upper + hgt-4 && lines_list[cy + 1])
2755 /* Toggle 'worthless' */
2756 toggle_string(lines_list, FLG_WORTHLESS, cy);
2761 /* Rotate within nameless, ego, artifact */
2762 if (!autopick_new_entry(entry, lines_list[cy]))
2764 string_free(lines_list[cy]);
2766 if (IS_FLG(FLG_NAMELESS))
2768 REM_FLG(FLG_NAMELESS);
2770 REM_FLG(FLG_ARTIFACT);
2772 else if (IS_FLG(FLG_EGO))
2774 REM_FLG(FLG_NAMELESS);
2776 ADD_FLG(FLG_ARTIFACT);
2778 else if (IS_FLG(FLG_ARTIFACT))
2780 REM_FLG(FLG_NAMELESS);
2782 REM_FLG(FLG_ARTIFACT);
2786 ADD_FLG(FLG_NAMELESS);
2788 REM_FLG(FLG_ARTIFACT);
2791 lines_list[cy] = autopick_line_from_entry(entry);
2798 /* Paste killed text */
2799 if (strlen(yank_buf))
2801 for (j = 0; yank_buf[j]; j += strlen(yank_buf + j) + 1)
2805 /* Split current line */
2806 insert_return_code(lines_list, cx, cy);
2808 /* Paste yank buffer */
2809 for(i = 0; lines_list[cy][i]; i++)
2810 buf[i] = lines_list[cy][i];
2811 while (yank_buf[k] && i < MAX_LINELEN)
2812 buf[i++] = yank_buf[k++];
2815 string_free(lines_list[cy]);
2816 lines_list[cy] = string_make(buf);
2818 /* Move to the beggining of next line */
2824 dirty_flags |= DIRTY_ALL;
2828 /* Toggle 'collecting' */
2829 toggle_string(lines_list, FLG_COLLECTING, cy);
2835 /* Kill rest of line */
2836 if (lines_list[cy][0] != '\0' && (uint)cx < strlen(lines_list[cy]))
2838 /* Save preceding string */
2839 for (i = 0; lines_list[cy][i] && i < cx; i++)
2842 if (iskanji(lines_list[cy][i]))
2844 buf[i] = lines_list[cy][i];
2848 buf[i] = lines_list[cy][i];
2853 if (old_key == KTRL('k'))
2855 j += strlen(yank_buf + j) + 1;
2857 /* Copy following to yank buffer */
2858 while (lines_list[cy][i] && j < MAX_YANK - 2)
2859 yank_buf[j++] = lines_list[cy][i++];
2860 yank_buf[j++] = '\0';
2863 /* Replace current line with 'preceding string' */
2864 string_free(lines_list[cy]);
2865 lines_list[cy] = string_make(buf);
2874 /* DELETE == go forward + BACK SPACE */
2876 if (iskanji(lines_list[cy][cx])) cx++;
2884 len = strlen(lines_list[cy]);
2887 if (lines_list[cy + 1])
2901 /* delete a return code and union two lines */
2903 cx = strlen(lines_list[cy-1]);
2904 strcpy(buf, lines_list[cy-1]);
2905 strcat(buf, lines_list[cy]);
2906 string_free(lines_list[cy-1]);
2907 string_free(lines_list[cy]);
2908 lines_list[cy-1] = string_make(buf);
2909 for (i = cy; lines_list[i+1]; i++)
2910 lines_list[i] = lines_list[i+1];
2911 lines_list[i] = NULL;
2915 dirty_flags |= DIRTY_ALL;
2919 for (i = j = 0; lines_list[cy][i] && i < cx; i++)
2923 if (iskanji(lines_list[cy][i]))
2924 buf[j++] = lines_list[cy][i++];
2926 buf[j++] = lines_list[cy][i];
2933 for (; lines_list[cy][i]; i++)
2934 buf[j++] = lines_list[cy][i];
2936 string_free(lines_list[cy]);
2937 lines_list[cy] = string_make(buf);
2946 /* Restore the screen */
2950 sprintf(buf, "picktype-%s.prf", player_name);
2952 sprintf(buf, "pickpref-%s.prf", player_name);
2954 write_text_lines(buf, lines_list);
2955 free_text_lines(lines_list);
2957 string_free(last_destroyed);
2959 /* Reload autopick pref */
2960 process_pickpref_file(buf);