OSDN Git Service

Reworded English description of the sniper's SP_PIERCE ability.
[hengband/hengband.git] / src / wizard / items-spoiler.c
1 #include "wizard/items-spoiler.h"
2 #include "flavor/flavor-describer.h"
3 #include "flavor/object-flavor-types.h"
4 #include "io/files-util.h"
5 #include "object-enchant/special-object-flags.h"
6 #include "object-enchant/trg-types.h"
7 #include "object/object-generator.h"
8 #include "object/object-kind.h"
9 #include "object/object-value.h"
10 #include "system/angband-version.h"
11 #include "system/object-type-definition.h"
12 #include "util/angband-files.h"
13 #include "view/display-messages.h"
14 #include "wizard/spoiler-util.h"
15
16 /*!
17  * @brief ベースアイテムの各情報を文字列化する /
18  * Describe the kind
19  * @param player_ptr プレーヤーへの参照ポインタ
20  * @param buf 名称を返すバッファ参照ポインタ
21  * @param dam ダメージダイス記述を返すバッファ参照ポインタ
22  * @param wgt 重量記述を返すバッファ参照ポインタ
23  * @param lev 生成階記述を返すバッファ参照ポインタ
24  * @param chance 生成機会を返すバッファ参照ポインタ
25  * @param val 価値を返すバッファ参照ポインタ
26  * @param k ベースアイテムID
27  * @return なし
28  */
29 static void kind_info(player_type *player_ptr, char *buf, char *dam, char *wgt, char *chance, DEPTH *lev, PRICE *val, OBJECT_IDX k)
30 {
31     object_type forge;
32     object_type *q_ptr = &forge;
33     object_prep(player_ptr, q_ptr, k);
34     q_ptr->ident |= IDENT_KNOWN;
35     q_ptr->pval = 0;
36     q_ptr->to_a = 0;
37     q_ptr->to_h = 0;
38     q_ptr->to_d = 0;
39     *lev = k_info[q_ptr->k_idx].level;
40     *val = object_value(player_ptr, q_ptr);
41     if (!buf || !dam || !chance || !wgt)
42         return;
43
44     describe_flavor(player_ptr, buf, q_ptr, OD_NAME_ONLY | OD_STORE);
45     strcpy(dam, "");
46     switch (q_ptr->tval) {
47     case TV_SHOT:
48     case TV_BOLT:
49     case TV_ARROW:
50         sprintf(dam, "%dd%d", q_ptr->dd, q_ptr->ds);
51         break;
52     case TV_HAFTED:
53     case TV_POLEARM:
54     case TV_SWORD:
55     case TV_DIGGING:
56         sprintf(dam, "%dd%d", q_ptr->dd, q_ptr->ds);
57         break;
58     case TV_BOOTS:
59     case TV_GLOVES:
60     case TV_CLOAK:
61     case TV_CROWN:
62     case TV_HELM:
63     case TV_SHIELD:
64     case TV_SOFT_ARMOR:
65     case TV_HARD_ARMOR:
66     case TV_DRAG_ARMOR:
67         sprintf(dam, "%d", q_ptr->ac);
68         break;
69     default:
70         break;
71     }
72
73     strcpy(chance, "");
74     for (int i = 0; i < 4; i++) {
75         char chance_aux[20] = "";
76         if (k_info[q_ptr->k_idx].chance[i] > 0) {
77             sprintf(chance_aux, "%s%3dF:%+4d", (i != 0 ? "/" : ""), (int)k_info[q_ptr->k_idx].locale[i], 100 / k_info[q_ptr->k_idx].chance[i]);
78             strcat(chance, chance_aux);
79         }
80     }
81
82     sprintf(wgt, "%3d.%d", (int)(q_ptr->weight / 10), (int)(q_ptr->weight % 10));
83 }
84
85 /*!
86  * @brief 各ベースアイテムの情報を一行毎に記述する /
87  * @param player_ptr プレーヤーへの参照ポインタ
88  * Create a spoiler file for items
89  * @param fname ファイル名
90  * @return なし
91  */
92 void spoil_obj_desc(player_type *player_ptr, concptr fname)
93 {
94     char buf[1024];
95     path_build(buf, sizeof(buf), ANGBAND_DIR_USER, fname);
96     spoiler_file = angband_fopen(buf, "w");
97     if (!spoiler_file) {
98         msg_print("Cannot create spoiler file.");
99         return;
100     }
101
102     char title[200];
103     put_version(title);
104     fprintf(spoiler_file, "Spoiler File -- Basic Items (%s)\n\n\n", title);
105     fprintf(spoiler_file, "%-37s%8s%7s%5s %40s%9s\n", "Description", "Dam/AC", "Wgt", "Lev", "Chance", "Cost");
106     fprintf(spoiler_file, "%-37s%8s%7s%5s %40s%9s\n", "-------------------------------------", "------", "---", "---", "----------------", "----");
107     int n = 0;
108     int group_start = 0;
109     for (int i = 0; TRUE; i++) {
110         OBJECT_IDX who[200];
111         if (group_item[i].name) {
112             if (n) {
113                 for (int s = 0; s < n - 1; s++) {
114                     for (int t = 0; t < n - 1; t++) {
115                         int i1 = t;
116                         int i2 = t + 1;
117
118                         DEPTH e1;
119                         DEPTH e2;
120
121                         PRICE t1;
122                         PRICE t2;
123
124                         kind_info(player_ptr, NULL, NULL, NULL, NULL, &e1, &t1, who[i1]);
125                         kind_info(player_ptr, NULL, NULL, NULL, NULL, &e2, &t2, who[i2]);
126
127                         if ((t1 > t2) || ((t1 == t2) && (e1 > e2))) {
128                             u16b tmp = who[i1];
129                             who[i1] = who[i2];
130                             who[i2] = tmp;
131                         }
132                     }
133                 }
134
135                 fprintf(spoiler_file, "\n\n%s\n\n", group_item[group_start].name);
136                 for (int s = 0; s < n; s++) {
137                     DEPTH e;
138                     PRICE v;
139                     char wgt[80];
140                     char chance[80];
141                     char dam[80];
142                     kind_info(player_ptr, buf, dam, wgt, chance, &e, &v, who[s]);
143                     fprintf(spoiler_file, "  %-35s%8s%7s%5d %-40s%9ld\n", buf, dam, wgt, (int)e, chance, (long)(v));
144                 }
145
146                 n = 0;
147             }
148
149             if (!group_item[i].tval)
150                 break;
151
152             group_start = i;
153         }
154
155         for (int k = 1; k < max_k_idx; k++) {
156             object_kind *k_ptr = &k_info[k];
157             if ((k_ptr->tval != group_item[i].tval) || (k_ptr->gen_flags & TRG_INSTA_ART))
158                 continue;
159
160             who[n++] = (u16b)k;
161         }
162     }
163
164     if (ferror(spoiler_file) || angband_fclose(spoiler_file)) {
165         msg_print("Cannot close spoiler file.");
166         return;
167     }
168
169     msg_print("Successfully created a spoiler file.");
170 }