diff options
author | orwell96 <mono96.mml@gmail.com> | 2016-09-13 14:44:35 +0200 |
---|---|---|
committer | orwell96 <mono96.mml@gmail.com> | 2016-09-13 14:44:35 +0200 |
commit | 1e93892d8ab8492a0f90a4e55806fc06ff6cb437 (patch) | |
tree | 33036b450c5347bfdc9db7af5aefb6dae9fedfa4 | |
parent | d3af97b63e92c84f1857483aa49fb677acaff541 (diff) | |
download | advtrains-1e93892d8ab8492a0f90a4e55806fc06ff6cb437.tar.gz advtrains-1e93892d8ab8492a0f90a4e55806fc06ff6cb437.tar.bz2 advtrains-1e93892d8ab8492a0f90a4e55806fc06ff6cb437.zip |
add mesecon support for switches and signals
-rw-r--r-- | signals.lua | 2 | ||||
-rw-r--r-- | tracks.lua | 29 |
2 files changed, 24 insertions, 7 deletions
diff --git a/signals.lua b/signals.lua index 44fe621..118d16e 100644 --- a/signals.lua +++ b/signals.lua @@ -20,7 +20,7 @@ for r,f in pairs({on="off", off="on"}) do not_blocking_trains=1 }, mesecons = {effector = { - action_on = function (pos, node) + ["action_"..f] = function (pos, node) minetest.swap_node(pos, {name = "advtrains:retrosignal_"..f, param2 = node.param2}) end }}, @@ -64,6 +64,12 @@ local t_30deg={ swrst="swrcr",
swrcr="swrst",
},
+ switchmc={
+ swlst="on",
+ swlcr="off",
+ swrst="on",
+ swrcr="off",
+ },
trackplacer={
st=true,
cr=true,
@@ -111,6 +117,12 @@ local t_45deg={ swrst="swrcr",
swrcr="swrst",
},
+ switchmc={
+ swlst="on",
+ swlcr="off",
+ swrst="on",
+ swrcr="off",
+ },
trackplacer={
st=true,
cr=true,
@@ -146,15 +158,19 @@ local t_45deg={ common={} change something on common rail appearance
}]]
function advtrains.register_tracks(tracktype, def, preset)
- local function make_switchfunc(suffix_target)
+ local function make_switchfunc(suffix_target, mesecon_state)
return function(pos, node)
if advtrains.is_train_at_pos(pos) then return end
advtrains.invalidate_all_paths()
minetest.set_node(pos, {name=def.nodename_prefix.."_"..suffix_target, param2=node.param2})
advtrains.reset_trackdb_position(pos)
- end
+ end, {effector = {
+ ["action_"..mesecon_state] = function (pos, node)
+ minetest.swap_node(pos, {name=def.nodename_prefix.."_"..suffix_target, param2=node.param2})
+ end
+ }}
end
- local function make_overdef(suffix, rotation, conns, switchfunc, in_creative_inv)
+ local function make_overdef(suffix, rotation, conns, switchfunc, mesecontbl, in_creative_inv)
local img_suffix=suffix..rotation
return {
mesh = def.shared_model or (def.models_prefix.."_"..img_suffix..def.models_suffix),
@@ -175,6 +191,7 @@ function advtrains.register_tracks(tracktype, def, preset) not_in_creative_inventory=(not in_creative_inv and 1 or nil),
not_blocking_trains=1,
},
+ mesecons=mesecontbl,
}
end
local function cycle_conns(conns, rotid)
@@ -219,16 +236,16 @@ function advtrains.register_tracks(tracktype, def, preset) 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
+ local switchfunc, mesecontbl
if preset.switch[suffix] then
- switchfunc=make_switchfunc(preset.switch[suffix]..rotation)
+ switchfunc, mesecontbl=make_switchfunc(preset.switch[suffix]..rotation, preset.switchmc[suffix])
end
minetest.register_node(def.nodename_prefix.."_"..suffix..rotation, advtrains.merge_tables(
common_def,
make_overdef(
suffix, rotation,
cycle_conns(conns, rotid),
- switchfunc, preset.increativeinv[suffix]
+ switchfunc, mesecontbl, preset.increativeinv[suffix]
)
)
)
|