OSDN Git Service

[Refactor] #37353 職業ID定義を player-class.h へ移動.
[hengband/hengband.git] / src / player-move.c
index c95201a..2d96595 100644 (file)
  * entirely open.
  *
  * Corners: If you are not in the open (i.e. you are in a corridor)
- * and there is only one way to go in the new squares, then turn in
+ * and there is only one way to go in the new squares, then current_world_ptr->game_turn in
  * that direction. If there are more than two new ways to go, STOP.
  * If there are two ways to go, and those ways are separated by a
  * square which does not seem to be open, then STOP.
  */
 
 #include "angband.h"
+#include "core.h"
+#include "util.h"
+
+#include "realm-song.h"
+#include "autopick.h"
+#include "dungeon.h"
+#include "floor.h"
 #include "melee.h"
+#include "grid.h"
 #include "trap.h"
-#include "projection.h"
 #include "quest.h"
 #include "artifact.h"
+#include "player-move.h"
 #include "player-status.h"
+#include "player-effects.h"
+#include "player-class.h"
+#include "spells-floor.h"
+#include "feature.h"
+#include "warning.h"
+#include "monster.h"
+#include "monster-spell.h"
+#include "monster-status.h"
+#include "object-hook.h"
+#include "object-flavor.h"
+#include "spells.h"
+#include "cmd-basic.h"
+#include "view-mainwindow.h"
+#include "world.h"
+#include "objectkind.h"
+#include "autopick.h"
+#include "targeting.h"
 
 
-
-/*!
- * @brief プレイヤー攻撃の種族スレイング倍率計算
- * @param mult 算出前の基本倍率(/10倍)
- * @param flgs スレイフラグ配列
- * @param m_ptr 目標モンスターの構造体参照ポインタ
- * @return スレイング加味後の倍率(/10倍)
- */
-static MULTIPLY mult_slaying(MULTIPLY mult, const BIT_FLAGS* flgs, const monster_type* m_ptr)
-{
-       static const struct slay_table_t {
-               int slay_flag;
-               BIT_FLAGS affect_race_flag;
-               MULTIPLY slay_mult;
-               size_t flag_offset;
-               size_t r_flag_offset;
-       } slay_table[] = {
-#define OFFSET(X) offsetof(monster_race, X)
-               {TR_SLAY_ANIMAL, RF3_ANIMAL, 25, OFFSET(flags3), OFFSET(r_flags3)},
-               {TR_KILL_ANIMAL, RF3_ANIMAL, 40, OFFSET(flags3), OFFSET(r_flags3)},
-               {TR_SLAY_EVIL,   RF3_EVIL,   20, OFFSET(flags3), OFFSET(r_flags3)},
-               {TR_KILL_EVIL,   RF3_EVIL,   35, OFFSET(flags3), OFFSET(r_flags3)},
-               {TR_SLAY_GOOD,   RF3_GOOD,   20, OFFSET(flags3), OFFSET(r_flags3)},
-               {TR_KILL_GOOD,   RF3_GOOD,   35, OFFSET(flags3), OFFSET(r_flags3)},
-               {TR_SLAY_HUMAN,  RF2_HUMAN,  25, OFFSET(flags2), OFFSET(r_flags2)},
-               {TR_KILL_HUMAN,  RF2_HUMAN,  40, OFFSET(flags2), OFFSET(r_flags2)},
-               {TR_SLAY_UNDEAD, RF3_UNDEAD, 30, OFFSET(flags3), OFFSET(r_flags3)},
-               {TR_KILL_UNDEAD, RF3_UNDEAD, 50, OFFSET(flags3), OFFSET(r_flags3)},
-               {TR_SLAY_DEMON,  RF3_DEMON,  30, OFFSET(flags3), OFFSET(r_flags3)},
-               {TR_KILL_DEMON,  RF3_DEMON,  50, OFFSET(flags3), OFFSET(r_flags3)},
-               {TR_SLAY_ORC,    RF3_ORC,    30, OFFSET(flags3), OFFSET(r_flags3)},
-               {TR_KILL_ORC,    RF3_ORC,    50, OFFSET(flags3), OFFSET(r_flags3)},
-               {TR_SLAY_TROLL,  RF3_TROLL,  30, OFFSET(flags3), OFFSET(r_flags3)},
-               {TR_KILL_TROLL,  RF3_TROLL,  50, OFFSET(flags3), OFFSET(r_flags3)},
-               {TR_SLAY_GIANT,  RF3_GIANT,  30, OFFSET(flags3), OFFSET(r_flags3)},
-               {TR_KILL_GIANT,  RF3_GIANT,  50, OFFSET(flags3), OFFSET(r_flags3)},
-               {TR_SLAY_DRAGON, RF3_DRAGON, 30, OFFSET(flags3), OFFSET(r_flags3)},
-               {TR_KILL_DRAGON, RF3_DRAGON, 50, OFFSET(flags3), OFFSET(r_flags3)},
-#undef OFFSET
-       };
-       int i;
-       monster_race* r_ptr = &r_info[m_ptr->r_idx];
-
-       for (i = 0; i < sizeof(slay_table) / sizeof(slay_table[0]); ++ i)
-       {
-               const struct slay_table_t* p = &slay_table[i];
-
-               if ((have_flag(flgs, p->slay_flag)) &&
-                   (atoffset(u32b, r_ptr, p->flag_offset) & p->affect_race_flag))
-               {
-                       if (is_original_ap_and_seen(m_ptr))
-                       {
-                               atoffset(u32b, r_ptr, p->r_flag_offset) |= p->affect_race_flag;
-                       }
-
-                       mult = MAX(mult, p->slay_mult);
-               }
-       }
-
-       return mult;
-}
-
-/*!
- * @brief プレイヤー攻撃の属性スレイング倍率計算
- * @param mult 算出前の基本倍率(/10倍)
- * @param flgs スレイフラグ配列
- * @param m_ptr 目標モンスターの構造体参照ポインタ
- * @return スレイング加味後の倍率(/10倍)
- */
-static MULTIPLY mult_brand(MULTIPLY mult, const BIT_FLAGS* flgs, const monster_type* m_ptr)
-{
-       static const struct brand_table_t {
-               int brand_flag;
-               BIT_FLAGS resist_mask;
-               BIT_FLAGS hurt_flag;
-       } brand_table[] = {
-               {TR_BRAND_ACID, RFR_EFF_IM_ACID_MASK, 0U           },
-               {TR_BRAND_ELEC, RFR_EFF_IM_ELEC_MASK, 0U           },
-               {TR_BRAND_FIRE, RFR_EFF_IM_FIRE_MASK, RF3_HURT_FIRE},
-               {TR_BRAND_COLD, RFR_EFF_IM_COLD_MASK, RF3_HURT_COLD},
-               {TR_BRAND_POIS, RFR_EFF_IM_POIS_MASK, 0U           },
-       };
-       int i;
-       monster_race* r_ptr = &r_info[m_ptr->r_idx];
-
-       for (i = 0; i < sizeof(brand_table) / sizeof(brand_table[0]); ++ i)
-       {
-               const struct brand_table_t* p = &brand_table[i];
-
-               if (have_flag(flgs, p->brand_flag))
-               {
-                       /* Notice immunity */
-                       if (r_ptr->flagsr & p->resist_mask)
-                       {
-                               if (is_original_ap_and_seen(m_ptr))
-                               {
-                                       r_ptr->r_flagsr |= (r_ptr->flagsr & p->resist_mask);
-                               }
-                       }
-
-                       /* Otherwise, take the damage */
-                       else if (r_ptr->flags3 & p->hurt_flag)
-                       {
-                               if (is_original_ap_and_seen(m_ptr))
-                               {
-                                       r_ptr->r_flags3 |= p->hurt_flag;
-                               }
-
-                               mult = MAX(mult, 50);
-                       }
-                       else
-                       {
-                               mult = MAX(mult, 25);
-                       }
-               }
-       }
-
-       return mult;
-}
-
-/*!
- * @brief ダメージにスレイ要素を加える総合処理ルーチン /
- * Extract the "total damage" from a given object hitting a given monster.
- * @param o_ptr 使用武器オブジェクトの構造体参照ポインタ
- * @param tdam 現在算出途中のダメージ値
- * @param m_ptr 目標モンスターの構造体参照ポインタ
- * @param mode 剣術のID
- * @param thrown 射撃処理ならばTRUEを指定する
- * @return 総合的なスレイを加味したダメージ値
- * @note
- * Note that "flasks of oil" do NOT do fire damage, although they\n
- * certainly could be made to do so.  XXX XXX\n
- *\n
- * Note that most brands and slays are x3, except Slay Animal (x2),\n
- * Slay Evil (x2), and Kill dragon (x5).\n
- */
-HIT_POINT tot_dam_aux(object_type *o_ptr, HIT_POINT tdam, monster_type *m_ptr, BIT_FLAGS mode, bool thrown)
-{
-       MULTIPLY mult = 10;
-
-       BIT_FLAGS flgs[TR_FLAG_SIZE];
-       object_flags(o_ptr, flgs);
-       torch_flags(o_ptr, flgs); /* torches has secret flags */
-
-       if (!thrown)
-       {
-               /* Magical Swords */
-               if (p_ptr->special_attack & (ATTACK_ACID)) add_flag(flgs, TR_BRAND_ACID);
-               if (p_ptr->special_attack & (ATTACK_COLD)) add_flag(flgs, TR_BRAND_COLD);
-               if (p_ptr->special_attack & (ATTACK_ELEC)) add_flag(flgs, TR_BRAND_ELEC);
-               if (p_ptr->special_attack & (ATTACK_FIRE)) add_flag(flgs, TR_BRAND_FIRE);
-               if (p_ptr->special_attack & (ATTACK_POIS)) add_flag(flgs, TR_BRAND_POIS);
-       }
-
-       /* Hex - Slay Good (Runesword) */
-       if (hex_spelling(HEX_RUNESWORD)) add_flag(flgs, TR_SLAY_GOOD);
-
-       /* Some "weapons" and "ammo" do extra damage */
-       switch (o_ptr->tval)
-       {
-               case TV_SHOT:
-               case TV_ARROW:
-               case TV_BOLT:
-               case TV_HAFTED:
-               case TV_POLEARM:
-               case TV_SWORD:
-               case TV_DIGGING:
-               case TV_LITE:
-               {
-                       /* Slaying */
-                       mult = mult_slaying(mult, flgs, m_ptr);
-
-                       /* Elemental Brand */
-                       mult = mult_brand(mult, flgs, m_ptr);
-
-                       /* Hissatsu */
-                       if (p_ptr->pclass == CLASS_SAMURAI)
-                       {
-                               mult = mult_hissatsu(mult, flgs, m_ptr, mode);
-                       }
-
-                       /* Force Weapon */
-                       if ((p_ptr->pclass != CLASS_SAMURAI) && (have_flag(flgs, TR_FORCE_WEAPON)) && (p_ptr->csp > (o_ptr->dd * o_ptr->ds / 5)))
-                       {
-                               p_ptr->csp -= (1+(o_ptr->dd * o_ptr->ds / 5));
-                               p_ptr->redraw |= (PR_MANA);
-                               mult = mult * 3 / 2 + 20;
-                       }
-
-                       /* Hack -- The Nothung cause special damage to Fafner */
-                       if ((o_ptr->name1 == ART_NOTHUNG) && (m_ptr->r_idx == MON_FAFNER))
-                               mult = 150;
-                       break;
-               }
-       }
-       if (mult > 150) mult = 150;
-
-       /* Return the total damage */
-       return (tdam * mult / 10);
-}
-
+#ifdef TRAVEL
+ /* for travel */
+travel_type travel;
+#endif
 
 /*!
  * @brief 地形やその上のアイテムの隠された要素を明かす /
@@ -361,7 +189,7 @@ static void discover_hidden_things(POSITION y, POSITION x)
 {
        OBJECT_IDX this_o_idx, next_o_idx = 0;
        grid_type *g_ptr;
-       g_ptr = &grid_array[y][x];
+       g_ptr = &current_floor_ptr->grid_array[y][x];
 
        /* Invisible trap */
        if (g_ptr->mimic && is_trap(g_ptr->feat))
