add cvar for separation of SPB, KARTBIG, and EXP

This commit is contained in:
Not 2022-04-18 19:32:05 +02:00
parent 553afc606d
commit c46f40001c
1 changed files with 71 additions and 22 deletions

View File

@ -28,6 +28,9 @@ local F_SPBJUS = 0x2
local F_SPBBIG = 0x4
local F_SPBEXP = 0x8
-- Score table separator
local ST_SEP = F_SPBATK
local clearcheats = false
local START_TIME = 6 * TICRATE + (3 * TICRATE / 4)
@ -112,24 +115,78 @@ local cv_interrupt = CV_RegisterVar({
end
})
local function setST(t, map, flags, scoreTable)
local mode = flags & ST_SEP
t[mode] = t[mode] or {}
t[mode][map] = scoreTable
end
local function getST(t, map, flags)
local mode = flags & ST_SEP
return t[mode] and t[mode][map] or nil
end
local function setScoreTable(map, flags, scoreTable)
local mode = flags & F_SPBATK
lb[mode] = lb[mode] or {}
lb[mode][map] = scoreTable
setST(lb, map, flags, scoreTable)
end
local function getScoreTable(map, flags)
--local id = tostring(map)
--if flags & F_SPBATK then
-- id = id + "S"
--end
--return id
local mode = flags & F_SPBATK
return lb[mode] and lb[mode][map] or nil
return getST(lb, map, flags)
end
-- True if a is better than b
local function lbComp(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
local function sortScores()
for mode, t in pairs(lb) do
for map, scoreTable in pairs(t) do
table.sort(scoreTable, lbComp)
setScoreTable(map, mode, scoreTable)
end
end
end
-- Reinitialize lb based on new ST_SEP value
local function reinit_lb()
local nlb = {}
for mode, t in pairs(lb) do
for map, scoreTable in pairs(t) do
for i, score in ipairs(scoreTable) do
local st = getST(nlb, map, score["flags"]) or {}
table.insert(st, score)
setST(nlb, map, score["flags"], st)
end
end
end
lb = nlb
sortScores()
end
local cv_spb_separate = CV_RegisterVar({
name = "lb_spb_separate",
defaultvalue = 0,
flags = CV_NETVAR | CV_CALL,
PossibleValue = CV_YesNo,
func = function(v)
if v.value then
ST_SEP = F_SPBATK | F_SPBBIG | F_SPBEXP
else
ST_SEP = F_SPBATK
end
reinit_lb()
end
})
local function score_t(map, name, skin, color, time, splits, flags, restat)
return {
["map"] = map,
@ -208,9 +265,11 @@ if f then
stats
)
)
setScoreTable(tonumber(t[1]), flags, scoreTable)
end
sortScores()
f:close()
else
print("Failed to open file: ", FILENAME)
@ -887,16 +946,6 @@ function cachePatches(v)
end
end
-- True if a is better than b
local function lbComp(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
-- Find location of player and scroll to it
function scroll_to(player)
local m = getScoreTable(gamemap, Flags) or {}