Пример #1
0
        public bool IsBlockWalkable(int blockX, int blockY)
        {
            ThreadingUtils.assertChildThread();

            if (CollisionUtils.IsBlockBlocking(GetBlockType(blockX, blockY)))
            {
                return(false);
            }

            Rect blockBounds = new Rect(blockX * WorldGrid.BlockSize.X, blockY * WorldGrid.BlockSize.Y, WorldGrid.BlockSize.X, WorldGrid.BlockSize.Y);

            if (ContainedObjects != null)
            {
                lock (ContainedObjects)
                {
                    foreach (var containedObject in ContainedObjects)
                    {
                        lock (containedObject)
                        {
                            if (containedObject.IsBlocking() && containedObject.BlockingBounds.Intersects(blockBounds))
                            {
                                return(false);
                            }
                        }
                    }
                }
            }

            return(true);
        }
Пример #2
0
        private static List <GridPos> findPathSync(WorldPosition startBlockPosition, WorldPosition endBlockPosition)
        {
            ThreadingUtils.assertChildThread();

            if (startBlockPosition.InteriorID != endBlockPosition.InteriorID)
            {
                var myPoint = findNextWorldLink(startBlockPosition, endBlockPosition);

                if (myPoint != null)
                {
                    Point newPoint = myPoint ?? Point.Zero;

                    endBlockPosition            = endBlockPosition.Clone();
                    endBlockPosition.X          = newPoint.X;
                    endBlockPosition.Y          = newPoint.Y;
                    endBlockPosition.InteriorID = startBlockPosition.InteriorID;
                }
                else
                {
                    return(null);
                }
            }

            if (startBlockPosition.InteriorID == Interior.Outside)
            {
                JumpPointParam jpp = new JumpPointParam(
                    new DynamicWalkableGrid(SimulationGame.World.WalkableGrid, (int)startBlockPosition.X, (int)startBlockPosition.Y, (int)endBlockPosition.X, (int)endBlockPosition.Y),
                    new GridPos((int)startBlockPosition.X, (int)startBlockPosition.Y),
                    new GridPos((int)endBlockPosition.X, (int)endBlockPosition.Y),
                    DiagonalMovement.OnlyWhenNoObstacles
                    );

                return(JumpPointFinder.GetFullPath(JumpPointFinder.FindPath(jpp)));
            }
            else
            {
                var interior = SimulationGame.World.InteriorManager.Get(startBlockPosition.InteriorID);
                var jpp      = new JumpPointParam(
                    new InteriorGrid(interior, (int)endBlockPosition.X, (int)endBlockPosition.Y),
                    new GridPos((int)startBlockPosition.X, (int)startBlockPosition.Y),
                    new GridPos((int)endBlockPosition.X, (int)endBlockPosition.Y),
                    DiagonalMovement.OnlyWhenNoObstacles
                    );

                return(JumpPointFinder.GetFullPath(JumpPointFinder.FindPath(jpp)));
            }
        }