OSDN Git Service

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