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/monster-describer.h"
10 #include "monster/monster-status.h"
11 #include "system/floor-type-definition.h"
12 #include "system/monster-entity.h"
13 #include "system/monster-race-info.h"
14 #include "system/player-type-definition.h"
15 #include "target/target-checker.h"
16 #include "target/target-setter.h"
17 #include "target/target-types.h"
18 #include "timed-effect/timed-effects.h"
19 #include "util/finalizer.h"
20 #include "view/display-messages.h"
24 * Get an "aiming direction" from the user.
26 * The "dir" is loaded with 1,2,3,4,6,7,8,9 for "actual direction", and
27 * "0" for "current target", and "-1" for "entry aborted".
29 * Note that "Force Target", if set, will pre-empt user interaction,
30 * if there is a usable target already set.
32 * Note that confusion over-rides any (explicit?) user choice.
34 bool get_aim_dir(PlayerType *player_ptr, int *dp)
36 auto dir = command_dir;
37 if (use_old_target && target_okay(player_ptr)) {
42 if (repeat_pull(&code)) {
43 if (!(code == 5 && !target_okay(player_ptr))) {
51 if (!target_okay(player_ptr)) {
52 prompt = _("方向 ('*'でターゲット選択, ESCで中断)? ", "Direction ('*' to choose a target, Escape to cancel)? ");
54 prompt = _("方向 ('5'でターゲットへ, '*'でターゲット再選択, ESCで中断)? ", "Direction ('5' for target, '*' to re-target, Escape to cancel)? ");
57 const auto command_opt = input_command(prompt, true);
62 auto command = *command_opt;
63 if (use_menu && (command == '\r')) {
78 if (target_set(player_ptr, TARGET_KILL)) {
84 dir = get_keymap_dir(command);
88 if ((dir == 5) && !target_okay(player_ptr)) {
103 if (player_ptr->effects()->confusion().is_confused()) {
104 dir = ddd[randint0(8)];
107 if (command_dir != dir) {
108 msg_print(_("あなたは混乱している。", "You are confused."));
112 repeat_push((COMMAND_CODE)command_dir);
117 * @brief 方向を指定する(テンキー配列順)
120 * 指定された方向は整数で返され、それぞれの値方向は以下の通り。
128 * @return 指定した方向。指定をキャンセルした場合はstd::nullopt。
130 std::optional<int> get_direction(PlayerType *player_ptr)
132 auto dir = command_dir;
134 if (repeat_pull(&code)) {
138 constexpr auto prompt = _("方向 (ESCで中断)? ", "Direction (Escape to cancel)? ");
140 const auto command = input_command(prompt, true);
145 dir = get_keymap_dir(*command);
152 const auto finalizer = util::make_finalizer([] {
153 repeat_push(static_cast<short>(command_dir));
155 const auto is_confused = player_ptr->effects()->confusion().is_confused();
156 if (is_confused && evaluate_percent(75)) {
157 dir = ddd[randint0(8)];
160 if (command_dir == dir) {
165 msg_print(_("あなたは混乱している。", "You are confused."));
169 const auto &monster = player_ptr->current_floor_ptr->m_list[player_ptr->riding];
170 const auto m_name = monster_desc(player_ptr, &monster, 0);
171 const auto fmt = monster.is_confused()
172 ? _("%sは混乱している。", "%s^ is confused.")
173 : _("%sは思い通りに動いてくれない。", "You cannot control %s.");
174 msg_format(fmt, m_name.data());
179 * @brief 方向を指定する(円周順)
182 * 指定された方向は整数で返され、それぞれの値方向は以下の通り。
190 * @return 指定した方向。指定をキャンセルした場合はstd::nullopt。
192 std::optional<int> get_direction_as_cdir(PlayerType *player_ptr)
194 constexpr std::array<int, 10> cdirs = { { 0, 7, 0, 1, 6, 0, 2, 5, 4, 3 } };
196 const auto dir = get_direction(player_ptr);
197 if (!dir || (dir <= 0) || (dir == 5) || (dir >= std::ssize(cdirs))) {
205 * @brief 進行方向を指定する(騎乗対象の混乱の影響を受ける) / Request a "movement" direction (1,2,3,4,6,7,8,9) from the user,
206 * and place it into "command_dir", unless we already have one.
208 * This function should be used for all "repeatable" commands, such as
209 * run, walk, open, close, bash, disarm, spike, tunnel, etc, as well
210 * as all commands which must reference a grid adjacent to the player,
211 * and which may not reference the grid under the player. Note that,
212 * for example, it is no longer possible to "disarm" or "open" chests
213 * in the same grid as the player.
215 * Direction "5" is illegal and will (cleanly) abort the command.
217 * This function tracks and uses the "global direction", and uses
218 * that as the "desired direction", to which "confusion" is applied.
220 bool get_rep_dir(PlayerType *player_ptr, int *dp, bool under)
222 auto dir = command_dir;
224 if (repeat_pull(&code)) {
229 const auto prompt = under ? _("方向 ('.'足元, ESCで中断)? ", "Direction ('.' at feet, Escape to cancel)? ")
230 : _("方向 (ESCで中断)? ", "Direction (Escape to cancel)? ");
232 const auto command = input_command(prompt, true);
237 if (under && ((command == '5') || (command == '-') || (command == '.'))) {
242 dir = get_keymap_dir(*command);
248 if ((dir == 5) && !under) {
253 auto is_confused = player_ptr->effects()->confusion().is_confused();
255 if (evaluate_percent(75)) {
256 dir = ddd[randint0(8)];
258 } else if (player_ptr->riding) {
259 auto *m_ptr = &player_ptr->current_floor_ptr->m_list[player_ptr->riding];
260 auto *r_ptr = &m_ptr->get_monrace();
261 if (m_ptr->is_confused()) {
262 if (evaluate_percent(75)) {
263 dir = ddd[randint0(8)];
265 } else if (r_ptr->behavior_flags.has_all_of({ MonsterBehaviorType::RAND_MOVE_50, MonsterBehaviorType::RAND_MOVE_25 }) && one_in_(2)) {
266 dir = ddd[randint0(8)];
267 } else if (r_ptr->behavior_flags.has(MonsterBehaviorType::RAND_MOVE_50) && one_in_(4)) {
268 dir = ddd[randint0(8)];
272 if (command_dir != dir) {
274 msg_print(_("あなたは混乱している。", "You are confused."));
276 auto *m_ptr = &player_ptr->current_floor_ptr->m_list[player_ptr->riding];
277 const auto m_name = monster_desc(player_ptr, m_ptr, 0);
278 if (m_ptr->is_confused()) {
279 msg_format(_("%sは混乱している。", "%s^ is confused."), m_name.data());
281 msg_format(_("%sは思い通りに動いてくれない。", "You cannot control %s."), m_name.data());
287 repeat_push(static_cast<short>(command_dir));