develop #32

Merged
milan merged 7 commits from develop into master 2021-02-28 22:06:32 +01:00
16 changed files with 472 additions and 339 deletions
Showing only changes of commit a6f38971cc - Show all commits

View file

@ -436,7 +436,11 @@ end, true)
minetest.register_globalstep(function(dtime)
timer = timer + dtime
if timer > armor.config.init_delay then
if timer <= armor.config.init_delay then
return
end
timer = 0
for player, count in pairs(pending_players) do
local remove = init_player_armor(player) == true
pending_players[player] = count + 1
@ -448,68 +452,52 @@ minetest.register_globalstep(function(dtime)
pending_players[player] = nil
end
end
timer = 0
end
end)
-- Fire Protection and water breathing, added by TenPlus1.
if armor.config.fire_protect == true then
-- override hot nodes so they do not hurt player anywhere but mod
for _, row in pairs(armor.fire_nodes) do
if minetest.registered_nodes[row[1]] then
minetest.override_item(row[1], {damage_per_second = 0})
end
end
else
print (S("[3d_armor] Fire Nodes disabled"))
end
if armor.config.water_protect == true or armor.config.fire_protect == true then
minetest.register_globalstep(function(dtime)
armor.timer = armor.timer + dtime
if armor.timer < armor.config.update_time then
return
end
-- water breathing protection, added by TenPlus1
if armor.config.water_protect == true then
for _,player in pairs(minetest.get_connected_players()) do
local name = player:get_player_name()
local pos = player:get_pos()
local hp = player:get_hp()
if not name or not pos or not hp then
return
end
-- water breathing
if armor.config.water_protect == true then
if armor.def[name].water > 0 and
player:get_breath() < 10 then
player:set_breath(10)
end
end
-- fire protection
if armor.config.fire_protect == true then
local fire_damage = true
pos.y = pos.y + 1.4 -- head level
local node_head = minetest.get_node(pos).name
pos.y = pos.y - 1.2 -- feet level
local node_feet = minetest.get_node(pos).name
-- is player inside a hot node?
for _, row in pairs(armor.fire_nodes) do
-- check fire protection, if not enough then get hurt
if row[1] == node_head or row[1] == node_feet then
if fire_damage == true then
armor:punch(player, "fire")
last_punch_time[name] = minetest.get_gametime()
fire_damage = false
end
if hp > 0 and armor.def[name].fire < row[2] then
hp = hp - row[3] * armor.config.update_time
player:set_hp(hp)
break
end
end
end
end
end
armor.timer = 0
end)
-- Fire Protection, added by TenPlus1.
if armor.config.fire_protect == true then
-- override any hot nodes that do not already deal damage
for _, row in pairs(armor.fire_nodes) do
if minetest.registered_nodes[row[1]] then
local damage = minetest.registered_nodes[row[1]].damage_per_second
if not damage or damage == 0 then
minetest.override_item(row[1], {damage_per_second = row[3]})
end
end
end
else
print ("[3d_armor] Fire Nodes disabled")
end
if armor.config.fire_protect == true then
minetest.register_on_player_hpchange(function(player, hp_change, reason)
if reason.type == "node_damage" and reason.node then
-- fire protection
if armor.config.fire_protect == true and hp_change < 0 then
local name = player:get_player_name()
for _,igniter in pairs(armor.fire_nodes) do
if reason.node == igniter[1] then
if armor.def[name].fire < igniter[2] then
armor:punch(player, "fire")
else
hp_change = 0
end
end
end
end
end
return hp_change
end, true)
end

View file

@ -106,7 +106,7 @@ minetest.register_entity("advtrains:couple", {
end,
on_step=function(self, dtime)
return advtrains.pcall(function()
if advtrains.outside_range(self.object:getpos()) then
if advtrains.wagon_outside_range(self.object:getpos()) then
self.object:remove()
return
end

View file

@ -445,3 +445,28 @@ atdebug("pts",os.clock()-t1,"s")
]]
-- Function to check whether a position is near (within range of) any player
function advtrains.position_in_range(pos, range)
if not pos then
return true
end
for _,p in pairs(minetest.get_connected_players()) do
if vector.distance(p:get_pos(),pos)<=range then
return true
end
end
return false
end
local active_node_range = tonumber(minetest.settings:get("active_block_range"))*16 + 16
-- Function to check whether node at position(pos) is "loaded"/"active"
-- That is, whether it is within the active_block_range to a player
if minetest.is_block_active then -- define function differently whether minetest.is_block_active is available or not
advtrains.is_node_loaded = minetest.is_block_active
else
function advtrains.is_node_loaded(pos)
if advtrains.position_in_range(pos, active_node_range) then
return true
end
end
end

View file

@ -223,7 +223,7 @@ end
function ndb.swap_node(pos, node, no_inval)
if minetest.get_node_or_nil(pos) then
if advtrains.is_node_loaded(pos) then
minetest.swap_node(pos, node)
end
ndb.update(pos, node)
@ -294,11 +294,12 @@ ndb.run_lbm = function(pos, node)
ndb.update(pos, node)
else
if (nodeid~=node.name or param2~=node.param2) then
atprint("nodedb: lbm replaced", pos, "with nodeid", nodeid, "param2", param2, "cid is", cid)
minetest.swap_node(pos, {name=nodeid, param2 = param2})
--atprint("nodedb: lbm replaced", pos, "with nodeid", nodeid, "param2", param2, "cid is", cid)
local newnode = {name=nodeid, param2 = param2}
minetest.swap_node(pos, newnode)
local ndef=minetest.registered_nodes[nodeid]
if ndef and ndef.on_updated_from_nodedb then
ndef.on_updated_from_nodedb(pos, node)
if ndef and ndef.advtrains and ndef.advtrains.on_updated_from_nodedb then
ndef.advtrains.on_updated_from_nodedb(pos, newnode)
end
return true
end

View file

@ -13,16 +13,18 @@ minetest.override_item("mesecons_switch:mesecon_switch_off", {
mesecon.receptor_on(pos)
minetest.sound_play("mesecons_switch", {pos=pos})
end,
on_updated_from_nodedb = function(pos, node)
mesecon.receptor_off(pos)
end,
advtrains = {
getstate = "off",
setstate = function(pos, node, newstate)
if newstate=="on" then
advtrains.ndb.swap_node(pos, {name="mesecons_switch:mesecon_switch_on", param2=node.param2})
if advtrains.is_node_loaded(pos) then
mesecon.receptor_on(pos)
end
end
end,
on_updated_from_nodedb = function(pos, node)
mesecon.receptor_off(pos)
end,
},
})
@ -38,17 +40,19 @@ minetest.override_item("mesecons_switch:mesecon_switch_on", {
mesecon.receptor_off(pos)
minetest.sound_play("mesecons_switch", {pos=pos})
end,
on_updated_from_nodedb = function(pos, node)
mesecon.receptor_on(pos)
end,
advtrains = {
getstate = "on",
setstate = function(pos, node, newstate)
if newstate=="off" then
advtrains.ndb.swap_node(pos, {name="mesecons_switch:mesecon_switch_off", param2=node.param2})
if advtrains.is_node_loaded(pos) then
mesecon.receptor_off(pos)
end
end
end,
fallback_state = "off",
on_updated_from_nodedb = function(pos, node)
mesecon.receptor_on(pos)
end,
},
})

View file

@ -527,7 +527,7 @@ function advtrains.train_step_c(id, train, dtime)
local collpos = advtrains.path_get(train, atround(collindex))
if collpos then
local rcollpos=advtrains.round_vector_floor_y(collpos)
local is_loaded_area = minetest.get_node_or_nil(rcollpos) ~= nil
local is_loaded_area = advtrains.is_node_loaded(rcollpos)
for x=-train.extent_h,train.extent_h do
for z=-train.extent_h,train.extent_h do
local testpos=vector.add(rcollpos, {x=x, y=0, z=z})
@ -870,14 +870,7 @@ function advtrains.spawn_wagons(train_id)
local index = advtrains.path_get_index_by_offset(train, train.index, -data.pos_in_train)
local pos = advtrains.path_get(train, atfloor(index))
local spawn = false
for _,p in pairs(minetest.get_connected_players()) do
if vector.distance(p:get_pos(),pos)<=ablkrng then
spawn = true
end
end
if spawn then
if advtrains.position_in_range(pos, ablkrng) then
--atdebug("wagon",w_id,"spawning")
local wt = advtrains.get_wagon_prototype(data)
local wagon = minetest.add_entity(pos, wt):get_luaentity()
@ -1032,7 +1025,7 @@ function advtrains.train_check_couples(train)
if not train.cpl_front then
-- recheck front couple
local front_trains, pos = advtrains.occ.get_occupations(train, atround(train.index) + CPL_CHK_DST)
if minetest.get_node_or_nil(pos) then -- if the position is loaded...
if advtrains.is_node_loaded(pos) then -- if the position is loaded...
for tid, idx in pairs(front_trains) do
local other_train = advtrains.trains[tid]
if not advtrains.train_ensure_init(tid, other_train) then
@ -1062,7 +1055,7 @@ function advtrains.train_check_couples(train)
if not train.cpl_back then
-- recheck back couple
local back_trains, pos = advtrains.occ.get_occupations(train, atround(train.end_index) - CPL_CHK_DST)
if minetest.get_node_or_nil(pos) then -- if the position is loaded...
if advtrains.is_node_loaded(pos) then -- if the position is loaded...
for tid, idx in pairs(back_trains) do
local other_train = advtrains.trains[tid]
if not advtrains.train_ensure_init(tid, other_train) then

View file

@ -15,19 +15,8 @@ advtrains.wagon_prototypes = {}
advtrains.wagon_objects = {}
local unload_wgn_range = advtrains.wagon_load_range + 32
function advtrains.outside_range(pos) -- returns true if the object is outside of unload_wgn_range of any player
-- this is part of a workaround until mintest core devs decide to fix a bug with static_save=false.
local outofrange = true
if not pos then
return true
end
for _,p in pairs(minetest.get_connected_players()) do
if vector.distance(p:get_pos(),pos)<=unload_wgn_range then
outofrange = false
break
end
end
return outofrange
function advtrains.wagon_outside_range(pos) -- returns true if the object is outside of unload_wgn_range of any player
return not advtrains.position_in_range(pos, unload_wgn_range)
end
local setting_show_ids = minetest.settings:get_bool("advtrains_show_ids")
@ -300,6 +289,8 @@ function wagon:on_step(dtime)
local train=self:train()
local is_in_loaded_area = advtrains.is_node_loaded(pos)
--custom on_step function
if self.custom_on_step then
self:custom_on_step(dtime, data, train)
@ -453,7 +444,7 @@ function wagon:on_step(dtime)
end
--checking for environment collisions(a 3x3 cube around the center)
if not train.recently_collided_with_env then
if is_in_loaded_area and not train.recently_collided_with_env then
local collides=false
local exh = self.extent_h or 1
local exv = self.extent_v or 2
@ -477,7 +468,7 @@ function wagon:on_step(dtime)
--DisCouple
-- FIX: Need to do this after the yaw calculation
if data.pos_in_trainparts and data.pos_in_trainparts>1 then
if is_in_loaded_area and data.pos_in_trainparts and data.pos_in_trainparts>1 then
if train.velocity==0 then
if not self.discouple or not self.discouple.object:getyaw() then
atprint(self.id,"trying to spawn discouple")
@ -530,7 +521,7 @@ function wagon:on_step(dtime)
end
end
if not players_in then
if advtrains.outside_range(pos) then
if advtrains.wagon_outside_range(pos) then
--atdebug("wagon",self.id,"unloading (too far away)")
-- Workaround until minetest engine deletes attached sounds
if self.sound_loop_handle then

485
mods/advtrains/advtrains_luaautomation/README.txt Normal file → Executable file
View file

@ -1,288 +1,359 @@
#### Advtrains - Lua Automation features
# Advtrains - Lua Automation features
This mod offers components that run LUA code and interface with each other through a global environment. It makes complex automated railway systems possible.
This mod offers components that run LUA code and interface with each other through a global environment. It makes complex automated railway systems possible. The mod is sometimes abbreviated as 'atlatc'. This stands for AdvTrainsLuaATC. This short name has been chosen for user convenience, since the name of this mod ('advtrains_luaautomation') is very long.
### atlatc
The mod is sometimes abbreviated as 'atlatc'. This stands for AdvTrainsLuaATC. This short name has been chosen for user convenience, since the name of this mod ('advtrains_luaautomation') is very long.
### Privilege
## Privileges
To perform any operations using this mod (except executing operation panels), players need the "atlatc" privilege.
This privilege should never be granted to anyone except trusted administrators. Even though the LUA environment is sandboxed, it is still possible to DoS the server by coding infinite loops or requesting expotentially growing interrupts.
### Active and passive
Active components are these who have LUA code running in them. They are triggered on specific events. Passive components are dumb, they only have a state and can be set to another state, they can't perform actions themselves.
## Environments
### Environments
Each active component is assigned to an environment. This is where all data are held. Components in different environments can't inferface with each other.
Each active component is assigned to an environment where all atlac data is held. Components in different environments can't inferface with each other.
This system allows multiple independent automation systems to run simultaneously without polluting each other's environment.
/env_create <env_name>
Create environment with the given name. To be able to do anything, you first need to create an environment. Choose the name wisely, you can't change it afterwards.
- `/env_create <env_name>`:
Create environment with the given name. To be able to do anything, you first need to create an environment. Choose the name wisely, you can't change it afterwards without deleting the environment and starting again.
/env_setup <env_name>
- `/env_setup <env_name>`:
Invoke the form to edit the environment's initialization code. For more information, see the section on active components. You can also delete an environment from here.
### Active components
## Functions and variables
### General Functions and Variables
The following standard Lua libraries are available:
- `string`
- `math`
- `table`
- `os`
The code of every active component is run on specific events which are explained soon. When run, every variable written that is not local and is no function or userdata is saved over code re-runs and over server restarts. Additionally, the following global variables are defined:
The following standard Lua functions are available:
- `assert`
- `error`
- `ipairs`
- `pairs`
- `next`
- `select`
- `tonumber`
- `tostring`
- `type`
- `unpack`
# event
The variable 'event' contains a table with information on the current event. How this table can look is explained below.
Any attempt to overwrite the predefined values results in an error.
# S
## Components and Events
### Components
Atlac components introduce automation-capable components that fall within two categories:
- Active Components are components that are able to run Lua code, triggered by specific events.
- Passive Components can't perform actions themselves. Their state can be read and set by active components or manually by the player.
## Functions and Variables
### Events
The event table is a variable created locally by the component being triggered. It is a table with the following format:
```lua
event = {
type = "<event type>",
<event type> = true,
--additional event-specific content
}
```
You can check the event type by using the following:
```lua
if event.type == "wanted" then
--do stuff
end
```
or
```lua
if event.wanted then
--do stuff
end
````
where `wanted` is the event type to check for.
See the "Active Components" section below for details on the various event types as not all of them are applicable to all components.
### LuaAutomation Global Variables
- `S`
The variable 'S' contains a table which is shared between all components of the environment. Its contents are persistent over server restarts. May not contain functions, every other value is allowed.
Example:
Component 1: S.stuff="foo"
Component 2: print(S.stuff)
-> foo
# F
- `F`
The variable 'F' also contains a table which is shared between all components of the environment. Its contents are discarded on server shutdown or when the init code gets re-run. Every data type is allowed, even functions.
The purpose of this table is not to save data, but to provide static value and function definitions. The table should be populated by the init code.
# Standard Lua functions
The following standard Lua libraries are available:
string, math, table, os
The following standard Lua functions are available:
assert, error, ipairs, pairs, next, select, tonumber, tostring, type, unpack
### LuaAutomation Global Functions
> Note: in the following functions, all parameters named `pos` designate a position. You can use the following:
> - a default Minetest position vector (eg. {x=34, y=2, z=-18})
> - the POS(34,2,-18) shorthand below.
> - A string, the passive component name. See 'passive component naming'.
Every attempt to overwrite any of the predefined values results in an error.
# LuaAutomation-specific global functions
POS(x,y,z)
Shorthand function to create a position vector {x=?, y=?, z=?} with less characters
- `POS(x,y,z)`
Shorthand function to create a position vector {x=?, y=?, z=?} with less characters.
In the following functions, all parameters named 'pos' designate a position. You can use either:
- a default Minetest position vector (like {x=34, y=2, z=-18})
- the POS(34,2,-18) shorthand
- A string, the passive component name. See 'passive component naming'.
- `getstate(pos)`
Get the state of the passive component at position `pos`.
getstate(pos)
Get the state of the passive component at position 'pos'. See section on passive components for more info.
pos can be either a position vector (created by POS()) or a string, the name of this passive component.
- `setstate(pos, newstate)`
Set the state of the passive component at position `pos`.
setstate(pos, newstate)
Set the state of the passive component at position 'pos'.
is_passive(pos)
- `is_passive(pos)`
Checks whether there is a passive component at the position pos (and/or whether a passive component with this name exists)
interrupt(time, message)
Cause LuaAutomation to trigger an 'int' event on this component after the given time in seconds with the specified 'message' field. 'message' can be of any Lua data type.
Not available in init code!
- `interrupt(time, message)`
Cause LuaAutomation to trigger an `int` event on this component after the given time in seconds with the specified `message` field. `message` can be of any Lua data type. *Not available in init code.*
interrupt_pos(pos, message)
Immediately trigger an 'ext_int' event on the active component at position pos. 'message' is like in interrupt().
USE WITH CARE, or better don't use! Incorrect use can result in expotential growth of interrupts.
- `interrupt_pos(pos, message)`
Immediately trigger an `ext_int` event on the active component at position pos. `message` is like in interrupt(). Use with care, or better **_don't use_**! Incorrect use can result in **_expotential growth of interrupts_**.
digiline_send(channel, message)
- `digiline_send(channel, message)`
Make this active component send a digiline message on the specified channel.
Not available in init code!
Not available in init code.
-- The next 4 functions are available when advtrains_interlocking is enabled: --
#### Interlocking Route Management Functions
If `advtrains_interlocking` is enabled, the following aditional functions can be used:
can_set_route(pos, route_name)
- `can_set_route(pos, route_name)`
Returns whether it is possible to set the route designated by route_name from the signal at pos.
set_route(pos, route_name)
- `set_route(pos, route_name)`
Requests the given route from the signal at pos. Has the same effect as clicking "Set Route" in the signalling dialog.
cancel_route(pos)
- `cancel_route(pos)`
Cancels the route that is set from the signal at pos. Has the same effect as clicking "Cancel Route" in the signalling dialog.
get_aspect(pos)
- `get_aspect(pos)`
Returns the signal aspect of the signal at pos. A signal aspect has the following format:
aspect = {
```lua
{
main = { -- the next track section in line. Shows blocked for shunt routes
free = <boolean>,
speed = <int km/h>,
},
shunt = { -- whether a "shunting allowed" aspect should be shown
free = <boolean>,
}
},
dst = { -- the aspect of the next main signal on (at end of) route
free = <boolean>,
speed = <int km/h>,
}
},
info = {
call_on = <boolean>, -- Call-on route, expect train in track ahead
dead_end = <boolean>, -- Route ends on a dead end (e.g. bumper)
}
}
As of August 2018, only the aspect.main.free field is ever used by the interlocking system.
```
As of August 2018 (git commit d837e7e), only the aspect.main.free field is ever used by the interlocking system.
# Lines
### Active Component
#### Lua ATC Rails
Lua ATC rails are the only components that can actually interface with trains. The following event types are available to the Lua ATC rails:
- ```lua
{type="train", train=true, id="<train_id>"}
```
* This event is fired when a train enters the rail. The field `id` is the unique train ID, which is 6-digit random numerical string.
* If the world contains trains from an older advtrains version, this string may be longer and contain a dot `.`
- ```lua
{type="int", int=true, msg=<message>}
```
* Fired when an interrupt set by the `interrupt` function runs out. `<message>` is the message passed to the interrupt function.
* For backwards compatiblity reasons, `<message>` is also contained in an `event.message` variable.
- ```lua
{type="ext_int", ext_int=true, message=<message>}
```
* Fired when another node called `interrupt_pos` on this position. `message` is the message passed to the interrupt_pos function.
- ```lua
{type="digiline", digiline=true, channel=<channel>, msg=<message>}
```
* Fired when the controller receives a digiline message.
##### Basic Lua Rail Functions and Variables
In addition to the above environment functions, the following functions are available to whilst the train is in contact with the LuaATC rail:
- `atc_send(<atc_command>)`
Sends the specified ATC command to the train (a string) and returns true. If there is no train, returns false and does nothing. See [atc_command.txt](../atc_command.txt) for the ATC command syntax.
- `atc_reset()`
Resets the train's current ATC command. If there is no train, returns false and does nothing.
- `atc_arrow`
Boolean, true when the train is driving in the direction of the arrows of the ATC rail. Nil if there is no train.
- `atc_id`
Train ID of the train currently passing the controller. Nil if there's no train.
- `atc_speed`
Speed of the train, or nil if there is no train.
- `atc_set_text_outside(text)`
Set text shown on the outside of the train. Pass nil to show no text. `text` must be a string.
- `atc_set_text_inside(text)`
Set text shown to train passengers. Pass nil to show no text. `text` must be a string.
- `get_line()`
Returns the "Line" property of the train (a string).
This can be used to distinguish between trains of different lines and route them appropriately.
The interlocking system also uses this property for Automatic Routesetting.
- `set_line(line)`
Sets the "Line" property of the train (a string).
If the first digit of this string is a number (0-9), any subway wagons on the train (from advtrains_train_subway) will have this one displayed as line number
(where "0" is actually shown as Line 10 on the train)
- `get_rc()`
Returns the "Routingcode" property of the train (a string).
The interlocking system uses this property for Automatic Routesetting.
- `set_rc(routingcode)`
Sets the "Routingcode" property of the train (a string).
The interlocking system uses this property for Automatic Routesetting.
##### Shunting Functions and Variables
There are several functions available especially for shunting operations. Some of these functions make use of Freight Codes (FC) set in the Wagon Properties of each wagon and/or locomotive:
- `split_at_index(index, atc_command)`
Splits the train at the specified index, into a train with index-1 wagons and a second train starting with the index-th wagon. The `atc_command` specified is sent to the second train after decoupling. `"S0"` or `"B0"` is common to ensure any locomotives in the remaining train don't continue to move.
Example: train has wagons `"foo","foo","foo","bar","bar","bar"`
Command: `split_at_index(4,"S0")`
Result: first train (continues at previous speed): `"foo","foo","foo"`, second train (slows at S0): `"bar","bar","bar"`
- `split_at_fc(atc_command, len)`
Splits the train in such a way that all cars with non-empty current FC of the first part of the train have the same FC. The
`atc_command` specified is sent to the rear part, as with split_at_index. It returns the fc of the cars of the first part.
Example : Train has current FCs `"" "" "bar" "foo" "bar"`
Command: `split_at_fc(<atc_command>)`
Result: `train "" "" "bar"` and `train "foo" "bar"`
The function returns `"bar"` in this case.
The optional argument `len` specifies the maximum length for the
first part of the train.
Example: Train has current FCs `"foo" "foo" "foo" "foo" "bar" "bar"`
Command: `split_at_fc(<atc_command>,3)`
Result: `"foo" "foo" "foo"` and `"foo" "bar" "bar"`
The function returns `"foo"` in this case.
- `split_off_locomotive(command, len)`
Splits off the locomotives at the front of the train, which are
identified by an empty FC. `command` specifies the ATC command to be
executed by the rear half of the train. The optional argument `len` specifies the maximum length for the
first part of the train as above.
- `step_fc()`
Steps the FCs of all train cars forward. FCs are composed of codes
separated by exclamation marks (`!`), for instance
`"foo!bar!baz"`. Each wagon has a current FC, indicating its next
destination. Stepping the freight code forward, selects the next
code after the !. If the end of the string is reached, then the
first code is selected, except if the string ends with a question
mark (`?`), then the order is reversed.
- `train_length()`
returns the number of cars the train is composed of.
- `set_autocouple()`
Sets the train into autocouple mode. The train will couple to the next train it collides with.
- `unset_autocouple()`
Unsets autocouple mode
Deprecated:
- `set_shunt()`, `unset_shunt()`
deprecated aliases for set_autocouple() and unset_autocouple(), will be removed from a later release.
##### Timetable Automation
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 https://advtrains.de/wiki/doku.php?id=dev:lines:rwt
- `rwt.*`
All Railway Time functions are included as documented in https://advtrains.de/wiki/doku.php?id=dev:lines:rwt
- 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)
- `schedule(rw_time, msg)`
- `schedule_in(rw_dtime, msg)`
Schedules the following event `{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.
## Components and events
#### Operator panel
This simple node executes its actions when punched. It can be used to change a switch and update the corresponding signals or similar applications. It can also be connected to by the`digilines` mod.
The event table is a table of the following format:
{
type = "<type>",
<type> = true,
... additional content ...
}
You can check for the event type by either using
if event.type == "wanted" then ...do stuff... end
or
if event.wanted then ...do stuff... end
(if 'wanted' is the event type to check for)
The event fired is `{type="punch", punch=true}` by default. In case of an interrupt or a digiline message, the events are similar to the ones of the ATC rail.
# Init code
#### Init code
The initialization code is not a component as such, but rather a part of the whole environment. It can (and should) be used to make definitions that other components can refer to.
Examples:
A function to define behavior for trains in subway stations:
function F.station()
if event.train then atc_send("B0WOL") end
if event.int and event.message="depart" then atc_send("OCD1SM") end
A basic example function to define behavior for trains in stations:
```lua
function F.station(station_name)
if event.train then
atc_send("B0WOL")
atc_set_text_inside(station_name)
interrupt(10,"depart")
end
if event.int and event.message="depart" then
atc_set_text_inside("") --an empty string clears the displayed text
atc_send("OCD1SM")
end
end
````
The corresponding Lua ATC Rail(s) would then contain the following or similar:
````lua
F.station("Main Station")
````
The init code is run whenever the F table needs to be refilled with data. This is the case on server startup and whenever the init code is changed and you choose to run it.
Functions are run in the environment of the currently active node, regardless of where they were defined. So, the 'event' table always reflects the state of the calling node.
The 'event' table of the init code is always {type="init", init=true}.
# ATC rails
The Lua-controlled ATC rails are the only components that can actually interface with trains. The following event types are generated:
{type="train", train=true, id="<train_id>"}
This event is fired when a train enters the rail. The field 'id' is the unique train ID, which is 6-digit random numerical string.
If the world contains trains from an older advtrains version, this string may be longer and contain a dot (.)
{type="int", int=true, msg=<message>}
Fired when an interrupt set by the 'interrupt' function runs out. 'message' is the message passed to the interrupt function.
For backwards compatiblity reasons, <message> is also contained in an event.message field.
{type="ext_int", ext_int=true, message=<message>}
Fired when another node called 'interrupt_pos' on this position. 'message' is the message passed to the interrupt_pos function.
{type="digiline", digiline=true, channel=<channel>, msg=<message>}
Fired when the controller receives a digiline message.
In addition to the default environment functions, the following functions are available:
atc_send(<atc_command>)
Sends the specified ATC command to the train and returns true. If there is no train, returns false and does nothing.
atc_reset()
Resets the train's current ATC command. If there is no train, returns false and does nothing.
atc_arrow
Boolean, true when the train is driving in the direction of the arrows of the ATC rail. Nil if there is no train.
atc_id
Train ID of the train currently passing the controller. Nil if there's no train.
atc_speed
Speed of the train, or nil if there is no train.
atc_set_text_outside(text)
Set text shown on the outside of the train. Pass nil to show no text.
atc_set_text_inside(text)
Set text shown to train passengers. Pass nil to show no text.
get_line()
Returns the "Line" property of the train (a string).
This can be used to distinguish between trains of different lines and route them appropriately.
The interlocking system also uses this property for Automatic Routesetting.
set_line(line)
Sets the "Line" property of the train (a string).
If the first digit of this string is a number (0-9), any subway wagons on the train will have this one displayed as line number
(where "0" is actually shown as Line 10 on the train)
get_rc()
Returns the "Routingcode" property of the train (a string).
The interlocking system uses this property for Automatic Routesetting.
set_rc(routingcode)
Sets the "Routingcode" property of the train (a string).
The interlocking system uses this property for Automatic Routesetting.
split_at_index(index, command)
Splits the train at the specified index, into a train with index-1 wagons and a second train starting with the index-th wagon.
command specifies an atc command to be sent to the second train after decoupling.
split_at_fc(command, len)
Splits the train in such a way that all cars with non-empty
current FC of the first part of the train have the same FC. The
command specified is sent to the rear part, as with
split_at_index. It returns the fc of the cars of the first part.
The optional argument len specifies the maximum length for the
first part of the train. Say, we have len=3, and the train has ""
"" "foo" "foo" "foo" "bar", then the first train part will be ""
"" "foo".
Example : Train has current FCs "" "" "foo" "bar" "foo"
Result: first train: "" "" "foo"; second train: "bar" "foo"
The command returns "foo" in this case
split_off_locomotive(command, len)
Splits off the locomotives at the front of the train, which are
identified by an empty FC. command specifies the command to be
executed by the rear half of the train.
The optional argument len specifies the maximum length for the
first part of the train. Say, we have len=3, and the train has ""
"" "foo" "foo" "foo" "bar", then the first train part will be ""
"" "foo".
step_fc()
Steps the FCs of all train cars forward. FCs are composed of codes
separated by exclamation marks (!), for instance
"foo!bar!baz". Each wagon has a current FC, indicating its next
destination. Stepping the freight code forward, selects the next
code after the !. If the end of the string is reached, then the
first code is selected, except if the string ends with a question
mark, then the order is reversed.
train_length()
returns the number of cars the train is composed of
set_autocouple()
Sets the train into autocouple mode
unset_autocouple()
Unsets autocouple mode
set_shunt(), unset_shunt()
deprecated aliases for set_autocouple() and unset_autocouple(), will be removed from a later release.
# Operator panel
This simple node executes its actions when punched. It can be used to change a switch and update the corresponding signals or similar applications.
The event fired is {type="punch", punch=true} by default. In case of an interrupt or a digiline message, the events are similar to the ones of the ATC rail.
The event table of the init code is always `{type="init", init=true}` and can not be anything else.
Functions are run in the environment of the currently active node, regardless of where they were defined.
### Passive components
All passive components can be interfaced with the setstate and getstate functions(see above).
Below, each apperance is mapped to the "state" of that node.
All passive components can be interfaced with the `setstate()` and `getstate()` functions (see above).
Each node below has been mapped to specific "states":
## Signals
The light signals are interfaceable, the analog signals are not.
"green" - Signal shows green light
"red" - Signal shows red light
#### Signals
The red/green light signals `advtrains:signal_on/off` are interfaceable. Others such as `advtrains:retrosignal_on/off` are not. If advtrains_interlocking is enabled, trains will obey the signal if the influence point is set.
- "green" - Signal shows green light
- "red" - Signal shows red light
## Switches
#### Switches/Turnouts
All default rail switches are interfaceable, independent of orientation.
"cr" - The switch is set in the direction that is not straight.
"st" - The switch is set in the direction that is straight.
- "cr" The switch is set in the direction that is not straight.
- "st" The switch is set in the direction that is straight.
## Mesecon Switch
The Mesecon switch can be switched using LuaAutomation. Note that this is not possible on levers, only the full-node 'Switch' block.
"on" - the switch is switched on
"off" - the switch is switched off
The "Y" and "3-Way" switches have custom states. Looking from the convergence point:
- "l" The switch is set towards the left.
- "c" The switch is set towards the center (3-way only).
- "r" The switch is set towards the right.
##Andrew's Cross
"on" - it blinks
"off" - it does not blink
### Passive component naming
#### Mesecon Switch
The Mesecon switch can be switched using LuaAutomation. Note that this is not possible on levers or protected mesecon switches, only the unprotected full-node 'Switch' block `mesecons_switch:mesecon_switch_on/off`.
- "on" - the switch is switched on.
- "off" - the switch is switched off.
#### Andrew's Cross
- "on" - it blinks.
- "off" - it does not blink.
#### Passive Component Naming
You can assign names to passive components using the Passive Component Naming tool.
Once you set a name for any component, you can reference it by that name in the getstate() and setstate() functions, like this:
(Imagine a signal that you have named "Stn_P1_out" at position (1,2,3) )
setstate("Stn_P1_out", "green") instead of setstate(POS(1,2,3), "green")
Once you set a name for any component, you can reference it by that name in the `getstate()` and `setstate()` functions.
This way, you don't need to memorize positions.
PC-Naming can also be used to name interlocking signals for route setting via the set_route() functions. IMPORTANT: The "Signal Name" set in the
signalling formspec is completely independent and can NOT be used to look up the position, you need to explicitly use the PCNaming tool.
Example: signal named `"Stn_P1_out"` at `(1,2,3)`
Use `setstate("Stn_P1_out", "green")` instead of `setstate(POS(1,2,3), "green")`
If `advtrains_interlocking` is enabled, PC-Naming can also be used to name interlocking signals for route setting via the `set_route()` functions.
**Important**: The "Signal Name" field in the signalling formspec is completely independent from PC-Naming and can't be used to look up the position. You need to explicitly use the PC-Naming tool.
--TODO: Ein paar mehr Codebeispiele wären schön, insbesondere mit os.date und so...

View file

@ -101,7 +101,7 @@ function ac.run_in_env(pos, evtdata, customfct_p)
end
local meta
if minetest.get_node_or_nil(pos) then
if advtrains.is_node_loaded(pos) then
meta=minetest.get_meta(pos)
end
@ -125,9 +125,11 @@ function ac.run_in_env(pos, evtdata, customfct_p)
if minetest.global_exists("digiline") then
customfct.digiline_send=function(channel, msg)
assertt(channel, "string")
if advtrains.is_node_loaded(pos) then
digiline:receptor_send(pos, digiline.rules.default, channel, msg)
end
end
end
-- add lines scheduler if enabled
if advtrains.lines and advtrains.lines.sched then
customfct.schedule = function(rwtime, msg)

View file

@ -318,10 +318,15 @@ if mesecon then
}
},
advtrains = {
on_updated_from_nodedb = function(pos, node)
mesecon.receptor_off(pos, advtrains.meseconrules)
end,
on_train_enter=function(pos, train_id)
advtrains.ndb.swap_node(pos, {name="advtrains:dtrack_detector_on".."_"..suffix..rotation, param2=advtrains.ndb.get_node(pos).param2})
if advtrains.is_node_loaded(pos) then
mesecon.receptor_on(pos, advtrains.meseconrules)
end
end
}
}
end
@ -343,10 +348,15 @@ if mesecon then
}
},
advtrains = {
on_updated_from_nodedb = function(pos, node)
mesecon.receptor_on(pos, advtrains.meseconrules)
end,
on_train_leave=function(pos, train_id)
advtrains.ndb.swap_node(pos, {name="advtrains:dtrack_detector_off".."_"..suffix..rotation, param2=advtrains.ndb.get_node(pos).param2})
if advtrains.is_node_loaded(pos) then
mesecon.receptor_off(pos, advtrains.meseconrules)
end
end
}
}
end

View file

@ -177,6 +177,7 @@ core.register_entity(":__builtin:item", {
end
local name1 = stack:get_meta():get_string("description")
local name
if name1 == "" then
name = core.registered_items[itemname].description

View file

@ -8,7 +8,7 @@ local use_cmi = minetest.global_exists("cmi")
mobs = {
mod = "redo",
version = "20210114",
version = "20210206",
intllib = S,
invis = minetest.global_exists("invisibility") and invisibility or {}
}
@ -539,12 +539,10 @@ local ray_line_of_sight = function(self, pos1, pos2)
return true
end
-- detect if using minetest 5.0 by searching for permafrost node
local is_50 = minetest.registered_nodes["default:permafrost"]
function mob_class:line_of_sight(pos1, pos2, stepsize)
if is_50 then -- only use if minetest 5.0 is detected
if minetest.raycast then -- only use if minetest 5.0 is detected
return ray_line_of_sight(self, pos1, pos2)
end
@ -1354,11 +1352,15 @@ function mob_class:breed()
self.on_grown(self)
else
-- jump when fully grown so as not to fall into ground
self.object:set_velocity({
x = 0,
y = self.jump_height,
z = 0
})
-- self.object:set_velocity({
-- x = 0,
-- y = self.jump_height,
-- z = 0
-- })
local pos = self.object:get_pos() ; if not pos then return end
local ent = self.object:get_luaentity()
pos.y = pos.y + (ent.collisionbox[2] * -1) - 0.4
self.object:set_pos(pos)
end
end
@ -1458,6 +1460,8 @@ function mob_class:breed()
effect(pos, 15, "tnt_smoke.png", 1, 2, 2, 15, 5)
end
pos.y = pos.y + 0.5 -- spawn child a little higher
local mob = minetest.add_entity(pos, self.name)
local ent2 = mob:get_luaentity()
local textures = self.base_texture

View file

@ -1,4 +1,4 @@
name = mobs_sky
name = mobs_bat
depends = default, mobs
optional_depends =
description = Adds bats into your world.

View file

@ -19,6 +19,11 @@ minetest.register_node("woodsoils:dirt_with_leaves_1", {
sounds = default.node_sound_dirt_defaults({
footstep = {name="default_grass_footstep", gain=0.4},
}),
soil = {
base = "woodsoils:dirt_with_leaves_1",
dry = "farming:soil",
wet = "farming:soil_wet"
}
})
minetest.register_node("woodsoils:dirt_with_leaves_2", {
@ -37,6 +42,11 @@ minetest.register_node("woodsoils:dirt_with_leaves_2", {
sounds = default.node_sound_dirt_defaults({
footstep = {name="default_grass_footstep", gain=0.4},
}),
soil = {
base = "woodsoils:dirt_with_leaves_2",
dry = "farming:soil",
wet = "farming:soil_wet"
}
})
minetest.register_node("woodsoils:grass_with_leaves_1", {
@ -55,6 +65,11 @@ minetest.register_node("woodsoils:grass_with_leaves_1", {
sounds = default.node_sound_dirt_defaults({
footstep = {name="default_grass_footstep", gain=0.4},
}),
soil = {
base = "woodsoils:grass_with_leaves_1",
dry = "farming:soil",
wet = "farming:soil_wet"
}
})
minetest.register_node("woodsoils:grass_with_leaves_2", {
@ -73,6 +88,11 @@ minetest.register_node("woodsoils:grass_with_leaves_2", {
sounds = default.node_sound_dirt_defaults({
footstep = {name="default_grass_footstep", gain=0.4},
}),
soil = {
base = "woodsoils:grass_with_leaves_2",
dry = "farming:soil",
wet = "farming:soil_wet"
}
})
-- For compatibility with older stuff

View file

@ -105,9 +105,9 @@ local function update1(self, pos, dir)
end
local function update2(self, pos1, dir1, pos2, dir2)
local fpos1,fdir1 = self:walk_tube_line(pos1, dir1)
local fpos2,fdir2 = self:walk_tube_line(pos2, dir2)
if not fdir1 or not fdir2 then -- line to long?
local fpos1,fdir1,cnt1 = self:walk_tube_line(pos1, dir1)
local fpos2,fdir2,cnt2 = self:walk_tube_line(pos2, dir2)
if cnt1 + cnt2 >= self.max_tube_length then -- line to long?
-- reset next tube(s) to head tube(s) again
local param2 = self:encode_param2(dir1, dir2, 2)
self:update_after_dig_tube(pos1, param2)

View file

@ -62,7 +62,7 @@ local Tube = tubelib2.Tube:new({
-- dirs_to_check = {1,2,3,4}, -- horizontal only
-- dirs_to_check = {5,6}, -- vertical only
dirs_to_check = {1,2,3,4,5,6},
max_tube_length = 1000,
max_tube_length = 10,
show_infotext = true,
primary_node_names = {"tubelib2:tubeS", "tubelib2:tubeA"},
secondary_node_names = {"default:chest", "default:chest_open",
@ -385,18 +385,45 @@ local function remove_tube(itemstack, placer, pointed_thing)
end
end
local function walk(itemstack, placer, pointed_thing)
--local function walk(itemstack, placer, pointed_thing)
-- if pointed_thing.type == "node" then
-- local pos = pointed_thing.under
-- local dir = (minetest.dir_to_facedir(placer:get_look_dir()) % 4) + 1
-- local t = minetest.get_us_time()
-- local pos1, outdir1, pos2, outdir2, cnt = Tube:walk(pos, dir)
-- t = minetest.get_us_time() - t
-- print("time", t)
-- if pos1 then
-- local s = "[Tubelib2] pos1="..P2S(pos1)..", outdir1="..outdir1..", pos2="..P2S(pos2)..", outdir2="..outdir2..", cnt="..cnt
-- minetest.chat_send_player(placer:get_player_name(), s)
-- end
-- else
-- local dir = (minetest.dir_to_facedir(placer:get_look_dir()) % 4) + 1
-- minetest.chat_send_player(placer:get_player_name(),
-- "[Tool Help] dir="..dir.."\n"..
-- " left: remove node\n"..
-- " right: repair tube line\n")
-- end
--end
local function repair_tube(itemstack, placer, pointed_thing)
if pointed_thing.type == "node" then
local pos = pointed_thing.under
local dir = (minetest.dir_to_facedir(placer:get_look_dir()) % 4) + 1
local t = minetest.get_us_time()
local pos1, outdir1, pos2, outdir2, cnt = Tube:walk(pos, dir)
t = minetest.get_us_time() - t
print("time", t)
if pos1 then
local s = "[Tubelib2] pos1="..P2S(pos1)..", outdir1="..outdir1..", pos2="..P2S(pos2)..", outdir2="..outdir2..", cnt="..cnt
local _, _, fpos1, fpos2, _, _, cnt1, cnt2 = Tube:tool_repair_tube(pos)
local length = cnt1 + cnt2
local s = "Tube from " .. P2S(fpos1) .. " to " .. P2S(fpos2) .. ". Lenght = " .. length
minetest.chat_send_player(placer:get_player_name(), s)
if length > Tube.max_tube_length then
local s = string.char(0x1b) .. "(c@#ff0000)" .. "Tube length error!"
minetest.chat_send_player(placer:get_player_name(), s)
end
minetest.sound_play("carts_cart_new", {
pos = pos,
gain = 1,
max_hear_distance = 5})
else
local dir = (minetest.dir_to_facedir(placer:get_look_dir()) % 4) + 1
minetest.chat_send_player(placer:get_player_name(),
@ -406,10 +433,6 @@ local function walk(itemstack, placer, pointed_thing)
end
end
local function debug(itemstack, placer, pointed_thing)
Tube:dbg_out()
end
-- Tool for tube workers to crack a protected tube line
minetest.register_node("tubelib2:tool", {
description = "Tubelib2 Tool",
@ -418,7 +441,7 @@ minetest.register_node("tubelib2:tool", {
use_texture_alpha = true,
groups = {cracky=1, book=1},
on_use = remove_tube,
on_place = debug,
on_place = repair_tube,
node_placement_prediction = "",
stack_max = 1,
})