/// <summary>
        /// Gets the next movement command - expects you to have confirmed there is a movement first
        /// </summary>
        /// <returns></returns>
        public MovementCommandDirection GetNextMovementCommandDirection(bool bPeek = false)
        {
            if (movementQueue.Count <= 0)
            {
                throw new Exception("You have requested to GetNextMovementCommand but there are non left.");
            }
            MovementCommandDirection direction = movementQueue.Peek().Direction;

            // calculate how many you will have left after you
            int nRemaining = movementQueue.Peek().Iterations - 1;

            Debug.Assert(nRemaining >= 0);

            if (nRemaining == 0 && !bPeek)
            {
                // we are done with it, so let's toss it
                movementQueue.Dequeue();
            }
            else if (!bPeek)
            {
                // we have more moves, but we are going to spend one
                movementQueue.Peek().SpendSingleMovement();
            }

            return(direction);
        }
Beispiel #2
0
        /// <summary>
        /// Construct a NonPlayerCharacterMovement
        /// </summary>
        /// <param name="nDialogIndex">the index of an NPC</param>
        /// <param name="movementInstructionDataChunk">The full memory chunk of all movement instructions</param>
        /// <param name="movementOffsetDataChunk">the full memory chunk of the movement offsets</param>
        public NonPlayerCharacterMovement(int nDialogIndex, DataChunk movementInstructionDataChunk, DataChunk movementOffsetDataChunk)
        {
            // we totally ignore the first entry, since it's bad stuff
            if (nDialogIndex == 0)
            {
                return;
            }

            this._movementInstructionDataChunk = movementInstructionDataChunk;
            this._movementOffsetDataChunk      = movementOffsetDataChunk;
            this._nDialogIndex = nDialogIndex;

            // todo: not a very efficient method of getting a UINT16 from the list -> it has to create a brand new list!
            _nOffset = movementOffsetDataChunk.GetChunkAsUint16List() [nDialogIndex];

            // if it has the value of 0xFFFF then it indicates there are currently no instructions
            if (_nOffset == 0xFFFF)
            {
                return;
            }

            // calculate the offset
            int nOffsetIndex = (nDialogIndex) * (MAX_COMMAND_LIST_ENTRIES * MAX_MOVEMENT_COMMAND_SIZE);

            // get a copy because the GetAsByteList is an expensive method call
            List <byte> rawData = movementInstructionDataChunk.GetAsByteList();

            // gets a smaller version of it - much easier to keep track of
            _loadedData = rawData.GetRange(nOffsetIndex, MAX_COMMAND_LIST_ENTRIES * 2);

            int nIndex = _nOffset;

            for (int i = 0; i < MAX_COMMAND_LIST_ENTRIES; i++)
            {
                byte nIterations = _loadedData[nIndex];
                MovementCommandDirection direction = (MovementCommandDirection)_loadedData[nIndex + 1];

                // if we have hit 0xFF then there is nothing else in the list and we can just return
                if (nIterations == 0xFF || nIterations == 0)
                {
                    return;
                }

                if (!(direction == MovementCommandDirection.East || direction == MovementCommandDirection.West || direction == MovementCommandDirection.North ||
                      direction == MovementCommandDirection.South))
                {
                    throw new Ultima5ReduxException("a bad direction was set: " + direction.ToString());
                }


                // we have a proper movement instruction so let's add it to the queue
                MovementCommand movementCommand = new MovementCommand(direction, nIterations);
                //this.movementQueue.Enqueue(movementCommand);
                AddNewMovementInstruction(movementCommand);

                // we actually grab from the offset, but it is circular, so we need to mod it
                nIndex = (nIndex + 2) % (MAX_COMMAND_LIST_ENTRIES * 2);
            }
        }
Beispiel #3
0
 public MovementCommand(MovementCommandDirection direction, int iterations)
 {
     Iterations = iterations;
     Direction  = direction;
 }