OSDN Git Service

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