OSDN Git Service

Merge pull request #2290 from habu1010/feature/clang-format-insert-braces
[hengbandforosx/hengbandosx.git] / src / autopick / autopick-entry.cpp
1 #include "autopick/autopick-entry.h"
2 #include "autopick/autopick-flags-table.h"
3 #include "autopick/autopick-key-flag-process.h"
4 #include "autopick/autopick-keys-table.h"
5 #include "autopick/autopick-methods-table.h"
6 #include "autopick/autopick-util.h"
7 #include "core/show-file.h"
8 #include "flavor/flavor-describer.h"
9 #include "flavor/object-flavor-types.h"
10 #include "floor/floor-object.h"
11 #include "monster-race/monster-race.h"
12 #include "monster-race/race-flags1.h"
13 #include "object-enchant/item-feeling.h"
14 #include "object-enchant/object-ego.h"
15 #include "object-enchant/special-object-flags.h"
16 #include "object-hook/hook-quest.h"
17 #include "object-hook/hook-weapon.h"
18 #include "object/item-use-flags.h"
19 #include "object/object-info.h"
20 #include "object/object-kind.h"
21 #include "perception/object-perception.h"
22 #include "player-base/player-class.h"
23 #include "player/player-realm.h"
24 #include "system/monster-race-definition.h"
25 #include "system/object-type-definition.h"
26 #include "system/player-type-definition.h"
27 #include "util/quarks.h"
28 #include "util/string-processor.h"
29
30 #ifdef JP
31 static char kanji_colon[] = ":";
32 #endif
33
34 /*!
35  * @brief A function to create new entry
36  */
37 bool autopick_new_entry(autopick_type *entry, concptr str, bool allow_default)
38 {
39     if (str[0] && str[1] == ':') {
40         switch (str[0]) {
41         case '?':
42         case '%':
43         case 'A':
44         case 'P':
45         case 'C':
46             return false;
47         }
48     }
49
50     entry->flag[0] = entry->flag[1] = 0L;
51     entry->dice = 0;
52     entry->bonus = 0;
53
54     byte act = DO_AUTOPICK | DO_DISPLAY;
55     while (true) {
56         if ((act & DO_AUTOPICK) && *str == '!') {
57             act &= ~DO_AUTOPICK;
58             act |= DO_AUTODESTROY;
59             str++;
60             continue;
61         }
62
63         if ((act & DO_AUTOPICK) && *str == '~') {
64             act &= ~DO_AUTOPICK;
65             act |= DONT_AUTOPICK;
66             str++;
67             continue;
68         }
69
70         if ((act & DO_AUTOPICK) && *str == ';') {
71             act &= ~DO_AUTOPICK;
72             act |= DO_QUERY_AUTOPICK;
73             str++;
74             continue;
75         }
76
77         if ((act & DO_DISPLAY) && *str == '(') {
78             act &= ~DO_DISPLAY;
79             str++;
80             continue;
81         }
82
83         break;
84     }
85
86     concptr insc = nullptr;
87     char buf[MAX_LINELEN];
88     int i;
89     for (i = 0; *str; i++) {
90         char c = *str++;
91 #ifdef JP
92         if (iskanji(c)) {
93             buf[i++] = c;
94             buf[i] = *str++;
95             continue;
96         }
97 #endif
98         if (c == '#') {
99             buf[i] = '\0';
100             insc = str;
101             break;
102         }
103
104         if (isupper(c)) {
105             c = (char)tolower(c);
106         }
107
108         buf[i] = c;
109     }
110
111     buf[i] = '\0';
112     if (!allow_default && *buf == 0) {
113         return false;
114     }
115     if (*buf == 0 && insc) {
116         return false;
117     }
118
119     concptr prev_ptr, ptr;
120     ptr = prev_ptr = buf;
121     concptr old_ptr = nullptr;
122     while (old_ptr != ptr) {
123         old_ptr = ptr;
124         if (MATCH_KEY(KEY_ALL)) {
125             ADD_FLG(FLG_ALL);
126         }
127         if (MATCH_KEY(KEY_COLLECTING)) {
128             ADD_FLG(FLG_COLLECTING);
129         }
130         if (MATCH_KEY(KEY_UNAWARE)) {
131             ADD_FLG(FLG_UNAWARE);
132         }
133         if (MATCH_KEY(KEY_UNIDENTIFIED)) {
134             ADD_FLG(FLG_UNIDENTIFIED);
135         }
136         if (MATCH_KEY(KEY_IDENTIFIED)) {
137             ADD_FLG(FLG_IDENTIFIED);
138         }
139         if (MATCH_KEY(KEY_STAR_IDENTIFIED)) {
140             ADD_FLG(FLG_STAR_IDENTIFIED);
141         }
142         if (MATCH_KEY(KEY_BOOSTED)) {
143             ADD_FLG(FLG_BOOSTED);
144         }
145
146         /*** Weapons whose dd*ds is more than nn ***/
147         if (MATCH_KEY2(KEY_MORE_THAN)) {
148             int k = 0;
149             entry->dice = 0;
150
151             while (' ' == *ptr) {
152                 ptr++;
153             }
154
155             while ('0' <= *ptr && *ptr <= '9') {
156                 entry->dice = 10 * entry->dice + (*ptr - '0');
157                 ptr++;
158                 k++;
159             }
160
161             if (k > 0 && k <= 2) {
162                 (void)MATCH_KEY(KEY_DICE);
163                 ADD_FLG(FLG_MORE_DICE);
164             } else {
165                 ptr = prev_ptr;
166             }
167         }
168
169         /*** Items whose magical bonus is more than n ***/
170         if (MATCH_KEY2(KEY_MORE_BONUS)) {
171             int k = 0;
172             entry->bonus = 0;
173
174             while (' ' == *ptr) {
175                 ptr++;
176             }
177
178             while ('0' <= *ptr && *ptr <= '9') {
179                 entry->bonus = 10 * entry->bonus + (*ptr - '0');
180                 ptr++;
181                 k++;
182             }
183
184             if (k > 0 && k <= 2) {
185 #ifdef JP
186                 (void)MATCH_KEY(KEY_MORE_BONUS2);
187 #else
188                 if (' ' == *ptr) {
189                     ptr++;
190                 }
191 #endif
192                 ADD_FLG(FLG_MORE_BONUS);
193             } else {
194                 ptr = prev_ptr;
195             }
196         }
197
198         if (MATCH_KEY(KEY_WORTHLESS)) {
199             ADD_FLG(FLG_WORTHLESS);
200         }
201         if (MATCH_KEY(KEY_EGO)) {
202             ADD_FLG(FLG_EGO);
203         }
204         if (MATCH_KEY(KEY_GOOD)) {
205             ADD_FLG(FLG_GOOD);
206         }
207         if (MATCH_KEY(KEY_NAMELESS)) {
208             ADD_FLG(FLG_NAMELESS);
209         }
210         if (MATCH_KEY(KEY_AVERAGE)) {
211             ADD_FLG(FLG_AVERAGE);
212         }
213         if (MATCH_KEY(KEY_RARE)) {
214             ADD_FLG(FLG_RARE);
215         }
216         if (MATCH_KEY(KEY_COMMON)) {
217             ADD_FLG(FLG_COMMON);
218         }
219         if (MATCH_KEY(KEY_WANTED)) {
220             ADD_FLG(FLG_WANTED);
221         }
222         if (MATCH_KEY(KEY_UNIQUE)) {
223             ADD_FLG(FLG_UNIQUE);
224         }
225         if (MATCH_KEY(KEY_HUMAN)) {
226             ADD_FLG(FLG_HUMAN);
227         }
228         if (MATCH_KEY(KEY_UNREADABLE)) {
229             ADD_FLG(FLG_UNREADABLE);
230         }
231         if (MATCH_KEY(KEY_REALM1)) {
232             ADD_FLG(FLG_REALM1);
233         }
234         if (MATCH_KEY(KEY_REALM2)) {
235             ADD_FLG(FLG_REALM2);
236         }
237         if (MATCH_KEY(KEY_FIRST)) {
238             ADD_FLG(FLG_FIRST);
239         }
240         if (MATCH_KEY(KEY_SECOND)) {
241             ADD_FLG(FLG_SECOND);
242         }
243         if (MATCH_KEY(KEY_THIRD)) {
244             ADD_FLG(FLG_THIRD);
245         }
246         if (MATCH_KEY(KEY_FOURTH)) {
247             ADD_FLG(FLG_FOURTH);
248         }
249     }
250
251     int prev_flg = -1;
252     if (MATCH_KEY2(KEY_ARTIFACT)) {
253         ADD_FLG_NOUN(FLG_ARTIFACT);
254     }
255
256     if (MATCH_KEY2(KEY_ITEMS)) {
257         ADD_FLG_NOUN(FLG_ITEMS);
258     } else if (MATCH_KEY2(KEY_WEAPONS)) {
259         ADD_FLG_NOUN(FLG_WEAPONS);
260     } else if (MATCH_KEY2(KEY_FAVORITE_WEAPONS)) {
261         ADD_FLG_NOUN(FLG_FAVORITE_WEAPONS);
262     } else if (MATCH_KEY2(KEY_ARMORS)) {
263         ADD_FLG_NOUN(FLG_ARMORS);
264     } else if (MATCH_KEY2(KEY_MISSILES)) {
265         ADD_FLG_NOUN(FLG_MISSILES);
266     } else if (MATCH_KEY2(KEY_DEVICES)) {
267         ADD_FLG_NOUN(FLG_DEVICES);
268     } else if (MATCH_KEY2(KEY_LIGHTS)) {
269         ADD_FLG_NOUN(FLG_LIGHTS);
270     } else if (MATCH_KEY2(KEY_JUNKS)) {
271         ADD_FLG_NOUN(FLG_JUNKS);
272     } else if (MATCH_KEY2(KEY_CORPSES)) {
273         ADD_FLG_NOUN(FLG_CORPSES);
274     } else if (MATCH_KEY2(KEY_SPELLBOOKS)) {
275         ADD_FLG_NOUN(FLG_SPELLBOOKS);
276     } else if (MATCH_KEY2(KEY_HAFTED)) {
277         ADD_FLG_NOUN(FLG_HAFTED);
278     } else if (MATCH_KEY2(KEY_SHIELDS)) {
279         ADD_FLG_NOUN(FLG_SHIELDS);
280     } else if (MATCH_KEY2(KEY_BOWS)) {
281         ADD_FLG_NOUN(FLG_BOWS);
282     } else if (MATCH_KEY2(KEY_RINGS)) {
283         ADD_FLG_NOUN(FLG_RINGS);
284     } else if (MATCH_KEY2(KEY_AMULETS)) {
285         ADD_FLG_NOUN(FLG_AMULETS);
286     } else if (MATCH_KEY2(KEY_SUITS)) {
287         ADD_FLG_NOUN(FLG_SUITS);
288     } else if (MATCH_KEY2(KEY_CLOAKS)) {
289         ADD_FLG_NOUN(FLG_CLOAKS);
290     } else if (MATCH_KEY2(KEY_HELMS)) {
291         ADD_FLG_NOUN(FLG_HELMS);
292     } else if (MATCH_KEY2(KEY_GLOVES)) {
293         ADD_FLG_NOUN(FLG_GLOVES);
294     } else if (MATCH_KEY2(KEY_BOOTS)) {
295         ADD_FLG_NOUN(FLG_BOOTS);
296     }
297
298     if (*ptr == ':') {
299         ptr++;
300     }
301 #ifdef JP
302     else if (ptr[0] == kanji_colon[0] && ptr[1] == kanji_colon[1]) {
303         ptr += 2;
304     }
305 #endif
306     else if (*ptr == '\0') {
307         if (prev_flg == -1) {
308             ADD_FLG_NOUN(FLG_ITEMS);
309         }
310     } else {
311         if (prev_flg != -1) {
312             entry->flag[prev_flg / 32] &= ~(1UL << (prev_flg % 32));
313             ptr = prev_ptr;
314         }
315     }
316
317     entry->name = ptr;
318     entry->action = act;
319     entry->insc = insc != nullptr ? insc : "";
320
321     return true;
322 }
323
324 /*!
325  * @brief Get auto-picker entry from o_ptr.
326  */
327 void autopick_entry_from_object(PlayerType *player_ptr, autopick_type *entry, ObjectType *o_ptr)
328 {
329     /* Assume that object name is to be added */
330     bool name = true;
331     GAME_TEXT name_str[MAX_NLEN + 32];
332     name_str[0] = '\0';
333     auto insc = quark_str(o_ptr->inscription);
334     entry->insc = insc != nullptr ? insc : "";
335     entry->action = DO_AUTOPICK | DO_DISPLAY;
336     entry->flag[0] = entry->flag[1] = 0L;
337     entry->dice = 0;
338
339     // エゴ銘が邪魔かもしれないので、デフォルトで「^」は付けない.
340     // We can always use the ^ mark in English.
341     bool is_hat_added = _(false, true);
342     if (!o_ptr->is_aware()) {
343         ADD_FLG(FLG_UNAWARE);
344         is_hat_added = true;
345     } else if (!o_ptr->is_known()) {
346         if (!(o_ptr->ident & IDENT_SENSE)) {
347             ADD_FLG(FLG_UNIDENTIFIED);
348             is_hat_added = true;
349         } else {
350             switch (o_ptr->feeling) {
351             case FEEL_AVERAGE:
352             case FEEL_GOOD:
353                 ADD_FLG(FLG_NAMELESS);
354                 is_hat_added = true;
355                 break;
356
357             case FEEL_BROKEN:
358             case FEEL_CURSED:
359                 ADD_FLG(FLG_NAMELESS);
360                 ADD_FLG(FLG_WORTHLESS);
361                 is_hat_added = true;
362                 break;
363
364             case FEEL_TERRIBLE:
365             case FEEL_WORTHLESS:
366                 ADD_FLG(FLG_WORTHLESS);
367                 break;
368
369             case FEEL_EXCELLENT:
370                 ADD_FLG(FLG_EGO);
371                 break;
372
373             case FEEL_UNCURSED:
374                 break;
375
376             default:
377                 break;
378             }
379         }
380     } else {
381         if (o_ptr->is_ego()) {
382             if (o_ptr->is_weapon_armour_ammo()) {
383                 /*
384                  * Base name of ego weapons and armors
385                  * are almost meaningless.
386                  * Register the ego type only.
387                  */
388                 auto *e_ptr = &e_info[o_ptr->ego_idx];
389 #ifdef JP
390                 /* エゴ銘には「^」マークが使える */
391                 sprintf(name_str, "^%s", e_ptr->name.c_str());
392 #else
393                 /* We ommit the basename and cannot use the ^ mark */
394                 strcpy(name_str, e_ptr->name.c_str());
395 #endif
396                 name = false;
397                 if (!o_ptr->is_rare()) {
398                     ADD_FLG(FLG_COMMON);
399                 }
400             }
401
402             ADD_FLG(FLG_EGO);
403         } else if (o_ptr->is_artifact()) {
404             ADD_FLG(FLG_ARTIFACT);
405         } else {
406             if (o_ptr->is_equipment()) {
407                 ADD_FLG(FLG_NAMELESS);
408             }
409
410             is_hat_added = true;
411         }
412     }
413
414     if (o_ptr->is_melee_weapon()) {
415         auto *k_ptr = &k_info[o_ptr->k_idx];
416
417         if ((o_ptr->dd != k_ptr->dd) || (o_ptr->ds != k_ptr->ds)) {
418             ADD_FLG(FLG_BOOSTED);
419         }
420     }
421
422     if (object_is_bounty(player_ptr, o_ptr)) {
423         REM_FLG(FLG_WORTHLESS);
424         ADD_FLG(FLG_WANTED);
425     }
426
427     if ((o_ptr->tval == ItemKindType::CORPSE || o_ptr->tval == ItemKindType::STATUE) && r_info[o_ptr->pval].kind_flags.has(MonsterKindType::UNIQUE)) {
428         ADD_FLG(FLG_UNIQUE);
429     }
430
431     if (o_ptr->tval == ItemKindType::CORPSE && angband_strchr("pht", r_info[o_ptr->pval].d_char)) {
432         ADD_FLG(FLG_HUMAN);
433     }
434
435     if (o_ptr->tval >= ItemKindType::LIFE_BOOK && !check_book_realm(player_ptr, o_ptr->tval, o_ptr->sval)) {
436         ADD_FLG(FLG_UNREADABLE);
437         if (o_ptr->tval != ItemKindType::ARCANE_BOOK) {
438             name = false;
439         }
440     }
441
442     PlayerClass pc(player_ptr);
443     auto realm_except_class = pc.equals(PlayerClassType::SORCERER) || pc.equals(PlayerClassType::RED_MAGE);
444
445     if ((get_realm1_book(player_ptr) == o_ptr->tval) && !realm_except_class) {
446         ADD_FLG(FLG_REALM1);
447         name = false;
448     }
449
450     if ((get_realm2_book(player_ptr) == o_ptr->tval) && !realm_except_class) {
451         ADD_FLG(FLG_REALM2);
452         name = false;
453     }
454
455     if (o_ptr->tval >= ItemKindType::LIFE_BOOK && 0 == o_ptr->sval) {
456         ADD_FLG(FLG_FIRST);
457     }
458     if (o_ptr->tval >= ItemKindType::LIFE_BOOK && 1 == o_ptr->sval) {
459         ADD_FLG(FLG_SECOND);
460     }
461     if (o_ptr->tval >= ItemKindType::LIFE_BOOK && 2 == o_ptr->sval) {
462         ADD_FLG(FLG_THIRD);
463     }
464     if (o_ptr->tval >= ItemKindType::LIFE_BOOK && 3 == o_ptr->sval) {
465         ADD_FLG(FLG_FOURTH);
466     }
467
468     if (o_ptr->is_ammo()) {
469         ADD_FLG(FLG_MISSILES);
470     } else if (o_ptr->tval == ItemKindType::SCROLL || o_ptr->tval == ItemKindType::STAFF || o_ptr->tval == ItemKindType::WAND || o_ptr->tval == ItemKindType::ROD) {
471         ADD_FLG(FLG_DEVICES);
472     } else if (o_ptr->tval == ItemKindType::LITE) {
473         ADD_FLG(FLG_LIGHTS);
474     } else if (o_ptr->tval == ItemKindType::SKELETON || o_ptr->tval == ItemKindType::BOTTLE || o_ptr->tval == ItemKindType::JUNK || o_ptr->tval == ItemKindType::STATUE) {
475         ADD_FLG(FLG_JUNKS);
476     } else if (o_ptr->tval == ItemKindType::CORPSE) {
477         ADD_FLG(FLG_CORPSES);
478     } else if (o_ptr->tval >= ItemKindType::LIFE_BOOK) {
479         ADD_FLG(FLG_SPELLBOOKS);
480     } else if (o_ptr->tval == ItemKindType::POLEARM || o_ptr->tval == ItemKindType::SWORD || o_ptr->tval == ItemKindType::DIGGING || o_ptr->tval == ItemKindType::HAFTED) {
481         ADD_FLG(FLG_WEAPONS);
482     } else if (o_ptr->tval == ItemKindType::SHIELD) {
483         ADD_FLG(FLG_SHIELDS);
484     } else if (o_ptr->tval == ItemKindType::BOW) {
485         ADD_FLG(FLG_BOWS);
486     } else if (o_ptr->tval == ItemKindType::RING) {
487         ADD_FLG(FLG_RINGS);
488     } else if (o_ptr->tval == ItemKindType::AMULET) {
489         ADD_FLG(FLG_AMULETS);
490     } else if (o_ptr->tval == ItemKindType::DRAG_ARMOR || o_ptr->tval == ItemKindType::HARD_ARMOR || o_ptr->tval == ItemKindType::SOFT_ARMOR) {
491         ADD_FLG(FLG_SUITS);
492     } else if (o_ptr->tval == ItemKindType::CLOAK) {
493         ADD_FLG(FLG_CLOAKS);
494     } else if (o_ptr->tval == ItemKindType::HELM) {
495         ADD_FLG(FLG_HELMS);
496     } else if (o_ptr->tval == ItemKindType::GLOVES) {
497         ADD_FLG(FLG_GLOVES);
498     } else if (o_ptr->tval == ItemKindType::BOOTS) {
499         ADD_FLG(FLG_BOOTS);
500     }
501
502     if (!name) {
503         str_tolower(name_str);
504         entry->name = name_str;
505         return;
506     }
507
508     GAME_TEXT o_name[MAX_NLEN];
509     describe_flavor(player_ptr, o_name, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL | OD_NAME_ONLY));
510
511     /*
512      * If necessary, add a '^' which indicates the
513      * beginning of line.
514      */
515     sprintf(name_str, "%s%s", is_hat_added ? "^" : "", o_name);
516     str_tolower(name_str);
517     entry->name = name_str;
518 }
519
520 /*!
521  * @brief Reconstruct preference line from entry
522  */
523 concptr autopick_line_from_entry(autopick_type *entry)
524 {
525     char buf[MAX_LINELEN];
526     *buf = '\0';
527     if (!(entry->action & DO_DISPLAY)) {
528         strcat(buf, "(");
529     }
530     if (entry->action & DO_QUERY_AUTOPICK) {
531         strcat(buf, ";");
532     }
533     if (entry->action & DO_AUTODESTROY) {
534         strcat(buf, "!");
535     }
536     if (entry->action & DONT_AUTOPICK) {
537         strcat(buf, "~");
538     }
539
540     char *ptr;
541     ptr = buf;
542     if (IS_FLG(FLG_ALL)) {
543         ADD_KEY(KEY_ALL);
544     }
545     if (IS_FLG(FLG_COLLECTING)) {
546         ADD_KEY(KEY_COLLECTING);
547     }
548     if (IS_FLG(FLG_UNAWARE)) {
549         ADD_KEY(KEY_UNAWARE);
550     }
551     if (IS_FLG(FLG_UNIDENTIFIED)) {
552         ADD_KEY(KEY_UNIDENTIFIED);
553     }
554     if (IS_FLG(FLG_IDENTIFIED)) {
555         ADD_KEY(KEY_IDENTIFIED);
556     }
557     if (IS_FLG(FLG_STAR_IDENTIFIED)) {
558         ADD_KEY(KEY_STAR_IDENTIFIED);
559     }
560     if (IS_FLG(FLG_BOOSTED)) {
561         ADD_KEY(KEY_BOOSTED);
562     }
563
564     if (IS_FLG(FLG_MORE_DICE)) {
565         ADD_KEY(KEY_MORE_THAN);
566         strcat(ptr, format("%d", entry->dice));
567         ADD_KEY(KEY_DICE);
568     }
569
570     if (IS_FLG(FLG_MORE_BONUS)) {
571         ADD_KEY(KEY_MORE_BONUS);
572         strcat(ptr, format("%d", entry->bonus));
573         ADD_KEY(KEY_MORE_BONUS2);
574     }
575
576     if (IS_FLG(FLG_UNREADABLE)) {
577         ADD_KEY(KEY_UNREADABLE);
578     }
579     if (IS_FLG(FLG_REALM1)) {
580         ADD_KEY(KEY_REALM1);
581     }
582     if (IS_FLG(FLG_REALM2)) {
583         ADD_KEY(KEY_REALM2);
584     }
585     if (IS_FLG(FLG_FIRST)) {
586         ADD_KEY(KEY_FIRST);
587     }
588     if (IS_FLG(FLG_SECOND)) {
589         ADD_KEY(KEY_SECOND);
590     }
591     if (IS_FLG(FLG_THIRD)) {
592         ADD_KEY(KEY_THIRD);
593     }
594     if (IS_FLG(FLG_FOURTH)) {
595         ADD_KEY(KEY_FOURTH);
596     }
597     if (IS_FLG(FLG_WANTED)) {
598         ADD_KEY(KEY_WANTED);
599     }
600     if (IS_FLG(FLG_UNIQUE)) {
601         ADD_KEY(KEY_UNIQUE);
602     }
603     if (IS_FLG(FLG_HUMAN)) {
604         ADD_KEY(KEY_HUMAN);
605     }
606     if (IS_FLG(FLG_WORTHLESS)) {
607         ADD_KEY(KEY_WORTHLESS);
608     }
609     if (IS_FLG(FLG_GOOD)) {
610         ADD_KEY(KEY_GOOD);
611     }
612     if (IS_FLG(FLG_NAMELESS)) {
613         ADD_KEY(KEY_NAMELESS);
614     }
615     if (IS_FLG(FLG_AVERAGE)) {
616         ADD_KEY(KEY_AVERAGE);
617     }
618     if (IS_FLG(FLG_RARE)) {
619         ADD_KEY(KEY_RARE);
620     }
621     if (IS_FLG(FLG_COMMON)) {
622         ADD_KEY(KEY_COMMON);
623     }
624     if (IS_FLG(FLG_EGO)) {
625         ADD_KEY(KEY_EGO);
626     }
627
628     if (IS_FLG(FLG_ARTIFACT)) {
629         ADD_KEY(KEY_ARTIFACT);
630     }
631
632     bool sepa_flag = true;
633     if (IS_FLG(FLG_ITEMS)) {
634         ADD_KEY2(KEY_ITEMS);
635     } else if (IS_FLG(FLG_WEAPONS)) {
636         ADD_KEY2(KEY_WEAPONS);
637     } else if (IS_FLG(FLG_FAVORITE_WEAPONS)) {
638         ADD_KEY2(KEY_FAVORITE_WEAPONS);
639     } else if (IS_FLG(FLG_ARMORS)) {
640         ADD_KEY2(KEY_ARMORS);
641     } else if (IS_FLG(FLG_MISSILES)) {
642         ADD_KEY2(KEY_MISSILES);
643     } else if (IS_FLG(FLG_DEVICES)) {
644         ADD_KEY2(KEY_DEVICES);
645     } else if (IS_FLG(FLG_LIGHTS)) {
646         ADD_KEY2(KEY_LIGHTS);
647     } else if (IS_FLG(FLG_JUNKS)) {
648         ADD_KEY2(KEY_JUNKS);
649     } else if (IS_FLG(FLG_CORPSES)) {
650         ADD_KEY2(KEY_CORPSES);
651     } else if (IS_FLG(FLG_SPELLBOOKS)) {
652         ADD_KEY2(KEY_SPELLBOOKS);
653     } else if (IS_FLG(FLG_HAFTED)) {
654         ADD_KEY2(KEY_HAFTED);
655     } else if (IS_FLG(FLG_SHIELDS)) {
656         ADD_KEY2(KEY_SHIELDS);
657     } else if (IS_FLG(FLG_BOWS)) {
658         ADD_KEY2(KEY_BOWS);
659     } else if (IS_FLG(FLG_RINGS)) {
660         ADD_KEY2(KEY_RINGS);
661     } else if (IS_FLG(FLG_AMULETS)) {
662         ADD_KEY2(KEY_AMULETS);
663     } else if (IS_FLG(FLG_SUITS)) {
664         ADD_KEY2(KEY_SUITS);
665     } else if (IS_FLG(FLG_CLOAKS)) {
666         ADD_KEY2(KEY_CLOAKS);
667     } else if (IS_FLG(FLG_HELMS)) {
668         ADD_KEY2(KEY_HELMS);
669     } else if (IS_FLG(FLG_GLOVES)) {
670         ADD_KEY2(KEY_GLOVES);
671     } else if (IS_FLG(FLG_BOOTS)) {
672         ADD_KEY2(KEY_BOOTS);
673     } else if (!IS_FLG(FLG_ARTIFACT)) {
674         sepa_flag = false;
675     }
676
677     if (!entry->name.empty()) {
678         if (sepa_flag) {
679             strcat(buf, ":");
680         }
681
682         int i = strlen(buf);
683         int j = 0;
684         while (entry->name[j] && i < MAX_LINELEN - 2 - 1) {
685 #ifdef JP
686             if (iskanji(entry->name[j])) {
687                 buf[i++] = entry->name[j++];
688             }
689 #endif
690             buf[i++] = entry->name[j++];
691         }
692         buf[i] = '\0';
693     }
694
695     if (entry->insc.empty()) {
696         return string_make(buf);
697     }
698
699     int i, j = 0;
700     strcat(buf, "#");
701     i = strlen(buf);
702
703     while (entry->insc[j] && i < MAX_LINELEN - 2) {
704 #ifdef JP
705         if (iskanji(entry->insc[j])) {
706             buf[i++] = entry->insc[j++];
707         }
708 #endif
709         buf[i++] = entry->insc[j++];
710     }
711
712     buf[i] = '\0';
713     return string_make(buf);
714 }
715
716 /*!
717  * @brief Reconstruct preference line from entry and kill entry
718  */
719 concptr autopick_line_from_entry_kill(autopick_type *entry)
720 {
721     concptr ptr = autopick_line_from_entry(entry);
722     return ptr;
723 }
724
725 /*!
726  * @brief Choose an item and get auto-picker entry from it.
727  */
728 bool entry_from_choosed_object(PlayerType *player_ptr, autopick_type *entry)
729 {
730     concptr q = _("どのアイテムを登録しますか? ", "Enter which item? ");
731     concptr s = _("アイテムを持っていない。", "You have nothing to enter.");
732     ObjectType *o_ptr;
733     o_ptr = choose_object(player_ptr, nullptr, q, s, USE_INVEN | USE_FLOOR | USE_EQUIP);
734     if (!o_ptr) {
735         return false;
736     }
737
738     autopick_entry_from_object(player_ptr, entry, o_ptr);
739     return true;
740 }