Add check for wind turbine areas

This commit is contained in:
Joachim Stolberg 2020-10-11 17:57:15 +02:00
parent 51f08765ba
commit 43a2161d7e
3 changed files with 97 additions and 3 deletions

84
basis/windturbine_lib.lua Normal file
View File

@ -0,0 +1,84 @@
--[[
TechAge
=======
Copyright (C) 2019-2020 Joachim Stolberg
GPL v3
See LICENSE.txt for more information
Wind turbine helper function
]]--
local S = techage.S
local P = minetest.string_to_pos
local M = minetest.get_meta
local function chat_message(player_name, msg)
if player_name then
minetest.chat_send_player(player_name, S("[TA4 Wind Turbine]").." "..msg)
end
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
chat_message(player_name, S("This is not the surface of the ocean!"))
return false
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
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.." biome and no ocean!"))
return false
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, "")
chat_message(player_name,
S("Here is not enough wind (A free air space of 41x41x21 m is necessary)!"))
return false
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}
num = #minetest.find_nodes_in_area(pos1, pos2,
{"default:water_source", "default:water_flowing", "ignore"})
print(num, (41 * 41 * 0.9))
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
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}
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
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
end

View File

@ -84,6 +84,7 @@ dofile(MP.."/basis/assemble.lua")
dofile(MP.."/basis/networks.lua") dofile(MP.."/basis/networks.lua")
dofile(MP.."/basis/recipe_lib.lua") dofile(MP.."/basis/recipe_lib.lua")
dofile(MP.."/basis/formspec_update.lua") dofile(MP.."/basis/formspec_update.lua")
dofile(MP.."/basis/windturbine_lib.lua")
-- Main doc -- Main doc
dofile(MP.."/doc/manual_DE.lua") dofile(MP.."/doc/manual_DE.lua")

View File

@ -199,15 +199,23 @@ local function read_state(itemstack, user, pointed_thing)
local hours = math.floor(time / 6) local hours = math.floor(time / 6)
local mins = (time % 6) * 10 local mins = (time % 6) * 10
if mins < 10 then mins = "00" end if mins < 10 then mins = "00" end
local number = techage.get_node_number(pos)
local node = minetest.get_node(pos)
local ndef = minetest.registered_nodes[node.name]
if node.name == "default:water_source" then
local player_name = user:get_player_name()
techage.valid_place_for_windturbine(pos, player_name, 0)
return itemstack
end
minetest.chat_send_player(user:get_player_name(), S("Time")..": "..hours..":"..mins.." ") minetest.chat_send_player(user:get_player_name(), S("Time")..": "..hours..":"..mins.." ")
local data = minetest.get_biome_data(pos) local data = minetest.get_biome_data(pos)
if data then if data then
local name = minetest.get_biome_name(data.biome) local name = minetest.get_biome_name(data.biome)
minetest.chat_send_player(user:get_player_name(), S("Biome")..": "..name..", "..S("Position temperature")..": "..math.floor(data.heat).." ") minetest.chat_send_player(user:get_player_name(), S("Biome")..": "..name..", "..S("Position temperature")..": "..math.floor(data.heat).." ")
end end
local number = techage.get_node_number(pos)
local node = minetest.get_node(pos)
local ndef = minetest.registered_nodes[node.name]
if ndef and ndef.networks then if ndef and ndef.networks then
local player_name = user:get_player_name() local player_name = user:get_player_name()
@ -291,6 +299,7 @@ minetest.register_tool("techage:end_wrench", {
on_use = read_state, on_use = read_state,
on_place = read_state, on_place = read_state,
node_placement_prediction = "", node_placement_prediction = "",
liquids_pointable = true,
stack_max = 1, stack_max = 1,
}) })