IntVector3 FindStartLoc(Random r, SideEdge edge)
{
int side = m_terrain.Width;
int yo = r.Next(0, side);
int zo = m_terrain.GetSurfaceLevel(MapCoord(yo, edge));
int yu = yo;
int zu = zo;
for (int y = yo - 1; y >= 0; --y)
{
int z = m_terrain.GetSurfaceLevel(MapCoord(y, edge));
if (z < zu)
{
zu = z;
yu = y;
}
if (z - 2 > zu)
{
break;
}
}
int yd = yo;
int zd = zo;
for (int y = yo + 1; y < side; ++y)
{
int z = m_terrain.GetSurfaceLevel(MapCoord(y, edge));
if (z < zd)
{
zd = z;
yd = y;
}
if (z - 2 > zd)
{
break;
}
}
int yf = zd < zu ? yd : yu;
var p2 = MapCoord(yf, edge);
return(m_terrain.GetSurfaceLocation(p2));
}