예제 #1
0
        private Bitmap CreateMineralsToNormalizedBitmap(MineralLayer layer)
        {
            var bitmap = _zone.CreatePassableBitmap(_passableColor);

            foreach (var node in layer.Nodes)
            {
                var maxAmount = node.GetMaxAmount();

                for (int y = node.Area.Y1; y <= node.Area.Y2; y++)
                {
                    for (int x = node.Area.X1; x <= node.Area.X2; x++)
                    {
                        var n = (double)node.GetValue(x, y) / maxAmount;
                        if (n > 0.0)
                        {
                            var c = (int)(n * 255);
                            bitmap.SetPixel(x, y, Color.FromArgb(c, 0, 0));
                        }
                    }
                }
            }

            return(bitmap.WithGraphics(g =>
            {
                var infoString = $"{layer.Type}";
                g.DrawString(infoString, new Font("Tahoma", 10), Brushes.White, 10, 10);
            }));
        }
예제 #2
0
        public List <ItemInfo> ExtractWithinRange(MineralLayer layer, Point location, int range, uint amount)
        {
            var nodes = layer.GetNodesWithinRange(location, range).OrderBy(n => n.Area.SqrDistance(location));

            var result = new List <ItemInfo>();

            foreach (var node in nodes)
            {
                var needed = amount - result.Sum(r => r.Quantity);
                if (needed <= 0)
                {
                    break;
                }

                var nearestNode = node.GetNearestMineralPosition(location);
                if (nearestNode.Distance(location) > range)
                {
                    continue;
                }

                var e = new MineralExtractor(nearestNode, (uint)needed, _materialHelper);
                layer.AcceptVisitor(e);
                result.AddRange(e.Items);
            }

            return(result);
        }
        private MineralNode CreateMineralNode(MineralLayer layer, Dictionary <Point, double> tiles)
        {
            int minx = int.MaxValue, miny = int.MaxValue, maxx = 0, maxy = 0;

            var sum = 0.0;

            foreach (var t in tiles)
            {
                var p = t.Key;

                minx = Math.Min(p.X, minx);
                miny = Math.Min(p.Y, miny);
                maxx = Math.Max(p.X, maxx);
                maxy = Math.Max(p.Y, maxy);

                sum += t.Value;
            }

            var area = new Area(minx, miny, maxx, maxy);
            var node = layer.CreateNode(area);

            foreach (var t in tiles)
            {
                var u = (t.Value / sum) * TotalAmount;
                u *= FastRandom.NextFloat(0.9f, 1.1f);
                node.SetValue(t.Key, (uint)u);
            }

            return(node);
        }
        private Position FindStartPosition(MineralLayer layer)
        {
            var finder = new RandomPassablePositionFinder(_zone);

            while (true)
            {
                if (!finder.Find(out Position startPosition))
                {
                    continue;
                }

                if (!IsValid(startPosition))
                {
                    continue;
                }

                var n = layer.GetNearestNode(startPosition);
                if (n == null)
                {
                    return(startPosition);
                }

                var d = n.Area.Distance(startPosition);
                if (d < Radius * 2)
                {
                    // ha tul kozel van akkor keresunk ujat
                    continue;
                }

                return(startPosition);
            }
        }
        public MineralNode Generate(MineralLayer layer)
        {
            var startPosition   = FindStartPosition(layer);
            var noise           = GenerateNoise(startPosition);
            var normalizedNoise = NormalizeNoise(noise);
            var node            = CreateMineralNode(layer, normalizedNoise);

            return(node);
        }
예제 #6
0
        public List <ItemInfo> Extract(MineralLayer layer, Point location, uint amount)
        {
            if (!layer.HasMineral(location))
            {
                return(new List <ItemInfo>());
            }

            var extractor = new MineralExtractor(location, amount, _materialHelper);

            layer.AcceptVisitor(extractor);
            return(new List <ItemInfo>(extractor.Items));
        }
        public override void VisitMineralLayer(MineralLayer layer)
        {
            var node = _nodeGenerator.Generate(layer);

            if (node == null)
            {
                return;
            }

            layer.NodeRepository.Insert(node);
            layer.AddNode(node);
            layer.WriteLog($"Node generated. X = {node.Area.X1} Y = {node.Area.Y1}");
        }
예제 #8
0
 private MineralScanResultBuilder(MineralLayer mineralLayer)
 {
     _mineralLayer = mineralLayer;
 }
 public virtual void VisitMineralLayer(MineralLayer layer)
 {
     VisitLayer(layer);
 }