----- parameters -----

floors = 10:: int_slider("Floors", 1, 100)
width = 3:: int_slider("Width", 1, 40)
length = 4:: int_slider("Length", 1, 40)

pillar_width = 1:: float_slider("Pillar Width", 0.2, 10, 0.2)
pillar_height = 6:: float_slider("Pillar Height", 0.2, 10, 0.2)
beam_length = 10:: float_slider("Beam Length", 0.5, 40, 0.5)
beam_height = 1:: float_slider("Beam Height", 0.2, 10, 0.2)

do_floor_boards = true:: toggle("Do Floor Boards")
floor_board_height = 0.1:: float_slider("Floorboard Height", 0.1, 1, 0.1)

----------------------

local dist = beam_length
local pw = pillar_width

c=col()
c.dim = vec(pw,pillar_height,pw)

cbeam = col()
cbeam.dim = vec(dist,beam_height,pw)

cflr = col()
cflr.dim = vec(dist-pw,floor_board_height,dist)

ctrk = col()
ctrk.dim = vec(pw*0.5,beam_height,pw)

y_off = c.dim.y * 0.5

for x=1,width do
 for z=1,length do
  for y=1,floors do
   local _y = y_off + (y-1) * (c.dim.y + cbeam.dim.y*2)
   brk(c).pos = vec(x*dist, _y, z*dist)

   _y = _y + c.dim.y * 0.5 + cbeam.dim.y * 0.5
   if x < width then
    local _beamx = x*dist+cbeam.dim.x*0.5
    brk(cbeam).pos = vec(_beamx, _y, z*dist)
   end

   _y = _y + cbeam.dim.y
   if z < length then
    local _beamz = z*dist+cbeam.dim.x*0.5
    local beam = brk(cbeam)
    beam.pos = vec(x*dist, _y, _beamz)
    beam.rot.y = 90

    if do_floor_boards and x < width then
    	local f = brk(cflr)
    	local _yflr = _y + cbeam.dim.y*0.5 + floor_board_height * 0.5
    	f.pos = vec((x+0.5)*dist, _yflr, _beamz)
    	f.rot.y = 90
   	end
   end
  end
 end
end

for z=1,length do
 for y=1,floors do
  --local _y = y_off + y * (c.dim.y + cbeam.dim.y)
  local _y = y * (c.dim.y + cbeam.dim.y*2) - cbeam.dim.y * 1.5
  brk(ctrk).pos = vec(dist-ctrk.dim.x*0.5, _y, z*dist)
  brk(ctrk).pos = vec((width) * dist +ctrk.dim.x*0.5, _y, z*dist)
 end
end

for x=1,width do
 for y=1,floors do
  --local _y = y_off + y * (c.dim.y + cbeam.dim.y)
  local _y = y * (c.dim.y + cbeam.dim.y*2) - cbeam.dim.y * 0.5
  
  pkt = brk(ctrk)
  pkt.pos = vec(x*dist, _y,dist - ctrk.dim.x*0.5)
  pkt.rot.y = 90

  pkt = brk(ctrk)
  pkt.pos = vec(x*dist, _y,length * dist + ctrk.dim.x*0.5)
  pkt.rot.y = 90
 end
end

randomize_colors()