aboutsummaryrefslogtreecommitdiff
path: root/tracks.lua
diff options
context:
space:
mode:
authororwell96 <mono96.mml@gmail.com>2016-08-22 22:41:09 +0200
committerorwell96 <mono96.mml@gmail.com>2016-08-22 22:41:09 +0200
commit522a9ccd6818a14efe4886365e57b312d559d8db (patch)
treeee2ae877ea62944b8da34ccee0fe611a07d242d5 /tracks.lua
parent2593b1af1625f9cc3db879541f8425217646b652 (diff)
downloadadvtrains-522a9ccd6818a14efe4886365e57b312d559d8db.tar.gz
advtrains-522a9ccd6818a14efe4886365e57b312d559d8db.tar.bz2
advtrains-522a9ccd6818a14efe4886365e57b312d559d8db.zip
tidying up the tracks and trackworker/placer code and making rail registration a lot more modular
Diffstat (limited to 'tracks.lua')
-rw-r--r--tracks.lua504
1 files changed, 214 insertions, 290 deletions
diff --git a/tracks.lua b/tracks.lua
index 0f08e74..73d3033 100644
--- a/tracks.lua
+++ b/tracks.lua
@@ -26,7 +26,99 @@ vert2={
]]--
advtrains.all_tracktypes={}
-function advtrains.register_tracks(tracktype, def)
+--definition preparation
+local function conns(c1, c2, r1, r2, rh, rots) return {conn1=c1, conn2=c2, rely1=r1, rely2=r2, railheight=rh} end
+
+local 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),
+ },
+ switch={
+ swlst="swlcr",
+ swlcr="swlst",
+ swrst="swrcr",
+ swrcr="swrst",
+ },
+ trackplacer={
+ st=true,
+ cr=true,
+ },
+ tpsingle={
+ st=true,
+ },
+ tpdefault="st",
+ trackworker={
+ ["swrcr"]="st",
+ ["swrst"]="st",
+ ["st"]="cr",
+ ["cr"]="swlst",
+ ["swlcr"]="swrcr",
+ ["swlst"]="swrst",
+ },
+ rotation={"", "_30", "_45", "_60"},
+ increativeinv={vst1=true, vst2=true}
+}
+local 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),
+ },
+ switch={
+ swlst="swlcr",
+ swlcr="swlst",
+ swrst="swrcr",
+ swrcr="swrst",
+ },
+ trackplacer={
+ st=true,
+ cr=true,
+ },
+ tpsingle={
+ st=true,
+ },
+ tpdefault="st",
+ trackworker={
+ ["swrcr"]="st",
+ ["swrst"]="st",
+ ["st"]="cr",
+ ["cr"]="swlst",
+ ["swlcr"]="swrcr",
+ ["swlst"]="swrst",
+ },
+ rotation={"", "_45"},
+ increativeinv={vst1=true, vst2=true}
+}
+
+--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)
return function(pos, node)
if advtrains.is_train_at_pos(pos) then return end
@@ -35,115 +127,33 @@ function advtrains.register_tracks(tracktype, def)
advtrains.reset_trackdb_position(pos)
end
end
- local function make_overdef(img_suffix, conn1, conn2, switchfunc)
+ local function make_overdef(img_suffix, conns, switchfunc)
return {
- tiles = {def.texture_prefix.."_"..img_suffix..".png"},
+ 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",
- connect1=conn1,
- connect2=conn2,
+ connect1=conns.conn1,
+ connect2=conns.conn2,
+ rely1=conns.rely1 or 0,
+ rely2=conns.rely2 or 0,
+ railheight=conns.railheight or 0,
on_rightclick=switchfunc,
}
end
- local common_def=advtrains.merge_tables({
- description = def.description,
- drawtype = "mesh",
- mesh = "trackplane.b3d",
- 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},
- },
- groups = {
- attached_node=1,
- ["advtrains_track_"..tracktype]=1,
- dig_immediate=2,
- not_in_creative_inventory=1,
- },
- rely1=0,
- rely2=0,
- railheight=0,
- drop="advtrains:placetrack_"..tracktype,
- --on_rightclick=function(pos, node, clicker)
- -- minetest.set_node(pos, {name=node.name, param2=(node.param2+1)%4})
- --end
- 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,
- }, def.common or {})
- minetest.register_node(def.nodename_prefix.."_st", advtrains.merge_tables(common_def, make_overdef("st", 0, 8), def.straight or {}))
- minetest.register_node(def.nodename_prefix.."_st_45", advtrains.merge_tables(common_def, make_overdef("st_45", 2, 10), def.straight45 or {}))
-
- minetest.register_node(def.nodename_prefix.."_cr", advtrains.merge_tables(common_def, make_overdef("cr", 0, 6), def.curve or {}))
- minetest.register_node(def.nodename_prefix.."_cr_45", advtrains.merge_tables(common_def, make_overdef("cr_45", 2, 8), def.curve45 or {}))
-
- advtrains.trackplacer_register(def.nodename_prefix.."_st", 0, 8)
- advtrains.trackplacer_register(def.nodename_prefix.."_st_45", 2, 10)
- advtrains.trackplacer_register(def.nodename_prefix.."_cr", 0, 6)
- advtrains.trackplacer_register(def.nodename_prefix.."_cr_45", 2, 8)
-
-
- minetest.register_node(def.nodename_prefix.."_swl_st", advtrains.merge_tables(common_def, make_overdef("swl_st", 0, 8, make_switchfunc("swl_cr")), def.lswitchst or {}))
- minetest.register_node(def.nodename_prefix.."_swl_st_45", advtrains.merge_tables(common_def, make_overdef("swl_st_45", 2, 10, make_switchfunc("swl_cr_45")), def.lswitchst45 or {}))
- minetest.register_node(def.nodename_prefix.."_swl_cr", advtrains.merge_tables(common_def, make_overdef("swl_cr", 0, 6, make_switchfunc("swl_st")), def.lswitchcr or {}))
- minetest.register_node(def.nodename_prefix.."_swl_cr_45", advtrains.merge_tables(common_def, make_overdef("swl_cr_45", 2, 8, make_switchfunc("swl_st_45")), def.lswitchcr45 or {}))
-
- minetest.register_node(def.nodename_prefix.."_swr_st", advtrains.merge_tables(common_def, make_overdef("swr_st", 0, 8, make_switchfunc("swr_cr")), def.rswitchst or {}))
- minetest.register_node(def.nodename_prefix.."_swr_st_45", advtrains.merge_tables(common_def, make_overdef("swr_st_45", 2, 10, make_switchfunc("swr_cr_45")), def.rswitchst45 or {}))
- minetest.register_node(def.nodename_prefix.."_swr_cr", advtrains.merge_tables(common_def, make_overdef("swr_cr", 0, 10, make_switchfunc("swr_st")), def.rswitchcr or {}))
- minetest.register_node(def.nodename_prefix.."_swr_cr_45", advtrains.merge_tables(common_def, make_overdef("swr_cr_45", 2, 12, make_switchfunc("swr_st_45")), def.rswitchcr45 or {}))
-
- minetest.register_node(def.nodename_prefix.."_vert1", advtrains.merge_tables(common_def, make_overdef("vert1", 0, 8), {
- mesh = "trackvertical1.b3d",
- rely1=0,
- rely2=0.5,
- railheight=0.25,
- description = def.description.." (vertical track lower node)",
- }, def.vert1 or {}))
- minetest.register_node(def.nodename_prefix.."_vert2", advtrains.merge_tables(common_def, make_overdef("vert2", 0, 8), {
- mesh = "trackvertical2.b3d",
- rely1=0.5,
- rely2=1,
- railheight=0.75,
- description = def.description.." (vertical track upper node)",
- },def.vert2 or {}))
-
- advtrains.register_track_placer(def.nodename_prefix, def.texture_prefix, def.description)
- table.insert(advtrains.all_tracktypes, tracktype)
-end
-
-function advtrains.register_tracks_finer(tracktype, def)
- local function make_switchfunc(suffix_target)
- 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
- local function make_overdef(img_suffix, conn1, conn2, switchfunc)
+ local function cycle_conns(conns, rotid)
+ local add=(rotid-1)*preset.regstep
return {
- tiles = {def.texture_prefix.."_"..img_suffix..".png"},
- inventory_image = def.texture_prefix.."_"..img_suffix..".png",
- wield_image = def.texture_prefix.."_"..img_suffix..".png",
- connect1=conn1,
- connect2=conn2,
- on_rightclick=switchfunc,
+ 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",
- mesh = "trackplane.b3d",
paramtype="light",
paramtype2="facedir",
walkable = false,
@@ -155,15 +165,12 @@ function advtrains.register_tracks_finer(tracktype, def)
attached_node=1,
["advtrains_track_"..tracktype]=1,
dig_immediate=2,
- --not_in_creative_inventory=1,
+ not_in_creative_inventory=1,--NOTE see below when changing groups
},
rely1=0,
rely2=0,
railheight=0,
drop="advtrains:placetrack_"..tracktype,
- --on_rightclick=function(pos, node, clicker)
- -- minetest.set_node(pos, {name=node.name, param2=(node.param2+1)%4})
- --end
can_dig=function(pos)
return not advtrains.is_train_at_pos(pos)
end,
@@ -175,200 +182,47 @@ function advtrains.register_tracks_finer(tracktype, def)
advtrains.reset_trackdb_position(pos)
end,
}, def.common or {})
- minetest.register_node(def.nodename_prefix.."_st", advtrains.merge_tables(common_def, make_overdef("st", 0, 8), def.straight or {}))
- minetest.register_node(def.nodename_prefix.."_st_30", advtrains.merge_tables(common_def, make_overdef("st_30", 1, 9), def.straight30 or {}))
- minetest.register_node(def.nodename_prefix.."_st_45", advtrains.merge_tables(common_def, make_overdef("st_45", 2, 10), def.straight45 or {}))
- minetest.register_node(def.nodename_prefix.."_st_60", advtrains.merge_tables(common_def, make_overdef("st_60", 3, 11), def.straight60 or {}))
-
- minetest.register_node(def.nodename_prefix.."_cr", advtrains.merge_tables(common_def, make_overdef("cr", 0, 7), def.curve or {}))
- minetest.register_node(def.nodename_prefix.."_cr_30", advtrains.merge_tables(common_def, make_overdef("cr_30", 1, 8), def.curve45 or {}))
- minetest.register_node(def.nodename_prefix.."_cr_45", advtrains.merge_tables(common_def, make_overdef("cr_45", 2, 9), def.curve45 or {}))
- minetest.register_node(def.nodename_prefix.."_cr_60", advtrains.merge_tables(common_def, make_overdef("cr_60", 3, 10), def.curve45 or {}))
+ --make trackplacer base def
+ advtrains.trackplacer.register_tracktype(def.nodename_prefix, preset.tpdefault)
+ advtrains.trackplacer.register_track_placer(def.nodename_prefix, def.texture_prefix, def.description)
- --[[advtrains.trackplacer_register(def.nodename_prefix.."_st", 0, 8)
- advtrains.trackplacer_register(def.nodename_prefix.."_st_45", 2, 10)
- advtrains.trackplacer_register(def.nodename_prefix.."_cr", 0, 6)
- advtrains.trackplacer_register(def.nodename_prefix.."_cr_45", 2, 8)
- --]]
- --[[
- minetest.register_node(def.nodename_prefix.."_swl_st", advtrains.merge_tables(common_def, make_overdef("swl_st", 0, 8, make_switchfunc("swl_cr")), def.lswitchst or {}))
- minetest.register_node(def.nodename_prefix.."_swl_st_45", advtrains.merge_tables(common_def, make_overdef("swl_st_45", 2, 10, make_switchfunc("swl_cr_45")), def.lswitchst45 or {}))
- minetest.register_node(def.nodename_prefix.."_swl_cr", advtrains.merge_tables(common_def, make_overdef("swl_cr", 0, 6, make_switchfunc("swl_st")), def.lswitchcr or {}))
- minetest.register_node(def.nodename_prefix.."_swl_cr_45", advtrains.merge_tables(common_def, make_overdef("swl_cr_45", 2, 8, make_switchfunc("swl_st_45")), def.lswitchcr45 or {}))
-
- minetest.register_node(def.nodename_prefix.."_swr_st", advtrains.merge_tables(common_def, make_overdef("swr_st", 0, 8, make_switchfunc("swr_cr")), def.rswitchst or {}))
- minetest.register_node(def.nodename_prefix.."_swr_st_45", advtrains.merge_tables(common_def, make_overdef("swr_st_45", 2, 10, make_switchfunc("swr_cr_45")), def.rswitchst45 or {}))
- minetest.register_node(def.nodename_prefix.."_swr_cr", advtrains.merge_tables(common_def, make_overdef("swr_cr", 0, 10, make_switchfunc("swr_st")), def.rswitchcr or {}))
- minetest.register_node(def.nodename_prefix.."_swr_cr_45", advtrains.merge_tables(common_def, make_overdef("swr_cr_45", 2, 12, make_switchfunc("swr_st_45")), def.rswitchcr45 or {}))
-
- minetest.register_node(def.nodename_prefix.."_vert1", advtrains.merge_tables(common_def, make_overdef("vert1", 0, 8), {
- mesh = "trackvertical1.b3d",
- rely1=0,
- rely2=0.5,
- railheight=0.25,
- description = def.description.." (vertical track lower node)",
- }, def.vert1 or {}))
- minetest.register_node(def.nodename_prefix.."_vert2", advtrains.merge_tables(common_def, make_overdef("vert2", 0, 8), {
- mesh = "trackvertical2.b3d",
- rely1=0.5,
- rely2=1,
- railheight=0.75,
- description = def.description.." (vertical track upper node)",
- },def.vert2 or {}))
- ]]
-
- --we don't have texures yet
-
- advtrains.register_track_placer(def.nodename_prefix, def.texture_prefix, def.description)
- table.insert(advtrains.all_tracktypes, tracktype)
-end
-
---def must include: models_prefix, models_suffix(with dot)
--- def.shared_texture="full_name.png" if shared texture for all models is wanted
-function advtrains.register_tracks_modeled(tracktype, def)
- local function make_switchfunc(suffix_target)
- 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)
+ 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
+ if preset.switch[suffix] then
+ switchfunc=make_switchfunc(preset.switch[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
+ )
+ ),
+ preset.increativeinv[suffix] and {
+ groups = {--NOTE change groups here too
+ attached_node=1,
+ ["advtrains_track_"..tracktype]=1,
+ dig_immediate=2,
+ },
+ } or {}
+ )
+ --trackplacer
+ 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
+ advtrains.trackplacer.add_worked(def.nodename_prefix, suffix, rotation, preset.trackworker[suffix])
+ end
end
end
- local function make_overdef(img_suffix, conn1, conn2, switchfunc)
- return {
- mesh = 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",
- connect1=conn1,
- connect2=conn2,
- on_rightclick=switchfunc,
- }
- 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},
- },
- groups = {
- attached_node=1,
- ["advtrains_track_"..tracktype]=1,
- dig_immediate=2,
- not_in_creative_inventory=1,
- },
- rely1=0,
- rely2=0,
- railheight=0,
- drop="advtrains:placetrack_"..tracktype,
- --on_rightclick=function(pos, node, clicker)
- -- minetest.set_node(pos, {name=node.name, param2=(node.param2+1)%4})
- --end
- 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,
- }, def.common or {})
- minetest.register_node(def.nodename_prefix.."_st", advtrains.merge_tables(common_def, make_overdef("st", 0, 8), def.straight or {}))
- minetest.register_node(def.nodename_prefix.."_st_30", advtrains.merge_tables(common_def, make_overdef("st_30", 1, 9), def.straight30 or {}))
- minetest.register_node(def.nodename_prefix.."_st_45", advtrains.merge_tables(common_def, make_overdef("st_45", 2, 10), def.straight45 or {}))
- minetest.register_node(def.nodename_prefix.."_st_60", advtrains.merge_tables(common_def, make_overdef("st_60", 3, 11), def.straight60 or {}))
-
- minetest.register_node(def.nodename_prefix.."_cr", advtrains.merge_tables(common_def, make_overdef("cr", 0, 7), def.curve or {}))
- minetest.register_node(def.nodename_prefix.."_cr_30", advtrains.merge_tables(common_def, make_overdef("cr_30", 1, 8), def.curve30 or {}))
- minetest.register_node(def.nodename_prefix.."_cr_45", advtrains.merge_tables(common_def, make_overdef("cr_45", 2, 9), def.curve45 or {}))
- minetest.register_node(def.nodename_prefix.."_cr_60", advtrains.merge_tables(common_def, make_overdef("cr_60", 3, 10), def.curve60 or {}))
-
- minetest.register_node(def.nodename_prefix.."_vst1", advtrains.merge_tables(common_def, make_overdef("vst1", 8, 0),
- {
- rely1=0,
- rely2=0.5,
- railheight=0.25,
- },
- def.vst1 or {}))
- minetest.register_node(def.nodename_prefix.."_vst2", advtrains.merge_tables(common_def, make_overdef("vst2", 8, 0),
- {
- rely1=0.5,
- rely2=1,
- railheight=0.75,
- },
- def.vst2 or {}))
-
- advtrains.trackplacer_register(def.nodename_prefix.."_st", 0, 8)
- advtrains.trackplacer_register(def.nodename_prefix.."_st_30", 1, 9)
- advtrains.trackplacer_register(def.nodename_prefix.."_st_45", 2, 10)
- advtrains.trackplacer_register(def.nodename_prefix.."_st_60", 3, 11)
- advtrains.trackplacer_register(def.nodename_prefix.."_cr", 0, 7)
- advtrains.trackplacer_register(def.nodename_prefix.."_cr_30", 1, 8)
- advtrains.trackplacer_register(def.nodename_prefix.."_cr_45", 2, 9)
- advtrains.trackplacer_register(def.nodename_prefix.."_cr_60", 3, 10)
-
- --[[advtrains.trackplacer_register(def.nodename_prefix.."_st", 0, 8)
- advtrains.trackplacer_register(def.nodename_prefix.."_st_45", 2, 10)
- advtrains.trackplacer_register(def.nodename_prefix.."_cr", 0, 6)
- advtrains.trackplacer_register(def.nodename_prefix.."_cr_45", 2, 8)
- --]]
- --[[
- minetest.register_node(def.nodename_prefix.."_swl_st", advtrains.merge_tables(common_def, make_overdef("swl_st", 0, 8, make_switchfunc("swl_cr")), def.lswitchst or {}))
- minetest.register_node(def.nodename_prefix.."_swl_st_45", advtrains.merge_tables(common_def, make_overdef("swl_st_45", 2, 10, make_switchfunc("swl_cr_45")), def.lswitchst45 or {}))
- minetest.register_node(def.nodename_prefix.."_swl_cr", advtrains.merge_tables(common_def, make_overdef("swl_cr", 0, 6, make_switchfunc("swl_st")), def.lswitchcr or {}))
- minetest.register_node(def.nodename_prefix.."_swl_cr_45", advtrains.merge_tables(common_def, make_overdef("swl_cr_45", 2, 8, make_switchfunc("swl_st_45")), def.lswitchcr45 or {}))
-
- minetest.register_node(def.nodename_prefix.."_swr_st", advtrains.merge_tables(common_def, make_overdef("swr_st", 0, 8, make_switchfunc("swr_cr")), def.rswitchst or {}))
- minetest.register_node(def.nodename_prefix.."_swr_st_45", advtrains.merge_tables(common_def, make_overdef("swr_st_45", 2, 10, make_switchfunc("swr_cr_45")), def.rswitchst45 or {}))
- minetest.register_node(def.nodename_prefix.."_swr_cr", advtrains.merge_tables(common_def, make_overdef("swr_cr", 0, 10, make_switchfunc("swr_st")), def.rswitchcr or {}))
- minetest.register_node(def.nodename_prefix.."_swr_cr_45", advtrains.merge_tables(common_def, make_overdef("swr_cr_45", 2, 12, make_switchfunc("swr_st_45")), def.rswitchcr45 or {}))
-
- minetest.register_node(def.nodename_prefix.."_vert1", advtrains.merge_tables(common_def, make_overdef("vert1", 0, 8), {
- mesh = "trackvertical1.b3d",
- rely1=0,
- rely2=0.5,
- railheight=0.25,
- description = def.description.." (vertical track lower node)",
- }, def.vert1 or {}))
- minetest.register_node(def.nodename_prefix.."_vert2", advtrains.merge_tables(common_def, make_overdef("vert2", 0, 8), {
- mesh = "trackvertical2.b3d",
- rely1=0.5,
- rely2=1,
- railheight=0.75,
- description = def.description.." (vertical track upper node)",
- },def.vert2 or {}))
- ]]
-
- advtrains.register_track_placer(def.nodename_prefix, def.texture_prefix, def.description)
table.insert(advtrains.all_tracktypes, tracktype)
end
-advtrains.register_tracks("regular", {
- nodename_prefix="advtrains:track",
- texture_prefix="advtrains_track",
- description="Regular Train Track",
-})
-
-advtrains.register_tracks_finer("fineturns", {
- nodename_prefix="advtrains:olddtrack",
- texture_prefix="advtrains_dtrack",
- description="Fine Turn Train Track",
-})
-
-advtrains.register_tracks_modeled("default", {
- nodename_prefix="advtrains:dtrack",
- texture_prefix="advtrains_dtrack",
- models_prefix="advtrains_dtrack",
- models_suffix=".b3d",
- shared_texture="advtrains_dtrack_rail.png",
- description="New Default Train Track",
-})
function advtrains.is_track_and_drives_on(nodename, drives_on)
if not minetest.registered_nodes[nodename] then
@@ -393,6 +247,76 @@ function advtrains.get_track_connections(name, param2)
return (nodedef.connect1 + 4 * noderot)%16, (nodedef.connect2 + 4 * noderot)%16, nodedef.rely1 or 0, nodedef.rely2 or 0, nodedef.railheight or 0
end
+--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="Regular Train Track",
+ formats={vst1={}, vst2={}},
+}, 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="New Default Train Track",
+ formats={vst1={true}, vst2={true}, swlcr={}, swlst={}, swrcr={}, swrst={}},
+}, t_30deg)
+
+--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
+
+minetest.register_abm({
+-- In the following two fields, also group:groupname will work.
+ nodenames = {"advtrains:track_vert1"},
+ 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:dtrack_vst1", param2=(node.param2+2)%4}) end,
+})
+minetest.register_abm({
+-- In the following two fields, also group:groupname will work.
+ nodenames = {"advtrains:track_vert2"},
+ 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:dtrack_vst2", param2=(node.param2+2)%4}) end,
+})
+
+
="hl opt">} } static StkId adjust_varargs (lua_State *L, Proto *p, int actual) { int i; int nfixargs = p->numparams; Table *htab = NULL; StkId base, fixed; for (; actual < nfixargs; ++actual) setnilvalue(L->top++); #if defined(LUA_COMPAT_VARARG) if (p->is_vararg & VARARG_NEEDSARG) { /* compat. with old-style vararg? */ int nvar = actual - nfixargs; /* number of extra arguments */ lua_assert(p->is_vararg & VARARG_HASARG); luaC_checkGC(L); luaD_checkstack(L, p->maxstacksize); htab = luaH_new(L, nvar, 1); /* create `arg' table */ for (i=0; i<nvar; i++) /* put extra arguments into `arg' table */ setobj2n(L, luaH_setnum(L, htab, i+1), L->top - nvar + i); /* store counter in field `n' */ setnvalue(luaH_setstr(L, htab, luaS_newliteral(L, "n")), cast_num(nvar)); } #endif /* move fixed parameters to final position */ fixed = L->top - actual; /* first fixed argument */ base = L->top; /* final position of first argument */ for (i=0; i<nfixargs; i++) { setobjs2s(L, L->top++, fixed+i); setnilvalue(fixed+i); } /* add `arg' parameter */ if (htab) { sethvalue(L, L->top++, htab); lua_assert(iswhite(obj2gco(htab))); } return base; } static StkId tryfuncTM (lua_State *L, StkId func) { const TValue *tm = luaT_gettmbyobj(L, func, TM_CALL); StkId p; ptrdiff_t funcr = savestack(L, func); if (!ttisfunction(tm)) luaG_typeerror(L, func, "call"); /* Open a hole inside the stack at `func' */ for (p = L->top; p > func; p--) setobjs2s(L, p, p-1); incr_top(L); func = restorestack(L, funcr); /* previous call may change stack */ setobj2s(L, func, tm); /* tag method is the new function to be called */ return func; } #define inc_ci(L) \ ((L->ci == L->end_ci) ? growCI(L) : \ (condhardstacktests(luaD_reallocCI(L, L->size_ci)), ++L->ci)) int luaD_precall (lua_State *L, StkId func, int nresults) { LClosure *cl; ptrdiff_t funcr; if (!ttisfunction(func)) /* `func' is not a function? */ func = tryfuncTM(L, func); /* check the `function' tag method */ funcr = savestack(L, func); cl = &clvalue(func)->l; L->ci->savedpc = L->savedpc; if (!cl->isC) { /* Lua function? prepare its call */ CallInfo *ci; StkId st, base; Proto *p = cl->p; luaD_checkstack(L, p->maxstacksize); func = restorestack(L, funcr); if (!p->is_vararg) { /* no varargs? */ base = func + 1; if (L->top > base + p->numparams) L->top = base + p->numparams; } else { /* vararg function */ int nargs = cast_int(L->top - func) - 1; base = adjust_varargs(L, p, nargs); func = restorestack(L, funcr); /* previous call may change the stack */ } ci = inc_ci(L); /* now `enter' new function */ ci->func = func; L->base = ci->base = base; ci->top = L->base + p->maxstacksize; lua_assert(ci->top <= L->stack_last); L->savedpc = p->code; /* starting point */ ci->tailcalls = 0; ci->nresults = nresults; for (st = L->top; st < ci->top; st++) setnilvalue(st); L->top = ci->top; if (L->hookmask & LUA_MASKCALL) { L->savedpc++; /* hooks assume 'pc' is already incremented */ luaD_callhook(L, LUA_HOOKCALL, -1); L->savedpc--; /* correct 'pc' */ } return PCRLUA; } else { /* if is a C function, call it */ CallInfo *ci; int n; luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */ ci = inc_ci(L); /* now `enter' new function */ ci->func = restorestack(L, funcr); L->base = ci->base = ci->func + 1; ci->top = L->top + LUA_MINSTACK; lua_assert(ci->top <= L->stack_last); ci->nresults = nresults; if (L->hookmask & LUA_MASKCALL) luaD_callhook(L, LUA_HOOKCALL, -1); lua_unlock(L); n = (*curr_func(L)->c.f)(L); /* do the actual call */ lua_lock(L); if (n < 0) /* yielding? */ return PCRYIELD; else { luaD_poscall(L, L->top - n); return PCRC; } } } static StkId callrethooks (lua_State *L, StkId firstResult) { ptrdiff_t fr = savestack(L, firstResult); /* next call may change stack */ luaD_callhook(L, LUA_HOOKRET, -1); if (f_isLua(L->ci)) { /* Lua function? */ while ((L->hookmask & LUA_MASKRET) && L->ci->tailcalls--) /* tail calls */ luaD_callhook(L, LUA_HOOKTAILRET, -1); } return restorestack(L, fr); } int luaD_poscall (lua_State *L, StkId firstResult) { StkId res; int wanted, i; CallInfo *ci; if (L->hookmask & LUA_MASKRET) firstResult = callrethooks(L, firstResult); ci = L->ci--; res = ci->func; /* res == final position of 1st result */ wanted = ci->nresults; L->base = (ci - 1)->base; /* restore base */ L->savedpc = (ci - 1)->savedpc; /* restore savedpc */ /* move results to correct place */ for (i = wanted; i != 0 && firstResult < L->top; i--) setobjs2s(L, res++, firstResult++); while (i-- > 0) setnilvalue(res++); L->top = res; return (wanted - LUA_MULTRET); /* 0 iff wanted == LUA_MULTRET */ } /* ** Call a function (C or Lua). The function to be called is at *func. ** The arguments are on the stack, right after the function. ** When returns, all the results are on the stack, starting at the original ** function position. */ void luaD_call (lua_State *L, StkId func, int nResults) { if (++L->nCcalls >= LUAI_MAXCCALLS) { if (L->nCcalls == LUAI_MAXCCALLS) luaG_runerror(L, "C stack overflow"); else if (L->nCcalls >= (LUAI_MAXCCALLS + (LUAI_MAXCCALLS>>3))) luaD_throw(L, LUA_ERRERR); /* error while handing stack error */ } if (luaD_precall(L, func, nResults) == PCRLUA) /* is a Lua function? */ luaV_execute(L, 1); /* call it */ L->nCcalls--; luaC_checkGC(L); } static void resume (lua_State *L, void *ud) { StkId firstArg = cast(StkId, ud); CallInfo *ci = L->ci; if (L->status == 0) { /* start coroutine? */ lua_assert(ci == L->base_ci && firstArg > L->base); if (luaD_precall(L, firstArg - 1, LUA_MULTRET) != PCRLUA) return; } else { /* resuming from previous yield */ lua_assert(L->status == LUA_YIELD); L->status = 0; if (!f_isLua(ci)) { /* `common' yield? */ /* finish interrupted execution of `OP_CALL' */ lua_assert(GET_OPCODE(*((ci-1)->savedpc - 1)) == OP_CALL || GET_OPCODE(*((ci-1)->savedpc - 1)) == OP_TAILCALL); if (luaD_poscall(L, firstArg)) /* complete it... */ L->top = L->ci->top; /* and correct top if not multiple results */ } else /* yielded inside a hook: just continue its execution */ L->base = L->ci->base; } luaV_execute(L, cast_int(L->ci - L->base_ci)); } static int resume_error (lua_State *L, const char *msg) { L->top = L->ci->base; setsvalue2s(L, L->top, luaS_new(L, msg)); incr_top(L); lua_unlock(L); return LUA_ERRRUN; } LUA_API int lua_resume (lua_State *L, int nargs) { int status; lua_lock(L); if (L->status != LUA_YIELD && (L->status != 0 || L->ci != L->base_ci)) return resume_error(L, "cannot resume non-suspended coroutine"); if (L->nCcalls >= LUAI_MAXCCALLS) return resume_error(L, "C stack overflow"); luai_userstateresume(L, nargs); lua_assert(L->errfunc == 0); L->baseCcalls = ++L->nCcalls; status = luaD_rawrunprotected(L, resume, L->top - nargs); if (status != 0) { /* error? */ L->status = cast_byte(status); /* mark thread as `dead' */ luaD_seterrorobj(L, status, L->top); L->ci->top = L->top; } else { lua_assert(L->nCcalls == L->baseCcalls); status = L->status; } --L->nCcalls; lua_unlock(L); return status; } LUA_API int lua_yield (lua_State *L, int nresults) { luai_userstateyield(L, nresults); lua_lock(L); if (L->nCcalls > L->baseCcalls) luaG_runerror(L, "attempt to yield across metamethod/C-call boundary"); L->base = L->top - nresults; /* protect stack slots below */ L->status = LUA_YIELD; lua_unlock(L); return -1; } int luaD_pcall (lua_State *L, Pfunc func, void *u, ptrdiff_t old_top, ptrdiff_t ef) { int status; unsigned short oldnCcalls = L->nCcalls; ptrdiff_t old_ci = saveci(L, L->ci); lu_byte old_allowhooks = L->allowhook; ptrdiff_t old_errfunc = L->errfunc; L->errfunc = ef; status = luaD_rawrunprotected(L, func, u); if (status != 0) { /* an error occurred? */ StkId oldtop = restorestack(L, old_top); luaF_close(L, oldtop); /* close eventual pending closures */ luaD_seterrorobj(L, status, oldtop); L->nCcalls = oldnCcalls; L->ci = restoreci(L, old_ci); L->base = L->ci->base; L->savedpc = L->ci->savedpc; L->allowhook = old_allowhooks; restore_stack_limit(L); } L->errfunc = old_errfunc; return status; } /* ** Execute a protected parser. */ struct SParser { /* data to `f_parser' */ ZIO *z; Mbuffer buff; /* buffer to be used by the scanner */ const char *name; }; static void f_parser (lua_State *L, void *ud) { int i; Proto *tf; Closure *cl; struct SParser *p = cast(struct SParser *, ud); int c = luaZ_lookahead(p->z); luaC_checkGC(L); tf = ((c == LUA_SIGNATURE[0]) ? luaU_undump : luaY_parser)(L, p->z, &p->buff, p->name); cl = luaF_newLclosure(L, tf->nups, hvalue(gt(L))); cl->l.p = tf; for (i = 0; i < tf->nups; i++) /* initialize eventual upvalues */ cl->l.upvals[i] = luaF_newupval(L); setclvalue(L, L->top, cl); incr_top(L); } int luaD_protectedparser (lua_State *L, ZIO *z, const char *name) { struct SParser p; int status; p.z = z; p.name = name; luaZ_initbuffer(L, &p.buff); status = luaD_pcall(L, f_parser, &p, savestack(L, L->top), L->errfunc); luaZ_freebuffer(L, &p.buff); return status; }