1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
rem LIGN OF SIGHT FUNCTION
rem Ported From: http://roguebasin.roguelikedevelopment.org/index.php?title=Simple_Line_of_Sight
FUNCTION SGN(a)
IF a<0 THEN EXITFUNCTION -1
ENDFUNCTION 1
FUNCTION LOS(StartX,StartY,EndX,EndY) `returns BOOL
LOCAL t, x, y, ax, ay, sx, sy, dx, dy AS INTEGER
IF StartX=EndX AND StartY=EndY THEN EXITFUNCTION 1
dx = StartX - EndX
dy = StartY - EndY
ax = ABS(dx)*2
ay = ABS(dy)*2
sx = SGN(dx)
sy = SGN(dy)
x = EndX
y = EndY
rem The following if statement checks to see if the line
rem is x dominate or y dominate and loops accordingly
IF ax > ay
rem X dominate loop
t = ay - (ax/2)
REPEAT
IF t >= 0
y = y+sy
t = t-ax
ENDIF
x = x+sx
t = t+ay
rem check to see if we are at the player's position
IF (x=StartX) AND (y=StartY)
rem return that the player can see the specified map location
EXITFUNCTION 1
ENDIF
rem keep looping until the specified map location is blocked
rem by an object at the updated x,y coord
UNTIL array_pfmap(x,y).object<>OBJ_EMPTY_FLOOR
rem Unable to see map location
EXITFUNCTION 0
ELSE
rem Y dominate loop
t = ax - (ay/2)
REPEAT
IF t >= 0
x = x+sx
t = t-ay
ENDIF
y = y+sy
t = t+ax
IF (x=StartX) AND (y=StartY)
EXITFUNCTION 1
ENDIF
UNTIL array_pfmap(x,y).object<>OBJ_EMPTY_FLOOR
EXITFUNCTION 0
ENDIF
ENDFUNCTION 0
|