OSDN Git Service

[Refactor] monster_idxと0との比較を関数化する
[hengbandforosx/hengbandosx.git] / src / mind / mind-warrior.cpp
1 #include "mind/mind-warrior.h"
2 #include "cmd-action/cmd-attack.h"
3 #include "floor/geometry.h"
4 #include "monster/monster-util.h"
5 #include "spell-kind/spells-teleport.h"
6 #include "system/floor-type-definition.h"
7 #include "system/grid-type-definition.h"
8 #include "system/player-type-definition.h"
9 #include "target/target-getter.h"
10 #include "view/display-messages.h"
11
12 /*!
13  * 戦士と盗賊における、ヒット&アウェイのレイシャルパワー/突然変異
14  * @param player_ptr プレイヤーへの参照ポインタ
15  * @return コマンドの入力先にモンスターがいたらTRUE
16  */
17 bool hit_and_away(PlayerType *player_ptr)
18 {
19     DIRECTION dir;
20     if (!get_direction(player_ptr, &dir)) {
21         return false;
22     }
23     POSITION y = player_ptr->y + ddy[dir];
24     POSITION x = player_ptr->x + ddx[dir];
25     if (is_monster(player_ptr->current_floor_ptr->grid_array[y][x].m_idx)) {
26         do_cmd_attack(player_ptr, y, x, HISSATSU_NONE);
27         if (randint0(player_ptr->skill_dis) < 7) {
28             msg_print(_("うまく逃げられなかった。", "You failed to run away."));
29         } else {
30             teleport_player(player_ptr, 30, TELEPORT_SPONTANEOUS);
31         }
32         return true;
33     }
34
35     msg_print(_("その方向にはモンスターはいません。", "You don't see any monster in this direction"));
36     msg_print(nullptr);
37     return false;
38 }
39
40 /*!
41  * 剣の舞い
42  * @param player_ptr プレイヤーへの参照ポインタ
43  * @return 常にTRUE
44  */
45 bool sword_dancing(PlayerType *player_ptr)
46 {
47     DIRECTION dir;
48     POSITION y = 0, x = 0;
49     Grid *g_ptr;
50     for (int i = 0; i < 6; i++) {
51         dir = randint0(8);
52         y = player_ptr->y + ddy_ddd[dir];
53         x = player_ptr->x + ddx_ddd[dir];
54         g_ptr = &player_ptr->current_floor_ptr->grid_array[y][x];
55
56         /* Hack -- attack monsters */
57         if (is_monster(g_ptr->m_idx)) {
58             do_cmd_attack(player_ptr, y, x, HISSATSU_NONE);
59         } else {
60             msg_print(_("攻撃が空をきった。", "You attack the empty air."));
61         }
62     }
63
64     return true;
65 }