예제 #1
0
        public void TestOneDiagonalObject4()
        {
            var expectedMap = @"***." +
                              "****" +
                              "..**" +
                              "..**";

            var map          = CreateMap(4, 4, false, new Point(2, 1));
            var visibleCells = ShadowCasting.For(new Point(3, 0), 4, map).GetVisibleCells().Distinct().ToList();

            AssertMap(4, 4, expectedMap, visibleCells);
        }
예제 #2
0
        public void TestOneCloseObject2()
        {
            var expectedMap = @"****.****" +
                              "*********" +
                              "***...***" +
                              "**.....**" +
                              "*.......*";

            var map          = CreateMap(9, 5, false, new Point(4, 1));
            var visibleCells = ShadowCasting.For(new Point(4, 0), 4, map).GetVisibleCells().Distinct().ToList();

            AssertMap(9, 5, expectedMap, visibleCells);
        }
예제 #3
0
        public void TestCornerObjects4()
        {
            var expectedMap = @".*****" +
                              "******" +
                              "******" +
                              "***..*" +
                              "***..." +
                              "****..";

            var map          = CreateMap(6, 6, false, new Point(2, 3), new Point(3, 2), new Point(2, 2));
            var visibleCells = ShadowCasting.For(new Point(0, 0), 7, map).GetVisibleCells().Distinct().ToList();

            AssertMap(6, 6, expectedMap, visibleCells);
        }
예제 #4
0
        public void TestTwoDiagonalObjects3()
        {
            var expectedMap = @"*****." +
                              "******" +
                              "******" +
                              "*.****" +
                              ".*.***" +
                              "*.****";

            var map          = CreateMap(6, 6, false, new Point(2, 2), new Point(3, 3));
            var visibleCells = ShadowCasting.For(new Point(5, 0), 7, map).GetVisibleCells().Distinct().ToList();

            AssertMap(6, 6, expectedMap, visibleCells);
        }
예제 #5
0
        public void TestOneDistantObject1()
        {
            var expectedMap = @"**************" +
                              "*.************" +
                              "**************" +
                              "******..******" +
                              "********......" +
                              "**********...." +
                              "***********..." +
                              "*************." +
                              "**************";

            var map          = CreateMap(14, 9, false, new Point(4, 2));
            var visibleCells = ShadowCasting.For(new Point(1, 1), 15, map).GetVisibleCells().Distinct().ToList();

            AssertMap(14, 9, expectedMap, visibleCells);
        }
예제 #6
0
        public void TestOneCloseObject4()
        {
            var expectedMap = @"*****" +
                              "****." +
                              "***.." +
                              "**..." +
                              ".*..." +
                              "**..." +
                              "***.." +
                              "****." +
                              "*****";

            var map          = CreateMap(5, 9, false, new Point(1, 4));
            var visibleCells = ShadowCasting.For(new Point(0, 4), 4, map).GetVisibleCells().Distinct().ToList();

            AssertMap(5, 9, expectedMap, visibleCells);
        }
예제 #7
0
        public void TestOneCornerPicker2()
        {
            var expectedMap = @"..........." +
                              "...*****..." +
                              "....***...." +
                              "....*.*...." +
                              "....***...." +
                              "...*****..." +
                              "..*******.." +
                              ".*********.";

            var map = CreateMap(11, 8, false, new Point(4, 3), new Point(6, 3), new Point(0, 1), new Point(1, 1), new Point(2, 1), new Point(3, 1),
                                new Point(4, 1), new Point(5, 1), new Point(6, 1), new Point(7, 1), new Point(8, 1), new Point(9, 1), new Point(10, 1));
            var visibleCells = ShadowCasting.For(new Point(5, 3), 6, map).GetVisibleCells().Distinct().ToList();

            AssertMap(11, 8, expectedMap, visibleCells);
        }
예제 #8
0
        public void TestOneCornerPicker4()
        {
            var expectedMap = @"........" +
                              ".......*" +
                              "......**" +
                              ".*...***" +
                              ".*******" +
                              ".**.****" +
                              ".*******" +
                              ".*...***" +
                              "......**" +
                              ".......*" +
                              "........";

            var map = CreateMap(8, 11, false, new Point(3, 4), new Point(3, 6), new Point(1, 0), new Point(1, 1), new Point(1, 2), new Point(1, 3),
                                new Point(1, 4), new Point(1, 5), new Point(1, 6), new Point(1, 7), new Point(1, 8), new Point(1, 9), new Point(1, 10));
            var visibleCells = ShadowCasting.For(new Point(3, 5), 6, map).GetVisibleCells().Distinct().ToList();

            AssertMap(8, 11, expectedMap, visibleCells);
        }
        public static IFieldOfView GetFieldOfView(IBoard <IGridHex> board, ICoordsUser origin, int range,
                                                  FovTargetMode targetMode)
        {
            DebugTracing.LogTime(TraceFlag.FieldOfView, "FieldOfView - begin");
            var fov = new FieldOfView(board);

            if (board.IsPassable(origin))
            {
                Func <ICoordsCanon, int> target;
                int observer;
                switch (targetMode)
                {
                case FovTargetMode.EqualHeights:
                    observer = board[origin].ElevationASL + 1;
                    target   = canon => board[canon.User].ElevationASL + 1;
                    break;

                case FovTargetMode.TargetHeightEqualZero:
                    observer = board[origin].HeightObserver;
                    target   = canon => board[canon.User].ElevationASL;
                    break;

                default:
                case FovTargetMode.TargetHeightEqualActual:
                    observer = board[origin].HeightObserver;
                    target   = canon => board[canon.User].HeightTarget;
                    break;
                }
                ShadowCasting.ComputeFieldOfView(
                    origin.Canon,
                    range,
                    observer,
                    canon => board.IsOnBoard(canon.User),
                    target,
                    canon => board[canon.User].HeightTerrain,
                    canon => fov[canon.User] = true
                    );
            }
            DebugTracing.LogTime(TraceFlag.FieldOfView, "FieldOfView - end");
            return(fov);
        }
예제 #10
0
        public override bool CheckForUnExpected()
        {
            if (_bundle.IsFull || !(State is Resting || State is Wondering))
            {
                return(true);
            }

            var visibleCells = ShadowCasting.For(PositionCell, ViewRadius - 1, Game.Map).GetVisibleCells().OrderBy(p => p.Distance).ToList();

            var eatableCell = visibleCells.FirstOrDefault(p =>
            {
                var obj = Game.Map.GetObjectFromCell(p);
                if ((obj is Berry && obj.Name == Resource.Apple) || obj is Mushroom)
                {
                    return(true);
                }

                return(false);
            });

            if (eatableCell != null)
            {
                _stateQueue.Clear();
                EnqueueMovingToDestinationObject(eatableCell, Game.Map.GetObjectFromCell(eatableCell));
                _stateQueue.Enqueue(new Doing(this, () =>
                {
                    var obj = Game.Map.GetObjectFromCell(eatableCell);
                    if (obj != null)
                    {
                        _bundle.Add(obj);
                    }
                }));

                StateEvent.FireEvent();
                return(false);
            }

            return(true);
        }