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