//get the turf something is eventually on (or null if none)
proc/getturf(var/atom/movable/A)
while(A && istype(A))
A = A.loc
if(isturf(A))
return A
return null
proc/isblocked(var/turf/start, var/turf/end)
start = getturf(start)
end = getturf(end)
if(!start || !end || start.z != end.z) return 0
var/dx = end.x - start.x
//special case: vertical alignment
if(dx == 0)
for(var/turf/T in block(start,end))
if(T.density)
return 1
return 0
var/dy = end.y - start.y
var/ratio = dy / dx
world << ratio
var/x = start.x
var/y = start.y
var/z = start.z
var/count = 0
var/turf/curturf
do
curturf = locate(x,y,z)
if(curturf.density) return 1
if(count < 1)
count += ratio
x++
else
y++
count--
while(curturf && curturf != end)
return 0
Because nobody else seems to know how to do this. Note that this is only one possible implementation, it does not give exactly the results that you have described. For example, in your example, it would not consider the northmost green tile to be unblocked.
This does, however, have the benefit of being quite fast. You probably don't want to try using it to generate a map of locations you can and can't teleport to, however. But, for determining whether the path between two turfs is unblocked, it works great.
Wow.
WOW.
Didn't expect such a great response from everyone. Thanks, and glad I asked. :)
Jtgibson, thanks for your suggestion of using opacity. I was actually thinking something like that might be a way to go. I'll definitely look into it.
Thanks to all who tried to help, whether they initially understood it or not :P I could have written the question clearer. Sorry.
And Garthor, I want to be one of your "fans". o_o
Thanks for spoon feeding me all the time. :)
It took me about 7 minutes but I think I understand it now.
*tear* I promised myself I wouldn't cry!
Cheers.