OSDN Git Service

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