1------------------------------------------------------------------------------ 2-- geoelf_directions.lua: 3-- 4-- Contains the direction constants used by the geoelf layout 5-- generator. Corridors are all in one of these directions, 6-- and a room can have at most one corridor leaving it per 7-- direction. 8------------------------------------------------------------------------------ 9 10geoelf.directions = {} -- Namespace for direction constants, etc. 11 12 13 14-- 15-- The number of directions 16-- 17 18geoelf.directions.COUNT = 8 19geoelf.directions.COUNT_STRAIGHT = 4 20 21-- 22-- The possible directions 23-- 24 25geoelf.directions.S = 0 26geoelf.directions.N = 1 27geoelf.directions.E = 2 28geoelf.directions.W = 3 29geoelf.directions.SE = 4 30geoelf.directions.NW = 5 31geoelf.directions.SW = 6 32geoelf.directions.NE = 7 33 34-- 35-- There are two possible direction values that can describe 36-- each corridor, depending on which way along it you are 37-- going. To avoid redundancy, we declare one of each 38-- direction pair to be forwards and one to be backwards. We 39-- will reverse the backwards corridors before drawing them. 40-- 41-- We are using lookup arrays here instead of functions for 42-- speed reasons. 43-- 44-- Note that the direction values are being used as the indexes 45-- here, not the names. 46-- 47 48geoelf.directions.IS_REVERSE = 49 { [geoelf.directions.S] = false, 50 [geoelf.directions.N] = true, 51 [geoelf.directions.E] = false, 52 [geoelf.directions.W] = true, 53 [geoelf.directions.SE] = false, 54 [geoelf.directions.NW] = true, 55 [geoelf.directions.SW] = false, 56 [geoelf.directions.NE] = true } 57 58geoelf.directions.GET_REVERSE = 59 { [geoelf.directions.S] = geoelf.directions.N, 60 [geoelf.directions.N] = geoelf.directions.S, 61 [geoelf.directions.E] = geoelf.directions.W, 62 [geoelf.directions.W] = geoelf.directions.E, 63 [geoelf.directions.SE] = geoelf.directions.NW, 64 [geoelf.directions.NW] = geoelf.directions.SE, 65 [geoelf.directions.SW] = geoelf.directions.NE, 66 [geoelf.directions.NE] = geoelf.directions.SW } 67 68-- 69-- Moving along any straight directions involve repeatedly 70-- either increasing or decreasing the component of the 71-- position. This can be seen as either adding 1 or -1. 72-- 73 74geoelf.directions.STEP_SIGN = 75 { [geoelf.directions.S] = 1, 76 [geoelf.directions.N] = -1, 77 [geoelf.directions.E] = 1, 78 [geoelf.directions.W] = -1 } 79 80-- 81-- Each diagonal direction is a combination of 2 straight 82-- directions. 83-- 84 85geoelf.directions.COMPONENT_X = 86 { [geoelf.directions.SE] = geoelf.directions.E, 87 [geoelf.directions.NW] = geoelf.directions.W, 88 [geoelf.directions.SW] = geoelf.directions.W, 89 [geoelf.directions.NE] = geoelf.directions.E } 90 91geoelf.directions.COMPONENT_Y = 92 { [geoelf.directions.SE] = geoelf.directions.S, 93 [geoelf.directions.NW] = geoelf.directions.N, 94 [geoelf.directions.SW] = geoelf.directions.S, 95 [geoelf.directions.NE] = geoelf.directions.N } 96