private static void SetupSinglePlayerGameSides( MapFile mapFile, List <Player> mapPlayers, List <Team> mapTeams, List <ScriptList> mapScriptLists) { mapPlayers.AddRange(mapFile.SidesList.Players); mapTeams.AddRange(mapFile.GetTeams()); mapScriptLists.AddRange(mapFile.GetPlayerScriptsList().ScriptLists); mapTeams.Add(CreateDefaultTeam("ReplayObserver")); }
private static void SetupSkirmishGameSides( Game game, MapFile mapFile, PlayerSetting[] playerSettings, GameType gameType, List <Player> mapPlayers, List <Team> mapTeams, List <ScriptList> mapScriptLists) { var originalMapPlayers = mapFile.SidesList.Players; // Neutral player. mapPlayers.Add(originalMapPlayers[0]); // Civilian player. It isn't necessarily the second player. // TODO: There might be more than one civilian player. mapPlayers.Add(originalMapPlayers.FirstOrDefault(x => (string)x.Properties["playerFaction"].Value == "FactionCivilian")); //var hasAIPlayer = false; for (var i = 0; i < playerSettings.Length; i++) { var playerSetting = playerSettings[i]; var factionPlayer = originalMapPlayers.First(x => (string)x.Properties["playerFaction"].Value == playerSetting.SideName); var isHuman = playerSetting.Owner == PlayerOwner.Player; var playerName = isHuman ? $"player{i}" : $"{factionPlayer.Properties["playerName"].Value}{i}"; //if (!isHuman) //{ // hasAIPlayer = true; //} var playerProperties = new AssetPropertyCollection(); playerProperties.AddAsciiString("playerFaction", (string)factionPlayer.Properties["playerFaction"].Value); playerProperties.AddAsciiString("playerName", playerName); playerProperties.AddAsciiString("playerDisplayName", (string)factionPlayer.Properties["playerDisplayName"].Value); playerProperties.AddBoolean("playerIsHuman", isHuman); playerProperties.AddInteger("playerColor", playerSetting.Color.ToUInt32()); // TODO: Other player properties. mapPlayers.Add(new Player { Properties = playerProperties, BuildList = factionPlayer.BuildList, }); } // Setup player relationships. var playerAllies = new string[playerSettings.Length]; var playerEnemies = new string[playerSettings.Length]; for (var i = 0; i < playerSettings.Length; i++) { playerAllies[i] = ""; playerEnemies[i] = ""; } for (var i = 0; i < playerSettings.Length; i++) { var outerPlayer = playerSettings[i]; for (var j = i + 1; j < playerSettings.Length; j++) { var innerPlayer = playerSettings[j]; if (outerPlayer.Team == innerPlayer.Team && outerPlayer.Team != 0) { playerAllies[i] += mapPlayers[j + 2].Properties["playerName"].Value + " "; playerAllies[j] += mapPlayers[i + 2].Properties["playerName"].Value + " "; } else { playerEnemies[i] += mapPlayers[j + 2].Properties["playerName"].Value + " "; playerEnemies[j] += mapPlayers[i + 2].Properties["playerName"].Value + " "; } } } for (var i = 0; i < playerSettings.Length; i++) { mapPlayers[i + 2].Properties.AddAsciiString("playerAllies", playerAllies[i]); mapPlayers[i + 2].Properties.AddAsciiString("playerEnemies", playerEnemies[i]); } var originalMapScriptLists = mapFile.GetPlayerScriptsList().ScriptLists; var playerNames = mapPlayers .Select(p => p.Properties.GetPropOrNull("playerName")?.Value.ToString()) .ToArray(); while (mapScriptLists.Count < mapPlayers.Count) { mapScriptLists.Add(null); } // Copy neutral player scripts. var neutralPlayerName = (string)mapPlayers[0].Properties["playerName"].Value; CopyScripts( originalMapScriptLists, playerNames, neutralPlayerName, mapScriptLists, 0, appendIndex: false); // Copy civilian player scripts. var civilianPlayerName = (string)mapPlayers[1].Properties["playerName"].Value; CopyScripts( originalMapScriptLists, playerNames, civilianPlayerName, mapScriptLists, 1, appendIndex: false); switch (game.SageGame) { case SageGame.CncGenerals: case SageGame.CncGeneralsZeroHour: CreateTeamsFromScbFile(game, mapPlayers, mapTeams, mapScriptLists, playerSettings, neutralPlayerName, civilianPlayerName); break; case SageGame.Bfme: case SageGame.Bfme2: case SageGame.Bfme2Rotwk: mapTeams.AddRange(mapFile.GetTeams()); break; } if (playerSettings.Length > 1) { var multiplayerScriptsEntry = game.ContentManager.GetScriptEntry(@"Data\Scripts\MultiplayerScripts.scb"); if (multiplayerScriptsEntry != null) { using var stream = multiplayerScriptsEntry.Open(); var multiplayerScripts = ScbFile.FromStream(stream); // TODO: This is a bit hardcoded. mapScriptLists[0] = multiplayerScripts.PlayerScripts.ScriptLists[0]; } } }