From 7677bf10c475c11d47aafa23244e19d7efb908e9 Mon Sep 17 00:00:00 2001
From: Tim Felgentreff <timfelgentreff@gmail.com>
Date: Thu, 3 Mar 2022 22:43:07 +0100
Subject: [PATCH] give games the opportunity to store custom settings in
 GameSettings that get synced across the network

---
 src/include/settings.h | 22 ++++++++++++----------
 src/tolua/game.pkg     |  8 ++++++--
 2 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/src/include/settings.h b/src/include/settings.h
index 0cdb818da..a3197a551 100644
--- a/src/include/settings.h
+++ b/src/include/settings.h
@@ -254,6 +254,14 @@ struct Settings {
 		uint32_t _Bitfield;
 	};
 
+	bool GetUserGameSetting(int i) {
+		return UserGameSettings & (1 << i);
+	}
+
+	void SetUserGameSetting(int i, bool v) {
+		UserGameSettings |= (1 << i);
+	}
+
 	bool operator==(const Settings &other) const {
 		for (int i = 0; i < PlayerMax; i++) {
 			if (Presets[i] == other.Presets[i]) {
@@ -277,7 +285,7 @@ struct Settings {
 	void Save(const std::function <void (std::string)>& f, bool withPlayers = true) {
 		f(std::string("NetGameType = ") + std::to_string(static_cast<int>(NetGameType)));
 		if (withPlayers) {
-			for (int i = 0; i < PlayerMax - 1; ++i) {
+			for (int i = 0; i < PlayerMax; ++i) {
 				Presets[i].Save([&] (std::string field) {
 					f(std::string("Presets[") + std::to_string(i) + "]." + field);
 				});
@@ -291,9 +299,7 @@ struct Settings {
 		f(std::string("FoV = ") + std::to_string(static_cast<int>(FoV)));
 		f(std::string("RevealMap = ") + std::to_string(static_cast<int>(RevealMap)));
 		f(std::string("DefeatReveal = ") + std::to_string(static_cast<int>(DefeatReveal)));
-		f(std::string("NoFogOfWar = ") + std::to_string(NoFogOfWar));
-		f(std::string("Inside = ") + std::to_string(Inside));
-		f(std::string("UserGameSettings = ") + std::to_string(UserGameSettings));
+		f(std::string("Flags = ") + std::to_string(_Bitfield));
 	}
 
 	bool SetField(std::string field, int value) {
@@ -315,12 +321,8 @@ struct Settings {
 			RevealMap = static_cast<MapRevealModes>(value);
 		} else if (field == "DefeatReveal") {
 			DefeatReveal = static_cast<RevealTypes>(value);
-		} else if (field == "NoFogOfWar") {
-			NoFogOfWar = value;
-		} else if (field == "Inside") {
-			Inside = value;
-		} else if (field == "UserGameSettings") {
-			UserGameSettings = value;
+		} else if (field == "Flags") {
+			_Bitfield = value;
 		} else {
 			return false;
 		}
diff --git a/src/tolua/game.pkg b/src/tolua/game.pkg
index 444c366e6..db2efe27e 100644
--- a/src/tolua/game.pkg
+++ b/src/tolua/game.pkg
@@ -74,9 +74,13 @@ class Settings {
 	int Opponents;
 	int Difficulty;
 	GameTypes GameType;
-	bool NoFogOfWar;
-	bool Inside;
+        FieldOfViewTypes FoV;
 	MapRevealModes RevealMap;
+        RevealTypes DefeatReveal;
+        int _Bitfield @ Flags;
+
+        bool GetUserGameSetting(int i);
+        void SetUserGameSetting(int i, bool v);
 };
 
 $[