OSDN Git Service

プレイヤーのテレポートに受動テレポートモードを与えた. 主に自分の意志
[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, FALSE, FALSE);
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         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, FALSE, FALSE);
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, get_object_level(o_ptr),
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_ENCHANT_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 (artifact_p(o_ptr) || o_ptr->art_name) 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 (artifact_p(o_ptr) || o_ptr->art_name) 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 (artifact_p(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 (artifact_p(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 (!artifact_p(q_ptr) && !q_ptr->art_name) 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 (artifact_p(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 (artifact_p(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 (artifact_p(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 (artifact_p(o_ptr) || o_ptr->art_name) 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                         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         p_ptr->chp = p_ptr->mhp;
1437         p_ptr->chp_frac = 0;
1438
1439         /* Restore mana */
1440         if (p_ptr->csp < p_ptr->msp)
1441         {
1442                 p_ptr->csp = p_ptr->msp;
1443                 p_ptr->csp_frac = 0;
1444         }
1445
1446         /* Cure stuff */
1447         (void)set_blind(0);
1448         (void)set_confused(0);
1449         (void)set_poisoned(0);
1450         (void)set_afraid(0);
1451         (void)set_paralyzed(0);
1452         (void)set_image(0);
1453         (void)set_stun(0);
1454         (void)set_cut(0);
1455         (void)set_slow(0, TRUE);
1456
1457         /* No longer hungry */
1458         (void)set_food(PY_FOOD_MAX - 1);
1459
1460         /* Redraw everything */
1461         do_cmd_redraw();
1462 }
1463
1464
1465 /*
1466  * Go to any level
1467  */
1468 static void do_cmd_wiz_jump(void)
1469 {
1470         /* Ask for level */
1471         if (command_arg <= 0)
1472         {
1473                 char    ppp[80];
1474
1475                 char    tmp_val[160];
1476                 int             tmp_dungeon_type;
1477
1478                 /* Prompt */
1479                 sprintf(ppp, "Jump which dungeon : ");
1480
1481                 /* Default */
1482                 sprintf(tmp_val, "%d", dungeon_type);
1483
1484                 /* Ask for a level */
1485                 if (!get_string(ppp, tmp_val, 2)) return;
1486
1487                 tmp_dungeon_type = atoi(tmp_val);
1488                 if (!d_info[tmp_dungeon_type].maxdepth || (tmp_dungeon_type > max_d_idx)) tmp_dungeon_type = DUNGEON_ANGBAND;
1489
1490                 /* Prompt */
1491                 sprintf(ppp, "Jump to level (0, %d-%d): ", d_info[tmp_dungeon_type].mindepth, d_info[tmp_dungeon_type].maxdepth);
1492
1493                 /* Default */
1494                 sprintf(tmp_val, "%d", dun_level);
1495
1496                 /* Ask for a level */
1497                 if (!get_string(ppp, tmp_val, 10)) return;
1498
1499                 /* Extract request */
1500                 command_arg = atoi(tmp_val);
1501
1502                 dungeon_type = tmp_dungeon_type;
1503         }
1504
1505         /* Paranoia */
1506         if (command_arg < d_info[dungeon_type].mindepth) command_arg = 0;
1507
1508         /* Paranoia */
1509         if (command_arg > d_info[dungeon_type].maxdepth) command_arg = d_info[dungeon_type].maxdepth;
1510
1511         /* Accept request */
1512         msg_format("You jump to dungeon level %d.", command_arg);
1513
1514         if (autosave_l) do_cmd_save_game(TRUE);
1515
1516         /* Change level */
1517         dun_level = command_arg;
1518
1519         prepare_change_floor_mode(CFM_RAND_PLACE);
1520
1521         if (!dun_level) dungeon_type = 0;
1522         p_ptr->inside_arena = FALSE;
1523         p_ptr->wild_mode = FALSE;
1524
1525         leave_quest_check();
1526
1527         if (record_stair) do_cmd_write_nikki(NIKKI_WIZ_TELE,0,NULL);
1528
1529         p_ptr->inside_quest = 0;
1530         energy_use = 0;
1531
1532         /* Prevent energy_need from being too lower than 0 */
1533         p_ptr->energy_need = 0;
1534
1535         /*
1536          * Clear all saved floors
1537          * and create a first saved floor
1538          */
1539         prepare_change_floor_mode(CFM_FIRST_FLOOR);
1540
1541         /* Leaving */
1542         p_ptr->leaving = TRUE;
1543 }
1544
1545
1546 /*
1547  * Become aware of a lot of objects
1548  */
1549 static void do_cmd_wiz_learn(void)
1550 {
1551         int i;
1552
1553         object_type forge;
1554         object_type *q_ptr;
1555
1556         /* Scan every object */
1557         for (i = 1; i < max_k_idx; i++)
1558         {
1559                 object_kind *k_ptr = &k_info[i];
1560
1561                 /* Induce awareness */
1562                 if (k_ptr->level <= command_arg)
1563                 {
1564                         /* Get local object */
1565                         q_ptr = &forge;
1566
1567                         /* Prepare object */
1568                         object_prep(q_ptr, i);
1569
1570                         /* Awareness */
1571                         object_aware(q_ptr);
1572                 }
1573         }
1574 }
1575
1576
1577 /*
1578  * Summon some creatures
1579  */
1580 static void do_cmd_wiz_summon(int num)
1581 {
1582         int i;
1583
1584         for (i = 0; i < num; i++)
1585         {
1586                 (void)summon_specific(0, py, px, dun_level, 0, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE));
1587         }
1588 }
1589
1590
1591 /*
1592  * Summon a creature of the specified type
1593  *
1594  * XXX XXX XXX This function is rather dangerous
1595  */
1596 static void do_cmd_wiz_named(int r_idx)
1597 {
1598         (void)summon_named_creature(0, py, px, r_idx, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1599 }
1600
1601
1602 /*
1603  * Summon a creature of the specified type
1604  *
1605  * XXX XXX XXX This function is rather dangerous
1606  */
1607 static void do_cmd_wiz_named_friendly(int r_idx)
1608 {
1609         (void)summon_named_creature(0, py, px, r_idx, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP | PM_FORCE_PET));
1610 }
1611
1612
1613
1614 /*
1615  * Hack -- Delete all nearby monsters
1616  */
1617 static void do_cmd_wiz_zap(void)
1618 {
1619         int i;
1620
1621
1622         /* Genocide everyone nearby */
1623         for (i = 1; i < m_max; i++)
1624         {
1625                 monster_type *m_ptr = &m_list[i];
1626
1627                 /* Paranoia -- Skip dead monsters */
1628                 if (!m_ptr->r_idx) continue;
1629
1630                 /* Skip the mount */
1631                 if (i == p_ptr->riding) continue;
1632
1633                 /* Delete nearby monsters */
1634                 if (m_ptr->cdis <= MAX_SIGHT)
1635                 {
1636                         delete_monster_idx(i);
1637                 }
1638         }
1639 }
1640
1641
1642 /*
1643  * Hack -- Delete all monsters
1644  */
1645 static void do_cmd_wiz_zap_all(void)
1646 {
1647         int i;
1648
1649         /* Genocide everyone */
1650         for (i = 1; i < m_max; i++)
1651         {
1652                 monster_type *m_ptr = &m_list[i];
1653
1654                 /* Paranoia -- Skip dead monsters */
1655                 if (!m_ptr->r_idx) continue;
1656
1657                 /* Skip the mount */
1658                 if (i == p_ptr->riding) continue;
1659
1660                 /* Delete this monster */
1661                 delete_monster_idx(i);
1662         }
1663 }
1664
1665
1666 #define NUM_O_SET 8
1667 #define NUM_O_BIT 32
1668
1669 /*
1670  * Hack -- Dump option bits usage
1671  */
1672 static void do_cmd_dump_options(void)
1673 {
1674         int  i, j;
1675         FILE *fff;
1676         char buf[1024];
1677         int  **exist;
1678
1679         /* Build the filename */
1680         path_build(buf, sizeof buf, ANGBAND_DIR_USER, "opt_info.txt");
1681
1682         /* File type is "TEXT" */
1683         FILE_TYPE(FILE_TYPE_TEXT);
1684
1685         /* Open the file */
1686         fff = my_fopen(buf, "a");
1687
1688         /* Oops */
1689         if (!fff)
1690         {
1691 #ifdef JP
1692                 msg_format("¥Õ¥¡¥¤¥ë %s ¤ò³«¤±¤Þ¤»¤ó¤Ç¤·¤¿¡£", buf);
1693 #else
1694                 msg_format("Failed to open file %s.", buf);
1695 #endif
1696                 msg_print(NULL);
1697                 return;
1698         }
1699
1700         /* Allocate the "exist" array (2-dimension) */
1701         C_MAKE(exist, NUM_O_SET, int *);
1702         C_MAKE(*exist, NUM_O_BIT * NUM_O_SET, int);
1703         for (i = 1; i < NUM_O_SET; i++) exist[i] = *exist + i * NUM_O_BIT;
1704
1705         /* Check for exist option bits */
1706         for (i = 0; option_info[i].o_desc; i++)
1707         {
1708                 option_type *ot_ptr = &option_info[i];
1709                 if (ot_ptr->o_var) exist[ot_ptr->o_set][ot_ptr->o_bit] = i + 1;
1710         }
1711
1712         fprintf(fff, "[Option bits usage on Hengband %d.%d.%d]\n\n",
1713                 FAKE_VER_MAJOR - 10, FAKE_VER_MINOR, FAKE_VER_PATCH);
1714
1715         fputs("Set - Bit (Page) Option Name\n", fff);
1716         fputs("------------------------------------------------\n", fff);
1717         /* Dump option bits usage */
1718         for (i = 0; i < NUM_O_SET; i++)
1719         {
1720                 for (j = 0; j < NUM_O_BIT; j++)
1721                 {
1722                         if (exist[i][j])
1723                         {
1724                                 option_type *ot_ptr = &option_info[exist[i][j] - 1];
1725                                 fprintf(fff, "  %d -  %02d (%4d) %s\n",
1726                                         i, j, ot_ptr->o_page, ot_ptr->o_text);
1727                         }
1728                         else
1729                         {
1730                                 fprintf(fff, "  %d -  %02d\n", i, j);
1731                         }
1732                 }
1733                 fputc('\n', fff);
1734         }
1735
1736         /* Free the "exist" array (2-dimension) */
1737         C_KILL(*exist, NUM_O_BIT * NUM_O_SET, int);
1738         C_KILL(exist, NUM_O_SET, int *);
1739
1740         /* Close it */
1741         my_fclose(fff);
1742
1743 #ifdef JP
1744         msg_format("¥ª¥×¥·¥ç¥óbit»ÈÍѾõ¶·¤ò¥Õ¥¡¥¤¥ë %s ¤Ë½ñ¤­½Ð¤·¤Þ¤·¤¿¡£", buf);
1745 #else
1746         msg_format("Option bits usage dump saved to file %s.", buf);
1747 #endif
1748 }
1749
1750
1751 #ifdef ALLOW_SPOILERS
1752
1753 /*
1754  * External function
1755  */
1756 extern void do_cmd_spoilers(void);
1757
1758 #endif /* ALLOW_SPOILERS */
1759
1760
1761
1762 /*
1763  * Hack -- declare external function
1764  */
1765 extern void do_cmd_debug(void);
1766
1767
1768
1769 /*
1770  * Ask for and parse a "debug command"
1771  * The "command_arg" may have been set.
1772  */
1773 void do_cmd_debug(void)
1774 {
1775         int     x, y;
1776         char    cmd;
1777
1778
1779         /* Get a "debug command" */
1780         get_com("Debug Command: ", &cmd, FALSE);
1781
1782         /* Analyze the command */
1783         switch (cmd)
1784         {
1785         /* Nothing */
1786         case ESCAPE:
1787         case ' ':
1788         case '\n':
1789         case '\r':
1790                 break;
1791
1792 #ifdef ALLOW_SPOILERS
1793
1794         /* Hack -- Generate Spoilers */
1795         case '"':
1796                 do_cmd_spoilers();
1797                 break;
1798
1799 #endif /* ALLOW_SPOILERS */
1800
1801         /* Hack -- Help */
1802         case '?':
1803                 do_cmd_help();
1804                 break;
1805
1806         /* Cure all maladies */
1807         case 'a':
1808                 do_cmd_wiz_cure_all();
1809                 break;
1810
1811         /* Know alignment */
1812         case 'A':
1813                 msg_format("Your alignment is %d.", p_ptr->align);
1814                 break;
1815
1816         /* Teleport to target */
1817         case 'b':
1818                 do_cmd_wiz_bamf();
1819                 break;
1820
1821         case 'B':
1822                 battle_monsters();
1823                 break;
1824
1825         /* Create any object */
1826         case 'c':
1827                 wiz_create_item();
1828                 break;
1829
1830         /* Create a named artifact */
1831         case 'C':
1832                 wiz_create_named_art(command_arg);
1833                 break;
1834
1835         /* Detect everything */
1836         case 'd':
1837                 detect_all(DETECT_RAD_ALL * 3);
1838                 break;
1839
1840         /* Dimension_door */
1841         case 'D':
1842                 wiz_dimension_door();
1843                 break;
1844
1845         /* Edit character */
1846         case 'e':
1847                 do_cmd_wiz_change();
1848                 break;
1849
1850         /* Blue Mage Only */
1851         case 'E':
1852                 if (p_ptr->pclass == CLASS_BLUE_MAGE)
1853                 {
1854                         do_cmd_wiz_blue_mage();
1855                 }
1856                 break;
1857
1858         /* View item info */
1859         case 'f':
1860                 identify_fully(FALSE);
1861                 break;
1862
1863         /* Good Objects */
1864         case 'g':
1865                 if (command_arg <= 0) command_arg = 1;
1866                 acquirement(py, px, command_arg, FALSE, TRUE);
1867                 break;
1868
1869         /* Hitpoint rerating */
1870         case 'h':
1871                 do_cmd_rerate(TRUE);
1872                 break;
1873
1874 #ifdef MONSTER_HORDES
1875         case 'H':
1876                 do_cmd_summon_horde();
1877                 break;
1878 #endif /* MONSTER_HORDES */
1879
1880         /* Identify */
1881         case 'i':
1882                 (void)ident_spell(FALSE);
1883                 break;
1884
1885         /* Go up or down in the dungeon */
1886         case 'j':
1887                 do_cmd_wiz_jump();
1888                 break;
1889
1890         /* Self-Knowledge */
1891         case 'k':
1892                 self_knowledge();
1893                 break;
1894
1895         /* Learn about objects */
1896         case 'l':
1897                 do_cmd_wiz_learn();
1898                 break;
1899
1900         /* Magic Mapping */
1901         case 'm':
1902                 map_area(DETECT_RAD_ALL * 3);
1903                 break;
1904
1905         /* Mutation */
1906         case 'M':
1907                 (void)gain_random_mutation(command_arg);
1908                 break;
1909
1910         /* Specific reward */
1911         case 'r':
1912                 (void)gain_level_reward(command_arg);
1913                 break;
1914
1915         /* Summon _friendly_ named monster */
1916         case 'N':
1917                 do_cmd_wiz_named_friendly(command_arg);
1918                 break;
1919
1920         /* Summon Named Monster */
1921         case 'n':
1922                 do_cmd_wiz_named(command_arg);
1923                 break;
1924
1925         /* Dump option bits usage */
1926         case 'O':
1927                 do_cmd_dump_options();
1928                 break;
1929
1930         /* Object playing routines */
1931         case 'o':
1932                 do_cmd_wiz_play();
1933                 break;
1934
1935         /* Phase Door */
1936         case 'p':
1937                 teleport_player(10, FALSE);
1938                 break;
1939
1940 #if 0
1941         /* Complete a Quest -KMW- */
1942         case 'q':
1943                 for (i = 0; i < max_quests; i++)
1944                 {
1945                         if (p_ptr->quest[i].status == QUEST_STATUS_TAKEN)
1946                         {
1947                                 p_ptr->quest[i].status++;
1948                                 msg_print("Completed Quest");
1949                                 msg_print(NULL);
1950                                 break;
1951                         }
1952                 }
1953                 if (i == max_quests)
1954                 {
1955                         msg_print("No current quest");
1956                         msg_print(NULL);
1957                 }
1958                 break;
1959 #endif
1960
1961         /* Make every dungeon square "known" to test streamers -KMW- */
1962         case 'u':
1963                 for (y = 0; y < cur_hgt; y++)
1964                 {
1965                         for (x = 0; x < cur_wid; x++)
1966                         {
1967                                 cave[y][x].info |= (CAVE_GLOW | CAVE_MARK);
1968                         }
1969                 }
1970                 wiz_lite(FALSE);
1971                 break;
1972
1973         /* Summon Random Monster(s) */
1974         case 's':
1975                 if (command_arg <= 0) command_arg = 1;
1976                 do_cmd_wiz_summon(command_arg);
1977                 break;
1978
1979         /* Teleport */
1980         case 't':
1981                 teleport_player(100, FALSE);
1982                 break;
1983
1984         /* Very Good Objects */
1985         case 'v':
1986                 if (command_arg <= 0) command_arg = 1;
1987                 acquirement(py, px, command_arg, TRUE, TRUE);
1988                 break;
1989
1990         /* Wizard Light the Level */
1991         case 'w':
1992                 wiz_lite((bool)(p_ptr->pclass == CLASS_NINJA));
1993                 break;
1994
1995         /* Increase Experience */
1996         case 'x':
1997                 gain_exp(command_arg ? command_arg : (p_ptr->exp + 1));
1998                 break;
1999
2000         /* Zap Monsters (Genocide) */
2001         case 'z':
2002                 do_cmd_wiz_zap();
2003                 break;
2004
2005         /* Zap Monsters (Omnicide) */
2006         case 'Z':
2007                 do_cmd_wiz_zap_all();
2008                 break;
2009
2010         /* Hack -- whatever I desire */
2011         case '_':
2012                 do_cmd_wiz_hack_ben();
2013                 break;
2014
2015         /* Not a Wizard Command */
2016         default:
2017                 msg_print("That is not a valid debug command.");
2018                 break;
2019         }
2020 }
2021
2022
2023 #else
2024
2025 #ifdef MACINTOSH
2026 static int i = 0;
2027 #endif
2028
2029 #endif
2030