OSDN Git Service

[Refactor] #40521 Separated inventory-slot-types.h from player-status.h
[hengband/hengband.git] / src / view / display-player-middle.c
1 #include "view/display-player-middle.h"
2 #include "combat/shoot.h"
3 #include "floor/floor.h"
4 #include "game-option/birth-options.h"
5 #include "game-option/special-options.h"
6 #include "inventory/inventory-slot-types.h"
7 #include "mind/stances-table.h"
8 #include "monster/monster-status.h"
9 #include "object-enchant/special-object-flags.h"
10 #include "perception/object-perception.h"
11 #include "player/player-race-types.h"
12 #include "player/player-skill.h"
13 #include "sv-definition/sv-bow-types.h"
14 #include "system/object-type-definition.h"
15 #include "term/term-color-types.h"
16 #include "view/display-util.h"
17 #include "view/status-first-page.h"
18 #include "world/world.h"
19
20 /*!
21  * @brief プレイヤーの打撃能力修正を表示する
22  * @param creature_ptr プレーヤーへの参照ポインタ
23  * @param hand 武器の装備部位ID
24  * @param hand_entry 項目ID
25  * @return なし
26  */
27 static void display_player_melee_bonus(player_type *creature_ptr, int hand, int hand_entry)
28 {
29         HIT_PROB show_tohit = creature_ptr->dis_to_h[hand];
30         HIT_POINT show_todam = creature_ptr->dis_to_d[hand];
31         object_type *o_ptr = &creature_ptr->inventory_list[INVEN_RARM + hand];
32
33         if (object_is_known(o_ptr)) show_tohit += o_ptr->to_h;
34         if (object_is_known(o_ptr)) show_todam += o_ptr->to_d;
35
36         show_tohit += creature_ptr->skill_thn / BTH_PLUS_ADJ;
37
38         char buf[160];
39         sprintf(buf, "(%+d,%+d)", (int)show_tohit, (int)show_todam);
40
41         if (!has_melee_weapon(creature_ptr, INVEN_RARM) && !has_melee_weapon(creature_ptr, INVEN_LARM))
42                 display_player_one_line(ENTRY_BARE_HAND, buf, TERM_L_BLUE);
43         else if (creature_ptr->ryoute)
44                 display_player_one_line(ENTRY_TWO_HANDS, buf, TERM_L_BLUE);
45         else
46                 display_player_one_line(hand_entry, buf, TERM_L_BLUE);
47 }
48
49
50 /*!
51  * @brief 右手に比べて左手の表示ルーチンが複雑なので分離
52  * @param creature_ptr プレーヤーへの参照ポインタ
53  * @return なし
54  */
55 static void display_left_hand(player_type *creature_ptr)
56 {
57         if (creature_ptr->hidarite)
58         {
59                 display_player_melee_bonus(creature_ptr, 1, left_hander ? ENTRY_RIGHT_HAND2 : ENTRY_LEFT_HAND2);
60                 return;
61         }
62
63         if ((creature_ptr->pclass != CLASS_MONK) || ((empty_hands(creature_ptr, TRUE) & EMPTY_HAND_RARM) == 0))
64                 return;
65
66         if ((creature_ptr->special_defense & KAMAE_MASK) == 0)
67         {
68                 display_player_one_line(ENTRY_POSTURE, _("構えなし", "none"), TERM_YELLOW);
69                 return;
70         }
71
72         int kamae_num;
73         for (kamae_num = 0; kamae_num < MAX_KAMAE; kamae_num++)
74         {
75                 if ((creature_ptr->special_defense >> kamae_num) & KAMAE_GENBU)
76                         break;
77         }
78
79         if (kamae_num < MAX_KAMAE)
80         {
81                 display_player_one_line(ENTRY_POSTURE, format(_("%sの構え", "%s form"), monk_stances[kamae_num].desc), TERM_YELLOW);
82         }
83 }
84
85
86 /*!
87  * @brief 武器による命中率とダメージの補正を表示する
88  * @param creature_ptr プレーヤーへの参照ポインタ
89  * @return なし
90  */
91 static void display_hit_damage(player_type *creature_ptr)
92 {
93         object_type *o_ptr = &creature_ptr->inventory_list[INVEN_BOW];
94         HIT_PROB show_tohit = creature_ptr->dis_to_h_b;
95         HIT_POINT show_todam = 0;
96         if (object_is_known(o_ptr)) show_tohit += o_ptr->to_h;
97         if (object_is_known(o_ptr)) show_todam += o_ptr->to_d;
98
99         if ((o_ptr->sval == SV_LIGHT_XBOW) || (o_ptr->sval == SV_HEAVY_XBOW))
100                 show_tohit += creature_ptr->weapon_exp[0][o_ptr->sval] / 400;
101         else
102                 show_tohit += (creature_ptr->weapon_exp[0][o_ptr->sval] - (WEAPON_EXP_MASTER / 2)) / 200;
103
104         show_tohit += creature_ptr->skill_thb / BTH_PLUS_ADJ;
105
106         display_player_one_line(ENTRY_SHOOT_HIT_DAM, format("(%+d,%+d)", show_tohit, show_todam), TERM_L_BLUE);
107 }
108
109
110 /*!
111  * @brief 射撃武器倍率を表示する
112  * @param creature_ptr プレーヤーへの参照ポインタ
113  * @return なし
114  */
115 static void display_shoot_magnification(player_type *creature_ptr)
116 {
117         int tmul = 0;
118         if (creature_ptr->inventory_list[INVEN_BOW].k_idx)
119         {
120                 tmul = bow_tmul(creature_ptr->inventory_list[INVEN_BOW].sval);
121                 if (creature_ptr->xtra_might) tmul++;
122
123                 tmul = tmul * (100 + (int)(adj_str_td[creature_ptr->stat_ind[A_STR]]) - 128);
124         }
125
126         display_player_one_line(ENTRY_SHOOT_POWER, format("x%d.%02d", tmul / 100, tmul % 100), TERM_L_BLUE);
127 }
128
129
130 /*!
131  * @brief プレーヤーの速度から表示色を決める
132  * @param creature_ptr プレーヤーへの参照ポインタ
133  * @param base_speed プレーヤーの速度
134  */
135 static TERM_COLOR decide_speed_color(player_type *creature_ptr, const int base_speed)
136 {
137         TERM_COLOR attr;
138         if (base_speed > 0)
139         {
140                 if (!creature_ptr->riding)
141                         attr = TERM_L_GREEN;
142                 else
143                         attr = TERM_GREEN;
144         }
145         else if (base_speed == 0)
146         {
147                 if (!creature_ptr->riding)
148                         attr = TERM_L_BLUE;
149                 else
150                         attr = TERM_GREEN;
151         }
152         else
153         {
154                 if (!creature_ptr->riding)
155                         attr = TERM_L_UMBER;
156                 else
157                         attr = TERM_RED;
158         }
159
160         return attr;
161 }
162
163
164 /*!
165  * @brief 何らかの効果による一時的な速度変化を計算する
166  * @param creature_ptr プレーヤーへの参照ポインタ
167  * @return プレーヤーの速度
168  */
169 static int calc_temporary_speed(player_type *creature_ptr)
170 {
171         int tmp_speed = 0;
172         if (!creature_ptr->riding)
173         {
174                 if (is_fast(creature_ptr)) tmp_speed += 10;
175                 if (creature_ptr->slow) tmp_speed -= 10;
176                 if (creature_ptr->lightspeed) tmp_speed = 99;
177         }
178         else
179         {
180                 if (monster_fast_remaining(&creature_ptr->current_floor_ptr->m_list[creature_ptr->riding])) tmp_speed += 10;
181                 if (monster_slow_remaining(&creature_ptr->current_floor_ptr->m_list[creature_ptr->riding])) tmp_speed -= 10;
182         }
183
184         return tmp_speed;
185 }
186
187
188 /*!
189  * @brief プレーヤーの最終的な速度を表示する
190  * @param creature_ptr プレーヤーへの参照ポインタ
191  * @param attr 表示色
192  * @param base_speed プレーヤーの素の速度
193  * @param tmp_speed アイテム等で一時的に変化した速度量
194  * @return なし
195  */
196 static void display_player_speed(player_type *creature_ptr, TERM_COLOR attr, int base_speed, int tmp_speed)
197 {
198         char buf[160];
199         if (tmp_speed)
200         {
201                 if (!creature_ptr->riding)
202                         sprintf(buf, "(%+d%+d)", base_speed - tmp_speed, tmp_speed);
203                 else
204                         sprintf(buf, _("乗馬中 (%+d%+d)", "Riding (%+d%+d)"), base_speed - tmp_speed, tmp_speed);
205
206                 if (tmp_speed > 0)
207                         attr = TERM_YELLOW;
208                 else
209                         attr = TERM_VIOLET;
210         }
211         else
212         {
213                 if (!creature_ptr->riding)
214                         sprintf(buf, "(%+d)", base_speed);
215                 else
216                         sprintf(buf, _("乗馬中 (%+d)", "Riding (%+d)"), base_speed);
217         }
218
219         display_player_one_line(ENTRY_SPEED, buf, attr);
220         display_player_one_line(ENTRY_LEVEL, format("%d", creature_ptr->lev), TERM_L_GREEN);
221 }
222
223
224 /*!
225  * @brief プレーヤーの現在経験値・最大経験値・次のレベルまでに必要な経験値を表示する
226  * @param creature_ptr プレーヤーへの参照ポインタ
227  * @return なし
228  */
229 static void display_player_exp(player_type *creature_ptr)
230 {
231         int e = (creature_ptr->prace == RACE_ANDROID) ? ENTRY_EXP_ANDR : ENTRY_CUR_EXP;
232         if (creature_ptr->exp >= creature_ptr->max_exp)
233                 display_player_one_line(e, format("%ld", creature_ptr->exp), TERM_L_GREEN);
234         else
235                 display_player_one_line(e, format("%ld", creature_ptr->exp), TERM_YELLOW);
236
237         if (creature_ptr->prace != RACE_ANDROID)
238                 display_player_one_line(ENTRY_MAX_EXP, format("%ld", creature_ptr->max_exp), TERM_L_GREEN);
239
240         e = (creature_ptr->prace == RACE_ANDROID) ? ENTRY_EXP_TO_ADV_ANDR : ENTRY_EXP_TO_ADV;
241
242         if (creature_ptr->lev >= PY_MAX_LEVEL)
243                 display_player_one_line(e, "*****", TERM_L_GREEN);
244         else if (creature_ptr->prace == RACE_ANDROID)
245                 display_player_one_line(e, format("%ld", (s32b)(player_exp_a[creature_ptr->lev - 1] * creature_ptr->expfact / 100L)), TERM_L_GREEN);
246         else
247                 display_player_one_line(e, format("%ld", (s32b)(player_exp[creature_ptr->lev - 1] * creature_ptr->expfact / 100L)), TERM_L_GREEN);
248 }
249
250
251 /*!
252  * @brief ゲーム内の経過時間を表示する
253  * @param creature_ptr プレーヤーへの参照ポインタ
254  * @return なし
255  */
256 static void display_playtime_in_game(player_type *creature_ptr)
257 {
258         int day, hour, min;
259         extract_day_hour_min(creature_ptr, &day, &hour, &min);
260
261         char buf[160];
262         if (day < MAX_DAYS)
263                 sprintf(buf, _("%d日目 %2d:%02d", "Day %d %2d:%02d"), day, hour, min);
264         else
265                 sprintf(buf, _("*****日目 %2d:%02d", "Day ***** %2d:%02d"), hour, min);
266
267         display_player_one_line(ENTRY_DAY, buf, TERM_L_GREEN);
268
269         if (creature_ptr->chp >= creature_ptr->mhp)
270                 display_player_one_line(ENTRY_HP, format("%4d/%4d", creature_ptr->chp, creature_ptr->mhp), TERM_L_GREEN);
271         else if (creature_ptr->chp > (creature_ptr->mhp * hitpoint_warn) / 10)
272                 display_player_one_line(ENTRY_HP, format("%4d/%4d", creature_ptr->chp, creature_ptr->mhp), TERM_YELLOW);
273         else
274                 display_player_one_line(ENTRY_HP, format("%4d/%4d", creature_ptr->chp, creature_ptr->mhp), TERM_RED);
275
276         if (creature_ptr->csp >= creature_ptr->msp)
277                 display_player_one_line(ENTRY_SP, format("%4d/%4d", creature_ptr->csp, creature_ptr->msp), TERM_L_GREEN);
278         else if (creature_ptr->csp > (creature_ptr->msp * mana_warn) / 10)
279                 display_player_one_line(ENTRY_SP, format("%4d/%4d", creature_ptr->csp, creature_ptr->msp), TERM_YELLOW);
280         else
281                 display_player_one_line(ENTRY_SP, format("%4d/%4d", creature_ptr->csp, creature_ptr->msp), TERM_RED);
282 }
283
284
285 /*!
286  * @brief 現実世界におけるプレイ時間を表示する
287  * @param なし
288  * @param なし
289  */
290 static void display_real_playtime(void)
291 {
292         u32b play_hour = current_world_ptr->play_time / (60 * 60);
293         u32b play_min = (current_world_ptr->play_time / 60) % 60;
294         u32b play_sec = current_world_ptr->play_time % 60;
295         display_player_one_line(ENTRY_PLAY_TIME, format("%.2lu:%.2lu:%.2lu", play_hour, play_min, play_sec), TERM_L_GREEN);
296 }
297
298
299 /*!
300  * @brief プレイヤーステータス表示の中央部分を表示するサブルーチン
301  * @param creature_ptr プレーヤーへの参照ポインタ
302  * Prints the following information on the screen.
303  * @return なし
304  */
305 void display_player_middle(player_type *creature_ptr)
306 {
307         if (creature_ptr->migite)
308                 display_player_melee_bonus(creature_ptr, 0, left_hander ? ENTRY_LEFT_HAND1 : ENTRY_RIGHT_HAND1);
309
310         display_left_hand(creature_ptr);
311         display_hit_damage(creature_ptr);
312         display_shoot_magnification(creature_ptr);
313         display_player_one_line(ENTRY_BASE_AC, format("[%d,%+d]", creature_ptr->dis_ac, creature_ptr->dis_to_a), TERM_L_BLUE);
314
315         int base_speed = creature_ptr->pspeed - 110;
316         if (creature_ptr->action == ACTION_SEARCH) base_speed += 10;
317
318         TERM_COLOR attr = decide_speed_color(creature_ptr, base_speed);
319         int tmp_speed = calc_temporary_speed(creature_ptr);
320         display_player_speed(creature_ptr, attr, base_speed, tmp_speed);
321         display_player_exp(creature_ptr);
322         display_player_one_line(ENTRY_GOLD, format("%ld", creature_ptr->au), TERM_L_GREEN);
323         display_playtime_in_game(creature_ptr);
324         display_real_playtime();
325 }