OSDN Git Service

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