OSDN Git Service

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