OSDN Git Service

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