Restructure mod directory
authororwell96 <mono96.mml@gmail.com>
Wed, 4 Jan 2017 18:10:03 +0000 (19:10 +0100)
committerorwell96 <mono96.mml@gmail.com>
Wed, 4 Jan 2017 18:10:03 +0000 (19:10 +0100)
470 files changed:
Makefile [deleted file]
advtrains.zip [deleted file]
advtrains/Makefile [new file with mode: 0644]
advtrains/advtrains.zip [new file with mode: 0644]
advtrains/advtrains/api_doc.txt [new file with mode: 0644]
advtrains/advtrains/atc.lua [new file with mode: 0644]
advtrains/advtrains/atc_command.txt [new file with mode: 0644]
advtrains/advtrains/couple.lua [new file with mode: 0644]
advtrains/advtrains/crafting.lua [new file with mode: 0644]
advtrains/advtrains/damage.lua [new file with mode: 0644]
advtrains/advtrains/debugitems.lua [new file with mode: 0644]
advtrains/advtrains/depends.txt [new file with mode: 0644]
advtrains/advtrains/description.txt [new file with mode: 0644]
advtrains/advtrains/helpers.lua [new file with mode: 0644]
advtrains/advtrains/init.lua [new file with mode: 0644]
advtrains/advtrains/misc_nodes.lua [new file with mode: 0644]
advtrains/advtrains/models/advtrains_dtrack_bumper_st.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_dtrack_bumper_st_30.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_dtrack_bumper_st_45.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_dtrack_bumper_st_60.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_dtrack_cr.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_dtrack_cr_30.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_dtrack_cr_45.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_dtrack_cr_60.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_dtrack_detector_st.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_dtrack_detector_st_30.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_dtrack_detector_st_45.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_dtrack_detector_st_60.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_dtrack_st.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_dtrack_st_30.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_dtrack_st_45.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_dtrack_st_60.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_dtrack_swlcr.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_dtrack_swlcr_30.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_dtrack_swlcr_45.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_dtrack_swlcr_60.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_dtrack_swlst.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_dtrack_swlst_30.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_dtrack_swlst_45.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_dtrack_swlst_60.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_dtrack_swrcr.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_dtrack_swrcr_30.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_dtrack_swrcr_45.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_dtrack_swrcr_60.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_dtrack_swrst.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_dtrack_swrst_30.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_dtrack_swrst_45.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_dtrack_swrst_60.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_dtrack_vst1.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_dtrack_vst1_45.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_dtrack_vst2.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_dtrack_vst2_45.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_dtrack_vst31.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_dtrack_vst32.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_dtrack_vst33.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_modernwagon.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_retrosignal_off.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_retrosignal_off_30.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_retrosignal_off_45.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_retrosignal_off_60.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_retrosignal_on.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_retrosignal_on_30.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_retrosignal_on_45.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_retrosignal_on_60.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_signal.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_signal_30.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_signal_45.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_signal_60.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_track_cr.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_track_st.b3d [new file with mode: 0644]
advtrains/advtrains/models/advtrains_track_st_45.b3d [new file with mode: 0644]
advtrains/advtrains/models/trackplane.b3d [new file with mode: 0644]
advtrains/advtrains/pseudoload.lua [new file with mode: 0644]
advtrains/advtrains/readme.txt [new file with mode: 0644]
advtrains/advtrains/signals.lua [new file with mode: 0644]
advtrains/advtrains/textures/advtrains_couple.png [new file with mode: 0644]
advtrains/advtrains/textures/advtrains_discouple.png [new file with mode: 0644]
advtrains/advtrains/textures/advtrains_dtrack_atc_placer.png [new file with mode: 0644]
advtrains/advtrains/textures/advtrains_dtrack_bumper_placer.png [new file with mode: 0644]
advtrains/advtrains/textures/advtrains_dtrack_detector_placer.png [new file with mode: 0644]
advtrains/advtrains/textures/advtrains_dtrack_placer.png [new file with mode: 0644]
advtrains/advtrains/textures/advtrains_dtrack_rail.png [new file with mode: 0644]
advtrains/advtrains/textures/advtrains_dtrack_rail_atc.png [new file with mode: 0644]
advtrains/advtrains/textures/advtrains_dtrack_rail_detector_on.png [new file with mode: 0644]
advtrains/advtrains/textures/advtrains_dtrack_slopeplacer.png [new file with mode: 0644]
advtrains/advtrains/textures/advtrains_platform.png [new file with mode: 0644]
advtrains/advtrains/textures/advtrains_retrosignal.png [new file with mode: 0644]
advtrains/advtrains/textures/advtrains_retrosignal_inv.png [new file with mode: 0644]
advtrains/advtrains/textures/advtrains_signal_inv.png [new file with mode: 0644]
advtrains/advtrains/textures/advtrains_signal_off.png [new file with mode: 0644]
advtrains/advtrains/textures/advtrains_signal_on.png [new file with mode: 0644]
advtrains/advtrains/textures/advtrains_track_cr.png [new file with mode: 0644]
advtrains/advtrains/textures/advtrains_track_cr_45.png [new file with mode: 0644]
advtrains/advtrains/textures/advtrains_track_placer.png [new file with mode: 0644]
advtrains/advtrains/textures/advtrains_track_st.png [new file with mode: 0644]
advtrains/advtrains/textures/advtrains_track_st_45.png [new file with mode: 0644]
advtrains/advtrains/textures/advtrains_track_swlcr.png [new file with mode: 0644]
advtrains/advtrains/textures/advtrains_track_swlcr_45.png [new file with mode: 0644]
advtrains/advtrains/textures/advtrains_track_swlst.png [new file with mode: 0644]
advtrains/advtrains/textures/advtrains_track_swlst_45.png [new file with mode: 0644]
advtrains/advtrains/textures/advtrains_track_swrcr.png [new file with mode: 0644]
advtrains/advtrains/textures/advtrains_track_swrcr_45.png [new file with mode: 0644]
advtrains/advtrains/textures/advtrains_track_swrst.png [new file with mode: 0644]
advtrains/advtrains/textures/advtrains_track_swrst_45.png [new file with mode: 0644]
advtrains/advtrains/textures/advtrains_trackworker.png [new file with mode: 0644]
advtrains/advtrains/textures/drwho_screwdriver.png [new file with mode: 0644]
advtrains/advtrains/trackplacer.lua [new file with mode: 0644]
advtrains/advtrains/tracks.lua [new file with mode: 0644]
advtrains/advtrains/trainhud.lua [new file with mode: 0644]
advtrains/advtrains/trainlogic.lua [new file with mode: 0644]
advtrains/advtrains/wagons.lua [new file with mode: 0644]
advtrains/advtrains_train_industrial/depends.txt [new file with mode: 0644]
advtrains/advtrains_train_industrial/init.lua [new file with mode: 0644]
advtrains/advtrains_train_industrial/models/advtrains_engine_industrial.b3d [new file with mode: 0644]
advtrains/advtrains_train_industrial/models/advtrains_wagon_tank.b3d [new file with mode: 0644]
advtrains/advtrains_train_industrial/models/advtrains_wagon_wood.b3d [new file with mode: 0644]
advtrains/advtrains_train_industrial/textures/advtrains_engine_industrial.png [new file with mode: 0644]
advtrains/advtrains_train_industrial/textures/advtrains_engine_industrial_inv.png [new file with mode: 0644]
advtrains/advtrains_train_industrial/textures/advtrains_wagon_tank.png [new file with mode: 0644]
advtrains/advtrains_train_industrial/textures/advtrains_wagon_tank_inv.png [new file with mode: 0644]
advtrains/advtrains_train_industrial/textures/advtrains_wagon_wood.png [new file with mode: 0644]
advtrains/advtrains_train_industrial/textures/advtrains_wagon_wood_inv.png [new file with mode: 0644]
advtrains/advtrains_train_japan/depends.txt [new file with mode: 0644]
advtrains/advtrains_train_japan/init.lua [new file with mode: 0644]
advtrains/advtrains_train_japan/models/advtrains_engine_japan.b3d [new file with mode: 0644]
advtrains/advtrains_train_japan/models/advtrains_wagon_japan.b3d [new file with mode: 0644]
advtrains/advtrains_train_japan/textures/advtrains_engine_japan.png [new file with mode: 0644]
advtrains/advtrains_train_japan/textures/advtrains_engine_japan_inv.png [new file with mode: 0644]
advtrains/advtrains_train_japan/textures/advtrains_wagon_japan.png [new file with mode: 0644]
advtrains/advtrains_train_japan/textures/advtrains_wagon_japan_inv.png [new file with mode: 0644]
advtrains/advtrains_train_steam/depends.txt [new file with mode: 0644]
advtrains/advtrains_train_steam/init.lua [new file with mode: 0644]
advtrains/advtrains_train_steam/models/advtrains_engine_steam.b3d [new file with mode: 0644]
advtrains/advtrains_train_steam/models/advtrains_wagon.b3d [new file with mode: 0644]
advtrains/advtrains_train_steam/textures/advtrains_newlocomotive.png [new file with mode: 0644]
advtrains/advtrains_train_steam/textures/advtrains_newlocomotive_inv.png [new file with mode: 0644]
advtrains/advtrains_train_steam/textures/advtrains_wagon.png [new file with mode: 0644]
advtrains/advtrains_train_steam/textures/advtrains_wagon_box.png [new file with mode: 0644]
advtrains/advtrains_train_steam/textures/advtrains_wagon_box_inv.png [new file with mode: 0644]
advtrains/advtrains_train_steam/textures/advtrains_wagon_inv.png [new file with mode: 0644]
advtrains/advtrains_train_subway/depends.txt [new file with mode: 0644]
advtrains/advtrains_train_subway/init.lua [new file with mode: 0644]
advtrains/advtrains_train_subway/models/advtrains_subway_train.b3d [new file with mode: 0644]
advtrains/advtrains_train_subway/textures/advtrains_subway_train.png [new file with mode: 0644]
advtrains/advtrains_train_subway/textures/advtrains_subway_train_inv.png [new file with mode: 0644]
advtrains/api_doc.txt [deleted file]
advtrains/atc.lua [deleted file]
advtrains/atc_command.txt [deleted file]
advtrains/couple.lua [deleted file]
advtrains/crafting.lua [deleted file]
advtrains/damage.lua [deleted file]
advtrains/debugitems.lua [deleted file]
advtrains/depends.txt [deleted file]
advtrains/description.txt [deleted file]
advtrains/helpers.lua [deleted file]
advtrains/init.lua [deleted file]
advtrains/license.txt [new file with mode: 0644]
advtrains/license_media.txt [new file with mode: 0644]
advtrains/manual.pdf [new file with mode: 0644]
advtrains/misc_nodes.lua [deleted file]
advtrains/models/advtrains_dtrack_bumper_st.b3d [deleted file]
advtrains/models/advtrains_dtrack_bumper_st_30.b3d [deleted file]
advtrains/models/advtrains_dtrack_bumper_st_45.b3d [deleted file]
advtrains/models/advtrains_dtrack_bumper_st_60.b3d [deleted file]
advtrains/models/advtrains_dtrack_cr.b3d [deleted file]
advtrains/models/advtrains_dtrack_cr_30.b3d [deleted file]
advtrains/models/advtrains_dtrack_cr_45.b3d [deleted file]
advtrains/models/advtrains_dtrack_cr_60.b3d [deleted file]
advtrains/models/advtrains_dtrack_detector_st.b3d [deleted file]
advtrains/models/advtrains_dtrack_detector_st_30.b3d [deleted file]
advtrains/models/advtrains_dtrack_detector_st_45.b3d [deleted file]
advtrains/models/advtrains_dtrack_detector_st_60.b3d [deleted file]
advtrains/models/advtrains_dtrack_st.b3d [deleted file]
advtrains/models/advtrains_dtrack_st_30.b3d [deleted file]
advtrains/models/advtrains_dtrack_st_45.b3d [deleted file]
advtrains/models/advtrains_dtrack_st_60.b3d [deleted file]
advtrains/models/advtrains_dtrack_swlcr.b3d [deleted file]
advtrains/models/advtrains_dtrack_swlcr_30.b3d [deleted file]
advtrains/models/advtrains_dtrack_swlcr_45.b3d [deleted file]
advtrains/models/advtrains_dtrack_swlcr_60.b3d [deleted file]
advtrains/models/advtrains_dtrack_swlst.b3d [deleted file]
advtrains/models/advtrains_dtrack_swlst_30.b3d [deleted file]
advtrains/models/advtrains_dtrack_swlst_45.b3d [deleted file]
advtrains/models/advtrains_dtrack_swlst_60.b3d [deleted file]
advtrains/models/advtrains_dtrack_swrcr.b3d [deleted file]
advtrains/models/advtrains_dtrack_swrcr_30.b3d [deleted file]
advtrains/models/advtrains_dtrack_swrcr_45.b3d [deleted file]
advtrains/models/advtrains_dtrack_swrcr_60.b3d [deleted file]
advtrains/models/advtrains_dtrack_swrst.b3d [deleted file]
advtrains/models/advtrains_dtrack_swrst_30.b3d [deleted file]
advtrains/models/advtrains_dtrack_swrst_45.b3d [deleted file]
advtrains/models/advtrains_dtrack_swrst_60.b3d [deleted file]
advtrains/models/advtrains_dtrack_vst1.b3d [deleted file]
advtrains/models/advtrains_dtrack_vst1_45.b3d [deleted file]
advtrains/models/advtrains_dtrack_vst2.b3d [deleted file]
advtrains/models/advtrains_dtrack_vst2_45.b3d [deleted file]
advtrains/models/advtrains_dtrack_vst31.b3d [deleted file]
advtrains/models/advtrains_dtrack_vst32.b3d [deleted file]
advtrains/models/advtrains_dtrack_vst33.b3d [deleted file]
advtrains/models/advtrains_modernwagon.b3d [deleted file]
advtrains/models/advtrains_retrosignal_off.b3d [deleted file]
advtrains/models/advtrains_retrosignal_off_30.b3d [deleted file]
advtrains/models/advtrains_retrosignal_off_45.b3d [deleted file]
advtrains/models/advtrains_retrosignal_off_60.b3d [deleted file]
advtrains/models/advtrains_retrosignal_on.b3d [deleted file]
advtrains/models/advtrains_retrosignal_on_30.b3d [deleted file]
advtrains/models/advtrains_retrosignal_on_45.b3d [deleted file]
advtrains/models/advtrains_retrosignal_on_60.b3d [deleted file]
advtrains/models/advtrains_signal.b3d [deleted file]
advtrains/models/advtrains_signal_30.b3d [deleted file]
advtrains/models/advtrains_signal_45.b3d [deleted file]
advtrains/models/advtrains_signal_60.b3d [deleted file]
advtrains/models/advtrains_track_cr.b3d [deleted file]
advtrains/models/advtrains_track_st.b3d [deleted file]
advtrains/models/advtrains_track_st_45.b3d [deleted file]
advtrains/models/blender/engine-with-animation.blend [deleted file]
advtrains/models/blender/gleis/detectorpart.png [deleted file]
advtrains/models/blender/gleis/infos/Grafik_weiche.png [deleted file]
advtrains/models/blender/gleis/infos/breite [deleted file]
advtrains/models/blender/gleis/licence.txt~ [deleted file]
advtrains/models/blender/gleis/rail_my.blend [deleted file]
advtrains/models/blender/gleis/rail_my.blend1 [deleted file]
advtrains/models/blender/gleis/rail_my_rt.blend [deleted file]
advtrains/models/blender/gleis/rail_my_rt.blend1 [deleted file]
advtrains/models/blender/gleis/rail_my_rt_final.blend [deleted file]
advtrains/models/blender/gleis/rail_my_rt_final.blend1 [deleted file]
advtrains/models/blender/gleis/rail_my_rt_switches.blend [deleted file]
advtrains/models/blender/gleis/rail_my_rt_switches.blend1 [deleted file]
advtrains/models/blender/gleis/rail_my_rt_switches2.blend [deleted file]
advtrains/models/blender/gleis/rail_my_rt_switches2.blend1 [deleted file]
advtrains/models/blender/gleis/rail_together.blend [deleted file]
advtrains/models/blender/gleis/rail_together.png [deleted file]
advtrains/models/blender/gleis/rail_together2.png [deleted file]
advtrains/models/blender/gleis/rail_together3.png [deleted file]
advtrains/models/blender/gleis/rail_verticals.blend [deleted file]
advtrains/models/blender/gleis/rail_verticals.blend1 [deleted file]
advtrains/models/blender/gleis/rail_verticals3.blend [deleted file]
advtrains/models/blender/gleis/rail_verticals3.blend1 [deleted file]
advtrains/models/blender/gleis/rail_verticals45.blend [deleted file]
advtrains/models/blender/gleis/rail_verticals45.blend1 [deleted file]
advtrains/models/blender/gleis/rail_verticals45.blend11 [deleted file]
advtrains/models/blender/gleis/texturen/rail.png [deleted file]
advtrains/models/blender/gleis/texturen/uv.png [deleted file]
advtrains/models/blender/industrial/industry_loc.blend [deleted file]
advtrains/models/blender/industrial/industry_loc.blend1 [deleted file]
advtrains/models/blender/industrial/industry_loc.blend11 [deleted file]
advtrains/models/blender/industrial/industry_oil_ wagong.blend [deleted file]
advtrains/models/blender/industrial/industry_oil_ wagong.blend1 [deleted file]
advtrains/models/blender/industrial/industry_tree_wagong.blend [deleted file]
advtrains/models/blender/industrial/industry_tree_wagong.blend1 [deleted file]
advtrains/models/blender/industrial/industry_tree_wagong.png [deleted file]
advtrains/models/blender/locomotive.blend [deleted file]
advtrains/models/blender/magnet_track.blend [deleted file]
advtrains/models/blender/mbb/advtrains_wagon_japan.xcf [deleted file]
advtrains/models/blender/mbb/modern_japanlocomotive.blend [deleted file]
advtrains/models/blender/mbb/modern_japanlocomotive.blend1 [deleted file]
advtrains/models/blender/mbb/modern_japanlocomotive.png [deleted file]
advtrains/models/blender/mbb/modern_japanlocomotive.xcf [deleted file]
advtrains/models/blender/mbb/modern_locomotive.blend [deleted file]
advtrains/models/blender/mbb/modern_wagong.blend [deleted file]
advtrains/models/blender/mbb/modern_wagong.blend1 [deleted file]
advtrains/models/blender/mbb/modern_wagong_uv.blend [deleted file]
advtrains/models/blender/mbb/modern_wagong_uv.blend1 [deleted file]
advtrains/models/blender/mbb/modern_wagong_uv.png [deleted file]
advtrains/models/blender/mbb/prellbock.blend [deleted file]
advtrains/models/blender/mbb/prellbock.blend1 [deleted file]
advtrains/models/blender/mbb/prellbock.uv.png [deleted file]
advtrains/models/blender/mbb/regio-lokomotive.blend [deleted file]
advtrains/models/blender/mbb/regio-waron.blend [deleted file]
advtrains/models/blender/mbb/retrosignal.blend [deleted file]
advtrains/models/blender/mbb/retrosignal.blend1 [deleted file]
advtrains/models/blender/mbb/signal(2)_hoch.blend [deleted file]
advtrains/models/blender/mbb/signal(2)_unten.blend [deleted file]
advtrains/models/blender/mbb/signal.blend [deleted file]
advtrains/models/blender/mbb/signal.blend1 [deleted file]
advtrains/models/blender/mbb/signal.png [deleted file]
advtrains/models/blender/mbb/signal.xcf [deleted file]
advtrains/models/blender/mbb/signal2.png [deleted file]
advtrains/models/blender/mbb/tr-logo.png [deleted file]
advtrains/models/blender/mbb/weichenhebel1.blend [deleted file]
advtrains/models/blender/mbb/weichenhebel2.blend [deleted file]
advtrains/models/blender/newlocomotive.blend [deleted file]
advtrains/models/blender/newlocomotive.blend1 [deleted file]
advtrains/models/blender/newlocomotive_uvs.png [deleted file]
advtrains/models/blender/newwagon.blend [deleted file]
advtrains/models/blender/newwagon.blend1 [deleted file]
advtrains/models/blender/newwagon.png [deleted file]
advtrains/models/blender/subway-train.blend [deleted file]
advtrains/models/blender/subway-train.blend1 [deleted file]
advtrains/models/blender/subway-train.png [deleted file]
advtrains/models/blender/subway-train.xcf [deleted file]
advtrains/models/blender/trackplane.blend [deleted file]
advtrains/models/blender/trackvertical1.blend [deleted file]
advtrains/models/blender/trackvertical1.blend1 [deleted file]
advtrains/models/blender/trackvertical1.png [deleted file]
advtrains/models/blender/trackvertical2.blend [deleted file]
advtrains/models/blender/trackvertical2.png [deleted file]
advtrains/models/oldmodels/locomotive.b3d [deleted file]
advtrains/models/oldmodels/trackvertical1.b3d [deleted file]
advtrains/models/oldmodels/trackvertical2.b3d [deleted file]
advtrains/models/trackplane.b3d [deleted file]
advtrains/modpack.txt [new file with mode: 0644]
advtrains/pseudoload.lua [deleted file]
advtrains/readme.txt [deleted file]
advtrains/screenshot.png [new file with mode: 0644]
advtrains/signals.lua [deleted file]
advtrains/textures/advtrains_couple.png [deleted file]
advtrains/textures/advtrains_discouple.png [deleted file]
advtrains/textures/advtrains_dtrack_atc_placer.png [deleted file]
advtrains/textures/advtrains_dtrack_bumper_placer.png [deleted file]
advtrains/textures/advtrains_dtrack_detector_placer.png [deleted file]
advtrains/textures/advtrains_dtrack_placer.png [deleted file]
advtrains/textures/advtrains_dtrack_rail.png [deleted file]
advtrains/textures/advtrains_dtrack_rail_atc.png [deleted file]
advtrains/textures/advtrains_dtrack_rail_detector_on.png [deleted file]
advtrains/textures/advtrains_dtrack_slopeplacer.png [deleted file]
advtrains/textures/advtrains_newlocomotive.xcf [deleted file]
advtrains/textures/advtrains_platform.png [deleted file]
advtrains/textures/advtrains_retrosignal.png [deleted file]
advtrains/textures/advtrains_retrosignal_inv.png [deleted file]
advtrains/textures/advtrains_signal_inv.png [deleted file]
advtrains/textures/advtrains_signal_off.png [deleted file]
advtrains/textures/advtrains_signal_on.png [deleted file]
advtrains/textures/advtrains_track_cr.png [deleted file]
advtrains/textures/advtrains_track_cr_45.png [deleted file]
advtrains/textures/advtrains_track_placer.png [deleted file]
advtrains/textures/advtrains_track_st.png [deleted file]
advtrains/textures/advtrains_track_st_45.png [deleted file]
advtrains/textures/advtrains_track_swlcr.png [deleted file]
advtrains/textures/advtrains_track_swlcr_45.png [deleted file]
advtrains/textures/advtrains_track_swlst.png [deleted file]
advtrains/textures/advtrains_track_swlst_45.png [deleted file]
advtrains/textures/advtrains_track_swrcr.png [deleted file]
advtrains/textures/advtrains_track_swrcr_45.png [deleted file]
advtrains/textures/advtrains_track_swrst.png [deleted file]
advtrains/textures/advtrains_track_swrst_45.png [deleted file]
advtrains/textures/advtrains_trackworker.png [deleted file]
advtrains/textures/drwho_screwdriver.png [deleted file]
advtrains/textures/larger rails.xcf [deleted file]
advtrains/trackplacer.lua [deleted file]
advtrains/tracks.lua [deleted file]
advtrains/trainhud.lua [deleted file]
advtrains/trainlogic.lua [deleted file]
advtrains/wagons.lua [deleted file]
advtrains_train_industrial/depends.txt [deleted file]
advtrains_train_industrial/init.lua [deleted file]
advtrains_train_industrial/models/advtrains_engine_industrial.b3d [deleted file]
advtrains_train_industrial/models/advtrains_wagon_tank.b3d [deleted file]
advtrains_train_industrial/models/advtrains_wagon_wood.b3d [deleted file]
advtrains_train_industrial/textures/advtrains_engine_industrial.png [deleted file]
advtrains_train_industrial/textures/advtrains_engine_industrial_inv.png [deleted file]
advtrains_train_industrial/textures/advtrains_wagon_tank.png [deleted file]
advtrains_train_industrial/textures/advtrains_wagon_tank_inv.png [deleted file]
advtrains_train_industrial/textures/advtrains_wagon_wood.png [deleted file]
advtrains_train_industrial/textures/advtrains_wagon_wood_inv.png [deleted file]
advtrains_train_japan/depends.txt [deleted file]
advtrains_train_japan/init.lua [deleted file]
advtrains_train_japan/models/advtrains_engine_japan.b3d [deleted file]
advtrains_train_japan/models/advtrains_wagon_japan.b3d [deleted file]
advtrains_train_japan/textures/advtrains_engine_japan.png [deleted file]
advtrains_train_japan/textures/advtrains_engine_japan_inv.png [deleted file]
advtrains_train_japan/textures/advtrains_wagon_japan.png [deleted file]
advtrains_train_japan/textures/advtrains_wagon_japan_inv.png [deleted file]
advtrains_train_steam/depends.txt [deleted file]
advtrains_train_steam/init.lua [deleted file]
advtrains_train_steam/models/advtrains_engine_steam.b3d [deleted file]
advtrains_train_steam/models/advtrains_wagon.b3d [deleted file]
advtrains_train_steam/textures/advtrains_newlocomotive.png [deleted file]
advtrains_train_steam/textures/advtrains_newlocomotive_inv.png [deleted file]
advtrains_train_steam/textures/advtrains_wagon.png [deleted file]
advtrains_train_steam/textures/advtrains_wagon_box.png [deleted file]
advtrains_train_steam/textures/advtrains_wagon_box_inv.png [deleted file]
advtrains_train_steam/textures/advtrains_wagon_inv.png [deleted file]
advtrains_train_subway/depends.txt [deleted file]
advtrains_train_subway/init.lua [deleted file]
advtrains_train_subway/models/advtrains_subway_train.b3d [deleted file]
advtrains_train_subway/textures/advtrains_subway_train.png [deleted file]
advtrains_train_subway/textures/advtrains_subway_train_inv.png [deleted file]
assets/advtrains_newlocomotive.xcf [new file with mode: 0644]
assets/blender/engine-with-animation.blend [new file with mode: 0644]
assets/blender/gleis/detectorpart.png [new file with mode: 0644]
assets/blender/gleis/infos/Grafik_weiche.png [new file with mode: 0644]
assets/blender/gleis/infos/breite [new file with mode: 0644]
assets/blender/gleis/licence.txt~ [new file with mode: 0644]
assets/blender/gleis/rail_my.blend [new file with mode: 0644]
assets/blender/gleis/rail_my.blend1 [new file with mode: 0644]
assets/blender/gleis/rail_my_rt.blend [new file with mode: 0644]
assets/blender/gleis/rail_my_rt.blend1 [new file with mode: 0644]
assets/blender/gleis/rail_my_rt_final.blend [new file with mode: 0644]
assets/blender/gleis/rail_my_rt_final.blend1 [new file with mode: 0644]
assets/blender/gleis/rail_my_rt_switches.blend [new file with mode: 0644]
assets/blender/gleis/rail_my_rt_switches.blend1 [new file with mode: 0644]
assets/blender/gleis/rail_my_rt_switches2.blend [new file with mode: 0644]
assets/blender/gleis/rail_my_rt_switches2.blend1 [new file with mode: 0644]
assets/blender/gleis/rail_together.blend [new file with mode: 0644]
assets/blender/gleis/rail_together.png [new file with mode: 0644]
assets/blender/gleis/rail_together2.png [new file with mode: 0644]
assets/blender/gleis/rail_together3.png [new file with mode: 0644]
assets/blender/gleis/rail_verticals.blend [new file with mode: 0644]
assets/blender/gleis/rail_verticals.blend1 [new file with mode: 0644]
assets/blender/gleis/rail_verticals3.blend [new file with mode: 0644]
assets/blender/gleis/rail_verticals3.blend1 [new file with mode: 0644]
assets/blender/gleis/rail_verticals45.blend [new file with mode: 0644]
assets/blender/gleis/rail_verticals45.blend1 [new file with mode: 0644]
assets/blender/gleis/rail_verticals45.blend11 [new file with mode: 0644]
assets/blender/gleis/texturen/rail.png [new file with mode: 0644]
assets/blender/gleis/texturen/uv.png [new file with mode: 0644]
assets/blender/industrial/industry_loc.blend [new file with mode: 0644]
assets/blender/industrial/industry_loc.blend1 [new file with mode: 0644]
assets/blender/industrial/industry_loc.blend11 [new file with mode: 0644]
assets/blender/industrial/industry_oil_ wagong.blend [new file with mode: 0644]
assets/blender/industrial/industry_oil_ wagong.blend1 [new file with mode: 0644]
assets/blender/industrial/industry_tree_wagong.blend [new file with mode: 0644]
assets/blender/industrial/industry_tree_wagong.blend1 [new file with mode: 0644]
assets/blender/industrial/industry_tree_wagong.png [new file with mode: 0644]
assets/blender/locomotive.blend [new file with mode: 0644]
assets/blender/magnet_track.blend [new file with mode: 0644]
assets/blender/mbb/advtrains_wagon_japan.xcf [new file with mode: 0644]
assets/blender/mbb/modern_japanlocomotive.blend [new file with mode: 0644]
assets/blender/mbb/modern_japanlocomotive.blend1 [new file with mode: 0644]
assets/blender/mbb/modern_japanlocomotive.png [new file with mode: 0644]
assets/blender/mbb/modern_japanlocomotive.xcf [new file with mode: 0644]
assets/blender/mbb/modern_locomotive.blend [new file with mode: 0644]
assets/blender/mbb/modern_wagong.blend [new file with mode: 0644]
assets/blender/mbb/modern_wagong.blend1 [new file with mode: 0644]
assets/blender/mbb/modern_wagong_uv.blend [new file with mode: 0644]
assets/blender/mbb/modern_wagong_uv.blend1 [new file with mode: 0644]
assets/blender/mbb/modern_wagong_uv.png [new file with mode: 0644]
assets/blender/mbb/prellbock.blend [new file with mode: 0644]
assets/blender/mbb/prellbock.blend1 [new file with mode: 0644]
assets/blender/mbb/prellbock.uv.png [new file with mode: 0644]
assets/blender/mbb/regio-lokomotive.blend [new file with mode: 0644]
assets/blender/mbb/regio-waron.blend [new file with mode: 0644]
assets/blender/mbb/retrosignal.blend [new file with mode: 0644]
assets/blender/mbb/retrosignal.blend1 [new file with mode: 0644]
assets/blender/mbb/signal(2)_hoch.blend [new file with mode: 0644]
assets/blender/mbb/signal(2)_unten.blend [new file with mode: 0644]
assets/blender/mbb/signal.blend [new file with mode: 0644]
assets/blender/mbb/signal.blend1 [new file with mode: 0644]
assets/blender/mbb/signal.png [new file with mode: 0644]
assets/blender/mbb/signal.xcf [new file with mode: 0644]
assets/blender/mbb/signal2.png [new file with mode: 0644]
assets/blender/mbb/tr-logo.png [new file with mode: 0644]
assets/blender/mbb/weichenhebel1.blend [new file with mode: 0644]
assets/blender/mbb/weichenhebel2.blend [new file with mode: 0644]
assets/blender/newlocomotive.blend [new file with mode: 0644]
assets/blender/newlocomotive.blend1 [new file with mode: 0644]
assets/blender/newlocomotive_uvs.png [new file with mode: 0644]
assets/blender/newwagon.blend [new file with mode: 0644]
assets/blender/newwagon.blend1 [new file with mode: 0644]
assets/blender/newwagon.png [new file with mode: 0644]
assets/blender/subway-train.blend [new file with mode: 0644]
assets/blender/subway-train.blend1 [new file with mode: 0644]
assets/blender/subway-train.png [new file with mode: 0644]
assets/blender/subway-train.xcf [new file with mode: 0644]
assets/blender/trackplane.blend [new file with mode: 0644]
assets/blender/trackvertical1.blend [new file with mode: 0644]
assets/blender/trackvertical1.blend1 [new file with mode: 0644]
assets/blender/trackvertical1.png [new file with mode: 0644]
assets/blender/trackvertical2.blend [new file with mode: 0644]
assets/blender/trackvertical2.png [new file with mode: 0644]
assets/init.lua [new file with mode: 0644]
assets/larger rails.xcf [new file with mode: 0644]
assets/oldmodels/locomotive.b3d [new file with mode: 0644]
assets/oldmodels/trackvertical1.b3d [new file with mode: 0644]
assets/oldmodels/trackvertical2.b3d [new file with mode: 0644]
license.txt [deleted file]
license_media.txt [deleted file]
manual.pdf [deleted file]
screenshot.png [deleted file]

