mob
var/blindspots = list()
var/complex_blind = 0
var/masked_from[0]
proc/RefreshView()
Blindspots(1)
for (var/mob/M in view())
CanSee(M)
proc/RefreshViewers()
for(var/mob/P in view())
P.CanSee(src)
proc/Blindspots(recalc)
if (recalc)
blindspots = list()
if (!client && !complex_blind)
//NPCs don't need big blindspot calculation for now but have that var there just in case
if (dir == SOUTH)
blindspots += locate(x, y + 1, z)
if (dir == NORTH)
blindspots += locate(x, y - 1, z)
if (dir == EAST)
blindspots += locate(x - 1, y, z)
if (dir == WEST)
blindspots += locate(x + 1, y, z)
return
var/p
var/newy = y
var/newx = x
var/xref = x
var/yref = y
var/loops = 0
if (dir == SOUTH)
for(p=0, p<6, p++)
newy = newy + 1
blindspots += locate(newx, newy, z)
if (loops)
for(p=0, p<loops, p++)
newx = newx + 1
blindspots += locate(newx, newy, z)
newx = xref
for(p=0, p<loops, p++)
newx = newx - 1
blindspots += locate(newx, newy, z)
newx = xref
loops++
if (dir == NORTH)
for(p=0, p<6, p++) //p<howevermany tiles the screen extends from the player
newy = newy - 1
blindspots += locate(newx, newy, z)
if (loops)
for(p=0, p<loops, p++)
newx = newx + 1
blindspots += locate(newx, newy, z)
newx = xref
for(p=0, p<loops, p++) // The tiles immediately in the player's rear peripheral aren't made a 'blind spot' this way
newx = newx - 1
blindspots += locate(newx, newy, z)
newx = xref
loops++
if (dir == EAST)
for(p=0, p<6, p++)
newx = newx - 1
blindspots += locate(newx, newy, z)
if (loops)
for(p=0, p<loops, p++)
newy = newy + 1
blindspots += locate(newx, newy, z)
newy = yref
for(p=0, p<loops, p++)
newy = newy - 1
blindspots += locate(newx, newy, z)
newy = yref
loops++
if (dir == WEST)
for(p=0, p<6, p++)
newx = newx + 1
blindspots += locate(newx, newy, z)
if (loops)
for(p=0, p<loops, p++)
newy = newy + 1
blindspots += locate(newx, newy, z)
newy = yref
for(p=0, p<loops, p++)
newy = newy - 1
blindspots += locate(newx, newy, z)
newy = yref
loops++
proc/CanSee(mob/M)
var/T
if (src.key in M.masked_from)
for (T in blindspots)
if (M.loc == T)
return 0
if (client)
del M.masked_from[src.key]
M.masked_from -= src.key
return 1
else
for (T in blindspots)
if (M.loc == T)
if (client)
var/image/mask = image(null, loc = M)
M.masked_from[src.key] = mask
mask.override = 1
src << mask
return 0
If (client) code in saves on a little bit of CPU if the player is disconnected or an NPC. Feel free to critique and offer feedback on how this could be made more efficient or useful if you think you see a way it could.
Looks clean though.