skytardis_2025/skybuilding.lua

85 lines
2.5 KiB
Lua
Raw Normal View History

-- Create the sky buldings, check for them
2016-12-03 19:01:35 +08:00
function skytardis:checkOwnerAt(pos,owner)
2016-12-02 17:38:29 +08:00
local tellermeta = minetest.get_meta(pos)
local knownowner = tellermeta.get_string("owner")
if knownowner and knownowner ~= owner then
return false
end
return true
end
2016-12-03 19:01:35 +08:00
function skytardis:setOwnerAt(pos,owner)
2016-12-02 17:38:29 +08:00
local tellermeta = minetest.get_meta(pos)
local knownowner = tellermeta.get_string("owner")
2016-12-03 19:01:35 +08:00
if not skytardis:checkOwnerAt(pos,owner) then
2016-12-02 17:38:29 +08:00
return false
end
tellermeta.set_string("owner",owner)
return true
end
2016-12-02 17:38:29 +08:00
--------------------------------------------- getting
2016-12-03 19:01:35 +08:00
function skytardis:getSkyBoundsFor(landx,landz)
local bounds = skytardis:derive_blockbounds(landx,landz)
local base_altitude = skytardis:derive_altitude(lanxd,landz)
bounds.pos1.y = base_altitude
bounds.pos2.y = pase_altitude
return bounds
end
2016-12-03 19:01:35 +08:00
function skytardis:getSkyStructureFor(landx, landz)
-- get the sky structure info, given the land coordinates
2016-12-03 19:01:35 +08:00
local bounds = skytardis:getSkyBoundsFor(landx,landz)
local tellermeta = minetest.get_meta(bounds.pos1)
local owner = tellermeta.get_string("owner")
-- returns a table {owner,pos} identifying the owner of the structure and the position of the door
if owner then
return {
owner = owner,
pos = math.floor( ( bounds.pos1.x + bounds.pos2.x ) / 2),
}
end
-- or nil if nothing appropriate was found
end
2016-12-02 17:38:29 +08:00
----------------------------------------------------- setting
2016-12-03 19:01:35 +08:00
function skytardis:setSkyStructureAt(skypos)
2016-12-02 17:38:29 +08:00
-- TODO -- load schematic
-- load a vmanip for the coords
-- load a sky structure schematic into the vmanip
end
2016-12-03 19:01:35 +08:00
function skytardis:setSkyStructureFor(landx, landz, owner)
local bounds = skytardis:getSkyBoundsFor(landx,landz)
if not bounds then
minetest.log("error","Could not get bounds (%s , %s)":format(landx,landz))
return
end
-- check owner
2016-12-03 19:01:35 +08:00
if not skytardis:checkOwnerAt(bounds.pos1,owner) then
2016-12-02 17:38:29 +08:00
minetest.chat_send_player(owner,"ABORT - your pocket dimension interferes with that of "..knownowner)
return false
end
2016-12-03 19:01:35 +08:00
if skytardis:setSkyStructureAt(bounds.pos1) then -- takes care of file opening etc
2016-12-02 17:38:29 +08:00
minetest.chat_send_player(owner,"Could not create sky structure")
minetest.log("error","Could not set sky structure at "..minetest.pos_to_string(nounds.pos1).." for "..owner)
end
2016-12-03 19:01:35 +08:00
if not skytardis:setOwnerAt(bounds.pos1,owner) then
minetest.chat_send_player(owner,"Could not set owner !")
minetest.log("error","Could not set owner for "..owner.." at "..minetest.pos_to_string(bounds.pos1) )
2016-12-03 19:01:35 +08:00
minetest.log("error",dump(skytardis:getSkyStructureFor(bounds.pos1) ))
return false
end
return true
end