(line_of_sight): Normalize coordinates before indexing. Closes
#950514. (line_of_sight): There's just one straight line between two points on a plane, but on a torus there are four. Code assumed plane, and thus could screw up near the origin. Pick a shortest line of the four. Partial fix for #950510.
This commit is contained in:
parent
e4d1c38c96
commit
c6678f3899
1 changed files with 8 additions and 5 deletions
|
@ -332,10 +332,12 @@ plane_sona(struct emp_qelem *plane_list, int x, int y,
|
|||
#define DIST(ax,ay,bx,by) LEN(bx - ax, by -ay)
|
||||
|
||||
int
|
||||
line_of_sight(s_char **rad, int ax, int ay, int bx, int by)
|
||||
line_of_sight(char **rad, int ax, int ay, int bx, int by)
|
||||
{
|
||||
int dx = bx - ax;
|
||||
int dy = by - ay;
|
||||
int dxn = XNORM(bx - ax);
|
||||
int dyn = YNORM(by - ay);
|
||||
int dx = dxn > WORLD_X / 2 ? dxn - WORLD_X : dxn;
|
||||
int dy = dyn > WORLD_Y / 2 ? dyn - WORLD_Y : dyn;
|
||||
int dlen = LEN(dx, dy);
|
||||
int n;
|
||||
int cx = 0;
|
||||
|
@ -366,12 +368,13 @@ line_of_sight(s_char **rad, int ax, int ay, int bx, int by)
|
|||
closest = n;
|
||||
}
|
||||
}
|
||||
if (closest < 0) /* not possible */
|
||||
if (CANT_HAPPEN(closest < 0))
|
||||
return 0;
|
||||
cx = cx + diroff[closest][0];
|
||||
cy = cy + diroff[closest][1];
|
||||
if (rad) {
|
||||
blocked = (rad[ay + cy][ax + cx] != dchr[SCT_WATER].d_mnem);
|
||||
blocked = (rad[YNORM(ay + cy)][XNORM(ax + cx)]
|
||||
!= dchr[SCT_WATER].d_mnem);
|
||||
} else {
|
||||
sectp = getsectp((ax + cx), (ay + cy));
|
||||
if (sectp) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue