#!/usr/bin/perl -w
#
#


sub convert_level
{
  my $filename = $_[0];

  open(LVL,$filename) || die "can't open file $filename. $!\n";
  my $squares=0;
  my $orig_square=0;
  foreach (<LVL>)
  {
    if (/^Z /) {
      $squares++;
      if (/^Z .*,TELEPORT1/)
      {
	$orig_square = $squares;
	s/TELEPORT1/TELEPORT /g;
	print "Z CAN_GO_ABOVE,TELEPORT                 teleport.png\n";
	print "Z CAN_GO_ABOVE,TELEPORT                 teleport.png\n";
	print "Z CAN_GO_ABOVE,TELEPORT                 teleport.png\n";
	print "Z CAN_GO_ABOVE,TELEPORT                 teleport.png\n";
	print "Z CAN_GO_ABOVE,TELEPORT                 teleport.png\n";
      }
      print $_;
    } elsif (/^L /) {
      my @a = split(/ /,$_);
      print "L";
      for (my $i=1;$i<scalar(@a);$i++)
      {
	if ($a[$i] =~ /^\d\d$/) {
	  if ($a[$i] >= $orig_square) {
	    $a[$i]+=5;
	  }
	  printf(" %2.2d",$a[$i]);
	} else {
	  print " ",$a[$i];
	}
      }
      print "\n";

    } else  {
      print $_;
    }
  }
  print "\n";
}


foreach (@ARGV)
{
  convert_level($_);
}

