OSDN Git Service

41185846257291782851b4d59c54265345ebe29d
[hengband/hengband.git] / src / player / player-move.c
1 /*!
2  *  @brief プレイヤーの移動処理 / Movement commands
3  *  @date 2014/01/02
4  *  @author
5  *  Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
6  */
7
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"
41
42 int flow_head = 0;
43 int flow_tail = 0;
44 POSITION temp2_x[MAX_SHORT];
45 POSITION temp2_y[MAX_SHORT];
46
47 /*!
48  * @brief 地形やその上のアイテムの隠された要素を全て明かす /
49  * Search for hidden things
50  * @param creature_ptr プレーヤーへの参照ポインタ
51  * @param y 対象となるマスのY座標
52  * @param x 対象となるマスのX座標
53  * @return なし
54  */
55 static void discover_hidden_things(player_type *creature_ptr, POSITION y, POSITION x)
56 {
57     grid_type *g_ptr;
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);
64     }
65
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);
70     }
71
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) {
74         object_type *o_ptr;
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)
78             continue;
79         if (!chest_traps[o_ptr->pval])
80             continue;
81         if (!object_is_known(o_ptr)) {
82             msg_print(_("箱に仕掛けられたトラップを発見した!", "You have discovered a trap on the chest!"));
83             object_known(o_ptr);
84             disturb(creature_ptr, FALSE, FALSE);
85         }
86     }
87 }
88
89 /*!
90  * @brief プレイヤーの探索処理判定
91  * @param creature_ptr プレーヤーへの参照ポインタ
92  * @return なし
93  */
94 void search(player_type *creature_ptr)
95 {
96     PERCENTAGE chance = creature_ptr->skill_srh;
97     if (creature_ptr->blind || no_lite(creature_ptr))
98         chance = chance / 10;
99
100     if (creature_ptr->confused || creature_ptr->image)
101         chance = chance / 10;
102
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]);
106 }
107
108 /*!
109  * @brief 移動に伴うプレイヤーのステータス変化処理
110  * @param creature_ptr プレーヤーへの参照ポインタ
111  * @param ny 移動先Y座標
112  * @param nx 移動先X座標
113  * @param mpe_mode 移動オプションフラグ
114  * @return プレイヤーが死亡やフロア離脱を行わず、実際に移動が可能ならばTRUEを返す。
115  */
116 bool move_player_effect(player_type *creature_ptr, POSITION ny, POSITION nx, BIT_FLAGS mpe_mode)
117 {
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];
125
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;
134             if (om_idx > 0) {
135                 monster_type *om_ptr = &floor_ptr->m_list[om_idx];
136                 om_ptr->fy = ny;
137                 om_ptr->fx = nx;
138                 update_monster(creature_ptr, om_idx, TRUE);
139             }
140
141             if (nm_idx > 0) {
142                 monster_type *nm_ptr = &floor_ptr->m_list[nm_idx];
143                 nm_ptr->fy = oy;
144                 nm_ptr->fx = ox;
145                 update_monster(creature_ptr, nm_idx, TRUE);
146             }
147         }
148
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;
156         }
157
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);
162
163         if (floor_ptr->dun_level && (d_info[creature_ptr->dungeon_idx].flags1 & DF1_FORGET))
164             wiz_dark(creature_ptr);
165
166         if (mpe_mode & MPE_HANDLE_STUFF)
167             handle_stuff(creature_ptr);
168
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);
174         }
175
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);
180         }
181
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);
186             }
187         }
188     }
189
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)
194                 return FALSE;
195         }
196
197         if ((creature_ptr->skill_fos >= 50) || (0 == randint0(50 - creature_ptr->skill_fos)))
198             search(creature_ptr);
199
200         if (creature_ptr->action == ACTION_SEARCH)
201             search(creature_ptr);
202     }
203
204     if (!(mpe_mode & MPE_DONT_PICKUP))
205         carry(creature_ptr, (mpe_mode & MPE_DO_PICKUP) ? TRUE : FALSE);
206
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);
222
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);
234         }
235
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)
238             return FALSE;
239     }
240
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!*"));
246
247             if (disturb_trap_detect)
248                 disturb(creature_ptr, FALSE, TRUE);
249         }
250     }
251
252     return player_bold(creature_ptr, ny, nx) && !creature_ptr->is_dead && !creature_ptr->leaving;
253 }
254
255 /*!
256  * @brief 該当地形のトラップがプレイヤーにとって無効かどうかを判定して返す
257  * @param creature_ptr プレーヤーへの参照ポインタ
258  * @param feat 地形ID
259  * @return トラップが自動的に無効ならばTRUEを返す
260  */
261 bool trap_can_be_ignored(player_type *creature_ptr, FEAT_IDX feat)
262 {
263     feature_type *f_ptr = &f_info[feat];
264     if (!has_flag(f_ptr->flags, FF_TRAP))
265         return TRUE;
266
267     switch (f_ptr->subtype) {
268     case TRAP_TRAPDOOR:
269     case TRAP_PIT:
270     case TRAP_SPIKED_PIT:
271     case TRAP_POISON_PIT:
272         if (creature_ptr->levitation)
273             return TRUE;
274         break;
275     case TRAP_TELEPORT:
276         if (creature_ptr->anti_tele)
277             return TRUE;
278         break;
279     case TRAP_FIRE:
280         if (creature_ptr->immune_fire)
281             return TRUE;
282         break;
283     case TRAP_ACID:
284         if (creature_ptr->immune_acid)
285             return TRUE;
286         break;
287     case TRAP_BLIND:
288         if (creature_ptr->resist_blind)
289             return TRUE;
290         break;
291     case TRAP_CONFUSE:
292         if (creature_ptr->resist_conf)
293             return TRUE;
294         break;
295     case TRAP_POISON:
296         if (creature_ptr->resist_pois)
297             return TRUE;
298         break;
299     case TRAP_SLEEP:
300         if (creature_ptr->free_act)
301             return TRUE;
302         break;
303     }
304
305     return FALSE;
306 }