I dug into this a bit and I believe I've found what causes it... Z-coordinates are stored in a grid based around 32x32 blocks, so if you accidentally place a slope or a block off this grid, the slopes will get the wrong Z value because the correct cell might not be set (or the slopes access the next cell rather than the appropriate cell). Either make sure your room grid is set to 32x32 when placing terrain, or change the value of the GRIDSIZE_PX macro to 16.