1 #include "wizard/wizard-item-modifier.h"
2 #include "artifact/random-art-generator.h"
3 #include "core/asking-player.h"
4 #include "core/player-update-types.h"
5 #include "core/window-redrawer.h"
6 #include "flavor/flavor-describer.h"
7 #include "flavor/object-flavor-types.h"
8 #include "floor/floor-object.h"
9 #include "io/input-key-acceptor.h"
10 #include "object-enchant/apply-magic.h"
11 #include "object-enchant/item-apply-magic.h"
12 #include "object-hook/hook-enchant.h"
13 #include "object/item-use-flags.h"
14 #include "object/object-flags.h"
15 #include "object/object-generator.h"
16 #include "object/object-kind.h"
17 #include "object/object-value.h"
18 #include "system/alloc-entries.h"
19 #include "system/artifact-type-definition.h"
20 #include "system/floor-type-definition.h"
21 #include "system/object-type-definition.h"
22 #include "term/screen-processor.h"
23 #include "term/term-color-types.h"
24 #include "view/display-messages.h"
26 #define K_MAX_DEPTH 110 /*!< アイテムの階層毎生成率を表示する最大階 */
29 * @brief アイテムの階層毎生成率を表示する / Output a rarity graph for a type of object.
30 * @param tval ベースアイテムの大項目ID
31 * @param sval ベースアイテムの小項目ID
36 static void prt_alloc(tval_type tval, OBJECT_SUBTYPE_VALUE sval, TERM_LEN row, TERM_LEN col)
38 u32b rarity[K_MAX_DEPTH];
39 (void)C_WIPE(rarity, K_MAX_DEPTH, u32b);
40 u32b total[K_MAX_DEPTH];
41 (void)C_WIPE(total, K_MAX_DEPTH, u32b);
43 (void)C_WIPE(display, 22, s32b);
46 for (int i = 0; i < K_MAX_DEPTH; i++) {
49 alloc_entry *table = alloc_kind_table;
50 for (int j = 0; j < alloc_kind_size; j++) {
53 if (table[j].level <= i) {
54 prob = table[j].prob1 * GREAT_OBJ * K_MAX_DEPTH;
55 } else if (table[j].level - 1 > 0) {
56 prob = table[j].prob1 * i * K_MAX_DEPTH / (table[j].level - 1);
59 k_ptr = &k_info[table[j].index];
61 total[i] += prob / (GREAT_OBJ * K_MAX_DEPTH);
62 total_frac += prob % (GREAT_OBJ * K_MAX_DEPTH);
64 if ((k_ptr->tval == tval) && (k_ptr->sval == sval)) {
66 rarity[i] += prob / (GREAT_OBJ * K_MAX_DEPTH);
70 total[i] += total_frac / (GREAT_OBJ * K_MAX_DEPTH);
73 for (int i = 0; i < 22; i++) {
75 for (int j = i * K_MAX_DEPTH / 22; j < (i + 1) * K_MAX_DEPTH / 22; j++)
76 possibility += rarity[j] * 100000 / total[j];
78 display[i] = possibility / 5;
81 for (int i = 0; i < 22; i++) {
82 term_putch(col, row + i + 1, TERM_WHITE, '|');
83 prt(format("%2dF", (i * 5)), row + i + 1, col);
84 if ((i * K_MAX_DEPTH / 22 <= home) && (home < (i + 1) * K_MAX_DEPTH / 22))
85 c_prt(TERM_RED, format("%3d.%04d%%", display[i] / 1000, display[i] % 1000), row + i + 1, col + 3);
87 c_prt(TERM_WHITE, format("%3d.%04d%%", display[i] / 1000, display[i] % 1000), row + i + 1, col + 3);
90 concptr r = "+---Rate---+";
95 * @brief 32ビット変数のビット配列を並べて描画する / Output a long int in binary format.
98 static void prt_binary(BIT_FLAGS flags, const int row, int col)
101 for (int i = bitmask = 1; i <= 32; i++, bitmask *= 2)
103 term_putch(col++, row, TERM_BLUE, '*');
105 term_putch(col++, row, TERM_WHITE, '-');
109 * @brief アイテムの詳細ステータスを表示する /
110 * Change various "permanent" player variables.
111 * @param player_ptr プレーヤーへの参照ポインタ
112 * @param o_ptr 詳細を表示するアイテム情報の参照ポインタ
115 static void wiz_display_item(player_type *player_ptr, object_type *o_ptr)
117 BIT_FLAGS flgs[TR_FLAG_SIZE];
118 object_flags(player_ptr, o_ptr, flgs);
120 for (int i = 1; i <= 23; i++)
123 prt_alloc(o_ptr->tval, o_ptr->sval, 1, 0);
125 describe_flavor(player_ptr, buf, o_ptr, OD_STORE);
127 prt(format("kind = %-5d level = %-4d tval = %-5d sval = %-5d", o_ptr->k_idx, k_info[o_ptr->k_idx].level, o_ptr->tval, o_ptr->sval), 4, j);
128 prt(format("number = %-3d wgt = %-6d ac = %-5d damage = %dd%d", o_ptr->number, o_ptr->weight, o_ptr->ac, o_ptr->dd, o_ptr->ds), 5, j);
129 prt(format("pval = %-5d toac = %-5d tohit = %-4d todam = %-4d", o_ptr->pval, o_ptr->to_a, o_ptr->to_h, o_ptr->to_d), 6, j);
130 prt(format("name1 = %-4d name2 = %-4d cost = %ld", o_ptr->name1, o_ptr->name2, (long)object_value_real(player_ptr, o_ptr)), 7, j);
131 prt(format("ident = %04x xtra1 = %-4d xtra2 = %-4d timeout = %-d", o_ptr->ident, o_ptr->xtra1, o_ptr->xtra2, o_ptr->timeout), 8, j);
132 prt(format("xtra3 = %-4d xtra4 = %-4d xtra5 = %-4d cursed = %-d", o_ptr->xtra3, o_ptr->xtra4, o_ptr->xtra5, o_ptr->curse_flags), 9, j);
134 prt("+------------FLAGS1------------+", 10, j);
135 prt("AFFECT........SLAY........BRAND.", 11, j);
136 prt(" mf cvae xsqpaefc", 12, j);
137 prt("siwdccsossidsahanvudotgddhuoclio", 13, j);
138 prt("tnieohtctrnipttmiinmrrnrrraiierl", 14, j);
139 prt("rtsxnarelcfgdkcpmldncltggpksdced", 15, j);
140 prt_binary(flgs[0], 16, j);
142 prt("+------------FLAGS2------------+", 17, j);
143 prt("SUST....IMMUN.RESIST............", 18, j);
144 prt(" reaefctrpsaefcpfldbc sn ", 19, j);
145 prt("siwdcciaclioheatcliooeialoshtncd", 20, j);
146 prt("tnieohdsierlrfraierliatrnnnrhehi", 21, j);
147 prt("rtsxnaeydcedwlatdcedsrekdfddrxss", 22, j);
148 prt_binary(flgs[1], 23, j);
150 prt("+------------FLAGS3------------+", 10, j + 32);
151 prt("fe cnn t stdrmsiiii d ab ", 11, j + 32);
152 prt("aa aoomywhs lleeieihgggg rtgl ", 12, j + 32);
153 prt("uu utmacaih eielgggonnnnaaere ", 13, j + 32);
154 prt("rr reanurdo vtieeehtrrrrcilas ", 14, j + 32);
155 prt("aa algarnew ienpsntsaefctnevs ", 15, j + 32);
156 prt_binary(flgs[2], 16, j + 32);
158 prt("+------------FLAGS4------------+", 17, j + 32);
159 prt("KILL....ESP......... ", 18, j + 32);
160 prt("aeud tghaud tgdhegnu ", 19, j + 32);
161 prt("nvneoriunneoriruvoon ", 20, j + 32);
162 prt("iidmroamidmroagmionq ", 21, j + 32);
163 prt("mlenclnmmenclnnnldlu ", 22, j + 32);
164 prt_binary(flgs[3], 23, j + 32);
168 * @brief 検査対象のアイテムを基準とした生成テストを行う /
169 * Try to create an item again. Output some statistics. -Bernd-
170 * @param caster_ptr プレーヤーへの参照ポインタ
171 * @param o_ptr 生成テストの基準となるアイテム情報の参照ポインタ
173 * The statistics are correct now. We acquire a clean grid, and then
174 * repeatedly place an object in this grid, copying it into an item
175 * holder, and then deleting the object. We fiddle with the artifact
176 * counter flags to prevent weirdness. We use the items to collect
177 * statistics on item creation relative to the initial item.
179 static void wiz_statistics(player_type *caster_ptr, object_type *o_ptr)
181 concptr q = "Rolls: %ld Correct: %ld Matches: %ld Better: %ld Worse: %ld Other: %ld";
182 concptr p = "Enter number of items to roll: ";
185 if (object_is_fixed_artifact(o_ptr))
186 a_info[o_ptr->name1].cur_num = 0;
188 u32b i, matches, better, worse, other, correct;
189 u32b test_roll = 1000000;
194 concptr pmt = "Roll for [n]ormal, [g]ood, or [e]xcellent treasure? ";
195 wiz_display_item(caster_ptr, o_ptr);
196 if (!get_com(pmt, &ch, FALSE))
199 if (ch == 'n' || ch == 'N') {
202 } else if (ch == 'g' || ch == 'G') {
205 } else if (ch == 'e' || ch == 'E') {
206 mode = AM_GOOD | AM_GREAT;
207 quality = "excellent";
212 sprintf(tmp_val, "%ld", (long int)test_roll);
213 if (get_string(p, tmp_val, 10))
214 test_roll = atol(tmp_val);
215 test_roll = MAX(1, test_roll);
216 msg_format("Creating a lot of %s items. Base level = %d.", quality, caster_ptr->current_floor_ptr->dun_level);
219 correct = matches = better = worse = other = 0;
220 for (i = 0; i <= test_roll; i++) {
221 if ((i < 100) || (i % 100 == 0)) {
225 break; // stop rolling
228 prt(format(q, i, correct, matches, better, worse, other), 0, 0);
229 if (need_term_fresh(caster_ptr))
234 object_type *q_ptr = &forge;
236 make_object(caster_ptr, q_ptr, mode);
237 if (object_is_fixed_artifact(q_ptr))
238 a_info[q_ptr->name1].cur_num = 0;
240 if ((o_ptr->tval != q_ptr->tval) || (o_ptr->sval != q_ptr->sval))
244 if ((q_ptr->pval == o_ptr->pval) && (q_ptr->to_a == o_ptr->to_a) && (q_ptr->to_h == o_ptr->to_h) && (q_ptr->to_d == o_ptr->to_d)
245 && (q_ptr->name1 == o_ptr->name1)) {
247 } else if ((q_ptr->pval >= o_ptr->pval) && (q_ptr->to_a >= o_ptr->to_a) && (q_ptr->to_h >= o_ptr->to_h) && (q_ptr->to_d >= o_ptr->to_d)) {
249 } else if ((q_ptr->pval <= o_ptr->pval) && (q_ptr->to_a <= o_ptr->to_a) && (q_ptr->to_h <= o_ptr->to_h) && (q_ptr->to_d <= o_ptr->to_d)) {
256 msg_format(q, i, correct, matches, better, worse, other);
260 if (object_is_fixed_artifact(o_ptr))
261 a_info[o_ptr->name1].cur_num = 1;
265 * @brief アイテムの質を選択して再生成する /
266 * Apply magic to an item or turn it into an artifact. -Bernd-
267 * @param o_ptr 再生成の対象となるアイテム情報の参照ポインタ
270 static void wiz_reroll_item(player_type *owner_ptr, object_type *o_ptr)
272 if (object_is_artifact(o_ptr))
278 object_copy(q_ptr, o_ptr);
281 bool changed = FALSE;
283 wiz_display_item(owner_ptr, q_ptr);
284 if (!get_com("[a]ccept, [w]orthless, [c]ursed, [n]ormal, [g]ood, [e]xcellent, [s]pecial? ", &ch, FALSE)) {
285 if (object_is_fixed_artifact(q_ptr)) {
286 a_info[q_ptr->name1].cur_num = 0;
294 if (ch == 'A' || ch == 'a') {
299 if (object_is_fixed_artifact(q_ptr)) {
300 a_info[q_ptr->name1].cur_num = 0;
304 switch (tolower(ch)) {
305 /* Apply bad magic, but first clear object */
307 object_prep(owner_ptr, q_ptr, o_ptr->k_idx);
308 apply_magic(owner_ptr, q_ptr, owner_ptr->current_floor_ptr->dun_level, AM_NO_FIXED_ART | AM_GOOD | AM_GREAT | AM_CURSED);
310 /* Apply bad magic, but first clear object */
312 object_prep(owner_ptr, q_ptr, o_ptr->k_idx);
313 apply_magic(owner_ptr, q_ptr, owner_ptr->current_floor_ptr->dun_level, AM_NO_FIXED_ART | AM_GOOD | AM_CURSED);
315 /* Apply normal magic, but first clear object */
317 object_prep(owner_ptr, q_ptr, o_ptr->k_idx);
318 apply_magic(owner_ptr, q_ptr, owner_ptr->current_floor_ptr->dun_level, AM_NO_FIXED_ART);
320 /* Apply good magic, but first clear object */
322 object_prep(owner_ptr, q_ptr, o_ptr->k_idx);
323 apply_magic(owner_ptr, q_ptr, owner_ptr->current_floor_ptr->dun_level, AM_NO_FIXED_ART | AM_GOOD);
325 /* Apply great magic, but first clear object */
327 object_prep(owner_ptr, q_ptr, o_ptr->k_idx);
328 apply_magic(owner_ptr, q_ptr, owner_ptr->current_floor_ptr->dun_level, AM_NO_FIXED_ART | AM_GOOD | AM_GREAT);
330 /* Apply special magic, but first clear object */
332 object_prep(owner_ptr, q_ptr, o_ptr->k_idx);
333 apply_magic(owner_ptr, q_ptr, owner_ptr->current_floor_ptr->dun_level, AM_GOOD | AM_GREAT | AM_SPECIAL);
334 if (!object_is_artifact(q_ptr))
335 become_random_artifact(owner_ptr, q_ptr, FALSE);
342 q_ptr->iy = o_ptr->iy;
343 q_ptr->ix = o_ptr->ix;
344 q_ptr->next_o_idx = o_ptr->next_o_idx;
345 q_ptr->marked = o_ptr->marked;
351 object_copy(o_ptr, q_ptr);
352 owner_ptr->update |= PU_BONUS;
353 owner_ptr->update |= PU_COMBINE | PU_REORDER;
354 owner_ptr->window |= PW_INVEN | PW_EQUIP | PW_SPELL | PW_PLAYER;
358 * @briefアイテムの基礎能力値を調整する / Tweak an item
359 * @param player_ptr プレーヤーへの参照ポインタ
360 * @param o_ptr 調整するアイテムの参照ポインタ
363 static void wiz_tweak_item(player_type *player_ptr, object_type *o_ptr)
365 if (object_is_artifact(o_ptr))
368 concptr p = "Enter new 'pval' setting: ";
370 sprintf(tmp_val, "%d", o_ptr->pval);
371 if (!get_string(p, tmp_val, 5))
374 o_ptr->pval = (s16b)atoi(tmp_val);
375 wiz_display_item(player_ptr, o_ptr);
376 p = "Enter new 'to_a' setting: ";
377 sprintf(tmp_val, "%d", o_ptr->to_a);
378 if (!get_string(p, tmp_val, 5))
381 o_ptr->to_a = (s16b)atoi(tmp_val);
382 wiz_display_item(player_ptr, o_ptr);
383 p = "Enter new 'to_h' setting: ";
384 sprintf(tmp_val, "%d", o_ptr->to_h);
385 if (!get_string(p, tmp_val, 5))
388 o_ptr->to_h = (s16b)atoi(tmp_val);
389 wiz_display_item(player_ptr, o_ptr);
390 p = "Enter new 'to_d' setting: ";
391 sprintf(tmp_val, "%d", (int)o_ptr->to_d);
392 if (!get_string(p, tmp_val, 5))
395 o_ptr->to_d = (s16b)atoi(tmp_val);
396 wiz_display_item(player_ptr, o_ptr);
400 * @brief 検査対象のアイテムの数を変更する /
401 * Change the quantity of a the item
402 * @param caster_ptr プレーヤーへの参照ポインタ
403 * @param o_ptr 変更するアイテム情報構造体の参照ポインタ
406 static void wiz_quantity_item(object_type *o_ptr)
408 if (object_is_artifact(o_ptr))
411 int tmp_qnt = o_ptr->number;
413 sprintf(tmp_val, "%d", (int)o_ptr->number);
414 if (get_string("Quantity: ", tmp_val, 2)) {
415 int tmp_int = atoi(tmp_val);
422 o_ptr->number = (byte)tmp_int;
425 if (o_ptr->tval == TV_ROD)
426 o_ptr->pval = o_ptr->pval * o_ptr->number / tmp_qnt;
430 * @brief アイテムを弄るデバッグコマンド
431 * Play with an item. Options include:
434 * - Output statistics (via wiz_roll_item)<br>
435 * - Reroll item (via wiz_reroll_item)<br>
436 * - Change properties (via wiz_tweak_item)<br>
437 * - Change the number of items (via wiz_quantity_item)<br>
439 void wiz_modify_item(player_type *creature_ptr)
441 concptr q = "Play with which object? ";
442 concptr s = "You have nothing to play with.";
445 o_ptr = choose_object(creature_ptr, &item, q, s, USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT, 0);
449 screen_save(creature_ptr);
454 object_copy(q_ptr, o_ptr);
456 bool changed = FALSE;
458 wiz_display_item(creature_ptr, q_ptr);
459 if (!get_com("[a]ccept [s]tatistics [r]eroll [t]weak [q]uantity? ", &ch, FALSE)) {
464 if (ch == 'A' || ch == 'a') {
469 if (ch == 's' || ch == 'S') {
470 wiz_statistics(creature_ptr, q_ptr);
473 if (ch == 'r' || ch == 'R') {
474 wiz_reroll_item(creature_ptr, q_ptr);
477 if (ch == 't' || ch == 'T') {
478 wiz_tweak_item(creature_ptr, q_ptr);
481 if (ch == 'q' || ch == 'Q') {
482 wiz_quantity_item(q_ptr);
486 screen_load(creature_ptr);
488 msg_print("Changes accepted.");
490 object_copy(o_ptr, q_ptr);
491 creature_ptr->update |= PU_BONUS;
492 creature_ptr->update |= PU_COMBINE | PU_REORDER;
493 creature_ptr->window |= PW_INVEN | PW_EQUIP | PW_SPELL | PW_PLAYER;
495 msg_print("Changes ignored.");