OSDN Git Service

faef529d570f154b4b3192c0bec5d5afeddc8dae
[hengband/hengband.git] / src / spell-kind / spells-fetcher.c
1 #include "spell-kind/spells-fetcher.h"
2 #include "core/player-redraw-types.h"
3 #include "core/player-update-types.h"
4 #include "core/stuff-handler.h"
5 #include "flavor/flavor-describer.h"
6 #include "flavor/object-flavor-types.h"
7 #include "floor/cave.h"
8 #include "floor/floor.h"
9 #include "grid/feature-flag-types.h"
10 #include "grid/grid.h"
11 #include "monster-race/monster-race.h"
12 #include "monster-race/race-flags7.h"
13 #include "monster/monster-describer.h"
14 #include "monster/monster-status-setter.h"
15 #include "monster/monster-update.h"
16 #include "system/floor-type-definition.h"
17 #include "system/object-type-definition.h"
18 #include "target/target-checker.h"
19 #include "target/target-setter.h"
20 #include "target/target-types.h"
21 #include "util/bit-flags-calculator.h"
22 #include "view/display-messages.h"
23
24 /*!
25  * @brief アイテム引き寄せ処理 /
26  * Fetch an item (teleport it right underneath the caster)
27  * @param caster_ptr プレーヤーへの参照ポインタ
28  * @param dir 魔法の発動方向
29  * @param wgt 許容重量
30  * @param require_los 射線の通りを要求するならばTRUE
31  * @return なし
32  */
33 void fetch_item(player_type *caster_ptr, DIRECTION dir, WEIGHT wgt, bool require_los)
34 {
35     grid_type *g_ptr;
36     object_type *o_ptr;
37     GAME_TEXT o_name[MAX_NLEN];
38
39     if (caster_ptr->current_floor_ptr->grid_array[caster_ptr->y][caster_ptr->x].o_idx) {
40         msg_print(_("自分の足の下にある物は取れません。", "You can't fetch when you're already standing on something."));
41         return;
42     }
43
44     POSITION ty, tx;
45     if (dir == 5 && target_okay(caster_ptr)) {
46         tx = target_col;
47         ty = target_row;
48
49         if (distance(caster_ptr->y, caster_ptr->x, ty, tx) > get_max_range(caster_ptr)) {
50             msg_print(_("そんなに遠くにある物は取れません!", "You can't fetch something that far away!"));
51             return;
52         }
53
54         g_ptr = &caster_ptr->current_floor_ptr->grid_array[ty][tx];
55         if (!g_ptr->o_idx) {
56             msg_print(_("そこには何もありません。", "There is no object at this place."));
57             return;
58         }
59
60         if (g_ptr->info & CAVE_ICKY) {
61             msg_print(_("アイテムがコントロールを外れて落ちた。", "The item slips from your control."));
62             return;
63         }
64
65         if (require_los) {
66             if (!player_has_los_bold(caster_ptr, ty, tx)) {
67                 msg_print(_("そこはあなたの視界に入っていません。", "You have no direct line of sight to that location."));
68                 return;
69             } else if (!projectable(caster_ptr, caster_ptr->y, caster_ptr->x, ty, tx)) {
70                 msg_print(_("そこは壁の向こうです。", "You have no direct line of sight to that location."));
71                 return;
72             }
73         }
74     } else {
75         ty = caster_ptr->y;
76         tx = caster_ptr->x;
77         bool is_first_loop = TRUE;
78         g_ptr = &caster_ptr->current_floor_ptr->grid_array[ty][tx];
79         while (is_first_loop || !g_ptr->o_idx) {
80             is_first_loop = FALSE;
81             ty += ddy[dir];
82             tx += ddx[dir];
83             g_ptr = &caster_ptr->current_floor_ptr->grid_array[ty][tx];
84
85             if ((distance(caster_ptr->y, caster_ptr->x, ty, tx) > get_max_range(caster_ptr))
86                 || !cave_have_flag_bold(caster_ptr->current_floor_ptr, ty, tx, FF_PROJECT))
87                 return;
88         }
89     }
90
91     o_ptr = &caster_ptr->current_floor_ptr->o_list[g_ptr->o_idx];
92     if (o_ptr->weight > wgt) {
93         msg_print(_("そのアイテムは重過ぎます。", "The object is too heavy."));
94         return;
95     }
96
97     OBJECT_IDX i = g_ptr->o_idx;
98     g_ptr->o_idx = o_ptr->next_o_idx;
99     caster_ptr->current_floor_ptr->grid_array[caster_ptr->y][caster_ptr->x].o_idx = i; /* 'move' it */
100
101     o_ptr->next_o_idx = 0;
102     o_ptr->iy = caster_ptr->y;
103     o_ptr->ix = caster_ptr->x;
104
105     describe_flavor(caster_ptr, o_name, o_ptr, OD_NAME_ONLY);
106     msg_format(_("%^sがあなたの足元に飛んできた。", "%^s flies through the air to your feet."), o_name);
107
108     note_spot(caster_ptr, caster_ptr->y, caster_ptr->x);
109     caster_ptr->redraw |= PR_MAP;
110 }
111
112 bool fetch_monster(player_type *caster_ptr)
113 {
114     monster_type *m_ptr;
115     MONSTER_IDX m_idx;
116     GAME_TEXT m_name[MAX_NLEN];
117     int i;
118     int path_n;
119     u16b path_g[512];
120     POSITION ty, tx;
121
122     if (!target_set(caster_ptr, TARGET_KILL))
123         return FALSE;
124
125     m_idx = caster_ptr->current_floor_ptr->grid_array[target_row][target_col].m_idx;
126     if (!m_idx)
127         return FALSE;
128     if (m_idx == caster_ptr->riding)
129         return FALSE;
130     if (!player_has_los_bold(caster_ptr, target_row, target_col))
131         return FALSE;
132     if (!projectable(caster_ptr, caster_ptr->y, caster_ptr->x, target_row, target_col))
133         return FALSE;
134
135     m_ptr = &caster_ptr->current_floor_ptr->m_list[m_idx];
136     monster_desc(caster_ptr, m_name, m_ptr, 0);
137     msg_format(_("%sを引き戻した。", "You pull back %s."), m_name);
138     path_n = project_path(caster_ptr, path_g, get_max_range(caster_ptr), target_row, target_col, caster_ptr->y, caster_ptr->x, 0);
139     ty = target_row, tx = target_col;
140     for (i = 1; i < path_n; i++) {
141         POSITION ny = GRID_Y(path_g[i]);
142         POSITION nx = GRID_X(path_g[i]);
143         grid_type *g_ptr = &caster_ptr->current_floor_ptr->grid_array[ny][nx];
144
145         if (in_bounds(caster_ptr->current_floor_ptr, ny, nx) && is_cave_empty_bold(caster_ptr, ny, nx) && !(g_ptr->info & CAVE_OBJECT)
146             && !pattern_tile(caster_ptr->current_floor_ptr, ny, nx)) {
147             ty = ny;
148             tx = nx;
149         }
150     }
151
152     caster_ptr->current_floor_ptr->grid_array[target_row][target_col].m_idx = 0;
153     caster_ptr->current_floor_ptr->grid_array[ty][tx].m_idx = m_idx;
154     m_ptr->fy = ty;
155     m_ptr->fx = tx;
156     (void)set_monster_csleep(caster_ptr, m_idx, 0);
157     update_monster(caster_ptr, m_idx, TRUE);
158     lite_spot(caster_ptr, target_row, target_col);
159     lite_spot(caster_ptr, ty, tx);
160     if (r_info[m_ptr->r_idx].flags7 & (RF7_LITE_MASK | RF7_DARK_MASK))
161         caster_ptr->update |= (PU_MON_LITE);
162
163     if (m_ptr->ml) {
164         if (!caster_ptr->image)
165             monster_race_track(caster_ptr, m_ptr->ap_r_idx);
166
167         health_track(caster_ptr, m_idx);
168     }
169
170     return TRUE;
171 }