1 #include "target/target-getter.h"
2 #include "core/asking-player.h"
3 #include "effect/spells-effect-util.h"
4 #include "floor/geometry.h"
5 #include "game-option/input-options.h"
6 #include "io/command-repeater.h"
7 #include "io/input-key-requester.h"
8 #include "main/sound-of-music.h"
9 #include "monster-race/monster-race.h"
10 #include "monster-race/race-flags1.h"
11 #include "monster/monster-describer.h"
12 #include "monster/monster-status.h"
13 #include "system/floor-type-definition.h"
14 #include "system/monster-race-definition.h"
15 #include "system/monster-type-definition.h"
16 #include "system/player-type-definition.h"
17 #include "target/target-checker.h"
18 #include "target/target-setter.h"
19 #include "target/target-types.h"
20 #include "view/display-messages.h"
23 * Get an "aiming direction" from the user.
25 * The "dir" is loaded with 1,2,3,4,6,7,8,9 for "actual direction", and
26 * "0" for "current target", and "-1" for "entry aborted".
28 * Note that "Force Target", if set, will pre-empt user interaction,
29 * if there is a usable target already set.
31 * Note that confusion over-rides any (explicit?) user choice.
33 bool get_aim_dir(PlayerType *player_ptr, DIRECTION *dp)
35 DIRECTION dir = command_dir;
36 if (use_old_target && target_okay(player_ptr))
40 if (repeat_pull(&code))
41 if (!(code == 5 && !target_okay(player_ptr)))
42 dir = (DIRECTION)code;
44 *dp = (DIRECTION)code;
48 if (!target_okay(player_ptr))
49 p = _("方向 ('*'でターゲット選択, ESCで中断)? ", "Direction ('*' to choose a target, Escape to cancel)? ");
51 p = _("方向 ('5'でターゲットへ, '*'でターゲット再選択, ESCで中断)? ", "Direction ('5' for target, '*' to re-target, Escape to cancel)? ");
53 if (!get_com(p, &command, true))
56 if (use_menu && (command == '\r'))
70 if (target_set(player_ptr, TARGET_KILL))
75 dir = get_keymap_dir(command);
79 if ((dir == 5) && !target_okay(player_ptr))
92 if (player_ptr->confused)
93 dir = ddd[randint0(8)];
95 if (command_dir != dir)
96 msg_print(_("あなたは混乱している。", "You are confused."));
99 repeat_push((COMMAND_CODE)command_dir);
103 bool get_direction(PlayerType *player_ptr, DIRECTION *dp, bool allow_under, bool with_steed)
105 DIRECTION dir = command_dir;
107 if (repeat_pull(&code))
108 dir = (DIRECTION)code;
110 *dp = (DIRECTION)code;
111 concptr prompt = allow_under ? _("方向 ('.'足元, ESCで中断)? ", "Direction ('.' at feet, Escape to cancel)? ")
112 : _("方向 (ESCで中断)? ", "Direction (Escape to cancel)? ");
116 if (!get_com(prompt, &ch, true))
119 if ((allow_under) && ((ch == '5') || (ch == '-') || (ch == '.'))) {
124 dir = get_keymap_dir(ch);
129 if ((dir == 5) && (!allow_under))
136 if (player_ptr->confused) {
137 if (randint0(100) < 75) {
138 dir = ddd[randint0(8)];
140 } else if (player_ptr->riding && with_steed) {
141 monster_type *m_ptr = &player_ptr->current_floor_ptr->m_list[player_ptr->riding];
142 monster_race *r_ptr = &r_info[m_ptr->r_idx];
143 if (monster_confused_remaining(m_ptr)) {
144 if (randint0(100) < 75)
145 dir = ddd[randint0(8)];
146 } else if (r_ptr->behavior_flags.has(MonsterBehaviorType::RAND_MOVE_50) && r_ptr->behavior_flags.has(MonsterBehaviorType::RAND_MOVE_25) && (randint0(100) < 50))
147 dir = ddd[randint0(8)];
148 else if (r_ptr->behavior_flags.has(MonsterBehaviorType::RAND_MOVE_50) && (randint0(100) < 25))
149 dir = ddd[randint0(8)];
152 if (command_dir != dir) {
153 if (player_ptr->confused) {
154 msg_print(_("あなたは混乱している。", "You are confused."));
156 GAME_TEXT m_name[MAX_NLEN];
157 monster_type *m_ptr = &player_ptr->current_floor_ptr->m_list[player_ptr->riding];
159 monster_desc(player_ptr, m_name, m_ptr, 0);
160 if (monster_confused_remaining(m_ptr)) {
161 msg_format(_("%sは混乱している。", "%^s is confused."), m_name);
163 msg_format(_("%sは思い通りに動いてくれない。", "You cannot control %s."), m_name);
169 repeat_push((COMMAND_CODE)command_dir);
174 * @brief 進行方向を指定する(騎乗対象の混乱の影響を受ける) / Request a "movement" direction (1,2,3,4,6,7,8,9) from the user,
175 * and place it into "command_dir", unless we already have one.
177 * This function should be used for all "repeatable" commands, such as
178 * run, walk, open, close, bash, disarm, spike, tunnel, etc, as well
179 * as all commands which must reference a grid adjacent to the player,
180 * and which may not reference the grid under the player. Note that,
181 * for example, it is no longer possible to "disarm" or "open" chests
182 * in the same grid as the player.
184 * Direction "5" is illegal and will (cleanly) abort the command.
186 * This function tracks and uses the "global direction", and uses
187 * that as the "desired direction", to which "confusion" is applied.
189 bool get_rep_dir(PlayerType *player_ptr, DIRECTION *dp, bool under)
191 DIRECTION dir = command_dir;
193 if (repeat_pull(&code))
194 dir = (DIRECTION)code;
196 *dp = (DIRECTION)code;
197 concptr prompt = under ? _("方向 ('.'足元, ESCで中断)? ", "Direction ('.' at feet, Escape to cancel)? ") : _("方向 (ESCで中断)? ", "Direction (Escape to cancel)? ");
200 if (!get_com(prompt, &ch, true))
203 if ((under) && ((ch == '5') || (ch == '-') || (ch == '.'))) {
208 dir = get_keymap_dir(ch);
213 if ((dir == 5) && (!under))
220 if (player_ptr->confused) {
221 if (randint0(100) < 75)
222 dir = ddd[randint0(8)];
223 } else if (player_ptr->riding) {
224 monster_type *m_ptr = &player_ptr->current_floor_ptr->m_list[player_ptr->riding];
225 monster_race *r_ptr = &r_info[m_ptr->r_idx];
226 if (monster_confused_remaining(m_ptr)) {
227 if (randint0(100) < 75)
228 dir = ddd[randint0(8)];
229 } else if (r_ptr->behavior_flags.has_all_of({ MonsterBehaviorType::RAND_MOVE_50, MonsterBehaviorType::RAND_MOVE_25 }) && (randint0(100) < 50))
230 dir = ddd[randint0(8)];
231 else if (r_ptr->behavior_flags.has(MonsterBehaviorType::RAND_MOVE_50) && (randint0(100) < 25))
232 dir = ddd[randint0(8)];
235 if (command_dir != dir) {
236 if (player_ptr->confused) {
237 msg_print(_("あなたは混乱している。", "You are confused."));
239 GAME_TEXT m_name[MAX_NLEN];
240 monster_type *m_ptr = &player_ptr->current_floor_ptr->m_list[player_ptr->riding];
241 monster_desc(player_ptr, m_name, m_ptr, 0);
242 if (monster_confused_remaining(m_ptr))
243 msg_format(_("%sは混乱している。", "%^s is confused."), m_name);
245 msg_format(_("%sは思い通りに動いてくれない。", "You cannot control %s."), m_name);
250 repeat_push((COMMAND_CODE)command_dir);