OSDN Git Service

Merge pull request #2290 from habu1010/feature/clang-format-insert-braces
[hengbandforosx/hengbandosx.git] / src / view / object-describer.cpp
1 #include "view/object-describer.h"
2 #include "cmd-action/cmd-spell.h"
3 #include "flavor/flavor-describer.h"
4 #include "flavor/object-flavor-types.h"
5 #include "object-enchant/special-object-flags.h"
6 #include "object/tval-types.h"
7 #include "perception/object-perception.h"
8 #include "player-base/player-class.h"
9 #include "realm/realm-names-table.h"
10 #include "spell/spell-info.h"
11 #include "system/object-type-definition.h"
12 #include "system/player-type-definition.h"
13 #include "term/term-color-types.h"
14 #include "view/display-messages.h"
15
16 /*!
17  * @brief 魔道具の使用回数の残量を示すメッセージを表示する /
18  * Describe the charges on an item in the inventory.
19  * @param player_ptr プレイヤーへの参照ポインタ
20  * @param item 残量を表示したいプレイヤーのアイテム所持スロット
21  */
22 void inven_item_charges(PlayerType *player_ptr, INVENTORY_IDX item)
23 {
24     auto *o_ptr = &player_ptr->inventory_list[item];
25     if ((o_ptr->tval != ItemKindType::STAFF) && (o_ptr->tval != ItemKindType::WAND)) {
26         return;
27     }
28     if (!o_ptr->is_known()) {
29         return;
30     }
31
32 #ifdef JP
33     if (o_ptr->pval <= 0) {
34         msg_print("もう魔力が残っていない。");
35     } else {
36         msg_format("あと %d 回分の魔力が残っている。", o_ptr->pval);
37     }
38 #else
39     if (o_ptr->pval != 1) {
40         msg_format("You have %d charges remaining.", o_ptr->pval);
41     }
42
43     else {
44         msg_format("You have %d charge remaining.", o_ptr->pval);
45     }
46 #endif
47 }
48
49 /*!
50  * @brief アイテムの残り所持数メッセージを表示する /
51  * Describe an item in the inventory.
52  * @param player_ptr プレイヤーへの参照ポインタ
53  * @param item 残量を表示したいプレイヤーのアイテム所持スロット
54  */
55 void inven_item_describe(PlayerType *player_ptr, INVENTORY_IDX item)
56 {
57     auto *o_ptr = &player_ptr->inventory_list[item];
58     GAME_TEXT o_name[MAX_NLEN];
59     describe_flavor(player_ptr, o_name, o_ptr, 0);
60 #ifdef JP
61     if (o_ptr->number <= 0) {
62         msg_format("もう%sを持っていない。", o_name);
63     } else {
64         msg_format("まだ %sを持っている。", o_name);
65     }
66 #else
67     msg_format("You have %s.", o_name);
68 #endif
69 }
70
71 /*!
72  * @brief 現在アクティブになっているウィンドウにオブジェクトの詳細を表示する /
73  * Hack -- display an object kind in the current window
74  * @param player_ptr プレイヤーへの参照ポインタ
75  * @param k_idx ベースアイテムの参照ID
76  * @details
77  * Include list of usable spells for readible books
78  */
79 void display_koff(PlayerType *player_ptr, KIND_OBJECT_IDX k_idx)
80 {
81     ObjectType forge;
82     ObjectType *q_ptr;
83     int sval;
84     int16_t use_realm;
85     GAME_TEXT o_name[MAX_NLEN];
86     for (int y = 0; y < game_term->hgt; y++) {
87         term_erase(0, y, 255);
88     }
89
90     if (!k_idx) {
91         return;
92     }
93     q_ptr = &forge;
94
95     q_ptr->prep(k_idx);
96     describe_flavor(player_ptr, o_name, q_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY | OD_STORE));
97
98     term_putstr(0, 0, -1, TERM_WHITE, o_name);
99     sval = q_ptr->sval;
100     use_realm = tval2realm(q_ptr->tval);
101
102     if (player_ptr->realm1 || player_ptr->realm2) {
103         if ((use_realm != player_ptr->realm1) && (use_realm != player_ptr->realm2)) {
104             return;
105         }
106     } else {
107         PlayerClass pc(player_ptr);
108         if (!pc.is_every_magic()) {
109             return;
110         }
111         if (!is_magic(use_realm)) {
112             return;
113         }
114         if (pc.equals(PlayerClassType::RED_MAGE) && (use_realm != REALM_ARCANE) && (sval > 1)) {
115             return;
116         }
117     }
118
119     int num = 0;
120     SPELL_IDX spells[64];
121
122     for (int spell = 0; spell < 32; spell++) {
123         if (fake_spell_flags[sval] & (1UL << spell)) {
124             spells[num++] = spell;
125         }
126     }
127
128     print_spells(player_ptr, 0, spells, num, 2, 0, use_realm);
129 }