OSDN Git Service

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