OSDN Git Service

[Refactor] #3230 PlayerType::update に関わる処理を、RedrawingFlagsUpdaterに集約した
[hengbandforosx/hengbandosx.git] / src / autopick / autopick-util.cpp
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 "system/item-entity.h"
10 #include "system/player-type-definition.h"
11 #include "system/redrawing-flags-updater.h"
12 #include "util/bit-flags-calculator.h"
13 #include "util/quarks.h"
14
15 /*!
16  * @brief 自動拾い/破壊設定のリストに関する変数 / List for auto-picker/destroyer entries
17  */
18 std::vector<autopick_type> autopick_list; /*!< 自動拾い/破壊設定構造体の配列 */
19
20 /*!
21  * @brief Automatically destroy an item if it is to be destroyed
22  * @details
23  * When always_pickup is 'yes', we disable auto-destroyer function of
24  * auto-picker/destroyer, and do only easy-auto-destroyer.
25  */
26 ItemEntity autopick_last_destroyed_object;
27
28 bool autopick_type::has(int flag) const
29 {
30     return this->flags[flag / 32] & (1UL << (flag % 32));
31 }
32
33 void autopick_type::add(int flag)
34 {
35     set_bits(this->flags[flag / 32], 1UL << (flag % 32));
36 }
37
38 void autopick_type::remove(int flag)
39 {
40     reset_bits(this->flags[flag / 32], 1UL << (flag % 32));
41 }
42
43 /*!
44  * @brief Free memory of lines_list.
45  */
46 void free_text_lines(std::vector<concptr> &lines_list)
47 {
48     for (int lines = 0; lines_list[lines]; lines++) {
49         string_free(lines_list[lines]);
50     }
51
52     lines_list.clear();
53 }
54
55 /*!
56  * @brief Find a command by 'key'.
57  */
58 int get_com_id(char key)
59 {
60     for (int i = 0; menu_data[i].name; i++) {
61         if (menu_data[i].key == key) {
62             return menu_data[i].com_id;
63         }
64     }
65
66     return 0;
67 }
68
69 /*!
70  * @brief Auto inscription
71  */
72 void auto_inscribe_item(PlayerType *player_ptr, ItemEntity *o_ptr, int idx)
73 {
74     if (idx < 0 || autopick_list[idx].insc.empty()) {
75         return;
76     }
77
78     if (!o_ptr->is_inscribed()) {
79         o_ptr->inscription = autopick_list[idx].insc;
80     }
81
82     auto &rfu = RedrawingFlagsUpdater::get_instance();
83     player_ptr->window_flags |= (PW_EQUIPMENT | PW_INVENTORY);
84     const auto flags = {
85         StatusRedrawingFlag::BONUS,
86         StatusRedrawingFlag::COMBINATION,
87     };
88     rfu.set_flags(flags);
89 }
90
91 /*!
92  * @brief 行数をカウントする
93  * @param tb text_body_type
94  * @return 行数
95  */
96 int count_line(text_body_type *tb)
97 {
98     int num_lines;
99     for (num_lines = 0; tb->lines_list[num_lines]; num_lines++) {
100         ;
101     }
102
103     return num_lines;
104 }