aboutsummaryrefslogtreecommitdiff
path: root/advtrains
diff options
context:
space:
mode:
Diffstat (limited to 'advtrains')
-rw-r--r--advtrains/init.lua35
-rw-r--r--advtrains/nodedb.lua4
-rw-r--r--advtrains/tracks.lua2
-rw-r--r--advtrains/wagons.lua4
4 files changed, 37 insertions, 8 deletions
diff --git a/advtrains/init.lua b/advtrains/init.lua
index fd56d6d..d21a887 100644
--- a/advtrains/init.lua
+++ b/advtrains/init.lua
@@ -26,17 +26,33 @@ minetest.log("action", "[advtrains] Loading...")
attrans = minetest.get_translator ("advtrains")
--advtrains
+advtrains = {trains={}, player_to_train_mapping={}}
+-- =======================Development/debugging settings=====================
+-- DO NOT USE FOR NORMAL OPERATION
local DUMP_DEBUG_SAVE = false
+-- dump the save files in human-readable format into advtrains_DUMP
+
local GENERATE_ATRICIFIAL_LAG = false
local HOW_MANY_LAG = 1.0
+-- Simulate a higher server step interval, as it occurs when the server is on high load
+
+advtrains.IGNORE_WORLD = false
+-- Run advtrains without respecting the world map
+-- - No world collision checks occur
+-- - The NDB forcibly places all nodes stored in it into the world regardless of the world's content.
+-- - Rails do not set the 'attached_node' group
+-- This mode can be useful for debugging/testing a world without the map data available
+-- In this case, choose 'singlenode' as mapgen
+
+local NO_SAVE = false
+-- Do not save any data to advtrains save files
+-- ==========================================================================
--Constant for maximum connection value/division of the circle
AT_CMAX = 16
-advtrains = {trains={}, player_to_train_mapping={}}
-
-- get wagon loading range
advtrains.wagon_load_range = tonumber(minetest.settings:get("advtrains_wagon_load_range"))
if not advtrains.wagon_load_range then
@@ -622,6 +638,18 @@ function advtrains.save(remove_players_from_wagons)
atwarn("Instructed to save() but load() was never called!")
return
end
+
+ -- Cleanup actions
+ --TODO very simple yet hacky workaround for the "green signals" bug
+ advtrains.invalidate_all_paths()
+
+ if advtrains.IGNORE_WORLD then
+ advtrains.ndb.restore_all()
+ end
+
+ if NO_SAVE then
+ return
+ end
if no_action then
atlog("[save] Saving requested externally, but Advtrains step is disabled. Not saving any data as state may be inconsistent.")
return
@@ -632,9 +660,6 @@ function advtrains.save(remove_players_from_wagons)
atlatc.save()
end
atprint("[save_all]Saved advtrains save files")
-
- --TODO very simple yet hacky workaround for the "green signals" bug
- advtrains.invalidate_all_paths()
end
minetest.register_on_shutdown(advtrains.save)
diff --git a/advtrains/nodedb.lua b/advtrains/nodedb.lua
index 4539529..ca7b195 100644
--- a/advtrains/nodedb.lua
+++ b/advtrains/nodedb.lua
@@ -281,6 +281,8 @@ function advtrains.get_rail_info_at(pos, drives_on)
return true, conns, railheight
end
+local IGNORE_WORLD = advtrains.IGNORE_WORLD
+
ndb.run_lbm = function(pos, node)
local cid=ndbget(pos.x, pos.y, pos.z)
if cid then
@@ -335,7 +337,7 @@ ndb.restore_all = function()
if node then
local ori_ndef=minetest.registered_nodes[node.name]
local ndbnode=ndb.get_node_raw(pos)
- if ori_ndef and ori_ndef.groups.save_in_at_nodedb then --check if this node has been worldedited, and don't replace then
+ if (ori_ndef and ori_ndef.groups.save_in_at_nodedb) or IGNORE_WORLD then --check if this node has been worldedited, and don't replace then
if (ndbnode.name~=node.name or ndbnode.param2~=node.param2) then
minetest.swap_node(pos, ndbnode)
--atlog("Replaced",node.name,"@",pos,"with",ndbnode.name)
diff --git a/advtrains/tracks.lua b/advtrains/tracks.lua
index 7037244..ba59720 100644
--- a/advtrains/tracks.lua
+++ b/advtrains/tracks.lua
@@ -469,7 +469,7 @@ function advtrains.register_tracks(tracktype, def, preset)
tiles = {def.shared_texture or (def.texture_prefix.."_"..img_suffix..".png"), def.second_texture},
groups = {
- attached_node=1,
+ attached_node = advtrains.IGNORE_WORLD and 0 or 1,
advtrains_track=1,
["advtrains_track_"..tracktype]=1,
save_in_at_nodedb=1,
diff --git a/advtrains/wagons.lua b/advtrains/wagons.lua
index 4e7fb26..7b6a381 100644
--- a/advtrains/wagons.lua
+++ b/advtrains/wagons.lua
@@ -10,6 +10,8 @@
-- TP delay when getting off wagon
local GETOFF_TP_DELAY = 0.5
+local IGNORE_WORLD = advtrains.IGNORE_WORLD
+
advtrains.wagons = {}
advtrains.wagon_prototypes = {}
advtrains.wagon_objects = {}
@@ -446,7 +448,7 @@ function wagon:on_step(dtime)
end
--checking for environment collisions(a 3x3 cube around the center)
- if is_in_loaded_area and not train.recently_collided_with_env then
+ if not IGNORE_WORLD and is_in_loaded_area and not train.recently_collided_with_env then
local collides=false
local exh = self.extent_h or 1
local exv = self.extent_v or 2
pan>path_cn[index] == 1) -- speed tvel=train.velocity end end local customfct={ atc_send = function(cmd) if not train_id then return false end assertt(cmd, "string") advtrains.atc.train_set_command(train, cmd, atc_arrow) return true end, split_at_index = function(index, cmd) if not train_id then return false end assertt(cmd, "string") if type(index) ~= "number" then return false end local new_id = advtrains.split_train_at_index(train, index) if new_id then minetest.after(1,advtrains.atc.train_set_command,advtrains.trains[new_id], cmd, atc_arrow) return true end return false end, split_at_fc = function(cmd, len) assertt(cmd, "string") if not train_id then return false end local new_id, fc = advtrains.split_train_at_fc(train, false, len) if new_id then minetest.after(1,advtrains.atc.train_set_command,advtrains.trains[new_id], cmd, atc_arrow) end return fc or "" end, split_off_locomotive = function(cmd, len) assertt(cmd, "string") if not train_id then return false end local new_id, fc = advtrains.split_train_at_fc(train, true, len) if new_id then minetest.after(1,advtrains.atc.train_set_command,advtrains.trains[new_id], cmd, atc_arrow) end end, train_length = function () if not train_id then return false end return #train.trainparts end, step_fc = function() if not train_id then return false end advtrains.train_step_fc(train) end, set_shunt = function() -- enable shunting mode if not train_id then return false end train.is_shunt = true end, unset_shunt = function() if not train_id then return false end train.is_shunt = nil end, set_autocouple = function () if not train_id then return false end train.autocouple = true end, unset_autocouple = function () if not train_id then return false end train.autocouple = nil end, set_line = function(line) if type(line)~="string" and type(line)~="number" then return false end train.line = line .. "" minetest.after(0, advtrains.invalidate_path, train_id) return true end, get_line = function() return train.line end, set_rc = function(rc) if type(rc)~="string"then return false end train.routingcode = rc minetest.after(0, advtrains.invalidate_path, train_id) return true end, get_rc = function() return train.routingcode end, atc_reset = function(cmd) if not train_id then return false end assertt(cmd, "string") advtrains.atc.train_reset_command(train) return true end, atc_arrow = atc_arrow, atc_id = train_id, atc_speed = tvel, atc_set_text_outside = function(text) if not train_id then return false end if text then assertt(text, "string") end advtrains.trains[train_id].text_outside=text return true end, atc_set_text_inside = function(text) if not train_id then return false end if text then assertt(text, "string") end advtrains.trains[train_id].text_inside=text return true end, atc_set_lzb_tsr = function(speed) if not appr_internal then error("atc_set_lzb_tsr() can only be used during 'approach' events!") end assert(tonumber(speed), "Number expected!") local index = appr_internal.index advtrains.lzb_add_checkpoint(train, index, speed, nil) return true end, } -- interlocking specific if advtrains.interlocking then customfct.atc_set_ars_disable = function(value) advtrains.interlocking.ars_set_disable(train, value) end end atlatc.active.run_in_env(pos, evtdata, customfct) end advtrains.register_tracks("default", { nodename_prefix="advtrains_luaautomation:dtrack", texture_prefix="advtrains_dtrack_atc", models_prefix="advtrains_dtrack", models_suffix=".b3d", shared_texture="advtrains_dtrack_shared_atc.png", description=atltrans("LuaAutomation ATC Rail"), formats={}, get_additional_definiton = function(def, preset, suffix, rotation) return { after_place_node = atlatc.active.after_place_node, after_dig_node = atlatc.active.after_dig_node, on_receive_fields = function(pos, ...) atlatc.active.on_receive_fields(pos, ...) --set arrowconn (for ATC) local ph=minetest.pos_to_string(pos) local _, conns=advtrains.get_rail_info_at(pos, advtrains.all_tracktypes) atlatc.active.nodes[ph].arrowconn=conns[1].c end, advtrains = { on_train_enter = function(pos, train_id, train, index) --do async. Event is fired in train steps atlatc.interrupt.add(0, pos, {type="train", train=true, id=train_id, _train_id = train_id, _train_arrow = (train.path_cn[index] == 1)}) end, on_train_approach = function(pos, train_id, train, index, has_entered, lzbdata) -- Insert an event only if the rail indicated that it supports approach callbacks local ph=minetest.pos_to_string(pos) local railtbl = atlatc.active.nodes[ph] -- uses a "magic variable" in the local environment of the node -- This hack is necessary because code might not be prepared to get approach events... if railtbl and railtbl.data and railtbl.data.__approach_callback_mode then local acm = railtbl.data.__approach_callback_mode local in_arrow = (train.path_cn[index] == 1) if acm==2 or (acm==1 and in_arrow) then local evtdata = {type="approach", approach=true, id=train_id, has_entered = has_entered, _train_id = train_id, _train_arrow = in_arrow} -- reuses code from train_enter -- This event is *required* to run synchronously, because it might set the ars_disable flag on the train and add LZB checkpoints, -- although this is generally discouraged because this happens right in a train step -- At this moment, I am not aware whether this may cause side effects, and I must encourage users not to do expensive calculations here. r.fire_event(pos, evtdata, {train_id = train_id, train = train, index = index, lzbdata = lzbdata}) end end end, }, luaautomation = { fire_event=r.fire_event }, digiline = { receptor = {}, effector = { action = atlatc.active.on_digiline_receive }, }, } end, }, advtrains.trackpresets.t_30deg_straightonly) atlatc.rail = r