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/geometry.h"
22 #include "floor/floor-util.h"
23 #include "game-option/disturbance-options.h"
24 #include "grid/feature.h"
25 #include "grid/grid.h"
26 #include "grid/trap.h"
27 #include "inventory/player-inventory.h"
28 #include "io/input-key-requester.h"
29 #include "mind/mind-ninja.h"
30 #include "monster/monster-update.h"
31 #include "perception/object-perception.h"
32 #include "player-status/player-energy.h"
33 #include "player/attack-defense-types.h"
34 #include "player/player-status-flags.h"
35 #include "player/player-status.h"
36 #include "realm/realm-song-numbers.h"
37 #include "spell-kind/spells-floor.h"
38 #include "spell-realm/spells-song.h"
39 #include "effect/attribute-types.h"
40 #include "status/action-setter.h"
41 #include "system/floor-type-definition.h"
42 #include "system/grid-type-definition.h"
43 #include "system/monster-type-definition.h"
44 #include "system/object-type-definition.h"
45 #include "system/player-type-definition.h"
46 #include "target/target-checker.h"
47 #include "util/bit-flags-calculator.h"
48 #include "util/enum-converter.h"
49 #include "view/display-messages.h"
53 POSITION temp2_x[MAX_SHORT];
54 POSITION temp2_y[MAX_SHORT];
57 * @brief 地形やその上のアイテムの隠された要素を全て明かす /
58 * Search for hidden things
59 * @param player_ptr プレイヤーへの参照ポインタ
60 * @param y 対象となるマスのY座標
61 * @param x 対象となるマスのX座標
63 static void discover_hidden_things(PlayerType *player_ptr, POSITION y, POSITION x)
66 floor_type *floor_ptr = player_ptr->current_floor_ptr;
67 g_ptr = &floor_ptr->grid_array[y][x];
68 if (g_ptr->mimic && is_trap(player_ptr, g_ptr->feat)) {
69 disclose_grid(player_ptr, y, x);
70 msg_print(_("トラップを発見した。", "You have found a trap."));
71 disturb(player_ptr, false, true);
74 if (is_hidden_door(player_ptr, g_ptr)) {
75 msg_print(_("隠しドアを発見した。", "You have found a secret door."));
76 disclose_grid(player_ptr, y, x);
77 disturb(player_ptr, false, false);
80 for (const auto this_o_idx : g_ptr->o_idx_list) {
82 o_ptr = &floor_ptr->o_list[this_o_idx];
83 if (o_ptr->tval != ItemKindType::CHEST)
85 if (chest_traps[o_ptr->pval].none())
87 if (!o_ptr->is_known()) {
88 msg_print(_("箱に仕掛けられたトラップを発見した!", "You have discovered a trap on the chest!"));
90 disturb(player_ptr, false, false);
97 * @param player_ptr プレイヤーへの参照ポインタ
99 void search(PlayerType *player_ptr)
101 PERCENTAGE chance = player_ptr->skill_srh;
102 if (player_ptr->blind || no_lite(player_ptr))
103 chance = chance / 10;
105 if (player_ptr->confused || player_ptr->hallucinated)
106 chance = chance / 10;
108 for (DIRECTION i = 0; i < 9; ++i)
109 if (randint0(100) < chance)
110 discover_hidden_things(player_ptr, player_ptr->y + ddy_ddd[i], player_ptr->x + ddx_ddd[i]);
114 * @brief 移動に伴うプレイヤーのステータス変化処理
115 * @param player_ptr プレイヤーへの参照ポインタ
118 * @param mpe_mode 移動オプションフラグ
119 * @return プレイヤーが死亡やフロア離脱を行わず、実際に移動が可能ならばTRUEを返す。
121 bool move_player_effect(PlayerType *player_ptr, POSITION ny, POSITION nx, BIT_FLAGS mpe_mode)
123 POSITION oy = player_ptr->y;
124 POSITION ox = player_ptr->x;
125 floor_type *floor_ptr = player_ptr->current_floor_ptr;
126 grid_type *g_ptr = &floor_ptr->grid_array[ny][nx];
127 grid_type *oc_ptr = &floor_ptr->grid_array[oy][ox];
128 feature_type *f_ptr = &f_info[g_ptr->feat];
129 feature_type *of_ptr = &f_info[oc_ptr->feat];
131 if (!(mpe_mode & MPE_STAYING)) {
132 MONSTER_IDX om_idx = oc_ptr->m_idx;
133 MONSTER_IDX nm_idx = g_ptr->m_idx;
136 if (!(mpe_mode & MPE_DONT_SWAP_MON)) {
137 g_ptr->m_idx = om_idx;
138 oc_ptr->m_idx = nm_idx;
140 monster_type *om_ptr = &floor_ptr->m_list[om_idx];
143 update_monster(player_ptr, om_idx, true);
147 monster_type *nm_ptr = &floor_ptr->m_list[nm_idx];
150 update_monster(player_ptr, nm_idx, true);
154 lite_spot(player_ptr, oy, ox);
155 lite_spot(player_ptr, ny, nx);
156 verify_panel(player_ptr);
157 if (mpe_mode & MPE_FORGET_FLOW) {
158 forget_flow(floor_ptr);
159 player_ptr->update |= PU_UN_VIEW;
160 player_ptr->redraw |= PR_MAP;
163 player_ptr->update |= PU_VIEW | PU_LITE | PU_FLOW | PU_MON_LITE | PU_DISTANCE;
164 player_ptr->window_flags |= PW_OVERHEAD | PW_DUNGEON;
165 if ((!player_ptr->blind && !no_lite(player_ptr)) || !is_trap(player_ptr, g_ptr->feat))
166 g_ptr->info &= ~(CAVE_UNSAFE);
168 if (floor_ptr->dun_level && d_info[player_ptr->dungeon_idx].flags.has(DungeonFeatureType::FORGET))
169 wiz_dark(player_ptr);
171 if (mpe_mode & MPE_HANDLE_STUFF)
172 handle_stuff(player_ptr);
174 if (player_ptr->pclass == PlayerClassType::NINJA) {
175 if (g_ptr->info & (CAVE_GLOW))
176 set_superstealth(player_ptr, false);
177 else if (player_ptr->cur_lite <= 0)
178 set_superstealth(player_ptr, true);
181 if ((player_ptr->action == ACTION_HAYAGAKE)
182 && (f_ptr->flags.has_not(FloorFeatureType::PROJECT) || (!player_ptr->levitation && f_ptr->flags.has(FloorFeatureType::DEEP)))) {
183 msg_print(_("ここでは素早く動けない。", "You cannot run in here."));
184 set_action(player_ptr, ACTION_NONE);
187 if (player_ptr->prace == PlayerRaceType::MERFOLK) {
188 if (f_ptr->flags.has(FloorFeatureType::WATER) ^ of_ptr->flags.has(FloorFeatureType::WATER)) {
189 player_ptr->update |= PU_BONUS;
190 update_creature(player_ptr);
195 if (mpe_mode & MPE_ENERGY_USE) {
196 if (music_singing(player_ptr, MUSIC_WALL)) {
197 (void)project(player_ptr, 0, 0, player_ptr->y, player_ptr->x, (60 + player_ptr->lev), AttributeType::DISINTEGRATE, PROJECT_KILL | PROJECT_ITEM);
198 if (!player_bold(player_ptr, ny, nx) || player_ptr->is_dead || player_ptr->leaving)
202 if ((player_ptr->skill_fos >= 50) || (0 == randint0(50 - player_ptr->skill_fos)))
205 if (player_ptr->action == ACTION_SEARCH)
209 if (!(mpe_mode & MPE_DONT_PICKUP))
210 carry(player_ptr, any_bits(mpe_mode, MPE_DO_PICKUP));
212 if (!player_ptr->running) {
213 // 自動拾い/自動破壊により床上のアイテムリストが変化した可能性があるので表示を更新
214 set_bits(player_ptr->window_flags, PW_FLOOR_ITEM_LIST);
215 window_stuff(player_ptr);
218 PlayerEnergy energy(player_ptr);
219 if (f_ptr->flags.has(FloorFeatureType::STORE)) {
220 disturb(player_ptr, false, true);
221 energy.reset_player_turn();
222 command_new = SPECIAL_KEY_STORE;
223 } else if (f_ptr->flags.has(FloorFeatureType::BLDG)) {
224 disturb(player_ptr, false, true);
225 energy.reset_player_turn();
226 command_new = SPECIAL_KEY_BUILDING;
227 } else if (f_ptr->flags.has(FloorFeatureType::QUEST_ENTER)) {
228 disturb(player_ptr, false, true);
229 energy.reset_player_turn();
230 command_new = SPECIAL_KEY_QUEST;
231 } else if (f_ptr->flags.has(FloorFeatureType::QUEST_EXIT)) {
232 if (quest[floor_ptr->inside_quest].type == QuestKindType::FIND_EXIT)
233 complete_quest(player_ptr, floor_ptr->inside_quest);
235 leave_quest_check(player_ptr);
236 floor_ptr->inside_quest = g_ptr->special;
237 floor_ptr->dun_level = 0;
238 if (!floor_ptr->inside_quest)
239 player_ptr->word_recall = 0;
240 player_ptr->oldpx = 0;
241 player_ptr->oldpy = 0;
242 player_ptr->leaving = true;
243 } else if (f_ptr->flags.has(FloorFeatureType::HIT_TRAP) && !(mpe_mode & MPE_STAYING)) {
244 disturb(player_ptr, false, true);
245 if (g_ptr->mimic || f_ptr->flags.has(FloorFeatureType::SECRET)) {
246 msg_print(_("トラップだ!", "You found a trap!"));
247 disclose_grid(player_ptr, player_ptr->y, player_ptr->x);
250 hit_trap(player_ptr, any_bits(mpe_mode, MPE_BREAK_TRAP));
251 if (!player_bold(player_ptr, ny, nx) || player_ptr->is_dead || player_ptr->leaving)
255 if (!(mpe_mode & MPE_STAYING) && (disturb_trap_detect || alert_trap_detect) && player_ptr->dtrap && !(g_ptr->info & CAVE_IN_DETECT)) {
256 player_ptr->dtrap = false;
257 if (!(g_ptr->info & CAVE_UNSAFE)) {
258 if (alert_trap_detect)
259 msg_print(_("* 注意:この先はトラップの感知範囲外です! *", "*Leaving trap detect region!*"));
261 if (disturb_trap_detect)
262 disturb(player_ptr, false, true);
266 return player_bold(player_ptr, ny, nx) && !player_ptr->is_dead && !player_ptr->leaving;
270 * @brief 該当地形のトラップがプレイヤーにとって無効かどうかを判定して返す
271 * @param player_ptr プレイヤーへの参照ポインタ
273 * @return トラップが自動的に無効ならばTRUEを返す
275 bool trap_can_be_ignored(PlayerType *player_ptr, FEAT_IDX feat)
277 feature_type *f_ptr = &f_info[feat];
278 if (f_ptr->flags.has_not(FloorFeatureType::TRAP))
281 switch (i2enum<TrapType>(f_ptr->subtype)) {
282 case TrapType::TRAPDOOR:
284 case TrapType::SPIKED_PIT:
285 case TrapType::POISON_PIT:
286 if (player_ptr->levitation)
289 case TrapType::TELEPORT:
290 if (player_ptr->anti_tele)
294 if (has_immune_fire(player_ptr))
298 if (has_immune_acid(player_ptr))
301 case TrapType::BLIND:
302 if (has_resist_blind(player_ptr))
305 case TrapType::CONFUSE:
306 if (has_resist_conf(player_ptr))
309 case TrapType::POISON:
310 if (has_resist_pois(player_ptr))
313 case TrapType::SLEEP:
314 if (player_ptr->free_act)