sx, sy, sz = GetInt("size", 100, 30, 100)
wall = GetString("type", "outerwall/brick.vox", "brush vox")
outside = GetString("outside", "", "brush vox")
inside = GetString("inside", "", "brush vox")
outsideOffset = GetInt("outsideOffset", 1)
insideOffset = GetInt("insideOffset", 1)
onesided = GetInt("Onesided", 0)

e0, e1, e2, e3 = GetInt("extension", 4, 4, 4, 4)
height = {}

function init()
	wallMat = CreateBrush(wall)
	local x,y,z = GetBrushSize(wallMat)
	thickness = z

	if outside ~= "" then
		outsideMat = CreateBrush(outside)
		local x,y,z = GetBrushSize(outsideMat)
		outsideThickness = z
	end
	
	if inside ~= "" then
		insideMat = CreateBrush(inside)
		local x,y,z = GetBrushSize(insideMat)
		insideThickness = z
	end

	roof = CreateMaterial("plaster", 0.4, 0.4, 0.4)
	wood = CreateMaterial("wood", .4, .3, .2)
	lakt = CreateMaterial("masonry", .4, .3, .2)
	t = thickness

	for x=0, sx do
		local q = x / (sx*0.5)
		height[x] = math.floor(q*sy)
	end
	for x=sx/2, sx do
		local q = 1.0 - (x-(sx*0.5)) / (sx*0.5)
		height[x] = math.floor(q*sy)
	end

	Vox(0,0,0)

	--Gavelspetsar
	Material(wallMat)
	for x=0, sx do
		local y = height[x]
		Box(x, 0, 0, x+1, y, t)
	end
	TranslateBrush(wallMat, 0, 0, (sz-t))
	FlipBrush(wallMat, "z")
	if onesided == 0 then
		for x=0, sx do
			local y = height[x]
			Box(x, 0, sz-t, x+1, y, sz)
		end
	end
	if outsideMat then 
		Material(outsideMat)
		for x=0, sx do
			local y = height[x]
			Box(x, 0, outsideOffset-outsideThickness, x+1, y, outsideOffset)
			if onesided == 0 then
				Box(x, 0, sz-outsideOffset, x+1, y, sz+outsideThickness-outsideOffset)
			end
		end
	end
	if insideMat then 
		Material(insideMat)
		for x=0, sx do
			local y = height[x]
			Box(x, 0, t-1, x+1, y, t)
			if onesided == 0 then
				Box(x, 0, sz-t, x+1, y, sz-t+1)
			end
		end
	end
	
	Material(roof)

	--Main
	for x=0, sx do
		local y = height[x]
		Box(x, y, -e0, x+1, y+2, sz+e1)
	end
	--Utskjut
	Box(-e2, -1, -e0, 0, 1, sz+e1)
	Box(sx, -1, -e0, sx+e3, 1, sz+e1)

	--Lakt
	Material(lakt)
	for x=0, sx,6 do
		local y = height[x]
		Box(x, y-1, -e0+1, x+1, y, sz+e1-1)
	end

	Material(wood)
	---Takstolar
	for z=2, sz-t-2, 12 do
		--Hogben
		for x=0, sx-t do
			local y = height[x]
			Box(x, y-3, z, x+1, y-1, z+2)
		end

		--Overram
		Box(t, -3, z, sx-t, -1, z+2)
		
		--Stodben
		local x0 = math.floor(sx*0.3)
		local y = height[x0]
		Box(x0, -1, z, x0+2, y-3, z+2)
		x0 = math.floor(sx*0.7)
		y = height[x0]
		Box(x0, -1, z, x0+2, y-3, z+2)
	end
end

