Improve move/fly controller

This commit is contained in:
Joachim Stolberg 2021-12-24 16:05:04 +01:00
parent b75a9277b5
commit fd5b33e025
9 changed files with 89 additions and 37 deletions

View File

@ -50,6 +50,13 @@ local function lvect_subtract(lvect1, lvect2)
return lvect3 return lvect3
end 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 -- to_path function for the fly/move path
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
@ -89,13 +96,13 @@ function flylib.to_path(s, max_dist)
if line ~= "" then if line ~= "" then
local v = flylib.to_vector(line) local v = flylib.to_vector(line)
if v then if v then
--dist = dist + flylib.distance(v) dist = dist + flylib.distance(v)
--if not max_dist or dist <= max_dist then if not max_dist or dist <= max_dist then
tPath = tPath or {} tPath = tPath or {}
tPath[#tPath + 1] = v tPath[#tPath + 1] = v
--else else
-- return tPath, S("Error: Max. length of the flight route exceeded !!") return tPath, S("Error: Max. length of the flight route exceeded !!")
--end end
else else
return tPath, S("Error: Invalid path !!") return tPath, S("Error: Invalid path !!")
end end
@ -193,12 +200,27 @@ end
-- Attach player/mob to given parent object (block) -- Attach player/mob to given parent object (block)
local function attach_single_object(parent, obj, dir) local function attach_single_object(parent, obj, dir)
local self = parent:get_luaentity() local self = parent:get_luaentity()
local rot = obj:get_rotation()
local res = obj:get_attach() 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) 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) 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}}) obj:set_properties({visual_size = {x=2.9, y=2.9}})
if obj:is_player() then if obj:is_player() then
if lock_player(obj) then if lock_player(obj) then
@ -247,6 +269,7 @@ local function detach_objects(pos, self)
obj:set_detach() obj:set_detach()
obj:set_properties({visual_size = {x=1, y=1}}) obj:set_properties({visual_size = {x=1, y=1}})
local pos1 = vector.add(pos, item.offs) local pos1 = vector.add(pos, item.offs)
pos1.y = pos1.y + 0.1
obj:set_pos(pos1) obj:set_pos(pos1)
unlock_player(obj) unlock_player(obj)
end end

View File

