OSDN Git Service

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