OSDN Git Service

[Refactor] #37353 record_turn の宣言を gameoption.h へ移動.
[hengband/hengband.git] / src / wizard2.c
1 /*!
2  * @file wizard2.c
3  * @brief ウィザードモードの処理(特別処理中心) / Wizard commands
4  * @date 2014/09/07
5  * @author
6  * Copyright (c) 1997 Ben Harrison, and others<br>
7  * This software may be copied and distributed for educational, research,
8  * and not for profit purposes provided that this copyright and statement
9  * are included in all such copies.  Other copyrights may also apply.<br>
10  * 2014 Deskull rearranged comment for Doxygen.<br>
11  */
12
13 #include "angband.h"
14 #include "dungeon.h"
15 #include "cmd-dump.h"
16 #include "util.h"
17 #include "birth.h"
18 #include "selfinfo.h"
19 #include "patron.h"
20 #include "mutation.h"
21 #include "quest.h"
22 #include "artifact.h"
23 #include "player-status.h"
24 #include "player-effects.h"
25 #include "player-skill.h"
26
27 #include "spells.h"
28 #include "spells-object.h"
29 #include "spells-summon.h"
30 #include "spells-status.h"
31 #include "spells-world.h"
32 #include "spells-floor.h"
33
34 #include "object-flavor.h"
35 #include "object-hook.h"
36 #include "monster-status.h"
37
38 #include "floor.h"
39 #include "floor-save.h"
40 #include "grid.h"
41 #include "dungeon-file.h"
42 #include "files.h"
43 #include "monster-spell.h"
44 #include "bldg.h"
45 #include "objectkind.h"
46 #include "targeting.h"
47
48 #ifdef ALLOW_WIZARD
49
50 /*!
51  * @brief 必ず成功するウィザードモード用次元の扉処理 / Wizard Dimension Door
52  * @return 実際にテレポートを行ったらTRUEを返す
53  */
54 static bool wiz_dimension_door(void)
55 {
56         POSITION x = 0, y = 0;
57         if (!tgt_pt(&x, &y)) return FALSE;
58         teleport_player_to(y, x, TELEPORT_NONMAGICAL);
59         return (TRUE);
60 }
61
62 /*!
63  * @brief 指定されたIDの固定アーティファクトを生成する / Create the artifact of the specified number
64  * @return なし
65  */
66 static void wiz_create_named_art(void)
67 {
68         char tmp_val[10] = "";
69         ARTIFACT_IDX a_idx;
70
71         /* Query */
72         if (!get_string("Artifact ID:", tmp_val, 3)) return;
73
74         /* Extract */
75         a_idx = (ARTIFACT_IDX)atoi(tmp_val);
76         if(a_idx < 0) a_idx = 0;
77         if(a_idx >= max_a_idx) a_idx = 0; 
78
79         (void)create_named_art(a_idx, p_ptr->y, p_ptr->x);
80
81         /* All done */
82         msg_print("Allocated.");
83 }
84
85 /*!
86  * @brief ウィザードモード用モンスターの群れ生成 / Summon a horde of monsters
87  * @return なし
88  */
89 static void do_cmd_summon_horde(void)
90 {
91         POSITION wy = p_ptr->y, wx = p_ptr->x;
92         int attempts = 1000;
93
94         while (--attempts)
95         {
96                 scatter(&wy, &wx, p_ptr->y, p_ptr->x, 3, 0);
97                 if (cave_empty_bold(wy, wx)) break;
98         }
99
100         (void)alloc_horde(wy, wx);
101 }
102
103 /*!
104  * @brief 32ビット変数のビット配列を並べて描画する / Output a long int in binary format.
105  * @return なし
106  */
107 static void prt_binary(BIT_FLAGS flags, int row, int col)
108 {
109         int i;
110         u32b bitmask;
111
112         /* Scan the flags */
113         for (i = bitmask = 1; i <= 32; i++, bitmask *= 2)
114         {
115                 /* Dump set bits */
116                 if (flags & bitmask)
117                 {
118                         Term_putch(col++, row, TERM_BLUE, '*');
119                 }
120
121                 /* Dump unset bits */
122                 else
123                 {
124                         Term_putch(col++, row, TERM_WHITE, '-');
125                 }
126         }
127 }
128
129
130 #define K_MAX_DEPTH 110 /*!< アイテムの階層毎生成率を表示する最大階 */
131
132 /*!
133  * @brief アイテムの階層毎生成率を表示する / Output a rarity graph for a type of object.
134  * @param tval ベースアイテムの大項目ID
135  * @param sval ベースアイテムの小項目ID
136  * @param row 表示列
137  * @param col 表示行
138  * @return なし
139  */
140 static void prt_alloc(OBJECT_TYPE_VALUE tval, OBJECT_SUBTYPE_VALUE sval, TERM_LEN row, TERM_LEN col)
141 {
142         int i, j;
143         int home = 0;
144         u32b rarity[K_MAX_DEPTH];
145         u32b total[K_MAX_DEPTH];
146         s32b display[22];
147         concptr r = "+---Rate---+";
148         object_kind *k_ptr;
149
150
151         /* Get the entry */
152         alloc_entry *table = alloc_kind_table;
153
154         /* Wipe the tables */
155         (void)C_WIPE(rarity, K_MAX_DEPTH, u32b);
156         (void)C_WIPE(total, K_MAX_DEPTH, u32b);
157         (void)C_WIPE(display, 22, s32b);
158
159         /* Scan all entries */
160         for (i = 0; i < K_MAX_DEPTH; i++)
161         {
162                 int total_frac = 0;
163                 for (j = 0; j < alloc_kind_size; j++)
164                 {
165                         PERCENTAGE prob = 0;
166
167                         if (table[j].level <= i)
168                         {
169                                 prob = table[j].prob1 * GREAT_OBJ * K_MAX_DEPTH;
170                         }
171                         else if (table[j].level - 1 > 0)
172                         {
173                                 prob = table[j].prob1 * i * K_MAX_DEPTH / (table[j].level - 1);
174                         }
175
176                         /* Acquire this kind */
177                         k_ptr = &k_info[table[j].index];
178
179                         /* Accumulate probabilities */
180                         total[i] += prob / (GREAT_OBJ * K_MAX_DEPTH);
181                         total_frac += prob % (GREAT_OBJ * K_MAX_DEPTH);
182
183                         /* Accumulate probabilities */
184                         if ((k_ptr->tval == tval) && (k_ptr->sval == sval))
185                         {
186                                 home = k_ptr->level;
187                                 rarity[i] += prob / (GREAT_OBJ * K_MAX_DEPTH);
188                         }
189                 }
190                 total[i] += total_frac / (GREAT_OBJ * K_MAX_DEPTH);
191         }
192
193         /* Calculate probabilities for each range */
194         for (i = 0; i < 22; i++)
195         {
196                 /* Shift the values into view */
197                 int possibility = 0;
198                 for (j = i * K_MAX_DEPTH / 22; j < (i + 1) * K_MAX_DEPTH / 22; j++)
199                         possibility += rarity[j] * 100000 / total[j];
200                 display[i] = possibility / 5;
201         }
202
203         /* Graph the rarities */
204         for (i = 0; i < 22; i++)
205         {
206                 Term_putch(col, row + i + 1, TERM_WHITE,  '|');
207
208                 prt(format("%2dF", (i * 5)), row + i + 1, col);
209
210
211                 /* Note the level */
212                 if ((i * K_MAX_DEPTH / 22 <= home) && (home < (i + 1) * K_MAX_DEPTH / 22))
213                 {
214                         c_prt(TERM_RED, format("%3d.%04d%%", display[i] / 1000, display[i] % 1000), row + i + 1, col + 3);
215                 }
216                 else
217                 {
218                         c_prt(TERM_WHITE, format("%3d.%04d%%", display[i] / 1000, display[i] % 1000), row + i + 1, col + 3);
219                 }
220         }
221
222         /* Make it look nice */
223         prt(r, row, col);
224 }
225
226 /*!
227  * @brief プレイヤーの職業を変更する
228  * @return なし
229  * @todo 魔法領域の再選択などがまだ不完全、要実装。
230  */
231 static void do_cmd_wiz_reset_class(void)
232 {
233         int tmp_int;
234         char tmp_val[160];
235         char ppp[80];
236
237         /* Prompt */
238         sprintf(ppp, "Class (0-%d): ", MAX_CLASS - 1);
239
240         /* Default */
241         sprintf(tmp_val, "%d", p_ptr->pclass);
242
243         /* Query */
244         if (!get_string(ppp, tmp_val, 2)) return;
245
246         /* Extract */
247         tmp_int = atoi(tmp_val);
248
249         /* Verify */
250         if (tmp_int < 0 || tmp_int >= MAX_CLASS) return;
251
252         /* Save it */
253         p_ptr->pclass = (byte_hack)tmp_int;
254
255         /* Redraw inscription */
256         p_ptr->window |= (PW_PLAYER);
257
258         /* {.} and {$} effect p_ptr->warning and TRC_TELEPORT_SELF */
259         p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
260
261         handle_stuff();
262 }
263
264
265 /*!
266  * @brief ウィザードモード用処理としてターゲット中の相手をテレポートバックする / Hack -- Teleport to the target
267  * @return なし
268  */
269 static void do_cmd_wiz_bamf(void)
270 {
271         /* Must have a target */
272         if (!target_who) return;
273
274         /* Teleport to the target */
275         teleport_player_to(target_row, target_col, TELEPORT_NONMAGICAL);
276 }
277
278
279 /*!
280  * @brief プレイヤーの現能力値を調整する
281  * Aux function for "do_cmd_wiz_change()".      -RAK-
282  * @return なし
283  */
284 static void do_cmd_wiz_change_aux(void)
285 {
286         int i, j;
287         int tmp_int;
288         long tmp_long;
289         s16b tmp_s16b;
290         char tmp_val[160];
291         char ppp[80];
292
293
294         /* Query the stats */
295         for (i = 0; i < A_MAX; i++)
296         {
297                 /* Prompt */
298                 sprintf(ppp, "%s (3-%d): ", stat_names[i], p_ptr->stat_max_max[i]);
299
300                 /* Default */
301                 sprintf(tmp_val, "%d", p_ptr->stat_max[i]);
302
303                 /* Query */
304                 if (!get_string(ppp, tmp_val, 3)) return;
305
306                 /* Extract */
307                 tmp_int = atoi(tmp_val);
308
309                 /* Verify */
310                 if (tmp_int > p_ptr->stat_max_max[i]) tmp_int = p_ptr->stat_max_max[i];
311                 else if (tmp_int < 3) tmp_int = 3;
312
313                 /* Save it */
314                 p_ptr->stat_cur[i] = p_ptr->stat_max[i] = (BASE_STATUS)tmp_int;
315         }
316
317
318         /* Default */
319         sprintf(tmp_val, "%d", WEAPON_EXP_MASTER);
320
321         /* Query */
322         if (!get_string(_("熟練度: ", "Proficiency: "), tmp_val, 9)) return;
323
324         /* Extract */
325         tmp_s16b = (s16b)atoi(tmp_val);
326
327         /* Verify */
328         if (tmp_s16b < WEAPON_EXP_UNSKILLED) tmp_s16b = WEAPON_EXP_UNSKILLED;
329         if (tmp_s16b > WEAPON_EXP_MASTER) tmp_s16b = WEAPON_EXP_MASTER;
330
331         for (j = 0; j <= TV_WEAPON_END - TV_WEAPON_BEGIN; j++)
332         {
333                 for (i = 0;i < 64;i++)
334                 {
335                         p_ptr->weapon_exp[j][i] = tmp_s16b;
336                         if (p_ptr->weapon_exp[j][i] > s_info[p_ptr->pclass].w_max[j][i]) p_ptr->weapon_exp[j][i] = s_info[p_ptr->pclass].w_max[j][i];
337                 }
338         }
339
340         for (j = 0; j < 10; j++)
341         {
342                 p_ptr->skill_exp[j] = tmp_s16b;
343                 if (p_ptr->skill_exp[j] > s_info[p_ptr->pclass].s_max[j]) p_ptr->skill_exp[j] = s_info[p_ptr->pclass].s_max[j];
344         }
345
346         for (j = 0; j < 32; j++)
347                 p_ptr->spell_exp[j] = (tmp_s16b > SPELL_EXP_MASTER ? SPELL_EXP_MASTER : tmp_s16b);
348         for (; j < 64; j++)
349                 p_ptr->spell_exp[j] = (tmp_s16b > SPELL_EXP_EXPERT ? SPELL_EXP_EXPERT : tmp_s16b);
350
351         /* Default */
352         sprintf(tmp_val, "%ld", (long)(p_ptr->au));
353
354         /* Query */
355         if (!get_string("Gold: ", tmp_val, 9)) return;
356
357         /* Extract */
358         tmp_long = atol(tmp_val);
359
360         /* Verify */
361         if (tmp_long < 0) tmp_long = 0L;
362
363         /* Save */
364         p_ptr->au = tmp_long;
365
366         /* Default */
367         sprintf(tmp_val, "%ld", (long)(p_ptr->max_exp));
368
369         /* Query */
370         if (!get_string("Experience: ", tmp_val, 9)) return;
371
372         /* Extract */
373         tmp_long = atol(tmp_val);
374
375         /* Verify */
376         if (tmp_long < 0) tmp_long = 0L;
377
378         if (p_ptr->prace != RACE_ANDROID)
379         {
380                 /* Save */
381                 p_ptr->max_exp = tmp_long;
382                 p_ptr->exp = tmp_long;
383
384                 /* Update */
385                 check_experience();
386         }
387 }
388
389
390 /*!
391  * @brief プレイヤーの現能力値を調整する(メインルーチン)
392  * Change various "permanent" player variables.
393  * @return なし
394  */
395 static void do_cmd_wiz_change(void)
396 {
397         /* Interact */
398         do_cmd_wiz_change_aux();
399         do_cmd_redraw();
400 }
401
402
403 /*!
404  * @brief アイテムの詳細ステータスを表示する / 
405  * Change various "permanent" player variables.
406  * @param o_ptr 詳細を表示するアイテム情報の参照ポインタ
407  * @return なし
408  * @details
409  * Wizard routines for creating objects         -RAK-
410  * And for manipulating them!                   -Bernd-
411  *
412  * This has been rewritten to make the whole procedure
413  * of debugging objects much easier and more comfortable.
414  *
415  * The following functions are meant to play with objects:
416  * Create, modify, roll for them (for statistic purposes) and more.
417  * The original functions were by RAK.
418  * The function to show an item's debug information was written
419  * by David Reeve Sward <sward+@CMU.EDU>.
420  *                             Bernd (wiebelt@mathematik.hu-berlin.de)
421  *
422  * Here are the low-level functions
423  * - wiz_display_item()
424  *     display an item's debug-info
425  * - wiz_create_itemtype()
426  *     specify tval and sval (type and subtype of object)
427  * - wiz_tweak_item()
428  *     specify pval, +AC, +tohit, +todam
429  *     Note that the wizard can leave this function anytime,
430  *     thus accepting the default-values for the remaining values.
431  *     pval comes first now, since it is most important.
432  * - wiz_reroll_item()
433  *     apply some magic to the item or current_world_ptr->game_turn it into an artifact.
434  * - wiz_roll_item()
435  *     Get some statistics about the rarity of an item:
436  *     We create a lot of fake items and see if they are of the
437  *     same type (tval and sval), then we compare pval and +AC.
438  *     If the fake-item is better or equal it is counted.
439  *     Note that cursed items that are better or equal (absolute values)
440  *     are counted, too.
441  *     HINT: This is *very* useful for balancing the game!
442  * - wiz_quantity_item()
443  *     change the quantity of an item, but be sane about it.
444  *
445  * And now the high-level functions
446  * - do_cmd_wiz_play()
447  *     play with an existing object
448  * - wiz_create_item()
449  *     create a new object
450  *
451  * Note -- You do not have to specify "pval" and other item-properties
452  * directly. Just apply magic until you are satisfied with the item.
453  *
454  * Note -- For some items (such as wands, staffs, some rings, etc), you
455  * must apply magic, or you will get "broken" or "uncharged" objects.
456  *
457  * Note -- Redefining artifacts via "do_cmd_wiz_play()" may destroy
458  * the artifact.  Be careful.
459  *
460  * Hack -- this function will allow you to create multiple artifacts.
461  * This "feature" may induce crashes or other nasty effects.
462  * Just display an item's properties (debug-info)
463  * Originally by David Reeve Sward <sward+@CMU.EDU>
464  * Verbose item flags by -Bernd-
465  */
466 static void wiz_display_item(object_type *o_ptr)
467 {
468         int i, j = 13;
469         BIT_FLAGS flgs[TR_FLAG_SIZE];
470         char buf[256];
471         object_flags(o_ptr, flgs);
472
473         /* Clear the screen */
474         for (i = 1; i <= 23; i++) prt("", i, j - 2);
475
476         prt_alloc(o_ptr->tval, o_ptr->sval, 1, 0);
477
478         /* Describe fully */
479         object_desc(buf, o_ptr, OD_STORE);
480
481         prt(buf, 2, j);
482
483         prt(format("kind = %-5d  level = %-4d  tval = %-5d  sval = %-5d",
484                    o_ptr->k_idx, k_info[o_ptr->k_idx].level,
485                    o_ptr->tval, o_ptr->sval), 4, j);
486
487         prt(format("number = %-3d  wgt = %-6d  ac = %-5d    damage = %dd%d",
488                    o_ptr->number, o_ptr->weight,
489                    o_ptr->ac, o_ptr->dd, o_ptr->ds), 5, j);
490
491         prt(format("pval = %-5d  toac = %-5d  tohit = %-4d  todam = %-4d",
492                    o_ptr->pval, o_ptr->to_a, o_ptr->to_h, o_ptr->to_d), 6, j);
493
494         prt(format("name1 = %-4d  name2 = %-4d  cost = %ld",
495                    o_ptr->name1, o_ptr->name2, (long)object_value_real(o_ptr)), 7, j);
496
497         prt(format("ident = %04x  xtra1 = %-4d  xtra2 = %-4d  timeout = %-d",
498                    o_ptr->ident, o_ptr->xtra1, o_ptr->xtra2, o_ptr->timeout), 8, j);
499
500         prt(format("xtra3 = %-4d  xtra4 = %-4d  xtra5 = %-4d  cursed  = %-d",
501                    o_ptr->xtra3, o_ptr->xtra4, o_ptr->xtra5, o_ptr->curse_flags), 9, j);
502
503         prt("+------------FLAGS1------------+", 10, j);
504         prt("AFFECT........SLAY........BRAND.", 11, j);
505         prt("      mf      cvae      xsqpaefc", 12, j);
506         prt("siwdccsossidsahanvudotgddhuoclio", 13, j);
507         prt("tnieohtctrnipttmiinmrrnrrraiierl", 14, j);
508         prt("rtsxnarelcfgdkcpmldncltggpksdced", 15, j);
509         prt_binary(flgs[0], 16, j);
510
511         prt("+------------FLAGS2------------+", 17, j);
512         prt("SUST....IMMUN.RESIST............", 18, j);
513         prt("      reaefctrpsaefcpfldbc sn   ", 19, j);
514         prt("siwdcciaclioheatcliooeialoshtncd", 20, j);
515         prt("tnieohdsierlrfraierliatrnnnrhehi", 21, j);
516         prt("rtsxnaeydcedwlatdcedsrekdfddrxss", 22, j);
517         prt_binary(flgs[1], 23, j);
518
519         prt("+------------FLAGS3------------+", 10, j+32);
520         prt("fe cnn t      stdrmsiiii d ab   ", 11, j+32);
521         prt("aa aoomywhs lleeieihgggg rtgl   ", 12, j+32);
522         prt("uu utmacaih eielgggonnnnaaere   ", 13, j+32);
523         prt("rr reanurdo vtieeehtrrrrcilas   ", 14, j+32);
524         prt("aa algarnew ienpsntsaefctnevs   ", 15, j+32);
525         prt_binary(flgs[2], 16, j+32);
526
527         prt("+------------FLAGS4------------+", 17, j+32);
528         prt("KILL....ESP.........            ", 18, j+32);
529         prt("aeud tghaud tgdhegnu            ", 19, j+32);
530         prt("nvneoriunneoriruvoon            ", 20, j+32);
531         prt("iidmroamidmroagmionq            ", 21, j+32);
532         prt("mlenclnmmenclnnnldlu            ", 22, j+32);
533         prt_binary(flgs[3], 23, j+32);
534 }
535
536
537 /*!
538  * ベースアイテムの大項目IDの種別名をまとめる構造体 / A structure to hold a tval and its description
539  */
540 typedef struct tval_desc
541 {
542         int        tval; /*!< 大項目のID */
543         concptr       desc; /*!< 大項目名 */
544 } tval_desc;
545
546 /*!
547  * ベースアイテムの大項目IDの種別名定義 / A list of tvals and their textual names
548  */
549 static tval_desc tvals[] =
550 {
551         { TV_SWORD,             "Sword"                },
552         { TV_POLEARM,           "Polearm"              },
553         { TV_HAFTED,            "Hafted Weapon"        },
554         { TV_BOW,               "Bow"                  },
555         { TV_ARROW,             "Arrows"               },
556         { TV_BOLT,              "Bolts"                },
557         { TV_SHOT,              "Shots"                },
558         { TV_SHIELD,            "Shield"               },
559         { TV_CROWN,             "Crown"                },
560         { TV_HELM,              "Helm"                 },
561         { TV_GLOVES,            "Gloves"               },
562         { TV_BOOTS,             "Boots"                },
563         { TV_CLOAK,             "Cloak"                },
564         { TV_DRAG_ARMOR,        "Dragon Scale Mail"    },
565         { TV_HARD_ARMOR,        "Hard Armor"           },
566         { TV_SOFT_ARMOR,        "Soft Armor"           },
567         { TV_RING,              "Ring"                 },
568         { TV_AMULET,            "Amulet"               },
569         { TV_LITE,              "Lite"                 },
570         { TV_POTION,            "Potion"               },
571         { TV_SCROLL,            "Scroll"               },
572         { TV_WAND,              "Wand"                 },
573         { TV_STAFF,             "Staff"                },
574         { TV_ROD,               "Rod"                  },
575         { TV_LIFE_BOOK,         "Life Spellbook"       },
576         { TV_SORCERY_BOOK,      "Sorcery Spellbook"    },
577         { TV_NATURE_BOOK,       "Nature Spellbook"     },
578         { TV_CHAOS_BOOK,        "Chaos Spellbook"      },
579         { TV_DEATH_BOOK,        "Death Spellbook"      },
580         { TV_TRUMP_BOOK,        "Trump Spellbook"      },
581         { TV_ARCANE_BOOK,       "Arcane Spellbook"     },
582         { TV_CRAFT_BOOK,      "Craft Spellbook"},
583         { TV_DAEMON_BOOK,       "Daemon Spellbook"},
584         { TV_CRUSADE_BOOK,      "Crusade Spellbook"},
585         { TV_MUSIC_BOOK,        "Music Spellbook"      },
586         { TV_HISSATSU_BOOK,     "Book of Kendo" },
587         { TV_HEX_BOOK,          "Hex Spellbook"        },
588         { TV_PARCHMENT,         "Parchment" },
589         { TV_WHISTLE,           "Whistle"       },
590         { TV_SPIKE,             "Spikes"               },
591         { TV_DIGGING,           "Digger"               },
592         { TV_CHEST,             "Chest"                },
593         { TV_CAPTURE,           "Capture Ball"         },
594         { TV_CARD,              "Express Card"         },
595         { TV_FIGURINE,          "Magical Figurine"     },
596         { TV_STATUE,            "Statue"               },
597         { TV_CORPSE,            "Corpse"               },
598         { TV_FOOD,              "Food"                 },
599         { TV_FLASK,             "Flask"                },
600         { TV_JUNK,              "Junk"                 },
601         { TV_SKELETON,          "Skeleton"             },
602         { 0,                    NULL                   }
603 };
604
605 /*!
606  * @brief ベースアイテムのウィザード生成のために大項目IDと小項目IDを取得する /
607  * Specify tval and sval (type and subtype of object) originally
608  * @return ベースアイテムID
609  * @details
610  * by RAK, heavily modified by -Bernd-
611  * This function returns the k_idx of an object type, or zero if failed
612  * List up to 50 choices in three columns
613  */
614 static KIND_OBJECT_IDX wiz_create_itemtype(void)
615 {
616         KIND_OBJECT_IDX i;
617         int num, max_num;
618         TERM_LEN col, row;
619         OBJECT_TYPE_VALUE tval;
620
621         concptr tval_desc;
622         char ch;
623
624         KIND_OBJECT_IDX choice[80];
625
626         char buf[160];
627
628         Term_clear();
629
630         /* Print all tval's and their descriptions */
631         for (num = 0; (num < 80) && tvals[num].tval; num++)
632         {
633                 row = 2 + (num % 20);
634                 col = 20 * (num / 20);
635                 ch = listsym[num];
636                 prt(format("[%c] %s", ch, tvals[num].desc), row, col);
637         }
638
639         /* Me need to know the maximal possible tval_index */
640         max_num = num;
641
642         /* Choose! */
643         if (!get_com("Get what type of object? ", &ch, FALSE)) return (0);
644
645         /* Analyze choice */
646         for (num = 0; num < max_num; num++)
647         {
648                 if (listsym[num] == ch) break;
649         }
650
651         /* Bail out if choice is illegal */
652         if ((num < 0) || (num >= max_num)) return (0);
653
654         /* Base object type chosen, fill in tval */
655         tval = tvals[num].tval;
656         tval_desc = tvals[num].desc;
657
658
659         /*** And now we go for k_idx ***/
660         Term_clear();
661
662         /* We have to search the whole itemlist. */
663         for (num = 0, i = 1; (num < 80) && (i < max_k_idx); i++)
664         {
665                 object_kind *k_ptr = &k_info[i];
666
667                 /* Analyze matching items */
668                 if (k_ptr->tval == tval)
669                 {
670                         /* Prepare it */
671                         row = 2 + (num % 20);
672                         col = 20 * (num / 20);
673                         ch = listsym[num];
674                         strcpy(buf,"                    ");
675
676                         /* Acquire the "name" of object "i" */
677                         strip_name(buf, i);
678
679                         /* Print it */
680                         prt(format("[%c] %s", ch, buf), row, col);
681
682                         /* Remember the object index */
683                         choice[num++] = i;
684                 }
685         }
686
687         /* Me need to know the maximal possible remembered object_index */
688         max_num = num;
689
690         /* Choose! */
691         if (!get_com(format("What Kind of %s? ", tval_desc), &ch, FALSE)) return (0);
692
693         /* Analyze choice */
694         for (num = 0; num < max_num; num++)
695         {
696                 if (listsym[num] == ch) break;
697         }
698
699         /* Bail out if choice is "illegal" */
700         if ((num < 0) || (num >= max_num)) return (0);
701
702         /* And return successful */
703         return (choice[num]);
704 }
705
706
707 /*!
708  * @briefアイテムの基礎能力値を調整する / Tweak an item
709  * @param o_ptr 調整するアイテムの参照ポインタ
710  * @return なし
711  */
712 static void wiz_tweak_item(object_type *o_ptr)
713 {
714         concptr p;
715         char tmp_val[80];
716
717         if (object_is_artifact(o_ptr)) return;
718
719         p = "Enter new 'pval' setting: ";
720         sprintf(tmp_val, "%d", o_ptr->pval);
721         if (!get_string(p, tmp_val, 5)) return;
722         o_ptr->pval = (s16b)atoi(tmp_val);
723         wiz_display_item(o_ptr);
724
725         p = "Enter new 'to_a' setting: ";
726         sprintf(tmp_val, "%d", o_ptr->to_a);
727         if (!get_string(p, tmp_val, 5)) return;
728         o_ptr->to_a = (s16b)atoi(tmp_val);
729         wiz_display_item(o_ptr);
730
731         p = "Enter new 'to_h' setting: ";
732         sprintf(tmp_val, "%d", o_ptr->to_h);
733         if (!get_string(p, tmp_val, 5)) return;
734         o_ptr->to_h = (s16b)atoi(tmp_val);
735         wiz_display_item(o_ptr);
736
737         p = "Enter new 'to_d' setting: ";
738         sprintf(tmp_val, "%d", (int)o_ptr->to_d);
739         if (!get_string(p, tmp_val, 5)) return;
740         o_ptr->to_d = (s16b)atoi(tmp_val);
741         wiz_display_item(o_ptr);
742 }
743
744
745 /*!
746  * @brief アイテムの質を選択して再生成する /
747  * Apply magic to an item or current_world_ptr->game_turn it into an artifact. -Bernd-
748  * @param o_ptr 再生成の対象となるアイテム情報の参照ポインタ
749  * @return なし
750  */
751 static void wiz_reroll_item(object_type *o_ptr)
752 {
753         object_type forge;
754         object_type *q_ptr;
755         char ch;
756         bool changed = FALSE;
757
758         if (object_is_artifact(o_ptr)) return;
759
760         q_ptr = &forge;
761         object_copy(q_ptr, o_ptr);
762
763         /* Main loop. Ask for magification and artifactification */
764         while (TRUE)
765         {
766                 /* Display full item debug information */
767                 wiz_display_item(q_ptr);
768
769                 /* Ask wizard what to do. */
770                 if (!get_com("[a]ccept, [w]orthless, [c]ursed, [n]ormal, [g]ood, [e]xcellent, [s]pecial? ", &ch, FALSE))
771                 {
772                         /* Preserve wizard-generated artifacts */
773                         if (object_is_fixed_artifact(q_ptr))
774                         {
775                                 a_info[q_ptr->name1].cur_num = 0;
776                                 q_ptr->name1 = 0;
777                         }
778
779                         changed = FALSE;
780                         break;
781                 }
782
783                 /* Create/change it! */
784                 if (ch == 'A' || ch == 'a')
785                 {
786                         changed = TRUE;
787                         break;
788                 }
789
790                 /* Preserve wizard-generated artifacts */
791                 if (object_is_fixed_artifact(q_ptr))
792                 {
793                         a_info[q_ptr->name1].cur_num = 0;
794                         q_ptr->name1 = 0;
795                 }
796
797                 switch(ch)
798                 {
799                         /* Apply bad magic, but first clear object */
800                         case 'w': case 'W':
801                         {
802                                 object_prep(q_ptr, o_ptr->k_idx);
803                                 apply_magic(q_ptr, current_floor_ptr->dun_level, AM_NO_FIXED_ART | AM_GOOD | AM_GREAT | AM_CURSED);
804                                 break;
805                         }
806                         /* Apply bad magic, but first clear object */
807                         case 'c': case 'C':
808                         {
809                                 object_prep(q_ptr, o_ptr->k_idx);
810                                 apply_magic(q_ptr, current_floor_ptr->dun_level, AM_NO_FIXED_ART | AM_GOOD | AM_CURSED);
811                                 break;
812                         }
813                         /* Apply normal magic, but first clear object */
814                         case 'n': case 'N':
815                         {
816                                 object_prep(q_ptr, o_ptr->k_idx);
817                                 apply_magic(q_ptr, current_floor_ptr->dun_level, AM_NO_FIXED_ART);
818                                 break;
819                         }
820                         /* Apply good magic, but first clear object */
821                         case 'g': case 'G':
822                         {
823                                 object_prep(q_ptr, o_ptr->k_idx);
824                                 apply_magic(q_ptr, current_floor_ptr->dun_level, AM_NO_FIXED_ART | AM_GOOD);
825                                 break;
826                         }
827                         /* Apply great magic, but first clear object */
828                         case 'e': case 'E':
829                         {
830                                 object_prep(q_ptr, o_ptr->k_idx);
831                                 apply_magic(q_ptr, current_floor_ptr->dun_level, AM_NO_FIXED_ART | AM_GOOD | AM_GREAT);
832                                 break;
833                         }
834                         /* Apply special magic, but first clear object */
835                         case 's': case 'S':
836                         {
837                                 object_prep(q_ptr, o_ptr->k_idx);
838                                 apply_magic(q_ptr, current_floor_ptr->dun_level, AM_GOOD | AM_GREAT | AM_SPECIAL);
839
840                                 /* Failed to create artifact; make a random one */
841                                 if (!object_is_artifact(q_ptr)) create_artifact(q_ptr, FALSE);
842                                 break;
843                         }
844                 }
845                 q_ptr->iy = o_ptr->iy;
846                 q_ptr->ix = o_ptr->ix;
847                 q_ptr->next_o_idx = o_ptr->next_o_idx;
848                 q_ptr->marked = o_ptr->marked;
849         }
850
851         /* Notice change */
852         if (changed)
853         {
854                 object_copy(o_ptr, q_ptr);
855                 p_ptr->update |= (PU_BONUS);
856                 p_ptr->update |= (PU_COMBINE | PU_REORDER);
857                 p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_SPELL | PW_PLAYER);
858         }
859 }
860
861
862
863 /*!
864  * @brief 検査対象のアイテムを基準とした生成テストを行う /
865  * Try to create an item again. Output some statistics.    -Bernd-
866  * @param o_ptr 生成テストの基準となるアイテム情報の参照ポインタ
867  * @return なし
868  * The statistics are correct now.  We acquire a clean grid, and then
869  * repeatedly place an object in this grid, copying it into an item
870  * holder, and then deleting the object.  We fiddle with the artifact
871  * counter flags to prevent weirdness.  We use the items to collect
872  * statistics on item creation relative to the initial item.
873  */
874 static void wiz_statistics(object_type *o_ptr)
875 {
876         u32b i, matches, better, worse, other, correct;
877
878         u32b test_roll = 1000000;
879
880         char ch;
881         concptr quality;
882
883         BIT_FLAGS mode;
884
885         object_type forge;
886         object_type     *q_ptr;
887
888         concptr q = "Rolls: %ld  Correct: %ld  Matches: %ld  Better: %ld  Worse: %ld  Other: %ld";
889
890         concptr p = "Enter number of items to roll: ";
891         char tmp_val[80];
892
893
894         /* Mega-Hack -- allow multiple artifacts */
895         if (object_is_fixed_artifact(o_ptr)) a_info[o_ptr->name1].cur_num = 0;
896
897
898         /* Interact */
899         while (TRUE)
900         {
901                 concptr pmt = "Roll for [n]ormal, [g]ood, or [e]xcellent treasure? ";
902
903                 /* Display item */
904                 wiz_display_item(o_ptr);
905
906                 /* Get choices */
907                 if (!get_com(pmt, &ch, FALSE)) break;
908
909                 if (ch == 'n' || ch == 'N')
910                 {
911                         mode = 0L;
912                         quality = "normal";
913                 }
914                 else if (ch == 'g' || ch == 'G')
915                 {
916                         mode = AM_GOOD;
917                         quality = "good";
918                 }
919                 else if (ch == 'e' || ch == 'E')
920                 {
921                         mode = AM_GOOD | AM_GREAT;
922                         quality = "excellent";
923                 }
924                 else
925                 {
926                         break;
927                 }
928
929                 sprintf(tmp_val, "%ld", (long int)test_roll);
930                 if (get_string(p, tmp_val, 10)) test_roll = atol(tmp_val);
931                 test_roll = MAX(1, test_roll);
932
933                 /* Let us know what we are doing */
934                 msg_format("Creating a lot of %s items. Base level = %d.",
935                                           quality, current_floor_ptr->dun_level);
936                 msg_print(NULL);
937
938                 /* Set counters to zero */
939                 correct = matches = better = worse = other = 0;
940
941                 /* Let's rock and roll */
942                 for (i = 0; i <= test_roll; i++)
943                 {
944                         /* Output every few rolls */
945                         if ((i < 100) || (i % 100 == 0))
946                         {
947                                 /* Do not wait */
948                                 inkey_scan = TRUE;
949
950                                 /* Allow interupt */
951                                 if (inkey())
952                                 {
953                                         flush();
954                                         break; // stop rolling
955                                 }
956
957                                 /* Dump the stats */
958                                 prt(format(q, i, correct, matches, better, worse, other), 0, 0);
959                                 Term_fresh();
960                         }
961                         q_ptr = &forge;
962                         object_wipe(q_ptr);
963
964                         /* Create an object */
965                         make_object(q_ptr, mode);
966
967
968                         /* Mega-Hack -- allow multiple artifacts */
969                         if (object_is_fixed_artifact(q_ptr)) a_info[q_ptr->name1].cur_num = 0;
970
971
972                         /* Test for the same tval and sval. */
973                         if ((o_ptr->tval) != (q_ptr->tval)) continue;
974                         if ((o_ptr->sval) != (q_ptr->sval)) continue;
975
976                         /* One more correct item */
977                         correct++;
978
979                         /* Check for match */
980                         if ((q_ptr->pval == o_ptr->pval) &&
981                                  (q_ptr->to_a == o_ptr->to_a) &&
982                                  (q_ptr->to_h == o_ptr->to_h) &&
983                                  (q_ptr->to_d == o_ptr->to_d) &&
984                                  (q_ptr->name1 == o_ptr->name1))
985                         {
986                                 matches++;
987                         }
988
989                         /* Check for better */
990                         else if ((q_ptr->pval >= o_ptr->pval) &&
991                                                 (q_ptr->to_a >= o_ptr->to_a) &&
992                                                 (q_ptr->to_h >= o_ptr->to_h) &&
993                                                 (q_ptr->to_d >= o_ptr->to_d))
994                         {
995                                 better++;
996                         }
997
998                         /* Check for worse */
999                         else if ((q_ptr->pval <= o_ptr->pval) &&
1000                                                 (q_ptr->to_a <= o_ptr->to_a) &&
1001                                                 (q_ptr->to_h <= o_ptr->to_h) &&
1002                                                 (q_ptr->to_d <= o_ptr->to_d))
1003                         {
1004                                 worse++;
1005                         }
1006
1007                         /* Assume different */
1008                         else
1009                         {
1010                                 other++;
1011                         }
1012                 }
1013
1014                 /* Final dump */
1015                 msg_format(q, i, correct, matches, better, worse, other);
1016                 msg_print(NULL);
1017         }
1018
1019
1020         /* Hack -- Normally only make a single artifact */
1021         if (object_is_fixed_artifact(o_ptr)) a_info[o_ptr->name1].cur_num = 1;
1022 }
1023
1024
1025 /*!
1026  * @brief 検査対象のアイテムの数を変更する /
1027  * Change the quantity of a the item
1028  * @param o_ptr 変更するアイテム情報構造体の参照ポインタ
1029  * @return なし
1030  */
1031 static void wiz_quantity_item(object_type *o_ptr)
1032 {
1033         int         tmp_int, tmp_qnt;
1034
1035         char        tmp_val[100];
1036
1037
1038         /* Never duplicate artifacts */
1039         if (object_is_artifact(o_ptr)) return;
1040
1041         /* Store old quantity. -LM- */
1042         tmp_qnt = o_ptr->number;
1043
1044         /* Default */
1045         sprintf(tmp_val, "%d", (int)o_ptr->number);
1046
1047         /* Query */
1048         if (get_string("Quantity: ", tmp_val, 2))
1049         {
1050                 /* Extract */
1051                 tmp_int = atoi(tmp_val);
1052                 if (tmp_int < 1) tmp_int = 1;
1053                 if (tmp_int > 99) tmp_int = 99;
1054
1055                 /* Accept modifications */
1056                 o_ptr->number = (byte_hack)tmp_int;
1057         }
1058
1059         if (o_ptr->tval == TV_ROD)
1060         {
1061                 o_ptr->pval = o_ptr->pval * o_ptr->number / tmp_qnt;
1062         }
1063 }
1064
1065 /*!
1066  * @brief 青魔導師の魔法を全て習得済みにする /
1067  * debug command for blue mage
1068  * @return なし
1069  */
1070 static void do_cmd_wiz_blue_mage(void)
1071 {
1072         int i = 0;
1073         int j = 0;
1074         BIT_FLAGS f4 = 0L, f5 = 0L, f6 = 0L;
1075
1076         for (j = 1; j < A_MAX; j++)
1077         {
1078                 set_rf_masks(&f4, &f5, &f6, j);
1079
1080                 for (i = 0; i < 32; i++)
1081                 {
1082                         if ((0x00000001 << i) & f4) p_ptr->magic_num2[i] = 1;
1083                 }
1084                 for (; i < 64; i++)
1085                 {
1086                         if ((0x00000001 << (i - 32)) & f5) p_ptr->magic_num2[i] = 1;
1087                 }
1088                 for (; i < 96; i++)
1089                 {
1090                         if ((0x00000001 << (i - 64)) & f6) p_ptr->magic_num2[i] = 1;
1091                 }
1092         }
1093 }
1094
1095
1096 /*!
1097  * @brief アイテム検査のメインルーチン /
1098  * Play with an item. Options include:
1099  * @return なし
1100  * @details 
1101  *   - Output statistics (via wiz_roll_item)<br>
1102  *   - Reroll item (via wiz_reroll_item)<br>
1103  *   - Change properties (via wiz_tweak_item)<br>
1104  *   - Change the number of items (via wiz_quantity_item)<br>
1105  */
1106 static void do_cmd_wiz_play(void)
1107 {
1108         OBJECT_IDX item;
1109         object_type     forge;
1110         object_type *q_ptr;
1111         object_type *o_ptr;
1112         char ch;
1113         bool changed;
1114         concptr q, s;
1115
1116         q = "Play with which object? ";
1117         s = "You have nothing to play with.";
1118
1119         o_ptr = choose_object(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR | IGNORE_BOTHHAND_SLOT));
1120
1121         if (!o_ptr) return;
1122         
1123         /* The item was not changed */
1124         changed = FALSE;
1125
1126         screen_save();
1127
1128         q_ptr = &forge;
1129         object_copy(q_ptr, o_ptr);
1130
1131
1132         /* The main loop */
1133         while (TRUE)
1134         {
1135                 /* Display the item */
1136                 wiz_display_item(q_ptr);
1137
1138                 /* Get choice */
1139                 if (!get_com("[a]ccept [s]tatistics [r]eroll [t]weak [q]uantity? ", &ch, FALSE))
1140                 {
1141                         changed = FALSE;
1142                         break;
1143                 }
1144
1145                 if (ch == 'A' || ch == 'a')
1146                 {
1147                         changed = TRUE;
1148                         break;
1149                 }
1150
1151                 if (ch == 's' || ch == 'S')
1152                 {
1153                         wiz_statistics(q_ptr);
1154                 }
1155
1156                 if (ch == 'r' || ch == 'r')
1157                 {
1158                         wiz_reroll_item(q_ptr);
1159                 }
1160
1161                 if (ch == 't' || ch == 'T')
1162                 {
1163                         wiz_tweak_item(q_ptr);
1164                 }
1165
1166                 if (ch == 'q' || ch == 'Q')
1167                 {
1168                         wiz_quantity_item(q_ptr);
1169                 }
1170         }
1171
1172         screen_load();
1173
1174
1175         /* Accept change */
1176         if (changed)
1177         {
1178                 msg_print("Changes accepted.");
1179
1180                 /* Recalcurate object's weight */
1181                 if (item >= 0)
1182                 {
1183                         p_ptr->total_weight += (q_ptr->weight * q_ptr->number)
1184                                 - (o_ptr->weight * o_ptr->number);
1185                 }
1186
1187                 /* Change */
1188                 object_copy(o_ptr, q_ptr);
1189
1190                 p_ptr->update |= (PU_BONUS);
1191                 p_ptr->update |= (PU_COMBINE | PU_REORDER);
1192
1193                 p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_SPELL | PW_PLAYER);
1194         }
1195
1196         /* Ignore change */
1197         else
1198         {
1199                 msg_print("Changes ignored.");
1200         }
1201 }
1202
1203
1204 /*!
1205  * @brief 任意のベースアイテム生成のメインルーチン /
1206  * Wizard routine for creating objects          -RAK-
1207  * @return なし
1208  * @details
1209  * Heavily modified to allow magification and artifactification  -Bernd-
1210  *
1211  * Note that wizards cannot create objects on top of other objects.
1212  *
1213  * Hack -- this routine always makes a "dungeon object", and applies
1214  * magic to it, and attempts to decline cursed items.
1215  */
1216 static void wiz_create_item(void)
1217 {
1218         object_type     forge;
1219         object_type *q_ptr;
1220
1221         OBJECT_IDX k_idx;
1222         screen_save();
1223
1224         /* Get object base type */
1225         k_idx = wiz_create_itemtype();
1226
1227         screen_load();
1228
1229         /* Return if failed */
1230         if (!k_idx) return;
1231
1232         if (k_info[k_idx].gen_flags & TRG_INSTA_ART)
1233         {
1234                 ARTIFACT_IDX i;
1235
1236                 /* Artifactify */
1237                 for (i = 1; i < max_a_idx; i++)
1238                 {
1239                         /* Ignore incorrect tval */
1240                         if (a_info[i].tval != k_info[k_idx].tval) continue;
1241
1242                         /* Ignore incorrect sval */
1243                         if (a_info[i].sval != k_info[k_idx].sval) continue;
1244
1245                         /* Create this artifact */
1246                         (void)create_named_art(i, p_ptr->y, p_ptr->x);
1247
1248                         /* All done */
1249                         msg_print("Allocated(INSTA_ART).");
1250
1251                         return;
1252                 }
1253         }
1254         q_ptr = &forge;
1255         object_prep(q_ptr, k_idx);
1256
1257         apply_magic(q_ptr, current_floor_ptr->dun_level, AM_NO_FIXED_ART);
1258
1259         /* Drop the object from heaven */
1260         (void)drop_near(q_ptr, -1, p_ptr->y, p_ptr->x);
1261
1262         /* All done */
1263         msg_print("Allocated.");
1264 }
1265
1266
1267 /*!
1268  * @brief プレイヤーを完全回復する /
1269  * Cure everything instantly
1270  * @return なし
1271  */
1272 static void do_cmd_wiz_cure_all(void)
1273 {
1274         (void)life_stream(FALSE, FALSE);
1275         (void)restore_mana(TRUE);
1276         (void)set_food(PY_FOOD_MAX - 1);
1277 }
1278
1279
1280 /*!
1281  * @brief 任意のダンジョン及び階層に飛ぶ /
1282  * Go to any level
1283  * @return なし
1284  */
1285 static void do_cmd_wiz_jump(void)
1286 {
1287         /* Ask for level */
1288         if (command_arg <= 0)
1289         {
1290                 char    ppp[80];
1291                 char    tmp_val[160];
1292                 DUNGEON_IDX tmp_dungeon_type;
1293
1294                 /* Prompt */
1295                 sprintf(ppp, "Jump which dungeon : ");
1296
1297                 /* Default */
1298                 sprintf(tmp_val, "%d", p_ptr->dungeon_idx);
1299
1300                 /* Ask for a level */
1301                 if (!get_string(ppp, tmp_val, 2)) return;
1302
1303                 tmp_dungeon_type = (DUNGEON_IDX)atoi(tmp_val);
1304                 if (!d_info[tmp_dungeon_type].maxdepth || (tmp_dungeon_type > max_d_idx)) tmp_dungeon_type = DUNGEON_ANGBAND;
1305
1306                 /* Prompt */
1307                 sprintf(ppp, "Jump to level (0, %d-%d): ",
1308                         (int)d_info[tmp_dungeon_type].mindepth, (int)d_info[tmp_dungeon_type].maxdepth);
1309
1310                 /* Default */
1311                 sprintf(tmp_val, "%d", (int)current_floor_ptr->dun_level);
1312
1313                 /* Ask for a level */
1314                 if (!get_string(ppp, tmp_val, 10)) return;
1315
1316                 /* Extract request */
1317                 command_arg = (COMMAND_ARG)atoi(tmp_val);
1318
1319                 p_ptr->dungeon_idx = tmp_dungeon_type;
1320         }
1321         if (command_arg < d_info[p_ptr->dungeon_idx].mindepth) command_arg = 0;
1322         if (command_arg > d_info[p_ptr->dungeon_idx].maxdepth) command_arg = (COMMAND_ARG)d_info[p_ptr->dungeon_idx].maxdepth;
1323
1324         /* Accept request */
1325         msg_format("You jump to dungeon level %d.", command_arg);
1326
1327         if (autosave_l) do_cmd_save_game(TRUE);
1328
1329         /* Change level */
1330         current_floor_ptr->dun_level = command_arg;
1331
1332         prepare_change_floor_mode(CFM_RAND_PLACE);
1333
1334         if (!current_floor_ptr->dun_level) p_ptr->dungeon_idx = 0;
1335         p_ptr->inside_arena = FALSE;
1336         p_ptr->wild_mode = FALSE;
1337
1338         leave_quest_check();
1339
1340         if (record_stair) do_cmd_write_nikki(NIKKI_WIZ_TELE,0,NULL);
1341
1342         p_ptr->inside_quest = 0;
1343         free_turn(p_ptr);
1344
1345         /* Prevent energy_need from being too lower than 0 */
1346         p_ptr->energy_need = 0;
1347
1348         /*
1349          * Clear all saved floors
1350          * and create a first saved floor
1351          */
1352         prepare_change_floor_mode(CFM_FIRST_FLOOR);
1353         p_ptr->leaving = TRUE;
1354 }
1355
1356
1357 /*!
1358  * @brief 全ベースアイテムを鑑定済みにする /
1359  * Become aware of a lot of objects
1360  * @return なし
1361  */
1362 static void do_cmd_wiz_learn(void)
1363 {
1364         KIND_OBJECT_IDX i;
1365
1366         object_type forge;
1367         object_type *q_ptr;
1368
1369         /* Scan every object */
1370         for (i = 1; i < max_k_idx; i++)
1371         {
1372                 object_kind *k_ptr = &k_info[i];
1373
1374                 /* Induce awareness */
1375                 if (k_ptr->level <= command_arg)
1376                 {
1377                         q_ptr = &forge;
1378                         object_prep(q_ptr, i);
1379                         object_aware(q_ptr);
1380                 }
1381         }
1382 }
1383
1384
1385 /*!
1386  * @brief 現在のフロアに合ったモンスターをランダムに召喚する /
1387  * Summon some creatures
1388  * @param num 生成処理回数
1389  * @return なし
1390  */
1391 static void do_cmd_wiz_summon(int num)
1392 {
1393         int i;
1394         for (i = 0; i < num; i++)
1395         {
1396                 (void)summon_specific(0, p_ptr->y, p_ptr->x, current_floor_ptr->dun_level, 0, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE));
1397         }
1398 }
1399
1400
1401
1402 /*!
1403  * @brief モンスターを種族IDを指定して敵対的に召喚する /
1404  * Summon a creature of the specified type
1405  * @param r_idx モンスター種族ID
1406  * @return なし
1407  * @details
1408  * This function is rather dangerous
1409  */
1410 static void do_cmd_wiz_named(MONRACE_IDX r_idx)
1411 {
1412         (void)summon_named_creature(0, p_ptr->y, p_ptr->x, r_idx, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1413 }
1414
1415
1416 /*!
1417  * @brief モンスターを種族IDを指定してペット召喚する /
1418  * Summon a creature of the specified type
1419  * @param r_idx モンスター種族ID
1420  * @return なし
1421  * @details
1422  * This function is rather dangerous
1423  */
1424 static void do_cmd_wiz_named_friendly(MONRACE_IDX r_idx)
1425 {
1426         (void)summon_named_creature(0, p_ptr->y, p_ptr->x, r_idx, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP | PM_FORCE_PET));
1427 }
1428
1429
1430
1431 /*!
1432  * @brief プレイヤー近辺の全モンスターを消去する /
1433  * Hack -- Delete all nearby monsters
1434  * @return なし
1435  */
1436 static void do_cmd_wiz_zap(void)
1437 {
1438         MONSTER_IDX i;
1439
1440         /* Genocide everyone nearby */
1441         for (i = 1; i < current_floor_ptr->m_max; i++)
1442         {
1443                 monster_type *m_ptr = &current_floor_ptr->m_list[i];
1444                 if (!monster_is_valid(m_ptr)) continue;
1445
1446                 /* Skip the mount */
1447                 if (i == p_ptr->riding) continue;
1448
1449                 /* Delete nearby monsters */
1450                 if (m_ptr->cdis <= MAX_SIGHT)
1451                 {
1452                         if (record_named_pet && is_pet(m_ptr) && m_ptr->nickname)
1453                         {
1454                                 GAME_TEXT m_name[MAX_NLEN];
1455
1456                                 monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
1457                                 do_cmd_write_nikki(NIKKI_NAMED_PET, RECORD_NAMED_PET_WIZ_ZAP, m_name);
1458                         }
1459
1460                         delete_monster_idx(i);
1461                 }
1462         }
1463 }
1464
1465
1466 /*!
1467  * @brief フロアに存在する全モンスターを消去する /
1468  * Hack -- Delete all monsters
1469  * @return なし
1470  */
1471 static void do_cmd_wiz_zap_all(void)
1472 {
1473         MONSTER_IDX i;
1474
1475         /* Genocide everyone */
1476         for (i = 1; i < current_floor_ptr->m_max; i++)
1477         {
1478                 monster_type *m_ptr = &current_floor_ptr->m_list[i];
1479                 if (!monster_is_valid(m_ptr)) continue;
1480
1481                 /* Skip the mount */
1482                 if (i == p_ptr->riding) continue;
1483
1484                 if (record_named_pet && is_pet(m_ptr) && m_ptr->nickname)
1485                 {
1486                         GAME_TEXT m_name[MAX_NLEN];
1487
1488                         monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
1489                         do_cmd_write_nikki(NIKKI_NAMED_PET, RECORD_NAMED_PET_WIZ_ZAP, m_name);
1490                 }
1491
1492                 /* Delete this monster */
1493                 delete_monster_idx(i);
1494         }
1495 }
1496
1497
1498 /*!
1499  * @brief 指定された地点の地形IDを変更する /
1500  * Create desired feature
1501  * @return なし
1502  */
1503 static void do_cmd_wiz_create_feature(void)
1504 {
1505         static int   prev_feat = 0;
1506         static int   prev_mimic = 0;
1507         grid_type    *g_ptr;
1508         feature_type *f_ptr;
1509         char         tmp_val[160];
1510         IDX          tmp_feat, tmp_mimic;
1511         POSITION y, x;
1512
1513         if (!tgt_pt(&x, &y)) return;
1514
1515         g_ptr = &current_floor_ptr->grid_array[y][x];
1516
1517         /* Default */
1518         sprintf(tmp_val, "%d", prev_feat);
1519
1520         /* Query */
1521         if (!get_string(_("地形: ", "Feature: "), tmp_val, 3)) return;
1522
1523         /* Extract */
1524         tmp_feat = (IDX)atoi(tmp_val);
1525         if (tmp_feat < 0) tmp_feat = 0;
1526         else if (tmp_feat >= max_f_idx) tmp_feat = max_f_idx - 1;
1527
1528         /* Default */
1529         sprintf(tmp_val, "%d", prev_mimic);
1530
1531         /* Query */
1532         if (!get_string(_("地形 (mimic): ", "Feature (mimic): "), tmp_val, 3)) return;
1533
1534         /* Extract */
1535         tmp_mimic = (IDX)atoi(tmp_val);
1536         if (tmp_mimic < 0) tmp_mimic = 0;
1537         else if (tmp_mimic >= max_f_idx) tmp_mimic = max_f_idx - 1;
1538
1539         cave_set_feat(y, x, tmp_feat);
1540         g_ptr->mimic = (s16b)tmp_mimic;
1541
1542         f_ptr = &f_info[get_feat_mimic(g_ptr)];
1543
1544         if (have_flag(f_ptr->flags, FF_GLYPH) ||
1545             have_flag(f_ptr->flags, FF_MINOR_GLYPH))
1546                 g_ptr->info |= (CAVE_OBJECT);
1547         else if (have_flag(f_ptr->flags, FF_MIRROR))
1548                 g_ptr->info |= (CAVE_GLOW | CAVE_OBJECT);
1549
1550         note_spot(y, x);
1551         lite_spot(y, x);
1552         p_ptr->update |= (PU_FLOW);
1553
1554         prev_feat = tmp_feat;
1555         prev_mimic = tmp_mimic;
1556 }
1557
1558
1559 #define NUM_O_SET 8
1560 #define NUM_O_BIT 32
1561
1562 /*!
1563  * @brief 現在のオプション設定をダンプ出力する /
1564  * Hack -- Dump option bits usage
1565  * @return なし
1566  */
1567 static void do_cmd_dump_options(void)
1568 {
1569         int  i, j;
1570         FILE *fff;
1571         char buf[1024];
1572         int  **exist;
1573
1574         /* Build the filename */
1575         path_build(buf, sizeof buf, ANGBAND_DIR_USER, "opt_info.txt");
1576
1577         /* File type is "TEXT" */
1578         FILE_TYPE(FILE_TYPE_TEXT);
1579
1580         /* Open the file */
1581         fff = my_fopen(buf, "a");
1582
1583         if (!fff)
1584         {
1585                 msg_format(_("ファイル %s を開けませんでした。", "Failed to open file %s."), buf);
1586                 msg_print(NULL);
1587                 return;
1588         }
1589
1590         /* Allocate the "exist" array (2-dimension) */
1591         C_MAKE(exist, NUM_O_SET, int *);
1592         C_MAKE(*exist, NUM_O_BIT * NUM_O_SET, int);
1593         for (i = 1; i < NUM_O_SET; i++) exist[i] = *exist + i * NUM_O_BIT;
1594
1595         /* Check for exist option bits */
1596         for (i = 0; option_info[i].o_desc; i++)
1597         {
1598                 const option_type *ot_ptr = &option_info[i];
1599                 if (ot_ptr->o_var) exist[ot_ptr->o_set][ot_ptr->o_bit] = i + 1;
1600         }
1601
1602         fprintf(fff, "[Option bits usage on Hengband %d.%d.%d]\n\n",
1603                 FAKE_VER_MAJOR - 10, FAKE_VER_MINOR, FAKE_VER_PATCH);
1604
1605         fputs("Set - Bit (Page) Option Name\n", fff);
1606         fputs("------------------------------------------------\n", fff);
1607         /* Dump option bits usage */
1608         for (i = 0; i < NUM_O_SET; i++)
1609         {
1610                 for (j = 0; j < NUM_O_BIT; j++)
1611                 {
1612                         if (exist[i][j])
1613                         {
1614                                 const option_type *ot_ptr = &option_info[exist[i][j] - 1];
1615                                 fprintf(fff, "  %d -  %02d (%4d) %s\n",
1616                                         i, j, ot_ptr->o_page, ot_ptr->o_text);
1617                         }
1618                         else
1619                         {
1620                                 fprintf(fff, "  %d -  %02d\n", i, j);
1621                         }
1622                 }
1623                 fputc('\n', fff);
1624         }
1625
1626         /* Free the "exist" array (2-dimension) */
1627         C_KILL(*exist, NUM_O_BIT * NUM_O_SET, int);
1628         C_KILL(exist, NUM_O_SET, int *);
1629         my_fclose(fff);
1630
1631         msg_format(_("オプションbit使用状況をファイル %s に書き出しました。", "Option bits usage dump saved to file %s."), buf);
1632 }
1633
1634
1635 #ifdef ALLOW_SPOILERS
1636
1637 /*
1638  * External function
1639  */
1640 extern void do_cmd_spoilers(void);
1641
1642 #endif /* ALLOW_SPOILERS */
1643
1644
1645
1646 /*
1647  * Hack -- declare external function
1648  */
1649 extern void do_cmd_debug(void);
1650
1651
1652
1653 /*!
1654  * @brief デバッグコマンドを選択する処理のメインルーチン /
1655  * Ask for and parse a "debug command"
1656  * The "command_arg" may have been set.
1657  * @return なし
1658  */
1659 void do_cmd_debug(void)
1660 {
1661         int     x, y;
1662         char    cmd;
1663
1664         /* Get a "debug command" */
1665         get_com("Debug Command: ", &cmd, FALSE);
1666
1667         /* Analyze the command */
1668         switch (cmd)
1669         {
1670         /* Nothing */
1671         case ESCAPE:
1672         case ' ':
1673         case '\n':
1674         case '\r':
1675                 break;
1676
1677 #ifdef ALLOW_SPOILERS
1678
1679         /* Hack -- Generate Spoilers */
1680         case '"':
1681                 do_cmd_spoilers();
1682                 break;
1683
1684 #endif /* ALLOW_SPOILERS */
1685
1686         /* Hack -- Help */
1687         case '?':
1688                 do_cmd_help();
1689                 break;
1690
1691         /* Cure all maladies */
1692         case 'a':
1693                 do_cmd_wiz_cure_all();
1694                 break;
1695
1696         /* Know alignment */
1697         case 'A':
1698                 msg_format("Your alignment is %d.", p_ptr->align);
1699                 break;
1700
1701         /* Teleport to target */
1702         case 'b':
1703                 do_cmd_wiz_bamf();
1704                 break;
1705
1706         case 'B':
1707                 update_gambling_monsters();
1708                 break;
1709
1710         /* Create any object */
1711         case 'c':
1712                 wiz_create_item();
1713                 break;
1714
1715         /* Create a named artifact */
1716         case 'C':
1717                 wiz_create_named_art();
1718                 break;
1719
1720         /* Detect everything */
1721         case 'd':
1722                 detect_all(DETECT_RAD_ALL * 3);
1723                 break;
1724
1725         /* Dimension_door */
1726         case 'D':
1727                 wiz_dimension_door();
1728                 break;
1729
1730         /* Edit character */
1731         case 'e':
1732                 do_cmd_wiz_change();
1733                 break;
1734
1735         /* Blue Mage Only */
1736         case 'E':
1737                 if (p_ptr->pclass == CLASS_BLUE_MAGE)
1738                 {
1739                         do_cmd_wiz_blue_mage();
1740                 }
1741                 break;
1742
1743         /* View item info */
1744         case 'f':
1745                 identify_fully(FALSE);
1746                 break;
1747
1748         /* Create desired feature */
1749         case 'F':
1750                 do_cmd_wiz_create_feature();
1751                 break;
1752
1753         /* Good Objects */
1754         case 'g':
1755                 if (command_arg <= 0) command_arg = 1;
1756                 acquirement(p_ptr->y, p_ptr->x, command_arg, FALSE, FALSE, TRUE);
1757                 break;
1758
1759         /* Hitpoint rerating */
1760         case 'h':
1761                 roll_hitdice(p_ptr, SPOP_DISPLAY_MES | SPOP_DEBUG);
1762                 break;
1763
1764         case 'H':
1765                 do_cmd_summon_horde();
1766                 break;
1767
1768         /* Identify */
1769         case 'i':
1770                 (void)ident_spell(FALSE);
1771                 break;
1772
1773         /* Go up or down in the dungeon */
1774         case 'j':
1775                 do_cmd_wiz_jump();
1776                 break;
1777
1778         /* Self-Knowledge */
1779         case 'k':
1780                 self_knowledge();
1781                 break;
1782
1783         /* Learn about objects */
1784         case 'l':
1785                 do_cmd_wiz_learn();
1786                 break;
1787
1788         /* Magic Mapping */
1789         case 'm':
1790                 map_area(DETECT_RAD_ALL * 3);
1791                 break;
1792
1793         /* Mutation */
1794         case 'M':
1795                 (void)gain_mutation(p_ptr, command_arg);
1796                 break;
1797
1798         /* Reset Class */
1799         case 'R':
1800                 (void)do_cmd_wiz_reset_class();
1801                 break;
1802
1803         /* Specific reward */
1804         case 'r':
1805                 (void)gain_level_reward(command_arg);
1806                 break;
1807
1808         /* Summon _friendly_ named monster */
1809         case 'N':
1810                 do_cmd_wiz_named_friendly(command_arg);
1811                 break;
1812
1813         /* Summon Named Monster */
1814         case 'n':
1815                 do_cmd_wiz_named(command_arg);
1816                 break;
1817
1818         /* Dump option bits usage */
1819         case 'O':
1820                 do_cmd_dump_options();
1821                 break;
1822
1823         /* Object playing routines */
1824         case 'o':
1825                 do_cmd_wiz_play();
1826                 break;
1827
1828         /* Phase Door */
1829         case 'p':
1830                 teleport_player(10, 0L);
1831                 break;
1832
1833         /* Take a Quests */
1834         case 'Q':
1835                 {
1836                         char ppp[30];
1837                         char tmp_val[5];
1838                         int tmp_int;
1839                         sprintf(ppp, "QuestID (0-%d):", max_q_idx - 1);
1840                         sprintf(tmp_val, "%d", 0);
1841
1842                         if (!get_string(ppp, tmp_val, 3)) return;
1843                         tmp_int = atoi(tmp_val);
1844
1845                         if(tmp_int < 0) break;
1846                         if(tmp_int >= max_q_idx) break;
1847
1848                         p_ptr->inside_quest = (QUEST_IDX)tmp_int;
1849                         process_dungeon_file("q_info.txt", 0, 0, 0, 0);
1850                         quest[tmp_int].status = QUEST_STATUS_TAKEN;
1851                         p_ptr->inside_quest = 0;
1852                 }
1853                 break;
1854
1855         /* Complete a Quest -KMW- */
1856         case 'q':
1857                 if(p_ptr->inside_quest)
1858                 {
1859                         if (quest[p_ptr->inside_quest].status == QUEST_STATUS_TAKEN)
1860                         {
1861                                 complete_quest(p_ptr->inside_quest);
1862                                 break;
1863                         }
1864                 }
1865                 else
1866                 {
1867                         msg_print("No current quest");
1868                         msg_print(NULL);
1869                 }
1870                 break;
1871
1872         /* Make every dungeon square "known" to test streamers -KMW- */
1873         case 'u':
1874                 for (y = 0; y < current_floor_ptr->height; y++)
1875                 {
1876                         for (x = 0; x < current_floor_ptr->width; x++)
1877                         {
1878                                 current_floor_ptr->grid_array[y][x].info |= (CAVE_GLOW | CAVE_MARK);
1879                         }
1880                 }
1881                 wiz_lite(FALSE);
1882                 break;
1883
1884         /* Summon Random Monster(s) */
1885         case 's':
1886                 if (command_arg <= 0) command_arg = 1;
1887                 do_cmd_wiz_summon(command_arg);
1888                 break;
1889
1890         /* Special(Random Artifact) Objects */
1891         case 'S':
1892                 if (command_arg <= 0) command_arg = 1;
1893                 acquirement(p_ptr->y, p_ptr->x, command_arg, TRUE, TRUE, TRUE);
1894                 break;
1895
1896         /* Teleport */
1897         case 't':
1898                 teleport_player(100, 0L);
1899                 break;
1900
1901         /* Game Time Setting */
1902         case 'T':
1903                 set_gametime();
1904                 break;
1905
1906
1907         /* Very Good Objects */
1908         case 'v':
1909                 if (command_arg <= 0) command_arg = 1;
1910                 acquirement(p_ptr->y, p_ptr->x, command_arg, TRUE, FALSE, TRUE);
1911                 break;
1912
1913         /* Wizard Light the Level */
1914         case 'w':
1915                 wiz_lite((bool)(p_ptr->pclass == CLASS_NINJA));
1916                 break;
1917
1918         /* Increase Experience */
1919         case 'x':
1920                 gain_exp(command_arg ? command_arg : (p_ptr->exp + 1));
1921                 break;
1922
1923         /* Zap Monsters (Genocide) */
1924         case 'z':
1925                 do_cmd_wiz_zap();
1926                 break;
1927
1928         /* Zap Monsters (Omnicide) */
1929         case 'Z':
1930                 do_cmd_wiz_zap_all();
1931                 break;
1932
1933         /* Hack -- whatever I desire */
1934         case '_':
1935                 probing();
1936                 break;
1937
1938         /* For temporary test. */
1939         case 'X':
1940         {
1941                 INVENTORY_IDX i;
1942                 for(i = INVEN_TOTAL - 1; i >= 0; i--)
1943                 {
1944                         if(p_ptr->inventory_list[i].k_idx) inven_drop(i, 999);
1945                 }
1946                 player_outfit();
1947                 break;
1948         }
1949
1950         case 'V':
1951                 do_cmd_wiz_reset_class();
1952                 break;
1953
1954         /* Not a Wizard Command */
1955         default:
1956                 msg_print("That is not a valid debug command.");
1957                 break;
1958         }
1959 }
1960
1961
1962 #else
1963
1964 #ifdef MACINTOSH
1965 static int i = 0;
1966 #endif
1967
1968 #endif
1969