OSDN Git Service

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