#!/usr/local/bin/perl

open (INFILE, "first.survey.data.txt") || die "Couldn't open data!\n";

foreach (<INFILE>) {
  ($sector,$location,$name,$uwp,$remarks,$bases,$pbg,$uh,$stellar) = split(/\t/);
  $loc1 = substr($location,0,2);
  $loc2 = substr($location,2,2);

  $modloc1 = $loc1 - 1;
  $modloc2 = $loc2 - 40; 
  if ($sector =~ "ant") {
    $modloc1 -= 64;
    $modloc2 -= 40;
  }
  if ($sector =~ "vla") {
    $modloc1 -= 32;
    $modloc2 -= 40;
  }
  if ($sector =~ "lis") {
    $modloc1 += 0;
    $modloc2 -= 40;
  }
  if ($sector =~ "ant") {
    $modloc1 += 32;
    $modloc2 -= 40;
  }
  if ($sector =~ "gus") {
    $modloc1 -= 64;
    $modloc2 += 0;
  }
  if ($sector =~ "dag") {
    $modloc1 -= 32;
    $modloc2 += 0;
  }
  if ($sector =~ "for") {
    $modloc1 += 32;
    $modloc2 += 0;
  }
  if ($sector =~ "ile") {
    $modloc1 -= 64;
    $modloc2 += 40;
  }
  if ($sector =~ "zar") {
    $modloc1 -= 32;
    $modloc2 += 40;
  }
  if ($sector =~ "mas") {
    $modloc1 += 0;
    $modloc2 += 40;
  }
  if ($sector =~ "del") {
    $modloc1 += 32;
    $modloc2 += 40;
  }

  $popmod = substr($pbg,0,1);
  $belts = substr($pbg,1,1);
  $gas = substr($pbg,2,1);

  $starport = substr($uwp,0,1);
  $size = substr($uwp,1,1);
  $atmo = substr($uwp,2,1);
  $hydro = substr($uwp,3,1);
  $pop = substr($uwp,4,1);
  $govern = substr($uwp,5,1);
  $law = substr($uwp,6,1);
  $tech = substr($uwp,8,1);

  print "$sector\t$modloc1\t$modloc2\t$name\t$starport$size$atmo$hydro$pop$govern$law-$tech\t$bases\t$popmod$belts$gas\t$stellar";
#  print "$sector\t$loc1\t$loc2\t$name\t$starport\t$size\t$atmo\t$hydro\t$pop\t$govern\t$law\t$tech\t$remarks\t$bases\t$popmod\t$belts\t$gas\t$stellar";
}
