built on 01/08/2021 11:00:22
19
README.md
@ -7,6 +7,7 @@ This modpack includes:
|
||||
- techage: The main mod
|
||||
- ta4_jetpack: A Jetpack for techage with hydrogen as fuel and TA4 recipe
|
||||
- ta4_paraglider: A Paraglider for techage with TA4 recipe
|
||||
- ta4_addons: A Touchscreen like the TA4 display, but with additional commands and features
|
||||
- autobahn: Street blocks and slopes with stripes for faster traveling (the only need of bitumen from techage)
|
||||
- compost: The garden soil is needed for the TA4 LED Grow Light based flower bed
|
||||
- signs_bot: For many automation tasks in TA3/TA4 like farming, mining, and item transportation
|
||||
@ -19,6 +20,7 @@ This modpack includes:
|
||||
- doc: Ingame documentation mod, used for minecart and signs_bot
|
||||
- unified_inventory V1: Player's inventory with crafting guide, bags, and more.
|
||||
- tubelib2: Necessary library
|
||||
- networks: Necessary library
|
||||
- safer_lua: Necessary library
|
||||
- lcdlib: Necessary library
|
||||
- datastorage: Necessary library
|
||||
@ -45,6 +47,23 @@ ta4_jetpack requires the modpack 3d_armor. 3d_armor is itself a modpack and can'
|
||||
### History
|
||||
|
||||
|
||||
#### 2021-08-01
|
||||
|
||||
Added Mods:
|
||||
- networks
|
||||
- ta4_addons (Touchscreen)
|
||||
|
||||
Changed Mods:
|
||||
- techage (see readme and constuction board)
|
||||
- minecart (see readme "Migration to v2")
|
||||
|
||||
Updated Mods:
|
||||
- autobahn
|
||||
- signs_bot
|
||||
- hyperloop
|
||||
- ta4_jetpack
|
||||
|
||||
|
||||
#### 2021-05-14
|
||||
|
||||
Updated Mods:
|
||||
|
@ -10,7 +10,7 @@ default
|
||||
Optional: moreblocks, techage, minecart
|
||||
|
||||
# License
|
||||
Copyright (C) 2017-2020 Joachim Stolberg
|
||||
Copyright (C) 2017-2021 Joachim Stolberg
|
||||
Code: Licensed under the GNU GPL version 3 or later. See LICENSE.txt
|
||||
Textures: CC BY-SA 3.0
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
Autobahn
|
||||
|
||||
Copyright (C) 2017-2020 Joachim Stolberg
|
||||
Copyright (C) 2017-2021 Joachim Stolberg
|
||||
GPL v3
|
||||
See LICENSE.txt for more information
|
||||
|
||||
@ -17,6 +17,9 @@ local S = minetest.get_translator("autobahn")
|
||||
|
||||
autobahn = {}
|
||||
|
||||
-- Test for MT 5.4 new string mode
|
||||
autobahn.CLIP = minetest.features.use_texture_alpha_string_modes and "clip" or true
|
||||
|
||||
local Facedir2Dir = {[0] =
|
||||
{x=0, y=0, z=1},
|
||||
{x=1, y=0, z=0},
|
||||
@ -237,6 +240,7 @@ local function register_node(name, tiles, drawtype, mesh, box, drop)
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
sunlight_propagates = true,
|
||||
use_texture_alpha = autobahn.CLIP,
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
is_ground_content = false,
|
||||
groups = {cracky=2, crumbly=2,
|
||||
@ -332,8 +336,7 @@ if minetest.global_exists("techage") then
|
||||
},
|
||||
replacements = {{"techage:ta3_barrel_bitumen", "techage:ta3_barrel_empty"}},
|
||||
})
|
||||
end
|
||||
if minetest.global_exists("moreblocks") then
|
||||
elseif minetest.global_exists("moreblocks") then
|
||||
minetest.register_craft({
|
||||
output = "autobahn:node1 4",
|
||||
recipe = {
|
||||
|
@ -308,6 +308,7 @@ minetest.register_node("hyperloop:booking_ground", {
|
||||
|
||||
on_receive_fields = on_receive_fields,
|
||||
on_destruct = on_destruct,
|
||||
on_rightclick = on_rightclick,
|
||||
|
||||
on_rotate = screwdriver.disallow,
|
||||
drop = "hyperloop:booking",
|
||||
|
@ -266,23 +266,36 @@ minetest.register_node("hyperloop:shaftA2", {
|
||||
|
||||
-- Form spec for the floor list
|
||||
local function formspec(pos, lFloors)
|
||||
local tRes = {"size[5,10]label[0.5,0; "..S("Select your destination").."]"}
|
||||
tRes[2] = "label[1,0.6;"..S("Destination").."]label[2.5,0.6;"..S("Floor").."]"
|
||||
local tRes = {"size[6,10]label[0.5,0; "..S("Select your destination").."]"}
|
||||
tRes[2] = "label[0.5,0.6;"..S("Destination").."]label[2,0.6;"..S("Floor").."]"
|
||||
if #lFloors == 0 then
|
||||
tRes[#tRes+1] = "button_exit[1,3;3,1;button;Update]"
|
||||
elseif #lFloors < 10 then
|
||||
for idx,floor in ipairs(lFloors) do
|
||||
if idx >= 12 then
|
||||
break
|
||||
end
|
||||
local ypos = 0.5 + idx*0.8
|
||||
local ypos2 = ypos - 0.2
|
||||
tRes[#tRes+1] = "button_exit[1,"..ypos2..";1,1;button;"..(#lFloors-idx).."]"
|
||||
tRes[#tRes+1] = "button_exit[0.5,"..ypos2..";1,1;button;"..(#lFloors-idx).."]"
|
||||
if vector.equals(floor.pos, pos) then
|
||||
tRes[#tRes+1] = "label[2.5,"..ypos..";"..S("(current position)").."]"
|
||||
tRes[#tRes+1] = "label[2,"..ypos..";"..S("(current position)").."]"
|
||||
else
|
||||
tRes[#tRes+1] = "label[2.5,"..ypos..";"..(floor.name or "<unknown>").."]"
|
||||
tRes[#tRes+1] = "label[2,"..ypos..";"..(floor.name or "<unknown>").."]"
|
||||
end
|
||||
end
|
||||
if #tRes == 2 then
|
||||
tRes[#tRes+1] = "button_exit[1,3;3,1;button;Update]"
|
||||
else
|
||||
tRes[3] = "scrollbaroptions[smallstep=100;largestep=200]"
|
||||
tRes[4] = "scrollbar[5.3,1.5;0.4,8.2;vertical;floors;0]"
|
||||
tRes[5] = "scroll_container[0.5,2;5,9.5;floors;vertical;0.02]"
|
||||
for idx,floor in ipairs(lFloors) do
|
||||
local ypos = idx*0.8 - 0.5
|
||||
local ypos2 = ypos - 0.2
|
||||
tRes[#tRes+1] = "button_exit[0,"..ypos2..";1,1;button;"..(#lFloors-idx).."]"
|
||||
if vector.equals(floor.pos, pos) then
|
||||
tRes[#tRes+1] = "label[1.5,"..ypos..";"..S("(current position)").."]"
|
||||
else
|
||||
tRes[#tRes+1] = "label[1.5,"..ypos..";"..(floor.name or "<unknown>").."]"
|
||||
end
|
||||
end
|
||||
tRes[#tRes+1] = "scroll_container_end[]"
|
||||
end
|
||||
return table.concat(tRes)
|
||||
end
|
||||
|
@ -69,6 +69,7 @@ local function get_stations(tStations, sKey, tRes)
|
||||
if not tRes[dest] then
|
||||
-- Known station?
|
||||
if tStations[dest] then
|
||||
tStations[dest].name = tStations[dest].name or ""
|
||||
tRes[dest] = tStations[dest]
|
||||
get_stations(tStations, dest, tRes)
|
||||
end
|
||||
@ -143,7 +144,7 @@ function Network:set(pos, name, tAttr)
|
||||
conn = {},
|
||||
}
|
||||
end
|
||||
self.tStations[sKey].name = name
|
||||
self.tStations[sKey].name = name or ""
|
||||
for k,v in pairs(tAttr) do
|
||||
self.tStations[sKey][k] = v
|
||||
end
|
||||
|
@ -16,27 +16,23 @@
|
||||
|
||||
-- 'pos' is the position of the puncher/sensor, the cart
|
||||
-- position will be determined by means of 'param2' and 'radius'
|
||||
|
||||
-- Function returns true for all standing carts (entities and nodes)
|
||||
function minecart.is_cart_available(pos, param2, radius)
|
||||
local pos2 = minecart.get_nodecart_nearby(pos, param2, radius)
|
||||
if pos2 then
|
||||
return true
|
||||
end
|
||||
-- The entity check is needed for a cart with driver
|
||||
local entity = minecart.get_entitycart_nearby(pos, param2, radius)
|
||||
if entity then
|
||||
return true
|
||||
end
|
||||
return minecart.get_nodecart_nearby(pos, param2, radius) ~= nil or
|
||||
minecart.get_entitycart_nearby(pos, param2, radius) ~= nil
|
||||
end
|
||||
|
||||
-- Function returns true if a standing cart as node is avaliable
|
||||
function minecart.is_nodecart_available(pos, param2, radius)
|
||||
local pos2 = minecart.get_nodecart_nearby(pos, param2, radius)
|
||||
if pos2 then
|
||||
return true
|
||||
end
|
||||
return minecart.get_nodecart_nearby(pos, param2, radius) ~= nil
|
||||
end
|
||||
|
||||
-- Function returns true if a standing cart as entity is avaliable
|
||||
function minecart.is_entitycart_available(pos, param2, radius)
|
||||
return minecart.get_entitycart_nearby(pos, param2, radius) ~= nil
|
||||
end
|
||||
|
||||
-- 'pos' is the position of the puncher/sensor, the cart
|
||||
-- position will be determined by means of 'param2' and 'radius'
|
||||
function minecart.punch_cart(pos, param2, radius, punch_dir)
|
||||
local pos2, node = minecart.get_nodecart_nearby(pos, param2, radius)
|
||||
if pos2 then
|
||||
|
@ -75,7 +75,8 @@ function minecart.find_node_near_lvm(pos, radius, items)
|
||||
for y = pos1.y, pos2.y do
|
||||
for z = pos1.z, pos2.z do
|
||||
local idx = area:indexp({x = x, y = y, z = z})
|
||||
if minetest.get_name_from_content_id(data[idx]) then
|
||||
local name = minetest.get_name_from_content_id(data[idx])
|
||||
if name and tItems[name] then
|
||||
return {x = x, y = y, z = z}
|
||||
end
|
||||
end
|
||||
@ -96,7 +97,7 @@ function minecart.set_marker(pos, text, size, ttl)
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_entity(":minecart:marker_cube", {
|
||||
minetest.register_entity("minecart:marker_cube", {
|
||||
initial_properties = {
|
||||
visual = "cube",
|
||||
textures = {
|
||||
@ -118,6 +119,41 @@ minetest.register_entity(":minecart:marker_cube", {
|
||||
end,
|
||||
})
|
||||
|
||||
function minecart.set_land_marker(pos, radius, ttl)
|
||||
local offs = radius + 0.5
|
||||
local posses = {
|
||||
{x = pos.x + offs, y = pos.y, z=pos.z},
|
||||
{x = pos.x, y = pos.y, z=pos.z + offs},
|
||||
{x = pos.x - offs, y = pos.y, z=pos.z},
|
||||
{x = pos.x, y = pos.y, z=pos.z - offs},
|
||||
}
|
||||
for i, pos in ipairs(posses) do
|
||||
local marker = minetest.add_entity(pos, "minecart:marker")
|
||||
if marker ~= nil then
|
||||
marker:set_properties({
|
||||
visual_size = {x = 2 * offs, y = 2 * offs},
|
||||
collisionbox = {-offs, -offs, 0, offs, offs, 0},
|
||||
})
|
||||
marker:set_yaw(math.pi / 2 * i)
|
||||
minetest.after(ttl, marker.remove, marker)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_entity("minecart:marker", {
|
||||
initial_properties = {
|
||||
visual = "upright_sprite",
|
||||
textures = {"minecart_marker_cube.png"},
|
||||
use_texture_alpha = true,
|
||||
physical = false,
|
||||
glow = 12,
|
||||
static_save = false,
|
||||
},
|
||||
on_punch = function(self)
|
||||
self.object:remove()
|
||||
end,
|
||||
})
|
||||
|
||||
function minecart.is_air_like(name)
|
||||
local ndef = minetest.registered_nodes[name]
|
||||
if ndef and ndef.buildable_to then
|
||||
@ -270,12 +306,12 @@ function minecart.add_entitycart(pos, node_name, entity_name, vel, cargo, owner,
|
||||
end
|
||||
end
|
||||
|
||||
function minecart.start_entitycart(self, pos)
|
||||
function minecart.start_entitycart(self, pos, facedir)
|
||||
local route = {}
|
||||
|
||||
self.is_running = true
|
||||
self.arrival_time = 0
|
||||
self.start_pos = minecart.get_buffer_pos(pos, self.owner)
|
||||
self.start_pos = minecart.get_buffer_pos(pos, self.owner) or minecart.get_next_buffer(pos, facedir)
|
||||
if self.start_pos then
|
||||
-- Read buffer route for the junction info
|
||||
route = minecart.get_route(self.start_pos) or {}
|
||||
|
@ -13,6 +13,8 @@
|
||||
local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end
|
||||
local P2H = minetest.hash_node_position
|
||||
local H2P = minetest.get_position_from_hash
|
||||
local LEN = function(t) local c = 0; for _ in pairs(t) do c = c + 1 end; return c; end
|
||||
|
||||
local MAX_SPEED = minecart.MAX_SPEED
|
||||
local dot2dir = minecart.dot2dir
|
||||
local get_waypoint = minecart.get_waypoint
|
||||
@ -71,7 +73,14 @@ local function running(self)
|
||||
local dir = minetest.yaw_to_dir(rot.y)
|
||||
dir.y = math.floor((rot.x / (math.pi/4)) + 0.5)
|
||||
dir = vector.round(dir)
|
||||
local facedir = minetest.dir_to_facedir(dir)
|
||||
-- If running in a 45 degree direction (extra cycle), use the old dir
|
||||
-- to calculate face_dir. Otherwise the junction detection will not work as expected.
|
||||
local facedir
|
||||
if self.waypoint and self.waypoint.old_dir then
|
||||
facedir = minetest.dir_to_facedir(self.waypoint.old_dir)
|
||||
else
|
||||
facedir = minetest.dir_to_facedir(dir)
|
||||
end
|
||||
local cart_pos, wayp_pos, is_junction
|
||||
|
||||
if self.reenter then -- through monitoring
|
||||
@ -115,7 +124,7 @@ local function running(self)
|
||||
self.ctrl = nil
|
||||
end
|
||||
|
||||
--print("dist", P2S(cart_pos), P2S(self.waypoint.pos), P2S(self.waypoint.cart_pos), self.waypoint.dot)
|
||||
--print("running", LEN(self.junctions))
|
||||
local dist = vector.distance(cart_pos, self.waypoint.cart_pos or self.waypoint.pos)
|
||||
local new_dir = dot2dir(self.waypoint.dot)
|
||||
local new_speed = new_speed(self, new_dir)
|
||||
@ -129,7 +138,7 @@ local function running(self)
|
||||
local new_cart_pos, extra_cycle = minecart.get_current_cart_pos_correction(
|
||||
wayp_pos, facedir, dir.y, self.waypoint.dot) -- TODO: Why has self.waypoint no dot?
|
||||
if extra_cycle and not vector.equals(cart_pos, new_cart_pos) then
|
||||
self.waypoint = {pos = wayp_pos, cart_pos = new_cart_pos}
|
||||
self.waypoint = {pos = wayp_pos, cart_pos = new_cart_pos, old_dir = vector.new(dir)}
|
||||
new_dir = vector.direction(cart_pos, new_cart_pos)
|
||||
dist = vector.distance(cart_pos, new_cart_pos)
|
||||
--print("extra_cycle", P2S(cart_pos), P2S(wayp_pos), P2S(new_cart_pos), new_speed)
|
||||
@ -174,7 +183,7 @@ local function play_sound(self)
|
||||
self.sound_handle = minetest.sound_play(
|
||||
"carts_cart_moving", {
|
||||
object = self.object,
|
||||
gain = self.curr_speed / MAX_SPEED,
|
||||
gain = (self.curr_speed or 0) / MAX_SPEED,
|
||||
})
|
||||
end
|
||||
end
|
||||
@ -243,9 +252,11 @@ local function on_entitycard_punch(self, puncher, time_from_last_punch, tool_cap
|
||||
local pos = vector.round(self.object:get_pos())
|
||||
if puncher then
|
||||
local yaw = puncher:get_look_horizontal()
|
||||
dir = minetest.yaw_to_dir(yaw)
|
||||
self.object:set_rotation({x = 0, y = yaw, z = 0})
|
||||
end
|
||||
minecart.start_entitycart(self, pos)
|
||||
local facedir = minetest.dir_to_facedir(dir or {x=0, y=0, z=0})
|
||||
minecart.start_entitycart(self, pos, facedir or 0)
|
||||
minecart.start_recording(self, pos)
|
||||
end
|
||||
end
|
||||
|
@ -2,7 +2,6 @@
|
||||
Station name=Stationsname
|
||||
Waiting time/sec=Wartezeit/s
|
||||
connected to=verbunden mit
|
||||
Minecart Railway Buffer=Minecart Prellbock
|
||||
Summary=Zusammenfassung
|
||||
1. Place your rails and build a route with two endpoints. Junctions are allowed as long as each route has its own start and endpoint.=1. Baue eine Schienenstrecke mit zwei Enden. Kreuzungen sind zulässig, solange jede Route ihre eigenen Start- und Endpunkte hat.
|
||||
2. Place a Railway Buffer at both endpoints (buffers are always needed, they store the route and timing information).=2. Platziere einen Prellbock an beide Schienenenden (Prellböcke sind zwingend notwendig, sie speichern die Routen- und Zeit-Informationen).
|
||||
@ -26,7 +25,10 @@ Minecart Cart=Wagen
|
||||
Minecart Speed Signs=Geschwindigkeitsbegrenzungszeichen
|
||||
If several carts are running on one route,@nit can happen that a buffer position is already occupied and one cart therefore stops earlier.@nIn this case, the cart pusher is used to push the cart towards the buffer again.@nThis block must be placed under the rail at a distance of 2 m in front of the buffer.=Wenn mehrere Wagen auf einer Route fahren, kann es vorkommen,@ndass eine Prellbock Position bereits belegt ist und ein Wagen daher früher anhält.@nDer Cart Anschieber dient in diesem Fall dazu, die Wagen wieder in Richtung Prellbock anzuschieben.@nDieser Block muss unter der Schiene mit 2 m Abstand vor dem Prellbock platziert werden.
|
||||
Limit the cart speed with speed limit signs.@n@nAs before, the speed of the carts is also influenced by power rails.@nBrake rails are irrelevant, the cart does not brake here.@nThe maximum speed is 8 m/s. This assumes a ratio of power rails@nto normal rails of 1 to 4 on a flat section of rail. A rail section is a@nseries of rail nodes without a change of direction. After every curve / kink,@nthe speed for the next section of the route is newly determined,@ntaking into account the swing of the cart. This means that a cart can@nroll over short rail sections without power rails.@n@nIn order to additionally brake the cart at certain points@n(at switches or in front of a buffer), speed limit signs can be placed@non the track. With these signs the speed can be reduced to 4, 2, or 1 m / s.@nThe "No speed limit" sign can be used to remove the speed limit.@n@nThe speed limit signs must be placed next to the track so that they can@nbe read from the cart. This allows different speeds in each direction of travel.=Begrenze die Geschwindigkeit der Wagen mit Geschwindigkeitsbegrenzungszeichen@n@nDie Geschwindigkeit der Carts wird wie bisher auch über "power rails" beeinflusst. "Brake rails" sind ohne Bedeutung, das Cart bremst hier nicht. Die maximale Geschwindigkeit beträgt 8 m/s. Dies setzt eine Verhältnis von "power rails" zu "normal rails" von 1 zu 4 auf einem ebenen Streckenabschnitt voraus. Ein Streckenabschnitt ist dabei ein Reihe von Schienenblöcken ohne Richtungsänderung. Nach jeder Kurve/Knick wird die Geschwindigkeit für den nächsten Streckenabschnitt neu bestimmt, wobei hier der Schwung des Carts mit berücksichtigt wird. So kann ein Cart auch über kurze Streckenabschnitt ohne "power rails" rollen.@n@nUm das Cart zusätzlich an bestimmten Stellen abzubremsen (an Weichen oder vor einen Puffer), können Geschwindigkeitsbegrenzungszeichen an der Strecke platziert werden. Durch diese Zeichen kann die Geschwindigkeit auf 4, 2, oder 1 m/s reduziert werden. Durch das Aufhebungszeichen kann die Geschwindigkeitsbegrenzung wieder aufgehoben werden.@n@nDie Geschwindigkeitsbegrenzungszeichen müssen so neben die Strecke platziert werden, dass sie vom Cart ablesbar sind. Dies erlaubt damit unterschiedliche Geschwindigkeiten pro Fahrtrichtung.
|
||||
Minecart Railway Buffer=Minecart Prellbock
|
||||
Minecart Hopper=Minecart Hopper
|
||||
Minecart Landmark=Minecart Meilenstein
|
||||
Cart Pusher=Wagen Anschieber
|
||||
Minecart (Sneak+Click to pick up)=Minecart (Shift+Klick zum Entfernen des Carts)
|
||||
Output cart state and position, or a list of carts, if no cart number is given.=Gibt Status und Position des Wagens, oder eine Liste aller Wagen aus, wenn keine Wagennummer angegeben ist.
|
||||
List of carts=Liste aller Wagen
|
||||
@ -34,8 +36,6 @@ Enter cart number=Gebe Cart Nummer ein
|
||||
Save=Speichern
|
||||
[minecart] Area is protected!=[minecart] Bereich ist geschützt!
|
||||
Allow to dig/place rails in Minecart Landmark areas=Erlaubt dir, Schienen in Meilensteinbereichen zu setzen/zu entfernen
|
||||
Minecart Landmark=Minecart Meilenstein
|
||||
Cart Pusher=Wagen Anschieber
|
||||
left=links
|
||||
right=rechts
|
||||
straight=geradeaus
|
||||
@ -45,6 +45,7 @@ next junction=nächste Weiche
|
||||
Travel time=Fahrzeit
|
||||
[minecart] Route stored!=[minecart] Strecke gespeichert
|
||||
[minecart] Speed @= %u m/s, Time @= %u s, Route length @= %u m=[minecart] Geschw. @= %u m/s, Zeit @= %u s, Routenlänge @= %u m
|
||||
[minecart] Your route is too short to record!=[minecart] Deine Strecke ist zu kurz für eine Aufzeichnung!
|
||||
Speed "1"=Tempo "1"
|
||||
Speed "2"=Tempo "2"
|
||||
Speed "4"=Tempo "4"
|
||||
|
@ -2,7 +2,6 @@
|
||||
Station name=
|
||||
Waiting time/sec=
|
||||
connected to=
|
||||
Minecart Railway Buffer=
|
||||
Summary=
|
||||
1. Place your rails and build a route with two endpoints. Junctions are allowed as long as each route has its own start and endpoint.=
|
||||
2. Place a Railway Buffer at both endpoints (buffers are always needed, they store the route and timing information).=
|
||||
@ -26,7 +25,10 @@ Minecart Cart=
|
||||
Minecart Speed Signs=
|
||||
If several carts are running on one route,@nit can happen that a buffer position is already occupied and one cart therefore stops earlier.@nIn this case, the cart pusher is used to push the cart towards the buffer again.@nThis block must be placed under the rail at a distance of 2 m in front of the buffer.=
|
||||
Limit the cart speed with speed limit signs.@n@nAs before, the speed of the carts is also influenced by power rails.@nBrake rails are irrelevant, the cart does not brake here.@nThe maximum speed is 8 m/s. This assumes a ratio of power rails@nto normal rails of 1 to 4 on a flat section of rail. A rail section is a@nseries of rail nodes without a change of direction. After every curve / kink,@nthe speed for the next section of the route is newly determined,@ntaking into account the swing of the cart. This means that a cart can@nroll over short rail sections without power rails.@n@nIn order to additionally brake the cart at certain points@n(at switches or in front of a buffer), speed limit signs can be placed@non the track. With these signs the speed can be reduced to 4, 2, or 1 m / s.@nThe "No speed limit" sign can be used to remove the speed limit.@n@nThe speed limit signs must be placed next to the track so that they can@nbe read from the cart. This allows different speeds in each direction of travel.=
|
||||
Minecart Railway Buffer=
|
||||
Minecart Hopper=
|
||||
Minecart Landmark=
|
||||
Cart Pusher=
|
||||
Minecart (Sneak+Click to pick up)=
|
||||
Output cart state and position, or a list of carts, if no cart number is given.=
|
||||
List of carts=
|
||||
@ -34,8 +36,6 @@ Enter cart number=
|
||||
Save=
|
||||
[minecart] Area is protected!=
|
||||
Allow to dig/place rails in Minecart Landmark areas=
|
||||
Minecart Landmark=
|
||||
Cart Pusher=
|
||||
left=
|
||||
right=
|
||||
straight=
|
||||
@ -45,6 +45,7 @@ next junction=
|
||||
Travel time=
|
||||
[minecart] Route stored!=
|
||||
[minecart] Speed @= %u m/s, Time @= %u s, Route length @= %u m=
|
||||
[minecart] Your route is too short to record!=
|
||||
Speed "1"=
|
||||
Speed "2"=
|
||||
Speed "4"=
|
||||
|
@ -30,11 +30,16 @@ function minecart.start_nodecart(pos, node_name, puncher, punch_dir)
|
||||
local userID = M(pos):get_int("userID")
|
||||
-- check if valid cart
|
||||
if not minecart.monitoring_valid_cart(owner, userID, pos, node_name) then
|
||||
--print("invalid cart", owner, userID, P2S(pos), node_name)
|
||||
--print("Lost cart", owner, userID, P2S(pos), node_name)
|
||||
local entity_name = minecart.tNodeNames[node_name]
|
||||
if owner ~= "" and userID ~= "" and entity_name then
|
||||
minecart.monitoring_add_cart(owner, userID, pos, node_name, entity_name)
|
||||
else
|
||||
M(pos):set_string("infotext",
|
||||
minetest.get_color_escape_sequence("#FFFF00") .. owner .. ": 0")
|
||||
return
|
||||
end
|
||||
end
|
||||
-- Only the owner or a noplayer can start the cart, but owner has to be online
|
||||
if minecart.is_owner(puncher, owner) and minetest.get_player_by_name(owner) and
|
||||
userID ~= 0 then
|
||||
@ -42,14 +47,19 @@ function minecart.start_nodecart(pos, node_name, puncher, punch_dir)
|
||||
local obj = minecart.node_to_entity(pos, node_name, entity_name)
|
||||
if obj then
|
||||
local entity = obj:get_luaentity()
|
||||
local facedir
|
||||
|
||||
if puncher then
|
||||
local yaw = puncher:get_look_horizontal()
|
||||
entity.object:set_rotation({x = 0, y = yaw, z = 0})
|
||||
local dir = minetest.yaw_to_dir(yaw)
|
||||
facedir = minetest.dir_to_facedir(dir)
|
||||
elseif punch_dir then
|
||||
local yaw = minetest.dir_to_yaw(punch_dir)
|
||||
entity.object:set_rotation({x = 0, y = yaw, z = 0})
|
||||
facedir = minetest.dir_to_facedir(punch_dir)
|
||||
end
|
||||
minecart.start_entitycart(entity, pos)
|
||||
minecart.start_entitycart(entity, pos, facedir or 0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -91,6 +91,10 @@ minetest.register_node("minecart:landmark", {
|
||||
return false
|
||||
end,
|
||||
|
||||
on_punch = function(pos, node, puncher, pointed_thing)
|
||||
minecart.set_land_marker(pos, RANGE, 20)
|
||||
end,
|
||||
|
||||
paramtype2 = "facedir",
|
||||
sunlight_propagates = true,
|
||||
groups = {cracky = 3, stone = 1},
|
||||
|
@ -424,6 +424,52 @@ function minecart.delete_waypoint(pos)
|
||||
end
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- find next buffer (needed as starting position)
|
||||
-------------------------------------------------------------------------------
|
||||
local function get_next_waypoints(pos)
|
||||
local t = get_metadata(pos)
|
||||
if not t then
|
||||
t = find_all_next_waypoints(pos)
|
||||
end
|
||||
return t
|
||||
end
|
||||
|
||||
local function get_next_pos_and_facedir(waypoints, facedir)
|
||||
local cnt = 0
|
||||
local newpos, newfacedir
|
||||
facedir = (facedir + 2) % 4 -- opposite dir
|
||||
|
||||
for i = 0, 3 do
|
||||
if waypoints[i] then
|
||||
cnt = cnt + 1
|
||||
if i ~= facedir then -- not the same way back
|
||||
newpos = vector.new(waypoints[i].pos)
|
||||
newfacedir = i
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- no junction and valid facedir
|
||||
if cnt < 3 and newfacedir then
|
||||
return newpos, newfacedir
|
||||
end
|
||||
end
|
||||
|
||||
local function get_next_buffer(pos, facedir)
|
||||
facedir = (facedir + 2) % 4 -- opposite dir
|
||||
for i = 1,5 do -- limit search depth
|
||||
local waypoints = get_next_waypoints(pos) or {}
|
||||
local pos1, facedir1 = get_next_pos_and_facedir(waypoints, facedir)
|
||||
if pos1 then
|
||||
pos, facedir = pos1, facedir1
|
||||
else
|
||||
return minecart.find_node_near_lvm(pos, 1, {"minecart:buffer"})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
carts:register_rail("minecart:rail", {
|
||||
description = "Rail",
|
||||
tiles = {
|
||||
@ -536,13 +582,17 @@ function minecart.add_raillike_nodes(name)
|
||||
lRailsExt[#lRailsExt + 1] = name
|
||||
end
|
||||
|
||||
-- minecart.get_next_buffer(pos, facedir)
|
||||
minecart.get_next_buffer = get_next_buffer
|
||||
|
||||
--minetest.register_lbm({
|
||||
-- label = "Delete waypoints",
|
||||
-- name = "minecart:del_meta",
|
||||
-- nodenames = {"carts:brakerail"},
|
||||
-- nodenames = {"minecart:rail", "minecart:powerrail"},
|
||||
-- run_at_every_load = true,
|
||||
-- action = function(pos, node)
|
||||
-- del_metadata(pos)
|
||||
-- end,
|
||||
--})
|
||||
|
||||
|
||||
|
@ -124,6 +124,8 @@ function minecart.stop_recording(self, pos)
|
||||
local fmt = S("[minecart] Speed = %u m/s, Time = %u s, Route length = %u m")
|
||||
minetest.chat_send_player(self.driver, string.format(fmt, speed, self.runtime, length))
|
||||
end
|
||||
elseif #self.checkpoints <= 3 then
|
||||
minetest.chat_send_player(self.driver, S("[minecart] Your route is too short to record!"))
|
||||
end
|
||||
dashboard_destroy(self)
|
||||
end
|
||||
|
Before Width: | Height: | Size: 154 KiB After Width: | Height: | Size: 305 KiB |
@ -68,7 +68,7 @@ minetest.after(10, function()
|
||||
for owner, carts in pairs(minecart.CartsOnRail) do
|
||||
for userID, cart in pairs(carts) do
|
||||
-- Remove node carts that are not available anymore
|
||||
if cart.objID == 0 or not cart.objID then
|
||||
if cart.pos and (cart.objID == 0 or not cart.objID) then
|
||||
local node = minecart.get_node_lvm(cart.pos)
|
||||
if not minecart.tNodeNames[node.name] then
|
||||
-- Mark as "to be deleted"
|
||||
|
@ -29,6 +29,16 @@ end
|
||||
|
||||
local old_pos
|
||||
|
||||
local function test_get_buffer(pos, player)
|
||||
local yaw = player:get_look_horizontal()
|
||||
local dir = minetest.yaw_to_dir(yaw)
|
||||
local facedir = minetest.dir_to_facedir(dir)
|
||||
local pos1 = minecart.get_next_buffer(pos, facedir)
|
||||
if pos1 then
|
||||
minecart.set_marker(pos1, "buffer", 1.2, 10)
|
||||
end
|
||||
end
|
||||
|
||||
local function test_get_route(pos, node, player)
|
||||
local yaw = player:get_look_horizontal()
|
||||
local dir = minetest.yaw_to_dir(yaw)
|
||||
@ -67,9 +77,8 @@ end
|
||||
local function click_left(itemstack, placer, pointed_thing)
|
||||
if pointed_thing.type == "node" then
|
||||
local pos = pointed_thing.under
|
||||
local node = minetest.get_node(pos)
|
||||
if node.name == "carts:rail" or node.name == "carts:powerrail" then
|
||||
test_get_route(pos, node, placer)
|
||||
if minecart.is_rail(pos) then
|
||||
test_get_buffer(pos, placer)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
662
networks/LICENSE.txt
Normal file
@ -0,0 +1,662 @@
|
||||
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
Version 3, 19 November 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU Affero General Public License is a free, copyleft license for
|
||||
software and other kinds of works, specifically designed to ensure
|
||||
cooperation with the community in the case of network server software.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
our General Public Licenses are intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
Developers that use our General Public Licenses protect your rights
|
||||
with two steps: (1) assert copyright on the software, and (2) offer
|
||||
you this License which gives you legal permission to copy, distribute
|
||||
and/or modify the software.
|
||||
|
||||
A secondary benefit of defending all users' freedom is that
|
||||
improvements made in alternate versions of the program, if they
|
||||
receive widespread use, become available for other developers to
|
||||
incorporate. Many developers of free software are heartened and
|
||||
encouraged by the resulting cooperation. However, in the case of
|
||||
software used on network servers, this result may fail to come about.
|
||||
The GNU General Public License permits making a modified version and
|
||||
letting the public access it on a server without ever releasing its
|
||||
source code to the public.
|
||||
|
||||
The GNU Affero General Public License is designed specifically to
|
||||
ensure that, in such cases, the modified source code becomes available
|
||||
to the community. It requires the operator of a network server to
|
||||
provide the source code of the modified version running there to the
|
||||
users of that server. Therefore, public use of a modified version, on
|
||||
a publicly accessible server, gives the public access to the source
|
||||
code of the modified version.
|
||||
|
||||
An older license, called the Affero General Public License and
|
||||
published by Affero, was designed to accomplish similar goals. This is
|
||||
a different license, not a version of the Affero GPL, but Affero has
|
||||
released a new version of the Affero GPL which permits relicensing under
|
||||
this license.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, if you modify the
|
||||
Program, your modified version must prominently offer all users
|
||||
interacting with it remotely through a computer network (if your version
|
||||
supports such interaction) an opportunity to receive the Corresponding
|
||||
Source of your version by providing access to the Corresponding Source
|
||||
from a network server at no charge, through some standard or customary
|
||||
means of facilitating copying of software. This Corresponding Source
|
||||
shall include the Corresponding Source for any work covered by version 3
|
||||
of the GNU General Public License that is incorporated pursuant to the
|
||||
following paragraph.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the work with which it is combined will remain governed by version
|
||||
3 of the GNU General Public License.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU Affero General Public License from time to time. Such new versions
|
||||
will be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU Affero General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU Affero General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU Affero General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If your software can interact with users remotely through a computer
|
||||
network, you should also make sure that it provides a way for users to
|
||||
get its source. For example, if your program is a web application, its
|
||||
interface could display a "Source" link that leads users to an archive
|
||||
of the code. There are many ways you could offer source, and different
|
||||
solutions will be better for different programs; see section 13 for the
|
||||
specific requirements.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
124
networks/README.md
Normal file
@ -0,0 +1,124 @@
|
||||
# Networks [networks]
|
||||
|
||||
A library to build and manage networks based on tubelib2 tubes, pipes, or cables.
|
||||
|
||||
![networks](https://github.com/joe7575/networks/blob/main/screenshot.png)
|
||||
|
||||
|
||||
### Power Networks
|
||||
|
||||
Power networks consists of following node types:
|
||||
|
||||
- Generators, nodes providing power
|
||||
- Consumers, nodes consuming power
|
||||
- Storage nodes, nodes storing power
|
||||
- Cables, to build power connections
|
||||
- Junctions, to connect point to point connection to networks
|
||||
- Switches, to turn on/off network segments
|
||||
|
||||
All storage nodes in a network form a storage system. Storage systems are
|
||||
required as buffers. Generators "charge" the storage system, consumers
|
||||
"discharge" the storage system.
|
||||
|
||||
Charging the storage system follows a degressive/adaptive charging curve.
|
||||
When the storage system e.g. is 80% full, the charging load is continuously reduced.
|
||||
This ensures that all generators are loaded in a balanced manner.
|
||||
|
||||
Cables, junctions, and switches can be hidden under blocks (plastering)
|
||||
and opened again with a tool.
|
||||
This makes power installations in buildings more realistic.
|
||||
The mod uses a whitelist for filling material. The function
|
||||
`networks.register_filling_items` is used to register node names.
|
||||
|
||||
|
||||
### Liquid Networks
|
||||
|
||||
Liquid networks consists of following node types:
|
||||
|
||||
- Pumps, nodes pumping liquids from/to tanks
|
||||
- Tanks, storuing liquids
|
||||
- Junctions, to connect pipes to networks
|
||||
- Valves, to turn on/off pipe segments
|
||||
|
||||
|
||||
### Control
|
||||
|
||||
In addition to any network the 'control' API can be used to send commands
|
||||
or request data from nodes, specified via 'node_type'.
|
||||
|
||||
|
||||
### Test Nodes
|
||||
|
||||
The file `./test/test_power.lua` contains test nodes of each kind of power nodes.
|
||||
It can be used to play with the features and to study the use of `networks`.
|
||||
|
||||
- [G] a generator, which provides 20 units of power every 2 s
|
||||
- [C] a consumer, which need 5 units of power every 2 s
|
||||
- [S] a storage with 500 units capacity
|
||||
|
||||
All three nodes can be turned on/off by right-clicking.
|
||||
|
||||
- cable node for power transportation
|
||||
- junction node for power distribution
|
||||
- a power switch to turn on/off consumers
|
||||
- a tool to hide/open cables and junctions
|
||||
|
||||
The file `./test/test_liquid.lua` contains test nodes of each kind of liquid nodes.
|
||||
|
||||
- [P] a pump which pumps 2 items every 2 s
|
||||
- [T] tree types of tanks (empty, milk, water)
|
||||
- junction node
|
||||
- a value to connect/disconnect pipes
|
||||
|
||||
The file `./test/test_control.lua` contains server [S] and client [C] nodes
|
||||
to demonstrate simple on/off commands.
|
||||
|
||||
All this testing nodes can be enabled via mod settings `networks_test_enabled = true` in `minetest.conf`
|
||||
|
||||
|
||||
|
||||
|
||||
### License
|
||||
|
||||
Copyright (C) 2021 Joachim Stolberg
|
||||
Code: Licensed under the GNU AGPL version 3 or later. See LICENSE.txt
|
||||
Textures: CC BY-SA 3.0
|
||||
|
||||
|
||||
### Dependencies
|
||||
|
||||
Required: tubelib2
|
||||
|
||||
|
||||
### History
|
||||
|
||||
**2021-05-23 V0.01**
|
||||
- First shot
|
||||
|
||||
**2021-05-24 V0.02**
|
||||
- Add switch
|
||||
- Add tool and hide/open feature
|
||||
- bug fixes and improvements
|
||||
|
||||
**2021-05-25 V0.03**
|
||||
- Add function `networks.get_power_data`
|
||||
- bug fixes and improvements
|
||||
|
||||
**2021-05-29 V0.04**
|
||||
- bug fixes and improvements
|
||||
|
||||
**2021-05-30 V0.05**
|
||||
- Change power API
|
||||
|
||||
**2021-06-03 V0.06**
|
||||
- Add 'liquid'
|
||||
- bug fixes and improvements
|
||||
|
||||
**2021-06-04 V0.07**
|
||||
- Add 'control' API
|
||||
|
||||
**2021-07-06 V0.08**
|
||||
- Add 'transfer' functions to the 'power' API
|
||||
|
||||
**2021-07-23 V0.09**
|
||||
- bug fixes and improvements
|
80
networks/control.lua
Normal file
@ -0,0 +1,80 @@
|
||||
--[[
|
||||
|
||||
Networks
|
||||
========
|
||||
|
||||
Copyright (C) 2021 Joachim Stolberg
|
||||
|
||||
AGPL v3
|
||||
See LICENSE.txt for more information
|
||||
|
||||
Control API to control other network nodes which have a control interface
|
||||
|
||||
]]--
|
||||
|
||||
-- for lazy programmers
|
||||
local S2P = minetest.string_to_pos
|
||||
local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end
|
||||
local M = minetest.get_meta
|
||||
local N = tubelib2.get_node_lvm
|
||||
local CTL = function(pos) return (minetest.registered_nodes[N(pos).name] or {}).control end
|
||||
|
||||
networks.control = {}
|
||||
|
||||
-- return list of nodes {pos = ..., indir = ...} of given node_type
|
||||
local function get_network_table(pos, tlib2, outdir, node_type)
|
||||
local netw = networks.get_network_table(pos, tlib2, outdir)
|
||||
if netw then
|
||||
return netw[node_type] or {}
|
||||
end
|
||||
return {}
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- For all types of nodes
|
||||
-------------------------------------------------------------------------------
|
||||
-- names: list of node names
|
||||
-- control_callbacks = {
|
||||
-- on_receive = function(pos, tlib2, topic, payload),
|
||||
-- on_request = function(pos, tlib2, topic), -- returns: response
|
||||
-- }
|
||||
function networks.control.register_nodes(names, control_callbacks)
|
||||
assert(type(control_callbacks) == "table")
|
||||
|
||||
for _, name in ipairs(names) do
|
||||
minetest.override_item(name, {control = control_callbacks})
|
||||
end
|
||||
end
|
||||
|
||||
-- Send a message with 'topic' string and any 'payload 'to all 'tlib2' network
|
||||
-- nodes of type 'node_type'.
|
||||
-- Function returns the number of nodes the message was sent to.
|
||||
function networks.control.send(pos, tlib2, outdir, node_type, topic, payload)
|
||||
assert(outdir and node_type and topic)
|
||||
assert(type(topic) == "string")
|
||||
local cnt = 0
|
||||
for _,item in ipairs(get_network_table(pos, tlib2, outdir, node_type)) do
|
||||
local ctl = CTL(item.pos)
|
||||
if ctl and ctl.on_receive then
|
||||
ctl.on_receive(item.pos, tlib2, topic, payload)
|
||||
cnt = cnt + 1
|
||||
end
|
||||
end
|
||||
return cnt
|
||||
end
|
||||
|
||||
-- Send a request with 'topic' string to all 'tlib2' network
|
||||
-- nodes of type 'node_type'.
|
||||
-- Function returns a list with all responses.
|
||||
function networks.control.request(pos, tlib2, outdir, node_type, topic)
|
||||
assert(outdir and node_type and topic)
|
||||
assert(type(topic) == "string")
|
||||
local t = {}
|
||||
for _,item in ipairs(get_network_table(pos, tlib2, outdir, node_type)) do
|
||||
local ctl = CTL(item.pos)
|
||||
if ctl and ctl.on_request then
|
||||
t[#t + 1] = ctl.on_request(item.pos, tlib2, topic)
|
||||
end
|
||||
end
|
||||
return t
|
||||
end
|
166
networks/hidden.lua
Normal file
@ -0,0 +1,166 @@
|
||||
--[[
|
||||
|
||||
Networks
|
||||
========
|
||||
|
||||
Copyright (C) 2021 Joachim Stolberg
|
||||
|
||||
AGPL v3
|
||||
See LICENSE.txt for more information
|
||||
|
||||
]]--
|
||||
|
||||
-- for lazy programmers
|
||||
local S2P = minetest.string_to_pos
|
||||
local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end
|
||||
local M = minetest.get_meta
|
||||
local N = tubelib2.get_node_lvm
|
||||
|
||||
local hidden_message = ""
|
||||
local tFillingMaterial = {}
|
||||
|
||||
-- handle old techage names
|
||||
local function legacy_names(meta)
|
||||
if meta:contains("techage_hidden_nodename") then
|
||||
meta:set_string("netw_name", meta:get_string("techage_hidden_nodename"))
|
||||
meta:set_string("techage_hidden_nodename", "")
|
||||
end
|
||||
if meta:contains("tl2_param2") then
|
||||
meta:set_int("netw_param2", meta:get_int("tl2_param2"))
|
||||
meta:set_string("tl2_param2", "")
|
||||
end
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- API
|
||||
-------------------------------------------------------------------------------
|
||||
function networks.hidden_name(pos)
|
||||
local meta = M(pos)
|
||||
legacy_names(meta)
|
||||
if meta:contains("netw_name") then
|
||||
return meta:get_string("netw_name")
|
||||
end
|
||||
end
|
||||
|
||||
function networks.get_nodename(pos)
|
||||
local meta = M(pos)
|
||||
legacy_names(meta)
|
||||
if meta:contains("netw_name") then
|
||||
return meta:get_string("netw_name")
|
||||
end
|
||||
return tubelib2.get_node_lvm(pos).name
|
||||
end
|
||||
|
||||
function networks.get_node(pos)
|
||||
local meta = M(pos)
|
||||
legacy_names(meta)
|
||||
if meta:contains("netw_name") then
|
||||
return {name = meta:get_string("netw_name"), param2 = meta:get_int("netw_param2")}
|
||||
end
|
||||
return tubelib2.get_node_lvm(pos)
|
||||
end
|
||||
|
||||
local get_node = networks.get_node
|
||||
local get_nodename = networks.get_nodename
|
||||
|
||||
-- Override methods of tubelib2 to store tube/cable info as metadata,
|
||||
-- used for hidden cables/tubes/junctions/switches.
|
||||
function networks.use_metadata(tlib2)
|
||||
tlib2.get_primary_node_param2 = function(self, pos, dir)
|
||||
local npos = vector.add(pos, tubelib2.Dir6dToVector[dir or 0])
|
||||
if self.primary_node_names[get_nodename(npos)] then
|
||||
local meta = M(npos)
|
||||
return meta:get_int("netw_param2"), npos
|
||||
end
|
||||
end
|
||||
tlib2.is_primary_node = function(self, pos, dir)
|
||||
local npos = vector.add(pos, tubelib2.Dir6dToVector[dir or 0])
|
||||
return self.primary_node_names[get_nodename(npos)] ~= nil
|
||||
end
|
||||
tlib2.get_secondary_node = function(self, pos, dir)
|
||||
local npos = vector.add(pos, tubelib2.Dir6dToVector[dir or 0])
|
||||
local node = get_node(npos)
|
||||
if self.secondary_node_names[node.name] then
|
||||
return node, npos, true
|
||||
end
|
||||
end
|
||||
tlib2.is_secondary_node = function(self, pos, dir)
|
||||
local npos = vector.add(pos, tubelib2.Dir6dToVector[dir or 0])
|
||||
local name = get_nodename(npos)
|
||||
return self.secondary_node_names[name] ~= nil
|
||||
end
|
||||
end
|
||||
|
||||
function networks.hide_node(pos, node, placer)
|
||||
local inv = placer:get_inventory()
|
||||
local stack = inv:get_stack("main", 1)
|
||||
local taken = stack:take_item(1)
|
||||
|
||||
if taken:get_count() == 1 and tFillingMaterial[taken:get_name()] then
|
||||
local meta = M(pos)
|
||||
meta:set_string("netw_name", node.name)
|
||||
local param2 = 0
|
||||
local ndef = minetest.registered_nodes[taken:get_name()]
|
||||
if ndef.paramtype2 and ndef.paramtype2 == "facedir" then
|
||||
param2 = minetest.dir_to_facedir(placer:get_look_dir(), true)
|
||||
end
|
||||
minetest.swap_node(pos, {name = taken:get_name(), param2 = param2})
|
||||
inv:set_stack("main", 1, stack)
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
function networks.open_node(pos, node, placer)
|
||||
local name = networks.hidden_name(pos)
|
||||
local param2
|
||||
if M(pos):get_int("netw_param2") ~= 0 then
|
||||
param2 = M(pos):get_int("netw_param2")
|
||||
else
|
||||
param2 = M(pos):get_int("netw_param2_copy")
|
||||
end
|
||||
minetest.swap_node(pos, {name = name, param2 = param2 % 32})
|
||||
local meta = M(pos)
|
||||
meta:set_string("netw_name", "")
|
||||
local inv = placer:get_inventory()
|
||||
inv:add_item("main", ItemStack(node.name))
|
||||
return true
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Patch registered nodes
|
||||
-------------------------------------------------------------------------------
|
||||
function networks.register_hidden_message(msg)
|
||||
hidden_message = msg
|
||||
end
|
||||
|
||||
local function get_new_can_dig(old_can_dig)
|
||||
return function(pos, player, ...)
|
||||
if networks.hidden_name(pos) then
|
||||
if player and player.get_player_name then
|
||||
minetest.chat_send_player(player:get_player_name(), hidden_message)
|
||||
end
|
||||
return false
|
||||
end
|
||||
if old_can_dig then
|
||||
return old_can_dig(pos, player, ...)
|
||||
else
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Register item names to be used as filling material to hide tubes/cables
|
||||
function networks.register_filling_items(names)
|
||||
for _, name in ipairs(names) do
|
||||
tFillingMaterial[name] = true
|
||||
-- Change can_dig for registered filling materials.
|
||||
local ndef = minetest.registered_nodes[name]
|
||||
if ndef then
|
||||
local old_can_dig = ndef.can_dig
|
||||
minetest.override_item(ndef.name, {
|
||||
can_dig = get_new_can_dig(old_can_dig)
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
40
networks/init.lua
Normal file
@ -0,0 +1,40 @@
|
||||
--[[
|
||||
|
||||
Networks
|
||||
========
|
||||
|
||||
Copyright (C) 2021 Joachim Stolberg
|
||||
|
||||
AGPL v3
|
||||
See LICENSE.txt for more information
|
||||
|
||||
]]--
|
||||
|
||||
networks = {}
|
||||
|
||||
-- Version for compatibility checks, see readme.md/history
|
||||
networks.version = 0.09
|
||||
|
||||
if not minetest.global_exists("tubelib2") or tubelib2.version < 2.1 then
|
||||
minetest.log("error", "[networks] Networks requires tubelib2 version 2.1 or newer!")
|
||||
return
|
||||
end
|
||||
|
||||
local MP = minetest.get_modpath("networks")
|
||||
|
||||
dofile(MP .. "/hidden.lua")
|
||||
dofile(MP .. "/networks.lua")
|
||||
dofile(MP .. "/junction.lua")
|
||||
dofile(MP .. "/observer.lua")
|
||||
dofile(MP .. "/power.lua")
|
||||
dofile(MP .. "/liquid.lua")
|
||||
dofile(MP .. "/control.lua")
|
||||
|
||||
print("networks_test_enabled", minetest.settings:get_bool("networks_test_enabled"))
|
||||
if minetest.settings:get_bool("networks_test_enabled") == true then
|
||||
-- Only for testing/demo purposes
|
||||
dofile(MP .. "/test/test_liquid.lua")
|
||||
local Cable = dofile(MP .. "/test/test_power.lua")
|
||||
assert(loadfile(MP .. "/test/test_control.lua"))(Cable)
|
||||
dofile(MP .. "/test/test_tool.lua")
|
||||
end
|
@ -1,23 +1,15 @@
|
||||
--[[
|
||||
|
||||
TechAge
|
||||
=======
|
||||
Networks
|
||||
========
|
||||
|
||||
Copyright (C) 2019-2020 Joachim Stolberg
|
||||
Copyright (C) 2021 Joachim Stolberg
|
||||
|
||||
AGPL v3
|
||||
See LICENSE.txt for more information
|
||||
|
||||
Junction for power distribution
|
||||
|
||||
]]--
|
||||
|
||||
-- for lazy programmers
|
||||
local S = function(pos) if pos then return minetest.pos_to_string(pos) end end
|
||||
local P = minetest.string_to_pos
|
||||
local M = minetest.get_meta
|
||||
|
||||
|
||||
local function bit(p)
|
||||
return 2 ^ (p - 1) -- 1-based indexing
|
||||
end
|
||||
@ -51,7 +43,7 @@ end
|
||||
-- 'tlib2' is the tubelib2 instance
|
||||
-- 'node' is the node definition with tiles, callback functions, and so on
|
||||
-- 'index' number for the inventory node (default 0)
|
||||
function techage.register_junction(name, size, boxes, tlib2, node, index)
|
||||
function networks.register_junction(name, size, boxes, tlib2, node, index)
|
||||
local names = {}
|
||||
for idx = 0,63 do
|
||||
local ndef = table.copy(node)
|
||||
@ -60,20 +52,14 @@ function techage.register_junction(name, size, boxes, tlib2, node, index)
|
||||
else
|
||||
ndef.groups.not_in_creative_inventory = 1
|
||||
end
|
||||
ndef.groups.techage_trowel = 1
|
||||
ndef.drawtype = "nodebox"
|
||||
ndef.paramtype = "light"
|
||||
ndef.sunlight_propagates = true
|
||||
ndef.node_box = get_node_box(idx, size, boxes)
|
||||
ndef.paramtype2 = "facedir"
|
||||
ndef.on_rotate = screwdriver.disallow
|
||||
ndef.paramtype = "light"
|
||||
ndef.use_texture_alpha = techage.CLIP
|
||||
ndef.sunlight_propagates = true
|
||||
ndef.is_ground_content = false
|
||||
ndef.drop = name..(index or "0")
|
||||
minetest.register_node(name..idx, ndef)
|
||||
tlib2:add_secondary_node_names({name..idx})
|
||||
-- for the case that 'tlib2.force_to_use_tubes' is set
|
||||
tlib2:add_special_node_names({name..idx})
|
||||
names[#names + 1] = name..idx
|
||||
end
|
||||
return names
|
||||
@ -93,7 +79,18 @@ local function dir_to_dir2(dir, param2)
|
||||
return dir
|
||||
end
|
||||
|
||||
function techage.junction_type(pos, network, default_side, param2)
|
||||
function networks.junction_type(pos, network, default_side, param2)
|
||||
local connected = function(self, pos, dir)
|
||||
if network:is_primary_node(pos, dir) then
|
||||
local param2, npos = self:get_primary_node_param2(pos, dir)
|
||||
if param2 then
|
||||
local d1, d2, _ = self:decode_param2(npos, param2)
|
||||
dir = networks.Flip[dir]
|
||||
return d1 == dir or dir == d2
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local val = 0
|
||||
if default_side then
|
||||
val = setbit(val, bit(SideToDir[default_side]))
|
||||
@ -101,13 +98,15 @@ function techage.junction_type(pos, network, default_side, param2)
|
||||
for dir = 1,6 do
|
||||
local dir2 = dir_to_dir2(dir, param2)
|
||||
if network.force_to_use_tubes then
|
||||
if network:friendly_primary_node(pos, dir) then
|
||||
if connected(network, pos, dir) then
|
||||
val = setbit(val, bit(dir2))
|
||||
elseif network:is_special_node(pos, dir) then
|
||||
val = setbit(val, bit(dir2))
|
||||
end
|
||||
else
|
||||
if network:connected(pos, dir) then
|
||||
if connected(network, pos, dir) then
|
||||
val = setbit(val, bit(dir2))
|
||||
elseif network:is_secondary_node(pos, dir) then
|
||||
val = setbit(val, bit(dir2))
|
||||
end
|
||||
end
|
268
networks/liquid.lua
Normal file
@ -0,0 +1,268 @@
|
||||
--[[
|
||||
|
||||
Networks
|
||||
========
|
||||
|
||||
Copyright (C) 2021 Joachim Stolberg
|
||||
|
||||
AGPL v3
|
||||
See LICENSE.txt for more information
|
||||
|
||||
Liquid API for liquid pumping and storing nodes
|
||||
|
||||
]]--
|
||||
|
||||
-- for lazy programmers
|
||||
local S2P = minetest.string_to_pos
|
||||
local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end
|
||||
local M = minetest.get_meta
|
||||
local N = tubelib2.get_node_lvm
|
||||
local LQD = function(pos) return (minetest.registered_nodes[N(pos).name] or {}).liquid end
|
||||
|
||||
networks.liquid = {}
|
||||
networks.registered_networks.liquid = {}
|
||||
|
||||
-- return list of nodes {pos = ..., indir = ...} of given node_type
|
||||
local function get_network_table(pos, tlib2, outdir, node_type)
|
||||
local netw = networks.get_network_table(pos, tlib2, outdir)
|
||||
if netw then
|
||||
return netw[node_type] or {}
|
||||
end
|
||||
return {}
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- For all types of nodes
|
||||
-------------------------------------------------------------------------------
|
||||
-- names: list of node names
|
||||
-- tlib2: tubelib2 instance
|
||||
-- node_type: one of "pump", "tank", "junc"
|
||||
-- valid_sides: something like {"L", "R"} or nil
|
||||
-- liquid_callbacks = {
|
||||
-- capa = CAPACITY,
|
||||
-- peek = function(pos, indir), -- returns: liquid name
|
||||
-- put = function(pos, indir, name, amount), -- returns: liquid leftover or 0
|
||||
-- take = function(pos, indir, name, amount), -- returns: taken, name
|
||||
-- untake = function(pos, indir, name, amount), -- returns: leftover
|
||||
-- }
|
||||
function networks.liquid.register_nodes(names, tlib2, node_type, valid_sides, liquid_callbacks)
|
||||
if node_type == "pump" then
|
||||
assert(not valid_sides or type(valid_sides) == "table")
|
||||
valid_sides = valid_sides or {"B", "R", "F", "L", "D", "U"}
|
||||
elseif node_type == "tank" or node_type == "junc" then
|
||||
assert(not valid_sides or type(valid_sides) == "table")
|
||||
valid_sides = valid_sides or {"B", "R", "F", "L", "D", "U"}
|
||||
elseif node_type and type(node_type) == "string" then
|
||||
valid_sides = valid_sides or {"B", "R", "F", "L", "D", "U"}
|
||||
else
|
||||
error("parameter error")
|
||||
end
|
||||
|
||||
if node_type == "tank" then
|
||||
assert(type(liquid_callbacks) == "table")
|
||||
end
|
||||
|
||||
tlib2:add_secondary_node_names(names)
|
||||
networks.registered_networks.liquid[tlib2.tube_type] = tlib2
|
||||
|
||||
for _, name in ipairs(names) do
|
||||
local ndef = minetest.registered_nodes[name]
|
||||
local tbl = ndef.networks or {}
|
||||
tbl[tlib2.tube_type] = {ntype = node_type}
|
||||
minetest.override_item(name, {networks = tbl})
|
||||
minetest.override_item(name, {liquid = liquid_callbacks})
|
||||
tlib2:set_valid_sides(name, valid_sides)
|
||||
end
|
||||
end
|
||||
|
||||
-- To be called for each liquid network change via
|
||||
-- tubelib2_on_update2 or register_on_tube_update2
|
||||
function networks.liquid.update_network(pos, outdir, tlib2, node)
|
||||
local ndef = networks.net_def(pos, tlib2.tube_type)
|
||||
if ndef.ntype == "junc" then
|
||||
outdir = 0
|
||||
end
|
||||
networks.update_network(pos, outdir, tlib2, node)
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Client/pump functions
|
||||
-------------------------------------------------------------------------------
|
||||
-- Determine and return liquid 'name' from the
|
||||
-- remote inventory.
|
||||
function networks.liquid.peek(pos, tlib2, outdir)
|
||||
assert(outdir)
|
||||
for _,item in ipairs(get_network_table(pos, tlib2, outdir, "tank")) do
|
||||
local liq = LQD(item.pos)
|
||||
if liq and liq.peek then
|
||||
return liq.peek(item.pos, item.indir)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Add given amount of liquid to the remote inventory.
|
||||
-- return leftover amount
|
||||
function networks.liquid.put(pos, tlib2, outdir, name, amount, show_debug_cube)
|
||||
assert(outdir)
|
||||
assert(name)
|
||||
assert(amount and amount > 0)
|
||||
for _,item in ipairs(get_network_table(pos, tlib2, outdir, "tank")) do
|
||||
local liq = LQD(item.pos)
|
||||
if liq and liq.put and liq.peek then
|
||||
-- wrong items?
|
||||
local peek = liq.peek(item.pos, item.indir)
|
||||
if peek and peek ~= name then return amount or 0 end
|
||||
if show_debug_cube then
|
||||
networks.set_marker(item.pos, "put", 1.1, 1)
|
||||
end
|
||||
amount = liq.put(item.pos, item.indir, name, amount)
|
||||
if not amount or amount == 0 then break end
|
||||
end
|
||||
end
|
||||
return amount or 0
|
||||
end
|
||||
|
||||
-- Take given amount of liquid from the remote inventory.
|
||||
-- return taken amount and item name
|
||||
function networks.liquid.take(pos, tlib2, outdir, name, amount, show_debug_cube)
|
||||
assert(outdir)
|
||||
assert(amount and amount > 0)
|
||||
local taken = 0
|
||||
for _,item in ipairs(get_network_table(pos, tlib2, outdir, "tank")) do
|
||||
local liq = LQD(item.pos)
|
||||
if liq and liq.take then
|
||||
if show_debug_cube then
|
||||
networks.set_marker(item.pos, "take", 1.1, 1)
|
||||
end
|
||||
taken, name = liq.take(item.pos, item.indir, name, amount)
|
||||
if taken and name and taken > 0 then
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
return taken, name
|
||||
end
|
||||
|
||||
function networks.liquid.untake(pos, tlib2, outdir, name, amount)
|
||||
assert(outdir)
|
||||
assert(name)
|
||||
assert(amount)
|
||||
for _,item in ipairs(get_network_table(pos, tlib2, outdir, "tank")) do
|
||||
local liq = LQD(item.pos)
|
||||
if liq and liq.untake then
|
||||
amount = liq.untake(item.pos, item.indir, name, amount)
|
||||
if not amount or amount == 0 then break end
|
||||
end
|
||||
end
|
||||
return amount or 0
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Server/tank local functions
|
||||
-------------------------------------------------------------------------------
|
||||
function networks.liquid.is_empty(nvm)
|
||||
return not nvm.liquid or (nvm.liquid.amount or 0) <= 0
|
||||
end
|
||||
|
||||
function networks.liquid.get_amount(nvm)
|
||||
if nvm.liquid and nvm.liquid.amount then
|
||||
return nvm.liquid.amount
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
function networks.liquid.get_item(nvm)
|
||||
local itemname = "<empty>"
|
||||
if nvm.liquid and nvm.liquid.amount and nvm.liquid.amount > 0 and nvm.liquid.name then
|
||||
itemname = nvm.liquid.name.." "..nvm.liquid.amount
|
||||
end
|
||||
return itemname
|
||||
end
|
||||
|
||||
function networks.liquid.srv_peek(nvm)
|
||||
nvm.liquid = nvm.liquid or {}
|
||||
return nvm.liquid.name
|
||||
end
|
||||
|
||||
function networks.liquid.srv_put(nvm, name, amount, capa)
|
||||
assert(name)
|
||||
assert(amount and amount >= 0)
|
||||
assert(capa and capa > 0)
|
||||
|
||||
nvm.liquid = nvm.liquid or {}
|
||||
amount = amount or 0
|
||||
if not nvm.liquid.name then
|
||||
nvm.liquid.name = name
|
||||
nvm.liquid.amount = amount
|
||||
return 0
|
||||
elseif nvm.liquid.name == name then
|
||||
nvm.liquid.amount = nvm.liquid.amount or 0
|
||||
if nvm.liquid.amount + amount <= capa then
|
||||
nvm.liquid.amount = nvm.liquid.amount + amount
|
||||
return 0
|
||||
else
|
||||
local rest = nvm.liquid.amount + amount - capa
|
||||
nvm.liquid.amount = capa
|
||||
return rest
|
||||
end
|
||||
end
|
||||
return amount
|
||||
end
|
||||
|
||||
function networks.liquid.srv_take(nvm, name, amount)
|
||||
assert(amount and amount >= 0)
|
||||
|
||||
nvm.liquid = nvm.liquid or {}
|
||||
amount = amount or 0
|
||||
if not name or nvm.liquid.name == name then
|
||||
name = nvm.liquid.name
|
||||
nvm.liquid.amount = nvm.liquid.amount or 0
|
||||
if nvm.liquid.amount > amount then
|
||||
nvm.liquid.amount = nvm.liquid.amount - amount
|
||||
return amount, name
|
||||
else
|
||||
local rest = nvm.liquid.amount
|
||||
local name = nvm.liquid.name
|
||||
nvm.liquid.amount = 0
|
||||
nvm.liquid.name = nil
|
||||
return rest, name
|
||||
end
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Valve
|
||||
-------------------------------------------------------------------------------
|
||||
function networks.liquid.turn_valve_on(pos, tlib2, name_off, name_on)
|
||||
local node = N(pos)
|
||||
local meta = M(pos)
|
||||
if node.name == name_off then
|
||||
node.name = name_on
|
||||
minetest.swap_node(pos, node)
|
||||
tlib2:after_place_tube(pos)
|
||||
meta:set_int("networks_param2", node.param2)
|
||||
return true
|
||||
elseif meta:contains("networks_param2_copy") then
|
||||
meta:set_int("networks_param2", meta:get_int("networks_param2_copy"))
|
||||
tlib2:after_place_tube(pos)
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
function networks.liquid.turn_valve_off(pos, tlib2, name_off, name_on)
|
||||
local node = N(pos)
|
||||
local meta = M(pos)
|
||||
if node.name == name_on then
|
||||
node.name = name_off
|
||||
minetest.swap_node(pos, node)
|
||||
meta:set_int("networks_param2", 0)
|
||||
tlib2:after_dig_tube(pos, node)
|
||||
return true
|
||||
elseif meta:contains("networks_param2") then
|
||||
meta:set_int("networks_param2_copy", meta:get_int("networks_param2"))
|
||||
meta:set_int("networks_param2", 0)
|
||||
tlib2:after_dig_tube(pos, node)
|
||||
return true
|
||||
end
|
||||
end
|
4
networks/mod.conf
Normal file
@ -0,0 +1,4 @@
|
||||
name = networks
|
||||
depends = screwdriver,tubelib2
|
||||
description = Build and manage networks based on tubelib2 tubes/pipes/cables
|
||||
|
497
networks/networks.lua
Normal file
@ -0,0 +1,497 @@
|
||||
--[[
|
||||
|
||||
Networks
|
||||
========
|
||||
|
||||
Copyright (C) 2021 Joachim Stolberg
|
||||
|
||||
AGPL v3
|
||||
See LICENSE.txt for more information
|
||||
|
||||
]]--
|
||||
|
||||
-- for lazy programmers
|
||||
local S2P = minetest.string_to_pos
|
||||
local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end
|
||||
local M = minetest.get_meta
|
||||
local N = tubelib2.get_node_lvm
|
||||
|
||||
local Networks = {} -- cache for networks: {netw_type = {netID = <network>, ...}, ...}
|
||||
local NetIDs = {} -- cache for netw IDs: {pos_hash = {outdir = netID, ...}, ...}
|
||||
|
||||
local MAX_NUM_NODES = 1000 -- per network including junctions
|
||||
local TTL = 5 * 60 -- 5 minutes
|
||||
local Route = {} -- Used to determine the already passed nodes while walking
|
||||
local NumNodes = 0 -- Used to determine the number of network nodes
|
||||
|
||||
local Flip = tubelib2.Turn180Deg
|
||||
local get_nodename = networks.get_nodename
|
||||
local get_node = networks.get_node
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Debugging
|
||||
-------------------------------------------------------------------------------
|
||||
-- Table for all registered tubelib2 instances
|
||||
networks.registered_networks = {} -- {api_type = {instance,...}}
|
||||
|
||||
-- Maintain simple numbers for the bulky netID hashes
|
||||
local DbgNetIDs = {}
|
||||
local DbgCounter = 1
|
||||
|
||||
local function netw_num(netID)
|
||||
if not netID or netID < 1 then
|
||||
return netID or 0
|
||||
end
|
||||
if not DbgNetIDs[netID] then
|
||||
DbgNetIDs[netID] = DbgCounter
|
||||
DbgCounter = DbgCounter + 1
|
||||
end
|
||||
return DbgNetIDs[netID]
|
||||
end
|
||||
|
||||
local function network_nodes(netID, network)
|
||||
local tbl = {}
|
||||
for node_type,table in pairs(network or {}) do
|
||||
if type(table) == "table" then
|
||||
tbl[#tbl+1] = "#" .. node_type .. " = " .. #table
|
||||
end
|
||||
end
|
||||
tbl[#tbl+1] = "num_nodes = " .. (network.num_nodes or 0)
|
||||
return "Network " .. netw_num(netID) .. ": " .. table.concat(tbl, ", ")
|
||||
end
|
||||
|
||||
-- Marker entities for debugging purposes
|
||||
function networks.set_marker(pos, text, size, ttl)
|
||||
local marker = minetest.add_entity(pos, "networks:marker_cube")
|
||||
if marker ~= nil then
|
||||
marker:set_nametag_attributes({color = "#FFFFFF", text = text})
|
||||
size = size or 1
|
||||
marker:set_properties({visual_size = {x = size, y = size}})
|
||||
if ttl then
|
||||
minetest.after(ttl, marker.remove, marker)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_entity("networks:marker_cube", {
|
||||
initial_properties = {
|
||||
visual = "cube",
|
||||
textures = {
|
||||
"networks_marker.png",
|
||||
"networks_marker.png",
|
||||
"networks_marker.png",
|
||||
"networks_marker.png",
|
||||
"networks_marker.png",
|
||||
"networks_marker.png",
|
||||
},
|
||||
physical = false,
|
||||
visual_size = {x = 1.1, y = 1.1},
|
||||
collisionbox = {-0.55,-0.55,-0.55, 0.55,0.55,0.55},
|
||||
glow = 8,
|
||||
static_save = false,
|
||||
},
|
||||
on_punch = function(self)
|
||||
self.object:remove()
|
||||
end,
|
||||
})
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Helper
|
||||
-------------------------------------------------------------------------------
|
||||
-- return the networks table from the node definition
|
||||
local function net_def(pos, netw_type)
|
||||
local ndef = minetest.registered_nodes[get_nodename(pos)]
|
||||
if ndef and ndef.networks then
|
||||
return ndef.networks[netw_type]
|
||||
end
|
||||
error("Node " .. get_nodename(pos) .. " at ".. P2S(pos) .. " has no 'ndef.networks'")
|
||||
end
|
||||
|
||||
local function net_def2(pos, node_name, netw_type)
|
||||
local ndef = minetest.registered_nodes[node_name]
|
||||
if ndef and ndef.networks then
|
||||
return ndef.networks[netw_type]
|
||||
end
|
||||
return net_def(pos, netw_type)
|
||||
end
|
||||
|
||||
-- Don't allow direct connections between to nodes of the same type
|
||||
local function valid_secondary_node_connection(tlib2, pos, dir)
|
||||
local node1 = tlib2:get_secondary_node(pos, dir)
|
||||
if node1 then
|
||||
local node2 = N(pos)
|
||||
local ndef1 = minetest.registered_nodes[node1.name]
|
||||
local ndef2 = minetest.registered_nodes[node2.name]
|
||||
local ntype1 = ((ndef1.networks or {})[tlib2.tube_type] or {}).ntype
|
||||
local ntype2 = ((ndef2.networks or {})[tlib2.tube_type] or {}).ntype
|
||||
return ntype1 == "junc" or ntype1 ~= ntype2
|
||||
end
|
||||
end
|
||||
|
||||
-- Returns true if node is connected with another network node
|
||||
local function connected(tlib2, pos, dir)
|
||||
local param2, npos = tlib2:get_primary_node_param2(pos, dir)
|
||||
if param2 then
|
||||
local d1, d2, num = tlib2:decode_param2(npos, param2)
|
||||
if not num then return end
|
||||
return Flip[dir] == d1 or Flip[dir] == d2
|
||||
end
|
||||
-- secondary nodes allowed?
|
||||
if tlib2.force_to_use_tubes then
|
||||
return tlib2:is_special_node(pos, dir)
|
||||
else
|
||||
return valid_secondary_node_connection(tlib2, pos, dir)
|
||||
end
|
||||
end
|
||||
|
||||
local function side_to_outdir(pos, side)
|
||||
return tubelib2.side_to_dir(side, N(pos).param2)
|
||||
end
|
||||
|
||||
-- determine outdir based on node type
|
||||
local function get_outdir(node_type, indir)
|
||||
if node_type == "junc" then
|
||||
return 0 -- same network on all sides
|
||||
else
|
||||
return Flip[indir]
|
||||
end
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Node Connections
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
-- Get tlib2 connection dirs as table
|
||||
-- used e.g. for the connection walk
|
||||
local function get_node_connection_dirs(pos, netw_type)
|
||||
local val = M(pos):get_int(netw_type.."_conn")
|
||||
local tbl = {}
|
||||
if val % 0x40 >= 0x20 then tbl[#tbl+1] = 1 end
|
||||
if val % 0x20 >= 0x10 then tbl[#tbl+1] = 2 end
|
||||
if val % 0x10 >= 0x08 then tbl[#tbl+1] = 3 end
|
||||
if val % 0x08 >= 0x04 then tbl[#tbl+1] = 4 end
|
||||
if val % 0x04 >= 0x02 then tbl[#tbl+1] = 5 end
|
||||
if val % 0x02 >= 0x01 then tbl[#tbl+1] = 6 end
|
||||
return tbl
|
||||
end
|
||||
|
||||
local function get_node_connection_dirs_table(pos, netw_type)
|
||||
local val = M(pos):get_int(netw_type.."_conn")
|
||||
local tbl = {}
|
||||
if val % 0x40 >= 0x20 then tbl[1] = true end
|
||||
if val % 0x20 >= 0x10 then tbl[2] = true end
|
||||
if val % 0x10 >= 0x08 then tbl[3] = true end
|
||||
if val % 0x08 >= 0x04 then tbl[4] = true end
|
||||
if val % 0x04 >= 0x02 then tbl[5] = true end
|
||||
if val % 0x02 >= 0x01 then tbl[6] = true end
|
||||
return tbl
|
||||
end
|
||||
|
||||
-- store all node sides with tube connections as nodemeta
|
||||
local function store_node_connection_sides(pos, tlib2)
|
||||
local node = get_node(pos)
|
||||
local val = 0
|
||||
for dir = 1,6 do
|
||||
val = val * 2
|
||||
if tlib2:is_valid_dir(node, dir) and connected(tlib2, pos, dir) then
|
||||
val = val + 1
|
||||
end
|
||||
end
|
||||
M(pos):set_int(tlib2.tube_type.."_conn", val)
|
||||
end
|
||||
|
||||
-- If outdir is given, return outdir, otherwise return all valid node dirs with tube connections
|
||||
local function get_outdirs(pos, tlib2, outdir)
|
||||
if outdir then
|
||||
return {outdir}
|
||||
end
|
||||
return get_node_connection_dirs(pos, tlib2.tube_type)
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Connection Walk
|
||||
-------------------------------------------------------------------------------
|
||||
local function pos_already_reached(pos)
|
||||
local key = minetest.hash_node_position(pos)
|
||||
if not Route[key] and NumNodes < MAX_NUM_NODES then
|
||||
Route[key] = true
|
||||
NumNodes = NumNodes + 1
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
-- check if the given tube dir into the node is valid
|
||||
local function valid_indir(pos, indir, node, tlib2)
|
||||
local outdir = Flip[indir]
|
||||
return tlib2:is_valid_dir(node, outdir)
|
||||
end
|
||||
|
||||
local function is_junction(pos, name, tlib2)
|
||||
local ndef = net_def2(pos, name, tlib2.tube_type)
|
||||
if ndef then
|
||||
return ndef.ntype == "junc"
|
||||
end
|
||||
end
|
||||
|
||||
-- Do the walk through the tubelib2 network.
|
||||
-- `indir` is the direction which should not be covered by the walk
|
||||
-- (coming from there).
|
||||
-- if outdir is given, only this dir is used
|
||||
local function connection_walk(pos, outdir, indir, node, tlib2, clbk)
|
||||
if clbk then clbk(pos, indir, node) end
|
||||
if outdir or is_junction(pos, node.name, tlib2) then
|
||||
for _,outdir in ipairs(get_outdirs(pos, tlib2, outdir)) do
|
||||
local pos2, indir2 = tlib2:get_connected_node_pos(pos, outdir)
|
||||
local node = get_node(pos2)
|
||||
if valid_indir(pos2, indir2, node, tlib2) and not pos_already_reached(pos2) then
|
||||
connection_walk(pos2, nil, indir2, node, tlib2, clbk)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function collect_network_nodes(pos, tlib2, outdir)
|
||||
local t = minetest.get_us_time()
|
||||
Route = {}
|
||||
NumNodes = 0
|
||||
pos_already_reached(pos)
|
||||
local netw = {}
|
||||
local node = N(pos)
|
||||
local netw_type = tlib2.tube_type
|
||||
local tbl = get_node_connection_dirs_table(pos, netw_type)
|
||||
if tbl[outdir] then -- valid conncetion
|
||||
-- outdir corresponds to the indir coming from
|
||||
connection_walk(pos, outdir, Flip[outdir], node, tlib2, function(pos, indir, node)
|
||||
local ndef = net_def2(pos, node.name, netw_type)
|
||||
if ndef then
|
||||
local ntype = ndef.ntype
|
||||
if not netw[ntype] then netw[ntype] = {} end
|
||||
netw[ntype][#netw[ntype] + 1] = {pos = pos, indir = indir}
|
||||
end
|
||||
end)
|
||||
end
|
||||
netw.ttl = minetest.get_gametime() + TTL
|
||||
netw.num_nodes = NumNodes
|
||||
t = minetest.get_us_time() - t
|
||||
--print("collect_network_nodes in " .. t .. " us", NumNodes, P2S(pos), N(pos).name)
|
||||
return netw
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Maintain Network
|
||||
-------------------------------------------------------------------------------
|
||||
local function set_network(netw_type, netID, network)
|
||||
assert(netID)
|
||||
if netID > 0 then
|
||||
Networks[netw_type] = Networks[netw_type] or {}
|
||||
Networks[netw_type][netID] = network
|
||||
Networks[netw_type][netID].ttl = minetest.get_gametime() + TTL
|
||||
end
|
||||
end
|
||||
|
||||
-- Return network if available, or dummy network.
|
||||
-- The function updates the network TTL, thus keeping the network alive.
|
||||
local function get_network(netw_type, netID)
|
||||
assert(netID)
|
||||
if netID > 0 then
|
||||
local netw = Networks[netw_type] and Networks[netw_type][netID]
|
||||
if netw then
|
||||
netw.ttl = minetest.get_gametime() + TTL
|
||||
return netw
|
||||
end
|
||||
end
|
||||
return {num_nodes = 0}
|
||||
end
|
||||
|
||||
local function delete_network(netw_type, netID)
|
||||
assert(netID)
|
||||
if netID > 0 then
|
||||
if Networks[netw_type] and Networks[netw_type][netID] then
|
||||
Networks[netw_type][netID] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Keep data in memory small
|
||||
local function remove_outdated_networks()
|
||||
local to_be_deleted = {}
|
||||
local t = minetest.get_gametime()
|
||||
for net_name,tbl in pairs(Networks) do
|
||||
for netID,network in pairs(tbl) do
|
||||
local valid = (network.ttl or 0) - t
|
||||
if valid < 0 then
|
||||
to_be_deleted[#to_be_deleted+1] = {net_name, netID}
|
||||
end
|
||||
end
|
||||
end
|
||||
for _,item in ipairs(to_be_deleted) do
|
||||
local net_name, netID = unpack(item)
|
||||
Networks[net_name][netID] = nil
|
||||
print("Network " .. netw_num(netID) .. " timed out")
|
||||
end
|
||||
minetest.after(60, remove_outdated_networks)
|
||||
end
|
||||
minetest.after(60, remove_outdated_networks)
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Maintain netID
|
||||
-------------------------------------------------------------------------------
|
||||
local function set_netID(pos, outdir, netID)
|
||||
local hash = minetest.hash_node_position(pos)
|
||||
NetIDs[hash] = NetIDs[hash] or {}
|
||||
NetIDs[hash][outdir] = netID
|
||||
end
|
||||
|
||||
local function get_netID(pos, outdir)
|
||||
local hash = minetest.hash_node_position(pos)
|
||||
NetIDs[hash] = NetIDs[hash] or {}
|
||||
return NetIDs[hash][outdir]
|
||||
end
|
||||
|
||||
-- determine network ID (largest hash number of all nodes with given type)
|
||||
local function determine_netID(netw)
|
||||
local netID = 0
|
||||
for node_type, table in pairs(netw) do
|
||||
if type(table) == "table" then
|
||||
for _, item in ipairs(netw[node_type] or {}) do
|
||||
local outdir = Flip[item.indir]
|
||||
local new = minetest.hash_node_position(item.pos) * 8 + outdir
|
||||
if netID <= new then
|
||||
netID = new
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return netID
|
||||
end
|
||||
|
||||
-- store network ID for each network node
|
||||
local function store_netID(tlib2, netw, netID)
|
||||
for node_type, table in pairs(netw) do
|
||||
if type(table) == "table" then
|
||||
for _, item in ipairs(table) do
|
||||
local outdir = get_outdir(node_type, item.indir)
|
||||
set_netID(item.pos, outdir, netID)
|
||||
end
|
||||
end
|
||||
end
|
||||
set_network(tlib2.tube_type, netID, netw)
|
||||
end
|
||||
|
||||
-- delete network and netID for all nodes in the network
|
||||
-- `outdir` shall be 0 for junctions
|
||||
local function delete_netID(pos, tlib2, outdir)
|
||||
local netID = get_netID(pos, outdir)
|
||||
if netID then
|
||||
local netw = get_network(tlib2.tube_type, netID)
|
||||
for node_type, table in pairs(netw) do
|
||||
if type(table) == "table" then
|
||||
for _, item in ipairs(table) do
|
||||
local outdir = get_outdir(node_type, item.indir)
|
||||
set_netID(item.pos, outdir, nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
set_netID(pos, outdir, nil)
|
||||
delete_network(tlib2.tube_type, netID)
|
||||
end
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- API Functions
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
networks.MAX_NUM_NODES = MAX_NUM_NODES
|
||||
|
||||
-- Table for a 180 degree turn: indir => outdir and vice versa
|
||||
networks.Flip = tubelib2.Turn180Deg
|
||||
|
||||
-- networks.net_def(pos, netw_type)
|
||||
networks.net_def = net_def
|
||||
|
||||
-- sides: outdir:
|
||||
-- U
|
||||
-- | B
|
||||
-- | / 6 (N)
|
||||
-- +--|-----+ | 1
|
||||
-- / o /| | /
|
||||
-- +--------+ | |/
|
||||
-- L <----| |o----> R (W) 4 <-------+-------> 2 (O)
|
||||
-- | o | | /|
|
||||
-- | / | + / |
|
||||
-- | / |/ 3 |
|
||||
-- +-/------+ (S) 5
|
||||
-- / |
|
||||
-- F |
|
||||
-- D
|
||||
--
|
||||
-- networks.side_to_outdir(pos, side)
|
||||
networks.side_to_outdir = side_to_outdir
|
||||
|
||||
-- networks.is_junction(pos, name, tlib2)
|
||||
networks.is_junction = is_junction
|
||||
|
||||
-- Return a simple number instead of the netID
|
||||
-- Useful for debuging purposes
|
||||
-- networks.netw_num(netID)
|
||||
networks.netw_num = netw_num
|
||||
|
||||
-- For debugging purposes
|
||||
-- networks.network_nodes(netID, network)
|
||||
networks.network_nodes = network_nodes
|
||||
|
||||
-- networks.get_network(netw_type, netID)
|
||||
networks.get_network = get_network
|
||||
|
||||
-- return the networks table from the node definition
|
||||
-- networks.net_def(pos, netw_type)
|
||||
networks.net_def = net_def
|
||||
|
||||
-- Function returns {outdir} or all node dirs with connections
|
||||
-- networks.get_outdirs(pos, tlib2, outdir)
|
||||
networks.get_outdirs = get_outdirs
|
||||
|
||||
-- Provide own netID
|
||||
-- networks.get_netID(pos, outdir)
|
||||
networks.get_netID = get_netID
|
||||
|
||||
-- networks.get_node_connection_dirs(pos, netw_type)
|
||||
networks.get_node_connection_dirs = get_node_connection_dirs
|
||||
|
||||
-- To be called from each node via 'tubelib2_on_update2'
|
||||
-- 'output' is optional and only needed for nodes with dedicated
|
||||
-- pipe sides. Junctions have to provide 0 (= same network on all sides).
|
||||
function networks.update_network(pos, outdir, tlib2, node)
|
||||
store_node_connection_sides(pos, tlib2) -- update node internal data
|
||||
delete_netID(pos, tlib2, outdir) -- delete node netIDs and network
|
||||
end
|
||||
|
||||
-- Provide or determine netID
|
||||
function networks.determine_netID(pos, tlib2, outdir)
|
||||
assert(outdir)
|
||||
local netID = get_netID(pos, outdir)
|
||||
if netID and Networks[tlib2.tube_type] and Networks[tlib2.tube_type][netID] then
|
||||
return netID
|
||||
elseif netID == 0 then
|
||||
return -- no network available
|
||||
end
|
||||
|
||||
local netw = collect_network_nodes(pos, tlib2, outdir)
|
||||
if netw.num_nodes > 1 then
|
||||
netID = determine_netID(netw)
|
||||
store_netID(tlib2, netw, netID)
|
||||
return netID
|
||||
end
|
||||
-- mark as "no network"
|
||||
set_netID(pos, outdir, 0)
|
||||
end
|
||||
|
||||
-- Provide network with all node tables
|
||||
function networks.get_network_table(pos, tlib2, outdir)
|
||||
assert(outdir)
|
||||
local netID = networks.determine_netID(pos, tlib2, outdir)
|
||||
if netID and netID > 0 then
|
||||
return get_network(tlib2.tube_type, netID)
|
||||
end
|
||||
end
|
32
networks/observer.lua
Normal file
@ -0,0 +1,32 @@
|
||||
--[[
|
||||
|
||||
Networks
|
||||
========
|
||||
|
||||
Copyright (C) 2021 Joachim Stolberg
|
||||
|
||||
AGPL v3
|
||||
See LICENSE.txt for more information
|
||||
|
||||
Node observer for debugging/testing purposes
|
||||
|
||||
]]--
|
||||
|
||||
-- for lazy programmers
|
||||
local S2P = minetest.string_to_pos
|
||||
local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end
|
||||
local M = minetest.get_meta
|
||||
local N = tubelib2.get_node_lvm
|
||||
|
||||
local ObservePos = nil
|
||||
|
||||
function networks.register_observe_pos(pos)
|
||||
ObservePos = pos
|
||||
end
|
||||
|
||||
function networks.node_observer(tag, pos, tbl1, tbl2)
|
||||
if ObservePos and pos and vector.equals(pos, ObservePos) then
|
||||
print("##### Node_observer (" .. (minetest.get_gametime() % 100) .. "): '" .. N(pos).name .. "' - " .. tag)
|
||||
print("tbl1", dump(tbl1), "\ntbl2", dump(tbl2))
|
||||
end
|
||||
end
|
441
networks/power.lua
Normal file
@ -0,0 +1,441 @@
|
||||
--[[
|
||||
|
||||
Networks
|
||||
========
|
||||
|
||||
Copyright (C) 2021 Joachim Stolberg
|
||||
|
||||
AGPL v3
|
||||
See LICENSE.txt for more information
|
||||
|
||||
Power API for power consuming and generating nodes
|
||||
|
||||
]]--
|
||||
|
||||
-- for lazy programmers
|
||||
local S2P = minetest.string_to_pos
|
||||
local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end
|
||||
local M = minetest.get_meta
|
||||
local N = tubelib2.get_node_lvm
|
||||
local OBS = networks.node_observer
|
||||
local Flip = tubelib2.Turn180Deg
|
||||
|
||||
networks.power = {}
|
||||
networks.registered_networks.power = {}
|
||||
|
||||
local DEFAULT_DATA = {
|
||||
curr_load = 0, -- network storage value
|
||||
max_capa = 0, -- network storage capacity
|
||||
consumed = 0, -- consumed power by consumers
|
||||
provided = 0, -- provided power by generators
|
||||
available = 0, -- max. available generator power
|
||||
netw_num = 0, -- network number
|
||||
}
|
||||
|
||||
-- Storage parameters:
|
||||
-- capa = maximum value in power units
|
||||
-- load = current value in power units
|
||||
-- level = ratio value (load/capa) (0..1)
|
||||
|
||||
local Power = {} -- {netID = {curr_load, max_capa, consumed, provided, available}}
|
||||
|
||||
|
||||
|
||||
-- Determine load, capa and other power network data
|
||||
local function get_power_data(pos, tlib2, outdir, netID)
|
||||
assert(outdir)
|
||||
local netw = networks.get_network_table(pos, tlib2, outdir) or {}
|
||||
local max_capa = 1 -- to prevent nan
|
||||
local max_perf = 0
|
||||
local curr_load = 0
|
||||
-- Generators
|
||||
for _,item in ipairs(netw.gen or {}) do
|
||||
local ndef = minetest.registered_nodes[N(item.pos).name]
|
||||
local data = ndef.get_generator_data and ndef.get_generator_data(item.pos, Flip[item.indir], tlib2)
|
||||
if data then
|
||||
OBS("get_power_data", item.pos, data)
|
||||
max_capa = max_capa + (data.capa or 0)
|
||||
max_perf = max_perf + (data.perf or 0)
|
||||
curr_load = curr_load + ((data.level or 0) * (data.capa or 0))
|
||||
end
|
||||
end
|
||||
-- Storage systems
|
||||
for _,item in ipairs(netw.sto or {}) do
|
||||
local ndef = minetest.registered_nodes[N(item.pos).name]
|
||||
local data = ndef.get_storage_data and ndef.get_storage_data(item.pos, Flip[item.indir], tlib2)
|
||||
if data then
|
||||
OBS("get_power_data", item.pos, data)
|
||||
max_capa = max_capa + (data.capa or 0)
|
||||
curr_load = curr_load + ((data.level or 0) * (data.capa or 0))
|
||||
end
|
||||
end
|
||||
Power[netID] = {
|
||||
curr_load = curr_load, -- network storage value
|
||||
max_capa = max_capa, -- network storage capacity
|
||||
max_perf = max_perf, -- max. available power
|
||||
consumed = 0, -- consumed power
|
||||
provided = 0, -- provided power
|
||||
available = 0, -- available power
|
||||
num_nodes = netw.num_nodes,
|
||||
}
|
||||
return Power[netID]
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- For all types of nodes
|
||||
-------------------------------------------------------------------------------
|
||||
-- names: list of node names
|
||||
-- tlib2: tubelib2 instance
|
||||
-- node_type: one of "gen", "con", "sto", "junc"
|
||||
-- valid_sides: something like {"L", "R"} or nil
|
||||
function networks.power.register_nodes(names, tlib2, node_type, valid_sides)
|
||||
if node_type == "gen" then
|
||||
assert(#valid_sides <= 2)
|
||||
elseif node_type == "sto" then
|
||||
assert(#valid_sides == 1)
|
||||
elseif node_type == "con" or node_type == "junc" then
|
||||
assert(not valid_sides or type(valid_sides) == "table")
|
||||
valid_sides = valid_sides or {"B", "R", "F", "L", "D", "U"}
|
||||
elseif node_type and type(node_type) == "string" then
|
||||
valid_sides = valid_sides or {"B", "R", "F", "L", "D", "U"}
|
||||
else
|
||||
error("parameter error")
|
||||
end
|
||||
|
||||
tlib2:add_secondary_node_names(names)
|
||||
networks.registered_networks.power[tlib2.tube_type] = tlib2
|
||||
|
||||
for _, name in ipairs(names) do
|
||||
local ndef = minetest.registered_nodes[name]
|
||||
local tbl = ndef.networks or {}
|
||||
assert(tbl[tlib2.tube_type] == nil, "more than one call of 'networks.power.register_nodes' for " .. names[1])
|
||||
tbl[tlib2.tube_type] = {ntype = node_type}
|
||||
minetest.override_item(name, {networks = tbl})
|
||||
tlib2:set_valid_sides(name, valid_sides)
|
||||
end
|
||||
end
|
||||
|
||||
-- To be called for each power network change via
|
||||
-- tubelib2_on_update2 or register_on_tube_update2
|
||||
function networks.power.update_network(pos, outdir, tlib2, node)
|
||||
local ndef = networks.net_def(pos, tlib2.tube_type)
|
||||
assert(ndef, "node " .. N(pos).name .. " has no 'networks." .. tlib2.tube_type .. "' table")
|
||||
if ndef.ntype == "junc" then
|
||||
outdir = 0
|
||||
end
|
||||
local netID = networks.get_netID(pos, outdir)
|
||||
if netID then
|
||||
Power[netID] = nil
|
||||
end
|
||||
networks.update_network(pos, outdir, tlib2, node)
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Consumer
|
||||
-------------------------------------------------------------------------------
|
||||
-- Function checks for a power grid, not for enough power
|
||||
-- Param outdir is optional
|
||||
function networks.power.power_available(pos, tlib2, outdir)
|
||||
for _,outdir in ipairs(networks.get_outdirs(pos, tlib2, outdir)) do
|
||||
local netID = networks.determine_netID(pos, tlib2, outdir)
|
||||
if netID then
|
||||
local pwr = Power[netID] or get_power_data(pos, tlib2, outdir, netID)
|
||||
OBS("power_available", pos, pwr)
|
||||
return pwr.curr_load > 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Param outdir is optional
|
||||
function networks.power.consume_power(pos, tlib2, outdir, amount)
|
||||
assert(amount)
|
||||
for _,outdir in ipairs(networks.get_outdirs(pos, tlib2, outdir)) do
|
||||
local netID = networks.determine_netID(pos, tlib2, outdir)
|
||||
if netID then
|
||||
local pwr = Power[netID] or get_power_data(pos, tlib2, outdir, netID)
|
||||
OBS("consume_power", pos, {outdir = outdir, amount = amount}, pwr)
|
||||
if pwr.curr_load >= amount then
|
||||
pwr.curr_load = pwr.curr_load - amount
|
||||
pwr.consumed = pwr.consumed + amount
|
||||
return amount
|
||||
else
|
||||
local consumed = pwr.curr_load
|
||||
pwr.curr_load = 0
|
||||
pwr.consumed = pwr.consumed + consumed
|
||||
return consumed
|
||||
end
|
||||
end
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Generator
|
||||
-------------------------------------------------------------------------------
|
||||
-- amount is the maximum power, the generator can provide.
|
||||
-- cp1 and cp2 are control points for the charge regulator.
|
||||
-- From cp1 the charging power is reduced more and more and reaches zero at cp2.
|
||||
--
|
||||
-- A
|
||||
-- |
|
||||
-- 100 % |-------------------__
|
||||
-- | --__
|
||||
-- | --__
|
||||
-- | --__
|
||||
-- --+------------------+---------------+---->
|
||||
-- | cp1 cp2
|
||||
--
|
||||
function networks.power.provide_power(pos, tlib2, outdir, amount, cp1, cp2)
|
||||
assert(outdir)
|
||||
assert(amount and amount > 0)
|
||||
local netID = networks.determine_netID(pos, tlib2, outdir)
|
||||
if netID then
|
||||
local pwr = Power[netID] or get_power_data(pos, tlib2, outdir, netID)
|
||||
local x = pwr.curr_load / pwr.max_capa
|
||||
OBS("provide_power", pos, {outdir = outdir, amount = amount}, pwr)
|
||||
|
||||
pwr.available = pwr.available + amount
|
||||
amount = math.min(amount, pwr.max_capa - pwr.curr_load)
|
||||
cp1 = cp1 or 0.8
|
||||
cp2 = cp2 or 1.0
|
||||
|
||||
if x < cp1 then -- charge with full power
|
||||
pwr.curr_load = pwr.curr_load + amount
|
||||
pwr.provided = pwr.provided + amount
|
||||
return amount
|
||||
elseif x < cp2 then -- charge with reduced power
|
||||
local factor = 1 - ((x - cp1) / (cp2 - cp1))
|
||||
local provided = amount * factor
|
||||
pwr.curr_load = pwr.curr_load + provided
|
||||
pwr.provided = pwr.provided + provided
|
||||
return provided
|
||||
else -- turn off
|
||||
return 0
|
||||
end
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
-- Function for generators with storage capacity
|
||||
function networks.power.get_storage_load(pos, tlib2, outdir, amount)
|
||||
local netID = networks.determine_netID(pos, tlib2, outdir)
|
||||
if netID then
|
||||
local pwr = Power[netID] or get_power_data(pos, tlib2, outdir, netID)
|
||||
OBS("get_storage_load", pos, pwr)
|
||||
if pwr.max_capa and pwr.max_capa > 0 then
|
||||
return pwr.curr_load / pwr.max_capa * amount
|
||||
else
|
||||
error("invalid pwr.max_capa", pwr.max_capa)
|
||||
end
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Storage
|
||||
-------------------------------------------------------------------------------
|
||||
-- Function returns a table with storage level as ratio (0..1) and the
|
||||
-- charging state (1 = charging, -1 = uncharging, or 0)
|
||||
-- Function provides nil if no network is available
|
||||
function networks.power.get_storage_data(pos, tlib2, outdir)
|
||||
assert(outdir)
|
||||
local netID = networks.determine_netID(pos, tlib2, outdir)
|
||||
if netID then
|
||||
local pwr = Power[netID] or get_power_data(pos, tlib2, outdir, netID)
|
||||
OBS("get_storage_data", pos, pwr)
|
||||
local charging = (pwr.provided > pwr.consumed and 1) or (pwr.provided < pwr.consumed and -1) or 0
|
||||
return {level = pwr.curr_load / pwr.max_capa, charging = charging}
|
||||
end
|
||||
end
|
||||
|
||||
-- To be called for each network storage change (turn on/off of storage/generator nodes)
|
||||
function networks.power.start_storage_calc(pos, tlib2, outdir)
|
||||
assert(outdir)
|
||||
local netID = networks.determine_netID(pos, tlib2, outdir)
|
||||
OBS("start_storage_calc", pos)
|
||||
if netID then
|
||||
Power[netID] = nil
|
||||
end
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Transformer
|
||||
-------------------------------------------------------------------------------
|
||||
-- Charge transfer in both directions between network 1 and network 2
|
||||
-- 'netw1' and 'netw2' are tubelib2 network instances.
|
||||
-- Function returns a table with result values for:
|
||||
-- {curr_load1, curr_load2, max_capa1, max_capa2, moved}
|
||||
function networks.power.transfer_duplex(pos, netw1, outdir1, netw2, outdir2, amount)
|
||||
local netID1 = networks.determine_netID(pos, netw1, outdir1)
|
||||
local netID2 = networks.determine_netID(pos, netw2, outdir2)
|
||||
if netID1 and netID2 then
|
||||
local pwr1 = Power[netID1] or get_power_data(pos, netw1, outdir1, netID1)
|
||||
local pwr2 = Power[netID2] or get_power_data(pos, netw2, outdir2, netID2)
|
||||
local lvl = pwr1.curr_load / pwr1.max_capa - pwr2.curr_load / pwr2.max_capa
|
||||
local moved
|
||||
|
||||
pwr2.available = pwr2.available + amount
|
||||
pwr1.available = pwr1.available + amount
|
||||
if lvl > 0 then
|
||||
-- transfer from netw1 to netw2
|
||||
moved = math.min(amount, lvl * math.min(pwr1.max_capa, pwr2.max_capa))
|
||||
moved = math.max(moved, 0)
|
||||
pwr1.curr_load = pwr1.curr_load - moved
|
||||
pwr2.curr_load = pwr2.curr_load + moved
|
||||
pwr1.consumed = (pwr1.consumed or 0) + moved
|
||||
pwr2.provided = (pwr2.provided or 0) + moved
|
||||
elseif lvl < 0 then
|
||||
-- transfer from netw2 to netw1
|
||||
moved = math.min(amount, lvl * math.min(pwr1.max_capa, pwr2.max_capa))
|
||||
moved = math.max(moved, 0)
|
||||
pwr2.curr_load = pwr2.curr_load - moved
|
||||
pwr1.curr_load = pwr1.curr_load + moved
|
||||
pwr2.consumed = (pwr2.consumed or 0) + moved
|
||||
pwr1.provided = (pwr1.provided or 0) + moved
|
||||
else
|
||||
moved = 0
|
||||
end
|
||||
OBS("transfer_duplex", pos, pwr1, pwr2)
|
||||
return {
|
||||
curr_load1 = pwr1.curr_load,
|
||||
curr_load2 = pwr2.curr_load,
|
||||
max_capa1 = pwr1.max_capa,
|
||||
max_capa2 = pwr2.max_capa,
|
||||
moved = moved}
|
||||
end
|
||||
end
|
||||
|
||||
-- Charge transfer in one direction from network 1 to network 2
|
||||
-- 'netw1' and 'netw2' are tubelib2 network instances.
|
||||
-- Function returns a table with result values for:
|
||||
-- {curr_load1, curr_load2, max_capa1, max_capa2, moved}
|
||||
function networks.power.transfer_simplex(pos, netw1, outdir1, netw2, outdir2, amount)
|
||||
local netID1 = networks.determine_netID(pos, netw1, outdir1)
|
||||
local netID2 = networks.determine_netID(pos, netw2, outdir2)
|
||||
if netID1 and netID2 then
|
||||
local pwr1 = Power[netID1] or get_power_data(pos, netw1, outdir1, netID1)
|
||||
local pwr2 = Power[netID2] or get_power_data(pos, netw2, outdir2, netID2)
|
||||
local lvl = pwr1.curr_load / pwr1.max_capa - pwr2.curr_load / pwr2.max_capa
|
||||
local moved
|
||||
|
||||
pwr2.available = pwr2.available + amount
|
||||
if lvl > 0 then
|
||||
-- transfer from netw1 to netw2
|
||||
moved = math.min(amount, lvl * math.min(pwr1.max_capa, pwr2.max_capa))
|
||||
moved = math.max(moved, 0)
|
||||
pwr1.curr_load = pwr1.curr_load - moved
|
||||
pwr2.curr_load = pwr2.curr_load + moved
|
||||
pwr1.consumed = (pwr1.consumed or 0) + moved
|
||||
pwr2.provided = (pwr2.provided or 0) + moved
|
||||
else
|
||||
moved = 0
|
||||
end
|
||||
OBS("transfer_simplex", pos, pwr1, pwr2)
|
||||
return {
|
||||
curr_load1 = pwr1.curr_load,
|
||||
curr_load2 = pwr2.curr_load,
|
||||
max_capa1 = pwr1.max_capa,
|
||||
max_capa2 = pwr2.max_capa,
|
||||
moved = moved}
|
||||
end
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Switch
|
||||
-------------------------------------------------------------------------------
|
||||
function networks.power.turn_switch_on(pos, tlib2, name_off, name_on)
|
||||
local node = N(pos)
|
||||
local meta = M(pos)
|
||||
local changed = false
|
||||
|
||||
if node.name == name_off then
|
||||
node.name = name_on
|
||||
changed = true
|
||||
elseif meta:get_string("netw_name") == name_off then
|
||||
meta:set_string("netw_name", name_on)
|
||||
else
|
||||
return false
|
||||
end
|
||||
|
||||
if meta:contains("netw_param2") then
|
||||
meta:set_int("netw_param2", meta:get_int("netw_param2_copy"))
|
||||
else
|
||||
node.param2 = meta:get_int("netw_param2_copy")
|
||||
end
|
||||
meta:set_int("netw_param2_copy", 0)
|
||||
|
||||
if changed then
|
||||
minetest.swap_node(pos, node)
|
||||
end
|
||||
|
||||
tlib2:after_place_tube(pos)
|
||||
return true
|
||||
end
|
||||
|
||||
function networks.power.turn_switch_off(pos, tlib2, name_off, name_on)
|
||||
local node = N(pos)
|
||||
local meta = M(pos)
|
||||
local changed = false
|
||||
|
||||
if node.name == name_on then
|
||||
node.name = name_off
|
||||
changed = true
|
||||
elseif meta:get_string("netw_name") == name_on then
|
||||
meta:set_string("netw_name", name_off)
|
||||
else
|
||||
return false
|
||||
end
|
||||
|
||||
if meta:contains("netw_param2") then
|
||||
meta:set_int("netw_param2_copy", meta:get_int("netw_param2"))
|
||||
--meta:set_int("netw_param2", 0)
|
||||
else
|
||||
meta:set_int("netw_param2_copy", node.param2)
|
||||
end
|
||||
|
||||
if changed then
|
||||
minetest.swap_node(pos, node)
|
||||
end
|
||||
|
||||
if meta:contains("netw_param2") then
|
||||
node.param2 = meta:get_int("netw_param2")
|
||||
end
|
||||
tlib2:after_dig_tube(pos, node)
|
||||
return true
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Statistics
|
||||
-------------------------------------------------------------------------------
|
||||
function networks.power.get_network_data(pos, tlib2, outdir)
|
||||
for _,outdir in ipairs(networks.get_outdirs(pos, tlib2, outdir)) do
|
||||
local netID = networks.determine_netID(pos, tlib2, outdir)
|
||||
if netID then
|
||||
local pwr = Power[netID] or get_power_data(pos, tlib2, outdir, netID)
|
||||
local consumed, provided, available
|
||||
if pwr.available > 0 and pwr.max_perf > 0 then
|
||||
local fac = pwr.max_perf / pwr.available
|
||||
available = pwr.max_perf
|
||||
provided = pwr.provided * fac
|
||||
consumed = pwr.consumed * fac
|
||||
else
|
||||
available = pwr.max_perf
|
||||
provided = 0
|
||||
consumed = pwr.consumed
|
||||
end
|
||||
local res = {
|
||||
curr_load = pwr.curr_load, -- network storage value
|
||||
max_capa = pwr.max_capa, -- network storage capacity
|
||||
consumed = consumed, -- consumed power by consumers
|
||||
provided = provided, -- provided power by generators
|
||||
available = available, -- max. available generator power
|
||||
netw_num = networks.netw_num(netID), -- network number
|
||||
}
|
||||
pwr.consumed = 0
|
||||
pwr.provided = 0
|
||||
pwr.available = 0
|
||||
return res
|
||||
end
|
||||
end
|
||||
return DEFAULT_DATA
|
||||
end
|
BIN
networks/screenshot.png
Normal file
After Width: | Height: | Size: 103 KiB |
2
networks/settingtypes.txt
Normal file
@ -0,0 +1,2 @@
|
||||
# Enable some nodes for testing/demo purposes
|
||||
networks_test_enabled (test nodes enabled) bool false
|
139
networks/test/test_control.lua
Normal file
@ -0,0 +1,139 @@
|
||||
--[[
|
||||
|
||||
Networks
|
||||
========
|
||||
|
||||
Copyright (C) 2021 Joachim Stolberg
|
||||
|
||||
AGPL v3
|
||||
See LICENSE.txt for more information
|
||||
|
||||
]]--
|
||||
|
||||
-- for lazy programmers
|
||||
local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end
|
||||
local S2P = minetest.string_to_pos
|
||||
local M = minetest.get_meta
|
||||
|
||||
local Cable = ...
|
||||
local power = networks.power
|
||||
local control = networks.control
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Client (sender)
|
||||
-------------------------------------------------------------------------------
|
||||
minetest.register_node("networks:client", {
|
||||
description = "Client",
|
||||
tiles = {
|
||||
-- up, down, right, left, back, front
|
||||
'networks_con.png^[colorize:#F05100:60',
|
||||
'networks_con.png^[colorize:#F05100:60',
|
||||
'networks_con.png^[colorize:#F05100:60',
|
||||
'networks_con.png^[colorize:#F05100:60',
|
||||
'networks_con.png^[colorize:#F05100:60',
|
||||
'networks_conn.png^[colorize:#F05100:60',
|
||||
},
|
||||
after_place_node = function(pos)
|
||||
local outdir = networks.side_to_outdir(pos, "F")
|
||||
M(pos):set_int("outdir", outdir)
|
||||
M(pos):set_string("infotext", "off")
|
||||
Cable:after_place_node(pos, {outdir})
|
||||
tubelib2.init_mem(pos)
|
||||
end,
|
||||
after_dig_node = function(pos, oldnode, oldmetadata)
|
||||
local outdir = tonumber(oldmetadata.fields.outdir or 0)
|
||||
Cable:after_dig_node(pos, {outdir})
|
||||
tubelib2.del_mem(pos)
|
||||
end,
|
||||
on_rightclick = function(pos, node, clicker)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
local cnt
|
||||
if mem.on then
|
||||
cnt = control.send(pos, Cable, outdir, "server", "off")
|
||||
M(pos):set_string("infotext", "off")
|
||||
mem.on = false
|
||||
else
|
||||
cnt = control.send(pos, Cable, outdir, "server", "on")
|
||||
M(pos):set_string("infotext", "on")
|
||||
mem.on = true
|
||||
end
|
||||
print("Command sent to " .. cnt .. " nodes.")
|
||||
end,
|
||||
paramtype2 = "facedir",
|
||||
on_rotate = screwdriver.disallow,
|
||||
is_ground_content = false,
|
||||
groups = {crumbly = 2, cracky = 2, snappy = 2},
|
||||
sounds = default.node_sound_defaults(),
|
||||
})
|
||||
|
||||
power.register_nodes({"networks:client"}, Cable, "client")
|
||||
control.register_nodes({"networks:client"}, {}) -- no callbacks
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Server (receiver)
|
||||
-------------------------------------------------------------------------------
|
||||
local function swap_node(pos, name)
|
||||
local node = tubelib2.get_node_lvm(pos)
|
||||
if node.name == name then
|
||||
return
|
||||
end
|
||||
node.name = name
|
||||
minetest.swap_node(pos, node)
|
||||
end
|
||||
|
||||
minetest.register_node("networks:server_off", {
|
||||
description = "Server",
|
||||
tiles = {
|
||||
-- up, down, right, left, back, front
|
||||
"networks_sto.png^[colorize:#F05100:60",
|
||||
},
|
||||
after_place_node = function(pos)
|
||||
Cable:after_place_node(pos)
|
||||
end,
|
||||
after_dig_node = function(pos)
|
||||
Cable:after_dig_node(pos)
|
||||
end,
|
||||
paramtype2 = "facedir",
|
||||
on_rotate = screwdriver.disallow,
|
||||
is_ground_content = false,
|
||||
groups = {crumbly = 2, cracky = 2, snappy = 2},
|
||||
sounds = default.node_sound_defaults(),
|
||||
})
|
||||
|
||||
minetest.register_node("networks:server_on", {
|
||||
description = "Server",
|
||||
tiles = {
|
||||
-- up, down, right, left, back, front
|
||||
"networks_sto.png^[colorize:#F05100:60",
|
||||
},
|
||||
after_place_node = function(pos)
|
||||
Cable:after_place_node(pos)
|
||||
end,
|
||||
after_dig_node = function(pos)
|
||||
Cable:after_dig_node(pos)
|
||||
end,
|
||||
paramtype = "light",
|
||||
light_source = 8,
|
||||
paramtype2 = "facedir",
|
||||
drop = "networks:server_off",
|
||||
groups = {crumbly = 2, cracky = 2, snappy = 2, not_in_creative_inventory = 1},
|
||||
is_ground_content = false,
|
||||
sounds = default.node_sound_defaults(),
|
||||
})
|
||||
|
||||
power.register_nodes({"networks:server_off", "networks:server_on"}, Cable, "server")
|
||||
control.register_nodes({"networks:server_off", "networks:server_on"}, {
|
||||
on_receive = function(pos, tlib2, topic, payload)
|
||||
if topic == "on" then
|
||||
swap_node(pos, "networks:server_on")
|
||||
elseif topic == "off" then
|
||||
swap_node(pos, "networks:server_off")
|
||||
end
|
||||
end,
|
||||
on_request = function(pos, tlib2, topic)
|
||||
return false
|
||||
end,
|
||||
}
|
||||
)
|
||||
|
430
networks/test/test_liquid.lua
Normal file
@ -0,0 +1,430 @@
|
||||
--[[
|
||||
|
||||
Networks
|
||||
========
|
||||
|
||||
Copyright (C) 2021 Joachim Stolberg
|
||||
|
||||
AGPL v3
|
||||
See LICENSE.txt for more information
|
||||
|
||||
]]--
|
||||
|
||||
-- for lazy programmers
|
||||
local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end
|
||||
local S2P = minetest.string_to_pos
|
||||
local M = minetest.get_meta
|
||||
|
||||
local CYCLE_TIME = 2
|
||||
local STORAGE_CAPA = 500
|
||||
local AMOUNT = 2
|
||||
|
||||
local liquid = networks.liquid
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Pipe
|
||||
-------------------------------------------------------------------------------
|
||||
local Pipe = tubelib2.Tube:new({
|
||||
dirs_to_check = {1,2,3,4,5,6},
|
||||
max_tube_length = 100,
|
||||
tube_type = "liq",
|
||||
primary_node_names = {"networks:pipeS", "networks:pipeA", "networks:valve_on"},
|
||||
secondary_node_names = {}, -- Names will be added via 'liquids.register_nodes'
|
||||
after_place_tube = function(pos, param2, tube_type, num_tubes, tbl)
|
||||
local name = minetest.get_node(pos).name
|
||||
if name == "networks:valve_on" then
|
||||
minetest.swap_node(pos, {name = "networks:valve_on", param2 = param2})
|
||||
elseif name == "networks:valve_off" then
|
||||
minetest.swap_node(pos, {name = "networks:valve_off", param2 = param2})
|
||||
else
|
||||
minetest.swap_node(pos, {name = "networks:pipe"..tube_type, param2 = param2})
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
-- Use global callback instead of node related functions
|
||||
Pipe:register_on_tube_update2(function(pos, outdir, tlib2, node)
|
||||
liquid.update_network(pos, outdir, tlib2, node)
|
||||
end)
|
||||
|
||||
minetest.register_node("networks:pipeS", {
|
||||
description = "Pipe",
|
||||
tiles = { -- Top, base, right, left, front, back
|
||||
"networks_cable.png^[colorize:#007577:60",
|
||||
"networks_cable.png^[colorize:#007577:60",
|
||||
"networks_cable.png^[colorize:#007577:60",
|
||||
"networks_cable.png^[colorize:#007577:60",
|
||||
"networks_hole.png",
|
||||
"networks_hole.png",
|
||||
},
|
||||
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
||||
if not Pipe:after_place_tube(pos, placer, pointed_thing) then
|
||||
minetest.remove_node(pos)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end,
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
Pipe:after_dig_tube(pos, oldnode, oldmetadata)
|
||||
end,
|
||||
paramtype2 = "facedir",
|
||||
drawtype = "nodebox",
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{-3/16, -3/16, -4/8, 3/16, 3/16, 4/8},
|
||||
},
|
||||
},
|
||||
on_rotate = screwdriver.disallow,
|
||||
paramtype = "light",
|
||||
use_texture_alpha = "clip",
|
||||
sunlight_propagates = true,
|
||||
is_ground_content = false,
|
||||
groups = {crumbly = 2, cracky = 2, snappy = 2},
|
||||
sounds = default.node_sound_defaults(),
|
||||
})
|
||||
|
||||
minetest.register_node("networks:pipeA", {
|
||||
description = "Pipe",
|
||||
tiles = { -- Top, base, right, left, front, back
|
||||
"networks_cable.png^[colorize:#007577:60",
|
||||
"networks_hole.png^[colorize:#007577:60",
|
||||
"networks_cable.png^[colorize:#007577:60",
|
||||
"networks_cable.png^[colorize:#007577:60",
|
||||
"networks_cable.png^[colorize:#007577:60",
|
||||
"networks_hole.png^[colorize:#007577:60",
|
||||
},
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
Pipe:after_dig_tube(pos, oldnode, oldmetadata)
|
||||
end,
|
||||
paramtype2 = "facedir",
|
||||
drawtype = "nodebox",
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{-3/16, -4/8, -3/16, 3/16, 3/16, 3/16},
|
||||
{-3/16, -3/16, -4/8, 3/16, 3/16, -3/16},
|
||||
},
|
||||
},
|
||||
on_rotate = screwdriver.disallow,
|
||||
paramtype = "light",
|
||||
use_texture_alpha = "clip",
|
||||
sunlight_propagates = true,
|
||||
is_ground_content = false,
|
||||
groups = {crumbly = 2, cracky = 2, snappy = 2, test_trowel = 1, not_in_creative_inventory=1},
|
||||
sounds = default.node_sound_defaults(),
|
||||
drop = "networks:pipeS",
|
||||
})
|
||||
|
||||
local size = 3/16
|
||||
local Boxes = {
|
||||
{{-size, -size, size, size, size, 0.5 }}, -- z+
|
||||
{{-size, -size, -size, 0.5, size, size}}, -- x+
|
||||
{{-size, -size, -0.5, size, size, size}}, -- z-
|
||||
{{-0.5, -size, -size, size, size, size}}, -- x-
|
||||
{{-size, -0.5, -size, size, size, size}}, -- y-
|
||||
{{-size, -size, -size, size, 0.5, size}}, -- y+
|
||||
}
|
||||
|
||||
local names = networks.register_junction("networks:junction", size, Boxes, Pipe, {
|
||||
description = "Junction",
|
||||
tiles = {"networks_junction.png^[colorize:#007577:60"},
|
||||
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
||||
local name = "networks:junction" .. networks.junction_type(pos, Pipe)
|
||||
minetest.swap_node(pos, {name = name, param2 = 0})
|
||||
Pipe:after_place_node(pos)
|
||||
end,
|
||||
-- junction needs own 'tubelib2_on_update2' to be able to call networks.junction_type
|
||||
tubelib2_on_update2 = function(pos, outdir, tlib2, node)
|
||||
local name = "networks:junction" .. networks.junction_type(pos, Pipe)
|
||||
minetest.swap_node(pos, {name = name, param2 = 0})
|
||||
liquid.update_network(pos, 0, tlib2, node)
|
||||
end,
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
Pipe:after_dig_node(pos)
|
||||
end,
|
||||
use_texture_alpha = "clip",
|
||||
is_ground_content = false,
|
||||
groups = {crumbly = 2, cracky = 2, snappy = 2},
|
||||
sounds = default.node_sound_defaults(),
|
||||
}, 63)
|
||||
|
||||
liquid.register_nodes(names, Pipe, "junc")
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Pump
|
||||
-------------------------------------------------------------------------------
|
||||
local function swap_node(pos, name)
|
||||
local node = tubelib2.get_node_lvm(pos)
|
||||
if node.name == name then
|
||||
return
|
||||
end
|
||||
node.name = name
|
||||
minetest.swap_node(pos, node)
|
||||
end
|
||||
|
||||
local function turn_on(pos, mem)
|
||||
swap_node(pos, "networks:pump_on")
|
||||
M(pos):set_string("infotext", "pumping")
|
||||
mem.running = true
|
||||
-- enable marker cube
|
||||
mem.dbg_cycles = 5
|
||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||
end
|
||||
|
||||
local function turn_off(pos, mem)
|
||||
swap_node(pos, "networks:pump_off")
|
||||
M(pos):set_string("infotext", "off")
|
||||
mem.running = false
|
||||
minetest.get_node_timer(pos):stop()
|
||||
end
|
||||
|
||||
local function on_rightclick(pos, node, clicker)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
if not mem.running then
|
||||
turn_on(pos, mem)
|
||||
else
|
||||
turn_off(pos, mem)
|
||||
end
|
||||
end
|
||||
|
||||
local function pumping(pos)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
local taken, name = liquid.take(pos, Pipe, networks.Flip[outdir], nil, AMOUNT, mem.dbg_cycles > 0)
|
||||
if taken > 0 then
|
||||
print("pumping " .. name .. " " .. taken)
|
||||
local leftover = liquid.put(pos, Pipe, outdir, name, taken, mem.dbg_cycles > 0)
|
||||
if leftover and leftover > 0 then
|
||||
liquid.untake(pos, Pipe, networks.Flip[outdir], name, leftover)
|
||||
if leftover == taken then
|
||||
turn_off(pos, mem)
|
||||
return false
|
||||
end
|
||||
end
|
||||
else
|
||||
print("pumping -")
|
||||
end
|
||||
mem.dbg_cycles = mem.dbg_cycles - 1
|
||||
return true
|
||||
end
|
||||
|
||||
local function after_place_node(pos)
|
||||
local outdir = networks.side_to_outdir(pos, "B")
|
||||
M(pos):set_int("outdir", outdir)
|
||||
Pipe:after_place_node(pos, {outdir})
|
||||
M(pos):set_string("infotext", "off")
|
||||
tubelib2.init_mem(pos)
|
||||
end
|
||||
|
||||
local function after_dig_node(pos, oldnode, oldmetadata)
|
||||
local outdir = tonumber(oldmetadata.fields.outdir or 0)
|
||||
Pipe:after_dig_node(pos, {outdir})
|
||||
tubelib2.del_mem(pos)
|
||||
end
|
||||
|
||||
minetest.register_node("networks:pump_off", {
|
||||
description = "Pump",
|
||||
tiles = {
|
||||
-- up, down, right, left, back, front
|
||||
'networks_arrow.png^[colorize:#007577:60',
|
||||
'networks_pump.png^[colorize:#007577:60',
|
||||
'networks_pump.png^[colorize:#007577:60',
|
||||
'networks_pump.png^[colorize:#007577:60',
|
||||
'networks_conn.png^[colorize:#007577:60',
|
||||
'networks_conn.png^[colorize:#007577:60',
|
||||
},
|
||||
after_place_node = after_place_node,
|
||||
after_dig_node = after_dig_node,
|
||||
on_timer = pumping,
|
||||
on_rightclick = on_rightclick,
|
||||
paramtype2 = "facedir",
|
||||
on_rotate = screwdriver.disallow,
|
||||
is_ground_content = false,
|
||||
groups = {crumbly = 2, cracky = 2, snappy = 2},
|
||||
sounds = default.node_sound_defaults(),
|
||||
})
|
||||
|
||||
minetest.register_node("networks:pump_on", {
|
||||
description = "Pump",
|
||||
tiles = {
|
||||
-- up, down, right, left, back, front
|
||||
'networks_arrow.png^[colorize:#007577:60',
|
||||
'networks_pump.png^[colorize:#007577:60',
|
||||
'networks_pump.png^[colorize:#007577:60',
|
||||
'networks_pump.png^[colorize:#007577:60',
|
||||
'networks_conn.png^[colorize:#007577:60',
|
||||
'networks_conn.png^[colorize:#007577:60',
|
||||
},
|
||||
after_place_node = after_place_node,
|
||||
after_dig_node = after_dig_node,
|
||||
on_timer = pumping,
|
||||
on_rightclick = on_rightclick,
|
||||
paramtype = "light",
|
||||
light_source = 8,
|
||||
paramtype2 = "facedir",
|
||||
diggable = false,
|
||||
drop = "",
|
||||
groups = {not_in_creative_inventory = 1},
|
||||
is_ground_content = false,
|
||||
sounds = default.node_sound_defaults(),
|
||||
})
|
||||
|
||||
-- Pumps have to provide one output and one input side
|
||||
liquid.register_nodes({"networks:pump_off", "networks:pump_on"}, Pipe, "pump", {"F", "B"}, {})
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Tank
|
||||
-------------------------------------------------------------------------------
|
||||
local function register_tank(name, description, liquid_name, liquid_amount)
|
||||
minetest.register_node(name, {
|
||||
description = description,
|
||||
tiles = {
|
||||
-- up, down, right, left, back, front
|
||||
"networks_tank.png^[colorize:#007577:60",
|
||||
"networks_tank.png^[colorize:#007577:60",
|
||||
"networks_tank.png^[colorize:#007577:60",
|
||||
"networks_tank.png^[colorize:#007577:60",
|
||||
"networks_tank.png^[colorize:#007577:60",
|
||||
'networks_tank.png^[colorize:#007577:60',
|
||||
},
|
||||
after_place_node = function(pos)
|
||||
Pipe:after_place_node(pos)
|
||||
local mem = tubelib2.init_mem(pos)
|
||||
mem.liquid = {}
|
||||
mem.liquid.name = liquid_name
|
||||
mem.liquid.amount = liquid_amount
|
||||
M(pos):set_string("infotext", networks.liquid.get_item(mem))
|
||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||
end,
|
||||
after_dig_node = function(pos, oldnode, oldmetadata)
|
||||
Pipe:after_dig_node(pos)
|
||||
tubelib2.del_mem(pos)
|
||||
end,
|
||||
on_timer = function(pos, elapsed)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
M(pos):set_string("infotext", networks.liquid.get_item(mem))
|
||||
return true
|
||||
end,
|
||||
paramtype2 = "facedir",
|
||||
on_rotate = screwdriver.disallow,
|
||||
is_ground_content = false,
|
||||
groups = {crumbly = 2, cracky = 2, snappy = 2},
|
||||
sounds = default.node_sound_defaults(),
|
||||
})
|
||||
end
|
||||
|
||||
-- 3 types of test tanks
|
||||
register_tank("networks:tank1", "Water Tank", "water", STORAGE_CAPA)
|
||||
register_tank("networks:tank2", "Milk Tank", "milk", STORAGE_CAPA)
|
||||
register_tank("networks:tank3", "Empty Tank", nil, 0)
|
||||
|
||||
liquid.register_nodes({"networks:tank1", "networks:tank2", "networks:tank3"},
|
||||
Pipe, "tank", nil, {
|
||||
capa = STORAGE_CAPA,
|
||||
peek = function(pos, indir)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
return liquid.srv_peek(mem)
|
||||
end,
|
||||
put = function(pos, indir, name, amount)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
return liquid.srv_put(mem, name, amount, STORAGE_CAPA)
|
||||
end,
|
||||
take = function(pos, indir, name, amount)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
return liquid.srv_take(mem, name, amount)
|
||||
end,
|
||||
untake = function(pos, indir, name, amount)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
return liquid.srv_put(mem, name, amount, STORAGE_CAPA)
|
||||
end,
|
||||
}
|
||||
)
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Valve
|
||||
-------------------------------------------------------------------------------
|
||||
local node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{-5/16, -5/16, -4/8, 5/16, 5/16, 4/8},
|
||||
},
|
||||
}
|
||||
|
||||
-- The on-valve is a "primary node" like pipes
|
||||
minetest.register_node("networks:valve_on", {
|
||||
description = "Valve",
|
||||
paramtype = "light",
|
||||
drawtype = "nodebox",
|
||||
node_box = node_box,
|
||||
tiles = {
|
||||
"networks_switch_on.png^[transformR90^[colorize:#007577:60",
|
||||
"networks_switch_on.png^[transformR90^[colorize:#007577:60",
|
||||
"networks_switch_on.png^[colorize:#007577:60",
|
||||
"networks_switch_on.png^[colorize:#007577:60",
|
||||
"networks_switch_hole.png^[colorize:#007577:60",
|
||||
"networks_switch_hole.png^[colorize:#007577:60",
|
||||
},
|
||||
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
||||
if not Pipe:after_place_tube(pos, placer, pointed_thing) then
|
||||
minetest.remove_node(pos)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end,
|
||||
on_rightclick = function(pos, node, clicker)
|
||||
if liquid.turn_valve_off(pos, Pipe, "networks:valve_off", "networks:valve_on") then
|
||||
minetest.sound_play("doors_glass_door_open", {
|
||||
pos = pos,
|
||||
gain = 1,
|
||||
max_hear_distance = 5})
|
||||
end
|
||||
end,
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
Pipe:after_dig_tube(pos, oldnode, oldmetadata)
|
||||
end,
|
||||
paramtype2 = "facedir",
|
||||
on_rotate = screwdriver.disallow,
|
||||
use_texture_alpha = "clip",
|
||||
sunlight_propagates = true,
|
||||
is_ground_content = false,
|
||||
groups = {crumbly = 2, cracky = 2, snappy = 2},
|
||||
sounds = default.node_sound_defaults(),
|
||||
})
|
||||
|
||||
-- The off-valve is a "secondary node" without connection sides
|
||||
minetest.register_node("networks:valve_off", {
|
||||
description = "Valve",
|
||||
paramtype = "light",
|
||||
drawtype = "nodebox",
|
||||
node_box = node_box,
|
||||
tiles = {
|
||||
"networks_switch_off.png^[transformR90^[colorize:#007577:60",
|
||||
"networks_switch_off.png^[transformR90^[colorize:#007577:60",
|
||||
"networks_switch_off.png^[colorize:#007577:60",
|
||||
"networks_switch_off.png^[colorize:#007577:60",
|
||||
"networks_switch_hole.png^[colorize:#007577:60",
|
||||
"networks_switch_hole.png^[colorize:#007577:60",
|
||||
},
|
||||
on_rightclick = function(pos, node, clicker)
|
||||
if liquid.turn_valve_on(pos, Pipe, "networks:valve_off", "networks:valve_on") then
|
||||
minetest.sound_play("doors_glass_door_open", {
|
||||
pos = pos,
|
||||
gain = 1,
|
||||
max_hear_distance = 5})
|
||||
end
|
||||
end,
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
Pipe:after_dig_node(pos)
|
||||
end,
|
||||
paramtype2 = "facedir",
|
||||
on_rotate = screwdriver.disallow,
|
||||
use_texture_alpha = "clip",
|
||||
sunlight_propagates = true,
|
||||
is_ground_content = false,
|
||||
drop = "networks:valve_on",
|
||||
groups = {crumbly = 2, cracky = 2, snappy = 2, test_trowel = 1, not_in_creative_inventory = 1},
|
||||
sounds = default.node_sound_defaults(),
|
||||
})
|
||||
|
||||
liquid.register_nodes({"networks:valve_off"}, Pipe, "tank", {}, {})
|
585
networks/test/test_power.lua
Normal file
@ -0,0 +1,585 @@
|
||||
--[[
|
||||
|
||||
Networks
|
||||
========
|
||||
|
||||
Copyright (C) 2021 Joachim Stolberg
|
||||
|
||||
AGPL v3
|
||||
See LICENSE.txt for more information
|
||||
|
||||
]]--
|
||||
|
||||
-- for lazy programmers
|
||||
local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end
|
||||
local S2P = minetest.string_to_pos
|
||||
local M = minetest.get_meta
|
||||
|
||||
local CYCLE_TIME = 2
|
||||
local STORAGE_CAPA = 500
|
||||
local GEN_MAX = 20
|
||||
local CON_MAX = 5
|
||||
local HIDDEN = true -- enable/disable hidden nodes
|
||||
|
||||
local function round(val)
|
||||
if val > 100 then
|
||||
return math.floor(val + 0.5)
|
||||
elseif val > 10 then
|
||||
return math.floor((val * 10) + 0.5) / 10
|
||||
else
|
||||
return math.floor((val * 100) + 0.5) / 100
|
||||
end
|
||||
end
|
||||
|
||||
local power = networks.power
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Cable
|
||||
-------------------------------------------------------------------------------
|
||||
local Cable = tubelib2.Tube:new({
|
||||
dirs_to_check = {1,2,3,4,5,6},
|
||||
max_tube_length = 100,
|
||||
tube_type = "pwr",
|
||||
primary_node_names = {"networks:cableS", "networks:cableA", "networks:switch_on"},
|
||||
secondary_node_names = {}, -- Names will be added via 'power.register_nodes'
|
||||
after_place_tube = function(pos, param2, tube_type, num_tubes, tbl)
|
||||
local name = minetest.get_node(pos).name
|
||||
if name == "networks:switch_on" or name == "networks:switch_off" then
|
||||
minetest.swap_node(pos, {name = name, param2 = param2 % 32})
|
||||
elseif not networks.hidden_name(pos) then
|
||||
minetest.swap_node(pos, {name = "networks:cable"..tube_type, param2 = param2 % 32})
|
||||
end
|
||||
M(pos):set_int("netw_param2", param2)
|
||||
end,
|
||||
})
|
||||
|
||||
if HIDDEN then
|
||||
-- Enable hidden cables
|
||||
networks.use_metadata(Cable)
|
||||
networks.register_hidden_message("Use the tool to remove the node.")
|
||||
networks.register_filling_items({
|
||||
"default:stone",
|
||||
"default:stonebrick",
|
||||
"default:stone_block",
|
||||
"default:clay",
|
||||
"default:snowblock",
|
||||
"default:ice",
|
||||
"default:glass",
|
||||
"default:obsidian_glass",
|
||||
"default:brick",
|
||||
"default:tree",
|
||||
"default:wood",
|
||||
"default:jungletree",
|
||||
"default:junglewood",
|
||||
"default:pine_tree",
|
||||
"default:pine_wood",
|
||||
"default:acacia_tree",
|
||||
"default:acacia_wood",
|
||||
"default:aspen_tree",
|
||||
"default:aspen_wood",
|
||||
"default:steelblock",
|
||||
"default:copperblock",
|
||||
"default:tinblock",
|
||||
"default:bronzeblock",
|
||||
"default:goldblock",
|
||||
"default:mese",
|
||||
"default:diamondblock",
|
||||
})
|
||||
end
|
||||
|
||||
-- Use global callback instead of node related functions
|
||||
Cable:register_on_tube_update2(function(pos, outdir, tlib2, node)
|
||||
power.update_network(pos, outdir, tlib2, node)
|
||||
end)
|
||||
|
||||
minetest.register_node("networks:cableS", {
|
||||
description = "Cable",
|
||||
tiles = { -- Top, base, right, left, front, back
|
||||
"networks_cable.png",
|
||||
"networks_cable.png",
|
||||
"networks_cable.png",
|
||||
"networks_cable.png",
|
||||
"networks_hole.png",
|
||||
"networks_hole.png",
|
||||
},
|
||||
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
||||
if not Cable:after_place_tube(pos, placer, pointed_thing) then
|
||||
minetest.remove_node(pos)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end,
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
Cable:after_dig_tube(pos, oldnode, oldmetadata)
|
||||
end,
|
||||
paramtype2 = "facedir",
|
||||
drawtype = "nodebox",
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{-3/16, -3/16, -4/8, 3/16, 3/16, 4/8},
|
||||
},
|
||||
},
|
||||
on_rotate = screwdriver.disallow,
|
||||
paramtype = "light",
|
||||
use_texture_alpha = "clip",
|
||||
sunlight_propagates = true,
|
||||
is_ground_content = false,
|
||||
groups = {crumbly = 2, cracky = 2, snappy = 2, test_trowel = 1},
|
||||
sounds = default.node_sound_defaults(),
|
||||
})
|
||||
|
||||
minetest.register_node("networks:cableA", {
|
||||
description = "Cable",
|
||||
tiles = { -- Top, base, right, left, front, back
|
||||
"networks_cable.png",
|
||||
"networks_hole.png",
|
||||
"networks_cable.png",
|
||||
"networks_cable.png",
|
||||
"networks_cable.png",
|
||||
"networks_hole.png",
|
||||
},
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
Cable:after_dig_tube(pos, oldnode, oldmetadata)
|
||||
end,
|
||||
paramtype2 = "facedir",
|
||||
drawtype = "nodebox",
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{-3/16, -4/8, -3/16, 3/16, 3/16, 3/16},
|
||||
{-3/16, -3/16, -4/8, 3/16, 3/16, -3/16},
|
||||
},
|
||||
},
|
||||
on_rotate = screwdriver.disallow,
|
||||
paramtype = "light",
|
||||
use_texture_alpha = "clip",
|
||||
sunlight_propagates = true,
|
||||
is_ground_content = false,
|
||||
groups = {crumbly = 2, cracky = 2, snappy = 2, test_trowel = 1, not_in_creative_inventory=1},
|
||||
sounds = default.node_sound_defaults(),
|
||||
drop = "networks:cableS",
|
||||
})
|
||||
|
||||
local size = 3/16
|
||||
local Boxes = {
|
||||
{{-size, -size, size, size, size, 0.5 }}, -- z+
|
||||
{{-size, -size, -size, 0.5, size, size}}, -- x+
|
||||
{{-size, -size, -0.5, size, size, size}}, -- z-
|
||||
{{-0.5, -size, -size, size, size, size}}, -- x-
|
||||
{{-size, -0.5, -size, size, size, size}}, -- y-
|
||||
{{-size, -size, -size, size, 0.5, size}}, -- y+
|
||||
}
|
||||
|
||||
local names = networks.register_junction("networks:junction", size, Boxes, Cable, {
|
||||
description = "Junction",
|
||||
tiles = {"networks_junction.png"},
|
||||
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
||||
local name = "networks:junction"..networks.junction_type(pos, Cable)
|
||||
minetest.swap_node(pos, {name = name, param2 = 0})
|
||||
Cable:after_place_node(pos)
|
||||
end,
|
||||
-- junction needs own 'tubelib2_on_update2' to be able to call networks.junction_type
|
||||
tubelib2_on_update2 = function(pos, outdir, tlib2, node)
|
||||
if not networks.hidden_name(pos) then
|
||||
local name = "networks:junction" .. networks.junction_type(pos, Cable)
|
||||
minetest.swap_node(pos, {name = name, param2 = 0})
|
||||
end
|
||||
power.update_network(pos, 0, tlib2, node)
|
||||
end,
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
Cable:after_dig_node(pos)
|
||||
end,
|
||||
use_texture_alpha = "clip",
|
||||
is_ground_content = false,
|
||||
groups = {crumbly = 2, cracky = 2, snappy = 2, test_trowel = 1},
|
||||
sounds = default.node_sound_defaults(),
|
||||
}, 63)
|
||||
|
||||
power.register_nodes(names, Cable, "junc")
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Generator
|
||||
-------------------------------------------------------------------------------
|
||||
minetest.register_node("networks:generator", {
|
||||
description = "Generator",
|
||||
tiles = {
|
||||
-- up, down, right, left, back, front
|
||||
'networks_gen.png',
|
||||
'networks_gen.png',
|
||||
'networks_gen.png',
|
||||
'networks_gen.png',
|
||||
'networks_gen.png',
|
||||
'networks_conn.png',
|
||||
},
|
||||
after_place_node = function(pos)
|
||||
local outdir = networks.side_to_outdir(pos, "F")
|
||||
M(pos):set_int("outdir", outdir)
|
||||
Cable:after_place_node(pos, {outdir})
|
||||
M(pos):set_string("infotext", "off")
|
||||
tubelib2.init_mem(pos)
|
||||
end,
|
||||
after_dig_node = function(pos, oldnode, oldmetadata)
|
||||
local outdir = tonumber(oldmetadata.fields.outdir or 0)
|
||||
Cable:after_dig_node(pos, {outdir})
|
||||
tubelib2.del_mem(pos)
|
||||
end,
|
||||
on_timer = function(pos, elapsed)
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
mem.provided = power.provide_power(pos, Cable, outdir, GEN_MAX)
|
||||
mem.load = power.get_storage_load(pos, Cable, outdir, GEN_MAX)
|
||||
M(pos):set_string("infotext", "providing "..round(mem.provided))
|
||||
return true
|
||||
end,
|
||||
on_rightclick = function(pos, node, clicker)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
if mem.running then
|
||||
mem.running = false
|
||||
M(pos):set_string("infotext", "off")
|
||||
minetest.get_node_timer(pos):stop()
|
||||
else
|
||||
mem.provided = mem.provided or 0
|
||||
mem.running = true
|
||||
M(pos):set_string("infotext", "providing "..round(mem.provided))
|
||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||
end
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
power.start_storage_calc(pos, Cable, outdir)
|
||||
end,
|
||||
get_generator_data = function(pos, outdir, tlib2)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
if mem.running then
|
||||
-- generator storage capa = 2 * performance
|
||||
return {level = (mem.load or 0) / GEN_MAX, perf = GEN_MAX, capa = GEN_MAX * 2}
|
||||
end
|
||||
end,
|
||||
paramtype2 = "facedir",
|
||||
on_rotate = screwdriver.disallow,
|
||||
is_ground_content = false,
|
||||
groups = {crumbly = 2, cracky = 2, snappy = 2},
|
||||
sounds = default.node_sound_defaults(),
|
||||
})
|
||||
|
||||
-- Generators have to provide one output side
|
||||
power.register_nodes({"networks:generator"}, Cable, "gen", {"F"})
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Storage
|
||||
-------------------------------------------------------------------------------
|
||||
minetest.register_node("networks:storage", {
|
||||
description = "Storage",
|
||||
tiles = {
|
||||
-- up, down, right, left, back, front
|
||||
"networks_sto.png",
|
||||
"networks_sto.png",
|
||||
"networks_sto.png",
|
||||
"networks_sto.png",
|
||||
"networks_sto.png",
|
||||
'networks_conn.png',
|
||||
},
|
||||
after_place_node = function(pos)
|
||||
local outdir = networks.side_to_outdir(pos, "F")
|
||||
M(pos):set_int("outdir", outdir)
|
||||
Cable:after_place_node(pos, {outdir})
|
||||
tubelib2.init_mem(pos)
|
||||
M(pos):set_string("infotext", "off")
|
||||
end,
|
||||
after_dig_node = function(pos, oldnode, oldmetadata)
|
||||
local outdir = tonumber(oldmetadata.fields.outdir or 0)
|
||||
Cable:after_dig_node(pos, {outdir})
|
||||
tubelib2.del_mem(pos)
|
||||
end,
|
||||
on_timer = function(pos, elapsed)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
local data = power.get_storage_data(pos, Cable, outdir)
|
||||
if data then
|
||||
mem.load = data.level * STORAGE_CAPA
|
||||
local percent = data.level * 100
|
||||
M(pos):set_string("infotext", "level = "..round(percent)..", charging = "..data.charging)
|
||||
end
|
||||
return true
|
||||
end,
|
||||
on_rightclick = function(pos, node, clicker)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
if mem.running then
|
||||
mem.running = false
|
||||
M(pos):set_string("infotext", "off")
|
||||
minetest.get_node_timer(pos):stop()
|
||||
else
|
||||
mem.provided = mem.provided or 0
|
||||
mem.running = true
|
||||
local percent = (mem.load or 0) / STORAGE_CAPA * 100
|
||||
M(pos):set_string("infotext", "level = "..round(percent))
|
||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||
end
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
power.start_storage_calc(pos, Cable, outdir)
|
||||
end,
|
||||
get_storage_data = function(pos, outdir, tlib2)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
if mem.running then
|
||||
return {level = (mem.load or 0) / STORAGE_CAPA, capa = STORAGE_CAPA}
|
||||
end
|
||||
end,
|
||||
paramtype2 = "facedir",
|
||||
on_rotate = screwdriver.disallow,
|
||||
is_ground_content = false,
|
||||
groups = {crumbly = 2, cracky = 2, snappy = 2},
|
||||
sounds = default.node_sound_defaults(),
|
||||
})
|
||||
|
||||
-- Storage nodes have to provide one input/output side
|
||||
power.register_nodes({"networks:storage"}, Cable, "sto", {"F"})
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Consumer
|
||||
-------------------------------------------------------------------------------
|
||||
local function swap_node(pos, name)
|
||||
local node = tubelib2.get_node_lvm(pos)
|
||||
if node.name == name then
|
||||
return
|
||||
end
|
||||
node.name = name
|
||||
minetest.swap_node(pos, node)
|
||||
end
|
||||
|
||||
local function turn_on(pos)
|
||||
swap_node(pos, "networks:consumer_on")
|
||||
M(pos):set_string("infotext", "on")
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
mem.running = true
|
||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||
end
|
||||
|
||||
local function turn_off(pos)
|
||||
swap_node(pos, "networks:consumer")
|
||||
M(pos):set_string("infotext", "off")
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
mem.running = false
|
||||
minetest.get_node_timer(pos):stop()
|
||||
end
|
||||
|
||||
local function on_rightclick(pos, node, clicker)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
if not mem.running and power.power_available(pos, Cable) then
|
||||
turn_on(pos)
|
||||
else
|
||||
turn_off(pos)
|
||||
end
|
||||
end
|
||||
|
||||
local function after_place_node(pos)
|
||||
M(pos):set_string("infotext", "off")
|
||||
Cable:after_place_node(pos)
|
||||
tubelib2.init_mem(pos)
|
||||
end
|
||||
|
||||
local function after_dig_node(pos, oldnode)
|
||||
Cable:after_dig_node(pos)
|
||||
tubelib2.del_mem(pos)
|
||||
end
|
||||
|
||||
minetest.register_node("networks:consumer", {
|
||||
description = "Consumer",
|
||||
tiles = {'networks_con.png^[colorize:#000000:50'},
|
||||
|
||||
on_timer = function(pos, elapsed)
|
||||
local consumed = power.consume_power(pos, Cable, nil, CON_MAX)
|
||||
if consumed == CON_MAX then
|
||||
swap_node(pos, "networks:consumer_on")
|
||||
M(pos):set_string("infotext", "on")
|
||||
end
|
||||
return true
|
||||
end,
|
||||
on_rightclick = on_rightclick,
|
||||
after_place_node = after_place_node,
|
||||
after_dig_node = after_dig_node,
|
||||
paramtype2 = "facedir",
|
||||
groups = {choppy = 2, cracky = 2, crumbly = 2},
|
||||
is_ground_content = false,
|
||||
sounds = default.node_sound_defaults(),
|
||||
})
|
||||
|
||||
minetest.register_node("networks:consumer_on", {
|
||||
description = "Consumer",
|
||||
tiles = {'networks_con.png'},
|
||||
|
||||
on_timer = function(pos, elapsed)
|
||||
local consumed = power.consume_power(pos, Cable, nil, CON_MAX)
|
||||
if consumed < CON_MAX then
|
||||
swap_node(pos, "networks:consumer")
|
||||
M(pos):set_string("infotext", "no power")
|
||||
end
|
||||
return true
|
||||
end,
|
||||
on_rightclick = on_rightclick,
|
||||
after_place_node = after_place_node,
|
||||
after_dig_node = after_dig_node,
|
||||
paramtype = "light",
|
||||
light_source = minetest.LIGHT_MAX,
|
||||
paramtype2 = "facedir",
|
||||
diggable = false,
|
||||
drop = "",
|
||||
groups = {not_in_creative_inventory = 1},
|
||||
is_ground_content = false,
|
||||
sounds = default.node_sound_defaults(),
|
||||
})
|
||||
|
||||
-- Consumer can provide dedicated input sides, otherwise all sides are used
|
||||
power.register_nodes({"networks:consumer", "networks:consumer_on"}, Cable, "con")
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Switch/valve
|
||||
-------------------------------------------------------------------------------
|
||||
local node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{-5/16, -5/16, -4/8, 5/16, 5/16, 4/8},
|
||||
},
|
||||
}
|
||||
|
||||
-- The on-switch is a "primary node" like cables
|
||||
minetest.register_node("networks:switch_on", {
|
||||
description = "Switch",
|
||||
paramtype = "light",
|
||||
drawtype = "nodebox",
|
||||
node_box = node_box,
|
||||
tiles = {
|
||||
"networks_switch_on.png^[transformR90",
|
||||
"networks_switch_on.png^[transformR90",
|
||||
"networks_switch_on.png",
|
||||
"networks_switch_on.png",
|
||||
"networks_switch_hole.png",
|
||||
"networks_switch_hole.png",
|
||||
},
|
||||
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
||||
if not Cable:after_place_tube(pos, placer, pointed_thing) then
|
||||
minetest.remove_node(pos)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end,
|
||||
on_rightclick = function(pos, node, clicker)
|
||||
if power.turn_switch_off(pos, Cable, "networks:switch_off", "networks:switch_on") then
|
||||
minetest.sound_play("doors_glass_door_open", {
|
||||
pos = pos,
|
||||
gain = 1,
|
||||
max_hear_distance = 5})
|
||||
end
|
||||
end,
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
Cable:after_dig_tube(pos, oldnode, oldmetadata)
|
||||
end,
|
||||
paramtype2 = "facedir",
|
||||
on_rotate = screwdriver.disallow,
|
||||
use_texture_alpha = "clip",
|
||||
sunlight_propagates = true,
|
||||
is_ground_content = false,
|
||||
groups = {crumbly = 2, cracky = 2, snappy = 2, test_trowel = 1},
|
||||
sounds = default.node_sound_defaults(),
|
||||
})
|
||||
|
||||
-- The off-switch is a "secondary node" without connection sides
|
||||
minetest.register_node("networks:switch_off", {
|
||||
description = "Switch",
|
||||
paramtype = "light",
|
||||
drawtype = "nodebox",
|
||||
node_box = node_box,
|
||||
tiles = {
|
||||
"networks_switch_off.png^[transformR90",
|
||||
"networks_switch_off.png^[transformR90",
|
||||
"networks_switch_off.png",
|
||||
"networks_switch_off.png",
|
||||
"networks_switch_hole.png",
|
||||
"networks_switch_hole.png",
|
||||
},
|
||||
on_rightclick = function(pos, node, clicker)
|
||||
if power.turn_switch_on(pos, Cable, "networks:switch_off", "networks:switch_on") then
|
||||
minetest.sound_play("doors_glass_door_open", {
|
||||
pos = pos,
|
||||
gain = 1,
|
||||
max_hear_distance = 5})
|
||||
end
|
||||
end,
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
Cable:after_dig_node(pos)
|
||||
end,
|
||||
paramtype2 = "facedir",
|
||||
on_rotate = screwdriver.disallow,
|
||||
use_texture_alpha = "clip",
|
||||
sunlight_propagates = true,
|
||||
is_ground_content = false,
|
||||
drop = "networks:switch_on",
|
||||
groups = {crumbly = 2, cracky = 2, snappy = 2, test_trowel = 1, not_in_creative_inventory = 1},
|
||||
sounds = default.node_sound_defaults(),
|
||||
})
|
||||
|
||||
power.register_nodes({"networks:switch_off"}, Cable, "con", {})
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Hide/open tool
|
||||
-------------------------------------------------------------------------------
|
||||
-- Hide or open a node
|
||||
local function replace_node(itemstack, placer, pointed_thing)
|
||||
if pointed_thing.type == "node" then
|
||||
local pos = pointed_thing.under
|
||||
local name = placer:get_player_name()
|
||||
if minetest.is_protected(pos, name) then
|
||||
return
|
||||
end
|
||||
local node = minetest.get_node(pos)
|
||||
local res = false
|
||||
if minetest.get_item_group(node.name, "test_trowel") == 1 then
|
||||
res = networks.hide_node(pos, node, placer)
|
||||
elseif networks.hidden_name(pos) then
|
||||
res = networks.open_node(pos, node, placer)
|
||||
end
|
||||
if res then
|
||||
minetest.sound_play("default_dig_snappy", {
|
||||
pos = pos,
|
||||
gain = 1,
|
||||
max_hear_distance = 5})
|
||||
elseif placer and placer.get_player_name then
|
||||
minetest.chat_send_player(placer:get_player_name(), "Invalid fill material in inventory slot 1!")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_tool("networks:tool", {
|
||||
description = "Hide Tool\n(Fill material to the right of the tool)",
|
||||
inventory_image = "networks_tool.png",
|
||||
wield_image = "networks_tool.png",
|
||||
use_texture_alpha = "clip",
|
||||
groups = {cracky=1},
|
||||
on_use = replace_node,
|
||||
on_place = replace_node,
|
||||
node_placement_prediction = "",
|
||||
stack_max = 1,
|
||||
})
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- Test Commands
|
||||
-------------------------------------------------------------------------------
|
||||
minetest.register_chatcommand("power_data", {
|
||||
func = function(name)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
local pos = player:get_pos()
|
||||
pos.y = pos.y - 0.5
|
||||
pos = vector.round(pos)
|
||||
local data = power.get_network_data(pos, Cable)
|
||||
if data then
|
||||
local s = string.format("Netw %u: generated = %u/%u, consumed = %u, storage load = %u/%u",
|
||||
data.netw_num, round(data.provided),
|
||||
data.available, round(data.consumed),
|
||||
round(data.curr_load), round(data.max_capa))
|
||||
return true, s
|
||||
end
|
||||
return false, "No valid node position!"
|
||||
|
||||
end
|
||||
})
|
||||
|
||||
return Cable
|
||||
|
165
networks/test/test_tool.lua
Normal file
@ -0,0 +1,165 @@
|
||||
--[[
|
||||
|
||||
Networks
|
||||
========
|
||||
|
||||
Copyright (C) 2021 Joachim Stolberg
|
||||
|
||||
AGPL v3
|
||||
See LICENSE.txt for more information
|
||||
|
||||
]]--
|
||||
|
||||
-- for lazy programmers
|
||||
local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end
|
||||
local S2P = minetest.string_to_pos
|
||||
local M = minetest.get_meta
|
||||
|
||||
local power = networks.power
|
||||
local liquid = networks.liquid
|
||||
|
||||
local function round(val)
|
||||
return math.floor(val + 0.5)
|
||||
end
|
||||
|
||||
local function get_list(tbl, sep)
|
||||
local keys = {}
|
||||
for k,v in pairs(tbl) do
|
||||
if v then
|
||||
keys[#keys + 1] = k
|
||||
end
|
||||
end
|
||||
return table.concat(keys, sep)
|
||||
end
|
||||
|
||||
local NetwTypes = false
|
||||
|
||||
local function collect_netw_types()
|
||||
NetwTypes = {}
|
||||
for k,v in pairs(networks.registered_networks.power) do
|
||||
NetwTypes[k] = "power"
|
||||
end
|
||||
for k,v in pairs(networks.registered_networks.liquid) do
|
||||
NetwTypes[k] = "liquid"
|
||||
end
|
||||
end
|
||||
|
||||
local function print_sides(pos, api, netw_type)
|
||||
local t = {}
|
||||
for _, dir in ipairs(networks.get_node_connection_dirs(pos, netw_type)) do
|
||||
t[#t + 1]= tubelib2.dir_to_string(dir)
|
||||
end
|
||||
print("# " .. api .. " - " .. netw_type .. " dirs: " .. table.concat(t, ", "))
|
||||
end
|
||||
|
||||
local function print_power_network_data(pos, api, netw, netw_type)
|
||||
local tlib2 = networks.registered_networks[api][netw_type]
|
||||
local outdir = netw[netw_type].ntype == "junc" and 0 or nil
|
||||
local data = power.get_network_data(pos, tlib2, outdir)
|
||||
if netw then
|
||||
print("- Number of network nodes: " .. (netw.num_nodes or 0))
|
||||
print("- Number of generators: " .. #(netw.gen or {}))
|
||||
print("- Number of consumers: " .. #(netw.con or {}))
|
||||
print("- Number of storage systems: " .. #(netw.sto or {}))
|
||||
end
|
||||
if data then
|
||||
local s = string.format("- Netw %u: generated = %u/%u, consumed = %u, storage load = %u/%u",
|
||||
data.netw_num, round(data.provided),
|
||||
data.available, round(data.consumed),
|
||||
round(data.curr_load), round(data.max_capa))
|
||||
print(s)
|
||||
else
|
||||
print("- Node has no '" .. netw_type .. "' network!!!")
|
||||
end
|
||||
end
|
||||
|
||||
local function print_netID(pos, api, netw_type)
|
||||
local tlib2 = networks.registered_networks[api][netw_type]
|
||||
for _,outdir in ipairs(networks.get_outdirs(pos, tlib2)) do
|
||||
local netID = networks.get_netID(pos, outdir)
|
||||
local s = tubelib2.dir_to_string(outdir)
|
||||
if netID then
|
||||
print("- " .. s .. ": netwNum for '" .. netw_type .. "': " .. networks.netw_num(netID))
|
||||
else
|
||||
print("- " .. s .. ": Node has no '" .. netw_type .. "' netID!!!")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function print_secondary_node(pos, api, netw_type)
|
||||
local tlib2 = networks.registered_networks[api][netw_type]
|
||||
if tlib2:is_secondary_node(pos) then
|
||||
print("- Secondary node: true")
|
||||
else
|
||||
print("- Is no secondary node!!!")
|
||||
end
|
||||
end
|
||||
|
||||
local function print_valid_sides(name, api, netw_type)
|
||||
local tlib2 = networks.registered_networks[api][netw_type]
|
||||
local sides = tlib2.valid_node_contact_sides[name]
|
||||
if sides then
|
||||
print("- Valid node contact sides: " .. get_list(sides, ", "))
|
||||
else
|
||||
print("- Has no valid node contact sides!!!")
|
||||
end
|
||||
end
|
||||
|
||||
-- debug print of node related data
|
||||
local function debug_print(pos)
|
||||
local node = minetest.get_node(pos)
|
||||
local ndef = minetest.registered_nodes[node.name]
|
||||
|
||||
if not NetwTypes then
|
||||
collect_netw_types()
|
||||
end
|
||||
|
||||
if not ndef.networks then
|
||||
print("No networks node!!!")
|
||||
return
|
||||
end
|
||||
|
||||
print("########## " .. node.name .. " ###########")
|
||||
|
||||
for netw_type,api in pairs(NetwTypes) do
|
||||
if ndef.networks[netw_type] then
|
||||
print_sides(pos, api, netw_type)
|
||||
if api == "power" then
|
||||
print_power_network_data(pos, api, ndef.networks, netw_type)
|
||||
elseif api == "liquid" then
|
||||
--print_liquid_network_data(pos, api, netw_type)
|
||||
end
|
||||
print_netID(pos, api, netw_type)
|
||||
print_secondary_node(pos, api, netw_type)
|
||||
print_valid_sides(node.name, api, netw_type)
|
||||
end
|
||||
end
|
||||
|
||||
print("#####################")
|
||||
end
|
||||
|
||||
local function action(itemstack, placer, pointed_thing)
|
||||
if pointed_thing.type == "node" then
|
||||
local pos = pointed_thing.under
|
||||
networks.register_observe_pos(pos)
|
||||
if placer:get_player_control().sneak then
|
||||
debug_print(pos)
|
||||
else
|
||||
debug_print(pos)
|
||||
end
|
||||
else
|
||||
networks.register_observe_pos(nil)
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_tool("networks:tool2", {
|
||||
description = "Debugging Tool",
|
||||
inventory_image = "networks_tool.png",
|
||||
wield_image = "networks_tool.png",
|
||||
use_texture_alpha = "clip",
|
||||
groups = {cracky=1},
|
||||
on_use = action,
|
||||
on_place = action,
|
||||
node_placement_prediction = "",
|
||||
stack_max = 1,
|
||||
})
|
BIN
networks/textures/networks_arrow.png
Normal file
After Width: | Height: | Size: 109 B |
BIN
networks/textures/networks_cable.png
Normal file
After Width: | Height: | Size: 125 B |
BIN
networks/textures/networks_con.png
Normal file
After Width: | Height: | Size: 108 B |
BIN
networks/textures/networks_conn.png
Normal file
After Width: | Height: | Size: 110 B |
BIN
networks/textures/networks_gen.png
Normal file
After Width: | Height: | Size: 116 B |
BIN
networks/textures/networks_hole.png
Normal file
After Width: | Height: | Size: 129 B |
BIN
networks/textures/networks_junction.png
Normal file
After Width: | Height: | Size: 125 B |
BIN
networks/textures/networks_marker.png
Normal file
After Width: | Height: | Size: 195 B |
BIN
networks/textures/networks_pump.png
Normal file
After Width: | Height: | Size: 105 B |
BIN
networks/textures/networks_sto.png
Normal file
After Width: | Height: | Size: 118 B |
BIN
networks/textures/networks_switch_hole.png
Normal file
After Width: | Height: | Size: 125 B |
BIN
networks/textures/networks_switch_off.png
Normal file
After Width: | Height: | Size: 125 B |
BIN
networks/textures/networks_switch_on.png
Normal file
After Width: | Height: | Size: 124 B |
BIN
networks/textures/networks_tank.png
Normal file
After Width: | Height: | Size: 101 B |
BIN
networks/textures/networks_tool.png
Normal file
After Width: | Height: | Size: 164 B |
@ -21,9 +21,9 @@ local S = signs_bot.S
|
||||
local lib = signs_bot.lib
|
||||
|
||||
signs_bot.MAX_CAPA = 600
|
||||
local PWR_NEEDED = 8
|
||||
|
||||
local CYCLE_TIME = 1
|
||||
local CYCLE_TIME2 = 2 -- for charging phase
|
||||
|
||||
local function in_range(val, min, max)
|
||||
if val < min then return min end
|
||||
@ -233,14 +233,14 @@ function signs_bot.stop_robot(base_pos, mem)
|
||||
if mem.signal_request ~= true then
|
||||
mem.running = false
|
||||
if minetest.global_exists("techage") then
|
||||
minetest.get_node_timer(base_pos):start(4)
|
||||
minetest.get_node_timer(base_pos):start(CYCLE_TIME2)
|
||||
mem.charging = true
|
||||
mem.power_available = false
|
||||
else
|
||||
minetest.get_node_timer(base_pos):stop()
|
||||
mem.charging = false
|
||||
end
|
||||
if mem.power_available then
|
||||
if mem.charging then
|
||||
signs_bot.infotext(base_pos, S("charging"))
|
||||
else
|
||||
signs_bot.infotext(base_pos, S("stopped"))
|
||||
@ -387,19 +387,6 @@ if minetest.global_exists("techage") then
|
||||
drop = ""
|
||||
end
|
||||
|
||||
local function on_power(pos)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
mem.power_available = true
|
||||
mem.charging = true
|
||||
signs_bot.infotext(pos, S("charging"))
|
||||
end
|
||||
|
||||
local function on_nopower(pos)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
mem.power_available = false
|
||||
signs_bot.infotext(pos, S("no power"))
|
||||
end
|
||||
|
||||
minetest.register_node("signs_bot:box", {
|
||||
description = S("Signs Bot Box"),
|
||||
stack_max = 1,
|
||||
@ -478,31 +465,6 @@ minetest.register_node("signs_bot:box", {
|
||||
on_timer = node_timer,
|
||||
on_rotate = screwdriver.disallow,
|
||||
|
||||
-- techage power definition
|
||||
tubelib2_on_update2 = function(pos, outdir, tlib2, node)
|
||||
if minetest.global_exists("techage") then
|
||||
techage.power.update_network(pos, outdir, tlib2)
|
||||
end
|
||||
end,
|
||||
networks = {
|
||||
ele1 = {
|
||||
sides = {L=1, U=1, D=1, F=1, B=1},
|
||||
ntype = "con1",
|
||||
on_power = function(pos)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
mem.power_available = true
|
||||
signs_bot.infotext(pos, S("charging"))
|
||||
end,
|
||||
on_nopower = function(pos)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
mem.power_available = false
|
||||
signs_bot.infotext(pos, S("no power"))
|
||||
end,
|
||||
nominal = PWR_NEEDED,
|
||||
}
|
||||
},
|
||||
-- techage power definition
|
||||
|
||||
drop = drop,
|
||||
paramtype2 = "facedir",
|
||||
is_ground_content = false,
|
||||
|
@ -156,6 +156,7 @@ end
|
||||
local function bot_error(base_pos, mem, err, cmd)
|
||||
minetest.sound_play('signs_bot_error', {pos = base_pos})
|
||||
minetest.sound_play('signs_bot_error', {pos = mem.robot_pos})
|
||||
err = err or "unknown"
|
||||
if cmd then
|
||||
signs_bot.infotext(base_pos, err .. ":\n'" .. cmd .. "'")
|
||||
mem.error = err .. ": '" .. cmd .. "'"
|
||||
|
@ -29,7 +29,7 @@ local function additem(mem, stack)
|
||||
pos = {x = pos.x, y = pos.y - 1, z = pos.z}
|
||||
node = minetest.get_node(pos)
|
||||
ndef = minetest.registered_nodes[node.name]
|
||||
if ndef.minecart_hopper_additem then
|
||||
if ndef and ndef.minecart_hopper_additem then
|
||||
return ndef.minecart_hopper_additem(pos, stack)
|
||||
end
|
||||
|
||||
@ -47,7 +47,7 @@ local function takeitem(mem)
|
||||
pos = {x = pos.x, y = pos.y - 1, z = pos.z}
|
||||
node = minetest.get_node(pos)
|
||||
ndef = minetest.registered_nodes[node.name]
|
||||
if ndef.minecart_hopper_takeitem then
|
||||
if ndef and ndef.minecart_hopper_takeitem then
|
||||
return ndef.minecart_hopper_takeitem(pos, 1)
|
||||
end
|
||||
end
|
||||
|
@ -20,8 +20,8 @@ signs_bot.version = 1.08
|
||||
-- Test for MT 5.4 new string mode
|
||||
signs_bot.CLIP = minetest.features.use_texture_alpha_string_modes and "clip" or true
|
||||
|
||||
if minetest.global_exists("techage") and techage.version < 0.25 then
|
||||
error("[signs_bot] Signs Bot requires techage version 0.25 or newer!")
|
||||
if minetest.global_exists("techage") and techage.version < 1.0 then
|
||||
error("[signs_bot] Signs Bot requires techage version 1.0 or newer!")
|
||||
end
|
||||
|
||||
if tubelib2.version < 1.9 then
|
||||
|
@ -188,7 +188,7 @@ register_command("end", 0,
|
||||
register_command("call", 1,
|
||||
function(base_pos, mem, addr)
|
||||
if #mem.Stack > 99 then
|
||||
return api.ERROR
|
||||
return api.ERROR, "call stack overrun"
|
||||
end
|
||||
mem.Stack[#mem.Stack + 1] = mem.pc + 2
|
||||
mem.pc = addr - 2
|
||||
@ -202,7 +202,7 @@ register_command("call", 1,
|
||||
register_command("return", 0,
|
||||
function(base_pos, mem)
|
||||
if #mem.Stack < 1 then
|
||||
return api.ERROR
|
||||
return api.ERROR, "no return address"
|
||||
end
|
||||
mem.pc = (mem.Stack[#mem.Stack] or 1) - 1
|
||||
mem.Stack[#mem.Stack] = nil
|
||||
|
@ -8,19 +8,33 @@
|
||||
GPLv3
|
||||
See LICENSE.txt for more information
|
||||
|
||||
Signs Bot: Bot Flap
|
||||
Signs Bot: interface for techage
|
||||
|
||||
]]--
|
||||
|
||||
-- Load support for I18n.
|
||||
local S = signs_bot.S
|
||||
|
||||
local CYCLE_TIME = 4
|
||||
local MAX_CAPA = signs_bot.MAX_CAPA
|
||||
local PWR_NEEDED = 8
|
||||
|
||||
if minetest.get_modpath("techage") then
|
||||
|
||||
local function on_power(pos)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
mem.power_available = true
|
||||
mem.charging = true
|
||||
signs_bot.infotext(pos, S("charging"))
|
||||
end
|
||||
|
||||
local function on_nopower(pos)
|
||||
local mem = tubelib2.get_mem(pos)
|
||||
mem.power_available = false
|
||||
signs_bot.infotext(pos, S("no power"))
|
||||
end
|
||||
|
||||
local Cable = techage.ElectricCable
|
||||
local power = techage.power
|
||||
local power = networks.power
|
||||
|
||||
signs_bot.register_inventory({"techage:chest_ta2", "techage:chest_ta3", "techage:chest_ta4",
|
||||
"techage:ta3_silo", "techage:ta4_silo", "techage:ta4_sensor_chest"}, {
|
||||
@ -164,12 +178,11 @@ send_cmnd 3465 pull*default:dirt*2]]),
|
||||
-- Bot in the box
|
||||
function signs_bot.while_charging(pos, mem)
|
||||
mem.capa = mem.capa or 0
|
||||
if mem.power_available then
|
||||
|
||||
if mem.capa < signs_bot.MAX_CAPA then
|
||||
local taken = power.consumer_alive(pos, Cable, CYCLE_TIME)
|
||||
mem.capa = mem.capa + taken
|
||||
local consumed = power.consume_power(pos, Cable, nil, PWR_NEEDED)
|
||||
mem.capa = mem.capa + consumed
|
||||
else
|
||||
power.consumer_stop(pos, Cable)
|
||||
minetest.get_node_timer(pos):stop()
|
||||
mem.charging = false
|
||||
if not mem.running then
|
||||
@ -177,13 +190,10 @@ send_cmnd 3465 pull*default:dirt*2]]),
|
||||
end
|
||||
return false
|
||||
end
|
||||
else
|
||||
power.consumer_start(pos, Cable, CYCLE_TIME)
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
Cable:add_secondary_node_names({"signs_bot:box"})
|
||||
power.register_nodes({"signs_bot:box"}, Cable, "con")
|
||||
|
||||
techage.register_node({"signs_bot:box"}, {
|
||||
on_inv_request = function(pos, in_dir, access_type)
|
||||
@ -267,8 +277,12 @@ send_cmnd 3465 pull*default:dirt*2]]),
|
||||
end,
|
||||
})
|
||||
|
||||
techage.register_node_for_v1_transition({"signs_bot:box"}, function(pos, node)
|
||||
power.update_network(pos, nil, Cable)
|
||||
end)
|
||||
else
|
||||
function signs_bot.formspec_battery_capa(max_capa, current_capa)
|
||||
return ""
|
||||
end
|
||||
end
|
||||
|
||||
|
662
ta4_addons/LICENSE.txt
Normal file
@ -0,0 +1,662 @@
|
||||
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
Version 3, 19 November 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU Affero General Public License is a free, copyleft license for
|
||||
software and other kinds of works, specifically designed to ensure
|
||||
cooperation with the community in the case of network server software.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
our General Public Licenses are intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
Developers that use our General Public Licenses protect your rights
|
||||
with two steps: (1) assert copyright on the software, and (2) offer
|
||||
you this License which gives you legal permission to copy, distribute
|
||||
and/or modify the software.
|
||||
|
||||
A secondary benefit of defending all users' freedom is that
|
||||
improvements made in alternate versions of the program, if they
|
||||
receive widespread use, become available for other developers to
|
||||
incorporate. Many developers of free software are heartened and
|
||||
encouraged by the resulting cooperation. However, in the case of
|
||||
software used on network servers, this result may fail to come about.
|
||||
The GNU General Public License permits making a modified version and
|
||||
letting the public access it on a server without ever releasing its
|
||||
source code to the public.
|
||||
|
||||
The GNU Affero General Public License is designed specifically to
|
||||
ensure that, in such cases, the modified source code becomes available
|
||||
to the community. It requires the operator of a network server to
|
||||
provide the source code of the modified version running there to the
|
||||
users of that server. Therefore, public use of a modified version, on
|
||||
a publicly accessible server, gives the public access to the source
|
||||
code of the modified version.
|
||||
|
||||
An older license, called the Affero General Public License and
|
||||
published by Affero, was designed to accomplish similar goals. This is
|
||||
a different license, not a version of the Affero GPL, but Affero has
|
||||
released a new version of the Affero GPL which permits relicensing under
|
||||
this license.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, if you modify the
|
||||
Program, your modified version must prominently offer all users
|
||||
interacting with it remotely through a computer network (if your version
|
||||
supports such interaction) an opportunity to receive the Corresponding
|
||||
Source of your version by providing access to the Corresponding Source
|
||||
from a network server at no charge, through some standard or customary
|
||||
means of facilitating copying of software. This Corresponding Source
|
||||
shall include the Corresponding Source for any work covered by version 3
|
||||
of the GNU General Public License that is incorporated pursuant to the
|
||||
following paragraph.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the work with which it is combined will remain governed by version
|
||||
3 of the GNU General Public License.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU Affero General Public License from time to time. Such new versions
|
||||
will be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU Affero General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU Affero General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU Affero General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If your software can interact with users remotely through a computer
|
||||
network, you should also make sure that it provides a way for users to
|
||||
get its source. For example, if your program is a web application, its
|
||||
interface could display a "Source" link that leads users to an archive
|
||||
of the code. There are many ways you could offer source, and different
|
||||
solutions will be better for different programs; see section 13 for the
|
||||
specific requirements.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
674
ta4_addons/LICENSE_GPL.txt
Normal file
@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
77
ta4_addons/README.md
Normal file
@ -0,0 +1,77 @@
|
||||
# ta4_addons
|
||||
|
||||
An extension mod for Minetest's [techage](https://github.com/joe7575/techage) mod to provide more TA4 devices.
|
||||
|
||||
Currently, the following devices are implemented:
|
||||
|
||||
- Touchscreen
|
||||
|
||||
## License
|
||||
|
||||
Copyright (C) 2020 Joachim Stolberg
|
||||
Copyright (C) 2020 Thomas-S
|
||||
|
||||
## Example Program for the Lua Controller
|
||||
|
||||
**Init:**
|
||||
|
||||
```lua
|
||||
$events(true)
|
||||
$loopcycle(0)
|
||||
|
||||
TOUCHSCREEN_NUM = 338
|
||||
|
||||
counter = 1
|
||||
|
||||
$send_cmnd(TOUCHSCREEN_NUM, "remove_content")
|
||||
|
||||
res = $send_cmnd(TOUCHSCREEN_NUM, "add_content", Store("type", "button", "w", 5, "label", counter))
|
||||
res2 = $send_cmnd(TOUCHSCREEN_NUM, "add_content", Store("type", "button", "w", 5, "y", 2, "label", counter))
|
||||
|
||||
$print("ID: "..res)
|
||||
```
|
||||
|
||||
**Loop:**
|
||||
|
||||
```lua
|
||||
local num,msg = $get_msg(true)
|
||||
|
||||
if num == tostring(TOUCHSCREEN_NUM) and msg.next then
|
||||
for k,v in msg.next() do
|
||||
if k == "button" then
|
||||
counter = counter + 1
|
||||
$print(res)
|
||||
$send_cmnd(TOUCHSCREEN_NUM, "update_content", Store("type", "button", "w", "5", "label", counter, "id", res))
|
||||
if counter > 10 then
|
||||
$send_cmnd(TOUCHSCREEN_NUM, "remove_content", Store("id", res2))
|
||||
else
|
||||
$send_cmnd(TOUCHSCREEN_NUM, "update_content", Store("type", "button", "w", "5", "y", 2, "label", counter, "id", res2))
|
||||
end
|
||||
end
|
||||
$print(k..": "..v)
|
||||
$display(TOUCHSCREEN_NUM, 0, k)
|
||||
$display(TOUCHSCREEN_NUM, 0, v)
|
||||
end
|
||||
end
|
||||
```
|
||||
|
||||
### Code
|
||||
Licensed under the GNU AGPL version 3 or later. See `LICENSE.txt`.
|
||||
|
||||
The only exception is the file `markdown2lua.py` (by Joachim Stolberg), which is licensed under the GNU GPL version 3 or later.
|
||||
See `LICENSE_GPL.txt`.
|
||||
It is taken from the [ta4_jetpack](https://github.com/joe7575/ta4_jetpack) mod.
|
||||
|
||||
### Textures
|
||||
|
||||
`ta4_addons_touchscreen.png`:
|
||||
Based on [techage_display.png](https://github.com/joe7575/techage/blob/master/textures/techage_display.png) by Joachim Stolberg, published under the CC BY-SA 3.0 license.
|
||||
Modifications were made by Thomas-S.
|
||||
|
||||
`ta4_addons_touchscreen_inventory.png`:
|
||||
Based on [techage_display_inventory.png](https://github.com/joe7575/techage/blob/master/textures/techage_display_inventory.png) by Joachim Stolberg, published under the CC BY-SA 3.0 license.
|
||||
Modifications were made by Thomas-S.
|
||||
|
||||
Everything else:
|
||||
CC BY-SA 3.0 by Thomas-S
|
||||
|
30
ta4_addons/init.lua
Normal file
@ -0,0 +1,30 @@
|
||||
--[[
|
||||
|
||||
TA4 Addons
|
||||
==========
|
||||
|
||||
Copyright (C) 2020 Joachim Stolberg
|
||||
Copyright (C) 2020 Thomas S.
|
||||
|
||||
GPL v3
|
||||
See LICENSE.txt for more information
|
||||
|
||||
]]--
|
||||
|
||||
ta4_addons = {}
|
||||
|
||||
-- Version for compatibility checks
|
||||
ta4_addons.version = 0.1
|
||||
|
||||
-- Load support for I18n.
|
||||
ta4_addons.S = minetest.get_translator("ta4_addons")
|
||||
|
||||
local MP = minetest.get_modpath("ta4_addons")
|
||||
|
||||
dofile(MP.."/touchscreen/main.lua") -- Touchscreen
|
||||
|
||||
dofile(MP.."/manual_DE.lua") -- Techage Manual DE
|
||||
dofile(MP.."/manual_EN.lua") -- Techage Manual EN
|
||||
|
||||
|
||||
techage.add_manual_items({ta4_addons_touchscreen = "ta4_addons_touchscreen_inventory.png"})
|
67
ta4_addons/manual_DE.lua
Normal file
@ -0,0 +1,67 @@
|
||||
techage.add_to_manual('DE', {
|
||||
"1,TA4 Addons",
|
||||
"2,Touchscreen",
|
||||
"3,Unterstützte Elemente und ihre Eigenschaften",
|
||||
}, {
|
||||
"Aktuell sind folgende Erweiterungen für TA4 verfügbar:\n"..
|
||||
"\n"..
|
||||
" - Touchscreen\n"..
|
||||
"\n",
|
||||
"\n"..
|
||||
"\n"..
|
||||
"Der Touchscreen kann wie ein normales TA 4 Display verwendet werden.\n"..
|
||||
"Zusätzlich werden folgende Befehle unterstützt\\, die es erlauben\\, ein Formular zu erstellen\\, das mittels Rechtsklick geöffnet werden kann:\n"..
|
||||
"\n"..
|
||||
" - add_content: Versucht\\, dem Touchscreen-Formular ein Element hinzuzufügen. Akzeptiert eine Element-Definition als Payload. Gibt im Erfolgsfall die ID des neu erstellten Elements zurück.\n"..
|
||||
" - update_content: Versucht\\, ein bereits bestehendes Element zu modifizieren. Akzeptiert eine Element-Definition mit einem zusätzlichem ID-Feld als Payload. Dieses ID-Feld wird verwendet\\, um das zu aktualisierende Element zu wählen. Gibt im Erfolgsfall true zurück.\n"..
|
||||
" - remove_content: Versucht\\, ein existierendes Element vom Touchscreen-Formular zu entfernen. Akzeptiert eine Store-Datenstruktur mit einem Feld \"id\" als Payload. Gibt im Erfolgsfall \"true\" zurück.\n"..
|
||||
" - private: Macht den Touchscreen privat. Nur Spieler mit Störschutz-Zugang können das Formular absenden.\n"..
|
||||
" - public: Macht den Touchscreen öffentlich. Alle Spieler können das Formular absenden.\n"..
|
||||
"\n"..
|
||||
"Eine Element-Definition ist eine \"Store\"-Datenstruktur. Der Element-Typ kann im \"type\"-Feld dieser Datenstruktur gesetzt werden.\n"..
|
||||
"Die Eigenschaften des entsprechenden Elements können als weitere Felder in der Store-Datenstruktur gesetzt werden.\n"..
|
||||
"Mehr oder weniger sinnvolle Standardwerte sind grundsätzlich für alle Eigenschaften gesetzt\\,\n"..
|
||||
"es wird aber dringend empfohlen\\, immer selbst die gewünschten Werte explizit zu übergeben\\, da die Standardwerte undokumentiert sind und sich ändern können.\n"..
|
||||
"\n"..
|
||||
"Wenn das Formular abgesendet wird\\, wird eine Store-Struktur an den Controller als Nachricht zurückgesandt.\n"..
|
||||
"Diese Datenstruktur beinhaltet alle Felder\\, die im on_receive_fields callback von Minetest verfügbar sind.\n"..
|
||||
"Zusätzlich ist im Feld \"_sent_by\" der Name des Absenders hinterlegt.\n"..
|
||||
"Mittels der Lua-Controller-Funktion $get_msg(true) kann auf diese Store-Struktur zugegriffen werden.\n"..
|
||||
"Der Wert \"true\" für den ersten Parameter darf dabei nicht vergessen werden\\; ansonsten wird nur die String-Repräsentation der Nachricht zurückgegeben.\n"..
|
||||
"\n"..
|
||||
"Das Formular wird mit der Formspec Version 3 angezeigt (real coordinates aktiviert). Es wird also dringend empfohlen\\, eine aktuelle Minetest Client-Version zu verwenden.\n"..
|
||||
"\n"..
|
||||
"Wenn der Touchscreen geöffnet wird\\, wird eine Nachricht an den Controller gesendet.\n"..
|
||||
"Diese Nachricht enthält einen Store\\, in dem das Feld \"_touchscreen_opened_by\" auf den jeweiligen Spielername gesetzt ist.\n"..
|
||||
"\n",
|
||||
"\n"..
|
||||
"\n"..
|
||||
"Bitte beachte: Diese Liste ist Gegenstand fortwährender Veränderung.\n"..
|
||||
"\n"..
|
||||
"button: x\\, y\\, w\\, h\\, name\\, label\n"..
|
||||
"label: x\\, y\\, label\n"..
|
||||
"image: x\\, y\\, w\\, h\\, texture_name\n"..
|
||||
"animated_image: x\\, y\\, w\\, h\\, name\\, texture_name\\, frame_count\\, frame_duration\\, frame_start\n"..
|
||||
"item_image: x\\, y\\, w\\, h\\, item_name\n"..
|
||||
"pwdfield: x\\, y\\, w\\, h\\, name\\, label\n"..
|
||||
"field: x\\, y\\, w\\, h\\, name\\, label\\, default\n"..
|
||||
"field_close_on_enter: name\\, close_on_enter\n"..
|
||||
"textarea: x\\, y\\, w\\, h\\, name\\, label\\, default\n"..
|
||||
"image_button: x\\, y\\, w\\, h\\, texture_name\\, name\\, label\n"..
|
||||
"item_image_button: x\\, y\\, w\\, h\\, item_name\\, name\\, label\n"..
|
||||
"button_exit: x\\, y\\, w\\, h\\, name\\, label\n"..
|
||||
"image_button_exit: x\\, y\\, w\\, h\\, texture_name\\, name\\, label\n"..
|
||||
"box: x\\, y\\, w\\, h\\, color\n"..
|
||||
"checkbox: x\\, y\\, name\\, label\\, selected\n"..
|
||||
"\n"..
|
||||
"Für weitere Informationen über die Bedeutung dieser Elemente sei die Datei lua_api.txt des Minetest-Projekts empfohlen.\n"..
|
||||
"\n",
|
||||
}, {
|
||||
"",
|
||||
"ta4_addons_touchscreen",
|
||||
"ta4_addons_touchscreen",
|
||||
}, {
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
})
|
57
ta4_addons/manual_DE.md
Normal file
@ -0,0 +1,57 @@
|
||||
# TA4 Addons
|
||||
|
||||
Aktuell sind folgende Erweiterungen für TA4 verfügbar:
|
||||
- Touchscreen
|
||||
|
||||
## Touchscreen
|
||||
|
||||
[ta4_addons_touchscreen|image]
|
||||
|
||||
Der Touchscreen kann wie ein normales TA 4 Display verwendet werden.
|
||||
Zusätzlich werden folgende Befehle unterstützt, die es erlauben, ein Formular zu erstellen, das mittels Rechtsklick geöffnet werden kann:
|
||||
|
||||
- add_content: Versucht, dem Touchscreen-Formular ein Element hinzuzufügen. Akzeptiert eine Element-Definition als Payload. Gibt im Erfolgsfall die ID des neu erstellten Elements zurück.
|
||||
- update_content: Versucht, ein bereits bestehendes Element zu modifizieren. Akzeptiert eine Element-Definition mit einem zusätzlichem ID-Feld als Payload. Dieses ID-Feld wird verwendet, um das zu aktualisierende Element zu wählen. Gibt im Erfolgsfall true zurück.
|
||||
- remove_content: Versucht, ein existierendes Element vom Touchscreen-Formular zu entfernen. Akzeptiert eine Store-Datenstruktur mit einem Feld "id" als Payload. Gibt im Erfolgsfall "true" zurück.
|
||||
- private: Macht den Touchscreen privat. Nur Spieler mit Störschutz-Zugang können das Formular absenden.
|
||||
- public: Macht den Touchscreen öffentlich. Alle Spieler können das Formular absenden.
|
||||
|
||||
Eine Element-Definition ist eine "Store"-Datenstruktur. Der Element-Typ kann im "type"-Feld dieser Datenstruktur gesetzt werden.
|
||||
Die Eigenschaften des entsprechenden Elements können als weitere Felder in der Store-Datenstruktur gesetzt werden.
|
||||
Mehr oder weniger sinnvolle Standardwerte sind grundsätzlich für alle Eigenschaften gesetzt,
|
||||
es wird aber dringend empfohlen, immer selbst die gewünschten Werte explizit zu übergeben, da die Standardwerte undokumentiert sind und sich ändern können.
|
||||
|
||||
Wenn das Formular abgesendet wird, wird eine Store-Struktur an den Controller als Nachricht zurückgesandt.
|
||||
Diese Datenstruktur beinhaltet alle Felder, die im on_receive_fields callback von Minetest verfügbar sind.
|
||||
Zusätzlich ist im Feld "_sent_by" der Name des Absenders hinterlegt.
|
||||
Mittels der Lua-Controller-Funktion $get_msg(true) kann auf diese Store-Struktur zugegriffen werden.
|
||||
Der Wert "true" für den ersten Parameter darf dabei nicht vergessen werden; ansonsten wird nur die String-Repräsentation der Nachricht zurückgegeben.
|
||||
|
||||
Das Formular wird mit der Formspec Version 3 angezeigt (real coordinates aktiviert). Es wird also dringend empfohlen, eine aktuelle Minetest Client-Version zu verwenden.
|
||||
|
||||
Wenn der Touchscreen geöffnet wird, wird eine Nachricht an den Controller gesendet.
|
||||
Diese Nachricht enthält einen Store, in dem das Feld "_touchscreen_opened_by" auf den jeweiligen Spielername gesetzt ist.
|
||||
|
||||
### Unterstützte Elemente und ihre Eigenschaften
|
||||
|
||||
[ta4_addons_touchscreen|image]
|
||||
|
||||
Bitte beachte: Diese Liste ist Gegenstand fortwährender Veränderung.
|
||||
|
||||
button: x, y, w, h, name, label
|
||||
label: x, y, label
|
||||
image: x, y, w, h, texture_name
|
||||
animated_image: x, y, w, h, name, texture_name, frame_count, frame_duration, frame_start
|
||||
item_image: x, y, w, h, item_name
|
||||
pwdfield: x, y, w, h, name, label
|
||||
field: x, y, w, h, name, label, default
|
||||
field_close_on_enter: name, close_on_enter
|
||||
textarea: x, y, w, h, name, label, default
|
||||
image_button: x, y, w, h, texture_name, name, label
|
||||
item_image_button: x, y, w, h, item_name, name, label
|
||||
button_exit: x, y, w, h, name, label
|
||||
image_button_exit: x, y, w, h, texture_name, name, label
|
||||
box: x, y, w, h, color
|
||||
checkbox: x, y, name, label, selected
|
||||
|
||||
Für weitere Informationen über die Bedeutung dieser Elemente sei die Datei lua_api.txt des Minetest-Projekts empfohlen.
|
67
ta4_addons/manual_EN.lua
Normal file
@ -0,0 +1,67 @@
|
||||
techage.add_to_manual('EN', {
|
||||
"1,TA4 Addons",
|
||||
"2,Touchscreen",
|
||||
"3,Supported Elements and their properties",
|
||||
}, {
|
||||
"Currently\\, the following extensions for TA4 are available:\n"..
|
||||
"\n"..
|
||||
" - Touchscreen\n"..
|
||||
"\n",
|
||||
"\n"..
|
||||
"\n"..
|
||||
"The touchscreen can be used like the normal TA 4 display.\n"..
|
||||
"Additionally\\, it supports the following commands\\, which allow to create a form that can be opened by right-clicking the touchscreen:\n"..
|
||||
"\n"..
|
||||
" - add_content: Tries to add an element to the touchscreen formspec. Takes an element definition as payload. Returns the ID of the newly created element on success.\n"..
|
||||
" - update_content: Tries to modify an already existing touchscreen formspec element. Takes an element definition with an additional id field\\, which can be used to choose the element to be updated. Returns true on success.\n"..
|
||||
" - remove_content: Tries to remove an existing element from the touchscreen formspec. Takes a Store as payload. The only field on this Store should be the id field. Returns true on success.\n"..
|
||||
" - private: Makes the touchscreen private. Only players with protection access can submit the form.\n"..
|
||||
" - public: Makes the touchscreen public. All players can submit the form.\n"..
|
||||
"\n"..
|
||||
"An element definition is a Store data structure. You can set the element type in the \"type\" field of this Store.\n"..
|
||||
"You can set properties for the element as further fields in this Store.\n"..
|
||||
"More or less reasonable default values are always provided for these additional properties\\,\n"..
|
||||
"but it is strongly suggested to always provide the values by yourself as the defaults are undocumented and subject to change.\n"..
|
||||
"\n"..
|
||||
"On formspec submit\\, a Store is sent back to the controller as message.\n"..
|
||||
"The fields as available in the Minetest on_receive_fields callbacks are set in this store.\n"..
|
||||
"The field \"_sent_by\" contains the sender's name.\n"..
|
||||
"You can access this store by using the $get_msg(true) function of the Lua Controller.\n"..
|
||||
"Please do not forget the \"true\" value as first parameter\\; otherwise you'll only get access to the string representation of the message.\n"..
|
||||
"\n"..
|
||||
"The form is rendered by using formspec version 3 (real coordinates enabled)\\, so please use a recent Minetest client version.\n"..
|
||||
"\n"..
|
||||
"When someone opens the touchscreen\\, a message will be sent to the controller.\n"..
|
||||
"This message contains a Store\\, in which the field \"_touchscreen_opened_by\" is set to the respective player name.\n"..
|
||||
"\n",
|
||||
"\n"..
|
||||
"\n"..
|
||||
"Please note: This list is subject to change.\n"..
|
||||
"\n"..
|
||||
"button: x\\, y\\, w\\, h\\, name\\, label\n"..
|
||||
"label: x\\, y\\, label\n"..
|
||||
"image: x\\, y\\, w\\, h\\, texture_name\n"..
|
||||
"animated_image: x\\, y\\, w\\, h\\, name\\, texture_name\\, frame_count\\, frame_duration\\, frame_start\n"..
|
||||
"item_image: x\\, y\\, w\\, h\\, item_name\n"..
|
||||
"pwdfield: x\\, y\\, w\\, h\\, name\\, label\n"..
|
||||
"field: x\\, y\\, w\\, h\\, name\\, label\\, default\n"..
|
||||
"field_close_on_enter: name\\, close_on_enter\n"..
|
||||
"textarea: x\\, y\\, w\\, h\\, name\\, label\\, default\n"..
|
||||
"image_button: x\\, y\\, w\\, h\\, texture_name\\, name\\, label\n"..
|
||||
"item_image_button: x\\, y\\, w\\, h\\, item_name\\, name\\, label\n"..
|
||||
"button_exit: x\\, y\\, w\\, h\\, name\\, label\n"..
|
||||
"image_button_exit: x\\, y\\, w\\, h\\, texture_name\\, name\\, label\n"..
|
||||
"box: x\\, y\\, w\\, h\\, color\n"..
|
||||
"checkbox: x\\, y\\, name\\, label\\, selected\n"..
|
||||
"\n"..
|
||||
"For further information of the meaning of these elements\\, please consult Minetest's lua_api.txt.\n"..
|
||||
"\n",
|
||||
}, {
|
||||
"",
|
||||
"ta4_addons_touchscreen",
|
||||
"ta4_addons_touchscreen",
|
||||
}, {
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
})
|
57
ta4_addons/manual_EN.md
Normal file
@ -0,0 +1,57 @@
|
||||
# TA4 Addons
|
||||
|
||||
Currently, the following extensions for TA4 are available:
|
||||
- Touchscreen
|
||||
|
||||
## Touchscreen
|
||||
|
||||
[ta4_addons_touchscreen|image]
|
||||
|
||||
The touchscreen can be used like the normal TA 4 display.
|
||||
Additionally, it supports the following commands, which allow to create a form that can be opened by right-clicking the touchscreen:
|
||||
|
||||
- add_content: Tries to add an element to the touchscreen formspec. Takes an element definition as payload. Returns the ID of the newly created element on success.
|
||||
- update_content: Tries to modify an already existing touchscreen formspec element. Takes an element definition with an additional id field, which can be used to choose the element to be updated. Returns true on success.
|
||||
- remove_content: Tries to remove an existing element from the touchscreen formspec. Takes a Store as payload. The only field on this Store should be the id field. Returns true on success.
|
||||
- private: Makes the touchscreen private. Only players with protection access can submit the form.
|
||||
- public: Makes the touchscreen public. All players can submit the form.
|
||||
|
||||
An element definition is a Store data structure. You can set the element type in the "type" field of this Store.
|
||||
You can set properties for the element as further fields in this Store.
|
||||
More or less reasonable default values are always provided for these additional properties,
|
||||
but it is strongly suggested to always provide the values by yourself as the defaults are undocumented and subject to change.
|
||||
|
||||
On formspec submit, a Store is sent back to the controller as message.
|
||||
The fields as available in the Minetest on_receive_fields callbacks are set in this store.
|
||||
The field "_sent_by" contains the sender's name.
|
||||
You can access this store by using the $get_msg(true) function of the Lua Controller.
|
||||
Please do not forget the "true" value as first parameter; otherwise you'll only get access to the string representation of the message.
|
||||
|
||||
The form is rendered by using formspec version 3 (real coordinates enabled), so please use a recent Minetest client version.
|
||||
|
||||
When someone opens the touchscreen, a message will be sent to the controller.
|
||||
This message contains a Store, in which the field "_touchscreen_opened_by" is set to the respective player name.
|
||||
|
||||
### Supported Elements and their properties
|
||||
|
||||
[ta4_addons_touchscreen|image]
|
||||
|
||||
Please note: This list is subject to change.
|
||||
|
||||
button: x, y, w, h, name, label
|
||||
label: x, y, label
|
||||
image: x, y, w, h, texture_name
|
||||
animated_image: x, y, w, h, name, texture_name, frame_count, frame_duration, frame_start
|
||||
item_image: x, y, w, h, item_name
|
||||
pwdfield: x, y, w, h, name, label
|
||||
field: x, y, w, h, name, label, default
|
||||
field_close_on_enter: name, close_on_enter
|
||||
textarea: x, y, w, h, name, label, default
|
||||
image_button: x, y, w, h, texture_name, name, label
|
||||
item_image_button: x, y, w, h, item_name, name, label
|
||||
button_exit: x, y, w, h, name, label
|
||||
image_button_exit: x, y, w, h, texture_name, name, label
|
||||
box: x, y, w, h, color
|
||||
checkbox: x, y, name, label, selected
|
||||
|
||||
For further information of the meaning of these elements, please consult Minetest's lua_api.txt.
|
203
ta4_addons/markdown2lua.py
Normal file
@ -0,0 +1,203 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (C) 2020 Joachim Stolberg
|
||||
# Licensed under the GNU GPL version 3 or later. See LICENSE_GPL.txt.
|
||||
# Apart from adding this copyright information comment, no further changes were made to this file.
|
||||
|
||||
import re
|
||||
import mistune # install v0.8.4 with: pip install mistune
|
||||
|
||||
__version__ = "1.0"
|
||||
|
||||
class WikiLinkInlineLexer(mistune.InlineLexer):
|
||||
def enable_wiki_link(self):
|
||||
# add wiki_link rules
|
||||
self.rules.wiki_link = re.compile(
|
||||
r'\[' # [
|
||||
r'([\s\S]+?\|[\s\S]+?)' # name| img-type
|
||||
r'\](?!\])' # ]
|
||||
)
|
||||
|
||||
# Add wiki_link parser to default rules
|
||||
# you can insert it some place you like
|
||||
# but place matters, maybe 3 is not good
|
||||
self.default_rules.insert(3, 'wiki_link')
|
||||
|
||||
def output_wiki_link(self, m):
|
||||
text = m.group(1)
|
||||
name, itype = text.split('|')
|
||||
# you can create an custom render
|
||||
# you can also return the html if you like
|
||||
return self.renderer.wiki_link(name, itype)
|
||||
|
||||
class MarkdownToLua(mistune.Renderer):
|
||||
def __init__(self, *args, **kwargs):
|
||||
mistune.Renderer.__init__(self, *args, **kwargs)
|
||||
self.item_name = ""
|
||||
self.plan_table = ""
|
||||
self.is_first_header = True
|
||||
self.text_chunck = []
|
||||
self.lTitle = []
|
||||
self.lText = []
|
||||
self.lItemName = []
|
||||
self.lPlanTable = []
|
||||
print("Markdown-to-Lua v%s" % __version__)
|
||||
|
||||
def m2l_formspec_escape(self, text):
|
||||
text = text.replace("\\", "")
|
||||
text = text.replace("[", "\\\\[")
|
||||
text = text.replace("]", "\\\\]")
|
||||
text = text.replace(";", "\\\\;")
|
||||
text = text.replace(",", "\\\\,")
|
||||
text = text.replace('"', '\\"')
|
||||
text = text.replace('\n', '\\n')
|
||||
return text
|
||||
|
||||
def m2l_add_last_paragraph(self):
|
||||
"""
|
||||
Used to add a text block before the next header or at the end of the document
|
||||
"""
|
||||
self.lText.append(self.text_chunck)
|
||||
self.text_chunck = []
|
||||
self.lItemName.append(self.item_name)
|
||||
self.item_name = ""
|
||||
self.lPlanTable.append(self.plan_table)
|
||||
self.plan_table = ""
|
||||
##
|
||||
## Block Level
|
||||
##
|
||||
def block_code(self, code, lang):
|
||||
text = self.m2l_formspec_escape(code.strip())
|
||||
lines = text.split("\n")
|
||||
lines = [" " + item for item in lines]
|
||||
self.text_chunck.extend(lines)
|
||||
self.text_chunck.append("")
|
||||
return ""
|
||||
|
||||
def header(self, text, level, raw=None):
|
||||
if not self.is_first_header:
|
||||
self.m2l_add_last_paragraph()
|
||||
self.is_first_header = False
|
||||
self.lTitle.append("%u,%s" % (level, self.m2l_formspec_escape(text)))
|
||||
return ""
|
||||
|
||||
def hrule(self):
|
||||
self.text_chunck.append("\n----------------------------------------------------\n")
|
||||
return ""
|
||||
|
||||
def paragraph(self, text):
|
||||
lines = text.split("\\n") + [""]
|
||||
self.text_chunck.extend(lines)
|
||||
return ""
|
||||
|
||||
def list(self, body, ordered=True):
|
||||
lines = body.split("\n")
|
||||
self.text_chunck.extend(lines)
|
||||
return ""
|
||||
|
||||
def list_item(self, text):
|
||||
return " - %s\n" % text.strip()
|
||||
##
|
||||
## Span Level
|
||||
##
|
||||
def emphasis(self, text):
|
||||
return "*%s*" % self.m2l_formspec_escape(text)
|
||||
|
||||
def double_emphasis(self, text):
|
||||
return "*%s*" % self.m2l_formspec_escape(text)
|
||||
|
||||
def codespan(self, text):
|
||||
return "'%s'" % self.m2l_formspec_escape(text)
|
||||
|
||||
def text(self, text):
|
||||
return self.m2l_formspec_escape(text)
|
||||
|
||||
def link(self, link, title, content):
|
||||
"""
|
||||
Used for plans and images:
|
||||
[myimage](/image/)
|
||||
[myplan](/plan/)
|
||||
"""
|
||||
if link == "/image/":
|
||||
self.item_name = content
|
||||
elif link == "/plan/":
|
||||
self.plan_table = content
|
||||
return ""
|
||||
|
||||
def wiki_link(self, name, itype):
|
||||
"""
|
||||
Used for plans and images:
|
||||
[myimage|image]
|
||||
[myplan|plan]
|
||||
"""
|
||||
if itype == "image":
|
||||
self.item_name = name
|
||||
elif itype == "plan":
|
||||
self.plan_table = name
|
||||
return ""
|
||||
|
||||
def autolink(self, link, is_email=False):
|
||||
return link
|
||||
|
||||
def linebreak(self):
|
||||
return "\\n"
|
||||
|
||||
def newline(self):
|
||||
return "\\n"
|
||||
|
||||
def inline_html(self, text):
|
||||
#print(text)
|
||||
pass
|
||||
|
||||
def parse_md_file(self, src_name):
|
||||
print(" - Read MD file '%s'" % src_name)
|
||||
inline = WikiLinkInlineLexer(self)
|
||||
# enable the feature
|
||||
inline.enable_wiki_link()
|
||||
md = mistune.Markdown(renderer=self, inline=inline)
|
||||
md.renderer.src_name = src_name
|
||||
md.render(open(src_name, 'r').read())
|
||||
md.renderer.m2l_add_last_paragraph()
|
||||
|
||||
def lua_table(self, lData):
|
||||
lOut = []
|
||||
lOut.append("{")
|
||||
for line in lData:
|
||||
lOut.append(' "%s",' % line)
|
||||
lOut.append("}")
|
||||
return "\n".join(lOut)
|
||||
|
||||
def lua_text_table(self, lData):
|
||||
lOut = []
|
||||
lOut.append("{")
|
||||
for lines in lData:
|
||||
for line in lines[:-1]:
|
||||
line = line.replace('<br>', '\\n')
|
||||
lOut.append(' "%s\\n"..' % line)
|
||||
if len(lines) > 0:
|
||||
lOut.append(' "%s\\n",' % lines[-1])
|
||||
else:
|
||||
lOut.append(' "",')
|
||||
lOut.append("}")
|
||||
return "\n".join(lOut)
|
||||
|
||||
def gen_lua_file(self, dest_name, language="EN"):
|
||||
print(" - Write Lua file '%s'" % dest_name)
|
||||
lOut = []
|
||||
s = ", ".join([self.lua_table(self.lTitle),
|
||||
self.lua_text_table(self.lText),
|
||||
self.lua_table(self.lItemName),
|
||||
self.lua_table(self.lPlanTable)])
|
||||
open(dest_name, "w").write("techage.add_to_manual('%s', %s)\n" % (language, s))
|
||||
print("done.")
|
||||
|
||||
|
||||
m2l = MarkdownToLua()
|
||||
m2l.parse_md_file("./manual_EN.md")
|
||||
m2l.gen_lua_file("./manual_EN.lua", "EN")
|
||||
|
||||
m2l = MarkdownToLua()
|
||||
m2l.parse_md_file("./manual_DE.md")
|
||||
m2l.gen_lua_file("./manual_DE.lua", "DE")
|
||||
|
3
ta4_addons/mod.conf
Normal file
@ -0,0 +1,3 @@
|
||||
name = ta4_addons
|
||||
depends = default,techage,lcdlib,safer_lua
|
||||
description = Addons for the TA4 age of Techage mod.
|
BIN
ta4_addons/textures/ta4_addons_touchscreen.png
Normal file
After Width: | Height: | Size: 98 B |
BIN
ta4_addons/textures/ta4_addons_touchscreen_inventory.png
Normal file
After Width: | Height: | Size: 211 B |
346
ta4_addons/touchscreen/main.lua
Normal file
@ -0,0 +1,346 @@
|
||||
--[[
|
||||
|
||||
TA4 Addons
|
||||
==========
|
||||
|
||||
Copyright (C) 2020 Joachim Stolberg
|
||||
Copyright (C) 2020 Thomas S.
|
||||
|
||||
AGPL v3
|
||||
See LICENSE.txt for more information
|
||||
|
||||
Touchscreen
|
||||
|
||||
]]--
|
||||
|
||||
local S = ta4_addons.S
|
||||
local M = minetest.get_meta
|
||||
local N = techage.get_nvm
|
||||
|
||||
local function get_value(element, key, default)
|
||||
return minetest.formspec_escape(element.get(key) or default)
|
||||
end
|
||||
|
||||
local function parse_payload(payload)
|
||||
local element_type = payload.get("type")
|
||||
if type(element_type) ~= "string" then
|
||||
return
|
||||
end
|
||||
element_type = string.lower(element_type)
|
||||
if element_type == "button" then
|
||||
local x = get_value(payload, "x", 1)
|
||||
local y = get_value(payload, "y", 1)
|
||||
local w = get_value(payload, "w", 2)
|
||||
local h = get_value(payload, "h", 1)
|
||||
local name = get_value(payload, "name", "button")
|
||||
local label = get_value(payload, "label", "Button")
|
||||
return "button["..x..","..y..";"..w..","..h..";"..name..";"..label.."]"
|
||||
elseif element_type == "label" then
|
||||
local x = get_value(payload, "x", 1)
|
||||
local y = get_value(payload, "y", 1)
|
||||
local label = get_value(payload, "label", "Label")
|
||||
return "label["..x..","..y..";"..label.."]"
|
||||
elseif element_type == "image" then
|
||||
local x = get_value(payload, "x", 1)
|
||||
local y = get_value(payload, "y", 1)
|
||||
local w = get_value(payload, "w", 1)
|
||||
local h = get_value(payload, "h", 1)
|
||||
local texture_name = get_value(payload, "texture_name", "default_apple.png")
|
||||
return "image["..x..","..y..";"..w..","..h..";"..texture_name.."]"
|
||||
elseif element_type == "animated_image" then
|
||||
local x = get_value(payload, "x", 1)
|
||||
local y = get_value(payload, "y", 1)
|
||||
local w = get_value(payload, "w", 1)
|
||||
local h = get_value(payload, "h", 1)
|
||||
local name = get_value(payload, "name", "animated_image")
|
||||
local texture_name = get_value(payload, "texture_name", "default_apple.png")
|
||||
local frame_count = get_value(payload, "frame_count", 1)
|
||||
local frame_duration = get_value(payload, "frame_duration", 1000)
|
||||
local frame_start = get_value(payload, "frame_start", 1)
|
||||
return "animated_image["..x..","..y..";"..w..","..h..";"..name..";"..texture_name..";"..frame_count..";"..frame_duration..";"..frame_start.."]"
|
||||
elseif element_type == "item_image" then
|
||||
local x = get_value(payload, "x", 1)
|
||||
local y = get_value(payload, "y", 1)
|
||||
local w = get_value(payload, "w", 1)
|
||||
local h = get_value(payload, "h", 1)
|
||||
local item_name = get_value(payload, "item_name", "default:apple")
|
||||
return "item_image["..x..","..y..";"..w..","..h..";"..item_name.."]"
|
||||
elseif element_type == "pwdfield" then
|
||||
local x = get_value(payload, "x", 1)
|
||||
local y = get_value(payload, "y", 1)
|
||||
local w = get_value(payload, "w", 2)
|
||||
local h = get_value(payload, "h", 1)
|
||||
local name = get_value(payload, "name", "pwdfield")
|
||||
local label = get_value(payload, "label", "Password")
|
||||
return "pwdfield["..x..","..y..";"..w..","..h..";"..name..";"..label.."]"
|
||||
elseif element_type == "field" then
|
||||
local x = get_value(payload, "x", 1)
|
||||
local y = get_value(payload, "y", 1)
|
||||
local w = get_value(payload, "w", 2)
|
||||
local h = get_value(payload, "h", 1)
|
||||
local name = get_value(payload, "name", "field")
|
||||
local label = get_value(payload, "label", "Input")
|
||||
local default = get_value(payload, "default", ""):gsub("%${", "$ {") -- To prevent reading metadata
|
||||
return "field["..x..","..y..";"..w..","..h..";"..name..";"..label..";"..default.."]"
|
||||
elseif element_type == "field_close_on_enter" then
|
||||
local name = get_value(payload, "name", "field")
|
||||
local close_on_enter = get_value(payload, "close_on_enter", "false")
|
||||
return "field_close_on_enter["..name..";"..close_on_enter"]"
|
||||
elseif element_type == "textarea" then
|
||||
local x = get_value(payload, "x", 1)
|
||||
local y = get_value(payload, "y", 1)
|
||||
local w = get_value(payload, "w", 2)
|
||||
local h = get_value(payload, "h", 1)
|
||||
local name = get_value(payload, "name", "")
|
||||
local label = get_value(payload, "label", "Textarea")
|
||||
local default = get_value(payload, "default", ""):gsub("%${", "$ {") -- To prevent reading metadata
|
||||
return "textarea["..x..","..y..";"..w..","..h..";"..name..";"..label..";"..default.."]"
|
||||
elseif element_type == "image_button" then
|
||||
local x = get_value(payload, "x", 1)
|
||||
local y = get_value(payload, "y", 1)
|
||||
local w = get_value(payload, "w", 1)
|
||||
local h = get_value(payload, "h", 1)
|
||||
local texture_name = get_value(payload, "texture_name", "default_apple.png")
|
||||
local name = get_value(payload, "name", "image_button")
|
||||
local label = get_value(payload, "label", "")
|
||||
return "image_button["..x..","..y..";"..w..","..h..";"..texture_name..";"..name..";"..label.."]"
|
||||
elseif element_type == "item_image_button" then
|
||||
local x = get_value(payload, "x", 1)
|
||||
local y = get_value(payload, "y", 1)
|
||||
local w = get_value(payload, "w", 1)
|
||||
local h = get_value(payload, "h", 1)
|
||||
local item_name = get_value(payload, "item_name", "default:apple")
|
||||
local name = get_value(payload, "name", "item_image_button")
|
||||
local label = get_value(payload, "label", "")
|
||||
return "item_image_button["..x..","..y..";"..w..","..h..";"..item_name..";"..name..";"..label.."]"
|
||||
elseif element_type == "button_exit" then
|
||||
local x = get_value(payload, "x", 1)
|
||||
local y = get_value(payload, "y", 1)
|
||||
local w = get_value(payload, "w", 2)
|
||||
local h = get_value(payload, "h", 1)
|
||||
local name = get_value(payload, "name", "button_exit")
|
||||
local label = get_value(payload, "label", "Exit Button")
|
||||
return "button_exit["..x..","..y..";"..w..","..h..";"..name..";"..label.."]"
|
||||
elseif element_type == "image_button_exit" then
|
||||
local x = get_value(payload, "x", 1)
|
||||
local y = get_value(payload, "y", 1)
|
||||
local w = get_value(payload, "w", 1)
|
||||
local h = get_value(payload, "h", 1)
|
||||
local texture_name = get_value(payload, "texture_name", "creative_clear_icon.png")
|
||||
local name = get_value(payload, "name", "image_button")
|
||||
local label = get_value(payload, "label", "")
|
||||
return "image_button_exit["..x..","..y..";"..w..","..h..";"..texture_name..";"..name..";"..label.."]"
|
||||
elseif element_type == "box" then
|
||||
local x = get_value(payload, "x", 1)
|
||||
local y = get_value(payload, "y", 1)
|
||||
local w = get_value(payload, "w", 2)
|
||||
local h = get_value(payload, "h", 1)
|
||||
local color = get_value(payload, "color", "")
|
||||
return "box["..x..","..y..";"..w..","..h..";"..color.."]"
|
||||
elseif element_type == "checkbox" then
|
||||
local x = get_value(payload, "x", 1)
|
||||
local y = get_value(payload, "y", 1)
|
||||
local name = get_value(payload, "name", "checkbox")
|
||||
local label = get_value(payload, "label", "")
|
||||
local selected = get_value(payload, "selected", "false")
|
||||
return "checkbox["..x..","..y..";"..name..";"..label..";"..selected.."]"
|
||||
end
|
||||
end
|
||||
|
||||
local function next_id(pos)
|
||||
local nvm = N(pos)
|
||||
local id = (nvm.element_id or 0) + 1
|
||||
nvm.element_id = id
|
||||
return id
|
||||
end
|
||||
|
||||
local function reset_id(pos)
|
||||
N(pos).element_id = 0
|
||||
end
|
||||
|
||||
local function get_elements(pos)
|
||||
local nvm = N(pos)
|
||||
nvm.elements = nvm.elements or {}
|
||||
return nvm.elements
|
||||
end
|
||||
|
||||
local function valid_payload(payload)
|
||||
if not payload then return false end
|
||||
if not type(payload) == "table" then return false end
|
||||
if not payload.get then return false end
|
||||
if not payload.next then return false end
|
||||
return true
|
||||
end
|
||||
|
||||
local function update_fs(pos)
|
||||
local meta = M(pos)
|
||||
local fs = "formspec_version[3]"
|
||||
fs = fs .. "size[10,10]"
|
||||
local elements = get_elements(pos)
|
||||
for _,ele in ipairs(elements) do
|
||||
fs = fs .. ele
|
||||
end
|
||||
meta:set_string("formspec", fs)
|
||||
end
|
||||
|
||||
local function add_content(pos, payload)
|
||||
if not valid_payload(payload) then
|
||||
return
|
||||
end
|
||||
local element = parse_payload(payload)
|
||||
if not element then
|
||||
return
|
||||
end
|
||||
local elements = get_elements(pos)
|
||||
local id = next_id(pos)
|
||||
elements[id] = element
|
||||
update_fs(pos)
|
||||
return id
|
||||
end
|
||||
|
||||
local function update_content(pos, payload)
|
||||
if not valid_payload(payload) then
|
||||
return false
|
||||
end
|
||||
local id = payload.get("id")
|
||||
local elements = get_elements(pos)
|
||||
if not id or not elements[id] then
|
||||
return false
|
||||
end
|
||||
local element = parse_payload(payload)
|
||||
if not element then
|
||||
return false
|
||||
end
|
||||
elements[id] = element
|
||||
update_fs(pos)
|
||||
return true
|
||||
end
|
||||
|
||||
local function remove_content(pos, payload)
|
||||
if valid_payload(payload) then
|
||||
local id = payload.get("id")
|
||||
if id then
|
||||
local elements = get_elements(pos)
|
||||
if not elements[id] then
|
||||
return false
|
||||
end
|
||||
elements[id] = nil
|
||||
update_fs(pos)
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
local nvm = techage.get_nvm(pos)
|
||||
nvm.elements = {}
|
||||
nvm.element_id = nil
|
||||
update_fs(pos)
|
||||
return true
|
||||
end
|
||||
|
||||
minetest.register_node("ta4_addons:touchscreen", {
|
||||
description = S("TA4 Display"),
|
||||
inventory_image = "ta4_addons_touchscreen_inventory.png",
|
||||
tiles = {"ta4_addons_touchscreen.png"},
|
||||
drawtype = "nodebox",
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
paramtype2 = "wallmounted",
|
||||
node_box = techage.display.lcd_box,
|
||||
selection_box = techage.display.lcd_box,
|
||||
light_source = 6,
|
||||
|
||||
display_entities = {
|
||||
["techage:display_entity"] = {
|
||||
depth = 0.42,
|
||||
on_display_update = techage.display.display_update
|
||||
},
|
||||
},
|
||||
|
||||
after_place_node = function(pos, placer)
|
||||
local number = techage.add_node(pos, "ta4_addons:touchscreen")
|
||||
local meta = M(pos)
|
||||
meta:set_string("node_number", number)
|
||||
meta:set_string("infotext", S("Touchscreen no: ")..number)
|
||||
update_fs(pos)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
nvm.text = {"My", "Techage","TA4", "Touchscreen", "No: "..number}
|
||||
lcdlib.update_entities(pos)
|
||||
minetest.get_node_timer(pos):start(1)
|
||||
end,
|
||||
|
||||
after_dig_node = function(pos, oldnode, oldmetadata)
|
||||
remove_content(pos)
|
||||
techage.remove_node(pos, oldnode, oldmetadata)
|
||||
end,
|
||||
|
||||
on_rightclick = function(pos, node, clicker)
|
||||
local meta = M(pos)
|
||||
local ctrl = meta:get_string("ctrl")
|
||||
if ctrl then
|
||||
local own_num = meta:get_string("node_number") or ""
|
||||
techage.send_single(own_num, ctrl, "msg", safer_lua.Store("_touchscreen_opened_by", clicker:get_player_name()))
|
||||
end
|
||||
end,
|
||||
|
||||
on_receive_fields = function(pos, formname, fields, sender)
|
||||
local meta = M(pos)
|
||||
local player_name = sender:get_player_name()
|
||||
if meta:get_string("public") ~= "true" and minetest.is_protected(pos, player_name) then
|
||||
return
|
||||
end
|
||||
local fields_store = safer_lua.Store()
|
||||
for k,v in pairs(fields) do
|
||||
fields_store.set(k, v)
|
||||
end
|
||||
fields_store.set("_sent_by", player_name)
|
||||
local ctrl = meta:get_string("ctrl")
|
||||
if ctrl then
|
||||
local own_num = meta:get_string("node_number") or ""
|
||||
techage.send_single(own_num, ctrl, "msg", fields_store)
|
||||
end
|
||||
end,
|
||||
|
||||
on_timer = techage.display.on_timer,
|
||||
on_place = lcdlib.on_place,
|
||||
on_construct = lcdlib.on_construct,
|
||||
on_destruct = lcdlib.on_destruct,
|
||||
on_rotate = lcdlib.on_rotate,
|
||||
groups = {cracky=2, crumbly=2},
|
||||
is_ground_content = false,
|
||||
sounds = default.node_sound_glass_defaults(),
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "ta4_addons:touchscreen",
|
||||
recipe = {
|
||||
{"", "dye:blue", ""},
|
||||
{"default:copper_ingot", "techage:ta4_display", "default:copper_ingot"},
|
||||
{"", "default:mese_crystal_fragment", ""},
|
||||
},
|
||||
})
|
||||
|
||||
techage.register_node({"ta4_addons:touchscreen"}, {
|
||||
on_recv_message = function(pos, src, topic, payload)
|
||||
if topic == "add" then -- add one line and scroll if necessary
|
||||
techage.display.add_line(pos, payload, 1)
|
||||
elseif topic == "set" then -- overwrite the given row
|
||||
techage.display.write_row(pos, payload, 1)
|
||||
elseif topic == "clear" then -- clear the screen
|
||||
techage.display.clear_screen(pos, 1)
|
||||
elseif topic == "add_content" then
|
||||
M(pos):set_string("ctrl", src)
|
||||
return add_content(pos, payload)
|
||||
elseif topic == "update_content" then
|
||||
M(pos):set_string("ctrl", src)
|
||||
return update_content(pos, payload)
|
||||
elseif topic == "remove_content" then
|
||||
M(pos):set_string("ctrl", src)
|
||||
return remove_content(pos, payload)
|
||||
elseif topic == "private" then
|
||||
M(pos):set_string("public", "false")
|
||||
elseif topic == "public" then
|
||||
M(pos):set_string("public", "true")
|
||||
end
|
||||
end,
|
||||
})
|
@ -13,6 +13,8 @@
|
||||
-- Load support for I18n.
|
||||
local S = minetest.get_translator("ta4_jetpack")
|
||||
|
||||
local liquid = networks.liquid
|
||||
|
||||
local ta4_jetpack = {}
|
||||
|
||||
local Players = {}
|
||||
@ -321,25 +323,27 @@ local function load_fuel(itemstack, user, pointed_thing)
|
||||
local pos = pointed_thing.under
|
||||
if pos then
|
||||
local name = user:get_player_name()
|
||||
local nvm = techage.get_nvm(pos)
|
||||
-- check jetpack
|
||||
if not Jetpacks[name] then
|
||||
minetest.chat_send_player(name, S("[Jetpack] You don't have your jetpack on your back!"))
|
||||
return itemstack
|
||||
end
|
||||
if techage.liquid.srv_peek(pos, 5) == "techage:hydrogen" then
|
||||
if name and liquid.srv_peek(nvm) == "techage:hydrogen" then
|
||||
local value = get_fuel_value(name)
|
||||
local newvalue
|
||||
|
||||
if user:get_player_control().sneak then -- back to tank?
|
||||
local amount = math.min(value, FUEL_UNIT)
|
||||
local rest = techage.liquid.srv_put(pos, 5, "techage:hydrogen", amount)
|
||||
local rest = liquid.srv_put(nvm, "techage:hydrogen", amount, MAX_FUEL)
|
||||
newvalue = value - amount + rest
|
||||
else
|
||||
local amount = math.min(FUEL_UNIT, MAX_FUEL - value)
|
||||
local taken = techage.liquid.srv_take(pos, 5, "techage:hydrogen", amount)
|
||||
local taken = liquid.srv_take(nvm, "techage:hydrogen", amount)
|
||||
newvalue = value + taken
|
||||
end
|
||||
set_fuel_value(name, newvalue)
|
||||
minetest.chat_send_player(name, S("[Jetpack]") .. ": " .. newvalue .. "/" .. MAX_FUEL)
|
||||
end
|
||||
end
|
||||
return itemstack
|
||||
|
@ -3,7 +3,7 @@
|
||||
TechAge
|
||||
=======
|
||||
|
||||
Copyright (C) 2019-2020 Joachim Stolberg
|
||||
Copyright (C) 2019-2021 Joachim Stolberg
|
||||
|
||||
GPL v3
|
||||
See LICENSE.txt for more information
|
||||
@ -21,7 +21,8 @@ local PWR_NEEDED = 5
|
||||
local CYCLE_TIME = 2
|
||||
|
||||
local Cable = techage.ElectricCable
|
||||
local power = techage.power
|
||||
--local Cable = techage.Axle
|
||||
local power = networks.power
|
||||
|
||||
local function swap_node(pos, name)
|
||||
local node = techage.get_node_lvm(pos)
|
||||
@ -32,39 +33,18 @@ local function swap_node(pos, name)
|
||||
minetest.swap_node(pos, node)
|
||||
end
|
||||
|
||||
local function on_power(pos)
|
||||
--print("on_power sink "..P2S(pos))
|
||||
swap_node(pos, "techage:sink_on")
|
||||
M(pos):set_string("infotext", "on")
|
||||
end
|
||||
|
||||
local function on_nopower(pos)
|
||||
--print("on_nopower sink "..P2S(pos))
|
||||
swap_node(pos, "techage:sink")
|
||||
M(pos):set_string("infotext", "off")
|
||||
end
|
||||
|
||||
local function node_timer(pos, elapsed)
|
||||
--print("node_timer sink "..P2S(pos))
|
||||
local nvm = techage.get_nvm(pos)
|
||||
power.consumer_alive(pos, Cable, CYCLE_TIME)
|
||||
return true
|
||||
end
|
||||
|
||||
local function on_rightclick(pos, node, clicker)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
if not nvm.running and power.power_available(pos, Cable) then
|
||||
nvm.running = true
|
||||
-- swap will be performed via on_power()
|
||||
power.consumer_start(pos, Cable, CYCLE_TIME)
|
||||
swap_node(pos, "techage:sink_on")
|
||||
M(pos):set_string("infotext", "on")
|
||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||
M(pos):set_string("infotext", "...")
|
||||
else
|
||||
nvm.running = false
|
||||
swap_node(pos, "techage:sink")
|
||||
power.consumer_stop(pos, Cable)
|
||||
minetest.get_node_timer(pos):stop()
|
||||
M(pos):set_string("infotext", "off")
|
||||
minetest.get_node_timer(pos):stop()
|
||||
end
|
||||
end
|
||||
|
||||
@ -79,30 +59,21 @@ local function after_dig_node(pos, oldnode)
|
||||
techage.del_mem(pos)
|
||||
end
|
||||
|
||||
local function tubelib2_on_update2(pos, outdir, tlib2, node)
|
||||
power.update_network(pos, outdir, tlib2)
|
||||
end
|
||||
|
||||
local net_def = {
|
||||
ele1 = {
|
||||
sides = techage.networks.AllSides, -- Cable connection sides
|
||||
ntype = "con1",
|
||||
on_power = on_power,
|
||||
on_nopower = on_nopower,
|
||||
nominal = PWR_NEEDED,
|
||||
},
|
||||
}
|
||||
|
||||
minetest.register_node("techage:sink", {
|
||||
description = "Sink",
|
||||
tiles = {'techage_electric_button.png'},
|
||||
tiles = {'techage_electric_button.png^[colorize:#000000:50'},
|
||||
|
||||
on_timer = node_timer,
|
||||
on_timer = function(pos, elapsed)
|
||||
local consumed = power.consume_power(pos, Cable, nil, PWR_NEEDED)
|
||||
if consumed == PWR_NEEDED then
|
||||
swap_node(pos, "techage:sink_on")
|
||||
M(pos):set_string("infotext", "on")
|
||||
end
|
||||
return true
|
||||
end,
|
||||
on_rightclick = on_rightclick,
|
||||
after_place_node = after_place_node,
|
||||
after_dig_node = after_dig_node,
|
||||
tubelib2_on_update2 = tubelib2_on_update2,
|
||||
networks = net_def,
|
||||
|
||||
paramtype = "light",
|
||||
light_source = 0,
|
||||
@ -116,12 +87,17 @@ minetest.register_node("techage:sink_on", {
|
||||
description = "Sink",
|
||||
tiles = {'techage_electric_button.png'},
|
||||
|
||||
on_timer = node_timer,
|
||||
on_timer = function(pos, elapsed)
|
||||
local consumed = power.consume_power(pos, Cable, nil, PWR_NEEDED)
|
||||
if consumed < PWR_NEEDED then
|
||||
swap_node(pos, "techage:sink")
|
||||
M(pos):set_string("infotext", "off")
|
||||
end
|
||||
return true
|
||||
end,
|
||||
on_rightclick = on_rightclick,
|
||||
after_place_node = after_place_node,
|
||||
after_dig_node = after_dig_node,
|
||||
tubelib2_on_update2 = tubelib2_on_update2,
|
||||
networks = net_def,
|
||||
|
||||
paramtype = "light",
|
||||
light_source = minetest.LIGHT_MAX,
|
||||
@ -133,5 +109,4 @@ minetest.register_node("techage:sink_on", {
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
})
|
||||
|
||||
Cable:add_secondary_node_names({"techage:sink", "techage:sink_on"})
|
||||
|
||||
power.register_nodes({"techage:sink", "techage:sink_on"}, Cable, "con")
|
||||
|
@ -31,11 +31,11 @@ Copyright (C) 2019-2021 Joachim Stolberg
|
||||
Code: Licensed under the GNU AGPL version 3 or later. See LICENSE.txt
|
||||
Textures: CC BY-SA 3.0
|
||||
|
||||
Many thanks to Thomas-S for his contributions
|
||||
Many thanks to Thomas-S and others for their contributions
|
||||
|
||||
|
||||
### Dependencies
|
||||
Required: default, doors, bucket, stairs, screwdriver, basic_materials, tubelib2, minecart, lcdlib, safer_lua
|
||||
Required: default, doors, bucket, stairs, screwdriver, basic_materials, tubelib2, networks, minecart, lcdlib, safer_lua
|
||||
Recommended: signs_bot, hyperloop, compost, techpack_stairway, autobahn
|
||||
Optional: unified_inventory, wielded_light, unifieddyes, lua-mashal, lsqlite3, moreores, ethereal, mesecon
|
||||
|
||||
@ -46,6 +46,7 @@ The mods `default`, `doors`, `bucket`, `stairs`, and `screwdriver` are part of M
|
||||
|
||||
The following mods in the newest version have to be downloaded directly from GitHub:
|
||||
* [tubelib2](https://github.com/joe7575/tubelib2)
|
||||
* [networks](https://github.com/joe7575/networks)
|
||||
* [minecart](https://github.com/joe7575/minecart)
|
||||
* [lcdlib](https://github.com/joe7575/lcdlib)
|
||||
* [safer_lua](https://github.com/joe7575/safer_lua)
|
||||
@ -77,7 +78,16 @@ Available worlds will be converted to 'lsqlite3', but there is no way back, so:
|
||||
|
||||
### History
|
||||
|
||||
**2021-05-14 V0.25**
|
||||
**2021-07-23 V1.00**
|
||||
- Change the way, power distribution works
|
||||
- Add TA2 storage system
|
||||
- Add TA4 Isolation Transformer
|
||||
- Add TA4 Electric Meter
|
||||
- Add new power terminal
|
||||
- Many improvements on power producing/consuming nodes
|
||||
- See Construction Board for some hints on moving to v1
|
||||
|
||||
**2021-05-14 V0.26**
|
||||
- Add concentrator tubes
|
||||
- Add ta4 cable wall entry
|
||||
- Pull request #57: Distributor improvements (from Thomas-S)
|
||||
|
@ -430,3 +430,9 @@ minetest.register_craft({
|
||||
},
|
||||
})
|
||||
|
||||
local Cable = techage.ElectricCable
|
||||
local power = networks.power
|
||||
|
||||
techage.register_node_for_v1_transition({"techage:ta3_autocrafter_pas"}, function(pos, node)
|
||||
power.update_network(pos, nil, Cable)
|
||||
end)
|
@ -14,7 +14,7 @@
|
||||
|
||||
local S = techage.S
|
||||
local Pipe = techage.LiquidPipe
|
||||
local liquid = techage.liquid
|
||||
local liquid = networks.liquid
|
||||
|
||||
local function take_liquid(pos, indir, name, amount)
|
||||
return 0, name
|
||||
@ -28,13 +28,6 @@ local function peek_liquid(pos, indir)
|
||||
return nil
|
||||
end
|
||||
|
||||
local networks_def = {
|
||||
pipe2 = {
|
||||
sides = {R=1}, -- Pipe connection sides
|
||||
ntype = "tank",
|
||||
},
|
||||
}
|
||||
|
||||
minetest.register_node("techage:blackhole", {
|
||||
description = S("TechAge Black Hole"),
|
||||
tiles = {
|
||||
@ -57,22 +50,12 @@ minetest.register_node("techage:blackhole", {
|
||||
after_dig_node = function(pos, oldnode)
|
||||
Pipe:after_dig_node(pos)
|
||||
end,
|
||||
tubelib2_on_update2 = function(pos, outdir, tlib2, node)
|
||||
liquid.update_network(pos, outdir)
|
||||
end,
|
||||
|
||||
on_rotate = screwdriver.disallow,
|
||||
paramtype2 = "facedir",
|
||||
groups = {choppy=2, cracky=2, crumbly=2},
|
||||
is_ground_content = false,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
liquid = {
|
||||
capa = 999999,
|
||||
peek = peek_liquid,
|
||||
put = put_liquid,
|
||||
take = take_liquid,
|
||||
},
|
||||
networks = networks_def,
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
@ -96,4 +79,11 @@ techage.register_node({"techage:blackhole"}, {
|
||||
end,
|
||||
})
|
||||
|
||||
Pipe:add_secondary_node_names({"techage:blackhole"})
|
||||
liquid.register_nodes({"techage:blackhole"},
|
||||
Pipe, "tank", {"R"}, {
|
||||
capa = 9999999,
|
||||
peek = peek_liquid,
|
||||
put = put_liquid,
|
||||
take = take_liquid,
|
||||
}
|
||||
)
|
||||
|
@ -16,6 +16,8 @@
|
||||
local M = minetest.get_meta
|
||||
local S = techage.S
|
||||
|
||||
local TA4_INV_SIZE = 50
|
||||
|
||||
local MP = minetest.get_modpath(minetest.get_current_modname())
|
||||
local mConf = dofile(MP.."/basis/conf_inv.lua")
|
||||
|
||||
@ -345,21 +347,15 @@ techage.register_node({"techage:chest_ta4"}, {
|
||||
local inv = meta:get_inventory()
|
||||
local mem = techage.get_mem(pos)
|
||||
|
||||
mem.filter = mem.filter or mConf.item_filter(pos, 50)
|
||||
mem.chest_configured = mem.chest_configured or
|
||||
not mem.filter["unconfigured"] or #mem.filter["unconfigured"] < 50
|
||||
mem.filter = mem.filter or mConf.item_filter(pos, TA4_INV_SIZE)
|
||||
mem.chest_configured = mem.chest_configured or not inv:is_empty("conf")
|
||||
|
||||
if inv:is_empty("main") then
|
||||
return nil
|
||||
end
|
||||
|
||||
if item_name then
|
||||
if mem.filter[item_name] then -- configured item
|
||||
local taken = inv:remove_item("main", {name = item_name, count = num})
|
||||
if taken:get_count() > 0 then
|
||||
return taken
|
||||
end
|
||||
elseif not mem.chest_configured then
|
||||
if mem.filter[item_name] or not mem.chest_configured then
|
||||
local taken = inv:remove_item("main", {name = item_name, count = num})
|
||||
if taken:get_count() > 0 then
|
||||
return taken
|
||||
@ -367,7 +363,7 @@ techage.register_node({"techage:chest_ta4"}, {
|
||||
end
|
||||
else -- no item given
|
||||
if mem.chest_configured then
|
||||
return mConf.take_item(pos, inv, "main", num, mem.filter["unconfigured"] or {})
|
||||
return mConf.take_item(pos, inv, "main", num, mem.filter["unconfigured"])
|
||||
else
|
||||
return techage.get_items(pos, inv, "main", num)
|
||||
end
|
||||
@ -378,9 +374,8 @@ techage.register_node({"techage:chest_ta4"}, {
|
||||
local inv = meta:get_inventory()
|
||||
local mem = techage.get_mem(pos)
|
||||
|
||||
mem.filter = mem.filter or mConf.item_filter(pos, 50)
|
||||
mem.chest_configured = mem.chest_configured or
|
||||
not mem.filter["unconfigured"] or #mem.filter["unconfigured"] < 50
|
||||
mem.filter = mem.filter or mConf.item_filter(pos, TA4_INV_SIZE)
|
||||
mem.chest_configured = mem.chest_configured or not inv:is_empty("conf")
|
||||
|
||||
if mem.chest_configured then
|
||||
local name = item:get_name()
|
||||
@ -395,9 +390,8 @@ techage.register_node({"techage:chest_ta4"}, {
|
||||
local inv = meta:get_inventory()
|
||||
local mem = techage.get_mem(pos)
|
||||
|
||||
mem.filter = mem.filter or mConf.item_filter(pos, 50)
|
||||
mem.chest_configured = mem.chest_configured or
|
||||
not mem.filter["unconfigured"] or #mem.filter["unconfigured"] < 50
|
||||
mem.filter = mem.filter or mConf.item_filter(pos, TA4_INV_SIZE)
|
||||
mem.chest_configured = mem.chest_configured or not inv:is_empty("conf")
|
||||
|
||||
if mem.chest_configured then
|
||||
local name = item:get_name()
|
||||
|
@ -16,7 +16,6 @@
|
||||
local M = minetest.get_meta
|
||||
local S = techage.S
|
||||
|
||||
local networks = techage.networks
|
||||
local Tube = techage.Tube
|
||||
|
||||
local size = 2/8
|
||||
@ -29,7 +28,7 @@ local Boxes = {
|
||||
{{-size, -size, -size, size, 0.5, size}}, -- y+
|
||||
}
|
||||
|
||||
local names = techage.register_junction("techage:concentrator", 2/8, Boxes, Tube, {
|
||||
local names = networks.register_junction("techage:concentrator", 2/8, Boxes, Tube, {
|
||||
description = S("Tube Concentrator"),
|
||||
tiles = {
|
||||
"techage_tube_junction.png^techage_appl_arrow2.png^[transformR270",
|
||||
@ -40,18 +39,19 @@ local names = techage.register_junction("techage:concentrator", 2/8, Boxes, Tube
|
||||
"techage_tube_junction.png^techage_appl_arrow2.png^[transformR270",
|
||||
},
|
||||
paramtype2 = "facedir", -- important!
|
||||
use_texture_alpha = techage.CLIP,
|
||||
groups = {snappy = 2, choppy = 2, oddly_breakable_by_hand = 3, techage_trowel = 1},
|
||||
sounds = default.node_sound_defaults(),
|
||||
|
||||
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
||||
local node = minetest.get_node(pos)
|
||||
local name = "techage:concentrator"..techage.junction_type(pos, Tube, "R", node.param2)
|
||||
local name = "techage:concentrator"..networks.junction_type(pos, Tube, "R", node.param2)
|
||||
minetest.swap_node(pos, {name = name, param2 = node.param2})
|
||||
M(pos):set_int("push_dir", techage.side_to_outdir("R", node.param2))
|
||||
Tube:after_place_node(pos)
|
||||
end,
|
||||
tubelib2_on_update2 = function(pos, dir1, tlib2, node)
|
||||
local name = "techage:concentrator"..techage.junction_type(pos, Tube, "R", node.param2)
|
||||
local name = "techage:concentrator"..networks.junction_type(pos, Tube, "R", node.param2)
|
||||
minetest.swap_node(pos, {name = name, param2 = node.param2})
|
||||
end,
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
@ -67,7 +67,7 @@ techage.register_node(names, {
|
||||
is_pusher = true, -- is a pulling/pushing node
|
||||
})
|
||||
|
||||
names = techage.register_junction("techage:ta4_concentrator", 2/8, Boxes, Tube, {
|
||||
names = networks.register_junction("techage:ta4_concentrator", 2/8, Boxes, Tube, {
|
||||
description = S("TA4 Tube Concentrator"),
|
||||
tiles = {
|
||||
"techage_tubeta4_junction.png^techage_appl_arrow2.png^[transformR270",
|
||||
@ -78,18 +78,19 @@ names = techage.register_junction("techage:ta4_concentrator", 2/8, Boxes, Tube,
|
||||
"techage_tubeta4_junction.png^techage_appl_arrow2.png^[transformR270",
|
||||
},
|
||||
paramtype2 = "facedir", -- important!
|
||||
use_texture_alpha = techage.CLIP,
|
||||
groups = {snappy = 2, choppy = 2, oddly_breakable_by_hand = 3, techage_trowel = 1},
|
||||
sounds = default.node_sound_defaults(),
|
||||
|
||||
after_place_node = function(pos, placer, itemstack, pointed_thing)
|
||||
local node = minetest.get_node(pos)
|
||||
local name = "techage:ta4_concentrator"..techage.junction_type(pos, Tube, "R", node.param2)
|
||||
local name = "techage:ta4_concentrator"..networks.junction_type(pos, Tube, "R", node.param2)
|
||||
minetest.swap_node(pos, {name = name, param2 = node.param2})
|
||||
M(pos):set_int("push_dir", techage.side_to_outdir("R", node.param2))
|
||||
Tube:after_place_node(pos)
|
||||
end,
|
||||
tubelib2_on_update2 = function(pos, dir1, tlib2, node)
|
||||
local name = "techage:ta4_concentrator"..techage.junction_type(pos, Tube, "R", node.param2)
|
||||
local name = "techage:ta4_concentrator"..networks.junction_type(pos, Tube, "R", node.param2)
|
||||
minetest.swap_node(pos, {name = name, param2 = node.param2})
|
||||
end,
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
|
@ -27,10 +27,18 @@ local M = minetest.get_meta
|
||||
local CRD = function(pos) return (minetest.registered_nodes[techage.get_node_lvm(pos).name] or {}).consumer end
|
||||
local CRDN = function(node) return (minetest.registered_nodes[node.name] or {}).consumer end
|
||||
|
||||
local power = techage.power
|
||||
local networks = techage.networks
|
||||
local Pipe = techage.LiquidPipe
|
||||
local liquid = techage.liquid
|
||||
local Tube = techage.Tube
|
||||
local power = networks.power
|
||||
local liquid = networks.liquid
|
||||
local CYCLE_TIME = 2
|
||||
|
||||
local function get_keys(tbl)
|
||||
local keys = {}
|
||||
for k,v in pairs(tbl) do
|
||||
keys[#keys + 1] = k
|
||||
end
|
||||
return keys
|
||||
end
|
||||
|
||||
local function has_power(pos, nvm, state)
|
||||
local crd = CRD(pos)
|
||||
@ -38,37 +46,53 @@ local function has_power(pos, nvm, state)
|
||||
end
|
||||
|
||||
local function start_node(pos, nvm, state)
|
||||
local crd = CRD(pos)
|
||||
power.consumer_start(pos, crd.power_netw, crd.cycle_time)
|
||||
end
|
||||
|
||||
local function stop_node(pos, nvm, state)
|
||||
local crd = CRD(pos)
|
||||
power.consumer_stop(pos, crd.power_netw)
|
||||
end
|
||||
|
||||
local function on_power(pos)
|
||||
local function node_timer_pas(pos, elapsed)
|
||||
local crd = CRD(pos)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
|
||||
-- handle power consumption
|
||||
if crd.power_netw and techage.needs_power(nvm) then
|
||||
local consumed = power.consume_power(pos, crd.power_netw, nil, crd.power_consumption)
|
||||
if consumed == crd.power_consumption then
|
||||
crd.State:start(pos, nvm)
|
||||
end
|
||||
|
||||
local function on_nopower(pos)
|
||||
local crd = CRD(pos)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
crd.State:nopower(pos, nvm)
|
||||
end
|
||||
|
||||
|
||||
local function node_timer(pos, elapsed)
|
||||
local crd = CRD(pos)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
if crd.power_netw and techage.needs_power(nvm) then
|
||||
power.consumer_alive(pos, crd.power_netw, crd.cycle_time)
|
||||
end
|
||||
-- call the node timer routine
|
||||
if techage.is_operational(nvm) then
|
||||
nvm.node_timer_call_cyle = (nvm.node_timer_call_cyle or 0) + 1
|
||||
if nvm.node_timer_call_cyle >= crd.call_cycle then
|
||||
crd.node_timer(pos, crd.cycle_time)
|
||||
nvm.node_timer_call_cyle = 0
|
||||
end
|
||||
end
|
||||
return crd.State:is_active(nvm)
|
||||
end
|
||||
|
||||
local function node_timer_act(pos, elapsed)
|
||||
local crd = CRD(pos)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
|
||||
-- handle power consumption
|
||||
if crd.power_netw and techage.needs_power(nvm) then
|
||||
local consumed = power.consume_power(pos, crd.power_netw, nil, crd.power_consumption)
|
||||
if consumed < crd.power_consumption then
|
||||
crd.State:nopower(pos, nvm)
|
||||
end
|
||||
end
|
||||
|
||||
-- call the node timer routine
|
||||
if techage.is_operational(nvm) then
|
||||
nvm.node_timer_call_cyle = (nvm.node_timer_call_cyle or 0) + 1
|
||||
if nvm.node_timer_call_cyle >= crd.call_cycle then
|
||||
crd.node_timer(pos, crd.cycle_time)
|
||||
nvm.node_timer_call_cyle = 0
|
||||
end
|
||||
end
|
||||
return crd.State:is_active(nvm)
|
||||
end
|
||||
@ -105,37 +129,17 @@ function techage.register_consumer(base_name, inv_name, tiles, tNode, validState
|
||||
local power_network
|
||||
local power_png = 'techage_axle_clutch.png'
|
||||
local power_used = tNode.power_consumption ~= nil
|
||||
local tNetworks
|
||||
local sides
|
||||
-- power needed?
|
||||
if power_used then
|
||||
if stage > 2 then
|
||||
power_network = techage.ElectricCable
|
||||
power_png = 'techage_appl_hole_electric.png'
|
||||
tNetworks = {
|
||||
ele1 = {
|
||||
sides = tNode.power_sides or {F=1, B=1, U=1, D=1},
|
||||
ntype = "con1",
|
||||
nominal = tNode.power_consumption[stage],
|
||||
on_power = on_power,
|
||||
on_nopower = on_nopower,
|
||||
is_running = function(pos, nvm) return techage.is_running(nvm) end,
|
||||
},
|
||||
}
|
||||
if tNode.networks and tNode.networks.pipe2 then
|
||||
tNetworks.pipe2 = tNode.networks.pipe2
|
||||
end
|
||||
sides = get_keys(tNode.power_sides or {F=1, B=1, U=1, D=1})
|
||||
else
|
||||
power_network = techage.Axle
|
||||
power_png = 'techage_axle_clutch.png'
|
||||
tNetworks = {
|
||||
axle = {
|
||||
sides = tNode.power_sides or {F=1, B=1, U=1, D=1},
|
||||
ntype = "con1",
|
||||
nominal = tNode.power_consumption[stage],
|
||||
on_power = on_power,
|
||||
on_nopower = on_nopower,
|
||||
}
|
||||
}
|
||||
sides = get_keys(tNode.power_sides or {F=1, B=1, U=1, D=1})
|
||||
end
|
||||
end
|
||||
|
||||
@ -143,7 +147,7 @@ function techage.register_consumer(base_name, inv_name, tiles, tNode, validState
|
||||
node_name_passive = name_pas,
|
||||
node_name_active = name_act,
|
||||
infotext_name = name_inv,
|
||||
cycle_time = tNode.cycle_time,
|
||||
cycle_time = CYCLE_TIME,
|
||||
standby_ticks = tNode.standby_ticks,
|
||||
formspec_func = tNode.formspec,
|
||||
on_state_change = tNode.on_state_change,
|
||||
@ -162,6 +166,7 @@ function techage.register_consumer(base_name, inv_name, tiles, tNode, validState
|
||||
tNode.power_consumption[stage] or 0,
|
||||
node_timer = tNode.node_timer,
|
||||
cycle_time = tNode.cycle_time,
|
||||
call_cycle = tNode.cycle_time / 2,
|
||||
power_netw = power_network,
|
||||
}
|
||||
|
||||
@ -198,17 +203,6 @@ function techage.register_consumer(base_name, inv_name, tiles, tNode, validState
|
||||
techage.del_mem(pos)
|
||||
end
|
||||
|
||||
local tubelib2_on_update2 = function(pos, outdir, tlib2, node)
|
||||
if tNode.tubelib2_on_update2 then
|
||||
tNode.tubelib2_on_update2(pos, outdir, tlib2, node)
|
||||
end
|
||||
if tlib2.tube_type == "pipe2" then
|
||||
liquid.update_network(pos, outdir, tlib2)
|
||||
else
|
||||
power.update_network(pos, outdir, tlib2)
|
||||
end
|
||||
end
|
||||
|
||||
tNode.groups.not_in_creative_inventory = 0
|
||||
|
||||
local def_pas = {
|
||||
@ -221,20 +215,18 @@ function techage.register_consumer(base_name, inv_name, tiles, tNode, validState
|
||||
|
||||
can_dig = tNode.can_dig,
|
||||
on_rotate = tNode.on_rotate or screwdriver.disallow,
|
||||
on_timer = node_timer,
|
||||
on_timer = node_timer_pas,
|
||||
on_receive_fields = tNode.on_receive_fields,
|
||||
on_rightclick = tNode.on_rightclick,
|
||||
after_place_node = after_place_node,
|
||||
after_dig_node = after_dig_node,
|
||||
preserve_metadata = tNode.preserve_metadata,
|
||||
tubelib2_on_update2 = tubelib2_on_update2,
|
||||
allow_metadata_inventory_put = tNode.allow_metadata_inventory_put,
|
||||
allow_metadata_inventory_move = tNode.allow_metadata_inventory_move,
|
||||
allow_metadata_inventory_take = tNode.allow_metadata_inventory_take,
|
||||
on_metadata_inventory_move = tNode.on_metadata_inventory_move,
|
||||
on_metadata_inventory_put = tNode.on_metadata_inventory_put,
|
||||
on_metadata_inventory_take = tNode.on_metadata_inventory_take,
|
||||
networks = tNetworks and table.copy(tNetworks),
|
||||
|
||||
paramtype = tNode.paramtype,
|
||||
paramtype2 = "facedir",
|
||||
@ -264,19 +256,17 @@ function techage.register_consumer(base_name, inv_name, tiles, tNode, validState
|
||||
selection_box = tNode.selection_box,
|
||||
|
||||
on_rotate = tNode.on_rotate or screwdriver.disallow,
|
||||
on_timer = node_timer,
|
||||
on_timer = node_timer_act,
|
||||
on_receive_fields = tNode.on_receive_fields,
|
||||
on_rightclick = tNode.on_rightclick,
|
||||
after_place_node = after_place_node,
|
||||
after_dig_node = after_dig_node,
|
||||
tubelib2_on_update2 = tubelib2_on_update2,
|
||||
allow_metadata_inventory_put = tNode.allow_metadata_inventory_put,
|
||||
allow_metadata_inventory_move = tNode.allow_metadata_inventory_move,
|
||||
allow_metadata_inventory_take = tNode.allow_metadata_inventory_take,
|
||||
on_metadata_inventory_move = tNode.on_metadata_inventory_move,
|
||||
on_metadata_inventory_put = tNode.on_metadata_inventory_put,
|
||||
on_metadata_inventory_take = tNode.on_metadata_inventory_take,
|
||||
networks = tNetworks and table.copy(tNetworks),
|
||||
|
||||
paramtype = tNode.paramtype,
|
||||
paramtype2 = "facedir",
|
||||
@ -297,9 +287,14 @@ function techage.register_consumer(base_name, inv_name, tiles, tNode, validState
|
||||
minetest.register_node(name_act, def_act)
|
||||
|
||||
if power_used then
|
||||
power_network:add_secondary_node_names({name_pas, name_act})
|
||||
power.register_nodes({name_pas, name_act}, power_network, "con", sides)
|
||||
end
|
||||
techage.register_node({name_pas, name_act}, tNode.tubing)
|
||||
|
||||
if tNode.tube_sides then
|
||||
Tube:set_valid_sides(name_pas, get_keys(tNode.tube_sides))
|
||||
Tube:set_valid_sides(name_act, get_keys(tNode.tube_sides))
|
||||
end
|
||||
end
|
||||
end
|
||||
return names[1], names[2], names[3]
|
||||
|
@ -357,7 +357,7 @@ local function on_receive_fields(pos, formname, fields, player)
|
||||
end
|
||||
local meta = M(pos)
|
||||
local crd = CRD(pos)
|
||||
local filter = minetest.deserialize(meta:get_string("filter"))
|
||||
local filter = minetest.deserialize(meta:get_string("filter")) or {false,false,false,false}
|
||||
if fields.filter1 ~= nil then
|
||||
filter[1] = fields.filter1 == "true"
|
||||
elseif fields.filter2 ~= nil then
|
||||
@ -385,7 +385,7 @@ end
|
||||
local function change_filter_settings(pos, slot, val)
|
||||
local slots = {["red"] = 1, ["green"] = 2, ["blue"] = 3, ["yellow"] = 4}
|
||||
local meta = M(pos)
|
||||
local filter = minetest.deserialize(meta:get_string("filter"))
|
||||
local filter = minetest.deserialize(meta:get_string("filter")) or {false,false,false,false}
|
||||
local num = slots[slot] or 1
|
||||
if num >= 1 and num <= 4 then
|
||||
filter[num] = val == "on"
|
||||
@ -402,7 +402,7 @@ end
|
||||
-- techage command to read filter channel status (on/off)
|
||||
local function read_filter_settings(pos, slot)
|
||||
local slots = {["red"] = 1, ["green"] = 2, ["blue"] = 3, ["yellow"] = 4}
|
||||
local filter = minetest.deserialize(M(pos):get_string("filter"))
|
||||
local filter = minetest.deserialize(M(pos):get_string("filter")) or {false,false,false,false}
|
||||
return filter[slots[slot]] and "on" or "off"
|
||||
end
|
||||
|
||||
|
@ -293,6 +293,7 @@ local node_name_ta2, node_name_ta3, node_name_ta4 =
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
num_items = {0,1,1,1},
|
||||
power_consumption = {0,3,3,3},
|
||||
tube_sides = {L=1, R=1, U=1},
|
||||
},
|
||||
{false, true, true, false}) -- TA2/TA3
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
TechAge
|
||||
=======
|
||||
|
||||
Copyright (C) 2019 Joachim Stolberg
|
||||
Copyright (C) 2019-2021 Joachim Stolberg
|
||||
|
||||
AGPL v3
|
||||
See LICENSE.txt for more information
|
||||
@ -161,7 +161,6 @@ local tubing = {
|
||||
local meta = minetest.get_meta(pos)
|
||||
if meta:get_int("push_dir") == in_dir or in_dir == 5 then
|
||||
local inv = M(pos):get_inventory()
|
||||
--CRD(pos).State:start_if_standby(pos) -- would need power!
|
||||
return techage.put_items(inv, "src", stack)
|
||||
end
|
||||
end,
|
||||
@ -217,6 +216,7 @@ local node_name_ta2, node_name_ta3, node_name_ta4 =
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
num_items = {0,1,2,4},
|
||||
power_consumption = {0,3,4,5},
|
||||
tube_sides = {L=1, R=1, U=1},
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
|
@ -3,7 +3,7 @@
|
||||
TechAge
|
||||
=======
|
||||
|
||||
Copyright (C) 2019 Joachim Stolberg
|
||||
Copyright (C) 2019-2021 Joachim Stolberg
|
||||
|
||||
AGPL v3
|
||||
See LICENSE.txt for more information
|
||||
@ -75,48 +75,54 @@ end
|
||||
|
||||
-- Grinder normaly handles 'num_items' per cycle. 'num_items' is node stage dependent.
|
||||
-- But if 'inp_num' > 1 (wheat recipes), use 'inp_num' and produce one output item.
|
||||
local function src_to_dst(src_stack, idx, num_items, inp_num, inv, dst_name, num_input)
|
||||
local taken, output
|
||||
local function src_to_dst(src_stack, idx, src_name, num_items, inp_num, inv, dst_name)
|
||||
if inp_num > 1 then
|
||||
if src_stack:get_count() >= inp_num then
|
||||
taken = src_stack:take_item(inp_num)
|
||||
output = ItemStack(dst_name)
|
||||
else
|
||||
return false
|
||||
local input = ItemStack(src_name)
|
||||
input:set_count(inp_num)
|
||||
local output = ItemStack(dst_name)
|
||||
if inv:contains_item("src", input) and inv:room_for_item("dst", output) then
|
||||
inv:remove_item("src", input)
|
||||
inv:add_item("dst", output)
|
||||
return true
|
||||
end
|
||||
else
|
||||
taken = src_stack:take_item(num_items)
|
||||
output = ItemStack(dst_name)
|
||||
local taken = src_stack:take_item(num_items)
|
||||
local output = ItemStack(dst_name)
|
||||
output:set_count(output:get_count() * taken:get_count())
|
||||
end
|
||||
if inv:room_for_item("dst", output) then
|
||||
inv:set_stack("src", idx, src_stack)
|
||||
inv:add_item("dst", output)
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local function grinding(pos, crd, nvm, inv)
|
||||
local num_items = 0
|
||||
local blocked = false -- idle
|
||||
for idx,stack in ipairs(inv:get_list("src")) do
|
||||
if not stack:is_empty() then
|
||||
local name = stack:get_name()
|
||||
if Recipes[name] then
|
||||
local recipe = Recipes[name]
|
||||
if src_to_dst(stack, idx, crd.num_items, recipe.inp_num, inv, recipe.output) then
|
||||
if src_to_dst(stack, idx, name, crd.num_items, recipe.inp_num, inv, recipe.output) then
|
||||
crd.State:keep_running(pos, nvm, COUNTDOWN_TICKS)
|
||||
return
|
||||
else
|
||||
crd.State:blocked(pos, nvm)
|
||||
blocked = true
|
||||
end
|
||||
else
|
||||
crd.State:fault(pos, nvm)
|
||||
end
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
if blocked then
|
||||
crd.State:blocked(pos, nvm)
|
||||
else
|
||||
crd.State:idle(pos, nvm)
|
||||
end
|
||||
end
|
||||
|
||||
local function keep_running(pos, elapsed)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
@ -241,6 +247,7 @@ local node_name_ta2, node_name_ta3, node_name_ta4 =
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
num_items = {0,1,2,4},
|
||||
power_consumption = {0,4,6,9},
|
||||
tube_sides = {L=1, R=1, U=1},
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
@ -252,23 +259,23 @@ minetest.register_craft({
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = node_name_ta3,
|
||||
recipe = {
|
||||
{"", "default:mese_crystal", ""},
|
||||
{"", node_name_ta2, ""},
|
||||
{"", "techage:vacuum_tube", ""},
|
||||
},
|
||||
})
|
||||
--minetest.register_craft({
|
||||
-- output = node_name_ta3,
|
||||
-- recipe = {
|
||||
-- {"", "default:mese_crystal", ""},
|
||||
-- {"", node_name_ta2, ""},
|
||||
-- {"", "techage:vacuum_tube", ""},
|
||||
-- },
|
||||
--})
|
||||
|
||||
minetest.register_craft({
|
||||
output = node_name_ta4,
|
||||
recipe = {
|
||||
{"", "default:mese_crystal", ""},
|
||||
{"", node_name_ta3, ""},
|
||||
{"", "techage:ta4_wlanchip", ""},
|
||||
},
|
||||
})
|
||||
--minetest.register_craft({
|
||||
-- output = node_name_ta4,
|
||||
-- recipe = {
|
||||
-- {"", "default:mese_crystal", ""},
|
||||
-- {"", node_name_ta3, ""},
|
||||
-- {"", "techage:ta4_wlanchip", ""},
|
||||
-- },
|
||||
--})
|
||||
|
||||
if minetest.global_exists("unified_inventory") then
|
||||
unified_inventory.register_craft_type("grinding", {
|
||||
|
@ -290,6 +290,7 @@ local node_name_ta2, node_name_ta3, node_name_ta4 =
|
||||
is_ground_content = false,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
num_items = {0,2,6,12},
|
||||
tube_sides = {L=1, R=1},
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
|
@ -3,12 +3,12 @@
|
||||
TechAge
|
||||
=======
|
||||
|
||||
Copyright (C) 2019-2020 Joachim Stolberg
|
||||
Copyright (C) 2019-2021 Joachim Stolberg
|
||||
|
||||
AGPL v3
|
||||
See LICENSE.txt for more information
|
||||
|
||||
TA2/TA3/TA4 Power Test Source
|
||||
TA2/TA3 Power Test Source
|
||||
|
||||
]]--
|
||||
|
||||
@ -18,26 +18,17 @@ local M = minetest.get_meta
|
||||
local S = techage.S
|
||||
|
||||
local Axle = techage.Axle
|
||||
local Pipe = techage.SteamPipe
|
||||
--local Pipe = techage.SteamPipe
|
||||
local Cable = techage.ElectricCable
|
||||
local power = techage.power
|
||||
local networks = techage.networks
|
||||
local power = networks.power
|
||||
local control = networks.control
|
||||
|
||||
local STANDBY_TICKS = 4
|
||||
local COUNTDOWN_TICKS = 4
|
||||
local CYCLE_TIME = 2
|
||||
local PWR_CAPA = 100
|
||||
local PWR_PERF = 100
|
||||
|
||||
local function formspec(self, pos, nvm)
|
||||
return "size[4,4]"..
|
||||
"box[0,-0.1;3.8,0.5;#c6e8ff]"..
|
||||
"label[1,-0.1;"..minetest.colorize( "#000000", S("Power Source")).."]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
power.formspec_label_bar(pos, 0, 0.8, S("power"), PWR_CAPA, nvm.provided)..
|
||||
"image_button[2.8,2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
|
||||
"tooltip[2.8,2;1,1;"..self:get_state_tooltip(nvm).."]"
|
||||
return techage.generator_formspec(self, pos, nvm, S("Power Source"), nvm.provided, PWR_PERF)
|
||||
end
|
||||
|
||||
-- Axles texture animation
|
||||
@ -47,44 +38,36 @@ local function switch_axles(pos, on)
|
||||
end
|
||||
|
||||
local function start_node2(pos, nvm, state)
|
||||
nvm.generating = true
|
||||
nvm.running = true
|
||||
nvm.provided = 0
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
power.generator_start(pos, Axle, CYCLE_TIME, outdir)
|
||||
switch_axles(pos, true)
|
||||
power.start_storage_calc(pos, Axle, outdir)
|
||||
end
|
||||
|
||||
local function stop_node2(pos, nvm, state)
|
||||
nvm.generating = false
|
||||
nvm.running = false
|
||||
nvm.provided = 0
|
||||
nvm.load = 0
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
power.generator_stop(pos, Axle, outdir)
|
||||
switch_axles(pos, false)
|
||||
power.start_storage_calc(pos, Axle, outdir)
|
||||
end
|
||||
|
||||
local function start_node3(pos, nvm, state)
|
||||
nvm.generating = true
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
power.generator_start(pos, Pipe, CYCLE_TIME, outdir)
|
||||
local meta = M(pos)
|
||||
nvm.running = true
|
||||
nvm.provided = 0
|
||||
techage.evaluate_charge_termination(nvm, meta)
|
||||
local outdir = meta:get_int("outdir")
|
||||
power.start_storage_calc(pos, Cable, outdir)
|
||||
end
|
||||
|
||||
local function stop_node3(pos, nvm, state)
|
||||
nvm.generating = false
|
||||
nvm.running = false
|
||||
nvm.provided = 0
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
power.generator_stop(pos, Pipe, outdir)
|
||||
end
|
||||
|
||||
local function start_node4(pos, nvm, state)
|
||||
nvm.generating = true
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
power.generator_start(pos, Cable, CYCLE_TIME, outdir)
|
||||
end
|
||||
|
||||
local function stop_node4(pos, nvm, state)
|
||||
nvm.generating = false
|
||||
nvm.provided = 0
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
power.generator_stop(pos, Cable, outdir)
|
||||
power.start_storage_calc(pos, Cable, outdir)
|
||||
end
|
||||
|
||||
local State2 = techage.NodeStates:new({
|
||||
@ -97,7 +80,7 @@ local State2 = techage.NodeStates:new({
|
||||
})
|
||||
|
||||
local State3 = techage.NodeStates:new({
|
||||
node_name_passive = "techage:t3_source",
|
||||
node_name_passive = "techage:t4_source",
|
||||
cycle_time = CYCLE_TIME,
|
||||
standby_ticks = STANDBY_TICKS,
|
||||
formspec_func = formspec,
|
||||
@ -105,44 +88,32 @@ local State3 = techage.NodeStates:new({
|
||||
stop_node = stop_node3,
|
||||
})
|
||||
|
||||
local State4 = techage.NodeStates:new({
|
||||
node_name_passive = "techage:t4_source",
|
||||
cycle_time = CYCLE_TIME,
|
||||
standby_ticks = STANDBY_TICKS,
|
||||
formspec_func = formspec,
|
||||
start_node = start_node4,
|
||||
stop_node = stop_node4,
|
||||
})
|
||||
|
||||
local function node_timer2(pos, elapsed)
|
||||
--print("node_timer2")
|
||||
local meta = M(pos)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
nvm.provided = power.generator_alive(pos, Axle, CYCLE_TIME, outdir)
|
||||
local outdir = meta:get_int("outdir")
|
||||
local tp1 = tonumber(meta:get_string("termpoint1"))
|
||||
local tp2 = tonumber(meta:get_string("termpoint2"))
|
||||
nvm.provided = power.provide_power(pos, Axle, outdir, PWR_PERF, tp1, tp2)
|
||||
nvm.load = power.get_storage_load(pos, Axle, outdir, PWR_PERF)
|
||||
if techage.is_activeformspec(pos) then
|
||||
M(pos):set_string("formspec", formspec(State2, pos, nvm))
|
||||
meta:set_string("formspec", formspec(State2, pos, nvm))
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
local function node_timer3(pos, elapsed)
|
||||
--print("node_timer3")
|
||||
local nvm = techage.get_nvm(pos)
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
nvm.provided = power.generator_alive(pos, Pipe, CYCLE_TIME, outdir)
|
||||
if techage.is_activeformspec(pos) then
|
||||
M(pos):set_string("formspec", formspec(State3, pos, nvm))
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
local function node_timer4(pos, elapsed)
|
||||
--print("node_timer4")
|
||||
local meta = M(pos)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
nvm.provided = power.generator_alive(pos, Cable, CYCLE_TIME, outdir)
|
||||
local tp1 = tonumber(meta:get_string("termpoint1"))
|
||||
local tp2 = tonumber(meta:get_string("termpoint2"))
|
||||
nvm.provided = power.provide_power(pos, Cable, outdir, PWR_PERF, tp1, tp2)
|
||||
nvm.load = power.get_storage_load(pos, Cable, outdir, PWR_PERF)
|
||||
if techage.is_activeformspec(pos) then
|
||||
M(pos):set_string("formspec", formspec(State4, pos, nvm))
|
||||
meta:set_string("formspec", formspec(State3, pos, nvm))
|
||||
end
|
||||
return true
|
||||
end
|
||||
@ -165,15 +136,6 @@ local function on_receive_fields3(pos, formname, fields, player)
|
||||
M(pos):set_string("formspec", formspec(State3, pos, nvm))
|
||||
end
|
||||
|
||||
local function on_receive_fields4(pos, formname, fields, player)
|
||||
if minetest.is_protected(pos, player:get_player_name()) then
|
||||
return
|
||||
end
|
||||
local nvm = techage.get_nvm(pos)
|
||||
State4:state_button_event(pos, nvm, fields)
|
||||
M(pos):set_string("formspec", formspec(State4, pos, nvm))
|
||||
end
|
||||
|
||||
local function on_rightclick2(pos, node, clicker)
|
||||
techage.set_activeformspec(pos, clicker)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
@ -186,12 +148,6 @@ local function on_rightclick3(pos, node, clicker)
|
||||
M(pos):set_string("formspec", formspec(State3, pos, nvm))
|
||||
end
|
||||
|
||||
local function on_rightclick4(pos, node, clicker)
|
||||
techage.set_activeformspec(pos, clicker)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
M(pos):set_string("formspec", formspec(State4, pos, nvm))
|
||||
end
|
||||
|
||||
local function after_place_node2(pos)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
State2:node_init(pos, nvm, "")
|
||||
@ -202,17 +158,10 @@ end
|
||||
|
||||
local function after_place_node3(pos)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
State3:node_init(pos, nvm, "")
|
||||
local number = techage.add_node(pos, "techage:t4_source")
|
||||
State3:node_init(pos, nvm, number)
|
||||
M(pos):set_int("outdir", networks.side_to_outdir(pos, "R"))
|
||||
M(pos):set_string("formspec", formspec(State3, pos, nvm))
|
||||
Pipe:after_place_node(pos)
|
||||
end
|
||||
|
||||
local function after_place_node4(pos)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
State4:node_init(pos, nvm, "")
|
||||
M(pos):set_int("outdir", networks.side_to_outdir(pos, "R"))
|
||||
M(pos):set_string("formspec", formspec(State4, pos, nvm))
|
||||
Cable:after_place_node(pos)
|
||||
end
|
||||
|
||||
@ -222,43 +171,16 @@ local function after_dig_node2(pos, oldnode)
|
||||
end
|
||||
|
||||
local function after_dig_node3(pos, oldnode)
|
||||
Pipe:after_dig_node(pos)
|
||||
techage.del_mem(pos)
|
||||
end
|
||||
|
||||
local function after_dig_node4(pos, oldnode)
|
||||
Cable:after_dig_node(pos)
|
||||
techage.del_mem(pos)
|
||||
end
|
||||
|
||||
local function tubelib2_on_update2(pos, outdir, tlib2, node)
|
||||
power.update_network(pos, outdir, tlib2)
|
||||
local function get_generator_data(pos, outdir, tlib2)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
if nvm.running then
|
||||
return {level = (nvm.load or 0) / PWR_PERF, perf = PWR_PERF, capa = PWR_PERF * 2}
|
||||
end
|
||||
end
|
||||
|
||||
local net_def2 = {
|
||||
axle = {
|
||||
sides = {R = 1},
|
||||
ntype = "gen1",
|
||||
nominal = PWR_CAPA,
|
||||
},
|
||||
}
|
||||
|
||||
local net_def3 = {
|
||||
pipe1 = {
|
||||
sides = {R = 1},
|
||||
ntype = "gen1",
|
||||
nominal = PWR_CAPA,
|
||||
},
|
||||
}
|
||||
|
||||
local net_def4 = {
|
||||
ele1 = {
|
||||
sides = {R = 1},
|
||||
ntype = "gen1",
|
||||
nominal = PWR_CAPA,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
minetest.register_node("techage:t2_source", {
|
||||
description = S("Axle Power Source"),
|
||||
@ -280,32 +202,7 @@ minetest.register_node("techage:t2_source", {
|
||||
on_timer = node_timer2,
|
||||
after_place_node = after_place_node2,
|
||||
after_dig_node = after_dig_node2,
|
||||
tubelib2_on_update2 = tubelib2_on_update2,
|
||||
networks = net_def2,
|
||||
})
|
||||
|
||||
minetest.register_node("techage:t3_source", {
|
||||
description = S("Steam Power Source"),
|
||||
tiles = {
|
||||
-- up, down, right, left, back, front
|
||||
"techage_filling_ta3.png^techage_frame_ta3_top.png",
|
||||
"techage_filling_ta3.png^techage_frame_ta3.png",
|
||||
"techage_filling_ta3.png^techage_steam_hole.png^techage_frame_ta3.png",
|
||||
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_source.png",
|
||||
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_source.png",
|
||||
"techage_filling_ta3.png^techage_frame_ta3.png^techage_appl_source.png",
|
||||
},
|
||||
paramtype2 = "facedir",
|
||||
groups = {cracky=2, crumbly=2, choppy=2},
|
||||
on_rotate = screwdriver.disallow,
|
||||
is_ground_content = false,
|
||||
on_receive_fields = on_receive_fields3,
|
||||
on_rightclick = on_rightclick3,
|
||||
on_timer = node_timer3,
|
||||
after_place_node = after_place_node3,
|
||||
after_dig_node = after_dig_node3,
|
||||
tubelib2_on_update2 = tubelib2_on_update2,
|
||||
networks = net_def3,
|
||||
get_generator_data = get_generator_data,
|
||||
})
|
||||
|
||||
minetest.register_node("techage:t4_source", {
|
||||
@ -323,15 +220,47 @@ minetest.register_node("techage:t4_source", {
|
||||
groups = {cracky=2, crumbly=2, choppy=2},
|
||||
on_rotate = screwdriver.disallow,
|
||||
is_ground_content = false,
|
||||
on_receive_fields = on_receive_fields4,
|
||||
on_rightclick = on_rightclick4,
|
||||
on_timer = node_timer4,
|
||||
after_place_node = after_place_node4,
|
||||
after_dig_node = after_dig_node4,
|
||||
tubelib2_on_update2 = tubelib2_on_update2,
|
||||
networks = net_def4,
|
||||
on_receive_fields = on_receive_fields3,
|
||||
on_rightclick = on_rightclick3,
|
||||
on_timer = node_timer3,
|
||||
after_place_node = after_place_node3,
|
||||
after_dig_node = after_dig_node3,
|
||||
get_generator_data = get_generator_data,
|
||||
ta3_formspec = techage.generator_settings("ta3", PWR_PERF),
|
||||
})
|
||||
|
||||
Axle:add_secondary_node_names({"techage:t2_source"})
|
||||
--Pipe:add_secondary_node_names({"techage:t3_source"})
|
||||
Cable:add_secondary_node_names({"techage:t4_source"})
|
||||
power.register_nodes({"techage:t2_source"}, Axle, "gen", {"R"})
|
||||
power.register_nodes({"techage:t4_source"}, Cable, "gen", {"R"})
|
||||
|
||||
techage.register_node({"techage:t4_source"}, {
|
||||
on_recv_message = function(pos, src, topic, payload)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
if topic == "delivered" then
|
||||
return nvm.provided or 0
|
||||
else
|
||||
return State3:on_receive_message(pos, topic, payload)
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
control.register_nodes({"techage:t4_source"}, {
|
||||
on_receive = function(pos, tlib2, topic, payload)
|
||||
end,
|
||||
on_request = function(pos, tlib2, topic)
|
||||
if topic == "info" then
|
||||
local nvm = techage.get_nvm(pos)
|
||||
local meta = M(pos)
|
||||
return {
|
||||
type = S("Ele Power Source"),
|
||||
number = meta:get_string("node_number") or "",
|
||||
running = nvm.running or false,
|
||||
available = PWR_PERF,
|
||||
provided = nvm.provided or 0,
|
||||
termpoint = meta:get_string("termpoint"),
|
||||
}
|
||||
end
|
||||
return false
|
||||
end,
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -26,7 +26,7 @@ local techage_use_sqlite = minetest.settings:get_bool('techage_use_sqlite', fals
|
||||
local string_split = string.split
|
||||
local NodeDef = techage.NodeDef
|
||||
local Tube = techage.Tube
|
||||
local is_cart_available = minecart.is_cart_available
|
||||
local is_cart_available = minecart.is_nodecart_available
|
||||
|
||||
-------------------------------------------------------------------
|
||||
-- Database
|
||||
@ -164,6 +164,19 @@ local function is_air_like(name)
|
||||
return false
|
||||
end
|
||||
|
||||
techage.SystemTime = 0
|
||||
minetest.register_globalstep(function(dtime)
|
||||
techage.SystemTime = techage.SystemTime + dtime
|
||||
end)
|
||||
|
||||
-- used by TA1 hammer: dug_node[player_name] = pos
|
||||
techage.dug_node = {}
|
||||
minetest.register_on_dignode(function(pos, oldnode, digger)
|
||||
if not digger then return end
|
||||
-- store pos for tools without own 'register_on_dignode'
|
||||
techage.dug_node[digger:get_player_name()] = pos
|
||||
end)
|
||||
|
||||
-------------------------------------------------------------------
|
||||
-- API helper functions
|
||||
-------------------------------------------------------------------
|
||||
|
@ -91,15 +91,15 @@ end
|
||||
|
||||
function inv_lib.take_item(pos, inv, listname, num, stacks)
|
||||
local mem = techage.get_mem(pos)
|
||||
local size = #stacks
|
||||
mem.ta_startpos = mem.ta_startpos or 1
|
||||
for idx = mem.ta_startpos, mem.ta_startpos + size do
|
||||
idx = (idx % size) + 1
|
||||
local size = #(stacks or {})
|
||||
for i = 1, size do
|
||||
local idx = stacks[((i + mem.ta_startpos) % size) + 1]
|
||||
local stack = inv:get_stack(listname, idx)
|
||||
local taken = stack:take_item(num)
|
||||
if taken:get_count() > 0 then
|
||||
inv:set_stack(listname, idx, stack)
|
||||
mem.ta_startpos = idx
|
||||
mem.ta_startpos = mem.ta_startpos + i
|
||||
return taken
|
||||
end
|
||||
end
|
||||
|
@ -3,7 +3,7 @@
|
||||
TechAge
|
||||
=======
|
||||
|
||||
Copyright (C) 2019 Joachim Stolberg
|
||||
Copyright (C) 2019-2021 Joachim Stolberg
|
||||
|
||||
AGPL v3
|
||||
See LICENSE.txt for more information
|
||||
|
@ -3,7 +3,7 @@
|
||||
TechAge
|
||||
=======
|
||||
|
||||
Copyright (C) 2019-2020 Joachim Stolberg
|
||||
Copyright (C) 2019-2021 Joachim Stolberg
|
||||
|
||||
AGPL v3
|
||||
See LICENSE.txt for more information
|
||||
@ -17,7 +17,7 @@ local P2S = minetest.pos_to_string
|
||||
local M = minetest.get_meta
|
||||
local S = techage.S
|
||||
local Pipe = techage.LiquidPipe
|
||||
local liquid = techage.liquid
|
||||
local liquid = networks.liquid
|
||||
local ValidOilFuels = techage.firebox.ValidOilFuels
|
||||
local Burntime = techage.firebox.Burntime
|
||||
|
||||
@ -28,11 +28,12 @@ local BLOCKING_TIME = 0.3 -- 300ms
|
||||
|
||||
techage.fuel.CAPACITY = CAPACITY
|
||||
|
||||
-- fuel burning categories (better than...)
|
||||
techage.fuel.BT_BITUMEN = 4
|
||||
techage.fuel.BT_OIL = 3
|
||||
techage.fuel.BT_FUELOIL = 2
|
||||
techage.fuel.BT_NAPHTHA = 1
|
||||
-- fuel burning categories (equal or better than...)
|
||||
techage.fuel.BT_BITUMEN = 5
|
||||
techage.fuel.BT_OIL = 4
|
||||
techage.fuel.BT_FUELOIL = 3
|
||||
techage.fuel.BT_NAPHTHA = 2
|
||||
techage.fuel.BT_GASOLINE = 1
|
||||
|
||||
|
||||
function techage.fuel.fuel_container(x, y, nvm)
|
||||
@ -41,7 +42,7 @@ function techage.fuel.fuel_container(x, y, nvm)
|
||||
itemname = nvm.liquid.name.." "..nvm.liquid.amount
|
||||
end
|
||||
local fuel_percent = 0
|
||||
if nvm.running then
|
||||
if nvm.running or techage.is_running(nvm) then
|
||||
fuel_percent = ((nvm.burn_cycles or 1) * 100) / (nvm.burn_cycles_total or 1)
|
||||
end
|
||||
return "container["..x..","..y.."]"..
|
||||
@ -95,6 +96,7 @@ function techage.fuel.burntime(name)
|
||||
return 0.01 -- not zero !
|
||||
end
|
||||
|
||||
-- equal or better than the given category (see 'techage.fuel.BT_BITUMEN,...')
|
||||
function techage.fuel.valid_fuel(name, category)
|
||||
return ValidOilFuels[name] and ValidOilFuels[name] <= category
|
||||
end
|
||||
@ -109,7 +111,7 @@ function techage.fuel.on_punch(pos, node, puncher, pointed_thing)
|
||||
|
||||
local wielded_item = puncher:get_wielded_item():get_name()
|
||||
local item_count = puncher:get_wielded_item():get_count()
|
||||
local new_item = liquid.fill_on_punch(nvm, wielded_item, item_count, puncher)
|
||||
local new_item = techage.liquid.fill_on_punch(nvm, wielded_item, item_count, puncher)
|
||||
if new_item then
|
||||
puncher:set_wielded_item(new_item)
|
||||
M(pos):set_string("formspec", techage.fuel.formspec(pos, nvm))
|
||||
@ -117,11 +119,11 @@ function techage.fuel.on_punch(pos, node, puncher, pointed_thing)
|
||||
return
|
||||
end
|
||||
|
||||
local ldef = liquid.get_liquid_def(wielded_item)
|
||||
local ldef = techage.liquid.get_liquid_def(wielded_item)
|
||||
if ldef and ValidOilFuels[ldef.inv_item] then
|
||||
local lqd = (minetest.registered_nodes[node.name] or {}).liquid
|
||||
if not lqd.fuel_cat or ValidOilFuels[ldef.inv_item] <= lqd.fuel_cat then
|
||||
local new_item = liquid.empty_on_punch(pos, nvm, wielded_item, item_count)
|
||||
local new_item = techage.liquid.empty_on_punch(pos, nvm, wielded_item, item_count)
|
||||
if new_item then
|
||||
puncher:set_wielded_item(new_item)
|
||||
M(pos):set_string("formspec", techage.fuel.formspec(pos, nvm))
|
||||
@ -154,3 +156,42 @@ function techage.fuel.get_fuel_amount(nvm)
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
function techage.fuel.get_liquid_table(valid_fuel, capacity, start_firebox)
|
||||
return {
|
||||
capa = capacity,
|
||||
fuel_cat = valid_fuel,
|
||||
peek = function(pos)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
return liquid.srv_peek(nvm)
|
||||
end,
|
||||
put = function(pos, indir, name, amount)
|
||||
if techage.fuel.valid_fuel(name, valid_fuel) then
|
||||
local nvm = techage.get_nvm(pos)
|
||||
local res = liquid.srv_put(nvm, name, amount, capacity)
|
||||
start_firebox(pos, nvm)
|
||||
if techage.is_activeformspec(pos) then
|
||||
M(pos):set_string("formspec", techage.fuel.formspec(nvm))
|
||||
end
|
||||
return res
|
||||
end
|
||||
return amount
|
||||
end,
|
||||
take = function(pos, indir, name, amount)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
amount, name = liquid.srv_take(nvm, name, amount)
|
||||
if techage.is_activeformspec(pos) then
|
||||
M(pos):set_string("formspec", techage.fuel.formspec(nvm))
|
||||
end
|
||||
return amount, name
|
||||
end,
|
||||
untake = function(pos, indir, name, amount)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
local leftover = liquid.srv_put(nvm, name, amount, capacity)
|
||||
if techage.is_activeformspec(pos) then
|
||||
M(pos):set_string("formspec", techage.fuel.formspec(nvm))
|
||||
end
|
||||
return leftover
|
||||
end
|
||||
}
|
||||
end
|
25
techage/basis/legacy.lua
Normal file
@ -0,0 +1,25 @@
|
||||
--[[
|
||||
|
||||
TechAge
|
||||
=======
|
||||
|
||||
Copyright (C) 2019-2021 Joachim Stolberg
|
||||
|
||||
AGPL v3
|
||||
See LICENSE.txt for more information
|
||||
|
||||
For the transition from v0.26 to v1.0
|
||||
|
||||
]]--
|
||||
|
||||
function techage.register_node_for_v1_transition(nodenames, on_node_load)
|
||||
minetest.register_lbm({
|
||||
label = "[TechAge] V1 transition",
|
||||
name = nodenames[1].."transition",
|
||||
nodenames = nodenames,
|
||||
run_at_every_load = false,
|
||||
action = function(pos, node)
|
||||
on_node_load(pos, node)
|
||||
end
|
||||
})
|
||||
end
|
@ -15,6 +15,7 @@
|
||||
-- for lazy programmers
|
||||
local P = minetest.string_to_pos
|
||||
local M = minetest.get_meta
|
||||
local S = techage.S
|
||||
|
||||
-- Input data to generate the Param2ToDir table
|
||||
local Input = {
|
||||
@ -336,3 +337,9 @@ function techage.question_mark_help(width, tooltip)
|
||||
"tooltip["..x..",-0.1;0.5,0.5;"..tooltip..";#0C3D32;#FFFFFF]"
|
||||
end
|
||||
|
||||
function techage.wrench_tooltip(x, y)
|
||||
local tooltip = S("Block has an\nadditional wrench menu")
|
||||
return "label["..x..","..y..";"..minetest.colorize("#000000", minetest.formspec_escape("[?]")).."]"..
|
||||
"tooltip["..x..","..y..";0.5,0.5;"..tooltip..";#0C3D32;#FFFFFF]"
|
||||
end
|
||||
|
||||
|
@ -1,362 +0,0 @@
|
||||
--[[
|
||||
|
||||
TechAge
|
||||
=======
|
||||
|
||||
Copyright (C) 2019 Joachim Stolberg
|
||||
|
||||
AGPL v3
|
||||
See LICENSE.txt for more information
|
||||
|
||||
Networks - the connection of tubelib2 tube/pipe/cable lines to networks
|
||||
]]--
|
||||
|
||||
local S2P = minetest.string_to_pos
|
||||
local P2S = minetest.pos_to_string
|
||||
local M = minetest.get_meta
|
||||
local N = techage.get_node_lvm
|
||||
local S = techage.S
|
||||
local hex = function(val) return string.format("%x", val) end
|
||||
|
||||
local Networks = {} -- cache for networks
|
||||
|
||||
techage.networks = {} -- name space
|
||||
|
||||
local MAX_NUM_NODES = 1000
|
||||
local BEST_BEFORE = 5 * 60 -- 5 minutes
|
||||
local Route = {} -- Used to determine the already passed nodes while walking
|
||||
local NumNodes = 0
|
||||
local DirToSide = {"B", "R", "F", "L", "D", "U"}
|
||||
local Sides = {B = true, R = true, F = true, L = true, D = true, U = true}
|
||||
local SideToDir = {B=1, R=2, F=3, L=4, D=5, U=6}
|
||||
local Flip = {[0]=0,3,4,1,2,6,5} -- 180 degree turn
|
||||
|
||||
local function error(pos, msg)
|
||||
minetest.log("error", "[techage] "..msg.." at "..P2S(pos).." "..N(pos).name)
|
||||
end
|
||||
|
||||
local function count_nodes(ntype, nodes)
|
||||
local num = 0
|
||||
for _,pos in ipairs(nodes or {}) do
|
||||
num = num + 1
|
||||
end
|
||||
return ntype.."="..num
|
||||
end
|
||||
|
||||
local function output(network, valid)
|
||||
local tbl = {}
|
||||
for ntype,table in pairs(network) do
|
||||
if type(table) == "table" then
|
||||
tbl[#tbl+1] = count_nodes(ntype, table)
|
||||
end
|
||||
end
|
||||
print("Network ("..valid.."): "..table.concat(tbl, ", "))
|
||||
end
|
||||
|
||||
local function debug(ntype)
|
||||
local tbl = {}
|
||||
for netID,netw in pairs(Networks[ntype] or {}) do
|
||||
if type(netw) == "table" then
|
||||
tbl[#tbl+1] = string.format("%X", netID)
|
||||
end
|
||||
end
|
||||
return "Networks: "..table.concat(tbl, ", ")
|
||||
end
|
||||
|
||||
local function hidden_node(pos, net_name)
|
||||
local name = M(pos):get_string("techage_hidden_nodename")
|
||||
local ndef = minetest.registered_nodes[name]
|
||||
if ndef and ndef.networks then
|
||||
return ndef.networks[net_name] or {}
|
||||
end
|
||||
return {}
|
||||
end
|
||||
|
||||
-- return the node definition local networks table
|
||||
local function net_def(pos, net_name)
|
||||
local ndef = minetest.registered_nodes[techage.get_node_lvm(pos).name]
|
||||
if ndef and ndef.networks then
|
||||
return ndef.networks[net_name] or {}
|
||||
else -- hidden junction
|
||||
return hidden_node(pos, net_name)
|
||||
end
|
||||
end
|
||||
|
||||
local function net_def2(pos, node_name, net_name)
|
||||
local ndef = minetest.registered_nodes[node_name]
|
||||
if ndef and ndef.networks then
|
||||
return ndef.networks[net_name] or {}
|
||||
else -- hidden junction
|
||||
return hidden_node(pos, net_name)
|
||||
end
|
||||
end
|
||||
|
||||
local function connected(tlib2, pos, dir)
|
||||
local param2, npos = tlib2:get_primary_node_param2(pos, dir)
|
||||
if param2 then
|
||||
local d1, d2, num = tlib2:decode_param2(npos, param2)
|
||||
if not num then return end
|
||||
return Flip[dir] == d1 or Flip[dir] == d2
|
||||
end
|
||||
-- secondary nodes allowed?
|
||||
if tlib2.force_to_use_tubes then
|
||||
return tlib2:is_special_node(pos, dir)
|
||||
else
|
||||
return tlib2:is_secondary_node(pos, dir)
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
-- Calculate the node outdir based on node.param2 and nominal dir (according to side)
|
||||
local function dir_to_outdir(dir, param2)
|
||||
if dir < 5 then
|
||||
return ((dir + param2 - 1) % 4) + 1
|
||||
end
|
||||
return dir
|
||||
end
|
||||
|
||||
local function indir_to_dir(indir, param2)
|
||||
if indir < 5 then
|
||||
return ((indir - param2 + 5) % 4) + 1
|
||||
end
|
||||
return Flip[indir]
|
||||
end
|
||||
|
||||
local function outdir_to_dir(outdir, param2)
|
||||
if outdir < 5 then
|
||||
return ((outdir - param2 + 3) % 4) + 1
|
||||
end
|
||||
return outdir
|
||||
end
|
||||
|
||||
local function side_to_outdir(pos, side)
|
||||
return dir_to_outdir(SideToDir[side], techage.get_node_lvm(pos).param2)
|
||||
end
|
||||
|
||||
-- Get tlib2 connection dirs as table
|
||||
-- used e.g. for the connection walk
|
||||
local function get_node_connections(pos, net_name)
|
||||
local val = M(pos):get_int(net_name.."_conn")
|
||||
local tbl = {}
|
||||
if val % 0x40 >= 0x20 then tbl[#tbl+1] = 1 end
|
||||
if val % 0x20 >= 0x10 then tbl[#tbl+1] = 2 end
|
||||
if val % 0x10 >= 0x08 then tbl[#tbl+1] = 3 end
|
||||
if val % 0x08 >= 0x04 then tbl[#tbl+1] = 4 end
|
||||
if val % 0x04 >= 0x02 then tbl[#tbl+1] = 5 end
|
||||
if val % 0x02 >= 0x01 then tbl[#tbl+1] = 6 end
|
||||
return tbl
|
||||
end
|
||||
|
||||
-- store all node sides with tube connections as nodemeta
|
||||
local function node_connections(pos, tlib2)
|
||||
local node = techage.get_node_lvm(pos)
|
||||
local val = 0
|
||||
local ndef = net_def2(pos, node.name, tlib2.tube_type)
|
||||
local sides = ndef.sides or ndef.get_sides and ndef.get_sides(pos, node)
|
||||
if sides then
|
||||
for dir = 1,6 do
|
||||
val = val * 2
|
||||
local side = DirToSide[outdir_to_dir(dir, node.param2)]
|
||||
if sides[side] then
|
||||
if connected(tlib2, pos, dir) then
|
||||
--techage.mark_side("singleplayer", pos, dir, "node_connections", "", 1)--------------------
|
||||
val = val + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
M(pos):set_int(tlib2.tube_type.."_conn", val)
|
||||
else
|
||||
--error(pos, "sides missing")
|
||||
end
|
||||
end
|
||||
|
||||
local function pos_already_reached(pos)
|
||||
local key = minetest.hash_node_position(pos)
|
||||
if not Route[key] and NumNodes < MAX_NUM_NODES then
|
||||
Route[key] = true
|
||||
NumNodes = NumNodes + 1
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
-- check if the given pipe dir into the node is valid
|
||||
local function valid_indir(pos, indir, node, net_name)
|
||||
local ndef = net_def2(pos, node.name, net_name)
|
||||
local sides = ndef.sides or ndef.get_sides and ndef.get_sides(pos, node)
|
||||
local side = DirToSide[indir_to_dir(indir, node.param2)]
|
||||
if not sides or sides and not sides[side] then return false end
|
||||
return true
|
||||
end
|
||||
|
||||
local function is_junction(pos, name, tube_type)
|
||||
local ndef = net_def2(pos, name, tube_type)
|
||||
-- ntype can be a string or an array of strings or nil
|
||||
if ndef.ntype == "junc" then
|
||||
return true
|
||||
end
|
||||
if type(ndef.ntype) == "table" then
|
||||
for _,ntype in ipairs(ndef.ntype) do
|
||||
if ntype == "junc" then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
-- do the walk through the tubelib2 network
|
||||
-- indir is the direction which should not be covered by the walk
|
||||
-- (coming from there)
|
||||
-- if outdirs is given, only this dirs are used
|
||||
local function connection_walk(pos, outdirs, indir, node, tlib2, clbk)
|
||||
if clbk then clbk(pos, indir, node) end
|
||||
--techage.mark_position("singleplayer", pos, "walk", "", 1)
|
||||
--print("connection_walk", node.name, outdirs or is_junction(pos, node.name, tlib2.tube_type))
|
||||
if outdirs or is_junction(pos, node.name, tlib2.tube_type) then
|
||||
for _,outdir in pairs(outdirs or get_node_connections(pos, tlib2.tube_type)) do
|
||||
--techage.mark_side("singleplayer", pos, outdir, "connection_walk", "", 3)--------------------
|
||||
--print("get_node_connections", node.name, outdir)
|
||||
local pos2, indir2 = tlib2:get_connected_node_pos(pos, outdir)
|
||||
local node = techage.get_node_lvm(pos2)
|
||||
if pos2 and not pos_already_reached(pos2) and valid_indir(pos2, indir2, node, tlib2.tube_type) then
|
||||
connection_walk(pos2, nil, indir2, node, tlib2, clbk)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function collect_network_nodes(pos, outdir, tlib2)
|
||||
Route = {}
|
||||
NumNodes = 0
|
||||
pos_already_reached(pos)
|
||||
local netw = {}
|
||||
local node = techage.get_node_lvm(pos)
|
||||
local net_name = tlib2.tube_type
|
||||
-- outdir corresponds to the indir coming from
|
||||
connection_walk(pos, outdir and {outdir}, nil, node, tlib2, function(pos, indir, node)
|
||||
local ndef = net_def2(pos, node.name, net_name)
|
||||
-- ntype can be a string or an array of strings or nil
|
||||
local ntypes = ndef.ntype or {}
|
||||
if type(ntypes) == "string" then
|
||||
ntypes = {ntypes}
|
||||
end
|
||||
for _,ntype in ipairs(ntypes) do
|
||||
if not netw[ntype] then netw[ntype] = {} end
|
||||
netw[ntype][#netw[ntype] + 1] = {pos = pos, indir = indir, nominal = ndef.nominal, regenerative = ndef.regenerative}
|
||||
end
|
||||
end)
|
||||
netw.best_before = minetest.get_gametime() + BEST_BEFORE
|
||||
netw.num_nodes = NumNodes
|
||||
return netw
|
||||
end
|
||||
|
||||
-- keep data base small and valid
|
||||
-- needed for networks without scheduler
|
||||
local function remove_outdated_networks()
|
||||
local to_be_deleted = {}
|
||||
local t = minetest.get_gametime()
|
||||
for net_name,tbl in pairs(Networks) do
|
||||
for netID,network in pairs(tbl) do
|
||||
local valid = (network.best_before or 0) - t
|
||||
--output(network, valid)
|
||||
if valid < 0 then
|
||||
to_be_deleted[#to_be_deleted+1] = {net_name, netID}
|
||||
end
|
||||
end
|
||||
end
|
||||
for _,item in ipairs(to_be_deleted) do
|
||||
local net_name, netID = unpack(item)
|
||||
Networks[net_name][netID] = nil
|
||||
end
|
||||
minetest.after(60, remove_outdated_networks)
|
||||
end
|
||||
minetest.after(60, remove_outdated_networks)
|
||||
|
||||
--
|
||||
-- API Functions
|
||||
--
|
||||
|
||||
-- Table fo a 180 degree turn
|
||||
techage.networks.Flip = Flip
|
||||
|
||||
-- techage.networks.net_def(pos, net_name)
|
||||
techage.networks.net_def = net_def
|
||||
|
||||
techage.networks.AllSides = Sides -- table for all 6 node sides
|
||||
|
||||
-- techage.networks.side_to_outdir(pos, side)
|
||||
techage.networks.side_to_outdir = side_to_outdir
|
||||
|
||||
-- techage.networks.node_connections(pos, tlib2)
|
||||
techage.networks.node_connections = node_connections
|
||||
|
||||
-- techage.networks.collect_network_nodes(pos, outdir, tlib2)
|
||||
techage.networks.collect_network_nodes = collect_network_nodes
|
||||
|
||||
function techage.networks.connection_walk(pos, outdir, tlib2, clbk)
|
||||
Route = {}
|
||||
NumNodes = 0
|
||||
pos_already_reached(pos) -- don't consider the start pos
|
||||
local node = techage.get_node_lvm(pos)
|
||||
connection_walk(pos, outdir and {outdir}, Flip[outdir], node, tlib2, clbk)
|
||||
return NumNodes
|
||||
end
|
||||
|
||||
-- return network without maintainting the "alive" data
|
||||
function techage.networks.peek_network(tube_type, netID)
|
||||
--print("peek_network", debug(tube_type))
|
||||
return Networks[tube_type] and Networks[tube_type][netID]
|
||||
end
|
||||
|
||||
function techage.networks.set_network(tube_type, netID, network)
|
||||
if netID then
|
||||
if not Networks[tube_type] then
|
||||
Networks[tube_type] = {}
|
||||
end
|
||||
Networks[tube_type][netID] = network
|
||||
Networks[tube_type][netID].best_before = minetest.get_gametime() + BEST_BEFORE
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--
|
||||
-- Power API
|
||||
--
|
||||
function techage.networks.has_network(tube_type, netID)
|
||||
return Networks[tube_type] and Networks[tube_type][netID]
|
||||
end
|
||||
|
||||
function techage.networks.build_network(pos, outdir, tlib2, netID)
|
||||
local netw = collect_network_nodes(pos, outdir, tlib2)
|
||||
Networks[tlib2.tube_type] = Networks[tlib2.tube_type] or {}
|
||||
Networks[tlib2.tube_type][netID] = netw
|
||||
netw.alive = 3
|
||||
-- sort generating1 nodes, so that regenerative ones will be used first
|
||||
if netw.gen1 then
|
||||
table.sort(netw.gen1, function(a,b) return a.regenerative and not b.regenerative end)
|
||||
end
|
||||
techage.schedule.start(tlib2.tube_type, netID)
|
||||
end
|
||||
|
||||
function techage.networks.get_network(tube_type, netID)
|
||||
--print("get_network", string.format("%X", netID), debug(tube_type))
|
||||
local netw = Networks[tube_type] and Networks[tube_type][netID]
|
||||
if netw then
|
||||
netw.alive = 3 -- monitored by scheduler (power)
|
||||
netw.best_before = minetest.get_gametime() + BEST_BEFORE -- monitored by networks (liquids)
|
||||
return netw
|
||||
end
|
||||
end
|
||||
|
||||
function techage.networks.delete_network(tube_type, netID)
|
||||
if Networks[tube_type] and Networks[tube_type][netID] then
|
||||
Networks[tube_type][netID] = nil
|
||||
end
|
||||
end
|
||||
|
||||
-- Get node tubelib2 connections as table of outdirs
|
||||
-- techage.networks.get_node_connections(pos, net_name)
|
||||
techage.networks.get_node_connections = get_node_connections
|
||||
|
||||
techage.networks.MAX_NUM_NODES = MAX_NUM_NODES
|
@ -158,7 +158,9 @@ function techage.needs_power(nvm)
|
||||
return state == RUNNING or state == NOPOWER
|
||||
end
|
||||
|
||||
-- consumes power
|
||||
function techage.needs_power2(state)
|
||||
state = state or STOPPED
|
||||
return state == RUNNING or state == NOPOWER
|
||||
end
|
||||
|
||||
|
@ -19,6 +19,16 @@ local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end
|
||||
local S2P = minetest.string_to_pos
|
||||
local MP = minetest.get_modpath("minecart")
|
||||
|
||||
local Tube = techage.Tube
|
||||
|
||||
local function on_rightclick(pos, node, clicker)
|
||||
if clicker and clicker:is_player() then
|
||||
if M(pos):get_int("userID") == 0 then
|
||||
minecart.show_formspec(pos, clicker)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function formspec()
|
||||
return "size[8,6]"..
|
||||
default.gui_bg..
|
||||
@ -78,6 +88,7 @@ minetest.register_node("techage:chest_cart", {
|
||||
on_punch = minecart.on_nodecart_punch,
|
||||
allow_metadata_inventory_put = allow_metadata_inventory_put,
|
||||
allow_metadata_inventory_take = allow_metadata_inventory_take,
|
||||
on_rightclick = on_rightclick,
|
||||
|
||||
after_place_node = function(pos, placer)
|
||||
local inv = M(pos):get_inventory()
|
||||
@ -150,6 +161,8 @@ techage.register_node({"techage:chest_cart"}, {
|
||||
end,
|
||||
})
|
||||
|
||||
Tube:set_valid_sides("techage:chest_cart", {"L", "R", "F", "B"})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "techage:chest_cart",
|
||||
recipe = {
|
||||
|
@ -18,9 +18,9 @@ local S = techage.S
|
||||
local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end
|
||||
local S2P = minetest.string_to_pos
|
||||
local Pipe = techage.LiquidPipe
|
||||
local liquid = techage.liquid
|
||||
local MP = minetest.get_modpath("minecart")
|
||||
|
||||
local liquid = networks.liquid
|
||||
local CAPACITY = 100
|
||||
|
||||
local function on_rightclick(pos, node, clicker)
|
||||
@ -30,7 +30,7 @@ local function on_rightclick(pos, node, clicker)
|
||||
else
|
||||
local nvm = techage.get_nvm(pos)
|
||||
techage.set_activeformspec(pos, clicker)
|
||||
M(pos):set_string("formspec", liquid.formspec(pos, nvm))
|
||||
M(pos):set_string("formspec", techage.liquid.formspec(pos, nvm))
|
||||
minetest.get_node_timer(pos):start(2)
|
||||
end
|
||||
end
|
||||
@ -39,50 +39,48 @@ end
|
||||
local function node_timer(pos, elapsed)
|
||||
if techage.is_activeformspec(pos) then
|
||||
local nvm = techage.get_nvm(pos)
|
||||
M(pos):set_string("formspec", liquid.formspec(pos, nvm))
|
||||
M(pos):set_string("formspec", techage.liquid.formspec(pos, nvm))
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local function take_liquid(pos, indir, name, amount)
|
||||
amount, name = liquid.srv_take(pos, indir, name, amount)
|
||||
if techage.is_activeformspec(pos) then
|
||||
local function peek_liquid(pos)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
M(pos):set_string("formspec", liquid.formspec(pos, nvm))
|
||||
end
|
||||
return amount, name
|
||||
return liquid.srv_peek(nvm)
|
||||
end
|
||||
|
||||
local function untake_liquid(pos, indir, name, amount)
|
||||
local leftover = liquid.srv_put(pos, indir, name, amount)
|
||||
if techage.is_activeformspec(pos) then
|
||||
local function take_liquid(pos, indir, name, amount)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
M(pos):set_string("formspec", liquid.formspec(pos, nvm))
|
||||
amount, name = liquid.srv_take(nvm, name, amount)
|
||||
if techage.is_activeformspec(pos) then
|
||||
M(pos):set_string("formspec", techage.liquid.formspec(pos, nvm))
|
||||
end
|
||||
return leftover
|
||||
return amount, name
|
||||
end
|
||||
|
||||
local function put_liquid(pos, indir, name, amount)
|
||||
-- check if it is not powder
|
||||
local ndef = minetest.registered_craftitems[name] or {}
|
||||
if not ndef.groups or ndef.groups.powder ~= 1 then
|
||||
local leftover = liquid.srv_put(pos, indir, name, amount)
|
||||
if techage.is_activeformspec(pos) then
|
||||
local nvm = techage.get_nvm(pos)
|
||||
M(pos):set_string("formspec", liquid.formspec(pos, nvm))
|
||||
local leftover = liquid.srv_put(nvm, name, amount, CAPACITY)
|
||||
if techage.is_activeformspec(pos) then
|
||||
M(pos):set_string("formspec", techage.liquid.formspec(pos, nvm))
|
||||
end
|
||||
return leftover
|
||||
end
|
||||
return amount
|
||||
end
|
||||
|
||||
local networks_def = {
|
||||
pipe2 = {
|
||||
sides = {U = 1}, -- Pipe connection side
|
||||
ntype = "tank",
|
||||
},
|
||||
}
|
||||
local function untake_liquid(pos, indir, name, amount)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
local leftover = liquid.srv_put(nvm, name, amount, CAPACITY)
|
||||
if techage.is_activeformspec(pos) then
|
||||
M(pos):set_string("formspec", techage.liquid.formspec(pos, nvm))
|
||||
end
|
||||
return leftover
|
||||
end
|
||||
|
||||
minetest.register_node("techage:tank_cart", {
|
||||
description = S("TA Tank Cart"),
|
||||
@ -119,6 +117,7 @@ minetest.register_node("techage:tank_cart", {
|
||||
after_place_node = function(pos)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
nvm.liquid = nvm.liquid or {}
|
||||
M(pos):set_string("formspec", techage.liquid.formspec(pos, nvm))
|
||||
end,
|
||||
|
||||
set_cargo = function(pos, data)
|
||||
@ -134,26 +133,24 @@ minetest.register_node("techage:tank_cart", {
|
||||
end,
|
||||
|
||||
has_cargo = function(pos)
|
||||
return not liquid.is_empty(pos)
|
||||
return not techage.liquid.is_empty(pos)
|
||||
end,
|
||||
|
||||
on_timer = node_timer,
|
||||
|
||||
liquid = {
|
||||
capa = CAPACITY,
|
||||
peek = liquid.srv_peek,
|
||||
put = put_liquid,
|
||||
take = take_liquid,
|
||||
untake = untake_liquid,
|
||||
},
|
||||
networks = networks_def,
|
||||
on_rightclick = on_rightclick,
|
||||
})
|
||||
|
||||
techage.register_node({"techage:tank_cart"}, liquid.recv_message)
|
||||
|
||||
Pipe:add_secondary_node_names({"techage:tank_cart"})
|
||||
techage.register_node({"techage:tank_cart"}, techage.liquid.recv_message)
|
||||
|
||||
liquid.register_nodes({"techage:tank_cart"},
|
||||
Pipe, "tank", {"U"}, {
|
||||
capa = CAPACITY,
|
||||
peek = peek_liquid,
|
||||
put = put_liquid,
|
||||
take = take_liquid,
|
||||
untake = untake_liquid,
|
||||
}
|
||||
)
|
||||
|
||||
minecart.register_cart_entity("techage:tank_cart_entity", "techage:tank_cart", "tank", {
|
||||
initial_properties = {
|
||||
|
@ -3,7 +3,7 @@
|
||||
TechAge
|
||||
=======
|
||||
|
||||
Copyright (C) 2019-2020 Joachim Stolberg
|
||||
Copyright (C) 2019-2021 Joachim Stolberg
|
||||
|
||||
AGPL v3
|
||||
See LICENSE.txt for more information
|
||||
@ -17,8 +17,7 @@ local P2S = minetest.pos_to_string
|
||||
local M = minetest.get_meta
|
||||
local S = techage.S
|
||||
local Pipe = techage.LiquidPipe
|
||||
local networks = techage.networks
|
||||
local liquid = techage.liquid
|
||||
local liquid = networks.liquid
|
||||
local recipes = techage.recipes
|
||||
|
||||
local Liquids = {} -- {hash(pos) = {name = outdir},...}
|
||||
@ -27,26 +26,6 @@ local STANDBY_TICKS = 2
|
||||
local COUNTDOWN_TICKS = 3
|
||||
local CYCLE_TIME = 10
|
||||
|
||||
-- to mark the pump source and destinstion node
|
||||
local DebugCache = {}
|
||||
|
||||
local function set_starter_name(pos, clicker)
|
||||
local key = minetest.hash_node_position(pos)
|
||||
DebugCache[key] = {starter = clicker:get_player_name(), count = 10}
|
||||
end
|
||||
|
||||
local function get_starter_name(pos)
|
||||
local key = minetest.hash_node_position(pos)
|
||||
local def = DebugCache[key]
|
||||
if def then
|
||||
def.count = (def.count or 0) - 1
|
||||
if def.count > 0 then
|
||||
return def.starter
|
||||
end
|
||||
DebugCache[key] = nil
|
||||
end
|
||||
end
|
||||
|
||||
local function formspec(self, pos, nvm)
|
||||
return "size[6,3.6]"..
|
||||
default.gui_bg..
|
||||
@ -67,7 +46,7 @@ local function get_liquids(pos)
|
||||
-- determine the available input liquids
|
||||
local tbl = {}
|
||||
for outdir = 1,4 do
|
||||
local name, num = liquid.peek(pos, outdir)
|
||||
local name, num = liquid.peek(pos, Pipe, outdir)
|
||||
if name then
|
||||
tbl[name] = outdir
|
||||
end
|
||||
@ -87,7 +66,7 @@ local function reload_liquids(pos)
|
||||
-- determine the available input liquids
|
||||
local tbl = {}
|
||||
for outdir = 1,4 do
|
||||
local name, num = liquid.peek(pos, outdir)
|
||||
local name, num = liquid.peek(pos, Pipe, outdir)
|
||||
if name then
|
||||
tbl[name] = outdir
|
||||
end
|
||||
@ -155,7 +134,7 @@ local State = techage.NodeStates:new({
|
||||
|
||||
local function untake(pos, taken)
|
||||
for _,item in pairs(taken) do
|
||||
liquid.untake(pos, item.outdir, item.name, item.num)
|
||||
liquid.untake(pos, Pipe, item.outdir, item.name, item.num)
|
||||
end
|
||||
end
|
||||
|
||||
@ -198,9 +177,37 @@ local function dosing(pos, nvm, elapsed)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- check leftover
|
||||
local leftover
|
||||
local mem = techage.get_mem(pos)
|
||||
if mem.waste_leftover then
|
||||
leftover = reactor_cmnd(pos, "waste", {
|
||||
name = mem.waste_leftover.name,
|
||||
amount = mem.waste_leftover.num}) or mem.waste_leftover.num
|
||||
if leftover > 0 then
|
||||
mem.waste_leftover.num = leftover
|
||||
State:blocked(pos, nvm)
|
||||
return
|
||||
end
|
||||
mem.waste_leftover = nil
|
||||
end
|
||||
if mem.output_leftover then
|
||||
leftover = reactor_cmnd(pos, "output", {
|
||||
name = mem.output_leftover.name,
|
||||
amount = mem.output_leftover.num}) or mem.output_leftover.num
|
||||
if leftover > 0 then
|
||||
mem.output_leftover.num = leftover
|
||||
State:blocked(pos, nvm)
|
||||
return
|
||||
end
|
||||
mem.output_leftover = nil
|
||||
end
|
||||
|
||||
-- inputs
|
||||
local starter = get_starter_name(pos)
|
||||
local taken = {}
|
||||
mem.dbg_cycles = (mem.dbg_cycles or 0) - 1
|
||||
|
||||
for _,item in pairs(recipe.input) do
|
||||
if item.name ~= "" then
|
||||
local outdir = liquids[item.name] or reload_liquids(pos)[item.name]
|
||||
@ -210,7 +217,7 @@ local function dosing(pos, nvm, elapsed)
|
||||
untake(pos, taken)
|
||||
return
|
||||
end
|
||||
local num = liquid.take(pos, outdir, item.name, item.num, starter)
|
||||
local num = liquid.take(pos, Pipe, outdir, item.name, item.num, mem.dbg_cycles > 0)
|
||||
if num < item.num then
|
||||
taken[#taken + 1] = {outdir = outdir, name = item.name, num = num}
|
||||
State:standby(pos, nvm)
|
||||
@ -222,13 +229,13 @@ local function dosing(pos, nvm, elapsed)
|
||||
end
|
||||
end
|
||||
-- waste
|
||||
local leftover
|
||||
if recipe.waste.name ~= "" then
|
||||
leftover = reactor_cmnd(pos, "waste", {
|
||||
name = recipe.waste.name,
|
||||
amount = recipe.waste.num})
|
||||
if not leftover or (tonumber(leftover) or 1) > 0 then
|
||||
untake(pos, taken)
|
||||
amount = recipe.waste.num}) or recipe.waste.num
|
||||
if leftover > 0 then
|
||||
mem.waste_leftover = {name = recipe.waste.name, num = leftover}
|
||||
mem.output_leftover = {name = recipe.output.name, num = recipe.output.num}
|
||||
State:blocked(pos, nvm)
|
||||
reactor_cmnd(pos, "stop")
|
||||
return
|
||||
@ -237,9 +244,9 @@ local function dosing(pos, nvm, elapsed)
|
||||
-- output
|
||||
leftover = reactor_cmnd(pos, "output", {
|
||||
name = recipe.output.name,
|
||||
amount = recipe.output.num})
|
||||
if not leftover or (tonumber(leftover) or 1) > 0 then
|
||||
untake(pos, taken)
|
||||
amount = recipe.output.num}) or recipe.output.num
|
||||
if leftover > 0 then
|
||||
mem.output_leftover = {name = recipe.output.name, num = leftover}
|
||||
State:blocked(pos, nvm)
|
||||
reactor_cmnd(pos, "stop")
|
||||
return
|
||||
@ -267,19 +274,12 @@ local function on_receive_fields(pos, formname, fields, player)
|
||||
if not nvm.running then
|
||||
recipes.on_receive_fields(pos, formname, fields, player)
|
||||
end
|
||||
set_starter_name(pos, player)
|
||||
local mem = techage.get_mem(pos)
|
||||
mem.dbg_cycles = 5
|
||||
State:state_button_event(pos, nvm, fields)
|
||||
M(pos):set_string("formspec", formspec(State, pos, nvm))
|
||||
end
|
||||
|
||||
local nworks = {
|
||||
pipe2 = {
|
||||
sides = techage.networks.AllSides, -- Pipe connection sides
|
||||
ntype = "pump",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
minetest.register_node("techage:ta4_doser", {
|
||||
description = S("TA4 Doser"),
|
||||
tiles = {
|
||||
@ -301,19 +301,17 @@ minetest.register_node("techage:ta4_doser", {
|
||||
Pipe:after_place_node(pos)
|
||||
end,
|
||||
tubelib2_on_update2 = function(pos, dir, tlib2, node)
|
||||
liquid.update_network(pos, dir)
|
||||
liquid.update_network(pos, dir, tlib2, node)
|
||||
del_liquids(pos)
|
||||
end,
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
techage.remove_node(pos, oldnode, oldmetadata)
|
||||
Pipe:after_dig_node(pos)
|
||||
liquid.after_dig_pump(pos)
|
||||
techage.del_mem(pos)
|
||||
end,
|
||||
on_receive_fields = on_receive_fields,
|
||||
on_rightclick = on_rightclick,
|
||||
on_timer = node_timer,
|
||||
networks = nworks,
|
||||
|
||||
paramtype2 = "facedir",
|
||||
on_rotate = screwdriver.disallow,
|
||||
@ -341,13 +339,12 @@ minetest.register_node("techage:ta4_doser_on", {
|
||||
},
|
||||
|
||||
tubelib2_on_update2 = function(pos, dir, tlib2, node)
|
||||
liquid.update_network(pos, dir)
|
||||
liquid.update_network(pos, dir, tlib2, node)
|
||||
del_liquids(pos)
|
||||
end,
|
||||
on_receive_fields = on_receive_fields,
|
||||
on_rightclick = on_rightclick,
|
||||
on_timer = node_timer,
|
||||
networks = nworks,
|
||||
|
||||
paramtype2 = "facedir",
|
||||
on_rotate = screwdriver.disallow,
|
||||
@ -357,15 +354,14 @@ minetest.register_node("techage:ta4_doser_on", {
|
||||
sounds = default.node_sound_metal_defaults(),
|
||||
})
|
||||
|
||||
liquid.register_nodes({"techage:ta4_doser", "techage:ta4_doser_on"}, Pipe, "pump", nil, {})
|
||||
|
||||
techage.register_node({"techage:ta4_doser", "techage:ta4_doser_on"}, {
|
||||
on_recv_message = function(pos, src, topic, payload)
|
||||
return State:on_receive_message(pos, topic, payload)
|
||||
end,
|
||||
})
|
||||
|
||||
Pipe:add_secondary_node_names({"techage:ta4_doser", "techage:ta4_doser_on"})
|
||||
|
||||
|
||||
if minetest.global_exists("unified_inventory") then
|
||||
unified_inventory.register_craft_type("ta4_doser", {
|
||||
description = S("TA4 Reactor"),
|
||||
|
@ -17,10 +17,9 @@
|
||||
-- If necessary, this can be adjusted later.
|
||||
|
||||
local M = minetest.get_meta
|
||||
local networks = techage.networks
|
||||
local S = techage.S
|
||||
local Pipe = techage.LiquidPipe
|
||||
local liquid = techage.liquid
|
||||
local liquid = networks.liquid
|
||||
|
||||
-- Checks if the filter structure is ok and returns the amount of gravel
|
||||
local function checkStructure(pos)
|
||||
@ -100,12 +99,8 @@ minetest.register_node("techage:ta4_liquid_filter_filler", {
|
||||
after_place_node = function(pos)
|
||||
Pipe:after_place_node(pos)
|
||||
end,
|
||||
tubelib2_on_update2 = function(pos, dir, tlib2, node)
|
||||
liquid.update_network(pos)
|
||||
end,
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
Pipe:after_dig_node(pos)
|
||||
liquid.after_dig_pump(pos)
|
||||
techage.del_mem(pos)
|
||||
end,
|
||||
|
||||
@ -116,9 +111,10 @@ minetest.register_node("techage:ta4_liquid_filter_filler", {
|
||||
groups = {cracky=2},
|
||||
is_ground_content = false,
|
||||
sounds = default.node_sound_metal_defaults(),
|
||||
})
|
||||
|
||||
|
||||
liquid = {
|
||||
liquid.register_nodes({"techage:ta4_liquid_filter_filler"},
|
||||
Pipe, "tank", {"U"}, {
|
||||
capa = 1,
|
||||
peek = function(...) return nil end,
|
||||
put = function(pos, indir, name, amount)
|
||||
@ -134,7 +130,7 @@ minetest.register_node("techage:ta4_liquid_filter_filler", {
|
||||
end
|
||||
if math.random() < 0.5 then
|
||||
local out_pos = {x=pos.x,y=pos.y-8,z=pos.z}
|
||||
local leftover = liquid.put(out_pos, networks.side_to_outdir(out_pos, "R"), "techage:lye", 1)
|
||||
local leftover = liquid.put(out_pos, Pipe, networks.side_to_outdir(out_pos, "R"), "techage:lye", 1)
|
||||
if leftover > 0 then
|
||||
return amount
|
||||
end
|
||||
@ -147,15 +143,9 @@ minetest.register_node("techage:ta4_liquid_filter_filler", {
|
||||
untake = function(pos, outdir, name, amount, player_name)
|
||||
return amount
|
||||
end,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
networks = {
|
||||
pipe2 = {
|
||||
sides = {U = 1}, -- Pipe connection sides
|
||||
ntype = "tank",
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_node("techage:ta4_liquid_filter_sink", {
|
||||
description = S("TA4 Liquid Filter Sink"),
|
||||
@ -182,9 +172,6 @@ minetest.register_node("techage:ta4_liquid_filter_sink", {
|
||||
after_place_node = function(pos)
|
||||
Pipe:after_place_node(pos)
|
||||
end,
|
||||
tubelib2_on_update2 = function(pos, dir, tlib2, node)
|
||||
liquid.update_network(pos)
|
||||
end,
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
Pipe:after_dig_node(pos)
|
||||
end,
|
||||
@ -196,16 +183,12 @@ minetest.register_node("techage:ta4_liquid_filter_sink", {
|
||||
groups = {cracky=2},
|
||||
is_ground_content = false,
|
||||
sounds = default.node_sound_metal_defaults(),
|
||||
|
||||
networks = {
|
||||
pipe2 = {
|
||||
sides = {R = 1}, -- Pipe connection sides
|
||||
ntype = "pump",
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
Pipe:add_secondary_node_names({"techage:ta4_liquid_filter_filler", "techage:ta4_liquid_filter_sink"})
|
||||
liquid.register_nodes({"techage:ta4_liquid_filter_sink"},
|
||||
Pipe, "pump", {"R"}, {}
|
||||
)
|
||||
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'techage:ta4_liquid_filter_filler',
|
||||
|
@ -15,8 +15,8 @@
|
||||
local S = techage.S
|
||||
local M = minetest.get_meta
|
||||
local Pipe = techage.LiquidPipe
|
||||
local networks = techage.networks
|
||||
local liquid = techage.liquid
|
||||
local Cable = techage.ElectricCable
|
||||
local liquid = networks.liquid
|
||||
|
||||
minetest.register_node("techage:ta4_reactor_fillerpipe", {
|
||||
description = S("TA4 Reactor Filler Pipe"),
|
||||
@ -48,9 +48,6 @@ minetest.register_node("techage:ta4_reactor_fillerpipe", {
|
||||
Pipe:after_place_node(pos1)
|
||||
end
|
||||
end,
|
||||
tubelib2_on_update2 = function(pos, dir, tlib2, node)
|
||||
liquid.update_network(pos)
|
||||
end,
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
Pipe:after_dig_node(pos)
|
||||
end,
|
||||
@ -63,13 +60,6 @@ minetest.register_node("techage:ta4_reactor_fillerpipe", {
|
||||
groups = {cracky=2},
|
||||
is_ground_content = false,
|
||||
sounds = default.node_sound_metal_defaults(),
|
||||
|
||||
networks = {
|
||||
pipe2 = {
|
||||
sides = {U = 1}, -- Pipe connection sides
|
||||
ntype = "tank",
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
local function stand_cmnd(pos, cmnd, payload)
|
||||
@ -85,7 +75,7 @@ end
|
||||
local function base_waste(pos, payload)
|
||||
local pos2 = {x = pos.x, y = pos.y-3, z = pos.z}
|
||||
local outdir = M(pos2):get_int("outdir")
|
||||
return liquid.put(pos2, outdir, payload.name, payload.amount, payload.player_name)
|
||||
return liquid.put(pos2, Pipe, outdir, payload.name, payload.amount, payload.player_name)
|
||||
end
|
||||
|
||||
-- controlled by the doser
|
||||
@ -117,6 +107,8 @@ techage.register_node({"techage:ta4_reactor_fillerpipe"}, {
|
||||
end,
|
||||
})
|
||||
|
||||
liquid.register_nodes({"techage:ta4_reactor_fillerpipe"}, Pipe, "tank", {"U"}, {})
|
||||
|
||||
local function formspec()
|
||||
local title = S("TA4 Reactor")
|
||||
return "size[8,6]"..
|
||||
@ -176,8 +168,6 @@ minetest.register_node("techage:ta4_reactor", {
|
||||
sounds = default.node_sound_metal_defaults(),
|
||||
})
|
||||
|
||||
Pipe:add_secondary_node_names({"techage:ta4_reactor_fillerpipe"})
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'techage:ta4_reactor',
|
||||
recipe = {
|
||||
|
@ -3,7 +3,7 @@
|
||||
TechAge
|
||||
=======
|
||||
|
||||
Copyright (C) 2019-2020 Joachim Stolberg
|
||||
Copyright (C) 2019-2021 Joachim Stolberg
|
||||
|
||||
AGPL v3
|
||||
See LICENSE.txt for more information
|
||||
@ -15,13 +15,12 @@
|
||||
local S = techage.S
|
||||
local M = minetest.get_meta
|
||||
local Cable = techage.ElectricCable
|
||||
local power = techage.power
|
||||
local Pipe = techage.LiquidPipe
|
||||
local networks = techage.networks
|
||||
local liquid = techage.liquid
|
||||
local power = networks.power
|
||||
local liquid = networks.liquid
|
||||
|
||||
local PWR_NEEDED = 8
|
||||
local CYCLE_TIME = 4
|
||||
local CYCLE_TIME = 2
|
||||
|
||||
local function play_sound(pos)
|
||||
local mem = techage.get_mem(pos)
|
||||
@ -49,18 +48,18 @@ local function on_power(pos)
|
||||
M(pos):set_string("infotext", S("on"))
|
||||
play_sound(pos)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
nvm.has_power = true
|
||||
nvm.running = true
|
||||
end
|
||||
|
||||
local function on_nopower(pos)
|
||||
M(pos):set_string("infotext", S("no power"))
|
||||
stop_sound(pos)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
nvm.has_power = false
|
||||
nvm.running = false
|
||||
end
|
||||
|
||||
local function is_running(pos, nvm)
|
||||
return nvm.has_power
|
||||
return nvm.running
|
||||
end
|
||||
|
||||
minetest.register_node("techage:ta4_reactor_stand", {
|
||||
@ -103,21 +102,19 @@ minetest.register_node("techage:ta4_reactor_stand", {
|
||||
Pipe:after_place_node(pos)
|
||||
Cable:after_place_node(pos)
|
||||
end,
|
||||
tubelib2_on_update2 = function(pos, dir, tlib2, node)
|
||||
if tlib2.tube_type == "ele1" then
|
||||
power.update_network(pos, dir, tlib2)
|
||||
else
|
||||
liquid.update_network(pos, dir, tlib2)
|
||||
end
|
||||
end,
|
||||
on_timer = function(pos, elapsed)
|
||||
power.consumer_alive(pos, Cable, CYCLE_TIME)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
local consumed = power.consume_power(pos, Cable, nil, PWR_NEEDED)
|
||||
if not nvm.running and consumed == PWR_NEEDED then
|
||||
on_power(pos)
|
||||
elseif nvm.running and consumed < PWR_NEEDED then
|
||||
on_nopower(pos)
|
||||
end
|
||||
return true
|
||||
end,
|
||||
after_dig_node = function(pos, oldnode)
|
||||
Pipe:after_dig_node(pos)
|
||||
Cable:after_dig_node(pos)
|
||||
liquid.after_dig_pump(pos)
|
||||
techage.del_mem(pos)
|
||||
end,
|
||||
|
||||
@ -128,21 +125,6 @@ minetest.register_node("techage:ta4_reactor_stand", {
|
||||
groups = {cracky=2},
|
||||
is_ground_content = false,
|
||||
sounds = default.node_sound_metal_defaults(),
|
||||
|
||||
networks = {
|
||||
pipe2 = {
|
||||
sides = {R=1},
|
||||
ntype = "pump",
|
||||
},
|
||||
ele1 = {
|
||||
sides = {L=1},
|
||||
ntype = "con1",
|
||||
on_power = on_power,
|
||||
on_nopower = on_nopower,
|
||||
nominal = PWR_NEEDED,
|
||||
is_running = is_running,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
-- controlled by the fillerpipe
|
||||
@ -150,21 +132,19 @@ techage.register_node({"techage:ta4_reactor_stand"}, {
|
||||
on_transfer = function(pos, in_dir, topic, payload)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
if topic == "power" then
|
||||
return nvm.has_power or power.power_available(pos, Cable)
|
||||
return nvm.running or power.power_available(pos, Cable)
|
||||
elseif topic == "output" then
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
return liquid.put(pos, outdir, payload.name, payload.amount, payload.player_name)
|
||||
return liquid.put(pos, Pipe, outdir, payload.name, payload.amount, payload.player_name)
|
||||
elseif topic == "can_start" then
|
||||
return power.power_available(pos, Cable)
|
||||
elseif topic == "start" then
|
||||
nvm.has_power = false
|
||||
power.consumer_start(pos, Cable, CYCLE_TIME)
|
||||
nvm.running = false
|
||||
minetest.get_node_timer(pos):start(CYCLE_TIME)
|
||||
M(pos):set_string("infotext", "...")
|
||||
return true
|
||||
elseif topic == "stop" then
|
||||
nvm.has_power = false
|
||||
power.consumer_stop(pos, Cable)
|
||||
stop_sound(pos)
|
||||
minetest.get_node_timer(pos):stop()
|
||||
M(pos):set_string("infotext", S("off"))
|
||||
@ -195,9 +175,6 @@ minetest.register_node("techage:ta4_reactor_base", {
|
||||
M(pos):set_int("outdir", networks.side_to_outdir(pos, "R"))
|
||||
Pipe:after_place_node(pos)
|
||||
end,
|
||||
tubelib2_on_update2 = function(pos, dir, tlib2, node)
|
||||
liquid.update_network(pos, dir, tlib2)
|
||||
end,
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
Pipe:after_dig_node(pos)
|
||||
end,
|
||||
@ -207,21 +184,11 @@ minetest.register_node("techage:ta4_reactor_base", {
|
||||
groups = {cracky=2},
|
||||
is_ground_content = false,
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
|
||||
networks = {
|
||||
pipe2 = {
|
||||
sides = {R=1}, -- Pipe connection sides
|
||||
ntype = "pump",
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
Pipe:add_secondary_node_names({
|
||||
"techage:ta4_reactor_base",
|
||||
"techage:ta4_reactor_stand",
|
||||
})
|
||||
|
||||
Cable:add_secondary_node_names({"techage:ta4_reactor_stand"})
|
||||
liquid.register_nodes({"techage:ta4_reactor_base"}, Pipe, "pump", {"R"}, {})
|
||||
liquid.register_nodes({"techage:ta4_reactor_stand"}, Pipe, "pump", {"R"}, {})
|
||||
power.register_nodes({"techage:ta4_reactor_stand"}, Cable, "con", {"L"})
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'techage:ta4_reactor_stand',
|
||||
|
@ -3,7 +3,7 @@
|
||||
TechAge
|
||||
=======
|
||||
|
||||
Copyright (C) 2019-2020 Joachim Stolberg
|
||||
Copyright (C) 2019-2021 Joachim Stolberg
|
||||
|
||||
AGPL v3
|
||||
See LICENSE.txt for more information
|
||||
@ -16,25 +16,17 @@
|
||||
local M = minetest.get_meta
|
||||
local S = techage.S
|
||||
|
||||
local Cable = techage.ElectricCable
|
||||
local power = networks.power
|
||||
local control = networks.control
|
||||
|
||||
local CYCLE_TIME = 2
|
||||
local STANDBY_TICKS = 4
|
||||
local COUNTDOWN_TICKS = 4
|
||||
local CYCLE_TIME = 2
|
||||
local PWR_CAPA = 80
|
||||
|
||||
local Cable = techage.ElectricCable
|
||||
local power = techage.power
|
||||
local networks = techage.networks
|
||||
local PWR_PERF = 80
|
||||
|
||||
local function formspec(self, pos, nvm)
|
||||
return "size[4,4]"..
|
||||
"box[0,-0.1;3.8,0.5;#c6e8ff]"..
|
||||
"label[1,-0.1;"..minetest.colorize( "#000000", S("Generator")).."]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
power.formspec_label_bar(pos, 0, 0.8, S("power"), PWR_CAPA, nvm.provided)..
|
||||
"image_button[2.8,2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
|
||||
"tooltip[2.8,2;1,1;"..self:get_state_tooltip(nvm).."]"
|
||||
return techage.generator_formspec(self, pos, nvm, S("Generator"), nvm.provided, PWR_PERF)
|
||||
end
|
||||
|
||||
local function transfer_turbine(pos, topic, payload)
|
||||
@ -46,19 +38,25 @@ local function can_start(pos, nvm, state)
|
||||
return (nvm.firebox_trigger or 0) > 0 -- by means of firebox
|
||||
end
|
||||
|
||||
local function has_fire(nvm)
|
||||
nvm.firebox_trigger = (nvm.firebox_trigger or 0) - 1
|
||||
return nvm.firebox_trigger > 0
|
||||
end
|
||||
|
||||
local function start_node(pos, nvm, state)
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
power.generator_start(pos, Cable, CYCLE_TIME, outdir)
|
||||
local meta = M(pos)
|
||||
nvm.provided = 0
|
||||
local outdir = meta:get_int("outdir")
|
||||
transfer_turbine(pos, "start")
|
||||
nvm.running = true
|
||||
power.start_storage_calc(pos, Cable, outdir)
|
||||
techage.evaluate_charge_termination(nvm, meta)
|
||||
end
|
||||
|
||||
local function stop_node(pos, nvm, state)
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
power.generator_stop(pos, Cable, outdir)
|
||||
nvm.provided = 0
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
transfer_turbine(pos, "stop")
|
||||
nvm.running = false
|
||||
power.start_storage_calc(pos, Cable, outdir)
|
||||
end
|
||||
|
||||
local State = techage.NodeStates:new({
|
||||
@ -75,14 +73,24 @@ local State = techage.NodeStates:new({
|
||||
|
||||
local function node_timer(pos, elapsed)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
nvm.firebox_trigger = (nvm.firebox_trigger or 0) - 1
|
||||
if nvm.firebox_trigger <= 0 then
|
||||
State:nopower(pos, nvm)
|
||||
local running = techage.is_running(nvm)
|
||||
local fire = has_fire(nvm)
|
||||
if running and not fire then
|
||||
State:standby(pos, nvm)
|
||||
stop_node(pos, nvm, State)
|
||||
transfer_turbine(pos, "stop")
|
||||
else
|
||||
local outdir = M(pos):get_int("outdir")
|
||||
nvm.provided = power.generator_alive(pos, Cable, CYCLE_TIME, outdir)
|
||||
elseif not running and fire then
|
||||
State:start(pos, nvm)
|
||||
-- start_node() is called implicit
|
||||
elseif running then
|
||||
local meta = M(pos)
|
||||
local outdir = meta:get_int("outdir")
|
||||
local tp1 = tonumber(meta:get_string("termpoint1"))
|
||||
local tp2 = tonumber(meta:get_string("termpoint2"))
|
||||
nvm.provided = power.provide_power(pos, Cable, outdir, PWR_PERF, tp1, tp2)
|
||||
local val = power.get_storage_load(pos, Cable, outdir, PWR_PERF)
|
||||
if val > 0 then
|
||||
nvm.load = val
|
||||
end
|
||||
State:keep_running(pos, nvm, COUNTDOWN_TICKS)
|
||||
end
|
||||
if techage.is_activeformspec(pos) then
|
||||
@ -119,17 +127,12 @@ local function after_dig_node(pos, oldnode)
|
||||
techage.del_mem(pos)
|
||||
end
|
||||
|
||||
local function tubelib2_on_update2(pos, outdir, tlib2, node)
|
||||
power.update_network(pos, outdir, tlib2)
|
||||
local function get_generator_data(pos, outdir, tlib2)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
if techage.is_running(nvm) then
|
||||
return {level = (nvm.load or 0) / PWR_PERF, perf = PWR_PERF, capa = PWR_PERF * 2}
|
||||
end
|
||||
end
|
||||
|
||||
local net_def = {
|
||||
ele1 = {
|
||||
sides = {R = 1},
|
||||
ntype = "gen1",
|
||||
nominal = PWR_CAPA,
|
||||
},
|
||||
}
|
||||
|
||||
minetest.register_node("techage:generator", {
|
||||
description = S("TA3 Generator"),
|
||||
@ -148,8 +151,8 @@ minetest.register_node("techage:generator", {
|
||||
on_timer = node_timer,
|
||||
after_place_node = after_place_node,
|
||||
after_dig_node = after_dig_node,
|
||||
tubelib2_on_update2 = tubelib2_on_update2,
|
||||
networks = net_def,
|
||||
get_generator_data = get_generator_data,
|
||||
ta3_formspec = techage.generator_settings("ta3", PWR_PERF),
|
||||
|
||||
paramtype2 = "facedir",
|
||||
groups = {cracky=2, crumbly=2, choppy=2},
|
||||
@ -193,8 +196,8 @@ minetest.register_node("techage:generator_on", {
|
||||
on_timer = node_timer,
|
||||
after_place_node = after_place_node,
|
||||
after_dig_node = after_dig_node,
|
||||
tubelib2_on_update2 = tubelib2_on_update2,
|
||||
networks = net_def,
|
||||
get_generator_data = get_generator_data,
|
||||
ta3_formspec = techage.generator_settings("ta3", PWR_PERF),
|
||||
|
||||
drop = "",
|
||||
paramtype2 = "facedir",
|
||||
@ -205,7 +208,7 @@ minetest.register_node("techage:generator_on", {
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
})
|
||||
|
||||
Cable:add_secondary_node_names({"techage:generator", "techage:generator_on"})
|
||||
power.register_nodes({"techage:generator", "techage:generator_on"}, Cable, "gen", {"R"})
|
||||
|
||||
-- controlled by the turbine
|
||||
techage.register_node({"techage:generator", "techage:generator_on"}, {
|
||||
@ -213,8 +216,8 @@ techage.register_node({"techage:generator", "techage:generator_on"}, {
|
||||
local nvm = techage.get_nvm(pos)
|
||||
if topic == "trigger" then
|
||||
nvm.firebox_trigger = 3
|
||||
if nvm.running then
|
||||
return math.max((nvm.provided or PWR_CAPA) / PWR_CAPA, 0.02)
|
||||
if techage.is_running(nvm) then
|
||||
return math.max((nvm.provided or PWR_PERF) / PWR_PERF, 0.02)
|
||||
else
|
||||
return 0
|
||||
end
|
||||
@ -230,6 +233,28 @@ techage.register_node({"techage:generator", "techage:generator_on"}, {
|
||||
end,
|
||||
})
|
||||
|
||||
-- used by power terminal
|
||||
control.register_nodes({"techage:generator", "techage:generator_on"}, {
|
||||
on_receive = function(pos, tlib2, topic, payload)
|
||||
end,
|
||||
on_request = function(pos, tlib2, topic)
|
||||
if topic == "info" then
|
||||
local nvm = techage.get_nvm(pos)
|
||||
local meta = M(pos)
|
||||
return {
|
||||
type = S("TA3 Generator"),
|
||||
number = meta:get_string("node_number") or "",
|
||||
running = techage.is_running(nvm) or false,
|
||||
available = PWR_PERF,
|
||||
provided = nvm.provided or 0,
|
||||
termpoint = meta:get_string("termpoint"),
|
||||
}
|
||||
end
|
||||
return false
|
||||
end,
|
||||
}
|
||||
)
|
||||
|
||||
minetest.register_craft({
|
||||
output = "techage:generator",
|
||||
recipe = {
|
||||
|
@ -3,7 +3,7 @@
|
||||
TechAge
|
||||
=======
|
||||
|
||||
Copyright (C) 2019-2020 Joachim Stolberg
|
||||
Copyright (C) 2019-2021 Joachim Stolberg
|
||||
|
||||
AGPL v3
|
||||
See LICENSE.txt for more information
|
||||
@ -20,7 +20,7 @@ local S = techage.S
|
||||
local firebox = techage.firebox
|
||||
local fuel = techage.fuel
|
||||
local Pipe = techage.LiquidPipe
|
||||
local liquid = techage.liquid
|
||||
local liquid = networks.liquid
|
||||
|
||||
local CYCLE_TIME = 2
|
||||
local BURN_CYCLE_FACTOR = 0.5
|
||||
@ -115,44 +115,10 @@ minetest.register_node("techage:oilfirebox", {
|
||||
minetest.after(1, start_firebox, pos, nvm)
|
||||
end
|
||||
end,
|
||||
|
||||
liquid = {
|
||||
capa = fuel.CAPACITY,
|
||||
fuel_cat = fuel.BT_BITUMEN,
|
||||
peek = liquid.srv_peek,
|
||||
put = function(pos, indir, name, amount)
|
||||
if fuel.valid_fuel(name, fuel.BT_BITUMEN) then
|
||||
local leftover = liquid.srv_put(pos, indir, name, amount)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
nvm.liquid = nvm.liquid or {}
|
||||
nvm.liquid.amount = nvm.liquid.amount or 0
|
||||
start_firebox(pos, nvm)
|
||||
if techage.is_activeformspec(pos) then
|
||||
local nvm = techage.get_nvm(pos)
|
||||
M(pos):set_string("formspec", fuel.formspec(nvm))
|
||||
end
|
||||
return leftover
|
||||
end
|
||||
return amount
|
||||
end,
|
||||
take = function(pos, indir, name, amount)
|
||||
amount, name = liquid.srv_take(pos, indir, name, amount)
|
||||
if techage.is_activeformspec(pos) then
|
||||
local nvm = techage.get_nvm(pos)
|
||||
M(pos):set_string("formspec", fuel.formspec(nvm))
|
||||
end
|
||||
return amount, name
|
||||
end
|
||||
},
|
||||
networks = {
|
||||
pipe2 = {
|
||||
sides = techage.networks.AllSides, -- Pipe connection sides
|
||||
ntype = "tank",
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
Pipe:add_secondary_node_names({"techage:oilfirebox"})
|
||||
liquid.register_nodes({"techage:oilfirebox"},
|
||||
Pipe, "tank", nil, fuel.get_liquid_table(fuel.BT_OIL, fuel.CAPACITY, start_firebox))
|
||||
|
||||
|
||||
techage.register_node({"techage:oilfirebox"}, {
|
||||
@ -161,7 +127,7 @@ techage.register_node({"techage:oilfirebox"}, {
|
||||
if topic == "state" then
|
||||
return nvm.running and "running" or "stopped"
|
||||
elseif topic == "fuel" then
|
||||
return techage.fuel.get_fuel_amount(nvm)
|
||||
return fuel.get_fuel_amount(nvm)
|
||||
else
|
||||
return "unsupported"
|
||||
end
|
||||
|