2020-02-16 18:55:07 +01:00
|
|
|
local scale = 0.25;
|
|
|
|
|
|
|
|
local variant_odds = { 1, 1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 4 };
|
|
|
|
local function get_variant(random)
|
|
|
|
return variant_odds[random:next(1, 12)];
|
|
|
|
end
|
|
|
|
|
|
|
|
local map_formspec_prefix = [[
|
|
|
|
formspec_version[3]
|
|
|
|
size[%f,%f]
|
|
|
|
real_coordinates[true]
|
|
|
|
style_type[image_button;border=false]
|
|
|
|
]];
|
|
|
|
|
|
|
|
local tile = "image[%f,%f;%f,%f;%s]";
|
|
|
|
local marker = "animated_image[%f,%f;%f,%f;%s:%d,%d]";
|
|
|
|
|
2020-03-17 11:52:15 +01:00
|
|
|
local function generate_map(data, x, y, w, h, player_x, player_y, detail, map_scale, is_visible, get_marker, user)
|
2020-02-16 18:55:07 +01:00
|
|
|
local str = "";
|
|
|
|
local random = PcgRandom(x + y + w + h); -- TODO: Better seed
|
|
|
|
for i = x,x + w,1 do
|
|
|
|
local fx = (i - x) * (scale - 0.01);
|
2020-03-07 16:26:24 +01:00
|
|
|
local column = data.generated[i * map_scale];
|
2020-02-16 18:55:07 +01:00
|
|
|
for j = y + h,y,-1 do
|
|
|
|
local fy = (y + h - j) * (scale - 0.01);
|
2020-03-07 16:26:24 +01:00
|
|
|
if column == nil or column[j * map_scale] == nil or (is_visible and not is_visible(user, i, j)) then
|
2020-02-16 18:55:07 +01:00
|
|
|
str = str..tile:format(fx, fy, scale, scale, "cartographer_unknown_biome." .. tostring(get_variant(random)) .. ".png")
|
|
|
|
else
|
2020-03-07 16:26:24 +01:00
|
|
|
local name = minetest.get_biome_name(column[j * map_scale].biome);
|
|
|
|
local height = column[j * map_scale].height;
|
2020-02-17 02:18:47 +01:00
|
|
|
local biome = cartographer.get_biome_texture(name, math.floor(height + 0.5), detail);
|
2020-02-20 01:56:31 +01:00
|
|
|
local depth = math.min(math.max(math.floor(height / 8), -8), 0) * -1
|
|
|
|
height = math.max(math.min(math.floor(height / 4), 8), 0)
|
|
|
|
|
|
|
|
local mod = "";
|
|
|
|
if height > 0 then
|
|
|
|
mod = "^[colorize:white:"..tostring(height * 10)
|
|
|
|
elseif depth > 0 then
|
|
|
|
mod = "^[colorize:#1f1f34:"..tostring(depth * 10)
|
|
|
|
end
|
2020-02-16 18:55:07 +01:00
|
|
|
|
|
|
|
if biome == nil then
|
2020-02-17 02:18:47 +01:00
|
|
|
-- minetest.chat_send_all(name);
|
2020-02-16 18:55:07 +01:00
|
|
|
str = str..tile:format(fx, fy, scale, scale, "cartographer_unknown_biome." .. tostring(get_variant(random)) .. ".png")
|
|
|
|
else
|
|
|
|
if height > 0 then
|
2020-02-20 01:56:31 +01:00
|
|
|
str = str..tile:format(fx, fy - (height * 0.05) + scale - 0.01, scale, (height * 0.05) + 0.01, "cartographer_cliff.png")
|
2020-02-16 18:55:07 +01:00
|
|
|
end
|
|
|
|
|
2020-02-20 01:56:31 +01:00
|
|
|
str = str..tile:format(fx, fy - (height * 0.05), scale, scale, biome .. "." .. tostring(get_variant(random)) .. ".png" .. mod)
|
2020-02-16 18:55:07 +01:00
|
|
|
end
|
|
|
|
|
2020-03-17 11:52:15 +01:00
|
|
|
if get_marker then
|
2020-03-17 12:15:38 +01:00
|
|
|
local marker = cartographer.get_marker_texture(get_marker(user, i, j), detail);
|
2020-03-17 11:52:15 +01:00
|
|
|
if marker then
|
|
|
|
str = str..tile:format(fx, fy - (height * 0.05), scale, scale, marker .. ".png")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-02-16 18:55:07 +01:00
|
|
|
if i == player_x and j == player_y then
|
2020-02-20 01:56:31 +01:00
|
|
|
str = str..marker:format(fx, fy - (height * 0.05), scale, scale, "cartographer_player_icon.png", 2, 500)
|
2020-02-16 18:55:07 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return str;
|
|
|
|
end
|
|
|
|
|
2020-03-08 15:06:26 +01:00
|
|
|
function cartographer.get_map_formspec(data, x, y, w, h, detail)
|
|
|
|
return map_formspec_prefix:format(w * scale, h * scale)..generate_map(data, x - (w * 0.5), y - (h * 0.5), w, h, x, y, detail, 4);
|
2020-02-16 18:55:07 +01:00
|
|
|
end
|
|
|
|
|
2020-03-08 15:06:26 +01:00
|
|
|
function cartographer.get_map_formspec_map(data, map, x, y)
|
2020-03-17 11:52:15 +01:00
|
|
|
return map_formspec_prefix:format(map.w * scale, map.h * scale)..generate_map(data, map.x, map.z, map.w, map.h, x, y, map.detail, map.scale, cartographer.is_filled, cartographer.get_marker, map);
|
2020-02-16 18:55:07 +01:00
|
|
|
end
|