OSDN Git Service

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