Fix multiple track types not working simultaneously

Bug was caused by the drives_on table of every train and advtrains.all_tracktypes
sharing the same reference, which caused advtrains.all_tracktypes to become the
intersection of all train drives_on's in the world.
However, this did become empty, causing nothing to work anymore.
master
orwell96 2017-11-22 23:13:42 +01:00
parent 2d4833b5a8
commit 5fc6cc7f5b
2 changed files with 12 additions and 2 deletions

View File

@ -408,11 +408,19 @@ end
function advtrains.is_track_and_drives_on(nodename, drives_on_p)
local drives_on = drives_on_p
if not drives_on then drives_on = advtrains.all_tracktypes end
local hasentry = false
for _,_ in pairs(drives_on) do
hasentry=true
end
if not hasentry then drives_on = advtrains.all_tracktypes end
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
for k,v in pairs(drives_on) do
if nodedef.groups["advtrains_track_"..k] then
return true
end

View File

@ -576,6 +576,7 @@ function advtrains.train_step_b(id, train, dtime)
end
--- 8b damage players ---
if not minetest.settings:get_bool("creative_mode") then
local testpts = minetest.pos_to_string(testpos)
local player=advtrains.playersbypts[testpts]
if player and not minetest.check_player_privs(player, "creative") and train.velocity>3 then
--instantly kill player
@ -644,7 +645,8 @@ function advtrains.add_wagon_to_train(wagon, train_id, index)
end
function advtrains.update_trainpart_properties(train_id, invert_flipstate)
local train=advtrains.trains[train_id]
train.drives_on=advtrains.all_tracktypes
train.drives_on=advtrains.merge_tables(advtrains.all_tracktypes)
--FIX: deep-copy the table!!!
train.max_speed=20
local rel_pos=0
local count_l=0