OSDN Git Service

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