/// <summary> /// Silently replays all commands in the original command history up to the specified full /// turn and active faction indices.</summary> /// <param name="turn"> /// The index of the full turn where replay should stop.</param> /// <param name="faction"> /// The index of the faction whose activation during the specified <paramref name="turn"/> /// should stop the replay.</param> /// <param name="events"> /// An optional <see cref="TaskEvents"/> object used for progress display.</param> /// <returns> /// <c>true</c> if all commands in the specified range were successfully replayed, and if /// more commands remain in the original command history; otherwise, <c>false</c>.</returns> /// <remarks><para> /// <b>SilentReplay</b> is called by <see cref="Skip"/> to skip over part of an ongoing /// interactive replay. /// </para><para> /// <b>SilentReplay</b> shows a dialog and returns <c>false</c> when an <see /// cref="InvalidCommandException"/> occurs during command replay.</para></remarks> private bool SilentReplay(int turn, int faction, TaskEvents events) { string progressMessage = Global.Strings.StatusReplayCommandsCount; WorldState worldState = Session.Instance.WorldState; ExecutionContext context = new ExecutionContext(worldState, null, null); IList <Command> commands = this._originalWorldState.History.Commands; /* * We only replay up to the next-to-last command because * there is nothing left to resume after the last command, * and the caller will invoke Stop anyway at this point. */ while (this._commandIndex < commands.Count - 1) { // show running count every 0.5 seconds if (events != null && events.RestartTimer(500L)) { events.OnTaskMessage(this, progressMessage, this._commandIndex + 1, commands.Count); } // fetch next command and increment counter Command command = commands[this._commandIndex++]; try { // attempt to validate & execute command command.Validate(worldState); command.Execute(context); } catch (InvalidCommandException e) { ShowCommandError(e); return(false); } // check if specified turn reached if (command is EndTurnCommand && worldState.CurrentTurn >= turn) { // succeed if specified faction dead or active if (faction >= worldState.Factions.Count || worldState.ActiveFactionIndex >= faction) { return(true); } } } return(false); // no commands left }