3 /* Purpose: Object Auto-picker/Destroyer */
6 * Copyright (c) 2002 Mogami
8 * This software may be copied and distributed for educational, research, and
9 * not for profit purposes provided that this copyright and statement are
10 * included in all such copies.
15 #define MAX_LINELEN 1024
17 static object_type autopick_last_destroyed_object;
23 #define FLG_COLLECTING 1
24 #define FLG_UNIDENTIFIED 2
25 #define FLG_IDENTIFIED 3
26 #define FLG_STAR_IDENTIFIED 4
28 #define FLG_MORE_THAN 6
30 #define FLG_MORE_BONUS 8
31 #define FLG_MORE_BONUS2 9
32 #define FLG_WORTHLESS 10
33 #define FLG_ARTIFACT 11
35 #define FLG_NAMELESS 13
36 #define FLG_UNAWARE 14
40 #define FLG_UNREADABLE 18
49 #define FLG_WEAPONS 31
51 #define FLG_MISSILES 33
52 #define FLG_DEVICES 34
55 #define FLG_SPELLBOOKS 37
57 #define FLG_SHIELDS 39
60 #define FLG_AMULETS 42
69 #define KEY_ALL "¤¹¤Ù¤Æ¤Î"
70 #define KEY_COLLECTING "¼ý½¸Ãæ¤Î"
71 #define KEY_UNIDENTIFIED "̤´ÕÄê¤Î"
72 #define KEY_IDENTIFIED "´ÕÄêºÑ¤ß¤Î"
73 #define KEY_STAR_IDENTIFIED "*´ÕÄê*ºÑ¤ß¤Î"
74 #define KEY_BOOSTED "¥À¥¤¥¹Ìܤΰ㤦"
75 #define KEY_MORE_THAN "¥À¥¤¥¹ÌÜ"
76 #define KEY_DICE "°Ê¾å¤Î"
77 #define KEY_MORE_BONUS "½¤ÀµÃͤ¬"
78 #define KEY_MORE_BONUS2 "°Ê¾å¤Î"
79 #define KEY_WORTHLESS "̵²ÁÃͤÎ"
80 #define KEY_ARTIFACT "¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È"
81 #define KEY_EGO "¥¨¥´"
82 #define KEY_NAMELESS "̵ÌäÎ"
83 #define KEY_UNAWARE "̤ȽÌÀ¤Î"
84 #define KEY_WANTED "¾Þ¶â¼ó¤Î"
85 #define KEY_UNIQUE "¥æ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼¤Î"
86 #define KEY_HUMAN "¿Í´Ö¤Î"
87 #define KEY_UNREADABLE "Æɤá¤Ê¤¤"
88 #define KEY_REALM1 "Âè°ìÎΰè¤Î"
89 #define KEY_REALM2 "ÂèÆóÎΰè¤Î"
90 #define KEY_FIRST "1ºýÌܤÎ"
91 #define KEY_SECOND "2ºýÌܤÎ"
92 #define KEY_THIRD "3ºýÌܤÎ"
93 #define KEY_FOURTH "4ºýÌܤÎ"
94 #define KEY_ITEMS "¥¢¥¤¥Æ¥à"
95 #define KEY_WEAPONS "Éð´ï"
96 #define KEY_ARMORS "Ëɶñ"
97 #define KEY_MISSILES "Ìð"
98 #define KEY_DEVICES "ËâË¡¥¢¥¤¥Æ¥à"
99 #define KEY_LIGHTS "¸÷¸»"
100 #define KEY_JUNKS "¤¬¤é¤¯¤¿"
101 #define KEY_SPELLBOOKS "ËâË¡½ñ"
102 #define KEY_HAFTED "Æß´ï"
103 #define KEY_SHIELDS "½â"
104 #define KEY_BOWS "µÝ"
105 #define KEY_RINGS "»ØÎØ"
106 #define KEY_AMULETS "¥¢¥ß¥å¥ì¥Ã¥È"
107 #define KEY_SUITS "³»"
108 #define KEY_CLOAKS "¥¯¥í¡¼¥¯"
109 #define KEY_HELMS "³õ"
110 #define KEY_GLOVES "äƼê"
111 #define KEY_BOOTS "·¤"
115 #define KEY_ALL "all"
116 #define KEY_COLLECTING "collecting"
117 #define KEY_UNIDENTIFIED "unidentified"
118 #define KEY_IDENTIFIED "identified"
119 #define KEY_STAR_IDENTIFIED "*identified*"
120 #define KEY_BOOSTED "dice boosted"
121 #define KEY_MORE_THAN "more than"
122 #define KEY_DICE " dice"
123 #define KEY_MORE_BONUS "more bonus than"
124 #define KEY_MORE_BONUS2 ""
125 #define KEY_WORTHLESS "worthless"
126 #define KEY_ARTIFACT "artifact"
127 #define KEY_EGO "ego"
128 #define KEY_NAMELESS "nameless"
129 #define KEY_UNAWARE "unaware"
130 #define KEY_WANTED "wanted"
131 #define KEY_UNIQUE "unique monster's"
132 #define KEY_HUMAN "human"
133 #define KEY_UNREADABLE "unreadable"
134 #define KEY_REALM1 "first realm's"
135 #define KEY_REALM2 "second realm's"
136 #define KEY_FIRST "first"
137 #define KEY_SECOND "second"
138 #define KEY_THIRD "third"
139 #define KEY_FOURTH "fourth"
140 #define KEY_ITEMS "items"
141 #define KEY_WEAPONS "weapons"
142 #define KEY_ARMORS "armors"
143 #define KEY_MISSILES "missiles"
144 #define KEY_DEVICES "magical devices"
145 #define KEY_LIGHTS "lights"
146 #define KEY_JUNKS "junks"
147 #define KEY_SPELLBOOKS "spellbooks"
148 #define KEY_HAFTED "hafted weapons"
149 #define KEY_SHIELDS "shields"
150 #define KEY_BOWS "bows"
151 #define KEY_RINGS "rings"
152 #define KEY_AMULETS "amulets"
153 #define KEY_SUITS "suits"
154 #define KEY_CLOAKS "cloaks"
155 #define KEY_HELMS "helms"
156 #define KEY_GLOVES "gloves"
157 #define KEY_BOOTS "boots"
161 #define MATCH_KEY(KEY) (!strncmp(ptr, KEY, sizeof(KEY)-1)\
162 ? (ptr += sizeof(KEY)-1, (' '==*ptr) ? ptr++ : 0, TRUE) : FALSE)
163 #define MATCH_KEY2(KEY) (!strncmp(ptr, KEY, sizeof(KEY)-1)\
164 ? (prev_ptr = ptr, ptr += sizeof(KEY)-1, (' '==*ptr) ? ptr++ : 0, TRUE) : FALSE)
167 #define ADD_KEY(KEY) strcat(ptr, KEY)
169 #define ADD_KEY(KEY) (strcat(ptr, KEY), strcat(ptr, " "))
171 #define ADD_KEY2(KEY) strcat(ptr, KEY)
173 #define ADD_FLG(FLG) (entry->flag[FLG / 32] |= (1L << (FLG % 32)))
174 #define REM_FLG(FLG) (entry->flag[FLG / 32] &= ~(1L << (FLG % 32)))
175 #define ADD_FLG_NOUN(FLG) (ADD_FLG(FLG), prev_flg = FLG)
176 #define IS_FLG(FLG) (entry->flag[FLG / 32] & (1L << (FLG % 32)))
179 static char kanji_colon[] = "¡§";
184 * Reconstruct preference line from entry
186 cptr autopick_line_from_entry(autopick_type *entry)
188 char buf[MAX_LINELEN];
190 bool sepa_flag = TRUE;
193 if (!(entry->action & DO_DISPLAY)) strcat(buf, "(");
194 if (entry->action & DO_AUTODESTROY) strcat(buf, "!");
195 if (entry->action & DONT_AUTOPICK) strcat(buf, "~");
199 if (IS_FLG(FLG_ALL)) ADD_KEY(KEY_ALL);
200 if (IS_FLG(FLG_COLLECTING)) ADD_KEY(KEY_COLLECTING);
201 if (IS_FLG(FLG_UNIDENTIFIED)) ADD_KEY(KEY_UNIDENTIFIED);
202 if (IS_FLG(FLG_IDENTIFIED)) ADD_KEY(KEY_IDENTIFIED);
203 if (IS_FLG(FLG_STAR_IDENTIFIED)) ADD_KEY(KEY_STAR_IDENTIFIED);
204 if (IS_FLG(FLG_UNAWARE)) ADD_KEY(KEY_UNAWARE);
205 if (IS_FLG(FLG_BOOSTED)) ADD_KEY(KEY_BOOSTED);
207 if (IS_FLG(FLG_MORE_THAN))
209 ADD_KEY(KEY_MORE_THAN);
210 strcat(ptr, format("%d", entry->dice));
214 if (IS_FLG(FLG_MORE_BONUS))
216 ADD_KEY(KEY_MORE_BONUS);
217 strcat(ptr, format("%d", entry->bonus));
218 ADD_KEY(KEY_MORE_BONUS2);
221 if (IS_FLG(FLG_UNREADABLE)) ADD_KEY(KEY_UNREADABLE);
222 if (IS_FLG(FLG_REALM1)) ADD_KEY(KEY_REALM1);
223 if (IS_FLG(FLG_REALM2)) ADD_KEY(KEY_REALM2);
224 if (IS_FLG(FLG_FIRST)) ADD_KEY(KEY_FIRST);
225 if (IS_FLG(FLG_SECOND)) ADD_KEY(KEY_SECOND);
226 if (IS_FLG(FLG_THIRD)) ADD_KEY(KEY_THIRD);
227 if (IS_FLG(FLG_FOURTH)) ADD_KEY(KEY_FOURTH);
228 if (IS_FLG(FLG_WANTED)) ADD_KEY(KEY_WANTED);
229 if (IS_FLG(FLG_UNIQUE)) ADD_KEY(KEY_UNIQUE);
230 if (IS_FLG(FLG_HUMAN)) ADD_KEY(KEY_HUMAN);
231 if (IS_FLG(FLG_WORTHLESS)) ADD_KEY(KEY_WORTHLESS);
232 if (IS_FLG(FLG_NAMELESS)) ADD_KEY(KEY_NAMELESS);
233 if (IS_FLG(FLG_ARTIFACT)) ADD_KEY(KEY_ARTIFACT);
234 if (IS_FLG(FLG_EGO)) ADD_KEY(KEY_EGO);
236 if (IS_FLG(FLG_ITEMS)) ADD_KEY2(KEY_ITEMS);
237 else if (IS_FLG(FLG_WEAPONS)) ADD_KEY2(KEY_WEAPONS);
238 else if (IS_FLG(FLG_ARMORS)) ADD_KEY2(KEY_ARMORS);
239 else if (IS_FLG(FLG_MISSILES)) ADD_KEY2(KEY_MISSILES);
240 else if (IS_FLG(FLG_DEVICES)) ADD_KEY2(KEY_DEVICES);
241 else if (IS_FLG(FLG_LIGHTS)) ADD_KEY2(KEY_LIGHTS);
242 else if (IS_FLG(FLG_JUNKS)) ADD_KEY2(KEY_JUNKS);
243 else if (IS_FLG(FLG_SPELLBOOKS)) ADD_KEY2(KEY_SPELLBOOKS);
244 else if (IS_FLG(FLG_HAFTED)) ADD_KEY2(KEY_HAFTED);
245 else if (IS_FLG(FLG_SHIELDS)) ADD_KEY2(KEY_SHIELDS);
246 else if (IS_FLG(FLG_BOWS)) ADD_KEY2(KEY_BOWS);
247 else if (IS_FLG(FLG_RINGS)) ADD_KEY2(KEY_RINGS);
248 else if (IS_FLG(FLG_AMULETS)) ADD_KEY2(KEY_AMULETS);
249 else if (IS_FLG(FLG_SUITS)) ADD_KEY2(KEY_SUITS);
250 else if (IS_FLG(FLG_CLOAKS)) ADD_KEY2(KEY_CLOAKS);
251 else if (IS_FLG(FLG_HELMS)) ADD_KEY2(KEY_HELMS);
252 else if (IS_FLG(FLG_GLOVES)) ADD_KEY2(KEY_GLOVES);
253 else if (IS_FLG(FLG_BOOTS)) ADD_KEY2(KEY_BOOTS);
257 if (entry->name && entry->name[0])
261 if (sepa_flag) strcat(buf, ":");
264 while (entry->name[j] && i < MAX_LINELEN - 2 - 1)
267 if (iskanji(entry->name[j]))
268 buf[i++] = entry->name[j++];
270 buf[i++] = entry->name[j++];
276 if (entry->flag[0] == 0L && entry->flag[0] == 0L)
286 while (entry->insc[j] && i < MAX_LINELEN - 2)
289 if (iskanji(entry->insc[j]))
290 buf[i++] = entry->insc[j++];
292 buf[i++] = entry->insc[j++];
297 /* Free memory for original entry */
298 autopick_free_entry(entry);
300 return string_make(buf);
304 * A function to create new entry
306 bool autopick_new_entry(autopick_type *entry, cptr str)
311 char buf[MAX_LINELEN];
312 cptr prev_ptr, ptr, old_ptr;
315 if (str[1] == ':') switch (str[0])
318 case 'A': case 'P': case 'C':
322 entry->flag[0] = entry->flag[1] = 0L;
325 act = DO_AUTOPICK | DO_DISPLAY;
328 if ((act & DO_AUTOPICK) && *str == '!')
331 act |= DO_AUTODESTROY;
334 else if ((act & DO_AUTOPICK) && *str == '~')
337 act |= DONT_AUTOPICK;
340 else if ((act & DO_DISPLAY) && *str == '(')
349 /* don't mind upper or lower case */
351 for (i = 0; *str; i++)
362 /* Auto-inscription? */
370 if (isupper(c)) c = tolower(c);
376 /* Skip empty line */
377 if (*buf == 0) return FALSE;
382 while (old_ptr != ptr)
384 /* Save current location */
387 if (MATCH_KEY(KEY_ALL)) ADD_FLG(FLG_ALL);
388 if (MATCH_KEY(KEY_COLLECTING)) ADD_FLG(FLG_COLLECTING);
389 if (MATCH_KEY(KEY_UNIDENTIFIED)) ADD_FLG(FLG_UNIDENTIFIED);
390 if (MATCH_KEY(KEY_IDENTIFIED)) ADD_FLG(FLG_IDENTIFIED);
391 if (MATCH_KEY(KEY_STAR_IDENTIFIED)) ADD_FLG(FLG_STAR_IDENTIFIED);
392 if (MATCH_KEY(KEY_BOOSTED)) ADD_FLG(FLG_BOOSTED);
394 /*** Weapons whose dd*ds is more than nn ***/
395 if (MATCH_KEY2(KEY_MORE_THAN))
400 /* Drop leading spaces */
401 while (' ' == *ptr) ptr++;
404 while (isdigit(*ptr))
406 entry->dice = 10 * entry->dice + (*ptr - '0');
413 (void)MATCH_KEY(KEY_DICE);
414 ADD_FLG(FLG_MORE_THAN);
420 /*** Items whose magical bonus is more than n ***/
421 if (MATCH_KEY2(KEY_MORE_BONUS))
426 /* Drop leading spaces */
427 while (' ' == *ptr) ptr++;
430 while (isdigit(*ptr))
432 entry->bonus = 10 * entry->bonus + (*ptr - '0');
439 (void)MATCH_KEY(KEY_MORE_BONUS2);
440 ADD_FLG(FLG_MORE_BONUS);
446 if (MATCH_KEY(KEY_WORTHLESS)) ADD_FLG(FLG_WORTHLESS);
447 if (MATCH_KEY(KEY_EGO)) ADD_FLG(FLG_EGO);
448 if (MATCH_KEY(KEY_NAMELESS)) ADD_FLG(FLG_NAMELESS);
449 if (MATCH_KEY(KEY_UNAWARE)) ADD_FLG(FLG_UNAWARE);
450 if (MATCH_KEY(KEY_WANTED)) ADD_FLG(FLG_WANTED);
451 if (MATCH_KEY(KEY_UNIQUE)) ADD_FLG(FLG_UNIQUE);
452 if (MATCH_KEY(KEY_HUMAN)) ADD_FLG(FLG_HUMAN);
453 if (MATCH_KEY(KEY_UNREADABLE)) ADD_FLG(FLG_UNREADABLE);
454 if (MATCH_KEY(KEY_REALM1)) ADD_FLG(FLG_REALM1);
455 if (MATCH_KEY(KEY_REALM2)) ADD_FLG(FLG_REALM2);
456 if (MATCH_KEY(KEY_FIRST)) ADD_FLG(FLG_FIRST);
457 if (MATCH_KEY(KEY_SECOND)) ADD_FLG(FLG_SECOND);
458 if (MATCH_KEY(KEY_THIRD)) ADD_FLG(FLG_THIRD);
459 if (MATCH_KEY(KEY_FOURTH)) ADD_FLG(FLG_FOURTH);
462 /* Not yet found any noun */
465 if (MATCH_KEY2(KEY_ARTIFACT)) ADD_FLG_NOUN(FLG_ARTIFACT);
467 if (MATCH_KEY2(KEY_ITEMS)) ADD_FLG_NOUN(FLG_ITEMS);
468 else if (MATCH_KEY2(KEY_WEAPONS)) ADD_FLG_NOUN(FLG_WEAPONS);
469 else if (MATCH_KEY2(KEY_ARMORS)) ADD_FLG_NOUN(FLG_ARMORS);
470 else if (MATCH_KEY2(KEY_MISSILES)) ADD_FLG_NOUN(FLG_MISSILES);
471 else if (MATCH_KEY2(KEY_DEVICES)) ADD_FLG_NOUN(FLG_DEVICES);
472 else if (MATCH_KEY2(KEY_LIGHTS)) ADD_FLG_NOUN(FLG_LIGHTS);
473 else if (MATCH_KEY2(KEY_JUNKS)) ADD_FLG_NOUN(FLG_JUNKS);
474 else if (MATCH_KEY2(KEY_SPELLBOOKS)) ADD_FLG_NOUN(FLG_SPELLBOOKS);
475 else if (MATCH_KEY2(KEY_HAFTED)) ADD_FLG_NOUN(FLG_HAFTED);
476 else if (MATCH_KEY2(KEY_SHIELDS)) ADD_FLG_NOUN(FLG_SHIELDS);
477 else if (MATCH_KEY2(KEY_BOWS)) ADD_FLG_NOUN(FLG_BOWS);
478 else if (MATCH_KEY2(KEY_RINGS)) ADD_FLG_NOUN(FLG_RINGS);
479 else if (MATCH_KEY2(KEY_AMULETS)) ADD_FLG_NOUN(FLG_AMULETS);
480 else if (MATCH_KEY2(KEY_SUITS)) ADD_FLG_NOUN(FLG_SUITS);
481 else if (MATCH_KEY2(KEY_CLOAKS)) ADD_FLG_NOUN(FLG_CLOAKS);
482 else if (MATCH_KEY2(KEY_HELMS)) ADD_FLG_NOUN(FLG_HELMS);
483 else if (MATCH_KEY2(KEY_GLOVES)) ADD_FLG_NOUN(FLG_GLOVES);
484 else if (MATCH_KEY2(KEY_BOOTS)) ADD_FLG_NOUN(FLG_BOOTS);
486 /* Last 'keyword' must be at the correct location */
490 else if (ptr[0] == kanji_colon[0] && ptr[1] == kanji_colon[1])
493 else if (*ptr == '\0')
494 ; /* nothing to do */
500 /* A noun type keyword didn't end correctly */
501 entry->flag[prev_flg/32] &= ~(1L<< (prev_flg%32));
506 /* Save this auto-picker entry line */
507 entry->name = string_make(ptr);
509 entry->insc = string_make(insc);
515 * A function to delete entry
517 void autopick_free_entry(autopick_type *entry)
519 string_free(entry->name);
520 string_free(entry->insc);
525 * A function for Auto-picker/destroyer
526 * Examine whether the object matches to the entry
528 static bool is_autopick_aux(object_type *o_ptr, autopick_type *entry, cptr o_name)
531 cptr ptr = entry->name;
533 /*** Unidentified ***/
534 if (IS_FLG(FLG_UNIDENTIFIED)
535 && (object_known_p(o_ptr) || (o_ptr->ident & IDENT_SENSE)))
539 if (IS_FLG(FLG_IDENTIFIED) && !object_known_p(o_ptr))
542 /*** *Identified* ***/
543 if (IS_FLG(FLG_STAR_IDENTIFIED) &&
544 (!object_known_p(o_ptr) || !(o_ptr->ident & IDENT_MENTAL)))
547 /*** Dice boosted (weapon of slaying) ***/
548 if (IS_FLG(FLG_BOOSTED))
550 object_kind *k_ptr = &k_info[o_ptr->k_idx];
552 switch( o_ptr->tval )
558 if ((o_ptr->dd != k_ptr->dd) || (o_ptr->ds != k_ptr->ds))
567 /*** Weapons whic dd*ds is more than nn ***/
568 if (IS_FLG(FLG_MORE_THAN))
570 if (o_ptr->dd * o_ptr->ds < entry->dice)
574 /*** Weapons whic dd*ds is more than nn ***/
575 if (IS_FLG(FLG_MORE_BONUS))
577 if (!object_known_p(o_ptr)) return FALSE;
579 if (k_info[o_ptr->k_idx].pval ||
580 (o_ptr->name2 && e_info[o_ptr->name2].max_pval))
582 if (o_ptr->pval < entry->bonus) return FALSE;
586 if (o_ptr->to_h < entry->bonus &&
587 o_ptr->to_d < entry->bonus &&
588 o_ptr->to_a < entry->bonus &&
589 o_ptr->pval < entry->bonus)
594 /*** Worthless items ***/
595 if (IS_FLG(FLG_WORTHLESS) && object_value(o_ptr) > 0)
598 /*** Artifact object ***/
599 if (IS_FLG(FLG_ARTIFACT))
601 if (!object_known_p(o_ptr) || (!o_ptr->name1 && !o_ptr->art_name))
608 if (!object_known_p(o_ptr) || !o_ptr->name2)
613 if (IS_FLG(FLG_NAMELESS))
618 case TV_SHOT: case TV_ARROW: case TV_BOLT: case TV_BOW:
619 case TV_DIGGING: case TV_HAFTED: case TV_POLEARM: case TV_SWORD:
620 case TV_BOOTS: case TV_GLOVES: case TV_HELM: case TV_CROWN:
621 case TV_SHIELD: case TV_CLOAK:
622 case TV_SOFT_ARMOR: case TV_HARD_ARMOR: case TV_DRAG_ARMOR:
623 case TV_LITE: case TV_AMULET: case TV_RING: case TV_CARD:
624 if ((!object_known_p(o_ptr) || o_ptr->inscription
625 || o_ptr->name1 || o_ptr->name2 || o_ptr->art_name))
634 /*** Unaware items ***/
635 if (IS_FLG(FLG_UNAWARE) && object_aware_p(o_ptr))
638 /*** Wanted monster's corpse/skeletons ***/
639 if (IS_FLG(FLG_WANTED) &&
640 (o_ptr->tval != TV_CORPSE || !object_is_shoukinkubi(o_ptr)))
643 /*** Unique monster's corpse/skeletons/statues ***/
644 if (IS_FLG(FLG_UNIQUE) &&
645 ((o_ptr->tval != TV_CORPSE && o_ptr->tval != TV_STATUE) ||
646 !(r_info[o_ptr->pval].flags1 & RF1_UNIQUE)))
649 /*** Human corpse/skeletons (for Daemon magic) ***/
650 if (IS_FLG(FLG_HUMAN) &&
651 (o_ptr->tval != TV_CORPSE ||
652 !strchr("pht", r_info[o_ptr->pval].d_char)))
655 /*** Unreadable spellbooks ***/
656 if (IS_FLG(FLG_UNREADABLE) &&
657 (o_ptr->tval < TV_LIFE_BOOK ||
658 check_book_realm(o_ptr->tval, o_ptr->sval)))
661 /*** First realm spellbooks ***/
662 if (IS_FLG(FLG_REALM1) &&
663 (REALM1_BOOK != o_ptr->tval ||
664 p_ptr->pclass == CLASS_SORCERER ||
665 p_ptr->pclass == CLASS_RED_MAGE))
668 /*** Second realm spellbooks ***/
669 if (IS_FLG(FLG_REALM2) &&
670 (REALM2_BOOK != o_ptr->tval ||
671 p_ptr->pclass == CLASS_SORCERER ||
672 p_ptr->pclass == CLASS_RED_MAGE))
675 /*** First rank spellbooks ***/
676 if (IS_FLG(FLG_FIRST) &&
677 (o_ptr->tval < TV_LIFE_BOOK || 0 != o_ptr->sval))
680 /*** Second rank spellbooks ***/
681 if (IS_FLG(FLG_SECOND) &&
682 (o_ptr->tval < TV_LIFE_BOOK || 1 != o_ptr->sval))
685 /*** Third rank spellbooks ***/
686 if (IS_FLG(FLG_THIRD) &&
687 (o_ptr->tval < TV_LIFE_BOOK || 2 != o_ptr->sval))
690 /*** Fourth rank spellbooks ***/
691 if (IS_FLG(FLG_FOURTH) &&
692 (o_ptr->tval < TV_LIFE_BOOK || 3 != o_ptr->sval))
696 if (IS_FLG(FLG_WEAPONS))
700 case TV_BOW: case TV_HAFTED: case TV_POLEARM:
701 case TV_SWORD: case TV_DIGGING:
703 default: return FALSE;
706 else if (IS_FLG(FLG_ARMORS))
710 case TV_BOOTS: case TV_GLOVES: case TV_CLOAK: case TV_CROWN:
711 case TV_HELM: case TV_SHIELD: case TV_SOFT_ARMOR:
712 case TV_HARD_ARMOR: case TV_DRAG_ARMOR:
714 default: return FALSE;
717 else if (IS_FLG(FLG_MISSILES))
721 case TV_SHOT: case TV_BOLT: case TV_ARROW:
723 default: return FALSE;
726 else if (IS_FLG(FLG_DEVICES))
730 case TV_SCROLL: case TV_STAFF: case TV_WAND: case TV_ROD:
732 default: return FALSE;
735 else if (IS_FLG(FLG_LIGHTS))
737 if (!(o_ptr->tval == TV_LITE))
740 else if (IS_FLG(FLG_JUNKS))
744 case TV_SKELETON: case TV_BOTTLE:
745 case TV_JUNK: case TV_STATUE:
747 default: return FALSE;
750 else if (IS_FLG(FLG_SPELLBOOKS))
752 if (!(o_ptr->tval >= TV_LIFE_BOOK))
755 else if (IS_FLG(FLG_HAFTED))
757 if (!(o_ptr->tval == TV_HAFTED))
760 else if (IS_FLG(FLG_SHIELDS))
762 if (!(o_ptr->tval == TV_SHIELD))
765 else if (IS_FLG(FLG_BOWS))
767 if (!(o_ptr->tval == TV_BOW))
770 else if (IS_FLG(FLG_RINGS))
772 if (!(o_ptr->tval == TV_RING))
775 else if (IS_FLG(FLG_AMULETS))
777 if (!(o_ptr->tval == TV_AMULET))
780 else if (IS_FLG(FLG_SUITS))
782 if (!(o_ptr->tval == TV_DRAG_ARMOR ||
783 o_ptr->tval == TV_HARD_ARMOR ||
784 o_ptr->tval == TV_SOFT_ARMOR))
787 else if (IS_FLG(FLG_CLOAKS))
789 if (!(o_ptr->tval == TV_CLOAK))
792 else if (IS_FLG(FLG_HELMS))
794 if (!(o_ptr->tval == TV_CROWN || o_ptr->tval == TV_HELM))
797 else if (IS_FLG(FLG_GLOVES))
799 if (!(o_ptr->tval == TV_GLOVES))
802 else if (IS_FLG(FLG_BOOTS))
804 if (!(o_ptr->tval == TV_BOOTS))
808 /* Keyword don't match */
812 if (strncmp(o_name, ptr, strlen(ptr))) return FALSE;
817 if (!strstr_j(o_name, ptr)) return FALSE;
819 if (!strstr(o_name, ptr)) return FALSE;
823 /* TRUE when it need not to be 'collecting' */
824 if (!IS_FLG(FLG_COLLECTING)) return TRUE;
826 /* Check if there is a same item */
827 for (j = 0; j < INVEN_PACK; j++)
830 * 'Collecting' means the item must be absorbed
831 * into an inventory slot.
832 * But an item can not be absorbed into itself!
834 if ((&inventory[j] != o_ptr) &&
835 object_similar(&inventory[j], o_ptr))
845 * A function for Auto-picker/destroyer
846 * Examine whether the object matches to the list of keywords or not.
848 int is_autopick(object_type *o_ptr)
851 char o_name[MAX_NLEN];
853 if (o_ptr->tval == TV_GOLD) return -1;
855 object_desc(o_name, o_ptr, FALSE, 3);
857 /* Force to be lower case string */
858 for (i = 0; o_name[i]; i++)
861 if (iskanji(o_name[i]))
865 if (isupper(o_name[i]))
866 o_name[i] = tolower(o_name[i]);
869 for (i=0; i < max_autopick; i++)
871 autopick_type *entry = &autopick_list[i];
873 if (is_autopick_aux(o_ptr, entry, o_name)) return i;
876 /* No matching entry */
882 * Automatically destroy items in this grid.
884 static bool is_opt_confirm_destroy(object_type *o_ptr)
886 if (!destroy_items) return FALSE;
888 /* Known to be worthless? */
890 if (object_value(o_ptr) > 0) return FALSE;
893 if ((o_ptr->tval >= TV_SHOT) && (o_ptr->tval <= TV_DRAG_ARMOR)) return FALSE;
896 if ((o_ptr->tval == TV_CHEST) && o_ptr->pval) return FALSE;
900 if (o_ptr->tval == TV_CORPSE
901 && object_is_shoukinkubi(o_ptr)) return FALSE;
905 if (o_ptr->tval == TV_CORPSE) return FALSE;
908 if ((o_ptr->tval == TV_SKELETON) || (o_ptr->tval == TV_BOTTLE) || (o_ptr->tval == TV_JUNK) || (o_ptr->tval == TV_STATUE)) return FALSE;
910 if (o_ptr->tval == TV_GOLD) return FALSE;
919 void auto_inscribe_item(int item, int idx)
923 /* Get the item (in the pack) */
924 if (item >= 0) o_ptr = &inventory[item];
926 /* Get the item (on the floor) */
927 else o_ptr = &o_list[0 - item];
929 /* Auto-inscription or Re-inscribe for resistances {%} */
930 if ((idx < 0 || !autopick_list[idx].insc) && !o_ptr->inscription)
933 if (o_ptr->inscription)
934 o_ptr->inscription = inscribe_flags(o_ptr, quark_str(o_ptr->inscription));
936 o_ptr->inscription = inscribe_flags(o_ptr, autopick_list[idx].insc);
938 if (item > INVEN_PACK)
940 /* Redraw inscription */
941 p_ptr->window |= (PW_EQUIP);
943 /* {.} and {$} effect p_ptr->warning and TRC_TELEPORT_SELF */
944 p_ptr->update |= (PU_BONUS);
948 /* Redraw inscription */
949 p_ptr->window |= (PW_INVEN);
955 * Automatically destroy an item if it is to be destroyed
957 bool auto_destroy_item(int item, int autopick_idx, bool wait_optimize)
959 bool destroy = FALSE;
960 char o_name[MAX_NLEN];
963 /* Don't destroy equipped items */
964 if (item > INVEN_PACK) return FALSE;
966 /* Get the item (in the pack) */
967 if (item >= 0) o_ptr = &inventory[item];
969 /* Get the item (on the floor) */
970 else o_ptr = &o_list[0 - item];
972 /* Easy-Auto-Destroyer */
973 if (is_opt_confirm_destroy(o_ptr)) destroy = TRUE;
975 /* Protected by auto-picker */
976 if (autopick_idx >= 0 &&
977 !(autopick_list[autopick_idx].action & DO_AUTODESTROY))
982 /* Auto-picker/destroyer */
983 if (autopick_idx >= 0 &&
984 (autopick_list[autopick_idx].action & DO_AUTODESTROY))
988 /* Not to be destroyed */
989 if (!destroy) return FALSE;
991 /* Now decided to destroy */
995 /* Describe the object (with {terrible/special}) */
996 object_desc(o_name, o_ptr, TRUE, 3);
999 if (!can_player_destroy_object(o_ptr))
1003 msg_format("%s¤ÏÇ˲õÉÔǽ¤À¡£", o_name);
1005 msg_format("You cannot auto-destroy %s.", o_name);
1012 /* Record name of destroyed item */
1013 COPY(&autopick_last_destroyed_object, o_ptr, object_type);
1015 /* Eliminate the item (from the pack) */
1018 inven_item_increase(item, -(o_ptr->number));
1021 * always optimize equipment.
1022 * optimize inventry only when wait_optimize is FALSE.
1024 if (!wait_optimize || item > INVEN_PACK)
1025 inven_item_optimize(item);
1028 /* Eliminate the item (from the floor) */
1031 delete_object_idx(0 - item);
1034 /* Print a message */
1036 msg_format("%s¤ò¼«Æ°Ç˲õ¤·¤Þ¤¹¡£", o_name);
1038 msg_format("Auto-destroying %s.", o_name);
1046 * Optimize all inventry items after consumption of staves or scrolls.
1048 void optimize_inventry_auto_destroy(void)
1052 for (i = 0; i <= INVEN_PACK; i++)
1053 inven_item_optimize(i);
1058 * Automatically pickup/destroy items in this grid.
1060 void auto_pickup_items(cave_type *c_ptr)
1062 s16b this_o_idx, next_o_idx = 0;
1064 /* Scan the pile of objects */
1065 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
1069 /* Acquire object */
1070 object_type *o_ptr = &o_list[this_o_idx];
1072 /* Acquire next object */
1073 next_o_idx = o_ptr->next_o_idx;
1075 idx = is_autopick(o_ptr);
1077 /* Item index for floor -1,-2,-3,... */
1078 auto_inscribe_item((-this_o_idx), idx);
1080 if (idx >= 0 && (autopick_list[idx].action & DO_AUTOPICK))
1084 if (!inven_carry_okay(o_ptr))
1086 char o_name[MAX_NLEN];
1088 /* Describe the object */
1089 object_desc(o_name, o_ptr, TRUE, 3);
1093 msg_format("¥¶¥Ã¥¯¤Ë¤Ï%s¤òÆþ¤ì¤ë·ä´Ö¤¬¤Ê¤¤¡£", o_name);
1095 msg_format("You have no room for %s.", o_name);
1099 py_pickup_aux(this_o_idx);
1106 * When always_pickup is 'yes', we disable
1107 * auto-destroyer from autopick function, and do only
1108 * easy-auto-destroyer.
1112 if (auto_destroy_item((-this_o_idx), idx, FALSE))
1120 * Describe which kind of object is Auto-picked/destroyed
1122 static void describe_autopick(char *buff, autopick_type *entry)
1124 cptr str = entry->name;
1125 byte act = entry->action;
1126 cptr insc = entry->insc;
1132 cptr before_str[100], body_str;
1135 body_str = "¥¢¥¤¥Æ¥à";
1137 /*** Collecting items ***/
1138 /*** Which can be absorbed into a slot as a bundle ***/
1139 if (IS_FLG(FLG_COLLECTING))
1140 before_str[before_n++] = "¼ý½¸Ãæ¤Ç´û¤Ë»ý¤Ã¤Æ¤¤¤ë¥¹¥í¥Ã¥È¤Ë¤Þ¤È¤á¤é¤ì¤ë";
1142 /*** Unidentified ***/
1143 if (IS_FLG(FLG_UNIDENTIFIED))
1144 before_str[before_n++] = "̤´ÕÄê¤Î";
1146 /*** Identified ***/
1147 if (IS_FLG(FLG_IDENTIFIED))
1148 before_str[before_n++] = "´ÕÄêºÑ¤ß¤Î";
1150 /*** *Identified* ***/
1151 if (IS_FLG(FLG_STAR_IDENTIFIED))
1152 before_str[before_n++] = "´°Á´¤Ë´ÕÄêºÑ¤ß¤Î";
1154 /*** Dice boosted (weapon of slaying) ***/
1155 if (IS_FLG(FLG_BOOSTED))
1157 before_str[before_n++] = "¥À¥á¡¼¥¸¥À¥¤¥¹¤¬Ä̾ï¤è¤êÂ礤¤";
1161 /*** Weapons whose dd*ds is more than nn ***/
1162 if (IS_FLG(FLG_MORE_THAN))
1164 static char more_than_desc_str[] = "___";
1165 before_str[before_n++] = "¥À¥á¡¼¥¸¥À¥¤¥¹¤ÎºÇÂçÃͤ¬";
1168 sprintf(more_than_desc_str,"%d", entry->dice);
1169 before_str[before_n++] = more_than_desc_str;
1170 before_str[before_n++] = "°Ê¾å¤Î";
1173 /*** Items whose magical bonus is more than nn ***/
1174 if (IS_FLG(FLG_MORE_BONUS))
1176 static char more_bonus_desc_str[] = "___";
1177 before_str[before_n++] = "½¤ÀµÃͤ¬(+";
1179 sprintf(more_bonus_desc_str,"%d", entry->bonus);
1180 before_str[before_n++] = more_bonus_desc_str;
1181 before_str[before_n++] = ")°Ê¾å¤Î";
1184 /*** Worthless items ***/
1185 if (IS_FLG(FLG_WORTHLESS))
1186 before_str[before_n++] = "Ź¤Ç̵²ÁÃͤÈȽÄꤵ¤ì¤ë";
1189 if (IS_FLG(FLG_ARTIFACT))
1191 before_str[before_n++] = "¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È¤Î";
1196 if (IS_FLG(FLG_EGO))
1198 before_str[before_n++] = "¥¨¥´¥¢¥¤¥Æ¥à¤Î";
1203 if (IS_FLG(FLG_NAMELESS))
1205 before_str[before_n++] = "¥¨¥´¤Ç¤â¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È¤Ç¤â¤Ê¤¤";
1209 /*** Unaware items ***/
1210 if (IS_FLG(FLG_UNAWARE))
1211 before_str[before_n++] = "̤´ÕÄê¤Ç¤½¤Î¸ú²Ì¤âȽÌÀ¤·¤Æ¤¤¤Ê¤¤";
1213 /*** Wanted monster's corpse/skeletons ***/
1214 if (IS_FLG(FLG_WANTED))
1216 before_str[before_n++] = "¥Ï¥ó¥¿¡¼»ö̳½ê¤Ç¾Þ¶â¼ó¤È¤µ¤ì¤Æ¤¤¤ë";
1217 body_str = "»àÂΤä¹ü";
1220 /*** Human corpse/skeletons (for Daemon magic) ***/
1221 if (IS_FLG(FLG_HUMAN))
1223 before_str[before_n++] = "°ËâËâË¡¤Ç»È¤¦¤¿¤á¤Î¿Í´Ö¤ä¥Ò¥å¡¼¥Þ¥Î¥¤¥É¤Î";
1224 body_str = "»àÂΤä¹ü";
1227 /*** Unique monster's corpse/skeletons/statues ***/
1228 if (IS_FLG(FLG_UNIQUE))
1230 before_str[before_n++] = "¥æ¥Ë¡¼¥¯¥â¥ó¥¹¥¿¡¼¤Î";
1231 body_str = "»àÂΤä¹ü";
1234 /*** Unreadable spellbooks ***/
1235 if (IS_FLG(FLG_UNREADABLE))
1237 before_str[before_n++] = "¤¢¤Ê¤¿¤¬Æɤá¤Ê¤¤Îΰè¤Î";
1238 body_str = "ËâË¡½ñ";
1241 /*** First realm spellbooks ***/
1242 if (IS_FLG(FLG_REALM1))
1244 before_str[before_n++] = "Âè°ìÎΰè¤Î";
1245 body_str = "ËâË¡½ñ";
1248 /*** Second realm spellbooks ***/
1249 if (IS_FLG(FLG_REALM2))
1251 before_str[before_n++] = "ÂèÆóÎΰè¤Î";
1252 body_str = "ËâË¡½ñ";
1255 /*** First rank spellbooks ***/
1256 if (IS_FLG(FLG_FIRST))
1258 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î1ºýÌܤÎ";
1259 body_str = "ËâË¡½ñ";
1262 /*** Second rank spellbooks ***/
1263 if (IS_FLG(FLG_SECOND))
1265 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î2ºýÌܤÎ";
1266 body_str = "ËâË¡½ñ";
1269 /*** Third rank spellbooks ***/
1270 if (IS_FLG(FLG_THIRD))
1272 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î3ºýÌܤÎ";
1273 body_str = "ËâË¡½ñ";
1276 /*** Fourth rank spellbooks ***/
1277 if (IS_FLG(FLG_FOURTH))
1279 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î4ºýÌܤÎ";
1280 body_str = "ËâË¡½ñ";
1284 if (IS_FLG(FLG_ITEMS))
1285 ; /* Nothing to do */
1286 else if (IS_FLG(FLG_WEAPONS))
1288 else if (IS_FLG(FLG_ARMORS))
1290 else if (IS_FLG(FLG_MISSILES))
1291 body_str = "ÃƤäÌð¤ä¥¯¥í¥¹¥Ü¥¦¤ÎÌð";
1292 else if (IS_FLG(FLG_DEVICES))
1293 body_str = "´¬Êª¤äËâË¡ËÀ¤ä¾ó¤ä¥í¥Ã¥É";
1294 else if (IS_FLG(FLG_LIGHTS))
1295 body_str = "¸÷¸»ÍѤΥ¢¥¤¥Æ¥à";
1296 else if (IS_FLG(FLG_JUNKS))
1297 body_str = "Àޤ줿ËÀÅù¤Î¥¬¥é¥¯¥¿";
1298 else if (IS_FLG(FLG_SPELLBOOKS))
1299 body_str = "ËâË¡½ñ";
1300 else if (IS_FLG(FLG_HAFTED))
1302 else if (IS_FLG(FLG_SHIELDS))
1304 else if (IS_FLG(FLG_BOWS))
1305 body_str = "¥¹¥ê¥ó¥°¤äµÝ¤ä¥¯¥í¥¹¥Ü¥¦";
1306 else if (IS_FLG(FLG_RINGS))
1308 else if (IS_FLG(FLG_AMULETS))
1309 body_str = "¥¢¥ß¥å¥ì¥Ã¥È";
1310 else if (IS_FLG(FLG_SUITS))
1312 else if (IS_FLG(FLG_CLOAKS))
1313 body_str = "¥¯¥í¡¼¥¯";
1314 else if (IS_FLG(FLG_HELMS))
1315 body_str = "¥Ø¥ë¥á¥Ã¥È¤ä´§";
1316 else if (IS_FLG(FLG_GLOVES))
1318 else if (IS_FLG(FLG_BOOTS))
1319 body_str = "¥Ö¡¼¥Ä";
1323 strcat(buff, "Á´¤Æ¤Î");
1324 else for (i = 0; i < before_n && before_str[i]; i++)
1325 strcat(buff, before_str[i]);
1327 strcat(buff, body_str);
1337 strcat(buff, "¤Ç¡¢Ì¾Á°¤¬¡Ö");
1338 strncat(buff, str, 80);
1340 strcat(buff, "¡×¤Ç»Ï¤Þ¤ë¤â¤Î");
1342 strcat(buff, "¡×¤ò´Þ¤à¤â¤Î");
1346 strncat(buff, format("¤Ë¡Ö%s¡×¤È¹ï¤ó¤Ç", insc), 80);
1350 if (act & DONT_AUTOPICK)
1351 strcat(buff, "ÊüÃÖ¤¹¤ë¡£");
1352 else if (act & DO_AUTODESTROY)
1353 strcat(buff, "Ç˲õ¤¹¤ë¡£");
1355 strcat(buff, "½¦¤¦¡£");
1357 if (act & DO_DISPLAY)
1359 if (act & DONT_AUTOPICK)
1360 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'N'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
1361 else if (act & DO_AUTODESTROY)
1362 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'K'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
1364 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'M'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
1367 strcat(buff, "Á´ÂΥޥåפˤÏɽ¼¨¤·¤Ê¤¤");
1371 cptr before_str[20], after_str[20], which_str[20], whose_str[20], body_str;
1372 int before_n = 0, after_n = 0, which_n = 0, whose_n = 0;
1376 /*** Collecting items ***/
1377 /*** Which can be absorbed into a slot as a bundle ***/
1378 if (IS_FLG(FLG_COLLECTING))
1379 which_str[which_n++] = "can be absorbed into an existing inventory slot";
1381 /*** Unidentified ***/
1382 if (IS_FLG(FLG_UNIDENTIFIED))
1383 before_str[before_n++] = "unidentified";
1385 /*** Identified ***/
1386 if (IS_FLG(FLG_IDENTIFIED))
1387 before_str[before_n++] = "identified";
1389 /*** *Identified* ***/
1390 if (IS_FLG(FLG_STAR_IDENTIFIED))
1391 before_str[before_n++] = "fully identified";
1393 /*** Worthless items ***/
1394 if (IS_FLG(FLG_WORTHLESS))
1396 before_str[before_n++] = "worthless";
1397 which_str[which_n++] = "can not be sold at stores";
1401 if (IS_FLG(FLG_ARTIFACT))
1403 before_str[before_n++] = "artifact";
1407 if (IS_FLG(FLG_EGO))
1409 before_str[before_n++] = "ego";
1413 if (IS_FLG(FLG_NAMELESS))
1415 body_str = "equipment";
1416 which_str[which_n++] = "is neither ego-item nor artifact";
1419 /*** Unaware items ***/
1420 if (IS_FLG(FLG_UNAWARE))
1422 before_str[before_n++] = "unidentified";
1423 whose_str[whose_n++] = "basic abilities are not known";
1426 /*** Dice boosted (weapon of slaying) ***/
1427 if (IS_FLG(FLG_BOOSTED))
1429 body_str = "weapons";
1430 whose_str[whose_n++] = "damage dice is bigger than normal";
1433 /*** Weapons whose dd*ds is more than nn ***/
1434 if (IS_FLG(FLG_MORE_THAN))
1436 static char more_than_desc_str[] =
1437 "maximum damage from dice is bigger than __";
1438 body_str = "weapons";
1440 sprintf(more_than_desc_str + sizeof(more_than_desc_str) - 3,
1442 whose_str[whose_n++] = more_than_desc_str;
1445 /*** Items whose magical bonus is more than nn ***/
1446 if (IS_FLG(FLG_MORE_BONUS))
1448 static char more_bonus_desc_str[] =
1449 "magical bonus is bigger than (+__)";
1451 sprintf(more_bonus_desc_str + sizeof(more_bonus_desc_str) - 4,
1452 "%d)", entry->bonus);
1453 whose_str[whose_n++] = more_bonus_desc_str;
1456 /*** Wanted monster's corpse/skeletons ***/
1457 if (IS_FLG(FLG_WANTED))
1459 body_str = "corpse or skeletons";
1460 which_str[which_n++] = "is wanted at the Hunter's Office";
1463 /*** Human corpse/skeletons (for Daemon magic) ***/
1464 if (IS_FLG(FLG_HUMAN))
1466 before_str[before_n++] = "humanoid";
1467 body_str = "corpse or skeletons";
1468 which_str[which_n++] = "can be used for Daemon magic";
1471 /*** Unique monster's corpse/skeletons/statues ***/
1472 if (IS_FLG(FLG_UNIQUE))
1474 before_str[before_n++] = "unique monster's";
1475 body_str = "corpse or skeletons";
1478 /*** Unreadable spellbooks ***/
1479 if (IS_FLG(FLG_UNREADABLE))
1481 body_str = "spellbooks";
1482 after_str[after_n++] = "of different realms from yours";
1485 /*** First realm spellbooks ***/
1486 if (IS_FLG(FLG_REALM1))
1488 body_str = "spellbooks";
1489 after_str[after_n++] = "of your first realm";
1492 /*** Second realm spellbooks ***/
1493 if (IS_FLG(FLG_REALM2))
1495 body_str = "spellbooks";
1496 after_str[after_n++] = "of your second realm";
1499 /*** First rank spellbooks ***/
1500 if (IS_FLG(FLG_FIRST))
1502 before_str[before_n++] = "first one of four";
1503 body_str = "spellbooks";
1506 /*** Second rank spellbooks ***/
1507 if (IS_FLG(FLG_SECOND))
1509 before_str[before_n++] = "second one of four";
1510 body_str = "spellbooks";
1513 /*** Third rank spellbooks ***/
1514 if (IS_FLG(FLG_THIRD))
1516 before_str[before_n++] = "third one of four";
1517 body_str = "spellbooks";
1520 /*** Fourth rank spellbooks ***/
1521 if (IS_FLG(FLG_FOURTH))
1523 before_str[before_n++] = "fourth one of four";
1524 body_str = "spellbooks";
1528 if (IS_FLG(FLG_ITEMS))
1529 ; /* Nothing to do */
1530 else if (IS_FLG(FLG_WEAPONS))
1531 body_str = "weapons";
1532 else if (IS_FLG(FLG_ARMORS))
1533 body_str = "armors";
1534 else if (IS_FLG(FLG_MISSILES))
1535 body_str = "shots, arrows or crossbow bolts";
1536 else if (IS_FLG(FLG_DEVICES))
1537 body_str = "scrolls, wands, staves or rods";
1538 else if (IS_FLG(FLG_LIGHTS))
1539 body_str = "light sources";
1540 else if (IS_FLG(FLG_JUNKS))
1541 body_str = "junk such as broken sticks";
1542 else if (IS_FLG(FLG_SPELLBOOKS))
1543 body_str = "spellbooks";
1544 else if (IS_FLG(FLG_HAFTED))
1545 body_str = "hafted weapons";
1546 else if (IS_FLG(FLG_SHIELDS))
1547 body_str = "shields";
1548 else if (IS_FLG(FLG_BOWS))
1549 body_str = "slings, bows or crossbows";
1550 else if (IS_FLG(FLG_RINGS))
1552 else if (IS_FLG(FLG_AMULETS))
1553 body_str = "amulets";
1554 else if (IS_FLG(FLG_SUITS))
1555 body_str = "body armors";
1556 else if (IS_FLG(FLG_CLOAKS))
1557 body_str = "cloaks";
1558 else if (IS_FLG(FLG_HELMS))
1559 body_str = "helms or crowns";
1560 else if (IS_FLG(FLG_GLOVES))
1561 body_str = "gloves";
1562 else if (IS_FLG(FLG_BOOTS))
1565 /* Prepare a string for item name */
1572 whose_str[whose_n++] = "name is beginning with \"";
1575 which_str[which_n++] = "have \"";
1579 /* Describe action flag */
1580 if (act & DONT_AUTOPICK)
1581 strcpy(buff, "Leave on floor ");
1582 else if (act & DO_AUTODESTROY)
1583 strcpy(buff, "Destroy ");
1585 strcpy(buff, "Pickup ");
1587 /* Auto-insctiption */
1589 strncat(buff, format("and inscribe \"%s\" on ", insc), 80);
1593 strcat(buff, "all ");
1594 else for (i = 0; i < before_n && before_str[i]; i++)
1596 strcat(buff, before_str[i]);
1601 strcat(buff, body_str);
1604 for (i = 0; i < after_n && after_str[i]; i++)
1607 strcat(buff, after_str[i]);
1611 for (i = 0; i < whose_n && whose_str[i]; i++)
1614 strcat(buff, " whose ");
1616 strcat(buff, ", and ");
1618 strcat(buff, whose_str[i]);
1621 /* Item name ; whose name is beginning with "str" */
1628 /* whose ..., and which .... */
1629 if (whose_n && which_n)
1630 strcat(buff, ", and ");
1633 for (i = 0; i < which_n && which_str[i]; i++)
1636 strcat(buff, " which ");
1638 strcat(buff, ", and ");
1640 strcat(buff, which_str[i]);
1643 /* Item name ; which have "str" as part of its name */
1646 strncat(buff, str, 80);
1647 strcat(buff, "\" as part of its name");
1651 /* Describe whether it will be displayed on the full map or not */
1652 if (act & DO_DISPLAY)
1654 if (act & DONT_AUTOPICK)
1655 strcat(buff, " Display these items when you press 'N' in the full map('M').");
1656 else if (act & DO_AUTODESTROY)
1657 strcat(buff, " Display these items when you press 'K' in the full map('M').");
1659 strcat(buff, " Display these items when you press 'M' in the full map('M').");
1662 strcat(buff, " Not displayed in the full map.");
1668 #define MAX_LINES 3000
1671 * Read whole lines of a file to memory
1673 static cptr *read_text_lines(cptr filename, bool user)
1675 cptr *lines_list = NULL;
1683 /* Hack -- drop permissions */
1685 path_build(buf, 1024, ANGBAND_DIR_USER, filename);
1689 path_build(buf, 1024, ANGBAND_DIR_PREF, filename);
1693 fff = my_fopen(buf, "r");
1697 /* Allocate list of pointers */
1698 C_MAKE(lines_list, MAX_LINES, cptr);
1701 while (0 == my_fgets(fff, buf, 1024))
1703 lines_list[lines++] = string_make(buf);
1704 if (lines >= MAX_LINES - 1) break;
1707 lines_list[0] = string_make("");
1715 if (!fff) return NULL;
1719 static cptr *read_pickpref_text_lines(void)
1725 sprintf(buf, "picktype-%s.prf", player_name);
1727 sprintf(buf, "pickpref-%s.prf", player_name);
1729 lines_list = read_text_lines(buf, TRUE);
1734 lines_list = read_text_lines("picktype.prf", TRUE);
1736 lines_list = read_text_lines("pickpref.prf", TRUE);
1743 lines_list = read_text_lines("picktype.prf", FALSE);
1745 lines_list = read_text_lines("pickpref.prf", FALSE);
1751 /* Allocate list of pointers */
1752 C_MAKE(lines_list, MAX_LINES, cptr);
1753 lines_list[0] = string_make("");
1759 * Write whole lines of memory to a file.
1761 static bool write_text_lines(cptr filename, cptr *lines_list)
1768 /* Hack -- drop permissions */
1771 /* Build the filename */
1772 path_build(buf, 1024, ANGBAND_DIR_USER, filename);
1775 fff = my_fopen(buf, "w");
1778 for (lines = 0; lines_list[lines]; lines++)
1779 my_fputs(fff, lines_list[lines], 1024);
1787 if (!fff) return FALSE;
1793 * Free memory of lines_list.
1795 static void free_text_lines(cptr *lines_list)
1799 for (lines = 0; lines_list[lines]; lines++)
1800 string_free(lines_list[lines]);
1802 /* free list of pointers */
1803 C_FREE((char **)lines_list, MAX_LINES, char *);
1808 * Delete or insert string
1810 static void toggle_string(cptr *lines_list, int flg, int y)
1812 autopick_type an_entry, *entry = &an_entry;
1814 if (!autopick_new_entry(entry, lines_list[y]))
1817 string_free(lines_list[y]);
1823 lines_list[y] = autopick_line_from_entry(entry);
1827 * Insert return code and split the line
1829 static bool insert_return_code(cptr *lines_list, int cx, int cy)
1831 char buf[MAX_LINELEN];
1834 for (k = 0; lines_list[k]; k++)
1835 /* count number of lines */ ;
1837 if (k >= MAX_LINES - 2) return FALSE;
1840 /* Move down lines */
1842 lines_list[k+1] = lines_list[k];
1844 /* Split current line */
1845 for (i = j = 0; lines_list[cy][i] && i < cx; i++)
1848 if (iskanji(lines_list[cy][i]))
1849 buf[j++] = lines_list[cy][i++];
1851 buf[j++] = lines_list[cy][i];
1854 lines_list[cy+1] = string_make(&lines_list[cy][i]);
1855 string_free(lines_list[cy]);
1856 lines_list[cy] = string_make(buf);
1862 * Get auto-picker entry from o_ptr.
1864 void autopick_entry_from_object(autopick_type *entry, object_type *o_ptr)
1866 char o_name[MAX_NLEN];
1867 object_desc(o_name, o_ptr, FALSE, 0);
1869 entry->name = string_make(o_name);
1870 entry->insc = string_make(quark_str(o_ptr->inscription));
1871 entry->action = DO_AUTOPICK | DO_DISPLAY;
1872 entry->flag[0] = entry->flag[1] = 0L;
1875 if (!object_aware_p(o_ptr))
1876 ADD_FLG(FLG_UNAWARE);
1877 if (object_value(o_ptr) <= 0)
1878 ADD_FLG(FLG_WORTHLESS);
1880 if (object_known_p(o_ptr))
1884 else if (o_ptr->name1 || o_ptr->art_name)
1885 ADD_FLG(FLG_ARTIFACT);
1891 case TV_HAFTED: case TV_POLEARM: case TV_SWORD: case TV_DIGGING:
1892 k_ptr = &k_info[o_ptr->k_idx];
1893 if ((o_ptr->dd != k_ptr->dd) || (o_ptr->ds != k_ptr->ds))
1894 ADD_FLG(FLG_BOOSTED);
1897 if (o_ptr->tval == TV_CORPSE && object_is_shoukinkubi(o_ptr))
1899 REM_FLG(FLG_WORTHLESS);
1900 ADD_FLG(FLG_WANTED);
1903 if ((o_ptr->tval == TV_CORPSE || o_ptr->tval == TV_STATUE)
1904 && (r_info[o_ptr->pval].flags1 & RF1_UNIQUE))
1906 REM_FLG(FLG_WORTHLESS);
1907 ADD_FLG(FLG_UNIQUE);
1910 if (o_ptr->tval == TV_CORPSE && strchr("pht", r_info[o_ptr->pval].d_char))
1912 REM_FLG(FLG_WORTHLESS);
1916 if (o_ptr->tval >= TV_LIFE_BOOK &&
1917 !check_book_realm(o_ptr->tval, o_ptr->sval))
1918 ADD_FLG(FLG_UNREADABLE);
1920 if (REALM1_BOOK == o_ptr->tval &&
1921 p_ptr->pclass != CLASS_SORCERER &&
1922 p_ptr->pclass != CLASS_RED_MAGE)
1923 ADD_FLG(FLG_REALM1);
1925 if (REALM2_BOOK == o_ptr->tval &&
1926 p_ptr->pclass != CLASS_SORCERER &&
1927 p_ptr->pclass != CLASS_RED_MAGE)
1928 ADD_FLG(FLG_REALM2);
1930 if (o_ptr->tval >= TV_LIFE_BOOK && 0 == o_ptr->sval)
1932 if (o_ptr->tval >= TV_LIFE_BOOK && 1 == o_ptr->sval)
1933 ADD_FLG(FLG_SECOND);
1934 if (o_ptr->tval >= TV_LIFE_BOOK && 2 == o_ptr->sval)
1936 if (o_ptr->tval >= TV_LIFE_BOOK && 3 == o_ptr->sval)
1937 ADD_FLG(FLG_FOURTH);
1939 if (o_ptr->tval == TV_SHOT || o_ptr->tval == TV_BOLT
1940 || o_ptr->tval == TV_ARROW)
1941 ADD_FLG(FLG_MISSILES);
1942 else if (o_ptr->tval == TV_SCROLL || o_ptr->tval == TV_STAFF
1943 || o_ptr->tval == TV_WAND || o_ptr->tval == TV_ROD)
1944 ADD_FLG(FLG_DEVICES);
1945 else if (o_ptr->tval == TV_LITE)
1946 ADD_FLG(FLG_LIGHTS);
1947 else if (o_ptr->tval == TV_SKELETON || o_ptr->tval == TV_BOTTLE
1948 || o_ptr->tval == TV_JUNK || o_ptr->tval == TV_STATUE)
1950 else if (o_ptr->tval >= TV_LIFE_BOOK)
1951 ADD_FLG(FLG_SPELLBOOKS);
1952 else if (o_ptr->tval == TV_HAFTED)
1953 ADD_FLG(FLG_HAFTED);
1954 else if (o_ptr->tval == TV_POLEARM || o_ptr->tval == TV_SWORD
1955 || o_ptr->tval == TV_DIGGING)
1956 ADD_FLG(FLG_WEAPONS);
1957 else if (o_ptr->tval == TV_SHIELD)
1958 ADD_FLG(FLG_SHIELDS);
1959 else if (o_ptr->tval == TV_BOW)
1961 else if (o_ptr->tval == TV_RING)
1963 else if (o_ptr->tval == TV_AMULET)
1964 ADD_FLG(FLG_AMULETS);
1965 else if (o_ptr->tval == TV_DRAG_ARMOR || o_ptr->tval == TV_HARD_ARMOR ||
1966 o_ptr->tval == TV_SOFT_ARMOR)
1968 else if (o_ptr->tval == TV_CLOAK)
1969 ADD_FLG(FLG_CLOAKS);
1970 else if (o_ptr->tval == TV_HELM)
1972 else if (o_ptr->tval == TV_GLOVES)
1973 ADD_FLG(FLG_GLOVES);
1974 else if (o_ptr->tval == TV_BOOTS)
1982 * Choose an item and get auto-picker entry from it.
1984 static object_type *choose_object(cptr q, cptr s)
1988 if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR | USE_EQUIP))) return NULL;
1990 /* Get the item (in the pack) */
1991 if (item >= 0) return &inventory[item];
1993 /* Get the item (on the floor) */
1994 else return &o_list[0 - item];
1999 * Choose an item and get auto-picker entry from it.
2001 static bool entry_from_choosed_object(autopick_type *entry)
2008 q = "¤É¤Î¥¢¥¤¥Æ¥à¤òÅÐÏ¿¤·¤Þ¤¹¤«? ";
2009 s = "¥¢¥¤¥Æ¥à¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£";
2011 q = "Entry which item? ";
2012 s = "You have nothing to entry.";
2014 o_ptr = choose_object(q, s);
2015 if (!o_ptr) return FALSE;
2017 autopick_entry_from_object(entry, o_ptr);
2023 * Choose an item or string for search
2025 static bool get_string_for_search(object_type **o_handle, cptr *search_strp)
2029 char buf[MAX_NLEN+20];
2032 int k_flag[MAX_NLEN+20];
2033 char prompt[] = "¸¡º÷(^I:»ý¤Áʪ ^L:Ç˲õ¤µ¤ì¤¿Êª):";
2035 char prompt[] = "Search key(^I:inven ^L:destroyed):";
2037 int col = sizeof(prompt) - 1;
2039 if (*o_handle) object_desc(buf, *o_handle, FALSE, 3);
2040 else if (*search_strp) strcpy(buf, *search_strp);
2043 /* Display prompt */
2046 /* Display the default answer */
2047 Term_erase(col, 0, 255);
2048 Term_putstr(col, 0, -1, TERM_YELLOW, buf);
2057 Term_gotoxy(col + pos, 0);
2059 /* Do not process macros except special keys */
2060 inkey_special = TRUE;
2065 /* Analyze the key */
2074 if (!pos && *o_handle) return TRUE;
2075 string_free(*search_strp);
2076 *search_strp = string_make(buf);
2083 q = "¤É¤Î¥¢¥¤¥Æ¥à¤ò¸¡º÷¤·¤Þ¤¹¤«? ";
2084 s = "¥¢¥¤¥Æ¥à¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£";
2086 q = "Entry which item? ";
2087 s = "You have nothing to entry.";
2089 o_ptr = choose_object(q, s);
2090 if (!o_ptr) return FALSE;
2093 string_free(*search_strp);
2094 *search_strp = NULL;
2098 if (!autopick_last_destroyed_object.k_idx) break;
2099 *o_handle = &autopick_last_destroyed_object;
2100 string_free(*search_strp);
2101 *search_strp = NULL;
2110 if (k_flag[pos]) pos--;
2125 if (pos + 1 < MAX_NLEN)
2133 else if (pos < MAX_NLEN && isprint(i))
2140 if (pos < MAX_NLEN && isprint(i)) buf[pos++] = i;
2149 /* Update the entry */
2150 Term_erase(col, 0, 255);
2151 Term_putstr(col, 0, -1, TERM_WHITE, buf);
2159 * Search next line matches for o_ptr
2161 static bool search_for_object(cptr *lines_list, object_type *o_ptr, int *cyp)
2164 autopick_type an_entry, *entry = &an_entry;
2165 char o_name[MAX_NLEN];
2167 object_desc(o_name, o_ptr, FALSE, 3);
2169 /* Force to be lower case string */
2170 for (i = 0; o_name[i]; i++)
2173 if (iskanji(o_name[i]))
2177 if (isupper(o_name[i]))
2178 o_name[i] = tolower(o_name[i]);
2181 for (i = *cyp + 1; lines_list[i]; i++)
2183 if (!autopick_new_entry(entry, lines_list[i])) continue;
2185 if (is_autopick_aux(o_ptr, entry, o_name))
2197 * Search next line matches to the string
2199 static bool search_for_string(cptr *lines_list, cptr search_str, int *cxp, int *cyp)
2203 for (i = *cyp + 1; lines_list[i]; i++)
2207 pos = strstr_j(lines_list[i], search_str);
2209 pos = strstr(lines_list[i], search_str);
2213 *cxp = (int)(pos - lines_list[i]);
2224 * Initialize auto-picker preference
2226 void init_autopicker(void)
2228 static const char easy_autopick_inscription[] = "(:=g";
2229 autopick_type entry;
2232 /* Clear old entries */
2233 for( i = 0; i < max_autopick; i++)
2234 autopick_free_entry(&autopick_list[i]);
2238 /* There is always one entry "=g" */
2239 autopick_new_entry(&entry, easy_autopick_inscription);
2240 autopick_list[max_autopick++] = entry;
2245 * Get a trigger key and insert ASCII string for the trigger
2247 static bool insert_macro_line(cptr *lines_list, int cy)
2256 /* Do not process macros */
2262 /* Read the pattern */
2268 /* Do not process macros */
2271 /* Do not wait for keys */
2274 /* Attempt to read a key */
2284 /* Convert the trigger */
2285 ascii_to_text(tmp, buf);
2288 if(!tmp[0]) return FALSE;
2290 /* Insert preference string */
2291 insert_return_code(lines_list, 0, cy);
2292 string_free(lines_list[cy]);
2293 lines_list[cy] = string_make(format("P:%s", tmp));
2295 /* Insert blank action preference line */
2296 insert_return_code(lines_list, 0, cy);
2297 string_free(lines_list[cy]);
2298 lines_list[cy] = string_make("A:");
2305 * Get a command key and insert ASCII string for the key
2307 static bool insert_keymap_line(cptr *lines_list, int cy)
2314 if (rogue_like_commands)
2316 mode = KEYMAP_MODE_ROGUE;
2322 mode = KEYMAP_MODE_ORIG;
2335 /* Convert the trigger */
2336 ascii_to_text(tmp, buf);
2339 if(!tmp[0]) return FALSE;
2341 /* Insert preference string */
2342 insert_return_code(lines_list, 0, cy);
2343 string_free(lines_list[cy]);
2344 lines_list[cy] = string_make(format("C:%d:%s", mode, tmp));
2346 /* Insert blank action preference line */
2347 insert_return_code(lines_list, 0, cy);
2348 string_free(lines_list[cy]);
2349 lines_list[cy] = string_make("A:");
2356 * Description of control commands
2361 static cptr ctrl_command_desc[] =
2364 #define LAST_DESTROYED 6
2365 "^P ^N ^B ^F ¾å²¼º¸±¦¤Ë°ÜÆ°",
2366 "^A ^E ¹Ô¤ÎÀèƬ¡¢½ªÃ¼",
2367 "^Q ÆþÎÏ/¥³¥Þ¥ó¥É¥â¡¼¥ÉÀÚ¤êÂؤ¨",
2368 "^R Êѹ¹¤òÁ´¤Æ¼è¤ê¾Ã¤·¤Æ¸µ¤ËÌ᤹",
2369 "------------------------------------",
2370 "^I »ý¤Áʪ/ÁõÈ÷¤«¤éÁªÂò",
2372 "^K ¥«¡¼¥½¥ë¤«¤é½ªÃ¼¤Þ¤Çºï½ü",
2373 "^Y ºï½ü(^K)¤·¤¿¹Ô¤òÁÞÆþ",
2374 "^C ¼ï²¡¢¿¦¶È¤Î¾ò·ï¼°¤òÁÞÆþ",
2375 "------------------------------------",
2376 "^S Êѹ¹ (!Ç˲õ/~ÊüÃÖ/½¦¤¦)",
2377 "^G \"(\" Á´ÂΥޥåפÇɽ¼¨¤·¤Ê¤¤",
2378 "^O \"#\" ¼«Æ°¹ï¤ß",
2379 "------------------------------------",
2380 "^U ̤´ÕÄê/̤ȽÌÀ/´ÕÄê/*´ÕÄê*",
2382 "^X ̵ÌÃ/¥¨¥´/¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È",
2386 #define LAST_DESTROYED 6
2387 "^P ^N ^B ^F Move Cursor",
2388 "^A ^E Beginning and End of Line",
2389 "^Q Toggle Insert/Command mode",
2390 "^R Revert to Original File",
2391 "------------------------------------",
2392 "^I Object in Inventry/Equipment",
2394 "^K Kill Rest of Line",
2395 "^Y Insert killed(^K) text",
2396 "^C Insert conditional expression",
2397 "------------------------------------",
2398 "^S Toggle(!Destroy/~Leave/Pick)",
2399 "^G \"(\" No display in the 'M'ap",
2400 "^O \"#\" Auto-Inscribe",
2401 "------------------------------------",
2402 "^U Toggle 'identified' state",
2404 "^X Toggle nameless/ego/artifact",
2405 "^Z \"collecting\"",
2411 #define MAX_YANK MAX_LINELEN
2412 #define DIRTY_ALL 0x01
2413 #define DIRTY_COMMAND 0x02
2414 #define DIRTY_MODE 0x04
2415 #define DIRTY_SCREEN 0x04
2418 * In-game editor of Object Auto-picker/Destoryer
2420 void do_cmd_edit_autopick(void)
2422 static int cx = 0, cy = 0;
2423 static int upper = 0, left = 0;
2425 object_type *search_o_ptr = NULL;
2426 cptr search_str = NULL;
2427 cptr last_destroyed;
2428 char last_destroyed_command[WID_DESC+3];
2429 char yank_buf[MAX_YANK];
2431 autopick_type an_entry, *entry = &an_entry;
2432 char buf[MAX_LINELEN];
2438 int old_upper = -1, old_left = -1;
2440 int key = -1, old_key;
2442 bool edit_mode = FALSE;
2444 byte dirty_flags = DIRTY_ALL | DIRTY_COMMAND | DIRTY_MODE;
2445 int dirty_line = -1;
2447 int wid, hgt, old_wid = -1, old_hgt = -1;
2449 /* Free old entries */
2452 /* Name of the Last Destroyed Item */
2453 autopick_entry_from_object(entry, &autopick_last_destroyed_object);
2454 last_destroyed = autopick_line_from_entry(entry);
2456 /* Command Description of the Last Destroyed Item */
2459 strcpy(last_destroyed_command, "^L \"");
2460 strncpy(last_destroyed_command + 4, last_destroyed, WID_DESC-4);
2461 last_destroyed_command[WID_DESC+2] = '\0';
2466 strcpy(last_destroyed_command, "^L ºÇ¸å¤Ë¼«Æ°Ç˲õ¤·¤¿¥¢¥¤¥Æ¥à̾");
2468 strcpy(last_destroyed_command, "^L Last destroyed object");
2471 ctrl_command_desc[LAST_DESTROYED] = last_destroyed_command;
2473 /* Conditional Expression for Class and Race */
2474 sprintf(classrace, "?:[AND [EQU $RACE %s] [EQU $CLASS %s]]",
2476 rp_ptr->E_title, cp_ptr->E_title
2478 rp_ptr->title, cp_ptr->title
2482 /* Clear yank buffer */
2485 /* Read or initialize whole text */
2486 lines_list = read_pickpref_text_lines();
2488 /* Reset cursor position if needed */
2489 for (i = 0; i < cy; i++)
2498 /* Save the screen */
2501 /* Process requests until done */
2505 Term_get_size(&wid, &hgt);
2508 /* Don't let cursor at second byte of kanji */
2509 for (i = 0; lines_list[cy][i]; i++)
2510 if (iskanji(lines_list[cy][i]))
2521 /* Scroll if necessary */
2522 if (cy < upper || upper + hgt - 4 <= cy)
2523 upper = cy - (hgt-4)/2;
2526 if ((cx < left + 10 && left > 0) || left + wid - WID_DESC - 5 <= cx)
2527 left = cx - (wid - WID_DESC)*2/3;
2531 /* Redraw whole window after resize */
2532 if (old_wid != wid || old_hgt != hgt)
2533 dirty_flags |= DIRTY_SCREEN;
2535 /* Redraw all text after scroll */
2536 else if (old_upper != upper || old_left != left)
2537 dirty_flags |= DIRTY_ALL;
2540 if (dirty_flags & DIRTY_SCREEN)
2542 dirty_flags = DIRTY_ALL | DIRTY_COMMAND | DIRTY_MODE;
2548 if (dirty_flags & DIRTY_COMMAND)
2550 /* Display control command */
2551 for (i = 0; ctrl_command_desc[i]; i++)
2552 Term_putstr(wid - WID_DESC, i + 1, WID_DESC, TERM_WHITE, ctrl_command_desc[i]);
2555 /* Redraw mode line */
2556 if (dirty_flags & DIRTY_MODE)
2558 int sepa_length = wid - WID_DESC;
2561 for (i = 0; i < sepa_length; i++)
2567 strncpy(buf + sepa_length - 21, " (INSERT MODE) ", 16);
2569 strncpy(buf + sepa_length - 21, " (COMMAND MODE) ", 16);
2571 Term_putstr(0, hgt - 3, sepa_length, (byte) (edit_mode ? TERM_YELLOW : TERM_WHITE), buf);
2574 /* Dump up to 20, or hgt-4, lines of messages */
2575 for (i = 0; i < hgt - 4; i++)
2580 /* clean or dirty? */
2581 if (!(dirty_flags & DIRTY_ALL) && (dirty_line != upper+i))
2584 msg = lines_list[upper+i];
2587 /* Apply horizontal scroll */
2588 for (j = 0; *msg; msg++, j++)
2590 if (j == left) break;
2606 Term_erase(0, i + 1, wid - WID_DESC);
2608 /* Dump the messages, bottom to top */
2609 Term_putstr(leftcol, i + 1, wid - WID_DESC - 1, TERM_WHITE, msg);
2612 for (; i < hgt - 4; i++)
2615 Term_erase(0, i + 1, wid - WID_DESC);
2618 /* Display header line */
2621 prt("^Q ESC ¤Ç¥³¥Þ¥ó¥É¥â¡¼¥É¤Ø°Ü¹Ô¡¢Ä̾ï¤Îʸ»ú¤Ï¤½¤Î¤Þ¤ÞÆþÎÏ", 0, 0);
2623 prt("q _ ¤Ç½ªÎ»¡¢hjkl2468 ¤Ç°ÜÆ°¡¢^Q a i ¤ÇÆþÎϥ⡼¥É", 0, 0);
2626 prt("Press ^Q ESC to command mode, any letters to insert", 0, 0);
2628 prt("Press q _ to quit, hjkl2468 to move, ^Q a i to insert mode", 0, 0);
2630 /* Display current position */
2631 prt (format("(%d,%d)", cx, cy), 0, 70);
2633 /* Display information when updated */
2634 if (old_cy != cy || (dirty_flags & DIRTY_ALL) || dirty_line == cy)
2636 /* Clear information line */
2637 Term_erase(0, hgt - 3 + 1, wid);
2638 Term_erase(0, hgt - 3 + 2, wid);
2640 /* Display information */
2641 if (lines_list[cy][0] == '#')
2644 prt("¤³¤Î¹Ô¤Ï¥³¥á¥ó¥È¤Ç¤¹¡£", hgt - 3 + 1, 0);
2646 prt("This line is comment.", hgt - 3 + 1, 0);
2649 else if (lines_list[cy][1] == ':')
2651 switch(lines_list[cy][0])
2655 prt("¤³¤Î¹Ô¤Ï¾ò·ïʬ´ô¼°¤Ç¤¹¡£", hgt - 3 + 1, 0);
2657 prt("This line is Conditional Expression.", hgt - 3 + 1, 0);
2662 prt("¤³¤Î¹Ô¤Ï¥Þ¥¯¥í¤Î¼Â¹ÔÆâÍƤòÄêµÁ¤·¤Þ¤¹¡£", hgt - 3 + 1, 0);
2664 prt("This line defines Macro action.", hgt - 3 + 1, 0);
2669 prt("¤³¤Î¹Ô¤Ï¥Þ¥¯¥í¤Î¥È¥ê¥¬¡¼¡¦¥¡¼¤òÄêµÁ¤·¤Þ¤¹¡£", hgt - 3 + 1, 0);
2671 prt("This line defines Macro trigger key.", hgt - 3 + 1, 0);
2676 prt("¤³¤Î¹Ô¤Ï¥¡¼ÇÛÃÖ¤òÄêµÁ¤·¤Þ¤¹¡£", hgt - 3 + 1, 0);
2678 prt("This line defines Keymap.", hgt - 3 + 1, 0);
2684 /* Get description of an autopicker preference line */
2685 else if (autopick_new_entry(entry, lines_list[cy]))
2690 describe_autopick(buf, entry);
2692 roff_to_buf(buf, 81, temp);
2694 for (i = 0; i< 2; i++)
2700 prt(t, hgt - 3 + 1 + i, 0);
2704 autopick_free_entry(entry);
2709 Term_gotoxy(cx - left, cy - upper + 1);
2715 /* Save old key and location */
2723 /* Do not process macros except special keys */
2724 inkey_special = TRUE;
2735 /* Mode line is now dirty */
2736 dirty_flags |= DIRTY_MODE;
2739 /* Insert a character */
2740 else if (!iscntrl(key&0xff))
2744 /* Save preceding string */
2745 for (i = j = 0; lines_list[cy][i] && i < cx; i++)
2746 buf[j++] = lines_list[cy][i];
2748 /* Add a character */
2754 if (j+2 < MAX_LINELEN)
2766 if (j+1 < MAX_LINELEN)
2772 for (; lines_list[cy][i] && j + 1 < MAX_LINELEN; i++)
2773 buf[j++] = lines_list[cy][i];
2776 /* Replace current line with new line */
2777 string_free(lines_list[cy]);
2778 lines_list[cy] = string_make(buf);
2780 /* Move to correct collumn */
2781 len = strlen(lines_list[cy]);
2782 if (len < cx) cx = len;
2791 if (key == 'q' || key == '_') break;
2798 /* Mode line is now dirty */
2799 dirty_flags |= DIRTY_MODE;
2802 if (!autopick_new_entry(entry, lines_list[cy]))
2804 string_free(lines_list[cy]);
2806 entry->action &= ~DO_AUTODESTROY;
2807 if (entry->action & DO_AUTOPICK)
2809 entry->action &= ~DO_AUTOPICK;
2810 entry->action |= DONT_AUTOPICK;
2814 entry->action &= ~DONT_AUTOPICK;
2815 entry->action |= DO_AUTOPICK;
2818 lines_list[cy] = autopick_line_from_entry(entry);
2824 if (!autopick_new_entry(entry, lines_list[cy]))
2826 string_free(lines_list[cy]);
2828 entry->action &= ~DONT_AUTOPICK;
2829 if (entry->action & DO_AUTOPICK)
2831 entry->action &= ~DO_AUTOPICK;
2832 entry->action |= DO_AUTODESTROY;
2836 entry->action &= ~DO_AUTODESTROY;
2837 entry->action |= DO_AUTOPICK;
2840 lines_list[cy] = autopick_line_from_entry(entry);
2865 while (cy < upper + hgt-4 && lines_list[cy + 1])
2870 while (0 < cy && upper <= cy)
2872 while (0 < upper && cy + 1 < upper + hgt - 4)
2881 while (lines_list[cy + 1])
2887 Term_erase(0, cy - upper + 1, wid - WID_DESC);
2891 Term_putstr(0, cy - upper + 1, wid - WID_DESC - 1, TERM_YELLOW, "P:<¥È¥ê¥¬¡¼¥¡¼>: ");
2893 Term_putstr(0, cy - upper + 1, wid - WID_DESC - 1, TERM_YELLOW, "P:<Trigger key>: ");
2895 if (insert_macro_line(lines_list, cy))
2897 /* Prepare to input action */
2902 dirty_flags |= DIRTY_ALL;
2903 dirty_flags |= DIRTY_MODE;
2910 Term_erase(0, cy - upper + 1, wid - WID_DESC);
2914 Term_putstr(0, cy - upper + 1, wid - WID_DESC - 1, TERM_YELLOW, format("C:%d:<¥³¥Þ¥ó¥É¥¡¼>: ", (rogue_like_commands ? KEYMAP_MODE_ROGUE : KEYMAP_MODE_ORIG)));
2916 Term_putstr(0, cy - upper + 1, wid - WID_DESC - 1, TERM_YELLOW, format("C:%d:<Keypress>: ", (rogue_like_commands ? KEYMAP_MODE_ROGUE : KEYMAP_MODE_ORIG)));
2919 if (insert_keymap_line(lines_list, cy))
2921 /* Prepare to input action */
2926 dirty_flags |= DIRTY_ALL;
2927 dirty_flags |= DIRTY_MODE;
2931 /* Become dirty because of item/equip menu */
2932 dirty_flags |= DIRTY_SCREEN;
2934 if (!get_string_for_search(&search_o_ptr, &search_str))
2938 if (search_for_object(lines_list, search_o_ptr, &cy)) cx = 0;
2940 else if (search_str)
2942 search_for_string(lines_list, search_str, &cx, &cy);
2951 /* Beginning of line */
2959 len = strlen(lines_list[cy]);
2960 if (len < cx) cx = len;
2965 cx = strlen(lines_list[cy]);
2969 /* Insert a conditinal expression line */
2970 insert_return_code(lines_list, 0, cy);
2971 lines_list[cy] = string_make(classrace);
2973 insert_return_code(lines_list, 0, cy);
2974 lines_list[cy] = string_make("?:1");
2978 dirty_flags |= DIRTY_ALL;
2982 cx = strlen(lines_list[cy]);
2987 if (iskanji(lines_list[cy][cx])) cx++;
2990 len = strlen(lines_list[cy]);
2993 if (lines_list[cy + 1])
3003 /* Toggle display on the 'M'ap */
3004 if (!autopick_new_entry(entry, lines_list[cy]))
3006 string_free(lines_list[cy]);
3008 if (entry->action & DO_DISPLAY)
3010 entry->action &= ~DO_DISPLAY;
3015 entry->action |= DO_DISPLAY;
3019 lines_list[cy] = autopick_line_from_entry(entry);
3025 /* Insert choosen item name */
3026 if (!entry_from_choosed_object(entry))
3028 /* Now dirty because of item/equip menu */
3029 dirty_flags |= DIRTY_SCREEN;
3032 tmp = autopick_line_from_entry(entry);
3036 insert_return_code(lines_list, 0, cy);
3037 lines_list[cy] = tmp;
3040 /* Now dirty because of item/equip menu */
3041 dirty_flags |= DIRTY_SCREEN;
3045 /* Insert a name of last destroyed item */
3048 insert_return_code(lines_list, 0, cy);
3049 lines_list[cy] = string_make(last_destroyed);
3053 dirty_flags |= DIRTY_ALL;
3056 case '\n': case '\r':
3057 /* Split a line or insert end of line */
3058 insert_return_code(lines_list, cx, cy);
3063 dirty_flags |= DIRTY_ALL;
3067 if (lines_list[cy + 1]) cy++;
3070 /* Prepare to write auto-inscription text */
3071 if (!autopick_new_entry(entry, lines_list[cy]))
3073 string_free(lines_list[cy]);
3075 if (!entry->insc) entry->insc = string_make("");
3077 lines_list[cy] = autopick_line_from_entry(entry);
3079 /* Move to collumn for auto inscription */
3080 for (cx = 0; lines_list[cy][cx]; cx++)
3081 if (lines_list[cy][cx] == '#') break;
3087 dirty_flags |= DIRTY_MODE;
3095 edit_mode = !edit_mode;
3097 /* Mode line is now dirty */
3098 dirty_flags |= DIRTY_MODE;
3101 /* Revert to original */
3103 if (!get_check("Á´¤Æ¤ÎÊѹ¹¤òÇË´þ¤·¤Æ¸µ¤Î¾õÂÖ¤ËÌᤷ¤Þ¤¹¡£¤è¤í¤·¤¤¤Ç¤¹¤«¡© "))
3105 if (!get_check("Discard all change and revert to original file. Are you sure? "))
3109 free_text_lines(lines_list);
3110 lines_list = read_pickpref_text_lines();
3111 dirty_flags |= DIRTY_ALL | DIRTY_MODE;
3116 /* Rotate action; pickup/destroy/leave */
3117 if (!autopick_new_entry(entry, lines_list[cy]))
3119 string_free(lines_list[cy]);
3121 if (entry->action & DO_AUTOPICK)
3123 entry->action &= ~DO_AUTOPICK;
3124 entry->action |= DO_AUTODESTROY;
3126 else if (entry->action & DO_AUTODESTROY)
3128 entry->action &= ~DO_AUTODESTROY;
3129 entry->action |= DONT_AUTOPICK;
3131 else if (entry->action & DONT_AUTOPICK)
3133 entry->action &= ~DONT_AUTOPICK;
3134 entry->action |= DO_AUTOPICK;
3137 lines_list[cy] = autopick_line_from_entry(entry);
3147 /* Rotate identify-state; identified/unidentified/... */
3148 if (!autopick_new_entry(entry, lines_list[cy]))
3150 string_free(lines_list[cy]);
3152 if (IS_FLG(FLG_UNIDENTIFIED))
3154 REM_FLG(FLG_UNIDENTIFIED);
3155 ADD_FLG(FLG_UNAWARE);
3156 REM_FLG(FLG_IDENTIFIED);
3157 REM_FLG(FLG_STAR_IDENTIFIED);
3159 else if (IS_FLG(FLG_UNAWARE))
3161 REM_FLG(FLG_UNIDENTIFIED);
3162 REM_FLG(FLG_UNAWARE);
3163 ADD_FLG(FLG_IDENTIFIED);
3164 REM_FLG(FLG_STAR_IDENTIFIED);
3166 else if (IS_FLG(FLG_STAR_IDENTIFIED))
3168 REM_FLG(FLG_UNIDENTIFIED);
3169 REM_FLG(FLG_UNAWARE);
3170 REM_FLG(FLG_IDENTIFIED);
3171 REM_FLG(FLG_STAR_IDENTIFIED);
3173 else if (IS_FLG(FLG_IDENTIFIED))
3175 REM_FLG(FLG_UNIDENTIFIED);
3176 REM_FLG(FLG_UNAWARE);
3177 REM_FLG(FLG_IDENTIFIED);
3178 ADD_FLG(FLG_STAR_IDENTIFIED);
3182 ADD_FLG(FLG_UNIDENTIFIED);
3183 REM_FLG(FLG_UNAWARE);
3184 REM_FLG(FLG_IDENTIFIED);
3185 REM_FLG(FLG_STAR_IDENTIFIED);
3188 lines_list[cy] = autopick_line_from_entry(entry);
3195 while (cy < upper + hgt-4 && lines_list[cy + 1])
3200 /* Toggle 'worthless' */
3201 toggle_string(lines_list, FLG_WORTHLESS, cy);
3206 /* Rotate within nameless, ego, artifact */
3207 if (!autopick_new_entry(entry, lines_list[cy]))
3209 string_free(lines_list[cy]);
3211 if (IS_FLG(FLG_NAMELESS))
3213 REM_FLG(FLG_NAMELESS);
3215 REM_FLG(FLG_ARTIFACT);
3217 else if (IS_FLG(FLG_EGO))
3219 REM_FLG(FLG_NAMELESS);
3221 ADD_FLG(FLG_ARTIFACT);
3223 else if (IS_FLG(FLG_ARTIFACT))
3225 REM_FLG(FLG_NAMELESS);
3227 REM_FLG(FLG_ARTIFACT);
3231 ADD_FLG(FLG_NAMELESS);
3233 REM_FLG(FLG_ARTIFACT);
3236 lines_list[cy] = autopick_line_from_entry(entry);
3243 /* Paste killed text */
3244 if (strlen(yank_buf))
3246 for (j = 0; yank_buf[j]; j += strlen(yank_buf + j) + 1)
3250 /* Split current line */
3251 insert_return_code(lines_list, cx, cy);
3253 /* Paste yank buffer */
3254 for(i = 0; lines_list[cy][i]; i++)
3255 buf[i] = lines_list[cy][i];
3256 while (yank_buf[k] && i < MAX_LINELEN)
3257 buf[i++] = yank_buf[k++];
3260 string_free(lines_list[cy]);
3261 lines_list[cy] = string_make(buf);
3263 /* Move to the beggining of next line */
3269 dirty_flags |= DIRTY_ALL;
3273 /* Toggle 'collecting' */
3274 toggle_string(lines_list, FLG_COLLECTING, cy);
3280 /* Kill rest of line */
3281 if (lines_list[cy][0] != '\0' && (uint)cx < strlen(lines_list[cy]))
3283 /* Save preceding string */
3284 for (i = 0; lines_list[cy][i] && i < cx; i++)
3287 if (iskanji(lines_list[cy][i]))
3289 buf[i] = lines_list[cy][i];
3293 buf[i] = lines_list[cy][i];
3298 if (old_key == KTRL('k'))
3300 j += strlen(yank_buf + j) + 1;
3302 /* Copy following to yank buffer */
3303 while (lines_list[cy][i] && j < MAX_YANK - 2)
3304 yank_buf[j++] = lines_list[cy][i++];
3305 yank_buf[j++] = '\0';
3308 /* Replace current line with 'preceding string' */
3309 string_free(lines_list[cy]);
3310 lines_list[cy] = string_make(buf);
3319 /* DELETE == go forward + BACK SPACE */
3321 if (iskanji(lines_list[cy][cx])) cx++;
3329 len = strlen(lines_list[cy]);
3332 if (lines_list[cy + 1])
3346 /* delete a return code and union two lines */
3348 cx = strlen(lines_list[cy-1]);
3349 strcpy(buf, lines_list[cy-1]);
3350 strcat(buf, lines_list[cy]);
3351 string_free(lines_list[cy-1]);
3352 string_free(lines_list[cy]);
3353 lines_list[cy-1] = string_make(buf);
3354 for (i = cy; lines_list[i+1]; i++)
3355 lines_list[i] = lines_list[i+1];
3356 lines_list[i] = NULL;
3360 dirty_flags |= DIRTY_ALL;
3364 for (i = j = 0; lines_list[cy][i] && i < cx; i++)
3368 if (iskanji(lines_list[cy][i]))
3369 buf[j++] = lines_list[cy][i++];
3371 buf[j++] = lines_list[cy][i];
3378 for (; lines_list[cy][i]; i++)
3379 buf[j++] = lines_list[cy][i];
3381 string_free(lines_list[cy]);
3382 lines_list[cy] = string_make(buf);
3391 /* Restore the screen */
3395 sprintf(buf, "picktype-%s.prf", player_name);
3397 sprintf(buf, "pickpref-%s.prf", player_name);
3399 write_text_lines(buf, lines_list);
3400 free_text_lines(lines_list);
3402 string_free(last_destroyed);
3404 /* Reload autopick pref */
3405 process_pickpref_file(buf);