Exemplo n.º 1
0
        /// <overloads>
        /// Starts an interactive replay.</overloads>
        /// <summary>
        /// Replays all commands present in the specified <see cref="WorldState"/> but missing from
        /// the current <see cref="WorldState"/>.</summary>
        /// <param name="worldState">
        /// The <see cref="WorldState"/> containing the new commands to show in an interactive
        /// replay.</param>
        /// <param name="isComputer">
        /// The new value for the <see cref="IsComputerTurn"/> property while the replay is active.
        /// </param>
        /// <exception cref="ArgumentException">
        /// One of the conditions described in <see cref="History.AddCommands"/>.</exception>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="worldState"/> is a null reference.</exception>
        /// <exception cref="PropertyValueException">
        /// The current session <see cref="Session.State"/> is neither <see
        /// cref="SessionState.Closed"/>, <see cref="SessionState.Computer"/>, nor <see
        /// cref="SessionState.Human"/>.</exception>
        /// <remarks><para>
        /// <b>Start</b> sets the session <see cref="Session.State"/> to <see
        /// cref="SessionState.Replay"/> and <see cref="CurrentState"/> to <see
        /// cref="ReplayState.Play"/>, and begins an interactive replay of all history commands
        /// stored in the specified <paramref name="worldState"/> that are not present in the <see
        /// cref="WorldState.History"/> of the current session's <see cref="Session.WorldState"/>.
        /// </para><para>
        /// When the replay ends or is aborted, the current session's <see
        /// cref="Session.WorldState"/> will be set to the specified <paramref name="worldState"/>,
        /// and its previous value will be discarded. The session's original <see
        /// cref="Graphics.MapView.SelectedSite"/> is likewise discarded and replaced with <see
        /// cref="Site.InvalidLocation"/>.
        /// </para><para>
        /// The specified <paramref name="worldState"/> may contain the same number of commands as
        /// that of the current <see cref="Session"/>. In this case, <b>Start</b> briefly highlights
        /// the home site of the active faction but does nothing else.</para></remarks>

        public void Start(WorldState worldState, bool isComputer)
        {
            CheckStartState();

            // store computer turn flag
            IsComputerTurn = isComputer;

            // store current history command count
            History history = Session.Instance.WorldState.History;
            int     index   = history.Commands.Count;

            // append new history commands, if any
            history.AddCommands(worldState.History);

            // set restore point to new world state
            this._originalWorldState = worldState;

            // save current session state
            this._originalState = Session.State;

            // ignore current site selection
            this._originalSelected = Site.InvalidLocation;

            // start replay with first new command
            Debug.Assert(index <= history.Commands.Count);
            this._commandIndex = index;

            // switch session to Replay state
            Session.State = SessionState.Replay;
            MainWindow.Instance.StatusMessage.Push(Global.Strings.StatusReplay);

            // show active faction's home site
            ShowFaction(Session.Instance.WorldState.ActiveFaction);

            // enter Play state
            CurrentState = ReplayState.Play;
            AsyncAction.Run(PlayCommands);
        }