Beispiel #1
0
        internal Image DrawDPMap(int size)
        {
            Bitmap worldImage = new Bitmap(WORLD_SIZE * size, WORLD_SIZE * size);

            using (Graphics g = Graphics.FromImage(worldImage))
            {
                //Draw background
                for (int x = 0; x < WORLD_SIZE / RATIO; x++)
                {
                    for (int y = 0; y < WORLD_SIZE / RATIO; y++)
                    {
                        WeatherPoint point = Instance.atmosphere[x * MaxZ + y * WORLD_SIZE / RATIO * MaxZ];
                        double       v     = 30 * point.dP;
                        if (v > 0)
                        {
                            g.FillRectangle(new SolidBrush(Color.FromArgb((int)v.Cut(0, 255), 0, 0, 255)), x * size * RATIO, y * size * RATIO, size * RATIO, size * RATIO);
                        }
                        else if (v == 0)
                        {
                        }
                        else
                        {
                            v = Math.Abs(v);
                            g.FillRectangle(new SolidBrush(Color.FromArgb((int)v.Cut(0, 255), 0, 255, 0)), x * size * RATIO, y * size * RATIO, size * RATIO, size * RATIO);
                        }
                    }
                }
            }
            return(worldImage);
        }
 public WeatherPointDto Map(WeatherPoint obj)
 {
     return(new WeatherPointDto
     {
         DateTime = DateUtils.FromUnixSeconds(obj.Dt),
         Temperature = obj.Main.Temp.KtoC(),
         Description = obj.Weather.Single().Description,
         Icon = obj.Weather.Single().Icon
     });
 }
