OSDN Git Service

[Refactor] #3187 関数マクロIS_FLG() をautopick_type::has() に差し替えた (autopick-entry.cpp のみ)
[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 "perception/object-perception.h"
21 #include "player-base/player-class.h"
22 #include "player/player-realm.h"
23 #include "system/baseitem-info.h"
24 #include "system/item-entity.h"
25 #include "system/monster-race-info.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->flags[0] = entry->flags[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->flags[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, ItemEntity *o_ptr)
328 {
329     /* Assume that object name is to be added */
330     bool name = true;
331     entry->name.clear();
332     entry->insc = o_ptr->inscription.value_or("");
333     entry->action = DO_AUTOPICK | DO_DISPLAY;
334     entry->flags[0] = entry->flags[1] = 0L;
335     entry->dice = 0;
336
337     // エゴ銘が邪魔かもしれないので、デフォルトで「^」は付けない.
338     // We can always use the ^ mark in English.
339     bool is_hat_added = _(false, true);
340     if (!o_ptr->is_aware()) {
341         ADD_FLG(FLG_UNAWARE);
342         is_hat_added = true;
343     } else if (!o_ptr->is_known()) {
344         if (!(o_ptr->ident & IDENT_SENSE)) {
345             ADD_FLG(FLG_UNIDENTIFIED);
346             is_hat_added = true;
347         } else {
348             switch (o_ptr->feeling) {
349             case FEEL_AVERAGE:
350             case FEEL_GOOD:
351                 ADD_FLG(FLG_NAMELESS);
352                 is_hat_added = true;
353                 break;
354
355             case FEEL_BROKEN:
356             case FEEL_CURSED:
357                 ADD_FLG(FLG_NAMELESS);
358                 ADD_FLG(FLG_WORTHLESS);
359                 is_hat_added = true;
360                 break;
361
362             case FEEL_TERRIBLE:
363             case FEEL_WORTHLESS:
364                 ADD_FLG(FLG_WORTHLESS);
365                 break;
366
367             case FEEL_EXCELLENT:
368                 ADD_FLG(FLG_EGO);
369                 break;
370
371             case FEEL_UNCURSED:
372                 break;
373
374             default:
375                 break;
376             }
377         }
378     } else {
379         if (o_ptr->is_ego()) {
380             if (o_ptr->is_weapon_armour_ammo()) {
381                 /*
382                  * Base name of ego weapons and armors
383                  * are almost meaningless.
384                  * Register the ego type only.
385                  */
386                 auto *e_ptr = &egos_info[o_ptr->ego_idx];
387 #ifdef JP
388                 /* エゴ銘には「^」マークが使える */
389                 entry->name = "^";
390                 entry->name.append(e_ptr->name);
391 #else
392                 /* We omit the basename and cannot use the ^ mark */
393                 entry->name = e_ptr->name;
394 #endif
395                 name = false;
396                 if (!o_ptr->is_rare()) {
397                     ADD_FLG(FLG_COMMON);
398                 }
399             }
400
401             ADD_FLG(FLG_EGO);
402         } else if (o_ptr->is_fixed_or_random_artifact()) {
403             ADD_FLG(FLG_ARTIFACT);
404         } else {
405             if (o_ptr->is_equipment()) {
406                 ADD_FLG(FLG_NAMELESS);
407             }
408
409             is_hat_added = true;
410         }
411     }
412
413     if (o_ptr->is_melee_weapon()) {
414         const auto &baseitem = baseitems_info[o_ptr->bi_id];
415         if ((o_ptr->dd != baseitem.dd) || (o_ptr->ds != baseitem.ds)) {
416             ADD_FLG(FLG_BOOSTED);
417         }
418     }
419
420     if (object_is_bounty(player_ptr, o_ptr)) {
421         REM_FLG(FLG_WORTHLESS);
422         ADD_FLG(FLG_WANTED);
423     }
424
425     const auto r_idx = i2enum<MonsterRaceId>(o_ptr->pval);
426     const auto &bi_key = o_ptr->bi_key;
427     const auto tval = bi_key.tval();
428     if ((tval == ItemKindType::CORPSE || tval == ItemKindType::STATUE) && monraces_info[r_idx].kind_flags.has(MonsterKindType::UNIQUE)) {
429         ADD_FLG(FLG_UNIQUE);
430     }
431
432     if (tval == ItemKindType::CORPSE && angband_strchr("pht", monraces_info[r_idx].d_char)) {
433         ADD_FLG(FLG_HUMAN);
434     }
435
436     if (o_ptr->is_spell_book() && !check_book_realm(player_ptr, bi_key)) {
437         ADD_FLG(FLG_UNREADABLE);
438         if (tval != ItemKindType::ARCANE_BOOK) {
439             name = false;
440         }
441     }
442
443     PlayerClass pc(player_ptr);
444     auto realm_except_class = pc.equals(PlayerClassType::SORCERER) || pc.equals(PlayerClassType::RED_MAGE);
445
446     if ((get_realm1_book(player_ptr) == tval) && !realm_except_class) {
447         ADD_FLG(FLG_REALM1);
448         name = false;
449     }
450
451     if ((get_realm2_book(player_ptr) == tval) && !realm_except_class) {
452         ADD_FLG(FLG_REALM2);
453         name = false;
454     }
455
456     const auto sval = bi_key.sval();
457     if (o_ptr->is_spell_book() && (sval == 0)) {
458         ADD_FLG(FLG_FIRST);
459     }
460     if (o_ptr->is_spell_book() && (sval == 1)) {
461         ADD_FLG(FLG_SECOND);
462     }
463     if (o_ptr->is_spell_book() && (sval == 2)) {
464         ADD_FLG(FLG_THIRD);
465     }
466     if (o_ptr->is_spell_book() && (sval == 3)) {
467         ADD_FLG(FLG_FOURTH);
468     }
469
470     if (o_ptr->is_ammo()) {
471         ADD_FLG(FLG_MISSILES);
472     } else if (tval == ItemKindType::SCROLL || o_ptr->is_wand_staff() || o_ptr->is_wand_rod()) {
473         ADD_FLG(FLG_DEVICES);
474     } else if (tval == ItemKindType::LITE) {
475         ADD_FLG(FLG_LIGHTS);
476     } else if (o_ptr->is_junk()) {
477         ADD_FLG(FLG_JUNKS);
478     } else if (tval == ItemKindType::CORPSE) {
479         ADD_FLG(FLG_CORPSES);
480     } else if (o_ptr->is_spell_book()) {
481         ADD_FLG(FLG_SPELLBOOKS);
482     } else if (o_ptr->is_melee_weapon()) {
483         ADD_FLG(FLG_WEAPONS);
484     } else if (tval == ItemKindType::SHIELD) {
485         ADD_FLG(FLG_SHIELDS);
486     } else if (tval == ItemKindType::BOW) {
487         ADD_FLG(FLG_BOWS);
488     } else if (tval == ItemKindType::RING) {
489         ADD_FLG(FLG_RINGS);
490     } else if (tval == ItemKindType::AMULET) {
491         ADD_FLG(FLG_AMULETS);
492     } else if (o_ptr->is_armour()) {
493         ADD_FLG(FLG_SUITS);
494     } else if (tval == ItemKindType::CLOAK) {
495         ADD_FLG(FLG_CLOAKS);
496     } else if (tval == ItemKindType::HELM) {
497         ADD_FLG(FLG_HELMS);
498     } else if (tval == ItemKindType::GLOVES) {
499         ADD_FLG(FLG_GLOVES);
500     } else if (tval == ItemKindType::BOOTS) {
501         ADD_FLG(FLG_BOOTS);
502     }
503
504     if (!name) {
505         str_tolower(entry->name.data());
506         return;
507     }
508
509     const auto item_name = describe_flavor(player_ptr, 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     entry->name = std::string(is_hat_added ? "^" : "").append(item_name);
516     str_tolower(entry->name.data());
517 }
518
519 /*!
520  * @brief Reconstruct preference line from entry
521  */
522 concptr autopick_line_from_entry(const autopick_type &entry)
523 {
524     char buf[MAX_LINELEN]{};
525     if (!(entry.action & DO_DISPLAY)) {
526         strcat(buf, "(");
527     }
528     if (entry.action & DO_QUERY_AUTOPICK) {
529         strcat(buf, ";");
530     }
531     if (entry.action & DO_AUTODESTROY) {
532         strcat(buf, "!");
533     }
534     if (entry.action & DONT_AUTOPICK) {
535         strcat(buf, "~");
536     }
537
538     char *ptr;
539     ptr = buf;
540     if (entry.has(FLG_ALL)) {
541         ADD_KEY(KEY_ALL);
542     }
543     if (entry.has(FLG_COLLECTING)) {
544         ADD_KEY(KEY_COLLECTING);
545     }
546     if (entry.has(FLG_UNAWARE)) {
547         ADD_KEY(KEY_UNAWARE);
548     }
549     if (entry.has(FLG_UNIDENTIFIED)) {
550         ADD_KEY(KEY_UNIDENTIFIED);
551     }
552     if (entry.has(FLG_IDENTIFIED)) {
553         ADD_KEY(KEY_IDENTIFIED);
554     }
555     if (entry.has(FLG_STAR_IDENTIFIED)) {
556         ADD_KEY(KEY_STAR_IDENTIFIED);
557     }
558     if (entry.has(FLG_BOOSTED)) {
559         ADD_KEY(KEY_BOOSTED);
560     }
561
562     if (entry.has(FLG_MORE_DICE)) {
563         ADD_KEY(KEY_MORE_THAN);
564         strcat(ptr, format("%d", entry.dice).data());
565         ADD_KEY(KEY_DICE);
566     }
567
568     if (entry.has(FLG_MORE_BONUS)) {
569         ADD_KEY(KEY_MORE_BONUS);
570         strcat(ptr, format("%d", entry.bonus).data());
571         ADD_KEY(KEY_MORE_BONUS2);
572     }
573
574     if (entry.has(FLG_UNREADABLE)) {
575         ADD_KEY(KEY_UNREADABLE);
576     }
577     if (entry.has(FLG_REALM1)) {
578         ADD_KEY(KEY_REALM1);
579     }
580     if (entry.has(FLG_REALM2)) {
581         ADD_KEY(KEY_REALM2);
582     }
583     if (entry.has(FLG_FIRST)) {
584         ADD_KEY(KEY_FIRST);
585     }
586     if (entry.has(FLG_SECOND)) {
587         ADD_KEY(KEY_SECOND);
588     }
589     if (entry.has(FLG_THIRD)) {
590         ADD_KEY(KEY_THIRD);
591     }
592     if (entry.has(FLG_FOURTH)) {
593         ADD_KEY(KEY_FOURTH);
594     }
595     if (entry.has(FLG_WANTED)) {
596         ADD_KEY(KEY_WANTED);
597     }
598     if (entry.has(FLG_UNIQUE)) {
599         ADD_KEY(KEY_UNIQUE);
600     }
601     if (entry.has(FLG_HUMAN)) {
602         ADD_KEY(KEY_HUMAN);
603     }
604     if (entry.has(FLG_WORTHLESS)) {
605         ADD_KEY(KEY_WORTHLESS);
606     }
607     if (entry.has(FLG_GOOD)) {
608         ADD_KEY(KEY_GOOD);
609     }
610     if (entry.has(FLG_NAMELESS)) {
611         ADD_KEY(KEY_NAMELESS);
612     }
613     if (entry.has(FLG_AVERAGE)) {
614         ADD_KEY(KEY_AVERAGE);
615     }
616     if (entry.has(FLG_RARE)) {
617         ADD_KEY(KEY_RARE);
618     }
619     if (entry.has(FLG_COMMON)) {
620         ADD_KEY(KEY_COMMON);
621     }
622     if (entry.has(FLG_EGO)) {
623         ADD_KEY(KEY_EGO);
624     }
625
626     if (entry.has(FLG_ARTIFACT)) {
627         ADD_KEY(KEY_ARTIFACT);
628     }
629
630     bool sepa_flag = true;
631     if (entry.has(FLG_ITEMS)) {
632         ADD_KEY2(KEY_ITEMS);
633     } else if (entry.has(FLG_WEAPONS)) {
634         ADD_KEY2(KEY_WEAPONS);
635     } else if (entry.has(FLG_FAVORITE_WEAPONS)) {
636         ADD_KEY2(KEY_FAVORITE_WEAPONS);
637     } else if (entry.has(FLG_ARMORS)) {
638         ADD_KEY2(KEY_ARMORS);
639     } else if (entry.has(FLG_MISSILES)) {
640         ADD_KEY2(KEY_MISSILES);
641     } else if (entry.has(FLG_DEVICES)) {
642         ADD_KEY2(KEY_DEVICES);
643     } else if (entry.has(FLG_LIGHTS)) {
644         ADD_KEY2(KEY_LIGHTS);
645     } else if (entry.has(FLG_JUNKS)) {
646         ADD_KEY2(KEY_JUNKS);
647     } else if (entry.has(FLG_CORPSES)) {
648         ADD_KEY2(KEY_CORPSES);
649     } else if (entry.has(FLG_SPELLBOOKS)) {
650         ADD_KEY2(KEY_SPELLBOOKS);
651     } else if (entry.has(FLG_HAFTED)) {
652         ADD_KEY2(KEY_HAFTED);
653     } else if (entry.has(FLG_SHIELDS)) {
654         ADD_KEY2(KEY_SHIELDS);
655     } else if (entry.has(FLG_BOWS)) {
656         ADD_KEY2(KEY_BOWS);
657     } else if (entry.has(FLG_RINGS)) {
658         ADD_KEY2(KEY_RINGS);
659     } else if (entry.has(FLG_AMULETS)) {
660         ADD_KEY2(KEY_AMULETS);
661     } else if (entry.has(FLG_SUITS)) {
662         ADD_KEY2(KEY_SUITS);
663     } else if (entry.has(FLG_CLOAKS)) {
664         ADD_KEY2(KEY_CLOAKS);
665     } else if (entry.has(FLG_HELMS)) {
666         ADD_KEY2(KEY_HELMS);
667     } else if (entry.has(FLG_GLOVES)) {
668         ADD_KEY2(KEY_GLOVES);
669     } else if (entry.has(FLG_BOOTS)) {
670         ADD_KEY2(KEY_BOOTS);
671     } else if (!entry.has(FLG_ARTIFACT)) {
672         sepa_flag = false;
673     }
674
675     if (!entry.name.empty()) {
676         if (sepa_flag) {
677             strcat(buf, ":");
678         }
679
680         int i = strlen(buf);
681         int j = 0;
682         while (entry.name[j] && i < MAX_LINELEN - 2 - 1) {
683 #ifdef JP
684             if (iskanji(entry.name[j])) {
685                 buf[i++] = entry.name[j++];
686             }
687 #endif
688             buf[i++] = entry.name[j++];
689         }
690         buf[i] = '\0';
691     }
692
693     if (entry.insc.empty()) {
694         return string_make(buf);
695     }
696
697     int i, j = 0;
698     strcat(buf, "#");
699     i = strlen(buf);
700
701     while (entry.insc[j] && i < MAX_LINELEN - 2) {
702 #ifdef JP
703         if (iskanji(entry.insc[j])) {
704             buf[i++] = entry.insc[j++];
705         }
706 #endif
707         buf[i++] = entry.insc[j++];
708     }
709
710     buf[i] = '\0';
711     return string_make(buf);
712 }
713
714 /*!
715  * @brief Reconstruct preference line from entry and kill entry
716  */
717 concptr autopick_line_from_entry_kill(autopick_type *entry)
718 {
719     return autopick_line_from_entry(*entry);
720 }
721
722 /*!
723  * @brief Choose an item and get auto-picker entry from it.
724  */
725 bool entry_from_choosed_object(PlayerType *player_ptr, autopick_type *entry)
726 {
727     constexpr auto q = _("どのアイテムを登録しますか? ", "Enter which item? ");
728     constexpr auto s = _("アイテムを持っていない。", "You have nothing to enter.");
729     auto *o_ptr = choose_object(player_ptr, nullptr, q, s, USE_INVEN | USE_FLOOR | USE_EQUIP);
730     if (!o_ptr) {
731         return false;
732     }
733
734     autopick_entry_from_object(player_ptr, entry, o_ptr);
735     return true;
736 }