From c7c908eed3a518c3c0f44d5243ce8e87f9656143 Mon Sep 17 00:00:00 2001
From: toasterbabe <rollerorbital@gmail.com>
Date: Mon, 24 Apr 2017 21:56:17 +0100
Subject: [PATCH] Emerald tokens being used as actual game tokens on the
 end-of-act screen!

https://gfycat.com/PlumpShowyBream https://gfycat.com/AlarmingLoathsomeBelugawhale
---
 src/doomstat.h |  1 +
 src/g_game.c   |  5 ++---
 src/hu_stuff.c |  2 +-
 src/hu_stuff.h |  1 +
 src/y_inter.c  | 57 +++++++++++++++++++++++++++++++++++++++++++-------
 5 files changed, 55 insertions(+), 11 deletions(-)

diff --git a/src/doomstat.h b/src/doomstat.h
index 9034fd62a3..a3b07c9cbf 100644
--- a/src/doomstat.h
+++ b/src/doomstat.h
@@ -379,6 +379,7 @@ nightsdata_t ntemprecords;
 
 extern UINT32 token; ///< Number of tokens collected in a level
 extern UINT32 tokenlist; ///< List of tokens collected
+extern boolean gottoken; ///< Did you get a token? Used for end of act
 extern INT32 tokenbits; ///< Used for setting token bits
 extern INT32 sstimer; ///< Time allotted in the special stage
 extern UINT32 bluescore; ///< Blue Team Scores
diff --git a/src/g_game.c b/src/g_game.c
index bdfea10d5a..db06edf464 100644
--- a/src/g_game.c
+++ b/src/g_game.c
@@ -156,6 +156,7 @@ UINT8 stagefailed; // Used for GEMS BONUS? Also to see if you beat the stage.
 UINT16 emeralds;
 UINT32 token; // Number of tokens collected in a level
 UINT32 tokenlist; // List of tokens collected
+boolean gottoken; // Did you get a token? Used for end of act
 INT32 tokenbits; // Used for setting token bits
 
 // Old Special Stage
