OSDN Git Service

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