From 69c11a8220477e64348f1fb5b47f0e86df324ea1 Mon Sep 17 00:00:00 2001
From: sphere <spherallic@gmail.com>
Date: Thu, 30 Apr 2020 16:01:03 +0200
Subject: [PATCH] Support act numbers up to 99 and draw both digits
 individually.

---
 src/dehacked.c |  2 +-
 src/hu_stuff.c |  4 ++--
 src/hu_stuff.h |  2 +-
 src/st_stuff.c |  9 +++++++--
 src/v_video.c  | 30 +++++++++++++++++++++++-------
 5 files changed, 34 insertions(+), 13 deletions(-)

diff --git a/src/dehacked.c b/src/dehacked.c
index a6c73e0b45..a71bfe0554 100644
--- a/src/dehacked.c
+++ b/src/dehacked.c
@@ -1557,7 +1557,7 @@ static void readlevelheader(MYFILE *f, INT32 num)
 			}
 			else if (fastcmp(word, "ACT"))
 			{
-				if (i >= 0 && i < 20) // 0 for no act number, TTL1 through TTL19
+				if (i >= 0 && i <= 99) // 0 for no act number
 					mapheaderinfo[num-1]->actnum = (UINT8)i;
 				else
 					deh_warning("Level header %d: invalid act number %d", num, i);
diff --git a/src/hu_stuff.c b/src/hu_stuff.c
index 6aa5a45100..3ff9db2b66 100644
--- a/src/hu_stuff.c
+++ b/src/hu_stuff.c
@@ -68,7 +68,7 @@ patch_t *nightsnum[10]; // 0-9
 // Level title and credits fonts
 patch_t *lt_font[LT_FONTSIZE];
 patch_t *cred_font[CRED_FONTSIZE];
-patch_t *ttlnum[20]; // act numbers (0-19)
+patch_t *ttlnum[10]; // act numbers (0-9)
 
 // Name tag fonts
 patch_t *ntb_font[NT_FONTSIZE];
@@ -243,7 +243,7 @@ void HU_LoadGraphics(void)
 	tallinfin = (patch_t *)W_CachePatchName("STTINFIN", PU_HUDGFX);
 
 	// cache act numbers for level titles
-	for (i = 0; i < 20; i++)
+	for (i = 0; i < 10; i++)
 	{
 		sprintf(buffer, "TTL%.2d", i);
 		ttlnum[i] = (patch_t *)W_CachePatchName(buffer, PU_HUDGFX);
diff --git a/src/hu_stuff.h b/src/hu_stuff.h
index 9e3c667479..63d85f1b81 100644
--- a/src/hu_stuff.h
+++ b/src/hu_stuff.h
@@ -85,7 +85,7 @@ extern patch_t *lt_font[LT_FONTSIZE];
 extern patch_t *cred_font[CRED_FONTSIZE];
 extern patch_t *ntb_font[NT_FONTSIZE];
 extern patch_t *nto_font[NT_FONTSIZE];
-extern patch_t *ttlnum[20];
+extern patch_t *ttlnum[10];
 extern patch_t *emeraldpics[3][8];
 extern patch_t *rflagico;
 extern patch_t *bflagico;
diff --git a/src/st_stuff.c b/src/st_stuff.c
index b6226d085e..26f2c1774f 100644
--- a/src/st_stuff.c
+++ b/src/st_stuff.c
@@ -1325,7 +1325,7 @@ void ST_drawTitleCard(void)
 {
 	char *lvlttl = mapheaderinfo[gamemap-1]->lvlttl;
 	char *subttl = mapheaderinfo[gamemap-1]->subttl;
-	INT32 actnum = mapheaderinfo[gamemap-1]->actnum;
+	UINT8 actnum = mapheaderinfo[gamemap-1]->actnum;
 	INT32 lvlttlxpos, ttlnumxpos, zonexpos;
 	INT32 subttlxpos = BASEVIDWIDTH/2;
 	INT32 ttlscroll = FixedInt(lt_scroll);
@@ -1382,7 +1382,12 @@ void ST_drawTitleCard(void)
 	if (actnum)
 	{
 		if (!splitscreen)
-			V_DrawMappedPatch(ttlnumxpos + ttlscroll, 104 - ttlscroll, 0, actpat, colormap);
+		{
+			if (actnum > 9)
+				V_DrawMappedPatch(ttlnumxpos + (V_LevelActNumWidth(actnum)/4) + ttlscroll, 104 - ttlscroll, 0, actpat, colormap);
+			else
+				V_DrawMappedPatch(ttlnumxpos + ttlscroll, 104 - ttlscroll, 0, actpat, colormap);
+		}
 		V_DrawLevelActNum(ttlnumxpos + ttlscroll, 104, V_PERPLAYER, actnum);
 	}
 
diff --git a/src/v_video.c b/src/v_video.c
index 3ce0e79f51..e8d121f9a5 100644
--- a/src/v_video.c
+++ b/src/v_video.c
@@ -2952,13 +2952,19 @@ void V_DrawPaddedTallNum(INT32 x, INT32 y, INT32 flags, INT32 num, INT32 digits)
 }
 
 // Draw an act number for a level title
-// Todo: actually draw two-digit numbers as two act num patches
-void V_DrawLevelActNum(INT32 x, INT32 y, INT32 flags, INT32 num)
+void V_DrawLevelActNum(INT32 x, INT32 y, INT32 flags, UINT8 num)
 {
-	if (num < 0 || num > 19)
+	if (num < 0 || num > 99)
 		return; // not supported
 
-	V_DrawScaledPatch(x, y, flags, ttlnum[num]);
+	while (num > 0)
+	{
+		if (num > 9)
+			V_DrawScaledPatch(x + (V_LevelActNumWidth(num) - V_LevelActNumWidth(num%10)), y, flags, ttlnum[num%10]);
+		else
+			V_DrawScaledPatch(x, y, flags, ttlnum[num]);
+		num = num/10;
+	}
 }
 
 // Write a string using the credit font
@@ -3340,12 +3346,22 @@ INT32 V_LevelNameHeight(const char *string)
 
 // For ST_drawTitleCard
 // Returns the width of the act num patch
-INT32 V_LevelActNumWidth(INT32 num)
+INT32 V_LevelActNumWidth(UINT8 num)
 {
-	if (num < 0 || num > 19)
+	SHORT result = 0;
+	if (num > 99)
 		return 0; // not a valid number
 
-	return SHORT(ttlnum[num]->width);
+	if (num == 0)
+		return SHORT(ttlnum[num]->width);
+
+	while (num > 0)
+	{
+		result = result + SHORT(ttlnum[num%10]->width);
+		num = num/10;
+	}
+
+	return result;
 }
 
 //
-- 
GitLab