mirror of
https://github.com/Sokomine/markers.git
synced 2025-07-04 16:10:22 +02:00
start to implement RAZ
This commit is contained in:
163
init.lua
163
init.lua
@ -1,50 +1,54 @@
|
||||
|
||||
-- markers are useful for measuring distances and for marking areas
|
||||
-- markers are useful for measuring distances and for marking areas, regions or zones
|
||||
-- it should work with areas and raz
|
||||
-- markers are protected from digging by other players for one day
|
||||
-- (the protection for the *marker* auto-expires then, and it can be digged)
|
||||
|
||||
markers = {}
|
||||
|
||||
dofile(minetest.get_modpath("markers").."/config.lua");
|
||||
dofile(minetest.get_modpath("markers").."/areas.lua");
|
||||
dofile(minetest.get_modpath("markers").."/marker_stone.lua");
|
||||
dofile(minetest.get_modpath("markers").."/land_title_register.lua");
|
||||
markers = {
|
||||
|
||||
|
||||
-- returns the first area found
|
||||
markers.get_area_by_pos1_pos2 = function(pos1, pos2)
|
||||
for id, area in pairs(areas.areas) do
|
||||
-- Paths and infos to the mod
|
||||
worlddir = minetest.get_worldpath(),
|
||||
modname = minetest.get_current_modname(),
|
||||
modpath = minetest.get_modpath(minetest.get_current_modname()),
|
||||
mod_areas_present = nil,
|
||||
mod_raz_present = nil,
|
||||
}
|
||||
|
||||
if( ((area.pos1.x == pos1.x and area.pos1.z == pos1.z )
|
||||
or (area.pos1.x == pos1.x and area.pos1.z == pos2.z )
|
||||
or (area.pos1.x == pos2.x and area.pos1.z == pos1.z )
|
||||
or (area.pos1.x == pos2.x and area.pos1.z == pos2.z ))
|
||||
|
||||
and((area.pos2.x == pos1.x and area.pos2.z == pos1.z )
|
||||
or (area.pos2.x == pos1.x and area.pos2.z == pos2.z )
|
||||
or (area.pos2.x == pos2.x and area.pos2.z == pos1.z )
|
||||
or (area.pos2.x == pos2.x and area.pos2.z == pos2.z ))) then
|
||||
-- load the .luas
|
||||
dofile(markers.modpath.."/config.lua")
|
||||
dofile(markers.modpath.."/functions.lua")
|
||||
|
||||
-- at least pos1 needs to have a hight value that fits in
|
||||
if( (area.pos1.y <= pos1.y and area.pos2.y >= pos1.y)
|
||||
or (area.pos1.y >= pos1.y and area.pos2.y <= pos1.y)) then
|
||||
-- check if areas or raz is installed
|
||||
markers.mod_areas_present = minetest.get_modpath("areas")
|
||||
markers.mod_raz_present = minetest.get_modpath("raz")
|
||||
|
||||
local found = area;
|
||||
found[ 'id' ] = id;
|
||||
return found;
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
return nil;
|
||||
if markers.mod_areas_present and markers.mod_raz_present then
|
||||
minetest.log("error", "[" .. markers.modname .. "] areas and raz is installed - what shall be used!!!!!!")
|
||||
elseif markers.mod_areas_present and not markers.mod_raz_present then
|
||||
dofile(modpath.."/areas.lua")
|
||||
minetest.log("action", "[" .. markers.modname .. "] areas is installed - load areas.lua")
|
||||
elseif markers.mod_raz_present and not markers.mod_areas_present then
|
||||
dofile(markers.modpath.."/raz.lua")
|
||||
minetest.log("action", "[" .. markers.modname .. "] raz is installed - load raz.lua")
|
||||
else
|
||||
minetest.log("error", "[" .. markers.modname .. "] I fond no installed version of areas or raz - what shall be used!!!!!!")
|
||||
end
|
||||
|
||||
|
||||
dofile(markers.modpath.."/marker_stone.lua")
|
||||
dofile(markers.modpath.."/land_title_register.lua")
|
||||
|
||||
|
||||
|
||||
|
||||
-- this function is supposed to return a text string describing the price of the land between po1 and pos2
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-- this function is supposed to return a text string describing the price of the land between pos1 and pos2
|
||||
-- You can return somethiing like "for free" or "the promise to build anything good" as well as any
|
||||
-- real prices in credits or materials - it's really just a text here.
|
||||
-- Make sure you do not charge the player more than what you ask here.
|
||||
@ -278,8 +282,7 @@ markers.get_marker_formspec = function(player, pos, error_msg)
|
||||
|
||||
-- has the area already been defined?
|
||||
local area = markers.get_area_by_pos1_pos2( coords[1], coords[2] );
|
||||
|
||||
|
||||
|
||||
local size = (math.abs( coords[1].x - coords[2].x )+1)
|
||||
* (math.abs( coords[1].z - coords[2].z )+1);
|
||||
|
||||
@ -339,103 +342,7 @@ end
|
||||
|
||||
|
||||
|
||||
-- protect/buy an area
|
||||
markers.marker_on_receive_fields = function(pos, formname, fields, sender)
|
||||
|
||||
if( not( pos )) then
|
||||
minetest.chat_send_player( name, 'Sorry, could not find the marker you where using to access this formspec.' );
|
||||
return;
|
||||
end
|
||||
|
||||
|
||||
local meta = minetest.get_meta( pos );
|
||||
|
||||
local name = sender:get_player_name();
|
||||
|
||||
local coords_string = meta:get_string( 'coords' );
|
||||
if( not( coords_string ) or coords_string == '' ) then
|
||||
minetest.chat_send_player( name, 'Could not find marked area. Please dig and place your markers again!');
|
||||
return;
|
||||
end
|
||||
local coords = minetest.deserialize( coords_string );
|
||||
|
||||
|
||||
-- do not protect areas twice
|
||||
local area = markers.get_area_by_pos1_pos2( coords[1], coords[2] );
|
||||
if( area ) then
|
||||
|
||||
minetest.chat_send_player( name, 'This area is already protected.');
|
||||
return;
|
||||
end
|
||||
|
||||
|
||||
-- check input
|
||||
local add_height = tonumber( fields['add_height'] );
|
||||
local add_depth = tonumber( fields['add_depth'] );
|
||||
|
||||
local error_msg = '';
|
||||
if( not( add_height ) or add_height < 0 or add_height > markers.MAX_HEIGHT ) then
|
||||
minetest.chat_send_player( name, 'Please enter a number between 0 and '..tostring( markers.MAX_HEIGHT )..
|
||||
' in the field where the height of your area is requested. Your area will stretch that many blocks '..
|
||||
'up into the sky from the position of this marker onward.');
|
||||
error_msg = 'The height value\nhas to be larger than 0\nand smaller than '..tostring( markers.MAX_HEIGHT );
|
||||
|
||||
elseif( not( add_depth ) or add_depth < 0 or add_depth > markers.MAX_HEIGHT ) then
|
||||
minetest.chat_send_player( name, 'Please enter a number between 0 and '..tostring( markers.MAX_HEIGHT )..
|
||||
' in the field where the depth of your area is requested. Your area will stretch that many blocks '..
|
||||
'into the ground from the position of this marker onward.');
|
||||
error_msg = 'The depth value\nhas to be larger than 0\nand smaller than '..tostring( markers.MAX_HEIGHT );
|
||||
|
||||
elseif( add_height + add_depth > markers.MAX_HEIGHT ) then
|
||||
minetest.chat_send_player( name, 'Sorry, your area exceeds the height limit. Height and depth added have to '..
|
||||
'be smaller than '..tostring( markers.MAX_HEIGHT )..'.');
|
||||
error_msg = 'height + depth has to\nbe smaller than '..tostring( markers.MAX_HEIGHT )..'.'
|
||||
|
||||
elseif( not( fields[ 'set_area_name' ] ) or fields['set_area_name'] == 'please enter a name' ) then
|
||||
minetest.chat_send_player( name, 'Please provide a name for your area, i.e. \"'..
|
||||
tostring( name )..'s first house\" The name ought to describe what you intend to build here.');
|
||||
error_msg = 'Please provide a\nname for your area!';
|
||||
|
||||
else
|
||||
error_msg = nil;
|
||||
end
|
||||
|
||||
|
||||
if( error_msg ~= nil ) then
|
||||
minetest.show_formspec( name, "markers:mark", markers.get_marker_formspec(sender, pos, error_msg));
|
||||
return;
|
||||
end
|
||||
|
||||
|
||||
-- those coords lack the height component
|
||||
local pos1 = coords[1];
|
||||
local pos2 = coords[2];
|
||||
-- apply height values from the formspeck
|
||||
pos1.y = pos1.y - add_depth;
|
||||
pos2.y = pos2.y + add_height;
|
||||
|
||||
pos1, pos2 = areas:sortPos( pos1, pos2 );
|
||||
|
||||
--minetest.chat_send_player('singleplayer','INPUT: '..minetest.serialize( pos1 )..' pos2: '..minetest.serialize( pos2 ));
|
||||
minetest.log("action", "[markers] /protect invoked, owner="..name..
|
||||
" areaname="..fields['set_area_name']..
|
||||
" startpos="..minetest.pos_to_string(pos1)..
|
||||
" endpos=" ..minetest.pos_to_string(pos2));
|
||||
|
||||
local canAdd, errMsg = areas:canPlayerAddArea(pos1, pos2, name)
|
||||
if not canAdd then
|
||||
minetest.chat_send_player(name, "You can't protect that area: "..errMsg)
|
||||
minetest.show_formspec( name, "markers:mark", markers.get_marker_formspec(sender, pos, errMsg));
|
||||
return
|
||||
end
|
||||
|
||||
local id = areas:add(name, fields['set_area_name'], pos1, pos2, nil)
|
||||
areas:save()
|
||||
|
||||
minetest.chat_send_player(name, "Area protected. ID: "..id)
|
||||
|
||||
minetest.show_formspec( name, "markers:mark", markers.get_marker_formspec(sender, pos, nil));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user