private void InitDefaultSettings() { Players.Clear(); AIPlayers.Clear(); Players.Add(new PlayerInfo(ProgramConstants.PLAYERNAME, 0, 0, 0, 0)); PlayerInfo aiPlayer = new PlayerInfo("Easy AI", 0, 0, 0, 0); aiPlayer.IsAI = true; aiPlayer.AILevel = 2; AIPlayers.Add(aiPlayer); LoadDefaultMap(); }
/// <summary> /// Loads skirmish settings from an INI file on the file system. /// </summary> private void LoadSettings() { if (!File.Exists(ProgramConstants.GamePath + SETTINGS_PATH)) { InitDefaultSettings(); return; } var skirmishSettingsIni = new IniFile(ProgramConstants.GamePath + SETTINGS_PATH); string gameModeName = skirmishSettingsIni.GetStringValue("Settings", "GameMode", string.Empty); int gameModeIndex = GameModes.FindIndex(g => g.Name == gameModeName); if (gameModeIndex > -1) { GameMode = GameModes[gameModeIndex]; ddGameMode.SelectedIndex = gameModeIndex; string mapSHA1 = skirmishSettingsIni.GetStringValue("Settings", "Map", string.Empty); int mapIndex = GameMode.Maps.FindIndex(m => m.SHA1 == mapSHA1); if (mapIndex > -1) { lbMapList.SelectedIndex = mapIndex; while (mapIndex > lbMapList.LastIndex) { lbMapList.TopIndex++; } } } else { LoadDefaultMap(); } var player = PlayerInfo.FromString(skirmishSettingsIni.GetStringValue("Player", "Info", string.Empty)); if (player == null) { Logger.Log("Failed to load human player information from skirmish settings!"); InitDefaultSettings(); return; } CheckLoadedPlayerVariableBounds(player); player.Name = ProgramConstants.PLAYERNAME; Players.Add(player); List <string> keys = skirmishSettingsIni.GetSectionKeys("AIPlayers"); if (keys == null) { keys = new List <string>(); // No point skip parsing all settings if only AI info is missing. //Logger.Log("AI player information doesn't exist in skirmish settings!"); //InitDefaultSettings(); //return; } bool AIAllowed = !(Map.MultiplayerOnly || GameMode.MultiplayerOnly) || !(Map.HumanPlayersOnly || GameMode.HumanPlayersOnly); foreach (string key in keys) { if (!AIAllowed) { break; } var aiPlayer = PlayerInfo.FromString(skirmishSettingsIni.GetStringValue("AIPlayers", key, string.Empty)); CheckLoadedPlayerVariableBounds(aiPlayer, true); if (aiPlayer == null) { Logger.Log("Failed to load AI player information from skirmish settings!"); InitDefaultSettings(); return; } if (AIPlayers.Count < MAX_PLAYER_COUNT - 1) { AIPlayers.Add(aiPlayer); } } if (ClientConfiguration.Instance.SaveSkirmishGameOptions) { foreach (GameLobbyDropDown dd in DropDowns) { // Maybe we should build an union of the game mode and map // forced options, we'd have less repetitive code that way if (GameMode != null) { int gameModeMatchIndex = GameMode.ForcedDropDownValues.FindIndex(p => p.Key.Equals(dd.Name)); if (gameModeMatchIndex > -1) { Logger.Log("Dropdown '" + dd.Name + "' has forced value in gamemode - saved settings ignored."); continue; } } if (Map != null) { int gameModeMatchIndex = Map.ForcedDropDownValues.FindIndex(p => p.Key.Equals(dd.Name)); if (gameModeMatchIndex > -1) { Logger.Log("Dropdown '" + dd.Name + "' has forced value in map - saved settings ignored."); continue; } } dd.UserSelectedIndex = skirmishSettingsIni.GetIntValue("GameOptions", dd.Name, dd.UserSelectedIndex); if (dd.UserSelectedIndex > -1 && dd.UserSelectedIndex < dd.Items.Count) { dd.SelectedIndex = dd.UserSelectedIndex; } } foreach (GameLobbyCheckBox cb in CheckBoxes) { if (GameMode != null) { int gameModeMatchIndex = GameMode.ForcedCheckBoxValues.FindIndex(p => p.Key.Equals(cb.Name)); if (gameModeMatchIndex > -1) { Logger.Log("Checkbox '" + cb.Name + "' has forced value in gamemode - saved settings ignored."); continue; } } if (Map != null) { int gameModeMatchIndex = Map.ForcedCheckBoxValues.FindIndex(p => p.Key.Equals(cb.Name)); if (gameModeMatchIndex > -1) { Logger.Log("Checkbox '" + cb.Name + "' has forced value in map - saved settings ignored."); continue; } } cb.Checked = skirmishSettingsIni.GetBooleanValue("GameOptions", cb.Name, cb.Checked); } } }
private void LoadSettings() { if (!File.Exists(ProgramConstants.GamePath + SETTINGS_PATH)) { InitDefaultSettings(); return; } var skirmishSettingsIni = new IniFile(ProgramConstants.GamePath + SETTINGS_PATH); var player = PlayerInfo.FromString(skirmishSettingsIni.GetStringValue("Player", "Info", string.Empty)); if (player == null) { Logger.Log("Failed to load human player information from skirmish settings!"); InitDefaultSettings(); return; } CheckLoadedPlayerVariableBounds(player); player.Name = ProgramConstants.PLAYERNAME; Players.Add(player); List <string> keys = skirmishSettingsIni.GetSectionKeys("AIPlayers"); if (keys == null) { Logger.Log("AI player information doesn't exist in skirmish settings!"); InitDefaultSettings(); return; } foreach (string key in keys) { var aiPlayer = PlayerInfo.FromString(skirmishSettingsIni.GetStringValue("AIPlayers", key, string.Empty)); CheckLoadedPlayerVariableBounds(aiPlayer); if (aiPlayer == null) { Logger.Log("Failed to load AI player information from skirmish settings!"); InitDefaultSettings(); return; } if (AIPlayers.Count < MAX_PLAYER_COUNT - 1) { AIPlayers.Add(aiPlayer); } } string gameModeName = skirmishSettingsIni.GetStringValue("Settings", "GameMode", string.Empty); int gameModeIndex = GameModes.FindIndex(g => g.Name == gameModeName); if (gameModeIndex > -1) { GameMode gm = GameModes[gameModeIndex]; string mapSHA1 = skirmishSettingsIni.GetStringValue("Settings", "Map", string.Empty); int mapIndex = gm.Maps.FindIndex(m => m.SHA1 == mapSHA1); if (mapIndex > -1) { ddGameMode.SelectedIndex = gameModeIndex; lbMapList.SelectedIndex = mapIndex; while (mapIndex > lbMapList.LastIndex) { lbMapList.TopIndex++; } return; } } LoadDefaultMap(); }
private void HandlePlayerOptionsBroadcast(string data) { if (IsHost) { return; } string[] parts = data.Split(ProgramConstants.LAN_DATA_SEPARATOR); int playerCount = parts.Length / 8; if (parts.Length != playerCount * 8) { return; } Players.Clear(); AIPlayers.Clear(); for (int i = 0; i < playerCount; i++) { int baseIndex = i * 8; string name = parts[baseIndex]; int side = Conversions.IntFromString(parts[baseIndex + 1], -1); int color = Conversions.IntFromString(parts[baseIndex + 2], -1); int start = Conversions.IntFromString(parts[baseIndex + 3], -1); int team = Conversions.IntFromString(parts[baseIndex + 4], -1); int readyStatus = Conversions.IntFromString(parts[baseIndex + 5], -1); string ipAddress = parts[baseIndex + 6]; int aiLevel = Conversions.IntFromString(parts[baseIndex + 7], -1); if (side < 0 || side > SideCount + RandomSelectorCount) { return; } if (color < 0 || color > MPColors.Count) { return; } if (start < 0 || start > MAX_PLAYER_COUNT) { return; } if (team < 0 || team > 4) { return; } if (ipAddress == "127.0.0.1") { ipAddress = hostEndPoint.Address.ToString(); } bool isAi = aiLevel > -1; if (aiLevel > 2) { return; } PlayerInfo pInfo; if (!isAi) { pInfo = new LANPlayerInfo(encoding); pInfo.Name = name; Players.Add(pInfo); } else { pInfo = new PlayerInfo(); pInfo.Name = AILevelToName(aiLevel); pInfo.IsAI = true; pInfo.AILevel = aiLevel; AIPlayers.Add(pInfo); } pInfo.SideId = side; pInfo.ColorId = color; pInfo.StartingLocation = start; pInfo.TeamId = team; pInfo.Ready = readyStatus > 0; pInfo.IPAddress = ipAddress; } CopyPlayerDataToUI(); }
public override void Read(NetIncomingMessage inInputStream) { bool stateBit = inInputStream.ReadBoolean(); UInt32 readState = 0; if (stateBit) { int playerId = inInputStream.ReadInt32(); SetPlayerId(playerId); Team = (core.Team)inInputStream.ReadUInt32(GameMode.MaxTeamBits); UserId = inInputStream.ReadString(); readState |= (UInt32)ReplicationState.PlayerId; } oldRotation = GetRotation(); oldLocation = GetLocation(); oldVelocity = GetVelocity(); Vector3 replicatedLocation = default(Vector3); Vector3 replicatedVelocity = default(Vector3); stateBit = inInputStream.ReadBoolean(); if (stateBit) { inInputStream.Read(ref replicatedVelocity); //replicatedVelocity.y = GetVelocity().y; SetVelocity(replicatedVelocity); //Debug.Log("replicatedVelocity : " + replicatedVelocity + ", player_id :" + GetPlayerId()); inInputStream.Read(ref replicatedLocation); //replicatedLocation.y = GetLocation().y; SetLocation(replicatedLocation); //LogHelper.LogInfo($"replicatedLocation : {replicatedLocation.x}, {replicatedLocation.y}, {replicatedLocation.z}, player_id : {GetPlayerId()}"); //if (replicatedVelocity.IsZero()) // mThrustDir = 0f; //else // mThrustDir = 1.0f; //is_move = inInputStream.ReadBoolean(); //if (is_move) //{ // degree = inInputStream.ReadUInt32(9); // mDirection = core.MathHelpers.DegreeToVector3Cached((int)degree); //} if (replicatedVelocity.x != 0 || replicatedVelocity.z != 0) { mDirection = new Vector3(replicatedVelocity.x, 0, replicatedVelocity.z); } //Debug.Log($"degree{degree}, mDirection : {mDirection}, player_id :{GetPlayerId()}"); readState |= (UInt32)ReplicationState.Pose; } // Health stateBit = inInputStream.ReadBoolean(); if (stateBit) { IsHealthUp = false; var HP = (int)inInputStream.ReadUInt32(12); if (mHealth <= HP) { IsHealthUp = true; } mLastHealth = mHealth; mHealth = HP; readState |= (UInt32)ReplicationState.Health; } // State stateBit = inInputStream.ReadBoolean(); if (stateBit) { IsInterpolate = true; LastStateServerSide = StateServerSide; StateServerSide = (core.ActorState)inInputStream.ReadInt32(4); LogHelper.LogInfo($"state serverside {StateServerSide}"); inInputStream.Read(ref TargetPos); JumpPower = inInputStream.ReadFloat(); JumpDuration = inInputStream.ReadFloat(); GameModeType mode = (GameModeType)inInputStream.ReadUInt32(GameMode.MaxGameModeTypeBits); switch (mode) { case GameModeType.KillTheKing: { isLastKilled = inInputStream.ReadBoolean(); if (isLastKilled) { killPlayerId = inInputStream.ReadInt32(); //Debug.Log($"public bool ReadState(NetIncomingMessage inOutputStream, Actor actor) killPlayerId : {killPlayerId}"); } } break; default: break; } readState |= (UInt32)ReplicationState.State; } // Character stateBit = inInputStream.ReadBoolean(); if (stateBit) { SelectedCharacter = inInputStream.ReadByte(); CharacterLevel = (int)inInputStream.ReadUInt32(6); SetCharacterData(SelectedCharacter, CharacterLevel); LogHelper.LogInfo($"Setting Character {characterData.Remark}"); readState |= (UInt32)ReplicationState.Character; } // Spawn stateBit = inInputStream.ReadBoolean(); if (stateBit) { degree = inInputStream.ReadUInt32(9); mDirection = core.MathHelpers.DegreeToVector3Cached((int)degree); readState |= (UInt32)ReplicationState.Spawn; } // AI stateBit = inInputStream.ReadBoolean(); if (stateBit) { AIPlayers.Clear(); var cnt = inInputStream.ReadUInt32((int)AIPlayer.MaxAIPlayerBit); //LogHelper.LogInfo($"ai count {cnt}"); for (int i = 0; i < cnt; ++i) { AIPlayers.Add(inInputStream.ReadInt32()); LogHelper.LogInfo($"ai player network_id:{AIPlayers[i]}"); } readState |= (UInt32)ReplicationState.AI; } // Hide stateBit = inInputStream.ReadBoolean(); if (stateBit) { var size = (int)inInputStream.ReadUInt32(4); HiddenMapObjects.Clear(); for (int i = 0; i < size; ++i) { HiddenMapObjects.Add(inInputStream.ReadUInt16()); } if (HiddenMapObjects.Count > 0) { IsHide = true; } else { IsHide = false; } readState |= (UInt32)ReplicationState.Hide; //LogHelper.LogInfo($"hide {IsHide}"); } OnAfterDeserialize(readState); }