OSDN Git Service

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