From b3b3f87cfb5b5ff58d82b2a231f4aa5f9549fa73 Mon Sep 17 00:00:00 2001
From: Tim Felgentreff <timfelgentreff@gmail.com>
Date: Thu, 3 Mar 2022 22:43:07 +0100
Subject: [PATCH] fix build issues on linux

---
 src/game/game.cpp              |  2 +-
 src/network/net_message.cpp    | 22 +++++++++++-----------
 src/network/netconnect.cpp     | 10 +++++-----
 src/network/online_service.cpp |  2 --
 src/stratagus/player.cpp       | 17 ++++++++---------
 src/stratagus/script.cpp       |  2 +-
 6 files changed, 26 insertions(+), 29 deletions(-)

diff --git a/src/game/game.cpp b/src/game/game.cpp
index 32ca68c41..80f11efdd 100644
--- a/src/game/game.cpp
+++ b/src/game/game.cpp
@@ -298,7 +298,7 @@ static int WriteMapPresentation(const std::string &mapname, CMap &map, Vec2i new
 			--topplayer;
 		}
 		for (int i = 0; i <= topplayer; ++i) {
-			f->printf("%s\"%s\"", (i ? ", " : ""), PlayerTypeNames[static_cast<int>(map.Info.PlayerType[i])]);
+			f->printf("%s\"%s\"", (i ? ", " : ""), PlayerTypeNames[static_cast<int>(map.Info.PlayerType[i])].c_str());
 			if (map.Info.PlayerType[i] == PlayerTypes::PlayerPerson) {
 				++numplayers;
 			}
diff --git a/src/network/net_message.cpp b/src/network/net_message.cpp
index b63cb6d55..d63dc4fb5 100644
--- a/src/network/net_message.cpp
+++ b/src/network/net_message.cpp
@@ -269,25 +269,25 @@ size_t CServerSetup::Serialize(unsigned char *buf) const
 size_t CServerSetup::Deserialize(const unsigned char *p)
 {
 	const unsigned char *buf = p;
-	p += deserialize8(p, &static_cast<int8_t>(this->ServerGameSettings.DefeatReveal));
-	p += deserialize8(p, &static_cast<int8_t>(this->ServerGameSettings.Difficulty));
-	p += deserialize8(p, &static_cast<int8_t>(this->ServerGameSettings.FoV));
-	p += deserialize8(p, &static_cast<int8_t>(this->ServerGameSettings.GameType));
+	p += deserialize8(p, reinterpret_cast<int8_t*>(&this->ServerGameSettings.DefeatReveal));
+	p += deserialize8(p, reinterpret_cast<int8_t*>(&this->ServerGameSettings.Difficulty));
+	p += deserialize8(p, reinterpret_cast<int8_t*>(&this->ServerGameSettings.FoV));
+	p += deserialize8(p, reinterpret_cast<int8_t*>(&this->ServerGameSettings.GameType));
 	// Inside is part of the bitfield
 	// NetGameType is not needed
 	// NoFogOfWar is part of the bitfield
-	p += deserialize8(p, &static_cast<int8_t>(this->ServerGameSettings.NumUnits));
-	p += deserialize8(p, &static_cast<int8_t>(this->ServerGameSettings.Opponents));
-	p += deserialize8(p, &static_cast<int8_t>(this->ServerGameSettings.Resources));
-	p += deserialize8(p, &static_cast<int8_t>(this->ServerGameSettings.RevealMap));
+	p += deserialize8(p, reinterpret_cast<int8_t*>(&this->ServerGameSettings.NumUnits));
+	p += deserialize8(p, reinterpret_cast<int8_t*>(&this->ServerGameSettings.Opponents));
+	p += deserialize8(p, reinterpret_cast<int8_t*>(&this->ServerGameSettings.Resources));
+	p += deserialize8(p, reinterpret_cast<int8_t*>(&this->ServerGameSettings.RevealMap));
 	// The bitfield contains Inside and NoFogOfWar, as well as game-defined settings
-	p += deserialize32(p, &static_cast<uint32_t>(this->ServerGameSettings._Bitfield));
+	p += deserialize32(p, reinterpret_cast<uint32_t*>(&this->ServerGameSettings._Bitfield));
 
 	for (int i = 0; i < PlayerMax; ++i) {
-		p += deserialize8(p, &static_cast<int8_t>(this->ServerGameSettings.Presets[i].Race));
+		p += deserialize8(p, reinterpret_cast<int8_t*>(&this->ServerGameSettings.Presets[i].Race));
 	}
 	for (int i = 0; i < PlayerMax; ++i) {
-		p += deserialize8(p, &static_cast<int8_t>(this->CompOpt[i]));
+		p += deserialize8(p, reinterpret_cast<int8_t*>(&this->CompOpt[i]));
 	}
 	for (int i = 0; i < PlayerMax; ++i) {
 		p += deserialize8(p, &this->Ready[i]);
diff --git a/src/network/netconnect.cpp b/src/network/netconnect.cpp
index 111924239..20b173df5 100644
--- a/src/network/netconnect.cpp
+++ b/src/network/netconnect.cpp
@@ -1750,7 +1750,7 @@ void NetworkServerStartGame()
 #ifdef DEBUG
 	printf("INITIAL ServerSetupState:\n");
 	for (int i = 0; i < PlayerMax - 1; ++i) {
-		printf("%02d: CO: %d   Race: %d   Host: ", i, ServerSetupState.CompOpt[i], ServerSetupState.ServerGameSettings.Presets[i].Race);
+		printf("%02d: CO: %d   Race: %d   Host: ", i, (int)ServerSetupState.CompOpt[i], ServerSetupState.ServerGameSettings.Presets[i].Race);
 		if (ServerSetupState.CompOpt[i] == SlotOption::Available) {
 			const std::string hostStr = CHost(Hosts[i].Host, Hosts[i].Port).toString();
 			printf(" %s %s", hostStr.c_str(), Hosts[i].PlyName);
@@ -2039,7 +2039,7 @@ void NetworkGamePrepareGameSettings()
 
 #ifdef DEBUG
 	for (int i = 0; i < PlayerMax - 1; i++) {
-		printf("%02d: CO: %d   Race: %d   Name: ", i, ServerSetupState.CompOpt[i], ServerSetupState.ServerGameSettings.Presets[i].Race);
+		printf("%02d: CO: %d   Race: %d   Name: ", i, (int)ServerSetupState.CompOpt[i], ServerSetupState.ServerGameSettings.Presets[i].Race);
 		if (ServerSetupState.CompOpt[i] == SlotOption::Available) {
 			for (int h = 0; h != HostsCount; ++h) {
 				if (Hosts[h].PlyNr == i) {
@@ -2070,14 +2070,14 @@ void NetworkGamePrepareGameSettings()
 	for (int i = 0; i < h; i++) {
 		GameSettings.Presets[num[i]].Race = ServerSetupState.ServerGameSettings.Presets[num[i]].Race;
 		switch (ServerSetupState.CompOpt[num[i]]) {
-			case 0: {
+			case SlotOption::Available: {
 				GameSettings.Presets[num[i]].Type = PlayerTypes::PlayerPerson;
 				break;
 			}
-			case 1:
+			case SlotOption::Computer:
 				GameSettings.Presets[num[i]].Type = PlayerTypes::PlayerComputer;
 				break;
-			case 2:
+			case SlotOption::Closed:
 				GameSettings.Presets[num[i]].Type = PlayerTypes::PlayerNobody;
 			default:
 				break;
diff --git a/src/network/online_service.cpp b/src/network/online_service.cpp
index e101a4bfa..f1d203a41 100644
--- a/src/network/online_service.cpp
+++ b/src/network/online_service.cpp
@@ -1054,8 +1054,6 @@ public:
             game_settings |= 0x400;
         }
         switch (GameSettings.Resources) {
-        case -1:
-            break;
         case 1:
             game_settings |= 0x1000;
             break;
diff --git a/src/stratagus/player.cpp b/src/stratagus/player.cpp
index 2475657fa..3a9cc88a4 100644
--- a/src/stratagus/player.cpp
+++ b/src/stratagus/player.cpp
@@ -452,7 +452,7 @@ void CPlayer::Save(CFile &file) const
 		case PlayerTypes::PlayerPerson:        file.printf("\"person\",");          break;
 		case PlayerTypes::PlayerRescuePassive: file.printf("\"rescue-passive\","); break;
 		case PlayerTypes::PlayerRescueActive:  file.printf("\"rescue-active\","); break;
-		default:                  file.printf("%d,", p.Type); break;
+		default:                  file.printf("%d,", (int)p.Type); break;
 	}
 	file.printf(" \"race\", \"%s\",", PlayerRaces.Name[p.Race].c_str());
 	file.printf(" \"ai-name\", \"%s\",\n", p.AiName.c_str());
@@ -1291,14 +1291,13 @@ void DebugPlayers()
 		const char *playertype;
 
 		switch (Players[i].Type) {
-			case 0: playertype = "Don't know 0"; break;
-			case 1: playertype = "Don't know 1"; break;
-			case 2: playertype = "neutral     "; break;
-			case 3: playertype = "nobody      "; break;
-			case 4: playertype = "computer    "; break;
-			case 5: playertype = "person      "; break;
-			case 6: playertype = "rescue pas. "; break;
-			case 7: playertype = "rescue akt. "; break;
+			case PlayerTypes::Unset: playertype = "unset     "; break;
+			case PlayerTypes::PlayerNeutral: playertype = "neutral     "; break;
+			case PlayerTypes::PlayerNobody: playertype = "nobody      "; break;
+			case PlayerTypes::PlayerComputer: playertype = "computer    "; break;
+			case PlayerTypes::PlayerPerson: playertype = "person      "; break;
+			case PlayerTypes::PlayerRescuePassive: playertype = "rescue pas. "; break;
+			case PlayerTypes::PlayerRescueActive: playertype = "rescue akt. "; break;
 			default : playertype = "?unknown?   "; break;
 		}
 		DebugPrint("%2d: %8.8s %c %-8.8s %s %7s %s\n" _C_ i _C_ PlayerColorNames[i].c_str() _C_
diff --git a/src/stratagus/script.cpp b/src/stratagus/script.cpp
index 348f9fea8..b040c39ae 100644
--- a/src/stratagus/script.cpp
+++ b/src/stratagus/script.cpp
@@ -2188,7 +2188,7 @@ static int CclRestartStratagus(lua_State *l)
 #endif
 	}
 	if (insertRestartArgument) {
-		argv[newArgc - 2] = "-r";
+		argv[newArgc - 2] = (char*)"-r";
 	}
 	argv[newArgc - 1] = (char *)0;
 #ifdef WIN32