2022-09-02 23:03:09 +02:00
|
|
|
rawset(_G, "lb_TicsToTime", function(tics, pure)
|
|
|
|
if tics == 0 and pure then
|
|
|
|
return "-:--:--"
|
|
|
|
end
|
|
|
|
|
|
|
|
return string.format(
|
|
|
|
"%d:%02d:%02d",
|
|
|
|
G_TicsToMinutes(tics, true),
|
|
|
|
G_TicsToSeconds(tics),
|
|
|
|
G_TicsToCentiseconds(tics)
|
|
|
|
)
|
|
|
|
end)
|
|
|
|
|
|
|
|
rawset(_G, "lb_ZoneAct", function(map)
|
|
|
|
local z = ""
|
|
|
|
if map.zonttl != "" then
|
|
|
|
z = " " + map.zonttl
|
|
|
|
elseif not(map.levelflags & LF_NOZONE) then
|
|
|
|
z = " Zone"
|
|
|
|
end
|
|
|
|
if map.actnum != "" then
|
|
|
|
z = $ + " " + map.actnum
|
|
|
|
end
|
|
|
|
|
|
|
|
return z
|
|
|
|
end)
|
2022-10-07 01:35:24 +02:00
|
|
|
|
|
|
|
rawset(_G, "lb_stat_t", function(speed, weight)
|
|
|
|
if speed and weight then
|
|
|
|
return (speed << 4) | weight
|
|
|
|
end
|
|
|
|
return 0
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
|
|
local F_SPBBIG = 0x4
|
|
|
|
local F_SPBEXP = 0x8
|
|
|
|
-- True if a is better than b
|
|
|
|
rawset(_G, "lb_comp", function(a, b)
|
|
|
|
-- Calculates the difficulty, harder has higher priority
|
|
|
|
-- if s is positive then a is harder
|
|
|
|
-- if s is negative then b is harder
|
|
|
|
-- if s is 0 then compare time
|
|
|
|
local s = (a.flags & (F_SPBEXP | F_SPBBIG)) - (b.flags & (F_SPBEXP | F_SPBBIG))
|
|
|
|
return s > 0 or not(s < 0 or a.time >= b.time)
|
|
|
|
end)
|
2022-11-18 01:35:59 +01:00
|
|
|
|
|
|
|
local function djb2(message)
|
|
|
|
local digest = 5381
|
|
|
|
for c in message:gmatch(".") do
|
|
|
|
digest = (($ << 5) + $) + string.byte(c)
|
|
|
|
end
|
|
|
|
|
|
|
|
return digest
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Produce a checksum by using the maps title, subtitle and zone
|
|
|
|
rawset(_G, "lb_map_checksum", function(mapnum)
|
|
|
|
local mh = mapheaderinfo[mapnum]
|
|
|
|
if not mh then
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
local digest = string.format("%04x", djb2(mh.lvlttl..mh.subttl..mh.zonttl))
|
|
|
|
return string.sub(digest, #digest - 3)
|
|
|
|
end)
|