Ejemplo n.º 1
0
 /// <summary>
 /// Reads a TTAB chunk from a stream.
 /// </summary>
 /// <param name="iff">An Iff instance.</param>
 /// <param name="stream">A Stream object holding a TTAB chunk.</param>
 public override void Read(Iff iff, Stream stream)
 {
     using (var io = IoBuffer.FromStream(stream, ByteOrder.LITTLE_ENDIAN))
     {
         Interactions = new TTABInteraction[io.ReadUInt16()];
         if (Interactions.Length == 0) return; //no interactions, don't bother reading remainder.
         InteractionByIndex = new Dictionary<uint, TTABInteraction>();
         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 = 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.Unknown = iop.ReadUInt32();
             Interactions[i] = result;
             InteractionByIndex.Add(result.TTAIndex, result);
         }
     }
 }
Ejemplo n.º 2
0
 public override void Read(Iff iff, Stream stream)
 {
     using (var io = IoBuffer.FromStream(stream, ByteOrder.LITTLE_ENDIAN))
     {
         Interactions = new TTABInteraction[io.ReadUInt16()];
         if (Interactions.Length == 0)
         {
             return;                           //no interactions, don't bother reading remainder.
         }
         InteractionByIndex = new Dictionary <uint, TTABInteraction>();
         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          = 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.Unknown = iop.ReadUInt32();
             }
             Interactions[i] = result;
             InteractionByIndex.Add(result.TTAIndex, result);
         }
     }
 }