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