OSDN Git Service

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