Compare commits
6 Commits
v1.2.21
...
1d4eb423d6
Author | SHA1 | Date | |
---|---|---|---|
1d4eb423d6 | |||
2d4784f62e | |||
6953f343dc | |||
dfecef7225 | |||
e03c9beecc | |||
518e9f7893 |
17
browser.lua
17
browser.lua
@ -266,15 +266,18 @@ local function drawFlags(v, x, y, flags)
|
||||
end
|
||||
end
|
||||
|
||||
local MSK_SPEED = 0xF0
|
||||
local MSK_WEIGHT = 0xF
|
||||
|
||||
local function drawStats(v, x, y, skin, stats)
|
||||
local s = skins[skin]
|
||||
if not (s
|
||||
and s.kartspeed == stats["speed"]
|
||||
and s.kartweight == stats["weight"]
|
||||
)
|
||||
and stats then
|
||||
v.drawString(x-2, y-2, stats["speed"], V_ALLOWLOWERCASE, "thin")
|
||||
v.drawString(x + 13, y + 9, stats["weight"], V_ALLOWLOWERCASE, "thin")
|
||||
if stats
|
||||
and not (s
|
||||
and s.kartspeed == (stats & MSK_SPEED) >> 4
|
||||
and s.kartweight == stats & MSK_WEIGHT
|
||||
) then
|
||||
v.drawString(x-2, y-2, (stats & MSK_SPEED) >> 4, V_ALLOWLOWERCASE, "thin")
|
||||
v.drawString(x + 13, y + 9, stats & MSK_WEIGHT, V_ALLOWLOWERCASE, "thin")
|
||||
end
|
||||
end
|
||||
|
||||
|
250
leaderboard.lua
250
leaderboard.lua
@ -253,79 +253,81 @@ local function score_t(map, name, skin, color, time, splits, flags, stat)
|
||||
}
|
||||
end
|
||||
|
||||
local MSK_SPEED = 0xF0
|
||||
local MSK_WEIGHT = 0xF
|
||||
|
||||
local function stat_t(speed, weight)
|
||||
if speed and weight then
|
||||
return {
|
||||
["speed"] = speed,
|
||||
["weight"] = weight
|
||||
}
|
||||
return (speed << 4) | weight
|
||||
end
|
||||
return nil
|
||||
return 0
|
||||
end
|
||||
|
||||
local function stat_str(stat)
|
||||
if stat then
|
||||
return string.format("%d%d", stat["speed"], stat["weight"])
|
||||
return string.format("%d%d", (stat & MSK_SPEED) >> 4, stat & MSK_WEIGHT)
|
||||
end
|
||||
|
||||
return "0"
|
||||
end
|
||||
|
||||
-- Read the leaderboard
|
||||
local f = io.open(FILENAME, "r")
|
||||
if f then
|
||||
for l in f:lines() do
|
||||
-- Leaderboard is stored in the following tab separated format
|
||||
-- mapnum, name, skin, color, time, splits, flags, stat
|
||||
local t = {}
|
||||
for word in (l+"\t"):gmatch("(.-)\t") do
|
||||
table.insert(t, word)
|
||||
end
|
||||
|
||||
local flags = 0
|
||||
if t[7] != nil then
|
||||
flags = tonumber(t[7])
|
||||
end
|
||||
|
||||
scoreTable = getScoreTable(tonumber(t[1]), flags) or {}
|
||||
|
||||
local spl = {}
|
||||
if t[6] != nil then
|
||||
for str in t[6]:gmatch("([^ ]+)") do
|
||||
table.insert(spl, tonumber(str))
|
||||
if isserver then
|
||||
local f = io.open(FILENAME, "r")
|
||||
if f then
|
||||
for l in f:lines() do
|
||||
-- Leaderboard is stored in the following tab separated format
|
||||
-- mapnum, name, skin, color, time, splits, flags, stat
|
||||
local t = {}
|
||||
for word in (l+"\t"):gmatch("(.-)\t") do
|
||||
table.insert(t, word)
|
||||
end
|
||||
end
|
||||
|
||||
local stats = nil
|
||||
if t[8] != nil then
|
||||
if #t[8] >= 2 then
|
||||
local speed = tonumber(string.sub(t[8], 1, 1))
|
||||
local weight = tonumber(string.sub(t[8], 2, 2))
|
||||
stats = stat_t(speed, weight)
|
||||
local flags = 0
|
||||
if t[7] != nil then
|
||||
flags = tonumber(t[7])
|
||||
end
|
||||
end
|
||||
|
||||
table.insert(
|
||||
scoreTable,
|
||||
score_t(
|
||||
tonumber(t[1]),
|
||||
t[2],
|
||||
t[3],
|
||||
t[4],
|
||||
tonumber(t[5]),
|
||||
spl,
|
||||
flags,
|
||||
stats
|
||||
scoreTable = getScoreTable(tonumber(t[1]), flags) or {}
|
||||
|
||||
local spl = {}
|
||||
if t[6] != nil then
|
||||
for str in t[6]:gmatch("([^ ]+)") do
|
||||
table.insert(spl, tonumber(str))
|
||||
end
|
||||
end
|
||||
|
||||
local stats = nil
|
||||
if t[8] != nil then
|
||||
if #t[8] >= 2 then
|
||||
local speed = tonumber(string.sub(t[8], 1, 1))
|
||||
local weight = tonumber(string.sub(t[8], 2, 2))
|
||||
stats = stat_t(speed, weight)
|
||||
end
|
||||
end
|
||||
|
||||
table.insert(
|
||||
scoreTable,
|
||||
score_t(
|
||||
tonumber(t[1]),
|
||||
t[2],
|
||||
t[3],
|
||||
t[4],
|
||||
tonumber(t[5]),
|
||||
spl,
|
||||
flags,
|
||||
stats
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
setScoreTable(tonumber(t[1]), flags, scoreTable)
|
||||
setScoreTable(tonumber(t[1]), flags, scoreTable)
|
||||
end
|
||||
|
||||
sortScores()
|
||||
f:close()
|
||||
else
|
||||
print("Failed to open file: ", FILENAME)
|
||||
end
|
||||
|
||||
sortScores()
|
||||
f:close()
|
||||
else
|
||||
print("Failed to open file: ", FILENAME)
|
||||
end
|
||||
|
||||
function allowJoin(v)
|
||||
@ -987,11 +989,11 @@ local function drawScore(v, player, pos, x, y, gui, faceRank, score, drawPos, te
|
||||
local pskin = score["skin"] and skins[score["skin"]]
|
||||
if stat and not (
|
||||
pskin
|
||||
and pskin.kartweight == stat["weight"]
|
||||
and pskin.kartspeed == stat["speed"]
|
||||
and pskin.kartweight == stat & MSK_WEIGHT
|
||||
and pskin.kartspeed == (stat & MSK_SPEED) >> 4
|
||||
) then
|
||||
v.drawString(x + FACERANK_DIM - 2, y + 4, stat["speed"], V_HUDTRANS | VFLAGS, "small")
|
||||
v.drawString(x + FACERANK_DIM - 2, y + 8, stat["weight"], V_HUDTRANS | VFLAGS, "small")
|
||||
v.drawString(x + FACERANK_DIM - 2, y + 4, (stat & MSK_SPEED) >> 4, V_HUDTRANS | VFLAGS, "small")
|
||||
v.drawString(x + FACERANK_DIM - 2, y + 8, stat & MSK_WEIGHT, V_HUDTRANS | VFLAGS, "small")
|
||||
end
|
||||
|
||||
if gui == GUI_ON or (gui == GUI_SPLITS and showSplit) then
|
||||
@ -1221,9 +1223,45 @@ local function writeStats()
|
||||
end
|
||||
end
|
||||
|
||||
local function saveTime(player)
|
||||
local function checkFlags(p)
|
||||
local flags = 0
|
||||
|
||||
scoreTable = $ or {}
|
||||
-- Encore
|
||||
if encoremode then
|
||||
flags = $ | F_ENCORE
|
||||
end
|
||||
|
||||
if not cv_spbatk then
|
||||
cv_spbatk = CV_FindVar("spbatk")
|
||||
end
|
||||
|
||||
-- SPBAttack
|
||||
if server.SPBArunning and cv_spbatk.value then
|
||||
flags = $ | F_SPBATK
|
||||
|
||||
if server.SPBAexpert then
|
||||
flags = $ | F_SPBEXP
|
||||
end
|
||||
if p.SPBAKARTBIG then
|
||||
flags = $ | F_SPBBIG
|
||||
end
|
||||
if p.SPBAjustice then
|
||||
flags = $ | F_SPBJUS
|
||||
end
|
||||
end
|
||||
|
||||
return flags
|
||||
end
|
||||
|
||||
local function saveTime(player)
|
||||
-- Disqualify if the flags changed mid trial.
|
||||
if checkFlags(player) != Flags then
|
||||
print("Game mode change detected! Time has been disqualified.")
|
||||
S_StartSound(nil, 110)
|
||||
return
|
||||
end
|
||||
|
||||
scoreTable = $ or {}
|
||||
|
||||
local pskin = skins[player.mo.skin]
|
||||
local newscore = score_t(
|
||||
@ -1279,30 +1317,32 @@ local function saveTime(player)
|
||||
StatTrack = true
|
||||
end
|
||||
|
||||
local f = assert(io.open(FILENAME, "w"))
|
||||
if f == nil then
|
||||
print("Failed to open file for writing: " + FILENAME)
|
||||
return
|
||||
end
|
||||
if isserver then
|
||||
local f = assert(io.open(FILENAME, "w"))
|
||||
if f == nil then
|
||||
print("Failed to open file for writing: " + FILENAME)
|
||||
return
|
||||
end
|
||||
|
||||
for _, tbl in pairs(lb) do
|
||||
for _, scoreTable in pairs(tbl) do
|
||||
for _, score in ipairs(scoreTable) do
|
||||
f:write(
|
||||
score["map"], "\t",
|
||||
score["name"], "\t",
|
||||
score["skin"], "\t",
|
||||
score["color"], "\t",
|
||||
score["time"], "\t",
|
||||
table.concat(score["splits"], " "), "\t",
|
||||
score["flags"], "\t",
|
||||
stat_str(score["stat"]), "\n"
|
||||
)
|
||||
for _, tbl in pairs(lb) do
|
||||
for _, scoreTable in pairs(tbl) do
|
||||
for _, score in ipairs(scoreTable) do
|
||||
f:write(
|
||||
score["map"], "\t",
|
||||
score["name"], "\t",
|
||||
score["skin"], "\t",
|
||||
score["color"], "\t",
|
||||
score["time"], "\t",
|
||||
table.concat(score["splits"], " "), "\t",
|
||||
score["flags"], "\t",
|
||||
stat_str(score["stat"]), "\n"
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
f:close()
|
||||
f:close()
|
||||
end
|
||||
end
|
||||
|
||||
-- DEBUGGING
|
||||
@ -1387,13 +1427,7 @@ local function think()
|
||||
end
|
||||
|
||||
-- Autospec
|
||||
-- Encore
|
||||
if leveltime == 1 then
|
||||
Flags = $ & !F_ENCORE
|
||||
if encoremode then
|
||||
Flags = $ | F_ENCORE
|
||||
end
|
||||
|
||||
if p then
|
||||
for s in players.iterate do
|
||||
if s.valid and s.spectator then
|
||||
@ -1402,49 +1436,29 @@ local function think()
|
||||
end
|
||||
end
|
||||
end
|
||||
if not cv_spbatk then
|
||||
cv_spbatk = CV_FindVar("spbatk")
|
||||
end
|
||||
|
||||
-- Gamemode flags
|
||||
Flags = $ & !(F_SPBATK | F_SPBEXP | F_SPBBIG | F_SPBJUS)
|
||||
if server.SPBArunning
|
||||
and cv_spbatk.value
|
||||
and leveltime > START_TIME - (3 * TICRATE) / 2 then
|
||||
Flags = $ | F_SPBATK
|
||||
if server.SPBAexpert then
|
||||
Flags = $ | F_SPBEXP
|
||||
end
|
||||
if leveltime > START_TIME - (3 * TICRATE) / 2 then
|
||||
if clearcheats then
|
||||
clearcheats = false
|
||||
for q in players.iterate do
|
||||
q.SPBAKARTBIG = false
|
||||
q.SPBAjustice = false
|
||||
q.SPBAshutup = false
|
||||
if p then
|
||||
p.SPBAKARTBIG = false
|
||||
p.SPBAjustice = false
|
||||
p.SPBAshutup = false
|
||||
end
|
||||
end
|
||||
|
||||
if p then
|
||||
if p.SPBAKARTBIG then
|
||||
Flags = $ | F_SPBBIG
|
||||
end
|
||||
if p.SPBAjustice then
|
||||
Flags = $ | F_SPBJUS
|
||||
end
|
||||
end
|
||||
Flags = checkFlags(p)
|
||||
|
||||
-- make sure the spb actually spawned
|
||||
if leveltime == START_TIME - 1 then
|
||||
if server.SPBArunning and leveltime == START_TIME - 1 then
|
||||
if not (server.SPBAbomb and server.SPBAbomb.valid) then
|
||||
-- it didn't spawn, clear spb flags
|
||||
Flags = $ & !(F_SPBATK | F_SPBEXP | F_SPBBIG | F_SPBJUS)
|
||||
end
|
||||
end
|
||||
|
||||
else
|
||||
hud.enable("freeplay")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
scoreTable = getScoreTable(gamemap, Flags)
|
||||
@ -1454,6 +1468,12 @@ local function think()
|
||||
end
|
||||
|
||||
if p then
|
||||
-- must be done before browser control
|
||||
if p.laps >= mapheaderinfo[gamemap].numlaps and timeFinished == 0 then
|
||||
timeFinished = p.realtime
|
||||
saveTime(p)
|
||||
end
|
||||
|
||||
-- Scroll controller
|
||||
-- Spectators can't input buttons so let the gamer do it
|
||||
if drawState == DS_SCROLL then
|
||||
@ -1478,7 +1498,7 @@ local function think()
|
||||
end
|
||||
|
||||
-- disable spba hud
|
||||
if server.SPBAdone then
|
||||
if server.SPBArunning and server.SPBAdone then
|
||||
server.SPBArunning = false
|
||||
p.pflags = $ & !(PF_TIMEOVER)
|
||||
p.exiting = 100
|
||||
@ -1509,10 +1529,6 @@ local function think()
|
||||
end
|
||||
end
|
||||
|
||||
if p.laps >= mapheaderinfo[gamemap].numlaps and timeFinished == 0 then
|
||||
timeFinished = p.realtime
|
||||
saveTime(p)
|
||||
end
|
||||
regLap(p)
|
||||
elseif cv_teamchange.value == 0 then
|
||||
allowJoin(true)
|
||||
|
Reference in New Issue
Block a user