OSDN Git Service

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