/// <summary>
 /// Pushes a command into the command buffer.
 /// </summary>
 /// <param name="commandPackage">The command to push.</param>
 public void PushOutgoingCommand(RCCommand command)
 {
     if (command == null)
     {
         throw new ArgumentNullException("command");
     }
     this.commandBuffer.Add(command.ToPackage());
 }
        /// <summary>
        /// Gets the list of the incoming commands. Calling this method automatically clears the incoming command queue.
        /// </summary>
        /// <returns>A list of the incoming commands.</returns>
        public List <RCCommand> GetIncomingCommands()
        {
            List <RCCommand> retList = new List <RCCommand>();

            foreach (RCPackage cmdPackage in this.incomingCommands)
            {
                retList.Add(RCCommand.FromPackage(cmdPackage));
            }
            this.incomingCommands.Clear();
            return(retList);
        }
示例#3
0
        /// <summary>
        /// Tries to complete the given listener and updates the command panel and the target position input slots accordingly.
        /// </summary>
        /// <param name="listener">The listener to be completed.</param>
        private void CompleteListener(CommandInputListener listener)
        {
            using (new CommandBuilderPermission(this.commandBuilder))
            {
                CommandInputListener.CompletionResultEnum completionResult = listener.TryComplete();
                if (completionResult == CommandInputListener.CompletionResultEnum.Succeeded)
                {
                    /// Listener completed successfully -> activate children.
                    List <CommandInputListener> children = new List <CommandInputListener>(listener.Children);
                    if (children.Count > 0)
                    {
                        /// Still has children -> continue the current command input procedure.
                        this.completedListeners.Add(listener);
                        this.activeListeners = children;
                    }
                    else
                    {
                        /// No children -> current command input procedure completed.
                        this.completedListeners.Clear();
                        this.activeListeners = new List <CommandInputListener>(this.rootListeners);
                        RCCommand command = this.commandBuilder.CreateCommand();
                        this.commandBuilder.Reset();
                        TraceManager.WriteAllTrace(command, BizLogicTraceFilters.INFO);
                        if (this.NewCommand != null)
                        {
                            this.NewCommand(command);
                        }
                    }
                }
                else if (completionResult == CommandInputListener.CompletionResultEnum.FailedAndCancel)
                {
                    /// Listener completion failed and command input procedure shall be cancelled.
                    this.completedListeners.Clear();
                    this.activeListeners = new List <CommandInputListener>(this.rootListeners);
                    this.commandBuilder.Reset();
                }
                else if (completionResult == CommandInputListener.CompletionResultEnum.FailedButContinue)
                {
                    /// Listener completion failed but command input procedure shall be continued.
                }
            }

            /// Update the command panel and the target position input slots.
            this.UpdateSlots();
        }
示例#4
0
        /// <see cref="ICommandManagerBC.PressProductionButton"/>
        public void PressProductionButton(int panelPosition)
        {
            int[] currentSelection = this.selectionManager.CurrentSelection.ToArray();
            if (currentSelection.Length != 1)
            {
                throw new InvalidOperationException("Exactly 1 entity has to be selected!");
            }

            /// Check if the selected entity exists and its owner is the local player.
            Entity entity = this.ActiveScenario.GetElementOnMap <Entity>(currentSelection[0], MapObjectLayerEnum.GroundObjects, MapObjectLayerEnum.AirObjects);

            if (entity == null)
            {
                throw new InvalidOperationException(String.Format("Entity with ID '{0}' doesn't exist!", currentSelection[0]));
            }
            if (entity.Owner == null || entity.Owner.PlayerIndex != (int)this.selectionManager.LocalPlayer)
            {
                throw new InvalidOperationException("The owner of the selected entity is not the local player!");
            }

            /// Get the ID of the production job at the given position in the active production line of the selected entity.
            ProductionLine productionLine = entity.ActiveProductionLine;

            if (productionLine == null)
            {
                throw new InvalidOperationException("The selected entity has no active production line!");
            }
            int productionJobID = productionLine.GetJobID(panelPosition);

            /// Create and send the CancelProduction command.
            CommandBuilder cancelProductionCommandBuilder = new CommandBuilder();

            cancelProductionCommandBuilder.SetEnabled(true);
            cancelProductionCommandBuilder.CommandType = CANCEL_PRODUCTION_COMMAND_TYPE;
            cancelProductionCommandBuilder.Parameter   = productionJobID.ToString(CultureInfo.InvariantCulture);

            RCCommand cancelProductionCommand = cancelProductionCommandBuilder.CreateCommand();

            TraceManager.WriteAllTrace(cancelProductionCommand, BizLogicTraceFilters.INFO);
            if (this.NewCommand != null)
            {
                this.NewCommand(cancelProductionCommand);
            }
        }
示例#5
0
        /// <see cref="ICommandManagerBC.PressCommandButton"/>
        public void SendFastCommand(RCNumVector position)
        {
            if (position == RCNumVector.Undefined)
            {
                throw new ArgumentNullException("position");
            }

            CommandBuilder fastCommandBuilder = new CommandBuilder();

            fastCommandBuilder.SetEnabled(true);
            fastCommandBuilder.TargetPosition = position;

            RCCommand fastCommand = fastCommandBuilder.CreateCommand();

            TraceManager.WriteAllTrace(fastCommand, BizLogicTraceFilters.INFO);
            if (this.NewCommand != null)
            {
                this.NewCommand(fastCommand);
            }
        }
 /// <see cref="IMultiplayerService.PostCommand"/>
 public void PostCommand(RCCommand cmd)
 {
     this.commandDispatcher.PushOutgoingCommand(cmd);
 }