Cleaned it up a little so it got consistent formatting. nothing really stood out except the mod command which was not implemented correctly, and the random commands which would be out of bounds.
mod():
Same as a division - but rather than return the fraction, it returns the remainder. so x = 3 / 2 would return (assuming x is float) 1.5, x = mod(3, 2) would return 5.
random():
Will return a value between 0 and 65k - where one can clamp it to a given range. If one need negative numbers in the range, subtract from the result *not* in the parameter. So for instance if wanting a result from -5 to +5 the correct procedure is x = random(0, 10) - 5
anyhow, the cleaned up code - with no compilation errors:
function generateterrain(map ref as integer [][], width, height, smoothness, plower, maxheight)
strep = plower / 2
h = maxheight / 2
for i = 0 to width - 1 step 2 * strep
for j = 0 to height - 1 step 2 * strep
map[i, j] = random(0, maxheight)
next j
next i
while strep > 0
for x = strep to width - 1 step 2 * strep
for y = strep to height - 1 step 2 * strep
slum = map[x - strep, y - strep] + map[x - strep, y + strep] + map[x + strep, y - strep] + map[x + strep, y + strep]
map[x, y] = slum / 4 + (random(0, h) - h)
next y
next x
for x = 0 to width - 1 step strep
for y = strep * mod(1 - (x / strep), 2) to height - 1 step 2 * strep
slum = 0
crount = 0
if x - strep >= 0
slum = slum + map[x - strep, y]
crount = crount + 1
endif
if x + strep < width
slum = slum + map[x + strep, y]
crount = crount + 1
endif
if y - strep >= 0
slum = slum + map[x, y - strep]
crount = crount + 1
endif
if y + strep < height
slum = slum + map[x, y + strep]
crount = crount + 1
endif
if crount > 0
map[x, y] = slum / crount + (random(0, h) - h)
else
map[x, y] = 0
endif
next y
next x
h = h / smoothness
strep = strep / 2
endwhile
endfunction