Dwarrowdelf.EnvironmentExtensions.CanMoveFrom C# (CSharp) Method

CanMoveFrom() public static method

Determine if a living can move from srcLoc to dir, without considering the destination
public static CanMoveFrom ( this env, IntVector3 srcLoc, Direction dir ) : bool
env this
srcLoc IntVector3
dir Direction
return bool
        public static bool CanMoveFrom(this IEnvironmentObject env, IntVector3 srcLoc, Direction dir)
        {
            Debug.Assert(dir.IsValid());

            if (env.Contains(srcLoc) == false)
                return false;

            var td = env.GetTileData(srcLoc);

            if (td.IsUndefined)
                return false;

            // Perhaps this check is not needed
            if (td.IsWalkable == false)
                return false;

            if (dir.IsPlanar())
                return true;

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

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

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

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

                return true;
            }

            return false;
        }