diff --git a/README.md b/README.md index cc269b5..b5a0e1c 100644 --- a/README.md +++ b/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: diff --git a/autobahn/README.md b/autobahn/README.md index 7cdeb1d..c781c3f 100644 --- a/autobahn/README.md +++ b/autobahn/README.md @@ -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 diff --git a/autobahn/init.lua b/autobahn/init.lua index a55b0ad..7ae3ce3 100644 --- a/autobahn/init.lua +++ b/autobahn/init.lua @@ -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 = { diff --git a/hyperloop/booking_node.lua b/hyperloop/booking_node.lua index 4b4809d..4f0ae13 100644 --- a/hyperloop/booking_node.lua +++ b/hyperloop/booking_node.lua @@ -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", diff --git a/hyperloop/elevator.lua b/hyperloop/elevator.lua index 0a0daf1..94ac74d 100644 --- a/hyperloop/elevator.lua +++ b/hyperloop/elevator.lua @@ -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").."]" - 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).."]" - if vector.equals(floor.pos, pos) then - tRes[#tRes+1] = "label[2.5,"..ypos..";"..S("(current position)").."]" - else - tRes[#tRes+1] = "label[2.5,"..ypos..";"..(floor.name or "").."]" - end - end - if #tRes == 2 then + 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 + local ypos = 0.5 + idx*0.8 + local ypos2 = ypos - 0.2 + 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,"..ypos..";"..S("(current position)").."]" + else + tRes[#tRes+1] = "label[2,"..ypos..";"..(floor.name or "").."]" + end + end + 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 "").."]" + end + end + tRes[#tRes+1] = "scroll_container_end[]" end return table.concat(tRes) end diff --git a/hyperloop/network.lua b/hyperloop/network.lua index ea9611f..ae08c19 100644 --- a/hyperloop/network.lua +++ b/hyperloop/network.lua @@ -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 diff --git a/minecart/api.lua b/minecart/api.lua index d93e188..e32d1b2 100644 --- a/minecart/api.lua +++ b/minecart/api.lua @@ -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 diff --git a/minecart/baselib.lua b/minecart/baselib.lua index d0c035a..505f242 100644 --- a/minecart/baselib.lua +++ b/minecart/baselib.lua @@ -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 {} diff --git a/minecart/entitylib.lua b/minecart/entitylib.lua index bf20953..b069421 100644 --- a/minecart/entitylib.lua +++ b/minecart/entitylib.lua @@ -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 diff --git a/minecart/locale/minecart.de.tr b/minecart/locale/minecart.de.tr index 615b0cc..4a52888 100644 --- a/minecart/locale/minecart.de.tr +++ b/minecart/locale/minecart.de.tr @@ -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" diff --git a/minecart/locale/template.txt b/minecart/locale/template.txt index b9a4ae5..7c64c6b 100644 --- a/minecart/locale/template.txt +++ b/minecart/locale/template.txt @@ -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"= diff --git a/minecart/nodelib.lua b/minecart/nodelib.lua index efb540c..098fc73 100644 --- a/minecart/nodelib.lua +++ b/minecart/nodelib.lua @@ -30,10 +30,15 @@ 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) - M(pos):set_string("infotext", - minetest.get_color_escape_sequence("#FFFF00") .. owner .. ": 0") - return + --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 @@ -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 diff --git a/minecart/protection.lua b/minecart/protection.lua index 6d4a542..1df495f 100644 --- a/minecart/protection.lua +++ b/minecart/protection.lua @@ -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}, diff --git a/minecart/rails.lua b/minecart/rails.lua index b7b5622..0448bd7 100644 --- a/minecart/rails.lua +++ b/minecart/rails.lua @@ -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, --}) + diff --git a/minecart/recording.lua b/minecart/recording.lua index d516a47..78bb36e 100644 --- a/minecart/recording.lua +++ b/minecart/recording.lua @@ -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 diff --git a/minecart/screenshot.png b/minecart/screenshot.png index 247e462..4511f22 100644 Binary files a/minecart/screenshot.png and b/minecart/screenshot.png differ diff --git a/minecart/storage.lua b/minecart/storage.lua index 04e471f..96eb7e1 100644 --- a/minecart/storage.lua +++ b/minecart/storage.lua @@ -52,7 +52,7 @@ minetest.register_on_mods_loaded(function() for owner, carts in pairs(t) do minecart.CartsOnRail[owner] = {} for userID, cart in pairs(carts) do - print("reload cart", owner, userID, cart.objID) + print("reload cart", owner, userID, cart.objID) minecart.CartsOnRail[owner][userID] = cart -- mark all entity carts as zombified if cart.objID and cart.objID ~= 0 then @@ -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" diff --git a/minecart/tool.lua b/minecart/tool.lua index c5b192c..bc8d297 100644 --- a/minecart/tool.lua +++ b/minecart/tool.lua @@ -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 diff --git a/networks/LICENSE.txt b/networks/LICENSE.txt new file mode 100644 index 0000000..2beb9e1 --- /dev/null +++ b/networks/LICENSE.txt @@ -0,0 +1,662 @@ + GNU AFFERO GENERAL PUBLIC LICENSE + Version 3, 19 November 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + 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. + + + Copyright (C) + + 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 . + +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 +. + diff --git a/networks/README.md b/networks/README.md new file mode 100644 index 0000000..2ab1d24 --- /dev/null +++ b/networks/README.md @@ -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 diff --git a/networks/control.lua b/networks/control.lua new file mode 100644 index 0000000..87060d8 --- /dev/null +++ b/networks/control.lua @@ -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 diff --git a/networks/hidden.lua b/networks/hidden.lua new file mode 100644 index 0000000..4e4a3d4 --- /dev/null +++ b/networks/hidden.lua @@ -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 + diff --git a/networks/init.lua b/networks/init.lua new file mode 100644 index 0000000..bed92ef --- /dev/null +++ b/networks/init.lua @@ -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 \ No newline at end of file diff --git a/techage/power/junction.lua b/networks/junction.lua similarity index 72% rename from techage/power/junction.lua rename to networks/junction.lua index e14c3ef..8832a59 100644 --- a/techage/power/junction.lua +++ b/networks/junction.lua @@ -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 diff --git a/networks/liquid.lua b/networks/liquid.lua new file mode 100644 index 0000000..9e53097 --- /dev/null +++ b/networks/liquid.lua @@ -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 = "" + 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 diff --git a/networks/mod.conf b/networks/mod.conf new file mode 100644 index 0000000..ebce7c7 --- /dev/null +++ b/networks/mod.conf @@ -0,0 +1,4 @@ +name = networks +depends = screwdriver,tubelib2 +description = Build and manage networks based on tubelib2 tubes/pipes/cables + diff --git a/networks/networks.lua b/networks/networks.lua new file mode 100644 index 0000000..4cca46a --- /dev/null +++ b/networks/networks.lua @@ -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 = , ...}, ...} +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 diff --git a/networks/observer.lua b/networks/observer.lua new file mode 100644 index 0000000..f6676a9 --- /dev/null +++ b/networks/observer.lua @@ -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 \ No newline at end of file diff --git a/networks/power.lua b/networks/power.lua new file mode 100644 index 0000000..45433d4 --- /dev/null +++ b/networks/power.lua @@ -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 diff --git a/networks/screenshot.png b/networks/screenshot.png new file mode 100644 index 0000000..9010f4a Binary files /dev/null and b/networks/screenshot.png differ diff --git a/networks/settingtypes.txt b/networks/settingtypes.txt new file mode 100644 index 0000000..22d9819 --- /dev/null +++ b/networks/settingtypes.txt @@ -0,0 +1,2 @@ +# Enable some nodes for testing/demo purposes +networks_test_enabled (test nodes enabled) bool false diff --git a/networks/test/test_control.lua b/networks/test/test_control.lua new file mode 100644 index 0000000..6c8bb0c --- /dev/null +++ b/networks/test/test_control.lua @@ -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, + } +) + diff --git a/networks/test/test_liquid.lua b/networks/test/test_liquid.lua new file mode 100644 index 0000000..7f15328 --- /dev/null +++ b/networks/test/test_liquid.lua @@ -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", {}, {}) diff --git a/networks/test/test_power.lua b/networks/test/test_power.lua new file mode 100644 index 0000000..033d9f2 --- /dev/null +++ b/networks/test/test_power.lua @@ -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 + diff --git a/networks/test/test_tool.lua b/networks/test/test_tool.lua new file mode 100644 index 0000000..a370b6f --- /dev/null +++ b/networks/test/test_tool.lua @@ -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, +}) diff --git a/networks/textures/networks_arrow.png b/networks/textures/networks_arrow.png new file mode 100644 index 0000000..d04f43c Binary files /dev/null and b/networks/textures/networks_arrow.png differ diff --git a/networks/textures/networks_cable.png b/networks/textures/networks_cable.png new file mode 100644 index 0000000..e974a6b Binary files /dev/null and b/networks/textures/networks_cable.png differ diff --git a/networks/textures/networks_con.png b/networks/textures/networks_con.png new file mode 100644 index 0000000..547b0bb Binary files /dev/null and b/networks/textures/networks_con.png differ diff --git a/networks/textures/networks_conn.png b/networks/textures/networks_conn.png new file mode 100644 index 0000000..2d9bfb3 Binary files /dev/null and b/networks/textures/networks_conn.png differ diff --git a/networks/textures/networks_gen.png b/networks/textures/networks_gen.png new file mode 100644 index 0000000..f9f7daa Binary files /dev/null and b/networks/textures/networks_gen.png differ diff --git a/networks/textures/networks_hole.png b/networks/textures/networks_hole.png new file mode 100644 index 0000000..c480dc2 Binary files /dev/null and b/networks/textures/networks_hole.png differ diff --git a/networks/textures/networks_junction.png b/networks/textures/networks_junction.png new file mode 100644 index 0000000..0afccb4 Binary files /dev/null and b/networks/textures/networks_junction.png differ diff --git a/networks/textures/networks_marker.png b/networks/textures/networks_marker.png new file mode 100644 index 0000000..1321451 Binary files /dev/null and b/networks/textures/networks_marker.png differ diff --git a/networks/textures/networks_pump.png b/networks/textures/networks_pump.png new file mode 100644 index 0000000..ac44054 Binary files /dev/null and b/networks/textures/networks_pump.png differ diff --git a/networks/textures/networks_sto.png b/networks/textures/networks_sto.png new file mode 100644 index 0000000..4a90785 Binary files /dev/null and b/networks/textures/networks_sto.png differ diff --git a/networks/textures/networks_switch_hole.png b/networks/textures/networks_switch_hole.png new file mode 100644 index 0000000..12a1963 Binary files /dev/null and b/networks/textures/networks_switch_hole.png differ diff --git a/networks/textures/networks_switch_off.png b/networks/textures/networks_switch_off.png new file mode 100644 index 0000000..1537a5a Binary files /dev/null and b/networks/textures/networks_switch_off.png differ diff --git a/networks/textures/networks_switch_on.png b/networks/textures/networks_switch_on.png new file mode 100644 index 0000000..57288f6 Binary files /dev/null and b/networks/textures/networks_switch_on.png differ diff --git a/networks/textures/networks_tank.png b/networks/textures/networks_tank.png new file mode 100644 index 0000000..d1df028 Binary files /dev/null and b/networks/textures/networks_tank.png differ diff --git a/networks/textures/networks_tool.png b/networks/textures/networks_tool.png new file mode 100644 index 0000000..0240dd7 Binary files /dev/null and b/networks/textures/networks_tool.png differ diff --git a/signs_bot/basis.lua b/signs_bot/basis.lua index 7f9ef00..893d413 100644 --- a/signs_bot/basis.lua +++ b/signs_bot/basis.lua @@ -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, diff --git a/signs_bot/commands.lua b/signs_bot/commands.lua index 6347273..542c790 100644 --- a/signs_bot/commands.lua +++ b/signs_bot/commands.lua @@ -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 .. "'" diff --git a/signs_bot/compost.lua b/signs_bot/compost.lua index d4f5e18..0a50d6f 100644 --- a/signs_bot/compost.lua +++ b/signs_bot/compost.lua @@ -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 diff --git a/signs_bot/init.lua b/signs_bot/init.lua index 5db123f..98a8ea8 100644 --- a/signs_bot/init.lua +++ b/signs_bot/init.lua @@ -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 diff --git a/signs_bot/interpreter.lua b/signs_bot/interpreter.lua index a0e859e..0d58f98 100644 --- a/signs_bot/interpreter.lua +++ b/signs_bot/interpreter.lua @@ -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 diff --git a/signs_bot/techage.lua b/signs_bot/techage.lua index 9283b45..e4e7def 100644 --- a/signs_bot/techage.lua +++ b/signs_bot/techage.lua @@ -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,26 +178,22 @@ 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 - else - power.consumer_stop(pos, Cable) - minetest.get_node_timer(pos):stop() - mem.charging = false - if not mem.running then - signs_bot.infotext(pos, S("fully charged")) - end - return false - end + + if mem.capa < signs_bot.MAX_CAPA then + local consumed = power.consume_power(pos, Cable, nil, PWR_NEEDED) + mem.capa = mem.capa + consumed else - power.consumer_start(pos, Cable, CYCLE_TIME) + minetest.get_node_timer(pos):stop() + mem.charging = false + if not mem.running then + signs_bot.infotext(pos, S("fully charged")) + end + return false 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) @@ -266,9 +276,13 @@ send_cmnd 3465 pull*default:dirt*2]]), return techage.put_items(inv, "main", stack) 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 \ No newline at end of file +end + diff --git a/ta4_addons/LICENSE.txt b/ta4_addons/LICENSE.txt new file mode 100644 index 0000000..2beb9e1 --- /dev/null +++ b/ta4_addons/LICENSE.txt @@ -0,0 +1,662 @@ + GNU AFFERO GENERAL PUBLIC LICENSE + Version 3, 19 November 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + 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. + + + Copyright (C) + + 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 . + +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 +. + diff --git a/ta4_addons/LICENSE_GPL.txt b/ta4_addons/LICENSE_GPL.txt new file mode 100644 index 0000000..7a3b7c2 --- /dev/null +++ b/ta4_addons/LICENSE_GPL.txt @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + 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. + + + Copyright (C) + + 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 . + +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: + + Copyright (C) + 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 +. + + 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 +. \ No newline at end of file diff --git a/ta4_addons/README.md b/ta4_addons/README.md new file mode 100644 index 0000000..87db92d --- /dev/null +++ b/ta4_addons/README.md @@ -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 + diff --git a/ta4_addons/init.lua b/ta4_addons/init.lua new file mode 100644 index 0000000..b47936c --- /dev/null +++ b/ta4_addons/init.lua @@ -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"}) diff --git a/ta4_addons/manual_DE.lua b/ta4_addons/manual_DE.lua new file mode 100644 index 0000000..4373bed --- /dev/null +++ b/ta4_addons/manual_DE.lua @@ -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", +}, { + "", + "", + "", +}) diff --git a/ta4_addons/manual_DE.md b/ta4_addons/manual_DE.md new file mode 100644 index 0000000..b70613a --- /dev/null +++ b/ta4_addons/manual_DE.md @@ -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. \ No newline at end of file diff --git a/ta4_addons/manual_EN.lua b/ta4_addons/manual_EN.lua new file mode 100644 index 0000000..5c8a7b1 --- /dev/null +++ b/ta4_addons/manual_EN.lua @@ -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", +}, { + "", + "", + "", +}) diff --git a/ta4_addons/manual_EN.md b/ta4_addons/manual_EN.md new file mode 100644 index 0000000..b4d6c71 --- /dev/null +++ b/ta4_addons/manual_EN.md @@ -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. \ No newline at end of file diff --git a/ta4_addons/markdown2lua.py b/ta4_addons/markdown2lua.py new file mode 100644 index 0000000..7de9dd4 --- /dev/null +++ b/ta4_addons/markdown2lua.py @@ -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('
', '\\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") + diff --git a/ta4_addons/mod.conf b/ta4_addons/mod.conf new file mode 100644 index 0000000..0cd42b5 --- /dev/null +++ b/ta4_addons/mod.conf @@ -0,0 +1,3 @@ +name = ta4_addons +depends = default,techage,lcdlib,safer_lua +description = Addons for the TA4 age of Techage mod. \ No newline at end of file diff --git a/ta4_addons/textures/ta4_addons_touchscreen.png b/ta4_addons/textures/ta4_addons_touchscreen.png new file mode 100644 index 0000000..0a08725 Binary files /dev/null and b/ta4_addons/textures/ta4_addons_touchscreen.png differ diff --git a/ta4_addons/textures/ta4_addons_touchscreen_inventory.png b/ta4_addons/textures/ta4_addons_touchscreen_inventory.png new file mode 100644 index 0000000..37d08af Binary files /dev/null and b/ta4_addons/textures/ta4_addons_touchscreen_inventory.png differ diff --git a/ta4_addons/touchscreen/main.lua b/ta4_addons/touchscreen/main.lua new file mode 100644 index 0000000..6674d8a --- /dev/null +++ b/ta4_addons/touchscreen/main.lua @@ -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, +}) \ No newline at end of file diff --git a/ta4_jetpack/init.lua b/ta4_jetpack/init.lua index 4d4d3c3..0c63ee6 100644 --- a/ta4_jetpack/init.lua +++ b/ta4_jetpack/init.lua @@ -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 diff --git a/techage/.test/sink.lua b/techage/.test/sink.lua index cd99fa3..ec32e83 100644 --- a/techage/.test/sink.lua +++ b/techage/.test/sink.lua @@ -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") diff --git a/techage/README.md b/techage/README.md index bc6eef2..db87c55 100644 --- a/techage/README.md +++ b/techage/README.md @@ -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) diff --git a/techage/basic_machines/autocrafter.lua b/techage/basic_machines/autocrafter.lua index b8d29ee..4f6fd85 100644 --- a/techage/basic_machines/autocrafter.lua +++ b/techage/basic_machines/autocrafter.lua @@ -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) \ No newline at end of file diff --git a/techage/basic_machines/blackhole.lua b/techage/basic_machines/blackhole.lua index b55c085..3deb033 100644 --- a/techage/basic_machines/blackhole.lua +++ b/techage/basic_machines/blackhole.lua @@ -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, + } +) diff --git a/techage/basic_machines/chest.lua b/techage/basic_machines/chest.lua index fd1882c..36312cc 100644 --- a/techage/basic_machines/chest.lua +++ b/techage/basic_machines/chest.lua @@ -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() diff --git a/techage/basic_machines/concentrator.lua b/techage/basic_machines/concentrator.lua index 2843c57..2d5217c 100644 --- a/techage/basic_machines/concentrator.lua +++ b/techage/basic_machines/concentrator.lua @@ -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) diff --git a/techage/basic_machines/consumer.lua b/techage/basic_machines/consumer.lua index eb6a623..e37daaa 100644 --- a/techage/basic_machines/consumer.lua +++ b/techage/basic_machines/consumer.lua @@ -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 crd = CRD(pos) - local nvm = techage.get_nvm(pos) - 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 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 - power.consumer_alive(pos, crd.power_netw, crd.cycle_time) + 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 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 - crd.node_timer(pos, crd.cycle_time) + 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] diff --git a/techage/basic_machines/distributor.lua b/techage/basic_machines/distributor.lua index 339dd0a..b5ac378 100644 --- a/techage/basic_machines/distributor.lua +++ b/techage/basic_machines/distributor.lua @@ -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 diff --git a/techage/basic_machines/legacy_nodes.lua b/techage/basic_machines/foreign_nodes.lua similarity index 100% rename from techage/basic_machines/legacy_nodes.lua rename to techage/basic_machines/foreign_nodes.lua diff --git a/techage/basic_machines/gravelrinser.lua b/techage/basic_machines/gravelrinser.lua index 77b853f..a680fb0 100644 --- a/techage/basic_machines/gravelrinser.lua +++ b/techage/basic_machines/gravelrinser.lua @@ -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 diff --git a/techage/basic_machines/gravelsieve.lua b/techage/basic_machines/gravelsieve.lua index 6c2a340..0bd9aa4 100644 --- a/techage/basic_machines/gravelsieve.lua +++ b/techage/basic_machines/gravelsieve.lua @@ -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({ diff --git a/techage/basic_machines/grinder.lua b/techage/basic_machines/grinder.lua index 53a3b7b..a67963c 100644 --- a/techage/basic_machines/grinder.lua +++ b/techage/basic_machines/grinder.lua @@ -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,47 +75,53 @@ 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 + 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) + return end - return end end - crd.State:idle(pos, nvm) + if blocked then + crd.State:blocked(pos, nvm) + else + crd.State:idle(pos, nvm) + end end local function keep_running(pos, elapsed) @@ -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", { diff --git a/techage/basic_machines/pusher.lua b/techage/basic_machines/pusher.lua index 4d1e1ee..12f177d 100644 --- a/techage/basic_machines/pusher.lua +++ b/techage/basic_machines/pusher.lua @@ -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({ diff --git a/techage/basic_machines/source.lua b/techage/basic_machines/source.lua index 5056980..14eefa2 100644 --- a/techage/basic_machines/source.lua +++ b/techage/basic_machines/source.lua @@ -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,44 +171,17 @@ 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"), tiles = { @@ -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, + } +) + diff --git a/techage/basis/command.lua b/techage/basis/command.lua index 230ccd5..435818b 100644 --- a/techage/basis/command.lua +++ b/techage/basis/command.lua @@ -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 ------------------------------------------------------------------- diff --git a/techage/basis/conf_inv.lua b/techage/basis/conf_inv.lua index 159a5f0..88aa4f3 100644 --- a/techage/basis/conf_inv.lua +++ b/techage/basis/conf_inv.lua @@ -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 diff --git a/techage/basis/firebox_lib.lua b/techage/basis/firebox_lib.lua index b88ce89..28e6807 100644 --- a/techage/basis/firebox_lib.lua +++ b/techage/basis/firebox_lib.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019 Joachim Stolberg + Copyright (C) 2019-2021 Joachim Stolberg AGPL v3 See LICENSE.txt for more information diff --git a/techage/basis/fuel_lib.lua b/techage/basis/fuel_lib.lua index d86bcb3..d7fb569 100644 --- a/techage/basis/fuel_lib.lua +++ b/techage/basis/fuel_lib.lua @@ -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)) @@ -153,4 +155,43 @@ function techage.fuel.get_fuel_amount(nvm) return nvm.liquid.amount 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 \ No newline at end of file diff --git a/techage/basis/legacy.lua b/techage/basis/legacy.lua new file mode 100644 index 0000000..1578262 --- /dev/null +++ b/techage/basis/legacy.lua @@ -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 diff --git a/techage/basis/lib.lua b/techage/basis/lib.lua index 217afa2..fda1525 100644 --- a/techage/basis/lib.lua +++ b/techage/basis/lib.lua @@ -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 + diff --git a/techage/basis/networks.lua b/techage/basis/networks.lua deleted file mode 100644 index 6b30c46..0000000 --- a/techage/basis/networks.lua +++ /dev/null @@ -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 diff --git a/techage/basis/node_states.lua b/techage/basis/node_states.lua index 4614481..0071893 100644 --- a/techage/basis/node_states.lua +++ b/techage/basis/node_states.lua @@ -67,7 +67,7 @@ local N = techage.get_node_lvm -- techage.RUNNING = 1 -- in normal operation/turned on -techage.BLOCKED = 2 -- a pushing node is blocked due to a full destination inventory +techage.BLOCKED = 2 -- a pushing node is blocked due to a full destination inventory techage.STANDBY = 3 -- nothing to do (e.g. no input items), or node (world) not loaded techage.NOPOWER = 4 -- only for power consuming nodes, no operation techage.FAULT = 5 -- any fault state (e.g. wrong source items), which can be fixed by the player @@ -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 diff --git a/techage/carts/chest_cart.lua b/techage/carts/chest_cart.lua index b225448..64361ce 100644 --- a/techage/carts/chest_cart.lua +++ b/techage/carts/chest_cart.lua @@ -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 = { diff --git a/techage/carts/tank_cart.lua b/techage/carts/tank_cart.lua index 2488f43..c7391c3 100644 --- a/techage/carts/tank_cart.lua +++ b/techage/carts/tank_cart.lua @@ -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 peek_liquid(pos) + local nvm = techage.get_nvm(pos) + return liquid.srv_peek(nvm) +end + local function take_liquid(pos, indir, name, amount) - amount, name = liquid.srv_take(pos, indir, name, amount) + local nvm = techage.get_nvm(pos) + amount, name = liquid.srv_take(nvm, name, amount) 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)) end return amount, name 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 nvm = techage.get_nvm(pos) - M(pos):set_string("formspec", liquid.formspec(pos, nvm)) - end - return leftover -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) + local nvm = techage.get_nvm(pos) + local leftover = liquid.srv_put(nvm, name, amount, CAPACITY) 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)) 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 = { diff --git a/techage/chemistry/ta4_doser.lua b/techage/chemistry/ta4_doser.lua index e9df68d..eafdda8 100644 --- a/techage/chemistry/ta4_doser.lua +++ b/techage/chemistry/ta4_doser.lua @@ -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"), diff --git a/techage/chemistry/ta4_liquid_filter.lua b/techage/chemistry/ta4_liquid_filter.lua index 47db659..de85e61 100644 --- a/techage/chemistry/ta4_liquid_filter.lua +++ b/techage/chemistry/ta4_liquid_filter.lua @@ -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', @@ -223,4 +206,4 @@ minetest.register_craft({ {'basic_materials:concrete_block', 'techage:ta3_pipeS', 'techage:ta3_pipeS'}, {'basic_materials:concrete_block', 'basic_materials:concrete_block', 'basic_materials:concrete_block'}, } -}) \ No newline at end of file +}) diff --git a/techage/chemistry/ta4_reactor.lua b/techage/chemistry/ta4_reactor.lua index 6443a4c..3377aca 100644 --- a/techage/chemistry/ta4_reactor.lua +++ b/techage/chemistry/ta4_reactor.lua @@ -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 = { diff --git a/techage/chemistry/ta4_stand.lua b/techage/chemistry/ta4_stand.lua index bbe5330..77db92f 100644 --- a/techage/chemistry/ta4_stand.lua +++ b/techage/chemistry/ta4_stand.lua @@ -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', diff --git a/techage/coal_power_station/generator.lua b/techage/coal_power_station/generator.lua index e8c6e8c..fc875ef 100644 --- a/techage/coal_power_station/generator.lua +++ b/techage/coal_power_station/generator.lua @@ -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,18 +127,13 @@ 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"), tiles = { @@ -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 = { diff --git a/techage/coal_power_station/oilfirebox.lua b/techage/coal_power_station/oilfirebox.lua index e3341dc..eff5593 100644 --- a/techage/coal_power_station/oilfirebox.lua +++ b/techage/coal_power_station/oilfirebox.lua @@ -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 diff --git a/techage/digtron/battery.lua b/techage/digtron/battery.lua index 021b955..515c314 100644 --- a/techage/digtron/battery.lua +++ b/techage/digtron/battery.lua @@ -19,7 +19,6 @@ local S = techage.S -- Consumer Related Data local CRD = function(pos) return (minetest.registered_nodes[techage.get_node_lvm(pos).name] or {}).consumer end -local power = techage.power local STANDBY_TICKS = 3 local COUNTDOWN_TICKS = 4 @@ -49,7 +48,7 @@ local function formspec(self, pos, nvm) default.gui_slots.. "box[0,-0.1;4.8,0.5;#c6e8ff]".. "label[1,-0.1;"..minetest.colorize("#000000", S("Digtron Battery")).."]".. - power.formspec_label_bar(pos, 0, 0.8, S("Load"), TOTAL_MAX, total, S("Coal Equivalents")).. + techage.formspec_label_bar(pos, 0, 0.8, S("Load"), TOTAL_MAX, total, S("Coal Equivalents")).. "image_button[2.6,2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]".. "tooltip[2.6,2;1,1;"..self:get_state_tooltip(nvm).."]".. "image[3.75,2;1,1;"..techage.get_power_image(pos, nvm).."]" @@ -163,7 +162,7 @@ techage.register_consumer("digtron_battery", S("Digtron Battery"), { act = tiles groups = {choppy=2, cracky=2, crumbly=2, digtron=5}, sounds = default.node_sound_wood_defaults(), power_consumption = {0,25,25,25}, - power_sides = techage.networks.AllSides, + power_sides = {L=1, R=1, U=1, D=1, F=1, B=1}, }, {false, false, true, false}) minetest.register_craft({ diff --git a/techage/doc/guide.lua b/techage/doc/guide.lua index cae14aa..c409678 100644 --- a/techage/doc/guide.lua +++ b/techage/doc/guide.lua @@ -221,3 +221,8 @@ minetest.register_craft({ recipe = {"techage:construction_board"}, }) +minetest.register_craft({ + type = "shapeless", + output = "techage:construction_board", + recipe = {"techage:construction_board_EN"}, +}) diff --git a/techage/doc/items.lua b/techage/doc/items.lua index a0a29d4..2db617d 100644 --- a/techage/doc/items.lua +++ b/techage/doc/items.lua @@ -50,6 +50,8 @@ techage.Items = { ta2_forceload = "techage:forceload", ta2_driveaxle = "techage:axle", ta2_generator = "techage:ta2_generator_off", + ta2_winch = "techage:ta2_winch", + ta2_weight_chest = "techage:ta2_weight_chest", --------------------- techage_ta3 = "techage_ta3.png", techage_ta31 = "techage_ta3b.png", @@ -182,6 +184,9 @@ techage.Items = { ta4_waterinlet = "techage:ta4_waterinlet", ta4_laser = "techage:ta4_laser_emitter", ta4_concentrator = "techage:ta4_concentrator27", + ta4_electricmeter = "techage:ta4_electricmeter", + ta4_transformer = "techage:ta4_transformer", + power_reduction = "techage_power_reduction.png", --ta4_ "", } diff --git a/techage/doc/manual_DE.lua b/techage/doc/manual_DE.lua index 983829f..f3dc08a 100644 --- a/techage/doc/manual_DE.lua +++ b/techage/doc/manual_DE.lua @@ -3,6 +3,8 @@ techage.manual_DE = {} techage.manual_DE.aTitel = { "1,Tech Age Mod", "2,Hinweise", + "2,Änderungen ab Version 1.0", + "3,Tipps zur Umstellung", "2,Erze und Mineralien", "3,Meridium", "3,Usmium", @@ -10,7 +12,6 @@ techage.manual_DE.aTitel = { "3,Erdöl", "3,Bauxit", "3,Basalt", - "2,History", "1,TA1: Eisenzeitalter", "2,Köhler / Coal Pile", "2,Kohlebrenner / Coal Burner", @@ -29,6 +30,9 @@ techage.manual_DE.aTitel = { "3,TA2 Dampfleitungen / Steam Pipe", "3,TA2 Antriebsachsen / TA2 Drive Axle", "3,TA2 Stromgenerator / TA2 Power Generator", + "2,TA2 Energiespeicher", + "3,TA2 Seilwinde / TA2 Winch", + "3,TA2 Gewichtekiste / TA2 Weight Chest", "2,Items schieben und sortieren", "3,Röhren / TechAge Tube", "3,Röhren Konzentrator / Tube Concentrator", @@ -56,6 +60,7 @@ techage.manual_DE.aTitel = { "3,TA3 Generator", "3,TA3 Kühler / Cooler", "2,Elektrischer Strom", + "3,Bedeutung von Speichersystemen", "3,TA Stromkabel / Electric Cable", "3,TA Verteilerdose / Electric Junction Box", "3,TA Stromleitung / Power Line", @@ -69,7 +74,6 @@ techage.manual_DE.aTitel = { "3,TA3 Akku Block / Akku Box", "3,TA3 Strom Terminal / Power Terminal", "3,TA3 Elektromotor / TA3 Electric Motor", - "3,TA3 Strom Terminal / Power Terminal", "2,TA3 Industrieofen", "3,TA3 Ofen-Ölbrenner / Furnace Oil Burner", "3,TA3 Ofenoberteil / Furnace Top", @@ -146,6 +150,10 @@ techage.manual_DE.aTitel = { "3,TA4 Generator", "3,TA4 Rohrzulauf / TA4 Pipe Inlet", "3,TA4 Röhre / Pipe", + "2,Stromverteilung", + "3,TA4 Trenntransformator / TA4 Isolation Transformer", + "3,TA4 Stromzähler / TA4 Electric Meter", + "3,TA4 Laser", "2,Wasserstoff", "3,Elektrolyseur", "3,Brennstoffzelle", @@ -197,7 +205,6 @@ techage.manual_DE.aTitel = { "3,TA4 Elektronikfabrik / Electronic Fab", "3,TA4 Injektor / Injector", "3,TA4 Recycler", - "3,TA4 Laser", } techage.manual_DE.aText = { @@ -233,6 +240,22 @@ techage.manual_DE.aText = { "\n".. "Mit TA4 kommen weitere Stromquellen dazu\\, aber auch höhere logistische Herausforderungen (Stromtrassen\\, Item Transport).\n".. "\n", + "Ab V1.0 (17.07.2021) hat sich folgendes geändert:\n".. + "\n".. + " - Der Algorithmus zur Berechnung der Stromverteilung hat sich geändert. Energiespeichersystem werden dadurch wichtiger. Diese gleichen Schankungen aus\\, was bei größeren Netzen mit mehreren Generatoren wichtig wird.\n".. + " - Aus diesem Grund hat TA2 seinen eigenen Energiespeicher erhalten.\n".. + " - Die Akkublöcke aus TA3 dienen auch als Energiespeicher. Ihre Funktionsweise wurde entsprechend angepasst.\n".. + " - Das TA4 Speichersystem wurde überarbeitet. Die Wärmetauscher (heatexchanger) haben eine neue Nummer bekommen\\, da die Funktionalität vom unteren in den mittleren Block verschoben wurde. Sofern diese ferngesteuert wurden\\, muss die Knotennummer angepasst werden. Die Generatoren haben kein eigenes Menü mehr\\, sondern werden nur noch über den Wärmetauscher ein-/ausgeschaltet. Wärmetauscher und Generator müssen jetzt am gleichen Netz hängen!\n".. + " - Mehrere Stromnetze können jetzt über einen TA4 Transformator Blöcke gekoppelt werden.\n".. + " - Neu ist auch ein TA4 Stromzähler Block für Unternetze.\n".. + "\n", + "Viele weitere Blöcke haben kleinere Änderungen bekommen. Daher kann es sein\\, dass Maschinen oder Anlagen nach der Umstellung nicht gleich wieder anlaufen. Sollte es zu Störungen kommen\\, helfen folgende Tipps:\n".. + "\n".. + " - Maschinen aus- und wieder eingeschalten\n".. + " - ein Stromkabel-Block entfernen und wieder setzen\n".. + " - den Block ganz entfernen und wieder setzen\n".. + " - mindestens ein Akkublock oder Speichersystem in jedes Netzwerk\n".. + "\n", "Techage fügt dem Spiel einige neue Items hinzu:\n".. "\n".. " - Meridium - eine Legierung zur Herstellung von leuchtenden Werkzeugen in TA1\n".. @@ -264,21 +287,13 @@ techage.manual_DE.aText = { "\n".. "\n".. "\n", - "Basalt entsteht nur\\, wenn Lava und Wasser zusammenkommen.\n".. + "Basalt entsteht nur\\, wenn Lava und Wasser zusammen kommen.\n".. "Dazu sollte man am besten eine Anlage aufbauen\\, bei der eine Lava- und eine Wasserquelle zusammenfließen.\n".. "Dort wo sich beide Flüssigkeiten treffen\\, entsteht Basalt.\n".. "Einen automatisierten Basalt Generator kann man mit dem Sign Bot aufbauen.\n".. "\n".. "\n".. "\n", - " - 28.09.2019: Um Solaranlage erweitert\n".. - " - 05.10.2019: Daten zur Solaranlage und Beschreibung zum Wechselrichter und zum Power-Terminal geändert\n".. - " - 18.11.2019: Kapitel für Erze\\, Reaktor\\, Aluminium\\, Silo\\, Bauxit\\, Ofenheizung\\, Kieswaschanlage hinzugefügt\n".. - " - 22.02.2020: Korrekturen und Kapitel zum Update\n".. - " - 29.02.2020: ICTA Controller hinzugefügt und weitere Korrekturen\n".. - " - 14.03.2020 Lua Controller hinzugefügt und weitere Korrekturen\n".. - " - 22.03.2020 Weitere TA4 Blöcke hinzugefügt\n".. - "\n", "In TA1 geht es darum\\, mit einfachen Werkzeugen und Gerätschaften ausreichend Erze zu schürfen und Holzkohle herzustellen\\, so dass damit TA2 Maschinen hergestellt und betrieben werden können.\n".. "\n".. "Natürlich muss es für ein Eisenzeitalter auch Eisen geben und nicht nur Stahl (steel)\\, wie in \"Minetest Game\". Daher wurden einige Rezepte geändert\\, so dass zuerst Eisen hergestellt werden muss und erst später dann Stahl.\n".. @@ -377,7 +392,7 @@ techage.manual_DE.aText = { "Die Feuerbox muss mit Kohle oder Holzkohle gefüllt werden.\n".. "Wenn das Wasser heiß ist (Temperaturanzeige ganz oben)\\, kann die Dampfmaschine am Schwungrad gestartet werden.\n".. "\n".. - "Die Dampfmaschine leistet 25 ku\\, kann damit mehrere Maschinen gleichzeitig antreiben.\n".. + "Die Dampfmaschine leistet 25 ku und kann damit mehrere Maschinen gleichzeitig antreiben.\n".. "\n".. "\n".. "\n", @@ -403,7 +418,7 @@ techage.manual_DE.aText = { "\n".. "\n".. "\n", - "Die Antriebsachsen dienen zur Kraftübertragung von der Dampfmaschine zu anderen Maschinen. Die maximale Länge einer Antriebsachse beträgt 8 Blöcke. Über Getriebeboxen können auch größere Strecken überbrückt\\, sowie Abzweigungen und Richtungswechsel realisiert werden.\n".. + "Die Antriebsachsen dienen zur Kraftübertragung von der Dampfmaschine zu anderen Maschinen. Die maximale Länge einer Antriebsachse beträgt 10 Blöcke. Über Getriebeboxen können auch größere Strecken überbrückt\\, sowie Abzweigungen und Richtungswechsel realisiert werden.\n".. "\n".. "\n".. "\n", @@ -415,6 +430,22 @@ techage.manual_DE.aText = { "\n".. "\n".. "\n", + "Bei größeren Anlagen mit mehreren Dampfmaschinen oder vielen angetriebenen Maschinen empfiehlt sich ein Energiespeicher. Der Energiespeicher bei TA2 arbeitet mit Lageenergie. Dazu wird Balast (Steine\\, Kies) in einer Kiste mit Hilfe einer Seilwinde in die Höhe gezogen. Ist überschüssige Energie im Achsen-Netzwerk vorhanden\\, so wird die Kiste nach oben gezogen. Wird kurzfristig mehr Energie benötigt\\, als die Dampfmaschine liefern kann\\, so gibt der Energiespeicher die gespeicherte Energie wieder ab\\, und die Balast-Kiste bewegt sich wieder nach unten.\n".. + "\n".. + "Der Energiespeicher besteht aus mehreren Blöcken und muss wie im Plan rechts abgebildet\\, zusammen gebaut werden.\n".. + "\n".. + "Um die maximale Speicherkapazität zu erreichen\\, muss die Kiste mit Gewichten komplett gefüllt\\, und der Mast inklusive der zwei Getriebeboxen 12 Blöcke hoch sein. Kleinere Aufbauten sind aber auch möglich.\n".. + "\n".. + "\n".. + "\n", + "Die Seilwinde muss mit einer Getriebebox verbunden werden und kann so überschüssige Energie aufnehmen und damit eine Gewichtekiste nach oben ziehen. Die maximale Seillänge beträgt 10 Blöcke.\n".. + "\n".. + "\n".. + "\n", + "Diese Kiste muss mit bis zu 10 Blöcken Abstand unter die Seilwinde gesetzt und mit Pflastersteinen Kies oder Sand gefüllt werden. Ist das Mindestgewicht von einem Stack (99+ Items) erreicht und überschüssige Energie vorhanden\\, wird die Kiste automatisch über eine Seil mit der Seilwinde verbunden und in die Höhe gezogen.\n".. + "\n".. + "\n".. + "\n", "Um Gegenstände (Items) von einer Verarbeitungsstation zur nächsten weiter zu transportieren\\, werden Schieber und Röhren verwendet. Siehe Plan.\n".. "\n".. "\n".. @@ -553,7 +584,7 @@ techage.manual_DE.aText = { "\n".. "Der Boiler muss mit Wasser gefüllt werden. Dazu bis zu 10 Eimer Wasser in den Boiler füllen.\n".. "Die Feuerbox muss mit Kohle oder Holzkohle gefüllt werden.\n".. - "Wenn das Wasser heiß ist\\, kann das Ventil am Boiler geöffnet und anschließend die Generator gestartet werden.\n".. + "Wenn das Wasser heiß ist\\, kann der Generator gestartet werden.\n".. "\n".. "Das Kraftwerk kann alternativ auch mit einem Ölbrenner ausgestattet und dann mit Öl betrieben werden.\n".. "Das Öl kann über eine Pumpe und Ölleitung nachgefüllt werden.\n".. @@ -593,13 +624,13 @@ techage.manual_DE.aText = { "\n".. "\n".. "\n", - "In TA3 (und TA4) werden die Maschinen mit Strom angetrieben. Dazu müssen die Maschinen und Generatoren mit Stromkabel verbunden werden.\n".. + "In TA3 (und TA4) werden die Maschinen mit Strom angetrieben. Dazu müssen die Maschinen\\, Speichersysteme und Generatoren mit Stromkabel verbunden werden.\n".. "TA3 besitzt 2 Arten von Stromkabel:\n".. "\n".. " - Isolierte Kabel (TA Stromkabel) für die lokale Verkabelung im Boden oder in Gebäuden. Diese Kabel lassen sich in der Wand oder im Boden verstecken (können mit der Kelle \"verputzt\" werden).\n".. " - Überlandleitungen (TA Stromleitung) für Freiluftverkabelung über große Strecken. Diese Kabel sind geschützt\\, können also von anderen Spielern nicht entfernt werden.\n".. "\n".. - "Mehrere Verbraucher und Generatoren können in einem Stromnetzwerk zusammen betrieben werden. Mit Hilfe der Verteilerdosen können so große Netzwerke aufgebaut werden.\n".. + "Mehrere Verbraucher\\, Speichersysteme und Generatoren können in einem Stromnetzwerk zusammen betrieben werden. Mit Hilfe der Verteilerdosen können so Netzwerke aufgebaut werden.\n".. "Wird zu wenig Strom bereitgestellt\\, gehen die Verbraucher aus.\n".. "In diesem Zusammenhang ist auch wichtig\\, dass die Funktionsweise von Forceload Blöcken verstanden wurde\\, denn bspw. Generatoren liefern nur Strom\\, wenn der entsprechende Map-Block geladen ist. Dies kann mit einen Forceload Block erzwungen werden.\n".. "\n".. @@ -607,8 +638,25 @@ techage.manual_DE.aText = { "\n".. "\n".. "\n", + "Speichersysteme im Stromnetz erfüllen zwei Aufgaben:\n".. + "\n".. + " - Um Bedarfsspitzen abzufangen: Alle Generatoren liefern immer gerade soviel Leistung\\, wie benötigt wird. Werden aber Verbraucher ein/ausgeschaltet oder kommt es aus anderen Gründen zu Bedarfsschwankungen\\, so können Verbraucher kurzzeitig ausfallen. Um dies zu verhindern\\, sollte immer mindestens ein Akkublock in jedem Netzwerk vorhanden sein. Dieser dient als Puffer und gleicht diese Schwankungen im Sekundenbereich aus.\n".. + " - Um regenerative Energie zu speichern: Solar und Wind stehen nicht 24 Stunden am Tag zur Verfügung. Damit die Stromversorgung nicht ausfällt\\, wenn kein Strom produziert wird\\, müssen ein oder mehrere Speichersysteme im Netzwerk verbaut werden. Alternativ können die Lücken auch mit Öl/Kohle-Strom überbrückt werden.\n".. + "\n".. + "Ein Speichersystem gibt seine Kapazität in kud an\\, also ku pro day (Tag). Bspw. ein Speichersystem mit 100 kud liefert 100 ku einen Spieltag lang\\, oder auch 10 ku für 10 Spieltage.\n".. + "\n".. + "Alle TA3/TA4 Energiequellen besitzen eine einstellbare Ladecharakteristik. Standardmäßig ist diese auf \"80% - 100%\" eingestellt. Dies bedeutet\\, dass die Leistung ab 80% Füllung des Speichersystems immer weiter reduziert wird\\, bis sie bei 100 % komplett abschaltet. Sofern Strom im Netzwerk benötigt wird\\, werden die 100 % nie erreicht\\, da die Leistung des Generators irgendwann auf den Strombedarf im Netzwerk abgesunken ist und damit das Speichersystem nicht mehr geladen\\, sondern nur noch die Verbraucher bedient werden.\n".. + "\n".. + "Dies hat mehrere Vorteile:\n".. + "\n".. + " - Die Ladecharakteristik ist einstellbar. Damit kann man bspw. Öl/Kohle Energiequellen bei 60% und die regenerativen Energiequellen erst bei 80% zurückfahren. Damit wird nur Öl/Kohle verbrannt\\, wenn nicht ausreichend regenerativen Energiequellen zur Verfügung stehen.\n".. + " - Mehrere Energiequellen können parallel betrieben werden und werden dabei nahezu gleichmäßig belastet\\, denn alle Energiequellen arbeiten bspw. bis 80% Ladekapazität des Speichersystems mit ihrer vollen Leistung und fahren dann gleichzeitig ihre Leistung zurück.\n".. + " - Alle Speichersysteme in einem Netzwerk bilden einen großen Puffer. An jedem Speichersystem aber auch am Strom Terminal kann immer die Ladekapazität und der Füllungsgrad des gesamten Speichersystems in Prozent abgelesen werden.\n".. + "\n".. + "\n".. + "\n", "Für die lokale Verkabelung im Boden oder in Gebäuden.\n".. - "Abzweigungen können mit Hilfe von Verteilerdosen realisiert werden. Die maximale Kabellänge zwischen Maschinen oder Verteilerdosen beträgt 1000 m. Es können maximale 1000 Knoten in einem Strom-Netzwerk verbunden werden. Als Knoten zählen alle Generatoren\\, Akkus\\, Verteilerdosen und Maschinen.\n".. + "Abzweigungen können mit Hilfe von Verteilerdosen realisiert werden. Die maximale Kabellänge zwischen Maschinen oder Verteilerdosen beträgt 1000 m. Es können maximale 1000 Knoten in einem Strom-Netzwerk verbunden werden. Als Knoten zählen alle Blöcke mit Stromanschluss\\, also auch Verteilerdosen.\n".. "\n".. "Da die Stromkabel nicht automatisch geschützt sind\\, wird für längere Strecken die Überlandleitungen (TA Stromleitung) empfohlen.\n".. "\n".. @@ -622,7 +670,6 @@ techage.manual_DE.aText = { "\n".. "\n", "Mit der Verteilerdose kann Strom in bis zu 6 Richtungen verteilt werden. Verteilerdosen können auch mit der Kelle verputzt (versteckt) und wieder sichtbar gemacht werden.\n".. - "Wird mit dem TechAge Info Werkzeug (Schraubenschlüssel) auf die Verteilerdose geklickt\\, wird angezeigt\\, wie viel Leistung die Generatoren liefern bzw. die Verbraucher im Netzwerk beziehen.\n".. "\n".. "\n".. "\n", @@ -663,17 +710,24 @@ techage.manual_DE.aText = { "\n".. "\n", "Der Akku Block dient zur Speicherung von überschüssiger Energie und gibt bei Stromausfall automatisch Strom ab (soweit vorhanden).\n".. - "Der Akku Block ist eine sekundäre Stromquelle. Das bedeutet\\, bei Strombedarf werden zuerst die Generatoren genutzt. Nur wenn der Strom im Netz nicht ausreicht\\, springt der Akku Block ein. Das Gleiche gilt auch für die Stromaufnahme. Daher kann auch kein Akku mit einem anderen Akku geladen werden.\n".. - "Der Akku liefert 10 ku bzw. nimmt 10 ku auf.\n".. - "Bei Volllast kann ein Akku 400 s lang Strom aufnehmen und wenn er voll ist\\, auch wieder abgeben. Dies entspricht 8 h Spielzeit bei einem normalen Spieltag von 20 min.\n".. + "Mehrere Akku Blocks zusammen bilden ein TA3 Energiespeichersystem. Jeder Akku Block hat eine Anzeige für den Ladezustand und für die gespeicherte Ladung\\, wobei hier immer die Werte für das gesamte Netzwerk angezeigt werden. Die gespeicherte Ladung wird in \"kud\" also \"ku-days\" angezeigt (analog zu kWh) 5 kud entspricht damit bspw. 5 ku für einen Spieltag (20 min) oder 1 ku für 5 Spieltage.\n".. + "\n".. + "Ein Akku Block hat 3.33 kud.\n".. "\n".. "\n".. "\n", "Das Strom-Terminal muss mit dem Stromnetz verbunden werden. Es zeigt Daten aus dem Stromnetz an.\n".. "\n".. - "In der oberen Hälfte werden nur die Daten eines ausgewählten Typs ausgegeben. Wird als Typ bspw. \"Kraftwerk\" gewählt\\, so werden nur die Daten von Öl- und Kohlekraftwerken gesammelt und ausgegeben. Links werden die Daten von Generatoren (Stromabgabe) und rechts die Daten von Energiespeichern (Stromaufnahme) ausgegeben. Beim Akkublocks bspw. wird beides ausgegeben\\, da der Akku Strom aufnehmen und abgeben kann.\n".. + "In der oberen Hälfte werden die wichtigsten Größen ausgegeben:\n".. "\n".. - "In der unteren Hälfte werden die Daten aller Generatoren und Speichersystemen des ganzen Stromnetzen zusammengefasst ausgegeben.\n".. + " - aktuelle/maximale Generatorleistung\n".. + " - aktueller Stromaufnahme aller Verbraucher\n".. + " - aktueller Ladestrom in/aus dem Speichersystems\n".. + " - aktuellen Ladezustand des Speichersystems in Prozent\n".. + "\n".. + "In der unteren Hälfte wird die Anzahl der Netzwerkblöcke ausgegeben.\n".. + "\n".. + "Über den Reiter \"console\" können weitere Daten zu den Generatoren und Speichersystemen abgefragt werden.\n".. "\n".. "\n".. "\n", @@ -684,14 +738,6 @@ techage.manual_DE.aText = { "\n".. "\n".. "\n", - "Das Strom-Terminal muss mit dem Stromnetz verbunden werden. Es zeigt Daten aus dem Stromnetz an.\n".. - "\n".. - "In der oberen Hälfte werden nur die Daten eines ausgewählten Typs ausgegeben. Wird als Typ bspw. \"Kraftwerk\" gewählt\\, so werden nur die Daten von Öl- und Kohlekraftwerken gesammelt und ausgegeben. Links werden die Daten von Generatoren (Stromabgabe) und rechts die Daten von Energiespeichern (Stromaufnahme) ausgegeben. Beim Akkublocks bspw. wird beides ausgegeben\\, da der Akku Strom aufnehmen und abgeben kann.\n".. - "\n".. - "In der unteren Hälfte werden die Daten aller Generatoren und Speichersystemen des ganzen Stromnetzen zusammengefasst ausgegeben.\n".. - "\n".. - "\n".. - "\n", "Der TA3 Industrieofen dient als Ergänzung zu normalen Ofen (furnace). Damit können alle Waren mit \"Koch\" Rezepten\\, auch im Industrieofen hergestellt werden. Es gibt aber auch spezielle Rezepte\\, die nur im Industrieofen hergestellt werden können.\n".. "Der Industrieofen hat sein eigenes Menü zur Rezeptauswahl. Abhängig von den Waren im Industrieofen Inventar links kann rechts das Ausgangsprodukt gewählt werden.\n".. "\n".. @@ -1116,7 +1162,8 @@ techage.manual_DE.aText = { "", "Das Techage Info Tool (Schraubenschlüssel) hat verschiedene Funktionen. Er zeigt die Uhrzeit\\, die Position\\, die Temperatur und das Biome an\\, wenn auf einen unbekannten Block geklickt wird.\n".. "Wird auf einen TechAge Block mit Kommandoschnittstelle geklickt\\, werden alle verfügbaren Daten abgerufen (siehe auch \"Logik-/Schalt-Blöcke\").\n".. - "Bei Strom-Verteilerdosen werden die benachbarten Netzwerkteilnehmer (bis zu 50 Meter weit) mit einem blauen Käfig angezeigt.\n".. + "\n".. + "Mit Shift+Rechtsklick kann bei einigen Blöcken ein erweitertes Menü geöffnet werden. Hier lassen sich je nach Block weitere Daten abrufen oder spezielle Einstellungen vornehmen. Bei einem Generator kann bspw. die Ladekurve/abschaltung programmiert werden. \n".. "\n".. "\n".. "\n", @@ -1150,9 +1197,7 @@ techage.manual_DE.aText = { "\n".. "\n", "Der Windkraftanlagenblock (Rotor) ist das Herzstück der Windkraftanlage. Dieser Block muss oben auf den Mast gesetzt werden. Idealerweise auf Y = 15\\, dann bleibst du noch gerade innerhalb eines Map-/Forceload-Blocks.\n".. - "Nach dem Setzen des Blocks wird ein Check durchgeführt\\, ob alle Bedingungen für den Betrieb der Windkraftanlage erfüllt sind. Sofern alle Bedingungen erfüllt sind\\, erscheinen beim Setzen dieses Blocks auch automatisch die Rotorblätter (Flügel). Anderenfalls wird dir eine Fehlermeldung angezeigt. \n".. - "\n".. - "Durch Schlagen auf den Block kann der Check wiederholt werden.\n".. + "Beim Starten der Windkraftanlage werden alle Bedingungen für den Betrieb der Windkraftanlage überprüft. Sofern alle Bedingungen erfüllt sind\\, erscheinen auch automatisch die Rotorblätter (Flügel). Anderenfalls wird eine Fehlermeldung angezeigt. \n".. "\n".. "\n".. "\n", @@ -1224,26 +1269,27 @@ techage.manual_DE.aText = { "\n".. "\n".. "\n", + "Der TA4 Energiespeicher ersetzt den Batterie Block aus TA3.\n".. + "\n".. "Der Energiespeicher besteht aus einer Betonhülle (Concrete Block) gefüllt mit Gravel. Es gibt 3 Größen vom Speicher:\n".. "\n".. - " - Hülle mit 5x5x5 Concrete Blocks\\, gefüllt mit 27 Gravel\\, Speicherkapazität: 1/2 Tag bei 60 ku\n".. - " - Hülle mit 7x7x7 Concrete Blocks\\, gefüllt mit 125 Gravel\\, Speicherkapazität: 2\\,5 Tage bei 60 ku\n".. - " - Hülle mit 9x9x9 Concrete Blocks\\, gefüllt mit 343 Gravel\\, Speicherkapazität: 6\\,5 Tage bei 60 ku\n".. + " - Hülle mit 5x5x5 Concrete Blocks\\, gefüllt mit 27 Gravel\\, Speicherkapazität: 22.5 kud\n".. + " - dHülle mit 7x7x7 Concrete Blocks\\, gefüllt mit 125 Gravel\\, Speicherkapazität: 104 kud\n".. + " - Hülle mit 9x9x9 Concrete Blocks\\, gefüllt mit 343 Gravel\\, Speicherkapazität: 286 kud\n".. "\n".. "In der Betonhülle darf ein Fenster aus einem Obsidian Glas Block sein. Dieses muss ziemlich in der Mitte der Wand platziert werden. Durch dieses Fenster sieht man\\, ob der Speicher mehr als 80 % geladen ist. Im Plan rechts sieht man den Aufbau aus TA4 Wärmetauscher bestehend aus 3 Blöcken\\, der TA4 Turbine und dem TA4 Generator. Beim Wärmetauscher ist auf die Ausrichtung zu achten (der Pfeil bei Block 1 muss zur Turbine zeigen).\n".. "\n".. - "Entgegen dem Plan rechts müssen die Anschlüsse am Speicherblock auf gleicher Ebene sein (horizontal angeordnet\\, also nicht unten und oben). Die Rohrzuläufe (TA4 Pipe Inlet) müssen genau in der Mitte der Wand sein und stehen sich damit gegenüber. Als Röhren kommen die gelbel TA4 Röhren zum Einsatz. Die TA3 Dampfrohre können hier nicht verwendet werden.\n".. + "Entgegen dem Plan rechts müssen die Anschlüsse am Speicherblock auf gleicher Ebene sein (horizontal angeordnet\\, also nicht unten und oben). Die Rohrzuläufe (TA4 Pipe Inlet) müssen genau in der Mitte der Wand sein und stehen sich damit gegenüber. Als Röhren kommen die gelben TA4 Röhren zum Einsatz. Die TA3 Dampfrohre können hier nicht verwendet werden.\n".. "Sowohl der Generator als auch der Wärmetauscher haben einen Stromanschluss und müssen mit dem Stromnetz verbunden werden.\n".. "\n".. "Im Prinzip arbeitet das das Wärmespeichersystem genau gleich wie die Akkus\\, nur mit viel mehr Speicherkapazität. \n".. - "Der Wärmespeicher kann 60 ku aufnehmen und abgeben.\n".. "\n".. "Damit das Wärmespeichersystem funktioniert\\, müssen alle Blöcke (auch Betonhülle und Gravel) mit Hilfe eines Forceloadblockes geladen sein.\n".. "\n".. "\n".. "\n", "Der Wärmetauscher besteht aus 3 Teilen\\, die aufeinander gesetzt werden müssen\\, wobei der Pfeil des ersten Blockes Richtung Turbine zeigen muss. Die Rohrleitungen müssen mit den gelben TA4 Röhren aufgebaut werden.\n".. - "Der Wärmetauscher muss am Stromnetz angeschlossen werden. Der Wärmetauscher lädt den Energiespeicher wieder auf\\, wenn ausreichend Strom zur Verfügung steht und der Energiespeicher weniger als 95 % geladen ist. Der Wärmetauscher nimmt dabei 60 ku auf.\n".. + "Der Wärmetauscher muss am Stromnetz angeschlossen werden. Über den Wärmetauscher wird der Energiespeicher wieder aufgeladen\\, sofern ausreichend Strom zur Verfügung steht.\n".. "\n".. "\n".. "\n", @@ -1251,9 +1297,9 @@ techage.manual_DE.aText = { "\n".. "\n".. "\n", - "Der Generator dient zur Stromerzeugung. Daher muss auch der Generator am Stromnetz angeschlossen werden. \n".. + "Der Generator ist Teil des Energiespeichers. Er dient zur Stromerzeugung und gibt damt die Energie des Energiespeichers wieder ab. Daher muss auch der Generator am Stromnetz angeschlossen werden. \n".. "\n".. - "Der Generator kann 60 ku abgeben.\n".. + "Wichtig: Wärmetauscher und Generator müssen mit ein und demselben Stromnetz verbunden sein!\n".. "\n".. "\n".. "\n", @@ -1268,6 +1314,34 @@ techage.manual_DE.aText = { "\n".. "\n".. "\n", + "Mit Hilfe von Stromkabeln und Verteilerdosen können Stromnetze von bis zu 1000 Blöcke/Knoten aufgebaut werden. Hierbei ist aber zu beachten\\, dass Verteilerdosen auch mitgezählt werden müssen. Somit können bis zu 500 Generatoren/Speichersysteme/Maschinen/Lampen an einem Stromnetz hängen.\n".. + "\n".. + "Mit Hilfe von Trenntransformator und Stromzähler können Netzwerke zu noch größeren Strukturen verbunden werden.\n".. + "\n".. + "\n".. + "\n", + "Mit Hilfe eines Trenntransformators können zwei Stromnetze zu einem größeren Netzwerk verbunden werden. Der Trenntransformator kann Strom in beide Richtungen übertragen.\n".. + "\n".. + "Der Trenntransformator kann bis zu 100 ku übertragen.\n".. + "\n".. + "\n".. + "\n", + "Mit Hilfe eines Stromzählers können zwei Stromnetze zu einem größeren Netzwerk verbunden werden. Der Stromzähler leitet den Strom nur in eine Richtungen weiter (Pfeil beachten). Die Menge an Strom (in kud) wird gemessen und angezeigt. Die Strommenge kann auch über das Kommando 'consumption' durch einen Lua Controller abgefragt werden.\n".. + "\n".. + "Der Stromzähler kann bis zu 200 ku durchleiten.\n".. + "\n".. + "\n".. + "\n", + "Der TA4 Laser dient zur kabellosen Stromübertagung. Dazu sind zwei Blöcke notwendig: TA4 Laserstrahl Sender und TA4 Laserstrahl Empfänger. Zwischen beiden Blöcken muss sich eine Luftstrecke befinden\\, so dass der Laserstrahl vom Sender bis zum Empfänger aufgebaut werden kann.\n".. + "\n".. + "Zuerst muss der Sender platziert werden. Dieser schaltet sofort den Laserstahls ein und zeigt damit mögliche Positionen des Empfängers an. Mögliche Positionen für den Empfänger werden auch über eine Chat-Nachricht ausgegeben. Mit dem Laser lassen sich Strecken bis 96 Blöcke überbrücken.\n".. + "\n".. + "Ist die Verbindung aufgebaut (es muss dazu noch kein Strom fließen)\\, wird dies über den Info-Text des Senders und auch des Empfängers angezeigt.\n".. + "\n".. + "Die Laserblöcke selbst benötigen keinen Strom.\n".. + "\n".. + "\n".. + "\n", "Strom kann mittels Elektrolyse in Wasserstoff und Sauerstoff aufgespalten werden. Auf der anderen Seite kann über eine Brennstoffzelle Wasserstoff mit Sauerstoff aus der Luft wieder in Strom umgewandelt werden.\n".. "Damit können Stromspitzen oder ein Überangebot an Strom in Wasserstoff umgewandelt und so gespeichert werden.\n".. "\n".. @@ -1284,6 +1358,8 @@ techage.manual_DE.aText = { "Der Elektrolyseur kann bis zu 35 ku an Strom aufnehmen und generiert dann alle 4 s ein Wasserstoff Item.\n".. "In den Elektrolyseur passen 200 Einheiten Wasserstoff.\n".. "\n".. + "Der Elektrolyseur besitzt ein Schraubenschlüssel-Menü zur Einstellung der Stromaufnahme und des Abschaltpunkts.\n".. + "\n".. "\n".. "\n", "Die Brennstoffzelle wandelt Wasserstoff in Strom um.\n".. @@ -1630,29 +1706,20 @@ techage.manual_DE.aText = { "\n".. "\n".. "\n", - "Der TA4 Laser dient zur kabellosen Stromübertagung. Dazu sind zwei Blöcke notwendig: TA4 Laserstrahl Sender und TA4 Laserstrahl Empfänger. Zwischen beiden Blöcken muss sich eine Luftstrecke befinden\\, so dass der Laserstrahl vom Sender bis zum Empfänger aufgebaut werden kann.\n".. - "\n".. - "Zuerst muss der Sender platziert werden. Dieser schaltet sofort den Laserstahls ein und zeigt damit mögliche Positionen des Empfängers an. Mögliche Positionen für den Empfänger werden auch über eine Chat-Nachricht ausgegeben. Mit dem Laser lassen sich Strecken bis 96 Blöcke überbrücken.\n".. - "\n".. - "Ist die Verbindung aufgebaut (es muss dazu noch kein Strom fließen)\\, wird dies über den Info-Text des Senders und auch des Empfängers angezeigt.\n".. - "\n".. - "Die Laserblöcke selbst benötigen keinen Strom.\n".. - "\n".. - "t\n".. - "\n", } techage.manual_DE.aItemName = { "techage_ta4", "", "", + "", + "", "meridium", "usmium", "baborium", "oil", "bauxite", "basalt", - "", "techage_ta1", "", "", @@ -1672,6 +1739,9 @@ techage.manual_DE.aItemName = { "ta2_driveaxle", "ta2_generator", "", + "ta2_winch", + "ta2_weight_chest", + "", "tube", "concentrator", "ta2_pusher", @@ -1698,6 +1768,7 @@ techage.manual_DE.aItemName = { "ta3_generator", "ta3_cooler", "ta3_powerswitch", + "power_reduction", "ta3_powercable", "ta3_powerjunction", "ta3_powerline", @@ -1711,7 +1782,6 @@ techage.manual_DE.aItemName = { "ta3_akkublock", "ta3_powerterminal", "ta3_motor", - "ta3_powerterminal", "", "ta3_furnacefirebox", "ta3_furnace", @@ -1788,6 +1858,10 @@ techage.manual_DE.aItemName = { "ta4_generator", "ta4_pipeinlet", "ta4_pipe", + "ta4_transformer", + "ta4_transformer", + "ta4_electricmeter", + "ta4_laser", "ta4_hydrogen", "ta4_electrolyzer", "ta4_fuelcell", @@ -1839,7 +1913,6 @@ techage.manual_DE.aItemName = { "ta4_electronicfab", "ta4_injector", "ta4_recycler", - "ta4_laser", } techage.manual_DE.aPlanTable = { @@ -1854,6 +1927,7 @@ techage.manual_DE.aPlanTable = { "", "", "", + "", "coalpile", "coalburner", "", @@ -1871,6 +1945,9 @@ techage.manual_DE.aPlanTable = { "", "", "", + "ta2_storage", + "", + "", "itemtransport", "", "", @@ -1991,6 +2068,10 @@ techage.manual_DE.aPlanTable = { "", "", "", + "", + "", + "", + "", "ta4_reactor", "", "", @@ -2039,6 +2120,5 @@ techage.manual_DE.aPlanTable = { "", "", "", - "", } diff --git a/techage/doc/manual_EN.lua b/techage/doc/manual_EN.lua index 929623c..faeb7b8 100644 --- a/techage/doc/manual_EN.lua +++ b/techage/doc/manual_EN.lua @@ -3,6 +3,8 @@ techage.manual_EN = {} techage.manual_EN.aTitel = { "1,Tech Age Mod", "2,Hints", + "2,Changes from version 1.0", + "3,Tips on switching", "2,Ores and Minerals", "3,Meridium", "3,Usmium", @@ -29,6 +31,9 @@ techage.manual_EN.aTitel = { "3,TA2 Steam Pipes", "3,TA2 Drive Axle / TA2 Gearbox", "3,TA2 Power Generator", + "2,TA2 energy storage", + "3,TA2 Winch", + "3,TA2 Weight Chest", "2,Push and sort items", "3,TechAge Tube", "3,Tube Concentrator", @@ -56,6 +61,7 @@ techage.manual_EN.aTitel = { "3,TA3 generator", "3,TA3 cooler", "2,Electrical current", + "3,Importance of storage systems", "3,TA Electric Cable", "3,TA Electric Junction Box", "3,TA Power Line", @@ -145,6 +151,10 @@ techage.manual_EN.aTitel = { "3,TA4 Generator", "3,TA4 Pipe Inlet", "3,TA4 Pipe", + "2,Power Distribution", + "3,TA4 Isolation Transformer", + "3,TA4 Electric Meter", + "3,TA4 Laser", "2,Hydrogen", "3,Electrolyzer", "3,Fuel Cell", @@ -196,7 +206,6 @@ techage.manual_EN.aTitel = { "3,TA4 Electronic Fab", "3,TA4 Injector", "3,TA4 Recycler", - "3,TA4 Laser", } techage.manual_EN.aText = { @@ -232,6 +241,22 @@ techage.manual_EN.aText = { "\n".. "TA4 adds more power sources\\, but also higher logistical challenges (power lines\\, item transport).\n".. "\n", + "From V1.0 (07/17/2021) the following has changed:\n".. + "\n".. + " - The algorithm for calculating the power distribution has changed. This makes energy storage systems more important. These compensate for fluctuations\\, which is important in larger networks with several generators.\n".. + " - For this reason TA2 got its own energy storage.\n".. + " - The battery blocks from TA3 also serve as energy storage. Their functionality has been adapted accordingly.\n".. + " - The TA4 storage system has been revised. The heat heat exchanger have been given a new number because the functionality has been moved from the lower to the middle block. If these were remotely controlled\\, the node number must be adapted. The generators no longer have their own menu\\, but are only switched on / off via the heat exchanger. The heat exchanger and generator must now be connected to the same network!\n".. + " - Several power grids can now be coupled via a TA4 transformer blocks.\n".. + " - A TA4 electricity meter block for sub-networks is also new.\n".. + " - At least one battery block or a storage system in each network\n".. + "\n", + "Many more blocks have received minor changes. It is therefore possible that machines or systems do not start up again immediately after the changeover. In the event of malfunctions\\, the following tips will help:\n".. + "\n".. + " - Switch machines off and on again\n".. + " - remove a power cable block and put it back in place\n".. + " - remove the block completely and put it back in place\n".. + "\n", "Techage adds some new items to the game:\n".. "\n".. " - Meridium - an alloy for the production of luminous tools in TA1\n".. @@ -402,7 +427,7 @@ techage.manual_EN.aText = { "\n".. "\n".. "\n", - "The drive axles are used to transmit power from the steam engine to other machines. The maximum length of a drive axis is 8 blocks. With TA2 Gearboxes\\, larger distances can be bridged\\, and branches and changes of direction can be realized.\n".. + "The drive axles are used to transmit power from the steam engine to other machines. The maximum length of a drive axis is 10 blocks. With TA2 Gearboxes\\, larger distances can be bridged\\, and branches and changes of direction can be realized.\n".. "\n".. "\n".. "\n", @@ -414,6 +439,20 @@ techage.manual_EN.aText = { "\n".. "\n".. "\n", + "For larger systems with several steam engines or many driven machines\\, an energy storage system is recommended. The energy storage at TA2 works with position energy. For this purpose\\, ballast (stones\\, gravel\\, sand) is pulled up in a chest with the help of a cable winch. If there is excess energy in the axis network\\, the chest is pulled upwards. If more energy is required in the short term than the steam engine can supply\\, the energy store releases the stored energy again and the weight chest moves down again. \n".. + "The energy storage consists of several blocks and must be assembled as shown in the plan on the right. \n".. + "In order to achieve the maximum storage capacity\\, the chest must be completely filled with weights and the mast including the two gear boxes must be 12 blocks high. Smaller structures are also possible.\n".. + "\n".. + "\n".. + "\n", + "The cable winch must be connected to a gear box and can absorb excess energy and thus pull a weight chest upwards. The maximum rope length is 10 blocks. \n".. + "\n".. + "\n".. + "\n", + "This chest must be placed under the winch with a distance of up to 10 blocks and filled with cobblestone\\, gravel or sand. If the minimum weight of a stack (99+ items) is reached and there is excess energy\\, the box is automatically connected to the winch via a rope and pulled up. \n".. + "\n".. + "\n".. + "\n", "In order to transport objects from one processing station to the next\\, pushers and tubes are used. See plan.\n".. "\n".. "\n".. @@ -592,13 +631,13 @@ techage.manual_EN.aText = { "\n".. "\n".. "\n", - "In TA3 (and TA4) the machines are powered by electricity. To do this\\, the machines and generators must be connected with power cables.\n".. + "In TA3 (and TA4) the machines are powered by electricity. To do this\\, machines\\, storage systems\\, and generators must be connected with power cables.\n".. "TA3 has 2 types of power cables:\n".. "\n".. " - Insulated cables (TA power cables) for local wiring in the floor or in buildings. These cables can be hidden in the wall or in the floor (can be \"plastered\" with the trowel).\n".. " - Overland lines (TA power line) for outdoor cabling over long distances. These cables are protected and cannot be removed by other players.\n".. "\n".. - "Several consumers and generators can be operated together in a power network. Large networks can be set up with the help of the junction boxes.\n".. + "Several consumers\\, storage systems\\, and generators can be operated together in a power network. Networks can be set up with the help of the junction boxes.\n".. "If too little electricity is provided\\, consumers run out.\n".. "In this context\\, it is also important that the functionality of Forceload blocks is understood\\, because generators\\, for example\\, only supply electricity when the corresponding map block is loaded. This can be enforced with a forceload block.\n".. "\n".. @@ -606,8 +645,25 @@ techage.manual_EN.aText = { "\n".. "\n".. "\n", + "Storage systems in the power grid fulfill two tasks:\n".. + "\n".. + " - To cope with peaks in demand: All generators always deliver just as much power as is needed. However\\, if consumers are switched on/off or there are fluctuations in demand for other reasons\\, consumers can fail for a short time. To prevent this\\, there should always be at least one battery block in every network. This serves as a buffer and compensates for these fluctuations in the seconds range.\n".. + " - To store regenerative energy: Solar and wind are not available 24 hours a day. So that the power supply does not fail when no electricity is produced\\, one or more storage systems must be installed in the network. Alternatively\\, the gaps can also be bridged with oil/coal electricity.\n".. + "\n".. + "A storage system indicates its capacity in kud\\, i.e. ku per day. For example\\, a storage system with 100 kud delivers 100 ku for one game day\\, or 10 ku for 10 game days.\n".. + "\n".. + "All TA3/TA4 energy sources have adjustable charging characteristics. By default this is set to \"80% - 100%\". This means that when the storage system is 80% full\\, the output is reduced further and further until it switches off completely at 100%. If electricity is required in the network\\, 100% will never be reached\\, since the power of the generator has at some point dropped to the electricity demand in the network and the storage system is no longer charged\\, but only the consumers are served.\n".. + "\n".. + "This has several advantages:\n".. + "\n".. + " - The charging characteristics are adjustable. This means\\, for example\\, that oil/coal energy sources can be reduced at 60% and regenerative energy sources only at 80%. This means that oil/coal is only burned if there are not enough renewable energy sources available.\n".. + " - Several energy sources can be operated in parallel and are loaded almost evenly\\, because all energy sources work\\, for example\\, up to 80% of the storage system's charging capacity at their full capacity and then reduce their capacity at the same time.\n".. + " - All storage systems in a network form a large buffer. The charging capacity and the filling level of the entire storage system can always be read in percent on every storage system\\, but also on the electricity terminal.\n".. + "\n".. + " \n".. + "\n", "For local wiring in the floor or in buildings.\n".. - "Branches can be realized using junction boxes. The maximum cable length between machines or junction boxes is 1000 m. A maximum of 1000 nodes can be connected in a power network. All generators\\, batteries\\, junction boxes and machines count as nodes.\n".. + "Branches can be realized using junction boxes. The maximum cable length between machines or junction boxes is 1000 m. A maximum of 1000 nodes can be connected in a power network. All blocks with power connection\\, including junction boxes\\, count as nodes.\n".. "\n".. "Since the power cables are not automatically protected\\, the land lines (TA power line) are recommended for longer distances.\n".. "\n".. @@ -621,7 +677,6 @@ techage.manual_EN.aText = { "\n".. "\n", "With the junction box\\, electricity can be distributed in up to 6 directions. Junction boxes can also be plastered (hidden) with a trowel and made visible again.\n".. - "If the TechAge Info tool (wrench) is clicked on the junction box\\, it is shown whether the power line is powered or not.\n".. "\n".. "\n".. "\n", @@ -662,17 +717,25 @@ techage.manual_EN.aText = { "\n".. "\n", "The battery block is used to store excess energy and automatically delivers power in the event of a power failure (if available).\n".. - "The battery block is a secondary power source. This means that the generators are used first when electricity is required. The battery block will only provide power if there is insufficient electricity in the network. The same applies to the current consumption. Therefore\\, no battery can be charged with another battery.\n".. - "The battery delivers 10 ku or takes up 10 ku.\n".. - "At full load\\, a battery can take up to 400 s of current and\\, when it is full\\, also release it again. This corresponds to 8 hours of playing time on a normal game day of 20 minutes.\n".. + "Several battery blocks together form a TA3 energy storage system. Each battery block has a display for the charging state and for the stored load.\n".. + "The values for the entire network are always displayed here. The stored load is displayed in \"kud\" or \"ku-days\" (analogous to kWh) 5 kud thus corresponds\\, for example\\, to 5 ku for a game day (20 min) or 1 ku for 5 game days.\n".. + "\n".. + "A battery block has 3.33 kud\n".. "\n".. "\n".. "\n", "The power terminal must be connected to the power grid. It shows data from the power grid.\n".. "\n".. - "Only the data of a selected type are output in the upper half. If\\, for example\\, \"Power station\" is selected as the type\\, only the data from oil and coal-fired power stations are collected and output. The data from generators (power delivery) and the data from energy storage devices (power consumption) are output on the left. In the case of the battery blocl\\, for example\\, both are output because the battery can draw and deliver power.\n".. + "The most important figures are displayed in the upper half:\n".. "\n".. - "In the lower half\\, the data of all generators and storage systems of the entire electricity network are summarized.\n".. + " - current/maximum generator power\n".. + " - current power consumption of all consumers\n".. + " - current charging current in/from the storage system\n".. + " - Current state of charge of the storage system in percent\n".. + "\n".. + "The number of network blocks is output in the lower half.\n".. + "\n".. + "Additional data on the generators and storage systems can be queried via the \"console\" tab.\n".. "\n".. "\n".. "\n", @@ -1101,7 +1164,8 @@ techage.manual_EN.aText = { "", "The Techage Info Tool (wrench) has several functions. It shows the time\\, position\\, temperature and biome when an unknown block is clicked on.\n".. "If you click on a TechAge block with command interface\\, all available data will be shown (see also \"Logic / switching blocks\").\n".. - "In the case of power junction boxes\\, the neighboring network participants (up to 50 meters away) are displayed with a blue cage.\n".. + "\n".. + "With Shift + right click an extended menu can be opened for some blocks. Depending on the block\\, further data can be called up or special settings can be made here. In the case of a generator\\, for example\\, the charging curve/switch-off can be programmed. \n".. "\n".. "\n".. "\n", @@ -1135,9 +1199,7 @@ techage.manual_EN.aText = { "\n".. "\n", "The wind turbine block (rotor) is the heart of the wind turbine. This block must be placed on top of the mast. Ideally at Y = 15\\, then you just stay within a map / forceload block.\n".. - "After the block has been set\\, a check is carried out to determine whether all conditions for the operation of the wind turbine have been met. If all conditions are met\\, the rotor blades (wings) appear automatically when this block is set. Otherwise you will get an error message.\n".. - "\n".. - "The check can be repeated by hitting the block. \n".. + "When you start the turbine\\, all conditions for the operation of the wind turbine are checked. If all conditions are met\\, the rotor blades (wings) appear automatically. Otherwise you will get an error message.\n".. "\n".. "\n".. "\n", @@ -1209,11 +1271,13 @@ techage.manual_EN.aText = { "\n".. "\n".. "\n", + "The thermal energy storage replaces the battery block from TA3.\n".. + "\n".. "The thermal energy store consists of a concrete shell (concrete blocks) filled with gravel. Three sizes of the storage are possible:\n".. "\n".. - " - Cover with 5x5x5 concrete blocks\\, filled with 27 gravel\\, storage capacity: 1/2 day at 60 ku\n".. - " - Cover with 7x7x7 concrete blocks\\, filled with 125 gravel\\, storage capacity: 2.5 days at 60 ku\n".. - " - Cover with 9x9x9 concrete blocks\\, filled with 343 gravel\\, storage capacity: 6.5 days at 60 ku\n".. + " - Cover with 5x5x5 concrete blocks\\, filled with 27 gravel\\, storage capacity: 22.5 kud\n".. + " - Cover with 7x7x7 concrete blocks\\, filled with 125 gravel\\, storage capacity: 104 kud\n".. + " - Cover with 9x9x9 concrete blocks\\, filled with 343 gravel\\, storage capacity: 286 kud\n".. "\n".. "A window made of an obsidian glass block may be in the concrete shell. This must be placed fairly in the middle of the wall. Through this window you can see whether the storage is loaded more than 80%. In the plan on the right you can see the structure of TA4 heat exchanger consisting of 3 blocks\\, the TA4 turbine and the TA4 generator. Pay attention to the alignment of the heat exchanger (the arrow at block 1 must point to the turbine).\n".. "\n".. @@ -1221,14 +1285,13 @@ techage.manual_EN.aText = { "Both the generator and the heat exchanger have a power connection and must be connected to the power grid.\n".. "\n".. "In principle\\, the heat storage system works exactly the same as the batteries\\, only with much more storage capacity.\n".. - "The heat accumulator can hold and deliver 60 ku.\n".. "\n".. "In order for the heat storage system to work\\, all blocks (also the concrete shell and gravel) must be loaded using a forceload block.\n".. "\n".. "\n".. "\n", "The heat exchanger consists of 3 parts that must be placed on top of each other\\, with the arrow of the first block pointing towards the turbine. The pipes must be built with the yellow TA4 pipes.\n".. - "The heat exchanger must be connected to the power grid. The heat exchanger charges the energy store again when sufficient electricity is available and the energy storage is less than 95% charged. The heat exchanger takes up 60 ku. \n".. + "The heat exchanger must be connected to the power grid. The energy storage device is recharged via the heat exchanger\\, provided that sufficient electricity is available. \n".. "\n".. "\n".. "\n", @@ -1237,8 +1300,9 @@ techage.manual_EN.aText = { "\n".. "\n", "The generator is used to generate electricity. Therefore\\, the generator must also be connected to the power grid.\n".. + "The generator is part of the energy storage. It is used to generate electricity and thus releases the energy from the energy storage unit. Therefore\\, the generator must also be connected to the power grid.\n".. "\n".. - "The generator can deliver 60 ku.\n".. + "Important: Both\\, heat exchanger and generator must be connected to the same power grid! \n".. "\n".. "\n".. "\n", @@ -1253,6 +1317,32 @@ techage.manual_EN.aText = { "\n".. "\n".. "\n", + "With the help of power cables and junction boxes\\, power networks of up to 1000 blocks/nodes can be set up. However\\, it should be noted that distribution boxes must also be counted. This means that up to 500 generators/storage systems/machines/lamps can be connected to a power grid.\n".. + "\n".. + "With the help of an isolating transformer and electricity meter\\, networks can be connected to form even larger structures.\n".. + "\n".. + "\n".. + "\n", + "With the help of an isolating transformer\\, two power grids can be connected to form a larger network. The isolation transformer can transmit electricity in both directions.\n".. + "\n".. + "The isolation transformer can transmit up to 100 ku. \n".. + "\n".. + "\n".. + "\n", + "With the help of an electricity meter\\, two electricity networks can be connected to form a larger network. The electricity meter only transmits electricity in one direction (note arrow). The amount of electricity (in kud) is measured and displayed. The amount of electricity can also be queried by a Lua controller using the 'consumption' command.\n".. + "\n".. + "The electricity meter can pass up to 200 ku. \n".. + "\n".. + "\n".. + "\n", + "The TA4 laser is used for wireless power transmission. Two blocks are required for this: TA4 Laser Beam Emitter and TA4 Laser Beam Receiver. There must be an air gap between the two blocks so that the laser beam can be built up from the emitter to the receiver. First the emitter must be placed. This immediately switches on the laser beam and shows possible positions of the receiver. Possible positions for the receiver are also output via a chat message. \n".. + "\n".. + "With the laser\\, distances of up to 96 blocks can be bridged. Once the connection has been established (no current has to flow)\\, this is indicated via the info text of the emitter and also of the receiver. \n".. + "\n".. + "The laser blocks themselves do not require any electricity.\n".. + "\n".. + "\n".. + "\n", "Electrolysis can be used to split electricity into hydrogen and oxygen. On the other hand\\, hydrogen can be converted back into electricity with oxygen from the air using a fuel cell.\n".. "This enables current peaks or an excess supply of electricity to be converted into hydrogen and thus stored.\n".. "\n".. @@ -1269,6 +1359,8 @@ techage.manual_EN.aText = { "The electrolyzer can draw up to 35 ku of electricity and then generates a hydrogen item every 4 s.\n".. "200 units of hydrogen fit into the electrolyzer.\n".. "\n".. + "The electrolyzer has a wrench menu for setting the current consumption and the switch-off point.\n".. + "\n".. "\n".. "\n", "The fuel cell converts hydrogen into electricity.\n".. @@ -1616,20 +1708,14 @@ techage.manual_EN.aText = { "\n".. " \n".. "\n", - "The TA4 laser is used for wireless power transmission. Two blocks are required for this: TA4 Laser Beam Emitter and TA4 Laser Beam Receiver. There must be an air gap between the two blocks so that the laser beam can be built up from the emitter to the receiver. First the emitter must be placed. This immediately switches on the laser beam and shows possible positions of the receiver. Possible positions for the receiver are also output via a chat message. \n".. - "\n".. - "With the laser\\, distances of up to 96 blocks can be bridged. Once the connection has been established (no current has to flow)\\, this is indicated via the info text of the emitter and also of the receiver. \n".. - "\n".. - "The laser blocks themselves do not require any electricity.\n".. - "\n".. - "\n".. - "\n", } techage.manual_EN.aItemName = { "techage_ta4", "", "", + "", + "", "meridium", "usmium", "baborium", @@ -1656,6 +1742,9 @@ techage.manual_EN.aItemName = { "ta2_driveaxle", "ta2_generator", "", + "ta2_winch", + "ta2_weight_chest", + "", "tube", "concentrator", "ta2_pusher", @@ -1682,6 +1771,7 @@ techage.manual_EN.aItemName = { "ta3_generator", "ta3_cooler", "ta3_powerswitch", + "power_reduction", "ta3_powercable", "ta3_powerjunction", "ta3_powerline", @@ -1771,6 +1861,10 @@ techage.manual_EN.aItemName = { "ta4_generator", "ta4_pipeinlet", "ta4_pipe", + "ta4_transformer", + "ta4_transformer", + "ta4_electricmeter", + "ta4_laser", "ta4_hydrogen", "ta4_electrolyzer", "ta4_fuelcell", @@ -1822,7 +1916,6 @@ techage.manual_EN.aItemName = { "ta4_electronicfab", "ta4_injector", "ta4_recycler", - "ta4_laser", } techage.manual_EN.aPlanTable = { @@ -1837,6 +1930,8 @@ techage.manual_EN.aPlanTable = { "", "", "", + "", + "", "coalpile", "coalburner", "", @@ -1854,6 +1949,9 @@ techage.manual_EN.aPlanTable = { "", "", "", + "ta2_storage", + "", + "", "itemtransport", "", "", @@ -1894,6 +1992,7 @@ techage.manual_EN.aPlanTable = { "", "", "", + "", "ta3_furnace", "", "", @@ -1973,6 +2072,10 @@ techage.manual_EN.aPlanTable = { "", "", "", + "", + "", + "", + "", "ta4_reactor", "", "", @@ -2021,6 +2124,5 @@ techage.manual_EN.aPlanTable = { "", "", "", - "", } diff --git a/techage/doc/plans.lua b/techage/doc/plans.lua index ce3ac2f..05e2043 100644 --- a/techage/doc/plans.lua +++ b/techage/doc/plans.lua @@ -104,6 +104,29 @@ techage.ConstructionPlans["steamengine"] = { {false, FIBOX, false, PK090, CYLIN, FLYWH, false}, } +-- +-- TA2 Storage +-- +local GRBOX = {"techage_filling_ta2.png^techage_axle_gearbox.png^techage_frame_ta2.png", "techage:gearbox"} +local AXL00 = {"techage_axle.png", "techage:axle"} +local AXL90 = {"techage_axle.png^[transformR90", "techage:axle"} +local WINCH = {"techage_filling_ta2.png^techage_appl_winch.png^techage_frame_ta2.png", "techage:ta2_winch"} +local ROPE_ = {"techage_rope_inv.png", "techage:ta2_rope"} +local WCHST = {"techage_filling_ta2.png^techage_frame_ta2.png^techage_appl_chest_back_ta3.png^techage_weight_side.png", "techage:ta2_weight_chest"} + +techage.ConstructionPlans["ta2_storage"] = { + {false, false, false, GRBOX, WINCH, false, SIDEV}, + {false, false, false, AXL90, ROPE_, false, false}, + {false, false, false, AXL90, ROPE_, false, false}, + {false, false, false, AXL90, ROPE_, false, false}, + {false, false, false, AXL90, ROPE_, false, false}, + {false, false, false, AXL90, ROPE_, false, false}, + {false, false, false, AXL90, ROPE_, false, false}, + {false, false, false, AXL90, WCHST, false, false}, + {false, false, false, AXL90, false, false, false}, + {AXL00, AXL00, AXL00, GRBOX, false, false, false}, +} + -- -- Item Transport -- diff --git a/techage/energy_storage/generator.lua b/techage/energy_storage/generator.lua index 7e38079..ef0c30c 100644 --- a/techage/energy_storage/generator.lua +++ b/techage/energy_storage/generator.lua @@ -3,137 +3,32 @@ TechAge ======= - Copyright (C) 2019-2020 Joachim Stolberg + Copyright (C) 2019-2021 Joachim Stolberg AGPL v3 See LICENSE.txt for more information - TA4 TES Generator - + TA4 TES Generator (dummy) + - can be started and stopped + - provides netID of cable network ]]-- -- for lazy programmers local M = minetest.get_meta local S = techage.S -local STANDBY_TICKS = 4 -local COUNTDOWN_TICKS = 4 -local CYCLE_TIME = 2 -local PWR_CAPA = 60 - local Cable = techage.ElectricCable -local power = techage.power -local networks = techage.networks +local power = networks.power -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("Electricity"), 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).."]" -end - -local function transfer_turbine(pos, topic, payload) - return techage.transfer(pos, "L", topic, payload, nil, - {"techage:ta4_turbine", "techage:ta4_turbine_on"}) -end - -local function can_start(pos, nvm, state) - if (nvm.heatexchanger_trigger or 0) == 0 then -- by means of heatexchanger - return S("storage empty?") - end - return true -end - -local function start_node(pos, nvm, state) - local outdir = M(pos):get_int("outdir") - power.generator_start(pos, Cable, CYCLE_TIME, outdir) - transfer_turbine(pos, "start") - nvm.running = true -end - -local function stop_node(pos, nvm, state) - local outdir = M(pos):get_int("outdir") - power.generator_stop(pos, Cable, outdir) - nvm.provided = 0 - transfer_turbine(pos, "stop") - nvm.running = false -end - -local State = techage.NodeStates:new({ - node_name_passive = "techage:ta4_generator", - node_name_active = "techage:ta4_generator_on", - cycle_time = CYCLE_TIME, - standby_ticks = STANDBY_TICKS, - formspec_func = formspec, - infotext_name = S("TA4 Generator"), - can_start = can_start, - start_node = start_node, - stop_node = stop_node, -}) - -local function node_timer(pos, elapsed) - local nvm = techage.get_nvm(pos) - nvm.heatexchanger_trigger = (nvm.heatexchanger_trigger or 0) - 1 - if nvm.heatexchanger_trigger <= 0 then - State:nopower(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) - State:keep_running(pos, nvm, COUNTDOWN_TICKS) - end - if techage.is_activeformspec(pos) then - M(pos):set_string("formspec", formspec(State, pos, nvm)) - end - return State:is_active(nvm) -end - -local function on_receive_fields(pos, formname, fields, player) - if minetest.is_protected(pos, player:get_player_name()) then +local function swap_node(pos, name) + local node = techage.get_node_lvm(pos) + if node.name == name then return end - local nvm,_ = techage.get_nvm(pos, true) - State:state_button_event(pos, nvm, fields) + node.name = name + minetest.swap_node(pos, node) end -local function on_rightclick(pos, node, clicker) - local nvm = techage.get_nvm(pos) - techage.set_activeformspec(pos, clicker) - M(pos):set_string("formspec", formspec(State, pos, nvm)) -end - -local function after_place_node(pos) - local nvm = techage.get_nvm(pos) - local number = techage.add_node(pos, "techage:ta4_generator") - State:node_init(pos, nvm, number) - M(pos):set_int("outdir", networks.side_to_outdir(pos, "R")) - M(pos):set_string("formspec", formspec(State, pos, nvm)) - Cable:after_place_node(pos) -end - -local function after_dig_node(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) -end - -local net_def = { - ele1 = { - sides = {R = 1}, - ntype = "gen2", - nominal = PWR_CAPA, - }, -} - minetest.register_node("techage:ta4_generator", { description = S("TA4 Generator"), tiles = { @@ -146,13 +41,14 @@ minetest.register_node("techage:ta4_generator", { "techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_generator.png^[transformFX]", }, - on_receive_fields = on_receive_fields, - on_rightclick = on_rightclick, - 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, + after_place_node = function(pos) + M(pos):set_int("outdir", networks.side_to_outdir(pos, "R")) + Cable:after_place_node(pos) + end, + after_dig_node = function(pos, oldnode) + Cable:after_dig_node(pos) + techage.del_mem(pos) + end, paramtype2 = "facedir", groups = {cracky=2, crumbly=2, choppy=2}, @@ -191,16 +87,8 @@ minetest.register_node("techage:ta4_generator_on", { }, }, - on_receive_fields = on_receive_fields, - on_rightclick = on_rightclick, - 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, - - drop = "", paramtype2 = "facedir", + drop = "", groups = {not_in_creative_inventory=1}, diggable = false, on_rotate = screwdriver.disallow, @@ -208,32 +96,27 @@ minetest.register_node("techage:ta4_generator_on", { sounds = default.node_sound_wood_defaults(), }) -Cable:add_secondary_node_names({"techage:ta4_generator", "techage:ta4_generator_on"}) +-- The generator is a dummy, it only has to network connection to check the netID +power.register_nodes({"techage:ta4_generator", "techage:ta4_generator_on"}, Cable, "con", {"R"}) -- controlled by the turbine techage.register_node({"techage:ta4_generator", "techage:ta4_generator_on"}, { on_transfer = function(pos, in_dir, topic, payload) - local nvm = techage.get_nvm(pos) - if topic == "trigger" then - --print("trigger", nvm.provided) - nvm.heatexchanger_trigger = 3 - if nvm.running then - return nvm.provided or 0.1 - else - return 0 - end + if topic == "netID" then + local outdir = M(pos):get_int("outdir") + return networks.determine_netID(pos, Cable, outdir) + elseif topic == "start" then + swap_node(pos, "techage:ta4_generator_on") + elseif topic == "stop" then + swap_node(pos, "techage:ta4_generator") end end, on_recv_message = function(pos, src, topic, payload) - local nvm = techage.get_nvm(pos) - if topic == "delivered" then - return math.floor((nvm.provided or 0) + 0.5) - elseif topic == "load" then - local capa_max, capa = transfer_turbine(pos, "state") - return techage.power.percent(capa_max, capa) - else - return State:on_receive_message(pos, topic, payload) - end + return "unsupported" + end, + on_node_load = function(pos) + -- remove legacy formspec + M(pos):set_string("formspec", "") end, }) diff --git a/techage/energy_storage/heatexchanger1.lua b/techage/energy_storage/heatexchanger1.lua index 2bb016b..78f562b 100644 --- a/techage/energy_storage/heatexchanger1.lua +++ b/techage/energy_storage/heatexchanger1.lua @@ -3,13 +3,14 @@ TechAge ======= - Copyright (C) 2019-2020 Joachim Stolberg + Copyright (C) 2019-2021 Joachim Stolberg AGPL v3 See LICENSE.txt for more information TA4 Heat Exchanger1 (bottom part) - + - has a connection to storage and turbine (via pipes) + - acts as a cable junction for Exchanger2 ]]-- -- for lazy programmers @@ -18,38 +19,9 @@ local P2S = minetest.pos_to_string local M = minetest.get_meta local S = techage.S -local CYCLE_TIME = 2 -local PWR_PERF = 60 -local GRVL_CAPA = 700 -local PWR_CAPA = { - [5] = GRVL_CAPA * 3 * 3 * 3, -- 18900 Cyc = 630 min = 31.5 Tage bei einem ku, oder 31,5 * 24 kuh = 756 kuh = 12,6 h bei 60 ku - [7] = GRVL_CAPA * 5 * 5 * 5, -- ~2.5 days - [9] = GRVL_CAPA * 7 * 7 * 7, -- ~6 days -} - local Cable = techage.ElectricCable local Pipe = techage.LiquidPipe -local power = techage.power -local in_range = techage.in_range - -local function swap_node(pos, name) - local node = techage.get_node_lvm(pos) - if node.name == name then - return - end - node.name = name - minetest.swap_node(pos, node) -end - -local function glowing(pos, nvm, should_glow) - if nvm.win_pos then - if should_glow then - swap_node(nvm.win_pos, "techage:glow_gravel") - else - swap_node(nvm.win_pos, "default:gravel") - end - end -end +local power = networks.power local function turbine_cmnd(pos, topic, payload) return techage.transfer(pos, "R", topic, payload, Pipe, @@ -61,153 +33,6 @@ local function inlet_cmnd(pos, topic, payload) {"techage:ta4_pipe_inlet"}) end -local function play_sound(pos) - local mem = techage.get_mem(pos) - if not mem.handle or mem.handle == -1 then - mem.handle = minetest.sound_play("techage_booster", { - pos = pos, - gain = 0.3, - max_hear_distance = 10, - loop = true}) - if mem.handle == -1 then - minetest.after(1, play_sound, pos) - end - end - local nvm = techage.get_nvm(pos) - nvm.charging = true -end - -local function stop_sound(pos) - local mem = techage.get_mem(pos) - if mem.handle then - minetest.sound_stop(mem.handle) - mem.handle = nil - end - local nvm = techage.get_nvm(pos) - nvm.charging = false -end - -local function on_power(pos) -end - -local function on_nopower(pos) -end - -local function is_running(pos, nvm) - return nvm.charging -end - -local function start_node(pos, nvm) - nvm.running = true - nvm.needed = 0 - nvm.win_pos = inlet_cmnd(pos, "window") - power.consumer_start(pos, Cable, CYCLE_TIME) - minetest.get_node_timer(pos):start(CYCLE_TIME) - return true -end - -local function stop_node(pos, nvm) - nvm.running = false - nvm.needed = 0 - power.consumer_stop(pos, Cable) - minetest.get_node_timer(pos):stop() - stop_sound(pos) - return true -end - -local function after_place_node(pos, placer, itemstack) - local nvm = techage.get_nvm(pos) - nvm.capa = 0 - M(pos):set_string("owner", placer:get_player_name()) - local number = techage.add_node(pos, "techage:heatexchanger1") - M(pos):set_string("node_number", number) - M(pos):set_string("infotext", S("TA4 Heat Exchanger 1").." "..number) - Cable:after_place_node(pos) - Pipe:after_place_node(pos) -end - -local function can_dig(pos, player) - if minetest.is_protected(pos, player:get_player_name()) then - return false - end - local nvm = techage.get_nvm(pos) - return not nvm.running -end - -local function after_dig_node(pos, oldnode, oldmetadata, digger) - Cable:after_dig_node(pos) - Pipe: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 nvm = techage.get_nvm(pos) - nvm.running = false -end - -local function can_start(pos, nvm) - -- the heat exchanger shall be able to start even without - -- having power. Therefore, no "if power.power_available(pos, Cable) then" - local diameter = inlet_cmnd(pos, "diameter") - if diameter then - nvm.capa_max = PWR_CAPA[tonumber(diameter)] or 0 - if nvm.capa_max ~= 0 then - local owner = M(pos):get_string("owner") or "" - return inlet_cmnd(pos, "volume", owner) - else - return S("wrong storage diameter")..": "..diameter - end - else - return S("inlet/pipe error") - end - return S("did you check the plan?") -end - -local function node_timer(pos, elapsed) - local nvm = techage.get_nvm(pos) - nvm.capa = nvm.capa or 0 - nvm.capa_max = nvm.capa_max or 0 - local taken = 0 - local given = 0 - - if nvm.capa < (nvm.capa_max * 0.95) and not nvm.charging then - taken = power.consumer_alive(pos, Cable, CYCLE_TIME) - elseif nvm.capa < nvm.capa_max and nvm.charging then - taken = power.consumer_alive(pos, Cable, CYCLE_TIME) - end - if nvm.capa > 0 then - given = turbine_cmnd(pos, "trigger") or 0 - end - - if taken > 0 and not nvm.charging then - play_sound(pos) - elseif taken == 0 and nvm.charging then - stop_sound(pos) - end - - nvm.needed = taken - given - nvm.capa = in_range(nvm.capa + nvm.needed, 0, nvm.capa_max) - glowing(pos, nvm, nvm.capa > nvm.capa_max * 0.8) - --print("node_timer TES "..P2S(pos), nvm.needed, nvm.capa, nvm.capa_max) - return true -end - -local net_def = { - ele1 = { - sides = {F = 1, B = 1}, - ntype = "con2", - nominal = PWR_PERF, - on_power = on_power, - on_nopower = on_nopower, - is_running = is_running, - }, - pipe2 = { - sides = {L = 1, R = 1}, - ntype = "con1", - }, -} - minetest.register_node("techage:heatexchanger1", { description = S("TA4 Heat Exchanger 1"), tiles = { @@ -220,13 +45,27 @@ minetest.register_node("techage:heatexchanger1", { "techage_filling_ta4.png^techage_frameB_ta4.png^techage_appl_hole_electric.png", }, - on_timer = node_timer, - after_place_node = after_place_node, - can_dig = can_dig, - after_dig_node = after_dig_node, - tubelib2_on_update2 = tubelib2_on_update2, - networks = net_def, - + after_place_node = function(pos, placer, itemstack, pointed_thing) + Cable:after_place_node(pos) + Pipe:after_place_node(pos) + end, + tubelib2_on_update2 = function(pos, outdir, tlib2, node) + if tlib2 == Cable then + power.update_network(pos, 0, tlib2, node) + end + end, + can_dig = function(pos, player) + if minetest.is_protected(pos, player:get_player_name()) then + return false + end + pos.y = pos.y + 1 + return minetest.get_node(pos).name ~= "techage:heatexchanger2" + end, + after_dig_node = function(pos, oldnode, oldmetadata, digger) + Cable:after_dig_node(pos) + Pipe:after_dig_node(pos) + end, + networks = {}, paramtype2 = "facedir", groups = {crumbly = 2, cracky = 2, snappy = 2}, on_rotate = screwdriver.disallow, @@ -235,62 +74,21 @@ minetest.register_node("techage:heatexchanger1", { }) Pipe:add_secondary_node_names({"techage:heatexchanger1"}) -Cable:add_secondary_node_names({"techage:heatexchanger1"}) +Pipe:set_valid_sides("techage:heatexchanger1", {"R", "L"}) + +power.register_nodes({"techage:heatexchanger1"}, Cable, "junc", {"F", "B", "U"}) -- command interface techage.register_node({"techage:heatexchanger1"}, { on_transfer = function(pos, indir, topic, payload) local nvm = techage.get_nvm(pos) -- used by heatexchanger2 - if topic == "state" then - return (nvm.capa_max or 0), (nvm.capa or 0), PWR_PERF, math.max(nvm.needed or 0, 0) - elseif topic == "integrity" then - return inlet_cmnd(pos, "volume", payload) - elseif topic == "state" then - return inlet_cmnd(pos, "volume", payload) - elseif topic == "can_start" then - return can_start(pos, nvm) - elseif topic == "start" then - return start_node(pos, nvm) - elseif topic == "stop" then - return stop_node(pos, nvm) - end - end, - on_recv_message = function(pos, src, topic, payload) - local nvm = techage.get_nvm(pos) - if topic == "state" then - if nvm.charging then - return "running" - elseif nvm.running then - return "standby" - else - return "stopped" - end - elseif topic == "delivered" then - return -math.max(nvm.needed or 0, 0) - elseif topic == "load" then - return techage.power.percent(nvm.capa_max, nvm.capa) - elseif topic == "on" then - start_node(pos, techage.get_nvm(pos)) - return true - elseif topic == "off" then - stop_node(pos, techage.get_nvm(pos)) - return true + if topic == "diameter" or topic == "volume" or topic == "window" then + return inlet_cmnd(pos, topic, payload) else - return "unsupported" + return turbine_cmnd(pos, topic, payload) end end, - on_node_load = function(pos, node) - local nvm = techage.get_nvm(pos) - if nvm.running and nvm.charging then - play_sound(pos) - else - stop_sound(pos) - end - local mem = tubelib2.get_mem(pos) - nvm.capa = (nvm.capa or 0) + (mem.capa or 0) - --tubelib2.del_mem(pos) - end, }) minetest.register_craft({ diff --git a/techage/energy_storage/heatexchanger2.lua b/techage/energy_storage/heatexchanger2.lua index 55fcf86..1cb7c9f 100644 --- a/techage/energy_storage/heatexchanger2.lua +++ b/techage/energy_storage/heatexchanger2.lua @@ -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 @@ -18,57 +18,137 @@ local P2S = minetest.pos_to_string local M = minetest.get_meta local S = techage.S -local power = techage.power +local Cable = techage.ElectricCable +local Pipe = techage.LiquidPipe +local power = networks.power +local control = networks.control local CYCLE_TIME = 2 +local GRVL_CAPA = 500 +local PWR_CAPA = { + [5] = GRVL_CAPA * 3 * 3 * 3, -- 13500 Cyc = 450 min = 22.5 kud + [7] = GRVL_CAPA * 5 * 5 * 5, -- 104 kud + [9] = GRVL_CAPA * 7 * 7 * 7, -- 286 kuh +} +local DOWN = 5 -local function he1_cmnd(pos, topic, payload) +local function heatexchanger1_cmnd(pos, topic, payload) return techage.transfer({x = pos.x, y = pos.y - 1, z = pos.z}, nil, topic, payload, nil, {"techage:heatexchanger1"}) end -local function formspec(self, pos, nvm) - local capa_max, capa, needed_max, needed = he1_cmnd(pos, "state") - capa_max = capa_max or 0 - capa = capa or 0 - needed_max = needed_max or 0 - needed = needed or 0 - local arrow = "image[2.5,1.5;1,1;techage_form_arrow_bg.png^[transformR270]" - if needed > 0 then - arrow = "image[2.5,1.5;1,1;techage_form_arrow_fg.png^[transformR270]" +local function heatexchanger3_cmnd(pos, topic, payload) + return techage.transfer({x = pos.x, y = pos.y + 1, z = pos.z}, + nil, topic, payload, nil, + {"techage:heatexchanger3"}) +end + +local function swap_node(pos, name) + local node = techage.get_node_lvm(pos) + if node.name == name then + return end - return "size[6,4]".. - default.gui_bg.. - default.gui_bg_img.. - default.gui_slots.. - "box[0,-0.1;5.8,0.5;#c6e8ff]".. - "label[2,-0.1;"..minetest.colorize( "#000000", S("Heat Exchanger")).."]".. - power.formspec_label_bar(pos, 0, 0.8, S("Electricity"), needed_max, needed).. - power.formspec_label_bar(pos, 3.5, 0.8, S("Thermal"), capa_max, capa, "").. - arrow.. - "image_button[2.5,3;1,1;".. self:get_state_button_image(nvm) ..";state_button;]".. - "tooltip[2.5,3;1,1;"..self:get_state_tooltip(nvm).."]" + node.name = name + minetest.swap_node(pos, node) end -local function can_start(pos, nvm, state) - --print("can_start", he1_cmnd(pos, "can_start")) - return he1_cmnd(pos, "can_start") or S("did you check the plan?") +local function play_sound(pos) + local mem = techage.get_mem(pos) + if not mem.handle or mem.handle == -1 then + mem.handle = minetest.sound_play("techage_booster", { + pos = pos, + gain = 0.3, + max_hear_distance = 10, + loop = true}) + if mem.handle == -1 then + minetest.after(1, play_sound, pos) + end + end end -local function start_node(pos, nvm, state) - he1_cmnd(pos, "start") +local function stop_sound(pos) + local mem = techage.get_mem(pos) + if mem.handle then + minetest.sound_stop(mem.handle) + mem.handle = nil + end end -local function stop_node(pos, nvm, state) - he1_cmnd(pos, "stop") +local function can_start(pos, nvm) + local netID = networks.determine_netID(pos, Cable, DOWN) + if heatexchanger1_cmnd(pos, "netID") ~= netID then + return S("Power network connection error") + end + local diameter = heatexchanger1_cmnd(pos, "diameter") + if diameter then + nvm.capa_max = PWR_CAPA[tonumber(diameter)] or 0 + if nvm.capa_max ~= 0 then + nvm.capa = math.min(nvm.capa or 0, nvm.capa_max) + local owner = M(pos):get_string("owner") or "" + return heatexchanger1_cmnd(pos, "volume", owner) + else + return S("wrong storage diameter") .. ": " .. diameter + end + else + return S("inlet/pipe error") + end + return S("did you check the plan?") +end + +local function start_node(pos, nvm) + nvm.win_pos = heatexchanger1_cmnd(pos, "window") + power.start_storage_calc(pos, Cable, DOWN) + play_sound(pos) + heatexchanger1_cmnd(pos, "start") +end + +local function stop_node(pos, nvm) + power.start_storage_calc(pos, Cable, DOWN) + stop_sound(pos) + heatexchanger1_cmnd(pos, "stop") +end + +local function formspec(self, pos, nvm) + local data + + if techage.is_running(nvm) then + data = power.get_network_data(pos, Cable, DOWN) + end + return techage.storage_formspec(self, pos, nvm, S("TA4 Heat Exchanger"), data, nvm.capa, nvm.capa_max) +end + +local function glowing(pos, nvm, should_glow) + if nvm.win_pos then + if should_glow then + swap_node(nvm.win_pos, "techage:glow_gravel") + else + swap_node(nvm.win_pos, "default:gravel") + end + end end local function check_TES_integrity(pos, nvm) nvm.ticks = (nvm.ticks or 0) + 1 - if (nvm.ticks % 100) == 0 then -- not to often - return he1_cmnd(pos, "integrity", "singleplayer") + if (nvm.ticks % 30) == 0 then -- every minute + return heatexchanger1_cmnd(pos, "volume") end + if (nvm.ticks % 30) == 10 then -- every minute + return heatexchanger3_cmnd(pos, "diameter") ~= nil or S("inlet/pipe error") + end + if (nvm.ticks % 30) == 20 then -- every minute + return heatexchanger3_cmnd(pos, "diameter") ~= nil or S("inlet/pipe error") + end + local netID = networks.determine_netID(pos, Cable, DOWN) + if heatexchanger1_cmnd(pos, "netID") ~= netID then + if nvm.check_once_again then + nvm.check_once_again = false + return true + else + return S("Power network connection error") + end + end + nvm.check_once_again = true return true end @@ -88,13 +168,20 @@ local function node_timer(pos, elapsed) local res = check_TES_integrity(pos, nvm) if res ~= true then State:fault(pos, nvm, res) - he1_cmnd(pos, "stop") + heatexchanger1_cmnd(pos, "stop") + power.start_storage_calc(pos, Cable, DOWN) + end + + if techage.is_running(nvm) then + local capa = power.get_storage_load(pos, Cable, DOWN, nvm.capa_max) or 0 + if capa > 0 then + nvm.capa = capa + end end if techage.is_activeformspec(pos) then M(pos):set_string("formspec", formspec(State, pos, nvm)) - return true end - return false + return true end local function can_dig(pos, player) @@ -102,25 +189,34 @@ local function can_dig(pos, player) return false end local nvm = techage.get_nvm(pos) - return not nvm.running + return not techage.is_running(nvm) end local function on_rightclick(pos, node, clicker) techage.set_activeformspec(pos, clicker) local nvm = techage.get_nvm(pos) M(pos):set_string("formspec", formspec(State, pos, nvm)) - minetest.get_node_timer(pos):start(CYCLE_TIME) end local function after_place_node(pos, placer) if techage.orientate_node(pos, "techage:heatexchanger1") then return true end + local meta = M(pos) local nvm = techage.get_nvm(pos) - State:node_init(pos, nvm, "") - M(pos):set_string("formspec", formspec(State, pos, nvm)) + local own_num = techage.add_node(pos, "techage:heatexchanger1") + meta:set_string("owner", placer:get_player_name()) + meta:set_string("infotext", S("TA4 Heat Exchanger")..": "..own_num) + meta:set_string("formspec", formspec(State, pos, nvm)) + Cable:after_place_node(pos, {DOWN}) + State:node_init(pos, nvm, own_num) end +local function after_dig_node(pos, oldnode, oldmetadata, digger) + Cable:after_dig_node(pos) + techage.del_mem(pos) +end + local function on_receive_fields(pos, formname, fields, player) if minetest.is_protected(pos, player:get_player_name()) then return @@ -131,6 +227,14 @@ local function on_receive_fields(pos, formname, fields, player) M(pos):set_string("formspec", formspec(State, pos, nvm)) end +local function get_storage_data(pos, outdir, tlib2) + local nvm = techage.get_nvm(pos) + nvm.capa_max = nvm.capa_max or 1 + if techage.is_running(nvm) then + return {level = (nvm.capa or 0) / nvm.capa_max, capa = nvm.capa_max} + end +end + -- Middle node with the formspec from the bottom node minetest.register_node("techage:heatexchanger2", { description = S("TA4 Heat Exchanger 2"), @@ -154,6 +258,8 @@ minetest.register_node("techage:heatexchanger2", { on_timer = node_timer, after_place_node = after_place_node, can_dig = can_dig, + after_dig_node = after_dig_node, + get_storage_data = get_storage_data, paramtype2 = "facedir", groups = {crumbly = 2, cracky = 2, snappy = 2}, @@ -162,6 +268,81 @@ minetest.register_node("techage:heatexchanger2", { sounds = default.node_sound_metal_defaults(), }) +power.register_nodes({"techage:heatexchanger2"}, Cable, "sto", {"D"}) + +techage.register_node({"techage:heatexchanger2"}, { + on_recv_message = function(pos, src, topic, payload) + local nvm = techage.get_nvm(pos) + if topic == "state" then + if techage.is_running(nvm) then + return "running" + else + return "stopped" + end + elseif topic == "delivered" then + return -math.max(nvm.needed or 0, 0) + elseif topic == "load" then + return techage.power.percent(nvm.capa_max, nvm.capa) + elseif topic == "on" then + start_node(pos, techage.get_nvm(pos)) + return true + elseif topic == "off" then + stop_node(pos, techage.get_nvm(pos)) + return true + else + return "unsupported" + end + end, + on_node_load = function(pos, node) + local nvm = techage.get_nvm(pos) + if techage.is_running(nvm) then + play_sound(pos) + else + stop_sound(pos) + end + -- convert to v1 + if not nvm.capa_max then + local pos1 = {x = pos.x, y = pos.y - 1, z = pos.z} + local nvm1 = techage.get_nvm(pos1) + nvm.capa_max = nvm1.capa_max or 1 + nvm.capa = nvm1.capa or 0 + + local own_num = techage.add_node(pos, "techage:heatexchanger2") + State:node_init(pos, nvm, own_num) + if nvm1.running then + State:start(pos, nvm) + end + M(pos):set_string("owner", M(pos1):get_string("owner")) + M(pos):set_string("infotext", S("TA4 Heat Exchanger")..": "..own_num) + + M(pos1):set_string("node_number", "") + M(pos1):set_string("infotext", "") + techage.del_mem(pos1) + Cable:after_place_node(pos) + Cable:after_place_node(pos1) + end + end, +}) + +control.register_nodes({"techage:heatexchanger2"}, { + on_receive = function(pos, tlib2, topic, payload) + end, + on_request = function(pos, tlib2, topic) + if topic == "info" then + local nvm = techage.get_nvm(pos) + return { + type = S("TA4 Heat Exchanger"), + number = M(pos):get_string("node_number") or "", + running = techage.is_running(nvm) or false, + capa = nvm.capa_max or 1, + load = nvm.capa or 0, + } + end + return false + end, + } +) + minetest.register_craft({ output = "techage:heatexchanger2", recipe = { diff --git a/techage/energy_storage/heatexchanger3.lua b/techage/energy_storage/heatexchanger3.lua index 348fdfc..0fa9688 100644 --- a/techage/energy_storage/heatexchanger3.lua +++ b/techage/energy_storage/heatexchanger3.lua @@ -42,6 +42,11 @@ local function after_dig_node(pos, oldnode) Pipe:after_dig_node(pos) end +local function inlet_cmnd(pos, topic, payload) + return techage.transfer(pos, "L", topic, payload, Pipe, + {"techage:ta4_pipe_inlet"}) +end + minetest.register_node("techage:heatexchanger3", { description = S("TA4 Heat Exchanger 3"), tiles = { @@ -57,6 +62,9 @@ minetest.register_node("techage:heatexchanger3", { after_place_node = after_place_node, after_dig_node = after_dig_node, + networks = { + pipe2 = {}, + }, paramtype2 = "facedir", groups = {crumbly = 2, cracky = 2, snappy = 2}, on_rotate = screwdriver.disallow, @@ -66,10 +74,11 @@ minetest.register_node("techage:heatexchanger3", { Pipe:add_secondary_node_names({"techage:heatexchanger3"}) +-- command interface, used by heatexchanger2 techage.register_node({"techage:heatexchanger3"}, { - on_transfer = function(pos, in_dir, topic, payload) - return true - end + on_transfer = function(pos, indir, topic, payload) + return inlet_cmnd(pos, topic, payload) + end, }) minetest.register_craft({ diff --git a/techage/energy_storage/inlet.lua b/techage/energy_storage/inlet.lua index f0050dd..c9632b8 100644 --- a/techage/energy_storage/inlet.lua +++ b/techage/energy_storage/inlet.lua @@ -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 @@ -44,6 +44,9 @@ minetest.register_node("techage:ta4_pipe_inlet", { after_place_node = after_place_node, after_dig_node = after_dig_node, + networks = { + pipe2 = {}, + }, paramtype2 = "facedir", -- important! on_rotate = screwdriver.disallow, -- important! groups = {crumbly = 2, cracky = 2, snappy = 2}, @@ -66,13 +69,6 @@ local Numbers = { } } -local function chat(owner, text) - if owner ~= nil then - minetest.chat_send_player(owner, string.char(0x1b).."(c@#ff0000)".."[Techage] Error: "..text.."!") - end - return text -end - local function get_diameter(pos, in_dir) local dir = tubelib2.Dir6dToVector[in_dir] local pos2, node @@ -125,14 +121,14 @@ local function check_volume(pos, in_dir, owner) "basic_materials:concrete_block", "default:obsidian_glass", "techage:glow_gravel"}) if node_tbl["default:obsidian_glass"] > 1 then - return chat(owner, "one window maximum") + return S("one window maximum") elseif node_tbl["default:obsidian_glass"] + node_tbl["basic_materials:concrete_block"] ~= Numbers.shell[radius] then - return chat(owner, "wrong number of shell nodes") + return S("wrong number of shell nodes") elseif node_tbl["default:gravel"] + node_tbl["techage:glow_gravel"] ~= Numbers.filling[radius] then - return chat(owner, "wrong number of gravel nodes") + return S("wrong number of gravel nodes") end else - return chat(owner, "wrong diameter (should be 5, 7, or 9)") + return S("wrong diameter (should be 5, 7, or 9)") end return true end @@ -162,8 +158,6 @@ techage.register_node({"techage:ta4_pipe_inlet"}, { on_transfer = function(pos, in_dir, topic, payload) if topic == "diameter" then return get_diameter(pos, in_dir) - elseif topic == "integrity" then - return check_volume(pos, in_dir, payload) elseif topic == "volume" then return check_volume(pos, in_dir, payload) elseif topic == "window" then diff --git a/techage/energy_storage/turbine.lua b/techage/energy_storage/turbine.lua index 4e540b2..69e248f 100644 --- a/techage/energy_storage/turbine.lua +++ b/techage/energy_storage/turbine.lua @@ -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 @@ -18,17 +18,7 @@ local S = techage.S local Pipe = techage.LiquidPipe -local function transfer_heatexchanger3(pos, topic, payload) - return techage.transfer(pos, 6, topic, payload, Pipe, - {"techage:heatexchanger3"}) -end - -local function transfer_heatexchanger1(pos, topic, payload) - return techage.transfer(pos, "L", topic, payload, Pipe, - {"techage:heatexchanger1"}) -end - -local function transfer_generator(pos, topic, payload) +local function generator_cmnd(pos, topic, payload) return techage.transfer(pos, "R", topic, payload, nil, {"techage:ta4_generator", "techage:ta4_generator_on"}) end @@ -64,21 +54,6 @@ local function stop_sound(pos) end end -local function after_place_node(pos) - Pipe:after_place_node(pos) -end - -local function after_dig_node(pos, oldnode) - stop_sound(pos) - Pipe:after_dig_node(pos) - techage.del_mem(pos) -end - -local function tubelib2_on_update2(pos, outdir, tlib2, node) - swap_node(pos, "techage:ta4_turbine") - stop_sound(pos) -end - minetest.register_node("techage:ta4_turbine", { description = S("TA4 Turbine"), tiles = { @@ -91,10 +66,17 @@ minetest.register_node("techage:ta4_turbine", { "techage_filling_ta4.png^techage_appl_turbine.png^techage_frame_ta4.png", }, - after_place_node = after_place_node, - after_dig_node = after_dig_node, - tubelib2_on_update2 = tubelib2_on_update2, - + after_place_node = function(pos) + Pipe:after_place_node(pos) + end, + after_dig_node = function(pos, oldnode) + stop_sound(pos) + Pipe:after_dig_node(pos) + techage.del_mem(pos) + end, + networks = { + pipe2 = {}, + }, paramtype2 = "facedir", groups = {cracky=2, crumbly=2, choppy=2}, on_rotate = screwdriver.disallow, @@ -131,8 +113,14 @@ minetest.register_node("techage:ta4_turbine_on", { }, }, - tubelib2_on_update2 = tubelib2_on_update2, - + tubelib2_on_update2 = function(pos, outdir, tlib2, node) + swap_node(pos, "techage:ta4_turbine") + stop_sound(pos) + generator_cmnd(pos, "stop") + end, + networks = { + pipe2 = {}, + }, paramtype2 = "facedir", groups = {not_in_creative_inventory=1}, diggable = false, @@ -142,31 +130,25 @@ minetest.register_node("techage:ta4_turbine_on", { }) Pipe:add_secondary_node_names({"techage:ta4_turbine", "techage:ta4_turbine_on"}) +Pipe:set_valid_sides("techage:ta4_turbine", {"L", "U"}) +Pipe:set_valid_sides("techage:ta4_turbine_on", {"L", "U"}) techage.register_node({"techage:ta4_turbine", "techage:ta4_turbine_on"}, { on_transfer = function(pos, in_dir, topic, payload) local nvm = techage.get_nvm(pos) - if topic == "trigger" then -- used by heatexchanger1 - if not transfer_heatexchanger3(pos, topic, payload) then - return 0 - end - return transfer_generator(pos, topic, payload) - elseif topic == "start" then -- used by generator + if topic == "start" then -- used by heatexchanger1 swap_node(pos, "techage:ta4_turbine_on") play_sound(pos) - nvm.running = true - return true - elseif topic == "stop" then -- used by generator + return generator_cmnd(pos, topic, payload) + elseif topic == "stop" then -- used by heatexchanger1 swap_node(pos, "techage:ta4_turbine") stop_sound(pos) - nvm.running = false - return true - elseif topic == "state" then - return transfer_heatexchanger1(pos, topic, payload) + return generator_cmnd(pos, topic, payload) + else -- used by heatexchanger1 + return generator_cmnd(pos, topic, payload) end end, on_node_load = function(pos, node) - --print("on_node_load", node.name) if node.name == "techage:ta4_turbine_on" then play_sound(pos) end diff --git a/techage/furnace/booster.lua b/techage/furnace/booster.lua index 8783f0d..8e8be01 100644 --- a/techage/furnace/booster.lua +++ b/techage/furnace/booster.lua @@ -20,8 +20,7 @@ local PWR_NEEDED = 3 local CYCLE_TIME = 2 local Cable = techage.ElectricCable -local power = techage.power ---local networks = techage.networks +local power = networks.power local function infotext(pos, state) M(pos):set_string("infotext", S("TA3 Booster")..": "..state) @@ -58,23 +57,6 @@ local function stop_sound(pos) end end -local function on_power(pos) - swap_node(pos, "techage:ta3_booster_on") - infotext(pos, "running") - play_sound(pos) -end - -local function on_nopower(pos) - swap_node(pos, "techage:ta3_booster") - infotext(pos, "no power") - stop_sound(pos) -end - -local function node_timer(pos, elapsed) - power.consumer_alive(pos, Cable, CYCLE_TIME) - return true -end - local function after_place_node(pos) local nvm = techage.get_nvm(pos) Cable:after_place_node(pos) @@ -89,10 +71,6 @@ 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 - minetest.register_node("techage:ta3_booster", { description = S("TA3 Booster"), tiles = { @@ -105,19 +83,17 @@ minetest.register_node("techage:ta3_booster", { "techage_filling_ta3.png^techage_appl_compressor.png^[transformFX^techage_frame_ta3.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:ta3_booster_on") + infotext(pos, "running") + play_sound(pos) + end + return true + end, after_place_node = after_place_node, after_dig_node = after_dig_node, - tubelib2_on_update2 = tubelib2_on_update2, - networks = { - ele1 = { - sides = {B = true, F = true, L = true, D = true, U = true}, - ntype = "con1", - on_power = on_power, - on_nopower = on_nopower, - nominal = PWR_NEEDED, - }, - }, paramtype2 = "facedir", groups = {cracky=2, crumbly=2, choppy=2}, @@ -126,7 +102,6 @@ minetest.register_node("techage:ta3_booster", { sounds = default.node_sound_wood_defaults(), }) - minetest.register_node("techage:ta3_booster_on", { tiles = { -- up, down, right, left, back, front @@ -156,20 +131,17 @@ minetest.register_node("techage:ta3_booster_on", { }, }, - 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:ta3_booster") + infotext(pos, "no power") + stop_sound(pos) + end + return true + end, after_place_node = after_place_node, after_dig_node = after_dig_node, - tubelib2_on_update2 = tubelib2_on_update2, - networks = { - ele1 = { - sides = {B = true, F = true, L = true, D = true, U = true}, - ntype = "con1", - on_power = on_power, - on_nopower = on_nopower, - nominal = PWR_NEEDED, - is_running = function() return true end, - }, - }, paramtype2 = "facedir", groups = {not_in_creative_inventory = 1}, @@ -179,7 +151,7 @@ minetest.register_node("techage:ta3_booster_on", { sounds = default.node_sound_wood_defaults(), }) -Cable:add_secondary_node_names({"techage:ta3_booster", "techage:ta3_booster_on"}) +power.register_nodes({"techage:ta3_booster", "techage:ta3_booster_on"}, Cable, "con", {"B", "F", "L", "D", "U"}) -- for intra machine communication techage.register_node({"techage:ta3_booster", "techage:ta3_booster_on"}, { @@ -194,15 +166,16 @@ techage.register_node({"techage:ta3_booster", "techage:ta3_booster_on"}, { elseif topic == "start" and not nvm.running then if power.power_available(pos, Cable) then nvm.running = true - power.consumer_start(pos, Cable, CYCLE_TIME) minetest.get_node_timer(pos):start(CYCLE_TIME) + swap_node(pos, "techage:ta3_booster_on") + infotext(pos, "running") + play_sound(pos) else infotext(pos, "no power") end elseif topic == "stop" then nvm.running = false swap_node(pos, "techage:ta3_booster") - power.consumer_stop(pos, Cable) minetest.get_node_timer(pos):stop() infotext(pos, "stopped") stop_sound(pos) diff --git a/techage/furnace/firebox.lua b/techage/furnace/firebox.lua index a6f2ca5..813a78b 100644 --- a/techage/furnace/firebox.lua +++ b/techage/furnace/firebox.lua @@ -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 @@ -19,7 +19,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 EFFICIENCY = 2 -- burn cycles @@ -80,38 +80,6 @@ local function booster_cmnd(pos, cmnd) {"techage:ta3_booster", "techage:ta3_booster_on"}) end -local _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 res = liquid.srv_put(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 res - 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 -} - -local _networks = { - pipe2 = { - sides = techage.networks.AllSides, -- Pipe connection sides - ntype = "tank", - }, -} - minetest.register_node("techage:furnace_firebox", { description = S("TA3 Furnace Oil Burner"), tiles = { @@ -134,8 +102,6 @@ minetest.register_node("techage:furnace_firebox", { on_punch = fuel.on_punch, on_receive_fields = fuel.on_receive_fields, on_rightclick = fuel.on_rightclick, - liquid = _liquid, - networks = _networks, on_construct = function(pos) local nvm = techage.get_nvm(pos) @@ -185,8 +151,6 @@ minetest.register_node("techage:furnace_firebox_on", { on_receive_fields = fuel.on_receive_fields, on_punch = fuel.on_punch, on_rightclick = fuel.on_rightclick, - liquid = _liquid, - networks = _networks, }) minetest.register_craft({ @@ -204,7 +168,7 @@ techage.register_node({"techage:furnace_firebox", "techage:furnace_firebox_on"}, 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 @@ -237,4 +201,5 @@ techage.register_node({"techage:furnace_firebox", "techage:furnace_firebox_on"}, end, }) -Pipe:add_secondary_node_names({"techage:furnace_firebox", "techage:furnace_firebox_on"}) +liquid.register_nodes({"techage:furnace_firebox", "techage:furnace_firebox_on"}, + Pipe, "tank", nil, fuel.get_liquid_table(fuel.BT_OIL, fuel.CAPACITY, start_firebox)) diff --git a/techage/furnace/heater.lua b/techage/furnace/heater.lua index 98cde08..e7a4be6 100644 --- a/techage/furnace/heater.lua +++ b/techage/furnace/heater.lua @@ -16,11 +16,11 @@ local M = minetest.get_meta local S = techage.S -local CYCLE_TIME = 2 local PWR_NEEDED = 14 +local CYCLE_TIME = 2 local Cable = techage.ElectricCable -local power = techage.power +local power = networks.power local function swap_node(pos, name) local node = techage.get_node_lvm(pos) @@ -31,18 +31,6 @@ local function swap_node(pos, name) minetest.swap_node(pos, node) end -local function on_power(pos) - swap_node(pos, "techage:furnace_heater_on") -end - -local function on_nopower(pos) - swap_node(pos, "techage:furnace_heater") -end - -local function node_timer(pos, elapsed) - power.consumer_alive(pos, Cable, CYCLE_TIME) - return true -end local function after_place_node(pos) Cable:after_place_node(pos) @@ -53,10 +41,6 @@ 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 - minetest.register_node("techage:furnace_heater", { description = S("TA4 Furnace Heater"), tiles = { @@ -69,19 +53,15 @@ minetest.register_node("techage:furnace_heater", { "techage_concrete.png^techage_appl_heater.png^techage_frame_ta3.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:furnace_heater_on") + end + return true + end, after_place_node = after_place_node, after_dig_node = after_dig_node, - tubelib2_on_update2 = tubelib2_on_update2, - networks = { - ele1 = { - sides = {B = true, F = true, L = true, D = true, U = true}, - ntype = "con1", - on_power = on_power, - on_nopower = on_nopower, - nominal = PWR_NEEDED, - }, - }, paramtype2 = "facedir", groups = {cracky=2, crumbly=2, choppy=2}, @@ -102,20 +82,15 @@ minetest.register_node("techage:furnace_heater_on", { "techage_concrete.png^techage_appl_heater_on.png^techage_frame_ta3.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:furnace_heater") + end + return true + end, after_place_node = after_place_node, after_dig_node = after_dig_node, - tubelib2_on_update2 = tubelib2_on_update2, - networks = { - ele1 = { - sides = {B = true, F = true, L = true, D = true, U = true}, - ntype = "con1", - on_power = on_power, - on_nopower = on_nopower, - nominal = PWR_NEEDED, - is_running = function() return true end, - }, - }, light_source = 8, paramtype2 = "facedir", @@ -126,16 +101,7 @@ minetest.register_node("techage:furnace_heater_on", { sounds = default.node_sound_wood_defaults(), }) -Cable:add_secondary_node_names({"techage:furnace_heater", "techage:furnace_heater_on"}) - -minetest.register_craft({ - output = "techage:furnace_heater", - recipe = { - {'techage:aluminum', 'default:steel_ingot', 'techage:aluminum'}, - {'techage:basalt_stone', 'basic_materials:heating_element', 'techage:basalt_stone'}, - {'techage:aluminum', 'techage:ta4_furnace_ceramic', 'techage:aluminum'}, - }, -}) +power.register_nodes({"techage:furnace_heater", "techage:furnace_heater_on"}, Cable, "con", {"B", "F", "L", "D", "U"}) techage.register_node({"techage:furnace_heater", "techage:furnace_heater_on"}, { -- called from furnace_top @@ -148,16 +114,23 @@ techage.register_node({"techage:furnace_heater", "techage:furnace_heater_on"}, { elseif topic == "start" and not nvm.running then if power.power_available(pos, Cable) then nvm.running = true - power.consumer_start(pos, Cable, CYCLE_TIME) minetest.get_node_timer(pos):start(CYCLE_TIME) return true end elseif topic == "stop" and nvm.running then nvm.running = false swap_node(pos, "techage:furnace_heater") - power.consumer_stop(pos, Cable) minetest.get_node_timer(pos):stop() return true end end }) + +minetest.register_craft({ + output = "techage:furnace_heater", + recipe = { + {'techage:aluminum', 'default:steel_ingot', 'techage:aluminum'}, + {'techage:basalt_stone', 'basic_materials:heating_element', 'techage:basalt_stone'}, + {'techage:aluminum', 'techage:ta4_furnace_ceramic', 'techage:aluminum'}, + }, +}) diff --git a/techage/hydrogen/electrolyzer.lua b/techage/hydrogen/electrolyzer.lua index 48bea97..fb96019 100644 --- a/techage/hydrogen/electrolyzer.lua +++ b/techage/hydrogen/electrolyzer.lua @@ -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,10 +17,9 @@ local M = minetest.get_meta local S = techage.S local Cable = techage.ElectricCable -local power = techage.power +local power = networks.power local Pipe = techage.LiquidPipe -local liquid = techage.liquid -local networks = techage.networks +local liquid = networks.liquid local CYCLE_TIME = 2 local STANDBY_TICKS = 3 @@ -28,39 +27,53 @@ local PWR_NEEDED = 35 local PWR_UNITS_PER_HYDROGEN_ITEM = 80 local CAPACITY = 200 +local function evaluate_percent(s) + return (tonumber(s:sub(1, -2)) or 0) / 100 +end + local function formspec(self, pos, nvm) local amount = (nvm.liquid and nvm.liquid.amount) or 0 local lqd_name = (nvm.liquid and nvm.liquid.name) or "techage:liquid" local arrow = "image[3,1.5;1,1;techage_form_arrow_bg.png^[transformR270]" - if nvm.running then + if techage.is_running(nvm) then arrow = "image[3,1.5;1,1;techage_form_arrow_fg.png^[transformR270]" end if amount > 0 then - lqd_name = lqd_name.." "..amount + lqd_name = lqd_name .. " " .. amount end - return "size[6,4]".. - default.gui_bg.. - default.gui_bg_img.. - default.gui_slots.. - "box[0,-0.1;5.8,0.5;#c6e8ff]".. - "label[2.5,-0.1;"..minetest.colorize( "#000000", S("Electrolyzer")).."]".. - techage.power.formspec_label_bar(pos, 0.1, 0.8, S("Electricity"), PWR_NEEDED, nvm.taken).. - arrow.. - "image_button[3,2.5;1,1;".. self:get_state_button_image(nvm) ..";state_button;]".. - "tooltip[3,2.5;1,1;"..self:get_state_tooltip(nvm).."]".. + return "size[6,4]" .. + default.gui_bg .. + default.gui_bg_img .. + default.gui_slots .. + "box[0,-0.1;5.8,0.5;#c6e8ff]" .. + "label[0.2,-0.1;" .. minetest.colorize( "#000000", S("Electrolyzer")) .. "]" .. + techage.wrench_tooltip(5.4, -0.1).. + techage.formspec_power_bar(pos, 0.1, 0.8, S("Electricity"), nvm.taken, PWR_NEEDED) .. + arrow .. + "image_button[3,2.5;1,1;" .. self:get_state_button_image(nvm) .. ";state_button;]" .. + "tooltip[3,2.5;1,1;" .. self:get_state_tooltip(nvm) .. "]" .. techage.item_image(4.5,2, lqd_name) end +local function can_start(pos, nvm, state) + nvm.liquid = nvm.liquid or {} + nvm.liquid.amount = nvm.liquid.amount or 0 + + if nvm.liquid.amount < CAPACITY then + return true + end + return S("Storage full") +end + local function start_node(pos, nvm, state) - nvm.running = true - nvm.taken = 0 - power.consumer_start(pos, Cable, CYCLE_TIME) + nvm.taken = 0 + nvm.reduction = evaluate_percent(M(pos):get_string("reduction")) + nvm.turnoff = evaluate_percent(M(pos):get_string("turnoff")) end local function stop_node(pos, nvm, state) - nvm.running = false nvm.taken = 0 - power.consumer_stop(pos, Cable) + nvm.running = nil -- legacy end local State = techage.NodeStates:new({ @@ -70,30 +83,14 @@ local State = techage.NodeStates:new({ standby_ticks = STANDBY_TICKS, formspec_func = formspec, infotext_name = S("TA4 Electrolyzer"), + can_start = can_start, start_node = start_node, stop_node = stop_node, }) -local function on_power(pos) - local nvm = techage.get_nvm(pos) - State:start(pos, nvm) - nvm.running = true -end - -local function on_nopower(pos) - local nvm = techage.get_nvm(pos) - State:stop(pos, nvm) - nvm.running = false -end - -local function is_running(pos, nvm) - return nvm.running -end - local function generating(pos, nvm) nvm.num_pwr_units = nvm.num_pwr_units or 0 nvm.countdown = nvm.countdown or 0 - --print("electrolyzer", nvm.running, nvm.taken, nvm.num_pwr_units, nvm.liquid.amount) if nvm.taken > 0 then nvm.num_pwr_units = nvm.num_pwr_units + (nvm.taken or 0) if nvm.num_pwr_units >= PWR_UNITS_PER_HYDROGEN_ITEM then @@ -106,17 +103,33 @@ end -- converts power into hydrogen local function node_timer(pos, elapsed) + local meta = M(pos) local nvm = techage.get_nvm(pos) nvm.liquid = nvm.liquid or {} nvm.liquid.amount = nvm.liquid.amount or 0 if nvm.liquid.amount < CAPACITY then - nvm.taken = power.consumer_alive(pos, Cable, CYCLE_TIME) - generating(pos, nvm) - State:keep_running(pos, nvm, 1) -- TODO warum hier 1 und nicht COUNTDOWN_TICKS? + local in_dir = meta:get_int("in_dir") + local curr_load = power.get_storage_load(pos, Cable, in_dir, 1) + if curr_load > (nvm.turnoff or 0) then + local to_be_taken = PWR_NEEDED * (nvm.reduction or 1) + nvm.taken = power.consume_power(pos, Cable, in_dir, to_be_taken) or 0 + local running = techage.is_running(nvm) + if not running and nvm.taken == to_be_taken then + State:start(pos, nvm) + elseif running and nvm.taken < to_be_taken then + State:nopower(pos, nvm) + elseif running then + generating(pos, nvm) + State:keep_running(pos, nvm, 1) + end + elseif curr_load == 0 then + State:nopower(pos, nvm) + else + State:standby(pos, nvm, S("Turnoff point reached")) + end else - State:blocked(pos, nvm, S("full")) - power.consumer_stop(pos, Cable) + State:blocked(pos, nvm, S("Storage full")) end if techage.is_activeformspec(pos) then M(pos):set_string("formspec", formspec(State, pos, nvm)) @@ -129,6 +142,7 @@ local function on_receive_fields(pos, formname, fields, player) return end local nvm = techage.get_nvm(pos) + techage.set_activeformspec(pos, player) State:state_button_event(pos, nvm, fields) M(pos):set_string("formspec", formspec(State, pos, nvm)) end @@ -165,44 +179,32 @@ local function put(pos, indir, name, amount) return leftover end -local function tubelib2_on_update2(pos, outdir, tlib2, node) - if tlib2.tube_type == "pipe2" then - liquid.update_network(pos, outdir, tlib2) - else - power.update_network(pos, outdir, tlib2) - end -end - -local netw_def = { - pipe2 = { - sides = {R = 1}, -- Pipe connection sides - ntype = "tank", +local tool_config = { + { + type = "const", + name = "needed", + label = S("Maximum power consumption [ku]"), + tooltip = S("Maximum possible\ncurrent consumption"), + value = PWR_NEEDED, }, - ele1 = { - sides = {L = 1}, -- Cable connection sides - ntype = "con2", - on_power = on_power, - on_nopower = on_nopower, - nominal = PWR_NEEDED, - is_running = is_running, + { + type = "dropdown", + choices = "20%,40%,60%,80%,100%", + name = "reduction", + label = S("Current limitation"), + tooltip = S("Configurable value\nfor the current limit"), + default = "100%", + }, + { + type = "dropdown", + choices = "0%,20%,40%,60%,80%", + name = "turnoff", + label = S("Turnoff point"), + tooltip = S("If the charge of the storage\nsystem exceeds the configured value,\nthe block switches off"), + default = "0%", }, } - -local liquid_def = { - capa = CAPACITY, - peek = liquid.srv_peek, - put = put, - untake = put, - 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", formspec(State, pos, nvm)) - end - return amount, name - end -} - + minetest.register_node("techage:ta4_electrolyzer", { description = S("TA4 Electrolyzer"), tiles = { @@ -224,10 +226,7 @@ minetest.register_node("techage:ta4_electrolyzer", { after_place_node = after_place_node, after_dig_node = after_dig_node, - tubelib2_on_update2 = tubelib2_on_update2, on_punch = liquid.on_punch, - networks = netw_def, - liquid = liquid_def, on_receive_fields = on_receive_fields, on_timer = node_timer, on_rightclick = on_rightclick, @@ -236,6 +235,7 @@ minetest.register_node("techage:ta4_electrolyzer", { groups = {cracky=2, crumbly=2, choppy=2}, on_rotate = screwdriver.disallow, is_ground_content = false, + ta3_formspec = tool_config, }) minetest.register_node("techage:ta4_electrolyzer_on", { @@ -268,9 +268,6 @@ minetest.register_node("techage:ta4_electrolyzer_on", { }, }, - tubelib2_on_update2 = tubelib2_on_update2, - networks = netw_def, - liquid = liquid_def, on_receive_fields = on_receive_fields, on_punch = liquid.on_punch, on_timer = node_timer, @@ -283,10 +280,47 @@ minetest.register_node("techage:ta4_electrolyzer_on", { diggable = false, paramtype = "light", light_source = 6, + ta3_formspec = tool_config, }) -Cable:add_secondary_node_names({"techage:ta4_electrolyzer", "techage:ta4_electrolyzer_on"}) -Pipe:add_secondary_node_names({"techage:ta4_electrolyzer", "techage:ta4_electrolyzer_on"}) +local liquid_def = { + capa = CAPACITY, + peek = function(pos) + local nvm = techage.get_nvm(pos) + return liquid.srv_peek(nvm) + end, + put = 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 + local nvm = techage.get_nvm(pos) + M(pos):set_string("formspec", formspec(State, pos, nvm)) + end + return leftover + 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 + local nvm = techage.get_nvm(pos) + M(pos):set_string("formspec", formspec(State, pos, 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 + local nvm = techage.get_nvm(pos) + M(pos):set_string("formspec", formspec(State, pos, nvm)) + end + return leftover + end, +} + +liquid.register_nodes({"techage:ta4_electrolyzer", "techage:ta4_electrolyzer_on"}, Pipe, "tank", {"R"}, liquid_def) +power.register_nodes({"techage:ta4_electrolyzer", "techage:ta4_electrolyzer_on"}, Cable, "con", {"L"}) + techage.register_node({"techage:ta4_electrolyzer", "techage:ta4_electrolyzer_on"}, { on_recv_message = function(pos, src, topic, payload) local nvm = techage.get_nvm(pos) @@ -298,6 +332,13 @@ techage.register_node({"techage:ta4_electrolyzer", "techage:ta4_electrolyzer_on" return State:on_receive_message(pos, topic, payload) end end, + on_node_load = function(pos, node) + local meta = M(pos) + if not meta:contains("reduction") then + meta:set_string("reduction", "100%") + meta:set_string("turnoff", "0%") + end + end, }) minetest.register_craft({ diff --git a/techage/hydrogen/fuelcell.lua b/techage/hydrogen/fuelcell.lua index b7822f9..6fabbab 100644 --- a/techage/hydrogen/fuelcell.lua +++ b/techage/hydrogen/fuelcell.lua @@ -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,38 +17,23 @@ local M = minetest.get_meta local S = techage.S local Cable = techage.ElectricCable -local power = techage.power +local power = networks.power local Pipe = techage.LiquidPipe -local liquid = techage.liquid -local networks = techage.networks +local liquid = networks.liquid +local control = networks.control local CYCLE_TIME = 2 local STANDBY_TICKS = 4 -local PWR_CAPA = 34 +local COUNTDOWN_TICKS = 2 +local PWR_PERF = 34 local PWR_UNITS_PER_HYDROGEN_ITEM = 75 local CAPACITY = 100 -local States = {} -local STATE = function(pos) return States[techage.get_node_lvm(pos).name] end - -local function is_gen1(nvm) - if not nvm.running then - local is_gen1 = dump(nvm.is_gen1 or false) - return "checkbox[0.3,0.5;is_gen1;"..S("Cat. 1 generator")..";"..is_gen1.."]".. - "tooltip[0.3,0.5;1,1;"..S("If set, fuelcell will work\nas cat. 1 generator")..";#0C3D32;#FFFFFF]" - end - if nvm.is_gen1 then - return "label[0.5,0.7;"..S("Cat. 1 generator").."]" - else - return "label[0.5,0.7;"..S("Cat. 2 generator").."]" - end -end - local function formspec(self, pos, nvm) local amount = (nvm.liquid and nvm.liquid.amount) or 0 local lqd_name = (nvm.liquid and nvm.liquid.name) or "techage:liquid" local arrow = "image[2,1.5;1,1;techage_form_arrow_bg.png^[transformR270]" - if nvm.running then + if techage.is_running(nvm) then arrow = "image[2,1.5;1,1;techage_form_arrow_fg.png^[transformR270]" end if amount > 0 then @@ -59,40 +44,14 @@ local function formspec(self, pos, nvm) default.gui_bg_img.. default.gui_slots.. "box[0,-0.1;5.8,0.5;#c6e8ff]".. - "label[2.5,-0.1;"..minetest.colorize( "#000000", S("Fuel Cell")).."]".. + "label[0.2,-0.1;"..minetest.colorize( "#000000", S("Fuel Cell")).."]".. techage.item_image(0.5,2, lqd_name).. arrow.. - is_gen1(nvm).. "image_button[2,2.5;1,1;".. self:get_state_button_image(nvm) ..";state_button;]".. "tooltip[2,2.5;1,1;"..self:get_state_tooltip(nvm).."]".. - techage.power.formspec_label_bar(pos, 3.5, 0.8, S("Electricity"), PWR_CAPA, nvm.given) + techage.formspec_power_bar(pos, 3.5, 0.8, S("Electricity"), nvm.provided, PWR_PERF) end -local function start_node(pos, nvm, state) - nvm.running = true - nvm.given = 0 - local outdir = M(pos):get_int("outdir") - power.generator_start(pos, Cable, CYCLE_TIME, outdir) -end - -local function stop_node(pos, nvm, state) - nvm.running = false - nvm.given = 0 - local outdir = M(pos):get_int("outdir") - power.generator_stop(pos, Cable, outdir) -end - -local State = techage.NodeStates:new({ - node_name_passive = "techage:ta4_fuelcell", - node_name_active = "techage:ta4_fuelcell_on", - cycle_time = CYCLE_TIME, - standby_ticks = STANDBY_TICKS, - formspec_func = formspec, - infotext_name = S("TA4 Fuel Cell Gen2"), - start_node = start_node, - stop_node = stop_node, -}) - local function has_hydrogen(nvm) nvm.liquid = nvm.liquid or {} nvm.liquid.amount = nvm.liquid.amount or 0 @@ -100,32 +59,76 @@ local function has_hydrogen(nvm) return nvm.num_pwr_units > 0 or (nvm.liquid.amount > 0 and nvm.liquid.name == "techage:hydrogen") end +local function can_start(pos, nvm, state) + if has_hydrogen(nvm) then + return true + end + return S("no hydrogen") +end + + local function consuming(pos, nvm) if nvm.num_pwr_units <= 0 then nvm.num_pwr_units = nvm.num_pwr_units + PWR_UNITS_PER_HYDROGEN_ITEM nvm.liquid.amount = nvm.liquid.amount - 1 end - nvm.num_pwr_units = nvm.num_pwr_units - nvm.given + nvm.num_pwr_units = nvm.num_pwr_units - nvm.provided end --- converts hydrogen into power +local function start_node(pos, nvm, state) + local meta = M(pos) + nvm.provided = 0 + local outdir = meta:get_int("outdir") + power.start_storage_calc(pos, Cable, outdir) + techage.evaluate_charge_termination(nvm, meta) +end + +local function stop_node(pos, nvm, state) + nvm.provided = 0 + nvm.running = nil -- legacy + local outdir = M(pos):get_int("outdir") + power.start_storage_calc(pos, Cable, outdir) +end + +local State = techage.NodeStates:new({ + node_name_passive = "techage:ta4_fuelcell", + node_name_active = "techage:ta4_fuelcell_on", + cycle_time = CYCLE_TIME, + standby_ticks = STANDBY_TICKS, + formspec_func = formspec, + infotext_name = S("TA4 Fuel Cell"), + can_start = can_start, + start_node = start_node, + stop_node = stop_node, +}) + local function node_timer(pos, elapsed) local nvm = techage.get_nvm(pos) - local state = STATE(pos) - --print("fuelcell", nvm.running, nvm.given, nvm.num_pwr_units) - if has_hydrogen(nvm) then - local outdir = M(pos):get_int("outdir") - nvm.given = power.generator_alive(pos, Cable, CYCLE_TIME, outdir) + local running = techage.is_running(nvm) + local hydro = has_hydrogen(nvm) + if running and not hydro then + State:standby(pos, nvm, S("no hydrogen")) + stop_node(pos, nvm, State) + elseif not running and hydro 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 consuming(pos, nvm) - state:keep_running(pos, nvm, 1) -- TODO warum hier 1 und nicht COUNTDOWN_TICKS? - else - state:standby(pos, nvm) - nvm.given = 0 + State:keep_running(pos, nvm, COUNTDOWN_TICKS) end if techage.is_activeformspec(pos) then - M(pos):set_string("formspec", formspec(state, pos, nvm)) + M(pos):set_string("formspec", formspec(State, pos, nvm)) end - return true + return State:is_active(nvm) end local function on_receive_fields(pos, formname, fields, player) @@ -133,36 +136,22 @@ local function on_receive_fields(pos, formname, fields, player) return end local nvm = techage.get_nvm(pos) - if fields.is_gen1 then - nvm.is_gen1 = fields.is_gen1 == "true" - local node = minetest.get_node(pos) - if nvm.is_gen1 then - node.name = "techage:ta4_fuelcell2" - else - node.name = "techage:ta4_fuelcell" - end - minetest.swap_node(pos, node) - local outdir = M(pos):get_int("outdir") - techage.power.update_network(pos, outdir, Cable) - end - STATE(pos):state_button_event(pos, nvm, fields) - M(pos):set_string("formspec", formspec(STATE(pos), pos, nvm)) + State:state_button_event(pos, nvm, fields) end local function on_rightclick(pos, node, clicker) local nvm = techage.get_nvm(pos) techage.set_activeformspec(pos, clicker) - M(pos):set_string("formspec", formspec(STATE(pos), pos, nvm)) + M(pos):set_string("formspec", formspec(State, pos, nvm)) end local function after_place_node(pos) local nvm = techage.get_nvm(pos) - nvm.running = false nvm.num_pwr_units = 0 local number = techage.add_node(pos, "techage:ta4_fuelcell") - STATE(pos):node_init(pos, nvm, number) - local node = minetest.get_node(pos) + State:node_init(pos, nvm, number) M(pos):set_int("outdir", networks.side_to_outdir(pos, "R")) + M(pos):set_string("formspec", formspec(State, pos, nvm)) Pipe:after_place_node(pos) Cable:after_place_node(pos) local inv = M(pos):get_inventory() @@ -176,47 +165,13 @@ local function after_dig_node(pos, oldnode, oldmetadata, digger) Cable:after_dig_node(pos) end -local function tubelib2_on_update2(pos, outdir, tlib2, node) - if tlib2.tube_type == "pipe2" then - liquid.update_network(pos, outdir, tlib2) - else - 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 netw_def = { - pipe2 = { - sides = {L = 1}, -- Pipe connection sides - ntype = "tank", - }, - ele1 = { - sides = {R = 1}, -- Cable connection sides - ntype = "gen2", - nominal = PWR_CAPA, - }, -} - -local liquid_def = { - capa = CAPACITY, - peek = liquid.srv_peek, - put = function(pos, indir, name, amount) - 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", formspec(STATE(pos), pos, nvm)) - end - return leftover - 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", formspec(STATE(pos), pos, nvm)) - end - return amount, name - end -} - minetest.register_node("techage:ta4_fuelcell", { description = S("TA4 Fuel Cell"), tiles = { @@ -238,13 +193,12 @@ minetest.register_node("techage:ta4_fuelcell", { after_place_node = after_place_node, after_dig_node = after_dig_node, - tubelib2_on_update2 = tubelib2_on_update2, + get_generator_data = get_generator_data, on_punch = liquid.on_punch, - networks = netw_def, - liquid = liquid_def, on_receive_fields = on_receive_fields, on_timer = node_timer, on_rightclick = on_rightclick, + ta4_formspec = techage.generator_settings("ta4", PWR_PERF), paramtype2 = "facedir", groups = {cracky=2, crumbly=2, choppy=2}, @@ -282,13 +236,12 @@ minetest.register_node("techage:ta4_fuelcell_on", { }, }, - tubelib2_on_update2 = tubelib2_on_update2, - networks = netw_def, - liquid = liquid_def, + get_generator_data = get_generator_data, on_receive_fields = on_receive_fields, on_punch = liquid.on_punch, on_timer = node_timer, on_rightclick = on_rightclick, + ta4_formspec = techage.generator_settings("ta4", PWR_PERF), paramtype2 = "facedir", groups = {not_in_creative_inventory=1}, @@ -299,138 +252,81 @@ minetest.register_node("techage:ta4_fuelcell_on", { light_source = 6, }) -------------------------------------------------------------------------------- --- Gen1 fuellcell -------------------------------------------------------------------------------- -local State2 = techage.NodeStates:new({ - node_name_passive = "techage:ta4_fuelcell2", - node_name_active = "techage:ta4_fuelcell2_on", - cycle_time = CYCLE_TIME, - standby_ticks = STANDBY_TICKS, - formspec_func = formspec, - infotext_name = S("TA4 Fuel Cell Gen1"), - start_node = start_node, - stop_node = stop_node, -}) - -local netw_def2 = { - pipe2 = { - sides = {L = 1}, -- Pipe connection sides - ntype = "tank", - }, - ele1 = { - sides = {R = 1}, -- Cable connection sides - ntype = "gen1", - nominal = PWR_CAPA - 1, -- to be able to distiguish between cat1 and 2 - }, +local liquid_def = { + capa = CAPACITY, + peek = function(pos) + local nvm = techage.get_nvm(pos) + return liquid.srv_peek(nvm) + end, + put = 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 + local nvm = techage.get_nvm(pos) + M(pos):set_string("formspec", formspec(State, pos, nvm)) + end + return leftover + 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 + local nvm = techage.get_nvm(pos) + M(pos):set_string("formspec", formspec(State, pos, 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 + local nvm = techage.get_nvm(pos) + M(pos):set_string("formspec", formspec(State, pos, nvm)) + end + return leftover + end, } -minetest.register_node("techage:ta4_fuelcell2", { - description = S("TA4 Fuel Cell"), - tiles = { - -- up, down, right, left, back, front - "techage_filling_ta4.png^techage_frame_ta4_top.png^techage_appl_arrow.png", - "techage_filling_ta4.png^techage_frame_ta4.png", - "techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_hole_electric.png", - "techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_hole_pipe.png", - "techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_fuelcell.png^techage_appl_ctrl_unit.png^[transformFX", - "techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_fuelcell.png^techage_appl_ctrl_unit.png", - }, +liquid.register_nodes({"techage:ta4_fuelcell", "techage:ta4_fuelcell_on"}, Pipe, "tank", {"L"}, liquid_def) +power.register_nodes({"techage:ta4_fuelcell", "techage:ta4_fuelcell_on"}, Cable, "gen", {"R"}) - can_dig = function(pos, player) - if minetest.is_protected(pos, player:get_player_name()) then - return false - end - return liquid.is_empty(pos) - end, - - after_place_node = after_place_node, - after_dig_node = after_dig_node, - tubelib2_on_update2 = tubelib2_on_update2, - on_punch = liquid.on_punch, - networks = netw_def2, - liquid = liquid_def, - on_receive_fields = on_receive_fields, - on_timer = node_timer, - on_rightclick = on_rightclick, - - paramtype2 = "facedir", - groups = {cracky=2, crumbly=2, choppy=2, not_in_creative_inventory=1}, - on_rotate = screwdriver.disallow, - is_ground_content = false, - drop = "techage:ta4_fuelcell", -}) +minetest.register_alias_force("techage:ta4_fuelcell2", "techage:ta4_fuelcell") +minetest.register_alias_force("techage:ta4_fuelcell2_on", "techage:ta4_fuelcell_on") -minetest.register_node("techage:ta4_fuelcell2_on", { - description = S("TA4 Fuel Cell"), - tiles = { - -- up, down, right, left, back, front - "techage_filling_ta4.png^techage_frame_ta4_top.png^techage_appl_arrow.png", - "techage_filling_ta4.png^techage_frame_ta4.png", - "techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_hole_electric.png", - "techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_hole_pipe.png", - { - image = "techage_filling4_ta4.png^techage_frame4_ta4.png^techage_appl_fuelcell4.png^techage_appl_ctrl_unit4.png^[transformFX", - backface_culling = false, - animation = { - type = "vertical_frames", - aspect_w = 32, - aspect_h = 32, - length = 0.8, - }, - }, - { - image = "techage_filling4_ta4.png^techage_frame4_ta4.png^techage_appl_fuelcell4.png^techage_appl_ctrl_unit4.png", - backface_culling = false, - animation = { - type = "vertical_frames", - aspect_w = 32, - aspect_h = 32, - length = 0.8, - }, - }, - }, - - tubelib2_on_update2 = tubelib2_on_update2, - networks = netw_def2, - liquid = liquid_def, - on_receive_fields = on_receive_fields, - on_punch = liquid.on_punch, - on_timer = node_timer, - on_rightclick = on_rightclick, - - paramtype2 = "facedir", - groups = {not_in_creative_inventory=1}, - on_rotate = screwdriver.disallow, - is_ground_content = false, - diggable = false, - paramtype = "light", - light_source = 6, -}) - -States["techage:ta4_fuelcell"] = State -States["techage:ta4_fuelcell_on"] = State -States["techage:ta4_fuelcell2"] = State2 -States["techage:ta4_fuelcell2_on"] = State2 - -Cable:add_secondary_node_names({"techage:ta4_fuelcell", "techage:ta4_fuelcell_on", - "techage:ta4_fuelcell2", "techage:ta4_fuelcell2_on"}) -Pipe:add_secondary_node_names({"techage:ta4_fuelcell", "techage:ta4_fuelcell_on", - "techage:ta4_fuelcell2", "techage:ta4_fuelcell2_on"}) -techage.register_node({"techage:ta4_fuelcell", "techage:ta4_fuelcell_on", - "techage:ta4_fuelcell2", "techage:ta4_fuelcell2_on"}, { +techage.register_node({"techage:ta4_fuelcell", "techage:ta4_fuelcell_on"}, { on_recv_message = function(pos, src, topic, payload) local nvm = techage.get_nvm(pos) if topic == "load" then return techage.power.percent(CAPACITY, (nvm.liquid and nvm.liquid.amount) or 0) elseif topic == "delivered" then - return math.floor((nvm.given or 0) + 0.5) + return math.floor((nvm.provided or 0) + 0.5) else - return STATE(pos):on_receive_message(pos, topic, payload) + return State:on_receive_message(pos, topic, payload) end end, }) +control.register_nodes({"techage:ta4_fuelcell", "techage:ta4_fuelcell_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("TA4 Fuel Cell"), + 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:ta4_fuelcell", recipe = { diff --git a/techage/init.lua b/techage/init.lua index 9b5ffeb..f8a7b60 100644 --- a/techage/init.lua +++ b/techage/init.lua @@ -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 @@ -13,7 +13,7 @@ techage = {} -- Version for compatibility checks, see readme.md/history -techage.version = 0.26 +techage.version = 1.00 if minetest.global_exists("tubelib") then minetest.log("error", "[techage] Techage can't be used together with the mod tubelib!") @@ -36,6 +36,9 @@ elseif minetest.global_exists("lcdlib") and lcdlib.version < 1.0 then elseif minetest.global_exists("safer_lua") and safer_lua.version < 1.0 then minetest.log("error", "[techage] Techage requires safer_lua version 1.0 or newer!") return +elseif minetest.global_exists("networks") and networks.version < 0.08 then + minetest.log("error", "[techage] Techage requires networks version 0.08 or newer!") + return end -- Test MT 5.4 new string mode @@ -45,7 +48,7 @@ techage.BLEND = minetest.features.use_texture_alpha_string_modes and "blend" or techage.NodeDef = {} -- node registration info techage.max_num_forceload_blocks = tonumber(minetest.settings:get("techage_max_num_forceload_blocks")) or 24 - + techage.basalt_stone_enabled = minetest.settings:get_bool("techage_basalt_stone_enabled") ~= false techage.ore_rarity = tonumber(minetest.settings:get("techage_ore_rarity")) or 1 techage.modified_recipes_enabled = minetest.settings:get_bool("techage_modified_recipes_enabled") ~= false @@ -85,11 +88,11 @@ dofile(MP.."/basis/fuel_lib.lua") -- common fuel functions dofile(MP.."/basis/mark.lua") dofile(MP.."/basis/mark2.lua") dofile(MP.."/basis/assemble.lua") -dofile(MP.."/basis/networks.lua") dofile(MP.."/basis/recipe_lib.lua") dofile(MP.."/basis/formspec_update.lua") dofile(MP.."/basis/windturbine_lib.lua") dofile(MP.."/basis/laser_lib.lua") +dofile(MP.."/basis/legacy.lua") -- Main doc dofile(MP.."/doc/manual_DE.lua") @@ -99,11 +102,9 @@ dofile(MP.."/doc/items.lua") dofile(MP.."/doc/guide.lua") -- construction guides dofile(MP.."/doc/manual_api.lua") -- external API +dofile(MP.."/items/filling.lua") + -- Power networks -dofile(MP.."/power/node_api.lua") -dofile(MP.."/power/junction.lua") -dofile(MP.."/power/distribution.lua") -dofile(MP.."/power/schedule.lua") dofile(MP.."/power/formspecs.lua") dofile(MP.."/power/drive_axle.lua") dofile(MP.."/power/gearbox.lua") @@ -112,13 +113,13 @@ dofile(MP.."/power/electric_cable.lua") dofile(MP.."/power/junctionbox.lua") dofile(MP.."/power/power_terminal.lua") dofile(MP.."/power/power_terminal2.lua") +dofile(MP.."/power/powerswitchbox_legacy.lua") dofile(MP.."/power/powerswitchbox.lua") dofile(MP.."/power/powerswitch.lua") dofile(MP.."/power/protection.lua") dofile(MP.."/power/power_line.lua") dofile(MP.."/power/ta4_cable.lua") dofile(MP.."/power/ta4_cable_wall_entry.lua") -dofile(MP.."/power/laser.lua") -- Iron Age dofile(MP.."/iron_age/main.lua") @@ -143,17 +144,21 @@ dofile(MP.."/steam_engine/boiler.lua") dofile(MP.."/steam_engine/cylinder.lua") dofile(MP.."/steam_engine/flywheel.lua") +-- TA2 gravity-based energy storage +dofile(MP.."/ta2_energy_storage/ta2_rope.lua") +dofile(MP.."/ta2_energy_storage/ta2_winch.lua") +dofile(MP.."/ta2_energy_storage/ta2_weight_chest.lua") + -- Liquids I dofile(MP.."/liquids/liquid_pipe.lua") dofile(MP.."/liquids/valve.lua") -dofile(MP.."/liquids/node_api.lua") dofile(MP.."/liquids/pipe_wall_entry.lua") -- Basic Machines dofile(MP.."/basic_machines/consumer.lua") -- consumer base model dofile(MP.."/basic_machines/source.lua") dofile(MP.."/basic_machines/pusher.lua") -dofile(MP.."/basic_machines/legacy_nodes.lua") +dofile(MP.."/basic_machines/foreign_nodes.lua") dofile(MP.."/basic_machines/mods_support.lua") dofile(MP.."/basic_machines/grinder.lua") dofile(MP.."/basic_machines/distributor.lua") @@ -231,6 +236,11 @@ dofile(MP.."/ta3_power/akkubox.lua") dofile(MP.."/ta3_power/axle2power.lua") dofile(MP.."/ta3_power/power2axle.lua") +-- TA4 power based +dofile(MP.."/ta4_power/laser.lua") +dofile(MP.."/ta4_power/transformer.lua") +dofile(MP.."/ta4_power/electricmeter.lua") + -- Digtron if minetest.global_exists("digtron") then dofile(MP.."/digtron/battery.lua") @@ -263,7 +273,6 @@ end -- Test dofile(MP.."/recipe_checker.lua") dofile(MP.."/.test/sink.lua") ---dofile(MP.."/.test/meta_node.lua") -- Solar dofile(MP.."/solar/minicell.lua") @@ -335,10 +344,8 @@ dofile(MP.."/items/redstone.lua") dofile(MP.."/items/cement.lua") dofile(MP.."/items/cracking.lua") dofile(MP.."/items/ceramic.lua") - -if techage.basalt_stone_enabled then - dofile(MP.."/items/basalt.lua") -end +dofile(MP.."/items/basalt.lua") +dofile(MP.."/items/moreblocks.lua") -- Carts dofile(MP.."/carts/tank_cart.lua") @@ -347,3 +354,6 @@ dofile(MP.."/carts/chest_cart.lua") -- Prevent other mods from using IE techage.IE = nil + + +function techage.icta_register_condition(key, tData) end diff --git a/techage/items/basalt.lua b/techage/items/basalt.lua index e65d9a7..8a771d5 100644 --- a/techage/items/basalt.lua +++ b/techage/items/basalt.lua @@ -33,17 +33,6 @@ minetest.register_node("techage:basalt_stone", { sounds = default.node_sound_stone_defaults(), }) -stairs.register_stair_and_slab( - "basalt_stone", - "techage:basalt_stone", - {cracky = 3, stone = 1}, - {"default_stone.png^[brighten"}, - "Basalt Stone Stair", - "Basalt Stone Slab", - default.node_sound_stone_defaults(), - false -) - minetest.register_node("techage:basalt_cobble", { description = S("Basalt Cobble"), tiles = {"default_cobble.png^[brighten"}, @@ -51,17 +40,6 @@ minetest.register_node("techage:basalt_cobble", { sounds = default.node_sound_stone_defaults(), }) -stairs.register_stair_and_slab( - "basalt_cobble", - "techage:basalt_cobble", - {cracky = 3, stone = 2}, - {"default_cobble.png^[brighten"}, - "Basalt Cobble Stair", - "Basalt Cobble Slab", - default.node_sound_stone_defaults(), - false -) - minetest.register_node("techage:basalt_stone_brick", { description = S("Basalt Stone Brick"), paramtype2 = "facedir", @@ -72,17 +50,6 @@ minetest.register_node("techage:basalt_stone_brick", { sounds = default.node_sound_stone_defaults(), }) -stairs.register_stair_and_slab( - "basalt_stone_brick", - "techage:basalt_stone_brick", - {cracky = 2, stone = 1}, - {"default_stone_brick.png^[brighten"}, - "Basalt Brick Stair", - "Basalt Brick Slab", - default.node_sound_stone_defaults(), - false -) - minetest.register_node("techage:basalt_stone_block", { description = S("Basalt Stone Block"), tiles = {"default_stone_block.png^[brighten"}, @@ -91,39 +58,17 @@ minetest.register_node("techage:basalt_stone_block", { sounds = default.node_sound_stone_defaults(), }) -stairs.register_stair_and_slab( - "basalt_stone_block", - "techage:basalt_stone_block", - {cracky = 2, stone = 1}, - {"default_stone_block.png^[brighten"}, - "Basalt Stone Block Stair", - "Basalt Stone Block Slab", - default.node_sound_stone_defaults(), - false -) - minetest.register_node("techage:basalt_gravel", { description = S("Basalt Gravel"), tiles = {"default_gravel.png^[brighten"}, - groups = {crumbly = 2, falling_node = 1}, + groups = {crumbly = 2, falling_node = 1, gravel = 1}, sounds = default.node_sound_gravel_defaults(), }) -stairs.register_stair_and_slab( - "sieved_basalt_gravel", - "techage:sieved_basalt_gravel", - {crumbly = 2, falling_node = 1}, - {"default_gravel.png^[brighten"}, - "Basalt Gravel Stair", - "Basalt Gravel Slab", - default.node_sound_gravel_defaults(), - false -) - minetest.register_node("techage:sieved_basalt_gravel", { description = S("Sieved Basalt Gravel"), tiles = {"default_gravel.png^[brighten"}, - groups = {crumbly = 2, falling_node = 1, not_in_creative_inventory=1}, + groups = {crumbly = 2, falling_node = 1, gravel = 1, not_in_creative_inventory=1}, sounds = default.node_sound_gravel_defaults(), }) @@ -133,48 +78,26 @@ minetest.register_node("techage:basalt_glass", { tiles = {"techage_basalt_glass.png"}, use_texture_alpha = techage.BLEND, paramtype = "light", - paramtype2 = "glasslikeliquidlevel", + paramtype2 = "facedir", sunlight_propagates = true, is_ground_content = false, groups = {cracky = 3, oddly_breakable_by_hand = 3}, sounds = default.node_sound_glass_defaults(), }) -stairs.register_stair_and_slab( - "basalt_glass", - "techage:basalt_glass", - {cracky = 3, oddly_breakable_by_hand = 3}, - {"techage_basalt_glass.png"}, - "Basalt Glass Stair", - "Basalt Glass Slab", - default.node_sound_glass_defaults(), - false -) - minetest.register_node("techage:basalt_glass2", { description = S("Basalt Glass 2"), drawtype = "glasslike_framed_optional", tiles = {"techage_basalt_glass2.png"}, use_texture_alpha = techage.BLEND, paramtype = "light", - paramtype2 = "glasslikeliquidlevel", + paramtype2 = "facedir", sunlight_propagates = true, is_ground_content = false, groups = {cracky = 3, oddly_breakable_by_hand = 3}, sounds = default.node_sound_glass_defaults(), }) -stairs.register_stair_and_slab( - "basalt_glass2", - "techage:basalt_glass2", - {cracky = 3, oddly_breakable_by_hand = 3}, - {"techage_basalt_glass2.png"}, - "Basalt Glass 2 Stair", - "Basalt Glass 2 Slab", - default.node_sound_glass_defaults(), - false -) - minetest.register_node("techage:basalt_glass_thin", { description = S("Basalt Glass Thin"), drawtype = "nodebox", diff --git a/techage/items/filling.lua b/techage/items/filling.lua new file mode 100644 index 0000000..55fb0ac --- /dev/null +++ b/techage/items/filling.lua @@ -0,0 +1,14 @@ +-- Needed for the trowel + +local fillings = {} + +minetest.register_on_mods_loaded(function() + for name, ndef in pairs(minetest.registered_nodes) do + -- test if it is a simple node without logic + if ndef and not ndef.groups.soil and name ~= "default:cobble" and + not ndef.after_place_node and not ndef.on_construct then + table.insert(fillings, name) + end + end + networks.register_filling_items(fillings) +end) diff --git a/techage/items/moreblocks.lua b/techage/items/moreblocks.lua new file mode 100644 index 0000000..63a14ba --- /dev/null +++ b/techage/items/moreblocks.lua @@ -0,0 +1,90 @@ +--[[ + + TechAge + ======= + + Copyright (C) 2020-2021 Joachim Stolberg + + AGPL v3 + See LICENSE.txt for more information + + techage node registrations + +]]-- + +local function register_alias(name) + minetest.register_alias("stairs:slab_" ..name, "techage:slab_" ..name) + minetest.register_alias("stairs:slab_" ..name.. "_inverted", "techage:slab_" ..name.. "_inverted") + minetest.register_alias("stairs:slab_" ..name.. "_wall", "techage:slab_" ..name.. "_wall") + minetest.register_alias("stairs:slab_" ..name.. "_quarter", "techage:slab_" ..name.. "_quarter") + minetest.register_alias("stairs:slab_" ..name.. "_quarter_inverted", "techage:slab_" ..name.. "_quarter_inverted") + minetest.register_alias("stairs:slab_" ..name.. "_quarter_wall", "techage:slab_" ..name.. "_quarter_wall") + minetest.register_alias("stairs:slab_" ..name.. "_three_quarter", "techage:slab_" ..name.. "_three_quarter") + minetest.register_alias("stairs:slab_" ..name.. "_three_quarter_inverted", "techage:slab_" ..name.. "_three_quarter_inverted") + minetest.register_alias("stairs:slab_" ..name.. "_three_quarter_wall", "techage:slab_" ..name.. "_three_quarter_wall") + minetest.register_alias("stairs:stair_" ..name, "techage:stair_" ..name) + minetest.register_alias("stairs:stair_" ..name.. "_inverted", "techage:stair_" ..name.. "_inverted") + minetest.register_alias("stairs:stair_" ..name.. "_wall", "techage:stair_" ..name.. "_wall") + minetest.register_alias("stairs:stair_" ..name.. "_wall_half", "techage:stair_" ..name.. "_wall_half") + minetest.register_alias("stairs:stair_" ..name.. "_wall_half_inverted", "techage:stair_" ..name.. "_wall_half_inverted") + minetest.register_alias("stairs:stair_" ..name.. "_half", "techage:stair_" ..name.. "_half") + minetest.register_alias("stairs:stair_" ..name.. "_half_inverted", "techage:stair_" ..name.. "_half_inverted") + minetest.register_alias("stairs:stair_" ..name.. "_right_half", "techage:stair_" ..name.. "_right_half") + minetest.register_alias("stairs:stair_" ..name.. "_right_half_inverted", "techage:stair_" ..name.. "_right_half_inverted") + minetest.register_alias("stairs:stair_" ..name.. "_wall_half", "techage:stair_" ..name.. "_wall_half") + minetest.register_alias("stairs:stair_" ..name.. "_wall_half_inverted", "techage:stair_" ..name.. "_wall_half_inverted") + minetest.register_alias("stairs:stair_" ..name.. "_inner", "techage:stair_" ..name.. "_inner") + minetest.register_alias("stairs:stair_" ..name.. "_inner_inverted", "techage:stair_" ..name.. "_inner_inverted") + minetest.register_alias("stairs:stair_" ..name.. "_outer", "techage:stair_" ..name.. "_outer") + minetest.register_alias("stairs:stair_" ..name.. "_outer_inverted", "techage:stair_" ..name.. "_outer_inverted") +end + +local NodeNames = { + "techage:compressed_gravel", + "techage:red_stone", + "techage:red_stone_block", + "techage:red_stone_brick", + + "techage:basalt_cobble", + "techage:basalt_stone", + "techage:basalt_stone_block", + "techage:basalt_stone_brick", + "techage:sieved_basalt_gravel", + + "techage:basalt_glass", + "techage:basalt_glass2", + "techage:bauxite_stone", + "techage:bauxite_cobble", +} + +if(minetest.get_modpath("moreblocks")) then + for _,name in ipairs(NodeNames) do + local ndef = minetest.registered_nodes[name] + if ndef then + ndef = table.copy(ndef) + local subname = string.split(name, ":")[2] + ndef.sunlight_propagates = true + ndef.groups.not_in_creative_inventory = 1 + stairsplus:register_all("techage", subname, name, ndef) + register_alias(subname) + end + end +else + for _,name in ipairs(NodeNames) do + local ndef = minetest.registered_nodes[name] + if ndef then + local subname = string.split(name, ":")[2] + stairs.register_stair_and_slab( + subname, + name, + ndef.groups, + ndef.tiles, + ndef.description.." Stair", + ndef.description.." Slab", + ndef.sound, + false + ) + register_alias(subname) + end + end +end diff --git a/techage/items/redstone.lua b/techage/items/redstone.lua index edce07f..d1d2950 100644 --- a/techage/items/redstone.lua +++ b/techage/items/redstone.lua @@ -22,17 +22,6 @@ minetest.register_node("techage:red_stone", { sounds = default.node_sound_stone_defaults(), }) -stairs.register_stair_and_slab( - "red_stone", - "techage:red_stone", - {cracky = 3, stone = 1}, - {"default_stone.png^[colorize:#ff4538:110"}, - "Red Stone Stair", - "Red Stone Slab", - default.node_sound_stone_defaults(), - false -) - minetest.register_node("techage:red_stone_brick", { description = S("Red Stone Brick"), paramtype2 = "facedir", @@ -43,17 +32,6 @@ minetest.register_node("techage:red_stone_brick", { sounds = default.node_sound_stone_defaults(), }) -stairs.register_stair_and_slab( - "red_stone_brick", - "techage:red_stone_brick", - {cracky = 2, stone = 1}, - {"default_stone_brick.png^[colorize:#ff4538:110"}, - "Red Brick Stair", - "Red Brick Slab", - default.node_sound_stone_defaults(), - false -) - minetest.register_node("techage:red_stone_block", { description = S("Red Stone Block"), tiles = {"default_stone_block.png^[colorize:#ff4538:110"}, @@ -62,18 +40,6 @@ minetest.register_node("techage:red_stone_block", { sounds = default.node_sound_stone_defaults(), }) -stairs.register_stair_and_slab( - "red_stone_block", - "techage:red_stone_block", - {cracky = 2, stone = 1}, - {"default_stone_block.png^[colorize:#ff4538:110"}, - "Red Stone Block Stair", - "Red Stone Block Slab", - default.node_sound_stone_defaults(), - false -) - - minetest.register_craft({ output = "techage:red_stone_brick 4", recipe = { diff --git a/techage/items/registered_nodes.lua b/techage/items/registered_nodes.lua index 9645591..deccdeb 100644 --- a/techage/items/registered_nodes.lua +++ b/techage/items/registered_nodes.lua @@ -37,3 +37,4 @@ minetest.register_on_mods_loaded(function() end end) +minetest.override_item("default:gravel", {groups = {crumbly = 2, gravel = 1, falling_node = 1}}) \ No newline at end of file diff --git a/techage/lamps/growlight.lua b/techage/lamps/growlight.lua index ffbb4b4..20dc22c 100644 --- a/techage/lamps/growlight.lua +++ b/techage/lamps/growlight.lua @@ -16,8 +16,10 @@ local S = techage.S local CYCLE_TIME = 2 local RANDOM_VAL = 20 +local PWR_NEEDED = 1 + local Cable = techage.ElectricCable -local power = techage.power +local power = networks.power local Flowers = {} local Plants = {} local Ignore = { ["flowers:waterlily_waving"] = true } @@ -34,8 +36,30 @@ local Positions = { {x = 1, y =-1, z =-1}, } -local function node_timer(pos, elapsed) - power.consumer_alive(pos, Cable, CYCLE_TIME) +local function swap_node(pos, postfix) + local node = techage.get_node_lvm(pos) + local parts = string.split(node.name, "_") + if postfix == parts[2] then + return + end + node.name = parts[1].."_"..postfix + minetest.swap_node(pos, node) + techage.light_ring(pos, postfix == "on") +end + +local function on_nopower(pos) + swap_node(pos, "off") + local nvm = techage.get_nvm(pos) + nvm.turned_on = false +end + +local function on_power(pos) + swap_node(pos, "on") + local nvm = techage.get_nvm(pos) + nvm.turned_on = true +end + +local function grow_flowers(pos) local nvm = techage.get_nvm(pos) local mem = techage.get_mem(pos) mem.grow_pos = mem.grow_pos or {} -- keep the pos blank for some time @@ -67,6 +91,22 @@ local function node_timer(pos, elapsed) end end end +end + +local function node_timer_on(pos, elapsed) + grow_flowers(pos) + local consumed = power.consume_power(pos, Cable, nil, PWR_NEEDED) + if consumed < PWR_NEEDED then + on_nopower(pos) + end + return true +end + +local function node_timer_off(pos, elapsed) + local consumed = power.consume_power(pos, Cable, nil, PWR_NEEDED) + if consumed == PWR_NEEDED then + on_power(pos) + end return true end @@ -95,7 +135,6 @@ techage.register_lamp("techage:growlight", { {-8/16, -8/16, -8/16, 8/16, -13/32, 8/16}, }, }, - on_switch_lamp = on_switch_lamp, high_power = true, },{ description = S("TA4 LED Grow Light"), @@ -116,8 +155,7 @@ techage.register_lamp("techage:growlight", { {-8/16, -8/16, -8/16, 8/16, -13/32, 8/16}, }, }, - on_timer = node_timer, - on_switch_lamp = on_switch_lamp, + on_timer = node_timer_on, high_power = true, }) diff --git a/techage/lamps/lib.lua b/techage/lamps/lib.lua index aa7147b..2d30149 100644 --- a/techage/lamps/lib.lua +++ b/techage/lamps/lib.lua @@ -21,7 +21,7 @@ local PWR_NEEDED = 0.5 local CYCLE_TIME = 2 local Cable = techage.ElectricCable -local power = techage.power +local power = networks.power local function swap_node(pos, postfix) local node = techage.get_node_lvm(pos) @@ -53,8 +53,35 @@ local function is_running(pos, nvm) return nvm.turned_on end -local function node_timer(pos, elapsed) - power.consumer_alive(pos, Cable, CYCLE_TIME) +local function node_timer_off1(pos, elapsed) + local consumed = power.consume_power(pos, Cable, nil, PWR_NEEDED) + if consumed == PWR_NEEDED then + on_power(pos) + end + return true +end + +local function node_timer_off2(pos, elapsed) + local consumed = power.consume_power(pos, Cable, nil, PWR_NEEDED * 2) + if consumed == PWR_NEEDED * 2 then + on_power(pos) + end + return true +end + +local function node_timer_on1(pos, elapsed) + local consumed = power.consume_power(pos, Cable, nil, PWR_NEEDED) + if consumed < PWR_NEEDED then + on_nopower(pos) + end + return true +end + +local function node_timer_on2(pos, elapsed) + local consumed = power.consume_power(pos, Cable, nil, PWR_NEEDED * 2) + if consumed < PWR_NEEDED * 2 then + on_nopower(pos) + end return true end @@ -66,12 +93,10 @@ local function lamp_on_rightclick(pos, node, clicker) local nvm = techage.get_nvm(pos) if not nvm.turned_on and power.power_available(pos, Cable) then nvm.turned_on = true - power.consumer_start(pos, Cable, CYCLE_TIME) minetest.get_node_timer(pos):start(CYCLE_TIME) swap_node(pos, "on") else nvm.turned_on = false - power.consumer_stop(pos, Cable) minetest.get_node_timer(pos):stop() swap_node(pos, "off") end @@ -107,44 +132,19 @@ local function tubelib2_on_update2(pos, outdir, tlib2, node) power.update_network(pos, outdir, tlib2) end -local net_def = { - ele1 = { - sides = {U=1, D=1, L=1, R=1, F=1, B=1}, -- Cable connection sides - ntype = "con1", - on_power = on_power, - on_nopower = on_nopower, - nominal = PWR_NEEDED, - is_running = is_running, - }, -} - -local net_def2 = { - ele1 = { - sides = {U=1, D=1, L=1, R=1, F=1, B=1}, -- Cable connection sides - ntype = "con1", - on_power = on_power, - on_nopower = on_nopower, - nominal = PWR_NEEDED * 2, - is_running = is_running, - }, -} - - function techage.register_lamp(basename, ndef_off, ndef_on) + if ndef_off.high_power then + ndef_off.on_timer = ndef_off.on_timer or node_timer_off2 + else + ndef_off.on_timer = ndef_off.on_timer or node_timer_off1 + end ndef_off.after_place_node = after_place_node ndef_off.after_dig_node = after_dig_node - ndef_off.tubelib2_on_update2 = tubelib2_on_update2 - if ndef_off.high_power then - ndef_off.networks = net_def2 - else - ndef_off.networks = net_def - end ndef_off.on_rightclick = lamp_on_rightclick if not ndef_off.on_rotate then ndef_off.on_place = on_place end ndef_off.on_rotate = ndef_off.on_rotate or on_rotate - ndef_off.on_timer = node_timer ndef_off.paramtype = "light" ndef_off.use_texture_alpha = techage.CLIP ndef_off.light_source = 0 @@ -154,17 +154,15 @@ function techage.register_lamp(basename, ndef_off, ndef_on) ndef_off.is_ground_content = false ndef_off.sounds = default.node_sound_glass_defaults() + if ndef_on.high_power then + ndef_on.on_timer = ndef_on.on_timer or node_timer_on2 + else + ndef_on.on_timer = ndef_on.on_timer or node_timer_on1 + end ndef_on.after_place_node = after_place_node ndef_on.after_dig_node = after_dig_node - ndef_on.tubelib2_on_update2 = tubelib2_on_update2 - if ndef_on.high_power then - ndef_on.networks = net_def2 - else - ndef_on.networks = net_def - end ndef_on.on_rightclick = lamp_on_rightclick ndef_on.on_rotate = ndef_on.on_rotate or on_rotate - ndef_on.on_timer = ndef_on.on_timer or node_timer ndef_on.paramtype = "light" ndef_on.use_texture_alpha = techage.CLIP ndef_on.light_source = minetest.LIGHT_MAX @@ -178,6 +176,9 @@ function techage.register_lamp(basename, ndef_off, ndef_on) minetest.register_node(basename.."_off", ndef_off) minetest.register_node(basename.."_on", ndef_on) - Cable:add_secondary_node_names({basename.."_off", basename.."_on"}) + power.register_nodes({basename.."_off", basename.."_on"}, Cable, "con") + techage.register_node_for_v1_transition({basename.."_off", basename.."_on"}, function(pos, node) + power.update_network(pos, nil, Cable) + end) end diff --git a/techage/liquids/filler.lua b/techage/liquids/filler.lua index 2375e9b..842bd90 100644 --- a/techage/liquids/filler.lua +++ b/techage/liquids/filler.lua @@ -124,6 +124,7 @@ minetest.register_node("techage:filler", { on_rotate = screwdriver.disallow, -- important! paramtype = "light", sunlight_propagates = true, + use_texture_alpha = techage.CLIP, is_ground_content = false, groups = {cracky=2, crumbly=2, choppy=2}, sounds = default.node_sound_defaults(), diff --git a/techage/liquids/liquid_pipe.lua b/techage/liquids/liquid_pipe.lua index ea4ff11..9f485ce 100644 --- a/techage/liquids/liquid_pipe.lua +++ b/techage/liquids/liquid_pipe.lua @@ -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 @@ -19,7 +19,8 @@ local M = minetest.get_meta local S = techage.S local MAX_PIPE_LENGHT = 100 -local networks = techage.networks + +local power = networks.power local Pipe = tubelib2.Tube:new({ dirs_to_check = {1,2,3,4,5,6}, @@ -31,7 +32,7 @@ local Pipe = tubelib2.Tube:new({ "techage:ta3_pipeS", "techage:ta3_pipeA", "techage:ta3_pipe_wall_entry", "techage:ta3_valve_open", }, - secondary_node_names = {"techage:ta3_valve_closed"}, + secondary_node_names = {}, after_place_tube = function(pos, param2, tube_type, num_tubes) local name = minetest.get_node(pos).name if name == "techage:ta3_pipe_wall_entry" then @@ -44,6 +45,11 @@ local Pipe = tubelib2.Tube:new({ end, }) +-- Use global callback instead of node related functions +Pipe:register_on_tube_update2(function(pos, outdir, tlib2, node) + power.update_network(pos, outdir, tlib2, node) +end) + minetest.register_node("techage:ta3_pipeS", { description = S("TA Pipe"), tiles = { @@ -150,33 +156,31 @@ local Boxes = { } } -techage.register_junction("techage:ta3_junctionpipe", 1/8, Boxes, Pipe, { +local names = networks.register_junction("techage:ta3_junctionpipe", 1/8, Boxes, Pipe, { description = S("TA Junction Pipe"), tiles = {"techage_gaspipe_junction.png"}, + use_texture_alpha = techage.CLIP, + is_ground_content = false, groups = {crumbly = 2, cracky = 2, snappy = 2, techage_trowel = 1}, sounds = default.node_sound_metal_defaults(), after_place_node = function(pos, placer, itemstack, pointed_thing) - local name = "techage:ta3_junctionpipe"..techage.junction_type(pos, Pipe) + local name = "techage:ta3_junctionpipe" .. networks.junction_type(pos, Pipe) minetest.swap_node(pos, {name = name, param2 = 0}) Pipe:after_place_node(pos) end, tubelib2_on_update2 = function(pos, dir1, tlib2, node) - local name = "techage:ta3_junctionpipe"..techage.junction_type(pos, Pipe) + local name = "techage:ta3_junctionpipe" .. networks.junction_type(pos, Pipe) minetest.swap_node(pos, {name = name, param2 = 0}) - techage.liquid.update_network(pos) + power.update_network(pos, 0, tlib2, node) end, after_dig_node = function(pos, oldnode, oldmetadata, digger) Pipe:after_dig_node(pos) end, - networks = { - pipe2 = { - sides = networks.AllSides, -- connection sides for pipes - ntype = "junc", - }, - }, }, 25) +power.register_nodes(names, Pipe, "junc") + minetest.register_craft({ output = "techage:ta3_junctionpipe25 2", recipe = { diff --git a/techage/liquids/node_api.lua b/techage/liquids/node_api.lua deleted file mode 100644 index 87e9874..0000000 --- a/techage/liquids/node_api.lua +++ /dev/null @@ -1,245 +0,0 @@ ---[[ - - TechAge - ======= - - Copyright (C) 2019-2020 Joachim Stolberg - - AGPL v3 - See LICENSE.txt for more information - - Liquid transportation API via Pipe(s) (peer, put, take) - -]]-- - -local P2S = minetest.pos_to_string -local M = minetest.get_meta -local N = function(pos) return minetest.get_node(pos).name end -local LQD = function(pos) return (minetest.registered_nodes[techage.get_node_lvm(pos).name] or {}).liquid end -local Pipe = techage.LiquidPipe -local S = techage.S - -local net_def = techage.networks.net_def -local networks = techage.networks - -local liquid = techage.liquid - --- --- Networks --- - --- determine network ID (largest hash number of all pumps) -local function determine_netID(pos, outdir) - local netID = 0 - networks.connection_walk(pos, outdir, Pipe, function(pos, indir, node) - local ntype = net_def(pos, "pipe2").ntype - if ntype and ntype == "pump" then - local new = minetest.hash_node_position(pos) * 8 + outdir - if netID <= new then - netID = new - end - end - end) - return netID -end - --- store network ID on each pump like node -local function store_netID(pos, outdir, netID) - networks.connection_walk(pos, outdir, Pipe, function(pos, indir, node) - local ntype = net_def(pos, "pipe2").ntype - if ntype and ntype == "pump" then - local nvm = techage.get_nvm(pos) - local outdir = networks.Flip[indir] - nvm.pipe2 = nvm.pipe2 or {} - nvm.pipe2.netIDs = nvm.pipe2.netIDs or {} - nvm.pipe2.netIDs[outdir] = netID - end - end) -end - --- delete network and ID on each pump like node -local function delete_netID(pos, outdir) - local netID = 0 - networks.connection_walk(pos, outdir, Pipe, function(pos, indir, node) - local ntype = net_def(pos, "pipe2").ntype - if ntype and ntype == "pump" then - local nvm = techage.get_nvm(pos) - local outdir = networks.Flip[indir] - if nvm.pipe2 and nvm.pipe2.netIDs and nvm.pipe2.netIDs[outdir] then - netID = nvm.pipe2.netIDs[outdir] - nvm.pipe2.netIDs[outdir] = nil - end - end - end) - networks.delete_network("pipe2", netID) -end - -local function get_netID(pos, outdir) - local nvm = techage.get_nvm(pos) - if not nvm.pipe2 or not nvm.pipe2.netIDs or not nvm.pipe2.netIDs[outdir] then - local netID = determine_netID(pos, outdir) - store_netID(pos, outdir, netID) - end - return nvm.pipe2 and nvm.pipe2.netIDs and nvm.pipe2.netIDs[outdir] -end - --- return list of nodes {pos = ..., indir = ...} of given type -local function get_network_table(pos, outdir, ntype) - local netID = get_netID(pos, outdir) - if netID then - local netw = networks.get_network("pipe2", netID) - if not netw then - netw = networks.collect_network_nodes(pos, outdir, Pipe) - networks.set_network("pipe2", netID, netw) - end - if not netw[ntype] then -- connection lost (e.g. tank cart)? - -- reactivate network - networks.node_connections(pos, Pipe) - delete_netID(pos, outdir) - end - --print("netw", string.format("%012X", netID), dump(netw[ntype])) - return netw[ntype] or {} - end - return {} -end - - --- --- Client remote functions --- - --- Determine and return liquid 'name' from the --- remote inventory. -function liquid.peek(pos, outdir) - for _,item in ipairs(get_network_table(pos, 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 liquid.put(pos, outdir, name, amount, player_name) - for _,item in ipairs(get_network_table(pos, 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 player_name then - local num = techage.get_node_number(pos) or "000" - techage.mark_position(player_name, item.pos, "("..num..") put", "", 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 liquid.take(pos, outdir, name, amount, player_name) - local taken = 0 - for _,item in ipairs(get_network_table(pos, outdir, "tank")) do - local liq = LQD(item.pos) - if liq and liq.take then - if player_name then - local num = techage.get_node_number(pos) - techage.mark_position(player_name, item.pos, "("..num..") take", "", 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 liquid.untake(pos, outdir, name, amount) - for _,item in ipairs(get_network_table(pos, 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 local functions --- - -function liquid.srv_peek(pos, indir) - local nvm = techage.get_nvm(pos) - nvm.liquid = nvm.liquid or {} - return nvm.liquid.name -end - -function liquid.srv_put(pos, indir, name, amount) - local nvm = techage.get_nvm(pos) - 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 - local capa = LQD(pos).capa - 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 liquid.srv_take(pos, indir, name, amount) - local nvm = techage.get_nvm(pos) - 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 - - --- To be called from each node via 'tubelib2_on_update2' --- 'output' is optional and only needed for nodes with dedicated --- pipe sides (e.g. pumps). -function liquid.update_network(pos, outdir) - networks.node_connections(pos, Pipe) - delete_netID(pos, outdir) -end - --- To be called from each pump in 'after_dig_node' --- before calling 'techage.del_mem(pos)' -function liquid.after_dig_pump(pos) - local nvm = techage.get_nvm(pos) - if nvm.pipe2 and nvm.pipe2.netIDs then - for outdir, netID in pairs(nvm.pipe2.netIDs) do - networks.delete_network("pipe2", netID) - end - end -end \ No newline at end of file diff --git a/techage/liquids/pump.lua b/techage/liquids/pump.lua index 66cdd53..2762e78 100644 --- a/techage/liquids/pump.lua +++ b/techage/liquids/pump.lua @@ -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,35 +17,14 @@ 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 Flip = techage.networks.Flip +local liquid = networks.liquid +local Flip = networks.Flip local STANDBY_TICKS = 3 local COUNTDOWN_TICKS = 4 local CYCLE_TIME = 2 local CAPA = 4 --- 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 State3 = techage.NodeStates:new({ node_name_passive = "techage:t3_pump", node_name_active = "techage:t3_pump_on", @@ -63,14 +42,15 @@ local State4 = techage.NodeStates:new({ }) local function pumping(pos, nvm, state, capa) + local mem = techage.get_mem(pos) + mem.dbg_cycles = (mem.dbg_cycles or 0) - 1 local outdir = M(pos):get_int("outdir") - local starter = get_starter_name(pos) --print("pumping", outdir, Flip[outdir]) - local taken, name = liquid.take(pos, Flip[outdir], nil, capa, starter) + local taken, name = liquid.take(pos, Pipe, Flip[outdir], nil, capa, mem.dbg_cycles > 0) if taken > 0 then - local leftover = liquid.put(pos, outdir, name, taken, starter) - if leftover then - liquid.untake(pos, Flip[outdir], name, leftover) + local leftover = liquid.put(pos, Pipe, outdir, name, taken, mem.dbg_cycles > 0) + if leftover and leftover > 0 then + liquid.untake(pos, Pipe, Flip[outdir], name, leftover) if leftover == taken then state:blocked(pos, nvm) return @@ -117,25 +97,22 @@ local function on_rightclick(pos, node, clicker) local nvm = techage.get_nvm(pos) if node.name == "techage:t3_pump" then - set_starter_name(pos, clicker) + local mem = techage.get_mem(pos) + mem.dbg_cycles = 5 State3:start(pos, nvm) elseif node.name == "techage:t3_pump_on" then State3:stop(pos, nvm) elseif node.name == "techage:t4_pump" then - set_starter_name(pos, clicker) + local mem = techage.get_mem(pos) + mem.dbg_cycles = 5 State4:start(pos, nvm) elseif node.name == "techage:t4_pump_on" then State4:stop(pos, nvm) end end -local function tubelib2_on_update2(pos, outdir, tlib2, node) - liquid.update_network(pos, outdir) -end - local function after_dig_node(pos, oldnode, oldmetadata, digger) Pipe:after_dig_node(pos) - liquid.after_dig_pump(pos) techage.del_mem(pos) end @@ -215,23 +192,14 @@ local ta4_tiles_act = { }, } -local nworks = { - pipe2 = { - sides = {L = 1, R = 1}, -- Pipe connection side - ntype = "pump", - }, -} - minetest.register_node("techage:t3_pump", { description = S("TA3 Pump"), tiles = ta3_tiles_pas, after_place_node = after_place_node3, on_rightclick = on_rightclick, - tubelib2_on_update2 = tubelib2_on_update2, on_timer = node_timer3, after_dig_node = after_dig_node, on_rotate = screwdriver.disallow, - networks = nworks, paramtype2 = "facedir", on_rotate = screwdriver.disallow, groups = {cracky=2}, @@ -244,11 +212,9 @@ minetest.register_node("techage:t3_pump_on", { tiles = ta3_tiles_act, --after_place_node = after_place_node3, on_rightclick = on_rightclick, - tubelib2_on_update2 = tubelib2_on_update2, on_timer = node_timer3, after_dig_node = after_dig_node, on_rotate = screwdriver.disallow, - networks = nworks, paramtype2 = "facedir", on_rotate = screwdriver.disallow, diggable = false, @@ -262,11 +228,9 @@ minetest.register_node("techage:t4_pump", { tiles = ta4_tiles_pas, after_place_node = after_place_node4, on_rightclick = on_rightclick, - tubelib2_on_update2 = tubelib2_on_update2, on_timer = node_timer4, after_dig_node = after_dig_node, on_rotate = screwdriver.disallow, - networks = nworks, paramtype2 = "facedir", on_rotate = screwdriver.disallow, groups = {cracky=2}, @@ -279,11 +243,9 @@ minetest.register_node("techage:t4_pump_on", { tiles = ta4_tiles_act, --after_place_node = after_place_node4, on_rightclick = on_rightclick, - tubelib2_on_update2 = tubelib2_on_update2, on_timer = node_timer4, after_dig_node = after_dig_node, on_rotate = screwdriver.disallow, - networks = nworks, paramtype2 = "facedir", on_rotate = screwdriver.disallow, diggable = false, @@ -304,11 +266,12 @@ techage.register_node({"techage:t4_pump", "techage:t4_pump_on"}, { end, }) -Pipe:add_secondary_node_names({ +-- Pumps have to provide one output and one input side +liquid.register_nodes({ "techage:t3_pump", "techage:t3_pump_on", "techage:t4_pump", "techage:t4_pump_on", -}) - +}, Pipe, "pump", {"L", "R"}, {}) + minetest.register_craft({ output = "techage:t3_pump 2", recipe = { diff --git a/techage/liquids/silo.lua b/techage/liquids/silo.lua index 7b521f3..f570f78 100644 --- a/techage/liquids/silo.lua +++ b/techage/liquids/silo.lua @@ -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 @@ -18,7 +18,7 @@ local M = minetest.get_meta local S = techage.S local LQD = function(pos) return (minetest.registered_nodes[techage.get_node_lvm(pos).name] or {}).liquid end local Pipe = techage.LiquidPipe -local liquid = techage.liquid +local liquid = networks.liquid local INV_SIZE = 8 local STACKMAX = 99 @@ -170,13 +170,6 @@ local tLiquid = { end, } -local tNetworks = { - pipe2 = { - sides = techage.networks.AllSides, -- Pipe connection sides - ntype = "tank", - }, -} - minetest.register_node("techage:ta3_silo", { description = S("TA3 Silo"), tiles = { @@ -203,16 +196,11 @@ minetest.register_node("techage:ta3_silo", { meta:set_string("infotext", S("TA3 Silo").." "..number) Pipe:after_place_node(pos) end, - tubelib2_on_update2 = function(pos, outdir, tlib2, node) - liquid.update_network(pos, outdir) - end, after_dig_node = function(pos, oldnode, oldmetadata, digger) Pipe:after_dig_node(pos) techage.remove_node(pos, oldnode, oldmetadata) techage.del_mem(pos) end, - liquid = tLiquid, - networks = tNetworks, can_dig = can_dig, allow_metadata_inventory_put = allow_metadata_inventory_put, allow_metadata_inventory_take = allow_metadata_inventory_take, @@ -249,16 +237,11 @@ minetest.register_node("techage:ta4_silo", { meta:set_string("infotext", S("TA4 Silo").." "..number) Pipe:after_place_node(pos) end, - tubelib2_on_update2 = function(pos, outdir, tlib2, node) - liquid.update_network(pos, outdir) - end, after_dig_node = function(pos, oldnode, oldmetadata, digger) Pipe:after_dig_node(pos) techage.remove_node(pos, oldnode, oldmetadata) techage.del_mem(pos) end, - liquid = tLiquid, - networks = tNetworks, can_dig = can_dig, allow_metadata_inventory_put = allow_metadata_inventory_put, allow_metadata_inventory_take = allow_metadata_inventory_take, @@ -335,7 +318,7 @@ techage.register_node({"techage:ta3_silo", "techage:ta4_silo"}, { end, }) -Pipe:add_secondary_node_names({"techage:ta3_silo", "techage:ta4_silo"}) +liquid.register_nodes({"techage:ta3_silo", "techage:ta4_silo"}, Pipe, "tank", nil, tLiquid) minetest.register_craft({ output = "techage:ta3_silo", diff --git a/techage/liquids/tank.lua b/techage/liquids/tank.lua index 0e53d05..a2aab49 100644 --- a/techage/liquids/tank.lua +++ b/techage/liquids/tank.lua @@ -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,23 +15,25 @@ local S2P = minetest.string_to_pos local P2S = minetest.pos_to_string 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 local S = techage.S local Pipe = techage.LiquidPipe -local liquid = techage.liquid +local liquid = networks.liquid local CAPACITY = 1000 local function on_rightclick(pos, node, clicker) 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 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 @@ -41,14 +43,19 @@ local function can_dig(pos, player) if minetest.is_protected(pos, player:get_player_name()) then return false end - return liquid.is_empty(pos) + return techage.liquid.is_empty(pos) +end + +local function peek_liquid(pos, indir) + local nvm = techage.get_nvm(pos) + return liquid.srv_peek(nvm) end local function take_liquid(pos, indir, name, amount) - amount, name = liquid.srv_take(pos, indir, name, amount) + local nvm = techage.get_nvm(pos) + amount, name = liquid.srv_take(nvm, name, amount) 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)) end return amount, name end @@ -57,10 +64,10 @@ 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) + local nvm = techage.get_nvm(pos) + local leftover = liquid.srv_put(nvm, name, amount, LQD(pos).capa) 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)) end return leftover end @@ -68,21 +75,14 @@ local function put_liquid(pos, indir, name, amount) end local function untake_liquid(pos, indir, name, amount) - local leftover = liquid.srv_put(pos, indir, name, amount) + local nvm = techage.get_nvm(pos) + local leftover = liquid.srv_put(nvm, name, amount, LQD(pos).capa) 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)) end return leftover end -local networks_def = { - pipe2 = { - sides = techage.networks.AllSides, -- Pipe connection sides - ntype = "tank", - }, -} - minetest.register_node("techage:ta3_tank", { description = S("TA3 Tank"), tiles = { @@ -101,27 +101,16 @@ minetest.register_node("techage:ta3_tank", { local number = techage.add_node(pos, "techage:ta3_tank") meta:set_string("node_number", number) meta:set_string("owner", placer:get_player_name()) - meta:set_string("formspec", liquid.formspec(pos, nvm)) + meta:set_string("formspec", techage.liquid.formspec(pos, nvm)) meta:set_string("infotext", S("TA3 Tank").." "..number) Pipe:after_place_node(pos) end, - tubelib2_on_update2 = function(pos, outdir, tlib2, node) - liquid.update_network(pos, outdir) - end, on_timer = node_timer, - on_punch = liquid.on_punch, + on_punch = techage.liquid.on_punch, after_dig_node = function(pos, oldnode, oldmetadata, digger) Pipe:after_dig_node(pos) techage.remove_node(pos, oldnode, oldmetadata) end, - liquid = { - capa = CAPACITY, - peek = liquid.srv_peek, - put = put_liquid, - take = take_liquid, - untake = untake_liquid, - }, - networks = networks_def, on_rightclick = on_rightclick, can_dig = can_dig, paramtype2 = "facedir", @@ -131,6 +120,16 @@ minetest.register_node("techage:ta3_tank", { sounds = default.node_sound_metal_defaults(), }) +liquid.register_nodes({"techage:ta3_tank"}, + Pipe, "tank", nil, { + capa = CAPACITY, + peek = peek_liquid, + put = put_liquid, + take = take_liquid, + untake = untake_liquid, + } +) + minetest.register_node("techage:oiltank", { description = S("Oil Tank"), tiles = { @@ -161,27 +160,16 @@ minetest.register_node("techage:oiltank", { local number = techage.add_node(pos, "techage:oiltank") meta:set_string("node_number", number) meta:set_string("owner", placer:get_player_name()) - meta:set_string("formspec", liquid.formspec(pos, nvm)) + meta:set_string("formspec", techage.liquid.formspec(pos, nvm)) meta:set_string("infotext", S("Oil Tank").." "..number) Pipe:after_place_node(pos) end, - tubelib2_on_update2 = function(pos, outdir, tlib2, node) - liquid.update_network(pos, outdir) - end, on_timer = node_timer, - on_punch = liquid.on_punch, + on_punch = techage.liquid.on_punch, after_dig_node = function(pos, oldnode, oldmetadata, digger) Pipe:after_dig_node(pos) techage.remove_node(pos, oldnode, oldmetadata) end, - liquid = { - capa = CAPACITY * 4, - peek = liquid.srv_peek, - put = put_liquid, - take = take_liquid, - untake = untake_liquid, - }, - networks = networks_def, on_rightclick = on_rightclick, can_dig = can_dig, paramtype2 = "facedir", @@ -191,6 +179,16 @@ minetest.register_node("techage:oiltank", { sounds = default.node_sound_metal_defaults(), }) +liquid.register_nodes({"techage:oiltank"}, + Pipe, "tank", nil, { + capa = CAPACITY * 4, + peek = peek_liquid, + put = put_liquid, + take = take_liquid, + untake = untake_liquid, + } +) + minetest.register_node("techage:ta4_tank", { description = S("TA4 Tank"), tiles = { @@ -210,13 +208,10 @@ minetest.register_node("techage:ta4_tank", { local number = techage.add_node(pos, "techage:ta4_tank") meta:set_string("node_number", number) meta:set_string("owner", placer:get_player_name()) - meta:set_string("formspec", liquid.formspec(pos, nvm)) + meta:set_string("formspec", techage.liquid.formspec(pos, nvm)) meta:set_string("infotext", S("TA4 Tank").." "..number) Pipe:after_place_node(pos) end, - tubelib2_on_update2 = function(pos, outdir, tlib2, node) - liquid.update_network(pos, outdir) - end, on_receive_fields = function(pos, formname, fields, player) if minetest.is_protected(pos, player:get_player_name()) then return @@ -226,19 +221,11 @@ minetest.register_node("techage:ta4_tank", { end end, on_timer = node_timer, - on_punch = liquid.on_punch, + on_punch = techage.liquid.on_punch, after_dig_node = function(pos, oldnode, oldmetadata, digger) Pipe:after_dig_node(pos) techage.remove_node(pos, oldnode, oldmetadata) end, - liquid = { - capa = CAPACITY * 2, - peek = liquid.srv_peek, - put = put_liquid, - take = take_liquid, - untake = untake_liquid, - }, - networks = networks_def, on_rightclick = on_rightclick, can_dig = can_dig, paramtype2 = "facedir", @@ -248,9 +235,17 @@ minetest.register_node("techage:ta4_tank", { sounds = default.node_sound_metal_defaults(), }) -techage.register_node({"techage:ta3_tank", "techage:ta4_tank", "techage:oiltank"}, liquid.recv_message) +liquid.register_nodes({"techage:ta4_tank"}, + Pipe, "tank", nil, { + capa = CAPACITY * 2, + peek = peek_liquid, + put = put_liquid, + take = take_liquid, + untake = untake_liquid, + } +) -Pipe:add_secondary_node_names({"techage:ta3_tank", "techage:ta4_tank", "techage:oiltank"}) +techage.register_node({"techage:ta3_tank", "techage:ta4_tank", "techage:oiltank"}, techage.liquid.recv_message) minetest.register_craft({ output = "techage:ta3_tank 2", diff --git a/techage/liquids/valve.lua b/techage/liquids/valve.lua index a3ccc68..afea000 100644 --- a/techage/liquids/valve.lua +++ b/techage/liquids/valve.lua @@ -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,73 +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 function switch_node(pos, node) - if node.name == "techage:ta3_valve_open" then - node.name = "techage:ta3_valve_closed" - --node.name = "default:dirt" - minetest.swap_node(pos, node) - local number = M(pos):get_string("node_number") - M(pos):set_string("infotext", S("TA3 Valve closed")..": "..number) - Pipe:after_dig_tube(pos, {name = "techage:ta3_valve_open", param2 = node.param2}) - elseif node.name == "techage:ta3_valve_closed" then - node.name = "techage:ta3_valve_open" - minetest.swap_node(pos, node) - local number = M(pos):get_string("node_number") - M(pos):set_string("infotext", S("TA3 Valve open")..": "..number) - Pipe:after_place_tube(pos) - end - minetest.sound_play("techage_valve", { - pos = pos, - gain = 1, - max_hear_distance = 10}) -end - -local function on_rightclick(pos, node, clicker) - if not minetest.is_protected(pos, clicker:get_player_name()) then - switch_node(pos, node) - end -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)) --- return true --- end --- return false ---end - ---local function can_dig(pos, player) --- if minetest.is_protected(pos, player:get_player_name()) then --- return false --- end --- return liquid.is_empty(pos) ---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 nvm = techage.get_nvm(pos) --- M(pos):set_string("formspec", liquid.formspec(pos, nvm)) --- end --- 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)) --- end --- return leftover --- end --- return amount ---end +local liquid = networks.liquid minetest.register_node("techage:ta3_valve_open", { description = S("TA Valve"), @@ -102,21 +36,24 @@ minetest.register_node("techage:ta3_valve_open", { return true end local meta = M(pos) - local nvm = techage.get_nvm(pos) - nvm.liquid = {} local number = techage.add_node(pos, "techage:ta3_valve_closed") meta:set_string("node_number", number) meta:set_string("owner", placer:get_player_name()) - meta:set_string("infotext", S("TA3 Valve open")..": "..number) + meta:set_string("infotext", S("TA3 Valve")..": "..number) return false end, - + on_rightclick = function(pos, node, clicker) + if liquid.turn_valve_off(pos, Pipe, "techage:ta3_valve_closed", "techage:ta3_valve_open") then + minetest.sound_play("techage_valve", { + pos = pos, + gain = 1, + max_hear_distance = 10}) + end + end, after_dig_node = function(pos, oldnode, oldmetadata, digger) Pipe:after_dig_tube(pos, oldnode, oldmetadata) end, - on_rightclick = on_rightclick, - paramtype2 = "facedir", -- important! drawtype = "nodebox", node_box = { @@ -146,17 +83,19 @@ minetest.register_node("techage:ta3_valve_closed", { "techage_gaspipe_valve_hole.png", }, - tubelib2_on_update2 = function(pos, outdir, tlib2, node) - liquid.update_network(pos, outdir) + on_rightclick = function(pos, node, clicker) + if liquid.turn_valve_on(pos, Pipe, "techage:ta3_valve_closed", "techage:ta3_valve_open") then + minetest.sound_play("techage_valve", { + pos = pos, + gain = 1, + max_hear_distance = 10}) + end end, - after_dig_node = function(pos, oldnode, oldmetadata, digger) Pipe:after_dig_node(pos) techage.remove_node(pos, oldnode, oldmetadata) end, - on_rightclick = on_rightclick, - paramtype2 = "facedir", -- important! drawtype = "nodebox", node_box = { @@ -180,10 +119,10 @@ techage.register_node({"techage:ta3_valve_closed", "techage:ta3_valve_open"}, { on_recv_message = function(pos, src, topic, payload) local node = techage.get_node_lvm(pos) if topic == "on" and node.name == "techage:ta3_valve_closed" then - switch_node(pos, node) + liquid.turn_valve_on(pos, Pipe, "techage:ta3_valve_closed", "techage:ta3_valve_open") return true elseif topic == "off" and node.name == "techage:ta3_valve_open" then - switch_node(pos, node) + liquid.turn_valve_off(pos, Pipe, "techage:ta3_valve_closed", "techage:ta3_valve_open") return true elseif topic == "state" then if node.name == "techage:ta3_valve_open" then @@ -196,6 +135,8 @@ techage.register_node({"techage:ta3_valve_closed", "techage:ta3_valve_open"}, { end, }) +liquid.register_nodes({"techage:ta3_valve_closed"}, Pipe, "special", {}, {}) + minetest.register_craft({ output = "techage:ta3_valve_open", recipe = { diff --git a/techage/liquids/waterinlet.lua b/techage/liquids/waterinlet.lua index dd87391..10f210b 100644 --- a/techage/liquids/waterinlet.lua +++ b/techage/liquids/waterinlet.lua @@ -17,7 +17,7 @@ local M = minetest.get_meta local S = techage.S local Pipe = techage.LiquidPipe -local liquid = techage.liquid +local liquid = networks.liquid local function is_ocean(pos) if pos.y > 1 then @@ -33,37 +33,35 @@ local function is_ocean(pos) M(pos):set_string("infotext", S("Error: No natural water!")) return false end + M(pos):set_string("infotext", S("Operational")) return true end -local function srv_peek(pos) - local nvm = techage.get_nvm(pos) +local function peek_liquid(pos) + local mem = techage.get_mem(pos) if is_ocean(pos) then - nvm.liquid.name = "techage:water" - nvm.liquid.amount = 1 + mem.liquid_name = "techage:water" + mem.liquid_amount = 1 else - nvm.liquid.name = nil - nvm.liquid.amount = 0 + mem.liquid_name = "techage:water" + mem.liquid_amount = 0 end - return nvm.liquid.name + return mem.liquid_name end local function take_liquid(pos, indir, name, amount) - local nvm = techage.get_nvm(pos) - return nvm.liquid.amount, nvm.liquid.name + local mem = techage.get_mem(pos) + if not mem.liquid_name then + peek_liquid(pos) + end + return mem.liquid_amount or 0, mem.liquid_name end + local function untake_liquid(pos, indir, name, amount) return 0 end -local netw_def = { - pipe2 = { - sides = {U = 1}, -- Pipe connection sides - ntype = "tank", - }, -} - minetest.register_node("techage:ta4_waterinlet", { description = S("TA4 Water Inlet"), tiles = { @@ -78,29 +76,13 @@ minetest.register_node("techage:ta4_waterinlet", { after_place_node = function(pos, placer) local meta = M(pos) - local nvm = techage.get_nvm(pos) - nvm.liquid = {} Pipe:after_place_node(pos) - srv_peek(pos) + is_ocean(pos) end, - tubelib2_on_update2 = function(pos, outdir, tlib2, node) - liquid.update_network(pos, outdir) - end, - --on_timer = node_timer, - --on_punch = liquid.on_punch, after_dig_node = function(pos, oldnode, oldmetadata, digger) Pipe:after_dig_node(pos) techage.remove_node(pos, oldnode, oldmetadata) end, - liquid = { - capa = 1, - peek = liquid.srv_peek, - take = take_liquid, - untake = untake_liquid, - }, - networks = netw_def, - --on_rightclick = on_rightclick, - --can_dig = can_dig, paramtype2 = "facedir", on_rotate = screwdriver.disallow, groups = {cracky=2}, @@ -108,7 +90,14 @@ minetest.register_node("techage:ta4_waterinlet", { sounds = default.node_sound_metal_defaults(), }) -Pipe:add_secondary_node_names({"techage:ta4_waterinlet"}) +liquid.register_nodes({"techage:ta4_waterinlet"}, + Pipe, "tank", {"U"}, { + capa = 1, + peek = peek_liquid, + take = take_liquid, + untake = untake_liquid, + } +) minetest.register_craft({ output = "techage:ta4_waterinlet", diff --git a/techage/liquids/waterpump.lua b/techage/liquids/waterpump.lua index 4d69f73..8e8858a 100644 --- a/techage/liquids/waterpump.lua +++ b/techage/liquids/waterpump.lua @@ -17,12 +17,11 @@ local M = minetest.get_meta local S = techage.S local Cable = techage.ElectricCable -local power = techage.power local Pipe = techage.LiquidPipe -local liquid = techage.liquid -local networks = techage.networks +local power = networks.power +local liquid = networks.liquid -local CYCLE_TIME = 4 +local CYCLE_TIME = 2 local STANDBY_TICKS = 3 local COUNTDOWN_TICKS = 3 local PWR_NEEDED = 4 @@ -51,12 +50,11 @@ local function can_start(pos, nvm, state) end local function start_node(pos, nvm, state) - power.consumer_start(pos, Cable, CYCLE_TIME) + nvm.running = true end local function stop_node(pos, nvm, state) nvm.running = false - power.consumer_stop(pos, Cable) end local State = techage.NodeStates:new({ @@ -70,30 +68,31 @@ local State = techage.NodeStates:new({ stop_node = stop_node, }) -local function on_power(pos) - local nvm = techage.get_nvm(pos) - State:start(pos, nvm) - nvm.running = true -end - -local function on_nopower(pos) - local nvm = techage.get_nvm(pos) - State:nopower(pos, nvm) - nvm.running = false +local function has_power(pos, nvm) + local outdir = networks.Flip[M(pos):get_int("waterdir")] + local taken = power.consume_power(pos, Cable, outdir, PWR_NEEDED) + if techage.is_running(nvm) then + if taken < PWR_NEEDED then + State:nopower(pos, nvm) + else + return true -- keep running + end + elseif taken == PWR_NEEDED then + State:start(pos, nvm) + end end local function pumping(pos, nvm) - if techage.needs_power(nvm) then - power.consumer_alive(pos, Cable, CYCLE_TIME) - end - if nvm.running then - local leftover = liquid.put(pos, 6, "techage:water", 1) - if leftover and leftover > 0 then - State:blocked(pos, nvm) - return + if has_power(pos, nvm) then + nvm.ticks = (nvm.ticks or 0) + 1 + if nvm.ticks % 4 == 0 then + local leftover = liquid.put(pos, Pipe, 6, "techage:water", 1) + if leftover and leftover > 0 then + State:blocked(pos, nvm) + return + end end - State:keep_running(pos, nvm, COUNTDOWN_TICKS) - return + State:keep_running(pos, nvm, 1) end end @@ -126,32 +125,9 @@ end local function after_dig_node(pos, oldnode, oldmetadata, digger) Pipe:after_dig_node(pos) Cable:after_dig_node(pos) - liquid.after_dig_pump(pos) techage.del_mem(pos) end -local function tubelib2_on_update2(pos, outdir, tlib2, node) - if tlib2.tube_type == "pipe2" then - liquid.update_network(pos, outdir, tlib2) - else - power.update_network(pos, outdir, tlib2) - end -end - -local netw_def = { - pipe2 = { - sides = {U = 1}, -- Pipe connection sides - ntype = "pump", - }, - ele1 = { - sides = {L = 1}, -- Cable connection sides - ntype = "con1", - on_power = on_power, - on_nopower = on_nopower, - nominal = PWR_NEEDED, - }, -} - minetest.register_node("techage:t4_waterpump", { description = S("TA4 Water Pump"), tiles = { @@ -166,8 +142,6 @@ minetest.register_node("techage:t4_waterpump", { after_place_node = after_place_node, after_dig_node = after_dig_node, - tubelib2_on_update2 = tubelib2_on_update2, - networks = netw_def, on_receive_fields = on_receive_fields, on_timer = node_timer, @@ -177,21 +151,11 @@ minetest.register_node("techage:t4_waterpump", { is_ground_content = false, }) -Cable:add_secondary_node_names({"techage:t4_waterpump"}) -Pipe:add_secondary_node_names({"techage:t4_waterpump"}) +power.register_nodes({"techage:t4_waterpump"}, Cable, "con", {"L"}) +liquid.register_nodes({"techage:t4_waterpump"}, Pipe, "pump", {"U"}, {}) techage.register_node({"techage:t4_waterpump"}, { on_recv_message = function(pos, src, topic, payload) return State:on_receive_message(pos, topic, payload) end, }) - ---minetest.register_craft({ --- output = "techage:t4_waterpump", --- recipe = { --- {"", "default:mese_crystal", ""}, --- {"", "techage:ta3_liquidsampler_pas", ""}, --- {"", "techage:ta4_wlanchip", ""}, --- }, ---}) - diff --git a/techage/locale/techage.de.tr b/techage/locale/techage.de.tr index 212d9db..16a92b5 100644 --- a/techage/locale/techage.de.tr +++ b/techage/locale/techage.de.tr @@ -7,20 +7,6 @@ TA3 Accu Box=Akkublock TA3 Akku Box=TA3 Akku Block -### akkubox.lua ### -### battery.lua ### - -Load=Ladung - -### akkubox.lua ### -### electrolyzer.lua ### -### fuelcell.lua ### -### generator.lua ### -### heatexchanger2.lua ### -### tiny_generator.lua ### - -Electricity=Strom - ### aluminium.lua ### Aluminum=Aluminium @@ -42,7 +28,6 @@ Autocrafter=Autocrafter ### axle2power.lua ### TA2 Power Generator=TA2 Stromgenerator -TA2 Power Generator: Overload fault?@n(restart with right-click)=TA2 Stromgenerator: Überlastfehler?@n(Neustart mit Rechtsklick) ### baborium.lua ### @@ -82,6 +67,11 @@ Battery=Batterie Coal Equivalents=Kohleeinheiten Digtron Battery=Digtron Akku +### battery.lua ### +### storage.lua ### + +Load=Ladung + ### bauxit.lua ### Bauxite Cobblestone=Bauxit Kopfsteinpflaster @@ -139,6 +129,7 @@ Insert destination node number(s)=Gebe Zielnummer(n) ein ### doorcontroller.lua ### ### mesecons_converter.lua ### ### repeater.lua ### +### submenu.lua ### Save=Speichern @@ -286,15 +277,35 @@ TA2 Drive Axle=TA2 Antriebsachse TA Electric Cable=TA Stromkabel -### electrolyzer.lua ### +### electricmeter.lua ### -TA4 Electrolyzer=TA4 Elektrolyseur -full=voll +Consumption=Verbrauch +TA4 Electric Meter=TA4 Stromzähler + +### electricmeter.lua ### +### formspecs.lua ### +### transformer.lua ### + +Power=Strom ### electrolyzer.lua ### -### power_terminal2.lua ### +Configurable value@nfor the current limit=Konfigurierbarer Wert@nfür die Strombegrenzung +Current limitation=Strombegrenzung Electrolyzer=Eletrolyseur +If the charge of the storage@nsystem exceeds the configured value,@nthe block switches off=Überschreitet die Ladung des@nSpeichersystems den konfigurierten@nWert, schaltet sich der Block ab +Maximum possible@ncurrent consumption=Maximal mögliche Stromaufnahme +Maximum power consumption [ku]=maximale Stromaufnahme +Storage full=Speicher voll +TA4 Electrolyzer=TA4 Elektrolyseur +Turnoff point=Abschaltpunkt +Turnoff point reached=Abschaltpunkt erreicht + +### electrolyzer.lua ### +### fuelcell.lua ### +### tiny_generator.lua ### + +Electricity=Strom ### electronic.lua ### @@ -345,13 +356,6 @@ Firebox=Feuerkasten Flywheel=Schwungrad TA2 Flywheel=TA2 Schwungrad -### flywheel.lua ### -### generator.lua ### -### solarcell.lua ### -### source.lua ### - -power=Energie - ### forceload.lua ### Area already loaded or max. number of Forceload Blocks reached!=Bereich bereits geladen oder maximale Anzahl von Forceload Blöcken erreicht! @@ -363,6 +367,27 @@ Techage Forceload Block=Techage Forceload Block Techage Forceload Tile=Techage Forceload Kachel loaded=geladen +### formspecs.lua ### + +Charge termination=Ladebegrenzung +Current output [ku]=Aktueller Ausgabewert +Maximum output [ku]=Maximaler Ausgabewert +Range in which the generator reduces its power=Bereich in dem der Generator die Leistung reduziert +The current power the generator provides=Die aktuelle Leistung die der Generator liefert +The maximum power the generator can provide=Die maximale Leistung die der Generator liefern kann + +### formspecs.lua ### +### power_terminal2.lua ### + +Charging=Laden + +### formspecs.lua ### +### power_terminal2.lua ### +### storage.lua ### +### transformer.lua ### + +Storage=Speicher + ### fuel_lib.lua ### Fuel Menu=Brennstoff Menü @@ -370,13 +395,9 @@ To add fuel punch@nthis block@nwith a fuel container=Um Brennstoff nachzufüllen ### fuelcell.lua ### -Cat. 1 generator=Kat. 1 Generator -Cat. 2 generator=Kat. 2 Generator Fuel Cell=Brennstoffzelle -If set, fuelcell will work@nas cat. 1 generator=Wenn gesetzt, Brennstoffzelle@narbeitet als Kat. 1 Generator TA4 Fuel Cell=TA4 Brennstoffzelle -TA4 Fuel Cell Gen1=TA4 Brennstoffzelle Gen1 -TA4 Fuel Cell Gen2=TA4 Brennstoffzelle Gen2 +no hydrogen=kein Wasserstoff ### fuelcellstack.lua ### @@ -398,10 +419,13 @@ TA2 Gearbox=TA2 Getriebeblock ### generator.lua ### -Generator=Generator TA3 Generator=TA3 Generator TA4 Generator=TA4 Generator -storage empty?=Speicher leer? + +### generator.lua ### +### power_terminal2.lua ### + +Generator=Generator ### gravelrinser.lua ### @@ -450,20 +474,15 @@ TA4 Furnace Heater=TA4 Ofenheizung ### heatexchanger1.lua ### TA4 Heat Exchanger 1=TA4 Wärmetauscher 1 -inlet/pipe error=Einlass/Röhrenfehler -wrong storage diameter=Falscher Wärmespeicher-Durchmesser - -### heatexchanger1.lua ### -### heatexchanger2.lua ### - -did you check the plan?=hast du den Plan geprüft? ### heatexchanger2.lua ### -Heat Exchanger=Wärmetauscher +Power network connection error=Stromnetz Verbindungsfehler TA4 Heat Exchanger=TA4 Wärmetauscher TA4 Heat Exchanger 2=TA4 Wärmetauscher 2 -Thermal=Wärme +did you check the plan?=hast du den Plan geprüft? +inlet/pipe error=Einlass/Röhrenfehler +wrong storage diameter=Falscher Wärmespeicher-Durchmesser ### heatexchanger3.lua ### @@ -494,6 +513,10 @@ TA4 LED Industrial Lamp=TA4 LED Industrielampe ### inlet.lua ### TA4 Pipe Inlet=TA4 Rohrzulauf +one window maximum=maximal ein Fenster +wrong diameter (should be 5, 7, or 9)=falscher Durchmesser (sollte 5, 7, oder 9 sein) +wrong number of gravel nodes=falsche Anzahl von Kiesblöcken +wrong number of shell nodes=falsche Anzahl von Blöcken bei der Hülle ### inverter.lua ### @@ -501,6 +524,8 @@ Inverter=Wechselrichter Power AC=Wechselstrom Power DC=Gleichstrom TA4 Solar Inverter=TA4 Solar Wechselrichter +no solar power=keine Solarleistung +solar network error=Solar-Netzwerk Fehler ### junctionbox.lua ### @@ -523,6 +548,10 @@ TA4 Laser Beam Receiver=TA4 Laserstrahl Empfänger Valid destination positions:=Gültige Zielpositionen to=bis +### lib.lua ### + +Block has an@nadditional wrench menu=Block besitzt ein@nzusätzliches@nSchraubenschlüssel-Menü + ### lib.lua ### ### sensorchest.lua ### @@ -574,15 +603,10 @@ Syntax=Syntax ### logic_block.lua ### ### lua_logic.lua ### +Store=Speichern TA3 Logic Block=TA3 Logikblock Update=Update -### logic_block.lua ### -### lua_logic.lua ### -### power_terminal2.lua ### - -Store=Speichern - ### lye.lua ### Lye=Lauge @@ -695,7 +719,6 @@ Silver Sandstone Powder=Silbersandstein Pulver ### power2axle.lua ### TA3 Electric Motor=TA3 Elektromotor -TA3 Electric Motor: Overload fault?@n(restart with right-click)=TA3 Elektromotor: Überlastfehler?@n(Neustart mit Rechtsklick) ### power_line.lua ### @@ -704,57 +727,16 @@ TA Power Pole=TA Strommast TA Power Pole Top (for up to 6 connections)=TA Strommastkopf (für bis zu 6 Verbindungen) TA Power Pole Top 2 (for landlines)=TA Strommastkopf 2 (für Überlandleitungen) -### power_terminal.lua ### - -Active:=Aktiv: -All nodes:=Alle Blöcke: -Consum. 1=Konsum. 1 -Consum. 2=Konsum. 2 -Genera. 1=Genera. 1 -Genera. 2=Genera. 2 -In use:=In Benutzung: -No network or active generator available!=Kein Stromnetz oder aktiver Generator verfügbar -Number of all nodes=Anzahl aller Blöcke -TA3 Power Terminal Old=TA3 Strom Terminal Alt -The network is overloaded!=Das Stromnetz ist überlastet! -The network load is almost at the limit!=Das Stromnetz ist ziemlich am Limit! -Turned on:=Eingeschaltet: -With %u of a maximum of %u blocks you are almost at the limit!=Mit %u von maximal %u Blöcken bist du fast am Limit! - -### power_terminal.lua ### ### power_terminal2.lua ### +Commands@nhelp . . . print this text@ncls . . . . . clear screen@ngen . . . . print all generators@nsto . . . . . print all storage systems@n=Kommandos@nhelp . . . diesen Text ausgeben@ncls . . . . . Bildschirm löschen@ngen . . . . Alle Generatoren ausgeben@nsto . . . . . Alle Speichersysteme ausgeben@n +Consumer=Verbraucher Network Data=Netzwerkdaten - -### power_terminal2.lua ### - -Accu Box=Akkublock -Current power:=Strom aktuell: -Energy storage=Engergiespeicher -Energy stored:=Energie gespeichert -Fuel cell cat. 1=Brennstoffzelle Kat. 1 -Fuel cell cat. 2=Brennstoffzelle Kat. 2 -Generators=Generatoren -Intake=Stromaufnahme -Max. needed power=Max. benötigter Strom -Maximum power:=Maximalstrom: -No power grid or running generator!=Kein Stromnetz oder Generator verfügbar! -Number blocks:=Anzahl Blöcke: -Number of power grid blocks=Anzahl der Stromnetz Blöcke -Output=Stromabgabe -Power grid total=Stromnetz gesammt -Power station=Kraftwerk -Probably too many consumers (=Vermutlich zu viele Verbraucher ( -Select type=Wähle Typ -Solar system=Solaranlage -Storage systems=Speichersysteme -TA2 Generator=TA2 Generator +Number of consumers:=Anzahl der Verbraucher +Number of generators:=Anzahl der Generatoren +Number of network nodes:=Anzahl von Netzwerkblöcken +Number of storage systems:=Anzahl der Speichersysteme TA3 Power Terminal=TA3 Strom Terminal -Tiny generator=Kleingenerator -To many blocks in the power grid!=Zu viele Blöcke im Stromnetz! -Type=Typ -Wind turbine=Windkraftanlage -ku is needed=ku wird benötigt ### power_terminal2.lua ### ### terminal.lua ### @@ -767,6 +749,7 @@ TA Power Switch=TA Stromschalter TA Power Switch Small=TA Stromschalter klein ### powerswitchbox.lua ### +### powerswitchbox_legacy.lua ### TA Power Switch Box=TA Stromschalterbox @@ -817,7 +800,6 @@ inventory full=Inventar ist voll ### reboiler.lua ### TA3 Oil Reboiler=TA3 Aufkocher -TA3 Oil Reboiler: blocked=TA3 Aufkocher: blockiert ### recipe_lib.lua ### @@ -852,7 +834,6 @@ Position=Position Position temperature=Positionstemperatur TechAge Info Tool (use @= read status info)=TechAge Info Werkzeug TechAge Repair Kit=TechAge Reparaturset -repaired=repariert ### repeater.lua ### @@ -904,12 +885,17 @@ TA4 Solar Carrier Module T=TA4 Solar Trägermodul O TA4 Solar Module=TA4 Solarmodul light=Licht +### solarcell.lua ### +### source.lua ### + +power=Strom + ### source.lua ### Axle Power Source=Achsenkraftquelle Ele Power Source=Ele Kraftquelle Power Source=Stromquelle -Steam Power Source=Dampfenergiequelle +Test Generator=Test Generator ### steam_pipe.lua ### @@ -919,6 +905,10 @@ TA2 Steam Pipe=TA2 Dampfleitung TechAge Steel Mat=TechAge Stahlmatte +### storage.lua ### + +Test Storage=Test Speicher + ### streetlamp.lua ### TA Street Lamp=TA Straßenlampe @@ -929,6 +919,20 @@ TA4 LED Street Lamp=TA4 LED Straßenlampe TA4 LED Street Lamp Arm=TA4 LED Lampenarm TA4 LED Street Lamp Pole=TA4 LED Lampenmast +### submenu.lua ### + +Cancel=Abbruch +Note: You can't change any values while the block is running!=Hinweis: Während der Block läuft, kann kein Wert geändert werden! +Refresh=Aktualisieren + +### ta2_weight_chest.lua ### + +TA2 Weight Chest=TA2 Gewichtekiste + +### ta2_winch.lua ### + +TA2 Winch=TA2 Seilwinde + ### ta4_cable.lua ### TA4 Low Power Box=TA4 Niederspannungsverteilerbox @@ -1028,10 +1032,13 @@ TA4 Derrick=TA4 Bohrturm [TA] Derrick is being built!=[TA] Bohrturm wird errichtet [TA] Derrick is being removed!=[TA] Bohrturm wird abgebaut +### transformer.lua ### + +TA4 Isolation Transformer=TA4 Trenntransformator + ### trowel.lua ### TechAge Trowel=TechAge Kelle -Use a trowel to remove the node.=Verwende eine Kelle, um den Block zu entfernen. ### tube_wall_entry.lua ### @@ -1058,8 +1065,7 @@ Usmium Powder=Usmium Pulver ### valve.lua ### TA Valve=TA Ventil -TA3 Valve closed=TA3 Ventil zu -TA3 Valve open=TA3 Ventil offen +TA3 Valve=TA3 Ventil ### waterinlet.lua ### @@ -1085,8 +1091,3 @@ This is not the surface of the ocean!=Das ist nicht die Meeresoberfläche! biome and no ocean!=Biom und keine Meer (ocean)! is a suitable place for a wind turbine!=ist ein geeigneter Ort für eine Windkraftanlage! - -##### not used anymore ##### - -Fuel cell=Brennstoffzelle -Not suitable position!=Ungeeignete Position! diff --git a/techage/locale/template.txt b/techage/locale/template.txt index 888e603..ac33dce 100644 --- a/techage/locale/template.txt +++ b/techage/locale/template.txt @@ -7,20 +7,6 @@ TA3 Accu Box= TA3 Akku Box= -### akkubox.lua ### -### battery.lua ### - -Load= - -### akkubox.lua ### -### electrolyzer.lua ### -### fuelcell.lua ### -### generator.lua ### -### heatexchanger2.lua ### -### tiny_generator.lua ### - -Electricity= - ### aluminium.lua ### Aluminum= @@ -42,7 +28,6 @@ Autocrafter= ### axle2power.lua ### TA2 Power Generator= -TA2 Power Generator: Overload fault?@n(restart with right-click)= ### baborium.lua ### @@ -82,6 +67,11 @@ Battery= Coal Equivalents= Digtron Battery= +### battery.lua ### +### storage.lua ### + +Load= + ### bauxit.lua ### Bauxite Cobblestone= @@ -139,6 +129,7 @@ Insert destination node number(s)= ### doorcontroller.lua ### ### mesecons_converter.lua ### ### repeater.lua ### +### submenu.lua ### Save= @@ -286,15 +277,35 @@ TA2 Drive Axle= TA Electric Cable= -### electrolyzer.lua ### +### electricmeter.lua ### -TA4 Electrolyzer= -full= +Consumption= +TA4 Electric Meter= + +### electricmeter.lua ### +### formspecs.lua ### +### transformer.lua ### + +Power= ### electrolyzer.lua ### -### power_terminal2.lua ### +Configurable value@nfor the current limit= +Current limitation= Electrolyzer= +If the charge of the storage@nsystem exceeds the configured value,@nthe block switches off= +Maximum possible@ncurrent consumption= +Maximum power consumption [ku]= +Storage full= +TA4 Electrolyzer= +Turnoff point= +Turnoff point reached= + +### electrolyzer.lua ### +### fuelcell.lua ### +### tiny_generator.lua ### + +Electricity= ### electronic.lua ### @@ -345,13 +356,6 @@ Firebox= Flywheel= TA2 Flywheel= -### flywheel.lua ### -### generator.lua ### -### solarcell.lua ### -### source.lua ### - -power= - ### forceload.lua ### Area already loaded or max. number of Forceload Blocks reached!= @@ -363,6 +367,27 @@ Techage Forceload Block= Techage Forceload Tile= loaded= +### formspecs.lua ### + +Charge termination= +Current output [ku]= +Maximum output [ku]= +Range in which the generator reduces its power= +The current power the generator provides= +The maximum power the generator can provide= + +### formspecs.lua ### +### power_terminal2.lua ### + +Charging= + +### formspecs.lua ### +### power_terminal2.lua ### +### storage.lua ### +### transformer.lua ### + +Storage= + ### fuel_lib.lua ### Fuel Menu= @@ -370,13 +395,9 @@ To add fuel punch@nthis block@nwith a fuel container= ### fuelcell.lua ### -Cat. 1 generator= -Cat. 2 generator= Fuel Cell= -If set, fuelcell will work@nas cat. 1 generator= TA4 Fuel Cell= -TA4 Fuel Cell Gen1= -TA4 Fuel Cell Gen2= +no hydrogen= ### fuelcellstack.lua ### @@ -398,10 +419,13 @@ TA2 Gearbox= ### generator.lua ### -Generator= TA3 Generator= TA4 Generator= -storage empty?= + +### generator.lua ### +### power_terminal2.lua ### + +Generator= ### gravelrinser.lua ### @@ -450,20 +474,15 @@ TA4 Furnace Heater= ### heatexchanger1.lua ### TA4 Heat Exchanger 1= -inlet/pipe error= -wrong storage diameter= - -### heatexchanger1.lua ### -### heatexchanger2.lua ### - -did you check the plan?= ### heatexchanger2.lua ### -Heat Exchanger= +Power network connection error= TA4 Heat Exchanger= TA4 Heat Exchanger 2= -Thermal= +did you check the plan?= +inlet/pipe error= +wrong storage diameter= ### heatexchanger3.lua ### @@ -494,6 +513,10 @@ TA4 LED Industrial Lamp= ### inlet.lua ### TA4 Pipe Inlet= +one window maximum= +wrong diameter (should be 5, 7, or 9)= +wrong number of gravel nodes= +wrong number of shell nodes= ### inverter.lua ### @@ -501,6 +524,8 @@ Inverter= Power AC= Power DC= TA4 Solar Inverter= +no solar power= +solar network error= ### junctionbox.lua ### @@ -523,6 +548,10 @@ TA4 Laser Beam Receiver= Valid destination positions:= to= +### lib.lua ### + +Block has an@nadditional wrench menu= + ### lib.lua ### ### sensorchest.lua ### @@ -574,15 +603,10 @@ Syntax= ### logic_block.lua ### ### lua_logic.lua ### +Store= TA3 Logic Block= Update= -### logic_block.lua ### -### lua_logic.lua ### -### power_terminal2.lua ### - -Store= - ### lye.lua ### Lye= @@ -695,7 +719,6 @@ Silver Sandstone Powder= ### power2axle.lua ### TA3 Electric Motor= -TA3 Electric Motor: Overload fault?@n(restart with right-click)= ### power_line.lua ### @@ -704,57 +727,16 @@ TA Power Pole= TA Power Pole Top (for up to 6 connections)= TA Power Pole Top 2 (for landlines)= -### power_terminal.lua ### - -Active:= -All nodes:= -Consum. 1= -Consum. 2= -Genera. 1= -Genera. 2= -In use:= -No network or active generator available!= -Number of all nodes= -TA3 Power Terminal Old= -The network is overloaded!= -The network load is almost at the limit!= -Turned on:= -With %u of a maximum of %u blocks you are almost at the limit!= - -### power_terminal.lua ### ### power_terminal2.lua ### +Commands@nhelp . . . print this text@ncls . . . . . clear screen@ngen . . . . print all generators@nsto . . . . . print all storage systems@n= +Consumer= Network Data= - -### power_terminal2.lua ### - -Accu Box= -Current power:= -Energy storage= -Energy stored:= -Fuel cell cat. 1= -Fuel cell cat. 2= -Generators= -Intake= -Max. needed power= -Maximum power:= -No power grid or running generator!= -Number blocks:= -Number of power grid blocks= -Output= -Power grid total= -Power station= -Probably too many consumers (= -Select type= -Solar system= -Storage systems= -TA2 Generator= +Number of consumers:= +Number of generators:= +Number of network nodes:= +Number of storage systems:= TA3 Power Terminal= -Tiny generator= -To many blocks in the power grid!= -Type= -Wind turbine= -ku is needed= ### power_terminal2.lua ### ### terminal.lua ### @@ -767,6 +749,7 @@ TA Power Switch= TA Power Switch Small= ### powerswitchbox.lua ### +### powerswitchbox_legacy.lua ### TA Power Switch Box= @@ -817,7 +800,6 @@ inventory full= ### reboiler.lua ### TA3 Oil Reboiler= -TA3 Oil Reboiler: blocked= ### recipe_lib.lua ### @@ -852,7 +834,6 @@ Position= Position temperature= TechAge Info Tool (use @= read status info)= TechAge Repair Kit= -repaired= ### repeater.lua ### @@ -904,12 +885,17 @@ TA4 Solar Carrier Module T= TA4 Solar Module= light= +### solarcell.lua ### +### source.lua ### + +power= + ### source.lua ### Axle Power Source= Ele Power Source= Power Source= -Steam Power Source= +Test Generator= ### steam_pipe.lua ### @@ -919,6 +905,10 @@ TA2 Steam Pipe= TechAge Steel Mat= +### storage.lua ### + +Test Storage= + ### streetlamp.lua ### TA Street Lamp= @@ -929,6 +919,20 @@ TA4 LED Street Lamp= TA4 LED Street Lamp Arm= TA4 LED Street Lamp Pole= +### submenu.lua ### + +Cancel= +Note: You can't change any values while the block is running!= +Refresh= + +### ta2_weight_chest.lua ### + +TA2 Weight Chest= + +### ta2_winch.lua ### + +TA2 Winch= + ### ta4_cable.lua ### TA4 Low Power Box= @@ -1028,10 +1032,13 @@ TA4 Derrick= [TA] Derrick is being built!= [TA] Derrick is being removed!= +### transformer.lua ### + +TA4 Isolation Transformer= + ### trowel.lua ### TechAge Trowel= -Use a trowel to remove the node.= ### tube_wall_entry.lua ### @@ -1058,8 +1065,7 @@ Usmium Powder= ### valve.lua ### TA Valve= -TA3 Valve closed= -TA3 Valve open= +TA3 Valve= ### waterinlet.lua ### diff --git a/techage/logic/doorblock.lua b/techage/logic/doorblock.lua index b231a1b..5dcee0b 100644 --- a/techage/logic/doorblock.lua +++ b/techage/logic/doorblock.lua @@ -106,33 +106,3 @@ minetest.register_craft({ {"group:wood", "", ""}, }, }) - - - -minetest.register_lbm({ - label = "Upgrade doors and gates", - name = "techage:replace_legacy_doors_and_gates", - - nodenames = { - "techage:doorblock19", - "techage:doorblock20", - "techage:gateblock19", - "techage:gateblock20", - }, - - run_at_every_load = false, - - action = function(pos, node) - if node.name == "techage:doorblock19" then - node.name = "techage:doorblock21" - elseif node.name == "techage:doorblock20" then - node.name = "techage:doorblock22" - elseif node.name == "techage:gateblock19" then - node.name = "techage:gateblock21" - elseif node.name == "techage:gateblock20" then - node.name = "techage:gateblock22" - end - minetest.swap_node(pos, node) - end, -}) - diff --git a/techage/logic/doorcontroller2.lua b/techage/logic/doorcontroller2.lua index d8409a7..d8c2f76 100644 --- a/techage/logic/doorcontroller2.lua +++ b/techage/logic/doorcontroller2.lua @@ -153,7 +153,7 @@ end local function exchange_node(pos, item, param2) local node = minetest.get_node_or_nil(pos) if node and is_simple_node(node.name) then - if item and item:get_name() ~= "" then + if item and item:get_name() ~= "" and minetest.registered_nodes[item:get_name()] then minetest.swap_node(pos, {name = item:get_name(), param2 = param2}) else minetest.remove_node(pos) diff --git a/techage/manuals/QSG.md b/techage/manuals/QSG.md index 4c28014..445ae89 100644 --- a/techage/manuals/QSG.md +++ b/techage/manuals/QSG.md @@ -74,7 +74,7 @@ Since the levels build on each other, all ages have to be run through one after ## Power Consumption -| TechAge Machine | TA2 [ku] | TA3 [ku] | TA4 [ku] | +t| TechAge Machine | TA2 [ku] | TA3 [ku] | TA4 [ku] | | ------------------------------ | -------- | -------- | --------- | | Autocrafter | 4 | 6 | (9) | | Electronic Fab | 8 | 12 | 12 | @@ -93,9 +93,7 @@ Since the levels build on each other, all ages have to be run through one after | TA4 Reactor | - | - | 8 | | Steam Engine | 25 | | | | Coal Power Station | | 80 | | -| TA3 Accu Box | | 10 | | | TA3 Tiny Power Generator | | 12 | | -| TA4 Energy Storage Generator | | | 60 | | TA4 Solar Inverter | | | up to 100 | | TA4 Wind Turbine | | | 70 | diff --git a/techage/manuals/manual_DE.md b/techage/manuals/manual_DE.md index 20ca8dd..6a4995a 100644 --- a/techage/manuals/manual_DE.md +++ b/techage/manuals/manual_DE.md @@ -37,6 +37,29 @@ Ab TA3 laufen die Maschinen mit Strom und besitzen eine Kommunikationsschnittste Mit TA4 kommen weitere Stromquellen dazu, aber auch höhere logistische Herausforderungen (Stromtrassen, Item Transport). + +## Änderungen ab Version 1.0 + +Ab V1.0 (17.07.2021) hat sich folgendes geändert: + +- Der Algorithmus zur Berechnung der Stromverteilung hat sich geändert. Energiespeichersystem werden dadurch wichtiger. Diese gleichen Schankungen aus, was bei größeren Netzen mit mehreren Generatoren wichtig wird. +- Aus diesem Grund hat TA2 seinen eigenen Energiespeicher erhalten. +- Die Akkublöcke aus TA3 dienen auch als Energiespeicher. Ihre Funktionsweise wurde entsprechend angepasst. +- Das TA4 Speichersystem wurde überarbeitet. Die Wärmetauscher (heatexchanger) haben eine neue Nummer bekommen, da die Funktionalität vom unteren in den mittleren Block verschoben wurde. Sofern diese ferngesteuert wurden, muss die Knotennummer angepasst werden. Die Generatoren haben kein eigenes Menü mehr, sondern werden nur noch über den Wärmetauscher ein-/ausgeschaltet. Wärmetauscher und Generator müssen jetzt am gleichen Netz hängen! +- Mehrere Stromnetze können jetzt über einen TA4 Transformator Blöcke gekoppelt werden. +- Neu ist auch ein TA4 Stromzähler Block für Unternetze. + +### Tipps zur Umstellung + +Viele weitere Blöcke haben kleinere Änderungen bekommen. Daher kann es sein, dass Maschinen oder Anlagen nach der Umstellung nicht gleich wieder anlaufen. Sollte es zu Störungen kommen, helfen folgende Tipps: + +- Maschinen aus- und wieder eingeschalten +- ein Stromkabel-Block entfernen und wieder setzen +- den Block ganz entfernen und wieder setzen +- mindestens ein Akkublock oder Speichersystem in jedes Netzwerk + + + ## Erze und Mineralien Techage fügt dem Spiel einige neue Items hinzu: @@ -48,6 +71,7 @@ Techage fügt dem Spiel einige neue Items hinzu: - Bauxit - ein Aluminiumerz, was in TA4 zur Herstellung von Aluminium benötigt wird - Basalt - entsteht, wenn sich Wasser und Lave berühren + ### Meridium Meridium ist eine Legierung aus Stahl und Mesekristallen. Meridium Ingots können mit dem Kohlebrenner aus Stahl und Mesesplitter hergestellt werden. Meridium leuchtet im Dunkeln. Auch Werkzeuge aus Meridium leuchten und sind daher im Untertagebau sehr hilfreich. @@ -87,22 +111,10 @@ Es wird zur Herstellung von Aluminium benötigt, was vor allem in TA4 Verwendung ### Basalt -Basalt entsteht nur, wenn Lava und Wasser zusammenkommen. +Basalt entsteht nur, wenn Lava und Wasser zusammen kommen. Dazu sollte man am besten eine Anlage aufbauen, bei der eine Lava- und eine Wasserquelle zusammenfließen. Dort wo sich beide Flüssigkeiten treffen, entsteht Basalt. Einen automatisierten Basalt Generator kann man mit dem Sign Bot aufbauen. [basalt|image] - - -## History - -- 28.09.2019: Um Solaranlage erweitert -- 05.10.2019: Daten zur Solaranlage und Beschreibung zum Wechselrichter und zum Power-Terminal geändert -- 18.11.2019: Kapitel für Erze, Reaktor, Aluminium, Silo, Bauxit, Ofenheizung, Kieswaschanlage hinzugefügt -- 22.02.2020: Korrekturen und Kapitel zum Update -- 29.02.2020: ICTA Controller hinzugefügt und weitere Korrekturen -- 14.03.2020 Lua Controller hinzugefügt und weitere Korrekturen -- 22.03.2020 Weitere TA4 Blöcke hinzugefügt - diff --git a/techage/manuals/manual_EN.md b/techage/manuals/manual_EN.md index e369794..e346d95 100644 --- a/techage/manuals/manual_EN.md +++ b/techage/manuals/manual_EN.md @@ -37,6 +37,30 @@ From TA3, the machines run on electricity and have a communication interface for TA4 adds more power sources, but also higher logistical challenges (power lines, item transport). + +## Changes from version 1.0 + +From V1.0 (07/17/2021) the following has changed: + +- The algorithm for calculating the power distribution has changed. This makes energy storage systems more important. These compensate for fluctuations, which is important in larger networks with several generators. +- For this reason TA2 got its own energy storage. +- The battery blocks from TA3 also serve as energy storage. Their functionality has been adapted accordingly. +- The TA4 storage system has been revised. The heat heat exchanger have been given a new number because the functionality has been moved from the lower to the middle block. If these were remotely controlled, the node number must be adapted. The generators no longer have their own menu, but are only switched on / off via the heat exchanger. The heat exchanger and generator must now be connected to the same network! +- Several power grids can now be coupled via a TA4 transformer blocks. +- A TA4 electricity meter block for sub-networks is also new. +- At least one battery block or a storage system in each network + + +### Tips on switching + +Many more blocks have received minor changes. It is therefore possible that machines or systems do not start up again immediately after the changeover. In the event of malfunctions, the following tips will help: + +- Switch machines off and on again +- remove a power cable block and put it back in place +- remove the block completely and put it back in place + + + ## Ores and Minerals Techage adds some new items to the game: diff --git a/techage/manuals/manual_ta2_DE.md b/techage/manuals/manual_ta2_DE.md index d6dc310..c996d1b 100644 --- a/techage/manuals/manual_ta2_DE.md +++ b/techage/manuals/manual_ta2_DE.md @@ -23,7 +23,7 @@ Der Boiler muss mit Wasser gefüllt werden. Dazu bis zu 10 Eimer Wasser in den B Die Feuerbox muss mit Kohle oder Holzkohle gefüllt werden. Wenn das Wasser heiß ist (Temperaturanzeige ganz oben), kann die Dampfmaschine am Schwungrad gestartet werden. -Die Dampfmaschine leistet 25 ku, kann damit mehrere Maschinen gleichzeitig antreiben. +Die Dampfmaschine leistet 25 ku und kann damit mehrere Maschinen gleichzeitig antreiben. [steamengine|plan] @@ -66,7 +66,7 @@ Teil der Dampfmaschine. Der Boiler muss mit dem Zylinder über die Dampfleitunge ### TA2 Antriebsachsen / TA2 Drive Axle -Die Antriebsachsen dienen zur Kraftübertragung von der Dampfmaschine zu anderen Maschinen. Die maximale Länge einer Antriebsachse beträgt 8 Blöcke. Über Getriebeboxen können auch größere Strecken überbrückt, sowie Abzweigungen und Richtungswechsel realisiert werden. +Die Antriebsachsen dienen zur Kraftübertragung von der Dampfmaschine zu anderen Maschinen. Die maximale Länge einer Antriebsachse beträgt 10 Blöcke. Über Getriebeboxen können auch größere Strecken überbrückt, sowie Abzweigungen und Richtungswechsel realisiert werden. [ta2_driveaxle|image] @@ -81,6 +81,33 @@ Das Stromgenerator nimmt primär max. 25 ku an Achsenkraft auf und gibt sekundä [ta2_generator|image] +## TA2 Energiespeicher + +Bei größeren Anlagen mit mehreren Dampfmaschinen oder vielen angetriebenen Maschinen empfiehlt sich ein Energiespeicher. Der Energiespeicher bei TA2 arbeitet mit Lageenergie. Dazu wird Balast (Steine, Kies) in einer Kiste mit Hilfe einer Seilwinde in die Höhe gezogen. Ist überschüssige Energie im Achsen-Netzwerk vorhanden, so wird die Kiste nach oben gezogen. Wird kurzfristig mehr Energie benötigt, als die Dampfmaschine liefern kann, so gibt der Energiespeicher die gespeicherte Energie wieder ab, und die Balast-Kiste bewegt sich wieder nach unten. + +Der Energiespeicher besteht aus mehreren Blöcken und muss wie im Plan rechts abgebildet, zusammen gebaut werden. + +Um die maximale Speicherkapazität zu erreichen, muss die Kiste mit Gewichten komplett gefüllt, und der Mast inklusive der zwei Getriebeboxen 12 Blöcke hoch sein. Kleinere Aufbauten sind aber auch möglich. + +[ta2_storage|plan] + + + +### TA2 Seilwinde / TA2 Winch + +Die Seilwinde muss mit einer Getriebebox verbunden werden und kann so überschüssige Energie aufnehmen und damit eine Gewichtekiste nach oben ziehen. Die maximale Seillänge beträgt 10 Blöcke. + +[ta2_winch|image] + + + +### TA2 Gewichtekiste / TA2 Weight Chest + +Diese Kiste muss mit bis zu 10 Blöcken Abstand unter die Seilwinde gesetzt und mit Pflastersteinen Kies oder Sand gefüllt werden. Ist das Mindestgewicht von einem Stack (99+ Items) erreicht und überschüssige Energie vorhanden, wird die Kiste automatisch über eine Seil mit der Seilwinde verbunden und in die Höhe gezogen. + +[ta2_weight_chest|image] + + ## Items schieben und sortieren diff --git a/techage/manuals/manual_ta2_EN.md b/techage/manuals/manual_ta2_EN.md index 0d4c30c..ff24e46 100644 --- a/techage/manuals/manual_ta2_EN.md +++ b/techage/manuals/manual_ta2_EN.md @@ -67,7 +67,7 @@ Part of the steam engine. The boiler must be connected to the cylinder via the s ### TA2 Drive Axle / TA2 Gearbox -The drive axles are used to transmit power from the steam engine to other machines. The maximum length of a drive axis is 8 blocks. With TA2 Gearboxes, larger distances can be bridged, and branches and changes of direction can be realized. +The drive axles are used to transmit power from the steam engine to other machines. The maximum length of a drive axis is 10 blocks. With TA2 Gearboxes, larger distances can be bridged, and branches and changes of direction can be realized. [ta2_driveaxle|image] @@ -82,6 +82,31 @@ The Power Generator takes max. 25 ku of axle power and provides on the other sid [ta2_generator|image] +## TA2 energy storage + +For larger systems with several steam engines or many driven machines, an energy storage system is recommended. The energy storage at TA2 works with position energy. For this purpose, ballast (stones, gravel, sand) is pulled up in a chest with the help of a cable winch. If there is excess energy in the axis network, the chest is pulled upwards. If more energy is required in the short term than the steam engine can supply, the energy store releases the stored energy again and the weight chest moves down again. +The energy storage consists of several blocks and must be assembled as shown in the plan on the right. +In order to achieve the maximum storage capacity, the chest must be completely filled with weights and the mast including the two gear boxes must be 12 blocks high. Smaller structures are also possible. + +[ta2_storage|plan] + + + +### TA2 Winch + +The cable winch must be connected to a gear box and can absorb excess energy and thus pull a weight chest upwards. The maximum rope length is 10 blocks. + +[ta2_winch|image] + + + +### TA2 Weight Chest + +This chest must be placed under the winch with a distance of up to 10 blocks and filled with cobblestone, gravel or sand. If the minimum weight of a stack (99+ items) is reached and there is excess energy, the box is automatically connected to the winch via a rope and pulled up. + +[ta2_weight_chest|image] + + ## Push and sort items diff --git a/techage/manuals/manual_ta3_DE.md b/techage/manuals/manual_ta3_DE.md index 7f8dfae..a02fca6 100644 --- a/techage/manuals/manual_ta3_DE.md +++ b/techage/manuals/manual_ta3_DE.md @@ -15,7 +15,7 @@ Das Kohlekraftwerk besteht aus mehreren Blöcken und muss wie im Plan rechts abg Der Boiler muss mit Wasser gefüllt werden. Dazu bis zu 10 Eimer Wasser in den Boiler füllen. Die Feuerbox muss mit Kohle oder Holzkohle gefüllt werden. -Wenn das Wasser heiß ist, kann das Ventil am Boiler geöffnet und anschließend die Generator gestartet werden. +Wenn das Wasser heiß ist, kann der Generator gestartet werden. Das Kraftwerk kann alternativ auch mit einem Ölbrenner ausgestattet und dann mit Öl betrieben werden. Das Öl kann über eine Pumpe und Ölleitung nachgefüllt werden. @@ -77,26 +77,46 @@ Dient zur Abkühlung des heißen Dampfs aus der Turbine. Muss über Dampfleitun ## Elektrischer Strom -In TA3 (und TA4) werden die Maschinen mit Strom angetrieben. Dazu müssen die Maschinen und Generatoren mit Stromkabel verbunden werden. +In TA3 (und TA4) werden die Maschinen mit Strom angetrieben. Dazu müssen die Maschinen, Speichersysteme und Generatoren mit Stromkabel verbunden werden. TA3 besitzt 2 Arten von Stromkabel: - Isolierte Kabel (TA Stromkabel) für die lokale Verkabelung im Boden oder in Gebäuden. Diese Kabel lassen sich in der Wand oder im Boden verstecken (können mit der Kelle "verputzt" werden). - Überlandleitungen (TA Stromleitung) für Freiluftverkabelung über große Strecken. Diese Kabel sind geschützt, können also von anderen Spielern nicht entfernt werden. -Mehrere Verbraucher und Generatoren können in einem Stromnetzwerk zusammen betrieben werden. Mit Hilfe der Verteilerdosen können so große Netzwerke aufgebaut werden. +Mehrere Verbraucher, Speichersysteme und Generatoren können in einem Stromnetzwerk zusammen betrieben werden. Mit Hilfe der Verteilerdosen können so Netzwerke aufgebaut werden. Wird zu wenig Strom bereitgestellt, gehen die Verbraucher aus. In diesem Zusammenhang ist auch wichtig, dass die Funktionsweise von Forceload Blöcken verstanden wurde, denn bspw. Generatoren liefern nur Strom, wenn der entsprechende Map-Block geladen ist. Dies kann mit einen Forceload Block erzwungen werden. In TA4 kommt noch ein Kabel für die Solaranlage hinzu. - [ta3_powerswitch|image] +### Bedeutung von Speichersystemen + +Speichersysteme im Stromnetz erfüllen zwei Aufgaben: + +- Um Bedarfsspitzen abzufangen: Alle Generatoren liefern immer gerade soviel Leistung, wie benötigt wird. Werden aber Verbraucher ein/ausgeschaltet oder kommt es aus anderen Gründen zu Bedarfsschwankungen, so können Verbraucher kurzzeitig ausfallen. Um dies zu verhindern, sollte immer mindestens ein Akkublock in jedem Netzwerk vorhanden sein. Dieser dient als Puffer und gleicht diese Schwankungen im Sekundenbereich aus. +- Um regenerative Energie zu speichern: Solar und Wind stehen nicht 24 Stunden am Tag zur Verfügung. Damit die Stromversorgung nicht ausfällt, wenn kein Strom produziert wird, müssen ein oder mehrere Speichersysteme im Netzwerk verbaut werden. Alternativ können die Lücken auch mit Öl/Kohle-Strom überbrückt werden. + +Ein Speichersystem gibt seine Kapazität in kud an, also ku pro day (Tag). Bspw. ein Speichersystem mit 100 kud liefert 100 ku einen Spieltag lang, oder auch 10 ku für 10 Spieltage. + +Alle TA3/TA4 Energiequellen besitzen eine einstellbare Ladecharakteristik. Standardmäßig ist diese auf "80% - 100%" eingestellt. Dies bedeutet, dass die Leistung ab 80% Füllung des Speichersystems immer weiter reduziert wird, bis sie bei 100 % komplett abschaltet. Sofern Strom im Netzwerk benötigt wird, werden die 100 % nie erreicht, da die Leistung des Generators irgendwann auf den Strombedarf im Netzwerk abgesunken ist und damit das Speichersystem nicht mehr geladen, sondern nur noch die Verbraucher bedient werden. + +Dies hat mehrere Vorteile: + +- Die Ladecharakteristik ist einstellbar. Damit kann man bspw. Öl/Kohle Energiequellen bei 60% und die regenerativen Energiequellen erst bei 80% zurückfahren. Damit wird nur Öl/Kohle verbrannt, wenn nicht ausreichend regenerativen Energiequellen zur Verfügung stehen. +- Mehrere Energiequellen können parallel betrieben werden und werden dabei nahezu gleichmäßig belastet, denn alle Energiequellen arbeiten bspw. bis 80% Ladekapazität des Speichersystems mit ihrer vollen Leistung und fahren dann gleichzeitig ihre Leistung zurück. +- Alle Speichersysteme in einem Netzwerk bilden einen großen Puffer. An jedem Speichersystem aber auch am Strom Terminal kann immer die Ladekapazität und der Füllungsgrad des gesamten Speichersystems in Prozent abgelesen werden. + +[power_reduction|image] + + + ### TA Stromkabel / Electric Cable Für die lokale Verkabelung im Boden oder in Gebäuden. -Abzweigungen können mit Hilfe von Verteilerdosen realisiert werden. Die maximale Kabellänge zwischen Maschinen oder Verteilerdosen beträgt 1000 m. Es können maximale 1000 Knoten in einem Strom-Netzwerk verbunden werden. Als Knoten zählen alle Generatoren, Akkus, Verteilerdosen und Maschinen. +Abzweigungen können mit Hilfe von Verteilerdosen realisiert werden. Die maximale Kabellänge zwischen Maschinen oder Verteilerdosen beträgt 1000 m. Es können maximale 1000 Knoten in einem Strom-Netzwerk verbunden werden. Als Knoten zählen alle Blöcke mit Stromanschluss, also auch Verteilerdosen. Da die Stromkabel nicht automatisch geschützt sind, wird für längere Strecken die Überlandleitungen (TA Stromleitung) empfohlen. @@ -113,7 +133,6 @@ Außer Kabel können auch die TA Verteilerdose und die TA Stromschalterbox verpu ### TA Verteilerdose / Electric Junction Box Mit der Verteilerdose kann Strom in bis zu 6 Richtungen verteilt werden. Verteilerdosen können auch mit der Kelle verputzt (versteckt) und wieder sichtbar gemacht werden. -Wird mit dem TechAge Info Werkzeug (Schraubenschlüssel) auf die Verteilerdose geklickt, wird angezeigt, wie viel Leistung die Generatoren liefern bzw. die Verbraucher im Netzwerk beziehen. [ta3_powerjunction|image] @@ -180,9 +199,9 @@ Der Stromgenerator kann nur 50 Einheiten Benzin aufnehmen. Ein zusätzlicher Tan ### TA3 Akku Block / Akku Box Der Akku Block dient zur Speicherung von überschüssiger Energie und gibt bei Stromausfall automatisch Strom ab (soweit vorhanden). -Der Akku Block ist eine sekundäre Stromquelle. Das bedeutet, bei Strombedarf werden zuerst die Generatoren genutzt. Nur wenn der Strom im Netz nicht ausreicht, springt der Akku Block ein. Das Gleiche gilt auch für die Stromaufnahme. Daher kann auch kein Akku mit einem anderen Akku geladen werden. -Der Akku liefert 10 ku bzw. nimmt 10 ku auf. -Bei Volllast kann ein Akku 400 s lang Strom aufnehmen und wenn er voll ist, auch wieder abgeben. Dies entspricht 8 h Spielzeit bei einem normalen Spieltag von 20 min. +Mehrere Akku Blocks zusammen bilden ein TA3 Energiespeichersystem. Jeder Akku Block hat eine Anzeige für den Ladezustand und für die gespeicherte Ladung, wobei hier immer die Werte für das gesamte Netzwerk angezeigt werden. Die gespeicherte Ladung wird in "kud" also "ku-days" angezeigt (analog zu kWh) 5 kud entspricht damit bspw. 5 ku für einen Spieltag (20 min) oder 1 ku für 5 Spieltage. + +Ein Akku Block hat 3.33 kud. [ta3_akkublock|image] @@ -191,9 +210,16 @@ Bei Volllast kann ein Akku 400 s lang Strom aufnehmen und wenn er voll ist, auch Das Strom-Terminal muss mit dem Stromnetz verbunden werden. Es zeigt Daten aus dem Stromnetz an. -In der oberen Hälfte werden nur die Daten eines ausgewählten Typs ausgegeben. Wird als Typ bspw. "Kraftwerk" gewählt, so werden nur die Daten von Öl- und Kohlekraftwerken gesammelt und ausgegeben. Links werden die Daten von Generatoren (Stromabgabe) und rechts die Daten von Energiespeichern (Stromaufnahme) ausgegeben. Beim Akkublocks bspw. wird beides ausgegeben, da der Akku Strom aufnehmen und abgeben kann. +In der oberen Hälfte werden die wichtigsten Größen ausgegeben: -In der unteren Hälfte werden die Daten aller Generatoren und Speichersystemen des ganzen Stromnetzen zusammengefasst ausgegeben. +- aktuelle/maximale Generatorleistung +- aktueller Stromaufnahme aller Verbraucher +- aktueller Ladestrom in/aus dem Speichersystems +- aktuellen Ladezustand des Speichersystems in Prozent + +In der unteren Hälfte wird die Anzahl der Netzwerkblöcke ausgegeben. + +Über den Reiter "console" können weitere Daten zu den Generatoren und Speichersystemen abgefragt werden. [ta3_powerterminal|image] @@ -208,16 +234,6 @@ Das Elektromotor nimmt primär max. 40 ku an Strom auf und gibt sekundär max. 3 [ta3_motor|image] -### TA3 Strom Terminal / Power Terminal - -Das Strom-Terminal muss mit dem Stromnetz verbunden werden. Es zeigt Daten aus dem Stromnetz an. - -In der oberen Hälfte werden nur die Daten eines ausgewählten Typs ausgegeben. Wird als Typ bspw. "Kraftwerk" gewählt, so werden nur die Daten von Öl- und Kohlekraftwerken gesammelt und ausgegeben. Links werden die Daten von Generatoren (Stromabgabe) und rechts die Daten von Energiespeichern (Stromaufnahme) ausgegeben. Beim Akkublocks bspw. wird beides ausgegeben, da der Akku Strom aufnehmen und abgeben kann. - -In der unteren Hälfte werden die Daten aller Generatoren und Speichersystemen des ganzen Stromnetzen zusammengefasst ausgegeben. - -[ta3_powerterminal|image] - ## TA3 Industrieofen @@ -801,11 +817,14 @@ Die Verarbeitungsleistung beträgt bis zu 8 mal ein Item alle 4 Sekunden. Das Techage Info Tool (Schraubenschlüssel) hat verschiedene Funktionen. Er zeigt die Uhrzeit, die Position, die Temperatur und das Biome an, wenn auf einen unbekannten Block geklickt wird. Wird auf einen TechAge Block mit Kommandoschnittstelle geklickt, werden alle verfügbaren Daten abgerufen (siehe auch "Logik-/Schalt-Blöcke"). -Bei Strom-Verteilerdosen werden die benachbarten Netzwerkteilnehmer (bis zu 50 Meter weit) mit einem blauen Käfig angezeigt. + +Mit Shift+Rechtsklick kann bei einigen Blöcken ein erweitertes Menü geöffnet werden. Hier lassen sich je nach Block weitere Daten abrufen oder spezielle Einstellungen vornehmen. Bei einem Generator kann bspw. die Ladekurve/abschaltung programmiert werden. [ta3_end_wrench|image] + + ### TechAge Programmer Mit dem Programmer können Blocknummern mit einem Rechtsklick von mehreren Blöcken eingesammelt und mit einem Linksklick in einen Block wie Taster/Schalter geschrieben werden. diff --git a/techage/manuals/manual_ta3_EN.md b/techage/manuals/manual_ta3_EN.md index c1f2fb2..3f96e33 100644 --- a/techage/manuals/manual_ta3_EN.md +++ b/techage/manuals/manual_ta3_EN.md @@ -77,13 +77,13 @@ Used to cool the hot steam from the turbine. Must be connected to the boiler and ## Electrical current -In TA3 (and TA4) the machines are powered by electricity. To do this, the machines and generators must be connected with power cables. +In TA3 (and TA4) the machines are powered by electricity. To do this, machines, storage systems, and generators must be connected with power cables. TA3 has 2 types of power cables: - Insulated cables (TA power cables) for local wiring in the floor or in buildings. These cables can be hidden in the wall or in the floor (can be "plastered" with the trowel). - Overland lines (TA power line) for outdoor cabling over long distances. These cables are protected and cannot be removed by other players. -Several consumers and generators can be operated together in a power network. Large networks can be set up with the help of the junction boxes. +Several consumers, storage systems, and generators can be operated together in a power network. Networks can be set up with the help of the junction boxes. If too little electricity is provided, consumers run out. In this context, it is also important that the functionality of Forceload blocks is understood, because generators, for example, only supply electricity when the corresponding map block is loaded. This can be enforced with a forceload block. @@ -93,10 +93,31 @@ In TA4 there is also a cable for the solar system. [ta3_powerswitch|image] +### Importance of storage systems + +Storage systems in the power grid fulfill two tasks: + +- To cope with peaks in demand: All generators always deliver just as much power as is needed. However, if consumers are switched on/off or there are fluctuations in demand for other reasons, consumers can fail for a short time. To prevent this, there should always be at least one battery block in every network. This serves as a buffer and compensates for these fluctuations in the seconds range. +- To store regenerative energy: Solar and wind are not available 24 hours a day. So that the power supply does not fail when no electricity is produced, one or more storage systems must be installed in the network. Alternatively, the gaps can also be bridged with oil/coal electricity. + +A storage system indicates its capacity in kud, i.e. ku per day. For example, a storage system with 100 kud delivers 100 ku for one game day, or 10 ku for 10 game days. + +All TA3/TA4 energy sources have adjustable charging characteristics. By default this is set to "80% - 100%". This means that when the storage system is 80% full, the output is reduced further and further until it switches off completely at 100%. If electricity is required in the network, 100% will never be reached, since the power of the generator has at some point dropped to the electricity demand in the network and the storage system is no longer charged, but only the consumers are served. + +This has several advantages: + +- The charging characteristics are adjustable. This means, for example, that oil/coal energy sources can be reduced at 60% and regenerative energy sources only at 80%. This means that oil/coal is only burned if there are not enough renewable energy sources available. +- Several energy sources can be operated in parallel and are loaded almost evenly, because all energy sources work, for example, up to 80% of the storage system's charging capacity at their full capacity and then reduce their capacity at the same time. +- All storage systems in a network form a large buffer. The charging capacity and the filling level of the entire storage system can always be read in percent on every storage system, but also on the electricity terminal. + +[power_reduction|image] + + + ### TA Electric Cable For local wiring in the floor or in buildings. -Branches can be realized using junction boxes. The maximum cable length between machines or junction boxes is 1000 m. A maximum of 1000 nodes can be connected in a power network. All generators, batteries, junction boxes and machines count as nodes. +Branches can be realized using junction boxes. The maximum cable length between machines or junction boxes is 1000 m. A maximum of 1000 nodes can be connected in a power network. All blocks with power connection, including junction boxes, count as nodes. Since the power cables are not automatically protected, the land lines (TA power line) are recommended for longer distances. @@ -113,7 +134,6 @@ In addition to cables, the TA junction box and the TA power switch box can also ### TA Electric Junction Box With the junction box, electricity can be distributed in up to 6 directions. Junction boxes can also be plastered (hidden) with a trowel and made visible again. -If the TechAge Info tool (wrench) is clicked on the junction box, it is shown whether the power line is powered or not. [ta3_powerjunction|image] @@ -180,9 +200,10 @@ The power generator can only hold 50 units of gasoline. An additional tank and a ### TA3 Battery Block The battery block is used to store excess energy and automatically delivers power in the event of a power failure (if available). -The battery block is a secondary power source. This means that the generators are used first when electricity is required. The battery block will only provide power if there is insufficient electricity in the network. The same applies to the current consumption. Therefore, no battery can be charged with another battery. -The battery delivers 10 ku or takes up 10 ku. -At full load, a battery can take up to 400 s of current and, when it is full, also release it again. This corresponds to 8 hours of playing time on a normal game day of 20 minutes. +Several battery blocks together form a TA3 energy storage system. Each battery block has a display for the charging state and for the stored load. +The values for the entire network are always displayed here. The stored load is displayed in "kud" or "ku-days" (analogous to kWh) 5 kud thus corresponds, for example, to 5 ku for a game day (20 min) or 1 ku for 5 game days. + +A battery block has 3.33 kud [ta3_akkublock|image] @@ -191,9 +212,16 @@ At full load, a battery can take up to 400 s of current and, when it is full, al The power terminal must be connected to the power grid. It shows data from the power grid. -Only the data of a selected type are output in the upper half. If, for example, "Power station" is selected as the type, only the data from oil and coal-fired power stations are collected and output. The data from generators (power delivery) and the data from energy storage devices (power consumption) are output on the left. In the case of the battery blocl, for example, both are output because the battery can draw and deliver power. +The most important figures are displayed in the upper half: -In the lower half, the data of all generators and storage systems of the entire electricity network are summarized. +- current/maximum generator power +- current power consumption of all consumers +- current charging current in/from the storage system +- Current state of charge of the storage system in percent + +The number of network blocks is output in the lower half. + +Additional data on the generators and storage systems can be queried via the "console" tab. [ta3_powerterminal|image] @@ -784,7 +812,8 @@ The processing power is up to 8 times one item every 4 seconds. The Techage Info Tool (wrench) has several functions. It shows the time, position, temperature and biome when an unknown block is clicked on. If you click on a TechAge block with command interface, all available data will be shown (see also "Logic / switching blocks"). -In the case of power junction boxes, the neighboring network participants (up to 50 meters away) are displayed with a blue cage. + +With Shift + right click an extended menu can be opened for some blocks. Depending on the block, further data can be called up or special settings can be made here. In the case of a generator, for example, the charging curve/switch-off can be programmed. [ta3_end_wrench|image] diff --git a/techage/manuals/manual_ta4_DE.md b/techage/manuals/manual_ta4_DE.md index 5f1ae5f..5294279 100644 --- a/techage/manuals/manual_ta4_DE.md +++ b/techage/manuals/manual_ta4_DE.md @@ -23,9 +23,7 @@ Die Windkraftanlage liefert eine Leistung von 70 ku, aber dies nur 8 Stunden am ### TA4 Windkraftanlage / Wind Turbine Der Windkraftanlagenblock (Rotor) ist das Herzstück der Windkraftanlage. Dieser Block muss oben auf den Mast gesetzt werden. Idealerweise auf Y = 15, dann bleibst du noch gerade innerhalb eines Map-/Forceload-Blocks. -Nach dem Setzen des Blocks wird ein Check durchgeführt, ob alle Bedingungen für den Betrieb der Windkraftanlage erfüllt sind. Sofern alle Bedingungen erfüllt sind, erscheinen beim Setzen dieses Blocks auch automatisch die Rotorblätter (Flügel). Anderenfalls wird dir eine Fehlermeldung angezeigt. - -Durch Schlagen auf den Block kann der Check wiederholt werden. +Beim Starten der Windkraftanlage werden alle Bedingungen für den Betrieb der Windkraftanlage überprüft. Sofern alle Bedingungen erfüllt sind, erscheinen auch automatisch die Rotorblätter (Flügel). Anderenfalls wird eine Fehlermeldung angezeigt. [ta4_windturbine|image] @@ -131,19 +129,20 @@ Diese Solarzelle kann nicht mit den anderen Solarmodulen kombiniert werden. ## Energiespeicher +Der TA4 Energiespeicher ersetzt den Batterie Block aus TA3. + Der Energiespeicher besteht aus einer Betonhülle (Concrete Block) gefüllt mit Gravel. Es gibt 3 Größen vom Speicher: -- Hülle mit 5x5x5 Concrete Blocks, gefüllt mit 27 Gravel, Speicherkapazität: 1/2 Tag bei 60 ku -- Hülle mit 7x7x7 Concrete Blocks, gefüllt mit 125 Gravel, Speicherkapazität: 2,5 Tage bei 60 ku -- Hülle mit 9x9x9 Concrete Blocks, gefüllt mit 343 Gravel, Speicherkapazität: 6,5 Tage bei 60 ku +- Hülle mit 5x5x5 Concrete Blocks, gefüllt mit 27 Gravel, Speicherkapazität: 22.5 kud +- dHülle mit 7x7x7 Concrete Blocks, gefüllt mit 125 Gravel, Speicherkapazität: 104 kud +- Hülle mit 9x9x9 Concrete Blocks, gefüllt mit 343 Gravel, Speicherkapazität: 286 kud In der Betonhülle darf ein Fenster aus einem Obsidian Glas Block sein. Dieses muss ziemlich in der Mitte der Wand platziert werden. Durch dieses Fenster sieht man, ob der Speicher mehr als 80 % geladen ist. Im Plan rechts sieht man den Aufbau aus TA4 Wärmetauscher bestehend aus 3 Blöcken, der TA4 Turbine und dem TA4 Generator. Beim Wärmetauscher ist auf die Ausrichtung zu achten (der Pfeil bei Block 1 muss zur Turbine zeigen). -Entgegen dem Plan rechts müssen die Anschlüsse am Speicherblock auf gleicher Ebene sein (horizontal angeordnet, also nicht unten und oben). Die Rohrzuläufe (TA4 Pipe Inlet) müssen genau in der Mitte der Wand sein und stehen sich damit gegenüber. Als Röhren kommen die gelbel TA4 Röhren zum Einsatz. Die TA3 Dampfrohre können hier nicht verwendet werden. +Entgegen dem Plan rechts müssen die Anschlüsse am Speicherblock auf gleicher Ebene sein (horizontal angeordnet, also nicht unten und oben). Die Rohrzuläufe (TA4 Pipe Inlet) müssen genau in der Mitte der Wand sein und stehen sich damit gegenüber. Als Röhren kommen die gelben TA4 Röhren zum Einsatz. Die TA3 Dampfrohre können hier nicht verwendet werden. Sowohl der Generator als auch der Wärmetauscher haben einen Stromanschluss und müssen mit dem Stromnetz verbunden werden. Im Prinzip arbeitet das das Wärmespeichersystem genau gleich wie die Akkus, nur mit viel mehr Speicherkapazität. -Der Wärmespeicher kann 60 ku aufnehmen und abgeben. Damit das Wärmespeichersystem funktioniert, müssen alle Blöcke (auch Betonhülle und Gravel) mit Hilfe eines Forceloadblockes geladen sein. @@ -153,7 +152,7 @@ Damit das Wärmespeichersystem funktioniert, müssen alle Blöcke (auch Betonhü ### TA4 Wärmetauscher / Heat Exchanger Der Wärmetauscher besteht aus 3 Teilen, die aufeinander gesetzt werden müssen, wobei der Pfeil des ersten Blockes Richtung Turbine zeigen muss. Die Rohrleitungen müssen mit den gelben TA4 Röhren aufgebaut werden. -Der Wärmetauscher muss am Stromnetz angeschlossen werden. Der Wärmetauscher lädt den Energiespeicher wieder auf, wenn ausreichend Strom zur Verfügung steht und der Energiespeicher weniger als 95 % geladen ist. Der Wärmetauscher nimmt dabei 60 ku auf. +Der Wärmetauscher muss am Stromnetz angeschlossen werden. Über den Wärmetauscher wird der Energiespeicher wieder aufgeladen, sofern ausreichend Strom zur Verfügung steht. [ta4_heatexchanger|image] @@ -167,9 +166,9 @@ Die Turbine ist Teil des Energiespeichers. Sie muss neben den Generator gesetzt ### TA4 Generator -Der Generator dient zur Stromerzeugung. Daher muss auch der Generator am Stromnetz angeschlossen werden. +Der Generator ist Teil des Energiespeichers. Er dient zur Stromerzeugung und gibt damt die Energie des Energiespeichers wieder ab. Daher muss auch der Generator am Stromnetz angeschlossen werden. -Der Generator kann 60 ku abgeben. +Wichtig: Wärmetauscher und Generator müssen mit ein und demselben Stromnetz verbunden sein! [ta4_generator|image] @@ -190,6 +189,52 @@ Die maximale Leitungslänge beträgt 100 m. [ta4_pipe|image] + + +## Stromverteilung + +Mit Hilfe von Stromkabeln und Verteilerdosen können Stromnetze von bis zu 1000 Blöcke/Knoten aufgebaut werden. Hierbei ist aber zu beachten, dass Verteilerdosen auch mitgezählt werden müssen. Somit können bis zu 500 Generatoren/Speichersysteme/Maschinen/Lampen an einem Stromnetz hängen. + +Mit Hilfe von Trenntransformator und Stromzähler können Netzwerke zu noch größeren Strukturen verbunden werden. + +[ta4_transformer|image] + + + +### TA4 Trenntransformator / TA4 Isolation Transformer + +Mit Hilfe eines Trenntransformators können zwei Stromnetze zu einem größeren Netzwerk verbunden werden. Der Trenntransformator kann Strom in beide Richtungen übertragen. + +Der Trenntransformator kann bis zu 100 ku übertragen. + +[ta4_transformer|image] + + + +### TA4 Stromzähler / TA4 Electric Meter + +Mit Hilfe eines Stromzählers können zwei Stromnetze zu einem größeren Netzwerk verbunden werden. Der Stromzähler leitet den Strom nur in eine Richtungen weiter (Pfeil beachten). Die Menge an Strom (in kud) wird gemessen und angezeigt. Die Strommenge kann auch über das Kommando `consumption` durch einen Lua Controller abgefragt werden. + +Der Stromzähler kann bis zu 200 ku durchleiten. + +[ta4_electricmeter|image] + + + +### TA4 Laser + +Der TA4 Laser dient zur kabellosen Stromübertagung. Dazu sind zwei Blöcke notwendig: TA4 Laserstrahl Sender und TA4 Laserstrahl Empfänger. Zwischen beiden Blöcken muss sich eine Luftstrecke befinden, so dass der Laserstrahl vom Sender bis zum Empfänger aufgebaut werden kann. + +Zuerst muss der Sender platziert werden. Dieser schaltet sofort den Laserstahls ein und zeigt damit mögliche Positionen des Empfängers an. Mögliche Positionen für den Empfänger werden auch über eine Chat-Nachricht ausgegeben. Mit dem Laser lassen sich Strecken bis 96 Blöcke überbrücken. + +Ist die Verbindung aufgebaut (es muss dazu noch kein Strom fließen), wird dies über den Info-Text des Senders und auch des Empfängers angezeigt. + +Die Laserblöcke selbst benötigen keinen Strom. + +[ta4_laser|image] + + + ## Wasserstoff Strom kann mittels Elektrolyse in Wasserstoff und Sauerstoff aufgespalten werden. Auf der anderen Seite kann über eine Brennstoffzelle Wasserstoff mit Sauerstoff aus der Luft wieder in Strom umgewandelt werden. @@ -211,6 +256,8 @@ Es muss von links mit Strom versorgt werden. Rechts kann Wasserstoff über Röhr Der Elektrolyseur kann bis zu 35 ku an Strom aufnehmen und generiert dann alle 4 s ein Wasserstoff Item. In den Elektrolyseur passen 200 Einheiten Wasserstoff. +Der Elektrolyseur besitzt ein Schraubenschlüssel-Menü zur Einstellung der Stromaufnahme und des Abschaltpunkts. + [ta4_electrolyzer|image] @@ -683,14 +730,3 @@ Die Verarbeitungsleistung beträgt ein Item alle 8 s. Der Block benötigt hierf [ta4_recycler|image] -### TA4 Laser - -Der TA4 Laser dient zur kabellosen Stromübertagung. Dazu sind zwei Blöcke notwendig: TA4 Laserstrahl Sender und TA4 Laserstrahl Empfänger. Zwischen beiden Blöcken muss sich eine Luftstrecke befinden, so dass der Laserstrahl vom Sender bis zum Empfänger aufgebaut werden kann. - -Zuerst muss der Sender platziert werden. Dieser schaltet sofort den Laserstahls ein und zeigt damit mögliche Positionen des Empfängers an. Mögliche Positionen für den Empfänger werden auch über eine Chat-Nachricht ausgegeben. Mit dem Laser lassen sich Strecken bis 96 Blöcke überbrücken. - -Ist die Verbindung aufgebaut (es muss dazu noch kein Strom fließen), wird dies über den Info-Text des Senders und auch des Empfängers angezeigt. - -Die Laserblöcke selbst benötigen keinen Strom. - -[ta4_laser|image]t \ No newline at end of file diff --git a/techage/manuals/manual_ta4_EN.md b/techage/manuals/manual_ta4_EN.md index eebab93..6f5698d 100644 --- a/techage/manuals/manual_ta4_EN.md +++ b/techage/manuals/manual_ta4_EN.md @@ -23,9 +23,7 @@ The wind turbine delivers 70 ku, but only 8 hours a day (see above). ### TA4 Wind Turbine The wind turbine block (rotor) is the heart of the wind turbine. This block must be placed on top of the mast. Ideally at Y = 15, then you just stay within a map / forceload block. -After the block has been set, a check is carried out to determine whether all conditions for the operation of the wind turbine have been met. If all conditions are met, the rotor blades (wings) appear automatically when this block is set. Otherwise you will get an error message. - -The check can be repeated by hitting the block. +When you start the turbine, all conditions for the operation of the wind turbine are checked. If all conditions are met, the rotor blades (wings) appear automatically. Otherwise you will get an error message. [ta4_windturbine|image] @@ -131,11 +129,13 @@ This solar cell cannot be combined with the other solar modules. ## Thermal Energy Storage +The thermal energy storage replaces the battery block from TA3. + The thermal energy store consists of a concrete shell (concrete blocks) filled with gravel. Three sizes of the storage are possible: -- Cover with 5x5x5 concrete blocks, filled with 27 gravel, storage capacity: 1/2 day at 60 ku -- Cover with 7x7x7 concrete blocks, filled with 125 gravel, storage capacity: 2.5 days at 60 ku -- Cover with 9x9x9 concrete blocks, filled with 343 gravel, storage capacity: 6.5 days at 60 ku +- Cover with 5x5x5 concrete blocks, filled with 27 gravel, storage capacity: 22.5 kud +- Cover with 7x7x7 concrete blocks, filled with 125 gravel, storage capacity: 104 kud +- Cover with 9x9x9 concrete blocks, filled with 343 gravel, storage capacity: 286 kud A window made of an obsidian glass block may be in the concrete shell. This must be placed fairly in the middle of the wall. Through this window you can see whether the storage is loaded more than 80%. In the plan on the right you can see the structure of TA4 heat exchanger consisting of 3 blocks, the TA4 turbine and the TA4 generator. Pay attention to the alignment of the heat exchanger (the arrow at block 1 must point to the turbine). @@ -143,7 +143,6 @@ Contrary to the plan on the right, the connections on the storage block must be Both the generator and the heat exchanger have a power connection and must be connected to the power grid. In principle, the heat storage system works exactly the same as the batteries, only with much more storage capacity. -The heat accumulator can hold and deliver 60 ku. In order for the heat storage system to work, all blocks (also the concrete shell and gravel) must be loaded using a forceload block. @@ -153,7 +152,7 @@ In order for the heat storage system to work, all blocks (also the concrete shel ### TA4 Heat Exchanger The heat exchanger consists of 3 parts that must be placed on top of each other, with the arrow of the first block pointing towards the turbine. The pipes must be built with the yellow TA4 pipes. -The heat exchanger must be connected to the power grid. The heat exchanger charges the energy store again when sufficient electricity is available and the energy storage is less than 95% charged. The heat exchanger takes up 60 ku. +The heat exchanger must be connected to the power grid. The energy storage device is recharged via the heat exchanger, provided that sufficient electricity is available. [ta4_heatexchanger|image] @@ -168,8 +167,9 @@ The turbine is part of the energy storage. It must be placed next to the generat ### TA4 Generator The generator is used to generate electricity. Therefore, the generator must also be connected to the power grid. +The generator is part of the energy storage. It is used to generate electricity and thus releases the energy from the energy storage unit. Therefore, the generator must also be connected to the power grid. -The generator can deliver 60 ku. +Important: Both, heat exchanger and generator must be connected to the same power grid! [ta4_generator|image] @@ -190,6 +190,44 @@ The maximum cable length is 100 m. [ta4_pipe|image] + + +## Power Distribution + +With the help of power cables and junction boxes, power networks of up to 1000 blocks/nodes can be set up. However, it should be noted that distribution boxes must also be counted. This means that up to 500 generators/storage systems/machines/lamps can be connected to a power grid. + +With the help of an isolating transformer and electricity meter, networks can be connected to form even larger structures. + +[ta4_transformer|image] + +### TA4 Isolation Transformer + +With the help of an isolating transformer, two power grids can be connected to form a larger network. The isolation transformer can transmit electricity in both directions. + +The isolation transformer can transmit up to 100 ku. + +[ta4_transformer|image] + +### TA4 Electric Meter + +With the help of an electricity meter, two electricity networks can be connected to form a larger network. The electricity meter only transmits electricity in one direction (note arrow). The amount of electricity (in kud) is measured and displayed. The amount of electricity can also be queried by a Lua controller using the `consumption` command. + +The electricity meter can pass up to 200 ku. + +[ta4_electricmeter|image] + +### TA4 Laser + +The TA4 laser is used for wireless power transmission. Two blocks are required for this: TA4 Laser Beam Emitter and TA4 Laser Beam Receiver. There must be an air gap between the two blocks so that the laser beam can be built up from the emitter to the receiver. First the emitter must be placed. This immediately switches on the laser beam and shows possible positions of the receiver. Possible positions for the receiver are also output via a chat message. + +With the laser, distances of up to 96 blocks can be bridged. Once the connection has been established (no current has to flow), this is indicated via the info text of the emitter and also of the receiver. + +The laser blocks themselves do not require any electricity. + +[ta4_laser|image] + + + ## Hydrogen Electrolysis can be used to split electricity into hydrogen and oxygen. On the other hand, hydrogen can be converted back into electricity with oxygen from the air using a fuel cell. @@ -211,6 +249,8 @@ It must be powered from the left. On the right, hydrogen can be extracted via pi The electrolyzer can draw up to 35 ku of electricity and then generates a hydrogen item every 4 s. 200 units of hydrogen fit into the electrolyzer. +The electrolyzer has a wrench menu for setting the current consumption and the switch-off point. + [ta4_electrolyzer|image] @@ -683,13 +723,3 @@ The machine can disassemble pretty much any Techage and Hyperloop blocks. But no The processing power is one item every 8 s. The block requires 16 ku of electricity for this. [ta4_recycler|image] - -### TA4 Laser - -The TA4 laser is used for wireless power transmission. Two blocks are required for this: TA4 Laser Beam Emitter and TA4 Laser Beam Receiver. There must be an air gap between the two blocks so that the laser beam can be built up from the emitter to the receiver. First the emitter must be placed. This immediately switches on the laser beam and shows possible positions of the receiver. Possible positions for the receiver are also output via a chat message. - -With the laser, distances of up to 96 blocks can be bridged. Once the connection has been established (no current has to flow), this is indicated via the info text of the emitter and also of the receiver. - -The laser blocks themselves do not require any electricity. - -[ta4_laser|image] \ No newline at end of file diff --git a/techage/manuals/toc_DE.md b/techage/manuals/toc_DE.md index cbc8c7a..438c601 100644 --- a/techage/manuals/toc_DE.md +++ b/techage/manuals/toc_DE.md @@ -2,6 +2,8 @@ - [Tech Age Mod](./manual_DE.md#tech-age-mod) - [Hinweise](./manual_DE.md#hinweise) + - [Änderungen ab Version 1.0](./manual_DE.md#änderungen-ab-version-1.0) + - [Tipps zur Umstellung](./manual_DE.md#tipps-zur-umstellung) - [Erze und Mineralien](./manual_DE.md#erze-und-mineralien) - [Meridium](./manual_DE.md#meridium) - [Usmium](./manual_DE.md#usmium) @@ -9,7 +11,6 @@ - [Erdöl](./manual_DE.md#erdöl) - [Bauxit](./manual_DE.md#bauxit) - [Basalt](./manual_DE.md#basalt) - - [History](./manual_DE.md#history) - [TA1: Eisenzeitalter](./manual_ta1_DE.md#ta1:-eisenzeitalter) - [Köhler / Coal Pile](./manual_ta1_DE.md#köhler--coal-pile) - [Kohlebrenner / Coal Burner](./manual_ta1_DE.md#kohlebrenner--coal-burner) @@ -28,6 +29,9 @@ - [TA2 Dampfleitungen / Steam Pipe](./manual_ta2_DE.md#ta2-dampfleitungen--steam-pipe) - [TA2 Antriebsachsen / TA2 Drive Axle](./manual_ta2_DE.md#ta2-antriebsachsen--ta2-drive-axle) - [TA2 Stromgenerator / TA2 Power Generator](./manual_ta2_DE.md#ta2-stromgenerator--ta2-power-generator) + - [TA2 Energiespeicher](./manual_ta2_DE.md#ta2-energiespeicher) + - [TA2 Seilwinde / TA2 Winch](./manual_ta2_DE.md#ta2-seilwinde---ta2-winch) + - [TA2 Gewichtekiste / TA2 Weight Chest](./manual_ta2_DE.md#ta2-gewichtekiste--ta2-weight-chest) - [Items schieben und sortieren](./manual_ta2_DE.md#items-schieben-und-sortieren) - [Röhren / TechAge Tube](./manual_ta2_DE.md#röhren--techage-tube) - [Röhren Konzentrator / Tube Concentrator](./manual_ta2_DE.md#röhren-konzentrator--tube-concentrator) @@ -55,6 +59,7 @@ - [TA3 Generator](./manual_ta3_DE.md#ta3-generator) - [TA3 Kühler / Cooler](./manual_ta3_DE.md#ta3-kühler--cooler) - [Elektrischer Strom](./manual_ta3_DE.md#elektrischer-strom) + - [Bedeutung von Speichersystemen](./manual_ta3_DE.md#bedeutung-von-speichersystemen) - [TA Stromkabel / Electric Cable](./manual_ta3_DE.md#ta-stromkabel--electric-cable) - [TA Verteilerdose / Electric Junction Box](./manual_ta3_DE.md#ta-verteilerdose--electric-junction-box) - [TA Stromleitung / Power Line](./manual_ta3_DE.md#ta-stromleitung--power-line) @@ -68,7 +73,6 @@ - [TA3 Akku Block / Akku Box](./manual_ta3_DE.md#ta3-akku-block---akku-box) - [TA3 Strom Terminal / Power Terminal](./manual_ta3_DE.md#ta3-strom-terminal--power-terminal) - [TA3 Elektromotor / TA3 Electric Motor](./manual_ta3_DE.md#ta3-elektromotor--ta3-electric-motor) - - [TA3 Strom Terminal / Power Terminal](./manual_ta3_DE.md#ta3-strom-terminal--power-terminal) - [TA3 Industrieofen](./manual_ta3_DE.md#ta3-industrieofen) - [TA3 Ofen-Ölbrenner / Furnace Oil Burner](./manual_ta3_DE.md#ta3-ofen-ölbrenner--furnace-oil-burner) - [TA3 Ofenoberteil / Furnace Top](./manual_ta3_DE.md#ta3-ofenoberteil--furnace-top) @@ -145,6 +149,10 @@ - [TA4 Generator](./manual_ta4_DE.md#ta4-generator) - [TA4 Rohrzulauf / TA4 Pipe Inlet](./manual_ta4_DE.md#ta4-rohrzulauf--ta4-pipe-inlet) - [TA4 Röhre / Pipe](./manual_ta4_DE.md#ta4-röhre--pipe) + - [Stromverteilung](./manual_ta4_DE.md#stromverteilung) + - [TA4 Trenntransformator / TA4 Isolation Transformer](./manual_ta4_DE.md#ta4-trenntransformator--ta4-isolation-transformer) + - [TA4 Stromzähler / TA4 Electric Meter](./manual_ta4_DE.md#ta4-stromzähler--ta4-electric-meter) + - [TA4 Laser](./manual_ta4_DE.md#ta4-laser) - [Wasserstoff](./manual_ta4_DE.md#wasserstoff) - [Elektrolyseur](./manual_ta4_DE.md#elektrolyseur) - [Brennstoffzelle](./manual_ta4_DE.md#brennstoffzelle) @@ -195,5 +203,4 @@ - [TA4 Steinbrecher / Quarry](./manual_ta4_DE.md#ta4-steinbrecher--quarry) - [TA4 Elektronikfabrik / Electronic Fab](./manual_ta4_DE.md#ta4-elektronikfabrik--electronic-fab) - [TA4 Injektor / Injector](./manual_ta4_DE.md#ta4-injektor--injector) - - [TA4 Recycler](./manual_ta4_DE.md#ta4-recycler) - - [TA4 Laser](./manual_ta4_DE.md#ta4-laser) \ No newline at end of file + - [TA4 Recycler](./manual_ta4_DE.md#ta4-recycler) \ No newline at end of file diff --git a/techage/manuals/toc_EN.md b/techage/manuals/toc_EN.md index d3f880f..25fd56a 100644 --- a/techage/manuals/toc_EN.md +++ b/techage/manuals/toc_EN.md @@ -2,6 +2,8 @@ - [Tech Age Mod](./manual_EN.md#tech-age-mod) - [Hints](./manual_EN.md#hints) + - [Changes from version 1.0](./manual_EN.md#changes-from-version-1.0) + - [Tips on switching](./manual_EN.md#tips-on-switching) - [Ores and Minerals](./manual_EN.md#ores-and-minerals) - [Meridium](./manual_EN.md#meridium) - [Usmium](./manual_EN.md#usmium) @@ -28,6 +30,9 @@ - [TA2 Steam Pipes](./manual_ta2_EN.md#ta2-steam-pipes) - [TA2 Drive Axle / TA2 Gearbox](./manual_ta2_EN.md#ta2-drive-axle--ta2-gearbox) - [TA2 Power Generator](./manual_ta2_EN.md#ta2-power-generator) + - [TA2 energy storage](./manual_ta2_EN.md#ta2-energy-storage) + - [TA2 Winch](./manual_ta2_EN.md#ta2-winch) + - [TA2 Weight Chest](./manual_ta2_EN.md#ta2-weight-chest) - [Push and sort items](./manual_ta2_EN.md#push-and-sort-items) - [TechAge Tube](./manual_ta2_EN.md#techage-tube) - [Tube Concentrator](./manual_ta2_EN.md#tube-concentrator) @@ -55,6 +60,7 @@ - [TA3 generator](./manual_ta3_EN.md#ta3-generator) - [TA3 cooler](./manual_ta3_EN.md#ta3-cooler) - [Electrical current](./manual_ta3_EN.md#electrical-current) + - [Importance of storage systems](./manual_ta3_EN.md#importance-of-storage-systems) - [TA Electric Cable](./manual_ta3_EN.md#ta-electric-cable) - [TA Electric Junction Box](./manual_ta3_EN.md#ta-electric-junction-box) - [TA Power Line](./manual_ta3_EN.md#ta-power-line) @@ -144,6 +150,10 @@ - [TA4 Generator](./manual_ta4_EN.md#ta4-generator) - [TA4 Pipe Inlet](./manual_ta4_EN.md#ta4-pipe-inlet) - [TA4 Pipe](./manual_ta4_EN.md#ta4-pipe) + - [Power Distribution](./manual_ta4_EN.md#power-distribution) + - [TA4 Isolation Transformer](./manual_ta4_EN.md#ta4-isolation-transformer) + - [TA4 Electric Meter](./manual_ta4_EN.md#ta4-electric-meter) + - [TA4 Laser](./manual_ta4_EN.md#ta4-laser) - [Hydrogen](./manual_ta4_EN.md#hydrogen) - [Electrolyzer](./manual_ta4_EN.md#electrolyzer) - [Fuel Cell](./manual_ta4_EN.md#fuel-cell) @@ -194,5 +204,4 @@ - [TA4 Quarry](./manual_ta4_EN.md#ta4-quarry) - [TA4 Electronic Fab](./manual_ta4_EN.md#ta4-electronic-fab) - [TA4 Injector](./manual_ta4_EN.md#ta4-injector) - - [TA4 Recycler](./manual_ta4_EN.md#ta4-recycler) - - [TA4 Laser](./manual_ta4_EN.md#ta4-laser) \ No newline at end of file + - [TA4 Recycler](./manual_ta4_EN.md#ta4-recycler) \ No newline at end of file diff --git a/techage/mod.conf b/techage/mod.conf index ea1e24d..fde06d4 100644 --- a/techage/mod.conf +++ b/techage/mod.conf @@ -1,4 +1,4 @@ name = techage -depends = default,doors,flowers,tubelib2,basic_materials,bucket,stairs,screwdriver,minecart,lcdlib,safer_lua -optional_depends = unified_inventory,wielded_light,unifieddyes,moreores,ethereal,mesecon,digtron,bakedclay +depends = default,doors,flowers,tubelib2,networks,basic_materials,bucket,stairs,screwdriver,minecart,lcdlib,safer_lua +optional_depends = unified_inventory,wielded_light,unifieddyes,moreores,ethereal,mesecon,digtron,bakedclay,moreblocks description = Techage, go through 4 tech ages in search of wealth and power! diff --git a/techage/oil/distiller.lua b/techage/oil/distiller.lua index e8fcc6e..ac57644 100644 --- a/techage/oil/distiller.lua +++ b/techage/oil/distiller.lua @@ -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 function orientation(pos, names) @@ -40,10 +39,6 @@ local function after_place_node(pos, placer) Pipe:after_place_node(pos) end -local function tubelib2_on_update2(pos, dir, tlib2, node) - liquid.update_network(pos, dir, tlib2) -end - local function after_dig_node(pos, oldnode, oldmetadata, digger) Pipe:after_dig_node(pos) end @@ -73,9 +68,7 @@ minetest.register_node("techage:ta3_distiller_base", { type = "fixed", fixed = {-1/2, -1/2, -1/2, 1/2, 1/2, 1/2}, }, - after_place_node = after_place_node, - tubelib2_on_update2 = tubelib2_on_update2, after_dig_node = after_dig_node, paramtype2 = "facedir", @@ -83,15 +76,10 @@ minetest.register_node("techage:ta3_distiller_base", { groups = {cracky=2}, is_ground_content = false, sounds = default.node_sound_stone_defaults(), - - networks = { - pipe2 = { - sides = {B=1}, -- Pipe connection sides - ntype = "pump", - }, - }, }) +liquid.register_nodes({"techage:ta3_distiller_base"}, Pipe, "pump", {"B"}, {}) + minetest.register_node("techage:ta3_distiller1", { description = S("TA3 Distillation Tower 1"), tiles = {"techage_distiller1.png"}, @@ -112,8 +100,6 @@ minetest.register_node("techage:ta3_distiller1", { after_place_node(pos, placer) return res end, - - tubelib2_on_update2 = tubelib2_on_update2, after_dig_node = after_dig_node, paramtype = "light", @@ -122,15 +108,10 @@ minetest.register_node("techage:ta3_distiller1", { groups = {cracky=2}, is_ground_content = false, sounds = default.node_sound_metal_defaults(), - - networks = { - pipe2 = { - sides = {F=1}, -- Pipe connection sides - ntype = "tank", - }, - }, }) +liquid.register_nodes({"techage:ta3_distiller1"}, Pipe, "pump", {"F"}, {}) + minetest.register_node("techage:ta3_distiller2", { description = S("TA3 Distillation Tower 2"), tiles = {"techage_distiller2.png"}, @@ -175,8 +156,6 @@ minetest.register_node("techage:ta3_distiller3", { local res = orientation(pos, {"techage:ta3_distiller2"}) return res end, - - tubelib2_on_update2 = tubelib2_on_update2, after_dig_node = after_dig_node, paramtype = "light", @@ -185,15 +164,10 @@ minetest.register_node("techage:ta3_distiller3", { groups = {cracky=2}, is_ground_content = false, sounds = default.node_sound_metal_defaults(), - - networks = { - pipe2 = { - sides = {B=1}, -- Pipe connection sides - ntype = "pump", - }, - }, }) +liquid.register_nodes({"techage:ta3_distiller3"}, Pipe, "pump", {"B"}, {}) + minetest.register_node("techage:ta3_distiller4", { description = S("TA3 Distillation Tower 4"), tiles = {"techage_distiller4.png"}, @@ -213,8 +187,6 @@ minetest.register_node("techage:ta3_distiller4", { after_place_node(pos, placer) return res end, - - tubelib2_on_update2 = tubelib2_on_update2, after_dig_node = after_dig_node, paramtype = "light", @@ -223,40 +195,28 @@ minetest.register_node("techage:ta3_distiller4", { groups = {cracky=2}, is_ground_content = false, sounds = default.node_sound_metal_defaults(), - - networks = { - pipe2 = { - sides = {U=1}, -- Pipe connection sides - ntype = "pump", - }, - }, }) +liquid.register_nodes({"techage:ta3_distiller4"}, Pipe, "pump", {"U"}, {}) -Pipe:add_secondary_node_names({ - "techage:ta3_distiller_base", "techage:ta3_distiller1", - "techage:ta3_distiller3", "techage:ta3_distiller4", -}) - -local Liquids = { - [-1] = "techage:bitumen", - [2] = "techage:fueloil", - [4] = "techage:naphtha", - [6] = "techage:gasoline", - [7] = "techage:gas", -} +local Liquids = {"techage:bitumen", "techage:fueloil", "techage:naphtha", "techage:gasoline", "techage:gas"} +local YPos = {-1, 2, 4, 6, 7} techage.register_node({"techage:ta3_distiller1"}, { on_transfer = function(pos, in_dir, topic, payload) if topic == "put" then - local leftover = 0 - local outdir = M(pos):get_int("outdir") - for _,y in ipairs({-1, 2, 4, 6, 7}) do - local pos2 = {x = pos.x, y = pos.y + y, z = pos.z} - if y == 7 then - outdir = 6 - end - leftover = leftover + liquid.put(pos2, outdir, Liquids[y], 1) + local nvm = techage.get_nvm(pos) + nvm.idx = nvm.idx or 1 + local outdir + if nvm.idx == 5 then + outdir = 6 -- up + else + outdir = M(pos):get_int("outdir") + end + local pos2 = {x = pos.x, y = pos.y + YPos[nvm.idx], z = pos.z} + local leftover = liquid.put(pos2, Pipe, outdir, Liquids[nvm.idx], 1) + if leftover == 0 then + nvm.idx = (nvm.idx % 5) + 1 end return leftover end diff --git a/techage/oil/drillbox.lua b/techage/oil/drillbox.lua index 042afa2..bcc4466 100644 --- a/techage/oil/drillbox.lua +++ b/techage/oil/drillbox.lua @@ -238,7 +238,7 @@ local tubing = { local nvm = techage.get_nvm(pos) if not nvm.assemble_locked then local meta = minetest.get_meta(pos) - if meta:get_int("push_dir") == in_dir or in_dir == 5 then + if meta:get_int("push_dir") == in_dir then local inv = M(pos):get_inventory() CRD(pos).State:start_if_standby(pos) return techage.put_items(inv, "src", stack) @@ -299,6 +299,7 @@ local _, node_name_ta3, _ = sounds = default.node_sound_wood_defaults(), num_items = {0,1,1,1}, power_consumption = {0,10,16,24}, + tube_sides = {L=1, R=1}, }, {false, false, true, false}) -- TA3 only diff --git a/techage/oil/explore.lua b/techage/oil/explore.lua index c4d4180..c7f6e2c 100644 --- a/techage/oil/explore.lua +++ b/techage/oil/explore.lua @@ -23,7 +23,7 @@ local OIL_MAX = 20000 local DEPTH_MIN = 16 local DEPTH_MAX = 25*16 local DEPTH_STEP = 16 -local YPOS_MAX = -6*16 -- oil can found below this level +local YPOS_MAX = -6*16 -- oil can't found below this level local OIL_BUBBLE_SIZE = 4096 local seed = tonumber(minetest.settings:get("techage_oil_exploration_seed")) or 1234 -- confidental! diff --git a/techage/oil/pumpjack.lua b/techage/oil/pumpjack.lua index eb70012..4fbc016 100644 --- a/techage/oil/pumpjack.lua +++ b/techage/oil/pumpjack.lua @@ -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 @@ -18,7 +18,7 @@ local M = minetest.get_meta local P = minetest.string_to_pos local S = techage.S local Pipe = techage.LiquidPipe -local liquid = techage.liquid +local liquid = networks.liquid -- Consumer Related Data local CRD = function(pos) return (minetest.registered_nodes[techage.get_node_lvm(pos).name] or {}).consumer end @@ -103,7 +103,7 @@ end local function pumping(pos, crd, meta, nvm) if has_oil(pos, meta) then - local leftover = liquid.put(pos, 6, "techage:oil_source", 1) + local leftover = liquid.put(pos, Pipe, 6, "techage:oil_source", 1) if leftover and leftover > 0 then crd.State:blocked(pos, nvm) stop_sound(pos) @@ -211,12 +211,6 @@ local _, node_name_ta3, _ = end Pipe:after_place_node(pos) end, - networks = { - pipe2 = { - sides = {U = 1}, -- Pipe connection side - ntype = "pump", - }, - }, power_sides = {F=1, B=1, L=1, R=1, D=1}, on_rightclick = on_rightclick, on_receive_fields = on_receive_fields, @@ -244,5 +238,5 @@ minetest.register_craft({ }, }) -Pipe:add_secondary_node_names({"techage:ta3_pumpjack_pas", "techage:ta3_pumpjack_act"}) +liquid.register_nodes({"techage:ta3_pumpjack_pas", "techage:ta3_pumpjack_act"}, Pipe, "pump", {"U"}, {}) diff --git a/techage/oil/reboiler.lua b/techage/oil/reboiler.lua index d395f37..816d976 100644 --- a/techage/oil/reboiler.lua +++ b/techage/oil/reboiler.lua @@ -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,15 +16,14 @@ local S2P = minetest.string_to_pos local P2S = minetest.pos_to_string local M = minetest.get_meta local S = techage.S +local Flip = networks.Flip local Pipe = techage.LiquidPipe -local networks = techage.networks -local liquid = techage.liquid -local Flip = techage.networks.Flip local Cable = techage.ElectricCable -local power = techage.power +local liquid = networks.liquid +local power = networks.power -local CYCLE_TIME = 16 -local CAPA = 12 +local CYCLE_TIME = 2 +local WAITING_CYCLES = 5 -- in case BLOCKED local PWR_NEEDED = 14 local function play_sound(pos) @@ -51,88 +50,96 @@ end local function swap_node(pos, on) local nvm = techage.get_nvm(pos) - if on then - local node = techage.get_node_lvm(pos) + local node = techage.get_node_lvm(pos) + if on and node.name == "techage:ta3_reboiler" then node.name = "techage:ta3_reboiler_on" minetest.swap_node(pos, node) - minetest.get_node_timer(pos):start(CYCLE_TIME) play_sound(pos) - elseif not on and nvm.running then - local node = techage.get_node_lvm(pos) + elseif not on and node.name == "techage:ta3_reboiler_on" then node.name = "techage:ta3_reboiler" minetest.swap_node(pos, node) - minetest.get_node_timer(pos):stop() - nvm.running = false - power.consumer_stop(pos, Cable) stop_sound(pos) end end -local function on_power(pos) - swap_node(pos, true) -end - -local function on_nopower(pos) - swap_node(pos, false) -end - -local function is_running(pos, nvm) - return nvm.running -end - -local function pump_cmnd(pos, cmnd, payload) - return techage.transfer( +local function pump_cmnd(pos) + local leftover = techage.transfer( pos, "R", -- outdir - cmnd, -- topic - payload, -- payload + "put", -- topic + nil, -- payload Pipe, -- Pipe {"techage:ta3_distiller1"}) + + -- number of processed oil items + return 1 - (tonumber(leftover) or 1) end -local function node_timer(pos, elapsed) - local nvm = techage.get_nvm(pos) - nvm.liquid = nvm.liquid or {} - nvm.liquid.amount = nvm.liquid.amount or 0 - - if not nvm.error or nvm.error == 0 then - power.consumer_alive(pos, Cable, CYCLE_TIME) +local function new_state(pos, nvm, state) + if nvm.state ~= state then + nvm.state = state + M(pos):set_string("infotext", S("TA3 Oil Reboiler") .. ": " .. techage.StateStrings[state]) + swap_node(pos, state == techage.RUNNING) end - - if nvm.liquid.amount >= 5 and nvm.liquid.name == "techage:oil_source" then - nvm.liquid.amount = nvm.liquid.amount - 5 - local leftover = pump_cmnd(pos, "put") - if (tonumber(leftover) or 1) > 0 then - nvm.liquid.amount = nvm.liquid.amount + 5 - nvm.error = 2 -- = 2 pump cycles - M(pos):set_string("infotext", S("TA3 Oil Reboiler: blocked")) - swap_node(pos, false) - return false - end - return true - end - swap_node(pos, false) - return false -end +end -local function start_node(pos) +local function on_timer(pos) local nvm = techage.get_nvm(pos) - if nvm.running then return end + nvm.oil_amount = nvm.oil_amount or 0 - nvm.liquid = nvm.liquid or {} - nvm.liquid.amount = nvm.liquid.amount or 0 - if nvm.liquid.amount >= 5 and nvm.liquid.name == "techage:oil_source" then - if power.power_available(pos, Cable) then - if node_timer(pos, CYCLE_TIME) then - nvm.running = true - power.consumer_start(pos, Cable, CYCLE_TIME) - minetest.get_node_timer(pos):start(CYCLE_TIME) + -- Power handling + if nvm.state == techage.STOPPED then + local consumed = power.consume_power(pos, Cable, nil, PWR_NEEDED) + if consumed == PWR_NEEDED then + new_state(pos, nvm, techage.RUNNING) + return true + end + elseif nvm.state == techage.RUNNING then + local consumed = power.consume_power(pos, Cable, nil, PWR_NEEDED) + if consumed < PWR_NEEDED then + local nvm = techage.get_nvm(pos) + new_state(pos, nvm, techage.STOPPED) + return true + end + elseif nvm.state == techage.BLOCKED or nvm.state == techage.STANDBY then + if not power.power_available(pos, Cable) then + local nvm = techage.get_nvm(pos) + new_state(pos, nvm, techage.STOPPED) + return true + end + end + + -- Oil handling + if nvm.state == techage.RUNNING then + if nvm.oil_amount >= 1 then + local processed = pump_cmnd(pos) + nvm.oil_amount = nvm.oil_amount - processed + nvm.waiting_cycles = WAITING_CYCLES + if processed == 0 then + new_state(pos, nvm, techage.BLOCKED) + else + new_state(pos, nvm, techage.RUNNING) + end + else + nvm.waiting_cycles = (nvm.waiting_cycles or 0) - 1 + if nvm.waiting_cycles <= 0 then + new_state(pos, nvm, techage.STANDBY) end end + elseif nvm.state == techage.BLOCKED then + nvm.waiting_cycles = nvm.waiting_cycles - 1 + if nvm.waiting_cycles <= 0 then + new_state(pos, nvm, techage.RUNNING) + end + else + -- STANDBY: 'put' will trigger the state change end + return true end local function after_place_node(pos) + local nvm = techage.get_nvm(pos) + new_state(pos, nvm, techage.STOPPED) Pipe:after_place_node(pos) Cable:after_place_node(pos) end @@ -143,51 +150,13 @@ local function after_dig_node(pos, oldnode) techage.del_mem(pos) end -local function tubelib2_on_update2(pos, outdir, tlib2, node) - if tlib2.tube_type == "pipe2" then - liquid.update_network(pos, outdir, tlib2) - else - power.update_network(pos, outdir, tlib2) - end +local function on_rightclick(pos, node, clicker) + local nvm = techage.get_nvm(pos) + nvm.oil_amount = 0 + new_state(pos, nvm, techage.STOPPED) + minetest.get_node_timer(pos):start(CYCLE_TIME) end -local liquid_def = { - capa = CAPA, - peek = liquid.srv_peek, - put = function(pos, indir, name, amount) - local nvm = techage.get_nvm(pos) - if nvm.error and nvm.error > 0 then - nvm.error = nvm.error - 1 - if nvm.error <= 0 then - M(pos):set_string("infotext", S("TA3 Oil Reboiler")) - start_node(pos) - return liquid.srv_put(pos, indir, name, amount) - else - return amount - end - else - start_node(pos) - return liquid.srv_put(pos, indir, name, amount) - end - end, - take = liquid.srv_take, -} - -local net_def = { - pipe2 = { - sides = {L = true, R = true}, -- Pipe connection sides - ntype = "tank", - }, - ele1 = { - sides = techage.networks.AllSides, -- Cable connection sides - ntype = "con1", - on_power = on_power, - on_nopower = on_nopower, - nominal = PWR_NEEDED, - is_running = is_running, - }, -} - minetest.register_node("techage:ta3_reboiler", { description = S("TA3 Oil Reboiler"), tiles = { @@ -200,26 +169,10 @@ minetest.register_node("techage:ta3_reboiler", { "techage_filling_ta3.png^techage_appl_reboiler.png^techage_frame_ta3.png", }, - after_place_node = function(pos, placer) - local nvm = techage.get_nvm(pos) - nvm.liquid = {} - local meta = M(pos) - meta:set_string("infotext", S("TA3 Oil Reboiler")) - meta:set_int("outdir", networks.side_to_outdir(pos, "R")) - local number = techage.add_node(pos, "techage:ta3_reboiler") - meta:set_string("node_number", number) - meta:set_string("owner", placer:get_player_name()) - Pipe:after_place_node(pos) - power.after_place_node(pos) - end, - - tubelib2_on_update2 = tubelib2_on_update2, - on_timer = node_timer, + on_timer = on_timer, after_place_node = after_place_node, after_dig_node = after_dig_node, - after_dig_node = after_dig_node, - liquid = liquid_def, - networks = net_def, + on_rightclick = on_rightclick, paramtype2 = "facedir", on_rotate = screwdriver.disallow, @@ -258,10 +211,8 @@ minetest.register_node("techage:ta3_reboiler_on", { }, }, - tubelib2_on_update2 = tubelib2_on_update2, - on_timer = node_timer, - liquid = liquid_def, - networks = net_def, + on_timer = on_timer, + on_rightclick = on_rightclick, paramtype2 = "facedir", on_rotate = screwdriver.disallow, @@ -271,25 +222,43 @@ minetest.register_node("techage:ta3_reboiler_on", { sounds = default.node_sound_metal_defaults(), }) -Pipe:add_secondary_node_names({"techage:ta3_reboiler", "techage:ta3_reboiler_on"}) -Cable:add_secondary_node_names({"techage:ta3_reboiler", "techage:ta3_reboiler_on"}) +local liquid_def = { + peek = function(pos) + local nvm = techage.get_nvm(pos) + return liquid.srv_peek(nvm) + end, + put = function(pos, indir, name, amount) + local nvm = techage.get_nvm(pos) + nvm.oil_amount = nvm.oil_amount or 0 + + if nvm.state == techage.STANDBY or nvm.state == techage.RUNNING then + if name == "techage:oil_source" and amount > 0 then + if nvm.state == techage.STANDBY then + new_state(pos, nvm, techage.RUNNING) + end + -- Take one oil item every 2 cycles + -- Hint: We have to take two items, because the pump will pause for 4 cycles, + -- if nothing is taken. + nvm.take = nvm.take ~= true + if nvm.take and nvm.oil_amount < 5 then + nvm.oil_amount = nvm.oil_amount + 2 + return amount - 2 + end + end + end + return amount + end +} + +liquid.register_nodes({"techage:ta3_reboiler", "techage:ta3_reboiler_on"}, Pipe, "tank", {"L", "R"}, liquid_def) +power.register_nodes({"techage:ta3_reboiler", "techage:ta3_reboiler_on"}, Cable, "con") techage.register_node({"techage:ta3_reboiler", "techage:ta3_reboiler_on"}, { on_recv_message = function(pos, src, topic, payload) local nvm = techage.get_nvm(pos) - if topic == "on" then - start_node(pos) - return true - elseif topic == "off" then - swap_node(pos, false) - return true - elseif topic == "state" then - if nvm.error and nvm.error > 0 then - return "blocked" - elseif nvm.running then - return "running" - end - return "stopped" + if topic == "state" then + nvm.state = nvm.state or techage.STOPPED + return techage.StateStrings[nvm.state] else return "unsupported" end @@ -298,6 +267,7 @@ techage.register_node({"techage:ta3_reboiler", "techage:ta3_reboiler_on"}, { if node.name == "techage:ta3_reboiler_on" then play_sound(pos) end + minetest.get_node_timer(pos):start(CYCLE_TIME) end, }) diff --git a/techage/power/distribution.lua b/techage/power/distribution.lua deleted file mode 100644 index 60a4c20..0000000 --- a/techage/power/distribution.lua +++ /dev/null @@ -1,162 +0,0 @@ ---[[ - - TechAge - ======= - - Copyright (C) 2019-2020 Joachim Stolberg - - AGPL v3 - See LICENSE.txt for more information - - Power Distribution - -]]-- - -local N = function(pos) return techage.get_node_lvm(pos).name end -local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end -local net_def = techage.networks.net_def - -local STOPPED = techage.power.STOPPED -local NOPOWER = techage.power.NOPOWER -local RUNNING = techage.power.RUNNING - -local function start_consumer(tbl, tlib_type) - for _,v in pairs(tbl or {}) do - local nvm = techage.get_nvm(v.pos) - local def = nvm[tlib_type] -- power related network data - if def and def["cstate"] == NOPOWER and (def["calive"] or 0) > 0 then - local ndef = net_def(v.pos, tlib_type) - def["cstate"] = RUNNING - def["taken"] = v.nominal or def.curr_power or 0 - if ndef.on_power then - ndef.on_power(v.pos, tlib_type) - end - end - end -end - -local function stop_consumer(tbl, tlib_type) - for _,v in pairs(tbl or {}) do - local nvm = techage.get_nvm(v.pos) - local def = nvm[tlib_type] -- power related network data - local ndef = net_def(v.pos, tlib_type) - if (def and def["cstate"] == RUNNING) or (ndef.is_running and ndef.is_running(v.pos, nvm)) then - def["cstate"] = NOPOWER - def["taken"] = 0 - if ndef.on_nopower then - ndef.on_nopower(v.pos, tlib_type) - end - end - end -end - -local function get_generator_sum(tbl, tlib_type, cycle_time) - local sum = 0 - for _,v in ipairs(tbl or {}) do - local nvm = techage.get_nvm(v.pos) - local def = nvm[tlib_type] -- power related network data - if def and def["gstate"] ~= STOPPED then - def["galive"] = (def["galive"] or 1) - cycle_time/2 - if def["galive"] >= 0 then - sum = sum + (def.curr_power or v.nominal) - end - end - end - return sum -end - -local function get_consumer_sum(tbl, tlib_type, cycle_time) - local sum = 0 - for _,v in ipairs(tbl or {}) do - local nvm = techage.get_nvm(v.pos) - local def = nvm[tlib_type] -- power related network data - if def and def["cstate"] ~= STOPPED then - def["calive"] = (def["calive"] or 1) - cycle_time/2 - if def["calive"] >= 0 then - sum = sum + (v.nominal or def.curr_power or 0) - end - end - --print(N(v.pos), P2S(v.pos), def["cstate"], def["calive"], sum) - end - return sum -end - -local function set_given(pos, given, tlib_type) - local nvm = techage.get_nvm(pos) - local def = nvm[tlib_type] -- power related network data - if (def and def["galive"] or 0) > 0 then - if def.curr_power and def.curr_power < given then - def["given"] = def.curr_power - else - def["given"] = given - end - return def["given"] - end - return 0 -end - -local function set_taken(pos, taken, tlib_type) - local nvm = techage.get_nvm(pos) - local def = nvm[tlib_type] -- power related network data - if (def and def["calive"] or 0) > 0 then - def["taken"] = taken - def["cstate"] = RUNNING - return taken - end - return 0 -end - -local function set_given_values(tbl, needed, tlib_type) - for _,v in ipairs(tbl or {}) do - local real = math.max(math.min(needed, v.nominal), 0) - real = set_given(v.pos, real, tlib_type) - needed = needed - real - end - return needed -end - -local function set_taken_values(tbl, taken, tlib_type) - for _,v in pairs(tbl or {}) do - local real = math.max(math.min(taken, v.nominal), 0) - real = set_taken(v.pos, real, tlib_type) - taken = taken - real - end - return taken -end - -function techage.power.power_distribution(network, tlib_type, netID, cycle_time) - -- calc maximum power values - network.available1 = get_generator_sum(network.gen1, tlib_type, cycle_time) - network.available2 = get_generator_sum(network.gen2, tlib_type, cycle_time) - network.needed1 = get_consumer_sum(network.con1, tlib_type, cycle_time) - network.needed2 = get_consumer_sum(network.con2, tlib_type, cycle_time) - --print(string.format("%X", netID), network.available1, network.available2, network.needed1, network.needed2) - - -- store results - network.on = network.available1 + network.available2 >= network.needed1 - if network.on then - network.ticker = (network.ticker or 0) + 1 - set_given_values(network.gen1, network.needed1 + network.needed2, tlib_type) - set_given_values(network.gen2, network.needed1 - network.available1, tlib_type) - start_consumer(network.con1, tlib_type) - set_taken_values(network.con2, network.available1 - network.needed1, tlib_type) - else - set_given_values(network.gen1, 0, tlib_type) - set_given_values(network.gen2, 0, tlib_type) - stop_consumer(network.con1, tlib_type) - set_taken_values(network.con2, 0, tlib_type) - end -end - --- determine the maxiumum needed power of all con1 consumers -function techage.power.get_con1_sum(network, tlib_type) - local sum = 0 - for _,v in ipairs(network.con1 or {}) do - local nvm = techage.get_nvm(v.pos) - local def = nvm[tlib_type] -- power related network data - if def and def["cstate"] ~= STOPPED then - sum = sum + (v.nominal or def.curr_power or 0) - end - end - return sum -end diff --git a/techage/power/drive_axle.lua b/techage/power/drive_axle.lua index a1a0105..77a7058 100644 --- a/techage/power/drive_axle.lua +++ b/techage/power/drive_axle.lua @@ -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,13 +17,15 @@ local P = minetest.string_to_pos local M = minetest.get_meta local S = techage.S +local power = networks.power + local Axle = tubelib2.Tube:new({ dirs_to_check = {1,2,3,4,5,6}, - max_tube_length = 8, + max_tube_length = 10, show_infotext = false, tube_type = "axle", primary_node_names = {"techage:axle", "techage:axle_on"}, - secondary_node_names = {"techage:flywheel", "techage:flywheel_on", "techage:gearbox", "techage:gearbox_on"}, + secondary_node_names = {}, after_place_tube = function(pos, param2, tube_type, num_tubes, state) if state == "on" then minetest.swap_node(pos, {name = "techage:axle_on", param2 = param2}) @@ -33,6 +35,10 @@ local Axle = tubelib2.Tube:new({ end, }) +-- Use global callback instead of node related functions +Axle:register_on_tube_update2(function(pos, outdir, tlib2, node) + power.update_network(pos, outdir, tlib2, node) +end) minetest.register_node("techage:axle", { description = S("TA2 Drive Axle"), diff --git a/techage/power/electric_cable.lua b/techage/power/electric_cable.lua index 3799a62..5e87dca 100644 --- a/techage/power/electric_cable.lua +++ b/techage/power/electric_cable.lua @@ -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 @@ -18,7 +18,7 @@ local P2S = minetest.pos_to_string local M = minetest.get_meta local S = techage.S -local power = techage.power +local power = networks.power local ELE1_MAX_CABLE_LENGHT = 1000 @@ -29,56 +29,31 @@ local Cable = tubelib2.Tube:new({ tube_type = "ele1", primary_node_names = {"techage:electric_cableS", "techage:electric_cableA", "techage:power_line", "techage:power_lineS", "techage:power_lineA", - "techage:power_pole2", "techage:powerswitch_box"}, + "techage:power_pole2", "techage:powerswitch_box", "techage:powerswitch_box_on"}, secondary_node_names = {}, after_place_tube = function(pos, param2, tube_type, num_tubes) - -- Handle "power line" nodes local name = minetest.get_node(pos).name - if name == "techage:power_pole2" then - M(pos):set_int("tl2_param2", param2) - return - elseif name == "techage:powerswitch_box" then - minetest.swap_node(pos, {name = "techage:powerswitch_box", param2 = param2 % 32}) - M(pos):set_int("tl2_param2", param2) - return + if name == "techage:powerswitch_box" or name == "techage:powerswitch_box_on" or name == "techage:powerswitch_box_off" then + minetest.swap_node(pos, {name = name, param2 = param2 % 32}) elseif name == "techage:power_line" or name == "techage:power_lineS" or name == "techage:power_lineA" then minetest.swap_node(pos, {name = "techage:power_line"..tube_type, param2 = param2 % 32}) - M(pos):set_int("tl2_param2", param2) - return - end - -- Don't replace "hidden" cable - if M(pos):get_string("techage_hidden_nodename") == "" then + elseif name == "techage:power_pole2" then + -- nothing + elseif not networks.hidden_name(pos) then minetest.swap_node(pos, {name = "techage:electric_cable"..tube_type, param2 = param2 % 32}) end - M(pos):set_int("tl2_param2", param2) + M(pos):set_int("netw_param2", param2) end, }) +-- Enable hidden cables +networks.use_metadata(Cable) +networks.register_hidden_message("Use the trowel tool to remove the node.") --- Overridden method of tubelib2! -function Cable:get_primary_node_param2(pos, dir) - return techage.get_primary_node_param2(pos, dir) -end - -function Cable:is_primary_node(pos, dir) - return techage.is_primary_node(pos, dir) -end - -function Cable:get_secondary_node(pos, dir) - local npos = vector.add(pos, tubelib2.Dir6dToVector[dir or 0]) - local node = self:get_node_lvm(npos) - if self.secondary_node_names[node.name] or - self.secondary_node_names[M(npos):get_string("techage_hidden_nodename")] then - return node, npos, true - end -end - -function Cable:is_secondary_node(pos, dir) - local npos = vector.add(pos, tubelib2.Dir6dToVector[dir or 0]) - local node = self:get_node_lvm(npos) - return self.secondary_node_names[node.name] or - self.secondary_node_names[M(npos):get_string("techage_hidden_nodename")] -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("techage:electric_cableS", { description = S("TA Electric Cable"), @@ -101,10 +76,7 @@ minetest.register_node("techage:electric_cableS", { end, after_dig_node = function(pos, oldnode, oldmetadata, digger) - if oldmetadata and oldmetadata.fields and oldmetadata.fields.tl2_param2 then - oldnode.param2 = oldmetadata.fields.tl2_param2 - Cable:after_dig_tube(pos, oldnode) - end + Cable:after_dig_tube(pos, oldnode, oldmetadata) end, paramtype2 = "facedir", -- important! @@ -137,10 +109,7 @@ minetest.register_node("techage:electric_cableA", { }, after_dig_node = function(pos, oldnode, oldmetadata, digger) - if oldmetadata and oldmetadata.fields and oldmetadata.fields.tl2_param2 then - oldnode.param2 = oldmetadata.fields.tl2_param2 - Cable:after_dig_tube(pos, oldnode) - end + Cable:after_dig_tube(pos, oldnode, oldmetadata) end, paramtype2 = "facedir", -- important! @@ -163,11 +132,6 @@ minetest.register_node("techage:electric_cableA", { drop = "techage:electric_cableS", }) --- only needed for hidden nodes, cause they don't have a tubelib2_on_update2 callback -Cable:register_on_tube_update(function(node, pos, out_dir, peer_pos, peer_in_dir) - power.update_network(pos, nil, Cable) -end) - minetest.register_craft({ output = "techage:electric_cableS 6", recipe = { diff --git a/techage/power/formspecs.lua b/techage/power/formspecs.lua index 8b7f5d4..c014ab5 100644 --- a/techage/power/formspecs.lua +++ b/techage/power/formspecs.lua @@ -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,57 +15,280 @@ --local P2S = minetest.pos_to_string --local M = minetest.get_meta --local N = function(pos) return minetest.get_node(pos).name end ---local S = techage.S -local in_range = techage.in_range +local S = techage.S -function techage.power.percent(max_val, curr_val) - return math.min(math.ceil(((curr_val or 0) * 100) / (max_val or 1.0)), 100) +local CYCLE_TIME = 2 +local CYCLES_PER_DAY = 20 * 60 / CYCLE_TIME + +local in_range = techage.in_range +local power = networks.power +techage.power = {} + +------------------------------------------------------------------------------- +-- Helper function +------------------------------------------------------------------------------- +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 -function techage.power.formspec_load_bar(charging, max_val) - local percent - charging = charging or 0 - max_val = max_val or 1 - if charging ~= 0 then - percent = 50 + math.ceil((charging * 50.0) / max_val) - end +local function calc_percent(max_val, curr_val) + return math.min(((curr_val or 0) * 100) / (max_val or 1.0), 100) +end +------------------------------------------------------------------------------- +-- Local bar functions +------------------------------------------------------------------------------- +-- charging > 0 ==> charging +-- charging < 0 ==> uncharging +-- charging = 0 ==> off +-- percent: 0..100 +local function charging_bar(charging, percent) if charging > 0 then - return "techage_form_level_off.png^[lowpart:"..percent..":techage_form_level_charge.png" + return "techage_form_level_off.png^[lowpart:" .. percent .. ":techage_form_level_charge.png" elseif charging < 0 then - return "techage_form_level_unload.png^[lowpart:"..percent..":techage_form_level_off.png" + return "techage_form_level_unload.png^[lowpart:" .. percent .. ":techage_form_level_off.png" else return "techage_form_level_off.png" end end -function techage.power.formspec_power_bar(max_power, current_power) - if (current_power or 0) == 0 then - return "techage_form_level_bg.png" +local function power_bar(current_power, max_power) + local percent, ypos + + current_power = current_power or 0 + + if current_power == 0 then + percent = 0 + ypos = 2.8 + else + percent = calc_percent(max_power, current_power) + -- 0.4 to 2.8 = 2.4 + local offs = 2.4 - (current_power / max_power) * 2.4 + ypos = 0.4 + in_range(offs, 0.4, 2.4) end - local percent = techage.power.percent(max_power, current_power) - percent = (percent + 5) / 1.22 -- texture correction - return "techage_form_level_bg.png^[lowpart:"..percent..":techage_form_level_fg.png" + current_power = round(current_power) + max_power = round(max_power) + percent = (percent + 5) / 1.1 -- texture correction + + return "label[0.7,0.4;" .. max_power .. " ku]" .. + "image[0,0.5;1,3;" .. + "techage_form_level_bg.png^[lowpart:" .. percent .. + ":techage_form_level_fg.png]" .. + "label[0.7," .. ypos .. ";" .. current_power .. " ku]" end -function techage.power.formspec_label_bar(pos, x, y, label, max_power, current_power, unit) +local function storage_bar(current_power, max_power) + local percent, ypos + max_power = (max_power or 1) / CYCLES_PER_DAY + current_power = (current_power or 0) / CYCLES_PER_DAY + + if current_power == 0 then + percent = 0 + ypos = 2.8 + else + percent = calc_percent(max_power, current_power) + -- 0.4 to 2.8 = 2.4 + local offs = 2.4 - (current_power / max_power) * 2.4 + ypos = 0.4 + in_range(offs, 0.4, 2.4) + end + current_power = round(current_power) + max_power = round(max_power) + + local percent2 = (percent + 5) / 1.1 -- texture correction + return "label[0.7,0.4;" .. max_power .. " kud]" .. + "image[0,0.5;1,3;".. + "techage_form_level_bg.png^[lowpart:" .. percent2 .. + ":techage_form_level_fg.png]" .. + "label[0.7," .. ypos .. ";" .. round(percent) .. " %]" +end + +------------------------------------------------------------------------------- +-- API bar functions +------------------------------------------------------------------------------- +function techage.formspec_power_bar(pos, x, y, label, current_power, max_power) + return "container["..x..","..y.."]".. + "box[0,0;2.3,3.3;#395c74]".. + "label[0.2,0;"..label.."]".. + power_bar(current_power, max_power).. + "container_end[]" +end + +function techage.formspec_charging_bar(pos, x, y, label, data) + local charging = 0 + local percent = 50 + local ypos = 1.6 + + if data then + charging = data.provided - data.consumed + if charging > 0 then + percent = 50 + (charging / data.available * 50) + ypos = 1.6 - (charging / data.available * 1.2) + elseif charging < 0 then + percent = 50 + (charging / data.consumed * 50) + ypos = 1.6 - (charging / data.consumed * 1.2) + end + end + ypos = in_range(ypos, 0.4, 2.8) + + return "container[".. x .. "," .. y .. "]" .. + "box[0,0;2.3,3.3;#395c74]" .. + "label[0.2,0;" .. label .. "]" .. + "image[0,0.5;1,3;" .. charging_bar(charging, percent) .. "]" .. + "label[0.75," .. ypos .. ";" .. round(charging) .. " ku]" .. + "container_end[]" +end + +function techage.formspec_storage_bar(pos, x, y, label, curr_load, max_load) + curr_load = curr_load or 0 + + return "container[" .. x .. "," .. y .. "]" .. + "box[0,0;2.3,3.3;#395c74]" .. + "label[0.2,0;" .. label .. "]" .. + storage_bar(curr_load, max_load) .. + "container_end[]" +end + +function techage.formspec_meter(pos, x, y, label, value, unit) + return "container[" .. x .. "," .. y .. "]" .. + "box[0,0;2.3,1.2;#395c74]" .. + "label[0.2,0.0;" .. label .. ":]" .. + "label[0.2,0.5;" .. round(value) .. " " .. unit .. "]" .. + "container_end[]" +end + +------------------------------------------------------------------------------- +-- API formspec functions +------------------------------------------------------------------------------- +function techage.storage_formspec(self, pos, nvm, label, netw_data, curr_load, max_load) + return "size[6.3,4]" .. + default.gui_bg .. + default.gui_bg_img .. + default.gui_slots .. + "box[0,-0.1;6.1,0.5;#c6e8ff]" .. + "label[0.2,-0.1;" .. minetest.colorize( "#000000", label) .. "]" .. + techage.formspec_charging_bar(pos, 0.0, 0.8, S("Charging"), netw_data) .. + techage.formspec_storage_bar (pos, 3.8, 0.8, S("Storage"), curr_load, max_load) .. + "image_button[2.7,2;1,1;" .. self:get_state_button_image(nvm) .. ";state_button;]" .. + "tooltip[2.7,2;1,1;" .. self:get_state_tooltip(nvm) .. "]" +end + +function techage.generator_formspec(self, pos, nvm, label, provided, max_available, ta2) + local tooltip = "" + if not ta2 then + tooltip = techage.wrench_tooltip(4.4, -0.1) + end + return "size[5,4]" .. + default.gui_bg .. + default.gui_bg_img .. + default.gui_slots .. + "box[0,-0.1;4.8,0.5;#c6e8ff]" .. + "label[0.2,-0.1;" .. minetest.colorize( "#000000", label) .. "]" .. + tooltip.. + techage.formspec_power_bar(pos, 0, 0.8, S("Power"), provided, max_available) .. + "image_button[3.2,2.0;1,1;" .. self:get_state_button_image(nvm) .. ";state_button;]" .. + "tooltip[3.2,2.0;1,1;" .. self:get_state_tooltip(nvm) .. "]" +end + +function techage.generator_settings(tier, available) + if tier == "ta3" then + return { + { + type = "const", + name = "available", + label = S("Maximum output [ku]"), + tooltip = S("The maximum power the generator can provide"), + value = available, + }, + { + type = "output", + name = "provided", + label = S("Current output [ku]"), + tooltip = S("The current power the generator provides"), + }, + { + type = "dropdown", + choices = "0% - 20%,20% - 40%,40% - 60%,60% - 80%,80% - 100%,90% - 100%", + name = "termpoint", + label = S("Charge termination"), + tooltip = S("Range in which the generator reduces its power"), + default = "80% - 100%", + }, + } + else + return { + { + type = "const", + name = "available", + label = S("Maximum output [ku]"), + tooltip = S("The maximum power the generator can provide"), + value = available, + }, + { + type = "output", + name = "provided", + label = S("Current output [ku]"), + tooltip = S("The current power the generator provides"), + }, + { + type = "dropdown", + choices = "0% - 20%,20% - 40%,40% - 60%,60% - 80%,80% - 100%,90% - 100%", + name = "termpoint", + label = S("Charge termination"), + tooltip = S("Range in which the generator reduces its power"), + default = "80% - 100%", + }, + } + end +end + + +function techage.evaluate_charge_termination(nvm, meta) + local termpoint = meta:get_string("termpoint") + if termpoint == "0% - 20%" then + meta:set_string("termpoint1", 0.0) + meta:set_string("termpoint2", 0.2) + elseif termpoint == "20% - 40%" then + meta:set_string("termpoint1", 0.2) + meta:set_string("termpoint2", 0.4) + elseif termpoint == "40% - 60%" then + meta:set_string("termpoint1", 0.4) + meta:set_string("termpoint2", 0.6) + elseif termpoint == "60% - 80%" then + meta:set_string("termpoint1", 0.6) + meta:set_string("termpoint2", 0.8) + elseif termpoint == "80% - 100%" then + meta:set_string("termpoint1", 0.8) + meta:set_string("termpoint2", 1.0) + elseif termpoint == "90% - 100%" then + meta:set_string("termpoint1", 0.9) + meta:set_string("termpoint2", 1.0) + else + meta:set_string("termpoint", "80% - 100%") + meta:set_string("termpoint1", 0.8) + meta:set_string("termpoint2", 1.0) + end +end + +techage.power.percent = calc_percent +techage.CYCLES_PER_DAY = CYCLES_PER_DAY +techage.round = round + +------------------------------------------------------------------------------- +-- Still used legacy functions +------------------------------------------------------------------------------- +function techage.formspec_label_bar(pos, x, y, label, max_power, current_power, unit) local percent, ypos max_power = max_power or 1 unit = unit or "ku" - - if current_power == 0 then - -- check if power network is overloaded - if techage.power.network_overloaded(pos, techage.ElectricCable) then - return "container["..x..","..y.."]".. - "box[0,0;2.3,3.3;#395c74]".. - "label[0.2,0;"..label.."]".. - "label[0.7,0.4;"..max_power.." "..unit.."]".. - "image[0,0.5;1,3;techage_form_level_red_fg.png]".. - "container_end[]" - end - end current_power = current_power or 0 + if current_power == 0 then percent = 0 ypos = 2.8 diff --git a/techage/power/gearbox.lua b/techage/power/gearbox.lua index 30ee5de..d444f24 100644 --- a/techage/power/gearbox.lua +++ b/techage/power/gearbox.lua @@ -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 @@ -18,15 +18,14 @@ local M = minetest.get_meta local S = techage.S local PWR_NEEDED = 1 -local CYCLE_TIME = 4 +local CYCLE_TIME = 2 local Axle = techage.Axle -local power = techage.power -local networks = techage.networks +local power = networks.power -- Axles texture animation local function switch_axles(pos, on) - for _,outdir in ipairs(networks.get_node_connections(pos, "axle")) do + for _,outdir in ipairs(networks.get_outdirs(pos, Axle)) do Axle:switch_tube_line(pos, outdir, on and "on" or "off") end end @@ -40,63 +39,56 @@ local function swap_node(pos, name) minetest.swap_node(pos, node) end -local function on_power(pos) - swap_node(pos, "techage:gearbox_on") - switch_axles(pos, true) +local function node_timer_on(pos, elapsed) + local consumed = power.consume_power(pos, Axle, 0, PWR_NEEDED) + if consumed == 0 then + swap_node(pos, "techage:gearbox") + switch_axles(pos, false) + end + return true end -local function on_nopower(pos) - swap_node(pos, "techage:gearbox") - switch_axles(pos, false) -end - -local function node_timer(pos, elapsed) - power.consumer_alive(pos, Axle, CYCLE_TIME) +local function node_timer_off(pos, elapsed) + if power.power_available(pos, Axle, 0) then + swap_node(pos, "techage:gearbox_on") + switch_axles(pos, true) + end return true end -- to be able to restart the node after server crashes local function techage_on_repair(pos) minetest.get_node_timer(pos):start(CYCLE_TIME) - power.consumer_start(pos, Axle, CYCLE_TIME) end local function after_place_node(pos) Axle:after_place_node(pos) minetest.get_node_timer(pos):start(CYCLE_TIME) - power.consumer_start(pos, Axle, CYCLE_TIME) end local function after_dig_node(pos, oldnode) Axle:after_dig_node(pos) - techage.del_mem(pos) end -local function tubelib2_on_update2(pos, outdir, tlib2, node) - power.update_network(pos, nil, tlib2) +local function tubelib2_on_update2_on(pos, outdir, tlib2, node) + power.update_network(pos, 0, tlib2, node) + switch_axles(pos, true) end -local net_def = { - axle = { - sides = techage.networks.AllSides, -- Cable connection sides - ntype = {"con1", "junc"}, - on_power = on_power, - on_nopower = on_nopower, - nominal = PWR_NEEDED, - }, -} +local function tubelib2_on_update2_off(pos, outdir, tlib2, node) + power.update_network(pos, 0, tlib2, node) + switch_axles(pos, false) +end minetest.register_node("techage:gearbox", { description = S("TA2 Gearbox"), tiles = {"techage_filling_ta2.png^techage_axle_gearbox.png^techage_frame_ta2.png"}, - on_timer = node_timer, + on_timer = node_timer_off, techage_on_repair = techage_on_repair, after_place_node = after_place_node, after_dig_node = after_dig_node, - tubelib2_on_update2 = tubelib2_on_update2, - networks = net_def, - + tubelib2_on_update2 = tubelib2_on_update2_off, paramtype = "light", light_source = 0, paramtype2 = "facedir", @@ -122,13 +114,11 @@ minetest.register_node("techage:gearbox_on", { }, }, - on_timer = node_timer, + on_timer = node_timer_on, techage_on_repair = techage_on_repair, after_place_node = after_place_node, after_dig_node = after_dig_node, - tubelib2_on_update2 = tubelib2_on_update2, - networks = net_def, - + tubelib2_on_update2 = tubelib2_on_update2_on, paramtype2 = "facedir", groups = {not_in_creative_inventory=1}, diggable = false, @@ -138,8 +128,14 @@ minetest.register_node("techage:gearbox_on", { sounds = default.node_sound_wood_defaults(), }) -Axle:add_secondary_node_names({"techage:gearbox", "techage:gearbox_on"}) +power.register_nodes({"techage:gearbox", "techage:gearbox_on"}, Axle, "junc") +techage.register_node({"techage:gearbox", "techage:gearbox_on"}, { + on_node_load = function(pos, node) + minetest.get_node_timer(pos):start(CYCLE_TIME) + end, +}) + minetest.register_craft({ output = "techage:gearbox 2", recipe = { diff --git a/techage/power/junctionbox.lua b/techage/power/junctionbox.lua index a0ec5cb..59f4be2 100644 --- a/techage/power/junctionbox.lua +++ b/techage/power/junctionbox.lua @@ -16,9 +16,8 @@ local M = minetest.get_meta local S = techage.S -local networks = techage.networks local Cable = techage.ElectricCable -local power = techage.power +local power = networks.power local size = 3/32 local Boxes = { @@ -30,33 +29,33 @@ local Boxes = { {{-size, -size, -size, size, 0.5, size}}, -- y+ } -techage.register_junction("techage:electric_junction", 2/8, Boxes, Cable, { +local names = networks.register_junction("techage:electric_junction", 2/8, Boxes, Cable, { description = S("TA Electric Junction Box"), tiles = {"techage_electric_junction.png"}, + use_texture_alpha = techage.CLIP, + is_ground_content = false, 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 name = "techage:electric_junction"..techage.junction_type(pos, Cable) + local name = "techage:electric_junction" .. networks.junction_type(pos, Cable) minetest.swap_node(pos, {name = name, param2 = 0}) Cable:after_place_node(pos) end, tubelib2_on_update2 = function(pos, dir1, tlib2, node) - local name = "techage:electric_junction"..techage.junction_type(pos, Cable) - minetest.swap_node(pos, {name = name, param2 = 0}) - power.update_network(pos, nil, tlib2) + if not networks.hidden_name(pos) then + local name = "techage:electric_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, - networks = { - ele1 = { - sides = networks.AllSides, -- connection sides for cables - ntype = "junc", - }, - }, }) +power.register_nodes(names, Cable, "junc") + minetest.register_craft({ output = "techage:electric_junction0 2", recipe = { diff --git a/techage/power/node_api.lua b/techage/power/node_api.lua deleted file mode 100644 index 9cd912a..0000000 --- a/techage/power/node_api.lua +++ /dev/null @@ -1,262 +0,0 @@ ---[[ - - TechAge - ======= - - Copyright (C) 2019-2020 Joachim Stolberg - - AGPL v3 - See LICENSE.txt for more information - - API for Power Nodes - -]]-- - ---local P2S = minetest.pos_to_string ---local M = minetest.get_meta ---local N = function(pos) return minetest.get_node(pos).name end ---local S = techage.S - -local net_def = techage.networks.net_def -local networks = techage.networks - --- Consumer States -local STOPPED = 1 -local NOPOWER = 2 -local RUNNING = 3 - -techage.power = {} - -techage.power.STOPPED = STOPPED -techage.power.NOPOWER = NOPOWER -techage.power.RUNNING = RUNNING - --- determine network ID (largest hash number of all generators) -local function determine_netID(pos, outdir, Cable) - local netID = 0 - networks.connection_walk(pos, outdir, Cable, function(pos, indir, node) - local ntype = net_def(pos, Cable.tube_type).ntype - if ntype ~= "junc" then - local new = minetest.hash_node_position(pos) - if netID <= new then - netID = new - end - end - end) - return netID -end - --- store network ID on each node -local function store_netID(pos, outdir, netID, Cable) - networks.connection_walk(pos, outdir, Cable, function(pos, indir, node) - --techage.mark_position("singleplayer", pos, "store", "", 2)----------------------------------------- - --print(node.name, dump(net_def(pos, Cable.tube_type))) - if net_def(pos, Cable.tube_type) then - local nvm = techage.get_nvm(pos) - nvm[Cable.tube_type] = nvm[Cable.tube_type] or {} - nvm[Cable.tube_type]["netID"] = netID - end - end) -end - --- delete network and ID on each node -local function delete_netID(pos, outdir, Cable) - local netID = 0 - networks.connection_walk(pos, outdir, Cable, function(pos, indir, node) - --techage.mark_position("singleplayer", pos, "delete", "", 2)---------------------------------------- - if net_def(pos, Cable.tube_type) then - local nvm = techage.get_nvm(pos) - if nvm[Cable.tube_type] and nvm[Cable.tube_type]["netID"] then - netID = nvm[Cable.tube_type]["netID"] - nvm[Cable.tube_type]["netID"] = nil - end - end - end) - networks.delete_network(Cable.tube_type, netID) -end - --- Keep the network up and running -local function trigger_network(pos, outdir, Cable) - local nvm = techage.get_nvm(pos) - local netID = nvm[Cable.tube_type] and nvm[Cable.tube_type]["netID"] - if not netID then - --print("determine_netID !!!!!!!!!!!!!!!!!!!!") - netID = determine_netID(pos, outdir, Cable) - store_netID(pos, outdir, netID, Cable) - networks.build_network(pos, outdir, Cable, netID) - elseif not networks.get_network(Cable.tube_type, netID) then - --print("build_network !!!!!!!!!!!!!!!!!!!!") - netID = determine_netID(pos, outdir, Cable) - store_netID(pos, outdir, netID, Cable) - networks.build_network(pos, outdir, Cable, netID) - end -end - -local function build_network_consumer(pos, Cable) - local outdirs = techage.networks.get_node_connections(pos, Cable.tube_type) - if #outdirs == 1 then - local netID = determine_netID(pos, outdirs[1], Cable) - store_netID(pos, outdirs[1], netID, Cable) - networks.build_network(pos, outdirs[1], Cable, netID) - end -end - --- To be called from each node via 'tubelib2_on_update2' --- 'output' is optional and only needed for nodes with dedicated --- pipe sides (e.g. pumps). -function techage.power.update_network(pos, outdir, Cable) - networks.node_connections(pos, Cable) -- update node internal data - delete_netID(pos, outdir, Cable) -- network walk to delete all IDs -end - --- --- Read the current power value from all connected devices (used for solar cells) --- Only used by the solar inverter to collect the power of all solar cells. --- Only one inverter per network is allowed. Therefore, we have to check, --- if additional inverters are in the network. --- Function returns in addition the number of found inverters. -function techage.power.get_power(pos, outdir, Cable, inverter) - local sum = 0 - local num_inverter = 0 - networks.connection_walk(pos, outdir, Cable, function(pos, indir, node) - --techage.mark_position("singleplayer", pos, "get_power", "", 2)----------------------------------------- - local def = net_def(pos, Cable.tube_type) - if def and def.on_getpower then - sum = sum + def.on_getpower(pos) - else - local node = techage.get_node_lvm(pos) - if node.name == inverter then - num_inverter = num_inverter + 1 - end - end - end) - return sum, num_inverter -end - - - --- --- Consumer related functions --- - --- function checks for a power grid, not for enough power -function techage.power.power_available(pos, Cable) - local nvm = techage.get_nvm(pos) - local tlib_type = Cable.tube_type - local netID = nvm[Cable.tube_type] and nvm[Cable.tube_type]["netID"] - local netw = networks.has_network(tlib_type, netID) - return netw and netw.on and netw.alive and netw.alive > 0 -end - -function techage.power.network_overloaded(pos, Cable) - local nvm = techage.get_nvm(pos) - local tlib_type = Cable.tube_type - local netID = nvm[Cable.tube_type] and nvm[Cable.tube_type]["netID"] - local netw = networks.has_network(tlib_type, netID) - if netw then - local sum = (netw.available1 or 0) + (netw.available2 or 0) - return sum > 0 and sum < (netw.needed1 or 0) - end -end - --- this is more a try to start, the start will be performed by on_power() -function techage.power.consumer_start(pos, Cable, cycle_time) - local nvm = techage.get_nvm(pos) - local tlib_type = Cable.tube_type - nvm[tlib_type] = nvm[tlib_type] or {} - nvm[tlib_type]["calive"] = (cycle_time / 2) + 1 - nvm[tlib_type]["cstate"] = NOPOWER - nvm[tlib_type]["taken"] = 0 -end - -function techage.power.consumer_stop(pos, Cable) - local nvm = techage.get_nvm(pos) - local tlib_type = Cable.tube_type - nvm[tlib_type] = nvm[tlib_type] or {} - nvm[tlib_type]["calive"] = -1 - nvm[tlib_type]["cstate"] = STOPPED - nvm[tlib_type]["taken"] = 0 -end - -function techage.power.consumer_alive(pos, Cable, cycle_time) - local nvm = techage.get_nvm(pos) - local def = nvm[Cable.tube_type] -- power related network data - if def then - -- if network is deleted (cable removed/placed) rebuild it to prevent flickering lights - if not def["netID"] or not networks.get_network(Cable.tube_type, def["netID"]) then - build_network_consumer(pos, Cable) - end - local rv = (cycle_time / 2) + 1 - if def["netID"] and def["calive"] and def["calive"] < rv then -- network available - def["calive"] = rv - return def["taken"] or 0 - elseif not def["cstate"] or def["cstate"] == RUNNING then - local ndef = net_def(pos, Cable.tube_type) - ndef.on_nopower(pos, Cable.tube_type) - def["cstate"] = NOPOWER - end - else - local ndef = net_def(pos, Cable.tube_type) - ndef.on_nopower(pos, Cable.tube_type) - end - return 0 -end - --- --- Generator related functions --- --- curr_power is optional, only needed for generators with variable output power -function techage.power.generator_start(pos, Cable, cycle_time, outdir, curr_power) - local nvm = techage.get_nvm(pos) - local tlib_type = Cable.tube_type - nvm[tlib_type] = nvm[tlib_type] or {} - nvm[tlib_type]["galive"] = (cycle_time / 2) + 2 - nvm[tlib_type]["gstate"] = RUNNING - nvm[tlib_type]["given"] = 0 - nvm[tlib_type]["curr_power"] = curr_power - trigger_network(pos, outdir, Cable) -end - -function techage.power.generator_stop(pos, Cable, outdir) - local nvm = techage.get_nvm(pos) - local tlib_type = Cable.tube_type - nvm[tlib_type] = nvm[tlib_type] or {} - nvm[tlib_type]["galive"] = -1 - nvm[tlib_type]["gstate"] = STOPPED - nvm[tlib_type]["given"] = 0 -end - --- curr_power is optional, only needed for generators with variable output power -function techage.power.generator_alive(pos, Cable, cycle_time, outdir, curr_power) - local nvm = techage.get_nvm(pos) - local def = nvm[Cable.tube_type] -- power related network data - if def then - trigger_network(pos, outdir, Cable) - def["galive"] = (cycle_time / 2) + 2 - def["curr_power"] = curr_power - return def["given"] or 0 - end - return 0 -end - --- Calculate the needed power over all con1 consumers -function techage.power.needed_power(pos, Cable, outdir) - local sum = 0 - networks.connection_walk(pos, outdir, Cable, function(pos, indir, node) - local net = net_def(pos, Cable.tube_type) -- network definition - if net.ntype == "con1" then - local nvm = techage.get_nvm(pos) - local def = nvm[Cable.tube_type] -- power related data - - if def and def["cstate"] and def["cstate"] ~= STOPPED then - if def["calive"] >= 0 then - sum = sum + (net.nominal or def.curr_power or 0) - end - end - end - end) - return sum -end - --- function delete_netID(pos, outdir, Cable) -techage.power.delete_netID = delete_netID diff --git a/techage/power/power_line.lua b/techage/power/power_line.lua index 1b63162..4d3e9c4 100644 --- a/techage/power/power_line.lua +++ b/techage/power/power_line.lua @@ -16,9 +16,8 @@ local P = minetest.string_to_pos local M = minetest.get_meta local S = techage.S -local networks = techage.networks local Cable = techage.ElectricCable -local power = techage.power +local power = networks.power local function can_dig(pos, digger) if M(pos):get_string("owner") == digger:get_player_name() then @@ -44,10 +43,7 @@ minetest.register_node("techage:power_line", { end, after_dig_node = function(pos, oldnode, oldmetadata, digger) - if oldmetadata and oldmetadata.fields and oldmetadata.fields.tl2_param2 then - oldnode.param2 = oldmetadata.fields.tl2_param2 - Cable:after_dig_tube(pos, oldnode) - end + Cable:after_dig_tube(pos, oldnode) end, paramtype2 = "facedir", -- important! @@ -86,10 +82,7 @@ minetest.register_node("techage:power_lineS", { end, after_dig_node = function(pos, oldnode, oldmetadata, digger) - if oldmetadata and oldmetadata.fields and oldmetadata.fields.tl2_param2 then - oldnode.param2 = oldmetadata.fields.tl2_param2 - Cable:after_dig_tube(pos, oldnode) - end + Cable:after_dig_tube(pos, oldnode) end, paramtype2 = "facedir", -- important! @@ -134,10 +127,7 @@ minetest.register_node("techage:power_lineA", { end, after_dig_node = function(pos, oldnode, oldmetadata, digger) - if oldmetadata and oldmetadata.fields and oldmetadata.fields.tl2_param2 then - oldnode.param2 = oldmetadata.fields.tl2_param2 - Cable:after_dig_tube(pos, oldnode) - end + Cable:after_dig_tube(pos, oldnode) end, paramtype2 = "facedir", -- important! @@ -214,13 +204,7 @@ minetest.register_node("techage:power_pole2", { end, can_dig = can_dig, after_dig_node = function(pos, oldnode, oldmetadata, digger) - if oldmetadata and oldmetadata.fields and oldmetadata.fields.tl2_param2 then - oldnode.param2 = oldmetadata.fields.tl2_param2 - Cable:after_dig_tube(pos, oldnode) - end - end, - tubelib2_on_update2 = function(pos, dir1, tlib2, node) - power.update_network(pos, nil, tlib2) + Cable:after_dig_tube(pos, oldnode) end, on_rotate = screwdriver.disallow, -- important! @@ -304,20 +288,10 @@ minetest.register_node("techage:power_pole_conn", { }, connects_to = {"techage:power_line", "techage:power_lineS", "techage:power_lineA"}, - -- after_place_node -- see techage:power_pole - tubelib2_on_update2 = function(pos, dir1, tlib2, node) - power.update_network(pos, nil, tlib2) - end, + can_dig = can_dig, after_dig_node = function(pos, oldnode, oldmetadata, digger) Cable:after_dig_node(pos) end, - can_dig = can_dig, - networks = { - ele1 = { - sides = networks.AllSides, -- connection sides for cables - ntype = "junc", - }, - }, drop = "techage:power_pole", on_rotate = screwdriver.disallow, -- important! @@ -329,8 +303,7 @@ minetest.register_node("techage:power_pole_conn", { sounds = default.node_sound_defaults(), }) -Cable:add_secondary_node_names({"techage:power_pole_conn"}) - +power.register_nodes({"techage:power_pole_conn"}, Cable, "junc") minetest.register_node("techage:power_pole3", { description = S("TA Power Pole"), diff --git a/techage/power/power_terminal.lua b/techage/power/power_terminal.lua index 50b24b6..2d882ce 100644 --- a/techage/power/power_terminal.lua +++ b/techage/power/power_terminal.lua @@ -12,210 +12,4 @@ ]]-- --- 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 = function(pos) return minetest.get_node(pos).name end -local S = techage.S - -local CYCLE_TIME = 2 - -local Cable = techage.ElectricCable -local power = techage.power -local networks = techage.networks -local STOPPED = techage.power.STOPPED -local NOPOWER = techage.power.NOPOWER -local RUNNING = techage.power.RUNNING - -local function generator_data(gen_tbl) - local tbl = { - pow_all=0, pow_on=0, pow_act=0, pow_used=0, - num_on=0, num_act=0, num_used=0 - } - for i,gen in ipairs(gen_tbl or {}) do - local nvm = techage.get_nvm(gen.pos) - tbl.pow_all = tbl.pow_all + (gen.nominal or 0) - if nvm.ele1 and nvm.ele1.gstate and nvm.ele1.gstate ~= STOPPED then - tbl.num_on = tbl.num_on + 1 - tbl.pow_on = tbl.pow_on + (nvm.ele1.curr_power or gen.nominal or 0) - if (nvm.ele1.galive or -1) >= 0 then - tbl.num_act = tbl.num_act + 1 - tbl.pow_act = tbl.pow_act + (nvm.ele1.curr_power or gen.nominal or 0) - if (nvm.ele1.given or 0) > 0 then - tbl.num_used = tbl.num_used + 1 - tbl.pow_used = tbl.pow_used + (nvm.ele1.given or 0) - end - end - end - end - - tbl.num_all = #(gen_tbl or {}) - return tbl -end - -local function consumer_data(con_tbl) - local tbl = { - pow_all=0, pow_on=0, pow_act=0, pow_used=0, - num_on=0, num_act=0, num_used=0 - } - for i,gen in ipairs(con_tbl or {}) do - local nvm = techage.get_nvm(gen.pos) - tbl.pow_all = tbl.pow_all + (gen.nominal or 0) - if nvm.ele1 and nvm.ele1.cstate and nvm.ele1.cstate ~= STOPPED then - tbl.num_on = tbl.num_on + 1 - tbl.pow_on = tbl.pow_on + (gen.nominal or 0) - if (nvm.ele1.calive or -1) >= 0 then - tbl.num_act = tbl.num_act + 1 - tbl.pow_act = tbl.pow_act + (gen.nominal or 0) - if (nvm.ele1.taken or 0) > 0 then - tbl.num_used = tbl.num_used + 1 - tbl.pow_used = tbl.pow_used + (nvm.ele1.taken or 0) - end - end - end - end - - tbl.num_all = #(con_tbl or {}) - return tbl -end - -local function calc_network_data(pos, nvm) - local netw = techage.networks.has_network("ele1", nvm.ele1 and nvm.ele1.netID) or {} - local gen1 = generator_data(netw.gen1) - local gen2 = generator_data(netw.gen2) - local con1 = consumer_data(netw.con1) - local con2 = consumer_data(netw.con2) - - return netw, gen1, gen2, con1, con2 -end - -local function column(x,y, data) - return - "label["..x..","..(y+0.0)..";"..data.num_all.. " ("..data.pow_all.." ku)]".. - "label["..x..","..(y+0.5)..";"..data.num_on.. " ("..data.pow_on.." ku)]".. - "label["..x..","..(y+1.0)..";"..data.num_act.. " ("..data.pow_act.." ku)]".. - "label["..x..","..(y+1.5)..";"..data.num_used.." ("..data.pow_used.." ku)]" -end - -local function get_state(netw, gen1, gen2, con1, con2) - local num_nodes = gen1.num_all + gen2.num_all + con1.num_all + - con2.num_all + (#(netw.junc or {})) + (#(netw.term or {})) - local nload = (gen1.pow_act + gen2.pow_act) / con1.pow_act - local state = S("Number of all nodes")..": ".. num_nodes - if not netw.gen1 and not netw.gen2 then - state = S("No network or active generator available!") - elseif num_nodes > (techage.ELE1_MAX_CABLE_LENGHT - 50) then - state = string.format(S("With %u of a maximum of %u blocks you are almost at the limit!"), - num_nodes, techage.ELE1_MAX_CABLE_LENGHT) - elseif nload <= 1.0 then - state = S("The network is overloaded!") - elseif nload < 1.2 then - state = S("The network load is almost at the limit!") - end - return state -end - -local function formspec(pos, nvm) - local netw, gen1, gen2, con1, con2 = calc_network_data(pos, nvm) - netw.prop = ((netw.prop or 0) + 1) % 2 - local star = netw.prop == 1 and "*" or "" - local state = get_state(netw, gen1, gen2, con1, con2) - - return "size[10,7]".. - default.gui_bg.. - default.gui_bg_img.. - default.gui_slots.. - "box[0,-0.1;9.8,0.5;#c6e8ff]".. - "label[4,-0.1;"..minetest.colorize( "#000000", S("Network Data")).."]".. - "label[9.5,-0.1;"..minetest.colorize( "#000000", star).."]".. - power.formspec_label_bar(pos, 0, 0.7, S("Genera. 1"), gen1.pow_act, gen1.pow_used).. - power.formspec_label_bar(pos, 2.5, 0.7, S("Genera. 2"), gen2.pow_act, gen2.pow_used).. - power.formspec_label_bar(pos, 5, 0.7, S("Consum. 2"), con2.pow_act, con2.pow_used).. - power.formspec_label_bar(pos, 7.5, 0.7, S("Consum. 1"), con1.pow_act, con1.pow_used).. - "box[0,4.3;9.8,0.4;#c6e8ff]".. - "box[0,4.85;9.8,0.4;#395c74]".. - "box[0,5.35;9.8,0.4;#395c74]".. - "box[0,5.85;9.8,0.4;#395c74]".. - "box[0,6.35;9.8,0.4;#395c74]".. - "label[2,4.3;"..minetest.colorize( "#000000", S("Genera. 1")).."]".. - "label[4,4.3;"..minetest.colorize( "#000000", S("Genera. 2")).."]".. - "label[6,4.3;"..minetest.colorize( "#000000", S("Consum. 2")).."]".. - "label[8,4.3;"..minetest.colorize( "#000000", S("Consum. 1")).."]".. - "label[0.1,4.8;"..S("All nodes:").."]".. - "label[0.1,5.3;"..S("Turned on:").."]".. - "label[0.1,5.8;"..S("Active:").."]".. - "label[0.1,6.3;"..S("In use:").."]".. - "box[0,6.95;9.8,0.4;#000000]".. - "label[0.1,6.9;"..state.."]".. - column(2, 4.8, gen1).. - column(4, 4.8, gen2).. - column(6, 4.8, con2).. - column(8, 4.8, con1) -end - -minetest.register_node("techage:power_terminal", { - description = S("TA3 Power Terminal Old"), - inventory_image = "techage_power_terminal_front.png", - tiles = { - "techage_power_terminal_top.png", - "techage_power_terminal_top.png", - "techage_power_terminal_side.png", - "techage_power_terminal_side.png", - "techage_power_terminal_back.png", - "techage_power_terminal_front.png", - }, - drawtype = "nodebox", - node_box = { - type = "fixed", - fixed = { - { -8/16, -8/16, 0/16, 8/16, 8/16, 8/16}, - }, - }, - - after_place_node = function(pos) - local nvm = techage.get_nvm(pos) - M(pos):set_int("outdir", networks.side_to_outdir(pos, "B")) - Cable:after_place_node(pos) - M(pos):set_string("formspec", formspec(pos, nvm)) - end, - after_dig_node = function(pos) - Cable:after_dig_node(pos) - techage.del_mem(pos) - end, - tubelib2_on_update2 = function(pos, outdir, tlib2, node) - power.update_network(pos, outdir, tlib2) - end, - on_rightclick = function(pos, node, clicker) - techage.set_activeformspec(pos, clicker) - minetest.get_node_timer(pos):start(CYCLE_TIME) - local nvm = techage.get_nvm(pos) - M(pos):set_string("formspec", formspec(pos, nvm)) - end, - on_timer = function(pos, elapsed) - local nvm = techage.get_nvm(pos) - if techage.is_activeformspec(pos) then - M(pos):set_string("formspec", formspec(pos, nvm)) - end - return true - end, - - networks = { - ele1 = { - sides = {B = 1}, -- Cable connection side - ntype = "term", - }, - }, - - paramtype2 = "facedir", - paramtype = "light", - use_texture_alpha = techage.CLIP, - on_rotate = screwdriver.disallow, - sunlight_propagates = true, - is_ground_content = false, - groups = {cracky = 2, level = 2, not_in_creative_inventory = 1}, - sounds = default.node_sound_metal_defaults(), -}) - -Cable:add_secondary_node_names({"techage:power_terminal"}) - +minetest.register_alias_force("techage:power_terminal", "techage:ta3_power_terminal") \ No newline at end of file diff --git a/techage/power/power_terminal2.lua b/techage/power/power_terminal2.lua index cbd142d..e1513b2 100644 --- a/techage/power/power_terminal2.lua +++ b/techage/power/power_terminal2.lua @@ -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 @@ -22,417 +22,121 @@ local S = techage.S local CYCLE_TIME = 2 local Cable = techage.ElectricCable -local power = techage.power -local networks = techage.networks -local STOPPED = techage.power.STOPPED -local NOPOWER = techage.power.NOPOWER -local RUNNING = techage.power.RUNNING +local power = networks.power +local control = networks.control -local HELP = [[Commands -help print this text -cls clear screen -gen1 print all cat. 1 generators -gen2 print all cat. 2 generators -con2 print all cat. 2 consumers -num print number of network blocks -pow print provided and needed power]] +local HELP = S([[Commands +help . . . print this text +cls . . . . . clear screen +gen . . . . print all generators +sto . . . . . print all storage systems +]]) - -local Generators = { - S("Power station"), - S("Tiny generator"), - S("Solar system") , - S("Wind turbine"), - S("Accu Box"), - S("Energy storage"), - S("Fuel cell cat. 1"), - S("Fuel cell cat. 2"), - S("Electrolyzer"), - S("TA2 Generator"), -} - -local Storage = { - [S("Accu Box")] = true, - [S("Energy storage")] = true, - [S("Fuel cell cat. 1")] = true, - [S("Fuel cell cat. 2")] = true, - [S("Electrolyzer")] = true, -} - -local GeneratorPerformances = { - 80, -- S("Power station") - 12, -- S("Tiny generator") - 100, -- S("Solar system") - 70, -- S("Wind turbine") - 10, -- S("Accu Box") - 60, -- S("Energy storage") - 33, -- S("Fuel cell cat. 1") - 34, -- S("Fuel cell cat. 2") - 35, -- S("Electrolyzer") - 24, -- S("TA2 Generator") -} - --- --- Generate the needed tables for the formspec --- -local Gentypes = table.concat(Generators, ",") -local Gentype2Idx = {} -local Gentype2Maxvalue = {} -local Gentype = {} - -for idx,name in ipairs(Generators) do - Gentype2Idx[name] = idx - Gentype2Maxvalue[name] = GeneratorPerformances[idx] - Gentype[GeneratorPerformances[idx]] = name +local function row(num, label, data) + local y = 4.0 + num * 0.5 + return + "box[0," .. y .. ";9.8,0.4;#395c74]".. + "label[0.2,"..y..";" .. label .. "]" .. + "label[8.5,"..y..";" .. data .. "]" end -local function short_node_name(nominal) - return Gentype[nominal or 1] or "unknown" -end -local function generator_data(gen_tbl, nominal) - local pow_max = 0 - local pow_curr = 0 - local num_nodes = 0 - - for i,gen in ipairs(gen_tbl or {}) do - if gen.nominal == nominal then - local nvm = techage.get_nvm(gen.pos) - if nvm.ele1 and nvm.ele1.gstate and nvm.ele1.galive and nvm.ele1.given then - num_nodes = num_nodes + 1 - if nvm.ele1.gstate == RUNNING then - pow_max = pow_max + (nvm.ele1.curr_power or nominal) - if nvm.ele1.galive > 0 and nvm.ele1.given > 0 then - pow_curr = pow_curr + nvm.ele1.given - end - end - end - end - end +local function formspec1(pos, data) + local mem = techage.get_mem(pos) + local outdir = M(pos):get_int("outdir") + local netw = networks.get_network_table(pos, Cable, outdir, true) or {} + data = data or power.get_network_data(pos, Cable, outdir) - return pow_max, pow_curr, num_nodes -end - -local function get_generator_data(gen) - local nvm = techage.get_nvm(gen.pos) - local pow_max = 0 - local pow_curr = 0 - if nvm.ele1 and nvm.ele1.gstate and nvm.ele1.galive and nvm.ele1.given then - if nvm.ele1.gstate == RUNNING then - if nvm.ele1.curr_power and nvm.ele1.curr_power > 0 then - pow_max = nvm.ele1.curr_power - else - pow_max = gen.nominal - end - if nvm.ele1.galive > 0 and nvm.ele1.given > 0 then - pow_curr = nvm.ele1.given - end - end - end - return pow_curr, pow_max -end - -local function get_consumer_data(gen) - local nvm = techage.get_nvm(gen.pos) - local pow_max = 0 - local pow_curr = 0 - if nvm.ele1 and nvm.ele1.cstate and nvm.ele1.calive and nvm.ele1.taken then - if nvm.ele1.cstate == RUNNING then - pow_max = gen.nominal - if nvm.ele1.calive > 0 and nvm.ele1.taken > 0 then - pow_curr = nvm.ele1.taken - end - end - end - return pow_curr, pow_max -end - -local function consumer_data(gen_tbl, nominal) - local pow_max = 0 - local pow_curr = 0 - local num_nodes = 0 - - for i,gen in ipairs(gen_tbl or {}) do - if gen.nominal == nominal then - local nvm = techage.get_nvm(gen.pos) - if nvm.ele1 and nvm.ele1.cstate and nvm.ele1.calive and nvm.ele1.taken then - num_nodes = num_nodes + 1 - if nvm.ele1.cstate == RUNNING then - pow_max = pow_max + nominal - if nvm.ele1.calive > 0 and nvm.ele1.taken > 0 then - pow_curr = pow_curr + nvm.ele1.taken - end - end - end - end - end + mem.star = ((mem.star or 0) + 1) % 2 + local star = mem.star == 1 and "*" or "" + local storage_provided = math.max(data.consumed - data.available, 0) + local available = math.max(data.consumed, data.available) - return pow_max, pow_curr, num_nodes -end - -local function storage_load(gen_tbl, nominal) - local load_curr = 0 -- percentage - local num = 0 - - for i,gen in ipairs(gen_tbl or {}) do - if gen.nominal == nominal then - local ndef = techage.NodeDef[techage.get_node_lvm(gen.pos).name] - if ndef and ndef.on_recv_message then - local resp, _ = ndef.on_recv_message(gen.pos, "0", "load") - if type(resp) == "number" then - load_curr = load_curr + resp - num = num + 1 - end - end - end - end - - if num > 0 then - return math.floor(load_curr / num) - else - return 0 - end -end - -local function calc_network_data_type(pos, nvm, gentype) - local pow_max1, pow_curr1, num_nodes1, pow_stored1 - local pow_max2, pow_curr2, num_nodes2, pow_stored2 - local nominal = Gentype2Maxvalue[gentype] - local netw = techage.networks.has_network("ele1", nvm.ele1 and nvm.ele1.netID) or {} - - if gentype == S("Accu Box") or gentype == S("Energy storage") then - pow_max1, pow_curr1, num_nodes1 = generator_data(netw.gen2, nominal) - pow_max2, pow_curr2, num_nodes2 = consumer_data(netw.con2, nominal) - pow_stored1 = storage_load(netw.con2, Gentype2Maxvalue[gentype]).." %" - pow_stored2 = pow_stored1 - elseif gentype == S("Fuel cell cat. 2") then - pow_max1, pow_curr1, num_nodes1 = generator_data(netw.gen2, nominal) - pow_max2, pow_curr2, num_nodes2 = 0, 0, 0 - pow_stored1 = storage_load(netw.gen2, Gentype2Maxvalue[gentype]).." %" - pow_stored2 = "-" - elseif gentype == S("Fuel cell cat. 1") then - pow_max1, pow_curr1, num_nodes1 = generator_data(netw.gen1, nominal) - pow_max2, pow_curr2, num_nodes2 = 0, 0, 0 - pow_stored1 = storage_load(netw.gen1, Gentype2Maxvalue[gentype]).." %" - pow_stored2 = "-" - elseif gentype == S("Electrolyzer") then - pow_max1, pow_curr1, num_nodes1 = 0, 0, 0 - pow_max2, pow_curr2, num_nodes2 = consumer_data(netw.con2, nominal) - pow_stored2 = storage_load(netw.con2, Gentype2Maxvalue[gentype]).." %" - pow_stored1 = "-" - else -- gen1 generators - pow_max1, pow_curr1, num_nodes1 = generator_data(netw.gen1, nominal) - pow_max2, pow_curr2, num_nodes2 = 0, 0, 0 - pow_stored1 = "-" - pow_stored2 = "-" - end - return netw, - {pow_max = pow_max1, pow_curr = pow_curr1, num_nodes = num_nodes1, pow_stored = pow_stored1}, - {pow_max = pow_max2, pow_curr = pow_curr2, num_nodes = num_nodes2, pow_stored = pow_stored2} -end - -local function calc_network_data_total(pos, nvm) - local netw = techage.networks.has_network("ele1", nvm.ele1 and nvm.ele1.netID) or {} - - local pow_max1 = netw.available1 or 0 - local pow_max2 = netw.available2 or 0 - local pow_used1 = netw.on and math.min(netw.needed1 + netw.needed2, netw.available1) or 0 - local pow_used2 = netw.on and math.max(netw.needed1 - pow_used1, -netw.available2) or 0 - local num_nodes1 = #(netw.gen1 or {}) - local num_nodes2 = #(netw.gen2 or {}) - - return netw, - {pow_max = pow_max1, pow_curr = pow_used1, num_nodes = num_nodes1}, - {pow_max = pow_max2, pow_curr = pow_used2, num_nodes = num_nodes2} -end - -local function get_state(netw) - local state = "" - local needed = techage.power.get_con1_sum(netw, "ele1") or 0 - - if #(netw.gen1 or {}) + #(netw.gen2 or {}) == 0 then - state = S("No power grid or running generator!") - elseif needed > (netw.available1 or 0) then - state = S("Probably too many consumers (")..needed.." "..S("ku is needed").."!)" - elseif (netw.num_nodes or 0) < techage.networks.MAX_NUM_NODES then - state = S("Number of power grid blocks")..": "..(netw.num_nodes or 0)..", "..S("Max. needed power")..": "..needed.. " ku" - else - state = S("To many blocks in the power grid!") - end - return state -end - -local function column(x,y, data) - if data.pow_stored then - return - "label["..x..","..(y+0.0)..";"..data.num_nodes.. "]".. - "label["..x..","..(y+0.5)..";"..data.pow_max.. " ku]".. - "label["..x..","..(y+1.0)..";"..data.pow_curr.. " ku]".. - "label["..x..","..(y+1.5)..";"..data.pow_stored.."]" - else - return - "label["..x..","..(y+0.0)..";"..data.num_nodes.. "]".. - "label["..x..","..(y+0.5)..";"..data.pow_max.. " ku]".. - "label["..x..","..(y+1.0)..";"..data.pow_curr.. " ku]" - end -end - -local function formspec_type(pos, nvm) - return "size[5,4]".. - default.gui_bg.. - default.gui_bg_img.. - default.gui_slots.. - "box[0,-0.1;4.8,0.5;#c6e8ff]".. - "label[1.5,-0.1;"..minetest.colorize( "#000000", S("Select type")).."]".. - "dropdown[0,1;5.2;gentype;"..Gentypes..";"..(nvm.gentype_idx or 1).."]".. - "style_type[button;bgcolor=#395c74]".. - "button[0,2.4;5,1;set;"..S("Store").."]" -end - -local function formspec1(pos, nvm) - local gentype = nvm.gentype or S("Power station") - local netw, gen1, gen2 = calc_network_data_type(pos, nvm, gentype) - local _, sum1, sum2 = calc_network_data_total(pos, nvm) - netw.prop = ((netw.prop or 0) + 1) % 2 - local star = netw.prop == 1 and "*" or "" - local state = get_state(netw) - - return "size[11,9]".. + return "size[10,8]".. "tabheader[0,0;tab;status,console;1;;true]".. default.gui_bg.. default.gui_bg_img.. default.gui_slots.. - "box[0,-0.1;10.8,0.5;#c6e8ff]".. - "label[4.5,-0.1;"..minetest.colorize( "#000000", S("Network Data")).."]".. - "label[10.5,-0.1;"..minetest.colorize( "#000000", star).."]".. + "box[0,-0.1;9.8,0.5;#c6e8ff]".. + "label[0.2,-0.1;"..minetest.colorize( "#000000", S("Network Data")).."]".. + "label[9.5,-0.1;"..minetest.colorize( "#000000", star).."]".. + techage.formspec_power_bar(pos, 0.0, 0.7, S("Generator"), data.provided, data.available).. + techage.formspec_power_bar(pos, 2.5, 0.7, S("Consumer"), data.consumed, available).. + techage.formspec_charging_bar(pos, 5.0, 0.7, S("Charging"), data).. + techage.formspec_storage_bar(pos, 7.5, 0.7, S("Storage"), data.curr_load, data.max_capa).. - "style_type[button;bgcolor=#395c74]".. - "button[0,0.7;3,1;config;"..S("Type").."]".. - - "box[0,1.6;10.8,0.4;#c6e8ff]".. - "box[0,2.15;10.8,0.4;#395c74]".. - "box[0,2.65;10.8,0.4;#395c74]".. - "box[0,3.15;10.8,0.4;#395c74]".. - "box[0,3.65;10.8,0.4;#395c74]".. - "label[0.1,1.55;"..minetest.colorize( "#000000", gentype).."]".. - "label[5.7,1.55;"..minetest.colorize( "#000000", S("Output")).."]".. - "label[8.2,1.55;"..minetest.colorize( "#000000", S("Intake")).."]".. - "label[0.1,2.1;"..S("Number blocks:").."]".. - "label[0.1,2.6;"..S("Maximum power:").."]".. - "label[0.1,3.1;"..S("Current power:").."]".. - "label[0.1,3.6;"..S("Energy stored:").."]".. - column(5.7, 2.1, gen1).. - column(8.2, 2.1, gen2).. - - --"box[0,5.3;8.8,0.4;#c6e8ff]".. - "box[0,4.5;10.8,0.4;#c6e8ff]".. - "box[0,5.05;10.8,0.4;#395c74]".. - "box[0,5.55;10.8,0.4;#395c74]".. - "box[0,6.05;10.8,0.4;#395c74]".. - "label[0.1,4.45;"..minetest.colorize( "#000000", S("Power grid total")).."]".. - "label[5.7,4.45;"..minetest.colorize( "#000000", S("Generators")).."]".. - "label[8.2,4.45;"..minetest.colorize( "#000000", S("Storage systems")).."]".. - "label[0.1,5.0;"..S("Number blocks:").."]".. - "label[0.1,5.5;"..S("Maximum power:").."]".. - "label[0.1,6.0;"..S("Current power:").."]".. - column(5.7, 5.0, sum1).. - column(8.2, 5.0, sum2).. - "box[0,7.75;10.8,0.4;#000000]".. - "label[0.1,7.7;"..state.."]" + row(1, S("Number of network nodes:"), netw.num_nodes or 0) .. + row(2, S("Number of generators:"), #(netw.gen or {})) .. + row(3, S("Number of consumers:"), #(netw.con or {})) .. + row(4, S("Number of storage systems:"), #(netw.sto or {})) end -local function formspec2(pos, mem) +local function formspec2(pos) + local mem = techage.get_mem(pos) local meta = M(pos) local output = meta:get_string("output") local command = mem.cmnd or "help" output = minetest.formspec_escape(output) output = output:gsub("\n", ",") - return "size[11,9]".. + return "size[10,8]".. "tabheader[0,0;tab;status,console;2;;true]".. default.gui_bg.. default.gui_bg_img.. default.gui_slots.. - "box[0,-0.1;10.8,0.5;#c6e8ff]".. - "label[4.5,-0.1;"..minetest.colorize( "#000000", S("Network Data")).."]".. - "style_type[table,field;font=mono]".. - "table[0,0.5;10.8,7.8;output;"..output..";200]".. - "field[0.4,8.7;8.6,1;cmnd;;"..command.."]" .. + "box[0,-0.1;9.8,0.5;#c6e8ff]".. + "label[0.2,-0.1;"..minetest.colorize( "#000000", S("Network Data")).."]".. + --"style_type[table,field;font=mono]".. + "table[0,0.5;9.8,6.8;output;"..output..";200]".. + "field[0.4,7.7;7.6,1;cmnd;;"..command.."]" .. "field_close_on_enter[cmnd;false]".. - "button[8.9,8.4;2,1;enter;"..S("Enter").."]" + "button[7.9,7.4;2,1;enter;"..S("Enter").."]" end -local function generators(pos, gen_tbl) +local function generators(pos) local tbl = {} - for _, item in ipairs(gen_tbl) do - if item and item.pos then - local node = techage.get_node_lvm(item.pos) - local ndef = minetest.registered_nodes[node.name] - local name = short_node_name(item.nominal) - local spos = P2S(item.pos) - local pow_curr, pow_max = get_generator_data(item, ndef) - if Storage[name] then - local load_percent = 0 - local tdef = techage.NodeDef[node.name] - if tdef and tdef.on_recv_message then - load_percent = tdef.on_recv_message(item.pos, "0", "load") or 0 - end - local s = string.format("%-16s %s = %u/%u ku (%u %%)", - spos, name, pow_curr, pow_max, load_percent) - tbl[#tbl + 1] = s - else - local s = string.format("%-16s %s = %u/%u ku", spos, name, pow_curr, pow_max) - tbl[#tbl + 1] = s - end + local outdir = M(pos):get_int("outdir") + local resp = control.request(pos, Cable, outdir, "gen", "info") + for _, item in ipairs(resp) do + local name = item.type .. " (" .. item.number .. ")" + if item.running then + local s = string.format("%s (%s): %s/%u ku (%s)", + item.type, item.number, techage.round(item.provided), item.available, item.termpoint) + tbl[#tbl + 1] = s + else + local s = string.format("%s (%s): off", + item.type, item.number) + tbl[#tbl + 1] = s end end + table.sort(tbl) return table.concat(tbl, "\n") end -local function consumers(pos, gen_tbl) +local function storages(pos) local tbl = {} - for _, item in ipairs(gen_tbl) do - if item and item.pos then - local node = techage.get_node_lvm(item.pos) - local ndef = minetest.registered_nodes[node.name] - local name = short_node_name(item.nominal) - local spos = P2S(item.pos) - local pow_curr, pow_max = get_consumer_data(item, ndef) - if Storage[name] then - local load_percent = 0 - local tdef = techage.NodeDef[node.name] - if tdef and tdef.on_recv_message then - load_percent = tdef.on_recv_message(item.pos, "0", "load") or 0 - end - local s = string.format("%-16s %s = %u/%u ku (%u %%)", - spos, name, pow_curr, pow_max, load_percent) - tbl[#tbl + 1] = s - else - local s = string.format("%-16s %s = %u/%u ku", spos, name, pow_curr, pow_max) - tbl[#tbl + 1] = s - end + local outdir = M(pos):get_int("outdir") + local resp = control.request(pos, Cable, outdir, "sto", "info") + for _, item in ipairs(resp) do + local name = item.type .. " (" .. item.number .. ")" + if item.running then + local s = string.format("%s (%s): %s/%s kud", + item.type, item.number, + techage.round(item.load / techage.CYCLES_PER_DAY), + techage.round(item.capa / techage.CYCLES_PER_DAY)) + tbl[#tbl + 1] = s + else + local s = string.format("%s (%s): %s/%s kud (off)", + item.type, item.number, + techage.round(item.load / techage.CYCLES_PER_DAY), + techage.round(item.capa / techage.CYCLES_PER_DAY)) + tbl[#tbl + 1] = s end end + table.sort(tbl) return table.concat(tbl, "\n") end -local function number_nodes(pos, netw) - return - "num. generators cat. 1: " .. #(netw.gen1 or {}) .. "\n" .. - "num. generators cat. 2: " .. #(netw.gen2 or {}) .. "\n" .. - "num. consumers cat. 1: " .. #(netw.con1 or {}) .. "\n" .. - "num. consumers cat. 2: " .. #(netw.con2 or {}) -end - -local function power_network(pos, netw) - return - "pow. generators cat. 1: " .. (netw.available1 or 0) .. " ku\n" .. - "pow. generators cat. 2: " .. (netw.available2 or 0) .. " ku\n" .. - "pow. consumers cat. 1: " .. (netw.needed1 or 0) .. " ku\n" .. - "pow. consumers cat. 2: " .. (netw.needed2 or 0) .. " ku" -end - - local function output(pos, command, text) local meta = M(pos) text = meta:get_string("output") .. "\n$ " .. command .. "\n" .. (text or "") @@ -446,26 +150,16 @@ local function command(pos, nvm, command) if command then command = command:sub(1,80) command = string.trim(command) + local cmd, data = unpack(string.split(command, " ", false, 1)) - if command == "cls" then + if cmd == "cls" then meta:set_string("output", "") - elseif command == "help" then + elseif cmd == "help" then output(pos, command, HELP) - elseif command == "gen1" then - local netw = techage.networks.has_network("ele1", nvm.ele1 and nvm.ele1.netID) or {} - output(pos, command, generators(pos, netw.gen1 or {})) - elseif command == "gen2" then - local netw = techage.networks.has_network("ele1", nvm.ele1 and nvm.ele1.netID) or {} - output(pos, command, generators(pos, netw.gen2 or {})) - elseif command == "con2" then - local netw = techage.networks.has_network("ele1", nvm.ele1 and nvm.ele1.netID) or {} - output(pos, command, consumers(pos, netw.con2 or {})) - elseif command == "num" then - local netw = techage.networks.has_network("ele1", nvm.ele1 and nvm.ele1.netID) or {} - output(pos, command, number_nodes(pos, netw)) - elseif command == "pow" then - local netw = techage.networks.has_network("ele1", nvm.ele1 and nvm.ele1.netID) or {} - output(pos, command, power_network(pos, netw)) + elseif cmd == "gen" then + output(pos, command, generators(pos)) + elseif cmd == "sto" then + output(pos, command, storages(pos)) elseif command ~= "" then output(pos, command, "") end @@ -492,33 +186,32 @@ minetest.register_node("techage:ta3_power_terminal", { }, after_place_node = function(pos) - local nvm = techage.get_nvm(pos) M(pos):set_int("outdir", networks.side_to_outdir(pos, "B")) Cable:after_place_node(pos) - M(pos):set_string("formspec", formspec1(pos, nvm)) + M(pos):set_string("formspec", formspec1(pos)) end, after_dig_node = function(pos) Cable:after_dig_node(pos) techage.del_mem(pos) end, - tubelib2_on_update2 = function(pos, outdir, tlib2, node) - power.update_network(pos, outdir, tlib2) - end, on_rightclick = function(pos, node, clicker) local mem = techage.get_mem(pos) if mem.active_formspec == 2 then - M(pos):set_string("formspec", formspec2(pos, mem)) + M(pos):set_string("formspec", formspec2(pos)) else - local nvm = techage.get_nvm(pos) - M(pos):set_string("formspec", formspec1(pos, nvm)) + M(pos):set_string("formspec", formspec1(pos)) + minetest.get_node_timer(pos):start(CYCLE_TIME) + techage.set_activeformspec(pos, clicker) + mem.active_formspec = 1 end end, on_timer = function(pos, elapsed) - local nvm = techage.get_nvm(pos) if techage.is_activeformspec(pos) then - M(pos):set_string("formspec", formspec1(pos, nvm)) + local outdir = M(pos):get_int("outdir") + local data = power.get_network_data(pos, Cable, outdir) + M(pos):set_string("formspec", formspec1(pos, data)) + return true end - return true end, on_receive_fields = function(pos, formname, fields, player) @@ -533,34 +226,20 @@ minetest.register_node("techage:ta3_power_terminal", { mem.cmnd = "" M(pos):set_string("formspec", formspec2(pos, mem)) mem.cmnd = fields.cmnd - elseif fields.config then - techage.reset_activeformspec(pos, player) - M(pos):set_string("formspec", formspec_type(pos, nvm)) - elseif fields.set then - nvm.gentype = fields.gentype - nvm.gentype_idx = Gentype2Idx[fields.gentype] or 1 - techage.set_activeformspec(pos, player) - M(pos):set_string("formspec", formspec1(pos, nvm)) elseif fields.tab == "1" then - M(pos):set_string("formspec", formspec1(pos, nvm)) + M(pos):set_string("formspec", formspec1(pos)) techage.set_activeformspec(pos, player) + minetest.get_node_timer(pos):start(CYCLE_TIME) mem.active_formspec = 1 elseif fields.tab == "2" then - M(pos):set_string("formspec", formspec2(pos, mem)) + M(pos):set_string("formspec", formspec2(pos)) techage.reset_activeformspec(pos, player) mem.active_formspec = 2 elseif fields.key_up and mem.cmnd then - M(pos):set_string("formspec", formspec2(pos, mem)) + M(pos):set_string("formspec", formspec2(pos)) end end, - networks = { - ele1 = { - sides = {B = 1}, -- Cable connection side - ntype = "term", - }, - }, - paramtype2 = "facedir", paramtype = "light", use_texture_alpha = techage.CLIP, @@ -571,7 +250,7 @@ minetest.register_node("techage:ta3_power_terminal", { sounds = default.node_sound_metal_defaults(), }) -Cable:add_secondary_node_names({"techage:ta3_power_terminal"}) +power.register_nodes({"techage:ta3_power_terminal"}, Cable, "con", {"B"}) minetest.register_craft({ output = "techage:ta3_power_terminal", diff --git a/techage/power/powerswitch.lua b/techage/power/powerswitch.lua index 0b55363..4cf3577 100644 --- a/techage/power/powerswitch.lua +++ b/techage/power/powerswitch.lua @@ -18,6 +18,7 @@ local M = minetest.get_meta local S = techage.S local Cable = techage.ElectricCable +local power = networks.power local Param2ToDir = { [0] = 6, @@ -28,9 +29,16 @@ local Param2ToDir = { [5] = 3, } -local function is_switchbox(pos) - return techage.get_node_lvm(pos).name == "techage:powerswitch_box" or - M(pos):get_string("techage_hidden_nodename") == "techage:powerswitch_box" +local function sign_in(pos, node) + local dir = Param2ToDir[node.param2] + local pos2 = tubelib2.get_pos(pos, dir) + M(pos2):set_int("switch_sign_in", 1) +end + +local function sign_off(pos, node) + local dir = Param2ToDir[node.param2] + local pos2 = tubelib2.get_pos(pos, dir) + M(pos2):set_int("switch_sign_in", 0) end local function switch_on(pos, node, clicker, name) @@ -47,14 +55,8 @@ local function switch_on(pos, node, clicker, name) local dir = Param2ToDir[node.param2] local pos2 = tubelib2.get_pos(pos, dir) - if is_switchbox(pos2) then - if M(pos2):get_int("tl2_param2_copy") == 0 then - M(pos2):set_int("tl2_param2", techage.get_node_lvm(pos2).param2) - else - M(pos2):set_int("tl2_param2", M(pos2):get_int("tl2_param2_copy")) - end - Cable:after_place_tube(pos2, clicker) - end + techage.legacy_switches(pos2) + power.turn_switch_on(pos2, Cable, "techage:powerswitch_box_off", "techage:powerswitch_box_on") end local function switch_off(pos, node, clicker, name) @@ -72,13 +74,8 @@ local function switch_off(pos, node, clicker, name) local dir = Param2ToDir[node.param2] local pos2 = tubelib2.get_pos(pos, dir) - if is_switchbox(pos2) then - local node2 = techage.get_node_lvm(pos2) - node2.param2 = M(pos2):get_int("tl2_param2") - M(pos2):set_int("tl2_param2_copy", M(pos2):get_int("tl2_param2")) - M(pos2):set_int("tl2_param2", 0) - Cable:after_dig_tube(pos2, node2) - end + techage.legacy_switches(pos2) + power.turn_switch_off(pos2, Cable, "techage:powerswitch_box_off", "techage:powerswitch_box_on") end @@ -106,12 +103,14 @@ minetest.register_node("techage:powerswitch", { meta:set_string("infotext", S("TA Power Switch").." "..number) local node = minetest.get_node(pos) switch_on(pos, node, placer, "techage:powerswitch_on") + sign_in(pos, node) end, on_rightclick = function(pos, node, clicker) switch_on(pos, node, clicker, "techage:powerswitch_on") end, + after_dig_node = sign_off, on_rotate = screwdriver.disallow, paramtype = "light", use_texture_alpha = techage.CLIP, @@ -143,6 +142,7 @@ minetest.register_node("techage:powerswitch_on", { switch_off(pos, node, clicker, "techage:powerswitch") end, + after_dig_node = sign_off, drop = "techage:powerswitch", on_rotate = screwdriver.disallow, paramtype = "light", @@ -178,12 +178,14 @@ minetest.register_node("techage:powerswitchsmall", { meta:set_string("infotext", S("TA Power Switch Small").." "..number) local node = minetest.get_node(pos) switch_on(pos, node, placer, "techage:powerswitchsmall_on") + sign_in(pos, node) end, on_rightclick = function(pos, node, clicker) switch_on(pos, node, clicker, "techage:powerswitchsmall_on") end, + after_dig_node = sign_off, on_rotate = screwdriver.disallow, paramtype = "light", use_texture_alpha = techage.CLIP, @@ -215,6 +217,7 @@ minetest.register_node("techage:powerswitchsmall_on", { switch_off(pos, node, clicker, "techage:powerswitchsmall") end, + after_dig_node = sign_off, drop = "techage:powerswitchsmall", on_rotate = screwdriver.disallow, paramtype = "light", diff --git a/techage/power/powerswitchbox.lua b/techage/power/powerswitchbox.lua index 1d63318..523c294 100644 --- a/techage/power/powerswitchbox.lua +++ b/techage/power/powerswitchbox.lua @@ -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,32 +15,59 @@ 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 = function(pos) return minetest.get_node(pos).name end +local N = techage.get_node_lvm local S = techage.S local Cable = techage.ElectricCable +local power = networks.power --- primary power node -minetest.register_node("techage:powerswitch_box", { - description = S("TA Power Switch Box"), - tiles = { - -- up, down, right, left, back, front - 'techage_electric_switch.png^[transformR90', - 'techage_electric_switch.png^[transformR90', - 'techage_electric_switch.png', - 'techage_electric_switch.png', - 'techage_electric_junction.png', - 'techage_electric_junction.png', +local node_box = { + type = "fixed", + fixed = { + { -1/4, -1/4, -2/4, 1/4, 1/4, 2/4}, }, +} - drawtype = "nodebox", - node_box = { - type = "fixed", - fixed = { - { -1/4, -1/4, -2/4, 1/4, 1/4, 2/4}, - }, - }, +function techage.legacy_switches(pos) + local meta = M(pos) + local node = N(pos) + if node.name == "techage:powerswitch_box" then + if meta:get_int("netw_param2") == 0 then + node.name = "techage:powerswitch_box_off" + else + node.name = "techage:powerswitch_box_on" + end + minetest.swap_node(pos, node) + elseif meta:get_string("netw_name") == "techage:powerswitch_box" then + if meta:get_int("netw_param2") == 0 then + meta:set_string("netw_name", "techage:powerswitch_box_off") + else + meta:set_string("netw_name", "techage:powerswitch_box_on") + end + end + + if meta:contains("tl2_param2_copy") then + meta:set_string("netw_param2_copy", meta:get_string("tl2_param2_copy")) + meta:set_string("tl2_param2_copy", "") + end +end + + +-- The on-switch is a "primary node" like cables +minetest.register_node("techage:powerswitch_box_on", { + description = S("TA Power Switch Box"), + paramtype = "light", + drawtype = "nodebox", + node_box = node_box, + tiles = { + "techage_electric_switch.png^[transformR90", + "techage_electric_switch.png^[transformR90", + "techage_electric_switch.png", + "techage_electric_switch.png", + "techage_electric_junction.png", + "techage_electric_junction.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) @@ -48,23 +75,71 @@ minetest.register_node("techage:powerswitch_box", { end return false end, - + on_rightclick = function(pos, node, clicker) + techage.legacy_switches(pos) + if M(pos):get_int("switch_sign_in") ~= 1 then + if power.turn_switch_off(pos, Cable, "techage:powerswitch_box_off", "techage:powerswitch_box_on") then + minetest.sound_play("doors_glass_door_open", { + pos = pos, + gain = 1, + max_hear_distance = 5}) + end + end + end, after_dig_node = function(pos, oldnode, oldmetadata, digger) Cable:after_dig_tube(pos, oldnode, oldmetadata) end, - - paramtype = "light", + paramtype2 = "facedir", + on_rotate = screwdriver.disallow, use_texture_alpha = techage.CLIP, sunlight_propagates = true, - on_rotate = screwdriver.disallow, -- important! - paramtype2 = "facedir", - groups = {choppy=2, cracky=2, crumbly=2, techage_trowel = 1}, is_ground_content = false, - sounds = default.node_sound_wood_defaults(), + groups = {choppy=2, cracky=2, crumbly=2, techage_trowel = 1}, + sounds = default.node_sound_defaults(), }) +-- The off-switch is a "secondary node" without connection sides +minetest.register_node("techage:powerswitch_box_off", { + description = S("TA Power Switch Box"), + paramtype = "light", + drawtype = "nodebox", + node_box = node_box, + tiles = { + "techage_electric_switch_off.png^[transformR90", + "techage_electric_switch_off.png^[transformR90", + "techage_electric_switch_off.png", + "techage_electric_switch_off.png", + "techage_electric_junction.png", + "techage_electric_junction.png", + }, + on_rightclick = function(pos, node, clicker) + techage.legacy_switches(pos) + if M(pos):get_int("switch_sign_in") ~= 1 then + if power.turn_switch_on(pos, Cable, "techage:powerswitch_box_off", "techage:powerswitch_box_on") then + minetest.sound_play("doors_glass_door_open", { + pos = pos, + gain = 1, + max_hear_distance = 5}) + end + 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 = techage.CLIP, + sunlight_propagates = true, + is_ground_content = false, + drop = "techage:powerswitch_box_on", + groups = {choppy=2, cracky=2, crumbly=2, techage_trowel = 1, not_in_creative_inventory = 1}, + sounds = default.node_sound_defaults(), +}) + +power.register_nodes({"techage:powerswitch_box_off"}, Cable, "con", {}) + minetest.register_craft({ - output = "techage:powerswitch_box", + output = "techage:powerswitch_box_on", recipe = { {"", "basic_materials:plastic_sheet", ""}, {"techage:electric_cableS", "basic_materials:copper_wire", "techage:electric_cableS"}, diff --git a/techage/power/powerswitchbox_legacy.lua b/techage/power/powerswitchbox_legacy.lua new file mode 100644 index 0000000..60dab1e --- /dev/null +++ b/techage/power/powerswitchbox_legacy.lua @@ -0,0 +1,71 @@ +--[[ + + TechAge + ======= + + Copyright (C) 2019-2021 Joachim Stolberg + + AGPL v3 + See LICENSE.txt for more information + + TA3 Old Power Switch Box +]]-- + +-- 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 = function(pos) return minetest.get_node(pos).name end +local S = techage.S + +local Cable = techage.ElectricCable +local power = networks.power + +local node_box = { + type = "fixed", + fixed = { + { -1/4, -1/4, -2/4, 1/4, 1/4, 2/4}, + }, +} + +-- legacy node +minetest.register_node("techage:powerswitch_box", { + description = S("TA Power Switch Box"), + tiles = { + -- up, down, right, left, back, front + 'techage_electric_switch.png^[transformR90', + 'techage_electric_switch.png^[transformR90', + 'techage_electric_switch.png', + 'techage_electric_switch.png', + 'techage_electric_junction.png', + 'techage_electric_junction.png', + }, + + drawtype = "nodebox", + node_box = node_box, + + after_place_node = function(pos, placer, itemstack, pointed_thing) + local node = minetest.get_node(pos) + minetest.swap_node(pos, {name = "techage:powerswitch_box_on", param2 = node.param2}) + + 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, + + paramtype = "light", + use_texture_alpha = techage.CLIP, + sunlight_propagates = true, + on_rotate = screwdriver.disallow, -- important! + paramtype2 = "facedir", + drop = "techage:powerswitch_box_on", + groups = {choppy=2, cracky=2, crumbly=2, techage_trowel = 1, not_in_creative_inventory = 1}, + is_ground_content = false, + sounds = default.node_sound_wood_defaults(), +}) diff --git a/techage/power/schedule.lua b/techage/power/schedule.lua deleted file mode 100644 index 5e530a5..0000000 --- a/techage/power/schedule.lua +++ /dev/null @@ -1,83 +0,0 @@ ---[[ - - TechAge - ======= - - Copyright (C) 2019-2020 Joachim Stolberg - - AGPL v3 - See LICENSE.txt for more information - - Global power Job Scheduler - -]]-- - --- for lazy programmers -local P2P = 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 = function(pos) return minetest.get_node(pos).name end -local HEX = function(val) return string.format("%XH", val) end - -local power = techage.power -local networks = techage.networks - -local CYCLE_TIME = 1 - -techage.schedule = {} - -local JobTable = {} -local JobQueue = {} -local first = 0 -local last = -1 - -techage.SystemTime = 0 - -local function push(item) - last = last + 1 - item.time = techage.SystemTime + CYCLE_TIME - JobQueue[last] = item -end - -local function pop() - if first > last then return end - local item = JobQueue[first] - if item.time <= techage.SystemTime then - JobQueue[first] = nil -- to allow garbage collection - first = first + 1 - return item - end -end - --- Scheduler -minetest.register_globalstep(function(dtime) - techage.SystemTime = techage.SystemTime + dtime - local item = pop() - local t = minetest.get_us_time() - while item do - local network = networks.peek_network(item.tube_type, item.netID) - if network and network.alive and network.alive >= 0 then - power.power_distribution(network, item.tube_type, item.netID, CYCLE_TIME) - network.alive = network.alive - 1 - push(item) - else - JobTable[item.netID] = nil - networks.delete_network(item.tube_type, item.netID) - end - item = pop() - end - t = minetest.get_us_time() - t - if t > 10000 then - minetest.log("action", "[TA Schedule] duration="..t.."us") - end -end) - -function techage.schedule.start(tube_type, netID) - if not JobTable[netID] then - local network = networks.peek_network(tube_type, netID) - power.power_distribution(network, tube_type, netID, CYCLE_TIME/2) - network.alive = network.alive - 1 - push({tube_type = tube_type, netID = netID}) - JobTable[netID] = true - end -end diff --git a/techage/power/steam_pipe.lua b/techage/power/steam_pipe.lua index e667255..040d4f9 100644 --- a/techage/power/steam_pipe.lua +++ b/techage/power/steam_pipe.lua @@ -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 diff --git a/techage/power/ta4_cable.lua b/techage/power/ta4_cable.lua index cbd2760..6650e05 100644 --- a/techage/power/ta4_cable.lua +++ b/techage/power/ta4_cable.lua @@ -18,7 +18,7 @@ local P2S = minetest.pos_to_string local M = minetest.get_meta local S = techage.S -local power = techage.power +local power = networks.power local ELE2_MAX_CABLE_LENGHT = 200 @@ -40,13 +40,10 @@ local Cable = tubelib2.Tube:new({ end, }) ---Cable:register_on_tube_update(function(node, pos, out_dir, peer_pos, peer_in_dir) --- local ndef = minetest.registered_nodes[node.name] --- if ndef and ndef.after_tube_update then --- minetest.registered_nodes[node.name].after_tube_update(node, pos, out_dir, peer_pos, peer_in_dir) --- end ---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("techage:ta4_power_cableS", { description = S("TA4 Low Power Cable"), @@ -155,17 +152,11 @@ minetest.register_node("techage:ta4_power_box", { Cable:after_place_node(pos) end, tubelib2_on_update2 = function(pos, dir1, tlib2, node) - power.update_network(pos, nil, tlib2) + power.update_network(pos, 0, tlib2, node) end, after_dig_node = function(pos, oldnode, oldmetadata, digger) Cable:after_dig_node(pos) end, - networks = { - ele2 = { - sides = {L=1, R=1, F=1, B=1}, - ntype = "junc", - }, - }, on_rotate = screwdriver.disallow, -- important! paramtype = "light", @@ -176,7 +167,7 @@ minetest.register_node("techage:ta4_power_box", { sounds = default.node_sound_defaults(), }) -Cable:add_secondary_node_names({"techage:ta4_power_box"}) +power.register_nodes({"techage:ta4_power_box"}, Cable, "junc", {"L", "R", "F", "B"}) minetest.register_craft({ output = "techage:ta4_power_cableS 8", diff --git a/techage/recipe_checker.lua b/techage/recipe_checker.lua index f8ee53a..204b1fa 100644 --- a/techage/recipe_checker.lua +++ b/techage/recipe_checker.lua @@ -22,8 +22,10 @@ minetest.after(1, function() --print(dump(recipe.items)) local key = recipe_key(recipe.items) if Recipes[key] then - local text = Recipes[key].." and "..name.." have the same incredients" - minetest.log("error", text) + if not string.find(name, "slab") and not string.find(name, "stair") then + local text = Recipes[key].." and "..name.." have the same incredients" + minetest.log("error", text) + end end Recipes[key] = name end diff --git a/techage/solar/inverter.lua b/techage/solar/inverter.lua index 9930e31..d22afc0 100644 --- a/techage/solar/inverter.lua +++ b/techage/solar/inverter.lua @@ -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,45 +20,53 @@ local S2P = minetest.string_to_pos local Cable = techage.ElectricCable local Solar = techage.TA4_Cable -local power = techage.power -local networks = techage.networks +local power = networks.power +local control = networks.control local CYCLE_TIME = 2 local PWR_PERF = 100 +local COUNTDOWN_TICKS = 1 local function determine_power(pos, nvm) -- determine DC node position local outdir = M(pos):get_int("leftdir") - local max_power, num_inverter = power.get_power(pos, outdir, Solar, "techage:ta4_solar_inverter") - if num_inverter == 1 then + local netw = networks.get_network_table(pos, Solar, outdir) or {} + local num_inv = #(netw.con or {}) + local max_power = 0 + for _, power in ipairs(control.request(pos, Solar, outdir, "junc", "power")) do + max_power = max_power + power + end + + if num_inv == 1 then -- only one inverter is allowed nvm.max_power = math.min(PWR_PERF, max_power) else nvm.max_power = 0 end - return max_power, num_inverter + return max_power, num_inv end -local function determine_power_from_time_to_time(pos, nvm) +local function has_dc_power(pos, nvm) local time = minetest.get_timeofday() or 0 if time < 6.00/24.00 or time > 18.00/24.00 then nvm.ticks = 0 nvm.max_power = 0 - return + return false end nvm.ticks = nvm.ticks or 0 - if (nvm.ticks % 10) == 0 then -- calculate max_power not to often + if (nvm.ticks % 30) == 0 then -- calculate max_power not to often determine_power(pos, nvm) else nvm.max_power = nvm.max_power or 0 end nvm.ticks = nvm.ticks + 1 + return nvm.max_power > 0 end local function formspec(self, pos, nvm) local max_power = nvm.max_power or 0 - local delivered = nvm.delivered or 0 + local provided = nvm.provided or 0 local arrow = "image[2.5,1.5;1,1;techage_form_arrow_bg.png^[transformR270]" - if nvm.running then + if techage.is_running(nvm) then arrow = "image[2.5,1.5;1,1;techage_form_arrow_fg.png^[transformR270]" end return "size[6,4]".. @@ -67,8 +75,8 @@ local function formspec(self, pos, nvm) default.gui_slots.. "box[0,-0.1;5.8,0.5;#c6e8ff]".. "label[2.5,-0.1;"..minetest.colorize( "#000000", S("Inverter")).."]".. - power.formspec_label_bar(pos, 0, 0.8, S("Power DC"), PWR_PERF, max_power).. - power.formspec_label_bar(pos, 3.5, 0.8, S("Power AC"), max_power, delivered).. + techage.formspec_power_bar(pos, 0, 0.8, S("Power DC"), max_power, PWR_PERF).. + techage.formspec_power_bar(pos, 3.5, 0.8, S("Power AC"), provided, max_power).. arrow.. "image_button[2.5,3;1,1;".. self:get_state_button_image(nvm) ..";state_button;]".. "tooltip[2.5,3;1,1;"..self:get_state_tooltip(nvm).."]" @@ -76,30 +84,31 @@ end local function can_start(pos, nvm, state) local max_power, num_inverter = determine_power(pos, nvm) - if num_inverter > 1 then return "solar network error" end - if max_power == 0 then return "no solar power" end + if num_inverter > 1 then return S("solar network error") end + if max_power == 0 then return S("no solar power") end return true end local function start_node(pos, nvm, state) - nvm.running = true - nvm.delivered = 0 + local meta = M(pos) + nvm.provided = 0 nvm.ticks = 0 - local outdir = M(pos):get_int("outdir") - power.generator_start(pos, Cable, CYCLE_TIME, outdir, nvm.max_power) + local outdir = meta:get_int("outdir") + power.start_storage_calc(pos, Cable, outdir) + techage.evaluate_charge_termination(nvm, meta) end local function stop_node(pos, nvm, state) - nvm.running = false - nvm.delivered = 0 + nvm.provided = 0 + nvm.running = nil -- legacy local outdir = M(pos):get_int("outdir") - power.generator_stop(pos, Cable, outdir) + power.start_storage_calc(pos, Cable, outdir) end local State = techage.NodeStates:new({ node_name_passive = "techage:ta4_solar_inverter", cycle_time = CYCLE_TIME, - standby_ticks = 0, + standby_ticks = 2, formspec_func = formspec, infotext_name = S("TA4 Solar Inverter"), can_start = can_start, @@ -109,18 +118,30 @@ local State = techage.NodeStates:new({ local function node_timer(pos, elapsed) local nvm = techage.get_nvm(pos) - determine_power_from_time_to_time(pos, nvm) - --if nvm.max_power > 0 then - local outdir = M(pos):get_int("outdir") - nvm.delivered = power.generator_alive(pos, Cable, CYCLE_TIME, outdir, nvm.max_power) - --else - --nvm.delivered = 0 - --end + local running = techage.is_running(nvm) + local has_power = has_dc_power(pos, nvm) + if running and not has_power then + State:standby(pos, nvm) + stop_node(pos, nvm, State) + elseif not running and has_power 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, nvm.max_power, tp1, tp2) + local val = power.get_storage_load(pos, Cable, outdir, nvm.max_power) + if val > 0 then + nvm.load = val + end + State:keep_running(pos, nvm, COUNTDOWN_TICKS) + end if techage.is_activeformspec(pos) then M(pos):set_string("formspec", formspec(State, pos, nvm)) end - State:trigger_state(pos, nvm) - return true + return State:is_active(nvm) end local function on_receive_fields(pos, formname, fields, player) @@ -129,10 +150,6 @@ local function on_receive_fields(pos, formname, fields, player) end local nvm = techage.get_nvm(pos) State:state_button_event(pos, nvm, fields) - - if fields.update then - M(pos):set_string("formspec", formspec(State, pos, nvm)) - end end local function on_rightclick(pos, node, clicker) @@ -142,8 +159,11 @@ local function on_rightclick(pos, node, clicker) M(pos):set_string("formspec", formspec(State, pos, nvm)) 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) / nvm.max_power, perf = nvm.max_power, capa = nvm.max_power * 2} + end end minetest.register_node("techage:ta4_solar_inverter", { @@ -179,38 +199,48 @@ minetest.register_node("techage:ta4_solar_inverter", { techage.del_mem(pos) end, - tubelib2_on_update2 = tubelib2_on_update2, on_receive_fields = on_receive_fields, on_rightclick = on_rightclick, on_timer = node_timer, - networks = { - ele1 = { - sides = {R = 1}, - ntype = "gen1", - nominal = PWR_PERF, - regenerative = true, - }, - ele2 = { - sides = {L = 1}, - ntype = "con1", - }, - } + get_generator_data = get_generator_data, + ta3_formspec = techage.generator_settings("ta4", PWR_PERF) }) -Cable:add_secondary_node_names({"techage:ta4_solar_inverter"}) -Solar:add_secondary_node_names({"techage:ta4_solar_inverter"}) +power.register_nodes({"techage:ta4_solar_inverter"}, Cable, "gen", {"R"}) +power.register_nodes({"techage:ta4_solar_inverter"}, Solar, "con", {"L"}) techage.register_node({"techage:ta4_solar_inverter"}, { on_recv_message = function(pos, src, topic, payload) local nvm = techage.get_nvm(pos) if topic == "delivered" then - return math.floor((nvm.delivered or 0) + 0.5) + return math.floor((nvm.provided or 0) + 0.5) else return State:on_receive_message(pos, topic, payload) end end, }) +control.register_nodes({"techage:ta4_solar_inverter"}, { + 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("TA4 Solar Inverter"), + number = meta:get_string("node_number") or "", + running = techage.is_running(nvm) or false, + available = nvm.max_power or 0, + provided = nvm.provided or 0, + termpoint = meta:get_string("termpoint"), + } + end + return false + end, + } +) + minetest.register_craft({ output = "techage:ta4_solar_inverter", recipe = { @@ -220,11 +250,6 @@ minetest.register_craft({ }, }) ---minetest.register_craft({ --- output = "techage:ta4_solar_inverterDC", --- recipe = { --- {'default:steel_ingot', 'dye:green', 'default:steel_ingot'}, --- {'techage:ta4_power_cableS', '', ''}, --- {'default:steel_ingot', "techage:baborium_ingot", 'default:steel_ingot'}, --- }, ---}) +techage.register_node_for_v1_transition({"techage:ta4_solar_inverter"}, function(pos, node) + power.update_network(pos, nil, Solar) +end) diff --git a/techage/solar/minicell.lua b/techage/solar/minicell.lua index bd3713f..b12fba7 100644 --- a/techage/solar/minicell.lua +++ b/techage/solar/minicell.lua @@ -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 @@ -22,7 +22,7 @@ local PWR_PERF = 1 local PWR_CAPA = 2400 -- ticks (2s) with 1 ku ==> 80 min = 4 game days local Cable = techage.ElectricCable -local power = techage.power +local power = networks.power local function node_timer(pos, elapsed) local nvm = techage.get_nvm(pos) @@ -34,7 +34,6 @@ local function node_timer(pos, elapsed) if t > 0.25 and t < 0.75 then if nvm.providing then - power.generator_stop(pos, Cable, 5) nvm.providing = false nvm.provided = 0 end @@ -44,14 +43,14 @@ local function node_timer(pos, elapsed) else if nvm.capa > 0 then if not nvm.providing then - power.generator_start(pos, Cable, CYCLE_TIME, 5) + power.start_storage_calc(pos, Cable, 5) nvm.providing = true else - nvm.provided = power.generator_alive(pos, Cable, CYCLE_TIME, 5) + nvm.provided = power.provide_power(pos, Cable, 5, PWR_PERF) nvm.capa = nvm.capa - nvm.provided end else - power.generator_stop(pos, Cable, 5) + power.start_storage_calc(pos, Cable, 5) nvm.providing = false nvm.provided = 0 nvm.capa = 0 @@ -78,18 +77,6 @@ local function after_dig_node(pos, oldnode, oldmetadata) 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 = {D = 1}, - ntype = "gen1", - nominal = PWR_PERF, - }, -} - minetest.register_node("techage:ta4_solar_minicell", { description = S("TA4 Streetlamp Solar Cell"), tiles = { @@ -114,11 +101,9 @@ minetest.register_node("techage:ta4_solar_minicell", { after_place_node = after_place_node, after_dig_node = after_dig_node, on_timer = node_timer, - tubelib2_on_update2 = tubelib2_on_update2, - networks = net_def, }) -Cable:add_secondary_node_names({"techage:ta4_solar_minicell"}) +power.register_nodes({"techage:ta4_solar_minicell"}, Cable, "gen", {"D"}) techage.register_node({"techage:ta4_solar_minicell"}, { on_recv_message = function(pos, src, topic, payload) diff --git a/techage/solar/solarcell.lua b/techage/solar/solarcell.lua index e303f90..96a94ce 100644 --- a/techage/solar/solarcell.lua +++ b/techage/solar/solarcell.lua @@ -20,7 +20,8 @@ local S = techage.S local PWR_PERF = 3 local Cable = techage.TA4_Cable -local power = techage.power +local power = networks.power +local control = networks.control local function temperature(pos) local data = minetest.get_biome_data(pos) @@ -32,7 +33,7 @@ end -- return the required param2 for solar modules local function get_param2(pos, side) - local dir = techage.networks.side_to_outdir(pos, side) + local dir = networks.side_to_outdir(pos, side) return (dir + 1) % 4 end @@ -89,25 +90,9 @@ local function after_dig_node(pos, oldnode) end local function tubelib2_on_update2(pos, outdir, tlib2, node) - power.update_network(pos, nil, tlib2) + power.update_network(pos, 0, tlib2, node) end -local net_def1 = { - ele2 = { - sides = {F=1, B=1}, - ntype = "junc", - on_getpower = on_getpower1, - }, -} - -local net_def2 = { - ele2 = { - sides = {F=1, B=1}, - ntype = "junc", - on_getpower = on_getpower2, - }, -} - minetest.register_node("techage:ta4_solar_module", { description = S("TA4 Solar Module"), inventory_image = "techage_solar_module_top.png", @@ -170,7 +155,6 @@ minetest.register_node("techage:ta4_solar_carrier", { after_place_node = after_place_node, after_dig_node = after_dig_node, tubelib2_on_update2 = tubelib2_on_update2, - networks = net_def1, paramtype = "light", use_texture_alpha = techage.CLIP, @@ -210,7 +194,6 @@ minetest.register_node("techage:ta4_solar_carrierB", { after_place_node = after_place_node, after_dig_node = after_dig_node, tubelib2_on_update2 = tubelib2_on_update2, - networks = net_def2, paramtype = "light", use_texture_alpha = techage.CLIP, @@ -249,8 +232,29 @@ minetest.register_node("techage:ta4_solar_carrierT", { sounds = default.node_sound_stone_defaults(), }) -Cable:add_secondary_node_names({"techage:ta4_solar_carrier", "techage:ta4_solar_carrierB"}) +power.register_nodes({"techage:ta4_solar_carrier", "techage:ta4_solar_carrierB"}, Cable, "junc", {"F", "B"}) +control.register_nodes({"techage:ta4_solar_carrier"}, { + on_receive = function(pos, tlib2, topic, payload) + end, + on_request = function(pos, tlib2, topic) + if topic == "power" then + return on_getpower1(pos) + end + end, + } +) + +control.register_nodes({"techage:ta4_solar_carrierB"}, { + on_receive = function(pos, tlib2, topic, payload) + end, + on_request = function(pos, tlib2, topic) + if topic == "power" then + return on_getpower2(pos) + end + end, + } +) minetest.register_craft({ output = "techage:ta4_solar_module", @@ -288,13 +292,3 @@ minetest.register_craft({ }, }) ---minetest.register_lbm({ --- label = "Repair Carrier Module", --- name = "techage:ta4_solar_carrier", --- nodenames = {"techage:ta4_solar_carrier", "techage:ta4_solar_carrierB"}, --- run_at_every_load = false, --- action = function(pos, node) --- local ndef = minetest.registered_nodes[node.name] --- ndef.after_place_node(pos) --- end, ---}) diff --git a/techage/steam_engine/boiler.lua b/techage/steam_engine/boiler.lua index 436ce9a..8b44a86 100644 --- a/techage/steam_engine/boiler.lua +++ b/techage/steam_engine/boiler.lua @@ -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 diff --git a/techage/steam_engine/flywheel.lua b/techage/steam_engine/flywheel.lua index 189a3bd..3df10cf 100644 --- a/techage/steam_engine/flywheel.lua +++ b/techage/steam_engine/flywheel.lua @@ -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 @@ -19,11 +19,10 @@ local S = techage.S local STANDBY_TICKS = 4 local COUNTDOWN_TICKS = 4 local CYCLE_TIME = 2 -local PWR_CAPA = 25 +local PWR_PERF = 25 local Axle = techage.Axle -local power = techage.power -local networks = techage.networks +local power = networks.power -- Axles texture animation local function switch_axles(pos, on) @@ -32,15 +31,7 @@ local function switch_axles(pos, on) end 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("Flywheel")).."]".. - 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("Flywheel"), nvm.provided, PWR_PERF, true) end local function transfer_cylinder(pos, topic, payload) @@ -55,18 +46,16 @@ end local function start_node(pos, nvm, state) switch_axles(pos, true) local outdir = M(pos):get_int("outdir") - power.generator_start(pos, Axle, CYCLE_TIME, outdir) transfer_cylinder(pos, "start") - nvm.running = true + power.start_storage_calc(pos, Axle, outdir) end local function stop_node(pos, nvm, state) switch_axles(pos, false) local outdir = M(pos):get_int("outdir") - power.generator_stop(pos, Axle, outdir) nvm.provided = 0 transfer_cylinder(pos, "stop") - nvm.running = false + power.start_storage_calc(pos, Axle, outdir) end local State = techage.NodeStates:new({ @@ -83,13 +72,20 @@ 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) + if running and nvm.firebox_trigger <= 0 then + State:standby(pos, nvm) stop_node(pos, nvm, State) - transfer_cylinder(pos, "stop") - else + elseif not running and nvm.firebox_trigger > 0 then + State:start(pos, nvm) + -- start_node() is called implicit + elseif running then local outdir = M(pos):get_int("outdir") - nvm.provided = power.generator_alive(pos, Axle, CYCLE_TIME, outdir) + nvm.provided = power.provide_power(pos, Axle, outdir, PWR_PERF) + local val = power.get_storage_load(pos, Axle, 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 @@ -125,18 +121,13 @@ 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 * 4} + end end -local net_def = { - axle = { - sides = {R = 1}, - ntype = "gen1", - nominal = PWR_CAPA, - }, -} - minetest.register_node("techage:flywheel", { description = S("TA2 Flywheel"), tiles = { @@ -154,8 +145,7 @@ minetest.register_node("techage:flywheel", { 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, paramtype2 = "facedir", groups = {cracky=2, crumbly=2, choppy=2}, @@ -208,8 +198,7 @@ minetest.register_node("techage:flywheel_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, drop = "", paramtype2 = "facedir", @@ -220,22 +209,21 @@ minetest.register_node("techage:flywheel_on", { sounds = default.node_sound_wood_defaults(), }) -Axle:add_secondary_node_names({"techage:flywheel", "techage:flywheel_on"}) +power.register_nodes({"techage:flywheel", "techage:flywheel_on"}, Axle, "gen", {"R"}) techage.register_node({"techage:flywheel", "techage:flywheel_on"}, { on_transfer = function(pos, in_dir, topic, payload) 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.1) + if techage.is_running(nvm) then + return math.max((nvm.provided or PWR_PERF) / PWR_PERF, 0.1) else return 0 end end end, on_node_load = function(pos, node) - M(pos):set_int("outdir", networks.side_to_outdir(pos, "R")) State:on_node_load(pos) end, }) diff --git a/techage/ta2_energy_storage/ta2_rope.lua b/techage/ta2_energy_storage/ta2_rope.lua new file mode 100644 index 0000000..18ecf9e --- /dev/null +++ b/techage/ta2_energy_storage/ta2_rope.lua @@ -0,0 +1,85 @@ +--[[ + + TechAge + ======= + + Copyright (C) 2019-2021 Joachim Stolberg + + GPL v3 + See LICENSE.txt for more information + + Rope for TA2 gravity-based energy storage + +]]-- + +local Entities = {} + +-- Return first pos after start pos and the destination pos +local function get_positions(pos, length, force) + local pos1 = {x = pos.x, y = pos.y - 1, z = pos.z} -- start pos + local pos2 = {x = pos.x, y = pos.y - 1 - length, z = pos.z} -- end pos + if force then + return pos1, pos2 -- force given length + end + local _, pos3 = minetest.line_of_sight(pos1, pos2) + return pos1, pos3 or pos2 -- new values +end + +local function del_rope(pos) + local key = minetest.hash_node_position(pos) + local rope = Entities[key] + if rope then + rope:remove() + Entities[key] = nil + end + return key +end + +local function add_rope(pos, pos1, pos2) + local key = del_rope(pos) + + pos1.y = pos1.y + 0.5 -- from + pos2.y = pos2.y - 0.5 -- to + local pos3 = {x = pos1.x, y = (pos1.y + pos2.y) / 2, z = pos1.z} -- mid-pos + local length = math.abs(pos1.y - pos2.y) + + local rope = minetest.add_entity(pos3, "techage:ta2_rope") + if rope then + rope:set_properties({visual_size = {x = 0.06, y = length}, collisionbox = {x = 0.06, y = length}}) + end + Entities[key] = rope +end + +minetest.register_entity("techage:ta2_rope", { + initial_properties = { + visual = "cube", + textures = { + "techage_rope.png", + "techage_rope.png", + "techage_rope.png", + "techage_rope.png", + "techage_rope.png", + "techage_rope.png", + }, + use_texture_alpha = false, + physical = true, + collide_with_objects = true, + pointable = true, + static_save = false, + visual_size = {x = 0.06, y = 10, z = 0.06}, + shaded = true, + }, +}) + +------------------------------------------------------------------------------- +-- API functions +------------------------------------------------------------------------------- +function techage.renew_rope(pos, length, force) + local pos1, pos2 = get_positions(pos, length, force) + if pos1 then + add_rope(pos, pos1, pos2) + return pos1, pos2 + end +end + +techage.del_rope = del_rope diff --git a/techage/ta2_energy_storage/ta2_weight_chest.lua b/techage/ta2_energy_storage/ta2_weight_chest.lua new file mode 100644 index 0000000..f2f915f --- /dev/null +++ b/techage/ta2_energy_storage/ta2_weight_chest.lua @@ -0,0 +1,138 @@ +--[[ + + TechAge + ======= + + Copyright (C) 2019-2021 Joachim Stolberg + + GPL v3 + See LICENSE.txt for more information + + Chest for TA2 gravity-based energy storage + +]]-- + +-- 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 S = techage.S + +local function valid_weight_items(stack) + local name = stack:get_name() + local ndef = minetest.registered_nodes[name] + if ndef then + if minetest.get_item_group(name, "stone") > 0 then + return true + end + if minetest.get_item_group(name, "cobble") > 0 then + return true + end + if minetest.get_item_group(name, "gravel") > 0 then + return true + end + if minetest.get_item_group(name, "sand") > 0 then + return true + end + end +end + +minetest.register_entity("techage:ta2_weight_chest_entity", { + initial_properties = { + physical = true, + pointable = false, + collisionbox = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, + visual = "wielditem", + textures = {"techage:ta2_weight_chest"}, + visual_size = {x=0.66, y=0.66, z=0.66}, + static_save = false, + }, +}) + +local function allow_metadata_inventory_put(pos, listname, index, stack, player) + if minetest.is_protected(pos, player:get_player_name()) then + return 0 + end + if not valid_weight_items(stack) then + return 0 + end + return stack:get_count() +end + +local function allow_metadata_inventory_take(pos, listname, index, stack, player) + if minetest.is_protected(pos, player:get_player_name()) then + return 0 + end + return stack:get_count() +end + +local function can_dig(pos, player) + if minetest.is_protected(pos, player:get_player_name()) then + return false + end + local inv = minetest.get_meta(pos):get_inventory() + return inv:is_empty("main") +end + +local function after_dig_node(pos, oldnode, oldmetadata, digger) + techage.remove_node(pos, oldnode, oldmetadata) +end + +local function formspec() + return "size[8,6.7]".. + default.gui_bg.. + default.gui_bg_img.. + default.gui_slots.. + "list[context;main;1.5,0.2;5,2;]".. + "list[current_player;main;0,3;8,4;]".. + "listring[context;main]".. + "listring[current_player;main]" +end + +minetest.register_node("techage:ta2_weight_chest", { + description = S("TA2 Weight Chest"), + tiles = { + -- up, down, right, left, back, front + "techage_filling_ta2.png^techage_frame_ta2.png^techage_weight_bottom.png", + "techage_filling_ta2.png^techage_frame_ta2.png^techage_weight_bottom.png", + "techage_filling_ta2.png^techage_frame_ta2.png^techage_appl_chest_back_ta3.png^techage_weight_side.png", + "techage_filling_ta2.png^techage_frame_ta2.png^techage_appl_chest_back_ta3.png^techage_weight_side.png", + "techage_filling_ta2.png^techage_frame_ta2.png^techage_appl_chest_back_ta3.png^techage_weight_side.png", + "techage_filling_ta2.png^techage_frame_ta2.png^techage_appl_chest_back_ta3.png^techage_weight_side.png", + }, + + on_construct = function(pos) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + inv:set_size('main', 10) + end, + + after_place_node = function(pos) + local meta = minetest.get_meta(pos) + meta:set_string("formspec", formspec()) + end, + + techage_set_numbers = function(pos, numbers, player_name) + return techage.logic.set_numbers(pos, numbers, player_name, S("TA2 Weight Chest")) + end, + + can_dig = can_dig, + after_dig_node = after_dig_node, + allow_metadata_inventory_put = allow_metadata_inventory_put, + allow_metadata_inventory_take = allow_metadata_inventory_take, + + paramtype2 = "facedir", + groups = {choppy=2, cracky=2, crumbly=2}, + is_ground_content = false, + sounds = default.node_sound_wood_defaults(), +}) + +minetest.register_craft({ + output = "techage:ta2_weight_chest", + recipe = { + {"", "", ""}, + {"basic_materials:steel_strip", "techage:chest_ta2", "basic_materials:steel_strip"}, + {"", "", ""}, + }, +}) + diff --git a/techage/ta2_energy_storage/ta2_winch.lua b/techage/ta2_energy_storage/ta2_winch.lua new file mode 100644 index 0000000..d246a4b --- /dev/null +++ b/techage/ta2_energy_storage/ta2_winch.lua @@ -0,0 +1,193 @@ +--[[ + + TechAge + ======= + + Copyright (C) 2019-2021 Joachim Stolberg + + GPL v3 + See LICENSE.txt for more information + + Winch for TA2 gravity-based energy storage + +]]-- + +-- 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 S = techage.S + +local MIN_LOAD = 99 -- 1 stack +local MAX_ROPE_LEN = 10 +local CYCLE_TIME = 2 + +local Axle = techage.Axle +local power = networks.power + + +local function chest_pos(pos) + local pos1 = {x = pos.x, y = pos.y - 1, z = pos.z} -- start pos + local pos2 = {x = pos.x, y = pos.y - 1 - MAX_ROPE_LEN, z = pos.z} -- end pos + local _, pos3 = minetest.line_of_sight(pos1, pos2) + return pos3 or pos2 +end + +local function chest_load(nvm, pos) + local amount = 0 + local inv = minetest.get_inventory({type = "node", pos = pos}) + nvm.stored_items = {} + for i = 1, inv:get_size("main") do + local stack = inv:get_stack("main", i) + nvm.stored_items[i] = {name = stack:get_name(), count = stack:get_count()} + amount = amount + stack:get_count() + end + return amount +end + +local function chest_full(pos) + local nvm = techage.get_nvm(pos) + local pos1 = chest_pos(pos) + local node = minetest.get_node(pos1) + if node.name == "techage:ta2_weight_chest" then + return chest_load(nvm, pos1) >= MIN_LOAD + end +end + +local function add_chest_entity(pos, nvm) + local mem = techage.get_mem(pos) + local length = (nvm.length or MAX_ROPE_LEN) * (1 - nvm.load/nvm.capa) + local y = pos.y - length - 1 + techage.renew_rope(pos, length, true) + if mem.obj then + mem.obj:remove() + end + mem.obj = minetest.add_entity({x = pos.x, y = y, z = pos.z}, "techage:ta2_weight_chest_entity") +end + +-- Add chest node, remove chest entity instead +local function add_chest(pos) + local mem = techage.get_mem(pos) + local nvm = techage.get_nvm(pos) + if mem.obj then + mem.obj:remove() + mem.obj = nil + end + if nvm.capa and nvm.capa >= MIN_LOAD then + local pos1 = {x = pos.x, y = pos.y - (nvm.length or 1) - 1, z = pos.z} + minetest.add_node(pos1, {name = "techage:ta2_weight_chest", param2 = 0}) + local ndef = minetest.registered_nodes["techage:ta2_weight_chest"] + ndef.on_construct(pos1) + ndef.after_place_node(pos1) + local inv = minetest.get_inventory({type = "node", pos = pos1}) + for i, item in ipairs(nvm.stored_items or {}) do + inv:set_stack("main", i, item) + end + end + nvm.capa = 0 +end + +-- Remove chest node, add rope and chest entity instead +local function remove_chest(pos) + local mem = techage.get_mem(pos) + local nvm = techage.get_nvm(pos) + local pos1 = chest_pos(pos) + local mass = chest_load(nvm, pos1) + if mass > 0 then + nvm.length = pos.y - pos1.y - 1 + nvm.capa = mass * nvm.length / MAX_ROPE_LEN + minetest.remove_node(pos1) + mem.obj = minetest.add_entity(pos1, "techage:ta2_weight_chest_entity") + techage.renew_rope(pos, nvm.length) + return true + end +end + +minetest.register_node("techage:ta2_winch", { + description = S("TA2 Winch"), + tiles = { + -- up, down, right, left, back, front + "techage_filling_ta2.png^techage_appl_arrow2.png^techage_frame_ta2.png^[transformR270", + "techage_filling_ta2.png^techage_appl_arrow2.png^techage_frame_ta2.png^techage_appl_winch_hole.png^[transformR270", + "techage_filling_ta2.png^techage_axle_gearbox.png^techage_frame_ta2.png", + "techage_filling_ta2.png^techage_appl_winch.png^techage_frame_ta2.png", + "techage_filling_ta2.png^techage_appl_winch.png^techage_frame_ta2.png", + "techage_filling_ta2.png^techage_appl_winch.png^techage_frame_ta2.png", + }, + + after_place_node = function(pos, placer) + local nvm = techage.get_nvm(pos) + local outdir = networks.side_to_outdir(pos, "R") + M(pos):set_int("outdir", outdir) + Axle:after_place_node(pos, {outdir}) + minetest.get_node_timer(pos):start(CYCLE_TIME) + techage.renew_rope(pos, MAX_ROPE_LEN - 1) + end, + + on_timer = function(pos, elapsed) + local nvm = techage.get_nvm(pos) + local outdir = M(pos):get_int("outdir") + nvm.capa = nvm.capa or 1 + nvm.load = nvm.load or 0 + + if not nvm.running and power.power_available(pos, Axle, outdir) and chest_full(pos) then + remove_chest(pos) + nvm.running = true + power.start_storage_calc(pos, Axle, outdir) + elseif nvm.running and nvm.load == 0 and not power.power_available(pos, Axle, outdir) then + add_chest(pos) + nvm.running = false + power.start_storage_calc(pos, Axle, outdir) + end + + if nvm.running then + local val = power.get_storage_load(pos, Axle, outdir, nvm.capa) or 0 + if val > 0 then + nvm.load = val + add_chest_entity(pos, nvm) + end + end + return true + end, + + after_dig_node = function(pos, oldnode, oldmetadata) + add_chest(pos) + local outdir = tonumber(oldmetadata.fields.outdir or 0) + power.start_storage_calc(pos, Axle, outdir) + Axle:after_dig_node(pos, {outdir}) + techage.del_mem(pos) + end, + + get_storage_data = function(pos, outdir, tlib2) + local nvm = techage.get_nvm(pos) + nvm.capa = nvm.capa or 1 + if nvm.running then + return {level = (nvm.load or 0) / nvm.capa, capa = nvm.capa} + end + end, + + paramtype2 = "facedir", + groups = {choppy=2, cracky=2, crumbly=2}, + is_ground_content = false, + sounds = default.node_sound_wood_defaults(), +}) + +power.register_nodes({"techage:ta2_winch"}, Axle, "sto", {"R"}) + +techage.register_node({"techage:ta2_winch"}, { + on_node_load = function(pos, node) + minetest.get_node_timer(pos):start(CYCLE_TIME) + local nvm = techage.get_nvm(pos) + add_chest_entity(pos, nvm) + end, +}) + +minetest.register_craft({ + output = "techage:ta2_winch", + recipe = { + {"farming:string", "farming:string", "farming:string"}, + {"farming:string", "techage:gearbox", "farming:string"}, + {"farming:string", "farming:string", "farming:string"}, + }, +}) + diff --git a/techage/ta3_power/akkubox.lua b/techage/ta3_power/akkubox.lua index 3d7b662..debf025 100644 --- a/techage/ta3_power/akkubox.lua +++ b/techage/ta3_power/akkubox.lua @@ -18,51 +18,34 @@ local M = minetest.get_meta local S = techage.S local CYCLE_TIME = 2 -local PWR_PERF = 10 local PWR_CAPA = 2000 local Cable = techage.ElectricCable -local power = techage.power -local networks = techage.networks +local power = networks.power +local control = networks.control local in_range = techage.in_range local function formspec(self, pos, nvm) - local needed = nvm.needed or 0 - local capa = nvm.capa or 0 - return "size[5,4]".. - default.gui_bg.. - default.gui_bg_img.. - default.gui_slots.. - "box[0,-0.1;4.8,0.5;#c6e8ff]".. - "label[1,-0.1;"..minetest.colorize( "#000000", S("TA3 Akku Box")).."]".. - power.formspec_label_bar(pos, 0, 0.8, S("Load"), PWR_CAPA, capa).. - "image_button[2.6,2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]".. - "tooltip[3,2;1,1;"..self:get_state_tooltip(nvm).."]".. - "label[3.7,1.2;"..S("Electricity").."]".. - "image[3.8,1.7;1,2;"..techage.power.formspec_load_bar(needed, PWR_PERF).."]" -end - -local function on_power(pos) -end - -local function on_nopower(pos) + local data + + if nvm.running then + local outdir = M(pos):get_int("outdir") + data = power.get_network_data(pos, Cable, outdir) + end + return techage.storage_formspec(self, pos, nvm, S("TA3 Akku Box"), data, nvm.capa, PWR_CAPA) end local function start_node(pos, nvm, state) nvm.running = true - nvm.needed = 0 local outdir = M(pos):get_int("outdir") - power.generator_start(pos, Cable, CYCLE_TIME, outdir) - power.consumer_start(pos, Cable, CYCLE_TIME) + power.start_storage_calc(pos, Cable, outdir) end local function stop_node(pos, nvm, state) nvm.running = false - nvm.needed = 0 local outdir = M(pos):get_int("outdir") - power.generator_stop(pos, Cable, outdir) - power.consumer_stop(pos, Cable) + power.start_storage_calc(pos, Cable, outdir) end local State = techage.NodeStates:new({ @@ -76,24 +59,16 @@ local State = techage.NodeStates:new({ local function node_timer(pos, elapsed) local nvm = techage.get_nvm(pos) - nvm.capa = nvm.capa or 0 - local outdir = M(pos):get_int("outdir") - local taken = 0 - local given = 0 - if nvm.capa < PWR_CAPA then - taken = power.consumer_alive(pos, Cable, CYCLE_TIME) + if nvm.running then + local outdir = M(pos):get_int("outdir") + local capa = power.get_storage_load(pos, Cable, outdir, PWR_CAPA) or 0 + if capa > 0 then + nvm.capa = capa + end end - if nvm.capa > 0 then - given = power.generator_alive(pos, Cable, CYCLE_TIME, outdir) - end - nvm.needed = taken - given - nvm.capa = in_range(nvm.capa + nvm.needed, 0, PWR_CAPA) - --print("node_timer accu "..P2S(pos), nvm.needed, nvm.capa) - if techage.is_activeformspec(pos) then M(pos):set_string("formspec", formspec(State, pos, nvm)) end - return true end @@ -112,6 +87,13 @@ local function on_receive_fields(pos, formname, fields, player) M(pos):set_string("formspec", formspec(State, pos, nvm)) end +local function get_storage_data(pos, outdir, tlib2) + local nvm = techage.get_nvm(pos) + if nvm.running then + return {level = (nvm.capa or 0) / PWR_CAPA, capa = PWR_CAPA} + end +end + local function get_capa(itemstack) local meta = itemstack:get_meta() if meta then @@ -137,32 +119,20 @@ local function after_place_node(pos, placer, itemstack) local own_num = techage.add_node(pos, "techage:ta3_akku") meta:set_string("owner", placer:get_player_name()) meta:set_string("infotext", S("TA3 Accu Box").." "..own_num) - meta:set_int("outdir", networks.side_to_outdir(pos, "R")) + local outdir = networks.side_to_outdir(pos, "R") + meta:set_int("outdir", outdir) meta:set_string("formspec", formspec(State, pos, nvm)) - Cable:after_place_node(pos) + Cable:after_place_node(pos, {outdir}) State:node_init(pos, nvm, own_num) nvm.capa = get_capa(itemstack) end local function after_dig_node(pos, oldnode, oldmetadata, digger) - Cable:after_dig_node(pos) + local outdir = tonumber(oldmetadata.fields.outdir or 0) + Cable:after_dig_node(pos, {outdir}) 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 = {R = 1}, - ntype = {"gen2", "con2"}, - nominal = PWR_PERF, - on_power = on_power, - on_nopower = on_nopower, - }, -} - minetest.register_node("techage:ta3_akku", { description = S("TA3 Accu Box"), tiles = { @@ -180,8 +150,7 @@ minetest.register_node("techage:ta3_akku", { on_receive_fields = on_receive_fields, after_place_node = after_place_node, after_dig_node = after_dig_node, - tubelib2_on_update2 = tubelib2_on_update2, - networks = net_def, + get_storage_data = get_storage_data, paramtype2 = "facedir", groups = {cracky=2, crumbly=2, choppy=2}, on_rotate = screwdriver.disallow, @@ -190,7 +159,7 @@ minetest.register_node("techage:ta3_akku", { preserve_metadata = set_capa, }) -Cable:add_secondary_node_names({"techage:ta3_akku"}) +power.register_nodes({"techage:ta3_akku"}, Cable, "sto", {"R"}) -- for logical communication techage.register_node({"techage:ta3_akku"}, { @@ -198,27 +167,31 @@ techage.register_node({"techage:ta3_akku"}, { local nvm = techage.get_nvm(pos) if topic == "load" then return techage.power.percent(PWR_CAPA, nvm.capa) - elseif topic == "delivered" then - return -(nvm.needed or 0) else return State:on_receive_message(pos, topic, payload) end end, - on_node_load = function(pos) - local meta = M(pos) - meta:set_int("outdir", networks.side_to_outdir(pos, "R")) - if meta:get_string("node_number") == "" then - local own_num = techage.add_node(pos, "techage:ta3_akku") - meta:set_string("node_number", own_num) - meta:set_string("infotext", S("TA3 Accu Box").." "..own_num) - end - local mem = tubelib2.get_mem(pos) - local nvm = techage.get_nvm(pos) - nvm.capa = (nvm.capa or 0) + (mem.capa or 0) - tubelib2.del_mem(pos) - end, }) +control.register_nodes({"techage:ta3_akku"}, { + on_receive = function(pos, tlib2, topic, payload) + end, + on_request = function(pos, tlib2, topic) + if topic == "info" then + local nvm = techage.get_nvm(pos) + return { + type = S("TA3 Accu Box"), + number = M(pos):get_string("node_number") or "", + running = nvm.running or false, + capa = PWR_CAPA , + load = nvm.capa or 0, + } + end + return false + end, + } +) + minetest.register_craft({ output = "techage:ta3_akku", recipe = { diff --git a/techage/ta3_power/axle2power.lua b/techage/ta3_power/axle2power.lua index cc06dfd..4bc252b 100644 --- a/techage/ta3_power/axle2power.lua +++ b/techage/ta3_power/axle2power.lua @@ -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,8 +20,7 @@ local S2P = minetest.string_to_pos local Cable = techage.ElectricCable local Axle = techage.Axle -local power = techage.power -local networks = techage.networks +local power = networks.power local CYCLE_TIME = 2 local PWR_PERF = 24 @@ -35,64 +34,52 @@ local function swap_node(pos, name) minetest.swap_node(pos, node) end -local function on_power(pos) +local function node_timer_on(pos, elapsed) + local meta = M(pos) local nvm = techage.get_nvm(pos) - nvm.axle = nvm.axle or {} - nvm.consumer_powered = true - M(pos):set_string("infotext", S("TA2 Power Generator")) - swap_node(pos, "techage:ta2_generator_on") - nvm.ticks = 0 - local outdir = M(pos):get_int("outdir") - nvm.axle.curr_power = techage.power.needed_power(pos, Cable, outdir) -end - -local function on_nopower(pos) - local nvm = techage.get_nvm(pos) - nvm.consumer_powered = false - if (nvm.ticks or 0) < 4 then - M(pos):set_string("infotext", S("TA2 Power Generator: Overload fault?\n(restart with right-click)")) - end - nvm.ticks = 0 -end - -local function node_timer(pos, elapsed) - local nvm = techage.get_nvm(pos) - nvm.axle = nvm.axle or {} + local outdir = meta:get_int("outdir") + nvm.buffer = nvm.buffer or 0 - -- trigger network on consumer side - nvm.ticks = (nvm.ticks or 0) + 1 - if nvm.ticks % 2 then - power.consumer_alive(pos, Axle, CYCLE_TIME) - end + local amount = math.min(PWR_PERF * 2 - nvm.buffer, PWR_PERF) + local taken = power.consume_power(pos, Axle, networks.Flip[outdir], amount) + nvm.buffer = nvm.buffer + taken - 1 -- some loss - -- handle generator side delayed - if nvm.ticks > 3 then + if nvm.buffer >= PWR_PERF then + 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) + nvm.buffer = nvm.buffer - nvm.provided + end + if amount > 0 and taken == 0 then + swap_node(pos, "techage:ta2_generator_off") local outdir = M(pos):get_int("outdir") + nvm.running = false + power.start_storage_calc(pos, Cable, outdir) + end + return true +end - if nvm.consumer_powered and not nvm.running_as_generator then - nvm.running_as_generator = true - power.generator_start(pos, Cable, CYCLE_TIME, outdir, nvm.max_power) - elseif not nvm.consumer_powered and nvm.running_as_generator then - nvm.running_as_generator = false - power.generator_stop(pos, Cable, outdir) - end - - if nvm.running_as_generator then - nvm.axle.curr_power = power.generator_alive(pos, Cable, CYCLE_TIME, outdir, PWR_PERF) + 1 - else - swap_node(pos, "techage:ta2_generator_off") - end +local function node_timer_off(pos, elapsed) + local nvm = techage.get_nvm(pos) + local outdir = M(pos):get_int("outdir") + + if power.power_available(pos, Axle, networks.Flip[outdir]) then + swap_node(pos, "techage:ta2_generator_on") + nvm.running = true + power.start_storage_calc(pos, Cable, outdir) end return true end -local function tubelib2_on_update2(pos, outdir, tlib2, node) +local function get_generator_data(pos, outdir, tlib2) local nvm = techage.get_nvm(pos) - nvm.axle = nvm.axle or {} - nvm.axle.curr_power = 1 - power.update_network(pos, outdir, tlib2) + if nvm.running then + return {level = (nvm.load or 0) / PWR_PERF, perf = PWR_PERF, capa = PWR_PERF * 2} + end end + minetest.register_node("techage:ta2_generator_off", { description = S("TA2 Power Generator"), tiles = { @@ -110,24 +97,10 @@ minetest.register_node("techage:ta2_generator_off", { is_ground_content = false, after_place_node = function(pos) - local nvm = techage.get_nvm(pos) - nvm.axle = nvm.axle or {} - nvm.axle.curr_power = 1 - nvm.consumer_powered = false - nvm.running_as_generator = false M(pos):set_int("outdir", networks.side_to_outdir(pos, "R")) - M(pos):set_int("leftdir", networks.side_to_outdir(pos, "L")) Cable:after_place_node(pos) Axle:after_place_node(pos) minetest.get_node_timer(pos):start(CYCLE_TIME) - power.consumer_start(pos, Axle, CYCLE_TIME*2) - M(pos):set_string("infotext", S("TA2 Power Generator")) - end, - - on_rightclick = function(pos, node, clicker) - local nvm = techage.get_nvm(pos) - nvm.axle = nvm.axle or {} - nvm.axle.curr_power = 1 M(pos):set_string("infotext", S("TA2 Power Generator")) end, @@ -137,21 +110,8 @@ minetest.register_node("techage:ta2_generator_off", { techage.del_mem(pos) end, - tubelib2_on_update2 = tubelib2_on_update2, - on_timer = node_timer, - networks = { - ele1 = { - sides = {R = 1}, - ntype = "gen1", - nominal = PWR_PERF, - }, - axle = { - sides = {L = 1}, - ntype = "con1", - on_power = on_power, - on_nopower = on_nopower, - }, - } + on_timer = node_timer_off, + get_generator_data = get_generator_data, }) minetest.register_node("techage:ta2_generator_on", { @@ -199,21 +159,8 @@ minetest.register_node("techage:ta2_generator_on", { groups = {not_in_creative_inventory=1}, diggable = false, - tubelib2_on_update2 = tubelib2_on_update2, - on_timer = node_timer, - networks = { - ele1 = { - sides = {R = 1}, - ntype = "gen1", - nominal = PWR_PERF, - }, - axle = { - sides = {L = 1}, - ntype = "con1", - on_power = on_power, - on_nopower = on_nopower, - }, - } + on_timer = node_timer_on, + get_generator_data = get_generator_data, }) techage.register_node({"techage:ta2_generator_off", "techage:ta2_generator_on"}, { @@ -222,8 +169,8 @@ techage.register_node({"techage:ta2_generator_off", "techage:ta2_generator_on"}, end, }) -Cable:add_secondary_node_names({"techage:ta2_generator_off", "techage:ta2_generator_on"}) -Axle:add_secondary_node_names({"techage:ta2_generator_off", "techage:ta2_generator_on"}) +power.register_nodes({"techage:ta2_generator_off", "techage:ta2_generator_on"}, Axle, "con", {"L"}) +power.register_nodes({"techage:ta2_generator_off", "techage:ta2_generator_on"}, Cable, "gen", {"R"}) minetest.register_craft({ output = "techage:ta2_generator_off", diff --git a/techage/ta3_power/power2axle.lua b/techage/ta3_power/power2axle.lua index 3e37294..13c7f4a 100644 --- a/techage/ta3_power/power2axle.lua +++ b/techage/ta3_power/power2axle.lua @@ -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,17 +20,15 @@ local S2P = minetest.string_to_pos local Cable = techage.ElectricCable local Axle = techage.Axle -local power = techage.power -local networks = techage.networks +local power = networks.power local CYCLE_TIME = 2 local PWR_PERF = 40 -- Axles texture animation local function switch_axles(pos, on) - for _,outdir in ipairs(networks.get_node_connections(pos, "axle")) do - Axle:switch_tube_line(pos, outdir, on and "on" or "off") - end + local outdir = M(pos):get_int("outdir") + Axle:switch_tube_line(pos, outdir, on and "on" or "off") end local function swap_node(pos, name) @@ -42,64 +40,48 @@ local function swap_node(pos, name) minetest.swap_node(pos, node) end -local function on_power(pos) +local function node_timer_on(pos, elapsed) local nvm = techage.get_nvm(pos) - nvm.ele1 = nvm.ele1 or {} - nvm.consumer_powered = true - M(pos):set_string("infotext", S("TA3 Electric Motor")) - swap_node(pos, "techage:ta3_motor_on") - nvm.ticks = 0 local outdir = M(pos):get_int("outdir") - nvm.ele1.curr_power = techage.power.needed_power(pos, Axle, outdir) -end - -local function on_nopower(pos) - local nvm = techage.get_nvm(pos) - nvm.consumer_powered = false - if (nvm.ticks or 0) < 4 then - M(pos):set_string("infotext", S("TA3 Electric Motor: Overload fault?\n(restart with right-click)")) - end - nvm.ticks = 0 -end - -local function node_timer(pos, elapsed) - local nvm = techage.get_nvm(pos) - nvm.ele1 = nvm.ele1 or {} + nvm.buffer = nvm.buffer or 0 - -- trigger network on consumer side - nvm.ticks = (nvm.ticks or 0) + 1 - if nvm.ticks % 2 then - power.consumer_alive(pos, Cable, CYCLE_TIME) - end + local amount = math.min(PWR_PERF * 2 - nvm.buffer, PWR_PERF) + local taken = power.consume_power(pos, Cable, networks.Flip[outdir], amount) + nvm.buffer = nvm.buffer + taken - 1 -- some loss - -- handle generator side delayed - if nvm.ticks > 3 then + if nvm.buffer >= PWR_PERF then + nvm.provided = power.provide_power(pos, Axle, outdir, PWR_PERF) + nvm.load = power.get_storage_load(pos, Axle, outdir, PWR_PERF) + nvm.buffer = nvm.buffer - nvm.provided + end + if amount > 0 and taken == 0 then + swap_node(pos, "techage:ta3_motor_off") + switch_axles(pos, false) local outdir = M(pos):get_int("outdir") + nvm.running = false + power.start_storage_calc(pos, Cable, outdir) + end + return true +end - if nvm.consumer_powered and not nvm.running_as_generator then - nvm.running_as_generator = true - power.generator_start(pos, Axle, CYCLE_TIME, outdir, nvm.max_power) - switch_axles(pos, true) - elseif not nvm.consumer_powered and nvm.running_as_generator then - nvm.running_as_generator = false - power.generator_stop(pos, Axle, outdir) - switch_axles(pos, false) - end - - if nvm.running_as_generator then - nvm.ele1.curr_power = power.generator_alive(pos, Axle, CYCLE_TIME, outdir, PWR_PERF) + 1 - else - swap_node(pos, "techage:ta3_motor_off") - end +local function node_timer_off(pos, elapsed) + local nvm = techage.get_nvm(pos) + local outdir = M(pos):get_int("outdir") + + if power.power_available(pos, Cable) then + swap_node(pos, "techage:ta3_motor_on") + switch_axles(pos, true) + nvm.running = true + power.start_storage_calc(pos, Cable, outdir) end return true end -local function tubelib2_on_update2(pos, outdir, tlib2, node) +local function get_generator_data(pos, outdir, tlib2) local nvm = techage.get_nvm(pos) - nvm.ele1 = nvm.ele1 or {} - nvm.ele1.curr_power = 1 - power.update_network(pos, outdir, tlib2) + if nvm.running then + return {level = (nvm.load or 0) / PWR_PERF, perf = PWR_PERF, capa = PWR_PERF * 2} + end end minetest.register_node("techage:ta3_motor_off", { @@ -119,24 +101,10 @@ minetest.register_node("techage:ta3_motor_off", { is_ground_content = false, after_place_node = function(pos) - local nvm = techage.get_nvm(pos) - nvm.ele1 = nvm.ele1 or {} - nvm.ele1.curr_power = 1 - nvm.consumer_powered = false - nvm.running_as_generator = false M(pos):set_int("outdir", networks.side_to_outdir(pos, "R")) - M(pos):set_int("leftdir", networks.side_to_outdir(pos, "L")) Cable:after_place_node(pos) Axle:after_place_node(pos) minetest.get_node_timer(pos):start(CYCLE_TIME) - power.consumer_start(pos, Cable, CYCLE_TIME*2) - M(pos):set_string("infotext", S("TA3 Electric Motor")) - end, - - on_rightclick = function(pos, node, clicker) - local nvm = techage.get_nvm(pos) - nvm.ele1 = nvm.ele1 or {} - nvm.ele1.curr_power = 1 M(pos):set_string("infotext", S("TA3 Electric Motor")) end, @@ -146,21 +114,8 @@ minetest.register_node("techage:ta3_motor_off", { techage.del_mem(pos) end, - tubelib2_on_update2 = tubelib2_on_update2, - on_timer = node_timer, - networks = { - axle = { - sides = {R = 1}, - ntype = "gen1", - nominal = PWR_PERF, - }, - ele1 = { - sides = {L = 1}, - ntype = "con1", - on_power = on_power, - on_nopower = on_nopower, - }, - } + on_timer = node_timer_off, + get_generator_data = get_generator_data, }) minetest.register_node("techage:ta3_motor_on", { @@ -208,21 +163,8 @@ minetest.register_node("techage:ta3_motor_on", { groups = {not_in_creative_inventory=1}, diggable = false, - tubelib2_on_update2 = tubelib2_on_update2, - on_timer = node_timer, - networks = { - axle = { - sides = {R = 1}, - ntype = "gen1", - nominal = PWR_PERF, - }, - ele1 = { - sides = {L = 1}, - ntype = "con1", - on_power = on_power, - on_nopower = on_nopower, - }, - } + on_timer = node_timer_on, + get_generator_data = get_generator_data, }) techage.register_node({"techage:ta3_motor_off", "techage:ta3_motor_on"}, { @@ -231,8 +173,8 @@ techage.register_node({"techage:ta3_motor_off", "techage:ta3_motor_on"}, { end, }) -Cable:add_secondary_node_names({"techage:ta3_motor_off", "techage:ta3_motor_on"}) -Axle:add_secondary_node_names({"techage:ta3_motor_off", "techage:ta3_motor_on"}) +power.register_nodes({"techage:ta3_motor_off", "techage:ta3_motor_on"}, Axle, "gen", {"R"}) +power.register_nodes({"techage:ta3_motor_off", "techage:ta3_motor_on"}, Cable, "con", {"L"}) minetest.register_craft({ output = "techage:ta3_motor_off", diff --git a/techage/ta3_power/tiny_generator.lua b/techage/ta3_power/tiny_generator.lua index 3d27862..8a21e6d 100644 --- a/techage/ta3_power/tiny_generator.lua +++ b/techage/ta3_power/tiny_generator.lua @@ -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 @@ -18,14 +18,15 @@ local S = techage.S local Cable = techage.ElectricCable local firebox = techage.firebox -local power = techage.power local fuel = techage.fuel local Pipe = techage.LiquidPipe -local liquid = techage.liquid -local networks = techage.networks +local power = networks.power +local liquid = networks.liquid local CYCLE_TIME = 2 -local PWR_CAPA = 12 +local STANDBY_TICKS = 1 +local COUNTDOWN_TICKS = 2 +local PWR_PERF = 12 local EFFICIENCY = 2.5 local function formspec(self, pos, nvm) @@ -34,12 +35,12 @@ local function formspec(self, pos, nvm) default.gui_bg_img.. default.gui_slots.. "box[0,-0.1;4.8,0.5;#c6e8ff]".. - "label[1.5,-0.1;"..minetest.colorize( "#000000", S("Tiny Generator")).."]".. + "label[0.2,-0.1;"..minetest.colorize( "#000000", S("Tiny Generator")).."]".. fuel.fuel_container(0, 0.9, nvm).. "image[1.4,1.6;1,1;techage_form_arrow_bg.png^[transformR270]".. "image_button[1.4,3.2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]".. "tooltip[1.5,3;1,1;"..self:get_state_tooltip(nvm).."]".. - power.formspec_label_bar(pos, 2.5, 0.8, S("Electricity"), PWR_CAPA, nvm.provided) + techage.formspec_power_bar(pos, 2.5, 0.8, S("Electricity"), nvm.provided, PWR_PERF) end local function play_sound(pos) @@ -64,33 +65,38 @@ local function stop_sound(pos) end end +local function has_fuel(pos, nvm) + return (nvm.burn_cycles or 0) > 0 or (nvm.liquid and nvm.liquid.amount and nvm.liquid.amount > 0) +end + local function can_start(pos, nvm, state) - if (nvm.burn_cycles or 0) > 0 or (nvm.liquid and nvm.liquid.amount and nvm.liquid.amount > 0) then + if has_fuel(pos, nvm) then return true end return S("no fuel") end local function start_node(pos, nvm, state) - nvm.running = true -- needed by fuel_lib - 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") play_sound(pos) + power.start_storage_calc(pos, Cable, outdir) + techage.evaluate_charge_termination(nvm, meta) end local function stop_node(pos, nvm, state) - nvm.running = false nvm.provided = 0 local outdir = M(pos):get_int("outdir") - power.generator_stop(pos, Cable, outdir) stop_sound(pos) + power.start_storage_calc(pos, Cable, outdir) end local State = techage.NodeStates:new({ node_name_passive = "techage:tiny_generator", node_name_active = "techage:tiny_generator_on", cycle_time = CYCLE_TIME, - standby_ticks = 0, + standby_ticks = STANDBY_TICKS, formspec_func = formspec, infotext_name = S("TA3 Tiny Power Generator"), can_start = can_start, @@ -99,7 +105,7 @@ local State = techage.NodeStates:new({ }) local function burning(pos, nvm) - local ratio = math.max((nvm.provided or PWR_CAPA) / PWR_CAPA, 0.02) + local ratio = math.max((nvm.provided or PWR_PERF) / PWR_PERF, 0.02) nvm.liquid = nvm.liquid or {} nvm.liquid.amount = nvm.liquid.amount or 0 @@ -109,25 +115,34 @@ local function burning(pos, nvm) nvm.liquid.amount = nvm.liquid.amount - 1 nvm.burn_cycles = fuel.burntime(nvm.liquid.name) * EFFICIENCY / CYCLE_TIME nvm.burn_cycles_total = nvm.burn_cycles - return true else nvm.liquid.name = nil - State:fault(pos, nvm, S("no fuel")) - stop_sound(pos) - return false end - else - return true end end local function node_timer(pos, elapsed) local nvm = techage.get_nvm(pos) - local outdir = M(pos):get_int("outdir") - if nvm.running and burning(pos, nvm) then - nvm.provided = power.generator_alive(pos, Cable, CYCLE_TIME, outdir) - else - nvm.provided = 0 + local running = techage.is_running(nvm) + local fuel = has_fuel(pos, nvm) + if running and not fuel then + State:standby(pos, nvm, S("no fuel")) + stop_node(pos, nvm, State) + elseif not running and fuel 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 + burning(pos, nvm) + State:keep_running(pos, nvm, COUNTDOWN_TICKS) end if techage.is_activeformspec(pos) then M(pos):set_string("formspec", formspec(State, pos, nvm)) @@ -141,51 +156,20 @@ local function on_receive_fields(pos, formname, fields, player) end local nvm = techage.get_nvm(pos) State:state_button_event(pos, nvm, fields) - M(pos):set_string("formspec", formspec(State, pos, nvm)) end local function on_rightclick(pos, node, clicker) - techage.set_activeformspec(pos, clicker) local nvm = techage.get_nvm(pos) + techage.set_activeformspec(pos, clicker) M(pos):set_string("formspec", formspec(State, pos, nvm)) end -local liquid_def = { - fuel_cat = fuel.BT_NAPHTHA, - capa = fuel.CAPACITY, - peek = liquid.srv_peek, - put = function(pos, indir, name, amount) - if fuel.valid_fuel(name, fuel.BT_OIL) then - local res = liquid.srv_put(pos, indir, name, amount) - if techage.is_activeformspec(pos) then - local nvm = techage.get_nvm(pos) - M(pos):set_string("formspec", formspec(State, pos, nvm)) - end - return res - 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", formspec(State, pos, nvm)) - end - return amount, name +local function get_generator_data(pos, outdir, tlib2) + local nvm = techage.get_nvm(pos) + if nvm.running and techage.is_running(nvm) then + return {level = (nvm.load or 0) / PWR_PERF, perf = PWR_PERF, capa = PWR_PERF * 2} end -} - -local net_def = { - pipe2 = { - sides = techage.networks.AllSides, -- Pipe connection sides - ntype = "tank", - }, - ele1 = { - sides = {R = 1}, - ntype = "gen1", - nominal = PWR_CAPA, - }, -} +end minetest.register_node("techage:tiny_generator", { description = S("TA3 Tiny Power Generator"), @@ -221,13 +205,13 @@ minetest.register_node("techage:tiny_generator", { techage.del_mem(pos) end, + get_generator_data = get_generator_data, + ta3_formspec = techage.generator_settings("ta3", PWR_PERF), on_receive_fields = on_receive_fields, on_rightclick = on_rightclick, on_punch = fuel.on_punch, on_timer = node_timer, can_dig = fuel.can_dig, - liquid = liquid_def, - networks = net_def, }) minetest.register_node("techage:tiny_generator_on", { @@ -268,17 +252,56 @@ minetest.register_node("techage:tiny_generator_on", { on_rotate = screwdriver.disallow, is_ground_content = false, + get_generator_data = get_generator_data, + ta3_formspec = techage.generator_settings("ta3", PWR_PERF), on_receive_fields = on_receive_fields, on_rightclick = on_rightclick, on_punch = fuel.on_punch, on_timer = node_timer, can_dig = fuel.can_dig, - liquid = liquid_def, - networks = net_def, }) -Pipe:add_secondary_node_names({"techage:tiny_generator", "techage:tiny_generator_on"}) -Cable:add_secondary_node_names({"techage:tiny_generator", "techage:tiny_generator_on"}) +local liquid_def = { + fuel_cat = fuel.BT_GASOLINE, + capa = fuel.CAPACITY, + 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, fuel.BT_GASOLINE) then + local nvm = techage.get_nvm(pos) + local leftover = liquid.srv_put(nvm, name, amount, fuel.CAPACITY) + if techage.is_activeformspec(pos) then + local nvm = techage.get_nvm(pos) + M(pos):set_string("formspec", formspec(State, pos, nvm)) + end + return leftover + end + return amount + end, + take = function(pos, indir, name, amount) + local nvm = techage.get_nvm(pos) + local taken = liquid.srv_take(nvm, name, amount) + if techage.is_activeformspec(pos) then + local nvm = techage.get_nvm(pos) + M(pos):set_string("formspec", formspec(State, pos, nvm)) + end + return taken + end, + untake = function(pos, indir, name, amount) + local nvm = techage.get_nvm(pos) + local leftover = liquid.srv_put(nvm, name, amount, fuel.CAPACITY) + if techage.is_activeformspec(pos) then + local nvm = techage.get_nvm(pos) + M(pos):set_string("formspec", formspec(State, pos, nvm)) + end + return leftover + end, +} + +power.register_nodes({"techage:tiny_generator", "techage:tiny_generator_on"}, Cable, "gen", {"R"}) +liquid.register_nodes({"techage:tiny_generator", "techage:tiny_generator_on"}, Pipe, "tank", nil, liquid_def) techage.register_node({"techage:tiny_generator", "techage:tiny_generator_on"}, { on_recv_message = function(pos, src, topic, payload) diff --git a/techage/ta4_power/electricmeter.lua b/techage/ta4_power/electricmeter.lua new file mode 100644 index 0000000..f6ce2c1 --- /dev/null +++ b/techage/ta4_power/electricmeter.lua @@ -0,0 +1,193 @@ +--[[ + + TechAge + ======= + + Copyright (C) 2019-2021 Joachim Stolberg + + AGPL v3 + See LICENSE.txt for more information + + TA4 Electric Meter (to separate networks) + +]]-- + +-- for lazy programmers +local P2S = minetest.pos_to_string +local M = minetest.get_meta +local S = techage.S + +local CYCLE_TIME = 2 +local PWR_PERF = 200 + +local Cable = techage.ElectricCable +local power = networks.power +local control = networks.control + + +local function formspec(self, pos, nvm, power) + local units = (nvm.units or 0) / techage.CYCLES_PER_DAY + power = power or 0 + + return "size[5,4]" .. + default.gui_bg .. + default.gui_bg_img .. + default.gui_slots .. + "box[0,-0.1;4.8,0.5;#c6e8ff]" .. + "label[0.2,-0.1;" .. minetest.colorize( "#000000", S("TA4 Electric Meter")).."]" .. + techage.formspec_power_bar(pos, 0.0, 0.7, S("Power"), power, PWR_PERF) .. + techage.formspec_meter(pos, 2.5, 0.7, S("Consumption"), units, "kud") .. + "image_button[3.2,2.2;1,1;" .. self:get_state_button_image(nvm) .. ";state_button;]" .. + "tooltip[3.2,2.2;1,1;" .. self:get_state_tooltip(nvm) .. "]" +end + +local function start_node(pos, nvm, state) + local outdir = M(pos):get_int("outdir") + power.start_storage_calc(pos, Cable, outdir) + outdir = networks.Flip[outdir] + power.start_storage_calc(pos, Cable, outdir) +end + +local function stop_node(pos, nvm, state) + local outdir = M(pos):get_int("outdir") + power.start_storage_calc(pos, Cable, outdir) + outdir = networks.Flip[outdir] + power.start_storage_calc(pos, Cable, outdir) +end + +local State = techage.NodeStates:new({ + node_name_passive = "techage:ta4_electricmeter", + infotext_name = S("TA4 Electric Meter"), + cycle_time = CYCLE_TIME, + standby_ticks = 0, + formspec_func = formspec, + start_node = start_node, + stop_node = stop_node, +}) + +local function node_timer(pos, elapsed) + local nvm = techage.get_nvm(pos) + local data + if techage.is_running(nvm) then + local outdir2 = M(pos):get_int("outdir") + local outdir1 = networks.Flip[outdir2] + data = power.transfer_simplex(pos, Cable, outdir1, Cable, outdir2, PWR_PERF) + if data then + nvm.load = (data.curr_load1 / data.max_capa1 + data.curr_load2 / data.max_capa2) / 2 * PWR_PERF + nvm.moved = data.moved + nvm.units = (nvm.units or 0) + data.moved + end + end + if techage.is_activeformspec(pos) then + M(pos):set_string("formspec", formspec(State, pos, nvm, nvm.moved)) + end + return true +end + +local function on_rightclick(pos, node, clicker) + techage.set_activeformspec(pos, clicker) +end + +local function on_receive_fields(pos, formname, fields, player) + if minetest.is_protected(pos, player:get_player_name()) then + return + end + local nvm = techage.get_nvm(pos) + State:state_button_event(pos, nvm, fields) +end + +local function after_place_node(pos, placer, itemstack) + local meta = M(pos) + local nvm = techage.get_nvm(pos) + local own_num = techage.add_node(pos, "techage:ta4_electricmeter") + meta:set_string("owner", placer:get_player_name()) + local outdir = networks.side_to_outdir(pos, "R") + meta:set_int("outdir", outdir) + Cable:after_place_node(pos, {outdir, networks.Flip[outdir]}) + State:node_init(pos, nvm, own_num) +end + +local function after_dig_node(pos, oldnode, oldmetadata, digger) + local outdir = tonumber(oldmetadata.fields.outdir or 0) + Cable:after_dig_node(pos, {outdir, networks.Flip[outdir]}) + techage.del_mem(pos) +end + +local function get_generator_data(pos, outdir, tlib2) + local nvm = techage.get_nvm(pos) + -- check for secondary/generator side + if outdir == M(pos):get_int("outdir") then + if techage.is_running(nvm) then + return {level = (nvm.load or 0) / PWR_PERF, perf = PWR_PERF, capa = PWR_PERF * 2} + end + end +end + +minetest.register_node("techage:ta4_electricmeter", { + description = S("TA4 Electric Meter"), + tiles = { + -- up, down, right, left, back, front + "techage_filling_ta4.png^techage_frame_ta4_top.png^techage_appl_arrow.png", + "techage_filling_ta4.png^techage_frame_ta4.png", + "techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_hole_electric.png", + "techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_hole_electric.png", + "techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_meter.png", + "techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_meter.png", + }, + + on_timer = node_timer, + on_rightclick = on_rightclick, + on_receive_fields = on_receive_fields, + after_place_node = after_place_node, + after_dig_node = after_dig_node, + get_generator_data = get_generator_data, + paramtype2 = "facedir", + groups = {cracky=2, crumbly=2, choppy=2}, + on_rotate = screwdriver.disallow, + is_ground_content = false, + sounds = default.node_sound_wood_defaults(), +}) + +power.register_nodes({"techage:ta4_electricmeter"}, Cable, "gen", {"R", "L"}) + +-- for logical communication +techage.register_node({"techage:ta4_electricmeter"}, { + on_recv_message = function(pos, src, topic, payload) + local nvm = techage.get_nvm(pos) + if topic == "consumption" then + return math.floor((nvm.units or 0) / techage.CYCLES_PER_DAY) + else + return State:on_receive_message(pos, topic, payload) + end + end, +}) + +control.register_nodes({"techage:ta4_electricmeter"}, { + 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("TA4 Electric Meter"), + number = meta:get_string("node_number") or "", + running = techage.is_running(nvm) or false, + available = PWR_PERF, + provided = nvm.moved or 0, + termpoint = "-", + } + end + return false + end, + } +) + +minetest.register_craft({ + output = "techage:ta4_electricmeter", + recipe = { + {"default:steel_ingot", "dye:blue", "default:steel_ingot"}, + {"techage:electric_cableS", "basic_materials:gold_wire", "techage:electric_cableS"}, + {"default:steel_ingot", "techage:ta4_wlanchip", "default:steel_ingot"}, + }, +}) diff --git a/techage/power/laser.lua b/techage/ta4_power/laser.lua similarity index 94% rename from techage/power/laser.lua rename to techage/ta4_power/laser.lua index 7a0b359..58c89b4 100644 --- a/techage/power/laser.lua +++ b/techage/ta4_power/laser.lua @@ -19,8 +19,7 @@ local M = minetest.get_meta local S = techage.S local Cable = techage.ElectricCable -local power = techage.power -local networks = techage.networks +local power = networks.power minetest.register_node("techage:ta4_laser_emitter", { description = S("TA4 Laser Beam Emitter"), @@ -122,9 +121,7 @@ minetest.register_node("techage:ta4_laser_receiver", { sounds = default.node_sound_wood_defaults(), }) -Cable:add_secondary_node_names({"techage:ta4_laser_emitter", "techage:ta4_laser_receiver"}) -Cable:set_valid_sides("techage:ta4_laser_emitter", {"F"}) -Cable:set_valid_sides("techage:ta4_laser_receiver", {"F"}) +power.register_nodes({"techage:ta4_laser_emitter", "techage:ta4_laser_receiver"}, Cable, "special", {"F"}) minetest.register_craft({ output = "techage:ta4_laser_emitter", diff --git a/techage/ta4_power/transformer.lua b/techage/ta4_power/transformer.lua new file mode 100644 index 0000000..374bce6 --- /dev/null +++ b/techage/ta4_power/transformer.lua @@ -0,0 +1,183 @@ +--[[ + + TechAge + ======= + + Copyright (C) 2019-2021 Joachim Stolberg + + AGPL v3 + See LICENSE.txt for more information + + TA4 Isolation Transformer (to separate networks) + +]]-- + +-- for lazy programmers +local P2S = minetest.pos_to_string +local M = minetest.get_meta +local S = techage.S + +local CYCLE_TIME = 2 +local PWR_PERF = 100 + +local Cable = techage.ElectricCable +local power = networks.power +local control = networks.control + + +local function formspec(self, pos, nvm, data) + data = data or {curr_load1 = 0, curr_load2 = 0, max_capa1 = 0, max_capa2 = 0, moved = 0} + return "size[7.5,5.2]".. + default.gui_bg.. + default.gui_bg_img.. + default.gui_slots.. + "box[0,-0.1;7.3,0.5;#c6e8ff]".. + "label[0.2,-0.1;"..minetest.colorize( "#000000", S("TA4 Isolation Transformer")).."]".. + techage.formspec_storage_bar(pos, 0.0, 0.7, S("Storage"), data.curr_load1, data.max_capa1).. + techage.formspec_power_bar(pos, 2.5, 0.7, S("Power"), data.moved, PWR_PERF).. + techage.formspec_storage_bar(pos, 5.0, 0.7, S("Storage"), data.curr_load2, data.max_capa2).. + "image_button[3.3,4.3;1,1;" .. self:get_state_button_image(nvm) .. ";state_button;]" .. + "tooltip[3.3,4.3;1,1;" .. self:get_state_tooltip(nvm) .. "]" +end + +local function start_node(pos, nvm, state) + local outdir = M(pos):get_int("outdir") + power.start_storage_calc(pos, Cable, outdir) + outdir = networks.Flip[outdir] + power.start_storage_calc(pos, Cable, outdir) +end + +local function stop_node(pos, nvm, state) + local outdir = M(pos):get_int("outdir") + power.start_storage_calc(pos, Cable, outdir) + outdir = networks.Flip[outdir] + power.start_storage_calc(pos, Cable, outdir) +end + +local State = techage.NodeStates:new({ + node_name_passive = "techage:ta4_transformer", + infotext_name = S("TA4 Isolation Transformer"), + cycle_time = CYCLE_TIME, + standby_ticks = 0, + formspec_func = formspec, + start_node = start_node, + stop_node = stop_node, +}) + +local function node_timer(pos, elapsed) + local nvm = techage.get_nvm(pos) + local data + if techage.is_running(nvm) then + local outdir2 = M(pos):get_int("outdir") + local outdir1 = networks.Flip[outdir2] + data = power.transfer_duplex(pos, Cable, outdir1, Cable, outdir2, PWR_PERF) + if data then + nvm.load = (data.curr_load1 / data.max_capa1 + data.curr_load2 / data.max_capa2) / 2 * PWR_PERF + nvm.moved = data.moved + end + end + if techage.is_activeformspec(pos) then + M(pos):set_string("formspec", formspec(State, pos, nvm, data)) + end + return true +end + +local function on_rightclick(pos, node, clicker) + techage.set_activeformspec(pos, clicker) +end + +local function on_receive_fields(pos, formname, fields, player) + if minetest.is_protected(pos, player:get_player_name()) then + return + end + local nvm = techage.get_nvm(pos) + State:state_button_event(pos, nvm, fields) +end + +local function after_place_node(pos, placer, itemstack) + local meta = M(pos) + local nvm = techage.get_nvm(pos) + local own_num = techage.add_node(pos, "techage:ta4_transformer") + meta:set_string("owner", placer:get_player_name()) + local outdir = networks.side_to_outdir(pos, "R") + meta:set_int("outdir", outdir) + Cable:after_place_node(pos, {outdir, networks.Flip[outdir]}) + State:node_init(pos, nvm, own_num) +end + +local function after_dig_node(pos, oldnode, oldmetadata, digger) + local outdir = tonumber(oldmetadata.fields.outdir or 0) + Cable:after_dig_node(pos, {outdir, networks.Flip[outdir]}) + techage.del_mem(pos) +end + +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 + +minetest.register_node("techage:ta4_transformer", { + description = S("TA4 Isolation Transformer"), + tiles = { + -- up, down, right, left, back, front + "techage_filling_ta4.png^techage_frame_ta4_top.png^techage_appl_trafo.png", + "techage_filling_ta4.png^techage_frame_ta4.png", + "techage_trafo.png^techage_frame_ta4.png^techage_appl_hole_electric.png", + "techage_trafo.png^techage_frame_ta4.png^techage_appl_hole_electric.png", + "techage_trafo.png^techage_frame_ta4.png", + "techage_trafo.png^techage_frame_ta4.png", + }, + + on_timer = node_timer, + on_rightclick = on_rightclick, + on_receive_fields = on_receive_fields, + after_place_node = after_place_node, + after_dig_node = after_dig_node, + get_generator_data = get_generator_data, + paramtype2 = "facedir", + groups = {cracky=2, crumbly=2, choppy=2}, + on_rotate = screwdriver.disallow, + is_ground_content = false, + sounds = default.node_sound_wood_defaults(), +}) + +power.register_nodes({"techage:ta4_transformer"}, Cable, "gen", {"R", "L"}) + +-- for logical communication +techage.register_node({"techage:ta4_transformer"}, { + on_recv_message = function(pos, src, topic, payload) + return State:on_receive_message(pos, topic, payload) + end, +}) + +control.register_nodes({"techage:ta4_transformer"}, { + 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("TA4 Isolation Transformer"), + number = meta:get_string("node_number") or "", + running = techage.is_running(nvm) or false, + available = PWR_PERF, + provided = nvm.moved or 0, + termpoint = "-", + } + end + return false + end, + } +) + +minetest.register_craft({ + output = "techage:ta4_transformer", + recipe = { + {"default:steel_ingot", "dye:blue", "default:steel_ingot"}, + {"techage:electric_cableS", "basic_materials:copper_wire", "techage:electric_cableS"}, + {"default:steel_ingot", "techage:ta4_wlanchip", "default:steel_ingot"}, + }, +}) diff --git a/techage/textures/shrink.py b/techage/textures/shrink.py deleted file mode 100644 index 0cf29b8..0000000 --- a/techage/textures/shrink.py +++ /dev/null @@ -1,16 +0,0 @@ -import os, fnmatch - - -print(">>> Convert") -for filename in os.listdir("./"): - if fnmatch.fnmatch(filename, "*.png"): - print(filename) - os.system("pngquant --skip-if-larger --quality=80 --strip --output ./%s.new ./%s" % (filename, filename)) - -print("\n>>> Copy") -for filename in os.listdir("./"): - if fnmatch.fnmatch(filename, "*.new"): - print(filename) - os.remove("./" + filename[:-4]) - os.rename("./" + filename, "./" + filename[:-4]) - diff --git a/techage/textures/techage_appl_meter.png b/techage/textures/techage_appl_meter.png new file mode 100644 index 0000000..449e972 Binary files /dev/null and b/techage/textures/techage_appl_meter.png differ diff --git a/techage/textures/techage_appl_trafo.png b/techage/textures/techage_appl_trafo.png new file mode 100644 index 0000000..30c99c7 Binary files /dev/null and b/techage/textures/techage_appl_trafo.png differ diff --git a/techage/textures/techage_appl_turbine4.png b/techage/textures/techage_appl_turbine4.png index d1d8b52..eb4c916 100644 Binary files a/techage/textures/techage_appl_turbine4.png and b/techage/textures/techage_appl_turbine4.png differ diff --git a/techage/textures/techage_appl_winch.png b/techage/textures/techage_appl_winch.png new file mode 100644 index 0000000..b45c142 Binary files /dev/null and b/techage/textures/techage_appl_winch.png differ diff --git a/techage/textures/techage_appl_winch_hole.png b/techage/textures/techage_appl_winch_hole.png new file mode 100644 index 0000000..d4c2674 Binary files /dev/null and b/techage/textures/techage_appl_winch_hole.png differ diff --git a/techage/textures/techage_axle.png b/techage/textures/techage_axle.png index 5617ef0..6de95a6 100644 Binary files a/techage/textures/techage_axle.png and b/techage/textures/techage_axle.png differ diff --git a/techage/textures/techage_electric_switch.png b/techage/textures/techage_electric_switch.png index b890a51..736553c 100644 Binary files a/techage/textures/techage_electric_switch.png and b/techage/textures/techage_electric_switch.png differ diff --git a/techage/textures/techage_electric_switch_off.png b/techage/textures/techage_electric_switch_off.png new file mode 100644 index 0000000..2880073 Binary files /dev/null and b/techage/textures/techage_electric_switch_off.png differ diff --git a/techage/textures/techage_gaspipe_valve_open.png b/techage/textures/techage_gaspipe_valve_open.png index 45b929d..ef27b6f 100644 Binary files a/techage/textures/techage_gaspipe_valve_open.png and b/techage/textures/techage_gaspipe_valve_open.png differ diff --git a/techage/textures/techage_power_reduction.png b/techage/textures/techage_power_reduction.png new file mode 100644 index 0000000..6298226 Binary files /dev/null and b/techage/textures/techage_power_reduction.png differ diff --git a/techage/textures/techage_rope.png b/techage/textures/techage_rope.png new file mode 100644 index 0000000..f20a831 Binary files /dev/null and b/techage/textures/techage_rope.png differ diff --git a/techage/textures/techage_rope_inv.png b/techage/textures/techage_rope_inv.png new file mode 100644 index 0000000..7d54ddf Binary files /dev/null and b/techage/textures/techage_rope_inv.png differ diff --git a/techage/textures/techage_trafo.png b/techage/textures/techage_trafo.png new file mode 100644 index 0000000..0d9d49a Binary files /dev/null and b/techage/textures/techage_trafo.png differ diff --git a/techage/textures/techage_tube_junction.png b/techage/textures/techage_tube_junction.png index 8d44956..433d2e8 100644 Binary files a/techage/textures/techage_tube_junction.png and b/techage/textures/techage_tube_junction.png differ diff --git a/techage/textures/techage_weight_bottom.png b/techage/textures/techage_weight_bottom.png new file mode 100644 index 0000000..be4db17 Binary files /dev/null and b/techage/textures/techage_weight_bottom.png differ diff --git a/techage/textures/techage_weight_side.png b/techage/textures/techage_weight_side.png new file mode 100644 index 0000000..1f07d4f Binary files /dev/null and b/techage/textures/techage_weight_side.png differ diff --git a/techage/tools/repairkit.lua b/techage/tools/repairkit.lua index ea1a850..9a5d2bb 100644 --- a/techage/tools/repairkit.lua +++ b/techage/tools/repairkit.lua @@ -3,12 +3,11 @@ TechAge ======= - Copyright (C) 2017-2019 Joachim Stolberg + Copyright (C) 2017-2021 Joachim Stolberg AGPL v3 See LICENSE.txt for more information - repairkit.lua: ]]-- -- for lazy programmers @@ -18,178 +17,23 @@ local S = techage.S local Cable1 = techage.ElectricCable local Cable2 = techage.TA4_Cable local Pipe2 = techage.LiquidPipe -local networks = techage.networks +local menu = dofile(minetest.get_modpath("techage") .. "/tools/submenu.lua") -local ListOfNodes = { - ["techage:generator"] = true, - ["techage:generator_on"] = true, - ["techage:ta4_generator"] = true, - ["techage:ta4_generator_on"] = true, - ["techage:ta4_fuelcell"] = true, - ["techage:ta4_fuelcell_on"] = true, - ["techage:t3_pump"] = true, - ["techage:t3_pump_on"] = true, - ["techage:t4_pump"] = true, - ["techage:t4_pump_on"] = true, - ["techage:ta4_solar_inverter"] = true, - ["techage:flywheel"] = true, - ["techage:flywheel_on"] = true, - ["techage:tiny_generator"] = true, - ["techage:tiny_generator_on"] = true, - ["techage:ta4_electrolyzer"] = true, - ["techage:ta4_electrolyzer_on"] = true, - ["techage:oilfirebox"] = true, -} - - -local function delete_data(pos) - local meta = minetest.get_meta(pos) - local owner = meta:get_string("owner") - local number = meta:get_string("number") - local node_number = meta:get_string("node_number") - tubelib2.del_mem(pos) - meta:from_table(nil) - meta:set_string("owner", owner) - meta:set_string("number", number) - meta:set_string("node_number", node_number) -end - -local function inv_get_count(inv, listname, size) - local cnt = 0 - for i = 1,size do - cnt = cnt + inv:get_stack(listname, i):get_count() - end - return cnt -end - -local function inv_get_name(inv, listname, size) - for i = 1,size do - local name = inv:get_stack(listname, i):get_name() - if name ~= "" then - return name - end - end - return "" -end - -local function inv_clear(inv, listname, size) - for i = 1,size do - inv:set_stack(listname, i, nil) - end -end - -local function restore_inv_content(pos, listname, size) - local inv = M(pos):get_inventory() - local count = inv_get_count(inv, listname, size) - if count > 0 then - local nvm = techage.get_nvm(pos) - nvm.liquid = nvm.liquid or {} - nvm.liquid.amount = count - nvm.liquid.name = inv_get_name(inv, listname, size) - inv:set_stack(listname, 1, nil) - inv_clear(inv, listname, size) - return true - end - return false -end - -local function init_data(pos, netw) - local sides = netw.ele1 and netw.ele1.sides - if sides and sides["R"] then - M(pos):set_int("outdir", networks.side_to_outdir(pos, "R")) - M(pos):set_string("infotext", "repaired") - end - - sides = netw.pipe2 and netw.pipe2.sides - if sides and sides["R"] then - M(pos):set_int("outdir", networks.side_to_outdir(pos, "R")) - M(pos):set_string("infotext", "repaired") - end - - sides = netw.ele2 and netw.ele2.sides - if sides and sides["L"] then - M(pos):set_int("leftdir", networks.side_to_outdir(pos, "L")) - end - - sides = netw.axle and netw.axle.sides - if sides and sides["R"] then - M(pos):set_int("outdir", networks.side_to_outdir(pos, "R")) - end - - Cable1:after_place_node(pos) - Cable2:after_place_node(pos) - Pipe2:after_place_node(pos) -end - - -local function repair(itemstack, user, pointed_thing) - local pos = pointed_thing.under - if pos and user then - if minetest.is_protected(pos, user:get_player_name()) then - return itemstack - end - - local number = techage.get_node_number(pos) - local node = minetest.get_node(pos) - local ndef = minetest.registered_nodes[node.name] - if ndef then - local netw = ndef.networks - if netw and ListOfNodes[node.name] then - if node.name == "techage:tiny_generator" or node.name == "techage:tiny_generator_on" then - restore_inv_content(pos, "fuel", 1) - elseif node.name == "techage:oilfirebox" then - restore_inv_content(pos, "fuel", 1) - elseif node.name == "techage:ta4_fuelcell" or node.name == "techage:ta4_fuelcell_on" then - restore_inv_content(pos, "src", 4) - elseif node.name == "techage:ta4_electrolyzer" or node.name == "techage:ta4_electrolyzer_on" then - restore_inv_content(pos, "dst", 1) - end - delete_data(pos) - init_data(pos, netw) - minetest.chat_send_player(user:get_player_name(), ndef.description.." "..S("repaired")) - itemstack:add_wear(65636/200) - return itemstack - end - - if netw and netw.ele1 and netw.ele1.ntype == "junc" then - if ndef.after_place_node and ndef.tubelib2_on_update2 then - ndef.after_place_node(pos) - ndef.tubelib2_on_update2(pos, 0, Cable1) - minetest.chat_send_player(user:get_player_name(), ndef.description.." "..S("repaired")) - itemstack:add_wear(65636/200) - return itemstack - end - end - - if netw and netw.ele2 and netw.ele2.ntype == "junc" then - if ndef.after_place_node and ndef.tubelib2_on_update2 then - ndef.after_place_node(pos) - ndef.tubelib2_on_update2(pos, 0, Cable2) - minetest.chat_send_player(user:get_player_name(), ndef.description.." "..S("repaired")) - itemstack:add_wear(65636/200) - return itemstack - end - end - end - end - return itemstack -end - local function network_check(start_pos, Cable, player_name) - local ndef = techage.networks.net_def(start_pos, Cable.tube_type) - local outdir = nil - local num = 0 - if ndef and ndef.ntype ~= "junc" then - outdir = M(start_pos):get_int("outdir") - end - networks.connection_walk(start_pos, outdir, Cable, function(pos, indir, node) - local distance = vector.distance(start_pos, pos) - num = num + 1 - if distance < 50 and num < 100 then - local state = techage.power.power_available(pos, Cable) and "power" or "no power" - techage.mark_position(player_name, pos, state, "#ff0000", 6) - end - end) +-- local ndef = techage.networks.net_def(start_pos, Cable.tube_type) +-- local outdir = nil +-- local num = 0 +-- if ndef and ndef.ntype ~= "junc" then +-- outdir = M(start_pos):get_int("outdir") +-- end +-- networks.connection_walk(start_pos, outdir, Cable, function(pos, indir, node) +-- local distance = vector.distance(start_pos, pos) +-- num = num + 1 +-- if distance < 50 and num < 100 then +-- local state = techage.power.power_available(pos, Cable) and "power" or "no power" +-- techage.mark_position(player_name, pos, state, "#ff0000", 6) +-- end +-- end) end local function read_state(itemstack, user, pointed_thing) @@ -233,7 +77,7 @@ local function read_state(itemstack, user, pointed_thing) local info = techage.send_single("0", number, "info", nil) if info and info ~= "" and info ~= "unsupported" then info = dump(info) - minetest.chat_send_player(user:get_player_name(), ndef.description.." "..number..": Supported Commands:\n"..info.." ") + minetest.chat_send_player(user:get_player_name(), ndef.description.." "..number..":\n"..info.." ") end local state = techage.send_single("0", number, "state", nil) if state and state ~= "" and state ~= "unsupported" then @@ -260,6 +104,11 @@ local function read_state(itemstack, user, pointed_thing) delivered = dump(delivered) minetest.chat_send_player(user:get_player_name(), ndef.description.." "..number..": delivered = "..delivered.." ku ") end + local consumption = techage.send_single("0", number, "consumption", nil) + if consumption and consumption ~= "" and consumption ~= "unsupported" then + consumption = dump(consumption) + minetest.chat_send_player(user:get_player_name(), ndef.description.." "..number..": consumption = "..consumption.." kud ") + end local owner = M(pos):get_string("owner") or "" if owner ~= "" then minetest.chat_send_player(user:get_player_name(), S("Node owner")..": "..owner.." ") @@ -284,13 +133,64 @@ local function read_state(itemstack, user, pointed_thing) end end +local context = {} + +local function settings_menu(pos, playername) + local number = techage.get_node_number(pos) + local node = minetest.get_node(pos) + local ndef = minetest.registered_nodes[node.name] + local form_def = ndef and (ndef.ta3_formspec or ndef.ta4_formspec) + + context[playername] = pos + if form_def then + minetest.show_formspec(playername, "techage:ta_formspec", menu.generate_formspec(pos, ndef, form_def)) + end +end + +minetest.register_on_player_receive_fields(function(player, formname, fields) + if formname ~= "techage:ta_formspec" then + return false + end + + local playername = player:get_player_name() + local pos = context[playername] + if pos then + --context[playername] = nil + local number = techage.get_node_number(pos) + local node = minetest.get_node(pos) + local ndef = minetest.registered_nodes[node.name] + local form_def = ndef and (ndef.ta3_formspec or ndef.ta4_formspec) + + if form_def then + if menu.eval_input(pos, ndef, form_def, fields) then + --context[playername] = pos + minetest.after(0.2, function() + minetest.show_formspec(playername, "techage:ta_formspec", menu.generate_formspec(pos, ndef, form_def)) + end) + end + end + end + return true +end) + + +local function on_place(itemstack, placer, pointed_thing) + if pointed_thing.type == "node" then + local pos = pointed_thing.under + local playername = placer:get_player_name() + if placer:get_player_control().sneak then + settings_menu(pos, playername) + end + end +end + minetest.register_tool("techage:repairkit", { description = S("TechAge Repair Kit"), inventory_image = "techage_repairkit.png", wield_image = "techage_repairkit.png^[transformR270", groups = {cracky=1, book=1}, - on_use = repair, - on_place = repair, + --on_use = repair, + --on_place = repair, node_placement_prediction = "", stack_max = 1, }) @@ -302,21 +202,12 @@ minetest.register_tool("techage:end_wrench", { wield_image = "techage_end_wrench.png", groups = {cracky=1, book=1}, on_use = read_state, - on_place = read_state, + on_place = on_place, node_placement_prediction = "", liquids_pointable = true, stack_max = 1, }) ---minetest.register_craft({ --- output = "techage:repairkit", --- recipe = { --- {"", "basic_materials:gear_steel", ""}, --- {"", "techage:end_wrench", ""}, --- {"", "basic_materials:oil_extract", ""}, --- }, ---}) - minetest.register_craft({ output = "techage:end_wrench", recipe = { diff --git a/techage/tools/submenu.lua b/techage/tools/submenu.lua new file mode 100644 index 0000000..1e273f6 --- /dev/null +++ b/techage/tools/submenu.lua @@ -0,0 +1,211 @@ +--[[ + + TechAge + ======= + + Copyright (C) 2019-2021 Joachim Stolberg + + AGPL v3 + See LICENSE.txt for more information + + A formspec control to generate formspec strings for machine settings and monitoring +]]-- + +local S = techage.S + +local menu = {} + +local function index(list, x) + for idx, v in ipairs(list) do + if v == x then return idx end + end + return nil +end + + +-- generate the formspec string to be placed into a container frame +local function generate_formspec_substring(pos, meta, form_def) + local tbl = {} + if meta and form_def then + local nvm = techage.get_nvm(pos) + + for i,elem in ipairs(form_def) do + local offs = (i - 1) * 0.9 - 0.2 + tbl[#tbl+1] = "label[0," .. offs .. ";" .. minetest.formspec_escape(elem.label) .. ":]" + tbl[#tbl+1] = "tooltip[0," .. offs .. ";4,1;" .. elem.tooltip .. "]" + if elem.type == "number" then + local val = elem.default + if meta:contains(elem.name) then + val = meta:get_int(elem.name) + end + if nvm.running or techage.is_running(nvm) then + tbl[#tbl+1] = "label[4.75," .. offs .. ";" .. val .. "]" + else + tbl[#tbl+1] = "field[5," .. (offs+0.2) .. ";5.3,1;" .. elem.name .. ";;" .. val .. "]" + end + elseif elem.type == "numbers" then + local val = elem.default + if meta:contains(elem.name) then + val = meta:get_string(elem.name) + end + if nvm.running or techage.is_running(nvm) then + tbl[#tbl+1] = "label[4.75," .. offs .. ";" .. val .. "]" + else + tbl[#tbl+1] = "field[5," .. (offs+0.2) .. ";5.3,1;" .. elem.name .. ";;" .. val .. "]" + end + elseif elem.type == "float" then + local val = elem.default + if meta:contains(elem.name) then + val = tonumber(meta:get_string(elem.name)) or 0 + end + if nvm.running or techage.is_running(nvm) then + tbl[#tbl+1] = "label[4.75," .. offs .. ";" .. val .. "]" + else + tbl[#tbl+1] = "field[5," .. (offs+0.2) .. ";5.3,1;" .. elem.name .. ";;" .. val .. "]" + end + elseif elem.type == "ascii" then + local val = elem.default + if meta:contains(elem.name) then + val = meta:get_string(elem.name) + end + if nvm.running or techage.is_running(nvm) then + tbl[#tbl+1] = "label[4.75," .. offs .. ";" .. minetest.formspec_escape(val) .. "]" + else + tbl[#tbl+1] = "field[5," .. (offs+0.2) .. ";5.3,1;" .. elem.name .. ";;" .. minetest.formspec_escape(val) .. "]" + end + elseif elem.type == "const" then + tbl[#tbl+1] = "label[4.75," .. offs .. ";" .. elem.value .. "]" + elseif elem.type == "output" then + local val = nvm[elem.name] or "" + if tonumber(val) then + val = techage.round(val) + end + tbl[#tbl+1] = "label[4.75," .. offs .. ";" .. val .. "]" + elseif elem.type == "dropdown" then + local l = elem.choices:split(",") + if nvm.running or techage.is_running(nvm) then + local val = elem.default + if meta:contains(elem.name) then + val = meta:get_string(elem.name) or "" + end + tbl[#tbl+1] = "label[4.75," .. offs .. ";" .. val .. "]" + else + local val = elem.default + if meta:contains(elem.name) then + val = meta:get_string(elem.name) or "" + end + local idx = index(l, val) or 1 + tbl[#tbl+1] = "dropdown[4.72," .. (offs) .. ";5.5,1.4;" .. elem.name .. ";" .. elem.choices .. ";" .. idx .. "]" + end + end + end + if nvm.running or techage.is_running(nvm) then + local offs = #form_def * 0.9 - 0.2 + tbl[#tbl+1] = "label[0," .. offs .. ";" .. S("Note: You can't change any values while the block is running!") .. "]" + end + end + return table.concat(tbl, "") +end + +local function value_check(elem, value) + if elem.check then + return elem.check(value) + end + return true +end + +local function evaluate_data(pos, meta, form_def, fields) + local res = true + + if meta and form_def then + local nvm = techage.get_nvm(pos) + if nvm.running or techage.is_running(nvm) then + return res + end + for idx,elem in ipairs(form_def) do + if elem.type == "number" then + if fields[elem.name] then + if fields[elem.name]:find("^[%d ]+$") then + local val = tonumber(fields[elem.name]) + if value_check(elem, val) then + meta:set_int(elem.name, val) + --print("set_int", elem.name, val) + else + res = false + end + else + res = false + end + end + elseif elem.type == "numbers" then + if fields[elem.name] then + if fields[elem.name]:find("^[%d ]+$") and value_check(elem, fields[elem.name]) then + meta:set_string(elem.name, fields[elem.name]) + else + res = false + end + end + elseif elem.type == "float" then + if fields[elem.name] then + local val = tonumber(fields[elem.name]) + if val and value_check(elem, val) then + meta:set_string(elem.name, val) + else + res = false + end + end + elseif elem.type == "ascii" then + if fields[elem.name] then + if value_check(elem, fields[elem.name]) then + meta:set_string(elem.name, fields[elem.name]) + else + res = false + end + end + elseif elem.type == "dropdown" then + if fields[elem.name] ~= nil then + meta:set_string(elem.name, fields[elem.name]) + end + end + end + end + return res +end + +function menu.generate_formspec(pos, ndef, form_def) + local meta = minetest.get_meta(pos) + local number = techage.get_node_number(pos) + local mem = techage.get_mem(pos) + mem.star = ((mem.star or 0) + 1) % 2 + local star = mem.star == 1 and "*" or "" + + if meta and number and ndef and form_def then + local title = ndef.description .. " (" .. number .. ")" + + return "size[10,9]" .. + default.gui_bg .. + default.gui_bg_img .. + default.gui_slots .. + "box[0,-0.1;9.8,0.5;#c6e8ff]" .. + "label[0.2,-0.1;" .. minetest.colorize( "#000000", title) .. "]" .. + "label[9.5,-0.1;" .. minetest.colorize( "#000000", star) .. "]" .. + "container[0,1]" .. + generate_formspec_substring(pos, meta, form_def) .. + "container_end[]" .. + "button[0.5,8.4;3,1;refresh;" .. S("Refresh") .. "]" .. + "button_exit[3.5,8.4;3,1;cancel;" .. S("Cancel") .. "]" .. + "button[6.5,8.4;3,1;save;" .. S("Save") .. "]" + end + return "" +end + +function menu.eval_input(pos, ndef, form_def, fields) + --print(dump(fields)) + if fields.save then + local meta = minetest.get_meta(pos) + evaluate_data(pos, meta, form_def, fields) + end + return fields.refresh or fields.save +end + +return menu \ No newline at end of file diff --git a/techage/tools/trowel.lua b/techage/tools/trowel.lua index 6e895fe..2fa697d 100644 --- a/techage/tools/trowel.lua +++ b/techage/tools/trowel.lua @@ -17,53 +17,6 @@ local P = minetest.string_to_pos local M = minetest.get_meta local S = techage.S - --- used by other tools: dug_node[player_name] = pos -techage.dug_node = {} - --- Determine if one node in the surrounding is a hidden tube/cable/pipe -local function other_hidden_nodes(pos, node_name) - return M({x=pos.x+1, y=pos.y, z=pos.z}):get_string(node_name) ~= "" or - M({x=pos.x-1, y=pos.y, z=pos.z}):get_string(node_name) ~= "" or - M({x=pos.x, y=pos.y+1, z=pos.z}):get_string(node_name) ~= "" or - M({x=pos.x, y=pos.y-1, z=pos.z}):get_string(node_name) ~= "" or - M({x=pos.x, y=pos.y, z=pos.z+1}):get_string(node_name) ~= "" or - M({x=pos.x, y=pos.y, z=pos.z-1}):get_string(node_name) ~= "" -end - -local function hide_node(pos, node, meta, placer) - local inv = placer:get_inventory() - local stack = inv:get_stack("main", 1) - local taken = stack:take_item(1) - local ndef = minetest.registered_nodes[taken:get_name()] - -- test if it is a simple node without logic - if taken:get_count() == 1 - and ndef - and not ndef.groups.soil - and not ndef.after_place_node - and not ndef.on_construct then - meta:set_string("techage_hidden_nodename", node.name) - meta:set_string("techage_hidden_param2", node.param2) - local param2 = 0 - 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) - end -end - -local function open_node(pos, node, meta, placer) - local name = meta:get_string("techage_hidden_nodename") - local param2 = meta:get_string("techage_hidden_param2") - minetest.swap_node(pos, {name = name, param2 = param2}) - meta:set_string("techage_hidden_nodename", "") - meta:set_string("techage_hidden_param2", "") - local inv = placer:get_inventory() - inv:add_item("main", ItemStack(node.name)) -end - --- Hide or open a node local function replace_node(itemstack, placer, pointed_thing) if pointed_thing.type == "node" then local pos = pointed_thing.under @@ -71,17 +24,24 @@ local function replace_node(itemstack, placer, pointed_thing) if minetest.is_protected(pos, name) then return end - local meta = M(pos) - local node = minetest.get_node(pos) + local node = minetest.get_node(pos) + local res = false if minetest.get_item_group(node.name, "techage_trowel") == 1 then - hide_node(pos, node, meta, placer) - elseif meta:get_string("techage_hidden_nodename") ~= "" then - open_node(pos, node, meta, placer) + res = networks.hide_node(pos, node, placer) + elseif networks.hidden_name(pos) or M(pos):get_string("techage_hidden_nodename") ~= "" then + res = networks.open_node(pos, node, placer) + else + minetest.chat_send_player(placer:get_player_name(), "Invalid/unsuported block!") + return + 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 - minetest.sound_play("default_dig_snappy", { - pos = pos, - gain = 1, - max_hear_distance = 5}) end end @@ -97,20 +57,6 @@ minetest.register_tool("techage:trowel", { stack_max = 1, }) -minetest.register_on_dignode(function(pos, oldnode, digger) - if not digger then return end - -- If hidden nodes are arround, the removed one was probably - -- a hidden node, too. - if other_hidden_nodes(pos, "techage_hidden_nodename") then - -- test both hidden networks - techage.ElectricCable:after_dig_node(pos, oldnode, digger) - -- probably a hidden node with mem data - techage.del_mem(pos) - else - -- store pos for other tools without own 'register_on_dignode' - techage.dug_node[digger:get_player_name()] = pos - end -end) minetest.register_craft({ output = "techage:trowel", @@ -120,35 +66,3 @@ minetest.register_craft({ {"", "", "default:stick"}, }, }) - -local function get_new_can_dig(old_can_dig) - return function(pos, player, ...) - if M(pos):get_string("techage_hidden_nodename") ~= "" then - if player and player.get_player_name then - minetest.chat_send_player(player:get_player_name(), S("Use a trowel to remove the node.")) - end - return false - end - if old_can_dig then - return old_can_dig(pos, player, ...) - else - return true - end - end -end - --- Change can_dig for already registered nodes. -for _, ndef in pairs(minetest.registered_nodes) do - local old_can_dig = ndef.can_dig - minetest.override_item(ndef.name, { - can_dig = get_new_can_dig(old_can_dig) - }) -end - --- Change can_dig for all nodes that are going to be registered in the future. -local old_register_node = minetest.register_node -minetest.register_node = function(name, def) - local old_can_dig = def.can_dig - def.can_dig = get_new_can_dig(old_can_dig) - return old_register_node(name, def) -end diff --git a/techage/wind_turbine/pillar.lua b/techage/wind_turbine/pillar.lua index 8466106..cf75f7f 100644 --- a/techage/wind_turbine/pillar.lua +++ b/techage/wind_turbine/pillar.lua @@ -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 @@ -23,6 +23,8 @@ minetest.register_node("techage:pillar", { type = "fixed", fixed = {-8/32, -16/32, -8/32, 8/32, 16/32, 8/32}, }, + climbable = true, + walkable = false, paramtype = "light", backface_culling = true, groups = {cracky=1}, diff --git a/techage/wind_turbine/rotor.lua b/techage/wind_turbine/rotor.lua index 60cdaf6..97a6b26 100644 --- a/techage/wind_turbine/rotor.lua +++ b/techage/wind_turbine/rotor.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019-2020 DS-Minetest, Joachim Stolberg + Copyright (C) 2019-2021 DS-Minetest, Joachim Stolberg AGPL v3 See LICENSE.txt for more information @@ -21,11 +21,14 @@ local M = minetest.get_meta local S = techage.S +local STANDBY_TICKS = 4 local CYCLE_TIME = 2 local PWR_PERF = 70 +local COUNTDOWN_TICKS = 2 local Cable = techage.ElectricCable -local power = techage.power +local power = networks.power +local control = networks.control local Rotors = {} @@ -39,114 +42,157 @@ local Face2Dir = {[0]= } local function pos_and_yaw(pos, param2) - local dir = Face2Dir[param2] + local dir = Face2Dir[param2] or Face2Dir[0] local yaw = minetest.dir_to_yaw(dir) dir = vector.multiply(dir, 1.1) pos = vector.add(pos, dir) return pos, {x=0, y=yaw, z=0} end +local function is_windy() + local time = minetest.get_timeofday() or 0 + return (time >= 5.00/24.00 and time <= 9.00/24.00) or (time >= 17.00/24.00 and time <= 21.00/24.00) +end + local function check_rotor(pos, nvm) local resp, err = techage.valid_place_for_windturbine(pos, nil, 1) if not resp then - M(pos):set_string("infotext", S("TA4 Wind Turbine")..": "..err) - nvm.error = true + nvm.error = err return false end local npos = techage.get_pos(pos, "F") local node = techage.get_node_lvm(npos) if node.name ~= "techage:ta4_wind_turbine_nacelle" then - M(pos):set_string("infotext", S("TA4 Wind Turbine").." "..S("Nacelle is missing")) - nvm.error = true + nvm.error = S("Nacelle is missing") return false end local own_num = M(pos):get_string("node_number") or "" - M(pos):set_string("infotext", S("TA4 Wind Turbine").." "..own_num) + M(pos):set_string("infotext", S("TA4 Wind Turbine")..": "..own_num) nvm.error = false return true end -local function add_rotor(pos, nvm) - if check_rotor(pos, nvm) then +local function formspec(self, pos, nvm) + return techage.generator_formspec(self, pos, nvm, S("TA4 Wind Turbine"), nvm.provided, PWR_PERF) +end + +local function add_rotor(pos, nvm, force) + if (force and not nvm.error) or check_rotor(pos, nvm) then local hash = minetest.hash_node_position(pos) - if not Rotors[hash] then - local node = minetest.get_node(pos) - local npos, yaw = pos_and_yaw(pos, node.param2) - local obj = minetest.add_entity(npos, "techage:rotor_ent") - obj:set_animation({x = 0, y = 119}, 0, 0, true) - obj:set_rotation(yaw) - Rotors[hash] = obj + if Rotors[hash] then + Rotors[hash]:remove() end + local node = minetest.get_node(pos) + local npos, yaw = pos_and_yaw(pos, node.param2) + local obj = minetest.add_entity(npos, "techage:rotor_ent") + obj:set_animation({x = 0, y = 119}, 0, 0, true) + obj:set_rotation(yaw) + Rotors[hash] = obj end end -local function start_rotor(pos, nvm) +local function start_rotor(pos, nvm, state) if not nvm.error then - nvm.providing = true - nvm.delivered = 0 - power.generator_start(pos, Cable, CYCLE_TIME, 5) + local meta = M(pos) + nvm.provided = 0 + techage.evaluate_charge_termination(nvm, meta) + power.start_storage_calc(pos, Cable, 5) local hash = minetest.hash_node_position(pos) - if Rotors[hash] then + if Rotors[hash] and is_windy() then Rotors[hash]:set_animation_frame_speed(50) end end end -local function stop_rotor(pos, nvm) - nvm.providing = false - nvm.delivered = 0 - power.generator_stop(pos, Cable, 5) +local function stop_rotor(pos, nvm, state) + nvm.provided = 0 + nvm.load = 0 + power.start_storage_calc(pos, Cable, 5) local hash = minetest.hash_node_position(pos) if Rotors[hash] then Rotors[hash]:set_animation_frame_speed(0) end end +local function can_start(pos, nvm) + if nvm.error then + return nvm.error + end + return true +end + +local State = techage.NodeStates:new({ + node_name_passive = "techage:ta4_wind_turbine", + cycle_time = CYCLE_TIME, + standby_ticks = STANDBY_TICKS, + formspec_func = formspec, + start_node = start_rotor, + stop_node = stop_rotor, + can_start = can_start, +}) + local function node_timer(pos, elapsed) local nvm = techage.get_nvm(pos) - - if not nvm.running or nvm.error then - return false - end - - local time = minetest.get_timeofday() or 0 - if (time >= 5.00/24.00 and time <= 9.00/24.00) or (time >= 17.00/24.00 and time <= 21.00/24.00) then - if not nvm.providing then - start_rotor(pos, nvm) - end - else - if nvm.providing then - stop_rotor(pos, nvm) + local running = techage.is_running(nvm) + local windy = is_windy() + if running and not windy then + State:standby(pos, nvm) + stop_rotor(pos, nvm, State) + elseif not running and windy then + State:start(pos, nvm) + -- start_node() is called implicit + elseif running then + local meta = M(pos) + local tp1 = tonumber(meta:get_string("termpoint1")) + local tp2 = tonumber(meta:get_string("termpoint2")) + nvm.provided = power.provide_power(pos, Cable, 5, PWR_PERF, tp1, tp2) + local val = power.get_storage_load(pos, Cable, 5, PWR_PERF) + if val > 0 then + nvm.load = val end + State:keep_running(pos, nvm, COUNTDOWN_TICKS) + end + if techage.is_activeformspec(pos) then + M(pos):set_string("formspec", formspec(State, pos, nvm)) + end + return State:is_active(nvm) +end + +local function on_rightclick(pos, node, clicker) + techage.set_activeformspec(pos, clicker) + local nvm = techage.get_nvm(pos) + M(pos):set_string("formspec", formspec(State, pos, nvm)) +end + +local function on_receive_fields(pos, formname, fields, player) + if minetest.is_protected(pos, player:get_player_name()) then + return + end + local nvm = techage.get_nvm(pos) + State:state_button_event(pos, nvm, fields) + M(pos):set_string("formspec", formspec(State, pos, nvm)) +end + +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 - nvm.delivered = power.generator_alive(pos, Cable, CYCLE_TIME, 5, (nvm.providing and PWR_PERF) or 0) - return true end local function after_place_node(pos, placer) local meta = M(pos) local nvm = techage.get_nvm(pos) - local own_num = techage.add_node(pos, "techage:ta4_wind_turbine") - meta:set_string("node_number", own_num) + local number = techage.add_node(pos, "techage:ta4_wind_turbine") + State:node_init(pos, nvm, number) meta:set_string("owner", placer:get_player_name()) - nvm.providing = false - nvm.running = true + M(pos):set_string("formspec", formspec(State, pos, nvm)) add_rotor(pos, nvm) - minetest.get_node_timer(pos):start(CYCLE_TIME) Cable:after_place_node(pos) end -local function on_punch(pos, node, puncher, pointed_thing) - if minetest.is_protected(pos, puncher:get_player_name()) then - return - end - - local nvm = techage.get_nvm(pos) - add_rotor(pos, nvm) -end - local function after_dig_node(pos, oldnode, oldmetadata) local hash = minetest.hash_node_position(pos) if Rotors[hash] and Rotors[hash]:get_luaentity() then @@ -158,10 +204,6 @@ local function after_dig_node(pos, oldnode, oldmetadata) techage.del_mem(pos) end -local function tubelib2_on_update2(pos, outdir, tlib2, node) - power.update_network(pos, outdir, tlib2) -end - minetest.register_node("techage:ta4_wind_turbine", { description = S("TA4 Wind Turbine"), inventory_image = "techage_wind_turbine_inv.png", @@ -175,25 +217,41 @@ minetest.register_node("techage:ta4_wind_turbine", { "techage_rotor.png^techage_appl_open.png", }, - networks = { - ele1 = { - sides = {D = 1}, - ntype = "gen1", - nominal = PWR_PERF, - regenerative = true, - }, - }, after_place_node = after_place_node, after_dig_node = after_dig_node, - tubelib2_on_update2 = tubelib2_on_update2, + get_generator_data = get_generator_data, on_timer = node_timer, - on_punch = on_punch, + on_rightclick = on_rightclick, + on_receive_fields = on_receive_fields, paramtype2 = "facedir", groups = {cracky=2, crumbly=2, choppy=2}, is_ground_content = false, sounds = default.node_sound_metal_defaults(), + ta4_formspec = techage.generator_settings("ta4", PWR_PERF), }) +power.register_nodes({"techage:ta4_wind_turbine"}, Cable, "gen", {"D"}) + +control.register_nodes({"techage:ta4_wind_turbine"}, { + 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("TA4 Wind Turbine"), + 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_node("techage:ta4_wind_turbine_nacelle", { description = S("TA4 Wind Turbine Nacelle"), @@ -222,8 +280,6 @@ minetest.register_entity("techage:rotor_ent", {initial_properties = { static_save = false, }}) -Cable:add_secondary_node_names({"techage:ta4_wind_turbine"}) - techage.register_node({"techage:ta4_wind_turbine"}, { on_recv_message = function(pos, src, topic, payload) local nvm = techage.get_nvm(pos) @@ -234,7 +290,7 @@ techage.register_node({"techage:ta4_wind_turbine"}, { end if nvm.error then return "error" - elseif nvm.running and nvm.providing then + elseif techage.is_running(nvm) then return "running" else return "stopped" @@ -242,17 +298,16 @@ techage.register_node({"techage:ta4_wind_turbine"}, { elseif topic == "delivered" then return nvm.delivered or 0 elseif topic == "on" then - nvm.running = true + State:start(pos, nvm) elseif topic == "off" then - nvm.running = false + State:stop(pos, nvm) else return "unsupported" end end, on_node_load = function(pos) local nvm = techage.get_nvm(pos) - add_rotor(pos, nvm) - nvm.providing = false -- to force the rotor start + add_rotor(pos, nvm, true) minetest.get_node_timer(pos):start(CYCLE_TIME) end, }) diff --git a/tubelib2/README.md b/tubelib2/README.md index e7c9c2c..8403a59 100644 --- a/tubelib2/README.md +++ b/tubelib2/README.md @@ -88,5 +88,6 @@ Textures: CC0 - 2020-02-02 v1.8 * 'special nodes' as alternative to 'secondary nodes' introduced - 2020-05-31 v1.9 * Generator function 'get_tube_line' added, storage improvements - 2021-01-23 v2.0 * Add functions for easy & fast 'valid side' checking (PR #8) +- 2021-05-24 v2.1 * Add API functions 'register_on_tube_update2' diff --git a/tubelib2/internal1.lua b/tubelib2/internal1.lua index 5d7f5fa..daa2d2b 100644 --- a/tubelib2/internal1.lua +++ b/tubelib2/internal1.lua @@ -33,7 +33,7 @@ local function get_pos(pos, dir) end local function fdir(self, player) - local pitch = player:get_look_pitch() + local pitch = player:get_look_vertical() if pitch > 1.0 and self.valid_dirs[6] then -- up? return 6 elseif pitch < -1.0 and self.valid_dirs[5] then -- down? @@ -102,8 +102,12 @@ function Tube:update_secondary_node(pos1, dir1, pos2, dir2) local node,_ = self:get_secondary_node(pos1) if node then local ndef = minetest.registered_nodes[node.name] or {} + -- New functions if ndef.tubelib2_on_update2 then ndef.tubelib2_on_update2(pos1, dir1, self, node) + elseif self.clbk_update_secondary_node2 then + self.clbk_update_secondary_node2(pos1, dir1, self, node) + -- Legacy functions elseif ndef.tubelib2_on_update then ndef.tubelib2_on_update(node, pos1, dir1, pos2, Turn180Deg[dir2]) elseif self.clbk_update_secondary_node then diff --git a/tubelib2/internal2.lua b/tubelib2/internal2.lua index ffef3c8..3367a21 100644 --- a/tubelib2/internal2.lua +++ b/tubelib2/internal2.lua @@ -163,11 +163,13 @@ function Tube:get_next_tube(pos, dir) local val = Param2ToDir[param2 % 32] or 0 local dir1, dir2 = math.floor(val / 10), val % 10 local num_conn = math.floor(param2 / 32) or 0 - if Turn180Deg[dir] == dir1 then + local odir = Turn180Deg[dir] + if odir == dir1 then return npos, dir2, num_conn - else + elseif odir == dir2 then return npos, dir1, num_conn end + return end return self:get_next_teleport_node(pos, dir) end diff --git a/tubelib2/tube_api.lua b/tubelib2/tube_api.lua index e9996e4..b7789b4 100644 --- a/tubelib2/tube_api.lua +++ b/tubelib2/tube_api.lua @@ -13,7 +13,7 @@ ]]-- -- Version for compatibility checks, see readme.md/history -tubelib2.version = 2.0 +tubelib2.version = 2.1 -- for lazy programmers local S = function(pos) if pos then return minetest.pos_to_string(pos) end end @@ -320,6 +320,12 @@ function Tube:register_on_tube_update(update_secondary_node) self.clbk_update_secondary_node = update_secondary_node end +-- Called for each connected node when the tube connection has been changed. +-- func(pos1, out_dir, self, node) +function Tube:register_on_tube_update2(update_secondary_node2) + self.clbk_update_secondary_node2 = update_secondary_node2 +end + function Tube:get_pos(pos, dir) return vector.add(pos, Dir6dToVector[dir or 0]) end