Light now fallsoff according to tile contents (water for now only)

develop
Warmist 2013-06-23 12:55:14 +03:00
parent e3ee876a11
commit f7f70f4062
1 changed files with 27 additions and 9 deletions

@ -107,17 +107,28 @@ function LightOverlay:placeLightFov(pos,radius,color,f)
local vp=self:getViewport() local vp=self:getViewport()
local map = self.df_layout.map local map = self.df_layout.map
local ray=function(tx,ty) local ray=function(tx,ty)
local power=copyall(color)
local lx=pos.x
local ly=pos.y
local setTile=function(x,y) local setTile=function(x,y)
if x>0 and y>0 and x<=map.width and y<=map.height then if x>0 and y>0 and x<=map.width and y<=map.height then
local dtsq=(pos.x-x)*(pos.x-x)+(pos.y-y)*(pos.y-y) local dtsq=(lx-x)*(lx-x)+(ly-y)*(ly-y)
local dt=math.sqrt(dtsq)
local tile=x+y*map.width local tile=x+y*map.width
local ncol=f(color,dtsq,radius)
local ocol=self.lightMap[tile] or {r=0,g=0,b=0} local ocol=self.lightMap[tile] or {r=0,g=0,b=0}
ncol=blend(ncol,ocol) local ncol=blend(power,ocol)
self.lightMap[tile]=ncol self.lightMap[tile]=ncol
local v=self.ocupancy[tile]
return self.ocupancy[tile] if dtsq>0 then
power.r=power.r*(v.r^dt)
power.g=power.g*(v.g^dt)
power.b=power.b*(v.b^dt)
end
lx=x
ly=y
local pwsq=power.r*power.r+power.g*power.g+power.b*power.b
return pwsq>levelDim*levelDim
end end
return false return false
end end
@ -240,14 +251,21 @@ function LightOverlay:buildOcupancy()
local pos={x=i+vp.x1-1,y=j+vp.y1-1,z=vp.z} local pos={x=i+vp.x1-1,y=j+vp.y1-1,z=vp.z}
local tile=i+j*map.width local tile=i+j*map.width
local tt=dfhack.maps.getTileType(pos) local tt=dfhack.maps.getTileType(pos)
local t1=dfhack.maps.getTileFlags(pos)
if tt then if tt then
local shape=tile_attrs[tt].shape local shape=tile_attrs[tt].shape
self.ocupancy[tile]=lightPassable(shape) if not lightPassable(shape) then
self.ocupancy[tile]={r=0,g=0,b=0}
else
if t1 and not t1.liquid_type and t1.flow_size>2 then
self.ocupancy[tile]={r=0.5,g=0.5,b=0.7}
else
self.ocupancy[tile]={r=0.8,g=0.8,b=0.8}
end
end
end end
end end
end end
end end
function LightOverlay:makeLightMap() function LightOverlay:makeLightMap()
self.lightMap={} self.lightMap={}