public override void Read(IffFile iff, Stream stream)
{
using (var io = IoBuffer.FromStream(stream, ByteOrder.LITTLE_ENDIAN))
{
InteractionByIndex.Clear();
Interactions = new TTABInteraction[io.ReadUInt16()];
if (Interactions.Length == 0) return; //no interactions, don't bother reading remainder.
var version = io.ReadUInt16();
IOProxy iop;
if (version != 9 && version != 10) iop = new TTABNormal(io);
else
{
var compressionCode = io.ReadByte();
if (compressionCode != 1) throw new Exception("hey what!!");
iop = new TTABFieldEncode(io); //haven't guaranteed that this works, since none of the objects in the test lot use it.
}
for (int i = 0; i < Interactions.Length; i++)
{
var result = new TTABInteraction();
result.ActionFunction = iop.ReadUInt16();
result.TestFunction = iop.ReadUInt16();
result.MotiveEntries = new TTABMotiveEntry[iop.ReadUInt32()];
result.Flags = (TTABFlags)iop.ReadUInt32();
result.TTAIndex = iop.ReadUInt32();
if (version > 6) result.AttenuationCode = iop.ReadUInt32();
result.AttenuationValue = iop.ReadFloat();
result.AutonomyThreshold = iop.ReadUInt32();
result.JoiningIndex = iop.ReadInt32();
for (int j = 0; j < result.MotiveEntries.Length; j++)
{
var motive = new TTABMotiveEntry();
if (version > 6) motive.EffectRangeMinimum = iop.ReadInt16();
motive.EffectRangeMaximum = iop.ReadInt16();
if (version > 6) motive.PersonalityModifier = iop.ReadUInt16();
result.MotiveEntries[j] = motive;
}
if (version > 9)
{
result.Flags2 = (TSOFlags)iop.ReadUInt32();
}
Interactions[i] = result;
InteractionByIndex.Add(result.TTAIndex, result);
}
}
}