OSDN Git Service

31a7b295518052b3423c01291b67afc6f1482d5a
[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_HEX_BOOK,          "Hex Spellbook"        },
658         { TV_PARCHMENT,         "Parchment" },
659         { TV_WHISTLE,           "Whistle"       },
660         { TV_SPIKE,             "Spikes"               },
661         { TV_DIGGING,           "Digger"               },
662         { TV_CHEST,             "Chest"                },
663         { TV_CAPTURE,           "Capture Ball"         },
664         { TV_CARD,              "Express Card"         },
665         { TV_FIGURINE,          "Magical Figurine"     },
666         { TV_STATUE,            "Statue"               },
667         { TV_CORPSE,            "Corpse"               },
668         { TV_FOOD,              "Food"                 },
669         { TV_FLASK,             "Flask"                },
670         { TV_JUNK,              "Junk"                 },
671         { TV_SKELETON,          "Skeleton"             },
672         { 0,                    NULL                   }
673 };
674
675
676 /*
677  * Strip an "object name" into a buffer
678  */
679 void strip_name(char *buf, int k_idx)
680 {
681         char *t;
682
683         object_kind *k_ptr = &k_info[k_idx];
684
685         cptr str = (k_name + k_ptr->name);
686
687
688         /* Skip past leading characters */
689         while ((*str == ' ') || (*str == '&')) str++;
690
691         /* Copy useful chars */
692         for (t = buf; *str; str++)
693         {
694 #ifdef JP
695                 if (iskanji(*str)) {*t++ = *str++; *t++ = *str; continue;}
696 #endif
697                 if (*str != '~') *t++ = *str;
698         }
699
700         /* Terminate the new name */
701         *t = '\0';
702 }
703
704
705 /*
706  * Specify tval and sval (type and subtype of object) originally
707  * by RAK, heavily modified by -Bernd-
708  *
709  * This function returns the k_idx of an object type, or zero if failed
710  *
711  * List up to 50 choices in three columns
712  */
713 static int wiz_create_itemtype(void)
714 {
715         int i, num, max_num;
716         int col, row;
717         int tval;
718
719         cptr tval_desc;
720         char ch;
721
722         int choice[80];
723
724         char buf[160];
725
726
727         /* Clear screen */
728         Term_clear();
729
730         /* Print all tval's and their descriptions */
731         for (num = 0; (num < 80) && tvals[num].tval; num++)
732         {
733                 row = 2 + (num % 20);
734                 col = 20 * (num / 20);
735                 ch = listsym[num];
736                 prt(format("[%c] %s", ch, tvals[num].desc), row, col);
737         }
738
739         /* Me need to know the maximal possible tval_index */
740         max_num = num;
741
742         /* Choose! */
743         if (!get_com("Get what type of object? ", &ch, FALSE)) return (0);
744
745         /* Analyze choice */
746         for (num = 0; num < max_num; num++)
747         {
748                 if (listsym[num] == ch) break;
749         }
750
751         /* Bail out if choice is illegal */
752         if ((num < 0) || (num >= max_num)) return (0);
753
754         /* Base object type chosen, fill in tval */
755         tval = tvals[num].tval;
756         tval_desc = tvals[num].desc;
757
758
759         /*** And now we go for k_idx ***/
760
761         /* Clear screen */
762         Term_clear();
763
764         /* We have to search the whole itemlist. */
765         for (num = 0, i = 1; (num < 80) && (i < max_k_idx); i++)
766         {
767                 object_kind *k_ptr = &k_info[i];
768
769                 /* Analyze matching items */
770                 if (k_ptr->tval == tval)
771                 {
772                         /* Prepare it */
773                         row = 2 + (num % 20);
774                         col = 20 * (num / 20);
775                         ch = listsym[num];
776                         strcpy(buf,"                    ");
777
778                         /* Acquire the "name" of object "i" */
779                         strip_name(buf, i);
780
781                         /* Print it */
782                         prt(format("[%c] %s", ch, buf), row, col);
783
784                         /* Remember the object index */
785                         choice[num++] = i;
786                 }
787         }
788
789         /* Me need to know the maximal possible remembered object_index */
790         max_num = num;
791
792         /* Choose! */
793         if (!get_com(format("What Kind of %s? ", tval_desc), &ch, FALSE)) return (0);
794
795         /* Analyze choice */
796         for (num = 0; num < max_num; num++)
797         {
798                 if (listsym[num] == ch) break;
799         }
800
801         /* Bail out if choice is "illegal" */
802         if ((num < 0) || (num >= max_num)) return (0);
803
804         /* And return successful */
805         return (choice[num]);
806 }
807
808
809 /*
810  * Tweak an item
811  */
812 static void wiz_tweak_item(object_type *o_ptr)
813 {
814         cptr p;
815         char tmp_val[80];
816
817
818         /* Hack -- leave artifacts alone */
819         if (object_is_artifact(o_ptr)) return;
820
821         p = "Enter new 'pval' setting: ";
822         sprintf(tmp_val, "%d", o_ptr->pval);
823         if (!get_string(p, tmp_val, 5)) return;
824         o_ptr->pval = atoi(tmp_val);
825         wiz_display_item(o_ptr);
826
827         p = "Enter new 'to_a' setting: ";
828         sprintf(tmp_val, "%d", o_ptr->to_a);
829         if (!get_string(p, tmp_val, 5)) return;
830         o_ptr->to_a = atoi(tmp_val);
831         wiz_display_item(o_ptr);
832
833         p = "Enter new 'to_h' setting: ";
834         sprintf(tmp_val, "%d", o_ptr->to_h);
835         if (!get_string(p, tmp_val, 5)) return;
836         o_ptr->to_h = atoi(tmp_val);
837         wiz_display_item(o_ptr);
838
839         p = "Enter new 'to_d' setting: ";
840         sprintf(tmp_val, "%d", o_ptr->to_d);
841         if (!get_string(p, tmp_val, 5)) return;
842         o_ptr->to_d = atoi(tmp_val);
843         wiz_display_item(o_ptr);
844 }
845
846
847 /*
848  * Apply magic to an item or turn it into an artifact. -Bernd-
849  */
850 static void wiz_reroll_item(object_type *o_ptr)
851 {
852         object_type forge;
853         object_type *q_ptr;
854
855         char ch;
856
857         bool changed = FALSE;
858
859
860         /* Hack -- leave artifacts alone */
861         if (object_is_artifact(o_ptr)) return;
862
863
864         /* Get local object */
865         q_ptr = &forge;
866
867         /* Copy the object */
868         object_copy(q_ptr, o_ptr);
869
870
871         /* Main loop. Ask for magification and artifactification */
872         while (TRUE)
873         {
874                 /* Display full item debug information */
875                 wiz_display_item(q_ptr);
876
877                 /* Ask wizard what to do. */
878                 if (!get_com("[a]ccept, [w]orthless, [c]ursed, [n]ormal, [g]ood, [e]xcellent, [s]pecial? ", &ch, FALSE))
879                 {
880                         /* Preserve wizard-generated artifacts */
881                         if (object_is_fixed_artifact(q_ptr))
882                         {
883                                 a_info[q_ptr->name1].cur_num = 0;
884                                 q_ptr->name1 = 0;
885                         }
886
887                         changed = FALSE;
888                         break;
889                 }
890
891                 /* Create/change it! */
892                 if (ch == 'A' || ch == 'a')
893                 {
894                         changed = TRUE;
895                         break;
896                 }
897
898                 /* Preserve wizard-generated artifacts */
899                 if (object_is_fixed_artifact(q_ptr))
900                 {
901                         a_info[q_ptr->name1].cur_num = 0;
902                         q_ptr->name1 = 0;
903                 }
904
905                 switch(ch)
906                 {
907                         /* Apply bad magic, but first clear object */
908                         case 'w': case 'W':
909                         {
910                                 object_prep(q_ptr, o_ptr->k_idx);
911                                 apply_magic(q_ptr, dun_level, AM_NO_FIXED_ART | AM_GOOD | AM_GREAT | AM_CURSED);
912                                 break;
913                         }
914                         /* Apply bad magic, but first clear object */
915                         case 'c': case 'C':
916                         {
917                                 object_prep(q_ptr, o_ptr->k_idx);
918                                 apply_magic(q_ptr, dun_level, AM_NO_FIXED_ART | AM_GOOD | AM_CURSED);
919                                 break;
920                         }
921                         /* Apply normal magic, but first clear object */
922                         case 'n': case 'N':
923                         {
924                                 object_prep(q_ptr, o_ptr->k_idx);
925                                 apply_magic(q_ptr, dun_level, AM_NO_FIXED_ART);
926                                 break;
927                         }
928                         /* Apply good magic, but first clear object */
929                         case 'g': case 'G':
930                         {
931                                 object_prep(q_ptr, o_ptr->k_idx);
932                                 apply_magic(q_ptr, dun_level, AM_NO_FIXED_ART | AM_GOOD);
933                                 break;
934                         }
935                         /* Apply great magic, but first clear object */
936                         case 'e': case 'E':
937                         {
938                                 object_prep(q_ptr, o_ptr->k_idx);
939                                 apply_magic(q_ptr, dun_level, AM_NO_FIXED_ART | AM_GOOD | AM_GREAT);
940                                 break;
941                         }
942                         /* Apply special magic, but first clear object */
943                         case 's': case 'S':
944                         {
945                                 object_prep(q_ptr, o_ptr->k_idx);
946                                 apply_magic(q_ptr, dun_level, AM_GOOD | AM_GREAT | AM_SPECIAL);
947
948                                 /* Failed to create artifact; make a random one */
949                                 if (!object_is_artifact(q_ptr)) create_artifact(q_ptr, FALSE);
950                                 break;
951                         }
952                 }
953                 q_ptr->iy = o_ptr->iy;
954                 q_ptr->ix = o_ptr->ix;
955                 q_ptr->next_o_idx = o_ptr->next_o_idx;
956                 q_ptr->marked = o_ptr->marked;
957         }
958
959
960         /* Notice change */
961         if (changed)
962         {
963                 /* Apply changes */
964                 object_copy(o_ptr, q_ptr);
965
966                 /* Recalculate bonuses */
967                 p_ptr->update |= (PU_BONUS);
968
969                 /* Combine / Reorder the pack (later) */
970                 p_ptr->notice |= (PN_COMBINE | PN_REORDER);
971
972                 /* Window stuff */
973                 p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_SPELL | PW_PLAYER);
974         }
975 }
976
977
978
979 /*
980  * Try to create an item again. Output some statistics.    -Bernd-
981  *
982  * The statistics are correct now.  We acquire a clean grid, and then
983  * repeatedly place an object in this grid, copying it into an item
984  * holder, and then deleting the object.  We fiddle with the artifact
985  * counter flags to prevent weirdness.  We use the items to collect
986  * statistics on item creation relative to the initial item.
987  */
988 static void wiz_statistics(object_type *o_ptr)
989 {
990         u32b i, matches, better, worse, other, correct;
991
992         u32b test_roll = 1000000;
993
994         char ch;
995         cptr quality;
996
997         u32b mode;
998
999         object_type forge;
1000         object_type     *q_ptr;
1001
1002         cptr q = "Rolls: %ld  Correct: %ld  Matches: %ld  Better: %ld  Worse: %ld  Other: %ld";
1003
1004         cptr p = "Enter number of items to roll: ";
1005         char tmp_val[80];
1006
1007
1008         /* XXX XXX XXX Mega-Hack -- allow multiple artifacts */
1009         if (object_is_fixed_artifact(o_ptr)) a_info[o_ptr->name1].cur_num = 0;
1010
1011
1012         /* Interact */
1013         while (TRUE)
1014         {
1015                 cptr pmt = "Roll for [n]ormal, [g]ood, or [e]xcellent treasure? ";
1016
1017                 /* Display item */
1018                 wiz_display_item(o_ptr);
1019
1020                 /* Get choices */
1021                 if (!get_com(pmt, &ch, FALSE)) break;
1022
1023                 if (ch == 'n' || ch == 'N')
1024                 {
1025                         mode = 0L;
1026                         quality = "normal";
1027                 }
1028                 else if (ch == 'g' || ch == 'G')
1029                 {
1030                         mode = AM_GOOD;
1031                         quality = "good";
1032                 }
1033                 else if (ch == 'e' || ch == 'E')
1034                 {
1035                         mode = AM_GOOD | AM_GREAT;
1036                         quality = "excellent";
1037                 }
1038                 else
1039                 {
1040                         break;
1041                 }
1042
1043                 sprintf(tmp_val, "%ld", (long int)test_roll);
1044                 if (get_string(p, tmp_val, 10)) test_roll = atol(tmp_val);
1045                 test_roll = MAX(1, test_roll);
1046
1047                 /* Let us know what we are doing */
1048                 msg_format("Creating a lot of %s items. Base level = %d.",
1049                                           quality, dun_level);
1050                 msg_print(NULL);
1051
1052                 /* Set counters to zero */
1053                 correct = matches = better = worse = other = 0;
1054
1055                 /* Let's rock and roll */
1056                 for (i = 0; i <= test_roll; i++)
1057                 {
1058                         /* Output every few rolls */
1059                         if ((i < 100) || (i % 100 == 0))
1060                         {
1061                                 /* Do not wait */
1062                                 inkey_scan = TRUE;
1063
1064                                 /* Allow interupt */
1065                                 if (inkey())
1066                                 {
1067                                         /* Flush */
1068                                         flush();
1069
1070                                         /* Stop rolling */
1071                                         break;
1072                                 }
1073
1074                                 /* Dump the stats */
1075                                 prt(format(q, i, correct, matches, better, worse, other), 0, 0);
1076                                 Term_fresh();
1077                         }
1078
1079
1080                         /* Get local object */
1081                         q_ptr = &forge;
1082
1083                         /* Wipe the object */
1084                         object_wipe(q_ptr);
1085
1086                         /* Create an object */
1087                         make_object(q_ptr, mode);
1088
1089
1090                         /* XXX XXX XXX Mega-Hack -- allow multiple artifacts */
1091                         if (object_is_fixed_artifact(q_ptr)) a_info[q_ptr->name1].cur_num = 0;
1092
1093
1094                         /* Test for the same tval and sval. */
1095                         if ((o_ptr->tval) != (q_ptr->tval)) continue;
1096                         if ((o_ptr->sval) != (q_ptr->sval)) continue;
1097
1098                         /* One more correct item */
1099                         correct++;
1100
1101                         /* Check for match */
1102                         if ((q_ptr->pval == o_ptr->pval) &&
1103                                  (q_ptr->to_a == o_ptr->to_a) &&
1104                                  (q_ptr->to_h == o_ptr->to_h) &&
1105                                  (q_ptr->to_d == o_ptr->to_d) &&
1106                                  (q_ptr->name1 == o_ptr->name1))
1107                         {
1108                                 matches++;
1109                         }
1110
1111                         /* Check for better */
1112                         else if ((q_ptr->pval >= o_ptr->pval) &&
1113                                                 (q_ptr->to_a >= o_ptr->to_a) &&
1114                                                 (q_ptr->to_h >= o_ptr->to_h) &&
1115                                                 (q_ptr->to_d >= o_ptr->to_d))
1116                         {
1117                                 better++;
1118                         }
1119
1120                         /* Check for worse */
1121                         else if ((q_ptr->pval <= o_ptr->pval) &&
1122                                                 (q_ptr->to_a <= o_ptr->to_a) &&
1123                                                 (q_ptr->to_h <= o_ptr->to_h) &&
1124                                                 (q_ptr->to_d <= o_ptr->to_d))
1125                         {
1126                                 worse++;
1127                         }
1128
1129                         /* Assume different */
1130                         else
1131                         {
1132                                 other++;
1133                         }
1134                 }
1135
1136                 /* Final dump */
1137                 msg_format(q, i, correct, matches, better, worse, other);
1138                 msg_print(NULL);
1139         }
1140
1141
1142         /* Hack -- Normally only make a single artifact */
1143         if (object_is_fixed_artifact(o_ptr)) a_info[o_ptr->name1].cur_num = 1;
1144 }
1145
1146
1147 /*
1148  * Change the quantity of a the item
1149  */
1150 static void wiz_quantity_item(object_type *o_ptr)
1151 {
1152         int         tmp_int, tmp_qnt;
1153
1154         char        tmp_val[100];
1155
1156
1157         /* Never duplicate artifacts */
1158         if (object_is_artifact(o_ptr)) return;
1159
1160         /* Store old quantity. -LM- */
1161         tmp_qnt = o_ptr->number;
1162
1163         /* Default */
1164         sprintf(tmp_val, "%d", o_ptr->number);
1165
1166         /* Query */
1167         if (get_string("Quantity: ", tmp_val, 2))
1168         {
1169                 /* Extract */
1170                 tmp_int = atoi(tmp_val);
1171
1172                 /* Paranoia */
1173                 if (tmp_int < 1) tmp_int = 1;
1174                 if (tmp_int > 99) tmp_int = 99;
1175
1176                 /* Accept modifications */
1177                 o_ptr->number = tmp_int;
1178         }
1179
1180         if (o_ptr->tval == TV_ROD)
1181         {
1182                 o_ptr->pval = o_ptr->pval * o_ptr->number / tmp_qnt;
1183         }
1184 }
1185
1186 /* debug command for blue mage */
1187 static void do_cmd_wiz_blue_mage(void)
1188 {
1189
1190         int                             i = 0;
1191         int                             j = 0;
1192         s32b            f4 = 0, f5 = 0, f6 = 0; 
1193
1194         for (j=1; j<6; j++)
1195         {
1196
1197                 set_rf_masks(&f4, &f5, &f6, j);
1198
1199                 for (i = 0; i < 32; i++)
1200                 {
1201                         if ((0x00000001 << i) & f4) p_ptr->magic_num2[i] = 1;
1202                 }
1203                 for (; i < 64; i++)
1204                 {
1205                         if ((0x00000001 << (i - 32)) & f5) p_ptr->magic_num2[i] = 1;
1206                 }
1207                 for (; i < 96; i++)
1208                 {
1209                         if ((0x00000001 << (i - 64)) & f6) p_ptr->magic_num2[i] = 1;
1210                 }
1211         }
1212 }
1213
1214
1215 /*
1216  * Play with an item. Options include:
1217  *   - Output statistics (via wiz_roll_item)
1218  *   - Reroll item (via wiz_reroll_item)
1219  *   - Change properties (via wiz_tweak_item)
1220  *   - Change the number of items (via wiz_quantity_item)
1221  */
1222 static void do_cmd_wiz_play(void)
1223 {
1224         int item;
1225
1226         object_type     forge;
1227         object_type *q_ptr;
1228
1229         object_type *o_ptr;
1230
1231         char ch;
1232
1233         bool changed;
1234
1235         cptr q, s;
1236
1237         item_tester_no_ryoute = TRUE;
1238         /* Get an item */
1239         q = "Play with which object? ";
1240         s = "You have nothing to play with.";
1241         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return;
1242
1243         /* Get the item (in the pack) */
1244         if (item >= 0)
1245         {
1246                 o_ptr = &inventory[item];
1247         }
1248
1249         /* Get the item (on the floor) */
1250         else
1251         {
1252                 o_ptr = &o_list[0 - item];
1253         }
1254         
1255         /* The item was not changed */
1256         changed = FALSE;
1257
1258
1259         /* Save the screen */
1260         screen_save();
1261
1262
1263         /* Get local object */
1264         q_ptr = &forge;
1265
1266         /* Copy object */
1267         object_copy(q_ptr, o_ptr);
1268
1269
1270         /* The main loop */
1271         while (TRUE)
1272         {
1273                 /* Display the item */
1274                 wiz_display_item(q_ptr);
1275
1276                 /* Get choice */
1277                 if (!get_com("[a]ccept [s]tatistics [r]eroll [t]weak [q]uantity? ", &ch, FALSE))
1278                 {
1279                         changed = FALSE;
1280                         break;
1281                 }
1282
1283                 if (ch == 'A' || ch == 'a')
1284                 {
1285                         changed = TRUE;
1286                         break;
1287                 }
1288
1289                 if (ch == 's' || ch == 'S')
1290                 {
1291                         wiz_statistics(q_ptr);
1292                 }
1293
1294                 if (ch == 'r' || ch == 'r')
1295                 {
1296                         wiz_reroll_item(q_ptr);
1297                 }
1298
1299                 if (ch == 't' || ch == 'T')
1300                 {
1301                         wiz_tweak_item(q_ptr);
1302                 }
1303
1304                 if (ch == 'q' || ch == 'Q')
1305                 {
1306                         wiz_quantity_item(q_ptr);
1307                 }
1308         }
1309
1310
1311         /* Restore the screen */
1312         screen_load();
1313
1314
1315         /* Accept change */
1316         if (changed)
1317         {
1318                 /* Message */
1319                 msg_print("Changes accepted.");
1320
1321                 /* Recalcurate object's weight */
1322                 if (item >= 0)
1323                 {
1324                         p_ptr->total_weight += (q_ptr->weight * q_ptr->number)
1325                                 - (o_ptr->weight * o_ptr->number);
1326                 }
1327
1328                 /* Change */
1329                 object_copy(o_ptr, q_ptr);
1330
1331
1332                 /* Recalculate bonuses */
1333                 p_ptr->update |= (PU_BONUS);
1334
1335                 /* Combine / Reorder the pack (later) */
1336                 p_ptr->notice |= (PN_COMBINE | PN_REORDER);
1337
1338                 /* Window stuff */
1339                 p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_SPELL | PW_PLAYER);
1340         }
1341
1342         /* Ignore change */
1343         else
1344         {
1345                 msg_print("Changes ignored.");
1346         }
1347 }
1348
1349
1350 /*
1351  * Wizard routine for creating objects          -RAK-
1352  * Heavily modified to allow magification and artifactification  -Bernd-
1353  *
1354  * Note that wizards cannot create objects on top of other objects.
1355  *
1356  * Hack -- this routine always makes a "dungeon object", and applies
1357  * magic to it, and attempts to decline cursed items.
1358  */
1359 static void wiz_create_item(void)
1360 {
1361         object_type     forge;
1362         object_type *q_ptr;
1363
1364         int k_idx;
1365
1366
1367         /* Save the screen */
1368         screen_save();
1369
1370         /* Get object base type */
1371         k_idx = wiz_create_itemtype();
1372
1373         /* Restore the screen */
1374         screen_load();
1375
1376
1377         /* Return if failed */
1378         if (!k_idx) return;
1379
1380         if (k_info[k_idx].gen_flags & TRG_INSTA_ART)
1381         {
1382                 int i;
1383
1384                 /* Artifactify */
1385                 for (i = 1; i < max_a_idx; i++)
1386                 {
1387                         /* Ignore incorrect tval */
1388                         if (a_info[i].tval != k_info[k_idx].tval) continue;
1389
1390                         /* Ignore incorrect sval */
1391                         if (a_info[i].sval != k_info[k_idx].sval) continue;
1392
1393                         /* Create this artifact */
1394                         (void)create_named_art(i, py, px);
1395
1396                         /* All done */
1397                         msg_print("Allocated(INSTA_ART).");
1398
1399                         return;
1400                 }
1401         }
1402
1403         /* Get local object */
1404         q_ptr = &forge;
1405
1406         /* Create the item */
1407         object_prep(q_ptr, k_idx);
1408
1409         /* Apply magic */
1410         apply_magic(q_ptr, dun_level, AM_NO_FIXED_ART);
1411
1412         /* Drop the object from heaven */
1413         (void)drop_near(q_ptr, -1, py, px);
1414
1415         /* All done */
1416         msg_print("Allocated.");
1417 }
1418
1419
1420 /*
1421  * Cure everything instantly
1422  */
1423 static void do_cmd_wiz_cure_all(void)
1424 {
1425         /* Restore stats */
1426         (void)res_stat(A_STR);
1427         (void)res_stat(A_INT);
1428         (void)res_stat(A_WIS);
1429         (void)res_stat(A_CON);
1430         (void)res_stat(A_DEX);
1431         (void)res_stat(A_CHR);
1432
1433         /* Restore the level */
1434         (void)restore_level();
1435
1436         /* Heal the player */
1437         if (p_ptr->chp < p_ptr->mhp)
1438         {
1439                 p_ptr->chp = p_ptr->mhp;
1440                 p_ptr->chp_frac = 0;
1441
1442                 /* Redraw */
1443                 p_ptr->redraw |= (PR_HP);
1444
1445                 /* Window stuff */
1446                 p_ptr->window |= (PW_PLAYER);
1447         }
1448
1449         /* Restore mana */
1450         if (p_ptr->csp < p_ptr->msp)
1451         {
1452                 p_ptr->csp = p_ptr->msp;
1453                 p_ptr->csp_frac = 0;
1454
1455                 p_ptr->redraw |= (PR_MANA);
1456                 p_ptr->window |= (PW_PLAYER);
1457                 p_ptr->window |= (PW_SPELL);
1458         }
1459
1460         /* Cure stuff */
1461         (void)set_blind(0);
1462         (void)set_confused(0);
1463         (void)set_poisoned(0);
1464         (void)set_afraid(0);
1465         (void)set_paralyzed(0);
1466         (void)set_image(0);
1467         (void)set_stun(0);
1468         (void)set_cut(0);
1469         (void)set_slow(0, TRUE);
1470
1471         /* No longer hungry */
1472         (void)set_food(PY_FOOD_MAX - 1);
1473 }
1474
1475
1476 /*
1477  * Go to any level
1478  */
1479 static void do_cmd_wiz_jump(void)
1480 {
1481         /* Ask for level */
1482         if (command_arg <= 0)
1483         {
1484                 char    ppp[80];
1485
1486                 char    tmp_val[160];
1487                 int             tmp_dungeon_type;
1488
1489                 /* Prompt */
1490                 sprintf(ppp, "Jump which dungeon : ");
1491
1492                 /* Default */
1493                 sprintf(tmp_val, "%d", dungeon_type);
1494
1495                 /* Ask for a level */
1496                 if (!get_string(ppp, tmp_val, 2)) return;
1497
1498                 tmp_dungeon_type = atoi(tmp_val);
1499                 if (!d_info[tmp_dungeon_type].maxdepth || (tmp_dungeon_type > max_d_idx)) tmp_dungeon_type = DUNGEON_ANGBAND;
1500
1501                 /* Prompt */
1502                 sprintf(ppp, "Jump to level (0, %d-%d): ", d_info[tmp_dungeon_type].mindepth, d_info[tmp_dungeon_type].maxdepth);
1503
1504                 /* Default */
1505                 sprintf(tmp_val, "%d", dun_level);
1506
1507                 /* Ask for a level */
1508                 if (!get_string(ppp, tmp_val, 10)) return;
1509
1510                 /* Extract request */
1511                 command_arg = atoi(tmp_val);
1512
1513                 dungeon_type = tmp_dungeon_type;
1514         }
1515
1516         /* Paranoia */
1517         if (command_arg < d_info[dungeon_type].mindepth) command_arg = 0;
1518
1519         /* Paranoia */
1520         if (command_arg > d_info[dungeon_type].maxdepth) command_arg = d_info[dungeon_type].maxdepth;
1521
1522         /* Accept request */
1523         msg_format("You jump to dungeon level %d.", command_arg);
1524
1525         if (autosave_l) do_cmd_save_game(TRUE);
1526
1527         /* Change level */
1528         dun_level = command_arg;
1529
1530         prepare_change_floor_mode(CFM_RAND_PLACE);
1531
1532         if (!dun_level) dungeon_type = 0;
1533         p_ptr->inside_arena = FALSE;
1534         p_ptr->wild_mode = FALSE;
1535
1536         leave_quest_check();
1537
1538         if (record_stair) do_cmd_write_nikki(NIKKI_WIZ_TELE,0,NULL);
1539
1540         p_ptr->inside_quest = 0;
1541         energy_use = 0;
1542
1543         /* Prevent energy_need from being too lower than 0 */
1544         p_ptr->energy_need = 0;
1545
1546         /*
1547          * Clear all saved floors
1548          * and create a first saved floor
1549          */
1550         prepare_change_floor_mode(CFM_FIRST_FLOOR);
1551
1552         /* Leaving */
1553         p_ptr->leaving = TRUE;
1554 }
1555
1556
1557 /*
1558  * Become aware of a lot of objects
1559  */
1560 static void do_cmd_wiz_learn(void)
1561 {
1562         int i;
1563
1564         object_type forge;
1565         object_type *q_ptr;
1566
1567         /* Scan every object */
1568         for (i = 1; i < max_k_idx; i++)
1569         {
1570                 object_kind *k_ptr = &k_info[i];
1571
1572                 /* Induce awareness */
1573                 if (k_ptr->level <= command_arg)
1574                 {
1575                         /* Get local object */
1576                         q_ptr = &forge;
1577
1578                         /* Prepare object */
1579                         object_prep(q_ptr, i);
1580
1581                         /* Awareness */
1582                         object_aware(q_ptr);
1583                 }
1584         }
1585 }
1586
1587
1588 /*
1589  * Summon some creatures
1590  */
1591 static void do_cmd_wiz_summon(int num)
1592 {
1593         int i;
1594
1595         for (i = 0; i < num; i++)
1596         {
1597                 (void)summon_specific(0, py, px, dun_level, 0, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE));
1598         }
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(int r_idx)
1608 {
1609         (void)summon_named_creature(0, py, px, r_idx, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP));
1610 }
1611
1612
1613 /*
1614  * Summon a creature of the specified type
1615  *
1616  * XXX XXX XXX This function is rather dangerous
1617  */
1618 static void do_cmd_wiz_named_friendly(int r_idx)
1619 {
1620         (void)summon_named_creature(0, py, px, r_idx, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP | PM_FORCE_PET));
1621 }
1622
1623
1624
1625 /*
1626  * Hack -- Delete all nearby monsters
1627  */
1628 static void do_cmd_wiz_zap(void)
1629 {
1630         int i;
1631
1632
1633         /* Genocide everyone nearby */
1634         for (i = 1; i < m_max; i++)
1635         {
1636                 monster_type *m_ptr = &m_list[i];
1637
1638                 /* Paranoia -- Skip dead monsters */
1639                 if (!m_ptr->r_idx) continue;
1640
1641                 /* Skip the mount */
1642                 if (i == p_ptr->riding) continue;
1643
1644                 /* Delete nearby monsters */
1645                 if (m_ptr->cdis <= MAX_SIGHT)
1646                 {
1647                         if (record_named_pet && is_pet(m_ptr) && m_ptr->nickname)
1648                         {
1649                                 char m_name[80];
1650
1651                                 monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
1652                                 do_cmd_write_nikki(NIKKI_NAMED_PET, RECORD_NAMED_PET_WIZ_ZAP, m_name);
1653                         }
1654
1655                         delete_monster_idx(i);
1656                 }
1657         }
1658 }
1659
1660
1661 /*
1662  * Hack -- Delete all monsters
1663  */
1664 static void do_cmd_wiz_zap_all(void)
1665 {
1666         int i;
1667
1668         /* Genocide everyone */
1669         for (i = 1; i < m_max; i++)
1670         {
1671                 monster_type *m_ptr = &m_list[i];
1672
1673                 /* Paranoia -- Skip dead monsters */
1674                 if (!m_ptr->r_idx) continue;
1675
1676                 /* Skip the mount */
1677                 if (i == p_ptr->riding) continue;
1678
1679                 if (record_named_pet && is_pet(m_ptr) && m_ptr->nickname)
1680                 {
1681                         char m_name[80];
1682
1683                         monster_desc(m_name, m_ptr, MD_INDEF_VISIBLE);
1684                         do_cmd_write_nikki(NIKKI_NAMED_PET, RECORD_NAMED_PET_WIZ_ZAP, m_name);
1685                 }
1686
1687                 /* Delete this monster */
1688                 delete_monster_idx(i);
1689         }
1690 }
1691
1692
1693 /*
1694  * Create desired feature
1695  */
1696 static void do_cmd_wiz_create_feature(void)
1697 {
1698         static int   prev_feat = 0;
1699         static int   prev_mimic = 0;
1700         cave_type    *c_ptr;
1701         feature_type *f_ptr;
1702         char         tmp_val[160];
1703         int          tmp_feat, tmp_mimic;
1704         int          y, x;
1705
1706         if (!tgt_pt(&x, &y)) return;
1707
1708         c_ptr = &cave[y][x];
1709
1710         /* Default */
1711         sprintf(tmp_val, "%d", prev_feat);
1712
1713         /* Query */
1714 #ifdef JP
1715         if (!get_string("ÃÏ·Á: ", tmp_val, 3)) return;
1716 #else
1717         if (!get_string("Feature: ", tmp_val, 3)) return;
1718 #endif
1719
1720         /* Extract */
1721         tmp_feat = atoi(tmp_val);
1722         if (tmp_feat < 0) tmp_feat = 0;
1723         else if (tmp_feat >= max_f_idx) tmp_feat = max_f_idx - 1;
1724
1725         /* Default */
1726         sprintf(tmp_val, "%d", prev_mimic);
1727
1728         /* Query */
1729 #ifdef JP
1730         if (!get_string("ÃÏ·Á (mimic): ", tmp_val, 3)) return;
1731 #else
1732         if (!get_string("Feature (mimic): ", tmp_val, 3)) return;
1733 #endif
1734
1735         /* Extract */
1736         tmp_mimic = atoi(tmp_val);
1737         if (tmp_mimic < 0) tmp_mimic = 0;
1738         else if (tmp_mimic >= max_f_idx) tmp_mimic = max_f_idx - 1;
1739
1740         cave_set_feat(y, x, tmp_feat);
1741         c_ptr->mimic = tmp_mimic;
1742
1743         f_ptr = &f_info[get_feat_mimic(c_ptr)];
1744
1745         if (have_flag(f_ptr->flags, FF_GLYPH) ||
1746             have_flag(f_ptr->flags, FF_MINOR_GLYPH))
1747                 c_ptr->info |= (CAVE_OBJECT);
1748         else if (have_flag(f_ptr->flags, FF_MIRROR))
1749                 c_ptr->info |= (CAVE_GLOW | CAVE_OBJECT);
1750
1751         /* Notice */
1752         note_spot(y, x);
1753
1754         /* Redraw */
1755         lite_spot(y, x);
1756
1757         /* Update some things */
1758         p_ptr->update |= (PU_FLOW);
1759
1760         prev_feat = tmp_feat;
1761         prev_mimic = tmp_mimic;
1762 }
1763
1764
1765 #define NUM_O_SET 8
1766 #define NUM_O_BIT 32
1767
1768 /*
1769  * Hack -- Dump option bits usage
1770  */
1771 static void do_cmd_dump_options(void)
1772 {
1773         int  i, j;
1774         FILE *fff;
1775         char buf[1024];
1776         int  **exist;
1777
1778         /* Build the filename */
1779         path_build(buf, sizeof buf, ANGBAND_DIR_USER, "opt_info.txt");
1780
1781         /* File type is "TEXT" */
1782         FILE_TYPE(FILE_TYPE_TEXT);
1783
1784         /* Open the file */
1785         fff = my_fopen(buf, "a");
1786
1787         /* Oops */
1788         if (!fff)
1789         {
1790 #ifdef JP
1791                 msg_format("¥Õ¥¡¥¤¥ë %s ¤ò³«¤±¤Þ¤»¤ó¤Ç¤·¤¿¡£", buf);
1792 #else
1793                 msg_format("Failed to open file %s.", buf);
1794 #endif
1795                 msg_print(NULL);
1796                 return;
1797         }
1798
1799         /* Allocate the "exist" array (2-dimension) */
1800         C_MAKE(exist, NUM_O_SET, int *);
1801         C_MAKE(*exist, NUM_O_BIT * NUM_O_SET, int);
1802         for (i = 1; i < NUM_O_SET; i++) exist[i] = *exist + i * NUM_O_BIT;
1803
1804         /* Check for exist option bits */
1805         for (i = 0; option_info[i].o_desc; i++)
1806         {
1807                 option_type *ot_ptr = &option_info[i];
1808                 if (ot_ptr->o_var) exist[ot_ptr->o_set][ot_ptr->o_bit] = i + 1;
1809         }
1810
1811         fprintf(fff, "[Option bits usage on Hengband %d.%d.%d]\n\n",
1812                 FAKE_VER_MAJOR - 10, FAKE_VER_MINOR, FAKE_VER_PATCH);
1813
1814         fputs("Set - Bit (Page) Option Name\n", fff);
1815         fputs("------------------------------------------------\n", fff);
1816         /* Dump option bits usage */
1817         for (i = 0; i < NUM_O_SET; i++)
1818         {
1819                 for (j = 0; j < NUM_O_BIT; j++)
1820                 {
1821                         if (exist[i][j])
1822                         {
1823                                 option_type *ot_ptr = &option_info[exist[i][j] - 1];
1824                                 fprintf(fff, "  %d -  %02d (%4d) %s\n",
1825                                         i, j, ot_ptr->o_page, ot_ptr->o_text);
1826                         }
1827                         else
1828                         {
1829                                 fprintf(fff, "  %d -  %02d\n", i, j);
1830                         }
1831                 }
1832                 fputc('\n', fff);
1833         }
1834
1835         /* Free the "exist" array (2-dimension) */
1836         C_KILL(*exist, NUM_O_BIT * NUM_O_SET, int);
1837         C_KILL(exist, NUM_O_SET, int *);
1838
1839         /* Close it */
1840         my_fclose(fff);
1841
1842 #ifdef JP
1843         msg_format("¥ª¥×¥·¥ç¥óbit»ÈÍѾõ¶·¤ò¥Õ¥¡¥¤¥ë %s ¤Ë½ñ¤­½Ð¤·¤Þ¤·¤¿¡£", buf);
1844 #else
1845         msg_format("Option bits usage dump saved to file %s.", buf);
1846 #endif
1847 }
1848
1849
1850 #ifdef ALLOW_SPOILERS
1851
1852 /*
1853  * External function
1854  */
1855 extern void do_cmd_spoilers(void);
1856
1857 #endif /* ALLOW_SPOILERS */
1858
1859
1860
1861 /*
1862  * Hack -- declare external function
1863  */
1864 extern void do_cmd_debug(void);
1865
1866
1867
1868 /*
1869  * Ask for and parse a "debug command"
1870  * The "command_arg" may have been set.
1871  */
1872 void do_cmd_debug(void)
1873 {
1874         int     x, y;
1875         char    cmd;
1876
1877
1878         /* Get a "debug command" */
1879         get_com("Debug Command: ", &cmd, FALSE);
1880
1881         /* Analyze the command */
1882         switch (cmd)
1883         {
1884         /* Nothing */
1885         case ESCAPE:
1886         case ' ':
1887         case '\n':
1888         case '\r':
1889                 break;
1890
1891 #ifdef ALLOW_SPOILERS
1892
1893         /* Hack -- Generate Spoilers */
1894         case '"':
1895                 do_cmd_spoilers();
1896                 break;
1897
1898 #endif /* ALLOW_SPOILERS */
1899
1900         /* Hack -- Help */
1901         case '?':
1902                 do_cmd_help();
1903                 break;
1904
1905         /* Cure all maladies */
1906         case 'a':
1907                 do_cmd_wiz_cure_all();
1908                 break;
1909
1910         /* Know alignment */
1911         case 'A':
1912                 msg_format("Your alignment is %d.", p_ptr->align);
1913                 break;
1914
1915         /* Teleport to target */
1916         case 'b':
1917                 do_cmd_wiz_bamf();
1918                 break;
1919
1920         case 'B':
1921                 battle_monsters();
1922                 break;
1923
1924         /* Create any object */
1925         case 'c':
1926                 wiz_create_item();
1927                 break;
1928
1929         /* Create a named artifact */
1930         case 'C':
1931                 wiz_create_named_art(command_arg);
1932                 break;
1933
1934         /* Detect everything */
1935         case 'd':
1936                 detect_all(DETECT_RAD_ALL * 3);
1937                 break;
1938
1939         /* Dimension_door */
1940         case 'D':
1941                 wiz_dimension_door();
1942                 break;
1943
1944         /* Edit character */
1945         case 'e':
1946                 do_cmd_wiz_change();
1947                 break;
1948
1949         /* Blue Mage Only */
1950         case 'E':
1951                 if (p_ptr->pclass == CLASS_BLUE_MAGE)
1952                 {
1953                         do_cmd_wiz_blue_mage();
1954                 }
1955                 break;
1956
1957         /* View item info */
1958         case 'f':
1959                 identify_fully(FALSE);
1960                 break;
1961
1962         /* Create desired feature */
1963         case 'F':
1964                 do_cmd_wiz_create_feature();
1965                 break;
1966
1967         /* Good Objects */
1968         case 'g':
1969                 if (command_arg <= 0) command_arg = 1;
1970                 acquirement(py, px, command_arg, FALSE, TRUE);
1971                 break;
1972
1973         /* Hitpoint rerating */
1974         case 'h':
1975                 do_cmd_rerate(TRUE);
1976                 break;
1977
1978 #ifdef MONSTER_HORDES
1979         case 'H':
1980                 do_cmd_summon_horde();
1981                 break;
1982 #endif /* MONSTER_HORDES */
1983
1984         /* Identify */
1985         case 'i':
1986                 (void)ident_spell(FALSE);
1987                 break;
1988
1989         /* Go up or down in the dungeon */
1990         case 'j':
1991                 do_cmd_wiz_jump();
1992                 break;
1993
1994         /* Self-Knowledge */
1995         case 'k':
1996                 self_knowledge();
1997                 break;
1998
1999         /* Learn about objects */
2000         case 'l':
2001                 do_cmd_wiz_learn();
2002                 break;
2003
2004         /* Magic Mapping */
2005         case 'm':
2006                 map_area(DETECT_RAD_ALL * 3);
2007                 break;
2008
2009         /* Mutation */
2010         case 'M':
2011                 (void)gain_random_mutation(command_arg);
2012                 break;
2013
2014         /* Specific reward */
2015         case 'r':
2016                 (void)gain_level_reward(command_arg);
2017                 break;
2018
2019         /* Summon _friendly_ named monster */
2020         case 'N':
2021                 do_cmd_wiz_named_friendly(command_arg);
2022                 break;
2023
2024         /* Summon Named Monster */
2025         case 'n':
2026                 do_cmd_wiz_named(command_arg);
2027                 break;
2028
2029         /* Dump option bits usage */
2030         case 'O':
2031                 do_cmd_dump_options();
2032                 break;
2033
2034         /* Object playing routines */
2035         case 'o':
2036                 do_cmd_wiz_play();
2037                 break;
2038
2039         /* Phase Door */
2040         case 'p':
2041                 teleport_player(10, 0L);
2042                 break;
2043
2044 #if 0
2045         /* Complete a Quest -KMW- */
2046         case 'q':
2047                 for (i = 0; i < max_quests; i++)
2048                 {
2049                         if (p_ptr->quest[i].status == QUEST_STATUS_TAKEN)
2050                         {
2051                                 p_ptr->quest[i].status++;
2052                                 msg_print("Completed Quest");
2053                                 msg_print(NULL);
2054                                 break;
2055                         }
2056                 }
2057                 if (i == max_quests)
2058                 {
2059                         msg_print("No current quest");
2060                         msg_print(NULL);
2061                 }
2062                 break;
2063 #endif
2064
2065         /* Make every dungeon square "known" to test streamers -KMW- */
2066         case 'u':
2067                 for (y = 0; y < cur_hgt; y++)
2068                 {
2069                         for (x = 0; x < cur_wid; x++)
2070                         {
2071                                 cave[y][x].info |= (CAVE_GLOW | CAVE_MARK);
2072                         }
2073                 }
2074                 wiz_lite(FALSE);
2075                 break;
2076
2077         /* Summon Random Monster(s) */
2078         case 's':
2079                 if (command_arg <= 0) command_arg = 1;
2080                 do_cmd_wiz_summon(command_arg);
2081                 break;
2082
2083         /* Teleport */
2084         case 't':
2085                 teleport_player(100, 0L);
2086                 break;
2087
2088         /* Very Good Objects */
2089         case 'v':
2090                 if (command_arg <= 0) command_arg = 1;
2091                 acquirement(py, px, command_arg, TRUE, TRUE);
2092                 break;
2093
2094         /* Wizard Light the Level */
2095         case 'w':
2096                 wiz_lite((bool)(p_ptr->pclass == CLASS_NINJA));
2097                 break;
2098
2099         /* Increase Experience */
2100         case 'x':
2101                 gain_exp(command_arg ? command_arg : (p_ptr->exp + 1));
2102                 break;
2103
2104         /* Zap Monsters (Genocide) */
2105         case 'z':
2106                 do_cmd_wiz_zap();
2107                 break;
2108
2109         /* Zap Monsters (Omnicide) */
2110         case 'Z':
2111                 do_cmd_wiz_zap_all();
2112                 break;
2113
2114         /* Hack -- whatever I desire */
2115         case '_':
2116                 do_cmd_wiz_hack_ben();
2117                 break;
2118
2119         /* Not a Wizard Command */
2120         default:
2121                 msg_print("That is not a valid debug command.");
2122                 break;
2123         }
2124 }
2125
2126
2127 #else
2128
2129 #ifdef MACINTOSH
2130 static int i = 0;
2131 #endif
2132
2133 #endif
2134