1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2025-04-02 02:30:37 +02:00

[mesecons] Update

This commit is contained in:
LeMagnesium 2016-08-01 00:30:16 +02:00
parent e0a3d098f5
commit f8fd6f05d5
No known key found for this signature in database
GPG Key ID: A54DDB5272C51E8B
6 changed files with 81 additions and 51 deletions

View File

@ -76,7 +76,7 @@ function mesecon.get_conductor(nodename)
end end
end end
function mesecon.get_any_outputrules (node) function mesecon.get_any_outputrules(node)
if not node then return nil end if not node then return nil end
if mesecon.is_conductor(node.name) then if mesecon.is_conductor(node.name) then
@ -86,7 +86,7 @@ function mesecon.get_any_outputrules (node)
end end
end end
function mesecon.get_any_inputrules (node) function mesecon.get_any_inputrules(node)
if not node then return nil end if not node then return nil end
if mesecon.is_conductor(node.name) then if mesecon.is_conductor(node.name) then
@ -96,7 +96,7 @@ function mesecon.get_any_inputrules (node)
end end
end end
function mesecon.get_any_rules (node) function mesecon.get_any_rules(node)
return mesecon.mergetable(mesecon.get_any_inputrules(node) or {}, return mesecon.mergetable(mesecon.get_any_inputrules(node) or {},
mesecon.get_any_outputrules(node) or {}) mesecon.get_any_outputrules(node) or {})
end end
@ -381,27 +381,41 @@ function mesecon.turnon(pos, link)
-- area not loaded, postpone action -- area not loaded, postpone action
if not node then if not node then
mesecon.queue:add_action(f.pos, "turnon", {link}, nil, true) mesecon.queue:add_action(f.pos, "turnon", {f.link}, nil, true)
elseif mesecon.is_conductor_off(node, f.link) then elseif mesecon.is_conductor_off(node, f.link) then
local rules = mesecon.conductor_get_rules(node) local rules = mesecon.conductor_get_rules(node)
minetest.swap_node(f.pos, {name = mesecon.get_conductor_on(node, f.link), -- Success: If false, at least one neighboring node is unloaded,
param2 = node.param2}) -- postpone turning on action
local success = true
local neighborlinks = {}
-- call turnon on neighbors: normal rules -- call turnon on neighbors
for _, r in ipairs(mesecon.rule2meta(f.link, rules)) do for _, r in ipairs(mesecon.rule2meta(f.link, rules)) do
local np = vector.add(f.pos, r) local np = vector.add(f.pos, r)
-- area not loaded, postpone action -- Neighboring node not loaded, postpone turning on current node
-- since we can't even know if neighboring node has matching rules
if not mesecon.get_node_force(np) then if not mesecon.get_node_force(np) then
mesecon.queue:add_action(np, "turnon", {rulename}, success = false
nil, true) break
else else
local links = mesecon.rules_link_rule_all(f.pos, r) neighborlinks[minetest.hash_node_position(np)] = mesecon.rules_link_rule_all(f.pos, r)
end
end
if success then
minetest.swap_node(f.pos, {name = mesecon.get_conductor_on(node, f.link),
param2 = node.param2})
for npos, links in pairs(neighborlinks) do
-- links = all links to node, l = each single link
for _, l in ipairs(links) do for _, l in ipairs(links) do
table.insert(frontiers, {pos = np, link = l}) table.insert(frontiers, {pos = minetest.get_position_from_hash(npos), link = l})
end end
end end
else
mesecon.queue:add_action(f.pos, "turnon", {f.link}, nil, true)
end end
elseif mesecon.is_effector(node.name) then elseif mesecon.is_effector(node.name) then
mesecon.changesignal(f.pos, node, f.link, mesecon.state.on, depth) mesecon.changesignal(f.pos, node, f.link, mesecon.state.on, depth)
@ -413,7 +427,7 @@ function mesecon.turnon(pos, link)
end end
end end
mesecon.queue:add_function("turnon", function (pos, rulename, recdepth) mesecon.queue:add_function("turnon", function(pos, rulename, recdepth)
mesecon.turnon(pos, rulename, recdepth) mesecon.turnon(pos, rulename, recdepth)
end) end)
@ -427,27 +441,41 @@ function mesecon.turnoff(pos, link)
-- area not loaded, postpone action -- area not loaded, postpone action
if not node then if not node then
mesecon.queue:add_action(f.pos, "turnoff", {link}, nil, true) mesecon.queue:add_action(f.pos, "turnoff", {f.link}, nil, true)
elseif mesecon.is_conductor_on(node, f.link) then elseif mesecon.is_conductor_on(node, f.link) then
local rules = mesecon.conductor_get_rules(node) local rules = mesecon.conductor_get_rules(node)
minetest.swap_node(f.pos, {name = mesecon.get_conductor_off(node, f.link), -- Success: If false, at least one neighboring node is unloaded,
param2 = node.param2}) -- postpone turning on action
local success = true
local neighborlinks = {}
-- call turnoff on neighbors: normal rules -- call turnoff on neighbors
for _, r in ipairs(mesecon.rule2meta(f.link, rules)) do for _, r in ipairs(mesecon.rule2meta(f.link, rules)) do
local np = vector.add(f.pos, r) local np = vector.add(f.pos, r)
-- area not loaded, postpone action -- Neighboring node not loaded, postpone turning off current node
-- since we can't even know if neighboring node has matching rules
if not mesecon.get_node_force(np) then if not mesecon.get_node_force(np) then
mesecon.queue:add_action(np, "turnoff", {rulename}, success = false
nil, true) break
else else
local links = mesecon.rules_link_rule_all(f.pos, r) neighborlinks[minetest.hash_node_position(np)] = mesecon.rules_link_rule_all(f.pos, r)
end
end
if success then
minetest.swap_node(f.pos, {name = mesecon.get_conductor_off(node, f.link),
param2 = node.param2})
for npos, links in pairs(neighborlinks) do
-- links = all links to node, l = each single link
for _, l in ipairs(links) do for _, l in ipairs(links) do
table.insert(frontiers, {pos = np, link = l}) table.insert(frontiers, {pos = minetest.get_position_from_hash(npos), link = l})
end end
end end
else
mesecon.queue:add_action(f.pos, "turnoff", {f.link}, nil, true)
end end
elseif mesecon.is_effector(node.name) then elseif mesecon.is_effector(node.name) then
mesecon.changesignal(f.pos, node, f.link, mesecon.state.off, depth) mesecon.changesignal(f.pos, node, f.link, mesecon.state.off, depth)
@ -459,7 +487,7 @@ function mesecon.turnoff(pos, link)
end end
end end
mesecon.queue:add_function("turnoff", function (pos, rulename, recdepth) mesecon.queue:add_function("turnoff", function(pos, rulename, recdepth)
mesecon.turnoff(pos, rulename, recdepth) mesecon.turnoff(pos, rulename, recdepth)
end) end)
@ -523,8 +551,8 @@ function mesecon.rules_link(output, input, dug_outputrules) --output/input are p
local outputnode = mesecon.get_node_force(output) local outputnode = mesecon.get_node_force(output)
local inputnode = mesecon.get_node_force(input) local inputnode = mesecon.get_node_force(input)
local outputrules = dug_outputrules or mesecon.get_any_outputrules (outputnode) local outputrules = dug_outputrules or mesecon.get_any_outputrules(outputnode)
local inputrules = mesecon.get_any_inputrules (inputnode) local inputrules = mesecon.get_any_inputrules(inputnode)
if not outputrules or not inputrules then if not outputrules or not inputrules then
return return
end end
@ -547,7 +575,7 @@ end
function mesecon.rules_link_rule_all(output, rule) function mesecon.rules_link_rule_all(output, rule)
local input = vector.add(output, rule) local input = vector.add(output, rule)
local inputnode = mesecon.get_node_force(input) local inputnode = mesecon.get_node_force(input)
local inputrules = mesecon.get_any_inputrules (inputnode) local inputrules = mesecon.get_any_inputrules(inputnode)
if not inputrules then if not inputrules then
return {} return {}
end end
@ -567,7 +595,7 @@ function mesecon.rules_link_rule_all_inverted(input, rule)
--local irule = mesecon.invertRule(rule) --local irule = mesecon.invertRule(rule)
local output = vector.add(input, rule) local output = vector.add(input, rule)
local outputnode = mesecon.get_node_force(output) local outputnode = mesecon.get_node_force(output)
local outputrules = mesecon.get_any_outputrules (outputnode) local outputrules = mesecon.get_any_outputrules(outputnode)
if not outputrules then if not outputrules then
return {} return {}
end end

