OSDN Git Service

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