OSDN Git Service

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