コード例 #1
0
    /// <summary>
    /// Check if the added block is connected to the main robot path (no fully functional)
    /// </summary>
    /// <param name="block">The block to validate</param>
    /// <param name="grid">The voxelgrid</param>
    /// <returns>Can the block be added or not</returns>
    private bool ConnectedPath(Block block, Grid3D grid)
    {
        var pathFinding = grid.PFinding;
        var index       = block.BlockVoxels.Where(v => v.Type == VoxelType.Block).Select(v => v.Index);
        var prevVoxels  = index.Select(v => grid.GetVoxelAt(v));

        foreach (var vox in block.BlockVoxels.Where(v => v.Type == VoxelType.Block))
        {
            //place the block within the voxelgrid
            grid.AddVoxel(vox);

            foreach (var face in grid.GetVoxelAt(vox.Index).Faces.Where(f => f.Climable))
            {
                int test = pathFinding.GetPathCount(pathFinding.CreateGraph(), face);
                if (test != pathFinding.RidiculousHighNumber)
                {
                    return(true);
                }
            }
        }

        //restore the original state of the voxelgrid
        foreach (var v in prevVoxels)
        {
            grid.AddVoxel(v);
        }

        return(false);
    }