From 0bde2a7fead387bc5eaf8839f970f3181d63fd0a Mon Sep 17 00:00:00 2001
From: Not <not.git@protonmail.com>
Date: Mon, 4 Apr 2022 20:56:03 +0200
Subject: [PATCH] add encore support

---
 leaderboard.lua | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/leaderboard.lua b/leaderboard.lua
index f936edc..7b55824 100644
--- a/leaderboard.lua
+++ b/leaderboard.lua
@@ -20,6 +20,7 @@ local FILENAME = "leaderboard.txt"
 local nextMap = nil
 
 local Flags = 0
+local F_ENCORE = 0x80
 
 -- SPB flags with the least significance first
 local F_SPBATK = 0x1
@@ -352,6 +353,20 @@ local function changelevel(player, ...)
 end
 COM_AddCommand("changelevel", changelevel)
 
+local function toggleEncore(player)
+	if not doyoudare(player) then
+		return
+	end
+
+	local enc = CV_FindVar("kartencore")
+	if enc.value then
+		COM_BufInsertText(server, "kartencore off")
+	else
+		COM_BufInsertText(server, "kartencore on")
+	end
+end
+COM_AddCommand("encore", toggleEncore)
+
 local function clearcheats(player)
 	if not player.spectator then
 		clearcheats = true
@@ -616,12 +631,25 @@ local FACERANK_DIM = 16
 local FACERANK_SPC = FACERANK_DIM + 4
 local function drawScore(v, player, pos, x, y, gui, faceRank, score, drawPos, textVFlags)
 	textVFlags = textVFlags or V_HUDTRANSHALF
+
 	--draw Patch/chili
 	v.draw(x, y, faceRank, V_HUDTRANS | VFLAGS, v.getColormap("sonic", score["color"]))
 	if player.name == score["name"] then
 		v.draw(x, y, PATCH["CHILI"][(leveltime / 4) % 8], V_HUDTRANS | VFLAGS)
 	end
 
+	-- Encore
+	if score["flags"] & F_ENCORE then
+		local bob = sin((leveltime + i * 5) * (ANG10))
+		v.drawScaled(
+			x * FRACUNIT,
+			bob + (y + FACERANK_DIM / 2) * FRACUNIT,
+			FRACUNIT / 6,
+			PATCH["RUBY"],
+			V_HUDTRANS
+		)
+	end
+
 	-- SPB
 	if score["flags"] & F_SPBATK then
 		local scale = FRACUNIT / 4
@@ -850,6 +878,7 @@ function cachePatches(v)
 		end
 		PATCH["BIG"] = v.cachePatch("K_ISGROW")
 		PATCH["HYUD"] = v.cachePatch("K_ISHYUD")
+		PATCH["RUBY"] = v.cachePatch("RUBYICON")
 	end
 end
 
@@ -1021,7 +1050,13 @@ 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
-- 
2.47.2