10 Commits

2 changed files with 152 additions and 90 deletions

View File

@ -12,6 +12,8 @@ local ZoneAct = lb_ZoneAct
local TicsToTime = lb_TicsToTime
-----------------------------
local cv_kartencore
local function mapIndexOffset(n)
return (mapIndex + n + #maps - 1) % #maps + 1
end
@ -53,6 +55,7 @@ local mappY = 26
local ttlY = mappY + FixedMul(30, FRACUNIT / scalar)
local scoresY = ttlY + 16
local sin = sin
local function drawMapPatch(v, offset)
local scale = FRACUNIT / (abs(offset) + scalar)
local mapName = G_BuildMapName(getMap(offset))
@ -68,6 +71,26 @@ local function drawMapPatch(v, offset)
scale,
mapp
)
end
local function drawEncore(v)
if not cv_kartencore then
cv_kartencore = CV_FindVar("kartencore")
end
if not cv_kartencore.value then
return
end
local rubyp = v.cachePatch("RUBYICON")
local bob = sin(leveltime * ANG10) * 2
v.drawScaled(
hlfScrnWdth * FRACUNIT,
mappY * FRACUNIT + bob,
FRACUNIT,
rubyp
)
end
local colors = {
@ -181,7 +204,7 @@ local function drawGamemode(v)
end
if m & F_SPBEXP then
local invp = v.cachePatch("K_ITINV"..(leveltime / 6 % 7 + 1))
local invp = v.cachePatch("K_ITINV"..(leveltime / 3 % 7 + 1))
v.drawScaled(
modeX * FRACUNIT - scaledHalf + xoff,
modeY * FRACUNIT - scaledHalf,
@ -236,22 +259,25 @@ local function drawFlags(v, x, y, flags)
nx = $ + margin
end
if flags & F_SPBEXP then
local invp = v.cachePatch("K_ISINV"..(leveltime / 6 % 6 + 1))
local invp = v.cachePatch("K_ISINV"..(leveltime / 3 % 6 + 1))
v.drawScaled(nx, ny, scale, invp)
nx = $ + margin
end
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
@ -281,7 +307,7 @@ local colorFlags = {
[0] = V_SKYMAP,
[1] = 0
}
local function drawScore(v, i, pos, score)
local function drawScore(v, i, pos, score, highlight)
local y = scoresY + i * 18
local textFlag = colorFlags[pos%2]
@ -293,6 +319,13 @@ local function drawScore(v, i, pos, score)
local facerank = skin and v.cachePatch(skin.facerank) or v.cachePatch("M_NORANK")
v.draw(column[1], y, facerank, 0, v.getColormap("sonic", score["color"]))
-- chili
if highlight then
local chilip = v.cachePatch("K_CHILI"..leveltime/4%8+1)
v.draw(column[1], y, chilip)
textFlag = V_YELLOWMAP
end
-- stats
drawStats(v, column[1], y, score["skin"], score["stat"])
-- name
@ -303,7 +336,7 @@ local function drawScore(v, i, pos, score)
drawFlags(v, column[4], y, score["flags"])
end
local function drawBrowser(v)
local function drawBrowser(v, player)
if not leaderboard then return end
v.fadeScreen(0xFF00, 16)
@ -319,6 +352,7 @@ local function drawBrowser(v)
-- current map
drawMapPatch(v, 0)
drawEncore(v)
drawMapStrings(v)
drawGamemode(v)
@ -334,7 +368,7 @@ local function drawBrowser(v)
scrollPos = max(min(scrollPos, scores - 3), 1)
local endi = min(scrollPos + 7, scores)
for i = scrollPos, endi do
drawScore(v, i - scrollPos + 1, i, scoreTable[i])
drawScore(v, i - scrollPos + 1, i, scoreTable[i], scoreTable[i].name == player.name)
end
end
rawset(_G, "DrawBrowser", drawBrowser)
@ -395,6 +429,8 @@ local function resetKeyRepeat()
repeatCount = 0
end
local ValidButtons = BT_ACCELERATE | BT_BRAKE | BT_FORWARD | BT_BACKWARD | BT_DRIFT | BT_ATTACK
-- return value indicates we want to exit the browser
local function controller(player)
keyRepeat = max(0, $ - 1)
@ -405,32 +441,38 @@ local function controller(player)
local cmd = player.cmd
if not keyRepeat then
if cmd.driftturn > 0 then
updateMapIndex(-1)
updateKeyRepeat()
elseif cmd.driftturn < 0 then
updateMapIndex(1)
updateKeyRepeat()
if not (cmd.buttons & ValidButtons or cmd.driftturn) then
return
end
updateKeyRepeat()
if cmd.buttons & BT_BRAKE then
S_StartSound(nil, 115)
return true
elseif cmd.buttons & BT_ACCELERATE then
COM_BufInsertText(player, "changelevel "..G_BuildMapName(maps[mapIndex]))
return true
elseif cmd.buttons & BT_ATTACK then
COM_BufInsertText(player, "encore")
elseif cmd.driftturn then
local dir = cmd.driftturn > 0 and -1 or 1
if encoremode then
updateMapIndex(-dir)
else
updateMapIndex(dir)
end
elseif cmd.buttons & BT_FORWARD then
scrollPos = $ - 1
updateKeyRepeat()
elseif cmd.buttons & BT_BACKWARD then
scrollPos = $ + 1
updateKeyRepeat()
elseif cmd.buttons & BT_DRIFT then
scrollPos = 1
if modes and #modes then
mode = $ % #modes + 1
prefMode = modes[mode]
end
updateKeyRepeat()
elseif cmd.buttons & BT_BRAKE then
S_StartSound(nil, 115)
return true
elseif cmd.buttons & BT_ACCELERATE then
S_StartSound(nil, 143)
COM_BufInsertText(player, "changelevel "..G_BuildMapName(maps[mapIndex]))
return true
end
end
end

View File

@ -253,24 +253,36 @@ 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
local function splits_from_str(splitstr)
local spl = {}
for str in splitstr:gmatch("([^ ]+)") do
table.insert(spl, tonumber(str))
end
return spl
end
local function splits_to_str(splits)
return table.concat(splits, " ")
end
-- Read the leaderboard
local f = io.open(FILENAME, "r")
if f then
@ -289,12 +301,7 @@ if f then
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 spl = t[6] or ""
local stats = nil
if t[8] != nil then
@ -863,7 +870,7 @@ local modePatches = {
local function modePatch(flag)
if flag == F_SPBEXP then
return PATCH[modePatches[flag]][(leveltime / 4) % 6]
return PATCH[modePatches[flag]][(leveltime / 3) % 6]
end
return PATCH[modePatches[flag]]
end
@ -987,11 +994,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
@ -1028,8 +1035,9 @@ local function drawScore(v, player, pos, x, y, gui, faceRank, score, drawPos, te
)
-- Draw splits
if showSplit and score["splits"] and score["splits"][prevLap] != nil then
local split = splits[prevLap] - score["splits"][prevLap]
local splts = splits_from_str(score["splits"])
if showSplit and splts and splts[prevLap] != nil then
local split = splits[prevLap] - splts[prevLap]
v.drawString(
x + px + FACERANK_DIM,
y + 8,
@ -1122,7 +1130,7 @@ local function drawScrollTo(v, player, scoreTable, gui)
end
local function drawBrowser(v, player)
DrawBrowser(v, lb)
DrawBrowser(v, player)
end
local stateFunctions = {
@ -1221,9 +1229,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(
@ -1232,7 +1276,7 @@ local function saveTime(player)
player.mo.skin,
player.skincolor,
timeFinished,
splits,
splits_to_str(splits),
Flags,
stat_t(player.HMRs or pskin.kartspeed, player.HMRw or pskin.kartweight)
)
@ -1294,7 +1338,7 @@ local function saveTime(player)
score["skin"], "\t",
score["color"], "\t",
score["time"], "\t",
table.concat(score["splits"], " "), "\t",
score["splits"], "\t",
score["flags"], "\t",
stat_str(score["stat"]), "\n"
)
@ -1387,13 +1431,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 +1440,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 +1472,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 +1502,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 +1533,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)