/// <Summary> /// Process the timer event, used to determine how often the console, /// checks if the AI needs to run or a new turn can be generated. /// </Summary> /// <param name="sender">The source of the event.</param> /// <param name="e">A <see cref="EventArgs"/> that contains the event data.</param> private void ConsoleTimer_Tick(object sender, EventArgs e) { // Don't want multiple ticks consoleTimer.Enabled = false; try { // TODO (priority 4) - reading all the .orders files is overkill. Only really want to read orders for races that aren't turned in yet, and only if they have changed. OrderReader orderReader = new OrderReader(serverState); orderReader.ReadOrders(); if (SetPlayerList()) { generateTurnMenuItem.Enabled = true; if (autoGenerateCheckBox.Checked) { // TODO (Priority 4) Grey out the players or something so it is clearer you can not click to play at the moment. GenerateTurn(); } } else { if (runAiCheckBox.Checked) { // Look for AIs to run, and launch their processes. Do this in a seperate thread, so it does not stop the human player from opening a turn. // Dan 7 May 17 - not sure if putting this in a thread improved performance or not. Doesn't seem to hurt so I am leaving it in. ThreadPool.QueueUserWorkItem(new WaitCallback(RunAI)); } } } finally { consoleTimer.Enabled = true; } }
/// <summary> /// Open an existing game. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">A <see cref="EventArgs"/> that contains the event data.</param> private void OpenGameToolStripMenuItem_Click(object sender, EventArgs e) { // have the user identify the game to open try { OpenFileDialog fd = new OpenFileDialog(); fd.Title = "Open Game"; fd.FileName = "NovaServer" + Global.ServerStateExtension; DialogResult result = fd.ShowDialog(); if (result != DialogResult.OK) { return; } serverState.StatePathName = fd.FileName; } catch { Report.FatalError("Unable to open a game."); } // TODO (priority 4) - This code is a repeat of what we do when the console is normally opened. Consider consolodating these sections. serverState.GameFolder = System.IO.Path.GetDirectoryName(serverState.StatePathName); folderPath.Text = serverState.GameFolder; if (File.Exists(serverState.StatePathName)) { // We have a known game in progress. Load it: serverState.Restore(); serverState.GameInProgress = true; turnYearLabel.Text = serverState.TurnYear.ToString(); // load the game settings also GameSettings.Restore(); generateTurnMenuItem.Enabled = true; turnYearLabel.Text = serverState.TurnYear.ToString(); OrderReader orderReader = new OrderReader(this.serverState); orderReader.ReadOrders(); SetPlayerList(); Invalidate(); // remember which game we are playing using (Config conf = new Config()) { conf[Global.ServerStateKey] = serverState.StatePathName; } } else { /// If nothing is defined then the only option is to enable the /// "New Game" button. serverState.GameInProgress = false; this.newGameMenuItem.Enabled = true; turnYearLabel.Text = "Create a new game."; } }
/// <Summary> /// Refresh the turn in fields... /// </Summary> /// <param name="sender">The source of the event.</param> /// <param name="e">A <see cref="EventArgs"/> that contains the event data.</param> private void RefreshMenuItem_Click(object sender, EventArgs e) { // FIXME (priority 4) - Delete this once proven to work without it (release testing). - Dan 09 Jul 11 // Commented this out as console is searching for files each time the timer goes off. // ServerState.Data.AllRaces = FileSearcher.GetAvailableRaces(); OrderReader orderReader = new OrderReader(serverState); orderReader.ReadOrders(); if (SetPlayerList()) { generateTurnMenuItem.Enabled = true; } }
/// <Summary> /// Populate the nova console form when first loaded. /// </Summary> /// <param name="sender">The source of the event.</param> /// <param name="e">A <see cref="EventArgs"/> that contains the event data.</param> private void OnFirstShow(object sender, EventArgs e) { /// This function is called when the Nova Console form is loaded. /// Normally this is to manage a game in progress or one newly created, /// by the NewGame wizard. However it may be launched directly with either /// no game in progress or the in progress game unknown. /// /// First we try to open a current game based on the config file settings: serverState.StatePathName = FileSearcher.GetFile(Global.ServerStateKey, false, "", "", "", false); serverState.GameFolder = FileSearcher.GetFolder(Global.ServerFolderKey, Global.ServerFolderName); folderPath.Text = serverState.GameFolder; if (File.Exists(serverState.StatePathName)) { // We have a known game in progress. Load it: serverState.Restore(); serverState.GameInProgress = true; // load the game settings also GameSettings.Restore(); generateTurnMenuItem.Enabled = true; turnYearLabel.Text = serverState.TurnYear.ToString(); OrderReader orderReader = new OrderReader(serverState); orderReader.ReadOrders(); SetPlayerList(); Invalidate(); } else { /// If nothing is defined then the only option is to enable the /// "New Game" button. serverState.GameInProgress = false; newGameMenuItem.Enabled = true; turnYearLabel.Text = "Create a new game."; } }