local worldWidth, worldHeight, x, y, z, width, height, avoidance, name, policy, areaType
local specialAreaRect = {}
local innerRect = {}
local function gettilepos(x, y, z)
local tile = getobjectarea(x, y, z)
if tile == nil then
local xDiff, yDiff = x - $posx, y - $posy
if math.abs($posx - x) <= 7 then
tile = getobjectarea(x, $posy, $posz)
xDiff = 0
elseif math.abs($posy - y) <= 5 then
tile = getobjectarea($posx, y, $posz)
yDiff = 0
else
tile = getobjectarea($posx, $posy, $posz)
end
-- Some strange stuff happens when you go from 0 to -1, so I'm
-- adding this as a precaution.
if tile ~= nil then
local width, height = $worldwin.width, $worldwin.height
local function getAreaRect(x, y, w, h)
local ret = {x = 0, y = 0, w = 0, h = 0}
local topLeftTilePos = gettilepos(x, y, $posz)
local botRightTilePos = gettilepos(x + w - 1, y + h - 1, $posz)
if topLeftTilePos and botRightTilePos then
ret.x = math.max(topLeftTilePos.left, 0)
ret.y = math.max(topLeftTilePos.top, 0)
ret.w = math.min(botRightTilePos.right, worldWidth) - ret.x
ret.h = math.min(botRightTilePos.bottom, worldHeight) - ret.y
end
return ret
end
local function drawInnerRect(areaType, x, y, width, height)
innerRect = {w = 0, h = 0}
if areaType == 'Square (Border Only)' then
innerRect = getAreaRect(x + 1, y + 1, width - 2, height - 2)
elseif areaType == 'Square (Double Border)' then
innerRect = getAreaRect(x + 2, y + 2, width - 4, height - 4)
end
if innerRect.w > 0 and innerRect.h > 0 then
setfillstyle('color', 0xFF000000)
drawroundrect(innerRect.x, innerRect.y, innerRect.w, innerRect.h, 10, 10)
end
end
foreach settingsentry e 'Cavebot/SpecialAreas' do
x, y, z = getsetting(e, 'Coordinates'):match('.-(%d+).-(%d+).-(%d+)')
x, y, z = tonumber(x), tonumber(y), tonumber(z)
if z == $posz then
width, height = getsetting(e, 'Size'):match('(%d+).-(%d+)')
width, height = tonumber(width), tonumber(height)
specialAreaRect = getAreaRect(x, y, width, height)
if specialAreaRect.w > 0 and specialAreaRect.h > 0 then
avoidance = tonumber(getsetting(e, 'Avoidance'))
areaType = getsetting(e, 'Type')
name = getsetting(e, 'Name')
policy = getsetting(e, 'Policy'):gsub('[^A-Z]', '')
if specialAreaRect.w > 10 then
drawtext(
string.fit(name, specialAreaRect.w - 10, '...', true),
specialAreaRect.x + 5,
specialAreaRect.y + 3
)
drawtext(
string.fit(policy, specialAreaRect.w - 10, '...', true),
specialAreaRect.x + 5,
specialAreaRect.y + 15
)
end
end
end
end
if contextmenuinfo() == nil then
if draggedSP then
set(draggedSP, 'Coordinates', string.format('x:%i, y:%i, z:%i', $cursorinfo.x, $cursorinfo.y, $cursorinfo.z))
elseif resizedSP then
local x, y = get(resizedSP, 'Coordinates'):match(REGEX_COORDS)
x, y = tonumber(x), tonumber(y)
set(resizedSP, 'Size', string.format('%i x %i', math.max(1, 1 + ($cursorinfo.x - x)) , math.max(1, 1 + ($cursorinfo.y - y))))
end
end