OSDN Git Service

BCC++ 5.5.1で警告封じオプション -w- を外した場合のコンパイル警告の除去.
[hengband/hengband.git] / src / dungeon.c
1 /* File: dungeonc */
2
3 /*
4  * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
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: Angband game engine */
12
13 #include "angband.h"
14
15 #define TY_CURSE_CHANCE 200
16 #define CHAINSWORD_NOISE 100
17
18 static bool load = TRUE;
19 static int wild_regen = 20;
20
21 /*
22  * Return a "feeling" (or NULL) about an item.  Method 1 (Heavy).
23  */
24 static byte value_check_aux1(object_type *o_ptr)
25 {
26         /* Artifacts */
27         if (artifact_p(o_ptr) || o_ptr->art_name)
28         {
29                 /* Cursed/Broken */
30                 if (cursed_p(o_ptr) || broken_p(o_ptr)) return FEEL_TERRIBLE;
31
32                 /* Normal */
33                 return FEEL_SPECIAL;
34         }
35
36         /* Ego-Items */
37         if (ego_item_p(o_ptr))
38         {
39                 /* Cursed/Broken */
40                 if (cursed_p(o_ptr) || broken_p(o_ptr)) return FEEL_WORTHLESS;
41
42                 /* Normal */
43                 return FEEL_EXCELLENT;
44         }
45
46         /* Cursed items */
47         if (cursed_p(o_ptr)) return FEEL_CURSED;
48
49         /* Broken items */
50         if (broken_p(o_ptr)) return FEEL_BROKEN;
51
52         if ((o_ptr->tval == TV_RING) || (o_ptr->tval == TV_AMULET)) return FEEL_AVERAGE;
53
54         /* Good "armor" bonus */
55         if (o_ptr->to_a > 0) return FEEL_GOOD;
56
57         /* Good "weapon" bonus */
58         if (o_ptr->to_h + o_ptr->to_d > 0) return FEEL_GOOD;
59
60         /* Default to "average" */
61         return FEEL_AVERAGE;
62 }
63
64
65 /*
66  * Return a "feeling" (or NULL) about an item.  Method 2 (Light).
67  */
68 static byte value_check_aux2(object_type *o_ptr)
69 {
70         /* Cursed items (all of them) */
71         if (cursed_p(o_ptr)) return FEEL_CURSED;
72
73         /* Broken items (all of them) */
74         if (broken_p(o_ptr)) return FEEL_BROKEN;
75
76         /* Artifacts -- except cursed/broken ones */
77         if (artifact_p(o_ptr) || o_ptr->art_name) return FEEL_UNCURSED;
78
79         /* Ego-Items -- except cursed/broken ones */
80         if (ego_item_p(o_ptr)) return FEEL_UNCURSED;
81
82         /* Good armor bonus */
83         if (o_ptr->to_a > 0) return FEEL_UNCURSED;
84
85         /* Good weapon bonuses */
86         if (o_ptr->to_h + o_ptr->to_d > 0) return FEEL_UNCURSED;
87
88         /* No feeling */
89         return FEEL_NONE;
90 }
91
92
93
94 static void sense_inventory_aux(int slot, bool heavy)
95 {
96         byte        feel;
97         object_type *o_ptr = &inventory[slot];
98         char        o_name[MAX_NLEN];
99         int idx;
100
101         /* We know about it already, do not tell us again */
102         if (o_ptr->ident & (IDENT_SENSE))return;
103
104         /* It is fully known, no information needed */
105         if (object_known_p(o_ptr)) return;
106
107         /* Check for a feeling */
108         feel = (heavy ? value_check_aux1(o_ptr) : value_check_aux2(o_ptr));
109
110         /* Skip non-feelings */
111         if (!feel) return;
112
113         /* Bad luck */
114         if ((p_ptr->muta3 & MUT3_BAD_LUCK) && !randint0(13))
115         {
116                 switch (feel)
117                 {
118                         case FEEL_TERRIBLE:
119                         {
120                                 feel = FEEL_SPECIAL;
121                                 break;
122                         }
123                         case FEEL_WORTHLESS:
124                         {
125                                 feel = FEEL_EXCELLENT;
126                                 break;
127                         }
128                         case FEEL_CURSED:
129                         {
130                                 if (heavy)
131                                         feel = randint0(3) ? FEEL_GOOD : FEEL_AVERAGE;
132                                 else
133                                         feel = FEEL_UNCURSED;
134                                 break;
135                         }
136                         case FEEL_AVERAGE:
137                         {
138                                 feel = randint0(2) ? FEEL_CURSED : FEEL_GOOD;
139                                 break;
140                         }
141                         case FEEL_GOOD:
142                         {
143                                 if (heavy)
144                                         feel = randint0(3) ? FEEL_CURSED : FEEL_AVERAGE;
145                                 else
146                                         feel = FEEL_CURSED;
147                                 break;
148                         }
149                         case FEEL_EXCELLENT:
150                         {
151                                 feel = FEEL_WORTHLESS;
152                                 break;
153                         }
154                         case FEEL_SPECIAL:
155                         {
156                                 feel = FEEL_TERRIBLE;
157                                 break;
158                         }
159                 }
160         }
161
162         /* Stop everything */
163         if (disturb_minor) disturb(0, 0);
164
165         /* Get an object description */
166         object_desc(o_name, o_ptr, FALSE, 0);
167
168         /* Message (equipment) */
169         if (slot >= INVEN_RARM)
170         {
171 #ifdef JP
172 msg_format("%s%s(%c)¤Ï%s¤È¤¤¤¦´¶¤¸¤¬¤¹¤ë...",
173 describe_use(slot),o_name, index_to_label(slot),game_inscriptions[feel]);
174 #else
175                 msg_format("You feel the %s (%c) you are %s %s %s...",
176                            o_name, index_to_label(slot), describe_use(slot),
177                            ((o_ptr->number == 1) ? "is" : "are"),
178                                    game_inscriptions[feel]);
179 #endif
180
181         }
182
183         /* Message (inventory) */
184         else
185         {
186 #ifdef JP
187 msg_format("¥¶¥Ã¥¯¤ÎÃæ¤Î%s(%c)¤Ï%s¤È¤¤¤¦´¶¤¸¤¬¤¹¤ë...",
188 o_name, index_to_label(slot),game_inscriptions[feel]);
189 #else
190                 msg_format("You feel the %s (%c) in your pack %s %s...",
191                            o_name, index_to_label(slot),
192                            ((o_ptr->number == 1) ? "is" : "are"),
193                                    game_inscriptions[feel]);
194 #endif
195
196         }
197
198         /* We have "felt" it */
199         o_ptr->ident |= (IDENT_SENSE);
200
201         /* Set the "inscription" */
202         o_ptr->feeling = feel;
203
204         /* Auto-inscription/destroy */
205         idx = is_autopick(o_ptr);
206         auto_inscribe_item(slot, idx);
207         if (destroy_feeling)
208                 auto_destroy_item(slot, idx);
209
210         /* Combine / Reorder the pack (later) */
211         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
212
213         /* Window stuff */
214         p_ptr->window |= (PW_INVEN | PW_EQUIP);
215 }
216
217
218
219 /*
220  * Sense the inventory
221  *
222  *   Class 0 = Warrior --> fast and heavy
223  *   Class 1 = Mage    --> slow and light
224  *   Class 2 = Priest  --> fast but light
225  *   Class 3 = Rogue   --> okay and heavy
226  *   Class 4 = Ranger  --> slow but heavy  (changed!)
227  *   Class 5 = Paladin --> slow but heavy
228  */
229 static void sense_inventory1(void)
230 {
231         int         i;
232         int         plev = p_ptr->lev;
233         bool        heavy = FALSE;
234         object_type *o_ptr;
235
236
237         /*** Check for "sensing" ***/
238
239         /* No sensing when confused */
240         if (p_ptr->confused) return;
241
242         /* Analyze the class */
243         switch (p_ptr->pclass)
244         {
245                 case CLASS_WARRIOR:
246                 case CLASS_ARCHER:
247                 case CLASS_SAMURAI:
248                 case CLASS_CAVALRY:
249                 {
250                         /* Good sensing */
251                         if (0 != randint0(9000L / (plev * plev + 40))) return;
252
253                         /* Heavy sensing */
254                         heavy = TRUE;
255
256                         /* Done */
257                         break;
258                 }
259
260                 case CLASS_SMITH:
261                 {
262                         /* Good sensing */
263                         if (0 != randint0(6000L / (plev * plev + 50))) return;
264
265                         /* Heavy sensing */
266                         heavy = TRUE;
267
268                         /* Done */
269                         break;
270                 }
271
272                 case CLASS_MAGE:
273                 case CLASS_HIGH_MAGE:
274                 case CLASS_SORCERER:
275                 case CLASS_MAGIC_EATER:
276                 {
277                         /* Very bad (light) sensing */
278                         if (0 != randint0(240000L / (plev + 5))) return;
279
280                         /* Done */
281                         break;
282                 }
283
284                 case CLASS_PRIEST:
285                 case CLASS_BARD:
286                 {
287                         /* Good (light) sensing */
288                         if (0 != randint0(10000L / (plev * plev + 40))) return;
289
290                         /* Done */
291                         break;
292                 }
293
294                 case CLASS_ROGUE:
295                 case CLASS_NINJA:
296                 {
297                         /* Okay sensing */
298                         if (0 != randint0(20000L / (plev * plev + 40))) return;
299
300                         /* Heavy sensing */
301                         heavy = TRUE;
302
303                         /* Done */
304                         break;
305                 }
306
307                 case CLASS_RANGER:
308                 {
309                         /* Bad sensing */
310                         if (0 != randint0(95000L / (plev * plev + 40))) return;
311
312                         /* Changed! */
313                         heavy = TRUE;
314
315                         /* Done */
316                         break;
317                 }
318
319                 case CLASS_PALADIN:
320                 {
321                         /* Bad sensing */
322                         if (0 != randint0(77777L / (plev * plev + 40))) return;
323
324                         /* Heavy sensing */
325                         heavy = TRUE;
326
327                         /* Done */
328                         break;
329                 }
330
331                 case CLASS_WARRIOR_MAGE:
332                 case CLASS_RED_MAGE:
333                 {
334                         /* Bad sensing */
335                         if (0 != randint0(75000L / (plev * plev + 40))) return;
336
337                         /* Done */
338                         break;
339                 }
340
341                 case CLASS_MINDCRAFTER:
342                 case CLASS_IMITATOR:
343                 case CLASS_BLUE_MAGE:
344                 case CLASS_MIRROR_MASTER:
345                 {
346                         /* Bad sensing */
347                         if (0 != randint0(55000L / (plev * plev + 40))) return;
348
349                         /* Done */
350                         break;
351                 }
352
353                 case CLASS_CHAOS_WARRIOR:
354                 {
355                         /* Bad sensing */
356                         if (0 != randint0(80000L / (plev * plev + 40))) return;
357
358                         /* Changed! */
359                         heavy = TRUE;
360
361                         /* Done */
362                         break;
363                 }
364
365                 case CLASS_MONK:
366                 case CLASS_FORCETRAINER:
367                 {
368                         /* Okay sensing */
369                         if (0 != randint0(20000L / (plev * plev + 40))) return;
370
371                         /* Done */
372                         break;
373                 }
374
375                 case CLASS_TOURIST:
376                 {
377                         /* Good sensing */
378                         if (0 != randint0(20000L / ((plev+50)*(plev+50)))) return;
379
380                         /* Heavy sensing */
381                         heavy = TRUE;
382
383                         /* Done */
384                         break;
385                 }
386
387                 case CLASS_BEASTMASTER:
388                 {
389                         /* Bad sensing */
390                         if (0 != randint0(65000L / (plev * plev + 40))) return;
391
392                         /* Done */
393                         break;
394                 }
395                 case CLASS_BERSERKER:
396                 {
397                         /* Heavy sensing */
398                         heavy = TRUE;
399
400                         /* Done */
401                         break;
402                 }
403         }
404
405         if (compare_virtue(V_KNOWLEDGE, 100, VIRTUE_LARGE)) heavy = TRUE;
406
407         /*** Sense everything ***/
408
409         /* Check everything */
410         for (i = 0; i < INVEN_TOTAL; i++)
411         {
412                 bool okay = FALSE;
413
414                 o_ptr = &inventory[i];
415
416                 /* Skip empty slots */
417                 if (!o_ptr->k_idx) continue;
418
419                 /* Valid "tval" codes */
420                 switch (o_ptr->tval)
421                 {
422                         case TV_SHOT:
423                         case TV_ARROW:
424                         case TV_BOLT:
425                         case TV_BOW:
426                         case TV_DIGGING:
427                         case TV_HAFTED:
428                         case TV_POLEARM:
429                         case TV_SWORD:
430                         case TV_BOOTS:
431                         case TV_GLOVES:
432                         case TV_HELM:
433                         case TV_CROWN:
434                         case TV_SHIELD:
435                         case TV_CLOAK:
436                         case TV_SOFT_ARMOR:
437                         case TV_HARD_ARMOR:
438                         case TV_DRAG_ARMOR:
439                         case TV_CARD:
440                         {
441                                 okay = TRUE;
442                                 break;
443                         }
444                 }
445
446                 /* Skip non-sense machines */
447                 if (!okay) continue;
448
449                 /* Occasional failure on inventory items */
450                 if ((i < INVEN_RARM) && (0 != randint0(5))) continue;
451
452                 /* Good luck */
453                 if ((p_ptr->muta3 & MUT3_GOOD_LUCK) && !randint0(13))
454                 {
455                         heavy = TRUE;
456                 }
457
458                 sense_inventory_aux(i, heavy);
459         }
460 }
461
462
463 static void sense_inventory2(void)
464 {
465         int         i;
466         int         plev = p_ptr->lev;
467         object_type *o_ptr;
468
469
470         /*** Check for "sensing" ***/
471
472         /* No sensing when confused */
473         if (p_ptr->confused) return;
474
475         /* Analyze the class */
476         switch (p_ptr->pclass)
477         {
478                 case CLASS_WARRIOR:
479                 case CLASS_ARCHER:
480                 case CLASS_SAMURAI:
481                 case CLASS_CAVALRY:
482                 case CLASS_BERSERKER:
483                 {
484                         return;
485                 }
486
487                 case CLASS_SMITH:
488                 case CLASS_PALADIN:
489                 case CLASS_CHAOS_WARRIOR:
490                 case CLASS_IMITATOR:
491                 case CLASS_BEASTMASTER:
492                 case CLASS_NINJA:
493                 {
494                         /* Very bad (light) sensing */
495                         if (0 != randint0(240000L / (plev + 5))) return;
496
497                         /* Done */
498                         break;
499                 }
500
501                 case CLASS_RANGER:
502                 case CLASS_WARRIOR_MAGE:
503                 case CLASS_RED_MAGE:
504                 case CLASS_MONK:
505                 {
506                         /* Bad sensing */
507                         if (0 != randint0(95000L / (plev * plev + 40))) return;
508
509                         /* Done */
510                         break;
511                 }
512
513                 case CLASS_PRIEST:
514                 case CLASS_BARD:
515                 case CLASS_ROGUE:
516                 case CLASS_FORCETRAINER:
517                 case CLASS_MINDCRAFTER:
518                 {
519                         /* Good sensing */
520                         if (0 != randint0(20000L / (plev * plev + 40))) return;
521
522                         /* Done */
523                         break;
524                 }
525
526                 case CLASS_MAGE:
527                 case CLASS_HIGH_MAGE:
528                 case CLASS_SORCERER:
529                 case CLASS_MAGIC_EATER:
530                 case CLASS_MIRROR_MASTER:
531                 case CLASS_BLUE_MAGE:
532                 {
533                         /* Good sensing */
534                         if (0 != randint0(9000L / (plev * plev + 40))) return;
535
536                         /* Done */
537                         break;
538                 }
539
540                 case CLASS_TOURIST:
541                 {
542                         /* Good sensing */
543                         if (0 != randint0(20000L / ((plev+50)*(plev+50)))) return;
544
545                         /* Done */
546                         break;
547                 }
548         }
549
550         /*** Sense everything ***/
551
552         /* Check everything */
553         for (i = 0; i < INVEN_TOTAL; i++)
554         {
555                 bool okay = FALSE;
556
557                 o_ptr = &inventory[i];
558
559                 /* Skip empty slots */
560                 if (!o_ptr->k_idx) continue;
561
562                 /* Valid "tval" codes */
563                 switch (o_ptr->tval)
564                 {
565                         case TV_RING:
566                         case TV_AMULET:
567                         case TV_LITE:
568                         case TV_FIGURINE:
569                         {
570                                 okay = TRUE;
571                                 break;
572                         }
573                 }
574
575                 /* Skip non-sense machines */
576                 if (!okay) continue;
577
578                 /* Occasional failure on inventory items */
579                 if ((i < INVEN_RARM) && (0 != randint0(5))) continue;
580
581                 sense_inventory_aux(i, TRUE);
582         }
583 }
584
585
586
587 /*
588  * Go to any level (ripped off from wiz_jump)
589  */
590 static void pattern_teleport(void)
591 {
592         int min_level = 0;
593         int max_level = 99;
594
595         /* Ask for level */
596 #ifdef JP
597 if (get_check("¾¤Î³¬¤Ë¥Æ¥ì¥Ý¡¼¥È¤·¤Þ¤¹¤«¡©"))
598 #else
599         if (get_check("Teleport level? "))
600 #endif
601
602         {
603                 char    ppp[80];
604                 char    tmp_val[160];
605
606                 /* Only downward in ironman mode */
607                 if (ironman_downward)
608                         min_level = dun_level;
609
610                 /* Maximum level */
611                 if (dungeon_type == DUNGEON_ANGBAND)
612                 {
613                         if (dun_level > 100)
614                                 max_level = MAX_DEPTH - 1;
615                         else if (dun_level == 100)
616                                 max_level = 100;
617                 }
618                 else
619                 {
620                         max_level = d_info[dungeon_type].maxdepth;
621                         min_level = d_info[dungeon_type].mindepth;
622                 }
623
624                 /* Prompt */
625 #ifdef JP
626 sprintf(ppp, "¥Æ¥ì¥Ý¡¼¥ÈÀè:(%d-%d)", min_level, max_level);
627 #else
628                 sprintf(ppp, "Teleport to level (%d-%d): ", min_level, max_level);
629 #endif
630
631
632                 /* Default */
633                 sprintf(tmp_val, "%d", dun_level);
634
635                 /* Ask for a level */
636                 if (!get_string(ppp, tmp_val, 10)) return;
637
638                 /* Extract request */
639                 command_arg = atoi(tmp_val);
640         }
641 #ifdef JP
642 else if (get_check("Ä̾ï¥Æ¥ì¥Ý¡¼¥È¡©"))
643 #else
644         else if (get_check("Normal teleport? "))
645 #endif
646
647         {
648                 teleport_player(200);
649                 return;
650         }
651         else
652         {
653                 return;
654         }
655
656         /* Paranoia */
657         if (command_arg < min_level) command_arg = min_level;
658
659         /* Paranoia */
660         if (command_arg > max_level) command_arg = max_level;
661
662         /* Accept request */
663 #ifdef JP
664 msg_format("%d ³¬¤Ë¥Æ¥ì¥Ý¡¼¥È¤·¤Þ¤·¤¿¡£", command_arg);
665 #else
666         msg_format("You teleport to dungeon level %d.", command_arg);
667 #endif
668
669
670         if (autosave_l) do_cmd_save_game(TRUE);
671
672         /* Change level */
673         dun_level = command_arg;
674         prepare_change_floor_mode(CFM_CLEAR_ALL);
675
676         leave_quest_check();
677
678         if (record_stair) do_cmd_write_nikki(NIKKI_PAT_TELE,0,NULL);
679
680         p_ptr->inside_quest = 0;
681         p_ptr->leftbldg = FALSE;
682         energy_use = 0;
683
684         /* Leaving */
685         p_ptr->leaving = TRUE;
686 }
687
688
689 static void wreck_the_pattern(void)
690 {
691         int to_ruin = 0, r_y, r_x;
692
693         if (cave[py][px].feat == FEAT_PATTERN_XTRA2)
694         {
695                 /* Ruined already */
696                 return;
697         }
698
699 #ifdef JP
700 msg_print("¥Ñ¥¿¡¼¥ó¤ò·ì¤Ç±ø¤·¤Æ¤·¤Þ¤Ã¤¿¡ª");
701 msg_print("²¿¤«¶²¤í¤·¤¤»ö¤¬µ¯¤³¤Ã¤¿¡ª");
702 #else
703         msg_print("You bleed on the Pattern!");
704         msg_print("Something terrible happens!");
705 #endif
706
707
708         if (!p_ptr->invuln)
709 #ifdef JP
710 take_hit(DAMAGE_NOESCAPE, damroll(10, 8), "¥Ñ¥¿¡¼¥ó»²õ", -1);
711 #else
712                 take_hit(DAMAGE_NOESCAPE, damroll(10, 8), "corrupting the Pattern", -1);
713 #endif
714
715
716         to_ruin = randint1(45) + 35;
717
718         while (to_ruin--)
719         {
720                 scatter(&r_y, &r_x, py, px, 4, 0);
721
722                 if ((cave[r_y][r_x].feat >= FEAT_PATTERN_START) &&
723                     (cave[r_y][r_x].feat < FEAT_PATTERN_XTRA2))
724                 {
725                         cave_set_feat(r_y, r_x, FEAT_PATTERN_XTRA2);
726                 }
727         }
728
729         cave_set_feat(py, px, FEAT_PATTERN_XTRA2);
730 }
731
732
733 /* Returns TRUE if we are on the Pattern... */
734 static bool pattern_effect(void)
735 {
736         if ((cave[py][px].feat < FEAT_PATTERN_START) ||
737             (cave[py][px].feat > FEAT_PATTERN_XTRA2))
738                 return FALSE;
739
740         if ((prace_is_(RACE_AMBERITE)) &&
741             (p_ptr->cut > 0) && one_in_(10))
742         {
743                 wreck_the_pattern();
744         }
745
746         if (cave[py][px].feat == FEAT_PATTERN_END)
747         {
748                 (void)set_poisoned(0);
749                 (void)set_image(0);
750                 (void)set_stun(0);
751                 (void)set_cut(0);
752                 (void)set_blind(0);
753                 (void)set_afraid(0);
754                 (void)do_res_stat(A_STR);
755                 (void)do_res_stat(A_INT);
756                 (void)do_res_stat(A_WIS);
757                 (void)do_res_stat(A_DEX);
758                 (void)do_res_stat(A_CON);
759                 (void)do_res_stat(A_CHR);
760                 (void)restore_level();
761                 (void)hp_player(1000);
762                 cave_set_feat(py, px, FEAT_PATTERN_OLD);
763 #ifdef JP
764 msg_print("¡Ö¥Ñ¥¿¡¼¥ó¡×¤Î¤³¤ÎÉôʬ¤Ï¾¤ÎÉôʬ¤è¤ê¶¯ÎϤǤʤ¤¤è¤¦¤À¡£");
765 #else
766                 msg_print("This section of the Pattern looks less powerful.");
767 #endif
768
769         }
770
771
772         /*
773          * We could make the healing effect of the
774          * Pattern center one-time only to avoid various kinds
775          * of abuse, like luring the win monster into fighting you
776          * in the middle of the pattern...
777          */
778
779         else if (cave[py][px].feat == FEAT_PATTERN_OLD)
780         {
781                 /* No effect */
782         }
783         else if (cave[py][px].feat == FEAT_PATTERN_XTRA1)
784         {
785                 pattern_teleport();
786         }
787         else if (cave[py][px].feat == FEAT_PATTERN_XTRA2)
788         {
789                 if (!p_ptr->invuln)
790 #ifdef JP
791 take_hit(DAMAGE_NOESCAPE, 200, "²õ¤ì¤¿¡Ö¥Ñ¥¿¡¼¥ó¡×¤òÊ⤤¤¿¥À¥á¡¼¥¸", -1);
792 #else
793                 take_hit(DAMAGE_NOESCAPE, 200, "walking the corrupted Pattern", -1);
794 #endif
795
796         }
797         else
798         {
799                 if ((prace_is_(RACE_AMBERITE)) && !one_in_(2))
800                         return TRUE;
801                 else if (!p_ptr->invuln)
802 #ifdef JP
803 take_hit(DAMAGE_NOESCAPE, damroll(1,3), "¡Ö¥Ñ¥¿¡¼¥ó¡×¤òÊ⤤¤¿¥À¥á¡¼¥¸", -1);
804 #else
805                         take_hit(DAMAGE_NOESCAPE, damroll(1, 3), "walking the Pattern", -1);
806 #endif
807
808         }
809
810         return TRUE;
811 }
812
813
814
815
816
817 /*
818  * Regenerate hit points                                -RAK-
819  */
820 static void regenhp(int percent)
821 {
822         s32b    new_chp, new_chp_frac;
823         int     old_chp;
824
825         if (p_ptr->special_defense & KATA_KOUKIJIN) return;
826         if (p_ptr->action == ACTION_HAYAGAKE) return;
827         /* Save the old hitpoints */
828         old_chp = p_ptr->chp;
829
830         /* Extract the new hitpoints */
831         new_chp = ((long)p_ptr->mhp) * percent + PY_REGEN_HPBASE;
832         p_ptr->chp += (s16b)(new_chp >> 16);   /* div 65536 */
833
834         /* check for overflow */
835         if ((p_ptr->chp < 0) && (old_chp > 0)) p_ptr->chp = MAX_SHORT;
836         new_chp_frac = (new_chp & 0xFFFF) + p_ptr->chp_frac;    /* mod 65536 */
837         if (new_chp_frac >= 0x10000L)
838         {
839                 p_ptr->chp_frac = (u16b)(new_chp_frac - 0x10000L);
840                 p_ptr->chp++;
841         }
842         else
843         {
844                 p_ptr->chp_frac = (u16b)new_chp_frac;
845         }
846
847         /* Fully healed */
848         if (p_ptr->chp >= p_ptr->mhp)
849         {
850                 p_ptr->chp = p_ptr->mhp;
851                 p_ptr->chp_frac = 0;
852         }
853
854         /* Notice changes */
855         if (old_chp != p_ptr->chp)
856         {
857                 /* Redraw */
858                 p_ptr->redraw |= (PR_HP);
859
860                 /* Window stuff */
861                 p_ptr->window |= (PW_PLAYER);
862
863                 wild_regen = 20;
864         }
865 }
866
867
868 /*
869  * Regenerate mana points                               -RAK-
870  */
871 static void regenmana(int percent)
872 {
873         s32b        new_mana, new_mana_frac;
874         int                   old_csp;
875         bool    old_csp_msp = (p_ptr->csp > p_ptr->msp);
876
877         if (p_ptr->special_defense & KATA_KOUKIJIN) return;
878         if ((p_ptr->pclass == CLASS_SAMURAI) && (p_ptr->regenerate)) percent /= 2;
879         old_csp = p_ptr->csp;
880         new_mana = ((long)p_ptr->msp) * percent + PY_REGEN_MNBASE;
881         if (old_csp_msp && (new_mana > 0))
882         {
883                 new_mana *= 32;
884                 p_ptr->csp--;
885                 p_ptr->csp -= (s16b)(new_mana >> 16);   /* div 65536 */
886                 new_mana_frac = p_ptr->csp_frac + 0x10000L - (new_mana & 0xFFFF);
887         }
888         else
889         {
890                 if (old_csp_msp) new_mana += ((((long)p_ptr->msp) * percent + PY_REGEN_MNBASE) * 32);
891                 p_ptr->csp += (s16b)(new_mana >> 16);   /* div 65536 */
892
893                 new_mana_frac = (new_mana & 0xFFFF) + p_ptr->csp_frac;  /* mod 65536 */
894         }
895         if (new_mana_frac >= 0x10000L)
896         {
897                 p_ptr->csp_frac = (u16b)(new_mana_frac - 0x10000L);
898                 p_ptr->csp++;
899         }
900         else
901         {
902                 p_ptr->csp_frac = (u16b)(new_mana_frac);
903         }
904
905         /* check for overflow */
906         if (p_ptr->csp < 0)
907         {
908                 p_ptr->csp = 0;
909                 p_ptr->csp_frac = 0;
910         }
911
912         /* Must set frac to zero even if equal */
913         if ((old_csp_msp && p_ptr->csp < p_ptr->msp) || (!old_csp_msp && p_ptr->csp >= p_ptr->msp))
914         {
915                 p_ptr->csp = p_ptr->msp;
916                 p_ptr->csp_frac = 0;
917         }
918
919         /* Redraw mana */
920         if (old_csp != p_ptr->csp)
921         {
922                 /* Redraw */
923                 p_ptr->redraw |= (PR_MANA);
924
925                 /* Window stuff */
926                 p_ptr->window |= (PW_PLAYER);
927                 p_ptr->window |= (PW_SPELL);
928
929                 wild_regen = 20;
930         }
931 }
932
933
934
935 /*
936  * Regenerate magic
937  */
938 static void regenmagic(int percent)
939 {
940         s32b        new_mana;
941         int i;
942
943         for (i = 0; i < EATER_EXT*2; i++)
944         {
945                 if (!p_ptr->magic_num2[i]) continue;
946                 if (p_ptr->magic_num1[i] == ((long)p_ptr->magic_num2[i] << 16)) continue;
947                 new_mana = ((long)p_ptr->magic_num2[i]+adj_mag_mana[A_INT]+13) * percent / 8;
948                 p_ptr->magic_num1[i] += new_mana;
949
950                 /* Must set frac to zero even if equal */
951                 if (p_ptr->magic_num1[i] > (p_ptr->magic_num2[i] << 16))
952                 {
953                         p_ptr->magic_num1[i] = ((long)p_ptr->magic_num2[i] << 16);
954                 }
955                 wild_regen = 20;
956         }
957         for (i = EATER_EXT*2; i < EATER_EXT*3; i++)
958         {
959                 if (!p_ptr->magic_num1[i]) continue;
960                 if (!p_ptr->magic_num2[i]) continue;
961                 p_ptr->magic_num1[i] -= (long)(p_ptr->magic_num2[i] * (adj_mag_mana[A_INT] + 10)) * EATER_ROD_CHARGE/16;
962                 if (p_ptr->magic_num1[i] < 0) p_ptr->magic_num1[i] = 0;
963                 wild_regen = 20;
964         }
965 }
966
967
968
969
970
971
972 /*
973  * Regenerate the monsters (once per 100 game turns)
974  *
975  * XXX XXX XXX Should probably be done during monster turns.
976  */
977 static void regen_monsters(void)
978 {
979         int i, frac;
980
981
982         /* Regenerate everyone */
983         for (i = 1; i < m_max; i++)
984         {
985                 /* Check the i'th monster */
986                 monster_type *m_ptr = &m_list[i];
987                 monster_race *r_ptr = &r_info[m_ptr->r_idx];
988
989
990                 /* Skip dead monsters */
991                 if (!m_ptr->r_idx) continue;
992
993                 /* Allow regeneration (if needed) */
994                 if (m_ptr->hp < m_ptr->maxhp)
995                 {
996                         /* Hack -- Base regeneration */
997                         frac = m_ptr->maxhp / 100;
998
999                         /* Hack -- Minimal regeneration rate */
1000                         if (!frac) if (one_in_(2)) frac = 1;
1001
1002                         /* Hack -- Some monsters regenerate quickly */
1003                         if (r_ptr->flags2 & RF2_REGENERATE) frac *= 2;
1004
1005                         /* Hack -- Regenerate */
1006                         m_ptr->hp += frac;
1007
1008                         /* Do not over-regenerate */
1009                         if (m_ptr->hp > m_ptr->maxhp) m_ptr->hp = m_ptr->maxhp;
1010
1011                         /* Redraw (later) if needed */
1012                         if (p_ptr->health_who == i) p_ptr->redraw |= (PR_HEALTH);
1013                         if (p_ptr->riding == i) p_ptr->redraw |= (PR_UHEALTH);
1014                 }
1015         }
1016 }
1017
1018
1019 /*
1020  * Regenerate the monsters (once per 100 game turns)
1021  *
1022  * XXX XXX XXX Should probably be done during monster turns.
1023  */
1024 static void regen_captured_monsters(void)
1025 {
1026         int i, frac;
1027         bool heal = FALSE;
1028
1029         /* Regenerate everyone */
1030         for (i = 0; i < INVEN_TOTAL; i++)
1031         {
1032                 monster_race *r_ptr;
1033                 object_type *o_ptr = &inventory[i];
1034
1035                 if (!o_ptr->k_idx) continue;
1036                 if (o_ptr->tval != TV_CAPTURE) continue;
1037                 if (!o_ptr->pval) continue;
1038
1039                 heal = TRUE;
1040
1041                 r_ptr = &r_info[o_ptr->pval];
1042
1043                 /* Allow regeneration (if needed) */
1044                 if (o_ptr->xtra4 < o_ptr->xtra5)
1045                 {
1046                         /* Hack -- Base regeneration */
1047                         frac = o_ptr->xtra5 / 100;
1048
1049                         /* Hack -- Minimal regeneration rate */
1050                         if (!frac) if (one_in_(2)) frac = 1;
1051
1052                         /* Hack -- Some monsters regenerate quickly */
1053                         if (r_ptr->flags2 & RF2_REGENERATE) frac *= 2;
1054
1055                         /* Hack -- Regenerate */
1056                         o_ptr->xtra4 += frac;
1057
1058                         /* Do not over-regenerate */
1059                         if (o_ptr->xtra4 > o_ptr->xtra5) o_ptr->xtra4 = o_ptr->xtra5;
1060                 }
1061         }
1062
1063         if (heal)
1064         {
1065                 /* Combine pack */
1066                 p_ptr->notice |= (PN_COMBINE);
1067
1068                 /* Window stuff */
1069                 p_ptr->window |= (PW_INVEN);
1070                 p_ptr->window |= (PW_EQUIP);
1071                 wild_regen = 20;
1072         }
1073 }
1074
1075
1076 static void notice_lite_change(object_type *o_ptr)
1077 {
1078         /* Hack -- notice interesting fuel steps */
1079         if ((o_ptr->xtra4 < 100) || (!(o_ptr->xtra4 % 100)))
1080         {
1081                 /* Window stuff */
1082                 p_ptr->window |= (PW_EQUIP);
1083         }
1084
1085         /* Hack -- Special treatment when blind */
1086         if (p_ptr->blind)
1087         {
1088                 /* Hack -- save some light for later */
1089                 if (o_ptr->xtra4 == 0) o_ptr->xtra4++;
1090         }
1091
1092         /* The light is now out */
1093         else if (o_ptr->xtra4 == 0)
1094         {
1095                 disturb(0, 0);
1096 #ifdef JP
1097 msg_print("ÌÀ¤«¤ê¤¬¾Ã¤¨¤Æ¤·¤Þ¤Ã¤¿¡ª");
1098 #else
1099                 msg_print("Your light has gone out!");
1100 #endif
1101                 p_ptr->update |= (PU_BONUS);
1102         }
1103
1104         /* The light is getting dim */
1105         else if (o_ptr->name2 == EGO_LITE_LONG)
1106         {
1107                 if ((o_ptr->xtra4 < 50) && (!(o_ptr->xtra4 % 5))
1108                     && (turn % (TURNS_PER_TICK*2)))
1109                 {
1110                         if (disturb_minor) disturb(0, 0);
1111 #ifdef JP
1112 msg_print("ÌÀ¤«¤ê¤¬Èù¤«¤Ë¤Ê¤Ã¤Æ¤­¤Æ¤¤¤ë¡£");
1113 #else
1114                         msg_print("Your light is growing faint.");
1115 #endif
1116
1117                 }
1118         }
1119
1120         /* The light is getting dim */
1121         else if ((o_ptr->xtra4 < 100) && (!(o_ptr->xtra4 % 10)))
1122         {
1123                 if (disturb_minor) disturb(0, 0);
1124 #ifdef JP
1125 msg_print("ÌÀ¤«¤ê¤¬Èù¤«¤Ë¤Ê¤Ã¤Æ¤­¤Æ¤¤¤ë¡£");
1126 #else
1127                 msg_print("Your light is growing faint.");
1128 #endif
1129
1130         }
1131 }
1132
1133
1134 void leave_quest_check(void)
1135 {
1136         /* Save quset number for dungeon pref file ($LEAVING_QUEST) */
1137         leaving_quest = p_ptr->inside_quest;
1138
1139         /* Leaving an 'only once' quest marks it as failed */
1140         if (leaving_quest &&
1141             ((quest[leaving_quest].flags & QUEST_FLAG_ONCE)  || (quest[leaving_quest].type == QUEST_TYPE_RANDOM)) &&
1142             (quest[leaving_quest].status == QUEST_STATUS_TAKEN))
1143         {
1144                 quest[leaving_quest].status = QUEST_STATUS_FAILED;
1145                 quest[leaving_quest].complev = (byte)p_ptr->lev;
1146                 if (quest[leaving_quest].type == QUEST_TYPE_RANDOM)
1147                 {
1148                         r_info[quest[leaving_quest].r_idx].flags1 &= ~(RF1_QUESTOR);
1149                         if (record_rand_quest)
1150                                 do_cmd_write_nikki(NIKKI_RAND_QUEST_F, leaving_quest, NULL);
1151
1152                         /* Floor of random quest will be blocked */
1153                         prepare_change_floor_mode(CFM_NO_RETURN);
1154                 }
1155                 else if (record_fix_quest)
1156                         do_cmd_write_nikki(NIKKI_FIX_QUEST_F, leaving_quest, NULL);
1157         }
1158 }
1159
1160
1161 /*
1162  * Forcibly pseudo-identify an object in the inventory
1163  * (or on the floor)
1164  *
1165  * note: currently this function allows pseudo-id of any object,
1166  * including silly ones like potions & scrolls, which always
1167  * get '{average}'. This should be changed, either to stop such
1168  * items from being pseudo-id'd, or to allow psychometry to
1169  * detect whether the unidentified potion/scroll/etc is
1170  * good (Cure Light Wounds, Restore Strength, etc) or
1171  * bad (Poison, Weakness etc) or 'useless' (Slime Mold Juice, etc).
1172  */
1173 bool psychometry(void)
1174 {
1175         int             item;
1176         object_type     *o_ptr;
1177         char            o_name[MAX_NLEN];
1178         byte            feel;
1179         cptr            q, s;
1180         bool okay = FALSE;
1181         int idx;
1182
1183         item_tester_no_ryoute = TRUE;
1184         /* Get an item */
1185 #ifdef JP
1186 q = "¤É¤Î¥¢¥¤¥Æ¥à¤òÄ´¤Ù¤Þ¤¹¤«¡©";
1187 s = "Ä´¤Ù¤ë¥¢¥¤¥Æ¥à¤¬¤¢¤ê¤Þ¤»¤ó¡£";
1188 #else
1189         q = "Meditate on which item? ";
1190         s = "You have nothing appropriate.";
1191 #endif
1192
1193         if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return (FALSE);
1194
1195         /* Get the item (in the pack) */
1196         if (item >= 0)
1197         {
1198                 o_ptr = &inventory[item];
1199         }
1200
1201         /* Get the item (on the floor) */
1202         else
1203         {
1204                 o_ptr = &o_list[0 - item];
1205         }
1206
1207         /* It is fully known, no information needed */
1208         if (object_known_p(o_ptr))
1209         {
1210 #ifdef JP
1211 msg_print("²¿¤â¿·¤·¤¤¤³¤È¤ÏȽ¤é¤Ê¤«¤Ã¤¿¡£");
1212 #else
1213                 msg_print("You cannot find out anything more about that.");
1214 #endif
1215
1216                 return TRUE;
1217         }
1218
1219         /* Check for a feeling */
1220         feel = value_check_aux1(o_ptr);
1221
1222         /* Get an object description */
1223         object_desc(o_name, o_ptr, FALSE, 0);
1224
1225         /* Skip non-feelings */
1226         if (!feel)
1227         {
1228 #ifdef JP
1229 msg_format("%s¤«¤é¤ÏÆäËÊѤï¤Ã¤¿»ö¤Ï´¶¤¸¤È¤ì¤Ê¤«¤Ã¤¿¡£", o_name);
1230 #else
1231                 msg_format("You do not perceive anything unusual about the %s.", o_name);
1232 #endif
1233
1234                 return TRUE;
1235         }
1236
1237 #ifdef JP
1238 msg_format("%s¤Ï%s¤È¤¤¤¦´¶¤¸¤¬¤¹¤ë...",
1239     o_name,  game_inscriptions[feel]);
1240 #else
1241         msg_format("You feel that the %s %s %s...",
1242                            o_name, ((o_ptr->number == 1) ? "is" : "are"),
1243                            game_inscriptions[feel]);
1244 #endif
1245
1246
1247         /* We have "felt" it */
1248         o_ptr->ident |= (IDENT_SENSE);
1249
1250         /* "Inscribe" it */
1251         o_ptr->feeling = feel;
1252
1253         /* Combine / Reorder the pack (later) */
1254         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
1255
1256         /* Window stuff */
1257         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
1258
1259         /* Valid "tval" codes */
1260         switch (o_ptr->tval)
1261         {
1262         case TV_SHOT:
1263         case TV_ARROW:
1264         case TV_BOLT:
1265         case TV_BOW:
1266         case TV_DIGGING:
1267         case TV_HAFTED:
1268         case TV_POLEARM:
1269         case TV_SWORD:
1270         case TV_BOOTS:
1271         case TV_GLOVES:
1272         case TV_HELM:
1273         case TV_CROWN:
1274         case TV_SHIELD:
1275         case TV_CLOAK:
1276         case TV_SOFT_ARMOR:
1277         case TV_HARD_ARMOR:
1278         case TV_DRAG_ARMOR:
1279         case TV_CARD:
1280         case TV_RING:
1281         case TV_AMULET:
1282         case TV_LITE:
1283         case TV_FIGURINE:
1284                 okay = TRUE;
1285                 break;
1286         }
1287
1288         /* Auto-inscription/destroy */
1289         idx = is_autopick(o_ptr);
1290         auto_inscribe_item(item, idx);
1291         if (okay && destroy_feeling)
1292                 auto_destroy_item(item, idx);
1293
1294         /* Something happened */
1295         return (TRUE);
1296 }
1297
1298
1299 static void gere_music(s32b music)
1300 {
1301         switch(music)
1302         {
1303                 case MUSIC_SLOW:
1304                         slow_monsters();
1305                         break;
1306                 case MUSIC_STUN:
1307                         stun_monsters(damroll(p_ptr->lev/10,2));
1308                         break;
1309                 case MUSIC_L_LIFE:
1310                         hp_player(damroll(2,6));
1311                         break;
1312                 case MUSIC_FEAR:
1313                         project_hack(GF_TURN_ALL, p_ptr->lev);
1314                         break;
1315                 case MUSIC_PSI:
1316                         project_hack(GF_PSI, randint1(p_ptr->lev * 3 / 2));
1317                         break;
1318                 case MUSIC_ID:
1319                         project(0, 1, py, px, 0, GF_IDENTIFY, PROJECT_ITEM, -1);
1320                         break;
1321                 case MUSIC_CONF:
1322                         confuse_monsters(p_ptr->lev * 2);
1323                         break;
1324                 case MUSIC_SOUND:
1325                         project_hack(GF_SOUND, damroll(10 + p_ptr->lev/5,7));
1326                         break;
1327                 case MUSIC_CHARM:
1328                         charm_monsters(damroll(10 + p_ptr->lev/15,6));
1329                         break;
1330                 case MUSIC_WALL:
1331                         project(0, 0, py, px,
1332                                 0, GF_DISINTEGRATE, PROJECT_KILL | PROJECT_ITEM | PROJECT_HIDE, -1);
1333                         break;
1334                 case MUSIC_DISPEL:
1335                         dispel_monsters(randint1(p_ptr->lev * 3));
1336                         dispel_evil(randint1(p_ptr->lev * 3));
1337                         break;
1338                 case MUSIC_SARUMAN:
1339                         slow_monsters();
1340                         sleep_monsters();
1341                         break;
1342                 case MUSIC_QUAKE:
1343                         earthquake(py, px, 10);
1344                         break;
1345                 case MUSIC_STASIS:
1346                         stasis_monsters(p_ptr->lev * 4);
1347                         break;
1348                 case MUSIC_SHERO:
1349                         dispel_monsters(randint1(p_ptr->lev * 3));
1350                         break;
1351                 case MUSIC_H_LIFE:
1352                         hp_player(damroll(15,10));
1353                         set_stun(0);
1354                         set_cut(0);
1355                         break;
1356                 case MUSIC_DETECT+19:
1357                         wiz_lite(FALSE);
1358                 case MUSIC_DETECT+11:
1359                 case MUSIC_DETECT+12:
1360                 case MUSIC_DETECT+13:
1361                 case MUSIC_DETECT+14:
1362                 case MUSIC_DETECT+15:
1363                 case MUSIC_DETECT+16:
1364                 case MUSIC_DETECT+17:
1365                 case MUSIC_DETECT+18:
1366                         map_area(DETECT_RAD_MAP);
1367                         if ((p_ptr->lev > 39) && (music < MUSIC_DETECT+19)) p_ptr->magic_num1[0] = music+1;
1368                 case MUSIC_DETECT+6:
1369                 case MUSIC_DETECT+7:
1370                 case MUSIC_DETECT+8:
1371                 case MUSIC_DETECT+9:
1372                 case MUSIC_DETECT+10:
1373                         /* There are too many hidden treasure.  So... */
1374                         /* detect_treasure(DETECT_RAD_DEFAULT); */
1375                         detect_objects_gold(DETECT_RAD_DEFAULT);
1376                         detect_objects_normal(DETECT_RAD_DEFAULT);
1377                         if ((p_ptr->lev > 24) && (music < MUSIC_DETECT+11)) p_ptr->magic_num1[0] = music+1;
1378                 case MUSIC_DETECT+3:
1379                 case MUSIC_DETECT+4:
1380                 case MUSIC_DETECT+5:
1381                         detect_monsters_invis(DETECT_RAD_DEFAULT);
1382                         detect_monsters_normal(DETECT_RAD_DEFAULT);
1383                         if ((p_ptr->lev > 19) && (music < MUSIC_DETECT+6)) p_ptr->magic_num1[0] = music+1;
1384                 case MUSIC_DETECT:
1385                 case MUSIC_DETECT+1:
1386                 case MUSIC_DETECT+2:
1387                         detect_traps(DETECT_RAD_DEFAULT, TRUE);
1388                         detect_doors(DETECT_RAD_DEFAULT);
1389                         detect_stairs(DETECT_RAD_DEFAULT);
1390                         if ((p_ptr->lev > 14)  && (music  < MUSIC_DETECT+3)) p_ptr->magic_num1[0] = music+1;
1391                         break;
1392         }
1393 }
1394
1395 /*
1396  * If player has inscribed the object with "!!", let him know when it's
1397  * recharged. -LM-
1398  */
1399 static void recharged_notice(object_type *o_ptr)
1400 {
1401         char o_name[MAX_NLEN];
1402
1403         cptr s;
1404
1405         /* No inscription */
1406         if (!o_ptr->inscription) return;
1407
1408         /* Find a '!' */
1409         s = strchr(quark_str(o_ptr->inscription), '!');
1410
1411         /* Process notification request. */
1412         while (s)
1413         {
1414                 /* Find another '!' */
1415                 if (s[1] == '!')
1416                 {
1417                         /* Describe (briefly) */
1418                         object_desc(o_name, o_ptr, FALSE, 0);
1419
1420                         /* Notify the player */
1421 #ifdef JP
1422                         msg_format("%s¤ÏºÆ½¼Å¶¤µ¤ì¤¿¡£", o_name);
1423 #else
1424                         if (o_ptr->number > 1)
1425                                 msg_format("Your %s are recharged.", o_name);
1426                         else
1427                                 msg_format("Your %s is recharged.", o_name);
1428 #endif
1429
1430                         disturb(0, 0);
1431
1432                         /* Done. */
1433                         return;
1434                 }
1435
1436                 /* Keep looking for '!'s */
1437                 s = strchr(s + 1, '!');
1438         }
1439 }
1440
1441
1442 static void check_music(void)
1443 {
1444         magic_type *s_ptr;
1445         int spell;
1446         u32b need_mana;
1447
1448         /* Music singed by player */
1449         if (p_ptr->pclass != CLASS_BARD) return;
1450         if (!p_ptr->magic_num1[0] && !p_ptr->magic_num1[1]) return;
1451
1452         spell = p_ptr->magic_num2[0];
1453         s_ptr = &technic_info[REALM_MUSIC - MIN_TECHNIC][spell];
1454
1455         need_mana = mod_need_mana(s_ptr->smana, spell, REALM_MUSIC);
1456         need_mana *= 0x8000;
1457         if (((u32b)p_ptr->csp < (need_mana / 0x10000)) || (p_ptr->anti_magic))
1458         {
1459                 stop_singing();
1460                 return;
1461         }
1462         else
1463         {
1464                 p_ptr->csp -= (u16b) (need_mana / 0x10000);
1465                 need_mana = (need_mana & 0xffff);
1466                 if ((u32b)p_ptr->csp_frac < need_mana)
1467                 {
1468                         p_ptr->csp--;
1469                         p_ptr->csp_frac += (u16b)(0x10000L - need_mana);
1470                 }
1471                 else
1472                 {
1473                         p_ptr->csp_frac -= (u16b)need_mana;
1474                 }
1475
1476                 p_ptr->redraw |= PR_MANA;
1477                 if (p_ptr->magic_num1[1])
1478                 {
1479                         p_ptr->magic_num1[0] = p_ptr->magic_num1[1];
1480                         p_ptr->magic_num1[1] = 0;
1481 #ifdef JP
1482                         msg_print("²Î¤òºÆ³«¤·¤¿¡£");
1483 #else
1484                         msg_print("You restart singing.");
1485 #endif
1486                         p_ptr->action = ACTION_SING;
1487
1488                         /* Recalculate bonuses */
1489                         p_ptr->update |= (PU_BONUS | PU_HP);
1490
1491                         /* Redraw status bar */
1492                         p_ptr->redraw |= (PR_STATUS);
1493                 }
1494         }
1495         if (p_ptr->spell_exp[spell] < SPELL_EXP_BEGINNER)
1496                 p_ptr->spell_exp[spell] += 5;
1497         else if(p_ptr->spell_exp[spell] < SPELL_EXP_SKILLED)
1498         { if (one_in_(2) && (dun_level > 4) && ((dun_level + 10) > p_ptr->lev)) p_ptr->spell_exp[spell] += 1; }
1499         else if(p_ptr->spell_exp[spell] < SPELL_EXP_EXPERT)
1500         { if (one_in_(5) && ((dun_level + 5) > p_ptr->lev) && ((dun_level + 5) > s_ptr->slevel)) p_ptr->spell_exp[spell] += 1; }
1501         else if(p_ptr->spell_exp[spell] < SPELL_EXP_MASTER)
1502         { if (one_in_(5) && ((dun_level + 5) > p_ptr->lev) && (dun_level > s_ptr->slevel)) p_ptr->spell_exp[spell] += 1; }
1503
1504         gere_music(p_ptr->magic_num1[0]);
1505 }
1506
1507 /* Choose one of items that have cursed flag */
1508 static object_type *choose_cursed_obj_name(u32b flag)
1509 {
1510         int i;
1511         int choices[INVEN_TOTAL-INVEN_RARM];
1512         int number = 0;
1513
1514         /* Paranoia -- Player has no warning-item */
1515         if (!(p_ptr->cursed & flag)) return NULL;
1516
1517         /* Search Inventry */
1518         for (i = INVEN_RARM; i < INVEN_TOTAL; i++)
1519         {
1520                 object_type *o_ptr = &inventory[i];
1521
1522                 if (o_ptr->curse_flags & flag)
1523                 {
1524                         choices[number] = i;
1525                         number++;
1526                 }
1527         }
1528
1529         /* Choice one of them */
1530         return (&inventory[choices[randint0(number)]]);
1531 }
1532
1533
1534 /*
1535  * Handle certain things once every 10 game turns
1536  */
1537 static void process_world(void)
1538 {
1539         int x, y, i, j;
1540         int regen_amount;
1541         bool cave_no_regen = FALSE;
1542         int upkeep_factor = 0;
1543         cave_type *c_ptr;
1544         object_type *o_ptr;
1545         int temp;
1546         object_kind *k_ptr;
1547         const int dec_count = (easy_band ? 2 : 1);
1548
1549         int day, hour, min, prev_min;
1550
1551         s32b len = TURNS_PER_TICK * TOWN_DAWN;
1552         s32b tick = turn % len + len / 4;
1553
1554         extract_day_hour_min(&day, &hour, &min);
1555         prev_min = (1440 * (tick - TURNS_PER_TICK) / len) % 60;
1556
1557         if ((turn - old_turn == (150 - dun_level) * TURNS_PER_TICK)
1558             && (dun_level) &&
1559             !(quest_number(dun_level) && ((quest_number(dun_level) < MIN_RANDOM_QUEST) && !(quest_number(dun_level) == QUEST_OBERON || quest_number(dun_level) == QUEST_SERPENT || !(quest[quest_number(dun_level)].flags & QUEST_FLAG_PRESET)))) &&
1560             !(p_ptr->inside_battle))
1561                 do_cmd_feeling();
1562
1563         if (p_ptr->inside_battle && !p_ptr->leaving)
1564         {
1565
1566                 int i2, j2;
1567                 int win_m_idx = 0;
1568                 int number_mon = 0;
1569
1570                 /* Count all hostile monsters */
1571                 for (i2 = 0; i2 < cur_wid; ++i2)
1572                         for (j2 = 0; j2 < cur_hgt; j2++)
1573                                 if ((cave[j2][i2].m_idx > 0) && (cave[j2][i2].m_idx != p_ptr->riding))
1574                                 {
1575                                         number_mon++;
1576                                         win_m_idx = cave[j2][i2].m_idx;
1577                                 }
1578
1579                 if (number_mon == 0)
1580                 {
1581 #ifdef JP
1582 msg_print("ÁêÂǤÁ¤Ë½ª¤ï¤ê¤Þ¤·¤¿¡£");
1583 #else
1584                         msg_print("They have kill each other at the same time.");
1585 #endif
1586                         msg_print(NULL);
1587                         p_ptr->energy_need = 0;
1588                         battle_monsters();
1589                 }
1590                 else if ((number_mon-1) == 0)
1591                 {
1592                         char m_name[80];
1593                         monster_type *wm_ptr;
1594
1595                         wm_ptr = &m_list[win_m_idx];
1596
1597                         monster_desc(m_name, wm_ptr, 0);
1598 #ifdef JP
1599 msg_format("%s¤¬¾¡Íø¤·¤¿¡ª", m_name);
1600 #else
1601                         msg_format("%s is winner!", m_name);
1602 #endif
1603                         msg_print(NULL);
1604
1605                         if (win_m_idx == (sel_monster+1))
1606                         {
1607 #ifdef JP
1608 msg_print("¤ª¤á¤Ç¤È¤¦¤´¤¶¤¤¤Þ¤¹¡£");
1609 #else
1610                                 msg_print("Congratulations.");
1611 #endif
1612 #ifdef JP
1613 msg_format("%d¡ð¤ò¼õ¤±¼è¤Ã¤¿¡£", battle_odds);
1614 #else
1615                                 msg_format("You received %d gold.", battle_odds);
1616 #endif
1617                         p_ptr->au += battle_odds;
1618                         }
1619                         else
1620                         {
1621 #ifdef JP
1622 msg_print("»ÄÇ°¤Ç¤·¤¿¡£");
1623 #else
1624                                 msg_print("You lost gold.");
1625 #endif
1626                         }
1627                         msg_print(NULL);
1628                         p_ptr->energy_need = 0;
1629                         battle_monsters();
1630                 }
1631                 else if(turn - old_turn == 150*TURNS_PER_TICK)
1632                 {
1633 #ifdef JP
1634 msg_print("¿½¤·Ê¬¤±¤¢¤ê¤Þ¤»¤ó¤¬¡¢¤³¤Î¾¡Éé¤Ï°ú¤­Ê¬¤±¤È¤µ¤»¤Æ¤¤¤¿¤À¤­¤Þ¤¹¡£");
1635 #else
1636                         msg_format("This battle have ended in a draw.");
1637 #endif
1638                         p_ptr->au += kakekin;
1639                         msg_print(NULL);
1640                         p_ptr->energy_need = 0;
1641                         battle_monsters();
1642                 }
1643         }
1644
1645         /* Every 20 game turns */
1646         if (turn % TURNS_PER_TICK) return;
1647
1648         /*** Check the Time and Load ***/
1649
1650         if (!(turn % (50*TURNS_PER_TICK)))
1651         {
1652                 /* Check time and load */
1653                 if ((0 != check_time()) || (0 != check_load()))
1654                 {
1655                         /* Warning */
1656                         if (closing_flag <= 2)
1657                         {
1658                                 /* Disturb */
1659                                 disturb(0, 0);
1660
1661                                 /* Count warnings */
1662                                 closing_flag++;
1663
1664                                 /* Message */
1665 #ifdef JP
1666 msg_print("¥¢¥ó¥°¥Ð¥ó¥É¤Ø¤ÎÌ礬ÊĤ¸¤«¤«¤Ã¤Æ¤¤¤Þ¤¹...");
1667 msg_print("¥²¡¼¥à¤ò½ªÎ»¤¹¤ë¤«¥»¡¼¥Ö¤¹¤ë¤«¤·¤Æ²¼¤µ¤¤¡£");
1668 #else
1669                                 msg_print("The gates to ANGBAND are closing...");
1670                                 msg_print("Please finish up and/or save your game.");
1671 #endif
1672
1673                         }
1674
1675                         /* Slam the gate */
1676                         else
1677                         {
1678                                 /* Message */
1679 #ifdef JP
1680 msg_print("º£¡¢¥¢¥ó¥°¥Ð¥ó¥É¤Ø¤ÎÌ礬ÊĤ¶¤µ¤ì¤Þ¤·¤¿¡£");
1681 #else
1682                                 msg_print("The gates to ANGBAND are now closed.");
1683 #endif
1684
1685
1686                                 /* Stop playing */
1687                                 p_ptr->playing = FALSE;
1688
1689                                 /* Leaving */
1690                                 p_ptr->leaving = TRUE;
1691                         }
1692                 }
1693         }
1694
1695         /*** Attempt timed autosave ***/
1696         if (autosave_t && autosave_freq && !p_ptr->inside_battle)
1697         {
1698                 if (!(turn % ((s32b)autosave_freq * TURNS_PER_TICK)))
1699                         do_cmd_save_game(TRUE);
1700         }
1701
1702         if (mon_fight)
1703         {
1704 #ifdef JP
1705                 msg_print("²¿¤«¤¬Ê¹¤³¤¨¤¿¡£");
1706 #else
1707                 msg_print("You hear noise.");
1708 #endif
1709         }
1710
1711         /*** Handle the wilderness/town (sunshine) ***/
1712
1713         /* While in town/wilderness */
1714         if (!dun_level && !p_ptr->inside_quest && !p_ptr->inside_battle && !p_ptr->inside_arena && !p_ptr->wild_mode)
1715         {
1716                 /* Hack -- Daybreak/Nighfall in town */
1717                 if (!(turn % ((TURNS_PER_TICK * TOWN_DAWN) / 2)))
1718                 {
1719                         bool dawn;
1720
1721                         /* Check for dawn */
1722                         dawn = (!(turn % (TURNS_PER_TICK * TOWN_DAWN)));
1723
1724                         /* Day breaks */
1725                         if (dawn)
1726                         {
1727                                 /* Message */
1728 #ifdef JP
1729 msg_print("Ì뤬ÌÀ¤±¤¿¡£");
1730 #else
1731                                 msg_print("The sun has risen.");
1732 #endif
1733
1734
1735                                 /* Hack -- Scan the town */
1736                                 for (y = 0; y < cur_hgt; y++)
1737                                 {
1738                                         for (x = 0; x < cur_wid; x++)
1739                                         {
1740                                                 /* Get the cave grid */
1741                                                 c_ptr = &cave[y][x];
1742
1743                                                 /* Assume lit */
1744                                                 c_ptr->info |= (CAVE_GLOW);
1745
1746                                                 /* Hack -- Memorize lit grids if allowed */
1747                                                 if (view_perma_grids) c_ptr->info |= (CAVE_MARK);
1748
1749                                                 /* Hack -- Notice spot */
1750                                                 note_spot(y, x);
1751                                         }
1752                                 }
1753                         }
1754
1755                         /* Night falls */
1756                         else
1757                         {
1758                                 /* Message */
1759 #ifdef JP
1760 msg_print("Æü¤¬ÄÀ¤ó¤À¡£");
1761 #else
1762                                 msg_print("The sun has fallen.");
1763 #endif
1764
1765
1766                                 /* Hack -- Scan the town */
1767                                 for (y = 0; y < cur_hgt; y++)
1768                                 {
1769                                         for (x = 0; x < cur_wid; x++)
1770                                         {
1771                                                 /* Get the cave grid */
1772                                                 c_ptr = &cave[y][x];
1773
1774                                                 /* Darken "boring" features */
1775                                                 if ((c_ptr->feat <= FEAT_INVIS) ||
1776                                                     ((c_ptr->feat >= FEAT_DEEP_WATER) &&
1777                                                         (c_ptr->feat <= FEAT_MOUNTAIN) &&
1778                                                      (c_ptr->feat != FEAT_MUSEUM)) ||
1779                                                     (x == 0) || (x == cur_wid-1) ||
1780                                                     (y == 0) || (y == cur_hgt-1))
1781                                                 {
1782                                                         /* Forget the grid */
1783                                                         if (!is_mirror_grid(c_ptr)) c_ptr->info &= ~(CAVE_GLOW | CAVE_MARK);
1784
1785                                                         /* Hack -- Notice spot */
1786                                                         note_spot(y, x);
1787                                                 }
1788                                         }
1789
1790                                         /* Glow deep lava */
1791                                         glow_deep_lava();
1792                                 }
1793                         }
1794
1795                         /* Update the monsters */
1796                         p_ptr->update |= (PU_MONSTERS | PU_MON_LITE);
1797
1798                         /* Redraw map */
1799                         p_ptr->redraw |= (PR_MAP);
1800
1801                         /* Window stuff */
1802                         p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
1803                 }
1804         }
1805
1806         /* Set back the rewards once a day */
1807         if (!(turn % (TURNS_PER_TICK*10 * STORE_TURNS)))
1808         {
1809                 int n;
1810
1811                 /* Reset the rewards */
1812                 for (n = 0; n < MAX_BACT; n++)
1813                 {
1814                         p_ptr->rewards[n] = FALSE;
1815                 }
1816
1817                 /* Message */
1818 #ifdef JP
1819 if (cheat_xtra) msg_print("Êó½·¤ò¥ê¥»¥Ã¥È");
1820 #else
1821                 if (cheat_xtra) msg_print("Rewards reset.");
1822 #endif
1823
1824         }
1825
1826
1827         /*** Process the monsters ***/
1828
1829         /* Check for creature generation. */
1830         if (one_in_(d_info[dungeon_type].max_m_alloc_chance) &&
1831             !p_ptr->inside_arena && !p_ptr->inside_quest && !p_ptr->inside_battle)
1832         {
1833                 /* Make a new monster */
1834                 (void)alloc_monster(MAX_SIGHT + 5, 0);
1835         }
1836
1837         /* Hack -- Check for creature regeneration */
1838         if (!(turn % (TURNS_PER_TICK*10)) && !p_ptr->inside_battle) regen_monsters();
1839         if (!(turn % (TURNS_PER_TICK*3))) regen_captured_monsters();
1840
1841
1842         /*** Damage over Time ***/
1843
1844         /* Take damage from poison */
1845         if (p_ptr->poisoned && !p_ptr->invuln)
1846         {
1847                 /* Take damage */
1848 #ifdef JP
1849 take_hit(DAMAGE_NOESCAPE, 1, "ÆÇ", -1);
1850 #else
1851                 take_hit(DAMAGE_NOESCAPE, 1, "poison", -1);
1852 #endif
1853
1854         }
1855
1856
1857         /* (Vampires) Take damage from sunlight */
1858         if (prace_is_(RACE_VAMPIRE) || (p_ptr->mimic_form == MIMIC_VAMPIRE))
1859         {
1860                 if (!dun_level && !p_ptr->resist_lite && !p_ptr->invuln && is_daytime())
1861                 {
1862                         if (cave[py][px].info & CAVE_GLOW)
1863                         {
1864                                 /* Take damage */
1865 #ifdef JP
1866 msg_print("Æü¸÷¤¬¤¢¤Ê¤¿¤Î¥¢¥ó¥Ç¥Ã¥É¤ÎÆùÂΤò¾Æ¤­¾Ç¤¬¤·¤¿¡ª");
1867 take_hit(DAMAGE_NOESCAPE, 1, "Æü¸÷", -1);
1868 #else
1869                                 msg_print("The sun's rays scorch your undead flesh!");
1870                                 take_hit(DAMAGE_NOESCAPE, 1, "sunlight", -1);
1871 #endif
1872
1873                                 cave_no_regen = TRUE;
1874                         }
1875                 }
1876
1877                 if (inventory[INVEN_LITE].tval && (inventory[INVEN_LITE].name2 != EGO_LITE_DARKNESS) &&
1878                     !p_ptr->resist_lite)
1879                 {
1880                         object_type * o_ptr = &inventory[INVEN_LITE];
1881                         char o_name [MAX_NLEN];
1882                         char ouch [MAX_NLEN+40];
1883
1884                         /* Get an object description */
1885                         object_desc(o_name, o_ptr, FALSE, 0);
1886
1887 #ifdef JP
1888 msg_format("%s¤¬¤¢¤Ê¤¿¤Î¥¢¥ó¥Ç¥Ã¥É¤ÎÆùÂΤò¾Æ¤­¾Ç¤¬¤·¤¿¡ª", o_name);
1889 #else
1890                         msg_format("The %s scorches your undead flesh!", o_name);
1891 #endif
1892
1893
1894                         cave_no_regen = TRUE;
1895
1896                         /* Get an object description */
1897                         object_desc(o_name, o_ptr, TRUE, 0);
1898
1899 #ifdef JP
1900 sprintf(ouch, "%s¤òÁõÈ÷¤·¤¿¥À¥á¡¼¥¸", o_name);
1901 #else
1902                         sprintf(ouch, "wielding %s", o_name);
1903 #endif
1904
1905                         if (!p_ptr->invuln) take_hit(DAMAGE_NOESCAPE, 1, ouch, -1);
1906                 }
1907         }
1908
1909         if ((cave[py][px].feat == FEAT_SHAL_LAVA) &&
1910                 !p_ptr->invuln && !p_ptr->immune_fire && !p_ptr->ffall)
1911         {
1912                 int damage = 3000 + randint0(2000);
1913
1914                 if (prace_is_(RACE_ENT)) damage += damage/3;
1915
1916                 if (p_ptr->resist_fire) damage = damage / 3;
1917                 if (p_ptr->oppose_fire) damage = damage / 3;
1918                 damage = damage / 100 + (randint0(100) < (damage % 100));
1919
1920                 if (damage)
1921                 {
1922                         /* Take damage */
1923 #ifdef JP
1924 msg_print("ÍÏ´ä¤Ç²Ð½ý¤·¤¿¡ª");
1925 take_hit(DAMAGE_NOESCAPE, damage, "Àõ¤¤ÍÏ´äή", -1);
1926 #else
1927                         msg_print("The lava burns you!");
1928                         take_hit(DAMAGE_NOESCAPE, damage, "shallow lava", -1);
1929 #endif
1930
1931                         cave_no_regen = TRUE;
1932                 }
1933         }
1934
1935         else if ((cave[py][px].feat == FEAT_DEEP_LAVA) &&
1936                 !p_ptr->invuln && !p_ptr->immune_fire)
1937         {
1938                 int damage = 6000 + randint0(4000);
1939
1940                 cptr message;
1941                 cptr hit_from;
1942
1943                 if (p_ptr->resist_fire) damage = damage / 3;
1944                 if (p_ptr->oppose_fire) damage = damage / 3;
1945
1946                 if (p_ptr->ffall)
1947                 {
1948                         damage = damage / 5;
1949
1950 #ifdef JP
1951 message = "Ç®¤Ç²Ð½ý¤·¤¿¡ª";
1952 hit_from = "¿¼¤¤ÍÏ´äή¤Î¾å¤ËÉâÍ·¤·¤¿¥À¥á¡¼¥¸";
1953 #else
1954                         message = "The heat burns you!";
1955                         hit_from = "flying over deep lava";
1956 #endif
1957
1958                 }
1959                 else
1960                 {
1961 #ifdef JP
1962 message = "ÍÏ´ä¤Ç²Ð½ý¤·¤¿¡ª";
1963 hit_from = "¿¼¤¤ÍÏ´äή";
1964 #else
1965                         message = "The lava burns you!";
1966                         hit_from = "deep lava";
1967 #endif
1968
1969                 }
1970
1971                 damage = damage / 100 + (randint0(100) < (damage % 100));
1972                 if (damage)
1973                 {
1974                         /* Take damage */
1975                         msg_print(message);
1976                         take_hit(DAMAGE_NOESCAPE, damage, hit_from, -1);
1977
1978                         cave_no_regen = TRUE;
1979                 }
1980         }
1981
1982         else if ((cave[py][px].feat == FEAT_DEEP_WATER) && !p_ptr->ffall && !p_ptr->can_swim)
1983         {
1984                 if (p_ptr->total_weight > (((u32b)adj_str_wgt[p_ptr->stat_ind[A_STR]] * (p_ptr->pclass == CLASS_BERSERKER ? 150 : 100)) / 2))
1985                 {
1986                         /* Take damage */
1987 #ifdef JP
1988 msg_print("Å®¤ì¤Æ¤¤¤ë¡ª");
1989 take_hit(DAMAGE_NOESCAPE, randint1(p_ptr->lev), "Å®¤ì", -1);
1990 #else
1991                         msg_print("You are drowning!");
1992                         take_hit(DAMAGE_NOESCAPE, randint1(p_ptr->lev), "drowning", -1);
1993 #endif
1994
1995                         cave_no_regen = TRUE;
1996                 }
1997         }
1998
1999         if (p_ptr->riding)
2000         {
2001                 int damage;
2002                 if ((r_info[m_list[p_ptr->riding].r_idx].flags2 & RF2_AURA_FIRE) && !p_ptr->immune_fire)
2003                 {
2004                         damage = r_info[m_list[p_ptr->riding].r_idx].level / 2;
2005                         if (prace_is_(RACE_ENT)) damage += damage/3;
2006                         if (p_ptr->resist_fire) damage = damage / 3;
2007                         if (p_ptr->oppose_fire) damage = damage / 3;
2008 #ifdef JP
2009 msg_print("Ç®¤¤¡ª");
2010 take_hit(DAMAGE_NOESCAPE, damage, "±ê¤Î¥ª¡¼¥é", -1);
2011 #else
2012                         msg_print("It's hot!");
2013                         take_hit(DAMAGE_NOESCAPE, damage, "Fire aura", -1);
2014 #endif
2015                 }
2016                 if ((r_info[m_list[p_ptr->riding].r_idx].flags2 & RF2_AURA_ELEC) && !p_ptr->immune_elec)
2017                 {
2018                         damage = r_info[m_list[p_ptr->riding].r_idx].level / 2;
2019                         if (p_ptr->resist_elec) damage = damage / 3;
2020                         if (p_ptr->oppose_elec) damage = damage / 3;
2021 #ifdef JP
2022 msg_print("Äˤ¤¡ª");
2023 take_hit(DAMAGE_NOESCAPE, damage, "Åŵ¤¤Î¥ª¡¼¥é", -1);
2024 #else
2025                         msg_print("It hurts!");
2026                         take_hit(DAMAGE_NOESCAPE, damage, "Elec aura", -1);
2027 #endif
2028                 }
2029                 if ((r_info[m_list[p_ptr->riding].r_idx].flags3 & RF3_AURA_COLD) && !p_ptr->immune_cold)
2030                 {
2031                         damage = r_info[m_list[p_ptr->riding].r_idx].level / 2;
2032                         if (p_ptr->resist_cold) damage = damage / 3;
2033                         if (p_ptr->oppose_cold) damage = damage / 3;
2034 #ifdef JP
2035 msg_print("Î䤿¤¤¡ª");
2036 take_hit(DAMAGE_NOESCAPE, damage, "Î䵤¤Î¥ª¡¼¥é", -1);
2037 #else
2038                         msg_print("It's cold!");
2039                         take_hit(DAMAGE_NOESCAPE, damage, "Cold aura", -1);
2040 #endif
2041                 }
2042         }
2043
2044         /* Spectres -- take damage when moving through walls */
2045         /*
2046          * Added: ANYBODY takes damage if inside through walls
2047          * without wraith form -- NOTE: Spectres will never be
2048          * reduced below 0 hp by being inside a stone wall; others
2049          * WILL BE!
2050          */
2051         if (!cave_floor_bold(py, px))
2052         {
2053                 /* Player can walk through trees */
2054                 if ((cave[py][px].feat == FEAT_TREES) || ((cave[py][px].feat == FEAT_MOUNTAIN) && !dun_level && p_ptr->ffall))
2055                 {
2056                         /* Do nothing */
2057                 }
2058                 else if (!p_ptr->invuln && !p_ptr->wraith_form && !p_ptr->kabenuke &&
2059                     ((p_ptr->chp > (p_ptr->lev / 5)) || !p_ptr->pass_wall))
2060                 {
2061                         cptr dam_desc;
2062
2063                         cave_no_regen = TRUE;
2064
2065                         if (p_ptr->pass_wall)
2066                         {
2067 #ifdef JP
2068 msg_print("ÂΤÎʬ»Ò¤¬Ê¬²ò¤·¤¿µ¤¤¬¤¹¤ë¡ª");
2069 dam_desc = "Ì©ÅÙ";
2070 #else
2071                                 msg_print("Your molecules feel disrupted!");
2072                                 dam_desc = "density";
2073 #endif
2074
2075                         }
2076                         else
2077                         {
2078 #ifdef JP
2079 msg_print("Êø¤ì¤¿´ä¤Ë²¡¤·ÄÙ¤µ¤ì¤¿¡ª");
2080 dam_desc = "¹Å¤¤´ä";
2081 #else
2082                                 msg_print("You are being crushed!");
2083                                 dam_desc = "solid rock";
2084 #endif
2085
2086                         }
2087
2088                         take_hit(DAMAGE_NOESCAPE, 1 + (p_ptr->lev / 5), dam_desc, -1);
2089                 }
2090         }
2091
2092         if (!hour && !min)
2093         {
2094                 monster_race *r_ptr;
2095
2096                 if (min != prev_min)
2097                 {
2098                         int max_dl = 3;
2099                         bool old_inside_battle = p_ptr->inside_battle;
2100
2101                         do_cmd_write_nikki(NIKKI_HIGAWARI, 0, NULL);
2102
2103                         p_ptr->inside_battle = TRUE;
2104                         get_mon_num_prep(NULL,NULL);
2105
2106                         for (i = 0; i < max_d_idx; i++)
2107                         {
2108                                 if (max_dlv[i] < d_info[i].mindepth) continue;
2109                                 if (max_dl < max_dlv[i]) max_dl = max_dlv[i];
2110                         }
2111                         while (1)
2112                         {
2113                                 today_mon = get_mon_num(max_dl);
2114                                 r_ptr = &r_info[today_mon];
2115
2116                                 if (r_ptr->flags1 & RF1_UNIQUE) continue;
2117                                 if (r_ptr->flags7 & (RF7_UNIQUE_7 | RF7_UNIQUE2)) continue;
2118                                 if (r_ptr->flags2 & (RF2_MULTIPLY)) continue;
2119                                 if (!(r_ptr->flags9 & RF9_DROP_CORPSE) || !(r_ptr->flags9 & RF9_DROP_SKELETON)) continue;
2120                                 if (r_ptr->level < MIN(max_dl/2, 40)) continue;
2121                                 if (r_ptr->rarity > 10) continue;
2122                                 if (r_ptr->level == 0) continue;
2123                                 break;
2124                         }
2125                         p_ptr->today_mon = 0;
2126                         p_ptr->inside_battle = old_inside_battle;
2127                 }
2128         }
2129
2130         /* Nightmare mode activates the TY_CURSE at midnight */
2131         if (ironman_nightmare)
2132         {
2133                 /* Require exact minute */
2134                 if (min != prev_min)
2135                 {
2136                         /* Every 15 minutes after 11:00 pm */
2137                         if ((hour == 23) && !(min % 15))
2138                         {
2139                                 /* Disturbing */
2140                                 disturb(0, 0);
2141
2142                                 switch (min / 15)
2143                                 {
2144                                         case 0:
2145                                         {
2146 #ifdef JP
2147 msg_print("±ó¤¯¤ÇÉÔµ¤Ì£¤Ê¾â¤Î²»¤¬ÌĤä¿¡£");
2148 #else
2149                                                 msg_print("You hear a distant bell toll ominously.");
2150 #endif
2151
2152                                                 break;
2153                                         }
2154                                         case 1:
2155                                         {
2156 #ifdef JP
2157 msg_print("±ó¤¯¤Ç¾â¤¬Æó²óÌĤä¿¡£");
2158 #else
2159                                                 msg_print("A distant bell sounds twice.");
2160 #endif
2161
2162                                                 break;
2163                                         }
2164                                         case 2:
2165         {
2166 #ifdef JP
2167 msg_print("±ó¤¯¤Ç¾â¤¬»°²óÌĤä¿¡£");
2168 #else
2169                                                 msg_print("A distant bell sounds three times.");
2170 #endif
2171
2172                                                 break;
2173                                         }
2174                                         case 3:
2175                                         {
2176 #ifdef JP
2177 msg_print("±ó¤¯¤Ç¾â¤¬»Í²óÌĤä¿¡£");
2178 #else
2179                                                 msg_print("A distant bell tolls four times.");
2180 #endif
2181
2182                                                 break;
2183                                         }
2184                                 }
2185                         }
2186
2187                         /* TY_CURSE activates at mignight! */
2188                         if (!hour && !min)
2189                         {
2190                                 int count = 0;
2191
2192                                 disturb(1, 0);
2193 #ifdef JP
2194 msg_print("±ó¤¯¤Ç¾â¤¬²¿²ó¤âÌĤꡢ»à¤ó¤À¤è¤¦¤ÊÀŤ±¤µ¤ÎÃæ¤Ø¾Ã¤¨¤Æ¤¤¤Ã¤¿¡£");
2195 #else
2196                                 msg_print("A distant bell tolls many times, fading into an deathly silence.");
2197 #endif
2198
2199                 activate_ty_curse(FALSE, &count);
2200         }
2201                 }
2202         }
2203
2204         /* Take damage from cuts */
2205         if (p_ptr->cut && !p_ptr->invuln)
2206         {
2207                 /* Mortal wound or Deep Gash */
2208                 if (p_ptr->cut > 1000)
2209                 {
2210                         i = 200;
2211                 }
2212
2213                 else if (p_ptr->cut > 200)
2214                 {
2215                         i = 80;
2216                 }
2217
2218                 /* Severe cut */
2219                 else if (p_ptr->cut > 100)
2220                 {
2221                         i = 32;
2222                 }
2223
2224                 else if (p_ptr->cut > 50)
2225                 {
2226                         i = 16;
2227                 }
2228
2229                 else if (p_ptr->cut > 25)
2230                 {
2231                         i = 7;
2232                 }
2233
2234                 else if (p_ptr->cut > 10)
2235                 {
2236                         i = 3;
2237                 }
2238
2239                 /* Other cuts */
2240                 else
2241                 {
2242                         i = 1;
2243                 }
2244
2245                 /* Take damage */
2246 #ifdef JP
2247 take_hit(DAMAGE_NOESCAPE, i, "Ã×Ì¿½ý", -1);
2248 #else
2249                 take_hit(DAMAGE_NOESCAPE, i, "a fatal wound", -1);
2250 #endif
2251
2252         }
2253
2254
2255         /*** Check the Food, and Regenerate ***/
2256
2257         if (!p_ptr->inside_battle)
2258         {
2259                 /* Digest normally */
2260                 if (p_ptr->food < PY_FOOD_MAX)
2261                 {
2262                         /* Every 100 game turns */
2263                         if (!(turn % (TURNS_PER_TICK*5)))
2264                         {
2265                                 /* Basic digestion rate based on speed */
2266                                 i = /* extract_energy[p_ptr->pspeed] * 2;*/
2267                                 ((p_ptr->pspeed > 199) ? 49 : ((p_ptr->pspeed < 0) ?
2268                                 1 : extract_energy[p_ptr->pspeed]));
2269
2270                                 /* Regeneration takes more food */
2271                                 if (p_ptr->regenerate) i += 20;
2272                                 if (p_ptr->special_defense & (KAMAE_MASK | KATA_MASK)) i+= 20;
2273                                 if (p_ptr->cursed & TRC_FAST_DIGEST) i += 30;
2274
2275                                 /* Slow digestion takes less food */
2276                                 if (p_ptr->slow_digest) i -= 5;
2277
2278                                 /* Minimal digestion */
2279                                 if (i < 1) i = 1;
2280                                 /* Maximal digestion */
2281                                 if (i > 100) i = 100;
2282
2283                                 /* Digest some food */
2284                                 (void)set_food(p_ptr->food - i);
2285                         }
2286                 }
2287
2288                 /* Digest quickly when gorged */
2289                 else
2290                 {
2291                         /* Digest a lot of food */
2292                         (void)set_food(p_ptr->food - 100);
2293                 }
2294         }
2295
2296         /* Starve to death (slowly) */
2297         if (p_ptr->food < PY_FOOD_STARVE)
2298         {
2299                 /* Calculate damage */
2300                 i = (PY_FOOD_STARVE - p_ptr->food) / 10;
2301
2302                 /* Take damage */
2303 #ifdef JP
2304 if (!p_ptr->invuln) take_hit(DAMAGE_LOSELIFE, i, "¶õÊ¢", -1);
2305 #else
2306                 if (!p_ptr->invuln) take_hit(DAMAGE_LOSELIFE, i, "starvation", -1);
2307 #endif
2308
2309         }
2310
2311         /* Default regeneration */
2312         regen_amount = PY_REGEN_NORMAL;
2313
2314         /* Getting Weak */
2315         if (p_ptr->food < PY_FOOD_WEAK)
2316         {
2317                 /* Lower regeneration */
2318                 if (p_ptr->food < PY_FOOD_STARVE)
2319                 {
2320                         regen_amount = 0;
2321                 }
2322                 else if (p_ptr->food < PY_FOOD_FAINT)
2323                 {
2324                         regen_amount = PY_REGEN_FAINT;
2325                 }
2326                 else
2327                 {
2328                         regen_amount = PY_REGEN_WEAK;
2329                 }
2330
2331                 /* Getting Faint */
2332                 if ((p_ptr->food < PY_FOOD_FAINT) && !p_ptr->inside_battle)
2333                 {
2334                         /* Faint occasionally */
2335                         if (!p_ptr->paralyzed && (randint0(100) < 10))
2336                         {
2337                                 /* Message */
2338 #ifdef JP
2339 msg_print("¤¢¤Þ¤ê¤Ë¤â¶õÊ¢¤Çµ¤À䤷¤Æ¤·¤Þ¤Ã¤¿¡£");
2340 #else
2341                                 msg_print("You faint from the lack of food.");
2342 #endif
2343
2344                                 disturb(1, 0);
2345
2346                                 /* Hack -- faint (bypass free action) */
2347                                 (void)set_paralyzed(p_ptr->paralyzed + 1 + randint0(5));
2348                         }
2349                 }
2350         }
2351
2352
2353         /* Are we walking the pattern? */
2354         if (pattern_effect())
2355         {
2356                 cave_no_regen = TRUE;
2357         }
2358         else
2359         {
2360                 /* Regeneration ability */
2361                 if (p_ptr->regenerate)
2362                 {
2363                         regen_amount = regen_amount * 2;
2364                 }
2365                 if (p_ptr->special_defense & (KAMAE_MASK | KATA_MASK))
2366                 {
2367                         regen_amount /= 2;
2368                 }
2369                 if (p_ptr->cursed & TRC_SLOW_REGEN)
2370                 {
2371                         regen_amount /= 5;
2372                 }
2373         }
2374
2375
2376         /* Searching or Resting */
2377         if ((p_ptr->action == ACTION_SEARCH) || (p_ptr->action == ACTION_REST))
2378         {
2379                 regen_amount = regen_amount * 2;
2380         }
2381
2382         upkeep_factor = calculate_upkeep();
2383
2384         /* Regenerate the mana */
2385 /*      if (p_ptr->csp < p_ptr->msp) */
2386         {
2387                 if (upkeep_factor)
2388                 {
2389                         s32b upkeep_regen = ((100 - upkeep_factor) * regen_amount);
2390                         if ((p_ptr->action == ACTION_LEARN) || (p_ptr->action == ACTION_HAYAGAKE)) upkeep_regen -= regen_amount;
2391                         regenmana(upkeep_regen/100);
2392
2393 #ifdef TRACK_FRIENDS
2394                         if (p_ptr->wizard)
2395                         {
2396 #ifdef JP
2397 msg_format("£Í£Ð²óÉü: %d/%d", upkeep_regen, regen_amount);
2398 #else
2399                                 msg_format("Regen: %d/%d", upkeep_regen, regen_amount);
2400 #endif
2401
2402                         }
2403 #endif /* TRACK_FRIENDS */
2404
2405                 }
2406                 else if (p_ptr->action != ACTION_LEARN)
2407                 {
2408                         regenmana(regen_amount);
2409                 }
2410         }
2411         if (p_ptr->pclass == CLASS_MAGIC_EATER)
2412         {
2413                 regenmagic(regen_amount);
2414         }
2415
2416         if ((p_ptr->csp == 0) && (p_ptr->csp_frac == 0))
2417         {
2418                 while (upkeep_factor > 100)
2419                 {
2420 #ifdef JP
2421 msg_print("¤³¤ó¤Ê¤Ë¿¤¯¤Î¥Ú¥Ã¥È¤òÀ©¸æ¤Ç¤­¤Ê¤¤¡ª");
2422 #else
2423                         msg_print("Such much pets cannot be controled at once!");
2424 #endif
2425                         msg_print(NULL);
2426                         do_cmd_pet_dismiss();
2427
2428                         upkeep_factor = calculate_upkeep();
2429
2430 #ifdef JP
2431                         msg_format("°Ý»ý£Í£Ð¤Ï %d%%", upkeep_factor);
2432 #else
2433                         msg_format("Upkeep: %d%% mana.", upkeep_factor);
2434 #endif
2435                         msg_print(NULL);
2436                 }
2437         }
2438
2439         /* Poisoned or cut yields no healing */
2440         if (p_ptr->poisoned) regen_amount = 0;
2441         if (p_ptr->cut) regen_amount = 0;
2442
2443         /* Special floor -- Pattern, in a wall -- yields no healing */
2444         if (cave_no_regen) regen_amount = 0;
2445
2446         regen_amount = (regen_amount * mutant_regenerate_mod) / 100;
2447
2448         /* Regenerate Hit Points if needed */
2449         if ((p_ptr->chp < p_ptr->mhp) && !cave_no_regen)
2450         {
2451                 if ((cave[py][px].feat < FEAT_PATTERN_END) &&
2452                     (cave[py][px].feat >= FEAT_PATTERN_START))
2453                 {
2454                         regenhp(regen_amount / 5); /* Hmmm. this should never happen? */
2455                 }
2456                 else
2457                 {
2458                         regenhp(regen_amount);
2459                 }
2460         }
2461
2462
2463         /*** Timeout Various Things ***/
2464
2465         /* Mimic */
2466         if (p_ptr->tim_mimic)
2467         {
2468                 (void)set_mimic(p_ptr->tim_mimic - 1, p_ptr->mimic_form, TRUE);
2469         }
2470
2471         /* Hack -- Hallucinating */
2472         if (p_ptr->image)
2473         {
2474                 (void)set_image(p_ptr->image - dec_count);
2475         }
2476
2477         /* Blindness */
2478         if (p_ptr->blind)
2479         {
2480                 (void)set_blind(p_ptr->blind - dec_count);
2481         }
2482
2483         /* Times see-invisible */
2484         if (p_ptr->tim_invis)
2485         {
2486                 (void)set_tim_invis(p_ptr->tim_invis - 1, TRUE);
2487         }
2488
2489         if (multi_rew)
2490         {
2491                 multi_rew = FALSE;
2492         }
2493
2494         /* Timed esp */
2495         if (p_ptr->tim_esp)
2496         {
2497                 (void)set_tim_esp(p_ptr->tim_esp - 1, TRUE);
2498         }
2499
2500         /* Timed temporary elemental brands. -LM- */
2501         if (p_ptr->ele_attack)
2502         {
2503                 p_ptr->ele_attack--;
2504
2505                 /* Clear all temporary elemental brands. */
2506                 if (!p_ptr->ele_attack) set_ele_attack(0, 0);
2507         }
2508
2509         /* Timed temporary elemental immune. -LM- */
2510         if (p_ptr->ele_immune)
2511         {
2512                 p_ptr->ele_immune--;
2513
2514                 /* Clear all temporary elemental brands. */
2515                 if (!p_ptr->ele_immune) set_ele_immune(0, 0);
2516         }
2517
2518         /* Timed infra-vision */
2519         if (p_ptr->tim_infra)
2520         {
2521                 (void)set_tim_infra(p_ptr->tim_infra - 1, TRUE);
2522         }
2523
2524         /* Timed stealth */
2525         if (p_ptr->tim_stealth)
2526         {
2527                 (void)set_tim_stealth(p_ptr->tim_stealth - 1, TRUE);
2528         }
2529
2530         /* Timed levitation */
2531         if (p_ptr->tim_ffall)
2532         {
2533                 (void)set_tim_ffall(p_ptr->tim_ffall - 1, TRUE);
2534         }
2535
2536         /* Timed sh_touki */
2537         if (p_ptr->tim_sh_touki)
2538         {
2539                 (void)set_tim_sh_touki(p_ptr->tim_sh_touki - 1, TRUE);
2540         }
2541
2542         /* Timed sh_fire */
2543         if (p_ptr->tim_sh_fire)
2544         {
2545                 (void)set_tim_sh_fire(p_ptr->tim_sh_fire - 1, TRUE);
2546         }
2547
2548         /* Timed sh_holy */
2549         if (p_ptr->tim_sh_holy)
2550         {
2551                 (void)set_tim_sh_holy(p_ptr->tim_sh_holy - 1, TRUE);
2552         }
2553
2554         /* Timed eyeeye */
2555         if (p_ptr->tim_eyeeye)
2556         {
2557                 (void)set_tim_eyeeye(p_ptr->tim_eyeeye - 1, TRUE);
2558         }
2559
2560         /* Timed resist-magic */
2561         if (p_ptr->resist_magic)
2562         {
2563                 (void)set_resist_magic(p_ptr->resist_magic - 1, TRUE);
2564         }
2565
2566         /* Timed regeneration */
2567         if (p_ptr->tim_regen)
2568         {
2569                 (void)set_tim_regen(p_ptr->tim_regen - 1, TRUE);
2570         }
2571
2572         /* Timed resist nether */
2573         if (p_ptr->tim_res_nether)
2574         {
2575                 (void)set_tim_res_nether(p_ptr->tim_res_nether - 1, TRUE);
2576         }
2577
2578         /* Timed resist time */
2579         if (p_ptr->tim_res_time)
2580         {
2581                 (void)set_tim_res_time(p_ptr->tim_res_time - 1, TRUE);
2582         }
2583
2584         /* Timed reflect */
2585         if (p_ptr->tim_reflect)
2586         {
2587                 (void)set_tim_reflect(p_ptr->tim_reflect - 1, TRUE);
2588         }
2589
2590         /* Multi-shadow */
2591         if (p_ptr->multishadow)
2592         {
2593                 (void)set_multishadow(p_ptr->multishadow - 1, TRUE);
2594         }
2595
2596         /* Timed Robe of dust */
2597         if (p_ptr->dustrobe)
2598         {
2599                 (void)set_dustrobe(p_ptr->dustrobe - 1, TRUE);
2600         }
2601
2602         /* Timed infra-vision */
2603         if (p_ptr->kabenuke)
2604         {
2605                 (void)set_kabenuke(p_ptr->kabenuke - 1, TRUE);
2606         }
2607
2608         /* Paralysis */
2609         if (p_ptr->paralyzed)
2610         {
2611                 (void)set_paralyzed(p_ptr->paralyzed - dec_count);
2612         }
2613
2614         /* Confusion */
2615         if (p_ptr->confused)
2616         {
2617                 (void)set_confused(p_ptr->confused - dec_count);
2618         }
2619
2620         /* Afraid */
2621         if (p_ptr->afraid)
2622         {
2623                 (void)set_afraid(p_ptr->afraid - dec_count);
2624         }
2625
2626         /* Fast */
2627         if (p_ptr->fast)
2628         {
2629                 (void)set_fast(p_ptr->fast - 1, TRUE);
2630         }
2631
2632         /* Slow */
2633         if (p_ptr->slow)
2634         {
2635                 (void)set_slow(p_ptr->slow - dec_count, TRUE);
2636         }
2637
2638         /* Protection from evil */
2639         if (p_ptr->protevil)
2640         {
2641                 (void)set_protevil(p_ptr->protevil - 1, TRUE);
2642         }
2643
2644         /* Invulnerability */
2645         if (p_ptr->invuln)
2646         {
2647                 (void)set_invuln(p_ptr->invuln - 1, TRUE);
2648         }
2649
2650         /* Wraith form */
2651         if (p_ptr->wraith_form)
2652         {
2653                 (void)set_wraith_form(p_ptr->wraith_form - 1, TRUE);
2654         }
2655
2656         /* Heroism */
2657         if (p_ptr->hero)
2658         {
2659                 (void)set_hero(p_ptr->hero - 1, TRUE);
2660         }
2661
2662         /* Super Heroism */
2663         if (p_ptr->shero)
2664         {
2665                 (void)set_shero(p_ptr->shero - 1, TRUE);
2666         }
2667
2668         /* Blessed */
2669         if (p_ptr->blessed)
2670         {
2671                 (void)set_blessed(p_ptr->blessed - 1, TRUE);
2672         }
2673
2674         /* Shield */
2675         if (p_ptr->shield)
2676         {
2677                 (void)set_shield(p_ptr->shield - 1, TRUE);
2678         }
2679
2680         /* Tsubureru */
2681         if (p_ptr->tsubureru)
2682         {
2683                 (void)set_tsubureru(p_ptr->tsubureru - 1, TRUE);
2684         }
2685
2686         /* Magicdef */
2687         if (p_ptr->magicdef)
2688         {
2689                 (void)set_magicdef(p_ptr->magicdef - 1, TRUE);
2690         }
2691
2692         /* Tsuyoshi */
2693         if (p_ptr->tsuyoshi)
2694         {
2695                 (void)set_tsuyoshi(p_ptr->tsuyoshi - 1, TRUE);
2696         }
2697
2698         /* Oppose Acid */
2699         if (p_ptr->oppose_acid)
2700         {
2701                 (void)set_oppose_acid(p_ptr->oppose_acid - 1, TRUE);
2702         }
2703
2704         /* Oppose Lightning */
2705         if (p_ptr->oppose_elec)
2706         {
2707                 (void)set_oppose_elec(p_ptr->oppose_elec - 1, TRUE);
2708         }
2709
2710         /* Oppose Fire */
2711         if (p_ptr->oppose_fire)
2712         {
2713                 (void)set_oppose_fire(p_ptr->oppose_fire - 1, TRUE);
2714         }
2715
2716         /* Oppose Cold */
2717         if (p_ptr->oppose_cold)
2718         {
2719                 (void)set_oppose_cold(p_ptr->oppose_cold - 1, TRUE);
2720         }
2721
2722         /* Oppose Poison */
2723         if (p_ptr->oppose_pois)
2724         {
2725                 (void)set_oppose_pois(p_ptr->oppose_pois - 1, TRUE);
2726         }
2727
2728         if (p_ptr->ult_res)
2729         {
2730                 (void)set_ultimate_res(p_ptr->ult_res - 1, TRUE);
2731         }
2732
2733         /*** Poison and Stun and Cut ***/
2734
2735         /* Poison */
2736         if (p_ptr->poisoned)
2737         {
2738                 int adjust = adj_con_fix[p_ptr->stat_ind[A_CON]] + 1;
2739
2740                 /* Apply some healing */
2741                 (void)set_poisoned(p_ptr->poisoned - adjust);
2742         }
2743
2744         /* Stun */
2745         if (p_ptr->stun)
2746         {
2747                 int adjust = adj_con_fix[p_ptr->stat_ind[A_CON]] + 1;
2748
2749                 /* Apply some healing */
2750                 (void)set_stun(p_ptr->stun - adjust);
2751         }
2752
2753         /* Cut */
2754         if (p_ptr->cut)
2755         {
2756                 int adjust = adj_con_fix[p_ptr->stat_ind[A_CON]] + 1;
2757
2758                 /* Hack -- Truly "mortal" wound */
2759                 if (p_ptr->cut > 1000) adjust = 0;
2760
2761                 /* Apply some healing */
2762                 (void)set_cut(p_ptr->cut - adjust);
2763         }
2764
2765
2766
2767         /*** Process Light ***/
2768
2769         /* Check for light being wielded */
2770         o_ptr = &inventory[INVEN_LITE];
2771
2772         /* Burn some fuel in the current lite */
2773         if (o_ptr->tval == TV_LITE)
2774         {
2775                 /* Hack -- Use some fuel (except on artifacts) */
2776                 if (!(artifact_p(o_ptr) || o_ptr->sval == SV_LITE_FEANOR) && (o_ptr->xtra4 > 0))
2777                 {
2778                         /* Decrease life-span */
2779                         if (o_ptr->name2 == EGO_LITE_LONG)
2780                         {
2781                                 if (turn % (TURNS_PER_TICK*2)) o_ptr->xtra4--;
2782                         }
2783                         else o_ptr->xtra4--;
2784
2785                         /* Notice interesting fuel steps */
2786                         notice_lite_change(o_ptr);
2787                 }
2788         }
2789
2790         /* Calculate torch radius */
2791         p_ptr->update |= (PU_TORCH);
2792
2793
2794         /*** Process mutation effects ***/
2795         if (p_ptr->muta2 && !p_ptr->inside_battle && !p_ptr->wild_mode)
2796         {
2797                 if ((p_ptr->muta2 & MUT2_BERS_RAGE) && one_in_(3000))
2798                 {
2799                         disturb(0, 0);
2800 #ifdef JP
2801 msg_print("¥¦¥¬¥¡¥¡¥¢¡ª");
2802 msg_print("·ãÅܤÎȯºî¤Ë½±¤ï¤ì¤¿¡ª");
2803 #else
2804                         msg_print("RAAAAGHH!");
2805                         msg_print("You feel a fit of rage coming over you!");
2806 #endif
2807
2808                         (void)set_shero(10 + randint1(p_ptr->lev), FALSE);
2809                 }
2810
2811                 if ((p_ptr->muta2 & MUT2_COWARDICE) && (randint1(3000) == 13))
2812                 {
2813                         if (!(p_ptr->resist_fear || p_ptr->hero || p_ptr->shero))
2814                         {
2815                                 disturb(0, 0);
2816 #ifdef JP
2817 msg_print("¤È¤Æ¤â°Å¤¤... ¤È¤Æ¤â¶²¤¤¡ª");
2818 #else
2819                                 msg_print("It's so dark... so scary!");
2820 #endif
2821
2822                                 set_afraid(p_ptr->afraid + 13 + randint1(26));
2823                         }
2824                 }
2825
2826                 if ((p_ptr->muta2 & MUT2_RTELEPORT) && (randint1(5000) == 88))
2827                 {
2828                         if (!p_ptr->resist_nexus && !(p_ptr->muta1 & MUT1_VTELEPORT) &&
2829                             !p_ptr->anti_tele)
2830                         {
2831                                 disturb(0, 0);
2832
2833                                 /* Teleport player */
2834 #ifdef JP
2835 msg_print("¤¢¤Ê¤¿¤Î°ÌÃÖ¤ÏÆÍÁ³¤Ò¤¸¤ç¤¦¤ËÉÔ³ÎÄê¤Ë¤Ê¤Ã¤¿...");
2836 #else
2837                                 msg_print("Your position suddenly seems very uncertain...");
2838 #endif
2839
2840                                 msg_print(NULL);
2841                                 teleport_player(40);
2842                         }
2843                 }
2844
2845                 if ((p_ptr->muta2 & MUT2_ALCOHOL) && (randint1(6400) == 321))
2846                 {
2847                         if (!p_ptr->resist_conf && !p_ptr->resist_chaos)
2848                         {
2849                                 disturb(0, 0);
2850                                 p_ptr->redraw |= PR_EXTRA;
2851 #ifdef JP
2852 msg_print("¤¤¤Ò¤­¤¬¤â¡¼¤í¡¼¤È¤Ò¤Æ¤­¤¿¤­¤¬¤Õ¤ë...¥Ò¥Ã¥¯¡ª");
2853 #else
2854                                 msg_print("You feel a SSSCHtupor cOmINg over yOu... *HIC*!");
2855 #endif
2856
2857                         }
2858
2859                         if (!p_ptr->resist_conf)
2860                         {
2861                                 (void)set_confused(p_ptr->confused + randint0(20) + 15);
2862                         }
2863
2864                         if (!p_ptr->resist_chaos)
2865                         {
2866                                 if (one_in_(20))
2867                                 {
2868                                         msg_print(NULL);
2869                                         if (one_in_(3)) lose_all_info();
2870                                         else wiz_dark();
2871                                         teleport_player(100);
2872                                         wiz_dark();
2873 #ifdef JP
2874 msg_print("¤¢¤Ê¤¿¤Ï¸«ÃΤé¤Ì¾ì½ê¤ÇÌܤ¬Àä᤿...Ƭ¤¬Äˤ¤¡£");
2875 msg_print("²¿¤â³Ð¤¨¤Æ¤¤¤Ê¤¤¡£¤É¤¦¤ä¤Ã¤Æ¤³¤³¤ËÍ褿¤«¤âʬ¤«¤é¤Ê¤¤¡ª");
2876 #else
2877                                         msg_print("You wake up somewhere with a sore head...");
2878                                         msg_print("You can't remember a thing, or how you got here!");
2879 #endif
2880
2881                                 }
2882                                 else
2883                                 {
2884                                         if (one_in_(3))
2885                                         {
2886 #ifdef JP
2887 msg_print("¤­¡Á¤ì¤¤¤Ê¤Á¤ç¤ª¤Á¤ç¤é¤È¤ó¤ì¤¤¤ë¡Á");
2888 #else
2889                                                 msg_print("Thishcischs GooDSChtuff!");
2890 #endif
2891
2892                                                 (void)set_image(p_ptr->image + randint0(150) + 150);
2893                                         }
2894                                 }
2895                         }
2896                 }
2897
2898                 if ((p_ptr->muta2 & MUT2_HALLU) && (randint1(6400) == 42))
2899                 {
2900                         if (!p_ptr->resist_chaos)
2901                         {
2902                                 disturb(0, 0);
2903                                 p_ptr->redraw |= PR_EXTRA;
2904                                 (void)set_image(p_ptr->image + randint0(50) + 20);
2905                         }
2906                 }
2907
2908                 if ((p_ptr->muta2 & MUT2_FLATULENT) && (randint1(3000) == 13))
2909                 {
2910                         disturb(0, 0);
2911
2912 #ifdef JP
2913 msg_print("¥Ö¥¥¡¼¡¼¥Ã¡ª¤ª¤Ã¤È¡£");
2914 #else
2915                         msg_print("BRRAAAP! Oops.");
2916 #endif
2917
2918                         msg_print(NULL);
2919                         fire_ball(GF_POIS, 0, p_ptr->lev, 3);
2920                 }
2921
2922                 if ((p_ptr->muta2 & MUT2_PROD_MANA) &&
2923                     !p_ptr->anti_magic && one_in_(9000))
2924                 {
2925                         int dire = 0;
2926                         disturb(0, 0);
2927 #ifdef JP
2928 msg_print("ËâË¡¤Î¥¨¥Í¥ë¥®¡¼¤¬ÆÍÁ³¤¢¤Ê¤¿¤ÎÃæ¤Ëή¤ì¹þ¤ó¤Ç¤­¤¿¡ª¥¨¥Í¥ë¥®¡¼¤ò²òÊü¤·¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡ª");
2929 #else
2930                         msg_print("Magical energy flows through you! You must release it!");
2931 #endif
2932
2933                         flush();
2934                         msg_print(NULL);
2935                         (void)get_hack_dir(&dire);
2936                         fire_ball(GF_MANA, dire, p_ptr->lev * 2, 3);
2937                 }
2938
2939                 if ((p_ptr->muta2 & MUT2_ATT_DEMON) &&
2940                     !p_ptr->anti_magic && (randint1(6666) == 666))
2941                 {
2942                         bool pet = one_in_(6);
2943                         u32b mode = PM_ALLOW_GROUP;
2944
2945                         if (pet) mode |= PM_FORCE_PET;
2946                         else mode |= (PM_ALLOW_UNIQUE | PM_NO_PET);
2947
2948                         if (summon_specific((pet ? -1 : 0), py, px,
2949                                     dun_level, SUMMON_DEMON, mode))
2950                         {
2951 #ifdef JP
2952 msg_print("¤¢¤Ê¤¿¤Ï¥Ç¡¼¥â¥ó¤ò°ú¤­´ó¤»¤¿¡ª");
2953 #else
2954                                 msg_print("You have attracted a demon!");
2955 #endif
2956
2957                                 disturb(0, 0);
2958                         }
2959                 }
2960
2961                 if ((p_ptr->muta2 & MUT2_SPEED_FLUX) && one_in_(6000))
2962                 {
2963                         disturb(0, 0);
2964                         if (one_in_(2))
2965                         {
2966 #ifdef JP
2967 msg_print("ÀºÎÏŪ¤Ç¤Ê¤¯¤Ê¤Ã¤¿µ¤¤¬¤¹¤ë¡£");
2968 #else
2969                                 msg_print("You feel less energetic.");
2970 #endif
2971
2972                                 if (p_ptr->fast > 0)
2973                                 {
2974                                         set_fast(0, TRUE);
2975                                 }
2976                                 else
2977                                 {
2978                                         set_slow(randint1(30) + 10, FALSE);
2979                                 }
2980                         }
2981                         else
2982                         {
2983 #ifdef JP
2984 msg_print("ÀºÎÏŪ¤Ë¤Ê¤Ã¤¿µ¤¤¬¤¹¤ë¡£");
2985 #else
2986                                 msg_print("You feel more energetic.");
2987 #endif
2988
2989                                 if (p_ptr->slow > 0)
2990                                 {
2991                                         set_slow(0, TRUE);
2992                                 }
2993                                 else
2994                                 {
2995                                         set_fast(randint1(30) + 10, FALSE);
2996                                 }
2997                         }
2998                         msg_print(NULL);
2999                 }
3000                 if ((p_ptr->muta2 & MUT2_BANISH_ALL) && one_in_(9000))
3001                 {
3002                         disturb(0, 0);
3003 #ifdef JP
3004 msg_print("ÆÍÁ³¤Û¤È¤ó¤É¸ÉÆȤˤʤ俵¤¤¬¤¹¤ë¡£");
3005 #else
3006                         msg_print("You suddenly feel almost lonely.");
3007 #endif
3008
3009                         banish_monsters(100);
3010                         if (!dun_level && p_ptr->town_num)
3011                         {
3012 #ifdef JP
3013 msg_print("Ź¤Î¼ç¿Í¤¬µÖ¤Ë¸þ¤«¤Ã¤ÆÁö¤Ã¤Æ¤¤¤ë¡ª");
3014 #else
3015                                 msg_print("You see one of the shopkeepers running for the hills!");
3016 #endif
3017
3018                                 store_shuffle(randint0(MAX_STORES));
3019                         }
3020                         msg_print(NULL);
3021                 }
3022
3023                 if ((p_ptr->muta2 & MUT2_EAT_LIGHT) && one_in_(3000))
3024                 {
3025                         object_type *o_ptr;
3026
3027 #ifdef JP
3028 msg_print("±Æ¤Ë¤Ä¤Ä¤Þ¤ì¤¿¡£");
3029 #else
3030                         msg_print("A shadow passes over you.");
3031 #endif
3032
3033                         msg_print(NULL);
3034
3035                         /* Absorb light from the current possition */
3036                         if (cave[py][px].info & CAVE_GLOW)
3037                         {
3038                                 hp_player(10);
3039                         }
3040
3041                         o_ptr = &inventory[INVEN_LITE];
3042
3043                         /* Absorb some fuel in the current lite */
3044                         if (o_ptr->tval == TV_LITE)
3045                         {
3046                                 /* Use some fuel (except on artifacts) */
3047                                 if (!artifact_p(o_ptr) && (o_ptr->xtra4 > 0))
3048                                 {
3049                                         /* Heal the player a bit */
3050                                         hp_player(o_ptr->xtra4 / 20);
3051
3052                                         /* Decrease life-span of lite */
3053                                         o_ptr->xtra4 /= 2;
3054
3055 #ifdef JP
3056 msg_print("¸÷¸»¤«¤é¥¨¥Í¥ë¥®¡¼¤òµÛ¼ý¤·¤¿¡ª");
3057 #else
3058                                         msg_print("You absorb energy from your light!");
3059 #endif
3060
3061
3062                                         /* Notice interesting fuel steps */
3063                                         notice_lite_change(o_ptr);
3064                                 }
3065                         }
3066
3067                         /*
3068                          * Unlite the area (radius 10) around player and
3069                          * do 50 points damage to every affected monster
3070                          */
3071                         unlite_area(50, 10);
3072                 }
3073
3074                 if ((p_ptr->muta2 & MUT2_ATT_ANIMAL) &&
3075                    !p_ptr->anti_magic && one_in_(7000))
3076                 {
3077                         bool pet = one_in_(3);
3078                         u32b mode = PM_ALLOW_GROUP;
3079
3080                         if (pet) mode |= PM_FORCE_PET;
3081                         else mode |= (PM_ALLOW_UNIQUE | PM_NO_PET);
3082
3083                         if (summon_specific((pet ? -1 : 0), py, px, dun_level, SUMMON_ANIMAL, mode))
3084                         {
3085 #ifdef JP
3086 msg_print("ưʪ¤ò°ú¤­´ó¤»¤¿¡ª");
3087 #else
3088                                 msg_print("You have attracted an animal!");
3089 #endif
3090
3091                                 disturb(0, 0);
3092                         }
3093                 }
3094
3095                 if ((p_ptr->muta2 & MUT2_RAW_CHAOS) &&
3096                     !p_ptr->anti_magic && one_in_(8000))
3097                 {
3098                         disturb(0, 0);
3099 #ifdef JP
3100 msg_print("¼þ¤ê¤Î¶õ´Ö¤¬ÏĤó¤Ç¤¤¤ëµ¤¤¬¤¹¤ë¡ª");
3101 #else
3102                         msg_print("You feel the world warping around you!");
3103 #endif
3104
3105                         msg_print(NULL);
3106                         fire_ball(GF_CHAOS, 0, p_ptr->lev, 8);
3107                 }
3108                 if ((p_ptr->muta2 & MUT2_NORMALITY) && one_in_(5000))
3109                 {
3110                         if (!lose_mutation(0))
3111 #ifdef JP
3112 msg_print("´ñ̯¤Ê¤¯¤é¤¤ÉáÄ̤ˤʤ俵¤¤¬¤¹¤ë¡£");
3113 #else
3114                                 msg_print("You feel oddly normal.");
3115 #endif
3116
3117                 }
3118                 if ((p_ptr->muta2 & MUT2_WRAITH) && !p_ptr->anti_magic && one_in_(3000))
3119                 {
3120                         disturb(0, 0);
3121 #ifdef JP
3122 msg_print("Èóʪ¼Á²½¤·¤¿¡ª");
3123 #else
3124                         msg_print("You feel insubstantial!");
3125 #endif
3126
3127                         msg_print(NULL);
3128                         set_wraith_form(randint1(p_ptr->lev / 2) + (p_ptr->lev / 2), FALSE);
3129                 }
3130                 if ((p_ptr->muta2 & MUT2_POLY_WOUND) && one_in_(3000))
3131                 {
3132                         do_poly_wounds();
3133                 }
3134                 if ((p_ptr->muta2 & MUT2_WASTING) && one_in_(3000))
3135                 {
3136                         int which_stat = randint0(6);
3137                         int sustained = FALSE;
3138
3139                         switch (which_stat)
3140                         {
3141                         case A_STR:
3142                                 if (p_ptr->sustain_str) sustained = TRUE;
3143                                 break;
3144                         case A_INT:
3145                                 if (p_ptr->sustain_int) sustained = TRUE;
3146                                 break;
3147                         case A_WIS:
3148                                 if (p_ptr->sustain_wis) sustained = TRUE;
3149                                 break;
3150                         case A_DEX:
3151                                 if (p_ptr->sustain_dex) sustained = TRUE;
3152                                 break;
3153                         case A_CON:
3154                                 if (p_ptr->sustain_con) sustained = TRUE;
3155                                 break;
3156                         case A_CHR:
3157                                 if (p_ptr->sustain_chr) sustained = TRUE;
3158                                 break;
3159                         default:
3160 #ifdef JP
3161 msg_print("ÉÔÀµ¤Ê¾õÂÖ¡ª");
3162 #else
3163                                 msg_print("Invalid stat chosen!");
3164 #endif
3165
3166                                 sustained = TRUE;
3167                         }
3168
3169                         if (!sustained)
3170                         {
3171                                 disturb(0, 0);
3172 #ifdef JP
3173 msg_print("¼«Ê¬¤¬¿ê¼å¤·¤Æ¤¤¤¯¤Î¤¬Ê¬¤«¤ë¡ª");
3174 #else
3175                                 msg_print("You can feel yourself wasting away!");
3176 #endif
3177
3178                                 msg_print(NULL);
3179                                 (void)dec_stat(which_stat, randint1(6) + 6, one_in_(3));
3180                         }
3181                 }
3182                 if ((p_ptr->muta2 & MUT2_ATT_DRAGON) &&
3183                    !p_ptr->anti_magic && one_in_(3000))
3184                 {
3185                         bool pet = one_in_(5);
3186                         u32b mode = PM_ALLOW_GROUP;
3187
3188                         if (pet) mode |= PM_FORCE_PET;
3189                         else mode |= (PM_ALLOW_UNIQUE | PM_NO_PET);
3190
3191                         if (summon_specific((pet ? -1 : 0), py, px, dun_level, SUMMON_DRAGON, mode))
3192                         {
3193 #ifdef JP
3194 msg_print("¥É¥é¥´¥ó¤ò°ú¤­´ó¤»¤¿¡ª");
3195 #else
3196                                 msg_print("You have attracted a dragon!");
3197 #endif
3198
3199                                 disturb(0, 0);
3200                         }
3201                 }
3202                 if ((p_ptr->muta2 & MUT2_WEIRD_MIND) && !p_ptr->anti_magic &&
3203                         one_in_(3000))
3204                 {
3205                         if (p_ptr->tim_esp > 0)
3206                         {
3207 #ifdef JP
3208 msg_print("Àº¿À¤Ë¤â¤ä¤¬¤«¤«¤Ã¤¿¡ª");
3209 #else
3210                                 msg_print("Your mind feels cloudy!");
3211 #endif
3212
3213                                 set_tim_esp(0, TRUE);
3214                         }
3215                         else
3216                         {
3217 #ifdef JP
3218 msg_print("Àº¿À¤¬¹­¤¬¤Ã¤¿¡ª");
3219 #else
3220                                 msg_print("Your mind expands!");
3221 #endif
3222
3223                                 set_tim_esp(p_ptr->lev, FALSE);
3224                         }
3225                 }
3226                 if ((p_ptr->muta2 & MUT2_NAUSEA) && !p_ptr->slow_digest &&
3227                         one_in_(9000))
3228                 {
3229                         disturb(0, 0);
3230 #ifdef JP
3231 msg_print("°ß¤¬áÛÚ»¤·¡¢¿©»ö¤ò¼º¤Ã¤¿¡ª");
3232 #else
3233                         msg_print("Your stomach roils, and you lose your lunch!");
3234 #endif
3235
3236                         msg_print(NULL);
3237                         set_food(PY_FOOD_WEAK);
3238                 }
3239
3240                 if ((p_ptr->muta2 & MUT2_WALK_SHAD) &&
3241                    !p_ptr->anti_magic && one_in_(12000) && !p_ptr->inside_arena)
3242                 {
3243                         alter_reality();
3244                 }
3245
3246                 if ((p_ptr->muta2 & MUT2_WARNING) && one_in_(1000))
3247                 {
3248                         int danger_amount = 0;
3249                         int monster;
3250
3251                         for (monster = 0; monster < m_max; monster++)
3252                         {
3253                                 monster_type    *m_ptr = &m_list[monster];
3254                                 monster_race    *r_ptr = &r_info[m_ptr->r_idx];
3255
3256                                 /* Paranoia -- Skip dead monsters */
3257                                 if (!m_ptr->r_idx) continue;
3258
3259                                 if (r_ptr->level >= p_ptr->lev)
3260                                 {
3261                                         danger_amount += r_ptr->level - p_ptr->lev + 1;
3262                                 }
3263                         }
3264
3265                         if (danger_amount > 100)
3266 #ifdef JP
3267 msg_print("Èó¾ï¤Ë¶²¤í¤·¤¤µ¤¤¬¤¹¤ë¡ª");
3268 #else
3269                                 msg_print("You feel utterly terrified!");
3270 #endif
3271
3272                         else if (danger_amount > 50)
3273 #ifdef JP
3274 msg_print("¶²¤í¤·¤¤µ¤¤¬¤¹¤ë¡ª");
3275 #else
3276                                 msg_print("You feel terrified!");
3277 #endif
3278
3279                         else if (danger_amount > 20)
3280 #ifdef JP
3281 msg_print("Èó¾ï¤Ë¿´Çۤʵ¤¤¬¤¹¤ë¡ª");
3282 #else
3283                                 msg_print("You feel very worried!");
3284 #endif
3285
3286                         else if (danger_amount > 10)
3287 #ifdef JP
3288 msg_print("¿´Çۤʵ¤¤¬¤¹¤ë¡ª");
3289 #else
3290                                 msg_print("You feel paranoid!");
3291 #endif
3292
3293                         else if (danger_amount > 5)
3294 #ifdef JP
3295 msg_print("¤Û¤È¤ó¤É°ÂÁ´¤Êµ¤¤¬¤¹¤ë¡£");
3296 #else
3297                                 msg_print("You feel almost safe.");
3298 #endif
3299
3300                         else
3301 #ifdef JP
3302 msg_print("¼ä¤·¤¤µ¤¤¬¤¹¤ë¡£");
3303 #else
3304                                 msg_print("You feel lonely.");
3305 #endif
3306
3307                 }
3308                 if ((p_ptr->muta2 & MUT2_INVULN) && !p_ptr->anti_magic &&
3309                         one_in_(5000))
3310                 {
3311                         disturb(0, 0);
3312 #ifdef JP
3313 msg_print("̵Ũ¤Êµ¤¤¬¤¹¤ë¡ª");
3314 #else
3315                         msg_print("You feel invincible!");
3316 #endif
3317
3318                         msg_print(NULL);
3319                         (void)set_invuln(randint1(8) + 8, FALSE);
3320                 }
3321                 if ((p_ptr->muta2 & MUT2_SP_TO_HP) && one_in_(2000))
3322                 {
3323                         int wounds = p_ptr->mhp - p_ptr->chp;
3324
3325                         if (wounds > 0)
3326                         {
3327                                 int healing = p_ptr->csp;
3328
3329                                 if (healing > wounds)
3330                                 {
3331                                         healing = wounds;
3332                                 }
3333
3334                                 hp_player(healing);
3335                                 p_ptr->csp -= healing;
3336                         }
3337                 }
3338                 if ((p_ptr->muta2 & MUT2_HP_TO_SP) && !p_ptr->anti_magic &&
3339                         one_in_(4000))
3340                 {
3341                         int wounds = p_ptr->msp - p_ptr->csp;
3342
3343                         if (wounds > 0)
3344                         {
3345                                 int healing = p_ptr->chp;
3346
3347                                 if (healing > wounds)
3348                                 {
3349                                         healing = wounds;
3350                                 }
3351
3352                                 p_ptr->csp += healing;
3353 #ifdef JP
3354 take_hit(DAMAGE_LOSELIFE, healing, "Ƭ¤Ë¾º¤Ã¤¿·ì", -1);
3355 #else
3356                                 take_hit(DAMAGE_LOSELIFE, healing, "blood rushing to the head", -1);
3357 #endif
3358
3359                         }
3360                 }
3361                 if ((p_ptr->muta2 & MUT2_DISARM) && one_in_(10000))
3362                 {
3363                         object_type *o_ptr;
3364
3365                         disturb(0, 0);
3366 #ifdef JP
3367 msg_print("­¤¬¤â¤Ä¤ì¤Æž¤ó¤À¡ª");
3368 take_hit(DAMAGE_NOESCAPE, randint1(p_ptr->wt / 6), "žÅÝ", -1);
3369 #else
3370                         msg_print("You trip over your own feet!");
3371                         take_hit(DAMAGE_NOESCAPE, randint1(p_ptr->wt / 6), "tripping", -1);
3372 #endif
3373
3374
3375                         msg_print(NULL);
3376                         if (buki_motteruka(INVEN_RARM))
3377                         {
3378                                 int slot = INVEN_RARM;
3379                                 o_ptr = &inventory[INVEN_RARM];
3380                                 if (buki_motteruka(INVEN_LARM) && one_in_(2))
3381                                 {
3382                                         o_ptr = &inventory[INVEN_LARM];
3383                                         slot = INVEN_LARM;
3384                                 }
3385                                 if (!cursed_p(o_ptr))
3386                                 {
3387 #ifdef JP
3388 msg_print("Éð´ï¤òÍ¤Æ¤·¤Þ¤Ã¤¿¡ª");
3389 #else
3390                                         msg_print("You drop your weapon!");
3391 #endif
3392
3393                                         inven_drop(slot, 1);
3394                                 }
3395                         }
3396                 }
3397         }
3398
3399
3400         /*** Process Inventory ***/
3401
3402         if ((p_ptr->cursed & TRC_P_FLAG_MASK) && !p_ptr->inside_battle && !p_ptr->wild_mode)
3403         {
3404                 /*
3405                  * Hack: Uncursed teleporting items (e.g. Trump Weapons)
3406                  * can actually be useful!
3407                  */
3408                 if ((p_ptr->cursed & TRC_TELEPORT_SELF) && one_in_(200))
3409                 {
3410 #ifdef JP
3411 if (get_check_strict("¥Æ¥ì¥Ý¡¼¥È¤·¤Þ¤¹¤«¡©", CHECK_OKAY_CANCEL))
3412 #else
3413                         if (get_check_strict("Teleport? ", CHECK_OKAY_CANCEL))
3414 #endif
3415                         {
3416                                 disturb(0, 0);
3417                                 teleport_player(50);
3418                         }
3419                 }
3420                 /* Make a chainsword noise */
3421                 if ((p_ptr->cursed & TRC_CHAINSWORD) && one_in_(CHAINSWORD_NOISE))
3422                 {
3423                         char noise[1024];
3424 #ifdef JP
3425 if (!get_rnd_line("chainswd_j.txt", 0, noise))
3426 #else
3427                         if (!get_rnd_line("chainswd.txt", 0, noise))
3428 #endif
3429                                 msg_print(noise);
3430                         disturb(FALSE, FALSE);
3431                 }
3432                 /* TY Curse */
3433                 if ((p_ptr->cursed & TRC_TY_CURSE) && one_in_(TY_CURSE_CHANCE))
3434                 {
3435                         int count = 0;
3436                         (void)activate_ty_curse(FALSE, &count);
3437                 }
3438                 /* Handle experience draining */
3439                 if (p_ptr->prace != RACE_ANDROID && 
3440                         ((p_ptr->cursed & TRC_DRAIN_EXP) && one_in_(4)))
3441                 {
3442                         p_ptr->exp -= (p_ptr->lev+1)/2;
3443                         if (p_ptr->exp < 0) p_ptr->exp = 0;
3444                         p_ptr->max_exp -= (p_ptr->lev+1)/2;
3445                         if (p_ptr->max_exp < 0) p_ptr->max_exp = 0;
3446                         check_experience();
3447                 }
3448                 /* Add light curse (Later) */
3449                 if ((p_ptr->cursed & TRC_ADD_L_CURSE) && one_in_(2000))
3450                 {
3451                         u32b new_curse;
3452                         object_type *o_ptr;
3453
3454                         o_ptr = choose_cursed_obj_name(TRC_ADD_L_CURSE);
3455
3456                         new_curse = get_curse(0, o_ptr);
3457                         if (!(o_ptr->curse_flags & new_curse))
3458                         {
3459                                 char o_name[MAX_NLEN];
3460
3461                                 object_desc(o_name, o_ptr, FALSE, 0);
3462
3463                                 o_ptr->curse_flags |= new_curse;
3464 #ifdef JP
3465 msg_format("°­°Õ¤ËËþ¤Á¤¿¹õ¤¤¥ª¡¼¥é¤¬%s¤ò¤È¤ê¤Þ¤¤¤¿...", o_name);
3466 #else
3467                                 msg_format("There is a malignant black aura surrounding %s...", o_name);
3468 #endif
3469
3470                                 o_ptr->feeling = FEEL_NONE;
3471
3472                                 p_ptr->update |= (PU_BONUS);
3473                         }
3474                 }
3475                 /* Add heavy curse (Later) */
3476                 if ((p_ptr->cursed & TRC_ADD_H_CURSE) && one_in_(2000))
3477                 {
3478                         u32b new_curse;
3479                         object_type *o_ptr;
3480
3481                         o_ptr = choose_cursed_obj_name(TRC_ADD_H_CURSE);
3482
3483                         new_curse = get_curse(1, o_ptr);
3484                         if (!(o_ptr->curse_flags & new_curse))
3485                         {
3486                                 char o_name[MAX_NLEN];
3487
3488                                 object_desc(o_name, o_ptr, FALSE, 0);
3489
3490                                 o_ptr->curse_flags |= new_curse;
3491 #ifdef JP
3492 msg_format("°­°Õ¤ËËþ¤Á¤¿¹õ¤¤¥ª¡¼¥é¤¬%s¤ò¤È¤ê¤Þ¤¤¤¿...", o_name);
3493 #else
3494                                 msg_format("There is a malignant black aura surrounding %s...", o_name);
3495 #endif
3496
3497                                 o_ptr->feeling = FEEL_NONE;
3498
3499                                 p_ptr->update |= (PU_BONUS);
3500                         }
3501                 }
3502                 /* Call animal */
3503                 if ((p_ptr->cursed & TRC_CALL_ANIMAL) && one_in_(2500))
3504                 {
3505                         if (summon_specific(0, py, px, dun_level, SUMMON_ANIMAL,
3506                             (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET)))
3507                         {
3508                                 char o_name[MAX_NLEN];
3509
3510                                 object_desc(o_name, choose_cursed_obj_name(TRC_CALL_ANIMAL), FALSE, 0);
3511 #ifdef JP
3512 msg_format("%s¤¬Æ°Êª¤ò°ú¤­´ó¤»¤¿¡ª", o_name);
3513 #else
3514                                 msg_format("%s have attracted an animal!", o_name);
3515 #endif
3516
3517                                 disturb(0, 0);
3518                         }
3519                 }
3520                 /* Call demon */
3521                 if ((p_ptr->cursed & TRC_CALL_DEMON) && one_in_(1111))
3522                 {
3523                         if (summon_specific(0, py, px, dun_level, SUMMON_DEMON, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET)))
3524                         {
3525                                 char o_name[MAX_NLEN];
3526
3527                                 object_desc(o_name, choose_cursed_obj_name(TRC_CALL_DEMON), FALSE, 0);
3528 #ifdef JP
3529 msg_format("%s¤¬°­Ëâ¤ò°ú¤­´ó¤»¤¿¡ª", o_name);
3530 #else
3531                                 msg_format("%s have attracted a demon!", o_name);
3532 #endif
3533
3534                                 disturb(0, 0);
3535                         }
3536                 }
3537                 /* Call dragon */
3538                 if ((p_ptr->cursed & TRC_CALL_DRAGON) && one_in_(800))
3539                 {
3540                         if (summon_specific(0, py, px, dun_level, SUMMON_DRAGON,
3541                             (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET)))
3542                         {
3543                                 char o_name[MAX_NLEN];
3544
3545                                 object_desc(o_name, choose_cursed_obj_name(TRC_CALL_DRAGON), FALSE, 0);
3546 #ifdef JP
3547 msg_format("%s¤¬¥É¥é¥´¥ó¤ò°ú¤­´ó¤»¤¿¡ª", o_name);
3548 #else
3549                                 msg_format("%s have attracted an animal!", o_name);
3550 #endif
3551
3552                                 disturb(0, 0);
3553                         }
3554                 }
3555                 if ((p_ptr->cursed & TRC_COWARDICE) && one_in_(1500))
3556                 {
3557                         if (!(p_ptr->resist_fear || p_ptr->hero || p_ptr->shero))
3558                         {
3559                                 disturb(0, 0);
3560 #ifdef JP
3561 msg_print("¤È¤Æ¤â°Å¤¤... ¤È¤Æ¤â¶²¤¤¡ª");
3562 #else
3563                                 msg_print("It's so dark... so scary!");
3564 #endif
3565
3566                                 set_afraid(p_ptr->afraid + 13 + randint1(26));
3567                         }
3568                 }
3569                 /* Teleport player */
3570                 if ((p_ptr->cursed & TRC_TELEPORT) && one_in_(200) && !p_ptr->anti_tele)
3571                 {
3572                         disturb(0, 0);
3573
3574                         /* Teleport player */
3575                         teleport_player(40);
3576                 }
3577                 /* Handle HP draining */
3578                 if ((p_ptr->cursed & TRC_DRAIN_HP) && one_in_(666))
3579                 {
3580                         char o_name[MAX_NLEN];
3581
3582                         object_desc(o_name, choose_cursed_obj_name(TRC_DRAIN_HP), FALSE, 0);
3583 #ifdef JP
3584 msg_format("%s¤Ï¤¢¤Ê¤¿¤ÎÂÎÎϤòµÛ¼ý¤·¤¿¡ª", o_name);
3585 #else
3586                         msg_format("%s drains HP from you!", o_name);
3587 #endif
3588                         take_hit(DAMAGE_LOSELIFE, MIN(p_ptr->lev*2, 100), o_name, -1);
3589                 }
3590                 /* Handle mana draining */
3591                 if ((p_ptr->cursed & TRC_DRAIN_MANA) && one_in_(666))
3592                 {
3593                         char o_name[MAX_NLEN];
3594
3595                         object_desc(o_name, choose_cursed_obj_name(TRC_DRAIN_MANA), FALSE, 0);
3596 #ifdef JP
3597 msg_format("%s¤Ï¤¢¤Ê¤¿¤ÎËâÎϤòµÛ¼ý¤·¤¿¡ª", o_name);
3598 #else
3599                         msg_format("%s drains mana from you!", o_name);
3600 #endif
3601                         p_ptr->csp -= MIN(p_ptr->lev, 50);
3602                         if (p_ptr->csp < 0)
3603                         {
3604                                 p_ptr->csp = 0;
3605                                 p_ptr->csp_frac = 0;
3606                         }
3607                         p_ptr->redraw |= PR_MANA;
3608                 }
3609         }
3610
3611         /* Rarely, take damage from the Jewel of Judgement */
3612         if (one_in_(999) && !p_ptr->anti_magic)
3613         {
3614                 if ((inventory[INVEN_LITE].tval) &&
3615                     (inventory[INVEN_LITE].sval == SV_LITE_JUDGE))
3616                 {
3617 #ifdef JP
3618 msg_print("¡Ø¿³È½¤ÎÊõÀС٤Ϥ¢¤Ê¤¿¤ÎÂÎÎϤòµÛ¼ý¤·¤¿¡ª");
3619 take_hit(DAMAGE_LOSELIFE, MIN(p_ptr->lev, 50), "¿³È½¤ÎÊõÀÐ", -1);
3620 #else
3621                         msg_print("The Jewel of Judgement drains life from you!");
3622                         take_hit(DAMAGE_LOSELIFE, MIN(p_ptr->lev, 50), "the Jewel of Judgement", -1);
3623 #endif
3624
3625                 }
3626         }
3627
3628
3629         /* Process equipment */
3630         for (j = 0, i = INVEN_RARM; i < INVEN_TOTAL; i++)
3631         {
3632                 /* Get the object */
3633                 o_ptr = &inventory[i];
3634
3635                 /* Skip non-objects */
3636                 if (!o_ptr->k_idx) continue;
3637
3638                 /* Recharge activatable objects */
3639                 if (o_ptr->timeout > 0)
3640                 {
3641                         /* Recharge */
3642                         o_ptr->timeout--;
3643
3644                         /* Notice changes */
3645                         if (!o_ptr->timeout)
3646                         {
3647                                 recharged_notice(o_ptr);
3648                                 j++;
3649                         }
3650                 }
3651         }
3652
3653         /* Notice changes */
3654         if (j)
3655         {
3656                 /* Window stuff */
3657                 p_ptr->window |= (PW_EQUIP);
3658                 wild_regen = 20;
3659         }
3660
3661         /*
3662          * Recharge rods.  Rods now use timeout to control charging status,
3663          * and each charging rod in a stack decreases the stack's timeout by
3664          * one per turn. -LM-
3665          */
3666         for (j = 0, i = 0; i < INVEN_PACK; i++)
3667         {
3668                 o_ptr = &inventory[i];
3669                 k_ptr = &k_info[o_ptr->k_idx];
3670
3671                 /* Skip non-objects */
3672                 if (!o_ptr->k_idx) continue;
3673
3674                 /* Examine all charging rods or stacks of charging rods. */
3675                 if ((o_ptr->tval == TV_ROD) && (o_ptr->timeout))
3676                 {
3677                         /* Determine how many rods are charging. */
3678                         temp = (o_ptr->timeout + (k_ptr->pval - 1)) / k_ptr->pval;
3679                         if (temp > o_ptr->number) temp = o_ptr->number;
3680
3681                         /* Decrease timeout by that number. */
3682                         o_ptr->timeout -= temp;
3683
3684                         /* Boundary control. */
3685                         if (o_ptr->timeout < 0) o_ptr->timeout = 0;
3686
3687                         /* Notice changes, provide message if object is inscribed. */
3688                         if (!(o_ptr->timeout))
3689                         {
3690                                 recharged_notice(o_ptr);
3691                                 j++;
3692                         }
3693                 }
3694         }
3695
3696         /* Notice changes */
3697         if (j)
3698         {
3699                 /* Combine pack */
3700                 p_ptr->notice |= (PN_COMBINE);
3701
3702                 /* Window stuff */
3703                 p_ptr->window |= (PW_INVEN);
3704                 wild_regen = 20;
3705         }
3706
3707         /* Feel the inventory */
3708         sense_inventory1();
3709         sense_inventory2();
3710
3711
3712         /*** Process Objects ***/
3713
3714         /* Process objects */
3715         for (i = 1; i < o_max; i++)
3716         {
3717                 /* Access object */
3718                 o_ptr = &o_list[i];
3719
3720                 /* Skip dead objects */
3721                 if (!o_ptr->k_idx) continue;
3722
3723                 /* Recharge rods on the ground.  No messages. */
3724                 if ((o_ptr->tval == TV_ROD) && (o_ptr->timeout))
3725                 {
3726                         /* Charge it */
3727                         o_ptr->timeout -= o_ptr->number;
3728
3729                         /* Boundary control. */
3730                         if (o_ptr->timeout < 0) o_ptr->timeout = 0;
3731                 }
3732         }
3733
3734
3735         /*** Involuntary Movement ***/
3736
3737         /* Delayed Word-of-Recall */
3738         if (p_ptr->word_recall)
3739         {
3740                 /*
3741                  * HACK: Autosave BEFORE resetting the recall counter (rr9)
3742                  * The player is yanked up/down as soon as
3743                  * he loads the autosaved game.
3744                  */
3745                 if (autosave_l && (p_ptr->word_recall == 1) && !p_ptr->inside_battle)
3746                         do_cmd_save_game(TRUE);
3747
3748                 /* Count down towards recall */
3749                 p_ptr->word_recall--;
3750
3751                 p_ptr->redraw |= (PR_STATUS);
3752
3753                 /* Activate the recall */
3754                 if (!p_ptr->word_recall)
3755                 {
3756                         /* Disturbing! */
3757                         disturb(0, 0);
3758
3759                         /* Determine the level */
3760                         if (dun_level || p_ptr->inside_quest)
3761                         {
3762 #ifdef JP
3763 msg_print("¾å¤Ë°ú¤ÃÄ¥¤ê¤¢¤²¤é¤ì¤ë´¶¤¸¤¬¤¹¤ë¡ª");
3764 #else
3765                                 msg_print("You feel yourself yanked upwards!");
3766 #endif
3767
3768                                 p_ptr->recall_dungeon = dungeon_type;
3769                                 if (record_stair)
3770                                         do_cmd_write_nikki(NIKKI_RECALL, dun_level, NULL);
3771
3772                                 dun_level = 0;
3773                                 dungeon_type = 0;
3774                                 prepare_change_floor_mode(CFM_CLEAR_ALL);
3775
3776                                 leave_quest_check();
3777
3778                                 p_ptr->inside_quest = 0;
3779                                 p_ptr->leaving = TRUE;
3780                         }
3781                         else
3782                         {
3783 #ifdef JP
3784 msg_print("²¼¤Ë°ú¤­¤º¤ê¹ß¤í¤µ¤ì¤ë´¶¤¸¤¬¤¹¤ë¡ª");
3785 #else
3786                                 msg_print("You feel yourself yanked downwards!");
3787 #endif
3788
3789                                 dungeon_type = p_ptr->recall_dungeon;
3790
3791                                 if (record_stair)
3792                                         do_cmd_write_nikki(NIKKI_RECALL, dun_level, NULL);
3793
3794                                 /* New depth */
3795                                 dun_level = max_dlv[dungeon_type];
3796                                 if (dun_level < 1) dun_level = 1;
3797
3798                                 /* Nightmare mode makes recall more dangerous */
3799                                 if (ironman_nightmare && !randint0(666) && (dungeon_type == DUNGEON_ANGBAND))
3800                                 {
3801                                         if (dun_level < 50)
3802                                         {
3803                                                 dun_level *= 2;
3804                                         }
3805                                         else if (dun_level < 99)
3806                                         {
3807                                                 dun_level = (dun_level + 99) / 2;
3808                                         }
3809                                         else if (dun_level > 100)
3810                                         {
3811                                                 dun_level = d_info[dungeon_type].maxdepth - 1;
3812                                         }
3813                                 }
3814
3815                                 if (p_ptr->wild_mode)
3816                                 {
3817                                         p_ptr->wilderness_y = py;
3818                                         p_ptr->wilderness_x = px;
3819                                 }
3820                                 else
3821                                 {
3822                                         /* Save player position */
3823                                         p_ptr->oldpx = px;
3824                                         p_ptr->oldpy = py;
3825                                 }
3826                                 p_ptr->wild_mode = FALSE;
3827
3828                                 prepare_change_floor_mode(CFM_CLEAR_ALL);
3829
3830                                 /* Leaving */
3831                                 p_ptr->leaving = TRUE;
3832
3833                                 if (dungeon_type == DUNGEON_ANGBAND)
3834                                 {
3835                                         for (i = MIN_RANDOM_QUEST; i < MAX_RANDOM_QUEST + 1; i++)
3836                                         {
3837                                                 if ((quest[i].type == QUEST_TYPE_RANDOM) &&
3838                                                     (quest[i].status == QUEST_STATUS_TAKEN) &&
3839                                                     (quest[i].level < dun_level))
3840                                                 {
3841                                                         quest[i].status = QUEST_STATUS_FAILED;
3842                                                         quest[i].complev = (byte)p_ptr->lev;
3843                                                         r_info[quest[i].r_idx].flags1 &= ~(RF1_QUESTOR);
3844                                                 }
3845                                         }
3846                                 }
3847                         }
3848
3849                         /* Sound */
3850                         sound(SOUND_TPLEVEL);
3851                 }
3852         }
3853
3854
3855         /* Delayed Alter reality */
3856         if (p_ptr->alter_reality)
3857         {
3858                 if (autosave_l && (p_ptr->alter_reality == 1) && !p_ptr->inside_battle)
3859                         do_cmd_save_game(TRUE);
3860
3861                 /* Count down towards alter */
3862                 p_ptr->alter_reality--;
3863
3864                 p_ptr->redraw |= (PR_STATUS);
3865
3866                 /* Activate the alter reality */
3867                 if (!p_ptr->alter_reality)
3868                 {
3869                         /* Disturbing! */
3870                         disturb(0, 0);
3871
3872                         /* Determine the level */
3873                         if (!quest_number(dun_level) && dun_level)
3874                         {
3875 #ifdef JP
3876                                 msg_print("À¤³¦¤¬ÊѤï¤Ã¤¿¡ª");
3877 #else
3878                                 msg_print("The world changes!");
3879 #endif
3880
3881                                 prepare_change_floor_mode(CFM_CLEAR_ALL);
3882
3883                                 /* Leaving */
3884                                 p_ptr->leaving = TRUE;
3885                         }
3886                         else
3887                         {
3888 #ifdef JP
3889                                 msg_print("À¤³¦¤¬¾¯¤·¤Î´ÖÊѲ½¤·¤¿¤è¤¦¤À¡£");
3890 #else
3891                                 msg_print("The world seems to change for a moment!");
3892 #endif
3893                         }
3894
3895                         /* Sound */
3896                         sound(SOUND_TPLEVEL);
3897                 }
3898         }
3899 }
3900
3901
3902
3903 /*
3904  * Verify use of "wizard" mode
3905  */
3906 static bool enter_wizard_mode(void)
3907 {
3908         /* Ask first time */
3909         if (!p_ptr->noscore)
3910         {
3911                 /* Wizard mode is not permitted */
3912                 if (!allow_debug_opts)
3913                 {
3914 #ifdef JP
3915                         msg_print("¥¦¥£¥¶¡¼¥É¥â¡¼¥É¤Ïµö²Ä¤µ¤ì¤Æ¤¤¤Þ¤»¤ó¡£ ");
3916 #else
3917                         msg_print("Wizard mode is not permitted.");
3918 #endif
3919                         return FALSE;
3920                 }
3921
3922                 /* Mention effects */
3923 #ifdef JP
3924                 msg_print("¥¦¥£¥¶¡¼¥É¥â¡¼¥É¤Ï¥Ç¥Ð¥°¤È¼Â¸³¤Î¤¿¤á¤Î¥â¡¼¥É¤Ç¤¹¡£ ");
3925                 msg_print("°ìÅÙ¥¦¥£¥¶¡¼¥É¥â¡¼¥É¤ËÆþ¤ë¤È¥¹¥³¥¢¤Ïµ­Ï¿¤µ¤ì¤Þ¤»¤ó¡£");
3926 #else
3927                 msg_print("Wizard mode is for debugging and experimenting.");
3928                 msg_print("The game will not be scored if you enter wizard mode.");
3929 #endif
3930
3931                 msg_print(NULL);
3932
3933                 /* Verify request */
3934 #ifdef JP
3935                 if (!get_check("ËÜÅö¤Ë¥¦¥£¥¶¡¼¥É¥â¡¼¥É¤ËÆþ¤ê¤¿¤¤¤Î¤Ç¤¹¤«? "))
3936 #else
3937                 if (!get_check("Are you sure you want to enter wizard mode? "))
3938 #endif
3939                 {
3940                         return (FALSE);
3941                 }
3942
3943 #ifdef JP
3944                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "¥¦¥£¥¶¡¼¥É¥â¡¼¥É¤ËÆÍÆþ¤·¤Æ¥¹¥³¥¢¤ò»Ä¤»¤Ê¤¯¤Ê¤Ã¤¿¡£");
3945 #else
3946                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "give up recording score to enter wizard mode.");
3947 #endif
3948                 /* Mark savefile */
3949                 p_ptr->noscore |= 0x0002;
3950         }
3951
3952         /* Success */
3953         return (TRUE);
3954 }
3955
3956
3957 #ifdef ALLOW_WIZARD
3958
3959 /*
3960  * Verify use of "debug" commands
3961  */
3962 static bool enter_debug_mode(void)
3963 {
3964         /* Ask first time */
3965         if (!p_ptr->noscore)
3966         {
3967                 /* Debug mode is not permitted */
3968                 if (!allow_debug_opts)
3969                 {
3970 #ifdef JP
3971                         msg_print("¥Ç¥Ð¥Ã¥°¥³¥Þ¥ó¥É¤Ïµö²Ä¤µ¤ì¤Æ¤¤¤Þ¤»¤ó¡£ ");
3972 #else
3973                         msg_print("Use of debug command is not permitted.");
3974 #endif
3975                         return FALSE;
3976                 }
3977
3978                 /* Mention effects */
3979 #ifdef JP
3980                 msg_print("¥Ç¥Ð¥°¡¦¥³¥Þ¥ó¥É¤Ï¥Ç¥Ð¥°¤È¼Â¸³¤Î¤¿¤á¤Î¥³¥Þ¥ó¥É¤Ç¤¹¡£ ");
3981                 msg_print("¥Ç¥Ð¥°¡¦¥³¥Þ¥ó¥É¤ò»È¤¦¤È¥¹¥³¥¢¤Ïµ­Ï¿¤µ¤ì¤Þ¤»¤ó¡£");
3982 #else
3983                 msg_print("The debug commands are for debugging and experimenting.");
3984                 msg_print("The game will not be scored if you use debug commands.");
3985 #endif
3986
3987                 msg_print(NULL);
3988
3989                 /* Verify request */
3990 #ifdef JP
3991                 if (!get_check("ËÜÅö¤Ë¥Ç¥Ð¥°¡¦¥³¥Þ¥ó¥É¤ò»È¤¤¤Þ¤¹¤«? "))
3992 #else
3993                 if (!get_check("Are you sure you want to use debug commands? "))
3994 #endif
3995                 {
3996                         return (FALSE);
3997                 }
3998
3999 #ifdef JP
4000                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "¥Ç¥Ð¥Ã¥°¥â¡¼¥É¤ËÆÍÆþ¤·¤Æ¥¹¥³¥¢¤ò»Ä¤»¤Ê¤¯¤Ê¤Ã¤¿¡£");
4001 #else
4002                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "give up sending score to use debug commands.");
4003 #endif
4004                 /* Mark savefile */
4005                 p_ptr->noscore |= 0x0008;
4006         }
4007
4008         /* Success */
4009         return (TRUE);
4010 }
4011
4012 /*
4013  * Hack -- Declare the Debug Routines
4014  */
4015 extern void do_cmd_debug(void);
4016
4017 #endif /* ALLOW_WIZARD */
4018
4019
4020 #ifdef ALLOW_BORG
4021
4022 /*
4023  * Verify use of "borg" commands
4024  */
4025 static bool enter_borg_mode(void)
4026 {
4027         /* Ask first time */
4028         if (!(p_ptr->noscore & 0x0010))
4029         {
4030                 /* Mention effects */
4031 #ifdef JP
4032                 msg_print("¥Ü¡¼¥°¡¦¥³¥Þ¥ó¥É¤Ï¥Ç¥Ð¥°¤È¼Â¸³¤Î¤¿¤á¤Î¥³¥Þ¥ó¥É¤Ç¤¹¡£ ");
4033                 msg_print("¥Ü¡¼¥°¡¦¥³¥Þ¥ó¥É¤ò»È¤¦¤È¥¹¥³¥¢¤Ïµ­Ï¿¤µ¤ì¤Þ¤»¤ó¡£");
4034 #else
4035                 msg_print("The borg commands are for debugging and experimenting.");
4036                 msg_print("The game will not be scored if you use borg commands.");
4037 #endif
4038
4039                 msg_print(NULL);
4040
4041                 /* Verify request */
4042 #ifdef JP
4043                 if (!get_check("ËÜÅö¤Ë¥Ü¡¼¥°¡¦¥³¥Þ¥ó¥É¤ò»È¤¤¤Þ¤¹¤«? "))
4044 #else
4045                 if (!get_check("Are you sure you want to use borg commands? "))
4046 #endif
4047                 {
4048                         return (FALSE);
4049                 }
4050
4051 #ifdef JP
4052                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "¥Ü¡¼¥°¡¦¥³¥Þ¥ó¥É¤ò»ÈÍѤ·¤Æ¥¹¥³¥¢¤ò»Ä¤»¤Ê¤¯¤Ê¤Ã¤¿¡£");
4053 #else
4054                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "give up recording score to use borg commands.");
4055 #endif
4056                 /* Mark savefile */
4057                 p_ptr->noscore |= 0x0010;
4058         }
4059
4060         /* Success */
4061         return (TRUE);
4062 }
4063
4064 /*
4065  * Hack -- Declare the Ben Borg
4066  */
4067 extern void do_cmd_borg(void);
4068
4069 #endif /* ALLOW_BORG */
4070
4071
4072
4073 /*
4074  * Parse and execute the current command
4075  * Give "Warning" on illegal commands.
4076  *
4077  * XXX XXX XXX Make some "blocks"
4078  */
4079 static void process_command(void)
4080 {
4081         int old_now_message = now_message;
4082
4083 #ifdef ALLOW_REPEAT /* TNB */
4084
4085         /* Handle repeating the last command */
4086         repeat_check();
4087
4088 #endif /* ALLOW_REPEAT -- TNB */
4089
4090         now_message = 0;
4091
4092         /* Parse the command */
4093         switch (command_cmd)
4094         {
4095                 /* Ignore */
4096                 case ESCAPE:
4097                 case ' ':
4098                 {
4099                         break;
4100                 }
4101
4102                 /* Ignore return */
4103                 case '\r':
4104                 case '\n':
4105                 {
4106                         break;
4107                 }
4108
4109                 /*** Wizard Commands ***/
4110
4111                 /* Toggle Wizard Mode */
4112                 case KTRL('W'):
4113                 {
4114                         if (p_ptr->wizard)
4115                         {
4116                                 p_ptr->wizard = FALSE;
4117 #ifdef JP
4118 msg_print("¥¦¥£¥¶¡¼¥É¥â¡¼¥É²ò½ü¡£");
4119 #else
4120                                 msg_print("Wizard mode off.");
4121 #endif
4122
4123                         }
4124                         else if (enter_wizard_mode())
4125                         {
4126                                 p_ptr->wizard = TRUE;
4127 #ifdef JP
4128 msg_print("¥¦¥£¥¶¡¼¥É¥â¡¼¥ÉÆÍÆþ¡£");
4129 #else
4130                                 msg_print("Wizard mode on.");
4131 #endif
4132
4133                         }
4134
4135                         /* Update monsters */
4136                         p_ptr->update |= (PU_MONSTERS);
4137
4138                         /* Redraw "title" */
4139                         p_ptr->redraw |= (PR_TITLE);
4140
4141                         break;
4142                 }
4143
4144
4145 #ifdef ALLOW_WIZARD
4146
4147                 /* Special "debug" commands */
4148                 case KTRL('A'):
4149                 {
4150                         /* Enter debug mode */
4151                         if (enter_debug_mode())
4152                         {
4153                                 do_cmd_debug();
4154                         }
4155                         break;
4156                 }
4157
4158 #endif /* ALLOW_WIZARD */
4159
4160
4161 #ifdef ALLOW_BORG
4162
4163                 /* Special "borg" commands */
4164                 case KTRL('Z'):
4165                 {
4166                         /* Enter borg mode */
4167                         if (enter_borg_mode())
4168                         {
4169                                 if (!p_ptr->wild_mode) do_cmd_borg();
4170                         }
4171
4172                         break;
4173                 }
4174
4175 #endif /* ALLOW_BORG */
4176
4177
4178
4179                 /*** Inventory Commands ***/
4180
4181                 /* Wear/wield equipment */
4182                 case 'w':
4183                 {
4184                         if (!p_ptr->wild_mode) do_cmd_wield();
4185                         break;
4186                 }
4187
4188                 /* Take off equipment */
4189                 case 't':
4190                 {
4191                         if (!p_ptr->wild_mode) do_cmd_takeoff();
4192                         break;
4193                 }
4194
4195                 /* Drop an item */
4196                 case 'd':
4197                 {
4198                         if (!p_ptr->wild_mode) do_cmd_drop();
4199                         break;
4200                 }
4201
4202                 /* Destroy an item */
4203                 case 'k':
4204                 {
4205                         do_cmd_destroy();
4206                         break;
4207                 }
4208
4209                 /* Equipment list */
4210                 case 'e':
4211                 {
4212                         do_cmd_equip();
4213                         break;
4214                 }
4215
4216                 /* Inventory list */
4217                 case 'i':
4218                 {
4219                         do_cmd_inven();
4220                         break;
4221                 }
4222
4223
4224                 /*** Various commands ***/
4225
4226                 /* Identify an object */
4227                 case 'I':
4228                 {
4229                         do_cmd_observe();
4230                         break;
4231                 }
4232
4233                 /* Hack -- toggle windows */
4234                 case KTRL('I'):
4235                 {
4236                         toggle_inven_equip();
4237                         break;
4238                 }
4239
4240
4241                 /*** Standard "Movement" Commands ***/
4242
4243                 /* Alter a grid */
4244                 case '+':
4245                 {
4246                         if (!p_ptr->wild_mode) do_cmd_alter();
4247                         break;
4248                 }
4249
4250                 /* Dig a tunnel */
4251                 case 'T':
4252                 {
4253                         if (!p_ptr->wild_mode) do_cmd_tunnel();
4254                         break;
4255                 }
4256
4257                 /* Move (usually pick up things) */
4258                 case ';':
4259                 {
4260 #ifdef ALLOW_EASY_DISARM /* TNB */
4261
4262                         do_cmd_walk(FALSE);
4263
4264 #else /* ALLOW_EASY_DISARM -- TNB */
4265
4266                         do_cmd_walk(always_pickup);
4267
4268 #endif /* ALLOW_EASY_DISARM -- TNB */
4269
4270                         break;
4271                 }
4272
4273                 /* Move (usually do not pick up) */
4274                 case '-':
4275                 {
4276 #ifdef ALLOW_EASY_DISARM /* TNB */
4277
4278                         do_cmd_walk(TRUE);
4279
4280 #else /* ALLOW_EASY_DISARM -- TNB */
4281
4282                         do_cmd_walk(!always_pickup);
4283
4284 #endif /* ALLOW_EASY_DISARM -- TNB */
4285
4286                         break;
4287                 }
4288
4289
4290                 /*** Running, Resting, Searching, Staying */
4291
4292                 /* Begin Running -- Arg is Max Distance */
4293                 case '.':
4294                 {
4295                         if (!p_ptr->wild_mode) do_cmd_run();
4296                         break;
4297                 }
4298
4299                 /* Stay still (usually pick things up) */
4300                 case ',':
4301                 {
4302                         do_cmd_stay(always_pickup);
4303                         break;
4304                 }
4305
4306                 /* Stay still (usually do not pick up) */
4307                 case 'g':
4308                 {
4309                         do_cmd_stay(!always_pickup);
4310                         break;
4311                 }
4312
4313                 /* Rest -- Arg is time */
4314                 case 'R':
4315                 {
4316                         do_cmd_rest();
4317                         break;
4318                 }
4319
4320                 /* Search for traps/doors */
4321                 case 's':
4322                 {
4323                         do_cmd_search();
4324                         break;
4325                 }
4326
4327                 /* Toggle search mode */
4328                 case 'S':
4329                 {
4330                         if (p_ptr->action == ACTION_SEARCH) set_action(ACTION_NONE);
4331                         else set_action(ACTION_SEARCH);
4332                         break;
4333                 }
4334
4335
4336                 /*** Stairs and Doors and Chests and Traps ***/
4337
4338                 /* Enter store */
4339                 case SPECIAL_KEY_STORE:
4340                 {
4341                         if (!p_ptr->wild_mode) do_cmd_store();
4342                         break;
4343                 }
4344
4345                 /* Enter building -KMW- */
4346                 case SPECIAL_KEY_BUILDING:
4347                 {
4348                         if (!p_ptr->wild_mode) do_cmd_bldg();
4349                         break;
4350                 }
4351
4352                 /* Enter quest level -KMW- */
4353                 case SPECIAL_KEY_QUEST:
4354                 {
4355                         if (!p_ptr->wild_mode) do_cmd_quest();
4356                         break;
4357                 }
4358
4359                 /* Go up staircase */
4360                 case '<':
4361                 {
4362                         if(!p_ptr->wild_mode && !dun_level && !p_ptr->inside_arena && !p_ptr->inside_quest)
4363                         {
4364                                 if (!vanilla_town)
4365                                 {
4366                                         if(ambush_flag)
4367                                         {
4368 #ifdef JP
4369                                                 msg_print("½±·â¤«¤éƨ¤²¤ë¤Ë¤Ï¥Þ¥Ã¥×¤Îü¤Þ¤Ç°ÜÆ°¤·¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£");
4370 #else
4371                                                 msg_print("To flee the ambush you have to reach the edge of the map.");
4372 #endif
4373                                         }
4374                                         else if (p_ptr->food < PY_FOOD_WEAK)
4375                                         {
4376 #ifdef JP
4377                                                 msg_print("¤½¤ÎÁ°¤Ë¿©»ö¤ò¤È¤é¤Ê¤¤¤È¡£");
4378 #else
4379                                                 msg_print("You must eat something here.");
4380 #endif
4381                                         }
4382                                         else
4383                                         {
4384                                                 if (change_wild_mode())
4385                                                 {
4386                                                         p_ptr->oldpx = px;
4387                                                         p_ptr->oldpy = py;
4388                                                 }
4389                                         }
4390                                 }
4391                         }
4392                         else
4393                                 do_cmd_go_up();
4394                         break;
4395                 }
4396
4397                 /* Go down staircase */
4398                 case '>':
4399                 {
4400                         if(!p_ptr->wild_mode) do_cmd_go_down();
4401                         else
4402                         {
4403                                 p_ptr->wilderness_x = px;
4404                                 p_ptr->wilderness_y = py;
4405                                 change_wild_mode();
4406                         }
4407                         break;
4408                 }
4409
4410                 /* Open a door or chest */
4411                 case 'o':
4412                 {
4413                         if (!p_ptr->wild_mode) do_cmd_open();
4414                         break;
4415                 }
4416
4417                 /* Close a door */
4418                 case 'c':
4419                 {
4420                         if (!p_ptr->wild_mode) do_cmd_close();
4421                         break;
4422                 }
4423
4424                 /* Jam a door with spikes */
4425                 case 'j':
4426                 {
4427                         if (!p_ptr->wild_mode) do_cmd_spike();
4428                         break;
4429                 }
4430
4431                 /* Bash a door */
4432                 case 'B':
4433                 {
4434                         if (!p_ptr->wild_mode) do_cmd_bash();
4435                         break;
4436                 }
4437
4438                 /* Disarm a trap or chest */
4439                 case 'D':
4440                 {
4441                         if (!p_ptr->wild_mode) do_cmd_disarm();
4442                         break;
4443                 }
4444
4445
4446                 /*** Magic and Prayers ***/
4447
4448                 /* Gain new spells/prayers */
4449                 case 'G':
4450                 {
4451                         if ((p_ptr->pclass == CLASS_SORCERER) || (p_ptr->pclass == CLASS_RED_MAGE))
4452 #ifdef JP
4453                                 msg_print("¼öʸ¤ò³Ø½¬¤¹¤ëɬÍפϤʤ¤¡ª");
4454 #else
4455                                 msg_print("You don't have to learn spells!");
4456 #endif
4457                         else if (p_ptr->pclass == CLASS_SAMURAI)
4458                                 do_cmd_gain_hissatsu();
4459                         else if (p_ptr->pclass == CLASS_MAGIC_EATER)
4460                                 gain_magic();
4461                         else
4462                                 do_cmd_study();
4463                         break;
4464                 }
4465
4466                 /* Browse a book */
4467                 case 'b':
4468                 {
4469                         if ( (p_ptr->pclass == CLASS_MINDCRAFTER) ||
4470                              (p_ptr->pclass == CLASS_BERSERKER) ||
4471                              (p_ptr->pclass == CLASS_NINJA) ||
4472                              (p_ptr->pclass == CLASS_MIRROR_MASTER) 
4473                              ) do_cmd_mind_browse();
4474                         else if (p_ptr->pclass == CLASS_SMITH)
4475                                 do_cmd_kaji(TRUE);
4476                         else if (p_ptr->pclass == CLASS_MAGIC_EATER)
4477                                 do_cmd_magic_eater(TRUE);
4478                         else do_cmd_browse();
4479                         break;
4480                 }
4481
4482                 /* Cast a spell */
4483                 case 'm':
4484                 {
4485                         /* -KMW- */
4486                         if (!p_ptr->wild_mode)
4487                         {
4488                                 if ((p_ptr->pclass == CLASS_WARRIOR) || (p_ptr->pclass == CLASS_ARCHER) || (p_ptr->pclass == CLASS_CAVALRY))
4489                                 {
4490 #ifdef JP
4491                                         msg_print("¼öʸ¤ò¾§¤¨¤é¤ì¤Ê¤¤¡ª");
4492 #else
4493                                         msg_print("You cannot cast spells!");
4494 #endif
4495                                 }
4496                                 else if (dun_level && (d_info[dungeon_type].flags1 & DF1_NO_MAGIC) && (p_ptr->pclass != CLASS_BERSERKER) && (p_ptr->pclass != CLASS_SMITH))
4497                                 {
4498 #ifdef JP
4499                                         msg_print("¥À¥ó¥¸¥ç¥ó¤¬ËâË¡¤òµÛ¼ý¤·¤¿¡ª");
4500 #else
4501                                         msg_print("The dungeon absorbs all attempted magic!");
4502 #endif
4503                                         msg_print(NULL);
4504                                 }
4505                                 else if (p_ptr->anti_magic && (p_ptr->pclass != CLASS_BERSERKER) && (p_ptr->pclass != CLASS_SMITH))
4506                                 {
4507 #ifdef JP
4508
4509                                         cptr which_power = "ËâË¡";
4510 #else
4511                                         cptr which_power = "magic";
4512 #endif
4513                                         if (p_ptr->pclass == CLASS_MINDCRAFTER)
4514 #ifdef JP
4515                                                 which_power = "ĶǽÎÏ";
4516 #else
4517                                                 which_power = "psionic powers";
4518 #endif
4519                                         else if (p_ptr->pclass == CLASS_IMITATOR)
4520 #ifdef JP
4521                                                 which_power = "¤â¤Î¤Þ¤Í";
4522 #else
4523                                                 which_power = "imitation";
4524 #endif
4525                                         else if (p_ptr->pclass == CLASS_SAMURAI)
4526 #ifdef JP
4527                                                 which_power = "ɬ»¦·õ";
4528 #else
4529                                                 which_power = "hissatsu";
4530 #endif
4531                                         else if (p_ptr->pclass == CLASS_MIRROR_MASTER)
4532 #ifdef JP
4533                                                 which_power = "¶ÀËâË¡";
4534 #else
4535                                                 which_power = "mirror magic";
4536 #endif
4537                                         else if (p_ptr->pclass == CLASS_NINJA)
4538 #ifdef JP
4539                                                 which_power = "Ǧ½Ñ";
4540 #else
4541                                                 which_power = "ninjutsu";
4542 #endif
4543                                         else if (mp_ptr->spell_book == TV_LIFE_BOOK)
4544 #ifdef JP
4545                                                 which_power = "µ§¤ê";
4546 #else
4547                                                 which_power = "prayer";
4548 #endif
4549
4550 #ifdef JP
4551                                         msg_format("È¿ËâË¡¥Ð¥ê¥¢¤¬%s¤ò¼ÙË⤷¤¿¡ª", which_power);
4552 #else
4553                                         msg_format("An anti-magic shell disrupts your %s!", which_power);
4554 #endif
4555                                         energy_use = 0;
4556                                 }
4557                                 else if (p_ptr->shero && (p_ptr->pclass != CLASS_BERSERKER))
4558                                 {
4559 #ifdef JP
4560                                         msg_format("¶¸Àï»Î²½¤·¤Æ¤¤¤ÆƬ¤¬²ó¤é¤Ê¤¤¡ª");
4561 #else
4562                                         msg_format("You cannot think directly!");
4563 #endif
4564                                         energy_use = 0;
4565                                 }
4566                                 else
4567                                 {
4568                                         if ((p_ptr->pclass == CLASS_MINDCRAFTER) ||
4569                                             (p_ptr->pclass == CLASS_BERSERKER) ||
4570                                             (p_ptr->pclass == CLASS_NINJA) ||
4571                                             (p_ptr->pclass == CLASS_MIRROR_MASTER)
4572                                             )
4573                                                 do_cmd_mind();
4574                                         else if (p_ptr->pclass == CLASS_IMITATOR)
4575                                                 do_cmd_mane(FALSE);
4576                                         else if (p_ptr->pclass == CLASS_MAGIC_EATER)
4577                                                 do_cmd_magic_eater(FALSE);
4578                                         else if (p_ptr->pclass == CLASS_SAMURAI)
4579                                                 do_cmd_hissatsu();
4580                                         else if (p_ptr->pclass == CLASS_BLUE_MAGE)
4581                                                 do_cmd_cast_learned();
4582                                         else if (p_ptr->pclass == CLASS_SMITH)
4583                                                 do_cmd_kaji(FALSE);
4584                                         else
4585                                                 do_cmd_cast();
4586                                 }
4587                         }
4588                         break;
4589                 }
4590
4591                 /* Issue a pet command */
4592                 case 'p':
4593                 {
4594                         if (!p_ptr->wild_mode) do_cmd_pet();
4595                         break;
4596                 }
4597
4598                 /*** Use various objects ***/
4599
4600                 /* Inscribe an object */
4601                 case '{':
4602                 {
4603                         do_cmd_inscribe();
4604                         break;
4605                 }
4606
4607                 /* Uninscribe an object */
4608                 case '}':
4609                 {
4610                         do_cmd_uninscribe();
4611                         break;
4612                 }
4613
4614                 /* Activate an artifact */
4615                 case 'A':
4616                 {
4617                         if (!p_ptr->wild_mode)
4618                         {
4619                         if (!p_ptr->inside_arena)
4620                                 do_cmd_activate();
4621                         else
4622                         {
4623 #ifdef JP
4624 msg_print("¥¢¥ê¡¼¥Ê¤¬ËâË¡¤òµÛ¼ý¤·¤¿¡ª");
4625 #else
4626                                 msg_print("The arena absorbs all attempted magic!");
4627 #endif
4628
4629                                 msg_print(NULL);
4630                         }
4631                         }
4632                         break;
4633                 }
4634
4635                 /* Eat some food */
4636                 case 'E':
4637                 {
4638                         do_cmd_eat_food();
4639                         break;
4640                 }
4641
4642                 /* Fuel your lantern/torch */
4643                 case 'F':
4644                 {
4645                         do_cmd_refill();
4646                         break;
4647                 }
4648
4649                 /* Fire an item */
4650                 case 'f':
4651                 {
4652                         if (!p_ptr->wild_mode) do_cmd_fire();
4653                         break;
4654                 }
4655
4656                 /* Throw an item */
4657                 case 'v':
4658                 {
4659                         if (!p_ptr->wild_mode)
4660                         {
4661                                 do_cmd_throw();
4662                         }
4663                         break;
4664                 }
4665
4666                 /* Aim a wand */
4667                 case 'a':
4668                 {
4669                         if (!p_ptr->wild_mode)
4670                         {
4671                         if (!p_ptr->inside_arena)
4672                                 do_cmd_aim_wand();
4673                         else
4674                         {
4675 #ifdef JP
4676 msg_print("¥¢¥ê¡¼¥Ê¤¬ËâË¡¤òµÛ¼ý¤·¤¿¡ª");
4677 #else
4678                                 msg_print("The arena absorbs all attempted magic!");
4679 #endif
4680
4681                                 msg_print(NULL);
4682                         }
4683                         }
4684                         break;
4685                 }
4686
4687                 /* Zap a rod */
4688                 case 'z':
4689                 {
4690                         if (!p_ptr->wild_mode)
4691                         {
4692                         if (p_ptr->inside_arena)
4693                         {
4694 #ifdef JP
4695 msg_print("¥¢¥ê¡¼¥Ê¤¬ËâË¡¤òµÛ¼ý¤·¤¿¡ª");
4696 #else
4697                                 msg_print("The arena absorbs all attempted magic!");
4698 #endif
4699
4700                                 msg_print(NULL);
4701                         }
4702                         else if (use_command && rogue_like_commands)
4703                         {
4704                                 do_cmd_use();
4705                         }
4706                         else
4707                         {
4708                                 do_cmd_zap_rod();
4709                         }
4710                         }
4711                         break;
4712                 }
4713
4714                 /* Quaff a potion */
4715                 case 'q':
4716                 {
4717                         if (!p_ptr->wild_mode)
4718                         {
4719                         if (!p_ptr->inside_arena)
4720                                 do_cmd_quaff_potion();
4721                         else
4722                         {
4723 #ifdef JP
4724 msg_print("¥¢¥ê¡¼¥Ê¤¬ËâË¡¤òµÛ¼ý¤·¤¿¡ª");
4725 #else
4726                                 msg_print("The arena absorbs all attempted magic!");
4727 #endif
4728
4729                                 msg_print(NULL);
4730                         }
4731                         }
4732                         break;
4733                 }
4734
4735                 /* Read a scroll */
4736                 case 'r':
4737                 {
4738                         if (!p_ptr->wild_mode)
4739                         {
4740                         if (!p_ptr->inside_arena)
4741                                 do_cmd_read_scroll();
4742                         else
4743                         {
4744 #ifdef JP
4745 msg_print("¥¢¥ê¡¼¥Ê¤¬ËâË¡¤òµÛ¼ý¤·¤¿¡ª");
4746 #else
4747                                 msg_print("The arena absorbs all attempted magic!");
4748 #endif
4749
4750                                 msg_print(NULL);
4751                         }
4752                         }
4753                         break;
4754                 }
4755
4756                 /* Use a staff */
4757                 case 'u':
4758                 {
4759                         if (!p_ptr->wild_mode)
4760                         {
4761                         if (p_ptr->inside_arena)
4762                         {
4763 #ifdef JP
4764 msg_print("¥¢¥ê¡¼¥Ê¤¬ËâË¡¤òµÛ¼ý¤·¤¿¡ª");
4765 #else
4766                                 msg_print("The arena absorbs all attempted magic!");
4767 #endif
4768
4769                                 msg_print(NULL);
4770                         }
4771                         else if (use_command && !rogue_like_commands)
4772                         {
4773                                 do_cmd_use();
4774                         }
4775                         else
4776                                 do_cmd_use_staff();
4777                         }
4778                         break;
4779                 }
4780
4781                 /* Use racial power */
4782                 case 'U':
4783                 {
4784                         if (!p_ptr->wild_mode) do_cmd_racial_power();
4785                         break;
4786                 }
4787
4788
4789                 /*** Looking at Things (nearby or on map) ***/
4790
4791                 /* Full dungeon map */
4792                 case 'M':
4793                 {
4794                         do_cmd_view_map();
4795                         break;
4796                 }
4797
4798                 /* Locate player on map */
4799                 case 'L':
4800                 {
4801                         do_cmd_locate();
4802                         break;
4803                 }
4804
4805                 /* Look around */
4806                 case 'l':
4807                 {
4808                         do_cmd_look();
4809                         break;
4810                 }
4811
4812                 /* Target monster or location */
4813                 case '*':
4814                 {
4815                         if (!p_ptr->wild_mode) do_cmd_target();
4816                         break;
4817                 }
4818
4819
4820
4821                 /*** Help and Such ***/
4822
4823                 /* Help */
4824                 case '?':
4825                 {
4826                         do_cmd_help();
4827                         break;
4828                 }
4829
4830                 /* Identify symbol */
4831                 case '/':
4832                 {
4833                         do_cmd_query_symbol();
4834                         break;
4835                 }
4836
4837                 /* Character description */
4838                 case 'C':
4839                 {
4840                         do_cmd_change_name();
4841                         break;
4842                 }
4843
4844
4845                 /*** System Commands ***/
4846
4847                 /* Hack -- User interface */
4848                 case '!':
4849                 {
4850                         (void)Term_user(0);
4851                         break;
4852                 }
4853
4854                 /* Single line from a pref file */
4855                 case '"':
4856                 {
4857                         do_cmd_pref();
4858                         break;
4859                 }
4860
4861                 case '$':
4862                 {
4863                         do_cmd_pickpref();
4864                         break;
4865                 }
4866
4867                 case '_':
4868                 {
4869                         do_cmd_edit_autopick();
4870                         break;
4871                 }
4872
4873                 /* Interact with macros */
4874                 case '@':
4875                 {
4876                         do_cmd_macros();
4877                         break;
4878                 }
4879
4880                 /* Interact with visuals */
4881                 case '%':
4882                 {
4883                         do_cmd_visuals();
4884                         do_cmd_redraw();
4885                         break;
4886                 }
4887
4888                 /* Interact with colors */
4889                 case '&':
4890                 {
4891                         do_cmd_colors();
4892                         do_cmd_redraw();
4893                         break;
4894                 }
4895
4896                 /* Interact with options */
4897                 case '=':
4898                 {
4899                         do_cmd_options();
4900                         do_cmd_redraw();
4901                         break;
4902                 }
4903
4904                 /*** Misc Commands ***/
4905
4906                 /* Take notes */
4907                 case ':':
4908                 {
4909                         do_cmd_note();
4910                         break;
4911                 }
4912
4913                 /* Version info */
4914                 case 'V':
4915                 {
4916                         do_cmd_version();
4917                         break;
4918                 }
4919
4920                 /* Repeat level feeling */
4921                 case KTRL('F'):
4922                 {
4923                         if (!p_ptr->wild_mode) do_cmd_feeling();
4924                         break;
4925                 }
4926
4927                 /* Show previous message */
4928                 case KTRL('O'):
4929                 {
4930                         do_cmd_message_one();
4931                         break;
4932                 }
4933
4934                 /* Show previous messages */
4935                 case KTRL('P'):
4936                 {
4937                         do_cmd_messages(old_now_message);
4938                         break;
4939                 }
4940
4941                 /* Show quest status -KMW- */
4942                 case KTRL('Q'):
4943                 {
4944                         do_cmd_checkquest();
4945                         break;
4946                 }
4947
4948                 /* Redraw the screen */
4949                 case KTRL('R'):
4950                 {
4951                         now_message = old_now_message;
4952                         do_cmd_redraw();
4953                         break;
4954                 }
4955
4956 #ifndef VERIFY_SAVEFILE
4957
4958                 /* Hack -- Save and don't quit */
4959                 case KTRL('S'):
4960                 {
4961                         do_cmd_save_game(FALSE);
4962                         break;
4963                 }
4964
4965 #endif /* VERIFY_SAVEFILE */
4966
4967                 case KTRL('T'):
4968                 {
4969                         do_cmd_time();
4970                         break;
4971                 }
4972
4973                 /* Save and quit */
4974                 case KTRL('X'):
4975                 case SPECIAL_KEY_QUIT:
4976                 {
4977                         do_cmd_save_and_exit();
4978                         break;
4979                 }
4980
4981                 /* Quit (commit suicide) */
4982                 case 'Q':
4983                 {
4984                         do_cmd_suicide();
4985                         break;
4986                 }
4987
4988                 case '|':
4989                 {
4990                         do_cmd_nikki();
4991                         break;
4992                 }
4993
4994                 /* Check artifacts, uniques, objects */
4995                 case '~':
4996                 {
4997                         do_cmd_knowledge();
4998                         break;
4999                 }
5000
5001                 /* Load "screen dump" */
5002                 case '(':
5003                 {
5004                         do_cmd_load_screen();
5005                         break;
5006                 }
5007
5008                 /* Save "screen dump" */
5009                 case ')':
5010                 {
5011                         do_cmd_save_screen();
5012                         break;
5013                 }
5014
5015                 /* Make random artifact list */
5016                 case KTRL('V'):
5017                 {
5018                         spoil_random_artifact("randifact.txt");
5019                         break;
5020                 }
5021
5022                 /* Hack -- Unknown command */
5023                 default:
5024                 {
5025                         if (flush_failure) flush();
5026                         if (one_in_(2))
5027                         {
5028                                 char error_m[1024];
5029                                 sound(SOUND_ILLEGAL);
5030 #ifdef JP
5031                                 if (!get_rnd_line("error_j.txt", 0, error_m))
5032 #else
5033                                 if (!get_rnd_line("error.txt", 0, error_m))
5034 #endif
5035
5036                                         msg_print(error_m);
5037                         }
5038                         else
5039 #ifdef JP
5040 prt(" '?' ¤Ç¥Ø¥ë¥×¤¬É½¼¨¤µ¤ì¤Þ¤¹¡£", 0, 0);
5041 #else
5042                                 prt("Type '?' for help.", 0, 0);
5043 #endif
5044
5045                         break;
5046                 }
5047         }
5048         if (!energy_use && !now_message)
5049                 now_message = old_now_message;
5050 }
5051
5052
5053
5054
5055 static bool monster_tsuri(int r_idx)
5056 {
5057         monster_race *r_ptr = &r_info[r_idx];
5058
5059         if ((r_ptr->flags7 & RF7_AQUATIC) && !(r_ptr->flags1 & RF1_UNIQUE) && strchr("Jjlw", r_ptr->d_char))
5060                 return TRUE;
5061         else
5062                 return FALSE;
5063 }
5064
5065
5066 /*
5067  * Process the player
5068  *
5069  * Notice the annoying code to handle "pack overflow", which
5070  * must come first just in case somebody manages to corrupt
5071  * the savefiles by clever use of menu commands or something.
5072  */
5073 static void process_player(void)
5074 {
5075         int i;
5076
5077         /*** Apply energy ***/
5078
5079         if (hack_mutation)
5080         {
5081 #ifdef JP
5082 msg_print("²¿¤«ÊѤï¤Ã¤¿µ¤¤¬¤¹¤ë¡ª");
5083 #else
5084                 msg_print("You feel different!");
5085 #endif
5086
5087                 (void)gain_random_mutation(0);
5088                 hack_mutation = FALSE;
5089         }
5090
5091         if (p_ptr->inside_battle)
5092         {
5093                 for(i = 1; i < m_max; i++)
5094                 {
5095                         monster_type *m_ptr = &m_list[i];
5096
5097                         if (!m_ptr->r_idx) continue;
5098
5099                         /* Hack -- Detect monster */
5100                         m_ptr->mflag |= (MFLAG_MARK | MFLAG_SHOW);
5101
5102                         /* Update the monster */
5103                         update_mon(i, FALSE);
5104                 }
5105                 prt_time();
5106         }
5107
5108         /* Give the player some energy */
5109         else if (!(load && p_ptr->energy_need <= 0))
5110         {
5111                 p_ptr->energy_need -= (p_ptr->pspeed > 199 ? 49 : (p_ptr->pspeed < 0 ? 1 : extract_energy[p_ptr->pspeed]));
5112         }
5113
5114         /* No turn yet */
5115         if (p_ptr->energy_need > 0) return;
5116         if (!command_rep) prt_time();
5117
5118         /*** Check for interupts ***/
5119
5120         /* Complete resting */
5121         if (resting < 0)
5122         {
5123                 /* Basic resting */
5124                 if (resting == -1)
5125                 {
5126                         /* Stop resting */
5127                         if ((p_ptr->chp == p_ptr->mhp) &&
5128                             (p_ptr->csp >= p_ptr->msp))
5129                         {
5130                                 set_action(ACTION_NONE);
5131                         }
5132                 }
5133
5134                 /* Complete resting */
5135                 else if (resting == -2)
5136                 {
5137                         /* Stop resting */
5138                         if ((p_ptr->chp == p_ptr->mhp) &&
5139                             (p_ptr->csp >= p_ptr->msp) &&
5140                             !p_ptr->blind && !p_ptr->confused &&
5141                             !p_ptr->poisoned && !p_ptr->afraid &&
5142                             !p_ptr->stun && !p_ptr->cut &&
5143                             !p_ptr->slow && !p_ptr->paralyzed &&
5144                             !p_ptr->image && !p_ptr->word_recall &&
5145                             !p_ptr->alter_reality)
5146                         {
5147                                 set_action(ACTION_NONE);
5148                         }
5149                 }
5150         }
5151
5152         if (p_ptr->action == ACTION_FISH)
5153         {
5154                 /* Delay */
5155                 Term_xtra(TERM_XTRA_DELAY, 10);
5156                 if (one_in_(1000))
5157                 {
5158                         int r_idx;
5159                         bool success = FALSE;
5160                         get_mon_num_prep(monster_tsuri,NULL);
5161                         r_idx = get_mon_num(dun_level ? dun_level : wilderness[p_ptr->wilderness_y][p_ptr->wilderness_x].level);
5162                         msg_print(NULL);
5163                         if (r_idx && one_in_(2))
5164                         {
5165                                 int y, x;
5166                                 y = py+ddy[tsuri_dir];
5167                                 x = px+ddx[tsuri_dir];
5168                                 if (place_monster_aux(0, y, x, r_idx, PM_NO_KAGE))
5169                                 {
5170                                         char m_name[80];
5171                                         monster_desc(m_name, &m_list[cave[y][x].m_idx], 0);
5172 #ifdef JP
5173                                         msg_format("%s¤¬Äà¤ì¤¿¡ª", m_name);
5174 #else
5175                                         msg_format("You have a good catch!", m_name);
5176 #endif
5177                                         success = TRUE;
5178                                 }
5179                         }
5180                         if (!success)
5181                         {
5182 #ifdef JP
5183                                 msg_print("±Â¤À¤±¿©¤ï¤ì¤Æ¤·¤Þ¤Ã¤¿¡ª¤¯¤Ã¤½¡Á¡ª");
5184 #else
5185                                 msg_print("Damn!  The fish stole your bait!");
5186 #endif
5187                         }
5188                         disturb(0, 0);
5189                 }
5190         }
5191
5192         /* Handle "abort" */
5193         if (check_abort)
5194         {
5195                 /* Check for "player abort" (semi-efficiently for resting) */
5196                 if (running || command_rep || (p_ptr->action == ACTION_REST) || (p_ptr->action == ACTION_FISH))
5197                 {
5198                         /* Do not wait */
5199                         inkey_scan = TRUE;
5200
5201                         /* Check for a key */
5202                         if (inkey())
5203                         {
5204                                 /* Flush input */
5205                                 flush();
5206
5207                                 /* Disturb */
5208                                 disturb(0, 0);
5209
5210                                 /* Hack -- Show a Message */
5211 #ifdef JP
5212 msg_print("ÃæÃǤ·¤Þ¤·¤¿¡£");
5213 #else
5214                                 msg_print("Canceled.");
5215 #endif
5216
5217                         }
5218                 }
5219         }
5220
5221         if (p_ptr->riding && !p_ptr->confused && !p_ptr->blind)
5222         {
5223                 monster_type *m_ptr = &m_list[p_ptr->riding];
5224
5225                 if (m_ptr->csleep)
5226                 {
5227                         char m_name[80];
5228
5229                         /* Recover fully */
5230                         m_ptr->csleep = 0;
5231
5232                         /* Acquire the monster name */
5233                         monster_desc(m_name, m_ptr, 0);
5234 #ifdef JP
5235 msg_format("%^s¤òµ¯¤³¤·¤¿¡£", m_name);
5236 #else
5237                         msg_format("You have waked %s up.", m_name);
5238 #endif
5239                         if (p_ptr->health_who == p_ptr->riding) p_ptr->redraw |= (PR_HEALTH);
5240                         p_ptr->redraw |= (PR_UHEALTH);
5241                 }
5242
5243                 if (m_ptr->stunned)
5244                 {
5245                         int d = 1;
5246
5247                         /* Make a "saving throw" against stun */
5248                         if (randint0(r_info[m_ptr->r_idx].level) < p_ptr->skill_exp[GINOU_RIDING])
5249                         {
5250                                 /* Recover fully */
5251                                 d = m_ptr->stunned;
5252                         }
5253
5254                         /* Hack -- Recover from stun */
5255                         if (m_ptr->stunned > d)
5256                         {
5257                                 /* Recover somewhat */
5258                                 m_ptr->stunned -= d;
5259                         }
5260
5261                         /* Fully recover */
5262                         else
5263                         {
5264                                 char m_name[80];
5265
5266                                 /* Recover fully */
5267                                 m_ptr->stunned = 0;
5268
5269                                 /* Acquire the monster name */
5270                                 monster_desc(m_name, m_ptr, 0);
5271
5272                                 /* Dump a message */
5273 #ifdef JP
5274 msg_format("%^s¤òÛ¯Û°¾õÂÖ¤«¤éΩ¤Áľ¤é¤»¤¿¡£", m_name);
5275 #else
5276                                 msg_format("%^s is no longer stunned.", m_name);
5277 #endif
5278                                 if (p_ptr->health_who == p_ptr->riding) p_ptr->redraw |= (PR_HEALTH);
5279                                 p_ptr->redraw |= (PR_UHEALTH);
5280                         }
5281                 }
5282
5283                 if (m_ptr->confused)
5284                 {
5285                         int d = 1;
5286
5287                         /* Make a "saving throw" against stun */
5288                         if (randint0(r_info[m_ptr->r_idx].level) < p_ptr->skill_exp[GINOU_RIDING])
5289                         {
5290                                 /* Recover fully */
5291                                 d = m_ptr->confused;
5292                         }
5293
5294                         /* Hack -- Recover from stun */
5295                         if (m_ptr->confused > d)
5296                         {
5297                                 /* Recover somewhat */
5298                                 m_ptr->confused -= d;
5299                         }
5300
5301                         /* Fully recover */
5302                         else
5303                         {
5304                                 char m_name[80];
5305
5306                                 /* Recover fully */
5307                                 m_ptr->confused = 0;
5308
5309                                 /* Acquire the monster name */
5310                                 monster_desc(m_name, m_ptr, 0);
5311
5312                                 /* Dump a message */
5313 #ifdef JP
5314 msg_format("%^s¤òº®Íð¾õÂÖ¤«¤éΩ¤Áľ¤é¤»¤¿¡£", m_name);
5315 #else
5316                                 msg_format("%^s is no longer confused.", m_name);
5317 #endif
5318                                 if (p_ptr->health_who == p_ptr->riding) p_ptr->redraw |= (PR_HEALTH);
5319                                 p_ptr->redraw |= (PR_UHEALTH);
5320                         }
5321                 }
5322
5323                 if (m_ptr->monfear)
5324                 {
5325                         int d = 1;
5326
5327                         /* Make a "saving throw" against stun */
5328                         if (randint0(r_info[m_ptr->r_idx].level) < p_ptr->skill_exp[GINOU_RIDING])
5329                         {
5330                                 /* Recover fully */
5331                                 d = m_ptr->monfear;
5332                         }
5333
5334                         /* Hack -- Recover from stun */
5335                         if (m_ptr->monfear > d)
5336                         {
5337                                 /* Recover somewhat */
5338                                 m_ptr->monfear -= d;
5339                         }
5340
5341                         /* Fully recover */
5342                         else
5343                         {
5344                                 char m_name[80];
5345
5346                                 /* Recover fully */
5347                                 m_ptr->monfear = 0;
5348
5349                                 /* Acquire the monster name */
5350                                 monster_desc(m_name, m_ptr, 0);
5351
5352                                 /* Dump a message */
5353 #ifdef JP
5354 msg_format("%^s¤ò¶²Éݤ«¤éΩ¤Áľ¤é¤»¤¿¡£", m_name);
5355 #else
5356                                 msg_format("%^s is no longer fear.", m_name);
5357 #endif
5358                                 if (p_ptr->health_who == p_ptr->riding) p_ptr->redraw |= (PR_HEALTH);
5359                                 p_ptr->redraw |= (PR_UHEALTH);
5360                         }
5361                 }
5362
5363                 /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
5364                 handle_stuff();
5365         }
5366
5367         /* Handle the player song */
5368         if (!load) check_music();
5369
5370         load = FALSE;
5371
5372         /* Fast */
5373         if (p_ptr->lightspeed)
5374         {
5375                 (void)set_lightspeed(p_ptr->lightspeed - 1, TRUE);
5376         }
5377         if ((p_ptr->pclass == CLASS_FORCETRAINER) && (p_ptr->magic_num1[0]))
5378         {
5379                 if (p_ptr->magic_num1[0] < 40)
5380                 {
5381                         p_ptr->magic_num1[0] = 0;
5382                 }
5383                 else p_ptr->magic_num1[0] -= 40;
5384                 p_ptr->update |= (PU_BONUS);
5385         }
5386         if (p_ptr->action == ACTION_LEARN)
5387         {
5388                 int hoge = ((p_ptr->msp * 0x10000L) / 256L)+7680L;
5389                 if ((p_ptr->csp * 0x10000L + p_ptr->csp_frac) < hoge)
5390                 {
5391                         p_ptr->csp = 0;
5392                         p_ptr->csp_frac = 0;
5393                         set_action(ACTION_NONE);
5394                 }
5395                 else
5396                 {
5397                         p_ptr->csp -= (s16b)(hoge >> 16);
5398                         hoge &= 0xFFFFL;
5399                         if (p_ptr->csp_frac < hoge)
5400                         {
5401                                 p_ptr->csp_frac += 0x10000L - hoge;
5402                                 p_ptr->csp--;
5403                         }
5404                         else
5405                                 p_ptr->csp_frac -= hoge;
5406                 }
5407                 p_ptr->redraw |= PR_MANA;
5408         }
5409
5410         if (p_ptr->special_defense & KATA_MASK)
5411         {
5412                 if (p_ptr->special_defense & KATA_MUSOU)
5413                 {
5414                         if (p_ptr->csp < 3)
5415                         {
5416                                 set_action(ACTION_NONE);
5417                         }
5418                         else
5419                         {
5420                                 p_ptr->csp -= 2;
5421                                 p_ptr->redraw |= (PR_MANA);
5422                         }
5423                 }
5424         }
5425
5426         /*** Handle actual user input ***/
5427
5428         /* Repeat until out of energy */
5429         while (p_ptr->energy_need <= 0)
5430         {
5431                 p_ptr->window |= PW_PLAYER;
5432                 p_ptr->sutemi = FALSE;
5433                 p_ptr->counter = FALSE;
5434                 now_damaged = FALSE;
5435
5436                 /* Handle "p_ptr->notice" */
5437                 notice_stuff();
5438
5439                 /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
5440                 handle_stuff();
5441
5442                 /* Place the cursor on the player */
5443                 move_cursor_relative(py, px);
5444
5445                 /* Refresh (optional) */
5446                 if (fresh_before) Term_fresh();
5447
5448
5449                 /* Hack -- Pack Overflow */
5450                 if (inventory[INVEN_PACK].k_idx)
5451                 {
5452                         int item = INVEN_PACK;
5453
5454                         char o_name[MAX_NLEN];
5455
5456                         object_type *o_ptr;
5457
5458                         /* Access the slot to be dropped */
5459                         o_ptr = &inventory[item];
5460
5461                         /* Disturbing */
5462                         disturb(0, 0);
5463
5464                         /* Warning */
5465 #ifdef JP
5466 msg_print("¥¶¥Ã¥¯¤«¤é¥¢¥¤¥Æ¥à¤¬¤¢¤Õ¤ì¤¿¡ª");
5467 #else
5468                         msg_print("Your pack overflows!");
5469 #endif
5470
5471
5472                         /* Describe */
5473                         object_desc(o_name, o_ptr, TRUE, 3);
5474
5475                         /* Message */
5476 #ifdef JP
5477 msg_format("%s(%c)¤òÍî¤È¤·¤¿¡£", o_name, index_to_label(item));
5478 #else
5479                         msg_format("You drop %s (%c).", o_name, index_to_label(item));
5480 #endif
5481
5482
5483                         /* Drop it (carefully) near the player */
5484                         (void)drop_near(o_ptr, 0, py, px);
5485
5486                         /* Modify, Describe, Optimize */
5487                         inven_item_increase(item, -255);
5488                         inven_item_describe(item);
5489                         inven_item_optimize(item);
5490
5491                         /* Handle "p_ptr->notice" */
5492                         notice_stuff();
5493
5494                         /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
5495                         handle_stuff();
5496                 }
5497
5498
5499                 /* Hack -- cancel "lurking browse mode" */
5500                 if (!command_new) command_see = FALSE;
5501
5502
5503                 /* Assume free turn */
5504                 energy_use = 0;
5505
5506
5507                 if (p_ptr->inside_battle)
5508                 {
5509                         /* Place the cursor on the player */
5510                         move_cursor_relative(py, px);
5511
5512                         command_cmd = SPECIAL_KEY_BUILDING;
5513
5514                         /* Process the command */
5515                         process_command();
5516                 }
5517
5518                 /* Paralyzed or Knocked Out */
5519                 else if (p_ptr->paralyzed || (p_ptr->stun >= 100))
5520                 {
5521                         /* Take a turn */
5522                         energy_use = 100;
5523                 }
5524
5525                 /* Resting */
5526                 else if (p_ptr->action == ACTION_REST)
5527                 {
5528                         /* Timed rest */
5529                         if (resting > 0)
5530                         {
5531                                 /* Reduce rest count */
5532                                 resting--;
5533
5534                                 if (!resting) set_action(ACTION_NONE);
5535
5536                                 /* Redraw the state */
5537                                 p_ptr->redraw |= (PR_STATE);
5538                         }
5539
5540                         /* Take a turn */
5541                         energy_use = 100;
5542                 }
5543
5544                 /* Fishing */
5545                 else if (p_ptr->action == ACTION_FISH)
5546                 {
5547                         /* Take a turn */
5548                         energy_use = 100;
5549                 }
5550
5551                 /* Running */
5552                 else if (running)
5553                 {
5554                         /* Take a step */
5555                         run_step(0);
5556                 }
5557
5558                 /* Repeated command */
5559                 else if (command_rep)
5560                 {
5561                         /* Count this execution */
5562                         command_rep--;
5563
5564                         /* Redraw the state */
5565                         p_ptr->redraw |= (PR_STATE);
5566
5567                         /* Redraw stuff */
5568                         redraw_stuff();
5569
5570                         /* Hack -- Assume messages were seen */
5571                         msg_flag = FALSE;
5572
5573                         /* Clear the top line */
5574                         prt("", 0, 0);
5575
5576                         /* Process the command */
5577                         process_command();
5578                 }
5579
5580                 /* Normal command */
5581                 else
5582                 {
5583                         /* Place the cursor on the player */
5584                         move_cursor_relative(py, px);
5585
5586                         can_save = TRUE;
5587                         /* Get a command (normal) */
5588                         request_command(FALSE);
5589                         can_save = FALSE;
5590
5591                         /* Process the command */
5592                         process_command();
5593                 }
5594
5595
5596                 /*** Clean up ***/
5597
5598                 /* Significant */
5599                 if (energy_use)
5600                 {
5601                         /* Use some energy */
5602                         if (world_player || energy_use > 400)
5603                         {
5604                                 /* The Randomness is irrelevant */
5605                                 p_ptr->energy_need += energy_use * TURNS_PER_TICK / 10;
5606                         }
5607                         else
5608                         {
5609                                 /* There is some randomness of needed energy */
5610                                 p_ptr->energy_need += (s16b)((s32b)energy_use * ENERGY_NEED() / 100L);
5611                         }
5612
5613                         /* Hack -- constant hallucination */
5614                         if (p_ptr->image) p_ptr->redraw |= (PR_MAP);
5615
5616
5617                         /* Shimmer monsters if needed */
5618                         if (shimmer_monsters)
5619                         {
5620                                 /* Clear the flag */
5621                                 shimmer_monsters = FALSE;
5622
5623                                 /* Shimmer multi-hued monsters */
5624                                 for (i = 1; i < m_max; i++)
5625                                 {
5626                                         monster_type *m_ptr;
5627                                         monster_race *r_ptr;
5628
5629                                         /* Access monster */
5630                                         m_ptr = &m_list[i];
5631
5632                                         /* Skip dead monsters */
5633                                         if (!m_ptr->r_idx) continue;
5634
5635                                         /* Access the monster race */
5636                                         r_ptr = &r_info[m_ptr->r_idx];
5637
5638                                         /* Skip non-multi-hued monsters */
5639                                         if (!(r_ptr->flags1 & RF1_ATTR_MULTI)) continue;
5640
5641                                         /* Reset the flag */
5642                                         shimmer_monsters = TRUE;
5643
5644                                         /* Redraw regardless */
5645                                         lite_spot(m_ptr->fy, m_ptr->fx);
5646                                 }
5647                         }
5648
5649
5650                         /* Handle monster detection */
5651                         if (repair_monsters)
5652                         {
5653                                 /* Reset the flag */
5654                                 repair_monsters = FALSE;
5655
5656                                 /* Rotate detection flags */
5657                                 for (i = 1; i < m_max; i++)
5658                                 {
5659                                         monster_type *m_ptr;
5660
5661                                         /* Access monster */
5662                                         m_ptr = &m_list[i];
5663
5664                                         /* Skip dead monsters */
5665                                         if (!m_ptr->r_idx) continue;
5666
5667                                         /* Nice monsters get mean */
5668                                         if (m_ptr->mflag & MFLAG_NICE)
5669                                         {
5670                                                 /* Nice monsters get mean */
5671                                                 m_ptr->mflag &= ~(MFLAG_NICE);
5672                                         }
5673
5674                                         /* Handle memorized monsters */
5675                                         if (m_ptr->mflag & MFLAG_MARK)
5676                                         {
5677                                                 /* Maintain detection */
5678                                                 if (m_ptr->mflag & MFLAG_SHOW)
5679                                                 {
5680                                                         /* Forget flag */
5681                                                         m_ptr->mflag &= ~(MFLAG_SHOW);
5682
5683                                                         /* Still need repairs */
5684                                                         repair_monsters = TRUE;
5685                                                 }
5686
5687                                                 /* Remove detection */
5688                                                 else
5689                                                 {
5690                                                         /* Forget flag */
5691                                                         m_ptr->mflag &= ~(MFLAG_MARK);
5692
5693                                                         /* Assume invisible */
5694                                                         m_ptr->ml = FALSE;
5695
5696                                                         /* Update the monster */
5697                                                         update_mon(i, FALSE);
5698
5699                                                         if (p_ptr->health_who == i) p_ptr->redraw |= (PR_HEALTH);
5700                                                         if (p_ptr->riding == i) p_ptr->redraw |= (PR_UHEALTH);
5701
5702                                                         /* Redraw regardless */
5703                                                         lite_spot(m_ptr->fy, m_ptr->fx);
5704                                                 }
5705                                         }
5706                                 }
5707                         }
5708                         if (p_ptr->pclass == CLASS_IMITATOR)
5709                         {
5710                                 if (p_ptr->mane_num > (p_ptr->lev > 44 ? 3 : p_ptr->lev > 29 ? 2 : 1))
5711                                 {
5712                                         p_ptr->mane_num--;
5713                                         for (i = 0; i < p_ptr->mane_num; i++)
5714                                         {
5715                                                 p_ptr->mane_spell[i] = p_ptr->mane_spell[i+1];
5716                                                 p_ptr->mane_dam[i] = p_ptr->mane_dam[i+1];
5717                                         }
5718                                 }
5719                                 new_mane = FALSE;
5720                                 p_ptr->redraw |= (PR_MANE);
5721                         }
5722                         if (p_ptr->action == ACTION_LEARN)
5723                         {
5724                                 new_mane = FALSE;
5725                                 p_ptr->redraw |= (PR_STATE);
5726                         }
5727
5728                         if (world_player && (p_ptr->energy_need > - 1000))
5729                         {
5730                                 /* Redraw map */
5731                                 p_ptr->redraw |= (PR_MAP);
5732
5733                                 /* Update monsters */
5734                                 p_ptr->update |= (PU_MONSTERS);
5735
5736                                 /* Window stuff */
5737                                 p_ptr->window |= (PW_OVERHEAD | PW_DUNGEON);
5738
5739 #ifdef JP
5740                                 msg_print("¡Ö»þ¤ÏÆ°¤­¤À¤¹¡Ä¡×");
5741 #else
5742                                 msg_print("You feel time flowing around you once more.");
5743 #endif
5744                                 msg_print(NULL);
5745                                 world_player = FALSE;
5746                                 p_ptr->energy_need = ENERGY_NEED();
5747
5748                                 /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
5749                                 handle_stuff();
5750                         }
5751                 }
5752
5753                 /* Hack -- notice death */
5754                 if (!p_ptr->playing || p_ptr->is_dead)
5755                 {
5756                         world_player = FALSE;
5757                         break;
5758                 }
5759
5760                 /* Handle "leaving" */
5761                 if (p_ptr->leaving) break;
5762         }
5763
5764         /* Update scent trail */
5765         update_smell();
5766 }
5767
5768
5769 /*
5770  * Interact with the current dungeon level.
5771  *
5772  * This function will not exit until the level is completed,
5773  * the user dies, or the game is terminated.
5774  */
5775 static void dungeon(bool load_game)
5776 {
5777         int quest_num = 0;
5778
5779         /* Set the base level */
5780         base_level = dun_level;
5781
5782         /* Reset various flags */
5783         hack_mind = FALSE;
5784
5785         /* Not leaving */
5786         p_ptr->leaving = FALSE;
5787
5788         /* Reset the "command" vars */
5789         command_cmd = 0;
5790         command_new = 0;
5791         command_rep = 0;
5792         command_arg = 0;
5793         command_dir = 0;
5794
5795
5796         /* Cancel the target */
5797         target_who = 0;
5798         pet_t_m_idx = 0;
5799         riding_t_m_idx = 0;
5800         ambush_flag = FALSE;
5801
5802         /* Cancel the health bar */
5803         health_track(0);
5804
5805         /* Check visual effects */
5806         shimmer_monsters = TRUE;
5807         shimmer_objects = TRUE;
5808         repair_monsters = TRUE;
5809         repair_objects = TRUE;
5810
5811
5812         /* Disturb */
5813         disturb(1, 0);
5814
5815         /* Get index of current quest (if any) */
5816         quest_num = quest_number(dun_level);
5817
5818         /* Inside a quest? */
5819         if (quest_num)
5820         {
5821                 /* Mark the quest monster */
5822                 r_info[quest[quest_num].r_idx].flags1 |= RF1_QUESTOR;
5823         }
5824
5825         /* Track maximum player level */
5826         if (p_ptr->max_plv < p_ptr->lev)
5827         {
5828                 p_ptr->max_plv = p_ptr->lev;
5829         }
5830
5831
5832         /* Track maximum dungeon level (if not in quest -KMW-) */
5833         if ((max_dlv[dungeon_type] < dun_level) && !p_ptr->inside_quest)
5834         {
5835                 max_dlv[dungeon_type] = dun_level;
5836                 if (record_maxdeapth) do_cmd_write_nikki(NIKKI_MAXDEAPTH, dun_level, NULL);
5837         }
5838
5839         /* Validate the panel */
5840         panel_bounds_center();
5841
5842         /* Verify the panel */
5843         verify_panel();
5844
5845         /* Flush messages */
5846         msg_print(NULL);
5847
5848
5849         /* Enter "xtra" mode */
5850         character_xtra = TRUE;
5851
5852         /* Window stuff */
5853         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_SPELL | PW_PLAYER | PW_MONSTER | PW_OVERHEAD | PW_DUNGEON);
5854
5855         /* Redraw dungeon */
5856         p_ptr->redraw |= (PR_WIPE | PR_BASIC | PR_EXTRA | PR_EQUIPPY);
5857
5858         /* Redraw map */
5859         p_ptr->redraw |= (PR_MAP);
5860
5861         /* Update stuff */
5862         p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
5863
5864         /* Update lite/view */
5865         p_ptr->update |= (PU_VIEW | PU_LITE | PU_MON_LITE | PU_TORCH);
5866
5867         /* Update monsters */
5868         p_ptr->update |= (PU_MONSTERS | PU_DISTANCE | PU_FLOW);
5869
5870         /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
5871         handle_stuff();
5872
5873         /* Leave "xtra" mode */
5874         character_xtra = FALSE;
5875
5876         /* Update stuff */
5877         p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
5878
5879         /* Combine / Reorder the pack */
5880         p_ptr->notice |= (PN_COMBINE | PN_REORDER);
5881
5882         /* Handle "p_ptr->notice" */
5883         notice_stuff();
5884
5885         /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
5886         handle_stuff();
5887
5888         /* Refresh */
5889         Term_fresh();
5890
5891         if (quest_number(dun_level) && ((quest_number(dun_level) < MIN_RANDOM_QUEST) && !(quest_number(dun_level) == QUEST_OBERON || quest_number(dun_level) == QUEST_SERPENT || !(quest[quest_number(dun_level)].flags & QUEST_FLAG_PRESET)))) do_cmd_feeling();
5892
5893         if (p_ptr->inside_battle)
5894         {
5895                 if (load_game)
5896                 {
5897                         p_ptr->energy_need = 0;
5898                         battle_monsters();
5899                 }
5900                 else
5901                 {
5902                         
5903 #ifdef JP
5904 msg_print("»î¹ç³«»Ï¡ª");
5905 #else
5906                         msg_format("Ready..Fight!");
5907 #endif
5908                         msg_print(NULL);
5909                 }
5910         }
5911
5912         if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] > MUSIC_DETECT))
5913                 p_ptr->magic_num1[0] = MUSIC_DETECT;
5914
5915         /* Hack -- notice death or departure */
5916         if (!p_ptr->playing || p_ptr->is_dead) return;
5917
5918         /* Print quest message if appropriate */
5919         if (!p_ptr->inside_quest && (dungeon_type == DUNGEON_ANGBAND))
5920         {
5921                 quest_discovery(random_quest_number(dun_level));
5922                 p_ptr->inside_quest = random_quest_number(dun_level);
5923         }
5924         if ((dun_level == d_info[dungeon_type].maxdepth) && d_info[dungeon_type].final_guardian)
5925         {
5926                 if (r_info[d_info[dungeon_type].final_guardian].max_num)
5927 #ifdef JP
5928                         msg_format("¤³¤Î³¬¤Ë¤Ï%s¤Î¼ç¤Ç¤¢¤ë%s¤¬À³¤ó¤Ç¤¤¤ë¡£",
5929                                    d_name+d_info[dungeon_type].name, 
5930                                    r_name+r_info[d_info[dungeon_type].final_guardian].name);
5931 #else
5932                 msg_format("%^s lives in this level as the keeper of %s.",
5933                                    r_name+r_info[d_info[dungeon_type].final_guardian].name, 
5934                                    d_name+d_info[dungeon_type].name);
5935 #endif
5936         }
5937
5938         /*** Process this dungeon level ***/
5939
5940         /* Reset the monster generation level */
5941         monster_level = base_level;
5942
5943         /* Reset the object generation level */
5944         object_level = base_level;
5945
5946         hack_mind = TRUE;
5947
5948         if (p_ptr->energy_need > 0 && !p_ptr->inside_battle &&
5949             (dun_level || p_ptr->leaving_dungeon || p_ptr->inside_arena))
5950                 p_ptr->energy_need = 0;
5951
5952         /* Not leaving dungeon */
5953         p_ptr->leaving_dungeon = FALSE;
5954
5955         /* Main loop */
5956         while (TRUE)
5957         {
5958                 /* Hack -- Compact the monster list occasionally */
5959                 if ((m_cnt + 32 > max_m_idx) && !p_ptr->inside_battle) compact_monsters(64);
5960
5961                 /* Hack -- Compress the monster list occasionally */
5962                 if ((m_cnt + 32 < m_max) && !p_ptr->inside_battle) compact_monsters(0);
5963
5964
5965                 /* Hack -- Compact the object list occasionally */
5966                 if (o_cnt + 32 > max_o_idx) compact_objects(64);
5967
5968                 /* Hack -- Compress the object list occasionally */
5969                 if (o_cnt + 32 < o_max) compact_objects(0);
5970
5971
5972                 /* Process the player */
5973                 process_player();
5974
5975                 /* Handle "p_ptr->notice" */
5976                 notice_stuff();
5977
5978                 /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
5979                 handle_stuff();
5980
5981                 /* Hack -- Hilite the player */
5982                 move_cursor_relative(py, px);
5983
5984                 /* Optional fresh */
5985                 if (fresh_after) Term_fresh();
5986
5987                 /* Hack -- Notice death or departure */
5988                 if (!p_ptr->playing || p_ptr->is_dead) break;
5989
5990                 /* Process all of the monsters */
5991                 process_monsters();
5992
5993                 /* Handle "p_ptr->notice" */
5994                 notice_stuff();
5995
5996                 /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
5997                 handle_stuff();
5998
5999                 /* Hack -- Hilite the player */
6000                 move_cursor_relative(py, px);
6001
6002                 /* Optional fresh */
6003                 if (fresh_after) Term_fresh();
6004
6005                 /* Hack -- Notice death or departure */
6006                 if (!p_ptr->playing || p_ptr->is_dead) break;
6007
6008
6009                 /* Process the world */
6010                 process_world();
6011
6012                 /* Handle "p_ptr->notice" */
6013                 notice_stuff();
6014
6015                 /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
6016                 handle_stuff();
6017
6018                 /* Hack -- Hilite the player */
6019                 move_cursor_relative(py, px);
6020
6021                 /* Optional fresh */
6022                 if (fresh_after) Term_fresh();
6023
6024                 /* Hack -- Notice death or departure */
6025                 if (!p_ptr->playing || p_ptr->is_dead) break;
6026
6027                 /* Handle "leaving" */
6028                 if (p_ptr->leaving) break;
6029
6030                 /* Count game turns */
6031                 turn++;
6032                 if (!p_ptr->wild_mode || wild_regen) dungeon_turn++;
6033                 else if (p_ptr->wild_mode && !(turn % ((MAX_HGT + MAX_WID) / 2))) dungeon_turn++;
6034                 if (wild_regen) wild_regen--;
6035         }
6036
6037         /* Inside a quest and non-unique questor? */
6038         if (quest_num && !(r_info[quest[quest_num].r_idx].flags1 & RF1_UNIQUE))
6039         {
6040                 /* Un-mark the quest monster */
6041                 r_info[quest[quest_num].r_idx].flags1 &= ~RF1_QUESTOR;
6042         }
6043
6044         /* Not save-and-quit and not dead? */
6045         if (p_ptr->playing && !p_ptr->is_dead)
6046         {
6047                 /*
6048                  * Maintain Unique monsters and artifact, save current
6049                  * floor, then prepare next floor
6050                  */
6051                 leave_floor();
6052
6053                 /* Forget the flag */
6054                 reinit_wilderness = FALSE;
6055         }
6056
6057         /* Write about current level on the play record once per level */
6058         write_level = TRUE;
6059 }
6060
6061
6062 /*
6063  * Load some "user pref files"
6064  *
6065  * Modified by Arcum Dagsson to support
6066  * separate macro files for different realms.
6067  */
6068 static void load_all_pref_files(void)
6069 {
6070         char buf[1024];
6071         errr err;
6072
6073         /* Access the "user" pref file */
6074         sprintf(buf, "user.prf");
6075
6076         /* Process that file */
6077         process_pref_file(buf);
6078
6079         /* Access the "user" system pref file */
6080         sprintf(buf, "user-%s.prf", ANGBAND_SYS);
6081
6082         /* Process that file */
6083         process_pref_file(buf);
6084
6085         /* Access the "race" pref file */
6086         sprintf(buf, "%s.prf", rp_ptr->title);
6087
6088         /* Process that file */
6089         process_pref_file(buf);
6090
6091         /* Access the "class" pref file */
6092         sprintf(buf, "%s.prf", cp_ptr->title);
6093
6094         /* Process that file */
6095         process_pref_file(buf);
6096
6097         /* Access the "character" pref file */
6098         sprintf(buf, "%s.prf", player_base);
6099
6100         /* Process that file */
6101         process_pref_file(buf);
6102
6103         /* Free old entries */
6104         init_autopicker();
6105
6106 #ifdef JP
6107         sprintf(buf, "picktype-%s.prf", player_base);
6108 #else
6109         sprintf(buf, "pickpref-%s.prf", player_base);
6110 #endif
6111
6112         err = process_pickpref_file(buf);
6113
6114         /* Process 'pick????.prf' if 'pick????-<name>.prf' doesn't exist */
6115         if (0 > err)
6116         {
6117 #ifdef JP
6118                 process_pickpref_file("picktype.prf");
6119 #else
6120                 process_pickpref_file("pickpref.prf");
6121 #endif
6122         }
6123
6124         /* Access the "realm 1" pref file */
6125         if (p_ptr->realm1 != REALM_NONE)
6126         {
6127                 sprintf(buf, "%s.prf", realm_names[p_ptr->realm1]);
6128
6129                 /* Process that file */
6130                 process_pref_file(buf);
6131         }
6132
6133         /* Access the "realm 2" pref file */
6134         if (p_ptr->realm2 != REALM_NONE)
6135         {
6136                 sprintf(buf, "%s.prf", realm_names[p_ptr->realm2]);
6137
6138                 /* Process that file */
6139                 process_pref_file(buf);
6140         }
6141 }
6142
6143
6144 /*
6145  * Actually play a game
6146  *
6147  * If the "new_game" parameter is true, then, after loading the
6148  * savefile, we will commit suicide, if necessary, to allow the
6149  * player to start a new game.
6150  */
6151 void play_game(bool new_game)
6152 {
6153         int i;
6154         bool load_game = TRUE;
6155
6156 #ifdef CHUUKEI
6157         if(chuukei_client){
6158           reset_visuals();
6159           browse_chuukei();
6160           return;
6161         }
6162 #endif
6163
6164         hack_mutation = FALSE;
6165
6166         /* Hack -- Character is "icky" */
6167         character_icky = TRUE;
6168
6169         /* Make sure main term is active */
6170         Term_activate(angband_term[0]);
6171
6172         /* Initialise the resize hooks */
6173         angband_term[0]->resize_hook = resize_map;
6174         
6175         for (i = 1; i < 8; i++)
6176         {
6177                 /* Does the term exist? */
6178                 if (angband_term[i])
6179                 {
6180                         /* Add the redraw on resize hook */
6181                         angband_term[i]->resize_hook = redraw_window;
6182                 }
6183         }
6184
6185         /* Hack -- turn off the cursor */
6186         (void)Term_set_cursor(0);
6187
6188
6189         /* Attempt to load */
6190         if (!load_player())
6191         {
6192                 /* Oops */
6193 #ifdef JP
6194 quit("¥»¡¼¥Ö¥Õ¥¡¥¤¥ë¤¬²õ¤ì¤Æ¤¤¤Þ¤¹");
6195 #else
6196                 quit("broken savefile");
6197 #endif
6198
6199         }
6200
6201         /* Extract the options */
6202         for (i = 0; option_info[i].o_desc; i++)
6203         {
6204                 int os = option_info[i].o_set;
6205                 int ob = option_info[i].o_bit;
6206
6207                 /* Set the "default" options */
6208                 if (option_info[i].o_var)
6209                 {
6210                         /* Set */
6211                         if (option_flag[os] & (1L << ob))
6212                         {
6213                                 /* Set */
6214                                 (*option_info[i].o_var) = TRUE;
6215                         }
6216
6217                         /* Clear */
6218                         else
6219                         {
6220                                 /* Clear */
6221                                 (*option_info[i].o_var) = FALSE;
6222                         }
6223                 }
6224         }
6225
6226         /* Report waited score */
6227         if (p_ptr->wait_report_score)
6228         {
6229                 char buf[1024];
6230                 bool success;
6231
6232 #ifdef JP
6233                 if (!get_check_strict("ÂÔµ¡¤·¤Æ¤¤¤¿¥¹¥³¥¢ÅÐÏ¿¤òº£¹Ô¤Ê¤¤¤Þ¤¹¤«¡©", CHECK_NO_HISTORY))
6234 #else
6235                 if (!get_check_strict("Do you register score now? ", CHECK_NO_HISTORY))
6236 #endif
6237                         quit(0);
6238
6239                 /* Update stuff */
6240                 p_ptr->update |= (PU_BONUS | PU_HP | PU_MANA | PU_SPELLS);
6241
6242                 /* Update stuff */
6243                 update_stuff();
6244
6245                 p_ptr->is_dead = TRUE;
6246
6247                 start_time = time(NULL);
6248
6249                 /* No suspending now */
6250                 signals_ignore_tstp();
6251                 
6252                 /* Hack -- Character is now "icky" */
6253                 character_icky = TRUE;
6254
6255                 /* Build the filename */
6256                 path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw");
6257
6258                 /* Open the high score file, for reading/writing */
6259                 highscore_fd = fd_open(buf, O_RDWR);
6260
6261                 /* Handle score, show Top scores */
6262                 success = send_world_score(TRUE);
6263
6264 #ifdef JP
6265                 if (!success && !get_check_strict("¥¹¥³¥¢ÅÐÏ¿¤òÄü¤á¤Þ¤¹¤«¡©", CHECK_NO_HISTORY))
6266 #else
6267                 if (!success && !get_check_strict("Do you give up score registration? ", CHECK_NO_HISTORY))
6268 #endif
6269                 {
6270 #ifdef JP
6271                         prt("°ú¤­Â³¤­ÂÔµ¡¤·¤Þ¤¹¡£", 0, 0);
6272 #else
6273                         prt("standing by for future registration...", 0, 0);
6274 #endif
6275                         (void)inkey();
6276                 }
6277                 else
6278                 {
6279                         p_ptr->wait_report_score = FALSE;
6280                         top_twenty();
6281 #ifdef JP
6282                         if (!save_player()) msg_print("¥»¡¼¥Ö¼ºÇÔ¡ª");
6283 #else
6284                         if (!save_player()) msg_print("death save failed!");
6285 #endif
6286                 }
6287                 /* Shut the high score file */
6288                 (void)fd_close(highscore_fd);
6289
6290                 /* Forget the high score fd */
6291                 highscore_fd = -1;
6292                 
6293                 /* Allow suspending now */
6294                 signals_handle_tstp();
6295
6296                 quit(0);
6297         }
6298
6299         /* Nothing loaded */
6300         if (!character_loaded)
6301         {
6302                 /* Make new player */
6303                 new_game = TRUE;
6304
6305                 /* The dungeon is not ready */
6306                 character_dungeon = FALSE;
6307
6308                 /* Prepare to init the RNG */
6309                 Rand_quick = TRUE;
6310
6311                 /* Initialize the saved floors data */
6312                 init_saved_floors();
6313         }
6314
6315         /* Old game is loaded.  But new game is requested. */
6316         else if (new_game)
6317         {
6318                 /* Delete expanded temporal files */
6319                 clear_saved_floor_files();
6320         }
6321
6322         /* Process old character */
6323         if (!new_game)
6324         {
6325                 /* Process the player name */
6326                 process_player_name(FALSE);
6327         }
6328
6329         /* Init the RNG */
6330         if (Rand_quick)
6331         {
6332                 u32b seed;
6333
6334                 /* Basic seed */
6335                 seed = (time(NULL));
6336
6337 #ifdef SET_UID
6338
6339                 /* Mutate the seed on Unix machines */
6340                 seed = ((seed >> 3) * (getpid() << 1));
6341
6342 #endif
6343
6344                 /* Use the complex RNG */
6345                 Rand_quick = FALSE;
6346
6347                 /* Seed the "complex" RNG */
6348                 Rand_state_init(seed);
6349         }
6350
6351         /* Roll new character */
6352         if (new_game)
6353         {
6354                 monster_race *r_ptr;
6355
6356                 /* The dungeon is not ready */
6357                 character_dungeon = FALSE;
6358
6359                 /* Start in town */
6360                 dun_level = 0;
6361                 p_ptr->inside_quest = 0;
6362                 p_ptr->inside_arena = FALSE;
6363                 p_ptr->inside_battle = FALSE;
6364
6365                 write_level = TRUE;
6366
6367                 /* Hack -- seed for flavors */
6368                 seed_flavor = randint0(0x10000000);
6369
6370                 /* Hack -- seed for town layout */
6371                 seed_town = randint0(0x10000000);
6372
6373                 /* Roll up a new character */
6374                 player_birth();
6375
6376                 counts_write(2,0);
6377                 p_ptr->count = 0;
6378
6379 #ifdef JP
6380                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "ÊÕ¶­¤ÎÃϤ˹ߤêΩ¤Ã¤¿¡£");
6381 #else
6382                 do_cmd_write_nikki(NIKKI_BUNSHOU, 0, "You are standing in the Outpost.");
6383 #endif
6384
6385                 load = FALSE;
6386                 get_mon_num_prep(NULL, NULL);
6387                 for (i = 0; i < MAX_KUBI; i++)
6388                 {
6389                         while (1)
6390                         {
6391                                 int j;
6392
6393                                 kubi_r_idx[i] = get_mon_num(MAX_DEPTH - 1);
6394                                 r_ptr = &r_info[kubi_r_idx[i]];
6395
6396                                 if(!(r_ptr->flags1 & RF1_UNIQUE)) continue;
6397
6398                                 if(!(r_ptr->flags9 & RF9_DROP_CORPSE)) continue;
6399                                 if (r_ptr->rarity > 100) continue;
6400
6401                                 if(r_ptr->flags6 & RF6_SPECIAL) continue;
6402
6403                                 for (j = 0; j < i; j++)
6404                                         if (kubi_r_idx[i] == kubi_r_idx[j])break;
6405
6406                                 if (j == i) break;
6407                         }
6408                 }
6409                 for (i = 0; i < MAX_KUBI -1; i++)
6410                 {
6411                         int j,tmp;
6412                         for (j = i; j < MAX_KUBI; j++)
6413                         {
6414                                 if (r_info[kubi_r_idx[i]].level > r_info[kubi_r_idx[j]].level)
6415                                 {
6416                                         tmp = kubi_r_idx[i];
6417                                         kubi_r_idx[i] = kubi_r_idx[j];
6418                                         kubi_r_idx[j] = tmp;
6419                                 }
6420                         }
6421                 }
6422
6423                 p_ptr->inside_battle = TRUE;
6424                 while (1)
6425                 {
6426                         today_mon = get_mon_num(3);
6427                         r_ptr = &r_info[today_mon];
6428
6429                         if (r_ptr->flags1 & RF1_UNIQUE) continue;
6430                         if (r_ptr->flags2 & (RF2_MULTIPLY)) continue;
6431                         if (!(r_ptr->flags9 & RF9_DROP_CORPSE) || !(r_ptr->flags9 & RF9_DROP_SKELETON)) continue;
6432                         if (r_ptr->rarity > 10) continue;
6433                         if (r_ptr->level == 0) continue;
6434                         break;
6435                 }
6436                 p_ptr->inside_battle = FALSE;
6437         }
6438         else
6439         {
6440                 write_level = FALSE;
6441
6442 #ifdef JP
6443                 do_cmd_write_nikki(NIKKI_GAMESTART, 1, "                            ----¥²¡¼¥àºÆ³«----");
6444 #else
6445                 do_cmd_write_nikki(NIKKI_GAMESTART, 1, "                            ---- Restart Game ----");
6446 #endif
6447
6448 /*
6449  * 1.0.9 °ÊÁ°¤Ï¥»¡¼¥ÖÁ°¤Ë p_ptr->riding = -1 ¤È¤·¤Æ¤¤¤¿¤Î¤Ç¡¢ºÆÀßÄ꤬ɬÍפÀ¤Ã¤¿¡£
6450  * ¤â¤¦ÉÔÍפÀ¤¬¡¢°ÊÁ°¤Î¥»¡¼¥Ö¥Õ¥¡¥¤¥ë¤È¤Î¸ß´¹¤Î¤¿¤á¤Ë»Ä¤·¤Æ¤ª¤¯¡£
6451  */
6452                 if (p_ptr->riding == -1)
6453                 {
6454                         p_ptr->riding = 0;
6455                         for(i = m_max; i > 0; i--)
6456                         {
6457                                 if ((m_list[i].fy == py) && (m_list[i].fx == px))
6458                                 {
6459                                         p_ptr->riding = i;
6460                                         break;
6461                                 }
6462                         }
6463                 }
6464         }
6465
6466         p_ptr->teleport_town = FALSE;
6467         p_ptr->sutemi = FALSE;
6468         world_monster = FALSE;
6469         now_damaged = FALSE;
6470         now_message = 0;
6471         start_time = time(NULL) - 1;
6472         record_o_name[0] = '\0';
6473
6474         /* Reset map panel */
6475         panel_row_min = cur_hgt;
6476         panel_col_min = cur_wid;
6477
6478         /* Sexy gal gets bonus to maximum weapon skill of whip */
6479         if (p_ptr->pseikaku == SEIKAKU_SEXY)
6480                 s_info[p_ptr->pclass].w_max[TV_HAFTED-TV_BOW][SV_WHIP] = WEAPON_EXP_MASTER;
6481
6482         /* Fill the arrays of floors and walls in the good proportions */
6483         set_floor_and_wall(dungeon_type);
6484
6485         /* Flavor the objects */
6486         flavor_init();
6487         if (new_game)
6488         {
6489                 wipe_o_list();
6490                 player_outfit();
6491         }
6492
6493         /* Flash a message */
6494 #ifdef JP
6495 prt("¤ªÂÔ¤Á²¼¤µ¤¤...", 0, 0);
6496 #else
6497         prt("Please wait...", 0, 0);
6498 #endif
6499
6500
6501         /* Flush the message */
6502         Term_fresh();
6503
6504
6505         /* Hack -- Enter wizard mode */
6506         if (arg_wizard)
6507         {
6508                 if (enter_wizard_mode()) p_ptr->wizard = TRUE;
6509                 else if (p_ptr->is_dead) quit("Already dead.");
6510         }
6511
6512         /* Initialize the town-buildings if necessary */
6513         if (!dun_level && !p_ptr->inside_quest)
6514         {
6515                 /* Init the wilderness */
6516
6517                 process_dungeon_file("w_info.txt", 0, 0, max_wild_y, max_wild_x);
6518
6519                 /* Init the town */
6520                 init_flags = INIT_ONLY_BUILDINGS;
6521
6522                 process_dungeon_file("t_info.txt", 0, 0, MAX_HGT, MAX_WID);
6523
6524         }
6525
6526
6527         /* Initialize vault info */
6528 #ifdef JP
6529 if (init_v_info()) quit("·úÃÛʪ½é´ü²½ÉÔǽ");
6530 #else
6531         if (init_v_info()) quit("Cannot initialize vaults");
6532 #endif
6533
6534         /* Generate a dungeon level if needed */
6535         if (!character_dungeon) change_floor();
6536
6537
6538         /* Character is now "complete" */
6539         character_generated = TRUE;
6540
6541
6542         /* Hack -- Character is no longer "icky" */
6543         character_icky = FALSE;
6544
6545
6546         /* Start game */
6547         p_ptr->playing = TRUE;
6548
6549         /* Reset the visual mappings */
6550         reset_visuals();
6551
6552         /* Load the "pref" files */
6553         load_all_pref_files();
6554
6555         /* React to changes */
6556         Term_xtra(TERM_XTRA_REACT, 0);
6557
6558         /* Window stuff */
6559         p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_SPELL | PW_PLAYER);
6560
6561         /* Window stuff */
6562         p_ptr->window |= (PW_MESSAGE | PW_OVERHEAD | PW_DUNGEON | PW_MONSTER | PW_OBJECT);
6563
6564         /* Window stuff */
6565         window_stuff();
6566
6567
6568         /* Set or clear "rogue_like_commands" if requested */
6569         if (arg_force_original) rogue_like_commands = FALSE;
6570         if (arg_force_roguelike) rogue_like_commands = TRUE;
6571
6572         /* Hack -- Enforce "delayed death" */
6573         if (p_ptr->chp < 0) p_ptr->is_dead = TRUE;
6574
6575         if (p_ptr->prace == RACE_ANDROID) calc_android_exp();
6576
6577         if (new_game && ((p_ptr->pclass == CLASS_CAVALRY) || (p_ptr->pclass == CLASS_BEASTMASTER)))
6578         {
6579                 monster_type *m_ptr;
6580                 int pet_r_idx = ((p_ptr->pclass == CLASS_CAVALRY) ? MON_HORSE : MON_YASE_HORSE);
6581                 monster_race *r_ptr = &r_info[pet_r_idx];
6582                 place_monster_aux(0, py, px - 1, pet_r_idx,
6583                                   (PM_FORCE_PET | PM_NO_KAGE));
6584                 m_ptr = &m_list[hack_m_idx_ii];
6585                 m_ptr->mspeed = r_ptr->speed;
6586                 m_ptr->maxhp = r_ptr->hdice*(r_ptr->hside+1)/2;
6587                 m_ptr->max_maxhp = m_ptr->maxhp;
6588                 m_ptr->hp = r_ptr->hdice*(r_ptr->hside+1)/2;
6589                 m_ptr->energy_need = ENERGY_NEED() + ENERGY_NEED();
6590         }
6591
6592         /* Process */
6593         while (TRUE)
6594         {
6595                 /* Process the level */
6596                 dungeon(load_game);
6597
6598                 /* Handle "p_ptr->notice" */
6599                 notice_stuff();
6600
6601                 /* Handle "p_ptr->update" and "p_ptr->redraw" and "p_ptr->window" */
6602                 handle_stuff();
6603
6604                 /* Cancel the target */
6605                 target_who = 0;
6606
6607                 /* Cancel the health bar */
6608                 health_track(0);
6609
6610
6611                 /* Forget the lite */
6612                 forget_lite();
6613
6614                 /* Forget the view */
6615                 forget_view();
6616
6617                 /* Forget the view */
6618                 clear_mon_lite();
6619
6620                 /* Handle "quit and save" */
6621                 if (!p_ptr->playing && !p_ptr->is_dead) break;
6622
6623                 /* Erase the old cave */
6624                 wipe_o_list();
6625                 if (!p_ptr->is_dead) wipe_m_list();
6626
6627
6628                 /* XXX XXX XXX */
6629                 msg_print(NULL);
6630
6631                 load_game = FALSE;
6632
6633                 /* Accidental Death */
6634                 if (p_ptr->playing && p_ptr->is_dead)
6635                 {
6636                         if (p_ptr->inside_arena)
6637                         {
6638                                 p_ptr->inside_arena = FALSE;
6639                                 if(p_ptr->arena_number > MAX_ARENA_MONS)
6640                                         p_ptr->arena_number++;
6641                                 else
6642                                         p_ptr->arena_number = 99;
6643                                 p_ptr->is_dead = FALSE;
6644                                 p_ptr->chp = 0;
6645                                 p_ptr->chp_frac = 0;
6646                                 p_ptr->exit_bldg = TRUE;
6647                                 reset_tim_flags();
6648                         }
6649                         else
6650                         {
6651                                 /* Mega-Hack -- Allow player to cheat death */
6652 #ifdef JP
6653 if ((p_ptr->wizard || cheat_live) && !get_check("»à¤Ë¤Þ¤¹¤«? "))
6654 #else
6655                                 if ((p_ptr->wizard || cheat_live) && !get_check("Die? "))
6656 #endif
6657
6658                                 {
6659                                         /* Mark social class, reset age, if needed */
6660                                         if (p_ptr->sc) p_ptr->sc = p_ptr->age = 0;
6661
6662                                         /* Increase age */
6663                                         p_ptr->age++;
6664
6665                                         /* Mark savefile */
6666                                         p_ptr->noscore |= 0x0001;
6667
6668                                         /* Message */
6669 #ifdef JP
6670 msg_print("¥¦¥£¥¶¡¼¥É¥â¡¼¥É¤ËÇ°¤òÁ÷¤ê¡¢»à¤òµ½¤¤¤¿¡£");
6671 #else
6672                                         msg_print("You invoke wizard mode and cheat death.");
6673 #endif
6674                                         wipe_m_list();
6675
6676                                         msg_print(NULL);
6677
6678                                         /* Restore hit points */
6679                                         p_ptr->chp = p_ptr->mhp;
6680                                         p_ptr->chp_frac = 0;
6681
6682                                         if (p_ptr->pclass == CLASS_MAGIC_EATER)
6683                                         {
6684                                                 for (i = 0; i < EATER_EXT*2; i++)
6685                                                 {
6686                                                         p_ptr->magic_num1[i] = p_ptr->magic_num2[i]*EATER_CHARGE;
6687                                                 }
6688                                                 for (; i < EATER_EXT*3; i++)
6689                                                 {
6690                                                         p_ptr->magic_num1[i] = 0;
6691                                                 }
6692                                         }
6693                                         /* Restore spell points */
6694                                         p_ptr->csp = p_ptr->msp;
6695                                         p_ptr->csp_frac = 0;
6696
6697                                         /* Hack -- Healing */
6698                                         (void)set_blind(0);
6699                                         (void)set_confused(0);
6700                                         (void)set_poisoned(0);
6701                                         (void)set_afraid(0);
6702                                         (void)set_paralyzed(0);
6703                                         (void)set_image(0);
6704                                         (void)set_stun(0);
6705                                         (void)set_cut(0);
6706
6707                                         /* Hack -- Prevent starvation */
6708                                         (void)set_food(PY_FOOD_MAX - 1);
6709
6710                                         /* Hack -- cancel recall */
6711                                         if (p_ptr->word_recall)
6712                                         {
6713                                                 /* Message */
6714 #ifdef JP
6715 msg_print("Ä¥¤ê¤Ä¤á¤¿Â絤¤¬Î®¤ìµî¤Ã¤¿...");
6716 #else
6717                                                 msg_print("A tension leaves the air around you...");
6718 #endif
6719
6720                                                 msg_print(NULL);
6721
6722                                                 /* Hack -- Prevent recall */
6723                                                 p_ptr->word_recall = 0;
6724                                                 p_ptr->redraw |= (PR_STATUS);
6725                                         }
6726
6727                                         /* Hack -- cancel alter */
6728                                         if (p_ptr->alter_reality)
6729                                         {
6730                                                 /* Hack -- Prevent alter */
6731                                                 p_ptr->alter_reality = 0;
6732                                                 p_ptr->redraw |= (PR_STATUS);
6733                                         }
6734
6735                                         /* Note cause of death XXX XXX XXX */
6736 #ifdef JP
6737 (void)strcpy(p_ptr->died_from, "»à¤Îµ½¤­");
6738 #else
6739                                         (void)strcpy(p_ptr->died_from, "Cheating death");
6740 #endif
6741
6742
6743                                         /* Do not die */
6744                                         p_ptr->is_dead = FALSE;
6745
6746                                         dun_level = 0;
6747                                         p_ptr->inside_arena = FALSE;
6748                                         p_ptr->inside_battle = FALSE;
6749                                         leaving_quest = 0;
6750                                         p_ptr->inside_quest = 0;
6751                                         p_ptr->recall_dungeon = dungeon_type;
6752                                         dungeon_type = 0;
6753                                         if (lite_town || vanilla_town)
6754                                         {
6755                                                 p_ptr->wilderness_y = 1;
6756                                                 p_ptr->wilderness_x = 1;
6757                                                 if (vanilla_town)
6758                                                 {
6759                                                         p_ptr->oldpy = 10;
6760                                                         p_ptr->oldpx = 34;
6761                                                 }
6762                                                 else
6763                                                 {
6764                                                         p_ptr->oldpy = 33;
6765                                                         p_ptr->oldpx = 131;
6766                                                 }
6767                                         }
6768                                         else
6769                                         {
6770                                                 p_ptr->wilderness_y = 48;
6771                                                 p_ptr->wilderness_x = 5;
6772                                                 p_ptr->oldpy = 33;
6773                                                 p_ptr->oldpx = 131;
6774                                         }
6775
6776                                         /* Leaving */
6777                                         p_ptr->wild_mode = FALSE;
6778                                         p_ptr->leaving = TRUE;
6779
6780 #ifdef JP
6781                                         do_cmd_write_nikki(NIKKI_BUNSHOU, 1, "                            ¤·¤«¤·¡¢À¸¤­Ê֤ä¿¡£");
6782 #else
6783                                         do_cmd_write_nikki(NIKKI_BUNSHOU, 1, "                            but revived.");
6784 #endif
6785                                 }
6786                         }
6787                 }
6788
6789                 /* Handle "death" */
6790                 if (p_ptr->is_dead) break;
6791
6792                 /* Make a new level */
6793                 change_floor();
6794         }
6795
6796         /* Close stuff */
6797         close_game();
6798
6799         /* Quit */
6800         quit(NULL);
6801 }
6802
6803 s32b turn_real(s32b hoge)
6804 {
6805         switch (p_ptr->start_race)
6806         {
6807         case RACE_VAMPIRE:
6808         case RACE_SKELETON:
6809         case RACE_ZOMBIE:
6810         case RACE_SPECTRE:
6811                 return hoge - (TURNS_PER_TICK * TOWN_DAWN * 3 / 4);
6812         default:
6813                 return hoge;
6814         }
6815 }