Пример #1
0
        internal static PolygonTrigger Parse(BinaryReader reader, ushort version)
        {
            var result = new PolygonTrigger
            {
                Name = reader.ReadUInt16PrefixedAsciiString()
            };

            if (version >= 4)
            {
                result.LayerName = reader.ReadUInt16PrefixedAsciiString();
            }

            result.UniqueId = reader.ReadUInt32();

            result.TriggerType = reader.ReadUInt16AsEnum <PolygonTriggerType>();

            result.RiverStartControlPoint = reader.ReadUInt32();

            if (version >= 5)
            {
                result.RiverTexture     = reader.ReadUInt16PrefixedAsciiString();
                result.NoiseTexture     = reader.ReadUInt16PrefixedAsciiString();
                result.AlphaEdgeTexture = reader.ReadUInt16PrefixedAsciiString();
                result.SparkleTexture   = reader.ReadUInt16PrefixedAsciiString();
                result.BumpMapTexture   = reader.ReadUInt16PrefixedAsciiString();
                result.SkyTexture       = reader.ReadUInt16PrefixedAsciiString();

                result.UseAdditiveBlending = reader.ReadBooleanChecked();

                result.RiverColor = reader.ReadColorRgb();

                result.Unknown = reader.ReadByte(); // 0
                if (result.Unknown != 0)
                {
                    throw new InvalidDataException();
                }

                result.UvScrollSpeed = reader.ReadVector2();

                result.RiverAlpha = reader.ReadSingle();
            }

            var numPoints = reader.ReadUInt32();

            result.Points = new MapVector3i[numPoints];

            for (var i = 0; i < numPoints; i++)
            {
                result.Points[i] = MapVector3i.Parse(reader);
            }

            return(result);
        }
Пример #2
0
        internal void Load(SaveFileReader reader)
        {
            reader.ReadVersion(1);

            var numPoints = reader.ReadUInt32();

            if (numPoints != Points.Length)
            {
                throw new InvalidDataException();
            }

            for (var i = 0; i < numPoints; i++)
            {
                Points[i] = MapVector3i.Parse(reader.Inner);
            }

            var topLeft     = reader.ReadPoint2D();
            var bottomRight = reader.ReadPoint2D();

            Bounds = Rectangle.FromCorners(topLeft, bottomRight);

            // The following value is what you get if you do this calculation:
            // width = (bottomRight.X - topLeft.X) * 0.5
            // height = (bottomRight.Y + topLeft.Y) * 0.5
            // value = sqrt(width * width + height * height)
            //
            // This looks like it's supposed to be a radius for this polygon trigger,
            // presumably used for quick distance tests prior to testing if
            // a point is inside the actual polygon.
            //
            // But there's a mistake... the height should instead be:
            // height = (bottomRight.Y - topLeft.Y) * 0.5
            //
            // As it is, this "radius" is significantly larger than it should be.
            var _ = reader.ReadSingle();

            Radius = MathF.Sqrt(Bounds.Width * Bounds.Width + Bounds.Height * Bounds.Height);

            var unknown = reader.ReadBoolean();

            if (unknown)
            {
                throw new InvalidDataException();
            }
        }
Пример #3
0
        internal static PolygonTrigger Parse(BinaryReader reader, ushort version)
        {
            var name = reader.ReadUInt16PrefixedAsciiString();

            string layerName = null;

            if (version == 4)
            {
                layerName = reader.ReadUInt16PrefixedAsciiString();
            }

            var uniqueId = reader.ReadUInt32();

            var triggerType = reader.ReadUInt16AsEnum <PolygonTriggerType>();

            var riverStartControlPoint = reader.ReadUInt32();

            var numPoints = reader.ReadUInt32();
            var points    = new MapVector3i[numPoints];

            if (riverStartControlPoint > numPoints - 1)
            {
                throw new InvalidDataException();
            }

            for (var i = 0; i < numPoints; i++)
            {
                points[i] = MapVector3i.Parse(reader);
            }

            return(new PolygonTrigger
            {
                Name = name,
                LayerName = layerName,
                UniqueId = uniqueId,
                TriggerType = triggerType,
                RiverStartControlPoint = riverStartControlPoint,
                Points = points
            });
        }