local rr = function()
	local r = {
		x = (math.random(0,360)/360)*math.pi*2,
		y = (math.random(0,360)/360)*math.pi*2,
		z = (math.random(0,360)/360)*math.pi*2,
	}
	return r
end
local ar = function()
	return math.random(-10,10)/10
end
local fbr = function()
	return { rotation = rr(), automatic_rotate = ar() }
end
local fbrt = function(count)
	local t = {}
	for c=0, count-1 do
		t[c] = fbr()
	end
	return t
end


eb_levels.register_level({
	schem = "eb_levels_ritual.mts",
	spawn_yaw = 0,
	music = "hall",
	sky = "temple_blue",
	world_pos_offset = vector.new(1, 0, 0),
	player_must_be_seen = false,
})
eb_levels.register_level({
	schem = "eb_levels_greeting_room.mts",
	spawn_yaw = 0,
	floating_blocks = fbrt(8),
	mobile_autorots = {
		[1] = true,
	},
	music = "hall",
	sky = "blood_red",
	world_pos_offset = vector.new(1, 0, 1),
})
eb_levels.register_level({
	schem = "eb_levels_wall.mts",
	spawn_yaw = 0,
	floating_blocks = fbrt(14),
	mobile_autorots = {
		[0] = true,
	},
	music = "temple",
	sky = "blood_red",
	cloud_height = -6,
})
eb_levels.register_level({
	schem = "eb_levels_arches_trigger.mts",
	spawn_yaw = math.pi/2,
	mobile_autorots = {
		[1] = true,
		[2] = true,
	},
	music = "temple",
	sky = "blood_red",
	triggers = {
		[2] = { eye_id = "enti:2" },
	},
	mobile_rotations = {
		[1] = { x = math.pi/2, y = 0, z = 0 },
		[2] = { x = math.pi/2, y = 0, z = 0 },
	},
})
eb_levels.register_level({
	schem = "eb_levels_lantern_plane.mts",
	spawn_yaw = 0,
	mobile_autorots = {
		[0] = true,
	},
	sky = "darkness",
	triggers = {
		[1] = { eye_id = "node:1" },
		[2] = { eye_id = "node:2" },
		[3] = { eye_id = "node:3" },
		[4] = { eye_id = "node:4" },
		[5] = { eye_id = "node:5" },
		[6] = { eye_id = "node:6" },
		[7] = { eye_id = "node:7" },
		[8] = { eye_id = "node:8" },
		[9] = { eye_id = "node:9" },
		[10] = { eye_id = "node:10" },
		[11] = { eye_id = "node:11" },
		[12] = { eye_id = "node:12" },
		[13] = { eye_id = "node:13" },
	},
	timeofday = 0.0, -- midnight
	music = "hall",
})
eb_levels.register_level({
	schem = "eb_levels_black_glass.mts",
	spawn_yaw = (math.pi/2)*3,
	mobile_autorots = {
		[0] = true,
	},
	music = "hall",
	sky = "blood_red",
})
eb_levels.register_level({
	schem = "eb_levels_circle.mts",
	spawn_yaw = 0,
	mobile_autorots = {
		[1] = true,
		[2] = true,
		[3] = true,
		[4] = true,
		[5] = true,
		[8] = true,
	},
	mobile_rotations = {
		[1] = { x = 0, y = 0, z = 0 },
		[2] = { x = 0, y = math.pi/2, z = 0 },
		[3] = { x = 0, y = math.pi, z = 0 },
		[4] = { x = 0, y = math.pi*3/2, z = 0 },

		[5] = { x = 0, y = math.pi, z = 0 },
		[6] = { x = 0, y = math.pi*3/2, z = 0 },
		[7] = { x = 0, y = 0, z = 0 },
		[8] = { x = 0, y = math.pi/2, z = 0 },
	},
	mobile_paths = {
		[1] = { waypoints = {
			vector.new(0,0,0),
			vector.new(3,0,0),
			vector.new(9,0,3),
			vector.new(13,0,7),
			vector.new(15,0,12),
			vector.new(15,0,18),
			vector.new(12,0,24),
			vector.new(8,0,28),
			vector.new(3,0,30),
			vector.new(-3,0,30),
			vector.new(-9,0,27),
			vector.new(-13,0,23),
			vector.new(-15,0,18),
			vector.new(-15,0,12),
			vector.new(-12,0,6),
			vector.new(-8,0,2),
			vector.new(-3,0,0),
		}, start_active = true},
		[2] = { waypoints = {
			vector.add(vector.new(-15,0,-15),vector.new(15,0,15)),
			vector.add(vector.new(-15,0,-15),vector.new(15,0,18)),
			vector.add(vector.new(-15,0,-15),vector.new(12,0,24)),
			vector.add(vector.new(-15,0,-15),vector.new(8,0,28)),
			vector.add(vector.new(-15,0,-15),vector.new(3,0,30)),
			vector.add(vector.new(-15,0,-15),vector.new(-3,0,30)),
			vector.add(vector.new(-15,0,-15),vector.new(-9,0,27)),
			vector.add(vector.new(-15,0,-15),vector.new(-13,0,23)),
			vector.add(vector.new(-15,0,-15),vector.new(-15,0,18)),
			vector.add(vector.new(-15,0,-15),vector.new(-15,0,12)),
			vector.add(vector.new(-15,0,-15),vector.new(-12,0,6)),
			vector.add(vector.new(-15,0,-15),vector.new(-8,0,2)),
			vector.add(vector.new(-15,0,-15),vector.new(-3,0,0)),
			vector.add(vector.new(-15,0,-15),vector.new(3,0,0)),
			vector.add(vector.new(-15,0,-15),vector.new(9,0,3)),
			vector.add(vector.new(-15,0,-15),vector.new(13,0,7)),
			vector.add(vector.new(-15,0,-15),vector.new(15,0,12)),
		}, start_active = true},
		[3] = { waypoints = {
			vector.add(vector.new(0,0,-30),vector.new(0,0,30)),
			vector.add(vector.new(0,0,-30),vector.new(-3,0,30)),
			vector.add(vector.new(0,0,-30),vector.new(-9,0,27)),
			vector.add(vector.new(0,0,-30),vector.new(-13,0,23)),
			vector.add(vector.new(0,0,-30),vector.new(-15,0,18)),
			vector.add(vector.new(0,0,-30),vector.new(-15,0,12)),
			vector.add(vector.new(0,0,-30),vector.new(-12,0,6)),
			vector.add(vector.new(0,0,-30),vector.new(-8,0,2)),
			vector.add(vector.new(0,0,-30),vector.new(-3,0,0)),
			vector.add(vector.new(0,0,-30),vector.new(0,0,0)),
			vector.add(vector.new(0,0,-30),vector.new(3,0,0)),
			vector.add(vector.new(0,0,-30),vector.new(9,0,3)),
			vector.add(vector.new(0,0,-30),vector.new(13,0,7)),
			vector.add(vector.new(0,0,-30),vector.new(15,0,12)),
			vector.add(vector.new(0,0,-30),vector.new(15,0,18)),
			vector.add(vector.new(0,0,-30),vector.new(12,0,24)),
			vector.add(vector.new(0,0,-30),vector.new(8,0,28)),
			vector.add(vector.new(0,0,-30),vector.new(3,0,30)),
		}, start_active = true},
		[4] = { waypoints = {
			vector.add(vector.new(15,0,-15),vector.new(-15,0,15)),
			vector.add(vector.new(15,0,-15),vector.new(-15,0,12)),
			vector.add(vector.new(15,0,-15),vector.new(-12,0,6)),
			vector.add(vector.new(15,0,-15),vector.new(-8,0,2)),
			vector.add(vector.new(15,0,-15),vector.new(-3,0,0)),
			vector.add(vector.new(15,0,-15),vector.new(0,0,0)),
			vector.add(vector.new(15,0,-15),vector.new(3,0,0)),
			vector.add(vector.new(15,0,-15),vector.new(9,0,3)),
			vector.add(vector.new(15,0,-15),vector.new(13,0,7)),
			vector.add(vector.new(15,0,-15),vector.new(15,0,12)),
			vector.add(vector.new(15,0,-15),vector.new(15,0,18)),
			vector.add(vector.new(15,0,-15),vector.new(12,0,24)),
			vector.add(vector.new(15,0,-15),vector.new(8,0,28)),
			vector.add(vector.new(15,0,-15),vector.new(3,0,30)),
			vector.add(vector.new(15,0,-15),vector.new(-3,0,30)),
			vector.add(vector.new(15,0,-15),vector.new(-9,0,27)),
			vector.add(vector.new(15,0,-15),vector.new(-13,0,23)),
			vector.add(vector.new(15,0,-15),vector.new(-15,0,18)),
		}, start_active = true},
	},
	sky = "darkness",
	timeofday = 0.5,
	music = "spooky",
})
eb_levels.register_level({
	schem = "eb_levels_stone_chicken.mts",
	spawn_yaw = math.pi,
	mobile_autorots = {
		[1] = true,
		[2] = true,
		[3] = true,
		[4] = true,
		[5] = true,
	},
	triggers = {
		[1] = { eye_id = "enti:1", trigger_type = "path" },
		[2] = { eye_id = "enti:2", trigger_type = "path" },
		[3] = { eye_id = "enti:3", trigger_type = "path" },
		[4] = { eye_id = "enti:4", trigger_type = "path" },
		[5] = { eye_id = "enti:5", trigger_type = "path" },
	},
	mobile_paths = {
		[1] = { waypoints = {
			vector.new(0, 0, 0),
			vector.new(0, 0, -9)
		}},
		[2] = { waypoints = {
			vector.new(0, 0, 0),
			vector.new(3, 0, 0),
			vector.new(3, 0, 8),
			vector.new(-9, 0, 8),
			vector.new(-9, 0, 0),
		}},
		[3] = { waypoints = {
			vector.new(0, 0, 0),
			vector.new(5, 0, 0),
			vector.new(5, 0, 10),
			vector.new(-5, 0, 10),
			vector.new(-5, 0, 0),
		}},
		[4] = { waypoints = {
			vector.new(0, 0, 0),
			vector.new(1, 0, 0),
			vector.new(6, -3, 0),
			vector.new(6, -3, 5),
			vector.new(6, -8, 10),
			vector.new(-6, -8, 10),
			vector.new(-6, -3, 5),
			vector.new(-6, -3, 0),
			vector.new(-1, 0, 0),
		}},
		[5] = { waypoints = {
			vector.new(0, 0, 0),
			vector.new(-1, 0, 0),
			vector.new(-1, 0, -2),
			vector.new(1, 0, -2),
			vector.new(1, 0, 0),
		}},
	},
	sky = "darkness",
	timeofday = 0.0, -- midnight
	music = "spooky",
})
eb_levels.register_level({
	schem = "eb_levels_sewers.mts",
	spawn_yaw = (math.pi*3)/2,
	sky = "darkness",
	mobile_autorots = {
		[0] = true,
		[1] = true,
		[2] = true,
		[3] = true,
		[4] = true,
		[5] = true,
		[6] = true,
	},
	triggers = {
		[1] = { eye_id = "enti:1", trigger_type = "path" },
		[2] = { eye_id = "enti:2", trigger_type = "path" },
		[3] = { eye_id = "enti:3", trigger_type = "path" },
		[4] = { eye_id = "enti:4", trigger_type = "path" },
		[5] = { eye_id = "enti:5", trigger_type = "path" },
		[6] = { eye_id = "enti:6", trigger_type = "path" },
		[7] = { eye_id = "node:7" },
		[8] = { eye_id = "node:8" },
	},
	mobile_paths = {
		-- Eyeball paths. The eyes move between
		-- 9 crossings (each numbered 1-9,
		-- as seen in the in-level graffiti).

		-- 7-8 (this means the eyeball travels between crossings 7 and 8)
		[1] = { waypoints = {
			vector.new(0,0,0),
			vector.new(29,0,0),
		}, speed = 3},
		-- 8-9-6-9
		[2] = { waypoints = {
			vector.new(0,0,0),
			vector.new(-29,0,0),
			vector.new(0,0,0),
			vector.new(0,0,-31),
		}, speed = 3},
		-- 2-3-6-5
		[3] = { waypoints = {
			vector.new(0,0,0),
			vector.new(0,0,-15),
			vector.new(-28,0,-15),
			vector.new(0,0,-15),
			vector.new(0,0,15),
			vector.new(-28,0,15),
			vector.new(0,0,15),
		}, start_active = true, speed = 3},
		-- 1-2-5
		[4] = { waypoints = {
			vector.new(0,0,0),
			vector.new(29,0,0),
			vector.new(29,0,30),
			vector.new(29,0,0),
		}, speed = 3},
		-- 4-5-6
		[5] = { waypoints = {
			vector.new(31,0,0),
			vector.new(-37,0,0),
		}, speed = 3},
		-- 8-5-2-EXIT
		[6] = { waypoints = {
			vector.new(0,0,0),
			vector.new(0,0,34),
			vector.new(0,0,-62),
		}, speed = 3},
	},
	music = "spooky",
})

