--Spawns Lights onto the CAZ Lamposts. Slope skew hides the lights again.

local function STRETLGT(line, mo)
	local lightheight = 220
	for i = 0 , #mapthings - 1
		if mapthings[i].type == mobjinfo[MT_LAMPPOST].doomednum
			if (mapthings[i].options & MTF_OBJECTFLIP)
				lightheight = -70
			end
			if ~(line.flags and ML_EFFECT1)
				if  not mapthings[i].mobj.target 
					mapthings[i].mobj.target = P_SpawnMobj(mapthings[i].mobj.x,mapthings[i].mobj.y,
					mapthings[i].mobj.z+lightheight*mapthings[i].mobj.scale,MT_MARBLELIGHT)
				else
					mapthings[i].mobj.target.state = S_MARBLELIGHT
				end
				mapthings[i].mobj.frame = $1 |FF_FULLBRIGHT
			end
			if (line.flags & ML_EFFECT1)
				if mapthings[i].mobj.target 
					mapthings[i].mobj.target.state = S_INVISIBLE
					mapthings[i].mobj.frame = $1 & ~FF_FULLBRIGHT
				end
			end
		end
	end
end
addHook("LinedefExecute", STRETLGT, "STRETLGT")

local function lightadjust(l,un,s) --Flips the glow of RRZ lamps and Marble Torches in reverse gravity
	local lighttable = {[_G["MT_MARBLETORCH"]]=-6,
						[_G["MT_RUSTYLAMP_ORANGE"]]=30}
	for i = 0 , #mapthings - 1
		if mapthings[i].mobj and lighttable[mapthings[i].mobj.type]
			if (mapthings[i].mobj.flags2 & MF2_OBJECTFLIP)
			A_FindTarget(mapthings[i].mobj,MT_MARBLELIGHT,0)
			mapthings[i].mobj.target.z = mapthings[i].mobj.z - lighttable[mapthings[i].mobj.type]*mapthings[i].mobj.scale
			end
		end
	end
end

addHook("LinedefExecute",lightadjust,"LGHTFLIP")

