OSDN Git Service

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