OSDN Git Service

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