OSDN Git Service

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