2013-09-26 16:30:36 +02:00
|
|
|
-- This is inspired by the landrush mod by Bremaweb
|
2020-03-08 22:15:00 +01:00
|
|
|
local S = minetest.get_translator("areas")
|
2013-09-26 16:30:36 +02:00
|
|
|
areas.hud = {}
|
2019-04-02 06:21:31 +02:00
|
|
|
areas.hud.refresh = 0
|
2013-09-26 16:30:36 +02:00
|
|
|
|
|
|
|
minetest.register_globalstep(function(dtime)
|
2019-04-02 06:21:31 +02:00
|
|
|
areas.hud.refresh = areas.hud.refresh + dtime
|
|
|
|
if areas.hud.refresh > areas.config["tick"] then
|
|
|
|
areas.hud.refresh = 0
|
|
|
|
else
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2013-09-26 16:30:36 +02:00
|
|
|
for _, player in pairs(minetest.get_connected_players()) do
|
|
|
|
local name = player:get_player_name()
|
2019-07-10 20:26:42 +02:00
|
|
|
local pos = vector.round(player:get_pos())
|
2019-04-02 05:24:59 +02:00
|
|
|
pos = vector.apply(pos, function(p)
|
|
|
|
return math.max(math.min(p, 2147483), -2147483)
|
|
|
|
end)
|
2014-10-14 02:32:02 +02:00
|
|
|
local areaStrings = {}
|
2016-11-26 08:20:23 +01:00
|
|
|
|
2014-01-16 02:10:24 +01:00
|
|
|
for id, area in pairs(areas:getAreasAtPos(pos)) do
|
2020-09-05 18:49:17 +02:00
|
|
|
local faction_info
|
|
|
|
if area.faction_open and areas.factions_available then
|
|
|
|
-- Gather and clean up disbanded factions
|
|
|
|
local changed = false
|
|
|
|
for i, fac_name in ipairs(area.faction_open) do
|
|
|
|
if not factions.get_owner(fac_name) then
|
|
|
|
table.remove(area.faction_open, i)
|
|
|
|
changed = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if #area.faction_open == 0 then
|
|
|
|
-- Prevent DB clutter, remove value
|
|
|
|
area.faction_open = nil
|
|
|
|
else
|
|
|
|
faction_info = table.concat(area.faction_open, ", ")
|
|
|
|
end
|
|
|
|
|
|
|
|
if changed then
|
|
|
|
areas:save()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-21 15:33:42 +02:00
|
|
|
table.insert(areaStrings, ("%s [%u] (%s%s%s)")
|
2014-03-30 19:53:56 +02:00
|
|
|
:format(area.name, id, area.owner,
|
2020-06-14 23:38:20 +02:00
|
|
|
area.open and S(":open") or area.openfarming and ":openfarming" or "",
|
2019-09-21 15:33:42 +02:00
|
|
|
faction_info and ":"..faction_info or ""))
|
2014-01-16 02:10:24 +01:00
|
|
|
end
|
2016-11-26 08:20:23 +01:00
|
|
|
|
|
|
|
for i, area in pairs(areas:getExternalHudEntries(pos)) do
|
|
|
|
local str = ""
|
|
|
|
if area.name then str = area.name .. " " end
|
|
|
|
if area.id then str = str.."["..area.id.."] " end
|
|
|
|
if area.owner then str = str.."("..area.owner..")" end
|
|
|
|
table.insert(areaStrings, str)
|
|
|
|
end
|
|
|
|
|
2020-03-08 22:15:00 +01:00
|
|
|
local areaString = S("Areas:")
|
2015-01-08 00:31:59 +01:00
|
|
|
if #areaStrings > 0 then
|
|
|
|
areaString = areaString.."\n"..
|
|
|
|
table.concat(areaStrings, "\n")
|
|
|
|
end
|
2014-10-14 02:32:02 +02:00
|
|
|
local hud = areas.hud[name]
|
|
|
|
if not hud then
|
|
|
|
hud = {}
|
|
|
|
areas.hud[name] = hud
|
|
|
|
hud.areasId = player:hud_add({
|
2024-07-17 18:18:21 +02:00
|
|
|
[minetest.features.hud_def_type_field and "type" or "hud_elem_type"] = "text", -- compatible with older versions
|
2014-01-16 02:10:24 +01:00
|
|
|
name = "Areas",
|
2013-11-19 03:04:14 +01:00
|
|
|
number = 0xFFFFFF,
|
|
|
|
position = {x=0, y=1},
|
2019-12-30 01:02:36 +01:00
|
|
|
offset = {x=8, y=-8},
|
2015-01-08 00:31:59 +01:00
|
|
|
text = areaString,
|
2013-11-19 03:08:22 +01:00
|
|
|
scale = {x=200, y=60},
|
2015-01-08 00:31:59 +01:00
|
|
|
alignment = {x=1, y=-1},
|
2013-11-19 03:04:14 +01:00
|
|
|
})
|
2014-10-14 02:32:02 +02:00
|
|
|
hud.oldAreas = areaString
|
2013-11-19 03:04:14 +01:00
|
|
|
return
|
2014-10-14 02:32:02 +02:00
|
|
|
elseif hud.oldAreas ~= areaString then
|
2015-01-08 00:31:59 +01:00
|
|
|
player:hud_change(hud.areasId, "text", areaString)
|
2014-10-14 02:32:02 +02:00
|
|
|
hud.oldAreas = areaString
|
2013-09-26 16:30:36 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
minetest.register_on_leaveplayer(function(player)
|
|
|
|
areas.hud[player:get_player_name()] = nil
|
|
|
|
end)
|