OSDN Git Service

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