OSDN Git Service

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