OSDN Git Service

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