*** This script replaces each tile in the map with another one with same dimensions.

mov r00 0
while r00 < 15360 // Maximum number of tiles
  gettiledim r00 r02 r03
  mov r01 r00
  if r02 != 0
    if r03 != 0
      mov r07 0 // Number of tiles found
      mov r04 0
      while r04 < 15360 // Maximum number of tiles
        gettiledim r04 r05 r06
        if r02 == r05
          if r03 == r06
            setpntb1x r07 r04 // Remember found tile
            inc r07
          endif
        endif
        inc r04
      continue
      rnd r04 // Assign random value
      and r04 2147483647 // Only positive values
      div r04 65536 // Take 15 major bits to provide random behavior
      mod r04 r07 // Values in range from 0 to r07-1
      getpntb1x r04 r01 // Get random tile ID
    endif
  endif
  setpntb1y r00 r01 // Return random tile
  inc r00
continue

mov r00 -1
for each nonignored sprite r00
  getsprite r00 lotag r01
  getsprite r00 hitag r02
  or r01 r02
  if r01 == 0 // Sprite has no tags
    getsprite r00 picnum r01 // Get sprite picnum
    if r01 > 10 // Sprite is not an effector
      getpntb1y r01 r01 // Get random tile
      setsprite r00 picnum r01 // Return sprite picnum
    endif
  endif
continue

mov r00 -1
for each nonignored sector r00
  getsector r00 floorpicnum r01 // Get picnum
  getpntb1y r01 r01 // Get random tile
  setsector r00 floorpicnum r01 // Return picnum
  getsector r00 ceilingpicnum r01 // Get picnum
  getpntb1y r01 r01 // Get random tile
  setsector r00 ceilingpicnum r01 // Return picnum
continue

mov r00 -1
for each nonignored wall r00
  getwall r00 lotag r01
  getwall r00 hitag r02
  or r01 r02
  if r01 == 0 // Wall has no tags
    getwall r00 picnum r01 // Get picnum
    getpntb1y r01 r01 // Get random tile
    setwall r00 picnum r01 // Return picnum
    getwall r00 overpicnum r01 // Get picnum
    getpntb1y r01 r01 // Get random tile
    setwall r00 overpicnum r01 // Return picnum
  endif
continue