techage/basis/windturbine_lib.lua

87 lines
2.6 KiB
Lua
Raw Permalink Normal View History

2020-10-11 18:57:15 +03:00
--[[
TechAge
=======
2023-04-13 21:20:58 +03:00
Copyright (C) 2019-2023 Joachim Stolberg
2020-10-11 18:57:15 +03:00
2020-10-19 20:09:17 +03:00
AGPL v3
2020-10-11 18:57:15 +03:00
See LICENSE.txt for more information
2022-01-03 23:40:31 +03:00
2020-10-11 18:57:15 +03:00
Wind turbine helper function
]]--
local S = techage.S
local P = minetest.string_to_pos
local M = minetest.get_meta
2023-04-13 21:20:58 +03:00
local OCEAN = "ocean"
if minetest.global_exists("asuna") then
OCEAN = "below"
end
2020-10-11 18:57:15 +03:00
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
2020-10-11 18:57:15 +03:00
end
-- num_turbines is the mx number of valid wind turbines. In the case of a tool
-- it should be 0, in case of the rotor: 1
function techage.valid_place_for_windturbine(pos, player_name, num_turbines)
local pos1, pos2, num
-- Check if occean (only for tool)
if num_turbines == 0 and pos.y ~= 1 then
return chat_message(player_name, S("This is not the surface of the ocean!"))
2020-10-11 18:57:15 +03:00
end
local node = minetest.get_node(pos)
if num_turbines == 0 and node.name ~= "default:water_source" then
return chat_message(player_name, S("This is no ocean water!"))
2020-10-11 18:57:15 +03:00
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)
2023-04-13 21:20:58 +03:00
if not string.find(name, OCEAN) then
return chat_message(player_name, S("This is a").." "..name.." "..S("biome and no ocean!"))
2020-10-11 18:57:15 +03:00
end
end
-- check the space over ocean
pos1 = {x=pos.x-20, y=2, z=pos.z-20}
pos2 = {x=pos.x+20, y=22, z=pos.z+20}
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, "")
2022-01-03 23:40:31 +03:00
return chat_message(player_name,
S("Here is not enough wind\n(A free air space of 41x41x21 m is necessary)!"))
2020-10-11 18:57:15 +03:00
end
-- Check for water surface (occean)
pos1 = {x=pos.x-20, y=1, z=pos.z-20}
pos2 = {x=pos.x+20, y=1, z=pos.z+20}
2022-01-03 23:40:31 +03:00
num = #minetest.find_nodes_in_area(pos1, pos2,
2020-10-11 18:57:15 +03:00
{"default:water_source", "default:water_flowing", "ignore"})
2022-01-03 23:40:31 +03:00
2020-10-11 18:57:15 +03:00
if num < (41*41 * 0.8) then
techage.mark_region(player_name, pos1, pos2, "")
return chat_message(player_name, S("Here is not enough water (41x41 m)!"))
2020-10-11 18:57:15 +03:00
end
-- Check for next wind turbine
pos1 = {x=pos.x-13, y=2, z=pos.z-13}
pos2 = {x=pos.x+13, y=22, z=pos.z+13}
2020-10-11 18:57:15 +03:00
num = #minetest.find_nodes_in_area(pos1, pos2, {"techage:ta4_wind_turbine"})
if num > num_turbines then
techage.mark_region(player_name, pos1, pos2, "")
return chat_message(player_name, S("The next wind turbines is too close!"))
2020-10-11 18:57:15 +03:00
end
2022-01-03 23:40:31 +03:00
2020-10-11 18:57:15 +03:00
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, "ok"
end