2 * @brief プレイヤーの移動処理 / Movement commands
5 * Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
8 #include "player/player-move.h"
9 #include "core/disturbance.h"
10 #include "core/player-redraw-types.h"
11 #include "core/player-update-types.h"
12 #include "core/special-internal-keys.h"
13 #include "core/stuff-handler.h"
14 #include "core/window-redrawer.h"
15 #include "dungeon/dungeon-flag-types.h"
16 #include "dungeon/dungeon.h"
17 #include "dungeon/quest.h"
18 #include "effect/effect-characteristics.h"
19 #include "effect/effect-processor.h"
20 #include "floor/cave.h"
21 #include "floor/floor-util.h"
22 #include "game-option/disturbance-options.h"
23 #include "grid/feature.h"
24 #include "grid/grid.h"
25 #include "grid/trap.h"
26 #include "inventory/player-inventory.h"
27 #include "io/input-key-requester.h"
28 #include "mind/mind-ninja.h"
29 #include "monster/monster-update.h"
30 #include "perception/object-perception.h"
31 #include "player/attack-defense-types.h"
32 #include "realm/realm-song-numbers.h"
33 #include "spell-kind/spells-floor.h"
34 #include "spell/spell-types.h"
35 #include "status/action-setter.h"
36 #include "system/floor-type-definition.h"
37 #include "system/object-type-definition.h"
38 #include "target/target-checker.h"
39 #include "util/bit-flags-calculator.h"
40 #include "view/display-messages.h"
44 POSITION temp2_x[MAX_SHORT];
45 POSITION temp2_y[MAX_SHORT];
48 * @brief 地形やその上のアイテムの隠された要素を全て明かす /
49 * Search for hidden things
50 * @param creature_ptr プレーヤーへの参照ポインタ
51 * @param y 対象となるマスのY座標
52 * @param x 対象となるマスのX座標
55 static void discover_hidden_things(player_type *creature_ptr, POSITION y, POSITION x)
58 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
59 g_ptr = &floor_ptr->grid_array[y][x];
60 if (g_ptr->mimic && is_trap(creature_ptr, g_ptr->feat)) {
61 disclose_grid(creature_ptr, y, x);
62 msg_print(_("トラップを発見した。", "You have found a trap."));
63 disturb(creature_ptr, FALSE, TRUE);
66 if (is_hidden_door(creature_ptr, g_ptr)) {
67 msg_print(_("隠しドアを発見した。", "You have found a secret door."));
68 disclose_grid(creature_ptr, y, x);
69 disturb(creature_ptr, FALSE, FALSE);
72 OBJECT_IDX next_o_idx = 0;
73 for (OBJECT_IDX this_o_idx = g_ptr->o_idx; this_o_idx; this_o_idx = next_o_idx) {
75 o_ptr = &floor_ptr->o_list[this_o_idx];
76 next_o_idx = o_ptr->next_o_idx;
77 if (o_ptr->tval != TV_CHEST)
79 if (!chest_traps[o_ptr->pval])
81 if (!object_is_known(o_ptr)) {
82 msg_print(_("箱に仕掛けられたトラップを発見した!", "You have discovered a trap on the chest!"));
84 disturb(creature_ptr, FALSE, FALSE);
91 * @param creature_ptr プレーヤーへの参照ポインタ
94 void search(player_type *creature_ptr)
96 PERCENTAGE chance = creature_ptr->skill_srh;
97 if (creature_ptr->blind || no_lite(creature_ptr))
100 if (creature_ptr->confused || creature_ptr->image)
101 chance = chance / 10;
103 for (DIRECTION i = 0; i < 9; ++i)
104 if (randint0(100) < chance)
105 discover_hidden_things(creature_ptr, creature_ptr->y + ddy_ddd[i], creature_ptr->x + ddx_ddd[i]);
109 * @brief 移動に伴うプレイヤーのステータス変化処理
110 * @param creature_ptr プレーヤーへの参照ポインタ
113 * @param mpe_mode 移動オプションフラグ
114 * @return プレイヤーが死亡やフロア離脱を行わず、実際に移動が可能ならばTRUEを返す。
116 bool move_player_effect(player_type *creature_ptr, POSITION ny, POSITION nx, BIT_FLAGS mpe_mode)
118 POSITION oy = creature_ptr->y;
119 POSITION ox = creature_ptr->x;
120 floor_type *floor_ptr = creature_ptr->current_floor_ptr;
121 grid_type *g_ptr = &floor_ptr->grid_array[ny][nx];
122 grid_type *oc_ptr = &floor_ptr->grid_array[oy][ox];
123 feature_type *f_ptr = &f_info[g_ptr->feat];
124 feature_type *of_ptr = &f_info[oc_ptr->feat];
126 if (!(mpe_mode & MPE_STAYING)) {
127 MONSTER_IDX om_idx = oc_ptr->m_idx;
128 MONSTER_IDX nm_idx = g_ptr->m_idx;
129 creature_ptr->y = ny;
130 creature_ptr->x = nx;
131 if (!(mpe_mode & MPE_DONT_SWAP_MON)) {
132 g_ptr->m_idx = om_idx;
133 oc_ptr->m_idx = nm_idx;
135 monster_type *om_ptr = &floor_ptr->m_list[om_idx];
138 update_monster(creature_ptr, om_idx, TRUE);
142 monster_type *nm_ptr = &floor_ptr->m_list[nm_idx];
145 update_monster(creature_ptr, nm_idx, TRUE);
149 lite_spot(creature_ptr, oy, ox);
150 lite_spot(creature_ptr, ny, nx);
151 verify_panel(creature_ptr);
152 if (mpe_mode & MPE_FORGET_FLOW) {
153 forget_flow(floor_ptr);
154 creature_ptr->update |= PU_UN_VIEW;
155 creature_ptr->redraw |= PR_MAP;
158 creature_ptr->update |= PU_VIEW | PU_LITE | PU_FLOW | PU_MON_LITE | PU_DISTANCE;
159 creature_ptr->window |= PW_OVERHEAD | PW_DUNGEON;
160 if ((!creature_ptr->blind && !no_lite(creature_ptr)) || !is_trap(creature_ptr, g_ptr->feat))
161 g_ptr->info &= ~(CAVE_UNSAFE);
163 if (floor_ptr->dun_level && (d_info[creature_ptr->dungeon_idx].flags1 & DF1_FORGET))
164 wiz_dark(creature_ptr);
166 if (mpe_mode & MPE_HANDLE_STUFF)
167 handle_stuff(creature_ptr);
169 if (creature_ptr->pclass == CLASS_NINJA) {
170 if (g_ptr->info & (CAVE_GLOW))
171 set_superstealth(creature_ptr, FALSE);
172 else if (creature_ptr->cur_lite <= 0)
173 set_superstealth(creature_ptr, TRUE);
176 if ((creature_ptr->action == ACTION_HAYAGAKE)
177 && (!has_flag(f_ptr->flags, FF_PROJECT) || (!creature_ptr->levitation && has_flag(f_ptr->flags, FF_DEEP)))) {
178 msg_print(_("ここでは素早く動けない。", "You cannot run in here."));
179 set_action(creature_ptr, ACTION_NONE);
182 if (creature_ptr->prace == RACE_MERFOLK) {
183 if (has_flag(f_ptr->flags, FF_WATER) ^ has_flag(of_ptr->flags, FF_WATER)) {
184 creature_ptr->update |= PU_BONUS;
185 update_creature(creature_ptr);
190 if (mpe_mode & MPE_ENERGY_USE) {
191 if (music_singing(creature_ptr, MUSIC_WALL)) {
192 (void)project(creature_ptr, 0, 0, creature_ptr->y, creature_ptr->x, (60 + creature_ptr->lev), GF_DISINTEGRATE, PROJECT_KILL | PROJECT_ITEM, -1);
193 if (!player_bold(creature_ptr, ny, nx) || creature_ptr->is_dead || creature_ptr->leaving)
197 if ((creature_ptr->skill_fos >= 50) || (0 == randint0(50 - creature_ptr->skill_fos)))
198 search(creature_ptr);
200 if (creature_ptr->action == ACTION_SEARCH)
201 search(creature_ptr);
204 if (!(mpe_mode & MPE_DONT_PICKUP))
205 carry(creature_ptr, (mpe_mode & MPE_DO_PICKUP) ? TRUE : FALSE);
207 if (has_flag(f_ptr->flags, FF_STORE)) {
208 disturb(creature_ptr, FALSE, TRUE);
209 free_turn(creature_ptr);
210 command_new = SPECIAL_KEY_STORE;
211 } else if (has_flag(f_ptr->flags, FF_BLDG)) {
212 disturb(creature_ptr, FALSE, TRUE);
213 free_turn(creature_ptr);
214 command_new = SPECIAL_KEY_BUILDING;
215 } else if (has_flag(f_ptr->flags, FF_QUEST_ENTER)) {
216 disturb(creature_ptr, FALSE, TRUE);
217 free_turn(creature_ptr);
218 command_new = SPECIAL_KEY_QUEST;
219 } else if (has_flag(f_ptr->flags, FF_QUEST_EXIT)) {
220 if (quest[floor_ptr->inside_quest].type == QUEST_TYPE_FIND_EXIT)
221 complete_quest(creature_ptr, floor_ptr->inside_quest);
223 leave_quest_check(creature_ptr);
224 floor_ptr->inside_quest = g_ptr->special;
225 floor_ptr->dun_level = 0;
226 creature_ptr->oldpx = 0;
227 creature_ptr->oldpy = 0;
228 creature_ptr->leaving = TRUE;
229 } else if (has_flag(f_ptr->flags, FF_HIT_TRAP) && !(mpe_mode & MPE_STAYING)) {
230 disturb(creature_ptr, FALSE, TRUE);
231 if (g_ptr->mimic || has_flag(f_ptr->flags, FF_SECRET)) {
232 msg_print(_("トラップだ!", "You found a trap!"));
233 disclose_grid(creature_ptr, creature_ptr->y, creature_ptr->x);
236 hit_trap(creature_ptr, (mpe_mode & MPE_BREAK_TRAP) ? TRUE : FALSE);
237 if (!player_bold(creature_ptr, ny, nx) || creature_ptr->is_dead || creature_ptr->leaving)
241 if (!(mpe_mode & MPE_STAYING) && (disturb_trap_detect || alert_trap_detect) && creature_ptr->dtrap && !(g_ptr->info & CAVE_IN_DETECT)) {
242 creature_ptr->dtrap = FALSE;
243 if (!(g_ptr->info & CAVE_UNSAFE)) {
244 if (alert_trap_detect)
245 msg_print(_("* 注意:この先はトラップの感知範囲外です! *", "*Leaving trap detect region!*"));
247 if (disturb_trap_detect)
248 disturb(creature_ptr, FALSE, TRUE);
252 return player_bold(creature_ptr, ny, nx) && !creature_ptr->is_dead && !creature_ptr->leaving;
256 * @brief 該当地形のトラップがプレイヤーにとって無効かどうかを判定して返す
257 * @param creature_ptr プレーヤーへの参照ポインタ
259 * @return トラップが自動的に無効ならばTRUEを返す
261 bool trap_can_be_ignored(player_type *creature_ptr, FEAT_IDX feat)
263 feature_type *f_ptr = &f_info[feat];
264 if (!has_flag(f_ptr->flags, FF_TRAP))
267 switch (f_ptr->subtype) {
270 case TRAP_SPIKED_PIT:
271 case TRAP_POISON_PIT:
272 if (creature_ptr->levitation)
276 if (creature_ptr->anti_tele)
280 if (creature_ptr->immune_fire)
284 if (creature_ptr->immune_acid)
288 if (creature_ptr->resist_blind)
292 if (creature_ptr->resist_conf)
296 if (creature_ptr->resist_pois)
300 if (creature_ptr->free_act)