Improve techage:ta4_wind_turbine checks

master
Joachim Stolberg 2021-03-14 16:00:45 +01:00
parent b632ee6212
commit efc364bbfc
7 changed files with 68 additions and 51 deletions

View File

@ -20,6 +20,7 @@ local function chat_message(player_name, msg)
if player_name then
minetest.chat_send_player(player_name, S("[TA4 Wind Turbine]").." "..msg)
end
return false, msg
end
-- num_turbines is the mx number of valid wind turbines. In the case of a tool
@ -29,20 +30,17 @@ function techage.valid_place_for_windturbine(pos, player_name, num_turbines)
-- Check if occean (only for tool)
if num_turbines == 0 and pos.y ~= 1 then
chat_message(player_name, S("This is not the surface of the ocean!"))
return false
return chat_message(player_name, S("This is not the surface of the ocean!"))
end
local node = minetest.get_node(pos)
if num_turbines == 0 and node.name ~= "default:water_source" then
chat_message(player_name, S("This is no ocean water!"))
return false
return chat_message(player_name, S("This is no ocean water!"))
end
local data = minetest.get_biome_data({x=pos.x, y=-2, z=pos.z})
if data then
local name = minetest.get_biome_name(data.biome)
if not string.find(name, "ocean") then
chat_message(player_name, S("This is a").." "..name.." "..S("biome and no ocean!"))
return false
return chat_message(player_name, S("This is a").." "..name.." "..S("biome and no ocean!"))
end
end
-- check the space over ocean
@ -51,9 +49,8 @@ function techage.valid_place_for_windturbine(pos, player_name, num_turbines)
num = #minetest.find_nodes_in_area(pos1, pos2, {"air", "ignore"})
if num < (41 * 41 * 21 * 0.9) then
techage.mark_region(player_name, pos1, pos2, "")
chat_message(player_name,
S("Here is not enough wind (A free air space of 41x41x21 m is necessary)!"))
return false
return chat_message(player_name,
S("Here is not enough wind\n(A free air space of 41x41x21 m is necessary)!"))
end
-- Check for water surface (occean)
pos1 = {x=pos.x-20, y=1, z=pos.z-20}
@ -63,8 +60,7 @@ function techage.valid_place_for_windturbine(pos, player_name, num_turbines)
if num < (41*41 * 0.8) then
techage.mark_region(player_name, pos1, pos2, "")
chat_message(player_name, S("Here is not enough water (41x41 m)!"))
return false
return chat_message(player_name, S("Here is not enough water (41x41 m)!"))
end
-- Check for next wind turbine
pos1 = {x=pos.x-13, y=2, z=pos.z-13}
@ -73,13 +69,12 @@ function techage.valid_place_for_windturbine(pos, player_name, num_turbines)
num = #minetest.find_nodes_in_area(pos1, pos2, {"techage:ta4_wind_turbine"})
if num > num_turbines then
techage.mark_region(player_name, pos1, pos2, "")
chat_message(player_name, S("The next wind turbines is too close!"))
return false
return chat_message(player_name, S("The next wind turbines is too close!"))
end
if num_turbines == 0 then
chat_message(player_name, minetest.pos_to_string(pos).." "..
S("is a suitable place for a wind turbine!"))
end
return true
return true, "ok"
end

View File

@ -1147,7 +1147,9 @@ 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"..
"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"..
"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"..
"\n"..
"\n"..
"\n",

View File

@ -1124,7 +1124,9 @@ 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"..
"If all conditions are met\\, the rotor blades appear automatically when this block is set. Otherwise you will see an error message.\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"..
"\n"..
"\n"..
"\n",

View File

@ -1050,7 +1050,7 @@ This is not the surface of the ocean!=Das ist nicht die Meeresoberfläche!
This is no ocean water!= Dies ist kein Meerwasser!
This is a=Dies ist ein
biome and no ocean!=Biom und keine Meer (ocean)!
Here is not enough wind (A free air space of 41x41x21 m is necessary)!=Hier ist nicht genug Wind (Ein freier Luftraum von 41x41x21 m ist notwendig)!
Here is not enough wind@n(A free air space of 41x41x21 m is necessary)!=Hier ist nicht genug Wind@n(Ein freier Luftraum von 41x41x21 m ist notwendig)!
Here is not enough water (41x41 m)!=Hier ist nicht genug Wasser (41x41 m)!
The next wind turbines is too close!= Die nächste Windkraftanlagen iat zu nahe!
is a suitable place for a wind turbine!=ist ein geeigneter Ort für eine Windkraftanlage!

View File

@ -23,7 +23,9 @@ 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.
Sofern alle Bedingungen erfüllt sind, erscheinen beim Setzen dieses Blocks auch automatisch die Rotorblätter (Flügel). Anderenfalls wird dir eine Fehlermeldung angezeigt.
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.
[ta4_windturbine|image]

View File

@ -23,7 +23,9 @@ 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.
If all conditions are met, the rotor blades appear automatically when this block is set. Otherwise you will see an error message.
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.
[ta4_windturbine|image]

View File

@ -29,8 +29,6 @@ local power = techage.power
local Rotors = {}
local MAX_NUM_FOREIGN_NODES = 50
local Face2Dir = {[0]=
{x=0, y=0, z=1},
{x=1, y=0, z=0},
@ -48,44 +46,51 @@ local function pos_and_yaw(pos, param2)
return pos, {x=0, y=yaw, z=0}
end
local function add_rotor(pos, nvm, player_name)
nvm.error = false
if not techage.valid_place_for_windturbine(pos, player_name, 1) then
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
M(pos):set_string("infotext", S("TA4 Wind Turbine")..": "..S("Not suitable position!"))
return
return false
end
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
end
local own_num = M(pos):get_string("node_number") or ""
M(pos):set_string("infotext", S("TA4 Wind Turbine").." "..own_num)
end
local function start_rotor(pos, nvm)
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
return
return false
end
nvm.providing = true
nvm.delivered = 0
power.generator_start(pos, Cable, CYCLE_TIME, 5)
local hash = minetest.hash_node_position(pos)
if Rotors[hash] then
Rotors[hash]:set_animation_frame_speed(50)
local own_num = M(pos):get_string("node_number") or ""
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 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
end
end
end
local function start_rotor(pos, nvm)
if not nvm.error then
nvm.providing = true
nvm.delivered = 0
power.generator_start(pos, Cable, CYCLE_TIME, 5)
local hash = minetest.hash_node_position(pos)
if Rotors[hash] then
Rotors[hash]:set_animation_frame_speed(50)
end
end
end
@ -126,14 +131,22 @@ local function after_place_node(pos, placer)
local own_num = techage.add_node(pos, "techage:ta4_wind_turbine")
meta:set_string("node_number", own_num)
meta:set_string("owner", placer:get_player_name())
meta:set_string("infotext", S("TA4 Wind Turbine").." "..own_num)
nvm.providing = false
nvm.running = true
add_rotor(pos, nvm, placer:get_player_name())
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
@ -174,6 +187,7 @@ minetest.register_node("techage:ta4_wind_turbine", {
after_dig_node = after_dig_node,
tubelib2_on_update2 = tubelib2_on_update2,
on_timer = node_timer,
on_punch = on_punch,
paramtype2 = "facedir",
groups = {cracky=2, crumbly=2, choppy=2},
is_ground_content = false,