OSDN Git Service

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