OSDN Git Service

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