tracks.lua 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. --advtrains by orwell96, see readme.txt
  2. --dev-time settings:
  3. --EDIT HERE
  4. --If the old non-model rails on straight tracks should be replaced by the new...
  5. --false: no
  6. --true: yes
  7. advtrains.register_replacement_lbms=false
  8. --[[TracksDefinition
  9. nodename_prefix
  10. texture_prefix
  11. description
  12. common={}
  13. straight={}
  14. straight45={}
  15. curve={}
  16. curve45={}
  17. lswitchst={}
  18. lswitchst45={}
  19. rswitchst={}
  20. rswitchst45={}
  21. lswitchcr={}
  22. lswitchcr45={}
  23. rswitchcr={}
  24. rswitchcr45={}
  25. vert1={
  26. --you'll probably want to override mesh here
  27. }
  28. vert2={
  29. --you'll probably want to override mesh here
  30. }
  31. ]]--
  32. advtrains.all_tracktypes={}
  33. --definition preparation
  34. local function conns(c1, c2, r1, r2) return {{c=c1, y=r1}, {c=c2, y=r2}} end
  35. local function conns3(c1, c2, c3, r1, r2, r3) return {{c=c1, y=r1}, {c=c2, y=r2}, {c=c3, y=r3}} end
  36. advtrains.ap={}
  37. advtrains.ap.t_30deg_flat={
  38. regstep=1,
  39. variant={
  40. st={
  41. conns = conns(0,8),
  42. desc = "straight",
  43. tpdouble = true,
  44. tpsingle = true,
  45. trackworker = "cr",
  46. },
  47. cr={
  48. conns = conns(0,7),
  49. desc = "curve",
  50. tpdouble = true,
  51. trackworker = "swlst",
  52. },
  53. swlst={
  54. conns = conns3(0,8,7),
  55. desc = "left switch (straight)",
  56. trackworker = "swrst",
  57. switchalt = "swlcr",
  58. switchmc = "on",
  59. switchst = "st",
  60. },
  61. swlcr={
  62. conns = conns3(0,7,8),
  63. desc = "left switch (curve)",
  64. trackworker = "swrcr",
  65. switchalt = "swlst",
  66. switchmc = "off",
  67. switchst = "cr",
  68. },
  69. swrst={
  70. conns = conns3(0,8,9),
  71. desc = "right switch (straight)",
  72. trackworker = "st",
  73. switchalt = "swrcr",
  74. switchmc = "on",
  75. switchst = "st",
  76. },
  77. swrcr={
  78. conns = conns3(0,9,8),
  79. desc = "right switch (curve)",
  80. trackworker = "st",
  81. switchalt = "swrst",
  82. switchmc = "off",
  83. switchst = "cr",
  84. },
  85. },
  86. regtp=true,
  87. tpdefault="st",
  88. trackworker={
  89. ["swrcr"]="st",
  90. ["swrst"]="st",
  91. ["cr"]="swlst",
  92. ["swlcr"]="swrcr",
  93. ["swlst"]="swrst",
  94. },
  95. rotation={"", "_30", "_45", "_60"},
  96. }
  97. advtrains.ap.t_30deg_slope={
  98. regstep=1,
  99. variant={
  100. vst1={conns = conns(8,0,0,0.5), rail_y = 0.25, desc = "steep uphill 1/2", slope=true},
  101. vst2={conns = conns(8,0,0.5,1), rail_y = 0.75, desc = "steep uphill 2/2", slope=true},
  102. vst31={conns = conns(8,0,0,0.33), rail_y = 0.16, desc = "uphill 1/3", slope=true},
  103. vst32={conns = conns(8,0,0.33,0.66), rail_y = 0.5, desc = "uphill 2/3", slope=true},
  104. vst33={conns = conns(8,0,0.66,1), rail_y = 0.83, desc = "uphill 3/3", slope=true},
  105. },
  106. regsp=true,
  107. slopeplacer={
  108. [2]={"vst1", "vst2"},
  109. [3]={"vst31", "vst32", "vst33"},
  110. max=3,--highest entry
  111. },
  112. slopeplacer_45={
  113. [2]={"vst1_45", "vst2_45"},
  114. max=2,
  115. },
  116. rotation={"", "_30", "_45", "_60"},
  117. trackworker={},
  118. increativeinv={},
  119. }
  120. advtrains.ap.t_30deg_straightonly={
  121. regstep=1,
  122. variant={
  123. st={
  124. conns = conns(0,8),
  125. desc = "straight",
  126. tpdouble = true,
  127. tpsingle = true,
  128. trackworker = "st",
  129. },
  130. },
  131. regtp=true,
  132. tpdefault="st",
  133. rotation={"", "_30", "_45", "_60"},
  134. }
  135. advtrains.ap.t_30deg_straightonly_noplacer={
  136. regstep=1,
  137. variant={
  138. st={
  139. conns = conns(0,8),
  140. desc = "straight",
  141. tpdouble = true,
  142. tpsingle = true,
  143. trackworker = "st",
  144. },
  145. },
  146. tpdefault="st",
  147. rotation={"", "_30", "_45", "_60"},
  148. }
  149. advtrains.ap.t_45deg={
  150. regstep=2,
  151. variant={
  152. st={
  153. conns = conns(0,8),
  154. desc = "straight",
  155. tpdouble = true,
  156. tpsingle = true,
  157. trackworker = "cr",
  158. },
  159. cr={
  160. conns = conns(0,6),
  161. desc = "curve",
  162. tpdouble = true,
  163. trackworker = "swlst",
  164. },
  165. swlst={
  166. conns = conns3(0,8,6),
  167. desc = "left switch (straight)",
  168. trackworker = "swrst",
  169. switchalt = "swlcr",
  170. switchmc = "on",
  171. switchst = "st",
  172. },
  173. swlcr={
  174. conns = conns3(0,6,8),
  175. desc = "left switch (curve)",
  176. trackworker = "swrcr",
  177. switchalt = "swlst",
  178. switchmc = "off",
  179. switchst = "cr",
  180. },
  181. swrst={
  182. conns = conns3(0,8,10),
  183. desc = "right switch (straight)",
  184. trackworker = "st",
  185. switchalt = "swrcr",
  186. switchmc = "on",
  187. switchst = "st",
  188. },
  189. swrcr={
  190. conns = conns3(0,10,8),
  191. desc = "right switch (curve)",
  192. trackworker = "st",
  193. switchalt = "swrst",
  194. switchmc = "off",
  195. switchst = "cr",
  196. },
  197. },
  198. regtp=true,
  199. tpdefault="st",
  200. trackworker={
  201. ["swrcr"]="st",
  202. ["swrst"]="st",
  203. ["cr"]="swlst",
  204. ["swlcr"]="swrcr",
  205. ["swlst"]="swrst",
  206. },
  207. rotation={"", "_30", "_45", "_60"},
  208. }
  209. advtrains.trackpresets = advtrains.ap
  210. --definition format: ([] optional)
  211. --[[{
  212. nodename_prefix
  213. texture_prefix
  214. [shared_texture]
  215. models_prefix
  216. models_suffix (with dot)
  217. [shared_model]
  218. formats={
  219. st,cr,swlst,swlcr,swrst,swrcr,vst1,vst2
  220. (each a table with indices 0-3, for if to register a rail with this 'rotation' table entry. nil is assumed as 'all', set {} to not register at all)
  221. }
  222. common={} change something on common rail appearance
  223. }
  224. [18.12.17] Note on new connection system:
  225. In order to support real rail crossing nodes and finally make the trackplacer respect switches, I changed the connection system.
  226. There can be a variable number of connections available. These are specified as tuples {c=<connection>, y=<rely>}
  227. The table "at_conns" consists of {<conn1>, <conn2>...}
  228. the "at_rail_y" property holds the value that was previously called "railheight"
  229. Depending on the number of connections:
  230. 2 conns: regular rail
  231. 3 conns: switch:
  232. - when train passes in at conn1, will move out of conn2
  233. - when train passes in at conn2 or conn3, will move out of conn1
  234. 4 conns: cross (or cross switch, depending on arrangement of conns):
  235. - conn1 <> conn2
  236. - conn3 <> conn4
  237. ]]
  238. function advtrains.register_tracks(tracktype, def, preset)
  239. for suffix, var in pairs(preset.variant) do
  240. for rotid, rotation in ipairs(preset.rotation) do
  241. if not def.formats[suffix] or def.formats[suffix][rotid] then
  242. --connections
  243. local at_conns = advtrains.rotate_conn_by(var.conns, (rotid-1)*preset.regstep)
  244. trackconns[def.nodename_prefix.."_"..suffix..rotation] = at_conns
  245. end
  246. end
  247. end
  248. end
  249. function advtrains.get_track_connections(name, param2)
  250. if not trackconns[name] then return end
  251. return advtrains.rotate_conn_by(trackconns[name], param2*AT_CMAX/4), nil, nil
  252. end