OSDN Git Service

[Refactor] #37353 dungeon~spell2間整理。 / Refactor between dungeon and spell2.
[hengband/hengband.git] / src / dungeon.c
index a058144..28a77d2 100644 (file)
  */
 
 #include "angband.h"
-
-#define TY_CURSE_CHANCE 200 /*!<太古の怨念の1ターン毎の発動確率(1/n)*/
-#define CHAINSWORD_NOISE 100 /*!<チェンソーの1ターン毎の発動確率(1/n)*/
+#include "cmd-activate.h"
+#include "cmd-eat.h"
+#include "cmd-item.h"
+#include "cmd-magiceat.h"
+#include "cmd-quaff.h"
+#include "cmd-read.h"
+#include "cmd-usestaff.h"
+#include "cmd-zaprod.h"
+#include "cmd-zapwand.h"
+#include "cmd-pet.h"
 
 static bool load = TRUE; /*!<ロード処理中の分岐フラグ*/
 static int wild_regen = 20; /*!<広域マップ移動時の自然回復処理カウンタ(広域マップ1マス毎に20回処理を基本とする)*/
@@ -23,7 +30,7 @@ static int wild_regen = 20; /*!<広域マップ移動時の自然回復処理カ
  * @param o_ptr 擬似鑑定を行うオブジェクトの参照ポインタ。
  * @return 擬似鑑定結果のIDを返す。
  */
-static byte value_check_aux1(object_type *o_ptr)
+byte value_check_aux1(object_type *o_ptr)
 {
        /* Artifacts */
        if (object_is_artifact(o_ptr))
@@ -68,7 +75,7 @@ static byte value_check_aux1(object_type *o_ptr)
  * @param o_ptr 擬似鑑定を行うオブジェクトの参照ポインタ。
  * @return 擬似鑑定結果のIDを返す。
  */
-static byte value_check_aux2(object_type *o_ptr)
+byte value_check_aux2(object_type *o_ptr)
 {
        /* Cursed items (all of them) */
        if (object_is_cursed(o_ptr)) return FEEL_CURSED;
@@ -600,8 +607,8 @@ static void sense_inventory2(void)
  */
 static void pattern_teleport(void)
 {
-       int min_level = 0;
-       int max_level = 99;
+       DEPTH min_level = 0;
+       DEPTH max_level = 99;
 
        /* Ask for level */
        if (get_check(_("他の階にテレポートしますか?", "Teleport level? ")))
@@ -628,16 +635,16 @@ static void pattern_teleport(void)
                }
 
                /* Prompt */
-               sprintf(ppp, _("テレポート先:(%d-%d)", "Teleport to level (%d-%d): "), min_level, max_level);
+               sprintf(ppp, _("テレポート先:(%d-%d)", "Teleport to level (%d-%d): "), (int)min_level, (int)max_level);
 
                /* Default */
-               sprintf(tmp_val, "%d", dun_level);
+               sprintf(tmp_val, "%d", (int)dun_level);
 
                /* Ask for a level */
                if (!get_string(ppp, tmp_val, 10)) return;
 
                /* Extract request */
-               command_arg = atoi(tmp_val);
+               command_arg = (COMMAND_ARG)atoi(tmp_val);
        }
        else if (get_check(_("通常テレポート?", "Normal teleport? ")))
        {
@@ -650,10 +657,10 @@ static void pattern_teleport(void)
        }
 
        /* Paranoia */
-       if (command_arg < min_level) command_arg = min_level;
+       if (command_arg < min_level) command_arg = (COMMAND_ARG)min_level;
 
        /* Paranoia */
-       if (command_arg > max_level) command_arg = max_level;
+       if (command_arg > max_level) command_arg = (COMMAND_ARG)max_level;
 
        /* Accept request */
        msg_format(_("%d 階にテレポートしました。", "You teleport to dungeon level %d."), command_arg);
@@ -668,7 +675,7 @@ static void pattern_teleport(void)
        if (record_stair) do_cmd_write_nikki(NIKKI_PAT_TELE,0,NULL);
 
        p_ptr->inside_quest = 0;
-       energy_use = 0;
+       p_ptr->energy_use = 0;
 
        /*
         * Clear all saved floors
@@ -686,8 +693,9 @@ static void pattern_teleport(void)
  */
 static void wreck_the_pattern(void)
 {
-       int to_ruin = 0, r_y, r_x;
-       int pattern_type = f_info[cave[py][px].feat].subtype;
+       int to_ruin = 0;
+       POSITION r_y, r_x;
+       int pattern_type = f_info[cave[p_ptr->y][p_ptr->x].feat].subtype;
 
        if (pattern_type == PATTERN_TILE_WRECKED)
        {
@@ -705,7 +713,7 @@ static void wreck_the_pattern(void)
 
        while (to_ruin--)
        {
-               scatter(&r_y, &r_x, py, px, 4, 0);
+               scatter(&r_y, &r_x, p_ptr->y, p_ptr->x, 4, 0);
 
                if (pattern_tile(r_y, r_x) &&
                    (f_info[cave[r_y][r_x].feat].subtype != PATTERN_TILE_WRECKED))
@@ -714,7 +722,7 @@ static void wreck_the_pattern(void)
                }
        }
 
-       cave_set_feat(py, px, feat_pattern_corrupted);
+       cave_set_feat(p_ptr->y, p_ptr->x, feat_pattern_corrupted);
 }
 
 /*!
@@ -725,7 +733,7 @@ static bool pattern_effect(void)
 {
        int pattern_type;
 
-       if (!pattern_tile(py, px)) return FALSE;
+       if (!pattern_tile(p_ptr->y, p_ptr->x)) return FALSE;
 
        if ((prace_is_(RACE_AMBERITE)) &&
            (p_ptr->cut > 0) && one_in_(10))
@@ -733,27 +741,17 @@ static bool pattern_effect(void)
                wreck_the_pattern();
        }
 
-       pattern_type = f_info[cave[py][px].feat].subtype;
+       pattern_type = f_info[cave[p_ptr->y][p_ptr->x].feat].subtype;
 
        switch (pattern_type)
        {
        case PATTERN_TILE_END:
-               (void)set_poisoned(0);
                (void)set_image(0);
-               (void)set_stun(0);
-               (void)set_cut(0);
-               (void)set_blind(0);
-               (void)set_afraid(0);
-               (void)do_res_stat(A_STR);
-               (void)do_res_stat(A_INT);
-               (void)do_res_stat(A_WIS);
-               (void)do_res_stat(A_DEX);
-               (void)do_res_stat(A_CON);
-               (void)do_res_stat(A_CHR);
+               (void)restore_all_status();
                (void)restore_level();
-               (void)hp_player(1000);
+               (void)cure_critical_wounds(1000);
 
-               cave_set_feat(py, px, feat_pattern_old);
+               cave_set_feat(p_ptr->y, p_ptr->x, feat_pattern_old);
                msg_print(_("「パターン」のこの部分は他の部分より強力でないようだ。", "This section of the Pattern looks less powerful."));
 
                /*
@@ -1064,7 +1062,7 @@ static void regen_captured_monsters(void)
                        if (r_ptr->flags2 & RF2_REGENERATE) frac *= 2;
 
                        /* Hack -- Regenerate */
-                       o_ptr->xtra4 += frac;
+                       o_ptr->xtra4 += (XTRA16)frac;
 
                        /* Do not over-regenerate */
                        if (o_ptr->xtra4 > o_ptr->xtra5) o_ptr->xtra4 = o_ptr->xtra5;
@@ -1211,127 +1209,6 @@ void leave_tower_check(void)
        }
 }
 
