Exemple #1
0
        /// <summary>Get the height of the topmost ground at a given position. Used for generating navigation data. (Eventually replace with a multi-layer heightmap.)</summary>
        public static int TopmostGroundHeight(ref CharacterPhysicsInfo info, WorldPhysics world, int x, int z, bool staticOnly = false)
        {
            int startX = x + info.startX;
            int endX   = x + info.endX;

            // Hack: If we slip in just under the ceiling, we can get the result for the next-highest floor
            //       This is a hack because it depends on knowledge of what GetGroundHeightInXRange is doing
            int minCeiling = WorldPhysics.MaximumHeight + info.height;

            if (world.levelCeiling != null)
            {
                for (int xx = startX; xx < endX; xx++)
                {
                    int c = world.levelCeiling[xx, z];
                    if (c == 0)
                    {
                        continue;
                    }

                    if (c < minCeiling)
                    {
                        minCeiling = c;
                    }
                }
            }

            return(world.GetGroundHeightInXRange(startX, endX, z, minCeiling - info.height, minCeiling, info.owner, staticOnly));
        }
Exemple #2
0
        /// <summary>Get the height of the lowest ground position we can stand at at the given XZ coordinates, in some given Y range.</summary>
        /// <returns>The resulting height, or WorldPhysics.MaximumHeight if it did not fit</returns>
        public static int LowestValidGroundHeight(ref CharacterPhysicsInfo info, WorldPhysics world, int x, int z, int startY, int endY, bool staticOnly = false)
        {
            int startX = x + info.startX;
            int endX   = x + info.endX;

            if (endY > WorldPhysics.MaximumHeight)
            {
                endY = WorldPhysics.MaximumHeight;
            }

            // Repeatedly test the walkable height upwards, until it returns somewhere we are confirmed to fit
            int tryingHeight = startY;
            int resultingHeight;

            do
            {
                resultingHeight = world.GetGroundHeightInXRange(startX, endX, z, tryingHeight, tryingHeight + info.height, info.owner, staticOnly);
                if (resultingHeight <= startY)
                {
                    return(startY);
                }
                if (resultingHeight == tryingHeight)
                {
                    break;
                }
                tryingHeight = resultingHeight;
            }while(resultingHeight < endY);

            if (resultingHeight == tryingHeight && resultingHeight >= startY && resultingHeight < endY)
            {
                return(resultingHeight);
            }

            return(WorldPhysics.MaximumHeight); // <- Failed
        }
Exemple #3
0
        public static int GroundHeight(ref CharacterPhysicsInfo info, WorldPhysics world, Position position, bool staticOnly = false)
        {
            int startX = position.X + info.startX;
            int endX   = position.X + info.endX;

            return(world.GetGroundHeightInXRange(startX, endX, position.Z, position.Y, position.Y + info.height, info.owner, staticOnly));
        }