|
| 1 | +-- This file adds placement rules for signs_lib, if present |
| 2 | + |
| 3 | +local spv = { |
| 4 | + [4] = true, |
| 5 | + [6] = true, |
| 6 | + [8] = true, |
| 7 | + [10] = true, |
| 8 | + [13] = true, |
| 9 | + [15] = true, |
| 10 | + [17] = true, |
| 11 | + [19] = true |
| 12 | +} |
| 13 | + |
| 14 | +local sphns = { |
| 15 | + [1] = true, |
| 16 | + [3] = true, |
| 17 | + [5] = true, |
| 18 | + [7] = true, |
| 19 | + [9] = true, |
| 20 | + [11] = true, |
| 21 | + [21] = true, |
| 22 | + [23] = true |
| 23 | +} |
| 24 | + |
| 25 | +local sphew = { |
| 26 | + [0] = true, |
| 27 | + [2] = true, |
| 28 | + [12] = true, |
| 29 | + [14] = true, |
| 30 | + [16] = true, |
| 31 | + [18] = true, |
| 32 | + [20] = true, |
| 33 | + [22] = true |
| 34 | +} |
| 35 | + |
| 36 | +local owtv = { |
| 37 | + [5] = true, |
| 38 | + [7] = true, |
| 39 | + [9] = true, |
| 40 | + [11] = true, |
| 41 | + [12] = true, |
| 42 | + [14] = true, |
| 43 | + [16] = true, |
| 44 | + [18] = true |
| 45 | +} |
| 46 | + |
| 47 | +local owtns = { |
| 48 | + [0] = true, |
| 49 | + [2] = true, |
| 50 | + [4] = true, |
| 51 | + [6] = true, |
| 52 | + [8] = true, |
| 53 | + [10] = true, |
| 54 | + [20] = true, |
| 55 | + [22] = true |
| 56 | +} |
| 57 | + |
| 58 | +local owtew = { |
| 59 | + [1] = true, |
| 60 | + [3] = true, |
| 61 | + [13] = true, |
| 62 | + [15] = true, |
| 63 | + [17] = true, |
| 64 | + [19] = true, |
| 65 | + [21] = true, |
| 66 | + [23] = true |
| 67 | +} |
| 68 | + |
| 69 | +local vert_n = { |
| 70 | + [3] = {[5] = true}, |
| 71 | + [6] = {[9] = true, [12] = true, [16] = true}, |
| 72 | + [7] = {[9] = true, [11] = true}, |
| 73 | +} |
| 74 | + |
| 75 | +local vert_e = { |
| 76 | + [3] = {[5] = true}, |
| 77 | + [6] = {[5] = true, [9] = true, [16] = true}, |
| 78 | + [7] = {[7] = true, [11] = true}, |
| 79 | +} |
| 80 | + |
| 81 | +local vert_s = { |
| 82 | + [3] = {[5] = true}, |
| 83 | + [6] = {[5] = true, [12] = true, [16] = true}, |
| 84 | + [7] = {[5] = true, [7] = true}, |
| 85 | +} |
| 86 | + |
| 87 | +local vert_w = { |
| 88 | + [3] = {[5] = true}, |
| 89 | + [6] = {[5] = true, [9] = true, [12] = true}, |
| 90 | + [7] = {[5] = true, [9] = true}, |
| 91 | +} |
| 92 | + |
| 93 | +local horiz_n = { |
| 94 | + [3] = {[0] = true}, |
| 95 | + [6] = {[0] = true, [4] = true, [20] = true}, |
| 96 | + [7] = {[2] = true, [10] = true}, |
| 97 | + [8] = {[0] = true}, |
| 98 | + [9] = {[2] = true}, |
| 99 | +} |
| 100 | + |
| 101 | +local horiz_e = { |
| 102 | + [3] = {[1] = true}, |
| 103 | + [6] = {[1] = true, [17] = true, [21] = true}, |
| 104 | + [7] = {[3] = true, [19] = true}, |
| 105 | + [8] = {[1] = true}, |
| 106 | + [9] = {[3] = true}, |
| 107 | +} |
| 108 | + |
| 109 | +local horiz_s = { |
| 110 | + [3] = {[0] = true}, |
| 111 | + [6] = {[0] = true, [8] = true, [20] = true}, |
| 112 | + [7] = {[0] = true, [4] = true}, |
| 113 | + [8] = {[0] = true}, |
| 114 | + [9] = {[0] = true}, |
| 115 | +} |
| 116 | + |
| 117 | +local horiz_w = { |
| 118 | + [3] = {[1] = true}, |
| 119 | + [6] = {[1] = true, [13] = true, [21] = true}, |
| 120 | + [7] = {[1] = true, [13] = true}, |
| 121 | + [8] = {[1] = true}, |
| 122 | + [9] = {[1] = true}, |
| 123 | +} |
| 124 | + |
| 125 | +local function get_sign_dir(node, def) |
| 126 | + if (node.param2 == 4 and def.paramtype2 == "wallmounted") |
| 127 | + or (node.param2 == 0 and def.paramtype2 ~= "wallmounted") then |
| 128 | + return {["N"] = true} |
| 129 | + elseif (node.param2 == 2 and def.paramtype2 == "wallmounted") |
| 130 | + or (node.param2 == 1 and def.paramtype2 ~= "wallmounted") then |
| 131 | + return {["E"] = true} |
| 132 | + elseif (node.param2 == 5 and def.paramtype2 == "wallmounted") |
| 133 | + or (node.param2 == 2 and def.paramtype2 ~= "wallmounted") then |
| 134 | + return {["S"] = true} |
| 135 | + elseif node.param2 == 3 then |
| 136 | + return {["W"] = true} |
| 137 | + end |
| 138 | + return {} |
| 139 | +end |
| 140 | + |
| 141 | +--[[ |
| 142 | +In the functions below: |
| 143 | +
|
| 144 | + pos: the (real) position of the placed sign |
| 145 | + node: the sign node itself |
| 146 | + def: its definition |
| 147 | +
|
| 148 | + ppos: the position of the pointed node (pipe/tube) |
| 149 | + pnode: the node itself |
| 150 | + pdef: its definition |
| 151 | +
|
| 152 | +--]] |
| 153 | + |
| 154 | + |
| 155 | +-- pipes |
| 156 | + |
| 157 | +function pipeworks.check_for_vert_pipe(pos, node, def, ppos, pnode, pdef) |
| 158 | + local signdir = get_sign_dir(node, def) |
| 159 | + local pipenumber = pdef.pipenumber |
| 160 | + local pipedir = pnode.param2 |
| 161 | + if string.find(pnode.name, "straight_pipe") and spv[pipedir] then |
| 162 | + return true |
| 163 | + elseif signdir["N"] and vert_n[pipenumber] and vert_n[pipenumber][pipedir] then |
| 164 | + return true |
| 165 | + elseif signdir["E"] and vert_e[pipenumber] and vert_e[pipenumber][pipedir] then |
| 166 | + return true |
| 167 | + elseif signdir["S"] and vert_s[pipenumber] and vert_s[pipenumber][pipedir] then |
| 168 | + return true |
| 169 | + elseif signdir["W"] and vert_w[pipenumber] and vert_w[pipenumber][pipedir] then |
| 170 | + return true |
| 171 | + end |
| 172 | +end |
| 173 | + |
| 174 | +function pipeworks.check_for_horiz_pipe(pos, node, def, ppos, pnode, pdef) |
| 175 | + local signdir = get_sign_dir(node, def) |
| 176 | + local pipenumber = pdef.pipenumber |
| 177 | + local pipedir = pnode.param2 |
| 178 | + if string.find(pnode.name, "straight_pipe") then |
| 179 | + if (signdir["N"] or signdir["S"]) and sphns[pipedir] then |
| 180 | + return true |
| 181 | + elseif (signdir["E"] or signdir["W"]) and sphew[pipedir] then |
| 182 | + return true |
| 183 | + end |
| 184 | + elseif signdir["N"] and horiz_n[pipenumber] and horiz_n[pipenumber][pipedir] then |
| 185 | + return true |
| 186 | + elseif signdir["E"] and horiz_e[pipenumber] and horiz_e[pipenumber][pipedir] then |
| 187 | + return true |
| 188 | + elseif signdir["S"] and horiz_s[pipenumber] and horiz_s[pipenumber][pipedir] then |
| 189 | + return true |
| 190 | + elseif signdir["W"] and horiz_w[pipenumber] and horiz_w[pipenumber][pipedir] then |
| 191 | + return true |
| 192 | + end |
| 193 | +end |
| 194 | + |
| 195 | +-- tubes |
| 196 | + |
| 197 | +function pipeworks.check_for_vert_tube(pos, node, def, ppos, pnode, pdef) |
| 198 | + local signdir = get_sign_dir(node, def) |
| 199 | + local tubenumber = pdef.tubenumber |
| 200 | + local tubedir = pnode.param2 |
| 201 | + if pnode.name == "pipeworks:one_way_tube" and owtv[tubedir] then |
| 202 | + return true |
| 203 | + elseif tubenumber == 2 and (tubedir == 5 or tubedir == 7) then -- it's a stub pointing up or down |
| 204 | + return true |
| 205 | + elseif signdir["N"] and vert_n[tubenumber] and vert_n[tubenumber][tubedir] then |
| 206 | + return true |
| 207 | + elseif signdir["E"] and vert_e[tubenumber] and vert_e[tubenumber][tubedir] then |
| 208 | + return true |
| 209 | + elseif signdir["S"] and vert_s[tubenumber] and vert_s[tubenumber][tubedir] then |
| 210 | + return true |
| 211 | + elseif signdir["W"] and vert_w[tubenumber] and vert_w[tubenumber][tubedir] then |
| 212 | + return true |
| 213 | + end |
| 214 | +end |
| 215 | + |
| 216 | +function pipeworks.check_for_horiz_tube(pos, node, def, ppos, pnode, pdef) |
| 217 | + local signdir = get_sign_dir(node, def) |
| 218 | + local tubenumber = pdef.tubenumber |
| 219 | + local tubedir = pnode.param2 |
| 220 | + if tubenumber == 2 then -- it'a a stub pointing sideways |
| 221 | + if (tubedir == 0 or tubedir == 2) and (signdir["N"] or signdir["S"]) then |
| 222 | + return true |
| 223 | + elseif (tubedir == 1 or tubedir == 3) and (signdir["E"] or signdir["W"]) then |
| 224 | + return true |
| 225 | + end |
| 226 | + elseif pnode.name == "pipeworks:one_way_tube" then |
| 227 | + if (signdir["N"] or signdir["S"]) and owtns[tubedir] then |
| 228 | + return true |
| 229 | + elseif (signdir["E"] or signdir["W"]) and owtew[tubedir] then |
| 230 | + return true |
| 231 | + end |
| 232 | + elseif signdir["N"] and horiz_n[tubenumber] and horiz_n[tubenumber][tubedir] then |
| 233 | + return true |
| 234 | + elseif signdir["E"] and horiz_e[tubenumber] and horiz_e[tubenumber][tubedir] then |
| 235 | + return true |
| 236 | + elseif signdir["S"] and horiz_s[tubenumber] and horiz_s[tubenumber][tubedir] then |
| 237 | + return true |
| 238 | + elseif signdir["W"] and horiz_w[tubenumber] and horiz_w[tubenumber][tubedir] then |
| 239 | + return true |
| 240 | + end |
| 241 | +end |
0 commit comments