OSDN Git Service

[Refactor] #40514 アイテムスロット型 inventory_slot_type への置換. / Replace to inventory_slot_type.
[hengband/hengband.git] / src / view / display-player-stat-info.c
1 /*!
2  * @brief プレーヤーの耐性と能力値を表示する
3  * @date 2020/02/27
4  * @author Hourier
5  * @details
6  * ここにこれ以上関数を引っ越してくるのは禁止。何ならここから更に分割していく
7  */
8
9 #include "display-player-stat-info.h"
10 #include "inventory/inventory-slot-types.h"
11 #include "mutation/mutation-flag-types.h"
12 #include "object-enchant/tr-types.h"
13 #include "object/object-flags.h"
14 #include "player/mimic-info-table.h"
15 #include "player/permanent-resistances.h"
16 #include "player/player-class.h"
17 #include "player/player-personality.h"
18 #include "player/player-race-types.h"
19 #include "term/screen-processor.h"
20 #include "term/term-color-types.h"
21 #include "util/bit-flags-calculator.h"
22
23 /*!
24  * @brief プレーヤーのパラメータ基礎値 (腕力等)を18以下になるようにして返す
25  * @param creature_ptr プレーヤーへの参照ポインタ
26  * @param stat_num 能力値番号
27  * @return 基礎値
28  * @details 最大が18になるのはD&D由来
29  */
30 static int calc_basic_stat(player_type *creature_ptr, int stat_num)
31 {
32         int e_adj = 0;
33         if ((creature_ptr->stat_max[stat_num] > 18) && (creature_ptr->stat_top[stat_num] > 18))
34                 e_adj = (creature_ptr->stat_top[stat_num] - creature_ptr->stat_max[stat_num]) / 10;
35
36         if ((creature_ptr->stat_max[stat_num] <= 18) && (creature_ptr->stat_top[stat_num] <= 18))
37                 e_adj = creature_ptr->stat_top[stat_num] - creature_ptr->stat_max[stat_num];
38
39         if ((creature_ptr->stat_max[stat_num] <= 18) && (creature_ptr->stat_top[stat_num] > 18))
40                 e_adj = (creature_ptr->stat_top[stat_num] - 18) / 10 - creature_ptr->stat_max[stat_num] + 18;
41
42         if ((creature_ptr->stat_max[stat_num] > 18) && (creature_ptr->stat_top[stat_num] <= 18))
43                 e_adj = creature_ptr->stat_top[stat_num] - (creature_ptr->stat_max[stat_num] - 19) / 10 - 19;
44
45         return e_adj;
46 }
47
48
49 /*!
50  * @brief 特殊な種族の時、腕力等の基礎パラメータを変動させる
51  * @param creature_ptr プレーヤーへの参照ポインタ
52  * @param stat_num 能力値番号
53  * @return 補正後の基礎パラメータ
54  */
55 static int compensate_special_race(player_type *creature_ptr, int stat_num)
56 {
57         if (!is_specific_player_race(creature_ptr, RACE_ENT)) return 0;
58
59         int r_adj = 0;
60         switch (stat_num)
61         {
62         case A_STR:
63         case A_CON:
64                 if (creature_ptr->lev > 25) r_adj++;
65                 if (creature_ptr->lev > 40) r_adj++;
66                 if (creature_ptr->lev > 45) r_adj++;
67                 break;
68         case A_DEX:
69                 if (creature_ptr->lev > 25) r_adj--;
70                 if (creature_ptr->lev > 40) r_adj--;
71                 if (creature_ptr->lev > 45) r_adj--;
72                 break;
73         }
74
75         return r_adj;
76 }
77
78
79 /*!
80  * @brief 能力値名を(もし一時的減少なら'x'を付けて)表示する
81  * @param creature_ptr プレーヤーへの参照ポインタ
82  * @param stat_num 能力値番号
83  * @param row 行数
84  * @param stat_col 列数
85  * @return なし
86  */
87 static void display_basic_stat_name(player_type *creature_ptr, int stat_num, int row, int stat_col)
88 {
89         if (creature_ptr->stat_cur[stat_num] < creature_ptr->stat_max[stat_num])
90                 c_put_str(TERM_WHITE, stat_names_reduced[stat_num], row + stat_num + 1, stat_col + 1);
91         else
92                 c_put_str(TERM_WHITE, stat_names[stat_num], row + stat_num + 1, stat_col + 1);
93 }
94
95
96 /*!
97  * @brief 能力値を、基本・種族補正・職業補正・性格補正・装備補正・合計・現在 (一時的減少のみ) の順で表示する
98  * @param creature_ptr プレーヤーへの参照ポインタ
99  * @param stat_num 能力値番号
100  * @param r_adj 補正後の基礎パラメータ
101  * @param e_adj 種族補正値
102  * @param row 行数
103  * @param stat_col 列数
104  * @param buf 能力値の数値
105  * @return なし
106  */
107 static void display_basic_stat_value(player_type *creature_ptr, int stat_num, int r_adj, int e_adj, int row, int stat_col, char *buf)
108 {
109         (void)sprintf(buf, "%3d", r_adj);
110         c_put_str(TERM_L_BLUE, buf, row + stat_num + 1, stat_col + 13);
111
112         (void)sprintf(buf, "%3d", (int)cp_ptr->c_adj[stat_num]);
113         c_put_str(TERM_L_BLUE, buf, row + stat_num + 1, stat_col + 16);
114
115         (void)sprintf(buf, "%3d", (int)ap_ptr->a_adj[stat_num]);
116         c_put_str(TERM_L_BLUE, buf, row + stat_num + 1, stat_col + 19);
117
118         (void)sprintf(buf, "%3d", (int)e_adj);
119         c_put_str(TERM_L_BLUE, buf, row + stat_num + 1, stat_col + 22);
120
121         cnv_stat(creature_ptr->stat_top[stat_num], buf);
122         c_put_str(TERM_L_GREEN, buf, row + stat_num + 1, stat_col + 26);
123
124         if (creature_ptr->stat_use[stat_num] < creature_ptr->stat_top[stat_num])
125         {
126                 cnv_stat(creature_ptr->stat_use[stat_num], buf);
127                 c_put_str(TERM_YELLOW, buf, row + stat_num + 1, stat_col + 33);
128         }
129 }
130
131
132 /*!
133  * @brief 能力値を補正しつつ表示する
134  * @param creature_ptr プレーヤーへの参照ポインタ
135  * @param row 行数
136  * @param stat_col 列数
137  * @return なし
138  */
139 static void process_stats(player_type *creature_ptr, int row, int stat_col)
140 {
141         char buf[80];
142         for (int i = 0; i < A_MAX; i++)
143         {
144                 int r_adj = creature_ptr->mimic_form
145                         ? mimic_info[creature_ptr->mimic_form].r_adj[i]
146                         : rp_ptr->r_adj[i];
147                 int e_adj = calc_basic_stat(creature_ptr, i);
148                 r_adj += compensate_special_race(creature_ptr, i);
149                 e_adj -= r_adj;
150                 e_adj -= cp_ptr->c_adj[i];
151                 e_adj -= ap_ptr->a_adj[i];
152
153                 display_basic_stat_name(creature_ptr, i, row, stat_col);
154                 cnv_stat(creature_ptr->stat_max[i], buf);
155                 if (creature_ptr->stat_max[i] == creature_ptr->stat_max_max[i])
156                         c_put_str(TERM_WHITE, "!", row + i + 1, _(stat_col + 6, stat_col + 4));
157
158                 c_put_str(TERM_BLUE, buf, row + i + 1, stat_col + 13 - strlen(buf));
159
160                 display_basic_stat_value(creature_ptr, i, r_adj, e_adj, row, stat_col, buf);
161         }
162 }
163
164
165 /*!
166  * @brief pval付きの装備に依るステータス補正を表示する
167  * @param c 補正後の表示記号
168  * @param a 表示色
169  * @param o_ptr 装備品への参照ポインタ
170  * @param stat 能力値番号
171  * @param flags 装備品に立っているフラグ
172  * @return なし
173  */
174 static void compensate_stat_by_weapon(char *c, TERM_COLOR *a, object_type *o_ptr, int stat, BIT_FLAGS *flags)
175 {
176         *c = '*';
177
178         if (o_ptr->pval > 0)
179         {
180                 *a = TERM_L_GREEN;
181                 if (o_ptr->pval < 10) *c = '0' + o_ptr->pval;
182         }
183
184         if (have_flag(flags, stat + TR_SUST_STR))
185         {
186                 *a = TERM_GREEN;
187         }
188
189         if (o_ptr->pval < 0)
190         {
191                 *a = TERM_RED;
192                 if (o_ptr->pval > -10) *c = '0' - o_ptr->pval;
193         }
194 }
195
196
197 /*!
198  * @brief 装備品を走査してpval付きのものをそれと分かるように表示する
199  * @param creature_ptr プレーヤーへの参照ポインタ
200  * @param flags 装備品に立っているフラグ
201  * @param row 行数
202  * @param col 列数
203  * @return なし
204  */
205 static void display_equipments_compensation(player_type *creature_ptr, BIT_FLAGS *flags, int row, int *col)
206 {
207         for (inventory_slot_type i = INVEN_RARM; i < INVEN_TOTAL; i++)
208         {
209                 object_type *o_ptr;
210                 o_ptr = &creature_ptr->inventory_list[i];
211                 object_flags_known(creature_ptr, o_ptr, flags);
212                 for (int stat = 0; stat < A_MAX; stat++)
213                 {
214                         TERM_COLOR a = TERM_SLATE;
215                         char c = '.';
216                         if (have_flag(flags, stat))
217                         {
218                                 compensate_stat_by_weapon(&c, &a, o_ptr, stat, flags);
219                         }
220                         else if (have_flag(flags, stat + TR_SUST_STR))
221                         {
222                                 a = TERM_GREEN;
223                                 c = 's';
224                         }
225
226                         term_putch(*col, row + stat + 1, a, c);
227                 }
228
229                 (*col)++;
230         }
231 }
232
233
234 /*!
235  * @brief 各能力値の補正
236  * @param creature_ptr プレーヤーへの参照ポインタ
237  * @param stat 能力値番号
238  * @return なし
239  */
240 static int compensation_stat_by_mutation(player_type *creature_ptr, int stat)
241 {
242         int compensation = 0;
243         if (stat == A_STR)
244         {
245                 if (creature_ptr->muta3 & MUT3_HYPER_STR) compensation += 4;
246                 if (creature_ptr->muta3 & MUT3_PUNY) compensation -= 4;
247                 if (creature_ptr->tsuyoshi) compensation += 4;
248                 return compensation;
249         }
250         
251         if (stat == A_WIS || stat == A_INT)
252         {
253                 if (creature_ptr->muta3 & MUT3_HYPER_INT) compensation += 4;
254                 if (creature_ptr->muta3 & MUT3_MORONIC) compensation -= 4;
255                 return compensation;
256         }
257         
258         if (stat == A_DEX)
259         {
260                 if (creature_ptr->muta3 & MUT3_IRON_SKIN) compensation -= 1;
261                 if (creature_ptr->muta3 & MUT3_LIMBER) compensation += 3;
262                 if (creature_ptr->muta3 & MUT3_ARTHRITIS) compensation -= 3;
263                 return compensation;
264         }
265         
266         if (stat == A_CON)
267         {
268                 if (creature_ptr->muta3 & MUT3_RESILIENT) compensation += 4;
269                 if (creature_ptr->muta3 & MUT3_XTRA_FAT) compensation += 2;
270                 if (creature_ptr->muta3 & MUT3_ALBINO) compensation -= 4;
271                 if (creature_ptr->muta3 & MUT3_FLESH_ROT) compensation -= 2;
272                 if (creature_ptr->tsuyoshi) compensation += 4;
273                 return compensation;
274         }
275         
276         if (stat == A_CHR)
277         {
278                 if (creature_ptr->muta3 & MUT3_SILLY_VOI) compensation -= 4;
279                 if (creature_ptr->muta3 & MUT3_BLANK_FAC) compensation -= 1;
280                 if (creature_ptr->muta3 & MUT3_FLESH_ROT) compensation -= 1;
281                 if (creature_ptr->muta3 & MUT3_SCALES) compensation -= 1;
282                 if (creature_ptr->muta3 & MUT3_WART_SKIN) compensation -= 2;
283                 if (creature_ptr->muta3 & MUT3_ILL_NORM) compensation = 0;
284                 return compensation;
285         }
286
287         return 0;
288 }
289
290
291 /*!
292  * @brief 突然変異 (と、つよしスペシャル)による能力値の補正有無で表示する記号を変える
293  * @param creature_ptr プレーヤーへの参照ポインタ
294  * @param stat 能力値番号
295  * @param c 補正後の表示記号
296  * @param a 表示色
297  * @return なし
298  */
299 static void change_display_by_mutation(player_type *creature_ptr, int stat, char *c, TERM_COLOR *a)
300 {
301         if ((creature_ptr->muta3 != 0) && !creature_ptr->tsuyoshi) return;
302
303         int compensation = compensation_stat_by_mutation(creature_ptr, stat);
304         if (compensation == 0) return;
305
306         *c = '*';
307         if (compensation > 0)
308         {
309                 *a = TERM_L_GREEN;
310                 if (compensation < 10) *c = '0' + compensation;
311         }
312
313         if (compensation < 0)
314         {
315                 *a = TERM_RED;
316                 if (compensation > -10) *c = '0' - compensation;
317         }
318 }
319
320
321 /*!
322  * @brief 能力値を走査し、突然変異 (と、つよしスペシャル)で補正をかける必要があればかける
323  * @param creature_ptr プレーヤーへの参照ポインタ
324  * @param stat 能力値番号
325  * @param col 列数
326  * @param row 行数
327  * @return なし
328  */
329 static void display_mutation_compensation(player_type *creature_ptr, BIT_FLAGS *flags, int row, int col)
330 {
331         for (int stat = 0; stat < A_MAX; stat++)
332         {
333                 byte a = TERM_SLATE;
334                 char c = '.';
335                 change_display_by_mutation(creature_ptr, stat, &c, &a);
336
337                 if (have_flag(flags, stat + TR_SUST_STR))
338                 {
339                         a = TERM_GREEN;
340                         c = 's';
341                 }
342
343                 term_putch(col, row + stat + 1, a, c);
344         }
345 }
346
347
348 /*!
349  * @brief プレイヤーの特性フラグ一覧表示2b /
350  * Special display, part 2b
351  * @param creature_ptr プレーヤーへの参照ポインタ
352  * @return なし
353  * @details
354  * <pre>
355  * How to print out the modifications and sustains.
356  * Positive mods with no sustain will be light green.
357  * Positive mods with a sustain will be dark green.
358  * Sustains (with no modification) will be a dark green 's'.
359  * Negative mods (from a curse) will be red.
360  * Huge mods (>9), like from MICoMorgoth, will be a '*'
361  * No mod, no sustain, will be a slate '.'
362  * </pre>
363  */
364 void display_player_stat_info(player_type *creature_ptr)
365 {
366         int stat_col = 22;
367         int row = 3;
368         c_put_str(TERM_WHITE, _("能力", "Stat"), row, stat_col + 1);
369         c_put_str(TERM_BLUE, _("  基本", "  Base"), row, stat_col + 7);
370         c_put_str(TERM_L_BLUE, _(" 種 職 性 装 ", "RacClaPerMod"), row, stat_col + 13);
371         c_put_str(TERM_L_GREEN, _("合計", "Actual"), row, stat_col + 28);
372         c_put_str(TERM_YELLOW, _("現在", "Current"), row, stat_col + 35);
373         process_stats(creature_ptr, row, stat_col);
374
375         int col = stat_col + 41;
376         c_put_str(TERM_WHITE, "abcdefghijkl@", row, col);
377         c_put_str(TERM_L_GREEN, _("能力修正", "Modification"), row - 1, col);
378
379         BIT_FLAGS flags[TR_FLAG_SIZE];
380         display_equipments_compensation(creature_ptr,flags, row, &col);
381         player_flags(creature_ptr, flags);
382         display_mutation_compensation(creature_ptr, flags, row, col);
383 }