From 3cca162bd7e356d23fb1df8dc42bcd0ae4a60e45 Mon Sep 17 00:00:00 2001 From: Joachim Stolberg Date: Mon, 14 Jun 2021 21:36:58 +0200 Subject: [PATCH] Add ta2 gravity energy storage system --- basis/rope_lib.lua | 84 ++++++++++++++++++++++++++++ init.lua | 2 + manuals/manual_ta2_DE.md | 2 +- manuals/manual_ta2_EN.md | 2 +- power/drive_axle.lua | 2 +- power/ta2_winch.lua | 112 ++++++++++++++++++++++++++++++++++++++ ta3_power/axle2power.lua | 2 - textures/techage_rope.png | Bin 0 -> 97 bytes 8 files changed, 201 insertions(+), 5 deletions(-) create mode 100644 basis/rope_lib.lua create mode 100644 power/ta2_winch.lua create mode 100644 textures/techage_rope.png diff --git a/basis/rope_lib.lua b/basis/rope_lib.lua new file mode 100644 index 0000000..7024103 --- /dev/null +++ b/basis/rope_lib.lua @@ -0,0 +1,84 @@ +--[[ + + TechAge + ======= + + Copyright (C) 2019-2021 Joachim Stolberg + + GPL v3 + See LICENSE.txt for more information + + Rope basis functions + +]]-- + +local Entities = {} + +-- Return first pos after start pos and the destination pos +local function get_positions(pos, length) + local pos1 = {x = pos.x, y = pos.y - 1, z = pos.z} -- start pos + local pos2 = {x = pos.x, y = pos.y - length, z = pos.z} -- end pos + 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.05, y = length}, collisionbox = {x = 0.05, y = length}}) + end + --print(pos1.y, pos2.y, pos3.y) + 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 = false, + collide_with_objects = false, + pointable = false, + static_save = false, + visual_size = {x = 0.05, y = 10, z = 0.05}, + shaded = true, + }, +}) + +------------------------------------------------------------------------------- +-- API functions +------------------------------------------------------------------------------- +function techage.renew_rope(pos, length) + local pos1, pos2 = get_positions(pos, length) + if pos1 then + add_rope(pos, pos1, pos2) + return pos1, pos2 + end +end + +-- techage.del_laser(pos) +techage.del_rope = del_rope diff --git a/init.lua b/init.lua index df08e80..1a37fc2 100644 --- a/init.lua +++ b/init.lua @@ -89,6 +89,7 @@ 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/rope_lib.lua") -- Main doc dofile(MP.."/doc/manual_DE.lua") @@ -114,6 +115,7 @@ dofile(MP.."/power/powerswitchbox.lua") dofile(MP.."/power/powerswitch.lua") dofile(MP.."/power/protection.lua") dofile(MP.."/power/power_line.lua") +dofile(MP.."/power/ta2_winch.lua") dofile(MP.."/power/ta4_cable.lua") dofile(MP.."/power/ta4_cable_wall_entry.lua") dofile(MP.."/power/laser.lua") diff --git a/manuals/manual_ta2_DE.md b/manuals/manual_ta2_DE.md index d6dc310..95b9492 100644 --- a/manuals/manual_ta2_DE.md +++ b/manuals/manual_ta2_DE.md @@ -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] diff --git a/manuals/manual_ta2_EN.md b/manuals/manual_ta2_EN.md index 0d4c30c..6697812 100644 --- a/manuals/manual_ta2_EN.md +++ b/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] diff --git a/power/drive_axle.lua b/power/drive_axle.lua index d67912e..77a7058 100644 --- a/power/drive_axle.lua +++ b/power/drive_axle.lua @@ -21,7 +21,7 @@ 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"}, diff --git a/power/ta2_winch.lua b/power/ta2_winch.lua new file mode 100644 index 0000000..fd5a8ed --- /dev/null +++ b/power/ta2_winch.lua @@ -0,0 +1,112 @@ +--[[ + + TechAge + ======= + + Copyright (C) 2019-2021 Joachim Stolberg + + GPL v3 + See LICENSE.txt for more information + + TA4 Laser beam emitter and receiver + +]]-- + +-- 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 STORAGE_CAPA = 1000 + +local Axle = techage.Axle +local power = networks.power + +minetest.register_node("techage:ta2_winch", { + description = S("TA2 Winch"), + tiles = { + -- up, down, right, left, back, front + "techage_filling_ta4.png^techage_frame_ta4_top.png", + "techage_filling_ta4.png^techage_frame_ta4.png", + "techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_laser.png", + "techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_laser.png", + "techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_laser_hole.png", + "techage_filling_ta4.png^techage_frame_ta4.png^techage_appl_hole_electric.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}) + local pos1, pos2 = techage.renew_rope(pos, 10) + local pos3 = {x = pos1.x, y = (pos1.y + pos2.y) / 2, z = pos1.z} -- mid-pos + minetest.add_entity(pos3, "techage:ta2_weight_chest") + minetest.get_node_timer(pos):start(2) + power.start_storage_calc(pos, Axle, outdir) + end, + + on_timer = function(pos, elapsed) + local nvm = techage.get_nvm(pos) + local mem = techage.get_mem(pos) + local outdir = M(pos):get_int("outdir") + + --power.start_storage_calc(pos, Axle, outdir) + + nvm.load = power.get_storage_load(pos, Axle, outdir, STORAGE_CAPA) + if nvm.load then + print("on_timer" , nvm.load) + local len = 11 - (nvm.load / STORAGE_CAPA * 10) + local y = pos.y - len + techage.renew_rope(pos, len) + 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") + end + --print("on_timer", nvm.load) + return true + end, + + after_dig_node = function(pos, oldnode, oldmetadata) + 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, tlib2) + local nvm = techage.get_nvm(pos) + return {level = (nvm.load or 0) / STORAGE_CAPA, capa = STORAGE_CAPA} + end, + + paramtype2 = "facedir", + groups = {choppy=2, cracky=2, crumbly=2}, + is_ground_content = false, + sounds = default.node_sound_wood_defaults(), +}) + +minetest.register_entity("techage:ta2_weight_chest", { + initial_properties = { + physical = true, + collisionbox = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, + visual = "wielditem", + textures = {"techage:chest_ta2"}, + visual_size = {x=0.66, y=0.66, z=0.66}, + static_save = false, + }, + driver_allowed = true, +}) + +power.register_nodes({"techage:ta2_winch"}, Axle, "sto", {"R"}) + +--minetest.register_craft({ +-- output = "techage:ta4_laser_emitter", +-- recipe = { +-- {"techage:ta4_carbon_fiber", "dye:blue", "techage:ta4_carbon_fiber"}, +-- {"techage:electric_cableS", "basic_materials:energy_crystal_simple", "techage:ta4_leds"}, +-- {"default:steel_ingot", "techage:ta4_wlanchip", "default:steel_ingot"}, +-- }, +--}) + diff --git a/ta3_power/axle2power.lua b/ta3_power/axle2power.lua index 1663666..43f5839 100644 --- a/ta3_power/axle2power.lua +++ b/ta3_power/axle2power.lua @@ -42,7 +42,6 @@ local function node_timer_on(pos, elapsed) local amount = math.min(PWR_PERF * 2 - nvm.buffer, PWR_PERF) local taken = power.consume_power(pos, Axle, networks.Flip[outdir], amount) - print("node_timer_on", amount, taken, nvm.buffer) nvm.buffer = nvm.buffer + taken - 1 -- some loss if nvm.buffer >= PWR_PERF then @@ -51,7 +50,6 @@ local function node_timer_on(pos, elapsed) 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 - print("provided", nvm.provided, nvm.load, nvm.buffer) end if amount > 0 and taken == 0 then swap_node(pos, "techage:ta2_generator_off") diff --git a/textures/techage_rope.png b/textures/techage_rope.png new file mode 100644 index 0000000000000000000000000000000000000000..f20a831ee81f47ffb4eb4bf1a04c7ec6668264de GIT binary patch literal 97 zcmeAS@N?(olHy`uVBq!ia0vp^OhBx_#0(@|_c(R|Db4_&5LZiG6<1@`U@Nuv*DO{7 s1%*9b978y+CkrGLB+NK4;edl0FN2vs7vqG+Par)Ep00i_>zopr0I}E?Z~y=R literal 0 HcmV?d00001