Beispiel #3
0
        private Bitmap DrawMap(int X, int Y, int Width, int Height, int size = 20, bool showTime = true, bool inGame = false)
        {
            //Trace.TraceInformation($"WorldRenderer::DrawMap({X}, {Y}, {Width}, {Height}, {size})");
            DateTime time       = DateTime.Now;
            Bitmap   worldImage = DrawBackground(X, Y, Math.Min(Instance.costMap.GetUpperBound(0), X + Width), Math.Min(Instance.costMap.GetUpperBound(0), Y + Height), size);

            //Trace.TraceInformation($"Rendering background in {(DateTime.Now - time).TotalMilliseconds}!");
            using (Graphics g = Graphics.FromImage(worldImage))
            {
                DateTime point = DateTime.Now;
                // Hiding water until better way to represent it has been found
                // Draw water ways
                //for (int y = Y; y < WORLD_SIZE; y++)
                //{
                //    for (int x = X; x < WORLD_SIZE; x++)
                //    {
                //        WorldRockMaterial rock = Instance.worldMap[x, y].rock;
                //        if (rock.WaterAmount > 60)
                //        {
                //            double riverSize = (rock.WaterAmount - 120) / 120 + 0.1;
                //            riverSize = riverSize.Cut(0, 0.8);
                //            double offset = 0.5 - riverSize / 2;
                //            if ((rock.xDirection ?? 0 ) != 0)
                //            {
                //                g.FillRectangle(Brushes.Blue, (int)((x - X + 0.5) * size), (int)((y - Y + offset) * size), size * (rock.xDirection ?? 0), (int)(riverSize * size));
                //            }
                //            else
                //            {
                //                g.FillRectangle(Brushes.Blue, (int)((x - X + offset) * size), (int)((y - Y + 0.5) * size), (int)(riverSize * size), (rock.yDirection ?? 0) * size);
                //            }
                //        }
                //    }
                //}
                //Trace.TraceInformation($"Rendering water in {(DateTime.Now - point).TotalMilliseconds}!");
                //point = DateTime.Now;

                //Draw features
                int features = 0;
                foreach (var feature in Instance.features.OrderBy(f => f.level))
                {
                    if (feature.MinimumSize <= size && feature.position.X.Between(X, X + Width) && feature.position.Y.Between(Y, Y + Height))
                    {
                        features++;
                        if (feature.alignment == RenderingAlignment.Left)
                        {
                            g.DrawImage(feature.image, (feature.position.X - X) * size, (feature.position.Y - Y) * size, size, size);
                        }
                        else if (feature.alignment == RenderingAlignment.Center)
                        {
                            int x = ((feature.position.X - X) - feature.size.X / 2) * size;
                            int y = ((feature.position.Y - Y) - feature.size.Y / 2) * size;
                            g.DrawImage(feature.image, x, y, size * feature.size.X, size * feature.size.Y);
                        }
                    }
                }
                //Trace.TraceInformation($"Rendering {features} features in {(DateTime.Now - point).TotalMilliseconds}!");
                point = DateTime.Now;
                //Draw actors
                foreach (var actor in Instance.actors)
                {
                    g.DrawImage(actor.troop.Image, (actor.WorldPosition.X - X) * size, (actor.WorldPosition.Y - Y) * size, size, size);
                }
                //Trace.TraceInformation($"Rendering {Instance.actors.Count} actors in {(DateTime.Now - point).TotalMilliseconds}!");

                //Draw overlay objects
                foreach (var obj in overlayObjects)
                {
                    if (obj is OverlayRectangle)
                    {
                        OverlayRectangle rect = obj as OverlayRectangle;
                        if (rect.filled)
                        {
                            g.FillRectangle(new SolidBrush(rect.fillColor), rect.x - X * size, rect.y - Y * size, rect.width, rect.height);
                        }
                        g.DrawRectangle(new Pen(rect.borderColor), rect.x - X * size, rect.y - Y * size, rect.width, rect.height);
                    }
                    else if (obj is OverlayText)
                    {
                        OverlayText txt = obj as OverlayText;
                        g.DrawString(txt.text, SystemFonts.DefaultFont, new SolidBrush(txt.color),
                                     new PointF(txt.x / 20 * size - X * size, txt.y / 20 * size - Y * size));
                    }
                    else if (obj is OverlayLine line)
                    {
                        g.DrawLine(new Pen(line.color), line.start.Div(20).Mult(size).Sub(X * size, Y * size).Add(10, 10), line.end.Div(20).Mult(size).Sub(X * size, Y * size).Add(10, 10));
                    }
                }
                //g.FillRectangle(Brushes.Blue, 0, 0, WORLD_SIZE * size, WORLD_SIZE * size);
                //Update Overlay
                overlayObjects = overlayObjects.Where(o => !o.once).ToList();
                //Draw weather and daytime
                point = DateTime.Now;
                int ratio = RATIO;
                for (int x = X / ratio; x < Math.Min(X / ratio + Width / ratio, WORLD_SIZE / ratio); x++)
                {
                    for (int y = Y / ratio; y < Math.Min(Y / ratio + Height / ratio, WORLD_SIZE / ratio); y++)
                    {
                        WeatherPoint weatherPoint = GetWeatherPoint(ratio, x, y);
                        float        cloudCover   = weatherPoint.CloudCover * 2;
                        if (x > 0 && y > 0)
                        {
                            cloudCover += GetWeatherPoint(ratio, x - 1, y).CloudCover + GetWeatherPoint(ratio, x, y - 1).CloudCover;
                            cloudCover /= 4;
                        }
                        if (x < WORLD_SIZE / ratio - 1 && y < WORLD_SIZE / ratio - 1)
                        {
                            cloudCover += GetWeatherPoint(ratio, x + 1, y).CloudCover + GetWeatherPoint(ratio, x, y + 1).CloudCover;
                            cloudCover /= 4;
                        }
                        if (inGame)
                        {
                            if (cloudCover * 6 < 190)
                            {
                                g.FillRectangle(new SolidBrush(Color.FromArgb((int)(cloudCover * 6).Cut(0, 255), 255, 255, 255)), (x - X) * size * ratio, (y - Y) * size * ratio, size * ratio, size * ratio);
                            }
                            else if (cloudCover > 10)
                            {
                                const int V = 180;
                                g.FillRectangle(new SolidBrush(Color.FromArgb(200, (int)(V - cloudCover * 2).Cut(0, 255), (int)(V - cloudCover * 2).Cut(0, 255), (int)(V - cloudCover * 2).Cut(0, 255))), (x - X) * size * ratio, (y - Y) * size * ratio, size * ratio, size * ratio);
                            }
                            if (showTime)
                            {
                                g.FillRectangle(new SolidBrush(Color.FromArgb(255 - (int)(weatherPoint.BaseSunlight / 100 * 255), 0, 0, 0)), (x - X) * size * ratio, (y - Y) * size * ratio, size * ratio, size * ratio);
                            }
                        }
                        else
                        {
                            if (cloudCover * 6 < 190)
                            {
                                g.FillRectangle(new SolidBrush(Color.FromArgb((int)(cloudCover * 3).Cut(0, 255), 255, 255, 255)), (x - X) * size * ratio, (y - Y) * size * ratio, size * ratio, size * ratio);
                            }
                            else if (cloudCover > 10)
                            {
                                const int V = 180;
                                g.FillRectangle(new SolidBrush(Color.FromArgb(100, (int)(V - cloudCover).Cut(0, 255), (int)(V - cloudCover).Cut(0, 255), (int)(V - cloudCover).Cut(0, 255))), (x - X) * size * ratio, (y - Y) * size * ratio, size * ratio, size * ratio);
                            }
                            if (showTime)
                            {
                                g.FillRectangle(new SolidBrush(Color.FromArgb(128 - (int)(weatherPoint.BaseSunlight / 100 * 128), 0, 0, 0)), (x - X) * size * ratio, (y - Y) * size * ratio, size * ratio, size * ratio);
                            }
                        }
                    }
                }
                //Trace.TraceInformation($"Rendering weather in {(DateTime.Now - point).TotalMilliseconds}!");
            }
            //Trace.TraceInformation($"Finished in {(DateTime.Now - time).TotalMilliseconds}");
            return(worldImage);
        }