From 2dc8ce330a3a4a87c12936664ea25048d1a65aed Mon Sep 17 00:00:00 2001
From: toaster <rollerorbital@gmail.com>
Date: Sun, 5 May 2024 20:07:54 +0100
Subject: [PATCH] Review

- Update SAV_VERSIONMINOR so 2.0/2.1 cup backup files won't load
- Move specialDamage to grandprixinfo_t (from rank_t, per Sal review)
---
 src/g_game.c      | 2 +-
 src/k_grandprix.h | 1 +
 src/k_rank.h      | 1 -
 src/objects/ufo.c | 6 +++---
 src/p_saveg.c     | 8 ++++++--
 5 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/src/g_game.c b/src/g_game.c
index c9fdfc91f5..38abfbf031 100644
--- a/src/g_game.c
+++ b/src/g_game.c
@@ -4977,7 +4977,7 @@ void G_DirtyGameData(void)
 // Can be called by the startup code or the menu task.
 //
 
-#define SAV_VERSIONMINOR 5
+#define SAV_VERSIONMINOR 6
 
 void G_LoadGame(void)
 {
diff --git a/src/k_grandprix.h b/src/k_grandprix.h
index 9da27a3975..d16f0eb03d 100644
--- a/src/k_grandprix.h
+++ b/src/k_grandprix.h
@@ -39,6 +39,7 @@ extern struct grandprixinfo
 	boolean initalize;		///< If true, we need to initialize a new session.
 	boolean wonround;		///< If false, then we retry the map instead of going to the next.
 	gpEvent_e eventmode;	///< Special event mode, bots are set to spectate and a special gametype is played
+	UINT32 specialDamage;	///< Accumulated Sealed Star difficulty reduction
 	gpRank_t rank;			///< Struct containing grading information. (See also: k_rank.h)
 } grandprixinfo;
 
diff --git a/src/k_rank.h b/src/k_rank.h
index c69270bf76..4d69740067 100644
--- a/src/k_rank.h
+++ b/src/k_rank.h
@@ -53,7 +53,6 @@ struct gpRank_t
 	UINT32 totalLaps;
 
 	UINT32 continuesUsed;
-	UINT32 specialDamage;
 
 	UINT32 prisons;
 	UINT32 totalPrisons;
diff --git a/src/objects/ufo.c b/src/objects/ufo.c
index 605462ee38..249e5b458e 100644
--- a/src/objects/ufo.c
+++ b/src/objects/ufo.c
@@ -938,7 +938,7 @@ boolean Obj_SpecialUFODamage(mobj_t *ufo, mobj_t *inflictor, mobj_t *source, UIN
 
 	if (grandprixinfo.gp)
 	{
-		grandprixinfo.rank.specialDamage += damage;
+		grandprixinfo.specialDamage += damage;
 	}
 
 	K_SetHitLagForObjects(ufo, inflictor, source, (damage / 3) + 2, true);
@@ -1345,9 +1345,9 @@ static mobj_t *InitSpecialUFO(waypoint_t *start)
 	P_SetTarget(&ufo_piece_prev(piece), prevPiece);
 	prevPiece = piece;
 
-	if (grandprixinfo.gp && grandprixinfo.rank.specialDamage)
+	if (grandprixinfo.gp && grandprixinfo.specialDamage)
 	{
-		ufo->health -= min(4*mobjinfo[MT_SPECIAL_UFO].spawnhealth/10, grandprixinfo.rank.specialDamage/6);
+		ufo->health -= min(4*mobjinfo[MT_SPECIAL_UFO].spawnhealth/10, grandprixinfo.specialDamage/6);
 	}
 
 	return ufo;
diff --git a/src/p_saveg.c b/src/p_saveg.c
index 4c270cbaa9..75e8fbd31d 100644
--- a/src/p_saveg.c
+++ b/src/p_saveg.c
@@ -6069,6 +6069,8 @@ static inline void P_ArchiveMisc(savebuffer_t *save)
 	WRITEUINT8(save->p, (UINT8)grandprixinfo.encore);
 	WRITEUINT8(save->p, (UINT8)grandprixinfo.masterbots);
 
+	WRITEUINT32(save->p, grandprixinfo.specialDamage);
+
 	WRITESTRINGL(save->p, grandprixinfo.cup->name, MAXCUPNAME);
 
 	// Round Queue information
@@ -6136,7 +6138,6 @@ static inline void P_ArchiveMisc(savebuffer_t *save)
 		WRITEUINT32(save->p, rank->totalLaps);
 
 		WRITEUINT32(save->p, (rank->continuesUsed + 1));
-		WRITEUINT32(save->p, rank->specialDamage);
 
 		WRITEUINT32(save->p, rank->prisons);
 		WRITEUINT32(save->p, rank->totalPrisons);
@@ -6217,6 +6218,8 @@ void P_GetBackupCupData(savebuffer_t *save)
 	cupsavedata.encore = (boolean)READUINT8(save->p);
 	boolean masterbots = (boolean)READUINT8(save->p);
 
+	save->p += 4; // specialDamage
+
 	if (masterbots == true)
 		cupsavedata.difficulty = KARTGP_MASTER;
 
@@ -6266,6 +6269,8 @@ static boolean P_UnArchiveSPGame(savebuffer_t *save)
 	grandprixinfo.encore = (boolean)READUINT8(save->p);
 	grandprixinfo.masterbots = (boolean)READUINT8(save->p);
 
+	grandprixinfo.specialDamage = READUINT32(save->p);
+
 	// Find the relevant cup.
 	char cupname[MAXCUPNAME];
 	READSTRINGL(save->p, cupname, sizeof(cupname));
@@ -6395,7 +6400,6 @@ static boolean P_UnArchiveSPGame(savebuffer_t *save)
 		rank->totalLaps = READUINT32(save->p);
 
 		rank->continuesUsed = READUINT32(save->p);
-		rank->specialDamage = READUINT32(save->p);
 
 		rank->prisons = READUINT32(save->p);
 		rank->totalPrisons = READUINT32(save->p);
-- 
GitLab