OSDN Git Service

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