Skip to content

Commit

Permalink
Merge branch 'optionalSmallestAreaUsingTable'
Browse files Browse the repository at this point in the history
  • Loading branch information
SwissalpS committed Sep 24, 2024
2 parents 1f770bc + 2b43015 commit 321b96b
Showing 1 changed file with 17 additions and 38 deletions.
55 changes: 17 additions & 38 deletions api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ function areas:getSmallestAreaAtPos(pos)
local smallest_area, smallest_id, volume
local smallest_volume = math.huge
for id, area in pairs(self:getAreasAtPos(pos)) do
volume = (area.pos2.x - area.pos1.x + 1)
* (area.pos2.y - area.pos1.y + 1)
* (area.pos2.z - area.pos1.z + 1)
volume = (area.pos2.x - area.pos1.x + 1)
* (area.pos2.y - area.pos1.y + 1)
* (area.pos2.z - area.pos1.z + 1)
if smallest_volume >= volume then
smallest_area = area
smallest_id = id
Expand All @@ -119,60 +119,39 @@ function areas:canInteract(pos, name)
if minetest.check_player_privs(name, self.adminPrivs) then
return true
end
local areas_list
if areas.config.use_smallest_area_precedence then
local area = self:getSmallestAreaAtPos(pos)
-- No area, player owns it or area is open
if not area
or area.owner == name
or area.open
then
local smallest_area, _ = self:getSmallestAreaAtPos(pos)
areas_list = { smallest_area }
else
areas_list = self:getAreasAtPos(pos)
end
local owned = false
for _, area in pairs(areas_list) do
-- Player owns the area or area is open
if area.owner == name or area.open then
return true
elseif areas.factions_available and area.faction_open then
if (factions.version or 0) < 2 then
local faction_name = factions.get_player_faction(name)
if faction_name then
for _, fname in ipairs(area.faction_open or {}) do
for _, fname in ipairs(area.faction_open) do
if faction_name == fname then
return true
end
end
end
else
for _, fname in ipairs(area.faction_open or {}) do
for _, fname in ipairs(area.faction_open) do
if factions.player_is_in_faction(fname, name) then
return true
end
end
end
end
return false
else
local owned = false
for _, area in pairs(self:getAreasAtPos(pos)) do
if area.owner == name or area.open then
return true
elseif areas.factions_available and area.faction_open then
if (factions.version or 0) < 2 then
local faction_name = factions.get_player_faction(name)
if faction_name then
for _, fname in ipairs(area.faction_open or {}) do
if faction_name == fname then
return true
end
end
end
else
for _, fname in ipairs(area.faction_open or {}) do
if factions.player_is_in_faction(fname, name) then
return true
end
end
end
end
owned = true
end
return not owned
owned = true
end
return not owned
end

-- Returns a table (list) of all players that own an area
Expand Down

0 comments on commit 321b96b

Please sign in to comment.