static vertical size setting

This commit is contained in:
Evert Prants 2019-01-20 16:45:50 +02:00
parent 82c7c9d694
commit ea08c52b01
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
5 changed files with 49 additions and 15 deletions

View File

@ -9,9 +9,14 @@ local modpath = minetest.get_modpath(minetest.get_current_modname())
towny = { towny = {
modpath = modpath, modpath = modpath,
regions = { regions = {
size = tonumber(minetest.settings:get('towny_claim_size')) or 16, size = tonumber(minetest.settings:get('towny_claim_size')) or 16,
height = tonumber(minetest.settings:get('towny_claim_height')) or 64, height = tonumber(minetest.settings:get('towny_claim_height')) or 64,
distance = tonumber(minetest.settings:get('towny_distance')) or 80, distance = tonumber(minetest.settings:get('towny_distance')) or 80,
vertical = {
static = minetest.settings:get_bool('towny_static_height', false),
miny = tonumber(minetest.settings:get('towny_static_miny')) or -32000,
maxy = tonumber(minetest.settings:get('towny_static_maxy')) or 32000,
},
-- Regions loaded into memory cache, see "Town regions data structure" -- Regions loaded into memory cache, see "Town regions data structure"
memloaded = {}, memloaded = {},

View File

@ -102,6 +102,12 @@ function towny.regions.ensure_range(p)
p1 = p[1] p1 = p[1]
p2 = p[2] p2 = p[2]
end end
if towny.regions.vertical.static then
p1.y = towny.regions.vertical.maxy
p2.y = towny.regions.vertical.miny
end
return p1,p2 return p1,p2
end end
@ -140,6 +146,11 @@ function towny.regions.get_closest_town(pos,name)
for _,tc in pairs(regions.blocks) do for _,tc in pairs(regions.blocks) do
local p1,p2 = towny.regions.ensure_range(tc) local p1,p2 = towny.regions.ensure_range(tc)
local center = vector.subtract(p1, {x=tr/2,y=th/2,z=tr/2}) local center = vector.subtract(p1, {x=tr/2,y=th/2,z=tr/2})
if towny.regions.vertical.static then
center.y = pos.y - th/2
end
local dist = vector.distance(pos, center) local dist = vector.distance(pos, center)
if dist < last_distance or last_distance == 0 then if dist < last_distance or last_distance == 0 then
last_distance = dist last_distance = dist
@ -177,7 +188,7 @@ function towny.regions.align_new_claim_block(pos,name)
new_pos = vector.add(p1, {x=-tr,y=0,z=0}) new_pos = vector.add(p1, {x=-tr,y=0,z=0})
end end
-- Y -- Y
elseif (pos.x <= p1.x and pos.x >= p2.x) and (pos.z <= p1.z and pos.z >= p2.z) then elseif (pos.x <= p1.x and pos.x >= p2.x) and (pos.z <= p1.z and pos.z >= p2.z) and not towny.regions.vertical.static then
if pos.y > p1.y then if pos.y > p1.y then
new_pos = vector.add(p1, {x=0,y=th,z=0}) new_pos = vector.add(p1, {x=0,y=th,z=0})
elseif pos.y < p2.y then elseif pos.y < p2.y then
@ -192,6 +203,10 @@ function towny.regions.align_new_claim_block(pos,name)
end end
end end
if towny.regions.vertical.static and new_pos then
new_pos.y = towny.regions.vertical.maxy
end
if new_pos == nil then return nil end -- Impossible position if new_pos == nil then return nil end -- Impossible position
return new_pos,closest_town return new_pos,closest_town
end end
@ -228,7 +243,7 @@ function towny.regions.visualize_town(town)
if not towny.regions.memloaded[town] then return end if not towny.regions.memloaded[town] then return end
for _,pos in pairs(towny.regions.memloaded[town].blocks) do for _,pos in pairs(towny.regions.memloaded[town].blocks) do
local p1,p2 = towny.regions.ensure_range(pos) local p1,p2 = towny.regions.ensure_range(pos)
towny.regions.visualize_area(p1,p2) towny.regions.visualize_area(p1,p2,towny.towns[town].flags['origin'])
end end
end end

View File

@ -13,13 +13,17 @@ towny_storage_engine (Storage engine) enum modstorage modstorage,flatfile
towny_claim_size (Claim size) int 16 towny_claim_size (Claim size) int 16
# Towny claim height # Towny claim height
towny_claim_size (Claim height) int 64 towny_claim_height (Claim height) int 64
# Use static height claim blocks
towny_static_height (Use static height claims) bool false
towny_static_miny (Static claim: minimum Y) int -32000
towny_static_maxy (Static claim: maximum Y) int 32000
# Minimum distance between towns (in claim blocks) # Minimum distance between towns (in claim blocks)
towny_distance (Max town claims) int 80 towny_distance (Max town claims) int 80
# Prevent protectors from being placed in a town # Prevent protectors from being placed in a town, as towns provide their own protection
# Towns provide their own protection
# Recommended to be kept as true, may cause issues with claims otherwise # Recommended to be kept as true, may cause issues with claims otherwise
towny_prevent_protector (Prevent protectors from being placed in a town) bool true towny_prevent_protector (Prevent protectors from being placed in a town) bool true
@ -38,4 +42,4 @@ towny_tax (Allow taxation) bool true
# Units depend on economy mod used in server # Units depend on economy mod used in server
towny_create_cost (Town creation cost) int 10000 towny_create_cost (Town creation cost) int 10000
towny_claim_cost (Town claim block cost) int 1000 towny_claim_cost (Town claim block cost) int 1000
towny_upkeep_cost (Town daily upkeep cost, multiplied by member count) int 10 towny_upkeep_cost (Town daily upkeep cost, multiplied by member count) int 0

View File

@ -95,7 +95,7 @@ function towny.create_town(pos, player, name)
end end
local _,__,distance = towny.regions.get_closest_town(pos) local _,__,distance = towny.regions.get_closest_town(pos)
if distance > towny.regions.distance * towny.regions.size and not towny_admin then if distance < towny.regions.distance * towny.regions.size and not towny_admin then
return err_msg(player, "This location is too close to another town!") return err_msg(player, "This location is too close to another town!")
end end
@ -109,6 +109,11 @@ function towny.create_town(pos, player, name)
local p1 = vector.add(pos, {x=tr / 2,y=th - 1,z=tr / 2}) local p1 = vector.add(pos, {x=tr / 2,y=th - 1,z=tr / 2})
local p2 = vector.subtract(pos, {x=tr / 2,y=1,z=tr / 2}) local p2 = vector.subtract(pos, {x=tr / 2,y=1,z=tr / 2})
if towny.regions.vertical.static then
p1.y = towny.regions.vertical.maxy
p2.y = towny.regions.vertical.miny
end
if towny.regions.protection_mod(p1,p2) then if towny.regions.protection_mod(p1,p2) then
return err_msg(player, "This area is protected by another protection mod! Please ensure that this is not the case.") return err_msg(player, "This area is protected by another protection mod! Please ensure that this is not the case.")
end end
@ -142,7 +147,7 @@ function towny.create_town(pos, player, name)
minetest.chat_send_player(player, "Your town has successfully been founded!") minetest.chat_send_player(player, "Your town has successfully been founded!")
minetest.chat_send_all(("%s has started a new town called '%s'!"):format(player,name)) minetest.chat_send_all(("%s has started a new town called '%s'!"):format(player,name))
towny.regions.visualize_area(p1,p2) towny.regions.visualize_area(p1,p2,pos)
return true return true
end end
@ -188,7 +193,7 @@ function towny.extend_town(pos,player)
minetest.chat_send_player(player, ("Successfully claimed this block! You have %d claim blocks left!"):format(towny.get_claims_available(town))) minetest.chat_send_player(player, ("Successfully claimed this block! You have %d claim blocks left!"):format(towny.get_claims_available(town)))
towny.mark_dirty(town, true) towny.mark_dirty(town, true)
towny.regions.visualize_area(p1,p2) towny.regions.visualize_area(p1,p2,pos)
return true return true
end end
@ -419,7 +424,7 @@ function towny.create_plot(pos,player)
towny.mark_dirty(t, true) towny.mark_dirty(t, true)
minetest.chat_send_player(player, "Successfully created a plot!") minetest.chat_send_player(player, "Successfully created a plot!")
towny.regions.visualize_area(c[1], c[2]) towny.regions.visualize_area(c[1], c[2], pos)
return true return true
end end
@ -456,7 +461,7 @@ function towny.claim_plot(pos,player)
towny.mark_dirty(t, false) towny.mark_dirty(t, false)
minetest.chat_send_player(player, "Successfully claimed the plot!") minetest.chat_send_player(player, "Successfully claimed the plot!")
towny.regions.visualize_area(c[1], c[2]) towny.regions.visualize_area(c[1], c[2], pos)
return true return true
else else

View File

@ -34,7 +34,12 @@ local function fl(x)
return math.floor(x) return math.floor(x)
end end
function towny.regions.visualize_area(p1,p2) function towny.regions.visualize_area(p1,p2,pos)
local center = {x=fl(p2.x + r1/2)+0.5,y=fl(p2.y + r2/2)+0.5,z=fl(p2.z + r1/2)+0.5} local center = {x=fl(p2.x + r1/2)+0.5,y=fl(p2.y + r2/2)+0.5,z=fl(p2.z + r1/2)+0.5}
if towny.regions.vertical.static then
center.y = pos.y
end
local e = minetest.add_entity(center, "towny:region_visual") local e = minetest.add_entity(center, "towny:region_visual")
end end