diff options
Diffstat (limited to 'advtrains_luaautomation')
-rw-r--r-- | advtrains_luaautomation/README.md | 24 | ||||
-rw-r--r-- | advtrains_luaautomation/active_common.lua | 4 | ||||
-rw-r--r--[-rwxr-xr-x] | advtrains_luaautomation/atc_rail.lua | 23 | ||||
-rw-r--r-- | advtrains_luaautomation/environment.lua | 10 | ||||
-rw-r--r--[-rwxr-xr-x] | advtrains_luaautomation/operation_panel.lua | 0 | ||||
-rw-r--r-- | advtrains_luaautomation/pcnaming.lua | 15 |
6 files changed, 52 insertions, 24 deletions
diff --git a/advtrains_luaautomation/README.md b/advtrains_luaautomation/README.md index a885075..275653c 100644 --- a/advtrains_luaautomation/README.md +++ b/advtrains_luaautomation/README.md @@ -93,6 +93,9 @@ Removes any pending interrupts of this node. Make this active component send a digiline message on the specified channel. Not available in init code. + - `trainparts(train_id)` + returns a table with the ids of the cars the train is composed of, or false if `train_id` is invalid. `train_id` can be replaced with `atc_id` when used in LuaATC Rails. + - `atc_send_to_train(<train_id>, <atc_command>)` Sends the specified ATC command to the train specified by its train id. This happens regardless of where the train is in the world, and can be used to remote-control trains. Returns true on success. If the train ID does not exist, returns false and does nothing. See [atc_command.txt](../atc_command.txt) for the ATC command syntax. @@ -142,22 +145,16 @@ asp = { -- the character of call_on and dead_end is purely informative call_on = <boolean>, -- Call-on route, expect train in track ahead (not implemented yet) dead_end = <boolean>, -- Route ends on a dead end (e.g. bumper) (not implemented yet) - - w_speed = <integer>, - -- "Warning speed restriction". Supposed for short-term speed - -- restrictions which always override any other restrictions - -- imposed by "speed" fields, until lifted by a value of -1 - -- (Example: german Langsamfahrstellen-Signale) } ``` -As of January 2020, the 'dst', 'call_on' and 'dead_end' fields are not used. +As of September 2024, the 'dst', 'call_on' and 'dead_end' fields are not used. #### Lines The advtrains_line_automation component adds a few contraptions that should make creating timeable systems easier. Part of its functionality is also available in LuaATC: -- `rwt.*` - all Railway Time functions are included as documented in [the wiki](https://advtrains.de/wiki/doku.php?id=dev:lines:rwt) +- `rwt.*` - all Railway Time functions are included as documented in [the wiki](https://advtrains.de/wiki/doku.php?id=dev:api:railway_time_api) - `schedule(rw_time, msg)`, `schedule_in(rw_dtime, msg)` Schedules an event of type {type="schedule", schedule=true, msg=msg} at (resp. after) the specified railway time (which can be in any format). You can only schedule one event this way. (uses the new lines-internal scheduler) @@ -273,10 +270,17 @@ Each wagon has a current FC, indicating its next destination. Returns a table with the entire FC list for each wagon in the train. Command: `get_fc()` Result: `{"", "foo!bar", "testing", "fc_1!fc_2!fc_3!?", "hello_world"}` + + - `get_fc_index()` + Returns a table with the current FC index for each wagon in the train. Use in conjunction with the result from `get_fc()` to find a the current FC for a wagon. + Command: `get_fc_index()` + Result: `{1, 1, 1, 2, 1}` - - `set_fc(fc_list)` + - `set_fc(fc_list, reset_index)` Overwrites the FC list according to a table `fc_list`. A false or nil entry will leave the wagon unaffected, however all others will be overwritten. - Useful for mass-programming freight trains that use FC-shunting instead of walking to each wagon individually. + Useful for mass-programming freight trains that use FC-shunting instead of walking to each wagon individually. If the new FC entry for a wagon is shorter than the old entry, the index will clip to the last FC in the new entry. + If `reset_index` is true, all Current FC values will reset to the first entry in the list, instead of remaining at the current index. + Example: train has FC lists: `"", "foo!bar", "testing", "fc_1!fc_2!fc_3!?", "hello_world"` Command: `set_fc({"", "foo!turtle", nil, "4tehlulz", false})` Result: `""` `"foo!turtle"` `"testing"` `"4tehlulz"` `"hello_world"` diff --git a/advtrains_luaautomation/active_common.lua b/advtrains_luaautomation/active_common.lua index 1a7009f..074d3b3 100644 --- a/advtrains_luaautomation/active_common.lua +++ b/advtrains_luaautomation/active_common.lua @@ -55,6 +55,10 @@ end function ac.after_dig_node(pos, node, player) advtrains.invalidate_all_paths(pos) advtrains.ndb.clear(pos) + atlatc.interrupt.clear_ints_at_pos(pos) + if advtrains.lines and advtrains.lines.sched then + advtrains.lines.sched.discard_all(advtrains.encode_pos(pos)) + end local ph=minetest.pos_to_string(pos) ac.nodes[ph]=nil end diff --git a/advtrains_luaautomation/atc_rail.lua b/advtrains_luaautomation/atc_rail.lua index f069600..dd26f51 100755..100644 --- a/advtrains_luaautomation/atc_rail.lua +++ b/advtrains_luaautomation/atc_rail.lua @@ -95,11 +95,19 @@ function r.fire_event(pos, evtdata, appr_internal) if not train_id then return end local fc_list = {} for index,wagon_id in ipairs(train.trainparts) do - fc_list[index] = table.concat(advtrains.wagons[wagon_id].fc,"!") or "" + fc_list[index] = table.concat(advtrains.wagons[wagon_id].fc or {},"!") end return fc_list end, - set_fc = function(fc_list) + get_fc_index = function() + if not train_id then return end + local fc_index_list = {} + for widx, wagon_id in ipars(train.trainparts) do + fc_index_list[widx] = advtrains.wagons[wagon_id].fcind or 1 + end + return fc_index_list + end, + set_fc = function(fc_list,reset_index) assertt(fc_list, "table") if not train_id then return false end -- safety type-check for entered values @@ -113,11 +121,12 @@ function r.fire_event(pos, evtdata, appr_internal) if fc_list[index] then -- has FC to enter to this wagon local data = advtrains.wagons[wagon_id] if data then -- wagon actually exists - for _,wagon in pairs(minetest.luaentities) do -- find wagon entity - if wagon.is_wagon and wagon.initialized and wagon.id==wagon_id then - wagon.set_fc(data,fc_list[index]) -- overwrite to new FC - break -- no point cycling through every other entity. we found our wagon - end + --effectively copyied from wagons.lua, allowing for the :split function and reset_index + data.fc = fc_list[index]:split("!") + if reset_index or not data.fcind then + data.fcind = 1 + elseif data.fcind > #data.fc then + data.fcind = #data.fc end end end diff --git a/advtrains_luaautomation/environment.lua b/advtrains_luaautomation/environment.lua index 6df5248..b54d45c 100644 --- a/advtrains_luaautomation/environment.lua +++ b/advtrains_luaautomation/environment.lua @@ -153,6 +153,12 @@ local static_env = { local pos=atlatc.pcnaming.resolve_pos(parpos, "interrupt_pos") atlatc.interrupt.add(0, pos, {type="ext_int", ext_int=true, message=imesg}) end, + train_parts = function(train_id) + if not train_id then return false end + local train = advtrains.trains[train_id] + if not train then return false end + return table.copy(train.trainparts or {}) + end, -- sends an atc command to train regardless of where it is in the world atc_send_to_train = function(train_id, command) assertt(command, "string") @@ -224,7 +230,7 @@ if advtrains.interlocking then end static_env.set_aspect = function(signal, asp) local pos = atlatc.pcnaming.resolve_pos(signal) - return advtrains.interlocking.signal_set_aspect(pos) + return advtrains.interlocking.signal_set_aspect(pos,asp) end --section_occupancy() @@ -233,7 +239,7 @@ if advtrains.interlocking then ts_id = tostring(ts_id) local response = advtrains.interlocking.db.get_ts(ts_id) if not response then return false end - return table.copy(response.trains) + return (response.trains and table.copy(response.trains)) or {} end end diff --git a/advtrains_luaautomation/operation_panel.lua b/advtrains_luaautomation/operation_panel.lua index 8e12651..8e12651 100755..100644 --- a/advtrains_luaautomation/operation_panel.lua +++ b/advtrains_luaautomation/operation_panel.lua diff --git a/advtrains_luaautomation/pcnaming.lua b/advtrains_luaautomation/pcnaming.lua index 60983a6..0089ae7 100644 --- a/advtrains_luaautomation/pcnaming.lua +++ b/advtrains_luaautomation/pcnaming.lua @@ -24,6 +24,9 @@ function atlatc.pcnaming.resolve_pos(pos, func_name) error("Invalid position supplied to " .. (func_name or "???")..": " .. dump(pos)) end + +local pcrename = {} + minetest.register_craftitem("advtrains_luaautomation:pcnaming",{ description = S("Passive Component Naming Tool\n\nRight-click to name a passive component."), groups = {cracky=1}, -- key=name, value=rating; rating=1..3. @@ -45,6 +48,7 @@ minetest.register_craftitem("advtrains_luaautomation:pcnaming",{ minetest.record_protection_violation(pos, pname) return end + local node = advtrains.ndb.get_node(pos) local ndef = minetest.registered_nodes[node.name] if node.name and ( @@ -59,16 +63,17 @@ minetest.register_craftitem("advtrains_luaautomation:pcnaming",{ pn=name end end - minetest.show_formspec(pname, "atlatc_naming_"..minetest.pos_to_string(pos), "field[pn;"..S("Set name of component (empty to clear)")..";"..minetest.formspec_escape(pn).."]") + pcrename[pname] = pos + minetest.show_formspec(pname, "atlatc_naming", "field[pn;"..S("Set name of component (empty to clear)")..";"..minetest.formspec_escape(pn).."]") end end end, }) minetest.register_on_player_receive_fields(function(player, formname, fields) - local pts=string.match(formname, "^atlatc_naming_(.+)") - if pts then - local pos=minetest.string_to_pos(pts) - if fields.pn then + if formname == "atlatc_naming" then + local pname = player:get_player_name() + local pos=pcrename[pname] + if fields.pn and pos then --first remove all occurences for name, npos in pairs(atlatc.pcnaming.name_map) do if vector.equals(npos, pos) then |