OSDN Git Service

Merge pull request #2214 from Hourier/Rename-Pascal-Case-To-Snake-Case
[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     if (!o_ptr->is_known())
28         return;
29
30 #ifdef JP
31     if (o_ptr->pval <= 0) {
32         msg_print("もう魔力が残っていない。");
33     } else {
34         msg_format("あと %d 回分の魔力が残っている。", o_ptr->pval);
35     }
36 #else
37     if (o_ptr->pval != 1) {
38         msg_format("You have %d charges remaining.", o_ptr->pval);
39     }
40
41     else {
42         msg_format("You have %d charge remaining.", o_ptr->pval);
43     }
44 #endif
45 }
46
47 /*!
48  * @brief アイテムの残り所持数メッセージを表示する /
49  * Describe an item in the inventory.
50  * @param player_ptr プレイヤーへの参照ポインタ
51  * @param item 残量を表示したいプレイヤーのアイテム所持スロット
52  */
53 void inven_item_describe(PlayerType *player_ptr, INVENTORY_IDX item)
54 {
55     auto *o_ptr = &player_ptr->inventory_list[item];
56     GAME_TEXT o_name[MAX_NLEN];
57     describe_flavor(player_ptr, o_name, o_ptr, 0);
58 #ifdef JP
59     if (o_ptr->number <= 0) {
60         msg_format("もう%sを持っていない。", o_name);
61     } else {
62         msg_format("まだ %sを持っている。", o_name);
63     }
64 #else
65     msg_format("You have %s.", o_name);
66 #endif
67 }
68
69 /*!
70  * @brief 現在アクティブになっているウィンドウにオブジェクトの詳細を表示する /
71  * Hack -- display an object kind in the current window
72  * @param player_ptr プレイヤーへの参照ポインタ
73  * @param k_idx ベースアイテムの参照ID
74  * @details
75  * Include list of usable spells for readible books
76  */
77 void display_koff(PlayerType *player_ptr, KIND_OBJECT_IDX k_idx)
78 {
79     ObjectType forge;
80     ObjectType *q_ptr;
81     int sval;
82     int16_t use_realm;
83     GAME_TEXT o_name[MAX_NLEN];
84     for (int y = 0; y < game_term->hgt; y++) {
85         term_erase(0, y, 255);
86     }
87
88     if (!k_idx)
89         return;
90     q_ptr = &forge;
91
92     q_ptr->prep(k_idx);
93     describe_flavor(player_ptr, o_name, q_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY | OD_STORE));
94
95     term_putstr(0, 0, -1, TERM_WHITE, o_name);
96     sval = q_ptr->sval;
97     use_realm = tval2realm(q_ptr->tval);
98
99     if (player_ptr->realm1 || player_ptr->realm2) {
100         if ((use_realm != player_ptr->realm1) && (use_realm != player_ptr->realm2))
101             return;
102     } else {
103         PlayerClass pc(player_ptr);
104         if (!pc.is_every_magic())
105             return;
106         if (!is_magic(use_realm))
107             return;
108         if (pc.equals(PlayerClassType::RED_MAGE) && (use_realm != REALM_ARCANE) && (sval > 1))
109             return;
110     }
111
112     int num = 0;
113     SPELL_IDX spells[64];
114
115     for (int spell = 0; spell < 32; spell++) {
116         if (fake_spell_flags[sval] & (1UL << spell)) {
117             spells[num++] = spell;
118         }
119     }
120
121     print_spells(player_ptr, 0, spells, num, 2, 0, use_realm);
122 }