Example #1
0
        /// <summary>
        /// Copies the keys of a pack file index into an array of Microsoft.Xna.Framework.Point structures.
        /// </summary>
        /// <param name="index">The pack file index.</param>
        /// <returns>See summary.</returns>
        private static Point3D[] CopyPackFileIndexKeys(PackFileIndex index)
        {
            string[] entries = new string[index.Entries.Count];
            index.Entries.Keys.CopyTo(entries, 0);

            Point3D[] points = new Point3D[entries.Length];
            for (int i = 0; i < points.Length; i++)
            {
                points[i] = MathExtensions.StringToPoint(entries[i]);
            }

            return points;
        }
Example #2
0
        /// <summary>
        /// Gets the highest terrain patch ID that will be needed to draw the map.
        /// </summary>
        /// <param name="terrainPatches">The terrain patch collection to determine the IDs with.</param>
        /// <returns>See summary.</returns>
        private static Point3D GetHighestTileID(Collection<TerrainPatch> terrainPatches)
        {
            PackFileIndex dict = new PackFileIndex();

            for (int i = 0; i < terrainPatches.Count; i++)
            {
                dict.Entries.Add(terrainPatches[i].PatchId.ToString(), PackFileEntry.Null);
            }

            return WorldMap.GetHighestTileID(dict);
        }
Example #3
0
        /// <summary>
        /// Gets the highest terrain patch ID that will be needed to draw the map.
        /// </summary>
        /// <param name="index">The pack file patch index to determine the IDs with.</param>
        /// <returns>See summary.</returns>
        private static Point3D GetHighestTileID(PackFileIndex index)
        {
            Point3D highestPatchID = Point3D.Zero;

            Point3D[] points = WorldMap.CopyPackFileIndexKeys(index);

            for (int i = 0; i < points.Length; i++)
            {
                if (points[i].X > highestPatchID.X)
                {
                    highestPatchID.X = points[i].X;
                }

                if (points[i].Y > highestPatchID.Y)
                {
                    highestPatchID.Y = points[i].Y;
                }
            }

            return highestPatchID;
        }
Example #4
0
        /// <summary>
        /// Draws the collection of terrain patches to a bitmap and returns the result.
        /// </summary>
        /// <param name="terrainPatches">The filenames of the terrain patches to draw on the wold map.</param>
        /// <param name="index">The pack file terrain patch index.</param>
        /// <param name="textured">Whether the map should be drawn textured.</param>
        /// <param name="season">The season to draw the map in.</param>
        /// <param name="hideBase">
        /// Whether to draw undefined for non-base season
        /// instead of showing the base season terrain.
        /// </param>
        /// <returns>See summary.</returns>
        public static Bitmap DrawMap(StringCollection terrainPatches, PackFileIndex index, bool textured, Season season, bool hideBase)
        {
            // Determine the lowest and highest patch IDs we'll need the coordinates of, to draw the map
            Point3D lowestPatchID = WorldMap.GetLowestTileID(index);
            Point3D highestPatchID = WorldMap.GetHighestTileID(index);

            // Determine the map size, in pixels
            Size bitmapSize = WorldMap.GetMapPixelSize(lowestPatchID, highestPatchID);

            // Generate the image objects
            Bitmap bmp = new Bitmap(bitmapSize.Width, bitmapSize.Height);
            Graphics g = Graphics.FromImage(bmp);

            WorldMap.Progress = 0;
            WorldMap.Cancel = false;

            // Draw all tiles onto the bitmap
            for (int i = 0; i < terrainPatches.Count && !WorldMap.Cancel; i++)
            {
                // Skip this tile if we're not at ground level
                TerrainPatch patch = TerrainPatch.FromByteArray(File.ReadAllBytes(terrainPatches[i]));
                if (patch.PatchId.Z != 0)
                {
                    continue;
                }

                WorldMap.DrawTerrainPatch(patch, lowestPatchID, bitmapSize, g, textured, season, hideBase);

                WorldMap.Progress = Convert.ToInt32((i + 1f) / terrainPatches.Count) * 100;
            }

            return bmp;
        }