OSDN Git Service

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