init.lua 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. ---------------------------------------------------------------------------------------
  2. -- JAPAN TRAM TLR0600<Toyama Light Rail model>
  3. -- by takaosan
  4. ---------------------------------------------------------------------------------------
  5. local S = attrans
  6. local illumination_timer_duration = 10
  7. local illumination_start_time = 18900
  8. local illumination_end_time = 5200
  9. local use_illuminated_appearance = minetest.settings:get_bool("advtrains_train_jpntlr600_illuminated_appearance", true)
  10. -- With the ability for players to now apply custom colors to their trams, it
  11. -- is no longer necessary for there to be trams of specific colors. This
  12. -- option is intended to be enabled for those worlds that do not include the
  13. -- AdvTaiins Livery Designer mod pack and for pre-existing worlds that already
  14. -- have such trams from earlier versions of this mod.
  15. local include_deprecated_trams = minetest.settings:get_bool("advtrains_train_jpntlr600_include_deprecated_trams", false)
  16. local deprecated_tram_colours = {
  17. "blue",
  18. "green",
  19. "red",
  20. "yellow"
  21. }
  22. -- Begin support code for AdvTrains Livery Designer
  23. local use_advtrains_livery_designer = minetest.get_modpath( "advtrains_livery_designer" ) and advtrains_livery_designer
  24. local mod_name = "advtrains_train_jpntlr600"
  25. local generic_tlr0600_front_unit = mod_name..":".."front_unit"
  26. local generic_tlr0600_back_unit = mod_name..":".."back_unit"
  27. local common_templates = {
  28. {
  29. name = "Toyama",
  30. designer = "Marnack",
  31. texture_license = "CC-BY-SA-3.0",
  32. texture_creator = "takaosan, with minor updates by Marnack",
  33. notes = "This template is loosely based on the livery for the TLR0600 Tram in Toyama, Japan. It supports the four livery schemes defined in the original version of this mod as well as additional customizations that build on the original livery.",
  34. base_textures = {"advtrains_tlr600_01.png"},
  35. overlays = {
  36. [1] = {name = "Exterior Walls", texture = "advtrains_tlr600_01_exterior_walls.png", alpha = 228},
  37. [2] = {name = "Window Trim", texture = "advtrains_tlr600_01_window_trim.png", alpha = 228},
  38. [3] = {name = "Service Color", texture = "advtrains_tlr600_01_line_coloring.png", alpha = 228},
  39. [4] = {name = "Seats", texture = "advtrains_tlr600_common_seats.png", alpha = 192},
  40. },
  41. },
  42. {
  43. name = "Ribbon",
  44. designer = "Marnack",
  45. texture_license = "CC-BY-SA-3.0",
  46. texture_creator = "takaosan, with updates by Marnack",
  47. notes = "This template features an optional multicolored ribbon that meanders around the exterior of the unit as well as cusomization options for the exterior walls, window trim and seats.",
  48. base_textures = {"advtrains_tlr600_02.png"},
  49. overlays = {
  50. [1] = {name = "Exterior Walls", texture = "advtrains_tlr600_02_exterior_walls.png", alpha = 228},
  51. [2] = {name = "Window Trim", texture = "advtrains_tlr600_02_window_trim.png", alpha = 228},
  52. [3] = {name = "Ribbon", texture = "advtrains_tlr600_02_ribbon.png", alpha = 228},
  53. [4] = {name = "Ribbon Middle", texture = "advtrains_tlr600_02_ribbon_middle.png", alpha = 228},
  54. [5] = {name = "Seats", texture = "advtrains_tlr600_common_seats.png", alpha = 192},
  55. },
  56. },
  57. {
  58. name = "Upper-Lower Split",
  59. designer = "Marnack",
  60. texture_license = "CC-BY-SA-3.0",
  61. texture_creator = "takaosan, with updates by Marnack",
  62. notes = "This template supports different colors for the upper and lower portions of the exterior walls and an optional service line as well as cusomization options for the window trim and seats.",
  63. base_textures = {"advtrains_tlr600_03.png"},
  64. overlays = {
  65. [1] = {name = "Upper Walls", texture = "advtrains_tlr600_03_exterior_walls_upper.png", alpha = 228},
  66. [2] = {name = "Window Trim", texture = "advtrains_tlr600_03_window_trim.png", alpha = 228},
  67. [3] = {name = "Lower Walls", texture = "advtrains_tlr600_03_exterior_walls_lower.png", alpha = 228},
  68. [4] = {name = "Service Stripe", texture = "advtrains_tlr600_03_service_stripe.png", alpha = 228},
  69. [5] = {name = "Seats", texture = "advtrains_tlr600_common_seats.png", alpha = 192},
  70. },
  71. },
  72. }
  73. local livery_templates = {
  74. [generic_tlr0600_front_unit] = common_templates,
  75. [generic_tlr0600_back_unit] = common_templates,
  76. }
  77. if include_deprecated_trams then
  78. -- Include a livery template for each of the deprecated trams so
  79. -- that players can use the design livery tool to view the trams.
  80. for _,colour in pairs(deprecated_tram_colours) do
  81. local deprecated_tram_livery_templates = {
  82. {
  83. name = "Default "..colour,
  84. designer = "takaosan",
  85. texture_license = "CC-BY-SA-3.0",
  86. texture_creator = "takaosan",
  87. notes = "The original livery of the deprecated "..colour.." tram.",
  88. base_textures = {"advtrains_tlr600_"..colour..".png"},
  89. }
  90. }
  91. livery_templates["advtrains:Tlr600_"..colour.."_front"] = deprecated_tram_livery_templates
  92. livery_templates["advtrains:Tlr600_"..colour.."_back"] = deprecated_tram_livery_templates
  93. end
  94. end
  95. local predefined_liveries = {
  96. {
  97. name = "Original Blue",
  98. notes = "This is the blue color used for the deprecated blue tram",
  99. livery_design = {
  100. livery_template_name = "Toyama",
  101. overlays = {
  102. [3] = {id = 3, color = "#2B73B0"}, -- Service Color
  103. },
  104. },
  105. },
  106. {
  107. name = "Original Green",
  108. notes = "This is the green color used for the deprecated green tram",
  109. livery_design = {
  110. livery_template_name = "Toyama",
  111. overlays = {
  112. [3] = {id = 3, color = "#7AB02B"}, -- Service Color
  113. },
  114. },
  115. },
  116. {
  117. name = "Original Red",
  118. notes = "This is the red color used for the deprecated red tram",
  119. livery_design = {
  120. livery_template_name = "Toyama",
  121. overlays = {
  122. [3] = {id = 3, color = "#EA4524"}, -- Service Color
  123. },
  124. },
  125. },
  126. {
  127. name = "Original Yellow",
  128. notes = "This is the yellow color used for the deprecated yellow tram",
  129. livery_design = {
  130. livery_template_name = "Toyama",
  131. overlays = {
  132. [3] = {id = 3, color = "#EBDB24"}, -- Service Color
  133. },
  134. },
  135. },
  136. {
  137. name = "Beachfront Express",
  138. livery_design = {
  139. livery_template_name = "Toyama",
  140. overlays = {
  141. [1] = {id = 1, color = "#ADD8E6"}, -- Exterior Walls
  142. [2] = {id = 2, color = "#FF7F50"}, -- Window Trim
  143. -- [3] = {id = 3, color = "#000000"}, -- Service Color
  144. [4] = {id = 4, color = "#4169E1"}, -- Seats
  145. },
  146. },
  147. },
  148. {
  149. name = "Historic District Special",
  150. livery_design = {
  151. livery_template_name = "Toyama",
  152. overlays = {
  153. [1] = {id = 1, color = "#F5DEB3"}, -- Exterior Walls
  154. [2] = {id = 2, color = "#2E8B57"}, -- Window Trim
  155. -- [3] = {id = 3, color = "#000000"}, -- Service Color
  156. [4] = {id = 4, color = "#2E8B57"}, -- Seats
  157. },
  158. },
  159. },
  160. {
  161. name = "Airport Shuttle",
  162. livery_design = {
  163. livery_template_name = "Ribbon",
  164. overlays = {
  165. [1] = {id = 1, color = "#87CEEB"}, -- Exterior Walls
  166. [2] = {id = 2, color = "#6FB5D1"}, -- Window Trim
  167. [3] = {id = 3, color = "#0000FF"}, -- Ribbon
  168. [4] = {id = 4, color = "#FAF0E6"}, -- Ribbon Middle
  169. -- [5] = {id = 5, color = "#000000"}, -- Seats
  170. },
  171. },
  172. },
  173. {
  174. name = "Park Service",
  175. livery_design = {
  176. livery_template_name = "Ribbon",
  177. overlays = {
  178. [1] = {id = 1, color = "#F0E68C"}, -- Exterior Walls
  179. [2] = {id = 2, color = "#F0E68C"}, -- Window Trim
  180. [3] = {id = 3, color = "#006400"}, -- Ribbon
  181. [4] = {id = 4, color = "#F0E68C"}, -- Ribbon Middle
  182. [5] = {id = 5, color = "#D2B48C"}, -- Seats
  183. },
  184. },
  185. },
  186. {
  187. name = "Uptown Transit - Red line",
  188. livery_design = {
  189. livery_template_name = "Ribbon",
  190. overlays = {
  191. [1] = {id = 1, color = "#708090"}, -- Exterior Walls
  192. [2] = {id = 2, color = "#090909"}, -- Window Trim
  193. [3] = {id = 3, color = "#800000"}, -- Ribbon
  194. [4] = {id = 4, color = "#FF0000"}, -- Ribbon Middle
  195. [5] = {id = 5, color = "#800000"}, -- Seats
  196. },
  197. },
  198. },
  199. {
  200. name = "Commercial District - Orange line",
  201. livery_design = {
  202. livery_template_name = "Ribbon",
  203. overlays = {
  204. [1] = {id = 1, color = "#008080"}, -- Exterior Walls
  205. [2] = {id = 2, color = "#800000"}, -- Window Trim
  206. -- [3] = {id = 3, color = "#000000"}, -- Ribbon
  207. [4] = {id = 4, color = "#FF4500"}, -- Ribbon Middle
  208. [5] = {id = 5, color = "#008080"}, -- Seats
  209. },
  210. },
  211. },
  212. {
  213. name = "Downtown - Green line",
  214. livery_design = {
  215. livery_template_name = "Upper-Lower Split",
  216. overlays = {
  217. [1] = {id = 1, color = "#C0C0C0"}, -- Upper Walls
  218. [2] = {id = 2, color = "#4682B4"}, -- Window Trim
  219. [3] = {id = 3, color = "#708090"}, -- Lower Walls
  220. [4] = {id = 4, color = "#00FF00"}, -- Service Stripe
  221. [5] = {id = 5, color = "#1B3A5C"}, -- Seats
  222. },
  223. },
  224. },
  225. {
  226. name = "Midtown Commuter",
  227. livery_design = {
  228. livery_template_name = "Upper-Lower Split",
  229. overlays = {
  230. [1] = {id = 1, color = "#C0C0C0"}, -- Upper Walls
  231. [2] = {id = 2, color = "#800000"}, -- Window Trim
  232. [3] = {id = 3, color = "#808080"}, -- Lower Walls
  233. -- [4] = {id = 4, color = "#000000"}, -- Service Stripe
  234. -- [5] = {id = 5, color = "#000000"}, -- Seats
  235. },
  236. },
  237. },
  238. {
  239. name = "Oldtown - Silver line",
  240. livery_design = {
  241. livery_template_name = "Upper-Lower Split",
  242. overlays = {
  243. [1] = {id = 1, color = "#F0FFFF"}, -- Upper Walls
  244. [2] = {id = 2, color = "#202020"}, -- Window Trim
  245. [3] = {id = 3, color = "#1A432C"}, -- Lower Walls
  246. [4] = {id = 4, color = "#C0C0C0"}, -- Service Stripe
  247. [5] = {id = 5, color = "#1A432C"}, -- Seats
  248. },
  249. },
  250. },
  251. {
  252. name = "Suburban Connector - Gold line",
  253. livery_design = {
  254. livery_template_name = "Upper-Lower Split",
  255. overlays = {
  256. [1] = {id = 1, color = "#F4F4F4"}, -- Upper Walls
  257. [2] = {id = 2, color = "#F4F4F4"}, -- Window Trim
  258. [3] = {id = 3, color = "#808080"}, -- Lower Walls
  259. [4] = {id = 4, color = "#FFD700"}, -- Service Stripe
  260. [5] = {id = 5, color = "#2E8B57"}, -- Seats
  261. },
  262. },
  263. },
  264. {
  265. name = "Theater District Shuttle",
  266. livery_design = {
  267. livery_template_name = "Upper-Lower Split",
  268. overlays = {
  269. [1] = {id = 1, color = "#C0C0C0"}, -- Upper Walls
  270. [2] = {id = 2, color = "#460046"}, -- Window Trim
  271. [3] = {id = 3, color = "#8F178F"}, -- Lower Walls
  272. -- [4] = {id = 4, color = "#000000"}, -- Service Stripe
  273. -- [5] = {id = 5, color = "#000000"}, -- Seats
  274. },
  275. },
  276. },
  277. }
  278. if use_advtrains_livery_designer then
  279. -- Notify player if a newer version of AdvTrains Livery Tools is needed.
  280. if not advtrains_livery_designer.is_compatible_mod_version or
  281. not advtrains_livery_designer.is_compatible_mod_version({major = 0, minor = 8, patch = 1}) then
  282. minetest.log("error", "["..mod_name.."] An old version of AdvTrains Livery Tools was detected. Please update to the latest version to avoid known issues.")
  283. -- Version 0.8.1 is needed to fix an issue with activating the livery designer tool for a tram that is in the nighttime/illuminated state.
  284. end
  285. -- This function is called by the advtrains_livery_designer tool whenever
  286. -- the player activates the "Apply" button. This implementation is specific
  287. -- to Tlr600_front and Tlr600_back. A more complex implementation may be
  288. -- needed if other wagons or livery templates are added.
  289. local function apply_wagon_livery_textures(player, wagon, textures)
  290. if wagon and textures and textures[1] then
  291. local data = advtrains.wagons[wagon.id]
  292. data.livery = textures[1]
  293. wagon:set_textures(data)
  294. -- The following will trigger an update of the wagon if it is
  295. -- currently nighttime. This is needed so that the illumination and
  296. -- lighting effect will be applied (if the mod setting is enabled).
  297. -- Because this is dependant on illumination_timer_duration, there
  298. -- can be a short delay before the wagon transitions to its
  299. -- nighttime appearance.
  300. wagon.object:set_properties({glow = 0,})
  301. end
  302. end
  303. -- Define a callback function that will return a wagon's daytime texture
  304. -- regardless the the time of day.
  305. local function on_pre_get_livery_design_from_textures(wagon_type, textures, wagon_id)
  306. local data = advtrains.wagons[wagon_id]
  307. if data and data.livery then
  308. return {data.livery}
  309. end
  310. -- Can't find the wagon or its livery has not yet been defined so just
  311. -- return the textures that were passed in.
  312. return textures
  313. end
  314. local optional_callback_functions = {}
  315. optional_callback_functions.on_pre_get_livery_design_from_textures = on_pre_get_livery_design_from_textures
  316. -- Register this mod and its livery function with the advtrains_livery_designer tool.
  317. advtrains_livery_designer.register_mod(mod_name, apply_wagon_livery_textures, optional_callback_functions)
  318. -- Register this mod's wagons and livery templates.
  319. for wagon_type, wagon_livery_templates in pairs(livery_templates) do
  320. advtrains_livery_database.register_wagon(wagon_type, mod_name)
  321. for _, livery_template in ipairs(wagon_livery_templates) do
  322. advtrains_livery_database.add_livery_template(
  323. wagon_type,
  324. livery_template.name,
  325. livery_template.base_textures,
  326. mod_name,
  327. (livery_template.overlays and #livery_template.overlays) or 0,
  328. livery_template.designer,
  329. livery_template.texture_license,
  330. livery_template.texture_creator,
  331. livery_template.notes
  332. )
  333. if livery_template.overlays then
  334. for overlay_id, overlay in ipairs(livery_template.overlays) do
  335. advtrains_livery_database.add_livery_template_overlay(
  336. wagon_type,
  337. livery_template.name,
  338. overlay_id,
  339. overlay.name,
  340. overlay.slot_idx or 1,
  341. overlay.texture,
  342. overlay.alpha
  343. )
  344. end
  345. end
  346. end
  347. end
  348. -- Register this mod's predefined wagon liveries.
  349. for _, predefined_livery in pairs(predefined_liveries) do
  350. -- Each predefined livery will be defined for each generic TLR0600 unit.
  351. for _, wagon_type in pairs({generic_tlr0600_front_unit, generic_tlr0600_back_unit}) do
  352. local livery_design = predefined_livery.livery_design
  353. livery_design.wagon_type = wagon_type
  354. advtrains_livery_database.add_predefined_livery(
  355. predefined_livery.name,
  356. livery_design,
  357. mod_name,
  358. predefined_livery.notes
  359. )
  360. end
  361. end
  362. end
  363. local function set_textures(wagon, data)
  364. if data.livery then
  365. wagon.object:set_properties({textures={data.livery}})
  366. end
  367. end
  368. local function update_livery(wagon, puncher)
  369. local itemstack = puncher:get_wielded_item()
  370. local item_name = itemstack:get_name()
  371. if use_advtrains_livery_designer and item_name == advtrains_livery_designer.tool_name then
  372. advtrains_livery_designer.activate_tool(puncher, wagon, mod_name)
  373. return true
  374. end
  375. return false
  376. end
  377. -- End of support code for AdvTrains Livery Designer
  378. local function on_custom_on_step(self, dtime, wagon_default_texture_name, tram_end)
  379. local illumination_timer = (self.illumination_timer or 0) - dtime
  380. if illumination_timer <= 0 then
  381. local data = advtrains.wagons[self.id]
  382. local current_livery = data and data.livery or wagon_default_texture_name
  383. local time = minetest.get_timeofday() * 24000
  384. local properties = self.object:get_properties()
  385. local current_glow = properties.glow or 0
  386. if (time > illumination_start_time or time < illumination_end_time) then
  387. -- To minimize server load, only set properties if they have changed.
  388. if current_glow ~= 5 then
  389. -- Set nighttime configuration
  390. self.object:set_properties({textures = {
  391. current_livery.."^("..current_livery.."^[mask:advtrains_tlr600_common_exterior_mask.png^[multiply:#464646)^advtrains_tlr600_common_illumination.png^advtrains_tlr600_common_lights_"..tram_end..".png"},})
  392. self.object:set_properties({glow = 5,})
  393. end
  394. else
  395. -- To minimize server load, only set properties if they have changed.
  396. if current_glow ~= 0 then
  397. -- Set daytime configuration
  398. self.object:set_properties({textures = {current_livery},})
  399. self.object:set_properties({glow = 0,})
  400. end
  401. end
  402. self.illumination_timer = illumination_timer_duration
  403. else
  404. self.illumination_timer = illumination_timer
  405. end
  406. end
  407. local colours = {
  408. "custom",
  409. }
  410. if include_deprecated_trams then
  411. for _,colour in pairs(deprecated_tram_colours) do
  412. table.insert(colours, colour)
  413. end
  414. end
  415. for _,colour in pairs(colours) do
  416. local use_predefined_color = colour ~= "custom"
  417. local wagon_info = {}
  418. if use_predefined_color then
  419. -- Register the deprecated trams using their original names in the
  420. -- advtrains namespace as had been done in earlier version of this mod.
  421. wagon_info.front = {
  422. internal_name = "Tlr600_"..colour.."_front",
  423. display_name = "Tlr600_"..colour.."_front",
  424. default_texture_name = "advtrains_tlr600_"..colour..".png",
  425. inventory_image_name = "advtrains_tlr600_"..colour.."_inv.png",
  426. }
  427. wagon_info.back = {
  428. internal_name = "Tlr600_"..colour.."_back",
  429. display_name = "Tlr600_"..colour.."_back",
  430. default_texture_name = "advtrains_tlr600_"..colour..".png",
  431. inventory_image_name = "advtrains_tlr600_"..colour.."_inv.png",
  432. }
  433. else
  434. -- Register the generic TLR0600 trams in this mod's namespace.
  435. wagon_info.front = {
  436. internal_name = generic_tlr0600_front_unit,
  437. display_name = "TLR0600 Front Unit",
  438. default_texture_name = "advtrains_tlr600_01.png",
  439. inventory_image_name = "advtrains_tlr600_front_inv.png",
  440. }
  441. wagon_info.back = {
  442. internal_name = generic_tlr0600_back_unit,
  443. display_name = "TLR0600 Back Unit",
  444. default_texture_name = "advtrains_tlr600_01.png",
  445. inventory_image_name = "advtrains_tlr600_back_inv.png",
  446. }
  447. end
  448. -- TLR0600 <FRONT>
  449. local wagon_def_front = {
  450. mesh="advtrains_tlr600_front.b3d",
  451. textures = {wagon_info.front.default_texture_name},
  452. set_textures = set_textures,
  453. custom_may_destroy = function(wagon, puncher, time_from_last_punch, tool_capabilities, direction)
  454. return not update_livery(wagon, puncher)
  455. end,
  456. drives_on={default=true},
  457. max_speed=8,
  458. seats = {
  459. {
  460. name=S("Driver stand"),
  461. attach_offset={x=0, y=-4, z=20},
  462. view_offset={x=0, y=-4, z=2},
  463. driving_ctrl_access=true,
  464. group="dstand",
  465. },
  466. {
  467. name="1",
  468. attach_offset={x=-4, y=-4, z=0},
  469. view_offset={x=0, y=-4, z=0},
  470. group="pass",
  471. },
  472. {
  473. name="2",
  474. attach_offset={x=4, y=-4, z=0},
  475. view_offset={x=0, y=-4, z=0},
  476. group="pass",
  477. },
  478. {
  479. name="3",
  480. attach_offset={x=-4, y=-4, z=-8},
  481. view_offset={x=0, y=-4, z=0},
  482. group="pass",
  483. },
  484. {
  485. name="4",
  486. attach_offset={x=4, y=-4, z=-8},
  487. view_offset={x=0, y=-4, z=0},
  488. group="pass",
  489. },
  490. },
  491. seat_groups = {
  492. dstand={
  493. name = "Driver Stand",
  494. access_to = {"pass"},
  495. driving_ctrl_access=true,
  496. },
  497. pass={
  498. name = "Passenger area",
  499. access_to = {"dstand"},
  500. require_doors_open=true,
  501. },
  502. },
  503. assign_to_seat_group = {"dstand", "pass"},
  504. doors={
  505. open={
  506. [-1]={frames={x=0, y=40}, time=1},
  507. [1]={frames={x=80, y=120}, time=1},
  508. sound = "advtrains_tlr600_dclose",
  509. },
  510. close={
  511. [-1]={frames={x=40, y=80}, time=1},
  512. [1]={frames={x=120, y=160}, time=1},
  513. sound = "advtrains_tlr600_dclose",
  514. }
  515. },
  516. door_entry={-1},
  517. assign_to_seat_group = {"dstand", "pass"},
  518. visual_size = {x=1, y=1},
  519. wagon_span=2.3,
  520. is_locomotive=true,
  521. collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
  522. drops={"default:steelblock 4"},
  523. horn_sound = "advtrains_tlr600_horn",
  524. custom_on_velocity_change = function(self, velocity, old_velocity, dtime)
  525. if not velocity or not old_velocity then return end
  526. if velocity > 0 and (self.sound_loop_tmr or 0)<=0 then
  527. self.sound_loop_handle = minetest.sound_play({name="advtrains_tlr600_loop", gain=0.3}, {object = self.object})
  528. self.sound_loop_tmr=3
  529. elseif velocity>0 then
  530. self.sound_loop_tmr = self.sound_loop_tmr - dtime
  531. elseif velocity==0 then
  532. if self.sound_loop_handle then
  533. minetest.sound_stop(self.sound_loop_handle)
  534. self.sound_loop_handle = nil
  535. end
  536. self.sound_loop_tmr=0
  537. end
  538. end,
  539. custom_on_step = use_illuminated_appearance and function(self, dtime)
  540. on_custom_on_step(self, dtime, wagon_info.front.default_texture_name, "front")
  541. end
  542. }
  543. advtrains.register_wagon(wagon_info.front.internal_name, wagon_def_front, wagon_info.front.display_name, wagon_info.front.inventory_image_name)
  544. -- TLR0600 <BACK>
  545. local wagon_def_back = {
  546. mesh="advtrains_tlr600_back.b3d",
  547. textures = {wagon_info.back.default_texture_name},
  548. set_textures = set_textures,
  549. custom_may_destroy = function(wagon, puncher, time_from_last_punch, tool_capabilities, direction)
  550. return not update_livery(wagon, puncher)
  551. end,
  552. drives_on={default=true},
  553. max_speed=8,
  554. seats = {
  555. {
  556. name="1",
  557. attach_offset={x=-4, y=-4, z=8},
  558. view_offset={x=0, y=-4, z=0},
  559. group="pass",
  560. },
  561. {
  562. name="2",
  563. attach_offset={x=4, y=-4, z=8},
  564. view_offset={x=0, y=-4, z=0},
  565. group="pass",
  566. },
  567. {
  568. name="3",
  569. attach_offset={x=-4, y=-4, z=-8},
  570. view_offset={x=0, y=-4, z=0},
  571. group="pass",
  572. },
  573. {
  574. name="4",
  575. attach_offset={x=4, y=-4, z=-8},
  576. view_offset={x=0, y=-4, z=0},
  577. group="pass",
  578. },
  579. },
  580. seat_groups = {
  581. pass={
  582. name = "Passenger area",
  583. access_to = {},
  584. require_doors_open=true,
  585. },
  586. },
  587. assign_to_seat_group = {"pass"},
  588. doors={
  589. open={
  590. [-1]={frames={x=0, y=40}, time=1},
  591. [1]={frames={x=80, y=120}, time=1}
  592. },
  593. close={
  594. [-1]={frames={x=40, y=80}, time=1},
  595. [1]={frames={x=120, y=160}, time=1}
  596. }
  597. },
  598. door_entry={-1, 1},
  599. visual_size = {x=1, y=1},
  600. wagon_span=2.1,
  601. collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
  602. drops={"default:steelblock 4"},
  603. custom_on_step = use_illuminated_appearance and function(self, dtime)
  604. on_custom_on_step(self, dtime, wagon_info.back.default_texture_name, "rear")
  605. end
  606. }
  607. advtrains.register_wagon(wagon_info.back.internal_name, wagon_def_back, wagon_info.back.display_name, wagon_info.back.inventory_image_name)
  608. end
  609. if minetest.get_modpath("default") then
  610. local door = "default:steel_ingot"
  611. if minetest.get_modpath("doors") then
  612. door = "doors:door_steel"
  613. end
  614. local cabin = mod_name..":TLR0600_cabin"
  615. minetest.register_craftitem(cabin, {
  616. description = attrans("TLR0600 Cabin"),
  617. inventory_image = "advtrains_tlr600_cabin.png",
  618. })
  619. minetest.register_craft({
  620. output = cabin,
  621. recipe = {
  622. {"default:tinblock", "default:tinblock", "default:tinblock"},
  623. {door, "wool:white", "default:glass"},
  624. {"default:steelblock", "default:steelblock", "default:steelblock"},
  625. }
  626. })
  627. minetest.register_craft({
  628. output = generic_tlr0600_front_unit,
  629. recipe = {
  630. {"", cabin, "default:steel_ingot"},
  631. {"advtrains:wheel", "default:steelblock", "advtrains:wheel"},
  632. }
  633. })
  634. minetest.register_craft({
  635. output = generic_tlr0600_back_unit,
  636. recipe = {
  637. {"", "default:copperblock", ""},
  638. {"", cabin, "default:steel_ingot"},
  639. {"advtrains:wheel", "default:steelblock", "advtrains:wheel"},
  640. }
  641. })
  642. end