From fd5b33e02545b6edeb749876d90d908eb03469ad Mon Sep 17 00:00:00 2001 From: Joachim Stolberg Date: Fri, 24 Dec 2021 16:05:04 +0100 Subject: [PATCH] Improve move/fly controller --- basis/fly_lib.lua | 39 +++++++++++++++++----- basis/lib.lua | 52 +++++++++++++++++------------- liquids/pump.lua | 1 + locale/template.txt | 2 -- manuals/manual_ta3_EN.md | 2 +- manuals/manual_ta4_DE.md | 5 +++ manuals/manual_ta4_EN.md | 5 +++ move_controller/flycontroller.lua | 14 ++++++-- move_controller/movecontroller.lua | 6 ++++ 9 files changed, 89 insertions(+), 37 deletions(-) diff --git a/basis/fly_lib.lua b/basis/fly_lib.lua index 7ea3156..00b1cea 100644 --- a/basis/fly_lib.lua +++ b/basis/fly_lib.lua @@ -50,6 +50,13 @@ local function lvect_subtract(lvect1, lvect2) return lvect3 end +-- yaw in radiant +local function rotate(v, yaw) + local sinyaw = math.sin(2 * math.pi - yaw) + local cosyaw = math.cos(2 * math.pi - yaw) + return {x = v.x * cosyaw - v.z * sinyaw, y = v.y, z = v.x * sinyaw + v.z * cosyaw} +end + ------------------------------------------------------------------------------- -- to_path function for the fly/move path ------------------------------------------------------------------------------- @@ -89,13 +96,13 @@ function flylib.to_path(s, max_dist) if line ~= "" then local v = flylib.to_vector(line) if v then - --dist = dist + flylib.distance(v) - --if not max_dist or dist <= max_dist then + dist = dist + flylib.distance(v) + if not max_dist or dist <= max_dist then tPath = tPath or {} tPath[#tPath + 1] = v - --else - -- return tPath, S("Error: Max. length of the flight route exceeded !!") - --end + else + return tPath, S("Error: Max. length of the flight route exceeded !!") + end else return tPath, S("Error: Invalid path !!") end @@ -193,12 +200,27 @@ end -- Attach player/mob to given parent object (block) local function attach_single_object(parent, obj, dir) local self = parent:get_luaentity() - local rot = obj:get_rotation() local res = obj:get_attach() - if not res then + if not res then -- not already attached + local yaw + if obj:is_player() then + yaw = obj:get_look_horizontal() + else + yaw = obj:get_rotation().y + end + -- store for later use local offs = table.copy(dir) + -- Calc entity rotation, which is relative to the parent's rotation + local rot = parent:get_rotation() + dir = rotate(dir, rot.y) + if self.param2 >= 20 then + dir.y = -dir.y + rot.y = rot.y - yaw + elseif self.param2 < 4 then + rot.y = rot.y - yaw + end dir = vector.multiply(dir, 29) - obj:set_attach(parent, "", dir, rot, true) + obj:set_attach(parent, "", dir, vector.multiply(rot, 180 / math.pi)) obj:set_properties({visual_size = {x=2.9, y=2.9}}) if obj:is_player() then if lock_player(obj) then @@ -247,6 +269,7 @@ local function detach_objects(pos, self) obj:set_detach() obj:set_properties({visual_size = {x=1, y=1}}) local pos1 = vector.add(pos, item.offs) + pos1.y = pos1.y + 0.1 obj:set_pos(pos1) unlock_player(obj) end diff --git a/basis/lib.lua b/basis/lib.lua index 201d270..6b83c27 100644 --- a/basis/lib.lua +++ b/basis/lib.lua @@ -3,7 +3,7 @@ TechAge ======= - Copyright (C) 2019 Joachim Stolberg + Copyright (C) 2019-2022 Joachim Stolberg AGPL v3 See LICENSE.txt for more information @@ -27,26 +27,6 @@ local Input = { 20,21,22,23, -- 6 } --- Input data for facedir_to_rotation -local PARAM2_TO_ROT = {[0] = - 1,39,35,47, - 49,38,32,48, - 17,14,56,8, - 2,50,12,28, - 4,20,10,52, - 3,7,11,15 -} - -local Idx_to_Rot = {} - -for x = 0,3 do - for y = 0,3 do - for z = 0,3 do - Idx_to_Rot[#Idx_to_Rot + 1] = {x=x*math.pi/2, y=y*math.pi/2, z=z*math.pi/2} - end - end -end - -- Input data to turn a "facedir" block to the right/left local ROTATION = { {5,14,11,16}, -- x+ @@ -57,6 +37,33 @@ local ROTATION = { {4,13,10,19}, -- z- } +local FACEDIR_TO_ROT = {[0] = + {x=0.000000, y=0.000000, z=0.000000}, + {x=0.000000, y=4.712389, z=0.000000}, + {x=0.000000, y=3.141593, z=0.000000}, + {x=0.000000, y=1.570796, z=0.000000}, + {x=4.712389, y=0.000000, z=0.000000}, + {x=3.141593, y=1.570796, z=1.570796}, + {x=1.570796, y=4.712389, z=4.712389}, + {x=3.141593, y=4.712389, z=4.712389}, + {x=1.570796, y=0.000000, z=0.000000}, + {x=0.000000, y=4.712389, z=1.570796}, + {x=4.712389, y=1.570796, z=4.712389}, + {x=0.000000, y=1.570796, z=4.712389}, + {x=0.000000, y=0.000000, z=1.570796}, + {x=4.712389, y=0.000000, z=1.570796}, + {x=0.000000, y=3.141593, z=4.712389}, + {x=1.570796, y=3.141593, z=4.712389}, + {x=0.000000, y=0.000000, z=4.712389}, + {x=1.570796, y=0.000000, z=4.712389}, + {x=0.000000, y=3.141593, z=1.570796}, + {x=4.712389, y=0.000000, z=4.712389}, + {x=0.000000, y=0.000000, z=3.141593}, + {x=0.000000, y=1.570796, z=3.141593}, + {x=0.000000, y=3.141593, z=3.141593}, + {x=0.000000, y=4.712389, z=3.141593}, +} + local RotationViaYAxis = {} for _,row in ipairs(ROTATION) do @@ -69,8 +76,7 @@ for _,row in ipairs(ROTATION) do end function techage.facedir_to_rotation(facedir) - local idx = PARAM2_TO_ROT[facedir] or 0 - return Idx_to_Rot[idx] + return FACEDIR_TO_ROT[facedir] end function techage.param2_turn_left(param2) diff --git a/liquids/pump.lua b/liquids/pump.lua index e50b245..9f25800 100644 --- a/liquids/pump.lua +++ b/liquids/pump.lua @@ -66,6 +66,7 @@ local function pumping(pos, nvm, state, capa) state:blocked(pos, nvm) return 0 end + state:keep_running(pos, nvm, COUNTDOWN_TICKS) return taken - leftover end state:keep_running(pos, nvm, COUNTDOWN_TICKS) diff --git a/locale/template.txt b/locale/template.txt index 4baf18d..6f8547d 100644 --- a/locale/template.txt +++ b/locale/template.txt @@ -1305,8 +1305,6 @@ TA4 Turbine= ### turncontroller.lua ### -Center Pos= -Center block position for the turn, e.g.: 237,6,-125= Click on all blocks that shall be turned= TA4 Turn Controller= Turn left= diff --git a/manuals/manual_ta3_EN.md b/manuals/manual_ta3_EN.md index 3cc0d7a..82b6f81 100644 --- a/manuals/manual_ta3_EN.md +++ b/manuals/manual_ta3_EN.md @@ -664,7 +664,7 @@ This can also be used to simulate extendable stairs and the like. [ta3_doorcontroller|image] -### TA3 sound block +### TA3 Sound Block Different sounds can be played with the sound block. All sounds of the Mods Techage, Signs Bot, Hyperloop, Unified Inventory, TA4 Jetpack and Minetest Game are available. diff --git a/manuals/manual_ta4_DE.md b/manuals/manual_ta4_DE.md index 0feefa4..6fb5341 100644 --- a/manuals/manual_ta4_DE.md +++ b/manuals/manual_ta4_DE.md @@ -579,6 +579,11 @@ Der Move Controller unterstützt folgende techage Kommandos: - `b2a` Bewege Block von B nach A - `move` Bewege Block auf die andere Seite +**Wichtige Hinweise:** + +- Sofern mehrere Blöcke bewegt werden sollen, muss der Block, der die Spieler/Mobs mitnehmen soll, beim Antrainieren als erstes angeklickt werden. +- Hat der Block, der die Spieler/Mobs mitnehmen soll, eine reduzierte Höhe, so muss die Höhe im Controller über das Schraubenschlüsselmenü eingestellt werden (bspw. Höhe = 0.5). Ansonsten wird der Spieler/Mob nicht "gefunden" und damit nicht mitgenommen. + [ta4_movecontroller|image] ### TA4 Drehcontroller / Turn Controller diff --git a/manuals/manual_ta4_EN.md b/manuals/manual_ta4_EN.md index 1b94e4c..fdf03e7 100644 --- a/manuals/manual_ta4_EN.md +++ b/manuals/manual_ta4_EN.md @@ -571,6 +571,11 @@ The Move Controller supports the following techage commands: - `b2a` Move block from B to A. - `move` Move block to the other side +**Important instructions:** + +- If several blocks are to be moved, the block that is to take the players/mobs must be clicked first when training. +- If the block that is supposed to take the players/mobs has a reduced height, the height must be set in the controller using the open-ended wrench menu (e.g. height = 0.5). Otherwise the player/mob will not be "found" and will not be taken away. + [ta4_movecontroller|image] ### TA4 Turn Controller diff --git a/move_controller/flycontroller.lua b/move_controller/flycontroller.lua index 45cc1d9..cb10a1f 100644 --- a/move_controller/flycontroller.lua +++ b/move_controller/flycontroller.lua @@ -22,7 +22,7 @@ local MP = minetest.get_modpath("techage") local fly = dofile(MP .. "/basis/fly_lib.lua") local mark = dofile(MP .. "/basis/mark_lib.lua") -local MAX_DIST = 200 +local MAX_DIST = 500 local MAX_BLOCKS = 16 local EX_PIONTS = 40 @@ -54,7 +54,7 @@ local function formspec(nvm, meta) techage.wrench_image(7.4, -0.05) .. "button[0.1,0.7;3.8,1;record;" .. S("Record") .. "]" .. "button[4.1,0.7;3.8,1;done;" .. S("Done") .. "]" .. - "textarea[0.4,2.1;3.8,4.4;path;" .. S("Move path (A to B)") .. ";"..path.."]" .. + "textarea[0.4,2.1;3.8,4.4;path;" .. S("Flight route (A to B)") .. ";"..path.."]" .. "button[4.1,1.8;3.8,1;store;" .. S("Store") .. "]" .. "button[4.1,2.6;3.8,1;test;" .. S("Test") .. "]" .. "button[4.1,3.4;3.8,1;moveAB;" .. S("Move A-B") .. "]" .. @@ -105,6 +105,11 @@ minetest.register_node("techage:ta5_flycontroller", { elseif fields.done then local name = player:get_player_name() local pos_list = mark.get_poslist(name) + local _, err = fly.to_path(fields.path, MAX_DIST) + if not err then + meta:set_string("path", fields.path) + end + nvm.running = false local text = #pos_list.." "..S("block positions are stored.") meta:set_string("status", text) nvm.lpos1 = pos_list @@ -155,6 +160,7 @@ minetest.register_node("techage:ta5_flycontroller", { elseif fields.moveAB then meta:set_string("status", "") if fly.move_to_other_pos(pos, false) then + nvm.moveBA = true nvm.running = true meta:set_string("formspec", formspec(nvm, meta)) local name = player:get_player_name() @@ -164,6 +170,7 @@ minetest.register_node("techage:ta5_flycontroller", { elseif fields.moveBA then meta:set_string("status", "") if fly.move_to_other_pos(pos, true) then + nvm.moveBA = false nvm.running = true meta:set_string("formspec", formspec(nvm, meta)) local name = player:get_player_name() @@ -174,6 +181,7 @@ minetest.register_node("techage:ta5_flycontroller", { meta:set_string("status", "") nvm.moveBA = nvm.moveBA == false if fly.move_to_other_pos(pos, nvm.moveBA == false) then + nvm.moveBA = nvm.moveBA == false nvm.running = true meta:set_string("formspec", formspec(nvm, meta)) local name = player:get_player_name() @@ -226,7 +234,7 @@ techage.register_node({"techage:ta5_flycontroller"}, { minetest.register_craft({ output = "techage:ta5_flycontroller", recipe = { - {"default:steel_ingot", "dye:blue", "default:steel_ingot"}, + {"default:steel_ingot", "dye:red", "default:steel_ingot"}, {"techage:aluminum", "techage:ta5_aichip", "techage:aluminum"}, {"group:wood", "basic_materials:gear_steel", "group:wood"}, }, diff --git a/move_controller/movecontroller.lua b/move_controller/movecontroller.lua index e283991..8068124 100644 --- a/move_controller/movecontroller.lua +++ b/move_controller/movecontroller.lua @@ -114,7 +114,11 @@ minetest.register_node("techage:ta4_movecontroller", { elseif fields.done then local name = player:get_player_name() local pos_list = mark.get_poslist(name) + if fly.to_vector(fields.path or "", MAX_DIST) then + meta:set_string("path", fields.path) + end local text = #pos_list.." "..S("block positions are stored.") + nvm.running = false meta:set_string("status", text) nvm.lpos1 = pos_list mark.unmark_all(name) @@ -135,6 +139,7 @@ minetest.register_node("techage:ta4_movecontroller", { elseif fields.moveAB then meta:set_string("status", "") if fly.move_to_other_pos(pos, false) then + nvm.moveBA = true nvm.running = true meta:set_string("formspec", formspec(nvm, meta)) local name = player:get_player_name() @@ -144,6 +149,7 @@ minetest.register_node("techage:ta4_movecontroller", { elseif fields.moveBA then meta:set_string("status", "") if fly.move_to_other_pos(pos, true) then + nvm.moveBA = false nvm.running = true meta:set_string("formspec", formspec(nvm, meta)) local name = player:get_player_name()