Pipeworks
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

242 lines
5.9KB

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