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
23 #define FLG_NAMELESS 5
25 #define FLG_WORTHLESS 7
27 #define FLG_MORE_THAN 9
32 #define FLG_UNREADABLE 14
40 #define FLG_XXX1 22 /* unused */
41 #define FLG_WEAPONS 23
43 #define FLG_MISSILES 25
44 #define FLG_DEVICES 26
47 #define FLG_SPELLBOOKS 29
49 #define FLG_SHIELDS 31
52 #define FLG_AMULETS 34
59 #define FLG_ARTIFACT 41
63 #define KEY_ALL "¤¹¤Ù¤Æ¤Î"
64 #define KEY_COLLECTING "¼ý½¸Ãæ¤Î"
65 #define KEY_UNIDENTIFIED "̤´ÕÄê¤Î"
66 #define KEY_IDENTIFIED "´ÕÄêºÑ¤ß¤Î"
67 #define KEY_STAR_IDENTIFIED "*´ÕÄê*ºÑ¤ß¤Î"
68 #define KEY_NAMELESS "̵ÌäÎ"
69 #define KEY_UNAWARE "̤ȽÌÀ¤Î"
70 #define KEY_WORTHLESS "̵²ÁÃͤÎ"
71 #define KEY_BOOSTED "¥À¥¤¥¹Ìܤΰ㤦"
72 #define KEY_MORE_THAN "¥À¥¤¥¹ÌÜ"
73 #define KEY_DICE "°Ê¾å¤Î"
74 #define KEY_WANTED "¾Þ¶â¼ó¤Î"
75 #define KEY_UNIQUE "¥æ¥Ë¡¼¥¯¡¦¥â¥ó¥¹¥¿¡¼¤Î"
76 #define KEY_HUMAN "¿Í´Ö¤Î"
77 #define KEY_UNREADABLE "Æɤá¤Ê¤¤"
78 #define KEY_REALM1 "Âè°ìÎΰè¤Î"
79 #define KEY_REALM2 "ÂèÆóÎΰè¤Î"
80 #define KEY_FIRST "1ºýÌܤÎ"
81 #define KEY_SECOND "2ºýÌܤÎ"
82 #define KEY_THIRD "3ºýÌܤÎ"
83 #define KEY_FOURTH "4ºýÌܤÎ"
84 #define KEY_ITEMS "¥¢¥¤¥Æ¥à"
86 #define KEY_WEAPONS "Éð´ï"
87 #define KEY_ARMORS "Ëɶñ"
88 #define KEY_MISSILES "Ìð"
89 #define KEY_DEVICES "ËâË¡¥¢¥¤¥Æ¥à"
90 #define KEY_LIGHTS "¸÷¸»"
91 #define KEY_JUNKS "¤¬¤é¤¯¤¿"
92 #define KEY_SPELLBOOKS "ËâË¡½ñ"
93 #define KEY_HAFTED "Æß´ï"
94 #define KEY_SHIELDS "½â"
96 #define KEY_RINGS "»ØÎØ"
97 #define KEY_AMULETS "¥¢¥ß¥å¥ì¥Ã¥È"
98 #define KEY_SUITS "³»"
99 #define KEY_CLOAKS "¥¯¥í¡¼¥¯"
100 #define KEY_HELMS "³õ"
101 #define KEY_GLOVES "äƼê"
102 #define KEY_BOOTS "·¤"
103 #define KEY_EGO "¥¨¥´"
104 #define KEY_ARTIFACT "¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È"
108 #define KEY_ALL "all"
109 #define KEY_COLLECTING "collecting"
110 #define KEY_UNIDENTIFIED "unidentified"
111 #define KEY_IDENTIFIED "identified"
112 #define KEY_STAR_IDENTIFIED "*identified*"
113 #define KEY_NAMELESS "nameless"
114 #define KEY_UNAWARE "unaware"
115 #define KEY_WORTHLESS "worthless"
116 #define KEY_BOOSTED "dice boosted"
117 #define KEY_MORE_THAN "more than "
118 #define KEY_DICE " dice "
119 #define KEY_WANTED "wanted"
120 #define KEY_UNIQUE "unique monster's"
121 #define KEY_HUMAN "human"
122 #define KEY_UNREADABLE "unreadable"
123 #define KEY_REALM1 "first realm's"
124 #define KEY_REALM2 "second realm's"
125 #define KEY_FIRST "first"
126 #define KEY_SECOND "second"
127 #define KEY_THIRD "third"
128 #define KEY_FOURTH "fourth"
129 #define KEY_ITEMS "items"
131 #define KEY_WEAPONS "weapons"
132 #define KEY_ARMORS "armors"
133 #define KEY_MISSILES "missiles"
134 #define KEY_DEVICES "magical devices"
135 #define KEY_LIGHTS "lights"
136 #define KEY_JUNKS "junks"
137 #define KEY_SPELLBOOKS "spellbooks"
138 #define KEY_HAFTED "hafted weapons"
139 #define KEY_SHIELDS "shields"
140 #define KEY_BOWS "bows"
141 #define KEY_RINGS "rings"
142 #define KEY_AMULETS "amulets"
143 #define KEY_SUITS "suits"
144 #define KEY_CLOAKS "cloaks"
145 #define KEY_HELMS "helms"
146 #define KEY_GLOVES "gloves"
147 #define KEY_BOOTS "boots"
148 #define KEY_EGO "ego"
149 #define KEY_ARTIFACT "artifact"
153 #define MATCH_KEY(KEY) (!strncmp(ptr, KEY, sizeof(KEY)-1)\
154 ? (prev_ptr = ptr, ptr += sizeof(KEY)-1, (' '==*ptr) ? ptr++ : 0, TRUE) : FALSE)
157 #define ADD_KEY(KEY) strcat(ptr, KEY)
159 #define ADD_KEY(KEY) (strcat(ptr, KEY), strcat(ptr, " "))
161 #define ADD_KEY2(KEY) strcat(ptr, KEY)
163 #define ADD_FLG(FLG) (entry->flag[FLG / 32] |= (1L << (FLG % 32)))
164 #define REM_FLG(FLG) (entry->flag[FLG / 32] &= ~(1L << (FLG % 32)))
165 #define ADD_FLG2(FLG) (entry->flag[FLG / 32] |= (1L << (FLG % 32)), prev_flg = FLG)
166 #define IS_FLG(FLG) (entry->flag[FLG / 32] & (1L << (FLG % 32)))
169 static char kanji_colon[] = "¡§";
174 * Reconstruct preference line from entry
176 cptr autopick_line_from_entry(autopick_type *entry)
180 bool sepa_flag = TRUE;
183 if (!(entry->action & DO_DISPLAY)) strcat(buf, "(");
184 if (entry->action & DO_AUTODESTROY) strcat(buf, "!");
185 if (entry->action & DONT_AUTOPICK) strcat(buf, "~");
189 if (IS_FLG(FLG_ALL)) ADD_KEY(KEY_ALL);
190 if (IS_FLG(FLG_COLLECTING)) ADD_KEY(KEY_COLLECTING);
191 if (IS_FLG(FLG_UNIDENTIFIED)) ADD_KEY(KEY_UNIDENTIFIED);
192 if (IS_FLG(FLG_IDENTIFIED)) ADD_KEY(KEY_IDENTIFIED);
193 if (IS_FLG(FLG_STAR_IDENTIFIED)) ADD_KEY(KEY_STAR_IDENTIFIED);
194 if (IS_FLG(FLG_ARTIFACT)) ADD_KEY(KEY_ARTIFACT);
195 if (IS_FLG(FLG_EGO)) ADD_KEY(KEY_EGO);
196 if (IS_FLG(FLG_NAMELESS)) ADD_KEY(KEY_NAMELESS);
197 if (IS_FLG(FLG_UNAWARE)) ADD_KEY(KEY_UNAWARE);
198 if (IS_FLG(FLG_WORTHLESS)) ADD_KEY(KEY_WORTHLESS);
199 if (IS_FLG(FLG_BOOSTED)) ADD_KEY(KEY_BOOSTED);
201 if (IS_FLG(FLG_MORE_THAN))
203 ADD_KEY(KEY_MORE_THAN);
204 strcat(ptr, format("%2d", entry->dice));
208 if (IS_FLG(FLG_WANTED)) ADD_KEY(KEY_WANTED);
209 if (IS_FLG(FLG_UNIQUE)) ADD_KEY(KEY_UNIQUE);
210 if (IS_FLG(FLG_HUMAN)) ADD_KEY(KEY_HUMAN);
211 if (IS_FLG(FLG_UNREADABLE)) ADD_KEY(KEY_UNREADABLE);
212 if (IS_FLG(FLG_REALM1)) ADD_KEY(KEY_REALM1);
213 if (IS_FLG(FLG_REALM2)) ADD_KEY(KEY_REALM2);
214 if (IS_FLG(FLG_FIRST)) ADD_KEY(KEY_FIRST);
215 if (IS_FLG(FLG_SECOND)) ADD_KEY(KEY_SECOND);
216 if (IS_FLG(FLG_THIRD)) ADD_KEY(KEY_THIRD);
217 if (IS_FLG(FLG_FOURTH)) ADD_KEY(KEY_FOURTH);
219 if (IS_FLG(FLG_ITEMS)) ADD_KEY2(KEY_ITEMS);
220 else if (IS_FLG(FLG_WEAPONS)) ADD_KEY2(KEY_WEAPONS);
221 else if (IS_FLG(FLG_ARMORS)) ADD_KEY2(KEY_ARMORS);
222 else if (IS_FLG(FLG_MISSILES)) ADD_KEY2(KEY_MISSILES);
223 else if (IS_FLG(FLG_DEVICES)) ADD_KEY2(KEY_DEVICES);
224 else if (IS_FLG(FLG_LIGHTS)) ADD_KEY2(KEY_LIGHTS);
225 else if (IS_FLG(FLG_JUNKS)) ADD_KEY2(KEY_JUNKS);
226 else if (IS_FLG(FLG_SPELLBOOKS)) ADD_KEY2(KEY_SPELLBOOKS);
227 else if (IS_FLG(FLG_HAFTED)) ADD_KEY2(KEY_HAFTED);
228 else if (IS_FLG(FLG_SHIELDS)) ADD_KEY2(KEY_SHIELDS);
229 else if (IS_FLG(FLG_BOWS)) ADD_KEY2(KEY_BOWS);
230 else if (IS_FLG(FLG_RINGS)) ADD_KEY2(KEY_RINGS);
231 else if (IS_FLG(FLG_AMULETS)) ADD_KEY2(KEY_AMULETS);
232 else if (IS_FLG(FLG_SUITS)) ADD_KEY2(KEY_SUITS);
233 else if (IS_FLG(FLG_CLOAKS)) ADD_KEY2(KEY_CLOAKS);
234 else if (IS_FLG(FLG_HELMS)) ADD_KEY2(KEY_HELMS);
235 else if (IS_FLG(FLG_GLOVES)) ADD_KEY2(KEY_GLOVES);
236 else if (IS_FLG(FLG_BOOTS)) ADD_KEY2(KEY_BOOTS);
240 if (entry->name && *entry->name)
244 strcat(buf, entry->name);
248 if (entry->flag[0] == 0L && entry->flag[0] == 0L)
255 strcat(buf, entry->insc);
258 return string_make(buf);
262 * A function to create new entry
264 bool autopick_new_entry(autopick_type *entry, cptr str)
273 if (str[1] == ':') switch (str[0])
276 case 'A': case 'P': case 'C':
280 entry->flag[0] = entry->flag[1] = 0L;
283 act = DO_AUTOPICK | DO_DISPLAY;
286 if ((act & DO_AUTOPICK) && *str == '!')
289 act |= DO_AUTODESTROY;
292 else if ((act & DO_AUTOPICK) && *str == '~')
295 act |= DONT_AUTOPICK;
298 else if ((act & DO_DISPLAY) && *str == '(')
307 /* don't mind upper or lower case */
309 for (i = 0; *str; i++)
320 /* Auto-inscription? */
328 if (isupper(c)) c = tolower(c);
334 /* Skip empty line */
335 if (*buf == 0) return FALSE;
338 prev_ptr = ptr = buf;
340 if (MATCH_KEY(KEY_ALL)) ADD_FLG(FLG_ALL);
341 if (MATCH_KEY(KEY_COLLECTING)) ADD_FLG(FLG_COLLECTING);
342 if (MATCH_KEY(KEY_UNIDENTIFIED)) ADD_FLG(FLG_UNIDENTIFIED);
343 if (MATCH_KEY(KEY_IDENTIFIED)) ADD_FLG(FLG_IDENTIFIED);
344 if (MATCH_KEY(KEY_STAR_IDENTIFIED)) ADD_FLG(FLG_STAR_IDENTIFIED);
345 if (MATCH_KEY(KEY_ARTIFACT)) ADD_FLG(FLG_ARTIFACT);
346 if (MATCH_KEY(KEY_EGO)) ADD_FLG(FLG_EGO);
347 if (MATCH_KEY(KEY_NAMELESS)) ADD_FLG(FLG_NAMELESS);
348 if (MATCH_KEY(KEY_UNAWARE)) ADD_FLG(FLG_UNAWARE);
349 if (MATCH_KEY(KEY_WORTHLESS)) ADD_FLG(FLG_WORTHLESS);
350 if (MATCH_KEY(KEY_BOOSTED)) ADD_FLG(FLG_BOOSTED);
352 /*** Weapons whic dd*ds is more than nn ***/
353 if (MATCH_KEY(KEY_MORE_THAN))
355 if (isdigit(ptr[0]) && isdigit(ptr[1]))
357 entry->dice = (ptr[0] - '0') * 10 + (ptr[1] - '0');
359 (void)MATCH_KEY(KEY_DICE);
360 ADD_FLG(FLG_MORE_THAN);
366 if (MATCH_KEY(KEY_WANTED)) ADD_FLG(FLG_WANTED);
367 if (MATCH_KEY(KEY_UNIQUE)) ADD_FLG(FLG_UNIQUE);
368 if (MATCH_KEY(KEY_HUMAN)) ADD_FLG(FLG_HUMAN);
369 if (MATCH_KEY(KEY_UNREADABLE)) ADD_FLG(FLG_UNREADABLE);
370 if (MATCH_KEY(KEY_REALM1)) ADD_FLG(FLG_REALM1);
371 if (MATCH_KEY(KEY_REALM2)) ADD_FLG(FLG_REALM2);
372 if (MATCH_KEY(KEY_FIRST)) ADD_FLG(FLG_FIRST);
373 if (MATCH_KEY(KEY_SECOND)) ADD_FLG(FLG_SECOND);
374 if (MATCH_KEY(KEY_THIRD)) ADD_FLG(FLG_THIRD);
375 if (MATCH_KEY(KEY_FOURTH)) ADD_FLG(FLG_FOURTH);
377 /* Reset previous word location */
380 if (MATCH_KEY(KEY_ITEMS)) ADD_FLG2(FLG_ITEMS);
381 else if (MATCH_KEY(KEY_WEAPONS)) ADD_FLG2(FLG_WEAPONS);
382 else if (MATCH_KEY(KEY_ARMORS)) ADD_FLG2(FLG_ARMORS);
383 else if (MATCH_KEY(KEY_MISSILES)) ADD_FLG2(FLG_MISSILES);
384 else if (MATCH_KEY(KEY_DEVICES)) ADD_FLG2(FLG_DEVICES);
385 else if (MATCH_KEY(KEY_LIGHTS)) ADD_FLG2(FLG_LIGHTS);
386 else if (MATCH_KEY(KEY_JUNKS)) ADD_FLG2(FLG_JUNKS);
387 else if (MATCH_KEY(KEY_SPELLBOOKS)) ADD_FLG2(FLG_SPELLBOOKS);
388 else if (MATCH_KEY(KEY_HAFTED)) ADD_FLG2(FLG_HAFTED);
389 else if (MATCH_KEY(KEY_SHIELDS)) ADD_FLG2(FLG_SHIELDS);
390 else if (MATCH_KEY(KEY_BOWS)) ADD_FLG2(FLG_BOWS);
391 else if (MATCH_KEY(KEY_RINGS)) ADD_FLG2(FLG_RINGS);
392 else if (MATCH_KEY(KEY_AMULETS)) ADD_FLG2(FLG_AMULETS);
393 else if (MATCH_KEY(KEY_SUITS)) ADD_FLG2(FLG_SUITS);
394 else if (MATCH_KEY(KEY_CLOAKS)) ADD_FLG2(FLG_CLOAKS);
395 else if (MATCH_KEY(KEY_HELMS)) ADD_FLG2(FLG_HELMS);
396 else if (MATCH_KEY(KEY_GLOVES)) ADD_FLG2(FLG_GLOVES);
397 else if (MATCH_KEY(KEY_BOOTS)) ADD_FLG2(FLG_BOOTS);
399 /* Last 'keyword' must be at the correct location */
402 else if (*ptr == '\0')
403 ; /* nothing to do */
405 else if (ptr[0] == kanji_colon[0] && ptr[1] == kanji_colon[1])
411 entry->flag[prev_flg/32] &= ~(1L<< (prev_flg%32));
414 entry->name = string_make(ptr);
416 entry->insc = string_make(insc);
422 * A function to delete entry
424 void autopick_free_entry(autopick_type *entry)
426 string_free(entry->name);
427 string_free(entry->insc);
431 * A function for Auto-picker/destroyer
432 * Examine whether the object matches to the list of keywords or not.
434 int is_autopick(object_type *o_ptr)
437 char o_name[MAX_NLEN];
439 if (o_ptr->tval == TV_GOLD) return -1;
441 object_desc(o_name, o_ptr, FALSE, 3);
443 /* Force to be lower case string */
444 for (i = 0; o_name[i]; i++)
447 if (iskanji(o_name[i]))
451 if (isupper(o_name[i]))
452 o_name[i] = tolower(o_name[i]);
455 for (i=0; i < max_autopick; i++)
457 autopick_type *entry = &autopick_list[i];
459 cptr ptr = autopick_list[i].name;
461 /*** Unidentified ***/
462 if (IS_FLG(FLG_UNIDENTIFIED)
463 && (object_known_p(o_ptr) || (o_ptr->ident & IDENT_SENSE)))
467 if (IS_FLG(FLG_IDENTIFIED) && !object_known_p(o_ptr))
470 /*** *Identified* ***/
471 if (IS_FLG(FLG_STAR_IDENTIFIED) &&
472 (!object_known_p(o_ptr) || !(o_ptr->ident & IDENT_MENTAL)))
475 /*** Artifact object ***/
476 if (IS_FLG(FLG_ARTIFACT))
478 if (!object_known_p(o_ptr) || (!o_ptr->name1 && !o_ptr->art_name))
485 if (!object_known_p(o_ptr) || !o_ptr->name2)
490 if (IS_FLG(FLG_NAMELESS))
495 case TV_SHOT: case TV_ARROW: case TV_BOLT: case TV_BOW:
496 case TV_DIGGING: case TV_HAFTED: case TV_POLEARM: case TV_SWORD:
497 case TV_BOOTS: case TV_GLOVES: case TV_HELM: case TV_CROWN:
498 case TV_SHIELD: case TV_CLOAK:
499 case TV_SOFT_ARMOR: case TV_HARD_ARMOR: case TV_DRAG_ARMOR:
500 case TV_LITE: case TV_AMULET: case TV_RING: case TV_CARD:
501 if ((!object_known_p(o_ptr) || o_ptr->inscription
502 || o_ptr->name1 || o_ptr->name2 || o_ptr->art_name))
511 /*** Unaware items ***/
512 if (IS_FLG(FLG_UNAWARE) && object_aware_p(o_ptr))
515 /*** Worthless items ***/
516 if (IS_FLG(FLG_WORTHLESS) && object_value(o_ptr) > 0)
519 /*** Dice boosted (weapon of slaying) ***/
520 if (IS_FLG(FLG_BOOSTED))
522 object_kind *k_ptr = &k_info[o_ptr->k_idx];
524 switch( o_ptr->tval )
530 if ((o_ptr->dd != k_ptr->dd) || (o_ptr->ds != k_ptr->ds))
539 /*** Weapons whic dd*ds is more than nn ***/
540 if (IS_FLG(FLG_MORE_THAN))
542 if (o_ptr->dd * o_ptr->ds < entry->dice)
546 /*** Wanted monster's corpse/skeletons ***/
547 if (IS_FLG(FLG_WANTED) &&
548 (o_ptr->tval != TV_CORPSE || !object_is_shoukinkubi(o_ptr)))
551 /*** Unique monster's corpse/skeletons/statues ***/
552 if (IS_FLG(FLG_UNIQUE) &&
553 ((o_ptr->tval != TV_CORPSE && o_ptr->tval != TV_STATUE) ||
554 !(r_info[o_ptr->pval].flags1 & RF1_UNIQUE)))
557 /*** Human corpse/skeletons (for Daemon magic) ***/
558 if (IS_FLG(FLG_HUMAN) &&
559 (o_ptr->tval != TV_CORPSE ||
560 !strchr("pht", r_info[o_ptr->pval].d_char)))
563 /*** Unreadable spellbooks ***/
564 if (IS_FLG(FLG_UNREADABLE) &&
565 (o_ptr->tval < TV_LIFE_BOOK ||
566 check_book_realm(o_ptr->tval, o_ptr->sval)))
569 /*** First realm spellbooks ***/
570 if (IS_FLG(FLG_REALM1) &&
571 (REALM1_BOOK != o_ptr->tval ||
572 p_ptr->pclass == CLASS_SORCERER ||
573 p_ptr->pclass == CLASS_RED_MAGE))
576 /*** Second realm spellbooks ***/
577 if (IS_FLG(FLG_REALM2) &&
578 (REALM2_BOOK != o_ptr->tval ||
579 p_ptr->pclass == CLASS_SORCERER ||
580 p_ptr->pclass == CLASS_RED_MAGE))
583 /*** First rank spellbooks ***/
584 if (IS_FLG(FLG_FIRST) &&
585 (o_ptr->tval < TV_LIFE_BOOK || 0 != o_ptr->sval))
588 /*** Second rank spellbooks ***/
589 if (IS_FLG(FLG_SECOND) &&
590 (o_ptr->tval < TV_LIFE_BOOK || 1 != o_ptr->sval))
593 /*** Third rank spellbooks ***/
594 if (IS_FLG(FLG_THIRD) &&
595 (o_ptr->tval < TV_LIFE_BOOK || 2 != o_ptr->sval))
598 /*** Fourth rank spellbooks ***/
599 if (IS_FLG(FLG_FOURTH) &&
600 (o_ptr->tval < TV_LIFE_BOOK || 3 != o_ptr->sval))
604 if (IS_FLG(FLG_WEAPONS))
608 case TV_BOW: case TV_HAFTED: case TV_POLEARM:
609 case TV_SWORD: case TV_DIGGING:
614 else if (IS_FLG(FLG_ARMORS))
618 case TV_BOOTS: case TV_GLOVES: case TV_CLOAK: case TV_CROWN:
619 case TV_HELM: case TV_SHIELD: case TV_SOFT_ARMOR:
620 case TV_HARD_ARMOR: case TV_DRAG_ARMOR:
625 else if (IS_FLG(FLG_MISSILES))
629 case TV_SHOT: case TV_BOLT: case TV_ARROW:
634 else if (IS_FLG(FLG_DEVICES))
638 case TV_SCROLL: case TV_STAFF: case TV_WAND: case TV_ROD:
643 else if (IS_FLG(FLG_LIGHTS))
645 if (!(o_ptr->tval == TV_LITE))
648 else if (IS_FLG(FLG_JUNKS))
652 case TV_SKELETON: case TV_BOTTLE:
653 case TV_JUNK: case TV_STATUE:
658 else if (IS_FLG(FLG_SPELLBOOKS))
660 if (!(o_ptr->tval >= TV_LIFE_BOOK))
663 else if (IS_FLG(FLG_HAFTED))
665 if (!(o_ptr->tval == TV_HAFTED))
668 else if (IS_FLG(FLG_SHIELDS))
670 if (!(o_ptr->tval == TV_SHIELD))
673 else if (IS_FLG(FLG_BOWS))
675 if (!(o_ptr->tval == TV_BOW))
678 else if (IS_FLG(FLG_RINGS))
680 if (!(o_ptr->tval == TV_RING))
683 else if (IS_FLG(FLG_AMULETS))
685 if (!(o_ptr->tval == TV_AMULET))
688 else if (IS_FLG(FLG_SUITS))
690 if (!(o_ptr->tval == TV_DRAG_ARMOR ||
691 o_ptr->tval == TV_HARD_ARMOR ||
692 o_ptr->tval == TV_SOFT_ARMOR))
695 else if (IS_FLG(FLG_CLOAKS))
697 if (!(o_ptr->tval == TV_CLOAK))
700 else if (IS_FLG(FLG_HELMS))
702 if (!(o_ptr->tval == TV_CROWN || o_ptr->tval == TV_HELM))
705 else if (IS_FLG(FLG_GLOVES))
707 if (!(o_ptr->tval == TV_GLOVES))
710 else if (IS_FLG(FLG_BOOTS))
712 if (!(o_ptr->tval == TV_BOOTS))
720 if (!strncmp(o_name, ptr, strlen(ptr)))
725 if (strstr_j(o_name, ptr))
727 if (strstr(o_name, ptr))
736 if (!IS_FLG(FLG_COLLECTING))
738 /* Check if there is a same item */
739 for (j = 0; j < INVEN_PACK; j++)
742 * 'Collecting' means the item must be absorbed
743 * into an inventory slot.
744 * But an item can not be absorbed into itself!
746 if ((&inventory[j] != o_ptr) &&
747 object_similar(&inventory[j], o_ptr))
758 * Automatically destroy items in this grid.
760 static bool is_opt_confirm_destroy(object_type *o_ptr)
762 if (!destroy_items) return FALSE;
764 /* Known to be worthless? */
766 if (object_value(o_ptr) > 0) return FALSE;
769 if ((o_ptr->tval >= TV_SHOT) && (o_ptr->tval <= TV_DRAG_ARMOR)) return FALSE;
772 if ((o_ptr->tval == TV_CHEST) && o_ptr->pval) return FALSE;
776 if (o_ptr->tval == TV_CORPSE
777 && object_is_shoukinkubi(o_ptr)) return FALSE;
781 if (o_ptr->tval == TV_CORPSE) return FALSE;
784 if ((o_ptr->tval == TV_SKELETON) || (o_ptr->tval == TV_BOTTLE) || (o_ptr->tval == TV_JUNK) || (o_ptr->tval == TV_STATUE)) return FALSE;
786 if (o_ptr->tval == TV_GOLD) return FALSE;
795 void auto_inscribe_item(int item, int idx)
799 /* Get the item (in the pack) */
800 if (item >= 0) o_ptr = &inventory[item];
802 /* Get the item (on the floor) */
803 else o_ptr = &o_list[0 - item];
805 if (idx >= 0 && autopick_list[idx].insc && !o_ptr->inscription)
807 o_ptr->inscription = inscribe_flags(o_ptr, autopick_list[idx].insc);
809 if (item >= INVEN_RARM)
811 /* Redraw inscription */
812 p_ptr->window |= (PW_EQUIP);
814 /* {.} and {$} effect p_ptr->warning and TRC_TELEPORT_SELF */
815 p_ptr->update |= (PU_BONUS);
819 /* Redraw inscription */
820 p_ptr->window |= (PW_INVEN);
827 * Automatically destroy an item if it is to be destroyed
829 bool auto_destroy_item(int item, int autopick_idx)
831 char o_name[MAX_NLEN];
834 /* Get the item (in the pack) */
835 if (item >= 0) o_ptr = &inventory[item];
837 /* Get the item (on the floor) */
838 else o_ptr = &o_list[0 - item];
840 if ((autopick_idx == -1 && is_opt_confirm_destroy(o_ptr)) ||
841 (autopick_idx >= 0 && (autopick_list[autopick_idx].action & DO_AUTODESTROY)))
845 /* Describe the object (with {terrible/special}) */
846 object_desc(o_name, o_ptr, TRUE, 3);
849 if (!can_player_destroy_object(o_ptr))
853 msg_format("%s¤ÏÇ˲õÉÔǽ¤À¡£", o_name);
855 msg_format("You cannot auto-destroy %s.", o_name);
862 /* Record name of destroyed item */
863 autopick_free_entry(&autopick_entry_last_destroyed);
864 autopick_entry_from_object(&autopick_entry_last_destroyed, o_ptr);
866 /* Eliminate the item (from the pack) */
869 inven_item_increase(item, -(o_ptr->number));
870 inven_item_optimize(item);
873 /* Eliminate the item (from the floor) */
876 delete_object_idx(0 - item);
879 /* Print a message */
881 msg_format("%s¤ò¼«Æ°Ç˲õ¤·¤Þ¤¹¡£", o_name);
883 msg_format("Auto-destroying %s.", o_name);
894 * Automatically pickup/destroy items in this grid.
896 void auto_pickup_items(cave_type *c_ptr)
898 s16b this_o_idx, next_o_idx = 0;
900 /* Scan the pile of objects */
901 for (this_o_idx = c_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
906 object_type *o_ptr = &o_list[this_o_idx];
908 /* Acquire next object */
909 next_o_idx = o_ptr->next_o_idx;
911 idx = is_autopick(o_ptr);
913 /* Item index for floor -1,-2,-3,... */
914 auto_inscribe_item((-this_o_idx), idx);
916 if (idx >= 0 && (autopick_list[idx].action & DO_AUTOPICK))
920 if (!inven_carry_okay(o_ptr))
922 char o_name[MAX_NLEN];
924 /* Describe the object */
925 object_desc(o_name, o_ptr, TRUE, 3);
929 msg_format("¥¶¥Ã¥¯¤Ë¤Ï%s¤òÆþ¤ì¤ë·ä´Ö¤¬¤Ê¤¤¡£", o_name);
931 msg_format("You have no room for %s.", o_name);
935 py_pickup_aux(this_o_idx);
942 * When always_pickup is 'yes', we disable
943 * auto-destroyer from autopick function, and do only
944 * easy-auto-destroyer.
948 if (auto_destroy_item((-this_o_idx), (!always_pickup ? idx : -2)))
956 * Describe which kind of object is Auto-picked/destroyed
958 static void describe_autopick(char *buff, autopick_type *entry)
960 cptr str = entry->name;
961 byte act = entry->action;
962 cptr insc = entry->insc;
968 cptr before_str[20], body_str;
971 body_str = "¥¢¥¤¥Æ¥à";
973 /*** Collecting items ***/
974 /*** Which can be absorbed into a slot as a bundle ***/
975 if (IS_FLG(FLG_COLLECTING))
976 before_str[before_n++] = "¼ý½¸Ãæ¤Ç´û¤Ë»ý¤Ã¤Æ¤¤¤ë¥¹¥í¥Ã¥È¤Ë¤Þ¤È¤á¤é¤ì¤ë";
978 /*** Unidentified ***/
979 if (IS_FLG(FLG_UNIDENTIFIED))
980 before_str[before_n++] = "̤´ÕÄê¤Î";
983 if (IS_FLG(FLG_IDENTIFIED))
984 before_str[before_n++] = "´ÕÄêºÑ¤ß¤Î";
986 /*** *Identified* ***/
987 if (IS_FLG(FLG_STAR_IDENTIFIED))
988 before_str[before_n++] = "´°Á´¤Ë´ÕÄêºÑ¤ß¤Î";
991 if (IS_FLG(FLG_ARTIFACT))
993 before_str[before_n++] = "¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È¤Î";
1000 before_str[before_n++] = "¥¨¥´¥¢¥¤¥Æ¥à¤Î";
1005 if (IS_FLG(FLG_NAMELESS))
1007 before_str[before_n++] = "¥¨¥´¤Ç¤â¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È¤Ç¤â¤Ê¤¤";
1011 /*** Unaware items ***/
1012 if (IS_FLG(FLG_UNAWARE))
1013 before_str[before_n++] = "̤´ÕÄê¤Ç¤½¤Î¸ú²Ì¤âȽÌÀ¤·¤Æ¤¤¤Ê¤¤";
1015 /*** Worthless items ***/
1016 if (IS_FLG(FLG_WORTHLESS))
1017 before_str[before_n++] = "Ź¤Ç̵²ÁÃͤÈȽÄꤵ¤ì¤ë";
1019 /*** Dice boosted (weapon of slaying) ***/
1020 if (IS_FLG(FLG_BOOSTED))
1022 before_str[before_n++] = "¥À¥á¡¼¥¸¥À¥¤¥¹¤¬Ä̾ï¤è¤êÂ礤¤";
1026 /*** Weapons whose dd*ds is more than nn ***/
1027 if (IS_FLG(FLG_MORE_THAN))
1029 static char more_than_desc_str[] = "___";
1030 before_str[before_n++] = "¥À¥á¡¼¥¸¥À¥¤¥¹¤ÎºÇÂçÃͤ¬";
1033 sprintf(more_than_desc_str,"%2d", entry->dice);
1034 before_str[before_n++] = more_than_desc_str;
1035 before_str[before_n++] = "°Ê¾å¤Î";
1038 /*** Wanted monster's corpse/skeletons ***/
1039 if (IS_FLG(FLG_WANTED))
1041 before_str[before_n++] = "¥Ï¥ó¥¿¡¼»ö̳½ê¤Ç¾Þ¶â¼ó¤È¤µ¤ì¤Æ¤¤¤ë";
1042 body_str = "»àÂΤä¹ü";
1045 /*** Human corpse/skeletons (for Daemon magic) ***/
1046 if (IS_FLG(FLG_HUMAN))
1048 before_str[before_n++] = "°ËâËâË¡¤Ç»È¤¦¤¿¤á¤Î¿Í´Ö¤ä¥Ò¥å¡¼¥Þ¥Î¥¤¥É¤Î";
1049 body_str = "»àÂΤä¹ü";
1052 /*** Unique monster's corpse/skeletons/statues ***/
1053 if (IS_FLG(FLG_UNIQUE))
1055 before_str[before_n++] = "¥æ¥Ë¡¼¥¯¥â¥ó¥¹¥¿¡¼¤Î";
1056 body_str = "»àÂΤä¹ü";
1059 /*** Unreadable spellbooks ***/
1060 if (IS_FLG(FLG_UNREADABLE))
1062 before_str[before_n++] = "Îΰ褬°Û¤Ê¤ë°Ù¤Ë¤¢¤Ê¤¿¤Ë¤ÏÆɤá¤Ê¤¤";
1063 body_str = "ËâË¡½ñ";
1066 /*** First realm spellbooks ***/
1067 if (IS_FLG(FLG_REALM1))
1069 before_str[before_n++] = "Âè°ìÎΰè¤Î";
1070 body_str = "ËâË¡½ñ";
1073 /*** Second realm spellbooks ***/
1074 if (IS_FLG(FLG_REALM2))
1076 before_str[before_n++] = "ÂèÆóÎΰè¤Î";
1077 body_str = "ËâË¡½ñ";
1080 /*** First rank spellbooks ***/
1081 if (IS_FLG(FLG_FIRST))
1083 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î1ºýÌܤÎ";
1084 body_str = "ËâË¡½ñ";
1087 /*** Second rank spellbooks ***/
1088 if (IS_FLG(FLG_SECOND))
1090 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î2ºýÌܤÎ";
1091 body_str = "ËâË¡½ñ";
1094 /*** Third rank spellbooks ***/
1095 if (IS_FLG(FLG_THIRD))
1097 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î3ºýÌܤÎ";
1098 body_str = "ËâË¡½ñ";
1101 /*** Fourth rank spellbooks ***/
1102 if (IS_FLG(FLG_FOURTH))
1104 before_str[before_n++] = "Á´4ºý¤ÎÆâ¤Î4ºýÌܤÎ";
1105 body_str = "ËâË¡½ñ";
1109 if (IS_FLG(FLG_ITEMS))
1110 ; /* Nothing to do */
1111 else if (IS_FLG(FLG_WEAPONS))
1113 else if (IS_FLG(FLG_ARMORS))
1115 else if (IS_FLG(FLG_MISSILES))
1116 body_str = "ÃƤäÌð¤ä¥¯¥í¥¹¥Ü¥¦¤ÎÌð";
1117 else if (IS_FLG(FLG_DEVICES))
1118 body_str = "´¬Êª¤äËâË¡ËÀ¤ä¾ó¤ä¥í¥Ã¥É";
1119 else if (IS_FLG(FLG_LIGHTS))
1120 body_str = "¸÷¸»ÍѤΥ¢¥¤¥Æ¥à";
1121 else if (IS_FLG(FLG_JUNKS))
1122 body_str = "Àޤ줿ËÀÅù¤Î¥¬¥é¥¯¥¿";
1123 else if (IS_FLG(FLG_SPELLBOOKS))
1124 body_str = "ËâË¡½ñ";
1125 else if (IS_FLG(FLG_HAFTED))
1127 else if (IS_FLG(FLG_SHIELDS))
1129 else if (IS_FLG(FLG_BOWS))
1130 body_str = "¥¹¥ê¥ó¥°¤äµÝ¤ä¥¯¥í¥¹¥Ü¥¦";
1131 else if (IS_FLG(FLG_RINGS))
1133 else if (IS_FLG(FLG_AMULETS))
1134 body_str = "¥¢¥ß¥å¥ì¥Ã¥È";
1135 else if (IS_FLG(FLG_SUITS))
1137 else if (IS_FLG(FLG_CLOAKS))
1138 body_str = "¥¯¥í¡¼¥¯";
1139 else if (IS_FLG(FLG_HELMS))
1140 body_str = "¥Ø¥ë¥á¥Ã¥È¤ä´§";
1141 else if (IS_FLG(FLG_GLOVES))
1143 else if (IS_FLG(FLG_BOOTS))
1144 body_str = "¥Ö¡¼¥Ä";
1148 strcat(buff, "Á´¤Æ¤Î");
1149 else for (i = 0; i < before_n && before_str[i]; i++)
1150 strcat(buff, before_str[i]);
1152 strcat(buff, body_str);
1162 strcat(buff, "¤Ç¡¢Ì¾Á°¤¬¡Ö");
1163 strncat(buff, str, 80);
1165 strcat(buff, "¡×¤Ç»Ï¤Þ¤ë¤â¤Î");
1167 strcat(buff, "¡×¤ò´Þ¤à¤â¤Î");
1171 strncat(buff, format("¤Ë¡Ö%s¡×¤È¹ï¤ó¤Ç", insc), 80);
1175 if (act & DONT_AUTOPICK)
1176 strcat(buff, "ÊüÃÖ¤¹¤ë¡£");
1177 else if (act & DO_AUTODESTROY)
1178 strcat(buff, "Ç˲õ¤¹¤ë¡£");
1180 strcat(buff, "½¦¤¦¡£");
1182 if (act & DO_DISPLAY)
1184 if (act & DONT_AUTOPICK)
1185 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'N'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
1186 else if (act & DO_AUTODESTROY)
1187 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'K'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
1189 strcat(buff, "Á´ÂΥޥå×('M')¤Ç'M'¤ò²¡¤·¤¿¤È¤¤Ëɽ¼¨¤¹¤ë¡£");
1192 strcat(buff, "Á´ÂΥޥåפˤÏɽ¼¨¤·¤Ê¤¤");
1196 cptr before_str[20], after_str[20], which_str[20], whose_str[20], body_str;
1197 int before_n = 0, after_n = 0, which_n = 0, whose_n = 0;
1201 /*** Collecting items ***/
1202 /*** Which can be absorbed into a slot as a bundle ***/
1203 if (IS_FLG(FLG_COLLECTING))
1204 which_str[which_n++] = "can be absorbed into an existing inventory slot";
1206 /*** Unidentified ***/
1207 if (IS_FLG(FLG_UNIDENTIFIED))
1208 before_str[before_n++] = "unidentified";
1210 /*** Identified ***/
1211 if (IS_FLG(FLG_IDENTIFIED))
1212 before_str[before_n++] = "identified";
1214 /*** *Identified* ***/
1215 if (IS_FLG(FLG_STAR_IDENTIFIED))
1216 before_str[before_n++] = "fully identified";
1219 if (IS_FLG(FLG_ARTIFACT))
1221 before_str[before_n++] = "artifact";
1225 if (IS_FLG(FLG_EGO))
1227 before_str[before_n++] = "ego";
1231 if (IS_FLG(FLG_NAMELESS))
1233 body_str = "equipment";
1234 which_str[which_n++] = "is neither ego-item nor artifact";
1237 /*** Unaware items ***/
1238 if (IS_FLG(FLG_UNAWARE))
1240 before_str[before_n++] = "unidentified";
1241 whose_str[whose_n++] = "basic abilities are not known";
1244 /*** Worthless items ***/
1245 if (IS_FLG(FLG_WORTHLESS))
1247 before_str[before_n++] = "worthless";
1248 which_str[which_n++] = "can not be sold at stores";
1251 /*** Dice boosted (weapon of slaying) ***/
1252 if (IS_FLG(FLG_BOOSTED))
1254 body_str = "weapons";
1255 whose_str[whose_n++] = "damage dice is bigger than normal";
1258 /*** Weapons whic dd*ds is more than nn ***/
1259 if (IS_FLG(FLG_MORE_THAN))
1261 static char more_than_desc_str[] =
1262 "maximum damage from dice is bigger than __";
1263 body_str = "weapons";
1265 sprintf(more_than_desc_str + sizeof(more_than_desc_str) - 3,
1266 "%2d", entry->dice);
1267 whose_str[whose_n++] = more_than_desc_str;
1270 /*** Wanted monster's corpse/skeletons ***/
1271 if (IS_FLG(FLG_WANTED))
1273 body_str = "corpse or skeletons";
1274 which_str[which_n++] = "is wanted at the Hunter's Office";
1277 /*** Human corpse/skeletons (for Daemon magic) ***/
1278 if (IS_FLG(FLG_HUMAN))
1280 before_str[before_n++] = "humanoid";
1281 body_str = "corpse or skeletons";
1282 which_str[which_n++] = "can be used for Daemon magic";
1285 /*** Unique monster's corpse/skeletons/statues ***/
1286 if (IS_FLG(FLG_UNIQUE))
1288 before_str[before_n++] = "unique monster's";
1289 body_str = "corpse or skeletons";
1292 /*** Unreadable spellbooks ***/
1293 if (IS_FLG(FLG_UNREADABLE))
1295 body_str = "spellbooks";
1296 after_str[after_n++] = "of different realms from yours";
1299 /*** First realm spellbooks ***/
1300 if (IS_FLG(FLG_REALM1))
1302 body_str = "spellbooks";
1303 after_str[after_n++] = "of your first realm";
1306 /*** Second realm spellbooks ***/
1307 if (IS_FLG(FLG_REALM2))
1309 body_str = "spellbooks";
1310 after_str[after_n++] = "of your second realm";
1313 /*** First rank spellbooks ***/
1314 if (IS_FLG(FLG_FIRST))
1316 before_str[before_n++] = "first one of four";
1317 body_str = "spellbooks";
1320 /*** Second rank spellbooks ***/
1321 if (IS_FLG(FLG_SECOND))
1323 before_str[before_n++] = "second one of four";
1324 body_str = "spellbooks";
1327 /*** Third rank spellbooks ***/
1328 if (IS_FLG(FLG_THIRD))
1330 before_str[before_n++] = "third one of four";
1331 body_str = "spellbooks";
1334 /*** Fourth rank spellbooks ***/
1335 if (IS_FLG(FLG_FOURTH))
1337 before_str[before_n++] = "fourth one of four";
1338 body_str = "spellbooks";
1342 if (IS_FLG(FLG_ITEMS))
1343 ; /* Nothing to do */
1344 else if (IS_FLG(FLG_WEAPONS))
1345 body_str = "weapons";
1346 else if (IS_FLG(FLG_ARMORS))
1347 body_str = "armors";
1348 else if (IS_FLG(FLG_MISSILES))
1349 body_str = "shots, arrows or crossbow bolts";
1350 else if (IS_FLG(FLG_DEVICES))
1351 body_str = "scrolls, wands, staves or rods";
1352 else if (IS_FLG(FLG_LIGHTS))
1353 body_str = "light sources";
1354 else if (IS_FLG(FLG_JUNKS))
1355 body_str = "junk such as broken sticks";
1356 else if (IS_FLG(FLG_SPELLBOOKS))
1357 body_str = "spellbooks";
1358 else if (IS_FLG(FLG_HAFTED))
1359 body_str = "hafted weapons";
1360 else if (IS_FLG(FLG_SHIELDS))
1361 body_str = "shields";
1362 else if (IS_FLG(FLG_BOWS))
1363 body_str = "slings, bows or crossbows";
1364 else if (IS_FLG(FLG_RINGS))
1366 else if (IS_FLG(FLG_AMULETS))
1367 body_str = "amulets";
1368 else if (IS_FLG(FLG_SUITS))
1369 body_str = "body armors";
1370 else if (IS_FLG(FLG_CLOAKS))
1371 body_str = "cloaks";
1372 else if (IS_FLG(FLG_HELMS))
1373 body_str = "helms or crowns";
1374 else if (IS_FLG(FLG_GLOVES))
1375 body_str = "gloves";
1376 else if (IS_FLG(FLG_BOOTS))
1379 /* Prepare a string for item name */
1386 whose_str[whose_n++] = "name is beginning with \"";
1389 which_str[which_n++] = "have \"";
1393 /* Describe action flag */
1394 if (act & DONT_AUTOPICK)
1395 strcpy(buff, "Leave on floor ");
1396 else if (act & DO_AUTODESTROY)
1397 strcpy(buff, "Destroy ");
1399 strcpy(buff, "Pickup ");
1401 /* Auto-insctiption */
1403 strncat(buff, format("and inscribe \"%s\" on ", insc), 80);
1407 strcat(buff, "all ");
1408 else for (i = 0; i < before_n && before_str[i]; i++)
1410 strcat(buff, before_str[i]);
1415 strcat(buff, body_str);
1418 for (i = 0; i < after_n && after_str[i]; i++)
1421 strcat(buff, after_str[i]);
1425 for (i = 0; i < whose_n && whose_str[i]; i++)
1428 strcat(buff, " whose ");
1430 strcat(buff, ", and ");
1432 strcat(buff, whose_str[i]);
1435 /* Item name ; whose name is beginning with "str" */
1442 /* whose ..., and which .... */
1443 if (whose_n && which_n)
1444 strcat(buff, ", and ");
1447 for (i = 0; i < which_n && which_str[i]; i++)
1450 strcat(buff, " which ");
1452 strcat(buff, ", and ");
1454 strcat(buff, which_str[i]);
1457 /* Item name ; which have "str" as part of its name */
1460 strncat(buff, str, 80);
1461 strcat(buff, "\" as part of its name");
1465 /* Describe whether it will be displayed on the full map or not */
1466 if (act & DO_DISPLAY)
1468 if (act & DONT_AUTOPICK)
1469 strcat(buff, " Display these items when you press 'N' in the full map('M').");
1470 else if (act & DO_AUTODESTROY)
1471 strcat(buff, " Display these items when you press 'K' in the full map('M').");
1473 strcat(buff, " Display these items when you press 'M' in the full map('M').");
1476 strcat(buff, " Not displayed in the full map.");
1482 #define MAX_LINES 3000
1485 * Read whole lines of a file to memory
1487 static cptr *read_text_lines(cptr filename, bool user)
1489 cptr *lines_list = NULL;
1497 /* Hack -- drop permissions */
1499 path_build(buf, 1024, ANGBAND_DIR_USER, filename);
1503 path_build(buf, 1024, ANGBAND_DIR_PREF, filename);
1507 fff = my_fopen(buf, "r");
1511 /* Allocate list of pointers */
1512 C_MAKE(lines_list, MAX_LINES, cptr);
1515 while (0 == my_fgets(fff, buf, 1024))
1517 lines_list[lines++] = string_make(buf);
1518 if (lines >= MAX_LINES - 1) break;
1521 lines_list[0] = string_make("");
1529 if (!fff) return NULL;
1533 static cptr *read_pickpref_text_lines(void)
1539 sprintf(buf, "picktype-%s.prf", player_name);
1541 sprintf(buf, "pickpref-%s.prf", player_name);
1543 lines_list = read_text_lines(buf, TRUE);
1548 lines_list = read_text_lines("picktype.prf", TRUE);
1550 lines_list = read_text_lines("pickpref.prf", TRUE);
1557 lines_list = read_text_lines("picktype.prf", FALSE);
1559 lines_list = read_text_lines("pickpref.prf", FALSE);
1565 /* Allocate list of pointers */
1566 C_MAKE(lines_list, MAX_LINES, cptr);
1567 lines_list[0] = string_make("");
1573 * Write whole lines of memory to a file.
1575 static bool write_text_lines(cptr filename, cptr *lines_list)
1582 /* Hack -- drop permissions */
1585 /* Build the filename */
1586 path_build(buf, 1024, ANGBAND_DIR_USER, filename);
1589 fff = my_fopen(buf, "w");
1592 for (lines = 0; lines_list[lines]; lines++)
1593 my_fputs(fff, lines_list[lines], 1024);
1601 if (!fff) return FALSE;
1607 * Free memory of lines_list.
1609 static void free_text_lines(cptr *lines_list)
1613 for (lines = 0; lines_list[lines]; lines++)
1614 string_free(lines_list[lines]);
1616 /* free list of pointers */
1617 C_FREE((char **)lines_list, MAX_LINES, char *);
1624 static void insert_string(cptr *lines_list, cptr str, int x, int y)
1629 for (i = j = 0; lines_list[y][i] && i < x; i++)
1630 buf[j++] = lines_list[y][i];
1632 while (*str) buf[j++] = *str++;
1634 for (; lines_list[y][i]; i++)
1635 buf[j++] = lines_list[y][i];
1637 string_free(lines_list[y]);
1638 lines_list[y] = string_make(buf);
1644 static void delete_string(cptr *lines_list, int n, int x, int y)
1649 for (i = j = 0; lines_list[y][i] && i < x; i++)
1652 if (iskanji(lines_list[y][i]))
1653 buf[j++] = lines_list[y][i++];
1655 buf[j++] = lines_list[y][i];
1659 for (; lines_list[y][i]; i++)
1660 buf[j++] = lines_list[y][i];
1662 string_free(lines_list[y]);
1663 lines_list[y] = string_make(buf);
1668 * Delete or insert string
1670 static void toggle_string(cptr *lines_list, int flg, int y)
1672 autopick_type an_entry, *entry = &an_entry;
1674 if (!autopick_new_entry(entry, lines_list[y]))
1677 string_free(lines_list[y]);
1683 lines_list[y] = autopick_line_from_entry(entry);
1687 * Insert return code and split the line
1689 static bool insert_return_code(cptr *lines_list, int cx, int cy)
1694 for (k = 0; lines_list[k]; k++)
1695 /* count number of lines */ ;
1697 if (k >= MAX_LINES - 2) return FALSE;
1700 /* Move down lines */
1702 lines_list[k+1] = lines_list[k];
1704 /* Split current line */
1705 for (i = j = 0; lines_list[cy][i] && i < cx; i++)
1708 if (iskanji(lines_list[cy][i]))
1709 buf[j++] = lines_list[cy][i++];
1711 buf[j++] = lines_list[cy][i];
1714 lines_list[cy+1] = string_make(&lines_list[cy][i]);
1715 string_free(lines_list[cy]);
1716 lines_list[cy] = string_make(buf);
1722 * Get auto-picker entry from o_ptr.
1724 void autopick_entry_from_object(autopick_type *entry, object_type *o_ptr)
1726 char o_name[MAX_NLEN];
1727 object_desc(o_name, o_ptr, FALSE, 0);
1729 entry->name = string_make(o_name);
1730 entry->insc = string_make(quark_str(o_ptr->inscription));
1731 entry->action = DO_AUTOPICK | DO_DISPLAY;
1732 entry->flag[0] = entry->flag[1] = 0L;
1735 if (!object_aware_p(o_ptr))
1736 ADD_FLG(FLG_UNAWARE);
1737 if (object_value(o_ptr) <= 0)
1738 ADD_FLG(FLG_WORTHLESS);
1740 if (object_known_p(o_ptr))
1744 else if (o_ptr->name1 || o_ptr->art_name)
1745 ADD_FLG(FLG_ARTIFACT);
1751 case TV_HAFTED: case TV_POLEARM: case TV_SWORD: case TV_DIGGING:
1752 k_ptr = &k_info[o_ptr->k_idx];
1753 if ((o_ptr->dd != k_ptr->dd) || (o_ptr->ds != k_ptr->ds))
1754 ADD_FLG(FLG_BOOSTED);
1757 if (o_ptr->tval == TV_CORPSE && object_is_shoukinkubi(o_ptr))
1759 REM_FLG(FLG_WORTHLESS);
1760 ADD_FLG(FLG_WANTED);
1763 if ((o_ptr->tval == TV_CORPSE || o_ptr->tval == TV_STATUE)
1764 && (r_info[o_ptr->pval].flags1 & RF1_UNIQUE))
1766 REM_FLG(FLG_WORTHLESS);
1767 ADD_FLG(FLG_UNIQUE);
1770 if (o_ptr->tval == TV_CORPSE && strchr("pht", r_info[o_ptr->pval].d_char))
1772 REM_FLG(FLG_WORTHLESS);
1776 if (o_ptr->tval >= TV_LIFE_BOOK &&
1777 !check_book_realm(o_ptr->tval, o_ptr->sval))
1778 ADD_FLG(FLG_UNREADABLE);
1780 if (REALM1_BOOK == o_ptr->tval &&
1781 p_ptr->pclass != CLASS_SORCERER &&
1782 p_ptr->pclass != CLASS_RED_MAGE)
1783 ADD_FLG(FLG_REALM1);
1785 if (REALM2_BOOK == o_ptr->tval &&
1786 p_ptr->pclass != CLASS_SORCERER &&
1787 p_ptr->pclass != CLASS_RED_MAGE)
1788 ADD_FLG(FLG_REALM2);
1790 if (o_ptr->tval >= TV_LIFE_BOOK && 0 == o_ptr->sval)
1792 if (o_ptr->tval >= TV_LIFE_BOOK && 1 == o_ptr->sval)
1793 ADD_FLG(FLG_SECOND);
1794 if (o_ptr->tval >= TV_LIFE_BOOK && 2 == o_ptr->sval)
1796 if (o_ptr->tval >= TV_LIFE_BOOK && 3 == o_ptr->sval)
1797 ADD_FLG(FLG_FOURTH);
1799 if (o_ptr->tval == TV_SHOT || o_ptr->tval == TV_BOLT
1800 || o_ptr->tval == TV_ARROW)
1801 ADD_FLG(FLG_MISSILES);
1802 else if (o_ptr->tval == TV_SCROLL || o_ptr->tval == TV_STAFF
1803 || o_ptr->tval == TV_WAND || o_ptr->tval == TV_ROD)
1804 ADD_FLG(FLG_DEVICES);
1805 else if (o_ptr->tval == TV_LITE)
1806 ADD_FLG(FLG_LIGHTS);
1807 else if (o_ptr->tval == TV_SKELETON || o_ptr->tval == TV_BOTTLE
1808 || o_ptr->tval == TV_JUNK || o_ptr->tval == TV_STATUE)
1810 else if (o_ptr->tval >= TV_LIFE_BOOK)
1811 ADD_FLG(FLG_SPELLBOOKS);
1812 else if (o_ptr->tval == TV_HAFTED)
1813 ADD_FLG(FLG_HAFTED);
1814 else if (o_ptr->tval == TV_POLEARM || o_ptr->tval == TV_SWORD
1815 || o_ptr->tval == TV_DIGGING)
1816 ADD_FLG(FLG_WEAPONS);
1817 else if (o_ptr->tval == TV_SHIELD)
1818 ADD_FLG(FLG_SHIELDS);
1819 else if (o_ptr->tval == TV_BOW)
1821 else if (o_ptr->tval == TV_RING)
1823 else if (o_ptr->tval == TV_AMULET)
1824 ADD_FLG(FLG_AMULETS);
1825 else if (o_ptr->tval == TV_DRAG_ARMOR || o_ptr->tval == TV_HARD_ARMOR ||
1826 o_ptr->tval == TV_SOFT_ARMOR)
1828 else if (o_ptr->tval == TV_CLOAK)
1829 ADD_FLG(FLG_CLOAKS);
1830 else if (o_ptr->tval == TV_HELM)
1832 else if (o_ptr->tval == TV_GLOVES)
1833 ADD_FLG(FLG_GLOVES);
1834 else if (o_ptr->tval == TV_BOOTS)
1841 * Choose an item and get auto-picker entry from it.
1843 static bool entry_from_choosed_object(autopick_type *entry)
1851 q = "¤É¤Î¥¢¥¤¥Æ¥à¤òÅÐÏ¿¤·¤Þ¤¹¤«? ";
1852 s = "¥¢¥¤¥Æ¥à¤ò»ý¤Ã¤Æ¤¤¤Ê¤¤¡£";
1854 q = "Entry which item? ";
1855 s = "You have nothing to entry.";
1857 if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR | USE_EQUIP))) return FALSE;
1859 /* Get the item (in the pack) */
1862 o_ptr = &inventory[item];
1865 /* Get the item (on the floor) */
1868 o_ptr = &o_list[0 - item];
1871 autopick_entry_from_object(entry, o_ptr);
1877 * Initialize auto-picker preference
1879 void init_autopicker(void)
1881 static const char easy_autopick_inscription[] = "(:=g";
1882 autopick_type entry;
1885 /* Clear old entries */
1886 for( i = 0; i < max_autopick; i++)
1887 autopick_free_entry(&autopick_list[i]);
1891 /* There is always one entry "=g" */
1892 autopick_new_entry(&entry, easy_autopick_inscription);
1893 autopick_list[max_autopick++] = entry;
1898 * Description of control commands
1903 static cptr ctrl_command_desc[] =
1906 #define LAST_DESTROYED 6
1907 "^P ^N ^B ^F ¾å²¼º¸±¦¤Ë°ÜÆ°",
1908 "^A ^E ¹Ô¤ÎÀèƬ¡¢½ªÃ¼",
1909 "^Q ÆþÎÏ/¥³¥Þ¥ó¥É¥â¡¼¥ÉÀÚ¤êÂؤ¨",
1910 "^R Êѹ¹¤òÁ´¤Æ¼è¤ê¾Ã¤·¤Æ¸µ¤ËÌ᤹",
1911 "------------------------------------",
1912 "^I »ý¤Áʪ/ÁõÈ÷¤«¤éÁªÂò",
1914 "^K ¥«¡¼¥½¥ë¤«¤é½ªÃ¼¤Þ¤Çºï½ü",
1915 "^Y ºï½ü(^K)¤·¤¿¹Ô¤òÁÞÆþ",
1916 "^C ¼ï²¡¢¿¦¶È¤Î¾ò·ï¼°¤òÁÞÆþ",
1917 "------------------------------------",
1918 "^S Êѹ¹ (!Ç˲õ/~ÊüÃÖ/½¦¤¦)",
1919 "^G \"(\" Á´ÂΥޥåפÇɽ¼¨¤·¤Ê¤¤",
1920 "^O \"#\" ¼«Æ°¹ï¤ß",
1921 "------------------------------------",
1922 "^U ̤´ÕÄê/̤ȽÌÀ/´ÕÄê/*´ÕÄê*",
1924 "^X ̵ÌÃ/¥¨¥´/¥¢¡¼¥Æ¥£¥Õ¥¡¥¯¥È",
1928 #define LAST_DESTROYED 6
1929 "^P ^N ^B ^F Move Cursor",
1930 "^A ^E Beginning and End of Line",
1931 "^Q Toggle Insert/Command mode",
1932 "^R Revert to Original File",
1933 "------------------------------------",
1934 "^I Object in Inventry/Equipment",
1936 "^K Kill Rest of Line",
1937 "^Y Insert killed(^K) text",
1938 "^C Insert conditional expression",
1939 "------------------------------------",
1940 "^S Toggle(!Destroy/~Leave/Pick)",
1941 "^G \"(\" No display in the 'M'ap",
1942 "^O \"#\" Auto-Inscribe",
1943 "------------------------------------",
1944 "^U Toggle 'identified' state",
1946 "^X Toggle nameless/ego/artifact",
1947 "^Z \"collecting\"",
1953 #define MAX_YANK 1024
1954 #define DIRTY_ALL 0x01
1955 #define DIRTY_COMMAND 0x02
1956 #define DIRTY_MODE 0x04
1957 #define DIRTY_SCREEN 0x04
1960 * In-game editor of Object Auto-picker/Destoryer
1962 void do_cmd_edit_autopick(void)
1964 static int cx = 0, cy = 0;
1965 static int upper = 0, left = 0;
1967 cptr last_destroyed;
1968 char last_destroyed_command[WID_DESC+3];
1969 char yank_buf[MAX_YANK];
1971 autopick_type an_entry, *entry = &an_entry;
1978 int old_upper = -1, old_left = -1;
1980 int key = -1, old_key;
1982 bool edit_mode = FALSE;
1984 byte dirty_flags = DIRTY_ALL | DIRTY_COMMAND | DIRTY_MODE;
1985 int dirty_line = -1;
1987 int wid, hgt, old_wid = -1, old_hgt = -1;
1989 /* Free old entries */
1992 /* Name of the Last Destroyed Item */
1993 last_destroyed = autopick_line_from_entry(&autopick_entry_last_destroyed);
1995 /* Command Description of the Last Destroyed Item */
1998 strcpy(last_destroyed_command, "^L \"");
1999 strncpy(last_destroyed_command + 4, last_destroyed, WID_DESC-4);
2000 last_destroyed_command[WID_DESC+2] = '\0';
2005 strcpy(last_destroyed_command, "^L ºÇ¸å¤Ë¼«Æ°Ç˲õ¤·¤¿¥¢¥¤¥Æ¥à̾");
2007 strcpy(last_destroyed_command, "^L Last destroyed object");
2010 ctrl_command_desc[LAST_DESTROYED] = last_destroyed_command;
2012 /* Conditional Expression for Class and Race */
2013 sprintf(classrace, "?:[AND [EQU $RACE %s] [EQU $CLASS %s]]",
2015 rp_ptr->E_title, cp_ptr->E_title
2017 rp_ptr->title, cp_ptr->title
2021 /* Clear yank buffer */
2024 /* Read or initialize whole text */
2025 lines_list = read_pickpref_text_lines();
2027 /* Reset cursor position if needed */
2028 for (i = 0; i < cy; i++)
2037 /* Save the screen */
2040 /* Process requests until done */
2044 Term_get_size(&wid, &hgt);
2047 /* Don't let cursor at second byte of kanji */
2048 for (i = 0; lines_list[cy][i]; i++)
2049 if (iskanji(lines_list[cy][i]))
2060 /* Scroll if necessary */
2061 if (cy < upper || upper + hgt - 4 <= cy)
2062 upper = cy - (hgt-4)/2;
2065 if ((cx < left + 10 && left > 0) || left + wid - WID_DESC - 5 <= cx)
2066 left = cx - (wid - WID_DESC)*2/3;
2070 /* Redraw whole window after resize */
2071 if (old_wid != wid || old_hgt != hgt)
2072 dirty_flags |= DIRTY_SCREEN;
2074 /* Redraw all text after scroll */
2075 else if (old_upper != upper || old_left != left)
2076 dirty_flags |= DIRTY_ALL;
2079 if (dirty_flags & DIRTY_SCREEN)
2081 dirty_flags = DIRTY_ALL | DIRTY_COMMAND | DIRTY_MODE;
2087 if (dirty_flags & DIRTY_COMMAND)
2089 /* Display control command */
2090 for (i = 0; ctrl_command_desc[i]; i++)
2091 Term_putstr(wid - WID_DESC, i + 1, WID_DESC, TERM_WHITE, ctrl_command_desc[i]);
2094 /* Redraw mode line */
2095 if (dirty_flags & DIRTY_MODE)
2097 int sepa_length = wid - WID_DESC;
2100 for (i = 0; i < sepa_length; i++)
2106 strncpy(buf + sepa_length - 21, " (INSERT MODE) ", 16);
2108 strncpy(buf + sepa_length - 21, " (COMMAND MODE) ", 16);
2110 Term_putstr(0, hgt - 3, sepa_length, (byte) (edit_mode ? TERM_YELLOW : TERM_WHITE), buf);
2113 /* Dump up to 20, or hgt-4, lines of messages */
2114 for (i = 0; i < hgt - 4; i++)
2119 /* clean or dirty? */
2120 if (!(dirty_flags & DIRTY_ALL) && (dirty_line != upper+i))
2123 msg = lines_list[upper+i];
2126 /* Apply horizontal scroll */
2127 for (j = 0; *msg; msg++, j++)
2129 if (j == left) break;
2145 Term_erase(0, i + 1, wid - WID_DESC);
2147 /* Dump the messages, bottom to top */
2148 Term_putstr(leftcol, i + 1, wid - WID_DESC - 1, TERM_WHITE, msg);
2151 for (; i < hgt - 4; i++)
2154 Term_erase(0, i + 1, wid - WID_DESC);
2157 /* Display header line */
2160 prt("^Q ESC ¤Ç¥³¥Þ¥ó¥É¥â¡¼¥É¤Ø°Ü¹Ô¡¢Ä̾ï¤Îʸ»ú¤Ï¤½¤Î¤Þ¤ÞÆþÎÏ", 0, 0);
2162 prt("q _ ¤Ç½ªÎ»¡¢hjkl2468 ¤Ç°ÜÆ°¡¢^Q a i ¤ÇÆþÎϥ⡼¥É", 0, 0);
2165 prt("Press ^Q ESC to command mode, any letters to insert", 0, 0);
2167 prt("Press q _ to quit, hjkl2468 to move, ^Q a i to insert mode", 0, 0);
2169 /* Display current position */
2170 prt (format("(%d,%d)", cx, cy), 0, 70);
2172 /* Display information when updated */
2173 if (old_cy != cy || (dirty_flags & DIRTY_ALL) || dirty_line == cy)
2175 /* Clear information line */
2176 Term_erase(0, hgt - 3 + 1, wid);
2177 Term_erase(0, hgt - 3 + 2, wid);
2179 /* Display information */
2180 if (lines_list[cy][0] == '#')
2183 prt("¤³¤Î¹Ô¤Ï¥³¥á¥ó¥È¤Ç¤¹¡£", hgt - 3 + 1, 0);
2185 prt("This line is comment.", hgt - 3 + 1, 0);
2188 else if (lines_list[cy][1] == ':')
2190 switch(lines_list[cy][0])
2194 prt("¤³¤Î¹Ô¤Ï¾ò·ïʬ´ô¼°¤Ç¤¹¡£", hgt - 3 + 1, 0);
2196 prt("This line is Conditional Expression.", hgt - 3 + 1, 0);
2201 prt("¤³¤Î¹Ô¤Ï¥Þ¥¯¥í¤Î¼Â¹ÔÆâÍƤòÄêµÁ¤·¤Þ¤¹¡£", hgt - 3 + 1, 0);
2203 prt("This line defines Macro action.", hgt - 3 + 1, 0);
2208 prt("¤³¤Î¹Ô¤Ï¥Þ¥¯¥í¤Î¥È¥ê¥¬¡¼¡¦¥¡¼¤òÄêµÁ¤·¤Þ¤¹¡£", hgt - 3 + 1, 0);
2210 prt("This line defines Macro trigger key.", hgt - 3 + 1, 0);
2215 prt("¤³¤Î¹Ô¤Ï¥¡¼ÇÛÃÖ¤òÄêµÁ¤·¤Þ¤¹¡£", hgt - 3 + 1, 0);
2217 prt("This line defines Keymap.", hgt - 3 + 1, 0);
2223 /* Get description of an autopicker preference line */
2224 else if (autopick_new_entry(entry, lines_list[cy]))
2229 describe_autopick(buf, entry);
2231 roff_to_buf(buf, 79, temp);
2233 for (i = 0; i< 2; i++)
2239 prt(t, hgt - 3 + 1 + i, 0);
2243 autopick_free_entry(entry);
2248 Term_gotoxy(cx - left, cy - upper + 1);
2254 /* Save old key and location */
2262 /* Do not process macros except special keys */
2263 inkey_special = TRUE;
2274 /* Mode line is now dirty */
2275 dirty_flags |= DIRTY_MODE;
2277 else if (!iscntrl(key&0xff))
2281 for (i = j = 0; lines_list[cy][i] && i < cx; i++)
2282 buf[j++] = lines_list[cy][i];
2305 for (; lines_list[cy][i] && j + 1 < 1024; i++)
2306 buf[j++] = lines_list[cy][i];
2308 string_free(lines_list[cy]);
2309 lines_list[cy] = string_make(buf);
2310 len = strlen(lines_list[cy]);
2311 if (len < cx) cx = len;
2320 if (key == 'q' || key == '_') break;
2327 /* Mode line is now dirty */
2328 dirty_flags |= DIRTY_MODE;
2331 if (!autopick_new_entry(entry, lines_list[cy]))
2333 string_free(lines_list[cy]);
2335 entry->action &= ~DO_AUTODESTROY;
2336 if (entry->action & DO_AUTOPICK)
2338 entry->action &= ~DO_AUTOPICK;
2339 entry->action |= DONT_AUTOPICK;
2343 entry->action &= ~DONT_AUTOPICK;
2344 entry->action |= DO_AUTOPICK;
2347 lines_list[cy] = autopick_line_from_entry(entry);
2353 if (!autopick_new_entry(entry, lines_list[cy]))
2355 string_free(lines_list[cy]);
2357 entry->action &= ~DONT_AUTOPICK;
2358 if (entry->action & DO_AUTOPICK)
2360 entry->action &= ~DO_AUTOPICK;
2361 entry->action |= DO_AUTODESTROY;
2365 entry->action &= ~DO_AUTODESTROY;
2366 entry->action |= DO_AUTOPICK;
2369 lines_list[cy] = autopick_line_from_entry(entry);
2394 while (cy < upper + hgt-4 && lines_list[cy + 1])
2399 while (0 < cy && upper <= cy)
2401 while (0 < upper && cy + 1 < upper + hgt - 4)
2410 /* Beginning of line */
2418 len = strlen(lines_list[cy]);
2419 if (len < cx) cx = len;
2424 cx = strlen(lines_list[cy]);
2428 /* Insert a conditinal expression line */
2429 insert_return_code(lines_list, 0, cy);
2430 lines_list[cy] = string_make(classrace);
2432 insert_return_code(lines_list, 0, cy);
2433 lines_list[cy] = string_make("?:1");
2437 dirty_flags |= DIRTY_ALL;
2441 cx = strlen(lines_list[cy]);
2446 if (iskanji(lines_list[cy][cx])) cx++;
2449 len = strlen(lines_list[cy]);
2452 if (lines_list[cy + 1])
2462 /* Toggle display in the 'M'ap */
2463 if (lines_list[cy][0] != '(' && lines_list[cy][1] != '(')
2464 insert_string(lines_list, "(", 0, cy);
2465 else if (lines_list[cy][0] == '(')
2466 delete_string(lines_list, 1, 0, cy);
2467 else if (lines_list[cy][1] == '(')
2468 delete_string(lines_list, 1, 1, cy);
2474 /* Insert choosen item name */
2475 if (!entry_from_choosed_object(entry))
2477 /* Now dirty because of item/equip menu */
2478 dirty_flags |= DIRTY_SCREEN;
2481 tmp = autopick_line_from_entry(entry);
2482 autopick_free_entry(entry);
2485 insert_return_code(lines_list, 0, cy);
2486 lines_list[cy] = tmp;
2489 /* Now dirty because of item/equip menu */
2490 dirty_flags |= DIRTY_SCREEN;
2494 /* Insert a name of last destroyed item */
2497 insert_return_code(lines_list, 0, cy);
2498 lines_list[cy] = string_make(last_destroyed);
2502 dirty_flags |= DIRTY_ALL;
2505 case '\n': case '\r':
2506 /* Split a line or insert end of line */
2507 insert_return_code(lines_list, cx, cy);
2512 dirty_flags |= DIRTY_ALL;
2516 if (lines_list[cy + 1]) cy++;
2519 /* Prepare to write auto-inscription text */
2520 for (i = 0; lines_list[cy][i]; i++)
2521 if (lines_list[cy][i] == '#') break;
2522 if (!lines_list[cy][i]) insert_string(lines_list, "#", i, cy);
2528 dirty_flags |= DIRTY_MODE;
2536 edit_mode = !edit_mode;
2538 /* Mode line is now dirty */
2539 dirty_flags |= DIRTY_MODE;
2542 /* Revert to original */
2544 if (!get_check("Á´¤Æ¤ÎÊѹ¹¤òÇË´þ¤·¤Æ¸µ¤Î¾õÂÖ¤ËÌᤷ¤Þ¤¹¡£¤è¤í¤·¤¤¤Ç¤¹¤«¡© "))
2546 if (!get_check("Discard all change and revert to original file. Are you sure? "))
2550 free_text_lines(lines_list);
2551 lines_list = read_pickpref_text_lines();
2552 dirty_flags |= DIRTY_ALL | DIRTY_MODE;
2557 /* Rotate action; pickup/destroy/leave */
2558 if (!autopick_new_entry(entry, lines_list[cy]))
2560 string_free(lines_list[cy]);
2562 if (entry->action & DO_AUTOPICK)
2564 entry->action &= ~DO_AUTOPICK;
2565 entry->action |= DO_AUTODESTROY;
2567 else if (entry->action & DO_AUTODESTROY)
2569 entry->action &= ~DO_AUTODESTROY;
2570 entry->action |= DONT_AUTOPICK;
2572 else if (entry->action & DONT_AUTOPICK)
2574 entry->action &= ~DONT_AUTOPICK;
2575 entry->action |= DO_AUTOPICK;
2578 lines_list[cy] = autopick_line_from_entry(entry);
2587 /* Rotate identify-state; identified/unidentified/... */
2588 if (!autopick_new_entry(entry, lines_list[cy]))
2590 string_free(lines_list[cy]);
2592 if (IS_FLG(FLG_UNIDENTIFIED))
2594 REM_FLG(FLG_UNIDENTIFIED);
2595 ADD_FLG(FLG_UNAWARE);
2596 REM_FLG(FLG_IDENTIFIED);
2597 REM_FLG(FLG_STAR_IDENTIFIED);
2599 else if (IS_FLG(FLG_UNAWARE))
2601 REM_FLG(FLG_UNIDENTIFIED);
2602 REM_FLG(FLG_UNAWARE);
2603 ADD_FLG(FLG_IDENTIFIED);
2604 REM_FLG(FLG_STAR_IDENTIFIED);
2606 else if (IS_FLG(FLG_STAR_IDENTIFIED))
2608 REM_FLG(FLG_UNIDENTIFIED);
2609 REM_FLG(FLG_UNAWARE);
2610 REM_FLG(FLG_IDENTIFIED);
2611 REM_FLG(FLG_STAR_IDENTIFIED);
2613 else if (IS_FLG(FLG_IDENTIFIED))
2615 REM_FLG(FLG_UNIDENTIFIED);
2616 REM_FLG(FLG_UNAWARE);
2617 REM_FLG(FLG_IDENTIFIED);
2618 ADD_FLG(FLG_STAR_IDENTIFIED);
2622 ADD_FLG(FLG_UNIDENTIFIED);
2623 REM_FLG(FLG_UNAWARE);
2624 REM_FLG(FLG_IDENTIFIED);
2625 REM_FLG(FLG_STAR_IDENTIFIED);
2628 lines_list[cy] = autopick_line_from_entry(entry);
2635 while (cy < upper + hgt-4 && lines_list[cy + 1])
2640 /* Toggle 'worthless' */
2641 toggle_string(lines_list, FLG_WORTHLESS, cy);
2646 /* Rotate within nameless, ego, artifact */
2647 if (!autopick_new_entry(entry, lines_list[cy]))
2649 string_free(lines_list[cy]);
2651 if (IS_FLG(FLG_NAMELESS))
2653 REM_FLG(FLG_NAMELESS);
2655 REM_FLG(FLG_ARTIFACT);
2657 else if (IS_FLG(FLG_EGO))
2659 REM_FLG(FLG_NAMELESS);
2661 ADD_FLG(FLG_ARTIFACT);
2663 else if (IS_FLG(FLG_ARTIFACT))
2665 REM_FLG(FLG_NAMELESS);
2667 REM_FLG(FLG_ARTIFACT);
2671 ADD_FLG(FLG_NAMELESS);
2673 REM_FLG(FLG_ARTIFACT);
2676 lines_list[cy] = autopick_line_from_entry(entry);
2683 /* Paste killed text */
2684 if (strlen(yank_buf))
2687 for (j = 0; yank_buf[j]; j += strlen(yank_buf + j) + 1)
2689 insert_return_code(lines_list, 0, cy);
2690 lines_list[cy] = string_make(yank_buf + j);
2695 dirty_flags |= DIRTY_ALL;
2699 /* Toggle 'collecting' */
2700 toggle_string(lines_list, FLG_COLLECTING, cy);
2706 /* Kill rest of line */
2707 if (lines_list[cy][0] != '\0' && (unsigned int) cx < strlen(lines_list[cy]))
2709 for (i = j = 0; lines_list[cy][i] && i < cx; i++)
2712 if (iskanji(lines_list[cy][i]))
2713 buf[j++] = lines_list[cy][i++];
2715 buf[j++] = lines_list[cy][i];
2720 if (old_key == KTRL('k'))
2722 j += strlen(yank_buf + j) + 1;
2724 if (j < MAX_YANK - 2)
2726 strncpy(yank_buf + j, lines_list[cy] + i, MAX_YANK-j-2);
2727 yank_buf[MAX_YANK-2] = '\0';
2728 yank_buf[j + strlen(lines_list[cy] + i) + 1] = '\0';
2730 string_free(lines_list[cy]);
2731 lines_list[cy] = string_make(buf);
2740 /* DELETE == go forward + BACK SPACE */
2742 if (iskanji(lines_list[cy][cx])) cx++;
2745 len = strlen(lines_list[cy]);
2748 if (lines_list[cy + 1])
2766 /* delete a return code and union two lines */
2768 cx = strlen(lines_list[cy-1]);
2769 strcpy(buf, lines_list[cy-1]);
2770 strcat(buf, lines_list[cy]);
2771 string_free(lines_list[cy-1]);
2772 string_free(lines_list[cy]);
2773 lines_list[cy-1] = string_make(buf);
2774 for (i = cy; lines_list[i+1]; i++)
2775 lines_list[i] = lines_list[i+1];
2776 lines_list[i] = NULL;
2780 dirty_flags |= DIRTY_ALL;
2784 for (i = j = 0; lines_list[cy][i] && i < cx; i++)
2788 if (iskanji(lines_list[cy][i]))
2789 buf[j++] = lines_list[cy][i++];
2791 buf[j++] = lines_list[cy][i];
2798 for (; lines_list[cy][i]; i++)
2799 buf[j++] = lines_list[cy][i];
2801 string_free(lines_list[cy]);
2802 lines_list[cy] = string_make(buf);
2811 /* Restore the screen */
2815 sprintf(buf, "picktype-%s.prf", player_name);
2817 sprintf(buf, "pickpref-%s.prf", player_name);
2819 write_text_lines(buf, lines_list);
2820 free_text_lines(lines_list);
2822 string_free(last_destroyed);
2824 /* Reload autopick pref */
2825 process_pickpref_file(buf);