OSDN Git Service

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