OSDN Git Service

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