*** This script assigns BLANK tile (#3026) to selected walls if they have no visible surfaces (masks are not considered). Useful for auto-aligning.

// Parameter list begins
mov r99 0 // Tolerance
// Parameter list ends
~~~ Default parameters:
~~~ mov r99 0 // Tolerance
mov r00 -1
for each selected wall r00
  getwall r00 nextwall r01
  if r01 == -1 // Non-paired
    getwallsectnum r00 r01
    getwall r00 x r10
    getwall r00 y r11
    gettruefloorz r10 r11 r01 r03
    gettrueceilingz r10 r11 r01 r04
    add r04 r99
    if r03 <= r04
      getwall r00 point2 r02
      getwall r02 x r10
      getwall r02 y r11
      gettruefloorz r10 r11 r01 r03
      gettrueceilingz r10 r11 r01 r04
      add r04 r99
      if r03 <= r04
        setwall r00 picnum 3026
      endif
    endif
  else // Paired
    mov r07 0
    getwall r00 x r10
    getwall r00 y r11
    getwall r00 point2 r06
    getwall r06 x r12
    getwall r06 y r13
    getwallsectnum r00 r02
    getwall r00 nextsector r05
    getwall r01 cstat r03
    and r03 2 // Get bottom swap bit
    if r03 != 0
      gettruefloorz r10 r11 r05 r03
      gettruefloorz r10 r11 r02 r04
      add r04 r99
      if r03 > r04  mov r07 1  else // Has a visible surface
        gettruefloorz r12 r13 r05 r03
        gettruefloorz r12 r13 r02 r04
        add r04 r99
        if r03 > r04  mov r07 1  endif // Has a visible surface
      endif
    endif
    if r07 == 0
      getwall r00 cstat r03
      and r03 2 // Get bottom swap bit
      if r03 == 0
        gettruefloorz r10 r11 r05 r03
        gettruefloorz r10 r11 r02 r04
        add r03 r99
        if r03 < r04  mov r07 1  else // Has a visible surface
          gettruefloorz r12 r13 r05 r03
          gettruefloorz r12 r13 r02 r04
          add r03 r99
          if r03 < r04  mov r07 1  endif // Has a visible surface
        endif
      endif
    endif
    if r07 == 0 // Main range
      gettrueceilingz r10 r11 r05 r03
      gettrueceilingz r10 r11 r02 r04
      add r04 r99
      if r03 > r04  mov r07 1  else // Has a visible surface
        gettrueceilingz r12 r13 r05 r03
        gettrueceilingz r12 r13 r02 r04
        add r04 r99
        if r03 > r04  mov r07 1  endif // Has a visible surface
      endif
    endif
    if r07 == 0 // All the surfaces are invisible
      setwall r00 picnum 3026
    endif
  endif
continue