-/*!
- * @brief 超能力者のサイコメトリー処理/ Forcibly pseudo-identify an object in the inventory (or on the floor)
- * @return なし
- * @todo mind.cにこの関数を移動させるべき。
- * @note
- * currently this function allows pseudo-id of any object,
- * including silly ones like potions & scrolls, which always
- * get '{average}'. This should be changed, either to stop such
- * items from being pseudo-id'd, or to allow psychometry to
- * detect whether the unidentified potion/scroll/etc is
- * good (Cure Light Wounds, Restore Strength, etc) or
- * bad (Poison, Weakness etc) or 'useless' (Slime Mold Juice, etc).
- */
-bool psychometry(void)
-{
-       int             item;
-       object_type     *o_ptr;
-       char            o_name[MAX_NLEN];
-       byte            feel;
-       cptr            q, s;
-       bool okay = FALSE;
-
-       item_tester_no_ryoute = TRUE;
-       /* Get an item */
-       q = _("どのアイテムを調べますか?", "Meditate on which item? ");
-       s = _("調べるアイテムがありません。", "You have nothing appropriate.");
-
-       if (!get_item(&item, q, s, (USE_EQUIP | USE_INVEN | USE_FLOOR))) return (FALSE);
-
-       /* Get the item (in the pack) */
-       if (item >= 0)
-       {
-               o_ptr = &inventory[item];
-       }
-
-       /* Get the item (on the floor) */
-       else
-       {
-               o_ptr = &o_list[0 - item];
-       }
-
-       /* It is fully known, no information needed */
-       if (object_is_known(o_ptr))
-       {
-               msg_print(_("何も新しいことは判らなかった。", "You cannot find out anything more about that."));
-               return TRUE;
-       }
-
-       /* Check for a feeling */
-       feel = value_check_aux1(o_ptr);
-
-       /* Get an object description */
-       object_desc(o_name, o_ptr, (OD_OMIT_PREFIX | OD_NAME_ONLY));
-
-       /* Skip non-feelings */
-       if (!feel)
-       {
-               msg_format(_("%sからは特に変わった事は感じとれなかった。", "You do not perceive anything unusual about the %s."), o_name);
-               return TRUE;
-       }
-
-#ifdef JP
-msg_format("%sは%sという感じがする...",
-    o_name,  game_inscriptions[feel]);
-#else
-       msg_format("You feel that the %s %s %s...",
-                          o_name, ((o_ptr->number == 1) ? "is" : "are"),
-                          game_inscriptions[feel]);
-#endif
-
-
-       /* We have "felt" it */
-       o_ptr->ident |= (IDENT_SENSE);
-
-       /* "Inscribe" it */
-       o_ptr->feeling = feel;
-
-       /* Player touches it */
-       o_ptr->marked |= OM_TOUCHED;
-
-       /* Combine / Reorder the pack (later) */
-       p_ptr->notice |= (PN_COMBINE | PN_REORDER);
-
-       /* Window stuff */
-       p_ptr->window |= (PW_INVEN | PW_EQUIP | PW_PLAYER);
-
-       /* Valid "tval" codes */
-       switch (o_ptr->tval)
-       {
-       case TV_SHOT:
-       case TV_ARROW:
-       case TV_BOLT:
-       case TV_BOW:
-       case TV_DIGGING:
-       case TV_HAFTED:
-       case TV_POLEARM:
-       case TV_SWORD:
-       case TV_BOOTS:
-       case TV_GLOVES:
-       case TV_HELM:
-       case TV_CROWN:
-       case TV_SHIELD:
-       case TV_CLOAK:
-       case TV_SOFT_ARMOR:
-       case TV_HARD_ARMOR:
-       case TV_DRAG_ARMOR:
-       case TV_CARD:
-       case TV_RING:
-       case TV_AMULET:
-       case TV_LITE:
-       case TV_FIGURINE:
-               okay = TRUE;
-               break;
-       }
-
-       /* Auto-inscription/destroy */
-       autopick_alter_item(item, (bool)(okay && destroy_feeling));
-
-       /* Something happened */
-       return (TRUE);
-}
 
 /*!
  * @brief !!を刻んだ魔道具の時間経過による再充填を知らせる処理 / If player has inscribed the object with "!!", let him know when it's recharged. -LM-
@@ -1393,7 +1270,7 @@ static void check_music(void)
 
        /* Music singed by player */
        if (p_ptr->pclass != CLASS_BARD) return;
