aboutsummaryrefslogtreecommitdiff
path: root/advtrains
diff options
context:
space:
mode:
authorGabriel Pérez-Cerezo <gabriel@gpcf.eu>2017-01-18 23:22:06 +0100
committerGabriel Pérez-Cerezo <gabriel@gpcf.eu>2017-01-18 23:22:06 +0100
commitfc67d4531a6cd53f29b14ce9f44da984149d9175 (patch)
tree5675c23d81f92d327b197d7c4474852f19ba3e52 /advtrains
parent0030409dd34f611b90861a528d6735a44dd663f2 (diff)
parent4bc5163787c6c4c42fd14016c1c5103529d0e239 (diff)
downloadadvtrains-fc67d4531a6cd53f29b14ce9f44da984149d9175.tar.gz
advtrains-fc67d4531a6cd53f29b14ce9f44da984149d9175.tar.bz2
advtrains-fc67d4531a6cd53f29b14ce9f44da984149d9175.zip
Merged priv
Diffstat (limited to 'advtrains')
-rw-r--r--advtrains/advtrains.zipbin0 -> 1488724 bytes
-rw-r--r--advtrains/advtrains/api_doc.txt114
-rw-r--r--advtrains/advtrains/atc.lua274
-rw-r--r--advtrains/advtrains/couple.lua156
-rw-r--r--advtrains/advtrains/crafting.lua71
-rw-r--r--advtrains/advtrains/damage.lua26
-rw-r--r--advtrains/advtrains/debugitems.lua28
-rw-r--r--advtrains/advtrains/depends.txt2
-rw-r--r--advtrains/advtrains/description.txt8
-rw-r--r--advtrains/advtrains/helpers.lua244
-rw-r--r--advtrains/advtrains/init.lua180
-rw-r--r--advtrains/advtrains/lua_atc.lua166
-rw-r--r--advtrains/advtrains/misc_nodes.lua67
-rw-r--r--advtrains/advtrains/models/advtrains_dtrack_bumper_st.b3dbin0 -> 32927 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_dtrack_bumper_st_30.b3dbin0 -> 48546 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_dtrack_bumper_st_45.b3dbin0 -> 32926 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_dtrack_bumper_st_60.b3dbin0 -> 48546 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_dtrack_cr.b3dbin0 -> 27540 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_dtrack_cr_30.b3dbin0 -> 27543 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_dtrack_cr_45.b3dbin0 -> 23037 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_dtrack_cr_60.b3dbin0 -> 23037 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_dtrack_detector_st.b3dbin0 -> 17157 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_dtrack_detector_st_30.b3dbin0 -> 32779 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_dtrack_detector_st_45.b3dbin0 -> 17163 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_dtrack_detector_st_60.b3dbin0 -> 32779 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_dtrack_st.b3dbin0 -> 15828 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_dtrack_st_30.b3dbin0 -> 31447 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_dtrack_st_45.b3dbin0 -> 15831 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_dtrack_st_60.b3dbin0 -> 31447 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_dtrack_swlcr.b3dbin0 -> 36743 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_dtrack_swlcr_30.b3dbin0 -> 45922 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_dtrack_swlcr_45.b3dbin0 -> 32112 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_dtrack_swlcr_60.b3dbin0 -> 44864 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_dtrack_swlst.b3dbin0 -> 36743 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_dtrack_swlst_30.b3dbin0 -> 45922 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_dtrack_swlst_45.b3dbin0 -> 32112 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_dtrack_swlst_60.b3dbin0 -> 44864 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_dtrack_swrcr.b3dbin0 -> 36743 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_dtrack_swrcr_30.b3dbin0 -> 44864 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_dtrack_swrcr_45.b3dbin0 -> 32112 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_dtrack_swrcr_60.b3dbin0 -> 45922 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_dtrack_swrst.b3dbin0 -> 36743 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_dtrack_swrst_30.b3dbin0 -> 44864 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_dtrack_swrst_45.b3dbin0 -> 32112 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_dtrack_swrst_60.b3dbin0 -> 45922 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_dtrack_vst1.b3dbin0 -> 21495 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_dtrack_vst1_45.b3dbin0 -> 20739 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_dtrack_vst2.b3dbin0 -> 25143 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_dtrack_vst2_45.b3dbin0 -> 20919 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_dtrack_vst31.b3dbin0 -> 19051 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_dtrack_vst32.b3dbin0 -> 21635 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_dtrack_vst33.b3dbin0 -> 28795 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_modernwagon.b3dbin0 -> 172028 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_retrosignal_off.b3dbin0 -> 13093 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_retrosignal_off_30.b3dbin0 -> 13093 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_retrosignal_off_45.b3dbin0 -> 13093 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_retrosignal_off_60.b3dbin0 -> 13093 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_retrosignal_on.b3dbin0 -> 13093 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_retrosignal_on_30.b3dbin0 -> 13093 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_retrosignal_on_45.b3dbin0 -> 13093 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_retrosignal_on_60.b3dbin0 -> 13093 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_signal.b3dbin0 -> 61544 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_signal_30.b3dbin0 -> 61544 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_signal_45.b3dbin0 -> 61544 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_signal_60.b3dbin0 -> 61544 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_track_cr.b3dbin0 -> 8023 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_track_st.b3dbin0 -> 15831 bytes
-rw-r--r--advtrains/advtrains/models/advtrains_track_st_45.b3dbin0 -> 8935 bytes
-rw-r--r--advtrains/advtrains/models/trackplane.b3dbin0 -> 262 bytes
-rw-r--r--advtrains/advtrains/nodedb.lua232
-rw-r--r--advtrains/advtrains/signals.lua78
-rw-r--r--advtrains/advtrains/textures/advtrains_couple.pngbin0 -> 265 bytes
-rw-r--r--advtrains/advtrains/textures/advtrains_discouple.pngbin0 -> 307 bytes
-rw-r--r--advtrains/advtrains/textures/advtrains_dtrack_atc_placer.pngbin0 -> 1259 bytes
-rw-r--r--advtrains/advtrains/textures/advtrains_dtrack_bumper_placer.pngbin0 -> 2213 bytes
-rw-r--r--advtrains/advtrains/textures/advtrains_dtrack_detector_placer.pngbin0 -> 1253 bytes
-rw-r--r--advtrains/advtrains/textures/advtrains_dtrack_placer.pngbin0 -> 1097 bytes
-rw-r--r--advtrains/advtrains/textures/advtrains_dtrack_rail.pngbin0 -> 2814 bytes
-rw-r--r--advtrains/advtrains/textures/advtrains_dtrack_rail_atc.pngbin0 -> 2837 bytes
-rw-r--r--advtrains/advtrains/textures/advtrains_dtrack_rail_detector_on.pngbin0 -> 2818 bytes
-rw-r--r--advtrains/advtrains/textures/advtrains_dtrack_slopeplacer.pngbin0 -> 2415 bytes
-rw-r--r--advtrains/advtrains/textures/advtrains_platform.pngbin0 -> 193 bytes
-rw-r--r--advtrains/advtrains/textures/advtrains_retrosignal.pngbin0 -> 8496 bytes
-rw-r--r--advtrains/advtrains/textures/advtrains_retrosignal_inv.pngbin0 -> 2242 bytes
-rw-r--r--advtrains/advtrains/textures/advtrains_signal_inv.pngbin0 -> 856 bytes
-rw-r--r--advtrains/advtrains/textures/advtrains_signal_off.pngbin0 -> 5882 bytes
-rw-r--r--advtrains/advtrains/textures/advtrains_signal_on.pngbin0 -> 5884 bytes
-rw-r--r--advtrains/advtrains/textures/advtrains_track_cr.pngbin0 -> 33370 bytes
-rw-r--r--advtrains/advtrains/textures/advtrains_track_cr_45.pngbin0 -> 33938 bytes
-rw-r--r--advtrains/advtrains/textures/advtrains_track_placer.pngbin0 -> 32349 bytes
-rw-r--r--advtrains/advtrains/textures/advtrains_track_st.pngbin0 -> 20405 bytes
-rw-r--r--advtrains/advtrains/textures/advtrains_track_st_45.pngbin0 -> 39977 bytes
-rw-r--r--advtrains/advtrains/textures/advtrains_track_swlcr.pngbin0 -> 33378 bytes
-rw-r--r--advtrains/advtrains/textures/advtrains_track_swlcr_45.pngbin0 -> 45772 bytes
-rw-r--r--advtrains/advtrains/textures/advtrains_track_swlst.pngbin0 -> 32321 bytes
-rw-r--r--advtrains/advtrains/textures/advtrains_track_swlst_45.pngbin0 -> 46408 bytes
-rw-r--r--advtrains/advtrains/textures/advtrains_track_swrcr.pngbin0 -> 33670 bytes
-rw-r--r--advtrains/advtrains/textures/advtrains_track_swrcr_45.pngbin0 -> 46865 bytes
-rw-r--r--advtrains/advtrains/textures/advtrains_track_swrst.pngbin0 -> 32654 bytes
-rw-r--r--advtrains/advtrains/textures/advtrains_track_swrst_45.pngbin0 -> 47636 bytes
-rw-r--r--advtrains/advtrains/textures/advtrains_trackworker.pngbin0 -> 328 bytes
-rw-r--r--advtrains/advtrains/textures/drwho_screwdriver.pngbin0 -> 328 bytes
-rw-r--r--advtrains/advtrains/trackdb_legacy.lua27
-rw-r--r--advtrains/advtrains/trackplacer.lua297
-rw-r--r--advtrains/advtrains/tracks.lua733
-rw-r--r--advtrains/advtrains/trainhud.lua109
-rw-r--r--advtrains/advtrains/trainlogic.lua803
-rw-r--r--advtrains/advtrains/wagons.lua590
-rw-r--r--advtrains/advtrains_train_industrial/depends.txt1
-rw-r--r--advtrains/advtrains_train_industrial/init.lua67
-rw-r--r--advtrains/advtrains_train_industrial/models/advtrains_engine_industrial.b3dbin0 -> 143659 bytes
-rw-r--r--advtrains/advtrains_train_industrial/models/advtrains_wagon_tank.b3dbin0 -> 223975 bytes
-rw-r--r--advtrains/advtrains_train_industrial/models/advtrains_wagon_wood.b3dbin0 -> 193975 bytes
-rw-r--r--advtrains/advtrains_train_industrial/textures/advtrains_engine_industrial.pngbin0 -> 59019 bytes
-rw-r--r--advtrains/advtrains_train_industrial/textures/advtrains_engine_industrial_inv.pngbin0 -> 381 bytes
-rw-r--r--advtrains/advtrains_train_industrial/textures/advtrains_wagon_tank.pngbin0 -> 8975 bytes
-rw-r--r--advtrains/advtrains_train_industrial/textures/advtrains_wagon_tank_inv.pngbin0 -> 408 bytes
-rw-r--r--advtrains/advtrains_train_industrial/textures/advtrains_wagon_wood.pngbin0 -> 5974 bytes
-rw-r--r--advtrains/advtrains_train_industrial/textures/advtrains_wagon_wood_inv.pngbin0 -> 316 bytes
-rw-r--r--advtrains/advtrains_train_japan/depends.txt1
-rw-r--r--advtrains/advtrains_train_japan/init.lua38
-rw-r--r--advtrains/advtrains_train_japan/models/advtrains_engine_japan.b3dbin0 -> 165287 bytes
-rw-r--r--advtrains/advtrains_train_japan/models/advtrains_wagon_japan.b3dbin0 -> 171991 bytes
-rw-r--r--advtrains/advtrains_train_japan/textures/advtrains_engine_japan.pngbin0 -> 12664 bytes
-rw-r--r--advtrains/advtrains_train_japan/textures/advtrains_engine_japan_inv.pngbin0 -> 434 bytes
-rw-r--r--advtrains/advtrains_train_japan/textures/advtrains_wagon_japan.pngbin0 -> 11175 bytes
-rw-r--r--advtrains/advtrains_train_japan/textures/advtrains_wagon_japan_inv.pngbin0 -> 400 bytes
-rw-r--r--advtrains/advtrains_train_steam/depends.txt1
-rw-r--r--advtrains/advtrains_train_steam/init.lua196
-rw-r--r--advtrains/advtrains_train_steam/models/advtrains_detailed_steam_engine.b3dbin0 -> 468002 bytes
-rw-r--r--advtrains/advtrains_train_steam/models/advtrains_engine_steam.b3dbin0 -> 437126 bytes
-rw-r--r--advtrains/advtrains_train_steam/models/advtrains_passenger_wagon.b3dbin0 -> 341965 bytes
-rw-r--r--advtrains/advtrains_train_steam/models/advtrains_wagon.b3dbin0 -> 107352 bytes
-rw-r--r--advtrains/advtrains_train_steam/textures/advtrains_detailed_steam_engine.pngbin0 -> 61988 bytes
-rw-r--r--advtrains/advtrains_train_steam/textures/advtrains_engine_steam.pngbin0 -> 31915 bytes
-rw-r--r--advtrains/advtrains_train_steam/textures/advtrains_engine_steam_inv.pngbin0 -> 469 bytes
-rw-r--r--advtrains/advtrains_train_steam/textures/advtrains_wagon.pngbin0 -> 42023 bytes
-rw-r--r--advtrains/advtrains_train_steam/textures/advtrains_wagon_box.pngbin0 -> 22503 bytes
-rw-r--r--advtrains/advtrains_train_steam/textures/advtrains_wagon_box_inv.pngbin0 -> 347 bytes
-rw-r--r--advtrains/advtrains_train_steam/textures/advtrains_wagon_inv.pngbin0 -> 709 bytes
-rw-r--r--advtrains/advtrains_train_subway/depends.txt1
-rw-r--r--advtrains/advtrains_train_subway/init.lua34
-rw-r--r--advtrains/advtrains_train_subway/models/advtrains_subway_wagon.b3dbin0 -> 459309 bytes
-rw-r--r--advtrains/advtrains_train_subway/textures/advtrains_subway_wagon.pngbin0 -> 3618 bytes
-rw-r--r--advtrains/advtrains_train_subway/textures/advtrains_subway_wagon_inv.pngbin0 -> 900 bytes
-rw-r--r--advtrains/atc_command.txt68
-rw-r--r--advtrains/license.txt142
-rw-r--r--advtrains/license_media.txt63
-rw-r--r--advtrains/manual.pdfbin0 -> 1037362 bytes
-rw-r--r--advtrains/modpack.txt0
-rw-r--r--advtrains/readme.txt25
-rw-r--r--advtrains/screenshot.pngbin0 -> 445014 bytes
152 files changed, 4842 insertions, 0 deletions
diff --git a/advtrains/advtrains.zip b/advtrains/advtrains.zip
new file mode 100644
index 0000000..a3dab82
--- /dev/null
+++ b/advtrains/advtrains.zip
Binary files differ
diff --git a/advtrains/advtrains/api_doc.txt b/advtrains/advtrains/api_doc.txt
new file mode 100644
index 0000000..6b1aa2e
--- /dev/null
+++ b/advtrains/advtrains/api_doc.txt
@@ -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,
+ 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
+ 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)
+ return not advtrains.is_train_at_pos(pos)
+ end,
+ after_dig_node=function(pos)
+ advtrains.invalidate_all_paths()
+ advtrains.reset_trackdb_position(pos)
+ end,
+ after_place_node=function(pos)
+ advtrains.reset_trackdb_position(pos)
+ end,
+ ^- the code in these 3 default minetest API functions is required for advtrains to work, however you can add your own code
+
+ advtrains = {
+ 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
+ }
+}) \ No newline at end of file
diff --git a/advtrains/advtrains/atc.lua b/advtrains/advtrains/atc.lua
new file mode 100644
index 0000000..2a4d226
--- /dev/null
+++ b/advtrains/advtrains/atc.lua
@@ -0,0 +1,274 @@
+--atc.lua
+--registers and controls the ATC system
+
+local atc={}
+-- ATC persistence table. advtrains.atc is created by init.lua when it loads the save file.
+atc.controllers = {}
+function atc.load_data(data)
+ atc.controllers = data and data.controllers or {}
+end
+function atc.save_data()
+ return atc.controllers
+end
+--contents: {command="...", arrowconn=0-15 where arrow points}
+
+--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
+ --atprint("Called send_command at "..pts)
+ local train_id = advtrains.detector.on_node[pts]
+ if train_id then
+ if advtrains.trains[train_id] then
+ --atprint("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
+ atprint("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, node)
+ advtrains.ndb.update(pos, node)
+ 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,
+ after_dig_node=function(pos)
+ advtrains.invalidate_all_paths()
+ advtrains.ndb.clear(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
+ minetest.chat_send_all("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
+ atprint("Evaluating if statement: "..command)
+ atprint("Cond: "..(cond or "nil"))
+ atprint("Applies: "..(cond_applies and "true" or "false"))
+ atprint("Rest: "..rest)
+ --find end of conditional statement
+ local nest, pos, elsepos=0, 1
+ while nest>=0 do
+ if pos>#rest then
+ minetest.chat_send_all("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
+ atprint("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)
+
+ atprint("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
+ minetest.chat_send_all("ATC command parse error: "..command)
+ atc.train_reset_command(id)
+end
+
+
+
+--move table to desired place
+advtrains.atc=atc
diff --git a/advtrains/advtrains/couple.lua b/advtrains/advtrains/couple.lua
new file mode 100644
index 0000000..c0dea84
--- /dev/null
+++ b/advtrains/advtrains/couple.lua
@@ -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
+ atprintbm("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 atprint("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
+ atprintbm("couple step", t)
+ end,
+})
diff --git a/advtrains/advtrains/crafting.lua b/advtrains/advtrains/crafting.lua
new file mode 100644
index 0000000..5ba12ce
--- /dev/null
+++ b/advtrains/advtrains/crafting.lua
@@ -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
index 0000000..b39fe67
--- /dev/null
+++ b/advtrains/advtrains/damage.lua
@@ -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
index 0000000..dcc95d9
--- /dev/null
+++ b/advtrains/advtrains/debugitems.lua
@@ -0,0 +1,28 @@
+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,
+}
+)
diff --git a/advtrains/advtrains/depends.txt b/advtrains/advtrains/depends.txt
new file mode 100644
index 0000000..20aa884
--- /dev/null
+++ b/advtrains/advtrains/depends.txt
@@ -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
index 0000000..ecc5d58
--- /dev/null
+++ b/advtrains/advtrains/description.txt
@@ -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
index 0000000..cc7deb8
--- /dev/null
+++ b/advtrains/advtrains/helpers.lua
@@ -0,0 +1,244 @@
+--advtrains by orwell96, see readme.txt
+
+advtrains.dir_trans_tbl={
+ [0]={x=0, z=1},
+ [1]={x=1, z=2},
+ [2]={x=1, z=1},
+ [3]={x=2, z=1},
+ [4]={x=1, z=0},
+ [5]={x=2, z=-1},
+ [6]={x=1, z=-1},
+ [7]={x=1, z=-2},
+ [8]={x=0, z=-1},
+ [9]={x=-1, z=-2},
+ [10]={x=-1, z=-1},
+ [11]={x=-2, z=-1},
+ [12]={x=-1, z=0},
+ [13]={x=-2, z=1},
+ [14]={x=-1, z=1},
+ [15]={x=-1, z=2},
+}
+
+function advtrains.dirCoordSet(coord, dir)
+ local x,z
+ if advtrains.dir_trans_tbl[dir] then
+ x,z=advtrains.dir_trans_tbl[dir].x, advtrains.dir_trans_tbl[dir].z
+ else
+ error("advtrains: in helpers.lua/dirCoordSet() given dir="..(dir or "nil"))
+ end
+ return {x=coord.x+x, y=coord.y, z=coord.z+z}
+end
+function advtrains.dirToCoord(dir)
+ return advtrains.dirCoordSet({x=0, y=0, z=0}, dir)
+end
+
+function advtrains.maxN(list, expectstart)
+ local n=expectstart or 0
+ while list[n] do
+ n=n+1
+ end
+ return n-1
+end
+
+function advtrains.minN(list, expectstart)
+ local n=expectstart or 0
+ while list[n] do
+ n=n-1
+ end
+ return n+1
+end
+
+--vertical_transmit:
+--[[
+rely1, rely2 tell to which height the connections are pointed to. 1 means it will go up the next node
+
+]]
+
+function advtrains.conway(midreal, prev, drives_on)--in order prev,mid,return
+ local mid=advtrains.round_vector_floor_y(midreal)
+
+ local midnode_ok, middir1, middir2, midrely1, midrely2=advtrains.get_rail_info_at(mid, drives_on)
+ if not midnode_ok then
+ return nil
+ end
+
+ local next, chkdir, chkrely, y_offset
+ y_offset=0
+ --atprint(" in order mid1,mid2",middir1,middir2)
+ --try if it is dir1
+ local cor1=advtrains.dirCoordSet(mid, middir2)--<<<<
+ if cor1.x==prev.x and cor1.z==prev.z then--this was previous
+ next=advtrains.dirCoordSet(mid, middir1)
+ if midrely1>=1 then
+ next.y=next.y+1
+ --atprint("found midrely1 to be >=1: next is now "..(next and minetest.pos_to_string(next) or "nil"))
+ y_offset=1
+ end
+ chkdir=middir1
+ chkrely=midrely1
+ --atprint("dir2 applied next pos:",minetest.pos_to_string(next),"(chkdir is ",chkdir,")")
+ end
+ --dir2???
+ local cor2=advtrains.dirCoordSet(mid, middir1)--<<<<
+ 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
+ next=advtrains.dirCoordSet(mid, middir2)--dir2 wird überprüft, alles gut.
+ if midrely2>=1 then
+ next.y=next.y+1
+ --atprint("found midrely2 to be >=1: next is now "..(next and minetest.pos_to_string(next) or "nil"))
+ y_offset=1
+ end
+ chkdir=middir2
+ chkrely=midrely2
+ --atprint(" dir2 applied next pos:",minetest.pos_to_string(next),"(chkdir is ",chkdir,")")
+ end
+ --atprint("dir applied next pos: "..(next and minetest.pos_to_string(next) or "nil").."(chkdir is "..(chkdir or "nil")..", y-offset "..y_offset..")")
+ --is there a next
+ if not next then
+ atprint("in conway: no next rail(nil), returning!")
+ return nil
+ end
+
+ local nextnode_ok, nextdir1, nextdir2, nextrely1, nextrely2, nextrailheight=advtrains.get_rail_info_at(advtrains.round_vector_floor_y(next), drives_on)
+
+ --is it a rail?
+ if(not nextnode_ok) then
+ atprint("in conway: next "..minetest.pos_to_string(next).." not a rail, trying one node below!")
+ next.y=next.y-1
+ y_offset=y_offset-1
+
+ nextnode_ok, nextdir1, nextdir2, nextrely1, nextrely2, nextrailheight=advtrains.get_rail_info_at(advtrains.round_vector_floor_y(next), drives_on)
+ if(not nextnode_ok) then
+ atprint("in conway: one below "..minetest.pos_to_string(next).." is not a rail either, returning!")
+ return nil
+ end
+ end
+
+ --is this next rail connecting to the mid?
+ if not ( (((nextdir1+8)%16)==chkdir and nextrely1==chkrely-y_offset) or (((nextdir2+8)%16)==chkdir and nextrely2==chkrely-y_offset) ) then
+ atprint("in conway: next "..minetest.pos_to_string(next).." not connecting, trying one node below!")
+ next.y=next.y-1
+ y_offset=y_offset-1
+
+ nextnode_ok, nextdir1, nextdir2, nextrely1, nextrely2, nextrailheight=advtrains.get_rail_info_at(advtrains.round_vector_floor_y(next), drives_on)
+ if(not nextnode_ok) then
+ atprint("in conway: (at connecting if check again) one below "..minetest.pos_to_string(next).." is not a rail either, returning!")
+ return nil
+ end
+ if not ( (((nextdir1+8)%16)==chkdir and nextrely1==chkrely) or (((nextdir2+8)%16)==chkdir and nextrely2==chkrely) ) then
+ atprint("in conway: one below "..minetest.pos_to_string(next).." rail not connecting, returning!")
+ atprint(" in order mid1,2,next1,2,chkdir "..middir1.." "..middir2.." "..nextdir1.." "..nextdir2.." "..chkdir)
+ return nil
+ end
+ end
+
+ --atprint("conway found rail.")
+ return vector.add(advtrains.round_vector_floor_y(next), {x=0, y=nextrailheight, z=0}), chkdir
+end
+--TODO use this
+function advtrains.oppd(dir)
+ return ((dir+8)%16)
+end
+
+function advtrains.round_vector_floor_y(vec)
+ return {x=math.floor(vec.x+0.5), y=math.floor(vec.y), z=math.floor(vec.z+0.5)}
+end
+
+function advtrains.yawToDirection(yaw, conn1, conn2)
+ if not conn1 or not conn2 then
+ error("given nil to yawToDirection: conn1="..(conn1 or "nil").." conn2="..(conn1 or "nil"))
+ end
+ local yaw1=math.pi*(conn1/4)
+ local yaw2=math.pi*(conn2/4)
+ if advtrains.minAngleDiffRad(yaw, yaw1)<advtrains.minAngleDiffRad(yaw, yaw2) then--change to > if weird behavior
+ return conn2
+ else
+ return conn1
+ end
+end
+
+function advtrains.minAngleDiffRad(r1, r2)
+ local try1=r2-r1
+ local try2=(r2+2*math.pi)-r1
+ local try3=r2-(r1+2*math.pi)
+ if math.min(math.abs(try1), math.abs(try2), math.abs(try3))==math.abs(try1) then
+ return try1
+ end
+ if math.min(math.abs(try1), math.abs(try2), math.abs(try3))==math.abs(try2) then
+ return try2
+ end
+ if math.min(math.abs(try1), math.abs(try2), math.abs(try3))==math.abs(try3) then
+ return try3
+ end
+end
+function advtrains.dumppath(path)
+ if not path then atprint("dumppath: no path(nil)") return end
+ local min=advtrains.minN(path)
+ local max=advtrains.maxN(path)
+ for i=min, max do atprint("["..i.."] "..(path[i] and minetest.pos_to_string(path[i]) or "nil")) end
+end
+
+function advtrains.merge_tables(a, ...)
+ local new={}
+ for _,t in ipairs({a,...}) do
+ for k,v in pairs(t) do new[k]=v end
+ end
+ return new
+end
+function advtrains.yaw_from_3_positions(prev, curr, next)
+ local pts=minetest.pos_to_string
+ --atprint("p3 "..pts(prev)..pts(curr)..pts(next))
+ local prev2curr=math.atan2((curr.x-prev.x), (prev.z-curr.z))
+ local curr2next=math.atan2((next.x-curr.x), (curr.z-next.z))
+ --atprint("y3 "..(prev2curr*360/(2*math.pi)).." "..(curr2next*360/(2*math.pi)))
+ return prev2curr+(advtrains.minAngleDiffRad(prev2curr, curr2next)/2)
+end
+function advtrains.get_wagon_yaw(front, first, second, back, pct)
+ local pts=minetest.pos_to_string
+ --atprint("p "..pts(front)..pts(first)..pts(second)..pts(back))
+ local y2=advtrains.yaw_from_3_positions(second, first, front)
+ local y1=advtrains.yaw_from_3_positions(back, second, first)
+ --atprint("y "..(y1*360/(2*math.pi)).." "..(y2*360/(2*math.pi)))
+ return y1+advtrains.minAngleDiffRad(y1, y2)*pct
+end
+function advtrains.get_real_index_position(path, index)
+ if not path or not index then return end
+
+ local first_pos=path[math.floor(index)]
+ local second_pos=path[math.floor(index)+1]
+
+ if not first_pos or not second_pos then return nil end
+
+ local factor=index-math.floor(index)
+ 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,}
+ return actual_pos
+end
+function advtrains.pos_median(pos1, pos2)
+ 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}
+end
+function advtrains.abs_ceil(i)
+ return math.ceil(math.abs(i))*math.sign(i)
+end
+
+function advtrains.serialize_inventory(inv)
+ local ser={}
+ local liszts=inv:get_lists()
+ for lisztname, liszt in pairs(liszts) do
+ ser[lisztname]={}
+ for idx, item in ipairs(liszt) do
+ local istring=item:to_string()
+ if istring~="" then
+ ser[lisztname][idx]=istring
+ end
+ end
+ end
+ return minetest.serialize(ser)
+end
+function advtrains.deserialize_inventory(sers, inv)
+ local ser=minetest.deserialize(sers)
+ if ser then
+ inv:set_lists(ser)
+ return true
+ end
+ return false
+end
+
diff --git a/advtrains/advtrains/init.lua b/advtrains/advtrains/init.lua
new file mode 100644
index 0000000..c8c4b56
--- /dev/null
+++ b/advtrains/advtrains/init.lua
@@ -0,0 +1,180 @@
+--advtrains
+
+advtrains = {trains={}, wagon_save={}}
+
+advtrains.modpath = minetest.get_modpath("advtrains")
+
+local function print_concat_table(a)
+ local str=""
+ local stra=""
+ for i=1,50 do
+ t=a[i]
+ if t==nil then
+ stra=stra.."nil "
+ else
+ str=str..stra
+ stra=""
+ if type(t)=="table" then
+ if t.x and t.y and t.z then
+ str=str..minetest.pos_to_string(t)
+ else
+ str=str..dump(t)
+ end
+ elseif type(t)=="boolean" then
+ if t then
+ str=str.."true"
+ else
+ str=str.."false"
+ end
+ else
+ str=str..t
+ end
+ str=str.." "
+ end
+ end
+ return str
+end
+--atprint=function() end
+atprint=function(t, ...) minetest.log("action", "[advtrains]"..print_concat_table({t, ...})) minetest.chat_send_all("[advtrains]"..print_concat_table({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.."/trackdb_legacy.lua")
+dofile(advtrains.modpath.."/nodedb.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")
+
+--load/save
+
+advtrains.fpath=minetest.get_worldpath().."/advtrains"
+local file, err = io.open(advtrains.fpath, "r")
+if not file then
+ minetest.log("error", " Failed to read advtrains save data from file "..advtrains.fpath..": "..(err or "Unknown Error"))
+else
+ local tbl = minetest.deserialize(file:read("*a"))
+ if type(tbl) == "table" then
+ if tbl.version then
+ --congrats, we have the new save format.
+ advtrains.trains = tbl.trains
+ advtrains.wagon_save = tbl.wagon_save
+ advtrains.ndb.load_data(tbl.ndb)
+ advtrains.atc.load_data(tbl.atc)
+ --advtrains.latc.load_data(tbl.latc)
+ else
+ --oh no, its the old one...
+ advtrains.trains=tbl
+ --load ATC
+ 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"
+ atprint("Failed loading advtrains atc save file "..er)
+ else
+ local tbl = minetest.deserialize(file:read("*a"))
+ if type(tbl) == "table" then
+ advtrains.atc.controllers=tbl.controllers
+ end
+ file:close()
+ end
+ --load wagon saves
+ 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"
+ atprint("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
+ end
+ else
+ minetest.log("error", " Failed to deserialize advtrains save data: Not a table!")
+ end
+ file:close()
+end
+
+advtrains.save = function()
+ --atprint("saving")
+ advtrains.invalidate_all_paths()
+
+ -- 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
+
+ --versions:
+ -- 1 - Initial new save format.
+ local save_tbl={
+ trains = advtrains.trains,
+ wagon_save = advtrains.wagon_save,
+ atc = advtrains.atc.save_data(),
+ --latc = advtrains.latc.save_data(),
+ ndb = advtrains.ndb.save_data(),
+ version = 1,
+ }
+ local datastr = minetest.serialize(save_tbl)
+ if not datastr then
+ minetest.log("error", " Failed to serialize advtrains save data!")
+ return
+ end
+ local file, err = io.open(advtrains.fpath, "w")
+ if err then
+ minetest.log("error", " Failed to write advtrains save data to file "..advtrains.fpath..": "..(err or "Unknown Error"))
+ return
+ end
+ file:write(datastr)
+ file:close()
+end
+minetest.register_on_shutdown(advtrains.save)
+
+
+
+
diff --git a/advtrains/advtrains/lua_atc.lua b/advtrains/advtrains/lua_atc.lua
new file mode 100644
index 0000000..313d70d
--- /dev/null
+++ b/advtrains/advtrains/lua_atc.lua
@@ -0,0 +1,166 @@
+-------------
+--LUA ATC controllers
+
+local latc={}
+
+function latc.load_data(data)
+end
+function latc.save_data()
+ return stuff
+end
+
+latc.data
+latc.env_cdata
+latc.init_code=""
+latc.step_code=""
+
+advtrains.fpath_latc=minetest.get_worldpath().."/advtrains_latc"
+local file, err = io.open(advtrains.fpath_atc, "r")
+if not file then
+ local er=err or "Unknown Error"
+ atprint("Failed loading advtrains latc 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 latc.save()
+
+ local datastr = minetest.serialize({controllers = atc.controllers})
+ if not datastr then
+ minetest.log("error", " Failed to serialize latc data!")
+ return
+ end
+ local file, err = io.open(advtrains.fpath_atc, "w")
+ if err then
+ return err
+ end
+ file:write(datastr)
+ file:close()
+end
+
+--Privilege
+--Only trusted players should be enabled to build stuff which can break the server.
+--If I later decide to have multiple environments ('data' tables), I better store an owner for every controller for future reference.
+
+minetest.register_privilege("advtrains_lua_atc", { description = "Player can place and modify LUA ATC components. Grant with care! Allows to execute bad LUA code.", give_to_singleplayer = false, default= false })
+
+--Environment
+--Code from mesecons_luacontroller (credit goes to Jeija and mesecons contributors)
+
+local safe_globals = {
+ "assert", "error", "ipairs", "next", "pairs", "select",
+ "tonumber", "tostring", "type", "unpack", "_VERSION"
+}
+local function safe_print(param)
+ print(dump(param))
+end
+
+local function safe_date()
+ return(os.date("*t",os.time()))
+end
+
+-- string.rep(str, n) with a high value for n can be used to DoS
+-- the server. Therefore, limit max. length of generated string.
+local function safe_string_rep(str, n)
+ if #str * n > mesecon.setting("luacontroller_string_rep_max", 64000) then
+ debug.sethook() -- Clear hook
+ error("string.rep: string length overflow", 2)
+ end
+
+ return string.rep(str, n)
+end
+
+-- string.find with a pattern can be used to DoS the server.
+-- Therefore, limit string.find to patternless matching.
+local function safe_string_find(...)
+ if (select(4, ...)) ~= true then
+ debug.sethook() -- Clear hook
+ error("string.find: 'plain' (fourth parameter) must always be true in a LuaController")
+ end
+
+ return string.find(...)
+end
+
+latc.static_env = {
+ print = safe_print,
+ string = {
+ byte = string.byte,
+ char = string.char,
+ format = string.format,
+ len = string.len,
+ lower = string.lower,
+ upper = string.upper,
+ rep = safe_string_rep,
+ reverse = string.reverse,
+ sub = string.sub,
+ find = safe_string_find,
+ },
+ math = {
+ abs = math.abs,
+ acos = math.acos,
+ asin = math.asin,
+ atan = math.atan,
+ atan2 = math.atan2,
+ ceil = math.ceil,
+ cos = math.cos,
+ cosh = math.cosh,
+ deg = math.deg,
+ exp = math.exp,
+ floor = math.floor,
+ fmod = math.fmod,
+ frexp = math.frexp,
+ huge = math.huge,
+ ldexp = math.ldexp,
+ log = math.log,
+ log10 = math.log10,
+ max = math.max,
+ min = math.min,
+ modf = math.modf,
+ pi = math.pi,
+ pow = math.pow,
+ rad = math.rad,
+ random = math.random,
+ sin = math.sin,
+ sinh = math.sinh,
+ sqrt = math.sqrt,
+ tan = math.tan,
+ tanh = math.tanh,
+ },
+ table = {
+ concat = table.concat,
+ insert = table.insert,
+ maxn = table.maxn,
+ remove = table.remove,
+ sort = table.sort,
+ },
+ os = {
+ clock = os.clock,
+ difftime = os.difftime,
+ time = os.time,
+ datetable = safe_date,
+ },
+}
+latc.static_env._G = env
+
+for _, name in pairs(safe_globals) do
+ latc.static_env[name] = _G[name]
+end
+
+
+--The environment all code calls get is a proxy table with a metatable.
+--When an index is read:
+-- Look in static_env
+-- Look in volatile_env (user_written functions and userdata)
+-- Look in saved_env (everything that's not a function or userdata)
+--when an index is written:
+-- If in static_env, do not allow
+-- if function or userdata, volatile_env
+-- if table, see below
+-- else, save in saved_env
+
+
+
+advtrains.latc=latc
diff --git a/advtrains/advtrains/misc_nodes.lua b/advtrains/advtrains/misc_nodes.lua
new file mode 100644
index 0000000..70b18fb
--- /dev/null
+++ b/advtrains/advtrains/misc_nodes.lua
@@ -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", " 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
index 0000000..a6d9745
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_dtrack_bumper_st.b3d
Binary files 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
index 0000000..5f5b3f4
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_dtrack_bumper_st_30.b3d
Binary files 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
index 0000000..f13ae75
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_dtrack_bumper_st_45.b3d
Binary files 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
index 0000000..59a2285
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_dtrack_bumper_st_60.b3d
Binary files differ
diff --git a/advtrains/advtrains/models/advtrains_dtrack_cr.b3d b/advtrains/advtrains/models/advtrains_dtrack_cr.b3d
new file mode 100644
index 0000000..159717e
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_dtrack_cr.b3d
Binary files 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
index 0000000..09cdb1f
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_dtrack_cr_30.b3d
Binary files 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
index 0000000..176da81
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_dtrack_cr_45.b3d
Binary files 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
index 0000000..00313c8
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_dtrack_cr_60.b3d
Binary files 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
index 0000000..6762bc3
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_dtrack_detector_st.b3d
Binary files 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
index 0000000..f2d5991
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_dtrack_detector_st_30.b3d
Binary files 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
index 0000000..9ecb4a6
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_dtrack_detector_st_45.b3d
Binary files 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
index 0000000..bd102cb
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_dtrack_detector_st_60.b3d
Binary files differ
diff --git a/advtrains/advtrains/models/advtrains_dtrack_st.b3d b/advtrains/advtrains/models/advtrains_dtrack_st.b3d
new file mode 100644
index 0000000..f3e2753
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_dtrack_st.b3d
Binary files 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
index 0000000..7a35c8d
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_dtrack_st_30.b3d
Binary files 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
index 0000000..b2a1702
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_dtrack_st_45.b3d
Binary files 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
index 0000000..0a59f77
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_dtrack_st_60.b3d
Binary files differ
diff --git a/advtrains/advtrains/models/advtrains_dtrack_swlcr.b3d b/advtrains/advtrains/models/advtrains_dtrack_swlcr.b3d
new file mode 100644
index 0000000..1adc23f
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_dtrack_swlcr.b3d
Binary files 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
index 0000000..7d8373b
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_dtrack_swlcr_30.b3d
Binary files 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
index 0000000..9679b9e
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_dtrack_swlcr_45.b3d
Binary files 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
index 0000000..3efc924
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_dtrack_swlcr_60.b3d
Binary files differ
diff --git a/advtrains/advtrains/models/advtrains_dtrack_swlst.b3d b/advtrains/advtrains/models/advtrains_dtrack_swlst.b3d
new file mode 100644
index 0000000..93841a4
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_dtrack_swlst.b3d
Binary files 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
index 0000000..e9a90c7
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_dtrack_swlst_30.b3d
Binary files 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
index 0000000..49c707c
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_dtrack_swlst_45.b3d
Binary files 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
index 0000000..c9a6ffe
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_dtrack_swlst_60.b3d
Binary files differ
diff --git a/advtrains/advtrains/models/advtrains_dtrack_swrcr.b3d b/advtrains/advtrains/models/advtrains_dtrack_swrcr.b3d
new file mode 100644
index 0000000..ee29b62
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_dtrack_swrcr.b3d
Binary files 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
index 0000000..ba065e1
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_dtrack_swrcr_30.b3d
Binary files 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
index 0000000..7f9dc43
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_dtrack_swrcr_45.b3d
Binary files 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
index 0000000..b8ffa61
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_dtrack_swrcr_60.b3d
Binary files differ
diff --git a/advtrains/advtrains/models/advtrains_dtrack_swrst.b3d b/advtrains/advtrains/models/advtrains_dtrack_swrst.b3d
new file mode 100644
index 0000000..0b3e7ad
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_dtrack_swrst.b3d
Binary files 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
index 0000000..4aea19b
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_dtrack_swrst_30.b3d
Binary files 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
index 0000000..4182fe5
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_dtrack_swrst_45.b3d
Binary files 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
index 0000000..6d2c891
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_dtrack_swrst_60.b3d
Binary files differ
diff --git a/advtrains/advtrains/models/advtrains_dtrack_vst1.b3d b/advtrains/advtrains/models/advtrains_dtrack_vst1.b3d
new file mode 100644
index 0000000..c9d7427
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_dtrack_vst1.b3d
Binary files 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
index 0000000..14d438c
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_dtrack_vst1_45.b3d
Binary files differ
diff --git a/advtrains/advtrains/models/advtrains_dtrack_vst2.b3d b/advtrains/advtrains/models/advtrains_dtrack_vst2.b3d
new file mode 100644
index 0000000..c128650
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_dtrack_vst2.b3d
Binary files 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
index 0000000..263276d
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_dtrack_vst2_45.b3d
Binary files differ
diff --git a/advtrains/advtrains/models/advtrains_dtrack_vst31.b3d b/advtrains/advtrains/models/advtrains_dtrack_vst31.b3d
new file mode 100644
index 0000000..df0f383
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_dtrack_vst31.b3d
Binary files differ
diff --git a/advtrains/advtrains/models/advtrains_dtrack_vst32.b3d b/advtrains/advtrains/models/advtrains_dtrack_vst32.b3d
new file mode 100644
index 0000000..01d2978
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_dtrack_vst32.b3d
Binary files differ
diff --git a/advtrains/advtrains/models/advtrains_dtrack_vst33.b3d b/advtrains/advtrains/models/advtrains_dtrack_vst33.b3d
new file mode 100644
index 0000000..7fe418d
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_dtrack_vst33.b3d
Binary files differ
diff --git a/advtrains/advtrains/models/advtrains_modernwagon.b3d b/advtrains/advtrains/models/advtrains_modernwagon.b3d
new file mode 100644
index 0000000..aacddca
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_modernwagon.b3d
Binary files differ
diff --git a/advtrains/advtrains/models/advtrains_retrosignal_off.b3d b/advtrains/advtrains/models/advtrains_retrosignal_off.b3d
new file mode 100644
index 0000000..3d231dd
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_retrosignal_off.b3d
Binary files 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
index 0000000..da258e1
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_retrosignal_off_30.b3d
Binary files 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
index 0000000..338224a
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_retrosignal_off_45.b3d
Binary files 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
index 0000000..c560ca1
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_retrosignal_off_60.b3d
Binary files differ
diff --git a/advtrains/advtrains/models/advtrains_retrosignal_on.b3d b/advtrains/advtrains/models/advtrains_retrosignal_on.b3d
new file mode 100644
index 0000000..3d19439
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_retrosignal_on.b3d
Binary files 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
index 0000000..98f8a92
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_retrosignal_on_30.b3d
Binary files 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
index 0000000..414e121
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_retrosignal_on_45.b3d
Binary files 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
index 0000000..a51529a
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_retrosignal_on_60.b3d
Binary files differ
diff --git a/advtrains/advtrains/models/advtrains_signal.b3d b/advtrains/advtrains/models/advtrains_signal.b3d
new file mode 100644
index 0000000..7f69560
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_signal.b3d
Binary files differ
diff --git a/advtrains/advtrains/models/advtrains_signal_30.b3d b/advtrains/advtrains/models/advtrains_signal_30.b3d
new file mode 100644
index 0000000..0b949a7
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_signal_30.b3d
Binary files differ
diff --git a/advtrains/advtrains/models/advtrains_signal_45.b3d b/advtrains/advtrains/models/advtrains_signal_45.b3d
new file mode 100644
index 0000000..ccaebf4
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_signal_45.b3d
Binary files differ
diff --git a/advtrains/advtrains/models/advtrains_signal_60.b3d b/advtrains/advtrains/models/advtrains_signal_60.b3d
new file mode 100644
index 0000000..cf41e6d
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_signal_60.b3d
Binary files differ
diff --git a/advtrains/advtrains/models/advtrains_track_cr.b3d b/advtrains/advtrains/models/advtrains_track_cr.b3d
new file mode 100644
index 0000000..b0f5e4b
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_track_cr.b3d
Binary files differ
diff --git a/advtrains/advtrains/models/advtrains_track_st.b3d b/advtrains/advtrains/models/advtrains_track_st.b3d
new file mode 100644
index 0000000..10b5d90
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_track_st.b3d
Binary files 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
index 0000000..32505a1
--- /dev/null
+++ b/advtrains/advtrains/models/advtrains_track_st_45.b3d
Binary files differ
diff --git a/advtrains/advtrains/models/trackplane.b3d b/advtrains/advtrains/models/trackplane.b3d
new file mode 100644
index 0000000..b4728c3
--- /dev/null
+++ b/advtrains/advtrains/models/trackplane.b3d
Binary files differ
diff --git a/advtrains/advtrains/nodedb.lua b/advtrains/advtrains/nodedb.lua
new file mode 100644
index 0000000..0e1d836
--- /dev/null
+++ b/advtrains/advtrains/nodedb.lua
@@ -0,0 +1,232 @@
+--nodedb.lua
+--database of all nodes that have 'save_in_nodedb' field set to true in node definition
+
+
+
+--serialization format:
+--(6byte poshash) (2byte contentid)
+--contentid := (14bit nodeid, 2bit param2)
+
+local function hash_to_bytes(x)
+ local aH = math.floor(x / 1099511627776) % 256;
+ local aL = math.floor(x / 4294967296) % 256;
+ local bH = math.floor(x / 16777216) % 256;
+ local bL = math.floor(x / 65536) % 256;
+ local cH = math.floor(x / 256) % 256;
+ local cL = math.floor(x ) % 256;
+ return(string.char(aH, aL, bH, bL, cH, cL));
+end
+local function cid_to_bytes(x)
+ local cH = math.floor(x / 256) % 256;
+ local cL = math.floor(x ) % 256;
+ return(string.char(cH, cL));
+end
+local function bytes_to_hash(bytes)
+ local t={string.byte(bytes,1,-1)}
+ local n =
+ t[1] * 1099511627776 +
+ t[2] * 4294967296 +
+ t[3] * 16777216 +
+ t[4] * 65536 +
+ t[5] * 256 +
+ t[6]
+ return n
+end
+local function bytes_to_cid(bytes)
+ local t={string.byte(bytes,1,-1)}
+ local n =
+ t[1] * 256 +
+ t[2]
+ return n
+end
+local function l2b(x)
+ return x%4
+end
+local function u14b(x)
+ return math.floor(x/4)
+end
+local ndb={}
+
+--local variables for performance
+local ndb_nodeids={}
+local ndb_nodes={}
+
+--load
+--nodeids get loaded by advtrains init.lua and passed here
+function ndb.load_data(data)
+ ndb_nodeids = data and data.nodeids or {}
+end
+
+local path=minetest.get_worldpath().."/advtrains_ndb"
+
+local file, err = io.open(path, "r")
+if not file then
+ atprint("load ndb failed: ", err or "Unknown Error")
+else
+ local cnt=0
+ local hst=file:read(6)
+ local cid=file:read(2)
+ while hst and #hst==6 and cid and #cid==2 do
+ ndb_nodes[bytes_to_hash(hst)]=bytes_to_cid(cid)
+ cnt=cnt+1
+ hst=file:read(6)
+ cid=file:read(2)
+ end
+ atprint("nodedb: read", cnt, "nodes.")
+ file:close()
+end
+
+--save
+function ndb.save_data()
+ local file, err = io.open(path, "w")
+ if not file then
+ atprint("load ndb failed: ", err or "Unknown Error")
+ else
+ for hash, cid in pairs(ndb_nodes) do
+ file:write(hash_to_bytes(hash))
+ file:write(cid_to_bytes(cid))
+ end
+ file:close()
+ end
+ return {nodeids = ndb_nodeids}
+end
+
+--function to get node. track database is not helpful here.
+function ndb.get_node_or_nil(pos)
+ local node=minetest.get_node_or_nil(pos)
+ if node then
+ return node
+ else
+ --maybe we have the node in the database...
+ local cid=ndb_nodes[minetest.hash_node_position(pos)]
+ if cid then
+ local nodeid = ndb_nodeids[u14b(cid)]
+ if nodeid then
+ --atprint("ndb.get_node_or_nil",pos,"found node",nodeid,"cid",cid,"par2",l2b(cid))
+ return {name=nodeid, param2 = l2b(cid)}
+ end
+ end
+ end
+ atprint("ndb.get_node_or_nil",pos,"not found")
+end
+function ndb.get_node(pos)
+ local n=ndb.get_node_or_nil(pos)
+ if not n then
+ return {name="ignore", param2=0}
+ end
+ return n
+end
+
+function ndb.swap_node(pos, node)
+ minetest.swap_node(pos, node)
+ ndb.update(pos, node)
+end
+
+function ndb.update(pos, pnode)
+ local node = pnode or minetest.get_node_or_nil(pos)
+ if not node or node.name=="ignore" then return end
+ if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].groups.save_in_nodedb then
+ local nid
+ for tnid, nname in pairs(ndb_nodeids) do
+ if nname==node.name then
+ nid=tnid
+ end
+ end
+ if not nid then
+ nid=#ndb_nodeids+1
+ ndb_nodeids[nid]=node.name
+ end
+ local hash = minetest.hash_node_position(pos)
+ ndb_nodes[hash] = (nid * 4) + (l2b(node.param2 or 0))
+ --atprint("nodedb: updating node", pos, "stored nid",nid,"assigned",ndb_nodeids[nid],"resulting cid",ndb_nodes[hash])
+ else
+ --at this position there is no longer a node that needs to be tracked.
+ local hash = minetest.hash_node_position(pos)
+ ndb_nodes[hash] = nil
+ end
+end
+
+function ndb.clear(pos)
+ local hash = minetest.hash_node_position(pos)
+ ndb_nodes[hash] = nil
+end
+
+
+--get_node with pseudoload. now we only need track data, so we can use the trackdb as second fallback
+--nothing new will be saved inside the trackdb.
+--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 rdp=advtrains.round_vector_floor_y(pos)
+
+ local node=ndb.get_node_or_nil(rdp)
+
+ --still no node?
+ --advtrains.trackdb is nil when there's no data available.
+ if not node then
+ if advtrains.trackdb then
+ --try raildb (see trackdb_legacy.lua)
+ local dbe=(advtrains.trackdb[rdp.y] and advtrains.trackdb[rdp.y][rdp.x] and advtrains.trackdb[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
+ end
+ end
+ return nil
+ 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)
+
+ return true, conn1, conn2, rely1, rely2, railheight
+end
+
+
+minetest.register_abm({
+ name = "advtrains:nodedb_on_load_update",
+ nodenames = {"group:save_in_nodedb"},
+ run_at_every_load = true,
+ action = function(pos, node)
+ local cid=ndb_nodes[minetest.hash_node_position(pos)]
+ if cid then
+ --if in database, detect changes and apply.
+ local nodeid = ndb_nodeids[u14b(cid)]
+ local param2 = l2b(cid)
+ if not nodeid then
+ --something went wrong
+ atprint("nodedb: lbm nid not found", pos, "with nid", u14b(cid), "param2", param2, "cid is", cid)
+ ndb.update(pos, node)
+ else
+ if (nodeid~=node.name or param2~=node.param2) then
+ atprint("nodedb: lbm replaced", pos, "with nodeid", nodeid, "param2", param2, "cid is", cid)
+ minetest.swap_node(pos, {name=nodeid, param2 = param2})
+ end
+ end
+ else
+ --if not in database, take it.
+ atprint("nodedb: ", pos, "not in database")
+ ndb.update(pos, node)
+ end
+ end,
+ interval=10,
+ chance=1,
+ })
+
+minetest.register_on_dignode(function(pos, oldnode, digger)
+ ndb.clear(pos)
+end)
+
+function ndb.t()
+ return ndb_nodes[141061759008906]
+end
+
+advtrains.ndb=ndb
+
diff --git a/advtrains/advtrains/signals.lua b/advtrains/advtrains/signals.lua
new file mode 100644
index 0000000..59c5af1
--- /dev/null
+++ b/advtrains/advtrains/signals.lua
@@ -0,0 +1,78 @@
+--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,
+ save_in_nodedb=1,
+ },
+ mesecons = {effector = {
+ ["action_"..f] = function (pos, node)
+ advtrains.np.swap_node(pos, {name = "advtrains:retrosignal_"..f..rotation, param2 = node.param2})
+ end
+ }},
+ on_rightclick=function(pos, node, clicker)
+ advtrains.np.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,
+ save_in_nodedb=1,
+ },
+ 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
index 0000000..9e997e4
--- /dev/null
+++ b/advtrains/advtrains/textures/advtrains_couple.png
Binary files differ
diff --git a/advtrains/advtrains/textures/advtrains_discouple.png b/advtrains/advtrains/textures/advtrains_discouple.png
new file mode 100644
index 0000000..b27c4fb
--- /dev/null
+++ b/advtrains/advtrains/textures/advtrains_discouple.png
Binary files 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
index 0000000..31c2b30
--- /dev/null
+++ b/advtrains/advtrains/textures/advtrains_dtrack_atc_placer.png
Binary files 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
index 0000000..27191fe
--- /dev/null
+++ b/advtrains/advtrains/textures/advtrains_dtrack_bumper_placer.png
Binary files 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
index 0000000..e6c6ad6
--- /dev/null
+++ b/advtrains/advtrains/textures/advtrains_dtrack_detector_placer.png
Binary files differ
diff --git a/advtrains/advtrains/textures/advtrains_dtrack_placer.png b/advtrains/advtrains/textures/advtrains_dtrack_placer.png
new file mode 100644
index 0000000..7bef8a9
--- /dev/null
+++ b/advtrains/advtrains/textures/advtrains_dtrack_placer.png
Binary files differ
diff --git a/advtrains/advtrains/textures/advtrains_dtrack_rail.png b/advtrains/advtrains/textures/advtrains_dtrack_rail.png
new file mode 100644
index 0000000..1cf7f83
--- /dev/null
+++ b/advtrains/advtrains/textures/advtrains_dtrack_rail.png
Binary files 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
index 0000000..d171985
--- /dev/null
+++ b/advtrains/advtrains/textures/advtrains_dtrack_rail_atc.png
Binary files 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
index 0000000..4f09b35
--- /dev/null
+++ b/advtrains/advtrains/textures/advtrains_dtrack_rail_detector_on.png
Binary files differ
diff --git a/advtrains/advtrains/textures/advtrains_dtrack_slopeplacer.png b/advtrains/advtrains/textures/advtrains_dtrack_slopeplacer.png
new file mode 100644
index 0000000..1d456b0
--- /dev/null
+++ b/advtrains/advtrains/textures/advtrains_dtrack_slopeplacer.png
Binary files differ
diff --git a/advtrains/advtrains/textures/advtrains_platform.png b/advtrains/advtrains/textures/advtrains_platform.png
new file mode 100644
index 0000000..5ba9663
--- /dev/null
+++ b/advtrains/advtrains/textures/advtrains_platform.png
Binary files differ
diff --git a/advtrains/advtrains/textures/advtrains_retrosignal.png b/advtrains/advtrains/textures/advtrains_retrosignal.png
new file mode 100644
index 0000000..141198d
--- /dev/null
+++ b/advtrains/advtrains/textures/advtrains_retrosignal.png
Binary files differ
diff --git a/advtrains/advtrains/textures/advtrains_retrosignal_inv.png b/advtrains/advtrains/textures/advtrains_retrosignal_inv.png
new file mode 100644
index 0000000..1036594
--- /dev/null
+++ b/advtrains/advtrains/textures/advtrains_retrosignal_inv.png
Binary files differ
diff --git a/advtrains/advtrains/textures/advtrains_signal_inv.png b/advtrains/advtrains/textures/advtrains_signal_inv.png
new file mode 100644
index 0000000..ed64ed9
--- /dev/null
+++ b/advtrains/advtrains/textures/advtrains_signal_inv.png
Binary files differ
diff --git a/advtrains/advtrains/textures/advtrains_signal_off.png b/advtrains/advtrains/textures/advtrains_signal_off.png
new file mode 100644
index 0000000..8046e52
--- /dev/null
+++ b/advtrains/advtrains/textures/advtrains_signal_off.png
Binary files differ
diff --git a/advtrains/advtrains/textures/advtrains_signal_on.png b/advtrains/advtrains/textures/advtrains_signal_on.png
new file mode 100644
index 0000000..5228bb3
--- /dev/null
+++ b/advtrains/advtrains/textures/advtrains_signal_on.png
Binary files differ
diff --git a/advtrains/advtrains/textures/advtrains_track_cr.png b/advtrains/advtrains/textures/advtrains_track_cr.png
new file mode 100644
index 0000000..40f0cc5
--- /dev/null
+++ b/advtrains/advtrains/textures/advtrains_track_cr.png
Binary files 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
index 0000000..54966b3
--- /dev/null
+++ b/advtrains/advtrains/textures/advtrains_track_cr_45.png
Binary files differ
diff --git a/advtrains/advtrains/textures/advtrains_track_placer.png b/advtrains/advtrains/textures/advtrains_track_placer.png
new file mode 100644
index 0000000..03e17ed
--- /dev/null
+++ b/advtrains/advtrains/textures/advtrains_track_placer.png
Binary files differ
diff --git a/advtrains/advtrains/textures/advtrains_track_st.png b/advtrains/advtrains/textures/advtrains_track_st.png
new file mode 100644
index 0000000..5ad7e4f
--- /dev/null
+++ b/advtrains/advtrains/textures/advtrains_track_st.png
Binary files 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
index 0000000..63b4c96
--- /dev/null
+++ b/advtrains/advtrains/textures/advtrains_track_st_45.png
Binary files differ
diff --git a/advtrains/advtrains/textures/advtrains_track_swlcr.png b/advtrains/advtrains/textures/advtrains_track_swlcr.png
new file mode 100644
index 0000000..d9b5c0b
--- /dev/null
+++ b/advtrains/advtrains/textures/advtrains_track_swlcr.png
Binary files 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
index 0000000..f098fc9
--- /dev/null
+++ b/advtrains/advtrains/textures/advtrains_track_swlcr_45.png
Binary files differ
diff --git a/advtrains/advtrains/textures/advtrains_track_swlst.png b/advtrains/advtrains/textures/advtrains_track_swlst.png
new file mode 100644
index 0000000..314bd2d
--- /dev/null
+++ b/advtrains/advtrains/textures/advtrains_track_swlst.png
Binary files 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
index 0000000..765d0ec
--- /dev/null
+++ b/advtrains/advtrains/textures/advtrains_track_swlst_45.png
Binary files differ
diff --git a/advtrains/advtrains/textures/advtrains_track_swrcr.png b/advtrains/advtrains/textures/advtrains_track_swrcr.png
new file mode 100644
index 0000000..f74e1bc
--- /dev/null
+++ b/advtrains/advtrains/textures/advtrains_track_swrcr.png
Binary files 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
index 0000000..fa432aa
--- /dev/null
+++ b/advtrains/advtrains/textures/advtrains_track_swrcr_45.png
Binary files differ
diff --git a/advtrains/advtrains/textures/advtrains_track_swrst.png b/advtrains/advtrains/textures/advtrains_track_swrst.png
new file mode 100644
index 0000000..06ea29e
--- /dev/null
+++ b/advtrains/advtrains/textures/advtrains_track_swrst.png
Binary files 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
index 0000000..be477b7
--- /dev/null
+++ b/advtrains/advtrains/textures/advtrains_track_swrst_45.png
Binary files differ
diff --git a/advtrains/advtrains/textures/advtrains_trackworker.png b/advtrains/advtrains/textures/advtrains_trackworker.png
new file mode 100644
index 0000000..b50bcae
--- /dev/null
+++ b/advtrains/advtrains/textures/advtrains_trackworker.png
Binary files differ
diff --git a/advtrains/advtrains/textures/drwho_screwdriver.png b/advtrains/advtrains/textures/drwho_screwdriver.png
new file mode 100644
index 0000000..b50bcae
--- /dev/null
+++ b/advtrains/advtrains/textures/drwho_screwdriver.png
Binary files differ
diff --git a/advtrains/advtrains/trackdb_legacy.lua b/advtrains/advtrains/trackdb_legacy.lua
new file mode 100644
index 0000000..99349e8
--- /dev/null
+++ b/advtrains/advtrains/trackdb_legacy.lua
@@ -0,0 +1,27 @@
+--trackdb_legacy.lua
+--loads the (old) track database. the only use for this is to provide data for rails that haven't been written into the ndb database.
+--nothing will be saved.
+--if the user thinks that he has loaded every track in his world at least once, he can delete the track database.
+
+--trackdb[[y][x][z]={conn1, conn2, rely1, rely2, railheight}
+
+
+--trackdb keeps its own save file.
+advtrains.fpath_tdb=minetest.get_worldpath().."/advtrains_trackdb2"
+local file, err = io.open(advtrains.fpath_tdb, "r")
+if not file then
+ atprint("Not loading a trackdb file.")
+else
+ local tbl = minetest.deserialize(file:read("*a"))
+ if type(tbl) == "table" then
+ advtrains.trackdb=tbl
+ atprint("Loaded trackdb file.")
+ end
+ file:close()
+end
+
+
+
+
+
+
diff --git a/advtrains/advtrains/trackplacer.lua b/advtrains/advtrains/trackplacer.lua
new file mode 100644
index 0000000..1cb7680
--- /dev/null
+++ b/advtrains/advtrains/trackplacer.lua
@@ -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
+ advtrains.ndb.swap_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
+ advtrains.ndb.swap_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)
+ advtrains.ndb.swap_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)
+ advtrains.ndb.swap_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)
+ advtrains.ndb.swap_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, "^(.+)_([^_]+)(_[^_]+)$")
+ --atprint(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
+ advtrains.ndb.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
+ advtrains.ndb.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, "^(.+)_([^_]+)(_[^_]+)$")
+ --atprint(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]
+ advtrains.ndb.swap_node(pos, {name=nnprefix.."_"..nextsuffix..rotation, param2=node.param2})
+ --invalidate trains
+ advtrains.invalidate_all_paths()
+ else
+ atprint(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
index 0000000..1108a06
--- /dev/null
+++ b/advtrains/advtrains/tracks.lua
@@ -0,0 +1,733 @@
+--advtrains by orwell96, see readme.txt
+
+--dev-time settings:
+--EDIT HERE
+--If the old non-model rails on straight tracks should be replaced by the new...
+--false: no
+--true: yes
+advtrains.register_replacement_lbms=false
+
+--[[TracksDefinition
+nodename_prefix
+texture_prefix
+description
+common={}
+straight={}
+straight45={}
+curve={}
+curve45={}
+lswitchst={}
+lswitchst45={}
+rswitchst={}
+rswitchst45={}
+lswitchcr={}
+lswitchcr45={}
+rswitchcr={}
+rswitchcr45={}
+vert1={
+ --you'll probably want to override mesh here
+}
+vert2={
+ --you'll probably want to override mesh here
+}
+]]--
+advtrains.all_tracktypes={}
+
+--definition preparation
+local function conns(c1, c2, r1, r2, rh, rots) return {conn1=c1, conn2=c2, rely1=r1, rely2=r2, railheight=rh} end
+
+local ap={}
+ap.t_30deg={
+ regstep=1,
+ variant={
+ st=conns(0,8),
+ cr=conns(0,7),
+ swlst=conns(0,8),
+ swlcr=conns(0,7),
+ swrst=conns(0,8),
+ swrcr=conns(0,9),
+ vst1=conns(8,0,0,0.5,0.25),
+ vst2=conns(8,0,0.5,1,0.75),
+ vst31=conns(8,0,0,0.33,0.16),
+ vst32=conns(8,0,0.33,0.66,0.5),
+ vst33=conns(8,0,0.66,1,0.83),
+ },
+ description={
+ st="straight",
+ cr="curve",
+ swlst="left switch (straight)",
+ swlcr="left switch (curve)",
+ swrst="right switch (straight)",
+ swrcr="right switch (curve)",
+ vst1="steep uphill 1/2",
+ vst2="steep uphill 2/2",
+ vst31="uphill 1/3",
+ vst32="uphill 2/3",
+ vst33="uphill 3/3",
+ },
+ switch={
+ swlst="swlcr",
+ swlcr="swlst",
+ swrst="swrcr",
+ swrcr="swrst",
+ },
+ switchmc={
+ swlst="on",
+ swlcr="off",
+ swrst="on",
+ swrcr="off",
+ },
+ regtp=true,
+ trackplacer={
+ st=true,
+ cr=true,
+ },
+ tpsingle={
+ st=true,
+ },
+ tpdefault="st",
+ trackworker={
+ ["swrcr"]="st",
+ ["swrst"]="st",
+ ["st"]="cr",
+ ["cr"]="swlst",
+ ["swlcr"]="swrcr",
+ ["swlst"]="swrst",
+ },
+ regsp=true,
+ slopenodes={
+ vst1=true, vst2=true,
+ vst31=true, vst32=true, vst33=true,
+ },
+ slopeplacer={
+ [2]={"vst1", "vst2"},
+ [3]={"vst31", "vst32", "vst33"},
+ max=3,--highest entry
+ },
+ slopeplacer_45={
+ [2]={"vst1_45", "vst2_45"},
+ max=2,
+ },
+ rotation={"", "_30", "_45", "_60"},
+ increativeinv={},
+}
+ap.t_30deg_straightonly={
+ regstep=1,
+ variant={
+ st=conns(0,8),
+ },
+ description={
+ st="straight",
+ },
+ switch={
+ },
+ switchmc={
+ },
+ regtp=true,
+ trackplacer={
+ },
+ tpsingle={
+ },
+ tpdefault="st",
+ trackworker={
+ ["st"]="st",
+ },
+ slopenodes={},
+ rotation={"", "_30", "_45", "_60"},
+ increativeinv={st},
+}
+ap.t_30deg_straightonly_noplacer={
+ regstep=1,
+ variant={
+ st=conns(0,8),
+ },
+ description={
+ st="straight",
+ },
+ switch={
+ },
+ switchmc={
+ },
+ regtp=false,
+ trackplacer={
+ },
+ tpsingle={
+ },
+ tpdefault="st",
+ trackworker={
+ ["st"]="st",
+ },
+ slopenodes={},
+ rotation={"", "_30", "_45", "_60"},
+ increativeinv={st},
+}
+ap.t_45deg={
+ regstep=2,
+ variant={
+ st=conns(0,8),
+ cr=conns(0,6),
+ swlst=conns(0,8),
+ swlcr=conns(0,6),
+ swrst=conns(0,8),
+ swrcr=conns(0,10),
+ vst1=conns(8,0,0,0.5,0.25),
+ vst2=conns(8,0,0.5,1,0.75),
+ },
+ description={
+ st="straight",
+ cr="curve",
+ swlst="left switch (straight)",
+ swlcr="left switch (curve)",
+ swrst="right switch (straight)",
+ swrcr="right switch (curve)",
+ vst1="vertical lower node",
+ vst2="vertical upper node",
+ },
+ switch={
+ swlst="swlcr",
+ swlcr="swlst",
+ swrst="swrcr",
+ swrcr="swrst",
+ },
+ switchmc={
+ swlst="on",
+ swlcr="off",
+ swrst="on",
+ swrcr="off",
+ },
+ regtp=true,
+ trackplacer={
+ st=true,
+ cr=true,
+ },
+ tpsingle={
+ st=true,
+ },
+ tpdefault="st",
+ trackworker={
+ ["swrcr"]="st",
+ ["swrst"]="st",
+ ["st"]="cr",
+ ["cr"]="swlst",
+ ["swlcr"]="swrcr",
+ ["swlst"]="swrst",
+ },
+ slopenodes={},
+ rotation={"", "_45"},
+ increativeinv={vst1=true, vst2=true}
+}
+advtrains.trackpresets = ap
+
+--definition format: ([] optional)
+--[[{
+ nodename_prefix
+ texture_prefix
+ [shared_texture]
+ models_prefix
+ models_suffix (with dot)
+ [shared_model]
+ formats={
+ st,cr,swlst,swlcr,swrst,swrcr,vst1,vst2
+ (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)
+ }
+ common={} change something on common rail appearance
+}]]
+function advtrains.register_tracks(tracktype, def, preset)
+ local function make_switchfunc(suffix_target, mesecon_state)
+ local switchfunc=function(pos, node)
+ advtrains.ndb.swap_node(pos, {name=def.nodename_prefix.."_"..suffix_target, param2=node.param2})
+ end
+ return switchfunc, {effector = {
+ ["action_"..mesecon_state] = switchfunc,
+ rules=advtrains.meseconrules
+ }}
+ end
+ local function make_overdef(suffix, rotation, conns, switchfunc, mesecontbl, in_creative_inv, drop_slope)
+ local img_suffix=suffix..rotation
+ return {
+ mesh = def.shared_model or (def.models_prefix.."_"..img_suffix..def.models_suffix),
+ tiles = {def.shared_texture or (def.texture_prefix.."_"..img_suffix..".png")},
+ --inventory_image = def.texture_prefix.."_"..img_suffix..".png",
+ --wield_image = def.texture_prefix.."_"..img_suffix..".png",
+ description=def.description.."("..preset.description[suffix]..rotation..")",
+ connect1=conns.conn1,
+ connect2=conns.conn2,
+ rely1=conns.rely1 or 0,
+ rely2=conns.rely2 or 0,
+ railheight=conns.railheight or 0,
+
+ on_rightclick=switchfunc,
+ groups = {
+ attached_node=1,
+ ["advtrains_track_"..tracktype]=1,
+ save_in_nodedb=1,
+ dig_immediate=2,
+ not_in_creative_inventory=(not in_creative_inv and 1 or nil),
+ not_blocking_trains=1,
+ },
+ mesecons=mesecontbl,
+ drop = increativeinv and def.nodename_prefix.."_"..suffix..rotation or (drop_slope and def.nodename_prefix.."_slopeplacer" or def.nodename_prefix.."_placer"),
+ }
+ end
+ local function cycle_conns(conns, rotid)
+ local add=(rotid-1)*preset.regstep
+ return {
+ conn1=(conns.conn1+add)%16,
+ conn2=(conns.conn2+add)%16,
+ rely1=conns.rely1 or 0,
+ rely2=conns.rely2 or 0,
+ railheight=conns.railheight or 0,
+ }
+ end
+ local common_def=advtrains.merge_tables({
+ description = def.description,
+ drawtype = "mesh",
+ paramtype="light",
+ paramtype2="facedir",
+ walkable = false,
+ selection_box = {
+ type = "fixed",
+ fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
+ },
+ rely1=0,
+ rely2=0,
+ railheight=0,
+ drop=def.nodename_prefix.."_placer",
+ can_dig=function(pos)
+ return not advtrains.is_train_at_pos(pos)
+ end,
+ after_dig_node=function(pos)
+ advtrains.invalidate_all_paths()
+ advtrains.ndb.update(pos)
+ end,
+ after_place_node=function(pos)
+ advtrains.ndb.update(pos)
+ end,
+ }, def.common or {})
+ --make trackplacer base def
+ advtrains.trackplacer.register_tracktype(def.nodename_prefix, preset.tpdefault)
+ if preset.regtp then
+ advtrains.trackplacer.register_track_placer(def.nodename_prefix, def.texture_prefix, def.description)
+ end
+ if preset.regsp then
+ advtrains.slope.register_placer(def, preset)
+ end
+ for suffix, conns in pairs(preset.variant) do
+ for rotid, rotation in ipairs(preset.rotation) do
+ if not def.formats[suffix] or def.formats[suffix][rotid] then
+ local switchfunc, mesecontbl
+ if preset.switch[suffix] then
+ switchfunc, mesecontbl=make_switchfunc(preset.switch[suffix]..rotation, preset.switchmc[suffix])
+ end
+ local adef={}
+ if def.get_additional_definiton then
+ adef=def.get_additional_definiton(def, preset, suffix, rotation)
+ end
+
+ minetest.register_node(def.nodename_prefix.."_"..suffix..rotation, advtrains.merge_tables(
+ common_def,
+ make_overdef(
+ suffix, rotation,
+ cycle_conns(conns, rotid),
+ switchfunc, mesecontbl, preset.increativeinv[suffix], preset.slopenodes[suffix]
+ ),
+ adef
+ )
+ )
+ --trackplacer
+ if preset.regtp then
+ if preset.trackplacer[suffix] then
+ advtrains.trackplacer.add_double_conn(def.nodename_prefix, suffix, rotation, cycle_conns(conns, rotid))
+ end
+ if preset.tpsingle[suffix] then
+ advtrains.trackplacer.add_single_conn(def.nodename_prefix, suffix, rotation, cycle_conns(conns, rotid))
+ end
+ end
+ advtrains.trackplacer.add_worked(def.nodename_prefix, suffix, rotation, preset.trackworker[suffix])
+ end
+ end
+ end
+ advtrains.all_tracktypes[tracktype]=true
+end
+
+
+function advtrains.is_track_and_drives_on(nodename, drives_on_p)
+ if not minetest.registered_nodes[nodename] then
+ return false
+ end
+ local nodedef=minetest.registered_nodes[nodename]
+ for k,v in pairs(drives_on_p) do
+ if nodedef.groups["advtrains_track_"..k] then
+ return true
+ end
+ end
+ return false
+end
+
+function advtrains.get_track_connections(name, param2)
+ local nodedef=minetest.registered_nodes[name]
+ if not nodedef then atprint(" get_track_connections couldn't find nodedef for nodename "..(name or "nil")) return 0, 8, 0, 0, 0 end
+ local noderot=param2
+ if not param2 then noderot=0 end
+ if noderot > 3 then atprint(" get_track_connections: rail has invaild param2 of "..noderot) noderot=0 end
+
+ local tracktype
+ for k,_ in pairs(nodedef.groups) do
+ local tt=string.match(k, "^advtrains_track_(.+)$")
+ if tt then
+ tracktype=tt
+ end
+ end
+ return (nodedef.connect1 + 4 * noderot)%16, (nodedef.connect2 + 4 * noderot)%16, nodedef.rely1 or 0, nodedef.rely2 or 0, nodedef.railheight or 0, tracktype
+end
+
+--detector code
+--holds a table with nodes on which trains are on.
+
+advtrains.detector = {}
+advtrains.detector.on_node = {}
+advtrains.detector.on_node_restore = {}
+--set if paths were invalidated before. tells trainlogic.lua to call advtrains.detector.finalize_restore()
+advtrains.detector.clean_step_before = false
+
+--when train enters a node, call this
+--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).
+function advtrains.detector.enter_node(pos, train_id)
+ local pts = minetest.pos_to_string(advtrains.round_vector_floor_y(pos))
+ --atprint("enterNode "..pts.." "..sid(train_id))
+ if advtrains.detector.on_node[pts] then
+ if advtrains.trains[advtrains.detector.on_node[pts]] then
+ --atprint(""..pts.." already occupied")
+ return false
+ else
+ advtrains.detector.leave_node(pos, advtrains.detector.on_node[pts])
+ end
+ end
+ advtrains.detector.on_node[pts]=train_id
+ if advtrains.detector.on_node_restore[pts]==train_id then
+ advtrains.detector.on_node_restore[pts]=nil
+ else
+ advtrains.detector.call_enter_callback(advtrains.round_vector_floor_y(pos), train_id)
+ end
+ return true
+end
+function advtrains.detector.leave_node(pos, train_id)
+ local pts = minetest.pos_to_string(advtrains.round_vector_floor_y(pos))
+ --atprint("leaveNode "..pts.." "..sid(train_id))
+ if not advtrains.detector.on_node[pts] then
+ --atprint(""..pts.." leave: nothing here")
+ return false
+ end
+ if advtrains.detector.on_node[pts]==train_id then
+ advtrains.detector.call_leave_callback(advtrains.round_vector_floor_y(pos), train_id)
+ advtrains.detector.on_node[pts]=nil
+ else
+ if advtrains.trains[advtrains.detector.on_node[pts]] then
+ --atprint(""..pts.." occupied by another train")
+ return false
+ else
+ advtrains.detector.leave_node(pos, advtrains.detector.on_node[pts])
+ return false
+ end
+ end
+ return true
+end
+--called immediately before invalidating paths
+function advtrains.detector.setup_restore()
+ --atprint("setup_restore")
+ -- don't execute if it already has been called. For some reason it gets called twice...
+ if advtrains.detector.clean_step_before then
+ return
+ end
+ advtrains.detector.on_node_restore={}
+ for k, v in pairs(advtrains.detector.on_node) do
+ advtrains.detector.on_node_restore[k]=v
+ end
+ advtrains.detector.on_node = {}
+ advtrains.detector.clean_step_before = true
+end
+--called one step after invalidating paths, when all trains have restored their path and called enter_node for their contents.
+function advtrains.detector.finalize_restore()
+ --atprint("finalize_restore")
+ for pts, train_id in pairs(advtrains.detector.on_node_restore) do
+ --atprint("called leave callback "..pts.." "..train_id)
+ advtrains.detector.call_leave_callback(minetest.string_to_pos(pts), train_id)
+ end
+ advtrains.detector.on_node_restore = {}
+ advtrains.detector.clean_step_before = false
+end
+function advtrains.detector.call_enter_callback(pos, train_id)
+ --atprint("instructed to call enter calback")
+
+ local node = minetest.get_node(pos) --this spares the check if node is nil, it has a name in any case
+ local mregnode=minetest.registered_nodes[node.name]
+ if mregnode and mregnode.advtrains and mregnode.advtrains.on_train_enter then
+ mregnode.advtrains.on_train_enter(pos, train_id)
+ end
+
+ --atc code wants to be notified too
+ advtrains.atc.trigger_controller_train_enter(pos, train_id)
+end
+function advtrains.detector.call_leave_callback(pos, train_id)
+ --atprint("instructed to call leave calback")
+
+ local node = minetest.get_node(pos) --this spares the check if node is nil, it has a name in any case
+ local mregnode=minetest.registered_nodes[node.name]
+ if mregnode and mregnode.advtrains and mregnode.advtrains.on_train_leave then
+ mregnode.advtrains.on_train_leave(pos, train_id)
+ end
+end
+
+-- slope placer. Defined in register_tracks.
+--crafted with rail and gravel
+local sl={}
+function sl.register_placer(def, preset)
+ minetest.register_craftitem(def.nodename_prefix.."_slopeplacer",{
+ description = def.description.." Slope",
+ inventory_image = def.texture_prefix.."_slopeplacer.png",
+ wield_image = def.texture_prefix.."_slopeplacer.png",
+ groups={},
+ on_place = sl.create_slopeplacer_on_place(def, preset)
+ })
+end
+--(itemstack, placer, pointed_thing)
+function sl.create_slopeplacer_on_place(def, preset)
+ return function(istack, player, pt)
+ if not pt.type=="node" then
+ minetest.chat_send_player(player:get_player_name(), "Can't place: not pointing at node")
+ return istack
+ end
+ local pos=pt.above
+ if not pos then
+ minetest.chat_send_player(player:get_player_name(), "Can't place: not pointing at node")
+ return istack
+ end
+ local node=minetest.get_node(pos)
+ if not minetest.registered_nodes[node.name] or not minetest.registered_nodes[node.name].buildable_to then
+ minetest.chat_send_player(player:get_player_name(), "Can't place: space occupied!")
+ return istack
+ end
+ if minetest.is_protected(pos, player:get_player_name()) then
+ minetest.chat_send_player(player:get_player_name(), "Can't place: protected position!")
+ return istack
+ end
+ --determine player orientation (only horizontal component)
+ --get_look_horizontal may not be available
+ local yaw=player.get_look_horizontal and player:get_look_horizontal() or (player:get_look_yaw() - math.pi/2)
+
+ --rounding unit vectors is a nice way for selecting 1 of 8 directions since sin(30°) is 0.5.
+ dirvec={x=math.floor(math.sin(-yaw)+0.5), y=0, z=math.floor(math.cos(-yaw)+0.5)}
+ --translate to direction to look up inside the preset table
+ local param2, rot45=({
+ [-1]={
+ [-1]=2,
+ [0]=3,
+ [1]=3,
+ },
+ [0]={
+ [-1]=2,
+ [1]=0,
+ },
+ [1]={
+ [-1]=1,
+ [0]=1,
+ [1]=0,
+ },
+ })[dirvec.x][dirvec.z], dirvec.x~=0 and dirvec.z~=0
+ local lookup=preset.slopeplacer
+ if rot45 then lookup=preset.slopeplacer_45 end
+
+ --go unitvector forward and look how far the next node is
+ local step=1
+ while step<=lookup.max do
+ local node=minetest.get_node(vector.add(pos, dirvec))
+ --next node solid?
+ 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
+ --do slopes of this distance exist?
+ if lookup[step] then
+ if minetest.setting_getbool("creative_mode") or istack:get_count()>=step then
+ --start placing
+ local placenodes=lookup[step]
+ while step>0 do
+ minetest.set_node(pos, {name=def.nodename_prefix.."_"..placenodes[step], param2=param2})
+ if not minetest.setting_getbool("creative_mode") then
+ istack:take_item()
+ end
+ step=step-1
+ pos=vector.subtract(pos, dirvec)
+ end
+ else
+ minetest.chat_send_player(player:get_player_name(), "Can't place: Not enough slope items left ("..step.." required)")
+ end
+ else
+ minetest.chat_send_player(player:get_player_name(), "Can't place: There's no slope of length "..step)
+ end
+ return istack
+ end
+ step=step+1
+ pos=vector.add(pos, dirvec)
+ end
+ minetest.chat_send_player(player:get_player_name(), "Can't place: no supporting node at upper end.")
+ return itemstack
+ end
+end
+
+advtrains.slope=sl
+
+--END code, BEGIN definition
+--definition format: ([] optional)
+--[[{
+ nodename_prefix
+ texture_prefix
+ [shared_texture]
+ models_prefix
+ models_suffix (with dot)
+ [shared_model]
+ formats={
+ st,cr,swlst,swlcr,swrst,swrcr,vst1,vst2
+ (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)
+ }
+ common={} change something on common rail appearance
+}]]
+
+advtrains.register_tracks("regular", {
+ nodename_prefix="advtrains:track",
+ texture_prefix="advtrains_track",
+ shared_model="trackplane.b3d",
+ description="Deprecated Track",
+ formats={vst1={}, vst2={}},
+}, ap.t_45deg)
+
+
+advtrains.register_tracks("default", {
+ nodename_prefix="advtrains:dtrack",
+ texture_prefix="advtrains_dtrack",
+ models_prefix="advtrains_dtrack",
+ models_suffix=".b3d",
+ shared_texture="advtrains_dtrack_rail.png",
+ description="Track",
+ formats={vst1={true, false, true}, vst2={true, false, true}, vst31={true}, vst32={true}, vst33={true}},
+}, ap.t_30deg)
+
+--bumpers
+advtrains.register_tracks("default", {
+ nodename_prefix="advtrains:dtrack_bumper",
+ texture_prefix="advtrains_dtrack_bumper",
+ models_prefix="advtrains_dtrack_bumper",
+ models_suffix=".b3d",
+ shared_texture="advtrains_dtrack_rail.png",
+ description="Bumper",
+ formats={},
+}, ap.t_30deg_straightonly)
+--legacy bumpers
+for _,rot in ipairs({"", "_30", "_45", "_60"}) do
+ minetest.register_alias("advtrains:dtrack_bumper"..rot, "advtrains:dtrack_bumper_st"..rot)
+end
+
+if mesecon then
+ advtrains.register_tracks("default", {
+ nodename_prefix="advtrains:dtrack_detector_off",
+ texture_prefix="advtrains_dtrack_detector",
+ models_prefix="advtrains_dtrack_detector",
+ models_suffix=".b3d",
+ shared_texture="advtrains_dtrack_rail.png",
+ description="Detector Rail",
+ formats={},
+ get_additional_definiton = function(def, preset, suffix, rotation)
+ return {
+ mesecons = {
+ receptor = {
+ state = mesecon.state.off,
+ rules = advtrains.meseconrules
+ }
+ },
+ advtrains = {
+ on_train_enter=function(pos, train_id)
+ minetest.swap_node(pos, {name="advtrains:dtrack_detector_on".."_"..suffix..rotation, param2=minetest.get_node(pos).param2})
+ mesecon.receptor_on(pos, advtrains.meseconrules)
+ end
+ }
+ }
+ end
+ }, ap.t_30deg_straightonly)
+ advtrains.register_tracks("default", {
+ nodename_prefix="advtrains:dtrack_detector_on",
+ texture_prefix="advtrains_dtrack_detector",
+ models_prefix="advtrains_dtrack_detector",
+ models_suffix=".b3d",
+ shared_texture="advtrains_dtrack_rail_detector_on.png",
+ description="Detector(on)(you hacker you)",
+ formats={},
+ get_additional_definiton = function(def, preset, suffix, rotation)
+ return {
+ mesecons = {
+ receptor = {
+ state = mesecon.state.on,
+ rules = advtrains.meseconrules
+ }
+ },
+ advtrains = {
+ on_train_leave=function(pos, train_id)
+ minetest.swap_node(pos, {name="advtrains:dtrack_detector_off".."_"..suffix..rotation, param2=minetest.get_node(pos).param2})
+ mesecon.receptor_off(pos, advtrains.meseconrules)
+ end
+ }
+ }
+ end
+ }, ap.t_30deg_straightonly_noplacer)
+end
+--TODO legacy
+--I know lbms are better for this purpose
+for name,rep in pairs({swl_st="swlst", swr_st="swrst", swl_cr="swlcr", swr_cr="swrcr", }) do
+ minetest.register_abm({
+ -- In the following two fields, also group:groupname will work.
+ nodenames = {"advtrains:track_"..name},
+ interval = 1.0, -- Operation interval in seconds
+ chance = 1, -- Chance of trigger per-node per-interval is 1.0 / this
+ action = function(pos, node, active_object_count, active_object_count_wider) minetest.set_node(pos, {name="advtrains:track_"..rep, param2=node.param2}) end,
+ })
+ minetest.register_abm({
+ -- In the following two fields, also group:groupname will work.
+ nodenames = {"advtrains:track_"..name.."_45"},
+ interval = 1.0, -- Operation interval in seconds
+ chance = 1, -- Chance of trigger per-node per-interval is 1.0 / this
+ action = function(pos, node, active_object_count, active_object_count_wider) minetest.set_node(pos, {name="advtrains:track_"..rep.."_45", param2=node.param2}) end,
+ })
+end
+
+if advtrains.register_replacement_lbms then
+minetest.register_lbm({
+ name = "advtrains:ramp_replacement_1",
+-- In the following two fields, also group:groupname will work.
+ nodenames = {"advtrains:track_vert1"},
+ 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,
+})
+minetest.register_lbm({
+ name = "advtrains:ramp_replacement_1",
+-- -- In the following two fields, also group:groupname will work.
+ nodenames = {"advtrains:track_vert2"},
+ 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,
+})
+ minetest.register_abm({
+ name = "advtrains:st_rep_1",
+ -- In the following two fields, also group:groupname will work.
+ nodenames = {"advtrains:track_st"},
+ interval=1,
+ chance=1,
+ action = function(pos, node, active_object_count, active_object_count_wider) minetest.set_node(pos, {name="advtrains:dtrack_st", param2=node.param2}) end,
+ })
+ minetest.register_lbm({
+ name = "advtrains:st_rep_1",
+ -- -- In the following two fields, also group:groupname will work.
+ nodenames = {"advtrains:track_st_45"},
+ action = function(pos, node, active_object_count, active_object_count_wider) minetest.set_node(pos, {name="advtrains:dtrack_st_45", param2=node.param2}) end,
+ })
+end
+
+
+
+
+
+
+
+
diff --git a/advtrains/advtrains/trainhud.lua b/advtrains/advtrains/trainhud.lua
new file mode 100644
index 0000000..e69f04a
--- /dev/null
+++ b/advtrains/advtrains/trainhud.lua
@@ -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
index 0000000..5bedfec
--- /dev/null
+++ b/advtrains/advtrains/trainlogic.lua
@@ -0,0 +1,803 @@
+--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
+atprintbm=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=10
+
+
+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
+ atprintbm("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
+
+ atprintbm("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
+ atprint("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
+ atprint("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
+ atprint("[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
+ if advtrains.trains[advtrains.detector.on_node[testpts]] 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
+ else
+ --unexistant train left in this place
+ advtrains.detector.on_node[testpts]=nil
+ end
+ 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
+ --atprint("[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.
+ --atprint("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.
+ --atprint("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
+ --atprint("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
+ --atprint("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)
+
+ --atprint("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
+ atprint("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
+ atprint("last_pos not available")
+ return nil
+ elseif node_ok==false then
+ atprint("no track here, (fail) removing train.")
+ advtrains.trains[id]=nil
+ return false
+ end
+
+ if not train.last_pos_prev then
+ --no chance to recover
+ atprint("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
+ atprint("prev not available")
+ return nil
+ elseif prevnode_ok==false then
+ atprint("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=train.max_index_on_track or 0
+ while (maxn-train.index) < pregen_front do--pregenerate
+ --atprint("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
+ atprint("over-generating path max to index "..(maxn+1).." (position "..minetest.pos_to_string(train.path[maxn]).." )")
+ 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=train.min_index_on_track or 0
+ 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)
+ --atprint("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
+ atprint("over-generating path min to index "..(minn-1).." (position "..minetest.pos_to_string(train.path[minn]).." )")
+ 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]
+ atprint("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]
+ atprint("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=20
+ local rel_pos=0
+ local count_l=0
+ for i, w_id in ipairs(train.trainparts) do
+ local wagon=nil
+ for aoid,iwagon in pairs(minetest.luaentities) do
+ if iwagon.is_wagon and iwagon.unique_id==w_id then
+ if wagon then
+ --duplicate
+ atprint("update_trainpart_properties: Removing duplicate wagon with id="..aoid)
+ 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()
+ if not wagon then
+ minetest.chat_send_all("[advtrains] Warning: Wagon "..advtrains.wagon_save[w_id].entity_name.." does not exist. Make sure all required modules are loaded!")
+ else
+ wagon:init_from_wagon_save(w_id)
+ end
+ 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
+ atprint(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
+ atprint("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
+ atprint("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
+ atprint("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
+ atprint("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)
+ atprint("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]
+
+ if not train1 or not train2 then return end
+
+ 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
+ atprint("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
+ atprint("End positions: "..minetest.pos_to_string(frontpos2)..minetest.pos_to_string(backpos2))
+
+ if vector.distance(frontpos2, pos)<2 then
+ t2_is_backpos=false
+ elseif vector.distance(backpos2, pos)<2 then
+ t2_is_backpos=true
+ else
+ atprint("Err: not a endpos")
+ return --the collision position is not the end position.
+ end
+ atprint("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 atprint("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
+ atprint("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)
+ --atprint("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
+ --atprint("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
+ --atprint("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
+ --atprint("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()
+ --atprint("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
index 0000000..029d2d1
--- /dev/null
+++ b/advtrains/advtrains/wagons.lua
@@ -0,0 +1,590 @@
+--atan2 counts angles clockwise, minetest does counterclockwise
+
+minetest.register_privilege("train_place", {
+ description = "Player can place trains on tracks not owned by player",
+ give_to_singleplayer= false,
+});
+minetest.register_privilege("train_remove", {
+ description = "Player can remove trains not owned by player",
+ give_to_singleplayer= false,
+});
+
+local wagon={
+ collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
+ --physical = true,
+ visual = "mesh",
+ mesh = "wagon.b3d",
+ visual_size = {x=3, y=3},
+ textures = {"black.png"},
+ is_wagon=true,
+ wagon_span=1,--how many index units of space does this wagon consume
+ has_inventory=false,
+}
+
+
+
+function wagon:on_rightclick(clicker)
+ if not self:ensure_init() then return end
+ if not clicker or not clicker:is_player() then
+ return
+ end
+ if clicker:get_player_control().aux1 then
+ --advtrains.dumppath(self:train().path)
+ --minetest.chat_send_all("at index "..(self:train().index or "nil"))
+ --advtrains.invert_train(self.train_id)
+ minetest.chat_send_all(dump(self:train()))
+ return
+ end
+ local no=self:get_seatno(clicker:get_player_name())
+ if no then
+ self:get_off(no)
+ else
+ self:show_get_on_form(clicker:get_player_name())
+ end
+end
+
+function wagon:train()
+ return advtrains.trains[self.train_id]
+end
+
+--[[about 'initalized':
+ when initialized is false, the entity hasn't got any data yet and should wait for these to be set before doing anything
+ when loading an existing object (with staticdata), it will be set
+ when instanciating a new object via add_entity, it is not set at the time on_activate is called.
+ then, wagon:initialize() will be called
+
+ wagon will save only uid in staticdata, no serialized table
+]]
+function wagon:on_activate(sd_uid, dtime_s)
+ atprint("[wagon "..((sd_uid and sd_uid~="" and sd_uid) or "no-id").."] activated")
+ self.object:set_armor_groups({immortal=1})
+ if sd_uid and sd_uid~="" then
+ --legacy
+ --expect this to be a serialized table and handle
+ if minetest.deserialize(sd_uid) then
+ self:init_from_wagon_save(minetest.deserialize(sd_uid).unique_id)
+ else
+ self:init_from_wagon_save(sd_uid)
+ end
+ end
+ self.entity_name=self.name
+
+ --duplicates?
+ for ao_id,wagon in pairs(minetest.luaentities) do
+ if wagon.is_wagon and wagon.initialized and wagon.unique_id==self.unique_id and wagon~=self then--i am a duplicate!
+ atprint("[wagon "..((sd_uid and sd_uid~="" and sd_uid) or "no-id").."] duplicate found(ao_id:"..ao_id.."), removing")
+ self.object:remove()
+ minetest.after(0.5, function() advtrains.update_trainpart_properties(self.train_id) end)
+ return
+ end
+ end
+
+ if self.custom_on_activate then
+ self:custom_on_activate(dtime_s)
+ end
+end
+
+function wagon:get_staticdata()
+ if not self:ensure_init() then return end
+ atprint("[wagon "..((self.unique_id and self.unique_id~="" and self.unique_id) or "no-id").."]: saving to wagon_save")
+ --serialize inventory, if it has one
+ if self.has_inventory then
+ local inv=minetest.get_inventory({type="detached", name="advtrains_wgn_"..self.unique_id})
+ self.ser_inv=advtrains.serialize_inventory(inv)
+ end
+ --save to table before being unloaded
+ advtrains.wagon_save[self.unique_id]=advtrains.merge_tables(self)
+ advtrains.wagon_save[self.unique_id].entity_name=self.name
+ advtrains.wagon_save[self.unique_id].name=nil
+ advtrains.wagon_save[self.unique_id].object=nil
+ return self.unique_id
+end
+--returns: uid of wagon
+function wagon:init_new_instance(train_id, properties)
+ self.unique_id=os.time()..os.clock()
+ self.train_id=train_id
+ for k,v in pairs(properties) do
+ if k~="name" and k~="object" then
+ self[k]=v
+ end
+ end
+ self:init_shared()
+ self.initialized=true
+ atprint("init_new_instance "..self.unique_id.." ("..self.train_id..")")
+ return self.unique_id
+end
+function wagon:init_from_wagon_save(uid)
+ if not advtrains.wagon_save[uid] then
+ self.object:remove()
+ return
+ end
+ self.unique_id=uid
+ for k,v in pairs(advtrains.wagon_save[uid]) do
+ if k~="name" and k~="object" then
+ self[k]=v
+ end
+ end
+ if not self.train_id or not self:train() then
+ self.object:remove()
+ return
+ end
+ self:init_shared()
+ self.initialized=true
+ minetest.after(1, function() self:reattach_all() end)
+ atprint("init_from_wagon_save "..self.unique_id.." ("..self.train_id..")")
+ advtrains.update_trainpart_properties(self.train_id)
+end
+function wagon:init_shared()
+ if self.has_inventory then
+ local uid_noptr=self.unique_id..""
+ --to be used later
+ local inv=minetest.create_detached_inventory("advtrains_wgn_"..self.unique_id, {
+ allow_move = function(inv, from_list, from_index, to_list, to_index, count, player)
+ return count
+ end,
+ allow_put = function(inv, listname, index, stack, player)
+ return stack:get_count()
+ end,
+ allow_take = function(inv, listname, index, stack, player)
+ return stack:get_count()
+ end
+ })
+ if self.ser_inv then
+ advtrains.deserialize_inventory(self.ser_inv, inv)
+ end
+ if self.inventory_list_sizes then
+ for lst, siz in pairs(self.inventory_list_sizes) do
+ inv:set_size(lst, siz)
+ end
+ end
+ end
+end
+function wagon:ensure_init()
+ if self.initialized then
+ if self.noninitticks then self.noninitticks=nil end
+ return true
+ end
+ if not self.noninitticks then self.noninitticks=0 end
+ self.noninitticks=self.noninitticks+1
+ if self.noninitticks>20 then
+ self.object:remove()
+ else
+ self.object:setvelocity({x=0,y=0,z=0})
+ end
+ return false
+end
+
+-- Remove the wagon
+function wagon:on_punch(puncher, time_from_last_punch, tool_capabilities, direction)
+ if not self:ensure_init() then return end
+ if not puncher or not puncher:is_player() then
+ return
+ end
+ if self.owner and puncher:get_player_name()~=self.owner and (not minetest.check_player_privs(puncher, {train_remove = true })) then
+ minetest.chat_send_player(puncher:get_player_name(), "This wagon is owned by "..self.owner..", you can't destroy it.");
+ return
+ end
+
+ if minetest.setting_getbool("creative_mode") then
+ if not self:destroy() then return end
+
+ local inv = puncher:get_inventory()
+ if not inv:contains_item("main", self.name) then
+ inv:add_item("main", self.name)
+ end
+ else
+ local pc=puncher:get_player_control()
+ if not pc.sneak then
+ 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.")
+ return
+ end
+
+ if not self:destroy() then return end
+
+ local inv = puncher:get_inventory()
+ for _,item in ipairs(self.drops or {self.name}) do
+ inv:add_item("main", item)
+ end
+ end
+end
+function wagon:destroy()
+ --some rules:
+ -- you get only some items back
+ -- single left-click shows warning
+ -- shift leftclick destroys
+ -- not when a driver is inside
+
+ for _,_ in pairs(self.seatp) do
+ return
+ end
+
+ if self.custom_may_destroy then
+ if not self.custom_may_destroy(self, puncher, time_from_last_punch, tool_capabilities, direction) then
+ return
+ end
+ end
+ if self.custom_on_destroy then
+ self.custom_on_destroy(self, puncher, time_from_last_punch, tool_capabilities, direction)
+ end
+
+ atprint("[wagon "..((self.unique_id and self.unique_id~="" and self.unique_id) or "no-id").."]: destroying")
+
+ self.object:remove()
+
+ table.remove(self:train().trainparts, self.pos_in_trainparts)
+ advtrains.update_trainpart_properties(self.train_id)
+ advtrains.wagon_save[self.unique_id]=nil
+ if self.discouple then self.discouple.object:remove() end--will have no effect on unloaded objects
+ return true
+end
+
+
+function wagon:on_step(dtime)
+ if not self:ensure_init() then return end
+
+ local t=os.clock()
+ local pos = self.object:getpos()
+
+ if not pos then
+ atprint("["..self.unique_id.."][fatal] missing position (object:getpos() returned nil)")
+ return
+ end
+
+ self.entity_name=self.name
+
+ --is my train still here
+ if not self.train_id or not self:train() then
+ atprint("[wagon "..self.unique_id.."] missing train_id, destroying")
+ self.object:remove()
+ return
+ elseif not self.initialized then
+ self.initialized=true
+ end
+ if not self.seatp then
+ self.seatp={}
+ end
+
+ --custom on_step function
+ if self.custom_on_step then
+ self:custom_on_step(self, dtime)
+ end
+
+ --driver control
+ for seatno, seat in ipairs(self.seats) do
+ if seat.driving_ctrl_access then
+ local driver=self.seatp[seatno] and minetest.get_player_by_name(self.seatp[seatno])
+ local get_off_pressed=false
+ if driver and driver:get_player_control_bits()~=self.old_player_control_bits then
+ local pc=driver:get_player_control()
+
+ advtrains.on_control_change(pc, self:train(), self.wagon_flipped)
+ if pc.aux1 and pc.sneak then
+ get_off_pressed=true
+ end
+
+ self.old_player_control_bits=driver:get_player_control_bits()
+ end
+ if driver then
+ if get_off_pressed then
+ self:get_off(seatno)
+ else
+ advtrains.update_driver_hud(driver:get_player_name(), self:train(), self.wagon_flipped)
+ end
+ end
+ end
+ end
+
+ local gp=self:train()
+
+ --DisCouple
+ if self.pos_in_trainparts and self.pos_in_trainparts>1 then
+ if gp.velocity==0 then
+ if not self.discouple or not self.discouple.object:getyaw() then
+ local object=minetest.add_entity(pos, "advtrains:discouple")
+ if object then
+ local le=object:get_luaentity()
+ le.wagon=self
+ --box is hidden when attached, so unuseful.
+ --object:set_attach(self.object, "", {x=0, y=0, z=self.wagon_span*10}, {x=0, y=0, z=0})
+ self.discouple=le
+ else
+ atprint("Couldn't spawn DisCouple")
+ end
+ end
+ else
+ if self.discouple and self.discouple.object:getyaw() then
+ self.discouple.object:remove()
+ end
+ end
+ end
+ --for path to be available. if not, skip step
+ if not advtrains.get_or_create_path(self.train_id, gp) then
+ self.object:setvelocity({x=0, y=0, z=0})
+ return
+ end
+ if not self.pos_in_train then
+ --why ever. but better continue next step...
+ advtrains.update_trainpart_properties(self.train_id)
+ return
+ end
+
+ local index=advtrains.get_real_path_index(self:train(), self.pos_in_train)
+ --atprint("trainindex "..gp.index.." wagonindex "..index)
+
+ --position recalculation
+ local first_pos=gp.path[math.floor(index)]
+ local second_pos=gp.path[math.floor(index)+1]
+ if not first_pos or not second_pos then
+ --atprint(" object "..self.unique_id.." path end reached!")
+ self.object:setvelocity({x=0,y=0,z=0})
+ return
+ end
+
+ --checking for environment collisions(a 3x3 cube around the center)
+ if not gp.recently_collided_with_env then
+ local collides=false
+ for x=-1,1 do
+ for y=0,2 do
+ for z=-1,1 do
+ local node=minetest.get_node_or_nil(vector.add(first_pos, {x=x, y=y, z=z}))
+ if (advtrains.train_collides(node)) then
+ collides=true
+ end
+ end
+ end
+ end
+ if collides then
+ gp.recently_collided_with_env=true
+ gp.velocity=-0.5*gp.velocity
+ gp.tarvelocity=0
+ end
+ end
+
+ --FIX: use index of the wagon, not of the train.
+ local velocity=(gp.velocity*gp.movedir)/(gp.path_dist[math.floor(index)] or 1)
+ local acceleration=(gp.last_accel or 0)/(gp.path_dist[math.floor(index)] or 1)
+ local factor=index-math.floor(index)
+ 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,}
+ 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}
+ 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}
+
+ --some additional positions to determine orientation
+ local aposfwd=gp.path[math.floor(index+2)]
+ local aposbwd=gp.path[math.floor(index-1)]
+
+ local yaw
+ if aposfwd and aposbwd then
+ yaw=advtrains.get_wagon_yaw(aposfwd, second_pos, first_pos, aposbwd, factor)+math.pi--TODO remove when cleaning up
+ else
+ yaw=math.atan2((first_pos.x-second_pos.x), (second_pos.z-first_pos.z))
+ end
+ if self.wagon_flipped then
+ yaw=yaw+math.pi
+ end
+
+ 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 not self.old_acceleration_vector
+ or not vector.equals(accelerationvec, self.old_acceleration_vector)
+ or self.old_yaw~=yaw
+ or self.updatepct_timer<=0 then--only send update packet if something changed
+ self.object:setpos(actual_pos)
+ self.object:setvelocity(velocityvec)
+ self.object:setacceleration(accelerationvec)
+ self.object:setyaw(yaw)
+ self.updatepct_timer=2
+ if self.update_animation then
+ self:update_animation(gp.velocity)
+ end
+ end
+
+
+ self.old_velocity_vector=velocityvec
+ self.old_acceleration_vector=accelerationvec
+ self.old_yaw=yaw
+ atprintbm("wagon step", t)
+end
+
+function advtrains.get_real_path_index(train, pit)
+ local pos_in_train_left=pit
+ local index=train.index
+ if pos_in_train_left>(index-math.floor(index))*(train.path_dist[math.floor(index)] or 1) then
+ pos_in_train_left=pos_in_train_left - (index-math.floor(index))*(train.path_dist[math.floor(index)] or 1)
+ index=math.floor(index)
+ while pos_in_train_left>(train.path_dist[index-1] or 1) do
+ pos_in_train_left=pos_in_train_left - (train.path_dist[index-1] or 1)
+ index=index-1
+ end
+ index=index-(pos_in_train_left/(train.path_dist[index-1] or 1))
+ else
+ index=index-(pos_in_train_left/(train.path_dist[math.floor(index-1)] or 1))
+ end
+ return index
+end
+
+function wagon:get_on(clicker, seatno)
+ if not self.seatp then
+ self.seatp={}
+ end
+ if not self.seats[seatno] then return end
+ if self.seatp[seatno] and self.seatp[seatno]~=clicker:get_player_name() then
+ self:get_off(seatno)
+ end
+ self.seatp[seatno] = clicker:get_player_name()
+ advtrains.player_to_train_mapping[clicker:get_player_name()]=self.train_id
+ clicker:set_attach(self.object, "", self.seats[seatno].attach_offset, {x=0,y=0,z=0})
+ clicker:set_eye_offset(self.seats[seatno].view_offset, self.seats[seatno].view_offset)
+end
+function wagon:get_off_plr(pname)
+ local no=self:get_seatno(pname)
+ if no then
+ self:get_off(no)
+ end
+end
+function wagon:get_seatno(pname)
+ for no, cont in pairs(self.seatp) do
+ if cont==pname then
+ return no
+ end
+ end
+ return nil
+end
+function wagon:get_off(seatno)
+ if not self.seatp[seatno] then return end
+ local pname = self.seatp[seatno]
+ local clicker = minetest.get_player_by_name(pname)
+ advtrains.player_to_train_mapping[pname]=nil
+ advtrains.clear_driver_hud(pname)
+ if clicker then
+ clicker:set_detach()
+ clicker:set_eye_offset({x=0,y=0,z=0}, {x=0,y=0,z=0})
+ local objpos=advtrains.round_vector_floor_y(self.object:getpos())
+ local yaw=self.object:getyaw()
+ local isx=(yaw < math.pi/4) or (yaw > 3*math.pi/4 and yaw < 5*math.pi/4) or (yaw > 7*math.pi/4)
+ --abuse helper function
+ for _,r in ipairs({-1, 1}) do
+ local p=vector.add({x=isx and r or 0, y=0, z=not isx and r or 0}, objpos)
+ if minetest.get_item_group(minetest.get_node(p).name, "platform")>0 then
+ minetest.after(0.2, function() clicker:setpos({x=p.x, y=p.y+1, z=p.z}) end)
+ end
+ end
+ end
+ self.seatp[seatno]=nil
+end
+function wagon:show_get_on_form(pname)
+ if not self.initialized then return end
+ if #self.seats==0 then
+ if self.has_inventory and self.get_inventory_formspec then
+ minetest.show_formspec(pname, "advtrains_inv_"..self.unique_id, self:get_inventory_formspec(pname))
+ end
+ return
+ end
+ local form, comma="size[5,8]label[0.5,0.5;Select seat:]textlist[0.5,1;4,6;seat;", ""
+ for seatno, seattbl in ipairs(self.seats) do
+ local addtext, colorcode="", ""
+ if self.seatp and self.seatp[seatno] then
+ colorcode="#FF0000"
+ addtext=" ("..self.seatp[seatno]..")"
+ end
+ form=form..comma..colorcode..seattbl.name..addtext
+ comma=","
+ end
+ form=form..";0,false]"
+ if self.has_inventory and self.get_inventory_formspec then
+ form=form.."button_exit[1,7;3,1;inv;Show Inventory]"
+ end
+ minetest.show_formspec(pname, "advtrains_geton_"..self.unique_id, form)
+end
+minetest.register_on_player_receive_fields(function(player, formname, fields)
+ local uid=string.match(formname, "^advtrains_geton_(.+)$")
+ if uid then
+ for _,wagon in pairs(minetest.luaentities) do
+ if wagon.is_wagon and wagon.initialized and wagon.unique_id==uid then
+ if fields.inv then
+ if wagon.has_inventory and wagon.get_inventory_formspec then
+ minetest.show_formspec(player:get_player_name(), "advtrains_inv_"..uid, wagon:get_inventory_formspec(player:get_player_name()))
+ end
+ elseif fields.seat then
+ local val=minetest.explode_textlist_event(fields.seat)
+ if val and val.type~="INV" and not wagon.seatp[player:get_player_name()] then
+ --get on
+ wagon:get_on(player, val.index)
+ --will work with the new close_formspec functionality. close exactly this formspec.
+ minetest.show_formspec(player:get_player_name(), formname, "")
+ end
+ end
+ end
+ end
+ end
+end)
+function wagon:reattach_all()
+ if not self.seatp then self.seatp={} end
+ for seatno, pname in pairs(self.seatp) do
+ local p=minetest.get_player_by_name(pname)
+ if p then
+ self:get_on(p ,seatno)
+ end
+ end
+end
+minetest.register_on_joinplayer(function(player)
+ for _,wagon in pairs(minetest.luaentities) do
+ if wagon.is_wagon and wagon.initialized then
+ wagon:reattach_all()
+ end
+ end
+end)
+
+function advtrains.register_wagon(sysname, prototype, desc, inv_img)
+ setmetatable(prototype, {__index=wagon})
+ minetest.register_entity(":advtrains:"..sysname,prototype)
+
+ minetest.register_craftitem(":advtrains:"..sysname, {
+ description = desc,
+ inventory_image = inv_img,
+ wield_image = inv_img,
+ stack_max = 1,
+
+ on_place = function(itemstack, placer, pointed_thing)
+ if not pointed_thing.type == "node" then
+ return
+ end
+
+
+ local node=minetest.get_node_or_nil(pointed_thing.under)
+ if not node then atprint("[advtrains]Ignore at placer position") return itemstack end
+ local nodename=node.name
+ if(not advtrains.is_track_and_drives_on(nodename, prototype.drives_on)) then
+ atprint("no track here, not placing.")
+ return itemstack
+ end
+ local conn1=advtrains.get_track_connections(node.name, node.param2)
+ local id=advtrains.create_new_train_at(pointed_thing.under, advtrains.dirCoordSet(pointed_thing.under, conn1))
+
+ local ob=minetest.add_entity(pointed_thing.under, "advtrains:"..sysname)
+ if not ob then
+ atprint("couldn't add_entity, aborting")
+ end
+ local le=ob:get_luaentity()
+
+ le.owner=placer:get_player_name()
+ le.infotext=desc..", owned by "..placer:get_player_name()
+
+ local wagon_uid=le:init_new_instance(id, {})
+
+ advtrains.add_wagon_to_train(le, id)
+ if not minetest.setting_getbool("creative_mode") then
+ itemstack:take_item()
+ end
+ return itemstack
+
+ end,
+ })
+end
+
+--[[
+ wagons can define update_animation(self, velocity) if they have a speed-dependent animation
+ this function will be called when the velocity vector changes or every 2 seconds.
+]]
+
+
diff --git a/advtrains/advtrains_train_industrial/depends.txt b/advtrains/advtrains_train_industrial/depends.txt
new file mode 100644
index 0000000..6f00bf6
--- /dev/null
+++ b/advtrains/advtrains_train_industrial/depends.txt
@@ -0,0 +1 @@
+advtrains \ No newline at end of file
diff --git a/advtrains/advtrains_train_industrial/init.lua b/advtrains/advtrains_train_industrial/init.lua
new file mode 100644
index 0000000..379832c
--- /dev/null
+++ b/advtrains/advtrains_train_industrial/init.lua
@@ -0,0 +1,67 @@
+advtrains.register_wagon("engine_industrial", {
+ mesh="advtrains_engine_industrial.b3d",
+ textures = {"advtrains_engine_industrial.png"},
+ drives_on={default=true},
+ max_speed=20,
+ seats = {
+ {
+ name="Driver Stand (left)",
+ attach_offset={x=-5, y=10, z=-10},
+ view_offset={x=0, y=10, z=0},
+ driving_ctrl_access=true,
+ },
+ {
+ name="Driver Stand (right)",
+ attach_offset={x=5, y=10, z=-10},
+ view_offset={x=0, y=10, z=0},
+ driving_ctrl_access=true,
+ },
+ },
+ visual_size = {x=1, y=1},
+ wagon_span=2.6,
+ is_locomotive=true,
+ collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
+ drops={"default:steelblock 4"},
+}, "Industrial Train Engine", "advtrains_engine_industrial_inv.png")
+advtrains.register_wagon("wagon_tank", {
+ mesh="advtrains_wagon_tank.b3d",
+ textures = {"advtrains_wagon_tank.png"},
+ seats = {},
+ drives_on={default=true},
+ max_speed=20,
+ visual_size = {x=1, y=1},
+ wagon_span=2.2,
+ collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
+ drops={"default:steelblock 4"},
+ has_inventory = true,
+ get_inventory_formspec = function(self)
+ return "size[8,11]"..
+ "list[detached:advtrains_wgn_"..self.unique_id..";box;0,0;8,6;]"..
+ "list[current_player;main;0,7;8,4;]"..
+ "listring[]"
+ end,
+ inventory_list_sizes = {
+ box=8*6,
+ },
+}, "Industrial tank wagon", "advtrains_wagon_tank_inv.png")
+advtrains.register_wagon("wagon_wood", {
+ mesh="advtrains_wagon_wood.b3d",
+ textures = {"advtrains_wagon_wood.png"},
+ seats = {},
+ drives_on={default=true},
+ max_speed=20,
+ visual_size = {x=1, y=1},
+ wagon_span=1.8,
+ collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
+ drops={"default:steelblock 4"},
+ has_inventory = true,
+ get_inventory_formspec = function(self)
+ return "size[8,11]"..
+ "list[detached:advtrains_wgn_"..self.unique_id..";box;0,0;8,6;]"..
+ "list[current_player;main;0,7;8,4;]"..
+ "listring[]"
+ end,
+ inventory_list_sizes = {
+ box=8*6,
+ },
+}, "Industrial wood wagon", "advtrains_wagon_wood_inv.png")
diff --git a/advtrains/advtrains_train_industrial/models/advtrains_engine_industrial.b3d b/advtrains/advtrains_train_industrial/models/advtrains_engine_industrial.b3d
new file mode 100644
index 0000000..f1ea485
--- /dev/null
+++ b/advtrains/advtrains_train_industrial/models/advtrains_engine_industrial.b3d
Binary files differ
diff --git a/advtrains/advtrains_train_industrial/models/advtrains_wagon_tank.b3d b/advtrains/advtrains_train_industrial/models/advtrains_wagon_tank.b3d
new file mode 100644
index 0000000..af2604b
--- /dev/null
+++ b/advtrains/advtrains_train_industrial/models/advtrains_wagon_tank.b3d
Binary files differ
diff --git a/advtrains/advtrains_train_industrial/models/advtrains_wagon_wood.b3d b/advtrains/advtrains_train_industrial/models/advtrains_wagon_wood.b3d
new file mode 100644
index 0000000..0e7fb4b
--- /dev/null
+++ b/advtrains/advtrains_train_industrial/models/advtrains_wagon_wood.b3d
Binary files differ
diff --git a/advtrains/advtrains_train_industrial/textures/advtrains_engine_industrial.png b/advtrains/advtrains_train_industrial/textures/advtrains_engine_industrial.png
new file mode 100644
index 0000000..38a872f
--- /dev/null
+++ b/advtrains/advtrains_train_industrial/textures/advtrains_engine_industrial.png
Binary files differ
diff --git a/advtrains/advtrains_train_industrial/textures/advtrains_engine_industrial_inv.png b/advtrains/advtrains_train_industrial/textures/advtrains_engine_industrial_inv.png
new file mode 100644
index 0000000..be4e80f
--- /dev/null
+++ b/advtrains/advtrains_train_industrial/textures/advtrains_engine_industrial_inv.png
Binary files differ
diff --git a/advtrains/advtrains_train_industrial/textures/advtrains_wagon_tank.png b/advtrains/advtrains_train_industrial/textures/advtrains_wagon_tank.png
new file mode 100644
index 0000000..79b1316
--- /dev/null
+++ b/advtrains/advtrains_train_industrial/textures/advtrains_wagon_tank.png
Binary files differ
diff --git a/advtrains/advtrains_train_industrial/textures/advtrains_wagon_tank_inv.png b/advtrains/advtrains_train_industrial/textures/advtrains_wagon_tank_inv.png
new file mode 100644
index 0000000..03401be
--- /dev/null
+++ b/advtrains/advtrains_train_industrial/textures/advtrains_wagon_tank_inv.png
Binary files differ
diff --git a/advtrains/advtrains_train_industrial/textures/advtrains_wagon_wood.png b/advtrains/advtrains_train_industrial/textures/advtrains_wagon_wood.png
new file mode 100644
index 0000000..acc6f72
--- /dev/null
+++ b/advtrains/advtrains_train_industrial/textures/advtrains_wagon_wood.png
Binary files differ
diff --git a/advtrains/advtrains_train_industrial/textures/advtrains_wagon_wood_inv.png b/advtrains/advtrains_train_industrial/textures/advtrains_wagon_wood_inv.png
new file mode 100644
index 0000000..87109dd
--- /dev/null
+++ b/advtrains/advtrains_train_industrial/textures/advtrains_wagon_wood_inv.png
Binary files differ
diff --git a/advtrains/advtrains_train_japan/depends.txt b/advtrains/advtrains_train_japan/depends.txt
new file mode 100644
index 0000000..6f00bf6
--- /dev/null
+++ b/advtrains/advtrains_train_japan/depends.txt
@@ -0,0 +1 @@
+advtrains \ No newline at end of file
diff --git a/advtrains/advtrains_train_japan/init.lua b/advtrains/advtrains_train_japan/init.lua
new file mode 100644
index 0000000..47f50cf
--- /dev/null
+++ b/advtrains/advtrains_train_japan/init.lua
@@ -0,0 +1,38 @@
+advtrains.register_wagon("engine_japan", {
+ mesh="advtrains_engine_japan.b3d",
+ textures = {"advtrains_engine_japan.png"},
+ drives_on={default=true},
+ max_speed=20,
+ seats = {
+ {
+ name="Default Seat (driver stand)",
+ attach_offset={x=0, y=10, z=0},
+ view_offset={x=0, y=6, z=0},
+ driving_ctrl_access=true,
+ },
+ },
+ visual_size = {x=1, y=1},
+ wagon_span=2.5,
+ is_locomotive=true,
+ collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
+ drops={"default:steelblock 4"},
+}, "Japanese Train Engine", "advtrains_engine_japan_inv.png")
+
+advtrains.register_wagon("wagon_japan", {
+ mesh="advtrains_wagon_japan.b3d",
+ textures = {"advtrains_wagon_japan.png"},
+ drives_on={default=true},
+ max_speed=20,
+ seats = {
+ {
+ name="Default Seat",
+ attach_offset={x=0, y=10, z=0},
+ view_offset={x=0, y=6, z=0},
+ },
+ },
+ visual_size = {x=1, y=1},
+ wagon_span=2.3,
+ collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
+ drops={"default:steelblock 4"},
+}, "Japanese Train Wagon", "advtrains_wagon_japan_inv.png")
+
diff --git a/advtrains/advtrains_train_japan/models/advtrains_engine_japan.b3d b/advtrains/advtrains_train_japan/models/advtrains_engine_japan.b3d
new file mode 100644
index 0000000..f82c33e
--- /dev/null
+++ b/advtrains/advtrains_train_japan/models/advtrains_engine_japan.b3d
Binary files differ
diff --git a/advtrains/advtrains_train_japan/models/advtrains_wagon_japan.b3d b/advtrains/advtrains_train_japan/models/advtrains_wagon_japan.b3d
new file mode 100644
index 0000000..7970438
--- /dev/null
+++ b/advtrains/advtrains_train_japan/models/advtrains_wagon_japan.b3d
Binary files differ
diff --git a/advtrains/advtrains_train_japan/textures/advtrains_engine_japan.png b/advtrains/advtrains_train_japan/textures/advtrains_engine_japan.png
new file mode 100644
index 0000000..b286b38
--- /dev/null
+++ b/advtrains/advtrains_train_japan/textures/advtrains_engine_japan.png
Binary files differ
diff --git a/advtrains/advtrains_train_japan/textures/advtrains_engine_japan_inv.png b/advtrains/advtrains_train_japan/textures/advtrains_engine_japan_inv.png
new file mode 100644
index 0000000..6af0636
--- /dev/null
+++ b/advtrains/advtrains_train_japan/textures/advtrains_engine_japan_inv.png
Binary files differ
diff --git a/advtrains/advtrains_train_japan/textures/advtrains_wagon_japan.png b/advtrains/advtrains_train_japan/textures/advtrains_wagon_japan.png
new file mode 100644
index 0000000..bee565e
--- /dev/null
+++ b/advtrains/advtrains_train_japan/textures/advtrains_wagon_japan.png
Binary files differ
diff --git a/advtrains/advtrains_train_japan/textures/advtrains_wagon_japan_inv.png b/advtrains/advtrains_train_japan/textures/advtrains_wagon_japan_inv.png
new file mode 100644
index 0000000..3e6357c
--- /dev/null
+++ b/advtrains/advtrains_train_japan/textures/advtrains_wagon_japan_inv.png
Binary files differ
diff --git a/advtrains/advtrains_train_steam/depends.txt b/advtrains/advtrains_train_steam/depends.txt
new file mode 100644
index 0000000..6f00bf6
--- /dev/null
+++ b/advtrains/advtrains_train_steam/depends.txt
@@ -0,0 +1 @@
+advtrains \ No newline at end of file
diff --git a/advtrains/advtrains_train_steam/init.lua b/advtrains/advtrains_train_steam/init.lua
new file mode 100644
index 0000000..22f525f
--- /dev/null
+++ b/advtrains/advtrains_train_steam/init.lua
@@ -0,0 +1,196 @@
+advtrains.register_wagon("newlocomotive", {
+ mesh="advtrains_engine_steam.b3d",
+ textures = {"advtrains_engine_steam.png"},
+ is_locomotive=true,
+ drives_on={default=true},
+ max_speed=10,
+ seats = {
+ {
+ name="Driver Stand (left)",
+ attach_offset={x=-5, y=10, z=-10},
+ view_offset={x=0, y=6, z=0},
+ driving_ctrl_access=true,
+ },
+ {
+ name="Driver Stand (right)",
+ attach_offset={x=5, y=10, z=-10},
+ view_offset={x=0, y=6, z=0},
+ driving_ctrl_access=true,
+ },
+ },
+ visual_size = {x=1, y=1},
+ wagon_span=1.85,
+ collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
+ update_animation=function(self, velocity)
+ if self.old_anim_velocity~=advtrains.abs_ceil(velocity) then
+ self.object:set_animation({x=1,y=80}, advtrains.abs_ceil(velocity)*15, 0, true)
+ self.old_anim_velocity=advtrains.abs_ceil(velocity)
+ end
+ end,
+ custom_on_activate = function(self, staticdata_table, dtime_s)
+ minetest.add_particlespawner({
+ amount = 10,
+ time = 0,
+ -- ^ If time is 0 has infinite lifespan and spawns the amount on a per-second base
+ minpos = {x=0, y=2, z=1.2},
+ maxpos = {x=0, y=2, z=1.2},
+ minvel = {x=-0.2, y=1.8, z=-0.2},
+ maxvel = {x=0.2, y=2, z=0.2},
+ minacc = {x=0, y=-0.1, z=0},
+ maxacc = {x=0, y=-0.3, z=0},
+ minexptime = 2,
+ maxexptime = 4,
+ minsize = 1,
+ maxsize = 5,
+ -- ^ The particle's properties are random values in between the bounds:
+ -- ^ minpos/maxpos, minvel/maxvel (velocity), minacc/maxacc (acceleration),
+ -- ^ minsize/maxsize, minexptime/maxexptime (expirationtime)
+ collisiondetection = true,
+ -- ^ collisiondetection: if true uses collision detection
+ vertical = false,
+ -- ^ vertical: if true faces player using y axis only
+ texture = "smoke_puff.png",
+ -- ^ Uses texture (string)
+ attached = self.object,
+ })
+ end,
+ drops={"default:steelblock 4"},
+}, "Steam Engine", "advtrains_engine_steam_inv.png")
+
+advtrains.register_wagon("detailed_steam_engine", {
+ mesh="advtrains_detailed_steam_engine.b3d",
+ textures = {"advtrains_detailed_steam_engine.png"},
+ is_locomotive=true,
+ drives_on={default=true},
+ max_speed=10,
+ seats = {
+ {
+ name="Driver Stand (left)",
+ attach_offset={x=-5, y=10, z=-10},
+ view_offset={x=0, y=6, z=0},
+ driving_ctrl_access=true,
+ },
+ {
+ name="Driver Stand (right)",
+ attach_offset={x=5, y=10, z=-10},
+ view_offset={x=0, y=6, z=0},
+ driving_ctrl_access=true,
+ },
+ },
+ visual_size = {x=1, y=1},
+ wagon_span=2.05,
+ collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
+ update_animation=function(self, velocity)
+ if self.old_anim_velocity~=advtrains.abs_ceil(velocity) then
+ self.object:set_animation({x=1,y=80}, advtrains.abs_ceil(velocity)*15, 0, true)
+ self.old_anim_velocity=advtrains.abs_ceil(velocity)
+ end
+ end,
+ custom_on_activate = function(self, staticdata_table, dtime_s)
+ minetest.add_particlespawner({
+ amount = 10,
+ time = 0,
+ -- ^ If time is 0 has infinite lifespan and spawns the amount on a per-second base
+ minpos = {x=0, y=2.3, z=1.45},
+ maxpos = {x=0, y=2.3, z=1.4},
+ minvel = {x=-0.2, y=1.8, z=-0.2},
+ maxvel = {x=0.2, y=2, z=0.2},
+ minacc = {x=0, y=-0.1, z=0},
+ maxacc = {x=0, y=-0.3, z=0},
+ minexptime = 2,
+ maxexptime = 4,
+ minsize = 1,
+ maxsize = 5,
+ -- ^ The particle's properties are random values in between the bounds:
+ -- ^ minpos/maxpos, minvel/maxvel (velocity), minacc/maxacc (acceleration),
+ -- ^ minsize/maxsize, minexptime/maxexptime (expirationtime)
+ collisiondetection = true,
+ -- ^ collisiondetection: if true uses collision detection
+ vertical = false,
+ -- ^ vertical: if true faces player using y axis only
+ texture = "smoke_puff.png",
+ -- ^ Uses texture (string)
+ attached = self.object,
+ })
+ end,
+ drops={"default:steelblock 4"},
+}, "Detailed Steam Engine", "advtrains_engine_steam_inv.png")
+
+advtrains.register_wagon("wagon_default", {
+ mesh="advtrains_passenger_wagon.b3d",
+ textures = {"advtrains_wagon.png"},
+ drives_on={default=true},
+ max_speed=10,
+ seats = {
+ {
+ name="1",
+ attach_offset={x=-4, y=8, z=8},
+ view_offset={x=0, y=0, z=0},
+ },
+ {
+ name="2",
+ attach_offset={x=4, y=8, z=8},
+ view_offset={x=0, y=0, z=0},
+ },
+ {
+ name="3",
+ attach_offset={x=-4, y=8, z=-8},
+ view_offset={x=0, y=0, z=0},
+ },
+ {
+ name="4",
+ attach_offset={x=4, y=8, z=-8},
+ view_offset={x=0, y=0, z=0},
+ },
+ },
+ visual_size = {x=1, y=1},
+ wagon_span=3.1,
+ collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
+ drops={"default:steelblock 4"},
+}, "Passenger Wagon", "advtrains_wagon_inv.png")
+advtrains.register_wagon("wagon_box", {
+ mesh="advtrains_wagon.b3d",
+ textures = {"advtrains_wagon_box.png"},
+ drives_on={default=true},
+ max_speed=10,
+ seats = {},
+ visual_size = {x=1, y=1},
+ wagon_span=1.8,
+ collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
+ drops={"default:steelblock 4"},
+ has_inventory = true,
+ get_inventory_formspec = function(self)
+ return "size[8,11]"..
+ "list[detached:advtrains_wgn_"..self.unique_id..";box;0,0;8,6;]"..
+ "list[current_player;main;0,7;8,4;]"..
+ "listring[]"
+ end,
+ inventory_list_sizes = {
+ box=8*6,
+ },
+}, "Box Wagon", "advtrains_wagon_box_inv.png")
+
+minetest.register_craft({
+ output = 'advtrains:newlocomotive',
+ recipe = {
+ {'default:steelblock', 'default:steelblock', 'default:steelblock'},
+ {'default:steelblock', 'dye:black', 'default:steelblock'},
+ {'default:steelblock', 'default:steelblock', 'default:steelblock'},
+ },
+})
+minetest.register_craft({
+ output = 'advtrains:wagon_default',
+ recipe = {
+ {'default:steelblock', 'default:steelblock', 'default:steelblock'},
+ {'default:steelblock', 'dye:dark_green', 'default:steelblock'},
+ {'default:steelblock', 'default:steelblock', 'default:steelblock'},
+ },
+})
+minetest.register_craft({
+ output = 'advtrains:wagon_box',
+ recipe = {
+ {'default:steelblock', 'default:steelblock', 'default:steelblock'},
+ {'default:steelblock', 'default:chest', 'default:steelblock'},
+ {'default:steelblock', 'default:steelblock', 'default:steelblock'},
+ },
+})
diff --git a/advtrains/advtrains_train_steam/models/advtrains_detailed_steam_engine.b3d b/advtrains/advtrains_train_steam/models/advtrains_detailed_steam_engine.b3d
new file mode 100644
index 0000000..7418d8a
--- /dev/null
+++ b/advtrains/advtrains_train_steam/models/advtrains_detailed_steam_engine.b3d
Binary files differ
diff --git a/advtrains/advtrains_train_steam/models/advtrains_engine_steam.b3d b/advtrains/advtrains_train_steam/models/advtrains_engine_steam.b3d
new file mode 100644
index 0000000..6a92f57
--- /dev/null
+++ b/advtrains/advtrains_train_steam/models/advtrains_engine_steam.b3d
Binary files differ
diff --git a/advtrains/advtrains_train_steam/models/advtrains_passenger_wagon.b3d b/advtrains/advtrains_train_steam/models/advtrains_passenger_wagon.b3d
new file mode 100644
index 0000000..bb057f8
--- /dev/null
+++ b/advtrains/advtrains_train_steam/models/advtrains_passenger_wagon.b3d
Binary files differ
diff --git a/advtrains/advtrains_train_steam/models/advtrains_wagon.b3d b/advtrains/advtrains_train_steam/models/advtrains_wagon.b3d
new file mode 100644
index 0000000..5c8214c
--- /dev/null
+++ b/advtrains/advtrains_train_steam/models/advtrains_wagon.b3d
Binary files differ
diff --git a/advtrains/advtrains_train_steam/textures/advtrains_detailed_steam_engine.png b/advtrains/advtrains_train_steam/textures/advtrains_detailed_steam_engine.png
new file mode 100644
index 0000000..eab4dc8
--- /dev/null
+++ b/advtrains/advtrains_train_steam/textures/advtrains_detailed_steam_engine.png
Binary files differ
diff --git a/advtrains/advtrains_train_steam/textures/advtrains_engine_steam.png b/advtrains/advtrains_train_steam/textures/advtrains_engine_steam.png
new file mode 100644
index 0000000..4b27e77
--- /dev/null
+++ b/advtrains/advtrains_train_steam/textures/advtrains_engine_steam.png
Binary files differ
diff --git a/advtrains/advtrains_train_steam/textures/advtrains_engine_steam_inv.png b/advtrains/advtrains_train_steam/textures/advtrains_engine_steam_inv.png
new file mode 100644
index 0000000..8d3fafb
--- /dev/null
+++ b/advtrains/advtrains_train_steam/textures/advtrains_engine_steam_inv.png
Binary files differ
diff --git a/advtrains/advtrains_train_steam/textures/advtrains_wagon.png b/advtrains/advtrains_train_steam/textures/advtrains_wagon.png
new file mode 100644
index 0000000..c850518
--- /dev/null
+++ b/advtrains/advtrains_train_steam/textures/advtrains_wagon.png
Binary files differ
diff --git a/advtrains/advtrains_train_steam/textures/advtrains_wagon_box.png b/advtrains/advtrains_train_steam/textures/advtrains_wagon_box.png
new file mode 100644
index 0000000..8bfbe06
--- /dev/null
+++ b/advtrains/advtrains_train_steam/textures/advtrains_wagon_box.png
Binary files differ
diff --git a/advtrains/advtrains_train_steam/textures/advtrains_wagon_box_inv.png b/advtrains/advtrains_train_steam/textures/advtrains_wagon_box_inv.png
new file mode 100644
index 0000000..480f245
--- /dev/null
+++ b/advtrains/advtrains_train_steam/textures/advtrains_wagon_box_inv.png
Binary files differ
diff --git a/advtrains/advtrains_train_steam/textures/advtrains_wagon_inv.png b/advtrains/advtrains_train_steam/textures/advtrains_wagon_inv.png
new file mode 100644
index 0000000..0b72ac3
--- /dev/null
+++ b/advtrains/advtrains_train_steam/textures/advtrains_wagon_inv.png
Binary files differ
diff --git a/advtrains/advtrains_train_subway/depends.txt b/advtrains/advtrains_train_subway/depends.txt
new file mode 100644
index 0000000..6f00bf6
--- /dev/null
+++ b/advtrains/advtrains_train_subway/depends.txt
@@ -0,0 +1 @@
+advtrains \ No newline at end of file
diff --git a/advtrains/advtrains_train_subway/init.lua b/advtrains/advtrains_train_subway/init.lua
new file mode 100644
index 0000000..b105f1a
--- /dev/null
+++ b/advtrains/advtrains_train_subway/init.lua
@@ -0,0 +1,34 @@
+
+advtrains.register_wagon("subway_wagon", {
+ mesh="advtrains_subway_wagon.b3d",
+ textures = {"advtrains_subway_wagon.png"},
+ drives_on={default=true},
+ max_speed=15,
+ seats = {
+ {
+ name="Default Seat (driver stand)",
+ attach_offset={x=0, y=10, z=0},
+ view_offset={x=0, y=0, z=0},
+ driving_ctrl_access=true,
+ },
+ },
+ visual_size = {x=1, y=1},
+ wagon_span=2,
+ collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
+ is_locomotive=true,
+ drops={"default:steelblock 4"},
+ --custom_on_activate = function(self, dtime_s)
+ -- atprint("subway custom_on_activate")
+ -- self.object:set_animation({x=1,y=80}, 15, 0, true)
+ --end,
+}, "Subway Passenger Wagon", "advtrains_subway_wagon_inv.png")
+
+--wagons
+minetest.register_craft({
+ output = 'advtrains:subway_wagon',
+ recipe = {
+ {'default:steelblock', 'default:steelblock', 'default:steelblock'},
+ {'default:steelblock', 'dye:yellow', 'default:steelblock'},
+ {'default:steelblock', 'default:steelblock', 'default:steelblock'},
+ },
+})
diff --git a/advtrains/advtrains_train_subway/models/advtrains_subway_wagon.b3d b/advtrains/advtrains_train_subway/models/advtrains_subway_wagon.b3d
new file mode 100644
index 0000000..8f35769
--- /dev/null
+++ b/advtrains/advtrains_train_subway/models/advtrains_subway_wagon.b3d
Binary files differ
diff --git a/advtrains/advtrains_train_subway/textures/advtrains_subway_wagon.png b/advtrains/advtrains_train_subway/textures/advtrains_subway_wagon.png
new file mode 100644
index 0000000..079d797
--- /dev/null
+++ b/advtrains/advtrains_train_subway/textures/advtrains_subway_wagon.png
Binary files differ
diff --git a/advtrains/advtrains_train_subway/textures/advtrains_subway_wagon_inv.png b/advtrains/advtrains_train_subway/textures/advtrains_subway_wagon_inv.png
new file mode 100644
index 0000000..1d0e809
--- /dev/null
+++ b/advtrains/advtrains_train_subway/textures/advtrains_subway_wagon_inv.png
Binary files differ
diff --git a/advtrains/atc_command.txt b/advtrains/atc_command.txt
new file mode 100644
index 0000000..fa846e3
--- /dev/null
+++ b/advtrains/atc_command.txt
@@ -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/license.txt b/advtrains/license.txt
new file mode 100644
index 0000000..68a4b60
--- /dev/null
+++ b/advtrains/license.txt
@@ -0,0 +1,142 @@
+GNU LESSER GENERAL PUBLIC LICENSE
+
+Version 2.1, February 1999
+
+Copyright (C) 1991, 1999 Free Software Foundation, Inc.
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+Everyone is permitted to copy and distribute verbatim copies
+of this license document, but changing it is not allowed.
+
+[This is the first released version of the Lesser GPL. It also counts
+ as the successor of the GNU Library Public License, version 2, hence
+ the version number 2.1.]
+
+Preamble
+
+The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users.
+
+This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below.
+
+When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things.
+
+To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it.
+
+For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights.
+
+We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library.
+
+To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others.
+
+Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license.
+
+Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs.
+
+When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library.
+
+We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances.
+
+For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License.
+
+In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system.
+
+Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library.
+
+The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run.
+TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you".
+
+A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables.
+
+The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".)
+
+"Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library.
+
+Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does.
+
+1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library.
+
+You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee.
+
+2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions:
+
+ a) The modified work must itself be a software library.
+ b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change.
+ c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License.
+ d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful.
+
+ (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library.
+
+In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License.
+
+3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices.
+
+Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy.
+
+This option is useful when you wish to copy part of the code of the Library into a program that is not a library.
+
+4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange.
+
+If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code.
+
+5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License.
+
+However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables.
+
+When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law.
+
+If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.)
+
+Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself.
+
+6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications.
+
+You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things:
+
+ a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.)
+ b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with.
+ c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution.
+ d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place.
+ e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy.
+
+For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable.
+
+It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute.
+
+7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things:
+
+ a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above.
+ b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work.
+
+8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance.
+
+9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it.
+
+10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License.
+
+11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library.
+
+If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances.
+
+It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice.
+
+This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License.
+
+12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License.
+
+13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation.
+
+14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally.
+
+NO WARRANTY
+
+15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+END OF TERMS AND CONDITIONS
diff --git a/advtrains/license_media.txt b/advtrains/license_media.txt
new file mode 100644
index 0000000..c0da560
--- /dev/null
+++ b/advtrains/license_media.txt
@@ -0,0 +1,63 @@
+License
+
+THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.
+
+BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE MAY BE CONSIDERED TO BE A CONTRACT, THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.
+
+1. Definitions
+
+ "Adaptation" means a work based upon the Work, or upon the Work and other pre-existing works, such as a translation, adaptation, derivative work, arrangement of music or other alterations of a literary or artistic work, or phonogram or performance and includes cinematographic adaptations or any other form in which the Work may be recast, transformed, or adapted including in any form recognizably derived from the original, except that a work that constitutes a Collection will not be considered an Adaptation for the purpose of this License. For the avoidance of doubt, where the Work is a musical work, performance or phonogram, the synchronization of the Work in timed-relation with a moving image ("synching") will be considered an Adaptation for the purpose of this License.
+ "Collection" means a collection of literary or artistic works, such as encyclopedias and anthologies, or performances, phonograms or broadcasts, or other works or subject matter other than works listed in Section 1(g) below, which, by reason of the selection and arrangement of their contents, constitute intellectual creations, in which the Work is included in its entirety in unmodified form along with one or more other contributions, each constituting separate and independent works in themselves, which together are assembled into a collective whole. A work that constitutes a Collection will not be considered an Adaptation (as defined above) for the purposes of this License.
+ "Distribute" means to make available to the public the original and copies of the Work or Adaptation, as appropriate, through sale or other transfer of ownership.
+ "License Elements" means the following high-level license attributes as selected by Licensor and indicated in the title of this License: Attribution, Noncommercial, ShareAlike.
+ "Licensor" means the individual, individuals, entity or entities that offer(s) the Work under the terms of this License.
+ "Original Author" means, in the case of a literary or artistic work, the individual, individuals, entity or entities who created the Work or if no individual or entity can be identified, the publisher; and in addition (i) in the case of a performance the actors, singers, musicians, dancers, and other persons who act, sing, deliver, declaim, play in, interpret or otherwise perform literary or artistic works or expressions of folklore; (ii) in the case of a phonogram the producer being the person or legal entity who first fixes the sounds of a performance or other sounds; and, (iii) in the case of broadcasts, the organization that transmits the broadcast.
+ "Work" means the literary and/or artistic work offered under the terms of this License including without limitation any production in the literary, scientific and artistic domain, whatever may be the mode or form of its expression including digital form, such as a book, pamphlet and other writing; a lecture, address, sermon or other work of the same nature; a dramatic or dramatico-musical work; a choreographic work or entertainment in dumb show; a musical composition with or without words; a cinematographic work to which are assimilated works expressed by a process analogous to cinematography; a work of drawing, painting, architecture, sculpture, engraving or lithography; a photographic work to which are assimilated works expressed by a process analogous to photography; a work of applied art; an illustration, map, plan, sketch or three-dimensional work relative to geography, topography, architecture or science; a performance; a broadcast; a phonogram; a compilation of data to the extent it is protected as a copyrightable work; or a work performed by a variety or circus performer to the extent it is not otherwise considered a literary or artistic work.
+ "You" means an individual or entity exercising rights under this License who has not previously violated the terms of this License with respect to the Work, or who has received express permission from the Licensor to exercise rights under this License despite a previous violation.
+ "Publicly Perform" means to perform public recitations of the Work and to communicate to the public those public recitations, by any means or process, including by wire or wireless means or public digital performances; to make available to the public Works in such a way that members of the public may access these Works from a place and at a place individually chosen by them; to perform the Work to the public by any means or process and the communication to the public of the performances of the Work, including by public digital performance; to broadcast and rebroadcast the Work by any means including signs, sounds or images.
+ "Reproduce" means to make copies of the Work by any means including without limitation by sound or visual recordings and the right of fixation and reproducing fixations of the Work, including storage of a protected performance or phonogram in digital form or other electronic medium.
+
+2. Fair Dealing Rights. Nothing in this License is intended to reduce, limit, or restrict any uses free from copyright or rights arising from limitations or exceptions that are provided for in connection with the copyright protection under copyright law or other applicable laws.
+
+3. License Grant. Subject to the terms and conditions of this License, Licensor hereby grants You a worldwide, royalty-free, non-exclusive, perpetual (for the duration of the applicable copyright) license to exercise the rights in the Work as stated below:
+
+ to Reproduce the Work, to incorporate the Work into one or more Collections, and to Reproduce the Work as incorporated in the Collections;
+ to create and Reproduce Adaptations provided that any such Adaptation, including any translation in any medium, takes reasonable steps to clearly label, demarcate or otherwise identify that changes were made to the original Work. For example, a translation could be marked "The original work was translated from English to Spanish," or a modification could indicate "The original work has been modified.";
+ to Distribute and Publicly Perform the Work including as incorporated in Collections; and,
+ to Distribute and Publicly Perform Adaptations.
+
+The above rights may be exercised in all media and formats whether now known or hereafter devised. The above rights include the right to make such modifications as are technically necessary to exercise the rights in other media and formats. Subject to Section 8(f), all rights not expressly granted by Licensor are hereby reserved, including but not limited to the rights described in Section 4(e).
+
+4. Restrictions. The license granted in Section 3 above is expressly made subject to and limited by the following restrictions:
+
+ You may Distribute or Publicly Perform the Work only under the terms of this License. You must include a copy of, or the Uniform Resource Identifier (URI) for, this License with every copy of the Work You Distribute or Publicly Perform. You may not offer or impose any terms on the Work that restrict the terms of this License or the ability of the recipient of the Work to exercise the rights granted to that recipient under the terms of the License. You may not sublicense the Work. You must keep intact all notices that refer to this License and to the disclaimer of warranties with every copy of the Work You Distribute or Publicly Perform. When You Distribute or Publicly Perform the Work, You may not impose any effective technological measures on the Work that restrict the ability of a recipient of the Work from You to exercise the rights granted to that recipient under the terms of the License. This Section 4(a) applies to the Work as incorporated in a Collection, but this does not require the Collection apart from the Work itself to be made subject to the terms of this License. If You create a Collection, upon notice from any Licensor You must, to the extent practicable, remove from the Collection any credit as required by Section 4(d), as requested. If You create an Adaptation, upon notice from any Licensor You must, to the extent practicable, remove from the Adaptation any credit as required by Section 4(d), as requested.
+ You may Distribute or Publicly Perform an Adaptation only under: (i) the terms of this License; (ii) a later version of this License with the same License Elements as this License; (iii) a Creative Commons jurisdiction license (either this or a later license version) that contains the same License Elements as this License (e.g., Attribution-NonCommercial-ShareAlike 3.0 US) ("Applicable License"). You must include a copy of, or the URI, for Applicable License with every copy of each Adaptation You Distribute or Publicly Perform. You may not offer or impose any terms on the Adaptation that restrict the terms of the Applicable License or the ability of the recipient of the Adaptation to exercise the rights granted to that recipient under the terms of the Applicable License. You must keep intact all notices that refer to the Applicable License and to the disclaimer of warranties with every copy of the Work as included in the Adaptation You Distribute or Publicly Perform. When You Distribute or Publicly Perform the Adaptation, You may not impose any effective technological measures on the Adaptation that restrict the ability of a recipient of the Adaptation from You to exercise the rights granted to that recipient under the terms of the Applicable License. This Section 4(b) applies to the Adaptation as incorporated in a Collection, but this does not require the Collection apart from the Adaptation itself to be made subject to the terms of the Applicable License.
+ You may not exercise any of the rights granted to You in Section 3 above in any manner that is primarily intended for or directed toward commercial advantage or private monetary compensation. The exchange of the Work for other copyrighted works by means of digital file-sharing or otherwise shall not be considered to be intended for or directed toward commercial advantage or private monetary compensation, provided there is no payment of any monetary compensation in con-nection with the exchange of copyrighted works.
+ If You Distribute, or Publicly Perform the Work or any Adaptations or Collections, You must, unless a request has been made pursuant to Section 4(a), keep intact all copyright notices for the Work and provide, reasonable to the medium or means You are utilizing: (i) the name of the Original Author (or pseudonym, if applicable) if supplied, and/or if the Original Author and/or Licensor designate another party or parties (e.g., a sponsor institute, publishing entity, journal) for attribution ("Attribution Parties") in Licensor's copyright notice, terms of service or by other reasonable means, the name of such party or parties; (ii) the title of the Work if supplied; (iii) to the extent reasonably practicable, the URI, if any, that Licensor specifies to be associated with the Work, unless such URI does not refer to the copyright notice or licensing information for the Work; and, (iv) consistent with Section 3(b), in the case of an Adaptation, a credit identifying the use of the Work in the Adaptation (e.g., "French translation of the Work by Original Author," or "Screenplay based on original Work by Original Author"). The credit required by this Section 4(d) may be implemented in any reasonable manner; provided, however, that in the case of a Adaptation or Collection, at a minimum such credit will appear, if a credit for all contributing authors of the Adaptation or Collection appears, then as part of these credits and in a manner at least as prominent as the credits for the other contributing authors. For the avoidance of doubt, You may only use the credit required by this Section for the purpose of attribution in the manner set out above and, by exercising Your rights under this License, You may not implicitly or explicitly assert or imply any connection with, sponsorship or endorsement by the Original Author, Licensor and/or Attribution Parties, as appropriate, of You or Your use of the Work, without the separate, express prior written permission of the Original Author, Licensor and/or Attribution Parties.
+
+ For the avoidance of doubt:
+ Non-waivable Compulsory License Schemes. In those jurisdictions in which the right to collect royalties through any statutory or compulsory licensing scheme cannot be waived, the Licensor reserves the exclusive right to collect such royalties for any exercise by You of the rights granted under this License;
+ Waivable Compulsory License Schemes. In those jurisdictions in which the right to collect royalties through any statutory or compulsory licensing scheme can be waived, the Licensor reserves the exclusive right to collect such royalties for any exercise by You of the rights granted under this License if Your exercise of such rights is for a purpose or use which is otherwise than noncommercial as permitted under Section 4(c) and otherwise waives the right to collect royalties through any statutory or compulsory licensing scheme; and,
+ Voluntary License Schemes. The Licensor reserves the right to collect royalties, whether individually or, in the event that the Licensor is a member of a collecting society that administers voluntary licensing schemes, via that society, from any exercise by You of the rights granted under this License that is for a purpose or use which is otherwise than noncommercial as permitted under Section 4(c).
+ Except as otherwise agreed in writing by the Licensor or as may be otherwise permitted by applicable law, if You Reproduce, Distribute or Publicly Perform the Work either by itself or as part of any Adaptations or Collections, You must not distort, mutilate, modify or take other derogatory action in relation to the Work which would be prejudicial to the Original Author's honor or reputation. Licensor agrees that in those jurisdictions (e.g. Japan), in which any exercise of the right granted in Section 3(b) of this License (the right to make Adaptations) would be deemed to be a distortion, mutilation, modification or other derogatory action prejudicial to the Original Author's honor and reputation, the Licensor will waive or not assert, as appropriate, this Section, to the fullest extent permitted by the applicable national law, to enable You to reasonably exercise Your right under Section 3(b) of this License (right to make Adaptations) but not otherwise.
+
+5. Representations, Warranties and Disclaimer
+
+UNLESS OTHERWISE MUTUALLY AGREED TO BY THE PARTIES IN WRITING AND TO THE FULLEST EXTENT PERMITTED BY APPLICABLE LAW, LICENSOR OFFERS THE WORK AS-IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE WORK, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, ACCURACY, OR THE PRESENCE OF ABSENCE OF ERRORS, WHETHER OR NOT DISCOVERABLE. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED WARRANTIES, SO THIS EXCLUSION MAY NOT APPLY TO YOU.
+
+6. Limitation on Liability. EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE LAW, IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF THIS LICENSE OR THE USE OF THE WORK, EVEN IF LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+
+7. Termination
+
+ This License and the rights granted hereunder will terminate automatically upon any breach by You of the terms of this License. Individuals or entities who have received Adaptations or Collections from You under this License, however, will not have their licenses terminated provided such individuals or entities remain in full compliance with those licenses. Sections 1, 2, 5, 6, 7, and 8 will survive any termination of this License.
+ Subject to the above terms and conditions, the license granted here is perpetual (for the duration of the applicable copyright in the Work). Notwithstanding the above, Licensor reserves the right to release the Work under different license terms or to stop distributing the Work at any time; provided, however that any such election will not serve to withdraw this License (or any other license that has been, or is required to be, granted under the terms of this License), and this License will continue in full force and effect unless terminated as stated above.
+
+8. Miscellaneous
+
+ Each time You Distribute or Publicly Perform the Work or a Collection, the Licensor offers to the recipient a license to the Work on the same terms and conditions as the license granted to You under this License.
+ Each time You Distribute or Publicly Perform an Adaptation, Licensor offers to the recipient a license to the original Work on the same terms and conditions as the license granted to You under this License.
+ If any provision of this License is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this License, and without further action by the parties to this agreement, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable.
+ No term or provision of this License shall be deemed waived and no breach consented to unless such waiver or consent shall be in writing and signed by the party to be charged with such waiver or consent.
+ This License constitutes the entire agreement between the parties with respect to the Work licensed here. There are no understandings, agreements or representations with respect to the Work not specified here. Licensor shall not be bound by any additional provisions that may appear in any communication from You. This License may not be modified without the mutual written agreement of the Licensor and You.
+ The rights granted under, and the subject matter referenced, in this License were drafted utilizing the terminology of the Berne Convention for the Protection of Literary and Artistic Works (as amended on September 28, 1979), the Rome Convention of 1961, the WIPO Copyright Treaty of 1996, the WIPO Performances and Phonograms Treaty of 1996 and the Universal Copyright Convention (as revised on July 24, 1971). These rights and subject matter take effect in the relevant jurisdiction in which the License terms are sought to be enforced according to the corresponding provisions of the implementation of those treaty provisions in the applicable national law. If the standard suite of rights granted under applicable copyright law includes additional rights not granted under this License, such additional rights are deemed to be included in the License; this License is not intended to restrict the license of any rights under applicable law.
+
diff --git a/advtrains/manual.pdf b/advtrains/manual.pdf
new file mode 100644
index 0000000..e8c6380
--- /dev/null
+++ b/advtrains/manual.pdf
Binary files differ
diff --git a/advtrains/modpack.txt b/advtrains/modpack.txt
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/advtrains/modpack.txt
diff --git a/advtrains/readme.txt b/advtrains/readme.txt
new file mode 100644
index 0000000..40516e4
--- /dev/null
+++ b/advtrains/readme.txt
@@ -0,0 +1,25 @@
+
+## ADVTRAINS ## realistic trains in Minetest!
+by orwell96 and contributors(see below)
+
+For up-to-date information, visit https://forum.minetest.net/viewtopic.php?f=9&t=14726
+
+
+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
+
+License of code: LGPL 2.1
+License of media: CC-BY-NC-SA 3.0
+
+Contributions:
+
+Gravel Texture : from Minetest Game
+Initial rail model/texture : DS-minetest
+Models for signals/bumpers : mbb
+Steam engine / wagon texture: mbb
+Detailed Steam engine : mbb / Krokoschlange(animation)
+Industrial engine/wagons : mbb
+Inventory images : mbb
+Small code contributions : NaruTrey / gpcf
+Mod Description : hajo
+If I forgot someone please punish me for that. \ No newline at end of file
diff --git a/advtrains/screenshot.png b/advtrains/screenshot.png
new file mode 100644
index 0000000..78783e1
--- /dev/null
+++ b/advtrains/screenshot.png
Binary files differ