eb_levels.register_level({
	schem = "eb_levels_glass_maze.mts",
	spawn_yaw = math.pi,
	mobile_autorots = {
		[1] = true,
		[2] = true,
		[3] = true,
		[4] = true,
		[5] = true,
		[8] = true,
		[9] = true,
		[10] = true,
		[11] = true,
		[14] = true,
		[15] = true,
		[16] = true,
		[17] = true,
		[18] = true,
	},
	triggers = {
		[3] = { eye_id = "enti:3", trigger_type = "see" },
		[6] = { eye_id = "node:6" },
		[7] = { eye_id = "node:7" },
		[8] = { eye_id = "enti:8", trigger_type = "see" },
		[11] = { eye_id = "enti:11", trigger_type = "path" },
		[12] = { eye_id = "node:12" },
		[13] = { eye_id = "node:13" },
		[14] = { eye_id = "enti:14", trigger_type = "path" },
		[15] = { eye_id = "enti:15", trigger_type = "path" },
		[16] = { eye_id = "enti:16", trigger_type = "path" },
		[17] = { eye_id = "enti:17", trigger_type = "path" },
		[18] = { eye_id = "enti:18", trigger_type = "path" },
	},
	mobile_paths = {
		[2] = { waypoints = {
			vector.new(0,0,0),
			vector.new(0,0,4),
			vector.new(-4,0,4),
			vector.new(-4,0,-4),
			vector.new(0,0,-4),
		}, start_active = true},
		[4] = { waypoints = {
			vector.new(0,0,0),
			vector.new(0,0,4),
			vector.new(0,0,-8)
		}, start_active = true},
		[5] = { waypoints = {
			vector.new(0,0,0),
			vector.new(0,0,-8),
			vector.new(0,0,4)
		}, start_active = true},
		[7] = { waypoints = {
			vector.new(0,0,0),
			vector.new(-7,0,0),
		}},
		[9] = { waypoints = {
			vector.new(0,0,0),
			vector.new(4,0,0),
		}, start_active = true},
		[10] = { waypoints = {
			vector.new(0,0,0),
			vector.new(-7,0,0),
		}, start_active = true},
		[14] = { waypoints = {
			vector.new(0,0,0),
			vector.new(0,0,3),
			vector.new(0,0,-46),
		}, start_active = true},
		[15] = { waypoints = {
			vector.new(0,0,0),
			vector.new(0,0,-17),
			vector.new(0,0,32),
		}, start_active = true},
		[16] = { waypoints = {
			vector.new(0,0,0),
			vector.new(0,0,8),
			vector.new(-3,0,8),
			vector.new(0,0,8),
		}},
		[17] = { waypoints = {
			vector.new(0,0,0),
			vector.new(0,0,14),
		}},
		[18] = { waypoints = {
			vector.new(0,0,0),
			vector.new(-3,0,0),
			vector.new(0,0,0),
			vector.new(0,0,4),
			vector.new(-3,0,4),
			vector.new(0,0,4),
		}, start_active = true},
	},
	sky = "blood_red",
	music = "temple",
})
eb_levels.register_level({
	schem = "eb_levels_ritual_fin.mts",
	spawn_yaw = math.pi,
	sky = "temple_blue",
	world_pos_offset = vector.new(1, 0, 0),
	player_must_be_seen = false,
	mobile_autorots = { [0] = true },
	music = "hall",
})


