void RefreshFreeFactions() { Session session = (Session)gGamesListView.SelectedItem; if (session == null) { return; } FactionInfo playerFaction = session.GetPlayerFaction(); fFactionComboBox.Items.Clear(); if (playerFaction != null) { fFactionComboBox.Items.Add(playerFaction); fFactionComboBox.SelectedIndex = 0; } foreach (FactionInfo faction in session.GetFreeFactions().OrderBy(f => f.Index)) { fFactionComboBox.Items.Add(faction); } if (fFactionComboBox.Items.Count == 0) { fFactionComboBox.Text = "Game is full."; fFactionComboBox.IsEnabled = false; } else { fFactionComboBox.IsEnabled = true; } }
public void ChooseFaction(FactionInfo faction) { byte factionIndex = (byte)(faction == null ? 0 : faction.Index); if (factionIndex == playerFactionIndex) { return; } if (factionIndex == 0) { freeFactionIndices.Add(playerFactionIndex); takenFactionIndices.Remove(playerFactionIndex); } else { if (!freeFactionIndices.Contains(factionIndex)) { Debug.ShowWarning("Faction is already taken!"); return; } if (playerFactionIndex != 0) { freeFactionIndices.Add(playerFactionIndex); takenFactionIndices.Remove(playerFactionIndex); } freeFactionIndices.Remove(factionIndex); takenFactionIndices.Add(factionIndex); if (lastPlayedFactionIndex == 0 && startFactionIndex == 0) { startFactionIndex = factionIndex; SaveGameInfo(); } } SaveFactionsFile(); if (lastPlayedFactionIndex == 0 && playerFactionIndex == startFactionIndex) // needs a new start faction { if (factionIndex == 0) { startFactionIndex = takenFactionIndices.Count > 0 ? takenFactionIndices[0] : (byte)0; SaveGameInfo(); } else { startFactionIndex = factionIndex; SaveGameInfo(); } } playerFactionIndex = factionIndex; SavePlayerInfo(); UpdateCurrentFaction(); }
static ModFolder LoadMod(string path, string name) { if (!Directory.Exists(Path.Combine(path, "data"))) { return(null); } List <FactionInfo> factions = new List <FactionInfo>(FactionInfo.LoadFactions(path)); if (factions.Count == 0) { return(null); } List <Campaign> campaigns = new List <Campaign>(Campaign.LoadCampaigns(path, factions)); if (campaigns.Count == 0) { return(null); } return(new ModFolder(path, name, campaigns, factions)); }
static void ReadFactions(StreamReader sr, IEnumerable <FactionInfo> factions, List <FactionInfo> output) { output.Clear(); string line; while ((line = sr.ReadRomeLine()) != null) { if (line.Length == 0) { continue; } if (string.Equals(line, "end", StringComparison.OrdinalIgnoreCase)) { break; } FactionInfo factionInfo = factions.FirstOrDefault(f => string.Equals(line, f.Name, StringComparison.OrdinalIgnoreCase)); if (factionInfo != null) { output.Add(factionInfo); } } }
public static void StartGame(Session session, Action OnExit) { if (Process.GetProcessesByName("RomeTW").Length > 0) { Debug.ShowWarning("Rome is already running!"); return; } if (session == null || OnExit == null || session.Installation == null) { return; } FactionInfo currentFaction = session.GetCurrentFaction(); if (currentFaction == null) { return; } if (currentFaction != session.GetPlayerFaction()) { Debug.ShowWarning("It's not the player's turn!"); return; } CodeVersion version = session.Version; Process.Start(new ProcessStartInfo(version.ProcessStartPath ?? session.Installation.FilePath)); Process proc; long startTicks = DateTime.UtcNow.Ticks; while (true) { var arr = Process.GetProcessesByName("RomeTW"); if (arr.Length > 0) { proc = arr[0]; break; } if (DateTime.UtcNow.Ticks - startTicks > 10 * TimeSpan.TicksPerSecond) { Debug.ShowWarning("Failed to start Rome!"); return; } System.Threading.Thread.Sleep(10); } SuspendProcess(proc); proc.Exited += (s, e) => Application.Current.Dispatcher.Invoke(OnExit); proc.EnableRaisingEvents = true; EditSettings(proc, version, session); EditFactionTurnStart(proc, version, session); if (session.GetLastPlayedFaction() == null) // new campaign { EditPlayableFactions(proc, version, session); EditStartNewCampaign(proc, version, session); } else { EditLoadGame(proc, version, session); EditFinishedLoading(proc, version, session); } //System.Windows.MessageBox.Show(""); ResumeProcess(proc); }
void CreateGame(object sender, RoutedEventArgs e) { try { string name = cNameTextBox.Text; if (string.IsNullOrWhiteSpace(name)) { Debug.ShowWarning("Please type in a game session name."); cNameTextBox.Focus(); return; } int invalidChar = name.IndexOfAny(Path.GetInvalidFileNameChars()); if (invalidChar >= 0) { Debug.ShowWarning("The symbol {0} is not allowed in the game session name.", name[invalidChar].ToString()); cNameTextBox.Focus(); return; } if (Session.ContainsSession(name)) { Debug.ShowWarning("There is already a game session with the name " + name); cNameTextBox.Focus(); return; } string transferPath = Path.GetFullPath(cTransferTextBox.Text); Directory.CreateDirectory(transferPath); string gameFile = Path.Combine(transferPath, name, Session.GameFileName); if (File.Exists(gameFile)) { Debug.ShowWarning("There is already a game session file in the following path. It might be from an older session which you left. If you are sure it's not used by / transferring to other players anymore delete it manually.\n\n" + gameFile); return; } Difficulty difficulty = (byte)cDifficultyComboBox.SelectedIndex; if (difficulty == Difficulty.Unset) { Debug.ShowWarning("Invalid difficulty."); cDifficultyComboBox.Focus(); return; } if (cFactionComboBox.SelectedItem == null) { Debug.ShowWarning("Please choose your starter faction."); cFactionComboBox.Focus(); return; } FactionInfo faction = ((CampaignFaction)cFactionComboBox.SelectedItem).Faction; if (faction == null || faction.Index == 0 || string.IsNullOrWhiteSpace(faction.Name)) { Debug.ShowWarning("Invalid starter faction."); cFactionComboBox.Focus(); return; } CreationArgs args = new CreationArgs(); args.Installation = (Installation)cInstallListView.SelectedItem; args.Mod = (ModFolder)cModComboBox.SelectedItem; args.Campaign = (Campaign)cCampaignComboBox.SelectedItem; args.Name = name; args.TransferPath = transferPath; args.Difficulty = difficulty; args.StartFaction = faction; args.FreeFactions = cSelectedFactionsListBox.Items.Cast <CampaignFaction>().Select(f => f.Faction); args.AutoSolve = cAutoSolveComboBox.IsChecked == true; args.AutoManage = cManageAllComboBox.IsChecked != true; args.ShortCampaign = cShortCampaignComboBox.IsChecked == true; args.ArcadeBattles = cArcadeBattlesComboBox.IsChecked == true; args.NoBattleTimeLimit = cNoTimeLimitComboBox.IsChecked == true; Session.Create(args); Settings.LastTransferPath = transferPath; Settings.Save(); ShowMenu(Menus.GameList); } catch (Exception exc) { Debug.ShowException(exc); } }
public static IEnumerable <FactionInfo> LoadFactions(string modFolder) { string file = Path.Combine(modFolder, "data/descr_sm_factions.txt"); if (File.Exists(file)) { using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read)) using (StreamReader sr = new StreamReader(fs)) { FactionInfo faction = null; string line; while ((line = sr.ReadRomeLine()) != null) { if (line.Length == 0) { continue; } if (line.StartsWith("faction", StringComparison.OrdinalIgnoreCase)) // new faction { if (faction != null) // save current faction { if (faction.index != 0) { yield return(faction); } faction = null; } string nameEntry = line.Substring("faction".Length); int commaIndex = nameEntry.IndexOf(','); // remove additional information (BI) if (commaIndex >= 0) { nameEntry = nameEntry.Remove(commaIndex); } nameEntry = nameEntry.Trim(); if (nameEntry.Length == 0) { continue; } faction = new FactionInfo(nameEntry); } else { if (faction == null) { continue; } if (line.StartsWith("standard_index", StringComparison.OrdinalIgnoreCase)) { byte index; if (byte.TryParse(line.Substring("standard_index".Length), out index)) { faction.index = (byte)(index + 1); } } } } if (faction != null && faction.index != 0) { yield return(faction); } } } }
public CampaignFaction(FactionInfo faction, bool playable) { this.faction = faction; this.playable = playable; }