/// <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); } }
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)); } }
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("_", " ")); } }