OSDN Git Service

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