1 #include "floor/geometry.h"
2 #include "floor/cave.h"
3 #include "game-option/text-display-options.h"
4 #include "grid/feature.h"
6 #include "system/floor-type-definition.h"
7 #include "target/projection-path-calculator.h"
8 #include "util/bit-flags-calculator.h"
11 * キーパッドの方向を南から反時計回り順に列挙 / Global array for looping through the "keypad directions"
13 const POSITION ddd[9] = { 2, 8, 6, 4, 3, 1, 9, 7, 5 };
16 * dddで定義した順にベクトルのX軸成分を定義 / Global arrays for converting "keypad direction" into offsets
18 const POSITION ddx[10] = { 0, -1, 0, 1, -1, 0, 1, -1, 0, 1 };
21 * dddで定義した順にベクトルのY軸成分を定義 / Global arrays for converting "keypad direction" into offsets
23 const POSITION ddy[10] = { 0, 1, 1, 1, 0, 0, 0, -1, -1, -1 };
26 * ddd越しにベクトルのX軸成分を定義 / Global arrays for optimizing "ddx[ddd[i]]" and "ddy[ddd[i]]"
28 const POSITION ddx_ddd[9] = { 0, 0, 1, -1, 1, -1, 1, -1, 0 };
31 * ddd越しにベクトルのY軸成分を定義 / Global arrays for optimizing "ddx[ddd[i]]" and "ddy[ddd[i]]"
33 const POSITION ddy_ddd[9] = { 1, -1, 0, 0, 1, 1, -1, -1, 0 };
36 * キーパッドの円環状方向配列 / Circular keypad direction array
38 const POSITION cdd[8] = { 2, 3, 6, 9, 8, 7, 4, 1 };
41 * cdd越しにベクトルのX軸成分を定義 / Global arrays for optimizing "ddx[cdd[i]]" and "ddy[cdd[i]]"
43 const POSITION ddx_cdd[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };
46 * cdd越しにベクトルのY軸成分を定義 / Global arrays for optimizing "ddx[cdd[i]]" and "ddy[cdd[i]]"
48 const POSITION ddy_cdd[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };
51 * @brief 2点間の距離をニュートン・ラプソン法で算出する / Distance between two points via Newton-Raphson technique
58 POSITION distance(POSITION y1, POSITION x1, POSITION y2, POSITION x2)
60 POSITION dy = (y1 > y2) ? (y1 - y2) : (y2 - y1);
61 POSITION dx = (x1 > x2) ? (x1 - x2) : (x2 - x1);
63 /* Squared distance */
64 POSITION target = (dy * dy) + (dx * dx);
66 /* Approximate distance: hypot(dy,dx) = max(dy,dx) + min(dy,dx) / 2 */
67 POSITION d = (dy > dx) ? (dy + (dx >> 1)) : (dx + (dy >> 1));
76 /* Approximate error */
77 err = (target - d * d) / (2 * d);
79 /* No error - we are done */
91 * @brief プレイヤーから指定の座標がどの方角にあるかを返す /
92 * Convert an adjacent location to a direction.
97 DIRECTION coords_to_dir(player_type *creature_ptr, POSITION y, POSITION x)
99 DIRECTION d[3][3] = { { 7, 4, 1 }, { 8, 5, 2 }, { 9, 6, 3 } };
102 dy = y - creature_ptr->y;
103 dx = x - creature_ptr->x;
104 if (ABS(dx) > 1 || ABS(dy) > 1)
107 return d[dx + 1][dy + 1];
111 * @brief 指定された座標をプレイヤーが視覚に収められるかを返す。 / Can the player "see" the given grid in detail?
114 * @return 視覚に収められる状態ならTRUEを返す
116 * He must have vision, illumination, and line of sight.\n
118 * Note -- "CAVE_LITE" is only set if the "torch" has "los()".\n
119 * So, given "CAVE_LITE", we know that the grid is "fully visible".\n
121 * Note that "CAVE_GLOW" makes little sense for a wall, since it would mean\n
122 * that a wall is visible from any direction. That would be odd. Except\n
123 * under wizard light, which might make sense. Thus, for walls, we require\n
124 * not only that they be "CAVE_GLOW", but also, that they be adjacent to a\n
125 * grid which is not only "CAVE_GLOW", but which is a non-wall, and which is\n
126 * in line of sight of the player.\n
128 * This extra check is expensive, but it provides a more "correct" semantics.\n
130 * Note that we should not run this check on walls which are "outer walls" of\n
131 * the dungeon, or we will induce a memory fault, but actually verifying all\n
132 * of the locations would be extremely expensive.\n
134 * Thus, to speed up the function, we assume that all "perma-walls" which are\n
135 * "CAVE_GLOW" are "illuminated" from all sides. This is correct for all cases\n
136 * except "vaults" and the "buildings" in town. But the town is a hack anyway,\n
137 * and the player has more important things on his mind when he is attacking a\n
138 * monster vault. It is annoying, but an extremely important optimization.\n
140 * Note that "glowing walls" are only considered to be "illuminated" if the\n
141 * grid which is next to the wall in the direction of the player is also a\n
142 * "glowing" grid. This prevents the player from being able to "see" the\n
143 * walls of illuminated rooms from a corridor outside the room.\n
145 bool player_can_see_bold(player_type *creature_ptr, POSITION y, POSITION x)
149 /* Blind players see nothing */
150 if (creature_ptr->blind)
153 g_ptr = &creature_ptr->current_floor_ptr->grid_array[y][x];
155 /* Note that "torch-lite" yields "illumination" */
156 if (g_ptr->info & (CAVE_LITE | CAVE_MNLT))
159 /* Require line of sight to the grid */
160 if (!player_has_los_bold(creature_ptr, y, x))
163 /* Noctovision of Ninja */
164 if (creature_ptr->see_nocto)
167 /* Require "perma-lite" of the grid */
168 if ((g_ptr->info & (CAVE_GLOW | CAVE_MNDK)) != CAVE_GLOW)
171 /* Feature code (applying "mimic" field) */
172 /* Floors are simple */
173 if (feat_supports_los(get_feat_mimic(g_ptr)))
176 /* Check for "local" illumination */
177 return check_local_illumination(creature_ptr, y, x);
181 * Calculate "incremental motion". Used by project() and shoot().
182 * Assumes that (*y,*x) lies on the path from (y1,x1) to (y2,x2).
184 void mmove2(POSITION *y, POSITION *x, POSITION y1, POSITION x1, POSITION y2, POSITION x2)
186 POSITION dy, dx, dist, shift;
188 /* Extract the distance travelled */
189 dy = (*y < y1) ? y1 - *y : *y - y1;
190 dx = (*x < x1) ? x1 - *x : *x - x1;
192 /* Number of steps */
193 dist = (dy > dx) ? dy : dx;
195 /* We are calculating the next location */
198 /* Calculate the total distance along each axis */
199 dy = (y2 < y1) ? (y1 - y2) : (y2 - y1);
200 dx = (x2 < x1) ? (x1 - x2) : (x2 - x1);
202 /* Paranoia -- Hack -- no motion */
206 /* Move mostly vertically */
208 /* Extract a shift factor */
209 shift = (dist * dx + (dy - 1) / 2) / dy;
211 /* Sometimes move along the minor axis */
212 (*x) = (x2 < x1) ? (x1 - shift) : (x1 + shift);
214 /* Always move along major axis */
215 (*y) = (y2 < y1) ? (y1 - dist) : (y1 + dist);
218 /* Move mostly horizontally */
220 /* Extract a shift factor */
221 shift = (dist * dy + (dx - 1) / 2) / dx;
223 /* Sometimes move along the minor axis */
224 (*y) = (y2 < y1) ? (y1 - shift) : (y1 + shift);
226 /* Always move along major axis */
227 (*x) = (x2 < x1) ? (x1 - dist) : (x1 + dist);
232 * todo is_seen() の関数マクロをバラそうとしたがインクルード関係のコンパイルエラーで失敗
233 * Is the monster seen by the player?
234 * @param creature_ptr プレーヤーへの参照ポインタ
235 * @param m_ptr 個々のモンスターへの参照ポインタ
236 * @return 個々のモンスターがプレーヤーが見えたらTRUE
238 bool is_seen(player_type *creature_ptr, monster_type *m_ptr)
240 bool is_inside_view = !ignore_unview;
241 is_inside_view |= creature_ptr->phase_out;
243 |= player_can_see_bold(creature_ptr, m_ptr->fy, m_ptr->fx) && projectable(creature_ptr, creature_ptr->y, creature_ptr->x, m_ptr->fy, m_ptr->fx);
244 return m_ptr->ml && is_inside_view;