OSDN Git Service

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