OSDN Git Service

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