forked from Not/srb2k-leaderboard
add cvar for separation of SPB, KARTBIG, and EXP
This commit is contained in:
parent
553afc606d
commit
c46f40001c
@ -28,6 +28,9 @@ local F_SPBJUS = 0x2
|
|||||||
local F_SPBBIG = 0x4
|
local F_SPBBIG = 0x4
|
||||||
local F_SPBEXP = 0x8
|
local F_SPBEXP = 0x8
|
||||||
|
|
||||||
|
-- Score table separator
|
||||||
|
local ST_SEP = F_SPBATK
|
||||||
|
|
||||||
local clearcheats = false
|
local clearcheats = false
|
||||||
|
|
||||||
local START_TIME = 6 * TICRATE + (3 * TICRATE / 4)
|
local START_TIME = 6 * TICRATE + (3 * TICRATE / 4)
|
||||||
@ -112,24 +115,78 @@ local cv_interrupt = CV_RegisterVar({
|
|||||||
end
|
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 function setScoreTable(map, flags, scoreTable)
|
||||||
local mode = flags & F_SPBATK
|
setST(lb, map, flags, scoreTable)
|
||||||
lb[mode] = lb[mode] or {}
|
|
||||||
lb[mode][map] = scoreTable
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function getScoreTable(map, flags)
|
local function getScoreTable(map, flags)
|
||||||
--local id = tostring(map)
|
return getST(lb, map, flags)
|
||||||
--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
|
|
||||||
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
|
||||||
|
|
||||||
|
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)
|
local function score_t(map, name, skin, color, time, splits, flags, restat)
|
||||||
return {
|
return {
|
||||||
["map"] = map,
|
["map"] = map,
|
||||||
@ -208,9 +265,11 @@ if f then
|
|||||||
stats
|
stats
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
setScoreTable(tonumber(t[1]), flags, scoreTable)
|
setScoreTable(tonumber(t[1]), flags, scoreTable)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sortScores()
|
||||||
f:close()
|
f:close()
|
||||||
else
|
else
|
||||||
print("Failed to open file: ", FILENAME)
|
print("Failed to open file: ", FILENAME)
|
||||||
@ -887,16 +946,6 @@ function cachePatches(v)
|
|||||||
end
|
end
|
||||||
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
|
-- Find location of player and scroll to it
|
||||||
function scroll_to(player)
|
function scroll_to(player)
|
||||||
local m = getScoreTable(gamemap, Flags) or {}
|
local m = getScoreTable(gamemap, Flags) or {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user