OSDN Git Service

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