OSDN Git Service

Merge remote-tracking branch 'remotes/hengband-osx/For2.2.2-Refactoring-English-New...
[hengband/hengband.git] / src / autopick / autopick-util.c
1 #include "autopick/autopick-util.h"
2 #include "autopick/autopick-menu-data-table.h"
3 #include "core/player-update-types.h"
4 #include "core/window-redrawer.h"
5 #include "game-option/input-options.h"
6 #include "main/sound-of-music.h"
7 #include "monster-race/race-indice-types.h"
8 #include "object-enchant/item-feeling.h"
9 #include "util/quarks.h"
10
11 /*
12  * 自動拾い/破壊設定のリストに関する変数 / List for auto-picker/destroyer entries
13  */
14 int max_autopick = 0; /*!< 現在登録している自動拾い/破壊設定の数 */
15 int max_max_autopick = 0; /*!< 自動拾い/破壊設定の限界数 */
16 autopick_type *autopick_list = NULL; /*!< 自動拾い/破壊設定構造体のポインタ配列 */
17
18 /*
19  * Automatically destroy an item if it is to be destroyed
20  *
21  * When always_pickup is 'yes', we disable auto-destroyer function of
22  * auto-picker/destroyer, and do only easy-auto-destroyer.
23  */
24 object_type autopick_last_destroyed_object;
25
26 /*
27  * A function to delete entry
28  */
29 void autopick_free_entry(autopick_type *entry)
30 {
31         string_free(entry->name);
32         string_free(entry->insc);
33         entry->name = NULL;
34         entry->insc = NULL;
35 }
36
37
38 /*
39  * Free memory of lines_list.
40  */
41 void free_text_lines(concptr *lines_list)
42 {
43         for (int lines = 0; lines_list[lines]; lines++)
44         {
45                 string_free(lines_list[lines]);
46         }
47
48         /* free list of pointers */
49         C_KILL(lines_list, MAX_LINES, concptr);
50 }
51
52
53 /*
54  * Find a command by 'key'.
55  */
56 int get_com_id(char key)
57 {
58         for (int i = 0; menu_data[i].name; i++)
59         {
60                 if (menu_data[i].key == key)
61                 {
62                         return menu_data[i].com_id;
63                 }
64         }
65
66         return 0;
67 }
68
69
70 /*
71  * Auto inscription
72  */
73 void auto_inscribe_item(player_type *player_ptr, object_type *o_ptr, int idx)
74 {
75         if (idx < 0 || !autopick_list[idx].insc) return;
76
77         if (!o_ptr->inscription)
78                 o_ptr->inscription = quark_add(autopick_list[idx].insc);
79
80         player_ptr->window |= (PW_EQUIP | PW_INVEN);
81         player_ptr->update |= (PU_BONUS);
82 }
83
84
85 /*
86  * Add one line to autopick_list[]
87  */
88 void add_autopick_list(autopick_type *entry)
89 {
90         if (max_autopick >= max_max_autopick)
91         {
92                 int old_max_max_autopick = max_max_autopick;
93                 autopick_type *old_autopick_list = autopick_list;
94                 max_max_autopick += MAX_AUTOPICK_DEFAULT;
95                 C_MAKE(autopick_list, max_max_autopick, autopick_type);
96                 (void)C_COPY(autopick_list, old_autopick_list, old_max_max_autopick, autopick_type);
97                 C_KILL(old_autopick_list, old_max_max_autopick, autopick_type);
98         }
99
100         autopick_list[max_autopick] = *entry;
101         max_autopick++;
102 }