示例#1
0
        /// <summary>
        /// Raises the north-eastern corner of the specified voxel
        /// </summary>
        /// <returns>false if the operation was unsuccessful.</returns>
        private bool raise(Location loc)
        {
            WorldDefinition w = WorldDefinition.World;

            // make sure that four surrounding voxels can be raised,
            // and the ground levels of them are the same
            if (!canBeRaised(loc))
            {
                return(false);
            }

            // then actually change the terrain
            for (int x = 0; x <= 1; x++)
            {
                for (int y = -1; y <= 0; y++)
                {
                    Location l = new Location(loc.x + x, loc.y + y, loc.z);

                    Voxel vx = w[l];
                    if (vx is WorldDefinition.OutOfWorldVoxel)
                    {
                        continue;       // this is beyond the border
                    }
                    MountainVoxel v = vx as MountainVoxel;

                    Direction d = Direction.get(1 - x * 2, -y * 2 - 1); // corner to modify

                    if (v == null)
                    {
                        v = new MountainVoxel(l, 0, 0, 0, 0);
                    }

                    // raise the corner
                    v.setHeight(d, v.getHeight(d) + 1);

                    if (v.isSaturated)
                    {
                        // if the voxel is saturated, raise the ground level
                        w.raiseGround(l);
                        w.remove(l);    // remove this voxel
                    }
                }
            }

            return(true);
        }