diff --git a/leaderboard.lua b/leaderboard.lua index 4ceb83e..5fea551 100644 --- a/leaderboard.lua +++ b/leaderboard.lua @@ -34,7 +34,7 @@ local RedFlash = { local StatTrack = false local UNCLAIMED = "Unclaimed Record" -local HELP_MESSAGE = "\x89Leaderboard Commands:\nretry exit findmap changelevel spba_clearcheats lb_gui rival scroll encore" +local HELP_MESSAGE = "\x89Leaderboard Commands:\nretry exit findmap changelevel spba_clearcheats lb_gui rival scroll encore records" local FILENAME = "leaderboard.txt" -- Retry / changelevel map @@ -383,6 +383,20 @@ local function exitlevel(player, ...) end COM_AddCommand("exit", exitlevel) +local function zoneAct(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 + local function findMap(player, ...) local search = ... @@ -395,28 +409,13 @@ local function findMap(player, ...) } local lvltype, map, lvlttl - local zoneAct = function(zone, act, levelflags) - local z = "" - if zone != "" then - z = " " + zone - elseif not(levelflags & LF_NOZONE) then - z = " Zone" - end - if act != "" then - z = $ + " " + act - end - - return z - end - - for i = 1, #mapheaderinfo do map = mapheaderinfo[i] if map == nil then continue end - lvlttl = map.lvlttl + zoneAct(map.zonttl, map.actnum, map.levelflags) + lvlttl = map.lvlttl + zoneAct(map) if not search or lvlttl:lower():find(search:lower()) then -- Only care for up to TOL_MATCH (0x10) @@ -443,10 +442,129 @@ local function findMap(player, ...) end COM_AddCommand("findmap", findMap) -local function mapNotExists(player, map) - CONS_Printf(player, string.format("Map doesn't exist: %s", map:upper())) +local function mapnumFromExtended(map) + local p, q = map:upper():match("MAP(%w)(%w)$", 1) + if not (p and q) then + return nil + end + + local mapnum = 0 + local A = string.byte("A") + + if tonumber(p) != nil then + -- Non extended map numbers + if tonumber(q) == nil then + return nil + end + mapnum = tonumber(p) * 10 + tonumber(q) + else + --Extended map numbers + p = string.byte(p) - A + local qn = tonumber(q) + if qn == nil then + qn = string.byte(q) - A + 10 + end + + mapnum = 36 * p + qn + 100 + end + + return mapnum end +local SPBModeSym = { + [F_SPBEXP] = "X", + [F_SPBBIG] = "B", + [F_SPBJUS] = "J", +} + +local function modeToString(mode) + local modestr = "Time Attack" + if mode & F_SPBATK then + modestr = "SPB" + for k, v in pairs(SPBModeSym) do + if mode & k then + modestr = $ + v + end + end + end + + return modestr +end + +local function records(player, ...) + local mapid = ... + local mapnum = gamemap + + if mapid then + mapnum = mapnumFromExtended(mapid) + if not mapnum then + CONS_Printf(player, string.format("Invalid map name: %s", mapid)) + return + end + end + + local map = mapheaderinfo[mapnum] + if map then + CONS_Printf(player, + string.format( + "\x83%s%8s", + map.lvlttl, + (map.menuflags & LF2_HIDEINMENU and "\x85HELL") or "" + ) + ) + + local zoneact = zoneAct(map) + -- print the zone/act on the right hand size under the title + CONS_Printf( + player, + string.format( + string.format("\x83%%%ds%%s\x80 - \x88%%s", #map.lvlttl - #zoneact / 2 - 1), + " ", + zoneAct(map), + map.subttl + ) + ) + else + CONS_Printf(player, "\x85UNKNOWN MAP") + end + + for mode, maps in pairs(lb) do + local maptbl = maps[mapnum] + if not maptbl then continue end + CONS_Printf(player, "") + CONS_Printf(player, modeToString(mode)) + + -- don't print flags for time attack + if mode then + for i, tbl in ipairs(maptbl) do + CONS_Printf( + player, + string.format( + "%2d %-21s \x89%8s \x80%s", + i, + tbl["name"], + ticsToTime(tbl["time"]), + modeToString(tbl["flags"]) + ) + ) + end + else + for i, tbl in ipairs(maptbl) do + CONS_Printf( + player, + string.format( + "%2d %-21s \x89%8s", + i, + tbl["name"], + ticsToTime(tbl["time"]) + ) + ) + end + end + end +end +COM_AddCommand("records", records) + local function changelevel(player, ...) if not doyoudare(player) then return @@ -461,35 +579,13 @@ local function changelevel(player, ...) return end - local p, q = map:upper():match("MAP(%w)(%w)$", 1) - if not (p and q) then + local mapnum = mapnumFromExtended(map) + if not mapnum then CONS_Printf(player, string.format("Invalid map name: %s", map)) - return end - local mapnum = 0 - local A = string.byte("A") - - if tonumber(p) != nil then - -- Non extended map numbers - if tonumber(q) == nil then - mapNotExists(player, map) - return - end - mapnum = tonumber(p) * 10 + tonumber(q) - else - --Extended map numbers - p = string.byte(p) - A - local qn = tonumber(q) - if qn == nil then - qn = string.byte(q) - A + 10 - end - - mapnum = 36 * p + qn + 100 - end - if mapheaderinfo[mapnum] == nil then - mapNotExists(player, map) + CONS_Printf(player, string.format("Map doesn't exist: %s", map:upper())) return end @@ -554,7 +650,7 @@ local function findRival(player, ...) [0] = "\x89", [-1] = "\x88" } - + local sym = { [true] = "-", [false] = "", @@ -612,12 +708,6 @@ local function findRival(player, ...) return a["rival"]["map"] < b["rival"]["map"] end - local modestrings = { - [F_SPBEXP] = "X", - [F_SPBBIG] = "B", - [F_SPBJUS] = "J", - } - for mode, tbl in pairs(scores) do if i >= stop then break end @@ -631,15 +721,7 @@ local function findRival(player, ...) if i >= stop then break end i = i + 1 - local modestr = "TA" - if score["rival"]["flags"] & F_SPBATK then - modestr = "SPB" - for k, v in pairs(modestrings) do - if score["rival"]["flags"] & k then - modestr = $ + v - end - end - end + local modestr = modeToString(score["rival"]["flags"]) if score["your"] then local diff = score["your"]["time"] - score["rival"]["time"] @@ -708,7 +790,7 @@ COM_AddCommand("rival", findRival) -- -- v[i]["flags"], -- -- "," -- -- ) --- -- +-- -- -- --end -- end -- end @@ -776,7 +858,7 @@ local function marquee(text, maxwidth) if #text <= maxwidth then return text end - + local shift = 16 -- Creates an index range ranging from -shift to #text + shift @@ -1297,7 +1379,7 @@ local function think() end end end - + -- Gamemode flags Flags = $ & !(F_SPBATK | F_SPBEXP | F_SPBBIG | F_SPBJUS) if leveltime > START_TIME - (3 * TICRATE) / 2 and server.SPBArunning then