@@ -389,9 +217,7 @@ static void discover_hidden_things(POSITION y, POSITION x)
        for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
        {
                object_type *o_ptr;
-               o_ptr = &o_list[this_o_idx];
-
-               /* Acquire next object */
+               o_ptr = &current_floor_ptr->o_list[this_o_idx];
                next_o_idx = o_ptr->next_o_idx;
 
                /* Skip non-chests */
@@ -453,7 +279,7 @@ void search(void)
  * だが、違和感が\n
  * あるという指摘をうけたので、「~を拾った、~を持っている」という表示\n
  * にかえてある。そのための配列。\n
- * Add the given dungeon object to the character's inventory.\n
+ * Add the given dungeon object to the character's p_ptr->inventory_list.\n
  * Delete the object afterwards.\n
  */
 void py_pickup_aux(OBJECT_IDX o_idx)
@@ -471,7 +297,7 @@ void py_pickup_aux(OBJECT_IDX o_idx)
 
        object_type *o_ptr;
 
-       o_ptr = &o_list[o_idx];
+       o_ptr = &current_floor_ptr->o_list[o_idx];
 
 #ifdef JP
        object_desc(old_name, o_ptr, OD_NAME_ONLY);
@@ -482,7 +308,7 @@ void py_pickup_aux(OBJECT_IDX o_idx)
        slot = inven_carry(o_ptr);
 
        /* Get the object again */
-       o_ptr = &inventory[slot];
+       o_ptr = &p_ptr->inventory_list[slot];
 
        delete_object_idx(o_idx);
 
@@ -527,7 +353,7 @@ void py_pickup_aux(OBJECT_IDX o_idx)
        msg_format("You have %s (%c).", o_name, index_to_label(slot));
        strcpy(record_o_name, o_name);
 #endif
-       record_turn = turn;
+       record_turn = current_world_ptr->game_turn;
 
 
        check_find_art_quest_completion(o_ptr);
@@ -545,7 +371,7 @@ void py_pickup_aux(OBJECT_IDX o_idx)
  */
 void carry(bool pickup)
 {
-       grid_type *g_ptr = &grid_array[p_ptr->y][p_ptr->x];
+       grid_type *g_ptr = &current_floor_ptr->grid_array[p_ptr->y][p_ptr->x];
 
        OBJECT_IDX this_o_idx, next_o_idx = 0;
 
@@ -572,7 +398,7 @@ void carry(bool pickup)
        for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
        {
                object_type *o_ptr;
-               o_ptr = &o_list[this_o_idx];
+               o_ptr = &current_floor_ptr->o_list[this_o_idx];
 
 #ifdef ALLOW_EASY_SENSE /* TNB */
 
@@ -586,11 +412,8 @@ void carry(bool pickup)
 #endif /* ALLOW_EASY_SENSE -- TNB */
 
                object_desc(o_name, o_ptr, 0);
-
-               /* Acquire next object */
                next_o_idx = o_ptr->next_o_idx;
 
-               /* Hack -- disturb */
                disturb(FALSE, FALSE);
 
                /* Pick up gold */
@@ -669,8 +492,8 @@ void carry(bool pickup)
  */
 bool pattern_seq(POSITION c_y, POSITION c_x, POSITION n_y, POSITION n_x)
 {
-       feature_type *cur_f_ptr = &f_info[grid_array[c_y][c_x].feat];
-       feature_type *new_f_ptr = &f_info[grid_array[n_y][n_x].feat];
+       feature_type *cur_f_ptr = &f_info[current_floor_ptr->grid_array[c_y][c_x].feat];
+       feature_type *new_f_ptr = &f_info[current_floor_ptr->grid_array[n_y][n_x].feat];
        bool is_pattern_tile_cur = have_flag(cur_f_ptr->flags, FF_PATTERN);
        bool is_pattern_tile_new = have_flag(new_f_ptr->flags, FF_PATTERN);
        int pattern_type_cur, pattern_type_new;
@@ -786,34 +609,6 @@ bool pattern_seq(POSITION c_y, POSITION c_x, POSITION n_y, POSITION n_x)
        }
 }
 
-
-/*!
- * @brief プレイヤーが地形踏破可能かを返す
- * @param feature 判定したい地形ID
- * @param mode 移動に関するオプションフラグ
- * @return 移動可能ならばTRUEを返す
- */
-bool player_can_enter(FEAT_IDX feature, BIT_FLAGS16 mode)
-{
-       feature_type *f_ptr = &f_info[feature];
-
-       if (p_ptr->riding) return monster_can_cross_terrain(feature, &r_info[m_list[p_ptr->riding].r_idx], mode | CEM_RIDING);
-
-       if (have_flag(f_ptr->flags, FF_PATTERN))
-       {
-               if (!(mode & CEM_P_CAN_ENTER_PATTERN)) return FALSE;
-       }
-
-       if (have_flag(f_ptr->flags, FF_CAN_FLY) && p_ptr->levitation) return TRUE;
-       if (have_flag(f_ptr->flags, FF_CAN_SWIM) && p_ptr->can_swim) return TRUE;
-       if (have_flag(f_ptr->flags, FF_CAN_PASS) && p_ptr->pass_wall) return TRUE;
-
-       if (!have_flag(f_ptr->flags, FF_MOVE)) return FALSE;
-
-       return TRUE;
-}
-
-
 /*!
  * @brief 移動に伴うプレイヤーのステータス変化処理
  * @param ny 移動先Y座標
@@ -825,8 +620,8 @@ bool move_player_effect(POSITION ny, POSITION nx, BIT_FLAGS mpe_mode)
 {
        POSITION oy = p_ptr->y;
        POSITION ox = p_ptr->x;
-       grid_type *g_ptr = &grid_array[ny][nx];
-       grid_type *oc_ptr = &grid_array[oy][ox];
+       grid_type *g_ptr = &current_floor_ptr->grid_array[ny][nx];
+       grid_type *oc_ptr = &current_floor_ptr->grid_array[oy][ox];
        feature_type *f_ptr = &f_info[g_ptr->feat];
        feature_type *of_ptr = &f_info[oc_ptr->feat];
 
@@ -847,7 +642,7 @@ bool move_player_effect(POSITION ny, POSITION nx, BIT_FLAGS mpe_mode)
 
                        if (om_idx > 0) /* Monster on old spot (or p_ptr->riding) */
                        {
-                               monster_type *om_ptr = &m_list[om_idx];
+                               monster_type *om_ptr = &current_floor_ptr->m_list[om_idx];
                                om_ptr->fy = ny;
                                om_ptr->fx = nx;
                                update_monster(om_idx, TRUE);
@@ -855,7 +650,7 @@ bool move_player_effect(POSITION ny, POSITION nx, BIT_FLAGS mpe_mode)
 
                        if (nm_idx > 0) /* Monster on new spot */
                        {
-                               monster_type *nm_ptr = &m_list[nm_idx];
+                               monster_type *nm_ptr = &current_floor_ptr->m_list[nm_idx];
                                nm_ptr->fy = oy;
                                nm_ptr->fx = ox;
                                update_monster(nm_idx, TRUE);
@@ -883,7 +678,7 @@ bool move_player_effect(POSITION ny, POSITION nx, BIT_FLAGS mpe_mode)
                if ((!p_ptr->blind && !no_lite()) || !is_trap(g_ptr->feat)) g_ptr->info &= ~(CAVE_UNSAFE);
 
                /* For get everything when requested hehe I'm *NASTY* */
-               if (dun_level && (d_info[p_ptr->dungeon_idx].flags1 & DF1_FORGET)) wiz_dark();
+               if (current_floor_ptr->dun_level && (d_info[p_ptr->dungeon_idx].flags1 & DF1_FORGET)) wiz_dark();
                if (mpe_mode & MPE_HANDLE_STUFF) handle_stuff();
 
                if (p_ptr->pclass == CLASS_NINJA)
@@ -978,7 +773,7 @@ bool move_player_effect(POSITION ny, POSITION nx, BIT_FLAGS mpe_mode)
                leave_quest_check();
 
                p_ptr->inside_quest = g_ptr->special;
-               dun_level = 0;
+               current_floor_ptr->dun_level = 0;
                p_ptr->oldpx = 0;
                p_ptr->oldpy = 0;
 
@@ -1093,7 +888,7 @@ bool trap_can_be_ignored(FEAT_IDX feat)
  * @note
  * This routine should (probably) always induce energy expenditure.\n
  * @details
- * Note that moving will *always* take a turn, and will *always* hit\n
+ * Note that moving will *always* take a current_world_ptr->game_turn, and will *always* hit\n
  * any monster which might be in the destination grid.  Previously,\n
  * moving into walls was "free" and did NOT hit invisible monsters.\n
  */
@@ -1104,14 +899,14 @@ void move_player(DIRECTION dir, bool do_pickup, bool break_trap)
        POSITION x = p_ptr->x + ddx[dir];
 
        /* Examine the destination */
-       grid_type *g_ptr = &grid_array[y][x];
+       grid_type *g_ptr = &current_floor_ptr->grid_array[y][x];
 
        feature_type *f_ptr = &f_info[g_ptr->feat];
 
        monster_type *m_ptr;
 
-       monster_type *riding_m_ptr = &m_list[p_ptr->riding];
-       monster_race *riding_r_ptr = &r_info[p_ptr->riding ? riding_m_ptr->r_idx : 0]; /* Paranoia */
+       monster_type *riding_m_ptr = &current_floor_ptr->m_list[p_ptr->riding];
+       monster_race *riding_r_ptr = &r_info[p_ptr->riding ? riding_m_ptr->r_idx : 0];
 
        GAME_TEXT m_name[MAX_NLEN];
 
@@ -1123,7 +918,7 @@ void move_player(DIRECTION dir, bool do_pickup, bool break_trap)
        bool do_past = FALSE;
 
        /* Exit the area */
-       if (!dun_level && !p_ptr->wild_mode &&
+       if (!current_floor_ptr->dun_level && !p_ptr->wild_mode &&
                ((x == 0) || (x == MAX_WID - 1) ||
                 (y == 0) || (y == MAX_HGT - 1)))
        {
@@ -1135,18 +930,18 @@ void move_player(DIRECTION dir, bool do_pickup, bool break_trap)
                        {
                                p_ptr->wilderness_y--;
                                p_ptr->wilderness_x--;
-                               p_ptr->oldpy = cur_hgt - 2;
-                               p_ptr->oldpx = cur_wid - 2;
-                               ambush_flag = FALSE;
+                               p_ptr->oldpy = current_floor_ptr->height - 2;
+                               p_ptr->oldpx = current_floor_ptr->width - 2;
+                               p_ptr->ambush_flag = FALSE;
                        }
 
                        else if ((y == 0) && (x == MAX_WID - 1))
                        {
                                p_ptr->wilderness_y--;
                                p_ptr->wilderness_x++;
-                               p_ptr->oldpy = cur_hgt - 2;
+                               p_ptr->oldpy = current_floor_ptr->height - 2;
                                p_ptr->oldpx = 1;
-                               ambush_flag = FALSE;
+                               p_ptr->ambush_flag = FALSE;
                        }
 
                        else if ((y == MAX_HGT - 1) && (x == 0))
@@ -1154,8 +949,8 @@ void move_player(DIRECTION dir, bool do_pickup, bool break_trap)
                                p_ptr->wilderness_y++;
                                p_ptr->wilderness_x--;
                                p_ptr->oldpy = 1;
-                               p_ptr->oldpx = cur_wid - 2;
-                               ambush_flag = FALSE;
+                               p_ptr->oldpx = current_floor_ptr->width - 2;
+                               p_ptr->ambush_flag = FALSE;
                        }
 
                        else if ((y == MAX_HGT - 1) && (x == MAX_WID - 1))
@@ -1164,15 +959,15 @@ void move_player(DIRECTION dir, bool do_pickup, bool break_trap)
                                p_ptr->wilderness_x++;
                                p_ptr->oldpy = 1;
                                p_ptr->oldpx = 1;
-                               ambush_flag = FALSE;
+                               p_ptr->ambush_flag = FALSE;
                        }
 
                        else if (y == 0)
                        {
                                p_ptr->wilderness_y--;
-                               p_ptr->oldpy = cur_hgt - 2;
+                               p_ptr->oldpy = current_floor_ptr->height - 2;
                                p_ptr->oldpx = x;
-                               ambush_flag = FALSE;
+                               p_ptr->ambush_flag = FALSE;
                        }
 
                        else if (y == MAX_HGT - 1)
@@ -1180,15 +975,15 @@ void move_player(DIRECTION dir, bool do_pickup, bool break_trap)
                                p_ptr->wilderness_y++;
                                p_ptr->oldpy = 1;
                                p_ptr->oldpx = x;
-                               ambush_flag = FALSE;
+                               p_ptr->ambush_flag = FALSE;
                        }
 
                        else if (x == 0)
                        {
                                p_ptr->wilderness_x--;
-                               p_ptr->oldpx = cur_wid - 2;
+                               p_ptr->oldpx = current_floor_ptr->width - 2;
                                p_ptr->oldpy = y;
-                               ambush_flag = FALSE;
+                               p_ptr->ambush_flag = FALSE;
                        }
 
                        else if (x == MAX_WID - 1)
@@ -1196,11 +991,11 @@ void move_player(DIRECTION dir, bool do_pickup, bool break_trap)
                                p_ptr->wilderness_x++;
                                p_ptr->oldpx = 1;
                                p_ptr->oldpy = y;
-                               ambush_flag = FALSE;
+                               p_ptr->ambush_flag = FALSE;
                        }
 
                        p_ptr->leaving = TRUE;
-                       take_turn(p_ptr, 100);;
+                       take_turn(p_ptr, 100);
 
                        return;
                }
@@ -1210,10 +1005,10 @@ void move_player(DIRECTION dir, bool do_pickup, bool break_trap)
                p_can_enter = FALSE;
        }
 
