OSDN Git Service

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