Example #1
0
        public static void WriteCompressedWaypoints(this LittleEndianWriter writer, GridPosition[] data)
        {
            int size = data.Length;

            if (size < 1)
            {
                throw new IOException("Need at least 1 waypoint!");
            }
            byte[] flagsBuffer;
            if (size > 1)
            {
                flagsBuffer = new byte[(size - 2) / 4 + 1u];
            }
            else
            {
                flagsBuffer = new byte[0];
            }
            var flags = new BitArray(flagsBuffer);

            for (int i = 1, flag = 0; i < size; i++)
            {
                int relativeX = data[i].X - data[i - 1].X;
                flags[flag] = (relativeX <= SByte.MaxValue && relativeX >= SByte.MinValue);
                flag++;

                int realtiveZ = data[i].Y - data[i - 1].Y;
                flags[flag] = (realtiveZ <= SByte.MaxValue && realtiveZ >= SByte.MinValue);
                flag++;
            }
            flags.CopyTo(flagsBuffer, 0);
            writer.WriteBytes(flagsBuffer);
            writer.WriteShort(data[0].X);
            writer.WriteShort(data[0].Y);
            for (int i = 1, flag = 0; i < size; i++)
            {
                if (flags[flag])
                {
                    writer.WriteSByte((SByte)(data[i].X - data[i - 1].X));
                }
                else
                {
                    writer.WriteShort(data[i].X);
                }
                flag++;
                if (flags[flag])
                {
                    writer.WriteSByte((SByte)(data[i].Y - data[i - 1].Y));
                }
                else
                {
                    writer.WriteShort(data[i].Y);
                }
                flag++;
            }
        }
Example #2
0
 public void Serialize(LittleEndianWriter writer)
 {
     writer.WriteUInt(TargetNetId);
     writer.WriteSByte((sbyte)(ExtraTime + 128));
     writer.WriteUInt(MissileNextId);
     writer.WriteByte((byte)AttackSlot); // attackSlot
     TargetPosition.Serialize(writer);
 }