summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcheapie <no-email-for-you@example.com>2015-10-20 16:15:59 -0500
committercheapie <no-email-for-you@example.com>2015-10-20 16:15:59 -0500
commit350150cf7fb58f672a5b4fb29ff0b6e5701bd006 (patch)
treee3b90395db566e8752074d414224bdc81492244f
parentb806b65a93a801b3032000b0c9289947036b08c9 (diff)
downloadlightcontroller-350150cf7fb58f672a5b4fb29ff0b6e5701bd006.tar
lightcontroller-350150cf7fb58f672a5b4fb29ff0b6e5701bd006.tar.gz
lightcontroller-350150cf7fb58f672a5b4fb29ff0b6e5701bd006.tar.bz2
lightcontroller-350150cf7fb58f672a5b4fb29ff0b6e5701bd006.tar.xz
lightcontroller-350150cf7fb58f672a5b4fb29ff0b6e5701bd006.zip
Add stuff
-rw-r--r--COPYING14
-rw-r--r--README8
-rw-r--r--depends.txt1
-rw-r--r--init.lua89
-rw-r--r--init.lua.save48
5 files changed, 160 insertions, 0 deletions
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..5a8e332
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,14 @@
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+ Version 2, December 2004
+
+ Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
+
+ Everyone is permitted to copy and distribute verbatim or modified
+ copies of this license document, and changing it is allowed as long
+ as the name is changed.
+
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. You just DO WHAT THE FUCK YOU WANT TO.
+
diff --git a/README b/README
new file mode 100644
index 0000000..f1b88e6
--- /dev/null
+++ b/README
@@ -0,0 +1,8 @@
+This mod adds two nodes that can be used to easily set up traffic lights.
+
+
+Use:
+
+* Install a normal traffic light setup, with the main street's lights on the "main" channel and the side street's lights on "side".
+* Place the master unit on a minor street approach and connect it with digilines
+* (4+-way intersections only) Place a slave unit on all other minor street approaches, and connect them with digilines to the master unit, but NOT to the lights
diff --git a/depends.txt b/depends.txt
new file mode 100644
index 0000000..da1d119
--- /dev/null
+++ b/depends.txt
@@ -0,0 +1 @@
+digilines
diff --git a/init.lua b/init.lua
new file mode 100644
index 0000000..564f4db
--- /dev/null
+++ b/init.lua
@@ -0,0 +1,89 @@
+local emit_signals = function(pos)
+ local meta = minetest.get_meta(pos)
+ if meta:get_string("locked")~="true" then
+ meta:set_string("locked","true")
+ digiline:receptor_send(pos, digiline.rules.default, "main", "RED")
+ minetest.after(5,function(pos)
+ digiline:receptor_send(pos, digiline.rules.default, "side", "GREEN")
+ minetest.after(10,function(pos)
+ digiline:receptor_send(pos, digiline.rules.default, "side", "RED")
+ minetest.after(5,function(pos)
+ digiline:receptor_send(pos, digiline.rules.default, "main", "GREEN")
+ minetest.after(15,function(pos)
+ local meta = minetest.get_meta(pos)
+ meta:set_string("locked","false")
+ end,pos)
+ end,pos)
+ end,pos)
+ end,pos)
+ end
+end
+
+local lc_scan = function(pos)
+ local objs = minetest.get_objects_inside_radius(pos, 6)
+ if objs then
+ local _,obj
+ for _,obj in ipairs(objs) do
+ if obj:is_player() then
+ emit_signals(pos)
+ return
+ end
+ end
+ end
+end
+
+local lc_slave_scan = function(pos)
+ local objs = minetest.get_objects_inside_radius(pos, 6)
+ if objs then
+ local _,obj
+ for _,obj in ipairs(objs) do
+ if obj:is_player() then
+ digiline:receptor_send(pos, digiline.rules.default, "detector", "car")
+ return
+ end
+ end
+ end
+end
+
+local on_digiline_receive = function (pos, node, channel, msg)
+ if channel=="detector" then emit_signals(pos) end
+end
+
+minetest.register_node("lightcontroller:trafficnext", {
+ description = "TrafficNeXt SoC - Master",
+ tiles = {"streets_tl_bg.png","streets_tl_bg.png","streets_tl_bg.png^streets_tl_green.png","streets_tl_bg.png^streets_tl_green.png","streets_tl_bg.png^streets_tl_green.png","streets_tl_bg.png^streets_tl_green.png"},
+ groups = {cracky=3, stone=1},
+ sounds = default.node_sound_stone_defaults(),
+ digiline =
+ {
+ receptor = {},
+ effector = { action = on_digiline_receive },
+ },
+ on_punch = function(pos) emit_signals(pos) end
+})
+
+minetest.register_abm({
+ nodenames = {"lightcontroller:trafficnext"},
+ interval = 1.0,
+ chance = 1,
+ action = function(pos) lc_scan(pos) end
+})
+
+minetest.register_node("lightcontroller:trafficnext_slave", {
+ description = "TrafficNeXt SoC - Slave",
+ tiles = {"streets_tl_bg.png","streets_tl_bg.png","streets_tl_bg.png^streets_tl_red.png","streets_tl_bg.png^streets_tl_red.png","streets_tl_bg.png^streets_tl_red.png","streets_tl_bg.png^streets_tl_red.png"},
+ groups = {cracky=3, stone=1},
+ sounds = default.node_sound_stone_defaults(),
+ digiline =
+ {
+ receptor = {},
+ effector = { action = function() end},
+ },
+})
+
+minetest.register_abm({
+ nodenames = {"lightcontroller:trafficnext_slave"},
+ interval = 1.0,
+ chance = 1,
+ action = function(pos) lc_slave_scan(pos) end
+})
diff --git a/init.lua.save b/init.lua.save
new file mode 100644
index 0000000..a577ef4
--- /dev/null
+++ b/init.lua.save
@@ -0,0 +1,48 @@
+-- This function somewhat "borrowed" from Mesecons
+local light_controller_scan = function (pos)
+ local objs = minetest.get_objects_inside_radius(pos, mesecon.setting("detector_radius", 6))
+ for k, obj in pairs(objs) do
+ local isname = obj:get_player_name()
+ if (isname ~= "") then
+ return true
+ end
+ end
+ return false
+end
+
+
+
+local emit_signals = function(pos)
+ local meta = minetest.get_meta(pos)
+ if meta:get_string("locked")~="true" then
+ meta:set_string("locked","true")
+ digiline:receptor_send(pos, digiline.rules.default, "main", "RED")
+ minetest.after(5,function(pos)
+ digiline:receptor_send(pos, digiline.rules.default, "side", "GREEN")
+ minetest.after(10,function(pos)
+ digiline:receptor_send(pos, digiline.rules.default, "side", "RED")
+ minetest.after(5,function(pos)
+ digiline:receptor_send(pos, digiline.rules.default, "main", "GREEN")
+ minetest.after(15,function(pos)
+ local meta = minetest.get_meta(pos)
+ meta:set_string("locked","false")
+ end,pos)
+ end,pos)
+ end,pos)
+ end,pos)
+ end
+end
+
+
+minetest.register_node("lightcontroller:trafficnext", {
+ description = "TrafficNeXt SoC",
+ tiles = {"default_stone.png"},
+ groups = {cracky=3, stone=1},
+ sounds = default.node_sound_stone_defaults(),
+ digiline =
+ {
+ receptor = {},
+ effector = {},
+ },
+ on_punch = function(pos) emit_signals(pos) end
+})