View File

@ -87,10 +87,6 @@ end
mesecon.queue:add_function("cooldown", function (pos) mesecon.queue:add_function("cooldown", function (pos)
if minetest.get_item_group(minetest.get_node(pos).name, "overheat") == 0 then
return -- node has been moved, this one does not use overheating - ignore
end
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local heat = meta:get_int("heat") local heat = meta:get_int("heat")

View File

@ -10,24 +10,12 @@ local toggle_timer = function (pos)
end end
local on_timer = function (pos) local on_timer = function (pos)
local activate = false
for _, player in pairs(minetest.get_connected_players()) do
local p = player:getpos()
local dist = ((p.x-pos.x)^2 + (p.y-pos.y)^2 + (p.z-pos.z)^2)^0.5
if dist < 40 then
activate = true
break
end
end
if activate then
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
if(mesecon.flipstate(pos, node) == "on") then if(mesecon.flipstate(pos, node) == "on") then
mesecon.receptor_on(pos) mesecon.receptor_on(pos)
else else
mesecon.receptor_off(pos) mesecon.receptor_off(pos)
end end
end
toggle_timer(pos) toggle_timer(pos)
end end

View File

@ -93,9 +93,22 @@ local function receive_fields(pos, formname, fields, sender)
end end
local function resolve_commands(commands, pos) local function resolve_commands(commands, pos)
local players = minetest.get_connected_players()
-- No players online: remove all commands containing
-- @nearest, @farthest and @random
if #players == 0 then
commands = commands:gsub("[^\r\n]+", function (line)
if line:find("@nearest") then return "" end
if line:find("@farthest") then return "" end
if line:find("@random") then return "" end
return line
end)
return commands
end
local nearest, farthest = nil, nil local nearest, farthest = nil, nil
local min_distance, max_distance = math.huge, -1 local min_distance, max_distance = math.huge, -1
local players = minetest.get_connected_players()
for index, player in pairs(players) do for index, player in pairs(players) do
local distance = vector.distance(pos, player:getpos()) local distance = vector.distance(pos, player:getpos())
if distance < min_distance then if distance < min_distance then

View File

@ -508,10 +508,15 @@ local digiline = {
end end
} }
} }
local function on_receive_fields(pos, form_name, fields) local function on_receive_fields(pos, form_name, fields, sender)
if not fields.program then if not fields.program then
return return
end end
local name = sender:get_player_name()
if minetest.is_protected(pos, name) and not minetest.check_player_privs(name, {protection_bypass=true}) then
minetest.record_protection_violation(pos, name)
return
end
reset(pos) reset(pos)
reset_meta(pos, fields.code) reset_meta(pos, fields.code)
local err = run(pos, {type="program"}) local err = run(pos, {type="program"})

View File

@ -26,7 +26,7 @@ minetest.register_craft({
-- GHOSTSTONE -- GHOSTSTONE
minetest.register_node("mesecons_random:ghoststone", { minetest.register_node("mesecons_random:ghoststone", {
description="ghoststone", description="Ghoststone",
tiles = {"jeija_ghoststone.png"}, tiles = {"jeija_ghoststone.png"},
is_ground_content = true, is_ground_content = true,
inventory_image = minetest.inventorycube("jeija_ghoststone_inv.png"), inventory_image = minetest.inventorycube("jeija_ghoststone_inv.png"),