diff options
-rw-r--r-- | advtrains/path.lua | 91 | ||||
-rw-r--r-- | advtrains/trainlogic.lua | 3 | ||||
-rw-r--r-- | advtrains/wagons.lua | 8 | ||||
-rw-r--r-- | advtrains_interlocking/route_ui.lua | 4 | ||||
-rw-r--r-- | advtrains_interlocking/tcb_ts_ui.lua | 12 | ||||
-rw-r--r-- | advtrains_line_automation/railwaytime.lua | 7 | ||||
-rw-r--r-- | advtrains_line_automation/stoprail.lua | 2 | ||||
-rw-r--r-- | advtrains_luaautomation/active_common.lua | 2 | ||||
-rw-r--r-- | advtrains_luaautomation/init.lua | 3 | ||||
-rw-r--r-- | advtrains_luaautomation/pcnaming.lua | 2 | ||||
-rw-r--r-- | advtrains_signals_ks/init.lua | 4 | ||||
-rw-r--r-- | advtrains_train_industrial/init.lua | 4 | ||||
-rw-r--r-- | advtrains_train_japan/init.lua | 2 | ||||
-rwxr-xr-x | advtrains_train_steam/init.lua | 5 | ||||
-rw-r--r-- | advtrains_train_subway/init.lua | 1 |
15 files changed, 85 insertions, 65 deletions
diff --git a/advtrains/path.lua b/advtrains/path.lua index 825e59b..ff034c9 100644 --- a/advtrains/path.lua +++ b/advtrains/path.lua @@ -17,12 +17,18 @@ -- path_cn - Connid of the current node that points towards path[i+1] -- path_cp - Connid of the current node that points towards path[i-1] -- When the day comes on that path!=node, these will only be set if this index represents a transition between rail nodes --- path_dist - The distance (in meters) between this (path[i]) and the next (path[i+1]) item of the path +-- path_dist - The total distance of this path element from path element 0 -- path_dir - The direction of this path item's transition to the next path item, which is the angle of conns[path_cn[i]].c --Variables: -- path_ext_f/b - how far path[i] is set -- path_trk_f/b - how far the path extends along a track. beyond those values, paths are generated in a straight line. -- path_req_f/b - how far path items were requested in the last step +-- +--Distance and index: +-- There is an important difference between the path index and the actual distance on the track: The distance between two path items can be larger than 1, +-- but the corresponding index increment is still 1. +-- Indexes in advtrains can be fractional values. If they are, it means that the actual position is interpolated between the 2 adjacent path items. +-- If you need to proceed along the path by a specific actual distance, it does NOT work to simply add it to the index. You should use the path_get_index_by_offset() function. -- creates the path data structure, reconstructing the train from a position and a connid -- Important! train.drives_on must exist while calling this method @@ -40,7 +46,7 @@ function advtrains.path_create(train, pos, connid, rel_index) train.path = { [0] = { x=posr.x, y=posr.y+rhe, z=posr.z } } train.path_cn = { [0] = connid } train.path_cp = { [0] = mconnid } - train.path_dist = {} + train.path_dist = { [0] = 0 } train.path_dir = { [0] = advtrains.conn_angle_median(conns[mconnid].c, conns[connid].c) @@ -135,12 +141,12 @@ function advtrains.path_print(train, printf) printf("path_print: Path is invalidated/inexistant.") return end - printf("i: CP Position Dir CN ->Dist->") + printf("i: CP Position Dir CN Dist") for i = train.path_ext_b, train.path_ext_f do if i==train.path_trk_b then printf("--Back on-track border here--") end - printf(i,": ",train.path_cp[i]," ",train.path[i]," ",train.path_dir[i]," ",train.path_cn[i]," ->",train.path_dist[i],"->") + printf(i,": ",train.path_cp[i]," ",train.path[i]," ",train.path_dir[i]," ",train.path_cn[i]," ",train.path_dist[i],"") if i==train.path_trk_f then printf("--Front on-track border here--") end @@ -156,7 +162,9 @@ function advtrains.path_get(train, index) if index ~= atfloor(index) then error("For train "..train.id..": Called path_get() but index="..index.." is not a round number") end + local pef = train.path_ext_f + -- generate forward (front of train, positive) while index > pef do local pos = train.path[pef] local connid = train.path_cn[pef] @@ -183,10 +191,13 @@ function advtrains.path_get(train, index) train.path_dir[pef] = train.path_dir[pef-1] end train.path[pef] = adj_pos - train.path_dist[pef - 1] = vector.distance(pos, adj_pos) + train.path_dist[pef] = train.path_dist[pef-1] + vector.distance(pos, adj_pos) end train.path_ext_f = pef + + local peb = train.path_ext_b + -- generate backward (back of train, negative) while index < peb do local pos = train.path[peb] local connid = train.path_cp[peb] @@ -213,7 +224,7 @@ function advtrains.path_get(train, index) train.path_dir[peb] = train.path_dir[peb+1] end train.path[peb] = adj_pos - train.path_dist[peb] = vector.distance(pos, adj_pos) + train.path_dist[peb] = train.path_dist[peb+1] - vector.distance(pos, adj_pos) end train.path_ext_b = peb @@ -256,37 +267,53 @@ function advtrains.path_get_adjacent(train, index) return p_floor, p_ceil, frac end +local function n_interpolate(s, e, f) + return s + (e-s)*f +end + +-- This function determines the index resulting from moving along the path by 'offset' meters +-- starting from 'index'. See also the comment on the top of the file. function advtrains.path_get_index_by_offset(train, index, offset) - local off = offset - local idx = atfloor(index) - -- go down to floor. Calculate required path_dist - advtrains.path_get_adjacent(train, idx) - off = off + ((index-idx) * train.path_dist[idx]) - --atdebug("pibo: 1 off=",off,"idx=",idx," index=",index) + -- Step 1: determine my current absolute pos on the path + local start_index_f = math.floor(index) + local _, _, frac = advtrains.path_get_adjacent(train, index) + local dist1, dist2 = train.path_dist[start_index_f], train.path_dist[start_index_f+1] + local start_dist = n_interpolate(dist1, dist2, frac) + + -- Step 2: determine the total end distance and estimate the index we'd come out + local end_dist = start_dist + offset + + local c_idx = math.floor(index + offset) + + -- Step 3: move forward/backward to find real index + -- We assume here that the distance between 2 path items is never smaller than 1. + -- Our estimated index is therefore either exact or too far over, and we're going to go back + -- towards the origin. It is therefore sufficient to query path_get a single time - -- then walk the path back until we overshoot (off becomes >=0) - while off<0 do - idx = idx - 1 - advtrains.path_get_adjacent(train, idx) - off = off + train.path_dist[idx] + -- How we'll adjust c_idx + -- Desired position: -------#------ + -- Path items : --|--|--|--|-- + -- c_idx : ^ + + advtrains.path_get_adjacent(train, c_idx) + + while train.path_dist[c_idx] < end_dist do + c_idx = c_idx + 1 end - --atdebug("pibo: 2 off=",off,"idx=",idx) - -- then walk the path forward until we would overshoot - while off - train.path_dist[idx] >= 0 do - idx = idx + 1 - advtrains.path_get_adjacent(train, idx) - if not train.path_dist[idx] then - for i=-5,5 do - atdebug(idx+i,train.path_dist[idx+i]) - end - end - off = off - train.path_dist[idx] + + while train.path_dist[c_idx] > end_dist do + c_idx = c_idx - 1 end - --atdebug("pibo: 3 off=",off,"idx=",idx," returns:",idx + (off / train.path_dist[idx])) - -- we should now be on the floor of the index we actually want. - -- give them the rest! - return idx + (off / train.path_dist[idx]) + -- Step 4: now c_idx points to the place shown above. Find out the fractional part. + + dist1, dist2 = train.path_dist[c_idx], train.path_dist[c_idx+1] + + frac = (end_dist - dist1) / (dist2 - dist1) + + assert(frac>=0 and frac<1, frac) + + return c_idx + frac end local PATH_CLEAR_KEEP = 4 diff --git a/advtrains/trainlogic.lua b/advtrains/trainlogic.lua index bc24feb..3c0d02e 100644 --- a/advtrains/trainlogic.lua +++ b/advtrains/trainlogic.lua @@ -474,7 +474,8 @@ function advtrains.train_step_b(id, train, dtime) --- 4. move train --- - local pdist = train.path_dist[math.floor(train.index)] or 1 + local idx_floor = math.floor(train.index) + local pdist = (train.path_dist[idx_floor+1] - train.path_dist[idx_floor]) local distance = (train.velocity*dtime) / pdist --debugging code diff --git a/advtrains/wagons.lua b/advtrains/wagons.lua index 040c1e4..b13b8d8 100644 --- a/advtrains/wagons.lua +++ b/advtrains/wagons.lua @@ -804,10 +804,10 @@ function wagon:show_bordcom(pname) local data = advtrains.wagons[self.id]
local form = "size[11,9]label[0.5,0;AdvTrains Boardcom v0.1]"
- form=form.."textarea[0.5,1.5;7,1;text_outside;"..attrans("Text displayed outside on train")..";"..(train.text_outside or "").."]"
- form=form.."textarea[0.5,3;7,1;text_inside;"..attrans("Text displayed inside train")..";"..(train.text_inside or "").."]"
- form=form.."field[7.5,1.75;3,1;line;"..attrans("Line")..";"..(train.line or "").."]"
- form=form.."field[7.5,3.25;3,1;routingcode;"..attrans("Routingcode")..";"..(train.routingcode or "").."]"
+ form=form.."textarea[0.5,1.5;7,1;text_outside;"..attrans("Text displayed outside on train")..";"..(minetest.formspec_escape(train.text_outside or "")).."]"
+ form=form.."textarea[0.5,3;7,1;text_inside;"..attrans("Text displayed inside train")..";"..(minetest.formspec_escape(train.text_inside or "")).."]"
+ form=form.."field[7.5,1.75;3,1;line;"..attrans("Line")..";"..(minetest.formspec_escape(train.line or "")).."]"
+ form=form.."field[7.5,3.25;3,1;routingcode;"..attrans("Routingcode")..";"..(minetest.formspec_escape(train.routingcode or "")).."]"
--row 5 : train overview and autocoupling
if train.velocity==0 then
form=form.."label[0.5,4.5;Train overview /coupling control:]"
diff --git a/advtrains_interlocking/route_ui.lua b/advtrains_interlocking/route_ui.lua index 4ddab0c..71fed09 100644 --- a/advtrains_interlocking/route_ui.lua +++ b/advtrains_interlocking/route_ui.lua @@ -25,13 +25,13 @@ function atil.show_route_edit_form(pname, sigd, routeid) if not route then return end local form = "size[9,10]label[0.5,0.2;Route overview]" - form = form.."field[0.8,1.2;5.2,1;name;Route name;"..route.name.."]" + form = form.."field[0.8,1.2;5.2,1;name;Route name;"..minetest.formspec_escape(route.name).."]" form = form.."button[5.5,0.9;1,1;setname;Set]" -- construct textlist for route information local tab = {} local function itab(t) - tab[#tab+1] = string.gsub(t, ",", " ") + tab[#tab+1] = minetest.formspec_escape(string.gsub(t, ",", " ")) end itab("TCB "..sigd_to_string(sigd).." ("..tcbs.signal_name..") Route #"..routeid) diff --git a/advtrains_interlocking/tcb_ts_ui.lua b/advtrains_interlocking/tcb_ts_ui.lua index 6c773ab..dcf6c6e 100644 --- a/advtrains_interlocking/tcb_ts_ui.lua +++ b/advtrains_interlocking/tcb_ts_ui.lua @@ -180,7 +180,7 @@ local function mktcbformspec(tcbs, btnpref, offset, pname) ts = ildb.get_ts(tcbs.ts_id) end if ts then - form = form.."label[0.5,"..offset..";Side "..btnpref..": "..ts.name.."]" + form = form.."label[0.5,"..offset..";Side "..btnpref..": "..minetest.formspec_escape(ts.name).."]" form = form.."button[0.5,"..(offset+0.5)..";5,1;"..btnpref.."_gotots;Show track section]" if ildb.may_modify_tcbs(tcbs) then -- Note: the security check to prohibit those actions is located in database.lua in the corresponding functions. @@ -315,7 +315,7 @@ function advtrains.interlocking.show_ts_form(ts_id, pname, sel_tcb) if not ts_id then return end local form = "size[10,10]label[0.5,0.5;Track Section Detail - "..ts_id.."]" - form = form.."field[0.8,2;5.2,1;name;Section name;"..ts.name.."]" + form = form.."field[0.8,2;5.2,1;name;Section name;"..minetest.formspec_escape(ts.name).."]" form = form.."button[5.5,1.7;1,1;setname;Set]" local hint @@ -334,7 +334,7 @@ function advtrains.interlocking.show_ts_form(ts_id, pname, sel_tcb) local other_ts = ildb.get_ts(other_id) if other_ts then if ildb.may_modify_ts(other_ts) then - form = form.."button[5.5,3;3.5,1;mklink;Join with "..other_ts.name.."]" + form = form.."button[5.5,3;3.5,1;mklink;Join with "..minetest.formspec_escape(other_ts.name).."]" form = form.."button[9 ,3;0.5,1;cancellink;X]" end end @@ -555,7 +555,7 @@ function advtrains.interlocking.show_signalling_form(sigd, pname, sel_rte) if not tcbs.routes then tcbs.routes = {} end local form = "size[7,10]label[0.5,0.5;Signal at "..minetest.pos_to_string(sigd.p).."]" - form = form.."field[0.8,1.5;5.2,1;name;Signal name;"..tcbs.signal_name.."]" + form = form.."field[0.8,1.5;5.2,1;name;Signal name;"..minetest.formspec_escape(tcbs.signal_name).."]" form = form.."button[5.5,1.2;1,1;setname;Set]" if tcbs.routeset then @@ -566,13 +566,13 @@ function advtrains.interlocking.show_signalling_form(sigd, pname, sel_rte) return end form = form.."label[0.5,2.5;A route is requested from this signal:]" - form = form.."label[0.5,3.0;"..rte.name.."]" + form = form.."label[0.5,3.0;"..minetest.formspec_escape(rte.name).."]" if tcbs.route_committed then form = form.."label[0.5,3.5;Route has been set.]" else form = form.."label[0.5,3.5;Waiting for route to be set...]" if tcbs.route_rsn then - form = form.."label[0.5,4;"..tcbs.route_rsn.."]" + form = form.."label[0.5,4;"..minetest.formspec_escape(tcbs.route_rsn).."]" end end if not tcbs.route_auto then diff --git a/advtrains_line_automation/railwaytime.lua b/advtrains_line_automation/railwaytime.lua index 3a044b6..258009e 100644 --- a/advtrains_line_automation/railwaytime.lua +++ b/advtrains_line_automation/railwaytime.lua @@ -39,6 +39,7 @@ local rwt = {} --Time Stamp (Seconds since start of world) local e_time = 0 +local e_has_loaded = false local setting_rwt_real = minetest.settings:get("advtrains_lines_rwt_realtime") if setting_rwt_real=="" then @@ -71,6 +72,8 @@ function rwt.set_time(t) end atlog("[lines][rwt] Initialized railway time: ",rwt.to_string(e_time)) e_last_epoch = os.time() + + e_has_loaded = true end function rwt.get_time() @@ -78,6 +81,10 @@ function rwt.get_time() end function rwt.step(dt) + if not e_has_loaded then + rwt.set_time(0) + end + if setting_rwt_real=="independent" then -- Regular stepping with dtime e_time = e_time + dt diff --git a/advtrains_line_automation/stoprail.lua b/advtrains_line_automation/stoprail.lua index 0db474f..0990876 100644 --- a/advtrains_line_automation/stoprail.lua +++ b/advtrains_line_automation/stoprail.lua @@ -58,7 +58,7 @@ local function show_stoprailform(pos, player) form = form.."dropdown[0.5,3;2;doors;Left,Right,Closed;"..door_dropdown[stdata.doors].."]" form = form.."dropdown[3,3;1.5;reverse;---,Reverse;"..(stdata.reverse and 2 or 1).."]" - form = form.."field[5,3.5;2,1;track;"..attrans("Track")..";"..stdata.track.."]" + form = form.."field[5,3.5;2,1;track;"..attrans("Track")..";"..minetest.formspec_escape(stdata.track).."]" form = form.."field[5,4.5;2,1;wait;"..attrans("Stop Time")..";"..stdata.wait.."]" form = form.."textarea[0.5,4;4,2;ars;Trains stopping here (ARS rules);"..advtrains.interlocking.ars_to_text(stdata.ars).."]" diff --git a/advtrains_luaautomation/active_common.lua b/advtrains_luaautomation/active_common.lua index c17c6e9..48f75ac 100644 --- a/advtrains_luaautomation/active_common.lua +++ b/advtrains_luaautomation/active_common.lua @@ -36,7 +36,7 @@ function ac.getform(pos, meta_p) end local sel = 1 for n,_ in pairs(atlatc.envs) do - envs_asvalues[#envs_asvalues+1]=n + envs_asvalues[#envs_asvalues+1]=minetest.formspec_escape(n) if n==env then sel=#envs_asvalues end diff --git a/advtrains_luaautomation/init.lua b/advtrains_luaautomation/init.lua index 75cf30a..573a553 100644 --- a/advtrains_luaautomation/init.lua +++ b/advtrains_luaautomation/init.lua @@ -44,7 +44,8 @@ local filename=minetest.get_worldpath().."/advtrains_luaautomation" function atlatc.load() local file, err = io.open(filename, "r") if not file then - minetest.log("error", " Failed to read advtrains_luaautomation save data from file "..filename..": "..(err or "Unknown Error")) + minetest.log("warning", " Failed to read advtrains_luaautomation save data from file "..filename..": "..(err or "Unknown Error")) + minetest.log("warning", " (this is normal when first enabling advtrains on this world)") else atprint("luaautomation reading file:",filename) local tbl = minetest.deserialize(file:read("*a")) diff --git a/advtrains_luaautomation/pcnaming.lua b/advtrains_luaautomation/pcnaming.lua index 427585d..ebb769f 100644 --- a/advtrains_luaautomation/pcnaming.lua +++ b/advtrains_luaautomation/pcnaming.lua @@ -52,7 +52,7 @@ minetest.register_craftitem("advtrains_luaautomation:pcnaming",{ pn=name end end - minetest.show_formspec(pname, "atlatc_naming_"..minetest.pos_to_string(pos), "field[pn;Set name of component (empty to clear);"..pn.."]") + minetest.show_formspec(pname, "atlatc_naming_"..minetest.pos_to_string(pos), "field[pn;Set name of component (empty to clear);"..minetest.formspec_escape(pn).."]") end end end, diff --git a/advtrains_signals_ks/init.lua b/advtrains_signals_ks/init.lua index 34fb6d3..c65d5f8 100644 --- a/advtrains_signals_ks/init.lua +++ b/advtrains_signals_ks/init.lua @@ -19,10 +19,6 @@ local setaspectf = function(rot) advtrains.ndb.swap_node(pos, {name="advtrains_signals_ks:hs_slow_"..rot, param2 = node.param2}) end end - local meta = minetest.get_meta(pos) - if meta then - meta:set_string("infotext", minetest.serialize(asp)) - end end end diff --git a/advtrains_train_industrial/init.lua b/advtrains_train_industrial/init.lua index 7fbe97c..64a98b8 100644 --- a/advtrains_train_industrial/init.lua +++ b/advtrains_train_industrial/init.lua @@ -41,7 +41,6 @@ advtrains.register_wagon("engine_industrial", { collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0}, drops={"default:steelblock 4"}, horn_sound = "advtrains_industrial_horn", - glow = -1, --supposed to disable effect of light to texture color, so that the entity always appears as full-bright }, S("Industrial Train Engine"), "advtrains_engine_industrial_inv.png") --big-- advtrains.register_wagon("engine_industrial_big", { @@ -79,7 +78,6 @@ advtrains.register_wagon("engine_industrial_big", { collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0}, drops={"default:steelblock 4"}, horn_sound = "advtrains_industrial_horn", - glow = -1, --supposed to disable effect of light to texture color, so that the entity always appears as full-bright }, S("Big Industrial Train Engine"), "advtrains_engine_industrial_inv.png") advtrains.register_wagon("wagon_tank", { mesh="advtrains_wagon_tank.b3d", @@ -101,7 +99,6 @@ advtrains.register_wagon("wagon_tank", { inventory_list_sizes = { box=8*3, }, - glow = -1, --supposed to disable effect of light to texture color, so that the entity always appears as full-bright }, S("Industrial tank wagon"), "advtrains_wagon_tank_inv.png") advtrains.register_wagon("wagon_wood", { mesh="advtrains_wagon_wood.b3d", @@ -123,5 +120,4 @@ advtrains.register_wagon("wagon_wood", { inventory_list_sizes = { box=8*3, }, - glow = -1, --supposed to disable effect of light to texture color, so that the entity always appears as full-bright }, S("Industrial wood wagon"), "advtrains_wagon_wood_inv.png") diff --git a/advtrains_train_japan/init.lua b/advtrains_train_japan/init.lua index a811dd1..c76ce8f 100644 --- a/advtrains_train_japan/init.lua +++ b/advtrains_train_japan/init.lua @@ -73,7 +73,6 @@ advtrains.register_wagon("engine_japan", { collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0}, drops={"default:steelblock 4"}, horn_sound = "advtrains_japan_horn", - glow = -1, --supposed to disable effect of light to texture color, so that the entity always appears as full-bright }, S("Japanese Train Engine"), "advtrains_engine_japan_inv.png") advtrains.register_wagon("wagon_japan", { @@ -142,6 +141,5 @@ advtrains.register_wagon("wagon_japan", { wagon_span=2.3, collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0}, drops={"default:steelblock 4"}, - glow = -1, --supposed to disable effect of light to texture color, so that the entity always appears as full-bright }, S("Japanese Train Wagon"), "advtrains_wagon_japan_inv.png") diff --git a/advtrains_train_steam/init.lua b/advtrains_train_steam/init.lua index 2c60dd7..c337a79 100755 --- a/advtrains_train_steam/init.lua +++ b/advtrains_train_steam/init.lua @@ -75,7 +75,6 @@ advtrains.register_wagon("newlocomotive", { end, drops={"default:steelblock 1"}, horn_sound = "advtrains_steam_whistle", - glow = -1, --supposed to disable effect of light to texture color, so that the entity always appears as full-bright }, S("Steam Engine"), "advtrains_engine_steam_inv.png") advtrains.register_wagon("detailed_steam_engine", { @@ -158,8 +157,6 @@ advtrains.register_wagon("detailed_steam_engine", { end, drops={"default:steelblock 1"}, horn_sound = "advtrains_steam_whistle", - glow = -1, --supposed to disable effect of light to texture color, so that the entity always appears as full-bright - }, S("Detailed Steam Engine"), "advtrains_detailed_engine_steam_inv.png") advtrains.register_wagon("wagon_default", { @@ -205,7 +202,6 @@ advtrains.register_wagon("wagon_default", { wagon_span=2.634, collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0}, drops={"default:steelblock 1"}, - glow = -1, --supposed to disable effect of light to texture color, so that the entity always appears as full-bright }, S("Passenger Wagon"), "advtrains_wagon_inv.png") @@ -229,7 +225,6 @@ advtrains.register_wagon("wagon_box", { inventory_list_sizes = { box=8*3, }, - glow = -1, --supposed to disable effect of light to texture color, so that the entity always appears as full-bright }, S("Box Wagon"), "advtrains_wagon_box_inv.png") minetest.register_craft({ diff --git a/advtrains_train_subway/init.lua b/advtrains_train_subway/init.lua index 0c19009..d47b9ca 100644 --- a/advtrains_train_subway/init.lua +++ b/advtrains_train_subway/init.lua @@ -76,7 +76,6 @@ advtrains.register_wagon("subway_wagon", { is_locomotive=true, drops={"default:steelblock 4"}, horn_sound = "advtrains_subway_horn", - glow = -1, --supposed to disable effect of light to texture color, so that the entity always appears as full-bright custom_on_velocity_change = function(self, velocity, old_velocity, dtime) if not velocity or not old_velocity then return end if old_velocity == 0 and velocity > 0 then |