示例#1
0
        /// <summary>
        ///     Saves the current height map to the provided file.
        /// </summary>
        /// <param name="file"></param>
        public static bool Save(string file)
        {
            if (_usePlugin)
            {
                return(_native_SaveCurrentHMap.InvokeBool(file));
            }

            try
            {
                using (FileStream stream = new FileStream(file, FileMode.Create, FileAccess.Write))
                {
                    foreach (var v in _data)
                    {
                        stream.Write(BitConverter.GetBytes(v), 0, 2);
                    }
                }

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
示例#2
0
        /// <summary>
        ///     Set the highest Z point at the provided point.
        /// </summary>
        /// <param name="x">X-coordinate of the point.</param>
        /// <param name="y">Y-coordinate of the point.</param>
        /// <param name="z">Z-coordinate of the hight at the provided point.</param>
        /// <returns>True on success; False otherwise.</returns>
        public static bool SetZ(float x, float y, float z)
        {
            if (_usePlugin)
            {
                return(_nativeSetZ.InvokeBool(x, y, z));
            }

            if (x < -3000.0f || x > 3000.0f || y > 3000.0f || y < -3000.0f)
            {
                return(false);
            }
            if (z < 0 || z > 655.35)
            {
                return(false);
            }

            // get row/col on 6000x6000 grid
            int iGridX = ((int)x) + 3000;
            int iGridY = -(((int)y) - 3000);
            int iDataPos;

            if (_mode == MapAndreasMode.Full)
            {
                iDataPos        = (iGridY * 6000) + iGridX;
                _data[iDataPos] = (ushort)(z * 100.0f + 0.5); // Add 0.5 to round it properly
                return(true);
            }
            if (_mode == MapAndreasMode.Minimal)
            {
                iDataPos        = ((iGridY / 3) * 2000) + iGridX / 3; // skip every 2nd and 3rd line
                _data[iDataPos] = (ushort)(z * 100.0f + 0.5);         // Add 0.5 to round it properly
                return(true);
            }

            return(false);
        }