-       m_ptr = &m_list[g_ptr->m_idx];
+       m_ptr = &current_floor_ptr->m_list[g_ptr->m_idx];
 
-       if (inventory[INVEN_RARM].name1 == ART_STORMBRINGER) stormbringer = TRUE;
-       if (inventory[INVEN_LARM].name1 == ART_STORMBRINGER) stormbringer = TRUE;
+       if (p_ptr->inventory_list[INVEN_RARM].name1 == ART_STORMBRINGER) stormbringer = TRUE;
+       if (p_ptr->inventory_list[INVEN_LARM].name1 == ART_STORMBRINGER) stormbringer = TRUE;
 
        /* Player can not walk through "walls"... */
        /* unless in Shadow Form */
@@ -1253,7 +1048,7 @@ void move_player(DIRECTION dir, bool do_pickup, bool break_trap)
                                py_attack(y, x, 0);
                                oktomove = FALSE;
                        }
-                       else if (monster_can_cross_terrain(grid_array[p_ptr->y][p_ptr->x].feat, r_ptr, 0))
+                       else if (monster_can_cross_terrain(current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].feat, r_ptr, 0))
                        {
                                do_past = TRUE;
                        }
@@ -1314,7 +1109,7 @@ void move_player(DIRECTION dir, bool do_pickup, bool break_trap)
                }
                else if (!have_flag(f_ptr->flags, FF_WATER) && (riding_r_ptr->flags7 & RF7_AQUATIC))
                {
-                       msg_format(_("%sから上がれない。", "Can't land."), f_name + f_info[get_feat_mimic(&grid_array[p_ptr->y][p_ptr->x])].name);
+                       msg_format(_("%sから上がれない。", "Can't land."), f_name + f_info[get_feat_mimic(&current_floor_ptr->grid_array[p_ptr->y][p_ptr->x])].name);
                        free_turn(p_ptr);
                        oktomove = FALSE;
                        disturb(FALSE, TRUE);
@@ -1345,7 +1140,7 @@ void move_player(DIRECTION dir, bool do_pickup, bool break_trap)
        {
                msg_format(_("空を飛ばないと%sの上には行けない。", "You need to fly to go through the %s."), f_name + f_info[get_feat_mimic(g_ptr)].name);
                free_turn(p_ptr);
-               running = 0;
+               p_ptr->running = 0;
                oktomove = FALSE;
        }
 
@@ -1432,7 +1227,7 @@ void move_player(DIRECTION dir, bool do_pickup, bool break_trap)
                                /*
                                 * Well, it makes sense that you lose time bumping into
                                 * a wall _if_ you are confused, stunned or blind; but
-                                * typing mistakes should not cost you a turn...
+                                * typing mistakes should not cost you a current_world_ptr->game_turn...
                                 */
                                if (!(p_ptr->confused || p_ptr->stun || p_ptr->image))
                                        free_turn(p_ptr);
@@ -1528,7 +1323,7 @@ static bool see_wall(DIRECTION dir, POSITION y, POSITION x)
        if (!in_bounds2(y, x)) return (FALSE);
 
        /* Access grid */
-       g_ptr = &grid_array[y][x];
+       g_ptr = &current_floor_ptr->grid_array[y][x];
 
        /* Must be known to the player */
        if (g_ptr->info & (CAVE_MARK))
@@ -1571,7 +1366,7 @@ static bool see_nothing(DIRECTION dir, POSITION y, POSITION x)
        if (!in_bounds2(y, x)) return (TRUE);
 
        /* Memorized grids are always known */
-       if (grid_array[y][x].info & (CAVE_MARK)) return (FALSE);
+       if (current_floor_ptr->grid_array[y][x].info & (CAVE_MARK)) return (FALSE);
 
        /* Viewable door/wall grids are known */
        if (player_can_see_bold(y, x)) return (FALSE);
@@ -1620,7 +1415,7 @@ static bool find_breakleft;
  * Diagonal Corridor -- allow diaginal entry into corridors.\n
  *\n
  * Blunt Corridor -- If there is a wall two spaces ahead and\n
- * we seem to be in a corridor, then force a turn into the side\n
+ * we seem to be in a corridor, then force a current_world_ptr->game_turn into the side\n
  * corridor, must be moving straight into a corridor here. ???\n
  *\n
  * Diagonal Corridor    Blunt Corridor (?)\n
@@ -1746,13 +1541,13 @@ static bool run_test(void)
 
        /* break run when leaving trap detected region */
        if ((disturb_trap_detect || alert_trap_detect)
-           && p_ptr->dtrap && !(grid_array[p_ptr->y][p_ptr->x].info & CAVE_IN_DETECT))
+           && p_ptr->dtrap && !(current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].info & CAVE_IN_DETECT))
        {
                /* No duplicate warning */
                p_ptr->dtrap = FALSE;
 
                /* You are just on the edge */
-               if (!(grid_array[p_ptr->y][p_ptr->x].info & CAVE_UNSAFE))
+               if (!(current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].info & CAVE_UNSAFE))
                {
                        if (alert_trap_detect)
                        {
@@ -1780,7 +1575,7 @@ static bool run_test(void)
                col = p_ptr->x + ddx[new_dir];
 
                /* Access grid */
-               g_ptr = &grid_array[row][col];
+               g_ptr = &current_floor_ptr->grid_array[row][col];
 
                /* Feature code (applying "mimic" field) */
                feat = get_feat_mimic(g_ptr);
@@ -1789,7 +1584,7 @@ static bool run_test(void)
                /* Visible monsters abort running */
                if (g_ptr->m_idx)
                {
-                       monster_type *m_ptr = &m_list[g_ptr->m_idx];
+                       monster_type *m_ptr = &current_floor_ptr->m_list[g_ptr->m_idx];
 
                        /* Visible monster */
                        if (m_ptr->ml) return (TRUE);
@@ -1799,9 +1594,7 @@ static bool run_test(void)
                for (this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx)
                {
                        object_type *o_ptr;
-                       o_ptr = &o_list[this_o_idx];
-
-                       /* Acquire next object */
+                       o_ptr = &current_floor_ptr->o_list[this_o_idx];
                        next_o_idx = o_ptr->next_o_idx;
 
                        /* Visible object */
@@ -2098,10 +1891,10 @@ void run_step(DIRECTION dir)
        }
 
        /* Decrease the run counter */
-       if (--running <= 0) return;
+       if (--p_ptr->running <= 0) return;
 
        /* Take time */
-       take_turn(p_ptr, 100);;
+       take_turn(p_ptr, 100);
 
        /* Move the player, using the "pickup" flag */
        move_player(find_current, FALSE, FALSE);
@@ -2139,13 +1932,13 @@ static DIRECTION travel_test(DIRECTION prev_dir)
 
        /* break run when leaving trap detected region */
        if ((disturb_trap_detect || alert_trap_detect)
-           && p_ptr->dtrap && !(grid_array[p_ptr->y][p_ptr->x].info & CAVE_IN_DETECT))
+           && p_ptr->dtrap && !(current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].info & CAVE_IN_DETECT))
        {
                /* No duplicate warning */
                p_ptr->dtrap = FALSE;
 
                /* You are just on the edge */
-               if (!(grid_array[p_ptr->y][p_ptr->x].info & CAVE_UNSAFE))
+               if (!(current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].info & CAVE_UNSAFE))
                {
                        if (alert_trap_detect)
                        {
@@ -2174,12 +1967,12 @@ static DIRECTION travel_test(DIRECTION prev_dir)
                POSITION col = p_ptr->x + ddx[dir];
 
                /* Access grid */
-               g_ptr = &grid_array[row][col];
+               g_ptr = &current_floor_ptr->grid_array[row][col];
 
                /* Visible monsters abort running */
                if (g_ptr->m_idx)
                {
-                       monster_type *m_ptr = &m_list[g_ptr->m_idx];
+                       monster_type *m_ptr = &current_floor_ptr->m_list[g_ptr->m_idx];
 
                        /* Visible monster */
                        if (m_ptr->ml) return (0);
@@ -2204,7 +1997,7 @@ static DIRECTION travel_test(DIRECTION prev_dir)
        if (!new_dir) return (0);
 
        /* Access newly move grid */
-       g_ptr = &grid_array[p_ptr->y+ddy[new_dir]][p_ptr->x+ddx[new_dir]];
+       g_ptr = &current_floor_ptr->grid_array[p_ptr->y+ddy[new_dir]][p_ptr->x+ddx[new_dir]];
 
        /* Close door abort traveling */
        if (!easy_open && is_closed_door(g_ptr->feat)) return (0);
@@ -2238,7 +2031,7 @@ void travel_step(void)
                return;
        }
 
-       take_turn(p_ptr, 100);;
+       take_turn(p_ptr, 100);
 
        move_player(travel.dir, always_pickup, FALSE);
 
@@ -2275,9 +2068,9 @@ void forget_travel_flow(void)
 {
        POSITION x, y;
        /* Check the entire dungeon / Forget the old data */
-       for (y = 0; y < cur_hgt; y++)
+       for (y = 0; y < current_floor_ptr->height; y++)
        {
-               for (x = 0; x < cur_wid; x++)
+               for (x = 0; x < current_floor_ptr->width; x++)
                {
 
                        travel.cost[y][x] = MAX_SHORT;
@@ -2294,7 +2087,7 @@ void forget_travel_flow(void)
  */
 static int travel_flow_cost(POSITION y, POSITION x)
 {
-       feature_type *f_ptr = &f_info[grid_array[y][x].feat];
+       feature_type *f_ptr = &f_info[current_floor_ptr->grid_array[y][x].feat];
        int cost = 1;
 
        /* Avoid obstacles (ex. trees) */
@@ -2318,7 +2111,7 @@ static int travel_flow_cost(POSITION y, POSITION x)
        }
 
        /* Detected traps and doors */
-       if (grid_array[y][x].info & (CAVE_MARK))
+       if (current_floor_ptr->grid_array[y][x].info & (CAVE_MARK))
        {
                if (have_flag(f_ptr->flags, FF_DOOR)) cost += 1;
                if (have_flag(f_ptr->flags, FF_TRAP)) cost += 10;
@@ -2337,7 +2130,7 @@ static int travel_flow_cost(POSITION y, POSITION x)
  */
 static void travel_flow_aux(POSITION y, POSITION x, int n, bool wall)
 {
-       grid_type *g_ptr = &grid_array[y][x];
+       grid_type *g_ptr = &current_floor_ptr->grid_array[y][x];
        feature_type *f_ptr = &f_info[g_ptr->feat];
        int old_head = flow_head;
        int add_cost = 1;
@@ -2349,12 +2142,12 @@ static void travel_flow_aux(POSITION y, POSITION x, int n, bool wall)
        if (!in_bounds(y, x)) return;
 
        /* Ignore unknown grid except in wilderness */
-       if (dun_level > 0 && !(g_ptr->info & CAVE_KNOWN)) return;
+       if (current_floor_ptr->dun_level > 0 && !(g_ptr->info & CAVE_KNOWN)) return;
 
        /* Ignore "walls" and "rubble" (include "secret doors") */
        if (have_flag(f_ptr->flags, FF_WALL) ||
                have_flag(f_ptr->flags, FF_CAN_DIG) ||
-               (have_flag(f_ptr->flags, FF_DOOR) && grid_array[y][x].mimic) ||
+               (have_flag(f_ptr->flags, FF_DOOR) && current_floor_ptr->grid_array[y][x].mimic) ||
                (!have_flag(f_ptr->flags, FF_MOVE) && have_flag(f_ptr->flags, FF_CAN_FLY) && !p_ptr->levitation))
        {
                if (!wall || !from_wall) return;
@@ -2397,7 +2190,7 @@ static void travel_flow(POSITION ty, POSITION tx)
        POSITION x, y;
        DIRECTION d;
        bool wall = FALSE;
-       feature_type *f_ptr = &f_info[grid_array[p_ptr->y][p_ptr->x].feat];
+       feature_type *f_ptr = &f_info[current_floor_ptr->grid_array[p_ptr->y][p_ptr->x].feat];
 
        /* Reset the "queue" */
        flow_head = flow_tail = 0;
@@ -2458,12 +2251,12 @@ void do_cmd_travel(void)
                return;
        }
 
-       f_ptr = &f_info[grid_array[y][x].feat];
+       f_ptr = &f_info[current_floor_ptr->grid_array[y][x].feat];
 
-       if ((grid_array[y][x].info & CAVE_MARK) &&
+       if ((current_floor_ptr->grid_array[y][x].info & CAVE_MARK) &&
                (have_flag(f_ptr->flags, FF_WALL) ||
                        have_flag(f_ptr->flags, FF_CAN_DIG) ||
-                       (have_flag(f_ptr->flags, FF_DOOR) && grid_array[y][x].mimic)))
+                       (have_flag(f_ptr->flags, FF_DOOR) && current_floor_ptr->grid_array[y][x].mimic)))
        {
                msg_print(_("そこには行くことができません!", "You cannot travel there!"));
                return;
@@ -2477,8 +2270,6 @@ void do_cmd_travel(void)
 
        /* Travel till 255 steps */
        travel.run = 255;
-
-       /* Paranoia */
        travel.dir = 0;
 
        /* Decides first direction */
@@ -2493,3 +2284,70 @@ void do_cmd_travel(void)
        }
 }
 #endif
+
+/*
+ * Something has happened to disturb the player.
+ * The first arg indicates a major disturbance, which affects search.
+ * The second arg is currently unused, but could induce output flush.
+ * All disturbance cancels repeated commands, resting, and running.
+ */
+void disturb(bool stop_search, bool stop_travel)
+{
+#ifndef TRAVEL
+       /* Unused */
+       stop_travel = stop_travel;
+#endif
+
+       /* Cancel auto-commands */
+       /* command_new = 0; */
+
+       /* Cancel repeated commands */
+       if (command_rep)
+       {
+               /* Cancel */
+               command_rep = 0;
+
+               /* Redraw the state (later) */
+               p_ptr->redraw |= (PR_STATE);
+       }
+
+       /* Cancel Resting */
+       if ((p_ptr->action == ACTION_REST) || (p_ptr->action == ACTION_FISH) || (stop_search && (p_ptr->action == ACTION_SEARCH)))
+       {
+               /* Cancel */
+               set_action(ACTION_NONE);
+       }
+
+       /* Cancel running */
+       if (p_ptr->running)
+       {
+               /* Cancel */
+               p_ptr->running = 0;
+
+               /* Check for new panel if appropriate */
+               if (center_player && !center_running) verify_panel();
+
+               /* Calculate torch radius */
+               p_ptr->update |= (PU_TORCH);
+
+               /* Update monster flow */
+               p_ptr->update |= (PU_FLOW);
+       }
+
+#ifdef TRAVEL
+       if (stop_travel)
+       {
+               /* Cancel */
+               travel.run = 0;
+
+               /* Check for new panel if appropriate */
+               if (center_player && !center_running) verify_panel();
+
+               /* Calculate torch radius */
+               p_ptr->update |= (PU_TORCH);
+       }
+#endif
+
+       /* Flush the input if requested */
+       if (flush_disturb) flush();
+}