コード例 #1
0
        public void ShouldGenerate1DVoroniwithTwoPoints()
        {
            var points = new[] {
                new OffsetCoordinate(-2, 0),
                new OffsetCoordinate(3, 0)
            }
            .Select(x => x.ToAxial()).ToList();

            var voroni = VoroniTilingMapper.SetupVoroniMap(
                points,
                new OffsetCoordinate(-2, 0),
                new OffsetCoordinate(4, 1));

            var expectedResult = new int[][]
            {
                new int[] { 0, 0, 0, 1, 1, 1 }
            };

            Assert.AreEqual(expectedResult.Length, voroni.Length);
            Assert.AreEqual(expectedResult[0].Length, voroni[0].Length);


            for (var row = 0; row < voroni.Length; row++)
            {
                for (var col = 0; col < voroni[row].Length; col++)
                {
                    Assert.AreEqual(
                        expectedResult[row][col],
                        voroni[row][col],
                        $"Expected result mismatch at row: {row} col: {col}");
                }
            }
        }
コード例 #2
0
        public void ShouldGenerateFullMapWithSinglePoint()
        {
            var points = new[] { new AxialCoordinate(0, 0) };

            var voroni = VoroniTilingMapper.SetupVoroniMap(points, new OffsetCoordinate(-1, -1), new OffsetCoordinate(1, 1));

            Assert.AreEqual(2, voroni.Length);
            Assert.AreEqual(2, voroni[0].Length);

            foreach (var row in voroni)
            {
                foreach (var cell in row)
                {
                    Assert.AreEqual(0, cell);
                }
            }
        }
コード例 #3
0
        public static void CalculateServiceRanges(HexTileMapManager manager)
        {
            //foreach (var market in allMarkets)
            //{
            //    var marketMember = market.GetComponentInParent<HexMember>();

            //    var myHexPosition = marketMember.PositionInTileMap;
            //    var effectiveRange = HexTileMapManager
            //        .GetPositionsWithinJumpDistance(myHexPosition, 2);
            //    market.myServiceRange = effectiveRange.ToArray();
            //}

            var allMarkets = manager.GetAllOfType <MarketBehavior>().ToList();

            Debug.Log($"Initializing {allMarkets.Count} markets");
            var marketPositions = allMarkets
                                  .Select(x => x.GetComponentInParent <HexMember>())
                                  .Select(x => x.PositionInTileMap)
                                  .ToList();

            var minimum      = manager.tileMapMin;
            var minimumAxial = minimum.ToAxial();
            var maximum      = manager.tileMapMax;

            var voroniData = VoroniTilingMapper.SetupVoroniMap(marketPositions, minimum, maximum);

            for (var row = 0; row < voroniData.Length; row++)
            {
                for (var col = 0; col < voroniData[row].Length; col++)
                {
                    var index      = voroniData[row][col];
                    var coordinate = new OffsetCoordinate(col, row).ToAxial() + minimumAxial;
                    allMarkets[index].myServiceRange.Add(coordinate.ToOffset());
                }
            }
        }