OSDN Git Service

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