Represents an interaction in a TTAB chunk.
        public void DeleteInteraction(int index)
        {
            var action = Interactions[index];
            var newInt = new TTABInteraction[Interactions.Length - 1];

            if (index == -1)
            {
                index = 0;
            }
            Array.Copy(Interactions, newInt, index); //copy before strings
            Array.Copy(Interactions, index + 1, newInt, index, (Interactions.Length - (index + 1)));
            Interactions = newInt;

            if (InteractionByIndex.ContainsKey(action.TTAIndex))
            {
                InteractionByIndex.Remove(action.TTAIndex);
            }
        }
        public void InsertInteraction(TTABInteraction action, int index)
        {
            var newInt = new TTABInteraction[Interactions.Length + 1];

            if (index == -1)
            {
                index = 0;
            }
            Array.Copy(Interactions, newInt, index); //copy before strings
            newInt[index] = action;
            Array.Copy(Interactions, index, newInt, index + 1, (Interactions.Length - index));
            Interactions = newInt;

            if (!InteractionByIndex.ContainsKey(action.TTAIndex))
            {
                InteractionByIndex.Add(action.TTAIndex, action);
            }
        }
 /// <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(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);
         }
     }
 }
Exemple #4
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(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 <= 3)
         {
             // DO NOT LOAD THIS TTAB TYPE
             Interactions = new TTABInteraction[0];
             return;
         }
         if (version < 9 || (version > 10 && !iff.TSBO))
         {
             iop = new TTABNormal(io);
         }
         else
         {
             var compressionCode = io.ReadByte();
             if (compressionCode != 1)
             {
                 iop = new TTABNormal(io);
             }
             else
             {
                 iop = new IffFieldEncode(io);
             }
         }
         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();
                 motive.MotiveIndex = j;
                 if (version > 6)
                 {
                     motive.EffectRangeMinimum = iop.ReadInt16();
                 }
                 motive.EffectRangeDelta = iop.ReadInt16();
                 if (version > 6)
                 {
                     motive.PersonalityModifier = iop.ReadUInt16();
                 }
                 result.MotiveEntries[j] = motive;
             }
             if (version > 9 && !iff.TSBO)
             {
                 result.Flags2 = (TSOFlags)iop.ReadUInt32();
             }
             Interactions[i] = result;
             InteractionByIndex.Add(result.TTAIndex, result);
         }
     }
     InitAutoInteractions();
 }
        private void AddBtn_Click(object sender, EventArgs e)
        {
            var sel = Selected;
            int TTAIndex = 0;
            Content.Content.Get().Changes.BlockingResMod(new ResAction(() =>
            {
                TTAIndex = Strings.Length;
                Strings.InsertString(Strings.Length, new STRItem { Value = "New Interaction" });
            }, Strings));

            Content.Content.Get().Changes.BlockingResMod(new ResAction(() =>
            {
                var action = new TTABInteraction() { TTAIndex = (uint)TTAIndex, MotiveEntries = new TTABMotiveEntry[MotiveNames.Length] };
                ActiveTTAB.InsertInteraction(action,
                    (sel == null)?ActiveTTAB.Interactions.Length:(Array.IndexOf(ActiveTTAB.Interactions, sel)+1));
            }, ActiveTTAB));

            UpdateListing();
        }
        public void UpdateSelection(int sel)
        {
            InternalChange = true;
            SelectedIndex = sel;
            bool enabled = true;
            try
            {
                Selected = ActiveTTAB.InteractionByIndex[(uint)sel];
            }
            catch (Exception) {

                Selected = new TTABInteraction() { TTAIndex = 0, MotiveEntries = new TTABMotiveEntry[MotiveNames.Length] };
                enabled = false;
                //disable everything and set Selected to a dummy.
            }

            AllowBox.Enabled = enabled;
            ActionButton.Enabled = enabled;
            CheckButton.Enabled = enabled;
            FlagsBox.Enabled = enabled;
            MetaBox.Enabled = enabled;
            MotiveBox.Enabled = enabled;

            InteractionPathName.Text = GetTTA(Selected.TTAIndex);
            AutonomyInput.Value = Selected.AutonomyThreshold;
            AttenuationCombo.Text = Selected.AttenuationValue.ToString();
            JoinInput.Value = Math.Max(-1, Selected.JoiningIndex);

            UpdateMotiveList();

            foreach (var checkAtt in FlagNames)
            {
                var check = checkAtt.Key;
                var att = checkAtt.Value;
                var property = Selected.GetType().GetProperty(att);
                check.Checked = (bool)property.GetValue(Selected, new object[0]);
            }

            if (InteractionList.Items.Count > 0)
            {
                var int1 = PieToInteraction.FirstOrDefault(x => x.Value == sel);
                PieView.SelectedNode = int1.Key;
                var int2 = -1;
                TTAToListIndex.TryGetValue(sel, out int2);
                if (int2 != -1 && !InteractionList.SelectedIndices.Contains(int2))
                {
                    InteractionList.SelectedIndices.Clear();
                    InteractionList.SelectedIndices.Add(int2);
                }
            }
            InternalChange = false;
            var oldInd = MotiveList.SelectedIndex;
            MotiveList.SelectedIndex = -1;
            MotiveList.SelectedIndex = oldInd;
        }
Exemple #7
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(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);
         }
     }
 }
Exemple #8
0
        public void InsertInteraction(TTABInteraction action, int index)
        {
            var newInt = new TTABInteraction[Interactions.Length + 1];
            if (index == -1) index = 0;
            Array.Copy(Interactions, newInt, index); //copy before strings
            newInt[index] = action;
            Array.Copy(Interactions, index, newInt, index + 1, (Interactions.Length - index));
            Interactions = newInt;

            if (!InteractionByIndex.ContainsKey(action.TTAIndex)) InteractionByIndex.Add(action.TTAIndex, action);
        }
Exemple #9
0
        public void DeleteInteraction(int index)
        {
            var action = Interactions[index];
            var newInt = new TTABInteraction[Interactions.Length - 1];
            if (index == -1) index = 0;
            Array.Copy(Interactions, newInt, index); //copy before strings
            Array.Copy(Interactions, index + 1, newInt, index, (Interactions.Length - (index + 1)));
            Interactions = newInt;

            if (InteractionByIndex.ContainsKey(action.TTAIndex)) InteractionByIndex.Remove(action.TTAIndex);
        }