OSDN Git Service

b2f6636c7c96ca3f06e548a2dfc63bed6dd472c7
[hengbandforosx/hengbandosx.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_real(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, AM_NO_FIXED_ART | AM_GOOD | AM_GREAT | AM_CURSED);
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, AM_NO_FIXED_ART | AM_GOOD | AM_CURSED);
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, AM_NO_FIXED_ART);
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, AM_NO_FIXED_ART | AM_GOOD);
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, AM_NO_FIXED_ART | AM_GOOD | AM_GREAT);
949                                 break;
950                         }
951                         /* Apply special magic, but first clear object */
952                         case 's': case 'S':
953                         {
954                                 object_prep(q_ptr, o_ptr->k_idx);
955                                 apply_magic(q_ptr, dun_level, AM_GOOD | AM_GREAT | AM_SPECIAL);
956
957                                 /* Failed to create artifact; make a random one */
958                                 if (!artifact_p(q_ptr) && !q_ptr->art_name) create_artifact(q_ptr, FALSE);
959                                 break;
960                         }
961                 }
962                 q_ptr->iy = o_ptr->iy;
963                 q_ptr->ix = o_ptr->ix;
964                 q_ptr->next_o_idx = o_ptr->next_o_idx;
965                 q_ptr->marked = o_ptr->marked;
966         }
967
968
969         /* Notice change */
970         if (changed)
971         {
972                 /* Apply changes */
973                 object_copy(o_ptr, q_ptr);
974
975                 /* Recalculate bonuses */
976                 p_ptr->update |= (PU_BONUS);
977
978                 /* Combine / Reorder the pack (later) */
979                 p_ptr->notice |= (PN_COMBINE | PN_REORDER);
980
981                 /* Window stuff */
982                 p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_SPELL | PW_PLAYER);
983         }
984 }
985
986
987
988 /*
989  * Try to create an item again. Output some statistics.    -Bernd-
990  *
991  * The statistics are correct now.  We acquire a clean grid, and then
992  * repeatedly place an object in this grid, copying it into an item
993  * holder, and then deleting the object.  We fiddle with the artifact
994  * counter flags to prevent weirdness.  We use the items to collect
995  * statistics on item creation relative to the initial item.
996  */
997 static void wiz_statistics(object_type *o_ptr)
998 {
999         u32b i, matches, better, worse, other, correct;
1000
1001         u32b test_roll = 1000000;
1002
1003         char ch;
1004         cptr quality;
1005
1006         u32b mode;
1007
1008         object_type forge;
1009         object_type     *q_ptr;
1010
1011         cptr q = "Rolls: %ld  Correct: %ld  Matches: %ld  Better: %ld  Worse: %ld  Other: %ld";
1012
1013         cptr p = "Enter number of items to roll: ";
1014         char tmp_val[80];
1015
1016
1017         /* XXX XXX XXX Mega-Hack -- allow multiple artifacts */
1018         if (artifact_p(o_ptr)) a_info[o_ptr->name1].cur_num = 0;
1019
1020
1021         /* Interact */
1022         while (TRUE)
1023         {
1024                 cptr pmt = "Roll for [n]ormal, [g]ood, or [e]xcellent treasure? ";
1025
1026                 /* Display item */
1027                 wiz_display_item(o_ptr);
1028
1029                 /* Get choices */
1030                 if (!get_com(pmt, &ch, FALSE)) break;
1031
1032                 if (ch == 'n' || ch == 'N')
1033                 {
1034                         mode = 0L;
1035                         quality = "normal";
1036                 }
1037                 else if (ch == 'g' || ch == 'G')
1038                 {
1039                         mode = AM_GOOD;
1040                         quality = "good";
1041                 }
1042                 else if (ch == 'e' || ch == 'E')
1043                 {
1044                         mode = AM_GOOD | AM_GREAT;
1045                         quality = "excellent";
1046                 }
1047                 else
1048                 {
1049                         break;
1050                 }
1051
1052                 sprintf(tmp_val, "%ld", test_roll);
1053                 if (get_string(p, tmp_val, 10)) test_roll = atol(tmp_val);
1054                 test_roll = MAX(1, test_roll);
1055
1056                 /* Let us know what we are doing */
1057                 msg_format("Creating a lot of %s items. Base level = %d.",
1058                                           quality, dun_level);
1059                 msg_print(NULL);
1060
1061                 /* Set counters to zero */
1062                 correct = matches = better = worse = other = 0;
1063
1064                 /* Let's rock and roll */
1065                 for (i = 0; i <= test_roll; i++)
1066                 {
1067                         /* Output every few rolls */
1068                         if ((i < 100) || (i % 100 == 0))
1069                         {
1070                                 /* Do not wait */
1071                                 inkey_scan = TRUE;
1072
1073                                 /* Allow interupt */
1074                                 if (inkey())
1075                                 {
1076                                         /* Flush */
1077                                         flush();
1078
1079                                         /* Stop rolling */
1080                                         break;
1081                                 }
1082
1083                                 /* Dump the stats */
1084                                 prt(format(q, i, correct, matches, better, worse, other), 0, 0);
1085                                 Term_fresh();
1086                         }
1087
1088
1089                         /* Get local object */
1090                         q_ptr = &forge;
1091
1092                         /* Wipe the object */
1093                         object_wipe(q_ptr);
1094
1095                         /* Create an object */
1096                         make_object(q_ptr, mode);
1097
1098
1099                         /* XXX XXX XXX Mega-Hack -- allow multiple artifacts */
1100                         if (artifact_p(q_ptr)) a_info[q_ptr->name1].cur_num = 0;
1101
1102
1103                         /* Test for the same tval and sval. */
1104                         if ((o_ptr->tval) != (q_ptr->tval)) continue;
1105                         if ((o_ptr->sval) != (q_ptr->sval)) continue;
1106
1107                         /* One more correct item */
1108                         correct++;
1109
1110                         /* Check for match */
1111                         if ((q_ptr->pval == o_ptr->pval) &&
1112                                  (q_ptr->to_a == o_ptr->to_a) &&
1113                                  (q_ptr->to_h == o_ptr->to_h) &&
1114                                  (q_ptr->to_d == o_ptr->to_d) &&
1115                                  (q_ptr->name1 == o_ptr->name1))
1116                         {
1117                                 matches++;
1118                         }
1119
1120                         /* Check for better */
1121                         else if ((q_ptr->pval >= o_ptr->pval) &&
1122                                                 (q_ptr->to_a >= o_ptr->to_a) &&
1123                                                 (q_ptr->to_h >= o_ptr->to_h) &&
1124                                                 (q_ptr->to_d >= o_ptr->to_d))
1125                         {
1126                                 better++;
1127                         }
1128
1129                         /* Check for worse */
1130                         else if ((q_ptr->pval <= o_ptr->pval) &&
1131                                                 (q_ptr->to_a <= o_ptr->to_a) &&
1132                                                 (q_ptr->to_h <= o_ptr->to_h) &&
1133                                                 (q_ptr->to_d <= o_ptr->to_d))
1134                         {
1135                                 worse++;
1136                         }
1137
1138                         /* Assume different */
1139                         else
1140                         {
1141                                 other++;
1142                         }
1143                 }
1144
1145                 /* Final dump */
1146                 msg_format(q, i, correct, matches, better, worse, other);
1147                 msg_print(NULL);
1148         }
1149
1150
1151         /* Hack -- Normally only make a single artifact */
1152         if (artifact_p(o_ptr)) a_info[o_ptr->name1].cur_num = 1;
1153 }
1154
1155
1156 /*
1157  * Change the quantity of a the item
1158  */
1159 static void wiz_quantity_item(object_type *o_ptr)
1160 {
1161         int         tmp_int, tmp_qnt;
1162
1163         char        tmp_val[100];
1164
1165
1166         /* Never duplicate artifacts */
1167         if (artifact_p(o_ptr) || o_ptr->art_name) return;
1168
1169         /* Store old quantity. -LM- */
1170         tmp_qnt = o_ptr->number;
1171
1172         /* Default */
1173         sprintf(tmp_val, "%d", o_ptr->number);
1174
1175         /* Query */
1176         if (get_string("Quantity: ", tmp_val, 2))
1177         {
1178                 /* Extract */
1179                 tmp_int = atoi(tmp_val);
1180
1181                 /* Paranoia */
1182                 if (tmp_int < 1) tmp_int = 1;
1183                 if (tmp_int > 99) tmp_int = 99;
1184
1185                 /* Accept modifications */
1186                 o_ptr->number = tmp_int;
1187         }
1188
1189         if (o_ptr->tval == TV_ROD)
1190         {
1191                 o_ptr->pval = o_ptr->pval * o_ptr->number / tmp_qnt;
1192         }
1193 }
1194
1195 /* debug command for blue mage */
1196 static void do_cmd_wiz_blue_mage(void)
1197 {
1198
1199         int                             i = 0;
1200         int                             j = 0;
1201         s32b            f4 = 0, f5 = 0, f6 = 0; 
1202
1203         for (j=1; j<6; j++)
1204         {
1205
1206                 set_rf_masks(&f4, &f5, &f6, j);
1207
1208                 for (i = 0; i < 32; i++)
1209                 {
1210                         if ((0x00000001 << i) & f4) p_ptr->magic_num2[i] = 1;
1211                 }
1212                 for (; i < 64; i++)
1213                 {
1214                         if ((0x00000001 << (i - 32)) & f5) p_ptr->magic_num2[i] = 1;
1215                 }
1216                 for (; i < 96; i++)
1217                 {
1218                         if ((0x00000001 << (i - 64)) & f6) p_ptr->magic_num2[i] = 1;
1219                 }
1220         }
1221 }
1222
1223
1224 /*
1225  * Play with an item. Options include:
1226  *   - Output statistics (via wiz_roll_item)
1227  *   - Reroll item (via wiz_reroll_item)
1228  *   - Change properties (via wiz_tweak_item)
1229  *   - Change the number of items (via wiz_quantity_item)
1230  */
1231 static void do_cmd_wiz_play(void)
1232 {
1233         int item;
1234
1235         object_type     forge;
1236         object_type *q_ptr;
1237
1238         object_type *o_ptr;
1239
1240         char ch;
1241
1242         bool changed;
1243
1244         cptr q, s;
1245
1246         item_tester_no_ryoute = TRUE;
1247         /* Get an item */
1248         q = "Play with which object? ";
1249         s = "You have nothing to play with.";
1250         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return;
1251
1252         /* Get the item (in the pack) */
1253         if (item >= 0)
1254         {
1255                 o_ptr = &inventory[item];
1256         }
1257
1258         /* Get the item (on the floor) */
1259         else
1260         {
1261                 o_ptr = &o_list[0 - item];
1262         }
1263         
1264         /* The item was not changed */
1265         changed = FALSE;
1266
1267
1268         /* Save the screen */
1269         screen_save();
1270
1271
1272         /* Get local object */
1273         q_ptr = &forge;
1274
1275         /* Copy object */
1276         object_copy(q_ptr, o_ptr);
1277
1278
1279         /* The main loop */
1280         while (TRUE)
1281         {
1282                 /* Display the item */
1283                 wiz_display_item(q_ptr);
1284
1285                 /* Get choice */
1286                 if (!get_com("[a]ccept [s]tatistics [r]eroll [t]weak [q]uantity? ", &ch, FALSE))
1287                 {
1288                         changed = FALSE;
1289                         break;
1290                 }
1291
1292                 if (ch == 'A' || ch == 'a')
1293                 {
1294                         changed = TRUE;
1295                         break;
1296                 }
1297
1298                 if (ch == 's' || ch == 'S')
1299                 {
1300                         wiz_statistics(q_ptr);
1301                 }
1302
1303                 if (ch == 'r' || ch == 'r')
1304                 {
1305                         wiz_reroll_item(q_ptr);
1306                 }
1307
1308                 if (ch == 't' || ch == 'T')
1309                 {
1310                         wiz_tweak_item(q_ptr);
1311                 }
1312
1313                 if (ch == 'q' || ch == 'Q')
1314                 {
1315                         wiz_quantity_item(q_ptr);
1316                 }
1317         }
1318
1319
1320         /* Restore the screen */
1321         screen_load();
1322
1323
1324         /* Accept change */
1325         if (changed)
1326         {
1327                 /* Message */
1328                 msg_print("Changes accepted.");
1329
1330                 /* Recalcurate object's weight */
1331                 if (item >= 0)
1332                 {
1333                         p_ptr->total_weight += (q_ptr->weight * q_ptr->number)
1334                                 - (o_ptr->weight * o_ptr->number);
1335                 }
1336
1337                 /* Change */
1338                 object_copy(o_ptr, q_ptr);
1339
1340
1341                 /* Recalculate bonuses */
1342                 p_ptr->update |= (PU_BONUS);
1343
1344                 /* Combine / Reorder the pack (later) */
1345                 p_ptr->notice |= (PN_COMBINE | PN_REORDER);
1346
1347                 /* Window stuff */
1348                 p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_SPELL | PW_PLAYER);
1349         }
1350
1351         /* Ignore change */
1352         else
1353         {
1354                 msg_print("Changes ignored.");
1355         }
1356 }
1357
1358
1359 /*
1360  * Wizard routine for creating objects          -RAK-
1361  * Heavily modified to allow magification and artifactification  -Bernd-
1362  *
1363  * Note that wizards cannot create objects on top of other objects.
1364  *
1365  * Hack -- this routine always makes a "dungeon object", and applies
1366  * magic to it, and attempts to decline cursed items.
1367  */
1368 static void wiz_create_item(void)
1369 {
1370         object_type     forge;
1371         object_type *q_ptr;
1372
1373         int k_idx;
1374
1375
1376         /* Save the screen */
1377         screen_save();
1378
1379         /* Get object base type */
1380         k_idx = wiz_create_itemtype();
1381
1382         /* Restore the screen */
1383         screen_load();
1384
1385
1386         /* Return if failed */
1387         if (!k_idx) return;
1388
1389         if (k_info[k_idx].gen_flags & TRG_INSTA_ART)
1390         {
1391                 int i;
1392
1393                 /* Artifactify */
1394                 for (i = 1; i < max_a_idx; i++)
1395                 {
1396                         /* Ignore incorrect tval */
1397                         if (a_info[i].tval != k_info[k_idx].tval) continue;
1398
1399                         /* Ignore incorrect sval */
1400                         if (a_info[i].sval != k_info[k_idx].sval) continue;
1401
1402                         /* Create this artifact */
1403                         create_named_art(i, py, px);
1404
1405                         /* All done */
1406                         msg_print("Allocated(INSTA_ART).");
1407
1408                         return;
1409                 }
1410         }
1411
1412         /* Get local object */
1413         q_ptr = &forge;
1414
1415         /* Create the item */
1416         object_prep(q_ptr, k_idx);
1417
1418         /* Apply magic */
1419         apply_magic(q_ptr, dun_level, AM_NO_FIXED_ART);
1420
1421         /* Drop the object from heaven */
1422         (void)drop_near(q_ptr, -1, py, px);
1423
1424         /* All done */
1425         msg_print("Allocated.");
1426 }
1427
1428
1429 /*
1430  * Cure everything instantly
1431  */
1432 static void do_cmd_wiz_cure_all(void)
1433 {
1434         /* Restore stats */
1435         (void)res_stat(A_STR);
1436         (void)res_stat(A_INT);
1437         (void)res_stat(A_WIS);
1438         (void)res_stat(A_CON);
1439         (void)res_stat(A_DEX);
1440         (void)res_stat(A_CHR);
1441
1442         /* Restore the level */
1443         (void)restore_level();
1444
1445         /* Heal the player */
1446         p_ptr->chp = p_ptr->mhp;
1447         p_ptr->chp_frac = 0;
1448
1449         /* Restore mana */
1450         if (p_ptr->csp < p_ptr->msp)
1451         {
1452                 p_ptr->csp = p_ptr->msp;
1453                 p_ptr->csp_frac = 0;
1454         }
1455
1456         /* Cure stuff */
1457         (void)set_blind(0);
1458         (void)set_confused(0);
1459         (void)set_poisoned(0);
1460         (void)set_afraid(0);
1461         (void)set_paralyzed(0);
1462         (void)set_image(0);
1463         (void)set_stun(0);
1464         (void)set_cut(0);
1465         (void)set_slow(0, TRUE);
1466
1467         /* No longer hungry */
1468         (void)set_food(PY_FOOD_MAX - 1);
1469
1470         /* Redraw everything */
1471         do_cmd_redraw();
1472 }
1473
1474
1475 /*
1476  * Go to any level
1477  */
1478 static void do_cmd_wiz_jump(void)
1479 {
1480         /* Ask for level */
1481         if (command_arg <= 0)
1482         {
1483                 char    ppp[80];
1484
1485                 char    tmp_val[160];
1486                 int             tmp_dungeon_type;
1487
1488                 /* Prompt */
1489                 sprintf(ppp, "Jump which dungeon : ");
1490
1491                 /* Default */
1492                 sprintf(tmp_val, "%d", dungeon_type);
1493
1494                 /* Ask for a level */
1495                 if (!get_string(ppp, tmp_val, 2)) return;
1496
1497                 tmp_dungeon_type = atoi(tmp_val);
1498                 if (!d_info[tmp_dungeon_type].maxdepth || (tmp_dungeon_type > max_d_idx)) tmp_dungeon_type = DUNGEON_ANGBAND;
1499
1500                 /* Prompt */
1501                 sprintf(ppp, "Jump to level (0, %d-%d): ", d_info[tmp_dungeon_type].mindepth, d_info[tmp_dungeon_type].maxdepth);
1502
1503                 /* Default */
1504                 sprintf(tmp_val, "%d", dun_level);
1505
1506                 /* Ask for a level */
1507                 if (!get_string(ppp, tmp_val, 10)) return;
1508
1509                 /* Extract request */
1510                 command_arg = atoi(tmp_val);
1511
1512                 dungeon_type = tmp_dungeon_type;
1513         }
1514
1515         /* Paranoia */
1516         if (command_arg < d_info[dungeon_type].mindepth) command_arg = 0;
1517
1518         /* Paranoia */
1519         if (command_arg > d_info[dungeon_type].maxdepth) command_arg = d_info[dungeon_type].maxdepth;
1520
1521         /* Accept request */
1522         msg_format("You jump to dungeon level %d.", command_arg);
1523
1524         if (autosave_l) do_cmd_save_game(TRUE);
1525
1526         /* Change level */
1527         dun_level = command_arg;
1528
1529         prepare_change_floor_mode(CFM_RAND_PLACE | CFM_CLEAR_ALL);
1530
1531         if (!dun_level) dungeon_type = 0;
1532         p_ptr->inside_arena = FALSE;
1533         p_ptr->wild_mode = FALSE;
1534
1535         leave_quest_check();
1536
1537         if (record_stair) do_cmd_write_nikki(NIKKI_WIZ_TELE,0,NULL);
1538
1539         p_ptr->inside_quest = 0;
1540         p_ptr->leftbldg = FALSE;
1541         energy_use = 0;
1542
1543         /* Prevent energy_need from being too lower than 0 */
1544         p_ptr->energy_need = 0;
1545
1546         /* Leaving */
1547         p_ptr->leaving = TRUE;
1548 }
1549
1550
1551 /*
1552  * Become aware of a lot of objects
1553  */
1554 static void do_cmd_wiz_learn(void)
1555 {
1556         int i;
1557
1558         object_type forge;
1559         object_type *q_ptr;
1560
1561         /* Scan every object */
1562         for (i = 1; i < max_k_idx; i++)
1563         {
1564                 object_kind *k_ptr = &k_info[i];
1565
1566                 /* Induce awareness */
1567                 if (k_ptr->level <= command_arg)
1568                 {
1569                         /* Get local object */
1570                         q_ptr = &forge;
1571
1572                         /* Prepare object */
1573                         object_prep(q_ptr, i);
1574
1575                         /* Awareness */
1576                         object_aware(q_ptr);
1577                 }
1578         }
1579 }
1580
1581
1582 /*
1583  * Summon some creatures
1584  */
1585 static void do_cmd_wiz_summon(int num)
1586 {
1587         int i;
1588
1589         for (i = 0; i < num; i++)
1590         {
1591                 (void)summon_specific(0, py, px, dun_level, 0, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE));
1592         }
1593 }
1594
1595
1596 /*
1597  * Summon a creature of the specified type
1598  *
1599  * XXX XXX XXX This function is rather dangerous
1600  */
1601 static void do_cmd_wiz_named(int r_idx)
1602 {
1603         int i, x, y;
1604
1605         /* Paranoia */
1606         /* if (!r_idx) return; */
1607
1608         /* Prevent illegal monsters */
1609         if (r_idx >= max_r_idx) return;
1610
1611         /* Try 10 times */
1612         for (i = 0; i < 10; i++)
1613         {
1614                 int d = 1;
1615
1616                 /* Pick a location */
1617                 scatter(&y, &x, py, px, d, 0);
1618
1619                 /* Require empty grids */
1620                 if (!cave_empty_bold(y, x)) continue;
1621
1622                 /* Place it (allow groups) */
1623                 if (place_monster_aux(0, y, x, r_idx, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP))) break;
1624         }
1625 }
1626
1627
1628 /*
1629  * Summon a creature of the specified type
1630  *
1631  * XXX XXX XXX This function is rather dangerous
1632  */
1633 static void do_cmd_wiz_named_friendly(int r_idx)
1634 {
1635         (void) summon_named_creature(0, py, px, r_idx, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP | PM_FORCE_PET));
1636 }
1637
1638
1639
1640 /*
1641  * Hack -- Delete all nearby monsters
1642  */
1643 static void do_cmd_wiz_zap(void)
1644 {
1645         int i;
1646
1647
1648         /* Genocide everyone nearby */
1649         for (i = 1; i < m_max; i++)
1650         {
1651                 monster_type *m_ptr = &m_list[i];
1652
1653                 /* Paranoia -- Skip dead monsters */
1654                 if (!m_ptr->r_idx) continue;
1655
1656                 /* Delete nearby monsters */
1657                 if (m_ptr->cdis <= MAX_SIGHT)
1658                 {
1659                         if (i == p_ptr->riding)
1660                         {
1661                                 rakuba(-1, FALSE);
1662                                 p_ptr->redraw |= (PR_EXTRA);
1663                         }
1664                         delete_monster_idx(i);
1665                 }
1666         }
1667 }
1668
1669
1670 /*
1671  * Hack -- Delete all monsters
1672  */
1673 static void do_cmd_wiz_zap_all(void)
1674 {
1675         int i;
1676
1677         /* Genocide everyone */
1678         for (i = 1; i < m_max; i++)
1679         {
1680                 monster_type *m_ptr = &m_list[i];
1681
1682                 /* Paranoia -- Skip dead monsters */
1683                 if (!m_ptr->r_idx) continue;
1684
1685                 if (i == p_ptr->riding)
1686                 {
1687                         rakuba(-1, FALSE);
1688                         p_ptr->redraw |= (PR_EXTRA);
1689                 }
1690
1691                 /* Delete this monster */
1692                 delete_monster_idx(i);
1693         }
1694 }
1695
1696
1697 #define NUM_O_SET 8
1698 #define NUM_O_BIT 32
1699
1700 /*
1701  * Hack -- Dump option bits usage
1702  */
1703 static void do_cmd_dump_options(void)
1704 {
1705         int  i, j;
1706         FILE *fff;
1707         char buf[1024];
1708         int  **exist;
1709
1710         /* Build the filename */
1711         path_build(buf, sizeof buf, ANGBAND_DIR_USER, "opt_info.txt");
1712
1713         /* File type is "TEXT" */
1714         FILE_TYPE(FILE_TYPE_TEXT);
1715
1716         /* Open the file */
1717         fff = my_fopen(buf, "a");
1718
1719         /* Oops */
1720         if (!fff)
1721         {
1722 #ifdef JP
1723                 msg_format("¥Õ¥¡¥¤¥ë %s ¤ò³«¤±¤Þ¤»¤ó¤Ç¤·¤¿¡£", buf);
1724 #else
1725                 msg_format("Failed to open file %s.", buf);
1726 #endif
1727                 msg_print(NULL);
1728                 return;
1729         }
1730
1731         /* Allocate the "exist" array (2-dimension) */
1732         C_MAKE(exist, NUM_O_SET, int *);
1733         C_MAKE(*exist, NUM_O_BIT * NUM_O_SET, int);
1734         for (i = 1; i < NUM_O_SET; i++) exist[i] = *exist + i * NUM_O_BIT;
1735
1736         /* Check for exist option bits */
1737         for (i = 0; option_info[i].o_desc; i++)
1738         {
1739                 option_type *ot_ptr = &option_info[i];
1740                 if (ot_ptr->o_var) exist[ot_ptr->o_set][ot_ptr->o_bit] = i + 1;
1741         }
1742
1743         fprintf(fff, "[Option bits usage on Hengband %d.%d.%d]\n\n",
1744                 FAKE_VER_MAJOR - 10, FAKE_VER_MINOR, FAKE_VER_PATCH);
1745
1746         fputs("Set - Bit (Page) Option Name\n", fff);
1747         fputs("------------------------------------------------\n", fff);
1748         /* Dump option bits usage */
1749         for (i = 0; i < NUM_O_SET; i++)
1750         {
1751                 for (j = 0; j < NUM_O_BIT; j++)
1752                 {
1753                         if (exist[i][j])
1754                         {
1755                                 option_type *ot_ptr = &option_info[exist[i][j] - 1];
1756                                 fprintf(fff, "  %d -  %02d (%4d) %s\n",
1757                                         i, j, ot_ptr->o_page, ot_ptr->o_text);
1758                         }
1759                         else
1760                         {
1761                                 fprintf(fff, "  %d -  %02d\n", i, j);
1762                         }
1763                 }
1764                 fputc('\n', fff);
1765         }
1766
1767         /* Free the "exist" array (2-dimension) */
1768         C_KILL(*exist, NUM_O_BIT * NUM_O_SET, int);
1769         C_KILL(exist, NUM_O_SET, int *);
1770
1771         /* Close it */
1772         my_fclose(fff);
1773
1774 #ifdef JP
1775         msg_format("¥ª¥×¥·¥ç¥óbit»ÈÍѾõ¶·¤ò¥Õ¥¡¥¤¥ë %s ¤Ë½ñ¤­½Ð¤·¤Þ¤·¤¿¡£", buf);
1776 #else
1777         msg_format("Option bits usage dump saved to file %s.", buf);
1778 #endif
1779 }
1780
1781
1782 #ifdef ALLOW_SPOILERS
1783
1784 /*
1785  * External function
1786  */
1787 extern void do_cmd_spoilers(void);
1788
1789 #endif /* ALLOW_SPOILERS */
1790
1791
1792
1793 /*
1794  * Hack -- declare external function
1795  */
1796 extern void do_cmd_debug(void);
1797
1798
1799
1800 /*
1801  * Ask for and parse a "debug command"
1802  * The "command_arg" may have been set.
1803  */
1804 void do_cmd_debug(void)
1805 {
1806         int     x, y;
1807         char    cmd;
1808
1809
1810         /* Get a "debug command" */
1811         get_com("Debug Command: ", &cmd, FALSE);
1812
1813         /* Analyze the command */
1814         switch (cmd)
1815         {
1816         /* Nothing */
1817         case ESCAPE:
1818         case ' ':
1819         case '\n':
1820         case '\r':
1821                 break;
1822
1823 #ifdef ALLOW_SPOILERS
1824
1825         /* Hack -- Generate Spoilers */
1826         case '"':
1827                 do_cmd_spoilers();
1828                 break;
1829
1830 #endif /* ALLOW_SPOILERS */
1831
1832         /* Hack -- Help */
1833         case '?':
1834                 do_cmd_help();
1835                 break;
1836
1837         /* Cure all maladies */
1838         case 'a':
1839                 do_cmd_wiz_cure_all();
1840                 break;
1841
1842         /* Know alignment */
1843         case 'A':
1844                 msg_format("Your alignment is %d.", p_ptr->align);
1845                 break;
1846
1847         /* Teleport to target */
1848         case 'b':
1849                 do_cmd_wiz_bamf();
1850                 break;
1851
1852         case 'B':
1853                 battle_monsters();
1854                 break;
1855
1856         /* Create any object */
1857         case 'c':
1858                 wiz_create_item();
1859                 break;
1860
1861         /* Create a named artifact */
1862         case 'C':
1863                 wiz_create_named_art(command_arg);
1864                 break;
1865
1866         /* Detect everything */
1867         case 'd':
1868                 detect_all(DETECT_RAD_ALL*3);
1869                 break;
1870
1871         /* Dimension_door */
1872         case 'D':
1873                 wiz_dimension_door();
1874                 break;
1875
1876         /* Edit character */
1877         case 'e':
1878                 do_cmd_wiz_change();
1879                 break;
1880
1881         /* Blue Mage Only */
1882         case 'E':
1883                 if (p_ptr->pclass == CLASS_BLUE_MAGE)
1884                 {
1885                         do_cmd_wiz_blue_mage();
1886                 }
1887                 break;
1888
1889         /* View item info */
1890         case 'f':
1891                 identify_fully(FALSE);
1892                 break;
1893
1894         /* Good Objects */
1895         case 'g':
1896                 if (command_arg <= 0) command_arg = 1;
1897                 acquirement(py, px, command_arg, FALSE, TRUE);
1898                 break;
1899
1900         /* Hitpoint rerating */
1901         case 'h':
1902                 do_cmd_rerate(TRUE);
1903                 break;
1904
1905 #ifdef MONSTER_HORDES
1906         case 'H':
1907                 do_cmd_summon_horde();
1908                 break;
1909 #endif /* MONSTER_HORDES */
1910
1911         /* Identify */
1912         case 'i':
1913                 (void)ident_spell(FALSE);
1914                 break;
1915
1916         /* Go up or down in the dungeon */
1917         case 'j':
1918                 do_cmd_wiz_jump();
1919                 break;
1920
1921         /* Self-Knowledge */
1922         case 'k':
1923                 self_knowledge();
1924                 break;
1925
1926         /* Learn about objects */
1927         case 'l':
1928                 do_cmd_wiz_learn();
1929                 break;
1930
1931         /* Magic Mapping */
1932         case 'm':
1933                 map_area(DETECT_RAD_ALL);
1934                 break;
1935
1936         /* Mutation */
1937         case 'M':
1938                 (void)gain_random_mutation(command_arg);
1939                 break;
1940
1941         /* Specific reward */
1942         case 'r':
1943                 (void)gain_level_reward(command_arg);
1944                 break;
1945
1946         /* Summon _friendly_ named monster */
1947         case 'N':
1948                 do_cmd_wiz_named_friendly(command_arg);
1949                 break;
1950
1951         /* Summon Named Monster */
1952         case 'n':
1953                 do_cmd_wiz_named(command_arg);
1954                 break;
1955
1956         /* Dump option bits usage */
1957         case 'O':
1958                 do_cmd_dump_options();
1959                 break;
1960
1961         /* Object playing routines */
1962         case 'o':
1963                 do_cmd_wiz_play();
1964                 break;
1965
1966         /* Phase Door */
1967         case 'p':
1968                 teleport_player(10);
1969                 break;
1970
1971 #if 0
1972         /* Complete a Quest -KMW- */
1973         case 'q':
1974                 for (i = 0; i < max_quests; i++)
1975                 {
1976                         if (p_ptr->quest[i].status == QUEST_STATUS_TAKEN)
1977                         {
1978                                 p_ptr->quest[i].status++;
1979                                 msg_print("Completed Quest");
1980                                 msg_print(NULL);
1981                                 break;
1982                         }
1983                 }
1984                 if (i == max_quests)
1985                 {
1986                         msg_print("No current quest");
1987                         msg_print(NULL);
1988                 }
1989                 break;
1990 #endif
1991
1992         /* Make every dungeon square "known" to test streamers -KMW- */
1993         case 'u':
1994                 for (y = 0; y < cur_hgt; y++)
1995                 {
1996                         for (x = 0; x < cur_wid; x++)
1997                         {
1998                                 cave[y][x].info |= (CAVE_GLOW | CAVE_MARK);
1999                         }
2000                 }
2001                 wiz_lite(FALSE);
2002                 break;
2003
2004         /* Summon Random Monster(s) */
2005         case 's':
2006                 if (command_arg <= 0) command_arg = 1;
2007                 do_cmd_wiz_summon(command_arg);
2008                 break;
2009
2010         /* Teleport */
2011         case 't':
2012                 teleport_player(100);
2013                 break;
2014
2015         /* Very Good Objects */
2016         case 'v':
2017                 if (command_arg <= 0) command_arg = 1;
2018                 acquirement(py, px, command_arg, TRUE, TRUE);
2019                 break;
2020
2021         /* Wizard Light the Level */
2022         case 'w':
2023                 wiz_lite((bool)(p_ptr->pclass == CLASS_NINJA));
2024                 break;
2025
2026         /* Increase Experience */
2027         case 'x':
2028                 gain_exp(command_arg ? command_arg : (p_ptr->exp + 1));
2029                 break;
2030
2031         /* Zap Monsters (Genocide) */
2032         case 'z':
2033                 do_cmd_wiz_zap();
2034                 break;
2035
2036         /* Zap Monsters (Omnicide) */
2037         case 'Z':
2038                 do_cmd_wiz_zap_all();
2039                 break;
2040
2041         /* Hack -- whatever I desire */
2042         case '_':
2043                 do_cmd_wiz_hack_ben();
2044                 break;
2045
2046         /* Not a Wizard Command */
2047         default:
2048                 msg_print("That is not a valid debug command.");
2049                 break;
2050         }
2051 }
2052
2053
2054 #else
2055
2056 #ifdef MACINTOSH
2057 static int i = 0;
2058 #endif
2059
2060 #endif
2061