OSDN Git Service

[Refactor] #39962 status-first-page.c の整形 / Reshaped status-first-page.c
[hengband/hengband.git] / src / view / status-first-page.c
1 /*!
2  * @file status-first-page.c
3  * @brief \83L\83\83\83\89\8aî\96{\8fî\95ñ\8by\82Ñ\8bZ\94\\92l\82Ì\95\\8e¦
4  * @date 2020/02/23
5  * @author Hourier
6  */
7
8 #include "angband.h"
9 #include "status-first-page.h"
10 #include "artifact.h"
11 #include "combat/melee.h"
12 #include "combat/shoot.h"
13 #include "object-hook.h"
14 #include "objectkind.h"
15
16 static TERM_COLOR likert_color = TERM_WHITE;
17
18 /*!
19  * @brief \8bZ\94\\83\89\83\93\83N\82Ì\95\\8e¦\8aî\8f\80\82ð\92è\82ß\82é
20  * Returns a "rating" of x depending on y
21  * @param x \8bZ\94\\92l
22  * @param y \8bZ\94\\92l\82É\91Î\82·\82é\83\89\83\93\83N\8aî\8f\80\94ä
23  * @return \82È\82µ
24  */
25 static concptr likert(int x, int y)
26 {
27         static char dummy[20] = "", dummy2[20] = "";
28         memset(dummy, 0, strlen(dummy));
29         memset(dummy2, 0, strlen(dummy2));
30         if (y <= 0) y = 1;
31
32         if (show_actual_value)
33                 sprintf(dummy, "%3d-", x);
34
35         if (x < 0)
36         {
37                 likert_color = TERM_L_DARK;
38                 strcat(dummy, _("\8dÅ\92á", "Very Bad"));
39                 return dummy;
40         }
41
42         switch ((x / y))
43         {
44         case 0:
45         case 1:
46         {
47                 likert_color = TERM_RED;
48                 strcat(dummy, _("\88«\82¢", "Bad"));
49                 break;
50
51         }
52         case 2:
53         {
54                 likert_color = TERM_L_RED;
55                 strcat(dummy, _("\97ò\82é", "Poor"));
56                 break;
57         }
58         case 3:
59         case 4:
60         {
61                 likert_color = TERM_ORANGE;
62                 strcat(dummy, _("\95\81\92Ê", "Fair"));
63                 break;
64         }
65         case 5:
66         {
67                 likert_color = TERM_YELLOW;
68                 strcat(dummy, _("\97Ç\82¢", "Good"));
69                 break;
70         }
71         case 6:
72         {
73                 likert_color = TERM_YELLOW;
74                 strcat(dummy, _("\91å\95Ï\97Ç\82¢", "Very Good"));
75                 break;
76         }
77         case 7:
78         case 8:
79         {
80                 likert_color = TERM_L_GREEN;
81                 strcat(dummy, _("\91ì\89z", "Excellent"));
82                 break;
83         }
84         case 9:
85         case 10:
86         case 11:
87         case 12:
88         case 13:
89         {
90                 likert_color = TERM_GREEN;
91                 strcat(dummy, _("\92´\89z", "Superb"));
92                 break;
93         }
94         case 14:
95         case 15:
96         case 16:
97         case 17:
98         {
99                 likert_color = TERM_BLUE;
100                 strcat(dummy, _("\89p\97Y\93I", "Heroic"));
101                 break;
102         }
103         default:
104         {
105                 likert_color = TERM_VIOLET;
106                 sprintf(dummy2, _("\93`\90à\93I[%d]", "Legendary[%d]"), (int)((((x / y) - 17) * 5) / 2));
107                 strcat(dummy, dummy2);
108                 break;
109         }
110         }
111
112         return dummy;
113 }
114
115
116 /*!
117  * @brief \83v\83\8c\83C\83\84\81[\83X\83e\81[\83^\83X\82Ì1\83y\81[\83W\96Ú\8ae\8eí\8fÚ\8d×\82ð\82Ü\82Æ\82ß\82Ä\95\\8e¦\82·\82é
118  * Prints ratings on certain abilities
119  * @param creature_ptr \83v\83\8c\81[\83\84\81[\82Ö\82Ì\8eQ\8fÆ\83|\83C\83\93\83^
120  * @return \82È\82µ
121  * @details
122  * This code is "imitated" elsewhere to "dump" a character sheet.
123  */
124 void display_player_various(player_type *creature_ptr, void(*display_player_one_line)(int, concptr, TERM_COLOR))
125 {
126         int muta_att = 0;
127         if (creature_ptr->muta2 & MUT2_HORNS)     muta_att++;
128         if (creature_ptr->muta2 & MUT2_SCOR_TAIL) muta_att++;
129         if (creature_ptr->muta2 & MUT2_BEAK)      muta_att++;
130         if (creature_ptr->muta2 & MUT2_TRUNK)     muta_att++;
131         if (creature_ptr->muta2 & MUT2_TENTACLES) muta_att++;
132
133         int xthn = creature_ptr->skill_thn + (creature_ptr->to_h_m * BTH_PLUS_ADJ);
134
135         object_type *o_ptr;
136         o_ptr = &creature_ptr->inventory_list[INVEN_BOW];
137         int tmp = creature_ptr->to_h_b + o_ptr->to_h;
138         int     xthb = creature_ptr->skill_thb + (tmp * BTH_PLUS_ADJ);
139         int     shots = 0;
140         int shot_frac = 0;
141         if (o_ptr->k_idx > 0)
142         {
143                 ENERGY energy_fire = bow_energy(o_ptr->sval);
144                 shots = creature_ptr->num_fire * 100;
145                 shot_frac = (shots * 100 / energy_fire) % 100;
146                 shots = shots / energy_fire;
147                 if (o_ptr->name1 == ART_CRIMSON)
148                 {
149                         shots = 1;
150                         shot_frac = 0;
151                         if (creature_ptr->pclass == CLASS_ARCHER)
152                         {
153                                 if (creature_ptr->lev >= 10) shots++;
154                                 if (creature_ptr->lev >= 30) shots++;
155                                 if (creature_ptr->lev >= 45) shots++;
156                         }
157                 }
158         }
159
160         int damage[2];
161         int to_h[2];
162         int basedam;
163         BIT_FLAGS flgs[TR_FLAG_SIZE];
164         for (int i = 0; i < 2; i++)
165         {
166                 damage[i] = creature_ptr->dis_to_d[i] * 100;
167                 if (((creature_ptr->pclass == CLASS_MONK) || (creature_ptr->pclass == CLASS_FORCETRAINER)) && (empty_hands(creature_ptr, TRUE) & EMPTY_HAND_RARM))
168                 {
169                         PLAYER_LEVEL level = creature_ptr->lev;
170                         if (i > 0)
171                         {
172                                 damage[i] = 0;
173                                 break;
174                         }
175
176                         if (creature_ptr->pclass == CLASS_FORCETRAINER) level = MAX(1, level - 3);
177                         if (creature_ptr->special_defense & KAMAE_BYAKKO)
178                                 basedam = monk_ave_damage[level][1];
179                         else if (creature_ptr->special_defense & (KAMAE_GENBU | KAMAE_SUZAKU))
180                                 basedam = monk_ave_damage[level][2];
181                         else
182                                 basedam = monk_ave_damage[level][0];
183
184                         damage[i] += basedam;
185                         if ((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_POISON_NEEDLE)) damage[i] = 1;
186                         if (damage[i] < 0) damage[i] = 0;
187                         continue;
188                 }
189
190                 o_ptr = &creature_ptr->inventory_list[INVEN_RARM + i];
191                 if (o_ptr->k_idx == 0)
192                 {
193                         basedam = 0;
194                         damage[i] += basedam;
195                         if ((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_POISON_NEEDLE)) damage[i] = 1;
196                         if (damage[i] < 0) damage[i] = 0;
197                         continue;
198                 }
199
200                 to_h[i] = 0;
201                 bool poison_needle = FALSE;
202                 if ((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_POISON_NEEDLE)) poison_needle = TRUE;
203                 if (object_is_known(o_ptr))
204                 {
205                         damage[i] += o_ptr->to_d * 100;
206                         to_h[i] += o_ptr->to_h;
207                 }
208
209                 basedam = ((o_ptr->dd + creature_ptr->to_dd[i]) * (o_ptr->ds + creature_ptr->to_ds[i] + 1)) * 50;
210                 object_flags_known(o_ptr, flgs);
211                 basedam = calc_expect_crit(creature_ptr, o_ptr->weight, to_h[i], basedam, creature_ptr->dis_to_h[i], poison_needle);
212                 if (OBJECT_IS_FULL_KNOWN(o_ptr) && ((o_ptr->name1 == ART_VORPAL_BLADE) || (o_ptr->name1 == ART_CHAINSWORD)))
213                 {
214                         /* vorpal blade */
215                         basedam *= 5;
216                         basedam /= 3;
217                 }
218                 else if (have_flag(flgs, TR_VORPAL))
219                 {
220                         /* vorpal flag only */
221                         basedam *= 11;
222                         basedam /= 9;
223                 }
224
225                 if ((creature_ptr->pclass != CLASS_SAMURAI) && have_flag(flgs, TR_FORCE_WEAPON) && (creature_ptr->csp > (o_ptr->dd * o_ptr->ds / 5)))
226                         basedam = basedam * 7 / 2;
227                 damage[i] += basedam;
228                 if ((o_ptr->tval == TV_SWORD) && (o_ptr->sval == SV_POISON_NEEDLE)) damage[i] = 1;
229                 if (damage[i] < 0) damage[i] = 0;
230         }
231
232         int blows1 = creature_ptr->migite ? creature_ptr->num_blow[0] : 0;
233         int blows2 = creature_ptr->hidarite ? creature_ptr->num_blow[1] : 0;
234         int xdis = creature_ptr->skill_dis;
235         int xdev = creature_ptr->skill_dev;
236         int xsav = creature_ptr->skill_sav;
237         int xstl = creature_ptr->skill_stl;
238         int     xsrh = creature_ptr->skill_srh;
239         int     xfos = creature_ptr->skill_fos;
240         int xdig = creature_ptr->skill_dig;
241
242         concptr desc = likert(xthn, 12);
243         (*display_player_one_line)(ENTRY_SKILL_FIGHT, desc, likert_color);
244
245         desc = likert(xthb, 12);
246         (*display_player_one_line)(ENTRY_SKILL_SHOOT, desc, likert_color);
247
248         desc = likert(xsav, 7);
249         (*display_player_one_line)(ENTRY_SKILL_SAVING, desc, likert_color);
250
251         desc = likert((xstl > 0) ? xstl : -1, 1);
252         (*display_player_one_line)(ENTRY_SKILL_STEALTH, desc, likert_color);
253
254         desc = likert(xfos, 6);
255         (*display_player_one_line)(ENTRY_SKILL_PERCEP, desc, likert_color);
256
257         desc = likert(xsrh, 6);
258         (*display_player_one_line)(ENTRY_SKILL_SEARCH, desc, likert_color);
259
260         desc = likert(xdis, 8);
261         (*display_player_one_line)(ENTRY_SKILL_DISARM, desc, likert_color);
262
263         desc = likert(xdev, 6);
264         (*display_player_one_line)(ENTRY_SKILL_DEVICE, desc, likert_color);
265
266         desc = likert(xdev, 6);
267         (*display_player_one_line)(ENTRY_SKILL_DEVICE, desc, likert_color);
268
269         desc = likert(xdig, 4);
270         (*display_player_one_line)(ENTRY_SKILL_DIG, desc, likert_color);
271
272         if (!muta_att)
273                 (*display_player_one_line)(ENTRY_BLOWS, format("%d+%d", blows1, blows2), TERM_L_BLUE);
274         else
275                 (*display_player_one_line)(ENTRY_BLOWS, format("%d+%d+%d", blows1, blows2, muta_att), TERM_L_BLUE);
276
277         (*display_player_one_line)(ENTRY_SHOTS, format("%d.%02d", shots, shot_frac), TERM_L_BLUE);
278
279         if ((damage[0] + damage[1]) == 0)
280                 desc = "nil!";
281         else
282                 desc = format("%d+%d", blows1 * damage[0] / 100, blows2 * damage[1] / 100);
283
284         (*display_player_one_line)(ENTRY_AVG_DMG, desc, TERM_L_BLUE);
285
286         (*display_player_one_line)(ENTRY_INFRA, format("%d feet", creature_ptr->see_infra * 10), TERM_WHITE);
287 }