OSDN Git Service

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