OSDN Git Service

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