OSDN Git Service

鑑定した瞬間の自動破壊に根本的なバグがあった。
[hengband/hengband.git] / src / wizard2.c
1 /* File: wizard2.c */
2
3 /* Purpose: Wizard commands */
4
5 /*
6  * Copyright (c) 1989 James E. Wilson, Robert A. Koeneke
7  *
8  * This software may be copied and distributed for educational, research, and
9  * not for profit purposes provided that this copyright and statement are
10  * included in all such copies.
11  */
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                 player_hp[0] = p_ptr->hitdie;
33
34                 for (i = 1; i < 4; i++)
35                 {
36                         j = randint1(p_ptr->hitdie);
37                         player_hp[0] += j;
38                 }
39
40                 /* Collect values */
41                 for (i = 1; i < PY_MAX_LEVEL; i++)
42                 {
43                         player_hp[i] = randint1(p_ptr->hitdie);
44                         player_hp[i] += player_hp[i - 1];
45                 }
46
47                 /* Legal values */
48                 if ((player_hp[PY_MAX_LEVEL - 1] >= min_value) &&
49                     (player_hp[PY_MAX_LEVEL - 1] <= max_value)) break;
50         }
51
52         percent = (int)(((long)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, "8000");
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 < 0) tmp_s16b = 0L;
397         if (tmp_s16b > 8000) tmp_s16b = 8000L;
398
399         for (j = 0; j <= TV_SWORD - TV_BOW;j++)
400         {
401                 for (i = 0;i < 64;i++)
402                 {
403                         weapon_exp[j][i] = tmp_s16b;
404                         if (weapon_exp[j][i] > s_info[p_ptr->pclass].w_max[j][i]) 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                 skill_exp[j] = tmp_s16b;
411                 if (skill_exp[j] > s_info[p_ptr->pclass].s_max[j]) skill_exp[j] = s_info[p_ptr->pclass].s_max[j];
412         }
413
414         for (j = 0; j < 32; j++)
415                 spell_exp[j] = (tmp_s16b > 1600 ? 1600 : tmp_s16b);
416         for (; j < 64; j++)
417                 spell_exp[j] = (tmp_s16b > 1400 ? 1400 : 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 f1, f2, f3;
537         char buf[256];
538
539         /* Extract the flags */
540         object_flags(o_ptr, &f1, &f2, &f3);
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(f1, 16, j);
579
580         prt("+------------FLAGS2------------+", 17, j);
581         prt("SUST....IMMUN.RESIST............", 18, j);
582         prt("      r aefctrpsaefcpfldbc sn   ", 19, j);
583         prt("siwdcci clioheatcliooeialoshtncd", 20, j);
584         prt("tnieohd ierlrfraierliatrnnnrhehi", 21, j);
585         prt("rtsxnae.dcedwlatdcedsrekdfddrxss", 22, j);
586         prt_binary(f2, 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(f3, 16, j+32);
595 }
596
597
598 /*
599  * A structure to hold a tval and its description
600  */
601 typedef struct tval_desc
602 {
603         int        tval;
604         cptr       desc;
605 } tval_desc;
606
607 /*
608  * A list of tvals and their textual names
609  */
610 static tval_desc tvals[] =
611 {
612         { TV_SWORD,             "Sword"                },
613         { TV_POLEARM,           "Polearm"              },
614         { TV_HAFTED,            "Hafted Weapon"        },
615         { TV_BOW,               "Bow"                  },
616         { TV_ARROW,             "Arrows"               },
617         { TV_BOLT,              "Bolts"                },
618         { TV_SHOT,              "Shots"                },
619         { TV_SHIELD,            "Shield"               },
620         { TV_CROWN,             "Crown"                },
621         { TV_HELM,              "Helm"                 },
622         { TV_GLOVES,            "Gloves"               },
623         { TV_BOOTS,             "Boots"                },
624         { TV_CLOAK,             "Cloak"                },
625         { TV_DRAG_ARMOR,        "Dragon Scale Mail"    },
626         { TV_HARD_ARMOR,        "Hard Armor"           },
627         { TV_SOFT_ARMOR,        "Soft Armor"           },
628         { TV_RING,              "Ring"                 },
629         { TV_AMULET,            "Amulet"               },
630         { TV_LITE,              "Lite"                 },
631         { TV_POTION,            "Potion"               },
632         { TV_SCROLL,            "Scroll"               },
633         { TV_WAND,              "Wand"                 },
634         { TV_STAFF,             "Staff"                },
635         { TV_ROD,               "Rod"                  },
636         { TV_LIFE_BOOK,         "Life Spellbook"       },
637         { TV_SORCERY_BOOK,      "Sorcery Spellbook"    },
638         { TV_NATURE_BOOK,       "Nature Spellbook"     },
639         { TV_CHAOS_BOOK,        "Chaos Spellbook"      },
640         { TV_DEATH_BOOK,        "Death Spellbook"      },
641         { TV_TRUMP_BOOK,        "Trump Spellbook"      },
642         { TV_ARCANE_BOOK,       "Arcane Spellbook"     },
643         { TV_ENCHANT_BOOK,      "Craft Spellbook"},
644         { TV_DAEMON_BOOK,       "Daemon Spellbook"},
645         { TV_CRUSADE_BOOK,         "Crusade Spellbook"},
646         { TV_MUSIC_BOOK,        "Music Spellbook"      },
647         { TV_HISSATSU_BOOK,     "Book of Kendo" },
648         { TV_PARCHEMENT,        "Parchement" },
649         { TV_WHISTLE,           "Whistle"       },
650         { TV_SPIKE,             "Spikes"               },
651         { TV_DIGGING,           "Digger"               },
652         { TV_CHEST,             "Chest"                },
653         { TV_CAPTURE,           "Capture Ball"         },
654         { TV_CARD,              "Express Card"         },
655         { TV_FIGURINE,          "Magical Figurine"     },
656         { TV_STATUE,            "Statue"               },
657         { TV_CORPSE,            "Corpse"               },
658         { TV_FOOD,              "Food"                 },
659         { TV_FLASK,             "Flask"                },
660         { TV_JUNK,              "Junk"                 },
661         { TV_SKELETON,          "Skeleton"             },
662         { 0,                    NULL                   }
663 };
664
665
666 /*
667  * Strip an "object name" into a buffer
668  */
669 void strip_name(char *buf, int k_idx)
670 {
671         char *t;
672
673         object_kind *k_ptr = &k_info[k_idx];
674
675         cptr str = (k_name + k_ptr->name);
676
677
678         /* Skip past leading characters */
679         while ((*str == ' ') || (*str == '&')) str++;
680
681         /* Copy useful chars */
682         for (t = buf; *str; str++)
683         {
684 #ifdef JP
685                 if (iskanji(*str)) {*t++ = *str++; *t++ = *str; continue;}
686 #endif
687                 if (*str != '~') *t++ = *str;
688         }
689
690         /* Terminate the new name */
691         *t = '\0';
692 }
693
694
695 /*
696  * Specify tval and sval (type and subtype of object) originally
697  * by RAK, heavily modified by -Bernd-
698  *
699  * This function returns the k_idx of an object type, or zero if failed
700  *
701  * List up to 50 choices in three columns
702  */
703 static int wiz_create_itemtype(void)
704 {
705         int i, num, max_num;
706         int col, row;
707         int tval;
708
709         cptr tval_desc;
710         char ch;
711
712         int choice[80];
713
714         char buf[160];
715
716
717         /* Clear screen */
718         Term_clear();
719
720         /* Print all tval's and their descriptions */
721         for (num = 0; (num < 80) && tvals[num].tval; num++)
722         {
723                 row = 2 + (num % 20);
724                 col = 20 * (num / 20);
725                 ch = listsym[num];
726                 prt(format("[%c] %s", ch, tvals[num].desc), row, col);
727         }
728
729         /* Me need to know the maximal possible tval_index */
730         max_num = num;
731
732         /* Choose! */
733         if (!get_com("Get what type of object? ", &ch, FALSE)) return (0);
734
735         /* Analyze choice */
736         for (num = 0; num < max_num; num++)
737         {
738                 if (listsym[num] == ch) break;
739         }
740
741         /* Bail out if choice is illegal */
742         if ((num < 0) || (num >= max_num)) return (0);
743
744         /* Base object type chosen, fill in tval */
745         tval = tvals[num].tval;
746         tval_desc = tvals[num].desc;
747
748
749         /*** And now we go for k_idx ***/
750
751         /* Clear screen */
752         Term_clear();
753
754         /* We have to search the whole itemlist. */
755         for (num = 0, i = 1; (num < 80) && (i < max_k_idx); i++)
756         {
757                 object_kind *k_ptr = &k_info[i];
758
759                 /* Analyze matching items */
760                 if (k_ptr->tval == tval)
761                 {
762                         /* Prepare it */
763                         row = 2 + (num % 20);
764                         col = 20 * (num / 20);
765                         ch = listsym[num];
766                         strcpy(buf,"                    ");
767
768                         /* Acquire the "name" of object "i" */
769                         strip_name(buf, i);
770
771                         /* Print it */
772                         prt(format("[%c] %s", ch, buf), row, col);
773
774                         /* Remember the object index */
775                         choice[num++] = i;
776                 }
777         }
778
779         /* Me need to know the maximal possible remembered object_index */
780         max_num = num;
781
782         /* Choose! */
783         if (!get_com(format("What Kind of %s? ", tval_desc), &ch, FALSE)) return (0);
784
785         /* Analyze choice */
786         for (num = 0; num < max_num; num++)
787         {
788                 if (listsym[num] == ch) break;
789         }
790
791         /* Bail out if choice is "illegal" */
792         if ((num < 0) || (num >= max_num)) return (0);
793
794         /* And return successful */
795         return (choice[num]);
796 }
797
798
799 /*
800  * Tweak an item
801  */
802 static void wiz_tweak_item(object_type *o_ptr)
803 {
804         cptr p;
805         char tmp_val[80];
806
807
808         /* Hack -- leave artifacts alone */
809         if (artifact_p(o_ptr) || o_ptr->art_name) return;
810
811         p = "Enter new 'pval' setting: ";
812         sprintf(tmp_val, "%d", o_ptr->pval);
813         if (!get_string(p, tmp_val, 5)) return;
814         o_ptr->pval = atoi(tmp_val);
815         wiz_display_item(o_ptr);
816
817         p = "Enter new 'to_a' setting: ";
818         sprintf(tmp_val, "%d", o_ptr->to_a);
819         if (!get_string(p, tmp_val, 5)) return;
820         o_ptr->to_a = atoi(tmp_val);
821         wiz_display_item(o_ptr);
822
823         p = "Enter new 'to_h' setting: ";
824         sprintf(tmp_val, "%d", o_ptr->to_h);
825         if (!get_string(p, tmp_val, 5)) return;
826         o_ptr->to_h = atoi(tmp_val);
827         wiz_display_item(o_ptr);
828
829         p = "Enter new 'to_d' setting: ";
830         sprintf(tmp_val, "%d", o_ptr->to_d);
831         if (!get_string(p, tmp_val, 5)) return;
832         o_ptr->to_d = atoi(tmp_val);
833         wiz_display_item(o_ptr);
834 }
835
836
837 /*
838  * Apply magic to an item or turn it into an artifact. -Bernd-
839  */
840 static void wiz_reroll_item(object_type *o_ptr)
841 {
842         object_type forge;
843         object_type *q_ptr;
844
845         char ch;
846
847         bool changed = FALSE;
848
849
850         /* Hack -- leave artifacts alone */
851         if (artifact_p(o_ptr) || o_ptr->art_name) return;
852
853
854         /* Get local object */
855         q_ptr = &forge;
856
857         /* Copy the object */
858         object_copy(q_ptr, o_ptr);
859
860
861         /* Main loop. Ask for magification and artifactification */
862         while (TRUE)
863         {
864                 /* Display full item debug information */
865                 wiz_display_item(q_ptr);
866
867                 /* Ask wizard what to do. */
868                 if (!get_com("[a]ccept, [w]orthless, [c]ursed, [n]ormal, [g]ood, [e]xcellent, [s]pecial? ", &ch, FALSE))
869                 {
870                         /* Preserve wizard-generated artifacts */
871                         if (artifact_p(q_ptr))
872                         {
873                                 a_info[q_ptr->name1].cur_num = 0;
874                                 q_ptr->name1 = 0;
875                         }
876
877                         changed = FALSE;
878                         break;
879                 }
880
881                 /* Create/change it! */
882                 if (ch == 'A' || ch == 'a')
883                 {
884                         changed = TRUE;
885                         break;
886                 }
887
888                 /* Preserve wizard-generated artifacts */
889                 if (artifact_p(q_ptr))
890                 {
891                         a_info[q_ptr->name1].cur_num = 0;
892                         q_ptr->name1 = 0;
893                 }
894
895                 switch(ch)
896                 {
897                         /* Apply bad magic, but first clear object */
898                         case 'w': case 'W':
899                         {
900                                 object_prep(q_ptr, o_ptr->k_idx);
901                                 apply_magic(q_ptr, dun_level, FALSE, TRUE, TRUE, TRUE);
902                                 break;
903                         }
904                         /* Apply bad magic, but first clear object */
905                         case 'c': case 'C':
906                         {
907                                 object_prep(q_ptr, o_ptr->k_idx);
908                                 apply_magic(q_ptr, dun_level, FALSE, TRUE, FALSE, TRUE);
909                                 break;
910                         }
911                         /* Apply normal magic, but first clear object */
912                         case 'n': case 'N':
913                         {
914                                 object_prep(q_ptr, o_ptr->k_idx);
915                                 apply_magic(q_ptr, dun_level, FALSE, FALSE, FALSE, FALSE);
916                                 break;
917                         }
918                         /* Apply good magic, but first clear object */
919                         case 'g': case 'G':
920                         {
921                                 object_prep(q_ptr, o_ptr->k_idx);
922                                 apply_magic(q_ptr, dun_level, FALSE, TRUE, FALSE, FALSE);
923                                 break;
924                         }
925                         /* Apply great magic, but first clear object */
926                         case 'e': case 'E':
927                         {
928                                 object_prep(q_ptr, o_ptr->k_idx);
929                                 apply_magic(q_ptr, dun_level, FALSE, TRUE, TRUE, FALSE);
930                                 break;
931                         }
932                         case 's': case 'S':
933                         {
934                                 object_prep(q_ptr, o_ptr->k_idx);
935                                 apply_magic(q_ptr, dun_level, TRUE, TRUE, TRUE, FALSE);
936
937                                 /* Failed to create normal artifact; make a random one */
938                                 if (!artifact_p(q_ptr)) create_artifact(q_ptr, FALSE);
939                                 break;
940                         }
941                 }
942                 q_ptr->iy = o_ptr->iy;
943                 q_ptr->ix = o_ptr->ix;
944                 q_ptr->next_o_idx = o_ptr->next_o_idx;
945                 q_ptr->marked = o_ptr->marked;
946         }
947
948
949         /* Notice change */
950         if (changed)
951         {
952                 /* Apply changes */
953                 object_copy(o_ptr, q_ptr);
954
955                 /* Recalculate bonuses */
956                 p_ptr->update |= (PU_BONUS);
957
958                 /* Combine / Reorder the pack (later) */
959                 p_ptr->notice |= (PN_COMBINE | PN_REORDER);
960
961                 /* Window stuff */
962                 p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_SPELL | PW_PLAYER);
963         }
964 }
965
966
967
968 /*
969  * Try to create an item again. Output some statistics.    -Bernd-
970  *
971  * The statistics are correct now.  We acquire a clean grid, and then
972  * repeatedly place an object in this grid, copying it into an item
973  * holder, and then deleting the object.  We fiddle with the artifact
974  * counter flags to prevent weirdness.  We use the items to collect
975  * statistics on item creation relative to the initial item.
976  */
977 static void wiz_statistics(object_type *o_ptr)
978 {
979         u32b i, matches, better, worse, other, correct;
980
981         u32b test_roll = 1000000;
982
983         char ch;
984         cptr quality;
985
986         bool good, great;
987
988         object_type forge;
989         object_type     *q_ptr;
990
991         cptr q = "Rolls: %ld  Correct: %ld  Matches: %ld  Better: %ld  Worse: %ld  Other: %ld";
992
993         cptr p = "Enter number of items to roll: ";
994         char tmp_val[80];
995
996
997         /* XXX XXX XXX Mega-Hack -- allow multiple artifacts */
998         if (artifact_p(o_ptr)) a_info[o_ptr->name1].cur_num = 0;
999
1000
1001         /* Interact */
1002         while (TRUE)
1003         {
1004                 cptr pmt = "Roll for [n]ormal, [g]ood, or [e]xcellent treasure? ";
1005
1006                 /* Display item */
1007                 wiz_display_item(o_ptr);
1008
1009                 /* Get choices */
1010                 if (!get_com(pmt, &ch, FALSE)) break;
1011
1012                 if (ch == 'n' || ch == 'N')
1013                 {
1014                         good = FALSE;
1015                         great = FALSE;
1016                         quality = "normal";
1017                 }
1018                 else if (ch == 'g' || ch == 'G')
1019                 {
1020                         good = TRUE;
1021                         great = FALSE;
1022                         quality = "good";
1023                 }
1024                 else if (ch == 'e' || ch == 'E')
1025                 {
1026                         good = TRUE;
1027                         great = TRUE;
1028                         quality = "excellent";
1029                 }
1030                 else
1031                 {
1032                         good = FALSE;
1033                         great = FALSE;
1034                         break;
1035                 }
1036
1037                 sprintf(tmp_val, "%ld", test_roll);
1038                 if (get_string(p, tmp_val, 10)) test_roll = atol(tmp_val);
1039                 test_roll = MAX(1, test_roll);
1040
1041                 /* Let us know what we are doing */
1042                 msg_format("Creating a lot of %s items. Base level = %d.",
1043                                           quality, dun_level);
1044                 msg_print(NULL);
1045
1046                 /* Set counters to zero */
1047                 correct = matches = better = worse = other = 0;
1048
1049                 /* Let's rock and roll */
1050                 for (i = 0; i <= test_roll; i++)
1051                 {
1052                         /* Output every few rolls */
1053                         if ((i < 100) || (i % 100 == 0))
1054                         {
1055                                 /* Do not wait */
1056                                 inkey_scan = TRUE;
1057
1058                                 /* Allow interupt */
1059                                 if (inkey())
1060                                 {
1061                                         /* Flush */
1062                                         flush();
1063
1064                                         /* Stop rolling */
1065                                         break;
1066                                 }
1067
1068                                 /* Dump the stats */
1069                                 prt(format(q, i, correct, matches, better, worse, other), 0, 0);
1070                                 Term_fresh();
1071                         }
1072
1073
1074                         /* Get local object */
1075                         q_ptr = &forge;
1076
1077                         /* Wipe the object */
1078                         object_wipe(q_ptr);
1079
1080                         /* Create an object */
1081                         make_object(q_ptr, good, great);
1082
1083
1084                         /* XXX XXX XXX Mega-Hack -- allow multiple artifacts */
1085                         if (artifact_p(q_ptr)) a_info[q_ptr->name1].cur_num = 0;
1086
1087
1088                         /* Test for the same tval and sval. */
1089                         if ((o_ptr->tval) != (q_ptr->tval)) continue;
1090                         if ((o_ptr->sval) != (q_ptr->sval)) continue;
1091
1092                         /* One more correct item */
1093                         correct++;
1094
1095                         /* Check for match */
1096                         if ((q_ptr->pval == o_ptr->pval) &&
1097                                  (q_ptr->to_a == o_ptr->to_a) &&
1098                                  (q_ptr->to_h == o_ptr->to_h) &&
1099                                  (q_ptr->to_d == o_ptr->to_d) &&
1100                                  (q_ptr->name1 == o_ptr->name1))
1101                         {
1102                                 matches++;
1103                         }
1104
1105                         /* Check for better */
1106                         else if ((q_ptr->pval >= o_ptr->pval) &&
1107                                                 (q_ptr->to_a >= o_ptr->to_a) &&
1108                                                 (q_ptr->to_h >= o_ptr->to_h) &&
1109                                                 (q_ptr->to_d >= o_ptr->to_d))
1110                         {
1111                                 better++;
1112                         }
1113
1114                         /* Check for worse */
1115                         else if ((q_ptr->pval <= o_ptr->pval) &&
1116                                                 (q_ptr->to_a <= o_ptr->to_a) &&
1117                                                 (q_ptr->to_h <= o_ptr->to_h) &&
1118                                                 (q_ptr->to_d <= o_ptr->to_d))
1119                         {
1120                                 worse++;
1121                         }
1122
1123                         /* Assume different */
1124                         else
1125                         {
1126                                 other++;
1127                         }
1128                 }
1129
1130                 /* Final dump */
1131                 msg_format(q, i, correct, matches, better, worse, other);
1132                 msg_print(NULL);
1133         }
1134
1135
1136         /* Hack -- Normally only make a single artifact */
1137         if (artifact_p(o_ptr)) a_info[o_ptr->name1].cur_num = 1;
1138 }
1139
1140
1141 /*
1142  * Change the quantity of a the item
1143  */
1144 static void wiz_quantity_item(object_type *o_ptr)
1145 {
1146         int         tmp_int, tmp_qnt;
1147
1148         char        tmp_val[100];
1149
1150
1151         /* Never duplicate artifacts */
1152         if (artifact_p(o_ptr) || o_ptr->art_name) return;
1153
1154         /* Store old quantity. -LM- */
1155         tmp_qnt = o_ptr->number;
1156
1157         /* Default */
1158         sprintf(tmp_val, "%d", o_ptr->number);
1159
1160         /* Query */
1161         if (get_string("Quantity: ", tmp_val, 2))
1162         {
1163                 /* Extract */
1164                 tmp_int = atoi(tmp_val);
1165
1166                 /* Paranoia */
1167                 if (tmp_int < 1) tmp_int = 1;
1168                 if (tmp_int > 99) tmp_int = 99;
1169
1170                 /* Accept modifications */
1171                 o_ptr->number = tmp_int;
1172
1173                 /* Hack -- rod pvals must change if the number in the stack does. -LM- */
1174                 if (o_ptr->tval == TV_ROD)
1175                         o_ptr->pval = o_ptr->pval * o_ptr->number / tmp_qnt;
1176         }
1177 }
1178
1179
1180
1181 /*
1182  * Play with an item. Options include:
1183  *   - Output statistics (via wiz_roll_item)
1184  *   - Reroll item (via wiz_reroll_item)
1185  *   - Change properties (via wiz_tweak_item)
1186  *   - Change the number of items (via wiz_quantity_item)
1187  */
1188 static void do_cmd_wiz_play(void)
1189 {
1190         int item;
1191
1192         object_type     forge;
1193         object_type *q_ptr;
1194
1195         object_type *o_ptr;
1196
1197         char ch;
1198
1199         bool changed;
1200
1201         cptr q, s;
1202
1203         item_tester_no_ryoute = TRUE;
1204         /* Get an item */
1205         q = "Play with which object? ";
1206         s = "You have nothing to play with.";
1207         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return;
1208
1209         /* Get the item (in the pack) */
1210         if (item >= 0)
1211         {
1212                 o_ptr = &inventory[item];
1213         }
1214
1215         /* Get the item (on the floor) */
1216         else
1217         {
1218                 o_ptr = &o_list[0 - item];
1219         }
1220
1221
1222         /* The item was not changed */
1223         changed = FALSE;
1224
1225
1226         /* Save the screen */
1227         screen_save();
1228
1229
1230         /* Get local object */
1231         q_ptr = &forge;
1232
1233         /* Copy object */
1234         object_copy(q_ptr, o_ptr);
1235
1236
1237         /* The main loop */
1238         while (TRUE)
1239         {
1240                 /* Display the item */
1241                 wiz_display_item(q_ptr);
1242
1243                 /* Get choice */
1244                 if (!get_com("[a]ccept [s]tatistics [r]eroll [t]weak [q]uantity? ", &ch, FALSE))
1245                 {
1246                         changed = FALSE;
1247                         break;
1248                 }
1249
1250                 if (ch == 'A' || ch == 'a')
1251                 {
1252                         changed = TRUE;
1253                         break;
1254                 }
1255
1256                 if (ch == 's' || ch == 'S')
1257                 {
1258                         wiz_statistics(q_ptr);
1259                 }
1260
1261                 if (ch == 'r' || ch == 'r')
1262                 {
1263                         wiz_reroll_item(q_ptr);
1264                 }
1265
1266                 if (ch == 't' || ch == 'T')
1267                 {
1268                         wiz_tweak_item(q_ptr);
1269                 }
1270
1271                 if (ch == 'q' || ch == 'Q')
1272                 {
1273                         wiz_quantity_item(q_ptr);
1274                 }
1275         }
1276
1277
1278         /* Restore the screen */
1279         screen_load();
1280
1281
1282         /* Accept change */
1283         if (changed)
1284         {
1285                 /* Message */
1286                 msg_print("Changes accepted.");
1287
1288                 /* Change */
1289                 object_copy(o_ptr, q_ptr);
1290
1291                 /* Recalculate bonuses */
1292                 p_ptr->update |= (PU_BONUS);
1293
1294                 /* Combine / Reorder the pack (later) */
1295                 p_ptr->notice |= (PN_COMBINE | PN_REORDER);
1296
1297                 /* Window stuff */
1298                 p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_SPELL | PW_PLAYER);
1299         }
1300
1301         /* Ignore change */
1302         else
1303         {
1304                 msg_print("Changes ignored.");
1305         }
1306 }
1307
1308
1309 /*
1310  * Wizard routine for creating objects          -RAK-
1311  * Heavily modified to allow magification and artifactification  -Bernd-
1312  *
1313  * Note that wizards cannot create objects on top of other objects.
1314  *
1315  * Hack -- this routine always makes a "dungeon object", and applies
1316  * magic to it, and attempts to decline cursed items.
1317  */
1318 static void wiz_create_item(void)
1319 {
1320         object_type     forge;
1321         object_type *q_ptr;
1322
1323         int k_idx;
1324
1325
1326         /* Save the screen */
1327         screen_save();
1328
1329         /* Get object base type */
1330         k_idx = wiz_create_itemtype();
1331
1332         /* Restore the screen */
1333         screen_load();
1334
1335
1336         /* Return if failed */
1337         if (!k_idx) return;
1338
1339         /* Get local object */
1340         q_ptr = &forge;
1341
1342         /* Create the item */
1343         object_prep(q_ptr, k_idx);
1344
1345         if (k_info[k_idx].gen_flags & TRG_INSTA_ART)
1346         {
1347                 int i;
1348
1349                 /* Artifactify */
1350                 for (i = 1; i < max_a_idx; i++)
1351                 {
1352                         /* Ignore incorrect tval */
1353                         if (a_info[i].tval != q_ptr->tval) continue;
1354
1355                         /* Ignore incorrect sval */
1356                         if (a_info[i].sval != q_ptr->sval) continue;
1357
1358                         /* Choose this artifact */
1359                         q_ptr->name1 = i;
1360                         break;
1361                 }
1362
1363                 /* Apply magic */
1364                 apply_magic(q_ptr, -1, TRUE, TRUE, TRUE, FALSE);
1365         }
1366         else
1367         {
1368                 /* Apply magic */
1369                 apply_magic(q_ptr, dun_level, FALSE, FALSE, FALSE, FALSE);
1370         }
1371
1372         /* Drop the object from heaven */
1373         (void)drop_near(q_ptr, -1, py, px);
1374
1375         /* All done */
1376         msg_print("Allocated.");
1377 }
1378
1379
1380 /*
1381  * Cure everything instantly
1382  */
1383 static void do_cmd_wiz_cure_all(void)
1384 {
1385         /* Restore stats */
1386         (void)res_stat(A_STR);
1387         (void)res_stat(A_INT);
1388         (void)res_stat(A_WIS);
1389         (void)res_stat(A_CON);
1390         (void)res_stat(A_DEX);
1391         (void)res_stat(A_CHR);
1392
1393         /* Restore the level */
1394         (void)restore_level();
1395
1396         /* Heal the player */
1397         p_ptr->chp = p_ptr->mhp;
1398         p_ptr->chp_frac = 0;
1399
1400         /* Restore mana */
1401         if (p_ptr->csp < p_ptr->msp)
1402         {
1403                 p_ptr->csp = p_ptr->msp;
1404                 p_ptr->csp_frac = 0;
1405         }
1406
1407         /* Cure stuff */
1408         (void)set_blind(0);
1409         (void)set_confused(0);
1410         (void)set_poisoned(0);
1411         (void)set_afraid(0);
1412         (void)set_paralyzed(0);
1413         (void)set_image(0);
1414         (void)set_stun(0);
1415         (void)set_cut(0);
1416         (void)set_slow(0, TRUE);
1417
1418         /* No longer hungry */
1419         (void)set_food(PY_FOOD_MAX - 1);
1420
1421         /* Redraw everything */
1422         do_cmd_redraw();
1423 }
1424
1425
1426 /*
1427  * Go to any level
1428  */
1429 static void do_cmd_wiz_jump(void)
1430 {
1431         /* Ask for level */
1432         if (command_arg <= 0)
1433         {
1434                 char    ppp[80];
1435
1436                 char    tmp_val[160];
1437
1438                 /* Prompt */
1439                 sprintf(ppp, "Jump which dungeon : ");
1440
1441                 /* Default */
1442                 sprintf(tmp_val, "%d", dungeon_type);
1443
1444                 /* Ask for a level */
1445                 if (!get_string(ppp, tmp_val, 2)) return;
1446
1447                 dungeon_type = atoi(tmp_val);
1448                 if (!d_info[dungeon_type].maxdepth || (dungeon_type > max_d_idx)) dungeon_type = DUNGEON_ANGBAND;
1449
1450                 /* Prompt */
1451                 sprintf(ppp, "Jump to level (0, %d-%d): ", d_info[dungeon_type].mindepth, d_info[dungeon_type].maxdepth);
1452
1453                 /* Default */
1454                 sprintf(tmp_val, "%d", dun_level);
1455
1456                 /* Ask for a level */
1457                 if (!get_string(ppp, tmp_val, 10)) return;
1458
1459                 /* Extract request */
1460                 command_arg = atoi(tmp_val);
1461         }
1462
1463         /* Paranoia */
1464         if (command_arg < d_info[dungeon_type].mindepth) command_arg = 0;
1465
1466         /* Paranoia */
1467         if (command_arg > d_info[dungeon_type].maxdepth) command_arg = d_info[dungeon_type].maxdepth;
1468
1469         /* Accept request */
1470         msg_format("You jump to dungeon level %d.", command_arg);
1471
1472         if (autosave_l) do_cmd_save_game(TRUE);
1473
1474         /* Change level */
1475         dun_level = command_arg;
1476
1477         if (!dun_level) dungeon_type = 0;
1478         p_ptr->inside_arena = FALSE;
1479
1480         leave_quest_check();
1481
1482         if (record_stair) do_cmd_write_nikki(NIKKI_WIZ_TELE,0,NULL);
1483
1484         p_ptr->inside_quest = 0;
1485         p_ptr->leftbldg = FALSE;
1486         energy_use = 0;
1487
1488         /* Leaving */
1489         p_ptr->leaving = TRUE;
1490 }
1491
1492
1493 /*
1494  * Become aware of a lot of objects
1495  */
1496 static void do_cmd_wiz_learn(void)
1497 {
1498         int i;
1499
1500         object_type forge;
1501         object_type *q_ptr;
1502
1503         /* Scan every object */
1504         for (i = 1; i < max_k_idx; i++)
1505         {
1506                 object_kind *k_ptr = &k_info[i];
1507
1508                 /* Induce awareness */
1509                 if (k_ptr->level <= command_arg)
1510                 {
1511                         /* Get local object */
1512                         q_ptr = &forge;
1513
1514                         /* Prepare object */
1515                         object_prep(q_ptr, i);
1516
1517                         /* Awareness */
1518                         object_aware(q_ptr);
1519                 }
1520         }
1521 }
1522
1523
1524 /*
1525  * Summon some creatures
1526  */
1527 static void do_cmd_wiz_summon(int num)
1528 {
1529         int i;
1530
1531         for (i = 0; i < num; i++)
1532         {
1533                 (void)summon_specific(0, py, px, dun_level, 0, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE));
1534         }
1535 }
1536
1537
1538 /*
1539  * Summon a creature of the specified type
1540  *
1541  * XXX XXX XXX This function is rather dangerous
1542  */
1543 static void do_cmd_wiz_named(int r_idx)
1544 {
1545         int i, x, y;
1546
1547         /* Paranoia */
1548         /* if (!r_idx) return; */
1549
1550         /* Prevent illegal monsters */
1551         if (r_idx >= max_r_idx) return;
1552
1553         /* Try 10 times */
1554         for (i = 0; i < 10; i++)
1555         {
1556                 int d = 1;
1557
1558                 /* Pick a location */
1559                 scatter(&y, &x, py, px, d, 0);
1560
1561                 /* Require empty grids */
1562                 if (!cave_empty_bold(y, x)) continue;
1563
1564                 /* Place it (allow groups) */
1565                 if (place_monster_aux(0, y, x, r_idx, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP))) break;
1566         }
1567 }
1568
1569
1570 /*
1571  * Summon a creature of the specified type
1572  *
1573  * XXX XXX XXX This function is rather dangerous
1574  */
1575 static void do_cmd_wiz_named_friendly(int r_idx)
1576 {
1577         (void) summon_named_creature(0, py, px, r_idx, (PM_ALLOW_SLEEP | PM_ALLOW_GROUP | PM_FORCE_PET));
1578 }
1579
1580
1581
1582 /*
1583  * Hack -- Delete all nearby monsters
1584  */
1585 static void do_cmd_wiz_zap(void)
1586 {
1587         int i;
1588
1589
1590         /* Genocide everyone nearby */
1591         for (i = 1; i < m_max; i++)
1592         {
1593                 monster_type *m_ptr = &m_list[i];
1594
1595                 /* Paranoia -- Skip dead monsters */
1596                 if (!m_ptr->r_idx) continue;
1597
1598                 /* Delete nearby monsters */
1599                 if (m_ptr->cdis <= MAX_SIGHT)
1600                 {
1601                         if (i == p_ptr->riding)
1602                         {
1603                                 rakuba(-1, FALSE);
1604                                 p_ptr->redraw |= (PR_EXTRA);
1605                         }
1606                         delete_monster_idx(i);
1607                 }
1608         }
1609 }
1610
1611
1612 /*
1613  * Hack -- Delete all monsters
1614  */
1615 static void do_cmd_wiz_zap_all(void)
1616 {
1617         int i;
1618
1619         /* Genocide everyone */
1620         for (i = 1; i < m_max; i++)
1621         {
1622                 monster_type *m_ptr = &m_list[i];
1623
1624                 /* Paranoia -- Skip dead monsters */
1625                 if (!m_ptr->r_idx) continue;
1626
1627                 if (i == p_ptr->riding)
1628                 {
1629                         rakuba(-1, FALSE);
1630                         p_ptr->redraw |= (PR_EXTRA);
1631                 }
1632
1633                 /* Delete this monster */
1634                 delete_monster_idx(i);
1635         }
1636 }
1637
1638
1639 #ifdef ALLOW_SPOILERS
1640
1641 /*
1642  * External function
1643  */
1644 extern void do_cmd_spoilers(void);
1645
1646 #endif /* ALLOW_SPOILERS */
1647
1648
1649
1650 /*
1651  * Hack -- declare external function
1652  */
1653 extern void do_cmd_debug(void);
1654
1655
1656
1657 /*
1658  * Ask for and parse a "debug command"
1659  * The "command_arg" may have been set.
1660  */
1661 void do_cmd_debug(void)
1662 {
1663         int     x, y;
1664         char    cmd;
1665
1666
1667         /* Get a "debug command" */
1668         get_com("Debug Command: ", &cmd, FALSE);
1669
1670         /* Analyze the command */
1671         switch (cmd)
1672         {
1673                 /* Nothing */
1674                 case ESCAPE:
1675                 case ' ':
1676                 case '\n':
1677                 case '\r':
1678                 break;
1679
1680
1681 #ifdef ALLOW_SPOILERS
1682
1683                 /* Hack -- Generate Spoilers */
1684                 case '"':
1685                 do_cmd_spoilers();
1686                 break;
1687
1688 #endif /* ALLOW_SPOILERS */
1689
1690
1691                 /* Hack -- Help */
1692                 case '?':
1693                 do_cmd_help();
1694                 break;
1695
1696
1697                 /* Cure all maladies */
1698                 case 'a':
1699                 do_cmd_wiz_cure_all();
1700                 break;
1701
1702                 /* Know alignment */
1703                 case 'A':
1704                 msg_format("Your alignment is %d.", p_ptr->align);
1705                 break;
1706
1707                 /* Teleport to target */
1708                 case 'b':
1709                 do_cmd_wiz_bamf();
1710                 break;
1711
1712                 case 'B':
1713                 battle_monsters();
1714                 break;
1715
1716                 /* Create any object */
1717                 case 'c':
1718                 wiz_create_item();
1719                 break;
1720
1721                 /* Create a named artifact */
1722                 case 'C':
1723                 wiz_create_named_art(command_arg);
1724                 break;
1725
1726                 /* Detect everything */
1727                 case 'd':
1728                 detect_all(DETECT_RAD_ALL*3);
1729                 break;
1730
1731                 /* Dimension_door */
1732                 case 'D':
1733                 wiz_dimension_door();
1734                 break;
1735
1736                 /* Edit character */
1737                 case 'e':
1738                 do_cmd_wiz_change();
1739                 break;
1740
1741                 /* View item info */
1742                 case 'f':
1743                 identify_fully(FALSE, FALSE);
1744                 break;
1745
1746                 /* Good Objects */
1747                 case 'g':
1748                 if (command_arg <= 0) command_arg = 1;
1749                 acquirement(py, px, command_arg, FALSE, TRUE);
1750                 break;
1751
1752                 /* Hitpoint rerating */
1753                 case 'h':
1754                 do_cmd_rerate(TRUE); break;
1755
1756 #ifdef MONSTER_HORDES
1757                 case 'H':
1758                 do_cmd_summon_horde(); break;
1759 #endif /* MONSTER_HORDES */
1760
1761                 /* Identify */
1762                 case 'i':
1763                 (void)ident_spell(FALSE, FALSE);
1764                 break;
1765
1766                 /* Go up or down in the dungeon */
1767                 case 'j':
1768                 do_cmd_wiz_jump();
1769                 break;
1770
1771                 /* Self-Knowledge */
1772                 case 'k':
1773                         self_knowledge();
1774                         break;
1775
1776                 /* Learn about objects */
1777                 case 'l':
1778                         do_cmd_wiz_learn();
1779                         break;
1780
1781                 /* Magic Mapping */
1782                 case 'm':
1783                         map_area(DETECT_RAD_ALL);
1784                         break;
1785
1786                 /* Mutation */
1787                 case 'M':
1788                         (void)gain_random_mutation(command_arg);
1789                         break;
1790
1791                 /* Specific reward */
1792                 case 'r':
1793                         (void)gain_level_reward(command_arg);
1794                         break;
1795
1796                 /* Summon _friendly_ named monster */
1797                 case 'N':
1798                         do_cmd_wiz_named_friendly(command_arg);
1799                         break;
1800
1801                 /* Summon Named Monster */
1802                 case 'n':
1803                         do_cmd_wiz_named(command_arg);
1804                         break;
1805
1806                 /* Object playing routines */
1807                 case 'o':
1808                         do_cmd_wiz_play();
1809                         break;
1810
1811                 /* Phase Door */
1812                 case 'p':
1813                         teleport_player(10);
1814                         break;
1815
1816 #if 0
1817                 /* Complete a Quest -KMW- */
1818                 case 'q':
1819                 {
1820                         for (i = 0; i < max_quests; i++)
1821                         {
1822                                 if (p_ptr->quest[i].status == QUEST_STATUS_TAKEN)
1823                                 {
1824                                         p_ptr->quest[i].status++;
1825                                         msg_print("Completed Quest");
1826                                         msg_print(NULL);
1827                                         break;
1828                                 }
1829                         }
1830                         if (i == max_quests)
1831                         {
1832                                 msg_print("No current quest");
1833                                 msg_print(NULL);
1834                         }
1835                         break;
1836                 }
1837 #endif
1838
1839                 /* Make every dungeon square "known" to test streamers -KMW- */
1840                 case 'u':
1841                 {
1842                         for(y = 0; y < cur_hgt; y++)
1843                         {
1844                                 for(x = 0; x < cur_wid; x++)
1845                                 {
1846                                         cave[y][x].info |= (CAVE_GLOW | CAVE_MARK);
1847                                 }
1848                         }
1849                         wiz_lite(TRUE, FALSE);
1850                         break;
1851                 }
1852
1853                 /* Summon Random Monster(s) */
1854                 case 's':
1855                         if (command_arg <= 0) command_arg = 1;
1856                         do_cmd_wiz_summon(command_arg);
1857                         break;
1858
1859                 /* Teleport */
1860                 case 't':
1861                         teleport_player(100);
1862                         break;
1863
1864                 /* Very Good Objects */
1865                 case 'v':
1866                         if (command_arg <= 0) command_arg = 1;
1867                         acquirement(py, px, command_arg, TRUE, TRUE);
1868                         break;
1869
1870                 /* Wizard Light the Level */
1871                 case 'w':
1872                 wiz_lite(TRUE, (bool)(p_ptr->pclass == CLASS_NINJA));
1873                 break;
1874
1875                 /* Increase Experience */
1876                 case 'x':
1877                 if (command_arg)
1878                 {
1879                         gain_exp(command_arg);
1880                 }
1881                 else
1882                 {
1883                         gain_exp(p_ptr->exp + 1);
1884                 }
1885                 break;
1886
1887                 /* Zap Monsters (Genocide) */
1888                 case 'z':
1889                 do_cmd_wiz_zap();
1890                 break;
1891
1892                 case 'Z':
1893                 do_cmd_wiz_zap_all();
1894                 break;
1895
1896                 /* Hack -- whatever I desire */
1897                 case '_':
1898                 do_cmd_wiz_hack_ben();
1899                 break;
1900
1901                 /* Not a Wizard Command */
1902                 default:
1903                 msg_print("That is not a valid debug command.");
1904                 break;
1905         }
1906 }
1907
1908
1909 #else
1910
1911 #ifdef MACINTOSH
1912 static int i = 0;
1913 #endif
1914
1915 #endif
1916