@ -3,7 +3,7 @@
TechAge TechAge
======= =======
Copyright (C) 2019 Joachim Stolberg Copyright (C) 2019-2022 Joachim Stolberg
AGPL v3 AGPL v3
See LICENSE.txt for more information See LICENSE.txt for more information
@ -27,26 +27,6 @@ local Input = {
20,21,22,23, -- 6 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 -- Input data to turn a "facedir" block to the right/left
local ROTATION = { local ROTATION = {
{5,14,11,16}, -- x+ {5,14,11,16}, -- x+
@ -57,6 +37,33 @@ local ROTATION = {
{4,13,10,19}, -- z- {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 = {} local RotationViaYAxis = {}
for _,row in ipairs(ROTATION) do for _,row in ipairs(ROTATION) do
@ -69,8 +76,7 @@ for _,row in ipairs(ROTATION) do
end end
function techage.facedir_to_rotation(facedir) function techage.facedir_to_rotation(facedir)
local idx = PARAM2_TO_ROT[facedir] or 0 return FACEDIR_TO_ROT[facedir]
return Idx_to_Rot[idx]
end end
function techage.param2_turn_left(param2) function techage.param2_turn_left(param2)

View File

@ -66,6 +66,7 @@ local function pumping(pos, nvm, state, capa)
state:blocked(pos, nvm) state:blocked(pos, nvm)
return 0 return 0
end end
state:keep_running(pos, nvm, COUNTDOWN_TICKS)
return taken - leftover return taken - leftover
end end
state:keep_running(pos, nvm, COUNTDOWN_TICKS) state:keep_running(pos, nvm, COUNTDOWN_TICKS)

View File

@ -1305,8 +1305,6 @@ TA4 Turbine=
### turncontroller.lua ### ### turncontroller.lua ###
Center Pos=
Center block position for the turn, e.g.: 237,6,-125=
Click on all blocks that shall be turned= Click on all blocks that shall be turned=
TA4 Turn Controller= TA4 Turn Controller=
Turn left= Turn left=

View File

@ -664,7 +664,7 @@ This can also be used to simulate extendable stairs and the like.
[ta3_doorcontroller|image] [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. 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.

View File

@ -579,6 +579,11 @@ Der Move Controller unterstützt folgende techage Kommandos:
- `b2a` Bewege Block von B nach A - `b2a` Bewege Block von B nach A
- `move` Bewege Block auf die andere Seite - `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_movecontroller|image]
### TA4 Drehcontroller / Turn Controller ### TA4 Drehcontroller / Turn Controller

View File

@ -571,6 +571,11 @@ The Move Controller supports the following techage commands:
- `b2a` Move block from B to A. - `b2a` Move block from B to A.
- `move` Move block to the other side - `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_movecontroller|image]
### TA4 Turn Controller ### TA4 Turn Controller

View File

@ -22,7 +22,7 @@ local MP = minetest.get_modpath("techage")
local fly = dofile(MP .. "/basis/fly_lib.lua") local fly = dofile(MP .. "/basis/fly_lib.lua")
local mark = dofile(MP .. "/basis/mark_lib.lua") local mark = dofile(MP .. "/basis/mark_lib.lua")
local MAX_DIST = 200 local MAX_DIST = 500
local MAX_BLOCKS = 16 local MAX_BLOCKS = 16
local EX_PIONTS = 40 local EX_PIONTS = 40
@ -54,7 +54,7 @@ local function formspec(nvm, meta)
techage.wrench_image(7.4, -0.05) .. techage.wrench_image(7.4, -0.05) ..
"button[0.1,0.7;3.8,1;record;" .. S("Record") .. "]" .. "button[0.1,0.7;3.8,1;record;" .. S("Record") .. "]" ..
"button[4.1,0.7;3.8,1;done;" .. S("Done") .. "]" .. "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,1.8;3.8,1;store;" .. S("Store") .. "]" ..
"button[4.1,2.6;3.8,1;test;" .. S("Test") .. "]" .. "button[4.1,2.6;3.8,1;test;" .. S("Test") .. "]" ..
"button[4.1,3.4;3.8,1;moveAB;" .. S("Move A-B") .. "]" .. "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 elseif fields.done then
local name = player:get_player_name() local name = player:get_player_name()
local pos_list = mark.get_poslist(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.") local text = #pos_list.." "..S("block positions are stored.")
meta:set_string("status", text) meta:set_string("status", text)
nvm.lpos1 = pos_list nvm.lpos1 = pos_list
@ -155,6 +160,7 @@ minetest.register_node("techage:ta5_flycontroller", {
elseif fields.moveAB then elseif fields.moveAB then
meta:set_string("status", "") meta:set_string("status", "")
if fly.move_to_other_pos(pos, false) then if fly.move_to_other_pos(pos, false) then
nvm.moveBA = true
nvm.running = true nvm.running = true
meta:set_string("formspec", formspec(nvm, meta)) meta:set_string("formspec", formspec(nvm, meta))
local name = player:get_player_name() local name = player:get_player_name()
@ -164,6 +170,7 @@ minetest.register_node("techage:ta5_flycontroller", {
elseif fields.moveBA then elseif fields.moveBA then
meta:set_string("status", "") meta:set_string("status", "")
if fly.move_to_other_pos(pos, true) then if fly.move_to_other_pos(pos, true) then
nvm.moveBA = false
nvm.running = true nvm.running = true
meta:set_string("formspec", formspec(nvm, meta)) meta:set_string("formspec", formspec(nvm, meta))
local name = player:get_player_name() local name = player:get_player_name()
@ -174,6 +181,7 @@ minetest.register_node("techage:ta5_flycontroller", {
meta:set_string("status", "") meta:set_string("status", "")
nvm.moveBA = nvm.moveBA == false nvm.moveBA = nvm.moveBA == false
if fly.move_to_other_pos(pos, nvm.moveBA == false) then if fly.move_to_other_pos(pos, nvm.moveBA == false) then
nvm.moveBA = nvm.moveBA == false
nvm.running = true nvm.running = true
meta:set_string("formspec", formspec(nvm, meta)) meta:set_string("formspec", formspec(nvm, meta))
local name = player:get_player_name() local name = player:get_player_name()
@ -226,7 +234,7 @@ techage.register_node({"techage:ta5_flycontroller"}, {
minetest.register_craft({ minetest.register_craft({
output = "techage:ta5_flycontroller", output = "techage:ta5_flycontroller",
recipe = { recipe = {
{"default:steel_ingot", "dye:blue", "default:steel_ingot"}, {"default:steel_ingot", "dye:red", "default:steel_ingot"},
{"techage:aluminum", "techage:ta5_aichip", "techage:aluminum"}, {"techage:aluminum", "techage:ta5_aichip", "techage:aluminum"},
{"group:wood", "basic_materials:gear_steel", "group:wood"}, {"group:wood", "basic_materials:gear_steel", "group:wood"},
}, },

View File

@ -114,7 +114,11 @@ minetest.register_node("techage:ta4_movecontroller", {
elseif fields.done then elseif fields.done then
local name = player:get_player_name() local name = player:get_player_name()
local pos_list = mark.get_poslist(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.") local text = #pos_list.." "..S("block positions are stored.")
nvm.running = false
meta:set_string("status", text) meta:set_string("status", text)
nvm.lpos1 = pos_list nvm.lpos1 = pos_list
mark.unmark_all(name) mark.unmark_all(name)
@ -135,6 +139,7 @@ minetest.register_node("techage:ta4_movecontroller", {
elseif fields.moveAB then elseif fields.moveAB then
meta:set_string("status", "") meta:set_string("status", "")
if fly.move_to_other_pos(pos, false) then if fly.move_to_other_pos(pos, false) then
nvm.moveBA = true
nvm.running = true nvm.running = true
meta:set_string("formspec", formspec(nvm, meta)) meta:set_string("formspec", formspec(nvm, meta))
local name = player:get_player_name() local name = player:get_player_name()
@ -144,6 +149,7 @@ minetest.register_node("techage:ta4_movecontroller", {
elseif fields.moveBA then elseif fields.moveBA then
meta:set_string("status", "") meta:set_string("status", "")
if fly.move_to_other_pos(pos, true) then if fly.move_to_other_pos(pos, true) then
nvm.moveBA = false
nvm.running = true nvm.running = true
meta:set_string("formspec", formspec(nvm, meta)) meta:set_string("formspec", formspec(nvm, meta))
local name = player:get_player_name() local name = player:get_player_name()