@@ -2780,7 +2781,6 @@ static INT16 RandMap(INT16 tolflags, INT16 pprevmap)
 static void G_DoCompleted(void)
 {
 	INT32 i;
-	boolean gottoken = false;
 
 	tokenlist = 0; // Reset the list
 
@@ -2866,10 +2866,9 @@ static void G_DoCompleted(void)
 	if (nextmap >= 1100-1 && nextmap <= 1102-1 && (gametype == GT_RACE || gametype == GT_COMPETITION))
 		nextmap = (INT16)(spstage_start-1);
 
-	if (gametype == GT_COOP && token)
+	if ((gottoken = (gametype == GT_COOP && token)))
 	{
 		token--;
-		gottoken = true;
 
 		if (!(emeralds & EMERALD1))
 			nextmap = (INT16)(sstage_start - 1); // Special Stage 1
diff --git a/src/hu_stuff.c b/src/hu_stuff.c
index 30b2a12633..365ea093b8 100644
--- a/src/hu_stuff.c
+++ b/src/hu_stuff.c
@@ -91,7 +91,7 @@ patch_t *tallminus;
 patch_t *emeraldpics[7];
 patch_t *tinyemeraldpics[7];
 static patch_t *emblemicon;
-static patch_t *tokenicon;
+patch_t *tokenicon;
 
 //-------------------------------------------
 //              misc vars
diff --git a/src/hu_stuff.h b/src/hu_stuff.h
index c2654d2096..9bfb429122 100644
--- a/src/hu_stuff.h
+++ b/src/hu_stuff.h
@@ -71,6 +71,7 @@ extern patch_t *rmatcico;
 extern patch_t *bmatcico;
 extern patch_t *tagico;
 extern patch_t *tallminus;
+extern patch_t *tokenicon;
 
 // set true when entering a chat message
 extern boolean chat_on;
diff --git a/src/y_inter.c b/src/y_inter.c
index c730745d50..f639addd3b 100644
--- a/src/y_inter.c
+++ b/src/y_inter.c
@@ -147,6 +147,7 @@ static boolean useinterpic;
 static INT32 timer;
 
 static INT32 intertic;
+static INT32 tallydonetic = -1;
 static INT32 endtic = -1;
 
 intertype_t intertype = int_none;
@@ -159,6 +160,40 @@ static void Y_CalculateMatchWinners(void);
 static void Y_FollowIntermission(void);
 static void Y_UnloadData(void);
 
+static void Y_IntermissionTokenDrawer(void)
+{
+	INT32 y;
+	INT32 offs = 0;
+	UINT32 tokencount;
+	INT32 lowy = BASEVIDHEIGHT - 32;
+	INT16 temp = SHORT(tokenicon->height)/2;
+	INT32 calc;
+
+	if (tallydonetic != -1)
+	{
+		offs = (intertic - tallydonetic)*2;
+		if (offs > 10)
+			offs = 8;
+	}
+
+	V_DrawFill(32, lowy-1, 16, 1, 31); // slot
+
+	y = (lowy + offs + 1) - (temp + (token + 1)*8);
+
+	for (tokencount = token; tokencount; tokencount--)
+	{
+		if (y >= -temp)
+			V_DrawSmallScaledPatch(32, y, 0, tokenicon);
+		y += 8;
+	}
+
+	y += (offs*(temp - 1)/8);
+	calc = (lowy - y)*2;
+
+	if (calc > 0)
+		V_DrawCroppedPatch(32<<FRACBITS, y<<FRACBITS, FRACUNIT/2, 0, tokenicon, 32*FRACUNIT, y<<FRACBITS, SHORT(tokenicon->width), calc);
+}
+
 //
 // Y_IntermissionDrawer
 //
@@ -203,6 +238,9 @@ void Y_IntermissionDrawer(void)
 	{
 		INT32 bonusy;
 
+		if (gottoken) // first to be behind everything else
+			Y_IntermissionTokenDrawer();
+
 		// draw score
 		V_DrawScaledPatch(hudinfo[HUD_SCORE].x, hudinfo[HUD_SCORE].y, V_SNAPTOLEFT, sboscore);
 		V_DrawTallNum(hudinfo[HUD_SCORENUM].x, hudinfo[HUD_SCORENUM].y, V_SNAPTOLEFT, data.coop.score);
@@ -261,6 +299,9 @@ void Y_IntermissionDrawer(void)
 		INT32 xoffset3 = 0; // Line 3 x offset
 		UINT8 drawsection = 0;
 
+		if (gottoken) // first to be behind everything else
+			Y_IntermissionTokenDrawer();
+
 		// draw the header
 		if (intertic <= TICRATE)
 			animatetic = 0;
@@ -679,7 +720,10 @@ void Y_Ticker(void)
 		boolean anybonuses = false;
 
 		if (!intertic) // first time only
+		{
 			S_ChangeMusicInternal("_clear", false); // don't loop it
+			tallydonetic = -1;
+		}
 
 		if (intertic < TICRATE) // one second pause before tally begins
 			return;
@@ -709,6 +753,7 @@ void Y_Ticker(void)
 
 		if (!anybonuses)
 		{
+			tallydonetic = intertic;
 			endtic = intertic + 3*TICRATE; // 3 second pause after end of tally
 			S_StartSound(NULL, sfx_chchng); // cha-ching!
 
@@ -736,12 +781,11 @@ void Y_Ticker(void)
 		INT32 i;
 		UINT32 oldscore = data.spec.score;
 		boolean skip = false;
-		static INT32 tallydonetic = 0;
 
 		if (!intertic) // first time only
 		{
 			S_ChangeMusicInternal("_clear", false); // don't loop it
-			tallydonetic = 0;
+			tallydonetic = -1;
 		}
 
 		if (intertic < TICRATE) // one second pause before tally begins
@@ -751,9 +795,9 @@ void Y_Ticker(void)
 			if (playeringame[i] && (players[i].cmd.buttons & BT_USE))
 				skip = true;
 
-		if (tallydonetic != 0)
+		if ((data.spec.continues & 0x80) && tallydonetic != -1)
 		{
-			if (intertic > tallydonetic)
+			if ((intertic - tallydonetic) > (3*TICRATE)/2)
 			{
 				endtic = intertic + 4*TICRATE; // 4 second pause after end of tally
 				S_StartSound(NULL, sfx_s3kac); // cha-ching!
@@ -772,9 +816,8 @@ void Y_Ticker(void)
 
 		if (!data.spec.bonus.points)
 		{
-			if (data.spec.continues & 0x80) // don't set endtic yet!
-				tallydonetic = intertic + (3*TICRATE)/2;
-			else // okay we're good.
+			tallydonetic = intertic;
+			if (!(data.spec.continues & 0x80)) // don't set endtic yet!
 				endtic = intertic + 4*TICRATE; // 4 second pause after end of tally
 
 			S_StartSound(NULL, sfx_chchng); // cha-ching!
-- 
GitLab