diff --git a/Makefile b/Makefile
deleted file mode 100644 (file)
index 7300426..0000000
--- a/Makefile
+++ /dev/null
@@ -1,5 +0,0 @@
-tarball: clean
-#      tar czf advtrains.tar.gz textures/*.png models/*.b3d *.lua *.txt 
-       which zip && zip advtrains.zip textures/*.png models/*.b3d *.lua *.txt 
-clean:
-       rm -f advtrains.zip advtrains.tar.gz
diff --git a/advtrains.zip b/advtrains.zip
deleted file mode 100644 (file)
index a3dab82..0000000
Binary files a/advtrains.zip and /dev/null differ
diff --git a/advtrains/Makefile b/advtrains/Makefile
new file mode 100644 (file)
index 0000000..7300426
--- /dev/null
@@ -0,0 +1,5 @@
+tarball: clean
+#      tar czf advtrains.tar.gz textures/*.png models/*.b3d *.lua *.txt 
+       which zip && zip advtrains.zip textures/*.png models/*.b3d *.lua *.txt 
+clean:
+       rm -f advtrains.zip advtrains.tar.gz
diff --git a/advtrains/advtrains.zip b/advtrains/advtrains.zip
new file mode 100644 (file)
index 0000000..a3dab82
Binary files /dev/null and b/advtrains/advtrains.zip differ
diff --git a/advtrains/advtrains/api_doc.txt b/advtrains/advtrains/api_doc.txt
new file mode 100644 (file)
index 0000000..6b1aa2e
--- /dev/null
@@ -0,0 +1,114 @@
+Advanced Trains [advtrains] API documentation
+--------
+To use the API, mods must depend on 'advtrains'.
+All boolean values in definition tables default to 'false' and can be omitted.
+### Wagons
+Wagons are registered using the function
+
+advtrains.register_wagon(name, prototype, description, inventory_image)
+- 'name' is the internal name of the wagon. It is registered inside the 'advtrains:' namespace.
+       Example: A wagon with name="engine_tgv" will be registered as "advtrains:engine_tgv".
+- 'prototype' is the lua entity prototype. The regular definition keys for luaentites apply. Additional required and optional properties see below. DO NOT define 'on_step', 'on_activate', 'on_punch', 'on_rightclick' and 'get_staticdata' since these will be overridden. Use 'custom_*' instead.
+- 'description' is the description of the inventory item that is used to place the wagon.
+- 'inventory_image' is the inventory image of said item.
+
+# Wagon prototype properties
+{
+       ... all regular luaentity properties (mesh, textures, collisionbox a.s.o)...
+       drives_on = {default=true},
+       ^- used to define the tracktypes (see below) that wagon can drive on. The tracktype identifiers are given as keys, similar to privileges)
+       max_speed = 10,
+       ^- optional, default 10: defines the maximum speed this wagon can drive. The maximum speed of a train is determined by the wagon with the lowest max_speed value.
+       seats = {
+               {
+                       name="Left front window",
+                       ^- display name of this seat
+                       attach_offset={x=0, y=10, z=0},
+                       ^- this value is passed to 'set_attach'
+                       view_offset={x=0, y=6, z=0},
+                       ^- player:set_eye_offset is called with this parameter.
+                       driving_ctrl_access=false,
+                       ^- If the seat is a driver stand, and players sitting here should get access to the train's driving control.
+
+               },
+       },
+       ^- contains zero or more seat definitions. A seat is a place where a player can be attached when getting on a wagon.
+       wagon_span=2,
+       ^- How far this wagon extends from its base position. Is the half of the wagon length.
+       ^- Used to determine in which distance the other wagons have to be positioned. Will require tweaking.
+       drops = {"default:steelblock 3"}
+       ^- List of itemstrings what to drop when the wagon is destroyed
+       
+       has_inventory = false
+       ^- If this wagon has an inventory. The inventory is saved with the wagon.
+       ^- the following settings are ignored if not.
+       inventory_list_sizes = {
+               box=8*6,
+       },
+       ^- List of assignments of type list_name=size.
+       ^- For every entry, an inventory list is created with the specified size.
+       get_inventory_formspec = function(self, player_name)
+               return "<a formspec>"
+       end,
+       ^- Function that should return the formspec to be displayed when <player> requests to open the wagon's inventory
+       ^- Use "list[detached:advtrains_wgn_"..self.unique_id..";<list_name>;<X>,<Y>;<W>,<H>;<Start>]" to display a wagon's inventory list.
+
+       custom_on_step = function(self, dtime) end
+       ^- optional: Execute custom code on every step
+       custom_on_activate = function(self, dtime_s) end
+       ^- optional: Execute custom code on activate. Staticdata does not need to be saved and restored since all properties written in 'self' are preserved over unloads.
+       update_animation = function(self, velocity) end
+       ^- optional: Function that is called whenever the train's velocity changes or every 2 seconds. Used to call 'self.object:update_animation()' if needed. 
+
+}
+
+# Notes on wagons
+
+- Every wagon has the field 'unique_id' which assigns each wagon a random id.
+- All properties written in the lua entity (self) are saved and restored automatically. Minetest's internal staticdata is only used to save the unique_id of the wagon, which serves as a key in an externally saved table.
+- Assuming Z Axis as the axis parallel to the tracks and Y Axis as the one pointing into the sky, wagon models should be dimensioned in a way that:
+       - their origin is centered in X and Z direction
+       - their origin lies 0.5 units above the bottom of the model
+       - the overall extent in X and Y direction is <=3 units
+- wagon_span is then the distance between the model origin and the Z axis extent.
+
+### Tracks
+Most modders will be satisfied with the built-in tracks. If cog railways, maglev trains and mine trains are added, it is necessary to understand the definition of tracks. Although the tracks API is there, explaining it would require more effort than me creating the wanted definitions myself. Contact me if you need to register your own rails using my registration functions.
+
+However, it is still possible to register single rails by understanding the node properties of rails.
+minetest.register_node(nodename, {
+       ... usual node definition ...
+       groups = {
+               advtrains_track_<tracktype>=1
+               ^- this group tells that the node is a track
+               not_blocking_trains=1,
+               ^- this group tells that the node should not block trains although it's walkable.
+       },
+       connect1 = 0,
+       connect2 = 8,
+       ^- These values tell the direction (horizontal) the rail ends are pointing to. 0 means +Z, then rotation values increase clockwise. For a translation of directions to positions see helpers.lua.
+       rely1=0,\r
+       rely2=0,
+       ^- the Y height of the rail end 1/2. A value of >=1 means that the rail end points to the next y layer at rely-1 \r
+       railheight=0,
+       ^- the height value of this rail that is saved in the path. usually the median of rely1 and rely2.
+
+       can_dig=function(pos)\r
+               return not advtrains.is_train_at_pos(pos)\r
+       end,\r
+       after_dig_node=function(pos)\r
+               advtrains.invalidate_all_paths()\r
+               advtrains.reset_trackdb_position(pos)\r
+       end,\r
+       after_place_node=function(pos)\r
+               advtrains.reset_trackdb_position(pos)\r
+       end,
+       ^- the code in these 3 default minetest API functions is required for advtrains to work, however you can add your own code
+       
+       advtrains = {\r
+               on_train_enter=function(pos, train_id) end
+               ^- called when a train enters the rail
+               on_train_leave=function(pos, train_id) end
+               ^- called when a train leaves the rail\r
+       }
+})
\ No newline at end of file
diff --git a/advtrains/advtrains/atc.lua b/advtrains/advtrains/atc.lua
new file mode 100644 (file)
index 0000000..f070b20
--- /dev/null
@@ -0,0 +1,294 @@
+--atc.lua
+--registers and controls the ATC system
+
+local atc={}
+-- ATC persistence table
+atc.controllers = {}
+--contents: {command="...", arrowconn=0-15 where arrow points}
+
+advtrains.fpath_atc=minetest.get_worldpath().."/advtrains_atc"
+local file, err = io.open(advtrains.fpath_atc, "r")
+if not file then
+       local er=err or "Unknown Error"
+       print("[advtrains]Failed loading advtrains atc save file "..er)
+else
+       local tbl = minetest.deserialize(file:read("*a"))
+       if type(tbl) == "table" then
+               atc.controllers=tbl.controllers
+       end
+       file:close()
+end
+function atc.save()
+       --leave space for more save data.
+       local datastr = minetest.serialize({controllers = atc.controllers})
+       if not datastr then
+               minetest.log("error", "[advtrains] Failed to serialize trackdb data!")
+               return
+       end
+       local file, err = io.open(advtrains.fpath_atc, "w")
+       if err then
+               return err
+       end
+       file:write(datastr)
+       file:close()
+end
+
+--call from advtrains.detector subprogram
+
+function atc.trigger_controller_train_enter(pos, train_id)
+       atc.send_command(pos)
+end
+
+--general
+
+function atc.send_command(pos)
+       local pts=minetest.pos_to_string(pos)
+       if atc.controllers[pts] then
+               print("Called send_command at "..pts)
+               local train_id = advtrains.detector.on_node[pts]
+               if train_id then
+                       if advtrains.trains[train_id] then
+                               print("send_command inside if: "..sid(train_id))
+                               atc.train_reset_command(train_id)
+                               local arrowconn=atc.controllers[pts].arrowconn
+                               local train=advtrains.trains[train_id]
+                               for index, ppos in pairs(train.path) do
+                                       if vector.equals(advtrains.round_vector_floor_y(ppos), pos) then
+                                               advtrains.trains[train_id].atc_arrow =
+                                                               vector.equals(
+                                                                               advtrains.dirCoordSet(pos, arrowconn),
+                                                                               advtrains.round_vector_floor_y(train.path[index+train.movedir])
+                                                               )
+                                               advtrains.trains[train_id].atc_command=atc.controllers[pts].command
+                                               print("Sending ATC Command: "..atc.controllers[pts].command)
+                                       end
+                               end
+                       end
+               end
+       end
+       return false
+end
+
+function atc.train_reset_command(train_id)
+       advtrains.trains[train_id].atc_command=nil
+       advtrains.trains[train_id].atc_delay=0
+       advtrains.trains[train_id].atc_brake_target=nil
+       advtrains.trains[train_id].atc_wait_finish=nil
+       advtrains.trains[train_id].atc_arrow=nil
+end
+
+--nodes
+local idxtrans={static=1, mesecon=2, digiline=3}
+local apn_func=function(pos)
+       advtrains.reset_trackdb_position(pos)
+       local meta=minetest.get_meta(pos)
+       if meta then
+               meta:set_string("infotext", "ATC controller, unconfigured.")
+               meta:set_string("formspec", atc.get_atc_controller_formspec(pos, meta))
+       end
+end
+
+advtrains.register_tracks("default", {
+       nodename_prefix="advtrains:dtrack_atc",
+       texture_prefix="advtrains_dtrack_atc",
+       models_prefix="advtrains_dtrack_detector",
+       models_suffix=".b3d",
+       shared_texture="advtrains_dtrack_rail_atc.png",
+       description="ATC controller",
+       formats={},
+       get_additional_definiton = function(def, preset, suffix, rotation)
+               return {
+                       after_place_node=apn_func,
+                       on_place_rail=apn_func,
+                       after_dig_node=function(pos)
+                               advtrains.invalidate_all_paths()
+                               advtrains.reset_trackdb_position(pos)
+                               local pts=minetest.pos_to_string(pos)
+                               atc.controllers[pts]=nil
+                       end,
+                       on_receive_fields = function(pos, formname, fields, player)
+                               if minetest.is_protected(pos, player:get_player_name()) then
+                                       minetest.chat_send_player(player:get_player_name(), "This position is protected!")
+                                       return
+                               end
+                               local meta=minetest.get_meta(pos)
+                               if meta then
+                                       if not fields.save then 
+                                               --maybe only the dropdown changed
+                                               if fields.mode then
+                                                       meta:set_string("mode", idxtrans[fields.mode])
+                                                       meta:set_string("infotext", "ATC controller, mode "..fields.mode.."\n"..( fields.mode=="digiline" and "Channel: "..meta:get_string("channel") or "Command: "..meta:get_string("command") ) )
+                                                       meta:set_string("formspec", atc.get_atc_controller_formspec(pos, meta))
+                                               end
+                                               return
+                                       end
+                                       meta:set_string("mode", idxtrans[fields.mode])
+                                       meta:set_string("command", fields.command)
+                                       meta:set_string("command_on", fields.command_on)
+                                       meta:set_string("channel", fields.channel)
+                                       meta:set_string("infotext", "ATC controller, mode "..fields.mode.."\n"..( fields.mode=="digiline" and "Channel: "..meta:get_string("channel") or "Command: "..meta:get_string("command") ) )
+                                       meta:set_string("formspec", atc.get_atc_controller_formspec(pos, meta))
+                                       
+                                       local pts=minetest.pos_to_string(pos)
+                                       local _, conn1=advtrains.get_rail_info_at(pos, advtrains.all_tracktypes)
+                                       atc.controllers[pts]={command=fields.command, arrowconn=conn1}
+                                       atc.send_command(pos)
+                               end
+                       end,
+               }
+       end
+}, advtrains.trackpresets.t_30deg_straightonly)
+
+
+function atc.get_atc_controller_formspec(pos, meta)
+       local mode=tonumber(meta:get_string("mode")) or 1
+       local command=meta:get_string("command")
+       local command_on=meta:get_string("command_on")
+       local channel=meta:get_string("channel")
+       local formspec="size[8,6]"..
+               "dropdown[0,0;3;mode;static,mesecon,digiline;"..mode.."]"
+       if mode<3 then
+               formspec=formspec.."field[0.5,1.5;7,1;command;Command;"..minetest.formspec_escape(command).."]"
+               if tonumber(mode)==2 then
+                       formspec=formspec.."field[0.5,3;7,1;command_on;Command (on);"..minetest.formspec_escape(command_on).."]"
+               end
+       else
+               formspec=formspec.."field[0.5,1.5;7,1;channel;Digiline channel;"..minetest.formspec_escape(channel).."]"
+       end
+       return formspec.."button_exit[0.5,4.5;7,1;save;Save]"
+end
+
+--from trainlogic.lua train step
+local matchptn={
+       ["SM"]=function(id, train)
+               train.tarvelocity=train.max_speed
+               return 2
+       end,
+       ["S([0-9]+)"]=function(id, train, match)
+               train.tarvelocity=tonumber(match)
+               return #match+1
+       end,
+       ["B([0-9]+)"]=function(id, train, match)
+               if train.velocity>tonumber(match) then
+                       train.atc_brake_target=tonumber(match)
+                       if train.tarvelocity>train.atc_brake_target then
+                               train.tarvelocity=train.atc_brake_target
+                       end
+               end
+               return #match+1
+       end,
+       ["W"]=function(id, train)
+               train.atc_wait_finish=true
+               return 1
+       end,
+       ["D([0-9]+)"]=function(id, train, match)
+               train.atc_delay=tonumber(match)
+               return #match+1
+       end,
+       ["R"]=function(id, train)
+               if train.velocity<=0 then
+                       train.movedir=train.movedir*-1
+                       train.atc_arrow = not train.atc_arrow
+               else
+                       print("ATC Reverse command warning: didn't reverse train!")
+               end
+               return 1
+       end,
+}
+
+function atc.execute_atc_command(id, train)
+       --strip whitespaces
+       local command=string.match(train.atc_command, "^%s*(.*)$")
+       
+       
+       if string.match(command, "^%s*$") then
+               train.atc_command=nil
+               return
+       end
+       --conditional statement?
+       local is_cond, cond_applies
+       local cond, rest=string.match(command, "^I([%+%-])(.+)$")
+       if cond then
+               is_cond=true
+               if cond=="+" then
+                       cond_applies=train.atc_arrow
+               end
+               if cond=="-" then
+                       cond_applies=not train.atc_arrow
+               end
+       else 
+               cond, compare, rest=string.match(command, "^I([<>]=?)([0-9]+)(.+)$")
+               if cond and compare then
+                       is_cond=true
+                       if cond=="<" then
+                               cond_applies=train.velocity<tonumber(compare)
+                       end
+                       if cond==">" then
+                               cond_applies=train.velocity>tonumber(compare)
+                       end
+                       if cond=="<=" then
+                               cond_applies=train.velocity<=tonumber(compare)
+                       end
+                       if cond==">=" then
+                               cond_applies=train.velocity>=tonumber(compare)
+                       end
+               end
+       end     
+       if is_cond then
+               print("Evaluating if statement: "..command)
+               print("Cond: "..(cond or "nil"))
+               print("Applies: "..(cond_applies and "true" or "false"))
+               print("Rest: "..rest)
+               --find end of conditional statement
+               local nest, pos, elsepos=0, 1
+               while nest>=0 do
+                       if pos>#rest then
+                               print("ATC command syntax error: I statement not closed: "..command)
+                               atc.train_reset_command(id)
+                               return
+                       end
+                       local char=string.sub(rest, pos, pos)
+                       if char=="I" then
+                               nest=nest+1
+                       end
+                       if char==";" then
+                               nest=nest-1
+                       end
+                       if nest==0 and char=="E" then
+                               elsepos=pos+0
+                       end
+                       pos=pos+1
+               end
+               if not elsepos then elsepos=pos-1 end
+               if cond_applies then
+                       command=string.sub(rest, 1, elsepos-1)..string.sub(rest, pos)
+               else
+                       command=string.sub(rest, elsepos+1, pos-2)..string.sub(rest, pos)
+               end
+               print("Result: "..command)
+               train.atc_command=command
+               atc.execute_atc_command(id, train)
+               return
+       else
+               for pattern, func in pairs(matchptn) do
+                       local match=string.match(command, "^"..pattern)
+                       if match then
+                               local patlen=func(id, train, match)
+                               
+                               print("Executing: "..string.sub(command, 1, patlen))
+                               
+                               train.atc_command=string.sub(command, patlen+1)
+                               if train.atc_delay<=0 and not train.atc_wait_finish then
+                                       --continue (recursive, cmds shouldn't get too long, and it's a end-recursion.)
+                                       atc.execute_atc_command(id, train)
+                               end
+                               return
+                       end
+               end
+       end
+       print("ATC command parse error: "..command)
+       atc.train_reset_command(id)
+end
+
+--move table to desired place
+advtrains.atc=atc
diff --git a/advtrains/advtrains/atc_command.txt b/advtrains/advtrains/atc_command.txt
new file mode 100644 (file)
index 0000000..fa846e3
--- /dev/null
@@ -0,0 +1,68 @@
+ATC Command Syntax
+
+A train runs the current ATC command once it receives it, including delayed instructions. If the train receives a new command, the current command is discarded.
+Spaces can be inserted into commands as needed and are ignored.
+
+# simple commands:
+
+S<[0-9]+ speed or 'M'>
+Set target speed of train to <speed>. Accelerates if slower, rolls if faster. 'M' means maximum speed.
+Execution of command continues immediately.
+
+B<[0-9]+ speed>
+Brake until speed is reached. If faster, apply brakes, if slower, do nothing.
+Execution of command continues immediately.
+
+Examples:
+SM : accelerate to maximum speed
+S0 : roll to stand
+B0 : brake to stand
+S0B3 or B3S0: brake to 3, then roll to stand.
+
+W
+Wait until S and/or B commands reached the desired speed before continuing execution.
+
+D<[0-9]+ time>
+Delay: Wait for time seconds before continuing execution.
+
+R
+Reverse: change movement direction of train. ONLY WORKS WHEN TRAIN STANDS, else no-op.
+Use B0WR to definitely change direction.
+
+Examples:
+B0 W R D10 SM
+Subway train stopping in dead end station and returning in opposite direction
+
+# conditional statements:
+
+I<condition><code>;
+Execute code only if condition applies
+I<condition><code1>E<code2>;
+Execute code1 only if condition applies, else execute code2
+
+Conditions:
++ / -
+Tests the train's movement direction against the arrow on the ATC rail: M+ is true when train drives in direction of arrow.
+
+[</>/<=/>=][speed]
+Test if train's speed is greater or smaller than the given value
+
+Examples:
+I- B0 W R ; S8
+If the train drives in the 'wrong' direction, stop and reverse; independently accelerate to speed 8 afterwards.
+
+I<8 S8 ;
+If the train is slower than 8, accelerate to 8.
+
+# ATC controller operation modes
+static: Only give 1 static command.
+mesecon: Give 2 different commands depending on if the controller is mesecon-powered or not
+digiline: Don't give any commands by itself. When a train passes, a digiline message in the form of "[+/-][speed]" is sent on the set channel (where +/- means the same as with conditions). Any digiline message sent to the controller will be interpreted as ATC command and sent to the train.
+
+# Persistence
+ATC controllers that are configured as 'static' or 'mesecon' are persistent over mapblock unloads and will even command the train when the mapblock is unloaded. This is not possible with digilines since these do not work in unloaded mapchunks.
+
+# LUA ATC controller (in development)
+The LUA ATC Controller will operate by using LUA code. All operations shown above will have a function equivalent. Additionally all LUA ATC controllers share an environment and setting signal and switch status will be possible to allow for complicated railway systems/fully automated subways a.s.o.
+Also planned:
+- digicompute add-on to allow computer access to the ATC environment (railway maps... ... ... ... ...)
diff --git a/advtrains/advtrains/couple.lua b/advtrains/advtrains/couple.lua
new file mode 100644 (file)
index 0000000..974f450
--- /dev/null
@@ -0,0 +1,156 @@
+--couple.lua
+--defines couple entities.
+
+--advtrains:discouple
+--set into existing trains to split them when punched.
+--they are attached to the wagons.
+--[[fields
+wagon
+
+wagons keep their couple entity minetest-internal id inside the field discouple_id. if it refers to nowhere, they will spawn a new one if player is near
+]]
+
+
+minetest.register_entity("advtrains:discouple", {
+       visual="sprite",
+       textures = {"advtrains_discouple.png"},
+       collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
+       visual_size = {x=1, y=1},
+       initial_sprite_basepos = {x=0, y=0},
+       
+       is_discouple=true,
+       on_activate=function(self, staticdata) 
+               if staticdata=="DISCOUPLE" then
+                       --couple entities have no right to exist further...
+                       self.object:remove()
+                       return
+               end
+               self.object:set_armor_groups({immortal=1})
+       end,
+       get_staticdata=function() return "DISCOUPLE" end,
+       on_punch=function(self, player)
+               --only if player owns at least one wagon next to this
+               local own=player:get_player_name()
+               if self.wagon.owner and self.wagon.owner==own then
+                       local train=advtrains.trains[self.wagon.train_id]
+                       local nextwgn_id=train.trainparts[self.wagon.pos_in_trainparts-1]
+                       for aoi, le in pairs(minetest.luaentities) do
+                               if le and le.is_wagon then
+                                       if le.unique_id==nextwgn_id then
+                                               if le.owner and le.owner~=own then
+                                                       minetest.chat_send_player(own, "You need to own at least one neighboring wagon to destroy this couple.")
+                                                       return
+                                               end
+                                       end
+                               end
+                       end
+                       advtrains.split_train_at_wagon(self.wagon)--found in trainlogic.lua
+                       self.object:remove()
+               else
+                       minetest.chat_send_player(own, "You need to own at least one neighboring wagon to destroy this couple.")
+               end
+       end,
+       on_step=function(self, dtime)
+               local t=os.clock()
+               if not self.wagon then
+                       self.object:remove()
+                       return
+               end
+               --getyaw seems to be a reliable method to check if an object is loaded...if it returns nil, it is not.
+               if not self.wagon.object:getyaw() then
+                       self.object:remove()
+                       return
+               end
+               local velocityvec=self.wagon.object:getvelocity()
+               self.updatepct_timer=(self.updatepct_timer or 0)-dtime
+               if not self.old_velocity_vector or not vector.equals(velocityvec, self.old_velocity_vector) or self.updatepct_timer<=0 then--only send update packet if something changed
+                       local flipsign=self.wagon.wagon_flipped and -1 or 1
+                       self.object:setpos(vector.add(self.wagon.object:getpos(), {y=0, x=-math.sin(self.wagon.object:getyaw())*self.wagon.wagon_span*flipsign, z=math.cos(self.wagon.object:getyaw())*self.wagon.wagon_span*flipsign}))
+                       self.object:setvelocity(velocityvec)
+                       self.updatepct_timer=2
+               end
+               printbm("discouple_step", t)
+       end,
+})
+
+--advtrains:couple
+--when two trains overlap with their end-positions, this entity will be spawned and both trains set its id into appropiate fields for them to know when to free them again. The entity will destroy automatically when it recognizes that any of the trains left the common position. 
+--[[fields
+train_id_1
+train_id_2
+train1_is_backpos
+train2_is_backpos
+]]
+
+
+minetest.register_entity("advtrains:couple", {
+       visual="sprite",
+       textures = {"advtrains_couple.png"},
+       collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
+       visual_size = {x=1, y=1},
+       initial_sprite_basepos = {x=0, y=0},
+       
+       is_couple=true,
+       on_activate=function(self, staticdata) 
+               if staticdata=="COUPLE" then
+                       --couple entities have no right to exist further...
+                       self.object:remove()
+                       return
+               end
+       end,
+       get_staticdata=function(self) return "COUPLE" end,
+       on_rightclick=function(self)
+               if not self.train_id_1 or not self.train_id_2 then return end
+               
+               local id1, id2=self.train_id_1, self.train_id_2
+               
+               if self.train1_is_backpos and not self.train2_is_backpos then
+                       advtrains.do_connect_trains(id1, id2)
+                       --case 2 (second train is front)
+               elseif self.train2_is_backpos and not self.train1_is_backpos then
+                       advtrains.do_connect_trains(id2, id1)
+                       --case 3 
+               elseif self.train1_is_backpos and self.train2_is_backpos then
+                       advtrains.invert_train(id2)
+                       advtrains.do_connect_trains(id1, id2)
+                       --case 4 
+               elseif not self.train1_is_backpos and not self.train2_is_backpos then
+                       advtrains.invert_train(id1)
+                       advtrains.do_connect_trains(id1, id2)
+               end
+               self.object:remove()
+       end,
+       on_step=function(self, dtime)
+               local t=os.clock()
+               if not self.train_id_1 or not self.train_id_2 then print("wtf no train ids?")return end
+               local train1=advtrains.trains[self.train_id_1]
+               local train2=advtrains.trains[self.train_id_2]
+               if not train1 or not train2 or not train1.path or not train2.path or not train1.index or not train2.index then
+                       self.object:remove()
+                       return
+               end
+               
+               local tp1
+               if not self.train1_is_backpos then
+                       tp1=advtrains.get_real_index_position(train1.path, train1.index)
+               else
+                       tp1=advtrains.get_real_index_position(train1.path, advtrains.get_train_end_index(train1))
+               end
+               local tp2
+               if not self.train2_is_backpos then
+                       tp2=advtrains.get_real_index_position(train2.path, train2.index)
+               else
+                       tp2=advtrains.get_real_index_position(train2.path, advtrains.get_train_end_index(train2))
+               end
+               if not tp1 or not tp2 or not (vector.distance(tp1,tp2)<1.5) then
+                       self.object:remove()
+                       return
+               else
+                       local pos_median=advtrains.pos_median(tp1, tp2)
+                       if not vector.equals(pos_median, self.object:getpos()) then
+                               self.object:setpos(pos_median)
+                       end
+               end
+               printbm("couple step", t)
+       end,
+}) 
diff --git a/advtrains/advtrains/crafting.lua b/advtrains/advtrains/crafting.lua
new file mode 100644 (file)
index 0000000..5ba12ce
--- /dev/null
@@ -0,0 +1,71 @@
+--advtrains by orwell96, see readme.txt and license.txt
+--crafting.lua
+--registers crafting recipes
+
+--tracks
+minetest.register_craft({
+       output = 'advtrains:dtrack_placer 50',
+       recipe = {
+               {'default:steel_ingot', 'group:stick', 'default:steel_ingot'},
+               {'default:steel_ingot', 'group:stick', 'default:steel_ingot'},
+               {'default:steel_ingot', 'group:stick', 'default:steel_ingot'},
+       },
+})
+minetest.register_craft({
+       type = "shapeless",
+       output = 'advtrains:dtrack_slopeplacer 2',
+       recipe = {
+               "advtrains:dtrack_placer",
+               "advtrains:dtrack_placer",
+               "default:gravel",
+       },
+})
+
+minetest.register_craft({
+       output = 'advtrains:dtrack_bumper_placer 2',
+       recipe = {
+               {'default:wood', 'dye:red'},
+               {'default:steel_ingot', 'default:steel_ingot'},
+               {'advtrains:dtrack_placer', 'advtrains:dtrack_placer'},
+       },
+})
+minetest.register_craft({
+       type="shapeless",
+       output = 'advtrains:dtrack_detector_off_placer',
+       recipe = {
+               "advtrains:dtrack_placer",
+               "mesecons:wire_00000000_off"
+       },
+})
+--signals
+minetest.register_craft({
+       output = 'advtrains:retrosignal_off 2',
+       recipe = {
+               {'dye:red', 'default:steel_ingot', 'default:steel_ingot'},
+               {'', '', 'default:steel_ingot'},
+               {'', '', 'default:steel_ingot'},
+       },
+})
+minetest.register_craft({
+       output = 'advtrains:signal_off 2',
+       recipe = {
+               {'', 'dye:red', 'default:steel_ingot'},
+               {'', 'dye:dark_green', 'default:steel_ingot'},
+               {'', '', 'default:steel_ingot'},
+       },
+})
+
+--trackworker
+minetest.register_craft({
+       output = 'advtrains:trackworker',
+       recipe = {
+               {'default:diamond'},
+               {'screwdriver:screwdriver'},
+               {'default:steel_ingot'},
+       },
+})
+
+
+
+--misc_nodes
+--crafts for platforms see misc_nodes.lua
diff --git a/advtrains/advtrains/damage.lua b/advtrains/advtrains/damage.lua
new file mode 100644 (file)
index 0000000..b39fe67
--- /dev/null
@@ -0,0 +1,26 @@
+--damage.lua
+--a globalstep that damages players overrolled by trains.
+
+advtrains.player_to_train_mapping={}
+
+local tmr=0
+minetest.register_globalstep(function(dtime)
+       tmr=tmr-dtime
+       if tmr<=0 then
+       
+       for _, player in pairs(minetest.get_connected_players()) do
+               local pos=player:getpos()
+               for _, object in pairs(minetest.get_objects_inside_radius(pos, 1)) do
+                       local le=object:get_luaentity()
+                       if le and le.is_wagon and le.initialized and le:train() then
+                               if (not advtrains.player_to_train_mapping[player:get_player_name()] or le.train_id~=advtrains.player_to_train_mapping[player:get_player_name()]) and math.abs(le:train().velocity)>2 then
+                                       --player:punch(object, 1000, {damage={fleshy=3*math.abs(le:train().velocity)}})
+                                       player:set_hp(player:get_hp()-math.abs(le:train().velocity)-3)
+                               end
+                       end
+               end
+       end
+       
+       tmr=0.5
+       end
+end)
diff --git a/advtrains/advtrains/debugitems.lua b/advtrains/advtrains/debugitems.lua
new file mode 100644 (file)
index 0000000..b3164ff
--- /dev/null
@@ -0,0 +1,36 @@
+minetest.register_tool("advtrains:tunnelborer",
+{
+       description = "tunnelborer",
+       groups = {cracky=1}, -- key=name, value=rating; rating=1..3.
+       inventory_image = "drwho_screwdriver.png",
+       wield_image = "drwho_screwdriver.png",
+       stack_max = 1,
+       range = 7.0,
+               
+       on_place = function(itemstack, placer, pointed_thing)
+       
+       end,
+       --[[
+       ^ Shall place item and return the leftover itemstack
+       ^ default: minetest.item_place ]]
+       on_use = function(itemstack, user, pointed_thing)
+               if pointed_thing.type=="node" then
+                       for x=-1,1 do
+                               for y=-1,1 do
+                                       for z=-1,1 do
+                                               minetest.remove_node(vector.add(pointed_thing.under, {x=x, y=y, z=z}))
+                                       end
+                               end
+                       end
+               end
+       end,
+--[[
+^  default: nil
+^ Function must return either nil if no item shall be removed from
+inventory, or an itemstack to replace the original itemstack.
+e.g. itemstack:take_item(); return itemstack
+^ Otherwise, the function is free to do what it wants.
+^ The default functions handle regular use cases.
+]]
+}
+) 
diff --git a/advtrains/advtrains/depends.txt b/advtrains/advtrains/depends.txt
new file mode 100644 (file)
index 0000000..20aa884
--- /dev/null
@@ -0,0 +1,2 @@
+default
+mesecons?
\ No newline at end of file
diff --git a/advtrains/advtrains/description.txt b/advtrains/advtrains/description.txt
new file mode 100644 (file)
index 0000000..ecc5d58
--- /dev/null
@@ -0,0 +1,8 @@
+Advanced Trains v1.3.0, by orwell and contributors. Also see readme.
+Good-looking, realistic trains for minetest.
+
+For crafting recipes, see manual.pdf
+
+Website: http://advtrains.bleipb.de/
+Manual:  https://github.com/orwell96/advtrains/blob/master/manual.pdf
+Forum :  https://forum.minetest.net/viewtopic.php?f=11&t=14726
\ No newline at end of file
diff --git a/advtrains/advtrains/helpers.lua b/advtrains/advtrains/helpers.lua
new file mode 100644 (file)
index 0000000..1a02621
--- /dev/null
@@ -0,0 +1,248 @@
+--advtrains by orwell96, see readme.txt\r
+local print=function(t) minetest.log("action", t) minetest.chat_send_all(t) end\r
+\r
+advtrains.dir_trans_tbl={\r
+       [0]={x=0, z=1},\r
+       [1]={x=1, z=2},\r
+       [2]={x=1, z=1},\r
+       [3]={x=2, z=1},\r
+       [4]={x=1, z=0},\r
+       [5]={x=2, z=-1},\r
+       [6]={x=1, z=-1},\r
+       [7]={x=1, z=-2},\r
+       [8]={x=0, z=-1},\r
+       [9]={x=-1, z=-2},\r
+       [10]={x=-1, z=-1},\r
+       [11]={x=-2, z=-1},\r
+       [12]={x=-1, z=0},\r
+       [13]={x=-2, z=1},\r
+       [14]={x=-1, z=1},\r
+       [15]={x=-1, z=2},\r
+}\r
+\r
+function advtrains.dirCoordSet(coord, dir)\r
+       local x,z\r
+       if advtrains.dir_trans_tbl[dir] then\r
+               x,z=advtrains.dir_trans_tbl[dir].x, advtrains.dir_trans_tbl[dir].z\r
+       else\r
+               error("advtrains: in helpers.lua/dirCoordSet() given dir="..(dir or "nil"))\r
+       end\r
+       return {x=coord.x+x, y=coord.y, z=coord.z+z}\r
+end\r
+function advtrains.dirToCoord(dir)\r
+       return advtrains.dirCoordSet({x=0, y=0, z=0}, dir)\r
+end\r
+\r
+function advtrains.maxN(list, expectstart)\r
+       local n=expectstart or 0\r
+       while list[n] do\r
+               n=n+1\r
+       end\r
+       return n-1\r
+end\r
+\r
+function advtrains.minN(list, expectstart)\r
+       local n=expectstart or 0\r
+       while list[n] do\r
+               n=n-1\r
+       end\r
+       return n+1\r
+end\r
+\r
+--vertical_transmit:\r
+--[[\r
+rely1, rely2 tell to which height the connections are pointed to. 1 means it will go up the next node\r
+\r
+]]\r
+\r
+function advtrains.conway(midreal, prev, drives_on)--in order prev,mid,return\r
+       local mid=advtrains.round_vector_floor_y(midreal)\r
+       \r
+       if not advtrains.get_rail_info_at(advtrains.round_vector_floor_y(prev), drives_on) then\r
+               return nil\r
+       end\r
+       \r
+       local midnode_ok, middir1, middir2, midrely1, midrely2=advtrains.get_rail_info_at(advtrains.round_vector_floor_y(mid), drives_on)\r
+       if not midnode_ok then\r
+               return nil \r
+       end\r
+       \r
+       local next, chkdir, chkrely, y_offset\r
+       y_offset=0\r
+       --print("[advtrains] in order mid1,mid2",middir1,middir2)\r
+       --try if it is dir1\r
+       local cor1=advtrains.dirCoordSet(mid, middir2)--<<<<\r
+       if math.floor(cor1.x+0.5)==math.floor(prev.x+0.5) and math.floor(cor1.z+0.5)==math.floor(prev.z+0.5) then--this was previous\r
+               next=advtrains.dirCoordSet(mid, middir1)\r
+               if midrely1>=1 then\r
+                       next.y=next.y+1\r
+                       --print("[advtrains]found midrely1 to be >=1: next is now "..(next and minetest.pos_to_string(next) or "nil"))\r
+                       y_offset=1\r
+               end\r
+               chkdir=middir1\r
+               chkrely=midrely1\r
+               --print("[advtrains]dir2 applied next pos:",minetest.pos_to_string(next),"(chkdir is ",chkdir,")")\r
+       end\r
+       --dir2???\r
+       local cor2=advtrains.dirCoordSet(mid, middir1)--<<<<\r
+       if math.floor(cor2.x+0.5)==math.floor(prev.x+0.5) and math.floor(cor2.z+0.5)==math.floor(prev.z+0.5) then\r
+               next=advtrains.dirCoordSet(mid, middir2)--dir2 wird überprüft, alles gut.\r
+               if midrely2>=1 then\r
+                       next.y=next.y+1\r
+                       --print("[advtrains]found midrely2 to be >=1: next is now "..(next and minetest.pos_to_string(next) or "nil"))\r
+                       y_offset=1\r
+               end\r
+               chkdir=middir2\r
+               chkrely=midrely2\r
+               --print("[advtrains] dir2 applied next pos:",minetest.pos_to_string(next),"(chkdir is ",chkdir,")")\r
+       end\r
+       --print("[advtrains]dir applied next pos: "..(next and minetest.pos_to_string(next) or "nil").."(chkdir is "..(chkdir or "nil")..", y-offset "..y_offset..")")\r
+       --is there a next\r
+       if not next then\r
+               --print("[advtrains]in conway: no next rail(nil), returning!")\r
+               return nil\r
+       end\r
+       \r
+       local nextnode_ok, nextdir1, nextdir2, nextrely1, nextrely2, nextrailheight=advtrains.get_rail_info_at(advtrains.round_vector_floor_y(next), drives_on)\r
+       \r
+       --is it a rail?\r
+       if(not nextnode_ok) then\r
+               --print("[advtrains]in conway: next "..minetest.pos_to_string(next).." not a rail, trying one node below!")\r
+               next.y=next.y-1\r
+               y_offset=y_offset-1\r
+               \r
+               nextnode_ok, nextdir1, nextdir2, nextrely1, nextrely2, nextrailheight=advtrains.get_rail_info_at(advtrains.round_vector_floor_y(next), drives_on)\r
+               if(not nextnode_ok) then\r
+                       --print("[advtrains]in conway: one below "..minetest.pos_to_string(next).." is not a rail either, returning!")\r
+                       return nil\r
+               end\r
+       end\r
+       \r
+       --is this next rail connecting to the mid?\r
+       if not ( (((nextdir1+8)%16)==chkdir and nextrely1==chkrely-y_offset) or (((nextdir2+8)%16)==chkdir and nextrely2==chkrely-y_offset) ) then\r
+               --print("[advtrains]in conway: next "..minetest.pos_to_string(next).." not connecting, trying one node below!")\r
+               next.y=next.y-1\r
+               y_offset=y_offset-1\r
+               \r
+               nextnode_ok, nextdir1, nextdir2, nextrely1, nextrely2, nextrailheight=advtrains.get_rail_info_at(advtrains.round_vector_floor_y(next), drives_on)\r
+               if(not nextnode_ok) then\r
+                       --print("[advtrains]in conway: (at connecting if check again) one below "..minetest.pos_to_string(next).." is not a rail either, returning!")\r
+                       return nil\r
+               end\r
+               if not ( (((nextdir1+8)%16)==chkdir and nextrely1==chkrely) or (((nextdir2+8)%16)==chkdir and nextrely2==chkrely) ) then\r
+                       --print("[advtrains]in conway: one below "..minetest.pos_to_string(next).." rail not connecting, returning!")\r
+                       --print("[advtrains] in order mid1,2,next1,2,chkdir "..middir1.." "..middir2.." "..nextdir1.." "..nextdir2.." "..chkdir)\r
+                       return nil\r
+               end\r
+       end\r
+       \r
+       --print("[advtrains]conway found rail.")\r
+       return vector.add(advtrains.round_vector_floor_y(next), {x=0, y=nextrailheight, z=0}), chkdir\r
+end\r
+--TODO use this\r
+function advtrains.oppd(dir)\r
+       return ((dir+8)%16)\r
+end\r
+\r
+function advtrains.round_vector_floor_y(vec)\r
+       return {x=math.floor(vec.x+0.5), y=math.floor(vec.y), z=math.floor(vec.z+0.5)}\r
+end\r
+\r
+function advtrains.yawToDirection(yaw, conn1, conn2)\r
+       if not conn1 or not conn2 then\r
+               error("given nil to yawToDirection: conn1="..(conn1 or "nil").." conn2="..(conn1 or "nil"))\r
+       end\r
+       local yaw1=math.pi*(conn1/4)\r
+       local yaw2=math.pi*(conn2/4)\r
+       if advtrains.minAngleDiffRad(yaw, yaw1)<advtrains.minAngleDiffRad(yaw, yaw2) then--change to > if weird behavior\r
+               return conn2\r
+       else\r
+               return conn1\r
+       end\r
+end\r
+\r
+function advtrains.minAngleDiffRad(r1, r2)\r
+       local try1=r2-r1\r
+       local try2=(r2+2*math.pi)-r1\r
+       local try3=r2-(r1+2*math.pi)\r
+       if math.min(math.abs(try1), math.abs(try2), math.abs(try3))==math.abs(try1) then\r
+               return try1\r
+       end\r
+       if math.min(math.abs(try1), math.abs(try2), math.abs(try3))==math.abs(try2) then\r
+               return try2\r
+       end\r
+       if math.min(math.abs(try1), math.abs(try2), math.abs(try3))==math.abs(try3) then\r
+               return try3\r
+       end\r
+end\r
+function advtrains.dumppath(path)\r
+       if not path then print("dumppath: no path(nil)") return end\r
+       local min=advtrains.minN(path)\r
+       local max=advtrains.maxN(path)\r
+       for i=min, max do print("["..i.."] "..(path[i] and minetest.pos_to_string(path[i]) or "nil")) end\r
+end\r
+\r
+function advtrains.merge_tables(a, ...)\r
+       local new={}\r
+       for _,t in ipairs({a,...}) do\r
+               for k,v in pairs(t) do new[k]=v end\r
+       end\r
+       return new\r
+end\r
+function advtrains.yaw_from_3_positions(prev, curr, next)\r
+       local pts=minetest.pos_to_string\r
+       --print("p3 "..pts(prev)..pts(curr)..pts(next))\r
+       local prev2curr=math.atan2((curr.x-prev.x), (prev.z-curr.z))\r
+       local curr2next=math.atan2((next.x-curr.x), (curr.z-next.z))\r
+       --print("y3 "..(prev2curr*360/(2*math.pi)).." "..(curr2next*360/(2*math.pi)))\r
+       return prev2curr+(advtrains.minAngleDiffRad(prev2curr, curr2next)/2)\r
+end\r
+function advtrains.get_wagon_yaw(front, first, second, back, pct)\r
+       local pts=minetest.pos_to_string\r
+       --print("p "..pts(front)..pts(first)..pts(second)..pts(back))\r
+       local y2=advtrains.yaw_from_3_positions(second, first, front)\r
+       local y1=advtrains.yaw_from_3_positions(back, second, first)\r
+       --print("y "..(y1*360/(2*math.pi)).." "..(y2*360/(2*math.pi)))\r
+       return y1+advtrains.minAngleDiffRad(y1, y2)*pct\r
+end\r
+function advtrains.get_real_index_position(path, index)\r
+       if not path or not index then return end\r
+       \r
+       local first_pos=path[math.floor(index)]\r
+       local second_pos=path[math.floor(index)+1]\r
+       \r
+       if not first_pos or not second_pos then return nil end\r
+       \r
+       local factor=index-math.floor(index)\r
+       local actual_pos={x=first_pos.x-(first_pos.x-second_pos.x)*factor, y=first_pos.y-(first_pos.y-second_pos.y)*factor, z=first_pos.z-(first_pos.z-second_pos.z)*factor,}\r
+       return actual_pos\r
+end\r
+function advtrains.pos_median(pos1, pos2)\r
+       return {x=pos1.x-(pos1.x-pos2.x)*0.5, y=pos1.y-(pos1.y-pos2.y)*0.5, z=pos1.z-(pos1.z-pos2.z)*0.5}\r
+end\r
+function advtrains.abs_ceil(i)\r
+       return math.ceil(math.abs(i))*math.sign(i)\r
+end\r
+\r
+function advtrains.serialize_inventory(inv)\r
+       local ser={}\r
+       local liszts=inv:get_lists()\r
+       for lisztname, liszt in pairs(liszts) do\r
+               ser[lisztname]={}\r
+               for idx, item in ipairs(liszt) do\r
+                       local istring=item:to_string()\r
+                       if istring~="" then\r
+                               ser[lisztname][idx]=istring\r
+                       end\r
+               end\r
+       end\r
+       return minetest.serialize(ser)\r
+end\r
+function advtrains.deserialize_inventory(sers, inv)\r
+       local ser=minetest.deserialize(sers)\r
+       if ser then\r
+               inv:set_lists(ser)\r
+               return true\r
+       end\r
+       return false\r
+end\r
diff --git a/advtrains/advtrains/init.lua b/advtrains/advtrains/init.lua
new file mode 100644 (file)
index 0000000..33aa962
--- /dev/null
@@ -0,0 +1,40 @@
+--advtrains
+
+advtrains={}
+
+advtrains.modpath = minetest.get_modpath("advtrains")
+
+print=function(t, ...) minetest.log("action", table.concat({t, ...}, " ")) minetest.chat_send_all(table.concat({t, ...}, " ")) end
+sid=function(id) return string.sub(id, -4) end
+
+dofile(advtrains.modpath.."/helpers.lua");
+dofile(advtrains.modpath.."/debugitems.lua");
+
+advtrains.meseconrules = 
+{{x=0,  y=0,  z=-1},
+ {x=1,  y=0,  z=0},
+ {x=-1, y=0,  z=0},
+ {x=0,  y=0,  z=1},
+ {x=1,  y=1,  z=0},
+ {x=1,  y=-1, z=0},
+ {x=-1, y=1,  z=0},
+ {x=-1, y=-1, z=0},
+ {x=0,  y=1,  z=1},
+ {x=0,  y=-1, z=1},
+ {x=0,  y=1,  z=-1},
+ {x=0,  y=-1, z=-1},
+ {x=0, y=-2, z=0}}
+dofile(advtrains.modpath.."/trainlogic.lua")
+dofile(advtrains.modpath.."/trainhud.lua")
+dofile(advtrains.modpath.."/trackplacer.lua")
+dofile(advtrains.modpath.."/tracks.lua")
+dofile(advtrains.modpath.."/atc.lua")
+dofile(advtrains.modpath.."/wagons.lua")
+
+dofile(advtrains.modpath.."/pseudoload.lua")
+dofile(advtrains.modpath.."/couple.lua")
+dofile(advtrains.modpath.."/damage.lua")
+
+dofile(advtrains.modpath.."/signals.lua")
+dofile(advtrains.modpath.."/misc_nodes.lua")
+dofile(advtrains.modpath.."/crafting.lua")
diff --git a/advtrains/advtrains/misc_nodes.lua b/advtrains/advtrains/misc_nodes.lua
new file mode 100644 (file)
index 0000000..93829f0
--- /dev/null
@@ -0,0 +1,67 @@
+--all nodes that do not fit in any other category
+
+function advtrains.register_platform(preset)
+       local ndef=minetest.registered_nodes[preset]
+       if not ndef then 
+               minetest.log("warning", "[advtrains] register_platform couldn't find preset node "..preset)
+               return
+       end
+       local btex=ndef.tiles
+       if type(btex)=="table" then
+               btex=btex[1]
+       end
+       local desc=ndef.description or ""
+       local nodename=string.match(preset, ":(.+)$")
+       minetest.register_node("advtrains:platform_low_"..nodename, {
+               description = desc.." Platform (low)",
+               tiles = {btex.."^advtrains_platform.png", btex, btex, btex, btex, btex},
+               groups = {cracky = 1, not_blocking_trains = 1, platform=1},
+               sounds = default.node_sound_stone_defaults(),
+               drawtype = "nodebox",
+               node_box = {
+                       type = "fixed",
+                       fixed = {
+                               {-0.5, -0.1, -0.1, 0.5,  0  , 0.5},
+                               {-0.5, -0.5,  0  , 0.5, -0.1, 0.5}
+                       },
+               },
+               paramtype2="facedir",
+               paramtype = "light",
+               sunlight_propagates = true,
+       })
+       minetest.register_node("advtrains:platform_high_"..nodename, {
+               description = desc.." Platform (high)",
+               tiles = {btex.."^advtrains_platform.png", btex, btex, btex, btex, btex},
+               groups = {cracky = 1, not_blocking_trains = 1, platform=2},
+               sounds = default.node_sound_stone_defaults(),
+               drawtype = "nodebox",
+               node_box = {
+                       type = "fixed",
+                       fixed = {
+                               {-0.5,  0.3, -0.1, 0.5,  0.5, 0.5},
+                               {-0.5, -0.5,  0  , 0.5,  0.3, 0.5}
+                       },
+               },
+               paramtype2="facedir",
+               paramtype = "light",
+               sunlight_propagates = true,
+       })
+       minetest.register_craft({
+               type="shapeless",
+               output = "advtrains:platform_high_"..nodename.." 4",
+               recipe = {
+                       "dye:yellow", preset, preset
+               },
+       })
+       minetest.register_craft({
+               type="shapeless",
+               output = "advtrains:platform_low_"..nodename.." 4",
+               recipe = {
+                       "dye:yellow", preset
+               },
+       })
+end
+
+
+advtrains.register_platform("default:stonebrick")
+advtrains.register_platform("default:sandstonebrick")
diff --git a/advtrains/advtrains/models/advtrains_dtrack_bumper_st.b3d b/advtrains/advtrains/models/advtrains_dtrack_bumper_st.b3d
new file mode 100644 (file)
index 0000000..a6d9745
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_dtrack_bumper_st.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_dtrack_bumper_st_30.b3d b/advtrains/advtrains/models/advtrains_dtrack_bumper_st_30.b3d
new file mode 100644 (file)
index 0000000..5f5b3f4
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_dtrack_bumper_st_30.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_dtrack_bumper_st_45.b3d b/advtrains/advtrains/models/advtrains_dtrack_bumper_st_45.b3d
new file mode 100644 (file)
index 0000000..f13ae75
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_dtrack_bumper_st_45.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_dtrack_bumper_st_60.b3d b/advtrains/advtrains/models/advtrains_dtrack_bumper_st_60.b3d
new file mode 100644 (file)
index 0000000..59a2285
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_dtrack_bumper_st_60.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_dtrack_cr.b3d b/advtrains/advtrains/models/advtrains_dtrack_cr.b3d
new file mode 100644 (file)
index 0000000..159717e
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_dtrack_cr.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_dtrack_cr_30.b3d b/advtrains/advtrains/models/advtrains_dtrack_cr_30.b3d
new file mode 100644 (file)
index 0000000..09cdb1f
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_dtrack_cr_30.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_dtrack_cr_45.b3d b/advtrains/advtrains/models/advtrains_dtrack_cr_45.b3d
new file mode 100644 (file)
index 0000000..176da81
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_dtrack_cr_45.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_dtrack_cr_60.b3d b/advtrains/advtrains/models/advtrains_dtrack_cr_60.b3d
new file mode 100644 (file)
index 0000000..00313c8
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_dtrack_cr_60.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_dtrack_detector_st.b3d b/advtrains/advtrains/models/advtrains_dtrack_detector_st.b3d
new file mode 100644 (file)
index 0000000..6762bc3
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_dtrack_detector_st.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_dtrack_detector_st_30.b3d b/advtrains/advtrains/models/advtrains_dtrack_detector_st_30.b3d
new file mode 100644 (file)
index 0000000..f2d5991
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_dtrack_detector_st_30.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_dtrack_detector_st_45.b3d b/advtrains/advtrains/models/advtrains_dtrack_detector_st_45.b3d
new file mode 100644 (file)
index 0000000..9ecb4a6
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_dtrack_detector_st_45.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_dtrack_detector_st_60.b3d b/advtrains/advtrains/models/advtrains_dtrack_detector_st_60.b3d
new file mode 100644 (file)
index 0000000..bd102cb
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_dtrack_detector_st_60.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_dtrack_st.b3d b/advtrains/advtrains/models/advtrains_dtrack_st.b3d
new file mode 100644 (file)
index 0000000..f3e2753
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_dtrack_st.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_dtrack_st_30.b3d b/advtrains/advtrains/models/advtrains_dtrack_st_30.b3d
new file mode 100644 (file)
index 0000000..7a35c8d
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_dtrack_st_30.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_dtrack_st_45.b3d b/advtrains/advtrains/models/advtrains_dtrack_st_45.b3d
new file mode 100644 (file)
index 0000000..b2a1702
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_dtrack_st_45.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_dtrack_st_60.b3d b/advtrains/advtrains/models/advtrains_dtrack_st_60.b3d
new file mode 100644 (file)
index 0000000..0a59f77
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_dtrack_st_60.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_dtrack_swlcr.b3d b/advtrains/advtrains/models/advtrains_dtrack_swlcr.b3d
new file mode 100644 (file)
index 0000000..1adc23f
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_dtrack_swlcr.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_dtrack_swlcr_30.b3d b/advtrains/advtrains/models/advtrains_dtrack_swlcr_30.b3d
new file mode 100644 (file)
index 0000000..7d8373b
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_dtrack_swlcr_30.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_dtrack_swlcr_45.b3d b/advtrains/advtrains/models/advtrains_dtrack_swlcr_45.b3d
new file mode 100644 (file)
index 0000000..9679b9e
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_dtrack_swlcr_45.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_dtrack_swlcr_60.b3d b/advtrains/advtrains/models/advtrains_dtrack_swlcr_60.b3d
new file mode 100644 (file)
index 0000000..3efc924
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_dtrack_swlcr_60.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_dtrack_swlst.b3d b/advtrains/advtrains/models/advtrains_dtrack_swlst.b3d
new file mode 100644 (file)
index 0000000..93841a4
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_dtrack_swlst.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_dtrack_swlst_30.b3d b/advtrains/advtrains/models/advtrains_dtrack_swlst_30.b3d
new file mode 100644 (file)
index 0000000..e9a90c7
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_dtrack_swlst_30.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_dtrack_swlst_45.b3d b/advtrains/advtrains/models/advtrains_dtrack_swlst_45.b3d
new file mode 100644 (file)
index 0000000..49c707c
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_dtrack_swlst_45.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_dtrack_swlst_60.b3d b/advtrains/advtrains/models/advtrains_dtrack_swlst_60.b3d
new file mode 100644 (file)
index 0000000..c9a6ffe
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_dtrack_swlst_60.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_dtrack_swrcr.b3d b/advtrains/advtrains/models/advtrains_dtrack_swrcr.b3d
new file mode 100644 (file)
index 0000000..ee29b62
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_dtrack_swrcr.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_dtrack_swrcr_30.b3d b/advtrains/advtrains/models/advtrains_dtrack_swrcr_30.b3d
new file mode 100644 (file)
index 0000000..ba065e1
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_dtrack_swrcr_30.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_dtrack_swrcr_45.b3d b/advtrains/advtrains/models/advtrains_dtrack_swrcr_45.b3d
new file mode 100644 (file)
index 0000000..7f9dc43
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_dtrack_swrcr_45.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_dtrack_swrcr_60.b3d b/advtrains/advtrains/models/advtrains_dtrack_swrcr_60.b3d
new file mode 100644 (file)
index 0000000..b8ffa61
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_dtrack_swrcr_60.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_dtrack_swrst.b3d b/advtrains/advtrains/models/advtrains_dtrack_swrst.b3d
new file mode 100644 (file)
index 0000000..0b3e7ad
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_dtrack_swrst.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_dtrack_swrst_30.b3d b/advtrains/advtrains/models/advtrains_dtrack_swrst_30.b3d
new file mode 100644 (file)
index 0000000..4aea19b
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_dtrack_swrst_30.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_dtrack_swrst_45.b3d b/advtrains/advtrains/models/advtrains_dtrack_swrst_45.b3d
new file mode 100644 (file)
index 0000000..4182fe5
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_dtrack_swrst_45.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_dtrack_swrst_60.b3d b/advtrains/advtrains/models/advtrains_dtrack_swrst_60.b3d
new file mode 100644 (file)
index 0000000..6d2c891
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_dtrack_swrst_60.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_dtrack_vst1.b3d b/advtrains/advtrains/models/advtrains_dtrack_vst1.b3d
new file mode 100644 (file)
index 0000000..c9d7427
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_dtrack_vst1.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_dtrack_vst1_45.b3d b/advtrains/advtrains/models/advtrains_dtrack_vst1_45.b3d
new file mode 100644 (file)
index 0000000..14d438c
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_dtrack_vst1_45.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_dtrack_vst2.b3d b/advtrains/advtrains/models/advtrains_dtrack_vst2.b3d
new file mode 100644 (file)
index 0000000..c128650
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_dtrack_vst2.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_dtrack_vst2_45.b3d b/advtrains/advtrains/models/advtrains_dtrack_vst2_45.b3d
new file mode 100644 (file)
index 0000000..263276d
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_dtrack_vst2_45.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_dtrack_vst31.b3d b/advtrains/advtrains/models/advtrains_dtrack_vst31.b3d
new file mode 100644 (file)
index 0000000..df0f383
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_dtrack_vst31.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_dtrack_vst32.b3d b/advtrains/advtrains/models/advtrains_dtrack_vst32.b3d
new file mode 100644 (file)
index 0000000..01d2978
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_dtrack_vst32.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_dtrack_vst33.b3d b/advtrains/advtrains/models/advtrains_dtrack_vst33.b3d
new file mode 100644 (file)
index 0000000..7fe418d
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_dtrack_vst33.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_modernwagon.b3d b/advtrains/advtrains/models/advtrains_modernwagon.b3d
new file mode 100644 (file)
index 0000000..aacddca
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_modernwagon.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_retrosignal_off.b3d b/advtrains/advtrains/models/advtrains_retrosignal_off.b3d
new file mode 100644 (file)
index 0000000..3d231dd
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_retrosignal_off.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_retrosignal_off_30.b3d b/advtrains/advtrains/models/advtrains_retrosignal_off_30.b3d
new file mode 100644 (file)
index 0000000..da258e1
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_retrosignal_off_30.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_retrosignal_off_45.b3d b/advtrains/advtrains/models/advtrains_retrosignal_off_45.b3d
new file mode 100644 (file)
index 0000000..338224a
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_retrosignal_off_45.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_retrosignal_off_60.b3d b/advtrains/advtrains/models/advtrains_retrosignal_off_60.b3d
new file mode 100644 (file)
index 0000000..c560ca1
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_retrosignal_off_60.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_retrosignal_on.b3d b/advtrains/advtrains/models/advtrains_retrosignal_on.b3d
new file mode 100644 (file)
index 0000000..3d19439
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_retrosignal_on.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_retrosignal_on_30.b3d b/advtrains/advtrains/models/advtrains_retrosignal_on_30.b3d
new file mode 100644 (file)
index 0000000..98f8a92
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_retrosignal_on_30.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_retrosignal_on_45.b3d b/advtrains/advtrains/models/advtrains_retrosignal_on_45.b3d
new file mode 100644 (file)
index 0000000..414e121
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_retrosignal_on_45.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_retrosignal_on_60.b3d b/advtrains/advtrains/models/advtrains_retrosignal_on_60.b3d
new file mode 100644 (file)
index 0000000..a51529a
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_retrosignal_on_60.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_signal.b3d b/advtrains/advtrains/models/advtrains_signal.b3d
new file mode 100644 (file)
index 0000000..7f69560
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_signal.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_signal_30.b3d b/advtrains/advtrains/models/advtrains_signal_30.b3d
new file mode 100644 (file)
index 0000000..0b949a7
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_signal_30.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_signal_45.b3d b/advtrains/advtrains/models/advtrains_signal_45.b3d
new file mode 100644 (file)
index 0000000..ccaebf4
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_signal_45.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_signal_60.b3d b/advtrains/advtrains/models/advtrains_signal_60.b3d
new file mode 100644 (file)
index 0000000..cf41e6d
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_signal_60.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_track_cr.b3d b/advtrains/advtrains/models/advtrains_track_cr.b3d
new file mode 100644 (file)
index 0000000..b0f5e4b
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_track_cr.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_track_st.b3d b/advtrains/advtrains/models/advtrains_track_st.b3d
new file mode 100644 (file)
index 0000000..10b5d90
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_track_st.b3d differ
diff --git a/advtrains/advtrains/models/advtrains_track_st_45.b3d b/advtrains/advtrains/models/advtrains_track_st_45.b3d
new file mode 100644 (file)
index 0000000..32505a1
Binary files /dev/null and b/advtrains/advtrains/models/advtrains_track_st_45.b3d differ
diff --git a/advtrains/advtrains/models/trackplane.b3d b/advtrains/advtrains/models/trackplane.b3d
new file mode 100644 (file)
index 0000000..b4728c3
Binary files /dev/null and b/advtrains/advtrains/models/trackplane.b3d differ
diff --git a/advtrains/advtrains/pseudoload.lua b/advtrains/advtrains/pseudoload.lua
new file mode 100644 (file)
index 0000000..677cd14
--- /dev/null
@@ -0,0 +1,182 @@
+local print=function(t) minetest.log("action", t) minetest.chat_send_all(t) end
+
+--pseudoload.lua
+--responsible for keeping up a database of all rail nodes existant in the world, regardless of whether the mapchunk is loaded.
+
+advtrains.trackdb={}
+--trackdb[tt][y][x][z]={conn1, conn2, rely1, rely2, railheight}
+--serialization format:
+--(2byte x)(2byte y)(2byte z)(4bits conn1, 4bits conn2)[(plain rely1)|(plain rely2)|(plain railheight)]\n
+--[] may be missing if 0,0,0
+
+--load initially
+
+--[[ TODO temporary outcomment
+
+--delayed since all traintypes need to be registered
+minetest.after(0, function()
+
+for tt, _ in pairs(advtrains.all_traintypes) do
+       local pl_fpath=minetest.get_worldpath().."/advtrains_trackdb_"..tt
+       advtrains.trackdb[tt]={}
+       local file, err = io.open(pl_fpath, "r")
+       if not file then
+               local er=err or "Unknown Error"
+               print("[advtrains]Failed loading advtrains trackdb save file "..er)
+       else
+               --custom format to save memory
+               while true do
+                       local xbytes=file:read(2)
+                       if not xbytes or #xbytes<2 then
+                               break --eof reached
+                       end
+                       print(xbytes)
+                       local ybytes=file:read(2)
+                       local zbytes=file:read(2)
+                       local x=(string.byte(xbytes[1])-128)*256+(string.byte(xbytes[2]))
+                       local y=(string.byte(ybytes[1])-128)*256+(string.byte(ybytes[2]))
+                       local z=(string.byte(zbytes[1])-128)*256+(string.byte(zbytes[2]))
+                       
+                       local conn1=string.byte(file:read(1))
+                       local conn1=string.byte(file:read(1))
+                       
+                       if not advtrains.trackdb[tt][y] then advtrains.trackdb[tt][y]={} end
+                       if not advtrains.trackdb[tt][y][x] then advtrains.trackdb[tt][y][x]={} end
+                       
+                       local rest=file.read("*l")
+                       if rest~="" then
+                               local rely1, rely2, railheight=string.match(rest, "([^|]+)|([^|]+)|([^|]+)")
+                               if rely1 and rely2 and railheight then
+                                       advtrains.trackdb[tt][y][x][z]={
+                                               conn1=conn1, conn2=conn2,
+                                               rely1=rely1, rely2=rely2,
+                                               railheight=railheight
+                                       }
+                               else
+                                       advtrains.trackdb[tt][y][x][z]={
+                                               conn1=conn1, conn2=conn2
+                                       }
+                               end
+                       else
+                               advtrains.trackdb[tt][y][x][z]={
+                                       conn1=conn1, conn2=conn2
+                               }
+                       end
+               end
+               file:close()
+       end
+end
+
+--end minetest.after
+end)
+
+function advtrains.save_trackdb()
+       for tt, _ in pairs(advtrains.all_traintypes) do
+               local pl_fpath=minetest.get_worldpath().."/advtrains_trackdb_"..tt
+               local file, err = io.open(pl_fpath, "w")
+               if not file then
+                       local er=err or "Unknown Error"
+                       print("[advtrains]Failed saving advtrains trackdb save file "..er)
+               else
+                       --custom format to save memory
+                       for y,tyl in pairs(advtrains.trackdb[tt]) do
+                               for x,txl in pairs(tyl) do
+                                       for z,rail in pairs(txl) do
+                                               print("write "..x.." "..y.." "..z.." "..minetest.serialize(rail))
+                                               file:write(string.char(math.floor(x/256)+128)..string.char((x%256)))
+                                               file:write(string.char(math.floor(y/256)+128)..string.char((y%256)))
+                                               file:write(string.char(math.floor(z/256)+128)..string.char((z%256)))
+                                               file:write(string.char(rail.conn1))
+                                               file:write(string.char(rail.conn2))
+                                               if (rail.rely1 and rail.rely1~=0) or (rail.rely2 and rail.rely2~=0) or (rail.railheight and rail.railheight~=0) then
+                                                       file:write(rail.rely1.."|"..rail.rely2.."|"..rail.railheight)
+                                               end
+                                               file:write("\n")
+                                       end
+                               end
+                       end
+                       file:close()
+               end
+       end
+end
+]]--end temp outcomment
+advtrains.trackdb={}
+advtrains.fpath_tdb=minetest.get_worldpath().."/advtrains_trackdb2"
+local file, err = io.open(advtrains.fpath_tdb, "r")
+if not file then
+       local er=err or "Unknown Error"
+       print("[advtrains]Failed loading advtrains save file "..er)
+else
+       local tbl = minetest.deserialize(file:read("*a"))
+       if type(tbl) == "table" then
+               advtrains.trackdb=tbl
+       end
+       file:close()
+end
+function advtrains.save_trackdb()
+       local datastr = minetest.serialize(advtrains.trackdb)
+       if not datastr then
+               minetest.log("error", "[advtrains] Failed to serialize trackdb data!")
+               return
+       end
+       local file, err = io.open(advtrains.fpath_tdb, "w")
+       if err then
+               return err
+       end
+       file:write(datastr)
+       file:close()
+end
+
+--get_node with pseudoload.
+--returns:
+--true, conn1, conn2, rely1, rely2, railheight   in case everything's right.
+--false  if it's not a rail or the train does not drive on this rail, but it is loaded or
+--nil    if the node is neither loaded nor in trackdb
+--the distraction between false and nil will be needed only in special cases.(train initpos)
+function advtrains.get_rail_info_at(pos, drives_on)
+       local node=minetest.get_node_or_nil(pos)
+       if not node then
+               --try raildb
+               local rdp=vector.round(pos)
+               local dbe=(advtrains.trackdb[traintype] and advtrains.trackdb[traintype][rdp.y] and advtrains.trackdb[traintype][rdp.y][rdp.x] and advtrains.trackdb[traintype][rdp.y][rdp.x][rdp.z])
+               if dbe then
+                       for tt,_ in pairs(drives_on) do
+                               if not dbe.tracktype or tt==dbe.tracktype then
+                                       return true, dbe.conn1, dbe.conn2, dbe.rely1 or 0, dbe.rely2 or 0, dbe.railheight or 0
+                               end
+                       end
+               else
+                       return nil
+               end
+       end
+       local nodename=node.name
+       if(not advtrains.is_track_and_drives_on(nodename, drives_on)) then
+               return false
+       end
+       local conn1, conn2, rely1, rely2, railheight, tracktype=advtrains.get_track_connections(node.name, node.param2)
+       
+       --already in trackdb?
+       local rdp=vector.round(pos)
+       if not (advtrains.trackdb and advtrains.trackdb[rdp.y] and advtrains.trackdb[rdp.y][rdp.x] and advtrains.trackdb[rdp.y][rdp.x][rdp.z]) then--TODO is this necessary?
+               if not advtrains.trackdb then advtrains.trackdb={} end
+               if not advtrains.trackdb[rdp.y] then advtrains.trackdb[rdp.y]={} end
+               if not advtrains.trackdb[rdp.y][rdp.x] then advtrains.trackdb[rdp.y][rdp.x]={} end
+               advtrains.trackdb[rdp.y][rdp.x][rdp.z]={
+                       conn1=conn1, conn2=conn2,
+                       rely1=rely1, rely2=rely2,
+                       railheight=railheight, tracktype=tracktype
+               }
+       end
+       
+       return true, conn1, conn2, rely1, rely2, railheight
+end
+function advtrains.reset_trackdb_position(pos)
+       local rdp=vector.round(pos)
+       if not advtrains.trackdb then advtrains.trackdb={} end
+       if not advtrains.trackdb[rdp.y] then advtrains.trackdb[rdp.y]={} end
+       if not advtrains.trackdb[rdp.y][rdp.x] then advtrains.trackdb[rdp.y][rdp.x]={} end
+       advtrains.trackdb[rdp.y][rdp.x][rdp.z]=nil
+       advtrains.get_rail_info_at(pos, advtrains.all_tracktypes)--to restore it.
+end
+       
+
diff --git a/advtrains/advtrains/readme.txt b/advtrains/advtrains/readme.txt
new file mode 100644 (file)
index 0000000..ad093bd
--- /dev/null
@@ -0,0 +1,23 @@
+\r
+## ADVTRAINS ## realistic trains in Minetest!\r
+by orwell96 and contributors(see below)\r
+\r
+For up-to-date information, visit https://forum.minetest.net/viewtopic.php?f=9&t=14726
+\r
+\r
+Manual:
+If manual.pdf is not present (which is the case when you downloaded the zip file), see https://github.com/orwell96/advtrains/blob/master/manual.pdf\r
+\r
+License of code: LGPL 2.1\r
+License of media: CC-BY-NC-SA 3.0\r
+\r
+Contributions:\r
+\r
+Gravel Texture              : from Minetest Game\r
+Initial rail model/texture  : DS-minetest\r
+Models for signals/bumpers  : mbb\r
+Steam engine / wagon texture: mbb
+Industrial engine/wagons    : mbb
+Inventory images            : mbb
+Small code contributions    : NaruTrey / gpcf
+Mod Description             : hajo
\ No newline at end of file
diff --git a/advtrains/advtrains/signals.lua b/advtrains/advtrains/signals.lua
new file mode 100644 (file)
index 0000000..8be65e0
--- /dev/null
@@ -0,0 +1,76 @@
+--advtrains by orwell96
+--signals.lua
+for r,f in pairs({on="off", off="on"}) do
+
+       advtrains.trackplacer.register_tracktype("advtrains:retrosignal", "")
+       advtrains.trackplacer.register_tracktype("advtrains:signal", "")
+
+       for rotid, rotation in ipairs({"", "_30", "_45", "_60"}) do
+               local crea=1
+               if rotid==1 and r=="off" then crea=0 end
+               
+               minetest.register_node("advtrains:retrosignal_"..r..rotation, {
+                       drawtype = "mesh",
+                       paramtype="light",
+                       paramtype2="facedir",
+                       walkable = false,
+                       selection_box = {
+                               type = "fixed",
+                               fixed = {-1/4, -1/2, -1/4, 1/4, 2, 1/4},
+                       },
+                       mesh = "advtrains_retrosignal_"..r..rotation..".b3d",
+                       tiles = {"advtrains_retrosignal.png"},
+                       inventory_image="advtrains_retrosignal_inv.png",
+                       drop="advtrains:retrosignal_off",
+                       description="Lampless Signal ("..r..rotation..")",
+                       on_rightclick=switchfunc,
+                       sunlight_propagates=true,
+                       groups = {
+                               choppy=3,
+                               not_blocking_trains=1,
+                               not_in_creative_inventory=crea,
+                       },
+                       mesecons = {effector = {
+                               ["action_"..f] = function (pos, node)
+                                       minetest.swap_node(pos, {name = "advtrains:retrosignal_"..f..rotation, param2 = node.param2})
+                               end
+                       }},
+                       on_rightclick=function(pos, node, clicker)
+                               minetest.swap_node(pos, {name = "advtrains:retrosignal_"..f..rotation, param2 = node.param2})
+                       end,
+               })
+               advtrains.trackplacer.add_worked("advtrains:retrosignal", r, rotation, nil)
+               minetest.register_node("advtrains:signal_"..r..rotation, {
+                       drawtype = "mesh",
+                       paramtype="light",
+                       paramtype2="facedir",
+                       walkable = false,
+                       selection_box = {
+                               type = "fixed",
+                               fixed = {-1/4, -1/2, -1/4, 1/4, 2, 1/4},
+                       },
+                       mesh = "advtrains_signal"..rotation..".b3d",
+                       tiles = {"advtrains_signal_"..r..".png"},
+                       inventory_image="advtrains_signal_inv.png",
+                       drop="advtrains:signal_off",
+                       description="Signal ("..r..rotation..")",
+                       on_rightclick=switchfunc,
+                       groups = {
+                               choppy=3,
+                               not_blocking_trains=1,
+                               not_in_creative_inventory=crea,
+                       },
+                       light_source = 1,
+                       sunlight_propagates=true,
+                       mesecons = {effector = {
+                               ["action_"..f] = function (pos, node)
+                                       minetest.swap_node(pos, {name = "advtrains:signal_"..f..rotation, param2 = node.param2})
+                               end
+                       }},
+                       on_rightclick=function(pos, node, clicker)
+                               minetest.swap_node(pos, {name = "advtrains:signal_"..f..rotation, param2 = node.param2})
+                       end,
+               })
+               advtrains.trackplacer.add_worked("advtrains:signal", r, rotation, nil)
+       end
+end
diff --git a/advtrains/advtrains/textures/advtrains_couple.png b/advtrains/advtrains/textures/advtrains_couple.png
new file mode 100644 (file)
index 0000000..9e997e4
Binary files /dev/null and b/advtrains/advtrains/textures/advtrains_couple.png differ
diff --git a/advtrains/advtrains/textures/advtrains_discouple.png b/advtrains/advtrains/textures/advtrains_discouple.png
new file mode 100644 (file)
index 0000000..b27c4fb
Binary files /dev/null and b/advtrains/advtrains/textures/advtrains_discouple.png differ
diff --git a/advtrains/advtrains/textures/advtrains_dtrack_atc_placer.png b/advtrains/advtrains/textures/advtrains_dtrack_atc_placer.png
new file mode 100644 (file)
index 0000000..31c2b30
Binary files /dev/null and b/advtrains/advtrains/textures/advtrains_dtrack_atc_placer.png differ
diff --git a/advtrains/advtrains/textures/advtrains_dtrack_bumper_placer.png b/advtrains/advtrains/textures/advtrains_dtrack_bumper_placer.png
new file mode 100644 (file)
index 0000000..27191fe
Binary files /dev/null and b/advtrains/advtrains/textures/advtrains_dtrack_bumper_placer.png differ
diff --git a/advtrains/advtrains/textures/advtrains_dtrack_detector_placer.png b/advtrains/advtrains/textures/advtrains_dtrack_detector_placer.png
new file mode 100644 (file)
index 0000000..e6c6ad6
Binary files /dev/null and b/advtrains/advtrains/textures/advtrains_dtrack_detector_placer.png differ
diff --git a/advtrains/advtrains/textures/advtrains_dtrack_placer.png b/advtrains/advtrains/textures/advtrains_dtrack_placer.png
new file mode 100644 (file)
index 0000000..7bef8a9
Binary files /dev/null and b/advtrains/advtrains/textures/advtrains_dtrack_placer.png differ
diff --git a/advtrains/advtrains/textures/advtrains_dtrack_rail.png b/advtrains/advtrains/textures/advtrains_dtrack_rail.png
new file mode 100644 (file)
index 0000000..1cf7f83
Binary files /dev/null and b/advtrains/advtrains/textures/advtrains_dtrack_rail.png differ
diff --git a/advtrains/advtrains/textures/advtrains_dtrack_rail_atc.png b/advtrains/advtrains/textures/advtrains_dtrack_rail_atc.png
new file mode 100644 (file)
index 0000000..d171985
Binary files /dev/null and b/advtrains/advtrains/textures/advtrains_dtrack_rail_atc.png differ
diff --git a/advtrains/advtrains/textures/advtrains_dtrack_rail_detector_on.png b/advtrains/advtrains/textures/advtrains_dtrack_rail_detector_on.png
new file mode 100644 (file)
index 0000000..4f09b35
Binary files /dev/null and b/advtrains/advtrains/textures/advtrains_dtrack_rail_detector_on.png differ
diff --git a/advtrains/advtrains/textures/advtrains_dtrack_slopeplacer.png b/advtrains/advtrains/textures/advtrains_dtrack_slopeplacer.png
new file mode 100644 (file)
index 0000000..1d456b0
Binary files /dev/null and b/advtrains/advtrains/textures/advtrains_dtrack_slopeplacer.png differ
diff --git a/advtrains/advtrains/textures/advtrains_platform.png b/advtrains/advtrains/textures/advtrains_platform.png
new file mode 100644 (file)
index 0000000..5ba9663
Binary files /dev/null and b/advtrains/advtrains/textures/advtrains_platform.png differ
diff --git a/advtrains/advtrains/textures/advtrains_retrosignal.png b/advtrains/advtrains/textures/advtrains_retrosignal.png
new file mode 100644 (file)
index 0000000..141198d
Binary files /dev/null and b/advtrains/advtrains/textures/advtrains_retrosignal.png differ
diff --git a/advtrains/advtrains/textures/advtrains_retrosignal_inv.png b/advtrains/advtrains/textures/advtrains_retrosignal_inv.png
new file mode 100644 (file)
index 0000000..1036594
Binary files /dev/null and b/advtrains/advtrains/textures/advtrains_retrosignal_inv.png differ
diff --git a/advtrains/advtrains/textures/advtrains_signal_inv.png b/advtrains/advtrains/textures/advtrains_signal_inv.png
new file mode 100644 (file)
index 0000000..ed64ed9
Binary files /dev/null and b/advtrains/advtrains/textures/advtrains_signal_inv.png differ
diff --git a/advtrains/advtrains/textures/advtrains_signal_off.png b/advtrains/advtrains/textures/advtrains_signal_off.png
new file mode 100644 (file)
index 0000000..8046e52
Binary files /dev/null and b/advtrains/advtrains/textures/advtrains_signal_off.png differ
diff --git a/advtrains/advtrains/textures/advtrains_signal_on.png b/advtrains/advtrains/textures/advtrains_signal_on.png
new file mode 100644 (file)
index 0000000..5228bb3
Binary files /dev/null and b/advtrains/advtrains/textures/advtrains_signal_on.png differ
diff --git a/advtrains/advtrains/textures/advtrains_track_cr.png b/advtrains/advtrains/textures/advtrains_track_cr.png
new file mode 100644 (file)
index 0000000..40f0cc5
Binary files /dev/null and b/advtrains/advtrains/textures/advtrains_track_cr.png differ
diff --git a/advtrains/advtrains/textures/advtrains_track_cr_45.png b/advtrains/advtrains/textures/advtrains_track_cr_45.png
new file mode 100644 (file)
index 0000000..54966b3
Binary files /dev/null and b/advtrains/advtrains/textures/advtrains_track_cr_45.png differ
diff --git a/advtrains/advtrains/textures/advtrains_track_placer.png b/advtrains/advtrains/textures/advtrains_track_placer.png
new file mode 100644 (file)
index 0000000..03e17ed
Binary files /dev/null and b/advtrains/advtrains/textures/advtrains_track_placer.png differ
diff --git a/advtrains/advtrains/textures/advtrains_track_st.png b/advtrains/advtrains/textures/advtrains_track_st.png
new file mode 100644 (file)
index 0000000..5ad7e4f
Binary files /dev/null and b/advtrains/advtrains/textures/advtrains_track_st.png differ
diff --git a/advtrains/advtrains/textures/advtrains_track_st_45.png b/advtrains/advtrains/textures/advtrains_track_st_45.png
new file mode 100644 (file)
index 0000000..63b4c96
Binary files /dev/null and b/advtrains/advtrains/textures/advtrains_track_st_45.png differ
diff --git a/advtrains/advtrains/textures/advtrains_track_swlcr.png b/advtrains/advtrains/textures/advtrains_track_swlcr.png
new file mode 100644 (file)
index 0000000..d9b5c0b
Binary files /dev/null and b/advtrains/advtrains/textures/advtrains_track_swlcr.png differ
diff --git a/advtrains/advtrains/textures/advtrains_track_swlcr_45.png b/advtrains/advtrains/textures/advtrains_track_swlcr_45.png
new file mode 100644 (file)
index 0000000..f098fc9
Binary files /dev/null and b/advtrains/advtrains/textures/advtrains_track_swlcr_45.png differ
diff --git a/advtrains/advtrains/textures/advtrains_track_swlst.png b/advtrains/advtrains/textures/advtrains_track_swlst.png
new file mode 100644 (file)
index 0000000..314bd2d
Binary files /dev/null and b/advtrains/advtrains/textures/advtrains_track_swlst.png differ
diff --git a/advtrains/advtrains/textures/advtrains_track_swlst_45.png b/advtrains/advtrains/textures/advtrains_track_swlst_45.png
new file mode 100644 (file)
index 0000000..765d0ec
Binary files /dev/null and b/advtrains/advtrains/textures/advtrains_track_swlst_45.png differ
diff --git a/advtrains/advtrains/textures/advtrains_track_swrcr.png b/advtrains/advtrains/textures/advtrains_track_swrcr.png
new file mode 100644 (file)
index 0000000..f74e1bc
Binary files /dev/null and b/advtrains/advtrains/textures/advtrains_track_swrcr.png differ
diff --git a/advtrains/advtrains/textures/advtrains_track_swrcr_45.png b/advtrains/advtrains/textures/advtrains_track_swrcr_45.png
new file mode 100644 (file)
index 0000000..fa432aa
Binary files /dev/null and b/advtrains/advtrains/textures/advtrains_track_swrcr_45.png differ
diff --git a/advtrains/advtrains/textures/advtrains_track_swrst.png b/advtrains/advtrains/textures/advtrains_track_swrst.png
new file mode 100644 (file)
index 0000000..06ea29e
Binary files /dev/null and b/advtrains/advtrains/textures/advtrains_track_swrst.png differ
diff --git a/advtrains/advtrains/textures/advtrains_track_swrst_45.png b/advtrains/advtrains/textures/advtrains_track_swrst_45.png
new file mode 100644 (file)
index 0000000..be477b7
Binary files /dev/null and b/advtrains/advtrains/textures/advtrains_track_swrst_45.png differ
diff --git a/advtrains/advtrains/textures/advtrains_trackworker.png b/advtrains/advtrains/textures/advtrains_trackworker.png
new file mode 100644 (file)
index 0000000..b50bcae
Binary files /dev/null and b/advtrains/advtrains/textures/advtrains_trackworker.png differ
diff --git a/advtrains/advtrains/textures/drwho_screwdriver.png b/advtrains/advtrains/textures/drwho_screwdriver.png
new file mode 100644 (file)
index 0000000..b50bcae
Binary files /dev/null and b/advtrains/advtrains/textures/drwho_screwdriver.png differ
diff --git a/advtrains/advtrains/trackplacer.lua b/advtrains/advtrains/trackplacer.lua
new file mode 100644 (file)
index 0000000..b24103a
--- /dev/null
@@ -0,0 +1,297 @@
+--trackplacer.lua
+--holds code for the track-placing system. the default 'track' item will be a craftitem that places rails as needed. this will neither place or change switches nor place vertical rails.
+
+--all new trackplacer code
+local tp={
+       tracks={}
+}
+
+function tp.register_tracktype(nnprefix, n_suffix)
+       tp.tracks[nnprefix]={
+               default=n_suffix,
+               single_conn={},
+               double_conn={},
+               --keys:conn1_conn2 (example:1_4)
+               --values:{name=x, param2=x}
+               twcycle={},
+               twrotate={},--indexed by suffix, list, tells order of rotations
+               modify={}
+       }
+end
+function tp.add_double_conn(nnprefix, suffix, rotation, conns)
+       local nodename=nnprefix.."_"..suffix..rotation
+       for i=0,3 do
+               tp.tracks[nnprefix].double_conn[((conns.conn1+4*i)%16).."_"..((conns.conn2+4*i)%16)]={name=nodename, param2=i}
+               tp.tracks[nnprefix].double_conn[((conns.conn2+4*i)%16).."_"..((conns.conn1+4*i)%16)]={name=nodename, param2=i}
+       end
+       tp.tracks[nnprefix].modify[nodename]=true
+end
+function tp.add_single_conn(nnprefix, suffix, rotation, conns)
+       local nodename=nnprefix.."_"..suffix..rotation
+       for i=0,3 do
+               tp.tracks[nnprefix].single_conn[((conns.conn1+4*i)%16)]={name=nodename, param2=i}
+               tp.tracks[nnprefix].single_conn[((conns.conn2+4*i)%16)]={name=nodename, param2=i}
+       end
+       tp.tracks[nnprefix].modify[nodename]=true
+end
+
+function tp.add_worked(nnprefix, suffix, rotation, cycle_follows)
+       tp.tracks[nnprefix].twcycle[suffix]=cycle_follows
+       if not tp.tracks[nnprefix].twrotate[suffix] then tp.tracks[nnprefix].twrotate[suffix]={} end
+       table.insert(tp.tracks[nnprefix].twrotate[suffix], rotation)
+end
+
+
+--[[
+       rewrite algorithm.
+       selection criteria: these will never be changed or even selected:
+       - tracks being already connected on both sides
+       - tracks that are already connected on one side but are not bendable to the desired position
+       the following situations can occur:
+       1. there are two more than two rails around
+               1.1 there is one or more subset(s) that can be directly connected
+                       -> choose the first possibility
+               2.2 not
+                       -> choose the first one and orient straight
+       2. there's exactly 1 rail around
+               -> choose and orient straight
+       3. there's no rail around
+               -> set straight
+]]
+function tp.find_already_connected(pos)--TODO vertical calculations(check node below)
+       local function istrackandbc(pos, conn)
+               local cnode=minetest.get_node(advtrains.dirCoordSet(pos, conn))
+               local bconn=(conn+8)%16
+               if advtrains.is_track_and_drives_on(cnode.name, advtrains.all_tracktypes) then
+                       local cconn1, cconn2=advtrains.get_track_connections(cnode.name, cnode.param2)
+                       return cconn1==bconn or cconn2==bconn
+               end
+               return false
+       end
+       local dnode=minetest.get_node(pos)
+       local dconn1, dconn2=advtrains.get_track_connections(dnode.name, dnode.param2)
+       local t={[true]="true", [false]="false"}
+       if istrackandbc(pos, dconn1) and istrackandbc(pos, dconn2) then return dconn1, dconn2
+       elseif istrackandbc(pos, dconn1) then return dconn1
+       elseif istrackandbc(pos, dconn2) then return dconn2
+       end
+       return nil
+end
+function tp.rail_and_can_be_bent(originpos, conn, nnpref)
+       local pos=advtrains.dirCoordSet(originpos, conn)
+       local newdir=(conn+8)%16
+       local node=minetest.get_node(pos)
+       local tr=tp.tracks[nnpref]
+       if not advtrains.is_track_and_drives_on(node.name, advtrains.all_tracktypes) then
+               return false
+       end
+       --rail at other end?
+       local adj1, adj2=tp.find_already_connected(pos)
+       if adj1 and adj2 then
+               return false--dont destroy existing track
+       elseif adj1 and not adj2 then
+               if tr.double_conn[adj1.."_"..newdir] then
+                       return true--if exists, connect new rail and old end
+               end
+               return false
+       else
+               if tr.single_conn[newdir] then--just rotate old rail to right orientation
+                       return true
+               end
+               return false
+       end
+end
+function tp.bend_rail(originpos, conn, nnpref)
+       local pos=advtrains.dirCoordSet(originpos, conn)
+       local newdir=(conn+8)%16
+       local node=minetest.get_node(pos)
+       local tr=tp.tracks[nnpref]
+       --is rail already connected? no need to bend.
+       local conn1, conn2=advtrains.get_track_connections(node.name, node.param2)
+       if newdir==conn1 or newdir==conn2 then
+               return
+       end
+       --rail at other end?
+       local adj1, adj2=tp.find_already_connected(pos)
+       if adj1 and adj2 then
+               return false--dont destroy existing track
+       elseif adj1 and not adj2 then
+               if tr.double_conn[adj1.."_"..newdir] then
+                       minetest.set_node(pos, tr.double_conn[adj1.."_"..newdir])
+                       return true--if exists, connect new rail and old end
+               end
+               return false
+       else
+               if tr.single_conn[newdir] then--just rotate old rail to right orientation
+                       minetest.set_node(pos, tr.single_conn[newdir])
+                       return true
+               end
+               return false
+       end
+end
+function tp.placetrack(pos, nnpref, placer, itemstack, pointed_thing)
+       --1. find all rails that are likely to be connected
+       local tr=tp.tracks[nnpref]
+       local p_rails={}
+       for i=0,15 do
+               if tp.rail_and_can_be_bent(pos, i, nnpref) then
+                       p_rails[#p_rails+1]=i
+               end
+       end
+       if #p_rails==0 then
+               minetest.set_node(pos, {name=nnpref.."_"..tr.default})
+               if minetest.registered_nodes[nnpref.."_"..tr.default] and minetest.registered_nodes[nnpref.."_"..tr.default].after_place_node then
+                       minetest.registered_nodes[nnpref.."_"..tr.default].after_place_node(pos, placer, itemstack, pointed_thing)
+               end
+       elseif #p_rails==1 then
+               tp.bend_rail(pos, p_rails[1], nnpref)
+               minetest.set_node(pos, tr.single_conn[p_rails[1]])
+               local nname=tr.single_conn[p_rails[1]].name
+               if minetest.registered_nodes[nname] and minetest.registered_nodes[nname].after_place_node then
+                       minetest.registered_nodes[nname].after_place_node(pos, placer, itemstack, pointed_thing)
+               end
+       else
+               --iterate subsets
+               for k1, conn1 in ipairs(p_rails) do
+                       for k2, conn2 in ipairs(p_rails) do
+                               if k1~=k2 then
+                                       if (tr.double_conn[conn1.."_"..conn2]) then
+                                               tp.bend_rail(pos, conn1, nnpref)
+                                               tp.bend_rail(pos, conn2, nnpref)
+                                               minetest.set_node(pos, tr.double_conn[conn1.."_"..conn2])
+                                               local nname=tr.double_conn[conn1.."_"..conn2].name
+                                               if minetest.registered_nodes[nname] and minetest.registered_nodes[nname].after_place_node then
+                                                       minetest.registered_nodes[nname].after_place_node(pos, placer, itemstack, pointed_thing)
+                                               end
+                                               return
+                                       end
+                               end
+                       end
+               end
+               --not found
+               tp.bend_rail(pos, p_rails[1], nnpref)
+               minetest.set_node(pos, tr.single_conn[p_rails[1]])
+               local nname=tr.single_conn[p_rails[1]].name
+               if minetest.registered_nodes[nname] and minetest.registered_nodes[nname].after_place_node then
+                       minetest.registered_nodes[nname].after_place_node(pos, placer, itemstack, pointed_thing)
+               end
+       end
+end
+
+
+function tp.register_track_placer(nnprefix, imgprefix, dispname)
+       minetest.register_craftitem(nnprefix.."_placer",{
+               description = dispname,
+               inventory_image = imgprefix.."_placer.png",
+               wield_image = imgprefix.."_placer.png",
+               groups={},
+               on_place = function(itemstack, placer, pointed_thing)
+                       local name = placer:get_player_name()
+                       if not name then
+                          return itemstack
+                       end
+                       if pointed_thing.type=="node" then
+                               local pos=pointed_thing.above
+                               local upos=pointed_thing.under
+                               if minetest.is_protected(pos,name) and minetest.is_protected(upos,name) then
+                                  return itemstack
+                               end
+                               if minetest.registered_nodes[minetest.get_node(pos).name] and minetest.registered_nodes[minetest.get_node(pos).name].buildable_to
+                                       and minetest.registered_nodes[minetest.get_node(upos).name] and minetest.registered_nodes[minetest.get_node(upos).name].walkable then
+                                       tp.placetrack(pos, nnprefix, placer, itemstack, pointed_thing)
+                                       if not minetest.setting_getbool("creative_mode") then
+                                               itemstack:take_item()
+                                       end
+                               end
+                       end
+                       return itemstack
+               end,
+       })
+end
+
+
+
+minetest.register_craftitem("advtrains:trackworker",{
+       description = "Track Worker Tool\n\nLeft-click: change rail type (straight/curve/switch)\nRight-click: rotate rail/bumper/signal/etc.",
+       groups = {cracky=1}, -- key=name, value=rating; rating=1..3.
+       inventory_image = "advtrains_trackworker.png",
+       wield_image = "advtrains_trackworker.png",
+       stack_max = 1,
+       on_place = function(itemstack, placer, pointed_thing)
+               local name = placer:get_player_name()
+               if not name then
+                       return
+               end
+               if pointed_thing.type=="node" then
+                       local pos=pointed_thing.under
+                       if minetest.is_protected(pos, name) then
+                               return
+                       end
+                       local node=minetest.get_node(pos)
+
+                       --if not advtrains.is_track_and_drives_on(minetest.get_node(pos).name, advtrains.all_tracktypes) then return end
+                       if advtrains.is_train_at_pos(pos) then return end
+
+                       local nnprefix, suffix, rotation=string.match(node.name, "^(.+)_([^_]+)(_[^_]+)$")
+                       --print(node.name.."\npattern recognizes:"..nodeprefix.." / "..railtype.." / "..rotation)
+                       if not tp.tracks[nnprefix] or not tp.tracks[nnprefix].twrotate[suffix] then
+                               nnprefix, suffix=string.match(node.name, "^(.+)_([^_]+)$")
+                               rotation = ""
+                               if not tp.tracks[nnprefix] or not tp.tracks[nnprefix].twrotate[suffix] then
+                                       minetest.chat_send_player(placer:get_player_name(), "This node can't be rotated using the trackworker!")
+                                       return
+                               end
+                       end
+                       local modext=tp.tracks[nnprefix].twrotate[suffix]
+
+                       if rotation==modext[#modext] then --increase param2
+                               minetest.swap_node(pos, {name=nnprefix.."_"..suffix..modext[1], param2=(node.param2+1)%4})
+                               return
+                       else
+                               local modpos
+                               for k,v in pairs(modext) do if v==rotation then modpos=k end end
+                                       if not modpos then
+                                               minetest.chat_send_player(placer:get_player_name(), "This node can't be rotated using the trackworker!")
+                                       return
+                               end
+                               minetest.swap_node(pos, {name=nnprefix.."_"..suffix..modext[modpos+1], param2=node.param2})
+                       end
+                       advtrains.invalidate_all_paths()
+               end
+       end,
+       on_use=function(itemstack, user, pointed_thing)
+               local name = user:get_player_name()
+               if not name then
+                  return
+               end
+               if pointed_thing.type=="node" then
+                       local pos=pointed_thing.under
+                       local node=minetest.get_node(pos)
+                       if minetest.is_protected(pos, name) then
+                          return
+                       end
+                       
+                       --if not advtrains.is_track_and_drives_on(minetest.get_node(pos).name, advtrains.all_tracktypes) then return end
+                       if advtrains.is_train_at_pos(pos) then return end
+                       local nnprefix, suffix, rotation=string.match(node.name, "^(.+)_([^_]+)(_[^_]+)$")
+               --print(node.name.."\npattern recognizes:"..nodeprefix.." / "..railtype.." / "..rotation)
+                   if not tp.tracks[nnprefix] or not tp.tracks[nnprefix].twcycle[suffix] then
+                         nnprefix, suffix=string.match(node.name, "^(.+)_([^_]+)$")
+                         rotation = ""
+                         if not tp.tracks[nnprefix] or not tp.tracks[nnprefix].twcycle[suffix] then
+                           minetest.chat_send_player(user:get_player_name(), "This node can't be changed using the trackworker!")
+                           return
+                         end
+                   end
+                       local nextsuffix=tp.tracks[nnprefix].twcycle[suffix]
+                       minetest.swap_node(pos, {name=nnprefix.."_"..nextsuffix..rotation, param2=node.param2})
+                       --invalidate trains
+                       advtrains.invalidate_all_paths()
+               else
+                       print(name, dump(tp.tracks))
+               end
+       end,
+})
+
+--putting into right place
+advtrains.trackplacer=tp
diff --git a/advtrains/advtrains/tracks.lua b/advtrains/advtrains/tracks.lua
new file mode 100644 (file)
index 0000000..beb0bbc
--- /dev/null
@@ -0,0 +1,721 @@
+--advtrains by orwell96, see readme.txt\r
+\r
+--dev-time settings:\r
+--EDIT HERE\r
+--If the old non-model rails on straight tracks should be replaced by the new...\r
+--false: no\r
+--true: yes\r
+advtrains.register_replacement_lbms=false\r
+\r
+--[[TracksDefinition\r
+nodename_prefix\r
+texture_prefix\r
+description\r
+common={}\r
+straight={}\r
+straight45={}\r
+curve={}\r
+curve45={}\r
+lswitchst={}\r
+lswitchst45={}\r
+rswitchst={}\r
+rswitchst45={}\r
+lswitchcr={}\r
+lswitchcr45={}\r
+rswitchcr={}\r
+rswitchcr45={}\r
+vert1={\r
+       --you'll probably want to override mesh here\r
+}\r
+vert2={\r
+       --you'll probably want to override mesh here\r
+}\r
+]]--\r
+advtrains.all_tracktypes={}\r
+\r
+--definition preparation\r
+local function conns(c1, c2, r1, r2, rh, rots) return {conn1=c1, conn2=c2, rely1=r1, rely2=r2, railheight=rh} end\r
+\r
+local ap={}\r
+ap.t_30deg={\r
+       regstep=1,\r
+       variant={\r
+               st=conns(0,8),\r
+               cr=conns(0,7),\r
+               swlst=conns(0,8),\r
+               swlcr=conns(0,7),\r
+               swrst=conns(0,8),\r
+               swrcr=conns(0,9),\r
+               vst1=conns(8,0,0,0.5,0.25),\r
+               vst2=conns(8,0,0.5,1,0.75),\r
+               vst31=conns(8,0,0,0.33,0.16),\r
+               vst32=conns(8,0,0.33,0.66,0.5),\r
+               vst33=conns(8,0,0.66,1,0.83),\r
+       },\r
+       description={\r
+               st="straight",\r
+               cr="curve",\r
+               swlst="left switch (straight)",\r
+               swlcr="left switch (curve)",\r
+               swrst="right switch (straight)",\r
+               swrcr="right switch (curve)",\r
+               vst1="steep uphill 1/2",\r
+               vst2="steep uphill 2/2",\r
+               vst31="uphill 1/3",\r
+               vst32="uphill 2/3",\r
+               vst33="uphill 3/3",\r
+       },\r
+       switch={\r
+               swlst="swlcr",\r
+               swlcr="swlst",\r
+               swrst="swrcr",\r
+               swrcr="swrst",\r
+       },\r
+       switchmc={\r
+               swlst="on",\r
+               swlcr="off",\r
+               swrst="on",\r
+               swrcr="off",\r
+       },\r
+       regtp=true,\r
+       trackplacer={\r
+               st=true,\r
+               cr=true,\r
+       },\r
+       tpsingle={\r
+               st=true,\r
+       },\r
+       tpdefault="st",\r
+       trackworker={\r
+               ["swrcr"]="st",\r
+               ["swrst"]="st",\r
+               ["st"]="cr",\r
+               ["cr"]="swlst",\r
+               ["swlcr"]="swrcr",\r
+               ["swlst"]="swrst",\r
+       },\r
+       regsp=true,\r
+       slopenodes={\r
+               vst1=true, vst2=true,\r
+               vst31=true, vst32=true, vst33=true,\r
+       },\r
+       slopeplacer={\r
+               [2]={"vst1", "vst2"},\r
+               [3]={"vst31", "vst32", "vst33"},\r
+               max=3,--highest entry\r
+       },\r
+       slopeplacer_45={\r
+               [2]={"vst1_45", "vst2_45"},\r
+               max=2,\r
+       },\r
+       rotation={"", "_30", "_45", "_60"},\r
+       increativeinv={},\r
+}\r
+ap.t_30deg_straightonly={\r
+       regstep=1,\r
+       variant={\r
+               st=conns(0,8),\r
+       },\r
+       description={\r
+               st="straight",\r
+       },\r
+       switch={\r
+       },\r
+       switchmc={\r
+       },\r
+       regtp=true,\r
+       trackplacer={\r
+       },\r
+       tpsingle={\r
+       },\r
+       tpdefault="st",\r
+       trackworker={\r
+               ["st"]="st",\r
+       },\r
+       slopenodes={},\r
+       rotation={"", "_30", "_45", "_60"},\r
+       increativeinv={st},\r
+}\r
+ap.t_30deg_straightonly_noplacer={\r
+       regstep=1,\r
+       variant={\r
+               st=conns(0,8),\r
+       },\r
+       description={\r
+               st="straight",\r
+       },\r
+       switch={\r
+       },\r
+       switchmc={\r
+       },\r
+       regtp=false,\r
+       trackplacer={\r
+       },\r
+       tpsingle={\r
+       },\r
+       tpdefault="st",\r
+       trackworker={\r
+               ["st"]="st",\r
+       },\r
+       slopenodes={},\r
+       rotation={"", "_30", "_45", "_60"},\r
+       increativeinv={st},\r
+}\r
+ap.t_45deg={\r
+       regstep=2,\r
+       variant={\r
+               st=conns(0,8),\r
+               cr=conns(0,6),\r
+               swlst=conns(0,8),\r
+               swlcr=conns(0,6),\r
+               swrst=conns(0,8),\r
+               swrcr=conns(0,10),\r
+               vst1=conns(8,0,0,0.5,0.25),\r
+               vst2=conns(8,0,0.5,1,0.75),\r
+       },\r
+       description={\r
+               st="straight",\r
+               cr="curve",\r
+               swlst="left switch (straight)",\r
+               swlcr="left switch (curve)",\r
+               swrst="right switch (straight)",\r
+               swrcr="right switch (curve)",\r
+               vst1="vertical lower node",\r
+               vst2="vertical upper node",\r
+       },\r
+       switch={\r
+               swlst="swlcr",\r
+               swlcr="swlst",\r
+               swrst="swrcr",\r
+               swrcr="swrst",\r
+       },\r
+       switchmc={\r
+               swlst="on",\r
+               swlcr="off",\r
+               swrst="on",\r
+               swrcr="off",\r
+       },\r
+       regtp=true,\r
+       trackplacer={\r
+               st=true,\r
+               cr=true,\r
+       },\r
+       tpsingle={\r
+               st=true,\r
+       },\r
+       tpdefault="st",\r
+       trackworker={\r
+               ["swrcr"]="st",\r
+               ["swrst"]="st",\r
+               ["st"]="cr",\r
+               ["cr"]="swlst",\r
+               ["swlcr"]="swrcr",\r
+               ["swlst"]="swrst",\r
+       },\r
+       slopenodes={},\r
+       rotation={"", "_45"},\r
+       increativeinv={vst1=true, vst2=true}\r
+}\r
+advtrains.trackpresets = ap\r
+\r
+--definition format: ([] optional)\r
+--[[{\r
+       nodename_prefix\r
+       texture_prefix\r
+       [shared_texture]\r
+       models_prefix\r
+       models_suffix (with dot)\r
+       [shared_model]\r
+       formats={\r
+               st,cr,swlst,swlcr,swrst,swrcr,vst1,vst2\r
+               (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)\r
+       }\r
+       common={} change something on common rail appearance\r
+}]]\r
+function advtrains.register_tracks(tracktype, def, preset)\r
+       local function make_switchfunc(suffix_target, mesecon_state)\r
+               local switchfunc=function(pos, node)\r
+                       if advtrains.is_train_at_pos(pos) then return end\r
+                       minetest.set_node(pos, {name=def.nodename_prefix.."_"..suffix_target, param2=node.param2})\r
+                       advtrains.invalidate_all_paths()\r
+                       advtrains.reset_trackdb_position(pos)\r
+               end\r
+               return switchfunc, {effector = {\r
+                       ["action_"..mesecon_state] = switchfunc,\r
+                       rules=advtrains.meseconrules\r
+               }}\r
+       end\r
+       local function make_overdef(suffix, rotation, conns, switchfunc, mesecontbl, in_creative_inv, drop_slope)\r
+               local img_suffix=suffix..rotation\r
+               return {\r
+                       mesh = def.shared_model or (def.models_prefix.."_"..img_suffix..def.models_suffix),\r
+                       tiles = {def.shared_texture or (def.texture_prefix.."_"..img_suffix..".png")},\r
+                       --inventory_image = def.texture_prefix.."_"..img_suffix..".png",\r
+                       --wield_image = def.texture_prefix.."_"..img_suffix..".png",\r
+                       description=def.description.."("..preset.description[suffix]..rotation..")",\r
+                       connect1=conns.conn1,\r
+                       connect2=conns.conn2,\r
+                       rely1=conns.rely1 or 0,\r
+                       rely2=conns.rely2 or 0,\r
+                       railheight=conns.railheight or 0,\r
+                       on_rightclick=switchfunc,\r
+                       groups = {\r
+                               attached_node=1,\r
+                               ["advtrains_track_"..tracktype]=1,\r
+                               dig_immediate=2,\r
+                               not_in_creative_inventory=(not in_creative_inv and 1 or nil),\r
+                               not_blocking_trains=1,\r
+                       },\r
+                       mesecons=mesecontbl,\r
+                       drop = increativeinv and def.nodename_prefix.."_"..suffix..rotation or (drop_slope and def.nodename_prefix.."_slopeplacer" or def.nodename_prefix.."_placer"),\r
+                       }\r
+       end\r
+       local function cycle_conns(conns, rotid)\r
+               local add=(rotid-1)*preset.regstep\r
+               return {\r
+                       conn1=(conns.conn1+add)%16,\r
+                       conn2=(conns.conn2+add)%16,\r
+                       rely1=conns.rely1 or 0,\r
+                       rely2=conns.rely2 or 0,\r
+                       railheight=conns.railheight or 0,\r
+               }\r
+       end\r
+       local common_def=advtrains.merge_tables({\r
+               description = def.description,\r
+               drawtype = "mesh",\r
+               paramtype="light",\r
+               paramtype2="facedir",\r
+               walkable = false,\r
+               selection_box = {\r
+                       type = "fixed",\r
+                       fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},\r
+               },\r
+               rely1=0,\r
+               rely2=0,\r
+               railheight=0,\r
+               drop=def.nodename_prefix.."_placer",\r
+               can_dig=function(pos)\r
+                       return not advtrains.is_train_at_pos(pos)\r
+               end,\r
+               after_dig_node=function(pos)\r
+                       advtrains.invalidate_all_paths()\r
+                       advtrains.reset_trackdb_position(pos)\r
+               end,\r
+               after_place_node=function(pos)\r
+                       advtrains.reset_trackdb_position(pos)\r
+               end,\r
+               on_place_rail=function(pos)\r
+                       advtrains.reset_trackdb_position(pos)\r
+               end,\r
+       }, def.common or {})\r
+       --make trackplacer base def\r
+       advtrains.trackplacer.register_tracktype(def.nodename_prefix, preset.tpdefault)\r
+       if preset.regtp then\r
+               advtrains.trackplacer.register_track_placer(def.nodename_prefix, def.texture_prefix, def.description)                   \r
+       end\r
+       if preset.regsp then\r
+               advtrains.slope.register_placer(def, preset)                    \r
+       end\r
+       for suffix, conns in pairs(preset.variant) do\r
+               for rotid, rotation in ipairs(preset.rotation) do\r
+                       if not def.formats[suffix] or def.formats[suffix][rotid] then\r
+                               local switchfunc, mesecontbl\r
+                               if preset.switch[suffix] then\r
+                                       switchfunc, mesecontbl=make_switchfunc(preset.switch[suffix]..rotation, preset.switchmc[suffix])\r
+                               end\r
+                               local adef={}\r
+                               if def.get_additional_definiton then\r
+                                       adef=def.get_additional_definiton(def, preset, suffix, rotation)\r
+                               end\r
+\r
+                               minetest.register_node(def.nodename_prefix.."_"..suffix..rotation, advtrains.merge_tables(\r
+                                       common_def, \r
+                                       make_overdef(\r
+                                               suffix, rotation,\r
+                                               cycle_conns(conns, rotid),\r
+                                               switchfunc, mesecontbl, preset.increativeinv[suffix], preset.slopenodes[suffix]\r
+                                               ),\r
+                                       adef\r
+                                       )\r
+                               )\r
+                               --trackplacer\r
+                               if preset.regtp then\r
+                                       if preset.trackplacer[suffix] then\r
+                                               advtrains.trackplacer.add_double_conn(def.nodename_prefix, suffix, rotation, cycle_conns(conns, rotid))\r
+                                       end\r
+                                       if preset.tpsingle[suffix] then\r
+                                               advtrains.trackplacer.add_single_conn(def.nodename_prefix, suffix, rotation, cycle_conns(conns, rotid))\r
+                                       end\r
+                               end\r
+                               advtrains.trackplacer.add_worked(def.nodename_prefix, suffix, rotation, preset.trackworker[suffix])\r
+                       end\r
+               end\r
+       end\r
+       advtrains.all_tracktypes[tracktype]=true\r
+end\r
+\r
+\r
+function advtrains.is_track_and_drives_on(nodename, drives_on_p)\r
+       if not minetest.registered_nodes[nodename] then\r
+               return false\r
+       end\r
+       local nodedef=minetest.registered_nodes[nodename]\r
+       for k,v in pairs(drives_on_p) do\r
+               if nodedef.groups["advtrains_track_"..k] then\r
+                       return true\r
+               end\r
+       end\r
+       return false\r
+end\r
+\r
+function advtrains.get_track_connections(name, param2)\r
+       local nodedef=minetest.registered_nodes[name]\r
+       if not nodedef then print("[advtrains] get_track_connections couldn't find nodedef for nodename "..(name or "nil")) return 0, 8, 0, 0, 0 end\r
+       local noderot=param2\r
+       if not param2 then noderot=0 end\r
+       if noderot > 3 then print("[advtrains] get_track_connections: rail has invaild param2 of "..noderot) noderot=0 end\r
+       \r
+       return (nodedef.connect1 + 4 * noderot)%16, (nodedef.connect2  + 4 * noderot)%16, nodedef.rely1 or 0, nodedef.rely2 or 0, nodedef.railheight or 0\r
+end\r
+\r
+--detector code\r
+--holds a table with nodes on which trains are on.\r
+\r
+advtrains.detector = {}\r
+advtrains.detector.on_node = {}\r
+advtrains.detector.on_node_restore = {}\r
+--set if paths were invalidated before. tells trainlogic.lua to call advtrains.detector.finalize_restore()\r
+advtrains.detector.clean_step_before = false\r
+\r
+--when train enters a node, call this\r
+--The entry already being contained in advtrains.detector.on_node_restore will not trigger an on_train_enter event on the node.  (when path is reset, this is saved).\r
+function advtrains.detector.enter_node(pos, train_id)\r
+       local pts = minetest.pos_to_string(advtrains.round_vector_floor_y(pos))\r
+       --print("enterNode "..pts.." "..sid(train_id))\r
+       if advtrains.detector.on_node[pts] then\r
+               if advtrains.trains[advtrains.detector.on_node[pts]] then\r
+                       --print(""..pts.." already occupied")\r
+                       return false\r
+               else\r
+                       advtrains.detector.leave_node(pos, advtrains.detector.on_node[pts])\r
+               end\r
+       end\r
+       advtrains.detector.on_node[pts]=train_id\r
+       if advtrains.detector.on_node_restore[pts] then\r
+               advtrains.detector.on_node_restore[pts]=nil\r
+       else\r
+               advtrains.detector.call_enter_callback(advtrains.round_vector_floor_y(pos), train_id)\r
+       end\r
+       return true\r
+end\r
+function advtrains.detector.leave_node(pos, train_id)\r
+       local pts = minetest.pos_to_string(advtrains.round_vector_floor_y(pos))\r
+       --print("leaveNode "..pts.." "..sid(train_id))\r
+       if not advtrains.detector.on_node[pts] then\r
+               --print(""..pts.." leave: nothing here")\r
+               return false\r
+       end\r
+       if advtrains.detector.on_node[pts]==train_id then\r
+               advtrains.detector.call_leave_callback(advtrains.round_vector_floor_y(pos), train_id)\r
+               advtrains.detector.on_node[pts]=nil\r
+       else\r
+               if advtrains.trains[advtrains.detector.on_node[pts]] then\r
+                       --print(""..pts.." occupied by another train")\r
+                       return false\r
+               else\r
+                       advtrains.detector.leave_node(pos, advtrains.detector.on_node[pts])\r
+                       return false\r
+               end\r
+       end\r
+       return true\r
+end\r
+--called immediately before invalidating paths\r
+function advtrains.detector.setup_restore()\r
+       --print("setup_restore")\r
+       advtrains.detector.on_node_restore = advtrains.detector.on_node\r
+       advtrains.detector.on_node = {}\r
+end\r
+--called one step after invalidating paths, when all trains have restored their path and called enter_node for their contents.\r
+function advtrains.detector.finalize_restore()\r
+       --print("finalize_restore")\r
+       for pts, train_id in pairs(advtrains.detector.on_node_restore) do\r
+               --print("called leave callback "..pts.." "..train_id)\r
+               advtrains.detector.call_leave_callback(minetest.string_to_pos(pts), train_id)\r
+       end\r
+       advtrains.detector.on_node_restore = {}\r
+end\r
+function advtrains.detector.call_enter_callback(pos, train_id)\r
+       --print("instructed to call enter calback")\r
+\r
+       local node = minetest.get_node(pos) --this spares the check if node is nil, it has a name in any case\r
+       local mregnode=minetest.registered_nodes[node.name]\r
+       if mregnode and mregnode.advtrains and mregnode.advtrains.on_train_enter then\r
+               mregnode.advtrains.on_train_enter(pos, train_id)\r
+       end\r
+       \r
+       --atc code wants to be notified too\r
+       advtrains.atc.trigger_controller_train_enter(pos, train_id)\r
+end\r
+function advtrains.detector.call_leave_callback(pos, train_id)\r
+       --print("instructed to call leave calback")\r
+\r
+       local node = minetest.get_node(pos) --this spares the check if node is nil, it has a name in any case\r
+       local mregnode=minetest.registered_nodes[node.name]\r
+       if mregnode and mregnode.advtrains and mregnode.advtrains.on_train_leave then\r
+               mregnode.advtrains.on_train_leave(pos, train_id)\r
+       end \r
+end\r
+\r
+-- slope placer. Defined in register_tracks.\r
+--crafted with rail and gravel\r
+local sl={}\r
+function sl.register_placer(def, preset)\r
+       minetest.register_craftitem(def.nodename_prefix.."_slopeplacer",{\r
+               description = def.description.." Slope",\r
+               inventory_image = def.texture_prefix.."_slopeplacer.png",\r
+               wield_image = def.texture_prefix.."_slopeplacer.png",\r
+               groups={},\r
+               on_place = sl.create_slopeplacer_on_place(def, preset)\r
+       })\r
+end\r
+--(itemstack, placer, pointed_thing)\r
+function sl.create_slopeplacer_on_place(def, preset)\r
+       return function(istack, player, pt)\r
+               if not pt.type=="node" then \r
+                       minetest.chat_send_player(player:get_player_name(), "Can't place: not pointing at node")\r
+                       return istack \r
+               end\r
+               local pos=pt.above\r
+               if not pos then \r
+                       minetest.chat_send_player(player:get_player_name(), "Can't place: not pointing at node")\r
+                       return istack\r
+               end\r
+               local node=minetest.get_node(pos)\r
+               if not minetest.registered_nodes[node.name] or not minetest.registered_nodes[node.name].buildable_to then\r
+                       minetest.chat_send_player(player:get_player_name(), "Can't place: space occupied!")\r
+                       return istack\r
+               end\r
+               if minetest.is_protected(pos, player:get_player_name()) then \r
+                       minetest.chat_send_player(player:get_player_name(), "Can't place: protected position!")\r
+                       return istack\r
+               end\r
+               --determine player orientation (only horizontal component)\r
+               --get_look_horizontal may not be available\r
+               local yaw=player.get_look_horizontal and player:get_look_horizontal() or (player:get_look_yaw() - math.pi/2)\r
+               \r
+               --rounding unit vectors is a nice way for selecting 1 of 8 directions since sin(30°) is 0.5.\r
+               dirvec={x=math.floor(math.sin(-yaw)+0.5), y=0, z=math.floor(math.cos(-yaw)+0.5)}\r
+               --translate to direction to look up inside the preset table\r
+               local param2, rot45=({\r
+                       [-1]={\r
+                               [-1]=2,\r
+                               [0]=3,\r
+                               [1]=3,\r
+                               },\r
+                       [0]={\r
+                               [-1]=2,\r
+                               [1]=0,\r
+                               },\r
+                       [1]={\r
+                               [-1]=1,\r
+                               [0]=1,\r
+                               [1]=0,\r
+                               },\r
+               })[dirvec.x][dirvec.z], dirvec.x~=0 and dirvec.z~=0\r
+               local lookup=preset.slopeplacer\r
+               if rot45 then lookup=preset.slopeplacer_45 end\r
+               \r
+               --go unitvector forward and look how far the next node is\r
+               local step=1\r
+               while step<=lookup.max do\r
+                       local node=minetest.get_node(vector.add(pos, dirvec))\r
+                       --next node solid?\r
+                       if not minetest.registered_nodes[node.name] or not minetest.registered_nodes[node.name].buildable_to or minetest.is_protected(pos, player:get_player_name()) then \r
+                               --do slopes of this distance exist?\r
+                               if lookup[step] then\r
+                                       if minetest.setting_getbool("creative_mode") or istack:get_count()>=step then\r
+                                               --start placing\r
+                                               local placenodes=lookup[step]\r
+                                               while step>0 do\r
+                                                       minetest.set_node(pos, {name=def.nodename_prefix.."_"..placenodes[step], param2=param2})\r
+                                                       if not minetest.setting_getbool("creative_mode") then\r
+                                                               istack:take_item()\r
+                                                       end\r
+                                                       step=step-1\r
+                                                       pos=vector.subtract(pos, dirvec)\r
+                                               end\r
+                                       else\r
+                                               minetest.chat_send_player(player:get_player_name(), "Can't place: Not enough slope items left ("..step.." required)")\r
+                                       end\r
+                               else\r
+                                       minetest.chat_send_player(player:get_player_name(), "Can't place: There's no slope of length "..step)\r
+                               end\r
+                               return istack\r
+                       end\r
+                       step=step+1\r
+                       pos=vector.add(pos, dirvec)\r
+               end\r
+               minetest.chat_send_player(player:get_player_name(), "Can't place: no supporting node at upper end.")\r
+               return itemstack\r
+       end\r
+end\r
+\r
+advtrains.slope=sl\r
+\r
+--END code, BEGIN definition\r
+--definition format: ([] optional)\r
+--[[{\r
+       nodename_prefix\r
+       texture_prefix\r
+       [shared_texture]\r
+       models_prefix\r
+       models_suffix (with dot)\r
+       [shared_model]\r
+       formats={\r
+               st,cr,swlst,swlcr,swrst,swrcr,vst1,vst2\r
+               (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)\r
+       }\r
+       common={} change something on common rail appearance\r
+}]]\r
+\r
+advtrains.register_tracks("regular", {\r
+       nodename_prefix="advtrains:track",\r
+       texture_prefix="advtrains_track",\r
+       shared_model="trackplane.b3d",\r
+       description="Deprecated Track",\r
+       formats={vst1={}, vst2={}},\r
+}, ap.t_45deg)\r
+\r
+\r
+advtrains.register_tracks("default", {\r
+       nodename_prefix="advtrains:dtrack",\r
+       texture_prefix="advtrains_dtrack",\r
+       models_prefix="advtrains_dtrack",\r
+       models_suffix=".b3d",\r
+       shared_texture="advtrains_dtrack_rail.png",\r
+       description="Track",\r
+       formats={vst1={true, false, true}, vst2={true, false, true}, vst31={true}, vst32={true}, vst33={true}},\r
+}, ap.t_30deg)\r
+\r
+--bumpers\r
+advtrains.register_tracks("default", {\r
+       nodename_prefix="advtrains:dtrack_bumper",\r
+       texture_prefix="advtrains_dtrack_bumper",\r
+       models_prefix="advtrains_dtrack_bumper",\r
+       models_suffix=".b3d",\r
+       shared_texture="advtrains_dtrack_rail.png",\r
+       description="Bumper",\r
+       formats={},\r
+}, ap.t_30deg_straightonly)\r
+--legacy bumpers\r
+for _,rot in ipairs({"", "_30", "_45", "_60"}) do\r
+       minetest.register_alias("advtrains:dtrack_bumper"..rot, "advtrains:dtrack_bumper_st"..rot)\r
+end\r
+\r
+if mesecon then\r
+       advtrains.register_tracks("default", {\r
+               nodename_prefix="advtrains:dtrack_detector_off",\r
+               texture_prefix="advtrains_dtrack_detector",\r
+               models_prefix="advtrains_dtrack_detector",\r
+               models_suffix=".b3d",\r
+               shared_texture="advtrains_dtrack_rail.png",\r
+               description="Detector Rail",\r
+               formats={},\r
+               get_additional_definiton = function(def, preset, suffix, rotation)\r
+                       return {\r
+                               mesecons = {\r
+                                       receptor = {\r
+                                               state = mesecon.state.off,\r
+                                               rules = advtrains.meseconrules\r
+                                       }\r
+                               },\r
+                               advtrains = {\r
+                                       on_train_enter=function(pos, train_id)\r
+                                               minetest.swap_node(pos, {name="advtrains:dtrack_detector_on".."_"..suffix..rotation, param2=minetest.get_node(pos).param2})\r
+                                               mesecon.receptor_on(pos, advtrains.meseconrules)\r
+                                       end\r
+                               }\r
+                       }\r
+               end\r
+       }, ap.t_30deg_straightonly)\r
+       advtrains.register_tracks("default", {\r
+               nodename_prefix="advtrains:dtrack_detector_on",\r
+               texture_prefix="advtrains_dtrack_detector",\r
+               models_prefix="advtrains_dtrack_detector",\r
+               models_suffix=".b3d",\r
+               shared_texture="advtrains_dtrack_rail_detector_on.png",\r
+               description="Detector(on)(you hacker you)",\r
+               formats={},\r
+               get_additional_definiton = function(def, preset, suffix, rotation)\r
+                       return {\r
+                               mesecons = {\r
+                                       receptor = {\r
+                                               state = mesecon.state.on,\r
+                                               rules = advtrains.meseconrules\r
+                                       }\r
+                               },\r
+                               advtrains = {\r
+                                       on_train_leave=function(pos, train_id)\r
+                                               minetest.swap_node(pos, {name="advtrains:dtrack_detector_off".."_"..suffix..rotation, param2=minetest.get_node(pos).param2})\r
+                                               mesecon.receptor_off(pos, advtrains.meseconrules)\r
+                                       end\r
+                               }\r
+                       }\r
+               end\r
+       }, ap.t_30deg_straightonly_noplacer)\r
+end\r
+--TODO legacy\r
+--I know lbms are better for this purpose\r
+for name,rep in pairs({swl_st="swlst", swr_st="swrst", swl_cr="swlcr", swr_cr="swrcr", }) do\r
+       minetest.register_abm({\r
+    --  In the following two fields, also group:groupname will work.\r
+        nodenames = {"advtrains:track_"..name},\r
+       interval = 1.0, -- Operation interval in seconds\r
+       chance = 1, -- Chance of trigger per-node per-interval is 1.0 / this\r
+       action = function(pos, node, active_object_count, active_object_count_wider) minetest.set_node(pos, {name="advtrains:track_"..rep, param2=node.param2}) end,\r
+    })\r
+    minetest.register_abm({\r
+    --  In the following two fields, also group:groupname will work.\r
+        nodenames = {"advtrains:track_"..name.."_45"},\r
+       interval = 1.0, -- Operation interval in seconds\r
+       chance = 1, -- Chance of trigger per-node per-interval is 1.0 / this\r
+       action = function(pos, node, active_object_count, active_object_count_wider) minetest.set_node(pos, {name="advtrains:track_"..rep.."_45", param2=node.param2}) end,\r
+    })\r
+end\r
+\r
+if advtrains.register_replacement_lbms then\r
+minetest.register_lbm({\r
+       name = "advtrains:ramp_replacement_1",\r
+--  In the following two fields, also group:groupname will work.\r
+       nodenames = {"advtrains:track_vert1"},\r
+       action = function(pos, node, active_object_count, active_object_count_wider) minetest.set_node(pos, {name="advtrains:dtrack_vst1", param2=(node.param2+2)%4}) end,\r
+})\r
+minetest.register_lbm({\r
+       name = "advtrains:ramp_replacement_1",\r
+--  --  In the following two fields, also group:groupname will work.\r
+       nodenames = {"advtrains:track_vert2"},\r
+       action = function(pos, node, active_object_count, active_object_count_wider) minetest.set_node(pos, {name="advtrains:dtrack_vst2", param2=(node.param2+2)%4}) end,\r
+})\r
+       minetest.register_abm({\r
+               name = "advtrains:st_rep_1",\r
+       --  In the following two fields, also group:groupname will work.\r
+               nodenames = {"advtrains:track_st"},\r
+               interval=1,\r
+               chance=1,\r
+               action = function(pos, node, active_object_count, active_object_count_wider) minetest.set_node(pos, {name="advtrains:dtrack_st", param2=node.param2}) end,\r
+       })\r
+       minetest.register_lbm({\r
+               name = "advtrains:st_rep_1",\r
+       --  --  In the following two fields, also group:groupname will work.\r
+               nodenames = {"advtrains:track_st_45"},\r
+               action = function(pos, node, active_object_count, active_object_count_wider) minetest.set_node(pos, {name="advtrains:dtrack_st_45", param2=node.param2}) end,\r
+       })\r
+end\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
diff --git a/advtrains/advtrains/trainhud.lua b/advtrains/advtrains/trainhud.lua
new file mode 100644 (file)
index 0000000..e69f04a
--- /dev/null
@@ -0,0 +1,109 @@
+--trainhud.lua: holds all the code for train controlling
+
+advtrains.hud = {}
+
+minetest.register_on_leaveplayer(function(player)
+advtrains.hud[player:get_player_name()] = nil
+end)
+
+local mletter={[1]="F", [-1]="R", [0]="N"}
+
+function advtrains.on_control_change(pc, train, flip)
+       if pc.sneak then
+               if pc.up then
+                       train.tarvelocity = train.max_speed or 10
+               end
+               if pc.down then
+                       train.tarvelocity = 0
+               end
+               if pc.left then
+                       train.tarvelocity = 4
+               end
+               if pc.right then
+                       train.tarvelocity = 8
+               end
+               if pc.jump then
+                       train.brake = true
+                       --0: released, 1: brake and pressed, 2: released and brake, 3: pressed and brake
+                       if not train.brake_hold_state or train.brake_hold_state==0 then
+                               train.brake_hold_state = 1
+                       elseif train.brake_hold_state==2 then
+                               train.brake_hold_state = 3
+                       end
+               elseif train.brake_hold_state==1 then
+                       train.brake_hold_state = 2
+               elseif train.brake_hold_state==3 then
+                       train.brake = false
+                       train.brake_hold_state = 0
+               end
+               --shift+use:see wagons.lua
+       else
+               if pc.up then
+                       train.tarvelocity = train.tarvelocity + 1
+               end
+               if pc.down then
+                       if train.velocity>0 then
+                               train.tarvelocity = math.max(train.tarvelocity - 1, 0)
+                       else
+                               train.movedir = -train.movedir
+                       end
+               end
+               if train.brake_hold_state~=2 then
+                       train.brake = false
+               end
+               if pc.jump then
+                       train.brake = true
+               end
+               if pc.aux1 then
+                       --horn
+               end
+       end
+end
+function advtrains.update_driver_hud(pname, train, flip)
+       advtrains.set_trainhud(pname, advtrains.hud_train_format(train, flip))
+end
+function advtrains.clear_driver_hud(pname)
+       advtrains.set_trainhud(pname, "")
+end
+
+function advtrains.set_trainhud(name, text)
+       local hud = advtrains.hud[name]
+       local player=minetest.get_player_by_name(name)
+       if not player then
+          return
+       end
+       if not hud then
+               hud = {}
+               advtrains.hud[name] = hud
+               hud.id = player:hud_add({
+                       hud_elem_type = "text",
+                       name = "ADVTRAINS",
+                       number = 0xFFFFFF,
+                       position = {x=0.5, y=0.7},
+                       offset = {x=0, y=0},
+                       text = text,
+                       scale = {x=200, y=60},
+                       alignment = {x=0, y=0},
+               })
+               hud.oldText=text
+               return
+       elseif hud.oldText ~= text then
+               player:hud_change(hud.id, "text", text)
+               hud.oldText=text
+       end
+end
+function advtrains.hud_train_format(train, flip)
+       local fct=flip and -1 or 1
+       if not train then return "" end
+       
+       local max=train.max_speed or 10
+       local vel=advtrains.abs_ceil(train.velocity)
+       local tvel=advtrains.abs_ceil(train.tarvelocity)
+       local topLine, firstLine, secondLine
+       
+       topLine="Train".."  ["..mletter[fct*train.movedir].."]  "..(train.brake and "="..( train.brake_hold_state==2 and "^" or "" ).."B=" or "")
+       firstLine="Speed: |"..string.rep("+", vel)..string.rep("_", max-vel)..">"
+       secondLine="Target: |"..string.rep("+", tvel)..string.rep("_", max-tvel)..">"
+       
+       return topLine.."\n"..firstLine.."\n"..secondLine
+end
diff --git a/advtrains/advtrains/trainlogic.lua b/advtrains/advtrains/trainlogic.lua
new file mode 100644 (file)
index 0000000..eb45500
--- /dev/null
@@ -0,0 +1,875 @@
+--trainlogic.lua
+--controls train entities stuff about connecting/disconnecting/colliding trains and other things
+
+
+local benchmark=false
+local bm={}
+local bmlt=0
+local bmsteps=0
+local bmstepint=200
+printbm=function(action, ta)
+       if not benchmark then return end
+       local t=(os.clock()-ta)*1000
+       if not bm[action] then
+               bm[action]=t
+       else
+               bm[action]=bm[action]+t
+       end
+       bmlt=bmlt+t
+end
+function endstep()
+       if not benchmark then return end
+       bmsteps=bmsteps-1
+       if bmsteps<=0 then
+               bmsteps=bmstepint
+               for key, value in pairs(bm) do
+                       minetest.chat_send_all(key.." "..(value/bmstepint).." ms avg.")
+               end
+               minetest.chat_send_all("Total time consumed by all advtrains actions per step: "..(bmlt/bmstepint).." ms avg.")
+               bm={}
+               bmlt=0
+       end
+end
+
+advtrains.train_accel_force=2--per second and divided by number of wagons
+advtrains.train_brake_force=3--per second, not divided by number of wagons
+advtrains.train_roll_force=0.5--per second, not divided by number of wagons, acceleration when rolling without brake
+advtrains.train_emerg_force=10--for emergency brakes(when going off track)
+
+advtrains.audit_interval=30
+
+
+advtrains.trains={}
+advtrains.wagon_save={}
+
+--load initially
+advtrains.fpath=minetest.get_worldpath().."/advtrains"
+local file, err = io.open(advtrains.fpath, "r")
+if not file then
+       local er=err or "Unknown Error"
+       print("[advtrains]Failed loading advtrains save file "..er)
+else
+       local tbl = minetest.deserialize(file:read("*a"))
+       if type(tbl) == "table" then
+               advtrains.trains=tbl
+       end
+       file:close()
+end
+advtrains.fpath_ws=minetest.get_worldpath().."/advtrains_wagon_save"
+local file, err = io.open(advtrains.fpath_ws, "r")
+if not file then
+       local er=err or "Unknown Error"
+       print("[advtrains]Failed loading advtrains save file "..er)
+else
+       local tbl = minetest.deserialize(file:read("*a"))
+       if type(tbl) == "table" then
+               advtrains.wagon_save=tbl
+       end
+       file:close()
+end
+
+
+advtrains.save = function()
+       --print("[advtrains]saving")
+       advtrains.invalidate_all_paths()
+       local datastr = minetest.serialize(advtrains.trains)
+       if not datastr then
+               minetest.log("error", "[advtrains] Failed to serialize train data!")
+               return
+       end
+       local file, err = io.open(advtrains.fpath, "w")
+       if err then
+               return err
+       end
+       file:write(datastr)
+       file:close()
+       
+       -- update wagon saves
+       for _,wagon in pairs(minetest.luaentities) do
+               if wagon.is_wagon and wagon.initialized then
+                       wagon:get_staticdata()
+               end
+       end
+       --cross out userdata
+       for w_id, data in pairs(advtrains.wagon_save) do
+               data.name=nil
+               data.object=nil
+               if data.driver then
+                       data.driver_name=data.driver:get_player_name()
+                       data.driver=nil
+               else
+                       data.driver_name=nil
+               end
+               if data.discouple then
+                       data.discouple.object:remove()
+                       data.discouple=nil
+               end
+       end
+       --print(dump(advtrains.wagon_save))
+       datastr = minetest.serialize(advtrains.wagon_save)
+       if not datastr then
+               minetest.log("error", "[advtrains] Failed to serialize train data!")
+               return
+       end
+       file, err = io.open(advtrains.fpath_ws, "w")
+       if err then
+               return err
+       end
+       file:write(datastr)
+       file:close()
+       
+       advtrains.save_trackdb()
+       advtrains.atc.save()
+end
+minetest.register_on_shutdown(advtrains.save)
+
+advtrains.save_and_audit_timer=advtrains.audit_interval
+minetest.register_globalstep(function(dtime)
+       advtrains.save_and_audit_timer=advtrains.save_and_audit_timer-dtime
+       if advtrains.save_and_audit_timer<=0 then
+               local t=os.clock()
+               
+               --save
+               advtrains.save()
+               advtrains.save_and_audit_timer=advtrains.audit_interval
+               printbm("saving", t)
+       end
+       --regular train step
+       local t=os.clock()
+       for k,v in pairs(advtrains.trains) do
+               advtrains.train_step(k, v, dtime)
+       end
+       
+       --see tracks.lua
+       if advtrains.detector.clean_step_before then
+               advtrains.detector.finalize_restore()
+       end
+       
+       printbm("trainsteps", t)
+       endstep()
+end)
+
+function advtrains.train_step(id, train, dtime)
+       --Legacy: set drives_on and max_speed
+       if not train.drives_on or not train.max_speed then
+               advtrains.update_trainpart_properties(id)
+       end
+       --TODO check for all vars to be present
+       if not train.velocity then
+               train.velocity=0
+       end
+       if not train.movedir or (train.movedir~=1 and train.movedir~=-1) then
+               train.movedir=1
+       end
+       --very unimportant thing: check if couple is here
+       if train.couple_eid_front and (not minetest.luaentities[train.couple_eid_front] or not minetest.luaentities[train.couple_eid_front].is_couple) then train.couple_eid_front=nil end
+       if train.couple_eid_back and (not minetest.luaentities[train.couple_eid_back] or not minetest.luaentities[train.couple_eid_back].is_couple) then train.couple_eid_back=nil end
+       
+       --skip certain things (esp. collision) when not moving
+       local train_moves=(train.velocity~=0)
+       
+       --if not train.last_pos then advtrains.trains[id]=nil return end
+       
+       if not advtrains.pathpredict(id, train) then 
+               print("pathpredict failed(returned false)")
+               train.velocity=0
+               train.tarvelocity=0
+               return
+       end
+       
+       local path=advtrains.get_or_create_path(id, train)
+       if not path then
+               train.velocity=0
+               train.tarvelocity=0
+               print("train has no path for whatever reason")
+               return 
+       end
+       
+       local train_end_index=advtrains.get_train_end_index(train)
+       --apply off-track handling:
+       local front_off_track=train.max_index_on_track and train.index>train.max_index_on_track
+       local back_off_track=train.min_index_on_track and train_end_index<train.min_index_on_track
+       if front_off_track and back_off_track then--allow movement in both directions
+               if train.tarvelocity>1 then train.tarvelocity=1 end
+       elseif front_off_track then--allow movement only backward
+               if train.movedir==1 and train.tarvelocity>0 then train.tarvelocity=0 end
+               if train.movedir==-1 and train.tarvelocity>1 then train.tarvelocity=1 end
+       elseif back_off_track then--allow movement only forward
+               if train.movedir==-1 and train.tarvelocity>0 then train.tarvelocity=0 end
+               if train.movedir==1 and train.tarvelocity>1 then train.tarvelocity=1 end
+       end
+       
+       --update advtrains.detector
+       if not train.detector_old_index then
+               train.detector_old_index = math.floor(train_end_index)
+               train.detector_old_end_index = math.floor(train_end_index)
+       end
+       local ifo, ifn, ibo, ibn = train.detector_old_index, math.floor(train.index), train.detector_old_end_index, math.floor(train_end_index)
+       if ifn>ifo then
+               for i=ifo, ifn do
+                       if path[i] then
+                               advtrains.detector.enter_node(path[i], id)
+                       end
+               end
+       elseif ifn<ifo then
+               for i=ifn, ifo do
+                       if path[i] then
+                               advtrains.detector.leave_node(path[i], id)
+                       end
+               end
+       end
+       if ibn<ibo then
+               for i=ibn, ibn do
+                       if path[i] then
+                               advtrains.detector.enter_node(path[i], id)
+                       end
+               end
+       elseif ibn>ibo then
+               for i=ibo, ibn do
+                       if path[i] then
+                               advtrains.detector.leave_node(path[i], id)
+                       end
+               end
+       end
+       train.detector_old_index = math.floor(train.index)
+       train.detector_old_end_index = math.floor(train_end_index)
+       
+       --remove?
+       if #train.trainparts==0 then
+               print("[advtrains][train "..sid(id).."] has empty trainparts, removing.")
+               advtrains.detector.leave_node(path[train.detector_old_index], id)
+               advtrains.trains[id]=nil
+               return
+       end
+       
+       if train_moves then
+               --check for collisions by finding objects
+               
+               --heh, new collision again.
+               --this time, based on NODES and the advtrains.detector.on_node table.
+               local collpos
+               local coll_grace=1
+               if train.movedir==1 then
+                       collpos=advtrains.get_real_index_position(path, train.index-coll_grace)
+               else
+                       collpos=advtrains.get_real_index_position(path, train_end_index+coll_grace)
+               end
+               if collpos then
+                       local rcollpos=advtrains.round_vector_floor_y(collpos)
+                       for x=-1,1 do
+                               for z=-1,1 do
+                                       local testpos=vector.add(rcollpos, {x=x, y=0, z=z})
+                                       local testpts=minetest.pos_to_string(testpos)
+                                       if advtrains.detector.on_node[testpts] and advtrains.detector.on_node[testpts]~=id then
+                                               --collides
+                                               advtrains.spawn_couple_on_collide(id, testpos, advtrains.detector.on_node[testpts], train.movedir==-1)
+                                               
+                                               train.recently_collided_with_env=true
+                                               train.velocity=0.5*train.velocity
+                                               train.movedir=train.movedir*-1
+                                               train.tarvelocity=0
+                                               
+                                       end
+                               end
+                       end
+               end
+       end
+       --check for any trainpart entities if they have been unloaded. do this only if train is near a player, to not spawn entities into unloaded areas
+       --todo function will be taken by update_trainpart_properties
+       train.check_trainpartload=(train.check_trainpartload or 0)-dtime
+       local node_range=(math.max((minetest.setting_get("active_block_range") or 0),1)*16)
+       if train.check_trainpartload<=0 then
+               local ori_pos=advtrains.get_real_index_position(path, train.index) --not much to calculate
+               --print("[advtrains][train "..id.."] at "..minetest.pos_to_string(vector.round(ori_pos)))
+               
+               local should_check=false
+               for _,p in ipairs(minetest.get_connected_players()) do
+                       should_check=should_check or ((vector.distance(ori_pos, p:getpos())<node_range))
+               end
+               if should_check then
+                       advtrains.update_trainpart_properties(id)
+               end
+               train.check_trainpartload=2
+       end
+       
+       
+       --handle collided_with_env
+       if train.recently_collided_with_env then
+               train.tarvelocity=0
+               if not train_moves then
+                       train.recently_collided_with_env=false--reset status when stopped
+               end
+       end
+       if train.locomotives_in_train==0 then
+               train.tarvelocity=0
+       end
+       
+       --interpret ATC command
+       if train.atc_brake_target and train.atc_brake_target>=train.velocity then
+               train.atc_brake_target=nil
+       end
+       if train.atc_wait_finish then
+               if not train.atc_brake_target and train.velocity==train.tarvelocity then
+                       train.atc_wait_finish=nil
+               end
+       end
+       if train.atc_command then
+               if train.atc_delay<=0 and not train.atc_wait_finish then
+                       advtrains.atc.execute_atc_command(id, train)
+               else
+                       train.atc_delay=train.atc_delay-dtime
+               end
+       end
+       
+       --make brake adjust the tarvelocity if necessary
+       if train.brake and (math.ceil(train.velocity)-1)<train.tarvelocity then
+               train.tarvelocity=math.max((math.ceil(train.velocity)-1), 0)
+       end
+       --apply tarvel(but with physics in mind!)
+       if train.velocity~=train.tarvelocity then
+               local applydiff=0
+               local mass=#train.trainparts
+               local diff=train.tarvelocity-train.velocity
+               if diff>0 then--accelerating, force will be brought on only by locomotives.
+                       --print("accelerating with default force")
+                       applydiff=(math.min((advtrains.train_accel_force*train.locomotives_in_train*dtime)/mass, math.abs(diff)))
+               else--decelerating
+                       if front_off_track or back_off_track or train.recently_collided_with_env then --every wagon has a brake, so not divided by mass.
+                               --print("braking with emergency force")
+                               applydiff= -(math.min((advtrains.train_emerg_force*dtime), math.abs(diff)))
+                       elseif train.brake or (train.atc_brake_target and train.atc_brake_target<train.velocity) then
+                               --print("braking with default force")
+                               --no math.min, because it can grow beyond tarvelocity, see up there
+                               --dont worry, it will never fall below zero.
+                               applydiff= -((advtrains.train_brake_force*dtime))
+                       else
+                               --print("roll")
+                               applydiff= -(math.min((advtrains.train_roll_force*dtime), math.abs(diff)))
+                       end
+               end
+               train.last_accel=(applydiff*train.movedir)
+               train.velocity=math.min(math.max( train.velocity+applydiff , 0), train.max_speed or 10)
+       else
+               train.last_accel=0
+       end
+       
+       --move
+       --TODO 3,5 + 0.7
+       train.index=train.index and train.index+(((train.velocity*train.movedir)/(train.path_dist[math.floor(train.index)] or 1))*dtime) or 0
+       
+end
+
+
+--structure of train table:
+--[[
+trains={
+       [train_id]={
+               trainparts={
+                       [n]=wagon_id
+               }
+               path={path}
+               velocity
+               tarvelocity
+               index
+               trainlen
+               path_inv_level
+               last_pos       |
+               last_dir       | for pathpredicting.
+       }
+}
+--a wagon itself has the following properties:
+wagon={
+       unique_id
+       train_id
+       pos_in_train (is index difference, including train_span stuff)
+       pos_in_trainparts (is index in trainparts tabel of trains)
+}
+inherited by metatable:
+wagon_proto={
+       wagon_span
+}
+]]
+
+--returns new id
+function advtrains.create_new_train_at(pos, pos_prev)
+       local newtrain_id=os.time()..os.clock()
+       while advtrains.trains[newtrain_id] do newtrain_id=os.time()..os.clock() end--ensure uniqueness(will be unneccessary)
+       
+       advtrains.trains[newtrain_id]={}
+       advtrains.trains[newtrain_id].last_pos=pos
+       advtrains.trains[newtrain_id].last_pos_prev=pos_prev
+       advtrains.trains[newtrain_id].tarvelocity=0
+       advtrains.trains[newtrain_id].velocity=0
+       advtrains.trains[newtrain_id].trainparts={}
+       return newtrain_id
+end
+
+--returns false on failure. handle this case!
+function advtrains.pathpredict(id, train)
+       
+       --print("pos ",x,y,z)
+       --::rerun::
+       if not train.index then train.index=0 end
+       if not train.path or #train.path<2 then
+               if not train.last_pos then
+                       --no chance to recover
+                       print("[advtrains]train hasn't saved last-pos, removing train.")
+                       advtrains.train[id]=nil
+                       return false
+               end
+               
+               local node_ok=advtrains.get_rail_info_at(advtrains.round_vector_floor_y(train.last_pos), train.drives_on)
+               
+               if node_ok==nil then
+                       --block not loaded, do nothing
+                       return nil
+               elseif node_ok==false then
+                       print("[advtrains]no track here, (fail) removing train.")
+                       advtrains.trains[id]=nil
+                       return false
+               end
+               
+               if not train.last_pos_prev then
+                       --no chance to recover
+                       print("[advtrains]train hasn't saved last-pos_prev, removing train.")
+                       advtrains.trains[id]=nil
+                       return false
+               end
+               
+               local prevnode_ok=advtrains.get_rail_info_at(advtrains.round_vector_floor_y(train.last_pos_prev), train.drives_on)
+               
+               if prevnode_ok==nil then
+                       --block not loaded, do nothing
+                       return nil
+               elseif prevnode_ok==false then
+                       print("[advtrains]no track at prev, (fail) removing train.")
+                       advtrains.trains[id]=nil
+                       return false
+               end
+               
+               train.index=(train.restore_add_index or 0)+(train.savedpos_off_track_index_offset or 0)
+               --restore_add_index is set by save() to prevent trains hopping to next round index. should be between -0.5 and 0.5
+               --savedpos_off_track_index_offset is set if train went off track. see below.
+               train.path={}
+               train.path_dist={}
+               train.path[0]=train.last_pos
+               train.path[-1]=train.last_pos_prev
+               train.path_dist[-1]=vector.distance(train.last_pos, train.last_pos_prev)
+       end
+       
+       local pregen_front=2
+       local pregen_back=2
+       if train.velocity>0 then
+               if train.movedir>0 then
+                       pregen_front=2+math.ceil(train.velocity*0.15) --assumes server step of 0.1 seconds, +50% tolerance
+               else
+                       pregen_back=2+math.ceil(train.velocity*0.15)
+               end
+       end
+       
+       
+       local maxn=advtrains.maxN(train.path)
+       while (maxn-train.index) < pregen_front do--pregenerate
+               --print("[advtrains]maxn conway for ",maxn,minetest.pos_to_string(path[maxn]),maxn-1,minetest.pos_to_string(path[maxn-1]))
+               local conway=advtrains.conway(train.path[maxn], train.path[maxn-1], train.drives_on)
+               if conway then
+                       train.path[maxn+1]=conway
+                       train.max_index_on_track=maxn
+               else
+                       --do as if nothing has happened and preceed with path
+                       --but do not update max_index_on_track
+                       --print("over-generating path max to index "..maxn+1)
+                       train.path[maxn+1]=vector.add(train.path[maxn], vector.subtract(train.path[maxn], train.path[maxn-1]))
+               end
+               train.path_dist[maxn]=vector.distance(train.path[maxn+1], train.path[maxn])
+               maxn=advtrains.maxN(train.path)
+       end
+       
+       local minn=advtrains.minN(train.path)
+       while (train.index-minn) < (train.trainlen or 0) + pregen_back do --post_generate. has to be at least trainlen. (we let go of the exact calculation here since this would be unuseful here)
+               --print("[advtrains]minn conway for ",minn,minetest.pos_to_string(path[minn]),minn+1,minetest.pos_to_string(path[minn+1]))
+               local conway=advtrains.conway(train.path[minn], train.path[minn+1], train.drives_on)
+               if conway then
+                       train.path[minn-1]=conway
+                       train.min_index_on_track=minn
+               else
+                       --do as if nothing has happened and preceed with path
+                       --but do not update min_index_on_track
+                       --print("over-generating path min to index "..minn-1)
+                       train.path[minn-1]=vector.add(train.path[minn], vector.subtract(train.path[minn], train.path[minn+1]))
+               end
+               train.path_dist[minn-1]=vector.distance(train.path[minn], train.path[minn-1])
+               minn=advtrains.minN(train.path)
+       end
+       if not train.min_index_on_track then train.min_index_on_track=0 end
+       if not train.max_index_on_track then train.max_index_on_track=0 end
+       
+       --make pos/yaw available for possible recover calls
+       if train.max_index_on_track<train.index then --whoops, train went too far. the saved position will be the last one that lies on a track, and savedpos_off_track_index_offset will hold how far to go from here
+               train.savedpos_off_track_index_offset=train.index-train.max_index_on_track
+               train.last_pos=train.path[train.max_index_on_track]
+               train.last_pos_prev=train.path[train.max_index_on_track-1]
+               --print("train is off-track (front), last positions kept at "..minetest.pos_to_string(train.last_pos).." / "..minetest.pos_to_string(train.last_pos_prev))
+       elseif train.min_index_on_track+1>train.index then --whoops, train went even more far. same behavior
+               train.savedpos_off_track_index_offset=train.index-train.min_index_on_track
+               train.last_pos=train.path[train.min_index_on_track+1]
+               train.last_pos_prev=train.path[train.min_index_on_track]
+               --print("train is off-track (back), last positions kept at "..minetest.pos_to_string(train.last_pos).." / "..minetest.pos_to_string(train.last_pos_prev))
+       else --regular case
+               train.savedpos_off_track_index_offset=nil
+               train.last_pos=train.path[math.floor(train.index+0.5)]
+               train.last_pos_prev=train.path[math.floor(train.index-0.5)]
+       end
+       return train.path
+end
+function advtrains.get_train_end_index(train)
+       return advtrains.get_real_path_index(train, train.trainlen or 2)--this function can be found inside wagons.lua since it's more related to wagons. we just set trainlen as pos_in_train
+end
+
+function advtrains.get_or_create_path(id, train)
+       if not train.path then return advtrains.pathpredict(id, train) end
+       return train.path
+end
+
+function advtrains.add_wagon_to_train(wagon, train_id, index)
+       local train=advtrains.trains[train_id]
+       if index then
+               table.insert(train.trainparts, index, wagon.unique_id)
+       else
+               table.insert(train.trainparts, wagon.unique_id)
+       end
+       --this is not the usual case!!!
+       --we may set initialized because the wagon has no chance to step()
+       wagon.initialized=true
+       --TODO is this art or can we throw it away?
+       advtrains.update_trainpart_properties(train_id)
+end
+function advtrains.update_trainpart_properties(train_id, invert_flipstate)
+       local train=advtrains.trains[train_id]
+       train.drives_on=advtrains.all_tracktypes
+       train.max_speed=100
+       local rel_pos=0
+       local count_l=0
+       for i, w_id in ipairs(train.trainparts) do
+               local wagon=nil
+               for _,iwagon in pairs(minetest.luaentities) do
+                       if iwagon.is_wagon and iwagon.initialized and iwagon.unique_id==w_id then
+                               if wagon then
+                                       --duplicate
+                                       iwagon.object:remove()
+                               else
+                                       wagon=iwagon
+                               end
+                       end
+               end
+               if not wagon then
+                       if advtrains.wagon_save[w_id] then
+                               --spawn a new and initialize it with the properties from wagon_save
+                               wagon=minetest.env:add_entity(train.last_pos, advtrains.wagon_save[w_id].entity_name):get_luaentity()
+                               wagon:init_from_wagon_save(w_id)
+                       end
+               end
+               if wagon then
+                       rel_pos=rel_pos+wagon.wagon_span
+                       wagon.train_id=train_id
+                       wagon.pos_in_train=rel_pos
+                       wagon.pos_in_trainparts=i
+                       wagon.old_velocity_vector=nil
+                       if wagon.is_locomotive then
+                               count_l=count_l+1
+                       end
+                       if invert_flipstate then
+                               wagon.wagon_flipped = not wagon.wagon_flipped
+                       end
+                       rel_pos=rel_pos+wagon.wagon_span
+                       any_loaded=true
+                       
+                       if wagon.drives_on then
+                               for k,_ in pairs(train.drives_on) do
+                                       if not wagon.drives_on[k] then
+                                               train.drives_on[k]=nil
+                                       end
+                               end
+                       end
+                       train.max_speed=math.min(train.max_speed, wagon.max_speed)
+               else
+                       print(w_id.." not loaded and no save available")
+                       --what the hell...
+                       table.remove(train.trainparts, pit)
+               end
+       end
+       train.trainlen=rel_pos
+       train.locomotives_in_train=count_l
+end
+
+function advtrains.split_train_at_wagon(wagon)
+       --get train
+       local train=advtrains.trains[wagon.train_id]
+       local real_pos_in_train=advtrains.get_real_path_index(train, wagon.pos_in_train)
+       local pos_for_new_train=advtrains.get_or_create_path(wagon.train_id, train)[math.floor(real_pos_in_train+wagon.wagon_span)]
+       local pos_for_new_train_prev=advtrains.get_or_create_path(wagon.train_id, train)[math.floor(real_pos_in_train-1+wagon.wagon_span)]
+       
+       --before doing anything, check if both are rails. else do not allow
+       if not pos_for_new_train then
+               print("split_train: pos_for_new_train not set")
+               return false
+       end
+       local node_ok=advtrains.get_rail_info_at(advtrains.round_vector_floor_y(pos_for_new_train), train.drives_on)
+       if not node_ok then
+               print("split_train: pos_for_new_train "..minetest.pos_to_string(advtrains.round_vector_floor_y(pos_for_new_train_prev)).." not loaded or is not a rail")
+               return false
+       end
+       
+       if not train.last_pos_prev then
+               print("split_train: pos_for_new_train_prev not set")
+               return false
+       end
+       
+       local prevnode_ok=advtrains.get_rail_info_at(advtrains.round_vector_floor_y(pos_for_new_train), train.drives_on)
+       if not prevnode_ok then
+               print("split_train: pos_for_new_train_prev "..minetest.pos_to_string(advtrains.round_vector_floor_y(pos_for_new_train_prev)).." not loaded or is not a rail")
+               return false
+       end
+       
+       --create subtrain
+       local newtrain_id=advtrains.create_new_train_at(pos_for_new_train, pos_for_new_train_prev)
+       local newtrain=advtrains.trains[newtrain_id]
+       --insert all wagons to new train
+       for k,v in ipairs(train.trainparts) do
+               if k>=wagon.pos_in_trainparts then
+                       table.insert(newtrain.trainparts, v)
+                       train.trainparts[k]=nil
+               end
+       end
+       --update train parts
+       advtrains.update_trainpart_properties(wagon.train_id)--atm it still is the desierd id.
+       advtrains.update_trainpart_properties(newtrain_id)
+       train.tarvelocity=0
+       newtrain.velocity=train.velocity
+       newtrain.tarvelocity=0
+end
+
+--there are 4 cases:
+--1/2. F<->R F<->R regular, put second train behind first
+--->frontpos of first train will match backpos of second
+--3.   F<->R R<->F flip one of these trains, take the other as new train
+--->backpos's will match
+--4.   R<->F F<->R flip one of these trains and take it as new parent
+--->frontpos's will match
+
+--true when trains are facing each other. needed on colliding.
+-- check done by iterating paths and checking their direction
+--returns nil when not on the same track at all OR when required path items are not generated. this distinction may not always be needed.
+function advtrains.trains_facing(train1, train2)
+       local sr_pos=train1.path[math.floor(train1.index)]
+       local sr_pos_p=train1.path[math.floor(train1.index)-1]
+
+       for i=advtrains.minN(train2.path), advtrains.maxN(train2.path) do
+               if vector.equals(sr_pos, train2.path[i]) then
+                       if train2.path[i+1] and vector.equals(sr_pos_p, train2.path[i+1]) then return true end
+                       if train2.path[i-1] and vector.equals(sr_pos_p, train2.path[i-1]) then return false end
+                       return nil
+               end
+       end
+       return nil
+end
+
+function advtrains.spawn_couple_on_collide(id1, pos, id2, t1_is_backpos)
+       print("COLLISION: "..sid(id1).." and "..sid(id2).." at "..minetest.pos_to_string(pos)..", t1_is_backpos="..(t1_is_backpos and "true" or "false"))
+       --TODO:
+       local train1=advtrains.trains[id1]
+       local train2=advtrains.trains[id2]
+       
+       local found
+       for i=advtrains.minN(train1.path), advtrains.maxN(train1.path) do
+               if vector.equals(train1.path[i], pos) then
+                       found=true
+               end
+       end
+       if not found then
+               print("Err: pos not in path")
+               return 
+       end
+       
+       local frontpos2=train2.path[math.floor(train2.detector_old_index)]
+       local backpos2=train2.path[math.floor(train2.detector_old_end_index)]
+       local t2_is_backpos
+       print("End positions: "..minetest.pos_to_string(frontpos2)..minetest.pos_to_string(backpos2))
+       
+       if vector.equals(frontpos2, pos) then
+               t2_is_backpos=false
+       elseif vector.equals(backpos2, pos) then
+               t2_is_backpos=true
+       else
+               print("Err: not a endpos")
+               return --the collision position is not the end position.
+       end
+       print("t2_is_backpos="..(t2_is_backpos and "true" or "false"))
+       
+       local t1_has_couple
+       if t1_is_backpos then
+               t1_has_couple=train1.couple_eid_back
+       else
+               t1_has_couple=train1.couple_eid_front
+       end
+       local t2_has_couple
+       if t2_is_backpos then
+               t2_has_couple=train2.couple_eid_back
+       else
+               t2_has_couple=train2.couple_eid_front
+       end
+       
+       if t1_has_couple then
+               if minetest.object_refs[t1_has_couple] then minetest.object_refs[t1_has_couple]:remove() end
+       end
+       if t2_has_couple then
+               if minetest.object_refs[t2_has_couple] then minetest.object_refs[t2_has_couple]:remove() end
+       end
+       local obj=minetest.add_entity(pos, "advtrains:couple")
+       if not obj then print("failed creating object") return end
+       local le=obj:get_luaentity()
+       le.train_id_1=id1
+       le.train_id_2=id2
+       le.train1_is_backpos=t1_is_backpos
+       le.train2_is_backpos=t2_is_backpos
+       --find in object_refs
+       for aoi, compare in pairs(minetest.object_refs) do
+               if compare==obj then
+                       if t1_is_backpos then
+                               train1.couple_eid_back=aoi
+                       else
+                               train1.couple_eid_front=aoi
+                       end
+                       if t2_is_backpos then
+                               train2.couple_eid_back=aoi
+                       else
+                               train2.couple_eid_front=aoi
+                       end
+               end
+       end
+       print("Couple entity:"..dump(le))
+       
+       --also TODO: integrate check_trainpartload into update_trainpart_properties. 
+end
+--order of trains may be irrelevant in some cases. check opposite cases. TODO does this work?
+--pos1 and pos2 are just needed to form a median.
+
+
+function advtrains.do_connect_trains(first_id, second_id)
+       local first_wagoncnt=#advtrains.trains[first_id].trainparts
+       local second_wagoncnt=#advtrains.trains[second_id].trainparts
+       
+       for _,v in ipairs(advtrains.trains[second_id].trainparts) do
+               table.insert(advtrains.trains[first_id].trainparts, v)
+       end
+       --kick it like physics (with mass being #wagons)
+       local new_velocity=((advtrains.trains[first_id].velocity*first_wagoncnt)+(advtrains.trains[second_id].velocity*second_wagoncnt))/(first_wagoncnt+second_wagoncnt)
+       advtrains.trains[second_id]=nil
+       advtrains.update_trainpart_properties(first_id)
+       advtrains.trains[first_id].velocity=new_velocity
+       advtrains.trains[first_id].tarvelocity=0
+end
+
+function advtrains.invert_train(train_id)
+       local train=advtrains.trains[train_id]
+       
+       local old_path=advtrains.get_or_create_path(train_id, train)
+       train.path={}
+       train.index= - advtrains.get_train_end_index(train)
+       train.velocity=-train.velocity
+       train.tarvelocity=-train.tarvelocity
+       for k,v in pairs(old_path) do
+               train.path[-k]=v
+       end
+       local old_trainparts=train.trainparts
+       train.trainparts={}
+       for k,v in ipairs(old_trainparts) do
+               table.insert(train.trainparts, 1, v)--notice insertion at first place
+       end
+       advtrains.update_trainpart_properties(train_id, true)
+end
+
+function advtrains.is_train_at_pos(pos)
+       --print("istrainat: pos "..minetest.pos_to_string(pos))
+       local checked_trains={}
+       local objrefs=minetest.get_objects_inside_radius(pos, 2)
+       for _,v in pairs(objrefs) do
+               local le=v:get_luaentity()
+               if le and le.is_wagon and le.initialized and le.train_id and not checked_trains[le.train_id] then
+                       --print("istrainat: checking "..le.train_id)
+                       checked_trains[le.train_id]=true
+                       local path=advtrains.get_or_create_path(le.train_id, le:train())
+                       if path then
+                               --print("has path")
+                               for i=math.floor(advtrains.get_train_end_index(le:train())+0.5),math.floor(le:train().index+0.5) do
+                                       if path[i] then
+                                               --print("has pathitem "..i.." "..minetest.pos_to_string(path[i]))
+                                               if vector.equals(advtrains.round_vector_floor_y(path[i]), pos) then
+                                                       return true
+                                               end
+                                       end
+                               end
+                       end
+               end
+       end
+       return false
+end
+function advtrains.invalidate_all_paths()
+       --print("invalidating all paths")
+       for k,v in pairs(advtrains.trains) do
+               if v.index then
+                       v.restore_add_index=v.index-math.floor(v.index+0.5)
+               end
+               v.path=nil
+               v.path_dist=nil
+               v.index=nil
+               v.min_index_on_track=nil
+               v.max_index_on_track=nil
+               
+               advtrains.detector.setup_restore()
+               v.detector_old_index=nil
+               v.detector_old_end_index=nil
+       end
+end
+
+--not blocking trains group
+function advtrains.train_collides(node)
+       if node and minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].walkable then
+               if not minetest.registered_nodes[node.name].groups.not_blocking_trains then
+                       return true
+               end
+       end
+       return false
+end
+
+local nonblocknodes={
+       "default:fence_wood",
+       "default:fence_acacia_wood",
+       "default:fence_aspen_wood",
+       "default:fence_pine_wood",
+       "default:fence_junglewood",
+       "default:torch",
+       
+       "default:sign_wall",
+       "signs:sign_wall",
+       "signs:sign_wall_blue",
+       "signs:sign_wall_brown",
+       "signs:sign_wall_orange",
+       "signs:sign_wall_green",
+       "signs:sign_yard",
+       "signs:sign_wall_white_black",
+       "signs:sign_wall_red",
+       "signs:sign_wall_white_red",
+       "signs:sign_wall_yellow",
+       "signs:sign_post",
+       "signs:sign_hanging",
+       
+       
+}
+minetest.after(0, function()
+       for _,name in ipairs(nonblocknodes) do
+               if minetest.registered_nodes[name] then
+                       minetest.registered_nodes[name].groups.not_blocking_trains=1
+               end
+       end
+end)
diff --git a/advtrains/advtrains/wagons.lua b/advtrains/advtrains/wagons.lua
new file mode 100644 (file)
index 0000000..495f914
--- /dev/null
@@ -0,0 +1,573 @@
+--atan2 counts angles clockwise, minetest does counterclockwise\r
+--local print=function(t) minetest.log("action", t) minetest.chat_send_all(t) end\r
+local print=function() end\r
+\r
+local wagon={\r
+       collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},\r
+       --physical = true,\r
+       visual = "mesh",\r
+       mesh = "wagon.b3d",\r
+       visual_size = {x=3, y=3},\r
+       textures = {"black.png"},\r
+       is_wagon=true,\r
+       wagon_span=1,--how many index units of space does this wagon consume\r
+       has_inventory=false,\r
+}\r
+\r
+\r
+\r
+function wagon:on_rightclick(clicker)\r
+       if not self:ensure_init() then return end\r
+       if not clicker or not clicker:is_player() then\r
+               return\r
+       end\r
+       if clicker:get_player_control().aux1 then\r
+               --advtrains.dumppath(self:train().path)\r
+               --minetest.chat_send_all("at index "..(self:train().index or "nil"))\r
+               --advtrains.invert_train(self.train_id)\r
+               minetest.chat_send_all(dump(self:train()))\r
+               return\r
+       end     \r
+       local no=self:get_seatno(clicker:get_player_name())\r
+       if no then\r
+               self:get_off(no)\r
+       else\r
+               self:show_get_on_form(clicker:get_player_name())\r
+       end\r
+end\r
+\r
+function wagon:train()\r
+       return advtrains.trains[self.train_id]\r
+end\r
+\r
+--[[about 'initalized':\r
+       when initialized is false, the entity hasn't got any data yet and should wait for these to be set before doing anything\r
+       when loading an existing object (with staticdata), it will be set\r
+       when instanciating a new object via add_entity, it is not set at the time on_activate is called.\r
+       then, wagon:initialize() will be called\r
+       \r
+       wagon will save only uid in staticdata, no serialized table\r
+]]\r
+function wagon:on_activate(sd_uid, dtime_s)\r
+       print("[advtrains][wagon "..((sd_uid and sd_uid~="" and sd_uid) or "no-id").."] activated")\r
+       self.object:set_armor_groups({immortal=1})\r
+       if sd_uid and sd_uid~="" then\r
+               --legacy\r
+               --expect this to be a serialized table and handle\r
+               if minetest.deserialize(sd_uid) then\r
+                       self:init_from_wagon_save(minetest.deserialize(sd_uid).unique_id)\r
+               else\r
+                       self:init_from_wagon_save(sd_uid)\r
+               end\r
+       end\r
+       self.entity_name=self.name\r
+       \r
+       --duplicates?\r
+       for ao_id,wagon in pairs(minetest.luaentities) do\r
+               if wagon.is_wagon and wagon.initialized and wagon.unique_id==self.unique_id and wagon~=self then--i am a duplicate!\r
+                       print("[advtrains][wagon "..((sd_uid and sd_uid~="" and sd_uid) or "no-id").."] duplicate found(ao_id:"..ao_id.."), removing")\r
+                       self.object:remove()\r
+                       minetest.after(0.5, function() advtrains.update_trainpart_properties(self.train_id) end)\r
+                       return\r
+               end\r
+       end\r
+       \r
+       if self.custom_on_activate then\r
+               self:custom_on_activate(dtime_s)\r
+       end\r
+end\r
+\r
+function wagon:get_staticdata()\r
+       if not self:ensure_init() then return end\r
+       print("[advtrains][wagon "..((self.unique_id and self.unique_id~="" and self.unique_id) or "no-id").."]: saving to wagon_save")\r
+       --serialize inventory, if it has one\r
+       if self.has_inventory then\r
+               local inv=minetest.get_inventory({type="detached", name="advtrains_wgn_"..self.unique_id})\r
+               self.ser_inv=advtrains.serialize_inventory(inv)\r
+       end\r
+       --save to table before being unloaded\r
+       advtrains.wagon_save[self.unique_id]=advtrains.merge_tables(self)\r
+       advtrains.wagon_save[self.unique_id].entity_name=self.name\r
+       advtrains.wagon_save[self.unique_id].name=nil\r
+       advtrains.wagon_save[self.unique_id].object=nil\r
+       return self.unique_id\r
+end\r
+--returns: uid of wagon\r
+function wagon:init_new_instance(train_id, properties)\r
+       self.unique_id=os.time()..os.clock()\r
+       self.train_id=train_id\r
+       for k,v in pairs(properties) do\r
+               if k~="name" and k~="object" then\r
+                       self[k]=v\r
+               end\r
+       end\r
+       self:init_shared()\r
+       self.initialized=true\r
+       print("init_new_instance "..self.unique_id.." ("..self.train_id..")")\r
+       return self.unique_id\r
+end\r
+function wagon:init_from_wagon_save(uid)\r
+       if not advtrains.wagon_save[uid] then\r
+               self.object:remove()\r
+               return\r
+       end\r
+       self.unique_id=uid\r
+       for k,v in pairs(advtrains.wagon_save[uid]) do\r
+               if k~="name" and k~="object" then\r
+                       self[k]=v\r
+               end\r
+       end\r
+       if not self.train_id or not self:train() then\r
+               self.object:remove()\r
+               return\r
+       end\r
+       self:init_shared()\r
+       self.initialized=true\r
+       minetest.after(1, function() self:reattach_all() end)\r
+       print("init_from_wagon_save "..self.unique_id.." ("..self.train_id..")")\r
+       advtrains.update_trainpart_properties(self.train_id)\r
+end\r
+function wagon:init_shared()\r
+       if self.has_inventory then\r
+               local uid_noptr=self.unique_id..""\r
+               --to be used later\r
+               local inv=minetest.create_detached_inventory("advtrains_wgn_"..self.unique_id, {\r
+                       allow_move = function(inv, from_list, from_index, to_list, to_index, count, player)\r
+                               return count\r
+                       end,\r
+                       allow_put = function(inv, listname, index, stack, player)\r
+                               return stack:get_count()\r
+                       end,\r
+                       allow_take = function(inv, listname, index, stack, player)\r
+                               return stack:get_count()\r
+                       end\r
+               })\r
+               if self.ser_inv then\r
+                       advtrains.deserialize_inventory(self.ser_inv, inv)\r
+               end\r
+               if self.inventory_list_sizes then\r
+                       for lst, siz in pairs(self.inventory_list_sizes) do\r
+                               inv:set_size(lst, siz)\r
+                       end\r
+               end\r
+       end\r
+end\r
+function wagon:ensure_init()\r
+       if self.initialized then return true end\r
+       self.object:setvelocity({x=0,y=0,z=0})\r
+       return false\r
+end\r
+\r
+-- Remove the wagon\r
+function wagon:on_punch(puncher, time_from_last_punch, tool_capabilities, direction)\r
+       if not self:ensure_init() then return end\r
+       if not puncher or not puncher:is_player() then\r
+               return\r
+       end\r
+       if self.owner and puncher:get_player_name()~=self.owner then\r
+               minetest.chat_send_player(puncher:get_player_name(), "This wagon is owned by "..self.owner..", you can't destroy it.")\r
+               return\r
+       end\r
+       \r
+       if minetest.setting_getbool("creative_mode") then\r
+               if not self:destroy() then return end\r
+               \r
+               local inv = puncher:get_inventory()\r
+               if not inv:contains_item("main", self.name) then\r
+                       inv:add_item("main", self.name)\r
+               end\r
+       else\r
+               local pc=puncher:get_player_control()\r
+               if not pc.sneak then\r
+                       minetest.chat_send_player(puncher:get_player_name(), "Warning: If you destroy this wagon, you only get some steel back! If you are sure, shift-leftclick the wagon.")\r
+                       return\r
+               end\r
+\r
+               if not self:destroy() then return end\r
+\r
+               local inv = puncher:get_inventory()\r
+               for _,item in ipairs(self.drops or {self.name}) do\r
+                       inv:add_item("main", item)\r
+               end\r
+       end\r
+end\r
+function wagon:destroy()\r
+       --some rules:\r
+       -- you get only some items back\r
+       -- single left-click shows warning\r
+       -- shift leftclick destroys\r
+       -- not when a driver is inside\r
+       \r
+       for _,_ in pairs(self.seatp) do\r
+               return\r
+       end\r
+       \r
+       if self.custom_may_destroy then\r
+               if not self.custom_may_destroy(self, puncher, time_from_last_punch, tool_capabilities, direction) then\r
+                       return\r
+               end\r
+       end\r
+       if self.custom_on_destroy then\r
+               self.custom_on_destroy(self, puncher, time_from_last_punch, tool_capabilities, direction)\r
+       end\r
+       \r
+       print("[advtrains][wagon "..((self.unique_id and self.unique_id~="" and self.unique_id) or "no-id").."]: destroying")\r
+       \r
+       self.object:remove()\r
+\r
+       table.remove(self:train().trainparts, self.pos_in_trainparts)\r
+       advtrains.update_trainpart_properties(self.train_id)\r
+       advtrains.wagon_save[self.unique_id]=nil\r
+       if self.discouple then self.discouple.object:remove() end--will have no effect on unloaded objects\r
+       return true\r
+end\r
+\r
+\r
+function wagon:on_step(dtime)\r
+       if not self:ensure_init() then return end\r
+       \r
+       local t=os.clock()\r
+       local pos = self.object:getpos()\r
+       \r
+       if not pos then\r
+               print("["..self.unique_id.."][fatal] missing position (object:getpos() returned nil)")\r
+               return\r
+       end\r
+\r
+       self.entity_name=self.name\r
+       \r
+       --is my train still here\r
+       if not self.train_id or not self:train() then\r
+               print("[advtrains][wagon "..self.unique_id.."] missing train_id, destroying")\r
+               self.object:remove()\r
+               return\r
+       elseif not self.initialized then\r
+               self.initialized=true\r
+       end\r
+       if not self.seatp then\r
+               self.seatp={}\r
+       end\r
+\r
+       --custom on_step function\r
+       if self.custom_on_step then\r
+               self:custom_on_step(self, dtime)\r
+       end\r
+\r
+       --driver control\r
+       for seatno, seat in ipairs(self.seats) do\r
+               if seat.driving_ctrl_access then\r
+                       local driver=self.seatp[seatno] and minetest.get_player_by_name(self.seatp[seatno])\r
+                       local get_off_pressed=false\r
+                       if driver and driver:get_player_control_bits()~=self.old_player_control_bits then\r
+                               local pc=driver:get_player_control()\r
+                               \r
+                               advtrains.on_control_change(pc, self:train(), self.wagon_flipped)\r
+                               if pc.aux1 and pc.sneak then\r
+                                       get_off_pressed=true\r
+                               end\r
+                               \r
+                               self.old_player_control_bits=driver:get_player_control_bits()\r
+                       end\r
+                       if driver then\r
+                               if get_off_pressed then\r
+                                       self:get_off(seatno)\r
+                               else\r
+                                       advtrains.update_driver_hud(driver:get_player_name(), self:train(), self.wagon_flipped)\r
+                               end\r
+                       end\r
+               end\r
+       end\r
+\r
+       local gp=self:train()\r
+\r
+       --DisCouple\r
+       if self.pos_in_trainparts and self.pos_in_trainparts>1 then\r
+               if gp.velocity==0 then\r
+                       if not self.discouple or not self.discouple.object:getyaw() then\r
+                               local object=minetest.add_entity(pos, "advtrains:discouple")\r
+                               if object then\r
+                                       local le=object:get_luaentity()\r
+                                       le.wagon=self\r
+                                       --box is hidden when attached, so unuseful.\r
+                                       --object:set_attach(self.object, "", {x=0, y=0, z=self.wagon_span*10}, {x=0, y=0, z=0})\r
+                                       self.discouple=le\r
+                               else\r
+                                       print("Couldn't spawn DisCouple")\r
+                               end\r
+                       end\r
+               else\r
+                       if self.discouple and self.discouple.object:getyaw() then\r
+                               self.discouple.object:remove()\r
+                       end\r
+               end\r
+       end\r
+       --for path to be available. if not, skip step\r
+       if not advtrains.get_or_create_path(self.train_id, gp) then\r
+               self.object:setvelocity({x=0, y=0, z=0})\r
+               return\r
+       end\r
+       if not self.pos_in_train then\r
+               --why ever. but better continue next step...\r
+               advtrains.update_trainpart_properties(self.train_id)\r
+               return\r
+       end\r
+       \r
+       local index=advtrains.get_real_path_index(self:train(), self.pos_in_train)\r
+       --print("trainindex "..gp.index.." wagonindex "..index)\r
+       \r
+       --position recalculation\r
+       local first_pos=gp.path[math.floor(index)]\r
+       local second_pos=gp.path[math.floor(index)+1]\r
+       if not first_pos or not second_pos then\r
+               --print("[advtrains] object "..self.unique_id.." path end reached!")\r
+               self.object:setvelocity({x=0,y=0,z=0})\r
+               return\r
+       end\r
+       \r
+       --checking for environment collisions(a 3x3 cube around the center)\r
+       if not gp.recently_collided_with_env then\r
+               local collides=false\r
+               for x=-1,1 do\r
+                       for y=0,2 do\r
+                               for z=-1,1 do\r
+                                       local node=minetest.get_node_or_nil(vector.add(first_pos, {x=x, y=y, z=z}))\r
+                                       if (advtrains.train_collides(node)) then\r
+                                               collides=true\r
+                                       end\r
+                               end\r
+                       end\r
+               end\r
+               if collides then\r
+                       gp.recently_collided_with_env=true\r
+                       gp.velocity=-0.5*gp.velocity\r
+                       gp.tarvelocity=0\r
+               end\r
+       end\r
+       \r
+       --FIX: use index of the wagon, not of the train.\r
+       local velocity=(gp.velocity*gp.movedir)/(gp.path_dist[math.floor(index)] or 1)\r
+       local acceleration=(gp.last_accel or 0)/(gp.path_dist[math.floor(index)] or 1)\r
+       local factor=index-math.floor(index)\r
+       local actual_pos={x=first_pos.x-(first_pos.x-second_pos.x)*factor, y=first_pos.y-(first_pos.y-second_pos.y)*factor, z=first_pos.z-(first_pos.z-second_pos.z)*factor,}\r
+       local velocityvec={x=(first_pos.x-second_pos.x)*velocity*-1, z=(first_pos.z-second_pos.z)*velocity*-1, y=(first_pos.y-second_pos.y)*velocity*-1}\r
+       local accelerationvec={x=(first_pos.x-second_pos.x)*acceleration*-1, z=(first_pos.z-second_pos.z)*acceleration*-1, y=(first_pos.y-second_pos.y)*acceleration*-1}\r
+       \r
+       --some additional positions to determine orientation\r
+       local aposfwd=gp.path[math.floor(index+2)]\r
+       local aposbwd=gp.path[math.floor(index-1)]\r
+       \r
+       local yaw\r
+       if aposfwd and aposbwd then\r
+               yaw=advtrains.get_wagon_yaw(aposfwd, second_pos, first_pos, aposbwd, factor)+math.pi--TODO remove when cleaning up\r
+       else\r
+               yaw=math.atan2((first_pos.x-second_pos.x), (second_pos.z-first_pos.z))\r
+       end\r
+       if self.wagon_flipped then\r
+               yaw=yaw+math.pi\r
+       end\r
+       \r
+       self.updatepct_timer=(self.updatepct_timer or 0)-dtime\r
+       if not self.old_velocity_vector \r
+                       or not vector.equals(velocityvec, self.old_velocity_vector)\r
+                       or not self.old_acceleration_vector \r
+                       or not vector.equals(accelerationvec, self.old_acceleration_vector)\r
+                       or self.old_yaw~=yaw\r
+                       or self.updatepct_timer<=0 then--only send update packet if something changed\r
+                       self.object:setpos(actual_pos)\r
+               self.object:setvelocity(velocityvec)\r
+               self.object:setacceleration(accelerationvec)\r
+               self.object:setyaw(yaw)\r
+               self.updatepct_timer=2\r
+               if self.update_animation then\r
+                       self:update_animation(gp.velocity)\r
+               end\r
+       end\r
+       \r
+       \r
+       self.old_velocity_vector=velocityvec\r
+       self.old_acceleration_vector=accelerationvec\r
+       self.old_yaw=yaw\r
+       printbm("wagon step", t)\r
+end\r
+\r
+function advtrains.get_real_path_index(train, pit)\r
+       local pos_in_train_left=pit\r
+       local index=train.index\r
+       if pos_in_train_left>(index-math.floor(index))*(train.path_dist[math.floor(index)] or 1) then\r
+               pos_in_train_left=pos_in_train_left - (index-math.floor(index))*(train.path_dist[math.floor(index)] or 1)\r
+               index=math.floor(index)\r
+               while pos_in_train_left>(train.path_dist[index-1] or 1) do\r
+                       pos_in_train_left=pos_in_train_left - (train.path_dist[index-1] or 1)\r
+                       index=index-1\r
+               end\r
+               index=index-(pos_in_train_left/(train.path_dist[index-1] or 1))\r
+       else\r
+               index=index-(pos_in_train_left/(train.path_dist[math.floor(index-1)] or 1))\r
+       end\r
+       return index\r
+end\r
+\r
+function wagon:get_on(clicker, seatno)\r
+       if not self.seatp then\r
+               self.seatp={}\r
+       end\r
+       if not self.seats[seatno] then return end\r
+       if self.seatp[seatno] and self.seatp[seatno]~=clicker:get_player_name() then\r
+               self:get_off(seatno)\r
+       end\r
+       self.seatp[seatno] = clicker:get_player_name()\r
+       advtrains.player_to_train_mapping[clicker:get_player_name()]=self.train_id\r
+       clicker:set_attach(self.object, "", self.seats[seatno].attach_offset, {x=0,y=0,z=0})\r
+       clicker:set_eye_offset(self.seats[seatno].view_offset, self.seats[seatno].view_offset)\r
+end\r
+function wagon:get_off_plr(pname)\r
+       local no=self:get_seatno(pname)\r
+       if no then\r
+               self:get_off(no)\r
+       end\r
+end\r
+function wagon:get_seatno(pname)\r
+       for no, cont in pairs(self.seatp) do\r
+               if cont==pname then\r
+                       return no\r
+               end\r
+       end\r
+       return nil\r
+end\r
+function wagon:get_off(seatno)\r
+       if not self.seatp[seatno] then return end\r
+       local pname = self.seatp[seatno]\r
+       local clicker = minetest.get_player_by_name(pname)\r
+       advtrains.player_to_train_mapping[pname]=nil\r
+       advtrains.clear_driver_hud(pname)\r
+       if clicker then\r
+               clicker:set_detach()\r
+               clicker:set_eye_offset({x=0,y=0,z=0}, {x=0,y=0,z=0})\r
+               local objpos=advtrains.round_vector_floor_y(self.object:getpos())\r
+               local yaw=self.object:getyaw()\r
+               local isx=(yaw < math.pi/4) or (yaw > 3*math.pi/4 and yaw < 5*math.pi/4) or (yaw > 7*math.pi/4)\r
+               --abuse helper function\r
+               for _,r in ipairs({-1, 1}) do\r
+                       local p=vector.add({x=isx and r or 0, y=0, z=not isx and r or 0}, objpos)\r
+                       if minetest.get_item_group(minetest.get_node(p).name, "platform")>0 then\r
+                               minetest.after(0.2, function() clicker:setpos({