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