예제 #1
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);
            }
        }
예제 #2
0
        public MoonPhases GetMoonPhasesByTimeOfDay(TimeOfDay timeOfDay, MoonsAndSun moonsAndSun)
        {
            // the value stored is an offset and needs to be adjusted to a zero based index
            int getAdjustedValue(int nValue)
            {
                return(nValue - N_OFFSET_ADJUST);
            }

            switch (moonsAndSun)
            {
            case MoonsAndSun.Felucca:
                return((MoonPhases)getAdjustedValue(_moonPhaseChunk.GetAsByteList()[(timeOfDay.Day - 1) * 2]));

            case MoonsAndSun.Trammel:
                return((MoonPhases)getAdjustedValue(_moonPhaseChunk.GetAsByteList()[(timeOfDay.Day - 1) * 2 + 1]));

            case MoonsAndSun.Sun:
                return(MoonPhases.NoMoon);

            default:
                throw new Ultima5ReduxException("We have asked for a moon phase but did not met the criteria. " + timeOfDay);
            }
        }
예제 #3
0
        public void Load(MapCharacterAnimationStatesFiles mapCharacterAnimationStatesType, bool bLoadFromDisk)
        {
            MapCharacterAnimationStatesType = mapCharacterAnimationStatesType;

            if (!bLoadFromDisk)
            {
                return;
            }

            List <byte> characterStateBytes = _animationStatesDataChunk.GetAsByteList();

            for (int i = 0; i < MAX_CHARACTER_STATES; i++)
            {
                _characterStates.Add(new MapCharacterAnimationState(_tileReferences, characterStateBytes.GetRange(i * MapCharacterAnimationState.NBYTES, MapCharacterAnimationState.NBYTES).ToArray()));
            }
        }
예제 #4
0
        /// <summary>
        /// Constructor. Built with DataChunk references from save file
        /// </summary>
        /// <param name="xPos"></param>
        /// <param name="yPos"></param>
        /// <param name="buriedFlags"></param>
        /// <param name="zPos"></param>
        public Moongates(DataChunk xPos, DataChunk yPos, DataChunk buriedFlags, DataChunk zPos)
        {
            // save datachunks for saving later
            this.XPos        = xPos;
            this.YPos        = yPos;
            this.BuriedFlags = buriedFlags;
            this.ZPos        = zPos;
            List <byte> xPositions = xPos.GetAsByteList();
            List <byte> yPositions = yPos.GetAsByteList();
            List <byte> zPositions = zPos.GetAsByteList();
            List <byte> buried     = buriedFlags.GetAsByteList();

            Debug.Assert(xPositions.Count == TOTAL_MOONSTONES && yPositions.Count == TOTAL_MOONSTONES && zPositions.Count == TOTAL_MOONSTONES && buried.Count == TOTAL_MOONSTONES);

            for (int i = 0; i < TOTAL_MOONSTONES; i++)
            {
                Point3D moongatePos = new Point3D(xPositions[i], yPositions[i], zPositions[i]);
                _moongatePositions.Add(moongatePos);
                _moonstonesBuried.Add(buried[i] == 0);
                _moongateBuriedAtPositionDictionary.Add(_moongatePositions[i], _moonstonesBuried[i]);
            }
        }