OSDN Git Service

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