Dwarrowdelf.EnvironmentExtensions.CanMoveTo C# (CSharp) Method

CanMoveTo() public static method

Determine if a living can move to dir, ending to dstLoc, without considering the source
public static CanMoveTo ( this env, IntVector3 dstLoc, Direction dir ) : bool
env this
dstLoc IntVector3
dir Direction
return bool
        public static bool CanMoveTo(this IEnvironmentObject env, IntVector3 dstLoc, Direction dir)
        {
            Debug.Assert(dir.IsValid());

            if (!env.Contains(dstLoc))
                return false;

            var td = env.GetTileData(dstLoc);

            if (td.IsUndefined)
                return false;

            if (td.IsWalkable == false)
                return false;

            if (dir.IsPlanar())
                return true;

            if (dir == Direction.Up)
                return true;

            if (dir == Direction.Down)
                return td.ID == TileID.Stairs;

            if (dir.ContainsUp())
            {
                return true;
            }

            if (dir.ContainsDown() && env.Size.Depth > dstLoc.Z + 1)
            {
                if (env.GetTileData(dstLoc.Up).IsEmpty == false)
                    return false;

                return true;
            }

            return false;
        }