OSDN Git Service

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