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 Exception("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);

                // 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 MapCharacterStates(DataChunk charStatesDataChunk, TileReferences tileReferences)
        {
            DataChunk dataChunk = charStatesDataChunk;

            List <UInt16> characterStateBytes = dataChunk.GetChunkAsUINT16List();

            for (int nIndex = 0; nIndex < MAX_CHARACTER_STATES; nIndex++)
            {
                characterStates.Add(new MapCharacterState(tileReferences,
                                                          characterStateBytes.GetRange(nIndex * MapCharacterAnimationState.NBYTES, MapCharacterAnimationState.NBYTES).ToArray(), nIndex));
            }
        }
예제 #3
0
        public void InitializeLocationNames()
        {
            // get the data chunks that have the offsets to the strings in the data.ovl file, representing each location (most)
            DataChunk locationNameOffsetChunk = dataRef.GetDataChunk(DataOvlReference.DataChunkName.LOCATION_NAME_INDEXES);

            // get the offsets
            List <ushort> locationOffsets = locationNameOffsetChunk.GetChunkAsUINT16List();

            locationNames = new List <string>(locationOffsets.Count + 1);

            // I happen to know that the underworld and overworld is [0], so let's add a placeholder
            locationNames.Add("Overworld/Underworld");

            // grab each location string
            // it isn't the most efficient way, but it gets the job done
            foreach (ushort offset in locationOffsets)
            {
                locationNames.Add(dataRef.GetDataChunk(DataChunk.DataFormatType.SimpleString, string.Empty, offset, 20).GetChunkAsString().Replace("_", " "));
            }
        }