• R/O
  • HTTP
  • SSH
  • HTTPS

hengband: Commit

変愚蛮怒のメインリポジトリです


Commit MetaInfo

Revisiona9942e078eb3448f0426f0652abab1e323bc9dae (tree)
Time2019-04-04 23:35:13
Authordeskull <deskull@user...>
Commiterdeskull

Log Message

[Refactor] #37353 projection.c/h を geometry.c/h に統合。

Change Summary

Incremental Difference

--- a/Hengband_vcs2017/Hengband/Hengband.vcxproj
+++ b/Hengband_vcs2017/Hengband/Hengband.vcxproj
@@ -166,7 +166,6 @@
166166 <ClCompile Include="..\..\src\patron.c" />
167167 <ClCompile Include="..\..\src\player-damage.c" />
168168 <ClCompile Include="..\..\src\player-status.c" />
169- <ClCompile Include="..\..\src\projection.c" />
170169 <ClCompile Include="..\..\src\quest.c" />
171170 <ClCompile Include="..\..\src\realm-craft.c" />
172171 <ClCompile Include="..\..\src\realm-crusade.c" />
@@ -349,7 +348,6 @@
349348 <ClInclude Include="..\..\src\spells-status.h" />
350349 <ClInclude Include="..\..\src\spells-summon.h" />
351350 <ClInclude Include="..\..\src\floor-streams.h" />
352- <ClInclude Include="..\..\src\projection.h" />
353351 <ClInclude Include="..\..\src\spells-world.h" />
354352 <ClInclude Include="..\..\src\spells.h" />
355353 <ClInclude Include="..\..\src\store.h" />
--- a/Hengband_vcs2017/Hengband/Hengband.vcxproj.filters
+++ b/Hengband_vcs2017/Hengband/Hengband.vcxproj.filters
@@ -5,7 +5,6 @@
55 <ClCompile Include="..\..\src\chuukei.c" />
66 <ClCompile Include="..\..\src\geometry.c" />
77 <ClCompile Include="..\..\src\history.c" />
8- <ClCompile Include="..\..\src\projection.c" />
98 <ClCompile Include="..\..\src\quest.c" />
109 <ClCompile Include="..\..\src\realm-craft.c" />
1110 <ClCompile Include="..\..\src\realm-crusade.c" />
@@ -292,7 +291,6 @@
292291 <ClInclude Include="..\..\src\selfinfo.h" />
293292 <ClInclude Include="..\..\src\shoot.h" />
294293 <ClInclude Include="..\..\src\sort.h" />
295- <ClInclude Include="..\..\src\projection.h" />
296294 <ClInclude Include="..\..\src\store.h" />
297295 <ClInclude Include="..\..\src\term.h" />
298296 <ClInclude Include="..\..\src\trap.h" />
--- a/src/cmd-activate.c
+++ b/src/cmd-activate.c
@@ -11,7 +11,6 @@
1111 #include "object-hook.h"
1212 #include "spells-summon.h"
1313 #include "sort.h"
14-#include "projection.h"
1514 #include "artifact.h"
1615 #include "avatar.h"
1716 #include "spells-status.h"
--- a/src/cmd-usestaff.c
+++ b/src/cmd-usestaff.c
@@ -1,5 +1,4 @@
11 #include "angband.h"
2-#include "projection.h"
32 #include "spells-summon.h"
43 #include "avatar.h"
54 #include "player-status.h"
--- a/src/cmd2.c
+++ b/src/cmd2.c
@@ -16,7 +16,6 @@
1616 #include "floor.h"
1717 #include "melee.h"
1818 #include "object-hook.h"
19-#include "projection.h"
2019 #include "spells-summon.h"
2120 #include "spells-status.h"
2221 #include "monster-status.h"
--- a/src/externs.h
+++ b/src/externs.h
@@ -453,7 +453,6 @@ extern void cave_alter_feat(POSITION y, POSITION x, int action);
453453 extern void remove_mirror(POSITION y, POSITION x);
454454
455455 extern void mmove2(POSITION *y, POSITION *x, POSITION y1, POSITION x1, POSITION y2, POSITION x2);
456-extern bool projectable(POSITION y1, POSITION x1, POSITION y2, POSITION x2);
457456 extern void scatter(POSITION *yp, POSITION *xp, POSITION y, POSITION x, POSITION d, BIT_FLAGS mode);
458457 extern void health_track(MONSTER_IDX m_idx);
459458 extern void monster_race_track(MONRACE_IDX r_idx);
--- a/src/geometry.c
+++ b/src/geometry.c
@@ -18,3 +18,376 @@ DIRECTION coords_to_dir(POSITION y, POSITION x)
1818
1919 return d[dx + 1][dy + 1];
2020 }
21+
22+/*!
23+ * @brief 始点から終点への直線経路を返す /
24+ * Determine the path taken by a projection.
25+ * @param gp 経路座標リストを返す参照ポインタ
26+ * @param range 距離
27+ * @param y1 始点Y座標
28+ * @param x1 始点X座標
29+ * @param y2 終点Y座標
30+ * @param x2 終点X座標
31+ * @param flg フラグID
32+ * @return リストの長さ
33+ * @details
34+ * <pre>
35+ * The projection will always start from the grid (y1,x1), and will travel
36+ * towards the grid (y2,x2), touching one grid per unit of distance along
37+ * the major axis, and stopping when it enters the destination grid or a
38+ * wall grid, or has travelled the maximum legal distance of "range".
39+ *
40+ * Note that "distance" in this function (as in the "update_view()" code)
41+ * is defined as "MAX(dy,dx) + MIN(dy,dx)/2", which means that the player
42+ * actually has an "octagon of projection" not a "circle of projection".
43+ *
44+ * The path grids are saved into the grid array pointed to by "gp", and
45+ * there should be room for at least "range" grids in "gp". Note that
46+ * due to the way in which distance is calculated, this function normally
47+ * uses fewer than "range" grids for the projection path, so the result
48+ * of this function should never be compared directly to "range". Note
49+ * that the initial grid (y1,x1) is never saved into the grid array, not
50+ * even if the initial grid is also the final grid.
51+ *
52+ * The "flg" flags can be used to modify the behavior of this function.
53+ *
54+ * In particular, the "PROJECT_STOP" and "PROJECT_THRU" flags have the same
55+ * semantics as they do for the "project" function, namely, that the path
56+ * will stop as soon as it hits a monster, or that the path will continue
57+ * through the destination grid, respectively.
58+ *
59+ * The "PROJECT_JUMP" flag, which for the "project()" function means to
60+ * start at a special grid (which makes no sense in this function), means
61+ * that the path should be "angled" slightly if needed to avoid any wall
62+ * grids, allowing the player to "target" any grid which is in "view".
63+ * This flag is non-trivial and has not yet been implemented, but could
64+ * perhaps make use of the "vinfo" array (above).
65+ *
66+ * This function returns the number of grids (if any) in the path. This
67+ * function will return zero if and only if (y1,x1) and (y2,x2) are equal.
68+ *
69+ * This algorithm is similar to, but slightly different from, the one used
70+ * by "update_view_los()", and very different from the one used by "los()".
71+ * </pre>
72+ */
73+sint project_path(u16b *gp, POSITION range, POSITION y1, POSITION x1, POSITION y2, POSITION x2, BIT_FLAGS flg)
74+{
75+ POSITION y, x;
76+
77+ int n = 0;
78+ int k = 0;
79+
80+ /* Absolute */
81+ POSITION ay, ax;
82+
83+ /* Offsets */
84+ POSITION sy, sx;
85+
86+ /* Fractions */
87+ int frac;
88+
89+ /* Scale factors */
90+ int full, half;
91+
92+ /* Slope */
93+ int m;
94+
95+ /* No path necessary (or allowed) */
96+ if ((x1 == x2) && (y1 == y2)) return (0);
97+
98+
99+ /* Analyze "dy" */
100+ if (y2 < y1)
101+ {
102+ ay = (y1 - y2);
103+ sy = -1;
104+ }
105+ else
106+ {
107+ ay = (y2 - y1);
108+ sy = 1;
109+ }
110+
111+ /* Analyze "dx" */
112+ if (x2 < x1)
113+ {
114+ ax = (x1 - x2);
115+ sx = -1;
116+ }
117+ else
118+ {
119+ ax = (x2 - x1);
120+ sx = 1;
121+ }
122+
123+
124+ /* Number of "units" in one "half" grid */
125+ half = (ay * ax);
126+
127+ /* Number of "units" in one "full" grid */
128+ full = half << 1;
129+
130+ /* Vertical */
131+ if (ay > ax)
132+ {
133+ /* Let m = ((dx/dy) * full) = (dx * dx * 2) */
134+ m = ax * ax * 2;
135+
136+ /* Start */
137+ y = y1 + sy;
138+ x = x1;
139+
140+ frac = m;
141+
142+ if (frac > half)
143+ {
144+ /* Advance (X) part 2 */
145+ x += sx;
146+
147+ /* Advance (X) part 3 */
148+ frac -= full;
149+
150+ /* Track distance */
151+ k++;
152+ }
153+
154+ /* Create the projection path */
155+ while (1)
156+ {
157+ /* Save grid */
158+ gp[n++] = GRID(y, x);
159+
160+ /* Hack -- Check maximum range */
161+ if ((n + (k >> 1)) >= range) break;
162+
163+ /* Sometimes stop at destination grid */
164+ if (!(flg & (PROJECT_THRU)))
165+ {
166+ if ((x == x2) && (y == y2)) break;
167+ }
168+
169+ if (flg & (PROJECT_DISI))
170+ {
171+ if ((n > 0) && cave_stop_disintegration(y, x)) break;
172+ }
173+ else if (flg & (PROJECT_LOS))
174+ {
175+ if ((n > 0) && !cave_los_bold(y, x)) break;
176+ }
177+ else if (!(flg & (PROJECT_PATH)))
178+ {
179+ /* Always stop at non-initial wall grids */
180+ if ((n > 0) && !cave_have_flag_bold(y, x, FF_PROJECT)) break;
181+ }
182+
183+ /* Sometimes stop at non-initial monsters/players */
184+ if (flg & (PROJECT_STOP))
185+ {
186+ if ((n > 0) &&
187+ (player_bold(y, x) || current_floor_ptr->grid_array[y][x].m_idx != 0))
188+ break;
189+ }
190+
191+ if (!in_bounds(y, x)) break;
192+
193+ /* Slant */
194+ if (m)
195+ {
196+ /* Advance (X) part 1 */
197+ frac += m;
198+
199+ /* Horizontal change */
200+ if (frac > half)
201+ {
202+ /* Advance (X) part 2 */
203+ x += sx;
204+
205+ /* Advance (X) part 3 */
206+ frac -= full;
207+
208+ /* Track distance */
209+ k++;
210+ }
211+ }
212+
213+ /* Advance (Y) */
214+ y += sy;
215+ }
216+ }
217+
218+ /* Horizontal */
219+ else if (ax > ay)
220+ {
221+ /* Let m = ((dy/dx) * full) = (dy * dy * 2) */
222+ m = ay * ay * 2;
223+
224+ /* Start */
225+ y = y1;
226+ x = x1 + sx;
227+
228+ frac = m;
229+
230+ /* Vertical change */
231+ if (frac > half)
232+ {
233+ /* Advance (Y) part 2 */
234+ y += sy;
235+
236+ /* Advance (Y) part 3 */
237+ frac -= full;
238+
239+ /* Track distance */
240+ k++;
241+ }
242+
243+ /* Create the projection path */
244+ while (1)
245+ {
246+ /* Save grid */
247+ gp[n++] = GRID(y, x);
248+
249+ /* Hack -- Check maximum range */
250+ if ((n + (k >> 1)) >= range) break;
251+
252+ /* Sometimes stop at destination grid */
253+ if (!(flg & (PROJECT_THRU)))
254+ {
255+ if ((x == x2) && (y == y2)) break;
256+ }
257+
258+ if (flg & (PROJECT_DISI))
259+ {
260+ if ((n > 0) && cave_stop_disintegration(y, x)) break;
261+ }
262+ else if (flg & (PROJECT_LOS))
263+ {
264+ if ((n > 0) && !cave_los_bold(y, x)) break;
265+ }
266+ else if (!(flg & (PROJECT_PATH)))
267+ {
268+ /* Always stop at non-initial wall grids */
269+ if ((n > 0) && !cave_have_flag_bold(y, x, FF_PROJECT)) break;
270+ }
271+
272+ /* Sometimes stop at non-initial monsters/players */
273+ if (flg & (PROJECT_STOP))
274+ {
275+ if ((n > 0) &&
276+ (player_bold(y, x) || current_floor_ptr->grid_array[y][x].m_idx != 0))
277+ break;
278+ }
279+
280+ if (!in_bounds(y, x)) break;
281+
282+ /* Slant */
283+ if (m)
284+ {
285+ /* Advance (Y) part 1 */
286+ frac += m;
287+
288+ /* Vertical change */
289+ if (frac > half)
290+ {
291+ /* Advance (Y) part 2 */
292+ y += sy;
293+
294+ /* Advance (Y) part 3 */
295+ frac -= full;
296+
297+ /* Track distance */
298+ k++;
299+ }
300+ }
301+
302+ /* Advance (X) */
303+ x += sx;
304+ }
305+ }
306+
307+ /* Diagonal */
308+ else
309+ {
310+ /* Start */
311+ y = y1 + sy;
312+ x = x1 + sx;
313+
314+ /* Create the projection path */
315+ while (1)
316+ {
317+ /* Save grid */
318+ gp[n++] = GRID(y, x);
319+
320+ /* Hack -- Check maximum range */
321+ if ((n + (n >> 1)) >= range) break;
322+
323+ /* Sometimes stop at destination grid */
324+ if (!(flg & (PROJECT_THRU)))
325+ {
326+ if ((x == x2) && (y == y2)) break;
327+ }
328+
329+ if (flg & (PROJECT_DISI))
330+ {
331+ if ((n > 0) && cave_stop_disintegration(y, x)) break;
332+ }
333+ else if (flg & (PROJECT_LOS))
334+ {
335+ if ((n > 0) && !cave_los_bold(y, x)) break;
336+ }
337+ else if (!(flg & (PROJECT_PATH)))
338+ {
339+ /* Always stop at non-initial wall grids */
340+ if ((n > 0) && !cave_have_flag_bold(y, x, FF_PROJECT)) break;
341+ }
342+
343+ /* Sometimes stop at non-initial monsters/players */
344+ if (flg & (PROJECT_STOP))
345+ {
346+ if ((n > 0) &&
347+ (player_bold(y, x) || current_floor_ptr->grid_array[y][x].m_idx != 0))
348+ break;
349+ }
350+
351+ if (!in_bounds(y, x)) break;
352+
353+ /* Advance (Y) */
354+ y += sy;
355+
356+ /* Advance (X) */
357+ x += sx;
358+ }
359+ }
360+
361+ /* Length */
362+ return (n);
363+}
364+
365+/*
366+ * Determine if a bolt spell cast from (y1,x1) to (y2,x2) will arrive
367+ * at the final destination, assuming no monster gets in the way.
368+ *
369+ * This is slightly (but significantly) different from "los(y1,x1,y2,x2)".
370+ */
371+bool projectable(POSITION y1, POSITION x1, POSITION y2, POSITION x2)
372+{
373+ POSITION y, x;
374+
375+ int grid_n = 0;
376+ u16b grid_g[512];
377+
378+ /* Check the projection path */
379+ grid_n = project_path(grid_g, (project_length ? project_length : MAX_RANGE), y1, x1, y2, x2, 0);
380+
381+ /* Identical grid */
382+ if (!grid_n) return TRUE;
383+
384+ /* Final grid */
385+ y = GRID_Y(grid_g[grid_n - 1]);
386+ x = GRID_X(grid_g[grid_n - 1]);
387+
388+ /* May not end in an unrequested grid */
389+ if ((y != y2) || (x != x2)) return (FALSE);
390+
391+ /* Assume okay */
392+ return (TRUE);
393+}
--- a/src/geometry.h
+++ b/src/geometry.h
@@ -1,6 +1,29 @@
11 #pragma once
22
3-DIRECTION coords_to_dir(POSITION y, POSITION x);
3+extern DIRECTION coords_to_dir(POSITION y, POSITION x);
4+
5+/*
6+ * project()関数に用いられる、遠隔攻撃特性ビットフラグ / Bit flags for the "project()" function
7+ */
8+#define PROJECT_JUMP 0x0001 /*!< 遠隔攻撃特性: 発動者からの軌跡を持たず、指定地点に直接発生する(予め置いたトラップ、上空からの発生などのイメージ) / Jump directly to the target location (this is a hack) */
9+#define PROJECT_BEAM 0x0002 /*!< 遠隔攻撃特性: ビーム範囲を持つ。 / Work as a beam weapon (affect every grid passed through) */
10+#define PROJECT_THRU 0x0004 /*!< 遠隔攻撃特性: 目標地点に到達しても射程と遮蔽の限り引き延ばす。 / Continue "through" the target (used for "bolts"/"beams") */
11+#define PROJECT_STOP 0x0008 /*!< 遠隔攻撃特性: 道中にプレイヤーかモンスターがいた時点で到達地点を更新して停止する(壁や森はPROJECT_DISIがない限り最初から貫通しない) */
12+#define PROJECT_GRID 0x0010 /*!< 遠隔攻撃特性: 射程内の地形に影響を及ぼす / Affect each grid in the "blast area" in some way */
13+#define PROJECT_ITEM 0x0020 /*!< 遠隔攻撃特性: 射程内のアイテムに影響を及ぼす / Affect each object in the "blast area" in some way */
14+#define PROJECT_KILL 0x0040 /*!< 遠隔攻撃特性: 射程内のモンスターに影響を及ぼす / Affect each monster in the "blast area" in some way */
15+#define PROJECT_HIDE 0x0080 /*!< 遠隔攻撃特性: / Hack -- disable "visual" feedback from projection */
16+#define PROJECT_DISI 0x0100 /*!< 遠隔攻撃特性: / Disintegrate non-permanent features */
17+#define PROJECT_PLAYER 0x0200 /*!< 遠隔攻撃特性: / Main target is player (used for riding player) */
18+#define PROJECT_AIMED 0x0400 /*!< 遠隔攻撃特性: / Target is only player or monster, so don't affect another. Depend on PROJECT_PLAYER. (used for minimum (rad == 0) balls on riding player) */
19+#define PROJECT_REFLECTABLE 0x0800 /*!< 遠隔攻撃特性: 反射可能(ボルト系魔法に利用) / Refrectable spell attacks (used for "bolts") */
20+#define PROJECT_NO_HANGEKI 0x1000 /*!< 遠隔攻撃特性: / Avoid counter attacks of monsters */
21+#define PROJECT_PATH 0x2000 /*!< 遠隔攻撃特性: / Only used for printing project path */
22+#define PROJECT_FAST 0x4000 /*!< 遠隔攻撃特性: / Hide "visual" of flying bolts until blast */
23+#define PROJECT_LOS 0x8000 /*!< 遠隔攻撃特性: / */
24+extern sint project_path(u16b *gp, POSITION range, POSITION y1, POSITION x1, POSITION y2, POSITION x2, BIT_FLAGS flg);
25+
26+extern bool projectable(POSITION y1, POSITION x1, POSITION y2, POSITION x2);
427
528 //!< 対象グリッドの一覧をまとめる構造体
629 typedef struct
--- a/src/grid.c
+++ b/src/grid.c
@@ -19,7 +19,6 @@
1919
2020 #include "angband.h"
2121 #include "world.h"
22-#include "projection.h"
2322 #include "object-hook.h"
2423 #include "generate.h"
2524 #include "grid.h"
@@ -5380,37 +5379,6 @@ void mmove2(POSITION *y, POSITION *x, POSITION y1, POSITION x1, POSITION y2, POS
53805379
53815380
53825381 /*
5383- * Determine if a bolt spell cast from (y1,x1) to (y2,x2) will arrive
5384- * at the final destination, assuming no monster gets in the way.
5385- *
5386- * This is slightly (but significantly) different from "los(y1,x1,y2,x2)".
5387- */
5388-bool projectable(POSITION y1, POSITION x1, POSITION y2, POSITION x2)
5389-{
5390- POSITION y, x;
5391-
5392- int grid_n = 0;
5393- u16b grid_g[512];
5394-
5395- /* Check the projection path */
5396- grid_n = project_path(grid_g, (project_length ? project_length : MAX_RANGE), y1, x1, y2, x2, 0);
5397-
5398- /* Identical grid */
5399- if (!grid_n) return TRUE;
5400-
5401- /* Final grid */
5402- y = GRID_Y(grid_g[grid_n - 1]);
5403- x = GRID_X(grid_g[grid_n - 1]);
5404-
5405- /* May not end in an unrequested grid */
5406- if ((y != y2) || (x != x2)) return (FALSE);
5407-
5408- /* Assume okay */
5409- return (TRUE);
5410-}
5411-
5412-
5413-/*
54145382 * Standard "find me a location" function
54155383 *
54165384 * Obtains a legal location within the given distance of the initial
--- a/src/melee1.c
+++ b/src/melee1.c
@@ -17,7 +17,6 @@
1717 #include "player-damage.h"
1818 #include "monsterrace-hook.h"
1919 #include "melee.h"
20-#include "projection.h"
2120 #include "monster.h"
2221 #include "monster-status.h"
2322 #include "monster-spell.h"
--- a/src/mind.c
+++ b/src/mind.c
@@ -16,7 +16,6 @@
1616
1717 #include "angband.h"
1818 #include "melee.h"
19-#include "projection.h"
2019 #include "spells-summon.h"
2120 #include "avatar.h"
2221 #include "player-status.h"
--- a/src/monster-process.c
+++ b/src/monster-process.c
@@ -17,7 +17,6 @@
1717 #include "cmd-pet.h"
1818 #include "monsterrace-hook.h"
1919 #include "melee.h"
20-#include "projection.h"
2120 #include "spells-summon.h"
2221 #include "quest.h"
2322 #include "avatar.h"
--- a/src/monster1.c
+++ b/src/monster1.c
@@ -14,7 +14,6 @@
1414 #include "cmd-pet.h"
1515 #include "monsterrace-hook.h"
1616 #include "objectkind-hook.h"
17-#include "projection.h"
1817 #include "monster.h"
1918 #include "monster-spell.h"
2019 #include "spells-summon.h"
--- a/src/monster2.c
+++ b/src/monster2.c
@@ -14,7 +14,6 @@
1414 #include "cmd-pet.h"
1515 #include "monsterrace-hook.h"
1616 #include "monster-status.h"
17-#include "projection.h"
1817 #include "monster.h"
1918 #include "spells-summon.h"
2019 #include "quest.h"
--- a/src/mspells1.c
+++ b/src/mspells1.c
@@ -40,7 +40,6 @@
4040
4141 #include "angband.h"
4242 #include "object-curse.h"
43-#include "projection.h"
4443 #include "quest.h"
4544 #include "realm-hex.h"
4645 #include "player-move.h"
--- a/src/mspells2.c
+++ b/src/mspells2.c
@@ -12,7 +12,6 @@
1212 */
1313
1414 #include "angband.h"
15-#include "projection.h"
1615 #include "quest.h"
1716 #include "realm-hex.h"
1817 #include "player-move.h"
--- a/src/mspells3.c
+++ b/src/mspells3.c
@@ -12,7 +12,6 @@
1212
1313 #include "angband.h"
1414 #include "spells-summon.h"
15-#include "projection.h"
1615 #include "avatar.h"
1716 #include "spells-status.h"
1817 #include "cmd-spell.h"
--- a/src/mspells4.c
+++ b/src/mspells4.c
@@ -7,7 +7,6 @@
77
88
99 #include "angband.h"
10-#include "projection.h"
1110 #include "spells-summon.h"
1211 #include "artifact.h"
1312 #include "player-status.h"
--- a/src/object-broken.c
+++ b/src/object-broken.c
@@ -1,5 +1,4 @@
11 #include "angband.h"
2-#include "projection.h"
32
43 /*!
54 * @brief 薬の破損効果処理 /
--- a/src/player-move.c
+++ b/src/player-move.c
@@ -143,7 +143,6 @@
143143 #include "melee.h"
144144 #include "grid.h"
145145 #include "trap.h"
146-#include "projection.h"
147146 #include "quest.h"
148147 #include "artifact.h"
149148 #include "player-move.h"
--- a/src/projection.c
+++ /dev/null
@@ -1,346 +0,0 @@
1-#include "angband.h"
2-#include "projection.h"
3-
4-/*!
5- * @brief 始点から終点への経路を返す /
6- * Determine the path taken by a projection.
7- * @param gp 経路座標リストを返す参照ポインタ
8- * @param range 距離
9- * @param y1 始点Y座標
10- * @param x1 始点X座標
11- * @param y2 終点Y座標
12- * @param x2 終点X座標
13- * @param flg フラグID
14- * @return リストの長さ
15- * @details
16- * <pre>
17- * The projection will always start from the grid (y1,x1), and will travel
18- * towards the grid (y2,x2), touching one grid per unit of distance along
19- * the major axis, and stopping when it enters the destination grid or a
20- * wall grid, or has travelled the maximum legal distance of "range".
21- *
22- * Note that "distance" in this function (as in the "update_view()" code)
23- * is defined as "MAX(dy,dx) + MIN(dy,dx)/2", which means that the player
24- * actually has an "octagon of projection" not a "circle of projection".
25- *
26- * The path grids are saved into the grid array pointed to by "gp", and
27- * there should be room for at least "range" grids in "gp". Note that
28- * due to the way in which distance is calculated, this function normally
29- * uses fewer than "range" grids for the projection path, so the result
30- * of this function should never be compared directly to "range". Note
31- * that the initial grid (y1,x1) is never saved into the grid array, not
32- * even if the initial grid is also the final grid.
33- *
34- * The "flg" flags can be used to modify the behavior of this function.
35- *
36- * In particular, the "PROJECT_STOP" and "PROJECT_THRU" flags have the same
37- * semantics as they do for the "project" function, namely, that the path
38- * will stop as soon as it hits a monster, or that the path will continue
39- * through the destination grid, respectively.
40- *
41- * The "PROJECT_JUMP" flag, which for the "project()" function means to
42- * start at a special grid (which makes no sense in this function), means
43- * that the path should be "angled" slightly if needed to avoid any wall
44- * grids, allowing the player to "target" any grid which is in "view".
45- * This flag is non-trivial and has not yet been implemented, but could
46- * perhaps make use of the "vinfo" array (above).
47- *
48- * This function returns the number of grids (if any) in the path. This
49- * function will return zero if and only if (y1,x1) and (y2,x2) are equal.
50- *
51- * This algorithm is similar to, but slightly different from, the one used
52- * by "update_view_los()", and very different from the one used by "los()".
53- * </pre>
54- */
55-sint project_path(u16b *gp, POSITION range, POSITION y1, POSITION x1, POSITION y2, POSITION x2, BIT_FLAGS flg)
56-{
57- POSITION y, x;
58-
59- int n = 0;
60- int k = 0;
61-
62- /* Absolute */
63- POSITION ay, ax;
64-
65- /* Offsets */
66- POSITION sy, sx;
67-
68- /* Fractions */
69- int frac;
70-
71- /* Scale factors */
72- int full, half;
73-
74- /* Slope */
75- int m;
76-
77- /* No path necessary (or allowed) */
78- if ((x1 == x2) && (y1 == y2)) return (0);
79-
80-
81- /* Analyze "dy" */
82- if (y2 < y1)
83- {
84- ay = (y1 - y2);
85- sy = -1;
86- }
87- else
88- {
89- ay = (y2 - y1);
90- sy = 1;
91- }
92-
93- /* Analyze "dx" */
94- if (x2 < x1)
95- {
96- ax = (x1 - x2);
97- sx = -1;
98- }
99- else
100- {
101- ax = (x2 - x1);
102- sx = 1;
103- }
104-
105-
106- /* Number of "units" in one "half" grid */
107- half = (ay * ax);
108-
109- /* Number of "units" in one "full" grid */
110- full = half << 1;
111-
112- /* Vertical */
113- if (ay > ax)
114- {
115- /* Let m = ((dx/dy) * full) = (dx * dx * 2) */
116- m = ax * ax * 2;
117-
118- /* Start */
119- y = y1 + sy;
120- x = x1;
121-
122- frac = m;
123-
124- if (frac > half)
125- {
126- /* Advance (X) part 2 */
127- x += sx;
128-
129- /* Advance (X) part 3 */
130- frac -= full;
131-
132- /* Track distance */
133- k++;
134- }
135-
136- /* Create the projection path */
137- while (1)
138- {
139- /* Save grid */
140- gp[n++] = GRID(y, x);
141-
142- /* Hack -- Check maximum range */
143- if ((n + (k >> 1)) >= range) break;
144-
145- /* Sometimes stop at destination grid */
146- if (!(flg & (PROJECT_THRU)))
147- {
148- if ((x == x2) && (y == y2)) break;
149- }
150-
151- if (flg & (PROJECT_DISI))
152- {
153- if ((n > 0) && cave_stop_disintegration(y, x)) break;
154- }
155- else if (flg & (PROJECT_LOS))
156- {
157- if ((n > 0) && !cave_los_bold(y, x)) break;
158- }
159- else if (!(flg & (PROJECT_PATH)))
160- {
161- /* Always stop at non-initial wall grids */
162- if ((n > 0) && !cave_have_flag_bold(y, x, FF_PROJECT)) break;
163- }
164-
165- /* Sometimes stop at non-initial monsters/players */
166- if (flg & (PROJECT_STOP))
167- {
168- if ((n > 0) &&
169- (player_bold(y, x) || current_floor_ptr->grid_array[y][x].m_idx != 0))
170- break;
171- }
172-
173- if (!in_bounds(y, x)) break;
174-
175- /* Slant */
176- if (m)
177- {
178- /* Advance (X) part 1 */
179- frac += m;
180-
181- /* Horizontal change */
182- if (frac > half)
183- {
184- /* Advance (X) part 2 */
185- x += sx;
186-
187- /* Advance (X) part 3 */
188- frac -= full;
189-
190- /* Track distance */
191- k++;
192- }
193- }
194-
195- /* Advance (Y) */
196- y += sy;
197- }
198- }
199-
200- /* Horizontal */
201- else if (ax > ay)
202- {
203- /* Let m = ((dy/dx) * full) = (dy * dy * 2) */
204- m = ay * ay * 2;
205-
206- /* Start */
207- y = y1;
208- x = x1 + sx;
209-
210- frac = m;
211-
212- /* Vertical change */
213- if (frac > half)
214- {
215- /* Advance (Y) part 2 */
216- y += sy;
217-
218- /* Advance (Y) part 3 */
219- frac -= full;
220-
221- /* Track distance */
222- k++;
223- }
224-
225- /* Create the projection path */
226- while (1)
227- {
228- /* Save grid */
229- gp[n++] = GRID(y, x);
230-
231- /* Hack -- Check maximum range */
232- if ((n + (k >> 1)) >= range) break;
233-
234- /* Sometimes stop at destination grid */
235- if (!(flg & (PROJECT_THRU)))
236- {
237- if ((x == x2) && (y == y2)) break;
238- }
239-
240- if (flg & (PROJECT_DISI))
241- {
242- if ((n > 0) && cave_stop_disintegration(y, x)) break;
243- }
244- else if (flg & (PROJECT_LOS))
245- {
246- if ((n > 0) && !cave_los_bold(y, x)) break;
247- }
248- else if (!(flg & (PROJECT_PATH)))
249- {
250- /* Always stop at non-initial wall grids */
251- if ((n > 0) && !cave_have_flag_bold(y, x, FF_PROJECT)) break;
252- }
253-
254- /* Sometimes stop at non-initial monsters/players */
255- if (flg & (PROJECT_STOP))
256- {
257- if ((n > 0) &&
258- (player_bold(y, x) || current_floor_ptr->grid_array[y][x].m_idx != 0))
259- break;
260- }
261-
262- if (!in_bounds(y, x)) break;
263-
264- /* Slant */
265- if (m)
266- {
267- /* Advance (Y) part 1 */
268- frac += m;
269-
270- /* Vertical change */
271- if (frac > half)
272- {
273- /* Advance (Y) part 2 */
274- y += sy;
275-
276- /* Advance (Y) part 3 */
277- frac -= full;
278-
279- /* Track distance */
280- k++;
281- }
282- }
283-
284- /* Advance (X) */
285- x += sx;
286- }
287- }
288-
289- /* Diagonal */
290- else
291- {
292- /* Start */
293- y = y1 + sy;
294- x = x1 + sx;
295-
296- /* Create the projection path */
297- while (1)
298- {
299- /* Save grid */
300- gp[n++] = GRID(y, x);
301-
302- /* Hack -- Check maximum range */
303- if ((n + (n >> 1)) >= range) break;
304-
305- /* Sometimes stop at destination grid */
306- if (!(flg & (PROJECT_THRU)))
307- {
308- if ((x == x2) && (y == y2)) break;
309- }
310-
311- if (flg & (PROJECT_DISI))
312- {
313- if ((n > 0) && cave_stop_disintegration(y, x)) break;
314- }
315- else if (flg & (PROJECT_LOS))
316- {
317- if ((n > 0) && !cave_los_bold(y, x)) break;
318- }
319- else if (!(flg & (PROJECT_PATH)))
320- {
321- /* Always stop at non-initial wall grids */
322- if ((n > 0) && !cave_have_flag_bold(y, x, FF_PROJECT)) break;
323- }
324-
325- /* Sometimes stop at non-initial monsters/players */
326- if (flg & (PROJECT_STOP))
327- {
328- if ((n > 0) &&
329- (player_bold(y, x) || current_floor_ptr->grid_array[y][x].m_idx != 0))
330- break;
331- }
332-
333- if (!in_bounds(y, x)) break;
334-
335- /* Advance (Y) */
336- y += sy;
337-
338- /* Advance (X) */
339- x += sx;
340- }
341- }
342-
343- /* Length */
344- return (n);
345-}
346-
--- a/src/projection.h
+++ /dev/null
@@ -1,21 +0,0 @@
1-/*
2- * project()関数に用いられる、遠隔攻撃特性ビットフラグ / Bit flags for the "project()" function
3- */
4-#define PROJECT_JUMP 0x0001 /*!< 遠隔攻撃特性: 発動者からの軌跡を持たず、指定地点に直接発生する(予め置いたトラップ、上空からの発生などのイメージ) / Jump directly to the target location (this is a hack) */
5-#define PROJECT_BEAM 0x0002 /*!< 遠隔攻撃特性: ビーム範囲を持つ。 / Work as a beam weapon (affect every grid passed through) */
6-#define PROJECT_THRU 0x0004 /*!< 遠隔攻撃特性: 目標地点に到達しても射程と遮蔽の限り引き延ばす。 / Continue "through" the target (used for "bolts"/"beams") */
7-#define PROJECT_STOP 0x0008 /*!< 遠隔攻撃特性: 道中にプレイヤーかモンスターがいた時点で到達地点を更新して停止する(壁や森はPROJECT_DISIがない限り最初から貫通しない) */
8-#define PROJECT_GRID 0x0010 /*!< 遠隔攻撃特性: 射程内の地形に影響を及ぼす / Affect each grid in the "blast area" in some way */
9-#define PROJECT_ITEM 0x0020 /*!< 遠隔攻撃特性: 射程内のアイテムに影響を及ぼす / Affect each object in the "blast area" in some way */
10-#define PROJECT_KILL 0x0040 /*!< 遠隔攻撃特性: 射程内のモンスターに影響を及ぼす / Affect each monster in the "blast area" in some way */
11-#define PROJECT_HIDE 0x0080 /*!< 遠隔攻撃特性: / Hack -- disable "visual" feedback from projection */
12-#define PROJECT_DISI 0x0100 /*!< 遠隔攻撃特性: / Disintegrate non-permanent features */
13-#define PROJECT_PLAYER 0x0200 /*!< 遠隔攻撃特性: / Main target is player (used for riding player) */
14-#define PROJECT_AIMED 0x0400 /*!< 遠隔攻撃特性: / Target is only player or monster, so don't affect another. Depend on PROJECT_PLAYER. (used for minimum (rad == 0) balls on riding player) */
15-#define PROJECT_REFLECTABLE 0x0800 /*!< 遠隔攻撃特性: 反射可能(ボルト系魔法に利用) / Refrectable spell attacks (used for "bolts") */
16-#define PROJECT_NO_HANGEKI 0x1000 /*!< 遠隔攻撃特性: / Avoid counter attacks of monsters */
17-#define PROJECT_PATH 0x2000 /*!< 遠隔攻撃特性: / Only used for printing project path */
18-#define PROJECT_FAST 0x4000 /*!< 遠隔攻撃特性: / Hide "visual" of flying bolts until blast */
19-#define PROJECT_LOS 0x8000 /*!< 遠隔攻撃特性: / */
20-
21-extern sint project_path(u16b *gp, POSITION range, POSITION y1, POSITION x1, POSITION y2, POSITION x2, BIT_FLAGS flg);
--- a/src/realm-arcane.c
+++ b/src/realm-arcane.c
@@ -1,6 +1,5 @@
11 #include "angband.h"
22 #include "cmd-spell.h"
3-#include "projection.h"
43 #include "avatar.h"
54
65 #include "spells-floor.h"
--- a/src/realm-chaos.c
+++ b/src/realm-chaos.c
@@ -2,7 +2,6 @@
22 #include "cmd-spell.h"
33 #include "spells-summon.h"
44 #include "spells-status.h"
5-#include "projection.h"
65
76 /*!
87 * @brief カオス領域魔法の各処理を行う
--- a/src/realm-craft.c
+++ b/src/realm-craft.c
@@ -1,7 +1,6 @@
11 #include "angband.h"
22 #include "cmd-spell.h"
33 #include "selfinfo.h"
4-#include "projection.h"
54 #include "spells-object.h"
65 #include "spells-summon.h"
76 #include "spells-status.h"
--- a/src/realm-crusade.c
+++ b/src/realm-crusade.c
@@ -1,7 +1,6 @@
11 #include "angband.h"
22 #include "cmd-spell.h"
33 #include "spells-summon.h"
4-#include "projection.h"
54 #include "spells-status.h"
65
76
--- a/src/realm-daemon.c
+++ b/src/realm-daemon.c
@@ -3,7 +3,6 @@
33 #include "cmd-spell.h"
44 #include "spells-summon.h"
55 #include "spells-status.h"
6-#include "projection.h"
76
87 /*!
98 * @brief 悪魔領域魔法の各処理を行う
--- a/src/realm-death.c
+++ b/src/realm-death.c
@@ -1,6 +1,5 @@
11 #include "angband.h"
22 #include "cmd-spell.h"
3-#include "projection.h"
43 #include "spells-summon.h"
54 #include "spells-status.h"
65 #include "avatar.h"
--- a/src/realm-hex.c
+++ b/src/realm-hex.c
@@ -20,7 +20,6 @@
2020 #include "cmd-quaff.h"
2121 #include "object-hook.h"
2222 #include "object-curse.h"
23-#include "projection.h"
2423 #include "spells-status.h"
2524 #include "player-status.h"
2625
--- a/src/realm-hissatsu.c
+++ b/src/realm-hissatsu.c
@@ -2,7 +2,6 @@
22 #include "cmd-spell.h"
33 #include "melee.h"
44 #include "monsterrace-hook.h"
5-#include "projection.h"
65 #include "artifact.h"
76 #include "monster.h"
87 #include "player-status.h"
--- a/src/realm-life.c
+++ b/src/realm-life.c
@@ -1,6 +1,5 @@
11 #include "angband.h"
22 #include "cmd-spell.h"
3-#include "projection.h"
43 #include "spells-status.h"
54 #include "spells-floor.h"
65
--- a/src/realm-nature.c
+++ b/src/realm-nature.c
@@ -1,6 +1,5 @@
11 #include "angband.h"
22 #include "cmd-spell.h"
3-#include "projection.h"
43 #include "spells-summon.h"
54 #include "spells-status.h"
65 #include "spells-object.h"
--- a/src/realm-song.c
+++ b/src/realm-song.c
@@ -1,7 +1,6 @@
11 #include "angband.h"
22 #include "cmd-spell.h"
33 #include "spells-status.h"
4-#include "projection.h"
54 #include "spells-floor.h"
65
76 /*!
--- a/src/realm-sorcery.c
+++ b/src/realm-sorcery.c
@@ -1,7 +1,6 @@
11 #include "angband.h"
22 #include "cmd-spell.h"
33 #include "selfinfo.h"
4-#include "projection.h"
54 #include "avatar.h"
65 #include "spells-status.h"
76 #include "spells-floor.h"
--- a/src/realm-trump.c
+++ b/src/realm-trump.c
@@ -1,6 +1,5 @@
11 #include "angband.h"
22 #include "cmd-spell.h"
3-#include "projection.h"
43 #include "spells-summon.h"
54 #include "mutation.h"
65 #include "spells-status.h"
--- a/src/shoot.c
+++ b/src/shoot.c
@@ -1,5 +1,4 @@
11 #include "angband.h"
2-#include "projection.h"
32 #include "monster.h"
43 #include "monster-status.h"
54 #include "monster-spell.h"
--- a/src/spells-diceroll.c
+++ b/src/spells-diceroll.c
@@ -5,7 +5,6 @@
55 #include "monster.h"
66 #include "monsterrace-hook.h"
77 #include "mutation.h"
8-#include "projection.h"
98 #include "rooms.h"
109
1110
--- a/src/spells-status.c
+++ b/src/spells-status.c
@@ -2,7 +2,6 @@
22 #include "avatar.h"
33 #include "player-status.h"
44 #include "spells-status.h"
5-#include "projection.h"
65 #include "spells.h"
76 #include "monster.h"
87
--- a/src/spells1.c
+++ b/src/spells1.c
@@ -27,7 +27,6 @@
2727
2828 #include "melee.h"
2929 #include "world.h"
30-#include "projection.h"
3130 #include "mutation.h"
3231 #include "rooms.h"
3332 #include "artifact.h"
--- a/src/spells2.c
+++ b/src/spells2.c
@@ -18,7 +18,6 @@
1818 #include "monsterrace-hook.h"
1919 #include "melee.h"
2020 #include "world.h"
21-#include "projection.h"
2221 #include "spells-summon.h"
2322 #include "mutation.h"
2423 #include "quest.h"
--- a/src/spells3.c
+++ b/src/spells3.c
@@ -17,7 +17,6 @@
1717 #include "object-hook.h"
1818 #include "melee.h"
1919 #include "player-status.h"
20-#include "projection.h"
2120 #include "spells-summon.h"
2221 #include "quest.h"
2322 #include "artifact.h"
--- a/src/trap.c
+++ b/src/trap.c
@@ -3,7 +3,6 @@
33 #include "trap.h"
44 #include "player-damage.h"
55 #include "player-move.h"
6-#include "projection.h"
76 #include "spells-summon.h"
87 #include "quest.h"
98 #include "artifact.h"
--- a/src/xtra2.c
+++ b/src/xtra2.c
@@ -18,7 +18,6 @@
1818 #include "monsterrace-hook.h"
1919 #include "objectkind-hook.h"
2020 #include "sort.h"
21-#include "projection.h"
2221 #include "spells-summon.h"
2322 #include "floor-events.h"
2423 #include "player-move.h"
Show on old repository browser