*** This script interpolates Z-positions of selected sprites between minimal and maximal hitags using hitag as a key for interpolating.

// Find sprites with minimal and maximal hitags
mov r01 -1 // Minimal Z
mov r02 65536 // Minimal hitag
mov r03 -1 // Maximal Z
mov r04 -1 // Maximal hitag
mov r00 -1 // Counter
for each selected sprite r00
  getsprite r00 hitag r05
  if r05 < r02
    mov r02 r05
    getsprite r00 z r01
  endif
  if r05 > r04
    mov r04 r05
    getsprite r00 z r03
  endif
continue

// Assign interpolated Z-positions to selected sprites

sub r03 r01 // Z difference
sub r04 r02 // Hitag difference
mov r00 -1
for each selected sprite r00
  getsprite r00 hitag r05
  sub r05 r02
  mul r05 r03
  div r05 r04
  add r05 r01
  setsprite r00 z r05
continue