-       if (!p_ptr->magic_num1[0] && !p_ptr->magic_num1[1]) return;
+       if (!SINGING_SONG_EFFECT(p_ptr) && !INTERUPTING_SONG_EFFECT(p_ptr)) return;
 
        if (p_ptr->anti_magic)
        {
@@ -1401,7 +1278,7 @@ static void check_music(void)
                return;
        }
 
-       spell = p_ptr->magic_num2[0];
+       spell = SINGING_SONG_ID(p_ptr);
        s_ptr = &technic_info[REALM_MUSIC - MIN_TECHNIC][spell];
 
        need_mana = mod_need_mana(s_ptr->smana, spell, REALM_MUSIC);
@@ -1420,10 +1297,10 @@ static void check_music(void)
                s64b_sub(&(p_ptr->csp), &(p_ptr->csp_frac), need_mana, need_mana_frac);
 
                p_ptr->redraw |= PR_MANA;
-               if (p_ptr->magic_num1[1])
+               if (INTERUPTING_SONG_EFFECT(p_ptr))
                {
-                       p_ptr->magic_num1[0] = p_ptr->magic_num1[1];
-                       p_ptr->magic_num1[1] = 0;
+                       SINGING_SONG_EFFECT(p_ptr) = INTERUPTING_SONG_EFFECT(p_ptr);
+                       INTERUPTING_SONG_EFFECT(p_ptr) = MUSIC_NONE;
                        msg_print(_("歌を再開した。", "You restart singing."));
                        p_ptr->action = ACTION_SING;
 
@@ -1533,7 +1410,7 @@ static object_type *choose_cursed_obj_name(u32b flag)
  */
 static void process_world_aux_hp_and_sp(void)
 {
-       feature_type *f_ptr = &f_info[cave[py][px].feat];
+       feature_type *f_ptr = &f_info[cave[p_ptr->y][p_ptr->x].feat];
        bool cave_no_regen = FALSE;
        int upkeep_factor = 0;
 
@@ -1553,7 +1430,7 @@ static void process_world_aux_hp_and_sp(void)
        /* Take damage from cuts */
        if (p_ptr->cut && !IS_INVULN())
        {
-               int dam;
+               HIT_POINT dam;
 
                /* Mortal wound or Deep Gash */
                if (p_ptr->cut > 1000)
@@ -1603,7 +1480,7 @@ static void process_world_aux_hp_and_sp(void)
        {
                if (!dun_level && !p_ptr->resist_lite && !IS_INVULN() && is_daytime())
                {
-                       if ((cave[py][px].info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW)
+                       if ((cave[p_ptr->y][p_ptr->x].info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW)
                        {
                                /* Take damage */
                                msg_print(_("日光があなたのアンデッドの肉体を焼き焦がした!", "The sun's rays scorch your undead flesh!"));
@@ -1661,11 +1538,11 @@ static void process_world_aux_hp_and_sp(void)
                        {
                                msg_print(_("熱で火傷した!", "The heat burns you!"));
                                take_hit(DAMAGE_NOESCAPE, damage, format(_("%sの上に浮遊したダメージ", "flying over %s"), 
-                                                               f_name + f_info[get_feat_mimic(&cave[py][px])].name), -1);
+                                                               f_name + f_info[get_feat_mimic(&cave[p_ptr->y][p_ptr->x])].name), -1);
                        }
                        else
                        {
-                               cptr name = f_name + f_info[get_feat_mimic(&cave[py][px])].name;
+                               cptr name = f_name + f_info[get_feat_mimic(&cave[p_ptr->y][p_ptr->x])].name;
                                msg_format(_("%sで火傷した!", "The %s burns you!"), name);
                                take_hit(DAMAGE_NOESCAPE, damage, name, -1);
                        }
@@ -2318,12 +2195,12 @@ static void process_world_aux_mutation(void)
            !p_ptr->anti_magic && (randint1(6666) == 666))
        {
                bool pet = one_in_(6);
-               u32b mode = PM_ALLOW_GROUP;
+               BIT_FLAGS mode = PM_ALLOW_GROUP;
 
                if (pet) mode |= PM_FORCE_PET;
                else mode |= (PM_ALLOW_UNIQUE | PM_NO_PET);
 
-               if (summon_specific((pet ? -1 : 0), py, px,
+               if (summon_specific((pet ? -1 : 0), p_ptr->y, p_ptr->x,
                                    dun_level, SUMMON_DEMON, mode))
                {
                        msg_print(_("あなたはデーモンを引き寄せた!", "You have attracted a demon!"));
@@ -2393,7 +2270,7 @@ static void process_world_aux_mutation(void)
                msg_print(NULL);
 
                /* Absorb light from the current possition */
-               if ((cave[py][px].info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW)
+               if ((cave[p_ptr->y][p_ptr->x].info & (CAVE_GLOW | CAVE_MNDK)) == CAVE_GLOW)
                {
                        hp_player(10);
                }
@@ -2429,12 +2306,12 @@ static void process_world_aux_mutation(void)
            !p_ptr->anti_magic && one_in_(7000))
        {
                bool pet = one_in_(3);
-               u32b mode = PM_ALLOW_GROUP;
+               BIT_FLAGS mode = PM_ALLOW_GROUP;
 
                if (pet) mode |= PM_FORCE_PET;
                else mode |= (PM_ALLOW_UNIQUE | PM_NO_PET);
 
-               if (summon_specific((pet ? -1 : 0), py, px, dun_level, SUMMON_ANIMAL, mode))
+               if (summon_specific((pet ? -1 : 0), p_ptr->y, p_ptr->x, dun_level, SUMMON_ANIMAL, mode))
                {
                        msg_print(_("動物を引き寄せた!", "You have attracted an animal!"));
                        disturb(0, 1);
@@ -2509,12 +2386,12 @@ static void process_world_aux_mutation(void)
            !p_ptr->anti_magic && one_in_(3000))
        {
                bool pet = one_in_(5);
-               u32b mode = PM_ALLOW_GROUP;
+               BIT_FLAGS mode = PM_ALLOW_GROUP;
 
                if (pet) mode |= PM_FORCE_PET;
                else mode |= (PM_ALLOW_UNIQUE | PM_NO_PET);
 
-               if (summon_specific((pet ? -1 : 0), py, px, dun_level, SUMMON_DRAGON, mode))
+               if (summon_specific((pet ? -1 : 0), p_ptr->y, p_ptr->x, dun_level, SUMMON_DRAGON, mode))
                {
                        msg_print(_("ドラゴンを引き寄せた!", "You have attracted a dragon!"));
                        disturb(0, 1);
@@ -2634,7 +2511,7 @@ static void process_world_aux_mutation(void)
        }
        if ((p_ptr->muta2 & MUT2_DISARM) && one_in_(10000))
        {
-               int slot = 0;
+               INVENTORY_IDX slot = 0;
                object_type *o_ptr = NULL;
 
                disturb(0, 1);
@@ -2796,7 +2673,7 @@ static void process_world_aux_curse(void)
                /* Call animal */
                if ((p_ptr->cursed & TRC_CALL_ANIMAL) && one_in_(2500))
                {
-                       if (summon_specific(0, py, px, dun_level, SUMMON_ANIMAL,
+                       if (summon_specific(0, p_ptr->y, p_ptr->x, dun_level, SUMMON_ANIMAL,
                            (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET)))
                        {
                                char o_name[MAX_NLEN];
@@ -2809,7 +2686,7 @@ static void process_world_aux_curse(void)
                /* Call demon */
                if ((p_ptr->cursed & TRC_CALL_DEMON) && one_in_(1111))
                {
-                       if (summon_specific(0, py, px, dun_level, SUMMON_DEMON, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET)))
+                       if (summon_specific(0, p_ptr->y, p_ptr->x, dun_level, SUMMON_DEMON, (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET)))
                        {
                                char o_name[MAX_NLEN];
 
@@ -2821,7 +2698,7 @@ static void process_world_aux_curse(void)
                /* Call dragon */
                if ((p_ptr->cursed & TRC_CALL_DRAGON) && one_in_(800))
                {
-                       if (summon_specific(0, py, px, dun_level, SUMMON_DRAGON,
+                       if (summon_specific(0, p_ptr->y, p_ptr->x, dun_level, SUMMON_DRAGON,
                            (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET)))
                        {
                                char o_name[MAX_NLEN];
@@ -2834,7 +2711,7 @@ static void process_world_aux_curse(void)
                /* Call undead */
                if ((p_ptr->cursed & TRC_CALL_UNDEAD) && one_in_(1111))
                {
-                       if (summon_specific(0, py, px, dun_level, SUMMON_UNDEAD,
+                       if (summon_specific(0, p_ptr->y, p_ptr->x, dun_level, SUMMON_UNDEAD,
                            (PM_ALLOW_GROUP | PM_ALLOW_UNIQUE | PM_NO_PET)))
                        {
                                char o_name[MAX_NLEN];
@@ -2971,8 +2848,8 @@ static void process_world_aux_recharge(void)
                if ((o_ptr->tval == TV_ROD) && (o_ptr->timeout))
                {
                        /* Determine how many rods are charging. */
-                       int temp = (o_ptr->timeout + (k_ptr->pval - 1)) / k_ptr->pval;
-                       if (temp > o_ptr->number) temp = o_ptr->number;
+                       TIME_EFFECT temp = (o_ptr->timeout + (k_ptr->pval - 1)) / k_ptr->pval;
+                       if (temp > o_ptr->number) temp = (TIME_EFFECT)o_ptr->number;
 
                        /* Decrease timeout by that number. */
                        o_ptr->timeout -= temp;
@@ -3016,7 +2893,7 @@ static void process_world_aux_recharge(void)
                if ((o_ptr->tval == TV_ROD) && (o_ptr->timeout))
                {
                        /* Charge it */
-                       o_ptr->timeout -= o_ptr->number;
+                       o_ptr->timeout -= (TIME_EFFECT)o_ptr->number;
 
                        /* Boundary control. */
                        if (o_ptr->timeout < 0) o_ptr->timeout = 0;
@@ -3107,14 +2984,14 @@ static void process_world_aux_movement(void)
 
                                if (p_ptr->wild_mode)
                                {
-                                       p_ptr->wilderness_y = py;
-                                       p_ptr->wilderness_x = px;
+                                       p_ptr->wilderness_y = p_ptr->y;
+                                       p_ptr->wilderness_x = p_ptr->x;
                                }
                                else
                                {
                                        /* Save player position */
-                                       p_ptr->oldpx = px;
-                                       p_ptr->oldpy = py;
+                                       p_ptr->oldpx = p_ptr->x;
+                                       p_ptr->oldpy = p_ptr->y;
                                }
                                p_ptr->wild_mode = FALSE;
 
@@ -3205,7 +3082,7 @@ static void process_world_aux_movement(void)
  * @param m_idx 隣接数を調べたいモンスターのID
  * @return 隣接しているモンスターの数
  */
-static int get_monster_crowd_number(int m_idx)
+static int get_monster_crowd_number(MONSTER_IDX m_idx)
 {
        monster_type *m_ptr = &m_list[m_idx];
        int my = m_ptr->fy;
@@ -3243,7 +3120,7 @@ static byte get_dungeon_feeling(void)
 {
        const int base = 10;
        int rating = 0;
-       int i;
+       IDX i;
 
        /* Hack -- no feeling in the town */
        if (!dun_level) return 0;
@@ -3457,6 +3334,17 @@ static void process_world(void)
        /* Update dungeon feeling, and announce it if changed */
        update_dungeon_feeling();
 
+       /* 帰還無しモード時のレベルテレポバグ対策 / Fix for level teleport bugs on ironman_downward.*/
+       if (ironman_downward && (dungeon_type != DUNGEON_ANGBAND && dungeon_type != 0))
+       {
+               dun_level = 0;
+               dungeon_type = 0;
+               prepare_change_floor_mode(CFM_FIRST_FLOOR | CFM_RAND_PLACE);
+               p_ptr->inside_arena = FALSE;
+               p_ptr->wild_mode = FALSE;
+               p_ptr->leaving = TRUE;
+       }
+
        /*** Check monster arena ***/
        if (p_ptr->inside_battle && !p_ptr->leaving)
        {
@@ -3509,7 +3397,7 @@ static void process_world(void)
                        p_ptr->energy_need = 0;
                        battle_monsters();
                }
-               else if (turn - old_turn == 150*TURNS_PER_TICK)
+               else if (turn - old_turn == 150 * TURNS_PER_TICK)
                {
                        msg_print(_("申し分けありませんが、この勝負は引き分けとさせていただきます。", "This battle have ended in a draw."));
                        p_ptr->au += kakekin;
@@ -3670,7 +3558,7 @@ static void process_world(void)
 
                        if (p_ptr->special_defense & NINJA_S_STEALTH)
                        {
-                               if (cave[py][px].info & CAVE_GLOW) set_superstealth(FALSE);
+                               if (cave[p_ptr->y][p_ptr->x].info & CAVE_GLOW) set_superstealth(FALSE);
                        }
                }
        }
@@ -3762,11 +3650,12 @@ static void process_world(void)
 
        /*
         * Nightmare mode activates the TY_CURSE at midnight
-        *
         * Require exact minute -- Don't activate multiple times in a minute
         */
+
        if (ironman_nightmare && (min != prev_min))
        {
+
                /* Every 15 minutes after 11:00 pm */
                if ((hour == 23) && !(min % 15))
                {
@@ -3796,11 +3685,25 @@ static void process_world(void)
                /* TY_CURSE activates at midnight! */
                if (!hour && !min)
                {
-                       int count = 0;
 
                        disturb(1, 1);
                        msg_print(_("遠くで鐘が何回も鳴り、死んだような静けさの中へ消えていった。", "A distant bell tolls many times, fading into an deathly silence."));
-                       activate_ty_curse(FALSE, &count);
+
+                       if (p_ptr->wild_mode)
+                       {
+                               /* Go into large wilderness view */
+                               p_ptr->oldpy = randint1(MAX_HGT - 2);
+                               p_ptr->oldpx = randint1(MAX_WID - 2);
+                               change_wild_mode();
+
+                               /* Give first move to monsters */
+                               p_ptr->energy_use = 100;
+
+                               /* HACk -- set the encouter flag for the wilderness generation */
+                               generate_encounter = TRUE;
+                       }
+
+                       invoking_midnight_curse = TRUE;
                }
        }
 
@@ -3862,7 +3765,7 @@ static void process_world(void)
                        if (p_ptr->food < PY_FOOD_STARVE)
                        {
                                /* Calculate damage */
-                               int dam = (PY_FOOD_STARVE - p_ptr->food) / 10;
+                               HIT_POINT dam = (PY_FOOD_STARVE - p_ptr->food) / 10;
 
                                /* Take damage */
                                if (!IS_INVULN()) take_hit(DAMAGE_LOSELIFE, dam, _("空腹", "starvation"), -1);
@@ -4033,7 +3936,7 @@ extern void do_cmd_borg(void);
  */
 static void process_command(void)
 {
-       int old_now_message = now_message;
+       COMMAND_CODE old_now_message = now_message;
 
 #ifdef ALLOW_REPEAT /* TNB */
 
@@ -4444,12 +4347,12 @@ static void process_command(void)
                                                which_power = _("祈り", "prayer");
 
                                        msg_format(_("反魔法バリアが%sを邪魔した!", "An anti-magic shell disrupts your %s!"), which_power);
-                                       energy_use = 0;
+                                       p_ptr->energy_use = 0;
                                }
                                else if (p_ptr->shero && (p_ptr->pclass != CLASS_BERSERKER))
                                {
                                        msg_format(_("狂戦士化していて頭が回らない!", "You cannot think directly!"));
-                                       energy_use = 0;
+                                       p_ptr->energy_use = 0;
                                }
                                else
                                {
@@ -4541,10 +4444,7 @@ static void process_command(void)
                /* Throw an item */
                case 'v':
                {
-                       if (!p_ptr->wild_mode)
-                       {
-                               do_cmd_throw();
-                       }
+                       if (!p_ptr->wild_mode) do_cmd_throw(1, FALSE, -1);
                        break;
                }
 
@@ -4918,7 +4818,7 @@ static void process_command(void)
                        break;
                }
        }
-       if (!energy_use && !now_message)
+       if (!p_ptr->energy_use && !now_message)
                now_message = old_now_message;
 }
 
@@ -4927,7 +4827,7 @@ static void process_command(void)
  * @param r_idx 判定したいモンスター種族のID
  * @return 釣れる対象ならばTRUEを返す
  */
-static bool monster_tsuri(int r_idx)
+static bool monster_tsuri(MONRACE_IDX r_idx)
 {
        monster_race *r_ptr = &r_info[r_idx];
 
@@ -4969,7 +4869,7 @@ static void pack_overflow(void)
                msg_format(_("%s(%c)を落とした。", "You drop %s (%c)."), o_name, index_to_label(INVEN_PACK));
 
                /* Drop it (carefully) near the player */
-               (void)drop_near(o_ptr, 0, py, px);
+               (void)drop_near(o_ptr, 0, p_ptr->y, p_ptr->x);
 
                /* Modify, Describe, Optimize */
                inven_item_increase(INVEN_PACK, -255);
@@ -5023,7 +4923,7 @@ static void process_upkeep_with_speed(void)
  */
 static void process_player(void)
 {
-       int i;
+       IDX i;
 
        /*** Apply energy ***/
 
@@ -5035,6 +4935,13 @@ static void process_player(void)
                hack_mutation = FALSE;
        }
 
+       if (invoking_midnight_curse)
+       {
+               int count = 0;
+               activate_ty_curse(FALSE, &count);
+               invoking_midnight_curse = FALSE;
+       }
+
        if (p_ptr->inside_battle)
        {
                for(i = 1; i < m_max; i++)
@@ -5068,7 +4975,7 @@ static void process_player(void)
        if (resting < 0)
        {
                /* Basic resting */
-               if (resting == -1)
+               if (resting == COMMAND_ARG_REST_FULL_HEALING)
                {
                        /* Stop resting */
                        if ((p_ptr->chp == p_ptr->mhp) &&
@@ -5079,7 +4986,7 @@ static void process_player(void)
                }
 
                /* Complete resting */
-               else if (resting == -2)
+               else if (resting == COMMAND_ARG_REST_UNTIL_DONE)
                {
                        /* Stop resting */
                        if ((p_ptr->chp == p_ptr->mhp) &&
@@ -5102,7 +5009,7 @@ static void process_player(void)
                Term_xtra(TERM_XTRA_DELAY, 10);
                if (one_in_(1000))
                {
-                       int r_idx;
+                       MONRACE_IDX r_idx;
                        bool success = FALSE;
                        get_mon_num_prep(monster_tsuri,NULL);
                        r_idx = get_mon_num(dun_level ? dun_level : wilderness[p_ptr->wilderness_y][p_ptr->wilderness_x].level);
@@ -5110,8 +5017,8 @@ static void process_player(void)
                        if (r_idx && one_in_(2))
                        {
                                int y, x;
-                               y = py+ddy[tsuri_dir];
-                               x = px+ddx[tsuri_dir];
+                               y = p_ptr->y+ddy[tsuri_dir];
+                               x = p_ptr->x+ddx[tsuri_dir];
                                if (place_monster_aux(0, y, x, r_idx, PM_NO_KAGE))
                                {
                                        char m_name[80];
@@ -5228,13 +5135,13 @@ static void process_player(void)
        {
                (void)set_lightspeed(p_ptr->lightspeed - 1, TRUE);
        }
-       if ((p_ptr->pclass == CLASS_FORCETRAINER) && (p_ptr->magic_num1[0]))
+       if ((p_ptr->pclass == CLASS_FORCETRAINER) && P_PTR_KI)
        {
-               if (p_ptr->magic_num1[0] < 40)
+               if (P_PTR_KI < 40)
                {
-                       p_ptr->magic_num1[0] = 0;
+                       P_PTR_KI = 0;
                }
-               else p_ptr->magic_num1[0] -= 40;
+               else P_PTR_KI -= 40;
                p_ptr->update |= (PU_BONUS);
        }
        if (p_ptr->action == ACTION_LEARN)
@@ -5294,7 +5201,7 @@ static void process_player(void)
                handle_stuff();
 
                /* Place the cursor on the player */
-               move_cursor_relative(py, px);
+               move_cursor_relative(p_ptr->y, p_ptr->x);
 
                /* Refresh (optional) */
                if (fresh_before) Term_fresh();
@@ -5309,13 +5216,13 @@ static void process_player(void)
 
 
                /* Assume free turn */
-               energy_use = 0;
+               p_ptr->energy_use = 0;
 
 
                if (p_ptr->inside_battle)
                {
                        /* Place the cursor on the player */
-                       move_cursor_relative(py, px);
+                       move_cursor_relative(p_ptr->y, p_ptr->x);
 
                        command_cmd = SPECIAL_KEY_BUILDING;
 
@@ -5327,7 +5234,7 @@ static void process_player(void)
                else if (p_ptr->paralyzed || (p_ptr->stun >= 100))
                {
                        /* Take a turn */
-                       energy_use = 100;
+                       p_ptr->energy_use = 100;
                }
 
                /* Resting */
@@ -5346,14 +5253,14 @@ static void process_player(void)
                        }
 
                        /* Take a turn */
-                       energy_use = 100;
+                       p_ptr->energy_use = 100;
                }
 
                /* Fishing */
                else if (p_ptr->action == ACTION_FISH)
                {
                        /* Take a turn */
-                       energy_use = 100;
+                       p_ptr->energy_use = 100;
                }
 
                /* Running */
@@ -5398,7 +5305,7 @@ static void process_player(void)
                else
                {
                        /* Place the cursor on the player */
-                       move_cursor_relative(py, px);
+                       move_cursor_relative(p_ptr->y, p_ptr->x);
 
                        can_save = TRUE;
                        /* Get a command (normal) */
@@ -5417,18 +5324,18 @@ static void process_player(void)
                /*** Clean up ***/
 
                /* Significant */
-               if (energy_use)
+               if (p_ptr->energy_use)
                {
                        /* Use some energy */
-                       if (world_player || energy_use > 400)
+                       if (world_player || p_ptr->energy_use > 400)
                        {
                                /* The Randomness is irrelevant */
-                               p_ptr->energy_need += energy_use * TURNS_PER_TICK / 10;
+                               p_ptr->energy_need += p_ptr->energy_use * TURNS_PER_TICK / 10;
                        }
                        else
                        {
                                /* There is some randomness of needed energy */
-                               p_ptr->energy_need += (s16b)((s32b)energy_use * ENERGY_NEED() / 100L);
+                               p_ptr->energy_need += (s16b)((s32b)p_ptr->energy_use * ENERGY_NEED() / 100L);
                        }
 
                        /* Hack -- constant hallucination */
@@ -5579,7 +5486,7 @@ static void process_player(void)
                }
 
                /* Sniper */
-               if (energy_use && reset_concent) reset_concentration(TRUE);
+               if (p_ptr->energy_use && reset_concent) reset_concentration(TRUE);
 
                /* Handle "leaving" */
                if (p_ptr->leaving) break;
@@ -5592,9 +5499,15 @@ static void process_player(void)
 /*!
  * @brief 現在プレイヤーがいるダンジョンの全体処理 / Interact with the current dungeon level.
  * @return なし
- * @note
+ * @details
+ * <p>
+ * この関数から現在の階層を出る、プレイヤーがキャラが死ぬ、
+ * ゲームを終了するかのいずれかまでループする。
+ * </p>
+ * <p>
  * This function will not exit until the level is completed,\n
  * the user dies, or the game is terminated.\n
+ * </p>
  */
 static void dungeon(bool load_game)
 {
@@ -5604,7 +5517,7 @@ static void dungeon(bool load_game)
        base_level = dun_level;
 
        /* Reset various flags */
-       hack_mind = FALSE;
+       is_loading_now = FALSE;
 
        /* Not leaving */
        p_ptr->leaving = FALSE;
@@ -5736,8 +5649,8 @@ static void dungeon(bool load_game)
                }
        }
 
-       if ((p_ptr->pclass == CLASS_BARD) && (p_ptr->magic_num1[0] > MUSIC_DETECT))
-               p_ptr->magic_num1[0] = MUSIC_DETECT;
+       if ((p_ptr->pclass == CLASS_BARD) && (SINGING_SONG_EFFECT(p_ptr) > MUSIC_DETECT))
+               SINGING_SONG_EFFECT(p_ptr) = MUSIC_DETECT;
 
        /* Hack -- notice death or departure */
        if (!p_ptr->playing || p_ptr->is_dead) return;
@@ -5772,7 +5685,7 @@ static void dungeon(bool load_game)
        /* Reset the object generation level */
        object_level = base_level;
 
-       hack_mind = TRUE;
+       is_loading_now = TRUE;
 
        if (p_ptr->energy_need > 0 && !p_ptr->inside_battle &&
            (dun_level || p_ptr->leaving_dungeon || p_ptr->inside_arena))
@@ -5813,7 +5726,7 @@ static void dungeon(bool load_game)
                handle_stuff();
 
                /* Hack -- Hilite the player */
-               move_cursor_relative(py, px);
+               move_cursor_relative(p_ptr->y, p_ptr->x);
 
                /* Optional fresh */
                if (fresh_after) Term_fresh();
@@ -5831,7 +5744,7 @@ static void dungeon(bool load_game)
                handle_stuff();
 
                /* Hack -- Hilite the player */
-               move_cursor_relative(py, px);
+               move_cursor_relative(p_ptr->y, p_ptr->x);
 
                /* Optional fresh */
                if (fresh_after) Term_fresh();
@@ -5850,7 +5763,7 @@ static void dungeon(bool load_game)
                handle_stuff();
 
                /* Hack -- Hilite the player */
-               move_cursor_relative(py, px);
+               move_cursor_relative(p_ptr->y, p_ptr->x);
 
                /* Optional fresh */
                if (fresh_after) Term_fresh();
@@ -5858,9 +5771,6 @@ static void dungeon(bool load_game)
                /* Hack -- Notice death or departure */
                if (!p_ptr->playing || p_ptr->is_dead) break;
 
-               /* Handle "leaving" */
-               if (p_ptr->leaving) break;
-
                /* Count game turns */
                turn++;
 
@@ -5872,6 +5782,9 @@ static void dungeon(bool load_game)
 
                prevent_turn_overflow();
 
+               /* Handle "leaving" */
+               if (p_ptr->leaving) break;
+
                if (wild_regen) wild_regen--;
        }
 
@@ -6005,7 +5918,8 @@ void extract_option_vars(void)
  */
 void determine_bounty_uniques(void)
 {
-       int          i, j, tmp;
+       int i, j;
+       MONRACE_IDX tmp;
        monster_race *r_ptr;
 
        get_mon_num_prep(NULL, NULL);
@@ -6099,7 +6013,7 @@ void determine_today_mon(bool conv_old)
  */
 void play_game(bool new_game)
 {
-       int i;
+       MONSTER_IDX i;
        bool load_game = TRUE;
        bool init_random_seed = FALSE;
 
@@ -6176,7 +6090,7 @@ void play_game(bool new_game)
 
                p_ptr->is_dead = TRUE;
 
-               start_time = time(NULL);
+               start_time = (u32b)time(NULL);
 
                /* No suspending now */
                signals_ignore_tstp();
@@ -6190,6 +6104,9 @@ void play_game(bool new_game)
                /* Open the high score file, for reading/writing */
                highscore_fd = fd_open(buf, O_RDWR);
 
+               /* 町名消失バグ対策(#38205) Init the wilderness */
+               process_dungeon_file("w_info.txt", 0, 0, max_wild_y, max_wild_x);
+
                /* Handle score, show Top scores */
                success = send_world_score(TRUE);
 
@@ -6352,7 +6269,7 @@ void play_game(bool new_game)
                {
                        p_ptr->wizard = TRUE;
 
-                       if (p_ptr->is_dead || !py || !px)
+                       if (p_ptr->is_dead || !p_ptr->y || !p_ptr->x)
                        {
                                /* Initialize the saved floors data */
                                init_saved_floors(TRUE);
@@ -6361,7 +6278,7 @@ void play_game(bool new_game)
                                p_ptr->inside_quest = 0;
 
                                /* Avoid crash in update_view() */
-                               py = px = 10;
+                               p_ptr->y = p_ptr->x = 10;
                        }
                }
                else if (p_ptr->is_dead)
@@ -6398,14 +6315,14 @@ void play_game(bool new_game)
                if (p_ptr->panic_save)
                {
                        /* No player?  -- Try to regenerate floor */
-                       if (!py || !px)
+                       if (!p_ptr->y || !p_ptr->x)
                        {
                                msg_print(_("プレイヤーの位置がおかしい。フロアを再生成します。", "What a strange player location.  Regenerate the dungeon floor."));
                                change_floor();
                        }
 
                        /* Still no player?  -- Try to locate random place */
-                       if (!py || !px) py = px = 10;
+                       if (!p_ptr->y || !p_ptr->x) p_ptr->y = p_ptr->x = 10;
 
                        /* No longer in panic */
                        p_ptr->panic_save = 0;
@@ -6468,9 +6385,9 @@ void play_game(bool new_game)
        if (new_game && ((p_ptr->pclass == CLASS_CAVALRY) || (p_ptr->pclass == CLASS_BEASTMASTER)))
        {
                monster_type *m_ptr;
-               int pet_r_idx = ((p_ptr->pclass == CLASS_CAVALRY) ? MON_HORSE : MON_YASE_HORSE);
+               IDX pet_r_idx = ((p_ptr->pclass == CLASS_CAVALRY) ? MON_HORSE : MON_YASE_HORSE);
                monster_race *r_ptr = &r_info[pet_r_idx];
-               place_monster_aux(0, py, px - 1, pet_r_idx,
+               place_monster_aux(0, p_ptr->y, p_ptr->x - 1, pet_r_idx,
                                  (PM_FORCE_PET | PM_NO_KAGE));
                m_ptr = &m_list[hack_m_idx_ii];
                m_ptr->mspeed = r_ptr->speed;
@@ -6572,21 +6489,21 @@ void play_game(bool new_game)
                                        msg_print(_("ウィザードモードに念を送り、死を欺いた。", "You invoke wizard mode and cheat death."));
                                        msg_print(NULL);
 
-                                       /* Restore hit points */
-                                       p_ptr->chp = p_ptr->mhp;
-                                       p_ptr->chp_frac = 0;
+                                       (void)life_stream(FALSE, FALSE);
 
                                        if (p_ptr->pclass == CLASS_MAGIC_EATER)
                                        {
-                                               for (i = 0; i < EATER_EXT*2; i++)
+                                               int magic_idx;
+                                               for (magic_idx = 0; magic_idx < EATER_EXT*2; magic_idx++)
                                                {
-                                                       p_ptr->magic_num1[i] = p_ptr->magic_num2[i]*EATER_CHARGE;
+                                                       p_ptr->magic_num1[magic_idx] = p_ptr->magic_num2[magic_idx]*EATER_CHARGE;
                                                }
-                                               for (; i < EATER_EXT*3; i++)
+                                               for (; magic_idx < EATER_EXT*3; magic_idx++)
                                                {
-                                                       p_ptr->magic_num1[i] = 0;
+                                                       p_ptr->magic_num1[magic_idx] = 0;
                                                }
                                        }
+
                                        /* Restore spell points */
                                        p_ptr->csp = p_ptr->msp;
                                        p_ptr->csp_frac = 0;
@@ -6617,16 +6534,6 @@ void play_game(bool new_game)
                                        /* Do not die */
                                        p_ptr->is_dead = FALSE;
 
-                                       /* Hack -- Healing */
-                                       (void)set_blind(0);
-                                       (void)set_confused(0);
-                                       (void)set_poisoned(0);
-                                       (void)set_afraid(0);
-                                       (void)set_paralyzed(0);
-                                       (void)set_image(0);
-                                       (void)set_stun(0);
-                                       (void)set_cut(0);
-
                                        /* Hack -- Prevent starvation */
                                        (void)set_food(PY_FOOD_MAX - 1);